From 3dd1bffe2f2d4048274b21126d3422103a200a39 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 29 May 2022 13:57:03 +0300 Subject: [PATCH] don't unroll arr_csz --- src/builtins/md1.c | 2 +- src/builtins/sfns.c | 2 +- src/core/stuff.c | 2 +- src/core/stuff.h | 6 +++--- src/utils/each.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/builtins/md1.c b/src/builtins/md1.c index c160d3a8..145f620b 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -225,7 +225,7 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f; if (isArr(w)) { ur wr = rnk(w); usz* wsh = a(w)->sh; SGet(w) - if (wr+1!=xr || !eqShPrefix(wsh, xsh+1, wr)) thrF("`: Shape of 𝕨 must match the cell of 𝕩 (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); + if (wr+1!=xr || !eqShPart(wsh, xsh+1, wr)) thrF("`: Shape of 𝕨 must match the cell of 𝕩 (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); if (ia==0) return x; usz csz = arr_csz(x); for (; i < csz; i++) r.a[i] = fc2(f, Get(w,i), xget(xa,i)); diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 141ae053..1df7d6de 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -1281,7 +1281,7 @@ static B takedrop_ucw(i64 wi, B o, u64 am, B x, size_t xr) { B rep = c1(o, taga(arg)); if (isAtm(rep)) thrM("π”½βŒΎ(nβŠΈβ†‘): 𝔽 returned an atom"); usz* repsh = a(rep)->sh; - if (rnk(rep)==0 || !eqShPrefix(repsh+1, a(x)->sh+1, xr-1) || repsh[0]!=am) thrM("π”½βŒΎ(nβŠΈβ†‘)𝕩: 𝔽 returned an array with a different shape than n↑𝕩"); + if (rnk(rep)==0 || !eqShPart(repsh+1, a(x)->sh+1, xr-1) || repsh[0]!=am) thrM("π”½βŒΎ(nβŠΈβ†‘)𝕩: 𝔽 returned an array with a different shape than n↑𝕩"); MAKE_MUT(r, xia); mut_init(r, el_or(TI(x,elType), TI(rep,elType))); MUTG_INIT(r); diff --git a/src/core/stuff.c b/src/core/stuff.c index d38d3182..b9f52c2f 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -762,7 +762,7 @@ B bqn_merge(B x) { usz rp = 0; for (usz i = 0; i < xia; i++) { B c = GetU(x, i); - if (isArr(c)? (elR!=rnk(c) || !eqShPrefix(elSh, a(c)->sh, elR)) : elR!=0) { mut_pfree(r, rp); thrF(">: Elements didn't have equal shapes (contained shapes %H and %H)", x0, c); } + if (isArr(c)? (elR!=rnk(c) || !eqShPart(elSh, a(c)->sh, elR)) : elR!=0) { mut_pfree(r, rp); thrF(">: Elements didn't have equal shapes (contained shapes %H and %H)", x0, c); } if (isArr(c)) mut_copy(r, rp, c, 0, elIA); else mut_set(r, rp, inc(c)); if (!noFill(fill)) fill = fill_or(fill, getFillQ(c)); diff --git a/src/core/stuff.h b/src/core/stuff.h index 104a00ac..814a89ba 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -86,10 +86,10 @@ static usz arr_csz(B x) { if (xr<=1) return 1; usz* sh = a(x)->sh; usz r = 1; - for (i32 i = 1; i < xr; i++) r*= sh[i]; + NOUNROLL for (i32 i = 1; i < xr; i++) r*= sh[i]; return r; } -static bool eqShPrefix(usz* w, usz* x, ur len) { +static bool eqShPart(usz* w, usz* x, usz len) { return memcmp(w, x, len*sizeof(usz))==0; } static bool eqShape(B w, B x) { assert(isArr(w)); assert(isArr(x)); @@ -97,7 +97,7 @@ static bool eqShape(B w, B x) { assert(isArr(w)); assert(isArr(x)); ur xr = rnk(x); usz* xsh = a(x)->sh; if (wr!=xr) return false; if (wsh==xsh) return true; - return eqShPrefix(wsh, xsh, wr); + return eqShPart(wsh, xsh, wr); } B bit_sel(B b, B e0, bool h0, B e1, bool h1); // consumes b; h0/h1 represent whether the corresponding element _might_ be in the result (can be true if unknown) diff --git a/src/utils/each.c b/src/utils/each.c index eabbff5e..2761bd14 100644 --- a/src/utils/each.c +++ b/src/utils/each.c @@ -17,7 +17,7 @@ B eachd_fn(BBB2B f, B fo, B w, B x) { decG(w); decG(x); return m_hunit(r); } - if (rm && !eqShPrefix(a(w)->sh, a(x)->sh, rm)) thrF("Mapping: Expected equal shape prefix (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); + if (rm && !eqShPart(a(w)->sh, a(x)->sh, rm)) thrF("Mapping: Expected equal shape prefix (%H ≑ ≒𝕨, %H ≑ ≒𝕩)", w, x); bool rw = rM==wr && ((v(w)->type==t_harr) & reusable(w)); // v(…) is safe as rank>0 bool rx = rM==xr && ((v(x)->type==t_harr) & reusable(x)); if (rw|rx && (wr==xr | rm==0)) {