Skip to content

Commit

Permalink
winch aarch64 jmp_table
Browse files Browse the repository at this point in the history
  • Loading branch information
vulc41n committed Jul 31, 2024
1 parent b74d147 commit 5a54c64
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
18 changes: 18 additions & 0 deletions winch/codegen/src/isa/aarch64/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,24 @@ impl Assembler {
});
}

/// Emits a jump table sequence.
pub fn jmp_table(
&mut self,
targets: &[MachLabel],
default: MachLabel,
index: Reg,
tmp1: Reg,
tmp2: Reg,
) {
self.emit(Inst::JTSequence {
default,
targets: Box::new(targets.to_vec()),
ridx: index.into(),
rtmp1: Writable::from_reg(tmp1.into()),
rtmp2: Writable::from_reg(tmp2.into()),
});
}

/// Conditional Set sets the destination register to 1 if the condition
/// is true, and otherwise sets it to 0.
pub fn cset(&mut self, rd: Reg, cond: Cond) {
Expand Down
12 changes: 10 additions & 2 deletions winch/codegen/src/isa/aarch64/masm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,16 @@ impl Masm for MacroAssembler {
todo!()
}

fn jmp_table(&mut self, _targets: &[MachLabel], _index: Reg, _tmp: Reg) {
todo!()
fn jmp_table(&mut self, targets: &[MachLabel], index: Reg, tmp: Reg) {
// At least one default target.
assert!(targets.len() >= 1);
let max = targets.len() as u64 - 1;
self.asm.subs_ir(max, index, OperandSize::S64);
let default_index = max as usize;
let default = targets[default_index];
let rest = &targets[..default_index];
let tmp1 = regs::scratch();
self.asm.jmp_table(rest, default, index, tmp1, tmp);
}

fn trap(&mut self, _code: TrapCode) {
Expand Down

0 comments on commit 5a54c64

Please sign in to comment.