refactor headers, especially alltypes.h, and improve C++ ABI compat
[musl] / src / internal / longdbl.h
1 #ifndef _LDHACK_H
2 #define _LDHACK_H
3
4 #include <float.h>
5 #include <stdint.h>
6
7 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
8 #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
9 union ldshape {
10         long double value;
11         struct {
12                 uint64_t m;
13                 uint16_t exp:15;
14                 uint16_t sign:1;
15                 uint16_t pad;
16         } bits;
17 };
18 #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
19 union ldshape {
20         long double value;
21         struct {
22                 uint64_t mlo;
23                 uint64_t mhi:48;
24                 uint16_t exp:15;
25                 uint16_t sign:1;
26         } bits;
27 };
28 #else
29 #error Unsupported long double representation
30 #endif
31
32
33 // FIXME: hacks to make freebsd+openbsd long double code happy
34
35 // union and macros for freebsd
36
37 #if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384
38
39 union IEEEl2bits {
40         long double e;
41         struct {
42                 uint32_t manl:32;
43                 uint32_t manh:32;
44                 uint32_t exp:15;
45                 uint32_t sign:1;
46                 uint32_t pad:16;
47         } bits;
48         struct {
49                 uint64_t man:64;
50                 uint32_t expsign:16;
51                 uint32_t pad:16;
52         } xbits;
53 };
54
55 #define LDBL_MANL_SIZE 32
56 #define LDBL_MANH_SIZE 32
57 #define LDBL_NBIT (1ull << LDBL_MANH_SIZE-1)
58 #undef LDBL_IMPLICIT_NBIT
59 #define mask_nbit_l(u) ((u).bits.manh &= ~LDBL_NBIT)
60
61 #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384
62 /*
63 // ld128 float.h
64 //#define LDBL_MAX 1.189731495357231765085759326628007016E+4932L
65 #define LDBL_MAX 0x1.ffffffffffffffffffffffffffffp+16383
66 #define LDBL_MAX_EXP 16384
67 #define LDBL_HAS_INFINITY 1
68 //#define LDBL_MIN 3.362103143112093506262677817321752603E-4932L
69 #define LDBL_MIN 0x1p-16382
70 #define LDBL_HAS_QUIET_NAN 1
71 #define LDBL_HAS_DENORM 1
72 //#define LDBL_EPSILON 1.925929944387235853055977942584927319E-34L
73 #define LDBL_EPSILON 0x1p-112
74 #define LDBL_MANT_DIG 113
75 #define LDBL_MIN_EXP (-16381)
76 #define LDBL_MAX_10_EXP 4932
77 #define LDBL_DENORM_MIN 0x0.0000000000000000000000000001p-16381
78 #define LDBL_MIN_10_EXP (-4931)
79 #define LDBL_DIG 33
80 */
81
82 union IEEEl2bits {
83         long double e;
84         struct {
85                 uint64_t manl:64;
86                 uint64_t manh:48;
87                 uint32_t exp:15;
88                 uint32_t sign:1;
89         } bits;
90         struct {
91                 uint64_t unused0:64;
92                 uint64_t unused1:48;
93                 uint32_t expsign:16;
94         } xbits;
95 };
96
97 #define LDBL_MANL_SIZE 64
98 #define LDBL_MANH_SIZE 48
99 #define LDBL_NBIT (1ull << LDBL_MANH_SIZE)
100 #define LDBL_IMPLICIT_NBIT 1
101 #define mask_nbit_l(u)
102
103 #endif
104
105
106 // macros for openbsd
107
108 #define GET_LDOUBLE_WORDS(se,mh,ml, f) do{ \
109         union IEEEl2bits u; \
110         u.e = (f); \
111         (se) = u.xbits.expsign; \
112         (mh) = u.bits.manh; \
113         (ml) = u.bits.manl; \
114 }while(0)
115
116 #define SET_LDOUBLE_WORDS(f,  se,mh,ml) do{ \
117         union IEEEl2bits u; \
118         u.xbits.expsign = (se); \
119         u.bits.manh = (mh); \
120         u.bits.manl = (ml); \
121         (f) = u.e; \
122 }while(0)
123
124 #define GET_LDOUBLE_EXP(se, f) do{ \
125         union IEEEl2bits u; \
126         u.e = (f); \
127         (se) = u.xbits.expsign; \
128 }while(0)
129
130 #define SET_LDOUBLE_EXP(f, se) do{ \
131         union IEEEl2bits u; \
132         u.e = (f); \
133         u.xbits.expsign = (se); \
134         (f) = u.e; \
135 }while(0)
136
137 #endif