From 0e1aa765fc12912b6538acd5a0f10f37206f03ff Mon Sep 17 00:00:00 2001 From: Billy Laws Date: Fri, 29 Jul 2022 19:52:38 +0100 Subject: [PATCH] Prevent CNTVCT_EL0 reads from being optimised out by the compiler Without this the compiler will assume the read always produces the same value, causing issues when the register is used to time function execution --- app/src/main/cpp/skyline/common/utils.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/cpp/skyline/common/utils.h b/app/src/main/cpp/skyline/common/utils.h index bf7ab9af..e57fd2b9 100644 --- a/app/src/main/cpp/skyline/common/utils.h +++ b/app/src/main/cpp/skyline/common/utils.h @@ -27,7 +27,7 @@ namespace skyline::util { u64 frequency; asm("MRS %0, CNTFRQ_EL0" : "=r"(frequency)); u64 ticks; - asm("MRS %0, CNTVCT_EL0" : "=r"(ticks)); + asm volatile("MRS %0, CNTVCT_EL0" : "=r"(ticks)); return static_cast(((ticks / frequency) * constant::NsInSecond) + (((ticks % frequency) * constant::NsInSecond + (frequency / 2)) / frequency)); } @@ -37,7 +37,7 @@ namespace skyline::util { */ inline u64 GetTimeTicks() { u64 ticks; - asm("MRS %0, CNTVCT_EL0" : "=r"(ticks)); + asm volatile("MRS %0, CNTVCT_EL0" : "=r"(ticks)); return ticks; }