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