summaryrefslogtreecommitdiffstats
path: root/src/common
diff options
context:
space:
mode:
Diffstat (limited to 'src/common')
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/bit_util.h7
-rw-r--r--src/common/host_memory.cpp4
-rw-r--r--src/common/input.h366
-rw-r--r--src/common/logging/filter.cpp1
-rw-r--r--src/common/logging/types.h1
-rw-r--r--src/common/settings.cpp1
-rw-r--r--src/common/settings.h15
-rw-r--r--src/common/settings_input.h70
-rw-r--r--src/common/x64/cpu_detect.cpp12
-rw-r--r--src/common/x64/native_clock.cpp36
11 files changed, 453 insertions, 61 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 23d43a394..919da4a53 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -73,6 +73,7 @@ add_library(common STATIC
hex_util.h
host_memory.cpp
host_memory.h
+ input.h
intrusive_red_black_tree.h
literals.h
logging/backend.cpp
diff --git a/src/common/bit_util.h b/src/common/bit_util.h
index 64520ca4e..eef8c1c5a 100644
--- a/src/common/bit_util.h
+++ b/src/common/bit_util.h
@@ -7,6 +7,7 @@
#include <bit>
#include <climits>
#include <cstddef>
+#include <type_traits>
#include "common/common_types.h"
@@ -44,4 +45,10 @@ template <typename T>
return static_cast<u32>(log2_f + static_cast<u64>((value ^ (1ULL << log2_f)) != 0ULL));
}
+template <typename T>
+requires std::is_integral_v<T>
+[[nodiscard]] T NextPow2(T value) {
+ return static_cast<T>(1ULL << ((8U * sizeof(T)) - std::countl_zero(value - 1U)));
+}
+
} // namespace Common
diff --git a/src/common/host_memory.cpp b/src/common/host_memory.cpp
index b44a44949..28949fe5e 100644
--- a/src/common/host_memory.cpp
+++ b/src/common/host_memory.cpp
@@ -1,3 +1,7 @@
+// Copyright 2021 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
#ifdef _WIN32
#include <iterator>
diff --git a/src/common/input.h b/src/common/input.h
new file mode 100644
index 000000000..f775a4c01
--- /dev/null
+++ b/src/common/input.h
@@ -0,0 +1,366 @@
+// Copyright 2017 Citra Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <functional>
+#include <memory>
+#include <string>
+#include <unordered_map>
+#include <utility>
+#include "common/logging/log.h"
+#include "common/param_package.h"
+#include "common/uuid.h"
+
+namespace Common::Input {
+
+// Type of data that is expected to recieve or send
+enum class InputType {
+ None,
+ Battery,
+ Button,
+ Stick,
+ Analog,
+ Trigger,
+ Motion,
+ Touch,
+ Color,
+ Vibration,
+ Nfc,
+ Ir,
+};
+
+// Internal battery charge level
+enum class BatteryLevel : u32 {
+ None,
+ Empty,
+ Critical,
+ Low,
+ Medium,
+ Full,
+ Charging,
+};
+
+enum class PollingMode {
+ // Constant polling of buttons, analogs and motion data
+ Active,
+ // Only update on button change, digital analogs
+ Pasive,
+ // Enable near field communication polling
+ NFC,
+ // Enable infrared camera polling
+ IR,
+};
+
+// Vibration reply from the controller
+enum class VibrationError {
+ None,
+ NotSupported,
+ Disabled,
+ Unknown,
+};
+
+// Polling mode reply from the controller
+enum class PollingError {
+ None,
+ NotSupported,
+ Unknown,
+};
+
+// Hint for amplification curve to be used
+enum class VibrationAmplificationType {
+ Linear,
+ Exponential,
+};
+
+// Analog properties for calibration
+struct AnalogProperties {
+ // Anything below this value will be detected as zero
+ float deadzone{};
+ // Anyting above this values will be detected as one
+ float range{1.0f};
+ // Minimum value to be detected as active
+ float threshold{0.5f};
+ // Drift correction applied to the raw data
+ float offset{};
+ // Invert direction of the sensor data
+ bool inverted{};
+};
+
+// Single analog sensor data
+struct AnalogStatus {
+ float value{};
+ float raw_value{};
+ AnalogProperties properties{};
+};
+
+// Button data
+struct ButtonStatus {
+ Common::UUID uuid{};
+ bool value{};
+ bool inverted{};
+ bool toggle{};
+ bool locked{};
+};
+
+// Internal battery data
+using BatteryStatus = BatteryLevel;
+
+// Analog and digital joystick data
+struct StickStatus {
+ Common::UUID uuid{};
+ AnalogStatus x{};
+ AnalogStatus y{};
+ bool left{};
+ bool right{};
+ bool up{};
+ bool down{};
+};
+
+// Analog and digital trigger data
+struct TriggerStatus {
+ Common::UUID uuid{};
+ AnalogStatus analog{};
+ ButtonStatus pressed{};
+};
+
+// 3D vector representing motion input
+struct MotionSensor {
+ AnalogStatus x{};
+ AnalogStatus y{};
+ AnalogStatus z{};
+};
+
+// Motion data used to calculate controller orientation
+struct MotionStatus {
+ // Gyroscope vector measurement in radians/s.
+ MotionSensor gyro{};
+ // Acceleration vector measurement in G force
+ MotionSensor accel{};
+ // Time since last measurement in microseconds
+ u64 delta_timestamp{};
+ // Request to update after reading the value
+ bool force_update{};
+};
+
+// Data of a single point on a touch screen
+struct TouchStatus {
+ ButtonStatus pressed{};
+ AnalogStatus x{};
+ AnalogStatus y{};
+ int id{};
+};
+
+// Physical controller color in RGB format
+struct BodyColorStatus {
+ u32 body{};
+ u32 buttons{};
+};
+
+// HD rumble data
+struct VibrationStatus {
+ f32 low_amplitude{};
+ f32 low_frequency{};
+ f32 high_amplitude{};
+ f32 high_frequency{};
+ VibrationAmplificationType type;
+};
+
+// Physical controller LED pattern
+struct LedStatus {
+ bool led_1{};
+ bool led_2{};
+ bool led_3{};
+ bool led_4{};
+};
+
+// List of buttons to be passed to Qt that can be translated
+enum class ButtonNames {
+ Undefined,
+ Invalid,
+ // This will display the engine name instead of the button name
+ Engine,
+ // This will display the button by value instead of the button name
+ Value,
+ ButtonLeft,
+ ButtonRight,
+ ButtonDown,
+ ButtonUp,
+ TriggerZ,
+ TriggerR,
+ TriggerL,
+ ButtonA,
+ ButtonB,
+ ButtonX,
+ ButtonY,
+ ButtonStart,
+
+ // DS4 button names
+ L1,
+ L2,
+ L3,
+ R1,
+ R2,
+ R3,
+ Circle,
+ Cross,
+ Square,
+ Triangle,
+ Share,
+ Options,
+};
+
+// Callback data consisting of an input type and the equivalent data status
+struct CallbackStatus {
+ InputType type{InputType::None};
+ ButtonStatus button_status{};
+ StickStatus stick_status{};
+ AnalogStatus analog_status{};
+ TriggerStatus trigger_status{};
+ MotionStatus motion_status{};
+ TouchStatus touch_status{};
+ BodyColorStatus color_status{};
+ BatteryStatus battery_status{};
+ VibrationStatus vibration_status{};
+};
+
+// Triggered once every input change
+struct InputCallback {
+ std::function<void(const CallbackStatus&)> on_change;
+};
+
+/// An abstract class template for an input device (a button, an analog input, etc.).
+class InputDevice {
+public:
+ virtual ~InputDevice() = default;
+
+ // Request input device to update if necessary
+ virtual void SoftUpdate() {}
+
+ // Force input device to update data regardless of the current state
+ virtual void ForceUpdate() {}
+
+ // Sets the function to be triggered when input changes
+ void SetCallback(InputCallback callback_) {
+ callback = std::move(callback_);
+ }
+
+ // Triggers the function set in the callback
+ void TriggerOnChange(const CallbackStatus& status) {
+ if (callback.on_change) {
+ callback.on_change(status);
+ }
+ }
+
+private:
+ InputCallback callback;
+};
+
+/// An abstract class template for an output device (rumble, LED pattern, polling mode).
+class OutputDevice {
+public:
+ virtual ~OutputDevice() = default;
+
+ virtual void SetLED([[maybe_unused]] const LedStatus& led_status) {}
+
+ virtual VibrationError SetVibration([[maybe_unused]] const VibrationStatus& vibration_status) {
+ return VibrationError::NotSupported;
+ }
+
+ virtual PollingError SetPollingMode([[maybe_unused]] PollingMode polling_mode) {
+ return PollingError::NotSupported;
+ }
+};
+
+/// An abstract class template for a factory that can create input devices.
+template <typename InputDeviceType>
+class Factory {
+public:
+ virtual ~Factory() = default;
+ virtual std::unique_ptr<InputDeviceType> Create(const Common::ParamPackage&) = 0;
+};
+
+namespace Impl {
+
+template <typename InputDeviceType>
+using FactoryListType = std::unordered_map<std::string, std::shared_ptr<Factory<InputDeviceType>>>;
+
+template <typename InputDeviceType>
+struct FactoryList {
+ static FactoryListType<InputDeviceType> list;
+};
+
+template <typename InputDeviceType>
+FactoryListType<InputDeviceType> FactoryList<InputDeviceType>::list;
+
+} // namespace Impl
+
+/**
+ * Registers an input device factory.
+ * @tparam InputDeviceType the type of input devices the factory can create
+ * @param name the name of the factory. Will be used to match the "engine" parameter when creating
+ * a device
+ * @param factory the factory object to register
+ */
+template <typename InputDeviceType>
+void RegisterFactory(const std::string& name, std::shared_ptr<Factory<InputDeviceType>> factory) {
+ auto pair = std::make_pair(name, std::move(factory));
+ if (!Impl::FactoryList<InputDeviceType>::list.insert(std::move(pair)).second) {
+ LOG_ERROR(Input, "Factory '{}' already registered", name);
+ }
+}
+
+/**
+ * Unregisters an input device factory.
+ * @tparam InputDeviceType the type of input devices the factory can create
+ * @param name the name of the factory to unregister
+ */
+template <typename InputDeviceType>
+void UnregisterFactory(const std::string& name) {
+ if (Impl::FactoryList<InputDeviceType>::list.erase(name) == 0) {
+ LOG_ERROR(Input, "Factory '{}' not registered", name);
+ }
+}
+
+/**
+ * Create an input device from given paramters.
+ * @tparam InputDeviceType the type of input devices to create
+ * @param params a serialized ParamPackage string that contains all parameters for creating the
+ * device
+ */
+template <typename InputDeviceType>
+std::unique_ptr<InputDeviceType> CreateDeviceFromString(const std::string& params) {
+ const Common::ParamPackage package(params);
+ const std::string engine = package.Get("engine", "null");
+ const auto& factory_list = Impl::FactoryList<InputDeviceType>::list;
+ const auto pair = factory_list.find(engine);
+ if (pair == factory_list.end()) {
+ if (engine != "null") {
+ LOG_ERROR(Input, "Unknown engine name: {}", engine);
+ }
+ return std::make_unique<InputDeviceType>();
+ }
+ return pair->second->Create(package);
+}
+
+/**
+ * Create an input device from given paramters.
+ * @tparam InputDeviceType the type of input devices to create
+ * @param A ParamPackage that contains all parameters for creating the device
+ */
+template <typename InputDeviceType>
+std::unique_ptr<InputDeviceType> CreateDevice(const Common::ParamPackage package) {
+ const std::string engine = package.Get("engine", "null");
+ const auto& factory_list = Impl::FactoryList<InputDeviceType>::list;
+ const auto pair = factory_list.find(engine);
+ if (pair == factory_list.end()) {
+ if (engine != "null") {
+ LOG_ERROR(Input, "Unknown engine name: {}", engine);
+ }
+ return std::make_unique<InputDeviceType>();
+ }
+ return pair->second->Create(package);
+}
+
+} // namespace Common::Input
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp
index 42744c994..b898a652c 100644
--- a/src/common/logging/filter.cpp
+++ b/src/common/logging/filter.cpp
@@ -114,6 +114,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) {
SUB(Service, NGCT) \
SUB(Service, NIFM) \
SUB(Service, NIM) \
+ SUB(Service, NOTIF) \
SUB(Service, NPNS) \
SUB(Service, NS) \
SUB(Service, NVDRV) \
diff --git a/src/common/logging/types.h b/src/common/logging/types.h
index 2d21fc483..9ed0c7ad6 100644
--- a/src/common/logging/types.h
+++ b/src/common/logging/types.h
@@ -82,6 +82,7 @@ enum class Class : u8 {
Service_NGCT, ///< The NGCT (No Good Content for Terra) service
Service_NIFM, ///< The NIFM (Network interface) service
Service_NIM, ///< The NIM service
+ Service_NOTIF, ///< The NOTIF (Notification) service
Service_NPNS, ///< The NPNS service
Service_NS, ///< The NS services
Service_NVDRV, ///< The NVDRV (Nvidia driver) service
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index 3bcaa072f..6964a8273 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -183,6 +183,7 @@ void RestoreGlobalState(bool is_powered_on) {
values.max_anisotropy.SetGlobal(true);
values.use_speed_limit.SetGlobal(true);
values.speed_limit.SetGlobal(true);
+ values.fps_cap.SetGlobal(true);
values.use_disk_shader_cache.SetGlobal(true);
values.gpu_accuracy.SetGlobal(true);
values.use_asynchronous_gpu_emulation.SetGlobal(true);
diff --git a/src/common/settings.h b/src/common/settings.h
index 42f8b4a7d..313f1fa7f 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -6,7 +6,6 @@
#include <algorithm>
#include <array>
-#include <atomic>
#include <map>
#include <optional>
#include <string>
@@ -525,7 +524,7 @@ struct Values {
Setting<NvdecEmulation> nvdec_emulation{NvdecEmulation::GPU, "nvdec_emulation"};
Setting<bool> accelerate_astc{true, "accelerate_astc"};
Setting<bool> use_vsync{true, "use_vsync"};
- BasicRangedSetting<u16> fps_cap{1000, 1, 1000, "fps_cap"};
+ RangedSetting<u16> fps_cap{1000, 1, 1000, "fps_cap"};
BasicSetting<bool> disable_fps_limit{false, "disable_fps_limit"};
RangedSetting<ShaderBackend> shader_backend{ShaderBackend::GLASM, ShaderBackend::GLSL,
ShaderBackend::SPIRV, "shader_backend"};
@@ -560,25 +559,19 @@ struct Values {
Setting<bool> enable_accurate_vibrations{false, "enable_accurate_vibrations"};
Setting<bool> motion_enabled{true, "motion_enabled"};
- BasicSetting<std::string> motion_device{"engine:motion_emu,update_period:100,sensitivity:0.01",
- "motion_device"};
BasicSetting<std::string> udp_input_servers{"127.0.0.1:26760", "udp_input_servers"};
+ BasicSetting<bool> enable_udp_controller{false, "enable_udp_controller"};
BasicSetting<bool> pause_tas_on_load{true, "pause_tas_on_load"};
BasicSetting<bool> tas_enable{false, "tas_enable"};
BasicSetting<bool> tas_loop{false, "tas_loop"};
- BasicSetting<bool> tas_swap_controllers{true, "tas_swap_controllers"};
BasicSetting<bool> mouse_panning{false, "mouse_panning"};
BasicRangedSetting<u8> mouse_panning_sensitivity{10, 1, 100, "mouse_panning_sensitivity"};
BasicSetting<bool> mouse_enabled{false, "mouse_enabled"};
- std::string mouse_device;
- MouseButtonsRaw mouse_buttons;
BasicSetting<bool> emulate_analog_keyboard{false, "emulate_analog_keyboard"};
BasicSetting<bool> keyboard_enabled{false, "keyboard_enabled"};
- KeyboardKeysRaw keyboard_keys;
- KeyboardModsRaw keyboard_mods;
BasicSetting<bool> debug_pad_enabled{false, "debug_pad_enabled"};
ButtonsRaw debug_pad_buttons;
@@ -586,14 +579,11 @@ struct Values {
TouchscreenInput touchscreen;
- BasicSetting<bool> use_touch_from_button{false, "use_touch_from_button"};
BasicSetting<std::string> touch_device{"min_x:100,min_y:50,max_x:1800,max_y:850",
"touch_device"};
BasicSetting<int> touch_from_button_map_index{0, "touch_from_button_map"};
std::vector<TouchFromButtonMap> touch_from_button_maps;
- std::atomic_bool is_device_reload_pending{true};
-
// Data Storage
BasicSetting<bool> use_virtual_sd{true, "use_virtual_sd"};
BasicSetting<bool> gamecard_inserted{false, "gamecard_inserted"};
@@ -614,6 +604,7 @@ struct Values {
BasicSetting<bool> extended_logging{false, "extended_logging"};
BasicSetting<bool> use_debug_asserts{false, "use_debug_asserts"};
BasicSetting<bool> use_auto_stub{false, "use_auto_stub"};
+ BasicSetting<bool> enable_all_controllers{false, "enable_all_controllers"};
// Miscellaneous
BasicSetting<std::string> log_filter{"*:Info", "log_filter"};
diff --git a/src/common/settings_input.h b/src/common/settings_input.h
index 609600582..4ff37e186 100644
--- a/src/common/settings_input.h
+++ b/src/common/settings_input.h
@@ -62,11 +62,22 @@ enum Values : int {
constexpr int STICK_HID_BEGIN = LStick;
constexpr int STICK_HID_END = NumAnalogs;
-constexpr int NUM_STICKS_HID = NumAnalogs;
extern const std::array<const char*, NumAnalogs> mapping;
} // namespace NativeAnalog
+namespace NativeTrigger {
+enum Values : int {
+ LTrigger,
+ RTrigger,
+
+ NumTriggers,
+};
+
+constexpr int TRIGGER_HID_BEGIN = LTrigger;
+constexpr int TRIGGER_HID_END = NumTriggers;
+} // namespace NativeTrigger
+
namespace NativeVibration {
enum Values : int {
LeftVibrationDevice,
@@ -115,10 +126,20 @@ constexpr int NUM_MOUSE_HID = NumMouseButtons;
extern const std::array<const char*, NumMouseButtons> mapping;
} // namespace NativeMouseButton
+namespace NativeMouseWheel {
+enum Values {
+ X,
+ Y,
+
+ NumMouseWheels,
+};
+
+extern const std::array<const char*, NumMouseWheels> mapping;
+} // namespace NativeMouseWheel
+
namespace NativeKeyboard {
enum Keys {
None,
- Error,
A = 4,
B,
@@ -156,22 +177,22 @@ enum Keys {
N8,
N9,
N0,
- Enter,
+ Return,
Escape,
Backspace,
Tab,
Space,
Minus,
- Equal,
- LeftBrace,
- RightBrace,
- Backslash,
+ Plus,
+ OpenBracket,
+ CloseBracket,
+ Pipe,
Tilde,
Semicolon,
- Apostrophe,
- Grave,
+ Quote,
+ Backquote,
Comma,
- Dot,
+ Period,
Slash,
CapsLockKey,
@@ -188,7 +209,7 @@ enum Keys {
F11,
F12,
- SystemRequest,
+ PrintScreen,
ScrollLockKey,
Pause,
Insert,
@@ -257,8 +278,18 @@ enum Keys {
ScrollLockActive,
KPComma,
- KPLeftParenthesis,
- KPRightParenthesis,
+ Ro = 0x87,
+ KatakanaHiragana,
+ Yen,
+ Henkan,
+ Muhenkan,
+ NumPadCommaPc98,
+
+ HangulEnglish = 0x90,
+ Hanja,
+ KatakanaKey,
+ HiraganaKey,
+ ZenkakuHankaku,
LeftControlKey = 0xE0,
LeftShiftKey,
@@ -307,6 +338,8 @@ enum Modifiers {
CapsLock,
ScrollLock,
NumLock,
+ Katakana,
+ Hiragana,
NumKeyboardMods,
};
@@ -324,11 +357,6 @@ constexpr int NUM_KEYBOARD_MODS_HID = NumKeyboardMods;
using AnalogsRaw = std::array<std::string, NativeAnalog::NumAnalogs>;
using ButtonsRaw = std::array<std::string, NativeButton::NumButtons>;
using MotionsRaw = std::array<std::string, NativeMotion::NumMotions>;
-using VibrationsRaw = std::array<std::string, NativeVibration::NumVibrations>;
-
-using MouseButtonsRaw = std::array<std::string, NativeMouseButton::NumMouseButtons>;
-using KeyboardKeysRaw = std::array<std::string, NativeKeyboard::NumKeyboardKeys>;
-using KeyboardModsRaw = std::array<std::string, NativeKeyboard::NumKeyboardMods>;
constexpr u32 JOYCON_BODY_NEON_RED = 0xFF3C28;
constexpr u32 JOYCON_BUTTONS_NEON_RED = 0x1E0A0A;
@@ -342,6 +370,11 @@ enum class ControllerType {
RightJoycon,
Handheld,
GameCube,
+ Pokeball,
+ NES,
+ SNES,
+ N64,
+ SegaGenesis,
};
struct PlayerInput {
@@ -349,7 +382,6 @@ struct PlayerInput {
ControllerType controller_type;
ButtonsRaw buttons;
AnalogsRaw analogs;
- VibrationsRaw vibrations;
MotionsRaw motions;
bool vibration_enabled;
diff --git a/src/common/x64/cpu_detect.cpp b/src/common/x64/cpu_detect.cpp
index fccd2eee5..fbeacc7e2 100644
--- a/src/common/x64/cpu_detect.cpp
+++ b/src/common/x64/cpu_detect.cpp
@@ -71,9 +71,6 @@ static CPUCaps Detect() {
else
caps.manufacturer = Manufacturer::Unknown;
- u32 family = {};
- u32 model = {};
-
__cpuid(cpu_id, 0x80000000);
u32 max_ex_fn = cpu_id[0];
@@ -84,15 +81,6 @@ static CPUCaps Detect() {
// Detect family and other miscellaneous features
if (max_std_fn >= 1) {
__cpuid(cpu_id, 0x00000001);
- family = (cpu_id[0] >> 8) & 0xf;
- model = (cpu_id[0] >> 4) & 0xf;
- if (family == 0xf) {
- family += (cpu_id[0] >> 20) & 0xff;
- }
- if (family >= 6) {
- model += ((cpu_id[0] >> 16) & 0xf) << 4;
- }
-
if ((cpu_id[3] >> 25) & 1)
caps.sse = true;
if ((cpu_id[3] >> 26) & 1)
diff --git a/src/common/x64/native_clock.cpp b/src/common/x64/native_clock.cpp
index 87de40624..82ee2c8a1 100644
--- a/src/common/x64/native_clock.cpp
+++ b/src/common/x64/native_clock.cpp
@@ -15,26 +15,26 @@
namespace Common {
u64 EstimateRDTSCFrequency() {
- const auto milli_10 = std::chrono::milliseconds{10};
- // get current time
+ // Discard the first result measuring the rdtsc.
_mm_mfence();
- const u64 tscStart = __rdtsc();
- const auto startTime = std::chrono::high_resolution_clock::now();
- // wait roughly 3 seconds
- while (true) {
- auto milli = std::chrono::duration_cast<std::chrono::milliseconds>(
- std::chrono::high_resolution_clock::now() - startTime);
- if (milli.count() >= 3000)
- break;
- std::this_thread::sleep_for(milli_10);
- }
- const auto endTime = std::chrono::high_resolution_clock::now();
+ __rdtsc();
+ std::this_thread::sleep_for(std::chrono::milliseconds{1});
+ _mm_mfence();
+ __rdtsc();
+
+ // Get the current time.
+ const auto start_time = std::chrono::steady_clock::now();
+ _mm_mfence();
+ const u64 tsc_start = __rdtsc();
+ // Wait for 200 milliseconds.
+ std::this_thread::sleep_for(std::chrono::milliseconds{200});
+ const auto end_time = std::chrono::steady_clock::now();
_mm_mfence();
- const u64 tscEnd = __rdtsc();
- // calculate difference
- const u64 timer_diff =
- std::chrono::duration_cast<std::chrono::nanoseconds>(endTime - startTime).count();
- const u64 tsc_diff = tscEnd - tscStart;
+ const u64 tsc_end = __rdtsc();
+ // Calculate differences.
+ const u64 timer_diff = static_cast<u64>(
+ std::chrono::duration_cast<std::chrono::nanoseconds>(end_time - start_time).count());
+ const u64 tsc_diff = tsc_end - tsc_start;
const u64 tsc_freq = MultiplyAndDivide64(tsc_diff, 1000000000ULL, timer_diff);
return tsc_freq;
}