From 7512485b9440b742b38da451aaca4a72369596ec Mon Sep 17 00:00:00 2001 From: X512 Date: Sun, 26 Jan 2020 14:48:30 +0100 Subject: [PATCH] Optimize system_time function The uint128 code does not optimize as well as expected. Since this function can be called quite often, use a more optimal implementation (quite similar to what we had for x86_64 before refactoring). Unfortunately this is still not as good as the hand-optimized assembler previously used for 32bit x86, unless compiled with clang, where it gets pretty close. --- src/system/boot/arch/x86/cpu.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/system/boot/arch/x86/cpu.cpp b/src/system/boot/arch/x86/cpu.cpp index 9843a6cf76..9389fe042b 100644 --- a/src/system/boot/arch/x86/cpu.cpp +++ b/src/system/boot/arch/x86/cpu.cpp @@ -304,8 +304,10 @@ slower_sample: extern "C" bigtime_t system_time() { - uint128 tsc(rdtsc()); - return uint64((tsc * gTimeConversionFactor) >> 32); + uint64 tsc = rdtsc(); + uint64 lo = (uint32)tsc; + uint64 hi = tsc >> 32; + return ((lo * gTimeConversionFactor) >> 32) + hi * gTimeConversionFactor; }