cranelift-codegen 0.112.2

Low-level code generator library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
;;;; Instruction definition ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Note: in the instructions below, we order destination registers first and
;; then source registers afterwards.
(type MInst
  (enum
    ;;;; Pseudo-Instructions ;;;;

    ;; A pseudo-instruction that captures register arguments in vregs.
    (Args (args VecArgPair))

    ;; A pseudo-instruction that moves vregs to return registers.
    (Rets (rets VecRetPair))

    ;; A pseudo-instruction to update unwind info.
    (Unwind (inst UnwindInst))

    ;;;; Actual Instructions ;;;;

    ;; Raise a trap.
    (Trap (code TrapCode))

    ;; Nothing.
    (Nop)

    ;; Get the stack pointer.
    (GetSp (dst WritableXReg))

    ;; Return.
    (Ret)

    ;; Load an external symbol's address into a register.
    (LoadExtName (dst WritableXReg)
                 (name BoxExternalName)
                 (offset i64))

    ;; A direct call to a known callee.
    (Call (info BoxCallInfo))

    ;; An indirect call to an unknown callee.
    (IndirectCall (info BoxCallIndInfo))

    ;; Unconditional jumps.
    (Jump (label MachLabel))

    ;; Jump to `then` if `c` is nonzero, otherwise to `else`.
    (BrIf (c XReg) (taken MachLabel) (not_taken MachLabel))

    ;; Compare-and-branch macro ops.
    (BrIfXeq32 (src1 XReg) (src2 XReg) (taken MachLabel) (not_taken MachLabel))
    (BrIfXneq32 (src1 XReg) (src2 XReg) (taken MachLabel) (not_taken MachLabel))
    (BrIfXslt32 (src1 XReg) (src2 XReg) (taken MachLabel) (not_taken MachLabel))
    (BrIfXslteq32 (src1 XReg) (src2 XReg) (taken MachLabel) (not_taken MachLabel))
    (BrIfXult32 (src1 XReg) (src2 XReg) (taken MachLabel) (not_taken MachLabel))
    (BrIfXulteq32 (src1 XReg) (src2 XReg) (taken MachLabel) (not_taken MachLabel))

    ;; Register-to-register moves.
    (Xmov (dst WritableXReg) (src XReg))
    (Fmov (dst WritableFReg) (src FReg))
    (Vmov (dst WritableVReg) (src VReg))

    ;; Integer constants, zero-extended to 64 bits.
    (Xconst8 (dst WritableXReg) (imm i8))
    (Xconst16 (dst WritableXReg) (imm i16))
    (Xconst32 (dst WritableXReg) (imm i32))
    (Xconst64 (dst WritableXReg) (imm i64))

    ;; Integer arithmetic.
    (Xadd32 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xadd64 (dst WritableXReg) (src1 XReg) (src2 XReg))

    ;; Comparisons.
    (Xeq64 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xneq64 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xslt64 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xslteq64 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xult64 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xulteq64 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xeq32 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xneq32 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xslt32 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xslteq32 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xult32 (dst WritableXReg) (src1 XReg) (src2 XReg))
    (Xulteq32 (dst WritableXReg) (src1 XReg) (src2 XReg))

    ;; Load the memory address referenced by `mem` into `dst`.
    (LoadAddr (dst WritableXReg) (mem Amode))

    ;; Loads.
    (Load (dst WritableReg) (mem Amode) (ty Type) (flags MemFlags) (ext ExtKind))

    ;; Stores.
    (Store (mem Amode) (src Reg) (ty Type) (flags MemFlags))

    ;; Bitcasts.
    (BitcastIntFromFloat32 (dst WritableXReg) (src FReg))
    (BitcastIntFromFloat64 (dst WritableXReg) (src FReg))
    (BitcastFloatFromInt32 (dst WritableFReg) (src XReg))
    (BitcastFloatFromInt64 (dst WritableFReg) (src XReg))
  )
)

(type BoxCallInfo (primitive BoxCallInfo))
(type BoxCallIndInfo (primitive BoxCallIndInfo))

;;;; Address Modes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(type StackAMode extern (enum))

(type Amode
  (enum
    (SpOffset (offset i64))
    (RegOffset (base XReg) (offset i64))
    (Stack (amode StackAMode))
  )
)

(type ExtKind (enum None Sign Zero))

;;;; Newtypes for Different Register Classes ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(type XReg (primitive XReg))
(type WritableXReg (primitive WritableXReg))

(type FReg (primitive FReg))
(type WritableFReg (primitive WritableFReg))

(type VReg (primitive VReg))
(type WritableVReg (primitive WritableVReg))

;; Construct a new `XReg` from a `Reg`.
;;
;; Asserts that the register has an integer RegClass.
(decl xreg_new (Reg) XReg)
(extern constructor xreg_new xreg_new)
(convert Reg XReg xreg_new)

;; Construct a new `WritableXReg` from a `WritableReg`.
;;
;; Asserts that the register has an integer RegClass.
(decl writable_xreg_new (WritableReg) WritableXReg)
(extern constructor writable_xreg_new writable_xreg_new)
(convert WritableReg WritableXReg writable_xreg_new)

;; Put a value into a XReg.
;;
;; Asserts that the value goes into a XReg.
(decl put_in_xreg (Value) XReg)
(rule (put_in_xreg val) (xreg_new (put_in_reg val)))
(convert Value XReg put_in_xreg)

;; Construct an `InstOutput` out of a single XReg register.
(decl output_xreg (XReg) InstOutput)
(rule (output_xreg x) (output_reg x))
(convert XReg InstOutput output_xreg)

;; Convert a `WritableXReg` to an `XReg`.
(decl pure writable_xreg_to_xreg (WritableXReg) XReg)
(extern constructor writable_xreg_to_xreg writable_xreg_to_xreg)
(convert WritableXReg XReg writable_xreg_to_xreg)

;; Convert a `WritableXReg` to an `WritableReg`.
(decl pure writable_xreg_to_writable_reg (WritableXReg) WritableReg)
(extern constructor writable_xreg_to_writable_reg writable_xreg_to_writable_reg)
(convert WritableXReg WritableReg writable_xreg_to_writable_reg)

;; Convert a `WritableXReg` to an `Reg`.
(decl pure writable_xreg_to_reg (WritableXReg) Reg)
(rule (writable_xreg_to_reg x) (writable_xreg_to_writable_reg x))
(convert WritableXReg Reg writable_xreg_to_reg)

;; Convert an `XReg` to a `Reg`.
(decl pure xreg_to_reg (XReg) Reg)
(extern constructor xreg_to_reg xreg_to_reg)
(convert XReg Reg xreg_to_reg)

;; Convert a `XReg` to a `ValueRegs`.
(decl xreg_to_value_regs (XReg) ValueRegs)
(rule (xreg_to_value_regs x) (value_reg x))
(convert XReg ValueRegs xreg_to_reg)

;; Convert a `WritableXReg` to a `ValueRegs`.
(decl writable_xreg_to_value_regs (WritableXReg) ValueRegs)
(rule (writable_xreg_to_value_regs x) (value_reg x))
(convert WritableXReg ValueRegs writable_xreg_to_value_regs)

;; Allocates a new `WritableXReg`.
(decl temp_writable_xreg () WritableXReg)
(rule (temp_writable_xreg) (temp_writable_reg $I64))

;; Construct a new `FReg` from a `Reg`.
;;
;; Asserts that the register has a Float RegClass.
(decl freg_new (Reg) FReg)
(extern constructor freg_new freg_new)
(convert Reg FReg freg_new)

;; Construct a new `WritableFReg` from a `WritableReg`.
;;
;; Asserts that the register has a Float RegClass.
(decl writable_freg_new (WritableReg) WritableFReg)
(extern constructor writable_freg_new writable_freg_new)
(convert WritableReg WritableFReg writable_freg_new)

;; Put a value into a FReg.
;;
;; Asserts that the value goes into a FReg.
(decl put_in_freg (Value) FReg)
(rule (put_in_freg val) (freg_new (put_in_reg val)))
(convert Value FReg put_in_freg)

;; Construct an `InstOutput` out of a single FReg register.
(decl output_freg (FReg) InstOutput)
(rule (output_freg x) (output_reg x))
(convert FReg InstOutput output_freg)

;; Convert a `WritableFReg` to an `FReg`.
(decl pure writable_freg_to_freg (WritableFReg) FReg)
(extern constructor writable_freg_to_freg writable_freg_to_freg)
(convert WritableFReg FReg writable_freg_to_freg)

;; Convert a `WritableFReg` to an `WritableReg`.
(decl pure writable_freg_to_writable_reg (WritableFReg) WritableReg)
(extern constructor writable_freg_to_writable_reg writable_freg_to_writable_reg)
(convert WritableFReg WritableReg writable_freg_to_writable_reg)

;; Convert a `WritableFReg` to an `Reg`.
(decl pure writable_freg_to_reg (WritableFReg) Reg)
(rule (writable_freg_to_reg x) (writable_freg_to_writable_reg x))
(convert WritableFReg Reg writable_freg_to_reg)

;; Convert an `FReg` to a `Reg`.
(decl pure freg_to_reg (FReg) Reg)
(extern constructor freg_to_reg freg_to_reg)
(convert FReg Reg freg_to_reg)

;; Convert a `FReg` to a `ValueRegs`.
(decl freg_to_value_regs (FReg) ValueRegs)
(rule (freg_to_value_regs x) (value_reg x))
(convert FReg ValueRegs xreg_to_reg)

;; Convert a `WritableFReg` to a `ValueRegs`.
(decl writable_freg_to_value_regs (WritableFReg) ValueRegs)
(rule (writable_freg_to_value_regs x) (value_reg x))
(convert WritableFReg ValueRegs writable_freg_to_value_regs)

;; Allocates a new `WritableFReg`.
(decl temp_writable_freg () WritableFReg)
(rule (temp_writable_freg) (temp_writable_reg $F64))

;; Construct a new `VReg` from a `Reg`.
;;
;; Asserts that the register has a Vector RegClass.
(decl vreg_new (Reg) VReg)
(extern constructor vreg_new vreg_new)
(convert Reg VReg vreg_new)

;; Construct a new `WritableVReg` from a `WritableReg`.
;;
;; Asserts that the register has a Vector RegClass.
(decl writable_vreg_new (WritableReg) WritableVReg)
(extern constructor writable_vreg_new writable_vreg_new)
(convert WritableReg WritableVReg writable_vreg_new)

;; Put a value into a VReg.
;;
;; Asserts that the value goes into a VReg.
(decl put_in_vreg (Value) VReg)
(rule (put_in_vreg val) (vreg_new (put_in_reg val)))
(convert Value VReg put_in_vreg)

;; Construct an `InstOutput` out of a single VReg register.
(decl output_vreg (VReg) InstOutput)
(rule (output_vreg x) (output_reg x))
(convert VReg InstOutput output_vreg)

;; Convert a `WritableVReg` to an `VReg`.
(decl pure writable_vreg_to_vreg (WritableVReg) VReg)
(extern constructor writable_vreg_to_vreg writable_vreg_to_vreg)
(convert WritableVReg VReg writable_vreg_to_vreg)

;; Convert a `WritableVReg` to an `WritableReg`.
(decl pure writable_vreg_to_writable_reg (WritableVReg) WritableReg)
(extern constructor writable_vreg_to_writable_reg writable_vreg_to_writable_reg)
(convert WritableVReg WritableReg writable_vreg_to_writable_reg)

;; Convert a `WritableVReg` to an `Reg`.
(decl pure writable_vreg_to_reg (WritableVReg) Reg)
(rule (writable_vreg_to_reg x) (writable_vreg_to_writable_reg x))
(convert WritableVReg Reg writable_vreg_to_reg)

;; Convert an `VReg` to a `Reg`.
(decl pure vreg_to_reg (VReg) Reg)
(extern constructor vreg_to_reg vreg_to_reg)
(convert VReg Reg vreg_to_reg)

;; Convert a `VReg` to a `ValueRegs`.
(decl vreg_to_value_regs (VReg) ValueRegs)
(rule (vreg_to_value_regs x) (value_reg x))
(convert VReg ValueRegs xreg_to_reg)

;; Convert a `WritableVReg` to a `ValueRegs`.
(decl writable_vreg_to_value_regs (WritableVReg) ValueRegs)
(rule (writable_vreg_to_value_regs x) (value_reg x))
(convert WritableVReg ValueRegs writable_vreg_to_value_regs)

;; Allocates a new `WritableVReg`.
(decl temp_writable_vreg () WritableVReg)
(rule (temp_writable_vreg) (temp_writable_reg $I8X16))

;;;; Materializing Constants ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Lower a constant into a register.
(decl imm (Type u64) Reg)

;; If a value can fit into 8 bits, then prioritize that.
(rule 3 (imm (ty_int _) x)
      (if-let y (i8_try_from_u64 x))
      (pulley_xconst8 y))

;; If a value can fit into 16 bits, then prioritize that.
(rule 2 (imm (ty_int _) x)
      (if-let y (i16_try_from_u64 x))
      (pulley_xconst16 y))

;; If a value can fit into 32 bits, then prioritize that.
(rule 1 (imm (ty_int _) x)
      (if-let y (i32_try_from_u64 x))
      (pulley_xconst32 y))

;; Base cases for integers.
(rule 0 (imm $I8 x) (pulley_xconst8 (u8_as_i8 (u64_as_u8 x))))
(rule 0 (imm $I16 x) (pulley_xconst16 (u16_as_i16 (u64_as_u16 x))))
(rule 0 (imm $I32 x) (pulley_xconst32 (u64_as_i32 x)))
(rule 0 (imm $I64 x) (pulley_xconst64 (u64_as_i64 x)))

;; Base cases for floats.
(rule 0 (imm $F32 c) (gen_bitcast (imm $I32 c) $I32 $F32))
(rule 0 (imm $F64 c) (gen_bitcast (imm $I64 c) $I64 $F64))

;;;; Bitcasts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Bitcast from the first type, into the second type.
(decl gen_bitcast (Reg Type Type) Reg)
(rule (gen_bitcast r $F32 $I32) (pulley_bitcast_float_from_int_32 r))
(rule (gen_bitcast r $F64 $I64) (pulley_bitcast_float_from_int_64 r))
(rule (gen_bitcast r $I32 $F32) (pulley_bitcast_int_from_float_32 r))
(rule (gen_bitcast r $I64 $F64) (pulley_bitcast_int_from_float_64 r))
(rule -1 (gen_bitcast r ty ty) r)

;;;; Instruction Constructors ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(decl pulley_trap (TrapCode) SideEffectNoResult)
(rule (pulley_trap code)
      (SideEffectNoResult.Inst (MInst.Trap code)))

(decl pulley_get_sp () XReg)
(rule (pulley_get_sp)
      (let ((reg WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.GetSp reg))))
        reg))

(decl pulley_xconst8 (i8) XReg)
(rule (pulley_xconst8 x)
      (let ((reg WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xconst8 reg x))))
        reg))

(decl pulley_xconst16 (i16) XReg)
(rule (pulley_xconst16 x)
      (let ((reg WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xconst16 reg x))))
        reg))

(decl pulley_xconst32 (i32) XReg)
(rule (pulley_xconst32 x)
      (let ((reg WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xconst32 reg x))))
        reg))

(decl pulley_xconst64 (i64) XReg)
(rule (pulley_xconst64 x)
      (let ((reg WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xconst64 reg x))))
        reg))

(decl pulley_jump (MachLabel) SideEffectNoResult)
(rule (pulley_jump label)
      (SideEffectNoResult.Inst (MInst.Jump label)))

(decl pulley_br_if (XReg MachLabel MachLabel) SideEffectNoResult)
(rule (pulley_br_if c taken not_taken)
      (SideEffectNoResult.Inst (MInst.BrIf c taken not_taken)))

(decl pulley_br_if_xeq32 (XReg XReg MachLabel MachLabel) SideEffectNoResult)
(rule (pulley_br_if_xeq32 a b taken not_taken)
      (SideEffectNoResult.Inst (MInst.BrIfXeq32 a b taken not_taken)))

(decl pulley_br_if_xneq32 (XReg XReg MachLabel MachLabel) SideEffectNoResult)
(rule (pulley_br_if_xneq32 a b taken not_taken)
      (SideEffectNoResult.Inst (MInst.BrIfXneq32 a b taken not_taken)))

(decl pulley_br_if_xslt32 (XReg XReg MachLabel MachLabel) SideEffectNoResult)
(rule (pulley_br_if_xslt32 a b taken not_taken)
      (SideEffectNoResult.Inst (MInst.BrIfXslt32 a b taken not_taken)))

(decl pulley_br_if_xslteq32 (XReg XReg MachLabel MachLabel) SideEffectNoResult)
(rule (pulley_br_if_xslteq32 a b taken not_taken)
      (SideEffectNoResult.Inst (MInst.BrIfXslteq32 a b taken not_taken)))

(decl pulley_br_if_xult32 (XReg XReg MachLabel MachLabel) SideEffectNoResult)
(rule (pulley_br_if_xult32 a b taken not_taken)
      (SideEffectNoResult.Inst (MInst.BrIfXult32 a b taken not_taken)))

(decl pulley_br_if_xulteq32 (XReg XReg MachLabel MachLabel) SideEffectNoResult)
(rule (pulley_br_if_xulteq32 a b taken not_taken)
      (SideEffectNoResult.Inst (MInst.BrIfXulteq32 a b taken not_taken)))

(decl pulley_xadd32 (XReg XReg) XReg)
(rule (pulley_xadd32 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xadd32 dst a b))))
        dst))

(decl pulley_xadd64 (XReg XReg) XReg)
(rule (pulley_xadd64 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xadd64 dst a b))))
        dst))

(decl pulley_xeq64 (XReg XReg) XReg)
(rule (pulley_xeq64 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xeq64 dst a b))))
        dst))

(decl pulley_xneq64 (XReg XReg) XReg)
(rule (pulley_xneq64 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xneq64 dst a b))))
        dst))

(decl pulley_xslt64 (XReg XReg) XReg)
(rule (pulley_xslt64 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xslt64 dst a b))))
        dst))

(decl pulley_xslteq64 (XReg XReg) XReg)
(rule (pulley_xslteq64 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xslteq64 dst a b))))
        dst))

(decl pulley_xult64 (XReg XReg) XReg)
(rule (pulley_xult64 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xult64 dst a b))))
        dst))

(decl pulley_xulteq64 (XReg XReg) XReg)
(rule (pulley_xulteq64 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xulteq64 dst a b))))
        dst))

(decl pulley_xeq32 (XReg XReg) XReg)
(rule (pulley_xeq32 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xeq32 dst a b))))
        dst))

(decl pulley_xneq32 (XReg XReg) XReg)
(rule (pulley_xneq32 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xneq32 dst a b))))
        dst))

(decl pulley_xslt32 (XReg XReg) XReg)
(rule (pulley_xslt32 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xslt32 dst a b))))
        dst))

(decl pulley_xslteq32 (XReg XReg) XReg)
(rule (pulley_xslteq32 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xslteq32 dst a b))))
        dst))

(decl pulley_xult32 (XReg XReg) XReg)
(rule (pulley_xult32 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xult32 dst a b))))
        dst))

(decl pulley_xulteq32 (XReg XReg) XReg)
(rule (pulley_xulteq32 a b)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.Xulteq32 dst a b))))
        dst))

(decl pulley_load (Amode Type MemFlags ExtKind) Reg)
(rule (pulley_load amode ty flags ext)
      (let ((dst WritableReg (temp_writable_reg ty))
            (_ Unit (emit (MInst.Load dst amode ty flags ext))))
        dst))

(decl pulley_store (Amode Reg Type MemFlags) SideEffectNoResult)
(rule (pulley_store amode src ty flags)
      (SideEffectNoResult.Inst (MInst.Store amode src ty flags)))

(decl pulley_bitcast_float_from_int_32 (XReg) FReg)
(rule (pulley_bitcast_float_from_int_32 src)
      (let ((dst WritableFReg (temp_writable_freg))
            (_ Unit (emit (MInst.BitcastFloatFromInt32 dst src))))
        dst))

(decl pulley_bitcast_float_from_int_64 (XReg) FReg)
(rule (pulley_bitcast_float_from_int_64 src)
      (let ((dst WritableFReg (temp_writable_freg))
            (_ Unit (emit (MInst.BitcastFloatFromInt64 dst src))))
        dst))

(decl pulley_bitcast_int_from_float_32 (FReg) XReg)
(rule (pulley_bitcast_int_from_float_32 src)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.BitcastIntFromFloat32 dst src))))
        dst))

(decl pulley_bitcast_int_from_float_64 (FReg) XReg)
(rule (pulley_bitcast_int_from_float_64 src)
      (let ((dst WritableXReg (temp_writable_xreg))
            (_ Unit (emit (MInst.BitcastIntFromFloat64 dst src))))
        dst))

;;;; Helpers for Emitting Calls ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(decl gen_call (SigRef ExternalName RelocDistance ValueSlice) InstOutput)
(extern constructor gen_call gen_call)

(decl gen_call_indirect (SigRef Value ValueSlice) InstOutput)
(extern constructor gen_call_indirect gen_call_indirect)