diff options
Diffstat (limited to 'src/lj_bc.h')
-rw-r--r-- | src/lj_bc.h | 27 |
1 files changed, 13 insertions, 14 deletions
diff --git a/src/lj_bc.h b/src/lj_bc.h index 9dffe0c0..97e4d926 100644 --- a/src/lj_bc.h +++ b/src/lj_bc.h | |||
@@ -31,30 +31,29 @@ | |||
31 | #define NO_JMP (~(BCPos)0) | 31 | #define NO_JMP (~(BCPos)0) |
32 | 32 | ||
33 | /* Macros to get instruction fields. */ | 33 | /* Macros to get instruction fields. */ |
34 | #define bc_op(i) (cast(BCOp, (i)&0xff)) | 34 | #define bc_op(i) ((BCOp)((i)&0xff)) |
35 | #define bc_a(i) (cast(BCReg, ((i)>>8)&0xff)) | 35 | #define bc_a(i) ((BCReg)(((i)>>8)&0xff)) |
36 | #define bc_b(i) (cast(BCReg, (i)>>24)) | 36 | #define bc_b(i) ((BCReg)((i)>>24)) |
37 | #define bc_c(i) (cast(BCReg, ((i)>>16)&0xff)) | 37 | #define bc_c(i) ((BCReg)(((i)>>16)&0xff)) |
38 | #define bc_d(i) (cast(BCReg, (i)>>16)) | 38 | #define bc_d(i) ((BCReg)((i)>>16)) |
39 | #define bc_j(i) ((ptrdiff_t)bc_d(i)-BCBIAS_J) | 39 | #define bc_j(i) ((ptrdiff_t)bc_d(i)-BCBIAS_J) |
40 | 40 | ||
41 | /* Macros to set instruction fields. */ | 41 | /* Macros to set instruction fields. */ |
42 | #define setbc_byte(p, x, ofs) \ | 42 | #define setbc_byte(p, x, ofs) \ |
43 | ((uint8_t *)(p))[LJ_ENDIAN_SELECT(ofs, 3-ofs)] = cast_byte(x) | 43 | ((uint8_t *)(p))[LJ_ENDIAN_SELECT(ofs, 3-ofs)] = (uint8_t)(x) |
44 | #define setbc_op(p, x) setbc_byte(p, (x), 0) | 44 | #define setbc_op(p, x) setbc_byte(p, (x), 0) |
45 | #define setbc_a(p, x) setbc_byte(p, (x), 1) | 45 | #define setbc_a(p, x) setbc_byte(p, (x), 1) |
46 | #define setbc_b(p, x) setbc_byte(p, (x), 3) | 46 | #define setbc_b(p, x) setbc_byte(p, (x), 3) |
47 | #define setbc_c(p, x) setbc_byte(p, (x), 2) | 47 | #define setbc_c(p, x) setbc_byte(p, (x), 2) |
48 | #define setbc_d(p, x) \ | 48 | #define setbc_d(p, x) \ |
49 | ((uint16_t *)(p))[LJ_ENDIAN_SELECT(1, 0)] = cast(uint16_t, (x)) | 49 | ((uint16_t *)(p))[LJ_ENDIAN_SELECT(1, 0)] = (uint16_t)(x) |
50 | #define setbc_j(p, x) setbc_d(p, (BCPos)((int32_t)(x)+BCBIAS_J)) | 50 | #define setbc_j(p, x) setbc_d(p, (BCPos)((int32_t)(x)+BCBIAS_J)) |
51 | 51 | ||
52 | /* Macros to compose instructions. */ | 52 | /* Macros to compose instructions. */ |
53 | #define BCINS_ABC(o, a, b, c) \ | 53 | #define BCINS_ABC(o, a, b, c) \ |
54 | (cast(BCIns, o)|(cast(BCIns, a)<<8)|\ | 54 | (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(b)<<24)|((BCIns)(c)<<16)) |
55 | (cast(BCIns, b)<<24)|(cast(BCIns, c)<<16)) | ||
56 | #define BCINS_AD(o, a, d) \ | 55 | #define BCINS_AD(o, a, d) \ |
57 | (cast(BCIns, o)|(cast(BCIns, a)<<8)|(cast(BCIns, d)<<16)) | 56 | (((BCIns)(o))|((BCIns)(a)<<8)|((BCIns)(d)<<16)) |
58 | #define BCINS_AJ(o, a, j) BCINS_AD(o, a, (BCPos)((int32_t)(j)+BCBIAS_J)) | 57 | #define BCINS_AJ(o, a, j) BCINS_AD(o, a, (BCPos)((int32_t)(j)+BCBIAS_J)) |
59 | 58 | ||
60 | /* Bytecode instruction definition. Order matters, see below. | 59 | /* Bytecode instruction definition. Order matters, see below. |
@@ -240,12 +239,12 @@ typedef enum { | |||
240 | } BCMode; | 239 | } BCMode; |
241 | #define BCM___ BCMnone | 240 | #define BCM___ BCMnone |
242 | 241 | ||
243 | #define bcmode_a(op) (cast(BCMode, lj_bc_mode[op] & 7)) | 242 | #define bcmode_a(op) ((BCMode)(lj_bc_mode[op] & 7)) |
244 | #define bcmode_b(op) (cast(BCMode, (lj_bc_mode[op]>>3) & 15)) | 243 | #define bcmode_b(op) ((BCMode)((lj_bc_mode[op]>>3) & 15)) |
245 | #define bcmode_c(op) (cast(BCMode, (lj_bc_mode[op]>>7) & 15)) | 244 | #define bcmode_c(op) ((BCMode)((lj_bc_mode[op]>>7) & 15)) |
246 | #define bcmode_d(op) bcmode_c(op) | 245 | #define bcmode_d(op) bcmode_c(op) |
247 | #define bcmode_hasd(op) ((lj_bc_mode[op] & (15<<3)) == (BCMnone<<3)) | 246 | #define bcmode_hasd(op) ((lj_bc_mode[op] & (15<<3)) == (BCMnone<<3)) |
248 | #define bcmode_mm(op) (cast(MMS, lj_bc_mode[op]>>11)) | 247 | #define bcmode_mm(op) ((MMS)(lj_bc_mode[op]>>11)) |
249 | 248 | ||
250 | #define BCMODE(name, ma, mb, mc, mm) \ | 249 | #define BCMODE(name, ma, mb, mc, mm) \ |
251 | (BCM##ma|(BCM##mb<<3)|(BCM##mc<<7)|(MM_##mm<<11)), | 250 | (BCM##ma|(BCM##mb<<3)|(BCM##mc<<7)|(MM_##mm<<11)), |