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

Annotation of /xvidcore/src/portab.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.48 - (view) (download)

1 : edgomez 1.27 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Portable macros, types and inlined assembly -
5 :     *
6 : edgomez 1.33 * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
7 : edgomez 1.34 * 2002 Peter Ross <pross@xvid.org>
8 : edgomez 1.40 * 2002 Edouard Gomez <ed.gomez@free.fr>
9 : edgomez 1.27 *
10 : edgomez 1.35 * This file is part of XviD, a free MPEG-4 video encoder/decoder
11 :     *
12 :     * XviD is free software; you can redistribute it and/or modify it
13 :     * under the terms of the GNU General Public License as published by
14 :     * the Free Software Foundation; either version 2 of the License, or
15 : edgomez 1.27 * (at your option) any later version.
16 :     *
17 :     * This program is distributed in the hope that it will be useful,
18 : edgomez 1.35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 : edgomez 1.27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 :     * GNU General Public License for more details.
21 :     *
22 :     * You should have received a copy of the GNU General Public License
23 : edgomez 1.35 * along with this program; if not, write to the Free Software
24 : edgomez 1.27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 :     *
26 : suxen_drol 1.48 * $Id: portab.h,v 1.47 2003/03/04 16:33:16 chl Exp $
27 : edgomez 1.27 *
28 :     ****************************************************************************/
29 :    
30 : Isibaar 1.1 #ifndef _PORTAB_H_
31 :     #define _PORTAB_H_
32 :    
33 : edgomez 1.28 /*****************************************************************************
34 :     * Common things
35 :     ****************************************************************************/
36 : suxen_drol 1.23
37 : edgomez 1.28 /* Debug level masks */
38 : edgomez 1.44 #define DPRINTF_ERROR 0x00000001
39 :     #define DPRINTF_STARTCODE 0x00000002
40 :     #define DPRINTF_HEADER 0x00000004
41 :     #define DPRINTF_TIMECODE 0x00000008
42 :     #define DPRINTF_MB 0x00000010
43 :     #define DPRINTF_COEFF 0x00000020
44 :     #define DPRINTF_MV 0x00000040
45 :     #define DPRINTF_RC 0x00000080
46 :     #define DPRINTF_DEBUG 0x80000000
47 : suxen_drol 1.23
48 : edgomez 1.28 /* debug level for this library */
49 : edgomez 1.44 #ifdef _DEBUG
50 :     #define DPRINTF_LEVEL 0x000000ff
51 :     #else
52 :     #define DPRINTF_LEVEL 0
53 :     #endif
54 : suxen_drol 1.23
55 : edgomez 1.42 /* Buffer size for msvc implementation because it outputs to DebugOutput */
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 : edgomez 1.41 | For MSVC
64 : edgomez 1.28 *---------------------------------------------------------------------------*/
65 :    
66 : edgomez 1.43 #if defined(_MSC_VER) || defined (__WATCOMC__)
67 : edgomez 1.28 # define int8_t char
68 :     # define uint8_t unsigned char
69 :     # define int16_t short
70 :     # define uint16_t unsigned short
71 :     # define int32_t int
72 :     # define uint32_t unsigned int
73 :     # define int64_t __int64
74 :     # define uint64_t unsigned __int64
75 :    
76 :     /*----------------------------------------------------------------------------
77 : edgomez 1.42 | For all other compilers, use the standard header file
78 :     | (compiler should be ISO C99 compatible, perhaps ISO C89 is enough)
79 : edgomez 1.28 *---------------------------------------------------------------------------*/
80 :    
81 : edgomez 1.42 #else
82 : edgomez 1.28
83 : edgomez 1.42 # include <inttypes.h>
84 : suxen_drol 1.16
85 : h 1.2 #endif
86 : Isibaar 1.1
87 : edgomez 1.28 /*****************************************************************************
88 : chl 1.46 * Some things that are only architecture dependant
89 : edgomez 1.28 ****************************************************************************/
90 : Isibaar 1.1
91 : edgomez 1.41 #if defined(ARCH_IS_32BIT)
92 : chl 1.47 # define CACHE_LINE 64
93 : edgomez 1.28 # define ptr_t uint32_t
94 : chl 1.47 # define intptr_t int32_t
95 : suxen_drol 1.48 # if _MSC_VER < 1300
96 :     # define uintptr_t uint32_t
97 :     # else
98 :     # include <stdarg.h>
99 :     # endif
100 : edgomez 1.41 #elif defined(ARCH_IS_64BIT)
101 : chl 1.46 # define CACHE_LINE 64
102 : edgomez 1.28 # define ptr_t uint64_t
103 : chl 1.47 # define intptr_t int64_t
104 : suxen_drol 1.48 # if _MSC_VER < 1300
105 :     # define uintptr_t uint64_t
106 :     # else
107 :     # include <stdarg.h>
108 :     # endif
109 : suxen_drol 1.7 #else
110 : edgomez 1.41 # error You are trying to compile XviD without defining address bus size.
111 : suxen_drol 1.7 #endif
112 : Isibaar 1.4
113 : edgomez 1.28 /*****************************************************************************
114 :     * Things that must be sorted by compiler and then by architecture
115 :     ****************************************************************************/
116 : Isibaar 1.1
117 : edgomez 1.28 /*****************************************************************************
118 :     * MSVC compiler specific macros, functions
119 :     ****************************************************************************/
120 : edgomez 1.18
121 : edgomez 1.28 #if defined(_MSC_VER)
122 : edgomez 1.18
123 : edgomez 1.28 /*----------------------------------------------------------------------------
124 :     | Common msvc stuff
125 :     *---------------------------------------------------------------------------*/
126 : Isibaar 1.1
127 : edgomez 1.44 # include <windows.h>
128 :     # include <stdio.h>
129 :    
130 :     /* Non ANSI mapping */
131 :     # define snprintf _snprintf
132 :     # define vsnprintf _vsnprintf
133 : suxen_drol 1.23
134 : edgomez 1.28 /*
135 :     * This function must be declared/defined all the time because MSVC does
136 : edgomez 1.41 * not support C99 variable arguments macros.
137 :     *
138 :     * Btw, if the MS compiler does its job well, it should remove the nop
139 :     * DPRINTF function when not compiling in _DEBUG mode
140 : edgomez 1.28 */
141 : edgomez 1.41 # ifdef _DEBUG
142 : edgomez 1.28 static __inline void DPRINTF(int level, char *fmt, ...)
143 :     {
144 :     if (DPRINTF_LEVEL & level) {
145 :     va_list args;
146 :     char buf[DPRINTF_BUF_SZ];
147 :     va_start(args, fmt);
148 :     vsprintf(buf, fmt, args);
149 :     OutputDebugString(buf);
150 :     fprintf(stderr, "%s\n", buf);
151 :     }
152 :     }
153 : edgomez 1.41 # else
154 : suxen_drol 1.45 static __inline void DPRINTF(int level, char *fmt, ...) {}
155 : edgomez 1.41 # endif
156 : edgomez 1.28
157 :     # if _MSC_VER <= 1200
158 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
159 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
160 :     type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
161 :     # else
162 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
163 :     __declspec(align(alignment)) type name[(sizex)*(sizey)]
164 :     # endif
165 :    
166 :    
167 :     /*----------------------------------------------------------------------------
168 :     | msvc x86 specific macros/functions
169 :     *---------------------------------------------------------------------------*/
170 : edgomez 1.41 # if defined(ARCH_IS_IA32)
171 : h 1.31 # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
172 : edgomez 1.28
173 : suxen_drol 1.45 static __inline int64_t read_counter(void)
174 :     {
175 :     int64_t ts;
176 :     uint32_t ts1, ts2;
177 :     __asm {
178 :     rdtsc
179 :     mov ts1, eax
180 :     mov ts2, edx
181 : edgomez 1.28 }
182 : suxen_drol 1.45 ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
183 :     return ts;
184 :     }
185 : edgomez 1.28
186 :     /*----------------------------------------------------------------------------
187 : edgomez 1.41 | msvc GENERIC (plain C only) - Probably alpha or some embedded device
188 :     *---------------------------------------------------------------------------*/
189 :     # elif defined(ARCH_IS_GENERIC)
190 :     # define BSWAP(a) \
191 :     ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
192 :     (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
193 :    
194 : suxen_drol 1.45 # include <time.h>
195 :     static __inline int64_t read_counter(void)
196 :     {
197 :     return (int64_t)clock();
198 :     }
199 : edgomez 1.41
200 :     /*----------------------------------------------------------------------------
201 :     | msvc Not given architecture - This is probably an user who tries to build
202 :     | XviD the wrong way.
203 : edgomez 1.28 *---------------------------------------------------------------------------*/
204 :     # else
205 : edgomez 1.41 # error You are trying to compile XviD without defining the architecture type.
206 : edgomez 1.28 # endif
207 : suxen_drol 1.22
208 : chl 1.3
209 : Isibaar 1.1
210 :    
211 : edgomez 1.28 /*****************************************************************************
212 :     * GNU CC compiler stuff
213 :     ****************************************************************************/
214 : canard 1.8
215 : chl 1.37 #elif defined(__GNUC__) || defined(__ICC) /* Compiler test */
216 : Isibaar 1.1
217 : edgomez 1.28 /*----------------------------------------------------------------------------
218 :     | Common gcc stuff
219 :     *---------------------------------------------------------------------------*/
220 :    
221 :     /*
222 :     * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
223 :     * and it's a macro calling fprintf directly
224 :     */
225 :     # ifdef _DEBUG
226 :    
227 :     /* Needed for all debuf fprintf calls */
228 :     # include <stdio.h>
229 : edgomez 1.41 # include <stdarg.h>
230 : edgomez 1.28
231 : edgomez 1.41 static __inline void DPRINTF(int level, char *format, ...)
232 :     {
233 :     va_list args;
234 :     va_start(args, format);
235 :     if(DPRINTF_LEVEL & level) {
236 :     vfprintf(stderr, format, args);
237 : edgomez 1.42 fprintf(stderr, "\n");
238 : suxen_drol 1.45 }
239 :     }
240 : edgomez 1.28
241 :     # else /* _DEBUG */
242 : edgomez 1.41 static __inline void DPRINTF(int level, char *format, ...) {}
243 : edgomez 1.28 # endif /* _DEBUG */
244 :    
245 :    
246 : edgomez 1.29 # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
247 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
248 :     type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))
249 : edgomez 1.28
250 :     /*----------------------------------------------------------------------------
251 : edgomez 1.41 | gcc IA32 specific macros/functions
252 : edgomez 1.28 *---------------------------------------------------------------------------*/
253 : edgomez 1.41 # if defined(ARCH_IS_IA32)
254 : edgomez 1.28 # define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
255 :    
256 : suxen_drol 1.45 static __inline int64_t read_counter(void)
257 :     {
258 :     int64_t ts;
259 :     uint32_t ts1, ts2;
260 :     __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
261 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
262 :     return ts;
263 :     }
264 : edgomez 1.28
265 :     /*----------------------------------------------------------------------------
266 :     | gcc PPC and PPC Altivec specific macros/functions
267 :     *---------------------------------------------------------------------------*/
268 : edgomez 1.41 # elif defined(ARCH_IS_PPC)
269 : edgomez 1.28 # define BSWAP(a) __asm__ __volatile__ \
270 :     ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
271 :    
272 : suxen_drol 1.45 static __inline unsigned long get_tbl(void)
273 :     {
274 :     unsigned long tbl;
275 :     asm volatile ("mftb %0":"=r" (tbl));
276 :     return tbl;
277 :     }
278 : edgomez 1.28
279 : suxen_drol 1.45 static __inline unsigned long get_tbu(void)
280 :     {
281 :     unsigned long tbl;
282 :     asm volatile ("mftbu %0":"=r" (tbl));
283 :     return tbl;
284 :     }
285 : edgomez 1.28
286 : suxen_drol 1.45 static __inline int64_t read_counter(void)
287 :     {
288 :     unsigned long tb, tu;
289 :     do {
290 :     tu = get_tbu();
291 :     tb = get_tbl();
292 :     }while (tb != get_tbl());
293 :     return (((int64_t) tu) << 32) | (int64_t) tb;
294 :     }
295 : edgomez 1.28
296 :     /*----------------------------------------------------------------------------
297 :     | gcc IA64 specific macros/functions
298 :     *---------------------------------------------------------------------------*/
299 : edgomez 1.41 # elif defined(ARCH_IS_IA64)
300 : edgomez 1.28 # define BSWAP(a) __asm__ __volatile__ \
301 :     ("mux1 %1 = %0, @rev" ";;" \
302 :     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
303 :    
304 : suxen_drol 1.45 static __inline int64_t read_counter(void)
305 :     {
306 :     unsigned long result;
307 :     __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
308 :     return result;
309 :     }
310 : edgomez 1.28
311 :     /*----------------------------------------------------------------------------
312 : edgomez 1.41 | gcc GENERIC (plain C only) specific macros/functions
313 : edgomez 1.28 *---------------------------------------------------------------------------*/
314 : edgomez 1.41 # elif defined(ARCH_IS_GENERIC)
315 : edgomez 1.28 # define BSWAP(a) \
316 : edgomez 1.30 ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
317 : edgomez 1.28 (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
318 :    
319 : suxen_drol 1.45 # include <time.h>
320 :     static __inline int64_t read_counter(void)
321 :     {
322 :     return (int64_t)clock();
323 :     }
324 : edgomez 1.28
325 :     /*----------------------------------------------------------------------------
326 : edgomez 1.41 | gcc Not given architecture - This is probably an user who tries to build
327 :     | XviD the wrong way.
328 : edgomez 1.28 *---------------------------------------------------------------------------*/
329 :     # else
330 : edgomez 1.41 # error You are trying to compile XviD without defining the architecture type.
331 :     # endif
332 : edgomez 1.43
333 : edgomez 1.44
334 :    
335 :    
336 : edgomez 1.43 /*****************************************************************************
337 : edgomez 1.44 * Open WATCOM C/C++ compiler
338 : edgomez 1.43 ****************************************************************************/
339 : edgomez 1.44
340 : edgomez 1.43 #elif defined(__WATCOMC__)
341 :    
342 :     # include <stdio.h>
343 :     # include <stdarg.h>
344 :    
345 :     # ifdef _DEBUG
346 : suxen_drol 1.45 static __inline void DPRINTF(int level, char *fmt, ...)
347 :     {
348 :     if (DPRINTF_LEVEL & level) {
349 :     va_list args;
350 :     char buf[DPRINTF_BUF_SZ];
351 :     va_start(args, fmt);
352 :     vsprintf(buf, fmt, args);
353 :     fprintf(stderr, "%s\n", buf);
354 :     }
355 :     }
356 : edgomez 1.43 # else /* _DEBUG */
357 : suxen_drol 1.45 static __inline void DPRINTF(int level, char *format, ...) {}
358 : edgomez 1.43 # endif /* _DEBUG */
359 :    
360 : suxen_drol 1.45 # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
361 : edgomez 1.43 type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
362 :     type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
363 :    
364 :     /*----------------------------------------------------------------------------
365 : edgomez 1.44 | watcom ia32 specific macros/functions
366 : edgomez 1.43 *---------------------------------------------------------------------------*/
367 :     # if defined(ARCH_IS_IA32)
368 :    
369 :     # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
370 : edgomez 1.44
371 : edgomez 1.43 static __inline int64_t read_counter(void)
372 :     {
373 :     uint64_t ts;
374 :     uint32_t ts1, ts2;
375 :     __asm {
376 :     rdtsc
377 :     mov ts1, eax
378 :     mov ts2, edx
379 :     }
380 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
381 :     return ts;
382 :     }
383 :    
384 :     /*----------------------------------------------------------------------------
385 : edgomez 1.44 | watcom GENERIC (plain C only) specific macros/functions.
386 : edgomez 1.43 *---------------------------------------------------------------------------*/
387 : suxen_drol 1.45 # elif defined(ARCH_IS_GENERIC)
388 : edgomez 1.43
389 : suxen_drol 1.45 # define BSWAP(x) \
390 :     x = ((((x) & 0xff000000) >> 24) | \
391 :     (((x) & 0x00ff0000) >> 8) | \
392 :     (((x) & 0x0000ff00) << 8) | \
393 :     (((x) & 0x000000ff) << 24))
394 : edgomez 1.44
395 : edgomez 1.43 static int64_t read_counter() { return 0; }
396 :    
397 : edgomez 1.44 /*----------------------------------------------------------------------------
398 :     | watcom Not given architecture - This is probably an user who tries to build
399 :     | XviD the wrong way.
400 :     *---------------------------------------------------------------------------*/
401 :     # else
402 :     # error You are trying to compile XviD without defining the architecture type.
403 :     # endif
404 :    
405 : edgomez 1.9
406 : edgomez 1.28 /*****************************************************************************
407 :     * Unknown compiler
408 :     ****************************************************************************/
409 :     #else /* Compiler test */
410 : Isibaar 1.21
411 : edgomez 1.42 /*
412 : suxen_drol 1.45 * Ok we know nothing about the compiler, so we fallback to ANSI C
413 :     * features, so every compiler should be happy and compile the code.
414 :     *
415 :     * This is (mostly) equivalent to ARCH_IS_GENERIC.
416 :     */
417 : edgomez 1.42
418 :     # ifdef _DEBUG
419 :    
420 :     /* Needed for all debuf fprintf calls */
421 :     # include <stdio.h>
422 :     # include <stdarg.h>
423 :    
424 :     static __inline void DPRINTF(int level, char *format, ...)
425 :     {
426 :     va_list args;
427 :     va_start(args, format);
428 :     if(DPRINTF_LEVEL & level) {
429 :     vfprintf(stderr, format, args);
430 :     fprintf(stderr, "\n");
431 : suxen_drol 1.45 }
432 :     }
433 : edgomez 1.42
434 :     # else /* _DEBUG */
435 :     static __inline void DPRINTF(int level, char *format, ...) {}
436 :     # endif /* _DEBUG */
437 :    
438 :     # define BSWAP(a) \
439 :     ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
440 :     (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
441 :    
442 : suxen_drol 1.45 # include <time.h>
443 :     static __inline int64_t read_counter(void)
444 :     {
445 :     return (int64_t)clock();
446 :     }
447 : edgomez 1.42
448 : suxen_drol 1.45 # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
449 : edgomez 1.42 type name[(sizex)*(sizey)]
450 : Isibaar 1.21
451 : edgomez 1.28 #endif /* Compiler test */
452 : Isibaar 1.21
453 : Isibaar 1.1
454 : edgomez 1.44 #endif /* PORTAB_H */

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