1;; This is a prelude of standard definitions for ISLE, the instruction-selector
2;; DSL, as we use it bound to our interfaces.
3;;
4;; Note that all `extern` functions here are typically defined in the
5;; `isle_prelude_methods` macro defined in `src/isa/isle.rs`
6
7;;;; Primitive and External Types ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
9;; `()`
10(type Unit (primitive Unit))
11(model Unit (type Unit))
12
13(decl pure unit () Unit)
14(extern constructor unit unit)
15
16(model bool (type Bool))
17
18(model u8 (type (bv 8)))
19(model u16 (type (bv 16)))
20(model u32 (type (bv 32)))
21(model u64 (type (bv 64)))
22(model usize (type (bv)))
23
24(model i8 (type (bv 8)))
25(model i16 (type (bv 16)))
26(model i32 (type (bv 32)))
27(model i64 (type (bv 64)))
28
29;; `cranelift-entity`-based identifiers.
30(model Type (type Int))
31(type Type (primitive Type))
32(model Value (type (bv)))
33(type Value (primitive Value))
34(type ValueList (primitive ValueList))
35(type BlockCall (primitive BlockCall))
36(type Inst (primitive Inst))
37
38;; Match the instruction that defines the given value, if any.
39(spec (def_inst arg) (provide (= result arg)))
40(decl def_inst (Inst) Value)
41(extern extractor def_inst def_inst)
42
43;; ISLE representation of `&[Value]`.
44(type ValueSlice (primitive ValueSlice))
45
46;; Extract the type of a `Value`.
47(spec (value_type arg) (provide (= arg (widthof result))))
48(decl value_type (Type) Value)
49(extern extractor infallible value_type value_type)
50
51;; Extractor that matches a `u32` only if non-negative.
52(decl u32_nonnegative (u32) u32)
53(extern extractor u32_nonnegative u32_nonnegative)
54
55;; Extractor that pulls apart an Offset32 into a i32 with the raw
56;; signed-32-bit twos-complement bits.
57(decl offset32 (i32) Offset32)
58(extern extractor infallible offset32 offset32)
59
60;; Pure/fallible constructor that tests if one u32 is less than or
61;; equal to another.
62(spec (u32_lteq a b)
63    (provide (= result ()))
64    (require (<= a b)
65             (= (widthof a) 32)
66             (= (widthof b) 32)))
67(decl pure partial u32_lteq (u32 u32) Unit)
68(extern constructor u32_lteq u32_lteq)
69
70;; Pure/fallible constructor that tests if one u8 is less than or
71;; equal to another.
72(decl pure partial u8_lteq (u8 u8) Unit)
73(extern constructor u8_lteq u8_lteq)
74
75;; Pure/fallible constructor that tests if one u8 is strictly less
76;;  than another.
77(decl pure partial u8_lt (u8 u8) Unit)
78(extern constructor u8_lt u8_lt)
79
80;;;; Primitive Type Conversions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
81
82(decl pure u8_as_i8 (u8) i8)
83(extern constructor u8_as_i8 u8_as_i8)
84
85(spec (u8_as_u32 arg)
86    (provide (= result (zero_ext 32 arg)))
87    (require
88      (= (widthof arg) 8)
89      (= (widthof result) 32)))
90(decl pure u8_as_u32 (u8) u32)
91(extern constructor u8_as_u32 u8_as_u32)
92(convert u8 u32 u8_as_u32)
93
94(decl pure u8_as_u64 (u8) u64)
95(extern constructor u8_as_u64 u8_as_u64)
96(convert u8 u64 u8_as_u64)
97
98(decl pure u16_as_i16 (u16) i16)
99(extern constructor u16_as_i16 u16_as_i16)
100
101(decl pure u16_as_u32 (u16) u32)
102(extern constructor u16_as_u32 u16_as_u32)
103(convert u16 u32 u16_as_u32)
104
105(decl pure u16_as_u64 (u16) u64)
106(extern constructor u16_as_u64 u16_as_u64)
107(convert u16 u64 u16_as_u64)
108
109(decl pure u64_as_u8 (u64) u8)
110(extern constructor u64_as_u8 u64_as_u8)
111
112(decl pure u64_as_u16 (u64) u16)
113(extern constructor u64_as_u16 u64_as_u16)
114
115(decl pure u64_as_i64 (u64) i64)
116(extern constructor u64_as_i64 u64_as_i64)
117
118(decl pure partial u8_try_from_u64 (u64) u8)
119(extern constructor u8_try_from_u64 u8_try_from_u64)
120
121(decl pure partial u8_try_from_u16 (u16) u8)
122(extern constructor u8_try_from_u16 u8_try_from_u16)
123
124(decl pure partial u8_try_from_i32 (i32) u8)
125(extern constructor u8_try_from_i32 u8_try_from_i32)
126
127(decl u16_try_from_i32 (u16) i32)
128(extern extractor u16_try_from_i32 u16_try_from_i32)
129
130(decl pure partial u16_try_from_u64 (u64) u16)
131(extern constructor u16_try_from_u64 u16_try_from_u64)
132
133(decl pure partial u32_try_from_u64 (u64) u32)
134(extern constructor u32_try_from_u64 u32_try_from_u64)
135
136(decl pure partial u64_try_from_i64 (i64) u64)
137(extern constructor u64_try_from_i64 u64_try_from_i64)
138
139(decl i8_try_from_i32 (i8) i32)
140(extern extractor i8_try_from_i32 i8_try_from_i32)
141
142(decl pure partial i8_try_from_u64 (u64) i8)
143(extern constructor i8_try_from_u64 i8_try_from_u64)
144
145(decl pure partial i16_try_from_u64 (u64) i16)
146(extern constructor i16_try_from_u64 i16_try_from_u64)
147
148(decl pure partial i32_try_from_u64 (u64) i32)
149(extern constructor i32_try_from_u64 i32_try_from_u64)
150
151(decl pure u32_as_u64 (u32) u64)
152(extern constructor u32_as_u64 u32_as_u64)
153(convert u32 u64 u32_as_u64)
154
155(decl i32_as_u32 (u32) i32)
156(extern extractor i32_as_u32 i32_as_u32)
157
158(decl pure i32_as_i64 (i32) i64)
159(extern constructor i32_as_i64 i32_as_i64)
160(convert i32 i64 i32_as_i64)
161
162(spec (i64_as_u64 arg) (provide (= arg result)))
163(decl pure i64_as_u64 (i64) u64)
164(extern constructor i64_as_u64 i64_as_u64)
165
166(spec (i64_neg x) (provide (= result (bvneg x))))
167(decl pure i64_neg (i64) i64)
168(extern constructor i64_neg i64_neg)
169
170(decl pure i8_neg (i8) i8)
171(extern constructor i8_neg i8_neg)
172
173(decl u128_as_u64 (u64) u128)
174(extern extractor u128_as_u64 u128_as_u64)
175
176(decl u64_as_u32 (u32) u64)
177(extern extractor u64_as_u32 u64_as_u32)
178
179(decl u32_as_u16 (u16) u32)
180(extern extractor u32_as_u16 u32_as_u16)
181
182(decl i32_as_i8 (i8) i32)
183(extern extractor i32_as_i8 i32_as_i8)
184
185(decl pure u64_as_i32 (u64) i32)
186(extern constructor u64_as_i32 u64_as_i32)
187
188;;;; Primitive Arithmetic ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
189
190(decl pure u8_and (u8 u8) u8)
191(extern constructor u8_and u8_and)
192
193(decl pure u8_shl (u8 u8) u8)
194(extern constructor u8_shl u8_shl)
195
196(decl pure u8_shr (u8 u8) u8)
197(extern constructor u8_shr u8_shr)
198
199(decl pure u8_sub (u8 u8) u8)
200(extern constructor u8_sub u8_sub)
201
202(decl pure u32_add (u32 u32) u32)
203(extern constructor u32_add u32_add)
204
205(spec (u32_sub a b) (provide (= result (bvsub a b))))
206(decl pure u32_sub (u32 u32) u32)
207(extern constructor u32_sub u32_sub)
208
209(decl pure u32_and (u32 u32) u32)
210(extern constructor u32_and u32_and)
211
212(decl pure u32_shl (u32 u32) u32)
213(extern constructor u32_shl u32_shl)
214
215;; Pure/fallible constructor that tries to add two `u32`s, interpreted
216;; as signed values, and fails to match on overflow.
217(spec (s32_add_fallible x y)
218      (provide (= result (bvadd x y)))
219      (require (not (bvsaddo x y))))
220(decl pure partial s32_add_fallible (i32 i32) i32)
221(extern constructor s32_add_fallible s32_add_fallible)
222
223(decl pure partial checked_add_with_type (Type u64 u64) u64)
224(extern constructor checked_add_with_type checked_add_with_type)
225
226(decl pure add_overflows_with_type (Type u64 u64) bool)
227(extern constructor add_overflows_with_type add_overflows_with_type)
228
229(decl pure u64_add (u64 u64) u64)
230(extern constructor u64_add u64_add)
231
232(spec (u64_sub a b)
233      (provide (= result (bvsub a b))))
234(decl pure u64_sub (u64 u64) u64)
235(extern constructor u64_sub u64_sub)
236
237(decl pure u64_mul (u64 u64) u64)
238(extern constructor u64_mul u64_mul)
239
240(decl pure partial u64_udiv (u64 u64) u64)
241(extern constructor u64_udiv u64_udiv)
242
243(decl pure u64_and (u64 u64) u64)
244(extern constructor u64_and u64_and)
245
246(decl pure u64_or (u64 u64) u64)
247(extern constructor u64_or u64_or)
248
249(decl pure u64_xor (u64 u64) u64)
250(extern constructor u64_xor u64_xor)
251
252(decl pure u64_shl (u64 u64) u64)
253(extern constructor u64_shl u64_shl)
254
255(decl pure partial imm64_sdiv (Type Imm64 Imm64) Imm64)
256(extern constructor imm64_sdiv imm64_sdiv)
257
258(decl pure imm64_shl (Type Imm64 Imm64) Imm64)
259(extern constructor imm64_shl imm64_shl)
260
261(decl pure imm64_ushr (Type Imm64 Imm64) Imm64)
262(extern constructor imm64_ushr imm64_ushr)
263
264(decl pure imm64_sshr (Type Imm64 Imm64) Imm64)
265(extern constructor imm64_sshr imm64_sshr)
266
267(decl pure u64_not (u64) u64)
268(extern constructor u64_not u64_not)
269
270(decl pure u64_eq (u64 u64) bool)
271(extern constructor u64_eq u64_eq)
272
273(decl pure u64_le (u64 u64) bool)
274(extern constructor u64_le u64_le)
275
276(decl pure u64_lt (u64 u64) bool)
277(extern constructor u64_lt u64_lt)
278
279(decl pure i64_shr (i64 i64) i64)
280(extern constructor i64_shr i64_shr)
281
282(decl pure i64_ctz (i64) i64)
283(extern constructor i64_ctz i64_ctz)
284
285;; Sign extends a u64 from ty bits up to 64bits
286(decl pure i64_sextend_u64 (Type u64) i64)
287(extern constructor i64_sextend_u64 i64_sextend_u64)
288
289(spec (i64_sextend_imm64 ty a) (provide (= result (sign_ext 64 (conv_to ty a)))))
290(decl pure i64_sextend_imm64 (Type Imm64) i64)
291(extern constructor i64_sextend_imm64 i64_sextend_imm64)
292
293(decl pure u64_uextend_imm64 (Type Imm64) u64)
294(extern constructor u64_uextend_imm64 u64_uextend_imm64)
295
296(decl pure imm64_icmp (Type IntCC Imm64 Imm64) Imm64)
297(extern constructor imm64_icmp imm64_icmp)
298
299(decl u64_is_zero (bool) u64)
300(extern extractor infallible u64_is_zero u64_is_zero)
301
302(decl i64_is_zero (bool) i64)
303(extern extractor infallible i64_is_zero i64_is_zero)
304
305(decl u64_zero () u64)
306(extractor (u64_zero) (u64_is_zero true))
307
308(decl u64_nonzero (u64) u64)
309(extractor (u64_nonzero x) (and (u64_is_zero false) x))
310
311(decl i64_nonzero (i64) i64)
312(extractor (i64_nonzero x) (and (i64_is_zero false) x))
313
314;; x & 1 == 1
315(spec (u64_is_odd arg) (provide (= result (= #b1 (extract 0 0 arg)))))
316(decl pure u64_is_odd (u64) bool)
317(extern constructor u64_is_odd u64_is_odd)
318
319;; Each of these extractors tests whether the upper half of the input equals the
320;; lower half of the input
321(decl u128_replicated_u64 (u64) u128)
322(extern extractor u128_replicated_u64 u128_replicated_u64)
323(decl u64_replicated_u32 (u64) u64)
324(extern extractor u64_replicated_u32 u64_replicated_u32)
325(decl u32_replicated_u16 (u64) u64)
326(extern extractor u32_replicated_u16 u32_replicated_u16)
327(decl u16_replicated_u8 (u8) u64)
328(extern extractor u16_replicated_u8 u16_replicated_u8)
329
330;; Get the low and high bits of a `u128` as `u64`s.
331(decl u128_low_bits (u128) u64)
332(extern constructor u128_low_bits u128_low_bits)
333(decl u128_high_bits (u128) u64)
334(extern constructor u128_high_bits u128_high_bits)
335
336;; Floating point operations
337
338(decl pure partial f16_min (Ieee16 Ieee16) Ieee16)
339(extern constructor f16_min f16_min)
340(decl pure partial f16_max (Ieee16 Ieee16) Ieee16)
341(extern constructor f16_max f16_max)
342(decl pure f16_neg (Ieee16) Ieee16)
343(extern constructor f16_neg f16_neg)
344(decl pure f16_abs (Ieee16) Ieee16)
345(extern constructor f16_abs f16_abs)
346(decl pure f16_copysign (Ieee16 Ieee16) Ieee16)
347(extern constructor f16_copysign f16_copysign)
348(decl pure partial f32_add (Ieee32 Ieee32) Ieee32)
349(extern constructor f32_add f32_add)
350(decl pure partial f32_sub (Ieee32 Ieee32) Ieee32)
351(extern constructor f32_sub f32_sub)
352(decl pure partial f32_mul (Ieee32 Ieee32) Ieee32)
353(extern constructor f32_mul f32_mul)
354(decl pure partial f32_div (Ieee32 Ieee32) Ieee32)
355(extern constructor f32_div f32_div)
356(decl pure partial f32_sqrt (Ieee32) Ieee32)
357(extern constructor f32_sqrt f32_sqrt)
358(decl pure partial f32_ceil (Ieee32) Ieee32)
359(extern constructor f32_ceil f32_ceil)
360(decl pure partial f32_floor (Ieee32) Ieee32)
361(extern constructor f32_floor f32_floor)
362(decl pure partial f32_trunc (Ieee32) Ieee32)
363(extern constructor f32_trunc f32_trunc)
364(decl pure partial f32_nearest (Ieee32) Ieee32)
365(extern constructor f32_nearest f32_nearest)
366(decl pure partial f32_min (Ieee32 Ieee32) Ieee32)
367(extern constructor f32_min f32_min)
368(decl pure partial f32_max (Ieee32 Ieee32) Ieee32)
369(extern constructor f32_max f32_max)
370(decl pure f32_neg (Ieee32) Ieee32)
371(extern constructor f32_neg f32_neg)
372(decl pure f32_abs (Ieee32) Ieee32)
373(extern constructor f32_abs f32_abs)
374(decl pure f32_copysign (Ieee32 Ieee32) Ieee32)
375(extern constructor f32_copysign f32_copysign)
376(decl pure partial f64_add (Ieee64 Ieee64) Ieee64)
377(extern constructor f64_add f64_add)
378(decl pure partial f64_sub (Ieee64 Ieee64) Ieee64)
379(extern constructor f64_sub f64_sub)
380(decl pure partial f64_mul (Ieee64 Ieee64) Ieee64)
381(extern constructor f64_mul f64_mul)
382(decl pure partial f64_div (Ieee64 Ieee64) Ieee64)
383(extern constructor f64_div f64_div)
384(decl pure partial f64_sqrt (Ieee64) Ieee64)
385(extern constructor f64_sqrt f64_sqrt)
386(decl pure partial f64_ceil (Ieee64) Ieee64)
387(extern constructor f64_ceil f64_ceil)
388(decl pure partial f64_floor (Ieee64) Ieee64)
389(extern constructor f64_floor f64_floor)
390(decl pure partial f64_trunc (Ieee64) Ieee64)
391(extern constructor f64_trunc f64_trunc)
392(decl pure partial f64_nearest (Ieee64) Ieee64)
393(extern constructor f64_nearest f64_nearest)
394(decl pure partial f64_min (Ieee64 Ieee64) Ieee64)
395(extern constructor f64_min f64_min)
396(decl pure partial f64_max (Ieee64 Ieee64) Ieee64)
397(extern constructor f64_max f64_max)
398(decl pure f64_neg (Ieee64) Ieee64)
399(extern constructor f64_neg f64_neg)
400(decl pure f64_abs (Ieee64) Ieee64)
401(extern constructor f64_abs f64_abs)
402(decl pure f64_copysign (Ieee64 Ieee64) Ieee64)
403(extern constructor f64_copysign f64_copysign)
404(decl pure partial f128_min (Ieee128 Ieee128) Ieee128)
405(extern constructor f128_min f128_min)
406(decl pure partial f128_max (Ieee128 Ieee128) Ieee128)
407(extern constructor f128_max f128_max)
408(decl pure f128_neg (Ieee128) Ieee128)
409(extern constructor f128_neg f128_neg)
410(decl pure f128_abs (Ieee128) Ieee128)
411(extern constructor f128_abs f128_abs)
412(decl pure f128_copysign (Ieee128 Ieee128) Ieee128)
413(extern constructor f128_copysign f128_copysign)
414(type Ieee128 (primitive Ieee128))
415
416;;;; `cranelift_codegen::ir::Type` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
417
418(extern const $I8 Type)
419(extern const $I16 Type)
420(extern const $I32 Type)
421(extern const $I64 Type)
422(extern const $I128 Type)
423
424(extern const $F16 Type)
425(extern const $F32 Type)
426(extern const $F64 Type)
427(extern const $F128 Type)
428
429(extern const $I8X8 Type)
430(extern const $I8X16 Type)
431(extern const $I16X4 Type)
432(extern const $I16X8 Type)
433(extern const $I32X2 Type)
434(extern const $I32X4 Type)
435(extern const $I64X2 Type)
436
437(extern const $F16X8 Type)
438(extern const $F32X4 Type)
439(extern const $F64X2 Type)
440
441(extern const $I32X4XN Type)
442
443;; Get the unsigned minimum value for a given type.
444;; This always zero, but is included for completeness.
445(decl pure ty_umin (Type) u64)
446(extern constructor ty_umin ty_umin)
447
448;; Get the unsigned maximum value for a given type.
449(decl pure ty_umax (Type) u64)
450(extern constructor ty_umax ty_umax)
451
452;; Get the signed minimum value for a given type.
453(decl pure ty_smin (Type) u64)
454(extern constructor ty_smin ty_smin)
455
456;; Get the signed maximum value for a given type.
457(decl pure ty_smax (Type) u64)
458(extern constructor ty_smax ty_smax)
459
460;; Get the bit width of a given type.
461(spec (ty_bits x) (provide (= result (int2bv 8 x))))
462(decl pure ty_bits (Type) u8)
463(extern constructor ty_bits ty_bits)
464
465;; Get the bit width of a given type.
466(spec (ty_bits_u16 x)
467      (provide (= result (int2bv 16 x))))
468(decl pure ty_bits_u16 (Type) u16)
469(extern constructor ty_bits_u16 ty_bits_u16)
470
471;; Get the bit width of a given type.
472(decl pure ty_bits_u64 (Type) u64)
473(extern constructor ty_bits_u64 ty_bits_u64)
474
475;; Get a mask for the width of a given type.
476(decl pure ty_mask (Type) u64)
477(extern constructor ty_mask ty_mask)
478
479;; Get a mask that is set for each lane in a given type.
480(decl pure ty_lane_mask (Type) u64)
481(extern constructor ty_lane_mask ty_lane_mask)
482
483;; Get the number of lanes for a given type.
484(decl pure ty_lane_count (Type) u64)
485(extern constructor ty_lane_count ty_lane_count)
486
487;; Get the byte width of a given type.
488(decl pure ty_bytes (Type) u16)
489(extern constructor ty_bytes ty_bytes)
490
491;; Get the type of each lane in the given type.
492(decl pure lane_type (Type) Type)
493(extern constructor lane_type lane_type)
494
495;; Get a type with the same element type, but half the number of lanes.
496(decl pure partial ty_half_lanes (Type) Type)
497(extern constructor ty_half_lanes ty_half_lanes)
498
499;; Get a type with the same number of lanes but a lane type that is half as small.
500(decl pure partial ty_half_width (Type) Type)
501(extern constructor ty_half_width ty_half_width)
502
503;; Generate a mask for the maximum shift amount for a given type. i.e 31 for I32.
504(decl pure ty_shift_mask (Type) u64)
505(rule (ty_shift_mask ty) (u64_sub (ty_bits (lane_type ty)) 1))
506
507;; Compare two types for equality.
508(decl pure ty_equal (Type Type) bool)
509(extern constructor ty_equal ty_equal)
510
511;;;; `cranelift_codegen::ir::MemFlags ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
512
513;; Provide model for the MemFlags type (declared in generated clif_lower.isle).
514(model MemFlags (type (bv 16)))
515
516;; `MemFlags::trusted`
517(spec (mem_flags_trusted)
518      (provide (= result #x0003)))
519(decl pure mem_flags_trusted () MemFlags)
520(extern constructor mem_flags_trusted mem_flags_trusted)
521
522;;;; Helpers for Working with Flags ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
523
524;; Swap args of an IntCC flag.
525(decl intcc_swap_args (IntCC) IntCC)
526(extern constructor intcc_swap_args intcc_swap_args)
527
528;; Complement an IntCC flag.
529(decl intcc_complement (IntCC) IntCC)
530(extern constructor intcc_complement intcc_complement)
531
532;; This is a direct import of `IntCC::without_equal`.
533;; Get the corresponding IntCC with the equal component removed.
534;; For conditions without a zero component, this is a no-op.
535(decl pure intcc_without_eq (IntCC) IntCC)
536(extern constructor intcc_without_eq intcc_without_eq)
537
538;; Swap args of a FloatCC flag.
539(decl floatcc_swap_args (FloatCC) FloatCC)
540(extern constructor floatcc_swap_args floatcc_swap_args)
541
542;; Complement a FloatCC flag.
543(decl floatcc_complement (FloatCC) FloatCC)
544(extern constructor floatcc_complement floatcc_complement)
545
546;; True when this FloatCC involves an unordered comparison.
547(decl pure floatcc_unordered (FloatCC) bool)
548(extern constructor floatcc_unordered floatcc_unordered)
549
550;;;; Helper Clif Extractors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
551
552;; An extractor that only matches types that can fit in 16 bits.
553(spec (fits_in_16 arg)
554      (provide (= result arg))
555      (require (<= arg 16)))
556(decl fits_in_16 (Type) Type)
557(extern extractor fits_in_16 fits_in_16)
558
559;; An extractor that only matches types that can fit in 32 bits.
560(spec (fits_in_32 arg)
561      (provide (= result arg))
562      (require (<= arg 32)))
563(decl fits_in_32 (Type) Type)
564(extern extractor fits_in_32 fits_in_32)
565
566;; An extractor that only matches types that can fit in 32 bits.
567(decl lane_fits_in_32 (Type) Type)
568(extern extractor lane_fits_in_32 lane_fits_in_32)
569
570;; An extractor that only matches types that can fit in 64 bits.
571(spec (fits_in_64 arg)
572      (provide (= result arg))
573      (require (<= arg 64)))
574(decl fits_in_64 (Type) Type)
575(extern extractor fits_in_64 fits_in_64)
576
577;; An extractor that only matches types that fit in exactly 16 bits.
578(decl ty_16 (Type) Type)
579(extern extractor ty_16 ty_16)
580
581;; An extractor that only matches types that fit in exactly 32 bits.
582(decl ty_32 (Type) Type)
583(extern extractor ty_32 ty_32)
584
585;; An extractor that only matches types that fit in exactly 64 bits.
586(decl ty_64 (Type) Type)
587(extern extractor ty_64 ty_64)
588
589;; An extractor that only matches types that fit in exactly 128 bits.
590(decl ty_128 (Type) Type)
591(extern extractor ty_128 ty_128)
592
593;; A pure constructor/extractor that only matches scalar integers, and
594;; references that can fit in 64 bits.
595(spec (ty_int_ref_scalar_64 arg)
596    (provide (= result arg))
597    (require (<= arg 64)))
598(decl pure partial ty_int_ref_scalar_64 (Type) Type)
599(extern constructor ty_int_ref_scalar_64 ty_int_ref_scalar_64)
600(extern extractor ty_int_ref_scalar_64 ty_int_ref_scalar_64_extract)
601
602;; An extractor that matches 32- and 64-bit types only.
603(spec (ty_32_or_64 arg)
604      (provide (= result arg))
605      (require (or (= arg 32) (= arg 64))))
606(decl ty_32_or_64 (Type) Type)
607(extern extractor ty_32_or_64 ty_32_or_64)
608
609;; An extractor that matches 8- and 16-bit types only.
610(decl ty_8_or_16 (Type) Type)
611(extern extractor ty_8_or_16 ty_8_or_16)
612
613;; An extractor that matches 16- and 32-bit types only.
614(decl ty_16_or_32 (Type) Type)
615(extern extractor ty_16_or_32 ty_16_or_32)
616
617;; An extractor that matches int types that fit in 32 bits.
618(decl int_fits_in_32 (Type) Type)
619(extern extractor int_fits_in_32 int_fits_in_32)
620
621;; An extractor that matches I64.
622(decl ty_int_ref_64 (Type) Type)
623(extern extractor ty_int_ref_64 ty_int_ref_64)
624
625;; An extractor that matches int or reference types bigger than 16 bits but at most 64 bits.
626(decl ty_int_ref_16_to_64 (Type) Type)
627(extern extractor ty_int_ref_16_to_64 ty_int_ref_16_to_64)
628
629;; An extractor that only matches integers.
630(spec (ty_int a) (provide (= result a)))
631(decl ty_int (Type) Type)
632(extern extractor ty_int ty_int)
633
634;; An extractor that only matches scalar types, float or int or ref's.
635(decl ty_scalar (Type) Type)
636(extern extractor ty_scalar ty_scalar)
637
638;; An extractor that only matches scalar floating-point types.
639(decl ty_scalar_float (Type) Type)
640(extern extractor ty_scalar_float ty_scalar_float)
641
642;; An extractor that matches scalar floating-point types or vector types.
643(decl ty_float_or_vec (Type) Type)
644(extern extractor ty_float_or_vec ty_float_or_vec)
645
646;; A pure constructor that only matches vector floating-point types.
647(decl pure partial ty_vector_float (Type) Type)
648(extern constructor ty_vector_float ty_vector_float)
649
650;; A pure constructor that only matches vector types with lanes which
651;; are not floating-point.
652(decl pure partial ty_vector_not_float (Type) Type)
653(extern constructor ty_vector_not_float ty_vector_not_float)
654
655;; A pure constructor/extractor that only matches 64-bit vector types.
656(decl pure partial ty_vec64 (Type) Type)
657(extern constructor ty_vec64 ty_vec64_ctor)
658(extern extractor ty_vec64 ty_vec64)
659
660;; An extractor that only matches 128-bit vector types.
661(decl ty_vec128 (Type) Type)
662(extern extractor ty_vec128 ty_vec128)
663
664;; An extractor that only matches dynamic vector types with a 64-bit
665;; base type.
666(decl ty_dyn_vec64 (Type) Type)
667(extern extractor ty_dyn_vec64 ty_dyn_vec64)
668
669;; An extractor that only matches dynamic vector types with a 128-bit
670;; base type.
671(decl ty_dyn_vec128 (Type) Type)
672(extern extractor ty_dyn_vec128 ty_dyn_vec128)
673
674;; An extractor that only matches 64-bit vector types with integer
675;; lanes (I8X8, I16X4, I32X2)
676(decl ty_vec64_int (Type) Type)
677(extern extractor ty_vec64_int ty_vec64_int)
678
679;; An extractor that only matches 128-bit vector types with integer
680;; lanes (I8X16, I16X8, I32X4, I64X2).
681(decl ty_vec128_int (Type) Type)
682(extern extractor ty_vec128_int ty_vec128_int)
683
684;; An extractor that only matches types that can be a 64-bit address.
685(decl ty_addr64 (Type) Type)
686(extern extractor ty_addr64 ty_addr64)
687
688;; A pure constructor that matches everything except vectors with size 32X2.
689(decl pure partial not_vec32x2 (Type) Type)
690(extern constructor not_vec32x2 not_vec32x2)
691
692;; An extractor that matches everything except I64X2
693(decl not_i64x2 () Type)
694(extern extractor not_i64x2 not_i64x2)
695
696;; Extract a `u8` from an `Uimm8`.
697(decl u8_from_uimm8 (u8) Uimm8)
698(extern extractor infallible u8_from_uimm8 u8_from_uimm8)
699
700;; Extract a `u64` from a `bool`.
701(decl u64_from_bool (u64) bool)
702(extern extractor infallible u64_from_bool u64_from_bool)
703
704;; Extract a `u64` from an `Imm64`.
705(spec (u64_from_imm64 arg) (provide (= arg result)))
706(decl u64_from_imm64 (u64) Imm64)
707(extern extractor infallible u64_from_imm64 u64_from_imm64)
708
709;; Extract a `u64` from an `Imm64` which is not zero.
710(decl nonzero_u64_from_imm64 (u64) Imm64)
711(extern extractor nonzero_u64_from_imm64 nonzero_u64_from_imm64)
712
713;; If the given `Imm64` is a power-of-two, extract its log2 value.
714(decl imm64_power_of_two (u64) Imm64)
715(extern extractor imm64_power_of_two imm64_power_of_two)
716
717;; Create a new Imm64.
718(decl pure imm64 (u64) Imm64)
719(extern constructor imm64 imm64)
720
721;; Create a new Imm64, masked to the width of the given type.
722(decl pure imm64_masked (Type u64) Imm64)
723(extern constructor imm64_masked imm64_masked)
724
725;; Extract a `u16` from an `Ieee16`.
726(decl u16_from_ieee16 (u16) Ieee16)
727(extern extractor infallible u16_from_ieee16 u16_from_ieee16)
728
729;; Extract a `u32` from an `Ieee32`.
730(decl u32_from_ieee32 (u32) Ieee32)
731(extern extractor infallible u32_from_ieee32 u32_from_ieee32)
732
733;; Extract a `u64` from an `Ieee64`.
734(decl u64_from_ieee64 (u64) Ieee64)
735(extern extractor infallible u64_from_ieee64 u64_from_ieee64)
736
737;; Match a multi-lane type, extracting (# bits per lane, # lanes) from the given
738;; type. Will only match when there is more than one lane.
739(decl multi_lane (u32 u32) Type)
740(extern extractor multi_lane multi_lane)
741
742;; Match a dynamic-lane type, extracting (# bits per lane) from the given
743;; type.
744(decl dynamic_lane (u32 u32) Type)
745(extern extractor dynamic_lane dynamic_lane)
746
747;; An extractor that only matches 64-bit dynamic vector types with integer
748;; lanes (I8X8XN, I16X4XN, I32X2XN)
749(decl ty_dyn64_int (Type) Type)
750(extern extractor ty_dyn64_int ty_dyn64_int)
751
752;; An extractor that only matches 128-bit dynamic vector types with integer
753;; lanes (I8X16XN, I16X8XN, I32X4XN, I64X2XN).
754(decl ty_dyn128_int (Type) Type)
755(extern extractor ty_dyn128_int ty_dyn128_int)
756
757;; Convert an `Offset32` to a primitive number.
758(spec (offset32_to_i32 offset) (provide (= result offset)))
759(decl pure offset32_to_i32 (Offset32) i32)
760(extern constructor offset32_to_i32 offset32_to_i32)
761
762;; Convert a number to an `Offset32`
763(spec (i32_to_offset32 x) (provide (= result x)))
764(decl pure i32_to_offset32 (i32) Offset32)
765(extern constructor i32_to_offset32 i32_to_offset32)
766
767;; This is a direct import of `IntCC::unsigned`.
768;; Get the corresponding IntCC with the signed component removed.
769;; For conditions without a signed component, this is a no-op.
770(decl pure intcc_unsigned (IntCC) IntCC)
771(extern constructor intcc_unsigned intcc_unsigned)
772
773;; Pure constructor that only matches signed integer cond codes.
774(spec (signed_cond_code c)
775    (provide (= result c))
776    (require (and (bvuge c #x02) (bvule c #x05))))
777(decl pure partial signed_cond_code (IntCC) IntCC)
778(extern constructor signed_cond_code signed_cond_code)
779
780;;;; Helpers for Working with TrapCode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
781
782(decl pure trap_code_division_by_zero () TrapCode)
783(extern constructor trap_code_division_by_zero trap_code_division_by_zero)
784
785(decl pure trap_code_integer_overflow () TrapCode)
786(extern constructor trap_code_integer_overflow trap_code_integer_overflow)
787
788(decl pure trap_code_bad_conversion_to_integer () TrapCode)
789(extern constructor trap_code_bad_conversion_to_integer trap_code_bad_conversion_to_integer)
790
791;;;; Automatic conversions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
792
793(convert Offset32 i32 offset32_to_i32)
794(convert i32 Offset32 i32_to_offset32)
795
796;;;; Common Term Signatures ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
797
798(form
799  bv_unary_8_to_64
800  ((args (bv  8)) (ret (bv  8)) (canon (bv  8)))
801  ((args (bv 16)) (ret (bv 16)) (canon (bv 16)))
802  ((args (bv 32)) (ret (bv 32)) (canon (bv 32)))
803  ((args (bv 64)) (ret (bv 64)) (canon (bv 64)))
804)
805
806(form
807  bv_binary_8_to_64
808  ((args (bv  8) (bv  8)) (ret (bv  8)) (canon (bv  8)))
809  ((args (bv 16) (bv 16)) (ret (bv 16)) (canon (bv 16)))
810  ((args (bv 32) (bv 32)) (ret (bv 32)) (canon (bv 32)))
811  ((args (bv 64) (bv 64)) (ret (bv 64)) (canon (bv 64)))
812)
813
814(form
815  bv_ternary_8_to_64
816  ((args (bv  8) (bv  8) (bv  8)) (ret (bv  8)) (canon (bv  8)))
817  ((args (bv 16) (bv 16) (bv 16)) (ret (bv 16)) (canon (bv 16)))
818  ((args (bv 32) (bv 32) (bv 32)) (ret (bv 32)) (canon (bv 32)))
819  ((args (bv 64) (bv 64) (bv 64)) (ret (bv 64)) (canon (bv 64)))
820)
821