From a4ffa849745708f29107e4ad16d3a15a90c6c41e Mon Sep 17 00:00:00 2001 From: ligd Date: Tue, 4 Jun 2024 20:41:20 +0800 Subject: [PATCH] clock: use div_const() to optimize the div speed Signed-off-by: ligd --- include/nuttx/clock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nuttx/clock.h b/include/nuttx/clock.h index 902e2fccb4..c9facdf0cd 100644 --- a/include/nuttx/clock.h +++ b/include/nuttx/clock.h @@ -341,7 +341,7 @@ EXTERN volatile clock_t g_system_ticks; while (0) #define clock_time2ticks(ts) \ - ((clock_t)(ts)->tv_sec * TICK_PER_SEC + (ts)->tv_nsec / NSEC_PER_TICK) + ((clock_t)(ts)->tv_sec * TICK_PER_SEC + div_const((ts)->tv_nsec, NSEC_PER_TICK)) #define clock_usec2time(ts, usec) \ do \ @@ -354,7 +354,7 @@ EXTERN volatile clock_t g_system_ticks; while (0) #define clock_time2usec(ts) \ - ((uint64_t)(ts)->tv_sec * USEC_PER_SEC + (ts)->tv_nsec / NSEC_PER_USEC) + ((uint64_t)(ts)->tv_sec * USEC_PER_SEC + div_const((ts)->tv_nsec, NSEC_PER_USEC)) #define clock_nsec2time(ts, nsec) \ do \