3 /********************************************************************
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. *
10 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2002 *
11 * by the XIPHOPHORUS Company http://www.xiph.org/ *
13 ********************************************************************
15 function: #ifdef jail to whip a few platforms into the UNIX ideal.
18 ********************************************************************/
25 #include <ogg/os_types.h>
29 #ifndef _V_IFDEFJAIL_H_
30 # define _V_IFDEFJAIL_H_
33 # define STIN static __inline__
35 # define STIN static __inline
41 # define rint(x) (floor((x)+0.5f))
45 # define M_PI (3.1415926536f)
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))
56 # define FAST_HYPOT hypot
70 # define min(x,y) ((x)>(y)?(y):(x))
74 # define max(x,y) ((x)<(y)?(y):(x))
77 #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
78 # define VORBIS_FPU_CONTROL
79 /* both GCC and MSVC are kinda stupid about rounding/casting to int.
80 Because of encapsulation constraints (GCC can't see inside the asm
81 block and so we end up doing stupid things like a store/load that
82 is collectively a noop), we do it this way */
84 /* we must set up the fpu before this works!! */
86 typedef ogg_int16_t vorbis_fpu_control;
88 static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
91 __asm__ __volatile__("fnstcw %0\n\t"
95 "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
99 static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
100 __asm__ __volatile__("fldcw %0":: "m"(fpu));
103 /* assumes the FPU is in round mode! */
104 static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
105 we get extra fst/fld to
106 truncate precision */
108 __asm__("fistl %0": "=m"(i) : "t"(f));
114 #if defined(_WIN32) && !defined(__GNUC__) && !defined(__BORLANDC__)
115 # define VORBIS_FPU_CONTROL
117 typedef ogg_int16_t vorbis_fpu_control;
119 static __inline int vorbis_ftoi(double f){
128 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
131 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
137 #ifndef VORBIS_FPU_CONTROL
139 typedef int vorbis_fpu_control;
141 static int vorbis_ftoi(double f){
145 /* We don't have special code for this compiler/arch, so do it the slow way */
146 # define vorbis_fpu_setround(vorbis_fpu_control) {}
147 # define vorbis_fpu_restore(vorbis_fpu_control) {}