Skip to content

[M0-CORE-03] SimMath interface + fp32_pinned backend - #3

Merged
offdev merged 1 commit into
masterfrom
m0-core-03-simmath
Sep 11, 2026
Merged

offdev merged 1 commit into
masterfrom
m0-core-03-simmath

Conversation

@offdev

@offdev offdev commented Sep 10, 2026

Copy link
Copy Markdown
Owner

Step

Roadmap M0-CORE-03 (M0-foundations.md): SimMath interface + fp32_pinned backend. Refs: ADR 0002, PRD §10.3, S-7/G-R8.

What

  • src/laige-core/include/laige/sim_math.h — laige::sim::SimMath<Backend> op surface (add/sub/mul/div; ordered IEEE comparisons + isNaN/isInf/isFinite/isOrdered; clamp, lerp, normalize, length over scalar/Vec2/Vec3) and the Fp32Pinned backend (IEEE binary32 primitives). The pinned flag set and the full NaN/Inf policy are documented in the header — defined, not "whatever the CPU does".
  • src/laige-core/sim_math.cpp — pinned explicit instantiation (linkable symbol in both static and shared variants).
  • Root CMakeLists.txt — laige_apply_simmath_policy(): the ADR 0002 pinned set (-ffp-contract=off -fno-associative-math GCC/Clang/AppleClang; /fp:precise MSVC) on every sim target; applied to laige-core and the test targets.
  • tests/laige-core/math_float_tests.cpp — ctest -R math_float: 22 tests / 4 suites (bit-exact known values incl. ±0; full NaN/Inf policy; property tests incl. documented 4-ulp normalize round-trip tolerance; runtime FMA canaries that fail if the pinned flags are ever missing).
  • Docs: docs/api/sim_math.md (API contract + performance + misuse warnings), src/laige-core/README.md, docs/getting-started/building.md.

Bug found and fixed along the way

The existing result_status and logging CTest entries passed their --gtest_filter as quoted arguments. CTest passes quoted args through with the literal quote characters, and gtest's colon-split of the filter then silently matched only one pattern of each — so ctest -R result_status was running 4 tests / 1 suite instead of 17 / 3, and ctest -R logging 8 of 8 suites partially. All three entries now pass one unquoted filter argument (comment in tests/laige-core/CMakeLists.txt explains the hazard).

Verification

  • ctest -R math_float green (22 tests / 4 suites).
  • Full ctest green in: default tree, build-shared (-DLAIGE_BUILD_SHARED=ON), build-asan, build-tsan, plus the Clang 22 tree (GCC 16.2.1 is the default).
  • Pinned flags confirmed on the compile lines of laige-core and laige-core_tests (-ffp-contract=off -fno-associative-math).
  • FMA-canary sensitivity verified by a negative scratch build with -ffp-contract=fast -mfma: DotProductCanaryDetectsFmaContraction fails as designed.
  • include-lint green (real tree).

No dependencies added; no public API outside laige-core changed; roadmap step M0-CORE-03 marked done (its Verify commands pass). Next step per roadmap: M0-CORE-04 (fpx16_16 default backend).

Implements roadmap step M0-CORE-03 (ADR 0002, PRD §10.3, S-7/G-R8):
the single deterministic-math interface with the fp32_pinned backend.

- include/laige/sim_math.h: laige::sim::SimMath<Backend> op surface
  (add/sub/mul/div, ordered IEEE comparisons + NaN/Inf predicates,
  clamp, lerp, normalize, length over scalar/Vec2/Vec3) and the
  Fp32Pinned backend (IEEE binary32, add/sub/mul/div/sqrt primitives).
  The pinned flag set and the full NaN/Inf policy are documented in
  the header (defined, not "whatever the CPU does").
- sim_math.cpp: pinned explicit instantiation of the fp32_pinned
  backend (linkable symbol in both static and shared variants).
- CMake: laige_apply_simmath_policy() pins the ADR 0002 flag set
  (-ffp-contract=off -fno-associative-math GCC/Clang/AppleClang,
  /fp:precise MSVC) on every sim target; applied to laige-core and
  the test targets.
- tests/laige-core/math_float_tests.cpp: ctest -R math_float (22 tests,
  4 suites) — bit-exact known values, the full NaN/Inf policy, property
  tests (clamp idempotence, normalize round-trip within a documented
  4-ulp tolerance, sign invariance), and runtime FMA canaries
  (DotProductCanary, LerpIsNotFmaFused) that fail if the pinned flags
  are ever missing — sensitivity verified with a negative build
  (-ffp-contract=fast -mfma).
- Fix a latent CTest defect found while wiring math_float: quoted
  --gtest_filter arguments are passed through with literal quotes, and
  gtest's colon-split then silently under-ran the result_status and
  logging Verify suites (only one pattern of each matched). All three
  entries now pass one unquoted filter argument; result_status runs
  17 tests/3 suites and logging 27/8 again.
- Docs: docs/api/sim_math.md (API contract, backend table, pinned set,
  NaN/Inf policy, performance, misuse warnings), laige-core README
  entry, building.md pinned-policy section + math_float CTest entry.

Verified: ctest -R math_float green; full ctest green in the default,
shared (LAIGE_BUILD_SHARED), ASan, and TSan trees, plus the Clang 22
tree; pinned flags confirmed on the compile lines of laige-core and
laige-core_tests; include-lint green.
@offdev
offdev merged commit 0fd41f3 into master Sep 11, 2026
8 checks passed
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