mirror of
https://github.com/cc65/cc65.git
synced 2025-02-26 23:30:03 +00:00
Added optimization for g_inc and g_dec (remove handling of high byte if
not used). git-svn-id: svn://svn.cc65.org/cc65/trunk@680 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
e07945e9fc
commit
8e5d8b9e4f
@ -3367,14 +3367,47 @@ void g_dec (unsigned flags, unsigned long val)
|
|||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
|
|
||||||
case CF_INT:
|
case CF_INT:
|
||||||
if (val <= 8) {
|
if (CodeSizeFactor < 200) {
|
||||||
AddCodeLine ("\tjsr\tdecax%d", (int) val);
|
/* Use subroutines */
|
||||||
} else if (val <= 255) {
|
if (val <= 8) {
|
||||||
ldyconst (val);
|
AddCodeLine ("\tjsr\tdecax%d", (int) val);
|
||||||
AddCodeLine ("\tjsr\tdecaxy");
|
} else if (val <= 255) {
|
||||||
|
ldyconst (val);
|
||||||
|
AddCodeLine ("\tjsr\tdecaxy");
|
||||||
|
} else {
|
||||||
|
g_sub (flags | CF_CONST, val);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
g_sub (flags | CF_CONST, val);
|
/* Inline the code */
|
||||||
}
|
if (val < 0x300) {
|
||||||
|
if ((val & 0xFF) != 0) {
|
||||||
|
AddCodeLine ("\tsec");
|
||||||
|
AddCodeLine ("\tsbc\t#$%02X", (unsigned char) val);
|
||||||
|
AddCodeLine ("\tbcs\t*+3");
|
||||||
|
AddCodeLine ("\tdex");
|
||||||
|
/* Tell the optimizer that the X register may be invalid */
|
||||||
|
AddCodeHint ("x:!");
|
||||||
|
}
|
||||||
|
if (val >= 0x100) {
|
||||||
|
AddCodeLine ("\tdex");
|
||||||
|
}
|
||||||
|
if (val >= 0x200) {
|
||||||
|
AddCodeLine ("\tdex");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
AddCodeLine ("\tsec");
|
||||||
|
if ((val & 0xFF) != 0) {
|
||||||
|
AddCodeLine ("\tsbc\t#$%02X", (unsigned char) val);
|
||||||
|
/* Tell the optimizer that the X register may be invalid */
|
||||||
|
AddCodeHint ("x:!");
|
||||||
|
}
|
||||||
|
AddCodeLine ("\tpha");
|
||||||
|
AddCodeLine ("\ttxa");
|
||||||
|
AddCodeLine ("\tsbc\t#$%02X", (unsigned char) (val >> 8));
|
||||||
|
AddCodeLine ("\ttax");
|
||||||
|
AddCodeLine ("\tpla");
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CF_LONG:
|
case CF_LONG:
|
||||||
|
@ -1737,10 +1737,10 @@ static void OptLoads (void)
|
|||||||
* and replace it by:
|
* and replace it by:
|
||||||
*
|
*
|
||||||
* lda xx
|
* lda xx
|
||||||
* ldy #$01
|
* ldy #$01
|
||||||
* sta (sp),y
|
* sta (sp),y
|
||||||
* dey
|
* dey
|
||||||
* lda yy
|
* lda yy
|
||||||
* sta (sp),y
|
* sta (sp),y
|
||||||
*
|
*
|
||||||
* provided that that the X register is not used later. This code
|
* provided that that the X register is not used later. This code
|
||||||
@ -1762,7 +1762,48 @@ static void OptLoads (void)
|
|||||||
|
|
||||||
/* Remove the remaining line */
|
/* Remove the remaining line */
|
||||||
FreeLine (L2[1]);
|
FreeLine (L2[1]);
|
||||||
}
|
|
||||||
|
/* Search for
|
||||||
|
*
|
||||||
|
* adc #xx
|
||||||
|
* bcc *+3
|
||||||
|
* inx
|
||||||
|
*
|
||||||
|
* Remove the handling of the high byte if the X register
|
||||||
|
* is not used any more
|
||||||
|
*/
|
||||||
|
} else if (LineMatch (L, "\tadc\t#") &&
|
||||||
|
GetNextCodeLines (L, L2, 3) &&
|
||||||
|
LineFullMatch (L2[0], "\tbcc\t*+3") &&
|
||||||
|
LineFullMatch (L2[1], "\tinx") &&
|
||||||
|
L2[1]->Next &&
|
||||||
|
IsHint (L2[1]->Next, "x:!") &&
|
||||||
|
!RegXUsed (L2[1])) {
|
||||||
|
|
||||||
|
/* Delete the lines */
|
||||||
|
FreeLines (L2[0], L2[1]->Next);
|
||||||
|
|
||||||
|
/* Search for
|
||||||
|
*
|
||||||
|
* sbc #xx
|
||||||
|
* bcs *+3
|
||||||
|
* dex
|
||||||
|
*
|
||||||
|
* Remove the handling of the high byte if the X register
|
||||||
|
* is not used any more
|
||||||
|
*/
|
||||||
|
} else if (LineMatch (L, "\tsbc\t#") &&
|
||||||
|
GetNextCodeLines (L, L2, 3) &&
|
||||||
|
LineFullMatch (L2[0], "\tbcs\t*+3") &&
|
||||||
|
LineFullMatch (L2[1], "\tdex") &&
|
||||||
|
L2[1]->Next &&
|
||||||
|
IsHint (L2[1]->Next, "x:!") &&
|
||||||
|
!RegXUsed (L2[1])) {
|
||||||
|
|
||||||
|
/* Delete the lines */
|
||||||
|
FreeLines (L2[0], L2[1]->Next);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* All other patterns start with this one: */
|
/* All other patterns start with this one: */
|
||||||
if (!LineFullMatch (L, "\tldx\t#$00")) {
|
if (!LineFullMatch (L, "\tldx\t#$00")) {
|
||||||
@ -1772,12 +1813,12 @@ static void OptLoads (void)
|
|||||||
|
|
||||||
/* Search for:
|
/* Search for:
|
||||||
*
|
*
|
||||||
* ldx #$00
|
* ldx #$00
|
||||||
* jsr pushax
|
* jsr pushax
|
||||||
*
|
*
|
||||||
* and replace it by:
|
* and replace it by:
|
||||||
*
|
*
|
||||||
* jsr pusha0
|
* jsr pusha0
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
if (GetNextCodeLines (L, L2, 1) &&
|
if (GetNextCodeLines (L, L2, 1) &&
|
||||||
@ -1792,13 +1833,13 @@ static void OptLoads (void)
|
|||||||
|
|
||||||
/* Search for:
|
/* Search for:
|
||||||
*
|
*
|
||||||
* ldx #$00
|
* ldx #$00
|
||||||
* lda ...
|
* lda ...
|
||||||
* jsr pushax
|
* jsr pushax
|
||||||
*
|
*
|
||||||
* and replace it by:
|
* and replace it by:
|
||||||
*
|
*
|
||||||
* lda ...
|
* lda ...
|
||||||
* jsr pusha0
|
* jsr pusha0
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@ -1812,7 +1853,7 @@ static void OptLoads (void)
|
|||||||
/* Replace the subroutine call */
|
/* Replace the subroutine call */
|
||||||
L2 [1] = ReplaceLine (L2 [1], "\tjsr\tpusha0");
|
L2 [1] = ReplaceLine (L2 [1], "\tjsr\tpusha0");
|
||||||
|
|
||||||
/* Remove the unnecessary load */
|
/* Remove the unnecessary load */
|
||||||
FreeLine (L);
|
FreeLine (L);
|
||||||
|
|
||||||
/* L must be valid */
|
/* L must be valid */
|
||||||
@ -1898,20 +1939,20 @@ static void OptRegLoads (void)
|
|||||||
|
|
||||||
/* Search for a load of X and check if the value is used later */
|
/* Search for a load of X and check if the value is used later */
|
||||||
if (LineMatch (L, "\tldx\t") &&
|
if (LineMatch (L, "\tldx\t") &&
|
||||||
!RegXUsed (L) &&
|
!RegXUsed (L) &&
|
||||||
!IsCondJump (NextInstruction (L))) {
|
!IsCondJump (NextInstruction (L))) {
|
||||||
|
|
||||||
/* Remember to delete this line */
|
/* Remember to delete this line */
|
||||||
Delete = 1;
|
Delete = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search for a load of A and check if the value is used later */
|
/* Search for a load of A and check if the value is used later */
|
||||||
else if (LineMatch (L, "\tlda\t") &&
|
else if (LineMatch (L, "\tlda\t") &&
|
||||||
!RegAUsed (L) &&
|
!RegAUsed (L) &&
|
||||||
!IsCondJump (NextInstruction (L))) {
|
!IsCondJump (NextInstruction (L))) {
|
||||||
|
|
||||||
/* Remember to delete this line */
|
/* Remember to delete this line */
|
||||||
Delete = 1;
|
Delete = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search for a load of Y and check if the value is used later */
|
/* Search for a load of Y and check if the value is used later */
|
||||||
@ -1919,8 +1960,8 @@ static void OptRegLoads (void)
|
|||||||
!RegYUsed (L) &&
|
!RegYUsed (L) &&
|
||||||
!IsCondJump (NextInstruction (L))) {
|
!IsCondJump (NextInstruction (L))) {
|
||||||
|
|
||||||
/* Remember to delete this line */
|
/* Remember to delete this line */
|
||||||
Delete = 1;
|
Delete = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Go to the next line, delete the current if requested */
|
/* Go to the next line, delete the current if requested */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user