[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.40, Sat Dec 28 13:53:08 2002 UTC revision 1.46.2.7, Thu May 22 16:35:03 2003 UTC
# 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 63  Line 34 
34   *  Common things   *  Common things
35   ****************************************************************************/   ****************************************************************************/
36    
37  /* Debug level masks */  /* Buffer size for msvc implementation because it outputs to DebugOutput */
38  #define DPRINTF_ERROR           0x00000001  #if defined(_DEBUG)
39  #define DPRINTF_STARTCODE       0x00000002  extern unsigned int xvid_debug;
 #define DPRINTF_HEADER          0x00000004  
 #define DPRINTF_TIMECODE        0x00000008  
 #define DPRINTF_MB                      0x00000010  
 #define DPRINTF_COEFF           0x00000020  
 #define DPRINTF_MV                      0x00000040  
 #define DPRINTF_DEBUG           0x80000000  
   
 /* debug level for this library */  
 #define DPRINTF_LEVEL           0  
   
 /* Buffer size for non C99 compliant compilers (msvc) */  
40  #define DPRINTF_BUF_SZ  1024  #define DPRINTF_BUF_SZ  1024
41    #endif
42    
43  /*****************************************************************************  /*****************************************************************************
44   *  Types used in XviD sources   *  Types used in XviD sources
45   ****************************************************************************/   ****************************************************************************/
46    
47  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
48   | 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)  
49   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
50    
51  #elif defined(_MSC_VER)  #if defined(_MSC_VER) || defined (__WATCOMC__)
52  #    define int8_t   char  #    define int8_t   char
53  #    define uint8_t  unsigned char  #    define uint8_t  unsigned char
54  #    define int16_t  short  #    define int16_t  short
# Line 107  Line 59 
59  #    define uint64_t unsigned __int64  #    define uint64_t unsigned __int64
60    
61  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
62   | Fallback when using gcc   | For all other compilers, use the standard header file
63     | (compiler should be ISO C99 compatible, perhaps ISO C89 is enough)
64   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
65    
66  #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  
67    
68  /*----------------------------------------------------------------------------  #    include <inttypes.h>
  | Ok, we don't know how to define these types... error  
  *---------------------------------------------------------------------------*/  
69    
 #else  
 #    error Do not know how to define (u)int(size)_t types  
70  #endif  #endif
71    
72  /*****************************************************************************  /*****************************************************************************
73   *  Some things that are only architecture dependant   *  Some things that are only architecture dependant
74   ****************************************************************************/   ****************************************************************************/
75    
76  #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS)  || defined(ARCH_SPARC)  #if defined(ARCH_IS_32BIT)
77  #    define CACHE_LINE  16  #    define CACHE_LINE 64
78  #    define ptr_t uint32_t  #    define ptr_t uint32_t
79  #elif defined(ARCH_IA64)  #    define intptr_t int32_t
80  #    define CACHE_LINE  32  #    if _MSC_VER < 1300
81    #        define uintptr_t uint32_t
82    #    else
83    #        include <stdarg.h>
84    #    endif
85    #elif defined(ARCH_IS_64BIT)
86    #    define CACHE_LINE  64
87  #    define ptr_t uint64_t  #    define ptr_t uint64_t
88    #    define intptr_t int64_t
89    #    if _MSC_VER < 1300
90    #        define uintptr_t uint64_t
91  #else  #else
92  /* todo: fix cache_line 0 operation */  #        include <stdarg.h>
93  #    define CACHE_LINE  16  #    endif
94  #    define ptr_t uint32_t  #else
95    #    error You are trying to compile XviD without defining address bus size.
96  #endif  #endif
97    
98  /*****************************************************************************  /*****************************************************************************
# Line 162  Line 112 
112  #include <windows.h>  #include <windows.h>
113  #include <stdio.h>  #include <stdio.h>
114    
115         /* Non ANSI mapping */
116    #    define snprintf _snprintf
117    #    define vsnprintf _vsnprintf
118    
119      /*      /*
120       * This function must be declared/defined all the time because MSVC does       * This function must be declared/defined all the time because MSVC does
121       * not support C99 variable arguments macros       * not support C99 variable arguments macros.
122         *
123         * Btw, if the MS compiler does its job well, it should remove the nop
124         * DPRINTF function when not compiling in _DEBUG mode
125       */       */
126    #   ifdef _DEBUG
127      static __inline void DPRINTF(int level, char *fmt, ...)      static __inline void DPRINTF(int level, char *fmt, ...)
128      {      {
129          if (DPRINTF_LEVEL & level) {          if (xvid_debug & level) {
130              va_list args;              va_list args;
131              char buf[DPRINTF_BUF_SZ];              char buf[DPRINTF_BUF_SZ];
132              va_start(args, fmt);              va_start(args, fmt);
133              vsprintf(buf, fmt, args);              vsprintf(buf, fmt, args);
134              OutputDebugString(buf);              OutputDebugString(buf);
135              fprintf(stderr, "%s\n", buf);              fprintf(stderr, "%s", buf);
136           }           }
137       }       }
138    #    else
139             static __inline void DPRINTF(int level, char *fmt, ...) {}
140    #    endif
141    
142  #    if _MSC_VER <= 1200  #    if _MSC_VER <= 1200
143  #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
# Line 191  Line 152 
152  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
153   | msvc x86 specific macros/functions   | msvc x86 specific macros/functions
154   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
155  #    if defined(ARCH_X86)  #    if defined(ARCH_IS_IA32)
156  #        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
 #        define EMMS() __asm {emms}  
157    
158               static __inline int64_t read_counter(void)               static __inline int64_t read_counter(void)
159               {               {
# Line 209  Line 169 
169               }               }
170    
171  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
172   | msvc unknown architecture   | msvc GENERIC (plain C only) - Probably alpha or some embedded device
173   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
174  #    else  #    elif defined(ARCH_IS_GENERIC)
175  /* ANSI C version of BSWAP */  #        define BSWAP(a) \
176  #define BSWAP(x) \                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
177   x = ((((x) & 0xff000000) >> 24) | \                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
178       (((x) & 0x00ff0000) >>  8) | \  
179       (((x) & 0x0000ff00) <<  8) | \  #        include <time.h>
180       (((x) & 0x000000ff) << 24))           static __inline int64_t read_counter(void)
181             {
182                 return (int64_t)clock();
183             }
184    
185  #define EMMS()  /*----------------------------------------------------------------------------
186     | msvc Not given architecture - This is probably an user who tries to build
187     | XviD the wrong way.
188     *---------------------------------------------------------------------------*/
189    #    else
190    #        error You are trying to compile XviD without defining the architecture type.
191  #    endif  #    endif
192    
193    
# Line 243  Line 211 
211    
212          /* Needed for all debuf fprintf calls */          /* Needed for all debuf fprintf calls */
213  #       include <stdio.h>  #       include <stdio.h>
214    #       include <stdarg.h>
215    
216  #       define DPRINTF(level, format, ...) \          static __inline void DPRINTF(int level, char *format, ...)
217              do {\          {
218                  if(DPRINTF_LEVEL & level)\              va_list args;
219                      fprintf(stderr, format"\n", ##__VA_ARGS__);\              va_start(args, format);
220              }while(0);              if(xvid_debug & level) {
221                       vfprintf(stderr, format, args);
222                }
223            }
224    
225  #    else /* _DEBUG */  #    else /* _DEBUG */
226  #        define DPRINTF(level, format, ...)          static __inline void DPRINTF(int level, char *format, ...) {}
227  #    endif /* _DEBUG */  #    endif /* _DEBUG */
228    
229    
   
230  #    define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #    define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
231              type name##_storage[(sizex)*(sizey)+(alignment)-1]; \              type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
232              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))
233    
234  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
235   | gcc x86 specific macros/functions   | gcc IA32 specific macros/functions
236   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
237  #    if defined(ARCH_X86)  #    if defined(ARCH_IS_IA32)
238  #        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");  
239    
240           static __inline int64_t read_counter(void)           static __inline int64_t read_counter(void)
241           {           {
# Line 279  Line 249 
249  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
250   | gcc PPC and PPC Altivec specific macros/functions   | gcc PPC and PPC Altivec specific macros/functions
251   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
252  #    elif defined(ARCH_PPC)  #    elif defined(ARCH_IS_PPC)
253  #        define BSWAP(a) __asm__ __volatile__ \  #        define BSWAP(a) __asm__ __volatile__ \
254                  ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));                  ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
 #        define EMMS()  
255    
256           static __inline unsigned long get_tbl(void)           static __inline unsigned long get_tbl(void)
257           {           {
# Line 311  Line 280 
280  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
281   | gcc IA64 specific macros/functions   | gcc IA64 specific macros/functions
282   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
283  #    elif defined(ARCH_IA64)  #    elif defined(ARCH_IS_IA64)
284  #        define BSWAP(a)  __asm__ __volatile__ \  #        define BSWAP(a)  __asm__ __volatile__ \
285                  ("mux1 %1 = %0, @rev" ";;" \                  ("mux1 %1 = %0, @rev" ";;" \
286                   "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));                   "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
 #        define EMMS()  
287    
288           static __inline int64_t read_counter(void) {           static __inline int64_t read_counter(void)
289             {
290               unsigned long result;               unsigned long result;
291               __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");               __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
292               return result;               return result;
293           }           }
294    
295  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
296   | gcc SPARC specific macros/functions   | gcc GENERIC (plain C only) specific macros/functions
297   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
298  #    elif defined(ARCH_SPARC)  #    elif defined(ARCH_IS_GENERIC)
299  #        define BSWAP(a) \  #        define BSWAP(a) \
300                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
301                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
 #        define EMMS()  
302    
303    #        include <time.h>
304           static __inline int64_t read_counter(void)           static __inline int64_t read_counter(void)
305           {           {
306               return 0;               return (int64_t)clock();
307           }           }
308    
309  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
310   | gcc MIPS specific macros/functions   | gcc Not given architecture - This is probably an user who tries to build
311     | XviD the wrong way.
312   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
313  #    elif defined(ARCH_MIPS)  #    else
314  #        define BSWAP(a) \  #        error You are trying to compile XviD without defining the architecture type.
315                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \  #    endif
316                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))  
317  #        define EMMS()  
318    
319    
320    /*****************************************************************************
321     *  Open WATCOM C/C++ compiler
322     ****************************************************************************/
323    
324    #elif defined(__WATCOMC__)
325    
326    #    include <stdio.h>
327    #    include <stdarg.h>
328    
329    #    ifdef _DEBUG
330         static __inline void DPRINTF(int level, char *fmt, ...)
331         {
332             if (xvid_debug & level) {
333                 va_list args;
334                 char buf[DPRINTF_BUF_SZ];
335                 va_start(args, fmt);
336                 vsprintf(buf, fmt, args);
337                 fprintf(stderr, "%s", buf);
338             }
339         }
340    #    else /* _DEBUG */
341             static __inline void DPRINTF(int level, char *format, ...) {}
342    #    endif /* _DEBUG */
343    
344    #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
345                    type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
346                    type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
347    
348    /*----------------------------------------------------------------------------
349     | watcom ia32 specific macros/functions
350     *---------------------------------------------------------------------------*/
351    #    if defined(ARCH_IS_IA32)
352    
353    #        define BSWAP(a)  __asm mov eax,a __asm bswap eax __asm mov a, eax
354    
355           static __inline int64_t read_counter(void)           static __inline int64_t read_counter(void)
356           {           {
357               return 0;               uint64_t ts;
358                 uint32_t ts1, ts2;
359                 __asm {
360                     rdtsc
361                     mov ts1, eax
362                     mov ts2, edx
363                 }
364                 ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
365                 return ts;
366           }           }
367    
368  /*----------------------------------------------------------------------------  /*----------------------------------------------------------------------------
369   | XviD + gcc unsupported Architecture   | watcom GENERIC (plain C only) specific macros/functions.
370   *---------------------------------------------------------------------------*/   *---------------------------------------------------------------------------*/
371  #    else  #    elif defined(ARCH_IS_GENERIC)
372  /* ANSI C version of BSWAP */  
373  #define BSWAP(x) \  #define BSWAP(x) \
374   x = ((((x) & 0xff000000) >> 24) | \   x = ((((x) & 0xff000000) >> 24) | \
375       (((x) & 0x00ff0000) >>  8) | \       (((x) & 0x00ff0000) >>  8) | \
376       (((x) & 0x0000ff00) <<  8) | \       (((x) & 0x0000ff00) <<  8) | \
377       (((x) & 0x000000ff) << 24))       (((x) & 0x000000ff) << 24))
378    
379  #define EMMS()           static int64_t read_counter() { return 0; }
380  #    endif /* Architecture checking */  
381    /*----------------------------------------------------------------------------
382     | watcom Not given architecture - This is probably an user who tries to build
383     | XviD the wrong way.
384     *---------------------------------------------------------------------------*/
385    #    else
386    #        error You are trying to compile XviD without defining the architecture type.
387    #    endif
388    
389    
390  /*****************************************************************************  /*****************************************************************************
391   *  Unknown compiler   *  Unknown compiler
392   ****************************************************************************/   ****************************************************************************/
393  #else /* Compiler test */  #else /* Compiler test */
394    
395  #    error Compiler not supported        /*
396           * Ok we know nothing about the compiler, so we fallback to ANSI C
397           * features, so every compiler should be happy and compile the code.
398           *
399           * This is (mostly) equivalent to ARCH_IS_GENERIC.
400           */
401    
402    #    ifdef _DEBUG
403    
404            /* Needed for all debuf fprintf calls */
405    #       include <stdio.h>
406    #       include <stdarg.h>
407    
408            static __inline void DPRINTF(int level, char *format, ...)
409            {
410                va_list args;
411                va_start(args, format);
412                if(xvid_debug & level) {
413                       vfprintf(stderr, format, args);
414                }
415            }
416    
417    #    else /* _DEBUG */
418            static __inline void DPRINTF(int level, char *format, ...) {}
419    #    endif /* _DEBUG */
420    
421    #    define BSWAP(a) \
422                ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
423                       (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
424    
425    #    include <time.h>
426         static __inline int64_t read_counter(void)
427         {
428             return (int64_t)clock();
429         }
430    
431    #    define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
432                    type name[(sizex)*(sizey)]
433    
434  #endif /* Compiler test */  #endif /* Compiler test */
435    
436    
437  #endif  #endif /* PORTAB_H */

Legend:
Removed from v.1.40  
changed lines
  Added in v.1.46.2.7

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