From 74ef96850375d18c4b6394c3c56b68edf7ed9c33 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 20 Nov 2014 23:57:19 -0800 Subject: [PATCH 1/2] mips: Prevent compilation of an easy mistake. It's easy to write LW(T0, T1, T2) but that's not valid. --- Common/MipsEmitter.cpp | 12 ++++++++++++ Common/MipsEmitter.h | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/Common/MipsEmitter.cpp b/Common/MipsEmitter.cpp index 20e4ed79be..f75c7a6d32 100644 --- a/Common/MipsEmitter.cpp +++ b/Common/MipsEmitter.cpp @@ -268,6 +268,12 @@ void MIPSEmitter::LB(MIPSReg value, MIPSReg base, s16 offset) { Write32Fields(26, 0x20, 21, base, 16, value, 0, (u16)offset); } +void MIPSEmitter::LH(MIPSReg value, MIPSReg base, s16 offset) { + // 100001 sssss ttttt iiiiiiiiiiiiiiii - rs = base, rt = value + _dbg_assert_msg_(JIT, value < F_BASE && base < F_BASE, "Bad emitter arguments"); + Write32Fields(26, 0x21, 21, base, 16, value, 0, (u16)offset); +} + void MIPSEmitter::LW(MIPSReg value, MIPSReg base, s16 offset) { // 100011 sssss ttttt iiiiiiiiiiiiiiii - rs = base, rt = value _dbg_assert_msg_(JIT, value < F_BASE && base < F_BASE, "Bad emitter arguments"); @@ -280,6 +286,12 @@ void MIPSEmitter::SB(MIPSReg value, MIPSReg base, s16 offset) { Write32Fields(26, 0x28, 21, base, 16, value, 0, (u16)offset); } +void MIPSEmitter::SH(MIPSReg value, MIPSReg base, s16 offset) { + // 101001 sssss ttttt iiiiiiiiiiiiiiii - rs = base, rt = value + _dbg_assert_msg_(JIT, value < F_BASE && base < F_BASE, "Bad emitter arguments"); + Write32Fields(26, 0x29, 21, base, 16, value, 0, (u16)offset); +} + void MIPSEmitter::SW(MIPSReg value, MIPSReg base, s16 offset) { // 101011 sssss ttttt iiiiiiiiiiiiiiii - rs = base, rt = value _dbg_assert_msg_(JIT, value < F_BASE && base < F_BASE, "Bad emitter arguments"); diff --git a/Common/MipsEmitter.h b/Common/MipsEmitter.h index 14fdaba24c..190ee5b7f1 100644 --- a/Common/MipsEmitter.h +++ b/Common/MipsEmitter.h @@ -168,10 +168,20 @@ public: } void LB(MIPSReg dest, MIPSReg base, s16 offset); + void LH(MIPSReg dest, MIPSReg base, s16 offset); void LW(MIPSReg dest, MIPSReg base, s16 offset); void SB(MIPSReg value, MIPSReg base, s16 offset); + void SH(MIPSReg dest, MIPSReg base, s16 offset); void SW(MIPSReg value, MIPSReg base, s16 offset); + // These exist for the sole purpose of making compilation fail if you try to load/store from R+R. + void LB(MIPSReg dest, MIPSReg base, MIPSReg invalid); + void LH(MIPSReg dest, MIPSReg base, MIPSReg invalid); + void LW(MIPSReg dest, MIPSReg base, MIPSReg invalid); + void SB(MIPSReg value, MIPSReg base, MIPSReg invalid); + void SH(MIPSReg dest, MIPSReg base, MIPSReg invalid); + void SW(MIPSReg value, MIPSReg base, MIPSReg invalid); + void SLL(MIPSReg rd, MIPSReg rt, u8 sa); void SRL(MIPSReg rd, MIPSReg rt, u8 sa); void SRA(MIPSReg rd, MIPSReg rt, u8 sa); From 231d4a3da2cd17ecfa0e5f4135d492b1780a89bc Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 13 Dec 2014 19:21:41 -0800 Subject: [PATCH 2/2] mips: Improve MOVP2R() typesafety. --- Common/MipsEmitter.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Common/MipsEmitter.h b/Common/MipsEmitter.h index 190ee5b7f1..5d65a69bad 100644 --- a/Common/MipsEmitter.h +++ b/Common/MipsEmitter.h @@ -228,7 +228,11 @@ public: MOVI2R(reg, (u32)val); } template void MOVP2R(MIPSReg reg, T *val) { - MOVI2R(reg, (intptr_t)(const void *)val); + if (sizeof(uintptr_t) > sizeof(u32)) { + MOVI2R(reg, (u64)(intptr_t)(const void *)val); + } else { + MOVI2R(reg, (u32)(intptr_t)(const void *)val); + } } protected: