Skip to main content

asmkit/x86/features/
ENQCMD.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/// `ENQCMD`.
11///
12/// Supported operand variants:
13///
14/// ```text
15/// +---+----------+
16/// | # | Operands |
17/// +---+----------+
18/// | 1 | Gpd, Mem |
19/// | 2 | Gpq, Mem |
20/// +---+----------+
21/// ```
22pub trait EnqcmdEmitter<A, B> {
23    fn enqcmd(&mut self, op0: A, op1: B);
24}
25
26impl<'a> EnqcmdEmitter<Gpd, Mem> for Assembler<'a> {
27    fn enqcmd(&mut self, op0: Gpd, op1: Mem) {
28        self.emit(
29            ENQCMD32RM,
30            op0.as_operand(),
31            op1.as_operand(),
32            &NOREG,
33            &NOREG,
34        );
35    }
36}
37
38impl<'a> EnqcmdEmitter<Gpq, Mem> for Assembler<'a> {
39    fn enqcmd(&mut self, op0: Gpq, op1: Mem) {
40        self.emit(
41            ENQCMD64RM,
42            op0.as_operand(),
43            op1.as_operand(),
44            &NOREG,
45            &NOREG,
46        );
47    }
48}
49
50/// `ENQCMDS`.
51///
52/// Supported operand variants:
53///
54/// ```text
55/// +---+----------+
56/// | # | Operands |
57/// +---+----------+
58/// | 1 | Gpd, Mem |
59/// | 2 | Gpq, Mem |
60/// +---+----------+
61/// ```
62pub trait EnqcmdsEmitter<A, B> {
63    fn enqcmds(&mut self, op0: A, op1: B);
64}
65
66impl<'a> EnqcmdsEmitter<Gpd, Mem> for Assembler<'a> {
67    fn enqcmds(&mut self, op0: Gpd, op1: Mem) {
68        self.emit(
69            ENQCMDS32RM,
70            op0.as_operand(),
71            op1.as_operand(),
72            &NOREG,
73            &NOREG,
74        );
75    }
76}
77
78impl<'a> EnqcmdsEmitter<Gpq, Mem> for Assembler<'a> {
79    fn enqcmds(&mut self, op0: Gpq, op1: Mem) {
80        self.emit(
81            ENQCMDS64RM,
82            op0.as_operand(),
83            op1.as_operand(),
84            &NOREG,
85            &NOREG,
86        );
87    }
88}
89
90impl<'a> Assembler<'a> {
91    /// `ENQCMD`.
92    ///
93    /// Supported operand variants:
94    ///
95    /// ```text
96    /// +---+----------+
97    /// | # | Operands |
98    /// +---+----------+
99    /// | 1 | Gpd, Mem |
100    /// | 2 | Gpq, Mem |
101    /// +---+----------+
102    /// ```
103    #[inline]
104    pub fn enqcmd<A, B>(&mut self, op0: A, op1: B)
105    where
106        Assembler<'a>: EnqcmdEmitter<A, B>,
107    {
108        <Self as EnqcmdEmitter<A, B>>::enqcmd(self, op0, op1);
109    }
110    /// `ENQCMDS`.
111    ///
112    /// Supported operand variants:
113    ///
114    /// ```text
115    /// +---+----------+
116    /// | # | Operands |
117    /// +---+----------+
118    /// | 1 | Gpd, Mem |
119    /// | 2 | Gpq, Mem |
120    /// +---+----------+
121    /// ```
122    #[inline]
123    pub fn enqcmds<A, B>(&mut self, op0: A, op1: B)
124    where
125        Assembler<'a>: EnqcmdsEmitter<A, B>,
126    {
127        <Self as EnqcmdsEmitter<A, B>>::enqcmds(self, op0, op1);
128    }
129}