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

Annotation of /xvidcore/src/portab.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.34 - (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 :     * 2002 Edouard Gomez <ed.gomez@wanadoo.fr>
9 : edgomez 1.27 *
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 1.34 * $Id: portab.h,v 1.33 2002/10/19 11:41:11 edgomez Exp $
34 : edgomez 1.27 *
35 :     ****************************************************************************/
36 :    
37 : Isibaar 1.1 #ifndef _PORTAB_H_
38 :     #define _PORTAB_H_
39 :    
40 : edgomez 1.28 /*****************************************************************************
41 :     * Common things
42 :     ****************************************************************************/
43 : suxen_drol 1.23
44 : edgomez 1.28 /* Debug level masks */
45 : suxen_drol 1.23 #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 1.28 /* debug level for this library */
55 : suxen_drol 1.23 #define DPRINTF_LEVEL 0
56 :    
57 : edgomez 1.28 /* Buffer size for non C99 compliant compilers (msvc) */
58 : suxen_drol 1.23 #define DPRINTF_BUF_SZ 1024
59 :    
60 : edgomez 1.28 /*****************************************************************************
61 :     * Types used in XviD sources
62 :     ****************************************************************************/
63 : suxen_drol 1.23
64 : edgomez 1.28 /*----------------------------------------------------------------------------
65 :     | Standard Unix include file (sorry, we put all unix into "linux" case)
66 :     *---------------------------------------------------------------------------*/
67 :    
68 :     #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)
69 :    
70 :     /* All (u)int(size)_t types are defined here */
71 :     # include <inttypes.h>
72 :    
73 :     /*----------------------------------------------------------------------------
74 :     | msvc (lacks such a header file)
75 :     *---------------------------------------------------------------------------*/
76 :    
77 :     #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 :    
87 :     /*----------------------------------------------------------------------------
88 :     | Fallback when using gcc
89 :     *---------------------------------------------------------------------------*/
90 :    
91 :     #elif defined(__GNUC__)
92 :    
93 :     # 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 :    
102 :     /*----------------------------------------------------------------------------
103 :     | Ok, we don't know how to define these types... error
104 :     *---------------------------------------------------------------------------*/
105 : suxen_drol 1.16
106 : h 1.2 #else
107 : edgomez 1.28 # error Do not know how to define (u)int(size)_t types
108 : h 1.2 #endif
109 : Isibaar 1.1
110 : edgomez 1.28 /*****************************************************************************
111 :     * Some things that are only architecture dependant
112 :     ****************************************************************************/
113 : Isibaar 1.1
114 : edgomez 1.32 #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS) || defined(ARCH_SPARC)
115 : edgomez 1.28 # define CACHE_LINE 16
116 :     # define ptr_t uint32_t
117 : edgomez 1.32 #elif defined(ARCH_IA64)
118 : edgomez 1.28 # define CACHE_LINE 32
119 :     # define ptr_t uint64_t
120 : suxen_drol 1.7 #else
121 : edgomez 1.28 # error Architecture not supported.
122 : suxen_drol 1.7 #endif
123 : Isibaar 1.4
124 : edgomez 1.28 /*****************************************************************************
125 :     * Things that must be sorted by compiler and then by architecture
126 :     ****************************************************************************/
127 : Isibaar 1.1
128 : edgomez 1.28 /*****************************************************************************
129 :     * MSVC compiler specific macros, functions
130 :     ****************************************************************************/
131 : edgomez 1.18
132 : edgomez 1.28 #if defined(_MSC_VER)
133 : edgomez 1.18
134 : edgomez 1.28 /*----------------------------------------------------------------------------
135 :     | Common msvc stuff
136 :     *---------------------------------------------------------------------------*/
137 : Isibaar 1.1
138 : edgomez 1.28 #include <windows.h>
139 : suxen_drol 1.22 #include <stdio.h>
140 : suxen_drol 1.23
141 : edgomez 1.28 /*
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 :    
157 :     # 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 :    
166 :    
167 :     /*----------------------------------------------------------------------------
168 :     | msvc x86 specific macros/functions
169 :     *---------------------------------------------------------------------------*/
170 :     # if defined(ARCH_X86)
171 : h 1.31 # define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
172 : edgomez 1.28 # define EMMS() __asm {emms}
173 :    
174 :     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 :    
187 :     /*----------------------------------------------------------------------------
188 :     | msvc unknown architecture
189 :     *---------------------------------------------------------------------------*/
190 :     # else
191 :     # error Architecture not supported.
192 :     # endif
193 : suxen_drol 1.22
194 : chl 1.3
195 : Isibaar 1.1
196 :    
197 : edgomez 1.28 /*****************************************************************************
198 :     * GNU CC compiler stuff
199 :     ****************************************************************************/
200 : canard 1.8
201 : edgomez 1.28 #elif defined(__GNUC__) /* Compiler test */
202 : Isibaar 1.1
203 : edgomez 1.28 /*----------------------------------------------------------------------------
204 :     | Common gcc stuff
205 :     *---------------------------------------------------------------------------*/
206 :    
207 :     /*
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 :    
213 :     /* Needed for all debuf fprintf calls */
214 :     # include <stdio.h>
215 :    
216 :     # define DPRINTF(level, format, ...) \
217 :     do {\
218 :     if(DPRINTF_LEVEL & level)\
219 :     fprintf(stderr, format"\n", ##__VA_ARGS__);\
220 :     }while(0);
221 :    
222 :     # else /* _DEBUG */
223 :     # define DPRINTF(level, format, ...)
224 :     # endif /* _DEBUG */
225 :    
226 :    
227 : edgomez 1.29
228 :     # 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 : edgomez 1.28
232 :     /*----------------------------------------------------------------------------
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 :    
239 :     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 :    
248 :     /*----------------------------------------------------------------------------
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 :    
256 :     static __inline unsigned long get_tbl(void)
257 :     {
258 :     unsigned long tbl;
259 :     asm volatile ("mftb %0":"=r" (tbl));
260 :     return tbl;
261 :     }
262 :    
263 :     static __inline unsigned long get_tbu(void)
264 :     {
265 :     unsigned long tbl;
266 :     asm volatile ("mftbu %0":"=r" (tbl));
267 :     return tbl;
268 :     }
269 :    
270 :     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 :    
280 :     /*----------------------------------------------------------------------------
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 :    
289 :     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 :    
295 :     /*----------------------------------------------------------------------------
296 :     | gcc SPARC specific macros/functions
297 :     *---------------------------------------------------------------------------*/
298 :     # elif defined(ARCH_SPARC)
299 :     # define BSWAP(a) \
300 : edgomez 1.30 ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
301 : edgomez 1.28 (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
302 :     # define EMMS()
303 :    
304 :     static __inline int64_t read_counter(void)
305 :     {
306 :     return 0;
307 :     }
308 :    
309 :     /*----------------------------------------------------------------------------
310 :     | gcc MIPS specific macros/functions
311 :     *---------------------------------------------------------------------------*/
312 :     # elif defined(ARCH_MIPS)
313 :     # define BSWAP(a) \
314 : edgomez 1.30 ((a) = (((a) & 0xff) << 24) | (((a) & 0xff00) << 8) | \
315 : edgomez 1.28 (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
316 :     # define EMMS()
317 :    
318 :     static __inline int64_t read_counter(void)
319 :     {
320 :     return 0;
321 :     }
322 :    
323 :     /*----------------------------------------------------------------------------
324 :     | XviD + gcc unsupported Architecture
325 :     *---------------------------------------------------------------------------*/
326 :     # else
327 :     # error Architecture not supported.
328 :     # endif /* Architecture checking */
329 : edgomez 1.9
330 : edgomez 1.28 /*****************************************************************************
331 :     * Unknown compiler
332 :     ****************************************************************************/
333 :     #else /* Compiler test */
334 : Isibaar 1.21
335 : edgomez 1.28 # error Compiler not supported
336 : Isibaar 1.21
337 : edgomez 1.28 #endif /* Compiler test */
338 : Isibaar 1.21
339 : Isibaar 1.1
340 :     #endif

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