Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
hrydgard
GitHub Repository: hrydgard/ppsspp
Path: blob/master/android/jni/Arm64EmitterTest.cpp
3185 views
1
#include "Common/Arm64Emitter.h"
2
#include "Common/BitSet.h"
3
#include "Common/CPUDetect.h"
4
#include "Common/Log.h"
5
6
static bool functionWasCalled;
7
8
using namespace Arm64Gen;
9
10
class TestCode : public Arm64Gen::ARM64CodeBlock {
11
public:
12
TestCode();
13
void Generate();
14
const u8 *testCodePtr;
15
const u8 *testCodePtr2;
16
ARM64FloatEmitter fp;
17
};
18
19
TestCode::TestCode() : fp(this)
20
{
21
AllocCodeSpace(0x10000);
22
}
23
24
static float abc[256] = {1.0f, 2.0f, 0.0f};
25
26
static float a[4] = {1.0f, 2.0f, 3.0f, 4.5f};
27
static float b[4] = {1.0f, 1.0f, 1.0f, 0.5f};
28
static float c[4] = {0.0f, 0.0f, 0.0f, 0.0f};
29
30
static u32 x[4] = {0x04030201, 0x08070605, 0x0, 0x0};
31
static u32 y[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
32
static u32 z[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};
33
34
void TestCode::Generate()
35
{
36
testCodePtr = this->GetCodePtr();
37
38
uint32_t regs_to_save = Arm64Gen::ALL_CALLEE_SAVED;
39
uint32_t regs_to_save_fp = Arm64Gen::ALL_CALLEE_SAVED_FP;
40
fp.ABI_PushRegisters(regs_to_save, regs_to_save_fp);
41
42
PUSH(X3);
43
POP(X3);
44
45
PUSH2(X3, X4);
46
POP2(X3, X4);
47
48
fp.SCVTF(S0, W3, 12);
49
fp.SCVTF(S3, W12);
50
MOVI2R(X0, 1337);
51
52
fp.ABI_PopRegisters(regs_to_save, regs_to_save_fp);
53
54
RET();
55
56
FlushIcache();
57
}
58
59
static u32 CallPtr(const void *ptr) {
60
return ((u32(*)())ptr)();
61
}
62
63
void Arm64EmitterTest() {
64
return;
65
66
for (int i = 0; i < 6; i++) {
67
INFO_LOG(Log::System, "---------------------------");
68
}
69
INFO_LOG(Log::System, "---------------------------");
70
INFO_LOG(Log::System, "Running ARM64 emitter test!");
71
INFO_LOG(Log::System, "---------------------------");
72
73
TestCode gen;
74
gen.ReserveCodeSpace(0x1000);
75
const u8 *codeStart = gen.GetCodePtr();
76
gen.Generate();
77
78
u32 retval = CallPtr(gen.testCodePtr);
79
INFO_LOG(Log::System, "Returned %d", retval);
80
// INFO_LOG(Log::System, "ARM emitter test 1 passed if %f == 3.0! retval = %08x", abc[32 + 31], retval);
81
/*
82
INFO_LOG(Log::System, "x: %08x %08x %08x %08x", x[0], x[1], x[2], x[3]);
83
INFO_LOG(Log::System, "y: %08x %08x %08x %08x", y[0], y[1], y[2], y[3]);
84
INFO_LOG(Log::System, "z: %08x %08x %08x %08x", z[0], z[1], z[2], z[3]);
85
INFO_LOG(Log::System, "c: %f %f %f %f", c[0], c[1], c[2], c[3]);*/
86
for (int i = 0; i < 6; i++) {
87
INFO_LOG(Log::System, "--------------------------");
88
}
89
// DisassembleArm(codeStart, gen.GetCodePtr()-codeStart);
90
}
91
92