[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.7, Sun Jan 26 05:09:00 2003 UTC revision 1.48, Fri Mar 28 07:28:23 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 23  Line 23 
23   *  along with this program; if not, write to the Free Software   *  along with this program; if not, write to the Free Software
24   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
25   *   *
  *  Under section 8 of the GNU General Public License, the copyright  
  *  holders of XVID explicitly forbid distribution in the following  
  *  countries:  
  *  
  *    - Japan  
  *    - United States of America  
  *  
  *  Linking XviD statically or dynamically with other modules is making a  
  *  combined work based on XviD.  Thus, the terms and conditions of the  
  *  GNU General Public License cover the whole combination.  
  *  
  *  As a special exception, the copyright holders of XviD give you  
  *  permission to link XviD with independent modules that communicate with  
  *  XviD solely through the VFW1.1 and DShow interfaces, regardless of the  
  *  license terms of these independent modules, and to copy and distribute  
  *  the resulting combined work under terms of your choice, provided that  
  *  every copy of the combined work is accompanied by a complete copy of  
  *  the source code of XviD (the version of XviD used to produce the  
  *  combined work), being distributed under the terms of the GNU General  
  *  Public License plus this exception.  An independent module is a module  
  *  which is not derived from or based on XviD.  
  *  
  *  Note that people who make modified versions of XviD are not obligated  
  *  to grant this special exception for their modified versions; it is  
  *  their choice whether to do so.  The GNU General Public License gives  
  *  permission to release a modified version without this exception; this  
  *  exception also makes it possible to release a modified version which  
  *  carries forward this exception.  
  *  
26   * $Id$   * $Id$
27   *   *
28   ****************************************************************************/   ****************************************************************************/
# Line 76  Line 47 
47    
48  /* debug level for this library */  /* debug level for this library */
49  #ifdef _DEBUG  #ifdef _DEBUG
50  #define DPRINTF_LEVEL           (DPRINTF_RC|0x0000007F)  #define DPRINTF_LEVEL       0x000000ff
51  #else  #else
52  #define DPRINTF_LEVEL           DPRINTF_RC  #define DPRINTF_LEVEL       0
53  #endif  #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 89  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 112  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__) || 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  
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)  || defined(ARCH_SPARC)  #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)  #    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  #else
107  /* todo: fix cache_line 0 operation */  #        include <stdarg.h>
108  #    define CACHE_LINE  16  #    endif
109  #    define ptr_t uint32_t  #else
110    #    error You are trying to compile XviD without defining address bus size.
111  #endif  #endif
112    
113  /*****************************************************************************  /*****************************************************************************
# Line 167  Line 127 
127  #include <windows.h>  #include <windows.h>
128  #include <stdio.h>  #include <stdio.h>
129    
130          /* non-ansi function mapping */       /* Non ANSI mapping */
131  #       define snprintf _snprintf  #       define snprintf _snprintf
132  #       define vsnprintf _vsnprintf  #       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 186  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 200  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) __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               static __inline int64_t read_counter(void)               static __inline int64_t read_counter(void)
# Line 217  Line 184 
184               }               }
185    
186  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
187   | msvc unknown architecture   | msvc GENERIC (plain C only) - Probably alpha or some embedded device
188   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
189  #    else  #    elif defined(ARCH_IS_GENERIC)
190  /* ANSI C version of BSWAP */  #        define BSWAP(a) \
191  #define BSWAP(x) \                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
192   x = ((((x) & 0xff000000) >> 24) | \                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
      (((x) & 0x00ff0000) >>  8) | \  
      (((x) & 0x0000ff00) <<  8) | \  
      (((x) & 0x000000ff) << 24))  
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
205    #        error You are trying to compile XviD without defining the architecture type.
206  #    endif  #    endif
207    
208    
# Line 250  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    
   
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))
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) );
255    
256           static __inline int64_t read_counter(void)           static __inline int64_t read_counter(void)
# Line 285  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));
271    
# Line 316  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));
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))
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    
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  #    else  #    elif defined(ARCH_IS_GENERIC)
388  /* ANSI C version of BSWAP */  
389  #define BSWAP(x) \  #define BSWAP(x) \
390   x = ((((x) & 0xff000000) >> 24) | \   x = ((((x) & 0xff000000) >> 24) | \
391       (((x) & 0x00ff0000) >>  8) | \       (((x) & 0x00ff0000) >>  8) | \
392       (((x) & 0x0000ff00) <<  8) | \       (((x) & 0x0000ff00) <<  8) | \
393       (((x) & 0x000000ff) << 24))       (((x) & 0x000000ff) << 24))
394    
395  #    endif /* Architecture checking */           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
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.26.2.7  
changed lines
  Added in v.1.48

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