Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions BUILDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 14 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,23 @@ add_compile_definitions(
$<$<NOT:$<CONFIG:Debug>>: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()

Expand Down
Loading