diff --git a/build/src/build.bqn b/build/src/build.bqn index d6dcb1cc..4e8982f3 100755 --- a/build/src/build.bqn +++ b/build/src/build.bqn @@ -201,6 +201,8 @@ po ← { # parsed options args∾↩ GetOpt "f" args∾↩ GetOpt "CCFLAGS" + args∾↩ (singeli∧arch≡ "x86-64") / ⟨"-DSINGELI_X86_64"⟩ + args∾↩ (singeli∧arch≡"aarch64") / ⟨"-DSINGELI_NEON"⟩ args∾↩ ( wasm) / ⟨"-DWASM"⟩ args∾↩ ( wasi) / ⟨"-DWASI", "-DNO_MMAP", "-DCATCH_ERRORS=0", "-D_WASI_EMULATED_MMAN", "--target=wasm32-wasi"⟩ args∾↩ ( emcc) / ⟨"-DEMCC", "-O3"⟩ @@ -464,7 +466,7 @@ cachedBin‿linkerCache ← { ⟨"src/jit/", "nvm.c"⟩ ⟨"src/utils/", "utf.c", "hash.c", "file.c", "mut.c", "each.c", "bits.c"⟩ ⟩ - singeliMap ← ⟨ + singeliMap ← {po.arch≡"aarch64"? 𝕩/˜(1⊑¨𝕩)∊"cmp"‿"bits"‿"equal"; 𝕩} ⟨ "src/core/stuff.c"‿"equal", "src/utils/mut.c"‿"copy", "src/utils/bits.c"‿"bits" "src/builtins/arithd.c"‿"dyarith", "src/builtins/cmp.c"‿"cmp", "src/builtins/squeeze.c"‿"squeeze" "src/builtins/select.c"‿"select", "src/builtins/fold.c"‿"fold", "src/builtins/scan.c"‿"scan" diff --git a/makefile b/makefile index 81b578cf..10266c26 100644 --- a/makefile +++ b/makefile @@ -141,7 +141,7 @@ else NOWARN = -Wno-parentheses endif -ALL_CC_FLAGS = -std=gnu11 -Wall -Wno-unused-function -fms-extensions -ffp-contract=off -fno-math-errno $(CCFLAGS) $(f) $(i_f) $(NOWARN) -DBYTECODE_DIR=$(BYTECODE_DIR) -DSINGELI=$(i_singeli) -DFFI=$(i_FFI) $(i_LIBS_CC) +ALL_CC_FLAGS = -std=gnu11 -Wall -Wno-unused-function -fms-extensions -ffp-contract=off -fno-math-errno $(CCFLAGS) $(f) $(i_f) $(NOWARN) -DBYTECODE_DIR=$(BYTECODE_DIR) -DSINGELI=$(i_singeli) -DSINGELI_X86_64=$(i_singeli) -DFFI=$(i_FFI) $(i_LIBS_CC) ALL_LD_FLAGS = $(LDFLAGS) $(lf) $(i_lf) $(i_PIE) $(i_LIBS_LD) j=4 diff --git a/src/builtins/arithd.c b/src/builtins/arithd.c index 0a1ce8da..cf143c23 100644 --- a/src/builtins/arithd.c +++ b/src/builtins/arithd.c @@ -21,7 +21,7 @@ B atan2_c2(B, B, B); typedef void (*AndBytesFn)(u8*, u8*, u64, u64); -#if SINGELI +#if SINGELI_X86_64 #include "../singeli/c/arithdDispatch.c" static AndBytesFn andBytes_fn = avx2_andBytes; #else @@ -138,7 +138,7 @@ typedef void (*AndBytesFn)(u8*, u8*, u64, u64); #undef GC2f - #if SINGELI + #if SINGELI_X86_64 #define AA_DISPATCH(NAME) FORCE_INLINE B NAME##_AA(B t, B w, B x) { return dyArith_AA(&NAME##DyTableAA, w, x); } AA_DISPATCH(add) AA_DISPATCH(or) AA_DISPATCH(sub) diff --git a/src/builtins/fold.c b/src/builtins/fold.c index 4c847883..44056167 100644 --- a/src/builtins/fold.c +++ b/src/builtins/fold.c @@ -14,7 +14,7 @@ #include "../core.h" #include "../builtins.h" -#if SINGELI +#if SINGELI_X86_64 #define SINGELI_FILE fold #include "../utils/includeSingeli.h" #endif @@ -91,7 +91,7 @@ B sum_c1(B t, B x) { } r += s; } else { - #if SINGELI + #if SINGELI_X86_64 r = avx2_sum_f64(xv, ia); #else r=0; for (usz i=0; i) } DEF_MIN_MAX(i8) DEF_MIN_MAX(i16) DEF_MIN_MAX(i32) -#if SINGELI +#if SINGELI_X86_64 static f64 min_f64(void* xv, usz ia) { return avx2_fold_min_f64(xv,ia); } static f64 max_f64(void* xv, usz ia) { return avx2_fold_max_f64(xv,ia); } #else diff --git a/src/builtins/grade.h b/src/builtins/grade.h index 48da6f19..49410350 100644 --- a/src/builtins/grade.h +++ b/src/builtins/grade.h @@ -61,7 +61,7 @@ rp[j] = xi; \ } -#if SINGELI +#if SINGELI_X86_64 extern void (*const avx2_scan_max_i8)(int8_t* v0,int8_t* v1,uint64_t v2); extern void (*const avx2_scan_min_i8)(int8_t* v0,int8_t* v1,uint64_t v2); extern void (*const avx2_scan_max_i16)(int16_t* v0,int16_t* v1,uint64_t v2); @@ -227,7 +227,7 @@ B SORT_C1(B t, B x) { #undef SORT_C1 #undef INSERTION_SORT #undef COUNTING_SORT -#if SINGELI +#if SINGELI_X86_64 #undef WRITE_SPARSE_i8 #undef WRITE_SPARSE_i16 #endif diff --git a/src/builtins/radix.h b/src/builtins/radix.h index bcd68f7f..2a8e8900 100644 --- a/src/builtins/radix.h +++ b/src/builtins/radix.h @@ -11,7 +11,7 @@ #define RDX_SUM_2(T) GRADE_UD(c1[0]=0;,) T s0=0, s1=0; for(usz j=0;j<256;j++) { RDX_PRE(0); RDX_PRE(1); } #define RDX_SUM_4(T) GRADE_UD(c1[0]=c2[0]=c3[0]=0;,) T s0=0, s1=0, s2=0, s3=0; for(usz j=0;j<256;j++) { RDX_PRE(0); RDX_PRE(1); RDX_PRE(2); RDX_PRE(3); } -#if SINGELI +#if SINGELI_X86_64 extern void (*const avx2_scan_pluswrap_u8)(uint8_t* v0,uint8_t* v1,uint64_t v2,uint8_t v3); extern void (*const avx2_scan_pluswrap_u32)(uint32_t* v0,uint32_t* v1,uint64_t v2,uint32_t v3); #define RADIX_SUM_1_u8 avx2_scan_pluswrap_u8 (c0,c0, 256,0); @@ -29,7 +29,7 @@ extern void (*const avx2_scan_pluswrap_u32)(uint32_t* v0,uint32_t* v1,uint64_t v #define RADIX_SUM_4_u32 RDX_SUM_4(u32) #endif -#if SINGELI && !USZ_64 +#if SINGELI_X86_64 && !USZ_64 #define RADIX_SUM_1_usz avx2_scan_pluswrap_u32(c0,c0, 256,0); #define RADIX_SUM_2_usz avx2_scan_pluswrap_u32(c0,c0,2*256,0); #define RADIX_SUM_4_usz avx2_scan_pluswrap_u32(c0,c0,4*256,0); diff --git a/src/builtins/scan.c b/src/builtins/scan.c index 2099c2c2..21c83b77 100644 --- a/src/builtins/scan.c +++ b/src/builtins/scan.c @@ -9,7 +9,7 @@ static u64 vg_rand(u64 x) { return x; } #endif -#if SINGELI +#if SINGELI_X86_64 #define SINGELI_FILE scan #include "../utils/includeSingeli.h" #if __PCLMUL__ @@ -22,7 +22,7 @@ static u64 vg_rand(u64 x) { return x; } B scan_ne(B x, u64 p, u64 ia) { // consumes x u64* xp = bitarr_ptr(x); u64* rp; B r=m_bitarrv(&rp,ia); -#if SINGELI && __PCLMUL__ +#if SINGELI_X86_64 && __PCLMUL__ clmul_scan_ne(p, xp, rp, BIT_N(ia)); #else for (usz i = 0; i < BIT_N(ia); i++) { @@ -75,7 +75,7 @@ B scan_add_bool(B x, u64 ia) { // consumes x } else { void* rp = m_tyarrv(&r, elWidth(re), ia, el2t(re)); #define SUM_BITWISE(T) { T c=0; for (usz i=0; i= len/8) bmipopc_1slash16(src, (i16*)dst, len); #else if (sum >= len/4+len/8) WHERE_DENSE(src, dst, len, 0); @@ -299,7 +299,7 @@ static B where(B x, usz xia, u64 s) { u64* xp = bitarr_ptr(x); usz q=xia%64; if (q) xp[xia/64] &= ((u64)1<= xia/8) { i16* rp = m_tyarrvO(&r, 2, s, t_i16arr, 16); bmipopc_1slash16(xp, rp, xia); @@ -329,7 +329,7 @@ static B where(B x, usz xia, u64 s) { } } } else if (xia <= (usz)I32_MAX+1) { - #if SINGELI && defined(__BMI2__) + #if SINGELI_X86_64 && defined(__BMI2__) i32* rp; r = m_i32arrv(&rp, s); #else i32* rp = m_tyarrvO(&r, 4, s, t_i32arr, 4); @@ -344,7 +344,7 @@ static B where(B x, usz xia, u64 s) { } else { bs = bit_sum(xp,b); } - #if SINGELI && defined(__BMI2__) + #if SINGELI_X86_64 && defined(__BMI2__) if (bs >= b/8+b/16) { bmipopc_1slash16(xp, buf, b); for (usz j=0; jia = wsum; u64 cw = 0; // current word u64 ro = 0; // offset in word where next bit should be written; never 64 @@ -549,7 +549,7 @@ static B compress(B w, B x, usz wia, u8 xl, u8 xt) { else if (groups_lt(wp,wia, wia/128)) r = compress_grouped(wp, x, wia, wsum, xt); \ else { DENSE; } \ break; } - #if SINGELI + #if SINGELI_X86_64 case 3: WITH_SPARSE( 8, 32, rp=m_tyarrvO(&r,1,wsum,xt, 8); bmipopc_2slash8 (wp, xp, rp, wia); FINISH_OVERALLOC_A(r, wsum, 8)) case 4: WITH_SPARSE(16, 16, rp=m_tyarrvO(&r,2,wsum,xt, 16); bmipopc_2slash16(wp, xp, rp, wia); FINISH_OVERALLOC_A(r, wsum*2, 16)) #else @@ -606,7 +606,7 @@ static B compress(B w, B x, usz wia, u8 xl, u8 xt) { #define SUM_CORE(T, WV, PREP, INC) \ SCAN_CORE(WV, PREP; rp[ij]+=INC, , PLUS_SCAN(T)) -#if SINGELI +#if SINGELI_X86_64 #define IND_BY_SCAN \ SCAN_CORE(xp[j], rp[ij]=j, rp[k]=j, avx2_scan_max_i32(rp+k,rp+k,e-k)) #else @@ -883,7 +883,7 @@ B slash_c2(B t, B w, B x) { u8 xk = xl-3; void* rv = m_tyarrv(&r, 1< 1) goto r_x; else goto mostBit; } case el_i16: { or = avx2_squeeze_i16(i16any_ptr(x), ia); if(or> I8_MAX) goto r_x; else goto mostI8; } case el_i32: { or = avx2_squeeze_i32(i32any_ptr(x), ia); if(or> I16_MAX) goto r_x; else goto mostI16; } @@ -65,7 +65,7 @@ B num_squeeze(B x) { B* xp = arr_bptr(x); if (xp==NULL) goto r_f; - #if SINGELI + #if SINGELI_X86_64 or = avx2_squeeze_numB(xp, ia); if (-2==(i32)or) goto r_x; if (-1==(i32)or) goto r_f64; @@ -109,7 +109,7 @@ B chr_squeeze(B x) { i32 or = 0; switch(xe) { default: UD; case el_c8: goto r_x; - #if SINGELI + #if SINGELI_X86_64 case el_c16: { u32 t = avx2_squeeze_c16(c16any_ptr(x), ia); if (t==0) goto r_c8; else goto r_x; } case el_c32: { u32 t = avx2_squeeze_c32(c32any_ptr(x), ia); if (t==0) goto r_c8; else if (t==1) goto r_c16; else if (t==2) goto r_x; else UD; } #else @@ -134,7 +134,7 @@ B chr_squeeze(B x) { B* xp = arr_bptr(x); if (xp!=NULL) { - #if SINGELI + #if SINGELI_X86_64 u32 t = avx2_squeeze_chrB(xp, ia); if (t==0) goto r_c8; else if (t==1) goto r_c16; diff --git a/src/utils/mut.c b/src/utils/mut.c index 4600170d..972190d5 100644 --- a/src/utils/mut.c +++ b/src/utils/mut.c @@ -133,7 +133,7 @@ DEF_G(void, fill, B , (void* a, usz ms, B x, usz l), ms, x, l) { } -#if SINGELI +#if SINGELI_X86_64 #define DEF_COPY(T, BODY) DEF0(void, copy, T, u8 xe=TI(x,elType); u8 ne=el_or(xe,el_##T);, ne==el_##T, ne, (void* a, usz ms, B x, usz xs, usz l), ms, x, xs, l) #else #define DEF_COPY(T, BODY) DEF(void, copy, T, u8 xe=TI(x,elType); u8 ne=el_or(xe,el_##T);, ne==el_##T, ne, (void* a, usz ms, B x, usz xs, usz l), ms, x, xs, l) { u8 xt=TY(x); (void)xt; BODY } @@ -217,7 +217,7 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x } } -#if SINGELI +#if SINGELI_X86_64 #define SINGELI_FILE copy #include "./includeSingeli.h" typedef void (*copy_fn)(void*, void*, u64, void*);