Skip to main content

asmkit/x86/features/
WAITPKG.rs

1use super::super::opcodes::*;
2use crate::core::emitter::*;
3use crate::core::operand::*;
4use crate::x86::assembler::*;
5use crate::x86::operands::*;
6
7/// A dummy operand that represents no register. Here just for simplicity.
8const NOREG: Operand = Operand::new();
9
10/// `TPAUSE`.
11///
12/// Supported operand variants:
13///
14/// ```text
15/// +---+----------+
16/// | # | Operands |
17/// +---+----------+
18/// | 1 | Gpd      |
19/// +---+----------+
20/// ```
21pub trait TpauseEmitter<A> {
22    fn tpause(&mut self, op0: A);
23}
24
25impl<'a> TpauseEmitter<Gpd> for Assembler<'a> {
26    fn tpause(&mut self, op0: Gpd) {
27        self.emit(TPAUSER, op0.as_operand(), &NOREG, &NOREG, &NOREG);
28    }
29}
30
31/// `UMONITOR`.
32///
33/// Supported operand variants:
34///
35/// ```text
36/// +---+----------+
37/// | # | Operands |
38/// +---+----------+
39/// | 1 | Gpd      |
40/// | 2 | Gpq      |
41/// +---+----------+
42/// ```
43pub trait UmonitorEmitter<A> {
44    fn umonitor(&mut self, op0: A);
45}
46
47impl<'a> UmonitorEmitter<Gpd> for Assembler<'a> {
48    fn umonitor(&mut self, op0: Gpd) {
49        self.emit(UMONITOR32R, op0.as_operand(), &NOREG, &NOREG, &NOREG);
50    }
51}
52
53impl<'a> UmonitorEmitter<Gpq> for Assembler<'a> {
54    fn umonitor(&mut self, op0: Gpq) {
55        self.emit(UMONITOR64R, op0.as_operand(), &NOREG, &NOREG, &NOREG);
56    }
57}
58
59/// `UMWAIT`.
60///
61/// Supported operand variants:
62///
63/// ```text
64/// +---+----------+
65/// | # | Operands |
66/// +---+----------+
67/// | 1 | Gpd      |
68/// +---+----------+
69/// ```
70pub trait UmwaitEmitter<A> {
71    fn umwait(&mut self, op0: A);
72}
73
74impl<'a> UmwaitEmitter<Gpd> for Assembler<'a> {
75    fn umwait(&mut self, op0: Gpd) {
76        self.emit(UMWAITR, op0.as_operand(), &NOREG, &NOREG, &NOREG);
77    }
78}
79
80impl<'a> Assembler<'a> {
81    /// `TPAUSE`.
82    ///
83    /// Supported operand variants:
84    ///
85    /// ```text
86    /// +---+----------+
87    /// | # | Operands |
88    /// +---+----------+
89    /// | 1 | Gpd      |
90    /// +---+----------+
91    /// ```
92    #[inline]
93    pub fn tpause<A>(&mut self, op0: A)
94    where
95        Assembler<'a>: TpauseEmitter<A>,
96    {
97        <Self as TpauseEmitter<A>>::tpause(self, op0);
98    }
99    /// `UMONITOR`.
100    ///
101    /// Supported operand variants:
102    ///
103    /// ```text
104    /// +---+----------+
105    /// | # | Operands |
106    /// +---+----------+
107    /// | 1 | Gpd      |
108    /// | 2 | Gpq      |
109    /// +---+----------+
110    /// ```
111    #[inline]
112    pub fn umonitor<A>(&mut self, op0: A)
113    where
114        Assembler<'a>: UmonitorEmitter<A>,
115    {
116        <Self as UmonitorEmitter<A>>::umonitor(self, op0);
117    }
118    /// `UMWAIT`.
119    ///
120    /// Supported operand variants:
121    ///
122    /// ```text
123    /// +---+----------+
124    /// | # | Operands |
125    /// +---+----------+
126    /// | 1 | Gpd      |
127    /// +---+----------+
128    /// ```
129    #[inline]
130    pub fn umwait<A>(&mut self, op0: A)
131    where
132        Assembler<'a>: UmwaitEmitter<A>,
133    {
134        <Self as UmwaitEmitter<A>>::umwait(self, op0);
135    }
136}