2022-04-23 08:59:50 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2020-02-09 20:53:22 +00:00
|
|
|
|
2020-02-10 15:20:40 +00:00
|
|
|
#include "common/uint128.h"
|
2020-02-09 20:53:22 +00:00
|
|
|
#include "common/x64/native_clock.h"
|
2023-04-23 03:08:28 +00:00
|
|
|
#include "common/x64/rdtsc.h"
|
2020-02-09 20:53:22 +00:00
|
|
|
|
2023-04-23 03:08:28 +00:00
|
|
|
namespace Common::X64 {
|
2022-04-02 20:54:39 +00:00
|
|
|
|
2023-04-23 03:08:28 +00:00
|
|
|
NativeClock::NativeClock(u64 rdtsc_frequency_)
|
2023-10-29 13:50:55 +00:00
|
|
|
: rdtsc_frequency{rdtsc_frequency_}, ns_rdtsc_factor{GetFixedPoint64Factor(NsRatio::den,
|
|
|
|
rdtsc_frequency)},
|
2023-04-23 03:08:28 +00:00
|
|
|
us_rdtsc_factor{GetFixedPoint64Factor(UsRatio::den, rdtsc_frequency)},
|
|
|
|
ms_rdtsc_factor{GetFixedPoint64Factor(MsRatio::den, rdtsc_frequency)},
|
2023-05-28 21:45:47 +00:00
|
|
|
cntpct_rdtsc_factor{GetFixedPoint64Factor(CNTFRQ, rdtsc_frequency)},
|
|
|
|
gputick_rdtsc_factor{GetFixedPoint64Factor(GPUTickFreq, rdtsc_frequency)} {}
|
2020-02-09 20:53:22 +00:00
|
|
|
|
2023-04-23 03:08:28 +00:00
|
|
|
std::chrono::nanoseconds NativeClock::GetTimeNS() const {
|
2023-10-29 13:50:55 +00:00
|
|
|
return std::chrono::nanoseconds{MultiplyHigh(GetUptime(), ns_rdtsc_factor)};
|
2022-04-02 20:54:39 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 03:08:28 +00:00
|
|
|
std::chrono::microseconds NativeClock::GetTimeUS() const {
|
2023-10-29 13:50:55 +00:00
|
|
|
return std::chrono::microseconds{MultiplyHigh(GetUptime(), us_rdtsc_factor)};
|
2023-03-04 02:02:24 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 03:08:28 +00:00
|
|
|
std::chrono::milliseconds NativeClock::GetTimeMS() const {
|
2023-10-29 13:50:55 +00:00
|
|
|
return std::chrono::milliseconds{MultiplyHigh(GetUptime(), ms_rdtsc_factor)};
|
2020-02-09 20:53:22 +00:00
|
|
|
}
|
|
|
|
|
2023-10-29 13:50:55 +00:00
|
|
|
s64 NativeClock::GetCNTPCT() const {
|
|
|
|
return MultiplyHigh(GetUptime(), cntpct_rdtsc_factor);
|
2020-02-09 20:53:22 +00:00
|
|
|
}
|
|
|
|
|
2023-10-29 13:50:55 +00:00
|
|
|
s64 NativeClock::GetGPUTick() const {
|
|
|
|
return MultiplyHigh(GetUptime(), gputick_rdtsc_factor);
|
2023-05-28 21:45:47 +00:00
|
|
|
}
|
|
|
|
|
2023-10-29 13:50:55 +00:00
|
|
|
s64 NativeClock::GetUptime() const {
|
|
|
|
return static_cast<s64>(FencedRDTSC());
|
2020-02-09 20:53:22 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 03:08:28 +00:00
|
|
|
bool NativeClock::IsNative() const {
|
|
|
|
return true;
|
2020-02-09 20:53:22 +00:00
|
|
|
}
|
|
|
|
|
2023-04-23 03:08:28 +00:00
|
|
|
} // namespace Common::X64
|