doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
os.h
Go to the documentation of this file.
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-2002 *
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.33 2003/09/02 05:11:53 xiphmont Exp $
17 
18  ********************************************************************/
19 
20 #include <math.h>
21 #include "../ogg/os_types.h"
22 
23 #include "misc.h"
24 
25 #ifndef _V_IFDEFJAIL_H_
26 # define _V_IFDEFJAIL_H_
27 
28 # ifdef __GNUC__
29 # define STIN static __inline__
30 # elif _WIN32
31 # define STIN static __inline
32 # else
33 # define STIN static
34 # endif
35 
36 #ifdef DJGPP
37 # define rint(x) (floor((x)+0.5f))
38 #endif
39 
40 #ifndef M_PI
41 # define M_PI (3.1415926536f)
42 #endif
43 
44 #ifdef _WIN32
45 # include <malloc.h>
46 # define rint(x) (floor((x)+0.5f))
47 # define NO_FLOAT_MATH_LIB
48 # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
49 #endif
50 
51 #ifndef FAST_HYPOT
52 # define FAST_HYPOT hypot
53 #endif
54 
55 #endif
56 
57 #ifdef HAVE_ALLOCA_H
58 # include <alloca.h>
59 #endif
60 
61 #ifdef USE_MEMORY_H
62 # include <memory.h>
63 #endif
64 
65 #ifndef min
66 # define min(x,y) ((x)>(y)?(y):(x))
67 #endif
68 
69 #ifndef max
70 # define max(x,y) ((x)<(y)?(y):(x))
71 #endif
72 
73 #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
74 # define VORBIS_FPU_CONTROL
75 /* both GCC and MSVC are kinda stupid about rounding/casting to int.
76  Because of encapsulation constraints (GCC can't see inside the asm
77  block and so we end up doing stupid things like a store/load that
78  is collectively a noop), we do it this way */
79 
80 /* we must set up the fpu before this works!! */
81 
83 
84 static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
85  ogg_int16_t ret;
86  ogg_int16_t temp;
87  __asm__ __volatile__("fnstcw %0\n\t"
88  "movw %0,%%dx\n\t"
89  "orw $62463,%%dx\n\t"
90  "movw %%dx,%1\n\t"
91  "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
92  *fpu=ret;
93 }
94 
95 static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
96  __asm__ __volatile__("fldcw %0":: "m"(fpu));
97 }
98 
99 /* assumes the FPU is in round mode! */
100 static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
101  we get extra fst/fld to
102  truncate precision */
103  int i;
104  __asm__("fistl %0": "=m"(i) : "t"(f));
105  return(i);
106 }
107 #endif
108 
109 
110 #if defined(_WIN32) && !defined(__GNUC__) && !defined(__BORLANDC__)
111 # define VORBIS_FPU_CONTROL
112 
114 
115 static __inline int vorbis_ftoi(double f){
116  int i;
117  __asm{
118  fld f
119  fistp i
120  }
121  return i;
122 }
123 
124 static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
125 }
126 
127 static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
128 }
129 
130 #endif
131 
132 
133 #ifndef VORBIS_FPU_CONTROL
134 
135 typedef int vorbis_fpu_control;
136 
137 static int vorbis_ftoi(double f){
138  return (int)(f+.5);
139 }
140 
141 /* We don't have special code for this compiler/arch, so do it the slow way */
142 # define vorbis_fpu_setround(vorbis_fpu_control) {}
143 # define vorbis_fpu_restore(vorbis_fpu_control) {}
144 
145 #endif
146 
147 #endif /* _OS_H */
#define vorbis_fpu_setround(vorbis_fpu_control)
Definition: os.h:142
int i
Definition: process.py:33
int vorbis_fpu_control
Definition: os.h:135
int16_t ogg_int16_t
Definition: os_types.h:136
#define vorbis_fpu_restore(vorbis_fpu_control)
Definition: os.h:143
tuple f
Definition: idal.py:89