diff --git a/src/builtins/cmp.c b/src/builtins/cmp.c index 819b76b7..f3a01273 100644 --- a/src/builtins/cmp.c +++ b/src/builtins/cmp.c @@ -6,7 +6,7 @@ static NOINLINE void fillBits(u64* dst, u64 sz, bool v) { memset((u8*)dst, v?0xff:0, BIT_N(sz)*8); } static NOINLINE void fillBitsDec(u64* dst, u64 sz, bool v, u64 x) { - dec(b(x)); + dec(r_uB(x)); fillBits(dst, sz, v); } @@ -97,7 +97,7 @@ CMP_REC(ne, ne, swapped=0;) #define CMP_TO_FILL(N, T) cmp_fill_##N(r, l, xr) #define CMP_SA0(N, T, Q, SLOW, BODY) void base_##N##AS##_##T(u64* r, void* w, u64 xr, u64 l) { \ - assert(l>0); B x=b(xr); \ + assert(l>0); B x=r_uB(xr); \ if (LIKELY(q_##Q(x))) BODY; \ else SLOW(N, T); \ } diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index ea74c76e..6bbcfc3f 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -654,7 +654,7 @@ static NOINLINE void rand_init() { B makeRand_c1(B t, B x) { if (!isNum(x)) thrM("•MakeRand 𝕩: 𝕩 must be a number"); if (rand_ns==NULL) rand_init(); - B r = m_nns(rand_ns, b(x.u>>32), b(x.u&0xFFFFFFFF), m_nfn(rand_rangeDesc, bi_N), m_nfn(rand_dealDesc, bi_N), m_nfn(rand_subsetDesc, bi_N)); + B r = m_nns(rand_ns, r_uB(x.u>>32), r_uB(x.u&0xFFFFFFFF), m_nfn(rand_rangeDesc, bi_N), m_nfn(rand_dealDesc, bi_N), m_nfn(rand_subsetDesc, bi_N)); Scope* sc = c(NS,r)->sc; for (i32 i = 2; i < 5; i++) nfn_swapObj(sc->vars[i], incG(r)); return r; diff --git a/src/ffi.c b/src/ffi.c index 483c9d8b..cd21ac29 100644 --- a/src/ffi.c +++ b/src/ffi.c @@ -24,7 +24,7 @@ // base interface defs for when GC stuff needs to be added in static B getB(BQNV v) { - return b(v); + return r_uB(v); } static BQNV makeX(B x) { return x.u; diff --git a/src/h.h b/src/h.h index d219faf8..bb1642d1 100644 --- a/src/h.h +++ b/src/h.h @@ -194,27 +194,26 @@ static const u16 ARR_TAG = 0b1111111111110111; // FFF7 1111111111110111ppppppppp static const u16 VAL_TAG = 0b1111111111110 ; // FFF. 1111111111110................................................... pointer to Value, needs refcounting #define ftag(X) ((u64)(X) << 48) #define ptr2u64(X) ((u64)(uintptr_t)(X)) -#define tagu64(V, T) b((u64)(V) | ftag(T)) +#define tagu64(V, T) r_uB((u64)(V) | ftag(T)) #define TOPTR(T,X) ((T*)(uintptr_t)(X)) #define c(T,X) TOPTR(T, (X).u&0xFFFFFFFFFFFFull) -#define tag(V, T) ({ void* tagv_ = (V); b(ptr2u64(tagv_) | ftag(T)); }) +#define tag(V, T) ({ void* tagv_ = (V); r_uB(ptr2u64(tagv_) | ftag(T)); }) #define taga(V) tag(V,ARR_TAG) typedef union B { u64 u; f64 f; } B; -#define b(x) ((B)(x)) typedef union { u32 u; f32 f; } F32R; -FORCE_INLINE u64 r_f64u(f64 x) { return ((B) x).u; } -FORCE_INLINE f64 r_u64f(u64 x) { return ((B) x).f; } -FORCE_INLINE u32 r_f32u(f32 x) { return ((F32R) x).u; } -FORCE_INLINE f32 r_u32f(u32 x) { return ((F32R) x).f; } +FORCE_INLINE u64 r_f64u(f64 x) { return (B){.f=x}.u; } +FORCE_INLINE f64 r_u64f(u64 x) { return (B){.u=x}.f; } +FORCE_INLINE u32 r_f32u(f32 x) { return (F32R){.f=x}.u; } +FORCE_INLINE f32 r_u32f(u32 x) { return (F32R){.u=x}.f; } FORCE_INLINE u64 r_Bu(B x) { return x.u; } FORCE_INLINE f64 r_Bf(B x) { return x.f; } -FORCE_INLINE B r_uB(u64 x) { return b(x); } -FORCE_INLINE B r_fB(f64 x) { return b(x); } +FORCE_INLINE B r_uB(u64 x) { return (B){.u=x}; } +FORCE_INLINE B r_fB(f64 x) { return (B){.f=x}; } #if defined(RT_WRAP) || defined(WRAP_NNBI) #define IF_WRAP(X) X @@ -353,11 +352,11 @@ u64 tot_heapUsed(void); #endif // some primitive actions -static const B bi_N = b((u64)0x7FF2000000000000ull); -static const B bi_noVar = b((u64)0x7FF2C00000000001ull); -static const B bi_okHdr = b((u64)0x7FF2000000000002ull); -static const B bi_optOut = b((u64)0x7FF2800000000003ull); -static const B bi_noFill = b((u64)0x7FF2000000000005ull); +static const B bi_N = (B) {.u = (u64)0x7FF2000000000000ull }; +static const B bi_noVar = (B) {.u = (u64)0x7FF2C00000000001ull }; +static const B bi_okHdr = (B) {.u = (u64)0x7FF2000000000002ull }; +static const B bi_optOut = (B) {.u = (u64)0x7FF2800000000003ull }; +static const B bi_noFill = (B) {.u = (u64)0x7FF2000000000005ull }; extern GLOBAL B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; #define emptyHVec() incG(bi_emptyHVec) #define emptyIVec() incG(bi_emptyIVec) @@ -451,7 +450,7 @@ FORCE_INLINE bool isMd (B x) { return (x.u>>49) ==(MD2_TAG>>1); } FORCE_INLINE bool isNsp(B x) { return (x.u>>48) == NSP_TAG; } FORCE_INLINE bool isObj(B x) { return (x.u>>48) == OBJ_TAG; } // FORCE_INLINE bool isVal(B x) { return ((x.u>>51) == VAL_TAG) & ((x.u<<13) != 0); } -// FORCE_INLINE bool isF64(B x) { return ((x.u>>51&0xFFF) != 0xFFE) | ((x.u<<1)==(b(1.0/0.0).u<<1)); } +// FORCE_INLINE bool isF64(B x) { return ((x.u>>51&0xFFF) != 0xFFE) | ((x.u<<1)==(r_Bu(m_f64(1.0/0.0))<<1)); } FORCE_INLINE bool isVal(B x) { return (x.u - (((u64)VAL_TAG<<51) + 1)) < ((1ull<<51) - 1); } // ((x.u>>51) == VAL_TAG) & ((x.u<<13) != 0); FORCE_INLINE bool isF64(B x) { return (x.u<<1) - ((0xFFEull<<52) + 2) >= (1ull<<52) - 2; } FORCE_INLINE bool isNum(B x) { return isF64(x); } @@ -462,7 +461,7 @@ FORCE_INLINE bool isPrim(B x) { return isCallable(x) && RTID(x)!=RTID_NONE; } // make objects -static B m_f64(f64 n) { assert(isF64(b(n))); return b(n); } // assert just to make sure we're actually creating a float +static B m_f64(f64 n) { assert(isF64(r_fB(n))); return r_fB(n); } // assert just to make sure we're actually creating a float static B m_c32(u32 n) { return tagu64(n,C32_TAG); } // TODO check validity? static B m_i32(i32 n) { return m_f64(n); } static B m_usz(usz n) { return m_f64(n); } diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index 5c185319..00a24afe 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -110,12 +110,12 @@ INS B i_FN2O(B w, B f, B x, u32* bc) { POS_UPD; return r; } INS B i_FN1Oi(B x, FC1 fm, u32* bc) { POS_UPD; - B r = q_N(x)? x : fm(b((u64)0), x); + B r = q_N(x)? x : fm(r_uB(0), x); return r; } 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); + else return q_N(w)? fm(r_uB(0), x) : fd(r_uB(0), w, x); } INS B i_LST_0(void) { // TODO combine with ADDI return emptyHVec(); @@ -309,7 +309,7 @@ static OptRes opt(u32* bc0) { #define L64 ({ u64 r = bc[0] | ((u64)bc[1])<<32; bc+= 2; r; }) #define S(N,I) SRef N = stk[TSSIZE(stk)-1-(I)]; switch (*bc++) { case FN1Ci: case FN1Oi: case FN2Ci: case FN2Oi: fatal("optimization: didn't expect already immediate FN__"); - case ADDU: case ADDI: cact = 0; TSADD(stk,SREF(b(L64), pos)); break; + case ADDU: case ADDI: cact = 0; TSADD(stk,SREF(r_uB(L64), pos)); break; case POPS: { assert(TSSIZE(actions) > 0); u64 asz = TSSIZE(actions); if (actions[asz-1]!=2) goto defIns; @@ -463,13 +463,13 @@ static OptRes opt(u32* bc0) { A64(data[dpos++]); break; case 5:; - u64 on = data[dpos++]; B ob = b(on); + u64 on = data[dpos++]; B ob = r_uB(on); TSADD(rbc, isVal(ob)? ADDI : ADDU); A64(on); if (isVal(ob)) refs = vec_addN(refs, ob); break; case 6: - dec(b(data[dpos++])); + dec(r_uB(data[dpos++])); break; case 10: case 11:case 12:case 13:case 14:case 15:case 16:case 17:case 18:case 19: @@ -663,7 +663,7 @@ Nvm_res m_nvm(Body* body) { // if (depth>1) MOV8rm(R_RES, SPOS(R_A3, -1, 0)); NORES(1); break; - case ADDI: TOPs; { u64 x = L64; IMM(R_RES, x); IMM(R_A3, v(b(x))); INCV(R_A3); break; } // (u64 v, S) + case ADDI: TOPs; { u64 x = L64; IMM(R_RES, x); IMM(R_A3, v(r_uB(x))); INCV(R_A3); break; } // (u64 v, S) case ADDU: TOPs; IMM(R_RES, L64); break; case FN1C: TOPp; GET(R_A1,1,1); IMM(R_A2,off); CCALL(i_FN1C); break; // ( B f, B x, u32* bc) case FN1O: TOPp; GET(R_A1,1,1); IMM(R_A2,off); CCALL(i_FN1O); break; // ( B f, B x, u32* bc) diff --git a/src/utils/bits.c b/src/utils/bits.c index a72437cb..1857dd23 100644 --- a/src/utils/bits.c +++ b/src/utils/bits.c @@ -60,7 +60,7 @@ NOINLINE B bit_sel(B b, B e0, B e1) { t_i8: type=t_i8arr; width=0; e0i=( u8)( i8)f0; e1i=( u8)( i8)f1; goto sel; t_i16: type=t_i16arr; width=1; e0i=(u16)(i16)f0; e1i=(u16)(i16)f1; goto sel; t_i32: type=t_i32arr; width=2; e0i=(u32)(i32)f0; e1i=(u32)(i32)f1; goto sel; - t_f64: type=t_f64arr; width=3; e0i= b(f0).u; e1i= b(f1).u; goto sel; + t_f64: type=t_f64arr; width=3; e0i=r_Bu(m_f64(f0)); e1i=r_Bu(m_f64(f1)); goto sel; } else if (elChr(t0) && isC32(e1)) { u32 u0 = o2cG(e0); u32 u1 = o2cG(e1); diff --git a/src/utils/includeSingeli.h b/src/utils/includeSingeli.h index ce2edf74..8b214009 100644 --- a/src/utils/includeSingeli.h +++ b/src/utils/includeSingeli.h @@ -36,8 +36,8 @@ #define vg_loadLUT64(p, i) p[i] #endif - #define BCALL(N, X) N(b(X)) - #define interp_f64(X) b(X).f + #define BCALL(N, X) N(r_uB(X)) + #define interp_f64(X) r_u64f(X) #define SINGELI_FILE0(X) #X #define SINGELI_FILE1(X) SINGELI_FILE0(X) diff --git a/src/utils/mut.c b/src/utils/mut.c index 3e32f984..2109d1b6 100644 --- a/src/utils/mut.c +++ b/src/utils/mut.c @@ -81,7 +81,7 @@ NOINLINE void mut_to(Mut* m, u8 n) { if (n==el_B && o==el_f64) { // hack to make toHArr calling f64arr_get not cry about possible sNaN floats usz ia = m->val->ia; f64* p = f64arr_ptr(taga(m->val)); - for (usz i = 0; i < ia; i++) if (!isF64(b(p[i]))) p[i] = 1.2217638442043777e161; // 0x6161616161616161 + for (usz i = 0; i < ia; i++) if (!isF64(r_fB(p[i]))) p[i] = 1.2217638442043777e161; // 0x6161616161616161 } #endif Arr* t = cpyFns[n](taga(m->val)); diff --git a/src/vm.c b/src/vm.c index ec959775..3ca50762 100644 --- a/src/vm.c +++ b/src/vm.c @@ -767,11 +767,11 @@ B evalBC(Body* b, Scope* sc, Block* bl) { // doesn't consume break; } case ADDI: { - ADD(incG(b(L64))); + ADD(incG(r_uB(L64))); break; } case ADDU: { - ADD(b(L64)); + ADD(r_uB(L64)); break; } case FN1C: { P(f)P(x)