Separate where into its own function and split different types completely
This commit is contained in:
parent
638121c054
commit
1f40d36712
@ -109,30 +109,37 @@
|
|||||||
for (u64 v=X[i]; v; v&=v-1) R[j++] = i*64 + CTZ(v); \
|
for (u64 v=X[i]; v; v&=v-1) R[j++] = i*64 + CTZ(v); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
extern B rt_slash;
|
static B where(B x, usz xia, u64 s) {
|
||||||
B slash_c1(B t, B x) {
|
|
||||||
if (RARE(isAtm(x)) || RARE(RNK(x)!=1)) thrF("/: Argument must have rank 1 (%H ≡ ≢𝕩)", x);
|
|
||||||
u64 s = usum(x);
|
|
||||||
if (s>=USZ_MAX) thrOOM();
|
|
||||||
if (s==0) { decG(x); return emptyIVec(); }
|
|
||||||
usz xia = IA(x);
|
|
||||||
if (RARE(xia>=I32_MAX)) {
|
|
||||||
usz xia = IA(x);
|
|
||||||
SGetU(x)
|
|
||||||
f64* rp; B 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;
|
|
||||||
}
|
|
||||||
decG(x);
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
B r;
|
B r;
|
||||||
u8 xe = TI(x,elType);
|
|
||||||
if (xe==el_bit) {
|
|
||||||
u64* xp = bitarr_ptr(x);
|
u64* xp = bitarr_ptr(x);
|
||||||
if (xia > 32768) {
|
|
||||||
usz q=xia%64; if (q) xp[xia/64] &= ((u64)1<<q) - 1;
|
usz q=xia%64; if (q) xp[xia/64] &= ((u64)1<<q) - 1;
|
||||||
|
if (xia <= 128) {
|
||||||
|
#if SINGELI && defined(__BMI2__)
|
||||||
|
i8* rp = m_tyarrvO(&r, 1, s, t_i8arr, 8);
|
||||||
|
bmipopc_1slash8(xp, rp, xia);
|
||||||
|
#else
|
||||||
|
i8* rp; r=m_i8arrv(&rp,s); WHERE_SPARSE(xp,rp,s);
|
||||||
|
#endif
|
||||||
|
} else if (xia <= 32768) {
|
||||||
|
#if SINGELI && defined(__BMI2__)
|
||||||
|
if (s >= xia/16) {
|
||||||
|
i16* rp = m_tyarrvO(&r, 2, s, t_i16arr, 16);
|
||||||
|
bmipopc_1slash16(xp, rp, xia);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (s >= xia/2) {
|
||||||
|
i16* rp = m_tyarrvO(&r, 2, s, t_i16arr, 2);
|
||||||
|
for (usz i=0; i<(xia+7)/8; i++) {
|
||||||
|
u8 v = ((u8*)xp)[i];
|
||||||
|
for (usz k=0; k<8; k++) { *rp=8*i+k; rp+=v&1; v>>=1; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
else {
|
||||||
|
i16* rp; r=m_i16arrv(&rp,s); WHERE_SPARSE(xp,rp,s);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
assert(xia <= (usz)I32_MAX+1);
|
||||||
#if SINGELI && defined(__BMI2__)
|
#if SINGELI && defined(__BMI2__)
|
||||||
i32* rp; r = m_i32arrv(&rp, s);
|
i32* rp; r = m_i32arrv(&rp, s);
|
||||||
#else
|
#else
|
||||||
@ -153,6 +160,7 @@ B slash_c1(B t, B x) {
|
|||||||
if (bs >= b/8+b/16) {
|
if (bs >= b/8+b/16) {
|
||||||
bmipopc_1slash16(xp, buf, b);
|
bmipopc_1slash16(xp, buf, b);
|
||||||
for (usz j=0; j<bs; j++) rq[j] = i+buf[j];
|
for (usz j=0; j<bs; j++) rq[j] = i+buf[j];
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
if (bs >= b/2) {
|
if (bs >= b/2) {
|
||||||
for (usz ii=0; ii<(b+7)/8; ii++) {
|
for (usz ii=0; ii<(b+7)/8; ii++) {
|
||||||
@ -160,8 +168,9 @@ B slash_c1(B t, B x) {
|
|||||||
i32* rs=rq;
|
i32* rs=rq;
|
||||||
for (usz k=0; k<8; k++) { *rs=i+8*ii+k; rs+=v&1; v>>=1; }
|
for (usz k=0; k<8; k++) { *rs=i+8*ii+k; rs+=v&1; v>>=1; }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
} else if (bs >= b/256) { // Branchless sparse
|
else if (bs >= b/256) { // Branchless sparse
|
||||||
for (usz j=0; j<bs; j++) rq[j]=0;
|
for (usz j=0; j<bs; j++) rq[j]=0;
|
||||||
u32 top = 1<<24;
|
u32 top = 1<<24;
|
||||||
for (usz i=0, j=0; i<(b+63)/64; i++) {
|
for (usz i=0, j=0; i<(b+63)/64; i++) {
|
||||||
@ -185,32 +194,32 @@ B slash_c1(B t, B x) {
|
|||||||
xp+= b/64;
|
xp+= b/64;
|
||||||
}
|
}
|
||||||
TFREE(buf);
|
TFREE(buf);
|
||||||
} else
|
|
||||||
// Sparse method with CTZ
|
|
||||||
#if SINGELI && defined(__BMI2__)
|
|
||||||
if (xia>128 && s < xia/16) {
|
|
||||||
#else
|
|
||||||
if (xia<=128 || s < xia/2) {
|
|
||||||
#endif
|
|
||||||
usz q=xia%64; if (q) xp[xia/64] &= ((u64)1<<q) - 1;
|
|
||||||
#define WHERE(T) T* rp; r=m_##T##arrv(&rp,s); WHERE_SPARSE(xp,rp,s);
|
|
||||||
if (0&&xia<=32768) { WHERE(i16) } else { WHERE(i32) }
|
|
||||||
#undef WHERE
|
|
||||||
} else
|
|
||||||
#if SINGELI && defined(__BMI2__)
|
|
||||||
if (xia<=128) { i8* rp = m_tyarrvO(&r, 1, s, t_i8arr , 8); bmipopc_1slash8 (xp, rp, xia); }
|
|
||||||
else { i16* rp = m_tyarrvO(&r, 2, s, t_i16arr, 16); bmipopc_1slash16(xp, rp, xia); }
|
|
||||||
#else
|
|
||||||
{
|
|
||||||
i32* rp = m_tyarrvO(&r, 4, s, t_i32arr, 4);
|
|
||||||
u8* x8 = (u8*)xp;
|
|
||||||
u8 q=xia%8; if (q) x8[xia/8] &= (1<<q)-1;
|
|
||||||
for (usz i=0; i<(xia+7)/8; i++) {
|
|
||||||
u8 v = x8[i];
|
|
||||||
for (usz k=0; k<8; k++) { *rp=8*i+k; rp+= v&1; v>>=1; }
|
|
||||||
}
|
}
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
extern B rt_slash;
|
||||||
|
B slash_c1(B t, B x) {
|
||||||
|
if (RARE(isAtm(x)) || RARE(RNK(x)!=1)) thrF("/: Argument must have rank 1 (%H ≡ ≢𝕩)", x);
|
||||||
|
u64 s = usum(x);
|
||||||
|
if (s>=USZ_MAX) thrOOM();
|
||||||
|
if (s==0) { decG(x); return emptyIVec(); }
|
||||||
|
usz xia = IA(x);
|
||||||
|
if (RARE(xia>=I32_MAX)) {
|
||||||
|
usz xia = IA(x);
|
||||||
|
SGetU(x)
|
||||||
|
f64* rp; B 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;
|
||||||
|
}
|
||||||
|
decG(x);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
B r;
|
||||||
|
u8 xe = TI(x,elType);
|
||||||
|
if (xe==el_bit) {
|
||||||
|
r = where(x, xia, s);
|
||||||
} else {
|
} else {
|
||||||
i32* rp; r = m_i32arrv(&rp, s);
|
i32* rp; r = m_i32arrv(&rp, s);
|
||||||
if (xe==el_i8) {
|
if (xe==el_i8) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user