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