Skip to content

Commit c3a6710

Browse files
committed
Optimize semu_timer_clocksource() precision on macOS
Improve the precision of semu_timer_clocksource() by deferring the division by 1e9 until the final step. Since t.numer and t.denom are typically much smaller compared to the clock frequency and 1e9, performing the division earlier in the calculation could result in a significant loss of precision. This change ensures that precision is preserved by delaying the division until the end of the computation.
1 parent 1dc59cb commit c3a6710

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

utils.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ static uint64_t semu_timer_clocksource(uint64_t freq)
4848
static mach_timebase_info_data_t t;
4949
if (t.denom == 0)
5050
(void) mach_timebase_info(&t);
51-
return mult_frac(mult_frac(mach_absolute_time(), freq, 1e9), t.numer,
52-
t.denom);
51+
return mult_frac(mult_frac(mach_absolute_time(), t.numer, t.denom), freq,
52+
1e9);
5353
#else
5454
return time(0) * freq;
5555
#endif

0 commit comments

Comments
 (0)