• m68k OCaml porting issue

    From =?UTF-8?Q?St=c3=a9phane_Glondu?=@21:1/5 to All on Wed Dec 22 13:50:01 2021
    XPost: linux.debian.ports.68k

    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From =?UTF-8?Q?St=c3=a9phane_Glondu?=@21:1/5 to All on Wed Dec 22 14:50:01 2021
    XPost: linux.debian.ports.68k

    Le 22/12/2021 à 13:45, Stéphane Glondu a écrit :
    While debugging OCaml 4.13.1's testsuite on m68k, I've noticed that the following:
    [...]
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to All on Wed Dec 22 15:50:03 2021
    XPost: linux.debian.ports.68k

    Hi Stéphane!

    On 12/22/21 14:47, Stéphane Glondu wrote:
    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".

    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 - glaubitz@debian.org
    `. `' Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Laurent Vivier@21:1/5 to All on Wed Dec 22 17:50:01 2021
    XPost: linux.debian.ports.68k

    Le 22/12/2021 à 15:40, John Paul Adrian Glaubitz a écrit :
    Hi Stéphane!

    On 12/22/21 14:47, Stéphane Glondu wrote:
    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".

    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


    With Qemu 6.2.50 (from git repo):

    -NAN

    With Quadra 800 with 68040 FPU:

    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.

    First test gives me:

    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.

    Thanks,
    Laurent

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From John Paul Adrian Glaubitz@21:1/5 to Laurent Vivier on Thu Dec 23 10:00:02 2021
    XPost: linux.debian.ports.68k

    Hi Laurent!

    On 12/22/21 17:48, Laurent Vivier wrote:
    With Qemu 6.2.50 (from git repo):

    -NAN

    With Quadra 800 with 68040 FPU:

    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.

    First test gives me:

    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 - glaubitz@debian.org
    `. `' Freie Universitaet Berlin - glaubitz@physik.fu-berlin.de
    `- GPG: 62FF 8A75 84E0 2956 9546 0006 7426 3B37 F5B5 F913

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Laurent Vivier@21:1/5 to All on Thu Dec 23 10:40:01 2021
    XPost: linux.debian.ports.68k

    Le 23/12/2021 à 09:56, John Paul Adrian Glaubitz a écrit :
    Hi Laurent!

    On 12/22/21 17:48, Laurent Vivier wrote:
    With Qemu 6.2.50 (from git repo):

    -NAN

    With Quadra 800 with 68040 FPU:

    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.

    First test gives me:

    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?


    No other patches are missing.

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


    Correct. I try to resend a patch this week to have this merged, but spare time is missing.

    Thanks,
    Laurent

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)