xref: /openbmc/qemu/tests/tcg/i386/test-i386-fldcst.c (revision f0984d40)
1 /* Test instructions loading floating-point constants.  */
2 
3 #include <stdint.h>
4 #include <stdio.h>
5 
6 volatile long double ld_res;
7 
8 int main(void)
9 {
10     short cw;
11     int ret = 0;
12 
13     /* Round to nearest.  */
14     __asm__ volatile ("fnstcw %0" : "=m" (cw));
15     cw = (cw & ~0xc00) | 0x000;
16     __asm__ volatile ("fldcw %0" : : "m" (cw));
17     __asm__ volatile ("fldl2t" : "=t" (ld_res));
18     if (ld_res != 0x3.5269e12f346e2bf8p+0L) {
19         printf("FAIL: fldl2t N\n");
20         ret = 1;
21     }
22     /* Round downward.  */
23     __asm__ volatile ("fnstcw %0" : "=m" (cw));
24     cw = (cw & ~0xc00) | 0x400;
25     __asm__ volatile ("fldcw %0" : : "m" (cw));
26     __asm__ volatile ("fldl2t" : "=t" (ld_res));
27     if (ld_res != 0x3.5269e12f346e2bf8p+0L) {
28         printf("FAIL: fldl2t D\n");
29         ret = 1;
30     }
31     /* Round toward zero.  */
32     __asm__ volatile ("fnstcw %0" : "=m" (cw));
33     cw = (cw & ~0xc00) | 0xc00;
34     __asm__ volatile ("fldcw %0" : : "m" (cw));
35     __asm__ volatile ("fldl2t" : "=t" (ld_res));
36     if (ld_res != 0x3.5269e12f346e2bf8p+0L) {
37         printf("FAIL: fldl2t Z\n");
38         ret = 1;
39     }
40     /* Round upward.  */
41     __asm__ volatile ("fnstcw %0" : "=m" (cw));
42     cw = (cw & ~0xc00) | 0x800;
43     __asm__ volatile ("fldcw %0" : : "m" (cw));
44     __asm__ volatile ("fldl2t" : "=t" (ld_res));
45     if (ld_res != 0x3.5269e12f346e2bfcp+0L) {
46         printf("FAIL: fldl2t U\n");
47         ret = 1;
48     }
49 
50     /* Round to nearest.  */
51     __asm__ volatile ("fnstcw %0" : "=m" (cw));
52     cw = (cw & ~0xc00) | 0x000;
53     __asm__ volatile ("fldcw %0" : : "m" (cw));
54     __asm__ volatile ("fldl2e" : "=t" (ld_res));
55     if (ld_res != 0x1.71547652b82fe178p+0L) {
56         printf("FAIL: fldl2e N\n");
57         ret = 1;
58     }
59     /* Round downward.  */
60     __asm__ volatile ("fnstcw %0" : "=m" (cw));
61     cw = (cw & ~0xc00) | 0x400;
62     __asm__ volatile ("fldcw %0" : : "m" (cw));
63     __asm__ volatile ("fldl2e" : "=t" (ld_res));
64     if (ld_res != 0x1.71547652b82fe176p+0L) {
65         printf("FAIL: fldl2e D\n");
66         ret = 1;
67     }
68     /* Round toward zero.  */
69     __asm__ volatile ("fnstcw %0" : "=m" (cw));
70     cw = (cw & ~0xc00) | 0xc00;
71     __asm__ volatile ("fldcw %0" : : "m" (cw));
72     __asm__ volatile ("fldl2e" : "=t" (ld_res));
73     if (ld_res != 0x1.71547652b82fe176p+0L) {
74         printf("FAIL: fldl2e Z\n");
75         ret = 1;
76     }
77     /* Round upward.  */
78     __asm__ volatile ("fnstcw %0" : "=m" (cw));
79     cw = (cw & ~0xc00) | 0x800;
80     __asm__ volatile ("fldcw %0" : : "m" (cw));
81     __asm__ volatile ("fldl2e" : "=t" (ld_res));
82     if (ld_res != 0x1.71547652b82fe178p+0L) {
83         printf("FAIL: fldl2e U\n");
84         ret = 1;
85     }
86 
87     /* Round to nearest.  */
88     __asm__ volatile ("fnstcw %0" : "=m" (cw));
89     cw = (cw & ~0xc00) | 0x000;
90     __asm__ volatile ("fldcw %0" : : "m" (cw));
91     __asm__ volatile ("fldpi" : "=t" (ld_res));
92     if (ld_res != 0x3.243f6a8885a308d4p+0L) {
93         printf("FAIL: fldpi N\n");
94         ret = 1;
95     }
96     /* Round downward.  */
97     __asm__ volatile ("fnstcw %0" : "=m" (cw));
98     cw = (cw & ~0xc00) | 0x400;
99     __asm__ volatile ("fldcw %0" : : "m" (cw));
100     __asm__ volatile ("fldpi" : "=t" (ld_res));
101     if (ld_res != 0x3.243f6a8885a308dp+0L) {
102         printf("FAIL: fldpi D\n");
103         ret = 1;
104     }
105     /* Round toward zero.  */
106     __asm__ volatile ("fnstcw %0" : "=m" (cw));
107     cw = (cw & ~0xc00) | 0xc00;
108     __asm__ volatile ("fldcw %0" : : "m" (cw));
109     __asm__ volatile ("fldpi" : "=t" (ld_res));
110     if (ld_res != 0x3.243f6a8885a308dp+0L) {
111         printf("FAIL: fldpi Z\n");
112         ret = 1;
113     }
114     /* Round upward.  */
115     __asm__ volatile ("fnstcw %0" : "=m" (cw));
116     cw = (cw & ~0xc00) | 0x800;
117     __asm__ volatile ("fldcw %0" : : "m" (cw));
118     __asm__ volatile ("fldpi" : "=t" (ld_res));
119     if (ld_res != 0x3.243f6a8885a308d4p+0L) {
120         printf("FAIL: fldpi U\n");
121         ret = 1;
122     }
123 
124     /* Round to nearest.  */
125     __asm__ volatile ("fnstcw %0" : "=m" (cw));
126     cw = (cw & ~0xc00) | 0x000;
127     __asm__ volatile ("fldcw %0" : : "m" (cw));
128     __asm__ volatile ("fldlg2" : "=t" (ld_res));
129     if (ld_res != 0x4.d104d427de7fbcc8p-4L) {
130         printf("FAIL: fldlg2 N\n");
131         ret = 1;
132     }
133     /* Round downward.  */
134     __asm__ volatile ("fnstcw %0" : "=m" (cw));
135     cw = (cw & ~0xc00) | 0x400;
136     __asm__ volatile ("fldcw %0" : : "m" (cw));
137     __asm__ volatile ("fldlg2" : "=t" (ld_res));
138     if (ld_res != 0x4.d104d427de7fbccp-4L) {
139         printf("FAIL: fldlg2 D\n");
140         ret = 1;
141     }
142     /* Round toward zero.  */
143     __asm__ volatile ("fnstcw %0" : "=m" (cw));
144     cw = (cw & ~0xc00) | 0xc00;
145     __asm__ volatile ("fldcw %0" : : "m" (cw));
146     __asm__ volatile ("fldlg2" : "=t" (ld_res));
147     if (ld_res != 0x4.d104d427de7fbccp-4L) {
148         printf("FAIL: fldlg2 Z\n");
149         ret = 1;
150     }
151     /* Round upward.  */
152     __asm__ volatile ("fnstcw %0" : "=m" (cw));
153     cw = (cw & ~0xc00) | 0x800;
154     __asm__ volatile ("fldcw %0" : : "m" (cw));
155     __asm__ volatile ("fldlg2" : "=t" (ld_res));
156     if (ld_res != 0x4.d104d427de7fbcc8p-4L) {
157         printf("FAIL: fldlg2 U\n");
158         ret = 1;
159     }
160 
161     /* Round to nearest.  */
162     __asm__ volatile ("fnstcw %0" : "=m" (cw));
163     cw = (cw & ~0xc00) | 0x000;
164     __asm__ volatile ("fldcw %0" : : "m" (cw));
165     __asm__ volatile ("fldln2" : "=t" (ld_res));
166     if (ld_res != 0xb.17217f7d1cf79acp-4L) {
167         printf("FAIL: fldln2 N\n");
168         ret = 1;
169     }
170     /* Round downward.  */
171     __asm__ volatile ("fnstcw %0" : "=m" (cw));
172     cw = (cw & ~0xc00) | 0x400;
173     __asm__ volatile ("fldcw %0" : : "m" (cw));
174     __asm__ volatile ("fldln2" : "=t" (ld_res));
175     if (ld_res != 0xb.17217f7d1cf79abp-4L) {
176         printf("FAIL: fldln2 D\n");
177         ret = 1;
178     }
179     /* Round toward zero.  */
180     __asm__ volatile ("fnstcw %0" : "=m" (cw));
181     cw = (cw & ~0xc00) | 0xc00;
182     __asm__ volatile ("fldcw %0" : : "m" (cw));
183     __asm__ volatile ("fldln2" : "=t" (ld_res));
184     if (ld_res != 0xb.17217f7d1cf79abp-4L) {
185         printf("FAIL: fldln2 Z\n");
186         ret = 1;
187     }
188     /* Round upward.  */
189     __asm__ volatile ("fnstcw %0" : "=m" (cw));
190     cw = (cw & ~0xc00) | 0x800;
191     __asm__ volatile ("fldcw %0" : : "m" (cw));
192     __asm__ volatile ("fldln2" : "=t" (ld_res));
193     if (ld_res != 0xb.17217f7d1cf79acp-4L) {
194         printf("FAIL: fldln2 U\n");
195         ret = 1;
196     }
197 
198     return ret;
199 }
200