Basic operations on bitvectors #
Std has defined bitvector of length w
as Fin (2^w)
.
Here we define a few more operations on these bitvectors
Main definitions #
Std.BitVec.sgt
: Signed greater-than comparison of bitvectorsStd.BitVec.sge
: Signed greater-equals comparison of bitvectorsStd.BitVec.ugt
: Unsigned greater-than comparison of bitvectorsStd.BitVec.uge
: Unsigned greater-equals comparison of bitvectors
Constants #
The bitvector representing 1
.
That is, the bitvector with least-significant bit 1
and all other bits 0
Equations
- BitVec.one w = 1
Instances For
Bitwise operations #
Arithmetic operators #
Add with carry (no overflow)
See also Std.BitVec.adc
, which stores the carry bit separately.
Equations
- BitVec.adc' x y c = let a := BitVec.adc x y c; BitVec.cons a.1 a.2
Instances For
Comparison operators #
Signed greater than or equal to for bitvectors.
Equations
- BitVec.uge x y = BitVec.ule y x
Instances For
Signed greater than or equal to for bitvectors.
Equations
- BitVec.sge x y = BitVec.sle y x
Instances For
Conversion to nat
and int
#
addLsb r b
is r + r + 1
if b
is true
and r + r
otherwise.
Equations
- BitVec.addLsb r b = Nat.bit b r
Instances For
Return the i
-th least significant bit, where i
is a statically known in-bounds index
Equations
- BitVec.getLsb' x i = BitVec.getLsb x ↑i
Instances For
Return the i
-th most significant bit, where i
is a statically known in-bounds index
Equations
- BitVec.getMsb' x i = BitVec.getMsb x ↑i
Instances For
Convert a bitvector to a little-endian list of Booleans. That is, the head of the list is the least significant bit
Equations
Instances For
Convert a bitvector to a big-endian list of Booleans. That is, the head of the list is the most significant bit