From 1fa00c9c6f589b6f363821f1080f34023abb5987 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 8 Jul 2023 17:20:31 -0400 Subject: [PATCH] Update bins implementation comments --- src/builtins/grade.h | 28 ++++++++++++++++++++++------ src/singeli/src/bins.singeli | 2 ++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/builtins/grade.h b/src/builtins/grade.h index 58466ac5..47f80e79 100644 --- a/src/builtins/grade.h +++ b/src/builtins/grade.h @@ -19,15 +19,31 @@ // SHOULD widen odd cell sizes under 8 bytes in sort and grade // Bins +// Length 0 or 1 𝕨: trivial, or comparison +// Stand-alone 𝕨 sortedness check +// SHOULD vectorize sortedness check on lists of numbers // Mixed integer and character arguments gives all 0 or ≠𝕨 -// Integers and characters: 4-byte branchless binary search +// Non-Singeli, integers and characters: +// 4-byte branchless binary search, 4-byte output +// SHOULD support fast character searches +// SHOULD special-case boolean 𝕨 or 𝕩 +// Different widths: widen narrower argument +// SHOULD narrow wider-type 𝕩 if it isn't much shorter +// SHOULD trim wider-type 𝕨 and possibly narrow +// Same-width numbers: +// Output type based on ≠𝕨 +// Short 𝕨: vector binary search (then linear on extra lanes) +// 1- or 2-byte type, long enough 𝕩: lookup table from ⌈` +// Binary gallops to skip long repeated elements of 𝕨 +// 1-byte, no duplicates or few uniques: vector bit-table lookup +// General: interleaved branchless binary search +// COULD start interleaved search with a vector binary round // General case: branching binary search -// SHOULD implement f64 branchless binary search -// SHOULD interleave multiple branchless binary searches -// SHOULD specialize bins on equal types at least -// SHOULD implement table-based ⍋⍒ for small-range 𝕨 -// SHOULD special-case short 𝕨 +// COULD trim 𝕨 based on range of 𝕩 +// COULD optimize small-range 𝕨 with small-type methods // SHOULD partition 𝕩 when 𝕨 is large +// COULD interpolation search for large 𝕩 and short 𝕨 +// COULD use linear search and galloping for sorted 𝕩 #define GRADE_CAT(N) CAT(GRADE_UD(gradeUp,gradeDown),N) #define GRADE_NEG GRADE_UD(,-) diff --git a/src/singeli/src/bins.singeli b/src/singeli/src/bins.singeli index 5f47e52e..ab04ddbb 100644 --- a/src/singeli/src/bins.singeli +++ b/src/singeli/src/bins.singeli @@ -126,6 +126,7 @@ fn write_indices{I,T}(t:*I, w:*T, n:u64) : void = { @for (w over j from i to n) store{t, w, j+1} goto{break} } else if ((wi = load{w, i}) == load{w, id}) { + # Gallop md := n - i d2 := undefined{u64} while ((d2=d+d) < md and wi == load{w, i + d2}) d = d2 @@ -236,6 +237,7 @@ def bins_vectab_i8{up, w, wn, x, xn, rp, t0, t, done & hasarch{'AVX2'}} = { setlabel{no_bittab} } +# Binary search within vector registers def bin_search_vec{T, up, w:*T, wn, x:*T, xn, rp, maxwn & hasarch{'AVX2'}} = { assert{wn > 1}; assert{wn < maxwn} def wd = width{T}