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