1 /* { dg-do run { target { powerpc*-*-linux* } } } */
2 /* { dg-require-effective-target ppc_float128_sw } */
3 /* { dg-require-effective-target vsx_hw } */
4 /* { dg-options "-mvsx -O2" } */
7 * Test program to make sure we are getting more precision than the 53 bits we
8 * get with IEEE double.
17 #define TYPE __float128
21 #define NO_INLINE __attribute__((__noinline__))
24 static TYPE
power_of_two (ssize_t
) NO_INLINE
;
25 static TYPE
calc1 (TYPE
) NO_INLINE
;
26 static TYPE
calc2 (TYPE
) NO_INLINE
;
27 static TYPE
calc3 (TYPE
) NO_INLINE
;
39 #if defined(DEBUG) || defined(DEBUG2)
40 static void print_hex (const char *prefix
, TYPE
, const char *suffix
) NO_INLINE
;
42 #if defined (__i386__) || defined (__x86_64__) || defined (__LITTLE_ENDIAN__)
43 #define ENDIAN_REVERSE(N, MAX) ((MAX) - 1 - (N))
46 #define ENDIAN_REVERSE(N, MAX) (N)
50 print_hex (const char *prefix
, TYPE value
, const char *suffix
)
54 unsigned char uc
[sizeof (TYPE
)];
60 printf ("%s0x", prefix
);
61 for (i
= 0; i
< sizeof (TYPE
); i
++)
62 printf ("%.2x", u
.uc
[ ENDIAN_REVERSE (i
, sizeof (TYPE
)) ]);
64 printf (", %24.2Lf%s", (long double)value
, suffix
);
70 * Return a power of two.
74 power_of_two (ssize_t num
)
76 TYPE ret
= (TYPE
) 1.0;
81 for (i
= 0; i
< num
; i
++)
87 for (i
= 0; i
< num2
; i
++)
92 printf ("power_of_two (%2ld) = ", (long) num
);
93 print_hex ("", ret
, "\n");
101 static TYPE
add (TYPE a
, TYPE b
) NO_INLINE
;
102 static TYPE
sub (TYPE a
, TYPE b
) NO_INLINE
;
109 print_hex ("add, arg1 = ", a
, "\n");
110 print_hex ("add, arg2 = ", b
, "\n");
114 print_hex ("add, result = ", c
, "\n");
124 print_hex ("sub, arg1 = ", a
, "\n");
125 print_hex ("sub, arg2 = ", b
, "\n");
129 print_hex ("sub, result = ", c
, "\n");
135 #define add(x, y) ((x) + (y))
136 #define sub(x, y) ((x) - (y))
140 * Various calculations. Add in 2**POWER2, and subtract 2**(POWER2-1) twice, and we should
141 * get the original value.
147 TYPE num2
= add (power_of_two (POWER2
), num
);
151 print_hex ("calc1 (before call) = ", num2
, "\n");
157 print_hex ("calc1 (after call) = ", ret
, "\n");
166 TYPE num2
= sub (num
, power_of_two (POWER2
-1));
170 print_hex ("calc2 (before call) = ", num2
, "\n");
176 print_hex ("calc2 (after call) = ", ret
, "\n");
185 TYPE ret
= sub (num
, (((TYPE
) 2.0) * power_of_two (POWER2
-2)));
188 print_hex ("calc3 = ", ret
, "\n");
201 printf ("Testing, %ld bytes\n", (long) sizeof (TYPE
));
204 input
= power_of_two (-1);
205 if ((double)input
!= 0.5)
207 #if defined(DEBUG) || defined(DEBUG2)
208 print_hex ("Input should be 0.5: ", output
, "\n");
215 output
= calc1 (input
);
216 if ((double)output
!= 0.5)
218 #if defined(DEBUG) || defined(DEBUG2)
219 print_hex ("Output should be 0.5: ", output
, "\n");