[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.23, Sun Jun 30 10:46:29 2002 UTC revision 1.31, Sun Sep 22 18:17:32 2002 UTC
# Line 1  Line 1 
1    /*****************************************************************************
2     *
3     *  XVID MPEG-4 VIDEO CODEC
4     *  - Portable macros, types and inlined assembly -
5     *
6     *  Copyright(C) 2002 Michael Militzer
7     *
8     *  This program is an implementation of a part of one or more MPEG-4
9     *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
10     *  to use this software module in hardware or software products are
11     *  advised that its use may infringe existing patents or copyrights, and
12     *  any such use would be at such party's own risk.  The original
13     *  developer of this software module and his/her company, and subsequent
14     *  editors and their companies, will have no liability for use of this
15     *  software or modifications or derivatives thereof.
16     *
17     *  This program is free software ; you can redistribute it and/or modify
18     *  it under the terms of the GNU General Public License as published by
19     *  the Free Software Foundation ; either version 2 of the License, or
20     *  (at your option) any later version.
21     *
22     *  This program is distributed in the hope that it will be useful,
23     *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
24     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25     *  GNU General Public License for more details.
26     *
27     *  You should have received a copy of the GNU General Public License
28     *  along with this program ; if not, write to the Free Software
29     *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
30     *
31     * $Id$
32     *
33     ****************************************************************************/
34    
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 12  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  #include <windows.h>   *---------------------------------------------------------------------------*/
 #include <stdio.h>  
65    
66  static __inline void  #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)
 DPRINTF(int level, char *fmt,  
                 ...)  
 {  
         if ((DPRINTF_LEVEL & level))  
         {  
                 va_list args;  
                 char buf[DPRINTF_BUF_SZ];  
67    
68                  va_start(args, fmt);  /* All (u)int(size)_t types are defined here */
69                  vsprintf(buf, fmt, args);  #    include <inttypes.h>
                 OutputDebugString(buf);  
                 fprintf(stdout, "%s\n", buf);  
                 fflush(stdout);  
         }  
 }  
70    
71    /*----------------------------------------------------------------------------
72     | msvc (lacks such a header file)
73     *---------------------------------------------------------------------------*/
74    
75  #define DEBUGCBR(A,B,C) { char tmp[100]; wsprintf(tmp, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C)); OutputDebugString(tmp); }  #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  #ifdef _DEBUG  /*----------------------------------------------------------------------------
86  #define DEBUG(S) OutputDebugString((S));   | Fallback when using gcc
87  #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 67  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 84  Line 161 
161          __declspec(align(alignment)) type name[(sizex)*(sizey)]          __declspec(align(alignment)) type name[(sizex)*(sizey)]
162  #endif  #endif
163    
164  // needed for bitstream.h  
165    /*----------------------------------------------------------------------------
166     | msvc x86 specific macros/functions
167     *---------------------------------------------------------------------------*/
168    #    if defined(ARCH_X86)
169  #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
170    #        define EMMS() __asm {emms}
171    
172  // needed for timer.c               static __inline int64_t read_counter(void)
 static __inline int64_t  
 read_counter()  
173  {  {
174          int64_t ts;          int64_t ts;
175          uint32_t ts1, ts2;          uint32_t ts1, ts2;
   
176          __asm {          __asm {
177                  rdtsc                  rdtsc
178                  mov ts1, eax                  mov ts1, eax
179                  mov ts2, edx                  mov ts2, edx
180          }          }
   
181          ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);          ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
   
182          return ts;          return ts;
183  }  }
184    
185  #elif defined(LINUX) || defined(DJGPP) || defined(FREEBSD)  /*----------------------------------------------------------------------------
186     | msvc unknown architecture
187     *---------------------------------------------------------------------------*/
188    #    else
189    #        error Architecture not supported.
190    #    endif
191    
 #include <stdio.h>  
 #include <stdarg.h>  
192    
 static __inline void  
 DPRINTF(int level, char *fmt,  
                 ...)  
 {  
         if ((DPRINTF_LEVEL & level)) {  
                 va_list args;  
                 char buf[DPRINTF_BUF_SZ];  
193    
                 va_start(args, fmt);  
                 vsprintf(buf, fmt, args);  
                 fprintf(stdout, "%s\n", buf);  
         }  
 }  
194    
195    /*****************************************************************************
196     *  GNU CC compiler stuff
197     ****************************************************************************/
198    
199    #elif defined(__GNUC__) /* Compiler test */
200    
201    /*----------------------------------------------------------------------------
202     | Common gcc stuff
203     *---------------------------------------------------------------------------*/
204    
205    /*
206     * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
207     * and it's a macro calling fprintf directly
208     */
209  #ifdef _DEBUG  #ifdef _DEBUG
210    
211            /* Needed for all debuf fprintf calls */
212  #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  
213    
214  #if defined(LINUX)  #       define DPRINTF(level, format, ...) \
215                do {\
216                    if(DPRINTF_LEVEL & level)\
217                        fprintf(stderr, format"\n", ##__VA_ARGS__);\
218                }while(0);
219    
220    #    else /* _DEBUG */
221    #        define DPRINTF(level, format, ...)
222    #    endif /* _DEBUG */
223    
224    
 #include <stdint.h>  
225    
226  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
227          type name##_storage[(sizex)*(sizey)+(alignment)-1]; \          type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
228          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))
229    
230  #else  /*----------------------------------------------------------------------------
231     | gcc x86 specific macros/functions
232  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \   *---------------------------------------------------------------------------*/
233          __attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)]  #    if defined(ARCH_X86)
234    #        define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
235  #define int8_t   char  #        define EMMS() __asm__ ("emms\n\t");
 #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  
   
 #endif  
236    
237             static __inline int64_t read_counter(void)
238             {
239                 int64_t ts;
240                 uint32_t ts1, ts2;
241                 __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
242                 ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
243                 return ts;
244             }
245    
246  // needed for bitstream.h  /*----------------------------------------------------------------------------
247  #ifdef ARCH_PPC   | gcc PPC and PPC Altivec specific macros/functions
248  #define BSWAP(a) __asm__ __volatile__ ( "lwbrx %0,0,%1; eieio" : "=r" (a) : \   *---------------------------------------------------------------------------*/
249                  "r" (&(a)), "m" (a));  #    elif defined(ARCH_PPC)
250    #        define BSWAP(a) __asm__ __volatile__ \
251                    ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
252  #define EMMS()  #define EMMS()
253    
254  static __inline unsigned long           static __inline unsigned long get_tbl(void)
 get_tbl(void)  
255  {  {
256          unsigned long tbl;          unsigned long tbl;
257          asm volatile ("mftb %0":"=r" (tbl));          asm volatile ("mftb %0":"=r" (tbl));
   
258          return tbl;          return tbl;
259  }  }
260  static __inline unsigned long  
261  get_tbu(void)           static __inline unsigned long get_tbu(void)
262  {  {
263          unsigned long tbl;          unsigned long tbl;
264          asm volatile ("mftbu %0":"=r" (tbl));          asm volatile ("mftbu %0":"=r" (tbl));
   
265          return tbl;          return tbl;
266  }  }
267  static __inline int64_t  
268  read_counter()           static __inline int64_t read_counter(void)
269  {  {
270          unsigned long tb, tu;          unsigned long tb, tu;
   
271          do {          do {
272                  tu = get_tbu();                  tu = get_tbu();
273                  tb = get_tbl();                  tb = get_tbl();
# Line 202  Line 275 
275          return (((int64_t) tu) << 32) | (int64_t) tb;          return (((int64_t) tu) << 32) | (int64_t) tb;
276  }  }
277    
278  #define ptr_t   uint32_t  /*----------------------------------------------------------------------------
279     | gcc IA64 specific macros/functions
280  #define CACHE_LINE 16   *---------------------------------------------------------------------------*/
   
281  #elif defined(ARCH_IA64)  #elif defined(ARCH_IA64)
282    #        define BSWAP(a)  __asm__ __volatile__ \
283  #define ptr_t   uint64_t                  ("mux1 %1 = %0, @rev" ";;" \
284                     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
 #define CACHE_LINE 32  
   
285  #define EMMS()  #define EMMS()
286    
287  // needed for bitstream.h           static __inline int64_t read_counter(void) {
288  #define BSWAP(a) \               unsigned long result;
289           ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff))               __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
290                 return result;
 // rdtsc command most likely not supported,  
 // so just dummy code here  
 static __inline int64_t read_counter() {  
         return 0;  
291  }  }
292    
293  #else  /*----------------------------------------------------------------------------
294  #define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) )   | gcc SPARC specific macros/functions
295  #define EMMS() __asm__("emms\n\t")   *---------------------------------------------------------------------------*/
296    #    elif defined(ARCH_SPARC)
297    #        define BSWAP(a) \
298                    ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
299                           (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
300    #        define EMMS()
301    
302  // needed for timer.c           static __inline int64_t read_counter(void)
 static __inline int64_t  
 read_counter()  
303  {  {
304          int64_t ts;               return 0;
         uint32_t ts1, ts2;  
   
         __asm__ __volatile__("rdtsc\n\t":"=a"(ts1),  
                                                  "=d"(ts2));  
   
         ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);  
   
         return ts;  
305  }  }
306    
307  #define ptr_t   uint32_t  /*----------------------------------------------------------------------------
308     | gcc MIPS specific macros/functions
309  #define CACHE_LINE 16   *---------------------------------------------------------------------------*/
310    #    elif defined(ARCH_MIPS)
311  #endif  #        define BSWAP(a) \
312                    ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
313  #else                                                   // OTHER OS                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
314    #        define EMMS()
   
 #include <stdio.h>  
 #include <stdarg.h>  
315    
316  static __inline void           static __inline int64_t read_counter(void)
 DPRINTF(int level, char *fmt, ...)  
317  {  {
318          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);  
         }  
319  }  }
320    
321    /*----------------------------------------------------------------------------
322     | XviD + gcc unsupported Architecture
323     *---------------------------------------------------------------------------*/
324    #    else
325    #        error Architecture not supported.
326    #    endif /* Architecture checking */
327    
328  #define DEBUG(S)  /*****************************************************************************
329  #define DEBUG1(S,I)   *  Unknown compiler
330  #define DEBUG2(X,A,B)   ****************************************************************************/
331  #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()  
   
 // needed for bitstream.h  
 #define BSWAP(a) \  
          ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff))  
332    
333  // rdtsc command most likely not supported,  #    error Compiler not supported
 // so just dummy code here  
 static __inline int64_t  
 read_counter()  
 {  
         return 0;  
 }  
334    
335  #define ptr_t uint32_t  #endif /* Compiler test */
336    
 #define CACHE_LINE  16  
 #define CACHE_ALIGN  
337    
338  #endif  #endif
   
 #endif                                                  // _PORTAB_H_  

Legend:
Removed from v.1.23  
changed lines
  Added in v.1.31

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