bv: Bit-vector arithmetic library

[ bit-vectors, bsd3, data, library ] [ Propose Tags ] [ Report a vulnerability ]

Bit-vectors implemented as a thin wrapper over integers.


[Skip to Readme]

Modules

[Index]

Flags

Manual Flags

NameDescriptionDefault
test

Build the test suite, and an executable to run it.

Disabled
check-bounds

Bounds checking.

Enabled
dev

Development options.

Disabled
Automatic Flags
NameDescriptionDefault
gmp

Using Integer GMP backend.

Enabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.1.0, 0.2.0, 0.2.1, 0.2.2, 0.3.0, 0.4.0, 0.4.1, 0.5
Change log CHANGES.md
Dependencies base (>=4.6 && <5), ghc-prim, integer-gmp (>=0.5.1) [details]
License BSD-3-Clause
Copyright 2012-2016 Iago Abal
Author Iago Abal <mail@iagoabal.eu>
Maintainer Iago Abal <mail@iagoabal.eu>
Category Data, Bit Vectors
Home page https://github.com/iagoabal/haskell-bv
Bug tracker https://github.com/iagoabal/haskell-bv/issues
Source repo head: git clone https://github.com/iagoabal/haskell-bv.git
Uploaded by IagoAbal at 2018-03-11T07:24:16Z
Distributions LTSHaskell:0.5, NixOS:0.5, Stackage:0.5
Reverse Dependencies 7 direct, 0 indirect [details]
Executables bv-tester
Downloads 7921 total (41 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for bv-0.5

[back to package description]

A library for bit-vector arithmetic in Haskell

Bit-vectors are represented as a pair of a size and a value, where sizes are of type Int and values are Integer. Operations on bit-vectors are translated into operations on integers. Remarkably, most operations taking two or more bit-vectors, will perform zero-padding to adjust the size of the input bit-vectors when needed (eg. when adding bit-vectors of different sizes). Indexing operators don't do this, to avoid masking out of bounds errors.

Other libraries

There exist many Haskell libraries to handle bit-vectors, but to the best of my knowledge bv is the only one that adequately supports bit-vector arithmetic.

If you do not need bit-vector arithmetic, then you may consider using any of these other libraries, which could offer more compact and efficient implementations of bit arrays.

Importing and name clashes

Many exported functions name-clash with Prelude functions, it is therefore recommended to do a qualified import:

import           Data.BitVector ( BV )
import qualified Data.BitVector as BV

Running the test suite

If you wish to run the test suite simply:

cabal configure -ftest
cabal build

Then run:

dist/build/bv-tester/bv-tester

Performance

Tip: For best performance compile with -fgmp.

Tip: If you are brave enough, compile with -f -check-bounds (disables index bounds checking).

The BV datatype is simply a pair of an Int, to represent the size, and an arbitrary-precision Integer, to represent the value of a bit-vector. Both fields are strict, and we instruct GHC to unbox strict fields. Further, we ask GHC to inline virtually all bit-vector operations. When inlined, GHC should be able to remove any overhead associated with the BV data type, and unbox bit-vector sizes. Performance should depend mostly on the Integer data type implementation.