Discussion:
m68k OCaml porting issue
(too old to reply)
Stéphane Glondu
2021-12-22 12:50:01 UTC
Permalink
Hello,

While debugging OCaml 4.13.1's testsuite on m68k, I've noticed that the
following:

-----8<-----
#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include <stdlib.h>

int main(int argc, char** argv) {
int i = atoi(argv[1]);
union { double d; int64_t i; } u[2];
u[0].i = 0x7FF0000000000001L;
u[1].d = -u[0].d;
printf("%Lx, %F\n", u[i].i, u[i].d);
}
-----8<-----

when compiled with "gcc -O0" and run with argument "1", returns:

fff0000000000000, -INF

which seems to be incorrect.

For reference, on amd64 (and seemingly on arm64, armhf, i386, ppc64el,
s390x as well), it returns:

fff0000000000001, -NAN

which seems to be the correct behaviour.


Does anybody here have an explanation?


Cheers,
--
Stéphane
Stéphane Glondu
2021-12-22 13:50:01 UTC
Permalink
Post by Stéphane Glondu
While debugging OCaml 4.13.1's testsuite on m68k, I've noticed that the
[...]
which seems to be incorrect.
[...]
Another simpler example, not involving unions:

-----8<-----
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(int argc, char** argv) {
double d[2];
d[0] = NAN;
d[1] = -d[0];
printf("%F\n", d[1]);
}
-----8<-----

returns "-INF" instead of "-NAN".


Cheers,
--
Stéphane
John Paul Adrian Glaubitz
2021-12-22 14:50:03 UTC
Permalink
Hi Stéphane!
Post by Stéphane Glondu
-----8<-----
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, char** argv) {
double d[2];
d[0] = NAN;
d[1] = -d[0];
printf("%F\n", d[1]);
}
-----8<-----
returns "-INF" instead of "-NAN".
It might be an emulation issue with QEMU which has some issues with FPU emulation.

I can test it on real hardware but not until after Christmas.

Adrian
--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer - ***@debian.org
`. `' Freie Universitaet Berlin - ***@physik.fu-berlin.de
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
John Klos
2021-12-22 19:00:02 UTC
Permalink
Post by Stéphane Glondu
-----8<-----
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, char** argv) {
double d[2];
d[0] = NAN;
d[1] = -d[0];
printf("%F\n", d[1]);
}
-----8<-----
Gives NAN on '030 & '882, '040, '060, with gcc 7.4.0 & gcc 10.3.0.

Does Linux support softfloat? That'd be one way to get proper math out of
qemu.

John
Brad Boyer
2021-12-24 21:40:02 UTC
Permalink
Post by John Klos
Post by Stéphane Glondu
-----8<-----
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(int argc, char** argv) {
double d[2];
d[0] = NAN;
d[1] = -d[0];
printf("%F\n", d[1]);
}
-----8<-----
Gives NAN on '030 & '882, '040, '060, with gcc 7.4.0 & gcc 10.3.0.
The m68k PRM would seem to indicate that the FPU in both the 6888x and
the 68040 doesn't do a signed NAN. It specifically lists the sign bit
as a don't care bit for NAN while zero and infinity are both listed
as being signed quantities.

It seems to me this is expected behavior on the real hardware.

Brad Boyer
***@allandria.com

John Paul Adrian Glaubitz
2021-12-23 09:00:02 UTC
Permalink
Hi Laurent!
-NAN
NAN
Built with Qemu and debian bookworm/sid, gcc (Debian 10.2.0-15) 10.2.0.
On Quadra 800 it's executed on a debian/etch (not enough memory, 40 MB, to execute sid installer).
So it seems your test works better on Qemu than on real hardware.
Qemu: fff0000000000001, -NAN
Q800: 7ff8000000000001, NAN
Qemu reuses fonctions common to all emulated archs, so we will have results closer to x86 than to real 68040.
I will update the QEMU version on the Debian Porterbox then. Has the latest QEMU version
integrated all the changes for the m68k-virt machine or are there any other patches
missing?

I think the kernel part is not yet fully upstreamed, is it?

Adrian
--
.''`. John Paul Adrian Glaubitz
: :' : Debian Developer - ***@debian.org
`. `' Freie Universitaet Berlin - ***@physik.fu-berlin.de
`- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913
Loading...