]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/x86_64/fpu/bits/fenv.h
Optimize libm
[thirdparty/glibc.git] / sysdeps / x86_64 / fpu / bits / fenv.h
1 /* Copyright (C) 1997-2001,2004,2011 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
18
19 #ifndef _FENV_H
20 # error "Never use <bits/fenv.h> directly; include <fenv.h> instead."
21 #endif
22
23 #include <bits/wordsize.h>
24
25
26 /* Define bits representing the exception. We use the bit positions
27 of the appropriate bits in the FPU control word. */
28 enum
29 {
30 FE_INVALID = 0x01,
31 #define FE_INVALID FE_INVALID
32 __FE_DENORM = 0x02,
33 FE_DIVBYZERO = 0x04,
34 #define FE_DIVBYZERO FE_DIVBYZERO
35 FE_OVERFLOW = 0x08,
36 #define FE_OVERFLOW FE_OVERFLOW
37 FE_UNDERFLOW = 0x10,
38 #define FE_UNDERFLOW FE_UNDERFLOW
39 FE_INEXACT = 0x20
40 #define FE_INEXACT FE_INEXACT
41 };
42
43 #define FE_ALL_EXCEPT \
44 (FE_INEXACT | FE_DIVBYZERO | FE_UNDERFLOW | FE_OVERFLOW | FE_INVALID)
45
46 /* The ix87 FPU supports all of the four defined rounding modes. We
47 use again the bit positions in the FPU control word as the values
48 for the appropriate macros. */
49 enum
50 {
51 FE_TONEAREST = 0,
52 #define FE_TONEAREST FE_TONEAREST
53 FE_DOWNWARD = 0x400,
54 #define FE_DOWNWARD FE_DOWNWARD
55 FE_UPWARD = 0x800,
56 #define FE_UPWARD FE_UPWARD
57 FE_TOWARDZERO = 0xc00
58 #define FE_TOWARDZERO FE_TOWARDZERO
59 };
60
61
62 /* Type representing exception flags. */
63 typedef unsigned short int fexcept_t;
64
65
66 /* Type representing floating-point environment. This structure
67 corresponds to the layout of the block written by the `fstenv'
68 instruction and has additional fields for the contents of the MXCSR
69 register as written by the `stmxcsr' instruction. */
70 typedef struct
71 {
72 unsigned short int __control_word;
73 unsigned short int __unused1;
74 unsigned short int __status_word;
75 unsigned short int __unused2;
76 unsigned short int __tags;
77 unsigned short int __unused3;
78 unsigned int __eip;
79 unsigned short int __cs_selector;
80 unsigned int __opcode:11;
81 unsigned int __unused4:5;
82 unsigned int __data_offset;
83 unsigned short int __data_selector;
84 unsigned short int __unused5;
85 #if __WORDSIZE == 64
86 unsigned int __mxcsr;
87 #endif
88 }
89 fenv_t;
90
91 /* If the default argument is used we use this value. */
92 #define FE_DFL_ENV ((__const fenv_t *) -1)
93
94 #ifdef __USE_GNU
95 /* Floating-point environment where none of the exception is masked. */
96 # define FE_NOMASK_ENV ((__const fenv_t *) -2)
97 #endif
98
99
100 #ifdef __OPTIMIZE__
101 /* Optimized versions. */
102 extern int __feraiseexcept_renamed (int) __asm__ ("feraiseexcept");
103 __extern_inline int feraiseexcept (int __excepts)
104 {
105 if (__builtin_constant_p (__excepts)
106 && (__excepts & ~(FE_INVALID | FE_DIVBYZERO)) == 0)
107 {
108 if ((FE_INVALID & __excepts) != 0)
109 {
110 /* One example of a invalid operation is 0.0 / 0.0. */
111 float __f = 0.0;
112
113 __asm__ __volatile__ ("divss %0, %0 " : : "x" (__f));
114 (void) &__f;
115 }
116 if ((FE_DIVBYZERO & __excepts) != 0)
117 {
118 float f = 1.0;
119 float g = 0.0;
120
121 __asm__ __volatile__ ("divss %1, %0" : : "x" (f), "x" (g));
122 (void) &f;
123 }
124
125 return 0;
126 }
127
128 return __feraiseexcept_renamed (__excepts);
129 }
130 #endif