public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/111593] New: wrong code for 128-bit multiplication on MIPS64R6
@ 2023-09-25 19:22 mikulas at artax dot karlin.mff.cuni.cz
  0 siblings, 0 replies; only message in thread
From: mikulas at artax dot karlin.mff.cuni.cz @ 2023-09-25 19:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111593

            Bug ID: 111593
           Summary: wrong code for 128-bit multiplication on MIPS64R6
           Product: gcc
           Version: 13.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikulas at artax dot karlin.mff.cuni.cz
  Target Milestone: ---

MIPS64R6 has new instructions for multiplication and division. GCC uses them,
however it miscompiles 128-bit multiplication.

When you compile and run this program with -O1 or -O2 on mips64r6, you get
incorrect result 9F172AF9AEE4FDB2FD12E7537CC82A0F. The correct result is
60E3DC5DAC542B19FD12E7537CC82A0F.

#include <stdio.h>

__attribute__((noinline,noclone)) static unsigned __int128 power(unsigned
__int128 a, unsigned __int128 b)
{
        unsigned __int128 c = 1;
        while (b) {
                if (b & 1)
                        c *= a;
                a *= a;
                b >>= 1;
        }
        return c;
}

int main(void)
{
        int i;
        unsigned __int128 a = 0x1234567890abcdefULL;
        unsigned __int128 b = 0x1234567890abcdefULL;
        unsigned __int128 c = power(a, b);
        for (i = 124; i >= 0; i -= 4) {
                printf("%X", (unsigned)(c >> i) & 0xf);
        }
        printf("\n");
        return 0;
}

How to reproduce:

On Debian SID, install the packages gcc-13-mipsisa64r6-linux-gnuabi64,
libc6-dev-mips64r6-cross and qemu-user.

Run mipsisa64r6-linux-gnuabi64-gcc-13 -O2 power.c && /usr/bin/qemu-mips64 -L
/usr/mipsisa64r6-linux-gnuabi64/ a.out

The bug happens with gcc-10, gcc-11, gcc-12 and gcc-13 (I didn't try older
releases).

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-09-25 19:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-25 19:22 [Bug target/111593] New: wrong code for 128-bit multiplication on MIPS64R6 mikulas at artax dot karlin.mff.cuni.cz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).