mirror of
https://github.com/cc65/cc65.git
synced 2025-01-01 03:30:20 +00:00
Optimizations
git-svn-id: svn://svn.cc65.org/cc65/trunk@1009 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
8d6f5a2fca
commit
0c09cc7242
@ -2879,6 +2879,15 @@ void g_asr (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
case CF_INT:
|
||||
if (val >= 8 && (flags & CF_UNSIGNED)) {
|
||||
AddCodeLine ("txa");
|
||||
ldxconst (0);
|
||||
val -= 8;
|
||||
if (val == 0) {
|
||||
/* Done */
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (val >= 1 && val <= 4) {
|
||||
if (flags & CF_UNSIGNED) {
|
||||
AddCodeLine ("jsr shrax%ld", val);
|
||||
@ -2886,10 +2895,6 @@ void g_asr (unsigned flags, unsigned long val)
|
||||
AddCodeLine ("jsr asrax%ld", val);
|
||||
}
|
||||
return;
|
||||
} else if (val == 8 && (flags & CF_UNSIGNED)) {
|
||||
AddCodeLine ("txa");
|
||||
ldxconst (0);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -2962,6 +2967,15 @@ void g_asl (unsigned flags, unsigned long val)
|
||||
|
||||
case CF_CHAR:
|
||||
case CF_INT:
|
||||
if (val >= 8) {
|
||||
AddCodeLine ("tax");
|
||||
AddCodeLine ("lda #$00");
|
||||
val -= 8;
|
||||
if (val == 0) {
|
||||
/* Done */
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (val >= 1 && val <= 4) {
|
||||
if (flags & CF_UNSIGNED) {
|
||||
AddCodeLine ("jsr shlax%ld", val);
|
||||
@ -2969,10 +2983,6 @@ void g_asl (unsigned flags, unsigned long val)
|
||||
AddCodeLine ("jsr aslax%ld", val);
|
||||
}
|
||||
return;
|
||||
} else if (val == 8) {
|
||||
AddCodeLine ("tax");
|
||||
AddCodeLine ("lda #$00");
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
|
@ -161,31 +161,54 @@ static unsigned Opt_tosaddax (CodeSeg* S, unsigned Push, unsigned Add,
|
||||
const char* ZPLo, const char* ZPHi)
|
||||
/* Optimize the tosaddax sequence if possible */
|
||||
{
|
||||
CodeEntry* P;
|
||||
CodeEntry* N;
|
||||
CodeEntry* X;
|
||||
CodeEntry* PushEntry;
|
||||
CodeEntry* AddEntry;
|
||||
int DirectAdd;
|
||||
|
||||
|
||||
/* We need the entry behind the add */
|
||||
CHECK ((N = CS_GetNextEntry (S, Add)) != 0);
|
||||
|
||||
/* And the entry before the push */
|
||||
CHECK ((P = CS_GetPrevEntry (S, Push)) != 0);
|
||||
|
||||
/* Get the push entry */
|
||||
PushEntry = CS_GetEntry (S, Push);
|
||||
|
||||
/* Check the entry before the push, if it's a lda instruction with an
|
||||
* addressing mode that does not use an additional index register. If
|
||||
* so, we may use this location for the add and must not save the
|
||||
* value in the zero page location.
|
||||
*/
|
||||
DirectAdd = (P->OPC == OP65_LDA &&
|
||||
(P->AM == AM65_IMM || P->AM == AM65_ZP || P->AM == AM65_ABS));
|
||||
|
||||
/* Store the value into the zeropage instead of pushing it */
|
||||
X = NewCodeEntry (OP65_STX, AM65_ZP, ZPHi, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+1);
|
||||
++Add; /* Correct the index */
|
||||
if (!DirectAdd) {
|
||||
X = NewCodeEntry (OP65_STA, AM65_ZP, ZPLo, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+1);
|
||||
X = NewCodeEntry (OP65_STX, AM65_ZP, ZPHi, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+2);
|
||||
++Add; /* Correct the index */
|
||||
}
|
||||
|
||||
/* Correct the index of the add and get a pointer to the entry */
|
||||
Add += 2;
|
||||
/* Get a pointer to the add entry */
|
||||
AddEntry = CS_GetEntry (S, Add);
|
||||
|
||||
/* Inline the add */
|
||||
X = NewCodeEntry (OP65_CLC, AM65_IMP, 0, 0, AddEntry->LI);
|
||||
CS_InsertEntry (S, X, Add+1);
|
||||
if (DirectAdd) {
|
||||
/* Add from variable location */
|
||||
X = NewCodeEntry (OP65_ADC, P->AM, P->Arg, 0, AddEntry->LI);
|
||||
} else {
|
||||
/* Add from temp storage */
|
||||
X = NewCodeEntry (OP65_ADC, AM65_ZP, ZPLo, 0, AddEntry->LI);
|
||||
}
|
||||
CS_InsertEntry (S, X, Add+2);
|
||||
if (PushEntry->RI->In.RegX == 0) {
|
||||
/* The high byte is the value in X plus the carry */
|
||||
@ -240,25 +263,47 @@ static unsigned Opt_tosandax (CodeSeg* S, unsigned Push, unsigned And,
|
||||
const char* ZPLo, const char* ZPHi)
|
||||
/* Optimize the tosandax sequence if possible */
|
||||
{
|
||||
CodeEntry* P;
|
||||
CodeEntry* X;
|
||||
CodeEntry* PushEntry;
|
||||
CodeEntry* AndEntry;
|
||||
int DirectAnd;
|
||||
|
||||
/* Get the entry before the push */
|
||||
CHECK ((P = CS_GetPrevEntry (S, Push)) != 0);
|
||||
|
||||
/* Get the push entry */
|
||||
PushEntry = CS_GetEntry (S, Push);
|
||||
|
||||
/* Check the entry before the push, if it's a lda instruction with an
|
||||
* addressing mode that does not use an additional index register. If
|
||||
* so, we may use this location for the and and must not save the
|
||||
* value in the zero page location.
|
||||
*/
|
||||
DirectAnd = (P->OPC == OP65_LDA &&
|
||||
(P->AM == AM65_IMM || P->AM == AM65_ZP || P->AM == AM65_ABS));
|
||||
|
||||
/* Store the value into the zeropage instead of pushing it */
|
||||
X = NewCodeEntry (OP65_STX, AM65_ZP, ZPHi, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+1);
|
||||
++And; /* Correct the index */
|
||||
if (!DirectAnd) {
|
||||
X = NewCodeEntry (OP65_STA, AM65_ZP, ZPLo, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+1);
|
||||
X = NewCodeEntry (OP65_STX, AM65_ZP, ZPHi, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+2);
|
||||
++And; /* Correct the index */
|
||||
}
|
||||
|
||||
/* Correct the index of the add and get a pointer to the entry */
|
||||
And += 2;
|
||||
/* Get a pointer to the and entry */
|
||||
AndEntry = CS_GetEntry (S, And);
|
||||
|
||||
/* Inline the and */
|
||||
if (DirectAnd) {
|
||||
/* And with variable location */
|
||||
X = NewCodeEntry (OP65_AND, P->AM, P->Arg, 0, AndEntry->LI);
|
||||
} else {
|
||||
/* And with temp storage */
|
||||
X = NewCodeEntry (OP65_AND, AM65_ZP, ZPLo, 0, AndEntry->LI);
|
||||
}
|
||||
CS_InsertEntry (S, X, And+1);
|
||||
if (PushEntry->RI->In.RegX == 0 || AndEntry->RI->In.RegX == 0) {
|
||||
/* The high byte is zero */
|
||||
@ -292,25 +337,46 @@ static unsigned Opt_tosorax (CodeSeg* S, unsigned Push, unsigned Or,
|
||||
const char* ZPLo, const char* ZPHi)
|
||||
/* Optimize the tosorax sequence if possible */
|
||||
{
|
||||
CodeEntry* P;
|
||||
CodeEntry* X;
|
||||
CodeEntry* PushEntry;
|
||||
CodeEntry* OrEntry;
|
||||
int DirectOr;
|
||||
|
||||
/* Get the entry before the push */
|
||||
CHECK ((P = CS_GetPrevEntry (S, Push)) != 0);
|
||||
|
||||
/* Get the push entry */
|
||||
PushEntry = CS_GetEntry (S, Push);
|
||||
|
||||
/* Check the entry before the push, if it's a lda instruction with an
|
||||
* addressing mode that does not use an additional index register. If
|
||||
* so, we may use this location for the or and must not save the
|
||||
* value in the zero page location.
|
||||
*/
|
||||
DirectOr = (P->OPC == OP65_LDA &&
|
||||
(P->AM == AM65_IMM || P->AM == AM65_ZP || P->AM == AM65_ABS));
|
||||
|
||||
/* Store the value into the zeropage instead of pushing it */
|
||||
X = NewCodeEntry (OP65_STX, AM65_ZP, ZPHi, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+1);
|
||||
++Or; /* Correct the index */
|
||||
if (DirectOr) {
|
||||
X = NewCodeEntry (OP65_STA, AM65_ZP, ZPLo, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+1);
|
||||
X = NewCodeEntry (OP65_STX, AM65_ZP, ZPHi, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+2);
|
||||
++Or; /* Correct the index */
|
||||
}
|
||||
|
||||
/* Correct the index of the add and get a pointer to the entry */
|
||||
Or += 2;
|
||||
/* Get a pointer to the or entry */
|
||||
OrEntry = CS_GetEntry (S, Or);
|
||||
|
||||
/* Inline the or */
|
||||
if (DirectOr) {
|
||||
/* Or with variable location */
|
||||
X = NewCodeEntry (OP65_ORA, P->AM, P->Arg, 0, OrEntry->LI);
|
||||
} else {
|
||||
X = NewCodeEntry (OP65_ORA, AM65_ZP, ZPLo, 0, OrEntry->LI);
|
||||
}
|
||||
CS_InsertEntry (S, X, Or+1);
|
||||
if (PushEntry->RI->In.RegX >= 0 && OrEntry->RI->In.RegX >= 0) {
|
||||
/* Both values known, precalculate the result */
|
||||
@ -345,27 +411,49 @@ static unsigned Opt_tosorax (CodeSeg* S, unsigned Push, unsigned Or,
|
||||
|
||||
static unsigned Opt_tosxorax (CodeSeg* S, unsigned Push, unsigned Xor,
|
||||
const char* ZPLo, const char* ZPHi)
|
||||
/* Optimize the tosorax sequence if possible */
|
||||
/* Optimize the tosxorax sequence if possible */
|
||||
{
|
||||
CodeEntry* P;
|
||||
CodeEntry* X;
|
||||
CodeEntry* PushEntry;
|
||||
CodeEntry* XorEntry;
|
||||
int DirectXor;
|
||||
|
||||
/* Get the entry before the push */
|
||||
CHECK ((P = CS_GetPrevEntry (S, Push)) != 0);
|
||||
|
||||
/* Get the push entry */
|
||||
PushEntry = CS_GetEntry (S, Push);
|
||||
|
||||
/* Check the entry before the push, if it's a lda instruction with an
|
||||
* addressing mode that does not use an additional index register. If
|
||||
* so, we may use this location for the xor and must not save the
|
||||
* value in the zero page location.
|
||||
*/
|
||||
DirectXor = (P->OPC == OP65_LDA &&
|
||||
(P->AM == AM65_IMM || P->AM == AM65_ZP || P->AM == AM65_ABS));
|
||||
|
||||
/* Store the value into the zeropage instead of pushing it */
|
||||
X = NewCodeEntry (OP65_STX, AM65_ZP, ZPHi, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+1);
|
||||
++Xor; /* Correct the index */
|
||||
if (DirectXor) {
|
||||
X = NewCodeEntry (OP65_STA, AM65_ZP, ZPLo, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+1);
|
||||
X = NewCodeEntry (OP65_STX, AM65_ZP, ZPHi, 0, PushEntry->LI);
|
||||
CS_InsertEntry (S, X, Push+2);
|
||||
++Xor; /* Correct the index */
|
||||
}
|
||||
|
||||
/* Correct the index of the add and get a pointer to the entry */
|
||||
Xor += 2;
|
||||
/* Get a pointer to the entry */
|
||||
XorEntry = CS_GetEntry (S, Xor);
|
||||
|
||||
/* Inline the or */
|
||||
/* Inline the xor */
|
||||
if (DirectXor) {
|
||||
/* Xor with variable location */
|
||||
X = NewCodeEntry (OP65_EOR, P->AM, P->Arg, 0, XorEntry->LI);
|
||||
} else {
|
||||
/* Xor with temp storage */
|
||||
X = NewCodeEntry (OP65_EOR, AM65_ZP, ZPLo, 0, XorEntry->LI);
|
||||
}
|
||||
CS_InsertEntry (S, X, Xor+1);
|
||||
if (PushEntry->RI->In.RegX >= 0 && XorEntry->RI->In.RegX >= 0) {
|
||||
/* Both values known, precalculate the result */
|
||||
|
Loading…
Reference in New Issue
Block a user