From 71d487d995ed8209560d8442efd34fd628a0bf02 Mon Sep 17 00:00:00 2001 From: Richard Brooksby Date: Sun, 26 Aug 2012 17:07:32 +0100 Subject: [PATCH] Fixing further pedantic compilation issues on xci3gc. Copied from Perforce Change: 179057 ServerID: perforce.ravenbrook.com --- mps/code/config.h | 58 ----------------------------------- mps/code/event.h | 1 - mps/code/eventcnv.c | 6 ++-- mps/code/eventcom.h | 75 ++++++++++++++++++++++++++++++++++++++++++++- mps/code/eventpro.c | 6 ++-- 5 files changed, 81 insertions(+), 65 deletions(-) diff --git a/mps/code/config.h b/mps/code/config.h index e27ee92ddca..435d2a9e22a 100644 --- a/mps/code/config.h +++ b/mps/code/config.h @@ -277,7 +277,6 @@ #define RememberedSummaryBLOCK 15 - /* Events * * EventBufferSIZE is the number of words in the global event buffer. @@ -286,63 +285,6 @@ #define EventBufferSIZE ((size_t)4096) #define EventStringLengthMAX ((size_t)255) /* Not including NUL */ -/* EVENT_CLOCK -- fast event timestamp clock - * - * On platforms that support it, we want to stamp events with a very cheap - * and fast high-resolution timer. - */ - -/* http://msdn.microsoft.com/en-US/library/twchhe95%28v=vs.100%29.aspx */ -#if (defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6)) && defined(MPS_BUILD_MV) - -#pragma intrinsic(__rdtsc) -typedef unsigned __int64 EventClock; -#define EVENT_CLOCK(lvalue) \ -BEGIN \ -(lvalue) = __rdtsc(); \ -END - -/* http://clang.llvm.org/docs/LanguageExtensions.html#builtins */ -#elif defined(MPS_BUILD_LL) - -#if __has_builtin(__builtin_readcyclecounter) - -typedef unsigned long long EventClock; -#define EVENT_CLOCK(lvalue) \ - BEGIN \ - (lvalue) = __builtin_readcyclecounter(); \ - END - -#endif /* __has_builtin(__builtin_readcyclecounter) */ - -#endif - -/* Assemble the rdtsc instruction */ -#if !defined(EVENT_CLOCK) && \ - (defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6)) && \ - (defined(MPS_BUILD_GC) || defined(MPS_BUILD_LL)) - -/* Use __extension__ to enable use of a 64-bit type on 32-bit pedantic GCC */ -__extension__ typedef unsigned long long EventClock; -#define EVENT_CLOCK(lvalue) \ - BEGIN \ - unsigned _l, _h; \ - __asm__ __volatile__("rdtsc" : "=a"(_l), "=d"(_h)); \ - (lvalue) = ((EventClock)_h << 32) | _l; \ - END - -#endif - -/* no fast clock, use plinth, probably from the C library */ -#ifndef EVENT_CLOCK - -#define EVENT_CLOCK(lvalue) \ - BEGIN \ - (lvalue) = mps_clock(); \ - END - -#endif - /* Assert Buffer */ diff --git a/mps/code/event.h b/mps/code/event.h index 131e95496c2..161aa32d2e5 100644 --- a/mps/code/event.h +++ b/mps/code/event.h @@ -15,7 +15,6 @@ #ifndef event_h #define event_h -#include "config.h" /* for EVENT_CLOCK */ #include "eventcom.h" #include "mpm.h" #include "eventdef.h" diff --git a/mps/code/eventcnv.c b/mps/code/eventcnv.c index 4fac8bbc4d8..10241135ceb 100644 --- a/mps/code/eventcnv.c +++ b/mps/code/eventcnv.c @@ -556,7 +556,7 @@ static void readLog(EventProc proc) printf("(t"); } break; case 'C': { - printf("%llu", eventTime+1); + EVENT_CLOCK_PRINT(stdout, eventTime+1); } break; } reportEventResults(totalEventCount); @@ -568,7 +568,9 @@ static void readLog(EventProc proc) if (eventEnabled[c]) printf(" %04X %s\n", (unsigned)c, EventCode2Name(c)); if (bucketSize == 0) - printf("\nevent clock stopped at %llu\n", eventTime); + printf("\nevent clock stopped at "); + EVENT_CLOCK_PRINT(stdout, eventTime); + printf("\n"); } } } diff --git a/mps/code/eventcom.h b/mps/code/eventcom.h index 1bf0a67c311..64fe935edde 100644 --- a/mps/code/eventcom.h +++ b/mps/code/eventcom.h @@ -10,11 +10,84 @@ #define eventcom_h #include -#include "config.h" /* for EventClock */ #include "mpmtypes.h" /* for Word */ #include "eventdef.h" +/* EVENT_CLOCK -- fast event timestamp clock + * + * On platforms that support it, we want to stamp events with a very cheap + * and fast high-resolution timer. + */ + +/* http://msdn.microsoft.com/en-US/library/twchhe95%28v=vs.100%29.aspx */ +#if (defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6)) && defined(MPS_BUILD_MV) + +#pragma intrinsic(__rdtsc) + +typedef unsigned __int64 EventClock; + +#define EVENT_CLOCK(lvalue) \ + BEGIN \ + (lvalue) = __rdtsc(); \ + END + +#define EVENT_CLOCK_PRINT(stream, clock) fprintf(stream, "%llu", clock) + +/* http://clang.llvm.org/docs/LanguageExtensions.html#builtins */ +#elif defined(MPS_BUILD_LL) + +#if __has_builtin(__builtin_readcyclecounter) + +typedef unsigned long long EventClock; + +#define EVENT_CLOCK(lvalue) \ + BEGIN \ + (lvalue) = __builtin_readcyclecounter(); \ + END + +#define EVENT_CLOCK_PRINT(stream, clock) fprintf(stream, "%llu", clock) + +#endif /* __has_builtin(__builtin_readcyclecounter) */ + +#endif + +/* Assemble the rdtsc instruction */ +#if !defined(EVENT_CLOCK) && \ + (defined(MPS_ARCH_I3) || defined(MPS_ARCH_I6)) && \ + (defined(MPS_BUILD_GC) || defined(MPS_BUILD_LL)) + +/* Use __extension__ to enable use of a 64-bit type on 32-bit pedantic GCC */ +__extension__ typedef unsigned long long EventClock; + +#define EVENT_CLOCK(lvalue) \ + BEGIN \ + unsigned _l, _h; \ + __asm__ __volatile__("rdtsc" : "=a"(_l), "=d"(_h)); \ + (lvalue) = ((EventClock)_h << 32) | _l; \ + END + +#define EVENT_CLOCK_PRINT(stream, clock) \ + fprintf(stream, "%lu", (unsigned long)clock) /* FIXME: Should be %llu */ + +#endif /* Intel, GCC or Clang */ + +/* no fast clock, use plinth, probably from the C library */ +#ifndef EVENT_CLOCK + +typedef Word EventClock; + +#define EVENT_CLOCK(lvalue) \ + BEGIN \ + (lvalue) = mps_clock(); \ + END + +#define EVENT_CLOCK_PRINT(stream, clock) \ + fprintf(stream, "%llu", (unsigned long long)clock) + +#endif + + /* Types for event fields */ typedef unsigned short EventCode; diff --git a/mps/code/eventpro.c b/mps/code/eventpro.c index ac7475498e4..1dc7a2f0a11 100644 --- a/mps/code/eventpro.c +++ b/mps/code/eventpro.c @@ -109,7 +109,7 @@ for i in range(1,15): the offsets of the fields within an event structure with the specified format. -for i in range(0, 15): +for i in range(1, 15): plist = ", ".join(["p%d" % i for i in range(0, i)]) print "#define EVENT%d_OFFSETS(%s) {%s}" % ( i, plist, @@ -117,7 +117,7 @@ for i in range(0, 15): for j in range(0, i)]) ) */ -#define EVENT0_OFFSETS() {} +#define EVENT0_OFFSETS() {0} #define EVENT1_OFFSETS(p0) {offsetof(EVENT1_STRUCT(p0), f0)} #define EVENT2_OFFSETS(p0, p1) {offsetof(EVENT2_STRUCT(p0, p1), f0), offsetof(EVENT2_STRUCT(p0, p1), f1)} #define EVENT3_OFFSETS(p0, p1, p2) {offsetof(EVENT3_STRUCT(p0, p1, p2), f0), offsetof(EVENT3_STRUCT(p0, p1, p2), f1), offsetof(EVENT3_STRUCT(p0, p1, p2), f2)} @@ -134,7 +134,7 @@ for i in range(0, 15): #define EVENT14_OFFSETS(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13) {offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f0), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f1), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f2), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f3), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f4), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f5), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f6), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f7), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f8), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f9), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f10), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f11), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f12), offsetof(EVENT14_STRUCT(p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13), f13)} static eventRecord eventTypes[] = { - {"(unused)", 0, 0, 0, "", {}}, + {"(unused)", 0, 0, 0, "", {0}}, #define EVENT_INIT(X, name, code, always, kind, count, format) \ {#name, \ code, \