Small but significant shift optimization
git-svn-id: svn://svn.cc65.org/cc65/trunk@1559 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -138,13 +138,18 @@ static unsigned OptShift1 (CodeSeg* S)
|
|||||||
|
|
||||||
static unsigned OptShift2 (CodeSeg* S)
|
static unsigned OptShift2 (CodeSeg* S)
|
||||||
/* A call to the shraxN routine may get replaced by one or more lsr insns
|
/* A call to the shraxN routine may get replaced by one or more lsr insns
|
||||||
* if the value of X is not used later.
|
* if the value of X is not used later, or if the value of X is known and
|
||||||
|
* zero.
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
unsigned Changes = 0;
|
unsigned Changes = 0;
|
||||||
|
unsigned I;
|
||||||
|
|
||||||
|
/* Generate register info */
|
||||||
|
CS_GenRegInfo (S);
|
||||||
|
|
||||||
/* Walk over the entries */
|
/* Walk over the entries */
|
||||||
unsigned I = 0;
|
I = 0;
|
||||||
while (I < CS_GetEntryCount (S)) {
|
while (I < CS_GetEntryCount (S)) {
|
||||||
|
|
||||||
/* Get next entry */
|
/* Get next entry */
|
||||||
@@ -155,13 +160,13 @@ static unsigned OptShift2 (CodeSeg* S)
|
|||||||
strncmp (E->Arg, "shrax", 5) == 0 &&
|
strncmp (E->Arg, "shrax", 5) == 0 &&
|
||||||
strlen (E->Arg) == 6 &&
|
strlen (E->Arg) == 6 &&
|
||||||
IsDigit (E->Arg[5]) &&
|
IsDigit (E->Arg[5]) &&
|
||||||
!RegXUsed (S, I+1)) {
|
(E->RI->In.RegX == 0 || !RegXUsed (S, I+1))) {
|
||||||
|
|
||||||
/* Insert shift insns */
|
/* Insert shift insns */
|
||||||
unsigned Count = E->Arg[5] - '0';
|
unsigned Count = E->Arg[5] - '0';
|
||||||
while (Count--) {
|
while (Count--) {
|
||||||
CodeEntry* X = NewCodeEntry (OP65_LSR, AM65_ACC, "a", 0, E->LI);
|
CodeEntry* X = NewCodeEntry (OP65_LSR, AM65_ACC, "a", 0, E->LI);
|
||||||
CS_InsertEntry (S, X, I+1);
|
CS_InsertEntry (S, X, I+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Delete the call to shlax */
|
/* Delete the call to shlax */
|
||||||
@@ -177,6 +182,9 @@ static unsigned OptShift2 (CodeSeg* S)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Free the register info */
|
||||||
|
CS_FreeRegInfo (S);
|
||||||
|
|
||||||
/* Return the number of changes made */
|
/* Return the number of changes made */
|
||||||
return Changes;
|
return Changes;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user