[nvptx] Fix printing of 128-bit constant (negative case)
For this code: ... __int128 min_one = -1; ... we currently generate: ... .visible .global .align 8 .u64 min_one[2] = { -1, 0 }; ... Fix this in nvptx_assemble_value, such that we have instead: ... .visible .global .align 8 .u64 min_one[2] = { -1, -1 }; ... gcc/ChangeLog: * config/nvptx/nvptx.c (nvptx_assemble_value): Handle negative __int128. gcc/testsuite/ChangeLog: * gcc.target/nvptx/int128.c: New test.
This commit is contained in:
parent
848e74bea1
commit
60e537a026
@ -2050,13 +2050,16 @@ output_init_frag (rtx sym)
|
||||
static void
|
||||
nvptx_assemble_value (unsigned HOST_WIDE_INT val, unsigned size)
|
||||
{
|
||||
bool negative_p
|
||||
= val & (HOST_WIDE_INT_1U << (HOST_BITS_PER_WIDE_INT - 1));
|
||||
|
||||
val &= ((unsigned HOST_WIDE_INT)2 << (size * BITS_PER_UNIT - 1)) - 1;
|
||||
|
||||
for (unsigned part = 0; size; size -= part)
|
||||
{
|
||||
if (part * BITS_PER_UNIT == HOST_BITS_PER_WIDE_INT)
|
||||
/* Avoid undefined behaviour. */
|
||||
val = 0;
|
||||
val = negative_p ? -1 : 0;
|
||||
else
|
||||
val >>= (part * BITS_PER_UNIT);
|
||||
part = init_frag.size - init_frag.offset;
|
||||
|
15
gcc/testsuite/gcc.target/nvptx/int128.c
Normal file
15
gcc/testsuite/gcc.target/nvptx/int128.c
Normal file
@ -0,0 +1,15 @@
|
||||
/* { dg-do run } */
|
||||
/* { dg-additional-options "-Wno-pedantic" } */
|
||||
|
||||
__int128 one = 1;
|
||||
__int128 min_one = -1;
|
||||
__int128 zero = 0;
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
if (zero - one != min_one)
|
||||
__builtin_abort ();
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user