From 66c0fe041cd1424b1b14c935ce7065e7788858a1 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Fri, 4 Aug 2023 21:43:17 -0400 Subject: [PATCH] Get pext and popcount together, since generic pext emulation includes popc --- src/singeli/src/slash.singeli | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/singeli/src/slash.singeli b/src/singeli/src/slash.singeli index 995f4b22..caa87b5d 100644 --- a/src/singeli/src/slash.singeli +++ b/src/singeli/src/slash.singeli @@ -287,7 +287,7 @@ export{'si_2slash32', slash{1, i32}}; export{'si_thresh_2slash32', u64~~thresh{1 export{'si_2slash64', slash{1, i64}}; export{'si_thresh_2slash64', u64~~thresh{1, i64}} # pext, or boolean compress -fn pext{T}(x:T, m:T) { +def pext_popc{x:T, m:T} = { def w = width{T} def mod{a} = a % (1<> (o>>(sh-g) & s) - fold{|, b&s, each{gr, g*slice{iota{cdiv{w,g}},1}}} + pe := fold{|, b&s, each{gr, g*slice{iota{cdiv{w,g}},1}}} + tup{pe, w - o>>(w-g)} } -fn pext{T & hasarch{'PCLMUL'} & T==u64}(xs:T, ms:T) { +def pext_popc{xs:T, ms:T & hasarch{'PCLMUL'} & T==u64} = { def num = lb{width{T}} def vec{s} = make{[2]T, s, 0} m := vec{ms} @@ -346,18 +347,17 @@ fn pext{T & hasarch{'PCLMUL'} & T==u64}(xs:T, ms:T) { shift_at{m, p} shift_at{x, p} } - extract{x, 0} + tup{extract{x, 0}, popc{ms}} } -fn pext{T & hasarch{'BMI2'}}(x:T, m:T) = pext{x, m} +def pext_popc{x:T, m:T & hasarch{'BMI2'}} = tup{pext{x, m}, popc{m}} fn compress_bool(w:*u64, x:*u64, r:*u64, n:u64) : void = { cw:u64 = 0; # current word ro:u64 = 0; # offset in word where next bit should be written; never 64 @for (w, x over i to cdiv{n,64}) { - v := pext{u64}(x, w) - c := cast_i{u64, popcRand{w}} - cw|= v<= 64) { store{r, 0, cw}; ++r