Mercurial > sdl-ios-xcode
comparison src/video/math_private.h @ 1330:450721ad5436
It's now possible to build SDL without any C runtime at all on Windows,
using Visual C++ 2005
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Mon, 06 Feb 2006 08:28:51 +0000 |
parents | |
children | 62802d9d7c87 |
comparison
equal
deleted
inserted
replaced
1329:bc67bbf87818 | 1330:450721ad5436 |
---|---|
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 * $Id$ | |
15 */ | |
16 | |
17 #ifndef _MATH_PRIVATE_H_ | |
18 #define _MATH_PRIVATE_H_ | |
19 | |
20 #include "SDL_endian.h" | |
21 | |
22 typedef Sint32 int32_t; | |
23 typedef Uint32 u_int32_t; | |
24 | |
25 /* The original fdlibm code used statements like: | |
26 n0 = ((*(int*)&one)>>29)^1; * index of high word * | |
27 ix0 = *(n0+(int*)&x); * high word of x * | |
28 ix1 = *((1-n0)+(int*)&x); * low word of x * | |
29 to dig two 32 bit words out of the 64 bit IEEE floating point | |
30 value. That is non-ANSI, and, moreover, the gcc instruction | |
31 scheduler gets it wrong. We instead use the following macros. | |
32 Unlike the original code, we determine the endianness at compile | |
33 time, not at run time; I don't see much benefit to selecting | |
34 endianness at run time. */ | |
35 | |
36 /* A union which permits us to convert between a double and two 32 bit | |
37 ints. */ | |
38 | |
39 /* | |
40 * Math on arm is special: | |
41 * For FPA, float words are always big-endian. | |
42 * For VFP, floats words follow the memory system mode. | |
43 */ | |
44 | |
45 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN) || \ | |
46 (!defined(__VFP_FP__) && (defined(__arm__) || defined(__thumb__))) | |
47 | |
48 typedef union | |
49 { | |
50 double value; | |
51 struct | |
52 { | |
53 u_int32_t msw; | |
54 u_int32_t lsw; | |
55 } parts; | |
56 } ieee_double_shape_type; | |
57 | |
58 #else | |
59 | |
60 typedef union | |
61 { | |
62 double value; | |
63 struct | |
64 { | |
65 u_int32_t lsw; | |
66 u_int32_t msw; | |
67 } parts; | |
68 } ieee_double_shape_type; | |
69 | |
70 #endif | |
71 | |
72 /* Get two 32 bit ints from a double. */ | |
73 | |
74 #define EXTRACT_WORDS(ix0,ix1,d) \ | |
75 do { \ | |
76 ieee_double_shape_type ew_u; \ | |
77 ew_u.value = (d); \ | |
78 (ix0) = ew_u.parts.msw; \ | |
79 (ix1) = ew_u.parts.lsw; \ | |
80 } while (0) | |
81 | |
82 /* Get the more significant 32 bit int from a double. */ | |
83 | |
84 #define GET_HIGH_WORD(i,d) \ | |
85 do { \ | |
86 ieee_double_shape_type gh_u; \ | |
87 gh_u.value = (d); \ | |
88 (i) = gh_u.parts.msw; \ | |
89 } while (0) | |
90 | |
91 /* Get the less significant 32 bit int from a double. */ | |
92 | |
93 #define GET_LOW_WORD(i,d) \ | |
94 do { \ | |
95 ieee_double_shape_type gl_u; \ | |
96 gl_u.value = (d); \ | |
97 (i) = gl_u.parts.lsw; \ | |
98 } while (0) | |
99 | |
100 /* Set a double from two 32 bit ints. */ | |
101 | |
102 #define INSERT_WORDS(d,ix0,ix1) \ | |
103 do { \ | |
104 ieee_double_shape_type iw_u; \ | |
105 iw_u.parts.msw = (ix0); \ | |
106 iw_u.parts.lsw = (ix1); \ | |
107 (d) = iw_u.value; \ | |
108 } while (0) | |
109 | |
110 /* Set the more significant 32 bits of a double from an int. */ | |
111 | |
112 #define SET_HIGH_WORD(d,v) \ | |
113 do { \ | |
114 ieee_double_shape_type sh_u; \ | |
115 sh_u.value = (d); \ | |
116 sh_u.parts.msw = (v); \ | |
117 (d) = sh_u.value; \ | |
118 } while (0) | |
119 | |
120 /* Set the less significant 32 bits of a double from an int. */ | |
121 | |
122 #define SET_LOW_WORD(d,v) \ | |
123 do { \ | |
124 ieee_double_shape_type sl_u; \ | |
125 sl_u.value = (d); \ | |
126 sl_u.parts.lsw = (v); \ | |
127 (d) = sl_u.value; \ | |
128 } while (0) | |
129 | |
130 /* A union which permits us to convert between a float and a 32 bit | |
131 int. */ | |
132 | |
133 typedef union | |
134 { | |
135 float value; | |
136 u_int32_t word; | |
137 } ieee_float_shape_type; | |
138 | |
139 /* Get a 32 bit int from a float. */ | |
140 | |
141 #define GET_FLOAT_WORD(i,d) \ | |
142 do { \ | |
143 ieee_float_shape_type gf_u; \ | |
144 gf_u.value = (d); \ | |
145 (i) = gf_u.word; \ | |
146 } while (0) | |
147 | |
148 /* Set a float from a 32 bit int. */ | |
149 | |
150 #define SET_FLOAT_WORD(d,i) \ | |
151 do { \ | |
152 ieee_float_shape_type sf_u; \ | |
153 sf_u.word = (i); \ | |
154 (d) = sf_u.value; \ | |
155 } while (0) | |
156 | |
157 | |
158 #ifdef __STDC__ | |
159 static const double | |
160 #else | |
161 static double | |
162 #endif | |
163 zero = 0.0, | |
164 one = 1.0, | |
165 two = 2.0, | |
166 two53 = 9007199254740992.0, /* 0x43400000, 0x00000000 */ | |
167 two54 = 1.80143985094819840000e+16, /* 0x43500000, 0x00000000 */ | |
168 twom54 = 5.55111512312578270212e-17, /* 0x3C900000, 0x00000000 */ | |
169 huge = 1.0e+300, | |
170 tiny = 1.0e-300; | |
171 | |
172 #endif /* _MATH_PRIVATE_H_ */ |