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);
}
i32* rp; B r = m_i32arrc(&rp, x);
B r;
if (LIKELY(we<el_B & xe<el_B)) {
if (elNum(we)) { // number
if (elNum(xe)) {
@ -406,13 +405,15 @@ B GRADE_CAT(c2)(B t, B w, B x) {
w=toI32Any(w); x=toI32Any(x);
#endif
} 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;
goto done;
}
} else { // character
if (elNum(xe)) {
Arr* ra=allZeroes(xia); arr_shCopy(ra, x);
decG(r); r=taga(ra); goto done;
r=taga(ra); goto done;
} else {
we = el_c32;
w=toC32Any(w); x=toC32Any(x);
@ -421,8 +422,9 @@ B GRADE_CAT(c2)(B t, B w, B x) {
#if SINGELI
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
i32* rp; r = m_i32arrc(&rp, x);
i32* wi = tyany_ptr(w);
i32* xi = tyany_ptr(x);
for (usz i = 0; i < xia; i++) {
@ -436,6 +438,8 @@ B GRADE_CAT(c2)(B t, B w, B x) {
#if !SINGELI
gen:;
#endif
i32* rp; r = m_i32arrc(&rp, x);
SGetU(x)
SLOW2("𝕨"GRADE_CHR"𝕩", w, x);
B* wp = TO_BPTR(w);

View File

@ -5,7 +5,11 @@
#if SINGELI
#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"
#undef m_i8arrc_wrapu
#undef m_i32arrc_wrapu
#endif
#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}}
}
fn bins{T, up}(w:*void, wn:u64, x:*void, xn:u64, r:*i32) : void = {
if (hasarch{'AVX2'} and T==i8 and wn<16 and xn>=32) {
bin_search_vec{up, *T~~w, wn, *T~~x, xn, *i8~~r}
# Slow and useless: need to allocate i8 result
j:=xn; while (j > 0) { --j; store{r, j, cast_i{i32, load{*i8~~r, j}}} }
} else {
bin_search_branchless{up, *T~~w, wn, *T~~x, xn, r}
def B = u64
fn bins{T, up}(w:*void, wn:u64, x:*void, xn:u64, xb:B) : B = {
def alloc{T,ts} = {
u:*u64 = tup{0}
rpp:* *T = (* *T)~~u
r := emit{B, merge{'m_',ts,'arrc_wrapu'}, rpp, xb}
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{