diff --git a/src/builtins/cells.c b/src/builtins/cells.c index 67770082..3407be3d 100644 --- a/src/builtins/cells.c +++ b/src/builtins/cells.c @@ -214,7 +214,7 @@ NOINLINE B leading_axis_arith(FC2 fc2, B w, B x, usz* wsh, usz* xsh, ur mr) { // ur br = wr>xr? wr : xr; usz csz = shProd(bsh, mr, br); - if (csz<5120>>arrTypeBitsLog(TY(b))) { + if (HEURISTIC(csz<5120>>arrTypeBitsLog(TY(b)))) { B s = mr==wr? w : x; // smaller argument s = C2(slash, m_usz(csz), taga(arr_shVec(TI(s,slice)(s,0,IA(s))))); assert(reusable(s) && RNK(s)==1); @@ -265,7 +265,7 @@ static NOINLINE B pick_cells(usz ind, B x, ur xr, usz cam, usz k) { // ind <∘ static void set_column_typed(void* rp, B v, u8 e, ux p, ux stride, ux n) { // may write to all elements 0 ≤ i < stride×n, and after that too for masked stores assert(p < stride); switch(e) { default: UD; - case el_bit: if (stride<64 && n>64) goto bit_special; + case el_bit: if (stride<64 && HEURISTIC(n>64)) goto bit_special; NOVECTORIZE for (usz i=0; i(2048*8)>>arrTypeBitsLog(TY(x)) && IA(w)!=IA(x))) goto generic; + if (TI(w,elType)==el_B || TI(x,elType)==el_B || HEURISTIC(IA(x)>(2048*8)>>arrTypeBitsLog(TY(x)) && IA(w)!=IA(x))) goto generic; return c2(f, w, C2(shape, C1(fne, incG(w)), x)); } } else if (!isMd(f)) { @@ -812,7 +812,7 @@ NOINLINE B for_cells_SA(B f, B w, B x, ur xcr, ur xr, u32 chr) { // w⊸F⎉xcr if (isAtm(w)) return c2(f, w, x); if (IA(x)==0) break; if (RNK(w)!=xcr || !eqShPart(SH(w), xsh+xk, xcr)) break; - if (TI(w,elType)==el_B || TI(x,elType)==el_B || (IA(w)>(2048*8)>>arrTypeBitsLog(TY(w)) && IA(w)!=IA(x))) break; + if (TI(w,elType)==el_B || TI(x,elType)==el_B || HEURISTIC(IA(w)>(2048*8)>>arrTypeBitsLog(TY(w)) && IA(w)!=IA(x))) break; return c2(f, C2(shape, C1(fne, incG(x)), w), x); } } diff --git a/src/builtins/select.c b/src/builtins/select.c index 5ef96908..8a4ea717 100644 --- a/src/builtins/select.c +++ b/src/builtins/select.c @@ -291,7 +291,7 @@ B select_c2(B t, B w, B x) { #define BOOL_SPECIAL(W) #endif - if (!bool_use_simd && xe==el_bit && (csz&7)!=0 && (xl==0? wia>=256 : wia>=4) && csz<128 && TI(w,arrD1)) { + if (!bool_use_simd && xe==el_bit && (csz&7)!=0 && HEURISTIC(xl==0? wia>=256 : wia>=4) && csz<128 && TI(w,arrD1)) { // test widen/narrow on bitarr input // ShArr* sh = RNK(x)==1? NULL : ptr_inc(shObj(x)); // B t = C2(select, w, widenBitArr(x, 1)); @@ -300,7 +300,7 @@ B select_c2(B t, B w, B x) { // return r; if (csz==1) { if (wia/4>=xia) return taga(cpyBitArr(C2(select, w, taga(cpyI8Arr(x))))); - } else if (csz>64? wia/2>=xn : wia>=xn/2) { + } else if (HEURISTIC(csz>64? wia/2>=xn : wia>=xn/2)) { ShArr* sh = ptr_inc(shObj(x)); B t = C2(select, w, widenBitArr(x, 1)); B r = narrowWidenedBitArr(t, wr, xr-1, sh->a+1); @@ -368,11 +368,12 @@ B select_c2(B t, B w, B x) { case el_i16: TYPE(i16,cpyI32Arr) case el_i32: TYPE(i32,cpyF64Arr) case el_f64: { - if (FL_HAS(w, fl_squoze)) goto generic_l; // either has non-integers (i.e. error, thus don't care about speed) or very large (i.e. will hit memory bandwidth anyway) + if (MAY_T(FL_HAS(w, fl_squoze))) goto generic_l; // either has non-integers (i.e. error, thus don't care about speed) or very large (i.e. will hit memory bandwidth anyway) // else fallthrough - want to do integer 𝕨 if possible } case el_B: case el_c8: case el_c16: case el_c32: { w = squeeze_numTry(w, &we); + if (RANDOMIZE_HEURISTICS && we==el_f64) goto generic_l; // avoid infinite loop if (elNum(we)) goto retry; goto def_xf_base; } @@ -721,8 +722,7 @@ B select_rows_direct(B x, ux csz, ux cam, void* inds, ux indn, u8 ie) { // ⥊ ( if (ie==el_bit) { // TODO path for xe==el_bit + long indn - if (csz>32 || indn>32 || indn>INDS_BUF_MAX) { // TODO properly tune - assert(xe!=el_bit && (csz>8 || indn>8)); + if (HEURISTIC_BOUNDED(csz>32 || indn>32 || indn>INDS_BUF_MAX, xe!=el_bit && (csz>8 || indn>8), true)) { // TODO properly tune 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<0) { + if (MAY_F(isArr(o) && RNK(x)>0)) { usz xn = *SH(x); i64 buf[2]; if (wia!=0 && (!getRange_fns[we](tyany_ptr(w), buf, wia) || buf[0]<-(i64)xn || buf[1]>=xn)) { @@ -1039,7 +1039,7 @@ B select_ucw(B t, B o, B w, B x) { fatal("select_ucw expected to error"); } rep = incG(o); - } else if (isFun(o) && TY(o)==t_md1D && RNK(x)==1) { + } else if (MAY_F(isFun(o) && TY(o)==t_md1D && RNK(x)==1)) { Md1D* od = c(Md1D,o); if (PRTID(od->m1) != n_each) goto notConstEach; B c;