public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/64358] New: Wrong code for __int128 operations in powerpc64le
@ 2014-12-19 11:35 roger.ferrer at bsc dot es
  2014-12-19 15:13 ` [Bug target/64358] " pthaugen at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: roger.ferrer at bsc dot es @ 2014-12-19 11:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 64358
           Summary: Wrong code for __int128 operations in powerpc64le
           Product: gcc
           Version: 4.9.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roger.ferrer at bsc dot es

Hi,

I'm observing a weird behaviour in PowerPC64 Little Endian that does not seem
to occur on other architectures supporting __int128. The following code, when
compiled with -O1 generates wrong output in gcc 4.9.1.

-- test.c
#include <stdio.h>

typedef unsigned __int128 uint128_t;

#define PRINT(value) \
    { union u { uint128_t i; unsigned long long l[2]; } _t = { .i = value }; \
        fprintf(stderr, "%s => <%016llx, %016llx>\n", #value, _t.l[1],
_t.l[0]); }

__attribute__((noinline))
uint128_t get_int(uint128_t value, unsigned int num_bytes)
{
    uint128_t mask = ~(uint128_t)0;
    mask <<= (uint128_t)(8 * num_bytes); /* assuming 1 byte = 8 bits */
    mask = ~mask;
    value &= mask;

    return value;
}

int main(int argc, char* argv[])
{
    uint128_t x = 0;
    x = get_int(10, /* num_bytes */ 1);

    PRINT(x);

    return 0;
}
-- end of test.c

The problem is still present in a recent version from the svn:

$ gcc -v
Using built-in specs.
COLLECT_GCC=/home/Computational/rferrer/gcc/install/bin/gcc
COLLECT_LTO_WRAPPER=/home/Computational/rferrer/gcc/install/libexec/gcc/powerpc64le-unknown-linux-gnu/5.0.0/lto-wrapper
Target: powerpc64le-unknown-linux-gnu
Configured with: ../gcc-src/configure
--prefix=/home/Computational/rferrer/gcc/install
--enable-languages=c,c++,fortran
--with-gmp=/home/Computational/rferrer/gcc/install
--with-mpfr=/home/Computational/rferrer/gcc/install
--with-mpc=/home/Computational/rferrer/gcc/install --enable-multiarch
--disable-multilib
Thread model: posix
gcc version 5.0.0 20141218 (experimental) (GCC)

$ make
gcc  -O0 -o test.O0 test.c
./test.O0
x => <0000000000000000, 000000000000000a>
gcc  -O1 -o test.O1 test.c
./test.O1
x => <ffffffffffffffff, ffffffffffffff00>

Kind regards,


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-01-13 19:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-19 11:35 [Bug target/64358] New: Wrong code for __int128 operations in powerpc64le roger.ferrer at bsc dot es
2014-12-19 15:13 ` [Bug target/64358] " pthaugen at gcc dot gnu.org
2014-12-19 16:01 ` roger.ferrer at bsc dot es
2014-12-20 15:37 ` segher at gcc dot gnu.org
2015-01-13 19:09 ` pthaugen at gcc dot gnu.org
2015-01-13 19:18 ` pthaugen at gcc dot gnu.org

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).