bebbo / libnix

libnix (v4): a C link library for AmigaOS/m68k
14 stars 9 forks source link

Exe with floats compiled for kickstart 1.3 is using an inexistant library #36

Closed Samuel-DEVULDER closed 3 years ago

Samuel-DEVULDER commented 3 years ago

Hello.

When I compile this piece of code

#include <math.h>

int main(int ac, char **argv) {
    float f = 1, g=2;
    float h = f*g;
}

with m68k-amigaos-gcc -O0 -mcrt=nix13 tst_float_ks13.c -o tst_float_ks13, I get an exe which, when launched under kickstart 1.3 complains about mathieeesingbas.library failed to load

The issue is that mathieeesingbas.library does not exist for kickstart 1.3. It only exists since amigaos V36 (eg around kick 2.04).

A possible work around would be that in the supporting math lib functions internally opens mathieeetransbas.library which exists in kickstart 1.3, then call: DOUBLE IEEEDPFieee( FLOAT single ) to convert IEEE single-precision number to IEEE double-precision number. Then perform the basic arithmetic operations on doubles, and convert back the result to float using FLOAT IEEEDPTieee( DOUBLE parm ). Of course this would use much more cycles than needed with an proper mathieeesingbas.library, but that one does not exist. On the balance, this solution preserves the IEEE compatibility of memory representation of floats.

Another possibility is to drop IEEE compatibility and use motorola's ffp format provided by mathffp.library present in amigaos 1.3 rom IIRC, so neither extra libraries on disk nor extra memory are required while keeping a pretty good execution speed.

Of course the best approach would probably be to let the programmer choose between these two options via a dedicated -mffp or -mieee switch.

bebbo commented 3 years ago

If a library is missing, copy it to your system. mathieeesingbas.zip

Samuel-DEVULDER commented 3 years ago

Where does it comes from ? I don't have it in my KS1.3 disks. C:VERSION displays a suspicous 1.0 version from 2015 whereas KS1.3 math libraries are 34.x from 1988:

CLI> version file mathieeesingbas.library  full
mathieeesingbas.library 1.0 (19/07/15)
CLI> version file mathieedoubbas.library full
mathieeedoubbas.library 34.46
(28 May 1988)
bebbo commented 3 years ago

does it work or does it work?

Samuel-DEVULDER commented 3 years ago

does it work or does it work?

It works indeed !!! (no real choice here :P )

I tested under kickstack 1.3.3 (UAE), and there is no more complaint when running the test-program. Sans titre

(merry xmas by the way)