aboutsummaryrefslogtreecommitdiff
path: root/lopcodes.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-15 16:53:48 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-12-15 16:53:48 -0200
commitf8c1c1469aac2253f0787c0cb7cc228b1a57e738 (patch)
tree8770165aea5b365dfc230a669c6afe14a1b30bf9 /lopcodes.h
parent4b6928e7f524e2c2740fc1f9d16e130e0e2f4172 (diff)
downloadlua-f8c1c1469aac2253f0787c0cb7cc228b1a57e738.tar.gz
lua-f8c1c1469aac2253f0787c0cb7cc228b1a57e738.tar.bz2
lua-f8c1c1469aac2253f0787c0cb7cc228b1a57e738.zip
some cleaning on signed opcode parameters
Diffstat (limited to 'lopcodes.h')
-rw-r--r--lopcodes.h29
1 files changed, 16 insertions, 13 deletions
diff --git a/lopcodes.h b/lopcodes.h
index 3338f717..c3269dff 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.177 2017/12/13 18:32:09 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.178 2017/12/15 18:35:22 roberto Exp roberto $
3** Opcodes for Lua virtual machine 3** Opcodes for Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -62,13 +62,14 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
62** so they must fit in LUAI_BITSINT-1 bits (-1 for sign) 62** so they must fit in LUAI_BITSINT-1 bits (-1 for sign)
63*/ 63*/
64#if SIZE_Bx < LUAI_BITSINT-1 64#if SIZE_Bx < LUAI_BITSINT-1
65#define MAXARG_Bx ((1<<SIZE_Bx)-1) 65#define MAXARG_Bx ((1<<SIZE_Bx)-1)
66#define MAXARG_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */
67#else 66#else
68#define MAXARG_Bx MAX_INT 67#define MAXARG_Bx MAX_INT
69#define MAXARG_sBx MAX_INT
70#endif 68#endif
71 69
70#define OFFSET_sBx (MAXARG_Bx>>1) /* 'sBx' is signed */
71
72
72#if SIZE_Ax < LUAI_BITSINT-1 73#if SIZE_Ax < LUAI_BITSINT-1
73#define MAXARG_Ax ((1<<SIZE_Ax)-1) 74#define MAXARG_Ax ((1<<SIZE_Ax)-1)
74#else 75#else
@@ -76,16 +77,18 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
76#endif 77#endif
77 78
78#if SIZE_sJ < LUAI_BITSINT-1 79#if SIZE_sJ < LUAI_BITSINT-1
79#define MAXARG_sJ ((1 << (SIZE_sJ - 1)) - 1) 80#define MAXARG_sJ ((1 << SIZE_sJ) - 1)
80#else 81#else
81#define MAXARG_sJ MAX_INT 82#define MAXARG_sJ MAX_INT
82#endif 83#endif
83 84
85#define OFFSET_sJ (MAXARG_sJ >> 1)
86
84 87
85#define MAXARG_A ((1<<SIZE_A)-1) 88#define MAXARG_A ((1<<SIZE_A)-1)
86#define MAXARG_B ((1<<SIZE_B)-1) 89#define MAXARG_B ((1<<SIZE_B)-1)
87#define MAXARG_C ((1<<SIZE_C)-1) 90#define MAXARG_C ((1<<SIZE_C)-1)
88#define MAXARG_sC (MAXARG_C >> 1) 91#define OFFSET_sC (MAXARG_C >> 1)
89#define MAXARG_Cx ((1<<(SIZE_C + 1))-1) 92#define MAXARG_Cx ((1<<(SIZE_C + 1))-1)
90 93
91 94
@@ -114,11 +117,11 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
114#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A) 117#define SETARG_A(i,v) setarg(i, v, POS_A, SIZE_A)
115 118
116#define GETARG_B(i) check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B)) 119#define GETARG_B(i) check_exp(checkopm(i, iABC), getarg(i, POS_B, SIZE_B))
117#define GETARG_sB(i) (GETARG_B(i) - MAXARG_sC) 120#define GETARG_sB(i) (GETARG_B(i) - OFFSET_sC)
118#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B) 121#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
119 122
120#define GETARG_C(i) check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C)) 123#define GETARG_C(i) check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C))
121#define GETARG_sC(i) (GETARG_C(i) - MAXARG_sC) 124#define GETARG_sC(i) (GETARG_C(i) - OFFSET_sC)
122#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) 125#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
123 126
124#define TESTARG_k(i) (cast(int, ((i) & (1u << POS_k)))) 127#define TESTARG_k(i) (cast(int, ((i) & (1u << POS_k))))
@@ -132,13 +135,13 @@ enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
132#define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax) 135#define SETARG_Ax(i,v) setarg(i, v, POS_Ax, SIZE_Ax)
133 136
134#define GETARG_sBx(i) \ 137#define GETARG_sBx(i) \
135 check_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - MAXARG_sBx) 138 check_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - OFFSET_sBx)
136#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) 139#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+OFFSET_sBx))
137 140
138#define GETARG_sJ(i) \ 141#define GETARG_sJ(i) \
139 check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - MAXARG_sJ) 142 check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - OFFSET_sJ)
140#define SETARG_sJ(i,j) \ 143#define SETARG_sJ(i,j) \
141 setarg(i, cast(unsigned int, (j)+MAXARG_sJ), POS_sJ, SIZE_sJ) 144 setarg(i, cast(unsigned int, (j)+OFFSET_sJ), POS_sJ, SIZE_sJ)
142 145
143 146
144#define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \ 147#define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \