Skip to main content

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