Re: [cc65] Signed comparisions

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2003-10-27 16:21:46


Hi!

On Mon, Oct 27, 2003 at 03:02:45PM +0100, Piotr Fusik wrote:
> 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.

Ok.

> 2. Signed comparisions can be made unsigned. :-)
[...]
> 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.

The problem is that the high byte is in X, so it's not only the EOR that is
needed but the value has to moved into A for doing so. And, since A contains
the low byte, it has to be saved somewhere. Which gives a total of five
additional instructions - too much to inline it and probably not worth the
trouble.

There are some more possibilities to improve the code: unsigned compares can
have their own subroutine, which would be faster because it doesn't have to
mess with the V flag.

Regards


        Uz


-- 
Ullrich von Bassewitz                                  uz_at_musoftware.de
----------------------------------------------------------------------
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 16:22:04 CET