7 * Copyright (c) 2003 Fabrice Bellard
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 /**********************************************/
33 void test_fops(double a, double b)
35 printf("a=%f b=%f a+b=%f\n", a, b, a + b);
36 printf("a=%f b=%f a-b=%f\n", a, b, a - b);
37 printf("a=%f b=%f a*b=%f\n", a, b, a * b);
38 printf("a=%f b=%f a/b=%f\n", a, b, a / b);
39 printf("a=%f b=%f fmod(a, b)=%f\n", a, b, fmod(a, b));
40 printf("a=%f sqrt(a)=%f\n", a, sqrt(a));
41 printf("a=%f sin(a)=%f\n", a, sin(a));
42 printf("a=%f cos(a)=%f\n", a, cos(a));
43 printf("a=%f tan(a)=%f\n", a, tan(a));
44 printf("a=%f log(a)=%f\n", a, log(a));
45 printf("a=%f exp(a)=%f\n", a, exp(a));
46 printf("a=%f b=%f atan2(a, b)=%f\n", a, b, atan2(a, b));
47 /* just to test some op combining */
48 printf("a=%f asin(sin(a))=%f\n", a, asin(sin(a)));
49 printf("a=%f acos(cos(a))=%f\n", a, acos(cos(a)));
50 printf("a=%f atan(tan(a))=%f\n", a, atan(tan(a)));
60 void test_fcmp(double a, double b)
62 printf("(%f<%f)=%d\n",
64 printf("(%f<=%f)=%d\n",
66 printf("(%f==%f)=%d\n",
68 printf("(%f>%f)=%d\n",
70 printf("(%f<=%f)=%d\n",
74 /* test f(u)comi instruction */
80 printf("fcomi(%f %f)=%08x\n", a, b, eflags & (CC_Z | CC_P | CC_C));
84 void test_fcvt(double a)
97 printf("(float)%f = %f\n", a, fa);
98 printf("(long double)%f = %Lf\n", a, la);
99 printf("a=%016llx\n", *(long long *)&a);
100 printf("la=%016llx %04x\n", *(long long *)&la,
101 *(unsigned short *)((char *)(&la) + 8));
103 /* test all roundings */
104 asm volatile ("fstcw %0" : "=m" (fpuc));
106 int16_t tmp = (fpuc & ~0x0c00) | (i << 10);
107 asm volatile ("fldcw %0" : : "m" (tmp));
108 asm volatile ("fist %0" : "=m" (wa) : "t" (a));
109 asm volatile ("fistl %0" : "=m" (ia) : "t" (a));
110 asm volatile ("fistpll %0" : "=m" (lla) : "t" (a) : "st");
111 asm volatile ("frndint ; fstl %0" : "=m" (ra) : "t" (a));
112 asm volatile ("fldcw %0" : : "m" (fpuc));
113 printf("(short)a = %d\n", wa);
114 printf("(int)a = %d\n", ia);
115 printf("(int64_t)a = %lld\n", lla);
116 printf("rint(a) = %f\n", ra);
121 asm("fld" #N : "=t" (a)); \
122 printf("fld" #N "= %f\n", a);
124 void test_fconst(void)
136 void test_fbcd(double a)
138 unsigned short bcd[5];
141 asm("fbstp %0" : "=m" (bcd[0]) : "t" (a) : "st");
142 asm("fbld %1" : "=t" (b) : "m" (bcd[0]));
143 printf("a=%f bcd=%04x%04x%04x%04x%04x b=%f\n",
144 a, bcd[4], bcd[3], bcd[2], bcd[1], bcd[0], b);
147 #define TEST_ENV(env, save, restore)\
149 memset((env), 0xaa, sizeof(*(env)));\
151 asm volatile ("fldl %0" : : "m" (dtab[i]));\
152 asm(save " %0\n" : : "m" (*(env)));\
153 asm(restore " %0\n": : "m" (*(env)));\
155 asm volatile ("fstpl %0" : "=m" (rtab[i]));\
157 printf("res[%d]=%f\n", i, rtab[i]);\
158 printf("fpuc=%04x fpus=%04x fptag=%04x\n",\
160 (env)->fpus & 0xff00,\
166 struct __attribute__((packed)) {
174 long double fpregs[8];
176 struct __attribute__((packed)) {
181 long double fpregs[8];
190 TEST_ENV(&float_env16, "data16/fnstenv", "data16/fldenv");
191 TEST_ENV(&float_env16, "data16/fnsave", "data16/frstor");
192 TEST_ENV(&float_env32, "fnstenv", "fldenv");
193 TEST_ENV(&float_env32, "fnsave", "frstor");
197 asm volatile ("fldl %0" : : "m" (dtab[i]));
198 asm volatile("ffree %st(2)");
199 asm volatile ("fnstenv %0\n" : : "m" (float_env32));
200 asm volatile ("fninit");
201 printf("fptag=%04x\n", float_env32.fptag);
205 #define TEST_FCMOV(a, b, eflags, CC)\
210 "fcmov" CC " %2, %0\n"\
212 : "0" (a), "u" (b), "g" (eflags));\
213 printf("fcmov%s eflags=0x%04x-> %f\n", \
217 void test_fcmov(void)
224 for(i = 0; i < 4; i++) {
230 TEST_FCMOV(a, b, eflags, "b");
231 TEST_FCMOV(a, b, eflags, "e");
232 TEST_FCMOV(a, b, eflags, "be");
233 TEST_FCMOV(a, b, eflags, "nb");
234 TEST_FCMOV(a, b, eflags, "ne");
235 TEST_FCMOV(a, b, eflags, "nbe");
237 TEST_FCMOV(a, b, 0, "u");
238 TEST_FCMOV(a, b, CC_P, "u");
239 TEST_FCMOV(a, b, 0, "nu");
240 TEST_FCMOV(a, b, CC_P, "nu");
243 void test_floats(void)