From 9c66cbbb4b3b1841db1930067b27ee4c9e6faedc Mon Sep 17 00:00:00 2001 From: dzaima Date: Mon, 19 Jul 2021 02:58:36 +0300 Subject: [PATCH] move noinline fns out of .h files --- src/core/gstack.h | 2 +- src/core/stuff.c | 66 +++++++++++++++++++++++++++++++++++++++++ src/core/stuff.h | 70 +++++++++++--------------------------------- src/h.h | 16 ++++------ src/jit/nvm_x86_64.c | 2 +- src/vm.c | 1 + 6 files changed, 91 insertions(+), 66 deletions(-) diff --git a/src/core/gstack.h b/src/core/gstack.h index a9676ccb..89488ff1 100644 --- a/src/core/gstack.h +++ b/src/core/gstack.h @@ -26,7 +26,7 @@ static void gsReserve(u64 am) { #endif } -static NOINLINE void gsReserveR(u64 am) { gsReserve(am); } +void gsReserveR(u64 am); static inline void gsAdd(B x) { diff --git a/src/core/stuff.c b/src/core/stuff.c index faec7d25..eae49945 100644 --- a/src/core/stuff.c +++ b/src/core/stuff.c @@ -11,6 +11,45 @@ NORETURN NOINLINE void err(char* s) { exit(1); } +NOINLINE B c1_rare(B f, B x) { dec(x); + if (isMd(f)) thrM("Calling a modifier"); + return inc(VALIDATE(f)); +} +NOINLINE B c2_rare(B f, B w, B x) { dec(w); dec(x); + if (isMd(f)) thrM("Calling a modifier"); + return inc(VALIDATE(f)); +} +NOINLINE void value_freeR(Value* x) { value_free(x); } +void noop_visit(Value* x) { } +NOINLINE B c1_invalid(B f, B x) { thrM("This function can't be called monadically"); } +NOINLINE B c2_invalid(B f, B w, B x) { thrM("This function can't be called dyadically"); } +extern B rt_under, bi_before; +static B rtUnder_c1(B f, B g, B x) { // consumes x + B fn = m2_d(inc(rt_under), inc(f), inc(g)); + B r = c1(fn, x); + dec(fn); + return r; +} +static B rtUnder_cw(B f, B g, B w, B x) { // consumes w,x + B fn = m2_d(inc(rt_under), inc(f), m2_d(inc(bi_before), w, inc(g))); + B r = c1(fn, x); + dec(fn); + return r; +} +B def_getU(B x, usz n) { return x; } +B def_fn_uc1(B t, B o, B x) { return rtUnder_c1(o, t, x); } +B def_fn_ucw(B t, B o, B w, B x) { return rtUnder_cw(o, t, w, x); } +B def_m1_uc1(B t, B o, B f, B x) { B t2 = m1_d(inc(t),inc(f) ); B r = rtUnder_c1(o, t2, x); dec(t2); return r; } +B def_m1_ucw(B t, B o, B f, B w, B x) { B t2 = m1_d(inc(t),inc(f) ); B r = rtUnder_cw(o, t2, w, x); dec(t2); return r; } +B def_m2_uc1(B t, B o, B f, B g, B x) { B t2 = m2_d(inc(t),inc(f),inc(g)); B r = rtUnder_c1(o, t2, x); dec(t2); return r; } +B def_m2_ucw(B t, B o, B f, B g, B w, B x) { B t2 = m2_d(inc(t),inc(f),inc(g)); B r = rtUnder_cw(o, t2, w, x); dec(t2); return r; } +B def_decompose(B x) { return m_v2(m_i32(isCallable(x)? 0 : -1),x); } + + +void decShR(Value* x) { + ptr_dec(shObjP(x)); +} + B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; NOINLINE B emptyCVecR() { return emptyCVec(); @@ -502,3 +541,30 @@ NOINLINE void printAllocStats() { #endif #endif } + +#ifdef DEBUG + NOINLINE Value* VALIDATEP(Value* x) { + if (x->refc<=0 || (x->refc>>28) == 'a' || x->type==t_empty) { + printf("bad refcount for type %d: %d\nattempting to print: ", x->type, x->refc); fflush(stdout); + print(tag(x,OBJ_TAG)); putchar('\n'); fflush(stdout); + err(""); + } + if (TIv(x,isArr)) { + Arr* a = (Arr*)x; + if (prnk(x)<=1) assert(a->sh == &a->ia); + else VALIDATE(tag(shObjP(x),OBJ_TAG)); + } + return x; + } + NOINLINE B VALIDATE(B x) { + if (!isVal(x)) return x; + VALIDATEP(v(x)); + if(isArr(x)!=TI(x,isArr) && v(x)->type!=t_freed && v(x)->type!=t_harrPartial) { + printf("bad array tag/type: type=%d, obj=%p\n", v(x)->type, (void*)x.u); + print(x); + err("\nk"); + } + return x; + } +#endif + \ No newline at end of file diff --git a/src/core/stuff.h b/src/core/stuff.h index cee3844c..44309c14 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -20,9 +20,10 @@ typedef struct ShArr { struct Value; usz a[]; } ShArr; -static ShArr* shObj (B x) { return (ShArr*)((u64)a(x)->sh-offsetof(ShArr,a)); } -static ShArr* shObjP(Value* x) { return (ShArr*)((u64)((Arr*)x)->sh-offsetof(ShArr,a)); } -static void decSh(Value* x) { if (prnk(x)>1) ptr_dec(shObjP(x)); } +static ShArr* shObj (B x) { return RFLD(a(x)->sh, ShArr, a); } +static ShArr* shObjP(Value* x) { return RFLD(((Arr*)x)->sh, ShArr, a); } +void decShR(Value* x); +static void decSh(Value* x) { if (RARE(prnk(x)>1)) decShR(x); } // some array stuff @@ -114,29 +115,17 @@ char* format_pm2(u8 u); bool isPureFn(B x); // doesn't consume B bqn_merge(B x); // consumes B bqn_squeeze(B x); // consumes -static void noop_visit(Value* x) { } -static B def_getU(B x, usz n) { return x; } - -extern B rt_under, bi_before; -static B rtUnder_c1(B f, B g, B x) { // consumes x - B fn = m2_d(inc(rt_under), inc(f), inc(g)); - B r = c1(fn, x); - dec(fn); - return r; -} -static B rtUnder_cw(B f, B g, B w, B x) { // consumes w,x - B fn = m2_d(inc(rt_under), inc(f), m2_d(inc(bi_before), w, inc(g))); - B r = c1(fn, x); - dec(fn); - return r; -} -static B def_fn_uc1(B t, B o, B x) { return rtUnder_c1(o, t, x); } -static B def_fn_ucw(B t, B o, B w, B x) { return rtUnder_cw(o, t, w, x); } -static B def_m1_uc1(B t, B o, B f, B x) { B t2 = m1_d(inc(t),inc(f) ); B r = rtUnder_c1(o, t2, x); dec(t2); return r; } -static B def_m1_ucw(B t, B o, B f, B w, B x) { B t2 = m1_d(inc(t),inc(f) ); B r = rtUnder_cw(o, t2, w, x); dec(t2); return r; } -static B def_m2_uc1(B t, B o, B f, B g, B x) { B t2 = m2_d(inc(t),inc(f),inc(g)); B r = rtUnder_c1(o, t2, x); dec(t2); return r; } -static B def_m2_ucw(B t, B o, B f, B g, B w, B x) { B t2 = m2_d(inc(t),inc(f),inc(g)); B r = rtUnder_cw(o, t2, w, x); dec(t2); return r; } -static B def_decompose(B x) { return m_v2(m_i32(isCallable(x)? 0 : -1),x); } +B rtUnder_c1(B f, B g, B x); +B rtUnder_cw(B f, B g, B w, B x); +B def_getU(B x, usz n); +B def_fn_uc1(B t, B o, B x); +B def_fn_ucw(B t, B o, B w, B x); +B def_m1_uc1(B t, B o, B f, B x); +B def_m1_ucw(B t, B o, B f, B w, B x); +B def_m2_uc1(B t, B o, B f, B g, B x); +B def_m2_ucw(B t, B o, B f, B g, B w, B x); +B def_decompose(B x); +void noop_visit(Value* x); #define CMP(W,X) ({ AUTO wt = (W); AUTO xt = (X); (wt>xt?1:0)-(wtrefc<=0 || (x->refc>>28) == 'a' || x->type==t_empty) { - printf("bad refcount for type %d: %d\nattempting to print: ", x->type, x->refc); fflush(stdout); - print(tag(x,OBJ_TAG)); putchar('\n'); fflush(stdout); - err(""); - } - if (TIv(x,isArr)) { - Arr* a = (Arr*)x; - if (prnk(x)<=1) assert(a->sh == &a->ia); - else VALIDATE(tag(shObjP(x),OBJ_TAG)); - } - return x; - } - static NOINLINE B VALIDATE(B x) { - if (!isVal(x)) return x; - VALIDATEP(v(x)); - if(isArr(x)!=TI(x,isArr) && v(x)->type!=t_freed && v(x)->type!=t_harrPartial) { - printf("bad array tag/type: type=%d, obj=%p\n", v(x)->type, (void*)x.u); - print(x); - err("\nk"); - } - return x; - } -#endif #ifdef USE_VALGRIND #include @@ -193,8 +157,8 @@ static bool atomEqual(B w, B x) { // doesn't consume (not that that matters real // call stuff -static NOINLINE B c1_invalid(B f, B x) { thrM("This function can't be called monadically"); } -static NOINLINE B c2_invalid(B f, B w, B x) { thrM("This function can't be called dyadically"); } +NORETURN B c1_invalid(B f, B x); +NORETURN B c2_invalid(B f, B w, B x); static B md_c1(B t, B x) { thrM("Cannot call a modifier"); } static B md_c2(B t, B w, B x) { thrM("Cannot call a modifier"); } static B arr_c1(B t, B x) { return inc(t); } diff --git a/src/h.h b/src/h.h index 700c3568..cb4cfa5a 100644 --- a/src/h.h +++ b/src/h.h @@ -204,8 +204,8 @@ typedef struct Arr { #ifdef DEBUG #include - static B VALIDATE(B x); - static Value* VALIDATEP(Value* x); + B VALIDATE(B x); + Value* VALIDATEP(Value* x); #define UD assert(false); #else #define assert(x) {if (!(x)) __builtin_unreachable();} @@ -407,7 +407,7 @@ static inline void value_free(Value* x) { TIv(x,free)(x); mm_free(x); } -static NOINLINE void value_freeR(Value* x) { value_free(x); } +void value_freeR(Value* x); static void dec(B x) { if (!isVal(VALIDATE(x))) return; Value* vx = v(x); @@ -435,14 +435,8 @@ typedef struct Fun { } Fun; -static NOINLINE B c1_rare(B f, B x) { dec(x); - if (isMd(f)) thrM("Calling a modifier"); - return inc(VALIDATE(f)); -} -static NOINLINE B c2_rare(B f, B w, B x) { dec(w); dec(x); - if (isMd(f)) thrM("Calling a modifier"); - return inc(VALIDATE(f)); -} +B c1_rare(B f, B x); +B c2_rare(B f, B w, B x); static B c1(B f, B x) { // BQN-call f monadically; consumes x if (isFun(f)) return VALIDATE(c(Fun,f)->c1(f, x)); return c1_rare(f, x); diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index 712dbdd6..92aeaa1a 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -436,7 +436,7 @@ static void onJIT(Body* body, u8* binEx, u64 sz) { print(s); printf(": map\n"); dec(s); } - u32 bcPos = body->map[0]; + u32 bcPos = body->bl->map[0]; // printf("JIT %d:\n", perfid); // vm_printPos(body->comp, bcPos, -1); fprintf(perf_map, N64x" "N64x" JIT %d: BC@%u\n", (u64)binEx, sz, perfid++, bcPos); diff --git a/src/vm.c b/src/vm.c index ee6a2502..393ea1d6 100644 --- a/src/vm.c +++ b/src/vm.c @@ -111,6 +111,7 @@ Env* envEnd; B* gStack; // points to after end B* gStackStart; B* gStackEnd; +NOINLINE void gsReserveR(u64 am) { gsReserve(am); } void gsPrint() { B* c = gStackStart; i32 i = 0;