dbf-halloween2015

annotate libs/vorbis/os.h @ 1:c3f5c32cb210

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