slash.c cleanup
This commit is contained in:
parent
01f73dc83b
commit
cec5b7dc6c
@ -186,8 +186,8 @@ static B compress_grouped(u64* wp, B x, usz wia, usz wsum, u8 xt) {
|
|||||||
u64 ri = 0; \
|
u64 ri = 0; \
|
||||||
u64 wv = wp[0]; usz i = 0, wn = (wia-1)/64+1; \
|
u64 wv = wp[0]; usz i = 0, wn = (wia-1)/64+1; \
|
||||||
for (u64 e=wsum*width; ri < e; ) { \
|
for (u64 e=wsum*width; ri < e; ) { \
|
||||||
while (wv== 0) wv=wp[++i]; usz i0=64*i+CTZ( wv); wv|=wv-1; \
|
while (wv== 0) { wv=wp[++i]; } usz i0=64*i+CTZ( wv); wv|=wv-1; \
|
||||||
while (wv==-(u64)1) wv=++i<wn?wp[i]:0; usz i1=64*i+CTZ(~wv); wv&=wv+1; \
|
while (wv==-(u64)1) { wv=++i<wn?wp[i]:0; } usz i1=64*i+CTZ(~wv); wv&=wv+1; \
|
||||||
u64 l = (i1-i0) * width; \
|
u64 l = (i1-i0) * width; \
|
||||||
CPY(rp, ri, xp, i0*width, l); ri += l; \
|
CPY(rp, ri, xp, i0*width, l); ri += l; \
|
||||||
}
|
}
|
||||||
@ -474,7 +474,7 @@ B slash_c1(B t, B x) {
|
|||||||
for (usz i=k; i<e; i++) rp[i]=0; \
|
for (usz i=k; i<e; i++) rp[i]=0; \
|
||||||
while (ij<e) { rp[ij]++; ij+=xp[++j]; } \
|
while (ij<e) { rp[ij]++; ij+=xp[++j]; } \
|
||||||
for (usz i=k; i<e; i++) js=rp[i]+=js; \
|
for (usz i=k; i<e; i++) js=rp[i]+=js; \
|
||||||
if (e==s) break; k=e; \
|
if (e==s) {break;} k=e; \
|
||||||
}
|
}
|
||||||
i32* rp; r = m_i32arrv(&rp, s);
|
i32* rp; r = m_i32arrv(&rp, s);
|
||||||
if (xe == el_i8 ) { SPARSE_IND(i8 ); }
|
if (xe == el_i8 ) { SPARSE_IND(i8 ); }
|
||||||
@ -502,6 +502,7 @@ B slash_c1(B t, B x) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
B slash_c2(B t, B w, B x) {
|
B slash_c2(B t, B w, B x) {
|
||||||
|
B r;
|
||||||
if (isArr(w) && RNK(w)==1 && depth(w)==1) {
|
if (isArr(w) && RNK(w)==1 && depth(w)==1) {
|
||||||
usz wia = IA(w);
|
usz wia = IA(w);
|
||||||
if (wia==0) { decG(w); return isArr(x)? x : m_atomUnit(x); }
|
if (wia==0) { decG(w); return isArr(x)? x : m_atomUnit(x); }
|
||||||
@ -514,38 +515,43 @@ B slash_c2(B t, B w, B x) {
|
|||||||
u8 xt = arrNewType(TY(x));
|
u8 xt = arrNewType(TY(x));
|
||||||
|
|
||||||
u8 we = TI(w,elType);
|
u8 we = TI(w,elType);
|
||||||
if (we > el_i32) { w = any_squeeze(w); we = TI(w,elType); }
|
if (!elInt(we)) {
|
||||||
|
w=any_squeeze(w); we=TI(w,elType);
|
||||||
|
if (!elInt(we)) goto slow;
|
||||||
|
}
|
||||||
if (we==el_bit) {
|
if (we==el_bit) {
|
||||||
wbool:
|
wbool:
|
||||||
B r = compress(w, x, wia, xl, xt);
|
r = compress(w, x, wia, xl, xt);
|
||||||
decG(w); decG(x); return r;
|
goto decWX_ret;
|
||||||
}
|
}
|
||||||
if (xl > 6 || (xl < 3 && xl != 0)) goto base;
|
if (xl>6 || (xl<3 && xl!=0)) goto base;
|
||||||
u64 s = usum(w);
|
u64 s = usum(w);
|
||||||
if (we!=el_bit && s<=wia) {
|
if (s<=wia) {
|
||||||
w = num_squeeze(w); we = TI(w,elType);
|
w=num_squeezeChk(w); we=TI(w,elType);
|
||||||
if (we==el_bit) goto wbool;
|
if (we==el_bit) goto wbool;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RARE(we>el_i32 || TI(x,elType)==el_B)) { // Slow case
|
if (RARE(TI(x,elType)==el_B)) { // Slow case
|
||||||
|
slow:
|
||||||
if (xr > 1) goto base;
|
if (xr > 1) goto base;
|
||||||
SLOW2("𝕨/𝕩", w, x);
|
SLOW2("𝕨/𝕩", w, x);
|
||||||
B xf = getFillQ(x);
|
B xf = getFillQ(x);
|
||||||
u64 ria = usum(w);
|
MAKE_MUT(r0, s) mut_init(r0, el_B); MUTG_INIT(r0);
|
||||||
if (ria>=USZ_MAX) thrOOM();
|
SGetU(w) SGetU(x)
|
||||||
M_HARR(r, ria) SGetU(w) SGetU(x)
|
usz ri = 0;
|
||||||
for (usz i = 0; i < wia; i++) {
|
for (usz i = 0; i < wia; i++) {
|
||||||
usz c = o2s(GetU(w, i));
|
usz c = o2s(GetU(w, i));
|
||||||
if (c) {
|
if (c) {
|
||||||
B cx = incBy(GetU(x, i), c);
|
mut_fillG(r0, ri, GetU(x, i), c);
|
||||||
for (usz j = 0; RARE(j < c); j++) HARR_ADDA(r, cx);
|
ri+= c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decG(w); decG(x);
|
r = withFill(mut_fv(r0), xf);
|
||||||
return withFill(HARR_FV(r), xf);
|
decWX_ret: decG(w);
|
||||||
|
decX_ret: decG(x);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
B r;
|
|
||||||
// Make shape if needed; all cases below use it
|
// Make shape if needed; all cases below use it
|
||||||
usz* rsh = NULL;
|
usz* rsh = NULL;
|
||||||
if (xr > 1) {
|
if (xr > 1) {
|
||||||
@ -571,10 +577,10 @@ B slash_c2(B t, B w, B x) {
|
|||||||
rp[ij/64]^=(-(xx&1))<<(ij%64); ij+=wp[j]; \
|
rp[ij/64]^=(-(xx&1))<<(ij%64); ij+=wp[j]; \
|
||||||
} \
|
} \
|
||||||
for (usz i=k/64; i<eb; i++) js=-((rp[i]^=js)>>63); \
|
for (usz i=k/64; i<eb; i++) js=-((rp[i]^=js)>>63); \
|
||||||
if (e==s) break; k=e; \
|
if (e==s) {break;} k=e; \
|
||||||
}
|
}
|
||||||
if (we == el_i8 ) { SPARSE_REP(i8 ); }
|
if (we==el_i8 ) { SPARSE_REP(i8 ); }
|
||||||
else if (we == el_i16) { SPARSE_REP(i16); }
|
else if (we==el_i16) { SPARSE_REP(i16); }
|
||||||
else { SPARSE_REP(i32); }
|
else { SPARSE_REP(i32); }
|
||||||
#undef SPARSE_REP
|
#undef SPARSE_REP
|
||||||
} else {
|
} else {
|
||||||
@ -609,7 +615,7 @@ B slash_c2(B t, B w, B x) {
|
|||||||
for (usz i=k; i<e; i++) rp[i]=0; \
|
for (usz i=k; i<e; i++) rp[i]=0; \
|
||||||
while (ij<e) { j++; XT sx=px; rp[ij]^=sx^(px=xp[j]); ij+=wp[j]; } \
|
while (ij<e) { j++; XT sx=px; rp[ij]^=sx^(px=xp[j]); ij+=wp[j]; } \
|
||||||
for (usz i=k; i<e; i++) js=rp[i]^=js; \
|
for (usz i=k; i<e; i++) js=rp[i]^=js; \
|
||||||
if (e==s) break; k=e; \
|
if (e==s) {break;} k=e; \
|
||||||
} break; }
|
} break; }
|
||||||
#define SPARSE_REP(WT) \
|
#define SPARSE_REP(WT) \
|
||||||
WT* wp = WT##any_ptr(w); \
|
WT* wp = WT##any_ptr(w); \
|
||||||
@ -633,7 +639,7 @@ B slash_c2(B t, B w, B x) {
|
|||||||
#undef CASE
|
#undef CASE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
decG(w); decG(x); return r;
|
goto decWX_ret;
|
||||||
}
|
}
|
||||||
if (isArr(x) && RNK(x)==1 && q_i32(w)) {
|
if (isArr(x) && RNK(x)==1 && q_i32(w)) {
|
||||||
usz xia = IA(x);
|
usz xia = IA(x);
|
||||||
@ -644,23 +650,22 @@ B slash_c2(B t, B w, B x) {
|
|||||||
}
|
}
|
||||||
if (TI(x,elType)==el_i32) {
|
if (TI(x,elType)==el_i32) {
|
||||||
i32* xp = i32any_ptr(x);
|
i32* xp = i32any_ptr(x);
|
||||||
i32* rp; B r = m_i32arrv(&rp, xia*wv);
|
i32* rp; r = m_i32arrv(&rp, xia*wv);
|
||||||
for (usz i = 0; i < xia; i++) {
|
for (usz i = 0; i < xia; i++) {
|
||||||
for (i64 j = 0; j < wv; j++) *rp++ = xp[i];
|
for (i64 j = 0; j < wv; j++) *rp++ = xp[i];
|
||||||
}
|
}
|
||||||
decG(x);
|
goto decX_ret;
|
||||||
return r;
|
|
||||||
} else {
|
} else {
|
||||||
SLOW2("𝕨/𝕩", w, x);
|
SLOW2("𝕨/𝕩", w, x);
|
||||||
B xf = getFillQ(x);
|
B xf = getFillQ(x);
|
||||||
HArr_p r = m_harrUv(xia*wv);
|
HArr_p r0 = m_harrUv(xia*wv);
|
||||||
SGetU(x)
|
SGetU(x)
|
||||||
for (usz i = 0; i < xia; i++) {
|
for (usz i = 0; i < xia; i++) {
|
||||||
B cx = incBy(GetU(x, i), wv);
|
B cx = incBy(GetU(x, i), wv);
|
||||||
for (i64 j = 0; j < wv; j++) *r.a++ = cx;
|
for (i64 j = 0; j < wv; j++) *r0.a++ = cx;
|
||||||
}
|
}
|
||||||
decG(x);
|
r = withFill(r0.b, xf);
|
||||||
return withFill(r.b, xf);
|
goto decX_ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
base:
|
base:
|
||||||
|
|||||||
@ -57,7 +57,7 @@ extern u8 arrTypeWidthLog[];
|
|||||||
#define arrTypeWidthLog(X) arrTypeWidthLog[X]
|
#define arrTypeWidthLog(X) arrTypeWidthLog[X]
|
||||||
extern u8 arrTypeBitsLog[];
|
extern u8 arrTypeBitsLog[];
|
||||||
#define arrTypeBitsLog(X) arrTypeBitsLog[X]
|
#define arrTypeBitsLog(X) arrTypeBitsLog[X]
|
||||||
#define arrNewType(X) el2t(ti_elType[X])
|
#define arrNewType(X) el2t(TIi(X,elType))
|
||||||
|
|
||||||
// Log of width in bits: max of 7, and also return 7 if not power of 2
|
// Log of width in bits: max of 7, and also return 7 if not power of 2
|
||||||
static u8 cellWidthLog(B x) {
|
static u8 cellWidthLog(B x) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user