externals: Update oaknut to 2.0.1

Merge commit 'a37f3673f8ca59a0c7046616247db1c6bc00e131'
This commit is contained in:
Merry 2024-01-28 17:02:37 +00:00
commit ac9003fb78
11 changed files with 62 additions and 59 deletions

View file

@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.8)
project(oaknut LANGUAGES CXX VERSION 2.0.0)
project(oaknut LANGUAGES CXX VERSION 2.0.1)
# Determine if we're built as a subproject (using add_subdirectory)
# or if this is the master project.

View file

@ -32,7 +32,7 @@ EmittedFunction EmitExample(oaknut::CodeGenerator& code, int value)
int main()
{
oaknut::CodeBlock mem{4096};
oaknut::CodeGenerator code{mem.ptr(), mem.ptr()};
oaknut::CodeGenerator code{mem.ptr()};
mem.unprotect();
@ -47,7 +47,7 @@ int main()
}
```
CodeGenerator takes two pointers. The first pointer is the memory address to write to, and the second pointer is the memory address that the code will be executing from. This allows you to write to a buffer before copying to the final destination for execution, or to have to use dual-mapped memory blocks to avoid memory protection overhead.
CodeGenerator also has a constructor taking two pointers. The first pointer is the memory address to write to, and the second pointer is the memory address that the code will be executing from. This allows you to write to a buffer before copying to the final destination for execution, or to have to use dual-mapped memory blocks to avoid memory protection overhead.
Below is an example of using the oaknut-provided utility header for dual-mapped memory blocks:

View file

@ -300,8 +300,21 @@ private:
std::uint32_t* const m_xmem;
};
using CodeGenerator = BasicCodeGenerator<PointerCodeGeneratorPolicy>;
using VectorCodeGenerator = BasicCodeGenerator<VectorCodeGeneratorPolicy>;
struct CodeGenerator : BasicCodeGenerator<PointerCodeGeneratorPolicy> {
public:
CodeGenerator(std::uint32_t* mem)
: BasicCodeGenerator<PointerCodeGeneratorPolicy>(mem, mem) {}
CodeGenerator(std::uint32_t* wmem, std::uint32_t* xmem)
: BasicCodeGenerator<PointerCodeGeneratorPolicy>(wmem, xmem) {}
};
struct VectorCodeGenerator : BasicCodeGenerator<VectorCodeGeneratorPolicy> {
public:
VectorCodeGenerator(std::vector<std::uint32_t>& mem)
: BasicCodeGenerator<VectorCodeGeneratorPolicy>(mem, nullptr) {}
VectorCodeGenerator(std::vector<std::uint32_t>& wmem, std::uint32_t* xmem)
: BasicCodeGenerator<VectorCodeGeneratorPolicy>(wmem, xmem) {}
};
namespace util {

View file

@ -18,7 +18,7 @@ using namespace oaknut::util;
TEST_CASE("Basic Test")
{
CodeBlock mem{4096};
CodeGenerator code{mem.ptr(), mem.ptr()};
CodeGenerator code{mem.ptr()};
mem.unprotect();
@ -49,7 +49,7 @@ TEST_CASE("Basic Test (Dual)")
TEST_CASE("Fibonacci")
{
CodeBlock mem{4096};
CodeGenerator code{mem.ptr(), mem.ptr()};
CodeGenerator code{mem.ptr()};
mem.unprotect();
@ -142,7 +142,7 @@ TEST_CASE("Immediate generation (32-bit)", "[slow]")
for (int i = 0; i < 0x100000; i++) {
const std::uint32_t value = RandInt<std::uint32_t>(0, 0xffffffff);
CodeGenerator code{mem.ptr(), mem.ptr()};
CodeGenerator code{mem.ptr()};
auto f = code.xptr<std::uint64_t (*)()>();
mem.unprotect();
@ -162,7 +162,7 @@ TEST_CASE("Immediate generation (64-bit)", "[slow]")
for (int i = 0; i < 0x100000; i++) {
const std::uint64_t value = RandInt<std::uint64_t>(0, 0xffffffff'ffffffff);
CodeGenerator code{mem.ptr(), mem.ptr()};
CodeGenerator code{mem.ptr()};
auto f = code.xptr<std::uint64_t (*)()>();
mem.unprotect();
@ -182,7 +182,7 @@ TEST_CASE("ADR", "[slow]")
for (std::int64_t i = -1048576; i < 1048576; i++) {
const std::intptr_t value = reinterpret_cast<std::intptr_t>(mem.ptr()) + i;
CodeGenerator code{mem.ptr(), mem.ptr()};
CodeGenerator code{mem.ptr()};
auto f = code.xptr<std::intptr_t (*)()>();
mem.unprotect();
@ -218,7 +218,7 @@ TEST_CASE("ADRP", "[slow]")
const std::intptr_t value = reinterpret_cast<std::intptr_t>(mem.ptr()) + diff;
const std::uint64_t expect = static_cast<std::uint64_t>(value) & ~static_cast<std::uint64_t>(0xfff);
CodeGenerator code{mem.ptr(), mem.ptr()};
CodeGenerator code{mem.ptr()};
auto f = code.xptr<std::uint64_t (*)()>();
mem.unprotect();
@ -241,7 +241,7 @@ TEST_CASE("ADRL (near)")
const std::int64_t diff = i;
const std::intptr_t value = reinterpret_cast<std::intptr_t>(mem_ptr) + diff;
CodeGenerator code{mem_ptr, mem_ptr};
CodeGenerator code{mem_ptr};
auto f = code.xptr<std::uint64_t (*)()>();
mem.unprotect();
@ -264,7 +264,7 @@ TEST_CASE("ADRL (far)", "[slow]")
const std::int64_t diff = RandInt<std::int64_t>(-4294967296 + 100, 4294967295 - 100);
const std::intptr_t value = reinterpret_cast<std::intptr_t>(mem_ptr) + diff;
CodeGenerator code{mem_ptr, mem_ptr};
CodeGenerator code{mem_ptr};
auto f = code.xptr<std::uint64_t (*)()>();
mem.unprotect();
@ -288,7 +288,7 @@ TEST_CASE("MOVP2R (far)", "[slow]")
std::numeric_limits<std::int64_t>::max());
const std::intptr_t value = reinterpret_cast<std::intptr_t>(mem_ptr) + diff;
CodeGenerator code{mem_ptr, mem_ptr};
CodeGenerator code{mem_ptr};
auto f = code.xptr<std::uint64_t (*)()>();
mem.unprotect();
@ -310,7 +310,7 @@ TEST_CASE("MOVP2R (4GiB boundary)")
const auto test = [&](std::int64_t diff) {
const std::intptr_t value = reinterpret_cast<std::intptr_t>(mem_ptr) + diff;
CodeGenerator code{mem_ptr, mem_ptr};
CodeGenerator code{mem_ptr};
auto f = code.xptr<std::uint64_t (*)()>();
mem.unprotect();

View file

@ -8,18 +8,18 @@
#include "oaknut/oaknut.hpp"
#define T(HEX, CMD) \
TEST_CASE(#CMD) \
{ \
using namespace oaknut; \
using namespace oaknut::util; \
\
std::uint32_t result; \
CodeGenerator code{&result, &result}; \
\
code.CMD; \
\
REQUIRE(result == HEX); \
#define T(HEX, CMD) \
TEST_CASE(#CMD) \
{ \
using namespace oaknut; \
using namespace oaknut::util; \
\
std::uint32_t result; \
CodeGenerator code{&result}; \
\
code.CMD; \
\
REQUIRE(result == HEX); \
}
T(0x5ee0bb61, ABS(D1, D27))

View file

@ -8,18 +8,18 @@
#include "oaknut/oaknut.hpp"
#define T(HEX, CMD) \
TEST_CASE(#CMD) \
{ \
using namespace oaknut; \
using namespace oaknut::util; \
\
std::uint32_t result; \
CodeGenerator code{&result, &result}; \
\
code.CMD; \
\
REQUIRE(result == HEX); \
#define T(HEX, CMD) \
TEST_CASE(#CMD) \
{ \
using namespace oaknut; \
using namespace oaknut::util; \
\
std::uint32_t result; \
CodeGenerator code{&result}; \
\
code.CMD; \
\
REQUIRE(result == HEX); \
}
T(0x1a0f01c3, ADC(W3, W14, W15))

View file

@ -18,13 +18,14 @@ using namespace oaknut::util;
TEST_CASE("Basic Test (VectorCodeGenerator)")
{
CodeBlock mem{4096};
std::vector<std::uint32_t> vec;
VectorCodeGenerator code{vec, mem.ptr()};
VectorCodeGenerator code{vec};
code.MOV(W0, 42);
code.RET();
CodeBlock mem{4096};
mem.unprotect();
std::memcpy(mem.ptr(), vec.data(), vec.size() * sizeof(std::uint32_t));
mem.protect();
@ -36,9 +37,8 @@ TEST_CASE("Basic Test (VectorCodeGenerator)")
TEST_CASE("Fibonacci (VectorCodeGenerator)")
{
CodeBlock mem{4096};
std::vector<std::uint32_t> vec;
VectorCodeGenerator code{vec, mem.ptr()};
VectorCodeGenerator code{vec};
Label start, end, zero, recurse;
@ -69,6 +69,8 @@ TEST_CASE("Fibonacci (VectorCodeGenerator)")
code.LDP(X29, X30, SP, POST_INDEXED, 32);
code.RET();
CodeBlock mem{4096};
mem.unprotect();
std::memcpy(mem.ptr(), vec.data(), vec.size() * sizeof(std::uint32_t));
mem.protect();

View file

@ -19,10 +19,7 @@
#include "dynarmic/ir/location_descriptor.h"
namespace oaknut {
struct PointerCodeGeneratorPolicy;
template<typename>
class BasicCodeGenerator;
using CodeGenerator = BasicCodeGenerator<PointerCodeGeneratorPolicy>;
struct CodeGenerator;
struct Label;
} // namespace oaknut

View file

@ -6,10 +6,7 @@
#include <mcl/stdint.hpp>
namespace oaknut {
struct PointerCodeGeneratorPolicy;
template<typename>
class BasicCodeGenerator;
using CodeGenerator = BasicCodeGenerator<PointerCodeGeneratorPolicy>;
struct CodeGenerator;
struct Label;
} // namespace oaknut

View file

@ -8,10 +8,7 @@
#include <mcl/stdint.hpp>
namespace oaknut {
struct PointerCodeGeneratorPolicy;
template<typename>
class BasicCodeGenerator;
using CodeGenerator = BasicCodeGenerator<PointerCodeGeneratorPolicy>;
struct CodeGenerator;
} // namespace oaknut
namespace Dynarmic::Backend::Arm64 {

View file

@ -12,10 +12,7 @@
#include "dynarmic/backend/arm64/stack_layout.h"
namespace oaknut {
struct PointerCodeGeneratorPolicy;
template<typename>
class BasicCodeGenerator;
using CodeGenerator = BasicCodeGenerator<PointerCodeGeneratorPolicy>;
struct CodeGenerator;
struct Label;
} // namespace oaknut