public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PR66326, Cilk+] Fix FP exception occured in CilkPlus runtime
@ 2015-11-02 20:10 Zamyatin, Igor
  2015-11-02 21:38 ` Jeff Law
  2015-11-09 16:29 ` Thomas Schwinge
  0 siblings, 2 replies; 3+ messages in thread
From: Zamyatin, Igor @ 2015-11-02 20:10 UTC (permalink / raw)
  To: GCC Patches (gcc-patches@gcc.gnu.org)
  Cc: Jeff Law (law@redhat.com), Jakub Jelinek (jakub@redhat.com)

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.



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
 }

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-11-09 16:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-02 20:10 [PR66326, Cilk+] Fix FP exception occured in CilkPlus runtime Zamyatin, Igor
2015-11-02 21:38 ` Jeff Law
2015-11-09 16:29 ` Thomas Schwinge

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).