From b55c5a6d7496159a261186807d9bbe3f6f5dac38 Mon Sep 17 00:00:00 2001 From: Zahary Karadjov Date: Thu, 14 Jul 2022 15:11:34 +0300 Subject: [PATCH] Reorder the definitions to avoid a refernce to setBit before it's being defined --- stew/bitops2.nim | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/stew/bitops2.nim b/stew/bitops2.nim index d1e1133..e252362 100644 --- a/stew/bitops2.nim +++ b/stew/bitops2.nim @@ -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