[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.27, Wed Sep 4 22:01:59 2002 UTC revision 1.28, Sun Sep 22 16:59:57 2002 UTC
# Line 35  Line 35 
35  #ifndef _PORTAB_H_  #ifndef _PORTAB_H_
36  #define _PORTAB_H_  #define _PORTAB_H_
37    
38    /*****************************************************************************
39     *  Common things
40     ****************************************************************************/
41    
42  // debug level masks  /* Debug level masks */
43  #define DPRINTF_ERROR           0x00000001  #define DPRINTF_ERROR           0x00000001
44  #define DPRINTF_STARTCODE       0x00000002  #define DPRINTF_STARTCODE       0x00000002
45  #define DPRINTF_HEADER          0x00000004  #define DPRINTF_HEADER          0x00000004
# Line 46  Line 49 
49  #define DPRINTF_MV                      0x00000040  #define DPRINTF_MV                      0x00000040
50  #define DPRINTF_DEBUG           0x80000000  #define DPRINTF_DEBUG           0x80000000
51    
52  // debug level  /* debug level for this library */
53  #define DPRINTF_LEVEL           0  #define DPRINTF_LEVEL           0
54    
55    /* Buffer size for non C99 compliant compilers (msvc) */
56  #define DPRINTF_BUF_SZ  1024  #define DPRINTF_BUF_SZ  1024
57    
58    /*****************************************************************************
59     *  Types used in XviD sources
60     ****************************************************************************/
61    
62  #if defined(WIN32)  /*----------------------------------------------------------------------------
63     | Standard Unix include file (sorry, we put all unix into "linux" case)
64     *---------------------------------------------------------------------------*/
65    
66  #include <windows.h>  #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)
 #include <stdio.h>  
67    
68  static __inline void  /* All (u)int(size)_t types are defined here */
69  DPRINTF(int level, char *fmt,  #    include <inttypes.h>
                 ...)  
 {  
         if ((DPRINTF_LEVEL & level))  
         {  
                 va_list args;  
                 char buf[DPRINTF_BUF_SZ];  
70    
71                  va_start(args, fmt);  /*----------------------------------------------------------------------------
72                  vsprintf(buf, fmt, args);   | msvc (lacks such a header file)
73                  OutputDebugString(buf);   *---------------------------------------------------------------------------*/
                 fprintf(stdout, "%s\n", buf);  
                 fflush(stdout);  
         }  
 }  
74    
75    #elif defined(_MSC_VER)
76    #    define int8_t   char
77    #    define uint8_t  unsigned char
78    #    define int16_t  short
79    #    define uint16_t unsigned short
80    #    define int32_t  int
81    #    define uint32_t unsigned int
82    #    define int64_t  __int64
83    #    define uint64_t unsigned __int64
84    
85  #define DEBUGCBR(A,B,C) { char tmp[100]; wsprintf(tmp, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C)); OutputDebugString(tmp); }  /*----------------------------------------------------------------------------
86     | Fallback when using gcc
87  #ifdef _DEBUG   *---------------------------------------------------------------------------*/
 #define DEBUG(S) OutputDebugString((S));  
 #define DEBUG1(S,I) { char tmp[100]; wsprintf(tmp, "%s %i\n", (S), (I)); OutputDebugString(tmp); }  
 #define DEBUG2(X,A,B) { char tmp[100]; wsprintf(tmp, "%s %i %i\n", (X), (A), (B)); OutputDebugString(tmp); }  
 #define DEBUG3(X,A,B,C){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i",(X),(A), (B), (C)); OutputDebugString(tmp); }  
 #define DEBUG4(X,A,B,C,D){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i %i",(X),(A), (B), (C), (D)); OutputDebugString(tmp); }  
 #define DEBUG8(X,A,B,C,D,E,F,G,H){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i %i %i %i %i %i",(X),(A),(B),(C),(D),(E),(F),(G),(H)); OutputDebugString(tmp); }  
 #else  
 #define DEBUG(S)  
 #define DEBUG1(S,I)  
 #define DEBUG2(X,A,B)  
 #define DEBUG3(X,A,B,C)  
 #define DEBUG4(X,A,B,C,D)  
 #define DEBUG8(X,A,B,C,D,E,F,G,H)  
 #endif  
88    
89    #elif defined(__GNUC__)
90    
91  #define int8_t char  #define int8_t char
92  #define uint8_t unsigned char  #define uint8_t unsigned char
# Line 101  Line 94 
94  #define uint16_t unsigned short  #define uint16_t unsigned short
95  #define int32_t int  #define int32_t int
96  #define uint32_t unsigned int  #define uint32_t unsigned int
97  #define int64_t __int64  #    define int64_t  long long
98  #define uint64_t unsigned __int64  #    define uint64_t unsigned long long
 #define ptr_t uint32_t  
99    
100  #define EMMS() __asm {emms}  /*----------------------------------------------------------------------------
101     | Ok, we don't know how to define these types... error
102     *---------------------------------------------------------------------------*/
103    
104    #else
105    #    error Do not know how to define (u)int(size)_t types
106    #endif
107    
108    /*****************************************************************************
109     *  Some things that are only architecture dependant
110     ****************************************************************************/
111    
112    #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS)
113  #define CACHE_LINE  16  #define CACHE_LINE  16
114    #    define ptr_t uint32_t
115    #elif defined(ARCH_IA64) || defined(ARCH_SPARC)
116    #    define CACHE_LINE  32
117    #    define ptr_t uint64_t
118    #else
119    #    error Architecture not supported.
120    #endif
121    
122    /*****************************************************************************
123     *  Things that must be sorted by compiler and then by architecture
124     ****************************************************************************/
125    
126    /*****************************************************************************
127     *  MSVC compiler specific macros, functions
128     ****************************************************************************/
129    
130    #if defined(_MSC_VER)
131    
132    /*----------------------------------------------------------------------------
133     | Common msvc stuff
134     *---------------------------------------------------------------------------*/
135    
136    #include <windows.h>
137    #include <stdio.h>
138    
139        /*
140         * This function must be declared/defined all the time because MSVC does
141         * not support C99 variable arguments macros
142         */
143        static __inline void DPRINTF(int level, char *fmt, ...)
144        {
145            if (DPRINTF_LEVEL & level) {
146                va_list args;
147                char buf[DPRINTF_BUF_SZ];
148                va_start(args, fmt);
149                vsprintf(buf, fmt, args);
150                OutputDebugString(buf);
151                fprintf(stderr, "%s\n", buf);
152             }
153         }
154    
155  #if _MSC_VER <= 1200  #if _MSC_VER <= 1200
156  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
# Line 118  Line 161 
161          __declspec(align(alignment)) type name[(sizex)*(sizey)]          __declspec(align(alignment)) type name[(sizex)*(sizey)]
162  #endif  #endif
163    
 // needed for bitstream.h  
 #define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax  
164    
165  // needed for timer.c  /*----------------------------------------------------------------------------
166  static __inline int64_t   | msvc x86 specific macros/functions
167  read_counter()   *---------------------------------------------------------------------------*/
168    #    if defined(ARCH_X86)
169    #        define BSWAP(a)
170                 __asm { \
171                     mov eax,a \
172                     bswap eax \
173                     mov a, eax \
174                 }
175    #        define EMMS() __asm {emms}
176    
177                 static __inline int64_t read_counter(void)
178  {  {
179          int64_t ts;          int64_t ts;
180          uint32_t ts1, ts2;          uint32_t ts1, ts2;
   
181          __asm {          __asm {
182                  rdtsc                  rdtsc
183                  mov ts1, eax                  mov ts1, eax
184                  mov ts2, edx                  mov ts2, edx
185          }          }
   
186          ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);          ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
   
187          return ts;          return ts;
188  }  }
189    
190  #elif defined(LINUX) || defined(DJGPP) || defined(FREEBSD) || defined(BEOS)  /*----------------------------------------------------------------------------
191     | msvc unknown architecture
192     *---------------------------------------------------------------------------*/
193    #    else
194    #        error Architecture not supported.
195    #    endif
196    
 #include <stdio.h>  
 #include <stdarg.h>  
197    
 static __inline void  
 DPRINTF(int level, char *fmt,  
                 ...)  
 {  
         if ((DPRINTF_LEVEL & level)) {  
                 va_list args;  
                 char buf[DPRINTF_BUF_SZ];  
198    
                 va_start(args, fmt);  
                 vsprintf(buf, fmt, args);  
                 fprintf(stdout, "%s\n", buf);  
         }  
 }  
199    
200    /*****************************************************************************
201     *  GNU CC compiler stuff
202     ****************************************************************************/
203    
204    #elif defined(__GNUC__) /* Compiler test */
205    
206    /*----------------------------------------------------------------------------
207     | Common gcc stuff
208     *---------------------------------------------------------------------------*/
209    
210    /*
211     * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
212     * and it's a macro calling fprintf directly
213     */
214  #ifdef _DEBUG  #ifdef _DEBUG
215    
216            /* Needed for all debuf fprintf calls */
217  #include <stdio.h>  #include <stdio.h>
 #define DEBUG_WHERE               stdout  
 #define DEBUG(S)                  fprintf(DEBUG_WHERE, "%s\n", (S));  
 #define DEBUG1(S,I)               fprintf(DEBUG_WHERE, "%s %i\n", (S), (I))  
 #define DEBUG2(S,A,B)             fprintf(DEBUG_WHERE, "%s%i=%i\n", (S), (A), (B))  
 #define DEBUG3(S,A,B,C)           fprintf(DEBUG_WHERE, "%s %i %x %x\n", (S), (A), (B), (C))  
 #define DEBUG8(S,A,B,C,D,E,F,G,H)  
 #define DEBUGCBR(A,B,C)           fprintf(DEBUG_WHERE, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C))  
 #else  
 #define DEBUG(S)  
 #define DEBUG1(S,I)  
 #define DEBUG2(X,A,B)  
 #define DEBUG3(X,A,B,C)  
 #define DEBUG8(X,A,B,C,D,E,F,G,H)  
 #define DEBUGCBR(A,B,C)  
 #endif  
218    
219  #if defined(LINUX) || defined(BEOS)  #       define DPRINTF(level, format, ...) \
220                do {\
221                    if(DPRINTF_LEVEL & level)\
222                        fprintf(stderr, format"\n", ##__VA_ARGS__);\
223                }while(0);
224    
225    #    else /* _DEBUG */
226    #        define DPRINTF(level, format, ...)
227    #    endif /* _DEBUG */
228    
 #if defined(BEOS)  
 #include <inttypes.h>  
 #else  
 #include <stdint.h>  
 #endif  
229    
230    #    ifdef _DEBUG
231  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
232          type name##_storage[(sizex)*(sizey)+(alignment)-1]; \          type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
233          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))
   
234  #else  #else
   
235  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
236          __attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)]          __attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)]
   
 #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  
   
237  #endif  #endif
238    
239    /*----------------------------------------------------------------------------
240     | gcc x86 specific macros/functions
241     *---------------------------------------------------------------------------*/
242    #    if defined(ARCH_X86)
243    #        define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
244    #        define EMMS() __asm__ ("emms\n\t");
245    
246  // needed for bitstream.h           static __inline int64_t read_counter(void)
247  #ifdef ARCH_PPC           {
248  #define BSWAP(a) __asm__ __volatile__ ( "lwbrx %0,0,%1; eieio" : "=r" (a) : \               int64_t ts;
249                  "r" (&(a)), "m" (a));               uint32_t ts1, ts2;
250                 __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
251                 ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
252                 return ts;
253             }
254    
255    /*----------------------------------------------------------------------------
256     | gcc PPC and PPC Altivec specific macros/functions
257     *---------------------------------------------------------------------------*/
258    #    elif defined(ARCH_PPC)
259    #        define BSWAP(a) __asm__ __volatile__ \
260                    ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
261  #define EMMS()  #define EMMS()
262    
263  static __inline unsigned long           static __inline unsigned long get_tbl(void)
 get_tbl(void)  
264  {  {
265          unsigned long tbl;          unsigned long tbl;
266          asm volatile ("mftb %0":"=r" (tbl));          asm volatile ("mftb %0":"=r" (tbl));
   
267          return tbl;          return tbl;
268  }  }
269  static __inline unsigned long  
270  get_tbu(void)           static __inline unsigned long get_tbu(void)
271  {  {
272          unsigned long tbl;          unsigned long tbl;
273          asm volatile ("mftbu %0":"=r" (tbl));          asm volatile ("mftbu %0":"=r" (tbl));
   
274          return tbl;          return tbl;
275  }  }
276  static __inline int64_t  
277  read_counter()           static __inline int64_t read_counter(void)
278  {  {
279          unsigned long tb, tu;          unsigned long tb, tu;
   
280          do {          do {
281                  tu = get_tbu();                  tu = get_tbu();
282                  tb = get_tbl();                  tb = get_tbl();
# Line 240  Line 284 
284          return (((int64_t) tu) << 32) | (int64_t) tb;          return (((int64_t) tu) << 32) | (int64_t) tb;
285  }  }
286    
287  #define ptr_t   uint32_t  /*----------------------------------------------------------------------------
288     | gcc IA64 specific macros/functions
289  #define CACHE_LINE 16   *---------------------------------------------------------------------------*/
   
290  #elif defined(ARCH_IA64)  #elif defined(ARCH_IA64)
291    #        define BSWAP(a)  __asm__ __volatile__ \
292  #define ptr_t   uint64_t                  ("mux1 %1 = %0, @rev" ";;" \
   
 #define CACHE_LINE 32  
   
 #define EMMS()  
   
 #ifdef __GNUC__  
   
 // needed for bitstream.h  
 #define BSWAP(a)  __asm__ __volatile__ ("mux1 %1 = %0, @rev" \  
                         ";;" \  
293                          "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));                          "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
294    #        define EMMS()
295    
296  // rdtsc replacement for ia64           static __inline int64_t read_counter(void) {
 static __inline int64_t read_counter() {  
297          unsigned long result;          unsigned long result;
   
 //      __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");  
 //      while (__builtin_expect ((int) result == -1, 0))  
298                  __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");                  __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
299          return result;          return result;
   
300  }  }
301    
302  /* we are missing our ia64intrin.h file, but according to the  /*----------------------------------------------------------------------------
303     Intel's ecc manual, this should be the right way ...   | gcc SPARC specific macros/functions
304     this   *---------------------------------------------------------------------------*/
305    #    elif defined(ARCH_SPARC)
 #elif defined(__INTEL_COMPILER)  
   
 #include <ia64intrin.h>  
   
 static __inline int64_t read_counter() {  
   return __getReg(44);  
 }  
   
 #define BSWAP(a) ((unsigned int) (_m64_mux1(a, 0xb) >> 32))  
 */  
   
 #else  
   
 // needed for bitstream.h  
306  #define BSWAP(a) \  #define BSWAP(a) \
307           ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff))                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) |
308                           (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
309    #        define EMMS()
310    
311  // rdtsc command most likely not supported,           static __inline int64_t read_counter(void)
 // so just dummy code here  
 static __inline int64_t  
 read_counter()  
312  {  {
313          return 0;          return 0;
314  }  }
315    
316  #endif // gcc or ecc  /*----------------------------------------------------------------------------
317     | gcc MIPS specific macros/functions
318  #else   *---------------------------------------------------------------------------*/
319  #define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) )  #    elif defined(ARCH_MIPS)
320  #define EMMS() __asm__("emms\n\t")  #        define BSWAP(a) \
321                    ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) |
322                           (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
323  // needed for timer.c  #        define EMMS()
 static __inline int64_t  
 read_counter()  
 {  
         int64_t ts;  
         uint32_t ts1, ts2;  
   
         __asm__ __volatile__("rdtsc\n\t":"=a"(ts1),  
                                                  "=d"(ts2));  
   
         ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);  
   
         return ts;  
 }  
   
 #define ptr_t   uint32_t  
   
 #define CACHE_LINE 16  
   
 #endif  
   
 #else                                                   // OTHER OS  
   
   
 #include <stdio.h>  
 #include <stdarg.h>  
324    
325  static __inline void           static __inline int64_t read_counter(void)
 DPRINTF(int level, char *fmt, ...)  
326  {  {
327          if ((DPRINTF_LEVEL & level)) {               return 0;
   
                 va_list args;  
                 char buf[DPRINTF_BUF_SZ];  
   
                 va_start(args, fmt);  
                 vsprintf(buf, fmt, args);  
                 fprintf(stdout, "%s\n", buf);  
         }  
328  }  }
329    
330    /*----------------------------------------------------------------------------
331     | XviD + gcc unsupported Architecture
332     *---------------------------------------------------------------------------*/
333    #    else
334    #        error Architecture not supported.
335    #    endif /* Architecture checking */
336    
337  #define DEBUG(S)  /*****************************************************************************
338  #define DEBUG1(S,I)   *  Unknown compiler
339  #define DEBUG2(X,A,B)   ****************************************************************************/
340  #define DEBUG3(X,A,B,C)  #else /* Compiler test */
 #define DEBUG8(X,A,B,C,D,E,F,G,H)  
 #define DEBUGCBR(A,B,C)  
   
 #include <inttypes.h>  
   
 #define EMMS()  
341    
342  // needed for bitstream.h  #    error Compiler not supported
 #define BSWAP(a) \  
          ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff))  
   
 // rdtsc command most likely not supported,  
 // so just dummy code here  
 static __inline int64_t  
 read_counter()  
 {  
         return 0;  
 }  
343    
344  #define ptr_t uint32_t  #endif /* Compiler test */
345    
 #define CACHE_LINE  16  
 #define CACHE_ALIGN  
346    
347  #endif  #endif
   
 #endif                                                  // _PORTAB_H_  

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

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