From 4e9745688b2118e28bc48a49b3b98bdca7382511 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 7 Aug 2023 13:44:52 -0400 Subject: [PATCH] Use generic boolean Compress as the sparse case with Singeli --- src/builtins/slash.c | 7 ++++--- src/singeli/src/slash.singeli | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/builtins/slash.c b/src/builtins/slash.c index 47dcf595..be0aca20 100644 --- a/src/builtins/slash.c +++ b/src/builtins/slash.c @@ -442,8 +442,10 @@ static B compress(B w, B x, usz wia, u8 xl, u8 xt) { u64* xp = bitarr_ptr(x); u64* rp; r = m_bitarrv(&rp,wsum); #if SINGELI - si_compress_bool(wp, xp, rp, wia); - #else + if (wsum>=wia/si_thresh_compress_bool) { + si_compress_bool(wp, xp, rp, wia); break; + } + #endif u64 o = 0; usz j = 0; for (usz i=0; i>q; - #endif break; } #define COMPRESS_BLOCK_PREP(T, PREP) \ diff --git a/src/singeli/src/slash.singeli b/src/singeli/src/slash.singeli index 4ccc1be0..e73ccbc2 100644 --- a/src/singeli/src/slash.singeli +++ b/src/singeli/src/slash.singeli @@ -289,7 +289,8 @@ export{'si_2slash64', slash{1, i64}}; export{'si_thresh_2slash64', u64~~thresh{1 def scalwidth{T} = if (isvec{T}) elwidth{T} else width{T} # pext, or boolean compress -def pext_width{} = if (hasarch{'AVX2'}) 4 else 1 +def pext_width{} = if (hasarch{'AVX2'}) 4 else 1 +def thresh_bool{} = if (hasarch{'AVX2'}) 128 else 16 def pext_popc{x:T, m:T} = { def w = scalwidth{T} def scal{v} = if (isvec{T}) T**v else v @@ -354,7 +355,8 @@ def pext_popc{x:T, m:T} = { tup{pe, scal{w} - z} } -def pext_width{..._ & hasarch{'PCLMUL'} > hasarch{'AVX2'}} = 2 +def pext_width {..._ & hasarch{'PCLMUL'} > hasarch{'AVX2'}} = 2 +def thresh_bool{..._ & hasarch{'PCLMUL'} > hasarch{'AVX2'}} = 32 def pext_popc{x0:V, m0:V & hasarch{'PCLMUL'} & V==[2]u64} = { def clmul{a, b} = zipLo{...@collect (j to 2) clmul{a,b,j}} m := m0 @@ -373,7 +375,8 @@ def pext_popc{x0:V, m0:V & hasarch{'PCLMUL'} & V==[2]u64} = { tup{x, @collect (j to 2) popc{extract{m0,j}}} } -def pext_width{..._ & hasarch{'BMI2'}} = 1 +def pext_width {..._ & hasarch{'BMI2'}} = 1 +def thresh_bool{..._ & hasarch{'BMI2'}} = 512 def pext_popc{x:T, m:T & hasarch{'BMI2'} & T==u64} = tup{pext{x, m}, popc{m}} fn compress_bool(w:*u64, x:*u64, r:*u64, n:u64) : void = { @@ -412,3 +415,4 @@ fn compress_bool(w:*u64, x:*u64, r:*u64, n:u64) : void = { } export{'si_compress_bool', compress_bool} +export{'si_thresh_compress_bool', u64~~thresh_bool{}}