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

Annotation of /xvidcore/src/portab.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.40 - (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.40 * $Id: portab.h,v 1.39 2002/11/26 23:50:57 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.28 /* Buffer size for non C99 compliant compilers (msvc) */
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 :     | Standard Unix include file (sorry, we put all unix into "linux" case)
88 :     *---------------------------------------------------------------------------*/
89 :    
90 :     #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)
91 :    
92 :     /* All (u)int(size)_t types are defined here */
93 :     # include <inttypes.h>
94 :    
95 :     /*----------------------------------------------------------------------------
96 :     | msvc (lacks such a header file)
97 :     *---------------------------------------------------------------------------*/
98 :    
99 :     #elif defined(_MSC_VER)
100 :     # define int8_t char
101 :     # define uint8_t unsigned char
102 :     # define int16_t short
103 :     # define uint16_t unsigned short
104 :     # define int32_t int
105 :     # define uint32_t unsigned int
106 :     # define int64_t __int64
107 :     # define uint64_t unsigned __int64
108 :    
109 :     /*----------------------------------------------------------------------------
110 :     | Fallback when using gcc
111 :     *---------------------------------------------------------------------------*/
112 :    
113 : chl 1.37 #elif defined(__GNUC__) || defined(__ICC)
114 : edgomez 1.28
115 :     # define int8_t char
116 :     # define uint8_t unsigned char
117 :     # define int16_t short
118 :     # define uint16_t unsigned short
119 :     # define int32_t int
120 :     # define uint32_t unsigned int
121 :     # define int64_t long long
122 :     # define uint64_t unsigned long long
123 :    
124 :     /*----------------------------------------------------------------------------
125 :     | Ok, we don't know how to define these types... error
126 :     *---------------------------------------------------------------------------*/
127 : suxen_drol 1.16
128 : h 1.2 #else
129 : edgomez 1.28 # error Do not know how to define (u)int(size)_t types
130 : h 1.2 #endif
131 : Isibaar 1.1
132 : edgomez 1.28 /*****************************************************************************
133 :     * Some things that are only architecture dependant
134 :     ****************************************************************************/
135 : Isibaar 1.1
136 : edgomez 1.32 #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS) || defined(ARCH_SPARC)
137 : edgomez 1.28 # define CACHE_LINE 16
138 :     # define ptr_t uint32_t
139 : edgomez 1.32 #elif defined(ARCH_IA64)
140 : edgomez 1.28 # define CACHE_LINE 32
141 :     # define ptr_t uint64_t
142 : suxen_drol 1.7 #else
143 : edgomez 1.38 /* todo: fix cache_line 0 operation */
144 :     # define CACHE_LINE 16
145 :     # define ptr_t uint32_t
146 : suxen_drol 1.7 #endif
147 : Isibaar 1.4
148 : edgomez 1.28 /*****************************************************************************
149 :     * Things that must be sorted by compiler and then by architecture
150 :     ****************************************************************************/
151 : Isibaar 1.1
152 : edgomez 1.28 /*****************************************************************************
153 :     * MSVC compiler specific macros, functions
154 :     ****************************************************************************/
155 : edgomez 1.18
156 : edgomez 1.28 #if defined(_MSC_VER)
157 : edgomez 1.18
158 : edgomez 1.28 /*----------------------------------------------------------------------------
159 :     | Common msvc stuff
160 :     *---------------------------------------------------------------------------*/
161 : Isibaar 1.1
162 : edgomez 1.28 #include <windows.h>
163 : suxen_drol 1.22 #include <stdio.h>
164 : suxen_drol 1.23
165 : edgomez 1.28 /*
166 :     * This function must be declared/defined all the time because MSVC does
167 :     * not support C99 variable arguments macros
168 :     */
169 :     static __inline void DPRINTF(int level, char *fmt, ...)
170 :     {
171 :     if (DPRINTF_LEVEL & level) {
172 :     va_list args;
173 :     char buf[DPRINTF_BUF_SZ];
174 :     va_start(args, fmt);
175 :     vsprintf(buf, fmt, args);
176 :     OutputDebugString(buf);
177 :     fprintf(stderr, "%s\n", buf);
178 :     }
179 :     }
180 :    
181 :     # if _MSC_VER <= 1200
182 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
183 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
184 :     type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
185 :     # else
186 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
187 :     __declspec(align(alignment)) type name[(sizex)*(sizey)]
188 :     # endif
189 :    
190 :    
191 :     /*----------------------------------------------------------------------------
192 :     | msvc x86 specific macros/functions
193 :     *---------------------------------------------------------------------------*/
194 :     # if defined(ARCH_X86)
195 : h 1.31 # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
196 : edgomez 1.28 # define EMMS() __asm {emms}
197 :    
198 :     static __inline int64_t read_counter(void)
199 :     {
200 :     int64_t ts;
201 :     uint32_t ts1, ts2;
202 :     __asm {
203 :     rdtsc
204 :     mov ts1, eax
205 :     mov ts2, edx
206 :     }
207 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
208 :     return ts;
209 :     }
210 :    
211 :     /*----------------------------------------------------------------------------
212 :     | msvc unknown architecture
213 :     *---------------------------------------------------------------------------*/
214 :     # else
215 : edgomez 1.39 /* ANSI C version of BSWAP */
216 : edgomez 1.38 #define BSWAP(x) \
217 :     x = ((((x) & 0xff000000) >> 24) | \
218 :     (((x) & 0x00ff0000) >> 8) | \
219 :     (((x) & 0x0000ff00) << 8) | \
220 :     (((x) & 0x000000ff) << 24))
221 :    
222 : edgomez 1.39 #define EMMS()
223 : edgomez 1.28 # endif
224 : suxen_drol 1.22
225 : chl 1.3
226 : Isibaar 1.1
227 :    
228 : edgomez 1.28 /*****************************************************************************
229 :     * GNU CC compiler stuff
230 :     ****************************************************************************/
231 : canard 1.8
232 : chl 1.37 #elif defined(__GNUC__) || defined(__ICC) /* Compiler test */
233 : Isibaar 1.1
234 : edgomez 1.28 /*----------------------------------------------------------------------------
235 :     | Common gcc stuff
236 :     *---------------------------------------------------------------------------*/
237 :    
238 :     /*
239 :     * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
240 :     * and it's a macro calling fprintf directly
241 :     */
242 :     # ifdef _DEBUG
243 :    
244 :     /* Needed for all debuf fprintf calls */
245 :     # include <stdio.h>
246 :    
247 :     # define DPRINTF(level, format, ...) \
248 :     do {\
249 :     if(DPRINTF_LEVEL & level)\
250 :     fprintf(stderr, format"\n", ##__VA_ARGS__);\
251 :     }while(0);
252 :    
253 :     # else /* _DEBUG */
254 :     # define DPRINTF(level, format, ...)
255 :     # endif /* _DEBUG */
256 :    
257 :    
258 : edgomez 1.29
259 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
260 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
261 :     type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))
262 : edgomez 1.28
263 :     /*----------------------------------------------------------------------------
264 :     | gcc x86 specific macros/functions
265 :     *---------------------------------------------------------------------------*/
266 :     # if defined(ARCH_X86)
267 :     # define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
268 :     # define EMMS() __asm__ ("emms\n\t");
269 :    
270 :     static __inline int64_t read_counter(void)
271 :     {
272 :     int64_t ts;
273 :     uint32_t ts1, ts2;
274 :     __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
275 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
276 :     return ts;
277 :     }
278 :    
279 :     /*----------------------------------------------------------------------------
280 :     | gcc PPC and PPC Altivec specific macros/functions
281 :     *---------------------------------------------------------------------------*/
282 :     # elif defined(ARCH_PPC)
283 :     # define BSWAP(a) __asm__ __volatile__ \
284 :     ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
285 :     # define EMMS()
286 :    
287 :     static __inline unsigned long get_tbl(void)
288 :     {
289 :     unsigned long tbl;
290 :     asm volatile ("mftb %0":"=r" (tbl));
291 :     return tbl;
292 :     }
293 :    
294 :     static __inline unsigned long get_tbu(void)
295 :     {
296 :     unsigned long tbl;
297 :     asm volatile ("mftbu %0":"=r" (tbl));
298 :     return tbl;
299 :     }
300 :    
301 :     static __inline int64_t read_counter(void)
302 :     {
303 :     unsigned long tb, tu;
304 :     do {
305 :     tu = get_tbu();
306 :     tb = get_tbl();
307 :     }while (tb != get_tbl());
308 :     return (((int64_t) tu) << 32) | (int64_t) tb;
309 :     }
310 :    
311 :     /*----------------------------------------------------------------------------
312 :     | gcc IA64 specific macros/functions
313 :     *---------------------------------------------------------------------------*/
314 :     # elif defined(ARCH_IA64)
315 :     # define BSWAP(a) __asm__ __volatile__ \
316 :     ("mux1 %1 = %0, @rev" ";;" \
317 :     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
318 :     # define EMMS()
319 :    
320 :     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 :    
326 :     /*----------------------------------------------------------------------------
327 :     | gcc SPARC specific macros/functions
328 :     *---------------------------------------------------------------------------*/
329 :     # elif defined(ARCH_SPARC)
330 :     # define BSWAP(a) \
331 : edgomez 1.30 ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
332 : edgomez 1.28 (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
333 :     # define EMMS()
334 :    
335 :     static __inline int64_t read_counter(void)
336 :     {
337 :     return 0;
338 :     }
339 :    
340 :     /*----------------------------------------------------------------------------
341 :     | gcc MIPS specific macros/functions
342 :     *---------------------------------------------------------------------------*/
343 :     # elif defined(ARCH_MIPS)
344 :     # define BSWAP(a) \
345 : edgomez 1.30 ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
346 : edgomez 1.28 (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
347 :     # define EMMS()
348 :    
349 :     static __inline int64_t read_counter(void)
350 :     {
351 :     return 0;
352 :     }
353 :    
354 :     /*----------------------------------------------------------------------------
355 :     | XviD + gcc unsupported Architecture
356 :     *---------------------------------------------------------------------------*/
357 :     # else
358 : edgomez 1.39 /* ANSI C version of BSWAP */
359 : edgomez 1.38 #define BSWAP(x) \
360 :     x = ((((x) & 0xff000000) >> 24) | \
361 :     (((x) & 0x00ff0000) >> 8) | \
362 :     (((x) & 0x0000ff00) << 8) | \
363 :     (((x) & 0x000000ff) << 24))
364 :    
365 : edgomez 1.39 #define EMMS()
366 : edgomez 1.28 # endif /* Architecture checking */
367 : edgomez 1.9
368 : edgomez 1.28 /*****************************************************************************
369 :     * Unknown compiler
370 :     ****************************************************************************/
371 :     #else /* Compiler test */
372 : Isibaar 1.21
373 : edgomez 1.28 # error Compiler not supported
374 : Isibaar 1.21
375 : edgomez 1.28 #endif /* Compiler test */
376 : Isibaar 1.21
377 : Isibaar 1.1
378 :     #endif

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