Skip to main content

asmkit/x86/features/
AESNI.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/// `AESDEC`.
11///
12/// Supported operand variants:
13///
14/// ```text
15/// +---+----------+
16/// | # | Operands |
17/// +---+----------+
18/// | 1 | Xmm, Mem |
19/// | 2 | Xmm, Xmm |
20/// +---+----------+
21/// ```
22pub trait AesdecEmitter<A, B> {
23    fn aesdec(&mut self, op0: A, op1: B);
24}
25
26impl<'a> AesdecEmitter<Xmm, Xmm> for Assembler<'a> {
27    fn aesdec(&mut self, op0: Xmm, op1: Xmm) {
28        self.emit(AESDECRR, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
29    }
30}
31
32impl<'a> AesdecEmitter<Xmm, Mem> for Assembler<'a> {
33    fn aesdec(&mut self, op0: Xmm, op1: Mem) {
34        self.emit(AESDECRM, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
35    }
36}
37
38/// `AESDECLAST`.
39///
40/// Supported operand variants:
41///
42/// ```text
43/// +---+----------+
44/// | # | Operands |
45/// +---+----------+
46/// | 1 | Xmm, Mem |
47/// | 2 | Xmm, Xmm |
48/// +---+----------+
49/// ```
50pub trait AesdeclastEmitter<A, B> {
51    fn aesdeclast(&mut self, op0: A, op1: B);
52}
53
54impl<'a> AesdeclastEmitter<Xmm, Xmm> for Assembler<'a> {
55    fn aesdeclast(&mut self, op0: Xmm, op1: Xmm) {
56        self.emit(
57            AESDECLASTRR,
58            op0.as_operand(),
59            op1.as_operand(),
60            &NOREG,
61            &NOREG,
62        );
63    }
64}
65
66impl<'a> AesdeclastEmitter<Xmm, Mem> for Assembler<'a> {
67    fn aesdeclast(&mut self, op0: Xmm, op1: Mem) {
68        self.emit(
69            AESDECLASTRM,
70            op0.as_operand(),
71            op1.as_operand(),
72            &NOREG,
73            &NOREG,
74        );
75    }
76}
77
78/// `AESENC`.
79///
80/// Supported operand variants:
81///
82/// ```text
83/// +---+----------+
84/// | # | Operands |
85/// +---+----------+
86/// | 1 | Xmm, Mem |
87/// | 2 | Xmm, Xmm |
88/// +---+----------+
89/// ```
90pub trait AesencEmitter<A, B> {
91    fn aesenc(&mut self, op0: A, op1: B);
92}
93
94impl<'a> AesencEmitter<Xmm, Xmm> for Assembler<'a> {
95    fn aesenc(&mut self, op0: Xmm, op1: Xmm) {
96        self.emit(AESENCRR, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
97    }
98}
99
100impl<'a> AesencEmitter<Xmm, Mem> for Assembler<'a> {
101    fn aesenc(&mut self, op0: Xmm, op1: Mem) {
102        self.emit(AESENCRM, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
103    }
104}
105
106/// `AESENCLAST`.
107///
108/// Supported operand variants:
109///
110/// ```text
111/// +---+----------+
112/// | # | Operands |
113/// +---+----------+
114/// | 1 | Xmm, Mem |
115/// | 2 | Xmm, Xmm |
116/// +---+----------+
117/// ```
118pub trait AesenclastEmitter<A, B> {
119    fn aesenclast(&mut self, op0: A, op1: B);
120}
121
122impl<'a> AesenclastEmitter<Xmm, Xmm> for Assembler<'a> {
123    fn aesenclast(&mut self, op0: Xmm, op1: Xmm) {
124        self.emit(
125            AESENCLASTRR,
126            op0.as_operand(),
127            op1.as_operand(),
128            &NOREG,
129            &NOREG,
130        );
131    }
132}
133
134impl<'a> AesenclastEmitter<Xmm, Mem> for Assembler<'a> {
135    fn aesenclast(&mut self, op0: Xmm, op1: Mem) {
136        self.emit(
137            AESENCLASTRM,
138            op0.as_operand(),
139            op1.as_operand(),
140            &NOREG,
141            &NOREG,
142        );
143    }
144}
145
146/// `AESIMC`.
147///
148/// Supported operand variants:
149///
150/// ```text
151/// +---+----------+
152/// | # | Operands |
153/// +---+----------+
154/// | 1 | Xmm, Mem |
155/// | 2 | Xmm, Xmm |
156/// +---+----------+
157/// ```
158pub trait AesimcEmitter<A, B> {
159    fn aesimc(&mut self, op0: A, op1: B);
160}
161
162impl<'a> AesimcEmitter<Xmm, Xmm> for Assembler<'a> {
163    fn aesimc(&mut self, op0: Xmm, op1: Xmm) {
164        self.emit(AESIMCRR, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
165    }
166}
167
168impl<'a> AesimcEmitter<Xmm, Mem> for Assembler<'a> {
169    fn aesimc(&mut self, op0: Xmm, op1: Mem) {
170        self.emit(AESIMCRM, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
171    }
172}
173
174/// `AESKEYGENASSIST`.
175///
176/// Supported operand variants:
177///
178/// ```text
179/// +---+---------------+
180/// | # | Operands      |
181/// +---+---------------+
182/// | 1 | Xmm, Mem, Imm |
183/// | 2 | Xmm, Xmm, Imm |
184/// +---+---------------+
185/// ```
186pub trait AeskeygenassistEmitter<A, B, C> {
187    fn aeskeygenassist(&mut self, op0: A, op1: B, op2: C);
188}
189
190impl<'a> AeskeygenassistEmitter<Xmm, Xmm, Imm> for Assembler<'a> {
191    fn aeskeygenassist(&mut self, op0: Xmm, op1: Xmm, op2: Imm) {
192        self.emit(
193            AESKEYGENASSISTRRI,
194            op0.as_operand(),
195            op1.as_operand(),
196            op2.as_operand(),
197            &NOREG,
198        );
199    }
200}
201
202impl<'a> AeskeygenassistEmitter<Xmm, Mem, Imm> for Assembler<'a> {
203    fn aeskeygenassist(&mut self, op0: Xmm, op1: Mem, op2: Imm) {
204        self.emit(
205            AESKEYGENASSISTRMI,
206            op0.as_operand(),
207            op1.as_operand(),
208            op2.as_operand(),
209            &NOREG,
210        );
211    }
212}
213
214impl<'a> Assembler<'a> {
215    /// `AESDEC`.
216    ///
217    /// Supported operand variants:
218    ///
219    /// ```text
220    /// +---+----------+
221    /// | # | Operands |
222    /// +---+----------+
223    /// | 1 | Xmm, Mem |
224    /// | 2 | Xmm, Xmm |
225    /// +---+----------+
226    /// ```
227    #[inline]
228    pub fn aesdec<A, B>(&mut self, op0: A, op1: B)
229    where
230        Assembler<'a>: AesdecEmitter<A, B>,
231    {
232        <Self as AesdecEmitter<A, B>>::aesdec(self, op0, op1);
233    }
234    /// `AESDECLAST`.
235    ///
236    /// Supported operand variants:
237    ///
238    /// ```text
239    /// +---+----------+
240    /// | # | Operands |
241    /// +---+----------+
242    /// | 1 | Xmm, Mem |
243    /// | 2 | Xmm, Xmm |
244    /// +---+----------+
245    /// ```
246    #[inline]
247    pub fn aesdeclast<A, B>(&mut self, op0: A, op1: B)
248    where
249        Assembler<'a>: AesdeclastEmitter<A, B>,
250    {
251        <Self as AesdeclastEmitter<A, B>>::aesdeclast(self, op0, op1);
252    }
253    /// `AESENC`.
254    ///
255    /// Supported operand variants:
256    ///
257    /// ```text
258    /// +---+----------+
259    /// | # | Operands |
260    /// +---+----------+
261    /// | 1 | Xmm, Mem |
262    /// | 2 | Xmm, Xmm |
263    /// +---+----------+
264    /// ```
265    #[inline]
266    pub fn aesenc<A, B>(&mut self, op0: A, op1: B)
267    where
268        Assembler<'a>: AesencEmitter<A, B>,
269    {
270        <Self as AesencEmitter<A, B>>::aesenc(self, op0, op1);
271    }
272    /// `AESENCLAST`.
273    ///
274    /// Supported operand variants:
275    ///
276    /// ```text
277    /// +---+----------+
278    /// | # | Operands |
279    /// +---+----------+
280    /// | 1 | Xmm, Mem |
281    /// | 2 | Xmm, Xmm |
282    /// +---+----------+
283    /// ```
284    #[inline]
285    pub fn aesenclast<A, B>(&mut self, op0: A, op1: B)
286    where
287        Assembler<'a>: AesenclastEmitter<A, B>,
288    {
289        <Self as AesenclastEmitter<A, B>>::aesenclast(self, op0, op1);
290    }
291    /// `AESIMC`.
292    ///
293    /// Supported operand variants:
294    ///
295    /// ```text
296    /// +---+----------+
297    /// | # | Operands |
298    /// +---+----------+
299    /// | 1 | Xmm, Mem |
300    /// | 2 | Xmm, Xmm |
301    /// +---+----------+
302    /// ```
303    #[inline]
304    pub fn aesimc<A, B>(&mut self, op0: A, op1: B)
305    where
306        Assembler<'a>: AesimcEmitter<A, B>,
307    {
308        <Self as AesimcEmitter<A, B>>::aesimc(self, op0, op1);
309    }
310    /// `AESKEYGENASSIST`.
311    ///
312    /// Supported operand variants:
313    ///
314    /// ```text
315    /// +---+---------------+
316    /// | # | Operands      |
317    /// +---+---------------+
318    /// | 1 | Xmm, Mem, Imm |
319    /// | 2 | Xmm, Xmm, Imm |
320    /// +---+---------------+
321    /// ```
322    #[inline]
323    pub fn aeskeygenassist<A, B, C>(&mut self, op0: A, op1: B, op2: C)
324    where
325        Assembler<'a>: AeskeygenassistEmitter<A, B, C>,
326    {
327        <Self as AeskeygenassistEmitter<A, B, C>>::aeskeygenassist(self, op0, op1, op2);
328    }
329}