Elliott Hughes | 770a349 | 2013-10-01 17:57:19 -0700 | [diff] [blame] | 1 | /*- |
| 2 | * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG> |
| 3 | * All rights reserved. |
| 4 | * |
| 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. |
| 13 | * |
| 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. |
| 25 | */ |
| 26 | |
| 27 | #ifndef _AMD64_FENV_H_ |
| 28 | #define _AMD64_FENV_H_ |
| 29 | |
| 30 | #include <sys/types.h> |
| 31 | |
| 32 | /* |
Elliott Hughes | 361847f | 2013-10-02 17:02:58 -0700 | [diff] [blame] | 33 | * This file combines the OpenBSD include/fenv.h and machine/fenv.h to fit |
| 34 | * the style of the other architectures (where we couldn't just take an |
| 35 | * upstream fenv.h and had to write our own). |
| 36 | */ |
| 37 | |
| 38 | __BEGIN_DECLS |
| 39 | |
| 40 | /* |
Elliott Hughes | 770a349 | 2013-10-01 17:57:19 -0700 | [diff] [blame] | 41 | * Each symbol representing a floating point exception expands to an integer |
| 42 | * constant expression with values, such that bitwise-inclusive ORs of _all |
| 43 | * combinations_ of the constants result in distinct values. |
| 44 | * |
| 45 | * We use such values that allow direct bitwise operations on FPU/SSE registers. |
| 46 | */ |
| 47 | #define FE_INVALID 0x01 |
| 48 | #define FE_DENORMAL 0x02 |
| 49 | #define FE_DIVBYZERO 0x04 |
| 50 | #define FE_OVERFLOW 0x08 |
| 51 | #define FE_UNDERFLOW 0x10 |
| 52 | #define FE_INEXACT 0x20 |
| 53 | |
| 54 | /* |
| 55 | * The following symbol is simply the bitwise-inclusive OR of all floating-point |
| 56 | * exception constants defined above. |
| 57 | */ |
| 58 | #define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \ |
| 59 | FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) |
| 60 | #define _SSE_MASK_SHIFT 7 |
| 61 | |
| 62 | /* |
| 63 | * Each symbol representing the rounding direction, expands to an integer |
| 64 | * constant expression whose value is distinct non-negative value. |
| 65 | * |
| 66 | * We use such values that allow direct bitwise operations on FPU/SSE registers. |
| 67 | */ |
| 68 | #define FE_TONEAREST 0x000 |
| 69 | #define FE_DOWNWARD 0x400 |
| 70 | #define FE_UPWARD 0x800 |
| 71 | #define FE_TOWARDZERO 0xc00 |
| 72 | |
| 73 | /* |
| 74 | * The following symbol is simply the bitwise-inclusive OR of all floating-point |
| 75 | * rounding direction constants defined above. |
| 76 | */ |
| 77 | #define _X87_ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | \ |
| 78 | FE_TOWARDZERO) |
| 79 | #define _SSE_ROUND_SHIFT 3 |
| 80 | |
| 81 | /* |
| 82 | * fenv_t represents the entire floating-point environment. |
| 83 | */ |
| 84 | typedef struct { |
| 85 | struct { |
| 86 | unsigned int __control; /* Control word register */ |
| 87 | unsigned int __status; /* Status word register */ |
| 88 | unsigned int __tag; /* Tag word register */ |
| 89 | unsigned int __others[4]; /* EIP, Pointer Selector, etc */ |
| 90 | } __x87; |
| 91 | unsigned int __mxcsr; /* Control, status register */ |
| 92 | } fenv_t; |
| 93 | |
| 94 | /* |
| 95 | * The following constant represents the default floating-point environment |
| 96 | * (that is, the one installed at program startup) and has type pointer to |
| 97 | * const-qualified fenv_t. |
| 98 | * |
| 99 | * It can be used as an argument to the functions within the <fenv.h> header |
| 100 | * that manage the floating-point environment, namely fesetenv() and |
| 101 | * feupdateenv(). |
| 102 | */ |
Elliott Hughes | 770a349 | 2013-10-01 17:57:19 -0700 | [diff] [blame] | 103 | extern fenv_t __fe_dfl_env; |
Elliott Hughes | 770a349 | 2013-10-01 17:57:19 -0700 | [diff] [blame] | 104 | #define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) |
| 105 | |
| 106 | /* |
| 107 | * fexcept_t represents the floating-point status flags collectively, including |
| 108 | * any status the implementation associates with the flags. |
| 109 | * |
| 110 | * A floating-point status flag is a system variable whose value is set (but |
| 111 | * never cleared) when a floating-point exception is raised, which occurs as a |
| 112 | * side effect of exceptional floating-point arithmetic to provide auxiliary |
| 113 | * information. |
| 114 | * |
| 115 | * A floating-point control mode is a system variable whose value may be set by |
| 116 | * the user to affect the subsequent behavior of floating-point arithmetic. |
| 117 | */ |
| 118 | typedef unsigned int fexcept_t; |
| 119 | |
Elliott Hughes | 361847f | 2013-10-02 17:02:58 -0700 | [diff] [blame] | 120 | /* C99 floating-point exception functions */ |
| 121 | int feclearexcept(int excepts); |
| 122 | int fegetexceptflag(fexcept_t *flagp, int excepts); |
| 123 | int fesetexceptflag(const fexcept_t *flagp, int excepts); |
| 124 | /* feraiseexcept does not set the inexact flag on overflow/underflow */ |
| 125 | int feraiseexcept(int excepts); |
| 126 | int fetestexcept(int excepts); |
| 127 | |
| 128 | /* C99 rounding control functions */ |
| 129 | int fegetround(void); |
| 130 | int fesetround(int round); |
| 131 | |
| 132 | /* C99 floating-point environment functions */ |
| 133 | int fegetenv(fenv_t *__envp); |
| 134 | int feholdexcept(fenv_t *__envp); |
| 135 | int fesetenv(const fenv_t *envp); |
| 136 | int feupdateenv(const fenv_t *__envp); |
| 137 | |
| 138 | #if __BSD_VISIBLE |
| 139 | /* Additional support functions to set/query floating point traps */ |
| 140 | int feenableexcept(int __mask); |
| 141 | int fedisableexcept(int __mask); |
| 142 | int fegetexcept(void); |
| 143 | #endif /* __BSD_VISIBLE */ |
| 144 | |
| 145 | __END_DECLS |
| 146 | |
Elliott Hughes | 770a349 | 2013-10-01 17:57:19 -0700 | [diff] [blame] | 147 | #endif /* !_AMD64_FENV_H_ */ |