Replace a renaming in a third-party file with a #define

Our use of the clock-cycle counter from FFTW involved a rename of its
type ticks to our type CycleCounterTicks. This unnaturally bulks up
the diff from upstream, so undo it and use a simple #define to achieve
the same effect, as seen by our code.

Task-number: QTBUG-126080
Change-Id: Icbe9c413b73dd9213b95f183b71585f4a9c38de1
Reviewed-by: Kai Köhne <kai.koehne@qt.io>
(cherry picked from commit ed7becd9cba582640f19704b5c439e5f6807bc29)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Edward Welbourne 2024-06-11 18:17:20 +02:00 committed by Qt Cherry-pick Bot
parent 1c7c4c5ac9
commit 35062f6510

View File

@ -31,12 +31,12 @@
/* To use the cycle counters in your code, simply #include "cycle.h" (this
file), and then use the functions/macros:
CycleCounterTicks getticks(void);
ticks getticks(void);
CycleCounterTicks is an opaque typedef defined below, representing the current time.
ticks is an opaque typedef defined below, representing the current time.
You extract the elapsed time between two calls to gettick() via:
double elapsed(CycleCounterTicks t1, CycleCounterTicks t0);
double elapsed(ticks t1, ticks t0);
which returns a double-precision variable in arbitrary units. You
are not expected to convert this into human units like seconds; it
@ -77,10 +77,11 @@
dnl ---------------------------------------------------------------------
*/
/***************************************************************************/
#ifndef QBENCHLIB_CYCLE_H
#define QBENCHLIB_CYCLE_H
#define ticks CycleCounterTicks
/***************************************************************************/
#if TIME_WITH_SYS_TIME
# include <sys/time.h>
@ -93,7 +94,7 @@
# endif
#endif
#define INLINE_ELAPSED(INL) static INL double elapsed(CycleCounterTicks t1, CycleCounterTicks t0) \
#define INLINE_ELAPSED(INL) static INL double elapsed(ticks t1, ticks t0) \
{ \
return (double)(t1 - t0); \
}
@ -101,7 +102,7 @@
/*----------------------------------------------------------------*/
/* Solaris */
#if defined(HAVE_GETHRTIME) && defined(HAVE_HRTIME_T) && !defined(HAVE_TICK_COUNTER)
typedef hrtime_t CycleCounterTicks;
typedef hrtime_t ticks;
#define getticks gethrtime
@ -113,16 +114,16 @@ INLINE_ELAPSED(inline)
/*----------------------------------------------------------------*/
/* AIX v. 4+ routines to read the real-time clock or time-base register */
#if defined(HAVE_READ_REAL_TIME) && defined(HAVE_TIME_BASE_TO_TIME) && !defined(HAVE_TICK_COUNTER)
typedef timebasestruct_t CycleCounterTicks;
typedef timebasestruct_t ticks;
static inline CycleCounterTicks getticks(void)
static inline ticks getticks(void)
{
CycleCounterTicks t;
ticks t;
read_real_time(&t, TIMEBASE_SZ);
return t;
}
static inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0) /* time in nanoseconds */
static inline double elapsed(ticks t1, ticks t0) /* time in nanoseconds */
{
time_base_to_time(&t1, TIMEBASE_SZ);
time_base_to_time(&t0, TIMEBASE_SZ);
@ -137,9 +138,9 @@ static inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0) /* time
* PowerPC ``cycle'' counter using the time base register.
*/
#if ((defined(__GNUC__) && (defined(__powerpc__) || defined(__ppc__))) || (defined(__MWERKS__) && defined(macintosh))) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long long CycleCounterTicks;
typedef unsigned long long ticks;
static __inline__ CycleCounterTicks getticks(void)
static __inline__ ticks getticks(void)
{
unsigned int tbl, tbu0, tbu1;
@ -161,7 +162,7 @@ INLINE_ELAPSED(__inline__)
from Carbon, requires no additional libraries to be linked). */
#if defined(HAVE_MACH_ABSOLUTE_TIME) && defined(HAVE_MACH_MACH_TIME_H) && !defined(HAVE_TICK_COUNTER)
#include <mach/mach_time.h>
typedef uint64_t CycleCounterTicks;
typedef uint64_t ticks;
#define getticks mach_absolute_time
INLINE_ELAPSED(__inline__)
#define HAVE_TICK_COUNTER
@ -172,11 +173,11 @@ INLINE_ELAPSED(__inline__)
* Pentium cycle counter
*/
#if (defined(__GNUC__) || defined(__ICC)) && defined(__i386__) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long long CycleCounterTicks;
typedef unsigned long long ticks;
static __inline__ CycleCounterTicks getticks(void)
static __inline__ ticks getticks(void)
{
CycleCounterTicks ret;
ticks ret;
__asm__ __volatile__("rdtsc": "=A" (ret));
/* no input, nothing else clobbered */
@ -193,12 +194,12 @@ INLINE_ELAPSED(__inline__)
#if defined(_MSC_VER)
#if _MSC_VER >= 1200 && (_M_IX86 >= 500 || (defined(_WIN32_WCE) && defined(_X86_))) && !defined(HAVE_TICK_COUNTER)
#include <windows.h>
typedef LARGE_INTEGER CycleCounterTicks;
typedef LARGE_INTEGER ticks;
#define RDTSC __asm __emit 0fh __asm __emit 031h /* hack for VC++ 5.0 */
static __inline CycleCounterTicks getticks(void)
static __inline ticks getticks(void)
{
CycleCounterTicks retval;
ticks retval;
__asm {
RDTSC
@ -208,7 +209,7 @@ static __inline CycleCounterTicks getticks(void)
return retval;
}
static __inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0)
static __inline double elapsed(ticks t1, ticks t0)
{
return (double)(t1.QuadPart - t0.QuadPart);
}
@ -220,14 +221,14 @@ static __inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0)
#if _MSC_VER >= 1400 && defined(_WIN32_WCE) && !defined(HAVE_TICK_COUNTER)
#include <windows.h>
typedef DWORD CycleCounterTicks;
typedef DWORD ticks;
static __inline CycleCounterTicks getticks(void)
static __inline ticks getticks(void)
{
return GetTickCount();
}
static __inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0)
static __inline double elapsed(ticks t1, ticks t0)
{
return (double)(t1 - t0);
}
@ -241,13 +242,13 @@ static __inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0)
* X86-64 cycle counter
*/
#if (defined(__GNUC__) || defined(__ICC)) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long long CycleCounterTicks;
typedef unsigned long long ticks;
static __inline__ CycleCounterTicks getticks(void)
static __inline__ ticks getticks(void)
{
unsigned a, d;
asm volatile("rdtsc" : "=a" (a), "=d" (d));
return ((CycleCounterTicks)a) | (((CycleCounterTicks)d) << 32);
return ((ticks)a) | (((ticks)d) << 32);
}
INLINE_ELAPSED(__inline__)
@ -259,8 +260,8 @@ INLINE_ELAPSED(__inline__)
NOTE: this code will fail to link unless you use the -Masmkeyword compiler
option (grrr). */
#if defined(__PGI) && defined(__x86_64__) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long long CycleCounterTicks;
static CycleCounterTicks getticks(void)
typedef unsigned long long ticks;
static ticks getticks(void)
{
asm(" rdtsc; shl $0x20,%rdx; mov %eax,%eax; or %rdx,%rax; ");
}
@ -272,7 +273,7 @@ INLINE_ELAPSED(__inline__)
#if _MSC_VER >= 1400 && (defined(_M_AMD64) || defined(_M_X64)) && !defined(HAVE_TICK_COUNTER)
#include <intrin.h>
typedef unsigned __int64 CycleCounterTicks;
typedef unsigned __int64 ticks;
#define getticks __rdtsc
@ -288,10 +289,10 @@ INLINE_ELAPSED(__inline)
/* intel's icc/ecc compiler */
#if (defined(__EDG_VERSION) || defined(__ECC)) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long CycleCounterTicks;
typedef unsigned long ticks;
#include <ia64intrin.h>
static __inline__ CycleCounterTicks getticks(void)
static __inline__ ticks getticks(void)
{
return __getReg(_IA64_REG_AR_ITC);
}
@ -303,11 +304,11 @@ INLINE_ELAPSED(__inline__)
/* gcc */
#if defined(__GNUC__) && defined(__ia64__) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long CycleCounterTicks;
typedef unsigned long ticks;
static __inline__ CycleCounterTicks getticks(void)
static __inline__ ticks getticks(void)
{
CycleCounterTicks ret;
ticks ret;
__asm__ __volatile__ ("mov %0=ar.itc" : "=r"(ret));
return ret;
@ -321,11 +322,11 @@ INLINE_ELAPSED(__inline__)
/* HP/UX IA64 compiler, courtesy Teresa L. Johnson: */
#if defined(__hpux) && defined(__ia64) && !defined(HAVE_TICK_COUNTER)
#include <machine/sys/inline.h>
typedef unsigned long CycleCounterTicks;
typedef unsigned long ticks;
static inline CycleCounterTicks getticks(void)
static inline ticks getticks(void)
{
CycleCounterTicks ret;
ticks ret;
ret = _Asm_mov_from_ar (_AREG_ITC);
return ret;
@ -338,7 +339,7 @@ INLINE_ELAPSED(inline)
/* Microsoft Visual C++ */
#if defined(_MSC_VER) && defined(_M_IA64) && !defined(HAVE_TICK_COUNTER)
typedef unsigned __int64 CycleCounterTicks;
typedef unsigned __int64 ticks;
# ifdef __cplusplus
extern "C"
@ -346,9 +347,9 @@ extern "C"
ticks __getReg(int whichReg);
#pragma intrinsic(__getReg)
static __inline CycleCounterTicks getticks(void)
static __inline ticks getticks(void)
{
volatile CycleCounterTicks temp;
volatile ticks temp;
temp = __getReg(3116);
return temp;
}
@ -361,12 +362,12 @@ static __inline CycleCounterTicks getticks(void)
* PA-RISC cycle counter
*/
#if (defined(__hppa__) || defined(__hppa)) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long CycleCounterTicks;
typedef unsigned long ticks;
# ifdef __GNUC__
static __inline__ CycleCounterTicks getticks(void)
static __inline__ ticks getticks(void)
{
CycleCounterTicks ret;
ticks ret;
__asm__ __volatile__("mfctl 16, %0": "=r" (ret));
/* no input, nothing else clobbered */
@ -381,7 +382,7 @@ INLINE_ELAPSED(inline)
# include <machine/inline.h>
static inline unsigned long getticks(void)
{
register CycleCounterTicks ret;
register ticks ret;
_MFCTL(16, ret);
return ret;
}
@ -392,11 +393,11 @@ static inline unsigned long getticks(void)
/*----------------------------------------------------------------*/
/* S390, courtesy of James Treacy */
#if defined(__GNUC__) && defined(__s390__) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long long CycleCounterTicks;
typedef unsigned long long ticks;
static __inline__ CycleCounterTicks getticks(void)
static __inline__ ticks getticks(void)
{
CycleCounterTicks cycles;
ticks cycles;
__asm__("stck 0(%0)" : : "a" (&(cycles)) : "memory", "cc");
return cycles;
}
@ -411,9 +412,9 @@ INLINE_ELAPSED(__inline__)
* The 32-bit cycle counter on alpha overflows pretty quickly,
* unfortunately. A 1GHz machine overflows in 4 seconds.
*/
typedef unsigned int CycleCounterTicks;
typedef unsigned int ticks;
static __inline__ CycleCounterTicks getticks(void)
static __inline__ ticks getticks(void)
{
unsigned long cc;
__asm__ __volatile__ ("rpcc %0" : "=r"(cc));
@ -427,11 +428,11 @@ INLINE_ELAPSED(__inline__)
/*----------------------------------------------------------------*/
#if defined(__GNUC__) && defined(__sparc_v9__) && !defined(HAVE_TICK_COUNTER)
typedef unsigned long CycleCounterTicks;
typedef unsigned long ticks;
static __inline__ CycleCounterTicks getticks(void)
static __inline__ ticks getticks(void)
{
CycleCounterTicks ret;
ticks ret;
__asm__ __volatile__("rd %%tick, %0" : "=r" (ret));
return ret;
}
@ -444,9 +445,9 @@ INLINE_ELAPSED(__inline__)
/*----------------------------------------------------------------*/
#if (defined(__DECC) || defined(__DECCXX)) && defined(__alpha) && defined(HAVE_C_ASM_H) && !defined(HAVE_TICK_COUNTER)
# include <c_asm.h>
typedef unsigned int CycleCounterTicks;
typedef unsigned int ticks;
static __inline CycleCounterTicks getticks(void)
static __inline ticks getticks(void)
{
unsigned long cc;
cc = asm("rpcc %v0");
@ -460,16 +461,16 @@ INLINE_ELAPSED(__inline)
/*----------------------------------------------------------------*/
/* SGI/Irix */
#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_SGI_CYCLE) && !defined(HAVE_TICK_COUNTER)
typedef struct timespec CycleCounterTicks;
typedef struct timespec ticks;
static inline CycleCounterTicks getticks(void)
static inline ticks getticks(void)
{
struct timespec t;
clock_gettime(CLOCK_SGI_CYCLE, &t);
return t;
}
static inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0)
static inline double elapsed(ticks t1, ticks t0)
{
return (double)(t1.tv_sec - t0.tv_sec) * 1.0E9 +
(double)(t1.tv_nsec - t0.tv_nsec);
@ -484,7 +485,7 @@ static inline double elapsed(CycleCounterTicks t1, CycleCounterTicks t0)
# include <intrinsics.h>
#endif
typedef long long CycleCounterTicks;
typedef long long ticks;
#define getticks _rtc
@ -493,4 +494,5 @@ INLINE_ELAPSED(inline)
#define HAVE_TICK_COUNTER
#endif
#undef ticks
#endif // QBENCHLIB_CYCLE_H