Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 42 additions & 5 deletions src/core/disr3000a.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***************************************************************************

Check warning on line 1 in src/core/disr3000a.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

declare has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.

Check warning on line 1 in src/core/disr3000a.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Bumpy Road Ahead

declare has 2 blocks with nested conditional logic. Any nesting of 2 or deeper is considered. Threshold is one single, nested block per function. The Bumpy Road code smell is a function that contains multiple chunks of nested conditional logic. The deeper the nesting and the more bumps, the lower the code health.
* Copyright (C) 2023 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -57,6 +57,19 @@
"TagLo", "TagHi", "ErrorEPC", "*RES*", // 1c
};

const char *PCSX::Disasm::getSyscallName(uint32_t index) {
switch (index) {
case 0:
return "NOP";
case 1:
return "EnterCriticalSection";
case 2:
return "ExitCriticalSection";
default:
return "DeliverEvent";
}
}

#undef declare
#undef _Funct_
#undef _Rd_
Expand Down Expand Up @@ -226,6 +239,7 @@
}
}
}
virtual void SyscallName(const char *name) final { append(name); }
virtual void reset() final {
m_buf[0] = 0;
m_len = 0;
Expand Down Expand Up @@ -281,8 +295,9 @@
declare(disADDIU) {
if (_Rs_ == 0) {
// this is the common pseudo-instruction to load an immediate 16 bits value
dOpCode("li");
GPR(_Rt_);
if (disLI(_Rt_, _Im_, nextCode, skipNext, delaySlotNext)) {
return;
}
} else {
dOpCode("addiu");
GPR(_Rt_);
Expand All @@ -299,8 +314,9 @@
declare(disORI) {
if (_Rs_ == 0) {
// while rare, this can also be used to load an immediate 16-bits value
dOpCode("li");
GPR(_Rt_);
if (disLI(_Rt_, _Im_, nextCode, skipNext, delaySlotNext)) {
return;
}
} else {
dOpCode("ori");
GPR(_Rt_);
Expand Down Expand Up @@ -680,6 +696,27 @@
}
}

bool PCSX::Disasm::disLI(uint32_t reg, uint32_t imm, uint32_t nextCode, bool *skipNext, bool *delaySlotNext) {
// Merge syscalls, which usually have the pattern
// li $a0, syscallNumber
// syscall 0x0000
uint8_t nextIns = nextCode >> 26;
uint8_t nextSubfunc = nextCode & 0x3f;

if (skipNext && reg == 4 && nextIns == 0 && nextSubfunc == 0xC) {

Check warning on line 706 in src/core/disr3000a.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

❌ New issue: Complex Conditional

PCSX::Disasm::disLI has 1 complex conditionals with 3 branches, threshold = 2. A complex conditional is an expression inside a branch (e.g. if, for, while) which consists of multiple, logical operators such as AND/OR. The more logical operators in an expression, the more severe the code smell.
dOpCode("syscall");
SyscallName(getSyscallName(imm));

*skipNext = true;
return true;
} else {
dOpCode("li");
GPR(reg);

return false;
}
}

/*********************************************************
* Move from HI/LO to GPR *
* Format: OP rd *
Expand Down Expand Up @@ -969,7 +1006,7 @@
}

/*********************************************************
* Unknow instruction (would generate an exception) *
* Unknown instruction (would generate an exception) *
* Format: ? *
*********************************************************/
declare(disNULL) {
Expand Down
5 changes: 5 additions & 0 deletions src/core/disr3000a.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class Disasm {
static const char *s_disRNameCP2D[];
static const char *s_disRNameCP2C[];
static const char *s_disRNameCP0[];
static const char *getSyscallName(uint32_t index);

#define declare(n) \
void n(uint32_t code, uint32_t nextCode, uint32_t pc, bool *skipNext = nullptr, bool *delaySlotNext = nullptr)
Expand Down Expand Up @@ -72,6 +73,7 @@ class Disasm {
virtual void OfB(int16_t offset, uint8_t reg, int size) = 0;
virtual void BranchDest(uint32_t offset) = 0;
virtual void Offset(uint32_t offset, int size) = 0;
virtual void SyscallName(const char *) = 0;

private:
// Type definition of our functions
Expand Down Expand Up @@ -188,6 +190,9 @@ class Disasm {
declare(disGPL);
declare(disNCCT);
#undef declare

// li has a slightly different signature, being a pseudoinstruction
bool disLI(uint32_t reg, uint32_t imm, uint32_t nextCode, bool *skipNext = nullptr, bool *delaySlotNext = nullptr);
};

} // namespace PCSX
5 changes: 5 additions & 0 deletions src/gui/widgets/assembly.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/***************************************************************************

Check notice on line 1 in src/gui/widgets/assembly.cc

View check run for this annotation

CodeScene Delta Analysis / CodeScene Cloud Delta Analysis (main)

✅ Getting better: Overall Code Complexity

The mean cyclomatic complexity decreases from 8.00 to 7.77, threshold = 4. This file has many conditional statements (e.g. if, for, while) across its implementation, leading to lower code health. Avoid adding more conditionals.
* Copyright (C) 2019 PCSX-Redux authors *
* *
* This program is free software; you can redistribute it and/or modify *
Expand Down Expand Up @@ -104,6 +104,7 @@
virtual void OfB(int16_t offset, uint8_t reg, int size) final {}
virtual void BranchDest(uint32_t offset) final {}
virtual void Offset(uint32_t offset, int size) final {}
virtual void SyscallName(const char*) final {}
};

} // namespace
Expand Down Expand Up @@ -310,6 +311,10 @@
}
ImGui::PopStyleVar();
}
void PCSX::Widgets::Assembly::SyscallName(const char* name) {
sameLine();
ImGui::TextUnformatted(name);
}
void PCSX::Widgets::Assembly::Sa(uint8_t value) {
comma();
sameLine();
Expand Down
1 change: 1 addition & 0 deletions src/gui/widgets/assembly.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class Assembly : private Disasm {
virtual void OfB(int16_t offset, uint8_t reg, int size) final;
virtual void BranchDest(uint32_t value) final;
virtual void Offset(uint32_t addr, int size) final;
virtual void SyscallName(const char*) final;
bool m_gotArg = false;
bool m_notch = false;
bool m_notchAfterSkip[2] = {false, false};
Expand Down
Loading