Skip to content

Commit

Permalink
Disable runtime floating point exceptions
Browse files Browse the repository at this point in the history
Clang 15+ / GCC 13+ leave us no choice but to disable floating point exceptions.
Their auto-vectorization optimizations load invalid values and will cause FPEs even when fp-strict is enabled.
  • Loading branch information
sturnclaw authored and Webster Sheets committed Aug 26, 2023
1 parent b193b8e commit 422dbfe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
6 changes: 6 additions & 0 deletions src/Pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -871,6 +871,12 @@ static void OnPlayerDockOrUndock();
void GameLoop::Start()
{
PROFILE_SCOPED()

// NOTE: this is here because Clang 15+ and GCC 13+ ignore fp-model when
// generating vectorized/optimized code and will happily perform exception-
// raising operations on the contents of uninitialized or aliased memory
OS::DisableFPE();

// this is a bit brittle. skank may be forgotten and survive between
// games
Pi::input->InitGame();
Expand Down
2 changes: 0 additions & 2 deletions src/ship/PlayerShipController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,7 @@ void PlayerShipController::StaticUpdate(const float timeStep)
{
// call autopilot AI, if active
if (m_ship->AIIsActive()) {
OS::EnableFPE();
m_ship->AITimeStep(timeStep);
OS::DisableFPE();
// the speed limiter should not work when the autopilot is working
if (IsSpeedLimiterActive()) SetSpeedLimiterActive(false);
return;
Expand Down
2 changes: 0 additions & 2 deletions src/ship/ShipController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@

void ShipController::StaticUpdate(float timeStep)
{
OS::EnableFPE();
m_ship->AITimeStep(timeStep);
OS::DisableFPE();
}

0 comments on commit 422dbfe

Please sign in to comment.