[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.28, Sun Sep 22 16:59:57 2002 UTC revision 1.48, Fri Mar 28 07:28:23 2003 UTC
# Line 3  Line 3 
3   *  XVID MPEG-4 VIDEO CODEC   *  XVID MPEG-4 VIDEO CODEC
4   *  - Portable macros, types and inlined assembly -   *  - Portable macros, types and inlined assembly -
5   *   *
6   *  Copyright(C) 2002 Michael Militzer   *  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 program is an implementation of a part of one or more MPEG-4   *  This file is part of XviD, a free MPEG-4 video encoder/decoder
  *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending  
  *  to use this software module in hardware or software products are  
  *  advised that its use may infringe existing patents or copyrights, and  
  *  any such use would be at such party's own risk.  The original  
  *  developer of this software module and his/her company, and subsequent  
  *  editors and their companies, will have no liability for use of this  
  *  software or modifications or derivatives thereof.  
11   *   *
12   *  This program is free software ; you can redistribute it and/or modify   *  XviD is free software; you can redistribute it and/or modify it
13   *  it under the terms of the GNU General Public License as published by   *  under the terms of the GNU General Public License as published by
14   *  the Free Software Foundation ; either version 2 of the License, or   *  the Free Software Foundation ; either version 2 of the License, or
15   *  (at your option) any later version.   *  (at your option) any later version.
16   *   *
# Line 47  Line 42 
42  #define DPRINTF_MB                      0x00000010  #define DPRINTF_MB                      0x00000010
43  #define DPRINTF_COEFF           0x00000020  #define DPRINTF_COEFF           0x00000020
44  #define DPRINTF_MV                      0x00000040  #define DPRINTF_MV                      0x00000040
45    #define DPRINTF_RC          0x00000080
46  #define DPRINTF_DEBUG           0x80000000  #define DPRINTF_DEBUG           0x80000000
47    
48  /* debug level for this library */  /* debug level for this library */
49    #ifdef _DEBUG
50    #define DPRINTF_LEVEL       0x000000ff
51    #else
52  #define DPRINTF_LEVEL           0  #define DPRINTF_LEVEL           0
53    #endif
54    
55  /* Buffer size for non C99 compliant compilers (msvc) */  /* Buffer size for msvc implementation because it outputs to DebugOutput */
56  #define DPRINTF_BUF_SZ  1024  #define DPRINTF_BUF_SZ  1024
57    
58  /*****************************************************************************  /*****************************************************************************
# Line 60  Line 60 
60   ****************************************************************************/   ****************************************************************************/
61    
62  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
63   | Standard Unix include file (sorry, we put all unix into "linux" case)   | For MSVC
  *---------------------------------------------------------------------------*/  
   
 #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)  
   
 /* All (u)int(size)_t types are defined here */  
 #    include <inttypes.h>  
   
 /*----------------------------------------------------------------------------  
  | msvc (lacks such a header file)  
64   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
65    
66  #elif defined(_MSC_VER)  #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 83  Line 74 
74  #    define uint64_t unsigned __int64  #    define uint64_t unsigned __int64
75    
76  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
77   | Fallback when using gcc   | For all other compilers, use the standard header file
78     | (compiler should be ISO C99 compatible, perhaps ISO C89 is enough)
79   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
80    
81  #elif defined(__GNUC__)  #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  
82    
83  /*----------------------------------------------------------------------------  #    include <inttypes.h>
  | Ok, we don't know how to define these types... error  
  *---------------------------------------------------------------------------*/  
84    
 #else  
 #    error Do not know how to define (u)int(size)_t types  
85  #endif  #endif
86    
87  /*****************************************************************************  /*****************************************************************************
88   *  Some things that are only architecture dependant   *  Some things that are only architecture dependant
89   ****************************************************************************/   ****************************************************************************/
90    
91  #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS)  #if defined(ARCH_IS_32BIT)
92  #    define CACHE_LINE  16  #    define CACHE_LINE 64
93  #    define ptr_t uint32_t  #    define ptr_t uint32_t
94  #elif defined(ARCH_IA64) || defined(ARCH_SPARC)  #    define intptr_t int32_t
95  #    define CACHE_LINE  32  #    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  #    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  #else
110  #    error Architecture not supported.  #    error You are trying to compile XviD without defining address bus size.
111  #endif  #endif
112    
113  /*****************************************************************************  /*****************************************************************************
# Line 136  Line 127 
127  #include <windows.h>  #include <windows.h>
128  #include <stdio.h>  #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       * This function must be declared/defined all the time because MSVC does
136       * not support C99 variable arguments macros       * 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, ...)      static __inline void DPRINTF(int level, char *fmt, ...)
143      {      {
144          if (DPRINTF_LEVEL & level) {          if (DPRINTF_LEVEL & level) {
# Line 151  Line 150 
150              fprintf(stderr, "%s\n", buf);              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  #    if _MSC_VER <= 1200
158  #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
# Line 165  Line 167 
167  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
168   | msvc x86 specific macros/functions   | msvc x86 specific macros/functions
169   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
170  #    if defined(ARCH_X86)  #    if defined(ARCH_IS_IA32)
171  #        define BSWAP(a)  #        define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax
              __asm { \  
                  mov eax,a \  
                  bswap eax \  
                  mov a, eax \  
              }  
 #        define EMMS() __asm {emms}  
172    
173               static __inline int64_t read_counter(void)               static __inline int64_t read_counter(void)
174               {               {
# Line 188  Line 184 
184               }               }
185    
186  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
187   | msvc unknown architecture   | 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    /*----------------------------------------------------------------------------
201     | msvc Not given architecture - This is probably an user who tries to build
202     | XviD the wrong way.
203   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
204  #    else  #    else
205  #        error Architecture not supported.  #        error You are trying to compile XviD without defining the architecture type.
206  #    endif  #    endif
207    
208    
# Line 201  Line 212 
212   *  GNU CC compiler stuff   *  GNU CC compiler stuff
213   ****************************************************************************/   ****************************************************************************/
214    
215  #elif defined(__GNUC__) /* Compiler test */  #elif defined(__GNUC__) || defined(__ICC) /* Compiler test */
216    
217  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
218   | Common gcc stuff   | Common gcc stuff
# Line 215  Line 226 
226    
227          /* Needed for all debuf fprintf calls */          /* Needed for all debuf fprintf calls */
228  #       include <stdio.h>  #       include <stdio.h>
229    #       include <stdarg.h>
230    
231  #       define DPRINTF(level, format, ...) \          static __inline void DPRINTF(int level, char *format, ...)
232              do {\          {
233                  if(DPRINTF_LEVEL & level)\              va_list args;
234                      fprintf(stderr, format"\n", ##__VA_ARGS__);\              va_start(args, format);
235              }while(0);              if(DPRINTF_LEVEL & level) {
236                       vfprintf(stderr, format, args);
237                       fprintf(stderr, "\n");
238                }
239            }
240    
241  #    else /* _DEBUG */  #    else /* _DEBUG */
242  #        define DPRINTF(level, format, ...)          static __inline void DPRINTF(int level, char *format, ...) {}
243  #    endif /* _DEBUG */  #    endif /* _DEBUG */
244    
245    
 #    ifdef _DEBUG  
246  #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
247                  type name##_storage[(sizex)*(sizey)+(alignment)-1]; \                  type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
248                  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))
 #    else  
 #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  
                 __attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)]  
 #    endif  
249    
250  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
251   | gcc x86 specific macros/functions   | gcc IA32 specific macros/functions
252   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
253  #    if defined(ARCH_X86)  #    if defined(ARCH_IS_IA32)
254  #        define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );  #        define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
 #        define EMMS() __asm__ ("emms\n\t");  
255    
256           static __inline int64_t read_counter(void)           static __inline int64_t read_counter(void)
257           {           {
# Line 255  Line 265 
265  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
266   | gcc PPC and PPC Altivec specific macros/functions   | gcc PPC and PPC Altivec specific macros/functions
267   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
268  #    elif defined(ARCH_PPC)  #    elif defined(ARCH_IS_PPC)
269  #        define BSWAP(a) __asm__ __volatile__ \  #        define BSWAP(a) __asm__ __volatile__ \
270                  ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));                  ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
 #        define EMMS()  
271    
272           static __inline unsigned long get_tbl(void)           static __inline unsigned long get_tbl(void)
273           {           {
# Line 287  Line 296 
296  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
297   | gcc IA64 specific macros/functions   | gcc IA64 specific macros/functions
298   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
299  #    elif defined(ARCH_IA64)  #    elif defined(ARCH_IS_IA64)
300  #        define BSWAP(a)  __asm__ __volatile__ \  #        define BSWAP(a)  __asm__ __volatile__ \
301                  ("mux1 %1 = %0, @rev" ";;" \                  ("mux1 %1 = %0, @rev" ";;" \
302                   "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));                   "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
 #        define EMMS()  
303    
304           static __inline int64_t read_counter(void) {           static __inline int64_t read_counter(void)
305             {
306               unsigned long result;               unsigned long result;
307               __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");               __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
308               return result;               return result;
309           }           }
310    
311  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
312   | gcc SPARC specific macros/functions   | gcc GENERIC (plain C only) specific macros/functions
313   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
314  #    elif defined(ARCH_SPARC)  #    elif defined(ARCH_IS_GENERIC)
315  #        define BSWAP(a) \  #        define BSWAP(a) \
316                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) |                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
317                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
 #        define EMMS()  
318    
319    #        include <time.h>
320           static __inline int64_t read_counter(void)           static __inline int64_t read_counter(void)
321           {           {
322               return 0;               return (int64_t)clock();
323           }           }
324    
325  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
326   | gcc MIPS specific macros/functions   | gcc Not given architecture - This is probably an user who tries to build
327     | XviD the wrong way.
328   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
329  #    elif defined(ARCH_MIPS)  #    else
330  #        define BSWAP(a) \  #        error You are trying to compile XviD without defining the architecture type.
331                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) |  #    endif
332                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))  
333  #        define EMMS()  
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           static __inline int64_t read_counter(void)           static __inline int64_t read_counter(void)
372           {           {
373               return 0;               uint64_t ts;
374                 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   | XviD + gcc unsupported Architecture   | 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  #    else
402  #        error Architecture not supported.  #        error You are trying to compile XviD without defining the architecture type.
403  #    endif /* Architecture checking */  #    endif
404    
405    
406  /*****************************************************************************  /*****************************************************************************
407   *  Unknown compiler   *  Unknown compiler
408   ****************************************************************************/   ****************************************************************************/
409  #else /* Compiler test */  #else /* Compiler test */
410    
411  #    error Compiler not supported        /*
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 */  #endif /* Compiler test */
452    
453    
454  #endif  #endif /* PORTAB_H */

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

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