From f4e6602d3a4c5b22e9d8bcf0722d0afd0ec01ea2 Mon Sep 17 00:00:00 2001 From: Josef Ahmad Date: Thu, 15 Sep 2022 06:14:58 +0000 Subject: SERVER-69611 Set the -ffp-contract=off compiler option by default (cherry picked from commit d8901a2835d3f464d394631d85dc7aa9493fc095) --- SConstruct | 9 +++++ .../floating_point_exp_contraction_off.js | 47 ++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 jstests/noPassthrough/floating_point_exp_contraction_off.js diff --git a/SConstruct b/SConstruct index ceda985c349..eddc24db0f5 100644 --- a/SConstruct +++ b/SConstruct @@ -1636,6 +1636,15 @@ if debugBuild: else: env.AppendUnique( CPPDEFINES=[ 'NDEBUG' ] ) +# Disable floating-point contractions such as forming of fused multiply-add operations. +if env.ToolchainIs('clang', 'gcc'): + env.Append(CCFLAGS=["-ffp-contract=off"]) +else: + # msvc defaults to /fp:precise. Visual Studio 2022 does not emit floating-point contractions + # with /fp:precise, but previous versions can. Disable contractions altogether by using + # /fp:strict. + env.Append(CCFLAGS=["/fp:strict"]) + if env.TargetOSIs('linux'): env.Append( LIBS=["m"] ) if not env.TargetOSIs('android'): diff --git a/jstests/noPassthrough/floating_point_exp_contraction_off.js b/jstests/noPassthrough/floating_point_exp_contraction_off.js new file mode 100644 index 00000000000..601dcd20f0d --- /dev/null +++ b/jstests/noPassthrough/floating_point_exp_contraction_off.js @@ -0,0 +1,47 @@ +/** + * Validates that the server doesn't use fused multiply-add instructions (-ffp-contract=off). + * + * @tags: [ + * multiversion_incompatible, + * ] + */ + +(function() { +'use strict'; + +const conn = MongoRunner.runMongod(); + +const coll = conn.getDB('test').getCollection('c'); + +assert.commandWorked(coll.createIndex({loc: "2dsphere"})); +assert.commandWorked(coll.insertOne({ + "loc": { + "type": "Polygon", + "coordinates": [[ + [-85.0329458713531, 41.3677690255613], + [-85.0296092033386, 41.3677690255613], + [-85.0296092033386, 41.360594065847], + [-85.0329458713531, 41.360594065847], + [-85.0329458713531, 41.3677690255613] + ]] + } +})); + +// Assert that the query returns the document. If the query does not return any result, then +// this is likely because of different rounding due to fused multiply-add instructions on platforms +// that have native support, like arm64. +assert.eq( + 1, + coll.find({ + "loc": { + "$near": { + "$geometry": + {"type": "Point", "coordinates": [-85.031218528747559, 41.364586470348961]}, + "$maxDistance": 0 + } + } + }) + .itcount()); + +MongoRunner.stopMongod(conn); +}()); -- cgit v1.2.1