32 enum OpMode {iABC, iABx, iAsBx, iAx, isJ};
40 #define SIZE_Bx (SIZE_C + SIZE_B + 1) 42 #define SIZE_Ax (SIZE_Bx + SIZE_A) 43 #define SIZE_sJ (SIZE_Bx + SIZE_A) 49 #define POS_A (POS_OP + SIZE_OP) 50 #define POS_k (POS_A + SIZE_A) 51 #define POS_B (POS_k + 1) 52 #define POS_C (POS_B + SIZE_B) 68 #define L_INTHASBITS(b) ((UINT_MAX >> ((b) - 1)) >= 1) 71 #if L_INTHASBITS(SIZE_Bx) 72 #define MAXARG_Bx ((1<<SIZE_Bx)-1) 74 #define MAXARG_Bx MAX_INT 77 #define OFFSET_sBx (MAXARG_Bx>>1) 80 #if L_INTHASBITS(SIZE_Ax) 81 #define MAXARG_Ax ((1<<SIZE_Ax)-1) 83 #define MAXARG_Ax MAX_INT 86 #if L_INTHASBITS(SIZE_sJ) 87 #define MAXARG_sJ ((1 << SIZE_sJ) - 1) 89 #define MAXARG_sJ MAX_INT 92 #define OFFSET_sJ (MAXARG_sJ >> 1) 95 #define MAXARG_A ((1<<SIZE_A)-1) 96 #define MAXARG_B ((1<<SIZE_B)-1) 97 #define MAXARG_C ((1<<SIZE_C)-1) 98 #define OFFSET_sC (MAXARG_C >> 1) 100 #define int2sC(i) ((i) + OFFSET_sC) 101 #define sC2int(i) ((i) - OFFSET_sC) 105 #define MASK1(n,p) ((~((~(Instruction)0)<<(n)))<<(p)) 108 #define MASK0(n,p) (~MASK1(n,p)) 114 #define GET_OPCODE(i) (cast(OpCode, ((i)>>POS_OP) & MASK1(SIZE_OP,0))) 115 #define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,POS_OP)) | \ 116 ((cast(Instruction, o)<<POS_OP)&MASK1(SIZE_OP,POS_OP)))) 118 #define checkopm(i,m) (getOpMode(GET_OPCODE(i)) == m) 121 #define getarg(i,pos,size) (cast_int(((i)>>(pos)) & MASK1(size,0))) 122 #define setarg(i,v,pos,size) ((i) = (((i)&MASK0(size,pos)) | \ 123 ((cast(Instruction, v)<<pos)&MASK1(size,pos)))) 125 #define GETARG_A(i) getarg(i, POS_A, SIZE_A) 126 #define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A) 128 #define GETARG_B(i) check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B)) 129 #define GETARG_sB(i) sC2int(GETARG_B(i)) 130 #define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B) 132 #define GETARG_C(i) check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C)) 133 #define GETARG_sC(i) sC2int(GETARG_C(i)) 134 #define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) 136 #define TESTARG_k(i) check_exp(checkopm(i, iABC), (cast_int(((i) & (1u << POS_k))))) 137 #define GETARG_k(i) check_exp(checkopm(i, iABC), getarg(i, POS_k, 1)) 138 #define SETARG_k(i,v) setarg(i, v, POS_k, 1) 140 #define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx)) 141 #define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx) 143 #define GETARG_Ax(i) check_exp(checkopm(i, iAx), getarg(i, POS_Ax, SIZE_Ax)) 144 #define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax) 146 #define GETARG_sBx(i) \ 147 check_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - OFFSET_sBx) 148 #define SETARG_sBx(i,b) SETARG_Bx((i),cast_uint((b)+OFFSET_sBx)) 150 #define GETARG_sJ(i) \ 151 check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - OFFSET_sJ) 152 #define SETARG_sJ(i,j) \ 153 setarg(i, cast_uint((j)+OFFSET_sJ), POS_sJ, SIZE_sJ) 156 #define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \ 157 | (cast(Instruction, a)<<POS_A) \ 158 | (cast(Instruction, b)<<POS_B) \ 159 | (cast(Instruction, c)<<POS_C) \ 160 | (cast(Instruction, k)<<POS_k)) 162 #define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \ 163 | (cast(Instruction, a)<<POS_A) \ 164 | (cast(Instruction, bc)<<POS_Bx)) 166 #define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \ 167 | (cast(Instruction, a)<<POS_Ax)) 169 #define CREATE_sJ(o,j,k) ((cast(Instruction, o) << POS_OP) \ 170 | (cast(Instruction, j) << POS_sJ) \ 171 | (cast(Instruction, k) << POS_k)) 174 #if !defined(MAXINDEXRK) 175 #define MAXINDEXRK MAXARG_B 182 #define NO_REG MAXARG_A 312 #define NUM_OPCODES ((int)(OP_EXTRAARG) + 1) 368 LUAI_DDEC(
const lu_byte luaP_opmodes[NUM_OPCODES];)
370 #define getOpMode(m) (cast(
enum OpMode, luaP_opmodes[m] & 7))
371 #define testAMode(m) (luaP_opmodes[m] & (1 << 3))
372 #define testTMode(m) (luaP_opmodes[m] & (1 << 4)) 373 #define testITMode(m) (luaP_opmodes[m] & (1 << 5)) 374 #define testOTMode(m) (luaP_opmodes[m] & (1 << 6)) 375 #define testMMMode(m) (luaP_opmodes[m] & (1 << 7)) 379 ((testOTMode(GET_OPCODE(i)) && GETARG_C(i) == 0) || \ 380 GET_OPCODE(i) == OP_TAILCALL) 383 #define isIT(i) (testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0) 385 #define opmode(mm,ot,it,t,a,m) \ 386 (((mm) << 7) | ((ot) << 6) | ((it) << 5) | ((t) << 4) | ((a) << 3) | (m)) 390 #define LFIELDS_PER_FLUSH 50