mirror of
https://github.com/genodelabs/genode.git
synced 2025-02-20 17:52:52 +00:00
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
This commit is contained in:
parent
181c78d482
commit
0b9916cae2
@ -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); }
|
||||
|
Loading…
x
Reference in New Issue
Block a user