Path: blob/main/winch/codegen/src/isa/x64/regs.rs
1693 views
//! X64 register definition.12use crate::isa::reg::Reg;3use crate::regset::RegBitSet;4use regalloc2::{PReg, RegClass};56const ENC_RAX: u8 = 0;7const ENC_RCX: u8 = 1;8const ENC_RDX: u8 = 2;9const ENC_RBX: u8 = 3;10const ENC_RSP: u8 = 4;11const ENC_RBP: u8 = 5;12const ENC_RSI: u8 = 6;13const ENC_RDI: u8 = 7;14const ENC_R8: u8 = 8;15const ENC_R9: u8 = 9;16const ENC_R10: u8 = 10;17const ENC_R11: u8 = 11;18const ENC_R12: u8 = 12;19const ENC_R13: u8 = 13;20const ENC_R14: u8 = 14;21const ENC_R15: u8 = 15;2223fn gpr(enc: u8) -> Reg {24Reg::new(PReg::new(enc as usize, RegClass::Int))25}2627/// Constructors for GPR.2829pub(crate) fn rsi() -> Reg {30gpr(ENC_RSI)31}32pub(crate) fn rdi() -> Reg {33gpr(ENC_RDI)34}35pub(crate) fn rax() -> Reg {36gpr(ENC_RAX)37}38pub(crate) fn rcx() -> Reg {39gpr(ENC_RCX)40}41pub(crate) fn rdx() -> Reg {42gpr(ENC_RDX)43}44pub(crate) fn r8() -> Reg {45gpr(ENC_R8)46}47pub(crate) fn r9() -> Reg {48gpr(ENC_R9)49}50pub(crate) fn r10() -> Reg {51gpr(ENC_R10)52}53pub(crate) fn r12() -> Reg {54gpr(ENC_R12)55}56pub(crate) fn r13() -> Reg {57gpr(ENC_R13)58}59/// Used as a pinned register to hold60/// the `VMContext`.61/// Non-allocatable in Winch's default62/// ABI, and callee-saved in SystemV and63/// Fastcall.64pub(crate) fn r14() -> Reg {65gpr(ENC_R14)66}6768pub(crate) fn vmctx() -> Reg {69r14()70}7172pub(crate) fn rbx() -> Reg {73gpr(ENC_RBX)74}7576pub(crate) fn r15() -> Reg {77gpr(ENC_R15)78}7980pub(crate) fn rsp() -> Reg {81gpr(ENC_RSP)82}83pub(crate) fn rbp() -> Reg {84gpr(ENC_RBP)85}8687/// Used as the scratch register.88/// Non-allocatable in Winch's default89/// ABI.90pub(crate) fn r11() -> Reg {91gpr(ENC_R11)92}9394fn fpr(enc: u8) -> Reg {95Reg::new(PReg::new(enc as usize, RegClass::Float))96}9798/// Constructors for FPR.99100pub(crate) fn xmm0() -> Reg {101fpr(0)102}103pub(crate) fn xmm1() -> Reg {104fpr(1)105}106pub(crate) fn xmm2() -> Reg {107fpr(2)108}109pub(crate) fn xmm3() -> Reg {110fpr(3)111}112pub(crate) fn xmm4() -> Reg {113fpr(4)114}115pub(crate) fn xmm5() -> Reg {116fpr(5)117}118pub(crate) fn xmm6() -> Reg {119fpr(6)120}121pub(crate) fn xmm7() -> Reg {122fpr(7)123}124pub(crate) fn xmm8() -> Reg {125fpr(8)126}127pub(crate) fn xmm9() -> Reg {128fpr(9)129}130pub(crate) fn xmm10() -> Reg {131fpr(10)132}133pub(crate) fn xmm11() -> Reg {134fpr(11)135}136pub(crate) fn xmm12() -> Reg {137fpr(12)138}139pub(crate) fn xmm13() -> Reg {140fpr(13)141}142pub(crate) fn xmm14() -> Reg {143fpr(14)144}145pub(crate) fn xmm15() -> Reg {146fpr(15)147}148149/// GPR count.150const GPR: u32 = 16;151/// FPR count.152const FPR: u32 = 16;153/// GPR index bound.154const MAX_GPR: u32 = GPR;155/// GPR index bound.156const MAX_FPR: u32 = FPR;157const ALL_GPR: u32 = (1 << GPR) - 1;158const ALL_FPR: u32 = (1 << FPR) - 1;159/// Bitmask of non-alloctable GPRs.160// R11: Is used as the scratch register.161// R14: Is a pinned register, used as the instance register.162const SCRATCH: u32 = 1 << ENC_R11;163const INSTANCE: u32 = 1 << ENC_R14;164pub(crate) const NON_ALLOCATABLE_GPR: u32 = (1 << ENC_RBP) | (1 << ENC_RSP) | SCRATCH | INSTANCE;165166/// Bitmask of non-alloctable FPRs.167// xmm15: Is used as the scratch register.168const SCRATCH_FPR: u32 = 1 << 15;169const NON_ALLOCATABLE_FPR: u32 = SCRATCH_FPR;170171/// Bitmask to represent the available general purpose registers.172const ALLOCATABLE_GPR: u32 = ALL_GPR & !NON_ALLOCATABLE_GPR;173/// Bitmask to represent the available floating point registers.174const ALLOCATABLE_FPR: u32 = ALL_FPR & !NON_ALLOCATABLE_FPR;175176/// Allocatable scratch general purpose registers.177const ALLOCATABLE_SCRATCH_GPR: u32 = SCRATCH;178/// Non-allocatable scratch general purpose registers.179const NON_ALLOCATABLE_SCRATCH_GPR: u32 = ALL_GPR & !SCRATCH;180181/// Allocatable scratch floating-point registers.182const ALLOCATABLE_SCRATCH_FPR: u32 = SCRATCH_FPR;183/// Non-allocatable scratch floating-point registers.184const NON_ALLOCATABLE_SCRATCH_FPR: u32 = ALL_FPR & !SCRATCH_FPR;185186/// Bitset for allocatable general purpose registers.187pub fn gpr_bit_set() -> RegBitSet {188RegBitSet::int(189ALLOCATABLE_GPR.into(),190NON_ALLOCATABLE_GPR.into(),191usize::try_from(MAX_GPR).unwrap(),192)193}194195/// Bitset for allocatable floating point registers.196pub fn fpr_bit_set() -> RegBitSet {197RegBitSet::float(198ALLOCATABLE_FPR.into(),199NON_ALLOCATABLE_FPR.into(),200usize::try_from(MAX_FPR).unwrap(),201)202}203204/// Bitset for allocatable scratch general purpose registers.205pub fn scratch_gpr_bitset() -> RegBitSet {206RegBitSet::int(207ALLOCATABLE_SCRATCH_GPR.into(),208NON_ALLOCATABLE_SCRATCH_GPR.into(),209usize::try_from(MAX_GPR).unwrap(),210)211}212213/// Bitset for allocatable scratch floating point registers.214pub fn scratch_fpr_bitset() -> RegBitSet {215RegBitSet::float(216ALLOCATABLE_SCRATCH_FPR.into(),217NON_ALLOCATABLE_SCRATCH_FPR.into(),218usize::try_from(MAX_FPR).unwrap(),219)220}221222223