squeeze result of ⊒𝕩, copy result of ⊐𝕩 to smaller width when possible

This commit is contained in:
dzaima 2023-01-27 02:56:56 +02:00
parent ae4c4a03ee
commit ea0aa709fe
2 changed files with 13 additions and 9 deletions

View File

@ -61,7 +61,7 @@ static NOINLINE B2 splitCells(B n, B p, u8 mode) { // 0:∊ 1:⊐ 2:⊒
#undef SYMB
}
static B reduceWidth(B r, usz count) {
static B reduceI32Width(B r, usz count) {
return count<=I8_MAX? taga(cpyI8Arr(r)) : count<=I16_MAX? taga(cpyI16Arr(r)) : r;
}
@ -127,7 +127,7 @@ B indexOf_c2(B t, B w, B x) {
if (xia+wia>20 && we<=el_i16 && xe<=el_i16) {
B r;
TABLE(w, x, i32, wia, i)
return reduceWidth(r, wia);
return reduceI32Width(r, wia);
}
i32* rp; B r = m_i32arrc(&rp, x);
H_b2i* map = m_b2i(64);
@ -139,7 +139,7 @@ B indexOf_c2(B t, B w, B x) {
}
for (usz i = 0; i < xia; i++) rp[i] = getD_b2i(map, GetU(x,i), wia);
free_b2i(map); decG(w); decG(x);
return reduceWidth(r, wia);
return reduceI32Width(r, wia);
}
}
@ -266,7 +266,7 @@ B count_c2(B t, B w, B x) {
free_b2i(map);
}
TFREE(wnext); decG(w); decG(x);
return reduceWidth(r, wia);
return reduceI32Width(r, wia);
}

View File

@ -244,7 +244,7 @@ B memberOf_c1(B t, B x) {
else for (usz j=0; j<tn; j++) tab[j]=1; \
for (usz i=0; i<n; i++) { u##T j=xp[i]; rp[i]=tab[j]; tab[j]=0; } \
decG(x); TFREE(tab); \
return num_squeeze(r)
return taga(cpyBitArr(r))
if (lw == 3) { if (n<8) { BRUTE(8); } else { LOOKUP(8); } }
if (lw == 4) { if (n<8) { BRUTE(16); } else { LOOKUP(16); } }
#undef LOOKUP
@ -403,7 +403,11 @@ B count_c1(B t, B x) {
rp[i] = had? ++map->a[p].val : (map->a[p].val = 0);
}
decG(x); free_b2i(map);
return r;
return num_squeeze(r);
}
static B reduceI32WidthBelow(B r, usz after) {
return after<=2? taga(cpyBitArr(r)) : after<=I8_MAX+1? taga(cpyI8Arr(r)) : after<=I16_MAX+1? taga(cpyI16Arr(r)) : r;
}
B indexOf_c1(B t, B x) {
@ -431,7 +435,7 @@ B indexOf_c1(B t, B x) {
rp[i]=s; u+=u==s; \
} \
decG(x); TFREE(uniq); return r;
#define DOTAB(T) \
#define DOTAB(T) /*leaves 1+max in u */ \
i32 u=0; \
for (usz i=0; i<n; i++) { \
T j=xp[i]; i32 t=tab[j]; \
@ -476,7 +480,7 @@ B indexOf_c1(B t, B x) {
DOTAB(i32)
TFREE(tmp);
decG(x);
return r;
return reduceI32WidthBelow(r, u);
}
HASHTAB(u32, 32, sz==msz? 0 : sz>=(1<<18)? 1 : sz>=(1<<14)? 4 : 6)
decG(r); // Fall through
@ -503,7 +507,7 @@ B indexOf_c1(B t, B x) {
else rp[i] = map->a[p].val = ctr++;
}
free_b2i(map); decG(x);
return r;
return reduceI32WidthBelow(r, ctr);
}
B find_c1(B t, B x) {