diff mbox

[PR66326,Cilk+] Fix FP exception occured in CilkPlus runtime

Message ID 0EFAB2BDD0F67E4FB6CCC8B9F87D7569738142A0@IRSMSX101.ger.corp.intel.com
State New
Headers show

Commit Message

Zamyatin, Igor Nov. 2, 2015, 8:10 p.m. UTC
Hi!

This patches fixes FP exception that comes from CilkPlus runtime.

Bootstrapped and regtested for x86_64.
Is it ok for trunk?

Thanks,
Igor

Changelog:

libcilkrts

2015-10-30  Igor Zamyatin  <igor.zamyatin@intel.com>

	PR target/66326
	* untime/config/x86/os-unix-sysdep.c (sysdep_save_fp_ctrl_state):
	Use fnstcw instead fnstsw.


testsuite

2015-10-30  Igor Zamyatin  <igor.zamyatin@intel.com>

	PR target/66326
	* g++.dg/cilk-plus/CK/pr66326.cc: New test.

Comments

Jeff Law Nov. 2, 2015, 9:38 p.m. UTC | #1
On 11/02/2015 01:10 PM, Zamyatin, Igor wrote:
> Hi!
>
> This patches fixes FP exception that comes from CilkPlus runtime.
>
> Bootstrapped and regtested for x86_64.
> Is it ok for trunk?
>
> Thanks,
> Igor
>
> Changelog:
>
> libcilkrts
>
> 2015-10-30  Igor Zamyatin  <igor.zamyatin@intel.com>
>
> 	PR target/66326
> 	* untime/config/x86/os-unix-sysdep.c (sysdep_save_fp_ctrl_state):
> 	Use fnstcw instead fnstsw.
>
>
> testsuite
>
> 2015-10-30  Igor Zamyatin  <igor.zamyatin@intel.com>
>
> 	PR target/66326
> 	* g++.dg/cilk-plus/CK/pr66326.cc: New test.
OK.
jeff
Thomas Schwinge Nov. 9, 2015, 4:28 p.m. UTC | #2
Hi!

On Mon, 2 Nov 2015 20:10:06 +0000, "Zamyatin, Igor" <igor.zamyatin@intel.com> wrote:
> This patches fixes FP exception that comes from CilkPlus runtime.
> 
> Bootstrapped and regtested for x86_64.

> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/cilk-plus/CK/pr66326.cc
> @@ -0,0 +1,33 @@
> +/* { dg-options "-fcilkplus" } */
> +/* { dg-do run { target i?86-*-* x86_64-*-* } } */
> +/* { dg-options "-fcilkplus -lcilkrts" { target { i?86-*-* x86_64-*-* } } } */
> +
> +#include <cilk/cilk.h>
> +[...]

I'm seeing:

    FAIL: g++.dg/cilk-plus/CK/pr66326.cc  -O1 -fcilkplus (test for excess errors)
    UNRESOLVED: g++.dg/cilk-plus/CK/pr66326.cc  -O1 -fcilkplus compilation failed to produce executable
    FAIL: g++.dg/cilk-plus/CK/pr66326.cc  -O3 -fcilkplus (test for excess errors)
    UNRESOLVED: g++.dg/cilk-plus/CK/pr66326.cc  -O3 -fcilkplus compilation failed to produce executable
    FAIL: g++.dg/cilk-plus/CK/pr66326.cc  -g -O2 -fcilkplus (test for excess errors)
    UNRESOLVED: g++.dg/cilk-plus/CK/pr66326.cc  -g -O2 -fcilkplus compilation failed to produce executable
    FAIL: g++.dg/cilk-plus/CK/pr66326.cc  -g -fcilkplus (test for excess errors)
    UNRESOLVED: g++.dg/cilk-plus/CK/pr66326.cc  -g -fcilkplus compilation failed to produce executable

..., which is because of:

    [...]/gcc/testsuite/g++.dg/cilk-plus/CK/pr66326.cc:5:23: fatal error: cilk/cilk.h: No such file or directory

This is the only test case trying to include that file:

    $ git grep --cached -F cilk.h -- gcc/testsuite/
    gcc/testsuite/g++.dg/cilk-plus/CK/pr66326.cc:#include <cilk/cilk.h>

..., so I guess that's not supported?


Grüße
 Thomas
diff mbox

Patch

diff --git a/gcc/testsuite/g++.dg/cilk-plus/CK/pr66326.cc b/gcc/testsuite/g++.dg/cilk-plus/CK/pr66326.cc
new file mode 100644
index 0000000..1114ebd
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cilk-plus/CK/pr66326.cc
@@ -0,0 +1,33 @@ 
+/* { dg-options "-fcilkplus" } */
+/* { dg-do run { target i?86-*-* x86_64-*-* } } */
+/* { dg-options "-fcilkplus -lcilkrts" { target { i?86-*-* x86_64-*-* } } } */
+
+#include <cilk/cilk.h>
+#include <vector>
+#include <random>
+
+template <class T>
+void do_not_optimize_away(T&& x) {
+  asm volatile("" : "+r"(x));
+}
+
+const int N = 1'000'000;
+
+auto compute() {
+  std::vector<double> v(N);
+  auto rng = std::mt19937{std::random_device{}()};
+  std::uniform_real_distribution<double> dist(0, 1);
+  for (int i = 0; i < N; ++i) v[i] = std::log(std::sqrt(dist(rng)));
+  return v;
+}
+
+int main() {
+  std::vector<double> v1, v2, v3;
+  cilk_spawn [&] { v1 = compute(); }();
+  cilk_spawn [&] { v2 = compute(); }();
+  v3 = compute();
+  do_not_optimize_away(v1.data());
+  do_not_optimize_away(v2.data());
+  do_not_optimize_away(v3.data());
+  return 0;
+}
diff --git a/libcilkrts/runtime/config/x86/os-unix-sysdep.c b/libcilkrts/runtime/config/x86/os-unix-sysdep.c
index b505ddf..cbc7734 100644
--- a/libcilkrts/runtime/config/x86/os-unix-sysdep.c
+++ b/libcilkrts/runtime/config/x86/os-unix-sysdep.c
@@ -135,7 +135,7 @@  void sysdep_save_fp_ctrl_state(__cilkrts_stack_frame *sf)
         {
             __asm__ ("stmxcsr %0" : "=m" (sf->mxcsr));
         }
-        __asm__ ("fnstsw %0" : "=m" (sf->fpcsr));
+	__asm__ ("fnstcw %0" : "=m" (sf->fpcsr));
     }
 #endif
 }