[cc65] Signed comparisions

Date view Thread view Subject view

From: Piotr Fusik (P.Fusik_at_elka.pw.edu.pl)
Date: 2003-10-27 15:02:45


Hi,

Sorry, I hadn't time before to look at Ullrich's fixes.
I think they are correct, but I'm a bit sad that the generated code
is now worse. Of course this is not our fault - comparisions
in 6502 should set the V flag and there should be blt/bge branches,
like in other CPUs (I wonder if it's so in Z80...).

Just some ideas how signed comparisions could be improved
in special cases:

1. Comparisions against 0 never overflow, so the old code was fine.
Since comparisions against 0 are quite common, it makes sense
to support this special case. The difference is especially visible
for longs.

2. Signed comparisions can be made unsigned. :-)
E.g.
int a, b, result;
// ...
result1 = a < b;
result2 = (unsigned) (a + 0x8000) < (unsigned) (b + 0x8000);
or (better for 6502):
result2 = (unsigned) (a ^ 0x8000) < (unsigned) (b ^ 0x8000);
In cases when we didn't use CPX this gives penalty of just one EOR #$80
comparing with the old incorrect code or unsigned comparisions.

Bye,
Piotr

----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo_at_musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.


Date view Thread view Subject view

This archive was generated by hypermail 2.1.3 : 2003-10-27 15:06:02 CET