From 64d65ae837881292292d8a2608c000847f901f8b Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 18 Jul 2023 21:35:08 -0400 Subject: [PATCH] Never use generic dense compress methods if use_table: where is faster --- src/builtins/slash.c | 13 +++++++++---- src/singeli/src/slash.singeli | 13 ++++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/builtins/slash.c b/src/builtins/slash.c index 28265d19..3cb921ee 100644 --- a/src/builtins/slash.c +++ b/src/builtins/slash.c @@ -479,10 +479,15 @@ static B compress(B w, B x, usz wia, u8 xl, u8 xt) { TFREE(buf) #define COMPRESS_BLOCK(T) COMPRESS_BLOCK_PREP(T, ) #define WITH_SPARSE(W, CUTOFF, DENSE) { \ - i##W *xp=tyany_ptr(x), *rp; \ - if (wsum=wia/8 && groups_lt(wp,wia, wia/W)) r = compress_grouped(wp, x, wia, wsum, xt); \ + else { rp=m_tyarrv(&r,W/8,wsum,xt); COMPRESS_BLOCK(i##W); } \ + } \ break; } #if SINGELI #define DO(W) \ diff --git a/src/singeli/src/slash.singeli b/src/singeli/src/slash.singeli index d81e2ef7..54b9dfa6 100644 --- a/src/singeli/src/slash.singeli +++ b/src/singeli/src/slash.singeli @@ -95,7 +95,8 @@ def for_special_buffered{r, write_len}{vars,begin,sum,iter} = { } # Assumes w is trimmed, so the last 1 appears at index l-1 -def thresh{c, T} = 2 +def fast_where = hasarch{'X86_64'} & use_table +def thresh{c, T} = if (fast_where) 1 else 2 fn slash{c, T}(w:*u64, x:arg{c,T}, r:*T, l:u64, sum:u64) : void = { def bitp_get{arr, n} = (load{arr,n>>6} >> (n&63)) & 1 @for (i to l) { @@ -133,7 +134,9 @@ def topper{T, U, k, x} = { tup{top, inc} } -def thresh{c, T & hasarch{'X86_64'} & T<=(if (c) i8 else i32)} = 4 +def thresh{c, T & hasarch{'X86_64'} & T<=(if (c) i8 else i32)} = { + if (fast_where) 1 else 4 +} fn slash{c, T & hasarch{'X86_64'} & T<=(if (c) i8 else i32)}(w:*u64, x:arg{c,T}, r:*T, l:u64, sum:u64) : void = { def U = [16]u8 k1 := U**1 @@ -248,9 +251,9 @@ fn slash{c==0, T & (if (T==i8) use_table else T==i16)}(w:*u64, x:arg{c,T}, r:*T, } } -def thresh{c==0, T==i16 & hasarch{'X86_64'}} = 32 -def thresh{c==0, T==i32 & hasarch{'X86_64'}} = 16 -fn slash{c==0, T & hasarch{'X86_64'} & i16<=T & T<=i32}(w:*u64, x:arg{c,T}, r:*T, l:u64, sum:u64) : void = { +def thresh{c==0, T==i16 & hasarch{'X86_64'} & use_table} = 32 +def thresh{c==0, T==i32 & hasarch{'X86_64'} & use_table} = 16 +fn slash{c==0, T & hasarch{'X86_64'} & use_table & i16<=T & T<=i32}(w:*u64, x:arg{c,T}, r:*T, l:u64, sum:u64) : void = { def I = [16]i8 j := I**(if (T==i16) 0 else cast_i{i8,x}) def {top, inctop} = topper{T, I, 8, x}