From 3584ebd7a6b9e97049cadf66010be08bece6b6b4 Mon Sep 17 00:00:00 2001 From: Marshall Lochbaum Date: Sat, 30 Dec 2023 21:24:39 -0500 Subject: [PATCH] Non-BMI2 bit interleaving implementation --- src/builtins/transpose.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/builtins/transpose.c b/src/builtins/transpose.c index a071d407..b6a921cb 100644 --- a/src/builtins/transpose.c +++ b/src/builtins/transpose.c @@ -2,7 +2,7 @@ // Transpose // One length-2 axis: dedicated code -// Boolean: pdep for height 2; pext for width 2 +// Boolean: pdep or emulation for height 2; pext for width 2 // SHOULD use a generic implementation if BMI2 not present // SHOULD optimize other short lengths with pdep/pext and shuffles // Boolean 𝕩: convert to integer @@ -40,6 +40,9 @@ #include "../utils/calls.h" #ifdef __BMI2__ + #if !SLOW_PDEP + #define FAST_PDEP 1 + #endif #include #if USE_VALGRIND #define _pdep_u64 vg_pdep_u64 @@ -66,12 +69,27 @@ typedef void (*TranspFn)(void*,void*,u64,u64,u64,u64); #endif -#ifdef __BMI2__ static void interleave_bits(u64* rp, void* x0v, void* x1v, usz n) { u32* x0 = (u32*)x0v; u32* x1 = (u32*)x1v; - for (usz i=0; i>xlw && csz<=8) { // Require CPU-sized cells void* rv; @@ -125,12 +141,12 @@ static Arr* transpose_noshape(B* px, usz ia, usz w, usz h) { r=a(qWithFill(p.b, xf)); } else if (xe==el_bit) { - #ifdef __BMI2__ if (h==2) { u64* rp; r=m_bitarrp(&rp, ia); Arr* x1o = TI(x,slice)(inc(x),w,w); interleave_bits(rp, bitarr_ptr(x), ((TyArr*)x1o)->a, ia); mm_free((Value*)x1o); + #ifdef __BMI2__ } else if (w==2) { u64* xp = bitarr_ptr(x); u64* r0; r=m_bitarrp(&r0, ia); @@ -142,9 +158,8 @@ static Arr* transpose_noshape(B* px, usz ia, usz w, usz h) { } bit_cpyN(r0, h, r1, 0, h); TFREE(r1); - } else #endif - { + } else { *px = x = taga(cpyI8Arr(x)); xe=el_i8; void* rv = m_tyarrp(&r,elWidth(xe),ia,el2t(xe)); void* xv = tyany_ptr(x);