deduplicate things in ⊏

This commit is contained in:
dzaima 2022-05-01 02:24:51 +03:00
parent 886feb4ed0
commit 836fe9184a

View File

@ -41,11 +41,11 @@ B select_c2(B t, B w, B x) {
B xf = getFillQ(x); B xf = getFillQ(x);
SGet(x) SGet(x)
usz wia = a(w)->ia; usz wia = a(w)->ia;
B r;
if (xr==1) { if (xr==1) {
if (wia==0) { if (wia==0) {
decG(x); decG(x);
B r;
if (isVal(xf)) { if (isVal(xf)) {
Arr* ra = m_fillarrp(0); Arr* ra = m_fillarrp(0);
arr_shCopy(ra, w); arr_shCopy(ra, w);
@ -65,26 +65,31 @@ B select_c2(B t, B w, B x) {
u8 xe = TI(x,elType); u8 xe = TI(x,elType);
u8 we = TI(w,elType); u8 we = TI(w,elType);
#if SINGELI #if SINGELI
// if (we==el_i8 && xe==el_i32) { i32* rp; B r = m_i32arrc(&rp, w); if (!avx2_select_i8_32 ((u8*)i8any_ptr (w), (u8*)i32any_ptr(x), (u8*)rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); decG(w); decG(x); return r; } // if (we==el_i8 && xe==el_i32) { i32* rp; r = m_i32arrc(&rp, w); if (!avx2_select_i8_32 ((u8*)i8any_ptr (w), (u8*)i32any_ptr(x), (u8*)rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); goto dec_ret; }
// if (we==el_i16 && xe==el_i32) { i32* rp; B r = m_i32arrc(&rp, w); if (!avx2_select_i16_32((u8*)i16any_ptr(w), (u8*)i32any_ptr(x), (u8*)rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); decG(w); decG(x); return r; } // if (we==el_i16 && xe==el_i32) { i32* rp; r = m_i32arrc(&rp, w); if (!avx2_select_i16_32((u8*)i16any_ptr(w), (u8*)i32any_ptr(x), (u8*)rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); goto dec_ret; }
// if (we==el_i32 && xe==el_i8 ) { i8* rp; B r = m_i8arrc (&rp, w); if (!avx2_select_i32_8 ((u8*)i32any_ptr(w), (u8*)i8any_ptr (x), (u8*)rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); decG(w); decG(x); return r; } // if (we==el_i32 && xe==el_i8 ) { i8* rp; r = m_i8arrc (&rp, w); if (!avx2_select_i32_8 ((u8*)i32any_ptr(w), (u8*)i8any_ptr (x), (u8*)rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); goto dec_ret; }
// if (we==el_i32 && xe==el_i32) { i32* rp; B r = m_i32arrc(&rp, w); if (!avx2_select_i32_32((u8*)i32any_ptr(w), (u8*)i32any_ptr(x), (u8*)rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); decG(w); decG(x); return r; } // if (we==el_i32 && xe==el_i32) { i32* rp; r = m_i32arrc(&rp, w); if (!avx2_select_i32_32((u8*)i32any_ptr(w), (u8*)i32any_ptr(x), (u8*)rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); goto dec_ret; }
// if (we==el_i32 && xe==el_f64) { f64* rp; B r = m_f64arrc(&rp, w); if (!avx2_select_i32_64((u8*)i32any_ptr(w), (u8*)f64any_ptr(x), (u8*)rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); decG(w); decG(x); return r; } // if (we==el_i32 && xe==el_f64) { f64* rp; r = m_f64arrc(&rp, w); if (!avx2_select_i32_64((u8*)i32any_ptr(w), (u8*)f64any_ptr(x), (u8*)rp, wia, xia)) thrM("⊏: Indexing out-of-bounds"); goto dec_ret; }
#endif #endif
#define CASE(T,E) if (xe==el_##T) { \ #define CASE(E,TY) { \
E* rp; B r = m_##T##arrc(&rp, w); \ E* rp = m_tyarrc(&r, sizeof(E), w, TY); \
E* xp = T##any_ptr(x); \ E* xp = tyany_ptr(x); \
for (usz i = 0; i < wia; i++) rp[i] = xp[WRAP(wp[i], xia, thrF("⊏: Indexing out-of-bounds (%i∊𝕨, %s≡≠𝕩)", wp[i], xia))]; \ for (usz i = 0; i < wia; i++) rp[i] = xp[WRAP(wp[i], xia, thrF("⊏: Indexing out-of-bounds (%i∊𝕨, %s≡≠𝕩)", wp[i], xia))]; \
decG(w); decG(x); return r; \ goto dec_ret; \
} }
#define TYPE(W) { W* wp = W##any_ptr(w); \ #define TYPE(W) { W* wp = W##any_ptr(w); \
if (xe==el_bit) { u64* xp=bitarr_ptr(x); \ switch(xe) { default: UD; \
u64* rp; B r = m_bitarrc(&rp, w); \ case el_bit: { u64* xp=bitarr_ptr(x); \
u64* rp; r = m_bitarrc(&rp, w); \
for (usz i = 0; i < wia; i++) bitp_set(rp, i, bitp_get(xp, WRAP(wp[i], xia, thrF("⊏: Indexing out-of-bounds (%i∊𝕨, %s≡≠𝕩)", wp[i], xia)))); \ for (usz i = 0; i < wia; i++) bitp_set(rp, i, bitp_get(xp, WRAP(wp[i], xia, thrF("⊏: Indexing out-of-bounds (%i∊𝕨, %s≡≠𝕩)", wp[i], xia)))); \
decG(w); decG(x); return r; \ goto dec_ret; \
} \
case el_i8: case el_c8: CASE(u8 ,el2t(xe)) \
case el_i16:case el_c16:CASE(u16,el2t(xe)) \
case el_i32:case el_c32:CASE(u32,el2t(xe)) \
case el_f64: CASE(f64,t_f64arr) \
case el_B:; \
} \ } \
CASE(i8,i8) CASE(i16,i16) CASE(i32,i32) \
CASE(c8,u8) CASE(c16,u16) CASE(c32,u32) CASE(f64,f64) \
M_HARR(r, wia); \ M_HARR(r, wia); \
if (v(x)->type==t_harr || v(x)->type==t_hslice) { \ if (v(x)->type==t_harr || v(x)->type==t_hslice) { \
B* xp = hany_ptr(x); \ B* xp = hany_ptr(x); \
@ -96,7 +101,7 @@ B select_c2(B t, B w, B x) {
} }
if (we==el_bit && xia>=2) { if (we==el_bit && xia>=2) {
SGetU(x) SGetU(x)
B r = bit_sel(w, GetU(x,0), true, GetU(x,1), true); r = bit_sel(w, GetU(x,0), true, GetU(x,1), true);
decG(x); decG(x);
return withFill(r, xf); return withFill(r, xf);
} }
@ -145,9 +150,12 @@ B select_c2(B t, B w, B x) {
decG(w); decG(x); decG(w); decG(x);
return withFill(taga(ra),xf); return withFill(taga(ra),xf);
} }
base: base:;
dec(xf); dec(xf);
return c2(rt_select, w, x); return c2(rt_select, w, x);
dec_ret:;
decG(w); decG(x); return r;
} }