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