// Copyright 2024 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. //go:build !wasm package bigmod import "math/bits" // addMulVVW multiplies the multi-word value x by the single-word value y, // adding the result to the multi-word value z and returning the final carry. // It can be thought of as one row of a pen-and-paper column multiplication. func addMulVVW(z, x []uint, y uint) (carry uint) { _ = x[len(z)-1] // bounds check elimination hint for i := range z { hi, lo := bits.Mul(x[i], y) lo, c := bits.Add(lo, z[i], 0) // We use bits.Add with zero to get an add-with-carry instruction that // absorbs the carry from the previous bits.Add. hi, _ = bits.Add(hi, 0, c) lo, c = bits.Add(lo, carry, 0) hi, _ = bits.Add(hi, 0, c) carry = hi z[i] = lo } return carry }