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