From 3ed5b6313cc06a3e81e99cc4ae6e21d2a19ce6d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petri=20H=C3=A4kkinen?= Date: Thu, 18 Nov 2021 10:53:59 +0200 Subject: [PATCH] Eliminate LUA_FLOAT4_VECTORS. LUA_VECTOR_SIZE is enough for the few remaining cases. --- VM/include/lua.h | 2 +- VM/include/luaconf.h | 8 +------- VM/src/lapi.cpp | 2 +- VM/src/laux.cpp | 2 +- VM/src/lbuiltins.cpp | 4 ++-- VM/src/lmem.cpp | 2 +- VM/src/lnumutils.h | 4 ++-- VM/src/lobject.h | 2 +- VM/src/ltable.cpp | 2 +- VM/src/lvmexecute.cpp | 2 +- 10 files changed, 12 insertions(+), 18 deletions(-) diff --git a/VM/include/lua.h b/VM/include/lua.h index 95ce607c..0ed528f0 100644 --- a/VM/include/lua.h +++ b/VM/include/lua.h @@ -157,7 +157,7 @@ LUA_API void lua_pushnil(lua_State* L); LUA_API void lua_pushnumber(lua_State* L, double n); LUA_API void lua_pushinteger(lua_State* L, int n); LUA_API void lua_pushunsigned(lua_State* L, unsigned n); -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 LUA_API void lua_pushvector(lua_State* L, float x, float y, float z, float w); #else LUA_API void lua_pushvector(lua_State* L, float x, float y, float z); diff --git a/VM/include/luaconf.h b/VM/include/luaconf.h index b5f4cb12..cce70a20 100644 --- a/VM/include/luaconf.h +++ b/VM/include/luaconf.h @@ -123,12 +123,6 @@ long l; \ } -#define LUA_FLOAT4_VECTORS - -#ifdef LUA_FLOAT4_VECTORS -#define LUA_VECTOR_SIZE 4 -#else -#define LUA_VECTOR_SIZE 3 -#endif +#define LUA_VECTOR_SIZE 3 /* must be 3 or 4 */ #define LUA_EXTRA_SIZE LUA_VECTOR_SIZE - 2 diff --git a/VM/src/lapi.cpp b/VM/src/lapi.cpp index c9b2caf8..90a36a4d 100644 --- a/VM/src/lapi.cpp +++ b/VM/src/lapi.cpp @@ -550,7 +550,7 @@ void lua_pushunsigned(lua_State* L, unsigned u) return; } -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 void lua_pushvector(lua_State* L, float x, float y, float z, float w) { setvvalue(L->top, x, y, z, w); diff --git a/VM/src/laux.cpp b/VM/src/laux.cpp index baf5093d..10d30fdc 100644 --- a/VM/src/laux.cpp +++ b/VM/src/laux.cpp @@ -462,7 +462,7 @@ LUALIB_API const char* luaL_tolstring(lua_State* L, int idx, size_t* len) case LUA_TVECTOR: { const float* v = lua_tovector(L, idx); -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 lua_pushfstring(L, LUA_NUMBER_FMT ", " LUA_NUMBER_FMT ", " LUA_NUMBER_FMT ", " LUA_NUMBER_FMT, v[0], v[1], v[2], v[3]); #else lua_pushfstring(L, LUA_NUMBER_FMT ", " LUA_NUMBER_FMT ", " LUA_NUMBER_FMT, v[0], v[1], v[2]); diff --git a/VM/src/lbuiltins.cpp b/VM/src/lbuiltins.cpp index 772b73ff..85d7865a 100644 --- a/VM/src/lbuiltins.cpp +++ b/VM/src/lbuiltins.cpp @@ -1018,7 +1018,7 @@ static int luauF_tunpack(lua_State* L, StkId res, TValue* arg0, int nresults, St static int luauF_vector(lua_State* L, StkId res, TValue* arg0, int nresults, StkId args, int nparams) { -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 if (nparams >= 4 && nresults <= 1 && ttisnumber(arg0) && ttisnumber(args) && ttisnumber(args + 1) && ttisnumber(args + 2)) #else if (nparams >= 3 && nresults <= 1 && ttisnumber(arg0) && ttisnumber(args) && ttisnumber(args + 1)) @@ -1029,7 +1029,7 @@ static int luauF_vector(lua_State* L, StkId res, TValue* arg0, int nresults, Stk double z = nvalue(args + 1); double w = 0.0; -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 w = nvalue(args + 2); #endif diff --git a/VM/src/lmem.cpp b/VM/src/lmem.cpp index d4eed618..9f9d4a98 100644 --- a/VM/src/lmem.cpp +++ b/VM/src/lmem.cpp @@ -33,7 +33,7 @@ #define ABISWITCH(x64, ms32, gcc32) (sizeof(void*) == 8 ? x64 : ms32) #endif -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 static_assert(sizeof(TValue) == ABISWITCH(24, 24, 24), "size mismatch for value"); static_assert(sizeof(LuaNode) == ABISWITCH(48, 48, 48), "size mismatch for table entry"); #else diff --git a/VM/src/lnumutils.h b/VM/src/lnumutils.h index 65043be1..67f832dc 100644 --- a/VM/src/lnumutils.h +++ b/VM/src/lnumutils.h @@ -18,7 +18,7 @@ inline bool luai_veceq(const float* a, const float* b) { -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 return a[0] == b[0] && a[1] == b[1] && a[2] == b[2] && a[3] == b[3]; #else return a[0] == b[0] && a[1] == b[1] && a[2] == b[2]; @@ -27,7 +27,7 @@ inline bool luai_veceq(const float* a, const float* b) inline bool luai_vecisnan(const float* a) { -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 return a[0] != a[0] || a[1] != a[1] || a[2] != a[2] || a[3] != a[3]; #else return a[0] != a[0] || a[1] != a[1] || a[2] != a[2]; diff --git a/VM/src/lobject.h b/VM/src/lobject.h index 5ed64736..ba040af6 100644 --- a/VM/src/lobject.h +++ b/VM/src/lobject.h @@ -105,7 +105,7 @@ typedef struct lua_TValue i_o->tt = LUA_TNUMBER; \ } -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 #define setvvalue(obj, x, y, z, w) \ { \ TValue* i_o = (obj); \ diff --git a/VM/src/ltable.cpp b/VM/src/ltable.cpp index cd69c34b..2434e87a 100644 --- a/VM/src/ltable.cpp +++ b/VM/src/ltable.cpp @@ -113,7 +113,7 @@ static LuaNode* hashvec(const Table* t, const float* v) // Optimized Spatial Hashing for Collision Detection of Deformable Objects unsigned int h = (i[0] * 73856093) ^ (i[1] * 19349663) ^ (i[2] * 83492791); -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 i[3] = (i[3] == 0x8000000) ? 0 : i[3]; i[3] ^= i[3] >> 17; h ^= i[3] * 39916801; diff --git a/VM/src/lvmexecute.cpp b/VM/src/lvmexecute.cpp index 3e6a1b91..bf8d493e 100644 --- a/VM/src/lvmexecute.cpp +++ b/VM/src/lvmexecute.cpp @@ -601,7 +601,7 @@ static void luau_execute(lua_State* L) const char* name = getstr(tsvalue(kv)); int ic = (name[0] | ' ') - 'x'; -#ifdef LUA_FLOAT4_VECTORS +#if LUA_VECTOR_SIZE == 4 // 'w' is before 'x' in ascii, so ic is -1 when indexing with 'w' if (ic == -1) ic = 3;