aboutsummaryrefslogtreecommitdiff
path: root/lopcodes.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-07 15:20:42 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-11-07 15:20:42 -0200
commitc3e5946fb2b7b5781d9bca9d303967abe6263482 (patch)
tree012bee6184675f1559e994eba42dda7c38381283 /lopcodes.h
parentad0704e40cc7b3135fedc6d40a522addb039e090 (diff)
downloadlua-c3e5946fb2b7b5781d9bca9d303967abe6263482.tar.gz
lua-c3e5946fb2b7b5781d9bca9d303967abe6263482.tar.bz2
lua-c3e5946fb2b7b5781d9bca9d303967abe6263482.zip
new format for JUMP instructions (to allow larger offsets)
Diffstat (limited to 'lopcodes.h')
-rw-r--r--lopcodes.h30
1 files changed, 25 insertions, 5 deletions
diff --git a/lopcodes.h b/lopcodes.h
index de0c5cc1..bc8d722f 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.165 2017/10/04 15:49:24 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.166 2017/10/04 21:56:32 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*/
@@ -21,6 +21,7 @@ iABC |k| C(8) | | B(8) | | A(8) | | Op(7) |
21iABx | Bx(17) | | A(8) | | Op(7) | 21iABx | Bx(17) | | A(8) | | Op(7) |
22iAsBx | sBx (signed)(17) | | A(8) | | Op(7) | 22iAsBx | sBx (signed)(17) | | A(8) | | Op(7) |
23iAx | Ax(25) | | Op(7) | 23iAx | Ax(25) | | Op(7) |
24iksJ |k| sJ(24) | | Op(7) |
24 25
25 A signed argument is represented in excess K: the represented value is 26 A signed argument is represented in excess K: the represented value is
26 the written unsigned value minus K, where K is half the maximum for the 27 the written unsigned value minus K, where K is half the maximum for the
@@ -28,7 +29,7 @@ iAx | Ax(25) | | Op(7) |
28===========================================================================*/ 29===========================================================================*/
29 30
30 31
31enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */ 32enum OpMode {iABC, iABx, iAsBx, iAx, isJ}; /* basic instruction formats */
32 33
33 34
34/* 35/*
@@ -40,6 +41,8 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
40#define SIZE_Bx (SIZE_Cx + SIZE_B) 41#define SIZE_Bx (SIZE_Cx + SIZE_B)
41#define SIZE_A 8 42#define SIZE_A 8
42#define SIZE_Ax (SIZE_Cx + SIZE_B + SIZE_A) 43#define SIZE_Ax (SIZE_Cx + SIZE_B + SIZE_A)
44#define SIZE_sJ (SIZE_C + SIZE_B + SIZE_A)
45
43 46
44#define SIZE_OP 7 47#define SIZE_OP 7
45 48
@@ -50,6 +53,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
50#define POS_k (POS_C + SIZE_C) 53#define POS_k (POS_C + SIZE_C)
51#define POS_Bx POS_B 54#define POS_Bx POS_B
52#define POS_Ax POS_A 55#define POS_Ax POS_A
56#define POS_sJ POS_A
53 57
54 58
55/* 59/*
@@ -71,6 +75,12 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
71#define MAXARG_Ax MAX_INT 75#define MAXARG_Ax MAX_INT
72#endif 76#endif
73 77
78#if SIZE_sJ < LUAI_BITSINT-1
79#define MAXARG_sJ ((1 << (SIZE_sJ - 1)) - 1)
80#else
81#define MAXARG_sJ MAX_INT
82#endif
83
74 84
75#define MAXARG_A ((1<<SIZE_A)-1) 85#define MAXARG_A ((1<<SIZE_A)-1)
76#define MAXARG_B ((1<<SIZE_B)-1) 86#define MAXARG_B ((1<<SIZE_B)-1)
@@ -111,6 +121,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
111#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) 121#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
112 122
113#define GETARG_k(i) (cast(int, ((i) & (1 << POS_k)))) 123#define GETARG_k(i) (cast(int, ((i) & (1 << POS_k))))
124#define SETARG_k(i,v) setarg(i, v, POS_k, 1)
114 125
115#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx)) 126#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx))
116#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx) 127#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx)
@@ -122,12 +133,17 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
122 check_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - MAXARG_sBx) 133 check_exp(checkopm(i, iAsBx), getarg(i, POS_Bx, SIZE_Bx) - MAXARG_sBx)
123#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) 134#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
124 135
136#define GETARG_sJ(i) \
137 check_exp(checkopm(i, isJ), getarg(i, POS_sJ, SIZE_sJ) - MAXARG_sJ)
138#define SETARG_sJ(i,j) \
139 setarg(i, cast(unsigned int, (j)+MAXARG_sJ), POS_sJ, SIZE_sJ)
140
125 141
126#define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \ 142#define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \
127 | (cast(Instruction, a)<<POS_A) \ 143 | (cast(Instruction, a)<<POS_A) \
128 | (cast(Instruction, b)<<POS_B) \ 144 | (cast(Instruction, b)<<POS_B) \
129 | (cast(Instruction, c)<<POS_C)) \ 145 | (cast(Instruction, c)<<POS_C) \
130 | (cast(Instruction, k)<<POS_k) 146 | (cast(Instruction, k)<<POS_k))
131 147
132#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \ 148#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \
133 | (cast(Instruction, a)<<POS_A) \ 149 | (cast(Instruction, a)<<POS_A) \
@@ -136,6 +152,10 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
136#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \ 152#define CREATE_Ax(o,a) ((cast(Instruction, o)<<POS_OP) \
137 | (cast(Instruction, a)<<POS_Ax)) 153 | (cast(Instruction, a)<<POS_Ax))
138 154
155#define CREATE_sJ(o,j,k) ((cast(Instruction, o) << POS_OP) \
156 | (cast(Instruction, j) << POS_sJ) \
157 | (cast(Instruction, k) << POS_k))
158
139 159
140#if !defined(MAXINDEXRK) /* (for debugging only) */ 160#if !defined(MAXINDEXRK) /* (for debugging only) */
141#define MAXINDEXRK MAXARG_B 161#define MAXINDEXRK MAXARG_B
@@ -215,7 +235,7 @@ OP_LEN,/* A B R(A) := length of R(B) */
215OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */ 235OP_CONCAT,/* A B C R(A) := R(B).. ... ..R(C) */
216 236
217OP_CLOSE,/* A close all upvalues >= R(A) */ 237OP_CLOSE,/* A close all upvalues >= R(A) */
218OP_JMP,/* sBx pc+=sBx */ 238OP_JMP,/* k sJ pc += sJ (k is used in code generation) */
219OP_EQ,/* A B C if ((R(B) == R(C)) ~= A) then pc++ */ 239OP_EQ,/* A B C if ((R(B) == R(C)) ~= A) then pc++ */
220OP_LT,/* A B C if ((R(B) < R(C)) ~= A) then pc++ */ 240OP_LT,/* A B C if ((R(B) < R(C)) ~= A) then pc++ */
221OP_LE,/* A B C if ((R(B) <= R(C)) ~= A) then pc++ */ 241OP_LE,/* A B C if ((R(B) <= R(C)) ~= A) then pc++ */