Skip to content

Commit

Permalink
Rename rotate left/rotate right instructions for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
koute committed Jan 24, 2025
1 parent d54149c commit 1c0f92d
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 50 deletions.
16 changes: 8 additions & 8 deletions crates/polkavm-common/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,10 +1509,10 @@ define_opcodes! {
[I_64, I_32] cmov_if_zero_imm = 147,
[I_64, I_32] cmov_if_not_zero_imm = 148,

[I_64, I_32] rotate_right_32_imm = 160,
[I_64, I_32] rotate_right_32_imm_alt = 161,
[I_64] rotate_right_64_imm = 158,
[I_64] rotate_right_64_imm_alt = 159,
[I_64, I_32] rotate_right_imm_32 = 160,
[I_64, I_32] rotate_right_imm_alt_32 = 161,
[I_64] rotate_right_imm_64 = 158,
[I_64] rotate_right_imm_alt_64 = 159,
]

// Instructions with args: reg, reg, offset
Expand Down Expand Up @@ -2503,7 +2503,7 @@ impl<'a, 'b, 'c> InstructionVisitor for InstructionFormatter<'a, 'b, 'c> {
write!(self, "{d} = {s} if {c} != 0")
}

fn rotate_right_32_imm(&mut self, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
fn rotate_right_imm_32(&mut self, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
let d = self.format_reg(d);
let s = self.format_reg(s);
let c = self.format_imm(c);
Expand All @@ -2514,7 +2514,7 @@ impl<'a, 'b, 'c> InstructionVisitor for InstructionFormatter<'a, 'b, 'c> {
}
}

fn rotate_right_32_imm_alt(&mut self, d: RawReg, c: RawReg, s: u32) -> Self::ReturnTy {
fn rotate_right_imm_alt_32(&mut self, d: RawReg, c: RawReg, s: u32) -> Self::ReturnTy {
let d = self.format_reg(d);
let c = self.format_reg(c);
let s = self.format_imm(s);
Expand All @@ -2525,14 +2525,14 @@ impl<'a, 'b, 'c> InstructionVisitor for InstructionFormatter<'a, 'b, 'c> {
}
}

fn rotate_right_64_imm(&mut self, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
fn rotate_right_imm_64(&mut self, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
let d = self.format_reg(d);
let s = self.format_reg(s);
let c = self.format_imm(c);
write!(self, "{d} = {s} >>r {c}")
}

fn rotate_right_64_imm_alt(&mut self, d: RawReg, c: RawReg, s: u32) -> Self::ReturnTy {
fn rotate_right_imm_alt_64(&mut self, d: RawReg, c: RawReg, s: u32) -> Self::ReturnTy {
let d = self.format_reg(d);
let c = self.format_reg(c);
let s = self.format_imm(s);
Expand Down
12 changes: 6 additions & 6 deletions crates/polkavm-linker/src/program_from_elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7476,9 +7476,9 @@ fn emit_code(
K::Mul32 => I::mul_imm_32(dst, src1, src2),
K::Mul32AndSignExtend => I::mul_imm_32(dst, src1, src2),
K::Mul64 => I::mul_imm_64(dst, src1, src2),
K::RotateRight32 => I::rotate_right_32_imm(dst, src1, src2),
K::RotateRight32AndSignExtend => I::rotate_right_32_imm(dst, src1, src2),
K::RotateRight64 => I::rotate_right_64_imm(dst, src1, src2),
K::RotateRight32 => I::rotate_right_imm_32(dst, src1, src2),
K::RotateRight32AndSignExtend => I::rotate_right_imm_32(dst, src1, src2),
K::RotateRight64 => I::rotate_right_imm_64(dst, src1, src2),
}
}
(RegImm::Imm(src1), RegImm::Reg(src2)) => {
Expand Down Expand Up @@ -7512,9 +7512,9 @@ fn emit_code(
K::ShiftArithmeticRight32AndSignExtend => I::shift_arithmetic_right_imm_alt_32(dst, src2, src1),
K::ShiftArithmeticRight64 => I::shift_arithmetic_right_imm_alt_64(dst, src2, src1),

K::RotateRight32 => I::rotate_right_32_imm_alt(dst, src2, src1),
K::RotateRight32AndSignExtend => I::rotate_right_32_imm_alt(dst, src2, src1),
K::RotateRight64 => I::rotate_right_64_imm_alt(dst, src2, src1),
K::RotateRight32 => I::rotate_right_imm_alt_32(dst, src2, src1),
K::RotateRight32AndSignExtend => I::rotate_right_imm_alt_32(dst, src2, src1),
K::RotateRight64 => I::rotate_right_imm_alt_64(dst, src2, src1),
}
}
(RegImm::Imm(src1), RegImm::Imm(src2)) => {
Expand Down
24 changes: 12 additions & 12 deletions crates/polkavm/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,34 +1204,34 @@ where
}

#[inline(always)]
fn rotate_right_32_imm(&mut self, code_offset: u32, args_length: u32, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
fn rotate_right_imm_32(&mut self, code_offset: u32, args_length: u32, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
self.before_instruction(code_offset);
self.gas_visitor.rotate_right_32_imm(d, s, c);
ArchVisitor(self).rotate_right_32_imm(d, s, c);
self.gas_visitor.rotate_right_imm_32(d, s, c);
ArchVisitor(self).rotate_right_imm_32(d, s, c);
self.after_instruction::<CONTINUE_BASIC_BLOCK>(code_offset, args_length);
}

#[inline(always)]
fn rotate_right_32_imm_alt(&mut self, code_offset: u32, args_length: u32, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
fn rotate_right_imm_alt_32(&mut self, code_offset: u32, args_length: u32, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
self.before_instruction(code_offset);
self.gas_visitor.rotate_right_32_imm_alt(d, s, c);
ArchVisitor(self).rotate_right_32_imm_alt(d, s, c);
self.gas_visitor.rotate_right_imm_alt_32(d, s, c);
ArchVisitor(self).rotate_right_imm_alt_32(d, s, c);
self.after_instruction::<CONTINUE_BASIC_BLOCK>(code_offset, args_length);
}

#[inline(always)]
fn rotate_right_64_imm(&mut self, code_offset: u32, args_length: u32, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
fn rotate_right_imm_64(&mut self, code_offset: u32, args_length: u32, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
self.before_instruction(code_offset);
self.gas_visitor.rotate_right_64_imm(d, s, c);
ArchVisitor(self).rotate_right_64_imm(d, s, c);
self.gas_visitor.rotate_right_imm_64(d, s, c);
ArchVisitor(self).rotate_right_imm_64(d, s, c);
self.after_instruction::<CONTINUE_BASIC_BLOCK>(code_offset, args_length);
}

#[inline(always)]
fn rotate_right_64_imm_alt(&mut self, code_offset: u32, args_length: u32, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
fn rotate_right_imm_alt_64(&mut self, code_offset: u32, args_length: u32, d: RawReg, s: RawReg, c: u32) -> Self::ReturnTy {
self.before_instruction(code_offset);
self.gas_visitor.rotate_right_64_imm_alt(d, s, c);
ArchVisitor(self).rotate_right_64_imm_alt(d, s, c);
self.gas_visitor.rotate_right_imm_alt_64(d, s, c);
ArchVisitor(self).rotate_right_imm_alt_64(d, s, c);
self.after_instruction::<CONTINUE_BASIC_BLOCK>(code_offset, args_length);
}

Expand Down
8 changes: 4 additions & 4 deletions crates/polkavm/src/compiler/amd64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2041,12 +2041,12 @@ where
}

#[inline(always)]
pub fn rotate_right_32_imm(&mut self, d: RawReg, s: RawReg, c: u32) {
pub fn rotate_right_imm_32(&mut self, d: RawReg, s: RawReg, c: u32) {
self.rotate_right_imm_generic(RegSize::R32, d, s, c);
}

#[inline(always)]
pub fn rotate_right_64_imm(&mut self, d: RawReg, s: RawReg, c: u32) {
pub fn rotate_right_imm_64(&mut self, d: RawReg, s: RawReg, c: u32) {
assert_eq!(B::BITNESS, Bitness::B64);
self.rotate_right_imm_generic(RegSize::R64, d, s, c);
}
Expand All @@ -2071,12 +2071,12 @@ where
}

#[inline(always)]
pub fn rotate_right_32_imm_alt(&mut self, d: RawReg, s: RawReg, c: u32) {
pub fn rotate_right_imm_alt_32(&mut self, d: RawReg, s: RawReg, c: u32) {
self.rotate_right_imm_alt_generic(RegSize::R32, d, s, c);
}

#[inline(always)]
pub fn rotate_right_64_imm_alt(&mut self, d: RawReg, s: RawReg, c: u32) {
pub fn rotate_right_imm_alt_64(&mut self, d: RawReg, s: RawReg, c: u32) {
assert_eq!(B::BITNESS, Bitness::B64);
self.rotate_right_imm_alt_generic(RegSize::R64, d, s, c);
}
Expand Down
8 changes: 4 additions & 4 deletions crates/polkavm/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,22 +430,22 @@ impl InstructionVisitor for GasVisitor {
}

#[inline(always)]
fn rotate_right_32_imm(&mut self, _d: RawReg, _s: RawReg, _c: u32) -> Self::ReturnTy {
fn rotate_right_imm_32(&mut self, _d: RawReg, _s: RawReg, _c: u32) -> Self::ReturnTy {
self.cost += 1;
}

#[inline(always)]
fn rotate_right_32_imm_alt(&mut self, _d: RawReg, _s: RawReg, _c: u32) -> Self::ReturnTy {
fn rotate_right_imm_alt_32(&mut self, _d: RawReg, _s: RawReg, _c: u32) -> Self::ReturnTy {
self.cost += 1;
}

#[inline(always)]
fn rotate_right_64_imm(&mut self, _d: RawReg, _s: RawReg, _c: u32) -> Self::ReturnTy {
fn rotate_right_imm_64(&mut self, _d: RawReg, _s: RawReg, _c: u32) -> Self::ReturnTy {
self.cost += 1;
}

#[inline(always)]
fn rotate_right_64_imm_alt(&mut self, _d: RawReg, _s: RawReg, _c: u32) -> Self::ReturnTy {
fn rotate_right_imm_alt_64(&mut self, _d: RawReg, _s: RawReg, _c: u32) -> Self::ReturnTy {
self.cost += 1;
}

Expand Down
32 changes: 16 additions & 16 deletions crates/polkavm/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2824,33 +2824,33 @@ define_interpreter! {
visitor.go_to_next_instruction()
}

fn rotate_right_32_imm<const DEBUG: bool>(visitor: &mut Visitor, d: Reg, s1: Reg, s2: u32) -> Option<Target> {
fn rotate_right_imm_32<const DEBUG: bool>(visitor: &mut Visitor, d: Reg, s1: Reg, s2: u32) -> Option<Target> {
if DEBUG {
log::trace!("[{}]: {}", visitor.inner.compiled_offset, asm::rotate_right_32_imm(d, s1, s2));
log::trace!("[{}]: {}", visitor.inner.compiled_offset, asm::rotate_right_imm_32(d, s1, s2));
}

visitor.set3_32::<DEBUG>(d, s1, s2, u32::rotate_right)
}

fn rotate_right_32_imm_alt<const DEBUG: bool>(visitor: &mut Visitor, d: Reg, s1: Reg, s2: u32) -> Option<Target> {
fn rotate_right_imm_alt_32<const DEBUG: bool>(visitor: &mut Visitor, d: Reg, s1: Reg, s2: u32) -> Option<Target> {
if DEBUG {
log::trace!("[{}]: {}", visitor.inner.compiled_offset, asm::rotate_right_32_imm_alt(d, s1, s2));
log::trace!("[{}]: {}", visitor.inner.compiled_offset, asm::rotate_right_imm_alt_32(d, s1, s2));
}

visitor.set3_32::<DEBUG>(d, s2, s1, u32::rotate_right)
}

fn rotate_right_64_imm<const DEBUG: bool>(visitor: &mut Visitor, d: Reg, s1: Reg, s2: u32) -> Option<Target> {
fn rotate_right_imm_64<const DEBUG: bool>(visitor: &mut Visitor, d: Reg, s1: Reg, s2: u32) -> Option<Target> {
if DEBUG {
log::trace!("[{}]: {}", visitor.inner.compiled_offset, asm::rotate_right_64_imm(d, s1, s2));
log::trace!("[{}]: {}", visitor.inner.compiled_offset, asm::rotate_right_imm_64(d, s1, s2));
}

visitor.set3_64::<DEBUG>(d, s1, s2, |s1, s2| u64::rotate_right(s1, cast(s2).truncate_to_u32()))
}

fn rotate_right_64_imm_alt<const DEBUG: bool>(visitor: &mut Visitor, d: Reg, s1: Reg, s2: u32) -> Option<Target> {
fn rotate_right_imm_alt_64<const DEBUG: bool>(visitor: &mut Visitor, d: Reg, s1: Reg, s2: u32) -> Option<Target> {
if DEBUG {
log::trace!("[{}]: {}", visitor.inner.compiled_offset, asm::rotate_right_64_imm_alt(d, s1, s2));
log::trace!("[{}]: {}", visitor.inner.compiled_offset, asm::rotate_right_imm_alt_64(d, s1, s2));
}

visitor.set3_64::<DEBUG>(d, s2, s1, |s2, s1| u64::rotate_right(s2, cast(s1).truncate_to_u32()))
Expand Down Expand Up @@ -4069,22 +4069,22 @@ impl<'a, const DEBUG: bool> InstructionVisitor for Compiler<'a, DEBUG> {
emit!(self, cmov_if_not_zero_imm(d, c, s));
}

fn rotate_right_32_imm(&mut self, d: RawReg, s1: RawReg, s2: u32) -> Self::ReturnTy {
emit!(self, rotate_right_32_imm(d, s1, s2));
fn rotate_right_imm_32(&mut self, d: RawReg, s1: RawReg, s2: u32) -> Self::ReturnTy {
emit!(self, rotate_right_imm_32(d, s1, s2));
}

fn rotate_right_32_imm_alt(&mut self, d: RawReg, s2: RawReg, s1: u32) -> Self::ReturnTy {
emit!(self, rotate_right_32_imm_alt(d, s2, s1));
fn rotate_right_imm_alt_32(&mut self, d: RawReg, s2: RawReg, s1: u32) -> Self::ReturnTy {
emit!(self, rotate_right_imm_alt_32(d, s2, s1));
}

fn rotate_right_64_imm(&mut self, d: RawReg, s1: RawReg, s2: u32) -> Self::ReturnTy {
fn rotate_right_imm_64(&mut self, d: RawReg, s1: RawReg, s2: u32) -> Self::ReturnTy {
self.assert_64_bit();
emit!(self, rotate_right_64_imm(d, s1, s2));
emit!(self, rotate_right_imm_64(d, s1, s2));
}

fn rotate_right_64_imm_alt(&mut self, d: RawReg, s2: RawReg, s1: u32) -> Self::ReturnTy {
fn rotate_right_imm_alt_64(&mut self, d: RawReg, s2: RawReg, s1: u32) -> Self::ReturnTy {
self.assert_64_bit();
emit!(self, rotate_right_64_imm_alt(d, s2, s1));
emit!(self, rotate_right_imm_alt_64(d, s2, s1));
}

fn add_imm_64(&mut self, d: RawReg, s1: RawReg, s2: u32) -> Self::ReturnTy {
Expand Down

0 comments on commit 1c0f92d

Please sign in to comment.