1/* { dg-do run { target { powerpc*-*-linux* } } } */
2/* { dg-skip-if "" { powerpc*-*-darwin* } { "*" } { "" } } */
3/* { dg-skip-if "" { powerpc*-*-*spe* } { "*" } { "" } } */
4/* { dg-require-effective-target powerpc_fprs } */
5/* { dg-require-effective-target longdouble128 } */
6/* { dg-options "-O2 -mhard-float" } */
7
8#include <stddef.h>
9#include <stdlib.h>
10#include <math.h>
11
12#ifdef DEBUG
13#include <stdio.h>
14#endif
15
16int
17main (void)
18{
19  double high = pow (2.0, 60);
20  double low  = 2.0;
21  long double a = ((long double)high) + ((long double)low);
22  double x0 = __builtin_unpack_longdouble (a, 0);
23  double x1 = __builtin_unpack_longdouble (a, 1);
24  long double b = __builtin_pack_longdouble (x0, x1);
25
26#ifdef DEBUG
27  {
28    size_t i;
29    union {
30      long double ld;
31      double d;
32      unsigned char uc[sizeof (long double)];
33      char c[sizeof (long double)];
34    } u;
35
36    printf ("a  = 0x");
37    u.ld = a;
38    for (i = 0; i < sizeof (long double); i++)
39      printf ("%.2x", u.uc[i]);
40
41    printf (", %Lg\n", a);
42
43    printf ("b  = 0x");
44    u.ld = b;
45    for (i = 0; i < sizeof (long double); i++)
46      printf ("%.2x", u.uc[i]);
47
48    printf (", %Lg\n", b);
49
50    printf ("hi = 0x");
51    u.d = high;
52    for (i = 0; i < sizeof (double); i++)
53      printf ("%.2x", u.uc[i]);
54
55    printf (",%*s %g\n", (int)(2 * (sizeof (long double) - sizeof (double))), "", high);
56
57    printf ("lo = 0x");
58    u.d = low;
59    for (i = 0; i < sizeof (double); i++)
60      printf ("%.2x", u.uc[i]);
61
62    printf (",%*s %g\n", (int)(2 * (sizeof (long double) - sizeof (double))), "", low);
63
64    printf ("x0 = 0x");
65    u.d = x0;
66    for (i = 0; i < sizeof (double); i++)
67      printf ("%.2x", u.uc[i]);
68
69    printf (",%*s %g\n", (int)(2 * (sizeof (long double) - sizeof (double))), "", x0);
70
71    printf ("x1 = 0x");
72    u.d = x1;
73    for (i = 0; i < sizeof (double); i++)
74      printf ("%.2x", u.uc[i]);
75
76    printf (",%*s %g\n", (int)(2 * (sizeof (long double) - sizeof (double))), "", x1);
77  }
78#endif
79
80  if (high != x0)
81    abort ();
82
83  if (low != x1)
84    abort ();
85
86  if (a != b)
87    abort ();
88
89  if (x0 != high)
90    abort ();
91
92  if (x1 != low)
93    abort ();
94
95  return 0;
96}
97