From c4d25ec6e6a7800fb2dbeafc9de606587343da70 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Tue, 11 Sep 2012 18:03:28 +0100 Subject: Patching eventcom.h to provide a fast event clock on old versions of microsoft c. Copied from Perforce Change: 179431 ServerID: perforce.ravenbrook.com --- mps/code/eventcom.h | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'mps/code') diff --git a/mps/code/eventcom.h b/mps/code/eventcom.h index 9c761a552f4..cc78a45d09d 100644 --- a/mps/code/eventcom.h +++ b/mps/code/eventcom.h @@ -18,6 +18,10 @@ * * On platforms that support it, we want to stamp events with a very cheap * and fast high-resolution timer. + * + * TODO: This is a sufficiently complicated nest of ifdefs that it should + * be quarantined in its own header with KEEP OUT signs attached. + * RB 2012-09-11 */ /* TODO: Clang supposedly provides a cross-platform builtin for a fast @@ -36,9 +40,32 @@ */ #if (defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6)) && defined(MPS_BUILD_MV) +typedef unsigned __int64 EventClock; + +#if _MSC_VER >= 1400 + #pragma intrinsic(__rdtsc) -typedef unsigned __int64 EventClock; +#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 \ -- cgit v1.2.1