From ebfd52068aef3f11693da8eb38219bb21dce2a4f Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Wed, 12 Sep 2012 14:21:35 +0100 Subject: [PATCH] Removing dependency on microsoft c run-time __aullshr by treating the event clock as a struct in some circumstances. Copied from Perforce Change: 179444 ServerID: perforce.ravenbrook.com --- mps/code/eventcnv.c | 14 ++++++---- mps/code/eventcom.h | 65 +++++++++++++++++++++++++++++---------------- 2 files changed, 51 insertions(+), 28 deletions(-) diff --git a/mps/code/eventcnv.c b/mps/code/eventcnv.c index 8d22af1b898..fcd569add74 100644 --- a/mps/code/eventcnv.c +++ b/mps/code/eventcnv.c @@ -80,7 +80,8 @@ static void everror(const char *format, ...) va_list args; fflush(stdout); /* sync */ - fprintf(stderr, "%s: @%"PRIuLONGEST" ", prog, (ulongest_t)eventTime); + fprintf(stderr, "%s: @", prog); + EVENT_CLOCK_PRINT(stderr, eventTime); va_start(args, format); vfprintf(stderr, format, args); fprintf(stderr, "\n"); @@ -605,10 +606,13 @@ static void readLog(EventProc proc) printf("(t"); break; case 'C': - /* FIXME: This attempted to print the event stats on a row that - resembled a kind of final event, but the event clock no longer runs - monotonically upwards. */ - EVENT_CLOCK_PRINT(stdout, eventTime+1); + { + /* FIXME: This attempted to print the event stats on a row that + resembled a kind of final event, but the event clock no longer runs + monotonically upwards. */ + EventClock last = eventTime + 1; + EVENT_CLOCK_PRINT(stdout, last); + } break; } reportEventResults(totalEventCount); diff --git a/mps/code/eventcom.h b/mps/code/eventcom.h index cc78a45d09d..d108609715c 100644 --- a/mps/code/eventcom.h +++ b/mps/code/eventcom.h @@ -42,44 +42,63 @@ typedef unsigned __int64 EventClock; +typedef union EventClockUnion { + struct { + unsigned low, high; + } half; + unsigned __int64 whole; +} EventClockUnion; + #if _MSC_VER >= 1400 #pragma intrinsic(__rdtsc) -#else /* _MSC_VER < 1400 */ - -/* Fake the __rdtsc intrinsic for old Microsoft C versions. */ -static __inline unsigned __int64 __rdtsc() -{ - union { - struct { - unsigned low, high; - } half; - unsigned __int64 whole; - } li; - __asm { - __asm __emit 0fh __asm __emit 031h ; rdtsc - mov li.half.high, edx - mov li.half.low, eax - } - return li.whole; -} - -#endif /* _MSC_VER >= 1400 */ - #define EVENT_CLOCK(lvalue) \ BEGIN \ (lvalue) = __rdtsc(); \ END -#define EVENT_CLOCK_PRINT(stream, clock) fprintf(stream, "%llX", clock) +#else /* _MSC_VER < 1400 */ + +/* Fake the __rdtsc intrinsic for old Microsoft C versions. */ + +#define EVENT_CLOCK(lvalue) \ + BEGIN \ + EventClockUnion ecu; \ + __asm { \ + __asm __emit 0fh __asm __emit 031h ; rdtsc \ + mov ecu.half.high, edx \ + mov ecu.half.low, eax \ + } \ + (lvalue) = ecu.whole; \ + END + +#endif /* _MSC_VER < 1400 */ #if defined(MPS_ARCH_I3) + +/* We can't use a shift to get the top half of the 64-bit event clock, + because that introduces a dependency on `__aullshr` in the C run-time. */ + +#define EVENT_CLOCK_PRINT(stream, clock) \ + fprintf(stream, "%08lX%08lX", \ + (*(EventClockUnion *)&(clock)).half.high, \ + (*(EventClockUnion *)&(clock)).half.low) + #define EVENT_CLOCK_WRITE(stream, clock) \ - WriteF(stream, "$W$W", (WriteFW)((clock) >> 32), (WriteFW)clock, NULL) + WriteF(stream, "$W$W", \ + (*(EventClockUnion *)&(clock)).half.high, \ + (*(EventClockUnion *)&(clock)).half.low, \ + NULL) + #elif defined(MPS_ARCH_I6) + +#define EVENT_CLOCK_PRINT(stream, clock) \ + fprintf(stream, "%016lX", (clock)); + #define EVENT_CLOCK_WRITE(stream, clock) \ WriteF(stream, "$W", (WriteFW)(clock), NULL) + #endif #endif /* Microsoft C on Intel */