separate checks for x86-64 & NEON Singeli importing
& restrict the processed Singeli files on NEON to the ones supported
This commit is contained in:
parent
6d79ce9fb1
commit
bb7fe02a45
@ -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"
|
||||
|
||||
2
makefile
2
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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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<ia; i++) r+=((f64*)xv)[i];
|
||||
@ -132,7 +132,7 @@ static f64 (*const prod_fns[])(void*, usz, f64) = { prod_i8, prod_i16, prod_i32,
|
||||
static f64 min_##T(void* xv, usz ia) { MIN_MAX(T,<) } \
|
||||
static f64 max_##T(void* xv, usz ia) { MIN_MAX(T,>) }
|
||||
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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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<ia; i++) { c+= bitp_get(xp,i); ((T*)rp)[i]=c; } }
|
||||
#if SINGELI
|
||||
#if SINGELI_X86_64
|
||||
#define SUM(W,T) avx2_bcs##W(xp, rp, ia);
|
||||
#else
|
||||
#define SUM(W,T) SUM_BITWISE(T)
|
||||
@ -93,7 +93,7 @@ B scan_add_bool(B x, u64 ia) { // consumes x
|
||||
}
|
||||
|
||||
// min/max-scan
|
||||
#if SINGELI
|
||||
#if SINGELI_X86_64
|
||||
#define MINMAX_SCAN(T,NAME,C,I) avx2_scan_##NAME##_init_##T(xp, rp, ia, I);
|
||||
#else
|
||||
#define MINMAX_SCAN(T,NAME,C,I) T c=I; for (usz i=0; i<ia; i++) { if (xp[i] C c)c=xp[i]; rp[i]=c; }
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
#include "../utils/mut.h"
|
||||
#include "../builtins.h"
|
||||
|
||||
#if SINGELI
|
||||
#if SINGELI_X86_64
|
||||
#define SINGELI_FILE select
|
||||
#include "../utils/includeSingeli.h"
|
||||
#endif
|
||||
@ -95,7 +95,7 @@ B select_c2(B t, B w, B x) {
|
||||
if (xia==0) goto base; // can't just error immediately because depth 2 𝕨
|
||||
u8 xe = TI(x,elType);
|
||||
u8 we = TI(w,elType);
|
||||
#if SINGELI
|
||||
#if SINGELI_X86_64
|
||||
#define CPUSEL(W, NEXT) \
|
||||
if (!avx2_select_tab[4*(we-el_i8)+CTZ(xw)](wp, xp, rp, wia, xia)) thrM("⊏: Indexing out-of-bounds");
|
||||
#define BOOL_USE_SIMD (xia<=128)
|
||||
|
||||
@ -149,13 +149,13 @@
|
||||
|
||||
void storeu_u64(u64* p, u64 v) { memcpy(p, &v, 8); }
|
||||
u64 loadu_u64(u64* p) { u64 v; memcpy(&v, p, 8); return v; }
|
||||
#if SINGELI
|
||||
#if SINGELI_X86_64
|
||||
#define SINGELI_FILE slash
|
||||
#include "../utils/includeSingeli.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if SINGELI
|
||||
#if SINGELI_X86_64
|
||||
#define SINGELI_FILE constrep
|
||||
#include "../utils/includeSingeli.h"
|
||||
|
||||
@ -228,7 +228,7 @@ static void bsp_u16(u64* src, u16* dst, usz len, usz sum) {
|
||||
|
||||
static void where_block_u16(u64* src, u16* dst, usz len, usz sum) {
|
||||
assert(len <= bsp_max);
|
||||
#if SINGELI && defined(__BMI2__)
|
||||
#if SINGELI_X86_64 && defined(__BMI2__)
|
||||
if (sum >= 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<<q) - 1;
|
||||
if (xia <= 128) {
|
||||
#if SINGELI && defined(__BMI2__)
|
||||
#if SINGELI_X86_64 && defined(__BMI2__)
|
||||
i8* rp = m_tyarrvO(&r, 1, s, t_i8arr, 8);
|
||||
bmipopc_1slash8(xp, rp, xia);
|
||||
FINISH_OVERALLOC_A(r, s, 8);
|
||||
@ -307,7 +307,7 @@ static B where(B x, usz xia, u64 s) {
|
||||
i8* rp; r=m_i8arrv(&rp,s); WHERE_SPARSE(xp,rp,s,0,);
|
||||
#endif
|
||||
} else if (xia <= 32768) {
|
||||
#if SINGELI && defined(__BMI2__)
|
||||
#if SINGELI_X86_64 && defined(__BMI2__)
|
||||
if (s >= 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; j<bs; j++) rq[j] = i+buf[j];
|
||||
@ -430,7 +430,7 @@ B grade_bool(B x, usz xia, bool up) {
|
||||
u64* xp = bitarr_ptr(x);
|
||||
u64 sum = bit_sum(xp, xia);
|
||||
u64 l0 = up? xia-sum : sum; // Length of first set of indices
|
||||
#if SINGELI && defined(__BMI2__)
|
||||
#if SINGELI_X86_64 && defined(__BMI2__)
|
||||
if (xia < 16) { BRANCHLESS_GRADE(i8) }
|
||||
else if (xia <= 1<<15) {
|
||||
B notx = bit_negate(inc(x));
|
||||
@ -508,7 +508,7 @@ static B compress(B w, B x, usz wia, u8 xl, u8 xt) {
|
||||
default: r = compress_grouped(wp, x, wia, wsum, xt); break;
|
||||
case 0: {
|
||||
u64* xp = bitarr_ptr(x); u64* rp;
|
||||
#if SINGELI && defined(__BMI2__)
|
||||
#if SINGELI_X86_64 && defined(__BMI2__)
|
||||
r = m_bitarrv(&rp,wsum+128); a(r)->ia = 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<<xk, s, xt);
|
||||
void* xv = tyany_ptr(x);
|
||||
#if SINGELI
|
||||
#if SINGELI_X86_64
|
||||
#define CASE(L,T) case L: constrep_##T(wv, xv, rv, xlen); break;
|
||||
#else
|
||||
#define CASE(L,T) case L: { REP_BY_SCAN(T, wv) break; }
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "../core.h"
|
||||
|
||||
#if SINGELI
|
||||
#if SINGELI_X86_64
|
||||
#define SINGELI_FILE squeeze
|
||||
#include "../utils/includeSingeli.h"
|
||||
#endif
|
||||
@ -32,14 +32,14 @@ B num_squeeze(B x) {
|
||||
usz ia = IA(x);
|
||||
u8 xe = TI(x,elType);
|
||||
|
||||
#if !SINGELI
|
||||
#if !SINGELI_X86_64
|
||||
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_X86_64
|
||||
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; }
|
||||
@ -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;
|
||||
|
||||
@ -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*);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user