Skip to content

tests: the wake, boat-plant and tape tests without FMA contraction (master's macOS lanes) - #1606

Merged
transfix merged 2 commits into
masterfrom
fix/macos-golden-hashes
Nov 28, 2026
Merged

transfix merged 2 commits into
masterfrom
fix/macos-golden-hashes

Conversation

@transfix

@transfix transfix commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Fixes master's red CI (recipe-first) macOS lanes (recipe / macos-latest / Release and / Debug). They have failed libcvc's recipe ctest on every completed master run since 2026-11-25 (db642b6). PR runs skip macOS, so no PR showed it.

Cause

FMA contraction in three test files. Clang's default (-ffp-contract=on) fuses a * b + c into an FMA where the ISA has one. That means aarch64 (the macOS arm64 lanes), but not x86-64 Linux or MSVC (/fp:strict). The physics and ocean code these tests check is built with -ffp-contract=off, and the test files were not.

test lanes since what contracts
DynBoatPlant.CrossPlatformGoldenHash Debug #1538 (a529459) the test's dot(), called by libcvc (below)
PhysicsFieldWake.CrossPlatformGoldenHash Debug #1532 (dcc3c57) the test's dot(), called by libcvc
PhysicsFieldWakeShore.CrossPlatformGoldenHash Release, Debug #1532 the coast 7 - x - 0.2 |y| built in the test, plus dot() in Debug
PhTrain.TheTapesDerivativesMatchFiniteDifferences Release, Debug #1560 (1c7221d) the double side of f.v == expression(x0, y0): 5 to 8 ulps, past EXPECT_DOUBLE_EQ's 4

The Debug-only goldens: #1538 and #1532 added the first dot() calls to physics_dyn_boat_plant_test.cpp and physics_field_test.cpp. At -O0, cvc/physics/types.h's inline dot() is emitted as a weak definition in the test executable. dyld binds the shared libcvc's weak references to the first definition it loads, which is the executable's. So the field step (built with -ffp-contract=off) ended up calling the test's contracted dot(). Release inlines dot() at each call site with that file's flags, so it is unaffected.

The runner image is not the cause. The last green run (45610380387 on 3df78a3) and the red ones ran the same macos-26-arm64 20261117.0516 image with AppleClang 21.0.0. The failures also track the merges, on both the 20261117 and 20261123 images.

Fix

Build physics_field_test.cpp, physics_dyn_boat_plant_test.cpp and ph_train_test.cpp the way physics_dyn_bike_plant_test, nav_potential_test and physics_immersion_test already are: -ffp-contract=off, and /fp:precise under MSVC. No golden, tolerance or library code changes.

Testing

  • macOS: the ci/full/macos-fp-contract push run of CI (recipe-first) (46092709441) is green on all six jobs. Both macOS lanes ran macos-26-arm64 20261123.0526 with AppleClang 21.0.0, the image the reds also hit. ctest reported 100% tests passed (8695 tests in Release, 8693 in Debug), and no test needed the until-pass retry. All four tests above passed in both lanes, so the Debug lanes confirm the weak-definition explanation.
  • Linux and Windows: this PR's own CI.

…ion (macOS arm64)

Since #1538, #1532 and #1560, master's macos-latest recipe lanes have failed four tests that
pass on Linux and Windows. All four are contraction: clang's default on aarch64 fuses
multiply-adds into FMAs in these test files, while the code they check is built with
-ffp-contract=off.

- PhysicsFieldWakeShore.CrossPlatformGoldenHash (Release and Debug): the coast the test hands
  the wake, 7 - x - 0.2 |y|, fuses into an FMA.
- PhysicsFieldWake.CrossPlatformGoldenHash and DynBoatPlant.CrossPlatformGoldenHash (Debug
  only): #1532 and #1538 added the first dot() calls to physics_field_test.cpp and
  physics_dyn_boat_plant_test.cpp. At -O0, cvc/physics/types.h's inline dot() is a weak
  definition in the test executable, and dyld binds the shared libcvc's calls to it. So the
  field step ran a contracted dot().
- PhTrain.TheTapesDerivativesMatchFiniteDifferences: the tape rounds once per operation, but
  the same expression over double fuses x * y + 2 x and 1.5 + x * x. It lands 5 to 8 ulps off,
  past EXPECT_DOUBLE_EQ's 4.

The runner image did not cause it: the last green run and the red ones used the same
macos-26-arm64 image and AppleClang 21.

Build the three TUs as physics_dyn_bike_plant_test and nav_potential_test already are:
-ffp-contract=off, and /fp:precise under MSVC.
@transfix
transfix enabled auto-merge (squash) November 28, 2026 10:15
@transfix
transfix merged commit e56b8ad into master Nov 28, 2026
30 checks passed
@transfix
transfix deleted the fix/macos-golden-hashes branch November 28, 2026 12:25
transfix added a commit that referenced this pull request Nov 29, 2026
…racted or not (#1635)

cvc/physics/types.h's inline dot() fused into FMAs in any translation unit
built with contraction: clang's default -ffp-contract=on on aarch64, gcc's
default -ffp-contract=fast, MSVC's /fp:contract and /fp:fast.  The
deterministic sources are built with -ffp-contract=off, so the bits depended on
the caller's flags, and in a shared macOS Debug build dyld bound libcvc's own
calls to a test executable's contracted copy (the cause #1606 worked around
with per-TU flags).  Under -ffp-contract=fast the same held for a caller's
p + v * s.

Each product is now rounded before anything is added to it:

- gcc and clang on aarch64 and x86-64: detail::rounded(), an empty asm on the
  product ("+w" / "+x", as glibc's math_opt_barrier).  No instruction, and
  dot() stays inline.
- MSVC: #pragma fp_contract(off) around the operators and dot() only
  (float_control push/pop).

Checked in the generated code first.  For arm64 macOS, clang 20 and 22 under
-ffp-contract=off, on, fast and fast-honor-pragmas, at -O0 (the weak copy) and
-O2 (inlined): no FMA in dot(), operator* or a caller's p + v * s.  The
instruction sequence is the uncontracted one.  On an x86-64 with FMA, a hash
over 200000 random inputs (inlined, the out-of-line copies, p + v * s) is the
-ffp-contract=off hash for gcc 16, clang 20, MSVC 19.44 and clang-cl 22 in
every mode.  The old header gave five other hashes.  What did not work:
#pragma clang fp contract(off) and #pragma STDC FP_CONTRACT OFF (clang
disregards them under -ffp-contract=fast, gcc ignores them), named
temporaries (stop only -ffp-contract=on), gcc's optimize("fp-contract=off")
(gcc then will not inline dot()).  gcc's __builtin_assoc_barrier works, but
clang has no such builtin.

Goldens are untouched: the hardened helpers compute what the
-ffp-contract=off sources always did.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant