Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexey Lapshin <alexey.lapshin@espressif.com>2023-08-17 01:05:53 +0300
committerJeff Johnston <jjohnstn@redhat.com>2023-08-18 01:14:15 +0300
commit7ba103eb1a95703c7803e4ca48e6ba5c8e1f3d56 (patch)
tree36b6a578131e28363728a2ed685d66348c747d78 /newlib/libm
parent65d34484e9097fd9036dd577028423355cb5f5bc (diff)
newlib: add Xtensa port
Diffstat (limited to 'newlib/libm')
-rw-r--r--newlib/libm/Makefile.inc3
-rw-r--r--newlib/libm/acinclude.m43
-rw-r--r--newlib/libm/machine/xtensa/Makefile.inc12
-rw-r--r--newlib/libm/machine/xtensa/acinclude.m411
-rw-r--r--newlib/libm/machine/xtensa/ef_sqrt.c7
-rw-r--r--newlib/libm/machine/xtensa/feclearexcept.c48
-rw-r--r--newlib/libm/machine/xtensa/fegetenv.c55
-rw-r--r--newlib/libm/machine/xtensa/fegetexcept.c67
-rw-r--r--newlib/libm/machine/xtensa/fegetexceptflag.c63
-rw-r--r--newlib/libm/machine/xtensa/fegetround.c50
-rw-r--r--newlib/libm/machine/xtensa/feholdexcept.c54
-rw-r--r--newlib/libm/machine/xtensa/feraiseexcept.c49
-rw-r--r--newlib/libm/machine/xtensa/fetestexcept.c41
-rw-r--r--newlib/libm/machine/xtensa/feupdateenv.c46
14 files changed, 508 insertions, 1 deletions
diff --git a/newlib/libm/Makefile.inc b/newlib/libm/Makefile.inc
index 075693a73..28b84bfe2 100644
--- a/newlib/libm/Makefile.inc
+++ b/newlib/libm/Makefile.inc
@@ -92,6 +92,9 @@ if HAVE_LIBM_MACHINE_X86_64
include %D%/machine/x86_64/Makefile.inc
include %D%/ld80/Makefile.inc
endif
+if HAVE_LIBM_MACHINE_XTENSA
+include %D%/machine/xtensa/Makefile.inc
+endif
CLEANFILES += \
%D%/targetdep.tex \
diff --git a/newlib/libm/acinclude.m4 b/newlib/libm/acinclude.m4
index f7f9f534f..f6d88d411 100644
--- a/newlib/libm/acinclude.m4
+++ b/newlib/libm/acinclude.m4
@@ -1,10 +1,11 @@
dnl We have to include these unconditionally since machines might want to use
dnl AM_CONDITIONAL in their subdirs.
m4_include([libm/machine/nds32/acinclude.m4])
+m4_include([libm/machine/xtensa/acinclude.m4])
dnl Define HAVE_LIBM_MACHINE_<machine> automake conditionals.
m4_foreach_w([MACHINE], [
- aarch64 amdgcn arm i386 mips nds32 powerpc pru sparc spu riscv x86_64
+ aarch64 amdgcn arm i386 mips nds32 powerpc pru sparc spu riscv x86_64 xtensa
], [dnl
AM_CONDITIONAL([HAVE_LIBM_MACHINE_]m4_toupper(MACHINE), test "${libm_machine_dir}" = "MACHINE")
])
diff --git a/newlib/libm/machine/xtensa/Makefile.inc b/newlib/libm/machine/xtensa/Makefile.inc
new file mode 100644
index 000000000..3c95a56dd
--- /dev/null
+++ b/newlib/libm/machine/xtensa/Makefile.inc
@@ -0,0 +1,12 @@
+%C%_src = \
+ %D%/feclearexcept.c %D%/fegetenv.c %D%/fegetexcept.c %D%/fegetexceptflag.c \
+ %D%/fegetround.c %D%/feholdexcept.c %D%/feraiseexcept.c %D%/fetestexcept.c \
+ %D%/feupdateenv.c
+
+if XTENSA_XCHAL_HAVE_FP_SQRT
+%C%_src += \
+ %D%/ef_sqrt.c
+endif
+
+libm_a_CFLAGS_%C% = -D_LIBM
+libm_a_SOURCES += $(%C%_src)
diff --git a/newlib/libm/machine/xtensa/acinclude.m4 b/newlib/libm/machine/xtensa/acinclude.m4
new file mode 100644
index 000000000..4d242e057
--- /dev/null
+++ b/newlib/libm/machine/xtensa/acinclude.m4
@@ -0,0 +1,11 @@
+AC_CACHE_CHECK([for XCHAL_HAVE_FP_SQRT], newlib_cv_xchal_have_fp_sqrt, [dnl
+ AC_PREPROC_IFELSE([AC_LANG_PROGRAM(
+[[#define _LIBM
+// targ-include does not exist yet, use relative path
+#include "../sys/xtensa/include/xtensa/config/core-isa.h"
+#if (!XCHAL_HAVE_FP_SQRT)
+# error "Have not XCHAL_HAVE_FP_SQRT"
+#endif
+]])], [newlib_cv_xchal_have_fp_sqrt="yes"], [newlib_cv_xchal_have_fp_sqrt="no"])])
+
+AM_CONDITIONAL(XTENSA_XCHAL_HAVE_FP_SQRT, test "$newlib_cv_xchal_have_fp_sqrt" = "yes")
diff --git a/newlib/libm/machine/xtensa/ef_sqrt.c b/newlib/libm/machine/xtensa/ef_sqrt.c
new file mode 100644
index 000000000..39e8d7584
--- /dev/null
+++ b/newlib/libm/machine/xtensa/ef_sqrt.c
@@ -0,0 +1,7 @@
+#include <xtensa/config/core-isa.h>
+
+#if !XCHAL_HAVE_FP_SQRT
+#error "__ieee754_sqrtf from common libm must be used"
+#else
+/* Built-in GCC __ieee754_sqrtf must be used */
+#endif
diff --git a/newlib/libm/machine/xtensa/feclearexcept.c b/newlib/libm/machine/xtensa/feclearexcept.c
new file mode 100644
index 000000000..f1bd84f96
--- /dev/null
+++ b/newlib/libm/machine/xtensa/feclearexcept.c
@@ -0,0 +1,48 @@
+/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <xtensa/config/core-isa.h>
+
+#if XCHAL_HAVE_FP || XCHAL_HAVE_DFP
+
+#include <fenv.h>
+
+
+int feclearexcept(int except)
+{
+ unsigned int fsr;
+
+ if (except & ~FE_ALL_EXCEPT)
+ return -1;
+ except <<= _FE_EXCEPTION_FLAGS_OFFSET;
+ asm ("rur.fsr %0" : "=a"(fsr));
+ fsr = fsr & ~except;
+ asm ("wur.fsr %0" : : "a"(fsr));
+ return 0;
+}
+
+#endif
diff --git a/newlib/libm/machine/xtensa/fegetenv.c b/newlib/libm/machine/xtensa/fegetenv.c
new file mode 100644
index 000000000..b3984ee84
--- /dev/null
+++ b/newlib/libm/machine/xtensa/fegetenv.c
@@ -0,0 +1,55 @@
+/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <xtensa/config/core-isa.h>
+
+#if XCHAL_HAVE_FP || XCHAL_HAVE_DFP
+
+#include <fenv.h>
+
+int fegetenv(fenv_t * env_ptr)
+{
+ unsigned int fsr;
+ unsigned int fcr;
+ asm ("rur.fsr %0" : "=a"(fsr));
+ asm ("rur.fcr %0" : "=a"(fcr));
+ *env_ptr = fsr | fcr;
+ return 0;
+}
+
+
+int fesetenv(const fenv_t * env_ptr)
+{
+ fenv_t env = *env_ptr;
+ if (env & ~(_FE_FLOATING_ENV_MASK))
+ return -1;
+ asm ("wur.fsr %0" : : "a"(*env_ptr));
+ asm ("wur.fcr %0" : : "a"(*env_ptr));
+ return 0;
+}
+
+#endif
diff --git a/newlib/libm/machine/xtensa/fegetexcept.c b/newlib/libm/machine/xtensa/fegetexcept.c
new file mode 100644
index 000000000..250917c3e
--- /dev/null
+++ b/newlib/libm/machine/xtensa/fegetexcept.c
@@ -0,0 +1,67 @@
+/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <xtensa/config/core-isa.h>
+
+#if XCHAL_HAVE_FP || XCHAL_HAVE_DFP
+
+/* These functions are glibc extensions. */
+
+#include <fenv.h>
+
+int fegetexcept(void)
+{
+ fexcept_t current;
+ asm ("rur.fsr %0" : "=a"(current));
+ return (current >> _FE_EXCEPTION_ENABLE_OFFSET) & FE_ALL_EXCEPT;
+}
+
+
+int feenableexcept(int excepts)
+{
+ fexcept_t current;
+ if (excepts & ~FE_ALL_EXCEPT)
+ return -1;
+ asm ("rur.fcr %0" : "=a"(current));
+ current |= excepts << _FE_EXCEPTION_ENABLE_OFFSET;
+ asm ("wur.fcr %0" : "=a"(current));
+ return 0;
+}
+
+
+int fedisableexcept(int excepts)
+{
+ fexcept_t current;
+ if (excepts & ~FE_ALL_EXCEPT)
+ return -1;
+ asm ("rur.fcr %0" : "=a"(current));
+ current &= ~(excepts << _FE_EXCEPTION_ENABLE_OFFSET);
+ asm ("wur.fcr %0" : "=a"(current));
+ return 0;
+}
+
+#endif
diff --git a/newlib/libm/machine/xtensa/fegetexceptflag.c b/newlib/libm/machine/xtensa/fegetexceptflag.c
new file mode 100644
index 000000000..6d9e7e6ac
--- /dev/null
+++ b/newlib/libm/machine/xtensa/fegetexceptflag.c
@@ -0,0 +1,63 @@
+/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <xtensa/config/core-isa.h>
+
+#if XCHAL_HAVE_FP || XCHAL_HAVE_DFP
+
+#include <fenv.h>
+
+int fegetexceptflag(fexcept_t *flagp, int excepts)
+{
+ unsigned int fsr;
+ if (excepts & ~FE_ALL_EXCEPT)
+ return -1;
+ asm ("rur.fsr %0" : "=a"(fsr));
+ fsr >>= _FE_EXCEPTION_FLAGS_OFFSET;
+ excepts &= fsr;
+ *flagp = excepts;
+
+ return 0;
+}
+
+
+int fesetexceptflag(const fexcept_t *flagp, int excepts)
+{
+ if (excepts & ~FE_ALL_EXCEPT)
+ return -1;
+
+ unsigned int fsr;
+
+ asm ("rur.fsr %0" : "=a"(fsr));
+
+ fsr &= ~(excepts << _FE_EXCEPTION_FLAGS_OFFSET);
+ fsr |= ((*flagp & excepts) << _FE_EXCEPTION_FLAGS_OFFSET);
+ asm ("wur.fsr %0" : : "a"(fsr));
+ return 0;
+}
+
+#endif
diff --git a/newlib/libm/machine/xtensa/fegetround.c b/newlib/libm/machine/xtensa/fegetround.c
new file mode 100644
index 000000000..f17be6dc1
--- /dev/null
+++ b/newlib/libm/machine/xtensa/fegetround.c
@@ -0,0 +1,50 @@
+/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <xtensa/config/core-isa.h>
+
+#if XCHAL_HAVE_FP || XCHAL_HAVE_DFP
+
+#include <fenv.h>
+
+int fegetround(void)
+{
+ fexcept_t current;
+ asm ("rur.fcr %0" : "=a"(current));
+ return (current & _FE_ROUND_MODE_MASK) >> _FE_ROUND_MODE_OFFSET;
+}
+
+
+int fesetround(int round)
+{
+ if (round & ~_FE_ROUND_MODE_MASK)
+ return -1;
+ asm ("wur.fcr %0" : : "a"(round));
+ return 0;
+}
+
+#endif
diff --git a/newlib/libm/machine/xtensa/feholdexcept.c b/newlib/libm/machine/xtensa/feholdexcept.c
new file mode 100644
index 000000000..32e5e0b3b
--- /dev/null
+++ b/newlib/libm/machine/xtensa/feholdexcept.c
@@ -0,0 +1,54 @@
+/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <xtensa/config/core-isa.h>
+
+#if XCHAL_HAVE_FP || XCHAL_HAVE_DFP
+
+#include <fenv.h>
+
+int feholdexcept(fenv_t * envp)
+{
+ fexcept_t fsr;
+ fenv_t fcr;
+ /* Get the environment. */
+ asm ("rur.fcr %0" : "=a"(fcr));
+ asm ("rur.fsr %0" : "=a"(fsr));
+ *envp = fsr | fcr;
+
+ /* Clear the exception enable flags. */
+ fcr &= _FE_ROUND_MODE_MASK;
+ asm ("wur.fcr %0" : :"a"(fcr));
+
+ /* Clear the exception happened flags. */
+ fsr = 0;
+ asm ("wur.fsr %0" : :"a"(fsr));
+
+ return 0;
+}
+
+#endif
diff --git a/newlib/libm/machine/xtensa/feraiseexcept.c b/newlib/libm/machine/xtensa/feraiseexcept.c
new file mode 100644
index 000000000..8d418f0fe
--- /dev/null
+++ b/newlib/libm/machine/xtensa/feraiseexcept.c
@@ -0,0 +1,49 @@
+/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <xtensa/config/core-isa.h>
+
+#if XCHAL_HAVE_FP || XCHAL_HAVE_DFP
+
+/* Xtensa doesn't trap, so setting the flags is the best we can
+ do. */
+
+#include <fenv.h>
+
+int feraiseexcept(int excepts)
+{
+ fexcept_t current;
+
+ if (excepts & ~FE_ALL_EXCEPT)
+ return -1;
+ asm ("rur.fsr %0" : "=a"(current));
+ current |= excepts << _FE_EXCEPTION_FLAGS_OFFSET;
+ asm ("wur.fsr %0" : : "a"(current));
+ return 0;
+}
+
+#endif
diff --git a/newlib/libm/machine/xtensa/fetestexcept.c b/newlib/libm/machine/xtensa/fetestexcept.c
new file mode 100644
index 000000000..295085949
--- /dev/null
+++ b/newlib/libm/machine/xtensa/fetestexcept.c
@@ -0,0 +1,41 @@
+/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <xtensa/config/core-isa.h>
+
+#if XCHAL_HAVE_FP || XCHAL_HAVE_DFP
+
+#include <fenv.h>
+
+int fetestexcept(int excepts)
+{
+ fexcept_t current;
+ asm ("rur.fsr %0" : "=a"(current));
+ return (current >> _FE_EXCEPTION_FLAGS_OFFSET) & excepts;
+}
+
+#endif
diff --git a/newlib/libm/machine/xtensa/feupdateenv.c b/newlib/libm/machine/xtensa/feupdateenv.c
new file mode 100644
index 000000000..cbb1ffa43
--- /dev/null
+++ b/newlib/libm/machine/xtensa/feupdateenv.c
@@ -0,0 +1,46 @@
+/* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above
+ copyright notice, this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided
+ with the distribution.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
+ TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
+ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ OF THE POSSIBILITY OF SUCH DAMAGE. */
+
+#include <xtensa/config/core-isa.h>
+
+#if XCHAL_HAVE_FP || XCHAL_HAVE_DFP
+
+#include <fenv.h>
+
+int feupdateenv(const fenv_t * envp)
+{
+ fenv_t current;
+ int err = fegetenv (&current);
+ if (err != 0)
+ return err;
+ err = fesetenv (envp);
+ if (err != 0)
+ return err;
+ return feraiseexcept (current);
+}
+
+#endif