1
0
mirror of https://github.com/cc65/cc65.git synced 2025-01-11 11:30:13 +00:00

Better code for > compares

git-svn-id: svn://svn.cc65.org/cc65/trunk@823 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz 2001-07-26 06:10:10 +00:00
parent d604ed5e3f
commit 58592116ac

View File

@ -3642,25 +3642,39 @@ void g_gt (unsigned flags, unsigned long val)
*/
if (flags & CF_CONST) {
/* > is not very effective on the 6502, so try to convert
* it into >= if the value is in a valid range.
*/
/* Look at the type */
switch (flags & CF_TYPE) {
case CF_CHAR:
if (flags & CF_FORCECHAR) {
AddCodeLine ("cmp #$%02X", (unsigned char)val);
if (flags & CF_UNSIGNED) {
/* If we have a compare > 0, we will replace it by
* != 0 here, since both are identical but the latter
* is easier to optimize.
*/
if (val & 0xFF) {
AddCodeLine ("jsr boolugt");
} else {
if (val == 0) {
AddCodeLine ("cmp #$%02X", (unsigned char)val);
AddCodeLine ("jsr boolne");
} else if (val < 255) {
AddCodeLine ("cmp #$%02X", (unsigned char)val+1);
AddCodeLine ("jsr booluge");
} else {
AddCodeLine ("cmp #$%02X", (unsigned char)val);
AddCodeLine ("jsr boolugt");
}
} else {
if (val < 127) {
AddCodeLine ("cmp #$%02X", (unsigned char)val+1);
AddCodeLine ("jsr boolge");
} else {
AddCodeLine ("cmp #$%02X", (unsigned char)val);
AddCodeLine ("jsr boolgt");
}
}
return;
}
/* FALLTHROUGH */
@ -3671,17 +3685,22 @@ void g_gt (unsigned flags, unsigned long val)
* != 0 here, since both are identical but the latter
* is easier to optimize.
*/
if ((val & 0xFFFF) == 0) {
if (val == 0) {
AddCodeLine ("stx tmp1");
AddCodeLine ("ora tmp1");
AddCodeLine ("jsr boolne");
} else {
unsigned L = GetLocalLabel();
const char* Name = "boolugt";
if (val < 65535) {
++val;
Name = "booluge";
}
AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8));
AddCodeLine ("bne %s", LocalLabelName (L));
AddCodeLine ("cmp #$%02X", (unsigned char)val);
g_defcodelabel (L);
AddCodeLine ("jsr boolugt");
AddCodeLine ("jsr %s", Name);
}
return;
}