1 |
#ifndef _PORTAB_H_ |
#ifndef _PORTAB_H_ |
2 |
#define _PORTAB_H_ |
#define _PORTAB_H_ |
3 |
|
|
4 |
|
|
5 |
|
// debug level masks |
6 |
|
#define DPRINTF_ERROR 0x00000001 |
7 |
|
#define DPRINTF_STARTCODE 0x00000002 |
8 |
|
#define DPRINTF_HEADER 0x00000004 |
9 |
|
#define DPRINTF_TIMECODE 0x00000008 |
10 |
|
#define DPRINTF_MB 0x00000010 |
11 |
|
#define DPRINTF_COEFF 0x00000020 |
12 |
|
#define DPRINTF_MV 0x00000040 |
13 |
|
#define DPRINTF_DEBUG 0x80000000 |
14 |
|
|
15 |
|
// debug level |
16 |
|
#define DPRINTF_LEVEL 0 |
17 |
|
|
18 |
|
|
19 |
|
#define DPRINTF_BUF_SZ 1024 |
20 |
|
|
21 |
|
|
22 |
#if defined(WIN32) |
#if defined(WIN32) |
23 |
|
|
24 |
#include <windows.h> |
#include <windows.h> |
25 |
#include <stdio.h> |
#include <stdio.h> |
26 |
|
|
27 |
|
static __inline void |
28 |
#define DPRINTF_BUF_SZ 1024 |
DPRINTF(int level, char *fmt, |
29 |
static void dprintf(char *fmt, ...) |
...) |
30 |
|
{ |
31 |
|
if ((DPRINTF_LEVEL & level)) |
32 |
{ |
{ |
33 |
va_list args; |
va_list args; |
34 |
char buf[DPRINTF_BUF_SZ]; |
char buf[DPRINTF_BUF_SZ]; |
37 |
vsprintf(buf, fmt, args); |
vsprintf(buf, fmt, args); |
38 |
OutputDebugString(buf); |
OutputDebugString(buf); |
39 |
fprintf(stdout, "%s\n", buf); |
fprintf(stdout, "%s\n", buf); |
40 |
|
fflush(stdout); |
41 |
|
} |
42 |
} |
} |
43 |
|
|
44 |
|
|
49 |
#define DEBUG1(S,I) { char tmp[100]; wsprintf(tmp, "%s %i\n", (S), (I)); OutputDebugString(tmp); } |
#define DEBUG1(S,I) { char tmp[100]; wsprintf(tmp, "%s %i\n", (S), (I)); OutputDebugString(tmp); } |
50 |
#define DEBUG2(X,A,B) { char tmp[100]; wsprintf(tmp, "%s %i %i\n", (X), (A), (B)); OutputDebugString(tmp); } |
#define DEBUG2(X,A,B) { char tmp[100]; wsprintf(tmp, "%s %i %i\n", (X), (A), (B)); OutputDebugString(tmp); } |
51 |
#define DEBUG3(X,A,B,C){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i",(X),(A), (B), (C)); OutputDebugString(tmp); } |
#define DEBUG3(X,A,B,C){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i",(X),(A), (B), (C)); OutputDebugString(tmp); } |
52 |
|
#define DEBUG4(X,A,B,C,D){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i %i",(X),(A), (B), (C), (D)); OutputDebugString(tmp); } |
53 |
#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); } |
#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); } |
54 |
#else |
#else |
55 |
#define DEBUG(S) |
#define DEBUG(S) |
56 |
#define DEBUG1(S,I) |
#define DEBUG1(S,I) |
57 |
#define DEBUG2(X,A,B) |
#define DEBUG2(X,A,B) |
58 |
#define DEBUG3(X,A,B,C) |
#define DEBUG3(X,A,B,C) |
59 |
|
#define DEBUG4(X,A,B,C,D) |
60 |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
61 |
#endif |
#endif |
62 |
|
|
69 |
#define uint32_t unsigned int |
#define uint32_t unsigned int |
70 |
#define int64_t __int64 |
#define int64_t __int64 |
71 |
#define uint64_t unsigned __int64 |
#define uint64_t unsigned __int64 |
72 |
|
#define ptr_t uint32_t |
73 |
|
|
74 |
#define EMMS() __asm {emms} |
#define EMMS() __asm {emms} |
75 |
|
|
88 |
#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 |
89 |
|
|
90 |
// needed for timer.c |
// needed for timer.c |
91 |
static __inline int64_t read_counter() { |
static __inline int64_t |
92 |
|
read_counter() |
93 |
|
{ |
94 |
int64_t ts; |
int64_t ts; |
95 |
uint32_t ts1, ts2; |
uint32_t ts1, ts2; |
96 |
|
|
107 |
|
|
108 |
#elif defined(LINUX) || defined(DJGPP) || defined(FREEBSD) |
#elif defined(LINUX) || defined(DJGPP) || defined(FREEBSD) |
109 |
|
|
110 |
|
#include <stdio.h> |
111 |
|
#include <stdarg.h> |
112 |
|
|
113 |
|
static __inline void |
114 |
|
DPRINTF(int level, char *fmt, |
115 |
|
...) |
116 |
|
{ |
117 |
|
if ((DPRINTF_LEVEL & level)) { |
118 |
|
va_list args; |
119 |
|
char buf[DPRINTF_BUF_SZ]; |
120 |
|
|
121 |
|
va_start(args, fmt); |
122 |
|
vsprintf(buf, fmt, args); |
123 |
|
fprintf(stdout, "%s\n", buf); |
124 |
|
} |
125 |
|
} |
126 |
|
|
127 |
#ifdef _DEBUG |
#ifdef _DEBUG |
128 |
|
|
129 |
#include <stdio.h> |
#include <stdio.h> |
143 |
#define DEBUGCBR(A,B,C) |
#define DEBUGCBR(A,B,C) |
144 |
#endif |
#endif |
145 |
|
|
|
#define CACHE_LINE 16 |
|
|
|
|
146 |
#if defined(LINUX) |
#if defined(LINUX) |
147 |
|
|
148 |
#include <stdint.h> |
#include <stdint.h> |
149 |
|
|
150 |
#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
151 |
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
152 |
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)) |
153 |
|
|
154 |
#else |
#else |
155 |
|
|
174 |
"r" (&(a)), "m" (a)); |
"r" (&(a)), "m" (a)); |
175 |
#define EMMS() |
#define EMMS() |
176 |
|
|
177 |
static __inline unsigned long get_tbl(void) { |
static __inline unsigned long |
178 |
|
get_tbl(void) |
179 |
|
{ |
180 |
unsigned long tbl; |
unsigned long tbl; |
181 |
asm volatile("mftb %0" : "=r" (tbl)); |
asm volatile("mftb %0" : "=r" (tbl)); |
182 |
|
|
183 |
return tbl; |
return tbl; |
184 |
} |
} |
185 |
static __inline unsigned long get_tbu(void) { |
static __inline unsigned long |
186 |
|
get_tbu(void) |
187 |
|
{ |
188 |
unsigned long tbl; |
unsigned long tbl; |
189 |
asm volatile("mftbu %0" : "=r" (tbl)); |
asm volatile("mftbu %0" : "=r" (tbl)); |
190 |
|
|
191 |
return tbl; |
return tbl; |
192 |
} |
} |
193 |
static __inline int64_t read_counter() { |
static __inline int64_t |
194 |
|
read_counter() |
195 |
|
{ |
196 |
unsigned long tb, tu; |
unsigned long tb, tu; |
197 |
|
|
198 |
do { |
do { |
199 |
tu = get_tbu(); |
tu = get_tbu(); |
200 |
tb = get_tbl(); |
tb = get_tbl(); |
201 |
} while(tb != get_tbl()); |
} while(tb != get_tbl()); |
202 |
return (((int64_t)tu) << 32) | (int64_t)tb; |
return (((int64_t)tu) << 32) | (int64_t)tb; |
203 |
} |
} |
204 |
|
|
205 |
|
#define ptr_t uint32_t |
206 |
|
|
207 |
|
#define CACHE_LINE 16 |
208 |
|
|
209 |
|
#elif defined(ARCH_IA64) |
210 |
|
|
211 |
|
#define ptr_t uint64_t |
212 |
|
|
213 |
|
#define CACHE_LINE 32 |
214 |
|
|
215 |
|
#define EMMS() |
216 |
|
|
217 |
|
#ifdef __GNUC__ |
218 |
|
|
219 |
|
// needed for bitstream.h |
220 |
|
#define BSWAP(a) __asm__ __volatile__ ("mux1 %1 = %0, @rev" \ |
221 |
|
";;" \ |
222 |
|
"shr.u %1 = %1, 32" : "=r" (a) : "r" (a)); |
223 |
|
|
224 |
|
// rdtsc replacement for ia64 |
225 |
|
static __inline int64_t read_counter() { |
226 |
|
unsigned long result; |
227 |
|
|
228 |
|
// __asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); |
229 |
|
// while (__builtin_expect ((int) result == -1, 0)) |
230 |
|
__asm__ __volatile__("mov %0=ar.itc" : "=r"(result) :: "memory"); |
231 |
|
return result; |
232 |
|
|
233 |
|
} |
234 |
|
|
235 |
|
/* we are missing our ia64intrin.h file, but according to the |
236 |
|
Intel's ecc manual, this should be the right way ... |
237 |
|
this |
238 |
|
|
239 |
|
#elif defined(__INTEL_COMPILER) |
240 |
|
|
241 |
|
#include <ia64intrin.h> |
242 |
|
|
243 |
|
static __inline int64_t read_counter() { |
244 |
|
return __getReg(44); |
245 |
|
} |
246 |
|
|
247 |
|
#define BSWAP(a) ((unsigned int) (_m64_mux1(a, 0xb) >> 32)) |
248 |
|
*/ |
249 |
|
|
250 |
|
#else |
251 |
|
|
252 |
|
// needed for bitstream.h |
253 |
|
#define BSWAP(a) \ |
254 |
|
((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff)) |
255 |
|
|
256 |
|
// rdtsc command most likely not supported, |
257 |
|
// so just dummy code here |
258 |
|
static __inline int64_t |
259 |
|
read_counter() |
260 |
|
{ |
261 |
|
return 0; |
262 |
|
} |
263 |
|
|
264 |
|
#endif // gcc or ecc |
265 |
|
|
266 |
#else |
#else |
267 |
#define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ) |
#define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ) |
268 |
#define EMMS() __asm__("emms\n\t") |
#define EMMS() __asm__("emms\n\t") |
269 |
|
|
270 |
|
|
271 |
// needed for timer.c |
// needed for timer.c |
272 |
static __inline int64_t read_counter() { |
static __inline int64_t |
273 |
|
read_counter() |
274 |
|
{ |
275 |
int64_t ts; |
int64_t ts; |
276 |
uint32_t ts1, ts2; |
uint32_t ts1, ts2; |
277 |
|
|
278 |
__asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2)); |
__asm__ __volatile__("rdtsc\n\t":"=a"(ts1), |
279 |
|
"=d"(ts2)); |
280 |
|
|
281 |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
282 |
|
|
283 |
return ts; |
return ts; |
284 |
} |
} |
285 |
|
|
286 |
|
#define ptr_t uint32_t |
287 |
|
|
288 |
|
#define CACHE_LINE 16 |
289 |
|
|
290 |
#endif |
#endif |
291 |
|
|
292 |
#else // OTHER OS |
#else // OTHER OS |
293 |
|
|
294 |
|
|
295 |
|
#include <stdio.h> |
296 |
|
#include <stdarg.h> |
297 |
|
|
298 |
|
static __inline void |
299 |
|
DPRINTF(int level, char *fmt, ...) |
300 |
|
{ |
301 |
|
if ((DPRINTF_LEVEL & level)) { |
302 |
|
|
303 |
|
va_list args; |
304 |
|
char buf[DPRINTF_BUF_SZ]; |
305 |
|
|
306 |
|
va_start(args, fmt); |
307 |
|
vsprintf(buf, fmt, args); |
308 |
|
fprintf(stdout, "%s\n", buf); |
309 |
|
} |
310 |
|
} |
311 |
|
|
312 |
|
|
313 |
#define DEBUG(S) |
#define DEBUG(S) |
314 |
#define DEBUG1(S,I) |
#define DEBUG1(S,I) |
315 |
#define DEBUG2(X,A,B) |
#define DEBUG2(X,A,B) |
327 |
|
|
328 |
// rdtsc command most likely not supported, |
// rdtsc command most likely not supported, |
329 |
// so just dummy code here |
// so just dummy code here |
330 |
static __inline int64_t read_counter() { |
static __inline int64_t |
331 |
|
read_counter() |
332 |
|
{ |
333 |
return 0; |
return 0; |
334 |
} |
} |
335 |
|
|
336 |
|
#define ptr_t uint32_t |
337 |
|
|
338 |
#define CACHE_LINE 16 |
#define CACHE_LINE 16 |
339 |
#define CACHE_ALIGN |
#define CACHE_ALIGN |
340 |
|
|
341 |
#endif |
#endif |
342 |
|
|
343 |
#endif // _PORTAB_H_ |
#endif // _PORTAB_H_ |
|
|
|