Allocate binary search result in Singeli, using i8 for vectors

This commit is contained in:
Marshall Lochbaum 2023-07-04 11:15:58 -04:00
parent 70249d8b64
commit 302d637129
3 changed files with 29 additions and 11 deletions

View File

@ -390,8 +390,7 @@ B GRADE_CAT(c2)(B t, B w, B x) {
FL_SET(w, fl); FL_SET(w, fl);
} }
i32* rp; B r = m_i32arrc(&rp, x); B r;
if (LIKELY(we<el_B & xe<el_B)) { if (LIKELY(we<el_B & xe<el_B)) {
if (elNum(we)) { // number if (elNum(we)) { // number
if (elNum(xe)) { if (elNum(xe)) {
@ -406,13 +405,15 @@ B GRADE_CAT(c2)(B t, B w, B x) {
w=toI32Any(w); x=toI32Any(x); w=toI32Any(w); x=toI32Any(x);
#endif #endif
} else { } else {
// TODO pull copy-scalar part out of Reshape
i32* rp; r = m_i32arrc(&rp, x);
for (u64 i=0; i<xia; i++) rp[i]=wia; for (u64 i=0; i<xia; i++) rp[i]=wia;
goto done; goto done;
} }
} else { // character } else { // character
if (elNum(xe)) { if (elNum(xe)) {
Arr* ra=allZeroes(xia); arr_shCopy(ra, x); Arr* ra=allZeroes(xia); arr_shCopy(ra, x);
decG(r); r=taga(ra); goto done; r=taga(ra); goto done;
} else { } else {
we = el_c32; we = el_c32;
w=toC32Any(w); x=toC32Any(x); w=toC32Any(w); x=toC32Any(x);
@ -421,8 +422,9 @@ B GRADE_CAT(c2)(B t, B w, B x) {
#if SINGELI #if SINGELI
u8 k = elWidthLogBits(we) - 3; u8 k = elWidthLogBits(we) - 3;
si_bins[k*2 + GRADE_UD(0,1)](tyany_ptr(w), wia, tyany_ptr(x), xia, rp); r = b(si_bins[k*2 + GRADE_UD(0,1)](tyany_ptr(w), wia, tyany_ptr(x), xia, x.u));
#else #else
i32* rp; r = m_i32arrc(&rp, x);
i32* wi = tyany_ptr(w); i32* wi = tyany_ptr(w);
i32* xi = tyany_ptr(x); i32* xi = tyany_ptr(x);
for (usz i = 0; i < xia; i++) { for (usz i = 0; i < xia; i++) {
@ -436,6 +438,8 @@ B GRADE_CAT(c2)(B t, B w, B x) {
#if !SINGELI #if !SINGELI
gen:; gen:;
#endif #endif
i32* rp; r = m_i32arrc(&rp, x);
SGetU(x) SGetU(x)
SLOW2("𝕨"GRADE_CHR"𝕩", w, x); SLOW2("𝕨"GRADE_CHR"𝕩", w, x);
B* wp = TO_BPTR(w); B* wp = TO_BPTR(w);

View File

@ -5,7 +5,11 @@
#if SINGELI #if SINGELI
#define SINGELI_FILE bins #define SINGELI_FILE bins
#define m_i8arrc_wrapu(P, X) m_i8arrc(P, b(X)).u
#define m_i32arrc_wrapu(P, X) m_i32arrc(P, b(X)).u
#include "../utils/includeSingeli.h" #include "../utils/includeSingeli.h"
#undef m_i8arrc_wrapu
#undef m_i32arrc_wrapu
#endif #endif
#define CAT0(A,B) A##_##B #define CAT0(A,B) A##_##B

View File

@ -64,14 +64,24 @@ def bin_search_branchless{up, w, wn, x, n, res} = {
each{searches, tup{4, 1}} each{searches, tup{4, 1}}
} }
fn bins{T, up}(w:*void, wn:u64, x:*void, xn:u64, r:*i32) : void = { def B = u64
if (hasarch{'AVX2'} and T==i8 and wn<16 and xn>=32) { fn bins{T, up}(w:*void, wn:u64, x:*void, xn:u64, xb:B) : B = {
bin_search_vec{up, *T~~w, wn, *T~~x, xn, *i8~~r} def alloc{T,ts} = {
# Slow and useless: need to allocate i8 result u:*u64 = tup{0}
j:=xn; while (j > 0) { --j; store{r, j, cast_i{i32, load{*i8~~r, j}}} } rpp:* *T = (* *T)~~u
} else { r := emit{B, merge{'m_',ts,'arrc_wrapu'}, rpp, xb}
bin_search_branchless{up, *T~~w, wn, *T~~x, xn, r} rp := load{rpp,0}
tup{r, rp}
} }
r := undefined{B}
if (hasarch{'AVX2'} and T==i8 and wn<16 and xn>=32) {
def {rt, rp} = alloc{i8, 'i8'}; r = rt
bin_search_vec{up, *T~~w, wn, *T~~x, xn, rp}
} else {
def {rt, rp} = alloc{i32, 'i32'}; r = rt
bin_search_branchless{up, *T~~w, wn, *T~~x, xn, rp}
}
r
} }
exportT{ exportT{