Skip to content

Xezon/wip deterministic math v3#8

Open
xezon wants to merge 71 commits into
main-superhackers-on-xezon-forkfrom
xezon/wip-deterministic-math-v3
Open

Xezon/wip deterministic math v3#8
xezon wants to merge 71 commits into
main-superhackers-on-xezon-forkfrom
xezon/wip-deterministic-math-v3

Conversation

@xezon

@xezon xezon commented May 26, 2026

Copy link
Copy Markdown
Owner

No description provided.

Okladnoj and others added 30 commits May 25, 2026 13:13
Integrate GameMath library (fdlibm) for bit-perfect cross-platform
floating-point reproducibility. When USE_DETERMINISTIC_MATH is active,
all WWMath functions (Sin, Cos, Sqrt, Inv_Sqrt, Float_To_Long, Acos,
Asin, Atan, Atan2) use fdlibm instead of x87 asm or system CRT.

- Add GameMath via FetchContent with global include paths
- Replace Trig.cpp with inline WWMath::*Trig wrappers
- Add WWMath::*Origin wrappers for bare CRT calls in game logic
- Prioritize USE_DETERMINISTIC_MATH over _MSC_VER/_M_IX86 guards
- Verified: win32 replay CRC matches original x87 output
Add global Sqrt(double) to trig.h/Trig.cpp, routing through
WWMath::SqrtOrigin(). Replace 5 bare CRT sqrt() calls in BaseType.h
(Coord2D::length, Coord2D::toAngle, ICoord2D::length,
Coord3D::length, ICoord3D::length) with the new Sqrt() gateway.

This closes the last known CRT math leak in CRC-critical code paths.
Same pattern as existing Sin/Cos/ACos routing via Trig.cpp.
…erage

- Restore original Trig.cpp code (author comments, defines, REGENERATE_TRIG_TABLES)
- Keep only functional changes: sinf->WWMath::SinTrig redirects + Sqrt(double)
- Restore original tab alignment in wwmath.h #define block
- Route remaining CRT calls in SimulationMathCrc through WWMath (sinh/cosh/tanh/logf)
- Add cmake comments explaining FORCE usage
- Add RUN_MATH_BENCHMARK_REPLAY400_FLAG to SimulationMathCrc.h
- Implement 10000-iteration dual-path benchmark in SimulationMathCrc.cpp
- Inject benchmark trigger into GameLogic::update at replay frame 400
- Benchmark measures CRT vs WWMath precision and performance
- Declare loop iterator outside of for loop in runBenchmark to support legacy MSVC scoping rules
- Merge gmath.h include + USE_DETERMINISTIC_MATH into single __has_include block
- Replace all #ifdef/#if defined() with #if USE_DETERMINISTIC_MATH
- Remove TheSuperHackers @fix prefix from cmake comment
- Expand ODR abbreviation in gamemath.cmake comment
- Add blank lines after setFPMode() in benchmark
- Fix iters abbreviation in printf
- Simplify benchmark: remove replay dependency, auto-trigger at frame 400
- Rename WWMath wrappers to Function_Name convention (578 replacements, 79 files)
@xezon xezon force-pushed the xezon/wip-deterministic-math-v3 branch from 74d8ae3 to ec55507 Compare May 27, 2026 17:46
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.

3 participants