2017-03-18 17:20:21 +00:00
|
|
|
/* This file is part of the dynarmic project.
|
|
|
|
* Copyright (c) 2016 MerryMage
|
|
|
|
* This software may be used and distributed according to the terms of the GNU
|
|
|
|
* General Public License version 2 or any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2018-08-14 19:13:47 +01:00
|
|
|
#include "backend/x64/block_of_code.h"
|
|
|
|
#include "backend/x64/constant_pool.h"
|
2017-03-18 17:20:21 +00:00
|
|
|
#include "common/assert.h"
|
|
|
|
|
2018-01-26 13:51:48 +00:00
|
|
|
namespace Dynarmic::BackendX64 {
|
2017-03-18 17:20:21 +00:00
|
|
|
|
2018-02-03 14:28:57 +00:00
|
|
|
ConstantPool::ConstantPool(BlockOfCode& code, size_t size) : code(code), pool_size(size) {
|
|
|
|
code.int3();
|
|
|
|
code.align(align_size);
|
|
|
|
pool_begin = reinterpret_cast<u8*>(code.AllocateFromCodeSpace(size));
|
2017-03-18 17:20:21 +00:00
|
|
|
current_pool_ptr = pool_begin;
|
|
|
|
}
|
|
|
|
|
2018-02-20 14:04:11 +00:00
|
|
|
Xbyak::Address ConstantPool::GetConstant(const Xbyak::AddressFrame& frame, u64 lower, u64 upper) {
|
2018-02-10 16:25:07 +00:00
|
|
|
const auto constant = std::make_tuple(lower, upper);
|
2017-03-18 17:20:21 +00:00
|
|
|
auto iter = constant_info.find(constant);
|
|
|
|
if (iter == constant_info.end()) {
|
|
|
|
ASSERT(static_cast<size_t>(current_pool_ptr - pool_begin) < pool_size);
|
2018-02-10 16:25:07 +00:00
|
|
|
std::memcpy(current_pool_ptr, &lower, sizeof(u64));
|
|
|
|
std::memcpy(current_pool_ptr + sizeof(u64), &upper, sizeof(u64));
|
2017-03-18 17:20:21 +00:00
|
|
|
iter = constant_info.emplace(constant, current_pool_ptr).first;
|
|
|
|
current_pool_ptr += align_size;
|
|
|
|
}
|
2018-02-20 14:04:11 +00:00
|
|
|
return frame[code.rip + iter->second];
|
2017-03-18 17:20:21 +00:00
|
|
|
}
|
|
|
|
|
2018-01-26 13:51:48 +00:00
|
|
|
} // namespace Dynarmic::BackendX64
|