Contiki-Inga 3.x
Main Page
Related Pages
Modules
Data Structures
Files
Examples
File List
Globals
cpu
stm32w108
small-printf
vfieeefp.h
1
/**
2
* \addtogroup stm32w-cpu
3
*
4
* @{
5
*/
6
7
/****************************************************************
8
*
9
* The author of this software is David M. Gay.
10
*
11
* Copyright (c) 1991 by AT&T.
12
*
13
* Permission to use, copy, modify, and distribute this software for any
14
* purpose without fee is hereby granted, provided that this entire notice
15
* is included in all copies of any software which is or includes a copy
16
* or modification of this software and in all copies of the supporting
17
* documentation for such software.
18
*
19
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
20
* WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
21
* REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
22
* OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
23
*
24
***************************************************************/
25
26
/* Please send bug reports to
27
David M. Gay
28
AT&T Bell Laboratories, Room 2C-463
29
600 Mountain Avenue
30
Murray Hill, NJ 07974-2070
31
U.S.A.
32
dmg@research.att.com or research!dmg
33
*/
34
35
#ifndef VFIEEEFP_H_
36
#define VFIEEEFP_H_
37
38
/*
39
* This header file is a modification of mprec.h that only contains floating
40
* point union code.
41
*/
42
43
#include <ieeefp.h>
44
#include <math.h>
45
#include <float.h>
46
#include <errno.h>
47
#include <sys/config.h>
48
49
#ifdef __IEEE_LITTLE_ENDIAN
50
#define IEEE_8087
51
#endif
52
53
#ifdef __IEEE_BIG_ENDIAN
54
#define IEEE_MC68k
55
#endif
56
57
#ifdef __Z8000__
58
#define Just_16
59
#endif
60
61
#ifdef Unsigned_Shifts
62
#define Sign_Extend(a,b) if (b < 0) a |= (__uint32_t)0xffff0000;
63
#else
64
#define Sign_Extend(a,b)
/*no-op*/
65
#endif
66
67
#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
68
Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
69
#endif
70
71
#ifdef WANT_IO_LONG_DBL
72
/*
73
* If we are going to examine or modify specific bits in a long double using
74
* the lword0 or lwordx macros, then we must wrap the long double inside
75
* a union. This is necessary to avoid undefined behavior according to
76
* the ANSI C spec.
77
*/
78
#ifdef IEEE_8087
79
#if LDBL_MANT_DIG == 24
80
struct
ldieee
81
{
82
unsigned
manh:23;
83
unsigned
exp:8;
84
unsigned
sign:1;
85
};
86
#elif LDBL_MANT_DIG == 53
87
struct
ldieee
88
{
89
unsigned
manl:20;
90
unsigned
manh:32;
91
unsigned
exp:11;
92
unsigned
sign:1;
93
};
94
#elif LDBL_MANT_DIG == 64
95
struct
ldieee
96
{
97
unsigned
manl:32;
98
unsigned
manh:32;
99
unsigned
exp:15;
100
unsigned
sign:1;
101
};
102
#elif LDBL_MANT_DIG > 64
103
struct
ldieee
104
{
105
unsigned
manl3:16;
106
unsigned
manl2:32;
107
unsigned
manl:32;
108
unsigned
manh:32;
109
unsigned
exp:15;
110
unsigned
sign:1;
111
};
112
#endif
/* LDBL_MANT_DIG */
113
#else
/* !IEEE_8087 */
114
#if LDBL_MANT_DIG == 24
115
struct
ldieee
116
{
117
unsigned
sign:1;
118
unsigned
exp:8;
119
unsigned
manh:23;
120
};
121
#elif LDBL_MANT_DIG == 53
122
struct
ldieee
123
{
124
unsigned
sign:1;
125
unsigned
exp:11;
126
unsigned
manh:32;
127
unsigned
manl:20;
128
};
129
#elif LDBL_MANT_DIG == 64
130
struct
ldieee
131
{
132
unsigned
sign:1;
133
unsigned
exp:15;
134
unsigned
manh:32;
135
unsigned
manl:32;
136
};
137
#elif LDBL_MANT_DIG > 64
138
struct
ldieee
139
{
140
unsigned
sign:1;
141
unsigned
exp:15;
142
unsigned
manh:32;
143
unsigned
manl:32;
144
unsigned
manl2:32;
145
unsigned
manl3;16;
146
};
147
#endif
/* LDBL_MANT_DIG */
148
#endif
/* !IEEE_8087 */
149
#endif
/* WANT_IO_LONG_DBL */
150
151
/*
152
* If we are going to examine or modify specific bits in a double using
153
* the word0 and/or word1 macros, then we must wrap the double inside
154
* a union. This is necessary to avoid undefined behavior according to
155
* the ANSI C spec.
156
*/
157
union
double_union
158
{
159
double
d;
160
__uint32_t i[2];
161
};
162
163
#ifdef IEEE_8087
164
#define word0(x) (x.i[1])
165
#define word1(x) (x.i[0])
166
#else
167
#define word0(x) (x.i[0])
168
#define word1(x) (x.i[1])
169
#endif
170
171
/* #define P DBL_MANT_DIG */
172
/* Ten_pmax = floor(P*log(2)/log(5)) */
173
/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
174
/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
175
/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
176
177
#if defined(IEEE_8087) + defined(IEEE_MC68k)
178
#if defined (_DOUBLE_IS_32BITS)
179
#define Exp_shift 23
180
#define Exp_shift1 23
181
#define Exp_msk1 ((__uint32_t)0x00800000L)
182
#define Exp_msk11 ((__uint32_t)0x00800000L)
183
#define Exp_mask ((__uint32_t)0x7f800000L)
184
#define P 24
185
#define Bias 127
186
#if 0
187
#define IEEE_Arith
/* it is, but the code doesn't handle IEEE singles yet */
188
#endif
189
#define Emin (-126)
190
#define Exp_1 ((__uint32_t)0x3f800000L)
191
#define Exp_11 ((__uint32_t)0x3f800000L)
192
#define Ebits 8
193
#define Frac_mask ((__uint32_t)0x007fffffL)
194
#define Frac_mask1 ((__uint32_t)0x007fffffL)
195
#define Ten_pmax 10
196
#define Sign_bit ((__uint32_t)0x80000000L)
197
#define Ten_pmax 10
198
#define Bletch 2
199
#define Bndry_mask ((__uint32_t)0x007fffffL)
200
#define Bndry_mask1 ((__uint32_t)0x007fffffL)
201
#define LSB 1
202
#define Sign_bit ((__uint32_t)0x80000000L)
203
#define Log2P 1
204
#define Tiny0 0
205
#define Tiny1 1
206
#define Quick_max 5
207
#define Int_max 6
208
#define Infinite(x) (word0(x) == ((__uint32_t)0x7f800000L))
209
#undef word0
210
#undef word1
211
212
#define word0(x) (x.i[0])
213
#define word1(x) 0
214
#else
215
216
#define Exp_shift 20
217
#define Exp_shift1 20
218
#define Exp_msk1 ((__uint32_t)0x100000L)
219
#define Exp_msk11 ((__uint32_t)0x100000L)
220
#define Exp_mask ((__uint32_t)0x7ff00000L)
221
#define P 53
222
#define Bias 1023
223
#define IEEE_Arith
224
#define Emin (-1022)
225
#define Exp_1 ((__uint32_t)0x3ff00000L)
226
#define Exp_11 ((__uint32_t)0x3ff00000L)
227
#define Ebits 11
228
#define Frac_mask ((__uint32_t)0xfffffL)
229
#define Frac_mask1 ((__uint32_t)0xfffffL)
230
#define Ten_pmax 22
231
#define Bletch 0x10
232
#define Bndry_mask ((__uint32_t)0xfffffL)
233
#define Bndry_mask1 ((__uint32_t)0xfffffL)
234
#define LSB 1
235
#define Sign_bit ((__uint32_t)0x80000000L)
236
#define Log2P 1
237
#define Tiny0 0
238
#define Tiny1 1
239
#define Quick_max 14
240
#define Int_max 14
241
#define Infinite(x) (word0(x) == ((__uint32_t)0x7ff00000L))
/* sufficient test for here */
242
#endif
243
244
#else
245
#undef Sudden_Underflow
246
#define Sudden_Underflow
247
#ifdef IBM
248
#define Exp_shift 24
249
#define Exp_shift1 24
250
#define Exp_msk1 ((__uint32_t)0x1000000L)
251
#define Exp_msk11 ((__uint32_t)0x1000000L)
252
#define Exp_mask ((__uint32_t)0x7f000000L)
253
#define P 14
254
#define Bias 65
255
#define Exp_1 ((__uint32_t)0x41000000L)
256
#define Exp_11 ((__uint32_t)0x41000000L)
257
#define Ebits 8
/* exponent has 7 bits, but 8 is the right value in b2d */
258
#define Frac_mask ((__uint32_t)0xffffffL)
259
#define Frac_mask1 ((__uint32_t)0xffffffL)
260
#define Bletch 4
261
#define Ten_pmax 22
262
#define Bndry_mask ((__uint32_t)0xefffffL)
263
#define Bndry_mask1 ((__uint32_t)0xffffffL)
264
#define LSB 1
265
#define Sign_bit ((__uint32_t)0x80000000L)
266
#define Log2P 4
267
#define Tiny0 ((__uint32_t)0x100000L)
268
#define Tiny1 0
269
#define Quick_max 14
270
#define Int_max 15
271
#else
/* VAX */
272
#define Exp_shift 23
273
#define Exp_shift1 7
274
#define Exp_msk1 0x80
275
#define Exp_msk11 ((__uint32_t)0x800000L)
276
#define Exp_mask ((__uint32_t)0x7f80L)
277
#define P 56
278
#define Bias 129
279
#define Exp_1 ((__uint32_t)0x40800000L)
280
#define Exp_11 ((__uint32_t)0x4080L)
281
#define Ebits 8
282
#define Frac_mask ((__uint32_t)0x7fffffL)
283
#define Frac_mask1 ((__uint32_t)0xffff007fL)
284
#define Ten_pmax 24
285
#define Bletch 2
286
#define Bndry_mask ((__uint32_t)0xffff007fL)
287
#define Bndry_mask1 ((__uint32_t)0xffff007fL)
288
#define LSB ((__uint32_t)0x10000L)
289
#define Sign_bit ((__uint32_t)0x8000L)
290
#define Log2P 1
291
#define Tiny0 0x80
292
#define Tiny1 0
293
#define Quick_max 15
294
#define Int_max 15
295
#endif
296
#endif
297
298
#endif
/* VFIEEEFP_H_ */
299
/** @} */
Generated on Thu Apr 24 2014 16:26:15 for Contiki-Inga 3.x by
1.8.3.1