CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
hrydgard

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: hrydgard/ppsspp
Path: blob/master/android/jni/Arm64EmitterTest.cpp
Views: 1401
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
const u8 *start = AlignCode16();
39
40
uint32_t regs_to_save = Arm64Gen::ALL_CALLEE_SAVED;
41
uint32_t regs_to_save_fp = Arm64Gen::ALL_CALLEE_SAVED_FP;
42
fp.ABI_PushRegisters(regs_to_save, regs_to_save_fp);
43
44
PUSH(X3);
45
POP(X3);
46
47
PUSH2(X3, X4);
48
POP2(X3, X4);
49
50
fp.SCVTF(S0, W3, 12);
51
fp.SCVTF(S3, W12);
52
MOVI2R(X0, 1337);
53
54
fp.ABI_PopRegisters(regs_to_save, regs_to_save_fp);
55
56
RET();
57
58
FlushIcache();
59
}
60
61
static u32 CallPtr(const void *ptr) {
62
return ((u32(*)())ptr)();
63
}
64
65
void Arm64EmitterTest() {
66
return;
67
68
for (int i = 0; i < 6; i++) {
69
INFO_LOG(Log::System, "---------------------------");
70
}
71
INFO_LOG(Log::System, "---------------------------");
72
INFO_LOG(Log::System, "Running ARM64 emitter test!");
73
INFO_LOG(Log::System, "---------------------------");
74
75
TestCode gen;
76
gen.ReserveCodeSpace(0x1000);
77
const u8 *codeStart = gen.GetCodePtr();
78
gen.Generate();
79
80
u32 retval = CallPtr(gen.testCodePtr);
81
INFO_LOG(Log::System, "Returned %d", retval);
82
// INFO_LOG(Log::System, "ARM emitter test 1 passed if %f == 3.0! retval = %08x", abc[32 + 31], retval);
83
/*
84
INFO_LOG(Log::System, "x: %08x %08x %08x %08x", x[0], x[1], x[2], x[3]);
85
INFO_LOG(Log::System, "y: %08x %08x %08x %08x", y[0], y[1], y[2], y[3]);
86
INFO_LOG(Log::System, "z: %08x %08x %08x %08x", z[0], z[1], z[2], z[3]);
87
INFO_LOG(Log::System, "c: %f %f %f %f", c[0], c[1], c[2], c[3]);*/
88
for (int i = 0; i < 6; i++) {
89
INFO_LOG(Log::System, "--------------------------");
90
}
91
// DisassembleArm(codeStart, gen.GetCodePtr()-codeStart);
92
}
93
94