From 4b0f105a7f4d82f104c41e5e67320d3bf663c174 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Tue, 18 Jun 2024 14:05:16 -0400 Subject: [PATCH] =?UTF-8?q?Implement=20short-row=20num=E2=8A=8F=CB=98bool?= =?UTF-8?q?=20(including=20=E2=8A=A3=CB=9D=CB=98=20=E2=8A=A2=CB=9D=CB=98)?= =?UTF-8?q?=20with=20fold=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/cells.c | 9 ++++++++- src/singeli/src/fold.singeli | 25 ++++++++++++++++++++----- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/builtins/cells.c b/src/builtins/cells.c index 244f5e0e..316faa8e 100644 --- a/src/builtins/cells.c +++ b/src/builtins/cells.c @@ -177,6 +177,7 @@ NOINLINE B leading_axis_arith(FC2 fc2, B w, B x, usz* wsh, usz* xsh, ur mr) { // // fast special-case implementations +extern void (*const si_select_cells_bit_lt64)(uint64_t*,uint64_t*,uint32_t,uint32_t,uint32_t); // from fold.c (fold.singeli) static NOINLINE B select_cells(usz n, B x, usz cam, usz k, bool leaf) { // n {leaf? <∘⊑; ⊏}⎉¯k x; TODO probably can share some parts with takedrop_highrank and/or call ⊏? ur xr = RNK(x); assert(xr>1 && k loop_T{u16, {x} => extract{get{x}}}} } else { # generic width<64 {e0, d} := unaligned_spaced_mask_mod{l} - e := e0 << (l-1) # ending bit of each row - c:u64 = 0 # carry, use depends on algorithm + el:= e0 << (l-1) # ending bit of each row + e := if (same{off,-1}) el else e0< a>>o} + def run_loop4{m, t, loop} = loop{{x} => x<<(l-1-o)} + def pext_res{x, e, c} = pext{x, e} + def mult_in{x, e, c} = tup{x, {r}=>r} + def id{x} = x + fold_rows_bit_lt64{ + {a,b}=>a, run_loop2, run_loop4, pext_res, mult_in, o, id, id, id, + xp, rp, n, l + } +} fn xor_words(init:u64, x:*u64, l:usz):u64 = { @for (x over l) init ^= x @@ -222,7 +236,7 @@ fn xor_rows_bit(xp:*u64, rp:*u64, n:usz, l:usz, eq:u1) : void = { def pext_res{x, e, c} = pext{pext_in{x, e, c}, e} def mult_in{x, e, c} = tup{pext_in{x, e, c}, {r}=>r} fold_rows_bit_lt64{ - ^, run_loop2, run_loop4, pext_res, mult_in, {x}=>x, ^{rx,.}, ^{rx,.}, + ^, run_loop2, run_loop4, pext_res, mult_in, -1, {x}=>x, ^{rx,.}, ^{rx,.}, xp, rp, n, l } } else { @@ -277,7 +291,7 @@ fn or_rows_bit(xp:*u64, rp:*u64, n:usz, l:usz, op_and:u1) : void = { } def xx = ^{-promote{u64, op_and}, .} fold_rows_bit_lt64{ - |, run_loop2, run_loop4, pext_res, mult_in, xx, xx, {r}=>r, + |, run_loop2, run_loop4, pext_res, mult_in, -1, xx, xx, {r}=>r, xp, rp, n, l } return{} @@ -316,3 +330,4 @@ fn or_rows_bit(xp:*u64, rp:*u64, n:usz, l:usz, op_and:u1) : void = { } export{'si_xor_rows_bit', xor_rows_bit} export{'si_or_rows_bit', or_rows_bit} +export{'si_select_cells_bit_lt64', select_rows_bit_lt64}