diff options
author | Josef Ahmad <josef.ahmad@mongodb.com> | 2022-09-15 06:14:58 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-19 22:58:45 +0000 |
commit | 6ed754b0f4b4eb29c74d5b942e1b7ee005e91ed6 (patch) | |
tree | be915e11c3db0a6042bc4749924e8980a27e6eef | |
parent | cfe4fe45d31644ff6bfda613169245c7f9a7e2e9 (diff) | |
download | mongo-6ed754b0f4b4eb29c74d5b942e1b7ee005e91ed6.tar.gz |
SERVER-69611 Set the -ffp-contract=off compiler option by default
(cherry picked from commit d8901a2835d3f464d394631d85dc7aa9493fc095)
-rwxr-xr-x | SConstruct | 9 | ||||
-rw-r--r-- | jstests/noPassthrough/floating_point_exp_contraction_off.js | 47 |
2 files changed, 56 insertions, 0 deletions
diff --git a/SConstruct b/SConstruct index 6478ce68460..f1479a8890b 100755 --- a/SConstruct +++ b/SConstruct @@ -1837,6 +1837,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); +}()); |