mirror of
https://github.com/status-im/nim-stew.git
synced 2025-01-23 10:29:44 +00:00
Reorder the definitions to avoid a refernce to setBit before it's being defined
This commit is contained in:
parent
9c3596d9de
commit
b55c5a6d74
@ -443,20 +443,6 @@ template getBitBE*(x: BitIndexable, bit: Natural): bool =
|
||||
## `getBitLE` is considering the default indexing scheme.
|
||||
(x and mostSignificantBit(x.type) shr bit) != 0
|
||||
|
||||
func changeBit*(x: var BitIndexable, bit: Natural, val: bool) {.inline.} =
|
||||
## changes a bit in `x` to val, assuming 0 to be the position of the
|
||||
## least significant bit
|
||||
type T = type(x)
|
||||
x = (x and not (T(1) shl bit)) or (T(val) shl bit)
|
||||
|
||||
template changeBitLE*(x: var BitIndexable, bit: Natural, val: bool) =
|
||||
setBit(x, bit, val)
|
||||
|
||||
func changeBitBE*(x: var BitIndexable, bit: Natural, val: bool) {.inline.} =
|
||||
## changes a bit in `x` to val, assuming 0 to be the position of the
|
||||
## most significant bit
|
||||
changeBit(x, bitsof(x) - 1 - bit, val)
|
||||
|
||||
func setBit*(x: var BitIndexable, bit: Natural) {.inline.} =
|
||||
## sets bit in `x`, assuming 0 to be the position of the
|
||||
## least significant bit
|
||||
@ -473,6 +459,20 @@ func setBitBE*(x: var BitIndexable, bit: Natural) {.inline.} =
|
||||
let mask = mostSignificantBit(x.type) shr bit
|
||||
x = x or mask
|
||||
|
||||
func changeBit*(x: var BitIndexable, bit: Natural, val: bool) {.inline.} =
|
||||
## changes a bit in `x` to val, assuming 0 to be the position of the
|
||||
## least significant bit
|
||||
type T = type(x)
|
||||
x = (x and not (T(1) shl bit)) or (T(val) shl bit)
|
||||
|
||||
template changeBitLE*(x: var BitIndexable, bit: Natural, val: bool) =
|
||||
setBit(x, bit, val)
|
||||
|
||||
func changeBitBE*(x: var BitIndexable, bit: Natural, val: bool) {.inline.} =
|
||||
## changes a bit in `x` to val, assuming 0 to be the position of the
|
||||
## most significant bit
|
||||
changeBit(x, bitsof(x) - 1 - bit, val)
|
||||
|
||||
func clearBit*(x: var BitIndexable, bit: Natural) {.inline.} =
|
||||
## clears bit in a byte, assuming 0 to be the position of the
|
||||
## least significant bit
|
||||
|
Loading…
x
Reference in New Issue
Block a user