github.com/nova-foundation/go-ethereum@v1.0.1/crypto/bls12381/arithmetic_decl.go (about)

     1  // Copyright 2020 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  //go:build (amd64 && blsasm) || (amd64 && blsadx)
    18  // +build amd64,blsasm amd64,blsadx
    19  
    20  package bls12381
    21  
    22  import (
    23  	"golang.org/x/sys/cpu"
    24  )
    25  
    26  func init() {
    27  	if !enableADX || !cpu.X86.HasADX || !cpu.X86.HasBMI2 {
    28  		mul = mulNoADX
    29  	}
    30  }
    31  
    32  // Use ADX backend for default
    33  var mul func(c, a, b *fe) = mulADX
    34  
    35  func square(c, a *fe) {
    36  	mul(c, a, a)
    37  }
    38  
    39  func neg(c, a *fe) {
    40  	if a.isZero() {
    41  		c.set(a)
    42  	} else {
    43  		_neg(c, a)
    44  	}
    45  }
    46  
    47  //go:noescape
    48  func add(c, a, b *fe)
    49  
    50  //go:noescape
    51  func addAssign(a, b *fe)
    52  
    53  //go:noescape
    54  func ladd(c, a, b *fe)
    55  
    56  //go:noescape
    57  func laddAssign(a, b *fe)
    58  
    59  //go:noescape
    60  func double(c, a *fe)
    61  
    62  //go:noescape
    63  func doubleAssign(a *fe)
    64  
    65  //go:noescape
    66  func ldouble(c, a *fe)
    67  
    68  //go:noescape
    69  func sub(c, a, b *fe)
    70  
    71  //go:noescape
    72  func subAssign(a, b *fe)
    73  
    74  //go:noescape
    75  func lsubAssign(a, b *fe)
    76  
    77  //go:noescape
    78  func _neg(c, a *fe)
    79  
    80  //go:noescape
    81  func mulNoADX(c, a, b *fe)
    82  
    83  //go:noescape
    84  func mulADX(c, a, b *fe)