Back to index

glibc  2.9
fpu_control.h
Go to the documentation of this file.
00001 /* FPU control word bits.  i387 version.
00002    Copyright (C) 1993,1995-1998,2000,2001,2003 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by Olaf Flebbe.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 #ifndef _FPU_CONTROL_H
00022 #define _FPU_CONTROL_H      1
00023 
00024 /* Here is the dirty part. Set up your 387 through the control word
00025  * (cw) register.
00026  *
00027  *     15-13    12  11-10  9-8     7-6     5    4    3    2    1    0
00028  * | reserved | IC | RC  | PC | reserved | PM | UM | OM | ZM | DM | IM
00029  *
00030  * IM: Invalid operation mask
00031  * DM: Denormalized operand mask
00032  * ZM: Zero-divide mask
00033  * OM: Overflow mask
00034  * UM: Underflow mask
00035  * PM: Precision (inexact result) mask
00036  *
00037  * Mask bit is 1 means no interrupt.
00038  *
00039  * PC: Precision control
00040  * 11 - round to extended precision
00041  * 10 - round to double precision
00042  * 00 - round to single precision
00043  *
00044  * RC: Rounding control
00045  * 00 - rounding to nearest
00046  * 01 - rounding down (toward - infinity)
00047  * 10 - rounding up (toward + infinity)
00048  * 11 - rounding toward zero
00049  *
00050  * IC: Infinity control
00051  * That is for 8087 and 80287 only.
00052  *
00053  * The hardware default is 0x037f which we use.
00054  */
00055 
00056 #include <features.h>
00057 
00058 /* masking of interrupts */
00059 #define _FPU_MASK_IM  0x01
00060 #define _FPU_MASK_DM  0x02
00061 #define _FPU_MASK_ZM  0x04
00062 #define _FPU_MASK_OM  0x08
00063 #define _FPU_MASK_UM  0x10
00064 #define _FPU_MASK_PM  0x20
00065 
00066 /* precision control */
00067 #define _FPU_EXTENDED 0x300 /* libm requires double extended precision.  */
00068 #define _FPU_DOUBLE   0x200
00069 #define _FPU_SINGLE   0x0
00070 
00071 /* rounding control */
00072 #define _FPU_RC_NEAREST 0x0    /* RECOMMENDED */
00073 #define _FPU_RC_DOWN    0x400
00074 #define _FPU_RC_UP      0x800
00075 #define _FPU_RC_ZERO    0xC00
00076 
00077 #define _FPU_RESERVED 0xF0C0  /* Reserved bits in cw */
00078 
00079 
00080 /* The fdlibm code requires strict IEEE double precision arithmetic,
00081    and no interrupts for exceptions, rounding to nearest.  */
00082 
00083 #define _FPU_DEFAULT  0x037f
00084 
00085 /* IEEE:  same as above.  */
00086 #define _FPU_IEEE     0x037f
00087 
00088 /* Type of the control word.  */
00089 typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));
00090 
00091 /* Macros for accessing the hardware control word.
00092 
00093    Note that the use of these macros is no sufficient anymore with
00094    recent hardware.  Some floating point operations are executed in
00095    the SSE/SSE2 engines which have their own control and status register.  */
00096 #define _FPU_GETCW(cw) __asm__ __volatile__ ("fnstcw %0" : "=m" (*&cw))
00097 #define _FPU_SETCW(cw) __asm__ __volatile__ ("fldcw %0" : : "m" (*&cw))
00098 
00099 /* Default control word set at startup.  */
00100 extern fpu_control_t __fpu_control;
00101 
00102 #endif /* fpu_control.h */