You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/registers/xcontrol.rs
+59-8
Original file line number
Diff line number
Diff line change
@@ -7,19 +7,43 @@ pub struct XCr0;
7
7
8
8
bitflags!{
9
9
/// Configuration flags of the XCr0 register.
10
+
///
11
+
/// For MPX, [`BNDREG`](XCr0Flags::BNDREG) and [`BNDCSR`](XCr0Flags::BNDCSR) must be set/unset simultaneously.
12
+
/// For AVX-512, [`OPMASK`](XCr0Flags::OPMASK), [`ZMM_HI256`](XCr0Flags::ZMM_HI256), and [`HI16_ZMM`](XCr0Flags::HI16_ZMM) must be set/unset simultaneously.
10
13
pubstructXCr0Flags:u64{
11
-
/// Enables x87 FPU
14
+
/// Enables using the x87 FPU state
15
+
/// with `XSAVE`/`XRSTOR`.
16
+
///
17
+
/// Must be set.
12
18
constX87 = 1;
13
-
/// Enables 128-bit (legacy) SSE
14
-
/// Must be set to enable AVX and YMM
19
+
/// Enables using MXCSR and the XMM registers
20
+
/// with `XSAVE`/`XRSTOR`.
21
+
///
22
+
/// Must be set if [`YMM`](XCr0Flags::YMM) is set.
15
23
constSSE = 1<<1;
16
-
/// Enables 256-bit SSE
17
-
/// Must be set to enable AVX
24
+
/// Enables AVX instructions and using the upper halves of the YMM registers
25
+
/// with `XSAVE`/`XRSTOR`.
18
26
constYMM = 1<<2;
19
-
/// When set, PKRU state management is supported by
20
-
/// ZSAVE/XRSTOR
27
+
/// Enables MPX instructions and using the BND0-BND3 bound registers
28
+
/// with `XSAVE`/`XRSTOR` (Intel Only).
29
+
constBNDREG = 1 << 3;
30
+
/// Enables MPX instructions and using the BNDCFGU and BNDSTATUS registers
31
+
/// with `XSAVE`/`XRSTOR` (Intel Only).
32
+
constBNDCSR = 1 << 4;
33
+
/// Enables AVX-512 instructions and using the K0-K7 mask registers
34
+
/// with `XSAVE`/`XRSTOR` (Intel Only).
35
+
constOPMASK = 1 << 5;
36
+
/// Enables AVX-512 instructions and using the upper halves of the lower ZMM registers
37
+
/// with `XSAVE`/`XRSTOR` (Intel Only).
38
+
constZMM_HI256 = 1 << 6;
39
+
/// Enables AVX-512 instructions and using the upper ZMM registers
40
+
/// with `XSAVE`/`XRSTOR` (Intel Only).
41
+
constHI16_ZMM = 1 << 7;
42
+
/// Enables using the PKRU register
43
+
/// with `XSAVE`/`XRSTOR`.
21
44
constMPK = 1<<9;
22
-
/// When set the Lightweight Profiling extensions are enabled
45
+
/// Enables Lightweight Profiling extensions and managing LWP state
46
+
/// with `XSAVE`/`XRSTOR` (AMD Only).
23
47
constLWP = 1<<62;
24
48
}
25
49
}
@@ -58,6 +82,7 @@ mod x86_64 {
58
82
/// Write XCR0 flags.
59
83
///
60
84
/// Preserves the value of reserved fields.
85
+
/// Panics if invalid combinations of [`XCr0Flags`] are set.
61
86
///
62
87
/// ## Safety
63
88
///
@@ -69,6 +94,32 @@ mod x86_64 {
69
94
let reserved = old_value & !(XCr0Flags::all().bits());
70
95
let new_value = reserved | flags.bits();
71
96
97
+
assert!(flags.contains(XCr0Flags::X87),"The X87 flag must be set");
98
+
if flags.contains(XCr0Flags::YMM){
99
+
assert!(
100
+
flags.contains(XCr0Flags::SSE),
101
+
"AVX/YMM cannot be enabled without enabling SSE"
102
+
);
103
+
}
104
+
let mpx = XCr0Flags::BNDREG | XCr0Flags::BNDCSR;
105
+
if flags.intersects(mpx){
106
+
assert!(
107
+
flags.contains(mpx),
108
+
"MPX flags XCr0.BNDREG and XCr0.BNDCSR must be set and unset together"
109
+
);
110
+
}
111
+
let avx512 = XCr0Flags::OPMASK | XCr0Flags::ZMM_HI256 | XCr0Flags::HI16_ZMM;
112
+
if flags.intersects(avx512){
113
+
assert!(
114
+
flags.contains(XCr0Flags::YMM),
115
+
"AVX-512 cannot be enabled without enabling AVX/YMM"
116
+
);
117
+
assert!(
118
+
flags.contains(avx512),
119
+
"AVX-512 flags XCR0.opmask, XCR0.ZMM_Hi256, and XCR0.Hi16_ZMM must be set and unset together"
0 commit comments