diff --git a/src/builtins/group.c b/src/builtins/group.c index 6d945136..9f2cff82 100644 --- a/src/builtins/group.c +++ b/src/builtins/group.c @@ -100,9 +100,9 @@ static B group_simple(B w, B x, ur xr, usz wia, usz xn, usz* xsh, u8 we) { } if (we==el_bit) { assert(ria == 2); - if (wia>xn) w = take_c2(m_f64(0), m_f64(xn), w); - rp[1] = slash_c2(m_f64(0), inc(w), inc(x)); - rp[0] = slash_c2(m_f64(0), not_c1(m_f64(0), w), x); + if (wia>xn) w = C2(take, m_f64(xn), w); + rp[1] = C2(slash, inc(w), inc(x)); + rp[0] = C2(slash, C1(not, w), x); return taga(r); } // Needed to make sure wia>0 for ip[wia-1] below @@ -128,9 +128,6 @@ static B group_simple(B w, B x, ur xr, usz wia, usz xn, usz* xsh, u8 we) { // Few changes in 𝕨: move in chunks if (xn>64 && notB && change<(xn*width)/32) { - #define C1(F,X ) F##_c1(m_f64(0),X ) - #define C2(F,X,W) F##_c2(m_f64(0),X,W) - u64* mp; B m = m_bitarrv(&mp, xn); u8* wp0 = tyany_ptr(w); we = TI(w,elType); @@ -139,8 +136,6 @@ static B group_simple(B w, B x, ur xr, usz wia, usz xn, usz* xsh, u8 we) { B ind = C1(slash, m); w = C2(select, inc(ind), w); - #undef C1 - #undef C2 if (TI(ind,elType)!=el_i32) ind = taga(cpyI32Arr(ind)); if (TI(w ,elType)!=el_i32) w = taga(cpyI32Arr(w )); wia = IA(ind); @@ -179,10 +174,10 @@ static B group_simple(B w, B x, ur xr, usz wia, usz xn, usz* xsh, u8 we) { // Many ¯1s: filter out, then continue if (xn>32 && neg>(bits?0:xn/4)+xn/8) { - if (wia>xn) w = take_c2(m_f64(0), m_f64(xn), w); - B m = ne_c2(m_f64(0), m_f64(-1), inc(w)); - w = slash_c2(m_f64(0), inc(m), w); - x = slash_c2(m_f64(0), m, x); xn = *SH(x); + if (wia>xn) w = C2(take, m_f64(xn), w); + B m = C2(ne, m_f64(-1), inc(w)); + w = C2(slash, inc(m), w); + x = C2(slash, m, x); xn = *SH(x); neg = 0; } if (TI(w,elType)!=el_i32) w = taga(cpyI32Arr(w)); @@ -331,8 +326,8 @@ B group_c2(B t, B w, B x) { B group_c1(B t, B x) { if (isArr(x) && RNK(x)==1 && TI(x,arrD1)) { usz ia = IA(x); - B range = ud_c1(t, m_f64(ia)); - return group_c2(m_f64(0), x, range); + B range = C1(ud, m_f64(ia)); + return C2(group, x, range); } return c1(rt_group, x); } diff --git a/src/builtins/search.c b/src/builtins/search.c index 330f9285..ff1eeae3 100644 --- a/src/builtins/search.c +++ b/src/builtins/search.c @@ -1,8 +1,8 @@ #include "../core.h" #include "../utils/hash.h" #include "../utils/talloc.h" +#include "../utils/calls.h" -#define C2(F,X,W) F##_c2(m_f64(0),X,W) #define C2i(F, W, X) C2(F, m_i32(W), X) extern B eq_c2(B,B,B); extern B ne_c2(B,B,B); diff --git a/src/builtins/selfsearch.c b/src/builtins/selfsearch.c index c0346d75..d7d046ea 100644 --- a/src/builtins/selfsearch.c +++ b/src/builtins/selfsearch.c @@ -304,10 +304,9 @@ B count_c1(B t, B x) { if (lw==0) { x = toI8Any(x); lw = cellWidthLog(x); } if (use_sorted(x, lw) && n>16 && (lw>4 || n<1<<16)) { // ↕∘≠(⊣-⌈`∘×)∊ B c = shift_ne(x, n, lw, 1); - B i = ud_c1(m_f64(0), m_f64(n)); - Md1D d; d.f = bi_ceil; - B m = scan_c1(&d, mul_c2(m_f64(0), c, inc(i))); - return sub_c2(m_f64(0), i, m); + B i = C1(ud, m_f64(n)); + B m = M1C1(scan, ceil, C2(mul, c, inc(i))); + return C2(sub, i, m); } void* xv = tyany_ptr(x); #define BRUTE(T) \ @@ -395,13 +394,11 @@ B indexOf_c1(B t, B x) { u8 lw = cellWidthLog(x); void* xv = tyany_ptr(x); if (lw == 0) { - B r = 1&*(u64*)xv ? not_c1(m_f64(0), x) : x; - return shape_c1(m_f64(0), r); + B r = 1&*(u64*)xv ? C1(not, x) : x; + return C1(shape, r); } if (use_sorted(x, lw) && n>8) { - B r = shift_ne(x, n, lw, 0); - Md1D d; d.f = bi_add; - return scan_c1(&d, r); + return M1C1(scan, add, shift_ne(x, n, lw, 0)); } #define BRUTE(T) \ i##T* xp = xv; \ @@ -492,5 +489,5 @@ B find_c1(B t, B x) { if (isAtm(x) || RNK(x)==0) thrM("⍷: Argument cannot have rank 0"); usz n = *SH(x); if (n<=1) return x; - return slash_c2(m_f64(0), memberOf_c1(m_f64(0), inc(x)), x); + return C2(slash, C1(memberOf, inc(x)), x); } diff --git a/src/utils/calls.h b/src/utils/calls.h index c9cc4d1b..5fb4bc20 100644 --- a/src/utils/calls.h +++ b/src/utils/calls.h @@ -1,5 +1,12 @@ #pragma once +#define C1(F,X ) F##_c1(m_f64(0),X ) +#define C2(F,X,W) F##_c2(m_f64(0),X,W) +#define M1C1(M,F,X ) m1c1_unsafe(M##_c1, bi_##F, X ) +#define M1C2(M,F,X,W) m1c2_unsafe(M##_c1, bi_##F, X, W) +static inline B m1c1_unsafe(D1C1 m, B f, B x ) { Md1D d; d.f=f; return m(&d, x ); } +static inline B m1c2_unsafe(D1C2 m, B f, B x, B w) { Md1D d; d.f=f; return m(&d, x, w); } + typedef void (*M_CopyF)(void*, usz, B, usz, usz); typedef void (*M_FillF)(void*, usz, B, usz); extern M_CopyF copyFns[el_MAX]; @@ -28,4 +35,4 @@ CMP_DEF(le, AS); #define CMP_AA_IMM(FN, ELT, WHERE, WP, XP, LEN) CMP_AA_CALL(CMP_AA_FN(FN, ELT), WHERE, WP, XP, LEN) #define CMP_AS_IMM(FN, ELT, WHERE, WP, X, LEN) CMP_AS_CALL(CMP_AS_FN(FN, ELT), WHERE, WP, X, LEN) -void bit_negatePtr(u64* rp, u64* xp, usz count); // count is number of u64-s \ No newline at end of file +void bit_negatePtr(u64* rp, u64* xp, usz count); // count is number of u64-s