From: Dejan Jevtic Date: Thu, 14 Nov 2013 15:45:26 +0000 (+0000) Subject: mips32/64: Test case for VEX r2799. X-Git-Tag: svn/VALGRIND_3_10_0~723 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b4adb1bc502f6dc8f513e110af031cda62f4e60c;p=thirdparty%2Fvalgrind.git mips32/64: Test case for VEX r2799. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@13713 --- diff --git a/none/tests/mips32/Makefile.am b/none/tests/mips32/Makefile.am index 5aa4ea7e2d..7514034388 100644 --- a/none/tests/mips32/Makefile.am +++ b/none/tests/mips32/Makefile.am @@ -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 index 0000000000..8a0f2dcab6 --- /dev/null +++ b/none/tests/mips32/test_math.cpp @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include + +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 index 0000000000..e69de29bb2 diff --git a/none/tests/mips32/test_math.stdout.exp b/none/tests/mips32/test_math.stdout.exp new file mode 100644 index 0000000000..6017e26f41 --- /dev/null +++ b/none/tests/mips32/test_math.stdout.exp @@ -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 index 0000000000..a0d94d5c9c --- /dev/null +++ b/none/tests/mips32/test_math.vgtest @@ -0,0 +1,2 @@ +prog: test_math +vgopts: -q diff --git a/none/tests/mips64/Makefile.am b/none/tests/mips64/Makefile.am index 85993e8f09..b8f6d65dbf 100644 --- a/none/tests/mips64/Makefile.am +++ b/none/tests/mips64/Makefile.am @@ -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 index 0000000000..b2ce3d0bb2 --- /dev/null +++ b/none/tests/mips64/test_math.cpp @@ -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 index 0000000000..e69de29bb2 diff --git a/none/tests/mips64/test_math.stdout.exp b/none/tests/mips64/test_math.stdout.exp new file mode 100644 index 0000000000..2a0e71fd2f --- /dev/null +++ b/none/tests/mips64/test_math.stdout.exp @@ -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 index 0000000000..c2ace8dbd4 --- /dev/null +++ b/none/tests/mips64/test_math.vgtest @@ -0,0 +1 @@ +../mips32/test_math.vgtest \ No newline at end of file