From c0cf58ffc2a2080887dfe977afd5d33b96257ed0 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 18 Sep 2022 20:17:20 +0300 Subject: [PATCH 1/5] use existing function for 8-bit utf8Decode --- src/utils/utf.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/utils/utf.c b/src/utils/utf.c index 4bfba65d..1cb77491 100644 --- a/src/utils/utf.c +++ b/src/utils/utf.c @@ -34,9 +34,7 @@ B utf8Decode(const char* s, i64 len) { j+= l; } if (sz==len) { - u8* rp; B r = m_c8arrv(&rp, sz); - for (i64 i = 0; i < len; i++) rp[i] = s[i]; - return r; + return m_c8vec((char*)s, len); } else { u32* rp; B r = m_c32arrv(&rp, sz); u64 p = 0; From 770f7b2f0cc60282cfef364baa81dc19aadf38ba Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 18 Sep 2022 20:17:48 +0300 Subject: [PATCH 2/5] check type directly in pick_ucw --- src/builtins/sfns.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index ffb26c30..1dc3453a 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -1167,16 +1167,17 @@ B pick_ucw(B t, B o, B w, B x) { B arg = IGet(x, wi); B rep = c1(o, arg); if (reusable(x) && TI(x,canStore)(rep)) { REUSE(x); - if (TI(x,elType)==el_i8 ) { i8* xp = i8any_ptr (x); xp[wi] = o2iG(rep); return x; } - else if (TI(x,elType)==el_i16) { i16* xp = i16any_ptr(x); xp[wi] = o2iG(rep); return x; } - else if (TI(x,elType)==el_i32) { i32* xp = i32any_ptr(x); xp[wi] = o2iG(rep); return x; } - else if (TI(x,elType)==el_f64) { f64* xp = f64any_ptr(x); xp[wi] = o2fG(rep); return x; } - else if (TY(x)==t_harr) { + u8 xt = TY(x); + if (xt==t_i8arr ) { i8* xp = i8any_ptr (x); xp[wi] = o2iG(rep); return x; } + else if (xt==t_i16arr) { i16* xp = i16any_ptr(x); xp[wi] = o2iG(rep); return x; } + else if (xt==t_i32arr) { i32* xp = i32any_ptr(x); xp[wi] = o2iG(rep); return x; } + else if (xt==t_f64arr) { f64* xp = f64any_ptr(x); xp[wi] = o2fG(rep); return x; } + else if (xt==t_harr) { B* xp = harr_ptr(x); dec(xp[wi]); xp[wi] = rep; return x; - } else if (TY(x)==t_fillarr) { + } else if (xt==t_fillarr) { B* xp = fillarr_ptr(a(x)); dec(xp[wi]); xp[wi] = rep; From dd56cfab2077547c00de0cee572ace2d77ad4f56 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 18 Sep 2022 21:00:51 +0300 Subject: [PATCH 3/5] =?UTF-8?q?allow=20using=20picked=20element=20of=20?= =?UTF-8?q?=E2=8C=BE(n=E2=8A=B8=E2=8A=91)=20in-place?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/sfns.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/builtins/sfns.c b/src/builtins/sfns.c index 1dc3453a..7bd9a125 100644 --- a/src/builtins/sfns.c +++ b/src/builtins/sfns.c @@ -1164,6 +1164,27 @@ B pick_ucw(B t, B o, B w, B x) { if (isArr(w) || isAtm(x) || RNK(x)!=1) return def_fn_ucw(t, o, w, x); usz xia = IA(x); usz wi = WRAP(o2i64(w), xia, thrF("π”½βŒΎ(nβŠΈβŠ‘)𝕩: reading out-of-bounds (n≑%R, %s≑≠𝕩)", w, xia)); + if (TI(x,elType)==el_B) { + B* xp; + if (TY(x)==t_harr || TY(x)==t_hslice) { + if (!(TY(x)==t_harr && reusable(x))) x = taga(cpyHArr(x)); + xp = harr_ptr(x); + } else if (TY(x)==t_fillarr && reusable(x)) { + xp = fillarr_ptr(a(x)); + } else { + Arr* x2 = m_fillarrp(xia); + fillarr_setFill(x2, getFillQ(x)); + xp = fillarr_ptr(x2); + COPY_TO(xp, el_B, 0, x, 0, xia); + arr_shCopy(x2, x); + dec(x); + x = taga(x2); + } + B c = xp[wi]; + xp[wi] = m_f64(0); + xp[wi] = c1(o, c); + return x; + } B arg = IGet(x, wi); B rep = c1(o, arg); if (reusable(x) && TI(x,canStore)(rep)) { REUSE(x); @@ -1172,17 +1193,9 @@ B pick_ucw(B t, B o, B w, B x) { else if (xt==t_i16arr) { i16* xp = i16any_ptr(x); xp[wi] = o2iG(rep); return x; } else if (xt==t_i32arr) { i32* xp = i32any_ptr(x); xp[wi] = o2iG(rep); return x; } else if (xt==t_f64arr) { f64* xp = f64any_ptr(x); xp[wi] = o2fG(rep); return x; } - else if (xt==t_harr) { - B* xp = harr_ptr(x); - dec(xp[wi]); - xp[wi] = rep; - return x; - } else if (xt==t_fillarr) { - B* xp = fillarr_ptr(a(x)); - dec(xp[wi]); - xp[wi] = rep; - return x; - } + else if (xt==t_c8arr ) { u8* xp = c8any_ptr (x); xp[wi] = o2cG(rep); return x; } + else if (xt==t_c16arr) { u16* xp = c16any_ptr(x); xp[wi] = o2cG(rep); return x; } + else if (xt==t_c32arr) { u32* xp = c32any_ptr(x); xp[wi] = o2cG(rep); return x; } } MAKE_MUT(r, xia); mut_init(r, el_or(TI(x,elType), selfElType(rep))); MUTG_INIT(r); From 43ddb9759ceff69a278a13b3ff6513e31a087ab7 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 18 Sep 2022 21:58:53 +0300 Subject: [PATCH 4/5] inline part of depth --- src/core/stuff.c | 4 +--- src/core/stuff.h | 6 ++++++ src/h.h | 1 - 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/core/stuff.c b/src/core/stuff.c index fa8fc6a0..ceeba136 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -565,9 +565,7 @@ bool eequal(B w, B x) { // doesn't consume return true; } -u64 depth(B x) { // doesn't consume - if (isAtm(x)) return 0; - if (TI(x,arrD1)) return 1; +usz depthF(B x) { // doesn't consume u64 r = 0; usz ia = IA(x); SGetU(x) diff --git a/src/core/stuff.h b/src/core/stuff.h index c487e920..2b53734f 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -215,6 +215,12 @@ static bool atomEqual(B w, B x) { // doesn't consume return atomEqualF(w, x); } +NOINLINE usz depthF(B x); +static usz depth(B x) { // doesn't consume + if (isAtm(x)) return 0; + if (TI(x,arrD1)) return 1; + return depthF(x); +} diff --git a/src/h.h b/src/h.h index 7ffb24d1..25687256 100644 --- a/src/h.h +++ b/src/h.h @@ -338,7 +338,6 @@ void printRaw(B x); // doesn't consume void arr_print(B x); // doesn't consume bool equal(B w, B x); // doesn't consume bool eequal(B w, B x); // doesn't consume -u64 depth(B x); // doesn't consume B toCells(B x); // consumes B toKCells(B x, ur k); // consumes B withFill(B x, B f); // consumes both From 9453a9b665003241ded4c0ea1ba7b3542206791f Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 18 Sep 2022 22:11:16 +0300 Subject: [PATCH 5/5] =?UTF-8?q?remove=20old=20loops=20for=20non-bitarr=20?= =?UTF-8?q?=F0=9D=95=A8=20consisting=20of=200=20and=201=20from=20?= =?UTF-8?q?=F0=9D=95=A8/=F0=9D=95=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins/slash.c | 70 +++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/src/builtins/slash.c b/src/builtins/slash.c index 437f9480..6058c154 100644 --- a/src/builtins/slash.c +++ b/src/builtins/slash.c @@ -417,57 +417,61 @@ B slash_c2(B t, B w, B x) { } B xf = getFillQ(x); + B r; if (TI(w,elType)==el_bit) { - B r = compress(w, x, wia, xf); + compress: + r = compress(w, x, wia, xf); + decWX_ret: decG(w); decG(x); return r; + + to_compress: + wia = xia; + w = taga(cpyBitArr(w)); + goto compress; } #define CASE(WT,XT) if (TI(x,elType)==el_##XT) { \ XT* xp = XT##any_ptr(x); \ - XT* rp; B r = m_##XT##arrv(&rp, wsum); \ - if (or<2) for (usz i = 0; i < wia; i++) { \ - *rp = xp[i]; \ - rp+= wp[i]; \ - } else for (usz i = 0; i < wia; i++) { \ + XT* rp; r = m_##XT##arrv(&rp, wsum); \ + for (usz i = 0; i < wia; i++) { \ WT cw = wp[i]; XT cx = xp[i]; \ for (i64 j = 0; j < cw; j++) *rp++ = cx; \ } \ - decG(w); decG(x); return r; \ + goto decWX_ret; \ } - #define TYPED(WT,SIGN) { \ + + #define TYPED(WT,WTU,SIGN) { \ WT* wp = WT##any_ptr(w); \ while (wia>0 && !wp[wia-1]) wia--; \ i64 wsum = 0; \ - u32 or = 0; \ + WTU or = 0; \ for (usz i = 0; i < wia; i++) { \ wsum+= wp[i]; \ - or|= (u32)wp[i]; \ + or|= (WTU)wp[i]; \ } \ - if (or>>SIGN) thrM("/: 𝕨 must consist of natural numbers"); \ - if (TI(x,elType)==el_bit) { \ - u64* xp = bitarr_ptr(x); u64 ri=0; \ - u64* rp; B r = m_bitarrv(&rp, wsum); \ - if (or<2) for (usz i = 0; i < wia; i++) { \ - bitp_set(rp, ri, bitp_get(xp,i)); \ - ri+= wp[i]; \ - } else for (usz i = 0; i < wia; i++) { \ - WT cw = wp[i]; bool cx = bitp_get(xp,i); \ + if (RARE(or>>SIGN)) thrM("/: 𝕨 must consist of natural numbers"); \ + if (RARE(or<2)) goto to_compress; \ + if (TI(x,elType)==el_bit) { \ + u64* xp = bitarr_ptr(x); u64 ri=0; \ + u64* rp; r = m_bitarrv(&rp, wsum); \ + for (usz i = 0; i < wia; i++) { \ + WT cw = wp[i]; bool cx = bitp_get(xp,i); \ for (i64 j = 0; j < cw; j++) bitp_set(rp, ri++, cx); \ - } \ - decG(w); decG(x); return r; \ - } \ + } \ + decG(w); decG(x); return r; \ + } \ CASE(WT,i8) CASE(WT,i16) CASE(WT,i32) CASE(WT,f64) \ - SLOW2("𝕨/𝕩", w, x); \ - M_HARR(r, wsum) SGetU(x) \ - for (usz i = 0; i < wia; i++) { \ - i32 cw = wp[i]; if (cw==0) continue; \ - B cx = incBy(GetU(x, i), cw); \ - for (i64 j = 0; j < cw; j++) HARR_ADDA(r, cx);\ - } \ - decG(w); decG(x); \ - return withFill(HARR_FV(r), xf); \ + SLOW2("𝕨/𝕩", w, x); \ + M_HARR(r0, wsum) SGetU(x) \ + for (usz i = 0; i < wia; i++) { \ + i32 cw = wp[i]; if (cw==0) continue; \ + B cx = incBy(GetU(x, i), cw); \ + for (i64 j = 0; j < cw; j++) HARR_ADDA(r0, cx); \ + } \ + r = withFill(HARR_FV(r0), xf); goto decWX_ret; \ } - if (TI(w,elType)==el_i8 ) TYPED(i8,7); - if (TI(w,elType)==el_i32) TYPED(i32,31); + + if (TI(w,elType)==el_i8 ) TYPED(i8,u8,7); + if (TI(w,elType)==el_i32) TYPED(i32,u32,31); #undef TYPED #undef CASE SLOW2("𝕨/𝕩", w, x);