dbf-halloween2015

view libs/vorbis/os.h @ 4:4316c0c879e9

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