Recompiler: BC0T/BC0TL are never taken and BC0FL/BC0TL run their delay slot unconditionally
Maintainers usually reply within 5 days
@ahmedgamalalzatary is already working on this.
Since Oct 23, 2026.
- #390 by @ahmedgamalalzatary — open
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 72/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- cpp
- Domain
- compilers, reverse-engineering
Research direction
Read ps2xRecomp/src/lib/control_flow_emitter.cpp, especially ControlFlowEmitter::conditionalBranchExpression() and isLikelyBranch(), then inspect the COP0 handling in cop0_translator.cpp. Add or locate the code-generator test covering BC0F, BC0T, BC0FL, and BC0TL with a non-NOP delay slot. The change is complete when COP0 branch conditions use the intended CPCOND0 behavior and likely branches nullify delay slots when not taken.
Written by the indexing model from the issue text.
Description
What happens
The EE branch-on-COP0-condition instructions (BC0F, BC0T, BC0FL, BC0TL) branch on CPCOND0, which the DMAC drives. The recompiler has no COP0 case for them:
- The condition is always
false.ControlFlowEmitter::conditionalBranchExpression()(ps2xRecomp/src/lib/control_flow_emitter.cpp) handlesOPCODE_COP1andOPCODE_COP2branch conditions, but notOPCODE_COP0, so it returns"false"for every BC0 form.BC0FandBC0Tare therefore both never taken, although one of them must be taken for any value of CPCOND0. - The likely forms aren't recognized as likely.
ControlFlowEmitter::isLikelyBranch()lists COP1 and COP2BCxFL/BCxTL, but notCOP0_BC_BCFL/COP0_BC_BCTL. Their delay slot is emitted unconditionally, but a not-taken likely branch must nullify it.
cop0_translator.cpp says // BC0 ... - Handled by branch logic, but the branch logic doesn't handle it.
Effect
BC0F never taken matches "DMA already complete", which suits the runtime's eager DMA, so 1: bc0f 1b wait loops exit right away. But BC0T/BC0TL then go the wrong way, and BC0FL/BC0TL execute a delay-slot instruction the hardware would skip.
Hardware reference
CPCOND0 is true when every DMA channel selected in D_PCR.CPC has its D_STAT.CIS bit set. PCSX2 computes it as ((D_STAT.CIS | ~D_PCR.CPC) & 0x3FF) == 0x3FF, and BC0F branches when it's false.
Suggested fix
- Treat CPCOND0 as true:
BC0F/BC0FLnever taken (current behavior),BC0T/BC0TLalways taken. That matches the eager DMA model and can't turn abc0fwait loop into a hang. - Add
COP0_BC_BCFL/COP0_BC_BCTLtoisLikelyBranch().
A more exact alternative is to compute CPCOND0 from D_STAT/D_PCR at run time. But some DMA paths in the runtime can stall (VIF1/PATH3), so a bc0f wait loop could spin forever if a CIS bit isn't set when expected. The constant is the safer first step.
Repro
A code-generator test with a BC0x branch + non-NOP delay slot + target shows const bool branch_taken_... = (false); for all four forms, and the delay slot emitted before the taken check for BC0FL/BC0TL.
Found while reviewing COP0 coverage for #163. Tested on main e563698.
- Dominant language
- C++
- Stars
- 3.3k
- Forks
- 149
- Avg merge
- 8h 46m
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from ran-j/PS2Recomp
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
ran-j/PS2Recomp#393 · 1 comment ·
Maintainers usually reply within 5 days
-
EE sceCdStatus stub always reports READ (6), hanging games that wait for PAUSEPossibly taken @ahmedgamalalzatary claimed this 13 days ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 5 days
-
VU0 macro VSQI / VSQD: address and source registers swapped in generated codePossibly taken @yanm1103 claimed this 20 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 5 days
-
Runtime: SampleTexture casts unbounded or NaN texture coordinates to int, which is undefined behaviourMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
ran-j/PS2Recomp#273 · 2 comments ·
Maintainers usually reply within 5 days
-
Build: /Qspectre- is MSVC-only and breaks every Release target under clang-clPossibly taken @ahmedgamalalzatary claimed this 13 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 5 days
Similar issues
-
Linux npm packaging leaves workspace files that block subsequent CI checkoutPossibly taken @Spockkk0225 claimed this today. Openci
Difficulty 2/5 1-3 hours Newbie friendliness 73/100
alibaba/neug#1195 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 3 days
-
QA/No release-notes/exclude tests tests/missing-coverage tests/test-quality
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
brave/brave-browser#61019 ·
Maintainers usually reply within 1 day
-
? - Needs Triage bug CUTLASS C++
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 4 days