Skip to content

Commit

Permalink
[benchmark] Unbreaking the complex expression in ByteSwap
Browse files Browse the repository at this point in the history
Fixes: <rdar://problem/31543153>
  • Loading branch information
Max Moiseev committed May 17, 2017
1 parent 78768d8 commit d818008
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions benchmark/single-source/ByteSwap.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,25 @@ import TestsUtils

// a naive O(n) implementation of byteswap.
func byteswap_n(_ a: UInt64) -> UInt64 {
var result = ((a & 0x00000000000000FF) << 56)
result |= ((a & 0x000000000000FF00) << 40)
result |= ((a & 0x0000000000FF0000) << 24)
result |= ((a & 0x00000000FF000000) << 8)
result |= ((a & 0x000000FF00000000) >> 8)
result |= ((a & 0x0000FF0000000000) >> 24)
result |= ((a & 0x00FF000000000000) >> 40)
result |= ((a & 0xFF00000000000000) >> 56)
return result
#if swift(>=4)
return ((a & 0x00000000000000FF) &<< 56) |
((a & 0x000000000000FF00) &<< 40) |
((a & 0x0000000000FF0000) &<< 24) |
((a & 0x00000000FF000000) &<< 8) |
((a & 0x000000FF00000000) &>> 8) |
((a & 0x0000FF0000000000) &>> 24) |
((a & 0x00FF000000000000) &>> 40) |
((a & 0xFF00000000000000) &>> 56)
#else
return ((a & 0x00000000000000FF) << 56) |
((a & 0x000000000000FF00) << 40) |
((a & 0x0000000000FF0000) << 24) |
((a & 0x00000000FF000000) << 8) |
((a & 0x000000FF00000000) >> 8) |
((a & 0x0000FF0000000000) >> 24) |
((a & 0x00FF000000000000) >> 40) |
((a & 0xFF00000000000000) >> 56)
#endif
}

// a O(logn) implementation of byteswap.
Expand Down

0 comments on commit d818008

Please sign in to comment.