From ec3154360459bd8a1414480854713b3981e769b3 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 5 Nov 2023 15:04:30 -0500 Subject: [PATCH] Vector Member-of search up to an offset of 4 --- src/singeli/src/search.singeli | 38 +++++++++++++++++++++++++++++++++ src/singeli/src/vecfold.singeli | 1 - 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/singeli/src/search.singeli b/src/singeli/src/search.singeli index 5689d391..83f9f612 100644 --- a/src/singeli/src/search.singeli +++ b/src/singeli/src/search.singeli @@ -371,6 +371,7 @@ fn hashtab{T, name}(rp:*rty{name}, ip:*T, m:usz, fp:*T, n:usz, links:ity{name}) def setm{found, i} = has_maxh |= found end := maxh>>sh # Clip trailing maxh if it shouldn't be in the table def usem{} = { + try_vec_memb{T, hash, sz+ext, sh, maxh, has_maxh, rp, fp, n, abort} if (has_maxh) { while (load{hash,end}!=maxh) ++end } else end += promote{T,ext} # Unreachable } @@ -496,6 +497,43 @@ fn hashtab{T, name}(rp:*rty{name}, ip:*T, m:usz, fp:*T, n:usz, links:ity{name}) i == m # Whether it finished } +def try_vec_memb{} = {} +def try_vec_memb{T, hash, hashlen, sh, maxh, has_maxh, rp, fp, n, done + & hasarch{'SSE4.2'} & T==u32} = { + # Hash h wants bin h>>sh, so the offset for h in slot i is (in infite-precision ints) + # i-h>>sh = i+((1<>sh = (((i+1)<>sh + # We maintain io = (i+1)< (o+k)<> sh + + def memb{test} = { + def R = i8; def rw = width{R}; def u = width{T}/rw + l := n/u + @for (r in *T~~rp over i to l) { + c := V**0 # Will combine u results to avoid folding too much + @unroll (f in fp+u*i over a to u) c |= V**(1<<(rw*a)) & test{f} + r = vfold{|, c} + } + @for (rp, fp over _ from u*l to n) rp = promote{R, homAny{test{fp}}} + goto{done} + } + if (max_off < vl) { + hp := *V~~(hash + maxh>>sh) + hv := load{hp} + store{hp, 0, hv &~ (hv == V**(maxh &- ~has_maxh))} + def test{x} = { + h := hash_val{x}; j := h>>sh + V**h == load{*V~~(hash+j), 0} + } + memb{test} + } +} + def exp_hash{T, name} = { export{merge{name,'_c2_hash',fmtnat{width{T}}}, hashtab{T, name}} } diff --git a/src/singeli/src/vecfold.singeli b/src/singeli/src/vecfold.singeli index f8b85b26..f0aadea2 100644 --- a/src/singeli/src/vecfold.singeli +++ b/src/singeli/src/vecfold.singeli @@ -1,5 +1,4 @@ # Fold associative/commutative operation across a register -# Used by squeeze.singeli, count.singeli def vfold{F, x:T & w128{T} & hasarch{'X86_64'}} = { c:= x