OSDN Git Service

PR fortran/46416
[pf3gnuchains/gcc-fork.git] / libquadmath / quadmath-imp.h
1 /* GCC Quad-Precision Math Library
2    Copyright (C) 2010 Free Software Foundation, Inc.
3    Written by Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
4
5 This file is part of the libiberty library.
6 Libiberty is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Library General Public
8 License as published by the Free Software Foundation; either
9 version 2 of the License, or (at your option) any later version.
10
11 Libiberty is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 Library General Public License for more details.
15
16 You should have received a copy of the GNU Library General Public
17 License along with libiberty; see the file COPYING.LIB.  If
18 not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19 Boston, MA 02110-1301, USA.  */
20
21 #ifndef QUADMATH_IMP_H
22 #define QUADMATH_IMP_H
23
24 #include <stdint.h>
25 #include <stdlib.h>
26 #include "quadmath.h"
27 #include "config.h"
28
29
30 // Prototypes for internal functions
31 extern int32_t __quadmath_rem_pio2q (__float128, __float128 *);
32 extern void __quadmath_kernel_sincosq (__float128, __float128, __float128 *,
33                                        __float128 *, int);
34 extern __float128 __quadmath_kernel_sinq (__float128, __float128, int);
35 extern __float128 __quadmath_kernel_cosq (__float128, __float128);
36
37
38
39 // Frankly, if you have __float128, you have 64-bit integers, right?
40 #ifndef UINT64_C
41 # error "No way!"
42 #endif
43
44
45 // If we don't have macros to know endianess, assume little endian
46 #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
47 # define __LITTLE_ENDIAN__ 1
48 #endif
49
50
51 // Main union type we use to manipulate the floating-point type
52 typedef union
53 {
54   __float128 value;
55
56   struct
57   {
58 #if __BIG_ENDIAN__
59     unsigned negative:1;
60     unsigned exponent:15;
61     uint64_t mant_high:48;
62     uint64_t mant_low:64;
63 #endif
64 #if __LITTLE_ENDIAN__
65     uint64_t mant_low:64;
66     uint64_t mant_high:48;
67     unsigned exponent:15;
68     unsigned negative:1;
69 #endif
70   } ieee;
71
72   struct
73   {
74 #if __BIG_ENDIAN__
75     uint64_t high;
76     uint64_t low;
77 #endif
78 #if __LITTLE_ENDIAN__
79     uint64_t low;
80     uint64_t high;
81 #endif
82   } words64;
83
84   struct
85   {
86 #if __BIG_ENDIAN__
87     uint32_t w0;
88     uint32_t w1;
89     uint32_t w2;
90     uint32_t w3;
91 #endif
92 #if __LITTLE_ENDIAN__
93     uint32_t w3;
94     uint32_t w2;
95     uint32_t w1;
96     uint32_t w0;
97 #endif
98   } words32;
99
100   struct
101   {
102 #if __BIG_ENDIAN__
103     unsigned negative:1;
104     unsigned exponent:15;
105     unsigned quiet_nan:1;
106     uint64_t mant_high:47;
107     uint64_t mant_low:64;
108 #endif
109 #if __LITTLE_ENDIAN__
110     uint64_t mant_low:64;
111     uint64_t mant_high:47;
112     unsigned quiet_nan:1;
113     unsigned exponent:15;
114     unsigned negative:1;
115 #endif
116   } nan;
117
118 } ieee854_float128;
119
120
121 /* Get two 64 bit ints from a long double.  */
122 #define GET_FLT128_WORDS64(ix0,ix1,d)  \
123 do {                                   \
124   ieee854_float128 u;                  \
125   u.value = (d);                       \
126   (ix0) = u.words64.high;              \
127   (ix1) = u.words64.low;               \
128 } while (0)
129
130 /* Set a long double from two 64 bit ints.  */
131 #define SET_FLT128_WORDS64(d,ix0,ix1)  \
132 do {                                   \
133   ieee854_float128 u;                  \
134   u.words64.high = (ix0);              \
135   u.words64.low = (ix1);               \
136   (d) = u.value;                       \
137 } while (0)
138
139 /* Get the more significant 64 bits of a long double mantissa.  */
140 #define GET_FLT128_MSW64(v,d)          \
141 do {                                   \
142   ieee854_float128 u;                  \
143   u.value = (d);                       \
144   (v) = u.words64.high;                \
145 } while (0)
146
147 /* Set the more significant 64 bits of a long double mantissa from an int.  */
148 #define SET_FLT128_MSW64(d,v)          \
149 do {                                   \
150   ieee854_float128 u;                  \
151   u.value = (d);                       \
152   u.words64.high = (v);                \
153   (d) = u.value;                       \
154 } while (0)
155
156 /* Get the least significant 64 bits of a long double mantissa.  */
157 #define GET_FLT128_LSW64(v,d)          \
158 do {                                   \
159   ieee854_float128 u;                  \
160   u.value = (d);                       \
161   (v) = u.words64.low;                 \
162 } while (0)
163
164
165 #define IEEE854_FLOAT128_BIAS 0x3fff
166
167 #define QUADFP_NAN              0
168 #define QUADFP_INFINITE         1
169 #define QUADFP_ZERO             2
170 #define QUADFP_SUBNORMAL        3
171 #define QUADFP_NORMAL           4
172 #define fpclassifyq(x) \
173   __builtin_fpclassify (QUADFP_NAN, QUADFP_INFINITE, QUADFP_NORMAL, \
174                         QUADFP_SUBNORMAL, QUADFP_ZERO, x)
175
176 #endif