Skip to main content

asmkit/x86/features/
3DNOW.rs

1use crate::x86::assembler::*;
2use crate::x86::operands::*;
3use super::super::opcodes::*;
4use crate::core::emitter::*;
5use crate::core::operand::*;
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(_3DNOWRRI, op0.as_operand(), op1.as_operand(), op2.as_operand(), &NOREG);
29    }
30}
31
32impl<'a> _3dnowEmitter<Mm, Mem, Imm> for Assembler<'a> {
33    fn _3dnow(&mut self, op0: Mm, op1: Mem, op2: Imm) {
34        self.emit(_3DNOWRMI, op0.as_operand(), op1.as_operand(), op2.as_operand(), &NOREG);
35    }
36}
37
38/// `FEMMS`.
39///
40/// Supported operand variants:
41///
42/// ```text
43/// +---+----------+
44/// | # | Operands |
45/// +---+----------+
46/// | 1 | (none)   |
47/// +---+----------+
48/// ```
49pub trait FemmsEmitter {
50    fn femms(&mut self);
51}
52
53impl<'a> FemmsEmitter for Assembler<'a> {
54    fn femms(&mut self) {
55        self.emit(FEMMS, &NOREG, &NOREG, &NOREG, &NOREG);
56    }
57}
58
59
60impl<'a> Assembler<'a> {
61    /// `3DNOW`.
62    ///
63    /// Supported operand variants:
64    ///
65    /// ```text
66    /// +---+--------------+
67    /// | # | Operands     |
68    /// +---+--------------+
69    /// | 1 | Mm, Mem, Imm |
70    /// | 2 | Mm, Mm, Imm  |
71    /// +---+--------------+
72    /// ```
73    #[inline]
74    pub fn _3dnow<A, B, C>(&mut self, op0: A, op1: B, op2: C)
75    where Assembler<'a>: _3dnowEmitter<A, B, C> {
76        <Self as _3dnowEmitter<A, B, C>>::_3dnow(self, op0, op1, op2);
77    }
78    /// `FEMMS`.
79    ///
80    /// Supported operand variants:
81    ///
82    /// ```text
83    /// +---+----------+
84    /// | # | Operands |
85    /// +---+----------+
86    /// | 1 | (none)   |
87    /// +---+----------+
88    /// ```
89    #[inline]
90    pub fn femms(&mut self)
91    where Assembler<'a>: FemmsEmitter {
92        <Self as FemmsEmitter>::femms(self);
93    }
94}