1*c9683224Smartynas /* $OpenBSD: fenv.h,v 1.3 2011/05/25 21:46:49 martynas Exp $ */ 2b9557bebSmartynas /* $NetBSD: fenv.h,v 1.1.6.2 2010/10/24 22:48:02 jym Exp $ */ 3d6f349c8Smartynas 4b9557bebSmartynas /*- 5b9557bebSmartynas * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG> 6b9557bebSmartynas * All rights reserved. 7b9557bebSmartynas * 8b9557bebSmartynas * Redistribution and use in source and binary forms, with or without 9b9557bebSmartynas * modification, are permitted provided that the following conditions 10b9557bebSmartynas * are met: 11b9557bebSmartynas * 1. Redistributions of source code must retain the above copyright 12b9557bebSmartynas * notice, this list of conditions and the following disclaimer. 13b9557bebSmartynas * 2. Redistributions in binary form must reproduce the above copyright 14b9557bebSmartynas * notice, this list of conditions and the following disclaimer in the 15b9557bebSmartynas * documentation and/or other materials provided with the distribution. 16b9557bebSmartynas * 17b9557bebSmartynas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18b9557bebSmartynas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19b9557bebSmartynas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20b9557bebSmartynas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 21b9557bebSmartynas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22b9557bebSmartynas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23b9557bebSmartynas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24b9557bebSmartynas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25b9557bebSmartynas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26b9557bebSmartynas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27b9557bebSmartynas * SUCH DAMAGE. 28b9557bebSmartynas */ 29b9557bebSmartynas 30d6f349c8Smartynas #ifndef _I386_FENV_H_ 31d6f349c8Smartynas #define _I386_FENV_H_ 32b9557bebSmartynas 33b9557bebSmartynas /* 34b9557bebSmartynas * Each symbol representing a floating point exception expands to an integer 35b9557bebSmartynas * constant expression with values, such that bitwise-inclusive ORs of _all 36b9557bebSmartynas * combinations_ of the constants result in distinct values. 37b9557bebSmartynas * 38b9557bebSmartynas * We use such values that allow direct bitwise operations on FPU/SSE registers. 39b9557bebSmartynas */ 40d6f349c8Smartynas #define FE_INVALID 0x01 41d6f349c8Smartynas #define FE_DENORMAL 0x02 42d6f349c8Smartynas #define FE_DIVBYZERO 0x04 43d6f349c8Smartynas #define FE_OVERFLOW 0x08 44d6f349c8Smartynas #define FE_UNDERFLOW 0x10 45d6f349c8Smartynas #define FE_INEXACT 0x20 46b9557bebSmartynas 47b9557bebSmartynas /* 48b9557bebSmartynas * The following symbol is simply the bitwise-inclusive OR of all floating-point 49b9557bebSmartynas * exception constants defined above. 50b9557bebSmartynas */ 51d6f349c8Smartynas #define FE_ALL_EXCEPT (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \ 52d6f349c8Smartynas FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT) 53d6f349c8Smartynas #define _SSE_MASK_SHIFT 7 54b9557bebSmartynas 55b9557bebSmartynas /* 56b9557bebSmartynas * Each symbol representing the rounding direction, expands to an integer 57b9557bebSmartynas * constant expression whose value is distinct non-negative value. 58b9557bebSmartynas * 59b9557bebSmartynas * We use such values that allow direct bitwise operations on FPU/SSE registers. 60b9557bebSmartynas */ 61d6f349c8Smartynas #define FE_TONEAREST 0x000 62d6f349c8Smartynas #define FE_DOWNWARD 0x400 63d6f349c8Smartynas #define FE_UPWARD 0x800 64d6f349c8Smartynas #define FE_TOWARDZERO 0xc00 65b9557bebSmartynas 66b9557bebSmartynas /* 67d6f349c8Smartynas * The following symbol is simply the bitwise-inclusive OR of all floating-point 68d6f349c8Smartynas * rounding direction constants defined above. 69b9557bebSmartynas */ 70d6f349c8Smartynas #define _X87_ROUND_MASK (FE_TONEAREST | FE_DOWNWARD | FE_UPWARD | \ 71d6f349c8Smartynas FE_TOWARDZERO) 72d6f349c8Smartynas #define _SSE_ROUND_SHIFT 3 73b9557bebSmartynas 74b9557bebSmartynas /* 75d6f349c8Smartynas * fenv_t represents the entire floating-point environment. 76b9557bebSmartynas */ 77b9557bebSmartynas typedef struct { 78b9557bebSmartynas struct { 79d6f349c8Smartynas unsigned int __control; /* Control word register */ 80d6f349c8Smartynas unsigned int __status; /* Status word register */ 81d6f349c8Smartynas unsigned int __tag; /* Tag word register */ 82d6f349c8Smartynas unsigned int __others[4]; /* EIP, Pointer Selector, etc */ 83d6f349c8Smartynas } __x87; 84d6f349c8Smartynas unsigned int __mxcsr; /* Control, status register */ 85b9557bebSmartynas } fenv_t; 86b9557bebSmartynas 87b9557bebSmartynas /* 88b9557bebSmartynas * The following constant represents the default floating-point environment 89b9557bebSmartynas * (that is, the one installed at program startup) and has type pointer to 90b9557bebSmartynas * const-qualified fenv_t. 91b9557bebSmartynas * 92b9557bebSmartynas * It can be used as an argument to the functions within the <fenv.h> header 93d6f349c8Smartynas * that manage the floating-point environment, namely fesetenv() and 94d6f349c8Smartynas * feupdateenv(). 95b9557bebSmartynas */ 96*c9683224Smartynas __BEGIN_DECLS 97b9557bebSmartynas extern fenv_t __fe_dfl_env; 98*c9683224Smartynas __END_DECLS 99b9557bebSmartynas #define FE_DFL_ENV ((const fenv_t *)&__fe_dfl_env) 100b9557bebSmartynas 101b9557bebSmartynas /* 102b9557bebSmartynas * fexcept_t represents the floating-point status flags collectively, including 103b9557bebSmartynas * any status the implementation associates with the flags. 104b9557bebSmartynas * 105b9557bebSmartynas * A floating-point status flag is a system variable whose value is set (but 106b9557bebSmartynas * never cleared) when a floating-point exception is raised, which occurs as a 107b9557bebSmartynas * side effect of exceptional floating-point arithmetic to provide auxiliary 108b9557bebSmartynas * information. 109b9557bebSmartynas * 110b9557bebSmartynas * A floating-point control mode is a system variable whose value may be set by 111b9557bebSmartynas * the user to affect the subsequent behavior of floating-point arithmetic. 112b9557bebSmartynas */ 113d6f349c8Smartynas typedef unsigned int fexcept_t; 114b9557bebSmartynas 115d6f349c8Smartynas #endif /* !_I386_FENV_H_ */ 116