rev |
line source |
nuclear@0
|
1 #ifndef _OS_H
|
nuclear@0
|
2 #define _OS_H
|
nuclear@0
|
3 /********************************************************************
|
nuclear@0
|
4 * *
|
nuclear@0
|
5 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
|
nuclear@0
|
6 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS *
|
nuclear@0
|
7 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
|
nuclear@0
|
8 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
|
nuclear@0
|
9 * *
|
nuclear@0
|
10 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 *
|
nuclear@0
|
11 * by the Xiph.Org Foundation http://www.xiph.org/ *
|
nuclear@0
|
12 * *
|
nuclear@0
|
13 ********************************************************************
|
nuclear@0
|
14
|
nuclear@0
|
15 function: #ifdef jail to whip a few platforms into the UNIX ideal.
|
nuclear@0
|
16 last mod: $Id: os.h 16227 2009-07-08 06:58:46Z xiphmont $
|
nuclear@0
|
17
|
nuclear@0
|
18 ********************************************************************/
|
nuclear@0
|
19
|
nuclear@0
|
20 #ifdef HAVE_CONFIG_H
|
nuclear@0
|
21 #include "config.h"
|
nuclear@0
|
22 #endif
|
nuclear@0
|
23
|
nuclear@0
|
24 #include <math.h>
|
nuclear@0
|
25 #include <ogg/os_types.h>
|
nuclear@0
|
26
|
nuclear@0
|
27 #include "misc.h"
|
nuclear@0
|
28
|
nuclear@0
|
29 #ifndef _V_IFDEFJAIL_H_
|
nuclear@0
|
30 # define _V_IFDEFJAIL_H_
|
nuclear@0
|
31
|
nuclear@0
|
32 # ifdef __GNUC__
|
nuclear@0
|
33 # define STIN static __inline__
|
nuclear@0
|
34 # elif _WIN32
|
nuclear@0
|
35 # define STIN static __inline
|
nuclear@0
|
36 # else
|
nuclear@0
|
37 # define STIN static
|
nuclear@0
|
38 # endif
|
nuclear@0
|
39
|
nuclear@0
|
40 #ifdef DJGPP
|
nuclear@0
|
41 # define rint(x) (floor((x)+0.5f))
|
nuclear@0
|
42 #endif
|
nuclear@0
|
43
|
nuclear@0
|
44 #ifndef M_PI
|
nuclear@0
|
45 # define M_PI (3.1415926536f)
|
nuclear@0
|
46 #endif
|
nuclear@0
|
47
|
nuclear@0
|
48 #if defined(_WIN32) && !defined(__SYMBIAN32__)
|
nuclear@0
|
49 # include <malloc.h>
|
nuclear@0
|
50 # define rint(x) (floor((x)+0.5f))
|
nuclear@0
|
51 # define NO_FLOAT_MATH_LIB
|
nuclear@0
|
52 # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
|
nuclear@0
|
53 #endif
|
nuclear@0
|
54
|
nuclear@0
|
55 #if defined(__SYMBIAN32__) && defined(__WINS__)
|
nuclear@0
|
56 void *_alloca(size_t size);
|
nuclear@0
|
57 # define alloca _alloca
|
nuclear@0
|
58 #endif
|
nuclear@0
|
59
|
nuclear@0
|
60 #ifndef FAST_HYPOT
|
nuclear@0
|
61 # define FAST_HYPOT hypot
|
nuclear@0
|
62 #endif
|
nuclear@0
|
63
|
nuclear@0
|
64 #endif
|
nuclear@0
|
65
|
nuclear@0
|
66 #ifdef HAVE_ALLOCA_H
|
nuclear@0
|
67 # include <alloca.h>
|
nuclear@0
|
68 #endif
|
nuclear@0
|
69
|
nuclear@0
|
70 #ifdef USE_MEMORY_H
|
nuclear@0
|
71 # include <memory.h>
|
nuclear@0
|
72 #endif
|
nuclear@0
|
73
|
nuclear@0
|
74 #ifndef min
|
nuclear@0
|
75 # define min(x,y) ((x)>(y)?(y):(x))
|
nuclear@0
|
76 #endif
|
nuclear@0
|
77
|
nuclear@0
|
78 #ifndef max
|
nuclear@0
|
79 # define max(x,y) ((x)<(y)?(y):(x))
|
nuclear@0
|
80 #endif
|
nuclear@0
|
81
|
nuclear@0
|
82
|
nuclear@0
|
83 /* Special i386 GCC implementation */
|
nuclear@0
|
84 #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
|
nuclear@0
|
85 # define VORBIS_FPU_CONTROL
|
nuclear@0
|
86 /* both GCC and MSVC are kinda stupid about rounding/casting to int.
|
nuclear@0
|
87 Because of encapsulation constraints (GCC can't see inside the asm
|
nuclear@0
|
88 block and so we end up doing stupid things like a store/load that
|
nuclear@0
|
89 is collectively a noop), we do it this way */
|
nuclear@0
|
90
|
nuclear@0
|
91 /* we must set up the fpu before this works!! */
|
nuclear@0
|
92
|
nuclear@0
|
93 typedef ogg_int16_t vorbis_fpu_control;
|
nuclear@0
|
94
|
nuclear@0
|
95 static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
|
nuclear@0
|
96 ogg_int16_t ret;
|
nuclear@0
|
97 ogg_int16_t temp;
|
nuclear@0
|
98 __asm__ __volatile__("fnstcw %0\n\t"
|
nuclear@0
|
99 "movw %0,%%dx\n\t"
|
nuclear@0
|
100 "andw $62463,%%dx\n\t"
|
nuclear@0
|
101 "movw %%dx,%1\n\t"
|
nuclear@0
|
102 "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
|
nuclear@0
|
103 *fpu=ret;
|
nuclear@0
|
104 }
|
nuclear@0
|
105
|
nuclear@0
|
106 static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
|
nuclear@0
|
107 __asm__ __volatile__("fldcw %0":: "m"(fpu));
|
nuclear@0
|
108 }
|
nuclear@0
|
109
|
nuclear@0
|
110 /* assumes the FPU is in round mode! */
|
nuclear@0
|
111 static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
|
nuclear@0
|
112 we get extra fst/fld to
|
nuclear@0
|
113 truncate precision */
|
nuclear@0
|
114 int i;
|
nuclear@0
|
115 __asm__("fistl %0": "=m"(i) : "t"(f));
|
nuclear@0
|
116 return(i);
|
nuclear@0
|
117 }
|
nuclear@0
|
118 #endif /* Special i386 GCC implementation */
|
nuclear@0
|
119
|
nuclear@0
|
120
|
nuclear@0
|
121 /* MSVC inline assembly. 32 bit only; inline ASM isn't implemented in the
|
nuclear@0
|
122 * 64 bit compiler */
|
nuclear@0
|
123 #if defined(_MSC_VER) && !defined(_WIN64) && !defined(_WIN32_WCE)
|
nuclear@0
|
124 # define VORBIS_FPU_CONTROL
|
nuclear@0
|
125
|
nuclear@0
|
126 typedef ogg_int16_t vorbis_fpu_control;
|
nuclear@0
|
127
|
nuclear@0
|
128 static __inline int vorbis_ftoi(double f){
|
nuclear@0
|
129 int i;
|
nuclear@0
|
130 __asm{
|
nuclear@0
|
131 fld f
|
nuclear@0
|
132 fistp i
|
nuclear@0
|
133 }
|
nuclear@0
|
134 return i;
|
nuclear@0
|
135 }
|
nuclear@0
|
136
|
nuclear@0
|
137 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
|
nuclear@0
|
138 }
|
nuclear@0
|
139
|
nuclear@0
|
140 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
|
nuclear@0
|
141 }
|
nuclear@0
|
142
|
nuclear@0
|
143 #endif /* Special MSVC 32 bit implementation */
|
nuclear@0
|
144
|
nuclear@0
|
145
|
nuclear@0
|
146 /* Optimized code path for x86_64 builds. Uses SSE2 intrinsics. This can be
|
nuclear@0
|
147 done safely because all x86_64 CPUs supports SSE2. */
|
nuclear@0
|
148 #if (defined(_MSC_VER) && defined(_WIN64)) || (defined(__GNUC__) && defined (__x86_64__))
|
nuclear@0
|
149 # define VORBIS_FPU_CONTROL
|
nuclear@0
|
150
|
nuclear@0
|
151 typedef ogg_int16_t vorbis_fpu_control;
|
nuclear@0
|
152
|
nuclear@0
|
153 #include <emmintrin.h>
|
nuclear@0
|
154 static __inline int vorbis_ftoi(double f){
|
nuclear@0
|
155 return _mm_cvtsd_si32(_mm_load_sd(&f));
|
nuclear@0
|
156 }
|
nuclear@0
|
157
|
nuclear@0
|
158 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
|
nuclear@0
|
159 }
|
nuclear@0
|
160
|
nuclear@0
|
161 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
|
nuclear@0
|
162 }
|
nuclear@0
|
163
|
nuclear@0
|
164 #endif /* Special MSVC x64 implementation */
|
nuclear@0
|
165
|
nuclear@0
|
166
|
nuclear@0
|
167 /* If no special implementation was found for the current compiler / platform,
|
nuclear@0
|
168 use the default implementation here: */
|
nuclear@0
|
169 #ifndef VORBIS_FPU_CONTROL
|
nuclear@0
|
170
|
nuclear@0
|
171 typedef int vorbis_fpu_control;
|
nuclear@0
|
172
|
nuclear@0
|
173 static int vorbis_ftoi(double f){
|
nuclear@0
|
174 /* Note: MSVC and GCC (at least on some systems) round towards zero, thus,
|
nuclear@0
|
175 the floor() call is required to ensure correct roudning of
|
nuclear@0
|
176 negative numbers */
|
nuclear@0
|
177 return (int)floor(f+.5);
|
nuclear@0
|
178 }
|
nuclear@0
|
179
|
nuclear@0
|
180 /* We don't have special code for this compiler/arch, so do it the slow way */
|
nuclear@0
|
181 # define vorbis_fpu_setround(vorbis_fpu_control) {}
|
nuclear@0
|
182 # define vorbis_fpu_restore(vorbis_fpu_control) {}
|
nuclear@0
|
183
|
nuclear@0
|
184 #endif /* default implementation */
|
nuclear@0
|
185
|
nuclear@0
|
186 #endif /* _OS_H */
|