Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/libvorbis-1.2.0/lib/os.h @ 52

Last change on this file since 52 was 16, checked in by landauf, 17 years ago

added libvorbis

File size: 3.8 KB
Line 
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-2007             *
11 * by the Xiph.Org Foundation 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 13293 2007-07-24 00:09:47Z xiphmont $
17
18 ********************************************************************/
19
20#ifdef HAVE_CONFIG_H
21#include "config.h"
22#endif
23
24#include <math.h>
25#include <ogg/os_types.h>
26
27#include "misc.h"
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#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
54
55#if defined(__SYMBIAN32__) && defined(__WINS__)
56void *_alloca(size_t size);
57#  define alloca _alloca
58#endif
59
60#ifndef FAST_HYPOT
61#  define FAST_HYPOT hypot
62#endif
63
64#endif
65
66#ifdef HAVE_ALLOCA_H
67#  include <alloca.h>
68#endif
69
70#ifdef USE_MEMORY_H
71#  include <memory.h>
72#endif
73
74#ifndef min
75#  define min(x,y)  ((x)>(y)?(y):(x))
76#endif
77
78#ifndef max
79#  define max(x,y)  ((x)<(y)?(y):(x))
80#endif
81
82#if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
83#  define VORBIS_FPU_CONTROL
84/* both GCC and MSVC are kinda stupid about rounding/casting to int.
85   Because of encapsulation constraints (GCC can't see inside the asm
86   block and so we end up doing stupid things like a store/load that
87   is collectively a noop), we do it this way */
88
89/* we must set up the fpu before this works!! */
90
91typedef ogg_int16_t vorbis_fpu_control;
92
93static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
94  ogg_int16_t ret;
95  ogg_int16_t temp;
96  __asm__ __volatile__("fnstcw %0\n\t"
97          "movw %0,%%dx\n\t"
98          "orw $62463,%%dx\n\t"
99          "movw %%dx,%1\n\t"
100          "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
101  *fpu=ret;
102}
103
104static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
105  __asm__ __volatile__("fldcw %0":: "m"(fpu));
106}
107
108/* assumes the FPU is in round mode! */
109static inline int vorbis_ftoi(double f){  /* yes, double!  Otherwise,
110                                             we get extra fst/fld to
111                                             truncate precision */
112  int i;
113  __asm__("fistl %0": "=m"(i) : "t"(f));
114  return(i);
115}
116#endif
117
118
119#if defined(_WIN32) && !defined(__GNUC__) && !defined(__BORLANDC__)
120#  define VORBIS_FPU_CONTROL
121
122typedef ogg_int16_t vorbis_fpu_control;
123
124static __inline int vorbis_ftoi(double f){
125        int i;
126        __asm{
127                fld f
128                fistp i
129        }
130        return i;
131}
132
133static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
134}
135
136static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
137}
138
139#endif
140
141
142#ifndef VORBIS_FPU_CONTROL
143
144typedef int vorbis_fpu_control;
145
146static int vorbis_ftoi(double f){
147  return (int)(f+.5);
148}
149
150/* We don't have special code for this compiler/arch, so do it the slow way */
151#  define vorbis_fpu_setround(vorbis_fpu_control) {}
152#  define vorbis_fpu_restore(vorbis_fpu_control) {}
153
154#endif
155
156#endif /* _OS_H */
Note: See TracBrowser for help on using the repository browser.