arithmetic_decl.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. // +build amd64,blsasm amd64,blsadx
  17. package bls12381
  18. import (
  19. "golang.org/x/sys/cpu"
  20. )
  21. func init() {
  22. if !enableADX || !cpu.X86.HasADX || !cpu.X86.HasBMI2 {
  23. mul = mulNoADX
  24. }
  25. }
  26. // Use ADX backend for default
  27. var mul func(c, a, b *fe) = mulADX
  28. func square(c, a *fe) {
  29. mul(c, a, a)
  30. }
  31. func neg(c, a *fe) {
  32. if a.isZero() {
  33. c.set(a)
  34. } else {
  35. _neg(c, a)
  36. }
  37. }
  38. //go:noescape
  39. func add(c, a, b *fe)
  40. //go:noescape
  41. func addAssign(a, b *fe)
  42. //go:noescape
  43. func ladd(c, a, b *fe)
  44. //go:noescape
  45. func laddAssign(a, b *fe)
  46. //go:noescape
  47. func double(c, a *fe)
  48. //go:noescape
  49. func doubleAssign(a *fe)
  50. //go:noescape
  51. func ldouble(c, a *fe)
  52. //go:noescape
  53. func sub(c, a, b *fe)
  54. //go:noescape
  55. func subAssign(a, b *fe)
  56. //go:noescape
  57. func lsubAssign(a, b *fe)
  58. //go:noescape
  59. func _neg(c, a *fe)
  60. //go:noescape
  61. func mulNoADX(c, a, b *fe)
  62. //go:noescape
  63. func mulADX(c, a, b *fe)