vx32

Local 9vx git repository for patches.
git clone git://r-36.net/vx32
Log | Files | Refs

os.h (3900B)


      1 /* Hacked vx32 version of libvorbis's os.h.
      2  * What libvorbis really should do is use C99's fenv.h facility,
      3  * based on something like a HAVE_FENV_H configure setting.
      4  */
      5 #ifndef _OS_H
      6 #define _OS_H
      7 /********************************************************************
      8  *                                                                  *
      9  * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE.   *
     10  * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
     11  * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
     12  * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
     13  *                                                                  *
     14  * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002             *
     15  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
     16  *                                                                  *
     17  ********************************************************************
     18 
     19  function: #ifdef jail to whip a few platforms into the UNIX ideal.
     20  last mod: $Id: os.h 1919 2005-07-24 14:18:04Z baford $
     21 
     22  ********************************************************************/
     23 
     24 #include <math.h>
     25 #include <ogg/os_types.h>
     26 
     27 #include "libvorbis/lib/misc.h"	// XXX vx32
     28 
     29 #ifndef _V_IFDEFJAIL_H_
     30 #  define _V_IFDEFJAIL_H_
     31 
     32 #  ifdef __GNUC__
     33 #    define STIN static __inline__
     34 #  elif _WIN32
     35 #    define STIN static __inline
     36 #  else
     37 #    define STIN static
     38 #  endif
     39 
     40 #ifdef DJGPP
     41 #  define rint(x)   (floor((x)+0.5f))
     42 #endif
     43 
     44 #ifndef M_PI
     45 #  define M_PI (3.1415926536f)
     46 #endif
     47 
     48 #ifdef _WIN32
     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
     54 
     55 #ifndef FAST_HYPOT
     56 #  define FAST_HYPOT hypot
     57 #endif
     58 
     59 #endif
     60 
     61 #ifdef HAVE_ALLOCA_H
     62 #  include <alloca.h>
     63 #endif
     64 
     65 #ifdef USE_MEMORY_H
     66 #  include <memory.h>
     67 #endif
     68 
     69 #ifndef min
     70 #  define min(x,y)  ((x)>(y)?(y):(x))
     71 #endif
     72 
     73 #ifndef max
     74 #  define max(x,y)  ((x)<(y)?(y):(x))
     75 #endif
     76 
     77 #if 0	// XXX vx32
     78 #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
     79 #  define VORBIS_FPU_CONTROL
     80 /* both GCC and MSVC are kinda stupid about rounding/casting to int.
     81    Because of encapsulation constraints (GCC can't see inside the asm
     82    block and so we end up doing stupid things like a store/load that
     83    is collectively a noop), we do it this way */
     84 
     85 /* we must set up the fpu before this works!! */
     86 
     87 typedef ogg_int16_t vorbis_fpu_control;
     88 
     89 static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
     90   ogg_int16_t ret;
     91   ogg_int16_t temp;
     92   __asm__ __volatile__("fnstcw %0\n\t"
     93 	  "movw %0,%%dx\n\t"
     94 	  "orw $62463,%%dx\n\t"
     95 	  "movw %%dx,%1\n\t"
     96 	  "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
     97   *fpu=ret;
     98 }
     99 
    100 static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
    101   __asm__ __volatile__("fldcw %0":: "m"(fpu));
    102 }
    103 
    104 /* assumes the FPU is in round mode! */
    105 static inline int vorbis_ftoi(double f){  /* yes, double!  Otherwise,
    106                                              we get extra fst/fld to
    107                                              truncate precision */
    108   int i;
    109   __asm__("fistl %0": "=m"(i) : "t"(f));
    110   return(i);
    111 }
    112 #endif
    113 
    114 
    115 #if defined(_WIN32) && !defined(__GNUC__) && !defined(__BORLANDC__)
    116 #  define VORBIS_FPU_CONTROL
    117 
    118 typedef ogg_int16_t vorbis_fpu_control;
    119 
    120 static __inline int vorbis_ftoi(double f){
    121 	int i;
    122 	__asm{
    123 		fld f
    124 		fistp i
    125 	}
    126 	return i;
    127 }
    128 
    129 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
    130 }
    131 
    132 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
    133 }
    134 
    135 #endif
    136 #endif	// XXX vx32
    137 
    138 
    139 #ifndef VORBIS_FPU_CONTROL
    140 
    141 typedef int vorbis_fpu_control;
    142 
    143 static int vorbis_ftoi(double f){
    144   return (int)(f);
    145 }
    146 
    147 /* We don't have special code for this compiler/arch, so do it the slow way */
    148 #  define vorbis_fpu_setround(vorbis_fpu_control) {}
    149 #  define vorbis_fpu_restore(vorbis_fpu_control) {}
    150 
    151 #endif
    152 
    153 #endif /* _OS_H */