From 93ef4bb2a990c211d43557562689247e3b97fa3e Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 15 Nov 2022 18:37:54 -0500 Subject: [PATCH] =?UTF-8?q?Direct=20=E2=8D=B7bool=20implementation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/selfsearch.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/builtins/selfsearch.c b/src/builtins/selfsearch.c index cd10d5bd..c9e4051b 100644 --- a/src/builtins/selfsearch.c +++ b/src/builtins/selfsearch.c @@ -3,16 +3,14 @@ // Except for trivial cases, ⍷ is implemented as ∊⊸/ // Other functions use adaptations of the same set of methods -// Boolean ∊: 1 at first element and first ¬⊑𝕩 -// Boolean ⊒: Branchless sum thing +// Boolean cases all use special code, including ⍷ // COULD vectorize boolean ⊒ with +` -// Boolean ⊐: ⥊¬⍟⊑𝕩 -// SHOULD implement boolean ⍷ directly -// Sorted flags: start with r0⌾⊑»⊸≠𝕩 (r0 is 0 for ⊐ and 1 otherwise) +// Sorted flags: start with r0⌾⊑»⊸≠𝕩 (r0←0 for ⊐, 1 otherwise) // ∊: ⊢; ⊐: +`; ⊒: ↕∘≠⊸(⊣-⌈`∘×) // COULD determine ⊒ result type by direct comparisons on 𝕩 // Brute force or all-pairs comparison for small lengths // Branchless, not vectorized (+´∧` structure for ⊐) +// COULD use direct all-pairs filter, not ∊⊸/, for short ⍷ // Full-size table lookups for 1- and 2-byte 𝕩 // 2-byte table can be "sparse" initialized with an extra pass over 𝕩 // 4-byte ⊐ can use a small-range lookup table @@ -29,6 +27,8 @@ // Generic hash table for other cases // Resizing is pretty expensive here +// SHOULD widen small odd sizes + #include "../core.h" #include "../utils/hash.h" #include "../utils/talloc.h" @@ -510,5 +510,13 @@ 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; + if (TI(x,elType)==el_bit && RNK(x)==1) { + u64* xp = bitarr_ptr(x); + u64 x0 = 1 & *xp; + usz i = bit_find(xp, n, !x0); decG(x); + u64* rp; B r = m_bitarrv(&rp, 1 + (i