block_of_code: Make CallFunction accept function pointers only

This commit is contained in:
Lioncash
2016-08-31 16:09:26 -04:00
committed by MerryMage
parent 249a2be786
commit ea6a4e82b5
3 changed files with 36 additions and 32 deletions

View File

@@ -6,9 +6,7 @@
#pragma once
#include <array>
#include <vector>
#include <type_traits>
#include <xbyak.h>
#include "backend_x64/jitstate.h"
@@ -32,8 +30,24 @@ public:
void SwitchMxcsrOnEntry();
/// Code emitter: Makes saved host MXCSR the current MXCSR
void SwitchMxcsrOnExit();
/// Code emitter: Calls the function
void CallFunction(const void* fn);
template <typename FunctionPointer>
void CallFunction(FunctionPointer fn) {
static_assert(std::is_pointer<FunctionPointer>() && std::is_function<std::remove_pointer_t<FunctionPointer>>(),
"Supplied type must be a pointer to a function");
const u64 address = reinterpret_cast<u64>(fn);
const u64 distance = address - (getCurr<u64>() + 5);
if (distance >= 0x0000000080000000ULL && distance < 0xFFFFFFFF80000000ULL) {
// Far call
mov(rax, address);
call(rax);
} else {
call(fn);
}
}
Xbyak::Address MFloatPositiveZero32() {
return xword[rip + consts.FloatPositiveZero32];