TorchLean API

FloatLib.Floats.ExecFloat.Backends.FixedLimb.Pair.Fma.Runtime

Two-word fused multiply-add runtime #

The two-word counterpart of NativeSmallWordFma. The exact product of the two significands is a four-word value in the product rounder's coordinate; the addend significand joins it either by an exact left shift or, when the scales are far apart, through three guard positions and a sticky bit below the operand at the larger scale. The combined four-word magnitude is reduced to two words with a sticky bit (normalizeJam128) and rounded once by the two-word rounder of Addition.Runtime at scale offset 0. Correctness proofs live in Fma.Proof.

The kernel serves eligible layouts with at most 120 fraction bits and 32 exponent bits, which keep every intermediate in four words and every scale in one. It returns none for exceptional operands, a zero product, a sticky alignment whose higher operand is subnormal, results below the normal threshold, and overflow. fmaFinite? then falls back to the exact generic kernel.

@[inline]

Round a nonzero four-word magnitude at product scale scale to normal storage words, or decline.

First the magnitude is reduced to its leading 128-bit window with a sticky bit. At least fracWidth + 2 bits remain above the jammed positions, so nearest-even rounding is unchanged.

Instances For
    @[inline]

    Combine two nonzero signed four-word magnitudes aligned at one scale and round once.

    Its branches are those of FiniteScaleAdd.roundMagnitudes, and exact cancellation is positive zero. Same-sign callers keep left + right below 2 ^ 256.

    Instances For
      @[inline]

      The sticky magnitude of a product high above an addend low that lie gap ≥ 3 scale positions apart: high doubled three times, combined with low shifted right by gap - 3, with the lowest bit set when that shift discards a nonzero bit.

      Instances For
        @[inline]

        The sticky magnitude of an addend high above a product low that lie gap ≥ 3 scale positions apart: high shifted left by three guard positions, combined with low shifted right by gap - 3, with the lowest bit set when that shift discards a nonzero bit.

        Instances For
          @[inline]

          Whether a four-word product is at least 2 ^ fracWidth, the smallest normal significand.

          Instances For
            @[inline]

            Round product * 2 ^ productScale + addend * 2 ^ addendScale once, in product coordinates.

            A zero addend rounds the product alone. An addend at a scale at most fracWidth + 2 above the product is shifted onto the product exactly, and a larger gap leaves the product as a sticky tail of the addend. A product at a scale above the addend is aligned exactly for gaps below three and otherwise keeps the addend as its sticky tail. A zero product and a sticky alignment whose higher operand is below 2 ^ fracWidth return none.

            Instances For
              @[inline]

              Two-word finite fused multiply-add on storage words, or decline.

              The product scale is the sum of the operands' compact finite scales, and the addend's compact scale is moved into product coordinates by alignOffset fmt. Layouts with more than 120 fraction or 32 exponent bits decline. Fma.Proof.fmaFiniteWords_refines relates every accepted result to FiniteKernel.fma?.

              Instances For
                @[specialize #[0]]

                Evaluate finite two-word fused multiply-add on model values.

                The storage-word kernel runs first. Every remaining finite case uses the generic one-rounding exact kernel, and exceptional inputs return none to the dispatcher.

                Instances For