here's some rust:
#[derive(Copy, Clone)]
#[repr(u8)]
pub enum RotOps {
A = 0 << 3,
B = 1 << 3,
C = 2 << 3,
D = 3 << 3,
E = 4 << 3,
}
pub fn execute_op(op: RotOps) {
match op {
RotOps::A => { println!("a"); }
RotOps::B => { println!("b"); }
RotOps::C => { println!("c"); }
RotOps::D => { println!("d"); }
RotOps::E => { println!("e"); }
}
}
and if you're me, your first question looking at this would be "will llvm figure out that the branch table for that match can be indexed by shifting op right by 3?"
playground::execute_op:
sub rsp, 56 ; space for println
rol dil, 5 ; the rotate! but left by 5
movzx eax, dil ; instead of right by 3?
lea rcx, [rip + .LJTI0_0] ; jump table goop
movsxd rax, dword ptr [rcx + 4*rax]
add rax, rcx
jmp rax
so it did exactly the right thing, but with a rol instead of ror? why.
i guess i won't ask too many questions, it did exactly what i wanted. good job llvm!