aboutsummaryrefslogtreecommitdiff
path: root/lopcodes.h
diff options
context:
space:
mode:
Diffstat (limited to 'lopcodes.h')
-rw-r--r--lopcodes.h77
1 files changed, 44 insertions, 33 deletions
diff --git a/lopcodes.h b/lopcodes.h
index 71a712f2..e93f8c35 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lopcodes.h,v 1.52 2000/03/24 19:49:23 roberto Exp roberto $ 2** $Id: lopcodes.h,v 1.53 2000/03/27 14:31:12 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*/
@@ -13,26 +13,30 @@
13/*=========================================================================== 13/*===========================================================================
14 We assume that instructions are unsigned numbers. 14 We assume that instructions are unsigned numbers.
15 All instructions have an opcode in the first 6 bits. Moreover, 15 All instructions have an opcode in the first 6 bits. Moreover,
16 an instruction can have 0, 1, or 2 arguments. There are 4 types of 16 an instruction can have 0, 1, or 2 arguments. Instructions can
17 Instructions: 17 have the following types:
18 type 0: no arguments 18 type 0: no arguments
19 type 1: 1 unsigned argument in the higher bits (called `U') 19 type 1: 1 unsigned argument in the higher bits (called `U')
20 type 2: 1 signed argument in the higher bits (`S') 20 type 2: 1 signed argument in the higher bits (`S')
21 type 3: 1st unsigned argument in the higher bits (`A') 21 type 3: 1st unsigned argument in the higher bits (`A')
22 2nd unsigned argument in the middle bits (`B') 22 2nd unsigned argument in the middle bits (`B')
23 23
24 The signed argument is represented in excess 2^K; that is, the number 24 A signed argument is represented in excess K; that is, the number
25 value is the usigned value minus 2^K. 25 value is the unsigned value minus K. K is exactly the maximum value
26 for that argument (so that -max is represented by 0, and +max is
27 represented by 2*max), which is half the maximum for the corresponding
28 unsigned argument.
26 29
27 The size of each argument is defined in `llimits.h'. The usual is an 30 The size of each argument is defined in `llimits.h'. The usual is an
28 instruction with 32 bits, U and S arguments with 26 bits (32-6), B 31 instruction with 32 bits, U arguments with 26 bits (32-6), B arguments
29 argument with 9 bits, and A argument with 17 bits (32-6-9). For small 32 with 9 bits, and A arguments with 17 bits (32-6-9). For small
30 instalations, the instruction size can be 16, so U and S have 10 bits, 33 instalations, the instruction size can be 16, so U has 10 bits,
31 and A and B have 5 bits each. 34 and A and B have 5 bits each.
32===========================================================================*/ 35===========================================================================*/
33 36
34 37
35#define EXCESS_S (1<<(SIZE_S-1)) /* == 2^K */ 38
39#define MAXARG_sA (MAXARG_A>>1) /* max value for a signed A */
36 40
37 41
38/* creates a mask with `n' 1 bits at position `p' */ 42/* creates a mask with `n' 1 bits at position `p' */
@@ -45,27 +49,33 @@
45** the following macros help to manipulate instructions 49** the following macros help to manipulate instructions
46*/ 50*/
47 51
52#define CREATE_0(o) ((Instruction)(o))
48#define GET_OPCODE(i) ((OpCode)((i)&MASK1(SIZE_OP,0))) 53#define GET_OPCODE(i) ((OpCode)((i)&MASK1(SIZE_OP,0)))
49#define GETARG_U(i) ((int)((i)>>POS_U))
50#define GETARG_S(i) ((int)((i)>>POS_S)-EXCESS_S)
51#define GETARG_A(i) ((int)((i)>>POS_A))
52#define GETARG_B(i) ((int)(((i)>>POS_B) & MASK1(SIZE_B,0)))
53
54#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o))) 54#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o)))
55
56#define CREATE_U(o,u) ((Instruction)(o) | (Instruction)(u)<<POS_U)
57#define GETARG_U(i) ((int)((i)>>POS_U))
55#define SETARG_U(i,u) ((i) = (((i)&MASK0(SIZE_U,POS_U)) | \ 58#define SETARG_U(i,u) ((i) = (((i)&MASK0(SIZE_U,POS_U)) | \
56 ((Instruction)(u)<<POS_U))) 59 ((Instruction)(u)<<POS_U)))
57#define SETARG_S(i,s) ((i) = (((i)&MASK0(SIZE_S,POS_S)) | \ 60
58 ((Instruction)((s)+EXCESS_S)<<POS_S))) 61#define CREATE_S(o,s) CREATE_U((o),(s)+MAXARG_S)
62#define GETARG_S(i) (GETARG_U(i)-MAXARG_S)
63#define SETARG_S(i,s) SETARG_U((i),(s)+MAXARG_S)
64
65
66#define CREATE_AB(o,a,b) ((Instruction)(o) | ((Instruction)(a)<<POS_A) \
67 | ((Instruction)(b)<<POS_B))
68#define GETARG_A(i) ((int)((i)>>POS_A))
59#define SETARG_A(i,a) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \ 69#define SETARG_A(i,a) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
60 ((Instruction)(a)<<POS_A))) 70 ((Instruction)(a)<<POS_A)))
71#define GETARG_B(i) ((int)(((i)>>POS_B) & MASK1(SIZE_B,0)))
61#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \ 72#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
62 ((Instruction)(b)<<POS_B))) 73 ((Instruction)(b)<<POS_B)))
63 74
64#define CREATE_0(o) ((Instruction)(o)) 75
65#define CREATE_U(o,u) ((Instruction)(o) | (Instruction)(u)<<POS_U) 76#define CREATE_sAB(o,a,b) (CREATE_AB((o),(a)+MAXARG_sA,(b)))
66#define CREATE_S(o,s) ((Instruction)(o) | ((Instruction)(s)+EXCESS_S)<<POS_S) 77#define GETARG_sA(i) (GETARG_A(i)-MAXARG_sA)
67#define CREATE_AB(o,a,b) ((Instruction)(o) | ((Instruction)(a)<<POS_A) \ 78
68 | ((Instruction)(b)<<POS_B))
69 79
70 80
71/* 81/*
@@ -112,6 +122,7 @@ OP_SETTABLE,/* U v a_u-a_1 i t a_u-a_1 i t t[i]=v */
112OP_SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */ 122OP_SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */
113OP_SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */ 123OP_SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */
114 124
125OP_INCLOCAL,/* sA B - - LOC[B]+=sA */
115OP_ADD,/* - y x x+y */ 126OP_ADD,/* - y x x+y */
116OP_ADDI,/* S x x+s */ 127OP_ADDI,/* S x x+s */
117OP_SUB,/* - y x x-y */ 128OP_SUB,/* - y x x-y */
@@ -122,17 +133,17 @@ OP_CONC,/* U v_u-v_1 v1..-..v_u */
122OP_MINUS,/* - x -x */ 133OP_MINUS,/* - x -x */
123OP_NOT,/* - x (x==nil)? 1 : nil */ 134OP_NOT,/* - x (x==nil)? 1 : nil */
124 135
125OP_IFNEQJMP,/* J y x - (x~=y)? PC+=s */ 136OP_JMPNEQ,/* J y x - (x~=y)? PC+=s */
126OP_IFEQJMP,/* J y x - (x==y)? PC+=s */ 137OP_JMPEQ,/* J y x - (x==y)? PC+=s */
127OP_IFLTJMP,/* J y x - (x<y)? PC+=s */ 138OP_JMPLT,/* J y x - (x<y)? PC+=s */
128OP_IFLEJMP,/* J y x - (x<y)? PC+=s */ 139OP_JMPLE,/* J y x - (x<y)? PC+=s */
129OP_IFGTJMP,/* J y x - (x>y)? PC+=s */ 140OP_JMPGT,/* J y x - (x>y)? PC+=s */
130OP_IFGEJMP,/* J y x - (x>=y)? PC+=s */ 141OP_JMPGE,/* J y x - (x>=y)? PC+=s */
131 142
132OP_IFTJMP,/* J x - (x!=nil)? PC+=s */ 143OP_JMPT,/* J x - (x!=nil)? PC+=s */
133OP_IFFJMP,/* J x - (x==nil)? PC+=s */ 144OP_JMPF,/* J x - (x==nil)? PC+=s */
134OP_ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */ 145OP_JMPONT,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */
135OP_ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */ 146OP_JMPONF,/* J x (x==nil)? x : - (x==nil)? PC+=s */
136OP_JMP,/* J - - PC+=s */ 147OP_JMP,/* J - - PC+=s */
137 148
138OP_PUSHNILJMP,/* - - nil PC++; */ 149OP_PUSHNILJMP,/* - - nil PC++; */
@@ -145,7 +156,7 @@ OP_SETLINE/* U - - LINE=u */
145 156
146 157
147 158
148#define ISJUMP(o) (OP_IFNEQJMP <= (o) && (o) <= OP_JMP) 159#define ISJUMP(o) (OP_JMPNEQ <= (o) && (o) <= OP_JMP)
149 160
150 161
151#endif 162#endif