From 37bf551e5476a3fd55ca4dbb3bcd48fa2d2d7134 Mon Sep 17 00:00:00 2001 From: dzaima Date: Fri, 1 Apr 2022 22:41:32 +0300 Subject: [PATCH] BMI2 bitarr/i8arr & bitarr/i16arr --- README.md | 4 +-- makefile | 2 +- src/builtins/sfns.c | 19 +++++++++++++- src/core/stuff.c | 2 +- src/singeli/src/slash.singeli | 49 +++++++++++++++++++++++++++++++++++ 5 files changed, 71 insertions(+), 5 deletions(-) create mode 100644 src/singeli/src/slash.singeli diff --git a/README.md b/README.md index bb2fdfd7..13cc331a 100644 --- a/README.md +++ b/README.md @@ -15,8 +15,8 @@ ## Configuration options - `some-other-bqn-implementation ./genRuntime path/to/mlochbaum/BQN` can be used to avoid pulling precompiled bytecode with git from `remotes/origin/bytecode`. - This creates the dummy file `src/gen/customRuntime` and will disable automated bytecode retrieval whenever it's updated. - `make clean-runtime` (which is included in `make clean`) can be used to reset to the default state. + This creates the dummy file `src/gen/customRuntime`, which will disable automated bytecode retrieval, leading to the bytecode going out-of-sync whenever it needs updating. + `make clean-runtime` (which is included in `make clean`) can be used to reset this to the default state. - Different build types: - `make o3` - `-O3`, the default build - `make o3n` - `-O3 -march=native` diff --git a/makefile b/makefile index 0a9f1b23..3ffae6ea 100644 --- a/makefile +++ b/makefile @@ -136,7 +136,7 @@ preSingeliBin: @mv BQN obj/presingeli/BQN -gen-singeli: ${addprefix src/singeli/gen/, cmp.c dyarith.c} +gen-singeli: ${addprefix src/singeli/gen/, cmp.c dyarith.c slash.c} @echo $(postmsg) src/singeli/gen/%.c: src/singeli/src/%.singeli preSingeliBin @echo $< | cut -c 17- | sed 's/^/ /' diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 1e220a20..30994217 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -498,8 +498,17 @@ B slash_c1(B t, B x) { return r; } #ifdef __BMI2__ -#include + #include + u64 c16lut[] = {0x0000000000000000, 0x000000000000ffff, 0x00000000ffff0000, 0x00000000ffffffff, 0x0000ffff00000000, 0x0000ffff0000ffff, 0x0000ffffffff0000, 0x0000ffffffffffff, 0xffff000000000000, 0xffff00000000ffff, 0xffff0000ffff0000, 0xffff0000ffffffff, 0xffffffff00000000, 0xffffffff0000ffff, 0xffffffffffff0000, 0xffffffffffffffff}; + + #if SINGELI + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wunused-variable" + #include "../singeli/gen/slash.c" + #pragma GCC diagnostic pop + #endif #endif + B slash_c2(B t, B w, B x) { if (isArr(x) && rnk(x)==1 && isArr(w) && rnk(w)==1 && depth(w)==1) { usz wia = a(w)->ia; @@ -518,6 +527,7 @@ B slash_c2(B t, B w, B x) { if (wsum==0) { dec(w); dec(x); return q_N(xf)? emptyHVec() : isF64(xf)? emptyIVec() : isC32(xf)? emptyCVec() : m_emptyFVec(xf); } B r; switch(TI(x,elType)) { default: UD; + #ifdef __BMI2__ case el_bit: { u64* xp = bitarr_ptr(x); u64* rp; r = m_bitarrv(&rp,wsum+128); a(r)->ia = wsum; u64 cw = 0; // current word @@ -540,8 +550,15 @@ B slash_c2(B t, B w, B x) { #else case el_bit: { u64* xp = bitarr_ptr(x); u64* rp; r = m_bitarrv(&rp,wsum); for (usz i=0; iia-= 8; comp8 (wp, xp, rp, wia); break; } + case el_i16: { i16* xp = i16any_ptr(x); i16* rp; r = m_i16arrv(&rp, wsum+16); a(r)->ia-= 16; comp16(wp, xp, rp, wia); break; } + #else case el_i8: { i8* xp = i8any_ptr (x); i8* rp; r = m_i8arrv (&rp,wsum); for (usz i=0; i>4} +# } +# } +# 'comp16'=comp16 + +comp16(w:*u64, x:*i16, r:*i16, l:u64) : void = { + xv:= reinterpret{*u64, x} + @for(w in reinterpret{*u8,w} over i to cdiv{l,8}) { + def step{w} = { + pc:= popc{w} + store{reinterpret{*u64,r}, 0, pext{load{xv,0}, load{emit{*u64,'','c16lut'}, w}}} + r+= pc + xv+= 1 + } + step{w&15} + step{w>>4} + } +} +'comp16'=comp16 \ No newline at end of file