sub_n.S 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. # Alpha __mpn_sub_n -- Subtract two limb vectors of the same length > 0 and
  2. # store difference in a third limb vector.
  3. # Copyright (C) 1995-2026 Free Software Foundation, Inc.
  4. # This file is part of the GNU MP Library.
  5. # The GNU MP Library is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU Lesser General Public License as published by
  7. # the Free Software Foundation; either version 2.1 of the License, or (at your
  8. # option) any later version.
  9. # The GNU MP Library is distributed in the hope that it will be useful, but
  10. # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  12. # License for more details.
  13. # You should have received a copy of the GNU Lesser General Public License
  14. # along with the GNU MP Library. If not, see <https://www.gnu.org/licenses/>.
  15. # INPUT PARAMETERS
  16. # res_ptr $16
  17. # s1_ptr $17
  18. # s2_ptr $18
  19. # size $19
  20. .set noreorder
  21. .set noat
  22. .text
  23. .align 3
  24. .globl __mpn_sub_n
  25. .ent __mpn_sub_n
  26. __mpn_sub_n:
  27. .frame $30,0,$26,0
  28. or $31,$31,$25 # clear cy
  29. subq $19,4,$19 # decr loop cnt
  30. blt $19,.Lend2 # if less than 4 limbs, goto 2nd loop
  31. # Start software pipeline for 1st loop
  32. ldq $0,0($18)
  33. ldq $1,8($18)
  34. ldq $4,0($17)
  35. ldq $5,8($17)
  36. addq $17,32,$17 # update s1_ptr
  37. ldq $2,16($18)
  38. subq $4,$0,$20 # 1st main sub
  39. ldq $3,24($18)
  40. subq $19,4,$19 # decr loop cnt
  41. ldq $6,-16($17)
  42. cmpult $4,$20,$25 # compute cy from last sub
  43. ldq $7,-8($17)
  44. addq $1,$25,$28 # cy add
  45. addq $18,32,$18 # update s2_ptr
  46. subq $5,$28,$21 # 2nd main sub
  47. cmpult $28,$25,$8 # compute cy from last add
  48. blt $19,.Lend1 # if less than 4 limbs remain, jump
  49. # 1st loop handles groups of 4 limbs in a software pipeline
  50. .align 4
  51. .Loop: cmpult $5,$21,$25 # compute cy from last add
  52. ldq $0,0($18)
  53. or $8,$25,$25 # combine cy from the two adds
  54. ldq $1,8($18)
  55. addq $2,$25,$28 # cy add
  56. ldq $4,0($17)
  57. subq $6,$28,$22 # 3rd main sub
  58. ldq $5,8($17)
  59. cmpult $28,$25,$8 # compute cy from last add
  60. cmpult $6,$22,$25 # compute cy from last add
  61. stq $20,0($16)
  62. or $8,$25,$25 # combine cy from the two adds
  63. stq $21,8($16)
  64. addq $3,$25,$28 # cy add
  65. subq $7,$28,$23 # 4th main sub
  66. cmpult $28,$25,$8 # compute cy from last add
  67. cmpult $7,$23,$25 # compute cy from last add
  68. addq $17,32,$17 # update s1_ptr
  69. or $8,$25,$25 # combine cy from the two adds
  70. addq $16,32,$16 # update res_ptr
  71. addq $0,$25,$28 # cy add
  72. ldq $2,16($18)
  73. subq $4,$28,$20 # 1st main sub
  74. ldq $3,24($18)
  75. cmpult $28,$25,$8 # compute cy from last add
  76. ldq $6,-16($17)
  77. cmpult $4,$20,$25 # compute cy from last add
  78. ldq $7,-8($17)
  79. or $8,$25,$25 # combine cy from the two adds
  80. subq $19,4,$19 # decr loop cnt
  81. stq $22,-16($16)
  82. addq $1,$25,$28 # cy add
  83. stq $23,-8($16)
  84. subq $5,$28,$21 # 2nd main sub
  85. addq $18,32,$18 # update s2_ptr
  86. cmpult $28,$25,$8 # compute cy from last add
  87. bge $19,.Loop
  88. # Finish software pipeline for 1st loop
  89. .Lend1: cmpult $5,$21,$25 # compute cy from last add
  90. or $8,$25,$25 # combine cy from the two adds
  91. addq $2,$25,$28 # cy add
  92. subq $6,$28,$22 # 3rd main sub
  93. cmpult $28,$25,$8 # compute cy from last add
  94. cmpult $6,$22,$25 # compute cy from last add
  95. stq $20,0($16)
  96. or $8,$25,$25 # combine cy from the two adds
  97. stq $21,8($16)
  98. addq $3,$25,$28 # cy add
  99. subq $7,$28,$23 # 4th main sub
  100. cmpult $28,$25,$8 # compute cy from last add
  101. cmpult $7,$23,$25 # compute cy from last add
  102. or $8,$25,$25 # combine cy from the two adds
  103. addq $16,32,$16 # update res_ptr
  104. stq $22,-16($16)
  105. stq $23,-8($16)
  106. .Lend2: addq $19,4,$19 # restore loop cnt
  107. beq $19,.Lret
  108. # Start software pipeline for 2nd loop
  109. ldq $0,0($18)
  110. ldq $4,0($17)
  111. subq $19,1,$19
  112. beq $19,.Lend0
  113. # 2nd loop handles remaining 1-3 limbs
  114. .align 4
  115. .Loop0: addq $0,$25,$28 # cy add
  116. ldq $0,8($18)
  117. subq $4,$28,$20 # main sub
  118. ldq $1,8($17)
  119. addq $18,8,$18
  120. cmpult $28,$25,$8 # compute cy from last add
  121. addq $17,8,$17
  122. stq $20,0($16)
  123. cmpult $4,$20,$25 # compute cy from last add
  124. subq $19,1,$19 # decr loop cnt
  125. or $8,$25,$25 # combine cy from the two adds
  126. addq $16,8,$16
  127. or $1,$31,$4
  128. bne $19,.Loop0
  129. .Lend0: addq $0,$25,$28 # cy add
  130. subq $4,$28,$20 # main sub
  131. cmpult $28,$25,$8 # compute cy from last add
  132. cmpult $4,$20,$25 # compute cy from last add
  133. stq $20,0($16)
  134. or $8,$25,$25 # combine cy from the two adds
  135. .Lret: or $25,$31,$0 # return cy
  136. ret $31,($26),1
  137. .end __mpn_sub_n