1 |
Isibaar |
1.1 |
#ifndef _PORTAB_H_ |
2 |
|
|
#define _PORTAB_H_ |
3 |
|
|
|
4 |
|
|
#if defined(WIN32) |
5 |
|
|
|
6 |
|
|
#include <windows.h> |
7 |
|
|
|
8 |
h |
1.14 |
#define DEBUGCBR(A,B,C) { char tmp[100]; wsprintf(tmp, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C)); OutputDebugString(tmp); } |
9 |
|
|
|
10 |
h |
1.2 |
#ifdef _DEBUG |
11 |
Isibaar |
1.1 |
#define DEBUG(S) OutputDebugString((S)); |
12 |
|
|
#define DEBUG1(S,I) { char tmp[100]; wsprintf(tmp, "%s %i\n", (S), (I)); OutputDebugString(tmp); } |
13 |
|
|
#define DEBUG2(X,A,B) { char tmp[100]; wsprintf(tmp, "%s %i %i\n", (X), (A), (B)); OutputDebugString(tmp); } |
14 |
|
|
#define DEBUG3(X,A,B,C){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i",(X),(A), (B), (C)); OutputDebugString(tmp); } |
15 |
|
|
#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); } |
16 |
h |
1.2 |
#else |
17 |
|
|
#define DEBUG(S) |
18 |
|
|
#define DEBUG1(S,I) |
19 |
|
|
#define DEBUG2(X,A,B) |
20 |
|
|
#define DEBUG3(X,A,B,C) |
21 |
|
|
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
22 |
|
|
#endif |
23 |
Isibaar |
1.1 |
|
24 |
|
|
|
25 |
|
|
#define int8_t char |
26 |
|
|
#define uint8_t unsigned char |
27 |
|
|
#define int16_t short |
28 |
|
|
#define uint16_t unsigned short |
29 |
|
|
#define int32_t int |
30 |
|
|
#define uint32_t unsigned int |
31 |
|
|
#define int64_t __int64 |
32 |
|
|
#define uint64_t unsigned __int64 |
33 |
|
|
|
34 |
|
|
#define EMMS() __asm {emms} |
35 |
|
|
|
36 |
Isibaar |
1.4 |
#define CACHE_LINE 16 |
37 |
edgomez |
1.9 |
|
38 |
suxen_drol |
1.7 |
#if _MSC_VER <= 1200 |
39 |
h |
1.10 |
#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
40 |
edgomez |
1.9 |
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
41 |
|
|
type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1)) |
42 |
suxen_drol |
1.7 |
#else |
43 |
h |
1.10 |
#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
44 |
edgomez |
1.11 |
__declspec(align(alignment)) type name[(sizex)*(sizey)] |
45 |
suxen_drol |
1.7 |
#endif |
46 |
Isibaar |
1.4 |
|
47 |
Isibaar |
1.1 |
// needed for bitstream.h |
48 |
|
|
#define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax |
49 |
|
|
|
50 |
|
|
// needed for timer.c |
51 |
|
|
static __inline int64_t read_counter() { |
52 |
|
|
int64_t ts; |
53 |
|
|
uint32_t ts1, ts2; |
54 |
|
|
|
55 |
|
|
__asm { |
56 |
|
|
rdtsc |
57 |
|
|
mov ts1, eax |
58 |
|
|
mov ts2, edx |
59 |
|
|
} |
60 |
|
|
|
61 |
|
|
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
62 |
|
|
|
63 |
|
|
return ts; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
#elif defined(LINUX) || defined(DJGPP) |
67 |
|
|
|
68 |
chl |
1.3 |
#ifdef _DEBUG |
69 |
|
|
|
70 |
Isibaar |
1.1 |
#include <stdio.h> |
71 |
edgomez |
1.9 |
#define DEBUG_WHERE stdout |
72 |
|
|
#define DEBUG(S) fprintf(DEBUG_WHERE, "%s\n", (S)); |
73 |
|
|
#define DEBUG1(S,I) fprintf(DEBUG_WHERE, "%s %i\n", (S), (I)) |
74 |
|
|
#define DEBUG2(S,A,B) fprintf(DEBUG_WHERE, "%s%i=%i\n", (S), (A), (B)) |
75 |
|
|
#define DEBUG3(S,A,B,C) fprintf(DEBUG_WHERE, "%s %i %x %x\n", (S), (A), (B), (C)) |
76 |
Isibaar |
1.1 |
#define DEBUG8(S,A,B,C,D,E,F,G,H) |
77 |
h |
1.14 |
#define DEBUGCBR(A,B,C) fprintf(DEBUG_WHERE, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C)) |
78 |
chl |
1.3 |
#else |
79 |
|
|
#define DEBUG(S) |
80 |
|
|
#define DEBUG1(S,I) |
81 |
|
|
#define DEBUG2(X,A,B) |
82 |
|
|
#define DEBUG3(X,A,B,C) |
83 |
|
|
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
84 |
h |
1.14 |
#define DEBUGCBR(A,B,C) |
85 |
chl |
1.3 |
#endif |
86 |
Isibaar |
1.1 |
|
87 |
Isibaar |
1.4 |
#define CACHE_LINE 16 |
88 |
|
|
|
89 |
Isibaar |
1.1 |
#if defined(LINUX) |
90 |
|
|
|
91 |
|
|
#include <stdint.h> |
92 |
|
|
|
93 |
canard |
1.8 |
#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
94 |
|
|
type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ |
95 |
edgomez |
1.9 |
type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1)) |
96 |
canard |
1.8 |
|
97 |
Isibaar |
1.1 |
#else |
98 |
|
|
|
99 |
edgomez |
1.9 |
#define #define #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ |
100 |
|
|
__attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)] |
101 |
|
|
|
102 |
|
|
#define int8_t char |
103 |
|
|
#define uint8_t unsigned char |
104 |
|
|
#define int16_t short |
105 |
Isibaar |
1.1 |
#define uint16_t unsigned short |
106 |
edgomez |
1.9 |
#define int32_t int |
107 |
Isibaar |
1.1 |
#define uint32_t unsigned int |
108 |
edgomez |
1.9 |
#define int64_t long long |
109 |
Isibaar |
1.1 |
#define uint64_t unsigned long long |
110 |
|
|
|
111 |
|
|
#endif |
112 |
|
|
|
113 |
|
|
|
114 |
|
|
// needed for bitstream.h |
115 |
canard |
1.5 |
#ifdef ARCH_PPC |
116 |
canard |
1.13 |
#define BSWAP(a) __asm__ __volatile__ ( "lwbrx %0,0,%1; eieio" : "=r" (a) : \ |
117 |
canard |
1.5 |
"r" (&(a)), "m" (a)); |
118 |
|
|
#define EMMS() |
119 |
canard |
1.12 |
|
120 |
|
|
static __inline unsigned long get_tbl(void) { |
121 |
|
|
unsigned long tbl; |
122 |
|
|
asm volatile("mftb %0" : "=r" (tbl)); |
123 |
|
|
return tbl; |
124 |
|
|
} |
125 |
|
|
static __inline unsigned long get_tbu(void) { |
126 |
|
|
unsigned long tbl; |
127 |
|
|
asm volatile("mftbu %0" : "=r" (tbl)); |
128 |
|
|
return tbl; |
129 |
|
|
} |
130 |
|
|
static __inline int64_t read_counter() { |
131 |
|
|
unsigned long tb, tu; |
132 |
|
|
do { |
133 |
canard |
1.13 |
tu = get_tbu(); |
134 |
canard |
1.12 |
tb = get_tbl(); |
135 |
|
|
} while(tb != get_tbl()); |
136 |
|
|
return (((int64_t)tu) << 32) | (int64_t)tb; |
137 |
|
|
} |
138 |
canard |
1.5 |
#else |
139 |
|
|
#define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ) |
140 |
|
|
#define EMMS() __asm__("emms\n\t") |
141 |
edgomez |
1.9 |
|
142 |
Isibaar |
1.1 |
|
143 |
|
|
// needed for timer.c |
144 |
|
|
static __inline int64_t read_counter() { |
145 |
|
|
int64_t ts; |
146 |
|
|
uint32_t ts1, ts2; |
147 |
|
|
|
148 |
|
|
__asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2)); |
149 |
|
|
|
150 |
|
|
ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); |
151 |
|
|
|
152 |
|
|
return ts; |
153 |
|
|
} |
154 |
edgomez |
1.9 |
|
155 |
|
|
#endif |
156 |
Isibaar |
1.1 |
|
157 |
|
|
#else // OTHER OS |
158 |
|
|
|
159 |
|
|
#define DEBUG(S) |
160 |
|
|
#define DEBUG1(S,I) |
161 |
|
|
#define DEBUG2(X,A,B) |
162 |
|
|
#define DEBUG3(X,A,B,C) |
163 |
|
|
#define DEBUG8(X,A,B,C,D,E,F,G,H) |
164 |
h |
1.14 |
#define DEBUGCBR(A,B,C) |
165 |
Isibaar |
1.1 |
|
166 |
|
|
#include <inttypes.h> |
167 |
|
|
|
168 |
|
|
#define EMMS() |
169 |
|
|
|
170 |
|
|
// needed for bitstream.h |
171 |
|
|
#define BSWAP(a) \ |
172 |
|
|
((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff)) |
173 |
|
|
|
174 |
|
|
// rdtsc command most likely not supported, |
175 |
|
|
// so just dummy code here |
176 |
|
|
static __inline int64_t read_counter() { |
177 |
|
|
return 0; |
178 |
|
|
} |
179 |
Isibaar |
1.4 |
|
180 |
|
|
#define CACHE_LINE 16 |
181 |
|
|
#define CACHE_ALIGN |
182 |
Isibaar |
1.1 |
|
183 |
|
|
#endif |
184 |
|
|
|
185 |
|
|
#endif // _PORTAB_H_ |
186 |
|
|
|