[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.2, Sat Mar 16 14:15:10 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     ****************************************************************************/
43    
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
59    
60    /*****************************************************************************
61     *  Types used in XviD sources
62     ****************************************************************************/
63    
64    /*----------------------------------------------------------------------------
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)
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 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 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 29  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
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
158    #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
159                    type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
160                    type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1))
161    #    else
162    #        define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
163                    __declspec(align(alignment)) type name[(sizex)*(sizey)]
164    #    endif
165    
166    
167  // needed for bitstream.h  /*----------------------------------------------------------------------------
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)
175  static __inline int64_t read_counter() {               {
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)  /*----------------------------------------------------------------------------
188     | msvc unknown architecture
189     *---------------------------------------------------------------------------*/
190    #    else
191    #        error Architecture not supported.
192    #    endif
193    
 #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)  
194    
 #if defined(LINUX)  
195    
 #include <stdint.h>  
196    
197  #else  /*****************************************************************************
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
212    
213  #define int8_t char          /* Needed for all debuf fprintf calls */
214  #define uint8_t unsigned char  #       include <stdio.h>
215  #define int16_t short  
216  #define uint16_t unsigned short  #       define DPRINTF(level, format, ...) \
217  #define int32_t int              do {\
218  #define uint32_t unsigned int                  if(DPRINTF_LEVEL & level)\
219  #define int64_t long long                      fprintf(stderr, format"\n", ##__VA_ARGS__);\
220  #define uint64_t unsigned long long              }while(0);
221    
222    #    else /* _DEBUG */
223    #        define DPRINTF(level, format, ...)
224    #    endif /* _DEBUG */
225    
 #endif  
226    
 #define EMMS() __asm__("emms\n\t")  
227    
228  // needed for bitstream.h  #    define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \
229  #define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) )              type name##_storage[(sizex)*(sizey)+(alignment)-1]; \
230                type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1))
231    
232    /*----------------------------------------------------------------------------
233     | gcc x86 specific macros/functions
234     *---------------------------------------------------------------------------*/
235    #    if defined(ARCH_X86)
236    #        define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) );
237    #        define EMMS() __asm__ ("emms\n\t");
238    
239  // needed for timer.c           static __inline int64_t read_counter(void)
240  static __inline int64_t read_counter() {           {
241      int64_t ts;      int64_t ts;
242      uint32_t ts1, ts2;      uint32_t ts1, ts2;
   
243      __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));      __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2));
   
244      ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);      ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1);
   
245      return ts;      return ts;
246  }  }
247    
248  #else // OTHER OS  /*----------------------------------------------------------------------------
249     | gcc PPC and PPC Altivec specific macros/functions
250     *---------------------------------------------------------------------------*/
251    #    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()
255    
256  #define DEBUG(S)           static __inline unsigned long get_tbl(void)
257  #define DEBUG1(S,I)           {
258  #define DEBUG2(X,A,B)               unsigned long tbl;
259  #define DEBUG3(X,A,B,C)               asm volatile ("mftb %0":"=r" (tbl));
260  #define DEBUG8(X,A,B,C,D,E,F,G,H)               return tbl;
261             }
262    
263  #include <inttypes.h>           static __inline unsigned long get_tbu(void)
264             {
265                 unsigned long tbl;
266                 asm volatile ("mftbu %0":"=r" (tbl));
267                 return tbl;
268             }
269    
270             static __inline int64_t read_counter(void)
271             {
272                 unsigned long tb, tu;
273                 do {
274                     tu = get_tbu();
275                     tb = get_tbl();
276                 }while (tb != get_tbl());
277                 return (((int64_t) tu) << 32) | (int64_t) tb;
278             }
279    
280    /*----------------------------------------------------------------------------
281     | gcc IA64 specific macros/functions
282     *---------------------------------------------------------------------------*/
283    #    elif defined(ARCH_IA64)
284    #        define BSWAP(a)  __asm__ __volatile__ \
285                    ("mux1 %1 = %0, @rev" ";;" \
286                     "shr.u %1 = %1, 32" : "=r" (a) : "r" (a));
287  #define EMMS()  #define EMMS()
288    
289  // needed for bitstream.h           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    /*----------------------------------------------------------------------------
296     | gcc SPARC specific macros/functions
297     *---------------------------------------------------------------------------*/
298    #    elif defined(ARCH_SPARC)
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)
305  // so just dummy code here           {
 static __inline int64_t read_counter() {  
306          return 0;          return 0;
307  }  }
308    
309  #endif  /*----------------------------------------------------------------------------
310     | gcc MIPS specific macros/functions
311     *---------------------------------------------------------------------------*/
312    #    elif defined(ARCH_MIPS)
313    #        define BSWAP(a) \
314                    ((a) = (((a) & 0xff) << 24)  | (((a) & 0xff00) << 8) | \
315                           (((a) >> 8) & 0xff00) | (((a) >> 24) & 0xff))
316    #        define EMMS()
317    
318  #endif // _PORTAB_H_           static __inline int64_t read_counter(void)
319             {
320                 return 0;
321             }
322    
323    /*----------------------------------------------------------------------------
324     | XviD + gcc unsupported Architecture
325     *---------------------------------------------------------------------------*/
326    #    else
327    #        error Architecture not supported.
328    #    endif /* Architecture checking */
329    
330    /*****************************************************************************
331     *  Unknown compiler
332     ****************************************************************************/
333    #else /* Compiler test */
334    
335    #    error Compiler not supported
336    
337    #endif /* Compiler test */
338    
339    
340    #endif

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

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