From dc2ac37e0aa75e512db49f48cc2c6e9c37407b3b Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 31 Mar 2023 16:45:29 +0300 Subject: [PATCH] arch-independent Singeli builds --- build/singeliSubmodule | 2 +- build/src/build.bqn | 19 ++++++++++--------- makefile | 2 +- src/builtins/arithd.c | 4 ++-- src/builtins/arithm.c | 4 ++-- src/builtins/cmp.c | 2 +- src/builtins/squeeze.c | 12 ++++++------ src/core/stuff.c | 2 +- src/singeli/src/base.singeli | 10 ++++++++++ src/utils/bits.c | 4 ++-- src/utils/mut.c | 4 ++-- 11 files changed, 38 insertions(+), 27 deletions(-) diff --git a/build/singeliSubmodule b/build/singeliSubmodule index a17f83b2..0cb33ab7 160000 --- a/build/singeliSubmodule +++ b/build/singeliSubmodule @@ -1 +1 @@ -Subproject commit a17f83b2db2c1e025a56af0401682c45eb883257 +Subproject commit 0cb33ab7a747c4e7a22f7c5a54321e6136e2d688 diff --git a/build/src/build.bqn b/build/src/build.bqn index d39b4124..2c83ccf8 100755 --- a/build/src/build.bqn +++ b/build/src/build.bqn @@ -192,8 +192,7 @@ po ← { # parsed options singeli ⇐ GetOpt "singeli" replxx ⇐ GetOpt "REPLXX" - {𝕊: "Error: Cannot use Singeli on x86-64 without explicit 'native'"}_assert_¬ (arch≡"x86-64") ∧ singeli ∧ @≡GetOpt"native" - {𝕊: "Error: Cannot use Singeli on generic arch"}_assert_¬ singeli ∧ arch≡"generic" + {𝕊: arch↩"generic" ⋄ Log ∾⟨"Note: on x86-64, a native build will be much faster: ", compat⊑"add an argument of 'native'"‿"use 'make o3n-singeli' if possible"⟩}⍟⊢ (arch≡"x86-64") ∧ singeli ∧ @≡GetOpt"native" pie ⇐ {(¬shared)∧linux∧arch≡"x86-64"? 0; 1} DOpt "pie" @@ -249,6 +248,7 @@ po ← { # parsed options args∾↩ GetOpt "CCFLAGS" args∾↩ (singeli∧arch≡ "x86-64") / ⟨"-DSINGELI_X86_64"⟩ args∾↩ (singeli∧arch≡"aarch64") / ⟨"-DSINGELI_NEON"⟩ + args∾↩ (singeli∧⊑arch≢"generic") / ⟨"-DSINGELI_SIMD"⟩ args∾↩ ( wasm) / ⟨"-DWASM"⟩ args∾↩ ( wasi) / ⟨"-DWASI", "-DNO_MMAP", "-DCATCH_ERRORS=0", "-D_WASI_EMULATED_MMAN", "--target=wasm32-wasi"⟩ args∾↩ ( emcc) / ⟨"-DEMCC", "-O3"⟩ @@ -571,12 +571,12 @@ cachedBin‿linkerCache ← { ⟩ cbqnSrc ↩ cbqnSrc clangd.Files "src" singeliMap ← 1↓¨ (∨´¨ (⊑po.arch) = ⊑¨)⊸/ ⟨ - "xa"‿"src/builtins/arithm.c"‿"monarith", - "xa"‿"src/core/stuff.c"‿"equal", "xa"‿"src/utils/mut.c"‿"copy", "xa"‿"src/utils/bits.c"‿"bits" - "xa"‿"src/builtins/arithd.c"‿"dyarith", "xa"‿"src/builtins/cmp.c"‿"cmp", "xa"‿"src/builtins/squeeze.c"‿"squeeze" - "x."‿"src/builtins/select.c"‿"select", "x."‿"src/builtins/fold.c"‿"fold", "x."‿"src/builtins/scan.c"‿"scan" - "x."‿"src/builtins/scan.c"‿"neq", "x."‿"src/builtins/slash.c"‿"slash", "x."‿"src/builtins/slash.c"‿"constrep" - "xa"‿"src/builtins/transpose.c"‿"transpose" + "xa."‿"src/builtins/arithm.c"‿"monarith", + "xa."‿"src/core/stuff.c"‿"equal", "xa."‿"src/utils/mut.c"‿"copy", "xa."‿"src/utils/bits.c"‿"bits" + "xa."‿"src/builtins/arithd.c"‿"dyarith", "xa."‿"src/builtins/cmp.c"‿"cmp", "xa."‿"src/builtins/squeeze.c"‿"squeeze" + "x.."‿"src/builtins/select.c"‿"select", "x.."‿"src/builtins/fold.c"‿"fold", "x.."‿"src/builtins/scan.c"‿"scan" + "x.."‿"src/builtins/scan.c"‿"neq", "x.."‿"src/builtins/slash.c"‿"slash", "x.."‿"src/builtins/slash.c"‿"constrep" + "xag"‿"src/builtins/transpose.c"‿"transpose" ⟩ objs ← ⟨⟩ @@ -610,8 +610,9 @@ cachedBin‿linkerCache ← { singeliArgs ← po.singeliFlags∾⟨"-l", "gen="∾AtRoot singeliCache.folder⟩∾{ po.native? ⟨⟩; - "-a" ⋈ {"x86-64":"X86_64"; "aarch64":"AARCH64"} po.arch + "-a" ⋈ {"x86-64":"X86_64"; "aarch64":"AARCH64"; "none"} po.arch } + {𝕊: "Singeli args: "∾•Repr singeliArgs} _verboseLog @ singeliObjs ↩ {MakeSingeliInv ⟨singeliArgs, {𝕊:UpdateSubmodule po.singeliDir}, singeliCache, 𝕩, "src/singeli/src/"•file.At 𝕩∾".singeli", (𝕩≡"dyarith")/⟨gaRule⟩⟩}¨ 1⊑¨singeliMap singeliCache diff --git a/makefile b/makefile index b1655fb0..b7e1ddea 100644 --- a/makefile +++ b/makefile @@ -201,7 +201,7 @@ ifeq ($(WINDOWS), 1) endif endif -ALL_CC_FLAGS = -std=gnu11 -Wall -Wno-unused-function -fms-extensions -ffp-contract=off -fno-math-errno -fno-strict-aliasing $(CCFLAGS) $(f) $(i_f) $(NOWARN) -DBYTECODE_DIR=$(BYTECODE_DIR) -DSINGELI=$(i_singeli) -DSINGELI_X86_64=$(i_singeli) -DFFI=$(i_FFI) $(i_LIBS_CC) $(i_CC_PIE) +ALL_CC_FLAGS = -std=gnu11 -Wall -Wno-unused-function -fms-extensions -ffp-contract=off -fno-math-errno -fno-strict-aliasing $(CCFLAGS) $(f) $(i_f) $(NOWARN) -DBYTECODE_DIR=$(BYTECODE_DIR) -DSINGELI=$(i_singeli) -DSINGELI_SIMD=$(i_singeli) -DSINGELI_X86_64=$(i_singeli) -DFFI=$(i_FFI) $(i_LIBS_CC) $(i_CC_PIE) 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 d9cc0f2c..1e85f670 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_SIMD #include "../singeli/c/arithdDispatch.c" static AndBytesFn andBytes_fn = simd_andBytes; #else @@ -217,7 +217,7 @@ static B modint_AS(B w, B xv) { return modint_AA(w, C2(shape, C1(fne, incG(w)) #undef GC2f - #if SINGELI + #if SINGELI_SIMD #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/arithm.c b/src/builtins/arithm.c index 45aa5143..7737ff53 100644 --- a/src/builtins/arithm.c +++ b/src/builtins/arithm.c @@ -29,7 +29,7 @@ B add_c1(B t, B x) { dec(eachm_fn(m_f64(0), inc(x), add_c1)); return x; } -#if SINGELI +#if SINGELI_SIMD #define SINGELI_FILE monarith #include "../utils/includeSingeli.h" #endif @@ -60,7 +60,7 @@ B add_c1(B t, B x) { #define SIGN_EXPR(T, C) rp[i] = c>0? 1 : c==0? 0 : -1; #define SIGN_MAIN(FEXPR) LOOP_BODY(i8* rp; B r=m_i8arrc(&rp,x);, SIGN_EXPR,) -#if SINGELI +#if SINGELI_SIMD #define STILE_BODY(FEXPR) { usz ia = IA(x); B r; retry:; \ void* rp = m_tyarrlc(&r, elWidth(xe), x, el2t(xe)); \ u64 got = simd_abs[xe-el_i8](rp, tyany_ptr(x), ia); \ diff --git a/src/builtins/cmp.c b/src/builtins/cmp.c index 563cada2..4741630c 100644 --- a/src/builtins/cmp.c +++ b/src/builtins/cmp.c @@ -54,7 +54,7 @@ CMP_REC(ne, ne, swapped=0;) #define FN_LUT_C(B,A,F,S) FN_LUT_T(B,F,S)[] = {CMPFN(A,F,S,u1), CMPFN(A,F,S,i8), CMPFN(A,F,S,i16), CMPFN(A,F,S,i32), CMPFN(A,F,S,f64), CMPFN(A,F,S,u8), CMPFN(A,F,S,u16), CMPFN(A,F,S,u32)} #define FN_LUT_A(B,F,S) FN_LUT_T(B,F,S)[8] -#if SINGELI +#if SINGELI_SIMD #include "../singeli/c/cmp.c" #else void cmpA_init(void) { } diff --git a/src/builtins/squeeze.c b/src/builtins/squeeze.c index 6a8b9d8d..f8c63592 100644 --- a/src/builtins/squeeze.c +++ b/src/builtins/squeeze.c @@ -1,6 +1,6 @@ #include "../core.h" -#if SINGELI +#if SINGELI_SIMD #define SINGELI_FILE squeeze #include "../utils/includeSingeli.h" #endif @@ -36,14 +36,14 @@ B num_squeeze(B x) { goto r_bit; } - #if !SINGELI + #if !SINGELI_SIMD usz i = 0; #endif u32 or = 0; // using bitwise or as an approximate ⌈´ switch (xe) { default: UD; case el_bit: goto r_x; - #if SINGELI + #if SINGELI_SIMD case el_i8: { or = avx2_squeeze_i8 (i8any_ptr (x), ia); if(or> 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; } @@ -69,7 +69,7 @@ B num_squeeze(B x) { B* xp = arr_bptr(x); if (xp==NULL) goto r_f; - #if SINGELI + #if SINGELI_SIMD or = avx2_squeeze_numB(xp, ia); if (-2==(i32)or) goto r_x; if (-1==(i32)or) goto r_f64; @@ -117,7 +117,7 @@ B chr_squeeze(B x) { i32 or = 0; switch(xe) { default: UD; case el_c8: goto r_x; - #if SINGELI + #if SINGELI_SIMD 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 @@ -142,7 +142,7 @@ B chr_squeeze(B x) { B* xp = arr_bptr(x); if (xp!=NULL) { - #if SINGELI + #if SINGELI_SIMD u32 t = avx2_squeeze_chrB(xp, ia); if (t==0) goto r_c8; else if (t==1) goto r_c16; diff --git a/src/core/stuff.c b/src/core/stuff.c index 5c233b33..a5bfc534 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -420,7 +420,7 @@ u8 eqFnData[] = { // for the main diagonal, amount to shift length by; otherwise n,n,n,n,n,1,1,2, }; -#if SINGELI +#if SINGELI_SIMD #define F(X) avx2_equal_##X #define SINGELI_FILE equal #include "../utils/includeSingeli.h" diff --git a/src/singeli/src/base.singeli b/src/singeli/src/base.singeli index 4bd83f18..d10db695 100644 --- a/src/singeli/src/base.singeli +++ b/src/singeli/src/base.singeli @@ -150,6 +150,16 @@ def pair{...x} = assert{'pair not supported', show{...x}} def cvt{...x} = assert{'cvt not supported', show{...x}} def cvt{T, x:X & T==eltype{X}} = x def shuf{...x} = assert{'shuf not supported', show{...x}} +def homAll{...x} = assert{'homAll not supported', show{...x}} +def homAny{...x} = assert{'homAny not supported', show{...x}} +def homMask{...x} = assert{'homMask not supported', show{...x}} +def andAllZero{...x} = assert{'andAllZero not supported', show{...x}} +def loadLow{...x} = assert{'loadLow not supported', show{...x}} +def storeLow{...x} = assert{'storeLow not supported', show{...x}} +def sel{...x} = assert{'sel not supported', show{...x}} +def make{...x} = assert{'make not supported', show{...x}} +def half{...x} = assert{'half not supported', show{...x}} +def maskstoreF{...x} = assert{'maskstoreF not supported', show{...x}} def min{a, b & knum{a} & knum{b}} = tern{ab, a, b} diff --git a/src/utils/bits.c b/src/utils/bits.c index cfcf4d93..f2e6eb5a 100644 --- a/src/utils/bits.c +++ b/src/utils/bits.c @@ -2,7 +2,7 @@ #include "mut.h" -#if SINGELI +#if SINGELI_SIMD #define SINGELI_FILE bits #include "../utils/includeSingeli.h" #define bitselFns simd_bitsel @@ -58,7 +58,7 @@ NOINLINE B bit_sel(B b, B e0, B e1) { sel:; void* rp = m_tyarrlc(&r, width, b, type); - #if SINGELI + #if SINGELI_SIMD bitselFns[width](rp, bp, e0i, e1i, ia); #else switch(width) { diff --git a/src/utils/mut.c b/src/utils/mut.c index a47f0563..881781a0 100644 --- a/src/utils/mut.c +++ b/src/utils/mut.c @@ -167,7 +167,7 @@ DEF_G(void, fill, B , (void* a, usz ms, B x, usz l), ms, x, l) { } -#if SINGELI +#if SINGELI_SIMD #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 } @@ -253,7 +253,7 @@ DEF_G(void, copy, B, (void* a, usz ms, B x, usz xs, usz l), ms, x, x } } -#if SINGELI +#if SINGELI_SIMD static u64 loadu_u64(u64* p) { u64 v; memcpy(&v, p, 8); return v; } #define SINGELI_FILE copy #include "./includeSingeli.h"