]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
mips32/64: Test case for VEX r2799.
authorDejan Jevtic <dejan.jevtic@valgrind.org>
Thu, 14 Nov 2013 15:45:26 +0000 (15:45 +0000)
committerDejan Jevtic <dejan.jevtic@valgrind.org>
Thu, 14 Nov 2013 15:45:26 +0000 (15:45 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13713

none/tests/mips32/Makefile.am
none/tests/mips32/test_math.cpp [new file with mode: 0644]
none/tests/mips32/test_math.stderr.exp [new file with mode: 0644]
none/tests/mips32/test_math.stdout.exp [new file with mode: 0644]
none/tests/mips32/test_math.vgtest [new file with mode: 0644]
none/tests/mips64/Makefile.am
none/tests/mips64/test_math.cpp [new symlink]
none/tests/mips64/test_math.stderr.exp [new file with mode: 0644]
none/tests/mips64/test_math.stdout.exp [new file with mode: 0644]
none/tests/mips64/test_math.vgtest [new symlink]

index 5aa4ea7e2dc78c47f9fea5a04a15e6297e7d7509..751403438803f569e46c8439b2111f25383a7d35 100644 (file)
@@ -30,7 +30,8 @@ EXTRA_DIST = \
        mips32_dspr2.vgtest \
        unaligned_load_store.stdout.exp-LE unaligned_load_store.stdout.exp-BE \
        unaligned_load_store.stderr.exp unaligned_load_store.vgtest \
-       test_fcsr.stdout.exp test_fcsr.stderr.exp test_fcsr.vgtest
+       test_fcsr.stdout.exp test_fcsr.stderr.exp test_fcsr.vgtest \
+       test_math.stdout.exp test_math.stderr.exp test_math.vgtest
 
 check_PROGRAMS = \
        allexec \
@@ -49,7 +50,8 @@ check_PROGRAMS = \
        mips32_dsp \
        mips32_dspr2 \
        unaligned_load_store \
-       test_fcsr
+       test_fcsr \
+       test_math
 
 AM_CFLAGS    += @FLAG_M32@
 AM_CXXFLAGS  += @FLAG_M32@
@@ -57,3 +59,6 @@ AM_CCASFLAGS += @FLAG_M32@
 
 allexec_CFLAGS          = $(AM_CFLAGS) @FLAG_W_NO_NONNULL@
 bug320057_mips32_LDFLAGS = -lrt
+
+# C++ tests
+test_math_SOURCES          = test_math.cpp
diff --git a/none/tests/mips32/test_math.cpp b/none/tests/mips32/test_math.cpp
new file mode 100644 (file)
index 0000000..8a0f2dc
--- /dev/null
@@ -0,0 +1,115 @@
+#include <fenv.h>
+#include <limits.h>
+#include <math.h>
+#include <stdint.h>
+#include <stdio.h>
+
+static void DivideByZero() {
+  // volatile to prevent compiler optimizations.
+  volatile float zero = 0.0f;
+  volatile float result __attribute__((unused)) = 123.0f / zero;
+}
+
+int main () {
+   /* Testing lrint. */
+   fesetround(FE_UPWARD); // lrint/lrintf/lrintl obey the rounding mode.
+   printf("fesetround(FE_UPWARD)\n");
+   printf("lrint(1234.01): %ld\n", lrint(1234.01));
+   printf("lrintf(1234.01f): %ld\n", lrintf(1234.01f));
+   printf("lrintl(1234.01): %ld\n", lrintl(1234.01));
+   fesetround(FE_TOWARDZERO); // lrint/lrintf/lrintl obey the rounding mode.
+   printf("fesetround(FE_TOWARDZERO)\n");
+   printf("lrint(1234.01): %ld\n", lrint(1234.01));
+   printf("lrintf(1234.01f): %ld\n", lrintf(1234.01f));
+   printf("lrintl(1234.01): %ld\n", lrintl(1234.01));
+   fesetround(FE_UPWARD); // llrint/llrintf/llrintl obey the rounding mode.
+   printf("fesetround(FE_UPWARD)\n");
+   printf("llrint(1234.01): %lld\n", llrint(1234.01));
+   printf("llrintf(1234.01f): %lld\n", llrintf(1234.01f));
+   printf("llrintf(1234.01f): %lld\n", llrintl(1234.01));
+   fesetround(FE_TOWARDZERO); // llrint/llrintf/llrintl obey the rounding mode.
+   printf("fesetround(FE_TOWARDZERO)\n");
+   printf("llrint(1234.01): %lld\n", llrint(1234.01));
+   printf("llrintf(1234.01f): %lld\n", llrintf(1234.01f));
+   printf("llrintl(1234.01): %lld\n", llrintl(1234.01));
+
+   /* Tesing rint. */
+   fesetround(FE_UPWARD); // rint/rintf/rintl obey the rounding mode.
+   printf("fesetround(FE_UPWARD)\n");
+   feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
+   printf("feclearexcept(FE_ALL_EXCEPT)\n");
+   printf("rint(1234.0): %f\n", rint(1234.0));
+   printf("(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): %d\n",
+           (fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT));
+   printf("rint(1234.01): %f\n", rint(1234.01));
+   printf("(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): %d\n",
+           (fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT));
+
+   feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
+   printf("feclearexcept(FE_ALL_EXCEPT)\n");
+   printf("rintf(1234.0f): %f\n", rintf(1234.0f));
+   printf("(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): %d\n",
+           (fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT));
+   printf("rintf(1234.01f): %f\n", rintf(1234.01f));
+   printf("(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): %d\n",
+           (fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT));
+
+   feclearexcept(FE_ALL_EXCEPT); // rint/rintf/rintl do set the FE_INEXACT flag.
+   printf("feclearexcept(FE_ALL_EXCEPT)\n");
+   printf("rintl(1234.0): %Lf\n", rintl(1234.0));
+   printf("(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): %d\n",
+           (fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT));
+   printf("rintl(1234.01): %Lf\n", rintl(1234.01));
+   printf("(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): %d\n",
+           (fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT));
+
+   fesetround(FE_TOWARDZERO); // rint/rintf obey the rounding mode.
+   printf("fesetround(FE_TOWARDZERO)\n");
+   printf("rint(1234.01): %f\n", rint(1234.01));
+   printf("rintf(1234.01f): %f\n", rintf(1234.01f));
+   printf("rintl(1234.01): %Lf\n", rintl(1234.01));
+
+   /* Testing nearbyint. */
+   fesetround(FE_UPWARD); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
+   printf("fesetround(FE_UPWARD)\n");
+   feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
+   printf("feclearexcept(FE_ALL_EXCEPT)\n");
+   printf("nearbyint(1234.0): %f\n", nearbyint(1234.0));
+   printf("nearbyint(1234.01): %f\n", nearbyint(1234.01));
+
+   feclearexcept(FE_ALL_EXCEPT);
+   printf("feclearexcept(FE_ALL_EXCEPT)\n");
+   printf("nearbyintf(1234.0f): %f\n", nearbyintf(1234.0f));
+   printf("nearbyintf(1234.01f): %f\n", nearbyintf(1234.01f));
+
+   feclearexcept(FE_ALL_EXCEPT); // nearbyint/nearbyintf/nearbyintl don't set the FE_INEXACT flag.
+   printf("feclearexcept(FE_ALL_EXCEPT)\n");
+   printf("nearbyintl(1234.0f): %Lf\n", nearbyintl(1234.0f));
+   printf("nearbyintl(1234.01f): %Lf\n", nearbyintl(1234.01f));
+
+   fesetround(FE_TOWARDZERO); // nearbyint/nearbyintf/nearbyintl obey the rounding mode.
+   printf("fesetround(FE_TOWARDZERO)\n");
+   printf("nearbyint(1234.01): %f\n", nearbyint(1234.01));
+   printf("nearbyintf(1234.01f): %f\n", nearbyintf(1234.01f));
+   printf("nearbyintl(1234.01): %Lf\n", nearbyintl(1234.01));
+
+   /* Test log. */
+   printf("log(M_E): %lf\n", log(M_E));
+
+   /* Test tgamma. */
+   printf("tgamma(5.0): %lf\n", tgamma(5.0));
+
+   /* Test cbrt. */
+   printf("cbrt(27.0): %lf\n", cbrt(27.0));
+
+   /* Test dividing by zero. */
+   // Clearing clears.
+   printf("feclearexcept(FE_ALL_EXCEPT): %d\n", feclearexcept(FE_ALL_EXCEPT));
+
+   // Dividing by zero sets FE_DIVBYZERO.
+   DivideByZero();
+   int raised = fetestexcept(FE_DIVBYZERO | FE_OVERFLOW);
+   printf("raised: %d\n", raised);
+
+   return 0;
+}
diff --git a/none/tests/mips32/test_math.stderr.exp b/none/tests/mips32/test_math.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/none/tests/mips32/test_math.stdout.exp b/none/tests/mips32/test_math.stdout.exp
new file mode 100644 (file)
index 0000000..6017e26
--- /dev/null
@@ -0,0 +1,55 @@
+fesetround(FE_UPWARD)
+lrint(1234.01): 1235
+lrintf(1234.01f): 1235
+lrintl(1234.01): 1235
+fesetround(FE_TOWARDZERO)
+lrint(1234.01): 1234
+lrintf(1234.01f): 1234
+lrintl(1234.01): 1234
+fesetround(FE_UPWARD)
+llrint(1234.01): 1235
+llrintf(1234.01f): 1235
+llrintf(1234.01f): 1235
+fesetround(FE_TOWARDZERO)
+llrint(1234.01): 1234
+llrintf(1234.01f): 1234
+llrintl(1234.01): 1234
+fesetround(FE_UPWARD)
+feclearexcept(FE_ALL_EXCEPT)
+rint(1234.0): 1234.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 0
+rint(1234.01): 1235.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 4
+feclearexcept(FE_ALL_EXCEPT)
+rintf(1234.0f): 1234.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 0
+rintf(1234.01f): 1235.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 4
+feclearexcept(FE_ALL_EXCEPT)
+rintl(1234.0): 1234.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 0
+rintl(1234.01): 1235.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 4
+fesetround(FE_TOWARDZERO)
+rint(1234.01): 1234.000000
+rintf(1234.01f): 1234.000000
+rintl(1234.01): 1234.000000
+fesetround(FE_UPWARD)
+feclearexcept(FE_ALL_EXCEPT)
+nearbyint(1234.0): 1234.000000
+nearbyint(1234.01): 1235.000000
+feclearexcept(FE_ALL_EXCEPT)
+nearbyintf(1234.0f): 1234.000000
+nearbyintf(1234.01f): 1235.000000
+feclearexcept(FE_ALL_EXCEPT)
+nearbyintl(1234.0f): 1234.000000
+nearbyintl(1234.01f): 1235.000000
+fesetround(FE_TOWARDZERO)
+nearbyint(1234.01): 1234.000000
+nearbyintf(1234.01f): 1234.000000
+nearbyintl(1234.01): 1234.000000
+log(M_E): 1.000000
+tgamma(5.0): 24.000000
+cbrt(27.0): 3.000000
+feclearexcept(FE_ALL_EXCEPT): 0
+raised: 32
diff --git a/none/tests/mips32/test_math.vgtest b/none/tests/mips32/test_math.vgtest
new file mode 100644 (file)
index 0000000..a0d94d5
--- /dev/null
@@ -0,0 +1,2 @@
+prog: test_math
+vgopts: -q
index 85993e8f0942a8d1595f19b55dd5dd45ffdb2bfb..b8f6d65dbfba8879c1da916a862a98b29f1abc82 100644 (file)
@@ -43,7 +43,8 @@ EXTRA_DIST = \
        unaligned_load_store.stderr.exp unaligned_load_store.vgtest \
        test_fcsr.stdout.exp test_fcsr.stderr.exp \
        test_fcsr.vgtest \
-       const.h macro_fpu.h macro_int.h macro_load_store.h rounding_mode.h
+       const.h macro_fpu.h macro_int.h macro_load_store.h rounding_mode.h \
+       test_math.stdout.exp test_math.stderr.exp test_math.vgtest
 
 check_PROGRAMS = \
        allexec \
@@ -67,7 +68,8 @@ check_PROGRAMS = \
        test_block_size \
        unaligned_load \
        unaligned_load_store \
-       test_fcsr
+       test_fcsr \
+       test_math
 
 AM_CFLAGS    += @FLAG_M64@
 AM_CXXFLAGS  += @FLAG_M64@
@@ -77,3 +79,6 @@ allexec_CFLAGS          = $(AM_CFLAGS) @FLAG_W_NO_NONNULL@
 
 cvm_ins_CFLAGS = $(AM_CFLAGS) -g -O0 -march=octeon
 fpu_arithmetic_CFLAGS = $(AM_CFLAGS) -lm
+
+# C++ tests
+test_math_SOURCES          = test_math.cpp
diff --git a/none/tests/mips64/test_math.cpp b/none/tests/mips64/test_math.cpp
new file mode 120000 (symlink)
index 0000000..b2ce3d0
--- /dev/null
@@ -0,0 +1 @@
+../mips32/test_math.cpp
\ No newline at end of file
diff --git a/none/tests/mips64/test_math.stderr.exp b/none/tests/mips64/test_math.stderr.exp
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/none/tests/mips64/test_math.stdout.exp b/none/tests/mips64/test_math.stdout.exp
new file mode 100644 (file)
index 0000000..2a0e71f
--- /dev/null
@@ -0,0 +1,55 @@
+fesetround(FE_UPWARD)
+lrint(1234.01): 1235
+lrintf(1234.01f): 1235
+lrintl(1234.01): 1234
+fesetround(FE_TOWARDZERO)
+lrint(1234.01): 1234
+lrintf(1234.01f): 1234
+lrintl(1234.01): 1234
+fesetround(FE_UPWARD)
+llrint(1234.01): 1235
+llrintf(1234.01f): 1235
+llrintf(1234.01f): 1234
+fesetround(FE_TOWARDZERO)
+llrint(1234.01): 1234
+llrintf(1234.01f): 1234
+llrintl(1234.01): 1234
+fesetround(FE_UPWARD)
+feclearexcept(FE_ALL_EXCEPT)
+rint(1234.0): 1234.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 0
+rint(1234.01): 1235.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 4
+feclearexcept(FE_ALL_EXCEPT)
+rintf(1234.0f): 1234.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 0
+rintf(1234.01f): 1235.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 4
+feclearexcept(FE_ALL_EXCEPT)
+rintl(1234.0): 1234.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 0
+rintl(1234.01): 1234.000000
+(fetestexcept(FE_ALL_EXCEPT) & FE_INEXACT): 0
+fesetround(FE_TOWARDZERO)
+rint(1234.01): 1234.000000
+rintf(1234.01f): 1234.000000
+rintl(1234.01): 1234.000000
+fesetround(FE_UPWARD)
+feclearexcept(FE_ALL_EXCEPT)
+nearbyint(1234.0): 1234.000000
+nearbyint(1234.01): 1235.000000
+feclearexcept(FE_ALL_EXCEPT)
+nearbyintf(1234.0f): 1234.000000
+nearbyintf(1234.01f): 1235.000000
+feclearexcept(FE_ALL_EXCEPT)
+nearbyintl(1234.0f): 1234.000000
+nearbyintl(1234.01f): 1234.000000
+fesetround(FE_TOWARDZERO)
+nearbyint(1234.01): 1234.000000
+nearbyintf(1234.01f): 1234.000000
+nearbyintl(1234.01): 1234.000000
+log(M_E): 1.000000
+tgamma(5.0): 24.000000
+cbrt(27.0): 3.000000
+feclearexcept(FE_ALL_EXCEPT): 0
+raised: 32
diff --git a/none/tests/mips64/test_math.vgtest b/none/tests/mips64/test_math.vgtest
new file mode 120000 (symlink)
index 0000000..c2ace8d
--- /dev/null
@@ -0,0 +1 @@
+../mips32/test_math.vgtest
\ No newline at end of file