mirror of
https://github.com/cc65/cc65.git
synced 2025-01-01 03:30:20 +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:
parent
d604ed5e3f
commit
58592116ac
@ -3642,25 +3642,39 @@ void g_gt (unsigned flags, unsigned long val)
|
|||||||
*/
|
*/
|
||||||
if (flags & CF_CONST) {
|
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 */
|
/* Look at the type */
|
||||||
switch (flags & CF_TYPE) {
|
switch (flags & CF_TYPE) {
|
||||||
|
|
||||||
case CF_CHAR:
|
case CF_CHAR:
|
||||||
if (flags & CF_FORCECHAR) {
|
if (flags & CF_FORCECHAR) {
|
||||||
AddCodeLine ("cmp #$%02X", (unsigned char)val);
|
|
||||||
if (flags & CF_UNSIGNED) {
|
if (flags & CF_UNSIGNED) {
|
||||||
/* If we have a compare > 0, we will replace it by
|
/* If we have a compare > 0, we will replace it by
|
||||||
* != 0 here, since both are identical but the latter
|
* != 0 here, since both are identical but the latter
|
||||||
* is easier to optimize.
|
* is easier to optimize.
|
||||||
*/
|
*/
|
||||||
if (val & 0xFF) {
|
if (val == 0) {
|
||||||
AddCodeLine ("jsr boolugt");
|
AddCodeLine ("cmp #$%02X", (unsigned char)val);
|
||||||
} else {
|
|
||||||
AddCodeLine ("jsr boolne");
|
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 {
|
} else {
|
||||||
|
if (val < 127) {
|
||||||
|
AddCodeLine ("cmp #$%02X", (unsigned char)val+1);
|
||||||
|
AddCodeLine ("jsr boolge");
|
||||||
|
} else {
|
||||||
|
AddCodeLine ("cmp #$%02X", (unsigned char)val);
|
||||||
AddCodeLine ("jsr boolgt");
|
AddCodeLine ("jsr boolgt");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* FALLTHROUGH */
|
/* FALLTHROUGH */
|
||||||
@ -3671,17 +3685,22 @@ void g_gt (unsigned flags, unsigned long val)
|
|||||||
* != 0 here, since both are identical but the latter
|
* != 0 here, since both are identical but the latter
|
||||||
* is easier to optimize.
|
* is easier to optimize.
|
||||||
*/
|
*/
|
||||||
if ((val & 0xFFFF) == 0) {
|
if (val == 0) {
|
||||||
AddCodeLine ("stx tmp1");
|
AddCodeLine ("stx tmp1");
|
||||||
AddCodeLine ("ora tmp1");
|
AddCodeLine ("ora tmp1");
|
||||||
AddCodeLine ("jsr boolne");
|
AddCodeLine ("jsr boolne");
|
||||||
} else {
|
} else {
|
||||||
unsigned L = GetLocalLabel();
|
unsigned L = GetLocalLabel();
|
||||||
|
const char* Name = "boolugt";
|
||||||
|
if (val < 65535) {
|
||||||
|
++val;
|
||||||
|
Name = "booluge";
|
||||||
|
}
|
||||||
AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8));
|
AddCodeLine ("cpx #$%02X", (unsigned char)(val >> 8));
|
||||||
AddCodeLine ("bne %s", LocalLabelName (L));
|
AddCodeLine ("bne %s", LocalLabelName (L));
|
||||||
AddCodeLine ("cmp #$%02X", (unsigned char)val);
|
AddCodeLine ("cmp #$%02X", (unsigned char)val);
|
||||||
g_defcodelabel (L);
|
g_defcodelabel (L);
|
||||||
AddCodeLine ("jsr boolugt");
|
AddCodeLine ("jsr %s", Name);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user