1*0a6a1f1dSLionel Sambuc /* $NetBSD: fenv.h,v 1.2 2014/02/12 23:04:43 dsl Exp $ */ 2f6aac1c3SLionel Sambuc /*- 3f6aac1c3SLionel Sambuc * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG> 4f6aac1c3SLionel Sambuc * All rights reserved. 5f6aac1c3SLionel Sambuc * 6f6aac1c3SLionel Sambuc * Redistribution and use in source and binary forms, with or without 7f6aac1c3SLionel Sambuc * modification, are permitted provided that the following conditions 8f6aac1c3SLionel Sambuc * are met: 9f6aac1c3SLionel Sambuc * 1. Redistributions of source code must retain the above copyright 10f6aac1c3SLionel Sambuc * notice, this list of conditions and the following disclaimer. 11f6aac1c3SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright 12f6aac1c3SLionel Sambuc * notice, this list of conditions and the following disclaimer in the 13f6aac1c3SLionel Sambuc * documentation and/or other materials provided with the distribution. 14f6aac1c3SLionel Sambuc * 15f6aac1c3SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16f6aac1c3SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17f6aac1c3SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18f6aac1c3SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19f6aac1c3SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20f6aac1c3SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21f6aac1c3SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22f6aac1c3SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23f6aac1c3SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24f6aac1c3SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25f6aac1c3SLionel Sambuc * SUCH DAMAGE. 26f6aac1c3SLionel Sambuc */ 27f6aac1c3SLionel Sambuc 28f6aac1c3SLionel Sambuc #ifndef _X86_FENV_H_ 29f6aac1c3SLionel Sambuc #define _X86_FENV_H_ 30f6aac1c3SLionel Sambuc 31*0a6a1f1dSLionel Sambuc #ifndef _KERNEL 32f6aac1c3SLionel Sambuc #include <sys/stdint.h> 33*0a6a1f1dSLionel Sambuc #endif 34f6aac1c3SLionel Sambuc 35*0a6a1f1dSLionel Sambuc /* Default x87 control word. */ 36*0a6a1f1dSLionel Sambuc #define __INITIAL_NPXCW__ 0x037f 37*0a6a1f1dSLionel Sambuc /* Modern NetBSD uses the default control word.. */ 38*0a6a1f1dSLionel Sambuc #define __NetBSD_NPXCW__ __INITIAL_NPXCW__ 39*0a6a1f1dSLionel Sambuc /* NetBSD before 6.99.26 forced IEEE double precision. */ 40*0a6a1f1dSLionel Sambuc #define __NetBSD_COMPAT_NPXCW__ 0x127f 41*0a6a1f1dSLionel Sambuc 42*0a6a1f1dSLionel Sambuc /* Default values for the mxcsr. All traps masked. */ 43*0a6a1f1dSLionel Sambuc #define __INITIAL_MXCSR__ 0x1f80 44*0a6a1f1dSLionel Sambuc 45*0a6a1f1dSLionel Sambuc #ifndef _KERNEL 46f6aac1c3SLionel Sambuc /* 47f6aac1c3SLionel Sambuc * Each symbol representing a floating point exception expands to an integer 48f6aac1c3SLionel Sambuc * constant expression with values, such that bitwise-inclusive ORs of _all 49f6aac1c3SLionel Sambuc * combinations_ of the constants result in distinct values. 50f6aac1c3SLionel Sambuc * 51f6aac1c3SLionel Sambuc * We use such values that allow direct bitwise operations on FPU/SSE registers. 52f6aac1c3SLionel Sambuc */ 53f6aac1c3SLionel Sambuc #define FE_INVALID 0x01 /* 000000000001 */ 54f6aac1c3SLionel Sambuc #define FE_DENORMAL 0x02 /* 000000000010 */ 55f6aac1c3SLionel Sambuc #define FE_DIVBYZERO 0x04 /* 000000000100 */ 56f6aac1c3SLionel Sambuc #define FE_OVERFLOW 0x08 /* 000000001000 */ 57f6aac1c3SLionel Sambuc #define FE_UNDERFLOW 0x10 /* 000000010000 */ 58f6aac1c3SLionel Sambuc #define FE_INEXACT 0x20 /* 000000100000 */ 59f6aac1c3SLionel Sambuc 60f6aac1c3SLionel Sambuc /* 61f6aac1c3SLionel Sambuc * The following symbol is simply the bitwise-inclusive OR of all floating-point 62f6aac1c3SLionel Sambuc * exception constants defined above. 63f6aac1c3SLionel Sambuc */ 64f6aac1c3SLionel Sambuc #define FE_ALL_EXCEPT (FE_DIVBYZERO | FE_DENORMAL | FE_INEXACT | \ 65f6aac1c3SLionel Sambuc FE_INVALID | FE_OVERFLOW | FE_UNDERFLOW) 66f6aac1c3SLionel Sambuc 67f6aac1c3SLionel Sambuc /* 68f6aac1c3SLionel Sambuc * Each symbol representing the rounding direction, expands to an integer 69f6aac1c3SLionel Sambuc * constant expression whose value is distinct non-negative value. 70f6aac1c3SLionel Sambuc * 71f6aac1c3SLionel Sambuc * We use such values that allow direct bitwise operations on FPU/SSE registers. 72f6aac1c3SLionel Sambuc */ 73f6aac1c3SLionel Sambuc #define FE_TONEAREST 0x000 /* 000000000000 */ 74f6aac1c3SLionel Sambuc #define FE_DOWNWARD 0x400 /* 010000000000 */ 75f6aac1c3SLionel Sambuc #define FE_UPWARD 0x800 /* 100000000000 */ 76f6aac1c3SLionel Sambuc #define FE_TOWARDZERO 0xC00 /* 110000000000 */ 77f6aac1c3SLionel Sambuc 78f6aac1c3SLionel Sambuc /* 79f6aac1c3SLionel Sambuc * As compared to the x87 control word, the SSE unit's control has the rounding 80f6aac1c3SLionel Sambuc * control bits offset by 3 and the exception mask bits offset by 7 81f6aac1c3SLionel Sambuc */ 82f6aac1c3SLionel Sambuc #define __X87_ROUND_MASK 0xC00 /* 110000000000 */ 83f6aac1c3SLionel Sambuc #define __SSE_ROUND_SHIFT 3 84f6aac1c3SLionel Sambuc #define __SSE_EMASK_SHIFT 7 85f6aac1c3SLionel Sambuc 86f6aac1c3SLionel Sambuc /* 87f6aac1c3SLionel Sambuc * fenv_t represents the entire floating-point environment 88f6aac1c3SLionel Sambuc */ 89f6aac1c3SLionel Sambuc typedef struct { 90f6aac1c3SLionel Sambuc struct { 91f6aac1c3SLionel Sambuc uint16_t control; /* Control word register */ 92f6aac1c3SLionel Sambuc uint16_t unused1; 93f6aac1c3SLionel Sambuc uint16_t status; /* Status word register */ 94f6aac1c3SLionel Sambuc uint16_t unused2; 95f6aac1c3SLionel Sambuc uint16_t tag; /* Tag word register */ 96f6aac1c3SLionel Sambuc uint16_t unused3; 97f6aac1c3SLionel Sambuc uint32_t others[4]; /* EIP, Pointer Selector, etc */ 98f6aac1c3SLionel Sambuc } x87; 99f6aac1c3SLionel Sambuc 100f6aac1c3SLionel Sambuc uint32_t mxcsr; /* Control and status register */ 101f6aac1c3SLionel Sambuc } fenv_t; 102f6aac1c3SLionel Sambuc 103f6aac1c3SLionel Sambuc /* 104f6aac1c3SLionel Sambuc * The following constant represents the default floating-point environment 105f6aac1c3SLionel Sambuc * (that is, the one installed at program startup) and has type pointer to 106f6aac1c3SLionel Sambuc * const-qualified fenv_t. 107f6aac1c3SLionel Sambuc * 108f6aac1c3SLionel Sambuc * It can be used as an argument to the functions within the <fenv.h> header 109f6aac1c3SLionel Sambuc * that manage the floating-point environment. 110f6aac1c3SLionel Sambuc */ 111f6aac1c3SLionel Sambuc extern fenv_t __fe_dfl_env; 112f6aac1c3SLionel Sambuc #define FE_DFL_ENV ((const fenv_t *) &__fe_dfl_env) 113f6aac1c3SLionel Sambuc 114f6aac1c3SLionel Sambuc /* 115f6aac1c3SLionel Sambuc * fexcept_t represents the floating-point status flags collectively, including 116f6aac1c3SLionel Sambuc * any status the implementation associates with the flags. 117f6aac1c3SLionel Sambuc * 118f6aac1c3SLionel Sambuc * A floating-point status flag is a system variable whose value is set (but 119f6aac1c3SLionel Sambuc * never cleared) when a floating-point exception is raised, which occurs as a 120f6aac1c3SLionel Sambuc * side effect of exceptional floating-point arithmetic to provide auxiliary 121f6aac1c3SLionel Sambuc * information. 122f6aac1c3SLionel Sambuc * 123f6aac1c3SLionel Sambuc * A floating-point control mode is a system variable whose value may be set by 124f6aac1c3SLionel Sambuc * the user to affect the subsequent behavior of floating-point arithmetic. 125f6aac1c3SLionel Sambuc */ 126f6aac1c3SLionel Sambuc typedef uint32_t fexcept_t; 127*0a6a1f1dSLionel Sambuc #endif 128f6aac1c3SLionel Sambuc 129f6aac1c3SLionel Sambuc #endif /* ! _X86_FENV_H_ */ 130