luaur_code_gen/macros/rex_force.rs
1use crate::enums::size_x_64::SizeX64;
2use crate::records::register_x_64::RegisterX64;
3
4#[allow(non_snake_case)]
5pub const fn REX_FORCE(reg: RegisterX64) -> u8 {
6 // Note: RegisterX64::size() is not const, but we can compute it from bits.
7 // Based on RegisterX64's internal structure (bits), we extract the size.
8 let size_bits = reg.bits & RegisterX64::SIZE_MASK;
9
10 // SizeX64::byte is an enum variant. Since we cannot use == in const if the impl is not const,
11 // and size() is not const, we compare the raw bits against the discriminant of SizeX64::byte.
12 if size_bits == SizeX64::byte as u8 && reg.index() >= 4 {
13 0x40
14 } else {
15 0x00
16 }
17}