div.S 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. #------------------------------------------------------------------------------
  2. #
  3. # Copyright (c) 2011, ARM. 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_uidiv)
  18. GCC_ASM_EXPORT(__aeabi_uidivmod)
  19. GCC_ASM_EXPORT(__aeabi_idiv)
  20. GCC_ASM_EXPORT(__aeabi_idivmod)
  21. # AREA Math, CODE, READONLY
  22. #
  23. #UINT32
  24. #EFIAPI
  25. #__aeabi_uidivmode (
  26. # IN UINT32 Dividen
  27. # IN UINT32 Divisor
  28. # );
  29. #
  30. ASM_PFX(__aeabi_uidiv):
  31. ASM_PFX(__aeabi_uidivmod):
  32. rsbs r12, r1, r0, LSR #4
  33. mov r2, #0
  34. bcc ASM_PFX(__arm_div4)
  35. rsbs r12, r1, r0, LSR #8
  36. bcc ASM_PFX(__arm_div8)
  37. mov r3, #0
  38. b ASM_PFX(__arm_div_large)
  39. #
  40. #INT32
  41. #EFIAPI
  42. #__aeabi_idivmode (
  43. # IN INT32 Dividen
  44. # IN INT32 Divisor
  45. # );
  46. #
  47. ASM_PFX(__aeabi_idiv):
  48. ASM_PFX(__aeabi_idivmod):
  49. orrs r12, r0, r1
  50. bmi ASM_PFX(__arm_div_negative)
  51. rsbs r12, r1, r0, LSR #1
  52. mov r2, #0
  53. bcc ASM_PFX(__arm_div1)
  54. rsbs r12, r1, r0, LSR #4
  55. bcc ASM_PFX(__arm_div4)
  56. rsbs r12, r1, r0, LSR #8
  57. bcc ASM_PFX(__arm_div8)
  58. mov r3, #0
  59. b ASM_PFX(__arm_div_large)
  60. ASM_PFX(__arm_div8):
  61. rsbs r12, r1, r0, LSR #7
  62. subcs r0, r0, r1, LSL #7
  63. adc r2, r2, r2
  64. rsbs r12, r1, r0,LSR #6
  65. subcs r0, r0, r1, LSL #6
  66. adc r2, r2, r2
  67. rsbs r12, r1, r0, LSR #5
  68. subcs r0, r0, r1, LSL #5
  69. adc r2, r2, r2
  70. rsbs r12, r1, r0, LSR #4
  71. subcs r0, r0, r1, LSL #4
  72. adc r2, r2, r2
  73. ASM_PFX(__arm_div4):
  74. rsbs r12, r1, r0, LSR #3
  75. subcs r0, r0, r1, LSL #3
  76. adc r2, r2, r2
  77. rsbs r12, r1, r0, LSR #2
  78. subcs r0, r0, r1, LSL #2
  79. adcs r2, r2, r2
  80. rsbs r12, r1, r0, LSR #1
  81. subcs r0, r0, r1, LSL #1
  82. adc r2, r2, r2
  83. ASM_PFX(__arm_div1):
  84. subs r1, r0, r1
  85. movcc r1, r0
  86. adc r0, r2, r2
  87. bx r14
  88. ASM_PFX(__arm_div_negative):
  89. ands r2, r1, #0x80000000
  90. rsbmi r1, r1, #0
  91. eors r3, r2, r0, ASR #32
  92. rsbcs r0, r0, #0
  93. rsbs r12, r1, r0, LSR #4
  94. bcc label1
  95. rsbs r12, r1, r0, LSR #8
  96. bcc label2
  97. ASM_PFX(__arm_div_large):
  98. lsl r1, r1, #6
  99. rsbs r12, r1, r0, LSR #8
  100. orr r2, r2, #0xfc000000
  101. bcc label2
  102. lsl r1, r1, #6
  103. rsbs r12, r1, r0, LSR #8
  104. orr r2, r2, #0x3f00000
  105. bcc label2
  106. lsl r1, r1, #6
  107. rsbs r12, r1, r0, LSR #8
  108. orr r2, r2, #0xfc000
  109. orrcs r2, r2, #0x3f00
  110. lslcs r1, r1, #6
  111. rsbs r12, r1, #0
  112. bcs ASM_PFX(__aeabi_idiv0)
  113. label3:
  114. lsrcs r1, r1, #6
  115. label2:
  116. rsbs r12, r1, r0, LSR #7
  117. subcs r0, r0, r1, LSL #7
  118. adc r2, r2, r2
  119. rsbs r12, r1, r0, LSR #6
  120. subcs r0, r0, r1, LSL #6
  121. adc r2, r2, r2
  122. rsbs r12, r1, r0, LSR #5
  123. subcs r0, r0, r1, LSL #5
  124. adc r2, r2, r2
  125. rsbs r12, r1, r0, LSR #4
  126. subcs r0, r0, r1, LSL #4
  127. adc r2, r2, r2
  128. label1:
  129. rsbs r12, r1, r0, LSR #3
  130. subcs r0, r0, r1, LSL #3
  131. adc r2, r2, r2
  132. rsbs r12, r1, r0, LSR #2
  133. subcs r0, r0, r1, LSL #2
  134. adcs r2, r2, r2
  135. bcs label3
  136. rsbs r12, r1, r0, LSR #1
  137. subcs r0, r0, r1, LSL #1
  138. adc r2, r2, r2
  139. subs r1, r0, r1
  140. movcc r1, r0
  141. adc r0, r2, r2
  142. asrs r3, r3, #31
  143. rsbmi r0, r0, #0
  144. rsbcs r1, r1, #0
  145. bx r14
  146. @ What to do about division by zero? For now, just return.
  147. ASM_PFX(__aeabi_idiv0):
  148. bx r14
  149. #if defined(__ELF__) && defined(__linux__)
  150. .section .note.GNU-stack,"",%progbits
  151. #endif