remove a number of numeric op codes

pull/81/head
Dibyendu Majumdar 9 years ago
parent d3a8e1fc08
commit 71e651c05e

@ -240,23 +240,15 @@ OP_RAVI_UNMI, /* A B R(A) := -R(B) integer */
OP_RAVI_ADDFF, /* A B C R(A) := RK(B) + RK(C) */
OP_RAVI_ADDFI, /* A B C R(A) := RK(B) + RK(C) */
OP_RAVI_ADDII, /* A B C R(A) := RK(B) + RK(C) */
OP_RAVI_ADDFN, /* A B C R(A) := RK(B) + C */
OP_RAVI_ADDIN, /* A B C R(A) := RK(B) + C */
OP_RAVI_SUBFF, /* A B C R(A) := RK(B) - RK(C) */
OP_RAVI_SUBFI, /* A B C R(A) := RK(B) - RK(C) */
OP_RAVI_SUBIF, /* A B C R(A) := RK(B) - RK(C) */
OP_RAVI_SUBII, /* A B C R(A) := RK(B) - RK(C) */
OP_RAVI_SUBFN, /* A B C R(A) := RK(B) - C */
OP_RAVI_SUBNF, /* A B C R(A) := B - RK(C) */
OP_RAVI_SUBIN, /* A B C R(A) := RK(B) - C */
OP_RAVI_SUBNI, /* A B C R(A) := B - RK(C) */
OP_RAVI_MULFF, /* A B C R(A) := RK(B) * RK(C) */
OP_RAVI_MULFI, /* A B C R(A) := RK(B) * RK(C) */
OP_RAVI_MULII, /* A B C R(A) := RK(B) * RK(C) */
OP_RAVI_MULFN, /* A B C R(A) := RK(B) * C */
OP_RAVI_MULIN, /* A B C R(A) := RK(B) * C */
OP_RAVI_DIVFF, /* A B C R(A) := RK(B) / RK(C) */
OP_RAVI_DIVFI, /* A B C R(A) := RK(B) / RK(C) */
@ -366,8 +358,8 @@ LUAI_DDEC const char *const luaP_opnames[NUM_OPCODES+1]; /* opcode names */
/* number of list items to accumulate before a SETLIST instruction */
#define LFIELDS_PER_FLUSH 50
#define RAVI_ENABLED 1
/* Ravi extension - prints the given instruction to the supplied buffer */
LUAI_FUNC const char* raviP_instruction_to_str(char *buf, size_t n, Instruction i);
#endif

@ -522,6 +522,7 @@ struct RaviFunctionDef {
llvm::Function *raviV_op_shrF;
llvm::Function *raviV_op_shlF;
// array setters
llvm::Function *raviH_set_intF;
llvm::Function *raviH_set_floatF;
@ -544,11 +545,11 @@ struct RaviFunctionDef {
llvm::Instruction *k_ptr;
// Load L->ci
llvm::Value *L_ci; // gep
llvm::Value *L_ci; // This is the GEP for L->ci
llvm::Instruction *ci_val;
// Get pointer to base
llvm::Value *Ci_base; // gep
// Pointer to ci->u.l.base
llvm::Value *Ci_base; // This is the GEP for ci->u.l.base
llvm::Instruction *base_ptr;
// Pointer to LClosure
@ -832,10 +833,6 @@ public:
void emit_ADDII(RaviFunctionDef *def, int A, int B, int C);
void emit_ADDFN(RaviFunctionDef *def, int A, int B, int C);
void emit_ADDIN(RaviFunctionDef *def, int A, int B, int C);
void emit_SUBFF(RaviFunctionDef *def, int A, int B, int C);
void emit_SUBFI(RaviFunctionDef *def, int A, int B, int C);
@ -844,24 +841,12 @@ public:
void emit_SUBII(RaviFunctionDef *def, int A, int B, int C);
void emit_SUBFN(RaviFunctionDef *def, int A, int B, int C);
void emit_SUBNF(RaviFunctionDef *def, int A, int B, int C);
void emit_SUBIN(RaviFunctionDef *def, int A, int B, int C);
void emit_SUBNI(RaviFunctionDef *def, int A, int B, int C);
void emit_MULFF(RaviFunctionDef *def, int A, int B, int C);
void emit_MULFI(RaviFunctionDef *def, int A, int B, int C);
void emit_MULII(RaviFunctionDef *def, int A, int B, int C);
void emit_MULFN(RaviFunctionDef *def, int A, int B, int C);
void emit_MULIN(RaviFunctionDef *def, int A, int B, int C);
void emit_DIVFF(RaviFunctionDef *def, int A, int B, int C);
void emit_DIVFI(RaviFunctionDef *def, int A, int B, int C);

@ -250,42 +250,6 @@ static int luaK_code (FuncState *fs, Instruction i) {
return fs->pc++;
}
/* Code arith where C is a constant */
int luaK_codeABKi(FuncState *fs, OpCode o, int a, int b, int c) {
TValue *v;
int i;
lua_Integer val;
lua_assert(ISK(c));
i = INDEXK(c);
lua_assert(i >= 0 && i < fs->nk);
v = &fs->f->k[i];
lua_assert(ttisinteger(v));
val = ivalue(v);
/* if the value is upto MAXINDEXRK then it means we can
* hold it in operand C - operand C reserves 1 bit for indicating
* constants hence MAXINDEXRK and not MAXARG_C
*/
if (val >= 0 && val <= MAXINDEXRK) {
if (o == OP_RAVI_ADDFI) {
o = OP_RAVI_ADDFN;
c = (int)val;
}
else if (o == OP_RAVI_ADDII) {
o = OP_RAVI_ADDIN;
c = (int)val;
}
else if (o == OP_RAVI_MULFI) {
o = OP_RAVI_MULFN;
c = (int)val;
}
else if (o == OP_RAVI_MULII) {
o = OP_RAVI_MULIN;
c = (int)val;
}
}
return luaK_codeABC(fs, o, a, b, c);
}
int luaK_codeABC (FuncState *fs, OpCode o, int a, int b, int c) {
lua_assert(getOpMode(o) == iABC);
lua_assert(getBMode(o) != OpArgN || b == 0);
@ -673,7 +637,6 @@ int luaK_exp2RK (FuncState *fs, expdesc *e) {
}
static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
#if RAVI_ENABLED
/* VNONRELOC means we have fixed register and do we know the type? */
if (ex->k == VNONRELOC && (var->ravi_type == RAVI_TNUMFLT || var->ravi_type == RAVI_TNUMINT || var->ravi_type == RAVI_TARRAYFLT || var->ravi_type == RAVI_TARRAYINT)) {
/* handled by MOVEI, MOVEF, MOVEAI, MOVEAF at runtime */
@ -716,7 +679,6 @@ static void check_valid_store(FuncState *fs, expdesc *var, expdesc *ex) {
var->ravi_type,
ex->ravi_type));
}
#endif
}
static OpCode check_valid_setupval(FuncState *fs, expdesc *var, expdesc *ex) {
@ -974,11 +936,11 @@ static int getarithop(OpCode op) {
return op - OP_ADD + LUA_OPADD;
/* following are RAVI specific opcodes */
if (op >= OP_RAVI_ADDFF && op < OP_RAVI_ADDIN)
if (op >= OP_RAVI_ADDFF && op < OP_RAVI_ADDII)
return LUA_OPADD;
else if (op >= OP_RAVI_SUBFF && op <= OP_RAVI_SUBNI)
else if (op >= OP_RAVI_SUBFF && op <= OP_RAVI_SUBII)
return LUA_OPSUB;
else if (op >= OP_RAVI_MULFF && op <= OP_RAVI_MULIN)
else if (op >= OP_RAVI_MULFF && op <= OP_RAVI_MULII)
return LUA_OPMUL;
else if (op >= OP_RAVI_DIVFF && op <= OP_RAVI_DIVII)
return LUA_OPDIV;
@ -987,43 +949,6 @@ static int getarithop(OpCode op) {
return LUA_OPADD - 1;
}
/* generate ADD and MUL codes - for ADD supply offset as 0, and for
* MUL supply the difference between the two
*/
static void generate_binarithop(FuncState *fs, expdesc *e1, expdesc *e2, int o1,
int o2, int offset) {
if (e1->ravi_type == RAVI_TNUMFLT && e2->ravi_type == RAVI_TNUMFLT) {
e1->u.info = luaK_codeABC(fs, OP_RAVI_ADDFF + offset, 0, o1, o2);
} else if (e1->ravi_type == RAVI_TNUMFLT && e2->ravi_type == RAVI_TNUMINT) {
if (ISK(o2)) {
e1->u.info = luaK_codeABKi(fs, OP_RAVI_ADDFI + offset, 0, o1,
o2); /* generate opcode */
} else {
e1->u.info = luaK_codeABC(fs, OP_RAVI_ADDFI + offset, 0, o1,
o2); /* generate opcode */
}
} else if (e1->ravi_type == RAVI_TNUMINT && e2->ravi_type == RAVI_TNUMFLT) {
if (ISK(o1)) {
e1->u.info = luaK_codeABKi(fs, OP_RAVI_ADDFI + offset, 0, o2,
o1); /* generate opcode */
} else {
e1->u.info = luaK_codeABC(fs, OP_RAVI_ADDFI + offset, 0, o2,
o1); /* generate opcode */
}
} else if (e1->ravi_type == RAVI_TNUMINT && e2->ravi_type == RAVI_TNUMINT) {
if (ISK(o1)) {
e1->u.info = luaK_codeABKi(fs, OP_RAVI_ADDII + offset, 0, o2,
o1); /* generate opcode */
} else if (ISK(o2)) {
e1->u.info = luaK_codeABKi(fs, OP_RAVI_ADDII + offset, 0, o1,
o2); /* generate opcode */
} else {
e1->u.info = luaK_codeABC(fs, OP_RAVI_ADDII + offset, 0, o1,
o2); /* generate opcode */
}
}
}
/*
** Code for binary and unary expressions that "produce values"
** (arithmetic operations, bitwise operations, concat, length). First
@ -1057,18 +982,6 @@ static void codeexpval (FuncState *fs, OpCode op,
freeexp(fs, e2);
freeexp(fs, e1);
}
#if RAVI_ENABLED
#if 0
if (op == OP_ADD &&
(e1->ravi_type == RAVI_TNUMFLT || e1->ravi_type == RAVI_TNUMINT) &&
(e2->ravi_type == RAVI_TNUMFLT || e2->ravi_type == RAVI_TNUMINT))
generate_binarithop(fs, e1, e2, o1, o2, 0);
else if (op == OP_MUL &&
(e1->ravi_type == RAVI_TNUMFLT || e1->ravi_type == RAVI_TNUMINT) &&
(e2->ravi_type == RAVI_TNUMFLT || e2->ravi_type == RAVI_TNUMINT))
generate_binarithop(fs, e1, e2, o1, o2, OP_RAVI_MULFF - OP_RAVI_ADDFF);
#else
if (op == OP_ADD && e1->ravi_type == RAVI_TNUMFLT && e2->ravi_type == RAVI_TNUMFLT) {
e1->u.info = luaK_codeABC(fs, OP_RAVI_ADDFF, 0, o1, o2);
}
@ -1081,7 +994,6 @@ static void codeexpval (FuncState *fs, OpCode op,
else if (op == OP_ADD && e1->ravi_type == RAVI_TNUMINT && e2->ravi_type == RAVI_TNUMINT) {
e1->u.info = luaK_codeABC(fs, OP_RAVI_ADDII, 0, o1, o2);
}
else if (op == OP_MUL && e1->ravi_type == RAVI_TNUMFLT && e2->ravi_type == RAVI_TNUMFLT) {
e1->u.info = luaK_codeABC(fs, OP_RAVI_MULFF, 0, o1, o2);
}
@ -1094,7 +1006,6 @@ static void codeexpval (FuncState *fs, OpCode op,
else if (op == OP_MUL && e1->ravi_type == RAVI_TNUMINT && e2->ravi_type == RAVI_TNUMINT) {
e1->u.info = luaK_codeABC(fs, OP_RAVI_MULII, 0, o1, o2);
}
#endif
else if (op == OP_SUB && e1->ravi_type == RAVI_TNUMFLT && e2->ravi_type == RAVI_TNUMFLT) {
e1->u.info = luaK_codeABC(fs, OP_RAVI_SUBFF, 0, o1, o2);
}
@ -1107,7 +1018,6 @@ static void codeexpval (FuncState *fs, OpCode op,
else if (op == OP_SUB && e1->ravi_type == RAVI_TNUMINT && e2->ravi_type == RAVI_TNUMINT) {
e1->u.info = luaK_codeABC(fs, OP_RAVI_SUBII, 0, o1, o2);
}
else if (op == OP_DIV && e1->ravi_type == RAVI_TNUMFLT && e2->ravi_type == RAVI_TNUMFLT) {
e1->u.info = luaK_codeABC(fs, OP_RAVI_DIVFF, 0, o1, o2);
}
@ -1120,7 +1030,6 @@ static void codeexpval (FuncState *fs, OpCode op,
else if (op == OP_DIV && e1->ravi_type == RAVI_TNUMINT && e2->ravi_type == RAVI_TNUMINT) {
e1->u.info = luaK_codeABC(fs, OP_RAVI_DIVII, 0, o1, o2);
}
else if (op == OP_BAND && e1->ravi_type == RAVI_TNUMINT && e2->ravi_type == RAVI_TNUMINT) {
e1->u.info = luaK_codeABC(fs, OP_RAVI_BAND_II, 0, o1, o2);
}
@ -1141,11 +1050,8 @@ static void codeexpval (FuncState *fs, OpCode op,
}
else {
#endif
e1->u.info = luaK_codeABC(fs, op, 0, o1, o2); /* generate opcode */
#if RAVI_ENABLED
}
#endif
e1->k = VRELOCABLE; /* all those operations are relocable */
if (isbinary) {
if ((op == OP_ADD || op == OP_SUB || op == OP_MUL || op == OP_DIV) &&

@ -85,23 +85,15 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = {
"ADDFF", /* A B C R(A) := RK(B) + RK(C) */
"ADDFI", /* A B C R(A) := RK(B) + RK(C) */
"ADDII", /* A B C R(A) := RK(B) + RK(C) */
"ADDFN", /* A B C R(A) := RK(B) + C */
"ADDIN", /* A B C R(A) := RK(B) + C */
"SUBFF", /* A B C R(A) := RK(B) - RK(C) */
"SUBFI", /* A B C R(A) := RK(B) - RK(C) */
"SUBIF", /* A B C R(A) := RK(B) - RK(C) */
"SUBII", /* A B C R(A) := RK(B) - RK(C) */
"SUBFN", /* A B C R(A) := RK(B) - C */
"SUBNF", /* A B C R(A) := B - RK(C) */
"SUBIN", /* A B C R(A) := RK(B) - C */
"SUBNI", /* A B C R(A) := B - RK(C) */
"MULFF", /* A B C R(A) := RK(B) * RK(C) */
"MULFI", /* A B C R(A) := RK(B) * RK(C) */
"MULII", /* A B C R(A) := RK(B) * RK(C) */
"MULFN", /* A B C R(A) := RK(B) * C */
"MULIN", /* A B C R(A) := RK(B) * C */
"DIVFF", /* A B C R(A) := RK(B) / RK(C) */
"DIVFI", /* A B C R(A) := RK(B) / RK(C) */
@ -219,23 +211,15 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = {
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_ADDFF A B C R(A) := RK(B) + RK(C) */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_ADDFI A B C R(A) := RK(B) + RK(C) */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_ADDII A B C R(A) := RK(B) + RK(C) */
,opmode(0, 1, OpArgK, OpArgU, iABC) /* OP_RAVI_ADDFN A B C R(A) := RK(B) + C */
,opmode(0, 1, OpArgK, OpArgU, iABC) /* OP_RAVI_ADDIN A B C R(A) := RK(B) + C */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_SUBFF A B C R(A) := RK(B) - RK(C) */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_SUBFI A B C R(A) := RK(B) - RK(C) */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_SUBIF A B C R(A) := RK(B) - RK(C) */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_SUBII A B C R(A) := RK(B) - RK(C) */
,opmode(0, 1, OpArgK, OpArgU, iABC) /* OP_RAVI_SUBFN A B C R(A) := RK(B) - C */
,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_RAVI_SUBNF A B C R(A) := B - RK(C) */
,opmode(0, 1, OpArgK, OpArgU, iABC) /* OP_RAVI_SUBIN A B C R(A) := RK(B) - C */
,opmode(0, 1, OpArgU, OpArgK, iABC) /* OP_RAVI_SUBNI A B C R(A) := B - RK(C) */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_MULFF A B C R(A) := RK(B) * RK(C) */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_MULFI A B C R(A) := RK(B) * RK(C) */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_MULII A B C R(A) := RK(B) * RK(C) */
,opmode(0, 1, OpArgK, OpArgU, iABC) /* OP_RAVI_MULFN A B C R(A) := RK(B) * C */
,opmode(0, 1, OpArgK, OpArgU, iABC) /* OP_RAVI_MULIN A B C R(A) := RK(B) * C */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_DIVFF A B C R(A) := RK(B) / RK(C) */
,opmode(0, 1, OpArgK, OpArgK, iABC) /* OP_RAVI_DIVFI A B C R(A) := RK(B) / RK(C) */
@ -500,22 +484,6 @@ static void PrintCode(const Proto* f)
if (ISK(c)) PrintConstant(f,INDEXK(c)); else printf("-");
}
break;
case OP_RAVI_ADDFN:
case OP_RAVI_ADDIN:
case OP_RAVI_SUBFN:
case OP_RAVI_SUBIN:
case OP_RAVI_MULFN:
case OP_RAVI_MULIN:
printf("\t; ");
if (ISK(b)) PrintConstant(f, INDEXK(b)); else printf("-");
printf(" %d", c);
break;
case OP_RAVI_SUBNF:
case OP_RAVI_SUBNI:
printf("\t; ");
printf("%d ", b);
if (ISK(c)) PrintConstant(f, INDEXK(c)); else printf("-");
break;
case OP_JMP:
case OP_FORLOOP:
case OP_RAVI_FORLOOP_IP:

@ -622,13 +622,13 @@ static void localvar_adjust_assign(LexState *ls, int nvars, int nexps, expdesc *
if (extra < 0) extra = 0;
/* following adjusts the C operand in the OP_CALL instruction */
luaK_setreturns(fs, e, extra); /* last exp. provides the difference */
#if RAVI_ENABLED
/* Since we did not know how many return values to process in localvar_explist() we
* need to add instructions for type coercions at this stage for any remaining
* variables
*/
ravi_coercetype(ls, e, extra);
#endif
if (extra > 1) luaK_reserveregs(fs, extra - 1);
}
else {
@ -638,12 +638,11 @@ static void localvar_adjust_assign(LexState *ls, int nvars, int nexps, expdesc *
luaK_reserveregs(fs, extra);
/* RAVI TODO for typed variables we should not set to nil? */
luaK_nil(fs, reg, extra);
#if RAVI_ENABLED
/* typed variables that are primitives cannot be set to nil so
/* typed variables that are primitives cannot be set to nil so
* we need to emit instructions to initialise them to default values
*/
ravi_setzero(fs, reg, extra);
#endif
}
}
}
@ -1199,7 +1198,6 @@ static int explist (LexState *ls, expdesc *v) {
return n;
}
#if RAVI_ENABLED
/* TODO instead of using vars here could we just rely upon register_typeinfo? */
static void ravi_typecheck(LexState *ls, expdesc *v, int *vars, int nvars,
int n) {
@ -1274,7 +1272,6 @@ static void ravi_typecheck(LexState *ls, expdesc *v, int *vars, int nvars,
luaX_syntaxerror(ls, "Invalid local assignment");
}
}
#endif
/* parse expression list, and validate that the expressions match expected
* types provided in vars array. This is a modified version of explist() to be
@ -1284,15 +1281,11 @@ static int localvar_explist(LexState *ls, expdesc *v, int *vars, int nvars) {
/* explist -> expr { ',' expr } */
int n = 1; /* at least one expression */
expr(ls, v);
#if RAVI_ENABLED
ravi_typecheck(ls, v, vars, nvars, 0);
#endif
while (testnext(ls, ',')) {
luaK_exp2nextreg(ls->fs, v);
expr(ls, v);
#if RAVI_ENABLED
ravi_typecheck(ls, v, vars, nvars, n);
#endif
n++;
}
return n;

@ -1387,17 +1387,7 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rc = RKC(i);
setivalue(ra, ivalue(rb) + ivalue(rc));
} break;
case OP_RAVI_ADDFN: {
int c = INDEXK(GETARG_C(i)); /* do we need INDEXK here ?*/
TValue *rb = RKB(i);
setfltvalue(ra, fltvalue(rb) + c);
} break;
case OP_RAVI_ADDIN: {
int c = INDEXK(GETARG_C(i)); /* do we need INDEXK here? */
TValue *rb = RKB(i);
setivalue(ra, ivalue(rb) + c);
} break;
case OP_RAVI_SUBFF: {
TValue *rb = RKB(i);
TValue *rc = RKC(i);
@ -1418,26 +1408,6 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rc = RKC(i);
setivalue(ra, ivalue(rb) - ivalue(rc));
} break;
case OP_RAVI_SUBFN: {
int c = INDEXK(GETARG_C(i)); /* do we need INDEXK here ?*/
TValue *rb = RKB(i);
setfltvalue(ra, fltvalue(rb) - c);
} break;
case OP_RAVI_SUBNF: {
int b = INDEXK(GETARG_B(i)); /* do we need INDEXK here? */
TValue *rc = RKC(i);
setfltvalue(ra, b - fltvalue(rc));
} break;
case OP_RAVI_SUBIN: {
int c = INDEXK(GETARG_C(i)); /* do we need INDEXK here ?*/
TValue *rb = RKB(i);
setivalue(ra, ivalue(rb) - c);
} break;
case OP_RAVI_SUBNI: {
int b = INDEXK(GETARG_B(i)); /* do we need INDEXK here? */
TValue *rc = RKC(i);
setivalue(ra, b - ivalue(rc));
} break;
case OP_RAVI_MULFF: {
TValue *rb = RKB(i);
@ -1454,16 +1424,6 @@ newframe: /* reentry point when frame changes (call/return) */
TValue *rc = RKC(i);
setivalue(ra, ivalue(rb) * ivalue(rc));
} break;
case OP_RAVI_MULFN: {
int c = INDEXK(GETARG_C(i)); /* do we need INDEXK here ?*/
TValue *rb = RKB(i);
setfltvalue(ra, fltvalue(rb) * c);
} break;
case OP_RAVI_MULIN: {
int c = INDEXK(GETARG_C(i)); /* do we need INDEXK here? */
TValue *rb = RKB(i);
setivalue(ra, ivalue(rb) * c);
} break;
case OP_RAVI_DIVFF: {
TValue *rb = RKB(i);

@ -48,19 +48,6 @@ void RaviCodeGenerator::emit_UNMI(RaviFunctionDef *def, int A, int B) {
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) + C, result is floating
void RaviCodeGenerator::emit_ADDFN(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rb = emit_gep_register_or_constant(def, B);
llvm::Instruction *lhs = emit_load_reg_n(def, rb);
llvm::Value *result = def->builder->CreateFAdd(
lhs,
def->builder->CreateSIToFP(llvm::ConstantInt::get(def->types->C_intT, C),
def->types->lua_NumberT));
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) + RK(C), all floating
void RaviCodeGenerator::emit_ADDFF(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
@ -93,18 +80,6 @@ void RaviCodeGenerator::emit_ADDII(RaviFunctionDef *def, int A, int B, int C) {
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) + C, int+c
void RaviCodeGenerator::emit_ADDIN(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rb = emit_gep_register_or_constant(def, B);
llvm::Instruction *lhs = emit_load_reg_i(def, rb);
llvm::Value *result = def->builder->CreateAdd(
lhs, llvm::ConstantInt::get(def->types->lua_IntegerT, C), "", false,
true);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) - RK(C), float-float
void RaviCodeGenerator::emit_SUBFF(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
@ -147,68 +122,6 @@ void RaviCodeGenerator::emit_SUBII(RaviFunctionDef *def, int A, int B, int C) {
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) - C, float - c
void RaviCodeGenerator::emit_SUBFN(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rb = emit_gep_register_or_constant(def, B);
llvm::Instruction *lhs = emit_load_reg_n(def, rb);
llvm::Value *result = def->builder->CreateFSub(
lhs,
def->builder->CreateSIToFP(llvm::ConstantInt::get(def->types->C_intT, C),
def->types->lua_NumberT));
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := B - RK(C), b - float
void RaviCodeGenerator::emit_SUBNF(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rc = emit_gep_register_or_constant(def, C);
llvm::Instruction *rhs = emit_load_reg_n(def, rc);
llvm::Value *result = def->builder->CreateFSub(
def->builder->CreateSIToFP(llvm::ConstantInt::get(def->types->C_intT, B),
def->types->lua_NumberT),
rhs);
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := B - RK(C), b - int
void RaviCodeGenerator::emit_SUBIN(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rb = emit_gep_register_or_constant(def, B);
llvm::Instruction *lhs = emit_load_reg_i(def, rb);
llvm::Value *result = def->builder->CreateSub(
lhs, llvm::ConstantInt::get(def->types->lua_IntegerT, C), "", false,
true);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) - C, int - c
void RaviCodeGenerator::emit_SUBNI(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rc = emit_gep_register_or_constant(def, C);
llvm::Instruction *rhs = emit_load_reg_i(def, rc);
llvm::Value *result = def->builder->CreateSub(
llvm::ConstantInt::get(def->types->lua_IntegerT, C), rhs, "", false,
true);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) * C, float*c
void RaviCodeGenerator::emit_MULFN(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rb = emit_load_register_or_constant_n(def, B);
llvm::Value *result = def->builder->CreateFMul(
rb,
def->builder->CreateSIToFP(llvm::ConstantInt::get(def->types->C_intT, C),
def->types->lua_NumberT));
emit_store_reg_n_withtype(def, result, ra);
}
// R(A) := RK(B) * RK(C), float*float
void RaviCodeGenerator::emit_MULFF(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
@ -241,18 +154,6 @@ void RaviCodeGenerator::emit_MULII(RaviFunctionDef *def, int A, int B, int C) {
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) * C, int*c
void RaviCodeGenerator::emit_MULIN(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);
llvm::Value *ra = emit_gep_register(def, A);
llvm::Value *rb = emit_gep_register_or_constant(def, B);
llvm::Instruction *lhs = emit_load_reg_i(def, rb);
llvm::Value *result = def->builder->CreateMul(
lhs, llvm::ConstantInt::get(def->types->lua_IntegerT, C), "", false,
true);
emit_store_reg_i_withtype(def, result, ra);
}
// R(A) := RK(B) / RK(C), float/float
void RaviCodeGenerator::emit_DIVFF(RaviFunctionDef *def, int A, int B, int C) {
emit_load_base(def);

@ -713,8 +713,6 @@ bool RaviCodeGenerator::canCompile(Proto *p) {
case OP_RAVI_TOFLT:
case OP_RAVI_LOADFZ:
case OP_RAVI_LOADIZ:
case OP_RAVI_ADDFN:
case OP_RAVI_ADDIN:
case OP_RAVI_ADDFF:
case OP_RAVI_ADDFI:
case OP_RAVI_ADDII:
@ -722,12 +720,6 @@ bool RaviCodeGenerator::canCompile(Proto *p) {
case OP_RAVI_SUBFI:
case OP_RAVI_SUBIF:
case OP_RAVI_SUBII:
case OP_RAVI_SUBFN:
case OP_RAVI_SUBNF:
case OP_RAVI_SUBIN:
case OP_RAVI_SUBNI:
case OP_RAVI_MULFN:
case OP_RAVI_MULIN:
case OP_RAVI_MULFF:
case OP_RAVI_MULFI:
case OP_RAVI_MULII:
@ -1443,16 +1435,6 @@ void RaviCodeGenerator::compile(lua_State *L, Proto *p, bool doDump,
int C = GETARG_C(i);
emit_ARITH(def, A, B, C, OP_ADD, TM_ADD);
} break;
case OP_RAVI_ADDFN: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_ADDFN(def, A, B, C);
} break;
case OP_RAVI_ADDIN: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_ADDIN(def, A, B, C);
} break;
case OP_RAVI_ADDFF: {
int B = GETARG_B(i);
int C = GETARG_C(i);
@ -1494,42 +1476,12 @@ void RaviCodeGenerator::compile(lua_State *L, Proto *p, bool doDump,
int C = GETARG_C(i);
emit_SUBII(def, A, B, C);
} break;
case OP_RAVI_SUBFN: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_SUBFN(def, A, B, C);
} break;
case OP_RAVI_SUBNF: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_SUBNF(def, A, B, C);
} break;
case OP_RAVI_SUBIN: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_SUBIN(def, A, B, C);
} break;
case OP_RAVI_SUBNI: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_SUBNI(def, A, B, C);
} break;
case OP_MUL: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_ARITH(def, A, B, C, OP_MUL, TM_MUL);
} break;
case OP_RAVI_MULFN: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_MULFN(def, A, B, C);
} break;
case OP_RAVI_MULIN: {
int B = GETARG_B(i);
int C = GETARG_C(i);
emit_MULIN(def, A, B, C);
} break;
case OP_RAVI_MULFF: {
int B = GETARG_B(i);
int C = GETARG_C(i);

Loading…
Cancel
Save