--- portab.h 2002/04/25 06:55:00 1.16 +++ portab.h 2002/06/20 14:05:57 1.22 @@ -8,7 +8,9 @@ #define DPRINTF_BUF_SZ 1024 -static void dprintf(char *fmt, ...) +static void +DPRINTF(char *fmt, + ...) { va_list args; char buf[DPRINTF_BUF_SZ]; @@ -27,12 +29,14 @@ #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 @@ -45,6 +49,7 @@ #define uint32_t unsigned int #define int64_t __int64 #define uint64_t unsigned __int64 +#define ptr_t uint32_t #define EMMS() __asm {emms} @@ -63,23 +68,40 @@ #define BSWAP(a) __asm mov eax,a __asm bswap eax __asm mov a, eax // needed for timer.c -static __inline int64_t read_counter() { +static __inline int64_t +read_counter() +{ int64_t ts; uint32_t ts1, ts2; __asm { rdtsc - mov ts1, eax - mov ts2, edx + mov ts1, eax + mov ts2, edx } - + ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); - + return ts; } #elif defined(LINUX) || defined(DJGPP) || defined(FREEBSD) +#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); + fprintf(stdout, "%s\n", buf); +} + #ifdef _DEBUG #include @@ -99,15 +121,13 @@ #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)) + type * name = (type *) (((ptr_t) name##_storage+(alignment - 1)) & ~((ptr_t)(alignment)-1)) #else @@ -128,48 +148,104 @@ // needed for bitstream.h #ifdef ARCH_PPC - #define BSWAP(a) __asm__ __volatile__ ( "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() +#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; +} + +#define ptr_t uint32_t + +#define CACHE_LINE 16 + +#elif defined(ARCH_IA64) + +#define ptr_t uint64_t + +#define CACHE_LINE 32 + +#define EMMS() + +// needed for bitstream.h +#define BSWAP(a) \ + ((a) = ( ((a)&0xff)<<24) | (((a)&0xff00)<<8) | (((a)>>8)&0xff00) | (((a)>>24)&0xff)) + +// rdtsc command most likely not supported, +// so just dummy code here +static __inline int64_t read_counter() { + return 0; +} - 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") +#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() { - int64_t ts; - uint32_t ts1, ts2; +static __inline int64_t +read_counter() +{ + int64_t ts; + uint32_t ts1, ts2; - __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), "=d"(ts2)); + __asm__ __volatile__("rdtsc\n\t":"=a"(ts1), + "=d"(ts2)); - ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); + ts = ((uint64_t) ts2 << 32) | ((uint64_t) ts1); - return ts; + return ts; } +#define ptr_t uint32_t + +#define CACHE_LINE 16 + #endif -#else // OTHER OS +#else // OTHER OS + + +#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); + fprintf(stdout, "%s\n", buf); +} + #define DEBUG(S) #define DEBUG1(S,I) @@ -188,14 +264,17 @@ // rdtsc command most likely not supported, // so just dummy code here -static __inline int64_t read_counter() { +static __inline int64_t +read_counter() +{ return 0; } +#define ptr_t uint32_t + #define CACHE_LINE 16 #define CACHE_ALIGN #endif -#endif // _PORTAB_H_ - +#endif // _PORTAB_H_