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