divdi3.S 5.0 KB

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