Skip to content

Commit b5c277f

Browse files
committed
[MERGE chakra-core#2486 @ThomsonTan] Discard extra bits for left shift on arm
Merge pull request chakra-core#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.
2 parents fd6961c + 33f19f6 commit b5c277f

5 files changed

Lines changed: 26 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ install_manifest.txt
7777
# VIM
7878
.*.swo
7979
.*.swp
80+
tags
8081

8182
# VS Code
8283
.vscode/

lib/Backend/PreLowerPeeps.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ IR::Instr *Lowerer::PeepShl(IR::Instr *instrShl)
9898
instrDef->Remove();
9999

100100
IntConstType oldValue = src2->AsIntConstOpnd()->GetValue();
101+
102+
// Left shift operator (<<) on arm32 is implemented by LSL which doesn't discard bits beyond lowerest 5-bit.
103+
// Need to discard such bits to conform to << in JavaScript. This is not a problem for x86 and x64 because
104+
// behavior of SHL is consistent with JavaScript but keep the below line for clarity.
105+
oldValue %= sizeof(int32) * 8;
106+
101107
oldValue = ~((1 << oldValue) - 1);
102108
src2->AsIntConstOpnd()->SetValue(oldValue);
103109

test/Bugs/bug10026875.baseline

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
28442624
2+
28442624

test/Bugs/bug10026875.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//-------------------------------------------------------------------------------------------------------
2+
// Copyright (C) Microsoft. All rights reserved.
3+
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
4+
//-------------------------------------------------------------------------------------------------------
5+
6+
function test0() {
7+
WScript.Echo(28510759.1 >> 49 << 49)
8+
}
9+
test0();
10+
test0();

test/Bugs/rlexe.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,4 +367,11 @@
367367
<compile-flags>-maxinterpretcount:1 -off:simplejit</compile-flags>
368368
</default>
369369
</test>
370+
<test>
371+
<default>
372+
<files>bug10026875.js</files>
373+
<baseline>bug10026875.baseline</baseline>
374+
<compile-flags>-maxinterpretcount:1 -off:simplejit</compile-flags>
375+
</default>
376+
</test>
370377
</regress-exe>

0 commit comments

Comments
 (0)