3 /********************************************************************
5 * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. *
6 * USE, DISTRIBUTION AND REPRODUCTION OF THIS SOURCE IS GOVERNED BY *
7 * THE GNU LESSER/LIBRARY PUBLIC LICENSE, WHICH IS INCLUDED WITH *
8 * THIS SOURCE. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. *
10 * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2001 *
11 * by the XIPHOPHORUS Company http://www.xiph.org/ *
13 ********************************************************************
15 function: #ifdef jail to whip a few platforms into the UNIX ideal.
16 last mod: $Id: os.h,v 1.22 2001/02/02 03:51:57 xiphmont Exp $
18 ********************************************************************/
21 #include <ogg/os_types.h>
23 #ifndef _V_IFDEFJAIL_H_
24 # define _V_IFDEFJAIL_H_
27 # define STIN static inline
29 # define STIN static __inline
35 # define M_PI (3.1415926536f)
40 # define rint(x) (floor((x)+0.5f))
41 # define NO_FLOAT_MATH_LIB
42 # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
46 # define NO_FLOAT_MATH_LIB
49 #ifndef NO_FLOAT_MATH_LIB
62 # define FAST_HYPOT hypot
76 # define min(x,y) ((x)>(y)?(y):(x))
80 # define max(x,y) ((x)<(y)?(y):(x))
83 #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
84 # define VORBIS_FPU_CONTROL
85 /* both GCC and MSVC are kinda stupid about rounding/casting to int.
86 Because of encapsulation constraints (GCC can't see inside the asm
87 block and so we end up doing stupid things like a store/load that
88 is collectively a noop), we do it this way */
90 /* we must set up the fpu before this works!! */
92 typedef ogg_int16_t vorbis_fpu_control;
94 static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
97 __asm__ __volatile__("fnstcw %0\n\t"
101 "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
105 static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
106 __asm__ __volatile__("fldcw %0":: "m"(fpu));
109 /* assumes the FPU is in round mode! */
110 static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
111 we get extra fst/fld to
112 truncate precision */
114 __asm__("fistl %0": "=m"(i) : "t"(f));
120 #if defined(_WIN32) && !defined(__GNUC__)
121 # define VORBIS_FPU_CONTROL
123 typedef ogg_int16_t vorbis_fpu_control;
125 static __inline int vorbis_ftoi(double f){
134 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
137 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
143 #ifndef VORBIS_FPU_CONTROL
145 typedef int vorbis_fpu_control;
147 static int vorbis_ftoi(double f){
151 /* We don't have special code for this compiler/arch, so do it the slow way */
152 # define vorbis_fpu_setround(vorbis_fpu_control) {}
153 # define vorbis_fpu_restore(vorbis_fpu_control) {}