1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//! CPU features.
//!
//! Across generations, CPUs add features that include new instructions, e.g.,
//! [`Feature::sse`], [`Feature::avx`], etc. x64 instructions are governed by
//! boolean terms of these CPU features: e.g., `(_64b | compat) & ssse3`. These
//! terms are defined per instruction in the `meta` crate and are exposed to
//! users in two ways:
//! - via the [`Inst::is_available`] function, which uses the
//! [`AvailableFeatures`] trait below to query "is this instruction currently
//! allowed?"; use this for fast checks during compilation
//! - via the [`Inst::features`] function, which returns a fully-constructed
//! [`Features`] term; use this for time-insensitive analysis or
//! pretty-printing.
//!
//! ```rust
//! # use cranelift_assembler_x64::{Registers, inst};
//! # pub struct Regs;
//! # impl Registers for Regs {
//! # type ReadGpr = u8;
//! # type ReadWriteGpr = u8;
//! # type WriteGpr = u8;
//! # type ReadXmm = u8;
//! # type ReadWriteXmm = u8;
//! # type WriteXmm = u8;
//! # }
//! let xmm0: u8 = 0;
//! let andps = inst::andps_a::<Regs>::new(xmm0, xmm0);
//! assert_eq!(andps.features().to_string(), "((_64b | compat) & sse)");
//! ```
//!
//! [`Inst::is_available`]: crate::inst::Inst::is_available
//! [`Inst::features`]: crate::inst::Inst::features
use cratefor_each_feature;
use fmt;
// Helpfully generate `enum Feature`.
for_each_feature!;
// Helpfully generate trait functions in `AvailableFeatures`.
/// A trait for querying CPU features.
///
/// This is generated from the `dsl::Feature` enumeration defined in the `meta`
/// crate. It allows querying the CPUID features required by an instruction; see
/// [`Inst::is_available`] and [`for_each_feature`].
///
/// [`Inst::is_available`]: crate::inst::Inst::is_available
/// A boolean term of CPU features.
///
/// An instruction is valid when the boolean term (a recursive tree of `AND` and
/// `OR` terms) is satisfied; see [`Inst::features`].
///
/// [`Inst::features`]: crate::inst::Inst::features