From 85573b82a31a7016ce25a32815834a522f053ae1 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Mon, 13 Sep 2021 15:11:51 +0200 Subject: [PATCH] tsc: use compiler intrinsics --- common/include/villas/tsc.h | 42 ++++--------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/common/include/villas/tsc.h b/common/include/villas/tsc.h index 56add7949..8f650968d 100644 --- a/common/include/villas/tsc.h +++ b/common/include/villas/tsc.h @@ -29,6 +29,7 @@ #include #include +#include #ifdef __APPLE__ #include @@ -51,48 +52,13 @@ struct tsc { bool is_invariant; }; -/** Get CPU timestep counter */ -__attribute__((unused,always_inline)) -static inline uint64_t rdtscp() -{ - uint64_t tsc; - - __asm__ __volatile__( - "rdtscp;" - "shl $32, %%rdx;" - "or %%rdx,%%rax" - : "=a" (tsc) - : - : "%rcx", "%rdx", "memory" - ); - - return tsc; -} - -__attribute__((unused,always_inline)) -static inline uint64_t rdtsc() -{ - uint64_t tsc; - - __asm__ __volatile__( - "lfence;" - "rdtsc;" - "shl $32, %%rdx;" - "or %%rdx,%%rax" - : "=a" (tsc) - : - : "%rcx", "%rdx", "memory" - ); - - return tsc; -} - __attribute__((unused)) static uint64_t tsc_now(struct tsc *t) { + uint32_t tsc_aux; return t->rdtscp_supported - ? rdtscp() - : rdtsc(); + ? __rdtscp(&tsc_aux) + : __rdtsc(); } int tsc_init(struct tsc *t) __attribute__ ((warn_unused_result));