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 <isibaar@xvid.org> |
* Copyright(C) 2002 Michael Militzer |
|
* 2002 Peter Ross <pross@xvid.org> |
|
|
* 2002 Edouard Gomez <ed.gomez@wanadoo.fr> |
|
7 |
* |
* |
8 |
* This file is part of XviD, a free MPEG-4 video encoder/decoder |
* This program is an implementation of a part of one or more MPEG-4 |
9 |
|
* Video tools as specified in ISO/IEC 14496-2 standard. Those intending |
10 |
|
* to use this software module in hardware or software products are |
11 |
|
* advised that its use may infringe existing patents or copyrights, and |
12 |
|
* any such use would be at such party's own risk. The original |
13 |
|
* developer of this software module and his/her company, and subsequent |
14 |
|
* editors and their companies, will have no liability for use of this |
15 |
|
* software or modifications or derivatives thereof. |
16 |
* |
* |
17 |
* XviD is free software; you can redistribute it and/or modify it |
* This program is free software ; you can redistribute it and/or modify |
18 |
* under the terms of the GNU General Public License as published by |
* it under the terms of the GNU General Public License as published by |
19 |
* the Free Software Foundation; either version 2 of the License, or |
* the Free Software Foundation; either version 2 of the License, or |
20 |
* (at your option) any later version. |
* (at your option) any later version. |
21 |
* |
* |
28 |
* along with this program; if not, write to the Free Software |
* along with this program; if not, write to the Free Software |
29 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
30 |
* |
* |
|
* Under section 8 of the GNU General Public License, the copyright |
|
|
* 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. |
|
|
* |
|
31 |
* $Id$ |
* $Id$ |
32 |
* |
* |
33 |
****************************************************************************/ |
****************************************************************************/ |
47 |
#define DPRINTF_MB 0x00000010 |
#define DPRINTF_MB 0x00000010 |
48 |
#define DPRINTF_COEFF 0x00000020 |
#define DPRINTF_COEFF 0x00000020 |
49 |
#define DPRINTF_MV 0x00000040 |
#define DPRINTF_MV 0x00000040 |
|
#define DPRINTF_RC 0x00000080 |
|
50 |
#define DPRINTF_DEBUG 0x80000000 |
#define DPRINTF_DEBUG 0x80000000 |
51 |
|
|
52 |
/* debug level for this library */ |
/* debug level for this library */ |
53 |
#ifdef _DEBUG |
#define DPRINTF_LEVEL 0 |
|
#define DPRINTF_LEVEL (DPRINTF_RC|0x0000000f) |
|
|
#else |
|
|
#define DPRINTF_LEVEL DPRINTF_RC |
|
|
#endif |
|
54 |
|
|
55 |
/* Buffer size for non C99 compliant compilers (msvc) */ |
/* Buffer size for non C99 compliant compilers (msvc) */ |
56 |
#define DPRINTF_BUF_SZ 1024 |
#define DPRINTF_BUF_SZ 1024 |
86 |
| Fallback when using gcc |
| Fallback when using gcc |
87 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
88 |
|
|
89 |
#elif defined(__GNUC__) || defined(__ICC) |
#elif defined(__GNUC__) |
90 |
|
|
91 |
# define int8_t char |
# define int8_t char |
92 |
# define uint8_t unsigned char |
# define uint8_t unsigned char |
109 |
* Some things that are only architecture dependant |
* Some things that are only architecture dependant |
110 |
****************************************************************************/ |
****************************************************************************/ |
111 |
|
|
112 |
#if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS) || defined(ARCH_SPARC) |
#if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS) |
113 |
# define CACHE_LINE 16 |
# define CACHE_LINE 16 |
114 |
# define ptr_t uint32_t |
# define ptr_t uint32_t |
115 |
#elif defined(ARCH_IA64) |
#elif defined(ARCH_IA64) || defined(ARCH_SPARC) |
116 |
# define CACHE_LINE 32 |
# define CACHE_LINE 32 |
117 |
# define ptr_t uint64_t |
# define ptr_t uint64_t |
118 |
#else |
#else |
119 |
/* todo: fix cache_line 0 operation */ |
# error Architecture not supported. |
|
# define CACHE_LINE 16 |
|
|
# define ptr_t uint32_t |
|
120 |
#endif |
#endif |
121 |
|
|
122 |
/***************************************************************************** |
/***************************************************************************** |
166 |
| msvc x86 specific macros/functions |
| msvc x86 specific macros/functions |
167 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
168 |
# if defined(ARCH_X86) |
# if defined(ARCH_X86) |
169 |
# define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax |
# define BSWAP(a) |
170 |
|
__asm { \ |
171 |
|
mov eax,a \ |
172 |
|
bswap eax \ |
173 |
|
mov a, eax \ |
174 |
|
} |
175 |
# define EMMS() __asm {emms} |
# define EMMS() __asm {emms} |
|
# define FEMMS() __asm {femms} |
|
176 |
|
|
177 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
178 |
{ |
{ |
191 |
| msvc unknown architecture |
| msvc unknown architecture |
192 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
193 |
# else |
# else |
194 |
/* ANSI C version of BSWAP */ |
# error Architecture not supported. |
|
#define BSWAP(x) \ |
|
|
x = ((((x) & 0xff000000) >> 24) | \ |
|
|
(((x) & 0x00ff0000) >> 8) | \ |
|
|
(((x) & 0x0000ff00) << 8) | \ |
|
|
(((x) & 0x000000ff) << 24)) |
|
|
|
|
|
#define EMMS() |
|
|
#define FEMMS() |
|
195 |
# endif |
# endif |
196 |
|
|
197 |
|
|
201 |
* GNU CC compiler stuff |
* GNU CC compiler stuff |
202 |
****************************************************************************/ |
****************************************************************************/ |
203 |
|
|
204 |
#elif defined(__GNUC__) || defined(__ICC) /* Compiler test */ |
#elif defined(__GNUC__) /* Compiler test */ |
205 |
|
|
206 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
207 |
| Common gcc stuff |
| Common gcc stuff |
227 |
# endif /* _DEBUG */ |
# endif /* _DEBUG */ |
228 |
|
|
229 |
|
|
230 |
|
# ifdef _DEBUG |
231 |
# define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
# define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
232 |
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
233 |
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)) |
234 |
|
# else |
235 |
|
# define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
236 |
|
__attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)] |
237 |
|
# endif |
238 |
|
|
239 |
/*---------------------------------------------------------------------------- |
/*---------------------------------------------------------------------------- |
240 |
| gcc x86 specific macros/functions |
| gcc x86 specific macros/functions |
242 |
# if defined(ARCH_X86) |
# if defined(ARCH_X86) |
243 |
# define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ); |
# define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ); |
244 |
# define EMMS() __asm__ ("emms\n\t"); |
# define EMMS() __asm__ ("emms\n\t"); |
|
# define FEMMS() __asm__ ("femms\n\t"); |
|
245 |
|
|
246 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
247 |
{ |
{ |
259 |
# define BSWAP(a) __asm__ __volatile__ \ |
# define BSWAP(a) __asm__ __volatile__ \ |
260 |
( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a)); |
( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a)); |
261 |
# define EMMS() |
# define EMMS() |
|
# define FEMMS() |
|
262 |
|
|
263 |
static __inline unsigned long get_tbl(void) |
static __inline unsigned long get_tbl(void) |
264 |
{ |
{ |
292 |
("mux1 %1 = %0, @rev" ";;" \ |
("mux1 %1 = %0, @rev" ";;" \ |
293 |
"shr.u %1 = %1, 32" : "=r" (a) : "r" (a)); |
"shr.u %1 = %1, 32" : "=r" (a) : "r" (a)); |
294 |
# define EMMS() |
# define EMMS() |
|
# define FEMMS() |
|
295 |
|
|
296 |
static __inline int64_t read_counter(void) { |
static __inline int64_t read_counter(void) { |
297 |
unsigned long result; |
unsigned long result; |
304 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
305 |
# elif defined(ARCH_SPARC) |
# elif defined(ARCH_SPARC) |
306 |
# define BSWAP(a) \ |
# define BSWAP(a) \ |
307 |
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | |
308 |
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
309 |
# define EMMS() |
# define EMMS() |
|
# define FEMMS() |
|
310 |
|
|
311 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
312 |
{ |
{ |
318 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
319 |
# elif defined(ARCH_MIPS) |
# elif defined(ARCH_MIPS) |
320 |
# define BSWAP(a) \ |
# define BSWAP(a) \ |
321 |
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | |
322 |
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
(((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
323 |
# define EMMS() |
# define EMMS() |
|
# define FEMMS() |
|
324 |
|
|
325 |
static __inline int64_t read_counter(void) |
static __inline int64_t read_counter(void) |
326 |
{ |
{ |
331 |
| XviD + gcc unsupported Architecture |
| XviD + gcc unsupported Architecture |
332 |
*---------------------------------------------------------------------------*/ |
*---------------------------------------------------------------------------*/ |
333 |
# else |
# else |
334 |
/* ANSI C version of BSWAP */ |
# error Architecture not supported. |
|
#define BSWAP(x) \ |
|
|
x = ((((x) & 0xff000000) >> 24) | \ |
|
|
(((x) & 0x00ff0000) >> 8) | \ |
|
|
(((x) & 0x0000ff00) << 8) | \ |
|
|
(((x) & 0x000000ff) << 24)) |
|
|
|
|
|
#define EMMS() |
|
|
#define FEMMS() |
|
335 |
# endif /* Architecture checking */ |
# endif /* Architecture checking */ |
336 |
|
|
337 |
/***************************************************************************** |
/***************************************************************************** |