File tree Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Expand file tree Collapse file tree 1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import Foundation
17
17
import TestsUtils
18
18
19
19
// a naive O(n) implementation of byteswap.
20
+ @inline ( never)
20
21
func byteswap_n( _ a: UInt64 ) -> UInt64 {
21
22
#if swift(>=4)
22
23
return ( ( a & 0x00000000000000FF ) &<< 56 ) |
@@ -40,6 +41,7 @@ func byteswap_n(_ a: UInt64) -> UInt64 {
40
41
}
41
42
42
43
// a O(logn) implementation of byteswap.
44
+ @inline ( never)
43
45
func byteswap_logn( _ a: UInt64 ) -> UInt64 {
44
46
var a = a
45
47
a = ( a & 0x00000000FFFFFFFF ) << 32 | ( a & 0xFFFFFFFF00000000 ) >> 32
@@ -50,10 +52,13 @@ func byteswap_logn(_ a: UInt64) -> UInt64 {
50
52
51
53
@inline ( never)
52
54
public func run_ByteSwap( _ N: Int ) {
53
- for _ in 1 ... 100 * N {
55
+ var s : UInt64 = 0
56
+ for _ in 1 ... 10000 * N {
54
57
// 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 ) )
58
62
}
63
+ CheckResults ( s == ( 2457 &+ 9129 &+ 3333 ) &* 10000 &* N)
59
64
}
You can’t perform that action at this time.
0 commit comments