From 8a551ab5ce99c9b8d2bceea20bdbb85e11d0c17a Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sun, 30 Oct 2022 21:00:35 -0400 Subject: [PATCH] =?UTF-8?q?Add=2032-bit=20hash=20table=20for=20Classify=20?= =?UTF-8?q?(=E2=8A=92)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/selfsearch.c | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) diff --git a/src/builtins/selfsearch.c b/src/builtins/selfsearch.c index 65ab5dc3..9cb9fca6 100644 --- a/src/builtins/selfsearch.c +++ b/src/builtins/selfsearch.c @@ -6,6 +6,18 @@ B not_c1(B t, B x); B shape_c1(B t, B x); B slash_c2(B t, B w, B x); +#if defined(__SSE4_2__) +static inline u32 hash32(u32 x) { return _mm_crc32_u32(0x973afb51, x); } +#else +// Murmur3 +static inline u32 hash32(u32 x) { + x ^= x >> 16; x *= 0x85ebca6b; + x ^= x >> 13; x *= 0xc2b2ae35; + x ^= x >> 16; + return x; +} +#endif + #define GRADE_UD(U,D) U #include "radix.h" u8 radix_offsets_2_u32(usz* c0, u32* v0, usz n) { @@ -237,7 +249,9 @@ B indexOf_c1(B t, B x) { #undef LOOKUP if (lw==5) { - if (n<32) { BRUTE(32); } + if (n<12) { BRUTE(32); } + B r; + i32* rp; r = m_i32arrv(&rp, n); i32* xp = tyany_ptr(x); i32 min=I32_MAX, max=I32_MIN; for (usz i = 0; i < n; i++) { @@ -247,13 +261,29 @@ B indexOf_c1(B t, B x) { } i64 dst = 1 + (max-(i64)min); if (dstsz) for (usz j=0; j