-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Make makeSetValue rounding consistent with HEAP64 semantics #19239
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -211,7 +211,7 @@ function splitI64(value) { | |||||
| // | ||||||
| // $1$0 = ~~$d >>> 0; | ||||||
| // $1$1 = Math.abs($d) >= 1 ? ( | ||||||
| // $d > 0 ? Math.min(Math.floor(($d)/ 4294967296.0), 4294967295.0) | ||||||
| // $d > 0 ? Math.floor(($d)/ 4294967296.0) >>> 0, | ||||||
| // : Math.ceil(Math.min(-4294967296.0, $d - $1$0)/ 4294967296.0) | ||||||
| // ) : 0; | ||||||
| // | ||||||
|
|
@@ -227,9 +227,8 @@ function splitI64(value) { | |||||
| const high = makeInlineCalculation( | ||||||
| asmCoercion('Math.abs(VALUE)', 'double') + ' >= ' + asmEnsureFloat('1', 'double') + ' ? ' + | ||||||
| '(VALUE > ' + asmEnsureFloat('0', 'double') + ' ? ' + | ||||||
| asmCoercion('Math.min(' + asmCoercion('Math.floor((VALUE)/' + | ||||||
| asmEnsureFloat(4294967296, 'double') + ')', 'double') + ', ' + | ||||||
| asmEnsureFloat(4294967295, 'double') + ')', 'i32') + '>>>0' + | ||||||
| asmCoercion('Math.floor((VALUE)/' + | ||||||
| asmEnsureFloat(4294967296, 'double') + ')', 'double') + '>>>0' + | ||||||
|
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. Why is it correct to remove the I think the old code was correct. We can do rounding for the lower bits because we've ensured they are in the right range. But we need to use saturation because the value might be outside of range - imagine that the value is 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. The old code did saturation of the upper half produced this odd result: The new code truncates and produces the same result as BigInt64Array: 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. "imagine that the value is 2^70 plus some small value" .. I'm not sure I understand doesn't the 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. It removes the low bits, by my concern is that without saturation the loss But maybe I'm wrong and that is not the error to care about? What do you mean by 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. We run this test both with and without WASM_BIGINT: The change in the expected output was initially generated because I changed WASM_BIGINT to always use 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. Do you know what code path that is on? I'm surprised 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. For example: 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. True. Maybe I'm confused as to where we use If it is used to prepare for storing, then as I asked before, why is it even used in WASM_BIGINT mode? In that mode we can store directly. Or is my confusion that it isn't used in that mode, and you fixed it for non-WASM_BIGINT mode? 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.
Perhaps
After this change is not longer used in Prior to this change we used
Right the changes to 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. I see. Thanks, that all makes sense then! |
||||||
| ' : ' + | ||||||
| asmFloatToInt(asmCoercion('Math.ceil((VALUE - +((' + asmFloatToInt('VALUE') + ')>>>0))/' + | ||||||
| asmEnsureFloat(4294967296, 'double') + ')', 'double')) + '>>>0' + | ||||||
|
|
@@ -364,12 +363,10 @@ function makeSetValue(ptr, pos, value, type, noNeedFirst, ignore, align, sep) { | |||||
| assert(typeof align === 'undefined', 'makeSetValue no longer supports align parameter'); | ||||||
| assert(typeof noNeedFirst === 'undefined', 'makeSetValue no longer supports noNeedFirst parameter'); | ||||||
| assert(typeof sep === 'undefined', 'makeSetValue no longer supports sep parameter'); | ||||||
| if (type == 'i64' && (!WASM_BIGINT || !MEMORY64)) { | ||||||
| // If we lack either BigInt support or Memory64 then we must fall back to an | ||||||
| // unaligned read of a 64-bit value: without BigInt we do not have HEAP64, | ||||||
| // and without Memory64 i64 fields are not guaranteed to be aligned to 64 | ||||||
| // bits, so HEAP64[ptr>>3] might be broken. | ||||||
| return '(tempI64 = [' + splitI64(value) + '],' + | ||||||
| if (type == 'i64' && !WASM_BIGINT) { | ||||||
| // If we lack either BigInt we must fall back to an reading a pair of I32 | ||||||
|
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.
Suggested change
|
||||||
| // values. | ||||||
| return '(tempI64 = [' + splitI64(value) + '], ' + | ||||||
| makeSetValue(ptr, pos, 'tempI64[0]', 'i32') + ',' + | ||||||
| makeSetValue(ptr, getFastValue(pos, '+', getNativeTypeSize('i32')), 'tempI64[1]', 'i32') + ')'; | ||||||
| } | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 25939 | ||
| 25914 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 25903 | ||
| 25878 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 30453 | ||
| 30428 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 25748 | ||
| 25723 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 30457 | ||
| 30432 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 25939 | ||
| 25914 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 59613 | ||
| 59584 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 33284 | ||
| 33255 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| 58555 | ||
| 58526 |
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.