use arr_shSetU/arr_shSetI inline

and use incG more in rank_c2
This commit is contained in:
dzaima 2022-12-28 17:31:02 +02:00
parent a34bb0a433
commit 6a9e03bdb1
6 changed files with 19 additions and 33 deletions

View File

@ -119,8 +119,7 @@ B ud_c2(B t, B w, B x) {
for (usz i=wr; i<xr; i++) wsh[i] = xsh[i];
if (empty) {
Arr* ra = m_fillarrp(0);
arr_shSetU(ra, rr, sh);
Arr* ra = arr_shSetU(m_fillarrp(0), rr, sh);
fillarr_setFill(ra, getFillQ(x));
decG(x);
return taga(ra);
@ -155,9 +154,7 @@ B ud_c2(B t, B w, B x) {
}
}
decG(x); TFREE(ri);
Arr* ra = mut_fp(r);
arr_shSetU(ra, rr, sh);
return withFill(taga(ra), xf);
return withFill(taga(arr_shSetU(mut_fp(r), rr, sh)), xf);
}
B ltack_c1(B t, B x) { return x; }

View File

@ -163,7 +163,7 @@ static B m1c2(B t, B f, B w, B x) { // consumes w,x
} \
} else if (X##_cr!=0) X##_csz*= SH(X)[1];
#define SLICE(X, S) ({ Arr* r_ = X##_slc(incG(X), S, X##_csz); arr_shSetI(r_, X##_cr, X##_csh); taga(r_); })
#define SLICE(X, S) taga(arr_shSetI(X##_slc(incG(X), S, X##_csz), X##_cr, X##_csh))
#define E_SLICES(X) if (X##_cr>1) ptr_dec(X##_csh); decG(X);

View File

@ -326,7 +326,7 @@ B rank_c1(Md2D* d, B x) { B f = d->f; B g = d->g;
M_HARR(r, cam);
usz p = 0;
for (usz i = 0; i < cam; i++) {
Arr* s = slice(inc(x), p, csz); arr_shSetI(s, cr, csh);
Arr* s = arr_shSetI(slice(incG(x), p, csz), cr, csh);
HARR_ADD(r, i, c1(f, taga(s)));
p+= csz;
}
@ -373,7 +373,7 @@ B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g;
M_HARR(r, cam);
usz p = 0;
for (usz i = 0; i < cam; i++) {
Arr* s = slice(inc(x), p, csz); arr_shSetI(s, xc, csh);
Arr* s = arr_shSetI(slice(incG(x), p, csz), xc, csh);
HARR_ADD(r, i, c2(f, inc(w), taga(s)));
p+= csz;
}
@ -397,8 +397,8 @@ B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g;
M_HARR(r, cam);
usz p = 0;
for (usz i = 0; i < cam; i++) {
Arr* s = slice(inc(w), p, csz); arr_shSetI(s, wc, csh);
HARR_ADD(r, i, c2(f, taga(s), inc(x)));
Arr* s = arr_shSetI(slice(incG(w), p, csz), wc, csh);
HARR_ADD(r, i, c2(f, taga(s), incG(x)));
p+= csz;
}
@ -432,8 +432,7 @@ B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g;
M_HARR(r, cam);
usz wp = 0, xp = 0;
#define CELL(wx) \
Arr* wx##s = wx##slice(inc(wx), wx##p, wx##sz); \
arr_shSetI(wx##s, wx##c, wx##cs); \
Arr* wx##s = arr_shSetI(wx##slice(incG(wx), wx##p, wx##sz), wx##c, wx##cs); \
wx##p+= wx##sz
#define F(W,X) HARR_ADD(r, i, c2(f, W, X))
if (ext == 1) {
@ -443,13 +442,13 @@ B rank_c2(Md2D* d, B w, B x) { B f = d->f; B g = d->g;
} else if (wk < xk) {
for (usz i = 0; i < cam; ) {
CELL(w); B wb=taga(ws);
for (usz e = i+ext; i < e; i++) { CELL(x); F(inc(wb), taga(xs)); }
for (usz e = i+ext; i < e; i++) { CELL(x); F(incG(wb), taga(xs)); }
dec(wb);
}
} else {
for (usz i = 0; i < cam; ) {
CELL(x); B xb=taga(xs);
for (usz e = i+ext; i < e; i++) { CELL(w); F(taga(ws), inc(xb)); }
for (usz e = i+ext; i < e; i++) { CELL(w); F(taga(ws), incG(xb)); }
dec(xb);
}
}

View File

@ -265,9 +265,7 @@ B shape_c2(B t, B w, B x) {
for (i64 i = 0; i < div; i++) mut_copyG(m, i*xia, x, 0, xia);
mut_copyG(m, div*xia, x, 0, mod);
decG(x);
Arr* ra = mut_fp(m);
arr_shSetU(ra, nr, sh);
return withFill(taga(ra), xf);
return withFill(taga(arr_shSetU(mut_fp(m), nr, sh)), xf);
}
u8 xk = xl - 3;
rp = m_tyarrp(&r, 1<<xk, nia, xt);
@ -321,8 +319,7 @@ B shape_c2(B t, B w, B x) {
}
#undef FILL
}
arr_shSetU(r,nr,sh);
return taga(r);
return taga(arr_shSetU(r,nr,sh));
}
B pick_c1(B t, B x) {
@ -502,8 +499,7 @@ static NOINLINE B takedrop_highrank(bool take, B w, B x) {
} else {
Arr* ra = TI(x,slice)(x,0,IA(x));
PLAINLOOP for (usz i = 0; i < rr-xr; i++) rsh->a[i] = 1;
arr_shSetU(ra, rr, rsh);
x = VALIDATE(taga(ra));
x = VALIDATE(taga(arr_shSetU(ra, rr, rsh)));
}
if (cellStart==-1) { // printf("equal shape\n");
r = x;
@ -514,9 +510,7 @@ static NOINLINE B takedrop_highrank(bool take, B w, B x) {
goto basicTake;
}
} else if (ria==0) { // printf("empty result\n");
Arr* ra = emptyArr(x, rr);
arr_shSetU(ra, rr, rsh);
r = taga(ra);
r = taga(arr_shSetU(emptyArr(x, rr), rr, rsh));
} else { // printf("generic\n");
MAKE_MUT(rm, ria); mut_init(rm, TI(x,elType));
B xf = getFillR(x);
@ -589,9 +583,7 @@ static NOINLINE B takedrop_highrank(bool take, B w, B x) {
} // end of actual generic copying code
Arr* ra = mut_fp(rm);
arr_shSetU(ra, rr, rsh);
r = withFill(taga(ra), xf);
r = withFill(taga(arr_shSetU(mut_fp(rm), rr, rsh)), xf);
}
decG(x);
decW_tfree: TFREE(tmp);

View File

@ -1168,8 +1168,8 @@ B bitcast_impl(B el0, B el1, B x) {
r = taga(copy(xct, r));
} else if (v(r)->refc!=1) {
B pr = r;
r = taga(TI(r,slice)(r, 0, IA(r)));
arr_shSetI(a(r), xr, shObj(pr)); // safe to use pr because r has refcount>1 and slice only consumes one, leaving some behind
Arr* r2 = TI(r,slice)(r, 0, IA(r));
r = taga(arr_shSetI(r2, xr, shObj(pr))); // safe to use pr because r has refcount>1 and slice only consumes one, leaving some behind
} else {
#if VERIFY_TAIL
if (xct.s==1 && rct.s!=1) {

View File

@ -21,8 +21,7 @@ B toCells(B x) {
usz* xsh = SH(x);
shcpy(csh->a, xsh+1, cr);
for (usz i = 0; i < cam; i++) {
Arr* s = slice(incG(x), p, csz); arr_shSetI(s, cr, csh);
HARR_ADD(r, i, taga(s));
HARR_ADD(r, i, taga(arr_shSetI(slice(incG(x), p, csz), cr, csh)));
p+= csz;
}
ptr_dec(csh);
@ -47,8 +46,7 @@ B toKCells(B x, ur k) {
M_HARR(r, cam);
usz p = 0;
for (usz i = 0; i < cam; i++) {
Arr* s = slice(incG(x), p, csz); arr_shSetI(s, cr, csh);
HARR_ADD(r, i, taga(s));
HARR_ADD(r, i, taga(arr_shSetI(slice(incG(x), p, csz), cr, csh)));
p+= csz;
}
if (cr>1) ptr_dec(csh);