From aa5ed7cc7a99e761983d824d042243c88d1e1f08 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sat, 29 Apr 2023 15:31:16 +0300 Subject: [PATCH] =?UTF-8?q?BB2B=20&=20BBB2B=20=E2=86=92=20FC1=20&=20FC2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/builtins.h | 4 ++-- src/builtins/arithd.c | 2 +- src/builtins/arithm.c | 4 ++-- src/builtins/cells.c | 10 +++++----- src/builtins/cmp.c | 4 ++-- src/builtins/fold.c | 4 ++-- src/builtins/md1.c | 2 +- src/builtins/md2.c | 8 ++++---- src/builtins/scan.c | 4 ++-- src/core.h | 8 ++++---- src/core/stuff.h | 4 ++-- src/ffi.c | 2 +- src/h.h | 27 +++++++++++++++------------ src/jit/nvm_x86_64.c | 8 ++++---- src/load.c | 6 +++--- src/nfns.c | 2 +- src/nfns.h | 6 +++--- src/rtwrap.c | 4 ++-- src/singeli/c/arithdDispatch.c | 4 ++-- src/utils/each.c | 6 +++--- src/utils/each.h | 8 ++++---- 21 files changed, 65 insertions(+), 62 deletions(-) diff --git a/src/builtins.h b/src/builtins.h index 53b0692c..cec707fa 100644 --- a/src/builtins.h +++ b/src/builtins.h @@ -49,8 +49,8 @@ enum PrimNumbers { /* ´˝`∘○⊸⟜⌾⊘◶ */ n_fold , n_insert , n_scan , n_atop , n_over , n_before , n_after , n_under, n_val , n_cond, /* ⎉⚇⍟⎊ */ n_rank , n_depth , n_repeat, n_catch }; -extern BB2B rt_invFnRegFn; -extern BB2B rt_invFnSwapFn; +extern FC1 rt_invFnRegFn; +extern FC1 rt_invFnSwapFn; #ifdef RT_WRAP diff --git a/src/builtins/arithd.c b/src/builtins/arithd.c index b88c4c00..81cc50b2 100644 --- a/src/builtins/arithd.c +++ b/src/builtins/arithd.c @@ -231,7 +231,7 @@ static B modint_AS(B w, B xv) { return modint_AA(w, C2(shape, C1(fne, incG(w)) #undef SA_DISPATCH #else - static NOINLINE B bit_sel1Fn(BBB2B f, B w, B x, bool bitX) { // consumes both + static NOINLINE B bit_sel1Fn(FC2 f, B w, B x, bool bitX) { // consumes both B b = bitX? x : w; u64* bp = bitarr_ptr(b); usz ia = IA(b); diff --git a/src/builtins/arithm.c b/src/builtins/arithm.c index 83b51777..2728999f 100644 --- a/src/builtins/arithm.c +++ b/src/builtins/arithm.c @@ -5,7 +5,7 @@ #include "../ns.h" #include -static inline B arith_recm(BB2B f, B x) { +static inline B arith_recm(FC1 f, B x) { B fx = getFillQ(x); B r = eachm_fn(bi_N, x, f); return withFill(r, fx); @@ -146,7 +146,7 @@ f64 fact_inv(f64 y) { return logfact_inv(log(y)); } B pow_c1(B t, B x) { if (isF64(x)) return m_f64( exp(x.f)); P1( pow); thrM("⋆: Argument contained non-number"); } B log_c1(B t, B x) { if (isF64(x)) return m_f64( log(x.f)); P1( log); thrM("⋆⁼: Argument contained non-number"); } #undef P1 -static NOINLINE B arith_recm_slow(f64 (*fn)(f64), BB2B rec, B x, char* s) { +static NOINLINE B arith_recm_slow(f64 (*fn)(f64), FC1 rec, B x, char* s) { if (isF64(x)) return m_f64(fn(x.f)); if(isArr(x)) return arith_recm(rec, x); thrF("•math.%S: Argument contained non-number", s); diff --git a/src/builtins/cells.c b/src/builtins/cells.c index 3baaab81..190d7ee5 100644 --- a/src/builtins/cells.c +++ b/src/builtins/cells.c @@ -48,7 +48,7 @@ B insert_base(B f, B x, usz xia, bool has_w, B w) { p -= x_csz; r = SLICE(x, p); } - BBB2B fc2 = c2fn(f); + FC2 fc2 = c2fn(f); while(p!=0) { p-= x_csz; r = fc2(f, SLICE(x, p), r); @@ -384,7 +384,7 @@ B for_cells_c1(B f, u32 xr, u32 cr, u32 k, B x, u32 chr) { // F⎉cr x, with arr base:; M_APD_SH(r, k, xsh); - S_KSLICES(x, xsh, k, cam, 1); BB2B fc1 = c1fn(f); + S_KSLICES(x, xsh, k, cam, 1); FC1 fc1 = c1fn(f); for (usz i=0,xp=0; i0); incBy(x,l-1); \ - for (usz i=0; if; SLOW2("𝕎´ 𝕩", f, x); SGet(x) - BBB2B fc2 = c2fn(f); + FC2 fc2 = c2fn(f); B c; if (TI(x,elType)==el_i32) { i32* xp = i32any_ptr(x); @@ -285,7 +285,7 @@ B fold_c2(Md1D* d, B w, B x) { B f = d->f; B c = w; SGet(x) - BBB2B fc2 = c2fn(f); + FC2 fc2 = c2fn(f); for (usz i = ia; i>0; i--) c = fc2(f, Get(x, i-1), c); decG(x); return c; diff --git a/src/builtins/md1.c b/src/builtins/md1.c index 5a215841..c35b2d4d 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -71,7 +71,7 @@ B tbl_c2(Md1D* d, B w, B x) { B f = d->f; B r; usz* rsh; - BBB2B fc2 = c2fn(f); + FC2 fc2 = c2fn(f); if (isFun(f) && TI(w,arrD1) && isPervasiveDyExt(f)) { if (TI(x,arrD1) && wia>130 && xia<2560>>arrTypeBitsLog(TY(x))) { Arr* wd = arr_shVec(TI(w,slice)(incG(w), 0, wia)); diff --git a/src/builtins/md2.c b/src/builtins/md2.c index f89accd6..e6693ab8 100644 --- a/src/builtins/md2.c +++ b/src/builtins/md2.c @@ -185,14 +185,14 @@ B before_uc1(Md2* t, B o, B f, B g, B x) { B while_c1(Md2D* d, B x) { B f=d->f; B g=d->g; - BB2B ff = c1fn(f); - BB2B gf = c1fn(g); + FC1 ff = c1fn(f); + FC1 gf = c1fn(g); while (o2b(gf(g,inc(x)))) x = ff(f, x); return x; } B while_c2(Md2D* d, B w, B x) { B f=d->f; B g=d->g; - BBB2B ff = c2fn(f); - BBB2B gf = c2fn(g); + FC2 ff = c2fn(f); + FC2 gf = c2fn(g); while (o2b(gf(g,inc(w),inc(x)))) x = ff(f, inc(w), x); dec(w); return x; diff --git a/src/builtins/scan.c b/src/builtins/scan.c index c6690333..8f72ce12 100644 --- a/src/builtins/scan.c +++ b/src/builtins/scan.c @@ -218,7 +218,7 @@ B scan_c1(Md1D* d, B x) { B f = d->f; bool reuse = TY(x)==t_harr && reusable(x); HArr_p r = reuse? harr_parts(REUSE(x)) : m_harr0c(x); AS2B xget = reuse? TI(x,getU) : TI(x,get); Arr* xa = a(x); - BBB2B fc2 = c2fn(f); + FC2 fc2 = c2fn(f); if (xr==1) { r.a[0] = xget(xa,0); @@ -283,7 +283,7 @@ B scan_c2(Md1D* d, B w, B x) { B f = d->f; usz i = 0; HArr_p r = reuse? harr_parts(REUSE(x)) : m_harr0c(x); AS2B xget = reuse? TI(x,getU) : TI(x,get); Arr* xa = a(x); - BBB2B fc2 = c2fn(f); + FC2 fc2 = c2fn(f); if (isArr(w)) { ur wr = RNK(w); usz* wsh = SH(w); SGet(w) diff --git a/src/core.h b/src/core.h index 97e44a7a..84a7e5db 100644 --- a/src/core.h +++ b/src/core.h @@ -33,11 +33,11 @@ typedef struct BFn { struct Fun; B ident; - BBB2B uc1; + FC2 uc1; BBBB2B ucw; - BB2B im; - BBB2B iw; B rtInvSwap; - BBB2B ix; B rtInvReg; + FC1 im; + FC2 iw; B rtInvSwap; + FC2 ix; B rtInvReg; } BFn; typedef struct BMd1 { struct Md1; diff --git a/src/core/stuff.h b/src/core/stuff.h index 41119093..c4912940 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -322,12 +322,12 @@ B md_c1(B t, B x); B md_c2(B t, B w, B x); B arr_c1(B t, B x); B arr_c2(B t, B w, B x); -static BB2B c1fn(B f) { +static FC1 c1fn(B f) { if (isFun(f)) return c(Fun,f)->c1; if (isMd(f)) return md_c1; return arr_c1; } -static BBB2B c2fn(B f) { +static FC2 c2fn(B f) { if (isFun(f)) return c(Fun,f)->c2; if (isMd(f)) return md_c2; return arr_c2; diff --git a/src/ffi.c b/src/ffi.c index 48ef0d57..9ef46556 100644 --- a/src/ffi.c +++ b/src/ffi.c @@ -165,7 +165,7 @@ typedef BQNV (*bqn_foreignFn2)(BQNV w, BQNV x); B directFn_c1(B t, B x) { BoundFn* c = c(BoundFn,t); return getB(((bqn_foreignFn1)c->w_c1)( makeX(x))); } B directFn_c2(B t, B w, B x) { BoundFn* c = c(BoundFn,t); return getB(((bqn_foreignFn2)c->w_c2)(makeX(w), makeX(x))); } -static B m_ffiFn(NFnDesc* desc, B obj, BB2B c1, BBB2B c2, void* wc1, void* wc2) { +static B m_ffiFn(NFnDesc* desc, B obj, FC1 c1, FC2 c2, void* wc1, void* wc2) { BoundFn* r = mm_alloc(sizeof(BoundFn), t_nfn); nfn_lateInit((NFn*)r, desc); r->obj = obj; diff --git a/src/h.h b/src/h.h index 9012f595..a7382873 100644 --- a/src/h.h +++ b/src/h.h @@ -533,6 +533,9 @@ typedef B (* B2B)(B); typedef B (* BB2B)(B, B); typedef B (* BBB2B)(B, B, B); typedef B (* BBBB2B)(B, B, B, B); +typedef BB2B FC1; +typedef BBB2B FC2; + typedef B (*M1C3)(Md1*, B, B, B); typedef B (*M1C4)(Md1*, B, B, B, B); @@ -560,16 +563,16 @@ typedef B (*D2C2)(Md2D*, B, B); F(M2C4, m2_uc1) /* t,o,f,g, x→r; r≡O⌾( F _T_ G ) x; consumes x */ \ F(M2C5, m2_ucw) /* t,o,f,g,w,x→r; r≡O⌾(w⊸(F _T_ G)) x; consumes w,x */ \ \ - F( BB2B, fn_im) /* t, x; function monadic inverse; consumes x */ \ - F( BB2B, fn_is) /* t, x; function equal-arg inverse; consumes x */ \ - F(BBB2B, fn_iw) /* t,w,x; function dyadic 𝕨-inverse; consumes w,x */ \ - F(BBB2B, fn_ix) /* t,w,x; function dyadic 𝕩-inverse; consumes w,x */ \ - F( D1C1, m1_im) /* d, x; 1-modifier monadic inverse; consumes x */ \ - F( D1C2, m1_iw) /* d,w,x; 1-modifier dyadic 𝕨-inverse; consumes w,x */ \ - F( D1C2, m1_ix) /* d,w,x; 1-modifier dyadic 𝕩-inverse; consumes w,x */ \ - F( D2C1, m2_im) /* d, x; 2-modifier monadic inverse; consumes x */ \ - F( D2C2, m2_iw) /* d,w,x; 2-modifier dyadic 𝕨-inverse; consumes w,x */ \ - F( D2C2, m2_ix) /* d,w,x; 2-modifier dyadic 𝕩-inverse; consumes w,x */ \ + F(FC1, fn_im) /* t, x; function monadic inverse; consumes x */ \ + F(FC1, fn_is) /* t, x; function equal-arg inverse; consumes x */ \ + F(FC2, fn_iw) /* t,w,x; function dyadic 𝕨-inverse; consumes w,x */ \ + F(FC2, fn_ix) /* t,w,x; function dyadic 𝕩-inverse; consumes w,x */ \ + F(D1C1, m1_im) /* d, x; 1-modifier monadic inverse; consumes x */ \ + F(D1C2, m1_iw) /* d,w,x; 1-modifier dyadic 𝕨-inverse; consumes w,x */ \ + F(D1C2, m1_ix) /* d,w,x; 1-modifier dyadic 𝕩-inverse; consumes w,x */ \ + F(D2C1, m2_im) /* d, x; 2-modifier monadic inverse; consumes x */ \ + F(D2C2, m2_iw) /* d,w,x; 2-modifier dyadic 𝕨-inverse; consumes w,x */ \ + F(D2C2, m2_ix) /* d,w,x; 2-modifier dyadic 𝕩-inverse; consumes w,x */ \ \ F(B2b, canStore) /* doesn't consume */ \ F(u8, elType) /* guarantees that the corresponding i32any_ptr/f64any_ptr/c32any_ptr/… always succeeds */ \ @@ -665,8 +668,8 @@ static inline B incByG(B x, i64 am) { v(x)->refc+= am; return x; } typedef struct Fun { struct Value; - BB2B c1; - BBB2B c2; + FC1 c1; + FC2 c2; } Fun; #if USE_VALGRIND diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index f2269c62..8351d64b 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -105,11 +105,11 @@ INS B i_FN2O(B w, B f, B x, u32* bc) { POS_UPD; dec(f); return r; } -INS B i_FN1Oi(B x, BB2B fm, u32* bc) { POS_UPD; +INS B i_FN1Oi(B x, FC1 fm, u32* bc) { POS_UPD; B r = q_N(x)? x : fm(b((u64)0), x); return r; } -INS B i_FN2Oi(B w, B x, BB2B fm, BBB2B fd, u32* bc) { POS_UPD; +INS B i_FN2Oi(B w, B x, FC1 fm, FC2 fd, u32* bc) { POS_UPD; if (q_N(x)) { dec(w); return x; } else return q_N(w)? fm(b((u64)0), x) : fd(b((u64)0), w, x); } @@ -667,8 +667,8 @@ Nvm_res m_nvm(Body* body) { case FN2O: TOPp; GET(R_A1,1,0); GET(R_A2,2,1); IMM(R_A3,off); CCALL(i_FN2O); break; // (B w, B f, B x, u32* bc) case FN1Ci: { u64 fn = L64; POS_UPD(R_A0,R_A3); MOV(R_A1, R_RES); GET(R_A2,0,2); CCALL(fn); } break; case FN2Ci: { u64 fn = L64; POS_UPD(R_A0,R_A3); MOV(R_A1, R_RES); GET(R_A2,1,1); CCALL(fn); } break; - case FN1Oi:TOPp; GET(R_A1,0,2); IMM(R_A1,L64); IMM(R_A2,off); CCALL(i_FN1Oi); break; // ( B x, BB2B fm, u32* bc) - case FN2Oi:TOPp; GET(R_A1,1,1); IMM(R_A2,L64); IMM(R_A3, L64); IMM(R_A4,off); CCALL(i_FN2Oi); break; // (B w, B x, BB2B fm, BBB2B fd, u32* bc) + case FN1Oi:TOPp; GET(R_A1,0,2); IMM(R_A1,L64); IMM(R_A2,off); CCALL(i_FN1Oi); break; // ( B x, FC1 fm, u32* bc) + case FN2Oi:TOPp; GET(R_A1,1,1); IMM(R_A2,L64); IMM(R_A3, L64); IMM(R_A4,off); CCALL(i_FN2Oi); break; // (B w, B x, FC1 fm, FC2 fd, u32* bc) case LSTM: case LSTO:; { bool o = *(bc-1) == LSTO; u32 sz = *bc++; if (sz==0 ) { TOPs; CCALL(i_LST_0); } // unused with optimizations diff --git a/src/load.c b/src/load.c index f9e34d74..7dce909c 100644 --- a/src/load.c +++ b/src/load.c @@ -606,8 +606,8 @@ static B def_m2_d(B m, B f, B g) { thrM("cannot derive this"); } static Arr* def_slice(B x, usz s, usz ia) { thrM("cannot slice non-array!"); } B rt_invFnReg, rt_invFnSwap; -BB2B rt_invFnRegFn; -BB2B rt_invFnSwapFn; +FC1 rt_invFnRegFn; +FC1 rt_invFnSwapFn; B def_fn_im(B t, B x) { B fn = rt_invFnRegFn(rt_invFnReg, inc(t)); SLOW2("!runtime 𝕎⁼𝕩", t, x); B r = c1(fn, x); dec(fn); return r; } B def_fn_is(B t, B x) { B fn = rt_invFnSwapFn(rt_invFnSwap, inc(t)); SLOW2("!runtime 𝕎⁼𝕩", t, x); B r = c1(fn, x); dec(fn); return r; } B def_fn_iw(B t, B w, B x) { B fn = rt_invFnSwapFn(rt_invFnSwap, inc(t)); SLOW3("!runtime 𝕨F⁼𝕩", w, x, t); B r = c2(fn, w, x); dec(fn); return r; } @@ -662,7 +662,7 @@ void def_fallbackTriv(Value* v) { // used while vtables aren't yet fully loaded; TIv(v,freeF)(v); } -static NOINLINE B m_bfn(BB2B c1, BBB2B c2, u8 id) { +static NOINLINE B m_bfn(FC1 c1, FC2 c2, u8 id) { BFn* f = mm_alloc(sizeof(BFn), t_funBI); f->c1 = c1; f->c2 = c2; diff --git a/src/nfns.c b/src/nfns.c index 5a58932a..23af0350 100644 --- a/src/nfns.c +++ b/src/nfns.c @@ -5,7 +5,7 @@ static u32 nfn_curr; static B nfn_list; -NFnDesc* registerNFn(B name, BB2B c1, BBB2B c2) { +NFnDesc* registerNFn(B name, FC1 c1, FC2 c2) { u32 id = nfn_curr++; NFnDesc* r = mm_alloc(sizeof(NFnDesc), t_nfnDesc); r->id = id; diff --git a/src/nfns.h b/src/nfns.h index 6813296e..1920a460 100644 --- a/src/nfns.h +++ b/src/nfns.h @@ -13,11 +13,11 @@ struct NFnDesc { struct Value; u32 id; B name; - BB2B c1; - BBB2B c2; + FC1 c1; + FC2 c2; }; -NFnDesc* registerNFn(B name, BB2B c1, BBB2B c2); // should be called a constant number of times; consumes name +NFnDesc* registerNFn(B name, FC1 c1, FC2 c2); // should be called a constant number of times; consumes name B m_nfn(NFnDesc* desc, B obj); // consumes obj B nfn_name(B x); // doesn't consume static void nfn_lateInit(NFn* fn, NFnDesc* desc) { diff --git a/src/rtwrap.c b/src/rtwrap.c index 1ac8508b..84a56174 100644 --- a/src/rtwrap.c +++ b/src/rtwrap.c @@ -76,7 +76,7 @@ u64 fwTotal; B wfn_c1(B t, B x) { WFun* c = c(WFun,t); B f = c->v; - BB2B fi = c(Fun,f)->c1; + FC1 fi = c(Fun,f)->c1; #if RT_PERF u64 s = nsTime(); B r = fi(f, x); @@ -103,7 +103,7 @@ B wfn_c1(B t, B x) { B wfn_c2(B t, B w, B x) { WFun* c = c(WFun,t); B f = c->v; - BBB2B fi = c(Fun,f)->c2; + FC2 fi = c(Fun,f)->c2; #if RT_PERF u64 s = nsTime(); B r = fi(f, w, x); diff --git a/src/singeli/c/arithdDispatch.c b/src/singeli/c/arithdDispatch.c index 40afd15e..ede357b9 100644 --- a/src/singeli/c/arithdDispatch.c +++ b/src/singeli/c/arithdDispatch.c @@ -53,7 +53,7 @@ typedef struct EntAA { typedef struct DyTableAA { EntAA entsAA[el_B*el_B]; // one for each instruction - BBB2B mainFn; + FC2 mainFn; char* repr; } DyTableAA; @@ -161,7 +161,7 @@ typedef struct { struct DyTableSA { EntSA ents[el_B]; - BBB2B mainFn; + FC2 mainFn; char* repr; u8 fill[2][2]; // 0:none 1:int 2:char DyTableSA* chrAtom; diff --git a/src/utils/each.c b/src/utils/each.c index ecbe1883..d99d6381 100644 --- a/src/utils/each.c +++ b/src/utils/each.c @@ -4,7 +4,7 @@ static inline B mv(B* p, usz n) { B r = p [n]; p [n] = m_f64(0); return r; } static inline B hmv(HArr_p p, usz n) { B r = p.a[n]; p.a[n] = m_f64(0); return r; } -B eachd_fn(B fo, B w, B x, BBB2B f) { +B eachd_fn(B fo, B w, B x, FC2 f) { ur wr, xr; // if rank is 0, respective w/x will be disclosed if (isArr(w)) { wr=RNK(w); if (wr==0) { B c=IGet(w, 0); decG(w); w=c; } } else wr=0; if (isArr(x)) { xr=RNK(x); if (xr==0) { B c=IGet(x, 0); decG(x); x=c; } } else xr=0; @@ -56,7 +56,7 @@ B eachd_fn(B fo, B w, B x, BBB2B f) { return rb; } -B eachm_fn(B fo, B x, BB2B f) { +B eachm_fn(B fo, B x, FC1 f) { usz ia = IA(x); usz i = 0; if (ia==0) return x; @@ -117,7 +117,7 @@ B eachm_fn(B fo, B x, BB2B f) { } #if CATCH_ERRORS -B arith_recd(BBB2B f, B w, B x) { +B arith_recd(FC2 f, B w, B x) { B fx = getFillQ(x); if (noFill(fx)) return eachd_fn(bi_N, w, x, f); B fw = getFillQ(w); diff --git a/src/utils/each.h b/src/utils/each.h index 84ae2b4f..55264f2a 100644 --- a/src/utils/each.h +++ b/src/utils/each.h @@ -1,12 +1,12 @@ #pragma once #include "mut.h" -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 +B eachd_fn(B fo, B w, B x, FC2 f); // consumes w,x; assumes at least one is array +B eachm_fn(B fo, B x, FC1 f); // consumes x; x must be array #if CATCH_ERRORS -NOINLINE B arith_recd(BBB2B f, B w, B x); +NOINLINE B arith_recd(FC2 f, B w, B x); #else -static inline B arith_recd(BBB2B f, B w, B x) { return eachd_fn(bi_N, w, x, f); } +static inline B arith_recd(FC2 f, B w, B x) { return eachd_fn(bi_N, w, x, f); } #endif