1/*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4 *
5 * Developed at SunPro, a Sun Microsystems, Inc. business.
6 * Permission to use, copy, modify, and distribute this
7 * software is freely granted, provided that this notice
8 * is preserved.
9 * ====================================================
10 */
11
12/*
13 * from: @(#)fdlibm.h 5.1 93/09/24
14 */
15
16#ifndef _MATH_PRIVATE_H_
17#define _MATH_PRIVATE_H_
18
19#include <endian.h>
20#include <stdbool.h>
21#include <stdint.h>
22#include <sys/types.h>
23
24/* Gather machine dependent _Floatn support. */
25#include <bits/floatn.h>
26
27/* The original fdlibm code used statements like:
28 n0 = ((*(int*)&one)>>29)^1; * index of high word *
29 ix0 = *(n0+(int*)&x); * high word of x *
30 ix1 = *((1-n0)+(int*)&x); * low word of x *
31 to dig two 32 bit words out of the 64 bit IEEE floating point
32 value. That is non-ANSI, and, moreover, the gcc instruction
33 scheduler gets it wrong. We instead use the following macros.
34 Unlike the original code, we determine the endianness at compile
35 time, not at run time; I don't see much benefit to selecting
36 endianness at run time. */
37
38/* A union which permits us to convert between a double and two 32 bit
39 ints. */
40
41#if __FLOAT_WORD_ORDER == __BIG_ENDIAN
42
43typedef union
44{
45 double value;
46 struct
47 {
48 uint32_t msw;
49 uint32_t lsw;
50 } parts;
51 uint64_t word;
52} ieee_double_shape_type;
53
54#endif
55
56#if __FLOAT_WORD_ORDER == __LITTLE_ENDIAN
57
58typedef union
59{
60 double value;
61 struct
62 {
63 uint32_t lsw;
64 uint32_t msw;
65 } parts;
66 uint64_t word;
67} ieee_double_shape_type;
68
69#endif
70
71/* Get two 32 bit ints from a double. */
72
73#define EXTRACT_WORDS(ix0,ix1,d) \
74do { \
75 ieee_double_shape_type ew_u; \
76 ew_u.value = (d); \
77 (ix0) = ew_u.parts.msw; \
78 (ix1) = ew_u.parts.lsw; \
79} while (0)
80
81/* Get the more significant 32 bit int from a double. */
82
83#ifndef GET_HIGH_WORD
84# define GET_HIGH_WORD(i,d) \
85do { \
86 ieee_double_shape_type gh_u; \
87 gh_u.value = (d); \
88 (i) = gh_u.parts.msw; \
89} while (0)
90#endif
91
92/* Get the less significant 32 bit int from a double. */
93
94#ifndef GET_LOW_WORD
95# define GET_LOW_WORD(i,d) \
96do { \
97 ieee_double_shape_type gl_u; \
98 gl_u.value = (d); \
99 (i) = gl_u.parts.lsw; \
100} while (0)
101#endif
102
103/* Get all in one, efficient on 64-bit machines. */
104#ifndef EXTRACT_WORDS64
105# define EXTRACT_WORDS64(i,d) \
106do { \
107 ieee_double_shape_type gh_u; \
108 gh_u.value = (d); \
109 (i) = gh_u.word; \
110} while (0)
111#endif
112
113/* Set a double from two 32 bit ints. */
114#ifndef INSERT_WORDS
115# define INSERT_WORDS(d,ix0,ix1) \
116do { \
117 ieee_double_shape_type iw_u; \
118 iw_u.parts.msw = (ix0); \
119 iw_u.parts.lsw = (ix1); \
120 (d) = iw_u.value; \
121} while (0)
122#endif
123
124/* Get all in one, efficient on 64-bit machines. */
125#ifndef INSERT_WORDS64
126# define INSERT_WORDS64(d,i) \
127do { \
128 ieee_double_shape_type iw_u; \
129 iw_u.word = (i); \
130 (d) = iw_u.value; \
131} while (0)
132#endif
133
134/* Set the more significant 32 bits of a double from an int. */
135#ifndef SET_HIGH_WORD
136#define SET_HIGH_WORD(d,v) \
137do { \
138 ieee_double_shape_type sh_u; \
139 sh_u.value = (d); \
140 sh_u.parts.msw = (v); \
141 (d) = sh_u.value; \
142} while (0)
143#endif
144
145/* Set the less significant 32 bits of a double from an int. */
146#ifndef SET_LOW_WORD
147# define SET_LOW_WORD(d,v) \
148do { \
149 ieee_double_shape_type sl_u; \
150 sl_u.value = (d); \
151 sl_u.parts.lsw = (v); \
152 (d) = sl_u.value; \
153} while (0)
154#endif
155
156/* A union which permits us to convert between a float and a 32 bit
157 int. */
158
159typedef union
160{
161 float value;
162 uint32_t word;
163} ieee_float_shape_type;
164
165/* Get a 32 bit int from a float. */
166#ifndef GET_FLOAT_WORD
167# define GET_FLOAT_WORD(i,d) \
168do { \
169 ieee_float_shape_type gf_u; \
170 gf_u.value = (d); \
171 (i) = gf_u.word; \
172} while (0)
173#endif
174
175/* Set a float from a 32 bit int. */
176#ifndef SET_FLOAT_WORD
177# define SET_FLOAT_WORD(d,i) \
178do { \
179 ieee_float_shape_type sf_u; \
180 sf_u.word = (i); \
181 (d) = sf_u.value; \
182} while (0)
183#endif
184
185/* We need to guarantee an expansion of name when building
186 ldbl-128 files as another type (e.g _Float128). */
187#define mathx_hidden_def(name) hidden_def(name)
188
189/* Get long double macros from a separate header. */
190#include <math_ldbl.h>
191
192/* Include function declarations for each floating-point. */
193#define _Mdouble_ double
194#define _MSUF_
195#include <math_private_calls.h>
196#undef _MSUF_
197#undef _Mdouble_
198
199#define _Mdouble_ float
200#define _MSUF_ f
201#define __MATH_DECLARING_FLOAT
202#include <math_private_calls.h>
203#undef __MATH_DECLARING_FLOAT
204#undef _MSUF_
205#undef _Mdouble_
206
207#define _Mdouble_ long double
208#define _MSUF_ l
209#define __MATH_DECLARING_LONG_DOUBLE
210#include <math_private_calls.h>
211#undef __MATH_DECLARING_LONG_DOUBLE
212#undef _MSUF_
213#undef _Mdouble_
214
215#if __HAVE_DISTINCT_FLOAT128
216# define _Mdouble_ _Float128
217# define _MSUF_ f128
218# define __MATH_DECLARING_FLOATN
219# include <math_private_calls.h>
220# undef __MATH_DECLARING_FLOATN
221# undef _MSUF_
222# undef _Mdouble_
223#endif
224
225
226
227/* Prototypes for functions of the IBM Accurate Mathematical Library. */
228extern double __sin (double __x);
229extern double __cos (double __x);
230extern int __branred (double __x, double *__a, double *__aa);
231extern void __doasin (double __x, double __dx, double __v[]);
232extern void __dubsin (double __x, double __dx, double __v[]);
233extern void __dubcos (double __x, double __dx, double __v[]);
234extern double __sin32 (double __x, double __res, double __res1);
235extern double __cos32 (double __x, double __res, double __res1);
236extern double __mpsin (double __x, double __dx, bool __range_reduce);
237extern double __mpcos (double __x, double __dx, bool __range_reduce);
238extern void __docos (double __x, double __dx, double __v[]);
239
240#endif /* _MATH_PRIVATE_H_ */
241