diff options
author | Vincent Ren-Wei Chen <vincentc@andestech.com> | 2017-01-17 07:31:24 +0100 |
---|---|---|
committer | Waldemar Brodkorb <wbx@openadk.org> | 2017-01-22 10:06:29 +0100 |
commit | 6af3332a4cbd1ffbc81f74759ef7c5e1a87d2e10 (patch) | |
tree | 4deae5f23fd1e2664f21c09dfb57fda799dffd10 /libm | |
parent | 82af21a60bc6e53dd92c1c140f20179d2ae4ad40 (diff) |
nds32: add NPTL/TLS, *context function, libm changes and code cleanup
This commit includes following features.
1. Support NPTL/TLS
2. Add libm function which is used to handle FP rounding and excpetions
(ex: fclrexcpt,fedisblxcpti,feenablxcpt... )
3. Add *context function for operating user context
(ex: setcontext,getcontext,makecontext... )
4. Change the return flow from signal handler
5. Cleanup of old code
The testsuite only has 2 errors, tst-cpuclock1 and tst-cputimer1,
which are related to timing accuracy. (math and locale tests are disabled)
Signed-off-by: Vincent Ren-Wei Chen <vincentc@andestech.com>
Diffstat (limited to 'libm')
-rw-r--r-- | libm/nds32/Makefile.arch | 16 | ||||
-rw-r--r-- | libm/nds32/e_sqrt.c | 34 | ||||
-rw-r--r-- | libm/nds32/fclrexcpt.c | 52 | ||||
-rw-r--r-- | libm/nds32/fedisblxcpt.c | 49 | ||||
-rw-r--r-- | libm/nds32/feenablxcpt.c | 50 | ||||
-rw-r--r-- | libm/nds32/fegetenv.c | 40 | ||||
-rw-r--r-- | libm/nds32/fegetexcept.c | 41 | ||||
-rw-r--r-- | libm/nds32/fegetround.c | 40 | ||||
-rw-r--r-- | libm/nds32/feholdexcpt.c | 51 | ||||
-rw-r--r-- | libm/nds32/fenv_libc.h | 33 | ||||
-rw-r--r-- | libm/nds32/fesetenv.c | 51 | ||||
-rw-r--r-- | libm/nds32/fesetround.c | 42 | ||||
-rw-r--r-- | libm/nds32/feupdateenv.c | 48 | ||||
-rw-r--r-- | libm/nds32/fgetexcptflg.c | 44 | ||||
-rw-r--r-- | libm/nds32/fraiseexcpt.c | 104 | ||||
-rw-r--r-- | libm/nds32/fsetexcptflg.c | 48 | ||||
-rw-r--r-- | libm/nds32/ftestexcept.c | 40 |
17 files changed, 783 insertions, 0 deletions
diff --git a/libm/nds32/Makefile.arch b/libm/nds32/Makefile.arch new file mode 100644 index 000000000..bd38690be --- /dev/null +++ b/libm/nds32/Makefile.arch @@ -0,0 +1,16 @@ +# Makefile for uClibc-ng +# Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball. + +ifeq ($(UCLIBC_HAS_FENV),y) +libm_ARCH_SRC:=$(wildcard $(libm_ARCH_DIR)/*.c) +libm_ARCH_OBJ:=$(patsubst $(libm_ARCH_DIR)/%.c,$(libm_ARCH_OUT)/%.o,$(libm_ARCH_SRC)) +endif + +libm_ARCH_OBJS:=$(libm_ARCH_OBJ) + +ifeq ($(DOPIC),y) +libm-a-y+=$(libm_ARCH_OBJS:.o=.os) +else +libm-a-y+=$(libm_ARCH_OBJS) +endif +libm-so-y+=$(libm_ARCH_OBJS:.o=.os) diff --git a/libm/nds32/e_sqrt.c b/libm/nds32/e_sqrt.c new file mode 100644 index 000000000..c737e10c6 --- /dev/null +++ b/libm/nds32/e_sqrt.c @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Copyright (C) 2002-2013 Free Software Foundation, Inc. + + 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/>. */ + +#if defined(__NDS32_ABI_2FP_PLUS__) && defined(__NDS32_EXT_FPU_DP__) + +double __ieee754_sqrt (double x) +{ + double z; + __asm__ ("fsqrtd %0,%1" : "=f" (z) : "f" (x)); + return z; +} +strong_alias(__ieee754_sqrt, sqrt) +libm_hidden_def(sqrt) +#else +#include <libm/e_sqrt.c> +#endif diff --git a/libm/nds32/fclrexcpt.c b/libm/nds32/fclrexcpt.c new file mode 100644 index 000000000..938f15a25 --- /dev/null +++ b/libm/nds32/fclrexcpt.c @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Clear given exceptions in current floating-point environment. + Copyright (C) 1997-2013 Free Software Foundation, Inc. + + 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) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + unsigned long int temp; + + /* Mask out unsupported bits/exceptions. */ + excepts &= FE_ALL_EXCEPT; + + /* Get the current floating point status. */ + _FPU_GETCW (temp); + + /* Clear the relevant bits. */ + temp &= ~excepts; + + /* Put the new data in effect. */ + _FPU_SETCW (temp); + + /* Success. */ + return 0; +#else + /* Unsupported, so fail unless nothing needs to be done. */ + return (excepts != 0); +#endif +} diff --git a/libm/nds32/fedisblxcpt.c b/libm/nds32/fedisblxcpt.c new file mode 100644 index 000000000..bbb6d54e4 --- /dev/null +++ b/libm/nds32/fedisblxcpt.c @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Disable floating-point exceptions. + Copyright (C) 2001-2013 Free Software Foundation, Inc. + Contributed by Philip Blundell <philb@gnu.org>, 2001. + + 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) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + unsigned long int new_exc, old_exc; + + _FPU_GETCW(new_exc); + + old_exc = (new_exc & ENABLE_MASK) >> ENABLE_SHIFT; + + excepts &= FE_ALL_EXCEPT; + + new_exc &= ~(excepts << ENABLE_SHIFT); + new_exc &= ~_FPU_RESERVED; + _FPU_SETCW (new_exc); + + return old_exc; +#else + /* Unsupported, so return -1 for failure. */ + return -1; +#endif +} diff --git a/libm/nds32/feenablxcpt.c b/libm/nds32/feenablxcpt.c new file mode 100644 index 000000000..14aef9850 --- /dev/null +++ b/libm/nds32/feenablxcpt.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Enable floating-point exceptions. + Copyright (C) 2001-2013 Free Software Foundation, Inc. + Contributed by Philip Blundell <philb@gnu.org>, 2001. + + 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) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + unsigned long int new_exc, old_exc; + + _FPU_GETCW(new_exc); + + old_exc = (new_exc & ENABLE_MASK) >> ENABLE_SHIFT; + + excepts &= FE_ALL_EXCEPT; + + new_exc |= (excepts << ENABLE_SHIFT); + new_exc &= ~_FPU_RESERVED; + + _FPU_SETCW(new_exc); + + return old_exc; +#else + /* Unsupported, so return -1 for failure. */ + return -1; +#endif +} diff --git a/libm/nds32/fegetenv.c b/libm/nds32/fegetenv.c new file mode 100644 index 000000000..782cf793e --- /dev/null +++ b/libm/nds32/fegetenv.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Store current floating-point environment. + Copyright (C) 1997-2013 Free Software Foundation, Inc. + + 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) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + unsigned long int temp; + _FPU_GETCW (temp); + envp->__fpcsr = temp; + + /* Success. */ + return 0; +#else + /* Unsupported, so fail. */ + return 1; +#endif +} diff --git a/libm/nds32/fegetexcept.c b/libm/nds32/fegetexcept.c new file mode 100644 index 000000000..1ffe361cc --- /dev/null +++ b/libm/nds32/fegetexcept.c @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Get floating-point exceptions. + Copyright (C) 2001-2013 Free Software Foundation, Inc. + Contributed by Philip Blundell <philb@gnu.org>, 2001 + + 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) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + unsigned long temp; + + _FPU_GETCW (temp); + + return (temp & ENABLE_MASK) >> ENABLE_SHIFT; +#else + /* Unsupported. Return all exceptions disabled. */ + return 0; +#endif +} diff --git a/libm/nds32/fegetround.c b/libm/nds32/fegetround.c new file mode 100644 index 000000000..e4e70eaad --- /dev/null +++ b/libm/nds32/fegetround.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Return current rounding direction. + Copyright (C) 2004-2013 Free Software Foundation, Inc. + + 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) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + unsigned int temp; + + /* Get the current environment. */ + _FPU_GETCW (temp); + + return temp & 0x3; +#else + /* The current soft-float implementation only handles TONEAREST. */ + return FE_TONEAREST; +#endif +} diff --git a/libm/nds32/feholdexcpt.c b/libm/nds32/feholdexcpt.c new file mode 100644 index 000000000..4ea3679f5 --- /dev/null +++ b/libm/nds32/feholdexcpt.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Store current floating-point environment and clear exceptions. + Copyright (C) 1997-2013 Free Software Foundation, Inc. + + 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 +feholdexcept (fenv_t *envp) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + unsigned long int temp; + + /* Store the environment. */ + _FPU_GETCW(temp); + envp->__fpcsr = temp; + + /* Now set all exceptions to non-stop. */ + temp &= ~(FE_ALL_EXCEPT << ENABLE_SHIFT); + + /* And clear all exception flags. */ + temp &= ~FE_ALL_EXCEPT; + + _FPU_SETCW(temp); + + return 0; +#else + /* Unsupported, so fail. */ + return 1; +#endif +} + diff --git a/libm/nds32/fenv_libc.h b/libm/nds32/fenv_libc.h new file mode 100644 index 000000000..a76f131e4 --- /dev/null +++ b/libm/nds32/fenv_libc.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Copyright (C) 2000-2013 Free Software Foundation, Inc. + Contributed by Alexandre Oliva <aoliva@redhat.com> + based on the corresponding file in the mips port. + + 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 + +/* Mask for enabling exceptions and for the CAUSE bits. */ +#define ENABLE_MASK 0x00F80U + +/* Shift for FE_* flags to get up to the ENABLE bits. */ +#define ENABLE_SHIFT 5 + +#endif /* _FENV_LIBC_H */ diff --git a/libm/nds32/fesetenv.c b/libm/nds32/fesetenv.c new file mode 100644 index 000000000..4682d3c8e --- /dev/null +++ b/libm/nds32/fesetenv.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Install given floating-point environment. + Copyright (C) 2004-2013 Free Software Foundation, Inc. + + 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) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + unsigned int temp; + + _FPU_GETCW (temp); + temp &= _FPU_RESERVED; + + if (envp == FE_DFL_ENV) + temp |= _FPU_DEFAULT; + else if (envp == FE_NOMASK_ENV) + temp |= _FPU_IEEE; + else + temp |= envp->__fpcsr & ~_FPU_RESERVED; + + _FPU_SETCW (temp); + + /* Success. */ + return 0; +#else + + /* Unsupported, so fail. */ + return 1; +#endif +} diff --git a/libm/nds32/fesetround.c b/libm/nds32/fesetround.c new file mode 100644 index 000000000..012a5bfff --- /dev/null +++ b/libm/nds32/fesetround.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Set current rounding direction. + Copyright (C) 2004-2013 Free Software Foundation, Inc. + + 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 +fesetround (int round) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + fpu_control_t temp; + if ((round & ~0x3) != 0) + /* ROUND is no valid rounding mode. */ + return 1; + + _FPU_GETCW (temp); + temp = (temp & ~0x3) | round; + _FPU_SETCW (temp); + return 0; +#else + return (round != FE_TONEAREST); +#endif +} diff --git a/libm/nds32/feupdateenv.c b/libm/nds32/feupdateenv.c new file mode 100644 index 000000000..d58c9004b --- /dev/null +++ b/libm/nds32/feupdateenv.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Install given floating-point environment and raise exceptions. + Copyright (C) 1997-2013 Free Software Foundation, Inc. + Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. + + 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) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + unsigned int temp; + + /* Get the current exception state. */ + _FPU_GETCW (temp); + + /* Install new environment. */ + fesetenv (envp); + + /* Raise the saved exceptions. */ + feraiseexcept (temp & FE_ALL_EXCEPT); + + /* Success. */ + return 0; +#else + /* Unsupported, so fail. */ + return 1; +#endif +} diff --git a/libm/nds32/fgetexcptflg.c b/libm/nds32/fgetexcptflg.c new file mode 100644 index 000000000..e446c429c --- /dev/null +++ b/libm/nds32/fgetexcptflg.c @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Store current representation for exceptions. + Copyright (C) 1997-2013 Free Software Foundation, Inc. + Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997. + + 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 +fegetexceptflag (fexcept_t *flagp, int excepts) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + fpu_control_t temp; + + /* Get the current exceptions. */ + _FPU_GETCW (temp); + + *flagp = temp & excepts & FE_ALL_EXCEPT; + + /* Success. */ + return 0; +#else + /* Unsupported, so fail. */ + return 1; +#endif +} diff --git a/libm/nds32/fraiseexcpt.c b/libm/nds32/fraiseexcpt.c new file mode 100644 index 000000000..d1942110c --- /dev/null +++ b/libm/nds32/fraiseexcpt.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Raise given exceptions. + Copyright (C) 2004-2013 Free Software Foundation, Inc. + + 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 <fpu_control.h> +#include <fenv.h> +#include <float.h> +#include "fenv_libc.h" + +int +feraiseexcept (int excepts) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + float temp1 = 0.0, temp2 = 1.0; + if (FE_INVALID & excepts) + { + __asm__ volatile( + "fmtsr\t %0, $fs0\n\t" + "fdivs\t $fs0, $fs0, $fs0\n\t" + : + :"r"(temp1) + :"$fs0" + ); + } + if (FE_DIVBYZERO & excepts) + { + __asm__ volatile( + "fmtsr\t %0, $fs0\n\t" + "fmtsr\t %1, $fs1\n\t" + "fdivs\t $fs0, $fs1, $fs0\n\t" + : + :"r"(temp1),"r"(temp2) + :"$fs0" + ); + } + if (FE_OVERFLOW & excepts) + { + /* There's no way to raise overflow without also raising inexact. + */ + unsigned int fpcsr; + temp1 = FLT_MAX; + __asm__ volatile( + "fmfcsr\t %0\n\t" + "fmtsr\t %1, $fs0\n\t" + "fadds\t $fs0, $fs0, $fs0\n\t" + "ori\t %0,%0,0x10\n\t" + "fmtcsr\t %0\n\t" + :"=&r"(fpcsr) + :"r"(temp1) + :"$fs0" + ); + } + if (FE_UNDERFLOW & excepts) + { + /* There's no way to raise overflow without also raising inexact. + */ + temp1 = FLT_MIN; + temp2 = 2.0; + __asm__ volatile( + "fmtsr\t %0, $fs0\n\t" + "fmtsr\t %1, $fs1\n\t" + "fdivs\t $fs1, $fs0, $fs1\n\t" + : + :"r"(temp1),"r"(temp2) + :"$fs0","$fs1" + ); + } + if (FE_INEXACT & excepts) + { + temp1 = 3.0; + __asm__ volatile( + "fmtsr\t %0, $fs1\n\t" + "fmtsr\t %1, $fs0\n\t" + "fdivs\t $fs1, $fs0, $fs1\n\t" + : + :"r"(temp1),"r"(temp2) + :"$fs0","$fs1" + ); + } + + return 0; + +#endif + /* Unsupported, so fail unless nothing needs to be done. */ + return (excepts != 0); +} diff --git a/libm/nds32/fsetexcptflg.c b/libm/nds32/fsetexcptflg.c new file mode 100644 index 000000000..7da943b9d --- /dev/null +++ b/libm/nds32/fsetexcptflg.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Set floating-point environment exception handling. + Copyright (C) 1997-2013 Free Software Foundation, Inc. + + 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 +fesetexceptflag (const fexcept_t *flagp, int excepts) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + fexcept_t temp; + + /* Get the current environment. */ + _FPU_GETCW (temp); + + /* Set the desired exception mask. */ + temp &= ~(excepts & FE_ALL_EXCEPT); + temp |= (*flagp & excepts & FE_ALL_EXCEPT); + + /* Save state back to the FPU. */ + _FPU_SETCW (temp); + + /* Success. */ + return 0; +#else + /* Unsupported, so fail unless nothing needs to be done. */ + return (excepts != 0); +#endif +} diff --git a/libm/nds32/ftestexcept.c b/libm/nds32/ftestexcept.c new file mode 100644 index 000000000..8257b6f45 --- /dev/null +++ b/libm/nds32/ftestexcept.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2016-2017 Andes Technology, Inc. + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ + +/* Test exception in current environment. + Copyright (C) 1997-2013 Free Software Foundation, Inc. + + 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 +fetestexcept (int excepts) +{ +#ifdef __NDS32_ABI_2FP_PLUS__ + fexcept_t temp; + + /* Get current exceptions. */ + _FPU_GETCW(temp); + + return temp & excepts & FE_ALL_EXCEPT; +#else + /* Unsupported, return 0. */ + return 0; +#endif +} |