Subject: Software Floating Point for MPC821/823/860
To: None <tech-kern@netbsd.org>
From: David Querbach <querbach@realtime.bc.ca>
List: tech-kern
Date: 04/03/2000 17:45:12
I'm in the process of porting NetBSD to the MPC821/823/860 PowerPC
derivatives.  Since these chips have no floating-point hardware, I'm trying
to set up software emulation.

So far, I've managed to build a cross-compiler which will generate soft or
hard float code based on the presence or absence of a command-line switch
"-msoft-float".  I also caused two versions of gcclib.a to be built, one
assuming hardware floating point, and one assuming software floating point. 
The soft-float library also includes the floating-point emulator from
/usr/pkgsrc/cross/powerpc-netbsd/work/egcs-1.1.1/gcc/config/fpbit.c. 
Unfortunately, this emulator does not seem to support signals and rounding
mode control.

Upon further examination, I found another floating-point emulator in
/usr/src/lib/libc/arch/arm32/fplib and in usr/src/lib/libc/arch/mips/fplib.
This emulator _does_ seem to support signals and rounding modes.  The arm32
port appears to always use the emulator, whereas the mips port appears to
never use it.  Strangely, the sh3 port seems to refer to the emulator
without actually including it.

So which is the better emulator to use for NetBSD, fp-bit.c or fplib?  I'm
guessing that the fplib emulator would be better, but can anyone confirm
whether it works or not?

Once the emulator is chosen, I'd like to make soft/hard floating point
switchable at system build time.  The best way I can figure out is:

1.  Modify gcc/configure so that the powerpc-*-netbsd* choice includes:

    tmake_file="t-netbsd rs6000/t-netbsd"

    where rs6000/t-netbsd is a new file patterned after rs6000/t-rs6000. 
    The file rs6000/t-netbsd will modify the *cpp spec in the specs file to
    define SOFT_FLOAT whenever -msoft-float is given:

    #define CPP_SPEC ... %{msoft-float: -DSOFT_FLOAT} ...

    as well as ensuring that the appropriate multilibs get built.

2.  Copy src/lib/libc/arch/arm32/fplib to src/lib/libc/arch/powerpc and
    set it up appropriately.

3.  Use #ifdef SOFT_FLOAT to conditionalize several files in
    src/lib/libc/arch/powerpc/gen which now assume the existence of hardware
    floating point.

I'd really appreciate any comments this approach, in order to ensure that my
port will integrate cleanly with the rest of the system.

Regards,

David Querbach
Real-Time Systems Inc.