Skip to content

Commit

Permalink
Merge pull request bytecodealliance#2614 from kaseyc/nop
Browse files Browse the repository at this point in the history
Avoid creating 0-sized nops in x64's gen_nop().
  • Loading branch information
cfallin authored Jan 29, 2021
2 parents cbd7a6a + f76a9d4 commit ac60ad6
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cranelift/codegen/src/isa/x64/inst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ impl Inst {

impl Inst {
pub(crate) fn nop(len: u8) -> Self {
debug_assert!(len <= 16);
debug_assert!(len <= 15);
Self::Nop { len }
}

Expand Down Expand Up @@ -2602,11 +2602,11 @@ impl MachInst for Inst {
}

fn gen_zero_len_nop() -> Inst {
Inst::Nop { len: 0 }
Inst::nop(0)
}

fn gen_nop(preferred_size: usize) -> Inst {
Inst::nop((preferred_size % 16) as u8)
Inst::nop(std::cmp::min(preferred_size, 15) as u8)
}

fn maybe_direct_reload(&self, _reg: VirtualReg, _slot: SpillSlot) -> Option<Inst> {
Expand Down
2 changes: 1 addition & 1 deletion cranelift/codegen/src/machinst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ pub trait MachInst: Clone + Debug {
/// request a NOP of that size, or as close to it as possible. The machine
/// backend may return a NOP whose binary encoding is smaller than the
/// preferred size, but must not return a NOP that is larger. However,
/// the instruction must have a nonzero size.
/// the instruction must have a nonzero size if preferred_size is nonzero.
fn gen_nop(preferred_size: usize) -> Self;

/// Get the register universe for this backend.
Expand Down

0 comments on commit ac60ad6

Please sign in to comment.