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

Diff of /xvidcore/src/portab.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2, Sat Mar 16 14:15:10 2002 UTC revision 1.48, Fri Mar 28 07:28:23 2003 UTC
# Line 1  Line 1 
1    /*****************************************************************************
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@free.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     * $Id$
27     *
28     ****************************************************************************/
29    
30  #ifndef _PORTAB_H_  #ifndef _PORTAB_H_
31  #define _PORTAB_H_  #define _PORTAB_H_
32    
33  #if defined(WIN32)  /*****************************************************************************
34     *  Common things
35  #include <windows.h>   ****************************************************************************/
36    
37    /* Debug level masks */
38    #define DPRINTF_ERROR       0x00000001
39    #define DPRINTF_STARTCODE   0x00000002
40    #define DPRINTF_HEADER      0x00000004
41    #define DPRINTF_TIMECODE    0x00000008
42    #define DPRINTF_MB          0x00000010
43    #define DPRINTF_COEFF       0x00000020
44    #define DPRINTF_MV          0x00000040
45    #define DPRINTF_RC          0x00000080
46    #define DPRINTF_DEBUG       0x80000000
47    
48    /* debug level for this library */
49  #ifdef _DEBUG  #ifdef _DEBUG
50  #define DEBUG(S) OutputDebugString((S));  #define DPRINTF_LEVEL       0x000000ff
51  #define DEBUG1(S,I) { char tmp[100]; wsprintf(tmp, "%s %i\n", (S), (I)); OutputDebugString(tmp); }  #else
52  #define DEBUG2(X,A,B) { char tmp[100]; wsprintf(tmp, "%s %i %i\n", (X), (A), (B)); OutputDebugString(tmp); }  #define DPRINTF_LEVEL       0
 #define DEBUG3(X,A,B,C){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i",(X),(A), (B), (C)); OutputDebugString(tmp); }  
 #define DEBUG8(X,A,B,C,D,E,F,G,H){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i %i %i %i %i %i",(X),(A),(B),(C),(D),(E),(F),(G),(H)); OutputDebugString(tmp); }  
 #else  
 #define DEBUG(S)  
 #define DEBUG1(S,I)  
 #define DEBUG2(X,A,B)  
 #define DEBUG3(X,A,B,C)  
 #define DEBUG8(X,A,B,C,D,E,F,G,H)  
53  #endif  #endif
54    
55    /* Buffer size for msvc implementation because it outputs to DebugOutput */
56    #define DPRINTF_BUF_SZ  1024
57    
58    /*****************************************************************************
59     *  Types used in XviD sources
60     ****************************************************************************/
61    
62    /*----------------------------------------------------------------------------
63     | For MSVC
64     *---------------------------------------------------------------------------*/
65    
66    #if defined(_MSC_VER) || defined (__WATCOMC__)
67  #define int8_t char  #define int8_t char
68  #define uint8_t unsigned char  #define uint8_t unsigned char
69  #define int16_t short  #define int16_t short
# Line 29  Line 73 
73  #define int64_t __int64  #define int64_t __int64
74  #define uint64_t unsigned __int64  #define uint64_t unsigned __int64
75    
76  #define EMMS() __asm {emms}  /*----------------------------------------------------------------------------
77     | For all other compilers, use the standard header file
78     | (compiler should be ISO C99 compatible, perhaps ISO C89 is enough)
79     *---------------------------------------------------------------------------*/
80    
81    #else
82    
83    #    include <inttypes.h>
84    
85    #endif
86    
87    /*****************************************************************************
88     *  Some things that are only architecture dependant
89     ****************************************************************************/
90    
91    #if defined(ARCH_IS_32BIT)
92    #    define CACHE_LINE 64
93    #    define ptr_t uint32_t
94    #    define intptr_t int32_t
95    #    if _MSC_VER < 1300
96    #        define uintptr_t uint32_t
97    #    else
98    #        include <stdarg.h>
99    #    endif
100    #elif defined(ARCH_IS_64BIT)
101    #    define CACHE_LINE  64
102    #    define ptr_t uint64_t
103    #    define intptr_t int64_t
104    #    if _MSC_VER < 1300
105    #        define uintptr_t uint64_t
106    #    else
107    #        include <stdarg.h>
108    #    endif
109    #else
110    #    error You are trying to compile XviD without defining address bus size.
111    #endif
112    
113    /*****************************************************************************
114     *  Things that must be sorted by compiler and then by architecture
115     ****************************************************************************/
116    
117    /*****************************************************************************
118     *  MSVC compiler specific macros, functions
119     ****************************************************************************/
120    
121    #if defined(_MSC_VER)
122    
123    /*----------------------------------------------------------------------------
124     | Common msvc stuff
125     *---------------------------------------------------------------------------*/
126    
127    #    include <windows.h>
128    #    include <stdio.h>
129    
130         /* Non ANSI mapping */
131    #    define snprintf _snprintf
132    #    define vsnprintf _vsnprintf
133    
134        /*
135         * This function must be declared/defined all the time because MSVC does
136         * not support C99 variable arguments macros.
137         *
138         * Btw, if the MS compiler does its job well, it should remove the nop
139         * DPRINTF function when not compiling in _DEBUG mode
140         */
141    #   ifdef _DEBUG
142        static __inline void DPRINTF(int level, char *fmt, ...)
143        {
144            if (DPRINTF_LEVEL & level) {
145                va_list args;
146                char buf[DPRINTF_BUF_SZ];
147                va_start(args, fmt);
148                vsprintf(buf, fmt, args);
149                OutputDebugString(buf);
150                fprintf(stderr, "%s\n", buf);
151             }
152         }
153    #    else
154             static __inline void DPRINTF(int level, char *fmt, ...) {}
155    #    endif
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  // needed for bitstream.h  /*----------------------------------------------------------------------------
168     | msvc x86 specific macros/functions
169     *---------------------------------------------------------------------------*/
170    #    if defined(ARCH_IS_IA32)
171  #define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax  #define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
172    
173  // needed for timer.c           static __inline int64_t read_counter(void)
174  static __inline int64_t read_counter() {           {
175          int64_t ts;          int64_t ts;
176          uint32_t ts1, ts2;          uint32_t ts1, ts2;
   
177          __asm {          __asm {
178                  rdtsc                  rdtsc
179                  mov  ts1, eax                  mov  ts1, eax
180                  mov  ts2, edx                  mov  ts2, edx
181          }          }
   
182          ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);          ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
   
183          return ts;          return ts;
184  }  }
185    
186  #elif defined(LINUX) || defined(DJGPP)  /*----------------------------------------------------------------------------
187     | msvc GENERIC (plain C only) - Probably alpha or some embedded device
188     *---------------------------------------------------------------------------*/
189    #    elif defined(ARCH_IS_GENERIC)
190    #        define BSWAP(a) \
191                    ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
192                           (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
193    
194    #        include <time.h>
195             static __inline int64_t read_counter(void)
196             {
197                 return (int64_t)clock();
198             }
199    
200  #include <stdio.h>  /*----------------------------------------------------------------------------
201  #define DEBUG_WHERE             stdout   | msvc Not given architecture - This is probably an user who tries to build
202  #define DEBUG(S)        fprintf(DEBUG_WHERE, "%s\n", (S));   | XviD the wrong way.
203  #define DEBUG1(S,I)     fprintf(DEBUG_WHERE, "%s %i\n", (S), (I))   *---------------------------------------------------------------------------*/
204  #define DEBUG2(S,A,B)   fprintf(DEBUG_WHERE, "%s%i=%i\n", (S), (A), (B))  #    else
205  #define DEBUG3(S,A,B,C) fprintf(DEBUG_WHERE, "%s %i %x %x\n", (S), (A), (B), (C))  #        error You are trying to compile XviD without defining the architecture type.
206  #define DEBUG8(S,A,B,C,D,E,F,G,H)  #    endif
207    
 #if defined(LINUX)  
208    
 #include <stdint.h>  
209    
 #else  
210    
211  #define int8_t char  /*****************************************************************************
212  #define uint8_t unsigned char   *  GNU CC compiler stuff
213  #define int16_t short   ****************************************************************************/
214  #define uint16_t unsigned short  
215  #define int32_t int  #elif defined(__GNUC__) || defined(__ICC) /* Compiler test */
216  #define uint32_t unsigned int  
217  #define int64_t long long  /*----------------------------------------------------------------------------
218  #define uint64_t unsigned long long   | Common gcc stuff
219     *---------------------------------------------------------------------------*/
220    
221    /*
222     * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
223     * and it's a macro calling fprintf directly
224     */
225    #    ifdef _DEBUG
226    
227  #endif          /* Needed for all debuf fprintf calls */
228    #       include <stdio.h>
229    #       include <stdarg.h>
230    
231  #define EMMS() __asm__("emms\n\t")          static __inline void DPRINTF(int level, char *format, ...)
232            {
233                va_list args;
234                va_start(args, format);
235                if(DPRINTF_LEVEL & level) {
236                       vfprintf(stderr, format, args);
237                       fprintf(stderr, "\n");
238                }
239            }
240    
241  // needed for bitstream.h  #    else /* _DEBUG */
242  #define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) )          static __inline void DPRINTF(int level, char *format, ...) {}
243    #    endif /* _DEBUG */
244    
245    
246    #    define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
247                type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
248                type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))
249    
250    /*----------------------------------------------------------------------------
251     | gcc IA32 specific macros/functions
252     *---------------------------------------------------------------------------*/
253    #    if defined(ARCH_IS_IA32)
254    #        define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
255    
256  // needed for timer.c           static __inline int64_t read_counter(void)
257  static __inline int64_t read_counter() {           {
258      int64_t ts;      int64_t ts;
259      uint32_t ts1, ts2;      uint32_t ts1, ts2;
   
260      __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));      __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
   
261      ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);      ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
   
262      return ts;      return ts;
263  }  }
264    
265  #else // OTHER OS  /*----------------------------------------------------------------------------
266     | gcc PPC and PPC Altivec specific macros/functions
267     *---------------------------------------------------------------------------*/
268    #    elif defined(ARCH_IS_PPC)
269    #        define BSWAP(a) __asm__ __volatile__ \
270                    ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
271    
272             static __inline unsigned long get_tbl(void)
273             {
274                 unsigned long tbl;
275                 asm volatile ("mftb %0":"=r" (tbl));
276                 return tbl;
277             }
278    
279  #define DEBUG(S)           static __inline unsigned long get_tbu(void)
280  #define DEBUG1(S,I)           {
281  #define DEBUG2(X,A,B)               unsigned long tbl;
282  #define DEBUG3(X,A,B,C)               asm volatile ("mftbu %0":"=r" (tbl));
283  #define DEBUG8(X,A,B,C,D,E,F,G,H)               return tbl;
284             }
285    
286  #include <inttypes.h>           static __inline int64_t read_counter(void)
287             {
288                 unsigned long tb, tu;
289                 do {
290                     tu = get_tbu();
291                     tb = get_tbl();
292                 }while (tb != get_tbl());
293                 return (((int64_t) tu) << 32) | (int64_t) tb;
294             }
295    
296  #define EMMS()  /*----------------------------------------------------------------------------
297     | gcc IA64 specific macros/functions
298     *---------------------------------------------------------------------------*/
299    #    elif defined(ARCH_IS_IA64)
300    #        define BSWAP(a)  __asm__ __volatile__ \
301                    ("mux1 %1 = %0, @rev" ";;" \
302                     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
303    
304             static __inline int64_t read_counter(void)
305             {
306                 unsigned long result;
307                 __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
308                 return result;
309             }
310    
311  // needed for bitstream.h  /*----------------------------------------------------------------------------
312     | gcc GENERIC (plain C only) specific macros/functions
313     *---------------------------------------------------------------------------*/
314    #    elif defined(ARCH_IS_GENERIC)
315  #define BSWAP(a) \  #define BSWAP(a) \
316           ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff))                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
317                           (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
318    
319    #        include <time.h>
320             static __inline int64_t read_counter(void)
321             {
322                 return (int64_t)clock();
323             }
324    
325    /*----------------------------------------------------------------------------
326     | gcc Not given architecture - This is probably an user who tries to build
327     | XviD the wrong way.
328     *---------------------------------------------------------------------------*/
329    #    else
330    #        error You are trying to compile XviD without defining the architecture type.
331    #    endif
332    
333    
334    
335    
336    /*****************************************************************************
337     *  Open WATCOM C/C++ compiler
338     ****************************************************************************/
339    
340    #elif defined(__WATCOMC__)
341    
342    #    include <stdio.h>
343    #    include <stdarg.h>
344    
345    #    ifdef _DEBUG
346         static __inline void DPRINTF(int level, char *fmt, ...)
347         {
348             if (DPRINTF_LEVEL & level) {
349                 va_list args;
350                 char buf[DPRINTF_BUF_SZ];
351                 va_start(args, fmt);
352                 vsprintf(buf, fmt, args);
353                 fprintf(stderr, "%s\n", buf);
354             }
355         }
356    #    else /* _DEBUG */
357             static __inline void DPRINTF(int level, char *format, ...) {}
358    #    endif /* _DEBUG */
359    
360    #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
361                    type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
362                    type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
363    
364    /*----------------------------------------------------------------------------
365     | watcom ia32 specific macros/functions
366     *---------------------------------------------------------------------------*/
367    #    if defined(ARCH_IS_IA32)
368    
369    #        define BSWAP(a)  __asm mov eax,a __asm bswap eax __asm mov a, eax
370    
371  // rdtsc command most likely not supported,           static __inline int64_t read_counter(void)
372  // so just dummy code here           {
373  static __inline int64_t read_counter() {               uint64_t ts;
374          return 0;               uint32_t ts1, ts2;
375                 __asm {
376                     rdtsc
377                     mov ts1, eax
378                     mov ts2, edx
379                 }
380                 ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
381                 return ts;
382  }  }
383    
384    /*----------------------------------------------------------------------------
385     | watcom GENERIC (plain C only) specific macros/functions.
386     *---------------------------------------------------------------------------*/
387    #    elif defined(ARCH_IS_GENERIC)
388    
389    #        define BSWAP(x) \
390                x = ((((x) & 0xff000000) >> 24) | \
391                    (((x) & 0x00ff0000) >>  8) | \
392                    (((x) & 0x0000ff00) <<  8) | \
393                    (((x) & 0x000000ff) << 24))
394    
395             static int64_t read_counter() { return 0; }
396    
397    /*----------------------------------------------------------------------------
398     | watcom Not given architecture - This is probably an user who tries to build
399     | XviD the wrong way.
400     *---------------------------------------------------------------------------*/
401    #    else
402    #        error You are trying to compile XviD without defining the architecture type.
403  #endif  #endif
404    
 #endif // _PORTAB_H_  
405    
406    /*****************************************************************************
407     *  Unknown compiler
408     ****************************************************************************/
409    #else /* Compiler test */
410    
411          /*
412           * Ok we know nothing about the compiler, so we fallback to ANSI C
413           * features, so every compiler should be happy and compile the code.
414           *
415           * This is (mostly) equivalent to ARCH_IS_GENERIC.
416           */
417    
418    #    ifdef _DEBUG
419    
420            /* Needed for all debuf fprintf calls */
421    #       include <stdio.h>
422    #       include <stdarg.h>
423    
424            static __inline void DPRINTF(int level, char *format, ...)
425            {
426                va_list args;
427                va_start(args, format);
428                if(DPRINTF_LEVEL & level) {
429                       vfprintf(stderr, format, args);
430                       fprintf(stderr, "\n");
431                }
432            }
433    
434    #    else /* _DEBUG */
435            static __inline void DPRINTF(int level, char *format, ...) {}
436    #    endif /* _DEBUG */
437    
438    #    define BSWAP(a) \
439                ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
440                       (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
441    
442    #    include <time.h>
443         static __inline int64_t read_counter(void)
444         {
445             return (int64_t)clock();
446         }
447    
448    #    define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
449                    type name[(sizex)*(sizey)]
450    
451    #endif /* Compiler test */
452    
453    
454    #endif /* PORTAB_H */

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.48

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