Skip to content

Commit cce5280

Browse files
GUIDINGLIxiaoxiang781216
authored andcommitted
clock: use div_const() to optimize the div speed
Signed-off-by: ligd <liguiding1@xiaomi.com>
1 parent 48f2a07 commit cce5280

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

include/nuttx/clock.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ EXTERN volatile clock_t g_system_ticks;
334334
do \
335335
{ \
336336
clock_t _tick = (tick); \
337-
(ts)->tv_sec = _tick / TICK_PER_SEC; \
337+
(ts)->tv_sec = div_const(_tick, TICK_PER_SEC); \
338338
_tick -= (clock_t)(ts)->tv_sec * TICK_PER_SEC; \
339339
(ts)->tv_nsec = _tick * NSEC_PER_TICK; \
340340
} \
@@ -347,7 +347,7 @@ EXTERN volatile clock_t g_system_ticks;
347347
do \
348348
{ \
349349
uint64_t _usec = (usec); \
350-
(ts)->tv_sec = _usec / USEC_PER_SEC; \
350+
(ts)->tv_sec = div_const(_usec, USEC_PER_SEC); \
351351
_usec -= (uint64_t)(ts)->tv_sec * USEC_PER_SEC; \
352352
(ts)->tv_nsec = _usec * NSEC_PER_USEC; \
353353
} \
@@ -360,7 +360,7 @@ EXTERN volatile clock_t g_system_ticks;
360360
do \
361361
{ \
362362
uint64_t _nsec = (nsec); \
363-
(ts)->tv_sec = _nsec / NSEC_PER_SEC; \
363+
(ts)->tv_sec = div_const(_nsec, NSEC_PER_SEC); \
364364
_nsec -= (uint64_t)(ts)->tv_sec * NSEC_PER_SEC; \
365365
(ts)->tv_nsec = _nsec; \
366366
} \

0 commit comments

Comments
 (0)