keep more opcode arguments byte-aligned

This commit is contained in:
Roberto Ierusalimschy 2018-01-09 09:24:12 -02:00
parent a9295a2b8e
commit 33e3774f44
3 changed files with 31 additions and 27 deletions

12
lcode.c
View File

@ -1,5 +1,5 @@
/* /*
** $Id: lcode.c,v 2.147 2017/12/22 14:16:46 roberto Exp roberto $ ** $Id: lcode.c,v 2.149 2018/01/09 11:21:41 roberto Exp $
** Code generator for Lua ** Code generator for Lua
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -262,16 +262,16 @@ void luaK_patchtohere (FuncState *fs, int list) {
/* /*
** Correct a jump list to jump to 'target'. If 'hasclose' is true, ** Correct a jump list to jump to 'target'. If 'hasclose' is true,
** 'target' contains an OP_CLOSE instruction (see first assert). ** 'target' contains an OP_CLOSE instruction (see first assert).
** Only jumps with the 'k' arg true need that close; other jumps ** Only the jumps with ('m' == true) need that close; other jumps
** avoid it jumping to the next instruction. ** avoid it jumping to the next instruction.
*/ */
void luaK_patchgoto (FuncState *fs, int list, int target, int hasclose) { void luaK_patchgoto (FuncState *fs, int list, int target, int hasclose) {
lua_assert(!hasclose || GET_OPCODE(fs->f->code[target]) == OP_CLOSE); lua_assert(!hasclose || GET_OPCODE(fs->f->code[target]) == OP_CLOSE);
while (list != NO_JUMP) { while (list != NO_JUMP) {
int next = getjump(fs, list); int next = getjump(fs, list);
lua_assert(!GETARG_k(fs->f->code[list]) || hasclose); lua_assert(!GETARG_m(fs->f->code[list]) || hasclose);
patchtestreg(fs, list, NO_REG); /* do not generate values */ patchtestreg(fs, list, NO_REG); /* do not generate values */
if (!hasclose || GETARG_k(fs->f->code[list])) if (!hasclose || GETARG_m(fs->f->code[list]))
fixjump(fs, list, target); fixjump(fs, list, target);
else /* there is a CLOSE instruction but jump does not need it */ else /* there is a CLOSE instruction but jump does not need it */
fixjump(fs, list, target + 1); /* avoid CLOSE instruction */ fixjump(fs, list, target + 1); /* avoid CLOSE instruction */
@ -281,14 +281,14 @@ void luaK_patchgoto (FuncState *fs, int list, int target, int hasclose) {
/* /*
** Mark (using the 'k' arg) all jumps in 'list' to close upvalues. Mark ** Mark (using the 'm' arg) all jumps in 'list' to close upvalues. Mark
** will instruct 'luaK_patchgoto' to make these jumps go to OP_CLOSE ** will instruct 'luaK_patchgoto' to make these jumps go to OP_CLOSE
** instructions. ** instructions.
*/ */
void luaK_patchclose (FuncState *fs, int list) { void luaK_patchclose (FuncState *fs, int list) {
for (; list != NO_JUMP; list = getjump(fs, list)) { for (; list != NO_JUMP; list = getjump(fs, list)) {
lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP); lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP);
SETARG_k(fs->f->code[list], 1); SETARG_m(fs->f->code[list], 1);
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lopcodes.h,v 1.180 2017/12/18 17:49:31 roberto Exp roberto $ ** $Id: lopcodes.h,v 1.182 2018/01/09 11:21:41 roberto Exp $
** Opcodes for Lua virtual machine ** Opcodes for Lua virtual machine
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -17,11 +17,11 @@
3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 3 3 2 2 2 2 2 2 2 2 2 2 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
iABC |k| C(8) | | B(8) | | A(8) | | Op(7) | iABC C(8) | B(8) |k| A(8) | Op(7) |
iABx | Bx(17) | | A(8) | | Op(7) | iABx Bx(17) | A(8) | Op(7) |
iAsBx | sBx (signed)(17) | | A(8) | | Op(7) | iAsB sBx (signed)(17) | A(8) | Op(7) |
iAx | Ax(25) | | Op(7) | iAx Ax(25) | Op(7) |
iksJ |k| sJ(24) | | Op(7) | isJ sJ(24) |m| Op(7) |
A signed argument is represented in excess K: the represented value is A signed argument is represented in excess K: the represented value is
the written unsigned value minus K, where K is half the maximum for the the written unsigned value minus K, where K is half the maximum for the
@ -36,25 +36,27 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
** size and position of opcode arguments. ** size and position of opcode arguments.
*/ */
#define SIZE_C 8 #define SIZE_C 8
#define SIZE_Cx (SIZE_C + 1)
#define SIZE_B 8 #define SIZE_B 8
#define SIZE_Bx (SIZE_Cx + SIZE_B) #define SIZE_Bx (SIZE_C + SIZE_B + 1)
#define SIZE_A 8 #define SIZE_A 8
#define SIZE_Ax (SIZE_Cx + SIZE_B + SIZE_A) #define SIZE_Ax (SIZE_Bx + SIZE_A)
#define SIZE_sJ (SIZE_C + SIZE_B + SIZE_A) #define SIZE_sJ (SIZE_Bx + SIZE_A - 1)
#define SIZE_OP 7 #define SIZE_OP 7
#define POS_OP 0 #define POS_OP 0
#define POS_A (POS_OP + SIZE_OP)
#define POS_B (POS_A + SIZE_A)
#define POS_C (POS_B + SIZE_B)
#define POS_k (POS_C + SIZE_C)
#define POS_Bx POS_B
#define POS_Ax POS_A
#define POS_sJ POS_A
#define POS_A (POS_OP + SIZE_OP)
#define POS_k (POS_A + SIZE_A)
#define POS_B (POS_k + 1)
#define POS_C (POS_B + SIZE_B)
#define POS_Bx POS_k
#define POS_Ax POS_A
#define POS_m POS_A
#define POS_sJ (POS_A + 1)
/* /*
** limits for opcode arguments. ** limits for opcode arguments.
@ -125,7 +127,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) #define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
#define TESTARG_k(i) (cast(int, ((i) & (1u << POS_k)))) #define TESTARG_k(i) (cast(int, ((i) & (1u << POS_k))))
#define GETARG_k(i) getarg(i, POS_k, 1) #define GETARG_k(i) check_exp(checkopm(i, iABC), getarg(i, POS_k, 1))
#define SETARG_k(i,v) setarg(i, v, POS_k, 1) #define SETARG_k(i,v) setarg(i, v, POS_k, 1)
#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx)) #define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx))
@ -142,6 +144,8 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - OFFSET_sJ) check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - OFFSET_sJ)
#define SETARG_sJ(i,j) \ #define SETARG_sJ(i,j) \
setarg(i, cast(unsigned int, (j)+OFFSET_sJ), POS_sJ, SIZE_sJ) setarg(i, cast(unsigned int, (j)+OFFSET_sJ), POS_sJ, SIZE_sJ)
#define GETARG_m(i) check_exp(checkopm(i, isJ), getarg(i, POS_m, 1))
#define SETARG_m(i,m) setarg(i, m, POS_m, 1)
#define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \ #define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \

View File

@ -1,5 +1,5 @@
/* /*
** $Id: ltests.c,v 2.237 2017/12/15 18:53:48 roberto Exp roberto $ ** $Id: ltests.c,v 2.239 2018/01/09 11:21:41 roberto Exp $
** Internal Module for Debugging of the Lua Implementation ** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -557,7 +557,7 @@ static char *buildop (Proto *p, int pc, char *buff) {
break; break;
case isJ: case isJ:
sprintf(buff+strlen(buff), "%-12s%4d (%1d)", name, GETARG_sJ(i), sprintf(buff+strlen(buff), "%-12s%4d (%1d)", name, GETARG_sJ(i),
!!GETARG_k(i)); !!GETARG_m(i));
break; break;
} }
return buff; return buff;