udivdi3.S 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  3. This file is part of GNU CC.
  4. */
  5. .text
  6. .align 4
  7. .globl __udivdi3
  8. __udivdi3:
  9. save %sp,-104,%sp
  10. mov %i3,%o3
  11. cmp %i2,0
  12. bne .LL40
  13. mov %i1,%i3
  14. cmp %o3,%i0
  15. bleu .LL41
  16. mov %i3,%o1
  17. ! Inlined udiv_qrnnd
  18. mov 32,%g1
  19. subcc %i0,%o3,%g0
  20. 1: bcs 5f
  21. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  22. sub %i0,%o3,%i0 ! this kills msb of n
  23. addx %i0,%i0,%i0 ! so this cannot give carry
  24. subcc %g1,1,%g1
  25. 2: bne 1b
  26. subcc %i0,%o3,%g0
  27. bcs 3f
  28. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  29. b 3f
  30. sub %i0,%o3,%i0 ! this kills msb of n
  31. 4: sub %i0,%o3,%i0
  32. 5: addxcc %i0,%i0,%i0
  33. bcc 2b
  34. subcc %g1,1,%g1
  35. ! Got carry from n. Subtract next step to cancel this carry.
  36. bne 4b
  37. addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb
  38. sub %i0,%o3,%i0
  39. 3: xnor %o1,0,%o1
  40. ! End of inline udiv_qrnnd
  41. b .LL45
  42. mov 0,%o2
  43. .LL41:
  44. cmp %o3,0
  45. bne .LL77
  46. mov %i0,%o2
  47. mov 1,%o0
  48. mov 0,%o1
  49. wr %g0, 0, %y
  50. udiv %o0, %o1, %o0
  51. mov %o0,%o3
  52. mov %i0,%o2
  53. .LL77:
  54. mov 0,%o4
  55. ! Inlined udiv_qrnnd
  56. mov 32,%g1
  57. subcc %o4,%o3,%g0
  58. 1: bcs 5f
  59. addxcc %o2,%o2,%o2 ! shift n1n0 and a q-bit in lsb
  60. sub %o4,%o3,%o4 ! this kills msb of n
  61. addx %o4,%o4,%o4 ! so this cannot give carry
  62. subcc %g1,1,%g1
  63. 2: bne 1b
  64. subcc %o4,%o3,%g0
  65. bcs 3f
  66. addxcc %o2,%o2,%o2 ! shift n1n0 and a q-bit in lsb
  67. b 3f
  68. sub %o4,%o3,%o4 ! this kills msb of n
  69. 4: sub %o4,%o3,%o4
  70. 5: addxcc %o4,%o4,%o4
  71. bcc 2b
  72. subcc %g1,1,%g1
  73. ! Got carry from n. Subtract next step to cancel this carry.
  74. bne 4b
  75. addcc %o2,%o2,%o2 ! shift n1n0 and a 0-bit in lsb
  76. sub %o4,%o3,%o4
  77. 3: xnor %o2,0,%o2
  78. ! End of inline udiv_qrnnd
  79. mov %o4,%i0
  80. mov %i3,%o1
  81. ! Inlined udiv_qrnnd
  82. mov 32,%g1
  83. subcc %i0,%o3,%g0
  84. 1: bcs 5f
  85. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  86. sub %i0,%o3,%i0 ! this kills msb of n
  87. addx %i0,%i0,%i0 ! so this cannot give carry
  88. subcc %g1,1,%g1
  89. 2: bne 1b
  90. subcc %i0,%o3,%g0
  91. bcs 3f
  92. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  93. b 3f
  94. sub %i0,%o3,%i0 ! this kills msb of n
  95. 4: sub %i0,%o3,%i0
  96. 5: addxcc %i0,%i0,%i0
  97. bcc 2b
  98. subcc %g1,1,%g1
  99. ! Got carry from n. Subtract next step to cancel this carry.
  100. bne 4b
  101. addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb
  102. sub %i0,%o3,%i0
  103. 3: xnor %o1,0,%o1
  104. ! End of inline udiv_qrnnd
  105. b .LL78
  106. mov %o1,%l1
  107. .LL40:
  108. cmp %i2,%i0
  109. bleu .LL46
  110. sethi %hi(65535),%o0
  111. b .LL73
  112. mov 0,%o1
  113. .LL46:
  114. or %o0,%lo(65535),%o0
  115. cmp %i2,%o0
  116. bgu .LL53
  117. mov %i2,%o1
  118. cmp %i2,256
  119. addx %g0,-1,%o0
  120. b .LL59
  121. and %o0,8,%o2
  122. .LL53:
  123. sethi %hi(16777215),%o0
  124. or %o0,%lo(16777215),%o0
  125. cmp %o1,%o0
  126. bgu .LL59
  127. mov 24,%o2
  128. mov 16,%o2
  129. .LL59:
  130. srl %o1,%o2,%o1
  131. sethi %hi(__clz_tab),%o0
  132. or %o0,%lo(__clz_tab),%o0
  133. ldub [%o1+%o0],%o0
  134. add %o0,%o2,%o0
  135. mov 32,%o1
  136. subcc %o1,%o0,%o2
  137. bne,a .LL67
  138. mov 32,%o0
  139. cmp %i0,%i2
  140. bgu .LL69
  141. cmp %i3,%o3
  142. blu .LL73
  143. mov 0,%o1
  144. .LL69:
  145. b .LL73
  146. mov 1,%o1
  147. .LL67:
  148. sub %o0,%o2,%o0
  149. sll %i2,%o2,%i2
  150. srl %o3,%o0,%o1
  151. or %i2,%o1,%i2
  152. sll %o3,%o2,%o3
  153. srl %i0,%o0,%o1
  154. sll %i0,%o2,%i0
  155. srl %i3,%o0,%o0
  156. or %i0,%o0,%i0
  157. sll %i3,%o2,%i3
  158. mov %i0,%o5
  159. mov %o1,%o4
  160. ! Inlined udiv_qrnnd
  161. mov 32,%g1
  162. subcc %o4,%i2,%g0
  163. 1: bcs 5f
  164. addxcc %o5,%o5,%o5 ! shift n1n0 and a q-bit in lsb
  165. sub %o4,%i2,%o4 ! this kills msb of n
  166. addx %o4,%o4,%o4 ! so this cannot give carry
  167. subcc %g1,1,%g1
  168. 2: bne 1b
  169. subcc %o4,%i2,%g0
  170. bcs 3f
  171. addxcc %o5,%o5,%o5 ! shift n1n0 and a q-bit in lsb
  172. b 3f
  173. sub %o4,%i2,%o4 ! this kills msb of n
  174. 4: sub %o4,%i2,%o4
  175. 5: addxcc %o4,%o4,%o4
  176. bcc 2b
  177. subcc %g1,1,%g1
  178. ! Got carry from n. Subtract next step to cancel this carry.
  179. bne 4b
  180. addcc %o5,%o5,%o5 ! shift n1n0 and a 0-bit in lsb
  181. sub %o4,%i2,%o4
  182. 3: xnor %o5,0,%o5
  183. ! End of inline udiv_qrnnd
  184. mov %o4,%i0
  185. mov %o5,%o1
  186. ! Inlined umul_ppmm
  187. wr %g0,%o1,%y ! SPARC has 0-3 delay insn after a wr
  188. sra %o3,31,%g2 ! Do not move this insn
  189. and %o1,%g2,%g2 ! Do not move this insn
  190. andcc %g0,0,%g1 ! Do not move this insn
  191. mulscc %g1,%o3,%g1
  192. mulscc %g1,%o3,%g1
  193. mulscc %g1,%o3,%g1
  194. mulscc %g1,%o3,%g1
  195. mulscc %g1,%o3,%g1
  196. mulscc %g1,%o3,%g1
  197. mulscc %g1,%o3,%g1
  198. mulscc %g1,%o3,%g1
  199. mulscc %g1,%o3,%g1
  200. mulscc %g1,%o3,%g1
  201. mulscc %g1,%o3,%g1
  202. mulscc %g1,%o3,%g1
  203. mulscc %g1,%o3,%g1
  204. mulscc %g1,%o3,%g1
  205. mulscc %g1,%o3,%g1
  206. mulscc %g1,%o3,%g1
  207. mulscc %g1,%o3,%g1
  208. mulscc %g1,%o3,%g1
  209. mulscc %g1,%o3,%g1
  210. mulscc %g1,%o3,%g1
  211. mulscc %g1,%o3,%g1
  212. mulscc %g1,%o3,%g1
  213. mulscc %g1,%o3,%g1
  214. mulscc %g1,%o3,%g1
  215. mulscc %g1,%o3,%g1
  216. mulscc %g1,%o3,%g1
  217. mulscc %g1,%o3,%g1
  218. mulscc %g1,%o3,%g1
  219. mulscc %g1,%o3,%g1
  220. mulscc %g1,%o3,%g1
  221. mulscc %g1,%o3,%g1
  222. mulscc %g1,%o3,%g1
  223. mulscc %g1,0,%g1
  224. add %g1,%g2,%o0
  225. rd %y,%o2
  226. cmp %o0,%i0
  227. bgu,a .LL73
  228. add %o1,-1,%o1
  229. bne,a .LL45
  230. mov 0,%o2
  231. cmp %o2,%i3
  232. bleu .LL45
  233. mov 0,%o2
  234. add %o1,-1,%o1
  235. .LL73:
  236. mov 0,%o2
  237. .LL45:
  238. mov %o1,%l1
  239. .LL78:
  240. mov %o2,%l0
  241. mov %l0,%i0
  242. mov %l1,%i1
  243. ret
  244. restore