more comparison type fixing

and some more / opt to make it not slower
This commit is contained in:
dzaima 2021-07-20 21:56:35 +03:00
parent 99896fbace
commit 0bcf3b592f
9 changed files with 37 additions and 34 deletions

View File

@ -75,7 +75,7 @@ B repeat_replace(B g, B* q) { // doesn't consume
} \
i64 bound[2] = {0,0}; \
repeat_bounds(bound, g); \
u64 min=(u64)-bound[0]; u64 max=(u64)bound[1]; \
i64 min=(u64)-bound[0]; i64 max=(u64)bound[1]; \
TALLOC(B, all, min+max+1); \
B* q = all+min; \
q[0] = inc(x); \
@ -86,11 +86,11 @@ B repeat_replace(B g, B* q) { // doesn't consume
dec(x2); \
dec(fi); \
} \
for (u64 i = 0; i < max; i++) q[i+1] = inc(x = CN(f, __VA_ARGS__ x)); \
for (i64 i = 0; i < max; i++) q[i+1] = inc(x = CN(f, __VA_ARGS__ x)); \
dec(x); \
B r = repeat_replace(g, q); \
dec(g); \
for (u64 i = 0; i < min+max+1; i++) dec(all[i]); \
for (i64 i = 0; i < min+max+1; i++) dec(all[i]); \
END; TFREE(all); \
return r;

View File

@ -208,7 +208,7 @@ B slash_c1(B t, B x) {
if (TI(x,elType)==el_i32) {
i32* xp = i32any_ptr(x);
while (xia>0 && !xp[xia-1]) xia--;
for (i32 i = 0; i < xia; i++) {
for (u64 i = 0; i < xia; i++) {
i32 c = xp[i];
if (LIKELY(c==0 || c==1)) {
*rp = i;
@ -284,8 +284,8 @@ B slash_c2(B t, B w, B x) {
for (usz i = 0; i < wia; i++) {
i32 cw = wp[i];
if (cw==0) continue;
B cx = xgetU(x, i);
for (i64 j = 0; j < cw; j++) r.a[ri++] = inc(cx);
B cx = incBy(xgetU(x, i), cw);
for (i64 j = 0; j < cw; j++) r.a[ri++] = cx;
}
dec(w); dec(x);
return withFill(harr_fv(r), xf);
@ -299,8 +299,8 @@ B slash_c2(B t, B w, B x) {
for (usz i = 0; i < wia; i++) {
usz c = o2s(wgetU(w, i));
if (c) {
B cx = xgetU(x, i);
for (usz j = 0; j < c; j++) r.a[ri++] = inc(cx);
B cx = incBy(xgetU(x, i), c);
for (usz j = 0; RARE(j < c); j++) *r.a++ = cx;
}
}
dec(w); dec(x);
@ -316,12 +316,11 @@ B slash_c2(B t, B w, B x) {
arr_shVec(r,0);
return taga(r);
}
usz ri = 0;
if (TI(x,elType)==el_i32) {
i32* xp = i32any_ptr(x);
i32* rp; B r = m_i32arrv(&rp, xia*wv);
for (usz i = 0; i < xia; i++) {
for (usz j = 0; j < wv; j++) rp[ri++] = xp[i];
for (i64 j = 0; j < wv; j++) *rp++ = xp[i];
}
dec(x);
return r;
@ -330,8 +329,8 @@ B slash_c2(B t, B w, B x) {
HArr_p r = m_harrUv(xia*wv);
BS2B xgetU = TI(x,getU);
for (usz i = 0; i < xia; i++) {
B cx = xgetU(x, i);
for (usz j = 0; j < wv; j++) r.a[ri++] = inc(cx);
B cx = incBy(xgetU(x, i), wv);
for (i64 j = 0; j < wv; j++) *r.a++ = cx;
}
dec(x);
return withFill(r.b, xf);

View File

@ -225,7 +225,7 @@ B rand_range_c2(B t, B w, B x) {
f64* rp; r = m_f64arrv(&rp, am);
for (usz i = 0; i < am; i++) rp[i] = wy2u01(wyrand(&seed));
} else if (max > I32_MAX) {
if (max >= 1ULL<<53) thrM("(rand).Range: 𝕩 must be less than 2⋆53");
if (max >= 1LL<<53) thrM("(rand).Range: 𝕩 must be less than 2⋆53");
f64* rp; r = m_f64arrv(&rp, am);
for (usz i = 0; i < am; i++) rp[i] = wy2u0k(wyrand(&seed), max);
} else {
@ -281,12 +281,12 @@ B rand_deal_c2(B t, B w, B x) {
i64 sz = 1;
while (sz < wi*2) sz*= 2;
TALLOC(i32, hash, 2*sz); i32* val = hash+1;
for (u64 i = 0; i < 2*sz; i++) hash[i] = 0;
for (i64 i = 0; i < 2*sz; i++) hash[i] = 0;
for (i64 i = 0; i < wi; i++) rp[i] = i;
u64 mask = 2*(sz-1);
for (i64 i = 0; i < wi; i++) {
u64 j = wy2u0k(wyrand(&seed), xi-i) + i;
if (j<wi) {
if (j<(u64)wi) {
i32 c = rp[j];
rp[j] = rp[i];
rp[i] = c;
@ -294,11 +294,11 @@ B rand_deal_c2(B t, B w, B x) {
u64 p = 2*j;
i32 prev = j;
while (true) {
p &= mask;
p&= mask;
i32 h = hash[p];
if (h==0) { hash[p] = j; break; }
if (h==j) { prev = val[p]; break; }
p += 2;
if ((u64)h==j) { prev = val[p]; break; }
p+= 2;
}
val[p] = rp[i];
rp[i] = prev;
@ -320,7 +320,7 @@ B rand_subset_c2(B t, B w, B x) {
B r;
if (wi==xi) { // Only one complete subset; will hang without this
i32* rp; r = m_i32arrv(&rp, wi);
for (u64 i = 0; i < wi; i++) rp[i] = i;
for (i64 i = 0; i < wi; i++) rp[i] = i;
return r;
}
RAND_START;
@ -329,20 +329,20 @@ B rand_subset_c2(B t, B w, B x) {
TALLOC(u8, set, xi);
bool invert = wi > xi/2;
i32 wn = invert ? xi-wi : wi;
for (u64 i = 0; i < xi; i++) set[i] = 0;
for (i64 i = 0; i < xi; i++) set[i] = 0;
for (i32 i = xi-wn; i < xi; i++) {
i32 j = wy2u0k(wyrand(&seed), i+1);
if (set[j]) j=i;
set[j] = 1;
}
i32* rp; r = m_i32arrv(&rp, wi);
if (!invert) { for (u64 i = 0; i < xi; i++) if ( set[i]) *rp++=i; }
else { for (u64 i = 0; i < xi; i++) if (!set[i]) *rp++=i; }
if (!invert) { for (i64 i = 0; i < xi; i++) if ( set[i]) *rp++=i; }
else { for (i64 i = 0; i < xi; i++) if (!set[i]) *rp++=i; }
TFREE(set);
} else {
// Sorted "hash" set
u64 sh = 0;
for (u64 xt=xi/4; xt>=wi; xt>>=1) sh++;
for (u64 xt=xi/4; xt>=(u64)wi; xt>>=1) sh++;
u64 sz = ((xi-1)>>sh)+1 + wi;
TALLOC(i32, hash, sz);
for (u64 i = 0; i < sz; i++) hash[i] = xi;

View File

@ -22,7 +22,7 @@ static void gsReserve(u64 am) {
gStackEnd = gStackStart+n;
}
#elif DEBUG
if (am>gStackEnd-gStack) thrM("Stack overflow");
if ((i64)am > gStackEnd-gStack) thrM("Stack overflow");
#endif
}

View File

@ -422,6 +422,10 @@ static B inc(B x) {
if (isVal(VALIDATE(x))) v(x)->refc++;
return x;
}
static B incBy(B x, i64 am) {
if (isVal(VALIDATE(x))) v(x)->refc+= am;
return x;
}
static void ptr_inc(void* x) { VALIDATEP((Value*)x)->refc++; }

View File

@ -376,7 +376,7 @@ static OptRes opt(u32* bc0) {
TSADDA(rbc, sbc, ebc-sbc);
}
u64 added = TSSIZE(rbc)-psz;
for (i32 i = 0; i < added; i++) TSADD(roff, sbc-bc0);
for (u64 i = 0; i < added; i++) TSADD(roff, sbc-bc0);
#undef A64
if (ret) break;
bc = ebc;

View File

@ -129,7 +129,7 @@ int main(int argc, char* argv[]) {
args = emptySVec();
} else {
HArr_p ap = m_harrUv(argc-i); // eh whatever, erroring will exit anyways
for (usz j = 0; j < argc-i; j++) {
for (i64 j = 0; j < argc-i; j++) {
ap.a[j] = fromUTF8l(argv[i+j]);
}
args = ap.b;

View File

@ -41,7 +41,7 @@ B ns_getU(B ns, B cNL, i32 nameID) { VTY(ns, t_ns);
NS* n = c(NS, ns);
NSDesc* d = n->desc;
i32 dVarAm = d->varAm;
assert(nameID<a(cNL)->ia && nameID>=0);
assert((u64)nameID < a(cNL)->ia && nameID>=0);
B dNL = d->nameList;
if (cNL.u != dNL.u) {
B cName = TI(cNL,getU)(cNL, nameID);

View File

@ -217,9 +217,9 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl
i32 mpsc = 0;
if (depth==0 && sc && vam > sc->varAm) {
if (boIA==2) thrM("VM compiler: Full block info must be provided for extending scopes");
i32 regAm = sc->varAm;
u32 regAm = sc->varAm;
ScopeExt* oE = sc->ext;
if (oE==NULL || vam > regAm + oE->varAm) {
if (oE==NULL || vam > regAm+oE->varAm) {
i32 nSZ = vam - regAm;
ScopeExt* nE = mm_alloc(fsizeof(ScopeExt, vars, B, nSZ*2), t_scopeExt);
nE->varAm = nSZ;
@ -311,7 +311,7 @@ Block* compileBlock(B block, Comp* comp, bool* bDone, u32* bc, usz bcIA, B allBl
m_nsDesc(body, imm, ty, inc(nameList), biGetU(bodyRepr,2), biGetU(bodyRepr,3));
} else {
body->nsDesc = NULL;
for (i32 i = 0; i < vam; i++) body->varIDs[i] = -1;
for (u64 i = 0; i < vam; i++) body->varIDs[i] = -1;
}
TSADD(bodies, body);
@ -697,7 +697,7 @@ Scope* m_scope(Body* body, Scope* psc, u16 varAm, i32 initVarAm, B* initVars) {
static void scope_dec(Scope* sc) {
i32 varAm = sc->varAm;
if (sc->refc>1) {
usz innerRef = 1;
i32 innerRef = 1;
for (i32 i = 0; i < varAm; i++) {
B c = sc->vars[i];
if (isVal(c) && v(c)->refc==1) {
@ -707,7 +707,7 @@ static void scope_dec(Scope* sc) {
else if (t==t_md2_block && c(Md2Block,c)->sc==sc) innerRef++;
}
}
assert(innerRef<=sc->refc);
assert(innerRef <= sc->refc);
if (innerRef==sc->refc) {
value_free((Value*)sc);
return;
@ -958,8 +958,8 @@ NOINLINE B vm_fmtPoint(B src, B prepend, B path, usz cs, usz ce) { // consumes p
ce-= srcS;
ACHR('\n');
for (i64 i = padStart; i < padEnd; i++) ACHR(' ');
for (i32 i = 0; i < cs; i++) ACHR(o2cu(srcGetU(src, srcS+i))=='\t'? '\t' : ' '); // ugh tabs
for (i32 i = cs; i < ce; i++) ACHR('^');
for (u64 i = 0; i < cs; i++) ACHR(o2cu(srcGetU(src, srcS+i))=='\t'? '\t' : ' '); // ugh tabs
for (u64 i = cs; i < ce; i++) ACHR('^');
return s;
}