diff --git a/libs/jit/include/pslang/jit/helpers.hpp b/libs/jit/include/pslang/jit/helpers.hpp new file mode 100644 index 0000000..946c61b --- /dev/null +++ b/libs/jit/include/pslang/jit/helpers.hpp @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +#include +#include + +namespace pslang::jit +{ + + inline std::uint8_t operator""_ub(unsigned long long arg) + { + return (std::uint8_t)arg; + } + + template + static void check_bits(T value, std::uint32_t bits, char const * message) + { + auto mask = (T(1) << bits) - T(1); + bool good = true; + if (value >= T(0)) + { + good = value == (value & mask); + } + else + { + good = (value & (~mask)) == (T(-1) & (~mask)); + } + if (!good) + { + T min, max; + if (std::is_unsigned_v) + { + min = 0; + max = mask; + } + else + { + max = (T(1) << (bits - 1)) - 1; + min = - (max + 1); + } + throw std::runtime_error(std::format("{}: {} not in range [{}..{})", message, value, min, max)); + } + } + + template + void push_bytes(std::vector & code, Args ... args) + { + (code.insert(code.end(), (std::uint8_t const *)(&args), (std::uint8_t const *)(&args) + sizeof(args)), ...); + } + +} diff --git a/libs/jit/source/arch/macos_aarch64/instruction_builder.cpp b/libs/jit/source/arch/macos_aarch64/instruction_builder.cpp index 1cfac55..9a56e72 100644 --- a/libs/jit/source/arch/macos_aarch64/instruction_builder.cpp +++ b/libs/jit/source/arch/macos_aarch64/instruction_builder.cpp @@ -1,40 +1,9 @@ #include - -#include +#include namespace pslang::jit::macos_aarch64 { - template - static void check_bits(T value, std::uint32_t bits, char const * message) - { - auto mask = (T(1) << bits) - T(1); - bool good = true; - if (value >= T(0)) - { - good = value == (value & mask); - } - else - { - good = (value & (~mask)) == (T(-1) & (~mask)); - } - if (!good) - { - T min, max; - if (std::is_unsigned_v) - { - min = 0; - max = mask; - } - else - { - max = (T(1) << (bits - 1)) - 1; - min = - (max + 1); - } - throw std::runtime_error(std::format("{}: {} not in range [{}..{})", message, value, min, max)); - } - } - static constexpr std::uint32_t REG_MASK = 0x1fu; void instruction_builder::nop()