From c66185259b339a4041c6b01a20ce02bd364bea50 Mon Sep 17 00:00:00 2001 From: uz Date: Mon, 11 Jun 2012 17:58:32 +0000 Subject: [PATCH] Extend OPtShift3 to shift counts larger than 1. git-svn-id: svn://svn.cc65.org/cc65/trunk@5713 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/cc65/codeopt.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index 51dbfcec2..18444a265 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -261,7 +261,11 @@ static unsigned OptShift3 (CodeSeg* S) * * ror a * - * if X is zero on entry and unused later. + * if X is zero on entry and unused later. For shift counts > 1, more + * + * shr a + * + * must be added. */ { unsigned Changes = 0; @@ -287,12 +291,21 @@ static unsigned OptShift3 (CodeSeg* S) L[1]->OPC == OP65_INX && L[0]->JumpTo->Owner == L[2] && !CS_RangeHasLabel (S, I, 2) && - CE_IsCallTo (L[2], "shrax1") && + L[2]->OPC == OP65_JSR && + strlen (L[2]->Arg) == 6 && + memcmp (L[2]->Arg, "shrax", 5) == 0 && + IsDigit (L[2]->Arg[5]) && !RegXUsed (S, I+3)) { + unsigned ShiftCount = (L[2]->Arg[5] - '0'); + /* Add the replacement insn instead */ CodeEntry* X = NewCodeEntry (OP65_ROR, AM65_ACC, "a", 0, L[2]->LI); CS_InsertEntry (S, X, I+3); + while (--ShiftCount) { + X = NewCodeEntry (OP65_LSR, AM65_ACC, "a", 0, L[2]->LI); + CS_InsertEntry (S, X, I+4); + } /* Remove the bcs/dex/jsr */ CS_DelEntries (S, I, 3); -- 2.39.5