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