Skip to content

Commit

Permalink
Add VU test case for Shinobi.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpd002 committed May 11, 2023
1 parent 2f73765 commit 468de01
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tools/VuTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ endif()
add_executable(VuTest
AddTest.cpp
BranchTest.cpp
FdivEfuMixTest.cpp
FlagsTest.cpp
FlagsTest2.cpp
FlagsTest3.cpp
Expand All @@ -39,6 +40,7 @@ add_executable(VuTest

AddTest.h
BranchTest.h
FdivEfuMixTest.h
FlagsTest.h
FlagsTest2.h
FlagsTest3.h
Expand Down
75 changes: 75 additions & 0 deletions tools/VuTest/FdivEfuMixTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "FdivEfuMixTest.h"
#include "VuAssembler.h"

void CFdivEfuMixTest::Execute(CTestVm& virtualMachine)
{
//Inspired by Shinobi
//Starts an EFU operation and then a FDIV operation
//Uses WAITP a bit later and then reads the Q register right after
//Since WAITP waits for a huge number of cycles, the FDIV
//operation should be complete by the time WAITP finishes.

virtualMachine.Reset();

{
auto microMem = reinterpret_cast<uint32*>(virtualMachine.m_microMem);
CVuAssembler assembler(microMem);

auto branch1Label = assembler.CreateLabel();
auto branch2Label = assembler.CreateLabel();

assembler.Write(
CVuAssembler::Upper::NOP(),
CVuAssembler::Lower::ERLENG(CVuAssembler::VF27));

assembler.Write(
CVuAssembler::Upper::NOP(),
CVuAssembler::Lower::DIV(CVuAssembler::VF15, CVuAssembler::FVF_X, CVuAssembler::VF27, CVuAssembler::FVF_Z));

assembler.Write(
CVuAssembler::Upper::NOP(),
CVuAssembler::Lower::IBNE(CVuAssembler::VI0, CVuAssembler::VI1, branch1Label));

assembler.Write(
CVuAssembler::Upper::NOP(),
CVuAssembler::Lower::NOP());

assembler.Write(
CVuAssembler::Upper::NOP(),
CVuAssembler::Lower::IBEQ(CVuAssembler::VI0, CVuAssembler::VI0, branch2Label));

assembler.Write(
CVuAssembler::Upper::NOP(),
CVuAssembler::Lower::WAITP());

assembler.MarkLabel(branch1Label);

assembler.Write(
CVuAssembler::Upper::NOP(),
CVuAssembler::Lower::NOP());

assembler.MarkLabel(branch2Label);

//Read Q value into VF1
assembler.Write(
CVuAssembler::Upper::MULq(CVuAssembler::DEST_W, CVuAssembler::VF1, CVuAssembler::VF0),
CVuAssembler::Lower::NOP());

assembler.Write(
CVuAssembler::Upper::NOP() | CVuAssembler::Upper::E_BIT,
CVuAssembler::Lower::NOP());

assembler.Write(
CVuAssembler::Upper::NOP(),
CVuAssembler::Lower::NOP());
}

virtualMachine.m_cpu.m_State.nCOP2[15] = {Float::_1, Float::_1, Float::_1, Float::_1};
virtualMachine.m_cpu.m_State.nCOP2[27] = {Float::_0, Float::_0, Float::_2, Float::_1};

virtualMachine.ExecuteTest(0);

TEST_VERIFY(virtualMachine.m_cpu.m_State.nCOP2P == Float::_1Half);
TEST_VERIFY(virtualMachine.m_cpu.m_State.nCOP2Q == Float::_1Half);
TEST_VERIFY(virtualMachine.m_cpu.m_State.nCOP2[1].nV3 == Float::_1Half);
}
9 changes: 9 additions & 0 deletions tools/VuTest/FdivEfuMixTest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

#include "Test.h"

class CFdivEfuMixTest : public CTest
{
public:
void Execute(CTestVm&) override;
};
2 changes: 2 additions & 0 deletions tools/VuTest/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "FpUtils.h"
#include "AddTest.h"
#include "BranchTest.h"
#include "FdivEfuMixTest.h"
#include "FlagsTest.h"
#include "FlagsTest2.h"
#include "FlagsTest3.h"
Expand All @@ -27,6 +28,7 @@ static const TestFactoryFunction s_factories[] =
{
[]() { return new CAddTest(); },
[]() { return new CBranchTest(); },
[]() { return new CFdivEfuMixTest(); },
[]() { return new CFlagsTest(); },
[]() { return new CFlagsTest2(); },
[]() { return new CFlagsTest3(); },
Expand Down
12 changes: 12 additions & 0 deletions tools/VuTest/VuAssembler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,13 @@ uint32 CVuAssembler::Lower::DIV(VF_REGISTER fs, FVF fsf, VF_REGISTER ft, FVF ftf
return result;
}

uint32 CVuAssembler::Lower::ERLENG(VF_REGISTER fs)
{
uint32 result = 0x81C0073F;
result |= (fs << 11);
return result;
}

uint32 CVuAssembler::Lower::FCAND(uint32 imm)
{
uint32 result = 0x24000000;
Expand Down Expand Up @@ -409,6 +416,11 @@ uint32 CVuAssembler::Lower::SQ(DEST dest, VF_REGISTER fs, uint16 imm, VI_REGISTE
return result;
}

uint32 CVuAssembler::Lower::WAITP()
{
return 0x800007BF;
}

uint32 CVuAssembler::Lower::WAITQ()
{
return 0x800003BF;
Expand Down
2 changes: 2 additions & 0 deletions tools/VuTest/VuAssembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ class CVuAssembler
public:
static BRANCHOP B(LABEL);
static uint32 DIV(VF_REGISTER, FVF, VF_REGISTER, FVF);
static uint32 ERLENG(VF_REGISTER);
static uint32 FCAND(uint32);
static uint32 FCGET(VI_REGISTER);
static uint32 FMAND(VI_REGISTER, VI_REGISTER);
Expand All @@ -172,6 +173,7 @@ class CVuAssembler
static uint32 MTIR(VI_REGISTER, VF_REGISTER, FVF);
static uint32 NOP();
static uint32 SQ(DEST, VF_REGISTER, uint16, VI_REGISTER);
static uint32 WAITP();
static uint32 WAITQ();
};

Expand Down

0 comments on commit 468de01

Please sign in to comment.