use rucc_target::{ClassInfo, RegFile};
static GPR: [&str; 8] = ["rax", "rcx", "rdx", "rbx", "rsi", "rdi", "rsp", "rbp"];
static XMM: [&str; 4] = ["xmm0", "xmm1", "xmm2", "xmm3"];
static CLASSES: [ClassInfo; 2] = [
ClassInfo { name: "gpr", bits: 64, regs: &GPR, allocatable: true },
ClassInfo { name: "xmm", bits: 128, regs: &XMM, allocatable: true },
];
pub(crate) static REGS: RegFile = RegFile::new(&CLASSES);
pub(crate) const BEFORE: &str = "\
mfunc @scale {
block0(%0:gpr, %1:gpr):
%2:gpr = x64.mov_ri 4
%3:gpr(reuse 1) = x64.imul_rr %1, %2
x64.cmp_ri %0, 0
x64.jle block2(%0), block1(%3, %1)
block1(%4:gpr, %5:gpr):
%6:gpr = x64.lea [%4 + %5*4 + 16]
%7:gpr = x64.mov_rm [@counter + 8]
x64.mov_mi [%6 - 4], 1
%8:gpr($rax), early %9:gpr($rdx) = x64.idiv_rr %7($rax), %6(any)
x64.cmp_rr %8, %9(stack)
x64.jmp block2(%8)
block2(%10:gpr):
%11:xmm = x64.movd_xr %10
x64.ret $rax
}
";
pub(crate) const AFTER: &str = "\
mfunc @scale {
block0:
$rcx = x64.mov_ri 4
$rax = x64.imul_rr $rax, $rcx
x64.cmp_ri $rdi, 0
x64.jle block2, block1
block1:
$rdx = x64.lea [$rax + $rcx*4 + 16]
x64.mov_mi [$rdx - 4], 1
x64.jmp block2
block2:
x64.ret $rax
}
";