CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!
Path: blob/master/android/jni/ArmEmitterTest.cpp
Views: 1401
#include "ArmEmitterTest.h"12#include "Common/ArmEmitter.h"3#include "Common/CPUDetect.h"45static bool functionWasCalled;67using namespace ArmGen;89class TestCode : public ArmGen::ARMXCodeBlock {10public:11TestCode();12void Generate();13const u8 *testCodePtr;14const u8 *testCodePtr2;15};1617TestCode::TestCode()18{19AllocCodeSpace(0x10000);20}2122static float abc[256] = {1.0f, 2.0f, 0.0f};2324static float a[4] = {1.0f, 2.0f, 3.0f, 4.5f};25static float b[4] = {1.0f, 1.0f, 1.0f, 0.5f};26static float c[4] = {0.0f, 0.0f, 0.0f, 0.0f};2728static u32 x[4] = {0x04030201, 0x08070605, 0x0, 0x0};29static u32 y[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};30static u32 z[4] = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF};3132void TestCode::Generate()33{34testCodePtr = this->GetCodePtr();35// Sonic1 commented that R11 is the frame pointer in debug mode, whatever "debug mode" means.36PUSH(2, R11, R_LR);3738// Load the three pointers39/*40MOVP2R(R0, a);41MOVP2R(R1, b);42MOVP2R(R2, c);4344// Load from two, do the operation, write to the third.45VLD1(F_32, D0, R0, 2); // Load 2 doubles46VLD1(F_32, D2, R1, 2); // Load another 2 doubles47// VADD(F_32, Q2, Q0, Q1); // Add them, seeing them as floating point quads48VMUL_scalar(F_32, Q2, Q0, DScalar(D3, 1)); // Multiply a quad by a scalar (ultra efficient for matrix mul! limitation: Scalar has to come out of D0-D15)49ADD(R1, R1, 12);50VLD1_all_lanes(F_32, Q2, R1, true);51ADD(R0, R0, 12);52VLD1_lane(F_32, D4, R0, 1, true);53// VMUL(F_32, Q2, Q0, Q1);54VST1(F_32, D4, R2, 2);55*/5657// Let's try some integer stuff58MOVP2R(R0, x);59MOVP2R(R1, y);60MOVP2R(R2, z);61MOVP2R(R3, c);62VLD1(I_32, D0, R0, 1); // Load 1 double63VMOVL(I_8 | I_UNSIGNED, Q1, D0);64VMOVL(I_16 | I_UNSIGNED, Q2, D2);65VCVT(F_32 | I_SIGNED, Q3, Q2);66VST1(I_32, D2, R1, 2);67VST1(I_32, D4, R2, 2);68VST1(I_32, D6, R3, 2);69PLD(R1, 32);70u32 word = *(u32 *)(GetCodePtr() - 4);71INFO_LOG(Log::System, "Instruction Word: %08x", word);727374// This works!7576// c will later be logged.7778/*79MOVP2R(R11, &abc[0]);80MOVI2R(R1, 0x3f800000);81STR(R11, R1, 4 * (32 + 31));82VLDR(S0, R11, 0);83VLDR(S1, R11, 4);84VADD(S12, S0, S1);85VSTR(S0, R11, 4 * (32 + 31));86VSTR(S12, R11, 4 * (32 + 31));87*/88//VSTR(S2, R0, 8);89POP(2, R11, R_PC); // Yup, this is how you return.9091FlushLitPool();92FlushIcache();9394//VLDR(S1, R0, 4);95//VADD(S2, S0, S1);96//VSTR(S2, R0, 8);97//QuickCallFunction(R3, (void*)&TestLeaf);9899//ARMABI_CallFunctionCCC((void*)&TestLeaf, 0x1, 0x100, 0x1337);100//ARMABI_CallFunctionCCC((void*)&TestLeaf, 0x2, 0x100, 0x31337);101//ARMABI_CallFunctionCCC((void*)&TestLeaf, 0x3, 0x100, 0x1337);102}103104105u32 CallPtr(const void *ptr)106{107return ((u32(*)())ptr)();108}109110extern void DisassembleArm(const u8 *data, int size);111112113void ArmEmitterTest()114{115// Disabled for now.116return;117118// If I commit with it enabled by accident, let's not blow up.119if (!cpu_info.bNEON)120return;121122for (int i = 0; i < 6; i++) {123INFO_LOG(Log::System, "--------------------------");124}125INFO_LOG(Log::System, "--------------------------");126INFO_LOG(Log::System, "Running ARM emitter test!");127INFO_LOG(Log::System, "--------------------------");128129TestCode gen;130gen.ReserveCodeSpace(0x1000);131const u8 *codeStart = gen.GetCodePtr();132gen.Generate();133134u32 retval = CallPtr(gen.testCodePtr);135// INFO_LOG(Log::System, "ARM emitter test 1 passed if %f == 3.0! retval = %08x", abc[32 + 31], retval);136INFO_LOG(Log::System, "x: %08x %08x %08x %08x", x[0], x[1], x[2], x[3]);137INFO_LOG(Log::System, "y: %08x %08x %08x %08x", y[0], y[1], y[2], y[3]);138INFO_LOG(Log::System, "z: %08x %08x %08x %08x", z[0], z[1], z[2], z[3]);139INFO_LOG(Log::System, "c: %f %f %f %f", c[0], c[1], c[2], c[3]);140for (int i = 0; i < 6; i++) {141INFO_LOG(Log::System, "--------------------------");142}143// DisassembleArm(codeStart, gen.GetCodePtr()-codeStart);144}145146147