1.1 --- a/epoc32/include/stdapis/fenv.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/stdapis/fenv.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,268 @@
1.4 -fenv.h
1.5 +/*--------------------------------------------------------------------
1.6 + *© Portions copyright (c) 2006 Nokia Corporation. All rights reserved.
1.7 + *--------------------------------------------------------------------
1.8 +*/
1.9 +/*-
1.10 + * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
1.11 + * All rights reserved.
1.12 + *
1.13 + * Redistribution and use in source and binary forms, with or without
1.14 + * modification, are permitted provided that the following conditions
1.15 + * are met:
1.16 + * 1. Redistributions of source code must retain the above copyright
1.17 + * notice, this list of conditions and the following disclaimer.
1.18 + * 2. Redistributions in binary form must reproduce the above copyright
1.19 + * notice, this list of conditions and the following disclaimer in the
1.20 + * documentation and/or other materials provided with the distribution.
1.21 + *
1.22 + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1.23 + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1.24 + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1.25 + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1.26 + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1.27 + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.28 + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1.29 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.30 + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.31 + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.32 + * SUCH DAMAGE.
1.33 + *
1.34 + * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
1.35 + */
1.36 +
1.37 +#ifndef _FENV_H_
1.38 +#define _FENV_H_
1.39 +
1.40 +#include <sys/_types.h>
1.41 +
1.42 +#ifdef __WINSCW__
1.43 +/*to supress warnings 'arguments not used in function'
1.44 +This warnings crop up wherever fevn.h is included. So
1.45 +it is desirable to supress it here. The warning arises as a
1.46 +fact that these arguments are used within macros which get
1.47 +get replaced at the time of pre-processing and thus the
1.48 +compiler(s)warning 'argument/variable is not used in function*/
1.49 +#pragma warn_unusedarg off
1.50 +#endif //__WINSCW__
1.51 +
1.52 +typedef __uint32_t fenv_t;
1.53 +typedef __uint32_t fexcept_t;
1.54 +
1.55 +/* Exception flags */
1.56 +#define FE_INVALID 0x0001
1.57 +#define FE_DIVBYZERO 0x0002
1.58 +#define FE_OVERFLOW 0x0004
1.59 +#define FE_UNDERFLOW 0x0008
1.60 +#define FE_INEXACT 0x0010
1.61 +#define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
1.62 + FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
1.63 +
1.64 +/* Rounding modes */
1.65 +#define FE_TONEAREST 0x0000
1.66 +#define FE_TOWARDZERO 0x0001
1.67 +#define FE_UPWARD 0x0002
1.68 +#define FE_DOWNWARD 0x0003
1.69 +#define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
1.70 + FE_UPWARD | FE_TOWARDZERO)
1.71 +__BEGIN_DECLS
1.72 +
1.73 +/* Default floating-point environment */
1.74 +extern const fenv_t __fe_dfl_env;
1.75 +#define FE_DFL_ENV (&__fe_dfl_env)
1.76 +
1.77 +/* We need to be able to map status flag positions to mask flag positions */
1.78 +#define _FPUSW_SHIFT 16
1.79 +#define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT)
1.80 +
1.81 +#ifdef ARM_HARD_FLOAT
1.82 +#define __rfs(__fpsr) __asm __volatile("rfs %0" : "=r" (*(__fpsr)))
1.83 +#define __wfs(__fpsr) __asm __volatile("wfs %0" : : "r" (__fpsr))
1.84 +#else
1.85 +#define __rfs(__fpsr)
1.86 +#define __wfs(__fpsr)
1.87 +#endif
1.88 +
1.89 +static __inline int
1.90 +feclearexcept(int __excepts)
1.91 +{
1.92 + #ifdef __SYMBIAN32__
1.93 + fexcept_t __fpsr = 0;
1.94 + #else
1.95 + fexcept_t __fpsr ;
1.96 + #endif //__SYMBIAN32__
1.97 +
1.98 + __rfs(&__fpsr);
1.99 + __fpsr &= ~__excepts;
1.100 + __wfs(__fpsr);
1.101 + return (0);
1.102 +}
1.103 +
1.104 +static __inline int
1.105 +fegetexceptflag(fexcept_t *__flagp, int __excepts)
1.106 +{
1.107 + #ifdef __SYMBIAN32__
1.108 + fexcept_t __fpsr = 0;
1.109 + #else
1.110 + fexcept_t __fpsr ;
1.111 + #endif //__SYMBIAN32__
1.112 +
1.113 + __rfs(&__fpsr);
1.114 + *__flagp = __fpsr & __excepts;
1.115 + return (0);
1.116 +}
1.117 +
1.118 +static __inline int
1.119 +fesetexceptflag(const fexcept_t *__flagp, int __excepts)
1.120 +{
1.121 + #ifdef __SYMBIAN32__
1.122 + fexcept_t __fpsr = 0;
1.123 + #else
1.124 + fexcept_t __fpsr ;
1.125 + #endif //__SYMBIAN32__
1.126 +
1.127 + __rfs(&__fpsr);
1.128 + __fpsr &= ~__excepts;
1.129 + __fpsr |= *__flagp & __excepts;
1.130 + __wfs(__fpsr);
1.131 + return (0);
1.132 +}
1.133 +
1.134 +static __inline int
1.135 +feraiseexcept(int __excepts)
1.136 +{
1.137 + fexcept_t __ex = __excepts;
1.138 +
1.139 + fesetexceptflag(&__ex, __excepts); /* XXX */
1.140 + return (0);
1.141 +}
1.142 +
1.143 +static __inline int
1.144 +fetestexcept(int __excepts)
1.145 +{
1.146 + #ifdef __SYMBIAN32__
1.147 + fexcept_t __fpsr = 0;
1.148 + #else
1.149 + fexcept_t __fpsr ;
1.150 + #endif //__SYMBIAN32__
1.151 +
1.152 + __rfs(&__fpsr);
1.153 + return (__fpsr & __excepts);
1.154 +}
1.155 +
1.156 +static __inline int
1.157 +fegetround(void)
1.158 +{
1.159 +
1.160 + /*
1.161 + * Apparently, the rounding mode is specified as part of the
1.162 + * instruction format on ARM, so the dynamic rounding mode is
1.163 + * indeterminate. Some FPUs may differ.
1.164 + */
1.165 + return (-1);
1.166 +}
1.167 +
1.168 +static __inline int
1.169 +fesetround(int __round)
1.170 +{
1.171 +
1.172 + return (-1);
1.173 +}
1.174 +
1.175 +static __inline int
1.176 +fegetenv(fenv_t *__envp)
1.177 +{
1.178 +
1.179 + __rfs(__envp);
1.180 + return (0);
1.181 +}
1.182 +
1.183 +static __inline int
1.184 +feholdexcept(fenv_t *__envp)
1.185 +{
1.186 + #ifdef __SYMBIAN32__
1.187 + fenv_t __env = 0;
1.188 + #else
1.189 + fenv_t __env ;
1.190 + #endif //__SYMBIAN32__
1.191 +
1.192 + __rfs(&__env);
1.193 + *__envp = __env;
1.194 + __env &= ~(FE_ALL_EXCEPT | _ENABLE_MASK);
1.195 + __wfs(__env);
1.196 + return (0);
1.197 +}
1.198 +
1.199 +static __inline int
1.200 +fesetenv(const fenv_t *__envp)
1.201 +{
1.202 +
1.203 + __wfs(*__envp);
1.204 + return (0);
1.205 +}
1.206 +
1.207 +static __inline int
1.208 +feupdateenv(const fenv_t *__envp)
1.209 +{
1.210 + #ifdef __SYMBIAN32__
1.211 + fexcept_t __fpsr = 0;
1.212 + #else
1.213 + fexcept_t __fpsr ;
1.214 + #endif //__SYMBIAN32__
1.215 +
1.216 + __rfs(&__fpsr);
1.217 + __wfs(*__envp);
1.218 + feraiseexcept(__fpsr & FE_ALL_EXCEPT);
1.219 + return (0);
1.220 +}
1.221 +
1.222 +#if __BSD_VISIBLE
1.223 +
1.224 +static __inline int
1.225 +feenableexcept(int __mask)
1.226 +{
1.227 + #ifdef __SYMBIAN32__
1.228 + fenv_t __old_fpsr = 0, __new_fpsr= 0;
1.229 + #else
1.230 + fenv_t __old_fpsr, __new_fpsr;
1.231 + #endif //__SYMBIAN32__
1.232 +
1.233 + __rfs(&__old_fpsr);
1.234 + __new_fpsr = __old_fpsr | (__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT;
1.235 + __wfs(__new_fpsr);
1.236 + return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
1.237 +}
1.238 +
1.239 +static __inline int
1.240 +fedisableexcept(int __mask)
1.241 +{
1.242 +
1.243 + #ifdef __SYMBIAN32__
1.244 + fenv_t __old_fpsr =0, __new_fpsr =0;
1.245 + #else
1.246 + fenv_t __old_fpsr, __new_fpsr;
1.247 + #endif //__SYMBIAN32__
1.248 +
1.249 + __rfs(&__old_fpsr);
1.250 + __new_fpsr = __old_fpsr & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT);
1.251 + __wfs(__new_fpsr);
1.252 + return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
1.253 +}
1.254 +
1.255 +static __inline int
1.256 +fegetexcept(void)
1.257 +{
1.258 + #ifdef __SYMBIAN32__
1.259 + fexcept_t __fpsr = 0;
1.260 + #else
1.261 + fexcept_t __fpsr ;
1.262 + #endif //__SYMBIAN32__
1.263 +
1.264 + __rfs(&__fpsr);
1.265 + return ((__fpsr & _ENABLE_MASK) >> _FPUSW_SHIFT);
1.266 +}
1.267 +
1.268 +#endif /* __BSD_VISIBLE */
1.269 +
1.270 +__END_DECLS
1.271 +
1.272 +#endif /* !_FENV_H_ */