This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[RFC PATCH v3 04/12] C-SKY: Hard Float Support


This patch contains hardware floating-point support for C-SKY.

	* sysdeps/csky/fpu/fclrexcpt.c: New file.
	* sysdeps/csky/fpu/fedisblxcpt.c: Likewise.
	* sysdeps/csky/fpu/feenablxcpt.c: Likewise.
	* sysdeps/csky/fpu/fegetenv.c: Likewise.
	* sysdeps/csky/fpu/fegetexcept.c: Likewise.
	* sysdeps/csky/fpu/fegetmode.c: Likewise.
	* sysdeps/csky/fpu/fegetround.c: Likewise.
	* sysdeps/csky/fpu/feholdexcpt.c: Likewise.
	* sysdeps/csky/fpu/fenv_libc.h: Likewise.
	* sysdeps/csky/fpu/fenv_private.h: Likewise.
	* sysdeps/csky/fpu/fesetenv.c: Likewise.
	* sysdeps/csky/fpu/fesetexcept.c: Likewise.
	* sysdeps/csky/fpu/fesetmode.c: Likewise.
	* sysdeps/csky/fpu/fesetround.c: Likewise.
	* sysdeps/csky/fpu/feupdateenv.c: Likewise.
	* sysdeps/csky/fpu/fgetexcptflg.c: Likewise.
	* sysdeps/csky/fpu/fpu_control.h: Likewise.
	* sysdeps/csky/fpu/fraiseexcpt.c: Likewise.
	* sysdeps/csky/fpu/fsetexcptflg.c: Likewise.
	* sysdeps/csky/fpu/ftestexcept.c: Likewise.
	* sysdeps/csky/fpu/math_private.h: Likewise.
---
 sysdeps/csky/fpu/fclrexcpt.c    |  42 ++++++
 sysdeps/csky/fpu/fedisblxcpt.c  |  41 ++++++
 sysdeps/csky/fpu/feenablxcpt.c  |  40 ++++++
 sysdeps/csky/fpu/fegetenv.c     |  37 ++++++
 sysdeps/csky/fpu/fegetexcept.c  |  32 +++++
 sysdeps/csky/fpu/fegetmode.c    |  28 ++++
 sysdeps/csky/fpu/fegetround.c   |  34 +++++
 sysdeps/csky/fpu/feholdexcpt.c  |  34 +++++
 sysdeps/csky/fpu/fenv_libc.h    |  30 +++++
 sysdeps/csky/fpu/fenv_private.h | 284 ++++++++++++++++++++++++++++++++++++++++
 sysdeps/csky/fpu/fesetenv.c     |  59 +++++++++
 sysdeps/csky/fpu/fesetexcept.c  |  33 +++++
 sysdeps/csky/fpu/fesetmode.c    |  33 +++++
 sysdeps/csky/fpu/fesetround.c   |  32 +++++
 sysdeps/csky/fpu/feupdateenv.c  |  46 +++++++
 sysdeps/csky/fpu/fgetexcptflg.c |  32 +++++
 sysdeps/csky/fpu/fpu_control.h  | 133 +++++++++++++++++++
 sysdeps/csky/fpu/fraiseexcpt.c  | 126 ++++++++++++++++++
 sysdeps/csky/fpu/fsetexcptflg.c |  43 ++++++
 sysdeps/csky/fpu/ftestexcept.c  |  30 +++++
 sysdeps/csky/fpu/math_private.h |   7 +
 21 files changed, 1176 insertions(+)
 create mode 100644 sysdeps/csky/fpu/fclrexcpt.c
 create mode 100644 sysdeps/csky/fpu/fedisblxcpt.c
 create mode 100644 sysdeps/csky/fpu/feenablxcpt.c
 create mode 100644 sysdeps/csky/fpu/fegetenv.c
 create mode 100644 sysdeps/csky/fpu/fegetexcept.c
 create mode 100644 sysdeps/csky/fpu/fegetmode.c
 create mode 100644 sysdeps/csky/fpu/fegetround.c
 create mode 100644 sysdeps/csky/fpu/feholdexcpt.c
 create mode 100644 sysdeps/csky/fpu/fenv_libc.h
 create mode 100644 sysdeps/csky/fpu/fenv_private.h
 create mode 100644 sysdeps/csky/fpu/fesetenv.c
 create mode 100644 sysdeps/csky/fpu/fesetexcept.c
 create mode 100644 sysdeps/csky/fpu/fesetmode.c
 create mode 100644 sysdeps/csky/fpu/fesetround.c
 create mode 100644 sysdeps/csky/fpu/feupdateenv.c
 create mode 100644 sysdeps/csky/fpu/fgetexcptflg.c
 create mode 100644 sysdeps/csky/fpu/fpu_control.h
 create mode 100644 sysdeps/csky/fpu/fraiseexcpt.c
 create mode 100644 sysdeps/csky/fpu/fsetexcptflg.c
 create mode 100644 sysdeps/csky/fpu/ftestexcept.c
 create mode 100644 sysdeps/csky/fpu/math_private.h

diff --git a/sysdeps/csky/fpu/fclrexcpt.c b/sysdeps/csky/fpu/fclrexcpt.c
new file mode 100644
index 0000000..de3326b
--- /dev/null
+++ b/sysdeps/csky/fpu/fclrexcpt.c
@@ -0,0 +1,42 @@
+/* Clear given exceptions in current floating-point environment.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fenv_libc.h>
+#include <fpu_control.h>
+
+int
+feclearexcept (int excepts)
+{
+  int fpsr;
+
+  /* Mask out unsupported bits/exceptions.  */
+  excepts &= FE_ALL_EXCEPT;
+
+  /* Read the complete control word.  */
+  _FPU_GETFPSR (fpsr);
+
+  /* Clear the relevant bits.  */
+  fpsr &= ~(excepts | (excepts << CAUSE_SHIFT));
+
+  /* Put the new data in effect.  */
+  _FPU_SETFPSR (fpsr);
+
+  return 0;
+}
+libm_hidden_def (feclearexcept)
diff --git a/sysdeps/csky/fpu/fedisblxcpt.c b/sysdeps/csky/fpu/fedisblxcpt.c
new file mode 100644
index 0000000..6b51611
--- /dev/null
+++ b/sysdeps/csky/fpu/fedisblxcpt.c
@@ -0,0 +1,41 @@
+/* Disable floating-point exceptions.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fenv_libc.h>
+#include <fpu_control.h>
+
+int
+fedisableexcept (int excepts)
+{
+  unsigned int new_exc, old_exc;
+
+  /* Get the current control word.  */
+  _FPU_GETCW (new_exc);
+
+  old_exc = (new_exc & ENABLE_MASK) >> ENABLE_SHIFT;
+
+  /* Get the except disable mask.  */
+  excepts &= FE_ALL_EXCEPT;
+  new_exc &= ~(excepts << ENABLE_SHIFT);
+
+  /* Put the new data in effect.  */
+  _FPU_SETCW (new_exc);
+
+  return old_exc;
+}
diff --git a/sysdeps/csky/fpu/feenablxcpt.c b/sysdeps/csky/fpu/feenablxcpt.c
new file mode 100644
index 0000000..feafdb6
--- /dev/null
+++ b/sysdeps/csky/fpu/feenablxcpt.c
@@ -0,0 +1,40 @@
+/* Enable floating-point exceptions.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fenv_libc.h>
+#include <fpu_control.h>
+
+int
+feenableexcept (int excepts)
+{
+  unsigned int new_exc, old_exc;
+
+  /* Get the current control word.  */
+  _FPU_GETCW (new_exc);
+
+  old_exc = (new_exc & ENABLE_MASK) >> ENABLE_SHIFT;
+
+  excepts &= FE_ALL_EXCEPT;
+
+  new_exc |= excepts << ENABLE_SHIFT;
+
+  _FPU_SETCW (new_exc);
+
+  return old_exc;
+}
diff --git a/sysdeps/csky/fpu/fegetenv.c b/sysdeps/csky/fpu/fegetenv.c
new file mode 100644
index 0000000..3865839
--- /dev/null
+++ b/sysdeps/csky/fpu/fegetenv.c
@@ -0,0 +1,37 @@
+/* Store current floating-point environment.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+__fegetenv (fenv_t *envp)
+{
+  unsigned int fpcr;
+  unsigned int fpsr;
+
+  _FPU_GETCW (fpcr);
+  _FPU_GETFPSR (fpsr);
+  envp->__fpcr = fpcr;
+  envp->__fpsr = fpsr;
+
+  return 0;
+}
+libm_hidden_def (__fegetenv)
+weak_alias (__fegetenv, fegetenv)
+libm_hidden_weak (fegetenv)
diff --git a/sysdeps/csky/fpu/fegetexcept.c b/sysdeps/csky/fpu/fegetexcept.c
new file mode 100644
index 0000000..e6e46c0
--- /dev/null
+++ b/sysdeps/csky/fpu/fegetexcept.c
@@ -0,0 +1,32 @@
+/* Get enabled floating-point exceptions.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fenv_libc.h>
+#include <fpu_control.h>
+
+int
+fegetexcept (void)
+{
+  unsigned int exc;
+
+  /* Get the current control word.  */
+  _FPU_GETCW (exc);
+
+  return (exc & ENABLE_MASK) >> ENABLE_SHIFT;
+}
diff --git a/sysdeps/csky/fpu/fegetmode.c b/sysdeps/csky/fpu/fegetmode.c
new file mode 100644
index 0000000..e229f60
--- /dev/null
+++ b/sysdeps/csky/fpu/fegetmode.c
@@ -0,0 +1,28 @@
+/* Store current floating-point control modes.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+fegetmode (femode_t *modep)
+{
+  _FPU_GETCW (*modep);
+
+  return 0;
+}
diff --git a/sysdeps/csky/fpu/fegetround.c b/sysdeps/csky/fpu/fegetround.c
new file mode 100644
index 0000000..40bda2d
--- /dev/null
+++ b/sysdeps/csky/fpu/fegetround.c
@@ -0,0 +1,34 @@
+/* Return current rounding direction.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+__fegetround (void)
+{
+  unsigned int cw;
+
+  /* Get control word.  */
+  _FPU_GETCW (cw);
+
+  return cw & __FE_ROUND_MASK;
+}
+libm_hidden_def (__fegetround)
+weak_alias (__fegetround, fegetround)
+libm_hidden_weak (fegetround)
diff --git a/sysdeps/csky/fpu/feholdexcpt.c b/sysdeps/csky/fpu/feholdexcpt.c
new file mode 100644
index 0000000..e2b1782
--- /dev/null
+++ b/sysdeps/csky/fpu/feholdexcpt.c
@@ -0,0 +1,34 @@
+/* Store current floating-point environment and clear exceptions.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <fenv_libc.h>
+#include <fenv_private.h>
+
+#include <stdio.h>
+
+int
+__feholdexcept (fenv_t *envp)
+{
+  libc_feholdexcept_vfp (envp);
+  return 0;
+}
+libm_hidden_def (__feholdexcept)
+weak_alias (__feholdexcept, feholdexcept)
+libm_hidden_weak (feholdexcept)
diff --git a/sysdeps/csky/fpu/fenv_libc.h b/sysdeps/csky/fpu/fenv_libc.h
new file mode 100644
index 0000000..101d176
--- /dev/null
+++ b/sysdeps/csky/fpu/fenv_libc.h
@@ -0,0 +1,30 @@
+/* fpu registers environment.  C-SKY version.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _FENV_LIBC_H
+#define _FENV_LIBC_H	1
+
+/* Mask for enabling exceptions and for the CAUSE bits.  */
+#define ENABLE_MASK	0x0003FU
+#define CAUSE_MASK	0x3F000U
+
+/* Shift for FE_* flags to get up to the ENABLE bits and the CAUSE bits.  */
+#define	ENABLE_SHIFT	0
+#define CAUSE_SHIFT	8
+
+#endif /* fenv_libc.h */
diff --git a/sysdeps/csky/fpu/fenv_private.h b/sysdeps/csky/fpu/fenv_private.h
new file mode 100644
index 0000000..b33efab
--- /dev/null
+++ b/sysdeps/csky/fpu/fenv_private.h
@@ -0,0 +1,284 @@
+/* Private floating point rounding and exceptions handling. C-SKY version.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef FENV_PRIVATE_H
+#define FENV_PRIVATE_H 1
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <fenv_libc.h>
+
+static __always_inline void
+libc_feholdexcept_vfp (fenv_t *envp)
+{
+  unsigned int fpsr;
+  unsigned int fpcr;
+
+  _FPU_GETCW (fpcr);
+  envp->__fpcr = fpcr;
+
+  _FPU_GETFPSR (fpsr);
+  envp->__fpsr = fpsr;
+
+  /* Now set all exceptions to non-stop.  */
+  fpcr &= ~FE_ALL_EXCEPT;
+
+  /* And clear all exception flags.  */
+  fpsr &= ~(FE_ALL_EXCEPT << CAUSE_SHIFT);
+
+  _FPU_SETFPSR (fpsr);
+
+  _FPU_SETCW (fpcr);
+}
+
+static __always_inline void
+libc_fesetround_vfp (int round)
+{
+  fpu_control_t fpcr;
+
+  _FPU_GETCW (fpcr);
+
+  /* Set new rounding mode if different.  */
+  if (__glibc_unlikely ((fpcr & FE_DOWNWARD) != round))
+    _FPU_SETCW ((fpcr & ~FE_DOWNWARD) | round);
+}
+
+static __always_inline void
+libc_feholdexcept_setround_vfp (fenv_t *envp, int round)
+{
+  fpu_control_t fpsr;
+  fpu_control_t fpcr;
+
+  _FPU_GETCW (fpcr);
+  envp->__fpcr = fpcr;
+
+  _FPU_GETFPSR (fpsr);
+  envp->__fpsr = fpsr;
+
+  /* Clear exception flags, set all exceptions to non-stop,
+     and set new rounding mode.  */
+  fpcr &= ~(FE_ALL_EXCEPT | FE_DOWNWARD);
+  _FPU_SETCW (fpcr | round);
+
+  fpsr &= ~(FE_ALL_EXCEPT << CAUSE_SHIFT);
+  _FPU_SETFPSR (fpsr);
+}
+
+static __always_inline void
+libc_feholdsetround_vfp (fenv_t *envp, int round)
+{
+  fpu_control_t fpcr;
+
+  _FPU_GETCW (fpcr);
+  envp->__fpcr = fpcr;
+
+  /* Set new rounding mode if different.  */
+  if (__glibc_unlikely ((fpcr & FE_DOWNWARD) != round))
+    _FPU_SETCW ((fpcr & ~FE_DOWNWARD) | round);
+}
+
+static __always_inline void
+libc_feresetround_vfp (fenv_t *envp)
+{
+  fpu_control_t fpcr, round;
+
+  _FPU_GETCW (fpcr);
+
+  /* Check whether rounding modes are different.  */
+  round = (envp->__fpcr ^ fpcr) & FE_DOWNWARD;
+
+  /* Restore the rounding mode if it was changed.  */
+  if (__glibc_unlikely (round != 0))
+    _FPU_SETCW (fpcr ^ round);
+}
+
+static __always_inline int
+libc_fetestexcept_vfp (int ex)
+{
+  fpu_control_t fpsr;
+
+  _FPU_GETFPSR (fpsr);
+  fpsr = fpsr >> CAUSE_SHIFT;
+  return fpsr & ex & FE_ALL_EXCEPT;
+}
+
+static __always_inline void
+libc_fesetenv_vfp (const fenv_t *envp)
+{
+  unsigned int fpcr;
+  unsigned int fpsr;
+
+  _FPU_GETCW (fpcr);
+  _FPU_GETFPSR (fpsr);
+
+  fpcr &= _FPU_RESERVED;
+  fpsr &= _FPU_FPSR_RESERVED;
+
+  if (envp == FE_DFL_ENV)
+    {
+      fpcr |= _FPU_DEFAULT;
+      fpsr |= _FPU_FPSR_DEFAULT;
+    }
+  else if (envp == FE_NOMASK_ENV)
+    {
+      fpcr |= _FPU_FPCR_IEEE;
+      fpsr |= _FPU_FPSR_IEEE;
+    }
+  else
+    {
+      fpcr |= envp->__fpcr & ~_FPU_RESERVED;
+      fpsr |= envp->__fpsr & ~_FPU_FPSR_RESERVED;
+    }
+
+  _FPU_SETFPSR (fpsr);
+
+  _FPU_SETCW (fpcr);
+}
+
+static __always_inline int
+libc_feupdateenv_test_vfp (const fenv_t *envp, int ex)
+{
+  fpu_control_t fpsr, new_fpsr;
+  int excepts;
+
+  _FPU_GETFPSR (fpsr);
+
+  /* Merge current exception flags with the saved fenv.  */
+  excepts = (fpsr >> CAUSE_SHIFT) & FE_ALL_EXCEPT;
+  new_fpsr = envp->__fpsr | (excepts << CAUSE_SHIFT);
+
+  /* Write new FPSCR if different.  */
+  if (__glibc_unlikely (((fpsr ^ new_fpsr)) != 0))
+    _FPU_SETFPSR (new_fpsr);
+
+  /* Raise the exceptions if enabled in the new FP state.  */
+  if (__glibc_unlikely (excepts & (new_fpsr >> CAUSE_SHIFT)))
+    __feraiseexcept (excepts);
+
+  return excepts & ex;
+}
+
+static __always_inline void
+libc_feupdateenv_vfp (const fenv_t *envp)
+{
+  libc_feupdateenv_test_vfp (envp, 0);
+}
+
+static __always_inline void
+libc_feholdsetround_vfp_ctx (struct rm_ctx *ctx, int r)
+{
+  fpu_control_t fpcr, round;
+
+  _FPU_GETCW (fpcr);
+  ctx->updated_status = false;
+  ctx->env.__fpcr = fpcr;
+
+  /* Check whether rounding modes are different.  */
+  round = (fpcr ^ r) & FE_DOWNWARD;
+
+  /* Set the rounding mode if changed.  */
+  if (__glibc_unlikely (round != 0))
+    {
+      ctx->updated_status = true;
+      _FPU_SETCW (fpcr ^ round);
+    }
+}
+
+static __always_inline void
+libc_feresetround_vfp_ctx (struct rm_ctx *ctx)
+{
+  /* Restore the rounding mode if updated.  */
+  if (__glibc_unlikely (ctx->updated_status))
+    {
+      fpu_control_t fpcr;
+
+      _FPU_GETCW (fpcr);
+      fpcr = (fpcr & ~FE_DOWNWARD) | (ctx->env.__fpcr & FE_DOWNWARD);
+      _FPU_SETCW (fpcr);
+    }
+}
+
+static __always_inline void
+libc_fesetenv_vfp_ctx (struct rm_ctx *ctx)
+{
+  fpu_control_t fpcr, new_fpcr;
+
+  _FPU_GETCW (fpcr);
+  new_fpcr = ctx->env.__fpcr;
+
+  /* Write new FPSCR if different.  */
+  if (__glibc_unlikely (((fpcr ^ new_fpcr)) != 0))
+    _FPU_SETCW (new_fpcr);
+}
+
+#define libc_feholdexcept  libc_feholdexcept_vfp
+#define libc_feholdexceptf libc_feholdexcept_vfp
+#define libc_feholdexceptl libc_feholdexcept_vfp
+
+#define libc_fesetround  libc_fesetround_vfp
+#define libc_fesetroundf libc_fesetround_vfp
+#define libc_fesetroundl libc_fesetround_vfp
+
+#define libc_feresetround  libc_feresetround_vfp
+#define libc_feresetroundf libc_feresetround_vfp
+#define libc_feresetroundl libc_feresetround_vfp
+
+#define libc_feresetround_noex  libc_fesetenv_vfp
+#define libc_feresetround_noexf libc_fesetenv_vfp
+#define libc_feresetround_noexl libc_fesetenv_vfp
+
+#define libc_feholdexcept_setround  libc_feholdexcept_setround_vfp
+#define libc_feholdexcept_setroundf libc_feholdexcept_setround_vfp
+#define libc_feholdexcept_setroundl libc_feholdexcept_setround_vfp
+
+#define libc_feholdsetround  libc_feholdsetround_vfp
+#define libc_feholdsetroundf libc_feholdsetround_vfp
+#define libc_feholdsetroundl libc_feholdsetround_vfp
+
+#define libc_fetestexcept  libc_fetestexcept_vfp
+#define libc_fetestexceptf libc_fetestexcept_vfp
+#define libc_fetestexceptl libc_fetestexcept_vfp
+
+#define libc_fesetenv  libc_fesetenv_vfp
+#define libc_fesetenvf libc_fesetenv_vfp
+#define libc_fesetenvl libc_fesetenv_vfp
+
+#define libc_feupdateenv  libc_feupdateenv_vfp
+#define libc_feupdateenvf libc_feupdateenv_vfp
+#define libc_feupdateenvl libc_feupdateenv_vfp
+
+#define libc_feupdateenv_test  libc_feupdateenv_test_vfp
+#define libc_feupdateenv_testf libc_feupdateenv_test_vfp
+#define libc_feupdateenv_testl libc_feupdateenv_test_vfp
+
+/* We have support for rounding mode context.  */
+#define HAVE_RM_CTX 1
+
+#define libc_feholdsetround_ctx		libc_feholdsetround_vfp_ctx
+#define libc_feresetround_ctx		libc_feresetround_vfp_ctx
+#define libc_feresetround_noex_ctx	libc_fesetenv_vfp_ctx
+
+#define libc_feholdsetroundf_ctx	libc_feholdsetround_vfp_ctx
+#define libc_feresetroundf_ctx		libc_feresetround_vfp_ctx
+#define libc_feresetround_noexf_ctx	libc_fesetenv_vfp_ctx
+
+#define libc_feholdsetroundl_ctx	libc_feholdsetround_vfp_ctx
+#define libc_feresetroundl_ctx		libc_feresetround_vfp_ctx
+#define libc_feresetround_noexl_ctx	libc_fesetenv_vfp_ctx
+
+#endif /* fenv_private.h */
diff --git a/sysdeps/csky/fpu/fesetenv.c b/sysdeps/csky/fpu/fesetenv.c
new file mode 100644
index 0000000..dce6770
--- /dev/null
+++ b/sysdeps/csky/fpu/fesetenv.c
@@ -0,0 +1,59 @@
+/* Install given floating-point environment.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+__fesetenv (const fenv_t *envp)
+{
+  unsigned int fpcr;
+  unsigned int fpsr;
+
+  _FPU_GETCW (fpcr);
+  _FPU_GETFPSR (fpsr);
+
+  fpcr &= _FPU_RESERVED;
+  fpsr &= _FPU_FPSR_RESERVED;
+
+  if (envp == FE_DFL_ENV)
+    {
+      fpcr |= _FPU_DEFAULT;
+      fpsr |= _FPU_FPSR_DEFAULT;
+    }
+  else if (envp == FE_NOMASK_ENV)
+    {
+      fpcr |= _FPU_FPCR_IEEE;
+      fpsr |= _FPU_FPSR_IEEE;
+    }
+  else
+    {
+      fpcr |= envp->__fpcr & ~_FPU_RESERVED;
+      fpsr |= envp->__fpsr & ~_FPU_FPSR_RESERVED;
+    }
+
+  _FPU_SETFPSR (fpsr);
+
+  _FPU_SETCW (fpcr);
+
+  /* Success.  */
+  return 0;
+}
+libm_hidden_def (__fesetenv)
+weak_alias (__fesetenv, fesetenv)
+libm_hidden_weak (fesetenv)
diff --git a/sysdeps/csky/fpu/fesetexcept.c b/sysdeps/csky/fpu/fesetexcept.c
new file mode 100644
index 0000000..e7cd302
--- /dev/null
+++ b/sysdeps/csky/fpu/fesetexcept.c
@@ -0,0 +1,33 @@
+/* Set given exception flags.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <fenv_libc.h>
+
+int
+fesetexcept (int excepts)
+{
+  fpu_control_t fpsr, new_fpsr;
+  _FPU_GETFPSR (fpsr);
+  new_fpsr = fpsr | ((excepts & FE_ALL_EXCEPT) << CAUSE_SHIFT);
+  if (new_fpsr != fpsr)
+    _FPU_SETFPSR (new_fpsr);
+
+  return 0;
+}
diff --git a/sysdeps/csky/fpu/fesetmode.c b/sysdeps/csky/fpu/fesetmode.c
new file mode 100644
index 0000000..65977ef
--- /dev/null
+++ b/sysdeps/csky/fpu/fesetmode.c
@@ -0,0 +1,33 @@
+/* Install given floating-point control modes.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+
+int
+fesetmode (const femode_t *modep)
+{
+  femode_t mode;
+  if (modep == FE_DFL_MODE)
+    mode = _FPU_DEFAULT;
+  else
+    mode = *modep;
+  _FPU_SETCW (mode);
+
+  return 0;
+}
diff --git a/sysdeps/csky/fpu/fesetround.c b/sysdeps/csky/fpu/fesetround.c
new file mode 100644
index 0000000..c5c3604
--- /dev/null
+++ b/sysdeps/csky/fpu/fesetround.c
@@ -0,0 +1,32 @@
+/* Set current rounding direction.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <fenv_private.h>
+
+#include <stdio.h>
+int
+__fesetround (int round)
+{
+  libc_fesetround_vfp (round);
+  return 0;
+}
+libm_hidden_def (__fesetround)
+weak_alias (__fesetround, fesetround)
+libm_hidden_weak (fesetround)
diff --git a/sysdeps/csky/fpu/feupdateenv.c b/sysdeps/csky/fpu/feupdateenv.c
new file mode 100644
index 0000000..2368dee
--- /dev/null
+++ b/sysdeps/csky/fpu/feupdateenv.c
@@ -0,0 +1,46 @@
+/* Install given floating-point environment and raise exceptions.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <fenv_libc.h>
+#include <fenv_private.h>
+#include <stdio.h>
+
+int
+__feupdateenv (const fenv_t *envp)
+{
+  int temp;
+
+  /* Save current exceptions.  */
+  _FPU_GETFPSR (temp);
+  temp = (temp >> CAUSE_SHIFT) & FE_ALL_EXCEPT;
+  /* Install new environment.  */
+  libc_fesetenv_vfp (envp);
+
+  /* Raise the safed exception.  Incidently for us the implementation
+     defined format of the values in objects of type fexcept_t is the
+     same as the ones specified using the FE_* constants.  */
+  feraiseexcept (temp);
+
+  /* Success.  */
+  return 0;
+}
+libm_hidden_def (__feupdateenv)
+weak_alias (__feupdateenv, feupdateenv)
+libm_hidden_weak (feupdateenv)
diff --git a/sysdeps/csky/fpu/fgetexcptflg.c b/sysdeps/csky/fpu/fgetexcptflg.c
new file mode 100644
index 0000000..38c4df3
--- /dev/null
+++ b/sysdeps/csky/fpu/fgetexcptflg.c
@@ -0,0 +1,32 @@
+/* Store current representation for exceptions.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <fenv_libc.h>
+#include <fenv_private.h>
+#include <stdio.h>
+
+int
+fegetexceptflag (fexcept_t *flagp, int excepts)
+{
+  *flagp = libc_fetestexcept_vfp (excepts);
+
+  /* Success.  */
+  return 0;
+}
diff --git a/sysdeps/csky/fpu/fpu_control.h b/sysdeps/csky/fpu/fpu_control.h
new file mode 100644
index 0000000..8be2ee2
--- /dev/null
+++ b/sysdeps/csky/fpu/fpu_control.h
@@ -0,0 +1,133 @@
+/* FPU control word bits. C-SKY version.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef _FPU_CONTROL_H
+#define _FPU_CONTROL_H
+
+/* C-SKY FPU floating point control register bits.
+
+   31-28  -> reserved (read as 0, write with 0)
+   27     -> 0: flush denormalized results to zero
+             1: flush denormalized results to signed minimal normal number.
+   26     -> reserved (read as 0, write with 0)
+   25-24  -> rounding control
+   23-6   -> reserved (read as 0, write with 0)
+    5     -> enable exception for input denormalized exception
+    4     -> enable exception for inexact exception
+    3     -> enable exception for underflow exception
+    2     -> enable exception for overflow exception
+    1     -> enable exception for division by zero exception
+    0     -> enable exception for invalid operation exception
+
+   Rounding Control:
+   00 - rounding to nearest (RN)
+   01 - rounding toward zero (RZ)
+   10 - rounding (up) toward plus infinity (RP)
+   11 - rounding (down)toward minus infinity (RM)
+
+   C-SKY FPU floating point exception status register bits.
+
+   15     -> accumulate bit for any exception
+   14     -> reserved (read as 0, write with 0)
+   13     -> cause bit for input denormalized exception
+   12     -> cause bit for inexact exception
+   11     -> cause bit for underflow exception
+   10     -> cause bit for overflow exception
+    9     -> cause bit for division by zero exception
+    8     -> cause bit for invalid operation exception
+    7     -> flag bit for any exception
+    6     -> reserved (read as 0, write with 0)
+    5     -> flag exception for input denormalized exception
+    4     -> flag exception for inexact exception
+    3     -> flag exception for underflow exception
+    2     -> flag exception for overflow exception
+    1     -> flag exception for division by zero exception
+    0     -> flag exception for invalid operation exception  */
+
+#include <features.h>
+
+/* masking of interrupts */
+#define _FPU_MASK_IDE     (1 << 5)  /* input denormalized exception */
+#define _FPU_MASK_IXE     (1 << 4)  /* inexact exception            */
+#define _FPU_MASK_UFE     (1 << 3)  /* underflow exception          */
+#define _FPU_MASK_OFE     (1 << 2)  /* overflow exception           */
+#define _FPU_MASK_DZE     (1 << 1)  /* division by zero exception   */
+#define _FPU_MASK_IOE     (1 << 0)  /* invalid operation exception  */
+
+#define _FPU_MASK_FEA     (1 << 15) /* case for any exception */
+#define _FPU_MASK_FEC     (1 << 7)  /* flag for any exception */
+
+/* flush denormalized numbers to zero */
+#define _FPU_FLUSH_TZ   0x8000000
+
+/* rounding control */
+#define _FPU_RC_NEAREST (0x0 << 24)     /* RECOMMENDED */
+#define _FPU_RC_ZERO    (0x1 << 24)
+#define _FPU_RC_UP      (0x2 << 24)
+#define _FPU_RC_DOWN    (0x3 << 24)
+
+#define _FPU_RESERVED      0xf4ffffc0  /* Reserved bits in cw */
+#define _FPU_FPSR_RESERVED 0x3fff0000
+
+/* The fdlibm code requires strict IEEE double precision arithmetic,
+   and no interrupts for exceptions, rounding to nearest.  */
+
+#define _FPU_DEFAULT        0x00000000
+#define _FPU_FPSR_DEFAULT   0x00000000
+
+/* IEEE:  same as above, but exceptions */
+#define _FPU_FPCR_IEEE     0x0000001F
+#define _FPU_FPSR_IEEE     0x00000000
+
+/* Type of the control word.  */
+typedef unsigned int fpu_control_t;
+
+/* Macros for accessing the hardware control word.  */
+#if (__CSKY__ == 2)
+# define _FPU_GETCW(cw) __asm__ volatile ("mfcr %0, cr<1, 2>" : "=a" (cw))
+# define _FPU_SETCW(cw) __asm__ volatile ("mtcr %0, cr<1, 2>" : : "a" (cw))
+# define _FPU_GETFPSR(cw) __asm__ volatile ("mfcr %0, cr<2, 2>" : "=a" (cw))
+# define _FPU_SETFPSR(cw) __asm__ volatile ("mtcr %0, cr<2, 2>" : : "a" (cw))
+#else
+# define _FPU_GETCW(cw) __asm__ volatile ("1: cprcr  %0, cpcr2 \n"          \
+                                         "   btsti  %0, 31    \n"           \
+                                         "   bt     1b        \n"           \
+		                                 "   cprcr  %0, cpcr1\n" : "=b" (cw))
+
+# define _FPU_SETCW(cw) __asm__ volatile ("1: cprcr  r7, cpcr2 \n"          \
+                                         "   btsti  r7, 31    \n"           \
+                                         "   bt     1b        \n"           \
+                                         "   cpwcr  %0, cpcr1 \n"           \
+                                         : : "b" (cw) : "r7")
+
+# define _FPU_GETFPSR(cw) __asm__ volatile ("1: cprcr  %0, cpcr2 \n"        \
+                                           "   btsti  %0, 31    \n"         \
+                                           "   bt     1b        \n"         \
+                                           "   cprcr  %0, cpcr4\n" : "=b" (cw))
+
+# define _FPU_SETFPSR(cw) __asm__ volatile ("1: cprcr  r7, cpcr2 \n"        \
+                                           "   btsti  r7, 31    \n"         \
+                                           "   bt     1b        \n"         \
+                                           "   cpwcr %0, cpcr4  \n"         \
+                                           : : "b" (cw) : "r7")
+#endif /* __CSKY__ != 2 */
+
+/* Default control word set at startup.  */
+extern fpu_control_t __fpu_control;
+
+#endif	/* fpu_control.h */
diff --git a/sysdeps/csky/fpu/fraiseexcpt.c b/sysdeps/csky/fpu/fraiseexcpt.c
new file mode 100644
index 0000000..01fa0f2
--- /dev/null
+++ b/sysdeps/csky/fpu/fraiseexcpt.c
@@ -0,0 +1,126 @@
+/* Raise given exceptions.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fenv_libc.h>
+#include <fpu_control.h>
+#include <float.h>
+#include <math.h>
+
+int
+__feraiseexcept (int excepts)
+{
+    /* Raise exceptions represented by EXCEPTS.  But we must raise only one
+     signal at a time.  It is important that if the overflow/underflow
+     exception and the divide by zero exception are given at the same
+     time, the overflow/underflow exception follows the divide by zero
+     exception.  */
+
+# ifdef __csky_fpuv2__
+    /* First: invalid exception.  */
+    if (FE_INVALID & excepts)
+    {
+      /* One example of a invalid operation is 0 * Infinity.  */
+      float x = HUGE_VALF, y = 0.0f;
+      __asm__ __volatile__ ("fmuls %0, %0, %1" : "+v" (x) : "v" (y));
+    }
+
+    /* Next: division by zero.  */
+    if (FE_DIVBYZERO & excepts)
+    {
+      float x = 1.0f, y = 0.0f;
+      __asm__ __volatile__ ("fdivs %0, %0, %1" : "+v" (x) : "v" (y));
+    }
+
+    /* Next: overflow.  */
+    if (FE_OVERFLOW & excepts)
+    {
+      float x = FLT_MAX;
+      __asm__ __volatile__ ("fmuls %0, %0, %0" : "+v" (x));
+    }
+    /* Next: underflow.  */
+    if (FE_UNDERFLOW & excepts)
+    {
+      float x = -FLT_MIN;
+
+      __asm__ __volatile__ ("fmuls %0, %0, %0" : "+v" (x));
+    }
+
+    /* Last: inexact.  */
+    if (FE_INEXACT & excepts)
+    {
+      float x = 1.0f, y = 3.0f;
+      __asm__ __volatile__ ("fdivs %0, %0, %1" : "+v" (x) : "v" (y));
+    }
+
+    if (__FE_DENORMAL & excepts)
+    {
+      double x = 4.9406564584124654e-324;
+      __asm__ __volatile__ ("fstod %0, %0" : "+v" (x));
+    }
+# else
+     int tmp = 0;
+    /* First: invalid exception.  */
+    if (FE_INVALID & excepts)
+    {
+      /* One example of a invalid operation is 0 * Infinity.  */
+      float x = HUGE_VALF, y = 0.0f;
+      __asm__ __volatile__ ("fmuls %0, %0, %2, %1"
+                    : "+f" (x), "+r"(tmp) : "f" (y));
+    }
+
+    /* Next: division by zero.  */
+    if (FE_DIVBYZERO & excepts)
+    {
+      float x = 1.0f, y = 0.0f;
+      __asm__ __volatile__ ("fdivs %0, %0, %2, %1"
+                    : "+f" (x), "+r"(tmp) : "f" (y));
+    }
+
+    /* Next: overflow.  */
+    if (FE_OVERFLOW & excepts)
+    {
+      float x = FLT_MAX, y = FLT_MAX;
+      __asm__ __volatile__ ("fmuls %0, %0, %2, %1"
+                    : "+f" (x), "+r"(tmp) : "f" (y));
+    }
+
+    /* Next: underflow.  */
+    if (FE_UNDERFLOW & excepts)
+    {
+      float x = -FLT_MIN, y = -FLT_MIN;
+
+      __asm__ __volatile__ ("fmuls %0, %0, %2, %1"
+                    : "+f" (x), "+r"(tmp) : "f" (y));
+    }
+
+    /* Last: inexact.  */
+    if (FE_INEXACT & excepts)
+    {
+      float x = 1.0f, y = 3.0f;
+      __asm__ __volatile__ ("fdivs %0, %0, %2, %1"
+                    : "+f" (x), "+r"(tmp) : "f" (y));
+    }
+# endif /* __csky_fpuv2__ */
+
+    /* Success.  */
+    return 0;
+}
+libm_hidden_def (__feraiseexcept)
+weak_alias (__feraiseexcept, feraiseexcept)
+libm_hidden_weak (feraiseexcept)
diff --git a/sysdeps/csky/fpu/fsetexcptflg.c b/sysdeps/csky/fpu/fsetexcptflg.c
new file mode 100644
index 0000000..2eaa4cb
--- /dev/null
+++ b/sysdeps/csky/fpu/fsetexcptflg.c
@@ -0,0 +1,43 @@
+/* Set floating-point environment exception handling.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <fenv_libc.h>
+
+int
+fesetexceptflag (const fexcept_t *flagp, int excepts)
+{
+  fpu_control_t temp;
+
+  /* Get the current exceptions.  */
+   _FPU_GETFPSR (temp);
+
+  /* Make sure the flags we want restored are legal.  */
+  excepts &= FE_ALL_EXCEPT;
+
+  /* Now clear the bits called for, and copy them in from flagp. Note that
+     we ignore all non-flag bits from *flagp, so they don't matter.  */
+  temp = ((temp >> CAUSE_SHIFT) & ~excepts) | (*flagp & excepts);
+  temp = temp << CAUSE_SHIFT;
+
+  _FPU_SETFPSR (temp);
+
+  /* Success.  */
+  return 0;
+}
diff --git a/sysdeps/csky/fpu/ftestexcept.c b/sysdeps/csky/fpu/ftestexcept.c
new file mode 100644
index 0000000..fee7544
--- /dev/null
+++ b/sysdeps/csky/fpu/ftestexcept.c
@@ -0,0 +1,30 @@
+/* Test exception in current environment.
+   Copyright (C) 2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library.  If not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <fenv.h>
+#include <fpu_control.h>
+#include <fenv_libc.h>
+#include <fenv_private.h>
+#include <stdio.h>
+
+int
+fetestexcept (int excepts)
+{
+  return libc_fetestexcept_vfp (excepts);
+}
+libm_hidden_def (fetestexcept)
diff --git a/sysdeps/csky/fpu/math_private.h b/sysdeps/csky/fpu/math_private.h
new file mode 100644
index 0000000..db303da
--- /dev/null
+++ b/sysdeps/csky/fpu/math_private.h
@@ -0,0 +1,7 @@
+#ifndef CSKY_MATH_PRIVATE_H
+#define CSKY_MATH_PRIVATE_H 1
+
+#include "fenv_private.h"
+#include_next <math_private.h>
+
+#endif
-- 
2.7.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]