Re: [cc65] float and double support - libraries?

Date view Thread view Subject view

From: Ullrich von Bassewitz (uz_at_musoftware.de)
Date: 2003-03-08 00:19:37


On Fri, Mar 07, 2003 at 05:10:44PM +0100, Piotr Fusik wrote:
> I started writing IEEE-compliant 32-bit floats 6502 routines (integer
> conversion, comparision). Sign and 7 bits of exponent in A, lsb of
> exponent in X, mantissa in X, sreg and sreg+1.
>
> The problem is what routines are needed?

For a start: add, sub, mul, div, compares.

Calling conventions should be similar to the existing long routines, that is
lhs is on stack and rhs is passed in the primary register. The return value is
passed back in the primary register. With these calling conventions, the
functions are also C callable, which is nice in a first stage when there is no
compiler support:

        double __fastcall__ sub (double lhs, double rhs);

> char->float conversion is smaller and faster than long->float, but this
> way we will get many routines: signed char -> float, unsigned char -> float,
> int -> float, unsigned -> float, long -> float and unsigned long -> float
> (and as many float -> ... routines).

Since the overhead of a conversion from 8 or 16 bit to a 32 bit data type is
neglectible compared to the actual floating point operations, I would say that
conversions from long -> float and unsigned long -> float are the only ones
that are required.

> The comparision is a bit tricky - there are signed 0s, infinites and NaNs.
> Optimizing single comparision operator routines isn't probably the good
> way - there should be some common code for comparision. Note that some
> optimizations are not legal for IEEE floats (e.g. !(a>=b) is not
> neccessarily (a<b)).

I've already started to add support for signals, so in the near future, you
can raise SIGFPE. Implementing core dumps is left as an excercise for
interested users:-)

Adding lots of optimizations for floats is probably not worth the trouble
(floats are similar to longs in this respect): While the feature should be
available, the 6502 is definitely the wrong platform for number crunching.

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-03-08 00:20:09 CET