Skip to content

Commit 42352e1

Browse files
Blaisorbladeodersky
authored andcommitted
Use an *unsigned* right shift
Found by comparing testcases with the C version, and by then comparing the source code; both C versions use an unsigned right shift (or rather a right shift on unsigned integers). * Background: Right-shifting a signed number copies the sign bit into all the new "empty bits"; C uses the integer sign, while Java (and Scala) use a separate "unsigned right shift" operator.
1 parent cbf56ce commit 42352e1

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TastyHash.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object TastyHash {
1313
val d = data(i) & 0xFFL // Interpret byte as unsigned byte
1414
h = (h << 8) + d
1515
val high = h & 0xFF00000000000000L
16-
h ^= high >> 48L
16+
h ^= high >>> 48L
1717
h &= ~high
1818
i += 1
1919
}

tests/run-with-compiler/tasty-hash.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Test {
1313
testHash(0X101010101L, Array(1, 1, 1, 1, 1))
1414
testHash(0X202020202L, Array(2, 2, 2, 2, 2))
1515
testHash(0X1010101L, Array.fill(1024)(1))
16-
testHash(0X55aa01fe55ab54ffL, Array.tabulate(1024)(_.toByte))
16+
testHash(0xaafefeaaab54ffL, Array.tabulate(1024)(_.toByte))
1717
testHash(0x34545c16020230L, "abcdefghijklmnopqrstuvwxyz1234567890".getBytes)
1818
}
1919

0 commit comments

Comments
 (0)