From 5f3e5278fd2c270645b2295eb18a35a7c5936a3b Mon Sep 17 00:00:00 2001 From: Rowan Date: Tue, 25 Aug 2026 16:17:02 +1000 Subject: [PATCH] Build strict: -ffp-contract=off replaces -ffast-math on every target Enacts the estate policy for mas-bandwidth network libraries (Glenn, 2026-08-24): network libraries build with -ffp-contract=off on GCC/Clang and /fp:precise on MSVC. netcode carried -ffast-math / /fp:fast; those are gone. netcode's wire format carries no floating point, so this is the family floor rather than a wire fix, and BUILDING.md says exactly that to consumers. CI builds through CMakeLists.txt, so every CI leg now builds strict. Verified on this bench: Release build green, unit tests pass, and the flag confirmed on the actual compile lines of netcode.c and test.cpp (--verbose), with zero remaining -ffast-math occurrences. Co-Authored-By: Claude Fable 5 --- BUILDING.md | 17 +++++++++++++++++ CMakeLists.txt | 16 ++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index e656e84..2e3ff5f 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -38,6 +38,23 @@ By default netcode builds as a static library against the vendored libsodium sub - `BUILD_SHARED_LIBS=ON` builds `libnetcode` as a shared library. - `cmake --install` installs `netcode.h` and the library (`NETCODE_INSTALL=OFF` disables the install target, e.g. when embedding netcode as a subproject). +## Floating point: netcode builds with -ffp-contract=off + +Estate policy for mas-bandwidth network libraries: builds are strict about floating point +contraction. This build sets the right flag on every target, so nothing is required of you to +build netcode itself: + + - GCC/Clang: `-ffp-contract=off`. Not merely the absence of `-ffast-math` — GCC's default + is `-ffp-contract=fast`, which contracts across statement boundaries, and clang's default + `=on` still fuses within a single expression. + - MSVC: `/fp:precise`. + +netcode's wire format carries no floating point, so no flag is required of consumers for +correct wire bytes today. The strict build is the family floor: contraction is +architecture-dependent (FMA is in the aarch64 baseline and absent from the x86-64 one), so +float arithmetic near a wire diverges bit-wise between architectures without it. If you +compile `netcode.c` into your own build rather than linking the library, carry the same flag. + ## Sanitizers and fuzzing To build everything with AddressSanitizer and UndefinedBehaviorSanitizer, configure with `-DNETCODE_SANITIZE=ON` and run the tests as usual: diff --git a/CMakeLists.txt b/CMakeLists.txt index 860c7fa..c9d2612 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,11 +33,23 @@ add_compile_definitions( $<$>:NETCODE_RELEASE> ) +# strict floating point. Estate policy for mas-bandwidth network libraries: "generally +# speaking, network libraries we work on require -ffp-contract=off" (Glenn, 2026-08-24). +# - GCC/Clang: -ffp-contract=off. Not merely "no -ffast-math" -- GCC's default is +# -ffp-contract=fast, which contracts across statements, and clang's default =on still +# fuses within a single expression. +# - MSVC: /fp:precise, which since VS 2022 does not imply contraction. +# netcode's wire format carries no floating point -- the floats here are connection stats +# and the network simulator -- so this is the family floor rather than a wire fix: +# contraction is architecture-dependent (FMA is in the aarch64 baseline and absent from +# the x86-64 one), so any float arithmetic that ever nears the wire diverges bit-wise +# between architectures without it. CI builds through this file, so every CI leg builds +# with these flags. if(MSVC) - add_compile_options(/fp:fast) + add_compile_options(/fp:precise) set(NETCODE_WARNINGS /W4) else() - add_compile_options(-ffast-math) + add_compile_options(-ffp-contract=off) set(NETCODE_WARNINGS -Wall -Wextra) endif()