From 4283c71be5e93a286eddcc04608aabdfee7643ce Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 8 Jun 2026 13:04:53 -0500 Subject: [PATCH] Use float and not double in calcRxDelay * Swaps constant double values for constant float values * Use `powf` instead of `pow` for the calcualation On an ESP32 platform, this eliminates several implicit calls to the soft floating point routines __extendsfdf2, __subdf3, __floatunsidf, __muldf3, and __fixdfsi. After making the change, only the `powf` call remains. The code size also shrinks by ~80 bytes in a companion radio build. --- examples/companion_radio/MyMesh.cpp | 2 +- examples/simple_repeater/MyMesh.cpp | 2 +- examples/simple_room_server/MyMesh.cpp | 2 +- examples/simple_sensor/SensorMesh.cpp | 2 +- src/Dispatcher.cpp | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/companion_radio/MyMesh.cpp b/examples/companion_radio/MyMesh.cpp index c468967f97..87ea68a8d6 100644 --- a/examples/companion_radio/MyMesh.cpp +++ b/examples/companion_radio/MyMesh.cpp @@ -264,7 +264,7 @@ int MyMesh::getInterferenceThreshold() const { int MyMesh::calcRxDelay(float score, uint32_t air_time) const { if (_prefs.rx_delay_base <= 0.0f) return 0; - return (int)((pow(_prefs.rx_delay_base, 0.85f - score) - 1.0) * air_time); + return (int)((powf(_prefs.rx_delay_base, 0.85f - score) - 1.0f) * air_time); } uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) { diff --git a/examples/simple_repeater/MyMesh.cpp b/examples/simple_repeater/MyMesh.cpp index 096907494b..b04b1c2ce6 100644 --- a/examples/simple_repeater/MyMesh.cpp +++ b/examples/simple_repeater/MyMesh.cpp @@ -537,7 +537,7 @@ void MyMesh::logTxFail(mesh::Packet *pkt, int len) { int MyMesh::calcRxDelay(float score, uint32_t air_time) const { if (_prefs.rx_delay_base <= 0.0f) return 0; - return (int)((pow(_prefs.rx_delay_base, 0.85f - score) - 1.0) * air_time); + return (int)((powf(_prefs.rx_delay_base, 0.85f - score) - 1.0f) * air_time); } uint32_t MyMesh::getRetransmitDelay(const mesh::Packet *packet) { diff --git a/examples/simple_room_server/MyMesh.cpp b/examples/simple_room_server/MyMesh.cpp index 98b22fdb72..16951411c1 100644 --- a/examples/simple_room_server/MyMesh.cpp +++ b/examples/simple_room_server/MyMesh.cpp @@ -259,7 +259,7 @@ void MyMesh::logTxFail(mesh::Packet *pkt, int len) { int MyMesh::calcRxDelay(float score, uint32_t air_time) const { if (_prefs.rx_delay_base <= 0.0f) return 0; - return (int)((pow(_prefs.rx_delay_base, 0.85f - score) - 1.0) * air_time); + return (int)((powf(_prefs.rx_delay_base, 0.85f - score) - 1.0f) * air_time); } const char *MyMesh::getLogDateTime() { diff --git a/examples/simple_sensor/SensorMesh.cpp b/examples/simple_sensor/SensorMesh.cpp index 879fcbf026..739f4ca30f 100644 --- a/examples/simple_sensor/SensorMesh.cpp +++ b/examples/simple_sensor/SensorMesh.cpp @@ -309,7 +309,7 @@ bool SensorMesh::allowPacketForward(const mesh::Packet* packet) { int SensorMesh::calcRxDelay(float score, uint32_t air_time) const { if (_prefs.rx_delay_base <= 0.0f) return 0; - return (int) ((pow(_prefs.rx_delay_base, 0.85f - score) - 1.0) * air_time); + return (int) ((powf(_prefs.rx_delay_base, 0.85f - score) - 1.0f) * air_time); } uint32_t SensorMesh::getRetransmitDelay(const mesh::Packet* packet) { diff --git a/src/Dispatcher.cpp b/src/Dispatcher.cpp index 9d7a11131d..964bc76e7f 100644 --- a/src/Dispatcher.cpp +++ b/src/Dispatcher.cpp @@ -53,7 +53,7 @@ void Dispatcher::updateTxBudget() { } int Dispatcher::calcRxDelay(float score, uint32_t air_time) const { - return (int) ((pow(10, 0.85f - score) - 1.0) * air_time); + return (int) ((powf(10, 0.85f - score) - 1.0f) * air_time); } uint32_t Dispatcher::getCADFailRetryDelay() const { @@ -386,4 +386,4 @@ unsigned long Dispatcher::futureMillis(int millis_from_now) const { return _ms->getMillis() + millis_from_now; } -} \ No newline at end of file +}