divdi3.S 5.6 KB

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