You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.0 KiB

  1. // Copyright 2020 ConsenSys AG
  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. // Code generated by goff DO NOT EDIT
  15. package ff
  16. import (
  17. "math/bits"
  18. )
  19. func madd(a, b, t, u, v uint64) (uint64, uint64, uint64) {
  20. var carry uint64
  21. hi, lo := bits.Mul64(a, b)
  22. v, carry = bits.Add64(lo, v, 0)
  23. u, carry = bits.Add64(hi, u, carry)
  24. t, _ = bits.Add64(t, 0, carry)
  25. return t, u, v
  26. }
  27. // madd0 hi = a*b + c (discards lo bits)
  28. func madd0(a, b, c uint64) (hi uint64) {
  29. var carry, lo uint64
  30. hi, lo = bits.Mul64(a, b)
  31. _, carry = bits.Add64(lo, c, 0)
  32. hi, _ = bits.Add64(hi, 0, carry)
  33. return
  34. }
  35. // madd1 hi, lo = a*b + c
  36. func madd1(a, b, c uint64) (hi uint64, lo uint64) {
  37. var carry uint64
  38. hi, lo = bits.Mul64(a, b)
  39. lo, carry = bits.Add64(lo, c, 0)
  40. hi, _ = bits.Add64(hi, 0, carry)
  41. return
  42. }
  43. // madd2 hi, lo = a*b + c + d
  44. func madd2(a, b, c, d uint64) (hi uint64, lo uint64) {
  45. var carry uint64
  46. hi, lo = bits.Mul64(a, b)
  47. c, carry = bits.Add64(c, d, 0)
  48. hi, _ = bits.Add64(hi, 0, carry)
  49. lo, carry = bits.Add64(lo, c, 0)
  50. hi, _ = bits.Add64(hi, 0, carry)
  51. return
  52. }
  53. // madd2s superhi, hi, lo = 2*a*b + c + d + e
  54. func madd2s(a, b, c, d, e uint64) (superhi, hi, lo uint64) {
  55. var carry, sum uint64
  56. hi, lo = bits.Mul64(a, b)
  57. lo, carry = bits.Add64(lo, lo, 0)
  58. hi, superhi = bits.Add64(hi, hi, carry)
  59. sum, carry = bits.Add64(c, e, 0)
  60. hi, _ = bits.Add64(hi, 0, carry)
  61. lo, carry = bits.Add64(lo, sum, 0)
  62. hi, _ = bits.Add64(hi, 0, carry)
  63. hi, _ = bits.Add64(hi, 0, d)
  64. return
  65. }
  66. func madd1s(a, b, d, e uint64) (superhi, hi, lo uint64) {
  67. var carry uint64
  68. hi, lo = bits.Mul64(a, b)
  69. lo, carry = bits.Add64(lo, lo, 0)
  70. hi, superhi = bits.Add64(hi, hi, carry)
  71. lo, carry = bits.Add64(lo, e, 0)
  72. hi, _ = bits.Add64(hi, 0, carry)
  73. hi, _ = bits.Add64(hi, 0, d)
  74. return
  75. }
  76. func madd2sb(a, b, c, e uint64) (superhi, hi, lo uint64) {
  77. var carry, sum uint64
  78. hi, lo = bits.Mul64(a, b)
  79. lo, carry = bits.Add64(lo, lo, 0)
  80. hi, superhi = bits.Add64(hi, hi, carry)
  81. sum, carry = bits.Add64(c, e, 0)
  82. hi, _ = bits.Add64(hi, 0, carry)
  83. lo, carry = bits.Add64(lo, sum, 0)
  84. hi, _ = bits.Add64(hi, 0, carry)
  85. return
  86. }
  87. func madd1sb(a, b, e uint64) (superhi, hi, lo uint64) {
  88. var carry uint64
  89. hi, lo = bits.Mul64(a, b)
  90. lo, carry = bits.Add64(lo, lo, 0)
  91. hi, superhi = bits.Add64(hi, hi, carry)
  92. lo, carry = bits.Add64(lo, e, 0)
  93. hi, _ = bits.Add64(hi, 0, carry)
  94. return
  95. }
  96. func madd3(a, b, c, d, e uint64) (hi uint64, lo uint64) {
  97. var carry uint64
  98. hi, lo = bits.Mul64(a, b)
  99. c, carry = bits.Add64(c, d, 0)
  100. hi, _ = bits.Add64(hi, 0, carry)
  101. lo, carry = bits.Add64(lo, c, 0)
  102. hi, _ = bits.Add64(hi, e, carry)
  103. return
  104. }