aeabi_uidivmod.S 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. //===-- aeabi_uidivmod.S - EABI uidivmod implementation -------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #include "../assembly.h"
  9. // struct { unsigned quot, unsigned rem}
  10. // __aeabi_uidivmod(unsigned numerator, unsigned denominator) {
  11. // unsigned rem, quot;
  12. // quot = __udivmodsi4(numerator, denominator, &rem);
  13. // return {quot, rem};
  14. // }
  15. #if defined(__MINGW32__)
  16. #define __aeabi_uidivmod __rt_udiv
  17. #endif
  18. .syntax unified
  19. .text
  20. DEFINE_CODE_STATE
  21. .p2align 2
  22. DEFINE_COMPILERRT_FUNCTION(__aeabi_uidivmod)
  23. #if defined(USE_THUMB_1)
  24. cmp r0, r1
  25. bcc LOCAL_LABEL(case_denom_larger)
  26. push {r0, r1, lr}
  27. bl SYMBOL_NAME(__aeabi_uidiv)
  28. pop {r1, r2, r3}
  29. muls r2, r0, r2 // r2 = quot * denom
  30. subs r1, r1, r2
  31. JMP (r3)
  32. LOCAL_LABEL(case_denom_larger):
  33. movs r1, r0
  34. movs r0, #0
  35. JMP (lr)
  36. #else // defined(USE_THUMB_1)
  37. push { lr }
  38. sub sp, sp, #4
  39. mov r2, sp
  40. #if defined(__MINGW32__)
  41. mov r3, r0
  42. mov r0, r1
  43. mov r1, r3
  44. #endif
  45. bl SYMBOL_NAME(__udivmodsi4)
  46. ldr r1, [sp]
  47. add sp, sp, #4
  48. pop { pc }
  49. #endif
  50. END_COMPILERRT_FUNCTION(__aeabi_uidivmod)
  51. NO_EXEC_STACK_DIRECTIVE