diff options
| -rw-r--r-- | include/fenv.h | 69 | ||||
| -rw-r--r-- | libm/Makefile.in | 1 | ||||
| -rw-r--r-- | libm/sh/fpu/Makefile.arch | 18 | ||||
| -rw-r--r-- | libm/sh/fpu/feholdexcpt.c | 30 | ||||
| -rw-r--r-- | libm/sh/fpu/fesetenv.c | 27 |
5 files changed, 145 insertions, 0 deletions
diff --git a/include/fenv.h b/include/fenv.h new file mode 100644 index 000000000..11548e62c --- /dev/null +++ b/include/fenv.h @@ -0,0 +1,69 @@ +/* + * + * Copyright (c) 2007 STMicroelectronics Ltd + * Filippo Arcidiacono (filippo.arcidiacono@st.com) + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + * + * Taken from glibc 2.6 + * + */ + + +/* + * ISO C99 7.6: Floating-point environment <fenv.h> + */ + +#ifndef _FENV_H +#define _FENV_H 1 + +#include <features.h> + +/* Get the architecture dependend definitions. The following definitions + are expected to be done: + + fenv_t type for object representing an entire floating-point + environment + + FE_DFL_ENV macro of type pointer to fenv_t to be used as the argument + to functions taking an argument of type fenv_t; in this + case the default environment will be used + + fexcept_t type for object representing the floating-point exception + flags including status associated with the flags + + The following macros are defined iff the implementation supports this + kind of exception. + FE_INEXACT inexact result + FE_DIVBYZERO division by zero + FE_UNDERFLOW result not representable due to underflow + FE_OVERFLOW result not representable due to overflow + FE_INVALID invalid operation + + FE_ALL_EXCEPT bitwise OR of all supported exceptions + + The next macros are defined iff the appropriate rounding mode is + supported by the implementation. + FE_TONEAREST round to nearest + FE_UPWARD round toward +Inf + FE_DOWNWARD round toward -Inf + FE_TOWARDZERO round toward 0 +*/ +#include <bits/fenv.h> + +__BEGIN_DECLS + +/* Floating-point exception handling. */ + +/* Save the current environment in the object pointed to by ENVP, clear + exception flags and install a non-stop mode (if available) for all + exceptions. */ +extern int feholdexcept (fenv_t *__envp) __THROW; + +/* Establish the floating-point environment represented by the object + pointed to by ENVP. */ +extern int fesetenv (__const fenv_t *__envp) __THROW; + +__END_DECLS + +#endif /* fenv.h */ diff --git a/libm/Makefile.in b/libm/Makefile.in index bf6aafb06..117c3f20c 100644 --- a/libm/Makefile.in +++ b/libm/Makefile.in @@ -38,6 +38,7 @@ libm_ARCH_fpu_OUT:=$(libm_ARCH_OUT)/fpu ifeq ($(UCLIBC_HAS_FPU),y) ifeq ($(DO_C99_MATH),y) -include $(libm_ARCH_DIR)/Makefile.arch +-include $(libm_ARCH_fpu_DIR)/Makefile.arch endif endif diff --git a/libm/sh/fpu/Makefile.arch b/libm/sh/fpu/Makefile.arch new file mode 100644 index 000000000..e0f4fe952 --- /dev/null +++ b/libm/sh/fpu/Makefile.arch @@ -0,0 +1,18 @@ +# Makefile for uClibc +# +# Copyright (c) 2007 STMicroelectronics Ltd +# +# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. +# + +libm_ARCH_SRC:=$(wildcard $(libm_ARCH_fpu_DIR)/*.c) +libm_ARCH_OBJ:=$(patsubst $(libm_ARCH_fpu_DIR)/%.c,$(libm_ARCH_fpu_OUT)/%.o,$(libm_ARCH_SRC)) + +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/sh/fpu/feholdexcpt.c b/libm/sh/fpu/feholdexcpt.c new file mode 100644 index 000000000..1af79b31f --- /dev/null +++ b/libm/sh/fpu/feholdexcpt.c @@ -0,0 +1,30 @@ +/* + * + * Copyright (c) 2007 STMicroelectronics Ltd + * Filippo Arcidiacono (filippo.arcidiacono@st.com) + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + * + * Taken from glibc 2.6 + * + */ + +#include <fenv.h> +#include <fpu_control.h> + +int +feholdexcept (fenv_t *envp) +{ + unsigned long int temp; + + /* Store the environment. */ + _FPU_GETCW (temp); + envp->__fpscr = temp; + + /* Now set all exceptions to non-stop. */ + temp &= ~FE_ALL_EXCEPT; + _FPU_SETCW (temp); + + return 1; +} +libm_hidden_def (feholdexcept) diff --git a/libm/sh/fpu/fesetenv.c b/libm/sh/fpu/fesetenv.c new file mode 100644 index 000000000..9f9082cf3 --- /dev/null +++ b/libm/sh/fpu/fesetenv.c @@ -0,0 +1,27 @@ +/* + * + * Copyright (c) 2007 STMicroelectronics Ltd + * Filippo Arcidiacono (filippo.arcidiacono@st.com) + * + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + * + * Taken from glibc 2.6 + * + */ + +#include <fenv.h> +#include <fpu_control.h> + +int +fesetenv (const fenv_t *envp) +{ + if (envp == FE_DFL_ENV) + _FPU_SETCW (_FPU_DEFAULT); + else + { + unsigned long int temp = envp->__fpscr; + _FPU_SETCW (temp); + } + return 0; +} +libm_hidden_def (fesetenv) |
