From 7b40898cffbde503d1f479ac149a031ae0f54ed1 Mon Sep 17 00:00:00 2001 From: Julian Oes Date: Thu, 19 Nov 2026 13:18:04 +1300 Subject: [PATCH] perf(rc): use lroundf for the S.Bus scaling The S.Bus scale constants are float, so lround promoted the argument to double and pulled soft-double code into FPU-less targets like the IO. lroundf rounds the same float value identically (checked exhaustively over all encode and decode inputs) and saves 1104 B on the IO. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Julian Oes --- src/lib/rc/sbus.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/rc/sbus.cpp b/src/lib/rc/sbus.cpp index e6479afb70e..ab90b1e0b90 100644 --- a/src/lib/rc/sbus.cpp +++ b/src/lib/rc/sbus.cpp @@ -237,7 +237,7 @@ sbus1_output(int sbus_fd, uint16_t *values, uint16_t num_values) * currently ignoring single bit channels. */ for (unsigned i = 0; (i < num_values) && (i < 16); ++i) { - long scaled = lround((values[i] - SBUS_SCALE_OFFSET) / SBUS_SCALE_FACTOR); + long scaled = lroundf((values[i] - SBUS_SCALE_OFFSET) / SBUS_SCALE_FACTOR); /* limit to 11 bits before the cast: a value below the scale offset (an output with no * function is 0) is negative and would wrap to full scale */ @@ -649,7 +649,7 @@ sbus_decode(uint64_t frame_time, uint8_t *frame, uint16_t *values, uint16_t *num /* convert 0-2048 values to 1000-2000 ppm encoding in a not too sloppy fashion */ - values[channel] = static_cast(lround(value * SBUS_SCALE_FACTOR) + SBUS_SCALE_OFFSET); + values[channel] = static_cast(lroundf(value * SBUS_SCALE_FACTOR) + SBUS_SCALE_OFFSET); } /* decode switch channels if data fields are wide enough */