Home | History | Annotate | Download | only in bits
      1 /*-
      2  * Copyright (c) 2004-2005 David Schultz <das (at) FreeBSD.ORG>
      3  * All rights reserved.
      4  *
      5  * Redistribution and use in source and binary forms, with or without
      6  * modification, are permitted provided that the following conditions
      7  * are met:
      8  * 1. Redistributions of source code must retain the above copyright
      9  *    notice, this list of conditions and the following disclaimer.
     10  * 2. Redistributions in binary form must reproduce the above copyright
     11  *    notice, this list of conditions and the following disclaimer in the
     12  *    documentation and/or other materials provided with the distribution.
     13  *
     14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     24  * SUCH DAMAGE.
     25  */
     26 
     27 #pragma once
     28 
     29 #include <sys/types.h>
     30 
     31 __BEGIN_DECLS
     32 
     33 /*
     34  * Each symbol representing a floating point exception expands to an integer
     35  * constant expression with values, such that bitwise-inclusive ORs of _all
     36  * combinations_ of the constants result in distinct values.
     37  *
     38  * We use such values that allow direct bitwise operations on FPU/SSE registers.
     39  */
     40 #define FE_INVALID    0x01
     41 #define FE_DENORMAL   0x02
     42 #define FE_DIVBYZERO  0x04
     43 #define FE_OVERFLOW   0x08
     44 #define FE_UNDERFLOW  0x10
     45 #define FE_INEXACT    0x20
     46 
     47 /*
     48  * The following symbol is simply the bitwise-inclusive OR of all floating-point
     49  * exception constants defined above.
     50  */
     51 #define FE_ALL_EXCEPT   (FE_INVALID | FE_DENORMAL | FE_DIVBYZERO | \
     52                          FE_OVERFLOW | FE_UNDERFLOW | FE_INEXACT)
     53 
     54 /*
     55  * Each symbol representing the rounding direction, expands to an integer
     56  * constant expression whose value is distinct non-negative value.
     57  *
     58  * We use such values that allow direct bitwise operations on FPU/SSE registers.
     59  */
     60 #define FE_TONEAREST  0x000
     61 #define FE_DOWNWARD   0x400
     62 #define FE_UPWARD     0x800
     63 #define FE_TOWARDZERO 0xc00
     64 
     65 /*
     66  * fenv_t represents the entire floating-point environment.
     67  */
     68 typedef struct {
     69   struct {
     70     __uint32_t __control;   /* Control word register */
     71     __uint32_t __status;    /* Status word register */
     72     __uint32_t __tag;       /* Tag word register */
     73     __uint32_t __others[4]; /* EIP, Pointer Selector, etc */
     74   } __x87;
     75   __uint32_t __mxcsr;       /* Control, status register */
     76 } fenv_t;
     77 
     78 /*
     79  * fexcept_t represents the floating-point status flags collectively, including
     80  * any status the implementation associates with the flags.
     81  *
     82  * A floating-point status flag is a system variable whose value is set (but
     83  * never cleared) when a floating-point exception is raised, which occurs as a
     84  * side effect of exceptional floating-point arithmetic to provide auxiliary
     85  * information.
     86  *
     87  * A floating-point control mode is a system variable whose value may be set by
     88  * the user to affect the subsequent behavior of floating-point arithmetic.
     89  */
     90 typedef __uint32_t fexcept_t;
     91 
     92 __END_DECLS
     93