[abi] AsmJit v1.18 - performance and memory footprint improvements

* Refactored the whole codebase to use snake_case convention to
    name functions and variables, including member variables.
    Class naming is unchanged and each starts with upper-case
    character. The intention of this change is to make the source
    code more readable and consistent across multiple projects
    where AsmJit is currently used.

  * Refactored support.h to make it more shareable across projects.

  * x86::Vec now inherits from UniVec

  * minor changes in JitAllocator and WriteScope in order to make
    the size of WriteScope smaller

  * added ZoneStatistics and Zone::statistics() getter

  * improved x86::EmitHelper to use tables instead of choose() and
    other mechanisms to pick between SSE and AVX instructions

  * Refactored the whole codebase to use snake_case convention for
    for functions names, function parameter names, struct members,
    and variables

  * Added a non-owning asmjit::Span<T> type and use into public API
    to hide the usage of ZoneVector in CodeHolder, Builder, and
    Compiler. Users now only get Span (with data and size), which
    doesn't require users to know about ZoneVector

  * Removed RAWorkId from RATiedReg in favor of RAWorkReg*

  * Removed GEN from LiveInfo as it's not needed by CFG construction
    to save memory (GEN was merged with LIVE-IN bits). The remaining
    LIVE-IN, LIVE-OUT, and KILL bits are enough, however KILL bits may
    be removed in the future as KILL bits are not needed after LIVE-IN
    and LIVE-OUT converged

  * Optimized the representation of LIVE-IN, LIVE-OUT, and KILL bits
    per block. Now only registers that live across multiple basic
    blocks are included here, which means that virtual registers that
    only live in a single block are not included and won't be overhead
    during liveness analysis. This optimization alone can make liveness
    analysis 90% faster depending on the code generated (more virtual
    registers that only live in a single basic block -> more gains)

  * Optimized building liveness information bits per block. The new
    code uses an optimized algorithm to prevent too many traversals
    and uses a more optimized code for a case in which not too many
    registers are used (it avoids array operations if the number of
    all virtual registers within the function fits a single BitWord)

  * Optimized code that computes which virtual register is only used
    in a single basic block - this aims to optimize register allocator
    in the future by using a designed code path for allocating regs
    only used in a single basic block

  * Reduced the information required for each live-span, which is used
    by bin-packing. Now the struct is 8 bytes, which is good for a lot
    of optimizations C++ compiler can do

  * Added UniCompiler (ujit) which can be used to share code paths
    between X86, X86_64, and AArch64 code generation (experimental).
This commit is contained in:
kobalicek
2025-09-06 13:43:15 +02:00
parent a3199e8857
commit 7596c6d035
211 changed files with 56385 additions and 33857 deletions

View File

@@ -35,13 +35,13 @@ public:
class A64Test_GpArgs : public A64TestCase {
public:
uint32_t _argCount;
bool _preserveFP;
uint32_t _arg_count;
bool _preserve_fp;
A64Test_GpArgs(uint32_t argCount, bool preserveFP)
: _argCount(argCount),
_preserveFP(preserveFP) {
_name.assignFormat("GpArgs {NumArgs=%u PreserveFP=%c}", argCount, preserveFP ? 'Y' : 'N');
A64Test_GpArgs(uint32_t arg_count, bool preserve_fp)
: _arg_count(arg_count),
_preserve_fp(preserve_fp) {
_name.assign_format("GpArgs {NumArgs=%u PreserveFP=%c}", arg_count, preserve_fp ? 'Y' : 'N');
}
static void add(TestApp& app) {
@@ -52,38 +52,38 @@ public:
}
virtual void compile(a64::Compiler& cc) {
uint32_t i;
uint32_t argCount = _argCount;
uint32_t arg_count = _arg_count;
FuncSignature signature;
signature.setRetT<int>();
for (i = 0; i < argCount; i++)
signature.addArgT<int>();
FuncNode* funcNode = cc.addFunc(signature);
if (_preserveFP)
funcNode->frame().setPreservedFP();
signature.set_ret_t<int>();
for (uint32_t i = 0; i < arg_count; i++) {
signature.add_arg_t<int>();
}
FuncNode* func_node = cc.add_func(signature);
if (_preserve_fp)
func_node->frame().set_preserved_fp();
a64::Gp sum;
if (argCount) {
for (i = 0; i < argCount; i++) {
a64::Gp iReg = cc.newInt32("i%u", i);
funcNode->setArg(i, iReg);
if (arg_count) {
for (uint32_t i = 0; i < arg_count; i++) {
a64::Gp i_reg = cc.new_gp32("i%u", i);
func_node->set_arg(i, i_reg);
if (i == 0)
sum = iReg;
sum = i_reg;
else
cc.add(sum, sum, iReg);
cc.add(sum, sum, i_reg);
}
}
else {
sum = cc.newInt32("i");
sum = cc.new_gp32("i");
cc.mov(sum, 0);
}
cc.ret(sum);
cc.endFunc();
cc.end_func();
}
virtual bool run(void* _func, String& result, String& expect) {
@@ -107,82 +107,82 @@ public:
using Func15 = U (*)(U, U, U, U, U, U, U, U, U, U, U, U, U, U, U);
using Func16 = U (*)(U, U, U, U, U, U, U, U, U, U, U, U, U, U, U, U);
unsigned int resultRet = 0;
unsigned int expectRet = 0;
unsigned int result_ret = 0;
unsigned int expect_ret = 0;
switch (_argCount) {
switch (_arg_count) {
case 0:
resultRet = ptr_as_func<Func0>(_func)();
expectRet = 0;
result_ret = ptr_as_func<Func0>(_func)();
expect_ret = 0;
break;
case 1:
resultRet = ptr_as_func<Func1>(_func)(1);
expectRet = 1;
result_ret = ptr_as_func<Func1>(_func)(1);
expect_ret = 1;
break;
case 2:
resultRet = ptr_as_func<Func2>(_func)(1, 2);
expectRet = 1 + 2;
result_ret = ptr_as_func<Func2>(_func)(1, 2);
expect_ret = 1 + 2;
break;
case 3:
resultRet = ptr_as_func<Func3>(_func)(1, 2, 3);
expectRet = 1 + 2 + 3;
result_ret = ptr_as_func<Func3>(_func)(1, 2, 3);
expect_ret = 1 + 2 + 3;
break;
case 4:
resultRet = ptr_as_func<Func4>(_func)(1, 2, 3, 4);
expectRet = 1 + 2 + 3 + 4;
result_ret = ptr_as_func<Func4>(_func)(1, 2, 3, 4);
expect_ret = 1 + 2 + 3 + 4;
break;
case 5:
resultRet = ptr_as_func<Func5>(_func)(1, 2, 3, 4, 5);
expectRet = 1 + 2 + 3 + 4 + 5;
result_ret = ptr_as_func<Func5>(_func)(1, 2, 3, 4, 5);
expect_ret = 1 + 2 + 3 + 4 + 5;
break;
case 6:
resultRet = ptr_as_func<Func6>(_func)(1, 2, 3, 4, 5, 6);
expectRet = 1 + 2 + 3 + 4 + 5 + 6;
result_ret = ptr_as_func<Func6>(_func)(1, 2, 3, 4, 5, 6);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6;
break;
case 7:
resultRet = ptr_as_func<Func7>(_func)(1, 2, 3, 4, 5, 6, 7);
expectRet = 1 + 2 + 3 + 4 + 5 + 6 + 7;
result_ret = ptr_as_func<Func7>(_func)(1, 2, 3, 4, 5, 6, 7);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6 + 7;
break;
case 8:
resultRet = ptr_as_func<Func8>(_func)(1, 2, 3, 4, 5, 6, 7, 8);
expectRet = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8;
result_ret = ptr_as_func<Func8>(_func)(1, 2, 3, 4, 5, 6, 7, 8);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8;
break;
case 9:
resultRet = ptr_as_func<Func9>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9);
expectRet = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9;
result_ret = ptr_as_func<Func9>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9;
break;
case 10:
resultRet = ptr_as_func<Func10>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
expectRet = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
result_ret = ptr_as_func<Func10>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10;
break;
case 11:
resultRet = ptr_as_func<Func11>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
expectRet = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11;
result_ret = ptr_as_func<Func11>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11;
break;
case 12:
resultRet = ptr_as_func<Func12>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
expectRet = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12;
result_ret = ptr_as_func<Func12>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12;
break;
case 13:
resultRet = ptr_as_func<Func13>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
expectRet = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13;
result_ret = ptr_as_func<Func13>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13;
break;
case 14:
resultRet = ptr_as_func<Func14>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
expectRet = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14;
result_ret = ptr_as_func<Func14>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14;
break;
case 15:
resultRet = ptr_as_func<Func15>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
expectRet = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15;
result_ret = ptr_as_func<Func15>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15;
break;
case 16:
resultRet = ptr_as_func<Func16>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
expectRet = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16;
result_ret = ptr_as_func<Func16>(_func)(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16);
expect_ret = 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16;
break;
}
result.assignFormat("ret={%u, %u}", resultRet >> 28, resultRet & 0x0FFFFFFFu);
expect.assignFormat("ret={%u, %u}", expectRet >> 28, expectRet & 0x0FFFFFFFu);
result.assign_format("ret={%u, %u}", result_ret >> 28, result_ret & 0x0FFFFFFFu);
expect.assign_format("ret={%u, %u}", expect_ret >> 28, expect_ret & 0x0FFFFFFFu);
return result == expect;
}
@@ -201,42 +201,42 @@ public:
}
virtual void compile(a64::Compiler& cc) {
FuncNode* funcNode = cc.addFunc(FuncSignature::build<void, void*, const void*, const void*>());
FuncNode* func_node = cc.add_func(FuncSignature::build<void, void*, const void*, const void*>());
a64::Gp dst = cc.newUIntPtr("dst");
a64::Gp src1 = cc.newUIntPtr("src1");
a64::Gp src2 = cc.newUIntPtr("src2");
a64::Gp dst = cc.new_gp_ptr("dst");
a64::Gp src1 = cc.new_gp_ptr("src1");
a64::Gp src2 = cc.new_gp_ptr("src2");
funcNode->setArg(0, dst);
funcNode->setArg(1, src1);
funcNode->setArg(2, src2);
func_node->set_arg(0, dst);
func_node->set_arg(1, src1);
func_node->set_arg(2, src2);
a64::Vec v1 = cc.newVecQ("vec1");
a64::Vec v2 = cc.newVecQ("vec2");
a64::Vec v3 = cc.newVecQ("vec3");
a64::Vec v1 = cc.new_vec_q("vec1");
a64::Vec v2 = cc.new_vec_q("vec2");
a64::Vec v3 = cc.new_vec_q("vec3");
cc.ldr(v2, a64::ptr(src1));
cc.ldr(v3, a64::ptr(src2));
cc.add(v1.b16(), v2.b16(), v3.b16());
cc.str(v1, a64::ptr(dst));
cc.endFunc();
cc.end_func();
}
virtual bool run(void* _func, String& result, String& expect) {
using Func = void (*)(void*, const void*, const void*);
uint32_t dst[4];
uint32_t aSrc[4] = { 0 , 1 , 2 , 255 };
uint32_t bSrc[4] = { 99, 17, 33, 1 };
uint32_t a_src[4] = { 0 , 1 , 2 , 255 };
uint32_t b_src[4] = { 99, 17, 33, 1 };
// NOTE: It's a byte-add, so uint8_t(255+1) == 0.
uint32_t ref[4] = { 99, 18, 35, 0 };
ptr_as_func<Func>(_func)(dst, aSrc, bSrc);
ptr_as_func<Func>(_func)(dst, a_src, b_src);
result.assignFormat("ret={%u, %u, %u, %u}", dst[0], dst[1], dst[2], dst[3]);
expect.assignFormat("ret={%u, %u, %u, %u}", ref[0], ref[1], ref[2], ref[3]);
result.assign_format("ret={%u, %u, %u, %u}", dst[0], dst[1], dst[2], dst[3]);
expect.assign_format("ret={%u, %u, %u, %u}", ref[0], ref[1], ref[2], ref[3]);
return result == expect;
}
@@ -247,12 +247,12 @@ public:
class A64Test_ManyRegs : public A64TestCase {
public:
uint32_t _regCount;
uint32_t _reg_count;
A64Test_ManyRegs(uint32_t n)
: A64TestCase(),
_regCount(n) {
_name.assignFormat("GpRegs {NumRegs=%u}", n);
_reg_count(n) {
_name.assign_format("GpRegs {NumRegs=%u}", n);
}
static void add(TestApp& app) {
@@ -261,24 +261,24 @@ public:
}
virtual void compile(a64::Compiler& cc) {
cc.addFunc(FuncSignature::build<int>());
cc.add_func(FuncSignature::build<int>());
a64::Gp* regs = static_cast<a64::Gp*>(malloc(_regCount * sizeof(a64::Gp)));
a64::Gp* regs = static_cast<a64::Gp*>(malloc(_reg_count * sizeof(a64::Gp)));
for (uint32_t i = 0; i < _regCount; i++) {
regs[i] = cc.newUInt32("reg%u", i);
for (uint32_t i = 0; i < _reg_count; i++) {
regs[i] = cc.new_gp32("reg%u", i);
cc.mov(regs[i], i + 1);
}
a64::Gp sum = cc.newUInt32("sum");
a64::Gp sum = cc.new_gp32("sum");
cc.mov(sum, 0);
for (uint32_t i = 0; i < _regCount; i++) {
for (uint32_t i = 0; i < _reg_count; i++) {
cc.add(sum, sum, regs[i]);
}
cc.ret(sum);
cc.endFunc();
cc.end_func();
free(regs);
}
@@ -287,14 +287,14 @@ public:
using Func = int (*)(void);
Func func = ptr_as_func<Func>(_func);
result.assignFormat("ret={%d}", func());
expect.assignFormat("ret={%d}", calcSum());
result.assign_format("ret={%d}", func());
expect.assign_format("ret={%d}", calc_sum());
return result == expect;
}
uint32_t calcSum() const {
return (_regCount | 1) * ((_regCount + 1) / 2);
uint32_t calc_sum() const {
return (_reg_count | 1) * ((_reg_count + 1) / 2);
}
};
@@ -311,32 +311,32 @@ public:
}
virtual void compile(a64::Compiler& cc) {
cc.addFunc(FuncSignature::build<int>());
cc.add_func(FuncSignature::build<int>());
a64::Gp addr = cc.newIntPtr("addr");
a64::Gp val = cc.newIntPtr("val");
a64::Gp addr = cc.new_gp_ptr("addr");
a64::Gp val = cc.new_gp_ptr("val");
Label L_Table = cc.newLabel();
Label L_Table = cc.new_label();
cc.adr(addr, L_Table);
cc.ldrsw(val, a64::ptr(addr, 8));
cc.ret(val);
cc.endFunc();
cc.end_func();
cc.bind(L_Table);
cc.embedInt32(1);
cc.embedInt32(2);
cc.embedInt32(3);
cc.embedInt32(4);
cc.embedInt32(5);
cc.embed_int32(1);
cc.embed_int32(2);
cc.embed_int32(3);
cc.embed_int32(4);
cc.embed_int32(5);
}
virtual bool run(void* _func, String& result, String& expect) {
using Func = int (*)(void);
Func func = ptr_as_func<Func>(_func);
result.assignFormat("ret={%d}", func());
expect.assignFormat("ret={%d}", 3);
result.assign_format("ret={%d}", func());
expect.assign_format("ret={%d}", 3);
return result == expect;
}
@@ -355,15 +355,15 @@ public:
}
virtual void compile(a64::Compiler& cc) {
FuncNode* funcNode = cc.addFunc(FuncSignature::build<void, void*, size_t>());
FuncNode* func_node = cc.add_func(FuncSignature::build<void, void*, size_t>());
a64::Gp p = cc.newIntPtr("p");
a64::Gp count = cc.newIntPtr("count");
a64::Gp i = cc.newIntPtr("i");
Label L = cc.newLabel();
a64::Gp p = cc.new_gp_ptr("p");
a64::Gp count = cc.new_gp_ptr("count");
a64::Gp i = cc.new_gp_ptr("i");
Label L = cc.new_label();
funcNode->setArg(0, p);
funcNode->setArg(1, count);
func_node->set_arg(0, p);
func_node->set_arg(1, count);
cc.mov(i, 0);
@@ -373,7 +373,7 @@ public:
cc.cmp(i, count);
cc.b_ne(L);
cc.endFunc();
cc.end_func();
}
virtual bool run(void* _func, String& result, String& expect) {
@@ -389,7 +389,7 @@ public:
for (size_t i = 0; i < 16; i++) {
if (i)
result.append(", ");
result.appendFormat("%d", int(array[i]));
result.append_format("%d", int(array[i]));
}
result.append("}");
@@ -410,26 +410,26 @@ public:
}
virtual void compile(a64::Compiler& cc) {
FuncNode* funcNode = cc.addFunc(FuncSignature::build<uint32_t, uint32_t, uint32_t>());
FuncNode* func_node = cc.add_func(FuncSignature::build<uint32_t, uint32_t, uint32_t>());
a64::Gp x = cc.newUInt32("x");
a64::Gp y = cc.newUInt32("y");
a64::Gp r = cc.newUInt32("r");
a64::Gp fn = cc.newUIntPtr("fn");
a64::Gp x = cc.new_gp32("x");
a64::Gp y = cc.new_gp32("y");
a64::Gp r = cc.new_gp32("r");
a64::Gp fn = cc.new_gp_ptr("fn");
funcNode->setArg(0, x);
funcNode->setArg(1, y);
func_node->set_arg(0, x);
func_node->set_arg(1, y);
cc.mov(fn, (uint64_t)calledFunc);
cc.mov(fn, (uint64_t)called_fn);
InvokeNode* invokeNode;
cc.invoke(&invokeNode, fn, FuncSignature::build<uint32_t, uint32_t, uint32_t>());
invokeNode->setArg(0, x);
invokeNode->setArg(1, y);
invokeNode->setRet(0, r);
InvokeNode* invoke_node;
cc.invoke(Out(invoke_node), fn, FuncSignature::build<uint32_t, uint32_t, uint32_t>());
invoke_node->set_arg(0, x);
invoke_node->set_arg(1, y);
invoke_node->set_ret(0, r);
cc.ret(r);
cc.endFunc();
cc.end_func();
}
virtual bool run(void* _func, String& result, String& expect) {
@@ -439,13 +439,13 @@ public:
uint32_t x = 49;
uint32_t y = 7;
result.assignFormat("ret={%u}", func(x, y));
expect.assignFormat("ret={%u}", x - y);
result.assign_format("ret={%u}", func(x, y));
expect.assign_format("ret={%u}", x - y);
return result == expect;
}
static uint32_t calledFunc(uint32_t x, uint32_t y) {
static uint32_t called_fn(uint32_t x, uint32_t y) {
return x - y;
}
};
@@ -463,25 +463,25 @@ public:
}
virtual void compile(a64::Compiler& cc) {
FuncNode* funcNode = cc.addFunc(FuncSignature::build<double, double, double>());
FuncNode* func_node = cc.add_func(FuncSignature::build<double, double, double>());
a64::Vec x = cc.newVecD("x");
a64::Vec y = cc.newVecD("y");
a64::Vec r = cc.newVecD("r");
a64::Gp fn = cc.newUIntPtr("fn");
a64::Vec x = cc.new_vec_d("x");
a64::Vec y = cc.new_vec_d("y");
a64::Vec r = cc.new_vec_d("r");
a64::Gp fn = cc.new_gp_ptr("fn");
funcNode->setArg(0, x);
funcNode->setArg(1, y);
cc.mov(fn, (uint64_t)calledFunc);
func_node->set_arg(0, x);
func_node->set_arg(1, y);
cc.mov(fn, (uint64_t)called_fn);
InvokeNode* invokeNode;
cc.invoke(&invokeNode, fn, FuncSignature::build<double, double, double>());
invokeNode->setArg(0, x);
invokeNode->setArg(1, y);
invokeNode->setRet(0, r);
InvokeNode* invoke_node;
cc.invoke(Out(invoke_node), fn, FuncSignature::build<double, double, double>());
invoke_node->set_arg(0, x);
invoke_node->set_arg(1, y);
invoke_node->set_ret(0, r);
cc.ret(r);
cc.endFunc();
cc.end_func();
}
virtual bool run(void* _func, String& result, String& expect) {
@@ -491,13 +491,13 @@ public:
double x = 49;
double y = 7;
result.assignFormat("ret={%f}", func(x, y));
expect.assignFormat("ret={%f}", calledFunc(x, y));
result.assign_format("ret={%f}", func(x, y));
expect.assign_format("ret={%f}", called_fn(x, y));
return result == expect;
}
static double calledFunc(double x, double y) {
static double called_fn(double x, double y) {
return x - y;
}
};
@@ -515,25 +515,25 @@ public:
}
virtual void compile(a64::Compiler& cc) {
FuncNode* funcNode = cc.addFunc(FuncSignature::build<double, double, double>());
FuncNode* func_node = cc.add_func(FuncSignature::build<double, double, double>());
a64::Vec x = cc.newVecD("x");
a64::Vec y = cc.newVecD("y");
a64::Vec r = cc.newVecD("r");
a64::Gp fn = cc.newUIntPtr("fn");
a64::Vec x = cc.new_vec_d("x");
a64::Vec y = cc.new_vec_d("y");
a64::Vec r = cc.new_vec_d("r");
a64::Gp fn = cc.new_gp_ptr("fn");
funcNode->setArg(0, x);
funcNode->setArg(1, y);
cc.mov(fn, (uint64_t)calledFunc);
func_node->set_arg(0, x);
func_node->set_arg(1, y);
cc.mov(fn, (uint64_t)called_fn);
InvokeNode* invokeNode;
cc.invoke(&invokeNode, fn, FuncSignature::build<double, double, double>());
invokeNode->setArg(0, y);
invokeNode->setArg(1, x);
invokeNode->setRet(0, r);
InvokeNode* invoke_node;
cc.invoke(Out(invoke_node), fn, FuncSignature::build<double, double, double>());
invoke_node->set_arg(0, y);
invoke_node->set_arg(1, x);
invoke_node->set_ret(0, r);
cc.ret(r);
cc.endFunc();
cc.end_func();
}
virtual bool run(void* _func, String& result, String& expect) {
@@ -543,13 +543,13 @@ public:
double x = 49;
double y = 7;
result.assignFormat("ret={%f}", func(x, y));
expect.assignFormat("ret={%f}", calledFunc(y, x));
result.assign_format("ret={%f}", func(x, y));
expect.assign_format("ret={%f}", called_fn(y, x));
return result == expect;
}
static double calledFunc(double x, double y) {
static double called_fn(double x, double y) {
return x - y;
}
};
@@ -564,7 +564,7 @@ public:
A64Test_JumpTable(bool annotated)
: A64TestCase("A64Test_JumpTable"),
_annotated(annotated) {
_name.assignFormat("JumpTable {%s}", annotated ? "Annotated" : "Unknown Target");
_name.assign_format("JumpTable {%s}", annotated ? "Annotated" : "Unknown Target");
}
enum Operator {
@@ -580,26 +580,26 @@ public:
}
virtual void compile(a64::Compiler& cc) {
FuncNode* funcNode = cc.addFunc(FuncSignature::build<float, float, float, uint32_t>());
FuncNode* func_node = cc.add_func(FuncSignature::build<float, float, float, uint32_t>());
a64::Vec a = cc.newVecS("a");
a64::Vec b = cc.newVecS("b");
a64::Gp op = cc.newUInt32("op");
a64::Vec a = cc.new_vec_s("a");
a64::Vec b = cc.new_vec_s("b");
a64::Gp op = cc.new_gp32("op");
a64::Gp target = cc.newIntPtr("target");
a64::Gp offset = cc.newIntPtr("offset");
a64::Gp target = cc.new_gp_ptr("target");
a64::Gp offset = cc.new_gp_ptr("offset");
Label L_End = cc.newLabel();
Label L_End = cc.new_label();
Label L_Table = cc.newLabel();
Label L_Add = cc.newLabel();
Label L_Sub = cc.newLabel();
Label L_Mul = cc.newLabel();
Label L_Div = cc.newLabel();
Label L_Table = cc.new_label();
Label L_Add = cc.new_label();
Label L_Sub = cc.new_label();
Label L_Mul = cc.new_label();
Label L_Div = cc.new_label();
funcNode->setArg(0, a);
funcNode->setArg(1, b);
funcNode->setArg(2, op);
func_node->set_arg(0, a);
func_node->set_arg(1, b);
func_node->set_arg(2, op);
cc.adr(target, L_Table);
cc.ldrsw(offset, a64::ptr(target, op, a64::sxtw(2)));
@@ -608,11 +608,11 @@ public:
// JumpAnnotation allows to annotate all possible jump targets of
// instructions where it cannot be deduced from operands.
if (_annotated) {
JumpAnnotation* annotation = cc.newJumpAnnotation();
annotation->addLabel(L_Add);
annotation->addLabel(L_Sub);
annotation->addLabel(L_Mul);
annotation->addLabel(L_Div);
JumpAnnotation* annotation = cc.new_jump_annotation();
annotation->add_label(L_Add);
annotation->add_label(L_Sub);
annotation->add_label(L_Mul);
annotation->add_label(L_Div);
cc.br(target, annotation);
}
else {
@@ -636,13 +636,13 @@ public:
cc.bind(L_End);
cc.ret(a);
cc.endFunc();
cc.end_func();
cc.bind(L_Table);
cc.embedLabelDelta(L_Add, L_Table, 4);
cc.embedLabelDelta(L_Sub, L_Table, 4);
cc.embedLabelDelta(L_Mul, L_Table, 4);
cc.embedLabelDelta(L_Div, L_Table, 4);
cc.embed_label_delta(L_Add, L_Table, 4);
cc.embed_label_delta(L_Sub, L_Table, 4);
cc.embed_label_delta(L_Mul, L_Table, 4);
cc.embed_label_delta(L_Div, L_Table, 4);
}
virtual bool run(void* _func, String& result, String& expect) {
@@ -662,8 +662,8 @@ public:
ref[2] = 60.0f;
ref[3] = 10.0f;
result.assignFormat("ret={%f, %f, %f, %f}", dst[0], dst[1], dst[2], dst[3]);
expect.assignFormat("ret={%f, %f, %f, %f}", ref[0], ref[1], ref[2], ref[3]);
result.assign_format("ret={%f, %f, %f, %f}", double(dst[0]), double(dst[1]), double(dst[2]), double(dst[3]));
expect.assign_format("ret={%f, %f, %f, %f}", double(ref[0]), double(ref[1]), double(ref[2]), double(ref[3]));
return result == expect;
}
@@ -673,15 +673,15 @@ public:
// ======================
void compiler_add_a64_tests(TestApp& app) {
app.addT<A64Test_GpArgs>();
app.addT<A64Test_ManyRegs>();
app.addT<A64Test_Simd1>();
app.addT<A64Test_Adr>();
app.addT<A64Test_Branch1>();
app.addT<A64Test_Invoke1>();
app.addT<A64Test_Invoke2>();
app.addT<A64Test_Invoke3>();
app.addT<A64Test_JumpTable>();
app.add_t<A64Test_GpArgs>();
app.add_t<A64Test_ManyRegs>();
app.add_t<A64Test_Simd1>();
app.add_t<A64Test_Adr>();
app.add_t<A64Test_Branch1>();
app.add_t<A64Test_Invoke1>();
app.add_t<A64Test_Invoke2>();
app.add_t<A64Test_Invoke3>();
app.add_t<A64Test_JumpTable>();
}
#endif // !ASMJIT_NO_COMPILER && !ASMJIT_NO_AARCH64