Cygwin: unlink_nt: clean up debug output and comment
[newlib-cygwin.git] / newlib / libc / machine / aarch64 / sys / fenv.h
blob6b08792698a49c7c80abd1f73efdeab352093a77
1 /*-
2 * Copyright (c) 2004-2005 David Schultz <das@FreeBSD.ORG>
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
26 * $FreeBSD$
29 #ifndef _FENV_H_
30 #define _FENV_H_
32 #include <sys/_types.h>
34 #ifndef __fenv_static
35 #define __fenv_static static
36 #endif
38 typedef __uint64_t fenv_t;
39 typedef __uint64_t fexcept_t;
41 /* Exception flags */
42 #define FE_INVALID 0x00000001
43 #define FE_DIVBYZERO 0x00000002
44 #define FE_OVERFLOW 0x00000004
45 #define FE_UNDERFLOW 0x00000008
46 #define FE_INEXACT 0x00000010
47 #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_INEXACT | \
48 FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW)
51 * Rounding modes
53 * We can't just use the hardware bit values here, because that would
54 * make FE_UPWARD and FE_DOWNWARD negative, which is not allowed.
56 #define FE_TONEAREST 0x0
57 #define FE_UPWARD 0x1
58 #define FE_DOWNWARD 0x2
59 #define FE_TOWARDZERO 0x3
60 #define _ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | \
61 FE_UPWARD | FE_TOWARDZERO)
62 #define _ROUND_SHIFT 22
66 /* Default floating-point environment */
67 extern const fenv_t *_fe_dfl_env;
68 #define FE_DFL_ENV _fe_dfl_env
70 /* We need to be able to map status flag positions to mask flag positions */
71 #define _FPUSW_SHIFT 8
72 #define _ENABLE_MASK (FE_ALL_EXCEPT << _FPUSW_SHIFT)
74 #define __mrs_fpcr(__r) __asm __volatile("mrs %0, fpcr" : "=r" (__r))
75 #define __msr_fpcr(__r) __asm __volatile("msr fpcr, %0" : : "r" (__r))
77 #define __mrs_fpsr(__r) __asm __volatile("mrs %0, fpsr" : "=r" (__r))
78 #define __msr_fpsr(__r) __asm __volatile("msr fpsr, %0" : : "r" (__r))
81 #if __BSD_VISIBLE
83 /* We currently provide no external definitions of the functions below. */
85 static inline int
86 feenableexcept(int __mask)
88 fenv_t __old_r, __new_r;
90 __mrs_fpcr(__old_r);
91 __new_r = __old_r | ((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT);
92 __msr_fpcr(__new_r);
93 return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
96 static inline int
97 fedisableexcept(int __mask)
99 fenv_t __old_r, __new_r;
101 __mrs_fpcr(__old_r);
102 __new_r = __old_r & ~((__mask & FE_ALL_EXCEPT) << _FPUSW_SHIFT);
103 __msr_fpcr(__new_r);
104 return ((__old_r >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
107 static inline int
108 fegetexcept(void)
110 fenv_t __r;
112 __mrs_fpcr(__r);
113 return ((__r & _ENABLE_MASK) >> _FPUSW_SHIFT);
116 #endif /* __BSD_VISIBLE */
120 #endif /* !_FENV_H_ */