media/libvorbis/lib/os.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     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 19031 2013-12-03 19:20:50Z tterribe $
    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   (void)fpu;
   139 }
   141 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
   142   (void)fpu;
   143 }
   145 #endif /* Special MSVC 32 bit implementation */
   148 /* Optimized code path for x86_64 builds. Uses SSE2 intrinsics. This can be
   149    done safely because all x86_64 CPUs supports SSE2. */
   150 #if (defined(_MSC_VER) && defined(_WIN64)) || (defined(__GNUC__) && defined (__x86_64__))
   151 #  define VORBIS_FPU_CONTROL
   153 typedef ogg_int16_t vorbis_fpu_control;
   155 #include <emmintrin.h>
   156 static __inline int vorbis_ftoi(double f){
   157         return _mm_cvtsd_si32(_mm_load_sd(&f));
   158 }
   160 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
   161   (void)fpu;
   162 }
   164 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
   165   (void)fpu;
   166 }
   168 #endif /* Special MSVC x64 implementation */
   171 /* If no special implementation was found for the current compiler / platform,
   172    use the default implementation here: */
   173 #ifndef VORBIS_FPU_CONTROL
   175 typedef int vorbis_fpu_control;
   177 static int vorbis_ftoi(double f){
   178         /* Note: MSVC and GCC (at least on some systems) round towards zero, thus,
   179            the floor() call is required to ensure correct roudning of
   180            negative numbers */
   181         return (int)floor(f+.5);
   182 }
   184 /* We don't have special code for this compiler/arch, so do it the slow way */
   185 #  define vorbis_fpu_setround(vorbis_fpu_control) {}
   186 #  define vorbis_fpu_restore(vorbis_fpu_control) {}
   188 #endif /* default implementation */
   190 #endif /* _OS_H */

mercurial