issue #161 avoid taking address of math functions in the fast call scenario, instead assign unique codes to functions that may be inlined

experimental
Dibyendu Majumdar 5 years ago
parent 45716255c0
commit 01eb83dcfe

@ -549,7 +549,9 @@ struct lua_Debug {
LUA_API void (ravi_pushcfastcall)(lua_State *L, void *ptr, int tag);
#define RAVI_TFCF_D_D 1
#define RAVI_TFCF_EXP 1
#define RAVI_TFCF_LOG 2
#define RAVI_TFCF_D_D 3
/* Create an integer array (specialization of Lua table)
* of given size and initialize array with supplied initial value

@ -1695,6 +1695,16 @@ check(x, 'NEW_IARRAY', 'LOADK', 'SETLIST', 'TEST',
'RETURN', 'RETURN')
print 'Test 74 OK'
function x()
assert(math.exp(2) == ravi.exp(2))
assert(math.log(2) == ravi.ln(2))
assert(math.exp(math.log(2)) == ravi.exp(ravi.ln(2)))
end
x()
compile(x)
x()
print 'Test 75 OK'
for k,v in pairs(opcodes_coverage)
do
print(k, v)

@ -13,6 +13,7 @@
#include <setjmp.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "lua.h"
@ -514,10 +515,12 @@ int luaD_precall (lua_State *L, StkId func, int nresults, int op_call) {
return 0;
}
case RAVI_TFCF: {
int tt = rttype(func);
int nargs = L->top - func - 1;
int sig = tt >> 8;
int tt = rttype(func);
int sig = tt >> 8; /* Extract the function signature*/
switch (sig) {
case RAVI_TFCF_LOG:
case RAVI_TFCF_EXP:
case RAVI_TFCF_D_D: {
if (nargs == 1) {
TValue *arg1 = func + 1;
@ -529,8 +532,16 @@ int luaD_precall (lua_State *L, StkId func, int nresults, int op_call) {
else
nargs = 0;
if (nargs) {
double (*f)(double) = fcfvalue(func);
double v = f(arg);
double v;
switch (sig) {
case RAVI_TFCF_EXP: v = exp(arg); break;
case RAVI_TFCF_LOG: v = log(arg); break;
default: {
double(*f)(double) = fcfvalue(func);
double v = f(arg);
break;
}
}
setfltvalue(func, v);
L->top = func + 1; /* top points after the last result */
return 1;

@ -272,9 +272,9 @@ static const luaL_Reg ravilib[] = {{"iscompiled", ravi_is_compiled},
LUAMOD_API int raviopen_llvmjit(lua_State *L) {
luaL_newlib(L, ravilib);
/* faster calls some maths functions */
ravi_pushcfastcall(L, (void *)exp, RAVI_TFCF_D_D);
ravi_pushcfastcall(L, NULL, RAVI_TFCF_EXP);
lua_setfield(L, -2, "exp");
ravi_pushcfastcall(L, (void *)log, RAVI_TFCF_D_D);
ravi_pushcfastcall(L, NULL, RAVI_TFCF_LOG);
lua_setfield(L, -2, "ln");
return 1;
}

Loading…
Cancel
Save