4 |
#if defined(WIN32) |
#if defined(WIN32) |
5 |
|
|
6 |
#include <windows.h> |
#include <windows.h> |
7 |
|
#include <stdio.h> |
8 |
|
|
9 |
|
|
10 |
|
#define DPRINTF_BUF_SZ 1024 |
11 |
|
static void |
12 |
|
dprintf(char *fmt, |
13 |
|
...) |
14 |
|
{ |
15 |
|
va_list args; |
16 |
|
char buf[DPRINTF_BUF_SZ]; |
17 |
|
|
18 |
|
va_start(args, fmt); |
19 |
|
vsprintf(buf, fmt, args); |
20 |
|
OutputDebugString(buf); |
21 |
|
fprintf(stdout, "%s\n", buf); |
22 |
|
} |
23 |
|
|
24 |
|
|
25 |
|
#define DEBUGCBR(A,B,C) { char tmp[100]; wsprintf(tmp, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C)); OutputDebugString(tmp); } |
26 |
|
|
27 |
#ifdef _DEBUG |
#ifdef _DEBUG |
28 |
#define DEBUG(S) OutputDebugString((S)); |
#define DEBUG(S) OutputDebugString((S)); |
29 |
#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); } |
30 |
#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); } |
31 |
#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); } |
32 |
|
#define DEBUG4(X,A,B,C,D){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i %i",(X),(A), (B), (C), (D)); OutputDebugString(tmp); } |
33 |
#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); } |
34 |
#else |
#else |
35 |
#define DEBUG(S) |
#define DEBUG(S) |
36 |
#define DEBUG1(S,I) |
#define DEBUG1(S,I) |
37 |
#define DEBUG2(X,A,B) |
#define DEBUG2(X,A,B) |
38 |
#define DEBUG3(X,A,B,C) |
#define DEBUG3(X,A,B,C) |
39 |
|
#define DEBUG4(X,A,B,C,D) |
40 |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
41 |
#endif |
#endif |
42 |
|
|
49 |
#define uint32_t unsigned int |
#define uint32_t unsigned int |
50 |
#define int64_t __int64 |
#define int64_t __int64 |
51 |
#define uint64_t unsigned __int64 |
#define uint64_t unsigned __int64 |
52 |
|
#define ptr_t uint32_t |
53 |
|
|
54 |
#define EMMS() __asm {emms} |
#define EMMS() __asm {emms} |
55 |
|
|
68 |
#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 |
69 |
|
|
70 |
// needed for timer.c |
// needed for timer.c |
71 |
static __inline int64_t read_counter() { |
static __inline int64_t |
72 |
|
read_counter() |
73 |
|
{ |
74 |
int64_t ts; |
int64_t ts; |
75 |
uint32_t ts1, ts2; |
uint32_t ts1, ts2; |
76 |
|
|
85 |
return ts; |
return ts; |
86 |
} |
} |
87 |
|
|
88 |
#elif defined(LINUX) || defined(DJGPP) |
#elif defined(LINUX) || defined(DJGPP) || defined(FREEBSD) |
|
|
|
89 |
|
|
90 |
#ifdef _DEBUG |
#ifdef _DEBUG |
91 |
|
|
96 |
#define DEBUG2(S,A,B) fprintf(DEBUG_WHERE, "%s%i=%i\n", (S), (A), (B)) |
#define DEBUG2(S,A,B) fprintf(DEBUG_WHERE, "%s%i=%i\n", (S), (A), (B)) |
97 |
#define DEBUG3(S,A,B,C) fprintf(DEBUG_WHERE, "%s %i %x %x\n", (S), (A), (B), (C)) |
#define DEBUG3(S,A,B,C) fprintf(DEBUG_WHERE, "%s %i %x %x\n", (S), (A), (B), (C)) |
98 |
#define DEBUG8(S,A,B,C,D,E,F,G,H) |
#define DEBUG8(S,A,B,C,D,E,F,G,H) |
99 |
|
#define DEBUGCBR(A,B,C) fprintf(DEBUG_WHERE, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C)) |
100 |
#else |
#else |
101 |
#define DEBUG(S) |
#define DEBUG(S) |
102 |
#define DEBUG1(S,I) |
#define DEBUG1(S,I) |
103 |
#define DEBUG2(X,A,B) |
#define DEBUG2(X,A,B) |
104 |
#define DEBUG3(X,A,B,C) |
#define DEBUG3(X,A,B,C) |
105 |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
106 |
|
#define DEBUGCBR(A,B,C) |
107 |
#endif |
#endif |
108 |
|
|
|
#define CACHE_LINE 16 |
|
|
|
|
109 |
#if defined(LINUX) |
#if defined(LINUX) |
110 |
|
|
111 |
#include <stdint.h> |
#include <stdint.h> |
112 |
|
|
113 |
#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
114 |
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
115 |
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)) |
116 |
|
|
117 |
#else |
#else |
118 |
|
|
119 |
#define #define #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
120 |
__attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)] |
__attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)] |
121 |
|
|
122 |
#define int8_t char |
#define int8_t char |
133 |
|
|
134 |
// needed for bitstream.h |
// needed for bitstream.h |
135 |
#ifdef ARCH_PPC |
#ifdef ARCH_PPC |
136 |
#define BSWAP(a) __asm__ ( "lwbrx %0,0,%1; eieio" : "=r" (a) : \ |
#define BSWAP(a) __asm__ __volatile__ ( "lwbrx %0,0,%1; eieio" : "=r" (a) : \ |
137 |
"r" (&(a)), "m" (a)); |
"r" (&(a)), "m" (a)); |
138 |
#define EMMS() |
#define EMMS() |
139 |
|
|
140 |
static __inline unsigned long get_tbl(void) { |
static __inline unsigned long |
141 |
|
get_tbl(void) |
142 |
|
{ |
143 |
unsigned long tbl; |
unsigned long tbl; |
144 |
asm volatile("mftb %0" : "=r" (tbl)); |
asm volatile("mftb %0" : "=r" (tbl)); |
145 |
|
|
146 |
return tbl; |
return tbl; |
147 |
} |
} |
148 |
static __inline unsigned long get_tbu(void) { |
static __inline unsigned long |
149 |
|
get_tbu(void) |
150 |
|
{ |
151 |
unsigned long tbl; |
unsigned long tbl; |
152 |
asm volatile("mftbu %0" : "=r" (tbl)); |
asm volatile("mftbu %0" : "=r" (tbl)); |
153 |
|
|
154 |
return tbl; |
return tbl; |
155 |
} |
} |
156 |
static __inline int64_t read_counter() { |
static __inline int64_t |
157 |
|
read_counter() |
158 |
|
{ |
159 |
unsigned long tb, tu; |
unsigned long tb, tu; |
160 |
|
|
161 |
do { |
do { |
|
tb = get_tbl(); |
|
162 |
tu = get_tbu(); |
tu = get_tbu(); |
163 |
|
tb = get_tbl(); |
164 |
} while(tb != get_tbl()); |
} while(tb != get_tbl()); |
165 |
return (((int64_t)tu) << 32) | (int64_t)tb; |
return (((int64_t)tu) << 32) | (int64_t)tb; |
166 |
} |
} |
167 |
|
|
168 |
|
#define ptr_t uint32_t |
169 |
|
|
170 |
|
#define CACHE_LINE 16 |
171 |
|
|
172 |
|
#elif defined(ARCH_IA64) |
173 |
|
|
174 |
|
#define ptr_t uint64_t |
175 |
|
|
176 |
|
#define CACHE_LINE 32 |
177 |
|
|
178 |
|
#define EMMS() |
179 |
|
|
180 |
|
// needed for bitstream.h |
181 |
|
#define BSWAP(a) \ |
182 |
|
((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff)) |
183 |
|
|
184 |
|
// rdtsc command most likely not supported, |
185 |
|
// so just dummy code here |
186 |
|
static __inline int64_t read_counter() { |
187 |
|
return 0; |
188 |
|
} |
189 |
|
|
190 |
#else |
#else |
191 |
#define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ) |
#define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ) |
192 |
#define EMMS() __asm__("emms\n\t") |
#define EMMS() __asm__("emms\n\t") |
193 |
|
|
194 |
|
|
195 |
// needed for timer.c |
// needed for timer.c |
196 |
static __inline int64_t read_counter() { |
static __inline int64_t |
197 |
|
read_counter() |
198 |
|
{ |
199 |
int64_t ts; |
int64_t ts; |
200 |
uint32_t ts1, ts2; |
uint32_t ts1, ts2; |
201 |
|
|
202 |
__asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2)); |
__asm__ __volatile__("rdtsc\n\t":"=a"(ts1), |
203 |
|
"=d"(ts2)); |
204 |
|
|
205 |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
206 |
|
|
207 |
return ts; |
return ts; |
208 |
} |
} |
209 |
|
|
210 |
|
#define ptr_t uint32_t |
211 |
|
|
212 |
|
#define CACHE_LINE 16 |
213 |
|
|
214 |
#endif |
#endif |
215 |
|
|
216 |
#else // OTHER OS |
#else // OTHER OS |
220 |
#define DEBUG2(X,A,B) |
#define DEBUG2(X,A,B) |
221 |
#define DEBUG3(X,A,B,C) |
#define DEBUG3(X,A,B,C) |
222 |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
223 |
|
#define DEBUGCBR(A,B,C) |
224 |
|
|
225 |
#include <inttypes.h> |
#include <inttypes.h> |
226 |
|
|
232 |
|
|
233 |
// rdtsc command most likely not supported, |
// rdtsc command most likely not supported, |
234 |
// so just dummy code here |
// so just dummy code here |
235 |
static __inline int64_t read_counter() { |
static __inline int64_t |
236 |
|
read_counter() |
237 |
|
{ |
238 |
return 0; |
return 0; |
239 |
} |
} |
240 |
|
|
241 |
|
#define ptr_t uint32_t |
242 |
|
|
243 |
#define CACHE_LINE 16 |
#define CACHE_LINE 16 |
244 |
#define CACHE_ALIGN |
#define CACHE_ALIGN |
245 |
|
|
246 |
#endif |
#endif |
247 |
|
|
248 |
#endif // _PORTAB_H_ |
#endif // _PORTAB_H_ |
|
|
|