Back to index

glibc  2.9
fpu_control.h
Go to the documentation of this file.
00001 /* FPU control word bits.  x86-64 version.
00002    Copyright (C) 1993,1995,1996,1997,1998,2000,2001,2002 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 /* Note that this file sets on x86-64 only the x87 FPU, it does not
00025    touch the SSE unit.  */
00026 
00027 /* Here is the dirty part. Set up your 387 through the control word
00028  * (cw) register.
00029  *
00030  *     15-13    12  11-10  9-8     7-6     5    4    3    2    1    0
00031  * | reserved | IC | RC  | PC | reserved | PM | UM | OM | ZM | DM | IM
00032  *
00033  * IM: Invalid operation mask
00034  * DM: Denormalized operand mask
00035  * ZM: Zero-divide mask
00036  * OM: Overflow mask
00037  * UM: Underflow mask
00038  * PM: Precision (inexact result) mask
00039  *
00040  * Mask bit is 1 means no interrupt.
00041  *
00042  * PC: Precision control
00043  * 11 - round to extended precision
00044  * 10 - round to double precision
00045  * 00 - round to single precision
00046  *
00047  * RC: Rounding control
00048  * 00 - rounding to nearest
00049  * 01 - rounding down (toward - infinity)
00050  * 10 - rounding up (toward + infinity)
00051  * 11 - rounding toward zero
00052  *
00053  * IC: Infinity control
00054  * That is for 8087 and 80287 only.
00055  *
00056  * The hardware default is 0x037f which we use.
00057  */
00058 
00059 #include <features.h>
00060 
00061 /* masking of interrupts */
00062 #define _FPU_MASK_IM  0x01
00063 #define _FPU_MASK_DM  0x02
00064 #define _FPU_MASK_ZM  0x04
00065 #define _FPU_MASK_OM  0x08
00066 #define _FPU_MASK_UM  0x10
00067 #define _FPU_MASK_PM  0x20
00068 
00069 /* precision control */
00070 #define _FPU_EXTENDED 0x300 /* libm requires double extended precision.  */
00071 #define _FPU_DOUBLE   0x200
00072 #define _FPU_SINGLE   0x0
00073 
00074 /* rounding control */
00075 #define _FPU_RC_NEAREST 0x0    /* RECOMMENDED */
00076 #define _FPU_RC_DOWN    0x400
00077 #define _FPU_RC_UP      0x800
00078 #define _FPU_RC_ZERO    0xC00
00079 
00080 #define _FPU_RESERVED 0xF0C0  /* Reserved bits in cw */
00081 
00082 
00083 /* The fdlibm code requires strict IEEE double precision arithmetic,
00084    and no interrupts for exceptions, rounding to nearest.  */
00085 
00086 #define _FPU_DEFAULT  0x037f
00087 
00088 /* IEEE:  same as above.  */
00089 #define _FPU_IEEE     0x037f
00090 
00091 /* Type of the control word.  */
00092 typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));
00093 
00094 /* Macros for accessing the hardware control word.  */
00095 #define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw))
00096 #define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw))
00097 
00098 /* Default control word set at startup.  */
00099 extern fpu_control_t __fpu_control;
00100 
00101 #endif /* fpu_control.h */