asmkit/x86/features/
POPCNT.rs1use crate::x86::assembler::*;
2use crate::x86::operands::*;
3use super::super::opcodes::*;
4use crate::core::emitter::*;
5use crate::core::operand::*;
6
7const NOREG: Operand = Operand::new();
9
10pub trait PopcntEmitter<A, B> {
31 fn popcnt(&mut self, op0: A, op1: B);
32}
33
34impl<'a> PopcntEmitter<Gpw, Gpw> for Assembler<'a> {
35 fn popcnt(&mut self, op0: Gpw, op1: Gpw) {
36 self.emit(POPCNT16RR, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
37 }
38}
39
40impl<'a> PopcntEmitter<Gpw, Mem> for Assembler<'a> {
41 fn popcnt(&mut self, op0: Gpw, op1: Mem) {
42 self.emit(POPCNT16RM, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
43 }
44}
45
46impl<'a> PopcntEmitter<Gpd, Gpd> for Assembler<'a> {
47 fn popcnt(&mut self, op0: Gpd, op1: Gpd) {
48 self.emit(POPCNT32RR, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
49 }
50}
51
52impl<'a> PopcntEmitter<Gpd, Mem> for Assembler<'a> {
53 fn popcnt(&mut self, op0: Gpd, op1: Mem) {
54 self.emit(POPCNT32RM, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
55 }
56}
57
58impl<'a> PopcntEmitter<Gpq, Gpq> for Assembler<'a> {
59 fn popcnt(&mut self, op0: Gpq, op1: Gpq) {
60 self.emit(POPCNT64RR, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
61 }
62}
63
64impl<'a> PopcntEmitter<Gpq, Mem> for Assembler<'a> {
65 fn popcnt(&mut self, op0: Gpq, op1: Mem) {
66 self.emit(POPCNT64RM, op0.as_operand(), op1.as_operand(), &NOREG, &NOREG);
67 }
68}
69
70
71impl<'a> Assembler<'a> {
72 #[inline]
93 pub fn popcnt<A, B>(&mut self, op0: A, op1: B)
94 where Assembler<'a>: PopcntEmitter<A, B> {
95 <Self as PopcntEmitter<A, B>>::popcnt(self, op0, op1);
96 }
97}