epoc32/include/stdapis/fenv.h
author William Roberts <williamr@symbian.org>
Tue, 16 Mar 2010 16:12:26 +0000
branchSymbian2
changeset 2 2fe1408b6811
parent 0 061f57f2323e
permissions -rw-r--r--
Final list of Symbian^2 public API header files
     1 /*--------------------------------------------------------------------
     2  *© Portions copyright (c) 2006 Nokia Corporation.  All rights reserved.
     3  *--------------------------------------------------------------------
     4 */
     5 /*-
     6  * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
     7  * All rights reserved.
     8  *
     9  * Redistribution and use in source and binary forms, with or without
    10  * modification, are permitted provided that the following conditions
    11  * are met:
    12  * 1. Redistributions of source code must retain the above copyright
    13  *    notice, this list of conditions and the following disclaimer.
    14  * 2. Redistributions in binary form must reproduce the above copyright
    15  *    notice, this list of conditions and the following disclaimer in the
    16  *    documentation and/or other materials provided with the distribution.
    17  *
    18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
    19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    21  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
    22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    28  * SUCH DAMAGE.
    29  *
    30  * $FreeBSD: src/lib/msun/arm/fenv.h,v 1.5 2005/03/16 19:03:45 das Exp $
    31  */
    32 
    33 #ifndef	_FENV_H_
    34 #define	_FENV_H_
    35 
    36 #include <sys/_types.h>
    37 
    38 #ifdef __WINSCW__
    39 /*to supress warnings 'arguments not used in function' 
    40 This warnings crop up wherever fevn.h is included. So
    41 it is desirable to supress it here. The warning arises as a
    42 fact that these arguments are used within macros which get
    43 get replaced at the time of pre-processing and thus the 
    44 compiler(s)warning 'argument/variable is not used in function*/
    45 #pragma warn_unusedarg off
    46 #endif //__WINSCW__
    47 
    48 typedef	__uint32_t	fenv_t;
    49 typedef	__uint32_t	fexcept_t;
    50 
    51 /* Exception flags */
    52 #define	FE_INVALID	0x0001
    53 #define	FE_DIVBYZERO	0x0002
    54 #define	FE_OVERFLOW	0x0004
    55 #define	FE_UNDERFLOW	0x0008
    56 #define	FE_INEXACT	0x0010
    57 #define	FE_ALL_EXCEPT	(FE_DIVBYZERO | FE_INEXACT | \
    58 			 FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
    59 
    60 /* Rounding modes */
    61 #define	FE_TONEAREST	0x0000
    62 #define	FE_TOWARDZERO	0x0001
    63 #define	FE_UPWARD	0x0002
    64 #define	FE_DOWNWARD	0x0003
    65 #define	_ROUND_MASK	(FE_TONEAREST | FE_DOWNWARD | \
    66 			 FE_UPWARD | FE_TOWARDZERO)
    67 __BEGIN_DECLS
    68 
    69 /* Default floating-point environment */
    70 extern const fenv_t	__fe_dfl_env;
    71 #define	FE_DFL_ENV	(&__fe_dfl_env)
    72 
    73 /* We need to be able to map status flag positions to mask flag positions */
    74 #define _FPUSW_SHIFT	16
    75 #define	_ENABLE_MASK	(FE_ALL_EXCEPT << _FPUSW_SHIFT)
    76 
    77 #ifdef	ARM_HARD_FLOAT
    78 #define	__rfs(__fpsr)	__asm __volatile("rfs %0" : "=r" (*(__fpsr)))
    79 #define	__wfs(__fpsr)	__asm __volatile("wfs %0" : : "r" (__fpsr))
    80 #else
    81 #define __rfs(__fpsr)
    82 #define __wfs(__fpsr)
    83 #endif
    84 
    85 static __inline int
    86 feclearexcept(int __excepts)
    87 {
    88 	#ifdef __SYMBIAN32__
    89 	fexcept_t __fpsr = 0;
    90 	#else
    91 	fexcept_t __fpsr ;
    92 	#endif //__SYMBIAN32__
    93 
    94 	__rfs(&__fpsr);
    95 	__fpsr &= ~__excepts;
    96 	__wfs(__fpsr);
    97 	return (0);
    98 }
    99 
   100 static __inline int
   101 fegetexceptflag(fexcept_t *__flagp, int __excepts)
   102 {
   103 	#ifdef __SYMBIAN32__
   104 	fexcept_t __fpsr = 0;
   105 	#else
   106 	fexcept_t __fpsr ;
   107 	#endif //__SYMBIAN32__
   108 
   109 	__rfs(&__fpsr);
   110 	*__flagp = __fpsr & __excepts;
   111 	return (0);
   112 }
   113 
   114 static __inline int
   115 fesetexceptflag(const fexcept_t *__flagp, int __excepts)
   116 {
   117 	#ifdef __SYMBIAN32__
   118 	fexcept_t __fpsr = 0;
   119 	#else
   120 	fexcept_t __fpsr ;
   121 	#endif //__SYMBIAN32__
   122 
   123 	__rfs(&__fpsr);
   124 	__fpsr &= ~__excepts;
   125 	__fpsr |= *__flagp & __excepts;
   126 	__wfs(__fpsr);
   127 	return (0);
   128 }
   129 
   130 static __inline int
   131 feraiseexcept(int __excepts)
   132 {
   133 	fexcept_t __ex = __excepts;
   134 
   135 	fesetexceptflag(&__ex, __excepts);	/* XXX */
   136 	return (0);
   137 }
   138 
   139 static __inline int
   140 fetestexcept(int __excepts)
   141 {
   142 	#ifdef __SYMBIAN32__
   143 	fexcept_t __fpsr = 0;
   144 	#else
   145 	fexcept_t __fpsr ;
   146 	#endif //__SYMBIAN32__
   147 
   148 	__rfs(&__fpsr);
   149 	return (__fpsr & __excepts);
   150 }
   151 
   152 static __inline int
   153 fegetround(void)
   154 {
   155 
   156 	/*
   157 	 * Apparently, the rounding mode is specified as part of the
   158 	 * instruction format on ARM, so the dynamic rounding mode is
   159 	 * indeterminate.  Some FPUs may differ.
   160 	 */
   161 	return (-1);
   162 }
   163 
   164 static __inline int
   165 fesetround(int __round)
   166 {
   167 
   168 	return (-1);
   169 }
   170 
   171 static __inline int
   172 fegetenv(fenv_t *__envp)
   173 {
   174 
   175 	__rfs(__envp);
   176 	return (0);
   177 }
   178 
   179 static __inline int
   180 feholdexcept(fenv_t *__envp)
   181 {
   182 	#ifdef __SYMBIAN32__
   183 	fenv_t __env = 0;
   184 	#else
   185 	fenv_t __env ;
   186 	#endif //__SYMBIAN32__
   187 
   188 	__rfs(&__env);
   189 	*__envp = __env;
   190 	__env &= ~(FE_ALL_EXCEPT | _ENABLE_MASK);
   191 	__wfs(__env);
   192 	return (0);
   193 }
   194 
   195 static __inline int
   196 fesetenv(const fenv_t *__envp)
   197 {
   198 
   199 	__wfs(*__envp);
   200 	return (0);
   201 }
   202 
   203 static __inline int
   204 feupdateenv(const fenv_t *__envp)
   205 {
   206 	#ifdef __SYMBIAN32__
   207 	fexcept_t __fpsr = 0;
   208 	#else
   209 	fexcept_t __fpsr ;
   210 	#endif //__SYMBIAN32__
   211 
   212 	__rfs(&__fpsr);
   213 	__wfs(*__envp);
   214 	feraiseexcept(__fpsr & FE_ALL_EXCEPT);
   215 	return (0);
   216 }
   217 
   218 #if __BSD_VISIBLE
   219 
   220 static __inline int
   221 feenableexcept(int __mask)
   222 {
   223 	#ifdef __SYMBIAN32__
   224 	fenv_t __old_fpsr = 0, __new_fpsr=  0;
   225 	#else
   226 	fenv_t __old_fpsr, __new_fpsr;
   227 	#endif //__SYMBIAN32__
   228 
   229 	__rfs(&__old_fpsr);
   230 	__new_fpsr = __old_fpsr | (__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT;
   231 	__wfs(__new_fpsr);
   232 	return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
   233 }
   234 
   235 static __inline int
   236 fedisableexcept(int __mask)
   237 {
   238 
   239 	#ifdef __SYMBIAN32__
   240 	fenv_t __old_fpsr =0, __new_fpsr =0;
   241 	#else
   242 	fenv_t __old_fpsr, __new_fpsr;
   243 	#endif //__SYMBIAN32__
   244 	
   245 	__rfs(&__old_fpsr);
   246 	__new_fpsr = __old_fpsr & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT);
   247 	__wfs(__new_fpsr);
   248 	return ((__old_fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
   249 }
   250 
   251 static __inline int
   252 fegetexcept(void)
   253 {
   254 	#ifdef __SYMBIAN32__
   255 	fexcept_t __fpsr = 0;
   256 	#else
   257 	fexcept_t __fpsr ;
   258 	#endif //__SYMBIAN32__
   259 
   260 	__rfs(&__fpsr);
   261 	return ((__fpsr & _ENABLE_MASK) >> _FPUSW_SHIFT);
   262 }
   263 
   264 #endif /* __BSD_VISIBLE */
   265 
   266 __END_DECLS
   267 
   268 #endif	/* !_FENV_H_ */