diff --git a/src/builtins/md1.c b/src/builtins/md1.c index 2db8dfd2..01c7481d 100644 --- a/src/builtins/md1.c +++ b/src/builtins/md1.c @@ -460,7 +460,7 @@ static B m1c2(B t, B f, B w, B x) { // consumes w,x ShArr* X##_csh; \ if (X##_cr>1) { \ X##_csh = m_shArr(X##_cr); \ - NOUNROLL for (usz i = 0; i < X##_cr; i++) { \ + PLAINLOOP for (usz i = 0; i < X##_cr; i++) { \ usz v = SH(X)[i+1]; \ X##_csz*= v; \ X##_csh->a[i] = v; \ diff --git a/src/builtins/sysfn.c b/src/builtins/sysfn.c index d755f879..87914295 100644 --- a/src/builtins/sysfn.c +++ b/src/builtins/sysfn.c @@ -333,11 +333,11 @@ B rand_range_c2(B t, B w, B x) { if (max<1) { if (max!=0) thrM("(rand).Range: 𝕩 cannot be negative"); f64* rp; r = m_f64arrp(&rp, am); - NOUNROLL for (usz i = 0; i < am; i++) rp[i] = wy2u01(wyrand(&seed)); + PLAINLOOP for (usz i = 0; i < am; i++) rp[i] = wy2u01(wyrand(&seed)); } else if (max > (1ULL<<31)) { if (max >= 1LL<<53) thrM("(rand).Range: 𝕩 must be less than 2⋆53"); f64* rp; r = m_f64arrp(&rp, am); - NOUNROLL for (usz i = 0; i < am; i++) rp[i] = wy2u0k(wyrand(&seed), max); + PLAINLOOP for (usz i = 0; i < am; i++) rp[i] = wy2u0k(wyrand(&seed), max); } else { u8 t; usz u64am; @@ -351,9 +351,9 @@ B rand_range_c2(B t, B w, B x) { r = m_arr(offsetof(TyArr,a) + (u64am<<3), t, am); void* rp = ((TyArr*)r)->a; if (max & (max-1)) { // not power of two - if (t==t_i32arr) NOUNROLL for (usz i = 0; i < am; i++) ((i32*)rp)[i] = wy2u0k(wyrand(&seed), max); - else if (t==t_i16arr) NOUNROLL for (usz i = 0; i < am; i++) ((i16*)rp)[i] = wy2u0k(wyrand(&seed), max); - else if (t==t_i8arr) NOUNROLL for (usz i = 0; i < am; i++) (( i8*)rp)[i] = wy2u0k(wyrand(&seed), max); + if (t==t_i32arr) PLAINLOOP for (usz i = 0; i < am; i++) ((i32*)rp)[i] = wy2u0k(wyrand(&seed), max); + else if (t==t_i16arr) PLAINLOOP for (usz i = 0; i < am; i++) ((i16*)rp)[i] = wy2u0k(wyrand(&seed), max); + else if (t==t_i8arr) PLAINLOOP for (usz i = 0; i < am; i++) (( i8*)rp)[i] = wy2u0k(wyrand(&seed), max); else UD; // bitarr will be max==2, i.e. a power of two } else { u64 mask; @@ -364,7 +364,7 @@ B rand_range_c2(B t, B w, B x) { if (t==t_i16arr) { goto end; } mask|= mask<<8; end: - NOUNROLL for (usz i = 0; i < u64am; i++) ((u64*)rp)[i] = wyrand(&seed) & mask; + PLAINLOOP for (usz i = 0; i < u64am; i++) ((u64*)rp)[i] = wyrand(&seed) & mask; } } diff --git a/src/core/stuff.h b/src/core/stuff.h index 2b53734f..db0f96f3 100644 --- a/src/core/stuff.h +++ b/src/core/stuff.h @@ -86,12 +86,12 @@ static void arr_shCopy(Arr* n, B o) { // copy shape & rank from o to n } static void shcpy(usz* dst, usz* src, size_t len) { // memcpy(dst, src, len*sizeof(usz)); - NOUNROLL for (size_t i = 0; i < len; i++) dst[i] = src[i]; + PLAINLOOP for (size_t i = 0; i < len; i++) dst[i] = src[i]; } static usz shProd(usz* sh, usz s, usz e) { usz r = 1; - NOUNROLL for (i32 i = s; i < e; i++) r*= sh[i]; + PLAINLOOP for (i32 i = s; i < e; i++) r*= sh[i]; return r; } static usz arr_csz(B x) { @@ -101,7 +101,7 @@ static usz arr_csz(B x) { } static bool eqShPart(usz* w, usz* x, usz len) { // return memcmp(w, x, len*sizeof(usz))==0; - NOUNROLL for (i32 i = 0; i < len; i++) if (w[i]!=x[i]) return false; + PLAINLOOP for (i32 i = 0; i < len; i++) if (w[i]!=x[i]) return false; return true; } static bool eqShape(B w, B x) { assert(isArr(w)); assert(isArr(x)); diff --git a/src/ffi.c b/src/ffi.c index b5defd52..d64858e6 100644 --- a/src/ffi.c +++ b/src/ffi.c @@ -108,7 +108,7 @@ BQNV bqn_makeChar(uint32_t c) { return makeX(m_c32(c)); } static usz calcIA(size_t rank, const size_t* shape) { if (rank>UR_MAX) thrM("Rank too large"); usz r = 1; - NOUNROLL for (size_t i = 0; i < rank; i++) if (mulOn(r, shape[i])) thrM("Size too large"); + PLAINLOOP for (size_t i = 0; i < rank; i++) if (mulOn(r, shape[i])) thrM("Size too large"); return r; } static void copyBData(B* r, const BQNV* data, usz ia) { @@ -123,7 +123,7 @@ static void copyBData(B* r, const BQNV* data, usz ia) { } } #define CPYSH(R) usz* sh = arr_shAlloc((Arr*)(R), r0); \ - if (sh) NOUNROLL for (size_t i = 0; RARE(i < r0); i++) sh[i] = sh0[i]; + if (sh) PLAINLOOP for (size_t i = 0; RARE(i < r0); i++) sh[i] = sh0[i]; BQNV bqn_makeI8Arr (size_t r0, const size_t* sh0, const i8* data) { usz ia=calcIA(r0,sh0); i8* rp; Arr* r = m_i8arrp (&rp,ia); CPYSH(r); memcpy(rp,data,ia*1); return makeX(taga(r)); } BQNV bqn_makeI16Arr(size_t r0, const size_t* sh0, const i16* data) { usz ia=calcIA(r0,sh0); i16* rp; Arr* r = m_i16arrp(&rp,ia); CPYSH(r); memcpy(rp,data,ia*2); return makeX(taga(r)); } diff --git a/src/h.h b/src/h.h index 25687256..a15d4711 100644 --- a/src/h.h +++ b/src/h.h @@ -140,12 +140,16 @@ typedef double f64; #define N64d "%"SCNd64 #define N64u "%"SCNu64 #if __clang__ - #define NOUNROLL _Pragma("clang loop unroll(disable)") _Pragma("clang loop vectorize(disable)") + #define NOUNROLL _Pragma("clang loop unroll(disable)") + #define NOVECTORIZE _Pragma("clang loop vectorize(disable)") #elif __GNUC__ #define NOUNROLL _Pragma("GCC unroll 1") + #define NOVECTORIZE #else #define NOUNROLL + #define NOVECTORIZE #endif +#define PLAINLOOP NOUNROLL NOVECTORIZE #define JOIN0(A,B) A##B #define JOIN(A,B) JOIN0(A,B) diff --git a/src/opt/mm_buddyTemplate.c b/src/opt/mm_buddyTemplate.c index e1222b70..2cae5d89 100644 --- a/src/opt/mm_buddyTemplate.c +++ b/src/opt/mm_buddyTemplate.c @@ -20,7 +20,7 @@ u64 alSize; FORCE_INLINE void BN(splitTo)(EmptyValue* c, i64 from, i64 to, bool notEqual) { c->mmInfo = MMI(to); - NOUNROLL while (from != to) { + PLAINLOOP while (from != to) { from--; EmptyValue* b = (EmptyValue*) (BSZ(from) + (u8*)c); b->type = t_empty; diff --git a/src/vm.c b/src/vm.c index e60386fa..10bf434a 100644 --- a/src/vm.c +++ b/src/vm.c @@ -629,7 +629,7 @@ FORCE_INLINE Scope* m_scopeI(Body* body, Scope* psc, u16 varAm, i32 initVarAm, B } i = initVarAm; } else { - NOUNROLL while (ivars[i] = initVars[i]; i++; } + PLAINLOOP while (ivars[i] = initVars[i]; i++; } } // some bit of manual unrolling, but not too much @@ -637,7 +637,7 @@ FORCE_INLINE Scope* m_scopeI(Body* body, Scope* psc, u16 varAm, i32 initVarAm, B if (left==1) sc->vars[i] = bi_noVar; else if (left>=2) { B* vars = sc->vars+i; - NOUNROLL for (u32 i = 0; i < (left>>1); i++) { *(vars++) = bi_noVar; *(vars++) = bi_noVar; } + PLAINLOOP for (u32 i = 0; i < (left>>1); i++) { *(vars++) = bi_noVar; *(vars++) = bi_noVar; } if (left&1) *vars = bi_noVar; }