Skip to main content

asmkit/x86/features/
PTWRITE.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/// `PTWRITE`.
11///
12/// Supported operand variants:
13///
14/// ```text
15/// +---+----------+
16/// | # | Operands |
17/// +---+----------+
18/// | 1 | Gpd      |
19/// | 2 | Gpq      |
20/// | 3 | Mem      |
21/// +---+----------+
22/// ```
23pub trait PtwriteEmitter<A> {
24    fn ptwrite(&mut self, op0: A);
25}
26
27impl<'a> PtwriteEmitter<Gpd> for Assembler<'a> {
28    fn ptwrite(&mut self, op0: Gpd) {
29        self.emit(PTWRITE32R, op0.as_operand(), &NOREG, &NOREG, &NOREG);
30    }
31}
32
33impl<'a> PtwriteEmitter<Mem> for Assembler<'a> {
34    fn ptwrite(&mut self, op0: Mem) {
35        self.emit(PTWRITE32M, op0.as_operand(), &NOREG, &NOREG, &NOREG);
36    }
37}
38
39impl<'a> PtwriteEmitter<Gpq> for Assembler<'a> {
40    fn ptwrite(&mut self, op0: Gpq) {
41        self.emit(PTWRITE64R, op0.as_operand(), &NOREG, &NOREG, &NOREG);
42    }
43}
44
45impl<'a> Assembler<'a> {
46    /// `PTWRITE`.
47    ///
48    /// Supported operand variants:
49    ///
50    /// ```text
51    /// +---+----------+
52    /// | # | Operands |
53    /// +---+----------+
54    /// | 1 | Gpd      |
55    /// | 2 | Gpq      |
56    /// | 3 | Mem      |
57    /// +---+----------+
58    /// ```
59    #[inline]
60    pub fn ptwrite<A>(&mut self, op0: A)
61    where
62        Assembler<'a>: PtwriteEmitter<A>,
63    {
64        <Self as PtwriteEmitter<A>>::ptwrite(self, op0);
65    }
66}