Use union instead of memcpy in float_to_raw — xtensa-gcc doesn't optimize memcpy in all contexts

This commit is contained in:
J. Nick Koston
2026-03-18 10:16:37 -10:00
parent e7d1d08fa1
commit 85be827bb0
+6 -3
View File
@@ -27,9 +27,12 @@ constexpr uint8_t WIRE_TYPE_MASK = 0b111; // Mask to extract wire type
// Reinterpret float bits as uint32_t without floating-point comparison.
// Used by both encode_float() and calc_float() to ensure identical zero checks.
inline uint32_t float_to_raw(float value) {
uint32_t raw;
memcpy(&raw, &value, sizeof(raw));
return raw;
union {
float f;
uint32_t u;
} v;
v.f = value;
return v.u;
}
// Helper functions for ZigZag encoding/decoding