From 8a132467d2ccb5eb1acf81bf2a06c8e0a2d511fc Mon Sep 17 00:00:00 2001 From: dzaima Date: Wed, 28 Dec 2022 22:27:30 +0200 Subject: [PATCH] =?UTF-8?q?improve=20EACH=5FFILLS=20cases=20in=20=C2=A8=20?= =?UTF-8?q?&=20=E2=8C=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/md1.c | 59 ++++++++++++++++++++++++++++++---------------- src/utils/each.h | 16 ------------- 2 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/builtins/md1.c b/src/builtins/md1.c index e0050eb0..65c5dd8d 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -6,11 +6,11 @@ -static B homFil1(B f, B r, B xf) { +static NOINLINE B homFil1(B f, B r, B xf) { assert(EACH_FILLS); if (isPureFn(f)) { - if (f.u==bi_eq.u || f.u==bi_ne.u || f.u==bi_feq.u) { dec(xf); return toI32Any(r); } // ≠ may return ≥2⋆31, but whatever, this thing is stupid anyway - if (f.u==bi_fne.u) { dec(xf); return withFill(r, m_harrUv(0).b); } + if (f.u==bi_eq.u || f.u==bi_ne.u || f.u==bi_feq.u) { dec(xf); return num_squeeze(r); } + if (f.u==bi_fne.u) { dec(xf); return withFill(r, emptyHVec()); } if (!noFill(xf)) { if (CATCH) { freeThrown(); return r; } B rf = asFill(c1(f, xf)); @@ -21,10 +21,10 @@ static B homFil1(B f, B r, B xf) { dec(xf); return r; } -static B homFil2(B f, B r, B wf, B xf) { +static NOINLINE B homFil2(B f, B r, B wf, B xf) { assert(EACH_FILLS); if (isPureFn(f)) { - if (f.u==bi_feq.u || f.u==bi_fne.u) { dec(wf); dec(xf); return toI32Any(r); } + if (f.u==bi_feq.u || f.u==bi_fne.u) { dec(wf); dec(xf); return num_squeeze(r); } if (!noFill(wf) && !noFill(xf)) { if (CATCH) { freeThrown(); return r; } B rf = asFill(c2(f, wf, xf)); @@ -36,18 +36,30 @@ static B homFil2(B f, B r, B wf, B xf) { return r; } -B tbl_c1(Md1D* d, B x) { B f = d->f; - if (!EACH_FILLS) return eachm(f, x); - B xf = getFillQ(x); - return homFil1(f, eachm(f, x), xf); +B each_c1(Md1D* d, B x) { B f = d->f; + B r, xf; + if (EACH_FILLS) xf = getFillQ(x); + + if (isAtm(x)) r = m_hunit(c1(f, x)); + else if (isFun(f)) r = eachm_fn(f, x, c(Fun,f)->c1); + else { + if (isMd(f)) if (isAtm(x) || IA(x)) { decR(x); thrM("Calling a modifier"); } + usz ia = IA(x); + MAKE_MUT(rm, ia); + mut_fill(rm, 0, f, ia); + r = mut_fcd(rm, x); + } + + if (EACH_FILLS) return homFil1(f, r, xf); + else return r; +} +B tbl_c1(Md1D* d, B x) { + return each_c1(d, x); } B slash_c2(B f, B w, B x); B shape_c2(B f, B w, B x); B tbl_c2(Md1D* d, B w, B x) { B f = d->f; - B wf, xf; - if (EACH_FILLS) wf = getFillQ(w); - if (EACH_FILLS) xf = getFillQ(x); if (isAtm(w)) w = m_atomUnit(w); if (isAtm(x)) x = m_atomUnit(x); ur wr = RNK(w); usz wia = IA(w); @@ -59,7 +71,7 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f; usz* rsh; BBB2B fc2 = c2fn(f); - if (!EACH_FILLS && isFun(f) && isPervasiveDy(f) && TI(w,arrD1)) { + if (isFun(f) && isPervasiveDy(f) && TI(w,arrD1)) { if (TI(x,arrD1) && wia>130 && xia<2560>>arrTypeBitsLog(TY(x))) { Arr* wd = arr_shVec(TI(w,slice)(incG(w), 0, wia)); r = fc2(f, slash_c2(f, m_i32(xia), taga(wd)), shape_c2(f, m_f64(ria), incG(x))); @@ -90,16 +102,23 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f; shcpy(rsh , SH(w), wr); shcpy(rsh+wr, SH(x), xr); } - decG(w); decG(x); - if (EACH_FILLS) return homFil2(f, r, wf, xf); - return r; + B wf, xf; + if (EACH_FILLS) { + assert(isArr(w)); wf=getFillQ(w); + assert(isArr(x)); xf=getFillQ(x); + decG(w); decG(x); + return homFil2(f, r, wf, xf); + } else { + decG(w); decG(x); + return r; + } } -B each_c1(Md1D* d, B x) { B f = d->f; - if (!EACH_FILLS) return eachm(f, x); - B xf = getFillQ(x); - return homFil1(f, eachm(f, x), xf); +static B eachd(B f, B w, B x) { + if (isAtm(w) & isAtm(x)) return m_hunit(c2(f, w, x)); + return eachd_fn(f, w, x, c2fn(f)); } + B each_c2(Md1D* d, B w, B x) { B f = d->f; if (!EACH_FILLS) return eachd(f, w, x); B wf = getFillQ(w); diff --git a/src/utils/each.h b/src/utils/each.h index 9f99f328..84ae2b4f 100644 --- a/src/utils/each.h +++ b/src/utils/each.h @@ -4,22 +4,6 @@ B eachd_fn(B fo, B w, B x, BBB2B f); // consumes w,x; assumes at least one is array B eachm_fn(B fo, B x, BB2B f); // consumes x; x must be array -static B eachm(B f, B x) { // complete F¨ x without fills; consumes x - if (isAtm(x)) return m_hunit(c1(f, x)); - if (isFun(f)) return eachm_fn(f, x, c(Fun,f)->c1); - if (isMd(f)) if (isAtm(x) || IA(x)) { decR(x); thrM("Calling a modifier"); } - - usz ia = IA(x); - MAKE_MUT(r, ia); - mut_fill(r, 0, f, ia); - return mut_fcd(r, x); -} - -static B eachd(B f, B w, B x) { // complete w F¨ x without fills; consumes w,x - if (isAtm(w) & isAtm(x)) return m_hunit(c2(f, w, x)); - return eachd_fn(f, w, x, c2fn(f)); -} - #if CATCH_ERRORS NOINLINE B arith_recd(BBB2B f, B w, B x);