[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 605 - (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 :     * This program is an implementation of a part of one or more MPEG-4
11 :     * Video tools as specified in ISO/IEC 14496-2 standard. Those intending
12 :     * to use this software module in hardware or software products are
13 :     * advised that its use may infringe existing patents or copyrights, and
14 :     * any such use would be at such party's own risk. The original
15 :     * developer of this software module and his/her company, and subsequent
16 :     * editors and their companies, will have no liability for use of this
17 :     * software or modifications or derivatives thereof.
18 :     *
19 :     * This program is free software ; you can redistribute it and/or modify
20 :     * it under the terms of the GNU General Public License as published by
21 :     * the Free Software Foundation ; either version 2 of the License, or
22 :     * (at your option) any later version.
23 :     *
24 :     * This program is distributed in the hope that it will be useful,
25 :     * but WITHOUT ANY WARRANTY ; without even the implied warranty of
26 :     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 :     * GNU General Public License for more details.
28 :     *
29 :     * You should have received a copy of the GNU General Public License
30 :     * along with this program ; if not, write to the Free Software
31 :     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32 :     *
33 : edgomez 605 * $Id: portab.h,v 1.34 2002-10-19 12:20:33 edgomez Exp $
34 : edgomez 407 *
35 :     ****************************************************************************/
36 :    
37 : Isibaar 3 #ifndef _PORTAB_H_
38 :     #define _PORTAB_H_
39 :    
40 : edgomez 513 /*****************************************************************************
41 :     * Common things
42 :     ****************************************************************************/
43 : suxen_drol 252
44 : edgomez 513 /* Debug level masks */
45 : suxen_drol 252 #define DPRINTF_ERROR 0x00000001
46 :     #define DPRINTF_STARTCODE 0x00000002
47 :     #define DPRINTF_HEADER 0x00000004
48 :     #define DPRINTF_TIMECODE 0x00000008
49 :     #define DPRINTF_MB 0x00000010
50 :     #define DPRINTF_COEFF 0x00000020
51 :     #define DPRINTF_MV 0x00000040
52 :     #define DPRINTF_DEBUG 0x80000000
53 :    
54 : edgomez 513 /* debug level for this library */
55 : suxen_drol 252 #define DPRINTF_LEVEL 0
56 :    
57 : edgomez 513 /* Buffer size for non C99 compliant compilers (msvc) */
58 : suxen_drol 252 #define DPRINTF_BUF_SZ 1024
59 :    
60 : edgomez 513 /*****************************************************************************
61 :     * Types used in XviD sources
62 :     ****************************************************************************/
63 : suxen_drol 252
64 : edgomez 513 /*----------------------------------------------------------------------------
65 :     | Standard Unix include file (sorry, we put all unix into "linux" case)
66 :     *---------------------------------------------------------------------------*/
67 : Isibaar 3
68 : edgomez 513 #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)
69 : Isibaar 3
70 : edgomez 513 /* All (u)int(size)_t types are defined here */
71 :     # include <inttypes.h>
72 : suxen_drol 136
73 : edgomez 513 /*----------------------------------------------------------------------------
74 :     | msvc (lacks such a header file)
75 :     *---------------------------------------------------------------------------*/
76 : suxen_drol 136
77 : edgomez 513 #elif defined(_MSC_VER)
78 :     # define int8_t char
79 :     # define uint8_t unsigned char
80 :     # define int16_t short
81 :     # define uint16_t unsigned short
82 :     # define int32_t int
83 :     # define uint32_t unsigned int
84 :     # define int64_t __int64
85 :     # define uint64_t unsigned __int64
86 : suxen_drol 136
87 : edgomez 513 /*----------------------------------------------------------------------------
88 :     | Fallback when using gcc
89 :     *---------------------------------------------------------------------------*/
90 : h 108
91 : edgomez 513 #elif defined(__GNUC__)
92 : Isibaar 3
93 : edgomez 513 # define int8_t char
94 :     # define uint8_t unsigned char
95 :     # define int16_t short
96 :     # define uint16_t unsigned short
97 :     # define int32_t int
98 :     # define uint32_t unsigned int
99 :     # define int64_t long long
100 :     # define uint64_t unsigned long long
101 : Isibaar 3
102 : edgomez 513 /*----------------------------------------------------------------------------
103 :     | Ok, we don't know how to define these types... error
104 :     *---------------------------------------------------------------------------*/
105 : Isibaar 3
106 : suxen_drol 68 #else
107 : edgomez 513 # error Do not know how to define (u)int(size)_t types
108 : suxen_drol 68 #endif
109 : Isibaar 42
110 : edgomez 513 /*****************************************************************************
111 :     * Some things that are only architecture dependant
112 :     ****************************************************************************/
113 : Isibaar 3
114 : edgomez 521 #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS) || defined(ARCH_SPARC)
115 : edgomez 513 # define CACHE_LINE 16
116 :     # define ptr_t uint32_t
117 : edgomez 521 #elif defined(ARCH_IA64)
118 : edgomez 513 # define CACHE_LINE 32
119 :     # define ptr_t uint64_t
120 : chl 37 #else
121 : edgomez 513 # error Architecture not supported.
122 : chl 37 #endif
123 : Isibaar 3
124 : edgomez 513 /*****************************************************************************
125 :     * Things that must be sorted by compiler and then by architecture
126 :     ****************************************************************************/
127 : Isibaar 3
128 : edgomez 513 /*****************************************************************************
129 :     * MSVC compiler specific macros, functions
130 :     ****************************************************************************/
131 : Isibaar 3
132 : edgomez 513 #if defined(_MSC_VER)
133 : canard 73
134 : edgomez 513 /*----------------------------------------------------------------------------
135 :     | Common msvc stuff
136 :     *---------------------------------------------------------------------------*/
137 : Isibaar 3
138 : edgomez 513 #include <windows.h>
139 :     #include <stdio.h>
140 : edgomez 78
141 : edgomez 513 /*
142 :     * This function must be declared/defined all the time because MSVC does
143 :     * not support C99 variable arguments macros
144 :     */
145 :     static __inline void DPRINTF(int level, char *fmt, ...)
146 :     {
147 :     if (DPRINTF_LEVEL & level) {
148 :     va_list args;
149 :     char buf[DPRINTF_BUF_SZ];
150 :     va_start(args, fmt);
151 :     vsprintf(buf, fmt, args);
152 :     OutputDebugString(buf);
153 :     fprintf(stderr, "%s\n", buf);
154 :     }
155 :     }
156 : Isibaar 3
157 : edgomez 513 # if _MSC_VER <= 1200
158 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
159 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
160 :     type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
161 :     # else
162 :     # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
163 :     __declspec(align(alignment)) type name[(sizex)*(sizey)]
164 :     # endif
165 : Isibaar 3
166 :    
167 : edgomez 513 /*----------------------------------------------------------------------------
168 :     | msvc x86 specific macros/functions
169 :     *---------------------------------------------------------------------------*/
170 :     # if defined(ARCH_X86)
171 : h 518 # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
172 : edgomez 513 # define EMMS() __asm {emms}
173 : canard 89
174 : edgomez 513 static __inline int64_t read_counter(void)
175 :     {
176 :     int64_t ts;
177 :     uint32_t ts1, ts2;
178 :     __asm {
179 :     rdtsc
180 :     mov ts1, eax
181 :     mov ts2, edx
182 :     }
183 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
184 :     return ts;
185 :     }
186 : edgomez 195
187 : edgomez 513 /*----------------------------------------------------------------------------
188 :     | msvc unknown architecture
189 :     *---------------------------------------------------------------------------*/
190 :     # else
191 :     # error Architecture not supported.
192 :     # endif
193 : edgomez 195
194 :    
195 : Isibaar 209
196 :    
197 : edgomez 513 /*****************************************************************************
198 :     * GNU CC compiler stuff
199 :     ****************************************************************************/
200 : Isibaar 209
201 : edgomez 513 #elif defined(__GNUC__) /* Compiler test */
202 : Isibaar 209
203 : edgomez 513 /*----------------------------------------------------------------------------
204 :     | Common gcc stuff
205 :     *---------------------------------------------------------------------------*/
206 : Isibaar 209
207 : edgomez 513 /*
208 :     * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
209 :     * and it's a macro calling fprintf directly
210 :     */
211 :     # ifdef _DEBUG
212 : Isibaar 209
213 : edgomez 513 /* Needed for all debuf fprintf calls */
214 :     # include <stdio.h>
215 : Isibaar 209
216 : edgomez 513 # define DPRINTF(level, format, ...) \
217 :     do {\
218 :     if(DPRINTF_LEVEL & level)\
219 :     fprintf(stderr, format"\n", ##__VA_ARGS__);\
220 :     }while(0);
221 : ia64p 283
222 : edgomez 513 # else /* _DEBUG */
223 :     # define DPRINTF(level, format, ...)
224 :     # endif /* _DEBUG */
225 : Isibaar 209
226 : ia64p 280
227 :    
228 : edgomez 516 # define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
229 :     type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
230 :     type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))
231 :    
232 : edgomez 513 /*----------------------------------------------------------------------------
233 :     | gcc x86 specific macros/functions
234 :     *---------------------------------------------------------------------------*/
235 :     # if defined(ARCH_X86)
236 :     # define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
237 :     # define EMMS() __asm__ ("emms\n\t");
238 : Isibaar 209
239 : edgomez 513 static __inline int64_t read_counter(void)
240 :     {
241 :     int64_t ts;
242 :     uint32_t ts1, ts2;
243 :     __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
244 :     ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
245 :     return ts;
246 :     }
247 : ia64p 283
248 : edgomez 513 /*----------------------------------------------------------------------------
249 :     | gcc PPC and PPC Altivec specific macros/functions
250 :     *---------------------------------------------------------------------------*/
251 :     # elif defined(ARCH_PPC)
252 :     # define BSWAP(a) __asm__ __volatile__ \
253 :     ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
254 :     # define EMMS()
255 : ia64p 283
256 : edgomez 513 static __inline unsigned long get_tbl(void)
257 :     {
258 :     unsigned long tbl;
259 :     asm volatile ("mftb %0":"=r" (tbl));
260 :     return tbl;
261 :     }
262 : ia64p 283
263 : edgomez 513 static __inline unsigned long get_tbu(void)
264 :     {
265 :     unsigned long tbl;
266 :     asm volatile ("mftbu %0":"=r" (tbl));
267 :     return tbl;
268 :     }
269 : ia64p 283
270 : edgomez 513 static __inline int64_t read_counter(void)
271 :     {
272 :     unsigned long tb, tu;
273 :     do {
274 :     tu = get_tbu();
275 :     tb = get_tbl();
276 :     }while (tb != get_tbl());
277 :     return (((int64_t) tu) << 32) | (int64_t) tb;
278 :     }
279 : ia64p 283
280 : edgomez 513 /*----------------------------------------------------------------------------
281 :     | gcc IA64 specific macros/functions
282 :     *---------------------------------------------------------------------------*/
283 :     # elif defined(ARCH_IA64)
284 :     # define BSWAP(a) __asm__ __volatile__ \
285 :     ("mux1 %1 = %0, @rev" ";;" \
286 :     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
287 :     # define EMMS()
288 : ia64p 283
289 : edgomez 513 static __inline int64_t read_counter(void) {
290 :     unsigned long result;
291 :     __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
292 :     return result;
293 :     }
294 : ia64p 283
295 : edgomez 513 /*----------------------------------------------------------------------------
296 :     | gcc SPARC specific macros/functions
297 :     *---------------------------------------------------------------------------*/
298 :     # elif defined(ARCH_SPARC)
299 :     # define BSWAP(a) \
300 : edgomez 517 ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
301 : edgomez 513 (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
302 :     # define EMMS()
303 : ia64p 283
304 : edgomez 513 static __inline int64_t read_counter(void)
305 :     {
306 :     return 0;
307 :     }
308 : ia64p 283
309 : edgomez 513 /*----------------------------------------------------------------------------
310 :     | gcc MIPS specific macros/functions
311 :     *---------------------------------------------------------------------------*/
312 :     # elif defined(ARCH_MIPS)
313 :     # define BSWAP(a) \
314 : edgomez 517 ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
315 : edgomez 513 (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
316 :     # define EMMS()
317 : Isibaar 3
318 : edgomez 513 static __inline int64_t read_counter(void)
319 :     {
320 :     return 0;
321 :     }
322 : edgomez 78
323 : edgomez 513 /*----------------------------------------------------------------------------
324 :     | XviD + gcc unsupported Architecture
325 :     *---------------------------------------------------------------------------*/
326 :     # else
327 :     # error Architecture not supported.
328 :     # endif /* Architecture checking */
329 : Isibaar 3
330 : edgomez 513 /*****************************************************************************
331 :     * Unknown compiler
332 :     ****************************************************************************/
333 :     #else /* Compiler test */
334 : Isibaar 3
335 : edgomez 513 # error Compiler not supported
336 : Isibaar 3
337 : edgomez 513 #endif /* Compiler test */
338 : Isibaar 3
339 : Isibaar 209
340 : edgomez 78 #endif

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