vrshoot

diff libs/vorbis/os.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/libs/vorbis/os.h	Sat Feb 01 19:58:19 2014 +0200
     1.3 @@ -0,0 +1,186 @@
     1.4 +#ifndef _OS_H
     1.5 +#define _OS_H
     1.6 +/********************************************************************
     1.7 + *                                                                  *
     1.8 + * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
     1.9 + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
    1.10 + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
    1.11 + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
    1.12 + *                                                                  *
    1.13 + * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009             *
    1.14 + * by the Xiph.Org Foundation http://www.xiph.org/                  *
    1.15 + *                                                                  *
    1.16 + ********************************************************************
    1.17 +
    1.18 + function: #ifdef jail to whip a few platforms into the UNIX ideal.
    1.19 + last mod: $Id: os.h 16227 2009-07-08 06:58:46Z xiphmont $
    1.20 +
    1.21 + ********************************************************************/
    1.22 +
    1.23 +#ifdef HAVE_CONFIG_H
    1.24 +#include "config.h"
    1.25 +#endif
    1.26 +
    1.27 +#include <math.h>
    1.28 +#include <ogg/os_types.h>
    1.29 +
    1.30 +#include "misc.h"
    1.31 +
    1.32 +#ifndef _V_IFDEFJAIL_H_
    1.33 +#  define _V_IFDEFJAIL_H_
    1.34 +
    1.35 +#  ifdef __GNUC__
    1.36 +#    define STIN static __inline__
    1.37 +#  elif _WIN32
    1.38 +#    define STIN static __inline
    1.39 +#  else
    1.40 +#    define STIN static
    1.41 +#  endif
    1.42 +
    1.43 +#ifdef DJGPP
    1.44 +#  define rint(x)   (floor((x)+0.5f))
    1.45 +#endif
    1.46 +
    1.47 +#ifndef M_PI
    1.48 +#  define M_PI (3.1415926536f)
    1.49 +#endif
    1.50 +
    1.51 +#if defined(_WIN32) && !defined(__SYMBIAN32__)
    1.52 +#  include <malloc.h>
    1.53 +#  define rint(x)   (floor((x)+0.5f))
    1.54 +#  define NO_FLOAT_MATH_LIB
    1.55 +#  define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
    1.56 +#endif
    1.57 +
    1.58 +#if defined(__SYMBIAN32__) && defined(__WINS__)
    1.59 +void *_alloca(size_t size);
    1.60 +#  define alloca _alloca
    1.61 +#endif
    1.62 +
    1.63 +#ifndef FAST_HYPOT
    1.64 +#  define FAST_HYPOT hypot
    1.65 +#endif
    1.66 +
    1.67 +#endif
    1.68 +
    1.69 +#ifdef HAVE_ALLOCA_H
    1.70 +#  include <alloca.h>
    1.71 +#endif
    1.72 +
    1.73 +#ifdef USE_MEMORY_H
    1.74 +#  include <memory.h>
    1.75 +#endif
    1.76 +
    1.77 +#ifndef min
    1.78 +#  define min(x,y)  ((x)>(y)?(y):(x))
    1.79 +#endif
    1.80 +
    1.81 +#ifndef max
    1.82 +#  define max(x,y)  ((x)<(y)?(y):(x))
    1.83 +#endif
    1.84 +
    1.85 +
    1.86 +/* Special i386 GCC implementation */
    1.87 +#if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
    1.88 +#  define VORBIS_FPU_CONTROL
    1.89 +/* both GCC and MSVC are kinda stupid about rounding/casting to int.
    1.90 +   Because of encapsulation constraints (GCC can't see inside the asm
    1.91 +   block and so we end up doing stupid things like a store/load that
    1.92 +   is collectively a noop), we do it this way */
    1.93 +
    1.94 +/* we must set up the fpu before this works!! */
    1.95 +
    1.96 +typedef ogg_int16_t vorbis_fpu_control;
    1.97 +
    1.98 +static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
    1.99 +  ogg_int16_t ret;
   1.100 +  ogg_int16_t temp;
   1.101 +  __asm__ __volatile__("fnstcw %0\n\t"
   1.102 +          "movw %0,%%dx\n\t"
   1.103 +          "andw $62463,%%dx\n\t"
   1.104 +          "movw %%dx,%1\n\t"
   1.105 +          "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
   1.106 +  *fpu=ret;
   1.107 +}
   1.108 +
   1.109 +static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
   1.110 +  __asm__ __volatile__("fldcw %0":: "m"(fpu));
   1.111 +}
   1.112 +
   1.113 +/* assumes the FPU is in round mode! */
   1.114 +static inline int vorbis_ftoi(double f){  /* yes, double!  Otherwise,
   1.115 +                                             we get extra fst/fld to
   1.116 +                                             truncate precision */
   1.117 +  int i;
   1.118 +  __asm__("fistl %0": "=m"(i) : "t"(f));
   1.119 +  return(i);
   1.120 +}
   1.121 +#endif /* Special i386 GCC implementation */
   1.122 +
   1.123 +
   1.124 +/* MSVC inline assembly. 32 bit only; inline ASM isn't implemented in the
   1.125 + * 64 bit compiler */
   1.126 +#if defined(_MSC_VER) && !defined(_WIN64) && !defined(_WIN32_WCE)
   1.127 +#  define VORBIS_FPU_CONTROL
   1.128 +
   1.129 +typedef ogg_int16_t vorbis_fpu_control;
   1.130 +
   1.131 +static __inline int vorbis_ftoi(double f){
   1.132 +        int i;
   1.133 +        __asm{
   1.134 +                fld f
   1.135 +                fistp i
   1.136 +        }
   1.137 +        return i;
   1.138 +}
   1.139 +
   1.140 +static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
   1.141 +}
   1.142 +
   1.143 +static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
   1.144 +}
   1.145 +
   1.146 +#endif /* Special MSVC 32 bit implementation */
   1.147 +
   1.148 +
   1.149 +/* Optimized code path for x86_64 builds. Uses SSE2 intrinsics. This can be
   1.150 +   done safely because all x86_64 CPUs supports SSE2. */
   1.151 +#if (defined(_MSC_VER) && defined(_WIN64)) || (defined(__GNUC__) && defined (__x86_64__))
   1.152 +#  define VORBIS_FPU_CONTROL
   1.153 +
   1.154 +typedef ogg_int16_t vorbis_fpu_control;
   1.155 +
   1.156 +#include <emmintrin.h>
   1.157 +static __inline int vorbis_ftoi(double f){
   1.158 +        return _mm_cvtsd_si32(_mm_load_sd(&f));
   1.159 +}
   1.160 +
   1.161 +static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
   1.162 +}
   1.163 +
   1.164 +static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
   1.165 +}
   1.166 +
   1.167 +#endif /* Special MSVC x64 implementation */
   1.168 +
   1.169 +
   1.170 +/* If no special implementation was found for the current compiler / platform,
   1.171 +   use the default implementation here: */
   1.172 +#ifndef VORBIS_FPU_CONTROL
   1.173 +
   1.174 +typedef int vorbis_fpu_control;
   1.175 +
   1.176 +static int vorbis_ftoi(double f){
   1.177 +        /* Note: MSVC and GCC (at least on some systems) round towards zero, thus,
   1.178 +           the floor() call is required to ensure correct roudning of
   1.179 +           negative numbers */
   1.180 +        return (int)floor(f+.5);
   1.181 +}
   1.182 +
   1.183 +/* We don't have special code for this compiler/arch, so do it the slow way */
   1.184 +#  define vorbis_fpu_setround(vorbis_fpu_control) {}
   1.185 +#  define vorbis_fpu_restore(vorbis_fpu_control) {}
   1.186 +
   1.187 +#endif /* default implementation */
   1.188 +
   1.189 +#endif /* _OS_H */