23 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
24 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
25 |
* |
* |
26 |
* Under section 8 of the GNU General Public License, the copyright |
* $Id: portab.h,v 1.46.2.6 2003-05-17 13:26:51 suxen_drol Exp $ |
|
* holders of XVID explicitly forbid distribution in the following |
|
|
* countries: |
|
|
* |
|
|
* - Japan |
|
|
* - United States of America |
|
|
* |
|
|
* Linking XviD statically or dynamically with other modules is making a |
|
|
* combined work based on XviD. Thus, the terms and conditions of the |
|
|
* GNU General Public License cover the whole combination. |
|
|
* |
|
|
* As a special exception, the copyright holders of XviD give you |
|
|
* permission to link XviD with independent modules that communicate with |
|
|
* XviD solely through the VFW1.1 and DShow interfaces, regardless of the |
|
|
* license terms of these independent modules, and to copy and distribute |
|
|
* the resulting combined work under terms of your choice, provided that |
|
|
* every copy of the combined work is accompanied by a complete copy of |
|
|
* the source code of XviD (the version of XviD used to produce the |
|
|
* combined work), being distributed under the terms of the GNU General |
|
|
* Public License plus this exception. An independent module is a module |
|
|
* which is not derived from or based on XviD. |
|
|
* |
|
|
* Note that people who make modified versions of XviD are not obligated |
|
|
* to grant this special exception for their modified versions; it is |
|
|
* their choice whether to do so. The GNU General Public License gives |
|
|
* permission to release a modified version without this exception; this |
|
|
* exception also makes it possible to release a modified version which |
|
|
* carries forward this exception. |
|
|
* |
|
|
* $Id: portab.h,v 1.41 2003-02-09 19:32:52 edgomez Exp $ |
|
27 |
* |
* |
28 |
****************************************************************************/ |
****************************************************************************/ |
29 |
|
|
34 |
* Common things |
* Common things |
35 |
****************************************************************************/ |
****************************************************************************/ |
36 |
|
|
37 |
/* Debug level masks */ |
/* Buffer size for msvc implementation because it outputs to DebugOutput */ |
38 |
#define DPRINTF_ERROR 0x00000001 |
#if defined(_DEBUG) |
39 |
#define DPRINTF_STARTCODE 0x00000002 |
extern unsigned int xvid_debug; |
|
#define DPRINTF_HEADER 0x00000004 |
|
|
#define DPRINTF_TIMECODE 0x00000008 |
|
|
#define DPRINTF_MB 0x00000010 |
|
|
#define DPRINTF_COEFF 0x00000020 |
|
|
#define DPRINTF_MV 0x00000040 |
|
|
#define DPRINTF_DEBUG 0x80000000 |
|
|
|
|
|
/* debug level for this library */ |
|
|
#define DPRINTF_LEVEL 0 |
|
|
|
|
|
/* Buffer size for non C99 compliant compilers (msvc) */ |
|
40 |
#define DPRINTF_BUF_SZ 1024 |
#define DPRINTF_BUF_SZ 1024 |
41 |
|
#endif |
42 |
|
|
43 |
/***************************************************************************** |
/***************************************************************************** |
44 |
* Types used in XviD sources |
* Types used in XviD sources |
48 |
| For MSVC |
| For MSVC |
49 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
50 |
|
|
51 |
#if defined(_MSC_VER) |
#if defined(_MSC_VER) || defined (__WATCOMC__) |
52 |
# define int8_t char |
# define int8_t char |
53 |
# define uint8_t unsigned char |
# define uint8_t unsigned char |
54 |
# define int16_t short |
# define int16_t short |
59 |
# define uint64_t unsigned __int64 |
# define uint64_t unsigned __int64 |
60 |
|
|
61 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
62 |
| For GNU C compatible compilers |
| For all other compilers, use the standard header file |
63 |
|
| (compiler should be ISO C99 compatible, perhaps ISO C89 is enough) |
64 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
65 |
|
|
66 |
#elif defined(__GNUC__) || defined(__ICC) |
#else |
67 |
|
|
68 |
# define int8_t char |
# include <inttypes.h> |
|
# define uint8_t unsigned char |
|
|
# define int16_t short |
|
|
# define uint16_t unsigned short |
|
|
# define int32_t int |
|
|
# define uint32_t unsigned int |
|
|
# define int64_t long long |
|
|
# define uint64_t unsigned long long |
|
69 |
|
|
|
/*---------------------------------------------------------------------------- |
|
|
| Ok, we don't know how to define these types... error |
|
|
*---------------------------------------------------------------------------*/ |
|
|
|
|
|
#else |
|
|
# error Do not know how to define (u)int(size)_t types. |
|
70 |
#endif |
#endif |
71 |
|
|
72 |
/***************************************************************************** |
/***************************************************************************** |
74 |
****************************************************************************/ |
****************************************************************************/ |
75 |
|
|
76 |
#if defined(ARCH_IS_32BIT) |
#if defined(ARCH_IS_32BIT) |
77 |
# define CACHE_LINE 16 |
# define CACHE_LINE 64 |
78 |
# define ptr_t uint32_t |
# define ptr_t uint32_t |
79 |
|
# define intptr_t int32_t |
80 |
|
# if _MSC_VER < 1300 |
81 |
|
# define uintptr_t uint32_t |
82 |
|
# else |
83 |
|
# include <stdarg.h> |
84 |
|
# endif |
85 |
#elif defined(ARCH_IS_64BIT) |
#elif defined(ARCH_IS_64BIT) |
86 |
# define CACHE_LINE 32 |
# define CACHE_LINE 64 |
87 |
# define ptr_t uint64_t |
# define ptr_t uint64_t |
88 |
|
# define intptr_t int64_t |
89 |
|
# if _MSC_VER < 1300 |
90 |
|
# define uintptr_t uint64_t |
91 |
|
# else |
92 |
|
# include <stdarg.h> |
93 |
|
# endif |
94 |
#else |
#else |
95 |
# error You are trying to compile XviD without defining address bus size. |
# error You are trying to compile XviD without defining address bus size. |
96 |
#endif |
#endif |
112 |
#include <windows.h> |
#include <windows.h> |
113 |
#include <stdio.h> |
#include <stdio.h> |
114 |
|
|
115 |
|
/* Non ANSI mapping */ |
116 |
|
# define snprintf _snprintf |
117 |
|
# define vsnprintf _vsnprintf |
118 |
|
|
119 |
/* |
/* |
120 |
* This function must be declared/defined all the time because MSVC does |
* This function must be declared/defined all the time because MSVC does |
121 |
* not support C99 variable arguments macros. |
* not support C99 variable arguments macros. |
126 |
# ifdef _DEBUG |
# ifdef _DEBUG |
127 |
static __inline void DPRINTF(int level, char *fmt, ...) |
static __inline void DPRINTF(int level, char *fmt, ...) |
128 |
{ |
{ |
129 |
if (DPRINTF_LEVEL & level) { |
if (xvid_debug & level) { |
130 |
va_list args; |
va_list args; |
131 |
char buf[DPRINTF_BUF_SZ]; |
char buf[DPRINTF_BUF_SZ]; |
132 |
va_start(args, fmt); |
va_start(args, fmt); |
136 |
} |
} |
137 |
} |
} |
138 |
# else |
# else |
139 |
static __inline void DPRINTF(int level, char *fmt, ...) |
static __inline void DPRINTF(int level, char *fmt, ...) {} |
|
{ |
|
|
} |
|
140 |
# endif |
# endif |
141 |
|
|
142 |
# if _MSC_VER <= 1200 |
# if _MSC_VER <= 1200 |
154 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
155 |
# if defined(ARCH_IS_IA32) |
# if defined(ARCH_IS_IA32) |
156 |
# define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax |
# define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax |
|
# define EMMS() __asm {emms} |
|
157 |
|
|
|
# ifdef _PROFILING_ |
|
158 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
159 |
{ |
{ |
160 |
int64_t ts; |
int64_t ts; |
167 |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
168 |
return ts; |
return ts; |
169 |
} |
} |
|
# endif |
|
170 |
|
|
171 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
172 |
| msvc GENERIC (plain C only) - Probably alpha or some embedded device |
| msvc GENERIC (plain C only) - Probably alpha or some embedded device |
175 |
# define BSWAP(a) \ |
# define BSWAP(a) \ |
176 |
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
177 |
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
|
# define EMMS() |
|
178 |
|
|
|
# ifdef _PROFILING_ |
|
179 |
# include <time.h> |
# include <time.h> |
180 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
181 |
{ |
{ |
182 |
return (int64_t)clock(); |
return (int64_t)clock(); |
183 |
} |
} |
|
# endif |
|
184 |
|
|
185 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
186 |
| msvc Not given architecture - This is probably an user who tries to build |
| msvc Not given architecture - This is probably an user who tries to build |
217 |
{ |
{ |
218 |
va_list args; |
va_list args; |
219 |
va_start(args, format); |
va_start(args, format); |
220 |
if(DPRINTF_LEVEL & level) { |
if(xvid_debug & level) { |
221 |
vfprintf(stderr, format, args); |
vfprintf(stderr, format, args); |
222 |
fprintf(stderr, "\n"); |
fprintf(stderr, "\n"); |
223 |
} |
} |
237 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
238 |
# if defined(ARCH_IS_IA32) |
# if defined(ARCH_IS_IA32) |
239 |
# define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ); |
# define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ); |
|
# define EMMS() __asm__ ("emms\n\t"); |
|
240 |
|
|
|
# ifdef _PROFILING_ |
|
241 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
242 |
{ |
{ |
243 |
int64_t ts; |
int64_t ts; |
246 |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
247 |
return ts; |
return ts; |
248 |
} |
} |
|
# endif |
|
249 |
|
|
250 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
251 |
| gcc PPC and PPC Altivec specific macros/functions |
| gcc PPC and PPC Altivec specific macros/functions |
253 |
# elif defined(ARCH_IS_PPC) |
# elif defined(ARCH_IS_PPC) |
254 |
# define BSWAP(a) __asm__ __volatile__ \ |
# define BSWAP(a) __asm__ __volatile__ \ |
255 |
( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a)); |
( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a)); |
|
# define EMMS() |
|
256 |
|
|
|
# ifdef _PROFILING_ |
|
257 |
static __inline unsigned long get_tbl(void) |
static __inline unsigned long get_tbl(void) |
258 |
{ |
{ |
259 |
unsigned long tbl; |
unsigned long tbl; |
277 |
}while (tb != get_tbl()); |
}while (tb != get_tbl()); |
278 |
return (((int64_t) tu) << 32) | (int64_t) tb; |
return (((int64_t) tu) << 32) | (int64_t) tb; |
279 |
} |
} |
|
# endif |
|
280 |
|
|
281 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
282 |
| gcc IA64 specific macros/functions |
| gcc IA64 specific macros/functions |
285 |
# define BSWAP(a) __asm__ __volatile__ \ |
# define BSWAP(a) __asm__ __volatile__ \ |
286 |
("mux1 %1 = %0, @rev" ";;" \ |
("mux1 %1 = %0, @rev" ";;" \ |
287 |
"shr.u %1 = %1, 32" : "=r" (a) : "r" (a)); |
"shr.u %1 = %1, 32" : "=r" (a) : "r" (a)); |
|
# define EMMS() |
|
288 |
|
|
|
# ifdef _PROFILING_ |
|
289 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
290 |
{ |
{ |
291 |
unsigned long result; |
unsigned long result; |
292 |
__asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); |
__asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); |
293 |
return result; |
return result; |
294 |
} |
} |
|
# endif |
|
295 |
|
|
296 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
297 |
| gcc GENERIC (plain C only) specific macros/functions |
| gcc GENERIC (plain C only) specific macros/functions |
300 |
# define BSWAP(a) \ |
# define BSWAP(a) \ |
301 |
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
302 |
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
|
# define EMMS() |
|
303 |
|
|
|
# ifdef _PROFILING_ |
|
304 |
# include <time.h> |
# include <time.h> |
305 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
306 |
{ |
{ |
307 |
return (int64_t)clock(); |
return (int64_t)clock(); |
308 |
} |
} |
|
# endif |
|
309 |
|
|
310 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
311 |
| gcc Not given architecture - This is probably an user who tries to build |
| gcc Not given architecture - This is probably an user who tries to build |
315 |
# error You are trying to compile XviD without defining the architecture type. |
# error You are trying to compile XviD without defining the architecture type. |
316 |
# endif |
# endif |
317 |
|
|
318 |
|
|
319 |
|
|
320 |
|
|
321 |
|
/***************************************************************************** |
322 |
|
* Open WATCOM C/C++ compiler |
323 |
|
****************************************************************************/ |
324 |
|
|
325 |
|
#elif defined(__WATCOMC__) |
326 |
|
|
327 |
|
# include <stdio.h> |
328 |
|
# include <stdarg.h> |
329 |
|
|
330 |
|
# ifdef _DEBUG |
331 |
|
static __inline void DPRINTF(int level, char *fmt, ...) |
332 |
|
{ |
333 |
|
if (xvid_debug & level) { |
334 |
|
va_list args; |
335 |
|
char buf[DPRINTF_BUF_SZ]; |
336 |
|
va_start(args, fmt); |
337 |
|
vsprintf(buf, fmt, args); |
338 |
|
fprintf(stderr, "%s\n", buf); |
339 |
|
} |
340 |
|
} |
341 |
|
# else /* _DEBUG */ |
342 |
|
static __inline void DPRINTF(int level, char *format, ...) {} |
343 |
|
# endif /* _DEBUG */ |
344 |
|
|
345 |
|
# define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
346 |
|
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
347 |
|
type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1)) |
348 |
|
|
349 |
|
/*---------------------------------------------------------------------------- |
350 |
|
| watcom ia32 specific macros/functions |
351 |
|
*---------------------------------------------------------------------------*/ |
352 |
|
# if defined(ARCH_IS_IA32) |
353 |
|
|
354 |
|
# define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax |
355 |
|
|
356 |
|
static __inline int64_t read_counter(void) |
357 |
|
{ |
358 |
|
uint64_t ts; |
359 |
|
uint32_t ts1, ts2; |
360 |
|
__asm { |
361 |
|
rdtsc |
362 |
|
mov ts1, eax |
363 |
|
mov ts2, edx |
364 |
|
} |
365 |
|
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
366 |
|
return ts; |
367 |
|
} |
368 |
|
|
369 |
|
/*---------------------------------------------------------------------------- |
370 |
|
| watcom GENERIC (plain C only) specific macros/functions. |
371 |
|
*---------------------------------------------------------------------------*/ |
372 |
|
# elif defined(ARCH_IS_GENERIC) |
373 |
|
|
374 |
|
# define BSWAP(x) \ |
375 |
|
x = ((((x) & 0xff000000) >> 24) | \ |
376 |
|
(((x) & 0x00ff0000) >> 8) | \ |
377 |
|
(((x) & 0x0000ff00) << 8) | \ |
378 |
|
(((x) & 0x000000ff) << 24)) |
379 |
|
|
380 |
|
static int64_t read_counter() { return 0; } |
381 |
|
|
382 |
|
/*---------------------------------------------------------------------------- |
383 |
|
| watcom Not given architecture - This is probably an user who tries to build |
384 |
|
| XviD the wrong way. |
385 |
|
*---------------------------------------------------------------------------*/ |
386 |
|
# else |
387 |
|
# error You are trying to compile XviD without defining the architecture type. |
388 |
|
# endif |
389 |
|
|
390 |
|
|
391 |
/***************************************************************************** |
/***************************************************************************** |
392 |
* Unknown compiler |
* Unknown compiler |
393 |
****************************************************************************/ |
****************************************************************************/ |
394 |
#else /* Compiler test */ |
#else /* Compiler test */ |
395 |
|
|
396 |
# error Compiler not supported |
/* |
397 |
|
* Ok we know nothing about the compiler, so we fallback to ANSI C |
398 |
|
* features, so every compiler should be happy and compile the code. |
399 |
|
* |
400 |
|
* This is (mostly) equivalent to ARCH_IS_GENERIC. |
401 |
|
*/ |
402 |
|
|
403 |
|
# ifdef _DEBUG |
404 |
|
|
405 |
|
/* Needed for all debuf fprintf calls */ |
406 |
|
# include <stdio.h> |
407 |
|
# include <stdarg.h> |
408 |
|
|
409 |
|
static __inline void DPRINTF(int level, char *format, ...) |
410 |
|
{ |
411 |
|
va_list args; |
412 |
|
va_start(args, format); |
413 |
|
if(xvid_debug & level) { |
414 |
|
vfprintf(stderr, format, args); |
415 |
|
fprintf(stderr, "\n"); |
416 |
|
} |
417 |
|
} |
418 |
|
|
419 |
|
# else /* _DEBUG */ |
420 |
|
static __inline void DPRINTF(int level, char *format, ...) {} |
421 |
|
# endif /* _DEBUG */ |
422 |
|
|
423 |
|
# define BSWAP(a) \ |
424 |
|
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
425 |
|
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
426 |
|
|
427 |
|
# include <time.h> |
428 |
|
static __inline int64_t read_counter(void) |
429 |
|
{ |
430 |
|
return (int64_t)clock(); |
431 |
|
} |
432 |
|
|
433 |
|
# define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
434 |
|
type name[(sizex)*(sizey)] |
435 |
|
|
436 |
#endif /* Compiler test */ |
#endif /* Compiler test */ |
437 |
|
|
438 |
|
|
439 |
#endif |
#endif /* PORTAB_H */ |