This is an automated email from the ASF dual-hosted git repository. lupyuen pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit a4e9584715413b97a71e4f3f7b5d3e07713f43db Author: zhangyu117 <[email protected]> AuthorDate: Wed May 20 14:44:58 2026 +0800 arch/tricore: optimize perf counter conversion with fast integer division for tc3xx, without div64 hw inst: gcc toolchain software way: 684ns tasking toolchain software way: 3516ns. invdiv_u64: 182ns for tc4xx, with div64 hw inst: div64 hw inst cost 182ns. invdiv_u64: 125ns Although there is a delay of tens of nanoseconds for tc4xx, the impact on performance is minimal, but for simplicity, invdiv_u64 is used. Signed-off-by: zhangyu117 <[email protected]> --- arch/tricore/src/common/tricore_perf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/tricore/src/common/tricore_perf.c b/arch/tricore/src/common/tricore_perf.c index e73c6ba3f0f..987c9f12023 100644 --- a/arch/tricore/src/common/tricore_perf.c +++ b/arch/tricore/src/common/tricore_perf.c @@ -26,6 +26,7 @@ #include <nuttx/arch.h> #include <nuttx/clock.h> +#include <nuttx/lib/math32.h> #include "tricore_internal.h" @@ -36,6 +37,7 @@ ****************************************************************************/ static unsigned long g_cpu_freq = ULONG_MAX; +static invdiv_param64_t g_invdiv_param; /**************************************************************************** * Public Functions @@ -45,6 +47,7 @@ void up_perf_init(void *arg) { g_cpu_freq = (unsigned long)(uintptr_t)arg; + invdiv_init_param64(g_cpu_freq, &g_invdiv_param); IfxCpu_resetAndStartCounters(IfxCpu_CounterMode_normal); } @@ -62,8 +65,8 @@ void up_perf_convert(clock_t elapsed, struct timespec *ts) { clock_t left; - ts->tv_sec = elapsed / g_cpu_freq; + ts->tv_sec = invdiv_u64(elapsed, &g_invdiv_param); left = elapsed - ts->tv_sec * g_cpu_freq; - ts->tv_nsec = NSEC_PER_SEC * (uint64_t)left / g_cpu_freq; + ts->tv_nsec = invdiv_u64(NSEC_PER_SEC * (uint64_t)left, &g_invdiv_param); } #endif
