From b2758d355c709f44805ef9dfbcf985a8cf9019ba Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Wed, 14 Aug 2024 09:34:19 -0400 Subject: [PATCH] k/bool cleanup and implementation comments --- src/builtins/slash.c | 9 +++++++-- src/singeli/src/replicate.singeli | 8 +++----- src/singeli/src/spaced.singeli | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/builtins/slash.c b/src/builtins/slash.c index f108c7f8..5e883113 100644 --- a/src/builtins/slash.c +++ b/src/builtins/slash.c @@ -38,8 +38,13 @@ // COULD consolidate refcount updates for nested 𝕩 // Replicate by constant -// Boolean uses pdep, ≠`, or overwriting -// SHOULD make a shift/mask replacement for pdep +// Boolean uses specialized small-𝕨 methods, ≠`, or overwriting +// 𝕨≤64: Singeli generic and SIMD methods +// 𝕨=2,4,8: Various shift, shuffle, and zip-based loops +// odd 𝕨: Modular permutation +// COULD use pdep or similar to avoid overhead on small results +// Otherwise, factor into power of 2 times odd +// COULD fuse 2×odd, since 2/odd/ has a larger intermediate // Other typed 𝕩 uses +`, or lots of Singeli // Fixed shuffles, factorization, partial shuffles, self-overlapping // Otherwise, cell-by-cell copying diff --git a/src/singeli/src/replicate.singeli b/src/singeli/src/replicate.singeli index c96fd248..4759908b 100644 --- a/src/singeli/src/replicate.singeli +++ b/src/singeli/src/replicate.singeli @@ -394,9 +394,9 @@ def rep_const_bool_div8{wv, x, r, nw if hasarch{'SSE2'}} = { def __shl{x:(V), a} = V~~(H~~x << a) def __shr{x:(V), a} = V~~(H~~x >> a) - def {output, done, flush} = get_boolvec_writer{V, r, nw} + def {output, check_done, flush} = get_boolvec_writer{V, r, nw} def run24{x, get_halves} = { - i:usz = 0; while (1) { + i:usz = 0; while (1) { check_done{} xv := load{*V~~(x+i)}; ++i def getr = zip128{...get_halves{xv}, .} output{V~~getr{0}} @@ -407,7 +407,7 @@ def rep_const_bool_div8{wv, x, r, nw if hasarch{'SSE2'}} = { {xv} => { p := pre{xv}; tup{exh{p}, exh{p>>sh}} } } def run8{rep_bytes} = { - i:usz = 0; while (1) { + i:usz = 0; while (1) { check_done{} xh := load{*[16]u8~~(*ty_u{vl}~~x + i)}; ++i xv := if (avx2) pair{xh, xh} else xh xe := rep_bytes{xv} @@ -472,8 +472,6 @@ def sel_imm{V=([16]u8), x:X, {...inds}} = { sel{V, x, make{I, cycle{n, inds}}} } -def advance_spaced_mask{k, m, sh} = m<<(k-sh) | m>>sh - # Data for the permutation that sends bit i to k*i % width{T} def modperm_dat{T, k} = { def w = width{T} diff --git a/src/singeli/src/spaced.singeli b/src/singeli/src/spaced.singeli index ff477cb3..acb926a0 100644 --- a/src/singeli/src/spaced.singeli +++ b/src/singeli/src/spaced.singeli @@ -12,3 +12,5 @@ def unaligned_spaced_mask_mod{l:T} = { def d = cast_i{T, ctz{m}} # = 64%l tup{m>>d | m<<(l-d), d} } + +def advance_spaced_mask{k, m, sh} = m<<(k-sh) | m>>sh