TorchLean API

FloatLib.Kernels.FixedWord.Product.Runtime

Fixed-limb product runtime #

Carry-preserving addition and full products operate over one, two, and four native limbs. The explicit UInt256 carrier is large enough for the exact product of two UInt128 values, so the product needs no arbitrary-precision conversion.

Product.Proof shows that each returned value and carry reconstruct the exact natural-number sum or product.

A fixed-width addition result together with its unsigned carry.

  • value : α

    Low fixed-width part of the exact sum.

  • carry : UInt64

    Carry above the payload's highest bit, represented as a native word.

Instances For
    def FloatLib.Numerics.FixedWord.instDecidableEqAddResult.decEq {α✝ : Type u_1} [DecidableEq α✝] (x✝ x✝¹ : AddResult α✝) :
    Decidable (x✝ = x✝¹)
    Instances For
      @[instance_reducible]
      @[instance_reducible]
      instance FloatLib.Numerics.FixedWord.instReprAddResult {α✝ : Type u_1} [Repr α✝] :
      Repr (AddResult α✝)
      Instances For
        @[inline]

        Add two native words and retain the unsigned carry.

        Instances For
          @[inline]

          Add two words and an incoming carry.

          Instances For
            @[inline]

            Add two two-word values.

            Instances For

              A 256-bit unsigned value represented by four native 64-bit limbs.

              • limb3 : UInt64

                Bits 192 through 255.

              • limb2 : UInt64

                Bits 128 through 191.

              • limb1 : UInt64

                Bits 64 through 127.

              • limb0 : UInt64

                Bits 0 through 63.

              Instances For
                @[inline]

                Embed a two-limb unsigned value in the low half of a four-limb carrier.

                Instances For
                  @[inline]

                  Embed a two-limb value after shifting it left by shift bits, for 64 < shift < 128.

                  The two-word kernels for formats of at most 128 bits align a fracWidth + 1-bit significand by fracWidth or fracWidth + 1 places, so division, fused multiply-add, and square root share this one word shuffle. toNat_ofUInt128ShiftedLeft gives its value under the stated shift bounds; outside them the native shift counts wrap and the result is unspecified.

                  Instances For
                    @[inline]

                    Return the low two limbs of a four-limb unsigned value.

                    Instances For

                      Mathematical value of a four-limb unsigned integer.

                      Instances For
                        @[inline]

                        Position of the most significant set bit, with zero mapped to zero.

                        Instances For
                          @[inline]

                          Add two four-word values.

                          Instances For
                            @[inline]

                            Exact native multiplication of two two-limb values.

                            Four mul64 products form the schoolbook product. Each output column is reduced with add64, and the resulting carry count is passed to the next column.

                            Instances For