aboutsummaryrefslogtreecommitdiff
path: root/lopcodes.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-10-04 18:56:32 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2017-10-04 18:56:32 -0300
commita1ef58b3a5986293ed0b7acef50073d94c7f932f (patch)
treea2bb5ad195001c03caeec9b536a1f8d97acba693 /lopcodes.h
parent283e7455ffe32235eaf790ebd3c40c7970b7a833 (diff)
downloadlua-a1ef58b3a5986293ed0b7acef50073d94c7f932f.tar.gz
lua-a1ef58b3a5986293ed0b7acef50073d94c7f932f.tar.bz2
lua-a1ef58b3a5986293ed0b7acef50073d94c7f932f.zip
eplicit 1-bit opcode operand 'k'
Diffstat (limited to 'lopcodes.h')
-rw-r--r--lopcodes.h71
1 files changed, 29 insertions, 42 deletions
diff --git a/lopcodes.h b/lopcodes.h
index 39f36aa7..de0c5cc1 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.164 2017/10/02 22:51:32 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.165 2017/10/04 15:49:24 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*/
@@ -17,7 +17,7 @@
17 17
18 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 18 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
19 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 19 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
20iABC | C(9) | | B(8) | | A(8) | | Op(7) | 20iABC |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) |
@@ -34,19 +34,21 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
34/* 34/*
35** size and position of opcode arguments. 35** size and position of opcode arguments.
36*/ 36*/
37#define SIZE_C 9 37#define SIZE_C 8
38#define SIZE_Cx (SIZE_C + 1)
38#define SIZE_B 8 39#define SIZE_B 8
39#define SIZE_Bx (SIZE_C + SIZE_B) 40#define SIZE_Bx (SIZE_Cx + SIZE_B)
40#define SIZE_A 8 41#define SIZE_A 8
41#define SIZE_Ax (SIZE_C + SIZE_B + SIZE_A) 42#define SIZE_Ax (SIZE_Cx + SIZE_B + SIZE_A)
42 43
43#define SIZE_OP 7 44#define SIZE_OP 7
44 45
45#define POS_OP 0 46#define POS_OP 0
46#define POS_A (POS_OP + SIZE_OP) 47#define POS_A (POS_OP + SIZE_OP)
47#define POS_C (POS_A + SIZE_A) 48#define POS_B (POS_A + SIZE_A)
48#define POS_B (POS_C + SIZE_C) 49#define POS_C (POS_B + SIZE_B)
49#define POS_Bx POS_C 50#define POS_k (POS_C + SIZE_C)
51#define POS_Bx POS_B
50#define POS_Ax POS_A 52#define POS_Ax POS_A
51 53
52 54
@@ -70,10 +72,11 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
70#endif 72#endif
71 73
72 74
73#define MAXARG_A ((1<<SIZE_A)-1) 75#define MAXARG_A ((1<<SIZE_A)-1)
74#define MAXARG_B ((1<<SIZE_B)-1) 76#define MAXARG_B ((1<<SIZE_B)-1)
75#define MAXARG_C ((1<<SIZE_C)-1) 77#define MAXARG_C ((1<<SIZE_C)-1)
76#define MAXARG_Cr ((1<<(SIZE_C - 1))-1) 78#define MAXARG_sC (MAXARG_C >> 1)
79#define MAXARG_Cx ((1<<(SIZE_C + 1))-1)
77 80
78 81
79/* creates a mask with 'n' 1 bits at position 'p' */ 82/* creates a mask with 'n' 1 bits at position 'p' */
@@ -104,11 +107,10 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
104#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B) 107#define SETARG_B(i,v) setarg(i, v, POS_B, SIZE_B)
105 108
106#define GETARG_C(i) check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C)) 109#define GETARG_C(i) check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C))
110#define GETARG_sC(i) (GETARG_C(i) - MAXARG_sC)
107#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C) 111#define SETARG_C(i,v) setarg(i, v, POS_C, SIZE_C)
108 112
109#define GETARG_Cr(i) \ 113#define GETARG_k(i) (cast(int, ((i) & (1 << POS_k))))
110 check_exp(checkopm(i, iABC), getarg(i, POS_C, SIZE_C - 1))
111#define GETARG_Ck(i) getarg(i, (POS_C + SIZE_C - 1), 1)
112 114
113#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx)) 115#define GETARG_Bx(i) check_exp(checkopm(i, iABx), getarg(i, POS_Bx, SIZE_Bx))
114#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx) 116#define SETARG_Bx(i,v) setarg(i, v, POS_Bx, SIZE_Bx)
@@ -121,10 +123,11 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
121#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx)) 123#define SETARG_sBx(i,b) SETARG_Bx((i),cast(unsigned int, (b)+MAXARG_sBx))
122 124
123 125
124#define CREATE_ABC(o,a,b,c) ((cast(Instruction, o)<<POS_OP) \ 126#define CREATE_ABCk(o,a,b,c,k) ((cast(Instruction, o)<<POS_OP) \
125 | (cast(Instruction, a)<<POS_A) \ 127 | (cast(Instruction, a)<<POS_A) \
126 | (cast(Instruction, b)<<POS_B) \ 128 | (cast(Instruction, b)<<POS_B) \
127 | (cast(Instruction, c)<<POS_C)) 129 | (cast(Instruction, c)<<POS_C)) \
130 | (cast(Instruction, k)<<POS_k)
128 131
129#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \ 132#define CREATE_ABx(o,a,bc) ((cast(Instruction, o)<<POS_OP) \
130 | (cast(Instruction, a)<<POS_A) \ 133 | (cast(Instruction, a)<<POS_A) \
@@ -134,26 +137,10 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
134 | (cast(Instruction, a)<<POS_Ax)) 137 | (cast(Instruction, a)<<POS_Ax))
135 138
136 139
137/*
138** Macros to operate RK indices
139*/
140
141/* this bit 1 means constant (0 means register) */
142#define BITRK (1 << (SIZE_C - 1))
143
144/* test whether value is a constant */
145#define ISK(x) ((x) & BITRK)
146
147/* gets the index of the constant */
148#define INDEXK(r) ((int)(r) & ~BITRK)
149
150#if !defined(MAXINDEXRK) /* (for debugging only) */ 140#if !defined(MAXINDEXRK) /* (for debugging only) */
151#define MAXINDEXRK (BITRK - 1) 141#define MAXINDEXRK MAXARG_B
152#endif 142#endif
153 143
154/* code a constant index as a RK value */
155#define RKASK(x) ((x) | BITRK)
156
157 144
158/* 145/*
159** invalid register that fits in 8 bits 146** invalid register that fits in 8 bits
@@ -164,7 +151,7 @@ enum OpMode {iABC, iABx, iAsBx, iAx}; /* basic instruction format */
164/* 151/*
165** R(x) - register 152** R(x) - register
166** K(x) - constant (in constant table) 153** K(x) - constant (in constant table)
167** RK(x) == if ISK(x) then K(INDEXK(x)) else R(x) 154** RK(x) == if k(i) then K(x) else R(x)
168*/ 155*/
169 156
170 157
@@ -200,13 +187,13 @@ OP_NEWTABLE,/* A B C R(A) := {} (size = B,C) */
200 187
201OP_SELF,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C):string] */ 188OP_SELF,/* A B C R(A+1) := R(B); R(A) := R(B)[RK(C):string] */
202 189
203OP_ADDI,/* A B C R(A) := R(B) + C */ 190OP_ADDI,/* A B sC R(A) := R(B) + C */
204OP_SUBI,/* A B C R(A) := R(B) - C */ 191OP_SUBI,/* A B sC R(A) := R(B) - C */
205OP_MULI,/* A B C R(A) := R(B) * C */ 192OP_MULI,/* A B sC R(A) := R(B) * C */
206OP_MODI,/* A B C R(A) := R(B) % C */ 193OP_MODI,/* A B sC R(A) := R(B) % C */
207OP_POWI,/* A B C R(A) := R(B) ^ C */ 194OP_POWI,/* A B sC R(A) := R(B) ^ C */
208OP_DIVI,/* A B C R(A) := R(B) / C */ 195OP_DIVI,/* A B sC R(A) := R(B) / C */
209OP_IDIVI,/* A B C R(A) := R(B) // C */ 196OP_IDIVI,/* A B sC R(A) := R(B) // C */
210 197
211OP_ADD,/* A B C R(A) := R(B) + R(C) */ 198OP_ADD,/* A B C R(A) := R(B) + R(C) */
212OP_SUB,/* A B C R(A) := R(B) - R(C) */ 199OP_SUB,/* A B C R(A) := R(B) - R(C) */