uldiv.S 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. //------------------------------------------------------------------------------
  2. //
  3. // Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
  4. //
  5. // This program and the accompanying materials
  6. // are licensed and made available under the terms and conditions of the BSD License
  7. // which accompanies this distribution. The full text of the license may be found at
  8. // http://opensource.org/licenses/bsd-license.php
  9. //
  10. // THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
  12. //
  13. //------------------------------------------------------------------------------
  14. #include "edk2asm.h"
  15. .text
  16. .align 2
  17. GCC_ASM_EXPORT(__aeabi_uldivmod)
  18. //
  19. //UINT64
  20. //EFIAPI
  21. //__aeabi_uldivmod (
  22. // IN UINT64 Dividend
  23. // IN UINT64 Divisor
  24. // )
  25. //
  26. ASM_PFX(__aeabi_uldivmod):
  27. stmdb sp!, {r4, r5, r6, lr}
  28. mov r4, r1
  29. mov r5, r0
  30. mov r6, #0 // 0x0
  31. orrs ip, r3, r2, lsr #31
  32. bne ASM_PFX(__aeabi_uldivmod_label1)
  33. tst r2, r2
  34. beq ASM_PFX(_ll_div0)
  35. movs ip, r2, lsr #15
  36. addeq r6, r6, #16 // 0x10
  37. mov ip, r2, lsl r6
  38. movs lr, ip, lsr #23
  39. moveq ip, ip, lsl #8
  40. addeq r6, r6, #8 // 0x8
  41. movs lr, ip, lsr #27
  42. moveq ip, ip, lsl #4
  43. addeq r6, r6, #4 // 0x4
  44. movs lr, ip, lsr #29
  45. moveq ip, ip, lsl #2
  46. addeq r6, r6, #2 // 0x2
  47. movs lr, ip, lsr #30
  48. moveq ip, ip, lsl #1
  49. addeq r6, r6, #1 // 0x1
  50. b ASM_PFX(_ll_udiv_small)
  51. ASM_PFX(__aeabi_uldivmod_label1):
  52. tst r3, #-2147483648 // 0x80000000
  53. bne ASM_PFX(__aeabi_uldivmod_label2)
  54. movs ip, r3, lsr #15
  55. addeq r6, r6, #16 // 0x10
  56. mov ip, r3, lsl r6
  57. movs lr, ip, lsr #23
  58. moveq ip, ip, lsl #8
  59. addeq r6, r6, #8 // 0x8
  60. movs lr, ip, lsr #27
  61. moveq ip, ip, lsl #4
  62. addeq r6, r6, #4 // 0x4
  63. movs lr, ip, lsr #29
  64. moveq ip, ip, lsl #2
  65. addeq r6, r6, #2 // 0x2
  66. movs lr, ip, lsr #30
  67. addeq r6, r6, #1 // 0x1
  68. rsb r3, r6, #32 // 0x20
  69. moveq ip, ip, lsl #1
  70. orr ip, ip, r2, lsr r3
  71. mov lr, r2, lsl r6
  72. b ASM_PFX(_ll_udiv_big)
  73. ASM_PFX(__aeabi_uldivmod_label2):
  74. mov ip, r3
  75. mov lr, r2
  76. b ASM_PFX(_ll_udiv_ginormous)
  77. ASM_PFX(_ll_udiv_small):
  78. cmp r4, ip, lsl #1
  79. mov r3, #0 // 0x0
  80. subcs r4, r4, ip, lsl #1
  81. addcs r3, r3, #2 // 0x2
  82. cmp r4, ip
  83. subcs r4, r4, ip
  84. adcs r3, r3, #0 // 0x0
  85. add r2, r6, #32 // 0x20
  86. cmp r2, #32 // 0x20
  87. rsb ip, ip, #0 // 0x0
  88. bcc ASM_PFX(_ll_udiv_small_label1)
  89. orrs r0, r4, r5, lsr #30
  90. moveq r4, r5
  91. moveq r5, #0 // 0x0
  92. subeq r2, r2, #32 // 0x20
  93. ASM_PFX(_ll_udiv_small_label1):
  94. mov r1, #0 // 0x0
  95. cmp r2, #16 // 0x10
  96. bcc ASM_PFX(_ll_udiv_small_label2)
  97. movs r0, r4, lsr #14
  98. moveq r4, r4, lsl #16
  99. addeq r1, r1, #16 // 0x10
  100. ASM_PFX(_ll_udiv_small_label2):
  101. sub lr, r2, r1
  102. cmp lr, #8 // 0x8
  103. bcc ASM_PFX(_ll_udiv_small_label3)
  104. movs r0, r4, lsr #22
  105. moveq r4, r4, lsl #8
  106. addeq r1, r1, #8 // 0x8
  107. ASM_PFX(_ll_udiv_small_label3):
  108. rsb r0, r1, #32 // 0x20
  109. sub r2, r2, r1
  110. orr r4, r4, r5, lsr r0
  111. mov r5, r5, lsl r1
  112. cmp r2, #1 // 0x1
  113. bcc ASM_PFX(_ll_udiv_small_label5)
  114. sub r2, r2, #1 // 0x1
  115. and r0, r2, #7 // 0x7
  116. eor r0, r0, #7 // 0x7
  117. adds r0, r0, r0, lsl #1
  118. add pc, pc, r0, lsl #2
  119. nop // (mov r0,r0)
  120. ASM_PFX(_ll_udiv_small_label4):
  121. adcs r5, r5, r5
  122. adcs r4, ip, r4, lsl #1
  123. rsbcc r4, ip, r4
  124. adcs r5, r5, r5
  125. adcs r4, ip, r4, lsl #1
  126. rsbcc r4, ip, r4
  127. adcs r5, r5, r5
  128. adcs r4, ip, r4, lsl #1
  129. rsbcc r4, ip, r4
  130. adcs r5, r5, r5
  131. adcs r4, ip, r4, lsl #1
  132. rsbcc r4, ip, r4
  133. adcs r5, r5, r5
  134. adcs r4, ip, r4, lsl #1
  135. rsbcc r4, ip, r4
  136. adcs r5, r5, r5
  137. adcs r4, ip, r4, lsl #1
  138. rsbcc r4, ip, r4
  139. adcs r5, r5, r5
  140. adcs r4, ip, r4, lsl #1
  141. rsbcc r4, ip, r4
  142. adcs r5, r5, r5
  143. adcs r4, ip, r4, lsl #1
  144. sub r2, r2, #8 // 0x8
  145. tst r2, r2
  146. rsbcc r4, ip, r4
  147. bpl ASM_PFX(_ll_udiv_small_label4)
  148. ASM_PFX(_ll_udiv_small_label5):
  149. mov r2, r4, lsr r6
  150. bic r4, r4, r2, lsl r6
  151. adcs r0, r5, r5
  152. adc r1, r4, r4
  153. add r1, r1, r3, lsl r6
  154. mov r3, #0 // 0x0
  155. ldmia sp!, {r4, r5, r6, pc}
  156. ASM_PFX(_ll_udiv_big):
  157. subs r0, r5, lr
  158. mov r3, #0 // 0x0
  159. sbcs r1, r4, ip
  160. movcs r5, r0
  161. movcs r4, r1
  162. adcs r3, r3, #0 // 0x0
  163. subs r0, r5, lr
  164. sbcs r1, r4, ip
  165. movcs r5, r0
  166. movcs r4, r1
  167. adcs r3, r3, #0 // 0x0
  168. subs r0, r5, lr
  169. sbcs r1, r4, ip
  170. movcs r5, r0
  171. movcs r4, r1
  172. adcs r3, r3, #0 // 0x0
  173. mov r1, #0 // 0x0
  174. rsbs lr, lr, #0 // 0x0
  175. rsc ip, ip, #0 // 0x0
  176. cmp r6, #16 // 0x10
  177. bcc ASM_PFX(_ll_udiv_big_label1)
  178. movs r0, r4, lsr #14
  179. moveq r4, r4, lsl #16
  180. addeq r1, r1, #16 // 0x10
  181. ASM_PFX(_ll_udiv_big_label1):
  182. sub r2, r6, r1
  183. cmp r2, #8 // 0x8
  184. bcc ASM_PFX(_ll_udiv_big_label2)
  185. movs r0, r4, lsr #22
  186. moveq r4, r4, lsl #8
  187. addeq r1, r1, #8 // 0x8
  188. ASM_PFX(_ll_udiv_big_label2):
  189. rsb r0, r1, #32 // 0x20
  190. sub r2, r6, r1
  191. orr r4, r4, r5, lsr r0
  192. mov r5, r5, lsl r1
  193. cmp r2, #1 // 0x1
  194. bcc ASM_PFX(_ll_udiv_big_label4)
  195. sub r2, r2, #1 // 0x1
  196. and r0, r2, #3 // 0x3
  197. rsb r0, r0, #3 // 0x3
  198. adds r0, r0, r0, lsl #1
  199. add pc, pc, r0, lsl #3
  200. nop // (mov r0,r0)
  201. ASM_PFX(_ll_udiv_big_label3):
  202. adcs r5, r5, r5
  203. adcs r4, r4, r4
  204. adcs r0, lr, r5
  205. adcs r1, ip, r4
  206. movcs r5, r0
  207. movcs r4, r1
  208. adcs r5, r5, r5
  209. adcs r4, r4, r4
  210. adcs r0, lr, r5
  211. adcs r1, ip, r4
  212. movcs r5, r0
  213. movcs r4, r1
  214. adcs r5, r5, r5
  215. adcs r4, r4, r4
  216. adcs r0, lr, r5
  217. adcs r1, ip, r4
  218. movcs r5, r0
  219. movcs r4, r1
  220. sub r2, r2, #4 // 0x4
  221. adcs r5, r5, r5
  222. adcs r4, r4, r4
  223. adcs r0, lr, r5
  224. adcs r1, ip, r4
  225. tst r2, r2
  226. movcs r5, r0
  227. movcs r4, r1
  228. bpl ASM_PFX(_ll_udiv_big_label3)
  229. ASM_PFX(_ll_udiv_big_label4):
  230. mov r1, #0 // 0x0
  231. mov r2, r5, lsr r6
  232. bic r5, r5, r2, lsl r6
  233. adcs r0, r5, r5
  234. adc r1, r1, #0 // 0x0
  235. movs lr, r3, lsl r6
  236. mov r3, r4, lsr r6
  237. bic r4, r4, r3, lsl r6
  238. adc r1, r1, #0 // 0x0
  239. adds r0, r0, lr
  240. orr r2, r2, r4, ror r6
  241. adc r1, r1, #0 // 0x0
  242. ldmia sp!, {r4, r5, r6, pc}
  243. ASM_PFX(_ll_udiv_ginormous):
  244. subs r2, r5, lr
  245. mov r1, #0 // 0x0
  246. sbcs r3, r4, ip
  247. adc r0, r1, r1
  248. movcc r2, r5
  249. movcc r3, r4
  250. ldmia sp!, {r4, r5, r6, pc}
  251. ASM_PFX(_ll_div0):
  252. ldmia sp!, {r4, r5, r6, lr}
  253. mov r0, #0 // 0x0
  254. mov r1, #0 // 0x0
  255. b ASM_PFX(__aeabi_ldiv0)
  256. ASM_PFX(__aeabi_ldiv0):
  257. bx r14
  258. #if defined(__ELF__) && defined(__linux__)
  259. .section .note.GNU-stack,"",%progbits
  260. #endif