Fix memory leak in psy code.
[platform/upstream/libvorbis.git] / lib / os.h
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-2001             *
11  * by the XIPHOPHORUS Company http://www.xiph.org/                  *
12  *                                                                  *
13  ********************************************************************
14
15  function: #ifdef jail to whip a few platforms into the UNIX ideal.
16  last mod: $Id: os.h,v 1.30 2002/06/28 22:19:37 xiphmont Exp $
17
18  ********************************************************************/
19
20 #include <math.h>
21 #include <ogg/os_types.h>
22
23 #ifndef _V_IFDEFJAIL_H_
24 #  define _V_IFDEFJAIL_H_
25
26 #  ifdef __GNUC__
27 #    define STIN static __inline__
28 #  elif _WIN32
29 #    define STIN static __inline
30 #else
31 #  define STIN static
32 #endif
33
34 #ifndef M_PI
35 #  define M_PI (3.1415926536f)
36 #endif
37
38 #ifdef _WIN32
39 #  include <malloc.h>
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))
43 #endif
44
45 #ifndef FAST_HYPOT
46 #  define FAST_HYPOT hypot
47 #endif
48
49 #endif
50
51 #ifdef HAVE_ALLOCA_H
52 #  include <alloca.h>
53 #endif
54
55 #ifdef USE_MEMORY_H
56 #  include <memory.h>
57 #endif
58
59 #ifndef min
60 #  define min(x,y)  ((x)>(y)?(y):(x))
61 #endif
62
63 #ifndef max
64 #  define max(x,y)  ((x)<(y)?(y):(x))
65 #endif
66
67 #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
68 #  define VORBIS_FPU_CONTROL
69 /* both GCC and MSVC are kinda stupid about rounding/casting to int.
70    Because of encapsulation constraints (GCC can't see inside the asm
71    block and so we end up doing stupid things like a store/load that
72    is collectively a noop), we do it this way */
73
74 /* we must set up the fpu before this works!! */
75
76 typedef ogg_int16_t vorbis_fpu_control;
77
78 static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
79   ogg_int16_t ret;
80   ogg_int16_t temp;
81   __asm__ __volatile__("fnstcw %0\n\t"
82           "movw %0,%%dx\n\t"
83           "orw $62463,%%dx\n\t"
84           "movw %%dx,%1\n\t"
85           "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
86   *fpu=ret;
87 }
88
89 static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
90   __asm__ __volatile__("fldcw %0":: "m"(fpu));
91 }
92
93 /* assumes the FPU is in round mode! */
94 static inline int vorbis_ftoi(double f){  /* yes, double!  Otherwise,
95                                              we get extra fst/fld to
96                                              truncate precision */
97   int i;
98   __asm__("fistl %0": "=m"(i) : "t"(f));
99   return(i);
100 }
101 #endif
102
103
104 #if defined(_WIN32) && !defined(__GNUC__)
105 #  define VORBIS_FPU_CONTROL
106
107 typedef ogg_int16_t vorbis_fpu_control;
108
109 static __inline int vorbis_ftoi(double f){
110         int i;
111         __asm{
112                 fld f
113                 fistp i
114         }
115         return i;
116 }
117
118 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
119 }
120
121 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
122 }
123
124 #endif
125
126
127 #ifndef VORBIS_FPU_CONTROL
128
129 typedef int vorbis_fpu_control;
130
131 static int vorbis_ftoi(double f){
132   return (int)(f+.5);
133 }
134
135 /* We don't have special code for this compiler/arch, so do it the slow way */
136 #  define vorbis_fpu_setround(vorbis_fpu_control) {}
137 #  define vorbis_fpu_restore(vorbis_fpu_control) {}
138
139 #endif
140
141 #endif /* _OS_H */