forked from facebook/hermes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Summary: Newer versions of clang will automatically produce FMA instead of separate multiply and add when the multiplication and addition are in the same expression. This is undesirable because it results in non-standard behaviour in makeDate, and breaks an existing test262 test. We can do this in two ways: 1. We can split them into separate expressions 2. We can use `#pragma STDC FP_CONTRACT OFF` Unfortunately, neither of these address the issue with GCC, which uses `-ffp-contract=fast` by default, and cannot be overridden except by using `volatile`. To fix this, add `-ffp-contract=on` to our build flags, and split the expressions. Reviewed By: tmikov Differential Revision: D51725454 fbshipit-source-id: 3d4c91bb32c619c05c53fd8b1962adbc862554aa
- Loading branch information
1 parent
60c8567
commit 957502e
Showing
5 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
// RUN: %hermes %s | %FileCheck --match-full-lines %s | ||
|
||
// Check that the date implementation does not use fma which can produce | ||
// non-compliant output. | ||
print(Date.UTC(1970, 0, 213503982336, 0, 0, 0, -18446744073709552000)) | ||
// CHECK: 34447360 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "gtest/gtest.h" | ||
|
||
namespace { | ||
|
||
/// Test that Hermes is compiled such that floating point multiplication and | ||
/// addition in separate expressions cannot be combined into a single FMA | ||
/// operation with higher intermediate precision. For instance, GCC uses | ||
/// -ffp-contract=fast by default, which allows separate expressions to be | ||
/// contracted. This is important because it is sometimes required by the JS | ||
/// spec, for instance when computing dates. | ||
TEST(FPContractTest, SeparateExpressionsFMA) { | ||
double d0 = 213503982335.0 * 86400000.0; | ||
double d1 = d0 - 18446744073709552000.0; | ||
EXPECT_EQ(d1, 34447360.0); | ||
} | ||
|
||
} // namespace |