From 0b9916cae221007ed59f628d2de20abe09880d19 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 17 Apr 2019 12:16:42 +0200 Subject: [PATCH] Timer::Connection: simplify curr_time With the new fact that plain time values are always 64 bit unsigned, the timestamp type is never bigger than the plain time type. Therefore, a code path in the curr_time interpolation that treated this condition is not neccessary anymore. Ref #3208 --- .../src/lib/timeout/timer_connection_time.cc | 38 +++---------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/repos/base/src/lib/timeout/timer_connection_time.cc b/repos/base/src/lib/timeout/timer_connection_time.cc index 39e32b95d3..39ff2327e5 100644 --- a/repos/base/src/lib/timeout/timer_connection_time.cc +++ b/repos/base/src/lib/timeout/timer_connection_time.cc @@ -88,37 +88,9 @@ void Timer::Connection::_update_real_time() * Update timestamp-to-time factor and its shift */ - unsigned factor_shift = _us_to_ts_factor_shift; - uint64_t old_factor = _us_to_ts_factor; - Timestamp max_ts_diff = ~(Timestamp)0ULL >> factor_shift; - Timestamp min_ts_diff_shifted = ~(Timestamp)0ULL >> 1; - - /* - * If the calculation type is bigger than the resulting factor type, - * we have to apply further limitations to avoid a loss at the final cast. - */ - if (sizeof(Timestamp) > sizeof(uint64_t)) { - - Timestamp limit_ts_diff_shifted = (Timestamp)~0UL * us_diff; - Timestamp const limit_ts_diff = limit_ts_diff_shifted >> - factor_shift; - - /* - * Avoid that we leave the factor shift on such a high level that - * casting the factor to its final type causes a loss. - */ - if (max_ts_diff > limit_ts_diff) { - max_ts_diff = limit_ts_diff; - } - /* - * Avoid that we raise the factor shift such that casting the factor - * to its final type causes a loss. - */ - limit_ts_diff_shifted >>= 1; - if (min_ts_diff_shifted > limit_ts_diff_shifted) { - min_ts_diff_shifted = limit_ts_diff_shifted; - } - } + unsigned factor_shift = _us_to_ts_factor_shift; + uint64_t old_factor = _us_to_ts_factor; + Timestamp max_ts_diff = ~(Timestamp)0ULL >> factor_shift; struct Factor_update_failed : Genode::Exception { }; try { @@ -138,7 +110,7 @@ void Timer::Connection::_update_real_time() * Apply current shift to timestamp difference and try to even * raise the shift successively to get as much precision as possible. */ - Timestamp ts_diff_shifted = ts_diff << factor_shift; + uint64_t ts_diff_shifted = ts_diff << factor_shift; while (ts_diff_shifted < us_diff << MIN_FACTOR_LOG2) { factor_shift++; @@ -151,7 +123,7 @@ void Timer::Connection::_update_real_time() * the time difference cannot become null. */ uint64_t const new_factor = - (uint64_t)((Timestamp)ts_diff_shifted / us_diff); + (uint64_t)ts_diff_shifted / us_diff; /* update interpolation-quality value */ if (old_factor > new_factor) { _update_interpolation_quality(new_factor, old_factor); }