Skip to content

Commit e431e1a

Browse files
authored
Merge pull request swiftlang#10459 from eeckstein/fix-byteswap
2 parents c7e01f2 + e736089 commit e431e1a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

benchmark/single-source/ByteSwap.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import Foundation
1717
import TestsUtils
1818

1919
// a naive O(n) implementation of byteswap.
20+
@inline(never)
2021
func byteswap_n(_ a: UInt64) -> UInt64 {
2122
#if swift(>=4)
2223
return ((a & 0x00000000000000FF) &<< 56) |
@@ -40,6 +41,7 @@ func byteswap_n(_ a: UInt64) -> UInt64 {
4041
}
4142

4243
// a O(logn) implementation of byteswap.
44+
@inline(never)
4345
func byteswap_logn(_ a: UInt64) -> UInt64 {
4446
var a = a
4547
a = (a & 0x00000000FFFFFFFF) << 32 | (a & 0xFFFFFFFF00000000) >> 32
@@ -50,10 +52,13 @@ func byteswap_logn(_ a: UInt64) -> UInt64 {
5052

5153
@inline(never)
5254
public func run_ByteSwap(_ N: Int) {
53-
for _ in 1...100*N {
55+
var s: UInt64 = 0
56+
for _ in 1...10000*N {
5457
// Check some results.
55-
CheckResults(byteswap_logn(byteswap_n(2457)) == 2457)
56-
CheckResults(byteswap_logn(byteswap_n(9129)) == 9129)
57-
CheckResults(byteswap_logn(byteswap_n(3333)) == 3333)
58+
let x : UInt64 = UInt64(getInt(0))
59+
s = s &+ byteswap_logn(byteswap_n(x &+ 2457))
60+
&+ byteswap_logn(byteswap_n(x &+ 9129))
61+
&+ byteswap_logn(byteswap_n(x &+ 3333))
5862
}
63+
CheckResults(s == (2457 &+ 9129 &+ 3333) &* 10000 &* N)
5964
}

0 commit comments

Comments
 (0)