gfp_arm64.s 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // +build arm64,!generic
  2. #define storeBlock(a0,a1,a2,a3, r) \
  3. MOVD a0, 0+r \
  4. MOVD a1, 8+r \
  5. MOVD a2, 16+r \
  6. MOVD a3, 24+r
  7. #define loadBlock(r, a0,a1,a2,a3) \
  8. MOVD 0+r, a0 \
  9. MOVD 8+r, a1 \
  10. MOVD 16+r, a2 \
  11. MOVD 24+r, a3
  12. #define loadModulus(p0,p1,p2,p3) \
  13. MOVD ·p2+0(SB), p0 \
  14. MOVD ·p2+8(SB), p1 \
  15. MOVD ·p2+16(SB), p2 \
  16. MOVD ·p2+24(SB), p3
  17. #include "mul_arm64.h"
  18. TEXT ·gfpNeg(SB),0,$0-16
  19. MOVD a+8(FP), R0
  20. loadBlock(0(R0), R1,R2,R3,R4)
  21. loadModulus(R5,R6,R7,R8)
  22. SUBS R1, R5, R1
  23. SBCS R2, R6, R2
  24. SBCS R3, R7, R3
  25. SBCS R4, R8, R4
  26. SUBS R5, R1, R5
  27. SBCS R6, R2, R6
  28. SBCS R7, R3, R7
  29. SBCS R8, R4, R8
  30. CSEL CS, R5, R1, R1
  31. CSEL CS, R6, R2, R2
  32. CSEL CS, R7, R3, R3
  33. CSEL CS, R8, R4, R4
  34. MOVD c+0(FP), R0
  35. storeBlock(R1,R2,R3,R4, 0(R0))
  36. RET
  37. TEXT ·gfpAdd(SB),0,$0-24
  38. MOVD a+8(FP), R0
  39. loadBlock(0(R0), R1,R2,R3,R4)
  40. MOVD b+16(FP), R0
  41. loadBlock(0(R0), R5,R6,R7,R8)
  42. loadModulus(R9,R10,R11,R12)
  43. MOVD ZR, R0
  44. ADDS R5, R1
  45. ADCS R6, R2
  46. ADCS R7, R3
  47. ADCS R8, R4
  48. ADCS ZR, R0
  49. SUBS R9, R1, R5
  50. SBCS R10, R2, R6
  51. SBCS R11, R3, R7
  52. SBCS R12, R4, R8
  53. SBCS ZR, R0, R0
  54. CSEL CS, R5, R1, R1
  55. CSEL CS, R6, R2, R2
  56. CSEL CS, R7, R3, R3
  57. CSEL CS, R8, R4, R4
  58. MOVD c+0(FP), R0
  59. storeBlock(R1,R2,R3,R4, 0(R0))
  60. RET
  61. TEXT ·gfpSub(SB),0,$0-24
  62. MOVD a+8(FP), R0
  63. loadBlock(0(R0), R1,R2,R3,R4)
  64. MOVD b+16(FP), R0
  65. loadBlock(0(R0), R5,R6,R7,R8)
  66. loadModulus(R9,R10,R11,R12)
  67. SUBS R5, R1
  68. SBCS R6, R2
  69. SBCS R7, R3
  70. SBCS R8, R4
  71. CSEL CS, ZR, R9, R9
  72. CSEL CS, ZR, R10, R10
  73. CSEL CS, ZR, R11, R11
  74. CSEL CS, ZR, R12, R12
  75. ADDS R9, R1
  76. ADCS R10, R2
  77. ADCS R11, R3
  78. ADCS R12, R4
  79. MOVD c+0(FP), R0
  80. storeBlock(R1,R2,R3,R4, 0(R0))
  81. RET
  82. TEXT ·gfpMul(SB),0,$0-24
  83. MOVD a+8(FP), R0
  84. loadBlock(0(R0), R1,R2,R3,R4)
  85. MOVD b+16(FP), R0
  86. loadBlock(0(R0), R5,R6,R7,R8)
  87. mul(R9,R10,R11,R12,R13,R14,R15,R16)
  88. gfpReduce()
  89. MOVD c+0(FP), R0
  90. storeBlock(R1,R2,R3,R4, 0(R0))
  91. RET