[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.20, Fri Jun 14 13:06:33 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  #if defined(WIN32)  /*****************************************************************************
41     *  Common things
42  #include <windows.h>   ****************************************************************************/
43  #include <stdio.h>  
44    /* Debug level masks */
45    #define DPRINTF_ERROR           0x00000001
46    #define DPRINTF_STARTCODE       0x00000002
47    #define DPRINTF_HEADER          0x00000004
48    #define DPRINTF_TIMECODE        0x00000008
49    #define DPRINTF_MB                      0x00000010
50    #define DPRINTF_COEFF           0x00000020
51    #define DPRINTF_MV                      0x00000040
52    #define DPRINTF_DEBUG           0x80000000
53    
54    /* debug level for this library */
55    #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
 static void  
 dprintf(char *fmt,  
                 ...)  
 {  
         va_list args;  
         char buf[DPRINTF_BUF_SZ];  
59    
60          va_start(args, fmt);  /*****************************************************************************
61          vsprintf(buf, fmt, args);   *  Types used in XviD sources
62          OutputDebugString(buf);   ****************************************************************************/
         fprintf(stdout, "%s\n", buf);  
 }  
63    
64    /*----------------------------------------------------------------------------
65     | Standard Unix include file (sorry, we put all unix into "linux" case)
66     *---------------------------------------------------------------------------*/
67    
68  #define DEBUGCBR(A,B,C) { char tmp[100]; wsprintf(tmp, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C)); OutputDebugString(tmp); }  #if defined(LINUX) || defined(BEOS) || defined(FREEBSD)
69    
70  #ifdef _DEBUG  /* All (u)int(size)_t types are defined here */
71  #define DEBUG(S) OutputDebugString((S));  #    include <inttypes.h>
 #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  
72    
73    /*----------------------------------------------------------------------------
74     | msvc (lacks such a header file)
75     *---------------------------------------------------------------------------*/
76    
77    #elif defined(_MSC_VER)
78  #define int8_t char  #define int8_t char
79  #define uint8_t unsigned char  #define uint8_t unsigned char
80  #define int16_t short  #define int16_t short
# Line 50  Line 84 
84  #define int64_t __int64  #define int64_t __int64
85  #define uint64_t unsigned __int64  #define uint64_t unsigned __int64
86    
87  #define EMMS() __asm {emms}  /*----------------------------------------------------------------------------
88     | Fallback when using gcc
89     *---------------------------------------------------------------------------*/
90    
91    #elif defined(__GNUC__)
92    
93    #    define int8_t   char
94    #    define uint8_t  unsigned char
95    #    define int16_t  short
96    #    define uint16_t unsigned short
97    #    define int32_t  int
98    #    define uint32_t unsigned int
99    #    define int64_t  long long
100    #    define uint64_t unsigned long long
101    
102    /*----------------------------------------------------------------------------
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 63  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    
194    
195    
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  #define CACHE_LINE  16  #       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    
 #if defined(LINUX)  
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 *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))              type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))
   
 #else  
231    
232  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \  /*----------------------------------------------------------------------------
233          __attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)]   | gcc x86 specific macros/functions
234     *---------------------------------------------------------------------------*/
235  #define int8_t   char  #    if defined(ARCH_X86)
236  #define uint8_t  unsigned char  #        define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
237  #define int16_t  short  #        define EMMS() __asm__ ("emms\n\t");
 #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();
276          } while (tb != get_tbl());          } while (tb != get_tbl());
277          return (((int64_t) tu) << 32) | (int64_t) tb;          return (((int64_t) tu) << 32) | (int64_t) tb;
278  }  }
 #else  
 #define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) )  
 #define EMMS() __asm__("emms\n\t")  
   
279    
280  // needed for timer.c  /*----------------------------------------------------------------------------
281  static __inline int64_t   | gcc IA64 specific macros/functions
282  read_counter()   *---------------------------------------------------------------------------*/
283  {  #    elif defined(ARCH_IA64)
284          int64_t ts;  #        define BSWAP(a)  __asm__ __volatile__ \
285          uint32_t ts1, ts2;                  ("mux1 %1 = %0, @rev" ";;" \
286                     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
287          __asm__ __volatile__("rdtsc\n\t":"=a"(ts1),  #        define EMMS()
                                                  "=d"(ts2));  
   
         ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);  
288    
289          return ts;           static __inline int64_t read_counter(void) {
290                 unsigned long result;
291                 __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory");
292                 return result;
293  }  }
294    
295  #endif  /*----------------------------------------------------------------------------
296     | gcc SPARC specific macros/functions
297  #else                                                   // OTHER OS   *---------------------------------------------------------------------------*/
298    #    elif defined(ARCH_SPARC)
299  #define DEBUG(S)  #        define BSWAP(a) \
300  #define DEBUG1(S,I)                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
301  #define DEBUG2(X,A,B)                         (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
 #define DEBUG3(X,A,B,C)  
 #define DEBUG8(X,A,B,C,D,E,F,G,H)  
 #define DEBUGCBR(A,B,C)  
   
 #include <inttypes.h>  
   
302  #define EMMS()  #define EMMS()
303    
304  // needed for bitstream.h           static __inline int64_t read_counter(void)
305             {
306                 return 0;
307             }
308    
309    /*----------------------------------------------------------------------------
310     | gcc MIPS specific macros/functions
311     *---------------------------------------------------------------------------*/
312    #    elif defined(ARCH_MIPS)
313  #define BSWAP(a) \  #define BSWAP(a) \
314           ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff))                  ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
315                           (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
316    #        define EMMS()
317    
318  // rdtsc command most likely not supported,           static __inline int64_t read_counter(void)
 // so just dummy code here  
 static __inline int64_t  
 read_counter()  
319  {  {
320          return 0;          return 0;
321  }  }
322    
323  #define CACHE_LINE  16  /*----------------------------------------------------------------------------
324  #define CACHE_ALIGN   | XviD + gcc unsupported Architecture
325  #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \   *---------------------------------------------------------------------------*/
326          type name[(sizex)*(sizey)]  #    else
327    #        error Architecture not supported.
328    #    endif /* Architecture checking */
329    
330  #endif  /*****************************************************************************
331     *  Unknown compiler
332     ****************************************************************************/
333    #else /* Compiler test */
334    
335    #    error Compiler not supported
336    
337  #endif                                                  // _PORTAB_H_  #endif /* Compiler test */
338    
339    
340    #endif

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

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