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
17// Include code generated by the `meta` crate.
18include!(concat!(env!("OUT_DIR"), "/assembler.rs"));
19
20/// A macro listing all available CPU features.
21///
22/// This is generated from the `dsl::Feature` enumeration defined in the `meta`
23/// crate. It makes it easier to generate code based on the available features.
24///
25/// ```
26/// # use cranelift_assembler_x64::{AvailableFeatures, Fixed, for_each_feature, Imm8, inst, Registers};
27/// // Tell the assembler the type of registers we're using; we can always
28/// // encode a HW register as a `u8` (e.g., `eax = 0`).
29/// pub struct Regs;
30/// impl Registers for Regs {
31/// type ReadGpr = u8;
32/// type ReadWriteGpr = u8;
33/// type WriteGpr = u8;
34/// type ReadXmm = u8;
35/// type ReadWriteXmm = u8;
36/// type WriteXmm = u8;
37/// }
38///
39/// // Define a target that says all CPU features are available.
40/// macro_rules! return_true { ($($f:ident)+) => { $(fn $f(&self) -> bool { true })+ }; }
41/// struct AllFeatures;
42/// impl AvailableFeatures for AllFeatures {
43/// for_each_feature!(return_true);
44/// }
45///
46/// // Define a target that says no CPU features are available.
47/// macro_rules! return_false { ($($f:ident)+) => { $(fn $f(&self) -> bool { false })+ }; }
48/// struct NoFeatures;
49/// impl AvailableFeatures for NoFeatures {
50/// for_each_feature!(return_false);
51/// }
52///
53/// let rax: u8 = 0;
54/// let and = inst::andb_i::<Regs>::new(Fixed(rax), Imm8::new(0b10101010));
55///
56/// assert!(and.is_available(&AllFeatures));
57/// assert!(!and.is_available(&NoFeatures));
58/// ```
59#[doc(inline)]
60pub use for_each_feature;