[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.26.2.8, Sat Feb 15 08:39:17 2003 UTC revision 1.42.2.1, Fri Apr 4 22:10:38 2003 UTC
# Line 5  Line 5 
5   *   *
6   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>   *  Copyright(C) 2002 Michael Militzer <isibaar@xvid.org>
7   *               2002 Peter Ross <pross@xvid.org>   *               2002 Peter Ross <pross@xvid.org>
8   *               2002 Edouard Gomez <ed.gomez@wanadoo.fr>   *               2002 Edouard Gomez <ed.gomez@free.fr>
9   *   *
10   *  This file is part of XviD, a free MPEG-4 video encoder/decoder   *  This file is part of XviD, a free MPEG-4 video encoder/decoder
11   *   *
# Line 71  Line 71 
71  #define DPRINTF_MB                      0x00000010  #define DPRINTF_MB                      0x00000010
72  #define DPRINTF_COEFF           0x00000020  #define DPRINTF_COEFF           0x00000020
73  #define DPRINTF_MV                      0x00000040  #define DPRINTF_MV                      0x00000040
 #define DPRINTF_RC                      0x00000080  
74  #define DPRINTF_DEBUG           0x80000000  #define DPRINTF_DEBUG           0x80000000
75    
76  /* debug level for this library */  /* debug level for this library */
77  #ifdef _DEBUG  #define DPRINTF_LEVEL           0
 #define DPRINTF_LEVEL           (DPRINTF_RC|0x0000007F)  
 #else  
 #define DPRINTF_LEVEL           DPRINTF_RC  
 #endif  
78    
79  /* Buffer size for non C99 compliant compilers (msvc) */  /* Buffer size for msvc implementation because it outputs to DebugOutput */
80  #define DPRINTF_BUF_SZ  1024  #define DPRINTF_BUF_SZ  1024
81    
82  /*****************************************************************************  /*****************************************************************************
# Line 89  Line 84 
84   ****************************************************************************/   ****************************************************************************/
85    
86  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
87   | Standard Unix include file (sorry, we put all unix into "linux" case)   | For MSVC
88   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
89    
90  #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)  #if defined(_MSC_VER)
   
 /* All (u)int(size)_t types are defined here */  
 #    include <inttypes.h>  
   
 /*----------------------------------------------------------------------------  
  | msvc (lacks such a header file)  
  *---------------------------------------------------------------------------*/  
   
 #elif defined(_MSC_VER) || defined (__WATCOMC__)  
91  #    define int8_t   char  #    define int8_t   char
92  #    define uint8_t  unsigned char  #    define uint8_t  unsigned char
93  #    define int16_t  short  #    define int16_t  short
# Line 112  Line 98 
98  #    define uint64_t unsigned __int64  #    define uint64_t unsigned __int64
99    
100  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
101   | Fallback when using gcc   | For all other compilers, use the standard header file
102     | (compiler should be ISO C99 compatible, perhaps ISO C89 is enough)
103   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
104    
105  #elif defined(__GNUC__) || defined(__ICC)  #else
   
 #    define int8_t   char  
 #    define uint8_t  unsigned char  
 #    define int16_t  short  
 #    define uint16_t unsigned short  
 #    define int32_t  int  
 #    define uint32_t unsigned int  
 #    define int64_t  long long  
 #    define uint64_t unsigned long long  
106    
107  /*----------------------------------------------------------------------------  #    include <inttypes.h>
  | Ok, we don't know how to define these types... error  
  *---------------------------------------------------------------------------*/  
108    
 #else  
 #    error Do not know how to define (u)int(size)_t types  
109  #endif  #endif
110    
111  /*****************************************************************************  /*****************************************************************************
112   *  Some things that are only architecture dependant   *  Some things that are only architecture dependant
113   ****************************************************************************/   ****************************************************************************/
114    
115  #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS)  || defined(ARCH_SPARC)  #if defined(ARCH_IS_32BIT)
116  #    define CACHE_LINE  16  #    define CACHE_LINE  64
117  #    define ptr_t uint32_t  #    define ptr_t uint32_t
118  #elif defined(ARCH_IA64)  #elif defined(ARCH_IS_64BIT)
119  #    define CACHE_LINE  32  #    define CACHE_LINE  64
120  #    define ptr_t uint64_t  #    define ptr_t uint64_t
121  #else  #else
122  /* todo: fix cache_line 0 operation */  #    error You are trying to compile XviD without defining address bus size.
 #    define CACHE_LINE  16  
 #    define ptr_t uint32_t  
123  #endif  #endif
124    
125  /*****************************************************************************  /*****************************************************************************
# Line 167  Line 139 
139  #include <windows.h>  #include <windows.h>
140  #include <stdio.h>  #include <stdio.h>
141    
         /* non-ansi function mapping */  
 #       define snprintf _snprintf  
 #       define vsnprintf _vsnprintf  
   
142      /*      /*
143       * This function must be declared/defined all the time because MSVC does       * This function must be declared/defined all the time because MSVC does
144       * not support C99 variable arguments macros       * not support C99 variable arguments macros.
145         *
146         * Btw, if the MS compiler does its job well, it should remove the nop
147         * DPRINTF function when not compiling in _DEBUG mode
148       */       */
149    #   ifdef _DEBUG
150      static __inline void DPRINTF(int level, char *fmt, ...)      static __inline void DPRINTF(int level, char *fmt, ...)
151      {      {
152          if (DPRINTF_LEVEL & level) {          if (DPRINTF_LEVEL & level) {
# Line 186  Line 158 
158              fprintf(stderr, "%s\n", buf);              fprintf(stderr, "%s\n", buf);
159           }           }
160       }       }
161    #    else
162         static __inline void DPRINTF(int level, char *fmt, ...)
163         {
164         }
165    #    endif
166    
167  #    if _MSC_VER <= 1200  #    if _MSC_VER <= 1200
168  #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
# Line 200  Line 177 
177  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
178   | msvc x86 specific macros/functions   | msvc x86 specific macros/functions
179   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
180  #    if defined(ARCH_X86)  #    if defined(ARCH_IS_IA32)
181  #        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
182    #        define EMMS() __asm {emms}
183    
184    #        ifdef _PROFILING_
185               static __inline int64_t read_counter(void)               static __inline int64_t read_counter(void)
186               {               {
187                   int64_t ts;                   int64_t ts;
# Line 215  Line 194 
194                   ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);                   ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
195                   return ts;                   return ts;
196               }               }
197    #        endif
198    
199  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
200   | msvc unknown architecture   | msvc GENERIC (plain C only) - Probably alpha or some embedded device
201   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
202  #    else  #    elif defined(ARCH_IS_GENERIC)
203  /* ANSI C version of BSWAP */  #        define BSWAP(a) \
204  #define BSWAP(x) \                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
205   x = ((((x) & 0xff000000) >> 24) | \                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
206       (((x) & 0x00ff0000) >>  8) | \  #        define EMMS()
      (((x) & 0x0000ff00) <<  8) | \  
      (((x) & 0x000000ff) << 24))  
207    
208    #        ifdef _PROFILING_
209    #            include <time.h>
210                 static __inline int64_t read_counter(void)
211                 {
212                     return (int64_t)clock();
213                 }
214    #        endif
215    
216    /*----------------------------------------------------------------------------
217     | msvc Not given architecture - This is probably an user who tries to build
218     | XviD the wrong way.
219     *---------------------------------------------------------------------------*/
220    #    else
221    #        error You are trying to compile XviD without defining the architecture type.
222  #    endif  #    endif
223    
224    
# Line 250  Line 242 
242    
243          /* Needed for all debuf fprintf calls */          /* Needed for all debuf fprintf calls */
244  #       include <stdio.h>  #       include <stdio.h>
245    #       include <stdarg.h>
246    
247  #       define DPRINTF(level, format, ...) \          static __inline void DPRINTF(int level, char *format, ...)
248              do {\          {
249                  if(DPRINTF_LEVEL & level)\              va_list args;
250                      fprintf(stderr, format"\n", ##__VA_ARGS__);\              va_start(args, format);
251              }while(0);              if(DPRINTF_LEVEL & level) {
252                       vfprintf(stderr, format, args);
253                       fprintf(stderr, "\n");
254                            }
255                    }
256    
257  #    else /* _DEBUG */  #    else /* _DEBUG */
258  #        define DPRINTF(level, format, ...)          static __inline void DPRINTF(int level, char *format, ...) {}
259  #    endif /* _DEBUG */  #    endif /* _DEBUG */
260    
261    
   
262  #    define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #    define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
263              type name##_storage[(sizex)*(sizey)+(alignment)-1]; \              type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
264              type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))              type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))
265    
266  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
267   | gcc x86 specific macros/functions   | gcc IA32 specific macros/functions
268   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
269  #    if defined(ARCH_X86)  #    if defined(ARCH_IS_IA32)
270  #        define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );  #        define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
271    #        define EMMS() __asm__ ("emms\n\t");
272    
273    #        ifdef _PROFILING_
274           static __inline int64_t read_counter(void)           static __inline int64_t read_counter(void)
275           {           {
276               int64_t ts;               int64_t ts;
# Line 281  Line 279 
279               ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);               ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
280               return ts;               return ts;
281           }           }
282    #        endif
283    
284  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
285   | gcc PPC and PPC Altivec specific macros/functions   | gcc PPC and PPC Altivec specific macros/functions
286   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
287  #    elif defined(ARCH_PPC)  #    elif defined(ARCH_IS_PPC)
288  #        define BSWAP(a) __asm__ __volatile__ \  #        define BSWAP(a) __asm__ __volatile__ \
289                  ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));                  ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
290    #        define EMMS()
291    
292    #        ifdef _PROFILING_
293           static __inline unsigned long get_tbl(void)           static __inline unsigned long get_tbl(void)
294           {           {
295               unsigned long tbl;               unsigned long tbl;
# Line 312  Line 313 
313               }while (tb != get_tbl());               }while (tb != get_tbl());
314               return (((int64_t) tu) << 32) | (int64_t) tb;               return (((int64_t) tu) << 32) | (int64_t) tb;
315           }           }
316    #        endif
317    
318  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
319   | gcc IA64 specific macros/functions   | gcc IA64 specific macros/functions
320   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
321  #    elif defined(ARCH_IA64)  #    elif defined(ARCH_IS_IA64)
322  #        define BSWAP(a)  __asm__ __volatile__ \  #        define BSWAP(a)  __asm__ __volatile__ \
323                  ("mux1 %1 = %0, @rev" ";;" \                  ("mux1 %1 = %0, @rev" ";;" \
324                   "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));                   "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
325    #        define EMMS()
326    
327           static __inline int64_t read_counter(void) {  #        ifdef _PROFILING_
328                 static __inline int64_t read_counter(void)
329                 {
330               unsigned long result;               unsigned long result;
331               __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");               __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
332               return result;               return result;
333           }           }
334    #        endif
335    
336  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
337   | gcc SPARC specific macros/functions   | gcc GENERIC (plain C only) specific macros/functions
  *---------------------------------------------------------------------------*/  
 #    elif defined(ARCH_SPARC)  
 #        define BSWAP(a) \  
                 ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \  
                        (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))  
   
          static __inline int64_t read_counter(void)  
          {  
              return 0;  
          }  
   
 /*----------------------------------------------------------------------------  
  | gcc MIPS specific macros/functions  
338   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
339  #    elif defined(ARCH_MIPS)  #    elif defined(ARCH_IS_GENERIC)
340  #        define BSWAP(a) \  #        define BSWAP(a) \
341                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
342                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
343    #        define EMMS()
344    
345    #        ifdef _PROFILING_
346    #            include <time.h>
347           static __inline int64_t read_counter(void)           static __inline int64_t read_counter(void)
348           {           {
349               return 0;                   return (int64_t)clock();
350           }           }
351    #        endif
352    
353  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
354   | XviD + gcc unsupported Architecture   | gcc Not given architecture - This is probably an user who tries to build
355     | XviD the wrong way.
356   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
357  #    else  #    else
358  /* ANSI C version of BSWAP */  #        error You are trying to compile XviD without defining the architecture type.
359  #define BSWAP(x) \  #    endif
  x = ((((x) & 0xff000000) >> 24) | \  
      (((x) & 0x00ff0000) >>  8) | \  
      (((x) & 0x0000ff00) <<  8) | \  
      (((x) & 0x000000ff) << 24))  
   
 #    endif /* Architecture checking */  
360    
361  /*****************************************************************************  /*****************************************************************************
362   *  OPEN WATCOM C/C++ compiler   *  Unknown compiler
363   ****************************************************************************/   ****************************************************************************/
364  #elif defined(__WATCOMC__)  #else /* Compiler test */
365    
366          /*
367               * Ok we know nothing about the compiler, so we fallback to ANSI C
368               * features, so every compiler should be happy and compile the code.
369               *
370               * This is (mostly) equivalent to ARCH_IS_GENERIC.
371               */
372    
373    #    ifdef _DEBUG
374    
375            /* Needed for all debuf fprintf calls */
376  #       include <stdio.h>  #       include <stdio.h>
377  #       include <stdarg.h>  #       include <stdarg.h>
378    
379      static __inline void DPRINTF(int level, char *fmt, ...)          static __inline void DPRINTF(int level, char *format, ...)
380      {      {
                 if (DPRINTF_LEVEL & level) {  
381              va_list args;              va_list args;
382              char buf[DPRINTF_BUF_SZ];              va_start(args, format);
383              va_start(args, fmt);              if(DPRINTF_LEVEL & level) {
384              vsprintf(buf, fmt, args);                     vfprintf(stderr, format, args);
385                          fprintf(stderr, "%s\n", buf);                     fprintf(stderr, "\n");
386                  }                  }
387          }          }
388    
389  #       define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #    else /* _DEBUG */
390                  type name##_storage[(sizex)*(sizey)+(alignment)-1]; \          static __inline void DPRINTF(int level, char *format, ...) {}
391                  type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))  #    endif /* _DEBUG */
392    
393  /*----------------------------------------------------------------------------  #    define BSWAP(a) \
394   | watcom x86 specific macros/functions              ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
395   *---------------------------------------------------------------------------*/                     (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
 #       if defined(ARCH_X86)  
396    
397  #               define BSWAP(a)  __asm mov eax,a __asm bswap eax __asm mov a, eax  #    define EMMS()
398    
399    #    ifdef _PROFILING_
400    #       include <time.h>
401                  static __inline int64_t read_counter(void)                  static __inline int64_t read_counter(void)
402                  {                  {
403                          int64_t ts;              return (int64_t)clock();
                         uint32_t ts1, ts2;  
                         __asm {  
                                 rdtsc  
                                 mov ts1, eax  
                                 mov ts2, edx  
404                          }                          }
                         ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);  
                         return ts;  
                 }  
   
 /*----------------------------------------------------------------------------  
  | watcom unsupported architecture  
  *---------------------------------------------------------------------------*/  
 #       else  
   
 #               define BSWAP(x) \  
                         x = ((((x) & 0xff000000) >> 24) | \  
                                 (((x) & 0x00ff0000) >>  8) | \  
                                 (((x) & 0x0000ff00) <<  8) | \  
                                 (((x) & 0x000000ff) << 24))  
   
                 static int64_t read_counter() { return 0; }  
   
405  #       endif  #       endif
 /*****************************************************************************  
  *  Unknown compiler  
  ****************************************************************************/  
 #else /* Compiler test */  
406    
407  #    error Compiler not supported  #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
408                    type name[(sizex)*(sizey)]
409    
410  #endif /* Compiler test */  #endif /* Compiler test */
411    

Legend:
Removed from v.1.26.2.8  
changed lines
  Added in v.1.42.2.1

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