Refactored register allocator asm Compiler. (#249)

Refactored build system macros (ASMJIT_BUILD_STATIC -> ASMJIT_STATIC)
Refactored AVX512 broadcast {1toN} - moved to operand from instruction.
Refactored naming - renamed getters to not use get prefix.
Refactored code structure - move arch-specific stuff into x86 namespace.
Refactored some compiler/arch-specific macros, respect rel/abs option in mov REG, [ADDR].
Refactored StringBuilder (Renamed to String, added small string optimization).
Refactored LabelId<->LabelEntry mapping, force label offset to 64-bits on all archs.
Renamed Runtime to Target (JitRuntime kept for now).
Renamed VirtMemManager to JitAllocator.
Renamed VirtMem to JitUtils.
Renamed FuncSignatureX to FuncSignatureBuilder.
Fixed xchg [mem], rex-lo, refactored RelocEntry.
Fixed Logger to always show abs|rel when formatting a memory operand
Fixed Logger to prefix HEX numbers with 0x prefix
Fixed Support::ctzGeneric to always return uint32_t, T doesn't matter.
Fixed LightCall to not save MMX and K registers
Fixed CpuInfo constructor to propagate NoInit (#243)
Added VAES, AVX512_VBMI2, AVX512_VNNI, and AVX512_BITALG cpu-features and instructions.
Added emscripten support (asmjit can be now compiled by emscripten).
Added asmjit.natvis for better MSVC experience
Added x86::ptr_abs|ptr_rel
Added support for multibyte nop r/m (#135)
Added support for 32-bit to 64-bit zero-extended addresses, improved validation of memory addresses, and removed wrt address type as this will be reworked
Added support for multiple sections, reworked address table support (previously known as trampolines)
Added the following x86 modifiers to the x86::Emitter - xacquire(), xrelease(), and k(kreg)
Added a possibility to use REP prefix with RET instruction
Added a possibility to relocate [rel addr] during relocate()
Added a variadic function-call support (Compiler), argument duplication (Compiler), better /dev/shm vs /tmp shared memory handling (VirtMem).
Removed imm_u imm_ptr helpers, imm() can now accept any integer and pointer.
Changed the default behavior of optimizing instructions to disabled with a possibility to enable that feature through kOptionOptimizedForSize
Use default copy construction / assignment to prevent new kind of warnings introduced by GCC 9
This commit is contained in:
Petr Kobalicek
2019-07-16 01:24:22 +02:00
committed by GitHub
parent 761130b1d8
commit 5d40561d14
196 changed files with 65058 additions and 56743 deletions

View File

@@ -1,5 +1,5 @@
// [AsmJit]
// Complete x86/x64 JIT and Remote Assembler for C++.
// Machine Code Generation for C++.
//
// [License]
// Zlib - See LICENSE.md file in the package.
@@ -8,10 +8,8 @@
// disassembled in your IDE or by your favorite disassembler. Instructions
// are grouped by category and then sorted alphabetically.
// [Dependencies]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "./asmjit.h"
#include "./asmjit_test_opcode.h"
@@ -19,18 +17,18 @@
using namespace asmjit;
struct OpcodeDumpInfo {
uint32_t archType;
uint32_t archId;
bool useRex1;
bool useRex2;
};
static const char* archTypeToString(uint32_t archType) {
switch (archType) {
case ArchInfo::kTypeNone : return "None";
case ArchInfo::kTypeX86 : return "X86";
case ArchInfo::kTypeX64 : return "X64";
case ArchInfo::kTypeA32 : return "A32";
case ArchInfo::kTypeA64 : return "A64";
static const char* archIdToString(uint32_t archId) {
switch (archId) {
case ArchInfo::kIdNone: return "None";
case ArchInfo::kIdX86 : return "X86";
case ArchInfo::kIdX64 : return "X64";
case ArchInfo::kIdA32 : return "A32";
case ArchInfo::kIdA64 : return "A64";
default:
return "<unknown>";
@@ -38,51 +36,55 @@ static const char* archTypeToString(uint32_t archType) {
}
struct TestErrorHandler : public ErrorHandler {
virtual bool handleError(Error err, const char* message, CodeEmitter* origin) {
virtual void handleError(Error err, const char* message, BaseEmitter* origin) {
(void)origin;
printf("ERROR 0x%08X: %s\n", err, message);
return true;
}
};
typedef void (*VoidFunc)(void);
int main(int argc, char* argv[]) {
ASMJIT_UNUSED(argc);
ASMJIT_UNUSED(argv);
TestErrorHandler eh;
OpcodeDumpInfo infoList[] = {
{ ArchInfo::kTypeX86, false, false },
{ ArchInfo::kTypeX64, false, false },
{ ArchInfo::kTypeX64, false, true },
{ ArchInfo::kTypeX64, true , false },
{ ArchInfo::kTypeX64, true , true }
{ ArchInfo::kIdX86, false, false },
{ ArchInfo::kIdX64, false, false },
{ ArchInfo::kIdX64, false, true },
{ ArchInfo::kIdX64, true , false },
{ ArchInfo::kIdX64, true , true }
};
for (int i = 0; i < ASMJIT_ARRAY_SIZE(infoList); i++) {
for (uint32_t i = 0; i < ASMJIT_ARRAY_SIZE(infoList); i++) {
const OpcodeDumpInfo& info = infoList[i];
printf("Opcodes [ARCH=%s REX1=%s REX2=%s]\n",
archTypeToString(info.archType),
archIdToString(info.archId),
info.useRex1 ? "true" : "false",
info.useRex2 ? "true" : "false");
CodeHolder code;
code.init(CodeInfo(info.archType));
code.init(CodeInfo(info.archId));
code.setErrorHandler(&eh);
#if !defined(ASMJIT_DISABLE_LOGGING)
#ifndef ASMJIT_NO_LOGGING
FileLogger logger(stdout);
logger.addOptions(Logger::kOptionBinaryForm);
logger.addFlags(FormatOptions::kFlagMachineCode);
code.setLogger(&logger);
#endif // ASMJIT_DISABLE_LOGGING
#endif
X86Assembler a(&code);
asmtest::generateOpcodes(a, info.useRex1, info.useRex2);
x86::Assembler a(&code);
asmtest::generateOpcodes(a.as<x86::Emitter>(), info.useRex1, info.useRex2);
// If this is the host architecture the code generated can be executed
// for debugging purposes (the first instruction is ret anyway).
if (code.getArchType() == ArchInfo::kTypeHost) {
if (code.archId() == ArchInfo::kIdHost) {
JitRuntime runtime;
VoidFunc p;
Error err = runtime.add(&p, &code);
if (err == kErrorOk) p();
}