2 /* On amd64, to exercise x87, compile with
3 gcc4 -ffast-math -mfpmath=387 -mfancy-math-387
5 gcc4 really does generate all the sin cos tan stuff as
6 x87 insns inline. gcc 3.3 doesn't, which makes the test
7 pretty useless, but it should still pass. To be on the safe
8 side we need to link with -lm to handle the gcc 3.3 behaviour.
16 * Copyright (c) 2003 Fabrice Bellard
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, see <http://www.gnu.org/licenses/>.
39 /**********************************************/
41 void test_fops(double a
, double b
)
43 printf("a=%f b=%f a+b=%f\n", a
, b
, a
+ b
);
44 printf("a=%f b=%f a-b=%f\n", a
, b
, a
- b
);
45 printf("a=%f b=%f a*b=%f\n", a
, b
, a
* b
);
46 printf("a=%f b=%f a/b=%f\n", a
, b
, a
/ b
);
47 // requires fprem/fprem1 -- not done
48 //printf("a=%f b=%f fmod(a, b)=%f\n", a, b, fmod(a, b));
49 printf("a=%f sqrt(a)=%f\n", a
, sqrt(a
));
50 printf("a=%f sin(a)=%f\n", a
, sin(a
));
51 printf("a=%f cos(a)=%f\n", a
, cos(a
));
52 printf("a=%f tan(a)=%f\n", a
, tan(a
));
53 printf("a=%f log(a)=%f\n", a
, log(a
));
54 printf("a=%f exp(a)=%f\n", a
, exp(a
));
55 printf("a=%f b=%f atan2(a, b)=%f\n", a
, b
, atan2(a
, b
));
56 /* just to test some op combining */
57 printf("a=%f asin(sin(a))=%f\n", a
, asin(sin(a
)));
58 printf("a=%f acos(cos(a))=%f\n", a
, acos(cos(a
)));
59 printf("a=%f atan(tan(a))=%f\n", a
, atan(tan(a
)));
69 void test_fcmp(double a
, double b
)
71 printf("(%f<%f)=%d\n",
73 printf("(%f<=%f)=%d\n",
75 printf("(%f==%f)=%d\n",
77 printf("(%f>%f)=%d\n",
79 printf("(%f<=%f)=%d\n",
82 unsigned long long int eflags
;
83 /* test f(u)comi instruction */
89 printf("fcomi(%f %f)=%08llx\n", a
, b
, eflags
& (CC_Z
| CC_P
| CC_C
));
93 void test_fcvt(double a
)
106 printf("(float)%e = %e\n", a
, fa
);
107 printf("(long double)%f = %Lf\n", a
, la
);
108 printf("a=%016llx\n", *(long long *)&a
);
109 printf("la=%016llx %04x\n", *(long long *)&la
,
110 *(unsigned short *)((char *)(&la
) + 8));
112 /* test all roundings */
113 asm volatile ("fstcw %0" : "=m" (fpuc
));
115 int16_t tmp
= (fpuc
& ~0x0c00) | (i
<< 10);
116 asm volatile ("fldcw %0" : : "m" (tmp
));
117 wa
=0;//asm volatile ("fist %0" : "=m" (wa) : "t" (a));
118 asm volatile ("fistl %0" : "=m" (ia
) : "t" (a
));
119 asm volatile ("fistpll %0" : "=m" (lla
) : "t" (a
) : "st");
120 asm volatile ("frndint ; fstl %0" : "=m" (ra
) : "t" (a
));
121 asm volatile ("fldcw %0" : : "m" (fpuc
));
122 printf("(short)a = %d\n", wa
);
123 printf("(int)a = %d\n", ia
);
124 printf("(int64_t)a = %lld\n", (long long int)lla
);
125 printf("rint(a) = %f\n", ra
);
130 asm("fld" #N : "=t" (a)); \
131 printf("fld" #N "= %f\n", a);
133 void test_fconst(void)
145 void test_fbcd(double a
)
147 unsigned short bcd
[5];
150 asm("fbstp %0" : "=m" (bcd
[0]) : "t" (a
) : "st");
151 asm("fbld %1" : "=t" (b
) : "m" (bcd
[0]));
152 printf("a=%f bcd=%04x%04x%04x%04x%04x b=%f\n",
153 a
, bcd
[4], bcd
[3], bcd
[2], bcd
[1], bcd
[0], b
);
156 #define TEST_ENV(env, save, restore)\
158 memset((env), 0xaa, sizeof(*(env)));\
160 asm volatile ("fldl %0" : : "m" (dtab[i]));\
161 asm(save " %0\n" : : "m" (*(env)));\
162 asm(restore " %0\n": : "m" (*(env)));\
164 asm volatile ("fstpl %0" : "=m" (rtab[i]));\
166 printf("res[%d]=%f\n", i, rtab[i]);\
167 printf("fpuc=%04x fpus=%04x fptag=%04x\n",\
169 (env)->fpus & 0xff00,\
175 struct __attribute__((packed
)) {
183 long double fpregs
[8];
185 struct __attribute__((packed
)) {
190 long double fpregs
[8];
199 TEST_ENV(&float_env16
, "data16 fnstenv", "data16 fldenv");
200 TEST_ENV(&float_env16
, "data16 fnsave", "data16 frstor");
201 TEST_ENV(&float_env32
, "fnstenv", "fldenv");
202 TEST_ENV(&float_env32
, "fnsave", "frstor");
206 asm volatile ("fldl %0" : : "m" (dtab
[i
]));
207 asm volatile("ffree %st(2)");
208 asm volatile ("fnstenv %0\n" : : "m" (float_env32
));
209 asm volatile ("fninit");
210 printf("fptag=%04x\n", float_env32
.fptag
);
214 #define TEST_FCMOV(a, b, eflags, CC)\
219 "fcmov" CC " %2, %0\n"\
221 : "0" (a), "u" (b), "g" ((long long int)eflags));\
222 printf("fcmov%s eflags=0x%04llx-> %f\n", \
223 CC, (long long int)eflags, res);\
226 void test_fcmov(void)
229 long long int eflags
, i
;
233 for(i
= 0; i
< 4; i
++) {
239 TEST_FCMOV(a
, b
, eflags
, "b");
240 TEST_FCMOV(a
, b
, eflags
, "e");
241 TEST_FCMOV(a
, b
, eflags
, "be");
242 TEST_FCMOV(a
, b
, eflags
, "nb");
243 TEST_FCMOV(a
, b
, eflags
, "ne");
244 TEST_FCMOV(a
, b
, eflags
, "nbe");
246 TEST_FCMOV(a
, b
, 0, "u");
247 TEST_FCMOV(a
, b
, CC_P
, "u");
248 TEST_FCMOV(a
, b
, 0, "nu");
249 TEST_FCMOV(a
, b
, CC_P
, "nu");
252 void test_floats(void)