arithmetic_decl.go 1.7 KB

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