Changeset c734e86 in rtems


Ignore:
Timestamp:
Jan 8, 2021, 10:59:40 AM (3 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
30c71c3
Parents:
9d2db27a
git-author:
Sebastian Huber <sebastian.huber@…> (01/08/21 10:59:40)
git-committer:
Sebastian Huber <sebastian.huber@…> (01/26/21 14:29:36)
Message:

cpucounter: Increase conversion accuracy

The maximum frequency is UINT32_MAX. Converted to a uint64_t variable
it can be shifted by 32. The addition does not overflow since bin_per_s

  • 1 is UINT32_MAX.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpukit/sapi/src/cpucounterconverter.c

    r9d2db27a rc734e86  
    4343rtems_counter_ticks rtems_counter_sbintime_to_ticks( int64_t sbt )
    4444{
    45   return (rtems_counter_ticks) (((uint64_t) sbt * from_sbt_scaler) >> 31);
     45  return (rtems_counter_ticks) (((uint64_t) sbt * from_sbt_scaler) >> 32);
    4646}
    4747
     
    5050  uint64_t ns_per_s = UINT64_C(1000000000);
    5151  uint64_t bin_per_s = UINT64_C(1) << 32;
     52  uint64_t bin_freq = (uint64_t) frequency << 32;
    5253
    5354  to_ns_scaler = ((ns_per_s << 32) + frequency - 1) / frequency;
    54   from_ns_scaler = ((UINT64_C(1) << 32) * frequency + ns_per_s - 1) / ns_per_s;
     55  from_ns_scaler = (bin_freq + ns_per_s - 1) / ns_per_s;
    5556
    5657  to_sbt_scaler = ((bin_per_s << 31) + frequency - 1) / frequency;
    57   from_sbt_scaler = ((UINT64_C(1) << 31) * frequency + bin_per_s - 1) / bin_per_s;
     58  from_sbt_scaler = (bin_freq + bin_per_s - 1) / bin_per_s;
    5859}
    5960
Note: See TracChangeset for help on using the changeset viewer.