From 73b571c4b76fe635c0917d9262bc9b5fb30a4523 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 21 Sep 2026 14:32:35 +1000 Subject: [PATCH] Timer: Use pause intrinsics when spin-sleeping Hopefully reduce power a tiny amount? --- src/common/timer.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/common/timer.cpp b/src/common/timer.cpp index 958c29298..7474c2204 100644 --- a/src/common/timer.cpp +++ b/src/common/timer.cpp @@ -1,8 +1,10 @@ -// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin +// SPDX-FileCopyrightText: 2019-2026 Connor McLaughlin // SPDX-License-Identifier: CC-BY-NC-ND-4.0 #include "timer.h" +#include "intrin.h" #include "types.h" + #include #include @@ -117,13 +119,17 @@ void Timer::SleepUntil(Value value, bool exact) const Value wake_at = value - ConvertMillisecondsToValue(0.5); Value current = GetCurrentValue(); if (wake_at > current) + { SleepUntil(wake_at, false); + current = GetCurrentValue(); + } // And spin off whatever time is left. - do + while (current < value) { + MultiPause(); current = GetCurrentValue(); - } while (current < value); + } } else { @@ -205,13 +211,17 @@ void Timer::SleepUntil(Value value, bool exact) const Value wake_at = value - min_sleep_time; Value current = GetCurrentValue(); if (wake_at > current) + { SleepUntil(wake_at, false); + current = GetCurrentValue(); + } // And spin off whatever time is left. - do + while (current < value) { + MultiPause(); current = GetCurrentValue(); - } while (current < value); + } } else {