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