PR c/39902
[official-gcc.git] / gcc / testsuite / gcc.dg / dfp / pr39902.c
blob120610c37797061267430eeb901ad43deed89dd9
1 /* { dg-options "--std=gnu99" } */
3 /* Check that optimizations like (x * 1) to x, or (x * -1) to -x,
4 do not apply to decimal float computations where trailing zeroes
5 are significant. */
7 extern void abort (void);
8 int failcnt;
10 #ifdef DBG
11 extern int printf (const char *, ...);
12 #define FAILURE { printf ("failed at line %d\n", __LINE__); failcnt++; }
13 #else
14 #define FAILURE abort ();
15 #endif
17 #define COMPARE32(A,B) \
18 A.i == B.i
20 #define COMPARE64(A,B) \
21 A.i[0] == B.i[0] && A.i[1] == B.i[1]
23 #define COMPARE128(A,B) \
24 A.i[0] == B.i[0] && A.i[1] == B.i[1] && A.i[2] == B.i[2] && A.i[3] == B.i[3]
26 typedef union {
27 _Decimal32 d;
28 unsigned int i;
29 } u32;
31 typedef union {
32 _Decimal64 d;
33 unsigned int i[2];
34 } u64;
36 typedef union {
37 _Decimal128 d;
38 unsigned int i[4];
39 } u128;
41 volatile u32 p32_1;
42 volatile u32 p32_1_0;
43 volatile u32 p32_2_0;
44 volatile u32 m32_1;
45 volatile u32 m32_1_0;
46 volatile u32 m32_2_0;
47 volatile u32 a32;
49 volatile u64 p64_1;
50 volatile u64 p64_1_0;
51 volatile u64 p64_2_0;
52 volatile u64 m64_1;
53 volatile u64 m64_1_0;
54 volatile u64 m64_2_0;
55 volatile u64 a64;
57 volatile u128 p128_1;
58 volatile u128 p128_1_0;
59 volatile u128 p128_2_0;
60 volatile u128 m128_1;
61 volatile u128 m128_1_0;
62 volatile u128 m128_2_0;
63 volatile u128 a128;
65 void
66 init32 (void)
68 p32_1.d = 1.DF;
69 p32_1_0.d = 1.0DF;
70 p32_2_0.d = 2.0DF;
71 m32_1.d = -1.DF;
72 m32_1_0.d = -1.0DF;
73 m32_2_0.d = -2.0DF;
76 void
77 init64 (void)
79 p64_1.d = 1.DD;
80 p64_1_0.d = 1.0DD;
81 p64_2_0.d = 2.0DD;
82 m64_1.d = -1.DD;
83 m64_1_0.d = -1.0DD;
84 m64_2_0.d = -2.0DD;
87 void
88 init128 (void)
90 p128_1.d = 1.DL;
91 p128_1_0.d = 1.0DL;
92 p128_2_0.d = 2.0DL;
93 m128_1.d = -1.DL;
94 m128_1_0.d = -1.0DL;
95 m128_2_0.d = -2.0DL;
98 void
99 doit32 (void)
101 /* Multiplying by a value with no trailing zero should not change the
102 quantum exponent. */
104 a32.d = p32_2_0.d * p32_1.d;
105 if (! (COMPARE32 (a32, p32_2_0)))
106 FAILURE
108 a32.d = p32_2_0.d * 1.DF;
109 if (! (COMPARE32 (a32, p32_2_0)))
110 FAILURE
112 a32.d = p32_2_0.d * m32_1.d;
113 if (! (COMPARE32 (a32, m32_2_0)))
114 FAILURE
116 a32.d = p32_2_0.d * -1.DF;
117 if (! (COMPARE32 (a32, m32_2_0)))
118 FAILURE
120 /* Multiplying by a value with a trailing zero should change the
121 quantum exponent. */
123 a32.d = p32_2_0.d * p32_1_0.d;
124 if (COMPARE32 (a32, p32_2_0))
125 FAILURE
127 a32.d = p32_2_0.d * 1.0DF;
128 if (COMPARE32 (a32, p32_2_0))
129 FAILURE
131 a32.d = p32_2_0.d * m32_1_0.d;
132 if (COMPARE32 (a32, m32_2_0))
133 FAILURE
135 a32.d = p32_2_0.d * -1.0DF;
136 if (COMPARE32 (a32, m32_2_0))
137 FAILURE
140 void
141 doit64 (void)
143 /* Multiplying by a value with no trailing zero should not change the
144 quantum exponent. */
146 a64.d = p64_2_0.d * p64_1.d;
147 if (! (COMPARE64 (a64, p64_2_0)))
148 FAILURE
150 a64.d = p64_2_0.d * 1.DD;
151 if (! (COMPARE64 (a64, p64_2_0)))
152 FAILURE
154 a64.d = p64_2_0.d * m64_1.d;
155 if (! (COMPARE64 (a64, m64_2_0)))
156 FAILURE
158 a64.d = p64_2_0.d * -1.DD;
159 if (! (COMPARE64 (a64, m64_2_0)))
160 FAILURE
162 /* Multiplying by a value with a trailing zero should change the
163 quantum exponent. */
165 a64.d = p64_2_0.d * p64_1_0.d;
166 if (COMPARE64 (a64, p64_2_0))
167 FAILURE
169 a64.d = p64_2_0.d * 1.0DD;
170 if (COMPARE64 (a64, p64_2_0))
171 FAILURE
173 a64.d = p64_2_0.d * m64_1_0.d;
174 if (COMPARE64 (a64, m64_2_0))
175 FAILURE
177 a64.d = p64_2_0.d * -1.0DD;
178 if (COMPARE64 (a64, m64_2_0))
179 FAILURE
182 void
183 doit128 (void)
185 /* Multiplying by a value with no trailing zero should not change the
186 quantum exponent. */
188 a128.d = p128_2_0.d * p128_1_0.d;
189 if (COMPARE128 (a128, p128_2_0))
190 FAILURE
192 a128.d = p128_2_0.d * 1.0DL;
193 if (COMPARE128 (a128, p128_2_0))
194 FAILURE
196 a128.d = p128_2_0.d * m128_1_0.d;
197 if (COMPARE128 (a128, m128_2_0))
198 FAILURE
200 a128.d = p128_2_0.d * -1.0DL;
201 if (COMPARE128 (a128, m128_2_0))
202 FAILURE
204 /* Multiplying by a value with a trailing zero should change the
205 quantum exponent. */
207 a128.d = p128_2_0.d * p128_1.d;
208 if (! (COMPARE128 (a128, p128_2_0)))
209 FAILURE
211 a128.d = p128_2_0.d * 1.DL;
212 if (! (COMPARE128 (a128, p128_2_0)))
213 FAILURE
215 a128.d = p128_2_0.d * m128_1.d;
216 if (! (COMPARE128 (a128, m128_2_0)))
217 FAILURE
219 a128.d = p128_2_0.d * -1.DL;
220 if (! (COMPARE128 (a128, m128_2_0)))
221 FAILURE
225 main (void)
227 init32 ();
228 init64 ();
229 init128 ();
231 doit32 ();
232 doit64 ();
233 doit128 ();
235 if (failcnt != 0)
236 abort ();
238 return 0;