mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-12-02 10:43:44 +01:00
riscv: Add a simple unit test.
Since I haven't tried running these yet, at least best to validate...
This commit is contained in:
1 parent
08d82ec15b
commit
216fcb228c
6 files changed
+78
No files matched your search
@@ -2348,6 +2348,7 @@ if(UNITTEST)
|
||||
unittest/TestIRPassSimplify.cpp
|
||||
unittest/TestX64Emitter.cpp
|
||||
unittest/TestVertexJit.cpp
|
||||
unittest/TestRiscVEmitter.cpp
|
||||
unittest/TestSoftwareGPUJit.cpp
|
||||
unittest/TestThreadManager.cpp
|
||||
unittest/JitHarness.cpp
|
||||
|
||||
@@ -721,11 +721,13 @@ ifeq ($(UNITTEST),1)
|
||||
TESTARMEMITTER_FILE = \
|
||||
$(SRC)/Common/ArmEmitter.cpp \
|
||||
$(SRC)/Common/Arm64Emitter.cpp \
|
||||
$(SRC)/Common/RiscVEmitter.cpp \
|
||||
$(SRC)/Core/MIPS/ARM/ArmRegCacheFPU.cpp \
|
||||
$(SRC)/Core/Util/DisArm64.cpp \
|
||||
$(SRC)/ext/disarm.cpp \
|
||||
$(SRC)/unittest/TestArmEmitter.cpp \
|
||||
$(SRC)/unittest/TestArm64Emitter.cpp \
|
||||
$(SRC)/unittest/TestRiscVEmitter.cpp \
|
||||
$(SRC)/unittest/TestX64Emitter.cpp
|
||||
endif
|
||||
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
// Copyright (c) 2022- PPSSPP Project.
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 2.0 or later versions.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License 2.0 for more details.
|
||||
|
||||
// A copy of the GPL 2.0 should have been included with the program.
|
||||
// If not, see http://www.gnu.org/licenses/
|
||||
|
||||
// Official git repository and contact information can be found at
|
||||
// https://github.com/hrydgard/ppsspp and http://www.ppsspp.org/.
|
||||
|
||||
#include <cstdio>
|
||||
#include "Common/CPUDetect.h"
|
||||
#include "Common/RiscVEmitter.h"
|
||||
#include "UnitTest.h"
|
||||
|
||||
bool TestRiscVEmitter() {
|
||||
using namespace RiscVGen;
|
||||
|
||||
// TODO: Set cpu_info flags.
|
||||
|
||||
u32 code[1024];
|
||||
RiscVEmitter emitter((u8 *)code, (u8 *)code);
|
||||
|
||||
emitter.SetAutoCompress(false);
|
||||
emitter.LUI(X1, 0xFFFFF000);
|
||||
emitter.AUIPC(X2, 0x70051000);
|
||||
emitter.JAL(X3, code);
|
||||
emitter.JALR(X1, X2, -12);
|
||||
FixupBranch b1 = emitter.JAL(X4);
|
||||
emitter.SetJumpTarget(b1);
|
||||
emitter.BEQ(X5, X6, code);
|
||||
emitter.LB(X7, X8, 42);
|
||||
emitter.SB(X9, X10, 1337);
|
||||
emitter.ADDI(X11, X12, 42);
|
||||
emitter.SLLI(X13, X14, 3);
|
||||
emitter.ADD(X15, X16, X17);
|
||||
emitter.FENCE(Fence::RW, Fence::RW);
|
||||
|
||||
static constexpr uint32_t expected[] = {
|
||||
0xfffff0b7,
|
||||
0x70051117,
|
||||
0xff9ff1ef,
|
||||
0xff4100e7,
|
||||
0x0040026f,
|
||||
0xfe6286e3,
|
||||
0x02a40383,
|
||||
0x52950ca3,
|
||||
0x02a60593,
|
||||
0x00371693,
|
||||
0x011807b3,
|
||||
0x0330000f,
|
||||
};
|
||||
|
||||
ptrdiff_t len = (u32 *)emitter.GetWritableCodePtr() - code;
|
||||
EXPECT_EQ_INT(len, ARRAY_SIZE(expected));
|
||||
|
||||
for (ptrdiff_t i = 0; i < len; ++i) {
|
||||
EXPECT_EQ_HEX(code[i], expected[i]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -754,6 +754,7 @@ struct TestItem {
|
||||
bool TestArmEmitter();
|
||||
bool TestArm64Emitter();
|
||||
bool TestX64Emitter();
|
||||
bool TestRiscVEmitter();
|
||||
bool TestShaderGenerators();
|
||||
bool TestSoftwareGPUJit();
|
||||
bool TestIRPassSimplify();
|
||||
@@ -768,6 +769,9 @@ TestItem availableTests[] = {
|
||||
#endif
|
||||
#if PPSSPP_ARCH(AMD64) || PPSSPP_ARCH(X86)
|
||||
TEST_ITEM(X64Emitter),
|
||||
#endif
|
||||
#if PPSSPP_ARCH(AMD64) || PPSSPP_ARCH(X86) || PPSSPP_ARCH(RISCV64)
|
||||
TEST_ITEM(RiscVEmitter),
|
||||
#endif
|
||||
TEST_ITEM(VertexJit),
|
||||
TEST_ITEM(Asin),
|
||||
|
||||
@@ -383,6 +383,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="TestIRPassSimplify.cpp" />
|
||||
<ClCompile Include="TestRiscVEmitter.cpp" />
|
||||
<ClCompile Include="TestShaderGenerators.cpp" />
|
||||
<ClCompile Include="TestSoftwareGPUJit.cpp" />
|
||||
<ClCompile Include="TestThreadManager.cpp" />
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<ClCompile Include="TestThreadManager.cpp" />
|
||||
<ClCompile Include="TestSoftwareGPUJit.cpp" />
|
||||
<ClCompile Include="TestIRPassSimplify.cpp" />
|
||||
<ClCompile Include="TestRiscVEmitter.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="JitHarness.h" />
|
||||
|
||||
Reference in new issue
Block a user