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
This commit is contained in:
Billy Laws 2022-07-29 19:52:38 +01:00
parent 1df98ba57f
commit 0e1aa765fc

View File

@ -27,7 +27,7 @@ namespace skyline::util {
u64 frequency; u64 frequency;
asm("MRS %0, CNTFRQ_EL0" : "=r"(frequency)); asm("MRS %0, CNTFRQ_EL0" : "=r"(frequency));
u64 ticks; u64 ticks;
asm("MRS %0, CNTVCT_EL0" : "=r"(ticks)); asm volatile("MRS %0, CNTVCT_EL0" : "=r"(ticks));
return static_cast<i64>(((ticks / frequency) * constant::NsInSecond) + (((ticks % frequency) * constant::NsInSecond + (frequency / 2)) / frequency)); return static_cast<i64>(((ticks / frequency) * constant::NsInSecond) + (((ticks % frequency) * constant::NsInSecond + (frequency / 2)) / frequency));
} }
@ -37,7 +37,7 @@ namespace skyline::util {
*/ */
inline u64 GetTimeTicks() { inline u64 GetTimeTicks() {
u64 ticks; u64 ticks;
asm("MRS %0, CNTVCT_EL0" : "=r"(ticks)); asm volatile("MRS %0, CNTVCT_EL0" : "=r"(ticks));
return ticks; return ticks;
} }