diff options
Diffstat (limited to 'lopcodes.h')
-rw-r--r-- | lopcodes.h | 60 |
1 files changed, 36 insertions, 24 deletions
@@ -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 */ | |||
115 | SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */ | 121 | SETLIST,/* A B v_b-v_0 t t t[i+a*FPF]=v_i */ |
116 | SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */ | 122 | SETMAP,/* U v_u k_u - v_0 k_0 t t t[k_i]=v_i */ |
117 | 123 | ||
118 | NEQOP,/* - y x (x~=y)? 1 : nil */ | ||
119 | EQOP,/* - y x (x==y)? 1 : nil */ | ||
120 | LTOP,/* - y x (x<y)? 1 : nil */ | ||
121 | LEOP,/* - y x (x<y)? 1 : nil */ | ||
122 | GTOP,/* - y x (x>y)? 1 : nil */ | ||
123 | GEOP,/* - y x (x>=y)? 1 : nil */ | ||
124 | |||
125 | ADDOP,/* - y x x+y */ | 124 | ADDOP,/* - y x x+y */ |
126 | ADDI,/* S x x+s */ | 125 | ADDI,/* S x x+s */ |
127 | SUBOP,/* - y x x-y */ | 126 | SUBOP,/* - y x x-y */ |
@@ -132,19 +131,32 @@ CONCOP,/* U v_u-v_1 v1..-..v_u */ | |||
132 | MINUSOP,/* - x -x */ | 131 | MINUSOP,/* - x -x */ |
133 | NOTOP,/* - x (x==nil)? 1 : nil */ | 132 | NOTOP,/* - x (x==nil)? 1 : nil */ |
134 | 133 | ||
134 | IFNEQJMP,/* J y x - (x~=y)? PC+=s */ | ||
135 | IFEQJMP,/* J y x - (x==y)? PC+=s */ | ||
136 | IFLTJMP,/* J y x - (x<y)? PC+=s */ | ||
137 | IFLEJMP,/* J y x - (x<y)? PC+=s */ | ||
138 | IFGTJMP,/* J y x - (x>y)? PC+=s */ | ||
139 | IFGEJMP,/* J y x - (x>=y)? PC+=s */ | ||
140 | |||
141 | IFTJMP,/* J x - (x!=nil)? PC+=s */ | ||
142 | IFFJMP,/* J x - (x==nil)? PC+=s */ | ||
135 | ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */ | 143 | ONTJMP,/* J x (x!=nil)? x : - (x!=nil)? PC+=s */ |
136 | ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */ | 144 | ONFJMP,/* J x (x==nil)? x : - (x==nil)? PC+=s */ |
137 | JMP,/* J - - PC+=s */ | 145 | JMP,/* J - - PC+=s */ |
138 | IFTJMP,/* J x - (x!=nil)? PC+=s */ | ||
139 | IFFJMP,/* J x - (x==nil)? PC+=s */ | ||
140 | 146 | ||
141 | CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_b-v_1) */ | 147 | PUSHNILJMP,/* - - nil PC++; */ |
148 | |||
149 | CLOSURE,/* A B v_b-v_1 closure(CNST[a], v_1-v_b) */ | ||
142 | 150 | ||
143 | SETLINE/* U - - LINE=u */ | 151 | SETLINE/* 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 | ||