nuclear@1: #ifndef _OS_H nuclear@1: #define _OS_H nuclear@1: /******************************************************************** nuclear@1: * * nuclear@1: * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * nuclear@1: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * nuclear@1: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * nuclear@1: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * nuclear@1: * * nuclear@1: * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * nuclear@1: * by the Xiph.Org Foundation http://www.xiph.org/ * nuclear@1: * * nuclear@1: ******************************************************************** nuclear@1: nuclear@1: function: #ifdef jail to whip a few platforms into the UNIX ideal. nuclear@1: last mod: $Id: os.h 16227 2009-07-08 06:58:46Z xiphmont $ nuclear@1: nuclear@1: ********************************************************************/ nuclear@1: nuclear@1: #ifdef HAVE_CONFIG_H nuclear@1: #include "config.h" nuclear@1: #endif nuclear@1: nuclear@1: #include nuclear@1: #include nuclear@1: nuclear@1: #include "misc.h" nuclear@1: nuclear@1: #ifndef _V_IFDEFJAIL_H_ nuclear@1: # define _V_IFDEFJAIL_H_ nuclear@1: nuclear@1: # ifdef __GNUC__ nuclear@1: # define STIN static __inline__ nuclear@1: # elif _WIN32 nuclear@1: # define STIN static __inline nuclear@1: # else nuclear@1: # define STIN static nuclear@1: # endif nuclear@1: nuclear@1: #ifdef DJGPP nuclear@1: # define rint(x) (floor((x)+0.5f)) nuclear@1: #endif nuclear@1: nuclear@1: #ifndef M_PI nuclear@1: # define M_PI (3.1415926536f) nuclear@1: #endif nuclear@1: nuclear@1: #if defined(_WIN32) && !defined(__SYMBIAN32__) nuclear@1: # include nuclear@1: # define rint(x) (floor((x)+0.5f)) nuclear@1: # define NO_FLOAT_MATH_LIB nuclear@1: # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b)) nuclear@1: #endif nuclear@1: nuclear@1: #if defined(__SYMBIAN32__) && defined(__WINS__) nuclear@1: void *_alloca(size_t size); nuclear@1: # define alloca _alloca nuclear@1: #endif nuclear@1: nuclear@1: #ifndef FAST_HYPOT nuclear@1: # define FAST_HYPOT hypot nuclear@1: #endif nuclear@1: nuclear@1: #endif nuclear@1: nuclear@1: #ifdef HAVE_ALLOCA_H nuclear@1: # include nuclear@1: #endif nuclear@1: nuclear@1: #ifdef USE_MEMORY_H nuclear@1: # include nuclear@1: #endif nuclear@1: nuclear@1: #ifndef min nuclear@1: # define min(x,y) ((x)>(y)?(y):(x)) nuclear@1: #endif nuclear@1: nuclear@1: #ifndef max nuclear@1: # define max(x,y) ((x)<(y)?(y):(x)) nuclear@1: #endif nuclear@1: nuclear@1: nuclear@1: /* Special i386 GCC implementation */ nuclear@1: #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__) nuclear@1: # define VORBIS_FPU_CONTROL nuclear@1: /* both GCC and MSVC are kinda stupid about rounding/casting to int. nuclear@1: Because of encapsulation constraints (GCC can't see inside the asm nuclear@1: block and so we end up doing stupid things like a store/load that nuclear@1: is collectively a noop), we do it this way */ nuclear@1: nuclear@1: /* we must set up the fpu before this works!! */ nuclear@1: nuclear@1: typedef ogg_int16_t vorbis_fpu_control; nuclear@1: nuclear@1: static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ nuclear@1: ogg_int16_t ret; nuclear@1: ogg_int16_t temp; nuclear@1: __asm__ __volatile__("fnstcw %0\n\t" nuclear@1: "movw %0,%%dx\n\t" nuclear@1: "andw $62463,%%dx\n\t" nuclear@1: "movw %%dx,%1\n\t" nuclear@1: "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx"); nuclear@1: *fpu=ret; nuclear@1: } nuclear@1: nuclear@1: static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){ nuclear@1: __asm__ __volatile__("fldcw %0":: "m"(fpu)); nuclear@1: } nuclear@1: nuclear@1: /* assumes the FPU is in round mode! */ nuclear@1: static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise, nuclear@1: we get extra fst/fld to nuclear@1: truncate precision */ nuclear@1: int i; nuclear@1: __asm__("fistl %0": "=m"(i) : "t"(f)); nuclear@1: return(i); nuclear@1: } nuclear@1: #endif /* Special i386 GCC implementation */ nuclear@1: nuclear@1: nuclear@1: /* MSVC inline assembly. 32 bit only; inline ASM isn't implemented in the nuclear@1: * 64 bit compiler */ nuclear@1: #if defined(_MSC_VER) && !defined(_WIN64) && !defined(_WIN32_WCE) nuclear@1: # define VORBIS_FPU_CONTROL nuclear@1: nuclear@1: typedef ogg_int16_t vorbis_fpu_control; nuclear@1: nuclear@1: static __inline int vorbis_ftoi(double f){ nuclear@1: int i; nuclear@1: __asm{ nuclear@1: fld f nuclear@1: fistp i nuclear@1: } nuclear@1: return i; nuclear@1: } nuclear@1: nuclear@1: static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ nuclear@1: } nuclear@1: nuclear@1: static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){ nuclear@1: } nuclear@1: nuclear@1: #endif /* Special MSVC 32 bit implementation */ nuclear@1: nuclear@1: nuclear@1: /* Optimized code path for x86_64 builds. Uses SSE2 intrinsics. This can be nuclear@1: done safely because all x86_64 CPUs supports SSE2. */ nuclear@1: #if (defined(_MSC_VER) && defined(_WIN64)) || (defined(__GNUC__) && defined (__x86_64__)) nuclear@1: # define VORBIS_FPU_CONTROL nuclear@1: nuclear@1: typedef ogg_int16_t vorbis_fpu_control; nuclear@1: nuclear@1: #include nuclear@1: static __inline int vorbis_ftoi(double f){ nuclear@1: return _mm_cvtsd_si32(_mm_load_sd(&f)); nuclear@1: } nuclear@1: nuclear@1: static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){ nuclear@1: } nuclear@1: nuclear@1: static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){ nuclear@1: } nuclear@1: nuclear@1: #endif /* Special MSVC x64 implementation */ nuclear@1: nuclear@1: nuclear@1: /* If no special implementation was found for the current compiler / platform, nuclear@1: use the default implementation here: */ nuclear@1: #ifndef VORBIS_FPU_CONTROL nuclear@1: nuclear@1: typedef int vorbis_fpu_control; nuclear@1: nuclear@1: static int vorbis_ftoi(double f){ nuclear@1: /* Note: MSVC and GCC (at least on some systems) round towards zero, thus, nuclear@1: the floor() call is required to ensure correct roudning of nuclear@1: negative numbers */ nuclear@1: return (int)floor(f+.5); nuclear@1: } nuclear@1: nuclear@1: /* We don't have special code for this compiler/arch, so do it the slow way */ nuclear@1: # define vorbis_fpu_setround(vorbis_fpu_control) {} nuclear@1: # define vorbis_fpu_restore(vorbis_fpu_control) {} nuclear@1: nuclear@1: #endif /* default implementation */ nuclear@1: nuclear@1: #endif /* _OS_H */