Closed erique closed 1 year ago
guess: the wrong libs are linked
afaict we link with the correct/expected libgcc.a
$ m68k-amigaos-gcc -O0 -m68060 -mhard-float casttest.c -o casttest -Wl,--verbose | grep libgcc
attempt to open /opt/amiga/lib/libm060/libm020/libm881/libgcc.a failed
attempt to open /opt/amiga/lib/libm060/libm020/libgcc.a failed
attempt to open /opt/amiga/lib/libm060/libgcc.a failed
attempt to open /opt/amiga/lib/libgcc.a failed
attempt to open /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm060/libm060/libm020/libm881/libgcc.a failed
attempt to open /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm060/libm060/libm020/libgcc.a failed
attempt to open /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm060/libm060/libgcc.a failed
attempt to open /opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm060/libgcc.a succeeded
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm060/libgcc.a
(/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm060/libgcc.a)_floatundidf.o
(/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm060/libgcc.a)_udivdi3.o
(/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm060/libgcc.a)_umoddi3.o
(/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm060/libgcc.a)_clz.o
/opt/amiga/lib/gcc/m68k-amigaos/6.5.0b/libm060/libgcc.a
You could argue that it would (probably) work if linked against the regular (non libm060) version, but that would imho also be somewhat incorrect (that lib would have no FPU instructions at all).
Imho we link with the correct lib; it's just the generated call site is not matching libm060/libgcc.a generated code.
Perhaps stating the obvious / just to be clear: this code
jsr ___floatundidf
addq.l #8,sp
move.l d1,-(sp)
move.l d0,-(sp)
fdmove.d (sp)+,fp0
is not from any lib; afaict it's generated "on the fly" by optabs-libfuncs.c (see https://franke.ms/cex/z/h1r4os )
thanks - now I see: http://franke.ms/cex/z/r1jG4c
should be live in 1 hour
Still - assuming -mretfp0
whenever -m68060
is enabled causes a cascade of issues.
Here is one example : https://gist.github.com/erique/d6ff19dbfc7c810fd89e6070186768bb
The implementation of ceil()
in libnix calls mathieeedoubbas/IEEEDPCeil()
, which returns the result in d0/d1.
But libnix assumes the result is in fp0.
ups - need to test the proprer archive...
It's not enough to rebuild gcc, you need to rebuild all libs too.
I simply did
rm -rf projects/gcc
make all
and assumed libgcc et al would rebuild ; maybe that was a bold assumption :D It did look like it rebuilt most things tho.. 🤔
uh - dont' kill the projects, takes even more time, since you redownload all the the stuff.
since ceil.o
is in libnix and gcc was changed you only need:
make clean-gcc clean-libnix
make libnix -j30
building libnix implies building gcc. And 30 is maybe too large - use a number that fits your cpu
my build just finished:
stefan@ZETRA:~/amiga-gcc/tickets/gcc188$ /opt/amiga20220916/bin/m68k-amigaos-gcc -noixemul -m68060 -lm ceil_error.c -o ceil_error
stefan@ZETRA:~/amiga-gcc/tickets/gcc188$ vamos -C40 ceil_error
GCC 6.5.0b 220915211933
clamped = 00000004 ; PASS
yep, for some reason libnix wasn't rebuilt; possibly missed dependency between gcc and libnix. anyway - all good now.
fixed by e377bf7
Commit 2b293d1 ("always use fp0 for float/double if 68881 or better is present") changes the ABI from "softfp" (soft-float calling convention, with hardware floating-point instructions) to strict "hard" (FPU-specific calling conventions), as soon as 68881+ is enabled. Effectively this means that
-mretfp0
is always enabled whenever-m68881
(or-m68040/060
) is.When casting from a 64bit unsigned integer to float/double, the implicit call to
___floatundidf
assumes soft/softfp calling convention (i.e. result passed in d0/d1), butlibgcc
built with the above change will return the value in fp0.Test program : https://gist.github.com/erique/f5aa608f6e4a6d987a4e1d423f9b890f (CEX: https://franke.ms/cex/z/h1r4os ) Generated call (regardless of applying this change):
___floatundidf
before the change (or rather, by reverting it):___floatundidf
after the change:Suggest either reverting 2b293d1, or make libfuncs generation take the ABI change (
-mretfp0
/-m68881
) into account.