summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosef Ahmad <josef.ahmad@mongodb.com>2022-09-15 06:14:58 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-09-19 23:15:07 +0000
commitf4e6602d3a4c5b22e9d8bcf0722d0afd0ec01ea2 (patch)
tree80fde91f5794658eace068d7390b9d4ed55f8c9e
parent8e000f28edfff5f140351b330ba007345fff736d (diff)
downloadmongo-f4e6602d3a4c5b22e9d8bcf0722d0afd0ec01ea2.tar.gz
SERVER-69611 Set the -ffp-contract=off compiler option by defaultr4.2.23-rc1r4.2.23
(cherry picked from commit d8901a2835d3f464d394631d85dc7aa9493fc095)
-rw-r--r--SConstruct9
-rw-r--r--jstests/noPassthrough/floating_point_exp_contraction_off.js47
2 files changed, 56 insertions, 0 deletions
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);
+}());