diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index 0a5eacc14..83cd948cc 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -601,6 +601,7 @@ static OptFunc DOptCmp6 = { OptCmp6, "OptCmp6", 100, 0, static OptFunc DOptCmp7 = { OptCmp7, "OptCmp7", 85, 0, 0, 0, 0, 0 }; static OptFunc DOptCmp8 = { OptCmp8, "OptCmp8", 50, 0, 0, 0, 0, 0 }; static OptFunc DOptCmp9 = { OptCmp9, "OptCmp9", 85, 0, 0, 0, 0, 0 }; +static OptFunc DOptComplAX1 = { OptComplAX1, "OptComplAX1", 65, 0, 0, 0, 0, 0 }; static OptFunc DOptCondBranches1= { OptCondBranches1,"OptCondBranches1", 80, 0, 0, 0, 0, 0 }; static OptFunc DOptCondBranches2= { OptCondBranches2,"OptCondBranches2", 0, 0, 0, 0, 0, 0 }; static OptFunc DOptDeadCode = { OptDeadCode, "OptDeadCode", 100, 0, 0, 0, 0, 0 }; @@ -698,6 +699,7 @@ static OptFunc* OptFuncs[] = { &DOptCmp7, &DOptCmp8, &DOptCmp9, + &DOptComplAX1, &DOptCondBranches1, &DOptCondBranches2, &DOptDeadCode, @@ -1088,6 +1090,7 @@ static unsigned RunOptGroup3 (CodeSeg* S) C += RunOptFunc (S, &DOptStackOps, 3); C += RunOptFunc (S, &DOptShift1, 1); C += RunOptFunc (S, &DOptShift4, 1); + C += RunOptFunc (S, &DOptComplAX1, 1); C += RunOptFunc (S, &DOptSub1, 1); C += RunOptFunc (S, &DOptSub2, 1); C += RunOptFunc (S, &DOptSub3, 1); diff --git a/src/cc65/coptneg.c b/src/cc65/coptneg.c index a25556a01..083815e9a 100644 --- a/src/cc65/coptneg.c +++ b/src/cc65/coptneg.c @@ -557,3 +557,54 @@ unsigned OptNegAX2 (CodeSeg* S) +/*****************************************************************************/ +/* complax optimizations */ +/*****************************************************************************/ + + + +unsigned OptComplAX1 (CodeSeg* S) +/* Search for a call to complax and replace it by + * + * eor #$FF + * + * if X isn't used later. + */ +{ + unsigned Changes = 0; + unsigned I; + + /* Walk over the entries */ + I = 0; + while (I < CS_GetEntryCount (S)) { + + /* Get next entry */ + CodeEntry* E = CS_GetEntry (S, I); + + /* Check if this is a call to negax, and if X isn't used later */ + if (CE_IsCallTo (E, "complax") && !RegXUsed (S, I+1)) { + + CodeEntry* X; + + /* Add replacement code behind */ + X = NewCodeEntry (OP65_EOR, AM65_IMM, "$FF", 0, E->LI); + CS_InsertEntry (S, X, I+1); + + /* Delete the call to negax */ + CS_DelEntry (S, I); + + /* We had changes */ + ++Changes; + } + + /* Next entry */ + ++I; + + } + + /* Return the number of changes made */ + return Changes; +} + + + diff --git a/src/cc65/coptneg.h b/src/cc65/coptneg.h index 82bd2f39d..f5c36f79f 100644 --- a/src/cc65/coptneg.h +++ b/src/cc65/coptneg.h @@ -164,6 +164,22 @@ unsigned OptNegAX2 (CodeSeg* S); +/*****************************************************************************/ +/* complax optimizations */ +/*****************************************************************************/ + + + +unsigned OptComplAX1 (CodeSeg* S); +/* Search for a call to complax and replace it by + * + * eor #$FF + * + * if X isn't used later. + */ + + + /* End of coptneg.h */ #endif