minor perf improvements
This commit is contained in:
@@ -35,48 +35,48 @@ void Registers::SetPC32(s32 val) {
|
||||
}
|
||||
|
||||
template <>
|
||||
u64 Registers::Read<u64>(size_t idx) {
|
||||
return idx == 0 ? 0 : gpr[idx];
|
||||
__attribute__((always_inline)) u64 Registers::Read<u64>(size_t idx) {
|
||||
return gpr[idx];
|
||||
}
|
||||
|
||||
template <>
|
||||
s64 Registers::Read<s64>(const size_t idx) {
|
||||
__attribute__((always_inline)) s64 Registers::Read<s64>(const size_t idx) {
|
||||
return static_cast<s64>(Read<u64>(idx));
|
||||
}
|
||||
|
||||
template <>
|
||||
u32 Registers::Read<u32>(size_t idx) {
|
||||
return idx == 0 ? 0 : gpr[idx];
|
||||
__attribute__((always_inline)) u32 Registers::Read<u32>(size_t idx) {
|
||||
return gpr[idx];
|
||||
}
|
||||
|
||||
template <>
|
||||
s32 Registers::Read<s32>(size_t idx) {
|
||||
__attribute__((always_inline)) s32 Registers::Read<s32>(size_t idx) {
|
||||
return static_cast<s32>(Read<u32>(idx));
|
||||
}
|
||||
|
||||
template <>
|
||||
u16 Registers::Read<u16>(size_t idx) {
|
||||
return idx == 0 ? 0 : gpr[idx];
|
||||
__attribute__((always_inline)) u16 Registers::Read<u16>(size_t idx) {
|
||||
return gpr[idx];
|
||||
}
|
||||
|
||||
template <>
|
||||
s16 Registers::Read<s16>(size_t idx) {
|
||||
__attribute__((always_inline)) s16 Registers::Read<s16>(size_t idx) {
|
||||
return static_cast<s16>(Read<u16>(idx));
|
||||
}
|
||||
|
||||
template <>
|
||||
u8 Registers::Read<u8>(size_t idx) {
|
||||
return idx == 0 ? 0 : gpr[idx];
|
||||
__attribute__((always_inline)) u8 Registers::Read<u8>(size_t idx) {
|
||||
return gpr[idx];
|
||||
}
|
||||
|
||||
template <>
|
||||
s8 Registers::Read<s8>(size_t idx) {
|
||||
__attribute__((always_inline)) s8 Registers::Read<s8>(size_t idx) {
|
||||
return static_cast<s8>(Read<u8>(idx));
|
||||
}
|
||||
|
||||
#ifndef __aarch64__
|
||||
template <>
|
||||
void Registers::Read<u64>(size_t idx, Xbyak::Reg reg) {
|
||||
__attribute__((always_inline)) void Registers::Read<u64>(size_t idx, Xbyak::Reg reg) {
|
||||
if(IsRegConstant(idx)) {
|
||||
jit->code.mov(reg.cvt64(), Read<u64>(idx));
|
||||
return;
|
||||
@@ -86,7 +86,7 @@ void Registers::Read<u64>(size_t idx, Xbyak::Reg reg) {
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Read<s64>(size_t idx, Xbyak::Reg reg) {
|
||||
__attribute__((always_inline)) void Registers::Read<s64>(size_t idx, Xbyak::Reg reg) {
|
||||
if(IsRegConstant(idx)) {
|
||||
jit->code.mov(reg.cvt64(), Read<s64>(idx));
|
||||
return;
|
||||
@@ -96,7 +96,7 @@ void Registers::Read<s64>(size_t idx, Xbyak::Reg reg) {
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Read<u32>(size_t idx, Xbyak::Reg reg) {
|
||||
__attribute__((always_inline)) void Registers::Read<u32>(size_t idx, Xbyak::Reg reg) {
|
||||
if(IsRegConstant(idx)) {
|
||||
jit->code.mov(reg.cvt32(), Read<u32>(idx));
|
||||
return;
|
||||
@@ -106,7 +106,7 @@ void Registers::Read<u32>(size_t idx, Xbyak::Reg reg) {
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Read<s32>(size_t idx, Xbyak::Reg reg) {
|
||||
__attribute__((always_inline)) void Registers::Read<s32>(size_t idx, Xbyak::Reg reg) {
|
||||
if(IsRegConstant(idx)) {
|
||||
jit->code.mov(reg.cvt32(), Read<s32>(idx));
|
||||
return;
|
||||
@@ -116,7 +116,7 @@ void Registers::Read<s32>(size_t idx, Xbyak::Reg reg) {
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Read<u16>(size_t idx, Xbyak::Reg reg) {
|
||||
__attribute__((always_inline)) void Registers::Read<u16>(size_t idx, Xbyak::Reg reg) {
|
||||
if(IsRegConstant(idx)) {
|
||||
jit->code.mov(reg.cvt16(), Read<u16>(idx));
|
||||
return;
|
||||
@@ -126,7 +126,7 @@ void Registers::Read<u16>(size_t idx, Xbyak::Reg reg) {
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Read<s16>(size_t idx, Xbyak::Reg reg) {
|
||||
__attribute__((always_inline)) void Registers::Read<s16>(size_t idx, Xbyak::Reg reg) {
|
||||
if(IsRegConstant(idx)) {
|
||||
jit->code.mov(reg.cvt16(), Read<s16>(idx));
|
||||
return;
|
||||
@@ -136,7 +136,7 @@ void Registers::Read<s16>(size_t idx, Xbyak::Reg reg) {
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Read<u8>(size_t idx, Xbyak::Reg reg) {
|
||||
__attribute__((always_inline)) void Registers::Read<u8>(size_t idx, Xbyak::Reg reg) {
|
||||
if(IsRegConstant(idx)) {
|
||||
jit->code.mov(reg.cvt8(), Read<u8>(idx));
|
||||
return;
|
||||
@@ -146,7 +146,7 @@ void Registers::Read<u8>(size_t idx, Xbyak::Reg reg) {
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Read<s8>(size_t idx, Xbyak::Reg reg) {
|
||||
__attribute__((always_inline)) void Registers::Read<s8>(size_t idx, Xbyak::Reg reg) {
|
||||
if(IsRegConstant(idx)) {
|
||||
jit->code.mov(reg.cvt8(), Read<s8>(idx));
|
||||
return;
|
||||
@@ -157,199 +157,208 @@ void Registers::Read<s8>(size_t idx, Xbyak::Reg reg) {
|
||||
#endif
|
||||
|
||||
template <>
|
||||
void Registers::Write<bool>(size_t idx, bool v) {
|
||||
__attribute__((always_inline)) void Registers::Write<bool>(size_t idx, bool v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant |= (1 << idx);
|
||||
if (jit) [[unlikely]]
|
||||
regIsConstant |= (1 << idx);
|
||||
|
||||
gpr[idx] = v;
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<u64>(size_t idx, u64 v) {
|
||||
__attribute__((always_inline)) void Registers::Write<u64>(size_t idx, u64 v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant |= (1 << idx);
|
||||
if (jit) [[unlikely]]
|
||||
regIsConstant |= (1 << idx);
|
||||
gpr[idx] = v;
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<s64>(size_t idx, s64 v) {
|
||||
__attribute__((always_inline)) void Registers::Write<s64>(size_t idx, s64 v) {
|
||||
Write<u64>(idx, v);
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<u32>(size_t idx, u32 v) {
|
||||
__attribute__((always_inline)) void Registers::Write<u32>(size_t idx, u32 v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant |= (1 << idx);
|
||||
if (jit) [[unlikely]]
|
||||
regIsConstant |= (1 << idx);
|
||||
gpr[idx] = v;
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
void Registers::Write<s32>(size_t idx, s32 v) {
|
||||
__attribute__((always_inline)) void Registers::Write<s32>(size_t idx, s32 v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant |= (1 << idx);
|
||||
if (jit) [[unlikely]]
|
||||
regIsConstant |= (1 << idx);
|
||||
gpr[idx] = v;
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<u16>(size_t idx, u16 v) {
|
||||
__attribute__((always_inline)) void Registers::Write<u16>(size_t idx, u16 v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant |= (1 << idx);
|
||||
if (jit) [[unlikely]]
|
||||
regIsConstant |= (1 << idx);
|
||||
gpr[idx] = v;
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
void Registers::Write<s16>(size_t idx, s16 v) {
|
||||
__attribute__((always_inline)) void Registers::Write<s16>(size_t idx, s16 v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant |= (1 << idx);
|
||||
if (jit) [[unlikely]]
|
||||
regIsConstant |= (1 << idx);
|
||||
gpr[idx] = v;
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<u8>(size_t idx, u8 v) {
|
||||
__attribute__((always_inline)) void Registers::Write<u8>(size_t idx, u8 v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant |= (1 << idx);
|
||||
if (jit) [[unlikely]]
|
||||
regIsConstant |= (1 << idx);
|
||||
gpr[idx] = v;
|
||||
}
|
||||
|
||||
|
||||
template <>
|
||||
void Registers::Write<s8>(size_t idx, s8 v) {
|
||||
__attribute__((always_inline)) void Registers::Write<s8>(size_t idx, s8 v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant |= (1 << idx);
|
||||
if (jit) [[unlikely]]
|
||||
regIsConstant |= (1 << idx);
|
||||
gpr[idx] = v;
|
||||
}
|
||||
|
||||
#ifndef __aarch64__
|
||||
template <>
|
||||
void Registers::Write<bool>(size_t idx, Xbyak::Reg v) {
|
||||
__attribute__((always_inline)) void Registers::Write<bool>(size_t idx, Xbyak::Reg v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
if (!jit)
|
||||
panic("Did you try to call Registers::Write(size_t, *Xbyak::Reg*) from the interpreter?");
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
jit->code.movsx(v.cvt64(), v.cvt8());
|
||||
jit->code.mov(jit->GPR<u64>(idx), v);
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<s8>(size_t idx, Xbyak::Reg v) {
|
||||
__attribute__((always_inline)) void Registers::Write<s8>(size_t idx, Xbyak::Reg v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
if (!jit)
|
||||
panic("Did you try to call Registers::Write(size_t, *Xbyak::Reg*) from the interpreter?");
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
jit->code.movsx(v.cvt64(), v.cvt8());
|
||||
jit->code.mov(jit->GPR<u64>(idx), v);
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<u8>(size_t idx, Xbyak::Reg v) {
|
||||
__attribute__((always_inline)) void Registers::Write<u8>(size_t idx, Xbyak::Reg v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
if (!jit)
|
||||
panic("Did you try to call Registers::Write(size_t, *Xbyak::Reg*) from the interpreter?");
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
jit->code.movzx(v.cvt64(), v.cvt8());
|
||||
jit->code.mov(jit->GPR<u64>(idx), v.cvt64());
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<s16>(size_t idx, Xbyak::Reg v) {
|
||||
__attribute__((always_inline)) void Registers::Write<s16>(size_t idx, Xbyak::Reg v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
if (!jit)
|
||||
panic("Did you try to call Registers::Write(size_t, *Xbyak::Reg*) from the interpreter?");
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
jit->code.movsx(v.cvt64(), v.cvt16());
|
||||
jit->code.mov(jit->GPR<u64>(idx), v.cvt64());
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<u16>(size_t idx, Xbyak::Reg v) {
|
||||
__attribute__((always_inline)) void Registers::Write<u16>(size_t idx, Xbyak::Reg v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
if (!jit)
|
||||
panic("Did you try to call Registers::Write(size_t, *Xbyak::Reg*) from the interpreter?");
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
jit->code.movzx(v.cvt64(), v.cvt16());
|
||||
jit->code.mov(jit->GPR<u64>(idx), v.cvt64());
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<s32>(size_t idx, Xbyak::Reg v) {
|
||||
__attribute__((always_inline)) void Registers::Write<s32>(size_t idx, Xbyak::Reg v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
if (!jit)
|
||||
panic("Did you try to call Registers::Write(size_t, *Xbyak::Reg*) from the interpreter?");
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
jit->code.movsxd(v.cvt64(), v.cvt32());
|
||||
jit->code.mov(jit->GPR<u64>(idx), v.cvt64());
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<u32>(size_t idx, Xbyak::Reg v) {
|
||||
__attribute__((always_inline)) void Registers::Write<u32>(size_t idx, Xbyak::Reg v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
if (!jit)
|
||||
panic("Did you try to call Registers::Write(size_t, *Xbyak::Reg*) from the interpreter?");
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
jit->code.movzx(v.cvt64(), v.cvt32());
|
||||
jit->code.mov(jit->GPR<u64>(idx), v.cvt64());
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<u64>(size_t idx, Xbyak::Reg v) {
|
||||
__attribute__((always_inline)) void Registers::Write<u64>(size_t idx, Xbyak::Reg v) {
|
||||
if (idx == 0)
|
||||
return;
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
if (!jit)
|
||||
panic("Did you try to call Registers::Write(size_t, *Xbyak::Reg*) from the interpreter?");
|
||||
|
||||
regIsConstant &= ~(1 << idx);
|
||||
|
||||
jit->code.mov(jit->GPR<u64>(idx), v.cvt64());
|
||||
}
|
||||
|
||||
template <>
|
||||
void Registers::Write<s64>(size_t idx, Xbyak::Reg v) {
|
||||
__attribute__((always_inline)) void Registers::Write<s64>(size_t idx, Xbyak::Reg v) {
|
||||
Write<u64>(idx, v);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -66,13 +66,13 @@ struct Registers {
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
T Read(size_t);
|
||||
__attribute__((always_inline)) T Read(size_t);
|
||||
template <typename T>
|
||||
void Read(size_t, Xbyak::Reg);
|
||||
__attribute__((always_inline)) void Read(size_t, Xbyak::Reg);
|
||||
template <typename T>
|
||||
void Write(size_t, T);
|
||||
__attribute__((always_inline)) void Write(size_t, T);
|
||||
template <typename T>
|
||||
void Write(size_t, Xbyak::Reg);
|
||||
__attribute__((always_inline)) void Write(size_t, Xbyak::Reg);
|
||||
|
||||
std::array<s64, 32> gpr{};
|
||||
};
|
||||
|
||||
@@ -28,33 +28,11 @@ void print(const std::format_string<Args...> fmt, Args... args) {
|
||||
}
|
||||
}
|
||||
|
||||
#define panic(fmt, ...) do \
|
||||
{ \
|
||||
Util::print<Util::Error>("[FATAL] " fmt, __VA_ARGS__); \
|
||||
exit(-1); \
|
||||
} while(0)
|
||||
#define error(fmt, ...) do \
|
||||
{ \
|
||||
Util::print<Util::Error>("[ERROR] " fmt, __VA_ARGS__); \
|
||||
} while(0)
|
||||
#define warn(fmt, ...) do \
|
||||
{ \
|
||||
Util::print<Util::Warn>("[WARN] " fmt, __VA_ARGS__); \
|
||||
} while(0)
|
||||
#define info(fmt, ...) do \
|
||||
{ \
|
||||
Util::print<Util::Info>("[INFO] " fmt, __VA_ARGS__); \
|
||||
} while(0)
|
||||
#define debug(fmt, ...) do \
|
||||
{ \
|
||||
Util::print<Util::Debug>("[DEBUG] " fmt, __VA_ARGS__); \
|
||||
} while(0)
|
||||
#define trace(fmt, ...) do \
|
||||
{ \
|
||||
Util::print<Util::Trace>("[TRACE] " fmt, __VA_ARGS__); \
|
||||
} while(0)
|
||||
#define always(fmt, ...) do \
|
||||
{ \
|
||||
Util::print<Util::Always>(fmt, __VA_ARGS__); \
|
||||
} while(0)
|
||||
#define panic(fmt, ...) do { Util::print<Util::Error>("[FATAL] " fmt, __VA_ARGS__); exit(-1); } while(0)
|
||||
#define error(fmt, ...) do { Util::print<Util::Error>("[ERROR] " fmt, __VA_ARGS__); } while(0)
|
||||
#define warn(fmt, ...) do { Util::print<Util::Warn>("[WARN] " fmt, __VA_ARGS__); } while(0)
|
||||
#define info(fmt, ...) do { Util::print<Util::Info>("[INFO] " fmt, __VA_ARGS__); } while(0)
|
||||
#define debug(fmt, ...) do { Util::print<Util::Debug>("[DEBUG] " fmt, __VA_ARGS__); } while(0)
|
||||
#define trace(fmt, ...) do { Util::print<Util::Trace>("[TRACE] " fmt, __VA_ARGS__); } while(0)
|
||||
#define always(fmt, ...) do { Util::print<Util::Always>(fmt, __VA_ARGS__); } while(0)
|
||||
} // namespace Util
|
||||
|
||||
Reference in New Issue
Block a user