Parent Directory
|
Revision Log
Revision 1.42 - (view) (download)
1 : | edgomez | 1.27 | /***************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * - Portable macros, types and inlined assembly - | ||
5 : | * | ||
6 : | edgomez | 1.33 | * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org> |
7 : | edgomez | 1.34 | * 2002 Peter Ross <pross@xvid.org> |
8 : | edgomez | 1.40 | * 2002 Edouard Gomez <ed.gomez@free.fr> |
9 : | edgomez | 1.27 | * |
10 : | edgomez | 1.35 | * This file is part of XviD, a free MPEG-4 video encoder/decoder |
11 : | * | ||
12 : | * 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 | 1.27 | * (at your option) any later version. |
16 : | * | ||
17 : | * This program is distributed in the hope that it will be useful, | ||
18 : | edgomez | 1.35 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 : | edgomez | 1.27 | * 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 | 1.35 | * along with this program; if not, write to the Free Software |
24 : | edgomez | 1.27 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
25 : | * | ||
26 : | edgomez | 1.35 | * 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 : | edgomez | 1.42 | * $Id: portab.h,v 1.41 2003/02/09 19:32:52 edgomez Exp $ |
56 : | edgomez | 1.27 | * |
57 : | ****************************************************************************/ | ||
58 : | |||
59 : | Isibaar | 1.1 | #ifndef _PORTAB_H_ |
60 : | #define _PORTAB_H_ | ||
61 : | |||
62 : | edgomez | 1.28 | /***************************************************************************** |
63 : | * Common things | ||
64 : | ****************************************************************************/ | ||
65 : | suxen_drol | 1.23 | |
66 : | edgomez | 1.28 | /* Debug level masks */ |
67 : | suxen_drol | 1.23 | #define DPRINTF_ERROR 0x00000001 |
68 : | #define DPRINTF_STARTCODE 0x00000002 | ||
69 : | #define DPRINTF_HEADER 0x00000004 | ||
70 : | #define DPRINTF_TIMECODE 0x00000008 | ||
71 : | #define DPRINTF_MB 0x00000010 | ||
72 : | #define DPRINTF_COEFF 0x00000020 | ||
73 : | #define DPRINTF_MV 0x00000040 | ||
74 : | #define DPRINTF_DEBUG 0x80000000 | ||
75 : | |||
76 : | edgomez | 1.28 | /* debug level for this library */ |
77 : | suxen_drol | 1.23 | #define DPRINTF_LEVEL 0 |
78 : | |||
79 : | edgomez | 1.42 | /* Buffer size for msvc implementation because it outputs to DebugOutput */ |
80 : | suxen_drol | 1.23 | #define DPRINTF_BUF_SZ 1024 |
81 : | |||
82 : | edgomez | 1.28 | /***************************************************************************** |
83 : | * Types used in XviD sources | ||
84 : | ****************************************************************************/ | ||
85 : | suxen_drol | 1.23 | |
86 : | edgomez | 1.28 | /*---------------------------------------------------------------------------- |
87 : | edgomez | 1.41 | | For MSVC |
88 : | edgomez | 1.28 | *---------------------------------------------------------------------------*/ |
89 : | |||
90 : | edgomez | 1.41 | #if defined(_MSC_VER) |
91 : | edgomez | 1.28 | # define int8_t char |
92 : | # define uint8_t unsigned char | ||
93 : | # define int16_t short | ||
94 : | # define uint16_t unsigned short | ||
95 : | # define int32_t int | ||
96 : | # define uint32_t unsigned int | ||
97 : | # define int64_t __int64 | ||
98 : | # define uint64_t unsigned __int64 | ||
99 : | |||
100 : | /*---------------------------------------------------------------------------- | ||
101 : | edgomez | 1.42 | | For all other compilers, use the standard header file |
102 : | | (compiler should be ISO C99 compatible, perhaps ISO C89 is enough) | ||
103 : | edgomez | 1.28 | *---------------------------------------------------------------------------*/ |
104 : | |||
105 : | edgomez | 1.42 | #else |
106 : | edgomez | 1.28 | |
107 : | edgomez | 1.42 | # include <inttypes.h> |
108 : | suxen_drol | 1.16 | |
109 : | h | 1.2 | #endif |
110 : | Isibaar | 1.1 | |
111 : | edgomez | 1.28 | /***************************************************************************** |
112 : | * Some things that are only architecture dependant | ||
113 : | ****************************************************************************/ | ||
114 : | Isibaar | 1.1 | |
115 : | edgomez | 1.41 | #if defined(ARCH_IS_32BIT) |
116 : | edgomez | 1.28 | # define CACHE_LINE 16 |
117 : | # define ptr_t uint32_t | ||
118 : | edgomez | 1.41 | #elif defined(ARCH_IS_64BIT) |
119 : | edgomez | 1.28 | # define CACHE_LINE 32 |
120 : | # define ptr_t uint64_t | ||
121 : | suxen_drol | 1.7 | #else |
122 : | edgomez | 1.41 | # error You are trying to compile XviD without defining address bus size. |
123 : | suxen_drol | 1.7 | #endif |
124 : | Isibaar | 1.4 | |
125 : | edgomez | 1.28 | /***************************************************************************** |
126 : | * Things that must be sorted by compiler and then by architecture | ||
127 : | ****************************************************************************/ | ||
128 : | Isibaar | 1.1 | |
129 : | edgomez | 1.28 | /***************************************************************************** |
130 : | * MSVC compiler specific macros, functions | ||
131 : | ****************************************************************************/ | ||
132 : | edgomez | 1.18 | |
133 : | edgomez | 1.28 | #if defined(_MSC_VER) |
134 : | edgomez | 1.18 | |
135 : | edgomez | 1.28 | /*---------------------------------------------------------------------------- |
136 : | | Common msvc stuff | ||
137 : | *---------------------------------------------------------------------------*/ | ||
138 : | Isibaar | 1.1 | |
139 : | edgomez | 1.28 | #include <windows.h> |
140 : | suxen_drol | 1.22 | #include <stdio.h> |
141 : | suxen_drol | 1.23 | |
142 : | edgomez | 1.28 | /* |
143 : | * This function must be declared/defined all the time because MSVC does | ||
144 : | edgomez | 1.41 | * not support C99 variable arguments macros. |
145 : | * | ||
146 : | * Btw, if the MS compiler does its job well, it should remove the nop | ||
147 : | * DPRINTF function when not compiling in _DEBUG mode | ||
148 : | edgomez | 1.28 | */ |
149 : | edgomez | 1.41 | # ifdef _DEBUG |
150 : | edgomez | 1.28 | static __inline void DPRINTF(int level, char *fmt, ...) |
151 : | { | ||
152 : | if (DPRINTF_LEVEL & level) { | ||
153 : | va_list args; | ||
154 : | char buf[DPRINTF_BUF_SZ]; | ||
155 : | va_start(args, fmt); | ||
156 : | vsprintf(buf, fmt, args); | ||
157 : | OutputDebugString(buf); | ||
158 : | fprintf(stderr, "%s\n", buf); | ||
159 : | } | ||
160 : | } | ||
161 : | edgomez | 1.41 | # else |
162 : | static __inline void DPRINTF(int level, char *fmt, ...) | ||
163 : | { | ||
164 : | } | ||
165 : | # endif | ||
166 : | edgomez | 1.28 | |
167 : | # if _MSC_VER <= 1200 | ||
168 : | # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ | ||
169 : | type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ | ||
170 : | type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1)) | ||
171 : | # else | ||
172 : | # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ | ||
173 : | __declspec(align(alignment)) type name[(sizex)*(sizey)] | ||
174 : | # endif | ||
175 : | |||
176 : | |||
177 : | /*---------------------------------------------------------------------------- | ||
178 : | | msvc x86 specific macros/functions | ||
179 : | *---------------------------------------------------------------------------*/ | ||
180 : | edgomez | 1.41 | # if defined(ARCH_IS_IA32) |
181 : | h | 1.31 | # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax |
182 : | edgomez | 1.28 | # define EMMS() __asm {emms} |
183 : | |||
184 : | edgomez | 1.41 | # ifdef _PROFILING_ |
185 : | edgomez | 1.28 | static __inline int64_t read_counter(void) |
186 : | { | ||
187 : | int64_t ts; | ||
188 : | uint32_t ts1, ts2; | ||
189 : | __asm { | ||
190 : | rdtsc | ||
191 : | mov ts1, eax | ||
192 : | mov ts2, edx | ||
193 : | } | ||
194 : | ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); | ||
195 : | return ts; | ||
196 : | } | ||
197 : | edgomez | 1.41 | # endif |
198 : | edgomez | 1.28 | |
199 : | /*---------------------------------------------------------------------------- | ||
200 : | edgomez | 1.41 | | msvc GENERIC (plain C only) - Probably alpha or some embedded device |
201 : | *---------------------------------------------------------------------------*/ | ||
202 : | # elif defined(ARCH_IS_GENERIC) | ||
203 : | # define BSWAP(a) \ | ||
204 : | ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ | ||
205 : | (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) | ||
206 : | # define EMMS() | ||
207 : | |||
208 : | # ifdef _PROFILING_ | ||
209 : | # include <time.h> | ||
210 : | static __inline int64_t read_counter(void) | ||
211 : | { | ||
212 : | return (int64_t)clock(); | ||
213 : | } | ||
214 : | # endif | ||
215 : | |||
216 : | /*---------------------------------------------------------------------------- | ||
217 : | | msvc Not given architecture - This is probably an user who tries to build | ||
218 : | | XviD the wrong way. | ||
219 : | edgomez | 1.28 | *---------------------------------------------------------------------------*/ |
220 : | # else | ||
221 : | edgomez | 1.41 | # error You are trying to compile XviD without defining the architecture type. |
222 : | edgomez | 1.28 | # endif |
223 : | suxen_drol | 1.22 | |
224 : | chl | 1.3 | |
225 : | Isibaar | 1.1 | |
226 : | |||
227 : | edgomez | 1.28 | /***************************************************************************** |
228 : | * GNU CC compiler stuff | ||
229 : | ****************************************************************************/ | ||
230 : | canard | 1.8 | |
231 : | chl | 1.37 | #elif defined(__GNUC__) || defined(__ICC) /* Compiler test */ |
232 : | Isibaar | 1.1 | |
233 : | edgomez | 1.28 | /*---------------------------------------------------------------------------- |
234 : | | Common gcc stuff | ||
235 : | *---------------------------------------------------------------------------*/ | ||
236 : | |||
237 : | /* | ||
238 : | * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed | ||
239 : | * and it's a macro calling fprintf directly | ||
240 : | */ | ||
241 : | # ifdef _DEBUG | ||
242 : | |||
243 : | /* Needed for all debuf fprintf calls */ | ||
244 : | # include <stdio.h> | ||
245 : | edgomez | 1.41 | # include <stdarg.h> |
246 : | edgomez | 1.28 | |
247 : | edgomez | 1.41 | static __inline void DPRINTF(int level, char *format, ...) |
248 : | { | ||
249 : | va_list args; | ||
250 : | va_start(args, format); | ||
251 : | if(DPRINTF_LEVEL & level) { | ||
252 : | vfprintf(stderr, format, args); | ||
253 : | edgomez | 1.42 | fprintf(stderr, "\n"); |
254 : | edgomez | 1.41 | } |
255 : | } | ||
256 : | edgomez | 1.28 | |
257 : | # else /* _DEBUG */ | ||
258 : | edgomez | 1.41 | static __inline void DPRINTF(int level, char *format, ...) {} |
259 : | edgomez | 1.28 | # endif /* _DEBUG */ |
260 : | |||
261 : | |||
262 : | edgomez | 1.29 | # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
263 : | type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ | ||
264 : | type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1)) | ||
265 : | edgomez | 1.28 | |
266 : | /*---------------------------------------------------------------------------- | ||
267 : | edgomez | 1.41 | | gcc IA32 specific macros/functions |
268 : | edgomez | 1.28 | *---------------------------------------------------------------------------*/ |
269 : | edgomez | 1.41 | # if defined(ARCH_IS_IA32) |
270 : | edgomez | 1.28 | # define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ); |
271 : | # define EMMS() __asm__ ("emms\n\t"); | ||
272 : | |||
273 : | edgomez | 1.41 | # ifdef _PROFILING_ |
274 : | static __inline int64_t read_counter(void) | ||
275 : | { | ||
276 : | int64_t ts; | ||
277 : | uint32_t ts1, ts2; | ||
278 : | __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2)); | ||
279 : | ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); | ||
280 : | return ts; | ||
281 : | } | ||
282 : | # endif | ||
283 : | edgomez | 1.28 | |
284 : | /*---------------------------------------------------------------------------- | ||
285 : | | gcc PPC and PPC Altivec specific macros/functions | ||
286 : | *---------------------------------------------------------------------------*/ | ||
287 : | edgomez | 1.41 | # elif defined(ARCH_IS_PPC) |
288 : | edgomez | 1.28 | # define BSWAP(a) __asm__ __volatile__ \ |
289 : | ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a)); | ||
290 : | # define EMMS() | ||
291 : | |||
292 : | edgomez | 1.41 | # ifdef _PROFILING_ |
293 : | static __inline unsigned long get_tbl(void) | ||
294 : | { | ||
295 : | unsigned long tbl; | ||
296 : | asm volatile ("mftb %0":"=r" (tbl)); | ||
297 : | return tbl; | ||
298 : | } | ||
299 : | edgomez | 1.28 | |
300 : | edgomez | 1.41 | static __inline unsigned long get_tbu(void) |
301 : | { | ||
302 : | unsigned long tbl; | ||
303 : | asm volatile ("mftbu %0":"=r" (tbl)); | ||
304 : | return tbl; | ||
305 : | } | ||
306 : | edgomez | 1.28 | |
307 : | edgomez | 1.41 | static __inline int64_t read_counter(void) |
308 : | { | ||
309 : | unsigned long tb, tu; | ||
310 : | do { | ||
311 : | tu = get_tbu(); | ||
312 : | tb = get_tbl(); | ||
313 : | }while (tb != get_tbl()); | ||
314 : | return (((int64_t) tu) << 32) | (int64_t) tb; | ||
315 : | } | ||
316 : | # endif | ||
317 : | edgomez | 1.28 | |
318 : | /*---------------------------------------------------------------------------- | ||
319 : | | gcc IA64 specific macros/functions | ||
320 : | *---------------------------------------------------------------------------*/ | ||
321 : | edgomez | 1.41 | # elif defined(ARCH_IS_IA64) |
322 : | edgomez | 1.28 | # define BSWAP(a) __asm__ __volatile__ \ |
323 : | ("mux1 %1 = %0, @rev" ";;" \ | ||
324 : | "shr.u %1 = %1, 32" : "=r" (a) : "r" (a)); | ||
325 : | # define EMMS() | ||
326 : | |||
327 : | edgomez | 1.41 | # ifdef _PROFILING_ |
328 : | static __inline int64_t read_counter(void) | ||
329 : | { | ||
330 : | unsigned long result; | ||
331 : | __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); | ||
332 : | return result; | ||
333 : | } | ||
334 : | # endif | ||
335 : | edgomez | 1.28 | |
336 : | /*---------------------------------------------------------------------------- | ||
337 : | edgomez | 1.41 | | gcc GENERIC (plain C only) specific macros/functions |
338 : | edgomez | 1.28 | *---------------------------------------------------------------------------*/ |
339 : | edgomez | 1.41 | # elif defined(ARCH_IS_GENERIC) |
340 : | edgomez | 1.28 | # define BSWAP(a) \ |
341 : | edgomez | 1.30 | ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ |
342 : | edgomez | 1.28 | (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) |
343 : | # define EMMS() | ||
344 : | |||
345 : | edgomez | 1.41 | # ifdef _PROFILING_ |
346 : | # include <time.h> | ||
347 : | static __inline int64_t read_counter(void) | ||
348 : | { | ||
349 : | return (int64_t)clock(); | ||
350 : | } | ||
351 : | # endif | ||
352 : | edgomez | 1.28 | |
353 : | /*---------------------------------------------------------------------------- | ||
354 : | edgomez | 1.41 | | gcc Not given architecture - This is probably an user who tries to build |
355 : | | XviD the wrong way. | ||
356 : | edgomez | 1.28 | *---------------------------------------------------------------------------*/ |
357 : | # else | ||
358 : | edgomez | 1.41 | # error You are trying to compile XviD without defining the architecture type. |
359 : | # endif | ||
360 : | edgomez | 1.9 | |
361 : | edgomez | 1.28 | /***************************************************************************** |
362 : | * Unknown compiler | ||
363 : | ****************************************************************************/ | ||
364 : | #else /* Compiler test */ | ||
365 : | Isibaar | 1.21 | |
366 : | edgomez | 1.42 | /* |
367 : | * Ok we know nothing about the compiler, so we fallback to ANSI C | ||
368 : | * features, so every compiler should be happy and compile the code. | ||
369 : | * | ||
370 : | * This is (mostly) equivalent to ARCH_IS_GENERIC. | ||
371 : | */ | ||
372 : | |||
373 : | # ifdef _DEBUG | ||
374 : | |||
375 : | /* Needed for all debuf fprintf calls */ | ||
376 : | # include <stdio.h> | ||
377 : | # include <stdarg.h> | ||
378 : | |||
379 : | static __inline void DPRINTF(int level, char *format, ...) | ||
380 : | { | ||
381 : | va_list args; | ||
382 : | va_start(args, format); | ||
383 : | if(DPRINTF_LEVEL & level) { | ||
384 : | vfprintf(stderr, format, args); | ||
385 : | fprintf(stderr, "\n"); | ||
386 : | } | ||
387 : | } | ||
388 : | |||
389 : | # else /* _DEBUG */ | ||
390 : | static __inline void DPRINTF(int level, char *format, ...) {} | ||
391 : | # endif /* _DEBUG */ | ||
392 : | |||
393 : | # define BSWAP(a) \ | ||
394 : | ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ | ||
395 : | (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) | ||
396 : | |||
397 : | # define EMMS() | ||
398 : | |||
399 : | # ifdef _PROFILING_ | ||
400 : | # include <time.h> | ||
401 : | static __inline int64_t read_counter(void) | ||
402 : | { | ||
403 : | return (int64_t)clock(); | ||
404 : | } | ||
405 : | # endif | ||
406 : | |||
407 : | # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ | ||
408 : | type name[(sizex)*(sizey)] | ||
409 : | Isibaar | 1.21 | |
410 : | edgomez | 1.28 | #endif /* Compiler test */ |
411 : | Isibaar | 1.21 | |
412 : | Isibaar | 1.1 | |
413 : | #endif |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |