Path: blob/main/winch/codegen/src/isa/x64/regs.rs
3068 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 default ABI.62pub(crate) fn r14() -> Reg {63gpr(ENC_R14)64}6566pub(crate) fn vmctx() -> Reg {67r14()68}6970pub(crate) fn rbx() -> Reg {71gpr(ENC_RBX)72}7374pub(crate) fn r15() -> Reg {75gpr(ENC_R15)76}7778pub(crate) fn rsp() -> Reg {79gpr(ENC_RSP)80}81pub(crate) fn rbp() -> Reg {82gpr(ENC_RBP)83}8485/// Used as the scratch register.86/// Non-allocatable in Winch's default87/// ABI.88pub(crate) fn r11() -> Reg {89gpr(ENC_R11)90}9192fn fpr(enc: u8) -> Reg {93Reg::new(PReg::new(enc as usize, RegClass::Float))94}9596/// Constructors for FPR.9798pub(crate) fn xmm0() -> Reg {99fpr(0)100}101pub(crate) fn xmm1() -> Reg {102fpr(1)103}104pub(crate) fn xmm2() -> Reg {105fpr(2)106}107pub(crate) fn xmm3() -> Reg {108fpr(3)109}110pub(crate) fn xmm4() -> Reg {111fpr(4)112}113pub(crate) fn xmm5() -> Reg {114fpr(5)115}116pub(crate) fn xmm6() -> Reg {117fpr(6)118}119pub(crate) fn xmm7() -> Reg {120fpr(7)121}122pub(crate) fn xmm8() -> Reg {123fpr(8)124}125pub(crate) fn xmm9() -> Reg {126fpr(9)127}128pub(crate) fn xmm10() -> Reg {129fpr(10)130}131pub(crate) fn xmm11() -> Reg {132fpr(11)133}134pub(crate) fn xmm12() -> Reg {135fpr(12)136}137pub(crate) fn xmm13() -> Reg {138fpr(13)139}140pub(crate) fn xmm14() -> Reg {141fpr(14)142}143pub(crate) fn xmm15() -> Reg {144fpr(15)145}146147/// GPR count.148const GPR: u32 = 16;149/// FPR count.150const FPR: u32 = 16;151/// GPR index bound.152const MAX_GPR: u32 = GPR;153/// GPR index bound.154const MAX_FPR: u32 = FPR;155const ALL_GPR: u32 = (1 << GPR) - 1;156const ALL_FPR: u32 = (1 << FPR) - 1;157/// Bitmask of non-alloctable GPRs.158// R11: Is used as the scratch register.159// R14: Is a pinned register, used as the instance register.160const SCRATCH: u32 = 1 << ENC_R11;161const INSTANCE: u32 = 1 << ENC_R14;162pub(crate) const NON_ALLOCATABLE_GPR: u32 = (1 << ENC_RBP) | (1 << ENC_RSP) | SCRATCH | INSTANCE;163164/// Bitmask of non-alloctable FPRs.165// xmm15: Is used as the scratch register.166const SCRATCH_FPR: u32 = 1 << 15;167const NON_ALLOCATABLE_FPR: u32 = SCRATCH_FPR;168169/// Bitmask to represent the available general purpose registers.170const ALLOCATABLE_GPR: u32 = ALL_GPR & !NON_ALLOCATABLE_GPR;171/// Bitmask to represent the available floating point registers.172const ALLOCATABLE_FPR: u32 = ALL_FPR & !NON_ALLOCATABLE_FPR;173174/// Allocatable scratch general purpose registers.175const ALLOCATABLE_SCRATCH_GPR: u32 = SCRATCH;176/// Non-allocatable scratch general purpose registers.177const NON_ALLOCATABLE_SCRATCH_GPR: u32 = ALL_GPR & !SCRATCH;178179/// Allocatable scratch floating-point registers.180const ALLOCATABLE_SCRATCH_FPR: u32 = SCRATCH_FPR;181/// Non-allocatable scratch floating-point registers.182const NON_ALLOCATABLE_SCRATCH_FPR: u32 = ALL_FPR & !SCRATCH_FPR;183184/// Bitset for allocatable general purpose registers.185pub fn gpr_bit_set() -> RegBitSet {186RegBitSet::int(187ALLOCATABLE_GPR.into(),188NON_ALLOCATABLE_GPR.into(),189usize::try_from(MAX_GPR).unwrap(),190)191}192193/// Bitset for allocatable floating point registers.194pub fn fpr_bit_set() -> RegBitSet {195RegBitSet::float(196ALLOCATABLE_FPR.into(),197NON_ALLOCATABLE_FPR.into(),198usize::try_from(MAX_FPR).unwrap(),199)200}201202/// Bitset for allocatable scratch general purpose registers.203pub fn scratch_gpr_bitset() -> RegBitSet {204RegBitSet::int(205ALLOCATABLE_SCRATCH_GPR.into(),206NON_ALLOCATABLE_SCRATCH_GPR.into(),207usize::try_from(MAX_GPR).unwrap(),208)209}210211/// Bitset for allocatable scratch floating point registers.212pub fn scratch_fpr_bitset() -> RegBitSet {213RegBitSet::float(214ALLOCATABLE_SCRATCH_FPR.into(),215NON_ALLOCATABLE_SCRATCH_FPR.into(),216usize::try_from(MAX_FPR).unwrap(),217)218}219220221