udivdi3.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
  2. This file is part of GNU CC.
  3. GNU CC is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. GNU CC is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with GNU CC; see the file COPYING. If not, write to
  13. the Free Software Foundation, 59 Temple Place - Suite 330,
  14. Boston, MA 02111-1307, USA. */
  15. .text
  16. .align 4
  17. .globl __udivdi3
  18. __udivdi3:
  19. save %sp,-104,%sp
  20. mov %i3,%o3
  21. cmp %i2,0
  22. bne .LL40
  23. mov %i1,%i3
  24. cmp %o3,%i0
  25. bleu .LL41
  26. mov %i3,%o1
  27. ! Inlined udiv_qrnnd
  28. mov 32,%g1
  29. subcc %i0,%o3,%g0
  30. 1: bcs 5f
  31. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  32. sub %i0,%o3,%i0 ! this kills msb of n
  33. addx %i0,%i0,%i0 ! so this cannot give carry
  34. subcc %g1,1,%g1
  35. 2: bne 1b
  36. subcc %i0,%o3,%g0
  37. bcs 3f
  38. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  39. b 3f
  40. sub %i0,%o3,%i0 ! this kills msb of n
  41. 4: sub %i0,%o3,%i0
  42. 5: addxcc %i0,%i0,%i0
  43. bcc 2b
  44. subcc %g1,1,%g1
  45. ! Got carry from n. Subtract next step to cancel this carry.
  46. bne 4b
  47. addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb
  48. sub %i0,%o3,%i0
  49. 3: xnor %o1,0,%o1
  50. ! End of inline udiv_qrnnd
  51. b .LL45
  52. mov 0,%o2
  53. .LL41:
  54. cmp %o3,0
  55. bne .LL77
  56. mov %i0,%o2
  57. mov 1,%o0
  58. mov 0,%o1
  59. wr %g0, 0, %y
  60. udiv %o0, %o1, %o0
  61. mov %o0,%o3
  62. mov %i0,%o2
  63. .LL77:
  64. mov 0,%o4
  65. ! Inlined udiv_qrnnd
  66. mov 32,%g1
  67. subcc %o4,%o3,%g0
  68. 1: bcs 5f
  69. addxcc %o2,%o2,%o2 ! shift n1n0 and a q-bit in lsb
  70. sub %o4,%o3,%o4 ! this kills msb of n
  71. addx %o4,%o4,%o4 ! so this cannot give carry
  72. subcc %g1,1,%g1
  73. 2: bne 1b
  74. subcc %o4,%o3,%g0
  75. bcs 3f
  76. addxcc %o2,%o2,%o2 ! shift n1n0 and a q-bit in lsb
  77. b 3f
  78. sub %o4,%o3,%o4 ! this kills msb of n
  79. 4: sub %o4,%o3,%o4
  80. 5: addxcc %o4,%o4,%o4
  81. bcc 2b
  82. subcc %g1,1,%g1
  83. ! Got carry from n. Subtract next step to cancel this carry.
  84. bne 4b
  85. addcc %o2,%o2,%o2 ! shift n1n0 and a 0-bit in lsb
  86. sub %o4,%o3,%o4
  87. 3: xnor %o2,0,%o2
  88. ! End of inline udiv_qrnnd
  89. mov %o4,%i0
  90. mov %i3,%o1
  91. ! Inlined udiv_qrnnd
  92. mov 32,%g1
  93. subcc %i0,%o3,%g0
  94. 1: bcs 5f
  95. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  96. sub %i0,%o3,%i0 ! this kills msb of n
  97. addx %i0,%i0,%i0 ! so this cannot give carry
  98. subcc %g1,1,%g1
  99. 2: bne 1b
  100. subcc %i0,%o3,%g0
  101. bcs 3f
  102. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  103. b 3f
  104. sub %i0,%o3,%i0 ! this kills msb of n
  105. 4: sub %i0,%o3,%i0
  106. 5: addxcc %i0,%i0,%i0
  107. bcc 2b
  108. subcc %g1,1,%g1
  109. ! Got carry from n. Subtract next step to cancel this carry.
  110. bne 4b
  111. addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb
  112. sub %i0,%o3,%i0
  113. 3: xnor %o1,0,%o1
  114. ! End of inline udiv_qrnnd
  115. b .LL78
  116. mov %o1,%l1
  117. .LL40:
  118. cmp %i2,%i0
  119. bleu .LL46
  120. sethi %hi(65535),%o0
  121. b .LL73
  122. mov 0,%o1
  123. .LL46:
  124. or %o0,%lo(65535),%o0
  125. cmp %i2,%o0
  126. bgu .LL53
  127. mov %i2,%o1
  128. cmp %i2,256
  129. addx %g0,-1,%o0
  130. b .LL59
  131. and %o0,8,%o2
  132. .LL53:
  133. sethi %hi(16777215),%o0
  134. or %o0,%lo(16777215),%o0
  135. cmp %o1,%o0
  136. bgu .LL59
  137. mov 24,%o2
  138. mov 16,%o2
  139. .LL59:
  140. srl %o1,%o2,%o1
  141. sethi %hi(__clz_tab),%o0
  142. or %o0,%lo(__clz_tab),%o0
  143. ldub [%o1+%o0],%o0
  144. add %o0,%o2,%o0
  145. mov 32,%o1
  146. subcc %o1,%o0,%o2
  147. bne,a .LL67
  148. mov 32,%o0
  149. cmp %i0,%i2
  150. bgu .LL69
  151. cmp %i3,%o3
  152. blu .LL73
  153. mov 0,%o1
  154. .LL69:
  155. b .LL73
  156. mov 1,%o1
  157. .LL67:
  158. sub %o0,%o2,%o0
  159. sll %i2,%o2,%i2
  160. srl %o3,%o0,%o1
  161. or %i2,%o1,%i2
  162. sll %o3,%o2,%o3
  163. srl %i0,%o0,%o1
  164. sll %i0,%o2,%i0
  165. srl %i3,%o0,%o0
  166. or %i0,%o0,%i0
  167. sll %i3,%o2,%i3
  168. mov %i0,%o5
  169. mov %o1,%o4
  170. ! Inlined udiv_qrnnd
  171. mov 32,%g1
  172. subcc %o4,%i2,%g0
  173. 1: bcs 5f
  174. addxcc %o5,%o5,%o5 ! shift n1n0 and a q-bit in lsb
  175. sub %o4,%i2,%o4 ! this kills msb of n
  176. addx %o4,%o4,%o4 ! so this cannot give carry
  177. subcc %g1,1,%g1
  178. 2: bne 1b
  179. subcc %o4,%i2,%g0
  180. bcs 3f
  181. addxcc %o5,%o5,%o5 ! shift n1n0 and a q-bit in lsb
  182. b 3f
  183. sub %o4,%i2,%o4 ! this kills msb of n
  184. 4: sub %o4,%i2,%o4
  185. 5: addxcc %o4,%o4,%o4
  186. bcc 2b
  187. subcc %g1,1,%g1
  188. ! Got carry from n. Subtract next step to cancel this carry.
  189. bne 4b
  190. addcc %o5,%o5,%o5 ! shift n1n0 and a 0-bit in lsb
  191. sub %o4,%i2,%o4
  192. 3: xnor %o5,0,%o5
  193. ! End of inline udiv_qrnnd
  194. mov %o4,%i0
  195. mov %o5,%o1
  196. ! Inlined umul_ppmm
  197. wr %g0,%o1,%y ! SPARC has 0-3 delay insn after a wr
  198. sra %o3,31,%g2 ! Do not move this insn
  199. and %o1,%g2,%g2 ! Do not move this insn
  200. andcc %g0,0,%g1 ! Do not move this insn
  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,%o3,%g1
  224. mulscc %g1,%o3,%g1
  225. mulscc %g1,%o3,%g1
  226. mulscc %g1,%o3,%g1
  227. mulscc %g1,%o3,%g1
  228. mulscc %g1,%o3,%g1
  229. mulscc %g1,%o3,%g1
  230. mulscc %g1,%o3,%g1
  231. mulscc %g1,%o3,%g1
  232. mulscc %g1,%o3,%g1
  233. mulscc %g1,0,%g1
  234. add %g1,%g2,%o0
  235. rd %y,%o2
  236. cmp %o0,%i0
  237. bgu,a .LL73
  238. add %o1,-1,%o1
  239. bne,a .LL45
  240. mov 0,%o2
  241. cmp %o2,%i3
  242. bleu .LL45
  243. mov 0,%o2
  244. add %o1,-1,%o1
  245. .LL73:
  246. mov 0,%o2
  247. .LL45:
  248. mov %o1,%l1
  249. .LL78:
  250. mov %o2,%l0
  251. mov %l0,%i0
  252. mov %l1,%i1
  253. ret
  254. restore