Documentation

Mathlib.Data.BitVec.Defs

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 #

Constants #

@[inline, reducible]
abbrev Std.BitVec.one (w : ) :

The bitvector representing 1. That is, the bitvector with least-significant bit 1 and all other bits 0

Equations
Instances For

    Bitwise operations #

    Arithmetic operators #

    def Std.BitVec.adc' {n : } (x : Std.BitVec n) (y : Std.BitVec n) (c : Bool) :

    Add with carry (no overflow)

    See also Std.BitVec.adc, which stores the carry bit separately.

    Equations
    Instances For
      def Std.BitVec.sbb {n : } (x : Std.BitVec n) (y : Std.BitVec n) (b : Bool) :

      Subtract with borrow

      Equations
      Instances For

        Comparison operators #

        def Std.BitVec.ugt {w : } (x : Std.BitVec w) (y : Std.BitVec w) :

        Unsigned greater than for bitvectors.

        Equations
        Instances For
          def Std.BitVec.uge {w : } (x : Std.BitVec w) (y : Std.BitVec w) :

          Signed greater than or equal to for bitvectors.

          Equations
          Instances For
            def Std.BitVec.sgt {w : } (x : Std.BitVec w) (y : Std.BitVec w) :

            Signed greater than for bitvectors.

            Equations
            Instances For
              def Std.BitVec.sge {w : } (x : Std.BitVec w) (y : Std.BitVec w) :

              Signed greater than or equal to for bitvectors.

              Equations
              Instances For

                Conversion to nat and int #

                def Std.BitVec.addLsb (r : ) (b : Bool) :

                addLsb r b is r + r + 1 if b is true and r + r otherwise.

                Equations
                Instances For
                  def Std.BitVec.getLsb' {w : } (x : Std.BitVec w) (i : Fin w) :

                  Return the i-th least significant bit, where i is a statically known in-bounds index

                  Equations
                  Instances For
                    def Std.BitVec.getMsb' {w : } (x : Std.BitVec w) (i : Fin w) :

                    Return the i-th most significant bit, where i is a statically known in-bounds index

                    Equations
                    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

                        Equations
                        Instances For
                          Equations
                          • Std.BitVec.instSMulNatBitVec = { smul := fun (x : ) (y : Std.BitVec w) => { toFin := x y.toFin } }
                          Equations
                          • Std.BitVec.instSMulIntBitVec = { smul := fun (x : ) (y : Std.BitVec w) => { toFin := x y.toFin } }
                          Equations
                          • Std.BitVec.instPowBitVecNat = { pow := fun (x : Std.BitVec w) (n : ) => { toFin := x.toFin ^ n } }
                          Equations
                          Equations