Extend sparse and dense where to all cases fitting in i32s

This commit is contained in:
Marshall Lochbaum 2022-09-16 20:08:23 -04:00
parent fb1230bcc2
commit 5f196c49d9

View File

@ -361,54 +361,55 @@ B slash_c1(B t, B x) {
usz xia = IA(x);
B r;
u8 xe = TI(x,elType);
if (xe!=el_bit && s<=xia) { x = num_squeeze(x); xe = TI(x,elType); }
if (xe==el_bit) {
r = where(x, xia, s);
} else if (RARE(xia>=I32_MAX)) {
} else if (RARE(xia > (usz)I32_MAX+1)) {
SGetU(x)
f64* rp; r = m_f64arrv(&rp, s); usz ri = 0;
for (usz i = 0; i < xia; i++) {
usz c = o2s(GetU(x, i));
for (usz j = 0; j < c; j++) rp[ri++] = i;
}
} else {
} else if (RARE(xe > el_i32)) {
i32* rp; r = m_i32arrv(&rp, s);
if (xe==el_i8) {
i8* xp = i8any_ptr(x);
if (s/16 <= xia) {
usz b = 1<<10;
for (usz k=0, j=0, js=0, ij=xp[0]; ; ) {
usz e = b<s-k? k+b : s;
for (usz i=k; i<e; i++) rp[i]=0;
while (ij<e) { rp[ij]++; ij+=xp[++j]; }
for (usz i=k; i<e; i++) js=rp[i]+=js;
if (e==s) break; k=e;
SLOW1("/𝕩", x);
SGetU(x)
for (u64 i = 0; i < xia; i++) {
usz c = o2s(GetU(x, i));
for (u64 j = 0; j < c; j++) *rp++ = i;
}
} else {
if (s/16 <= xia) { // Sparse case: type of x matters
#define SPARSE_IND(T) \
T* xp = T##any_ptr(x); \
usz b = 1<<10; \
for (usz k=0, j=0, js=0, ij=xp[0]; ; ) { \
usz e = b<s-k? k+b : s; \
for (usz i=k; i<e; i++) rp[i]=0; \
while (ij<e) { rp[ij]++; ij+=xp[++j]; } \
for (usz i=k; i<e; i++) js=rp[i]+=js; \
if (e==s) break; k=e; \
}
} else {
while (xia>0 && !xp[xia-1]) xia--;
for (u64 i = 0; i < xia; i++) {
i32 c = xp[i];
for (i32 j = 0; j < c; j++) *rp++ = i;
i32* rp; r = m_i32arrv(&rp, s);
if (xe == el_i8 ) { SPARSE_IND(i8 ); }
else if (xe == el_i16) { SPARSE_IND(i16); }
else { SPARSE_IND(i32); }
#undef SPARSE_IND
} else { // Dense case: only result type matters
#define DENSE_IND(T) \
T* rp; r = m_##T##arrv(&rp, s); \
for (u64 i = 0; i < xia; i++) { \
i32 c = xp[i]; \
for (i32 j = 0; j < c; j++) *rp++ = i; \
}
}
} else if (xe==el_i32) {
if (xe < el_i32) x = taga(cpyI32Arr(x));
i32* xp = i32any_ptr(x);
while (xia>0 && !xp[xia-1]) xia--;
for (u64 i = 0; i < xia; i++) {
i32 c = xp[i];
if (LIKELY(c==0 || c==1)) {
*rp = i;
rp+= c;
} else {
for (i32 j = 0; j < c; j++) *rp++ = i;
}
}
} else {
SLOW1("/𝕩", x);
SGetU(x)
for (u64 i = 0; i < xia; i++) {
usz c = o2s(GetU(x, i));
for (u64 j = 0; j < c; j++) *rp++ = i;
}
if (xia <= 128) { DENSE_IND(i8 ); }
else if (xia <= 32768) { DENSE_IND(i16); }
else { DENSE_IND(i32); }
#undef DENSE_IND
}
}
decG(x);