aboutsummaryrefslogtreecommitdiff
path: root/lopcodes.h
diff options
context:
space:
mode:
Diffstat (limited to 'lopcodes.h')
-rw-r--r--lopcodes.h60
1 files changed, 36 insertions, 24 deletions
diff --git a/lopcodes.h b/lopcodes.h
index 1e3b9ee9..cd19ff3d 100644
--- a/lopcodes.h
+++ b/lopcodes.h
@@ -11,7 +11,7 @@
11 11
12/*=========================================================================== 12/*===========================================================================
13 We assume that instructions are unsigned numbers with 4 bytes. 13 We assume that instructions are unsigned numbers with 4 bytes.
14 All instructions have an opcode in the lower byte. Moreover, 14 All instructions have an opcode in the 8 bits. Moreover,
15 an instruction can have 0, 1, or 2 arguments. There are 4 types of 15 an instruction can have 0, 1, or 2 arguments. There are 4 types of
16 Instructions: 16 Instructions:
17 type 0: no arguments 17 type 0: no arguments
@@ -24,21 +24,23 @@
24 is the usigned value minus 2^23. 24 is the usigned value minus 2^23.
25===========================================================================*/ 25===========================================================================*/
26 26
27#define SIZE_INSTRUCTION 32
28
27#define SIZE_OP 8 29#define SIZE_OP 8
28#define SIZE_U 24 30#define SIZE_U (SIZE_INSTRUCTION-SIZE_OP)
29#define POS_U 8 31#define POS_U SIZE_OP
30#define SIZE_S 24 32#define SIZE_S (SIZE_INSTRUCTION-SIZE_OP)
31#define POS_S 8 33#define POS_S SIZE_OP
32#define SIZE_A 16
33#define POS_A 16
34#define SIZE_B 8 34#define SIZE_B 8
35#define POS_B 8 35#define POS_B SIZE_OP
36#define SIZE_A (SIZE_INSTRUCTION-(SIZE_OP+SIZE_B))
37#define POS_A (SIZE_OP+SIZE_B)
36 38
37#define EXCESS_S (1<<(SIZE_S-1)) /* == 2^23 */ 39#define EXCESS_S (1<<(SIZE_S-1)) /* == 2^23 */
38 40
39 41
40/* creates a mask with `n' 1 bits at position `p' */ 42/* creates a mask with `n' 1 bits at position `p' */
41#define MASK1(n,p) ((~((~0ul)<<n))<<p) 43#define MASK1(n,p) ((~((~(Instruction)0)<<n))<<p)
42 44
43/* creates a mask with `n' 0 bits at position `p' */ 45/* creates a mask with `n' 0 bits at position `p' */
44#define MASK0(n,p) (~MASK1(n,p)) 46#define MASK0(n,p) (~MASK1(n,p))
@@ -58,11 +60,15 @@
58#define GETARG_A(i) ((int)((i)>>POS_A)) 60#define GETARG_A(i) ((int)((i)>>POS_A))
59#define GETARG_B(i) ((int)(((i)>>POS_B) & MASK1(SIZE_B,0))) 61#define GETARG_B(i) ((int)(((i)>>POS_B) & MASK1(SIZE_B,0)))
60 62
61#define SET_OPCODE(i,o) (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o)) 63#define SET_OPCODE(i,o) ((i) = (((i)&MASK0(SIZE_OP,0)) | (Instruction)(o)))
62#define SETARG_U(i,u) (((i)&MASK0(SIZE_U,POS_U)) | ((Instruction)(u)<<POS_U)) 64#define SETARG_U(i,u) ((i) = (((i)&MASK0(SIZE_U,POS_U)) | \
63#define SETARG_S(i,s) (((i)&MASK0(SIZE_S,POS_S)) | ((Instruction)((s)+EXCESS_S)<<POS_S)) 65 ((Instruction)(u)<<POS_U)))
64#define SETARG_A(i,a) (((i)&MASK0(SIZE_A,POS_A)) | ((Instruction)(a)<<POS_A)) 66#define SETARG_S(i,s) ((i) = (((i)&MASK0(SIZE_S,POS_S)) | \
65#define SETARG_B(i,b) (((i)&MASK0(SIZE_B,POS_B)) | ((Instruction)(b)<<POS_B)) 67 ((Instruction)((s)+EXCESS_S)<<POS_S)))
68#define SETARG_A(i,a) ((i) = (((i)&MASK0(SIZE_A,POS_A)) | \
69 ((Instruction)(a)<<POS_A)))
70#define SETARG_B(i,b) ((i) = (((i)&MASK0(SIZE_B,POS_B)) | \
71 ((Instruction)(b)<<POS_B)))
66 72
67#define CREATE_0(o) ((Instruction)(o)) 73#define CREATE_0(o) ((Instruction)(o))
68#define CREATE_U(o,u) ((Instruction)(o) | (Instruction)(u)<<POS_U) 74#define CREATE_U(o,u) ((Instruction)(o) | (Instruction)(u)<<POS_U)
@@ -115,13 +121,6 @@ SETTABLE,/* U v a_u-a_1 i t a_u-a_1 i t t[i]=v */
115SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */ 121SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */
116SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */ 122SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */
117 123
118NEQOP,/* - y x (x~=y)? 1 : nil */
119EQOP,/* - y x (x==y)? 1 : nil */
120LTOP,/* - y x (x<y)? 1 : nil */
121LEOP,/* - y x (x<y)? 1 : nil */
122GTOP,/* - y x (x>y)? 1 : nil */
123GEOP,/* - y x (x>=y)? 1 : nil */
124
125ADDOP,/* - y x x+y */ 124ADDOP,/* - y x x+y */
126ADDI,/* S x x+s */ 125ADDI,/* S x x+s */
127SUBOP,/* - y x x-y */ 126SUBOP,/* - y x x-y */
@@ -132,19 +131,32 @@ CONCOP,/* U v_u-v_1 v1..-..v_u */
132MINUSOP,/* - x -x */ 131MINUSOP,/* - x -x */
133NOTOP,/* - x (x==nil)? 1 : nil */ 132NOTOP,/* - x (x==nil)? 1 : nil */
134 133
134IFNEQJMP,/* J y x - (x~=y)? PC+=s */
135IFEQJMP,/* J y x - (x==y)? PC+=s */
136IFLTJMP,/* J y x - (x<y)? PC+=s */
137IFLEJMP,/* J y x - (x<y)? PC+=s */
138IFGTJMP,/* J y x - (x>y)? PC+=s */
139IFGEJMP,/* J y x - (x>=y)? PC+=s */
140
141IFTJMP,/* J x - (x!=nil)? PC+=s */
142IFFJMP,/* J x - (x==nil)? PC+=s */
135ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */ 143ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */
136ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */ 144ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */
137JMP,/* J - - PC+=s */ 145JMP,/* J - - PC+=s */
138IFTJMP,/* J x - (x!=nil)? PC+=s */
139IFFJMP,/* J x - (x==nil)? PC+=s */
140 146
141CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_b-v_1) */ 147PUSHNILJMP,/* - - nil PC++; */
148
149CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_1-v_b) */
142 150
143SETLINE/* U - - LINE=u */ 151SETLINE/* U - - LINE=u */
144 152
145} OpCode; 153} OpCode;
146 154
147 155
156
157#define ISJUMP(o) (IFNEQJMP <= (o) && (o) <= JMP)
158
159
148#define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */ 160#define RFIELDS_PER_FLUSH 32 /* records (SETMAP) */
149#define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) (<=MAXARG_B) */ 161#define LFIELDS_PER_FLUSH 64 /* FPF - lists (SETLIST) (<=MAXARG_B) */
150 162