Skip to content

Commit

Permalink
issue #157 cleanup api for getting access to array raw data and revis…
Browse files Browse the repository at this point in the history
…e the inline short string table lookup so that we have an inline part and a slow part
  • Loading branch information
dibyendumajumdar committed Jul 23, 2019
1 parent 8cafee0 commit 58cc6cf
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 54 deletions.
2 changes: 1 addition & 1 deletion build-utils/cmake-64bit-llvm.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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 ..
8 changes: 4 additions & 4 deletions include/lobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
38 changes: 22 additions & 16 deletions include/ltable.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
31 changes: 23 additions & 8 deletions include/lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down
1 change: 1 addition & 0 deletions include/luaconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
28 changes: 12 additions & 16 deletions src/lapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 21 additions & 9 deletions src/ltable.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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

/*
Expand Down Expand Up @@ -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";
Expand Down

0 comments on commit 58cc6cf

Please sign in to comment.