2 /* { dg-require-effective-target ppc_float128_sw } */
3 /* { dg-options "-mdejagnu-cpu=power7 -O2 -mfloat128 -lm" } */
15 #if defined(__BIG_ENDIAN__)
21 #elif defined(__LITTLE_ENDIAN__)
28 #error "Unknown system"
37 static int num_errors
= 0;
39 __attribute__((__noinline__
))
41 failure (int expected
, int got
, __float128 x
)
53 upper
= u
.st128
.upper
;
54 lower
= u
.st128
.lower
;
56 sign
= (unsigned)((upper
>> 63) & 1);
57 exponent
= (unsigned)((upper
>> 48) & ((((uint64_t)1) << 16) - 1));
58 mantissa1
= (upper
& ((((uint64_t)1) << 48) - 1));
61 printf ("Expected %d, got %d, %c 0x%.4x 0x%.12" PRIx64
" 0x%.16" PRIx64
,
73 #define failure(E, G, F) abort ()
76 __attribute__((__noinline__
))
78 test_signbit_arg (__float128 f128
, int expected
)
80 int sign
= __builtin_signbit (f128
);
82 if ((expected
!= 0 && sign
== 0)
83 || (expected
== 0 && sign
!= 0))
84 failure (f128
, expected
, sign
);
87 __attribute__((__noinline__
))
89 test_signbit_mem (__float128
*ptr
, int expected
)
91 int sign
= __builtin_signbit (*ptr
);
93 if ((expected
!= 0 && sign
== 0)
94 || (expected
== 0 && sign
!= 0))
95 failure (*ptr
, expected
, sign
);
98 __attribute__((__noinline__
))
100 test_signbit_gpr (__float128
*ptr
, int expected
)
102 __float128 f128
= *ptr
;
105 __asm__ (" # %0" : "+r" (f128
));
107 sign
= __builtin_signbit (f128
);
108 if ((expected
!= 0 && sign
== 0)
109 || (expected
== 0 && sign
!= 0))
110 failure (f128
, expected
, sign
);
113 __attribute__((__noinline__
))
115 test_signbit (__float128 f128
, int expected
)
120 printf ("Expecting %d, trying %-5g "
121 "(0x%.16" PRIx64
" 0x%.16" PRIx64
")\n",
122 expected
, (double)f128
,
123 u
.st128
.upper
, u
.st128
.lower
);
126 test_signbit_arg (f128
, expected
);
127 test_signbit_mem (&f128
, expected
);
128 test_signbit_gpr (&f128
, expected
);
136 test_signbit (+0.0q
, 0);
137 test_signbit (+1.0q
, 0);
139 test_signbit (-0.0q
, 1);
140 test_signbit (-1.0q
, 1);
142 test_signbit (__builtin_copysign (__builtin_infq (), +1.0q
), 0);
143 test_signbit (__builtin_copysign (__builtin_infq (), -1.0q
), 1);
145 test_signbit (__builtin_copysign (__builtin_nanq (""), +1.0q
), 0);
146 test_signbit (__builtin_copysign (__builtin_nanq (""), -1.0q
), 1);
148 /* force the bottom double word to have specific bits in the 'sign' bit to
149 make sure we are picking the right word. */
151 u
.st128
.lower
= 0ULL;
152 test_signbit (u
.f128
, 0);
154 u
.st128
.lower
= ~0ULL;
155 test_signbit (u
.f128
, 0);
158 u
.st128
.lower
= 0ULL;
159 test_signbit (u
.f128
, 1);
161 u
.st128
.lower
= ~0ULL;
162 test_signbit (u
.f128
, 1);
165 printf ("%d error(s) were found\n", num_errors
);