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