From ac4729bb29709e6fce4adf89fbeb130df05ce611 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Mon, 19 Sep 2022 19:31:44 -0400 Subject: [PATCH] Use grouped compress for all byte sizes if the number of groups is small enough --- src/builtins/slash.c | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/src/builtins/slash.c b/src/builtins/slash.c index a6b454c7..1eda65be 100644 --- a/src/builtins/slash.c +++ b/src/builtins/slash.c @@ -313,6 +313,21 @@ static B where(B x, usz xia, u64 s) { return r; } +// Is the number of values switches in w at most max? +static bool groups_lt(u64* wp, usz len, usz max) { + usz r = 0; + u64 prev = 0; + usz l = (len-1)/64+1; // assume trailing bits are zeroed out + usz b = 1<<8; + for (usz i = 0; i < l; ) { + for (usz e = l-i>63; + } + if (r > max) return 0; + } + return 1; +} + extern B take_c2(B, B, B); static B compress(B w, B x, usz wia, u8 xl, u8 xt) { u64* wp = bitarr_ptr(w); @@ -375,8 +390,9 @@ static B compress(B w, B x, usz wia, u8 xl, u8 xt) { TFREE(buf) #define WITH_SPARSE(W, CUTOFF, DENSE) { \ i##W *xp=tyany_ptr(x), *rp; \ - if (wsum>=wia/CUTOFF) { DENSE; } \ - else { rp=m_tyarrv(&r,W/8,wsum,xt); COMPRESS_BLOCK(i##W); } \ + if (wsum=wia/8 && groups_lt(wp,wia, wia/16)) r = compress_grouped(wp, x, wia, wsum, xt); \ + else { T* xp=tyany_ptr(x); T* rp=m_tyarrv(&r,sizeof(T),wsum,xt); COMPRESS_BLOCK(T); break; } \ + break; + case 5: BLOCK_OR_GROUPED(i32) + case 6: if (TI(x,elType)!=el_B) { BLOCK_OR_GROUPED(u64) } + #undef BLOCK_OR_GROUPED else { B xf = getFillQ(x); B* xp = arr_bptr(x);