sysprog21 / semu

A minimalist RISC-V system emulator capable of running Linux kernel
MIT License
253 stars 47 forks source link

Enhance precision and safety in time calculations #54

Closed visitorckw closed 2 months ago

visitorckw commented 2 months ago

Introduces a new inline function, mult_frac(), to handle fractional multiplication with improved precision and safety by computing x * n / d while avoiding common issues like overflow and precision loss. Additionally, the semu_timer_clocksource() function has been refactored to use mult_frac() for time-related calculations, including the calculations for converting time derived from clock_gettime() and mach_absolute_time() into clock ticks. These updates collectively enhance the accuracy and reliability of time computations throughout the codebase.

jserv commented 2 months ago

Thank @visitorckw for contributing!