Skip to main content

asmkit/x86/features/
3DNOW.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/// `3DNOW`.
11///
12/// Supported operand variants:
13///
14/// ```text
15/// +---+--------------+
16/// | # | Operands     |
17/// +---+--------------+
18/// | 1 | Mm, Mem, Imm |
19/// | 2 | Mm, Mm, Imm  |
20/// +---+--------------+
21/// ```
22pub trait _3dnowEmitter<A, B, C> {
23    fn _3dnow(&mut self, op0: A, op1: B, op2: C);
24}
25
26impl<'a> _3dnowEmitter<Mm, Mm, Imm> for Assembler<'a> {
27    fn _3dnow(&mut self, op0: Mm, op1: Mm, op2: Imm) {
28        self.emit(
29            _3DNOWRRI,
30            op0.as_operand(),
31            op1.as_operand(),
32            op2.as_operand(),
33            &NOREG,
34        );
35    }
36}
37
38impl<'a> _3dnowEmitter<Mm, Mem, Imm> for Assembler<'a> {
39    fn _3dnow(&mut self, op0: Mm, op1: Mem, op2: Imm) {
40        self.emit(
41            _3DNOWRMI,
42            op0.as_operand(),
43            op1.as_operand(),
44            op2.as_operand(),
45            &NOREG,
46        );
47    }
48}
49
50/// `FEMMS`.
51///
52/// Supported operand variants:
53///
54/// ```text
55/// +---+----------+
56/// | # | Operands |
57/// +---+----------+
58/// | 1 | (none)   |
59/// +---+----------+
60/// ```
61pub trait FemmsEmitter {
62    fn femms(&mut self);
63}
64
65impl<'a> FemmsEmitter for Assembler<'a> {
66    fn femms(&mut self) {
67        self.emit(FEMMS, &NOREG, &NOREG, &NOREG, &NOREG);
68    }
69}
70
71impl<'a> Assembler<'a> {
72    /// `3DNOW`.
73    ///
74    /// Supported operand variants:
75    ///
76    /// ```text
77    /// +---+--------------+
78    /// | # | Operands     |
79    /// +---+--------------+
80    /// | 1 | Mm, Mem, Imm |
81    /// | 2 | Mm, Mm, Imm  |
82    /// +---+--------------+
83    /// ```
84    #[inline]
85    pub fn _3dnow<A, B, C>(&mut self, op0: A, op1: B, op2: C)
86    where
87        Assembler<'a>: _3dnowEmitter<A, B, C>,
88    {
89        <Self as _3dnowEmitter<A, B, C>>::_3dnow(self, op0, op1, op2);
90    }
91    /// `FEMMS`.
92    ///
93    /// Supported operand variants:
94    ///
95    /// ```text
96    /// +---+----------+
97    /// | # | Operands |
98    /// +---+----------+
99    /// | 1 | (none)   |
100    /// +---+----------+
101    /// ```
102    #[inline]
103    pub fn femms(&mut self)
104    where
105        Assembler<'a>: FemmsEmitter,
106    {
107        <Self as FemmsEmitter>::femms(self);
108    }
109}