[svn] / branches / release-1_0-branch / xvidcore / src / portab.h Repository:
ViewVC logotype

Annotation of /branches/release-1_0-branch/xvidcore/src/portab.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 905 - (view) (download)
Original Path: trunk/xvidcore/src/portab.h

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 : chl 905 * $Id: portab.h,v 1.47 2003-03-04 16:33:16 chl 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 :     # define uintptr_t uint32_t
96 : edgomez 824 #elif defined(ARCH_IS_64BIT)
97 : chl 869 # define CACHE_LINE 64
98 : edgomez 513 # define ptr_t uint64_t
99 : chl 905 # define intptr_t int64_t
100 :     # define uintptr_t uint64_t
101 : chl 37 #else
102 : edgomez 824 # error You are trying to compile XviD without defining address bus size.
103 : chl 37 #endif
104 : Isibaar 3
105 : edgomez 513 /*****************************************************************************
106 :     * Things that must be sorted by compiler and then by architecture
107 :     ****************************************************************************/
108 : Isibaar 3
109 : edgomez 513 /*****************************************************************************
110 :     * MSVC compiler specific macros, functions
111 :     ****************************************************************************/
112 : Isibaar 3
113 : edgomez 513 #if defined(_MSC_VER)
114 : canard 73
115 : edgomez 513 /*----------------------------------------------------------------------------
116 :     | Common msvc stuff
117 :     *---------------------------------------------------------------------------*/
118 : Isibaar 3
119 : edgomez 854 # include <windows.h>
120 :     # include <stdio.h>
121 : edgomez 78
122 : edgomez 854 /* Non ANSI mapping */
123 :     # define snprintf _snprintf
124 :     # define vsnprintf _vsnprintf
125 :    
126 : edgomez 513 /*
127 :     * This function must be declared/defined all the time because MSVC does
128 : edgomez 824 * not support C99 variable arguments macros.
129 :     *
130 :     * Btw, if the MS compiler does its job well, it should remove the nop
131 :     * DPRINTF function when not compiling in _DEBUG mode
132 : edgomez 513 */
133 : edgomez 824 # ifdef _DEBUG
134 : edgomez 513 static __inline void DPRINTF(int level, char *fmt, ...)
135 :     {
136 :     if (DPRINTF_LEVEL & level) {
137 :     va_list args;
138 :     char buf[DPRINTF_BUF_SZ];
139 :     va_start(args, fmt);
140 :     vsprintf(buf, fmt, args);
141 :     OutputDebugString(buf);
142 :     fprintf(stderr, "%s\n", buf);
143 :     }
144 :     }
145 : edgomez 824 # else
146 : suxen_drol 860 static __inline void DPRINTF(int level, char *fmt, ...) {}
147 : edgomez 824 # endif
148 : Isibaar 3
149 : edgomez 513 # if _MSC_VER <= 1200
150 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
151 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
152 :     type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
153 :     # else
154 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
155 :     __declspec(align(alignment)) type name[(sizex)*(sizey)]
156 :     # endif
157 : Isibaar 3
158 :    
159 : edgomez 513 /*----------------------------------------------------------------------------
160 :     | msvc x86 specific macros/functions
161 :     *---------------------------------------------------------------------------*/
162 : edgomez 824 # if defined(ARCH_IS_IA32)
163 : h 518 # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
164 : canard 89
165 : suxen_drol 860 static __inline int64_t read_counter(void)
166 :     {
167 :     int64_t ts;
168 :     uint32_t ts1, ts2;
169 :     __asm {
170 :     rdtsc
171 :     mov ts1, eax
172 :     mov ts2, edx
173 : edgomez 513 }
174 : suxen_drol 860 ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
175 :     return ts;
176 :     }
177 : edgomez 195
178 : edgomez 513 /*----------------------------------------------------------------------------
179 : edgomez 824 | msvc GENERIC (plain C only) - Probably alpha or some embedded device
180 : edgomez 513 *---------------------------------------------------------------------------*/
181 : edgomez 824 # elif defined(ARCH_IS_GENERIC)
182 :     # define BSWAP(a) \
183 :     ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
184 :     (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
185 :    
186 : suxen_drol 860 # include <time.h>
187 :     static __inline int64_t read_counter(void)
188 :     {
189 :     return (int64_t)clock();
190 :     }
191 : edgomez 824
192 :     /*----------------------------------------------------------------------------
193 :     | msvc Not given architecture - This is probably an user who tries to build
194 :     | XviD the wrong way.
195 :     *---------------------------------------------------------------------------*/
196 : edgomez 513 # else
197 : edgomez 824 # error You are trying to compile XviD without defining the architecture type.
198 : edgomez 513 # endif
199 : edgomez 195
200 :    
201 : Isibaar 209
202 :    
203 : edgomez 513 /*****************************************************************************
204 :     * GNU CC compiler stuff
205 :     ****************************************************************************/
206 : Isibaar 209
207 : chl 674 #elif defined(__GNUC__) || defined(__ICC) /* Compiler test */
208 : Isibaar 209
209 : edgomez 513 /*----------------------------------------------------------------------------
210 :     | Common gcc stuff
211 :     *---------------------------------------------------------------------------*/
212 : Isibaar 209
213 : edgomez 513 /*
214 :     * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
215 :     * and it's a macro calling fprintf directly
216 :     */
217 :     # ifdef _DEBUG
218 : Isibaar 209
219 : edgomez 513 /* Needed for all debuf fprintf calls */
220 :     # include <stdio.h>
221 : edgomez 824 # include <stdarg.h>
222 : Isibaar 209
223 : edgomez 824 static __inline void DPRINTF(int level, char *format, ...)
224 :     {
225 :     va_list args;
226 :     va_start(args, format);
227 :     if(DPRINTF_LEVEL & level) {
228 :     vfprintf(stderr, format, args);
229 : edgomez 826 fprintf(stderr, "\n");
230 : suxen_drol 860 }
231 :     }
232 : ia64p 283
233 : edgomez 513 # else /* _DEBUG */
234 : edgomez 824 static __inline void DPRINTF(int level, char *format, ...) {}
235 : edgomez 513 # endif /* _DEBUG */
236 : Isibaar 209
237 : ia64p 280
238 : edgomez 516 # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
239 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
240 :     type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))
241 :    
242 : edgomez 513 /*----------------------------------------------------------------------------
243 : edgomez 824 | gcc IA32 specific macros/functions
244 : edgomez 513 *---------------------------------------------------------------------------*/
245 : edgomez 824 # if defined(ARCH_IS_IA32)
246 : edgomez 513 # define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
247 : Isibaar 209
248 : suxen_drol 860 static __inline int64_t read_counter(void)
249 :     {
250 :     int64_t ts;
251 :     uint32_t ts1, ts2;
252 :     __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
253 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
254 :     return ts;
255 :     }
256 : ia64p 283
257 : edgomez 513 /*----------------------------------------------------------------------------
258 :     | gcc PPC and PPC Altivec specific macros/functions
259 :     *---------------------------------------------------------------------------*/
260 : edgomez 824 # elif defined(ARCH_IS_PPC)
261 : edgomez 513 # define BSWAP(a) __asm__ __volatile__ \
262 :     ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
263 : ia64p 283
264 : suxen_drol 860 static __inline unsigned long get_tbl(void)
265 :     {
266 :     unsigned long tbl;
267 :     asm volatile ("mftb %0":"=r" (tbl));
268 :     return tbl;
269 :     }
270 : ia64p 283
271 : suxen_drol 860 static __inline unsigned long get_tbu(void)
272 :     {
273 :     unsigned long tbl;
274 :     asm volatile ("mftbu %0":"=r" (tbl));
275 :     return tbl;
276 :     }
277 : ia64p 283
278 : suxen_drol 860 static __inline int64_t read_counter(void)
279 :     {
280 :     unsigned long tb, tu;
281 :     do {
282 :     tu = get_tbu();
283 :     tb = get_tbl();
284 :     }while (tb != get_tbl());
285 :     return (((int64_t) tu) << 32) | (int64_t) tb;
286 :     }
287 : ia64p 283
288 : edgomez 513 /*----------------------------------------------------------------------------
289 :     | gcc IA64 specific macros/functions
290 :     *---------------------------------------------------------------------------*/
291 : edgomez 824 # elif defined(ARCH_IS_IA64)
292 : edgomez 513 # define BSWAP(a) __asm__ __volatile__ \
293 :     ("mux1 %1 = %0, @rev" ";;" \
294 :     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
295 : ia64p 283
296 : suxen_drol 860 static __inline int64_t read_counter(void)
297 :     {
298 :     unsigned long result;
299 :     __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
300 :     return result;
301 :     }
302 : ia64p 283
303 : edgomez 513 /*----------------------------------------------------------------------------
304 : edgomez 824 | gcc GENERIC (plain C only) specific macros/functions
305 : edgomez 513 *---------------------------------------------------------------------------*/
306 : edgomez 824 # elif defined(ARCH_IS_GENERIC)
307 : edgomez 513 # define BSWAP(a) \
308 : edgomez 517 ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
309 : edgomez 513 (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
310 : ia64p 283
311 : suxen_drol 860 # include <time.h>
312 :     static __inline int64_t read_counter(void)
313 :     {
314 :     return (int64_t)clock();
315 :     }
316 : ia64p 283
317 : edgomez 513 /*----------------------------------------------------------------------------
318 : edgomez 824 | gcc Not given architecture - This is probably an user who tries to build
319 :     | XviD the wrong way.
320 : edgomez 513 *---------------------------------------------------------------------------*/
321 :     # else
322 : edgomez 824 # error You are trying to compile XviD without defining the architecture type.
323 :     # endif
324 : edgomez 677
325 : edgomez 854
326 :    
327 :    
328 : edgomez 513 /*****************************************************************************
329 : edgomez 854 * Open WATCOM C/C++ compiler
330 : edgomez 851 ****************************************************************************/
331 : edgomez 854
332 : edgomez 851 #elif defined(__WATCOMC__)
333 :    
334 :     # include <stdio.h>
335 :     # include <stdarg.h>
336 :    
337 :     # ifdef _DEBUG
338 : suxen_drol 860 static __inline void DPRINTF(int level, char *fmt, ...)
339 :     {
340 :     if (DPRINTF_LEVEL & level) {
341 :     va_list args;
342 :     char buf[DPRINTF_BUF_SZ];
343 :     va_start(args, fmt);
344 :     vsprintf(buf, fmt, args);
345 :     fprintf(stderr, "%s\n", buf);
346 :     }
347 :     }
348 : edgomez 851 # else /* _DEBUG */
349 : suxen_drol 860 static __inline void DPRINTF(int level, char *format, ...) {}
350 : edgomez 851 # endif /* _DEBUG */
351 :    
352 : suxen_drol 860 # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
353 : edgomez 851 type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
354 :     type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
355 :    
356 :     /*----------------------------------------------------------------------------
357 : edgomez 854 | watcom ia32 specific macros/functions
358 : edgomez 851 *---------------------------------------------------------------------------*/
359 :     # if defined(ARCH_IS_IA32)
360 :    
361 :     # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
362 : edgomez 854
363 : edgomez 851 static __inline int64_t read_counter(void)
364 :     {
365 :     uint64_t ts;
366 :     uint32_t ts1, ts2;
367 :     __asm {
368 :     rdtsc
369 :     mov ts1, eax
370 :     mov ts2, edx
371 :     }
372 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
373 :     return ts;
374 :     }
375 :    
376 :     /*----------------------------------------------------------------------------
377 : edgomez 854 | watcom GENERIC (plain C only) specific macros/functions.
378 : edgomez 851 *---------------------------------------------------------------------------*/
379 : suxen_drol 860 # elif defined(ARCH_IS_GENERIC)
380 : edgomez 851
381 : suxen_drol 860 # define BSWAP(x) \
382 :     x = ((((x) & 0xff000000) >> 24) | \
383 :     (((x) & 0x00ff0000) >> 8) | \
384 :     (((x) & 0x0000ff00) << 8) | \
385 :     (((x) & 0x000000ff) << 24))
386 : edgomez 854
387 : edgomez 851 static int64_t read_counter() { return 0; }
388 :    
389 : edgomez 854 /*----------------------------------------------------------------------------
390 :     | watcom Not given architecture - This is probably an user who tries to build
391 :     | XviD the wrong way.
392 :     *---------------------------------------------------------------------------*/
393 :     # else
394 :     # error You are trying to compile XviD without defining the architecture type.
395 :     # endif
396 : edgomez 851
397 : edgomez 854
398 : edgomez 851 /*****************************************************************************
399 : edgomez 513 * Unknown compiler
400 :     ****************************************************************************/
401 :     #else /* Compiler test */
402 : Isibaar 3
403 : edgomez 826 /*
404 : suxen_drol 860 * Ok we know nothing about the compiler, so we fallback to ANSI C
405 :     * features, so every compiler should be happy and compile the code.
406 :     *
407 :     * This is (mostly) equivalent to ARCH_IS_GENERIC.
408 :     */
409 : Isibaar 3
410 : edgomez 826 # ifdef _DEBUG
411 :    
412 :     /* Needed for all debuf fprintf calls */
413 :     # include <stdio.h>
414 :     # include <stdarg.h>
415 :    
416 :     static __inline void DPRINTF(int level, char *format, ...)
417 :     {
418 :     va_list args;
419 :     va_start(args, format);
420 :     if(DPRINTF_LEVEL & level) {
421 :     vfprintf(stderr, format, args);
422 :     fprintf(stderr, "\n");
423 : suxen_drol 860 }
424 :     }
425 : edgomez 826
426 :     # else /* _DEBUG */
427 :     static __inline void DPRINTF(int level, char *format, ...) {}
428 :     # endif /* _DEBUG */
429 :    
430 :     # define BSWAP(a) \
431 :     ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
432 :     (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
433 :    
434 : suxen_drol 860 # include <time.h>
435 :     static __inline int64_t read_counter(void)
436 :     {
437 :     return (int64_t)clock();
438 :     }
439 : edgomez 826
440 : suxen_drol 860 # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
441 : edgomez 826 type name[(sizex)*(sizey)]
442 :    
443 : edgomez 513 #endif /* Compiler test */
444 : Isibaar 3
445 : Isibaar 209
446 : edgomez 854 #endif /* PORTAB_H */

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