Skip to content

Commit

Permalink
[MERGE #2486 @ThomsonTan] Discard extra bits for left shift on arm
Browse files Browse the repository at this point in the history
Merge pull request #2486 from ThomsonTan:FixShiftPeepsOnArm

We use `<<` in Lowerer::PeepShl to convert SHR+SHL to AND. `<<` on ARM is implemented via LSL which generates all 0 when shift count is larger than 32. This is inconsistent to implement `<<` in JavaScript which only shift the lower 5-bit.

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators#Left_shift.
  • Loading branch information
ThomsonTan committed Feb 9, 2017
2 parents fd6961c + 33f19f6 commit b5c277f
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ install_manifest.txt
# VIM
.*.swo
.*.swp
tags

# VS Code
.vscode/
Expand Down
6 changes: 6 additions & 0 deletions lib/Backend/PreLowerPeeps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ IR::Instr *Lowerer::PeepShl(IR::Instr *instrShl)
instrDef->Remove();

IntConstType oldValue = src2->AsIntConstOpnd()->GetValue();

// Left shift operator (<<) on arm32 is implemented by LSL which doesn't discard bits beyond lowerest 5-bit.
// Need to discard such bits to conform to << in JavaScript. This is not a problem for x86 and x64 because
// behavior of SHL is consistent with JavaScript but keep the below line for clarity.
oldValue %= sizeof(int32) * 8;

oldValue = ~((1 << oldValue) - 1);
src2->AsIntConstOpnd()->SetValue(oldValue);

Expand Down
2 changes: 2 additions & 0 deletions test/Bugs/bug10026875.baseline
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
28442624
28442624
10 changes: 10 additions & 0 deletions test/Bugs/bug10026875.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

function test0() {
WScript.Echo(28510759.1 >> 49 << 49)
}
test0();
test0();
7 changes: 7 additions & 0 deletions test/Bugs/rlexe.xml
Original file line number Diff line number Diff line change
Expand Up @@ -367,4 +367,11 @@
<compile-flags>-maxinterpretcount:1 -off:simplejit</compile-flags>
</default>
</test>
<test>
<default>
<files>bug10026875.js</files>
<baseline>bug10026875.baseline</baseline>
<compile-flags>-maxinterpretcount:1 -off:simplejit</compile-flags>
</default>
</test>
</regress-exe>

0 comments on commit b5c277f

Please sign in to comment.