use fast path for inds⊸⊏˘el_B and ⌽˘el_B

This commit is contained in:
dzaima 2024-07-29 01:19:44 +03:00
parent 6900ae4b68
commit bc81b26a03
3 changed files with 29 additions and 9 deletions

View File

@ -505,7 +505,7 @@ B for_cells_c1(B f, u32 xr, u32 cr, u32 k, B x, u32 chr) { // F⎉cr x; array x,
ux csz = xsh[k];
if (csz<=1 || IA(x)==0) return x;
u8 xe = TI(x,elType);
if (cr==1 && csz<=64 && xe!=el_bit && xe!=el_B && csz < (128*8 >> arrTypeBitsLog(TY(x)))) {
if (cr==1 && csz<=64 && xe!=el_bit && csz < (128*8 >> arrTypeBitsLog(TY(x)))) {
incG(x); // TODO proper shape moving
Arr* r = customizeShape(select_rows_direct(x, csz, cam, reverse_inds_64+64-csz, csz, el_i8));
arr_shCopy(r, x);

View File

@ -559,10 +559,16 @@ B select_replace(u32 chr, B w, B x, B rep, usz wia, usz cam, usz csz) { // consu
#undef FREE_CHECK
}
static void* m_tyarrv_same(B* r, usz ia, B src) { // makes a new typed array with same element type as src, but new ia
u8 se = TI(src,elType); assert(se!=el_bit && se!=el_B);
static void* m_arrv_same(B* r, usz ia, B src) { // makes a new array with same element type as src, but new ia
u8 se = TI(src,elType); assert(se!=el_bit);
if (se==el_B) {
HArr_p p = m_harr0v(ia);
*r = p.b;
return p.a;
} else {
return m_tyarrlv(r, arrTypeWidthLog(TY(src)), ia, arrNewType(TY(src)));
}
}
B slash_c2(B, B, B);
Arr* customizeShape(B x); // from cells.c
@ -596,8 +602,15 @@ B select_rows_direct(B x, ux csz, ux cam, void* inds, ux indn, u8 ie) { // ⥊ (
u8 xe = TI(x,elType);
u8 lb = arrTypeWidthLog(TY(x));
u8* xp = tyany_ptr(x);
if (xe==el_bit || xe==el_B) goto generic_any;
u8* xp;
if (xe==el_B) {
if (sizeof(B) != 8) goto generic_any;
xp = (u8*) arr_bptr(x);
if (xp == NULL) goto generic_any;
} else {
if (xe == el_bit) goto generic_any;
xp = tyany_ptr(x);
}
B r;
ux ria = indn * cam;
@ -608,7 +621,7 @@ B select_rows_direct(B x, ux csz, ux cam, void* inds, ux indn, u8 ie) { // ⥊ (
if (ie==el_bit) {
if (csz>32 || indn>32 || indn>INDS_BUF_MAX) { // TODO properly tune
u8* rp = m_tyarrv_same(&r, ria, x);
u8* rp = m_arrv_same(&r, ria, x);
for (ux i = 0; i < cam; i++) {
bitselFns[lb](rp, inds, loadu_u64(xp), loadu_u64(xp + (1<<lb)), indn);
xp+= xbump;
@ -667,7 +680,7 @@ B select_rows_direct(B x, ux csz, ux cam, void* inds, ux indn, u8 ie) { // ⥊ (
}
#endif
u8* rp = m_tyarrv_same(&r, ria, x);
u8* rp = m_arrv_same(&r, ria, x);
ux slow_cam = cam;
#if SINGELI_AVX2 || SINGELI_NEON
@ -748,12 +761,18 @@ B select_rows_direct(B x, ux csz, ux cam, void* inds, ux indn, u8 ie) { // ⥊ (
assert(generic_allowed);
return select_cells_base(indo, x, csz, cam);
}
goto generic_int;
generic_int:;
assert(ie!=el_bit && generic_allowed);
B indo = taga(arr_shVec(m_tyslice(inds, a(emptyIVec()), ie, indn)));
return select_cells_base(indo, x, csz, cam);
decG_ret:;
if (xe==el_B) {
B* rp = harr_ptr(r);
for (ux i = 0; i < ria; i++) inc(rp[i]); // TODO if only a few columns are selected, could incBy in a stride per selected column
}
decG(x);
return r;
}

View File

@ -32,4 +32,5 @@
Test {{@ + 𝕩 •rand.Range 100}}
Test {{@ + 𝕩 •rand.Range 1000}}
Test {{@ + 𝕩 •rand.Range 1114111}}
Test {{"foo"@¨ 𝕩 •rand.Range 2}}
)