Skip to content

Commit 8a5c8b3

Browse files
Fidetrostephentyrone
authored andcommitted
Use the &>> operator in HashTest.
Gets rid of some obvious inefficiencies in this benchmark.
1 parent d3e5af6 commit 8a5c8b3

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

benchmark/single-source/Hash.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,19 +113,13 @@ class Hash {
113113
/// \brief Left-rotate \p x by \p c.
114114
final
115115
func rol(_ x: UInt32, _ c: UInt32) -> UInt32 {
116-
// TODO: use the &>> operator.
117-
let a = UInt32(truncatingIfNeeded: Int64(x) << Int64(c))
118-
let b = UInt32(truncatingIfNeeded: Int64(x) >> (32 - Int64(c)))
119-
return a|b
116+
return x &<< c | x &>> (32 &- c)
120117
}
121118

122119
/// \brief Right-rotate \p x by \p c.
123120
final
124121
func ror(_ x: UInt32, _ c: UInt32) -> UInt32 {
125-
// TODO: use the &>> operator.
126-
let a = UInt32(truncatingIfNeeded: Int64(x) >> Int64(c))
127-
let b = UInt32(truncatingIfNeeded: Int64(x) << (32 - Int64(c)))
128-
return a|b
122+
return x &>> c | x &<< (32 &- c)
129123
}
130124
}
131125

0 commit comments

Comments
 (0)