Skip to main content

juicebox_asm/insn/
sar.rs

1// SPDX-License-Identifier: MIT
2//
3// Copyright (c) 2026, Johannes Stoelp <dev@memzero.de>
4
5use super::Sar;
6use crate::{imm::Imm, Asm, Imm8, Reg32, Reg8};
7
8impl Sar<Reg32, Imm8> for Asm {
9    fn sar(&mut self, op1: Reg32, op2: Imm8) {
10        if op2.bytes()[0] == 1 {
11            self.encode_r(&[0xd1], 0x7, op1);
12        } else {
13            self.encode_ri(0xc1, 0x7, op1, op2);
14        }
15    }
16}
17
18impl Sar<Reg32, Reg8> for Asm {
19    fn sar(&mut self, op1: Reg32, op2: Reg8) {
20        assert!(matches!(op2, Reg8::cl), "shl only takes cl");
21        self.encode_r(&[0xd3], 0x7, op1);
22    }
23}