2

For the heck of it, I decided to see if a program I started writing on an Amiga many years ago and much further developed on other machines would still compile and run on an Amiga (after being developed on other machines). I originally used Lattice C because that's what I used before. But the 68881 support in Lattice is VERY buggy. So I decided to try gcc. I think the most recent version of gcc for Amiga is 2.7.0 (so I can't upgrade). It's worked rather well except for one bug in 68881 support: When multiplying any negative number by zero, the result is always:

1.:00000

when printed out (colon is NOT a typo). BTW, if you set x to zero, then print out, it's 0.00000 like it should be.

Here's a sample program to test the bug, it doesn't matter which variable is 0 and which is negative, and if the non-zero value is positive, it works fine.

#include <stdio.h>
#include <math.h>

main()
{
    float x,a,b;

    a=-10.0;
    b=0.0;
    x=a*b;
    printf("%f\n",x);
}

and it's compiled with: gcc -o tt -m68020 -m68881 tt.c -lm

Taking out -m68881 works fine (but of course, doesn't use the FPU) Taking out -lm and/or math.h makes no difference.

Does anyone know of a bug fix or workaround? Maybe a gcc command line argument? (would rather not have to do UGLY things like "if ((a<0)&&(b==0))")

BTW, since I don't have a working Amiga anymore, I've had to use an emulator. If you want to see what I've been doing on this project (using Lattice C version), you can view my video at:

https://www.youtube.com/watch?v=x8O-qYQvP4M

(Amiga part starts at 10:07)

Thanks for any help.

dvhh
  • 4,724
  • 27
  • 33
lasermc
  • 55
  • 7
  • 1
    what is your emulator ? that might help for having some insight into your issue – dvhh Dec 18 '19 at 01:56
  • 2
    What does it print for `printf("%f\n", -0.);`? What for `%g` or `%e`? – Eric Postpischil Dec 18 '19 at 03:02
  • 1
    gcc 2.7.0 is too old. I don't think any bug fixing will happen on it – phuclv Dec 18 '19 at 03:17
  • 1
    I can't see a reply button, so I hope the users commenting know I responded....%f with -0. gives 1.:00000 and %g with -0. gives 1.: and %e with 0. gives 1.:00000+00. And the emulator is WinUAE. – lasermc Dec 18 '19 at 05:40
  • @phuclv I know 2.7.0 is too old. I tried the code on a linux machine (x86 not 68000) and predictably it worked fine, so either it's specific to 68000/68881 or it was fixed a long time ago (just not in 2.7.0). I was just hoping there was some command line argument that would bypass problem (or even a printf format option). – lasermc Dec 18 '19 at 05:49
  • 1
    @dvhh WinUAE is the emulator (in case you didn't see it in my other comment) – lasermc Dec 18 '19 at 05:51
  • 2
    I've done a very quick search, and it looks like someone maintains a fork of GCC 6.5 for amiga, at least (with associated cross toolchain). links: https://github.com/bebbo/amiga-gcc/ https://github.com/bebbo/gcc https://franke.ms/amiga/gcc.wiki . Someone also seems to maintain a fork of GCC 8.1, https://github.com/mooli/gcc-amiga/ and https://retrocomputing.stackexchange.com/q/605 (Disregard this if irrelevant, I think I missed that you might want to compile on Amiga) – Hasturkun Dec 18 '19 at 08:00
  • @Hasturkun Thanks for the links, I'll check them out when I get a chance. I did look at aminet.net further - there are newer gcc's but they run on i386/i686 (I guess for those Amiga-like linux's?), and some that are cross-compilers. – lasermc Dec 18 '19 at 08:23

1 Answers1

0

This isn't exactly an answer, but a revelation that the problem is rather complicated (more so than a simple bug with gcc). Here's the info:

If I set the Amiga emulator to emulate a 68020 or a 68030 and a 68881 or a 68882 INSTEAD of a 68040 using the 68040's internal FPU it doesn't produce the 1.:00000 (in other words, it works). So that could mean the emulator is to blame for not emulating the 68040's FPU correctly (though I imagine the 68040's FPU is likely compatible with the 68881/68882). (Don't know if there's a performance hit in setting the emulator to 68020/30 68881/2 (I have the emulator set to run as fast as possible on the host machine instead of going at the speed of the 680xx)).

However, if I compile with the Amiga's gcc's -noixemul option, the code works correctly in every combination of CPU and FPU. So that would indicate it's a problem with the Amiga's version of gcc (really the part of the gcc system that tries to emulate UNIX on an Amiga (that is what ixemul.library does)). So that might not be gcc's fault (if it were compiled on some other system that uses a 68040 it would probably work), but the fault of the people who ported gcc to Amiga.

So, you might say "problem solved, just use -noixemul" - well not so fast... Although the simple test program doesn't crash, my bigger program that exposed this problem crashes on program exit (recoverable GURU meditation) only when compiled with -noixemul (perhaps it's trying to close a library that was never opened, I don't know). This is why I didn't use -noixemul even though I wanted to.

So, it's not exactly solved, but I would say it's not likely a non-Amiga gcc bug.

lasermc
  • 55
  • 7