1 /* { dg-do run { target { powerpc*-*-linux* } } } */
2 /* { dg-skip-if "" { powerpc*-*-darwin* } } */
3 /* { dg-require-effective-target powerpc_fprs } */
4 /* { dg-require-effective-target longdouble128 } */
5 /* { dg-options "-O2 -mhard-float" } */
6
7 #include <stddef.h>
8 #include <stdlib.h>
9 #include <math.h>
10
11 #ifdef DEBUG
12 #include <stdio.h>
13 #endif
14
15 #if defined(__LONG_DOUBLE_IEEE128__)
16 /* If long double is IEEE 128-bit, we need to use the __ibm128 type instead of
17 long double, and to use the appropriate pack/unpack routines. We can't use
18 __ibm128 on systems that don't support IEEE 128-bit floating point, because
19 the type is not enabled on those systems. */
20 #define PACK __builtin_pack_ibm128
21 #define UNPACK __builtin_unpack_ibm128
22 #define LDOUBLE __ibm128
23
24 #elif defined(__LONG_DOUBLE_IBM128__)
25 #define PACK __builtin_pack_longdouble
26 #define UNPACK __builtin_unpack_longdouble
27 #define LDOUBLE long double
28
29 #else
30 #error "long double must be either IBM 128-bit or IEEE 128-bit"
31 #endif
32
33 int
34 main (void)
35 {
36 double high = pow (2.0, 60);
37 double low = 2.0;
38 LDOUBLE a = ((LDOUBLE)high) + ((LDOUBLE)low);
39 double x0 = UNPACK (a, 0);
40 double x1 = UNPACK (a, 1);
41 LDOUBLE b = PACK (x0, x1);
42
43 #ifdef DEBUG
44 {
45 size_t i;
46 union {
47 LDOUBLE ld;
48 double d;
49 unsigned char uc[sizeof (LDOUBLE)];
50 char c[sizeof (LDOUBLE)];
51 } u;
52
53 printf ("a = 0x");
54 u.ld = a;
55 for (i = 0; i < sizeof (LDOUBLE); i++)
56 printf ("%.2x", u.uc[i]);
57
58 printf (", %Lg\n", a);
59
60 printf ("b = 0x");
61 u.ld = b;
62 for (i = 0; i < sizeof (LDOUBLE); i++)
63 printf ("%.2x", u.uc[i]);
64
65 printf (", %Lg\n", b);
66
67 printf ("hi = 0x");
68 u.d = high;
69 for (i = 0; i < sizeof (double); i++)
70 printf ("%.2x", u.uc[i]);
71
72 printf (",%*s %g\n", (int)(2 * (sizeof (LDOUBLE) - sizeof (double))), "", high);
73
74 printf ("lo = 0x");
75 u.d = low;
76 for (i = 0; i < sizeof (double); i++)
77 printf ("%.2x", u.uc[i]);
78
79 printf (",%*s %g\n", (int)(2 * (sizeof (LDOUBLE) - sizeof (double))), "", low);
80
81 printf ("x0 = 0x");
82 u.d = x0;
83 for (i = 0; i < sizeof (double); i++)
84 printf ("%.2x", u.uc[i]);
85
86 printf (",%*s %g\n", (int)(2 * (sizeof (LDOUBLE) - sizeof (double))), "", x0);
87
88 printf ("x1 = 0x");
89 u.d = x1;
90 for (i = 0; i < sizeof (double); i++)
91 printf ("%.2x", u.uc[i]);
92
93 printf (",%*s %g\n", (int)(2 * (sizeof (LDOUBLE) - sizeof (double))), "", x1);
94 }
95 #endif
96
97 if (high != x0)
98 abort ();
99
100 if (low != x1)
101 abort ();
102
103 if (a != b)
104 abort ();
105
106 if (x0 != high)
107 abort ();
108
109 if (x1 != low)
110 abort ();
111
112 return 0;
113 }