1//! `i386` intrinsics
2
3use crate::arch::asm;
4
5/// Reads EFLAGS.
6///
7/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=__readeflags)
8#[cfg(target_arch = "x86")]
9#[inline(always)]
10#[stable(feature = "simd_x86", since = "1.27.0")]
11#[deprecated(
12 since = "1.29.0",
13 note = "See issue #51810 - use inline assembly instead"
14)]
15#[doc(hidden)]
16pub unsafe fn __readeflags() -> u32 {
17 let eflags: u32;
18 asm!("pushfd", "pop {}", out(reg) eflags, options(nomem, att_syntax));
19 eflags
20}
21
22/// Reads EFLAGS.
23///
24/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=__readeflags)
25#[cfg(target_arch = "x86_64")]
26#[inline(always)]
27#[stable(feature = "simd_x86", since = "1.27.0")]
28#[deprecated(
29 since = "1.29.0",
30 note = "See issue #51810 - use inline assembly instead"
31)]
32#[doc(hidden)]
33pub unsafe fn __readeflags() -> u64 {
34 let eflags: u64;
35 asm!("pushfq", "pop {}", out(reg) eflags, options(nomem, att_syntax));
36 eflags
37}
38
39/// Write EFLAGS.
40///
41/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=__writeeflags)
42#[cfg(target_arch = "x86")]
43#[inline(always)]
44#[stable(feature = "simd_x86", since = "1.27.0")]
45#[deprecated(
46 since = "1.29.0",
47 note = "See issue #51810 - use inline assembly instead"
48)]
49#[doc(hidden)]
50pub unsafe fn __writeeflags(eflags: u32) {
51 asm!("push {}", "popfd", in(reg) eflags, options(nomem, att_syntax));
52}
53
54/// Write EFLAGS.
55///
56/// [Intel's documentation](https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=__writeeflags)
57#[cfg(target_arch = "x86_64")]
58#[inline(always)]
59#[stable(feature = "simd_x86", since = "1.27.0")]
60#[deprecated(
61 since = "1.29.0",
62 note = "See issue #51810 - use inline assembly instead"
63)]
64#[doc(hidden)]
65pub unsafe fn __writeeflags(eflags: u64) {
66 asm!("push {}", "popfq", in(reg) eflags, options(nomem, att_syntax));
67}
68
69#[cfg(test)]
70mod tests {
71 use crate::core_arch::x86::*;
72
73 #[test]
74 #[cfg_attr(miri, ignore)] // Uses inline assembly
75 #[allow(deprecated)]
76 fn test_eflags() {
77 unsafe {
78 // reads eflags, writes them back, reads them again,
79 // and compare for equality:
80 let v = __readeflags();
81 __writeeflags(v);
82 let u = __readeflags();
83 assert_eq!(v, u);
84 }
85 }
86}
87