diff --git a/src/builtins/selfsearch.c b/src/builtins/selfsearch.c index d7d046ea..cd10d5bd 100644 --- a/src/builtins/selfsearch.c +++ b/src/builtins/selfsearch.c @@ -4,7 +4,8 @@ // Other functions use adaptations of the same set of methods // Boolean ∊: 1 at first element and first Β¬βŠ‘π•© -// COULD do a branchless thing for boolean βŠ’ instead of converting to i8 +// Boolean βŠ’: Branchless sum thing +// COULD vectorize boolean βŠ’ with +` // Boolean ⊐: β₯ŠΒ¬βŸβŠ‘π•© // SHOULD implement boolean ⍷ directly // Sorted flags: start with r0βŒΎβŠ‘Β»βŠΈβ‰ π•© (r0 is 0 for ⊐ and 1 otherwise) @@ -301,7 +302,27 @@ B count_c1(B t, B x) { if (n>(usz)I32_MAX+1) thrM("βŠ’: Argument length >2⋆31 not supported"); u8 lw = cellWidthLog(x); - if (lw==0) { x = toI8Any(x); lw = cellWidthLog(x); } + if (lw==0) { + u64* xp = bitarr_ptr(x); + B r; + #define COUNT_BOOL(T) \ + T* rp; r = m_##T##arrv(&rp, n); \ + usz n1 = 0; \ + for (usz i=0; i>=1; \ + rp[i] = b? n1 : i-n1; \ + n1 += b; \ + } \ + } + if (n <= 128) { COUNT_BOOL(i8) } + else if (n <= 1<<15) { COUNT_BOOL(i16) } + else { COUNT_BOOL(i32) } + decG(x); return r; + #undef COUNT_LOOP + #undef COUNT_BOOL + } if (use_sorted(x, lw) && n>16 && (lw>4 || n<1<<16)) { // β†•βˆ˜β‰ (⊣-⌈`βˆ˜Γ—)∊ B c = shift_ne(x, n, lw, 1); B i = C1(ud, m_f64(n));