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 |
|
|
67 |
#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 |
68 |
|
|
69 |
// needed for timer.c |
// needed for timer.c |
70 |
static __inline int64_t read_counter() { |
static __inline int64_t |
71 |
|
read_counter() |
72 |
|
{ |
73 |
int64_t ts; |
int64_t ts; |
74 |
uint32_t ts1, ts2; |
uint32_t ts1, ts2; |
75 |
|
|
84 |
return ts; |
return ts; |
85 |
} |
} |
86 |
|
|
87 |
#elif defined(LINUX) || defined(DJGPP) |
#elif defined(LINUX) || defined(DJGPP) || defined(FREEBSD) |
|
|
|
88 |
|
|
89 |
#ifdef _DEBUG |
#ifdef _DEBUG |
90 |
|
|
95 |
#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)) |
96 |
#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)) |
97 |
#define DEBUG8(S,A,B,C,D,E,F,G,H) |
#define DEBUG8(S,A,B,C,D,E,F,G,H) |
98 |
|
#define DEBUGCBR(A,B,C) fprintf(DEBUG_WHERE, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C)) |
99 |
#else |
#else |
100 |
#define DEBUG(S) |
#define DEBUG(S) |
101 |
#define DEBUG1(S,I) |
#define DEBUG1(S,I) |
102 |
#define DEBUG2(X,A,B) |
#define DEBUG2(X,A,B) |
103 |
#define DEBUG3(X,A,B,C) |
#define DEBUG3(X,A,B,C) |
104 |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
105 |
|
#define DEBUGCBR(A,B,C) |
106 |
#endif |
#endif |
107 |
|
|
108 |
#define CACHE_LINE 16 |
#define CACHE_LINE 16 |
117 |
|
|
118 |
#else |
#else |
119 |
|
|
120 |
#define #define #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
121 |
__attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)] |
__attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)] |
122 |
|
|
123 |
#define int8_t char |
#define int8_t char |
138 |
"r" (&(a)), "m" (a)); |
"r" (&(a)), "m" (a)); |
139 |
#define EMMS() |
#define EMMS() |
140 |
|
|
141 |
static __inline unsigned long get_tbl(void) { |
static __inline unsigned long |
142 |
|
get_tbl(void) |
143 |
|
{ |
144 |
unsigned long tbl; |
unsigned long tbl; |
145 |
asm volatile("mftb %0" : "=r" (tbl)); |
asm volatile("mftb %0" : "=r" (tbl)); |
146 |
|
|
147 |
return tbl; |
return tbl; |
148 |
} |
} |
149 |
static __inline unsigned long get_tbu(void) { |
static __inline unsigned long |
150 |
|
get_tbu(void) |
151 |
|
{ |
152 |
unsigned long tbl; |
unsigned long tbl; |
153 |
asm volatile("mftbu %0" : "=r" (tbl)); |
asm volatile("mftbu %0" : "=r" (tbl)); |
154 |
|
|
155 |
return tbl; |
return tbl; |
156 |
} |
} |
157 |
static __inline int64_t read_counter() { |
static __inline int64_t |
158 |
|
read_counter() |
159 |
|
{ |
160 |
unsigned long tb, tu; |
unsigned long tb, tu; |
161 |
|
|
162 |
do { |
do { |
163 |
tu = get_tbu(); |
tu = get_tbu(); |
164 |
tb = get_tbl(); |
tb = get_tbl(); |
171 |
|
|
172 |
|
|
173 |
// needed for timer.c |
// needed for timer.c |
174 |
static __inline int64_t read_counter() { |
static __inline int64_t |
175 |
|
read_counter() |
176 |
|
{ |
177 |
int64_t ts; |
int64_t ts; |
178 |
uint32_t ts1, ts2; |
uint32_t ts1, ts2; |
179 |
|
|
180 |
__asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2)); |
__asm__ __volatile__("rdtsc\n\t":"=a"(ts1), |
181 |
|
"=d"(ts2)); |
182 |
|
|
183 |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
184 |
|
|
194 |
#define DEBUG2(X,A,B) |
#define DEBUG2(X,A,B) |
195 |
#define DEBUG3(X,A,B,C) |
#define DEBUG3(X,A,B,C) |
196 |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
197 |
|
#define DEBUGCBR(A,B,C) |
198 |
|
|
199 |
#include <inttypes.h> |
#include <inttypes.h> |
200 |
|
|
206 |
|
|
207 |
// rdtsc command most likely not supported, |
// rdtsc command most likely not supported, |
208 |
// so just dummy code here |
// so just dummy code here |
209 |
static __inline int64_t read_counter() { |
static __inline int64_t |
210 |
|
read_counter() |
211 |
|
{ |
212 |
return 0; |
return 0; |
213 |
} |
} |
214 |
|
|
218 |
#endif |
#endif |
219 |
|
|
220 |
#endif // _PORTAB_H_ |
#endif // _PORTAB_H_ |
|
|
|