From e86f27ad72e5ee1f0691efeba4858d573a3cd163 Mon Sep 17 00:00:00 2001 From: MerryMage Date: Mon, 21 Mar 2016 21:14:31 +0000 Subject: [PATCH] fixup! Builds on OS X now --- src/common/common_funcs.h | 24 +++++++++------- src/core/arm/decoder/decoder.h | 2 +- src/core/arm/decoder/thumb.cpp | 6 ++-- .../jit_x64/instructions/data_processing.cpp | 28 +++++++++---------- src/core/arm/jit_x64/interface.cpp | 3 +- src/core/arm/jit_x64/interpret.cpp | 2 +- .../arm/jit_x64/fuzz_arm_data_processing.cpp | 8 ++++-- 7 files changed, 41 insertions(+), 32 deletions(-) diff --git a/src/common/common_funcs.h b/src/common/common_funcs.h index aa6aff7b9..8456809e4 100644 --- a/src/common/common_funcs.h +++ b/src/common/common_funcs.h @@ -68,18 +68,22 @@ inline u64 _rotr64(u64 x, unsigned int shift){ } #else // _MSC_VER - #if (_MSC_VER < 1900) - // Function Cross-Compatibility - #define snprintf _snprintf - #endif +#if (_MSC_VER < 1900) + // Function Cross-Compatibility + #define snprintf _snprintf +#endif - // Locale Cross-Compatibility - #define locale_t _locale_t +// Locale Cross-Compatibility +#define locale_t _locale_t + +extern "C" { + __declspec(dllimport) void __stdcall DebugBreak(void); +} +#define Crash() {DebugBreak();} + +#define rotr _rotr +#define rotl _rotl - extern "C" { - __declspec(dllimport) void __stdcall DebugBreak(void); - } - #define Crash() {DebugBreak();} #endif // _MSC_VER ndef // Generic function to get last error message. diff --git a/src/core/arm/decoder/decoder.h b/src/core/arm/decoder/decoder.h index 41b44aab2..22f70670a 100644 --- a/src/core/arm/decoder/decoder.h +++ b/src/core/arm/decoder/decoder.h @@ -37,7 +37,7 @@ private: const std::unique_ptr matcher; public: - Instruction(char* name, std::unique_ptr matcher) : name(name), matcher(std::move(matcher)) {} + Instruction(const char* const name, std::unique_ptr matcher) : matcher(std::move(matcher)), name(name) {} const char* const name; diff --git a/src/core/arm/decoder/thumb.cpp b/src/core/arm/decoder/thumb.cpp index f988b42be..a6b02dfa4 100644 --- a/src/core/arm/decoder/thumb.cpp +++ b/src/core/arm/decoder/thumb.cpp @@ -31,8 +31,8 @@ namespace Impl { std::unique_ptr MakeMatcher(const char* str, std::function fn) { ASSERT(strlen(str) == 16); - u32 mask; - u32 expect; + u32 mask = 0; + u32 expect = 0; for (int i = 0; i < 16; i++) { mask <<= 1; @@ -445,7 +445,7 @@ const Instruction& DecodeThumb(u16 i) { // Example: // 000ooxxxxxxxxxxx comes before 000110oxxxxxxxxx // with a forward search direction notice how the first one will always be matched and the latter never will be. - return *std::find_if(thumb_instruction_table.crbegin(), thumb_instruction_table.crend(), [i](const auto& instruction) { + return *std::find_if(thumb_instruction_table.crbegin(), thumb_instruction_table.crend(), [i](const Instruction& instruction) { return instruction.Match(i); }); } diff --git a/src/core/arm/jit_x64/instructions/data_processing.cpp b/src/core/arm/jit_x64/instructions/data_processing.cpp index c1e76b61a..ff910fd82 100644 --- a/src/core/arm/jit_x64/instructions/data_processing.cpp +++ b/src/core/arm/jit_x64/instructions/data_processing.cpp @@ -102,7 +102,7 @@ void JitX64::CompileDataProcessingHelper_Reverse(ArmReg Rn_index, ArmReg Rd_inde void JitX64::ADC_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); CompileDataProcessingHelper(Rn_index, Rd_index, [&](X64Reg Rd) { code->BT(32, MJitStateCFlag(), Imm8(0)); @@ -125,7 +125,7 @@ void JitX64::ADC_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int ro void JitX64::ADD_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); CompileDataProcessingHelper(Rn_index, Rd_index, [&](X64Reg Rd) { code->ADD(32, R(Rd), Imm32(immediate)); @@ -147,7 +147,7 @@ void JitX64::ADD_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int ro void JitX64::AND_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); CompileDataProcessingHelper(Rn_index, Rd_index, [&](X64Reg Rd) { code->AND(32, R(Rd), Imm32(immediate)); @@ -172,7 +172,7 @@ void JitX64::AND_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int ro void JitX64::BIC_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); CompileDataProcessingHelper(Rn_index, Rd_index, [&](X64Reg Rd) { code->AND(32, R(Rd), Imm32(~immediate)); @@ -200,7 +200,7 @@ void JitX64::CMP_imm(Cond cond, ArmReg Rn_index, int rotate, ArmImm8 imm8) { Com void JitX64::EOR_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); CompileDataProcessingHelper(Rn_index, Rd_index, [&](X64Reg Rd) { code->XOR(32, R(Rd), Imm32(immediate)); @@ -225,7 +225,7 @@ void JitX64::EOR_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int ro void JitX64::MOV_imm(Cond cond, bool S, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); if (Rd_index != 15) { reg_alloc.LockArm(Rd_index); @@ -257,7 +257,7 @@ void JitX64::MOV_imm(Cond cond, bool S, ArmReg Rd_index, int rotate, ArmImm8 imm void JitX64::MVN_imm(Cond cond, bool S, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); if (Rd_index != 15) { reg_alloc.LockArm(Rd_index); @@ -289,7 +289,7 @@ void JitX64::MVN_imm(Cond cond, bool S, ArmReg Rd_index, int rotate, ArmImm8 imm void JitX64::ORR_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); CompileDataProcessingHelper(Rn_index, Rd_index, [&](X64Reg Rd) { code->OR(32, R(Rd), Imm32(immediate)); @@ -314,7 +314,7 @@ void JitX64::ORR_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int ro void JitX64::RSB_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); CompileDataProcessingHelper_Reverse(Rn_index, Rd_index, [&](X64Reg Rd) { code->MOV(32, R(Rd), Imm32(immediate)); @@ -345,7 +345,7 @@ void JitX64::RSB_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int ro void JitX64::RSC_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); CompileDataProcessingHelper_Reverse(Rn_index, Rd_index, [&](X64Reg Rd) { code->MOV(32, R(Rd), Imm32(immediate)); @@ -379,7 +379,7 @@ void JitX64::RSC_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int ro void JitX64::SBC_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); CompileDataProcessingHelper(Rn_index, Rd_index, [&](X64Reg Rd) { code->BT(32, MJitStateCFlag(), Imm8(0)); @@ -404,7 +404,7 @@ void JitX64::SBC_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int ro void JitX64::SUB_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); CompileDataProcessingHelper(Rn_index, Rd_index, [&](X64Reg Rd) { code->SUB(32, R(Rd), Imm32(immediate)); @@ -427,7 +427,7 @@ void JitX64::SUB_imm(Cond cond, bool S, ArmReg Rn_index, ArmReg Rd_index, int ro void JitX64::TEQ_imm(Cond cond, ArmReg Rn_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); X64Reg Rn = reg_alloc.AllocAndLockTemp(); @@ -457,7 +457,7 @@ void JitX64::TEQ_imm(Cond cond, ArmReg Rn_index, int rotate, ArmImm8 imm8) { void JitX64::TST_imm(Cond cond, ArmReg Rn_index, int rotate, ArmImm8 imm8) { cond_manager.CompileCond((ConditionCode)cond); - u32 immediate = _rotr(imm8, rotate * 2); + u32 immediate = rotr(imm8, rotate * 2); X64Reg Rn; diff --git a/src/core/arm/jit_x64/interface.cpp b/src/core/arm/jit_x64/interface.cpp index bbdc6b481..2c7be6440 100644 --- a/src/core/arm/jit_x64/interface.cpp +++ b/src/core/arm/jit_x64/interface.cpp @@ -4,6 +4,7 @@ // Refer to the license.txt file included. #include "common/assert.h" +#include "common/make_unique.h" #include "common/x64/abi.h" #include "common/x64/emitter.h" @@ -88,7 +89,7 @@ static JitX64 compiler = { &block_of_code }; ARM_Jit::ARM_Jit(PrivilegeMode initial_mode) { ASSERT_MSG(initial_mode == PrivilegeMode::USER32MODE, "Unimplemented"); - state = std::make_unique(); + state = Common::make_unique(); } ARM_Jit::~ARM_Jit() { diff --git a/src/core/arm/jit_x64/interpret.cpp b/src/core/arm/jit_x64/interpret.cpp index 79f96fdf5..8ee2d735a 100644 --- a/src/core/arm/jit_x64/interpret.cpp +++ b/src/core/arm/jit_x64/interpret.cpp @@ -51,7 +51,7 @@ void JitX64::CompileInterpretInstruction() { code->MOV(64, R(Gen::ABI_PARAM3), Imm64(current.TFlag)); code->MOV(64, R(Gen::ABI_PARAM4), Imm64(current.EFlag)); - const void *const fn = &CallInterpreter; + const void *const fn = reinterpret_cast(&CallInterpreter); const u64 distance = reinterpret_cast(fn) - (reinterpret_cast(code->GetCodePtr()) + 5); if (distance >= 0x0000000080000000ULL && distance < 0xFFFFFFFF80000000ULL) { diff --git a/src/tests/core/arm/jit_x64/fuzz_arm_data_processing.cpp b/src/tests/core/arm/jit_x64/fuzz_arm_data_processing.cpp index 865a94e2f..e54c8d5a7 100644 --- a/src/tests/core/arm/jit_x64/fuzz_arm_data_processing.cpp +++ b/src/tests/core/arm/jit_x64/fuzz_arm_data_processing.cpp @@ -2,6 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. +#include #include #include @@ -98,7 +99,7 @@ TEST_CASE("Fuzz ARM data processing instructions", "[JitX64]") { std::random_device rd; std::mt19937 mt(rd()); auto rand_int = [&mt](u32 min, u32 max) -> u32 { - std::uniform_int rand(min, max); + std::uniform_int_distribution rand(min, max); return rand(mt); }; @@ -197,6 +198,9 @@ TEST_CASE("Fuzz ARM data processing instructions", "[JitX64]") { FAIL(); } - if (run_number % 100 == 0) printf("%i\r", run_number); + if (run_number % 100 == 0) { + printf("%i\r", run_number); + fflush(stdout); + } } } \ No newline at end of file