Parent Directory | Revision Log
Revision 762 - (view) (download)
1 : | suxen_drol | 721 | /***************************************************************************** |
2 : | * | ||
3 : | * XVID MPEG-4 VIDEO CODEC | ||
4 : | * - Portable macros, types and inlined assembly - | ||
5 : | * | ||
6 : | * Copyright(C) 2002 Michael Militzer <isibaar@xvid.org> | ||
7 : | * 2002 Peter Ross <pross@xvid.org> | ||
8 : | * 2002 Edouard Gomez <ed.gomez@wanadoo.fr> | ||
9 : | * | ||
10 : | * 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 : | * (at your option) any later version. | ||
16 : | * | ||
17 : | * This program is distributed in the hope that it will be useful, | ||
18 : | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
19 : | * 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 : | * along with this program; if not, write to the Free Software | ||
24 : | * 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 | ||
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 : | suxen_drol | 762 | * $Id: portab.h,v 1.26.2.5 2003-01-05 03:31:26 suxen_drol Exp $ |
56 : | suxen_drol | 721 | * |
57 : | ****************************************************************************/ | ||
58 : | |||
59 : | Isibaar | 3 | #ifndef _PORTAB_H_ |
60 : | #define _PORTAB_H_ | ||
61 : | |||
62 : | suxen_drol | 721 | /***************************************************************************** |
63 : | * Common things | ||
64 : | ****************************************************************************/ | ||
65 : | suxen_drol | 252 | |
66 : | suxen_drol | 721 | /* Debug level masks */ |
67 : | suxen_drol | 252 | #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 : | suxen_drol | 721 | #define DPRINTF_RC 0x00000080 |
75 : | suxen_drol | 252 | #define DPRINTF_DEBUG 0x80000000 |
76 : | |||
77 : | suxen_drol | 721 | /* debug level for this library */ |
78 : | suxen_drol | 630 | #ifdef _DEBUG |
79 : | suxen_drol | 721 | #define DPRINTF_LEVEL (DPRINTF_RC|0x0000000f) |
80 : | suxen_drol | 630 | #else |
81 : | suxen_drol | 721 | #define DPRINTF_LEVEL DPRINTF_RC |
82 : | suxen_drol | 630 | #endif |
83 : | suxen_drol | 252 | |
84 : | suxen_drol | 721 | /* Buffer size for non C99 compliant compilers (msvc) */ |
85 : | suxen_drol | 252 | #define DPRINTF_BUF_SZ 1024 |
86 : | |||
87 : | suxen_drol | 721 | /***************************************************************************** |
88 : | * Types used in XviD sources | ||
89 : | ****************************************************************************/ | ||
90 : | suxen_drol | 252 | |
91 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
92 : | | Standard Unix include file (sorry, we put all unix into "linux" case) | ||
93 : | *---------------------------------------------------------------------------*/ | ||
94 : | Isibaar | 3 | |
95 : | suxen_drol | 721 | #if defined(LINUX) || defined(BEOS) || defined(FREEBSD) |
96 : | Isibaar | 3 | |
97 : | suxen_drol | 721 | /* All (u)int(size)_t types are defined here */ |
98 : | # include <inttypes.h> | ||
99 : | suxen_drol | 136 | |
100 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
101 : | | msvc (lacks such a header file) | ||
102 : | *---------------------------------------------------------------------------*/ | ||
103 : | suxen_drol | 136 | |
104 : | suxen_drol | 721 | #elif defined(_MSC_VER) |
105 : | # define int8_t char | ||
106 : | # define uint8_t unsigned char | ||
107 : | # define int16_t short | ||
108 : | # define uint16_t unsigned short | ||
109 : | # define int32_t int | ||
110 : | # define uint32_t unsigned int | ||
111 : | # define int64_t __int64 | ||
112 : | # define uint64_t unsigned __int64 | ||
113 : | suxen_drol | 136 | |
114 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
115 : | | Fallback when using gcc | ||
116 : | *---------------------------------------------------------------------------*/ | ||
117 : | h | 108 | |
118 : | suxen_drol | 721 | #elif defined(__GNUC__) || defined(__ICC) |
119 : | Isibaar | 3 | |
120 : | suxen_drol | 721 | # define int8_t char |
121 : | # define uint8_t unsigned char | ||
122 : | # define int16_t short | ||
123 : | # define uint16_t unsigned short | ||
124 : | # define int32_t int | ||
125 : | # define uint32_t unsigned int | ||
126 : | # define int64_t long long | ||
127 : | # define uint64_t unsigned long long | ||
128 : | Isibaar | 3 | |
129 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
130 : | | Ok, we don't know how to define these types... error | ||
131 : | *---------------------------------------------------------------------------*/ | ||
132 : | Isibaar | 3 | |
133 : | suxen_drol | 68 | #else |
134 : | suxen_drol | 721 | # error Do not know how to define (u)int(size)_t types |
135 : | suxen_drol | 68 | #endif |
136 : | Isibaar | 42 | |
137 : | suxen_drol | 721 | /***************************************************************************** |
138 : | * Some things that are only architecture dependant | ||
139 : | ****************************************************************************/ | ||
140 : | Isibaar | 3 | |
141 : | suxen_drol | 721 | #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS) || defined(ARCH_SPARC) |
142 : | # define CACHE_LINE 16 | ||
143 : | # define ptr_t uint32_t | ||
144 : | #elif defined(ARCH_IA64) | ||
145 : | # define CACHE_LINE 32 | ||
146 : | # define ptr_t uint64_t | ||
147 : | chl | 37 | #else |
148 : | suxen_drol | 721 | /* todo: fix cache_line 0 operation */ |
149 : | # define CACHE_LINE 16 | ||
150 : | # define ptr_t uint32_t | ||
151 : | chl | 37 | #endif |
152 : | Isibaar | 3 | |
153 : | suxen_drol | 721 | /***************************************************************************** |
154 : | * Things that must be sorted by compiler and then by architecture | ||
155 : | ****************************************************************************/ | ||
156 : | Isibaar | 3 | |
157 : | suxen_drol | 721 | /***************************************************************************** |
158 : | * MSVC compiler specific macros, functions | ||
159 : | ****************************************************************************/ | ||
160 : | Isibaar | 3 | |
161 : | suxen_drol | 721 | #if defined(_MSC_VER) |
162 : | canard | 73 | |
163 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
164 : | | Common msvc stuff | ||
165 : | *---------------------------------------------------------------------------*/ | ||
166 : | Isibaar | 3 | |
167 : | suxen_drol | 721 | #include <windows.h> |
168 : | #include <stdio.h> | ||
169 : | edgomez | 78 | |
170 : | suxen_drol | 721 | /* |
171 : | * This function must be declared/defined all the time because MSVC does | ||
172 : | * not support C99 variable arguments macros | ||
173 : | */ | ||
174 : | static __inline void DPRINTF(int level, char *fmt, ...) | ||
175 : | { | ||
176 : | if (DPRINTF_LEVEL & level) { | ||
177 : | va_list args; | ||
178 : | char buf[DPRINTF_BUF_SZ]; | ||
179 : | va_start(args, fmt); | ||
180 : | vsprintf(buf, fmt, args); | ||
181 : | OutputDebugString(buf); | ||
182 : | fprintf(stderr, "%s\n", buf); | ||
183 : | } | ||
184 : | } | ||
185 : | Isibaar | 3 | |
186 : | suxen_drol | 721 | # if _MSC_VER <= 1200 |
187 : | # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ | ||
188 : | type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ | ||
189 : | type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1)) | ||
190 : | # else | ||
191 : | # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ | ||
192 : | __declspec(align(alignment)) type name[(sizex)*(sizey)] | ||
193 : | # endif | ||
194 : | Isibaar | 3 | |
195 : | |||
196 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
197 : | | msvc x86 specific macros/functions | ||
198 : | *---------------------------------------------------------------------------*/ | ||
199 : | # if defined(ARCH_X86) | ||
200 : | # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax | ||
201 : | canard | 89 | |
202 : | suxen_drol | 721 | static __inline int64_t read_counter(void) |
203 : | { | ||
204 : | int64_t ts; | ||
205 : | uint32_t ts1, ts2; | ||
206 : | __asm { | ||
207 : | rdtsc | ||
208 : | mov ts1, eax | ||
209 : | mov ts2, edx | ||
210 : | } | ||
211 : | ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); | ||
212 : | return ts; | ||
213 : | } | ||
214 : | edgomez | 195 | |
215 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
216 : | | msvc unknown architecture | ||
217 : | *---------------------------------------------------------------------------*/ | ||
218 : | # else | ||
219 : | /* ANSI C version of BSWAP */ | ||
220 : | #define BSWAP(x) \ | ||
221 : | x = ((((x) & 0xff000000) >> 24) | \ | ||
222 : | (((x) & 0x00ff0000) >> 8) | \ | ||
223 : | (((x) & 0x0000ff00) << 8) | \ | ||
224 : | (((x) & 0x000000ff) << 24)) | ||
225 : | edgomez | 195 | |
226 : | suxen_drol | 721 | # endif |
227 : | Isibaar | 209 | |
228 : | ia64p | 283 | |
229 : | Isibaar | 209 | |
230 : | ia64p | 280 | |
231 : | suxen_drol | 721 | /***************************************************************************** |
232 : | * GNU CC compiler stuff | ||
233 : | ****************************************************************************/ | ||
234 : | ia64p | 280 | |
235 : | suxen_drol | 721 | #elif defined(__GNUC__) || defined(__ICC) /* Compiler test */ |
236 : | Isibaar | 209 | |
237 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
238 : | | Common gcc stuff | ||
239 : | *---------------------------------------------------------------------------*/ | ||
240 : | ia64p | 283 | |
241 : | suxen_drol | 721 | /* |
242 : | * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed | ||
243 : | * and it's a macro calling fprintf directly | ||
244 : | */ | ||
245 : | # ifdef _DEBUG | ||
246 : | ia64p | 283 | |
247 : | suxen_drol | 721 | /* Needed for all debuf fprintf calls */ |
248 : | # include <stdio.h> | ||
249 : | ia64p | 283 | |
250 : | suxen_drol | 721 | # define DPRINTF(level, format, ...) \ |
251 : | do {\ | ||
252 : | if(DPRINTF_LEVEL & level)\ | ||
253 : | fprintf(stderr, format"\n", ##__VA_ARGS__);\ | ||
254 : | }while(0); | ||
255 : | ia64p | 283 | |
256 : | suxen_drol | 721 | # else /* _DEBUG */ |
257 : | # define DPRINTF(level, format, ...) | ||
258 : | # endif /* _DEBUG */ | ||
259 : | ia64p | 283 | |
260 : | |||
261 : | |||
262 : | suxen_drol | 721 | # 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 : | ia64p | 283 | |
266 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
267 : | | gcc x86 specific macros/functions | ||
268 : | *---------------------------------------------------------------------------*/ | ||
269 : | # if defined(ARCH_X86) | ||
270 : | # define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ); | ||
271 : | ia64p | 283 | |
272 : | suxen_drol | 721 | static __inline int64_t read_counter(void) |
273 : | { | ||
274 : | int64_t ts; | ||
275 : | uint32_t ts1, ts2; | ||
276 : | __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2)); | ||
277 : | ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); | ||
278 : | return ts; | ||
279 : | } | ||
280 : | Isibaar | 3 | |
281 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
282 : | | gcc PPC and PPC Altivec specific macros/functions | ||
283 : | *---------------------------------------------------------------------------*/ | ||
284 : | # elif defined(ARCH_PPC) | ||
285 : | # define BSWAP(a) __asm__ __volatile__ \ | ||
286 : | ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a)); | ||
287 : | edgomez | 78 | |
288 : | suxen_drol | 721 | static __inline unsigned long get_tbl(void) |
289 : | { | ||
290 : | unsigned long tbl; | ||
291 : | asm volatile ("mftb %0":"=r" (tbl)); | ||
292 : | return tbl; | ||
293 : | } | ||
294 : | Isibaar | 3 | |
295 : | suxen_drol | 721 | static __inline unsigned long get_tbu(void) |
296 : | { | ||
297 : | unsigned long tbl; | ||
298 : | asm volatile ("mftbu %0":"=r" (tbl)); | ||
299 : | return tbl; | ||
300 : | } | ||
301 : | Isibaar | 3 | |
302 : | suxen_drol | 721 | static __inline int64_t read_counter(void) |
303 : | { | ||
304 : | unsigned long tb, tu; | ||
305 : | do { | ||
306 : | tu = get_tbu(); | ||
307 : | tb = get_tbl(); | ||
308 : | }while (tb != get_tbl()); | ||
309 : | return (((int64_t) tu) << 32) | (int64_t) tb; | ||
310 : | } | ||
311 : | Isibaar | 3 | |
312 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
313 : | | gcc IA64 specific macros/functions | ||
314 : | *---------------------------------------------------------------------------*/ | ||
315 : | # elif defined(ARCH_IA64) | ||
316 : | # define BSWAP(a) __asm__ __volatile__ \ | ||
317 : | ("mux1 %1 = %0, @rev" ";;" \ | ||
318 : | "shr.u %1 = %1, 32" : "=r" (a) : "r" (a)); | ||
319 : | Isibaar | 3 | |
320 : | suxen_drol | 721 | static __inline int64_t read_counter(void) { |
321 : | unsigned long result; | ||
322 : | __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); | ||
323 : | return result; | ||
324 : | } | ||
325 : | Isibaar | 209 | |
326 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
327 : | | gcc SPARC specific macros/functions | ||
328 : | *---------------------------------------------------------------------------*/ | ||
329 : | # elif defined(ARCH_SPARC) | ||
330 : | # define BSWAP(a) \ | ||
331 : | ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ | ||
332 : | (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) | ||
333 : | Isibaar | 209 | |
334 : | suxen_drol | 721 | static __inline int64_t read_counter(void) |
335 : | { | ||
336 : | return 0; | ||
337 : | } | ||
338 : | edgomez | 78 | |
339 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
340 : | | gcc MIPS specific macros/functions | ||
341 : | *---------------------------------------------------------------------------*/ | ||
342 : | # elif defined(ARCH_MIPS) | ||
343 : | # define BSWAP(a) \ | ||
344 : | ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \ | ||
345 : | (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff)) | ||
346 : | Isibaar | 3 | |
347 : | suxen_drol | 721 | static __inline int64_t read_counter(void) |
348 : | { | ||
349 : | return 0; | ||
350 : | } | ||
351 : | suxen_drol | 229 | |
352 : | suxen_drol | 721 | /*---------------------------------------------------------------------------- |
353 : | | XviD + gcc unsupported Architecture | ||
354 : | *---------------------------------------------------------------------------*/ | ||
355 : | # else | ||
356 : | /* ANSI C version of BSWAP */ | ||
357 : | #define BSWAP(x) \ | ||
358 : | x = ((((x) & 0xff000000) >> 24) | \ | ||
359 : | (((x) & 0x00ff0000) >> 8) | \ | ||
360 : | (((x) & 0x0000ff00) << 8) | \ | ||
361 : | (((x) & 0x000000ff) << 24)) | ||
362 : | suxen_drol | 252 | |
363 : | suxen_drol | 721 | # endif /* Architecture checking */ |
364 : | Isibaar | 3 | |
365 : | suxen_drol | 721 | /***************************************************************************** |
366 : | * Unknown compiler | ||
367 : | ****************************************************************************/ | ||
368 : | #else /* Compiler test */ | ||
369 : | Isibaar | 3 | |
370 : | suxen_drol | 721 | # error Compiler not supported |
371 : | Isibaar | 3 | |
372 : | suxen_drol | 721 | #endif /* Compiler test */ |
373 : | Isibaar | 209 | |
374 : | Isibaar | 42 | |
375 : | Isibaar | 3 | #endif |
No admin address has been configured | ViewVC Help |
Powered by ViewVC 1.0.4 |