mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-30 00:00:11 +01:00
tsc: use compiler intrinsics
This commit is contained in:
parent
6f39cbc8a6
commit
a028429119
1 changed files with 4 additions and 38 deletions
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include <cpuid.h>
|
#include <cpuid.h>
|
||||||
#include <cinttypes>
|
#include <cinttypes>
|
||||||
|
#include <x86intrin.h>
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
@ -51,48 +52,13 @@ struct tsc {
|
||||||
bool is_invariant;
|
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))
|
__attribute__((unused))
|
||||||
static uint64_t tsc_now(struct tsc *t)
|
static uint64_t tsc_now(struct tsc *t)
|
||||||
{
|
{
|
||||||
|
uint32_t tsc_aux;
|
||||||
return t->rdtscp_supported
|
return t->rdtscp_supported
|
||||||
? rdtscp()
|
? __rdtscp(&tsc_aux)
|
||||||
: rdtsc();
|
: __rdtsc();
|
||||||
}
|
}
|
||||||
|
|
||||||
int tsc_init(struct tsc *t) __attribute__ ((warn_unused_result));
|
int tsc_init(struct tsc *t) __attribute__ ((warn_unused_result));
|
||||||
|
|
Loading…
Add table
Reference in a new issue