From 8c5e74719039c7275a5a80b236b830b7b4ba1be7 Mon Sep 17 00:00:00 2001 From: Alex Smith Date: Mon, 9 Jul 2012 12:25:49 +0100 Subject: [PATCH] Don't need to shift the factor in system_time(), just store the already shifted value. --- src/system/kernel/arch/x86/arch_cpu.cpp | 3 ++- src/system/libroot/os/arch/x86_64/system_time_asm.S | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/system/kernel/arch/x86/arch_cpu.cpp b/src/system/kernel/arch/x86/arch_cpu.cpp index 2c61241a47..41713b3a57 100644 --- a/src/system/kernel/arch/x86/arch_cpu.cpp +++ b/src/system/kernel/arch/x86/arch_cpu.cpp @@ -824,7 +824,8 @@ arch_cpu_init(kernel_args* args) // The x86_64 system_time() implementation uses 64-bit multiplication and // therefore shifting is not necessary for low frequencies (it's also not // too likely that there'll be any x86_64 CPUs clocked under 1GHz). - __x86_setup_system_time(conversionFactor, conversionFactorNsecs); + __x86_setup_system_time((uint64)conversionFactor << 32, + conversionFactorNsecs); #else if (conversionFactorNsecs >> 32 != 0) { // the TSC frequency is < 1 GHz, which forces us to shift the factor diff --git a/src/system/libroot/os/arch/x86_64/system_time_asm.S b/src/system/libroot/os/arch/x86_64/system_time_asm.S index 135b54a4c3..641c86de26 100644 --- a/src/system/libroot/os/arch/x86_64/system_time_asm.S +++ b/src/system/libroot/os/arch/x86_64/system_time_asm.S @@ -29,9 +29,9 @@ FUNCTION_END(__x86_setup_system_time) /* int64 system_time(); */ FUNCTION(system_time): // (rdtsc * cv_factor) >> 32. + // Factor is pre-shifted left by 32 bits. movq cv_factor, %rcx - shl $32, %rcx // Load 64-bit TSC into %eax (low), %edx (high). rdtsc @@ -43,7 +43,7 @@ FUNCTION(system_time): // Multiply by conversion factor, result in %rax (low), %rdx (high). mulq %rcx - // Conversion factor preshifted by 32, whole result in high. + // Due to pre-shifting of the factor the whole result in high. movq %rdx, %rax ret FUNCTION_END(system_time) @@ -53,7 +53,7 @@ FUNCTION_END(system_time) FUNCTION(system_time_nsecs): // Same algorithm as system_time(), but with a different factor. // (rdtsc * cv_factor_nsecs) >> 32. - // Cannot pre-shift the factor here, otherwise we may lose the upper + // Factor has not been pre-shifted here, otherwise we may lose the upper // 32 bits. movq cv_factor_nsecs, %rcx