Unverified Commit 5f67de8d authored by Terry Ellison's avatar Terry Ellison Committed by GitHub
Browse files

Optimise ROTable accesses and interface (#2505)

-  Optimise ROTable accesses and interface

This includes some refinements to the ROTable cache which remove the linker cludges on the CROSS_COMPILE builds.  Also keyhole tweaks to some of the Lua VM code to implrove runtimes.

I also noticed some compile time warnings during the build; the change to uz_unzip.c doesn't impact the compiled code, but does remove the compiler warnings.
parent ff44b2f0
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
#include "lauxlib.h" #include "lauxlib.h"
#include "lualib.h" #include "lualib.h"
#include "lrotable.h"
static int os_pushresult (lua_State *L, int i, const char *filename) { static int os_pushresult (lua_State *L, int i, const char *filename) {
int en = errno; /* calls to Lua API may change this value */ int en = errno; /* calls to Lua API may change this value */
......
...@@ -896,13 +896,6 @@ union luai_Cast { double l_d; long l_l; }; ...@@ -896,13 +896,6 @@ union luai_Cast { double l_d; long l_l; };
** without modifying the main part of the file. ** without modifying the main part of the file.
*/ */
/* If you define the next macro you'll get the ability to set rotables as
metatables for tables/userdata/types (but the VM might run slower)
*/
#if (LUA_OPTIMIZE_MEMORY == 2)
#define LUA_META_ROTABLES
#endif
#if LUA_OPTIMIZE_MEMORY == 2 && defined(LUA_USE_POPEN) #if LUA_OPTIMIZE_MEMORY == 2 && defined(LUA_USE_POPEN)
#error "Pipes not supported in aggresive optimization mode (LUA_OPTIMIZE_MEMORY=2)" #error "Pipes not supported in aggresive optimization mode (LUA_OPTIMIZE_MEMORY=2)"
#endif #endif
......
...@@ -130,11 +130,21 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { ...@@ -130,11 +130,21 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
TValue temp; TValue temp;
for (loop = 0; loop < MAXTAGLOOP; loop++) { for (loop = 0; loop < MAXTAGLOOP; loop++) {
const TValue *tm; const TValue *tm;
if (ttistable(t) || ttisrotable(t)) { /* `t' is a table? */
void *h = ttistable(t) ? hvalue(t) : rvalue(t); if (ttistable(t)) { /* `t' is a table? */
const TValue *res = ttistable(t) ? luaH_get((Table*)h, key) : luaH_get_ro(h, key); /* do a primitive get */ Table *h = hvalue(t);
const TValue *res = luaH_get(h, key); /* do a primitive get */
if (!ttisnil(res) || /* result is no nil? */
(tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
setobj2s(L, val, res);
return;
}
/* else will try the tag method */
} else if (ttisrotable(t)) { /* `t' is a table? */
void *h = rvalue(t);
const TValue *res = luaH_get_ro(h, key); /* do a primitive get */
if (!ttisnil(res) || /* result is no nil? */ if (!ttisnil(res) || /* result is no nil? */
(tm = fasttm(L, ttistable(t) ? ((Table*)h)->metatable : (Table*)luaR_getmeta(h), TM_INDEX)) == NULL) { /* or no TM? */ (tm = fasttm(L, (Table*)luaR_getmeta(h), TM_INDEX)) == NULL) { /* or no TM? */
setobj2s(L, val, res); setobj2s(L, val, res);
return; return;
} }
...@@ -142,6 +152,7 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) { ...@@ -142,6 +152,7 @@ void luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val) {
} }
else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX))) else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))
luaG_typeerror(L, t, "index"); luaG_typeerror(L, t, "index");
if (ttisfunction(tm) || ttislightfunction(tm)) { if (ttisfunction(tm) || ttislightfunction(tm)) {
callTMres(L, val, tm, t, key); callTMres(L, val, tm, t, key);
return; return;
...@@ -161,25 +172,27 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) { ...@@ -161,25 +172,27 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
L->top++; L->top++;
fixedstack(L); fixedstack(L);
for (loop = 0; loop < MAXTAGLOOP; loop++) { for (loop = 0; loop < MAXTAGLOOP; loop++) {
const TValue *tm; const TValue *tm = NULL;
if (ttistable(t) || ttisrotable(t)) { /* `t' is a table? */ if (ttistable(t)) { /* `t' is a table? */
void *h = ttistable(t) ? hvalue(t) : rvalue(t); Table *h = hvalue(t);
TValue *oldval = ttistable(t) ? luaH_set(L, (Table*)h, key) : NULL; /* do a primitive set */ TValue *oldval = luaH_set(L, h, key); /* do a primitive set */
if ((oldval && !ttisnil(oldval)) || /* result is no nil? */ if ((!ttisnil(oldval)) || /* result is no nil? */
(tm = fasttm(L, ttistable(t) ? ((Table*)h)->metatable : (Table*)luaR_getmeta(h), TM_NEWINDEX)) == NULL) { /* or no TM? */ (tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL) {
if(oldval) {
L->top--; L->top--;
unfixedstack(L); unfixedstack(L);
setobj2t(L, oldval, val); setobj2t(L, oldval, val);
((Table *)h)->flags = 0; ((Table *)h)->flags = 0;
luaC_barriert(L, (Table*)h, val); luaC_barriert(L, (Table*)h, val);
}
return; return;
} }
/* else will try the tag method */ /* else will try the tag method */
} }
else if (ttisrotable(t)) {
luaG_runerror(L, "invalid write to ROM variable");
}
else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) else if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))
luaG_typeerror(L, t, "index"); luaG_typeerror(L, t, "index");
if (ttisfunction(tm) || ttislightfunction(tm)) { if (ttisfunction(tm) || ttislightfunction(tm)) {
L->top--; L->top--;
unfixedstack(L); unfixedstack(L);
...@@ -321,7 +334,7 @@ void luaV_concat (lua_State *L, int total, int last) { ...@@ -321,7 +334,7 @@ void luaV_concat (lua_State *L, int total, int last) {
if (G(L)->memlimit < max_sizet) max_sizet = G(L)->memlimit; if (G(L)->memlimit < max_sizet) max_sizet = G(L)->memlimit;
do { do {
/* Any call which does a memory allocation may trim the stack, /* Any call which does a memory allocation may trim the stack,
invalidating top unless the stack is fixed duri ng the allocation */ invalidating top unless the stack is fixed during the allocation */
StkId top = L->base + last + 1; StkId top = L->base + last + 1;
fixedstack(L); fixedstack(L);
int n = 2; /* number of elements handled in this pass (at least 2) */ int n = 2; /* number of elements handled in this pass (at least 2) */
......
...@@ -570,9 +570,9 @@ static int packet_map_lookup(lua_State *L) { ...@@ -570,9 +570,9 @@ static int packet_map_lookup(lua_State *L) {
} }
// Now search the packet function map // Now search the packet function map
const TValue *res = luaR_findentry((void *) packet_function_map, field, 0, NULL); lua_pushrotable(L, (void *)packet_function_map);
if (res) { lua_getfield(L, -1, field);
luaA_pushobject(L, res); if (!lua_isnil(L, -1)) {
return 1; return 1;
} }
} }
......
...@@ -131,20 +131,20 @@ int main(int argc, char *argv[]) { ...@@ -131,20 +131,20 @@ int main(int argc, char *argv[]) {
assert(sizeof(unsigned int) == 4); assert(sizeof(unsigned int) == 4);
/* allocate and zero the in and out Blocks */ /* allocate and zero the in and out Blocks */
assert(in = uz_malloc(sizeof(*in))); assert((in = uz_malloc(sizeof(*in))) != NULL);
assert(out = uz_malloc(sizeof(*out))); assert((out = uz_malloc(sizeof(*out))) != NULL);
memset(in, 0, sizeof(*in)); memset(in, 0, sizeof(*in));
memset(out, 0, sizeof(*out)); memset(out, 0, sizeof(*out));
/* open input files and probe end to read the expanded length */ /* open input files and probe end to read the expanded length */
assert((in->fin = fopen(inFile, "rb"))); assert((in->fin = fopen(inFile, "rb")) != NULL);
fseek(in->fin, -4, SEEK_END); fseek(in->fin, -4, SEEK_END);
assert(fread((uchar*)&(out->len), 1, 4, in->fin) == 4); assert(fread((uchar*)&(out->len), 1, 4, in->fin) == 4);
in->len = ftell(in->fin); in->len = ftell(in->fin);
fseek(in->fin, 0, SEEK_SET); fseek(in->fin, 0, SEEK_SET);
assert((out->fout = fopen(outFile, "wb"))); assert((out->fout = fopen(outFile, "wb")) != NULL);
printf ("Inflating in=%s out=%s\n", inFile, outFile); printf ("Inflating in=%s out=%s\n", inFile, outFile);
...@@ -152,7 +152,7 @@ int main(int argc, char *argv[]) { ...@@ -152,7 +152,7 @@ int main(int argc, char *argv[]) {
n = (out->len > DICTIONARY_WINDOW) ? WRITE_BLOCKS : n = (out->len > DICTIONARY_WINDOW) ? WRITE_BLOCKS :
1 + (out->len-1) / WRITE_BLOCKSIZE; 1 + (out->len-1) / WRITE_BLOCKSIZE;
for(i = WRITE_BLOCKS - n + 1; i <= WRITE_BLOCKS; i++) for(i = WRITE_BLOCKS - n + 1; i <= WRITE_BLOCKS; i++)
assert(out->block[i % WRITE_BLOCKS] = uz_malloc(sizeof(outBlock))); assert((out->block[i % WRITE_BLOCKS] = uz_malloc(sizeof(outBlock))) != NULL);
out->breakNdx = (out->len < WRITE_BLOCKSIZE) ? out->len : WRITE_BLOCKSIZE; out->breakNdx = (out->len < WRITE_BLOCKSIZE) ? out->len : WRITE_BLOCKSIZE;
out->fullBlkCB = processOutRec; out->fullBlkCB = processOutRec;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment