1
0
Fork 0
mirror of https://github.com/ton-blockchain/ton synced 2025-03-09 15:40:10 +00:00

fix compilation errors of different platforms and move to c++20

This commit is contained in:
birydrad 2024-09-12 16:37:25 +02:00
parent 0780a6a1b5
commit 1c66852842
10 changed files with 67 additions and 25 deletions

View file

@ -22,20 +22,22 @@
namespace td {
struct Clocks {
static int64 monotonic_nano();
static double monotonic();
static double system();
static int tz_offset();
#if defined(__i386__)
static __inline__ td::uint64 rdtsc(void) {
#if defined(__i386__) or defined(__M_IX86)
static uint64 rdtsc() {
unsigned long long int x;
__asm__ volatile("rdtsc" : "=A"(x));
return x;
}
static constexpr td::uint64 rdtsc_frequency(void) {
static constexpr uint64 rdtsc_frequency() {
return 2000'000'000;
}
@ -46,13 +48,13 @@ struct Clocks {
static constexpr double inv_ticks_per_second() {
return 0.5e-9;
}
#elif defined(__x86_64__)
static __inline__ td::uint64 rdtsc(void) {
#elif defined(__x86_64__) or defined(__M_X64)
static uint64 rdtsc() {
unsigned hi, lo;
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
}
static constexpr td::uint64 rdtsc_frequency(void) {
static constexpr uint64 rdtsc_frequency() {
return 2000'000'000;
}
@ -63,13 +65,13 @@ struct Clocks {
static constexpr double inv_ticks_per_second() {
return 0.5e-9;
}
#elif defined(__aarch64__)
static __inline__ td::uint64 rdtsc(void) {
#elif defined(__aarch64__) or defined(_M_ARM64)
static uint64 rdtsc() {
unsigned long long val;
asm volatile("mrs %0, cntvct_el0" : "=r"(val));
return val;
}
static __inline__ td::uint64 rdtsc_frequency(void) {
static uint64 rdtsc_frequency() {
unsigned long long val;
asm volatile("mrs %0, cntfrq_el0" : "=r"(val));
return val;
@ -79,6 +81,21 @@ struct Clocks {
return static_cast<double>(rdtsc_frequency());
}
static double inv_ticks_per_second() {
return 1.0 / static_cast<double>(rdtsc_frequency());
}
#else
static uint64 rdtsc() {
return monotonic_nano();
}
static uint64 rdtsc_frequency() {
return 1000'000'000;
}
static double ticks_per_second() {
return static_cast<double>(rdtsc_frequency());
}
static double inv_ticks_per_second() {
return 1.0 / static_cast<double>(rdtsc_frequency());
}