Skip to main content

vihaco_cpu/
computation.rs

1// SPDX-FileCopyrightText: 2026 The vihaco Authors
2// SPDX-License-Identifier: MIT
3
4//! Computational and heap operations; operands belong to ProgramImage.
5
6#[vihaco_runtime::dialect]
7pub mod cpu {
8    #[instruction]
9    #[pattern = "'heap_alloc $0"]
10    pub struct HeapAlloc(pub u32);
11
12    #[instruction]
13    #[pattern = "'get_item"]
14    pub struct GetItem;
15
16    #[instruction]
17    #[pattern = "'heap_dealloc"]
18    pub struct HeapDealloc;
19
20    #[instruction]
21    #[pattern = "'heap_reserve"]
22    pub struct HeapReserve;
23
24    #[instruction]
25    #[pattern = "'heap_push"]
26    pub struct HeapPush;
27
28    #[instruction]
29    #[pattern = "'heap_len"]
30    pub struct HeapLen;
31
32    #[instruction]
33    #[pattern = "'add_i32"]
34    pub struct AddI32;
35
36    #[instruction]
37    #[pattern = "'add_f32"]
38    pub struct AddF32;
39
40    #[instruction]
41    #[pattern = "'add_i64"]
42    pub struct AddI64;
43
44    #[instruction]
45    #[pattern = "'add_u32"]
46    pub struct AddU32;
47
48    #[instruction]
49    #[pattern = "'add_u64"]
50    pub struct AddU64;
51
52    #[instruction]
53    #[pattern = "'add_f64"]
54    pub struct AddF64;
55
56    #[instruction]
57    #[pattern = "'sub_i32"]
58    pub struct SubI32;
59
60    #[instruction]
61    #[pattern = "'sub_i64"]
62    pub struct SubI64;
63
64    #[instruction]
65    #[pattern = "'sub_u32"]
66    pub struct SubU32;
67
68    #[instruction]
69    #[pattern = "'sub_u64"]
70    pub struct SubU64;
71
72    #[instruction]
73    #[pattern = "'sub_f32"]
74    pub struct SubF32;
75
76    #[instruction]
77    #[pattern = "'sub_f64"]
78    pub struct SubF64;
79
80    #[instruction]
81    #[pattern = "'mul_i32"]
82    pub struct MulI32;
83
84    #[instruction]
85    #[pattern = "'mul_i64"]
86    pub struct MulI64;
87
88    #[instruction]
89    #[pattern = "'mul_u32"]
90    pub struct MulU32;
91
92    #[instruction]
93    #[pattern = "'mul_u64"]
94    pub struct MulU64;
95
96    #[instruction]
97    #[pattern = "'mul_f32"]
98    pub struct MulF32;
99
100    #[instruction]
101    #[pattern = "'mul_f64"]
102    pub struct MulF64;
103
104    #[instruction]
105    #[pattern = "'div_i32"]
106    pub struct DivI32;
107
108    #[instruction]
109    #[pattern = "'div_i64"]
110    pub struct DivI64;
111
112    #[instruction]
113    #[pattern = "'div_u32"]
114    pub struct DivU32;
115
116    #[instruction]
117    #[pattern = "'div_u64"]
118    pub struct DivU64;
119
120    #[instruction]
121    #[pattern = "'div_f32"]
122    pub struct DivF32;
123
124    #[instruction]
125    #[pattern = "'div_f64"]
126    pub struct DivF64;
127
128    #[instruction]
129    #[pattern = "'rem_i32"]
130    pub struct RemI32;
131
132    #[instruction]
133    #[pattern = "'rem_i64"]
134    pub struct RemI64;
135
136    #[instruction]
137    #[pattern = "'rem_u32"]
138    pub struct RemU32;
139
140    #[instruction]
141    #[pattern = "'rem_u64"]
142    pub struct RemU64;
143
144    #[instruction]
145    #[pattern = "'rem_f32"]
146    pub struct RemF32;
147
148    #[instruction]
149    #[pattern = "'rem_f64"]
150    pub struct RemF64;
151
152    #[instruction]
153    #[pattern = "'neg_i32"]
154    pub struct NegI32;
155
156    #[instruction]
157    #[pattern = "'neg_i64"]
158    pub struct NegI64;
159
160    #[instruction]
161    #[pattern = "'neg_f32"]
162    pub struct NegF32;
163
164    #[instruction]
165    #[pattern = "'neg_f64"]
166    pub struct NegF64;
167
168    #[instruction]
169    #[pattern = "'shl_i32"]
170    pub struct ShlI32;
171
172    #[instruction]
173    #[pattern = "'shl_i64"]
174    pub struct ShlI64;
175
176    #[instruction]
177    #[pattern = "'shl_u32"]
178    pub struct ShlU32;
179
180    #[instruction]
181    #[pattern = "'shl_u64"]
182    pub struct ShlU64;
183
184    #[instruction]
185    #[pattern = "'shr_i32"]
186    pub struct ShrI32;
187
188    #[instruction]
189    #[pattern = "'shr_i64"]
190    pub struct ShrI64;
191
192    #[instruction]
193    #[pattern = "'shr_u32"]
194    pub struct ShrU32;
195
196    #[instruction]
197    #[pattern = "'shr_u64"]
198    pub struct ShrU64;
199
200    #[instruction]
201    #[pattern = "'rol_i32"]
202    pub struct RolI32;
203
204    #[instruction]
205    #[pattern = "'rol_i64"]
206    pub struct RolI64;
207
208    #[instruction]
209    #[pattern = "'rol_u32"]
210    pub struct RolU32;
211
212    #[instruction]
213    #[pattern = "'rol_u64"]
214    pub struct RolU64;
215
216    #[instruction]
217    #[pattern = "'ror_i32"]
218    pub struct RorI32;
219
220    #[instruction]
221    #[pattern = "'ror_i64"]
222    pub struct RorI64;
223
224    #[instruction]
225    #[pattern = "'ror_u32"]
226    pub struct RorU32;
227
228    #[instruction]
229    #[pattern = "'ror_u64"]
230    pub struct RorU64;
231
232    #[instruction]
233    #[pattern = "'bitand_i32"]
234    pub struct BitAndI32;
235
236    #[instruction]
237    #[pattern = "'bitand_i64"]
238    pub struct BitAndI64;
239
240    #[instruction]
241    #[pattern = "'bitand_u32"]
242    pub struct BitAndU32;
243
244    #[instruction]
245    #[pattern = "'bitand_u64"]
246    pub struct BitAndU64;
247
248    #[instruction]
249    #[pattern = "'bitor_i32"]
250    pub struct BitOrI32;
251
252    #[instruction]
253    #[pattern = "'bitor_i64"]
254    pub struct BitOrI64;
255
256    #[instruction]
257    #[pattern = "'bitor_u32"]
258    pub struct BitOrU32;
259
260    #[instruction]
261    #[pattern = "'bitor_u64"]
262    pub struct BitOrU64;
263
264    #[instruction]
265    #[pattern = "'bitxor_i32"]
266    pub struct BitXorI32;
267
268    #[instruction]
269    #[pattern = "'bitxor_i64"]
270    pub struct BitXorI64;
271
272    #[instruction]
273    #[pattern = "'bitxor_u32"]
274    pub struct BitXorU32;
275
276    #[instruction]
277    #[pattern = "'bitxor_u64"]
278    pub struct BitXorU64;
279
280    #[instruction]
281    #[pattern = "'not"]
282    pub struct Not;
283
284    #[instruction]
285    #[pattern = "'and"]
286    pub struct And;
287
288    #[instruction]
289    #[pattern = "'or"]
290    pub struct Or;
291
292    #[instruction]
293    #[pattern = "'xor"]
294    pub struct Xor;
295
296    #[instruction]
297    #[pattern = "'eq_i32"]
298    pub struct EqI32;
299
300    #[instruction]
301    #[pattern = "'eq_i64"]
302    pub struct EqI64;
303
304    #[instruction]
305    #[pattern = "'eq_u32"]
306    pub struct EqU32;
307
308    #[instruction]
309    #[pattern = "'eq_u64"]
310    pub struct EqU64;
311
312    #[instruction]
313    #[pattern = "'eq_f32"]
314    pub struct EqF32;
315
316    #[instruction]
317    #[pattern = "'eq_f64"]
318    pub struct EqF64;
319
320    #[instruction]
321    #[pattern = "'ne_i32"]
322    pub struct NeI32;
323
324    #[instruction]
325    #[pattern = "'ne_i64"]
326    pub struct NeI64;
327
328    #[instruction]
329    #[pattern = "'ne_u32"]
330    pub struct NeU32;
331
332    #[instruction]
333    #[pattern = "'ne_u64"]
334    pub struct NeU64;
335
336    #[instruction]
337    #[pattern = "'ne_f32"]
338    pub struct NeF32;
339
340    #[instruction]
341    #[pattern = "'ne_f64"]
342    pub struct NeF64;
343
344    #[instruction]
345    #[pattern = "'lt_i32"]
346    pub struct LtI32;
347
348    #[instruction]
349    #[pattern = "'lt_i64"]
350    pub struct LtI64;
351
352    #[instruction]
353    #[pattern = "'lt_u32"]
354    pub struct LtU32;
355
356    #[instruction]
357    #[pattern = "'lt_u64"]
358    pub struct LtU64;
359
360    #[instruction]
361    #[pattern = "'lt_f32"]
362    pub struct LtF32;
363
364    #[instruction]
365    #[pattern = "'lt_f64"]
366    pub struct LtF64;
367
368    #[instruction]
369    #[pattern = "'gt_i32"]
370    pub struct GtI32;
371
372    #[instruction]
373    #[pattern = "'gt_i64"]
374    pub struct GtI64;
375
376    #[instruction]
377    #[pattern = "'gt_u32"]
378    pub struct GtU32;
379
380    #[instruction]
381    #[pattern = "'gt_u64"]
382    pub struct GtU64;
383
384    #[instruction]
385    #[pattern = "'gt_f32"]
386    pub struct GtF32;
387
388    #[instruction]
389    #[pattern = "'gt_f64"]
390    pub struct GtF64;
391
392    #[instruction]
393    #[pattern = "'le_i32"]
394    pub struct LeI32;
395
396    #[instruction]
397    #[pattern = "'le_i64"]
398    pub struct LeI64;
399
400    #[instruction]
401    #[pattern = "'le_u32"]
402    pub struct LeU32;
403
404    #[instruction]
405    #[pattern = "'le_u64"]
406    pub struct LeU64;
407
408    #[instruction]
409    #[pattern = "'le_f32"]
410    pub struct LeF32;
411
412    #[instruction]
413    #[pattern = "'le_f64"]
414    pub struct LeF64;
415
416    #[instruction]
417    #[pattern = "'ge_i32"]
418    pub struct GeI32;
419
420    #[instruction]
421    #[pattern = "'ge_i64"]
422    pub struct GeI64;
423
424    #[instruction]
425    #[pattern = "'ge_u32"]
426    pub struct GeU32;
427
428    #[instruction]
429    #[pattern = "'ge_u64"]
430    pub struct GeU64;
431
432    #[instruction]
433    #[pattern = "'ge_f32"]
434    pub struct GeF32;
435
436    #[instruction]
437    #[pattern = "'ge_f64"]
438    pub struct GeF64;
439}