Optimize substraction of 1
This commit is contained in:
@@ -2000,6 +2000,35 @@ void g_subeqstatic (unsigned flags, uintptr_t label, long offs,
|
|||||||
|
|
||||||
case CF_INT:
|
case CF_INT:
|
||||||
if (flags & CF_CONST) {
|
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 ("lda %s", lbuf);
|
||||||
AddCodeLine ("sec");
|
AddCodeLine ("sec");
|
||||||
AddCodeLine ("sbc #$%02X", (unsigned char)val);
|
AddCodeLine ("sbc #$%02X", (unsigned char)val);
|
||||||
@@ -2021,6 +2050,7 @@ void g_subeqstatic (unsigned flags, uintptr_t label, long offs,
|
|||||||
AddCodeLine ("lda %s", lbuf);
|
AddCodeLine ("lda %s", lbuf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
AddCodeLine ("eor #$FF");
|
AddCodeLine ("eor #$FF");
|
||||||
AddCodeLine ("sec");
|
AddCodeLine ("sec");
|
||||||
@@ -3693,7 +3723,13 @@ void g_dec (unsigned flags, unsigned long val)
|
|||||||
} else {
|
} else {
|
||||||
/* Inline the code */
|
/* Inline the code */
|
||||||
if (val < 0x300) {
|
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();
|
unsigned L = GetLocalLabel();
|
||||||
AddCodeLine ("sec");
|
AddCodeLine ("sec");
|
||||||
AddCodeLine ("sbc #$%02X", (unsigned char) val);
|
AddCodeLine ("sbc #$%02X", (unsigned char) val);
|
||||||
|
|||||||
Reference in New Issue
Block a user