mirror of
https://github.com/cc65/cc65.git
synced 2024-12-28 06:30:16 +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,6 +3367,8 @@ void g_dec (unsigned flags, unsigned long val)
|
||||
/* FALLTHROUGH */
|
||||
|
||||
case CF_INT:
|
||||
if (CodeSizeFactor < 200) {
|
||||
/* Use subroutines */
|
||||
if (val <= 8) {
|
||||
AddCodeLine ("\tjsr\tdecax%d", (int) val);
|
||||
} else if (val <= 255) {
|
||||
@ -3375,6 +3377,37 @@ void g_dec (unsigned flags, unsigned long val)
|
||||
} else {
|
||||
g_sub (flags | CF_CONST, val);
|
||||
}
|
||||
} else {
|
||||
/* 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;
|
||||
|
||||
case CF_LONG:
|
||||
|
@ -1762,8 +1762,49 @@ static void OptLoads (void)
|
||||
|
||||
/* Remove the remaining line */
|
||||
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: */
|
||||
if (!LineFullMatch (L, "\tldx\t#$00")) {
|
||||
/* Next line */
|
||||
|
Loading…
Reference in New Issue
Block a user