-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cherry-pick 274910@main (5f1ac64). https://bugs.webkit.org/show_bug.c…
…gi?id=269509 Preserve sign of NaN operands in fsub{32,64} https://bugs.webkit.org/show_bug.cgi?id=269509 rdar://120780768 Reviewed by Justin Michaud and Yusuke Suzuki. Negating a NaN operand for fsub is incorrect, as IEEE defines the result of an arithmetic operation with a NaN parameter as the NaN itself (without modification). This is observable when a copysign operation is done on the result, as copysign itself is exempt from that restriction and can thus detect the improper negation. By checking whether the operand is a NaN before negating we avoid this issue. * JSTests/wasm/stress/fsub-nan-copysign.js: Added. * Source/JavaScriptCore/wasm/WasmBBQJIT.cpp: (JSC::Wasm::BBQJITImpl::BBQJIT::addF32Sub): (JSC::Wasm::BBQJITImpl::BBQJIT::addF64Sub): Canonical link: https://commits.webkit.org/274910@main Canonical link: https://commits.webkit.org/274313.37@webkitglib/2.44
- Loading branch information
Showing
2 changed files
with
47 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import * as wabt from "../wabt-wrapper.js"; | ||
import * as assert from '../assert.js'; | ||
|
||
let wat = ` | ||
(module | ||
(type (func (param f64) (result i32))) | ||
(func (type 0) (local f64) (local f64) (local f64) (local i32) | ||
(local.set 1 (local.get 0)) | ||
(local.set 2 (local.get 0)) | ||
(local.set 3 (local.get 0)) | ||
;; Do the sub-operation with local/const, const/local, and const/const params | ||
(local.set 0 (f64.sub (local.get 1) (f64.const nan))) | ||
(local.set 1 (f64.copysign (local.get 1) (local.get 0))) | ||
(local.set 0 (f64.sub (f64.const nan) (local.get 2))) | ||
(local.set 2 (f64.copysign (local.get 2) (local.get 0))) | ||
(local.set 0 (f64.sub (f64.const 0.0) (f64.const nan))) | ||
(local.set 3 (f64.copysign (local.get 3) (local.get 0))) | ||
;; If any one of the results is negative, then fail: return a positive integer | ||
;; Otherwise return 0 for success | ||
(local.set 4 (f64.lt (local.get 1) (f64.const 0))) | ||
(local.set 4 (i32.add (local.get 4) (f64.lt (local.get 1) (f64.const 0)))) | ||
(local.set 4 (i32.add (local.get 4) (f64.lt (local.get 2) (f64.const 0)))) | ||
(local.set 4 (i32.add (local.get 4) (f64.lt (local.get 3) (f64.const 0)))) | ||
(local.get 4) | ||
) | ||
(export "poc" (func 0)) | ||
) | ||
` | ||
|
||
async function test() { | ||
const instance = await wabt.instantiate(wat, {}, {}); | ||
|
||
for (let i = 0; i < 50; i++) { | ||
assert.eq(instance.exports.poc(1), 0); | ||
} | ||
} | ||
|
||
assert.asyncTest(test()); |
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