[cvs] / xvidcore / src / portab.h Repository:
ViewVC logotype

Annotation of /xvidcore/src/portab.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26.2.8 - (view) (download)

1 : suxen_drol 1.26.2.3 /*****************************************************************************
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 1.26.2.8 * $Id: portab.h,v 1.26.2.7 2003/01/26 05:09:00 suxen_drol Exp $
56 : suxen_drol 1.26.2.3 *
57 :     ****************************************************************************/
58 :    
59 : Isibaar 1.1 #ifndef _PORTAB_H_
60 :     #define _PORTAB_H_
61 :    
62 : suxen_drol 1.26.2.3 /*****************************************************************************
63 :     * Common things
64 :     ****************************************************************************/
65 : suxen_drol 1.23
66 : suxen_drol 1.26.2.3 /* 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 : suxen_drol 1.26.2.3 #define DPRINTF_RC 0x00000080
75 : suxen_drol 1.23 #define DPRINTF_DEBUG 0x80000000
76 :    
77 : suxen_drol 1.26.2.3 /* debug level for this library */
78 : suxen_drol 1.26.2.1 #ifdef _DEBUG
79 : chl 1.26.2.6 #define DPRINTF_LEVEL (DPRINTF_RC|0x0000007F)
80 : suxen_drol 1.26.2.1 #else
81 : suxen_drol 1.26.2.3 #define DPRINTF_LEVEL DPRINTF_RC
82 : suxen_drol 1.26.2.1 #endif
83 : suxen_drol 1.23
84 : suxen_drol 1.26.2.3 /* Buffer size for non C99 compliant compilers (msvc) */
85 : suxen_drol 1.23 #define DPRINTF_BUF_SZ 1024
86 :    
87 : suxen_drol 1.26.2.3 /*****************************************************************************
88 :     * Types used in XviD sources
89 :     ****************************************************************************/
90 :    
91 :     /*----------------------------------------------------------------------------
92 :     | Standard Unix include file (sorry, we put all unix into "linux" case)
93 :     *---------------------------------------------------------------------------*/
94 :    
95 :     #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)
96 :    
97 :     /* All (u)int(size)_t types are defined here */
98 :     # include <inttypes.h>
99 :    
100 :     /*----------------------------------------------------------------------------
101 :     | msvc (lacks such a header file)
102 :     *---------------------------------------------------------------------------*/
103 :    
104 : suxen_drol 1.26.2.8 #elif defined(_MSC_VER) || defined (__WATCOMC__)
105 : suxen_drol 1.26.2.3 # 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 :    
114 :     /*----------------------------------------------------------------------------
115 :     | Fallback when using gcc
116 :     *---------------------------------------------------------------------------*/
117 :    
118 :     #elif defined(__GNUC__) || defined(__ICC)
119 :    
120 :     # 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 :    
129 :     /*----------------------------------------------------------------------------
130 :     | Ok, we don't know how to define these types... error
131 :     *---------------------------------------------------------------------------*/
132 : suxen_drol 1.23
133 : h 1.2 #else
134 : suxen_drol 1.26.2.3 # error Do not know how to define (u)int(size)_t types
135 : h 1.2 #endif
136 : Isibaar 1.1
137 : suxen_drol 1.26.2.3 /*****************************************************************************
138 :     * Some things that are only architecture dependant
139 :     ****************************************************************************/
140 :    
141 :     #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 : suxen_drol 1.7 #else
148 : suxen_drol 1.26.2.3 /* todo: fix cache_line 0 operation */
149 :     # define CACHE_LINE 16
150 :     # define ptr_t uint32_t
151 : suxen_drol 1.7 #endif
152 : Isibaar 1.4
153 : suxen_drol 1.26.2.3 /*****************************************************************************
154 :     * Things that must be sorted by compiler and then by architecture
155 :     ****************************************************************************/
156 :    
157 :     /*****************************************************************************
158 :     * MSVC compiler specific macros, functions
159 :     ****************************************************************************/
160 :    
161 :     #if defined(_MSC_VER)
162 :    
163 :     /*----------------------------------------------------------------------------
164 :     | Common msvc stuff
165 :     *---------------------------------------------------------------------------*/
166 : chl 1.3
167 : suxen_drol 1.26.2.3 #include <windows.h>
168 : Isibaar 1.1 #include <stdio.h>
169 : suxen_drol 1.26.2.7
170 :     /* non-ansi function mapping */
171 :     # define snprintf _snprintf
172 :     # define vsnprintf _vsnprintf
173 : Isibaar 1.1
174 : suxen_drol 1.26.2.3 /*
175 :     * This function must be declared/defined all the time because MSVC does
176 :     * not support C99 variable arguments macros
177 :     */
178 :     static __inline void DPRINTF(int level, char *fmt, ...)
179 :     {
180 :     if (DPRINTF_LEVEL & level) {
181 :     va_list args;
182 :     char buf[DPRINTF_BUF_SZ];
183 :     va_start(args, fmt);
184 :     vsprintf(buf, fmt, args);
185 :     OutputDebugString(buf);
186 :     fprintf(stderr, "%s\n", buf);
187 :     }
188 :     }
189 :    
190 :     # if _MSC_VER <= 1200
191 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
192 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
193 :     type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
194 :     # else
195 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
196 :     __declspec(align(alignment)) type name[(sizex)*(sizey)]
197 :     # endif
198 :    
199 :    
200 :     /*----------------------------------------------------------------------------
201 :     | msvc x86 specific macros/functions
202 :     *---------------------------------------------------------------------------*/
203 :     # if defined(ARCH_X86)
204 :     # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
205 :    
206 :     static __inline int64_t read_counter(void)
207 :     {
208 :     int64_t ts;
209 :     uint32_t ts1, ts2;
210 :     __asm {
211 :     rdtsc
212 :     mov ts1, eax
213 :     mov ts2, edx
214 :     }
215 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
216 :     return ts;
217 :     }
218 :    
219 :     /*----------------------------------------------------------------------------
220 :     | msvc unknown architecture
221 :     *---------------------------------------------------------------------------*/
222 :     # else
223 :     /* ANSI C version of BSWAP */
224 :     #define BSWAP(x) \
225 :     x = ((((x) & 0xff000000) >> 24) | \
226 :     (((x) & 0x00ff0000) >> 8) | \
227 :     (((x) & 0x0000ff00) << 8) | \
228 :     (((x) & 0x000000ff) << 24))
229 : Isibaar 1.1
230 : suxen_drol 1.26.2.3 # endif
231 : edgomez 1.18
232 : Isibaar 1.21
233 :    
234 :    
235 : suxen_drol 1.26.2.3 /*****************************************************************************
236 :     * GNU CC compiler stuff
237 :     ****************************************************************************/
238 :    
239 :     #elif defined(__GNUC__) || defined(__ICC) /* Compiler test */
240 :    
241 :     /*----------------------------------------------------------------------------
242 :     | Common gcc stuff
243 :     *---------------------------------------------------------------------------*/
244 :    
245 :     /*
246 :     * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
247 :     * and it's a macro calling fprintf directly
248 :     */
249 :     # ifdef _DEBUG
250 :    
251 :     /* Needed for all debuf fprintf calls */
252 :     # include <stdio.h>
253 :    
254 :     # define DPRINTF(level, format, ...) \
255 :     do {\
256 :     if(DPRINTF_LEVEL & level)\
257 :     fprintf(stderr, format"\n", ##__VA_ARGS__);\
258 :     }while(0);
259 :    
260 :     # else /* _DEBUG */
261 :     # define DPRINTF(level, format, ...)
262 :     # endif /* _DEBUG */
263 :    
264 :    
265 :    
266 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
267 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
268 :     type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))
269 :    
270 :     /*----------------------------------------------------------------------------
271 :     | gcc x86 specific macros/functions
272 :     *---------------------------------------------------------------------------*/
273 :     # if defined(ARCH_X86)
274 :     # define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
275 :    
276 :     static __inline int64_t read_counter(void)
277 :     {
278 :     int64_t ts;
279 :     uint32_t ts1, ts2;
280 :     __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
281 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
282 :     return ts;
283 :     }
284 :    
285 :     /*----------------------------------------------------------------------------
286 :     | gcc PPC and PPC Altivec specific macros/functions
287 :     *---------------------------------------------------------------------------*/
288 :     # elif defined(ARCH_PPC)
289 :     # define BSWAP(a) __asm__ __volatile__ \
290 :     ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
291 :    
292 :     static __inline unsigned long get_tbl(void)
293 :     {
294 :     unsigned long tbl;
295 :     asm volatile ("mftb %0":"=r" (tbl));
296 :     return tbl;
297 :     }
298 :    
299 :     static __inline unsigned long get_tbu(void)
300 :     {
301 :     unsigned long tbl;
302 :     asm volatile ("mftbu %0":"=r" (tbl));
303 :     return tbl;
304 :     }
305 :    
306 :     static __inline int64_t read_counter(void)
307 :     {
308 :     unsigned long tb, tu;
309 :     do {
310 :     tu = get_tbu();
311 :     tb = get_tbl();
312 :     }while (tb != get_tbl());
313 :     return (((int64_t) tu) << 32) | (int64_t) tb;
314 :     }
315 :    
316 :     /*----------------------------------------------------------------------------
317 :     | gcc IA64 specific macros/functions
318 :     *---------------------------------------------------------------------------*/
319 :     # elif defined(ARCH_IA64)
320 :     # define BSWAP(a) __asm__ __volatile__ \
321 :     ("mux1 %1 = %0, @rev" ";;" \
322 :     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
323 :    
324 :     static __inline int64_t read_counter(void) {
325 :     unsigned long result;
326 :     __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
327 :     return result;
328 :     }
329 :    
330 :     /*----------------------------------------------------------------------------
331 :     | gcc SPARC specific macros/functions
332 :     *---------------------------------------------------------------------------*/
333 :     # elif defined(ARCH_SPARC)
334 :     # define BSWAP(a) \
335 :     ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
336 :     (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
337 :    
338 :     static __inline int64_t read_counter(void)
339 :     {
340 :     return 0;
341 :     }
342 :    
343 :     /*----------------------------------------------------------------------------
344 :     | gcc MIPS specific macros/functions
345 :     *---------------------------------------------------------------------------*/
346 :     # elif defined(ARCH_MIPS)
347 :     # define BSWAP(a) \
348 :     ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
349 :     (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
350 :    
351 :     static __inline int64_t read_counter(void)
352 :     {
353 :     return 0;
354 :     }
355 :    
356 :     /*----------------------------------------------------------------------------
357 :     | XviD + gcc unsupported Architecture
358 :     *---------------------------------------------------------------------------*/
359 :     # else
360 :     /* ANSI C version of BSWAP */
361 :     #define BSWAP(x) \
362 :     x = ((((x) & 0xff000000) >> 24) | \
363 :     (((x) & 0x00ff0000) >> 8) | \
364 :     (((x) & 0x0000ff00) << 8) | \
365 :     (((x) & 0x000000ff) << 24))
366 : Isibaar 1.21
367 : suxen_drol 1.26.2.3 # endif /* Architecture checking */
368 : Isibaar 1.21
369 : suxen_drol 1.26.2.8 /*****************************************************************************
370 :     * OPEN WATCOM C/C++ compiler
371 :     ****************************************************************************/
372 :     #elif defined(__WATCOMC__)
373 :    
374 :     # include <stdio.h>
375 :     # include <stdarg.h>
376 :    
377 :     static __inline void DPRINTF(int level, char *fmt, ...)
378 :     {
379 :     if (DPRINTF_LEVEL & level) {
380 :     va_list args;
381 :     char buf[DPRINTF_BUF_SZ];
382 :     va_start(args, fmt);
383 :     vsprintf(buf, fmt, args);
384 :     fprintf(stderr, "%s\n", buf);
385 :     }
386 :     }
387 :    
388 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
389 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
390 :     type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
391 :    
392 :     /*----------------------------------------------------------------------------
393 :     | watcom x86 specific macros/functions
394 :     *---------------------------------------------------------------------------*/
395 :     # if defined(ARCH_X86)
396 :    
397 :     # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
398 :    
399 :     static __inline int64_t read_counter(void)
400 :     {
401 :     int64_t ts;
402 :     uint32_t ts1, ts2;
403 :     __asm {
404 :     rdtsc
405 :     mov ts1, eax
406 :     mov ts2, edx
407 :     }
408 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
409 :     return ts;
410 :     }
411 :    
412 :     /*----------------------------------------------------------------------------
413 :     | watcom unsupported architecture
414 :     *---------------------------------------------------------------------------*/
415 :     # else
416 :    
417 :     # define BSWAP(x) \
418 :     x = ((((x) & 0xff000000) >> 24) | \
419 :     (((x) & 0x00ff0000) >> 8) | \
420 :     (((x) & 0x0000ff00) << 8) | \
421 :     (((x) & 0x000000ff) << 24))
422 :    
423 :     static int64_t read_counter() { return 0; }
424 :    
425 :     # endif
426 : suxen_drol 1.26.2.3 /*****************************************************************************
427 :     * Unknown compiler
428 :     ****************************************************************************/
429 :     #else /* Compiler test */
430 : suxen_drol 1.22
431 : suxen_drol 1.26.2.3 # error Compiler not supported
432 : suxen_drol 1.23
433 : suxen_drol 1.26.2.3 #endif /* Compiler test */
434 : Isibaar 1.1
435 :    
436 :     #endif

No admin address has been configured
ViewVC Help
Powered by ViewVC 1.0.4