|
From: <sv...@va...> - 2006-02-06 04:50:05
|
Author: sewardj
Date: 2006-02-06 04:49:58 +0000 (Mon, 06 Feb 2006)
New Revision: 5613
Log:
Test program aimed at exercising x87 insns a bit on amd64.
Added:
trunk/memcheck/tests/amd64/more_x87_fp.c
trunk/memcheck/tests/amd64/more_x87_fp.stderr.exp
trunk/memcheck/tests/amd64/more_x87_fp.stdout.exp
trunk/memcheck/tests/amd64/more_x87_fp.vgtest
Modified:
trunk/memcheck/tests/amd64/Makefile.am
Modified: trunk/memcheck/tests/amd64/Makefile.am
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/amd64/Makefile.am 2006-02-06 04:20:51 UTC (rev 5=
612)
+++ trunk/memcheck/tests/amd64/Makefile.am 2006-02-06 04:49:58 UTC (rev 5=
613)
@@ -8,11 +8,16 @@
$(addsuffix .stderr.exp,$(INSN_TESTS)) \
$(addsuffix .stdout.exp,$(INSN_TESTS)) \
$(addsuffix .vgtest,$(INSN_TESTS)) \
+ more_x87_fp.stderr.exp more_x87_fp.stdout.exp more_x87_fp.vgtest \
sse_memory.stderr.exp sse_memory.stdout.exp sse_memory.vgtest
=20
-check_PROGRAMS =3D sse_memory
+check_PROGRAMS =3D more_x87_fp sse_memory
=20
AM_CPPFLAGS =3D -I$(top_srcdir)/include
AM_CFLAGS =3D $(WERROR) -Winline -Wall -Wshadow -g -I$(top_srcdir)/inc=
lude
@FLAG_M64@
AM_CXXFLAGS =3D $(AM_CFLAGS)
+
+more_x87_fp_CFLAGS =3D $(AM_CFLAGS) -O -ffast-math -mfpmath=3D387 \
+ -mfancy-math-387
+more_x87_fp_LDADD =3D -lm
Added: trunk/memcheck/tests/amd64/more_x87_fp.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/amd64/more_x87_fp.c (rev=
0)
+++ trunk/memcheck/tests/amd64/more_x87_fp.c 2006-02-06 04:49:58 UTC (rev=
5613)
@@ -0,0 +1,273 @@
+
+/* On amd64, to exercise x87, compile with=20
+ gcc4 -ffast-math -mfpmath=3D387 -mfancy-math-387
+
+ gcc4 really does generate all the sin cos tan stuff as=20
+ x87 insns inline. gcc 3.3 doesn't, which makes the test
+ pretty useless, but it should still pass. To be on the safe
+ side we need to link with -lm to handle the gcc 3.3 behaviour.
+*/
+
+/* Derived from: */
+
+/*
+ * x86 CPU test
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+#include <math.h>
+
+/**********************************************/
+
+void test_fops(double a, double b)
+{
+ printf("a=3D%f b=3D%f a+b=3D%f\n", a, b, a + b);
+ printf("a=3D%f b=3D%f a-b=3D%f\n", a, b, a - b);
+ printf("a=3D%f b=3D%f a*b=3D%f\n", a, b, a * b);
+ printf("a=3D%f b=3D%f a/b=3D%f\n", a, b, a / b);
+ // requires fprem/fprem1 -- not done
+ //printf("a=3D%f b=3D%f fmod(a, b)=3D%f\n", a, b, fmod(a, b));
+ printf("a=3D%f sqrt(a)=3D%f\n", a, sqrt(a));
+ printf("a=3D%f sin(a)=3D%f\n", a, sin(a));
+ printf("a=3D%f cos(a)=3D%f\n", a, cos(a));
+ printf("a=3D%f tan(a)=3D%f\n", a, tan(a));
+ printf("a=3D%f log(a)=3D%f\n", a, log(a));
+ printf("a=3D%f exp(a)=3D%f\n", a, exp(a));
+ printf("a=3D%f b=3D%f atan2(a, b)=3D%f\n", a, b, atan2(a, b));
+ /* just to test some op combining */
+ printf("a=3D%f asin(sin(a))=3D%f\n", a, asin(sin(a)));
+ printf("a=3D%f acos(cos(a))=3D%f\n", a, acos(cos(a)));
+ printf("a=3D%f atan(tan(a))=3D%f\n", a, atan(tan(a)));
+}
+#define CC_C 0x0001
+#define CC_P 0x0004
+#define CC_A 0x0010
+#define CC_Z 0x0040
+#define CC_S 0x0080
+#define CC_O 0x0800
+
+
+void test_fcmp(double a, double b)
+{
+ printf("(%f<%f)=3D%d\n",
+ a, b, a < b);
+ printf("(%f<=3D%f)=3D%d\n",
+ a, b, a <=3D b);
+ printf("(%f=3D=3D%f)=3D%d\n",
+ a, b, a =3D=3D b);
+ printf("(%f>%f)=3D%d\n",
+ a, b, a > b);
+ printf("(%f<=3D%f)=3D%d\n",
+ a, b, a >=3D b);
+ {
+ unsigned long long int eflags;
+ /* test f(u)comi instruction */
+ asm("fcomi %2, %1\n"
+ "pushfq\n"
+ "popq %0\n"
+ : "=3Dr" (eflags)
+ : "t" (a), "u" (b));
+ printf("fcomi(%f %f)=3D%08llx\n", a, b, eflags & (CC_Z | CC_P | =
CC_C));
+ }
+}
+
+void test_fcvt(double a)
+{
+ float fa;
+ long double la;
+ int16_t fpuc;
+ int i;
+ int64_t lla;
+ int ia;
+ int16_t wa;
+ double ra;
+
+ fa =3D a;
+ la =3D a;
+ printf("(float)%e =3D %e\n", a, fa);
+ printf("(long double)%f =3D %Lf\n", a, la);
+ printf("a=3D%016Lx\n", *(long long *)&a);
+ printf("la=3D%016Lx %04x\n", *(long long *)&la,=20
+ *(unsigned short *)((char *)(&la) + 8));
+
+ /* test all roundings */
+ asm volatile ("fstcw %0" : "=3Dm" (fpuc));
+ for(i=3D0;i<4;i++) {
+ int16_t tmp =3D (fpuc & ~0x0c00) | (i << 10);
+ asm volatile ("fldcw %0" : : "m" (tmp));
+ wa=3D0;//asm volatile ("fist %0" : "=3Dm" (wa) : "t" (a));
+ asm volatile ("fistl %0" : "=3Dm" (ia) : "t" (a));
+ asm volatile ("fistpll %0" : "=3Dm" (lla) : "t" (a) : "st");
+ asm volatile ("frndint ; fstl %0" : "=3Dm" (ra) : "t" (a));
+ asm volatile ("fldcw %0" : : "m" (fpuc));
+ printf("(short)a =3D %d\n", wa);
+ printf("(int)a =3D %d\n", ia);
+ printf("(int64_t)a =3D %lld\n", (long long int)lla);
+ printf("rint(a) =3D %f\n", ra);
+ }
+}
+
+#define TEST(N) \
+ asm("fld" #N : "=3Dt" (a)); \
+ printf("fld" #N "=3D %f\n", a);
+
+void test_fconst(void)
+{
+ double a;
+ TEST(1);
+ TEST(l2t);
+ TEST(l2e);
+ TEST(pi);
+ TEST(lg2);
+ TEST(ln2);
+ TEST(z);
+}
+
+void test_fbcd(double a)
+{
+ unsigned short bcd[5];
+ double b;
+
+ asm("fbstp %0" : "=3Dm" (bcd[0]) : "t" (a) : "st");
+ asm("fbld %1" : "=3Dt" (b) : "m" (bcd[0]));
+ printf("a=3D%f bcd=3D%04x%04x%04x%04x%04x b=3D%f\n",=20
+ a, bcd[4], bcd[3], bcd[2], bcd[1], bcd[0], b);
+}
+
+#define TEST_ENV(env, save, restore)\
+{\
+ memset((env), 0xaa, sizeof(*(env)));\
+ for(i=3D0;i<5;i++)\
+ asm volatile ("fldl %0" : : "m" (dtab[i]));\
+ asm(save " %0\n" : : "m" (*(env)));\
+ asm(restore " %0\n": : "m" (*(env)));\
+ for(i=3D0;i<5;i++)\
+ asm volatile ("fstpl %0" : "=3Dm" (rtab[i]));\
+ for(i=3D0;i<5;i++)\
+ printf("res[%d]=3D%f\n", i, rtab[i]);\
+ printf("fpuc=3D%04x fpus=3D%04x fptag=3D%04x\n",\
+ (env)->fpuc,\
+ (env)->fpus & 0xff00,\
+ (env)->fptag);\
+}
+
+void test_fenv(void)
+{
+ struct __attribute__((packed)) {
+ uint16_t fpuc;
+ uint16_t dummy1;
+ uint16_t fpus;
+ uint16_t dummy2;
+ uint16_t fptag;
+ uint16_t dummy3;
+ uint32_t ignored[4];
+ long double fpregs[8];
+ } float_env32;
+ struct __attribute__((packed)) {
+ uint16_t fpuc;
+ uint16_t fpus;
+ uint16_t fptag;
+ uint16_t ignored[4];
+ long double fpregs[8];
+ } float_env16;
+ double dtab[8];
+ double rtab[8];
+ int i;
+
+ for(i=3D0;i<8;i++)
+ dtab[i] =3D i + 1;
+
+ TEST_ENV(&float_env16, "data16 fnstenv", "data16 fldenv");
+ TEST_ENV(&float_env16, "data16 fnsave", "data16 frstor");
+ TEST_ENV(&float_env32, "fnstenv", "fldenv");
+ TEST_ENV(&float_env32, "fnsave", "frstor");
+
+ /* test for ffree */
+ for(i=3D0;i<5;i++)
+ asm volatile ("fldl %0" : : "m" (dtab[i]));
+ asm volatile("ffree %st(2)");
+ asm volatile ("fnstenv %0\n" : : "m" (float_env32));
+ asm volatile ("fninit");
+ printf("fptag=3D%04x\n", float_env32.fptag);
+}
+
+
+#define TEST_FCMOV(a, b, eflags, CC)\
+{\
+ double res;\
+ asm("pushq %3\n"\
+ "popfq\n"\
+ "fcmov" CC " %2, %0\n"\
+ : "=3Dt" (res)\
+ : "0" (a), "u" (b), "g" ((long long int)eflags));\
+ printf("fcmov%s eflags=3D0x%04llx-> %f\n", \
+ CC, (long long int)eflags, res);\
+}
+
+void test_fcmov(void)
+{
+ double a, b;
+ long long int eflags, i;
+
+ a =3D 1.0;
+ b =3D 2.0;
+ for(i =3D 0; i < 4; i++) {
+ eflags =3D 0;
+ if (i & 1)
+ eflags |=3D CC_C;
+ if (i & 2)
+ eflags |=3D CC_Z;
+ TEST_FCMOV(a, b, eflags, "b");
+ TEST_FCMOV(a, b, eflags, "e");
+ TEST_FCMOV(a, b, eflags, "be");
+ TEST_FCMOV(a, b, eflags, "nb");
+ TEST_FCMOV(a, b, eflags, "ne");
+ TEST_FCMOV(a, b, eflags, "nbe");
+ }
+ TEST_FCMOV(a, b, 0, "u");
+ TEST_FCMOV(a, b, CC_P, "u");
+ TEST_FCMOV(a, b, 0, "nu");
+ TEST_FCMOV(a, b, CC_P, "nu");
+}
+
+void test_floats(void)
+{
+ test_fops(2, 3);
+ test_fops(1.4, -5);
+ test_fcmp(2, -1);
+ test_fcmp(2, 2);
+ test_fcmp(2, 3);
+ test_fcvt(0.5);
+ test_fcvt(-0.5);
+ test_fcvt(1.0/7.0);
+ test_fcvt(-1.0/9.0);
+ test_fcvt(32768);
+ test_fcvt(-1e20);
+ test_fconst();
+}
+
+int main ( void )
+{
+ test_floats();
+ return 0;
+}
Added: trunk/memcheck/tests/amd64/more_x87_fp.stderr.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
Added: trunk/memcheck/tests/amd64/more_x87_fp.stdout.exp
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/amd64/more_x87_fp.stdout.exp =
(rev 0)
+++ trunk/memcheck/tests/amd64/more_x87_fp.stdout.exp 2006-02-06 04:49:58=
UTC (rev 5613)
@@ -0,0 +1,173 @@
+a=3D2.000000 b=3D3.000000 a+b=3D5.000000
+a=3D2.000000 b=3D3.000000 a-b=3D-1.000000
+a=3D2.000000 b=3D3.000000 a*b=3D6.000000
+a=3D2.000000 b=3D3.000000 a/b=3D0.666667
+a=3D2.000000 sqrt(a)=3D1.414214
+a=3D2.000000 sin(a)=3D0.909297
+a=3D2.000000 cos(a)=3D-0.416147
+a=3D2.000000 tan(a)=3D-2.185040
+a=3D2.000000 log(a)=3D0.693147
+a=3D2.000000 exp(a)=3D7.389056
+a=3D2.000000 b=3D3.000000 atan2(a, b)=3D0.588003
+a=3D2.000000 asin(sin(a))=3D1.141593
+a=3D2.000000 acos(cos(a))=3D2.000000
+a=3D2.000000 atan(tan(a))=3D-1.141593
+a=3D1.400000 b=3D-5.000000 a+b=3D-3.600000
+a=3D1.400000 b=3D-5.000000 a-b=3D6.400000
+a=3D1.400000 b=3D-5.000000 a*b=3D-7.000000
+a=3D1.400000 b=3D-5.000000 a/b=3D-0.280000
+a=3D1.400000 sqrt(a)=3D1.183216
+a=3D1.400000 sin(a)=3D0.985450
+a=3D1.400000 cos(a)=3D0.169967
+a=3D1.400000 tan(a)=3D5.797884
+a=3D1.400000 log(a)=3D0.336472
+a=3D1.400000 exp(a)=3D4.055200
+a=3D1.400000 b=3D-5.000000 atan2(a, b)=3D2.868584
+a=3D1.400000 asin(sin(a))=3D1.400000
+a=3D1.400000 acos(cos(a))=3D1.400000
+a=3D1.400000 atan(tan(a))=3D1.400000
+(2.000000<-1.000000)=3D0
+(2.000000<=3D-1.000000)=3D0
+(2.000000=3D=3D-1.000000)=3D0
+(2.000000>-1.000000)=3D1
+(2.000000<=3D-1.000000)=3D1
+fcomi(2.000000 -1.000000)=3D00000000
+(2.000000<2.000000)=3D0
+(2.000000<=3D2.000000)=3D1
+(2.000000=3D=3D2.000000)=3D1
+(2.000000>2.000000)=3D0
+(2.000000<=3D2.000000)=3D1
+fcomi(2.000000 2.000000)=3D00000040
+(2.000000<3.000000)=3D1
+(2.000000<=3D3.000000)=3D1
+(2.000000=3D=3D3.000000)=3D0
+(2.000000>3.000000)=3D0
+(2.000000<=3D3.000000)=3D0
+fcomi(2.000000 3.000000)=3D00000001
+(float)5.000000e-01 =3D 5.000000e-01
+(long double)0.500000 =3D 0.500000
+a=3D3fe0000000000000
+la=3D8000000000000000 3ffe
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D 0.000000
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D 0.000000
+(short)a =3D 0
+(int)a =3D 1
+(int64_t)a =3D 1
+rint(a) =3D 1.000000
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D 0.000000
+(float)-5.000000e-01 =3D -5.000000e-01
+(long double)-0.500000 =3D -0.500000
+a=3Dbfe0000000000000
+la=3D8000000000000000 bffe
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D -0.000000
+(short)a =3D 0
+(int)a =3D -1
+(int64_t)a =3D -1
+rint(a) =3D -1.000000
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D -0.000000
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D -0.000000
+(float)1.428571e-01 =3D 1.428571e-01
+(long double)0.142857 =3D 0.142857
+a=3D3fc2492492492492
+la=3D9249249249249000 3ffc
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D 0.000000
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D 0.000000
+(short)a =3D 0
+(int)a =3D 1
+(int64_t)a =3D 1
+rint(a) =3D 1.000000
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D 0.000000
+(float)-1.111111e-01 =3D -1.111111e-01
+(long double)-0.111111 =3D -0.111111
+a=3Dbfbc71c71c71c71c
+la=3De38e38e38e38e000 bffb
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D -0.000000
+(short)a =3D 0
+(int)a =3D -1
+(int64_t)a =3D -1
+rint(a) =3D -1.000000
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D -0.000000
+(short)a =3D 0
+(int)a =3D 0
+(int64_t)a =3D 0
+rint(a) =3D -0.000000
+(float)3.276800e+04 =3D 3.276800e+04
+(long double)32768.000000 =3D 32768.000000
+a=3D40e0000000000000
+la=3D8000000000000000 400e
+(short)a =3D 0
+(int)a =3D 32768
+(int64_t)a =3D 32768
+rint(a) =3D 32768.000000
+(short)a =3D 0
+(int)a =3D 32768
+(int64_t)a =3D 32768
+rint(a) =3D 32768.000000
+(short)a =3D 0
+(int)a =3D 32768
+(int64_t)a =3D 32768
+rint(a) =3D 32768.000000
+(short)a =3D 0
+(int)a =3D 32768
+(int64_t)a =3D 32768
+rint(a) =3D 32768.000000
+(float)-1.000000e+20 =3D -1.000000e+20
+(long double)-100000000000000000000.000000 =3D -100000000000000000000.00=
0000
+a=3Dc415af1d78b58c40
+la=3Dad78ebc5ac620000 c041
+(short)a =3D 0
+(int)a =3D -2147483648
+(int64_t)a =3D -9223372036854775808
+rint(a) =3D -100000000000000000000.000000
+(short)a =3D 0
+(int)a =3D -2147483648
+(int64_t)a =3D -9223372036854775808
+rint(a) =3D -100000000000000000000.000000
+(short)a =3D 0
+(int)a =3D -2147483648
+(int64_t)a =3D -9223372036854775808
+rint(a) =3D -100000000000000000000.000000
+(short)a =3D 0
+(int)a =3D -2147483648
+(int64_t)a =3D -9223372036854775808
+rint(a) =3D -100000000000000000000.000000
+fld1=3D 1.000000
+fldl2t=3D 3.321928
+fldl2e=3D 1.442695
+fldpi=3D 3.141593
+fldlg2=3D 0.301030
+fldln2=3D 0.693147
+fldz=3D 0.000000
Added: trunk/memcheck/tests/amd64/more_x87_fp.vgtest
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/memcheck/tests/amd64/more_x87_fp.vgtest =
(rev 0)
+++ trunk/memcheck/tests/amd64/more_x87_fp.vgtest 2006-02-06 04:49:58 UTC=
(rev 5613)
@@ -0,0 +1,2 @@
+prog: more_x87_fp
+vgopts: -q
|