diff --git a/build-utils/cmake-64bit-llvm.bat b/build-utils/cmake-64bit-llvm.bat index bd3a98bc..4d9cb12b 100644 --- a/build-utils/cmake-64bit-llvm.bat +++ b/build-utils/cmake-64bit-llvm.bat @@ -3,5 +3,5 @@ cd llvm64 rem pre LLVM 3.9 rem cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -G "Visual Studio 14 Win64" -DLLVM_JIT=ON -DLLVM_DIR=c:\LLVM37\share\llvm\cmake .. rem cmake -DCMAKE_INSTALL_PREFIX=c:\ravi -G "Visual Studio 15 2017 Win64" -DLLVM_JIT=ON -DLLVM_DIR=c:\d\LLVM40_64\lib\cmake\llvm .. -cmake -DCMAKE_INSTALL_PREFIX=c:\Software\ravi -G "Visual Studio 15 2017 Win64" -DSTATIC_BUILD=ON -DLLVM_JIT=ON -DLLVM_DIR=c:\Software\llvm501r\lib\cmake\llvm .. +cmake -DCMAKE_INSTALL_PREFIX=c:\Software\ravi -G "Visual Studio 15 2017 Win64" -DSTATIC_BUILD=ON -DLLVM_JIT=ON -DLLVM_DIR=c:\Software\llvm601r\lib\cmake\llvm .. cd .. \ No newline at end of file diff --git a/include/lobject.h b/include/lobject.h index fccce2e8..65555f59 100644 --- a/include/lobject.h +++ b/include/lobject.h @@ -599,10 +599,10 @@ typedef enum RaviArrayModifer { /** RAVI extension */ typedef struct RaviArray { - char *data; - unsigned int len; /* RAVI len specialization */ - unsigned int size; /* amount of memory allocated */ - lu_byte array_type; /* RAVI specialization */ + char *data; /* Note that the array data is 0-based so this holds 1+Lua length items */ + unsigned int len; /* RAVI len specialization, holds real length which is 1+Lua length */ + unsigned int size; /* amount of memory allocated */ + lu_byte array_type; /* RAVI specialization */ lu_byte array_modifier; /* Flags that affect how the array is handled */ } RaviArray; diff --git a/include/ltable.h b/include/ltable.h index 31dc5cf3..c2be98ec 100644 --- a/include/ltable.h +++ b/include/ltable.h @@ -77,27 +77,33 @@ required to get to a node in the hash table #endif -#if defined(RAVI_ENABLED) /* ** search function for short strings */ +#if !RAVI_USE_INLINE_SHORTSTR_TGET +LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); +#else +LUAI_FUNC const TValue *luaH_getshortstr_continue(Table *t, TString *key, Node *n); static RAVI_ALWAYS_INLINE const TValue *luaH_getshortstr(Table *t, TString *key) { + /* We inline the lookup in first two slots */ Node *n = hashstr(t, key); lua_assert(key->tt == LUA_TSHRSTR); - for (;;) { /* check whether 'key' is somewhere in the chain */ - const TValue *k = gkey(n); - if (ttisshrstring(k) && eqshrstr(tsvalue(k), key)) - return gval(n); /* that's it */ - else { - int nx = gnext(n); - if (nx == 0) - return luaO_nilobject; /* not found */ - n += nx; - } - } + const TValue *k = gkey(n); + if (ttisshrstring(k) && eqshrstr(tsvalue(k), key)) + return gval(n); /* that's it */ + int nx = gnext(n); + if (nx == 0) + return luaO_nilobject; /* not found */ + n += nx; + k = gkey(n); + if (ttisshrstring(k) && eqshrstr(tsvalue(k), key)) + return gval(n); /* that's it */ + nx = gnext(n); + if (nx == 0) + return luaO_nilobject; /* not found */ + /* Okay continue search slowly */ + return luaH_getshortstr_continue(t, key, n); } -#else -LUAI_FUNC const TValue *luaH_getshortstr (Table *t, TString *key); #endif LUAI_FUNC const TValue *luaH_getstr (Table *t, TString *key); LUAI_FUNC const TValue *luaH_get (Table *t, const TValue *key); @@ -197,8 +203,8 @@ LUAI_FUNC const TValue *raviH_slice_parent(lua_State *L, TValue *slice); raviH_set_float(L, t, ukey, (value)); \ } -LUAI_FUNC void raviH_get_number_array_rawdata(lua_State *L, Table *t, lua_Number **startp, lua_Number **endp); -LUAI_FUNC void raviH_get_integer_array_rawdata(lua_State *L, Table *t, lua_Integer **startp, lua_Integer **endp); +LUAI_FUNC void raviH_get_number_array_rawdata(lua_State *L, Table *t, Ravi_NumberArray *data); +LUAI_FUNC void raviH_get_integer_array_rawdata(lua_State *L, Table *t, Ravi_IntegerArray *data); #if defined(LUA_DEBUG) LUAI_FUNC Node *luaH_mainposition (const Table *t, const TValue *key); diff --git a/include/lua.h b/include/lua.h index a103b2a5..66ac8bb3 100644 --- a/include/lua.h +++ b/include/lua.h @@ -23,7 +23,7 @@ #define LUA_VERSION "Ravi " LUA_VERSION_MAJOR "." LUA_VERSION_MINOR #define LUA_RELEASE LUA_VERSION "." LUA_VERSION_RELEASE -#define LUA_COPYRIGHT LUA_RELEASE "\nCopyright (C) 1994-2018 Lua.org, PUC-Rio\nPortions Copyright (C) 2015-2018 Dibyendu Majumdar" +#define LUA_COPYRIGHT LUA_RELEASE "\nCopyright (C) 1994-2019 Lua.org, PUC-Rio\nPortions Copyright (C) 2015-2019 Dibyendu Majumdar" #define LUA_AUTHORS "R. Ierusalimschy, L. H. de Figueiredo, W. Celes, Dibyendu Majumdar" @@ -551,9 +551,11 @@ LUA_API void (ravi_pushcfastcall)(lua_State *L, void *ptr, int tag); /* Allowed tags - subject to change. Max value is 128. Note that each tag requires special handling in ldo.c */ -#define RAVI_TFCF_EXP 1 -#define RAVI_TFCF_LOG 2 -#define RAVI_TFCF_D_D 3 +enum { + RAVI_TFCF_EXP = 1, + RAVI_TFCF_LOG = 2, + RAVI_TFCF_D_D = 3, +}; /* Create an integer array (specialization of Lua table) * of given size and initialize array with supplied initial value @@ -592,10 +594,24 @@ LUA_API int ravi_is_integer_array(lua_State *L, int idx); /* Get the raw data associated with the number array at idx. * Note that Ravi arrays have an extra element at offset 0 - this * function returns a pointer to &data[0]. The number of - * array elements is returned in len. + * array elements is returned in length. + */ +typedef struct { + lua_Number *data; + unsigned int length; +} Ravi_NumberArray; +LUA_API void ravi_get_number_array_rawdata(lua_State *L, int idx, Ravi_NumberArray *array_data); + +/* Get the raw data associated with the integer array at idx. + * Note that Ravi arrays have an extra element at offset 0 - this + * function returns a pointer to &data[0]. The number of + * array elements is returned in length. */ -LUA_API lua_Number *ravi_get_number_array_rawdata(lua_State *L, int idx, size_t *len); -LUA_API lua_Integer *ravi_get_integer_array_rawdata(lua_State *L, int idx, size_t *len); +typedef struct { + lua_Integer *data; + unsigned int length; +} Ravi_IntegerArray; +LUA_API void ravi_get_integer_array_rawdata(lua_State *L, int idx, Ravi_IntegerArray *array_data); /* API to set the output functions used by Lua / Ravi * This allows the default implementations to be overridden @@ -640,7 +656,6 @@ LUA_API void ravi_set_debuglevel(int level); #define RAVI_DEBUG_STACK(p) if ((ravi_parser_debug & 8) != 0) {p;} else {} -#define RAVI_ENABLED 1 #define RAVI_BYTECODE_PROFILING_ENABLED 0 diff --git a/include/luaconf.h b/include/luaconf.h index 631713b5..f3f41d8a 100644 --- a/include/luaconf.h +++ b/include/luaconf.h @@ -824,6 +824,7 @@ #define RAVI_USE_NEWHASH 1 +#define RAVI_USE_INLINE_SHORTSTR_TGET 1 #define RAVI_USE_LLVM_BRANCH_WEIGHTS 1 /* If following is defined as true then LLVM instructions emitted for arithmetic ops priority floating point ops, else default is to prioritise integer ops */ diff --git a/src/lapi.c b/src/lapi.c index dec54a32..561dec03 100644 --- a/src/lapi.c +++ b/src/lapi.c @@ -851,28 +851,24 @@ LUA_API int ravi_is_integer_array(lua_State *L, int idx) { /* Get the raw data associated with the number array at idx. * Note that Ravi arrays have an extra element at offset 0 - this - * function returns a pointer to &data[0] - bear in mind that + * function returns a pointer to &data[0] */ -LUA_API lua_Number* ravi_get_number_array_rawdata(lua_State *L, int idx, size_t *len) { +LUA_API void ravi_get_number_array_rawdata(lua_State *L, int idx, Ravi_NumberArray *data) { StkId o = index2addr(L, idx); - lua_assert(ttisfarray(o)); - lua_Number *startp, *endp; - raviH_get_number_array_rawdata(L, hvalue(o), &startp, &endp); - *len = (endp - startp); - return startp; + if (!ttisfarray(o)) + luaG_runerror(L, "number[] required"); + raviH_get_number_array_rawdata(L, hvalue(o), data); } /* Get the raw data associated with the number array at idx. -* Note that Ravi arrays have an extra element at offset 0 - this -* function returns a pointer to &data[0] - bear in mind that -*/ -LUA_API lua_Integer* ravi_get_integer_array_rawdata(lua_State *L, int idx, size_t *len) { + * Note that Ravi arrays have an extra element at offset 0 - this + * function returns a pointer to &data[0] + */ +LUA_API void ravi_get_integer_array_rawdata(lua_State *L, int idx, Ravi_IntegerArray *data) { StkId o = index2addr(L, idx); - lua_assert(ttisiarray(o)); - lua_Integer *startp, *endp; - raviH_get_integer_array_rawdata(L, hvalue(o), &startp, &endp); - *len = (endp - startp); - return startp; + if (!ttisiarray(o)) + luaG_runerror(L, "integer[] required"); + raviH_get_integer_array_rawdata(L, hvalue(o), data); } /* Create a slice of an existing array diff --git a/src/ltable.c b/src/ltable.c index 6ce8ca8a..9cf0b191 100644 --- a/src/ltable.c +++ b/src/ltable.c @@ -598,7 +598,8 @@ const TValue *luaH_getint (Table *t, lua_Integer key) { } } -#if !defined(RAVI_ENABLED) +#if !RAVI_USE_INLINE_SHORTSTR_TGET +/* RAVI Change - we have split this into two parts - an inline part and a continue part */ /* ** search function for short strings */ @@ -617,6 +618,19 @@ const TValue *luaH_getshortstr (Table *t, TString *key) { } } } +#else +/* Continue search from n */ +const TValue *luaH_getshortstr_continue(Table *t, TString *key, Node *n) { + for (;;) { /* check whether 'key' is somewhere in the chain starting from next node after n */ + int nx = gnext(n); + if (nx == 0) + return luaO_nilobject; /* not found */ + n += nx; + const TValue *k = gkey(n); + if (ttisshrstring(k) && eqshrstr(tsvalue(k), key)) + return gval(n); /* that's it */ + } +} #endif /* @@ -877,20 +891,18 @@ Table *raviH_new_number_array(lua_State *L, unsigned int len, return t; } -void raviH_get_number_array_rawdata(lua_State *L, Table *t, lua_Number **startp, lua_Number **endp) { +void raviH_get_number_array_rawdata(lua_State *L, Table *t, Ravi_NumberArray *data) { (void)L; lua_assert(t->ravi_array.array_type == RAVI_TARRAYFLT); - lua_Number *data = (lua_Number *)t->ravi_array.data; - *startp = data; - *endp = data + t->ravi_array.len; + data->data = (lua_Number *)t->ravi_array.data; + data->length = t->ravi_array.len; } -void raviH_get_integer_array_rawdata(lua_State *L, Table *t, lua_Integer **startp, lua_Integer **endp) { +void raviH_get_integer_array_rawdata(lua_State *L, Table *t, Ravi_IntegerArray *data) { (void)L; lua_assert(t->ravi_array.array_type == RAVI_TARRAYINT); - lua_Integer *data = (lua_Integer *)t->ravi_array.data; - *startp = data; - *endp = data + t->ravi_array.len; + data->data = (lua_Integer *)t->ravi_array.data; + data->length = t->ravi_array.len; } static const char *key_orig_table = "Originaltable";