--- portab.h 2002/03/28 23:38:50 1.10 +++ portab.h 2002/05/06 03:51:43 1.17 @@ -4,18 +4,37 @@ #if defined(WIN32) #include +#include + + +#define DPRINTF_BUF_SZ 1024 +static void dprintf(char *fmt, ...) +{ + va_list args; + char buf[DPRINTF_BUF_SZ]; + + va_start(args, fmt); + vsprintf(buf, fmt, args); + OutputDebugString(buf); + fprintf(stdout, "%s\n", buf); +} + + +#define DEBUGCBR(A,B,C) { char tmp[100]; wsprintf(tmp, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C)); OutputDebugString(tmp); } #ifdef _DEBUG #define DEBUG(S) OutputDebugString((S)); #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 DEBUG4(X,A,B,C,D){ char tmp[1000]; wsprintf(tmp,"%s %i %i %i %i",(X),(A), (B), (C), (D)); 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 DEBUG4(X,A,B,C,D) #define DEBUG8(X,A,B,C,D,E,F,G,H) #endif @@ -39,7 +58,7 @@ type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1)) #else #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ - __declspec(align(CACHE_LINE)) type name[(sizex)*(sizey)] + __declspec(align(alignment)) type name[(sizex)*(sizey)] #endif // needed for bitstream.h @@ -61,8 +80,7 @@ return ts; } -#elif defined(LINUX) || defined(DJGPP) - +#elif defined(LINUX) || defined(DJGPP) || defined(FREEBSD) #ifdef _DEBUG @@ -73,12 +91,14 @@ #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) +#define DEBUGCBR(A,B,C) fprintf(DEBUG_WHERE, "CBR: frame: %i, quant: %i, deviation: %i\n", (A), (B), (C)) #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) +#define DEBUGCBR(A,B,C) #endif #define CACHE_LINE 16 @@ -93,7 +113,7 @@ #else -#define #define #define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ +#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ __attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)] #define int8_t char @@ -110,9 +130,28 @@ // needed for bitstream.h #ifdef ARCH_PPC - #define BSWAP(a) __asm__ ( "lwbrx %0,0,%1; eieio" : "=r" (a) : \ + #define BSWAP(a) __asm__ __volatile__ ( "lwbrx %0,0,%1; eieio" : "=r" (a) : \ "r" (&(a)), "m" (a)); #define EMMS() + + static __inline unsigned long get_tbl(void) { + unsigned long tbl; + asm volatile("mftb %0" : "=r" (tbl)); + return tbl; + } + static __inline unsigned long get_tbu(void) { + unsigned long tbl; + asm volatile("mftbu %0" : "=r" (tbl)); + return tbl; + } + static __inline int64_t read_counter() { + unsigned long tb, tu; + do { + tu = get_tbu(); + tb = get_tbl(); + } while(tb != get_tbl()); + return (((int64_t)tu) << 32) | (int64_t)tb; + } #else #define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ) #define EMMS() __asm__("emms\n\t") @@ -139,6 +178,7 @@ #define DEBUG2(X,A,B) #define DEBUG3(X,A,B,C) #define DEBUG8(X,A,B,C,D,E,F,G,H) +#define DEBUGCBR(A,B,C) #include