From 5813fd81d383f3e0520a41197ffa44b92b272cb9 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Sun, 8 May 2022 13:20:18 +0200 Subject: [PATCH] add extra optimizer step that replaces BRA by JMP if the target is external --- src/cc65/coptjmp.c | 31 +++++++++++++++++++++++++++++++ src/cc65/coptjmp.h | 3 +++ 2 files changed, 34 insertions(+) diff --git a/src/cc65/coptjmp.c b/src/cc65/coptjmp.c index dd092a5ad..9dd4a29c5 100644 --- a/src/cc65/coptjmp.c +++ b/src/cc65/coptjmp.c @@ -194,6 +194,37 @@ unsigned OptBranchDist (CodeSeg* S) +unsigned OptBranchDist2 (CodeSeg* S) +/* Change BRA to JMP if target is an external symbol */ +{ + unsigned Changes = 0; + + /* Walk over the entries */ + unsigned I = 0; + while (I < CS_GetEntryCount (S)) { + + /* Get next entry */ + CodeEntry* E = CS_GetEntry (S, I); + + if ((CPUIsets[CPU] & (CPU_ISET_65SC02 |CPU_ISET_6502DTV)) != 0 && /* CPU has BRA */ + (E->Info & OF_UBRA) != 0 && /* is a unconditional branch */ + E->JumpTo == NULL) { /* target is extern */ + /* BRA jumps to external symbol and must be replaced by a JMP on the 65C02 CPU */ + CE_ReplaceOPC (E, OP65_JMP); + ++Changes; + } + + /* Next entry */ + ++I; + + } + + /* Return the number of changes made */ + return Changes; +} + + + /*****************************************************************************/ /* Replace jumps to RTS by RTS */ /*****************************************************************************/ diff --git a/src/cc65/coptjmp.h b/src/cc65/coptjmp.h index 4cb7a2792..8df53415d 100644 --- a/src/cc65/coptjmp.h +++ b/src/cc65/coptjmp.h @@ -52,6 +52,9 @@ unsigned OptBranchDist (CodeSeg* S); /* Change branches for the distance needed. */ +unsigned OptBranchDist2 (CodeSeg* S); +/* If BRA points to an external symbol, change it to JMP */ + unsigned OptRTSJumps1 (CodeSeg* S); /* Replace jumps to RTS by RTS */