bsim is a single header library that provides arbitrary length bit vectors. The library also includes a bit vector wrapper for unsigned integers.
There are many bit vector libraries (like std::bitset) that provide bit vectors to represent sets. Unlike these libraries bsim was designed with hardware simulation in mind. This library supports logical operations as well as signed and unsigned arithmetic.
- Bitwise logical operators: and, or, nand, nor, xor, not
- Bitwise comparisons: equal and not equal
- Unsigned integer arithmetic: add, subtract, and multiply
- Unsigned integer comparisons: greater, less, greater than or equal, less than or equal
- Signed integer arithmetic: add, subtract, and multiply
I am currently working on adding support for signed and unsigned division and left and right shifts.
Native Instruction Use for Small Bit Vectors
bsim supports operating on arbitrary length bit vectors, but for operations on bit vectors with less than 65 bits the library uses conditional compilation to native instructions rather than arbitrary length algorithms.
Use of native operations comes at a slight storage cost. For example a 33 bit vector must be stored as 64 bits in order to use 64 bit operations without changing bits in memory beyond the object.
Just copy the file src/bit_vector.h in to your project.