1#![expect(non_snake_case, reason = "DSL style here")]
2
3use crate::cdsl::instructions::{
4 AllInstructions, InstructionBuilder as Inst, InstructionGroupBuilder,
5};
6use crate::cdsl::operands::Operand;
7use crate::cdsl::types::{LaneType, ValueType};
8use crate::cdsl::typevar::{Interval, TypeSetBuilder, TypeVar};
9use crate::shared::formats::Formats;
10use crate::shared::types;
11use crate::shared::{entities::EntityRefs, immediates::Immediates};
12
13#[inline(never)]
14fn define_control_flow(
15 ig: &mut InstructionGroupBuilder,
16 formats: &Formats,
17 imm: &Immediates,
18 entities: &EntityRefs,
19) {
20 ig.push(
21 Inst::new(
22 "jump",
23 r#"
24 Jump.
25
26 Unconditionally jump to a basic block, passing the specified
27 block arguments. The number and types of arguments must match the
28 destination block.
29 "#,
30 &formats.jump,
31 )
32 .operands_in(vec![
33 Operand::new("block_call", &entities.block_call)
34 .with_doc("Destination basic block, with its arguments provided"),
35 ])
36 .branches(),
37 );
38
39 let ScalarTruthy = &TypeVar::new(
40 "ScalarTruthy",
41 "A scalar truthy type",
42 TypeSetBuilder::new().ints(Interval::All).build(),
43 );
44
45 ig.push(
46 Inst::new(
47 "brif",
48 r#"
49 Conditional branch when cond is non-zero.
50
51 Take the ``then`` branch when ``c != 0``, and the ``else`` branch otherwise.
52 "#,
53 &formats.brif,
54 )
55 .operands_in(vec![
56 Operand::new("c", ScalarTruthy).with_doc("Controlling value to test"),
57 Operand::new("block_then", &entities.block_then).with_doc("Then block"),
58 Operand::new("block_else", &entities.block_else).with_doc("Else block"),
59 ])
60 .branches(),
61 );
62
63 {
64 let _i32 = &TypeVar::new(
65 "i32",
66 "A 32 bit scalar integer type",
67 TypeSetBuilder::new().ints(32..32).build(),
68 );
69
70 ig.push(
71 Inst::new(
72 "br_table",
73 r#"
74 Indirect branch via jump table.
75
76 Use ``x`` as an unsigned index into the jump table ``JT``. If a jump
77 table entry is found, branch to the corresponding block. If no entry was
78 found or the index is out-of-bounds, branch to the default block of the
79 table.
80
81 Note that this branch instruction can't pass arguments to the targeted
82 blocks. Split critical edges as needed to work around this.
83
84 Do not confuse this with "tables" in WebAssembly. ``br_table`` is for
85 jump tables with destinations within the current function only -- think
86 of a ``match`` in Rust or a ``switch`` in C. If you want to call a
87 function in a dynamic library, that will typically use
88 ``call_indirect``.
89 "#,
90 &formats.branch_table,
91 )
92 .operands_in(vec![
93 Operand::new("x", _i32).with_doc("i32 index into jump table"),
94 Operand::new("JT", &entities.jump_table),
95 ])
96 .branches(),
97 );
98 }
99
100 let iAddr = &TypeVar::new(
101 "iAddr",
102 "An integer address type",
103 TypeSetBuilder::new().ints(32..64).build(),
104 );
105
106 ig.push(
107 Inst::new(
108 "debugtrap",
109 r#"
110 Encodes an assembly debug trap.
111 "#,
112 &formats.nullary,
113 )
114 .other_side_effects()
115 .can_load()
116 .can_store(),
117 );
118
119 ig.push(
120 Inst::new(
121 "trap",
122 r#"
123 Terminate execution unconditionally.
124 "#,
125 &formats.trap,
126 )
127 .operands_in(vec![Operand::new("code", &imm.trapcode)])
128 .can_trap()
129 .terminates_block(),
130 );
131
132 ig.push(
133 Inst::new(
134 "trapz",
135 r#"
136 Trap when zero.
137
138 if ``c`` is non-zero, execution continues at the following instruction.
139 "#,
140 &formats.cond_trap,
141 )
142 .operands_in(vec![
143 Operand::new("c", ScalarTruthy).with_doc("Controlling value to test"),
144 Operand::new("code", &imm.trapcode),
145 ])
146 .can_trap()
147 .side_effects_idempotent(),
153 );
154
155 ig.push(
156 Inst::new(
157 "trapnz",
158 r#"
159 Trap when non-zero.
160
161 If ``c`` is zero, execution continues at the following instruction.
162 "#,
163 &formats.cond_trap,
164 )
165 .operands_in(vec![
166 Operand::new("c", ScalarTruthy).with_doc("Controlling value to test"),
167 Operand::new("code", &imm.trapcode),
168 ])
169 .can_trap()
170 .side_effects_idempotent(),
172 );
173
174 ig.push(
175 Inst::new(
176 "return",
177 r#"
178 Return from the function.
179
180 Unconditionally transfer control to the calling function, passing the
181 provided return values. The list of return values must match the
182 function signature's return types.
183 "#,
184 &formats.multiary,
185 )
186 .operands_in(vec![
187 Operand::new("rvals", &entities.varargs).with_doc("return values"),
188 ])
189 .returns(),
190 );
191
192 ig.push(
193 Inst::new(
194 "call",
195 r#"
196 Direct function call.
197
198 Call a function which has been declared in the preamble. The argument
199 types must match the function's signature.
200 "#,
201 &formats.call,
202 )
203 .operands_in(vec![
204 Operand::new("FN", &entities.func_ref)
205 .with_doc("function to call, declared by `function`"),
206 Operand::new("args", &entities.varargs).with_doc("call arguments"),
207 ])
208 .operands_out(vec![
209 Operand::new("rvals", &entities.varargs).with_doc("return values"),
210 ])
211 .call(),
212 );
213
214 ig.push(
215 Inst::new(
216 "call_indirect",
217 r#"
218 Indirect function call.
219
220 Call the function pointed to by `callee` with the given arguments. The
221 called function must match the specified signature.
222
223 Note that this is different from WebAssembly's ``call_indirect``; the
224 callee is a native address, rather than a table index. For WebAssembly,
225 `table_addr` and `load` are used to obtain a native address
226 from a table.
227 "#,
228 &formats.call_indirect,
229 )
230 .operands_in(vec![
231 Operand::new("SIG", &entities.sig_ref).with_doc("function signature"),
232 Operand::new("callee", iAddr).with_doc("address of function to call"),
233 Operand::new("args", &entities.varargs).with_doc("call arguments"),
234 ])
235 .operands_out(vec![
236 Operand::new("rvals", &entities.varargs).with_doc("return values"),
237 ])
238 .call(),
239 );
240
241 ig.push(
242 Inst::new(
243 "return_call",
244 r#"
245 Direct tail call.
246
247 Tail call a function which has been declared in the preamble. The
248 argument types must match the function's signature, the caller and
249 callee calling conventions must be the same, and must be a calling
250 convention that supports tail calls.
251
252 This instruction is a block terminator.
253 "#,
254 &formats.call,
255 )
256 .operands_in(vec![
257 Operand::new("FN", &entities.func_ref)
258 .with_doc("function to call, declared by `function`"),
259 Operand::new("args", &entities.varargs).with_doc("call arguments"),
260 ])
261 .returns()
262 .call(),
263 );
264
265 ig.push(
266 Inst::new(
267 "return_call_indirect",
268 r#"
269 Indirect tail call.
270
271 Call the function pointed to by `callee` with the given arguments. The
272 argument types must match the function's signature, the caller and
273 callee calling conventions must be the same, and must be a calling
274 convention that supports tail calls.
275
276 This instruction is a block terminator.
277
278 Note that this is different from WebAssembly's ``tail_call_indirect``;
279 the callee is a native address, rather than a table index. For
280 WebAssembly, `table_addr` and `load` are used to obtain a native address
281 from a table.
282 "#,
283 &formats.call_indirect,
284 )
285 .operands_in(vec![
286 Operand::new("SIG", &entities.sig_ref).with_doc("function signature"),
287 Operand::new("callee", iAddr).with_doc("address of function to call"),
288 Operand::new("args", &entities.varargs).with_doc("call arguments"),
289 ])
290 .returns()
291 .call(),
292 );
293
294 ig.push(
295 Inst::new(
296 "func_addr",
297 r#"
298 Get the address of a function.
299
300 Compute the absolute address of a function declared in the preamble.
301 The returned address can be used as a ``callee`` argument to
302 `call_indirect`. This is also a method for calling functions that
303 are too far away to be addressable by a direct `call`
304 instruction.
305 "#,
306 &formats.func_addr,
307 )
308 .operands_in(vec![
309 Operand::new("FN", &entities.func_ref)
310 .with_doc("function to call, declared by `function`"),
311 ])
312 .operands_out(vec![Operand::new("addr", iAddr)]),
313 );
314
315 ig.push(
316 Inst::new(
317 "try_call",
318 r#"
319 Call a function, catching the specified exceptions.
320
321 Call the function pointed to by `callee` with the given arguments. On
322 normal return, branch to the first target, with function returns
323 available as `retN` block arguments. On exceptional return,
324 look up the thrown exception tag in the provided exception table;
325 if the tag matches one of the targets, branch to the matching
326 target with the exception payloads available as `exnN` block arguments.
327 If no tag matches, then propagate the exception up the stack.
328
329 It is the Cranelift embedder's responsibility to define the meaning
330 of tags: they are accepted by this instruction and passed through
331 to unwind metadata tables in Cranelift's output. Actual unwinding is
332 outside the purview of the core Cranelift compiler.
333
334 Payload values on exception are passed in fixed register(s) that are
335 defined by the platform and ABI. See the documentation on `CallConv`
336 for details.
337 "#,
338 &formats.try_call,
339 )
340 .operands_in(vec![
341 Operand::new("callee", &entities.func_ref)
342 .with_doc("function to call, declared by `function`"),
343 Operand::new("args", &entities.varargs).with_doc("call arguments"),
344 Operand::new("ET", &entities.exception_table).with_doc("exception table"),
345 ])
346 .call()
347 .branches(),
348 );
349
350 ig.push(
351 Inst::new(
352 "try_call_indirect",
353 r#"
354 Call a function, catching the specified exceptions.
355
356 Call the function pointed to by `callee` with the given arguments. On
357 normal return, branch to the first target, with function returns
358 available as `retN` block arguments. On exceptional return,
359 look up the thrown exception tag in the provided exception table;
360 if the tag matches one of the targets, branch to the matching
361 target with the exception payloads available as `exnN` block arguments.
362 If no tag matches, then propagate the exception up the stack.
363
364 It is the Cranelift embedder's responsibility to define the meaning
365 of tags: they are accepted by this instruction and passed through
366 to unwind metadata tables in Cranelift's output. Actual unwinding is
367 outside the purview of the core Cranelift compiler.
368
369 Payload values on exception are passed in fixed register(s) that are
370 defined by the platform and ABI. See the documentation on `CallConv`
371 for details.
372 "#,
373 &formats.try_call_indirect,
374 )
375 .operands_in(vec![
376 Operand::new("callee", iAddr).with_doc("address of function to call"),
377 Operand::new("args", &entities.varargs).with_doc("call arguments"),
378 Operand::new("ET", &entities.exception_table).with_doc("exception table"),
379 ])
380 .call()
381 .branches(),
382 );
383}
384
385#[inline(never)]
386fn define_simd_lane_access(
387 ig: &mut InstructionGroupBuilder,
388 formats: &Formats,
389 imm: &Immediates,
390 _: &EntityRefs,
391) {
392 let TxN = &TypeVar::new(
393 "TxN",
394 "A SIMD vector type",
395 TypeSetBuilder::new()
396 .ints(Interval::All)
397 .floats(Interval::All)
398 .simd_lanes(Interval::All)
399 .dynamic_simd_lanes(Interval::All)
400 .includes_scalars(false)
401 .build(),
402 );
403
404 ig.push(
405 Inst::new(
406 "splat",
407 r#"
408 Vector splat.
409
410 Return a vector whose lanes are all ``x``.
411 "#,
412 &formats.unary,
413 )
414 .operands_in(vec![
415 Operand::new("x", &TxN.lane_of()).with_doc("Value to splat to all lanes"),
416 ])
417 .operands_out(vec![Operand::new("a", TxN)]),
418 );
419
420 let I8x16 = &TypeVar::new(
421 "I8x16",
422 "A SIMD vector type consisting of 16 lanes of 8-bit integers",
423 TypeSetBuilder::new()
424 .ints(8..8)
425 .simd_lanes(16..16)
426 .includes_scalars(false)
427 .build(),
428 );
429
430 ig.push(
431 Inst::new(
432 "swizzle",
433 r#"
434 Vector swizzle.
435
436 Returns a new vector with byte-width lanes selected from the lanes of the first input
437 vector ``x`` specified in the second input vector ``s``. The indices ``i`` in range
438 ``[0, 15]`` select the ``i``-th element of ``x``. For indices outside of the range the
439 resulting lane is 0. Note that this operates on byte-width lanes.
440 "#,
441 &formats.binary,
442 )
443 .operands_in(vec![
444 Operand::new("x", I8x16).with_doc("Vector to modify by re-arranging lanes"),
445 Operand::new("y", I8x16).with_doc("Mask for re-arranging lanes"),
446 ])
447 .operands_out(vec![Operand::new("a", I8x16)]),
448 );
449
450 ig.push(
451 Inst::new(
452 "x86_pshufb",
453 r#"
454 A vector swizzle lookalike which has the semantics of `pshufb` on x64.
455
456 This instruction will permute the 8-bit lanes of `x` with the indices
457 specified in `y`. Each lane in the mask, `y`, uses the bottom four
458 bits for selecting the lane from `x` unless the most significant bit
459 is set, in which case the lane is zeroed. The output vector will have
460 the following contents when the element of `y` is in these ranges:
461
462 * `[0, 127]` -> `x[y[i] % 16]`
463 * `[128, 255]` -> 0
464 "#,
465 &formats.binary,
466 )
467 .operands_in(vec![
468 Operand::new("x", I8x16).with_doc("Vector to modify by re-arranging lanes"),
469 Operand::new("y", I8x16).with_doc("Mask for re-arranging lanes"),
470 ])
471 .operands_out(vec![Operand::new("a", I8x16)]),
472 );
473
474 ig.push(
475 Inst::new(
476 "insertlane",
477 r#"
478 Insert ``y`` as lane ``Idx`` in x.
479
480 The lane index, ``Idx``, is an immediate value, not an SSA value. It
481 must indicate a valid lane index for the type of ``x``.
482 "#,
483 &formats.ternary_imm8,
484 )
485 .operands_in(vec![
486 Operand::new("x", TxN).with_doc("The vector to modify"),
487 Operand::new("y", &TxN.lane_of()).with_doc("New lane value"),
488 Operand::new("Idx", &imm.uimm8).with_doc("Lane index"),
489 ])
490 .operands_out(vec![Operand::new("a", TxN)]),
491 );
492
493 ig.push(
494 Inst::new(
495 "extractlane",
496 r#"
497 Extract lane ``Idx`` from ``x``.
498
499 The lane index, ``Idx``, is an immediate value, not an SSA value. It
500 must indicate a valid lane index for the type of ``x``. Note that the upper bits of ``a``
501 may or may not be zeroed depending on the ISA but the type system should prevent using
502 ``a`` as anything other than the extracted value.
503 "#,
504 &formats.binary_imm8,
505 )
506 .operands_in(vec![
507 Operand::new("x", TxN),
508 Operand::new("Idx", &imm.uimm8).with_doc("Lane index"),
509 ])
510 .operands_out(vec![Operand::new("a", &TxN.lane_of())]),
511 );
512}
513
514#[inline(never)]
515fn define_simd_arithmetic(
516 ig: &mut InstructionGroupBuilder,
517 formats: &Formats,
518 _: &Immediates,
519 _: &EntityRefs,
520) {
521 let Int = &TypeVar::new(
522 "Int",
523 "A scalar or vector integer type",
524 TypeSetBuilder::new()
525 .ints(Interval::All)
526 .simd_lanes(Interval::All)
527 .build(),
528 );
529
530 ig.push(
531 Inst::new(
532 "smin",
533 r#"
534 Signed integer minimum.
535 "#,
536 &formats.binary,
537 )
538 .operands_in(vec![Operand::new("x", Int), Operand::new("y", Int)])
539 .operands_out(vec![Operand::new("a", Int)]),
540 );
541
542 ig.push(
543 Inst::new(
544 "umin",
545 r#"
546 Unsigned integer minimum.
547 "#,
548 &formats.binary,
549 )
550 .operands_in(vec![Operand::new("x", Int), Operand::new("y", Int)])
551 .operands_out(vec![Operand::new("a", Int)]),
552 );
553
554 ig.push(
555 Inst::new(
556 "smax",
557 r#"
558 Signed integer maximum.
559 "#,
560 &formats.binary,
561 )
562 .operands_in(vec![Operand::new("x", Int), Operand::new("y", Int)])
563 .operands_out(vec![Operand::new("a", Int)]),
564 );
565
566 ig.push(
567 Inst::new(
568 "umax",
569 r#"
570 Unsigned integer maximum.
571 "#,
572 &formats.binary,
573 )
574 .operands_in(vec![Operand::new("x", Int), Operand::new("y", Int)])
575 .operands_out(vec![Operand::new("a", Int)]),
576 );
577
578 let IxN = &TypeVar::new(
579 "IxN",
580 "A SIMD vector type containing integers",
581 TypeSetBuilder::new()
582 .ints(Interval::All)
583 .simd_lanes(Interval::All)
584 .includes_scalars(false)
585 .build(),
586 );
587
588 ig.push(
589 Inst::new(
590 "avg_round",
591 r#"
592 Unsigned average with rounding: `a := (x + y + 1) // 2`
593
594 The addition does not lose any information (such as from overflow).
595 "#,
596 &formats.binary,
597 )
598 .operands_in(vec![Operand::new("x", IxN), Operand::new("y", IxN)])
599 .operands_out(vec![Operand::new("a", IxN)]),
600 );
601
602 ig.push(
603 Inst::new(
604 "uadd_sat",
605 r#"
606 Add with unsigned saturation.
607
608 This is similar to `iadd` but the operands are interpreted as unsigned integers and their
609 summed result, instead of wrapping, will be saturated to the highest unsigned integer for
610 the controlling type (e.g. `0xFF` for i8).
611 "#,
612 &formats.binary,
613 )
614 .operands_in(vec![Operand::new("x", IxN), Operand::new("y", IxN)])
615 .operands_out(vec![Operand::new("a", IxN)]),
616 );
617
618 ig.push(
619 Inst::new(
620 "sadd_sat",
621 r#"
622 Add with signed saturation.
623
624 This is similar to `iadd` but the operands are interpreted as signed integers and their
625 summed result, instead of wrapping, will be saturated to the lowest or highest
626 signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8). For example,
627 since an `sadd_sat.i8` of `0x70` and `0x70` is greater than `0x7F`, the result will be
628 clamped to `0x7F`.
629 "#,
630 &formats.binary,
631 )
632 .operands_in(vec![Operand::new("x", IxN), Operand::new("y", IxN)])
633 .operands_out(vec![Operand::new("a", IxN)]),
634 );
635
636 ig.push(
637 Inst::new(
638 "usub_sat",
639 r#"
640 Subtract with unsigned saturation.
641
642 This is similar to `isub` but the operands are interpreted as unsigned integers and their
643 difference, instead of wrapping, will be saturated to the lowest unsigned integer for
644 the controlling type (e.g. `0x00` for i8).
645 "#,
646 &formats.binary,
647 )
648 .operands_in(vec![Operand::new("x", IxN), Operand::new("y", IxN)])
649 .operands_out(vec![Operand::new("a", IxN)]),
650 );
651
652 ig.push(
653 Inst::new(
654 "ssub_sat",
655 r#"
656 Subtract with signed saturation.
657
658 This is similar to `isub` but the operands are interpreted as signed integers and their
659 difference, instead of wrapping, will be saturated to the lowest or highest
660 signed integer for the controlling type (e.g. `0x80` or `0x7F` for i8).
661 "#,
662 &formats.binary,
663 )
664 .operands_in(vec![Operand::new("x", IxN), Operand::new("y", IxN)])
665 .operands_out(vec![Operand::new("a", IxN)]),
666 );
667}
668
669pub(crate) fn define(
670 all_instructions: &mut AllInstructions,
671 formats: &Formats,
672 imm: &Immediates,
673 entities: &EntityRefs,
674) {
675 let mut ig = InstructionGroupBuilder::new(all_instructions);
676
677 define_control_flow(&mut ig, formats, imm, entities);
678 define_simd_lane_access(&mut ig, formats, imm, entities);
679 define_simd_arithmetic(&mut ig, formats, imm, entities);
680
681 let i8: &TypeVar = &ValueType::from(LaneType::from(types::Int::I8)).into();
683 let f16_: &TypeVar = &ValueType::from(LaneType::from(types::Float::F16)).into();
684 let f32_: &TypeVar = &ValueType::from(LaneType::from(types::Float::F32)).into();
685 let f64_: &TypeVar = &ValueType::from(LaneType::from(types::Float::F64)).into();
686 let f128_: &TypeVar = &ValueType::from(LaneType::from(types::Float::F128)).into();
687
688 let Int = &TypeVar::new(
690 "Int",
691 "A scalar or vector integer type",
692 TypeSetBuilder::new()
693 .ints(Interval::All)
694 .simd_lanes(Interval::All)
695 .dynamic_simd_lanes(Interval::All)
696 .build(),
697 );
698
699 let NarrowInt = &TypeVar::new(
700 "NarrowInt",
701 "An integer type of width up to `i64`",
702 TypeSetBuilder::new().ints(8..64).build(),
703 );
704
705 let ScalarTruthy = &TypeVar::new(
706 "ScalarTruthy",
707 "A scalar truthy type",
708 TypeSetBuilder::new().ints(Interval::All).build(),
709 );
710
711 let iB = &TypeVar::new(
712 "iB",
713 "A scalar integer type",
714 TypeSetBuilder::new().ints(Interval::All).build(),
715 );
716
717 let iSwappable = &TypeVar::new(
718 "iSwappable",
719 "A multi byte scalar integer type",
720 TypeSetBuilder::new().ints(16..128).build(),
721 );
722
723 let iAddr = &TypeVar::new(
724 "iAddr",
725 "An integer address type",
726 TypeSetBuilder::new().ints(32..64).build(),
727 );
728
729 let TxN = &TypeVar::new(
730 "TxN",
731 "A SIMD vector type",
732 TypeSetBuilder::new()
733 .ints(Interval::All)
734 .floats(Interval::All)
735 .simd_lanes(Interval::All)
736 .includes_scalars(false)
737 .build(),
738 );
739 let Any = &TypeVar::new(
740 "Any",
741 "Any integer, float, or reference scalar or vector type",
742 TypeSetBuilder::new()
743 .ints(Interval::All)
744 .floats(Interval::All)
745 .simd_lanes(Interval::All)
746 .includes_scalars(true)
747 .build(),
748 );
749
750 let Mem = &TypeVar::new(
751 "Mem",
752 "Any type that can be stored in memory",
753 TypeSetBuilder::new()
754 .ints(Interval::All)
755 .floats(Interval::All)
756 .simd_lanes(Interval::All)
757 .dynamic_simd_lanes(Interval::All)
758 .build(),
759 );
760
761 let MemTo = &TypeVar::copy_from(Mem, "MemTo".to_string());
762
763 ig.push(
764 Inst::new(
765 "load",
766 r#"
767 Load from memory at ``p + Offset``.
768
769 This is a polymorphic instruction that can load any value type which
770 has a memory representation.
771 "#,
772 &formats.load,
773 )
774 .operands_in(vec![
775 Operand::new("MemFlags", &imm.memflags),
776 Operand::new("p", iAddr),
777 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
778 ])
779 .operands_out(vec![Operand::new("a", Mem).with_doc("Value loaded")])
780 .can_load(),
781 );
782
783 ig.push(
784 Inst::new(
785 "store",
786 r#"
787 Store ``x`` to memory at ``p + Offset``.
788
789 This is a polymorphic instruction that can store any value type with a
790 memory representation.
791 "#,
792 &formats.store,
793 )
794 .operands_in(vec![
795 Operand::new("MemFlags", &imm.memflags),
796 Operand::new("x", Mem).with_doc("Value to be stored"),
797 Operand::new("p", iAddr),
798 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
799 ])
800 .can_store(),
801 );
802
803 let iExt8 = &TypeVar::new(
804 "iExt8",
805 "An integer type with more than 8 bits",
806 TypeSetBuilder::new().ints(16..64).build(),
807 );
808
809 ig.push(
810 Inst::new(
811 "uload8",
812 r#"
813 Load 8 bits from memory at ``p + Offset`` and zero-extend.
814
815 This is equivalent to ``load.i8`` followed by ``uextend``.
816 "#,
817 &formats.load,
818 )
819 .operands_in(vec![
820 Operand::new("MemFlags", &imm.memflags),
821 Operand::new("p", iAddr),
822 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
823 ])
824 .operands_out(vec![Operand::new("a", iExt8)])
825 .can_load(),
826 );
827
828 ig.push(
829 Inst::new(
830 "sload8",
831 r#"
832 Load 8 bits from memory at ``p + Offset`` and sign-extend.
833
834 This is equivalent to ``load.i8`` followed by ``sextend``.
835 "#,
836 &formats.load,
837 )
838 .operands_in(vec![
839 Operand::new("MemFlags", &imm.memflags),
840 Operand::new("p", iAddr),
841 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
842 ])
843 .operands_out(vec![Operand::new("a", iExt8)])
844 .can_load(),
845 );
846
847 ig.push(
848 Inst::new(
849 "istore8",
850 r#"
851 Store the low 8 bits of ``x`` to memory at ``p + Offset``.
852
853 This is equivalent to ``ireduce.i8`` followed by ``store.i8``.
854 "#,
855 &formats.store,
856 )
857 .operands_in(vec![
858 Operand::new("MemFlags", &imm.memflags),
859 Operand::new("x", iExt8),
860 Operand::new("p", iAddr),
861 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
862 ])
863 .can_store(),
864 );
865
866 let iExt16 = &TypeVar::new(
867 "iExt16",
868 "An integer type with more than 16 bits",
869 TypeSetBuilder::new().ints(32..64).build(),
870 );
871
872 ig.push(
873 Inst::new(
874 "uload16",
875 r#"
876 Load 16 bits from memory at ``p + Offset`` and zero-extend.
877
878 This is equivalent to ``load.i16`` followed by ``uextend``.
879 "#,
880 &formats.load,
881 )
882 .operands_in(vec![
883 Operand::new("MemFlags", &imm.memflags),
884 Operand::new("p", iAddr),
885 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
886 ])
887 .operands_out(vec![Operand::new("a", iExt16)])
888 .can_load(),
889 );
890
891 ig.push(
892 Inst::new(
893 "sload16",
894 r#"
895 Load 16 bits from memory at ``p + Offset`` and sign-extend.
896
897 This is equivalent to ``load.i16`` followed by ``sextend``.
898 "#,
899 &formats.load,
900 )
901 .operands_in(vec![
902 Operand::new("MemFlags", &imm.memflags),
903 Operand::new("p", iAddr),
904 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
905 ])
906 .operands_out(vec![Operand::new("a", iExt16)])
907 .can_load(),
908 );
909
910 ig.push(
911 Inst::new(
912 "istore16",
913 r#"
914 Store the low 16 bits of ``x`` to memory at ``p + Offset``.
915
916 This is equivalent to ``ireduce.i16`` followed by ``store.i16``.
917 "#,
918 &formats.store,
919 )
920 .operands_in(vec![
921 Operand::new("MemFlags", &imm.memflags),
922 Operand::new("x", iExt16),
923 Operand::new("p", iAddr),
924 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
925 ])
926 .can_store(),
927 );
928
929 let iExt32 = &TypeVar::new(
930 "iExt32",
931 "An integer type with more than 32 bits",
932 TypeSetBuilder::new().ints(64..64).build(),
933 );
934
935 ig.push(
936 Inst::new(
937 "uload32",
938 r#"
939 Load 32 bits from memory at ``p + Offset`` and zero-extend.
940
941 This is equivalent to ``load.i32`` followed by ``uextend``.
942 "#,
943 &formats.load,
944 )
945 .operands_in(vec![
946 Operand::new("MemFlags", &imm.memflags),
947 Operand::new("p", iAddr),
948 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
949 ])
950 .operands_out(vec![Operand::new("a", iExt32)])
951 .can_load(),
952 );
953
954 ig.push(
955 Inst::new(
956 "sload32",
957 r#"
958 Load 32 bits from memory at ``p + Offset`` and sign-extend.
959
960 This is equivalent to ``load.i32`` followed by ``sextend``.
961 "#,
962 &formats.load,
963 )
964 .operands_in(vec![
965 Operand::new("MemFlags", &imm.memflags),
966 Operand::new("p", iAddr),
967 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
968 ])
969 .operands_out(vec![Operand::new("a", iExt32)])
970 .can_load(),
971 );
972
973 ig.push(
974 Inst::new(
975 "istore32",
976 r#"
977 Store the low 32 bits of ``x`` to memory at ``p + Offset``.
978
979 This is equivalent to ``ireduce.i32`` followed by ``store.i32``.
980 "#,
981 &formats.store,
982 )
983 .operands_in(vec![
984 Operand::new("MemFlags", &imm.memflags),
985 Operand::new("x", iExt32),
986 Operand::new("p", iAddr),
987 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
988 ])
989 .can_store(),
990 );
991 ig.push(
992 Inst::new(
993 "stack_switch",
994 r#"
995 Suspends execution of the current stack and resumes execution of another
996 one.
997
998 The target stack to switch to is identified by the data stored at
999 ``load_context_ptr``. Before switching, this instruction stores
1000 analogous information about the
1001 current (i.e., original) stack at ``store_context_ptr``, to
1002 enabled switching back to the original stack at a later point.
1003
1004 The size, alignment and layout of the information stored at
1005 ``load_context_ptr`` and ``store_context_ptr`` is platform-dependent.
1006 The instruction assumes that ``load_context_ptr`` and
1007 ``store_context_ptr`` are valid pointers to memory with said layout and
1008 alignment, and does not perform any checks on these pointers or the data
1009 stored there.
1010
1011 The instruction is experimental and only supported on x64 Linux at the
1012 moment.
1013
1014 When switching from a stack A to a stack B, one of the following cases
1015 must apply:
1016 1. Stack B was previously suspended using a ``stack_switch`` instruction.
1017 2. Stack B is a newly initialized stack. The necessary initialization is
1018 platform-dependent and will generally involve running some kind of
1019 trampoline to start execution of a function on the new stack.
1020
1021 In both cases, the ``in_payload`` argument of the ``stack_switch``
1022 instruction executed on A is passed to stack B. In the first case above,
1023 it will be the result value of the earlier ``stack_switch`` instruction
1024 executed on stack B. In the second case, the value will be accessible to
1025 the trampoline in a platform-dependent register.
1026
1027 The pointers ``load_context_ptr`` and ``store_context_ptr`` are allowed
1028 to be equal; the instruction ensures that all data is loaded from the
1029 former before writing to the latter.
1030
1031 Stack switching is one-shot in the sense that each ``stack_switch``
1032 operation effectively consumes the context identified by
1033 ``load_context_ptr``. In other words, performing two ``stack_switches``
1034 using the same ``load_context_ptr`` causes undefined behavior, unless
1035 the context at ``load_context_ptr`` is overwritten by another
1036 `stack_switch` in between.
1037 "#,
1038 &formats.ternary,
1039 )
1040 .operands_in(vec![
1041 Operand::new("store_context_ptr", iAddr),
1042 Operand::new("load_context_ptr", iAddr),
1043 Operand::new("in_payload0", iAddr),
1044 ])
1045 .operands_out(vec![Operand::new("out_payload0", iAddr)])
1046 .other_side_effects()
1047 .can_load()
1048 .can_store()
1049 .call(),
1050 );
1051
1052 let I16x8 = &TypeVar::new(
1053 "I16x8",
1054 "A SIMD vector with exactly 8 lanes of 16-bit values",
1055 TypeSetBuilder::new()
1056 .ints(16..16)
1057 .simd_lanes(8..8)
1058 .includes_scalars(false)
1059 .build(),
1060 );
1061
1062 ig.push(
1063 Inst::new(
1064 "uload8x8",
1065 r#"
1066 Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i16x8
1067 vector.
1068 "#,
1069 &formats.load,
1070 )
1071 .operands_in(vec![
1072 Operand::new("MemFlags", &imm.memflags),
1073 Operand::new("p", iAddr),
1074 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
1075 ])
1076 .operands_out(vec![Operand::new("a", I16x8).with_doc("Value loaded")])
1077 .can_load(),
1078 );
1079
1080 ig.push(
1081 Inst::new(
1082 "sload8x8",
1083 r#"
1084 Load an 8x8 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i16x8
1085 vector.
1086 "#,
1087 &formats.load,
1088 )
1089 .operands_in(vec![
1090 Operand::new("MemFlags", &imm.memflags),
1091 Operand::new("p", iAddr),
1092 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
1093 ])
1094 .operands_out(vec![Operand::new("a", I16x8).with_doc("Value loaded")])
1095 .can_load(),
1096 );
1097
1098 let I32x4 = &TypeVar::new(
1099 "I32x4",
1100 "A SIMD vector with exactly 4 lanes of 32-bit values",
1101 TypeSetBuilder::new()
1102 .ints(32..32)
1103 .simd_lanes(4..4)
1104 .includes_scalars(false)
1105 .build(),
1106 );
1107
1108 ig.push(
1109 Inst::new(
1110 "uload16x4",
1111 r#"
1112 Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i32x4
1113 vector.
1114 "#,
1115 &formats.load,
1116 )
1117 .operands_in(vec![
1118 Operand::new("MemFlags", &imm.memflags),
1119 Operand::new("p", iAddr),
1120 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
1121 ])
1122 .operands_out(vec![Operand::new("a", I32x4).with_doc("Value loaded")])
1123 .can_load(),
1124 );
1125
1126 ig.push(
1127 Inst::new(
1128 "sload16x4",
1129 r#"
1130 Load a 16x4 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i32x4
1131 vector.
1132 "#,
1133 &formats.load,
1134 )
1135 .operands_in(vec![
1136 Operand::new("MemFlags", &imm.memflags),
1137 Operand::new("p", iAddr),
1138 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
1139 ])
1140 .operands_out(vec![Operand::new("a", I32x4).with_doc("Value loaded")])
1141 .can_load(),
1142 );
1143
1144 let I64x2 = &TypeVar::new(
1145 "I64x2",
1146 "A SIMD vector with exactly 2 lanes of 64-bit values",
1147 TypeSetBuilder::new()
1148 .ints(64..64)
1149 .simd_lanes(2..2)
1150 .includes_scalars(false)
1151 .build(),
1152 );
1153
1154 ig.push(
1155 Inst::new(
1156 "uload32x2",
1157 r#"
1158 Load an 32x2 vector (64 bits) from memory at ``p + Offset`` and zero-extend into an i64x2
1159 vector.
1160 "#,
1161 &formats.load,
1162 )
1163 .operands_in(vec![
1164 Operand::new("MemFlags", &imm.memflags),
1165 Operand::new("p", iAddr),
1166 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
1167 ])
1168 .operands_out(vec![Operand::new("a", I64x2).with_doc("Value loaded")])
1169 .can_load(),
1170 );
1171
1172 ig.push(
1173 Inst::new(
1174 "sload32x2",
1175 r#"
1176 Load a 32x2 vector (64 bits) from memory at ``p + Offset`` and sign-extend into an i64x2
1177 vector.
1178 "#,
1179 &formats.load,
1180 )
1181 .operands_in(vec![
1182 Operand::new("MemFlags", &imm.memflags),
1183 Operand::new("p", iAddr),
1184 Operand::new("Offset", &imm.offset32).with_doc("Byte offset from base address"),
1185 ])
1186 .operands_out(vec![Operand::new("a", I64x2).with_doc("Value loaded")])
1187 .can_load(),
1188 );
1189
1190 ig.push(
1191 Inst::new(
1192 "stack_addr",
1193 r#"
1194 Get the address of a stack slot.
1195
1196 Compute the absolute address of a byte in a stack slot. The offset must
1197 refer to a byte inside the stack slot:
1198 `0 <= Offset < sizeof(SS)`.
1199 "#,
1200 &formats.stack_addr,
1201 )
1202 .operands_in(vec![
1203 Operand::new("SS", &entities.stack_slot),
1204 Operand::new("Offset", &imm.offset32).with_doc("In-bounds offset into stack slot"),
1205 ])
1206 .operands_out(vec![Operand::new("addr", iAddr)]),
1207 );
1208
1209 ig.push(
1210 Inst::new(
1211 "dynamic_stack_addr",
1212 r#"
1213 Get the address of a dynamic stack slot.
1214
1215 Compute the absolute address of the first byte of a dynamic stack slot.
1216 "#,
1217 &formats.dynamic_stack_addr,
1218 )
1219 .operands_in(vec![Operand::new("DSS", &entities.dynamic_stack_slot)])
1220 .operands_out(vec![Operand::new("addr", iAddr)]),
1221 );
1222
1223 ig.push(
1224 Inst::new(
1225 "symbol_value",
1226 r#"
1227 Compute the value of global GV, which is a symbolic value.
1228 "#,
1229 &formats.unary_global_value,
1230 )
1231 .operands_in(vec![Operand::new("GV", &entities.global_value)])
1232 .operands_out(vec![Operand::new("a", Mem).with_doc("Value loaded")]),
1233 );
1234
1235 ig.push(
1236 Inst::new(
1237 "tls_value",
1238 r#"
1239 Compute the value of global GV, which is a TLS (thread local storage) value.
1240 "#,
1241 &formats.unary_global_value,
1242 )
1243 .operands_in(vec![Operand::new("GV", &entities.global_value)])
1244 .operands_out(vec![Operand::new("a", Mem).with_doc("Value loaded")]),
1245 );
1246
1247 ig.push(
1254 Inst::new(
1255 "get_pinned_reg",
1256 r#"
1257 Gets the content of the pinned register, when it's enabled.
1258 "#,
1259 &formats.nullary,
1260 )
1261 .operands_out(vec![Operand::new("addr", iAddr)])
1262 .other_side_effects(),
1263 );
1264
1265 ig.push(
1266 Inst::new(
1267 "set_pinned_reg",
1268 r#"
1269 Sets the content of the pinned register, when it's enabled.
1270 "#,
1271 &formats.unary,
1272 )
1273 .operands_in(vec![Operand::new("addr", iAddr)])
1274 .other_side_effects(),
1275 );
1276
1277 ig.push(
1278 Inst::new(
1279 "get_frame_pointer",
1280 r#"
1281 Get the address in the frame pointer register.
1282
1283 Usage of this instruction requires setting `preserve_frame_pointers` to `true`.
1284 "#,
1285 &formats.nullary,
1286 )
1287 .operands_out(vec![Operand::new("addr", iAddr)]),
1288 );
1289
1290 ig.push(
1291 Inst::new(
1292 "get_stack_pointer",
1293 r#"
1294 Get the address in the stack pointer register.
1295 "#,
1296 &formats.nullary,
1297 )
1298 .operands_out(vec![Operand::new("addr", iAddr)]),
1299 );
1300
1301 ig.push(
1302 Inst::new(
1303 "get_return_address",
1304 r#"
1305 Get the PC where this function will transfer control to when it returns.
1306
1307 Usage of this instruction requires setting `preserve_frame_pointers` to `true`.
1308 "#,
1309 &formats.nullary,
1310 )
1311 .operands_out(vec![Operand::new("addr", iAddr)]),
1312 );
1313
1314 ig.push(
1315 Inst::new(
1316 "get_exception_handler_address",
1317 r#"
1318 Get the handler PC for the given exceptional edge for an
1319 exception return from the given `try_call`-terminated block.
1320
1321 This instruction provides the PC for the handler resume point,
1322 as defined by the exception-handling aspect of the given
1323 callee ABI, for a return from the given calling block. It can
1324 be used when the exception unwind mechanism requires manual
1325 plumbing for this information which must be set up before the call
1326 itself: for example, if the resume address needs to be stored in
1327 some context structure for a runtime to resume to on error.
1328
1329 The given caller block must end in a `try_call` and the given
1330 exception-handling block must be one of its exceptional
1331 successors in the associated exception-handling table. The
1332 returned PC is *only* valid to resume to when the `try_call`
1333 is on the stack having called the callee; in other words, when
1334 a normal exception unwinder might otherwise resume to that
1335 handler.
1336 "#,
1337 &formats.exception_handler_address,
1338 )
1339 .operands_in(vec![
1340 Operand::new("block", &entities.raw_block),
1341 Operand::new("index", &imm.imm64),
1342 ])
1343 .operands_out(vec![Operand::new("addr", iAddr)]),
1344 );
1345
1346 ig.push(
1347 Inst::new(
1348 "iconst",
1349 r#"
1350 Integer constant.
1351
1352 Create a scalar integer SSA value with an immediate constant value, or
1353 an integer vector where all the lanes have the same value.
1354 "#,
1355 &formats.unary_imm,
1356 )
1357 .operands_in(vec![Operand::new("N", &imm.imm64)])
1358 .operands_out(vec![
1359 Operand::new("a", NarrowInt).with_doc("A constant integer scalar or vector value"),
1360 ]),
1361 );
1362
1363 ig.push(
1364 Inst::new(
1365 "f16const",
1366 r#"
1367 Floating point constant.
1368
1369 Create a `f16` SSA value with an immediate constant value.
1370 "#,
1371 &formats.unary_ieee16,
1372 )
1373 .operands_in(vec![Operand::new("N", &imm.ieee16)])
1374 .operands_out(vec![
1375 Operand::new("a", f16_).with_doc("A constant f16 scalar value"),
1376 ]),
1377 );
1378
1379 ig.push(
1380 Inst::new(
1381 "f32const",
1382 r#"
1383 Floating point constant.
1384
1385 Create a `f32` SSA value with an immediate constant value.
1386 "#,
1387 &formats.unary_ieee32,
1388 )
1389 .operands_in(vec![Operand::new("N", &imm.ieee32)])
1390 .operands_out(vec![
1391 Operand::new("a", f32_).with_doc("A constant f32 scalar value"),
1392 ]),
1393 );
1394
1395 ig.push(
1396 Inst::new(
1397 "f64const",
1398 r#"
1399 Floating point constant.
1400
1401 Create a `f64` SSA value with an immediate constant value.
1402 "#,
1403 &formats.unary_ieee64,
1404 )
1405 .operands_in(vec![Operand::new("N", &imm.ieee64)])
1406 .operands_out(vec![
1407 Operand::new("a", f64_).with_doc("A constant f64 scalar value"),
1408 ]),
1409 );
1410
1411 ig.push(
1412 Inst::new(
1413 "f128const",
1414 r#"
1415 Floating point constant.
1416
1417 Create a `f128` SSA value with an immediate constant value.
1418 "#,
1419 &formats.unary_const,
1420 )
1421 .operands_in(vec![Operand::new("N", &entities.pool_constant)])
1422 .operands_out(vec![
1423 Operand::new("a", f128_).with_doc("A constant f128 scalar value"),
1424 ]),
1425 );
1426
1427 ig.push(
1428 Inst::new(
1429 "vconst",
1430 r#"
1431 SIMD vector constant.
1432
1433 Construct a vector with the given immediate bytes.
1434 "#,
1435 &formats.unary_const,
1436 )
1437 .operands_in(vec![
1438 Operand::new("N", &entities.pool_constant)
1439 .with_doc("The 16 immediate bytes of a 128-bit vector"),
1440 ])
1441 .operands_out(vec![
1442 Operand::new("a", TxN).with_doc("A constant vector value"),
1443 ]),
1444 );
1445
1446 let Tx16 = &TypeVar::new(
1447 "Tx16",
1448 "A SIMD vector with exactly 16 lanes of 8-bit values; eventually this may support other \
1449 lane counts and widths",
1450 TypeSetBuilder::new()
1451 .ints(8..8)
1452 .simd_lanes(16..16)
1453 .includes_scalars(false)
1454 .build(),
1455 );
1456
1457 ig.push(
1458 Inst::new(
1459 "shuffle",
1460 r#"
1461 SIMD vector shuffle.
1462
1463 Shuffle two vectors using the given immediate bytes. For each of the 16 bytes of the
1464 immediate, a value i of 0-15 selects the i-th element of the first vector and a value i of
1465 16-31 selects the (i-16)th element of the second vector. Immediate values outside of the
1466 0-31 range are not valid.
1467 "#,
1468 &formats.shuffle,
1469 )
1470 .operands_in(vec![
1471 Operand::new("a", Tx16).with_doc("A vector value"),
1472 Operand::new("b", Tx16).with_doc("A vector value"),
1473 Operand::new("mask", &entities.uimm128)
1474 .with_doc("The 16 immediate bytes used for selecting the elements to shuffle"),
1475 ])
1476 .operands_out(vec![Operand::new("a", Tx16).with_doc("A vector value")]),
1477 );
1478
1479 ig.push(Inst::new(
1480 "nop",
1481 r#"
1482 Just a dummy instruction.
1483
1484 Note: this doesn't compile to a machine code nop.
1485 "#,
1486 &formats.nullary,
1487 ));
1488
1489 ig.push(
1490 Inst::new(
1491 "select",
1492 r#"
1493 Conditional select.
1494
1495 This instruction selects whole values. Use `bitselect` to choose each
1496 bit according to a mask.
1497 "#,
1498 &formats.ternary,
1499 )
1500 .operands_in(vec![
1501 Operand::new("c", ScalarTruthy).with_doc("Controlling value to test"),
1502 Operand::new("x", Any).with_doc("Value to use when `c` is true"),
1503 Operand::new("y", Any).with_doc("Value to use when `c` is false"),
1504 ])
1505 .operands_out(vec![Operand::new("a", Any)]),
1506 );
1507
1508 ig.push(
1509 Inst::new(
1510 "select_spectre_guard",
1511 r#"
1512 Conditional select intended for Spectre guards.
1513
1514 This operation is semantically equivalent to a select instruction.
1515 However, this instruction prohibits all speculation on the
1516 controlling value when determining which input to use as the result.
1517 As such, it is suitable for use in Spectre guards.
1518
1519 For example, on a target which may speculatively execute branches,
1520 the lowering of this instruction is guaranteed to not conditionally
1521 branch. Instead it will typically lower to a conditional move
1522 instruction. (No Spectre-vulnerable processors are known to perform
1523 value speculation on conditional move instructions.)
1524
1525 Ensure that the instruction you're trying to protect from Spectre
1526 attacks has a data dependency on the result of this instruction.
1527 That prevents an out-of-order CPU from evaluating that instruction
1528 until the result of this one is known, which in turn will be blocked
1529 until the controlling value is known.
1530
1531 Typical usage is to use a bounds-check as the controlling value,
1532 and select between either a null pointer if the bounds-check
1533 fails, or an in-bounds address otherwise, so that dereferencing
1534 the resulting address with a load or store instruction will trap if
1535 the bounds-check failed. When this instruction is used in this way,
1536 any microarchitectural side effects of the memory access will only
1537 occur after the bounds-check finishes, which ensures that no Spectre
1538 vulnerability will exist.
1539
1540 Optimization opportunities for this instruction are limited compared
1541 to a normal select instruction, but it is allowed to be replaced
1542 by other values which are functionally equivalent as long as doing
1543 so does not introduce any new opportunities to speculate on the
1544 controlling value.
1545 "#,
1546 &formats.ternary,
1547 )
1548 .operands_in(vec![
1549 Operand::new("c", ScalarTruthy).with_doc("Controlling value to test"),
1550 Operand::new("x", Any).with_doc("Value to use when `c` is true"),
1551 Operand::new("y", Any).with_doc("Value to use when `c` is false"),
1552 ])
1553 .operands_out(vec![Operand::new("a", Any)]),
1554 );
1555
1556 ig.push(
1557 Inst::new(
1558 "bitselect",
1559 r#"
1560 Conditional select of bits.
1561
1562 For each bit in `c`, this instruction selects the corresponding bit from `x` if the bit
1563 in `c` is 1 and the corresponding bit from `y` if the bit in `c` is 0. See also:
1564 `select`.
1565 "#,
1566 &formats.ternary,
1567 )
1568 .operands_in(vec![
1569 Operand::new("c", Any).with_doc("Controlling value to test"),
1570 Operand::new("x", Any).with_doc("Value to use when `c` is true"),
1571 Operand::new("y", Any).with_doc("Value to use when `c` is false"),
1572 ])
1573 .operands_out(vec![Operand::new("a", Any)]),
1574 );
1575
1576 ig.push(
1577 Inst::new(
1578 "blendv",
1579 r#"
1580 A bitselect-lookalike instruction except with the semantics of
1581 `blendv`-related instructions on x86.
1582
1583 This instruction will use the top bit of each lane in `c`, the condition
1584 mask. If the bit is 1 then the corresponding lane from `x` is chosen.
1585 Otherwise the corresponding lane from `y` is chosen.
1586
1587 "#,
1588 &formats.ternary,
1589 )
1590 .operands_in(vec![
1591 Operand::new("c", Any).with_doc("Controlling value to test"),
1592 Operand::new("x", Any).with_doc("Value to use when `c` is true"),
1593 Operand::new("y", Any).with_doc("Value to use when `c` is false"),
1594 ])
1595 .operands_out(vec![Operand::new("a", Any)]),
1596 );
1597
1598 ig.push(
1599 Inst::new(
1600 "vany_true",
1601 r#"
1602 Reduce a vector to a scalar boolean.
1603
1604 Return a scalar boolean true if any lane in ``a`` is non-zero, false otherwise.
1605 "#,
1606 &formats.unary,
1607 )
1608 .operands_in(vec![Operand::new("a", TxN)])
1609 .operands_out(vec![Operand::new("s", i8)]),
1610 );
1611
1612 ig.push(
1613 Inst::new(
1614 "vall_true",
1615 r#"
1616 Reduce a vector to a scalar boolean.
1617
1618 Return a scalar boolean true if all lanes in ``i`` are non-zero, false otherwise.
1619 "#,
1620 &formats.unary,
1621 )
1622 .operands_in(vec![Operand::new("a", TxN)])
1623 .operands_out(vec![Operand::new("s", i8)]),
1624 );
1625
1626 ig.push(
1627 Inst::new(
1628 "vhigh_bits",
1629 r#"
1630 Reduce a vector to a scalar integer.
1631
1632 Return a scalar integer, consisting of the concatenation of the most significant bit
1633 of each lane of ``a``.
1634 "#,
1635 &formats.unary,
1636 )
1637 .operands_in(vec![Operand::new("a", TxN)])
1638 .operands_out(vec![Operand::new("x", NarrowInt)]),
1639 );
1640
1641 ig.push(
1642 Inst::new(
1643 "icmp",
1644 r#"
1645 Integer comparison.
1646
1647 The condition code determines if the operands are interpreted as signed
1648 or unsigned integers.
1649
1650 | Signed | Unsigned | Condition |
1651 |--------|----------|-----------------------|
1652 | eq | eq | Equal |
1653 | ne | ne | Not equal |
1654 | slt | ult | Less than |
1655 | sge | uge | Greater than or equal |
1656 | sgt | ugt | Greater than |
1657 | sle | ule | Less than or equal |
1658
1659 When this instruction compares integer vectors, it returns a vector of
1660 lane-wise comparisons.
1661
1662 When comparing scalars, the result is:
1663 - `1` if the condition holds.
1664 - `0` if the condition does not hold.
1665
1666 When comparing vectors, the result is:
1667 - `-1` (i.e. all ones) in each lane where the condition holds.
1668 - `0` in each lane where the condition does not hold.
1669 "#,
1670 &formats.int_compare,
1671 )
1672 .operands_in(vec![
1673 Operand::new("Cond", &imm.intcc),
1674 Operand::new("x", Int),
1675 Operand::new("y", Int),
1676 ])
1677 .operands_out(vec![Operand::new("a", &Int.as_truthy())])
1678 .inst_builder_imm_method(true),
1679 );
1680
1681 ig.push(
1682 Inst::new(
1683 "iadd",
1684 r#"
1685 Wrapping integer addition: `a := x + y \pmod{2^B}`.
1686
1687 This instruction does not depend on the signed/unsigned interpretation
1688 of the operands.
1689 "#,
1690 &formats.binary,
1691 )
1692 .operands_in(vec![Operand::new("x", Int), Operand::new("y", Int)])
1693 .operands_out(vec![Operand::new("a", Int)])
1694 .inst_builder_imm_method(true),
1695 );
1696
1697 ig.push(
1698 Inst::new(
1699 "isub",
1700 r#"
1701 Wrapping integer subtraction: `a := x - y \pmod{2^B}`.
1702
1703 This instruction does not depend on the signed/unsigned interpretation
1704 of the operands.
1705 "#,
1706 &formats.binary,
1707 )
1708 .operands_in(vec![Operand::new("x", Int), Operand::new("y", Int)])
1709 .operands_out(vec![Operand::new("a", Int)]),
1710 );
1711
1712 ig.push(
1713 Inst::new(
1714 "ineg",
1715 r#"
1716 Integer negation: `a := -x \pmod{2^B}`.
1717 "#,
1718 &formats.unary,
1719 )
1720 .operands_in(vec![Operand::new("x", Int)])
1721 .operands_out(vec![Operand::new("a", Int)]),
1722 );
1723
1724 ig.push(
1725 Inst::new(
1726 "iabs",
1727 r#"
1728 Integer absolute value with wrapping: `a := |x|`.
1729 "#,
1730 &formats.unary,
1731 )
1732 .operands_in(vec![Operand::new("x", Int)])
1733 .operands_out(vec![Operand::new("a", Int)]),
1734 );
1735
1736 ig.push(
1737 Inst::new(
1738 "imul",
1739 r#"
1740 Wrapping integer multiplication: `a := x y \pmod{2^B}`.
1741
1742 This instruction does not depend on the signed/unsigned interpretation
1743 of the operands.
1744
1745 Polymorphic over all integer types (vector and scalar).
1746 "#,
1747 &formats.binary,
1748 )
1749 .operands_in(vec![Operand::new("x", Int), Operand::new("y", Int)])
1750 .operands_out(vec![Operand::new("a", Int)])
1751 .inst_builder_imm_method(true),
1752 );
1753
1754 ig.push(
1755 Inst::new(
1756 "umulhi",
1757 r#"
1758 Unsigned integer multiplication, producing the high half of a
1759 double-length result.
1760
1761 Polymorphic over all integer types (vector and scalar).
1762 "#,
1763 &formats.binary,
1764 )
1765 .operands_in(vec![Operand::new("x", Int), Operand::new("y", Int)])
1766 .operands_out(vec![Operand::new("a", Int)]),
1767 );
1768
1769 ig.push(
1770 Inst::new(
1771 "smulhi",
1772 r#"
1773 Signed integer multiplication, producing the high half of a
1774 double-length result.
1775
1776 Polymorphic over all integer types (vector and scalar).
1777 "#,
1778 &formats.binary,
1779 )
1780 .operands_in(vec![Operand::new("x", Int), Operand::new("y", Int)])
1781 .operands_out(vec![Operand::new("a", Int)]),
1782 );
1783
1784 let I16or32 = &TypeVar::new(
1785 "I16or32",
1786 "A vector integer type with 16- or 32-bit numbers",
1787 TypeSetBuilder::new().ints(16..32).simd_lanes(4..8).build(),
1788 );
1789
1790 ig.push(
1791 Inst::new(
1792 "sqmul_round_sat",
1793 r#"
1794 Fixed-point multiplication of numbers in the QN format, where N + 1
1795 is the number bitwidth:
1796 `a := signed_saturate((x * y + (1 << (Q - 1))) >> Q)`
1797
1798 Polymorphic over all integer vector types with 16- or 32-bit numbers.
1799 "#,
1800 &formats.binary,
1801 )
1802 .operands_in(vec![Operand::new("x", I16or32), Operand::new("y", I16or32)])
1803 .operands_out(vec![Operand::new("a", I16or32)]),
1804 );
1805
1806 ig.push(
1807 Inst::new(
1808 "x86_pmulhrsw",
1809 r#"
1810 A similar instruction to `sqmul_round_sat` except with the semantics
1811 of x86's `pmulhrsw` instruction.
1812
1813 This is the same as `sqmul_round_sat` except when both input lanes are
1814 `i16::MIN`.
1815 "#,
1816 &formats.binary,
1817 )
1818 .operands_in(vec![Operand::new("x", I16or32), Operand::new("y", I16or32)])
1819 .operands_out(vec![Operand::new("a", I16or32)]),
1820 );
1821
1822 ig.push(
1826 Inst::new(
1827 "udiv",
1828 r#"
1829 Unsigned integer division: `a := \lfloor {x \over y} \rfloor`.
1830
1831 This operation traps if the divisor is zero.
1832 "#,
1833 &formats.binary,
1834 )
1835 .operands_in(vec![Operand::new("x", iB), Operand::new("y", iB)])
1836 .operands_out(vec![Operand::new("a", iB)])
1837 .can_trap()
1838 .side_effects_idempotent()
1839 .inst_builder_imm_method(true),
1840 );
1841
1842 ig.push(
1843 Inst::new(
1844 "sdiv",
1845 r#"
1846 Signed integer division rounded toward zero: `a := sign(xy)
1847 \lfloor {|x| \over |y|}\rfloor`.
1848
1849 This operation traps if the divisor is zero, or if the result is not
1850 representable in `B` bits two's complement. This only happens
1851 when `x = -2^{B-1}, y = -1`.
1852 "#,
1853 &formats.binary,
1854 )
1855 .operands_in(vec![Operand::new("x", iB), Operand::new("y", iB)])
1856 .operands_out(vec![Operand::new("a", iB)])
1857 .can_trap()
1858 .side_effects_idempotent()
1859 .inst_builder_imm_method(true),
1860 );
1861
1862 ig.push(
1863 Inst::new(
1864 "urem",
1865 r#"
1866 Unsigned integer remainder.
1867
1868 This operation traps if the divisor is zero.
1869 "#,
1870 &formats.binary,
1871 )
1872 .operands_in(vec![Operand::new("x", iB), Operand::new("y", iB)])
1873 .operands_out(vec![Operand::new("a", iB)])
1874 .can_trap()
1875 .side_effects_idempotent()
1876 .inst_builder_imm_method(true),
1877 );
1878
1879 ig.push(
1880 Inst::new(
1881 "srem",
1882 r#"
1883 Signed integer remainder. The result has the sign of the dividend.
1884
1885 This operation traps if the divisor is zero.
1886 "#,
1887 &formats.binary,
1888 )
1889 .operands_in(vec![Operand::new("x", iB), Operand::new("y", iB)])
1890 .operands_out(vec![Operand::new("a", iB)])
1891 .can_trap()
1892 .side_effects_idempotent()
1893 .inst_builder_imm_method(true),
1894 );
1895
1896 ig.push(
1897 Inst::new(
1898 "sadd_overflow_cin",
1899 r#"
1900 Add signed integers with carry in and overflow out.
1901
1902 Same as `sadd_overflow` with an additional carry input. The `c_in` type
1903 is interpreted as 1 if it's nonzero or 0 if it's zero.
1904 "#,
1905 &formats.ternary,
1906 )
1907 .operands_in(vec![
1908 Operand::new("x", iB),
1909 Operand::new("y", iB),
1910 Operand::new("c_in", i8).with_doc("Input carry flag"),
1911 ])
1912 .operands_out(vec![
1913 Operand::new("a", iB),
1914 Operand::new("c_out", i8).with_doc("Output carry flag"),
1915 ]),
1916 );
1917
1918 ig.push(
1919 Inst::new(
1920 "uadd_overflow_cin",
1921 r#"
1922 Add unsigned integers with carry in and overflow out.
1923
1924 Same as `uadd_overflow` with an additional carry input. The `c_in` type
1925 is interpreted as 1 if it's nonzero or 0 if it's zero.
1926 "#,
1927 &formats.ternary,
1928 )
1929 .operands_in(vec![
1930 Operand::new("x", iB),
1931 Operand::new("y", iB),
1932 Operand::new("c_in", i8).with_doc("Input carry flag"),
1933 ])
1934 .operands_out(vec![
1935 Operand::new("a", iB),
1936 Operand::new("c_out", i8).with_doc("Output carry flag"),
1937 ]),
1938 );
1939
1940 {
1941 let of_out = Operand::new("of", i8).with_doc("Overflow flag");
1942 ig.push(
1943 Inst::new(
1944 "uadd_overflow",
1945 r#"
1946 Add integers unsigned with overflow out.
1947 ``of`` is set when the addition overflowed.
1948 ```text
1949 a &= x + y \pmod 2^B \\
1950 of &= x+y >= 2^B
1951 ```
1952 Polymorphic over all scalar integer types, but does not support vector
1953 types.
1954 "#,
1955 &formats.binary,
1956 )
1957 .operands_in(vec![Operand::new("x", iB), Operand::new("y", iB)])
1958 .operands_out(vec![Operand::new("a", iB), of_out.clone()]),
1959 );
1960
1961 ig.push(
1962 Inst::new(
1963 "sadd_overflow",
1964 r#"
1965 Add integers signed with overflow out.
1966 ``of`` is set when the addition over- or underflowed.
1967 Polymorphic over all scalar integer types, but does not support vector
1968 types.
1969 "#,
1970 &formats.binary,
1971 )
1972 .operands_in(vec![Operand::new("x", iB), Operand::new("y", iB)])
1973 .operands_out(vec![Operand::new("a", iB), of_out.clone()]),
1974 );
1975
1976 ig.push(
1977 Inst::new(
1978 "usub_overflow",
1979 r#"
1980 Subtract integers unsigned with overflow out.
1981 ``of`` is set when the subtraction underflowed.
1982 ```text
1983 a &= x - y \pmod 2^B \\
1984 of &= x - y < 0
1985 ```
1986 Polymorphic over all scalar integer types, but does not support vector
1987 types.
1988 "#,
1989 &formats.binary,
1990 )
1991 .operands_in(vec![Operand::new("x", iB), Operand::new("y", iB)])
1992 .operands_out(vec![Operand::new("a", iB), of_out.clone()]),
1993 );
1994
1995 ig.push(
1996 Inst::new(
1997 "ssub_overflow",
1998 r#"
1999 Subtract integers signed with overflow out.
2000 ``of`` is set when the subtraction over- or underflowed.
2001 Polymorphic over all scalar integer types, but does not support vector
2002 types.
2003 "#,
2004 &formats.binary,
2005 )
2006 .operands_in(vec![Operand::new("x", iB), Operand::new("y", iB)])
2007 .operands_out(vec![Operand::new("a", iB), of_out.clone()]),
2008 );
2009
2010 {
2011 let NarrowScalar = &TypeVar::new(
2012 "NarrowScalar",
2013 "A scalar integer type up to 64 bits",
2014 TypeSetBuilder::new().ints(8..64).build(),
2015 );
2016
2017 ig.push(
2018 Inst::new(
2019 "umul_overflow",
2020 r#"
2021 Multiply integers unsigned with overflow out.
2022 ``of`` is set when the multiplication overflowed.
2023 ```text
2024 a &= x * y \pmod 2^B \\
2025 of &= x * y > 2^B
2026 ```
2027 Polymorphic over all scalar integer types except i128, but does not support vector
2028 types.
2029 "#,
2030 &formats.binary,
2031 )
2032 .operands_in(vec![
2033 Operand::new("x", NarrowScalar),
2034 Operand::new("y", NarrowScalar),
2035 ])
2036 .operands_out(vec![Operand::new("a", NarrowScalar), of_out.clone()]),
2037 );
2038
2039 ig.push(
2040 Inst::new(
2041 "smul_overflow",
2042 r#"
2043 Multiply integers signed with overflow out.
2044 ``of`` is set when the multiplication over- or underflowed.
2045 Polymorphic over all scalar integer types except i128, but does not support vector
2046 types.
2047 "#,
2048 &formats.binary,
2049 )
2050 .operands_in(vec![
2051 Operand::new("x", NarrowScalar),
2052 Operand::new("y", NarrowScalar),
2053 ])
2054 .operands_out(vec![Operand::new("a", NarrowScalar), of_out.clone()]),
2055 );
2056 }
2057 }
2058
2059 let i32_64 = &TypeVar::new(
2060 "i32_64",
2061 "A 32 or 64-bit scalar integer type",
2062 TypeSetBuilder::new().ints(32..64).build(),
2063 );
2064
2065 ig.push(
2066 Inst::new(
2067 "uadd_overflow_trap",
2068 r#"
2069 Unsigned addition of x and y, trapping if the result overflows.
2070
2071 Accepts 32 or 64-bit integers, and does not support vector types.
2072 "#,
2073 &formats.int_add_trap,
2074 )
2075 .operands_in(vec![
2076 Operand::new("x", i32_64),
2077 Operand::new("y", i32_64),
2078 Operand::new("code", &imm.trapcode),
2079 ])
2080 .operands_out(vec![Operand::new("a", i32_64)])
2081 .can_trap()
2082 .side_effects_idempotent(),
2083 );
2084
2085 ig.push(
2086 Inst::new(
2087 "ssub_overflow_bin",
2088 r#"
2089 Subtract signed integers with borrow in and overflow out.
2090
2091 Same as `ssub_overflow` with an additional borrow input. The `b_in` type
2092 is interpreted as 1 if it's nonzero or 0 if it's zero. The computation
2093 performed here is `x - (y + (b_in != 0))`.
2094 "#,
2095 &formats.ternary,
2096 )
2097 .operands_in(vec![
2098 Operand::new("x", iB),
2099 Operand::new("y", iB),
2100 Operand::new("b_in", i8).with_doc("Input borrow flag"),
2101 ])
2102 .operands_out(vec![
2103 Operand::new("a", iB),
2104 Operand::new("b_out", i8).with_doc("Output borrow flag"),
2105 ]),
2106 );
2107
2108 ig.push(
2109 Inst::new(
2110 "usub_overflow_bin",
2111 r#"
2112 Subtract unsigned integers with borrow in and overflow out.
2113
2114 Same as `usub_overflow` with an additional borrow input. The `b_in` type
2115 is interpreted as 1 if it's nonzero or 0 if it's zero. The computation
2116 performed here is `x - (y + (b_in != 0))`.
2117 "#,
2118 &formats.ternary,
2119 )
2120 .operands_in(vec![
2121 Operand::new("x", iB),
2122 Operand::new("y", iB),
2123 Operand::new("b_in", i8).with_doc("Input borrow flag"),
2124 ])
2125 .operands_out(vec![
2126 Operand::new("a", iB),
2127 Operand::new("b_out", i8).with_doc("Output borrow flag"),
2128 ]),
2129 );
2130
2131 let bits = &TypeVar::new(
2132 "bits",
2133 "Any integer, float, or vector type",
2134 TypeSetBuilder::new()
2135 .ints(Interval::All)
2136 .floats(Interval::All)
2137 .simd_lanes(Interval::All)
2138 .includes_scalars(true)
2139 .build(),
2140 );
2141
2142 ig.push(
2143 Inst::new(
2144 "band",
2145 r#"
2146 Bitwise and.
2147 "#,
2148 &formats.binary,
2149 )
2150 .operands_in(vec![Operand::new("x", bits), Operand::new("y", bits)])
2151 .operands_out(vec![Operand::new("a", bits)])
2152 .inst_builder_imm_method(true),
2153 );
2154
2155 ig.push(
2156 Inst::new(
2157 "bor",
2158 r#"
2159 Bitwise or.
2160 "#,
2161 &formats.binary,
2162 )
2163 .operands_in(vec![Operand::new("x", bits), Operand::new("y", bits)])
2164 .operands_out(vec![Operand::new("a", bits)])
2165 .inst_builder_imm_method(true),
2166 );
2167
2168 ig.push(
2169 Inst::new(
2170 "bxor",
2171 r#"
2172 Bitwise xor.
2173 "#,
2174 &formats.binary,
2175 )
2176 .operands_in(vec![Operand::new("x", bits), Operand::new("y", bits)])
2177 .operands_out(vec![Operand::new("a", bits)])
2178 .inst_builder_imm_method(true),
2179 );
2180
2181 ig.push(
2182 Inst::new(
2183 "bnot",
2184 r#"
2185 Bitwise not.
2186 "#,
2187 &formats.unary,
2188 )
2189 .operands_in(vec![Operand::new("x", bits)])
2190 .operands_out(vec![Operand::new("a", bits)]),
2191 );
2192
2193 ig.push(
2194 Inst::new(
2195 "rotl",
2196 r#"
2197 Rotate left.
2198
2199 Rotate the bits in ``x`` by ``y`` places.
2200 "#,
2201 &formats.binary,
2202 )
2203 .operands_in(vec![
2204 Operand::new("x", Int).with_doc("Scalar or vector value to shift"),
2205 Operand::new("y", iB).with_doc("Number of bits to shift"),
2206 ])
2207 .operands_out(vec![Operand::new("a", Int)])
2208 .inst_builder_imm_method(true),
2209 );
2210
2211 ig.push(
2212 Inst::new(
2213 "rotr",
2214 r#"
2215 Rotate right.
2216
2217 Rotate the bits in ``x`` by ``y`` places.
2218 "#,
2219 &formats.binary,
2220 )
2221 .operands_in(vec![
2222 Operand::new("x", Int).with_doc("Scalar or vector value to shift"),
2223 Operand::new("y", iB).with_doc("Number of bits to shift"),
2224 ])
2225 .operands_out(vec![Operand::new("a", Int)])
2226 .inst_builder_imm_method(true),
2227 );
2228
2229 ig.push(
2230 Inst::new(
2231 "ishl",
2232 r#"
2233 Integer shift left. Shift the bits in ``x`` towards the MSB by ``y``
2234 places. Shift in zero bits to the LSB.
2235
2236 The shift amount is masked to the size of ``x``.
2237
2238 When shifting a B-bits integer type, this instruction computes:
2239
2240 ```text
2241 s &:= y \pmod B,
2242 a &:= x \cdot 2^s \pmod{2^B}.
2243 ```
2244 "#,
2245 &formats.binary,
2246 )
2247 .operands_in(vec![
2248 Operand::new("x", Int).with_doc("Scalar or vector value to shift"),
2249 Operand::new("y", iB).with_doc("Number of bits to shift"),
2250 ])
2251 .operands_out(vec![Operand::new("a", Int)])
2252 .inst_builder_imm_method(true),
2253 );
2254
2255 ig.push(
2256 Inst::new(
2257 "ushr",
2258 r#"
2259 Unsigned shift right. Shift bits in ``x`` towards the LSB by ``y``
2260 places, shifting in zero bits to the MSB. Also called a *logical
2261 shift*.
2262
2263 The shift amount is masked to the size of ``x``.
2264
2265 When shifting a B-bits integer type, this instruction computes:
2266
2267 ```text
2268 s &:= y \pmod B,
2269 a &:= \lfloor x \cdot 2^{-s} \rfloor.
2270 ```
2271 "#,
2272 &formats.binary,
2273 )
2274 .operands_in(vec![
2275 Operand::new("x", Int).with_doc("Scalar or vector value to shift"),
2276 Operand::new("y", iB).with_doc("Number of bits to shift"),
2277 ])
2278 .operands_out(vec![Operand::new("a", Int)])
2279 .inst_builder_imm_method(true),
2280 );
2281
2282 ig.push(
2283 Inst::new(
2284 "sshr",
2285 r#"
2286 Signed shift right. Shift bits in ``x`` towards the LSB by ``y``
2287 places, shifting in sign bits to the MSB. Also called an *arithmetic
2288 shift*.
2289
2290 The shift amount is masked to the size of ``x``.
2291 "#,
2292 &formats.binary,
2293 )
2294 .operands_in(vec![
2295 Operand::new("x", Int).with_doc("Scalar or vector value to shift"),
2296 Operand::new("y", iB).with_doc("Number of bits to shift"),
2297 ])
2298 .operands_out(vec![Operand::new("a", Int)])
2299 .inst_builder_imm_method(true),
2300 );
2301
2302 ig.push(
2303 Inst::new(
2304 "bitrev",
2305 r#"
2306 Reverse the bits of a integer.
2307
2308 Reverses the bits in ``x``.
2309 "#,
2310 &formats.unary,
2311 )
2312 .operands_in(vec![Operand::new("x", iB)])
2313 .operands_out(vec![Operand::new("a", iB)]),
2314 );
2315
2316 ig.push(
2317 Inst::new(
2318 "clz",
2319 r#"
2320 Count leading zero bits.
2321
2322 Starting from the MSB in ``x``, count the number of zero bits before
2323 reaching the first one bit. When ``x`` is zero, returns the size of x
2324 in bits.
2325 "#,
2326 &formats.unary,
2327 )
2328 .operands_in(vec![Operand::new("x", iB)])
2329 .operands_out(vec![Operand::new("a", iB)]),
2330 );
2331
2332 ig.push(
2333 Inst::new(
2334 "cls",
2335 r#"
2336 Count leading sign bits.
2337
2338 Starting from the MSB after the sign bit in ``x``, count the number of
2339 consecutive bits identical to the sign bit. When ``x`` is 0 or -1,
2340 returns one less than the size of x in bits.
2341 "#,
2342 &formats.unary,
2343 )
2344 .operands_in(vec![Operand::new("x", iB)])
2345 .operands_out(vec![Operand::new("a", iB)]),
2346 );
2347
2348 ig.push(
2349 Inst::new(
2350 "ctz",
2351 r#"
2352 Count trailing zeros.
2353
2354 Starting from the LSB in ``x``, count the number of zero bits before
2355 reaching the first one bit. When ``x`` is zero, returns the size of x
2356 in bits.
2357 "#,
2358 &formats.unary,
2359 )
2360 .operands_in(vec![Operand::new("x", iB)])
2361 .operands_out(vec![Operand::new("a", iB)]),
2362 );
2363
2364 ig.push(
2365 Inst::new(
2366 "bswap",
2367 r#"
2368 Reverse the byte order of an integer.
2369
2370 Reverses the bytes in ``x``.
2371 "#,
2372 &formats.unary,
2373 )
2374 .operands_in(vec![Operand::new("x", iSwappable)])
2375 .operands_out(vec![Operand::new("a", iSwappable)]),
2376 );
2377
2378 ig.push(
2379 Inst::new(
2380 "popcnt",
2381 r#"
2382 Population count
2383
2384 Count the number of one bits in ``x``.
2385 "#,
2386 &formats.unary,
2387 )
2388 .operands_in(vec![Operand::new("x", Int)])
2389 .operands_out(vec![Operand::new("a", Int)]),
2390 );
2391
2392 let Float = &TypeVar::new(
2393 "Float",
2394 "A scalar or vector floating point number",
2395 TypeSetBuilder::new()
2396 .floats(Interval::All)
2397 .simd_lanes(Interval::All)
2398 .dynamic_simd_lanes(Interval::All)
2399 .build(),
2400 );
2401
2402 ig.push(
2403 Inst::new(
2404 "fcmp",
2405 r#"
2406 Floating point comparison.
2407
2408 Two IEEE 754-2008 floating point numbers, `x` and `y`, relate to each
2409 other in exactly one of four ways:
2410
2411 ```text
2412 == ==========================================
2413 UN Unordered when one or both numbers is NaN.
2414 EQ When `x = y`. (And `0.0 = -0.0`).
2415 LT When `x < y`.
2416 GT When `x > y`.
2417 == ==========================================
2418 ```
2419
2420 The 14 `floatcc` condition codes each correspond to a subset of
2421 the four relations, except for the empty set which would always be
2422 false, and the full set which would always be true.
2423
2424 The condition codes are divided into 7 'ordered' conditions which don't
2425 include UN, and 7 unordered conditions which all include UN.
2426
2427 ```text
2428 +-------+------------+---------+------------+-------------------------+
2429 |Ordered |Unordered |Condition |
2430 +=======+============+=========+============+=========================+
2431 |ord |EQ | LT | GT|uno |UN |NaNs absent / present. |
2432 +-------+------------+---------+------------+-------------------------+
2433 |eq |EQ |ueq |UN | EQ |Equal |
2434 +-------+------------+---------+------------+-------------------------+
2435 |one |LT | GT |ne |UN | LT | GT|Not equal |
2436 +-------+------------+---------+------------+-------------------------+
2437 |lt |LT |ult |UN | LT |Less than |
2438 +-------+------------+---------+------------+-------------------------+
2439 |le |LT | EQ |ule |UN | LT | EQ|Less than or equal |
2440 +-------+------------+---------+------------+-------------------------+
2441 |gt |GT |ugt |UN | GT |Greater than |
2442 +-------+------------+---------+------------+-------------------------+
2443 |ge |GT | EQ |uge |UN | GT | EQ|Greater than or equal |
2444 +-------+------------+---------+------------+-------------------------+
2445 ```
2446
2447 The standard C comparison operators, `<, <=, >, >=`, are all ordered,
2448 so they are false if either operand is NaN. The C equality operator,
2449 `==`, is ordered, and since inequality is defined as the logical
2450 inverse it is *unordered*. They map to the `floatcc` condition
2451 codes as follows:
2452
2453 ```text
2454 ==== ====== ============
2455 C `Cond` Subset
2456 ==== ====== ============
2457 `==` eq EQ
2458 `!=` ne UN | LT | GT
2459 `<` lt LT
2460 `<=` le LT | EQ
2461 `>` gt GT
2462 `>=` ge GT | EQ
2463 ==== ====== ============
2464 ```
2465
2466 This subset of condition codes also corresponds to the WebAssembly
2467 floating point comparisons of the same name.
2468
2469 When this instruction compares floating point vectors, it returns a
2470 vector with the results of lane-wise comparisons.
2471
2472 When comparing scalars, the result is:
2473 - `1` if the condition holds.
2474 - `0` if the condition does not hold.
2475
2476 When comparing vectors, the result is:
2477 - `-1` (i.e. all ones) in each lane where the condition holds.
2478 - `0` in each lane where the condition does not hold.
2479 "#,
2480 &formats.float_compare,
2481 )
2482 .operands_in(vec![
2483 Operand::new("Cond", &imm.floatcc),
2484 Operand::new("x", Float),
2485 Operand::new("y", Float),
2486 ])
2487 .operands_out(vec![Operand::new("a", &Float.as_truthy())]),
2488 );
2489
2490 ig.push(
2491 Inst::new(
2492 "fadd",
2493 r#"
2494 Floating point addition.
2495 "#,
2496 &formats.binary,
2497 )
2498 .operands_in(vec![Operand::new("x", Float), Operand::new("y", Float)])
2499 .operands_out(vec![
2500 Operand::new("a", Float).with_doc("Result of applying operator to each lane"),
2501 ]),
2502 );
2503
2504 ig.push(
2505 Inst::new(
2506 "fsub",
2507 r#"
2508 Floating point subtraction.
2509 "#,
2510 &formats.binary,
2511 )
2512 .operands_in(vec![Operand::new("x", Float), Operand::new("y", Float)])
2513 .operands_out(vec![
2514 Operand::new("a", Float).with_doc("Result of applying operator to each lane"),
2515 ]),
2516 );
2517
2518 ig.push(
2519 Inst::new(
2520 "fmul",
2521 r#"
2522 Floating point multiplication.
2523 "#,
2524 &formats.binary,
2525 )
2526 .operands_in(vec![Operand::new("x", Float), Operand::new("y", Float)])
2527 .operands_out(vec![
2528 Operand::new("a", Float).with_doc("Result of applying operator to each lane"),
2529 ]),
2530 );
2531
2532 ig.push(
2533 Inst::new(
2534 "fdiv",
2535 r#"
2536 Floating point division.
2537
2538 Unlike the integer division instructions ` and
2539 `udiv`, this can't trap. Division by zero is infinity or
2540 NaN, depending on the dividend.
2541 "#,
2542 &formats.binary,
2543 )
2544 .operands_in(vec![Operand::new("x", Float), Operand::new("y", Float)])
2545 .operands_out(vec![
2546 Operand::new("a", Float).with_doc("Result of applying operator to each lane"),
2547 ]),
2548 );
2549
2550 ig.push(
2551 Inst::new(
2552 "sqrt",
2553 r#"
2554 Floating point square root.
2555 "#,
2556 &formats.unary,
2557 )
2558 .operands_in(vec![Operand::new("x", Float)])
2559 .operands_out(vec![
2560 Operand::new("a", Float).with_doc("Result of applying operator to each lane"),
2561 ]),
2562 );
2563
2564 ig.push(
2565 Inst::new(
2566 "fma",
2567 r#"
2568 Floating point fused multiply-and-add.
2569
2570 Computes `a := xy+z` without any intermediate rounding of the
2571 product.
2572 "#,
2573 &formats.ternary,
2574 )
2575 .operands_in(vec![
2576 Operand::new("x", Float),
2577 Operand::new("y", Float),
2578 Operand::new("z", Float),
2579 ])
2580 .operands_out(vec![
2581 Operand::new("a", Float).with_doc("Result of applying operator to each lane"),
2582 ]),
2583 );
2584
2585 ig.push(
2586 Inst::new(
2587 "fneg",
2588 r#"
2589 Floating point negation.
2590
2591 Note that this is a pure bitwise operation.
2592 "#,
2593 &formats.unary,
2594 )
2595 .operands_in(vec![Operand::new("x", Float)])
2596 .operands_out(vec![
2597 Operand::new("a", Float).with_doc("``x`` with its sign bit inverted"),
2598 ]),
2599 );
2600
2601 ig.push(
2602 Inst::new(
2603 "fabs",
2604 r#"
2605 Floating point absolute value.
2606
2607 Note that this is a pure bitwise operation.
2608 "#,
2609 &formats.unary,
2610 )
2611 .operands_in(vec![Operand::new("x", Float)])
2612 .operands_out(vec![
2613 Operand::new("a", Float).with_doc("``x`` with its sign bit cleared"),
2614 ]),
2615 );
2616
2617 ig.push(
2618 Inst::new(
2619 "fcopysign",
2620 r#"
2621 Floating point copy sign.
2622
2623 Note that this is a pure bitwise operation. The sign bit from ``y`` is
2624 copied to the sign bit of ``x``.
2625 "#,
2626 &formats.binary,
2627 )
2628 .operands_in(vec![Operand::new("x", Float), Operand::new("y", Float)])
2629 .operands_out(vec![
2630 Operand::new("a", Float).with_doc("``x`` with its sign bit changed to that of ``y``"),
2631 ]),
2632 );
2633
2634 ig.push(
2635 Inst::new(
2636 "fmin",
2637 r#"
2638 Floating point minimum, propagating NaNs using the WebAssembly rules.
2639
2640 If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if
2641 each input NaN consists of a mantissa whose most significant bit is 1 and the rest is
2642 0, then the output has the same form. Otherwise, the output mantissa's most significant
2643 bit is 1 and the rest is unspecified.
2644 "#,
2645 &formats.binary,
2646 )
2647 .operands_in(vec![Operand::new("x", Float), Operand::new("y", Float)])
2648 .operands_out(vec![
2649 Operand::new("a", Float).with_doc("The smaller of ``x`` and ``y``"),
2650 ]),
2651 );
2652
2653 ig.push(
2654 Inst::new(
2655 "fmax",
2656 r#"
2657 Floating point maximum, propagating NaNs using the WebAssembly rules.
2658
2659 If either operand is NaN, this returns NaN with an unspecified sign. Furthermore, if
2660 each input NaN consists of a mantissa whose most significant bit is 1 and the rest is
2661 0, then the output has the same form. Otherwise, the output mantissa's most significant
2662 bit is 1 and the rest is unspecified.
2663 "#,
2664 &formats.binary,
2665 )
2666 .operands_in(vec![Operand::new("x", Float), Operand::new("y", Float)])
2667 .operands_out(vec![
2668 Operand::new("a", Float).with_doc("The larger of ``x`` and ``y``"),
2669 ]),
2670 );
2671
2672 ig.push(
2673 Inst::new(
2674 "ceil",
2675 r#"
2676 Round floating point round to integral, towards positive infinity.
2677 "#,
2678 &formats.unary,
2679 )
2680 .operands_in(vec![Operand::new("x", Float)])
2681 .operands_out(vec![
2682 Operand::new("a", Float).with_doc("``x`` rounded to integral value"),
2683 ]),
2684 );
2685
2686 ig.push(
2687 Inst::new(
2688 "floor",
2689 r#"
2690 Round floating point round to integral, towards negative infinity.
2691 "#,
2692 &formats.unary,
2693 )
2694 .operands_in(vec![Operand::new("x", Float)])
2695 .operands_out(vec![
2696 Operand::new("a", Float).with_doc("``x`` rounded to integral value"),
2697 ]),
2698 );
2699
2700 ig.push(
2701 Inst::new(
2702 "trunc",
2703 r#"
2704 Round floating point round to integral, towards zero.
2705 "#,
2706 &formats.unary,
2707 )
2708 .operands_in(vec![Operand::new("x", Float)])
2709 .operands_out(vec![
2710 Operand::new("a", Float).with_doc("``x`` rounded to integral value"),
2711 ]),
2712 );
2713
2714 ig.push(
2715 Inst::new(
2716 "nearest",
2717 r#"
2718 Round floating point round to integral, towards nearest with ties to
2719 even.
2720 "#,
2721 &formats.unary,
2722 )
2723 .operands_in(vec![Operand::new("x", Float)])
2724 .operands_out(vec![
2725 Operand::new("a", Float).with_doc("``x`` rounded to integral value"),
2726 ]),
2727 );
2728
2729 ig.push(
2730 Inst::new(
2731 "bitcast",
2732 r#"
2733 Reinterpret the bits in `x` as a different type.
2734
2735 The input and output types must be storable to memory and of the same
2736 size. A bitcast is equivalent to storing one type and loading the other
2737 type from the same address, both using the specified MemFlags.
2738
2739 Note that this operation only supports the `big` or `little` MemFlags.
2740 The specified byte order only affects the result in the case where
2741 input and output types differ in lane count/size. In this case, the
2742 operation is only valid if a byte order specifier is provided.
2743 "#,
2744 &formats.load_no_offset,
2745 )
2746 .operands_in(vec![
2747 Operand::new("MemFlags", &imm.memflags),
2748 Operand::new("x", Mem),
2749 ])
2750 .operands_out(vec![
2751 Operand::new("a", MemTo).with_doc("Bits of `x` reinterpreted"),
2752 ]),
2753 );
2754
2755 ig.push(
2756 Inst::new(
2757 "scalar_to_vector",
2758 r#"
2759 Copies a scalar value to a vector value. The scalar is copied into the
2760 least significant lane of the vector, and all other lanes will be zero.
2761 "#,
2762 &formats.unary,
2763 )
2764 .operands_in(vec![
2765 Operand::new("s", &TxN.lane_of()).with_doc("A scalar value"),
2766 ])
2767 .operands_out(vec![Operand::new("a", TxN).with_doc("A vector value")]),
2768 );
2769
2770 let Truthy = &TypeVar::new(
2771 "Truthy",
2772 "A scalar whose values are truthy",
2773 TypeSetBuilder::new().ints(Interval::All).build(),
2774 );
2775 let IntTo = &TypeVar::new(
2776 "IntTo",
2777 "An integer type",
2778 TypeSetBuilder::new().ints(Interval::All).build(),
2779 );
2780
2781 ig.push(
2782 Inst::new(
2783 "bmask",
2784 r#"
2785 Convert `x` to an integer mask.
2786
2787 Non-zero maps to all 1s and zero maps to all 0s.
2788 "#,
2789 &formats.unary,
2790 )
2791 .operands_in(vec![Operand::new("x", Truthy)])
2792 .operands_out(vec![Operand::new("a", IntTo)]),
2793 );
2794
2795 let Int = &TypeVar::new(
2796 "Int",
2797 "A scalar integer type",
2798 TypeSetBuilder::new().ints(Interval::All).build(),
2799 );
2800
2801 ig.push(
2802 Inst::new(
2803 "ireduce",
2804 r#"
2805 Convert `x` to a smaller integer type by discarding
2806 the most significant bits.
2807
2808 This is the same as reducing modulo `2^n`.
2809 "#,
2810 &formats.unary,
2811 )
2812 .operands_in(vec![
2813 Operand::new("x", &Int.wider())
2814 .with_doc("A scalar integer type, wider than the controlling type"),
2815 ])
2816 .operands_out(vec![Operand::new("a", Int)]),
2817 );
2818
2819 let I16or32or64xN = &TypeVar::new(
2820 "I16or32or64xN",
2821 "A SIMD vector type containing integer lanes 16, 32, or 64 bits wide",
2822 TypeSetBuilder::new()
2823 .ints(16..64)
2824 .simd_lanes(2..8)
2825 .dynamic_simd_lanes(2..8)
2826 .includes_scalars(false)
2827 .build(),
2828 );
2829
2830 ig.push(
2831 Inst::new(
2832 "snarrow",
2833 r#"
2834 Combine `x` and `y` into a vector with twice the lanes but half the integer width while
2835 saturating overflowing values to the signed maximum and minimum.
2836
2837 The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
2838 and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
2839 returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
2840 "#,
2841 &formats.binary,
2842 )
2843 .operands_in(vec![
2844 Operand::new("x", I16or32or64xN),
2845 Operand::new("y", I16or32or64xN),
2846 ])
2847 .operands_out(vec![Operand::new("a", &I16or32or64xN.split_lanes())]),
2848 );
2849
2850 ig.push(
2851 Inst::new(
2852 "unarrow",
2853 r#"
2854 Combine `x` and `y` into a vector with twice the lanes but half the integer width while
2855 saturating overflowing values to the unsigned maximum and minimum.
2856
2857 Note that all input lanes are considered signed: any negative lanes will overflow and be
2858 replaced with the unsigned minimum, `0x00`.
2859
2860 The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
2861 and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
2862 returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
2863 "#,
2864 &formats.binary,
2865 )
2866 .operands_in(vec![
2867 Operand::new("x", I16or32or64xN),
2868 Operand::new("y", I16or32or64xN),
2869 ])
2870 .operands_out(vec![Operand::new("a", &I16or32or64xN.split_lanes())]),
2871 );
2872
2873 ig.push(
2874 Inst::new(
2875 "uunarrow",
2876 r#"
2877 Combine `x` and `y` into a vector with twice the lanes but half the integer width while
2878 saturating overflowing values to the unsigned maximum and minimum.
2879
2880 Note that all input lanes are considered unsigned: any negative values will be interpreted as unsigned, overflowing and being replaced with the unsigned maximum.
2881
2882 The lanes will be concatenated after narrowing. For example, when `x` and `y` are `i32x4`
2883 and `x = [x3, x2, x1, x0]` and `y = [y3, y2, y1, y0]`, then after narrowing the value
2884 returned is an `i16x8`: `a = [y3', y2', y1', y0', x3', x2', x1', x0']`.
2885 "#,
2886 &formats.binary,
2887 )
2888 .operands_in(vec![Operand::new("x", I16or32or64xN), Operand::new("y", I16or32or64xN)])
2889 .operands_out(vec![Operand::new("a", &I16or32or64xN.split_lanes())]),
2890 );
2891
2892 let I8or16or32xN = &TypeVar::new(
2893 "I8or16or32xN",
2894 "A SIMD vector type containing integer lanes 8, 16, or 32 bits wide.",
2895 TypeSetBuilder::new()
2896 .ints(8..32)
2897 .simd_lanes(2..16)
2898 .dynamic_simd_lanes(2..16)
2899 .includes_scalars(false)
2900 .build(),
2901 );
2902
2903 ig.push(
2904 Inst::new(
2905 "swiden_low",
2906 r#"
2907 Widen the low lanes of `x` using signed extension.
2908
2909 This will double the lane width and halve the number of lanes.
2910 "#,
2911 &formats.unary,
2912 )
2913 .operands_in(vec![Operand::new("x", I8or16or32xN)])
2914 .operands_out(vec![Operand::new("a", &I8or16or32xN.merge_lanes())]),
2915 );
2916
2917 ig.push(
2918 Inst::new(
2919 "swiden_high",
2920 r#"
2921 Widen the high lanes of `x` using signed extension.
2922
2923 This will double the lane width and halve the number of lanes.
2924 "#,
2925 &formats.unary,
2926 )
2927 .operands_in(vec![Operand::new("x", I8or16or32xN)])
2928 .operands_out(vec![Operand::new("a", &I8or16or32xN.merge_lanes())]),
2929 );
2930
2931 ig.push(
2932 Inst::new(
2933 "uwiden_low",
2934 r#"
2935 Widen the low lanes of `x` using unsigned extension.
2936
2937 This will double the lane width and halve the number of lanes.
2938 "#,
2939 &formats.unary,
2940 )
2941 .operands_in(vec![Operand::new("x", I8or16or32xN)])
2942 .operands_out(vec![Operand::new("a", &I8or16or32xN.merge_lanes())]),
2943 );
2944
2945 ig.push(
2946 Inst::new(
2947 "uwiden_high",
2948 r#"
2949 Widen the high lanes of `x` using unsigned extension.
2950
2951 This will double the lane width and halve the number of lanes.
2952 "#,
2953 &formats.unary,
2954 )
2955 .operands_in(vec![Operand::new("x", I8or16or32xN)])
2956 .operands_out(vec![Operand::new("a", &I8or16or32xN.merge_lanes())]),
2957 );
2958
2959 ig.push(
2960 Inst::new(
2961 "iadd_pairwise",
2962 r#"
2963 Does lane-wise integer pairwise addition on two operands, putting the
2964 combined results into a single vector result. Here a pair refers to adjacent
2965 lanes in a vector, i.e. i*2 + (i*2+1) for i == num_lanes/2. The first operand
2966 pairwise add results will make up the low half of the resulting vector while
2967 the second operand pairwise add results will make up the upper half of the
2968 resulting vector.
2969 "#,
2970 &formats.binary,
2971 )
2972 .operands_in(vec![
2973 Operand::new("x", I8or16or32xN),
2974 Operand::new("y", I8or16or32xN),
2975 ])
2976 .operands_out(vec![Operand::new("a", I8or16or32xN)]),
2977 );
2978
2979 let I8x16 = &TypeVar::new(
2980 "I8x16",
2981 "A SIMD vector type consisting of 16 lanes of 8-bit integers",
2982 TypeSetBuilder::new()
2983 .ints(8..8)
2984 .simd_lanes(16..16)
2985 .includes_scalars(false)
2986 .build(),
2987 );
2988
2989 ig.push(
2990 Inst::new(
2991 "x86_pmaddubsw",
2992 r#"
2993 An instruction with equivalent semantics to `pmaddubsw` on x86.
2994
2995 This instruction will take signed bytes from the first argument and
2996 multiply them against unsigned bytes in the second argument. Adjacent
2997 pairs are then added, with saturating, to a 16-bit value and are packed
2998 into the result.
2999 "#,
3000 &formats.binary,
3001 )
3002 .operands_in(vec![Operand::new("x", I8x16), Operand::new("y", I8x16)])
3003 .operands_out(vec![Operand::new("a", I16x8)]),
3004 );
3005
3006 ig.push(
3007 Inst::new(
3008 "uextend",
3009 r#"
3010 Convert `x` to a larger integer type by zero-extending.
3011
3012 Each lane in `x` is converted to a larger integer type by adding
3013 zeroes. The result has the same numerical value as `x` when both are
3014 interpreted as unsigned integers.
3015
3016 The result type must have the same number of vector lanes as the input,
3017 and each lane must not have fewer bits that the input lanes. If the
3018 input and output types are the same, this is a no-op.
3019 "#,
3020 &formats.unary,
3021 )
3022 .operands_in(vec![Operand::new("x", &Int.narrower()).with_doc(
3023 "A scalar integer type, narrower than the controlling type",
3024 )])
3025 .operands_out(vec![Operand::new("a", Int)]),
3026 );
3027
3028 ig.push(
3029 Inst::new(
3030 "sextend",
3031 r#"
3032 Convert `x` to a larger integer type by sign-extending.
3033
3034 Each lane in `x` is converted to a larger integer type by replicating
3035 the sign bit. The result has the same numerical value as `x` when both
3036 are interpreted as signed integers.
3037
3038 The result type must have the same number of vector lanes as the input,
3039 and each lane must not have fewer bits that the input lanes. If the
3040 input and output types are the same, this is a no-op.
3041 "#,
3042 &formats.unary,
3043 )
3044 .operands_in(vec![Operand::new("x", &Int.narrower()).with_doc(
3045 "A scalar integer type, narrower than the controlling type",
3046 )])
3047 .operands_out(vec![Operand::new("a", Int)]),
3048 );
3049
3050 let FloatScalar = &TypeVar::new(
3051 "FloatScalar",
3052 "A scalar only floating point number",
3053 TypeSetBuilder::new().floats(Interval::All).build(),
3054 );
3055
3056 ig.push(
3057 Inst::new(
3058 "fpromote",
3059 r#"
3060 Convert `x` to a larger floating point format.
3061
3062 Each lane in `x` is converted to the destination floating point format.
3063 This is an exact operation.
3064
3065 Cranelift currently only supports two floating point formats
3066 - `f32` and `f64`. This may change in the future.
3067
3068 The result type must have the same number of vector lanes as the input,
3069 and the result lanes must not have fewer bits than the input lanes.
3070 "#,
3071 &formats.unary,
3072 )
3073 .operands_in(vec![Operand::new("x", &FloatScalar.narrower()).with_doc(
3074 "A scalar only floating point number, narrower than the controlling type",
3075 )])
3076 .operands_out(vec![Operand::new("a", FloatScalar)]),
3077 );
3078
3079 ig.push(
3080 Inst::new(
3081 "fdemote",
3082 r#"
3083 Convert `x` to a smaller floating point format.
3084
3085 Each lane in `x` is converted to the destination floating point format
3086 by rounding to nearest, ties to even.
3087
3088 Cranelift currently only supports two floating point formats
3089 - `f32` and `f64`. This may change in the future.
3090
3091 The result type must have the same number of vector lanes as the input,
3092 and the result lanes must not have more bits than the input lanes.
3093 "#,
3094 &formats.unary,
3095 )
3096 .operands_in(vec![Operand::new("x", &FloatScalar.wider()).with_doc(
3097 "A scalar only floating point number, wider than the controlling type",
3098 )])
3099 .operands_out(vec![Operand::new("a", FloatScalar)]),
3100 );
3101
3102 let F64x2 = &TypeVar::new(
3103 "F64x2",
3104 "A SIMD vector type consisting of 2 lanes of 64-bit floats",
3105 TypeSetBuilder::new()
3106 .floats(64..64)
3107 .simd_lanes(2..2)
3108 .includes_scalars(false)
3109 .build(),
3110 );
3111 let F32x4 = &TypeVar::new(
3112 "F32x4",
3113 "A SIMD vector type consisting of 4 lanes of 32-bit floats",
3114 TypeSetBuilder::new()
3115 .floats(32..32)
3116 .simd_lanes(4..4)
3117 .includes_scalars(false)
3118 .build(),
3119 );
3120
3121 ig.push(
3122 Inst::new(
3123 "fvdemote",
3124 r#"
3125 Convert `x` to a smaller floating point format.
3126
3127 Each lane in `x` is converted to the destination floating point format
3128 by rounding to nearest, ties to even.
3129
3130 Cranelift currently only supports two floating point formats
3131 - `f32` and `f64`. This may change in the future.
3132
3133 Fvdemote differs from fdemote in that with fvdemote it targets vectors.
3134 Fvdemote is constrained to having the input type being F64x2 and the result
3135 type being F32x4. The result lane that was the upper half of the input lane
3136 is initialized to zero.
3137 "#,
3138 &formats.unary,
3139 )
3140 .operands_in(vec![Operand::new("x", F64x2)])
3141 .operands_out(vec![Operand::new("a", F32x4)]),
3142 );
3143
3144 ig.push(
3145 Inst::new(
3146 "fvpromote_low",
3147 r#"
3148 Converts packed single precision floating point to packed double precision floating point.
3149
3150 Considering only the lower half of the register, the low lanes in `x` are interpreted as
3151 single precision floats that are then converted to a double precision floats.
3152
3153 The result type will have half the number of vector lanes as the input. Fvpromote_low is
3154 constrained to input F32x4 with a result type of F64x2.
3155 "#,
3156 &formats.unary,
3157 )
3158 .operands_in(vec![Operand::new("a", F32x4)])
3159 .operands_out(vec![Operand::new("x", F64x2)]),
3160 );
3161
3162 let IntTo = &TypeVar::new(
3163 "IntTo",
3164 "An scalar only integer type",
3165 TypeSetBuilder::new().ints(Interval::All).build(),
3166 );
3167
3168 ig.push(
3169 Inst::new(
3170 "fcvt_to_uint",
3171 r#"
3172 Converts floating point scalars to unsigned integer.
3173
3174 Only operates on `x` if it is a scalar. If `x` is NaN or if
3175 the unsigned integral value cannot be represented in the result
3176 type, this instruction traps.
3177
3178 "#,
3179 &formats.unary,
3180 )
3181 .operands_in(vec![Operand::new("x", FloatScalar)])
3182 .operands_out(vec![Operand::new("a", IntTo)])
3183 .can_trap()
3184 .side_effects_idempotent(),
3185 );
3186
3187 ig.push(
3188 Inst::new(
3189 "fcvt_to_sint",
3190 r#"
3191 Converts floating point scalars to signed integer.
3192
3193 Only operates on `x` if it is a scalar. If `x` is NaN or if
3194 the unsigned integral value cannot be represented in the result
3195 type, this instruction traps.
3196
3197 "#,
3198 &formats.unary,
3199 )
3200 .operands_in(vec![Operand::new("x", FloatScalar)])
3201 .operands_out(vec![Operand::new("a", IntTo)])
3202 .can_trap()
3203 .side_effects_idempotent(),
3204 );
3205
3206 let IntTo = &TypeVar::new(
3207 "IntTo",
3208 "A larger integer type with the same number of lanes",
3209 TypeSetBuilder::new()
3210 .ints(Interval::All)
3211 .simd_lanes(Interval::All)
3212 .build(),
3213 );
3214
3215 ig.push(
3216 Inst::new(
3217 "fcvt_to_uint_sat",
3218 r#"
3219 Convert floating point to unsigned integer as fcvt_to_uint does, but
3220 saturates the input instead of trapping. NaN and negative values are
3221 converted to 0.
3222 "#,
3223 &formats.unary,
3224 )
3225 .operands_in(vec![Operand::new("x", Float)])
3226 .operands_out(vec![Operand::new("a", IntTo)]),
3227 );
3228
3229 ig.push(
3230 Inst::new(
3231 "fcvt_to_sint_sat",
3232 r#"
3233 Convert floating point to signed integer as fcvt_to_sint does, but
3234 saturates the input instead of trapping. NaN values are converted to 0.
3235 "#,
3236 &formats.unary,
3237 )
3238 .operands_in(vec![Operand::new("x", Float)])
3239 .operands_out(vec![Operand::new("a", IntTo)]),
3240 );
3241
3242 ig.push(
3243 Inst::new(
3244 "x86_cvtt2dq",
3245 r#"
3246 A float-to-integer conversion instruction for vectors-of-floats which
3247 has the same semantics as `cvttp{s,d}2dq` on x86. This specifically
3248 returns `INT_MIN` for NaN or out-of-bounds lanes.
3249 "#,
3250 &formats.unary,
3251 )
3252 .operands_in(vec![Operand::new("x", Float)])
3253 .operands_out(vec![Operand::new("a", IntTo)]),
3254 );
3255
3256 let Int = &TypeVar::new(
3257 "Int",
3258 "A scalar or vector integer type",
3259 TypeSetBuilder::new()
3260 .ints(Interval::All)
3261 .simd_lanes(Interval::All)
3262 .build(),
3263 );
3264
3265 let FloatTo = &TypeVar::new(
3266 "FloatTo",
3267 "A scalar or vector floating point number",
3268 TypeSetBuilder::new()
3269 .floats(Interval::All)
3270 .simd_lanes(Interval::All)
3271 .build(),
3272 );
3273
3274 ig.push(
3275 Inst::new(
3276 "fcvt_from_uint",
3277 r#"
3278 Convert unsigned integer to floating point.
3279
3280 Each lane in `x` is interpreted as an unsigned integer and converted to
3281 floating point using round to nearest, ties to even.
3282
3283 The result type must have the same number of vector lanes as the input.
3284 "#,
3285 &formats.unary,
3286 )
3287 .operands_in(vec![Operand::new("x", Int)])
3288 .operands_out(vec![Operand::new("a", FloatTo)]),
3289 );
3290
3291 ig.push(
3292 Inst::new(
3293 "fcvt_from_sint",
3294 r#"
3295 Convert signed integer to floating point.
3296
3297 Each lane in `x` is interpreted as a signed integer and converted to
3298 floating point using round to nearest, ties to even.
3299
3300 The result type must have the same number of vector lanes as the input.
3301 "#,
3302 &formats.unary,
3303 )
3304 .operands_in(vec![Operand::new("x", Int)])
3305 .operands_out(vec![Operand::new("a", FloatTo)]),
3306 );
3307
3308 let WideInt = &TypeVar::new(
3309 "WideInt",
3310 "An integer type of width `i16` upwards",
3311 TypeSetBuilder::new().ints(16..128).build(),
3312 );
3313
3314 ig.push(
3315 Inst::new(
3316 "isplit",
3317 r#"
3318 Split an integer into low and high parts.
3319
3320 Vectors of integers are split lane-wise, so the results have the same
3321 number of lanes as the input, but the lanes are half the size.
3322
3323 Returns the low half of `x` and the high half of `x` as two independent
3324 values.
3325 "#,
3326 &formats.unary,
3327 )
3328 .operands_in(vec![Operand::new("x", WideInt)])
3329 .operands_out(vec![
3330 Operand::new("lo", &WideInt.half_width()).with_doc("The low bits of `x`"),
3331 Operand::new("hi", &WideInt.half_width()).with_doc("The high bits of `x`"),
3332 ]),
3333 );
3334
3335 ig.push(
3336 Inst::new(
3337 "iconcat",
3338 r#"
3339 Concatenate low and high bits to form a larger integer type.
3340
3341 Vectors of integers are concatenated lane-wise such that the result has
3342 the same number of lanes as the inputs, but the lanes are twice the
3343 size.
3344 "#,
3345 &formats.binary,
3346 )
3347 .operands_in(vec![
3348 Operand::new("lo", NarrowInt),
3349 Operand::new("hi", NarrowInt),
3350 ])
3351 .operands_out(vec![
3352 Operand::new("a", &NarrowInt.double_width())
3353 .with_doc("The concatenation of `lo` and `hi`"),
3354 ]),
3355 );
3356
3357 let AtomicMem = &TypeVar::new(
3359 "AtomicMem",
3360 "Any type that can be stored in memory, which can be used in an atomic operation",
3361 TypeSetBuilder::new().ints(8..128).build(),
3362 );
3363
3364 ig.push(
3365 Inst::new(
3366 "atomic_rmw",
3367 r#"
3368 Atomically read-modify-write memory at `p`, with second operand `x`. The old value is
3369 returned. `p` has the type of the target word size, and `x` may be any integer type; note
3370 that some targets require specific target features to be enabled in order to support 128-bit
3371 integer atomics. The type of the returned value is the same as the type of `x`. This
3372 operation is sequentially consistent and creates happens-before edges that order normal
3373 (non-atomic) loads and stores.
3374 "#,
3375 &formats.atomic_rmw,
3376 )
3377 .operands_in(vec![
3378 Operand::new("MemFlags", &imm.memflags),
3379 Operand::new("AtomicRmwOp", &imm.atomic_rmw_op),
3380 Operand::new("p", iAddr),
3381 Operand::new("x", AtomicMem).with_doc("Value to be atomically stored"),
3382 ])
3383 .operands_out(vec![
3384 Operand::new("a", AtomicMem).with_doc("Value atomically loaded"),
3385 ])
3386 .can_load()
3387 .can_store()
3388 .other_side_effects(),
3389 );
3390
3391 ig.push(
3392 Inst::new(
3393 "atomic_cas",
3394 r#"
3395 Perform an atomic compare-and-swap operation on memory at `p`, with expected value `e`,
3396 storing `x` if the value at `p` equals `e`. The old value at `p` is returned,
3397 regardless of whether the operation succeeds or fails. `p` has the type of the target
3398 word size, and `x` and `e` must have the same type and the same size, which may be any
3399 integer type; note that some targets require specific target features to be enabled in order
3400 to support 128-bit integer atomics. The type of the returned value is the same as the type
3401 of `x` and `e`. This operation is sequentially consistent and creates happens-before edges
3402 that order normal (non-atomic) loads and stores.
3403 "#,
3404 &formats.atomic_cas,
3405 )
3406 .operands_in(vec![
3407 Operand::new("MemFlags", &imm.memflags),
3408 Operand::new("p", iAddr),
3409 Operand::new("e", AtomicMem).with_doc("Expected value in CAS"),
3410 Operand::new("x", AtomicMem).with_doc("Value to be atomically stored"),
3411 ])
3412 .operands_out(vec![
3413 Operand::new("a", AtomicMem).with_doc("Value atomically loaded"),
3414 ])
3415 .can_load()
3416 .can_store()
3417 .other_side_effects(),
3418 );
3419
3420 ig.push(
3421 Inst::new(
3422 "atomic_load",
3423 r#"
3424 Atomically load from memory at `p`.
3425
3426 This is a polymorphic instruction that can load any value type which has a memory
3427 representation. It can only be used for integer types; note that some targets require
3428 specific target features to be enabled in order to support 128-bit integer atomics. This
3429 operation is sequentially consistent and creates happens-before edges that order normal
3430 (non-atomic) loads and stores.
3431 "#,
3432 &formats.load_no_offset,
3433 )
3434 .operands_in(vec![
3435 Operand::new("MemFlags", &imm.memflags),
3436 Operand::new("p", iAddr),
3437 ])
3438 .operands_out(vec![
3439 Operand::new("a", AtomicMem).with_doc("Value atomically loaded"),
3440 ])
3441 .can_load()
3442 .other_side_effects(),
3443 );
3444
3445 ig.push(
3446 Inst::new(
3447 "atomic_store",
3448 r#"
3449 Atomically store `x` to memory at `p`.
3450
3451 This is a polymorphic instruction that can store any value type with a memory
3452 representation. It can only be used for integer types; note that some targets require
3453 specific target features to be enabled in order to support 128-bit integer atomics This
3454 operation is sequentially consistent and creates happens-before edges that order normal
3455 (non-atomic) loads and stores.
3456 "#,
3457 &formats.store_no_offset,
3458 )
3459 .operands_in(vec![
3460 Operand::new("MemFlags", &imm.memflags),
3461 Operand::new("x", AtomicMem).with_doc("Value to be atomically stored"),
3462 Operand::new("p", iAddr),
3463 ])
3464 .can_store()
3465 .other_side_effects(),
3466 );
3467
3468 ig.push(
3469 Inst::new(
3470 "fence",
3471 r#"
3472 A memory fence. This must provide ordering to ensure that, at a minimum, neither loads
3473 nor stores of any kind may move forwards or backwards across the fence. This operation
3474 is sequentially consistent.
3475 "#,
3476 &formats.nullary,
3477 )
3478 .other_side_effects(),
3479 );
3480
3481 let TxN = &TypeVar::new(
3482 "TxN",
3483 "A dynamic vector type",
3484 TypeSetBuilder::new()
3485 .ints(Interval::All)
3486 .floats(Interval::All)
3487 .dynamic_simd_lanes(Interval::All)
3488 .build(),
3489 );
3490
3491 ig.push(
3492 Inst::new(
3493 "extract_vector",
3494 r#"
3495 Return a fixed length sub vector, extracted from a dynamic vector.
3496 "#,
3497 &formats.binary_imm8,
3498 )
3499 .operands_in(vec![
3500 Operand::new("x", TxN).with_doc("The dynamic vector to extract from"),
3501 Operand::new("y", &imm.uimm8).with_doc("128-bit vector index"),
3502 ])
3503 .operands_out(vec![
3504 Operand::new("a", &TxN.dynamic_to_vector()).with_doc("New fixed vector"),
3505 ]),
3506 );
3507
3508 ig.push(
3509 Inst::new(
3510 "sequence_point",
3511 r#"
3512 A compiler barrier that acts as an immovable marker from IR input to machine-code output.
3513
3514 This "sequence point" can have debug tags attached to it, and these tags will be
3515 noted in the output `MachBuffer`.
3516
3517 It prevents motion of any other side-effects across this boundary.
3518 "#,
3519 &formats.nullary,
3520 )
3521 .other_side_effects(),
3522 );
3523}