1 #ifndef IVL_codes_H
2 #define IVL_codes_H
3 /*
4  * Copyright (c) 2001-2020 Stephen Williams (steve@icarus.com)
5  *
6  *    This source code is free software; you can redistribute it
7  *    and/or modify it in source code form under the terms of the GNU
8  *    General Public License as published by the Free Software
9  *    Foundation; either version 2 of the License, or (at your option)
10  *    any later version.
11  *
12  *    This program is distributed in the hope that it will be useful,
13  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *    GNU General Public License for more details.
16  *
17  *    You should have received a copy of the GNU General Public License
18  *    along with this program; if not, write to the Free Software
19  *    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 # include  "config.h"
23 # include  "vvp_net.h"
24 # include  "array.h"
25 # include  "vthread.h"
26 
27 typedef bool (*vvp_code_fun)(vthread_t thr, vvp_code_t code);
28 
29 /*
30  * These functions are implementations of executable op-codes. The
31  * implementation lives in the vthread.cc file so that they have
32  * access to the thread context.
33  */
34 extern bool of_ABS_WR(vthread_t thr, vvp_code_t code);
35 extern bool of_ADD(vthread_t thr, vvp_code_t code);
36 extern bool of_ADD_WR(vthread_t thr, vvp_code_t code);
37 extern bool of_ADDI(vthread_t thr, vvp_code_t code);
38 extern bool of_ALLOC(vthread_t thr, vvp_code_t code);
39 extern bool of_AND(vthread_t thr, vvp_code_t code);
40 extern bool of_ANDR(vthread_t thr, vvp_code_t code);
41 extern bool of_ASSIGN_AR(vthread_t thr, vvp_code_t code);
42 extern bool of_ASSIGN_ARD(vthread_t thr, vvp_code_t code);
43 extern bool of_ASSIGN_ARE(vthread_t thr, vvp_code_t code);
44 extern bool of_ASSIGN_D(vthread_t thr, vvp_code_t code);
45 extern bool of_ASSIGN_MV(vthread_t thr, vvp_code_t code);
46 extern bool of_ASSIGN_VEC4(vthread_t thr, vvp_code_t code);
47 extern bool of_ASSIGN_VEC4D(vthread_t thr, vvp_code_t code);
48 extern bool of_ASSIGN_VEC4E(vthread_t thr, vvp_code_t code);
49 extern bool of_ASSIGN_VEC4_A_D(vthread_t thr, vvp_code_t code);
50 extern bool of_ASSIGN_VEC4_A_E(vthread_t thr, vvp_code_t code);
51 extern bool of_ASSIGN_VEC4_OFF_D(vthread_t thr, vvp_code_t code);
52 extern bool of_ASSIGN_VEC4_OFF_E(vthread_t thr, vvp_code_t code);
53 extern bool of_ASSIGN_WR(vthread_t thr, vvp_code_t code);
54 extern bool of_ASSIGN_WRD(vthread_t thr, vvp_code_t code);
55 extern bool of_ASSIGN_WRE(vthread_t thr, vvp_code_t code);
56 extern bool of_BLEND(vthread_t thr, vvp_code_t code);
57 extern bool of_BLEND_WR(vthread_t thr, vvp_code_t code);
58 extern bool of_BREAKPOINT(vthread_t thr, vvp_code_t code);
59 extern bool of_CALLF_OBJ(vthread_t thr, vvp_code_t code);
60 extern bool of_CALLF_REAL(vthread_t thr, vvp_code_t code);
61 extern bool of_CALLF_STR(vthread_t thr, vvp_code_t code);
62 extern bool of_CALLF_VEC4(vthread_t thr, vvp_code_t code);
63 extern bool of_CALLF_VOID(vthread_t thr, vvp_code_t code);
64 extern bool of_CASSIGN_LINK(vthread_t thr, vvp_code_t code);
65 extern bool of_CASSIGN_VEC4(vthread_t thr, vvp_code_t code);
66 extern bool of_CASSIGN_VEC4_OFF(vthread_t thr, vvp_code_t code);
67 extern bool of_CASSIGN_WR(vthread_t thr, vvp_code_t code);
68 extern bool of_CAST2(vthread_t thr, vvp_code_t code);
69 extern bool of_CAST_VEC2_DAR(vthread_t thr, vvp_code_t code);
70 extern bool of_CAST_VEC4_DAR(vthread_t thr, vvp_code_t code);
71 extern bool of_CAST_VEC4_STR(vthread_t thr, vvp_code_t code);
72 extern bool of_CMPE(vthread_t thr, vvp_code_t code);
73 extern bool of_CMPIE(vthread_t thr, vvp_code_t code);
74 extern bool of_CMPINE(vthread_t thr, vvp_code_t code);
75 extern bool of_CMPNE(vthread_t thr, vvp_code_t code);
76 extern bool of_CMPS(vthread_t thr, vvp_code_t code);
77 extern bool of_CMPIS(vthread_t thr, vvp_code_t code);
78 extern bool of_CMPSTR(vthread_t thr, vvp_code_t code);
79 extern bool of_CMPU(vthread_t thr, vvp_code_t code);
80 extern bool of_CMPIU(vthread_t thr, vvp_code_t code);
81 extern bool of_CMPWE(vthread_t thr, vvp_code_t code);
82 extern bool of_CMPWNE(vthread_t thr, vvp_code_t code);
83 extern bool of_CMPWR(vthread_t thr, vvp_code_t code);
84 extern bool of_CMPWS(vthread_t thr, vvp_code_t code);
85 extern bool of_CMPWU(vthread_t thr, vvp_code_t code);
86 extern bool of_CMPX(vthread_t thr, vvp_code_t code);
87 extern bool of_CMPZ(vthread_t thr, vvp_code_t code);
88 extern bool of_CONCAT_STR(vthread_t thr, vvp_code_t code);
89 extern bool of_CONCATI_STR(vthread_t thr, vvp_code_t code);
90 extern bool of_CONCAT_VEC4(vthread_t thr, vvp_code_t code);
91 extern bool of_CONCATI_VEC4(vthread_t thr, vvp_code_t code);
92 extern bool of_CVT_RV(vthread_t thr, vvp_code_t code);
93 extern bool of_CVT_RV_S(vthread_t thr, vvp_code_t code);
94 extern bool of_CVT_SR(vthread_t thr, vvp_code_t code);
95 extern bool of_CVT_UR(vthread_t thr, vvp_code_t code);
96 extern bool of_CVT_VR(vthread_t thr, vvp_code_t code);
97 extern bool of_DEASSIGN(vthread_t thr, vvp_code_t code);
98 extern bool of_DEASSIGN_WR(vthread_t thr, vvp_code_t code);
99 extern bool of_DEBUG_THR(vthread_t thr, vvp_code_t code);
100 extern bool of_DELAY(vthread_t thr, vvp_code_t code);
101 extern bool of_DELAYX(vthread_t thr, vvp_code_t code);
102 extern bool of_DELETE_ELEM(vthread_t thr, vvp_code_t code);
103 extern bool of_DELETE_OBJ(vthread_t thr, vvp_code_t code);
104 extern bool of_DELETE_TAIL(vthread_t thr, vvp_code_t code);
105 extern bool of_DISABLE(vthread_t thr, vvp_code_t code);
106 extern bool of_DISABLE_FORK(vthread_t thr, vvp_code_t code);
107 extern bool of_DIV(vthread_t thr, vvp_code_t code);
108 extern bool of_DIV_S(vthread_t thr, vvp_code_t code);
109 extern bool of_DIV_WR(vthread_t thr, vvp_code_t code);
110 extern bool of_DUP_REAL(vthread_t thr, vvp_code_t code);
111 extern bool of_DUP_VEC4(vthread_t thr, vvp_code_t code);
112 extern bool of_END(vthread_t thr, vvp_code_t code);
113 extern bool of_EVENT(vthread_t thr, vvp_code_t code);
114 extern bool of_EVCTL(vthread_t thr, vvp_code_t code);
115 extern bool of_EVCTLC(vthread_t thr, vvp_code_t code);
116 extern bool of_EVCTLI(vthread_t thr, vvp_code_t code);
117 extern bool of_EVCTLS(vthread_t thr, vvp_code_t code);
118 extern bool of_FILE_LINE(vthread_t thr, vvp_code_t code);
119 extern bool of_FLAG_GET_VEC4(vthread_t thr, vvp_code_t code);
120 extern bool of_FLAG_INV(vthread_t thr, vvp_code_t code);
121 extern bool of_FLAG_MOV(vthread_t thr, vvp_code_t code);
122 extern bool of_FLAG_OR(vthread_t thr, vvp_code_t code);
123 extern bool of_FLAG_SET_IMM(vthread_t thr, vvp_code_t code);
124 extern bool of_FLAG_SET_VEC4(vthread_t thr, vvp_code_t code);
125 extern bool of_FORCE_LINK(vthread_t thr, vvp_code_t code);
126 extern bool of_FORCE_VEC4(vthread_t thr, vvp_code_t code);
127 extern bool of_FORCE_VEC4_OFF(vthread_t thr, vvp_code_t code);
128 extern bool of_FORCE_VEC4_OFF_D(vthread_t thr, vvp_code_t code);
129 extern bool of_FORCE_WR(vthread_t thr, vvp_code_t code);
130 extern bool of_FORK(vthread_t thr, vvp_code_t code);
131 extern bool of_FREE(vthread_t thr, vvp_code_t code);
132 extern bool of_INV(vthread_t thr, vvp_code_t code);
133 extern bool of_IX_ADD(vthread_t thr, vvp_code_t code);
134 extern bool of_IX_GETV(vthread_t thr, vvp_code_t code);
135 extern bool of_IX_GETV_S(vthread_t thr, vvp_code_t code);
136 extern bool of_IX_LOAD(vthread_t thr, vvp_code_t code);
137 extern bool of_IX_MOV(vthread_t thr, vvp_code_t code);
138 extern bool of_IX_MUL(vthread_t thr, vvp_code_t code);
139 extern bool of_IX_SUB(vthread_t thr, vvp_code_t code);
140 extern bool of_IX_VEC4(vthread_t thr, vvp_code_t code);
141 extern bool of_IX_VEC4_S(vthread_t thr, vvp_code_t code);
142 extern bool of_JMP(vthread_t thr, vvp_code_t code);
143 extern bool of_JMP0(vthread_t thr, vvp_code_t code);
144 extern bool of_JMP0XZ(vthread_t thr, vvp_code_t code);
145 extern bool of_JMP1(vthread_t thr, vvp_code_t code);
146 extern bool of_JMP1XZ(vthread_t thr, vvp_code_t code);
147 extern bool of_JOIN(vthread_t thr, vvp_code_t code);
148 extern bool of_JOIN_DETACH(vthread_t thr, vvp_code_t code);
149 extern bool of_LOAD_AR(vthread_t thr, vvp_code_t code);
150 extern bool of_LOAD_REAL(vthread_t thr, vvp_code_t code);
151 extern bool of_LOAD_DAR_R(vthread_t thr, vvp_code_t code);
152 extern bool of_LOAD_DAR_STR(vthread_t thr, vvp_code_t code);
153 extern bool of_LOAD_DAR_VEC4(vthread_t thr, vvp_code_t code);
154 extern bool of_LOAD_OBJ(vthread_t thr, vvp_code_t code);
155 extern bool of_LOAD_OBJA(vthread_t thr, vvp_code_t code);
156 extern bool of_LOAD_STR(vthread_t thr, vvp_code_t code);
157 extern bool of_LOAD_STRA(vthread_t thr, vvp_code_t code);
158 extern bool of_LOAD_VEC4(vthread_t thr, vvp_code_t code);
159 extern bool of_LOAD_VEC4A(vthread_t thr, vvp_code_t code);
160 extern bool of_MAX_WR(vthread_t thr, vvp_code_t code);
161 extern bool of_MIN_WR(vthread_t thr, vvp_code_t code);
162 extern bool of_MOD(vthread_t thr, vvp_code_t code);
163 extern bool of_MOD_S(vthread_t thr, vvp_code_t code);
164 extern bool of_MOD_WR(vthread_t thr, vvp_code_t code);
165 extern bool of_MOV_WU(vthread_t thr, vvp_code_t code);
166 extern bool of_MUL(vthread_t thr, vvp_code_t code);
167 extern bool of_MULI(vthread_t thr, vvp_code_t code);
168 extern bool of_MUL_WR(vthread_t thr, vvp_code_t code);
169 extern bool of_NAND(vthread_t thr, vvp_code_t code);
170 extern bool of_NANDR(vthread_t thr, vvp_code_t code);
171 extern bool of_NEW_COBJ(vthread_t thr, vvp_code_t code);
172 extern bool of_NEW_DARRAY(vthread_t thr, vvp_code_t code);
173 extern bool of_NOOP(vthread_t thr, vvp_code_t code);
174 extern bool of_NOR(vthread_t thr, vvp_code_t code);
175 extern bool of_NORR(vthread_t thr, vvp_code_t code);
176 extern bool of_NULL(vthread_t thr, vvp_code_t code);
177 extern bool of_OR(vthread_t thr, vvp_code_t code);
178 extern bool of_ORR(vthread_t thr, vvp_code_t code);
179 extern bool of_PAD_S(vthread_t thr, vvp_code_t code);
180 extern bool of_PAD_U(vthread_t thr, vvp_code_t code);
181 extern bool of_PART_S(vthread_t thr, vvp_code_t code);
182 extern bool of_PART_U(vthread_t thr, vvp_code_t code);
183 extern bool of_PARTI_S(vthread_t thr, vvp_code_t code);
184 extern bool of_PARTI_U(vthread_t thr, vvp_code_t code);
185 extern bool of_POP_OBJ(vthread_t thr, vvp_code_t code);
186 extern bool of_POP_REAL(vthread_t thr, vvp_code_t code);
187 extern bool of_POP_STR(vthread_t thr, vvp_code_t code);
188 extern bool of_POP_VEC4(vthread_t thr, vvp_code_t code);
189 extern bool of_POW(vthread_t thr, vvp_code_t code);
190 extern bool of_POW_S(vthread_t thr, vvp_code_t code);
191 extern bool of_POW_WR(vthread_t thr, vvp_code_t code);
192 extern bool of_QINSERT_REAL(vthread_t thr, vvp_code_t code);
193 extern bool of_QINSERT_STR(vthread_t thr, vvp_code_t code);
194 extern bool of_QINSERT_V(vthread_t thr, vvp_code_t code);
195 extern bool of_QPOP_B_REAL(vthread_t thr, vvp_code_t code);
196 extern bool of_QPOP_B_STR(vthread_t thr, vvp_code_t code);
197 extern bool of_QPOP_B_V(vthread_t thr, vvp_code_t code);
198 extern bool of_QPOP_F_REAL(vthread_t thr, vvp_code_t code);
199 extern bool of_QPOP_F_STR(vthread_t thr, vvp_code_t code);
200 extern bool of_QPOP_F_V(vthread_t thr, vvp_code_t code);
201 extern bool of_PROP_OBJ(vthread_t thr, vvp_code_t code);
202 extern bool of_PROP_R(vthread_t thr, vvp_code_t code);
203 extern bool of_PROP_STR(vthread_t thr, vvp_code_t code);
204 extern bool of_PROP_V(vthread_t thr, vvp_code_t code);
205 extern bool of_PUSHI_STR(vthread_t thr, vvp_code_t code);
206 extern bool of_PUSHI_REAL(vthread_t thr, vvp_code_t code);
207 extern bool of_PUSHI_VEC4(vthread_t thr, vvp_code_t code);
208 extern bool of_PUSHV_STR(vthread_t thr, vvp_code_t code);
209 extern bool of_PUTC_STR_VEC4(vthread_t thr, vvp_code_t code);
210 extern bool of_RELEASE_NET(vthread_t thr, vvp_code_t code);
211 extern bool of_RELEASE_REG(vthread_t thr, vvp_code_t code);
212 extern bool of_RELEASE_WR(vthread_t thr, vvp_code_t code);
213 extern bool of_REPLICATE(vthread_t thr, vvp_code_t code);
214 extern bool of_RET_REAL(vthread_t thr, vvp_code_t code);
215 extern bool of_RET_STR(vthread_t thr, vvp_code_t code);
216 extern bool of_RET_VEC4(vthread_t thr, vvp_code_t code);
217 extern bool of_RETLOAD_REAL(vthread_t thr, vvp_code_t code);
218 extern bool of_RETLOAD_STR(vthread_t thr, vvp_code_t code);
219 extern bool of_RETLOAD_VEC4(vthread_t thr, vvp_code_t code);
220 extern bool of_SCOPY(vthread_t thr, vvp_code_t code);
221 extern bool of_SET_DAR_OBJ_REAL(vthread_t thr, vvp_code_t code);
222 extern bool of_SET_DAR_OBJ_STR(vthread_t thr, vvp_code_t code);
223 extern bool of_SET_DAR_OBJ_VEC4(vthread_t thr, vvp_code_t code);
224 extern bool of_SET_X0_X(vthread_t thr, vvp_code_t code);
225 extern bool of_SHIFTL(vthread_t thr, vvp_code_t code);
226 extern bool of_SHIFTR(vthread_t thr, vvp_code_t code);
227 extern bool of_SHIFTR_S(vthread_t thr, vvp_code_t code);
228 extern bool of_SPLIT_VEC4(vthread_t thr, vvp_code_t code);
229 extern bool of_STORE_DAR_R(vthread_t thr, vvp_code_t code);
230 extern bool of_STORE_DAR_STR(vthread_t thr, vvp_code_t code);
231 extern bool of_STORE_DAR_VEC4(vthread_t thr, vvp_code_t code);
232 extern bool of_STORE_OBJ(vthread_t thr, vvp_code_t code);
233 extern bool of_STORE_OBJA(vthread_t thr, vvp_code_t code);
234 extern bool of_STORE_PROP_OBJ(vthread_t thr, vvp_code_t code);
235 extern bool of_STORE_PROP_R(vthread_t thr, vvp_code_t code);
236 extern bool of_STORE_PROP_STR(vthread_t thr, vvp_code_t code);
237 extern bool of_STORE_PROP_V(vthread_t thr, vvp_code_t code);
238 extern bool of_STORE_QB_R(vthread_t thr, vvp_code_t code);
239 extern bool of_STORE_QB_STR(vthread_t thr, vvp_code_t code);
240 extern bool of_STORE_QB_V(vthread_t thr, vvp_code_t code);
241 extern bool of_STORE_QDAR_R(vthread_t thr, vvp_code_t code);
242 extern bool of_STORE_QDAR_STR(vthread_t thr, vvp_code_t code);
243 extern bool of_STORE_QDAR_V(vthread_t thr, vvp_code_t code);
244 extern bool of_STORE_QF_R(vthread_t thr, vvp_code_t code);
245 extern bool of_STORE_QF_STR(vthread_t thr, vvp_code_t code);
246 extern bool of_STORE_QF_V(vthread_t thr, vvp_code_t code);
247 extern bool of_STORE_QOBJ_R(vthread_t thr, vvp_code_t code);
248 extern bool of_STORE_QOBJ_STR(vthread_t thr, vvp_code_t code);
249 extern bool of_STORE_QOBJ_V(vthread_t thr, vvp_code_t code);
250 extern bool of_STORE_REAL(vthread_t thr, vvp_code_t code);
251 extern bool of_STORE_REALA(vthread_t thr, vvp_code_t code);
252 extern bool of_STORE_STR(vthread_t thr, vvp_code_t code);
253 extern bool of_STORE_STRA(vthread_t thr, vvp_code_t code);
254 extern bool of_STORE_VEC4(vthread_t thr, vvp_code_t code);
255 extern bool of_STORE_VEC4A(vthread_t thr, vvp_code_t code);
256 extern bool of_SUB(vthread_t thr, vvp_code_t code);
257 extern bool of_SUBI(vthread_t thr, vvp_code_t code);
258 extern bool of_SUB_WR(vthread_t thr, vvp_code_t code);
259 extern bool of_SUBSTR(vthread_t thr, vvp_code_t code);
260 extern bool of_SUBSTR_VEC4(vthread_t thr, vvp_code_t code);
261 extern bool of_TEST_NUL(vthread_t thr, vvp_code_t code);
262 extern bool of_TEST_NUL_A(vthread_t thr, vvp_code_t code);
263 extern bool of_TEST_NUL_OBJ(vthread_t thr, vvp_code_t code);
264 extern bool of_TEST_NUL_PROP(vthread_t thr, vvp_code_t code);
265 extern bool of_VPI_CALL(vthread_t thr, vvp_code_t code);
266 extern bool of_WAIT(vthread_t thr, vvp_code_t code);
267 extern bool of_WAIT_FORK(vthread_t thr, vvp_code_t code);
268 extern bool of_XNOR(vthread_t thr, vvp_code_t code);
269 extern bool of_XNORR(vthread_t thr, vvp_code_t code);
270 extern bool of_XOR(vthread_t thr, vvp_code_t code);
271 extern bool of_XORR(vthread_t thr, vvp_code_t code);
272 
273 extern bool of_ZOMBIE(vthread_t thr, vvp_code_t code);
274 
275 extern bool of_EXEC_UFUNC_REAL(vthread_t thr, vvp_code_t code);
276 extern bool of_EXEC_UFUNC_VEC4(vthread_t thr, vvp_code_t code);
277 extern bool of_REAP_UFUNC(vthread_t thr, vvp_code_t code);
278 
279 extern bool of_CHUNK_LINK(vthread_t thr, vvp_code_t code);
280 
281 /*
282  * This is the format of a machine code instruction.
283  */
284 struct vvp_code_s {
285       vvp_code_fun opcode;
286 
287       union {
288 	    unsigned long number;
289 	    vvp_net_t    *net;
290 	    vvp_code_t   cptr;
291 	    vvp_array_t array;
292 	    class __vpiHandle*handle;
293 	    __vpiScope*scope;
294 	    const char*text;
295       };
296 
297       union {
298 	    uint32_t    bit_idx[2];
299 	    vvp_net_t   *net2;
300 	    vvp_code_t   cptr2;
301 	    class ufunc_core*ufunc_core_ptr;
302       };
303 };
304 
305 /*
306  * This function clears the code space, ready for initialization. This
307  * needs to be done exactly once before any instructions are created.
308  */
309 extern void codespace_init(void);
310 
311 
312 /*
313  * This function returns a pointer to the next free instruction in the
314  * code address space. The codespace_next returns a pointer to the
315  * next opcode that will be allocated. This is used by label
316  * statements to get the address that will be attached to a label in
317  * the code.
318  */
319 extern vvp_code_t codespace_allocate(void);
320 extern vvp_code_t codespace_next(void);
321 extern vvp_code_t codespace_null(void);
322 
323 #endif /* IVL_codes_H */
324