cranelift_assembler_x64/
inst.rs

1//! Expose all known instructions as Rust `struct`s; this is generated in
2//! `build.rs`.
3//!
4//! See also: [`Inst`], an `enum` containing all these instructions.
5
6use crate::Fixed;
7use crate::api::{AsReg, CodeSink, RegisterVisitor, Registers, TrapCode};
8use crate::evex::EvexPrefix;
9use crate::features::{AvailableFeatures, Feature, Features};
10use crate::gpr::{self, Gpr, Size};
11use crate::imm::{Extension, Imm8, Imm16, Imm32, Imm64, Simm8, Simm32};
12use crate::mem::{Amode, GprMem, XmmMem};
13use crate::rex::RexPrefix;
14use crate::vex::VexPrefix;
15use crate::xmm::{self, Xmm};
16
17use alloc::string::ToString;
18
19// Include code generated by the `meta` crate.
20include!(concat!(env!("OUT_DIR"), "/assembler.rs"));
21
22/// A macro listing all available CPU features.
23///
24/// This is generated from the `dsl::Feature` enumeration defined in the `meta`
25/// crate. It makes it easier to generate code based on the available features.
26///
27/// ```
28/// # use cranelift_assembler_x64::{AvailableFeatures, Fixed, for_each_feature, Imm8, inst, Registers};
29/// // Tell the assembler the type of registers we're using; we can always
30/// // encode a HW register as a `u8` (e.g., `eax = 0`).
31/// pub struct Regs;
32/// impl Registers for Regs {
33///     type ReadGpr = u8;
34///     type ReadWriteGpr = u8;
35///     type WriteGpr = u8;
36///     type ReadXmm = u8;
37///     type ReadWriteXmm = u8;
38///     type WriteXmm = u8;
39/// }
40///
41/// // Define a target that says all CPU features are available.
42/// macro_rules! return_true { ($($f:ident)+) => { $(fn $f(&self) -> bool { true })+ }; }
43/// struct AllFeatures;
44/// impl AvailableFeatures for AllFeatures {
45///     for_each_feature!(return_true);
46/// }
47///
48/// // Define a target that says no CPU features are available.
49/// macro_rules! return_false { ($($f:ident)+) => { $(fn $f(&self) -> bool { false })+ }; }
50/// struct NoFeatures;
51/// impl AvailableFeatures for NoFeatures {
52///     for_each_feature!(return_false);
53/// }
54///
55/// let rax: u8 = 0;
56/// let and = inst::andb_i::<Regs>::new(Fixed(rax), Imm8::new(0b10101010));
57///
58/// assert!(and.is_available(&AllFeatures));
59/// assert!(!and.is_available(&NoFeatures));
60/// ```
61#[doc(inline)]
62pub use for_each_feature;