Use conditional internal functions in if-conversion
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / float128-4.c
blob00b18881a0b966e08dd69c05f810b3c06d4f08b5
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" } */
6 /* This is the same as test float128-1.c, using the _Float128 keyword instead
7 of __float128, and not using -mfloat128. */
9 #ifdef DEBUG
10 #include <stdio.h>
11 #include <stddef.h>
12 #include <stdint.h>
13 #include <inttypes.h>
14 #endif
16 #if !defined(__FLOAT128__) || !defined(_ARCH_PPC)
17 static _Float128
18 pass_through (_Float128 x)
20 return x;
23 _Float128 (*no_optimize) (_Float128) = pass_through;
24 #endif
26 #ifdef DEBUG
27 __attribute__((__noinline__))
28 static void
29 print_f128 (_Float128 x)
31 unsigned sign;
32 unsigned exponent;
33 uint64_t mantissa1;
34 uint64_t mantissa2;
35 uint64_t upper;
36 uint64_t lower;
38 #if defined(_ARCH_PPC) && defined(__BIG_ENDIAN__)
39 struct ieee128 {
40 uint64_t upper;
41 uint64_t lower;
44 #elif (defined(_ARCH_PPC) && defined(__LITTLE_ENDIAN__)) || defined(__x86_64__)
45 struct ieee128 {
46 uint64_t lower;
47 uint64_t upper;
50 #else
51 #error "Unknown system"
52 #endif
54 union {
55 _Float128 f128;
56 struct ieee128 s128;
57 } u;
59 u.f128 = x;
60 upper = u.s128.upper;
61 lower = u.s128.lower;
63 sign = (unsigned)((upper >> 63) & 1);
64 exponent = (unsigned)((upper >> 48) & ((((uint64_t)1) << 16) - 1));
65 mantissa1 = (upper & ((((uint64_t)1) << 48) - 1));
66 mantissa2 = lower;
68 printf ("%c 0x%.4x 0x%.12" PRIx64 " 0x%.16" PRIx64,
69 sign ? '-' : '+',
70 exponent,
71 mantissa1,
72 mantissa2);
74 #endif
76 __attribute__((__noinline__))
77 static void
78 do_test (_Float128 expected, _Float128 got, const char *name)
80 int equal_p = (expected == got);
82 #ifdef DEBUG
83 printf ("Test %s, expected: ", name);
84 print_f128 (expected);
85 printf (" %5g, got: ", (double) expected);
86 print_f128 (got);
87 printf (" %5g, result %s\n",
88 (double) got,
89 (equal_p) ? "equal" : "not equal");
90 #endif
92 if (!equal_p)
93 __builtin_abort ();
97 int
98 main (void)
100 _Float128 one = 1.0f128;
101 _Float128 two = 2.0f128;
102 _Float128 three = 3.0f128;
103 _Float128 four = 4.0f128;
104 _Float128 five = 5.0f128;
105 _Float128 add_result = (1.0f128 + 2.0f128);
106 _Float128 mul_result = ((1.0f128 + 2.0f128) * 3.0f128);
107 _Float128 div_result = (((1.0f128 + 2.0f128) * 3.0f128) / 4.0f128);
108 _Float128 sub_result = ((((1.0f128 + 2.0f128) * 3.0f128) / 4.0f128)
109 - 5.0f128);
110 _Float128 neg_result = - sub_result;
111 _Float128 add_xresult;
112 _Float128 mul_xresult;
113 _Float128 div_xresult;
114 _Float128 sub_xresult;
115 _Float128 neg_xresult;
117 #if defined(__FLOAT128__) && defined(_ARCH_PPC)
118 __asm__ (" #prevent constant folding, %x0" : "+wa" (one));
119 __asm__ (" #prevent constant folding, %x0" : "+wa" (two));
120 __asm__ (" #prevent constant folding, %x0" : "+wa" (three));
121 __asm__ (" #prevent constant folding, %x0" : "+wa" (four));
122 __asm__ (" #prevent constant folding, %x0" : "+wa" (five));
124 #else
125 one = no_optimize (one);
126 two = no_optimize (two);
127 three = no_optimize (three);
128 four = no_optimize (four);
129 five = no_optimize (five);
130 #endif
132 add_xresult = (one + two);
133 do_test (add_result, add_xresult, "add");
135 mul_xresult = add_xresult * three;
136 do_test (mul_result, mul_xresult, "mul");
138 div_xresult = mul_xresult / four;
139 do_test (div_result, div_xresult, "div");
141 sub_xresult = div_xresult - five;
142 do_test (sub_result, sub_xresult, "sub");
144 neg_xresult = - sub_xresult;
145 do_test (neg_result, neg_xresult, "neg");
147 #ifdef DEBUG
148 printf ("Passed\n");
149 #endif
151 return 0;