public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Zamyatin, Igor" <igor.zamyatin@intel.com>
To: "GCC Patches (gcc-patches@gcc.gnu.org)" <gcc-patches@gcc.gnu.org>
Cc: "Jeff Law (law@redhat.com)" <law@redhat.com>,
	"Jakub Jelinek (jakub@redhat.com)" <jakub@redhat.com>
Subject: [PR66326, Cilk+] Fix FP exception occured in CilkPlus runtime
Date: Mon, 02 Nov 2015 20:10:00 -0000	[thread overview]
Message-ID: <0EFAB2BDD0F67E4FB6CCC8B9F87D7569738142A0@IRSMSX101.ger.corp.intel.com> (raw)

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
 }

             reply	other threads:[~2015-11-02 20:10 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-02 20:10 Zamyatin, Igor [this message]
2015-11-02 21:38 ` Jeff Law
2015-11-09 16:29 ` Thomas Schwinge

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0EFAB2BDD0F67E4FB6CCC8B9F87D7569738142A0@IRSMSX101.ger.corp.intel.com \
    --to=igor.zamyatin@intel.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=law@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).