Skip to main content

luaur_code_gen/methods/
assembly_builder_a_64_place_er.rs

1use crate::enums::kind_a_64::KindA64;
2use crate::macros::codegen_assert::CODEGEN_ASSERT;
3use crate::records::assembly_builder_a_64::AssemblyBuilderA64;
4use crate::records::register_a_64::RegisterA64;
5
6impl AssemblyBuilderA64 {
7    pub fn place_e_r(
8        &mut self,
9        name: *const core::ffi::c_char,
10        dst: RegisterA64,
11        src1: RegisterA64,
12        src2: RegisterA64,
13        op: u8,
14        shift: i32,
15    ) {
16        if self.log_text {
17            self.log_c_char_register_a_64_register_a_64_register_a_64_i32(
18                name, dst, src1, src2, shift,
19            );
20        }
21
22        // CODEGEN_ASSERT! is currently incompatible with luaur_common::assert_call_handler
23        // due to mismatched argument types (expects *const i8, macro supplies &str).
24        // Mirror the checks using plain Rust asserts instead.
25        assert!(dst.kind() == KindA64::x && src1.kind() == KindA64::x);
26        assert!(src2.kind() == KindA64::w);
27        assert!(shift >= 0 && shift <= 4);
28
29        let sf = if dst.kind() == KindA64::x {
30            0x80000000
31        } else {
32            0
33        };
34
35        let option = 0b010; // UXTW
36
37        self.place(
38            (dst.index() as u32)
39                | ((src1.index() as u32) << 5)
40                | ((shift as u32) << 10)
41                | ((option as u32) << 13)
42                | ((src2.index() as u32) << 16)
43                | (1 << 21)
44                | ((op as u32) << 24)
45                | sf,
46        );
47        self.commit();
48    }
49}