From 5f1c677d480c9518363325168b53f56bc1536ce4 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Thu, 20 Jun 2024 11:00:57 -0400 Subject: [PATCH] =?UTF-8?q?Support=20=E2=88=A7=E2=88=A8=20synonyms=20in=20?= =?UTF-8?q?fold=5Frows=5Fbit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/fold.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/builtins/fold.c b/src/builtins/fold.c index ac7100f6..169e2068 100644 --- a/src/builtins/fold.c +++ b/src/builtins/fold.c @@ -21,12 +21,11 @@ // TRIED scan-based version, faster for width 3 only // COULD have bit-twiddling versions of +˝˘ on very short rows // >64: popcount, boundary corrections (clang auto-vectorizes) -// ∨∧≠=, rows <64: extract from scan or windowed op +// ∨∧≠= and synonyms, rows <64: extract from scan or windowed op // Dedicated auto-vectorizing code for sizes 2, 4 // Extract is generic with multiplies or BMI2 (SHOULD add SIMD) // COULD use CLMUL for faster windowed ≠ -// ∨∧: -// SHOULD handle ∨∧ synonyms for boolean fold on rows +// ∨∧ and synonyms: // Multiples of 8 <256: comparison function, recurse if needed // Rows 64f)->flags-1; if (rtid==n_add) return sum_rows_bit(x, n, m); #if SINGELI - if (rtid==n_ne|rtid==n_eq|rtid==n_or|rtid==n_and) { - bool andor = rtid==n_or|rtid==n_and; + bool is_or = rtid==n_or |rtid==n_ceil; + bool andor = rtid==n_and|rtid==n_floor|rtid==n_mul|is_or; + if (rtid==n_ne|rtid==n_eq|andor) { if (andor && m < 256) while (m%8 == 0) { usz f = CTZ(m|32); m >>= f; usz c = m*n; u64* yp; B y = m_bitarrv(&yp, c); u8 e = el_i8 + f-3; - CmpASFn cmp = rtid==n_or ? CMP_AS_FN(ne, e) : CMP_AS_FN(eq, e); - CMP_AS_CALL(cmp, yp, bitarr_ptr(x), m_f64((rtid==n_or)-1), c); + CmpASFn cmp = is_or ? CMP_AS_FN(ne, e) : CMP_AS_FN(eq, e); + CMP_AS_CALL(cmp, yp, bitarr_ptr(x), m_f64(is_or-1), c); decG(x); if (m==1) return y; x = y; } u64* xp = bitarr_ptr(x); u64* rp; B r = m_bitarrv(&rp, n); - if (andor) si_or_rows_bit(xp, rp, n, m, rtid==n_and); + if (andor) si_or_rows_bit(xp, rp, n, m, !is_or); else si_xor_rows_bit(xp, rp, n, m, rtid==n_eq); decG(x); return r; }