divdi3.S 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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 __divdi3
  18. __divdi3:
  19. save %sp,-104,%sp
  20. cmp %i0,0
  21. bge .LL40
  22. mov 0,%l4
  23. mov -1,%l4
  24. sub %g0,%i1,%o0
  25. mov %o0,%o5
  26. subcc %g0,%o0,%g0
  27. sub %g0,%i0,%o0
  28. subx %o0,0,%o4
  29. mov %o4,%i0
  30. mov %o5,%i1
  31. .LL40:
  32. cmp %i2,0
  33. bge .LL84
  34. mov %i3,%o4
  35. xnor %g0,%l4,%l4
  36. sub %g0,%i3,%o0
  37. mov %o0,%o3
  38. subcc %g0,%o0,%g0
  39. sub %g0,%i2,%o0
  40. subx %o0,0,%o2
  41. mov %o2,%i2
  42. mov %o3,%i3
  43. mov %i3,%o4
  44. .LL84:
  45. cmp %i2,0
  46. bne .LL45
  47. mov %i1,%i3
  48. cmp %o4,%i0
  49. bleu .LL46
  50. mov %i3,%o1
  51. mov 32,%g1
  52. subcc %i0,%o4,%g0
  53. 1: bcs 5f
  54. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  55. sub %i0,%o4,%i0 ! this kills msb of n
  56. addx %i0,%i0,%i0 ! so this cannot give carry
  57. subcc %g1,1,%g1
  58. 2: bne 1b
  59. subcc %i0,%o4,%g0
  60. bcs 3f
  61. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  62. b 3f
  63. sub %i0,%o4,%i0 ! this kills msb of n
  64. 4: sub %i0,%o4,%i0
  65. 5: addxcc %i0,%i0,%i0
  66. bcc 2b
  67. subcc %g1,1,%g1
  68. ! Got carry from n. Subtract next step to cancel this carry.
  69. bne 4b
  70. addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb
  71. sub %i0,%o4,%i0
  72. 3: xnor %o1,0,%o1
  73. b .LL50
  74. mov 0,%o2
  75. .LL46:
  76. cmp %o4,0
  77. bne .LL85
  78. mov %i0,%o2
  79. mov 1,%o0
  80. mov 0,%o1
  81. wr %g0, 0, %y
  82. udiv %o0, %o1, %o0
  83. mov %o0,%o4
  84. mov %i0,%o2
  85. .LL85:
  86. mov 0,%g3
  87. mov 32,%g1
  88. subcc %g3,%o4,%g0
  89. 1: bcs 5f
  90. addxcc %o2,%o2,%o2 ! shift n1n0 and a q-bit in lsb
  91. sub %g3,%o4,%g3 ! this kills msb of n
  92. addx %g3,%g3,%g3 ! so this cannot give carry
  93. subcc %g1,1,%g1
  94. 2: bne 1b
  95. subcc %g3,%o4,%g0
  96. bcs 3f
  97. addxcc %o2,%o2,%o2 ! shift n1n0 and a q-bit in lsb
  98. b 3f
  99. sub %g3,%o4,%g3 ! this kills msb of n
  100. 4: sub %g3,%o4,%g3
  101. 5: addxcc %g3,%g3,%g3
  102. bcc 2b
  103. subcc %g1,1,%g1
  104. ! Got carry from n. Subtract next step to cancel this carry.
  105. bne 4b
  106. addcc %o2,%o2,%o2 ! shift n1n0 and a 0-bit in lsb
  107. sub %g3,%o4,%g3
  108. 3: xnor %o2,0,%o2
  109. mov %g3,%i0
  110. mov %i3,%o1
  111. mov 32,%g1
  112. subcc %i0,%o4,%g0
  113. 1: bcs 5f
  114. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  115. sub %i0,%o4,%i0 ! this kills msb of n
  116. addx %i0,%i0,%i0 ! so this cannot give carry
  117. subcc %g1,1,%g1
  118. 2: bne 1b
  119. subcc %i0,%o4,%g0
  120. bcs 3f
  121. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  122. b 3f
  123. sub %i0,%o4,%i0 ! this kills msb of n
  124. 4: sub %i0,%o4,%i0
  125. 5: addxcc %i0,%i0,%i0
  126. bcc 2b
  127. subcc %g1,1,%g1
  128. ! Got carry from n. Subtract next step to cancel this carry.
  129. bne 4b
  130. addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb
  131. sub %i0,%o4,%i0
  132. 3: xnor %o1,0,%o1
  133. b .LL86
  134. mov %o1,%l1
  135. .LL45:
  136. cmp %i2,%i0
  137. bleu .LL51
  138. sethi %hi(65535),%o0
  139. b .LL78
  140. mov 0,%o1
  141. .LL51:
  142. or %o0,%lo(65535),%o0
  143. cmp %i2,%o0
  144. bgu .LL58
  145. mov %i2,%o1
  146. cmp %i2,256
  147. addx %g0,-1,%o0
  148. b .LL64
  149. and %o0,8,%o2
  150. .LL58:
  151. sethi %hi(16777215),%o0
  152. or %o0,%lo(16777215),%o0
  153. cmp %i2,%o0
  154. bgu .LL64
  155. mov 24,%o2
  156. mov 16,%o2
  157. .LL64:
  158. srl %o1,%o2,%o0
  159. sethi %hi(__clz_tab),%o1
  160. or %o1,%lo(__clz_tab),%o1
  161. ldub [%o0+%o1],%o0
  162. add %o0,%o2,%o0
  163. mov 32,%o1
  164. subcc %o1,%o0,%o3
  165. bne,a .LL72
  166. sub %o1,%o3,%o1
  167. cmp %i0,%i2
  168. bgu .LL74
  169. cmp %i3,%o4
  170. blu .LL78
  171. mov 0,%o1
  172. .LL74:
  173. b .LL78
  174. mov 1,%o1
  175. .LL72:
  176. sll %i2,%o3,%o2
  177. srl %o4,%o1,%o0
  178. or %o2,%o0,%i2
  179. sll %o4,%o3,%o4
  180. srl %i0,%o1,%o2
  181. sll %i0,%o3,%o0
  182. srl %i3,%o1,%o1
  183. or %o0,%o1,%i0
  184. sll %i3,%o3,%i3
  185. mov %i0,%o1
  186. mov 32,%g1
  187. subcc %o2,%i2,%g0
  188. 1: bcs 5f
  189. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  190. sub %o2,%i2,%o2 ! this kills msb of n
  191. addx %o2,%o2,%o2 ! so this cannot give carry
  192. subcc %g1,1,%g1
  193. 2: bne 1b
  194. subcc %o2,%i2,%g0
  195. bcs 3f
  196. addxcc %o1,%o1,%o1 ! shift n1n0 and a q-bit in lsb
  197. b 3f
  198. sub %o2,%i2,%o2 ! this kills msb of n
  199. 4: sub %o2,%i2,%o2
  200. 5: addxcc %o2,%o2,%o2
  201. bcc 2b
  202. subcc %g1,1,%g1
  203. ! Got carry from n. Subtract next step to cancel this carry.
  204. bne 4b
  205. addcc %o1,%o1,%o1 ! shift n1n0 and a 0-bit in lsb
  206. sub %o2,%i2,%o2
  207. 3: xnor %o1,0,%o1
  208. mov %o2,%i0
  209. wr %g0,%o1,%y ! SPARC has 0-3 delay insn after a wr
  210. sra %o4,31,%g2 ! Do not move this insn
  211. and %o1,%g2,%g2 ! Do not move this insn
  212. andcc %g0,0,%g1 ! Do not move this insn
  213. mulscc %g1,%o4,%g1
  214. mulscc %g1,%o4,%g1
  215. mulscc %g1,%o4,%g1
  216. mulscc %g1,%o4,%g1
  217. mulscc %g1,%o4,%g1
  218. mulscc %g1,%o4,%g1
  219. mulscc %g1,%o4,%g1
  220. mulscc %g1,%o4,%g1
  221. mulscc %g1,%o4,%g1
  222. mulscc %g1,%o4,%g1
  223. mulscc %g1,%o4,%g1
  224. mulscc %g1,%o4,%g1
  225. mulscc %g1,%o4,%g1
  226. mulscc %g1,%o4,%g1
  227. mulscc %g1,%o4,%g1
  228. mulscc %g1,%o4,%g1
  229. mulscc %g1,%o4,%g1
  230. mulscc %g1,%o4,%g1
  231. mulscc %g1,%o4,%g1
  232. mulscc %g1,%o4,%g1
  233. mulscc %g1,%o4,%g1
  234. mulscc %g1,%o4,%g1
  235. mulscc %g1,%o4,%g1
  236. mulscc %g1,%o4,%g1
  237. mulscc %g1,%o4,%g1
  238. mulscc %g1,%o4,%g1
  239. mulscc %g1,%o4,%g1
  240. mulscc %g1,%o4,%g1
  241. mulscc %g1,%o4,%g1
  242. mulscc %g1,%o4,%g1
  243. mulscc %g1,%o4,%g1
  244. mulscc %g1,%o4,%g1
  245. mulscc %g1,0,%g1
  246. add %g1,%g2,%o0
  247. rd %y,%o2
  248. cmp %o0,%i0
  249. bgu,a .LL78
  250. add %o1,-1,%o1
  251. bne,a .LL50
  252. mov 0,%o2
  253. cmp %o2,%i3
  254. bleu .LL50
  255. mov 0,%o2
  256. add %o1,-1,%o1
  257. .LL78:
  258. mov 0,%o2
  259. .LL50:
  260. mov %o1,%l1
  261. .LL86:
  262. mov %o2,%l0
  263. mov %l0,%i0
  264. mov %l1,%i1
  265. cmp %l4,0
  266. be .LL81
  267. sub %g0,%i1,%o0
  268. mov %o0,%l3
  269. subcc %g0,%o0,%g0
  270. sub %g0,%i0,%o0
  271. subx %o0,0,%l2
  272. mov %l2,%i0
  273. mov %l3,%i1
  274. .LL81:
  275. ret
  276. restore