13 #if defined _WIN32_WCE
14 #include <cmnintrin.h>
17 #if defined(_M_ARM) || defined(_M_ARM64)
23 #if !defined ZMQ_HAVE_WINDOWS
27 #if defined HAVE_CLOCK_GETTIME || defined HAVE_GETHRTIME
31 #if defined ZMQ_HAVE_VXWORKS
35 #if defined ZMQ_HAVE_OSX
36 int alt_clock_gettime (
int clock_id, timespec *ts)
40 host_get_clock_service (mach_host_self (), clock_id, &cclock);
41 clock_get_time (cclock, &mts);
42 mach_port_deallocate (mach_task_self (), cclock);
43 ts->tv_sec = mts.tv_sec;
44 ts->tv_nsec = mts.tv_nsec;
49 #ifdef ZMQ_HAVE_WINDOWS
50 typedef ULONGLONG (*f_compatible_get_tick_count64) ();
54 ULONGLONG compatible_get_tick_count64 ()
56 #ifdef ZMQ_HAVE_WINDOWS_UWP
57 const ULONGLONG result = ::GetTickCount64 ();
62 static DWORD s_wrap = 0;
63 static DWORD s_last_tick = 0;
64 const DWORD current_tick = ::GetTickCount ();
66 if (current_tick < s_last_tick)
69 s_last_tick = current_tick;
70 const ULONGLONG result = (
static_cast<ULONGLONG
> (s_wrap) << 32)
71 +
static_cast<ULONGLONG
> (current_tick);
77 f_compatible_get_tick_count64 init_compatible_get_tick_count64 ()
79 f_compatible_get_tick_count64
func =
NULL;
80 #if !defined ZMQ_HAVE_WINDOWS_UWP
82 const HMODULE module = ::LoadLibraryA (
"Kernel32.dll");
84 func =
reinterpret_cast<f_compatible_get_tick_count64
> (
85 ::GetProcAddress (module,
"GetTickCount64"));
88 func = compatible_get_tick_count64;
90 #if !defined ZMQ_HAVE_WINDOWS_UWP
92 ::FreeLibrary (module);
98 static f_compatible_get_tick_count64 my_get_tick_count64 =
99 init_compatible_get_tick_count64 ();
102 #ifndef ZMQ_HAVE_WINDOWS
109 _last_tsc (rdtsc ()),
111 _last_time (static_cast<uint64_t> ((*my_get_tick_count64) ()))
120 #if defined ZMQ_HAVE_WINDOWS
126 LARGE_INTEGER ticks_per_second;
127 QueryPerformanceFrequency (&ticks_per_second);
131 QueryPerformanceCounter (&tick);
135 const double ticks_div =
136 static_cast<double> (ticks_per_second.QuadPart) /
usecs_per_sec;
137 return static_cast<uint64_t
> (tick.QuadPart / ticks_div);
139 #elif defined HAVE_CLOCK_GETTIME \
140 && (defined CLOCK_MONOTONIC || defined ZMQ_HAVE_VXWORKS)
145 #if defined ZMQ_HAVE_OSX \
146 && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12
147 int rc = alt_clock_gettime (SYSTEM_CLOCK, &tv);
149 int rc = clock_gettime (CLOCK_MONOTONIC, &tv);
155 #ifndef ZMQ_HAVE_VXWORKS
158 int rc = gettimeofday (&tv,
NULL);
165 #elif defined HAVE_GETHRTIME
174 int rc = gettimeofday (&tv,
NULL);
183 const uint64_t tsc = rdtsc ();
187 #ifdef ZMQ_HAVE_WINDOWS
192 return static_cast<uint64_t
> ((*my_get_tick_count64) ());
205 #ifdef ZMQ_HAVE_WINDOWS
206 _last_time =
static_cast<uint64_t
> ((*my_get_tick_count64) ());
215 #if (defined _MSC_VER && (defined _M_IX86 || defined _M_X64))
217 #elif defined(_MSC_VER) && defined(_M_ARM) // NC => added for windows ARM
218 return __rdpmccntr64 ();
219 #elif defined(_MSC_VER) && defined(_M_ARM64) // NC => added for windows ARM64
220 const int64_t pmccntr_el0 = (((3 & 1) << 14) |
225 return _ReadStatusReg (pmccntr_el0);
226 #elif (defined(_WIN32) && defined(__GNUC__) && defined(__aarch64__))
228 __asm__
volatile(
"mrs %0, pmccntr_el0" :
"=r"(
val));
230 #elif (defined __GNUC__ && (defined __i386__ || defined __x86_64__))
232 __asm__
volatile(
"rdtsc" :
"=a"(low),
"=d"(high));
233 return static_cast<uint64_t
> (high) << 32 | low;
234 #elif (defined __SUNPRO_CC && (__SUNPRO_CC >= 0x5100) \
235 && (defined __i386 || defined __amd64 || defined __x86_64))
241 asm(
"rdtsc" :
"=a"(tsc.u32val[0]),
"=d"(tsc.u32val[1]));
243 #elif defined(__s390__)
245 asm(
"\tstck\t%0\n" :
"=Q"(tsc) : :
"cc");
249 #if defined ZMQ_HAVE_OSX \
250 && __MAC_OS_X_VERSION_MIN_REQUIRED < 101200 // less than macOS 10.12
251 alt_clock_gettime (SYSTEM_CLOCK, &ts);
253 clock_gettime (CLOCK_MONOTONIC, &ts);