1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-30 20:29:25 +00:00

Inline some forms of aslax1

git-svn-id: svn://svn.cc65.org/cc65/trunk@4018 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
uz 2009-08-15 15:27:43 +00:00
parent f495a9edc3
commit 3381311674

View File

@ -90,15 +90,28 @@ enum {
static unsigned OptShift1 (CodeSeg* S)
/* A call to the shlaxN routine may get replaced by one or more asl insns
* if the value of X is not used later.
* if the value of X is not used later. If X is used later, but it is zero
* on entry and it's a shift by one, it may get replaced by:
*
* asl a
* bcc L1
* inx
* L1:
*
*/
{
unsigned Changes = 0;
/* Generate register info */
CS_GenRegInfo (S);
/* Walk over the entries */
unsigned I = 0;
while (I < CS_GetEntryCount (S)) {
CodeEntry* X;
CodeLabel* L;
/* Get next entry */
CodeEntry* E = CS_GetEntry (S, I);
@ -107,21 +120,45 @@ static unsigned OptShift1 (CodeSeg* S)
(strncmp (E->Arg, "shlax", 5) == 0 ||
strncmp (E->Arg, "aslax", 5) == 0) &&
strlen (E->Arg) == 6 &&
IsDigit (E->Arg[5]) &&
!RegXUsed (S, I+1)) {
IsDigit (E->Arg[5])) {
/* Insert shift insns */
unsigned Count = E->Arg[5] - '0';
while (Count--) {
CodeEntry* X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, E->LI);
CS_InsertEntry (S, X, I+1);
}
if (!RegXUsed (S, I+1)) {
/* Delete the call to shlax */
CS_DelEntry (S, I);
/* Insert shift insns */
unsigned Count = E->Arg[5] - '0';
while (Count--) {
X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, E->LI);
CS_InsertEntry (S, X, I+1);
}
/* Remember, we had changes */
++Changes;
/* Delete the call to shlax */
CS_DelEntry (S, I);
/* Remember, we had changes */
++Changes;
} else if (E->RI->In.RegX == 0 &&
E->Arg[5] == '1') {
/* asl a */
X = NewCodeEntry (OP65_ASL, AM65_ACC, "a", 0, E->LI);
CS_InsertEntry (S, X, I);
/* bcc L1 */
L = CS_GenLabel (S, E);
X = NewCodeEntry (OP65_BCC, AM65_BRA, L->Name, L, E->LI);
CS_InsertEntry (S, X, I+1);
/* inx */
X = NewCodeEntry (OP65_INX, AM65_IMP, 0, 0, E->LI);
CS_InsertEntry (S, X, I+2);
/* Delete the call to shlax */
CS_DelEntry (S, I+3);
/* Remember, we had changes */
++Changes;
}
}
@ -130,6 +167,9 @@ static unsigned OptShift1 (CodeSeg* S)
}
/* Free the register info */
CS_FreeRegInfo (S);
/* Return the number of changes made */
return Changes;
}