nrf: fix off-by-one in modulo of runtime.ticks
This code: foo & 0xffffff Is equivalent to this code: foo % 0x1000000 However, to drop the high 8 bits, this calculation was used: foo % 0xffffff This is far more expensive (and incorrect), as it needs an actual modulo operation which increases code size and probably reduces speed on a Cortex-M4 and needs library functions for a Cortex-M0 increasing code size by a much bigger amount.
Этот коммит содержится в:
родитель
c1a833c7cc
коммит
5bf058a0a6
1 изменённых файлов: 1 добавлений и 1 удалений
|
@ -75,7 +75,7 @@ var (
|
|||
// handling the overflow event.
|
||||
func ticks() timeUnit {
|
||||
rtcCounter := uint32(nrf.RTC0.COUNTER)
|
||||
offset := (rtcCounter - rtcLastCounter) % 0xffffff // change since last measurement
|
||||
offset := (rtcCounter - rtcLastCounter) & 0xffffff // change since last measurement
|
||||
rtcLastCounter = rtcCounter
|
||||
timestamp += timeUnit(offset) // TODO: not precise
|
||||
return timestamp
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче