Skip to content
This repository was archived by the owner on Jan 26, 2022. It is now read-only.

Commit 13bb258

Browse files
committed
Merge pull request #326 from stoklund/mask-shift-counts
Give shift operators masking shift count semantics.
2 parents ddfe45a + d08bcc7 commit 13bb258

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

‎src/ecmascript_simd.js‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,8 +1186,7 @@ var simdFns = {
11861186
shiftLeftByScalar:
11871187
function(type) {
11881188
return function(a, bits) {
1189-
if (bits>>>0 >= type.laneSize * 8)
1190-
return type.fn.splat(0);
1189+
bits &= type.laneSize * 8 - 1;
11911190
return simdShiftOp(type, binaryShiftLeft, a, bits);
11921191
}
11931192
},
@@ -1196,14 +1195,12 @@ var simdFns = {
11961195
function(type) {
11971196
if (type.unsigned) {
11981197
return function(a, bits) {
1199-
if (bits>>>0 >= type.laneSize * 8)
1200-
return type.fn.splat(0);
1198+
bits &= type.laneSize * 8 - 1;
12011199
return simdShiftOp(type, binaryShiftRightLogical, a, bits);
12021200
}
12031201
} else {
12041202
return function(a, bits) {
1205-
if (bits>>>0 >= type.laneSize * 8)
1206-
bits = type.laneSize * 8 - 1;
1203+
bits &= type.laneSize * 8 - 1;
12071204
return simdShiftOp(type, binaryShiftRightArithmetic, a, bits);
12081205
}
12091206
}

‎src/ecmascript_simd_tests.js‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,7 @@ simdTypes.filter(isIntType).forEach(function(type) {
939939
});
940940
test(type.name + ' shiftLeftByScalar', function() {
941941
function shift(a, bits) {
942-
if (bits>>>0 >= type.laneSize * 8) return 0;
942+
bits &= type.laneSize * 8 - 1;
943943
return a << bits;
944944
}
945945
testShiftOp(type, 'shiftLeftByScalar', shift);
@@ -949,8 +949,7 @@ simdTypes.filter(isIntType).forEach(function(type) {
949949
simdTypes.filter(isSignedIntType).forEach(function(type) {
950950
test(type.name + ' shiftRightByScalar', function() {
951951
function shift(a, bits) {
952-
if (bits>>>0 >= type.laneSize * 8)
953-
bits = type.laneSize * 8 - 1;
952+
bits &= type.laneSize * 8 - 1;
954953
return a >> bits;
955954
}
956955
testShiftOp(type, 'shiftRightByScalar', shift);
@@ -960,7 +959,7 @@ simdTypes.filter(isSignedIntType).forEach(function(type) {
960959
simdTypes.filter(isUnsignedIntType).forEach(function(type) {
961960
test(type.name + ' shiftRightByScalar', function() {
962961
function shift(a, bits) {
963-
if (bits>>>0 >= type.laneSize * 8) return 0;
962+
bits &= type.laneSize * 8 - 1;
964963
if (type.laneMask)
965964
a &= type.laneMask;
966965
return a >>> bits;

0 commit comments

Comments
 (0)