2019-01-12 22:48:48 +00:00
|
|
|
/*
|
|
|
|
Copyright 2019 flyinghead
|
|
|
|
|
|
|
|
This file is part of reicast.
|
|
|
|
|
|
|
|
reicast is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
reicast is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with reicast. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2021-05-22 08:43:41 +00:00
|
|
|
#pragma once
|
2019-01-12 22:48:48 +00:00
|
|
|
|
2020-03-22 09:08:05 +00:00
|
|
|
#include <xbyak/xbyak.h>
|
2019-06-10 11:57:10 +00:00
|
|
|
#include "hw/sh4/dyna/ssa_regalloc.h"
|
2019-01-12 22:48:48 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
static Xbyak::Operand::Code alloc_regs[] = { Xbyak::Operand::RBX, Xbyak::Operand::RBP, Xbyak::Operand::RDI, Xbyak::Operand::RSI,
|
|
|
|
Xbyak::Operand::R12, Xbyak::Operand::R13, Xbyak::Operand::R14, Xbyak::Operand::R15, (Xbyak::Operand::Code)-1 };
|
2019-01-18 16:02:50 +00:00
|
|
|
static s8 alloc_fregs[] = { 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, -1 }; // XMM6 to XMM15 are callee-saved in Windows
|
2022-12-23 15:06:54 +00:00
|
|
|
#define ALLOC_F64 true
|
2019-01-12 22:48:48 +00:00
|
|
|
#else
|
|
|
|
static Xbyak::Operand::Code alloc_regs[] = { Xbyak::Operand::RBX, Xbyak::Operand::RBP, Xbyak::Operand::R12, Xbyak::Operand::R13,
|
|
|
|
Xbyak::Operand::R14, Xbyak::Operand::R15, (Xbyak::Operand::Code)-1 };
|
2019-01-14 20:15:36 +00:00
|
|
|
static s8 alloc_fregs[] = { 8, 9, 10, 11, -1 }; // XMM8-11
|
2022-12-23 15:06:54 +00:00
|
|
|
// all xmm registers are caller-saved on linux
|
|
|
|
#define ALLOC_F64 false
|
2019-01-18 16:02:50 +00:00
|
|
|
#endif
|
2019-01-12 22:48:48 +00:00
|
|
|
|
|
|
|
class BlockCompiler;
|
|
|
|
|
2022-12-23 15:06:54 +00:00
|
|
|
struct X64RegAlloc : RegAlloc<Xbyak::Operand::Code, s8, ALLOC_F64>
|
2019-01-12 22:48:48 +00:00
|
|
|
{
|
|
|
|
X64RegAlloc(BlockCompiler *compiler) : compiler(compiler) {}
|
|
|
|
|
|
|
|
void DoAlloc(RuntimeBlockInfo* block)
|
|
|
|
{
|
|
|
|
RegAlloc::DoAlloc(block, alloc_regs, alloc_fregs);
|
|
|
|
}
|
|
|
|
|
2021-03-13 11:44:59 +00:00
|
|
|
void Preload(u32 reg, Xbyak::Operand::Code nreg) override;
|
|
|
|
void Writeback(u32 reg, Xbyak::Operand::Code nreg) override;
|
|
|
|
void Preload_FPU(u32 reg, s8 nreg) override;
|
|
|
|
void Writeback_FPU(u32 reg, s8 nreg) override;
|
2019-01-12 22:48:48 +00:00
|
|
|
|
|
|
|
Xbyak::Reg32 MapRegister(const shil_param& param)
|
|
|
|
{
|
|
|
|
Xbyak::Operand::Code ereg = mapg(param);
|
|
|
|
if (ereg == (Xbyak::Operand::Code)-1)
|
|
|
|
die("Register not allocated");
|
|
|
|
return Xbyak::Reg32(ereg);
|
|
|
|
}
|
|
|
|
|
2022-12-23 15:06:54 +00:00
|
|
|
Xbyak::Xmm MapXRegister(const shil_param& param, int index = 0)
|
2019-01-12 22:48:48 +00:00
|
|
|
{
|
2022-12-23 15:06:54 +00:00
|
|
|
s8 ereg = mapf(param, index);
|
2019-01-12 22:48:48 +00:00
|
|
|
if (ereg == -1)
|
|
|
|
die("VRegister not allocated");
|
|
|
|
return Xbyak::Xmm(ereg);
|
|
|
|
}
|
|
|
|
|
2019-03-25 10:53:13 +00:00
|
|
|
bool IsMapped(const Xbyak::Xmm &xmm, size_t opid)
|
|
|
|
{
|
2019-06-10 11:57:10 +00:00
|
|
|
return regf_used((s8)xmm.getIdx());
|
2019-03-25 10:53:13 +00:00
|
|
|
}
|
|
|
|
|
2019-01-12 22:48:48 +00:00
|
|
|
BlockCompiler *compiler;
|
|
|
|
};
|