--- portab.h 2002/03/16 22:28:37 1.3 +++ portab.h 2002/04/25 06:55:00 1.16 @@ -4,6 +4,23 @@ #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)); @@ -31,6 +48,17 @@ #define EMMS() __asm {emms} +#define CACHE_LINE 16 + +#if _MSC_VER <= 1200 +#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ + type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ + 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(alignment)) type name[(sizex)*(sizey)] +#endif + // needed for bitstream.h #define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax @@ -50,47 +78,82 @@ return ts; } -#elif defined(LINUX) || defined(DJGPP) - +#elif defined(LINUX) || defined(DJGPP) || defined(FREEBSD) #ifdef _DEBUG #include -#define DEBUG_WHERE stdout -#define DEBUG(S) fprintf(DEBUG_WHERE, "%s\n", (S)); -#define DEBUG1(S,I) fprintf(DEBUG_WHERE, "%s %i\n", (S), (I)) -#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 DEBUG_WHERE stdout +#define DEBUG(S) fprintf(DEBUG_WHERE, "%s\n", (S)); +#define DEBUG1(S,I) fprintf(DEBUG_WHERE, "%s %i\n", (S), (I)) +#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 + #if defined(LINUX) #include +#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ + type name##_storage[(sizex)*(sizey)+(alignment)-1]; \ + type * name = (type *) (((int32_t) name##_storage+(alignment - 1)) & ~((int32_t)(alignment)-1)) + #else -#define int8_t char -#define uint8_t unsigned char -#define int16_t short +#define DECLARE_ALIGNED_MATRIX(name,sizex,sizey,type,alignment) \ + __attribute__ ((__aligned__(CACHE_LINE))) type name[(sizex)*(sizey)] + +#define int8_t char +#define uint8_t unsigned char +#define int16_t short #define uint16_t unsigned short -#define int32_t int +#define int32_t int #define uint32_t unsigned int -#define int64_t long long +#define int64_t long long #define uint64_t unsigned long long #endif -#define EMMS() __asm__("emms\n\t") // needed for bitstream.h -#define BSWAP(a) __asm__ ( "bswapl %0\n" : "=r" (a) : "0" (a) ) +#ifdef ARCH_PPC + #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") + // needed for timer.c static __inline int64_t read_counter() { @@ -104,6 +167,8 @@ return ts; } +#endif + #else // OTHER OS #define DEBUG(S) @@ -111,6 +176,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 @@ -126,6 +192,9 @@ return 0; } +#define CACHE_LINE 16 +#define CACHE_ALIGN + #endif #endif // _PORTAB_H_