forked from WebKit/WebKit-http
-
Notifications
You must be signed in to change notification settings - Fork 157
Fix aliasing with scratch register on 32-bit bbq i64 div #1707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
justinmichaud
wants to merge
1
commit into
WebPlatformForEmbedded:wpe-2.46
Choose a base branch
from
justinmichaud:eng/246-bbq-div
base: wpe-2.46
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,52 @@ | ||
| import { instantiate } from "../wabt-wrapper.js" | ||
| import * as assert from "../assert.js" | ||
|
|
||
| // The i32 operand of the outer add is evaluated first, so it holds a register while the | ||
| // dividend is loaded. That pushes the dividend into a register pair overlapping the pair | ||
| // the C call passes it in, which is what makes the argument shuffle need a temporary. | ||
| let wat = ` | ||
| (module | ||
| (func (export "divS") (param $x i64) (param $k i32) (result i32) | ||
| (i32.add (local.get $k) (i32.wrap_i64 (i64.div_s (local.get $x) (i64.const 1000))))) | ||
| (func (export "divU") (param $x i64) (param $k i32) (result i32) | ||
| (i32.add (local.get $k) (i32.wrap_i64 (i64.div_u (local.get $x) (i64.const 1000))))) | ||
| (func (export "remS") (param $x i64) (param $k i32) (result i32) | ||
| (i32.add (local.get $k) (i32.wrap_i64 (i64.rem_s (local.get $x) (i64.const 1000))))) | ||
| (func (export "remU") (param $x i64) (param $k i32) (result i32) | ||
| (i32.add (local.get $k) (i32.wrap_i64 (i64.rem_u (local.get $x) (i64.const 1000))))) | ||
| (func (export "divSLeft") (param $x i64) (param $k i32) (result i32) | ||
| (i32.add (local.get $k) (i32.wrap_i64 (i64.div_s (i64.const 1000) (local.get $x))))) | ||
| (func (export "remSLeft") (param $x i64) (param $k i32) (result i32) | ||
| (i32.add (local.get $k) (i32.wrap_i64 (i64.rem_s (i64.const 1000) (local.get $x))))) | ||
| (func (export "divS32") (param $x i32) (param $k i32) (result i32) | ||
| (i32.add (local.get $k) (i32.div_s (local.get $x) (i32.const 1000)))) | ||
| ) | ||
| ` | ||
|
|
||
| async function test() { | ||
| const instance = await instantiate(wat, {}, { simd: true }) | ||
| const { divS, divU, remS, remU, divSLeft, remSLeft, divS32 } = instance.exports | ||
|
|
||
| for (let i = 1; i <= 10000; ++i) { | ||
| let x = i * 7919 | ||
| assert.eq(divS(BigInt(x), 5), 5 + (x / 1000 | 0)) | ||
| assert.eq(divU(BigInt(x), 5), 5 + (x / 1000 | 0)) | ||
| assert.eq(remS(BigInt(x), 5), 5 + x % 1000) | ||
| assert.eq(remU(BigInt(x), 5), 5 + x % 1000) | ||
| assert.eq(divSLeft(BigInt(x), 5), 5 + (1000 / x | 0)) | ||
| assert.eq(remSLeft(BigInt(x), 5), 5 + 1000 % x) | ||
| assert.eq(divS32(x, 5), 5 + (x / 1000 | 0)) | ||
| } | ||
|
|
||
| // A zero dividend with a non-zero constant divisor emits no zero check, so losing the | ||
| // divisor makes the runtime helper divide zero by zero and take SIGFPE. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly, I puzzled over "losing the divisor" here. IIUC this comment assumes the bug that's fixed by this commit. Perhaps "exercise the elided zero-check on the divisor"? |
||
| for (let i = 0; i < 10000; ++i) { | ||
| assert.eq(divS(0n, 5), 5) | ||
| assert.eq(divU(0n, 5), 5) | ||
| assert.eq(remS(0n, 5), 5) | ||
| assert.eq(remU(0n, 5), 5) | ||
| assert.eq(divS32(0, 5), 5) | ||
| } | ||
| } | ||
|
|
||
| await assert.asyncTest(test()) | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not entirely obvious what the issue with the argument shuffle needing a temporary is. Presumably it's because we place the value to be tested in the scratch registers in the
needsZeroCheckcase inemitModOrDiv(so we're assuming that the shuffle won't need the temporary), but this comment read pretty mysterious to me in this file :-)