Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / generic / get-rounding-mode.h
blobb46cab5926152aa69c89be681f56719d965f48c3
1 /* Determine floating-point rounding mode within libc. Generic version.
2 Copyright (C) 2012-2014 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
19 #ifndef _GET_ROUNDING_MODE_H
20 #define _GET_ROUNDING_MODE_H 1
22 #include <fpu_control.h>
24 /* Define values for FE_* modes not defined for this architecture. */
25 #ifdef FE_DOWNWARD
26 # define ORIG_FE_DOWNWARD FE_DOWNWARD
27 #else
28 # define ORIG_FE_DOWNWARD 0
29 #endif
30 #ifdef FE_TONEAREST
31 # define ORIG_FE_TONEAREST FE_TONEAREST
32 #else
33 # define ORIG_FE_TONEAREST 0
34 #endif
35 #ifdef FE_TOWARDZERO
36 # define ORIG_FE_TOWARDZERO FE_TOWARDZERO
37 #else
38 # define ORIG_FE_TOWARDZERO 0
39 #endif
40 #ifdef FE_UPWARD
41 # define ORIG_FE_UPWARD FE_UPWARD
42 #else
43 # define ORIG_FE_UPWARD 0
44 #endif
45 #define FE_CONSTRUCT_DISTINCT_VALUE(X, Y, Z) \
46 ((((X) & 1) | ((Y) & 2) | ((Z) & 4)) ^ 7)
47 #ifndef FE_DOWNWARD
48 # define FE_DOWNWARD FE_CONSTRUCT_DISTINCT_VALUE (ORIG_FE_TONEAREST, \
49 ORIG_FE_TOWARDZERO, \
50 ORIG_FE_UPWARD)
51 #endif
52 #ifndef FE_TONEAREST
53 # define FE_TONEAREST FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \
54 ORIG_FE_TOWARDZERO, \
55 ORIG_FE_UPWARD)
56 #endif
57 #ifndef FE_TOWARDZERO
58 # define FE_TOWARDZERO FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \
59 FE_TONEAREST, \
60 ORIG_FE_UPWARD)
61 #endif
62 #ifndef FE_UPWARD
63 # define FE_UPWARD FE_CONSTRUCT_DISTINCT_VALUE (FE_DOWNWARD, \
64 FE_TONEAREST, \
65 FE_TOWARDZERO)
66 #endif
68 /* Return the floating-point rounding mode. */
70 static inline int
71 get_rounding_mode (void)
73 #if (defined _FPU_RC_DOWN \
74 || defined _FPU_RC_NEAREST \
75 || defined _FPU_RC_ZERO \
76 || defined _FPU_RC_UP)
77 fpu_control_t fc;
78 const fpu_control_t mask = (0
79 # ifdef _FPU_RC_DOWN
80 | _FPU_RC_DOWN
81 # endif
82 # ifdef _FPU_RC_NEAREST
83 | _FPU_RC_NEAREST
84 # endif
85 # ifdef _FPU_RC_ZERO
86 | _FPU_RC_ZERO
87 # endif
88 # ifdef _FPU_RC_UP
89 | _FPU_RC_UP
90 # endif
93 _FPU_GETCW (fc);
94 switch (fc & mask)
96 # ifdef _FPU_RC_DOWN
97 case _FPU_RC_DOWN:
98 return FE_DOWNWARD;
99 # endif
101 # ifdef _FPU_RC_NEAREST
102 case _FPU_RC_NEAREST:
103 return FE_TONEAREST;
104 # endif
106 # ifdef _FPU_RC_ZERO
107 case _FPU_RC_ZERO:
108 return FE_TOWARDZERO;
109 # endif
111 # ifdef _FPU_RC_UP
112 case _FPU_RC_UP:
113 return FE_UPWARD;
114 # endif
116 default:
117 abort ();
119 #else
120 return FE_TONEAREST;
121 #endif
124 #endif /* get-rounding-mode.h */