github.com/emmansun/gmsm@v0.29.1/sm9/bn256/gfp_decl.go (about)

     1  //go:build (amd64 || arm64 || ppc64 || ppc64le) && !purego
     2  
     3  package bn256
     4  
     5  // This file contains forward declarations for the architecture-specific
     6  // assembly implementations of these functions, provided that they exist.
     7  
     8  import (
     9  	"golang.org/x/sys/cpu"
    10  )
    11  
    12  // amd64 assembly uses ADCX/ADOX/MULX if ADX is available to run two carry
    13  // chains in the flags in parallel across the whole operation, and aggressively
    14  // unrolls loops. arm64 processes four words at a time.
    15  var supportADX = cpu.X86.HasADX && cpu.X86.HasBMI2
    16  
    17  // Set c = p - a, if c == p, then c = 0
    18  // It seems this function's performance is worse than gfpSub with zero.
    19  //
    20  //go:noescape
    21  func gfpNeg(c, a *gfP)
    22  
    23  // Set c = a + b, if c >= p, then c = c - p
    24  //
    25  //go:noescape
    26  func gfpAdd(c, a, b *gfP)
    27  
    28  // Set c = a + a
    29  //
    30  //go:noescape
    31  func gfpDouble(c, a *gfP)
    32  
    33  // Set c = a + a + a
    34  //
    35  //go:noescape
    36  func gfpTriple(c, a *gfP)
    37  
    38  // Set c = a - b, if c is negative, then c = c + p
    39  //
    40  //go:noescape
    41  func gfpSub(c, a, b *gfP)
    42  
    43  // Montgomery multiplication. Sets res = in1 * in2 * R⁻¹ mod p.
    44  //
    45  //go:noescape
    46  func gfpMul(c, a, b *gfP)
    47  
    48  // Montgomery square, repeated n times (n >= 1).
    49  //
    50  //go:noescape
    51  func gfpSqr(res, in *gfP, n int)
    52  
    53  // Montgomery multiplication by R⁻¹, or 1 outside the domain.
    54  // Sets res = in * R⁻¹, bringing res out of the Montgomery domain.
    55  //
    56  //go:noescape
    57  func gfpFromMont(res, in *gfP)
    58  
    59  // Marshal gfP into big endian form
    60  //
    61  //go:noescape
    62  func gfpMarshal(out *[32]byte, in *gfP)
    63  
    64  // Unmarshal the bytes into little endian form
    65  //
    66  //go:noescape
    67  func gfpUnmarshal(out *gfP, in *[32]byte)