From 93e1262864a9a7a7d4bdc60f4277dff7ddc6ee3b Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 18 Jul 2023 16:52:08 -0400 Subject: [PATCH] Avoid using popcount primitive in Singeli if POPCNT isn't present --- src/singeli/src/slash.singeli | 45 +++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/src/singeli/src/slash.singeli b/src/singeli/src/slash.singeli index 2bc8e3f2..11c6a324 100644 --- a/src/singeli/src/slash.singeli +++ b/src/singeli/src/slash.singeli @@ -35,12 +35,19 @@ def loadu{p:T & *u64==T} = emit{eltype{T}, 'loadu_u64', p} def popcRand{x:T & isint{T} & width{T}==64} = emit{u8, 'rand_popc64', x} # under valgrind, return a random result in the range of possible ones def popcRand{x:T & isint{T} & width{T}<=32} = emit{u8, 'rand_popc64', x} -def maketab{l,w} = { # Table from l bits to w-bit indices - def lw = l*w - fold{{t,k} => join{each{tup,t,k+(t< join{each{tup, t, k + t<>(64-w) + 1) & (1<>4} + def rn = if (has_popc) r+popc{w} else 0 + def step{w} = { + i := load{tab, w} + storeu{*u64~~r, 0, j + i} + r += popc_alt{w, i, tw} + j += inc } - j += inc - r += pc + if (tw==8) { step{w} } + else { step{w&0xf}; step{w>>4} } + if (has_popc) r = rn # Shorter dependency chain } } @@ -237,9 +246,9 @@ fn slash{c==1, T & T<=i16 & hasarch{'SSSE3'} & use_table}(wp:*u64, x:arg{c,T}, r def tw = width{T} def V = [16]i8 @for_special_buffered{r,8} (w in *u8~~wp over i to sum) { - pc := popc{w} - ind := load{itab, w}; def I = type{ind} - s := V~~make{[2]I, ind,0} + ind := load{itab, w} + pc := popc_alt{w, ind, 8} + s := V~~make{[2]u64, ind,0} if (T==i16) { s+=s; s = V~~unpackLo{s, s+V**1} } res := sel{V, load{*V~~(x+8*i)}, s} if (T==i8) store{*u64~~r, 0, extract{[2]u64~~res, 0}}