1770a3495607497071693147f162ac75f39423973Elliott Hughes/*-
2770a3495607497071693147f162ac75f39423973Elliott Hughes * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG>
3770a3495607497071693147f162ac75f39423973Elliott Hughes * All rights reserved.
4770a3495607497071693147f162ac75f39423973Elliott Hughes *
5770a3495607497071693147f162ac75f39423973Elliott Hughes * Redistribution and use in source and binary forms, with or without
6770a3495607497071693147f162ac75f39423973Elliott Hughes * modification, are permitted provided that the following conditions
7770a3495607497071693147f162ac75f39423973Elliott Hughes * are met:
8770a3495607497071693147f162ac75f39423973Elliott Hughes * 1. Redistributions of source code must retain the above copyright
9770a3495607497071693147f162ac75f39423973Elliott Hughes *    notice, this list of conditions and the following disclaimer.
10770a3495607497071693147f162ac75f39423973Elliott Hughes * 2. Redistributions in binary form must reproduce the above copyright
11770a3495607497071693147f162ac75f39423973Elliott Hughes *    notice, this list of conditions and the following disclaimer in the
12770a3495607497071693147f162ac75f39423973Elliott Hughes *    documentation and/or other materials provided with the distribution.
13770a3495607497071693147f162ac75f39423973Elliott Hughes *
14770a3495607497071693147f162ac75f39423973Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15770a3495607497071693147f162ac75f39423973Elliott Hughes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16770a3495607497071693147f162ac75f39423973Elliott Hughes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17770a3495607497071693147f162ac75f39423973Elliott Hughes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18770a3495607497071693147f162ac75f39423973Elliott Hughes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19770a3495607497071693147f162ac75f39423973Elliott Hughes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20770a3495607497071693147f162ac75f39423973Elliott Hughes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21770a3495607497071693147f162ac75f39423973Elliott Hughes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22770a3495607497071693147f162ac75f39423973Elliott Hughes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23770a3495607497071693147f162ac75f39423973Elliott Hughes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24770a3495607497071693147f162ac75f39423973Elliott Hughes * SUCH DAMAGE.
25770a3495607497071693147f162ac75f39423973Elliott Hughes */
26770a3495607497071693147f162ac75f39423973Elliott Hughes
27d4ca231ae2891e5c9eccb6e9a2e6af7fabcfc2a5Elliott Hughes#ifndef _BITS_FENV_X86_64_H_
28d4ca231ae2891e5c9eccb6e9a2e6af7fabcfc2a5Elliott Hughes#define _BITS_FENV_X86_64_H_
29770a3495607497071693147f162ac75f39423973Elliott Hughes
30770a3495607497071693147f162ac75f39423973Elliott Hughes#include <sys/types.h>
31770a3495607497071693147f162ac75f39423973Elliott Hughes
32361847f9aca0b77a09e52cb1cbc8218132ea9b3aElliott Hughes__BEGIN_DECLS
33361847f9aca0b77a09e52cb1cbc8218132ea9b3aElliott Hughes
34361847f9aca0b77a09e52cb1cbc8218132ea9b3aElliott Hughes/*
35770a3495607497071693147f162ac75f39423973Elliott Hughes * Each symbol representing a floating point exception expands to an integer
36770a3495607497071693147f162ac75f39423973Elliott Hughes * constant expression with values, such that bitwise-inclusive ORs of _all
37770a3495607497071693147f162ac75f39423973Elliott Hughes * combinations_ of the constants result in distinct values.
38770a3495607497071693147f162ac75f39423973Elliott Hughes *
39770a3495607497071693147f162ac75f39423973Elliott Hughes * We use such values that allow direct bitwise operations on FPU/SSE registers.
40770a3495607497071693147f162ac75f39423973Elliott Hughes */
412d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_INVALID    0x01
422d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_DENORMAL   0x02
432d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_DIVBYZERO  0x04
442d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_OVERFLOW   0x08
452d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_UNDERFLOW  0x10
462d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_INEXACT    0x20
47770a3495607497071693147f162ac75f39423973Elliott Hughes
48770a3495607497071693147f162ac75f39423973Elliott Hughes/*
49770a3495607497071693147f162ac75f39423973Elliott Hughes * The following symbol is simply the bitwise-inclusive OR of all floating-point
50770a3495607497071693147f162ac75f39423973Elliott Hughes * exception constants defined above.
51770a3495607497071693147f162ac75f39423973Elliott Hughes */
522d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_ALL_EXCEPT   (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \
532d367905a2e1b950f79b408141eea07c222b590bCalin Juravle                         FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
54770a3495607497071693147f162ac75f39423973Elliott Hughes
55770a3495607497071693147f162ac75f39423973Elliott Hughes/*
56770a3495607497071693147f162ac75f39423973Elliott Hughes * Each symbol representing the rounding direction, expands to an integer
57770a3495607497071693147f162ac75f39423973Elliott Hughes * constant expression whose value is distinct non-negative value.
58770a3495607497071693147f162ac75f39423973Elliott Hughes *
59770a3495607497071693147f162ac75f39423973Elliott Hughes * We use such values that allow direct bitwise operations on FPU/SSE registers.
60770a3495607497071693147f162ac75f39423973Elliott Hughes */
612d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_TONEAREST  0x000
622d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_DOWNWARD   0x400
632d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_UPWARD     0x800
642d367905a2e1b950f79b408141eea07c222b590bCalin Juravle#define FE_TOWARDZERO 0xc00
65770a3495607497071693147f162ac75f39423973Elliott Hughes
66770a3495607497071693147f162ac75f39423973Elliott Hughes/*
67770a3495607497071693147f162ac75f39423973Elliott Hughes * fenv_t represents the entire floating-point environment.
68770a3495607497071693147f162ac75f39423973Elliott Hughes */
692d367905a2e1b950f79b408141eea07c222b590bCalin Juravletypedef struct {
702d367905a2e1b950f79b408141eea07c222b590bCalin Juravle  struct {
712d367905a2e1b950f79b408141eea07c222b590bCalin Juravle    __uint32_t __control;   /* Control word register */
722d367905a2e1b950f79b408141eea07c222b590bCalin Juravle    __uint32_t __status;    /* Status word register */
732d367905a2e1b950f79b408141eea07c222b590bCalin Juravle    __uint32_t __tag;       /* Tag word register */
742d367905a2e1b950f79b408141eea07c222b590bCalin Juravle    __uint32_t __others[4]; /* EIP, Pointer Selector, etc */
752d367905a2e1b950f79b408141eea07c222b590bCalin Juravle  } __x87;
762d367905a2e1b950f79b408141eea07c222b590bCalin Juravle  __uint32_t __mxcsr;       /* Control, status register */
77770a3495607497071693147f162ac75f39423973Elliott Hughes} fenv_t;
78770a3495607497071693147f162ac75f39423973Elliott Hughes
79770a3495607497071693147f162ac75f39423973Elliott Hughes/*
80770a3495607497071693147f162ac75f39423973Elliott Hughes * fexcept_t represents the floating-point status flags collectively, including
81770a3495607497071693147f162ac75f39423973Elliott Hughes * any status the implementation associates with the flags.
82770a3495607497071693147f162ac75f39423973Elliott Hughes *
83770a3495607497071693147f162ac75f39423973Elliott Hughes * A floating-point status flag is a system variable whose value is set (but
84770a3495607497071693147f162ac75f39423973Elliott Hughes * never cleared) when a floating-point exception is raised, which occurs as a
85770a3495607497071693147f162ac75f39423973Elliott Hughes * side effect of exceptional floating-point arithmetic to provide auxiliary
86770a3495607497071693147f162ac75f39423973Elliott Hughes * information.
87770a3495607497071693147f162ac75f39423973Elliott Hughes *
88770a3495607497071693147f162ac75f39423973Elliott Hughes * A floating-point control mode is a system variable whose value may be set by
89770a3495607497071693147f162ac75f39423973Elliott Hughes * the user to affect the subsequent behavior of floating-point arithmetic.
90770a3495607497071693147f162ac75f39423973Elliott Hughes */
917ba84d3108a65bc69e121f82b4ff747fb203d049Pavel Chupintypedef __uint32_t fexcept_t;
92361847f9aca0b77a09e52cb1cbc8218132ea9b3aElliott Hughes
93361847f9aca0b77a09e52cb1cbc8218132ea9b3aElliott Hughes__END_DECLS
94361847f9aca0b77a09e52cb1cbc8218132ea9b3aElliott Hughes
95d4ca231ae2891e5c9eccb6e9a2e6af7fabcfc2a5Elliott Hughes#endif
96