|
1 | | -@inline function reversebits(x::T, ::BitsPerSymbol{2}) where T <: Base.BitUnsigned |
| 1 | +const BitUnsigned = Union{UInt8, UInt16, UInt32, UInt64, UInt128} |
| 2 | + |
| 3 | +@inline function reversebits(x::T, ::BitsPerSymbol{2}) where T <: BitUnsigned |
2 | 4 | mask = 0x33333333333333333333333333333333 % T |
3 | 5 | x = ((x >> 2) & mask) | ((x & mask) << 2) |
4 | 6 | return reversebits(x, BitsPerSymbol{4}()) |
5 | 7 | end |
6 | 8 |
|
7 | | -@inline function reversebits(x::T, ::BitsPerSymbol{4}) where T <: Base.BitUnsigned |
| 9 | +@inline function reversebits(x::T, ::BitsPerSymbol{4}) where T <: BitUnsigned |
8 | 10 | mask = 0x0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F0F % T |
9 | 11 | x = ((x >> 4) & mask) | ((x & mask) << 4) |
10 | | - return bswap(x) |
| 12 | + return reversebits(x, BitsPerSymbol{8}()) |
| 13 | +end |
| 14 | + |
| 15 | +@inline reversebits(x::T, ::BitsPerSymbol{8}) where T <: BitUnsigned = bswap(x) |
| 16 | + |
| 17 | +@inline reversebits(x::UInt16, ::BitsPerSymbol{16}) = x |
| 18 | +@inline function reversebits(x::T, ::BitsPerSymbol{16}) where T <: Union{UInt32, UInt64} |
| 19 | + mask = 0x0000FFFF0000FFFF0000FFFF0000FFFF % T |
| 20 | + x = ((x >> 16) & mask) | ((x & mask) << 16) |
| 21 | + reversebits(x, BitsPerSymbol{32}()) |
| 22 | +end |
| 23 | + |
| 24 | +@inline reversebits(x::UInt32, ::BitsPerSymbol{32}) = x |
| 25 | +@inline function reversebits(x::T, ::BitsPerSymbol{32}) where T <: Union{UInt64} |
| 26 | + mask = 0x00000000FFFFFFF00000000FFFFFFFF % T |
| 27 | + x = ((x >> 32) & mask) | ((x & mask) << 32) |
| 28 | + reversebits(x, BitsPerSymbol{64}()) |
11 | 29 | end |
12 | 30 |
|
13 | | -reversebits(x::T, ::BitsPerSymbol{8}) where T <: Base.BitUnsigned = bswap(x) |
| 31 | +@inline reversebits(x::UInt64, ::BitsPerSymbol{64}) = x |
14 | 32 |
|
15 | 33 | @inline function complement_bitpar(x::Unsigned, ::T) where {T<:NucleicAcidAlphabet{2}} |
16 | 34 | return ~x |
|
0 commit comments