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

Annotation of /trunk/xvidcore/src/portab.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 956 - (view) (download)

1 : edgomez 407 /*****************************************************************************
2 :     *
3 :     * XVID MPEG-4 VIDEO CODEC
4 :     * - Portable macros, types and inlined assembly -
5 :     *
6 : edgomez 603 * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
7 : edgomez 605 * 2002 Peter Ross <pross@xvid.org>
8 : edgomez 742 * 2002 Edouard Gomez <ed.gomez@free.fr>
9 : edgomez 407 *
10 : edgomez 648 * This file is part of XviD, a free MPEG-4 video encoder/decoder
11 : edgomez 407 *
12 : edgomez 648 * 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 407 * (at your option) any later version.
16 :     *
17 :     * This program is distributed in the hope that it will be useful,
18 : edgomez 648 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 : edgomez 407 * 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 648 * along with this program; if not, write to the Free Software
24 : edgomez 407 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 :     *
26 : suxen_drol 956 * $Id: portab.h,v 1.48 2003-03-28 07:28:23 suxen_drol Exp $
27 : edgomez 407 *
28 :     ****************************************************************************/
29 :    
30 : Isibaar 3 #ifndef _PORTAB_H_
31 :     #define _PORTAB_H_
32 :    
33 : edgomez 513 /*****************************************************************************
34 :     * Common things
35 :     ****************************************************************************/
36 : suxen_drol 252
37 : edgomez 513 /* Debug level masks */
38 : edgomez 854 #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 252
48 : edgomez 513 /* debug level for this library */
49 : edgomez 854 #ifdef _DEBUG
50 :     #define DPRINTF_LEVEL 0x000000ff
51 :     #else
52 :     #define DPRINTF_LEVEL 0
53 :     #endif
54 : suxen_drol 252
55 : edgomez 826 /* Buffer size for msvc implementation because it outputs to DebugOutput */
56 : suxen_drol 252 #define DPRINTF_BUF_SZ 1024
57 :    
58 : edgomez 513 /*****************************************************************************
59 :     * Types used in XviD sources
60 :     ****************************************************************************/
61 : suxen_drol 252
62 : edgomez 513 /*----------------------------------------------------------------------------
63 : edgomez 824 | For MSVC
64 : edgomez 513 *---------------------------------------------------------------------------*/
65 : Isibaar 3
66 : edgomez 851 #if defined(_MSC_VER) || defined (__WATCOMC__)
67 : edgomez 513 # 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 : suxen_drol 136
76 : edgomez 513 /*----------------------------------------------------------------------------
77 : edgomez 826 | For all other compilers, use the standard header file
78 :     | (compiler should be ISO C99 compatible, perhaps ISO C89 is enough)
79 : edgomez 513 *---------------------------------------------------------------------------*/
80 : h 108
81 : edgomez 826 #else
82 : Isibaar 3
83 : edgomez 826 # include <inttypes.h>
84 : Isibaar 3
85 : suxen_drol 68 #endif
86 : Isibaar 42
87 : edgomez 513 /*****************************************************************************
88 : chl 869 * Some things that are only architecture dependant
89 : edgomez 513 ****************************************************************************/
90 : Isibaar 3
91 : edgomez 824 #if defined(ARCH_IS_32BIT)
92 : chl 905 # define CACHE_LINE 64
93 : edgomez 513 # define ptr_t uint32_t
94 : chl 905 # define intptr_t int32_t
95 : suxen_drol 956 # if _MSC_VER < 1300
96 :     # define uintptr_t uint32_t
97 :     # else
98 :     # include <stdarg.h>
99 :     # endif
100 : edgomez 824 #elif defined(ARCH_IS_64BIT)
101 : chl 869 # define CACHE_LINE 64
102 : edgomez 513 # define ptr_t uint64_t
103 : chl 905 # define intptr_t int64_t
104 : suxen_drol 956 # if _MSC_VER < 1300
105 :     # define uintptr_t uint64_t
106 :     # else
107 :     # include <stdarg.h>
108 :     # endif
109 : chl 37 #else
110 : edgomez 824 # error You are trying to compile XviD without defining address bus size.
111 : chl 37 #endif
112 : Isibaar 3
113 : edgomez 513 /*****************************************************************************
114 :     * Things that must be sorted by compiler and then by architecture
115 :     ****************************************************************************/
116 : Isibaar 3
117 : edgomez 513 /*****************************************************************************
118 :     * MSVC compiler specific macros, functions
119 :     ****************************************************************************/
120 : Isibaar 3
121 : edgomez 513 #if defined(_MSC_VER)
122 : canard 73
123 : edgomez 513 /*----------------------------------------------------------------------------
124 :     | Common msvc stuff
125 :     *---------------------------------------------------------------------------*/
126 : Isibaar 3
127 : edgomez 854 # include <windows.h>
128 :     # include <stdio.h>
129 : edgomez 78
130 : edgomez 854 /* Non ANSI mapping */
131 :     # define snprintf _snprintf
132 :     # define vsnprintf _vsnprintf
133 :    
134 : edgomez 513 /*
135 :     * This function must be declared/defined all the time because MSVC does
136 : edgomez 824 * 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 513 */
141 : edgomez 824 # ifdef _DEBUG
142 : edgomez 513 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 824 # else
154 : suxen_drol 860 static __inline void DPRINTF(int level, char *fmt, ...) {}
155 : edgomez 824 # endif
156 : Isibaar 3
157 : edgomez 513 # 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 : Isibaar 3
166 :    
167 : edgomez 513 /*----------------------------------------------------------------------------
168 :     | msvc x86 specific macros/functions
169 :     *---------------------------------------------------------------------------*/
170 : edgomez 824 # if defined(ARCH_IS_IA32)
171 : h 518 # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
172 : canard 89
173 : suxen_drol 860 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 513 }
182 : suxen_drol 860 ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
183 :     return ts;
184 :     }
185 : edgomez 195
186 : edgomez 513 /*----------------------------------------------------------------------------
187 : edgomez 824 | msvc GENERIC (plain C only) - Probably alpha or some embedded device
188 : edgomez 513 *---------------------------------------------------------------------------*/
189 : edgomez 824 # 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 860 # include <time.h>
195 :     static __inline int64_t read_counter(void)
196 :     {
197 :     return (int64_t)clock();
198 :     }
199 : edgomez 824
200 :     /*----------------------------------------------------------------------------
201 :     | msvc Not given architecture - This is probably an user who tries to build
202 :     | XviD the wrong way.
203 :     *---------------------------------------------------------------------------*/
204 : edgomez 513 # else
205 : edgomez 824 # error You are trying to compile XviD without defining the architecture type.
206 : edgomez 513 # endif
207 : edgomez 195
208 :    
209 : Isibaar 209
210 :    
211 : edgomez 513 /*****************************************************************************
212 :     * GNU CC compiler stuff
213 :     ****************************************************************************/
214 : Isibaar 209
215 : chl 674 #elif defined(__GNUC__) || defined(__ICC) /* Compiler test */
216 : Isibaar 209
217 : edgomez 513 /*----------------------------------------------------------------------------
218 :     | Common gcc stuff
219 :     *---------------------------------------------------------------------------*/
220 : Isibaar 209
221 : edgomez 513 /*
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 : Isibaar 209
227 : edgomez 513 /* Needed for all debuf fprintf calls */
228 :     # include <stdio.h>
229 : edgomez 824 # include <stdarg.h>
230 : Isibaar 209
231 : edgomez 824 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 826 fprintf(stderr, "\n");
238 : suxen_drol 860 }
239 :     }
240 : ia64p 283
241 : edgomez 513 # else /* _DEBUG */
242 : edgomez 824 static __inline void DPRINTF(int level, char *format, ...) {}
243 : edgomez 513 # endif /* _DEBUG */
244 : Isibaar 209
245 : ia64p 280
246 : edgomez 516 # 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 :    
250 : edgomez 513 /*----------------------------------------------------------------------------
251 : edgomez 824 | gcc IA32 specific macros/functions
252 : edgomez 513 *---------------------------------------------------------------------------*/
253 : edgomez 824 # if defined(ARCH_IS_IA32)
254 : edgomez 513 # define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
255 : Isibaar 209
256 : suxen_drol 860 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 : ia64p 283
265 : edgomez 513 /*----------------------------------------------------------------------------
266 :     | gcc PPC and PPC Altivec specific macros/functions
267 :     *---------------------------------------------------------------------------*/
268 : edgomez 824 # elif defined(ARCH_IS_PPC)
269 : edgomez 513 # define BSWAP(a) __asm__ __volatile__ \
270 :     ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
271 : ia64p 283
272 : suxen_drol 860 static __inline unsigned long get_tbl(void)
273 :     {
274 :     unsigned long tbl;
275 :     asm volatile ("mftb %0":"=r" (tbl));
276 :     return tbl;
277 :     }
278 : ia64p 283
279 : suxen_drol 860 static __inline unsigned long get_tbu(void)
280 :     {
281 :     unsigned long tbl;
282 :     asm volatile ("mftbu %0":"=r" (tbl));
283 :     return tbl;
284 :     }
285 : ia64p 283
286 : suxen_drol 860 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 : ia64p 283
296 : edgomez 513 /*----------------------------------------------------------------------------
297 :     | gcc IA64 specific macros/functions
298 :     *---------------------------------------------------------------------------*/
299 : edgomez 824 # elif defined(ARCH_IS_IA64)
300 : edgomez 513 # define BSWAP(a) __asm__ __volatile__ \
301 :     ("mux1 %1 = %0, @rev" ";;" \
302 :     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
303 : ia64p 283
304 : suxen_drol 860 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 : ia64p 283
311 : edgomez 513 /*----------------------------------------------------------------------------
312 : edgomez 824 | gcc GENERIC (plain C only) specific macros/functions
313 : edgomez 513 *---------------------------------------------------------------------------*/
314 : edgomez 824 # elif defined(ARCH_IS_GENERIC)
315 : edgomez 513 # define BSWAP(a) \
316 : edgomez 517 ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
317 : edgomez 513 (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
318 : ia64p 283
319 : suxen_drol 860 # include <time.h>
320 :     static __inline int64_t read_counter(void)
321 :     {
322 :     return (int64_t)clock();
323 :     }
324 : ia64p 283
325 : edgomez 513 /*----------------------------------------------------------------------------
326 : edgomez 824 | gcc Not given architecture - This is probably an user who tries to build
327 :     | XviD the wrong way.
328 : edgomez 513 *---------------------------------------------------------------------------*/
329 :     # else
330 : edgomez 824 # error You are trying to compile XviD without defining the architecture type.
331 :     # endif
332 : edgomez 677
333 : edgomez 854
334 :    
335 :    
336 : edgomez 513 /*****************************************************************************
337 : edgomez 854 * Open WATCOM C/C++ compiler
338 : edgomez 851 ****************************************************************************/
339 : edgomez 854
340 : edgomez 851 #elif defined(__WATCOMC__)
341 :    
342 :     # include <stdio.h>
343 :     # include <stdarg.h>
344 :    
345 :     # ifdef _DEBUG
346 : suxen_drol 860 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 851 # else /* _DEBUG */
357 : suxen_drol 860 static __inline void DPRINTF(int level, char *format, ...) {}
358 : edgomez 851 # endif /* _DEBUG */
359 :    
360 : suxen_drol 860 # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
361 : edgomez 851 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 854 | watcom ia32 specific macros/functions
366 : edgomez 851 *---------------------------------------------------------------------------*/
367 :     # if defined(ARCH_IS_IA32)
368 :    
369 :     # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
370 : edgomez 854
371 : edgomez 851 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 854 | watcom GENERIC (plain C only) specific macros/functions.
386 : edgomez 851 *---------------------------------------------------------------------------*/
387 : suxen_drol 860 # elif defined(ARCH_IS_GENERIC)
388 : edgomez 851
389 : suxen_drol 860 # define BSWAP(x) \
390 :     x = ((((x) & 0xff000000) >> 24) | \
391 :     (((x) & 0x00ff0000) >> 8) | \
392 :     (((x) & 0x0000ff00) << 8) | \
393 :     (((x) & 0x000000ff) << 24))
394 : edgomez 854
395 : edgomez 851 static int64_t read_counter() { return 0; }
396 :    
397 : edgomez 854 /*----------------------------------------------------------------------------
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 : edgomez 851
405 : edgomez 854
406 : edgomez 851 /*****************************************************************************
407 : edgomez 513 * Unknown compiler
408 :     ****************************************************************************/
409 :     #else /* Compiler test */
410 : Isibaar 3
411 : edgomez 826 /*
412 : suxen_drol 860 * 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 : Isibaar 3
418 : edgomez 826 # 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 860 }
432 :     }
433 : edgomez 826
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 860 # include <time.h>
443 :     static __inline int64_t read_counter(void)
444 :     {
445 :     return (int64_t)clock();
446 :     }
447 : edgomez 826
448 : suxen_drol 860 # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
449 : edgomez 826 type name[(sizex)*(sizey)]
450 :    
451 : edgomez 513 #endif /* Compiler test */
452 : Isibaar 3
453 : Isibaar 209
454 : edgomez 854 #endif /* PORTAB_H */

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