udivdi3.S 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. call .udiv,0
  59. mov 0,%o1
  60. mov %o0,%o3
  61. mov %i0,%o2
  62. .LL77:
  63. mov 0,%o4
  64. ! Inlined udiv_qrnnd
  65. mov 32,%g1
  66. subcc %o4,%o3,%g0
  67. 1: bcs 5f
  68. addxcc %o2,%o2,%o2 ! shift n1n0 and a q-bit in lsb
  69. sub %o4,%o3,%o4 ! this kills msb of n
  70. addx %o4,%o4,%o4 ! so this cannot give carry
  71. subcc %g1,1,%g1
  72. 2: bne 1b
  73. subcc %o4,%o3,%g0
  74. bcs 3f
  75. addxcc %o2,%o2,%o2 ! shift n1n0 and a q-bit in lsb
  76. b 3f
  77. sub %o4,%o3,%o4 ! this kills msb of n
  78. 4: sub %o4,%o3,%o4
  79. 5: addxcc %o4,%o4,%o4
  80. bcc 2b
  81. subcc %g1,1,%g1
  82. ! Got carry from n. Subtract next step to cancel this carry.
  83. bne 4b
  84. addcc %o2,%o2,%o2 ! shift n1n0 and a 0-bit in lsb
  85. sub %o4,%o3,%o4
  86. 3: xnor %o2,0,%o2
  87. ! End of inline udiv_qrnnd
  88. mov %o4,%i0
  89. mov %i3,%o1
  90. ! Inlined udiv_qrnnd
  91. mov 32,%g1
  92. subcc %i0,%o3,%g0
  93. 1: bcs 5f
  94. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  95. sub %i0,%o3,%i0 ! this kills msb of n
  96. addx %i0,%i0,%i0 ! so this cannot give carry
  97. subcc %g1,1,%g1
  98. 2: bne 1b
  99. subcc %i0,%o3,%g0
  100. bcs 3f
  101. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  102. b 3f
  103. sub %i0,%o3,%i0 ! this kills msb of n
  104. 4: sub %i0,%o3,%i0
  105. 5: addxcc %i0,%i0,%i0
  106. bcc 2b
  107. subcc %g1,1,%g1
  108. ! Got carry from n. Subtract next step to cancel this carry.
  109. bne 4b
  110. addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb
  111. sub %i0,%o3,%i0
  112. 3: xnor %o1,0,%o1
  113. ! End of inline udiv_qrnnd
  114. b .LL78
  115. mov %o1,%l1
  116. .LL40:
  117. cmp %i2,%i0
  118. bleu .LL46
  119. sethi %hi(65535),%o0
  120. b .LL73
  121. mov 0,%o1
  122. .LL46:
  123. or %o0,%lo(65535),%o0
  124. cmp %i2,%o0
  125. bgu .LL53
  126. mov %i2,%o1
  127. cmp %i2,256
  128. addx %g0,-1,%o0
  129. b .LL59
  130. and %o0,8,%o2
  131. .LL53:
  132. sethi %hi(16777215),%o0
  133. or %o0,%lo(16777215),%o0
  134. cmp %o1,%o0
  135. bgu .LL59
  136. mov 24,%o2
  137. mov 16,%o2
  138. .LL59:
  139. srl %o1,%o2,%o1
  140. sethi %hi(__clz_tab),%o0
  141. or %o0,%lo(__clz_tab),%o0
  142. ldub [%o1+%o0],%o0
  143. add %o0,%o2,%o0
  144. mov 32,%o1
  145. subcc %o1,%o0,%o2
  146. bne,a .LL67
  147. mov 32,%o0
  148. cmp %i0,%i2
  149. bgu .LL69
  150. cmp %i3,%o3
  151. blu .LL73
  152. mov 0,%o1
  153. .LL69:
  154. b .LL73
  155. mov 1,%o1
  156. .LL67:
  157. sub %o0,%o2,%o0
  158. sll %i2,%o2,%i2
  159. srl %o3,%o0,%o1
  160. or %i2,%o1,%i2
  161. sll %o3,%o2,%o3
  162. srl %i0,%o0,%o1
  163. sll %i0,%o2,%i0
  164. srl %i3,%o0,%o0
  165. or %i0,%o0,%i0
  166. sll %i3,%o2,%i3
  167. mov %i0,%o5
  168. mov %o1,%o4
  169. ! Inlined udiv_qrnnd
  170. mov 32,%g1
  171. subcc %o4,%i2,%g0
  172. 1: bcs 5f
  173. addxcc %o5,%o5,%o5 ! shift n1n0 and a q-bit in lsb
  174. sub %o4,%i2,%o4 ! this kills msb of n
  175. addx %o4,%o4,%o4 ! so this cannot give carry
  176. subcc %g1,1,%g1
  177. 2: bne 1b
  178. subcc %o4,%i2,%g0
  179. bcs 3f
  180. addxcc %o5,%o5,%o5 ! shift n1n0 and a q-bit in lsb
  181. b 3f
  182. sub %o4,%i2,%o4 ! this kills msb of n
  183. 4: sub %o4,%i2,%o4
  184. 5: addxcc %o4,%o4,%o4
  185. bcc 2b
  186. subcc %g1,1,%g1
  187. ! Got carry from n. Subtract next step to cancel this carry.
  188. bne 4b
  189. addcc %o5,%o5,%o5 ! shift n1n0 and a 0-bit in lsb
  190. sub %o4,%i2,%o4
  191. 3: xnor %o5,0,%o5
  192. ! End of inline udiv_qrnnd
  193. mov %o4,%i0
  194. mov %o5,%o1
  195. ! Inlined umul_ppmm
  196. wr %g0,%o1,%y ! SPARC has 0-3 delay insn after a wr
  197. sra %o3,31,%g2 ! Do not move this insn
  198. and %o1,%g2,%g2 ! Do not move this insn
  199. andcc %g0,0,%g1 ! Do not move this insn
  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,%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,0,%g1
  233. add %g1,%g2,%o0
  234. rd %y,%o2
  235. cmp %o0,%i0
  236. bgu,a .LL73
  237. add %o1,-1,%o1
  238. bne,a .LL45
  239. mov 0,%o2
  240. cmp %o2,%i3
  241. bleu .LL45
  242. mov 0,%o2
  243. add %o1,-1,%o1
  244. .LL73:
  245. mov 0,%o2
  246. .LL45:
  247. mov %o1,%l1
  248. .LL78:
  249. mov %o2,%l0
  250. mov %l0,%i0
  251. mov %l1,%i1
  252. ret
  253. restore