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;; Pure/fallible constructor that tries to add two `u32`s, interpreted
137;; as signed values, and fails to match on overflow.
138(decl pure partial s32_add_fallible (i32 i32) i32)
139(extern constructor s32_add_fallible s32_add_fallible)
140
141(decl pure u64_add (u64 u64) u64)
142(extern constructor u64_add u64_add)
143
144(decl pure u64_sub (u64 u64) u64)
145(extern constructor u64_sub u64_sub)
146
147(decl pure u64_mul (u64 u64) u64)
148(extern constructor u64_mul u64_mul)
149
150(decl pure partial u64_sdiv (u64 u64) u64)
151(extern constructor u64_sdiv u64_sdiv)
152
153(decl pure partial u64_udiv (u64 u64) u64)
154(extern constructor u64_udiv u64_udiv)
155
156(decl pure u64_and (u64 u64) u64)
157(extern constructor u64_and u64_and)
158
159(decl pure u64_or (u64 u64) u64)
160(extern constructor u64_or u64_or)
161
162(decl pure u64_xor (u64 u64) u64)
163(extern constructor u64_xor u64_xor)
164
165(decl pure u64_shl (u64 u64) u64)
166(extern constructor u64_shl u64_shl)
167
168(decl pure imm64_shl (Type Imm64 Imm64) Imm64)
169(extern constructor imm64_shl imm64_shl)
170
171(decl pure imm64_ushr (Type Imm64 Imm64) Imm64)
172(extern constructor imm64_ushr imm64_ushr)
173
174(decl pure imm64_sshr (Type Imm64 Imm64) Imm64)
175(extern constructor imm64_sshr imm64_sshr)
176
177(decl pure u64_not (u64) u64)
178(extern constructor u64_not u64_not)
179
180(decl pure u64_eq (u64 u64) bool)
181(extern constructor u64_eq u64_eq)
182
183(decl pure u64_le (u64 u64) bool)
184(extern constructor u64_le u64_le)
185
186(decl pure u64_lt (u64 u64) bool)
187(extern constructor u64_lt u64_lt)
188
189(decl pure i64_shr (i64 i64) i64)
190(extern constructor i64_shr i64_shr)
191
192(decl pure i64_ctz (i64) i64)
193(extern constructor i64_ctz i64_ctz)
194
195;; Sign extends a u64 from ty bits up to 64bits
196(decl pure i64_sextend_u64 (Type u64) i64)
197(extern constructor i64_sextend_u64 i64_sextend_u64)
198
199(decl pure i64_sextend_imm64 (Type Imm64) i64)
200(extern constructor i64_sextend_imm64 i64_sextend_imm64)
201
202(decl pure u64_uextend_imm64 (Type Imm64) u64)
203(extern constructor u64_uextend_imm64 u64_uextend_imm64)
204
205(decl pure imm64_icmp (Type IntCC Imm64 Imm64) Imm64)
206(extern constructor imm64_icmp imm64_icmp)
207
208(decl u64_is_zero (bool) u64)
209(extern extractor infallible u64_is_zero u64_is_zero)
210
211(decl i64_is_zero (bool) i64)
212(extern extractor infallible i64_is_zero i64_is_zero)
213
214(decl u64_zero () u64)
215(extractor (u64_zero) (u64_is_zero $true))
216
217(decl u64_nonzero (u64) u64)
218(extractor (u64_nonzero x) (and (u64_is_zero $false) x))
219
220(decl i64_nonzero (i64) i64)
221(extractor (i64_nonzero x) (and (i64_is_zero $false) x))
222
223(decl pure u64_is_odd (u64) bool)
224(extern constructor u64_is_odd u64_is_odd)
225
226;; Each of these extractors tests whether the upper half of the input equals the
227;; lower half of the input
228(decl u128_replicated_u64 (u64) u128)
229(extern extractor u128_replicated_u64 u128_replicated_u64)
230(decl u64_replicated_u32 (u64) u64)
231(extern extractor u64_replicated_u32 u64_replicated_u32)
232(decl u32_replicated_u16 (u64) u64)
233(extern extractor u32_replicated_u16 u32_replicated_u16)
234(decl u16_replicated_u8 (u8) u64)
235(extern extractor u16_replicated_u8 u16_replicated_u8)
236
237;; Floating point operations
238
239(decl pure f32_neg (Ieee32) Ieee32)
240(extern constructor f32_neg f32_neg)
241(decl pure f32_abs (Ieee32) Ieee32)
242(extern constructor f32_abs f32_abs)
243(decl pure f32_copysign (Ieee32 Ieee32) Ieee32)
244(extern constructor f32_copysign f32_copysign)
245(decl pure f64_neg (Ieee64) Ieee64)
246(extern constructor f64_neg f64_neg)
247(decl pure f64_abs (Ieee64) Ieee64)
248(extern constructor f64_abs f64_abs)
249(decl pure f64_copysign (Ieee64 Ieee64) Ieee64)
250(extern constructor f64_copysign f64_copysign)
251
252;;;; `cranelift_codegen::ir::Type` ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
253
254(extern const $I8 Type)
255(extern const $I16 Type)
256(extern const $I32 Type)
257(extern const $I64 Type)
258(extern const $I128 Type)
259
260(extern const $R32 Type)
261(extern const $R64 Type)
262
263(extern const $F32 Type)
264(extern const $F64 Type)
265
266(extern const $I8X8 Type)
267(extern const $I8X16 Type)
268(extern const $I16X4 Type)
269(extern const $I16X8 Type)
270(extern const $I32X2 Type)
271(extern const $I32X4 Type)
272(extern const $I64X2 Type)
273
274(extern const $F32X4 Type)
275(extern const $F64X2 Type)
276
277(extern const $I32X4XN Type)
278
279;; Get the unsigned minimum value for a given type.
280;; This always zero, but is included for completeness.
281(decl pure ty_umin (Type) u64)
282(extern constructor ty_umin ty_umin)
283
284;; Get the unsigned maximum value for a given type.
285(decl pure ty_umax (Type) u64)
286(extern constructor ty_umax ty_umax)
287
288;; Get the signed minimum value for a given type.
289(decl pure ty_smin (Type) u64)
290(extern constructor ty_smin ty_smin)
291
292;; Get the signed maximum value for a given type.
293(decl pure ty_smax (Type) u64)
294(extern constructor ty_smax ty_smax)
295
296;; Get the bit width of a given type.
297(decl pure ty_bits (Type) u8)
298(extern constructor ty_bits ty_bits)
299
300;; Get the bit width of a given type.
301(decl pure ty_bits_u16 (Type) u16)
302(extern constructor ty_bits_u16 ty_bits_u16)
303
304;; Get the bit width of a given type.
305(decl pure ty_bits_u64 (Type) u64)
306(extern constructor ty_bits_u64 ty_bits_u64)
307
308;; Get a mask for the width of a given type.
309(decl pure ty_mask (Type) u64)
310(extern constructor ty_mask ty_mask)
311
312;; Get a mask that is set for each lane in a given type.
313(decl pure ty_lane_mask (Type) u64)
314(extern constructor ty_lane_mask ty_lane_mask)
315
316;; Get the number of lanes for a given type.
317(decl pure ty_lane_count (Type) u64)
318(extern constructor ty_lane_count ty_lane_count)
319
320;; Get the byte width of a given type.
321(decl pure ty_bytes (Type) u16)
322(extern constructor ty_bytes ty_bytes)
323
324;; Get the type of each lane in the given type.
325(decl pure lane_type (Type) Type)
326(extern constructor lane_type lane_type)
327
328;; Get a type with the same element type, but half the number of lanes.
329(decl pure partial ty_half_lanes (Type) Type)
330(extern constructor ty_half_lanes ty_half_lanes)
331
332;; Get a type with the same number of lanes but a lane type that is half as small.
333(decl pure partial ty_half_width (Type) Type)
334(extern constructor ty_half_width ty_half_width)
335
336;; Generate a mask for the maximum shift amount for a given type. i.e 31 for I32.
337(decl pure ty_shift_mask (Type) u64)
338(rule (ty_shift_mask ty) (u64_sub (ty_bits (lane_type ty)) 1))
339
340;; Compare two types for equality.
341(decl pure ty_equal (Type Type) bool)
342(extern constructor ty_equal ty_equal)
343
344(decl pure is_ref_type (Type) bool)
345(rule 1 (is_ref_type $R32) $true)
346(rule 1 (is_ref_type $R64) $true)
347(rule 0 (is_ref_type _) $false)
348
349;;;; `cranelift_codegen::ir::MemFlags ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
350
351;; `MemFlags::trusted`
352(decl pure mem_flags_trusted () MemFlags)
353(extern constructor mem_flags_trusted mem_flags_trusted)
354
355;;;; Helpers for Working with Flags ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
356
357;; Swap args of an IntCC flag.
358(decl intcc_swap_args (IntCC) IntCC)
359(extern constructor intcc_swap_args intcc_swap_args)
360
361;; Complement an IntCC flag.
362(decl intcc_complement (IntCC) IntCC)
363(extern constructor intcc_complement intcc_complement)
364
365;; This is a direct import of `IntCC::without_equal`.
366;; Get the corresponding IntCC with the equal component removed.
367;; For conditions without a zero component, this is a no-op.
368(decl pure intcc_without_eq (IntCC) IntCC)
369(extern constructor intcc_without_eq intcc_without_eq)
370
371;; Swap args of a FloatCC flag.
372(decl floatcc_swap_args (FloatCC) FloatCC)
373(extern constructor floatcc_swap_args floatcc_swap_args)
374
375;; Complement a FloatCC flag.
376(decl floatcc_complement (FloatCC) FloatCC)
377(extern constructor floatcc_complement floatcc_complement)
378
379;; True when this FloatCC involves an unordered comparison.
380(decl pure floatcc_unordered (FloatCC) bool)
381(extern constructor floatcc_unordered floatcc_unordered)
382
383;;;; Helper Clif Extractors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
384
385(decl eq (Type Value Value) Value)
386(extractor (eq ty x y) (icmp ty (IntCC.Equal) x y))
387
388(decl ne (Type Value Value) Value)
389(extractor (ne ty x y) (icmp ty (IntCC.NotEqual) x y))
390
391(decl ult (Type Value Value) Value)
392(extractor (ult ty x y) (icmp ty (IntCC.UnsignedLessThan) x y))
393
394(decl ule (Type Value Value) Value)
395(extractor (ule ty x y) (icmp ty (IntCC.UnsignedLessThanOrEqual) x y))
396
397(decl ugt (Type Value Value) Value)
398(extractor (ugt ty x y) (icmp ty (IntCC.UnsignedGreaterThan) x y))
399
400(decl uge (Type Value Value) Value)
401(extractor (uge ty x y) (icmp ty (IntCC.UnsignedGreaterThanOrEqual) x y))
402
403(decl slt (Type Value Value) Value)
404(extractor (slt ty x y) (icmp ty (IntCC.SignedLessThan) x y))
405
406(decl sle (Type Value Value) Value)
407(extractor (sle ty x y) (icmp ty (IntCC.SignedLessThanOrEqual) x y))
408
409(decl sgt (Type Value Value) Value)
410(extractor (sgt ty x y) (icmp ty (IntCC.SignedGreaterThan) x y))
411
412(decl sge (Type Value Value) Value)
413(extractor (sge ty x y) (icmp ty (IntCC.SignedGreaterThanOrEqual) x y))
414
415;; An extractor that only matches types that can fit in 16 bits.
416(decl fits_in_16 (Type) Type)
417(extern extractor fits_in_16 fits_in_16)
418
419;; An extractor that only matches types that can fit in 32 bits.
420(decl fits_in_32 (Type) Type)
421(extern extractor fits_in_32 fits_in_32)
422
423;; An extractor that only matches types that can fit in 32 bits.
424(decl lane_fits_in_32 (Type) Type)
425(extern extractor lane_fits_in_32 lane_fits_in_32)
426
427;; An extractor that only matches types that can fit in 64 bits.
428(decl fits_in_64 (Type) Type)
429(extern extractor fits_in_64 fits_in_64)
430
431;; An extractor that only matches types that fit in exactly 32 bits.
432(decl ty_32 (Type) Type)
433(extern extractor ty_32 ty_32)
434
435;; An extractor that only matches types that fit in exactly 64 bits.
436(decl ty_64 (Type) Type)
437(extern extractor ty_64 ty_64)
438
439;; A pure constructor/extractor that only matches scalar integers, and
440;; references that can fit in 64 bits.
441(decl pure partial ty_int_ref_scalar_64 (Type) Type)
442(extern constructor ty_int_ref_scalar_64 ty_int_ref_scalar_64)
443(extern extractor ty_int_ref_scalar_64 ty_int_ref_scalar_64_extract)
444
445;; An extractor that matches 32- and 64-bit types only.
446(decl ty_32_or_64 (Type) Type)
447(extern extractor ty_32_or_64 ty_32_or_64)
448
449;; An extractor that matches 8- and 16-bit types only.
450(decl ty_8_or_16 (Type) Type)
451(extern extractor ty_8_or_16 ty_8_or_16)
452
453;; An extractor that matches 16- and 32-bit types only.
454(decl ty_16_or_32 (Type) Type)
455(extern extractor ty_16_or_32 ty_16_or_32)
456
457;; An extractor that matches int types that fit in 32 bits.
458(decl int_fits_in_32 (Type) Type)
459(extern extractor int_fits_in_32 int_fits_in_32)
460
461;; An extractor that matches I64 or R64.
462(decl ty_int_ref_64 (Type) Type)
463(extern extractor ty_int_ref_64 ty_int_ref_64)
464
465;; An extractor that matches int or reference types bigger than 16 bits but at most 64 bits.
466(decl ty_int_ref_16_to_64 (Type) Type)
467(extern extractor ty_int_ref_16_to_64 ty_int_ref_16_to_64)
468
469;; An extractor that only matches integers.
470(decl ty_int (Type) Type)
471(extern extractor ty_int ty_int)
472
473;; An extractor that only matches scalar types, float or int or ref's.
474(decl ty_scalar (Type) Type)
475(extern extractor ty_scalar ty_scalar)
476
477;; An extractor that only matches scalar floating-point types--F32 or F64.
478(decl ty_scalar_float (Type) Type)
479(extern extractor ty_scalar_float ty_scalar_float)
480
481;; An extractor that matches scalar floating-point types or vector types.
482(decl ty_float_or_vec (Type) Type)
483(extern extractor ty_float_or_vec ty_float_or_vec)
484
485;; A pure constructor that only matches vector floating-point types.
486(decl pure partial ty_vector_float (Type) Type)
487(extern constructor ty_vector_float ty_vector_float)
488
489;; A pure constructor that only matches vector types with lanes which
490;; are not floating-point.
491(decl pure partial ty_vector_not_float (Type) Type)
492(extern constructor ty_vector_not_float ty_vector_not_float)
493
494;; A pure constructor/extractor that only matches 64-bit vector types.
495(decl pure partial ty_vec64 (Type) Type)
496(extern constructor ty_vec64 ty_vec64_ctor)
497(extern extractor ty_vec64 ty_vec64)
498
499;; An extractor that only matches 128-bit vector types.
500(decl ty_vec128 (Type) Type)
501(extern extractor ty_vec128 ty_vec128)
502
503;; An extractor that only matches dynamic vector types with a 64-bit
504;; base type.
505(decl ty_dyn_vec64 (Type) Type)
506(extern extractor ty_dyn_vec64 ty_dyn_vec64)
507
508;; An extractor that only matches dynamic vector types with a 128-bit
509;; base type.
510(decl ty_dyn_vec128 (Type) Type)
511(extern extractor ty_dyn_vec128 ty_dyn_vec128)
512
513;; An extractor that only matches 64-bit vector types with integer
514;; lanes (I8X8, I16X4, I32X2)
515(decl ty_vec64_int (Type) Type)
516(extern extractor ty_vec64_int ty_vec64_int)
517
518;; An extractor that only matches 128-bit vector types with integer
519;; lanes (I8X16, I16X8, I32X4, I64X2).
520(decl ty_vec128_int (Type) Type)
521(extern extractor ty_vec128_int ty_vec128_int)
522
523;; An extractor that only matches types that can be a 64-bit address.
524(decl ty_addr64 (Type) Type)
525(extern extractor ty_addr64 ty_addr64)
526
527;; A pure constructor that matches everything except vectors with size 32X2.
528(decl pure partial not_vec32x2 (Type) Type)
529(extern constructor not_vec32x2 not_vec32x2)
530
531;; An extractor that matches everything except I64X2
532(decl not_i64x2 () Type)
533(extern extractor not_i64x2 not_i64x2)
534
535;; Extract a `u8` from an `Uimm8`.
536(decl u8_from_uimm8 (u8) Uimm8)
537(extern extractor infallible u8_from_uimm8 u8_from_uimm8)
538
539;; Extract a `u64` from a `bool`.
540(decl u64_from_bool (u64) bool)
541(extern extractor infallible u64_from_bool u64_from_bool)
542
543;; Extract a `u64` from an `Imm64`.
544(decl u64_from_imm64 (u64) Imm64)
545(extern extractor infallible u64_from_imm64 u64_from_imm64)
546
547;; Extract a `u64` from an `Imm64` which is not zero.
548(decl nonzero_u64_from_imm64 (u64) Imm64)
549(extern extractor nonzero_u64_from_imm64 nonzero_u64_from_imm64)
550
551;; If the given `Imm64` is a power-of-two, extract its log2 value.
552(decl imm64_power_of_two (u64) Imm64)
553(extern extractor imm64_power_of_two imm64_power_of_two)
554
555;; Create a new Imm64.
556(decl pure imm64 (u64) Imm64)
557(extern constructor imm64 imm64)
558
559;; Create a new Imm64, masked to the width of the given type.
560(decl pure imm64_masked (Type u64) Imm64)
561(extern constructor imm64_masked imm64_masked)
562
563;; Extract a `u64` from an `Ieee32`.
564(decl u32_from_ieee32 (u32) Ieee32)
565(extern extractor infallible u32_from_ieee32 u32_from_ieee32)
566
567;; Extract a `u64` from an `Ieee64`.
568(decl u64_from_ieee64 (u64) Ieee64)
569(extern extractor infallible u64_from_ieee64 u64_from_ieee64)
570
571;; Match a multi-lane type, extracting (# bits per lane, # lanes) from the given
572;; type. Will only match when there is more than one lane.
573(decl multi_lane (u32 u32) Type)
574(extern extractor multi_lane multi_lane)
575
576;; Match a dynamic-lane type, extracting (# bits per lane) from the given
577;; type.
578(decl dynamic_lane (u32 u32) Type)
579(extern extractor dynamic_lane dynamic_lane)
580
581;; Match a dynamic-lane integer type, extracting (# bits per lane) from the given
582;; type.
583(decl dynamic_int_lane (u32) Type)
584(extern extractor dynamic_int_lane dynamic_int_lane)
585
586;; Match a dynamic-lane floating point type, extracting (# bits per lane)
587;; from the given type.
588(decl dynamic_fp_lane (u32) Type)
589(extern extractor dynamic_fp_lane dynamic_fp_lane)
590
591;; An extractor that only matches 64-bit dynamic vector types with integer
592;; lanes (I8X8XN, I16X4XN, I32X2XN)
593(decl ty_dyn64_int (Type) Type)
594(extern extractor ty_dyn64_int ty_dyn64_int)
595
596;; An extractor that only matches 128-bit dynamic vector types with integer
597;; lanes (I8X16XN, I16X8XN, I32X4XN, I64X2XN).
598(decl ty_dyn128_int (Type) Type)
599(extern extractor ty_dyn128_int ty_dyn128_int)
600
601;; Convert an `Offset32` to a primitive number.
602(decl pure offset32_to_i32 (Offset32) i32)
603(extern constructor offset32_to_i32 offset32_to_i32)
604
605;; Convert a number to an `Offset32`
606(decl pure i32_to_offset32 (i32) Offset32)
607(extern constructor i32_to_offset32 i32_to_offset32)
608
609;; This is a direct import of `IntCC::unsigned`.
610;; Get the corresponding IntCC with the signed component removed.
611;; For conditions without a signed component, this is a no-op.
612(decl pure intcc_unsigned (IntCC) IntCC)
613(extern constructor intcc_unsigned intcc_unsigned)
614
615;; Pure constructor that only matches signed integer cond codes.
616(decl pure partial signed_cond_code (IntCC) IntCC)
617(extern constructor signed_cond_code signed_cond_code)
618
619;;;; Helpers for Working with TrapCode ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
620
621(decl pure trap_code_division_by_zero () TrapCode)
622(extern constructor trap_code_division_by_zero trap_code_division_by_zero)
623
624(decl pure trap_code_integer_overflow () TrapCode)
625(extern constructor trap_code_integer_overflow trap_code_integer_overflow)
626
627(decl pure trap_code_bad_conversion_to_integer () TrapCode)
628(extern constructor trap_code_bad_conversion_to_integer trap_code_bad_conversion_to_integer)
629
630;;;; Helpers for tail recursion loops ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
631
632;; A range of integers to loop through.
633(type Range (primitive Range))
634
635;; Create a new range from `start` through `end` (exclusive).
636(decl pure range (usize usize) Range)
637(extern constructor range range)
638
639;; A view on the current state of the range.
640(type RangeView extern
641      (enum
642        (Empty)
643        (NonEmpty (index usize) (rest Range))))
644
645;; View the current state of the range.
646(decl range_view (RangeView) Range)
647(extern extractor infallible range_view range_view)
648
649;; Extractor to test whether a range is empty.
650(decl range_empty () Range)
651(extractor (range_empty) (range_view (RangeView.Empty)))
652
653;; Extractor to return the first value in the range, and a sub-range
654;; containing the remaining values.
655(decl range_unwrap (usize Range) Range)
656(extractor (range_unwrap index rest) (range_view (RangeView.NonEmpty index rest)))
657
658;;;; Automatic conversions ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
659
660(convert Offset32 i32 offset32_to_i32)
661(convert i32 Offset32 i32_to_offset32)
662