[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.25, Wed Jul 10 15:27:37 2002 UTC revision 1.34, Sat Oct 19 12:20:33 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 <isibaar@xvid.org>
7     *               2002 Peter Ross <pross@xvid.org>
8     *               2002 Edouard Gomez <ed.gomez@wanadoo.fr>
9     *
10     *  This program is an implementation of a part of one or more MPEG-4
11     *  Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
12     *  to use this software module in hardware or software products are
13     *  advised that its use may infringe existing patents or copyrights, and
14     *  any such use would be at such party's own risk.  The original
15     *  developer of this software module and his/her company, and subsequent
16     *  editors and their companies, will have no liability for use of this
17     *  software or modifications or derivatives thereof.
18     *
19     *  This program is free software ; you can redistribute it and/or modify
20     *  it under the terms of the GNU General Public License as published by
21     *  the Free Software Foundation ; either version 2 of the License, or
22     *  (at your option) any later version.
23     *
24     *  This program is distributed in the hope that it will be useful,
25     *  but WITHOUT ANY WARRANTY ; without even the implied warranty of
26     *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27     *  GNU General Public License for more details.
28     *
29     *  You should have received a copy of the GNU General Public License
30     *  along with this program ; if not, write to the Free Software
31     *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
32     *
33     * $Id$
34     *
35     ****************************************************************************/
36    
37  #ifndef _PORTAB_H_  #ifndef _PORTAB_H_
38  #define _PORTAB_H_  #define _PORTAB_H_
39    
40    /*****************************************************************************
41     *  Common things
42     ****************************************************************************/
43    
44  // debug level masks  /* Debug level masks */
45  #define DPRINTF_ERROR           0x00000001  #define DPRINTF_ERROR           0x00000001
46  #define DPRINTF_STARTCODE       0x00000002  #define DPRINTF_STARTCODE       0x00000002
47  #define DPRINTF_HEADER          0x00000004  #define DPRINTF_HEADER          0x00000004
# Line 12  Line 51 
51  #define DPRINTF_MV                      0x00000040  #define DPRINTF_MV                      0x00000040
52  #define DPRINTF_DEBUG           0x80000000  #define DPRINTF_DEBUG           0x80000000
53    
54  // debug level  /* debug level for this library */
55  #define DPRINTF_LEVEL           0  #define DPRINTF_LEVEL           0
56    
57    /* Buffer size for non C99 compliant compilers (msvc) */
58  #define DPRINTF_BUF_SZ  1024  #define DPRINTF_BUF_SZ  1024
59    
60    /*****************************************************************************
61     *  Types used in XviD sources
62     ****************************************************************************/
63    
64  #if defined(WIN32)  /*----------------------------------------------------------------------------
65     | Standard Unix include file (sorry, we put all unix into "linux" case)
66     *---------------------------------------------------------------------------*/
67    
68  #include <windows.h>  #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)
 #include <stdio.h>  
69    
70  static __inline void  /* All (u)int(size)_t types are defined here */
71  DPRINTF(int level, char *fmt,  #    include <inttypes.h>
                 ...)  
 {  
         if ((DPRINTF_LEVEL & level))  
         {  
                 va_list args;  
                 char buf[DPRINTF_BUF_SZ];  
   
                 va_start(args, fmt);  
                 vsprintf(buf, fmt, args);  
                 OutputDebugString(buf);  
                 fprintf(stdout, "%s\n", buf);  
                 fflush(stdout);  
         }  
 }  
72    
73    /*----------------------------------------------------------------------------
74     | msvc (lacks such a header file)
75     *---------------------------------------------------------------------------*/
76    
77  #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)
78    #    define int8_t   char
79    #    define uint8_t  unsigned char
80    #    define int16_t  short
81    #    define uint16_t unsigned short
82    #    define int32_t  int
83    #    define uint32_t unsigned int
84    #    define int64_t  __int64
85    #    define uint64_t unsigned __int64
86    
87  #ifdef _DEBUG  /*----------------------------------------------------------------------------
88  #define DEBUG(S) OutputDebugString((S));   | Fallback when using gcc
89  #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  
90    
91    #elif defined(__GNUC__)
92    
93  #define int8_t char  #define int8_t char
94  #define uint8_t unsigned char  #define uint8_t unsigned char
# Line 67  Line 96 
96  #define uint16_t unsigned short  #define uint16_t unsigned short
97  #define int32_t int  #define int32_t int
98  #define uint32_t unsigned int  #define uint32_t unsigned int
99  #define int64_t __int64  #    define int64_t  long long
100  #define uint64_t unsigned __int64  #    define uint64_t unsigned long long
 #define ptr_t uint32_t  
101    
102  #define EMMS() __asm {emms}  /*----------------------------------------------------------------------------
103     | Ok, we don't know how to define these types... error
104     *---------------------------------------------------------------------------*/
105    
106    #else
107    #    error Do not know how to define (u)int(size)_t types
108    #endif
109    
110    /*****************************************************************************
111     *  Some things that are only architecture dependant
112     ****************************************************************************/
113    
114    #if defined(ARCH_X86) || defined(ARCH_PPC) || defined(ARCH_MIPS)  || defined(ARCH_SPARC)
115  #define CACHE_LINE  16  #define CACHE_LINE  16
116    #    define ptr_t uint32_t
117    #elif defined(ARCH_IA64)
118    #    define CACHE_LINE  32
119    #    define ptr_t uint64_t
120    #else
121    #    error Architecture not supported.
122    #endif
123    
124    /*****************************************************************************
125     *  Things that must be sorted by compiler and then by architecture
126     ****************************************************************************/
127    
128    /*****************************************************************************
129     *  MSVC compiler specific macros, functions
130     ****************************************************************************/
131    
132    #if defined(_MSC_VER)
133    
134    /*----------------------------------------------------------------------------
135     | Common msvc stuff
136     *---------------------------------------------------------------------------*/
137    
138    #include <windows.h>
139    #include <stdio.h>
140    
141        /*
142         * This function must be declared/defined all the time because MSVC does
143         * not support C99 variable arguments macros
144         */
145        static __inline void DPRINTF(int level, char *fmt, ...)
146        {
147            if (DPRINTF_LEVEL & level) {
148                va_list args;
149                char buf[DPRINTF_BUF_SZ];
150                va_start(args, fmt);
151                vsprintf(buf, fmt, args);
152                OutputDebugString(buf);
153                fprintf(stderr, "%s\n", buf);
154             }
155         }
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 84  Line 163 
163          __declspec(align(alignment)) type name[(sizex)*(sizey)]          __declspec(align(alignment)) type name[(sizex)*(sizey)]
164  #endif  #endif
165    
166  // needed for bitstream.h  
167    /*----------------------------------------------------------------------------
168     | msvc x86 specific macros/functions
169     *---------------------------------------------------------------------------*/
170    #    if defined(ARCH_X86)
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    #        define EMMS() __asm {emms}
173    
174  // needed for timer.c               static __inline int64_t read_counter(void)
 static __inline int64_t  
 read_counter()  
175  {  {
176          int64_t ts;          int64_t ts;
177          uint32_t ts1, ts2;          uint32_t ts1, ts2;
   
178          __asm {          __asm {
179                  rdtsc                  rdtsc
180                  mov ts1, eax                  mov ts1, eax
181                  mov ts2, edx                  mov ts2, edx
182          }          }
   
183          ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);          ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
   
184          return ts;          return ts;
185  }  }
186    
187  #elif defined(LINUX) || defined(DJGPP) || defined(FREEBSD)  /*----------------------------------------------------------------------------
188     | msvc unknown architecture
189     *---------------------------------------------------------------------------*/
190    #    else
191    #        error Architecture not supported.
192    #    endif
193    
 #include <stdio.h>  
 #include <stdarg.h>  
194    
 static __inline void  
 DPRINTF(int level, char *fmt,  
                 ...)  
 {  
         if ((DPRINTF_LEVEL & level)) {  
                 va_list args;  
                 char buf[DPRINTF_BUF_SZ];  
195    
                 va_start(args, fmt);  
                 vsprintf(buf, fmt, args);  
                 fprintf(stdout, "%s\n", buf);  
         }  
 }  
196    
197    /*****************************************************************************
198     *  GNU CC compiler stuff
199     ****************************************************************************/
200    
201    #elif defined(__GNUC__) /* Compiler test */
202    
203    /*----------------------------------------------------------------------------
204     | Common gcc stuff
205     *---------------------------------------------------------------------------*/
206    
207    /*
208     * As gcc is (mostly) C99 compliant, we define DPRINTF only if it's realy needed
209     * and it's a macro calling fprintf directly
210     */
211  #ifdef _DEBUG  #ifdef _DEBUG
212    
213            /* Needed for all debuf fprintf calls */
214  #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  
215    
216  #if defined(LINUX)  #       define DPRINTF(level, format, ...) \
217                do {\
218                    if(DPRINTF_LEVEL & level)\
219                        fprintf(stderr, format"\n", ##__VA_ARGS__);\
220                }while(0);
221    
222    #    else /* _DEBUG */
223    #        define DPRINTF(level, format, ...)
224    #    endif /* _DEBUG */
225    
226    
 #include <stdint.h>  
227    
228  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
229          type name##_storage[(sizex)*(sizey)+(alignment)-1]; \          type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
230          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))
231    
232  #else  /*----------------------------------------------------------------------------
233     | gcc x86 specific macros/functions
234  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \   *---------------------------------------------------------------------------*/
235          __attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)]  #    if defined(ARCH_X86)
236    #        define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
237  #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  
238    
239             static __inline int64_t read_counter(void)
240             {
241                 int64_t ts;
242                 uint32_t ts1, ts2;
243                 __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
244                 ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
245                 return ts;
246             }
247    
248  // needed for bitstream.h  /*----------------------------------------------------------------------------
249  #ifdef ARCH_PPC   | gcc PPC and PPC Altivec specific macros/functions
250  #define BSWAP(a) __asm__ __volatile__ ( "lwbrx %0,0,%1; eieio" : "=r" (a) : \   *---------------------------------------------------------------------------*/
251                  "r" (&(a)), "m" (a));  #    elif defined(ARCH_PPC)
252    #        define BSWAP(a) __asm__ __volatile__ \
253                    ( "lwbrx %0,0,%1; eieio" : "=r" (a) : "r" (&(a)), "m" (a));
254  #define EMMS()  #define EMMS()
255    
256  static __inline unsigned long           static __inline unsigned long get_tbl(void)
 get_tbl(void)  
257  {  {
258          unsigned long tbl;          unsigned long tbl;
259          asm volatile ("mftb %0":"=r" (tbl));          asm volatile ("mftb %0":"=r" (tbl));
   
260          return tbl;          return tbl;
261  }  }
262  static __inline unsigned long  
263  get_tbu(void)           static __inline unsigned long get_tbu(void)
264  {  {
265          unsigned long tbl;          unsigned long tbl;
266          asm volatile ("mftbu %0":"=r" (tbl));          asm volatile ("mftbu %0":"=r" (tbl));
   
267          return tbl;          return tbl;
268  }  }
269  static __inline int64_t  
270  read_counter()           static __inline int64_t read_counter(void)
271  {  {
272          unsigned long tb, tu;          unsigned long tb, tu;
   
273          do {          do {
274                  tu = get_tbu();                  tu = get_tbu();
275                  tb = get_tbl();                  tb = get_tbl();
# Line 202  Line 277 
277          return (((int64_t) tu) << 32) | (int64_t) tb;          return (((int64_t) tu) << 32) | (int64_t) tb;
278  }  }
279    
280  #define ptr_t   uint32_t  /*----------------------------------------------------------------------------
281     | gcc IA64 specific macros/functions
282  #define CACHE_LINE 16   *---------------------------------------------------------------------------*/
   
283  #elif defined(ARCH_IA64)  #elif defined(ARCH_IA64)
284    #        define BSWAP(a)  __asm__ __volatile__ \
285  #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" \  
                         ";;" \  
286                          "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));                          "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
287    #        define EMMS()
288    
289  // rdtsc replacement for ia64           static __inline int64_t read_counter(void) {
 static __inline int64_t read_counter() {  
290          unsigned long result;          unsigned long result;
   
 //      __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");  
 //      while (__builtin_expect ((int) result == -1, 0))  
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  /* we are missing our ia64intrin.h file, but according to the  /*----------------------------------------------------------------------------
296     Intel's ecc manual, this should be the right way ...   | gcc SPARC specific macros/functions
297     this   *---------------------------------------------------------------------------*/
298    #    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  
299  #define BSWAP(a) \  #define BSWAP(a) \
300           ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff))                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
301                           (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
302    #        define EMMS()
303    
304  // rdtsc command most likely not supported,           static __inline int64_t read_counter(void)
 // so just dummy code here  
 static __inline int64_t  
 read_counter()  
305  {  {
306          return 0;          return 0;
307  }  }
308    
309  #endif // gcc or ecc  /*----------------------------------------------------------------------------
310     | gcc MIPS specific macros/functions
311  #else   *---------------------------------------------------------------------------*/
312  #define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) )  #    elif defined(ARCH_MIPS)
313  #define EMMS() __asm__("emms\n\t")  #        define BSWAP(a) \
314                    ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
315                           (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
316  // 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>  
317    
318  static __inline void           static __inline int64_t read_counter(void)
 DPRINTF(int level, char *fmt, ...)  
319  {  {
320          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);  
         }  
321  }  }
322    
323    /*----------------------------------------------------------------------------
324     | XviD + gcc unsupported Architecture
325     *---------------------------------------------------------------------------*/
326    #    else
327    #        error Architecture not supported.
328    #    endif /* Architecture checking */
329    
330  #define DEBUG(S)  /*****************************************************************************
331  #define DEBUG1(S,I)   *  Unknown compiler
332  #define DEBUG2(X,A,B)   ****************************************************************************/
333  #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()  
334    
335  // 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;  
 }  
336    
337  #define ptr_t uint32_t  #endif /* Compiler test */
338    
 #define CACHE_LINE  16  
 #define CACHE_ALIGN  
339    
340  #endif  #endif
   
 #endif                                                  // _PORTAB_H_  

Legend:
Removed from v.1.25  
changed lines
  Added in v.1.34

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