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

Annotation of /trunk/xvidcore/src/portab.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 648 - (view) (download)

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

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