3 |
* XVID MPEG-4 VIDEO CODEC |
* XVID MPEG-4 VIDEO CODEC |
4 |
* - Portable macros, types and inlined assembly - |
* - Portable macros, types and inlined assembly - |
5 |
* |
* |
6 |
* Copyright(C) 2002 Michael Militzer |
* Copyright(C) 2002 Michael Militzer <isibaar@xvid.org> |
7 |
|
* 2002 Peter Ross <pross@xvid.org> |
8 |
|
* 2002 Edouard Gomez <ed.gomez@free.fr> |
9 |
* |
* |
10 |
* This program is an implementation of a part of one or more MPEG-4 |
* This file is part of XviD, a free MPEG-4 video encoder/decoder |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
|
|
* to use this software module in hardware or software products are |
|
|
* advised that its use may infringe existing patents or copyrights, and |
|
|
* any such use would be at such party's own risk. The original |
|
|
* developer of this software module and his/her company, and subsequent |
|
|
* editors and their companies, will have no liability for use of this |
|
|
* software or modifications or derivatives thereof. |
|
11 |
* |
* |
12 |
* This program is free software ; you can redistribute it and/or modify |
* XviD is free software; you can redistribute it and/or modify it |
13 |
* it under the terms of the GNU General Public License as published by |
* under the terms of the GNU General Public License as published by |
14 |
* the Free Software Foundation ; either version 2 of the License, or |
* the Free Software Foundation ; either version 2 of the License, or |
15 |
* (at your option) any later version. |
* (at your option) any later version. |
16 |
* |
* |
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 |
* $Id: portab.h,v 1.31 2002-09-22 18:17:32 h Exp $ |
* Under section 8 of the GNU General Public License, the copyright |
27 |
|
* holders of XVID explicitly forbid distribution in the following |
28 |
|
* countries: |
29 |
|
* |
30 |
|
* - Japan |
31 |
|
* - United States of America |
32 |
|
* |
33 |
|
* Linking XviD statically or dynamically with other modules is making a |
34 |
|
* combined work based on XviD. Thus, the terms and conditions of the |
35 |
|
* GNU General Public License cover the whole combination. |
36 |
|
* |
37 |
|
* As a special exception, the copyright holders of XviD give you |
38 |
|
* permission to link XviD with independent modules that communicate with |
39 |
|
* XviD solely through the VFW1.1 and DShow interfaces, regardless of the |
40 |
|
* license terms of these independent modules, and to copy and distribute |
41 |
|
* the resulting combined work under terms of your choice, provided that |
42 |
|
* every copy of the combined work is accompanied by a complete copy of |
43 |
|
* the source code of XviD (the version of XviD used to produce the |
44 |
|
* combined work), being distributed under the terms of the GNU General |
45 |
|
* Public License plus this exception. An independent module is a module |
46 |
|
* which is not derived from or based on XviD. |
47 |
|
* |
48 |
|
* Note that people who make modified versions of XviD are not obligated |
49 |
|
* to grant this special exception for their modified versions; it is |
50 |
|
* their choice whether to do so. The GNU General Public License gives |
51 |
|
* permission to release a modified version without this exception; this |
52 |
|
* exception also makes it possible to release a modified version which |
53 |
|
* carries forward this exception. |
54 |
|
* |
55 |
|
* $Id: portab.h,v 1.41 2003-02-09 19:32:52 edgomez Exp $ |
56 |
* |
* |
57 |
****************************************************************************/ |
****************************************************************************/ |
58 |
|
|
84 |
****************************************************************************/ |
****************************************************************************/ |
85 |
|
|
86 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
87 |
| Standard Unix include file (sorry, we put all unix into "linux" case) |
| For MSVC |
|
*---------------------------------------------------------------------------*/ |
|
|
|
|
|
#if defined(LINUX) || defined(BEOS) || defined(FREEBSD) |
|
|
|
|
|
/* All (u)int(size)_t types are defined here */ |
|
|
# include <inttypes.h> |
|
|
|
|
|
/*---------------------------------------------------------------------------- |
|
|
| msvc (lacks such a header file) |
|
88 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
89 |
|
|
90 |
#elif defined(_MSC_VER) |
#if defined(_MSC_VER) |
91 |
# define int8_t char |
# define int8_t char |
92 |
# define uint8_t unsigned char |
# define uint8_t unsigned char |
93 |
# define int16_t short |
# define int16_t short |
98 |
# define uint64_t unsigned __int64 |
# define uint64_t unsigned __int64 |
99 |
|
|
100 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
101 |
| Fallback when using gcc |
| For GNU C compatible compilers |
102 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
103 |
|
|
104 |
#elif defined(__GNUC__) |
#elif defined(__GNUC__) || defined(__ICC) |
105 |
|
|
106 |
# define int8_t char |
# define int8_t char |
107 |
# define uint8_t unsigned char |
# define uint8_t unsigned char |
117 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
118 |
|
|
119 |
#else |
#else |
120 |
# error Do not know how to define (u)int(size)_t types |
# error Do not know how to define (u)int(size)_t types. |
121 |
#endif |
#endif |
122 |
|
|
123 |
/***************************************************************************** |
/***************************************************************************** |
124 |
* Some things that are only architecture dependant |
* Some things that are only architecture dependant |
125 |
****************************************************************************/ |
****************************************************************************/ |
126 |
|
|
127 |
#if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS) |
#if defined(ARCH_IS_32BIT) |
128 |
# define CACHE_LINE 16 |
# define CACHE_LINE 16 |
129 |
# define ptr_t uint32_t |
# define ptr_t uint32_t |
130 |
#elif defined(ARCH_IA64) || defined(ARCH_SPARC) |
#elif defined(ARCH_IS_64BIT) |
131 |
# define CACHE_LINE 32 |
# define CACHE_LINE 32 |
132 |
# define ptr_t uint64_t |
# define ptr_t uint64_t |
133 |
#else |
#else |
134 |
# error Architecture not supported. |
# error You are trying to compile XviD without defining address bus size. |
135 |
#endif |
#endif |
136 |
|
|
137 |
/***************************************************************************** |
/***************************************************************************** |
153 |
|
|
154 |
/* |
/* |
155 |
* This function must be declared/defined all the time because MSVC does |
* This function must be declared/defined all the time because MSVC does |
156 |
* not support C99 variable arguments macros |
* not support C99 variable arguments macros. |
157 |
|
* |
158 |
|
* Btw, if the MS compiler does its job well, it should remove the nop |
159 |
|
* DPRINTF function when not compiling in _DEBUG mode |
160 |
*/ |
*/ |
161 |
|
# ifdef _DEBUG |
162 |
static __inline void DPRINTF(int level, char *fmt, ...) |
static __inline void DPRINTF(int level, char *fmt, ...) |
163 |
{ |
{ |
164 |
if (DPRINTF_LEVEL & level) { |
if (DPRINTF_LEVEL & level) { |
170 |
fprintf(stderr, "%s\n", buf); |
fprintf(stderr, "%s\n", buf); |
171 |
} |
} |
172 |
} |
} |
173 |
|
# else |
174 |
|
static __inline void DPRINTF(int level, char *fmt, ...) |
175 |
|
{ |
176 |
|
} |
177 |
|
# endif |
178 |
|
|
179 |
# if _MSC_VER <= 1200 |
# if _MSC_VER <= 1200 |
180 |
# define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
# define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
189 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
190 |
| msvc x86 specific macros/functions |
| msvc x86 specific macros/functions |
191 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
192 |
# if defined(ARCH_X86) |
# if defined(ARCH_IS_IA32) |
193 |
# 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 |
194 |
# define EMMS() __asm {emms} |
# define EMMS() __asm {emms} |
195 |
|
|
196 |
|
# ifdef _PROFILING_ |
197 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
198 |
{ |
{ |
199 |
int64_t ts; |
int64_t ts; |
206 |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
207 |
return ts; |
return ts; |
208 |
} |
} |
209 |
|
# endif |
210 |
|
|
211 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
212 |
| msvc unknown architecture |
| msvc GENERIC (plain C only) - Probably alpha or some embedded device |
213 |
|
*---------------------------------------------------------------------------*/ |
214 |
|
# elif defined(ARCH_IS_GENERIC) |
215 |
|
# define BSWAP(a) \ |
216 |
|
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
217 |
|
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
218 |
|
# define EMMS() |
219 |
|
|
220 |
|
# ifdef _PROFILING_ |
221 |
|
# include <time.h> |
222 |
|
static __inline int64_t read_counter(void) |
223 |
|
{ |
224 |
|
return (int64_t)clock(); |
225 |
|
} |
226 |
|
# endif |
227 |
|
|
228 |
|
/*---------------------------------------------------------------------------- |
229 |
|
| msvc Not given architecture - This is probably an user who tries to build |
230 |
|
| XviD the wrong way. |
231 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
232 |
# else |
# else |
233 |
# error Architecture not supported. |
# error You are trying to compile XviD without defining the architecture type. |
234 |
# endif |
# endif |
235 |
|
|
236 |
|
|
240 |
* GNU CC compiler stuff |
* GNU CC compiler stuff |
241 |
****************************************************************************/ |
****************************************************************************/ |
242 |
|
|
243 |
#elif defined(__GNUC__) /* Compiler test */ |
#elif defined(__GNUC__) || defined(__ICC) /* Compiler test */ |
244 |
|
|
245 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
246 |
| Common gcc stuff |
| Common gcc stuff |
254 |
|
|
255 |
/* Needed for all debuf fprintf calls */ |
/* Needed for all debuf fprintf calls */ |
256 |
# include <stdio.h> |
# include <stdio.h> |
257 |
|
# include <stdarg.h> |
258 |
|
|
259 |
# define DPRINTF(level, format, ...) \ |
static __inline void DPRINTF(int level, char *format, ...) |
260 |
do {\ |
{ |
261 |
if(DPRINTF_LEVEL & level)\ |
va_list args; |
262 |
fprintf(stderr, format"\n", ##__VA_ARGS__);\ |
va_start(args, format); |
263 |
}while(0); |
if(DPRINTF_LEVEL & level) { |
264 |
|
vfprintf(stderr, format, args); |
265 |
|
fprintf(stderr, "\n"); |
266 |
|
} |
267 |
|
} |
268 |
|
|
269 |
# else /* _DEBUG */ |
# else /* _DEBUG */ |
270 |
# define DPRINTF(level, format, ...) |
static __inline void DPRINTF(int level, char *format, ...) {} |
271 |
# endif /* _DEBUG */ |
# endif /* _DEBUG */ |
272 |
|
|
273 |
|
|
|
|
|
274 |
# define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
# define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
275 |
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
276 |
type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1)) |
type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1)) |
277 |
|
|
278 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
279 |
| gcc x86 specific macros/functions |
| gcc IA32 specific macros/functions |
280 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
281 |
# if defined(ARCH_X86) |
# if defined(ARCH_IS_IA32) |
282 |
# define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ); |
# define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ); |
283 |
# define EMMS() __asm__ ("emms\n\t"); |
# define EMMS() __asm__ ("emms\n\t"); |
284 |
|
|
285 |
|
# ifdef _PROFILING_ |
286 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
287 |
{ |
{ |
288 |
int64_t ts; |
int64_t ts; |
291 |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
292 |
return ts; |
return ts; |
293 |
} |
} |
294 |
|
# endif |
295 |
|
|
296 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
297 |
| gcc PPC and PPC Altivec specific macros/functions |
| gcc PPC and PPC Altivec specific macros/functions |
298 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
299 |
# elif defined(ARCH_PPC) |
# elif defined(ARCH_IS_PPC) |
300 |
# define BSWAP(a) __asm__ __volatile__ \ |
# define BSWAP(a) __asm__ __volatile__ \ |
301 |
( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a)); |
( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a)); |
302 |
# define EMMS() |
# define EMMS() |
303 |
|
|
304 |
|
# ifdef _PROFILING_ |
305 |
static __inline unsigned long get_tbl(void) |
static __inline unsigned long get_tbl(void) |
306 |
{ |
{ |
307 |
unsigned long tbl; |
unsigned long tbl; |
325 |
}while (tb != get_tbl()); |
}while (tb != get_tbl()); |
326 |
return (((int64_t) tu) << 32) | (int64_t) tb; |
return (((int64_t) tu) << 32) | (int64_t) tb; |
327 |
} |
} |
328 |
|
# endif |
329 |
|
|
330 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
331 |
| gcc IA64 specific macros/functions |
| gcc IA64 specific macros/functions |
332 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
333 |
# elif defined(ARCH_IA64) |
# elif defined(ARCH_IS_IA64) |
334 |
# define BSWAP(a) __asm__ __volatile__ \ |
# define BSWAP(a) __asm__ __volatile__ \ |
335 |
("mux1 %1 = %0, @rev" ";;" \ |
("mux1 %1 = %0, @rev" ";;" \ |
336 |
"shr.u %1 = %1, 32" : "=r" (a) : "r" (a)); |
"shr.u %1 = %1, 32" : "=r" (a) : "r" (a)); |
337 |
# define EMMS() |
# define EMMS() |
338 |
|
|
339 |
static __inline int64_t read_counter(void) { |
# ifdef _PROFILING_ |
340 |
|
static __inline int64_t read_counter(void) |
341 |
|
{ |
342 |
unsigned long result; |
unsigned long result; |
343 |
__asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); |
__asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); |
344 |
return result; |
return result; |
345 |
} |
} |
346 |
|
# endif |
347 |
|
|
348 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
349 |
| gcc SPARC specific macros/functions |
| gcc GENERIC (plain C only) specific macros/functions |
|
*---------------------------------------------------------------------------*/ |
|
|
# elif defined(ARCH_SPARC) |
|
|
# define BSWAP(a) \ |
|
|
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
|
|
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
|
|
# define EMMS() |
|
|
|
|
|
static __inline int64_t read_counter(void) |
|
|
{ |
|
|
return 0; |
|
|
} |
|
|
|
|
|
/*---------------------------------------------------------------------------- |
|
|
| gcc MIPS specific macros/functions |
|
350 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
351 |
# elif defined(ARCH_MIPS) |
# elif defined(ARCH_IS_GENERIC) |
352 |
# define BSWAP(a) \ |
# define BSWAP(a) \ |
353 |
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
354 |
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
355 |
# define EMMS() |
# define EMMS() |
356 |
|
|
357 |
|
# ifdef _PROFILING_ |
358 |
|
# include <time.h> |
359 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
360 |
{ |
{ |
361 |
return 0; |
return (int64_t)clock(); |
362 |
} |
} |
363 |
|
# endif |
364 |
|
|
365 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
366 |
| XviD + gcc unsupported Architecture |
| gcc Not given architecture - This is probably an user who tries to build |
367 |
|
| XviD the wrong way. |
368 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
369 |
# else |
# else |
370 |
# error Architecture not supported. |
# error You are trying to compile XviD without defining the architecture type. |
371 |
# endif /* Architecture checking */ |
# endif |
372 |
|
|
373 |
/***************************************************************************** |
/***************************************************************************** |
374 |
* Unknown compiler |
* Unknown compiler |