From e24d0bac634f1e97b9a1f44960710dd1ce2d69ac Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 14 Nov 2024 11:58:13 -0500 Subject: [PATCH] Extend SIMD counting to i16 in addition to i8 --- src/builtins/grade.h | 4 ++-- src/builtins/slash.c | 30 ++++++++++++++---------------- src/singeli/src/count.singeli | 8 +++++--- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/builtins/grade.h b/src/builtins/grade.h index be95c6fc..406a21e6 100644 --- a/src/builtins/grade.h +++ b/src/builtins/grade.h @@ -97,9 +97,9 @@ extern void (*const si_scan_min_i16)(int16_t* v0,int16_t* v1,uint64_t v2); if (e==n) {break;} k=e; \ } #define WRITE_SPARSE(T) WRITE_SPARSE_##T -extern i8 (*const avx2_count_i8)(usz*, i8*, u64, i8); +extern i8 (*const simd_count_i8)(usz*, i8*, u64, i8); #define SINGELI_COUNT_OR(T) \ - if (1==sizeof(T)) avx2_count_i8(c0o, (i8*)xp, n, -128); else + if (1==sizeof(T)) simd_count_i8(c0o, (i8*)xp, n, -128); else #else #define COUNT_THRESHOLD 16 #define WRITE_SPARSE(T) \ diff --git a/src/builtins/slash.c b/src/builtins/slash.c index 2934f9b1..07128741 100644 --- a/src/builtins/slash.c +++ b/src/builtins/slash.c @@ -865,12 +865,10 @@ B slash_im(B t, B x) { usz m=1<m/2) thrM("/⁼: Argument cannot contain negative numbers"); \ + SINGELI_COUNT(N) \ i32* rp; r = m_i32arrv(&rp, ria); vfor (usz i=0; im/2) thrM("/⁼: Argument cannot contain negative numbers"); #endif CASE_SMALL(8) CASE_SMALL(16) #undef CASE_SMALL -#undef SINGELI_COUNT_OR +#undef SINGELI_COUNT_ALLOC +#undef SINGELI_COUNT case el_i32: { i32* xp = i32any_ptr(x); IIND_INT(32) r = num_squeeze(r); break; } #undef IIND_INT case el_f64: { diff --git a/src/singeli/src/count.singeli b/src/singeli/src/count.singeli index 88b38c8d..1888b3f0 100644 --- a/src/singeli/src/count.singeli +++ b/src/singeli/src/count.singeli @@ -3,14 +3,14 @@ include './vecfold' if_inline (hasarch{'SSE2'}) { fn sum_vec{T}(v:T) = vfold{+, fold{+, mzip128{v, T**0}}} - def fold_addw{v:T=[_](u8)} = sum_vec{T}(v) + def fold_addw{v:T=[_]E if E<=u16} = sum_vec{T}(v) } def inc{ptr, ind, v} = store{ptr, ind, v + load{ptr, ind}} def inc{ptr, ind} = inc{ptr, ind, 1} # Write counts /⁼x to tab and return ⌈´x -fn count{T}(tab:*usz, x:*T, n:u64, min_allowed:T) : T = { +fn count{T}(tab:*usz, xp:*void, n:u64, min_allowed:T) : T = { def vbits = arch_defvw def vec = vbits/width{T} def uT = ty_u{T} @@ -18,6 +18,7 @@ fn count{T}(tab:*usz, x:*T, n:u64, min_allowed:T) : T = { def block = (2048*8) / vbits # Target vectors per block def b_max = block + block/4 # Last block max length assert{b_max < 1<