diff options
Diffstat (limited to 'libc/sysdeps/sh/sh4')
-rw-r--r-- | libc/sysdeps/sh/sh4/fpu/fedisblxcpt.c | 39 | ||||
-rw-r--r-- | libc/sysdeps/sh/sh4/fpu/feenablxcpt.c | 38 | ||||
-rw-r--r-- | libc/sysdeps/sh/sh4/fpu/fegetenv.c | 6 | ||||
-rw-r--r-- | libc/sysdeps/sh/sh4/fpu/fegetexcept.c | 35 | ||||
-rw-r--r-- | libc/sysdeps/sh/sh4/fpu/fesetround.c | 6 | ||||
-rw-r--r-- | libc/sysdeps/sh/sh4/fpu/feupdateenv.c | 39 | ||||
-rw-r--r-- | libc/sysdeps/sh/sh4/fpu/fraiseexcpt.c | 42 | ||||
-rw-r--r-- | libc/sysdeps/sh/sh4/fpu/ftestexcept.c | 3 |
8 files changed, 198 insertions, 10 deletions
diff --git a/libc/sysdeps/sh/sh4/fpu/fedisblxcpt.c b/libc/sysdeps/sh/sh4/fpu/fedisblxcpt.c new file mode 100644 index 000000000..029fcc386 --- /dev/null +++ b/libc/sysdeps/sh/sh4/fpu/fedisblxcpt.c @@ -0,0 +1,39 @@ +/* Disable floating-point exceptions. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Nobuhiro Iwamatsu <iwamatsu@nigauri.org>, 2012. + + 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 +fedisableexcept (int excepts) +{ + unsigned int temp, old_exc; + + /* Get the current control register contents. */ + _FPU_GETCW (temp); + + old_exc = (temp >> 5) & FE_ALL_EXCEPT; + + excepts &= FE_ALL_EXCEPT; + + temp &= ~(excepts << 5); + _FPU_SETCW (temp); + + return old_exc; +} diff --git a/libc/sysdeps/sh/sh4/fpu/feenablxcpt.c b/libc/sysdeps/sh/sh4/fpu/feenablxcpt.c new file mode 100644 index 000000000..93fa7498e --- /dev/null +++ b/libc/sysdeps/sh/sh4/fpu/feenablxcpt.c @@ -0,0 +1,38 @@ +/* Enable floating-point exceptions. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Nobuhiro Iwamatsu <iwamatsu@nigauri.org>, 2012. + + 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 +feenableexcept (int excepts) +{ + unsigned int temp, old_flag; + + /* Get current exceptions. */ + _FPU_GETCW (temp); + + old_flag = (temp >> 5) & FE_ALL_EXCEPT; + excepts &= FE_ALL_EXCEPT; + + temp |= excepts << 5; + _FPU_SETCW (temp); + + return old_flag; +} diff --git a/libc/sysdeps/sh/sh4/fpu/fegetenv.c b/libc/sysdeps/sh/sh4/fpu/fegetenv.c index 68687dc2d..3103316e3 100644 --- a/libc/sysdeps/sh/sh4/fpu/fegetenv.c +++ b/libc/sysdeps/sh/sh4/fpu/fegetenv.c @@ -1,5 +1,5 @@ /* Store current floating-point environment. - Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 1999, 2000, 2012 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 @@ -24,6 +24,10 @@ fegetenv (fenv_t *envp) { unsigned long int temp; _FPU_GETCW (temp); + /* When read fpscr, this was initialized. + We need to rewrite value of temp. */ + _FPU_SETCW (temp); + envp->__fpscr = temp; return 0; diff --git a/libc/sysdeps/sh/sh4/fpu/fegetexcept.c b/libc/sysdeps/sh/sh4/fpu/fegetexcept.c new file mode 100644 index 000000000..a849a1775 --- /dev/null +++ b/libc/sysdeps/sh/sh4/fpu/fegetexcept.c @@ -0,0 +1,35 @@ +/* Get enabled floating-point exceptions. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Nobuhiro Iwamatsu <iwamatsu@nigauri.org>, 2012. + + 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 +fegetexcept (void) +{ + unsigned int temp; + + /* Get current exceptions. */ + _FPU_GETCW (temp); + /* When read fpscr, this was initialized. + We need to rewrite value of temp. */ + _FPU_SETCW (temp); + + return (temp >> 5) & FE_ALL_EXCEPT; +} diff --git a/libc/sysdeps/sh/sh4/fpu/fesetround.c b/libc/sysdeps/sh/sh4/fpu/fesetround.c index 5df96d2d0..3269199ea 100644 --- a/libc/sysdeps/sh/sh4/fpu/fesetround.c +++ b/libc/sysdeps/sh/sh4/fpu/fesetround.c @@ -1,5 +1,5 @@ /* Set current rounding direction. - Copyright (C) 1998, 2000, 2005 Free Software Foundation, Inc. + Copyright (C) 1998, 2000, 2005, 2012 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Andreas Jaeger <aj@arthur.rhein-neckar.de>, 1998. @@ -27,7 +27,7 @@ fesetround (int round) if ((round & ~0x3) != 0) /* ROUND is no valid rounding mode. */ - return 0; + return 1; /* Get current state. */ _FPU_GETCW (cw); @@ -38,6 +38,6 @@ fesetround (int round) /* Set new state. */ _FPU_SETCW (cw); - return 1; + return 0; } libm_hidden_def (fesetround) diff --git a/libc/sysdeps/sh/sh4/fpu/feupdateenv.c b/libc/sysdeps/sh/sh4/fpu/feupdateenv.c new file mode 100644 index 000000000..96a697914 --- /dev/null +++ b/libc/sysdeps/sh/sh4/fpu/feupdateenv.c @@ -0,0 +1,39 @@ +/* Install given floating-point environment and raise exceptions. + Copyright (C) 2012 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Nobuhiro Iwamatsu <iwamatsu@nigauri.org>, 2012. + + 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 +feupdateenv (const fenv_t *envp) +{ + unsigned int temp; + + _FPU_GETCW (temp); + temp = (temp & FE_ALL_EXCEPT); + + /* Raise the saved 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. */ + fesetenv (envp); + feraiseexcept ((int) temp); + + return 0; +} +libm_hidden_def (feupdateenv) diff --git a/libc/sysdeps/sh/sh4/fpu/fraiseexcpt.c b/libc/sysdeps/sh/sh4/fpu/fraiseexcpt.c index 0bed3a529..a555b1088 100644 --- a/libc/sysdeps/sh/sh4/fpu/fraiseexcpt.c +++ b/libc/sysdeps/sh/sh4/fpu/fraiseexcpt.c @@ -1,6 +1,7 @@ /* Raise given exceptions. - Copyright (C) 1997, 1998, 2000, 2002 Free Software Foundation, Inc. + Copyright (C) 1997, 1998, 2000, 2002, 2012 Free Software Foundation, Inc. This file is part of the GNU C Library. + Contributed by Nobuhiro Iwamatsu <iwamatsu@nigauri.org>, 2012. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -17,18 +18,47 @@ <http://www.gnu.org/licenses/>. */ #include <fenv.h> +#include <float.h> #include <fpu_control.h> #include <math.h> int feraiseexcept (int excepts) { + if (excepts == 0) + return 0; + /* Raise exceptions represented by EXPECTS. */ - fexcept_t temp; - _FPU_GETCW (temp); - temp |= (excepts & FE_ALL_EXCEPT); - temp |= (excepts & FE_ALL_EXCEPT) << 5; - _FPU_SETCW (temp); + + if (excepts & FE_INEXACT) + { + double d = 1.0, x = 3.0; + __asm__ __volatile__ ("fdiv %1, %0" : "+d" (d) : "d" (x)); + } + + if (excepts & FE_UNDERFLOW) + { + long double d = LDBL_MIN, x = 10; + __asm__ __volatile__ ("fdiv %1, %0" : "+d" (d) : "d" (x)); + } + + if (excepts & FE_OVERFLOW) + { + long double d = LDBL_MAX; + __asm__ __volatile__ ("fmul %0, %0" : "+d" (d) : "d" (d)); + } + + if (excepts & FE_DIVBYZERO) + { + double d = 1.0, x = 0.0; + __asm__ __volatile__ ("fdiv %1, %0" : "+d" (d) : "d" (x)); + } + + if (excepts & FE_INVALID) + { + double d = HUGE_VAL, x = 0.0; + __asm__ __volatile__ ("fmul %1, %0" : "+d" (d) : "d" (x)); + } return 0; } diff --git a/libc/sysdeps/sh/sh4/fpu/ftestexcept.c b/libc/sysdeps/sh/sh4/fpu/ftestexcept.c index 9e0bfc5c2..c2e1772a9 100644 --- a/libc/sysdeps/sh/sh4/fpu/ftestexcept.c +++ b/libc/sysdeps/sh/sh4/fpu/ftestexcept.c @@ -26,6 +26,9 @@ fetestexcept (int excepts) /* Get current exceptions. */ _FPU_GETCW (temp); + /* When read fpscr, this was initialized. + We need to rewrite value of temp. */ + _FPU_SETCW (temp); return temp & excepts & FE_ALL_EXCEPT; } |