Nimony

The road to Nim 3

bitops

nimony/lib/std/bitops.nim

This module implements a series of low-level bit manipulation procedures over the fixed-width unsigned integers uint8, uint16, uint32 and uint64 -- or any type that satifies the BitInteger concept.

The procedures are generic and constrained by the BitInteger concept below, which lists exactly the bitwise and shift operators the algorithms rely on. The bodies are written against those operations only (plus a runtime sizeof to recover the bit width), so they lower cleanly to C, LLVM and JS alike, and any type providing the operator set is accepted.

Bit indices are 0-based and, for the rotate procedures, the shift amount is taken modulo the bit width so any amount is well defined.