OSDN Git Service

58e3146e36452b15c78297d501f26d8b5f606245
[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 // Main union type we use to manipulate the floating-point type
46 typedef union
47 {
48   __float128 value;
49
50   struct
51   {
52 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
53     unsigned negative:1;
54     unsigned exponent:15;
55     uint64_t mant_high:48;
56     uint64_t mant_low:64;
57 #else
58     uint64_t mant_low:64;
59     uint64_t mant_high:48;
60     unsigned exponent:15;
61     unsigned negative:1;
62 #endif
63   } ieee;
64
65   struct
66   {
67 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
68     uint64_t high;
69     uint64_t low;
70 #else
71     uint64_t low;
72     uint64_t high;
73 #endif
74   } words64;
75
76   struct
77   {
78 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
79     uint32_t w0;
80     uint32_t w1;
81     uint32_t w2;
82     uint32_t w3;
83 #else
84     uint32_t w3;
85     uint32_t w2;
86     uint32_t w1;
87     uint32_t w0;
88 #endif
89   } words32;
90
91   struct
92   {
93 #if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
94     unsigned negative:1;
95     unsigned exponent:15;
96     unsigned quiet_nan:1;
97     uint64_t mant_high:47;
98     uint64_t mant_low:64;
99 #else
100     uint64_t mant_low:64;
101     uint64_t mant_high:47;
102     unsigned quiet_nan:1;
103     unsigned exponent:15;
104     unsigned negative:1;
105 #endif
106   } nan;
107
108 } ieee854_float128;
109
110
111 /* Get two 64 bit ints from a long double.  */
112 #define GET_FLT128_WORDS64(ix0,ix1,d)  \
113 do {                                   \
114   ieee854_float128 u;                  \
115   u.value = (d);                       \
116   (ix0) = u.words64.high;              \
117   (ix1) = u.words64.low;               \
118 } while (0)
119
120 /* Set a long double from two 64 bit ints.  */
121 #define SET_FLT128_WORDS64(d,ix0,ix1)  \
122 do {                                   \
123   ieee854_float128 u;                  \
124   u.words64.high = (ix0);              \
125   u.words64.low = (ix1);               \
126   (d) = u.value;                       \
127 } while (0)
128
129 /* Get the more significant 64 bits of a long double mantissa.  */
130 #define GET_FLT128_MSW64(v,d)          \
131 do {                                   \
132   ieee854_float128 u;                  \
133   u.value = (d);                       \
134   (v) = u.words64.high;                \
135 } while (0)
136
137 /* Set the more significant 64 bits of a long double mantissa from an int.  */
138 #define SET_FLT128_MSW64(d,v)          \
139 do {                                   \
140   ieee854_float128 u;                  \
141   u.value = (d);                       \
142   u.words64.high = (v);                \
143   (d) = u.value;                       \
144 } while (0)
145
146 /* Get the least significant 64 bits of a long double mantissa.  */
147 #define GET_FLT128_LSW64(v,d)          \
148 do {                                   \
149   ieee854_float128 u;                  \
150   u.value = (d);                       \
151   (v) = u.words64.low;                 \
152 } while (0)
153
154
155 #define IEEE854_FLOAT128_BIAS 0x3fff
156
157 #define QUADFP_NAN              0
158 #define QUADFP_INFINITE         1
159 #define QUADFP_ZERO             2
160 #define QUADFP_SUBNORMAL        3
161 #define QUADFP_NORMAL           4
162 #define fpclassifyq(x) \
163   __builtin_fpclassify (QUADFP_NAN, QUADFP_INFINITE, QUADFP_NORMAL, \
164                         QUADFP_SUBNORMAL, QUADFP_ZERO, x)
165
166 #endif