[cvs] / xvidcore / src / portab.h Repository:
ViewVC logotype

Annotation of /xvidcore/src/portab.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.28 - (view) (download)

1 : edgomez 1.27 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Portable macros, types and inlined assembly -
5 :     *
6 :     * Copyright(C) 2002 Michael Militzer
7 :     *
8 :     * This program is an implementation of a part of one or more MPEG-4
9 :     * Video tools as specified in ISO/IEC 14496-2 standard. Those intending
10 :     * to use this software module in hardware or software products are
11 :     * advised that its use may infringe existing patents or copyrights, and
12 :     * any such use would be at such party's own risk. The original
13 :     * developer of this software module and his/her company, and subsequent
14 :     * editors and their companies, will have no liability for use of this
15 :     * software or modifications or derivatives thereof.
16 :     *
17 :     * This program is free software ; you can redistribute it and/or modify
18 :     * it under the terms of the GNU General Public License as published by
19 :     * the Free Software Foundation ; either version 2 of the License, or
20 :     * (at your option) any later version.
21 :     *
22 :     * This program is distributed in the hope that it will be useful,
23 :     * but WITHOUT ANY WARRANTY ; without even the implied warranty of
24 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 :     * GNU General Public License for more details.
26 :     *
27 :     * You should have received a copy of the GNU General Public License
28 :     * along with this program ; if not, write to the Free Software
29 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 :     *
31 : edgomez 1.28 * $Id: portab.h,v 1.27 2002/09/04 22:01:59 edgomez Exp $
32 : edgomez 1.27 *
33 :     ****************************************************************************/
34 :    
35 : Isibaar 1.1 #ifndef _PORTAB_H_
36 :     #define _PORTAB_H_
37 :    
38 : edgomez 1.28 /*****************************************************************************
39 :     * Common things
40 :     ****************************************************************************/
41 : suxen_drol 1.23
42 : edgomez 1.28 /* Debug level masks */
43 : suxen_drol 1.23 #define DPRINTF_ERROR 0x00000001
44 :     #define DPRINTF_STARTCODE 0x00000002
45 :     #define DPRINTF_HEADER 0x00000004
46 :     #define DPRINTF_TIMECODE 0x00000008
47 :     #define DPRINTF_MB 0x00000010
48 :     #define DPRINTF_COEFF 0x00000020
49 :     #define DPRINTF_MV 0x00000040
50 :     #define DPRINTF_DEBUG 0x80000000
51 :    
52 : edgomez 1.28 /* debug level for this library */
53 : suxen_drol 1.23 #define DPRINTF_LEVEL 0
54 :    
55 : edgomez 1.28 /* Buffer size for non C99 compliant compilers (msvc) */
56 : suxen_drol 1.23 #define DPRINTF_BUF_SZ 1024
57 :    
58 : edgomez 1.28 /*****************************************************************************
59 :     * Types used in XviD sources
60 :     ****************************************************************************/
61 : suxen_drol 1.23
62 : edgomez 1.28 /*----------------------------------------------------------------------------
63 :     | Standard Unix include file (sorry, we put all unix into "linux" case)
64 :     *---------------------------------------------------------------------------*/
65 :    
66 :     #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)
67 :    
68 :     /* All (u)int(size)_t types are defined here */
69 :     # include <inttypes.h>
70 :    
71 :     /*----------------------------------------------------------------------------
72 :     | msvc (lacks such a header file)
73 :     *---------------------------------------------------------------------------*/
74 :    
75 :     #elif defined(_MSC_VER)
76 :     # define int8_t char
77 :     # define uint8_t unsigned char
78 :     # define int16_t short
79 :     # define uint16_t unsigned short
80 :     # define int32_t int
81 :     # define uint32_t unsigned int
82 :     # define int64_t __int64
83 :     # define uint64_t unsigned __int64
84 :    
85 :     /*----------------------------------------------------------------------------
86 :     | Fallback when using gcc
87 :     *---------------------------------------------------------------------------*/
88 :    
89 :     #elif defined(__GNUC__)
90 :    
91 :     # define int8_t char
92 :     # define uint8_t unsigned char
93 :     # define int16_t short
94 :     # define uint16_t unsigned short
95 :     # define int32_t int
96 :     # define uint32_t unsigned int
97 :     # define int64_t long long
98 :     # define uint64_t unsigned long long
99 :    
100 :     /*----------------------------------------------------------------------------
101 :     | Ok, we don't know how to define these types... error
102 :     *---------------------------------------------------------------------------*/
103 : suxen_drol 1.16
104 : h 1.2 #else
105 : edgomez 1.28 # error Do not know how to define (u)int(size)_t types
106 : h 1.2 #endif
107 : Isibaar 1.1
108 : edgomez 1.28 /*****************************************************************************
109 :     * Some things that are only architecture dependant
110 :     ****************************************************************************/
111 : Isibaar 1.1
112 : edgomez 1.28 #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS)
113 :     # define CACHE_LINE 16
114 :     # define ptr_t uint32_t
115 :     #elif defined(ARCH_IA64) || defined(ARCH_SPARC)
116 :     # define CACHE_LINE 32
117 :     # define ptr_t uint64_t
118 : suxen_drol 1.7 #else
119 : edgomez 1.28 # error Architecture not supported.
120 : suxen_drol 1.7 #endif
121 : Isibaar 1.4
122 : edgomez 1.28 /*****************************************************************************
123 :     * Things that must be sorted by compiler and then by architecture
124 :     ****************************************************************************/
125 : Isibaar 1.1
126 : edgomez 1.28 /*****************************************************************************
127 :     * MSVC compiler specific macros, functions
128 :     ****************************************************************************/
129 : edgomez 1.18
130 : edgomez 1.28 #if defined(_MSC_VER)
131 : edgomez 1.18
132 : edgomez 1.28 /*----------------------------------------------------------------------------
133 :     | Common msvc stuff
134 :     *---------------------------------------------------------------------------*/
135 : Isibaar 1.1
136 : edgomez 1.28 #include <windows.h>
137 : suxen_drol 1.22 #include <stdio.h>
138 : suxen_drol 1.23
139 : edgomez 1.28 /*
140 :     * This function must be declared/defined all the time because MSVC does
141 :     * not support C99 variable arguments macros
142 :     */
143 :     static __inline void DPRINTF(int level, char *fmt, ...)
144 :     {
145 :     if (DPRINTF_LEVEL & level) {
146 :     va_list args;
147 :     char buf[DPRINTF_BUF_SZ];
148 :     va_start(args, fmt);
149 :     vsprintf(buf, fmt, args);
150 :     OutputDebugString(buf);
151 :     fprintf(stderr, "%s\n", buf);
152 :     }
153 :     }
154 :    
155 :     # if _MSC_VER <= 1200
156 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
157 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
158 :     type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
159 :     # else
160 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
161 :     __declspec(align(alignment)) type name[(sizex)*(sizey)]
162 :     # endif
163 :    
164 :    
165 :     /*----------------------------------------------------------------------------
166 :     | msvc x86 specific macros/functions
167 :     *---------------------------------------------------------------------------*/
168 :     # if defined(ARCH_X86)
169 :     # define BSWAP(a)
170 :     __asm { \
171 :     mov eax,a \
172 :     bswap eax \
173 :     mov a, eax \
174 :     }
175 :     # define EMMS() __asm {emms}
176 :    
177 :     static __inline int64_t read_counter(void)
178 :     {
179 :     int64_t ts;
180 :     uint32_t ts1, ts2;
181 :     __asm {
182 :     rdtsc
183 :     mov ts1, eax
184 :     mov ts2, edx
185 :     }
186 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
187 :     return ts;
188 :     }
189 :    
190 :     /*----------------------------------------------------------------------------
191 :     | msvc unknown architecture
192 :     *---------------------------------------------------------------------------*/
193 :     # else
194 :     # error Architecture not supported.
195 :     # endif
196 : suxen_drol 1.22
197 : chl 1.3
198 : Isibaar 1.1
199 :    
200 : edgomez 1.28 /*****************************************************************************
201 :     * GNU CC compiler stuff
202 :     ****************************************************************************/
203 : canard 1.8
204 : edgomez 1.28 #elif defined(__GNUC__) /* Compiler test */
205 : Isibaar 1.1
206 : edgomez 1.28 /*----------------------------------------------------------------------------
207 :     | Common gcc stuff
208 :     *---------------------------------------------------------------------------*/
209 :    
210 :     /*
211 :     * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
212 :     * and it's a macro calling fprintf directly
213 :     */
214 :     # ifdef _DEBUG
215 :    
216 :     /* Needed for all debuf fprintf calls */
217 :     # include <stdio.h>
218 :    
219 :     # define DPRINTF(level, format, ...) \
220 :     do {\
221 :     if(DPRINTF_LEVEL & level)\
222 :     fprintf(stderr, format"\n", ##__VA_ARGS__);\
223 :     }while(0);
224 :    
225 :     # else /* _DEBUG */
226 :     # define DPRINTF(level, format, ...)
227 :     # endif /* _DEBUG */
228 :    
229 :    
230 :     # ifdef _DEBUG
231 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
232 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
233 :     type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))
234 :     # else
235 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
236 :     __attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)]
237 :     # endif
238 :    
239 :     /*----------------------------------------------------------------------------
240 :     | gcc x86 specific macros/functions
241 :     *---------------------------------------------------------------------------*/
242 :     # if defined(ARCH_X86)
243 :     # define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
244 :     # define EMMS() __asm__ ("emms\n\t");
245 :    
246 :     static __inline int64_t read_counter(void)
247 :     {
248 :     int64_t ts;
249 :     uint32_t ts1, ts2;
250 :     __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
251 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
252 :     return ts;
253 :     }
254 :    
255 :     /*----------------------------------------------------------------------------
256 :     | gcc PPC and PPC Altivec specific macros/functions
257 :     *---------------------------------------------------------------------------*/
258 :     # elif defined(ARCH_PPC)
259 :     # define BSWAP(a) __asm__ __volatile__ \
260 :     ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
261 :     # define EMMS()
262 :    
263 :     static __inline unsigned long get_tbl(void)
264 :     {
265 :     unsigned long tbl;
266 :     asm volatile ("mftb %0":"=r" (tbl));
267 :     return tbl;
268 :     }
269 :    
270 :     static __inline unsigned long get_tbu(void)
271 :     {
272 :     unsigned long tbl;
273 :     asm volatile ("mftbu %0":"=r" (tbl));
274 :     return tbl;
275 :     }
276 :    
277 :     static __inline int64_t read_counter(void)
278 :     {
279 :     unsigned long tb, tu;
280 :     do {
281 :     tu = get_tbu();
282 :     tb = get_tbl();
283 :     }while (tb != get_tbl());
284 :     return (((int64_t) tu) << 32) | (int64_t) tb;
285 :     }
286 :    
287 :     /*----------------------------------------------------------------------------
288 :     | gcc IA64 specific macros/functions
289 :     *---------------------------------------------------------------------------*/
290 :     # elif defined(ARCH_IA64)
291 :     # define BSWAP(a) __asm__ __volatile__ \
292 :     ("mux1 %1 = %0, @rev" ";;" \
293 :     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
294 :     # define EMMS()
295 :    
296 :     static __inline int64_t read_counter(void) {
297 :     unsigned long result;
298 :     __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
299 :     return result;
300 :     }
301 :    
302 :     /*----------------------------------------------------------------------------
303 :     | gcc SPARC specific macros/functions
304 :     *---------------------------------------------------------------------------*/
305 :     # elif defined(ARCH_SPARC)
306 :     # define BSWAP(a) \
307 :     ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) |
308 :     (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
309 :     # define EMMS()
310 :    
311 :     static __inline int64_t read_counter(void)
312 :     {
313 :     return 0;
314 :     }
315 :    
316 :     /*----------------------------------------------------------------------------
317 :     | gcc MIPS specific macros/functions
318 :     *---------------------------------------------------------------------------*/
319 :     # elif defined(ARCH_MIPS)
320 :     # define BSWAP(a) \
321 :     ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) |
322 :     (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
323 :     # define EMMS()
324 :    
325 :     static __inline int64_t read_counter(void)
326 :     {
327 :     return 0;
328 :     }
329 :    
330 :     /*----------------------------------------------------------------------------
331 :     | XviD + gcc unsupported Architecture
332 :     *---------------------------------------------------------------------------*/
333 :     # else
334 :     # error Architecture not supported.
335 :     # endif /* Architecture checking */
336 : edgomez 1.9
337 : edgomez 1.28 /*****************************************************************************
338 :     * Unknown compiler
339 :     ****************************************************************************/
340 :     #else /* Compiler test */
341 : Isibaar 1.21
342 : edgomez 1.28 # error Compiler not supported
343 : Isibaar 1.21
344 : edgomez 1.28 #endif /* Compiler test */
345 : Isibaar 1.21
346 : Isibaar 1.1
347 :     #endif

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4