1
0
mirror of https://github.com/cc65/cc65.git synced 2025-08-07 15:25:31 +00:00

Optimize substraction of 1

This commit is contained in:
Colin Leroy-Mira
2023-11-12 22:15:03 +01:00
parent d7d1d89698
commit 9242508abf

View File

@@ -2000,6 +2000,35 @@ void g_subeqstatic (unsigned flags, uintptr_t label, long offs,
case CF_INT:
if (flags & CF_CONST) {
if (val == 1) {
unsigned L = GetLocalLabel();
if ((flags & CF_NOKEEP) == 0) {
if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0) {
AddCodeLine ("lda %s", lbuf);
AddCodeLine ("bne %s", LocalLabelName (L));
AddCodeLine ("dec %s+1", lbuf);
g_defcodelabel (L);
AddCodeLine ("dea");
AddCodeLine ("sta %s", lbuf);
AddCodeLine ("ldx %s+1", lbuf);
} else {
AddCodeLine ("ldx %s", lbuf);
AddCodeLine ("bne %s", LocalLabelName (L));
AddCodeLine ("dec %s+1", lbuf);
g_defcodelabel (L);
AddCodeLine ("dex");
AddCodeLine ("stx %s", lbuf);
AddCodeLine ("txa");
AddCodeLine ("ldx %s+1", lbuf);
}
} else {
AddCodeLine ("lda %s", lbuf);
AddCodeLine ("bne %s", LocalLabelName (L));
AddCodeLine ("dec %s+1", lbuf);
g_defcodelabel (L);
AddCodeLine ("dec %s", lbuf);
}
} else {
AddCodeLine ("lda %s", lbuf);
AddCodeLine ("sec");
AddCodeLine ("sbc #$%02X", (unsigned char)val);
@@ -2021,6 +2050,7 @@ void g_subeqstatic (unsigned flags, uintptr_t label, long offs,
AddCodeLine ("lda %s", lbuf);
}
}
}
} else {
AddCodeLine ("eor #$FF");
AddCodeLine ("sec");
@@ -3693,7 +3723,13 @@ void g_dec (unsigned flags, unsigned long val)
} else {
/* Inline the code */
if (val < 0x300) {
if ((val & 0xFF) != 0) {
if ((CPUIsets[CPU] & CPU_ISET_65SC02) != 0 && val == 1) {
unsigned L = GetLocalLabel();
AddCodeLine ("bne %s", LocalLabelName (L));
AddCodeLine ("dex");
g_defcodelabel (L);
AddCodeLine ("dea");
} else if ((val & 0xFF) != 0) {
unsigned L = GetLocalLabel();
AddCodeLine ("sec");
AddCodeLine ("sbc #$%02X", (unsigned char) val);