1*975af797SJoseph Myers /* Test floating-point exceptions.  */
2*975af797SJoseph Myers 
3*975af797SJoseph Myers #include <float.h>
4*975af797SJoseph Myers #include <stdint.h>
5*975af797SJoseph Myers #include <stdio.h>
6*975af797SJoseph Myers 
7*975af797SJoseph Myers union u {
8*975af797SJoseph Myers     struct { uint64_t sig; uint16_t sign_exp; } s;
9*975af797SJoseph Myers     long double ld;
10*975af797SJoseph Myers };
11*975af797SJoseph Myers 
12*975af797SJoseph Myers volatile float f_res;
13*975af797SJoseph Myers volatile double d_res;
14*975af797SJoseph Myers volatile long double ld_res;
15*975af797SJoseph Myers volatile long double ld_res2;
16*975af797SJoseph Myers 
17*975af797SJoseph Myers volatile union u ld_invalid_1 = { .s = { 1, 1234 } };
18*975af797SJoseph Myers volatile float f_snan = __builtin_nansf("");
19*975af797SJoseph Myers volatile double d_snan = __builtin_nans("");
20*975af797SJoseph Myers volatile long double ld_third = 1.0L / 3.0L;
21*975af797SJoseph Myers volatile long double ld_snan = __builtin_nansl("");
22*975af797SJoseph Myers volatile long double ld_nan = __builtin_nanl("");
23*975af797SJoseph Myers volatile long double ld_inf = __builtin_infl();
24*975af797SJoseph Myers volatile long double ld_ninf = -__builtin_infl();
25*975af797SJoseph Myers volatile long double ld_one = 1.0L;
26*975af797SJoseph Myers volatile long double ld_zero = 0.0L;
27*975af797SJoseph Myers volatile long double ld_nzero = -0.0L;
28*975af797SJoseph Myers volatile long double ld_min = LDBL_MIN;
29*975af797SJoseph Myers volatile long double ld_max = LDBL_MAX;
30*975af797SJoseph Myers volatile long double ld_nmax = -LDBL_MAX;
31*975af797SJoseph Myers 
32*975af797SJoseph Myers #define IE (1 << 0)
33*975af797SJoseph Myers #define ZE (1 << 2)
34*975af797SJoseph Myers #define OE (1 << 3)
35*975af797SJoseph Myers #define UE (1 << 4)
36*975af797SJoseph Myers #define PE (1 << 5)
37*975af797SJoseph Myers #define EXC (IE | ZE | OE | UE | PE)
38*975af797SJoseph Myers 
39*975af797SJoseph Myers int main(void)
40*975af797SJoseph Myers {
41*975af797SJoseph Myers     short sw;
42*975af797SJoseph Myers     unsigned char out[10];
43*975af797SJoseph Myers     int ret = 0;
44*975af797SJoseph Myers     int16_t res_16;
45*975af797SJoseph Myers     int32_t res_32;
46*975af797SJoseph Myers     int64_t res_64;
47*975af797SJoseph Myers 
48*975af797SJoseph Myers     __asm__ volatile ("fnclex");
49*975af797SJoseph Myers     ld_res = f_snan;
50*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
51*975af797SJoseph Myers     if ((sw & EXC) != IE) {
52*975af797SJoseph Myers         printf("FAIL: widen float snan\n");
53*975af797SJoseph Myers         ret = 1;
54*975af797SJoseph Myers     }
55*975af797SJoseph Myers     __asm__ volatile ("fnclex");
56*975af797SJoseph Myers     ld_res = d_snan;
57*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
58*975af797SJoseph Myers     if ((sw & EXC) != IE) {
59*975af797SJoseph Myers         printf("FAIL: widen double snan\n");
60*975af797SJoseph Myers         ret = 1;
61*975af797SJoseph Myers     }
62*975af797SJoseph Myers 
63*975af797SJoseph Myers     __asm__ volatile ("fnclex");
64*975af797SJoseph Myers     f_res = ld_min;
65*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
66*975af797SJoseph Myers     if ((sw & EXC) != (UE | PE)) {
67*975af797SJoseph Myers         printf("FAIL: narrow float underflow\n");
68*975af797SJoseph Myers         ret = 1;
69*975af797SJoseph Myers     }
70*975af797SJoseph Myers     __asm__ volatile ("fnclex");
71*975af797SJoseph Myers     d_res = ld_min;
72*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
73*975af797SJoseph Myers     if ((sw & EXC) != (UE | PE)) {
74*975af797SJoseph Myers         printf("FAIL: narrow double underflow\n");
75*975af797SJoseph Myers         ret = 1;
76*975af797SJoseph Myers     }
77*975af797SJoseph Myers 
78*975af797SJoseph Myers     __asm__ volatile ("fnclex");
79*975af797SJoseph Myers     f_res = ld_max;
80*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
81*975af797SJoseph Myers     if ((sw & EXC) != (OE | PE)) {
82*975af797SJoseph Myers         printf("FAIL: narrow float overflow\n");
83*975af797SJoseph Myers         ret = 1;
84*975af797SJoseph Myers     }
85*975af797SJoseph Myers     __asm__ volatile ("fnclex");
86*975af797SJoseph Myers     d_res = ld_max;
87*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
88*975af797SJoseph Myers     if ((sw & EXC) != (OE | PE)) {
89*975af797SJoseph Myers         printf("FAIL: narrow double overflow\n");
90*975af797SJoseph Myers         ret = 1;
91*975af797SJoseph Myers     }
92*975af797SJoseph Myers 
93*975af797SJoseph Myers     __asm__ volatile ("fnclex");
94*975af797SJoseph Myers     f_res = ld_third;
95*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
96*975af797SJoseph Myers     if ((sw & EXC) != PE) {
97*975af797SJoseph Myers         printf("FAIL: narrow float inexact\n");
98*975af797SJoseph Myers         ret = 1;
99*975af797SJoseph Myers     }
100*975af797SJoseph Myers     __asm__ volatile ("fnclex");
101*975af797SJoseph Myers     d_res = ld_third;
102*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
103*975af797SJoseph Myers     if ((sw & EXC) != PE) {
104*975af797SJoseph Myers         printf("FAIL: narrow double inexact\n");
105*975af797SJoseph Myers         ret = 1;
106*975af797SJoseph Myers     }
107*975af797SJoseph Myers 
108*975af797SJoseph Myers     __asm__ volatile ("fnclex");
109*975af797SJoseph Myers     f_res = ld_snan;
110*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
111*975af797SJoseph Myers     if ((sw & EXC) != IE) {
112*975af797SJoseph Myers         printf("FAIL: narrow float snan\n");
113*975af797SJoseph Myers         ret = 1;
114*975af797SJoseph Myers     }
115*975af797SJoseph Myers     __asm__ volatile ("fnclex");
116*975af797SJoseph Myers     d_res = ld_snan;
117*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
118*975af797SJoseph Myers     if ((sw & EXC) != IE) {
119*975af797SJoseph Myers         printf("FAIL: narrow double snan\n");
120*975af797SJoseph Myers         ret = 1;
121*975af797SJoseph Myers     }
122*975af797SJoseph Myers 
123*975af797SJoseph Myers     __asm__ volatile ("fnclex");
124*975af797SJoseph Myers     f_res = ld_invalid_1.ld;
125*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
126*975af797SJoseph Myers     if ((sw & EXC) != IE) {
127*975af797SJoseph Myers         printf("FAIL: narrow float invalid\n");
128*975af797SJoseph Myers         ret = 1;
129*975af797SJoseph Myers     }
130*975af797SJoseph Myers     __asm__ volatile ("fnclex");
131*975af797SJoseph Myers     d_res = ld_invalid_1.ld;
132*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
133*975af797SJoseph Myers     if ((sw & EXC) != IE) {
134*975af797SJoseph Myers         printf("FAIL: narrow double invalid\n");
135*975af797SJoseph Myers         ret = 1;
136*975af797SJoseph Myers     }
137*975af797SJoseph Myers 
138*975af797SJoseph Myers     __asm__ volatile ("fnclex");
139*975af797SJoseph Myers     __asm__ volatile ("frndint" : "=t" (ld_res) : "0" (ld_min));
140*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
141*975af797SJoseph Myers     if ((sw & EXC) != PE) {
142*975af797SJoseph Myers         printf("FAIL: frndint min\n");
143*975af797SJoseph Myers         ret = 1;
144*975af797SJoseph Myers     }
145*975af797SJoseph Myers     __asm__ volatile ("fnclex");
146*975af797SJoseph Myers     __asm__ volatile ("frndint" : "=t" (ld_res) : "0" (ld_snan));
147*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
148*975af797SJoseph Myers     if ((sw & EXC) != IE) {
149*975af797SJoseph Myers         printf("FAIL: frndint snan\n");
150*975af797SJoseph Myers         ret = 1;
151*975af797SJoseph Myers     }
152*975af797SJoseph Myers     __asm__ volatile ("fnclex");
153*975af797SJoseph Myers     __asm__ volatile ("frndint" : "=t" (ld_res) : "0" (ld_invalid_1.ld));
154*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
155*975af797SJoseph Myers     if ((sw & EXC) != IE) {
156*975af797SJoseph Myers         printf("FAIL: frndint invalid\n");
157*975af797SJoseph Myers         ret = 1;
158*975af797SJoseph Myers     }
159*975af797SJoseph Myers 
160*975af797SJoseph Myers     __asm__ volatile ("fnclex");
161*975af797SJoseph Myers     __asm__ volatile ("fcom" : : "t" (ld_nan), "u" (ld_zero));
162*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
163*975af797SJoseph Myers     if ((sw & EXC) != IE) {
164*975af797SJoseph Myers         printf("FAIL: fcom nan\n");
165*975af797SJoseph Myers         ret = 1;
166*975af797SJoseph Myers     }
167*975af797SJoseph Myers     __asm__ volatile ("fnclex");
168*975af797SJoseph Myers     __asm__ volatile ("fucom" : : "t" (ld_nan), "u" (ld_zero));
169*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
170*975af797SJoseph Myers     if ((sw & EXC) != 0) {
171*975af797SJoseph Myers         printf("FAIL: fucom nan\n");
172*975af797SJoseph Myers         ret = 1;
173*975af797SJoseph Myers     }
174*975af797SJoseph Myers     __asm__ volatile ("fnclex");
175*975af797SJoseph Myers     __asm__ volatile ("fucom" : : "t" (ld_snan), "u" (ld_zero));
176*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
177*975af797SJoseph Myers     if ((sw & EXC) != IE) {
178*975af797SJoseph Myers         printf("FAIL: fucom snan\n");
179*975af797SJoseph Myers         ret = 1;
180*975af797SJoseph Myers     }
181*975af797SJoseph Myers     __asm__ volatile ("fnclex");
182*975af797SJoseph Myers     __asm__ volatile ("fucom" : : "t" (1.0L), "u" (ld_invalid_1.ld));
183*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
184*975af797SJoseph Myers     if ((sw & EXC) != IE) {
185*975af797SJoseph Myers         printf("FAIL: fucom invalid\n");
186*975af797SJoseph Myers         ret = 1;
187*975af797SJoseph Myers     }
188*975af797SJoseph Myers 
189*975af797SJoseph Myers     __asm__ volatile ("fnclex");
190*975af797SJoseph Myers     ld_res = ld_max + ld_max;
191*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
192*975af797SJoseph Myers     if ((sw & EXC) != (OE | PE)) {
193*975af797SJoseph Myers         printf("FAIL: add overflow\n");
194*975af797SJoseph Myers         ret = 1;
195*975af797SJoseph Myers     }
196*975af797SJoseph Myers     __asm__ volatile ("fnclex");
197*975af797SJoseph Myers     ld_res = ld_max + ld_min;
198*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
199*975af797SJoseph Myers     if ((sw & EXC) != PE) {
200*975af797SJoseph Myers         printf("FAIL: add inexact\n");
201*975af797SJoseph Myers         ret = 1;
202*975af797SJoseph Myers     }
203*975af797SJoseph Myers     __asm__ volatile ("fnclex");
204*975af797SJoseph Myers     ld_res = ld_inf + ld_ninf;
205*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
206*975af797SJoseph Myers     if ((sw & EXC) != IE) {
207*975af797SJoseph Myers         printf("FAIL: add inf -inf\n");
208*975af797SJoseph Myers         ret = 1;
209*975af797SJoseph Myers     }
210*975af797SJoseph Myers     __asm__ volatile ("fnclex");
211*975af797SJoseph Myers     ld_res = ld_snan + ld_third;
212*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
213*975af797SJoseph Myers     if ((sw & EXC) != IE) {
214*975af797SJoseph Myers         printf("FAIL: add snan\n");
215*975af797SJoseph Myers         ret = 1;
216*975af797SJoseph Myers     }
217*975af797SJoseph Myers     __asm__ volatile ("fnclex");
218*975af797SJoseph Myers     ld_res = ld_third + ld_invalid_1.ld;
219*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
220*975af797SJoseph Myers     if ((sw & EXC) != IE) {
221*975af797SJoseph Myers         printf("FAIL: add invalid\n");
222*975af797SJoseph Myers         ret = 1;
223*975af797SJoseph Myers     }
224*975af797SJoseph Myers 
225*975af797SJoseph Myers     __asm__ volatile ("fnclex");
226*975af797SJoseph Myers     ld_res = ld_max - ld_nmax;
227*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
228*975af797SJoseph Myers     if ((sw & EXC) != (OE | PE)) {
229*975af797SJoseph Myers         printf("FAIL: sub overflow\n");
230*975af797SJoseph Myers         ret = 1;
231*975af797SJoseph Myers     }
232*975af797SJoseph Myers     __asm__ volatile ("fnclex");
233*975af797SJoseph Myers     ld_res = ld_max - ld_min;
234*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
235*975af797SJoseph Myers     if ((sw & EXC) != PE) {
236*975af797SJoseph Myers         printf("FAIL: sub inexact\n");
237*975af797SJoseph Myers         ret = 1;
238*975af797SJoseph Myers     }
239*975af797SJoseph Myers     __asm__ volatile ("fnclex");
240*975af797SJoseph Myers     ld_res = ld_inf - ld_inf;
241*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
242*975af797SJoseph Myers     if ((sw & EXC) != IE) {
243*975af797SJoseph Myers         printf("FAIL: sub inf inf\n");
244*975af797SJoseph Myers         ret = 1;
245*975af797SJoseph Myers     }
246*975af797SJoseph Myers     __asm__ volatile ("fnclex");
247*975af797SJoseph Myers     ld_res = ld_snan - ld_third;
248*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
249*975af797SJoseph Myers     if ((sw & EXC) != IE) {
250*975af797SJoseph Myers         printf("FAIL: sub snan\n");
251*975af797SJoseph Myers         ret = 1;
252*975af797SJoseph Myers     }
253*975af797SJoseph Myers     __asm__ volatile ("fnclex");
254*975af797SJoseph Myers     ld_res = ld_third - ld_invalid_1.ld;
255*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
256*975af797SJoseph Myers     if ((sw & EXC) != IE) {
257*975af797SJoseph Myers         printf("FAIL: sub invalid\n");
258*975af797SJoseph Myers         ret = 1;
259*975af797SJoseph Myers     }
260*975af797SJoseph Myers 
261*975af797SJoseph Myers     __asm__ volatile ("fnclex");
262*975af797SJoseph Myers     ld_res = ld_max * ld_max;
263*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
264*975af797SJoseph Myers     if ((sw & EXC) != (OE | PE)) {
265*975af797SJoseph Myers         printf("FAIL: mul overflow\n");
266*975af797SJoseph Myers         ret = 1;
267*975af797SJoseph Myers     }
268*975af797SJoseph Myers     __asm__ volatile ("fnclex");
269*975af797SJoseph Myers     ld_res = ld_third * ld_third;
270*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
271*975af797SJoseph Myers     if ((sw & EXC) != PE) {
272*975af797SJoseph Myers         printf("FAIL: mul inexact\n");
273*975af797SJoseph Myers         ret = 1;
274*975af797SJoseph Myers     }
275*975af797SJoseph Myers     __asm__ volatile ("fnclex");
276*975af797SJoseph Myers     ld_res = ld_min * ld_min;
277*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
278*975af797SJoseph Myers     if ((sw & EXC) != (UE | PE)) {
279*975af797SJoseph Myers         printf("FAIL: mul underflow\n");
280*975af797SJoseph Myers         ret = 1;
281*975af797SJoseph Myers     }
282*975af797SJoseph Myers     __asm__ volatile ("fnclex");
283*975af797SJoseph Myers     ld_res = ld_inf * ld_zero;
284*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
285*975af797SJoseph Myers     if ((sw & EXC) != IE) {
286*975af797SJoseph Myers         printf("FAIL: mul inf 0\n");
287*975af797SJoseph Myers         ret = 1;
288*975af797SJoseph Myers     }
289*975af797SJoseph Myers     __asm__ volatile ("fnclex");
290*975af797SJoseph Myers     ld_res = ld_snan * ld_third;
291*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
292*975af797SJoseph Myers     if ((sw & EXC) != IE) {
293*975af797SJoseph Myers         printf("FAIL: mul snan\n");
294*975af797SJoseph Myers         ret = 1;
295*975af797SJoseph Myers     }
296*975af797SJoseph Myers     __asm__ volatile ("fnclex");
297*975af797SJoseph Myers     ld_res = ld_third * ld_invalid_1.ld;
298*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
299*975af797SJoseph Myers     if ((sw & EXC) != IE) {
300*975af797SJoseph Myers         printf("FAIL: mul invalid\n");
301*975af797SJoseph Myers         ret = 1;
302*975af797SJoseph Myers     }
303*975af797SJoseph Myers 
304*975af797SJoseph Myers     __asm__ volatile ("fnclex");
305*975af797SJoseph Myers     ld_res = ld_max / ld_min;
306*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
307*975af797SJoseph Myers     if ((sw & EXC) != (OE | PE)) {
308*975af797SJoseph Myers         printf("FAIL: div overflow\n");
309*975af797SJoseph Myers         ret = 1;
310*975af797SJoseph Myers     }
311*975af797SJoseph Myers     __asm__ volatile ("fnclex");
312*975af797SJoseph Myers     ld_res = ld_one / ld_third;
313*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
314*975af797SJoseph Myers     if ((sw & EXC) != PE) {
315*975af797SJoseph Myers         printf("FAIL: div inexact\n");
316*975af797SJoseph Myers         ret = 1;
317*975af797SJoseph Myers     }
318*975af797SJoseph Myers     __asm__ volatile ("fnclex");
319*975af797SJoseph Myers     ld_res = ld_min / ld_max;
320*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
321*975af797SJoseph Myers     if ((sw & EXC) != (UE | PE)) {
322*975af797SJoseph Myers         printf("FAIL: div underflow\n");
323*975af797SJoseph Myers         ret = 1;
324*975af797SJoseph Myers     }
325*975af797SJoseph Myers     __asm__ volatile ("fnclex");
326*975af797SJoseph Myers     ld_res = ld_one / ld_zero;
327*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
328*975af797SJoseph Myers     if ((sw & EXC) != ZE) {
329*975af797SJoseph Myers         printf("FAIL: div 1 0\n");
330*975af797SJoseph Myers         ret = 1;
331*975af797SJoseph Myers     }
332*975af797SJoseph Myers     __asm__ volatile ("fnclex");
333*975af797SJoseph Myers     ld_res = ld_inf / ld_zero;
334*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
335*975af797SJoseph Myers     if ((sw & EXC) != 0) {
336*975af797SJoseph Myers         printf("FAIL: div inf 0\n");
337*975af797SJoseph Myers         ret = 1;
338*975af797SJoseph Myers     }
339*975af797SJoseph Myers     __asm__ volatile ("fnclex");
340*975af797SJoseph Myers     ld_res = ld_nan / ld_zero;
341*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
342*975af797SJoseph Myers     if ((sw & EXC) != 0) {
343*975af797SJoseph Myers         printf("FAIL: div nan 0\n");
344*975af797SJoseph Myers         ret = 1;
345*975af797SJoseph Myers     }
346*975af797SJoseph Myers     __asm__ volatile ("fnclex");
347*975af797SJoseph Myers     ld_res = ld_zero / ld_zero;
348*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
349*975af797SJoseph Myers     if ((sw & EXC) != IE) {
350*975af797SJoseph Myers         printf("FAIL: div 0 0\n");
351*975af797SJoseph Myers         ret = 1;
352*975af797SJoseph Myers     }
353*975af797SJoseph Myers     __asm__ volatile ("fnclex");
354*975af797SJoseph Myers     ld_res = ld_inf / ld_inf;
355*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
356*975af797SJoseph Myers     if ((sw & EXC) != IE) {
357*975af797SJoseph Myers         printf("FAIL: div inf inf\n");
358*975af797SJoseph Myers         ret = 1;
359*975af797SJoseph Myers     }
360*975af797SJoseph Myers     __asm__ volatile ("fnclex");
361*975af797SJoseph Myers     ld_res = ld_snan / ld_third;
362*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
363*975af797SJoseph Myers     if ((sw & EXC) != IE) {
364*975af797SJoseph Myers         printf("FAIL: div snan\n");
365*975af797SJoseph Myers         ret = 1;
366*975af797SJoseph Myers     }
367*975af797SJoseph Myers     __asm__ volatile ("fnclex");
368*975af797SJoseph Myers     ld_res = ld_third / ld_invalid_1.ld;
369*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
370*975af797SJoseph Myers     if ((sw & EXC) != IE) {
371*975af797SJoseph Myers         printf("FAIL: div invalid\n");
372*975af797SJoseph Myers         ret = 1;
373*975af797SJoseph Myers     }
374*975af797SJoseph Myers 
375*975af797SJoseph Myers     __asm__ volatile ("fnclex");
376*975af797SJoseph Myers     __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_max));
377*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
378*975af797SJoseph Myers     if ((sw & EXC) != PE) {
379*975af797SJoseph Myers         printf("FAIL: fsqrt inexact\n");
380*975af797SJoseph Myers         ret = 1;
381*975af797SJoseph Myers     }
382*975af797SJoseph Myers     __asm__ volatile ("fnclex");
383*975af797SJoseph Myers     __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_nmax));
384*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
385*975af797SJoseph Myers     if ((sw & EXC) != IE) {
386*975af797SJoseph Myers         printf("FAIL: fsqrt -max\n");
387*975af797SJoseph Myers         ret = 1;
388*975af797SJoseph Myers     }
389*975af797SJoseph Myers     __asm__ volatile ("fnclex");
390*975af797SJoseph Myers     __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_ninf));
391*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
392*975af797SJoseph Myers     if ((sw & EXC) != IE) {
393*975af797SJoseph Myers         printf("FAIL: fsqrt -inf\n");
394*975af797SJoseph Myers         ret = 1;
395*975af797SJoseph Myers     }
396*975af797SJoseph Myers     __asm__ volatile ("fnclex");
397*975af797SJoseph Myers     __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_snan));
398*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
399*975af797SJoseph Myers     if ((sw & EXC) != IE) {
400*975af797SJoseph Myers         printf("FAIL: fsqrt snan\n");
401*975af797SJoseph Myers         ret = 1;
402*975af797SJoseph Myers     }
403*975af797SJoseph Myers     __asm__ volatile ("fnclex");
404*975af797SJoseph Myers     __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_invalid_1.ld));
405*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
406*975af797SJoseph Myers     if ((sw & EXC) != IE) {
407*975af797SJoseph Myers         printf("FAIL: fsqrt invalid\n");
408*975af797SJoseph Myers         ret = 1;
409*975af797SJoseph Myers     }
410*975af797SJoseph Myers     __asm__ volatile ("fnclex");
411*975af797SJoseph Myers     __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (ld_nzero));
412*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
413*975af797SJoseph Myers     if ((sw & EXC) != 0) {
414*975af797SJoseph Myers         printf("FAIL: fsqrt -0\n");
415*975af797SJoseph Myers         ret = 1;
416*975af797SJoseph Myers     }
417*975af797SJoseph Myers     __asm__ volatile ("fnclex");
418*975af797SJoseph Myers     __asm__ volatile ("fsqrt" : "=t" (ld_res) : "0" (-__builtin_nanl("")));
419*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
420*975af797SJoseph Myers     if ((sw & EXC) != 0) {
421*975af797SJoseph Myers         printf("FAIL: fsqrt -nan\n");
422*975af797SJoseph Myers         ret = 1;
423*975af797SJoseph Myers     }
424*975af797SJoseph Myers 
425*975af797SJoseph Myers     __asm__ volatile ("fnclex");
426*975af797SJoseph Myers     __asm__ volatile ("fistp %0" : "=m" (res_16) : "t" (1.5L) : "st");
427*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
428*975af797SJoseph Myers     if ((sw & EXC) != PE) {
429*975af797SJoseph Myers         printf("FAIL: fistp inexact\n");
430*975af797SJoseph Myers         ret = 1;
431*975af797SJoseph Myers     }
432*975af797SJoseph Myers     __asm__ volatile ("fnclex");
433*975af797SJoseph Myers     __asm__ volatile ("fistp %0" : "=m" (res_16) : "t" (32767.5L) : "st");
434*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
435*975af797SJoseph Myers     if ((sw & EXC) != IE) {
436*975af797SJoseph Myers         printf("FAIL: fistp 32767.5\n");
437*975af797SJoseph Myers         ret = 1;
438*975af797SJoseph Myers     }
439*975af797SJoseph Myers     __asm__ volatile ("fnclex");
440*975af797SJoseph Myers     __asm__ volatile ("fistp %0" : "=m" (res_16) : "t" (-32768.51L) : "st");
441*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
442*975af797SJoseph Myers     if ((sw & EXC) != IE) {
443*975af797SJoseph Myers         printf("FAIL: fistp -32768.51\n");
444*975af797SJoseph Myers         ret = 1;
445*975af797SJoseph Myers     }
446*975af797SJoseph Myers     __asm__ volatile ("fnclex");
447*975af797SJoseph Myers     __asm__ volatile ("fistp %0" : "=m" (res_16) : "t" (ld_nan) : "st");
448*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
449*975af797SJoseph Myers     if ((sw & EXC) != IE) {
450*975af797SJoseph Myers         printf("FAIL: fistp nan\n");
451*975af797SJoseph Myers         ret = 1;
452*975af797SJoseph Myers     }
453*975af797SJoseph Myers     __asm__ volatile ("fnclex");
454*975af797SJoseph Myers     __asm__ volatile ("fistp %0" : "=m" (res_16) : "t" (ld_invalid_1.ld) :
455*975af797SJoseph Myers                       "st");
456*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
457*975af797SJoseph Myers     if ((sw & EXC) != IE) {
458*975af797SJoseph Myers         printf("FAIL: fistp invalid\n");
459*975af797SJoseph Myers         ret = 1;
460*975af797SJoseph Myers     }
461*975af797SJoseph Myers 
462*975af797SJoseph Myers     __asm__ volatile ("fnclex");
463*975af797SJoseph Myers     __asm__ volatile ("fistpl %0" : "=m" (res_32) : "t" (1.5L) : "st");
464*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
465*975af797SJoseph Myers     if ((sw & EXC) != PE) {
466*975af797SJoseph Myers         printf("FAIL: fistpl inexact\n");
467*975af797SJoseph Myers         ret = 1;
468*975af797SJoseph Myers     }
469*975af797SJoseph Myers     __asm__ volatile ("fnclex");
470*975af797SJoseph Myers     __asm__ volatile ("fistpl %0" : "=m" (res_32) : "t" (2147483647.5L) :
471*975af797SJoseph Myers                       "st");
472*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
473*975af797SJoseph Myers     if ((sw & EXC) != IE) {
474*975af797SJoseph Myers         printf("FAIL: fistpl 2147483647.5\n");
475*975af797SJoseph Myers         ret = 1;
476*975af797SJoseph Myers     }
477*975af797SJoseph Myers     __asm__ volatile ("fnclex");
478*975af797SJoseph Myers     __asm__ volatile ("fistpl %0" : "=m" (res_32) : "t" (-2147483648.51L) :
479*975af797SJoseph Myers                       "st");
480*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
481*975af797SJoseph Myers     if ((sw & EXC) != IE) {
482*975af797SJoseph Myers         printf("FAIL: fistpl -2147483648.51\n");
483*975af797SJoseph Myers         ret = 1;
484*975af797SJoseph Myers     }
485*975af797SJoseph Myers     __asm__ volatile ("fnclex");
486*975af797SJoseph Myers     __asm__ volatile ("fistpl %0" : "=m" (res_32) : "t" (ld_nan) : "st");
487*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
488*975af797SJoseph Myers     if ((sw & EXC) != IE) {
489*975af797SJoseph Myers         printf("FAIL: fistpl nan\n");
490*975af797SJoseph Myers         ret = 1;
491*975af797SJoseph Myers     }
492*975af797SJoseph Myers     __asm__ volatile ("fnclex");
493*975af797SJoseph Myers     __asm__ volatile ("fistpl %0" : "=m" (res_32) : "t" (ld_invalid_1.ld) :
494*975af797SJoseph Myers                       "st");
495*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
496*975af797SJoseph Myers     if ((sw & EXC) != IE) {
497*975af797SJoseph Myers         printf("FAIL: fistpl invalid\n");
498*975af797SJoseph Myers         ret = 1;
499*975af797SJoseph Myers     }
500*975af797SJoseph Myers 
501*975af797SJoseph Myers     __asm__ volatile ("fnclex");
502*975af797SJoseph Myers     __asm__ volatile ("fistpll %0" : "=m" (res_64) : "t" (1.5L) : "st");
503*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
504*975af797SJoseph Myers     if ((sw & EXC) != PE) {
505*975af797SJoseph Myers         printf("FAIL: fistpll inexact\n");
506*975af797SJoseph Myers         ret = 1;
507*975af797SJoseph Myers     }
508*975af797SJoseph Myers     __asm__ volatile ("fnclex");
509*975af797SJoseph Myers     __asm__ volatile ("fistpll %0" : "=m" (res_64) : "t" (0x1p63) :
510*975af797SJoseph Myers                       "st");
511*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
512*975af797SJoseph Myers     if ((sw & EXC) != IE) {
513*975af797SJoseph Myers         printf("FAIL: fistpll 0x1p63\n");
514*975af797SJoseph Myers         ret = 1;
515*975af797SJoseph Myers     }
516*975af797SJoseph Myers     __asm__ volatile ("fnclex");
517*975af797SJoseph Myers     __asm__ volatile ("fistpll %0" : "=m" (res_64) : "t" (-0x1.1p63L) :
518*975af797SJoseph Myers                       "st");
519*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
520*975af797SJoseph Myers     if ((sw & EXC) != IE) {
521*975af797SJoseph Myers         printf("FAIL: fistpll -0x1.1p63\n");
522*975af797SJoseph Myers         ret = 1;
523*975af797SJoseph Myers     }
524*975af797SJoseph Myers     __asm__ volatile ("fnclex");
525*975af797SJoseph Myers     __asm__ volatile ("fistpll %0" : "=m" (res_64) : "t" (ld_nan) : "st");
526*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
527*975af797SJoseph Myers     if ((sw & EXC) != IE) {
528*975af797SJoseph Myers         printf("FAIL: fistpll nan\n");
529*975af797SJoseph Myers         ret = 1;
530*975af797SJoseph Myers     }
531*975af797SJoseph Myers     __asm__ volatile ("fnclex");
532*975af797SJoseph Myers     __asm__ volatile ("fistpll %0" : "=m" (res_64) : "t" (ld_invalid_1.ld) :
533*975af797SJoseph Myers                       "st");
534*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
535*975af797SJoseph Myers     if ((sw & EXC) != IE) {
536*975af797SJoseph Myers         printf("FAIL: fistpll invalid\n");
537*975af797SJoseph Myers         ret = 1;
538*975af797SJoseph Myers     }
539*975af797SJoseph Myers 
540*975af797SJoseph Myers     __asm__ volatile ("fnclex");
541*975af797SJoseph Myers     __asm__ volatile ("fisttp %0" : "=m" (res_16) : "t" (1.5L) : "st");
542*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
543*975af797SJoseph Myers     if ((sw & EXC) != PE) {
544*975af797SJoseph Myers         printf("FAIL: fisttp inexact\n");
545*975af797SJoseph Myers         ret = 1;
546*975af797SJoseph Myers     }
547*975af797SJoseph Myers     __asm__ volatile ("fnclex");
548*975af797SJoseph Myers     __asm__ volatile ("fisttp %0" : "=m" (res_16) : "t" (32768.0L) : "st");
549*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
550*975af797SJoseph Myers     if ((sw & EXC) != IE) {
551*975af797SJoseph Myers         printf("FAIL: fisttp 32768\n");
552*975af797SJoseph Myers         ret = 1;
553*975af797SJoseph Myers     }
554*975af797SJoseph Myers     __asm__ volatile ("fnclex");
555*975af797SJoseph Myers     __asm__ volatile ("fisttp %0" : "=m" (res_16) : "t" (32768.5L) : "st");
556*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
557*975af797SJoseph Myers     if ((sw & EXC) != IE) {
558*975af797SJoseph Myers         printf("FAIL: fisttp 32768.5\n");
559*975af797SJoseph Myers         ret = 1;
560*975af797SJoseph Myers     }
561*975af797SJoseph Myers     __asm__ volatile ("fnclex");
562*975af797SJoseph Myers     __asm__ volatile ("fisttp %0" : "=m" (res_16) : "t" (-32769.0L) : "st");
563*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
564*975af797SJoseph Myers     if ((sw & EXC) != IE) {
565*975af797SJoseph Myers         printf("FAIL: fisttp -32769\n");
566*975af797SJoseph Myers         ret = 1;
567*975af797SJoseph Myers     }
568*975af797SJoseph Myers     __asm__ volatile ("fnclex");
569*975af797SJoseph Myers     __asm__ volatile ("fisttp %0" : "=m" (res_16) : "t" (-32769.5L) : "st");
570*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
571*975af797SJoseph Myers     if ((sw & EXC) != IE) {
572*975af797SJoseph Myers         printf("FAIL: fisttp -32769.5\n");
573*975af797SJoseph Myers         ret = 1;
574*975af797SJoseph Myers     }
575*975af797SJoseph Myers     __asm__ volatile ("fnclex");
576*975af797SJoseph Myers     __asm__ volatile ("fisttp %0" : "=m" (res_16) : "t" (ld_nan) : "st");
577*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
578*975af797SJoseph Myers     if ((sw & EXC) != IE) {
579*975af797SJoseph Myers         printf("FAIL: fisttp nan\n");
580*975af797SJoseph Myers         ret = 1;
581*975af797SJoseph Myers     }
582*975af797SJoseph Myers     __asm__ volatile ("fnclex");
583*975af797SJoseph Myers     __asm__ volatile ("fisttp %0" : "=m" (res_16) : "t" (ld_invalid_1.ld) :
584*975af797SJoseph Myers                       "st");
585*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
586*975af797SJoseph Myers     if ((sw & EXC) != IE) {
587*975af797SJoseph Myers         printf("FAIL: fisttp invalid\n");
588*975af797SJoseph Myers         ret = 1;
589*975af797SJoseph Myers     }
590*975af797SJoseph Myers 
591*975af797SJoseph Myers     __asm__ volatile ("fnclex");
592*975af797SJoseph Myers     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (1.5L) : "st");
593*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
594*975af797SJoseph Myers     if ((sw & EXC) != PE) {
595*975af797SJoseph Myers         printf("FAIL: fisttpl inexact\n");
596*975af797SJoseph Myers         ret = 1;
597*975af797SJoseph Myers     }
598*975af797SJoseph Myers     __asm__ volatile ("fnclex");
599*975af797SJoseph Myers     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (2147483648.0L) :
600*975af797SJoseph Myers                       "st");
601*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
602*975af797SJoseph Myers     if ((sw & EXC) != IE) {
603*975af797SJoseph Myers         printf("FAIL: fisttpl 2147483648\n");
604*975af797SJoseph Myers         ret = 1;
605*975af797SJoseph Myers     }
606*975af797SJoseph Myers     __asm__ volatile ("fnclex");
607*975af797SJoseph Myers     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (-2147483649.0L) :
608*975af797SJoseph Myers                       "st");
609*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
610*975af797SJoseph Myers     if ((sw & EXC) != IE) {
611*975af797SJoseph Myers         printf("FAIL: fisttpl -2147483649\n");
612*975af797SJoseph Myers         ret = 1;
613*975af797SJoseph Myers     }
614*975af797SJoseph Myers     __asm__ volatile ("fnclex");
615*975af797SJoseph Myers     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (ld_nan) : "st");
616*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
617*975af797SJoseph Myers     if ((sw & EXC) != IE) {
618*975af797SJoseph Myers         printf("FAIL: fisttpl nan\n");
619*975af797SJoseph Myers         ret = 1;
620*975af797SJoseph Myers     }
621*975af797SJoseph Myers     __asm__ volatile ("fnclex");
622*975af797SJoseph Myers     __asm__ volatile ("fisttpl %0" : "=m" (res_32) : "t" (ld_invalid_1.ld) :
623*975af797SJoseph Myers                       "st");
624*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
625*975af797SJoseph Myers     if ((sw & EXC) != IE) {
626*975af797SJoseph Myers         printf("FAIL: fisttpl invalid\n");
627*975af797SJoseph Myers         ret = 1;
628*975af797SJoseph Myers     }
629*975af797SJoseph Myers 
630*975af797SJoseph Myers     __asm__ volatile ("fnclex");
631*975af797SJoseph Myers     __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (1.5L) : "st");
632*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
633*975af797SJoseph Myers     if ((sw & EXC) != PE) {
634*975af797SJoseph Myers         printf("FAIL: fisttpll inexact\n");
635*975af797SJoseph Myers         ret = 1;
636*975af797SJoseph Myers     }
637*975af797SJoseph Myers     __asm__ volatile ("fnclex");
638*975af797SJoseph Myers     __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (0x1p63) :
639*975af797SJoseph Myers                       "st");
640*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
641*975af797SJoseph Myers     if ((sw & EXC) != IE) {
642*975af797SJoseph Myers         printf("FAIL: fisttpll 0x1p63\n");
643*975af797SJoseph Myers         ret = 1;
644*975af797SJoseph Myers     }
645*975af797SJoseph Myers     __asm__ volatile ("fnclex");
646*975af797SJoseph Myers     __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (-0x1.1p63L) :
647*975af797SJoseph Myers                       "st");
648*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
649*975af797SJoseph Myers     if ((sw & EXC) != IE) {
650*975af797SJoseph Myers         printf("FAIL: fisttpll -0x1.1p63\n");
651*975af797SJoseph Myers         ret = 1;
652*975af797SJoseph Myers     }
653*975af797SJoseph Myers     __asm__ volatile ("fnclex");
654*975af797SJoseph Myers     __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (ld_nan) : "st");
655*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
656*975af797SJoseph Myers     if ((sw & EXC) != IE) {
657*975af797SJoseph Myers         printf("FAIL: fisttpll nan\n");
658*975af797SJoseph Myers         ret = 1;
659*975af797SJoseph Myers     }
660*975af797SJoseph Myers     __asm__ volatile ("fnclex");
661*975af797SJoseph Myers     __asm__ volatile ("fisttpll %0" : "=m" (res_64) : "t" (ld_invalid_1.ld) :
662*975af797SJoseph Myers                       "st");
663*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
664*975af797SJoseph Myers     if ((sw & EXC) != IE) {
665*975af797SJoseph Myers         printf("FAIL: fisttpll invalid\n");
666*975af797SJoseph Myers         ret = 1;
667*975af797SJoseph Myers     }
668*975af797SJoseph Myers 
669*975af797SJoseph Myers     __asm__ volatile ("fnclex");
670*975af797SJoseph Myers     __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) :
671*975af797SJoseph Myers                       "0" (ld_zero));
672*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
673*975af797SJoseph Myers     if ((sw & EXC) != ZE) {
674*975af797SJoseph Myers         printf("FAIL: fxtract 0\n");
675*975af797SJoseph Myers         ret = 1;
676*975af797SJoseph Myers     }
677*975af797SJoseph Myers     __asm__ volatile ("fnclex");
678*975af797SJoseph Myers     __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) :
679*975af797SJoseph Myers                       "0" (ld_nzero));
680*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
681*975af797SJoseph Myers     if ((sw & EXC) != ZE) {
682*975af797SJoseph Myers         printf("FAIL: fxtract -0\n");
683*975af797SJoseph Myers         ret = 1;
684*975af797SJoseph Myers     }
685*975af797SJoseph Myers     __asm__ volatile ("fnclex");
686*975af797SJoseph Myers     __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) :
687*975af797SJoseph Myers                       "0" (ld_inf));
688*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
689*975af797SJoseph Myers     if ((sw & EXC) != 0) {
690*975af797SJoseph Myers         printf("FAIL: fxtract inf\n");
691*975af797SJoseph Myers         ret = 1;
692*975af797SJoseph Myers     }
693*975af797SJoseph Myers     __asm__ volatile ("fnclex");
694*975af797SJoseph Myers     __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) :
695*975af797SJoseph Myers                       "0" (ld_nan));
696*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
697*975af797SJoseph Myers     if ((sw & EXC) != 0) {
698*975af797SJoseph Myers         printf("FAIL: fxtract nan\n");
699*975af797SJoseph Myers         ret = 1;
700*975af797SJoseph Myers     }
701*975af797SJoseph Myers     __asm__ volatile ("fnclex");
702*975af797SJoseph Myers     __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) :
703*975af797SJoseph Myers                       "0" (ld_snan));
704*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
705*975af797SJoseph Myers     if ((sw & EXC) != IE) {
706*975af797SJoseph Myers         printf("FAIL: fxtract snan\n");
707*975af797SJoseph Myers         ret = 1;
708*975af797SJoseph Myers     }
709*975af797SJoseph Myers     __asm__ volatile ("fnclex");
710*975af797SJoseph Myers     __asm__ volatile ("fxtract" : "=t" (ld_res), "=u" (ld_res2) :
711*975af797SJoseph Myers                       "0" (ld_invalid_1.ld));
712*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
713*975af797SJoseph Myers     if ((sw & EXC) != IE) {
714*975af797SJoseph Myers         printf("FAIL: fxtract invalid\n");
715*975af797SJoseph Myers         ret = 1;
716*975af797SJoseph Myers     }
717*975af797SJoseph Myers 
718*975af797SJoseph Myers     __asm__ volatile ("fnclex");
719*975af797SJoseph Myers     __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_min), "u" (ld_max));
720*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
721*975af797SJoseph Myers     if ((sw & EXC) != (OE | PE)) {
722*975af797SJoseph Myers         printf("FAIL: fscale overflow\n");
723*975af797SJoseph Myers         ret = 1;
724*975af797SJoseph Myers     }
725*975af797SJoseph Myers     __asm__ volatile ("fnclex");
726*975af797SJoseph Myers     __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_max), "u" (ld_nmax));
727*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
728*975af797SJoseph Myers     if ((sw & EXC) != (UE | PE)) {
729*975af797SJoseph Myers         printf("FAIL: fscale underflow\n");
730*975af797SJoseph Myers         ret = 1;
731*975af797SJoseph Myers     }
732*975af797SJoseph Myers     __asm__ volatile ("fnclex");
733*975af797SJoseph Myers     __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_zero), "u" (ld_inf));
734*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
735*975af797SJoseph Myers     if ((sw & EXC) != IE) {
736*975af797SJoseph Myers         printf("FAIL: fscale 0 inf\n");
737*975af797SJoseph Myers         ret = 1;
738*975af797SJoseph Myers     }
739*975af797SJoseph Myers     __asm__ volatile ("fnclex");
740*975af797SJoseph Myers     __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_inf), "u" (ld_ninf));
741*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
742*975af797SJoseph Myers     if ((sw & EXC) != IE) {
743*975af797SJoseph Myers         printf("FAIL: fscale inf -inf\n");
744*975af797SJoseph Myers         ret = 1;
745*975af797SJoseph Myers     }
746*975af797SJoseph Myers     __asm__ volatile ("fnclex");
747*975af797SJoseph Myers     __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_one), "u" (ld_snan));
748*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
749*975af797SJoseph Myers     if ((sw & EXC) != IE) {
750*975af797SJoseph Myers         printf("FAIL: fscale 1 snan\n");
751*975af797SJoseph Myers         ret = 1;
752*975af797SJoseph Myers     }
753*975af797SJoseph Myers     __asm__ volatile ("fnclex");
754*975af797SJoseph Myers     __asm__ volatile ("fscale" : "=t" (ld_res) : "0" (ld_snan), "u" (ld_nan));
755*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
756*975af797SJoseph Myers     if ((sw & EXC) != IE) {
757*975af797SJoseph Myers         printf("FAIL: fscale snan nan\n");
758*975af797SJoseph Myers         ret = 1;
759*975af797SJoseph Myers     }
760*975af797SJoseph Myers     __asm__ volatile ("fnclex");
761*975af797SJoseph Myers     __asm__ volatile ("fscale" : "=t" (ld_res) :
762*975af797SJoseph Myers                       "0" (ld_invalid_1.ld), "u" (ld_one));
763*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
764*975af797SJoseph Myers     if ((sw & EXC) != IE) {
765*975af797SJoseph Myers         printf("FAIL: fscale invalid 1\n");
766*975af797SJoseph Myers         ret = 1;
767*975af797SJoseph Myers     }
768*975af797SJoseph Myers     __asm__ volatile ("fnclex");
769*975af797SJoseph Myers     __asm__ volatile ("fscale" : "=t" (ld_res) :
770*975af797SJoseph Myers                       "0" (ld_invalid_1.ld), "u" (ld_nan));
771*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
772*975af797SJoseph Myers     if ((sw & EXC) != IE) {
773*975af797SJoseph Myers         printf("FAIL: fscale invalid nan\n");
774*975af797SJoseph Myers         ret = 1;
775*975af797SJoseph Myers     }
776*975af797SJoseph Myers 
777*975af797SJoseph Myers     __asm__ volatile ("fnclex");
778*975af797SJoseph Myers     __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (1.5L) :
779*975af797SJoseph Myers                       "st");
780*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
781*975af797SJoseph Myers     if ((sw & EXC) != PE) {
782*975af797SJoseph Myers         printf("FAIL: fbstp 1.5\n");
783*975af797SJoseph Myers         ret = 1;
784*975af797SJoseph Myers     }
785*975af797SJoseph Myers     __asm__ volatile ("fnclex");
786*975af797SJoseph Myers     __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (999999999999999999.5L) :
787*975af797SJoseph Myers                       "st");
788*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
789*975af797SJoseph Myers     if ((sw & EXC) != IE) {
790*975af797SJoseph Myers         printf("FAIL: fbstp 999999999999999999.5\n");
791*975af797SJoseph Myers         ret = 1;
792*975af797SJoseph Myers     }
793*975af797SJoseph Myers     __asm__ volatile ("fnclex");
794*975af797SJoseph Myers     __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (-1000000000000000000.0L) :
795*975af797SJoseph Myers                       "st");
796*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
797*975af797SJoseph Myers     if ((sw & EXC) != IE) {
798*975af797SJoseph Myers         printf("FAIL: fbstp -1000000000000000000\n");
799*975af797SJoseph Myers         ret = 1;
800*975af797SJoseph Myers     }
801*975af797SJoseph Myers     __asm__ volatile ("fnclex");
802*975af797SJoseph Myers     __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_inf) : "st");
803*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
804*975af797SJoseph Myers     if ((sw & EXC) != IE) {
805*975af797SJoseph Myers         printf("FAIL: fbstp inf\n");
806*975af797SJoseph Myers         ret = 1;
807*975af797SJoseph Myers     }
808*975af797SJoseph Myers     __asm__ volatile ("fnclex");
809*975af797SJoseph Myers     __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_nan) : "st");
810*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
811*975af797SJoseph Myers     if ((sw & EXC) != IE) {
812*975af797SJoseph Myers         printf("FAIL: fbstp nan\n");
813*975af797SJoseph Myers         ret = 1;
814*975af797SJoseph Myers     }
815*975af797SJoseph Myers     __asm__ volatile ("fnclex");
816*975af797SJoseph Myers     __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_snan) : "st");
817*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
818*975af797SJoseph Myers     if ((sw & EXC) != IE) {
819*975af797SJoseph Myers         printf("FAIL: fbstp snan\n");
820*975af797SJoseph Myers         ret = 1;
821*975af797SJoseph Myers     }
822*975af797SJoseph Myers     __asm__ volatile ("fnclex");
823*975af797SJoseph Myers     __asm__ volatile ("fbstp %0" : "=m" (out) : "t" (ld_invalid_1.ld) : "st");
824*975af797SJoseph Myers     __asm__ volatile ("fnstsw" : "=a" (sw));
825*975af797SJoseph Myers     if ((sw & EXC) != IE) {
826*975af797SJoseph Myers         printf("FAIL: fbstp invalid\n");
827*975af797SJoseph Myers         ret = 1;
828*975af797SJoseph Myers     }
829*975af797SJoseph Myers 
830*975af797SJoseph Myers     return ret;
831*975af797SJoseph Myers }
832