github.com/consensys/gnark-crypto@v0.14.0/ecc/bls24-317/fp/arith.go (about)

     1  // Copyright 2020 ConsenSys Software Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // Code generated by consensys/gnark-crypto DO NOT EDIT
    16  
    17  package fp
    18  
    19  import (
    20  	"math/bits"
    21  )
    22  
    23  // madd0 hi = a*b + c (discards lo bits)
    24  func madd0(a, b, c uint64) (hi uint64) {
    25  	var carry, lo uint64
    26  	hi, lo = bits.Mul64(a, b)
    27  	_, carry = bits.Add64(lo, c, 0)
    28  	hi, _ = bits.Add64(hi, 0, carry)
    29  	return
    30  }
    31  
    32  // madd1 hi, lo = a*b + c
    33  func madd1(a, b, c uint64) (hi uint64, lo uint64) {
    34  	var carry uint64
    35  	hi, lo = bits.Mul64(a, b)
    36  	lo, carry = bits.Add64(lo, c, 0)
    37  	hi, _ = bits.Add64(hi, 0, carry)
    38  	return
    39  }
    40  
    41  // madd2 hi, lo = a*b + c + d
    42  func madd2(a, b, c, d uint64) (hi uint64, lo uint64) {
    43  	var carry uint64
    44  	hi, lo = bits.Mul64(a, b)
    45  	c, carry = bits.Add64(c, d, 0)
    46  	hi, _ = bits.Add64(hi, 0, carry)
    47  	lo, carry = bits.Add64(lo, c, 0)
    48  	hi, _ = bits.Add64(hi, 0, carry)
    49  	return
    50  }
    51  
    52  func madd3(a, b, c, d, e uint64) (hi uint64, lo uint64) {
    53  	var carry uint64
    54  	hi, lo = bits.Mul64(a, b)
    55  	c, carry = bits.Add64(c, d, 0)
    56  	hi, _ = bits.Add64(hi, 0, carry)
    57  	lo, carry = bits.Add64(lo, c, 0)
    58  	hi, _ = bits.Add64(hi, e, carry)
    59  	return
    60  }
    61  func max(a int, b int) int {
    62  	if a > b {
    63  		return a
    64  	}
    65  	return b
    66  }
    67  
    68  func min(a int, b int) int {
    69  	if a < b {
    70  		return a
    71  	}
    72  	return b
    73  }