1 |
691 |
jeremybenn |
/* { dg-do run { target powerpc*-*-darwin* } } */
|
2 |
|
|
/* { dg-options "" } */
|
3 |
|
|
/* No options so 'long long' can be used. */
|
4 |
|
|
|
5 |
|
|
#include <stdio.h>
|
6 |
|
|
#include <stdlib.h>
|
7 |
|
|
#include <string.h>
|
8 |
|
|
|
9 |
|
|
typedef unsigned long long uint64_t;
|
10 |
|
|
typedef uint64_t ldbits[2];
|
11 |
|
|
|
12 |
|
|
union ldu
|
13 |
|
|
{
|
14 |
|
|
ldbits lb;
|
15 |
|
|
long double ld;
|
16 |
|
|
};
|
17 |
|
|
|
18 |
|
|
static const struct {
|
19 |
|
|
ldbits a;
|
20 |
|
|
ldbits b;
|
21 |
|
|
ldbits result;
|
22 |
|
|
} single_tests[] = {
|
23 |
|
|
/* Test of values that add to near +Inf. */
|
24 |
|
|
{ { 0x7FEFFFFFFFFFFFFFLL, 0xFC88000000000000LL },
|
25 |
|
|
{ 0x7C94000000000000LL, 0x0000000000000000LL },
|
26 |
|
|
{ 0x7FEFFFFFFFFFFFFFLL, 0x7C80000000000000LL } },
|
27 |
|
|
{ { 0x7FEFFFFFFFFFFFFFLL, 0x7C8FFFFFFFFFFFFFLL },
|
28 |
|
|
{ 0x792FFFFFFFFFFFFFLL, 0x0000000000000000LL },
|
29 |
|
|
{ 0x7FEFFFFFFFFFFFFFLL, 0x7C8FFFFFFFFFFFFFLL } },
|
30 |
|
|
{ { 0x7FEFFFFFFFFFFFFFLL, 0x7C8FFFFFFFFFFFFFLL },
|
31 |
|
|
{ 0x7930000000000000LL, 0xF5DFFFFFFFFFFFFFLL },
|
32 |
|
|
/* correct result is: { 0x7FEFFFFFFFFFFFFFLL, 0x7C8FFFFFFFFFFFFFLL } */
|
33 |
|
|
{ 0x7FF0000000000000LL, 0x0000000000000000LL } },
|
34 |
|
|
/* Test of values that add to +Inf. */
|
35 |
|
|
{ { 0x7FEFFFFFFFFFFFFFLL, 0x7C8FFFFFFFFFFFFFLL },
|
36 |
|
|
{ 0x7930000000000000LL, 0x0000000000000000LL },
|
37 |
|
|
{ 0x7FF0000000000000LL, 0x0000000000000000LL } },
|
38 |
|
|
/* Tests of Inf addition. */
|
39 |
|
|
{ { 0x7FF0000000000000LL, 0x0000000000000000LL },
|
40 |
|
|
{ 0x0000000000000000LL, 0x0000000000000000LL },
|
41 |
|
|
{ 0x7FF0000000000000LL, 0x0000000000000000LL } },
|
42 |
|
|
{ { 0x7FF0000000000000LL, 0x0000000000000000LL },
|
43 |
|
|
{ 0x7FF0000000000000LL, 0x0000000000000000LL },
|
44 |
|
|
{ 0x7FF0000000000000LL, 0x0000000000000000LL } },
|
45 |
|
|
/* Test of Inf addition producing NaN. */
|
46 |
|
|
{ { 0x7FF0000000000000LL, 0x0000000000000000LL },
|
47 |
|
|
{ 0xFFF0000000000000LL, 0x0000000000000000LL },
|
48 |
|
|
{ 0x7FF8000000000000LL, 0x0000000000000000LL } },
|
49 |
|
|
/* Tests of NaN addition. */
|
50 |
|
|
{ { 0x7FF8000000000000LL, 0x0000000000000000LL },
|
51 |
|
|
{ 0x0000000000000000LL, 0x0000000000000000LL },
|
52 |
|
|
{ 0x7FF8000000000000LL, 0x7FF8000000000000LL } },
|
53 |
|
|
{ { 0x7FF8000000000000LL, 0x0000000000000000LL },
|
54 |
|
|
{ 0x7FF0000000000000LL, 0x0000000000000000LL },
|
55 |
|
|
{ 0x7FF8000000000000LL, 0x7FF8000000000000LL } },
|
56 |
|
|
/* Addition of positive integers, with interesting rounding properties. */
|
57 |
|
|
{ { 0x4690000000000000LL, 0x4330000000000000LL },
|
58 |
|
|
{ 0x4650000000000009LL, 0xC2FFFFFFFFFFFFF2LL },
|
59 |
|
|
/* correct result is: { 0x4691000000000001LL, 0xC32C000000000000LL } */
|
60 |
|
|
{ 0x4691000000000001LL, 0xc32bfffffffffffeLL } },
|
61 |
|
|
{ { 0x4690000000000000LL, 0x4330000000000000LL },
|
62 |
|
|
{ 0x4650000000000008LL, 0x42F0000000000010LL },
|
63 |
|
|
{ 0x4691000000000001LL, 0xC32E000000000000LL } },
|
64 |
|
|
{ { 0x469FFFFFFFFFFFFFLL, 0x433FFFFFFFFFFFFFLL },
|
65 |
|
|
{ 0x4340000000000000LL, 0x3FF0000000000000LL },
|
66 |
|
|
{ 0x46A0000000000000LL, 0x0000000000000000LL } },
|
67 |
|
|
{ { 0x469FFFFFFFFFFFFFLL, 0x433FFFFFFFFFFFFFLL },
|
68 |
|
|
{ 0x4340000000000000LL, 0x0000000000000000LL },
|
69 |
|
|
{ 0x46A0000000000000LL, 0xBFF0000000000000LL } },
|
70 |
|
|
/* Subtraction of integers, with cancellation. */
|
71 |
|
|
{ { 0x4690000000000000LL, 0x4330000000000000LL },
|
72 |
|
|
{ 0xC690000000000000LL, 0xC330000000000000LL },
|
73 |
|
|
{ 0x0000000000000000LL, 0x0000000000000000LL } },
|
74 |
|
|
{ { 0x4690000000000000LL, 0x4330000000000000LL },
|
75 |
|
|
{ 0xC330000000000000LL, 0x0000000000000000LL },
|
76 |
|
|
{ 0x4690000000000000LL, 0x0000000000000000LL } },
|
77 |
|
|
{ { 0x4690000000000000LL, 0x4330000000000000LL },
|
78 |
|
|
{ 0xC330000000000000LL, 0x3FA0000000000000LL },
|
79 |
|
|
{ 0x4690000000000000LL, 0x3FA0000000000000LL } },
|
80 |
|
|
{ { 0x4690000000000000LL, 0x4330000000000000LL },
|
81 |
|
|
{ 0xC690000000000000LL, 0x3FA0000000000000LL },
|
82 |
|
|
/* correct result is: { 0x4330000000000000LL, 0x3FA0000000000000LL } */
|
83 |
|
|
{ 0x4330000000000000LL, 0x0000000000000000LL } }
|
84 |
|
|
};
|
85 |
|
|
|
86 |
|
|
static int fail = 0;
|
87 |
|
|
|
88 |
|
|
static void
|
89 |
|
|
run_single_tests (void)
|
90 |
|
|
{
|
91 |
|
|
size_t i;
|
92 |
|
|
for (i = 0; i < sizeof (single_tests) / sizeof (single_tests[0]); i++)
|
93 |
|
|
{
|
94 |
|
|
union ldu a, b, result, expected;
|
95 |
|
|
memcpy (a.lb, single_tests[i].a, sizeof (ldbits));
|
96 |
|
|
memcpy (b.lb, single_tests[i].b, sizeof (ldbits));
|
97 |
|
|
memcpy (expected.lb, single_tests[i].result, sizeof (ldbits));
|
98 |
|
|
result.ld = a.ld + b.ld;
|
99 |
|
|
if (memcmp (result.lb, expected.lb,
|
100 |
|
|
result.ld == result.ld ? sizeof (ldbits) : sizeof (double))
|
101 |
|
|
!= 0)
|
102 |
|
|
{
|
103 |
|
|
printf ("FAIL: %016llx %016llx + %016llx %016llx\n",
|
104 |
|
|
a.lb[0], a.lb[1], b.lb[0], b.lb[1]);
|
105 |
|
|
printf (" = %016llx %016llx not %016llx %016llx\n",
|
106 |
|
|
result.lb[0], result.lb[1], expected.lb[0], expected.lb[1]);
|
107 |
|
|
fail = 1;
|
108 |
|
|
}
|
109 |
|
|
}
|
110 |
|
|
}
|
111 |
|
|
|
112 |
|
|
int main(void)
|
113 |
|
|
{
|
114 |
|
|
run_single_tests();
|
115 |
|
|
if (fail)
|
116 |
|
|
abort ();
|
117 |
|
|
else
|
118 |
|
|
exit (0);
|
119 |
|
|
}
|