aeabi_idivmod.S 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //===-- aeabi_idivmod.S - EABI idivmod 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 { int quot, int rem} __aeabi_idivmod(int numerator, int denominator) {
  10. // int rem, quot;
  11. // quot = __divmodsi4(numerator, denominator, &rem);
  12. // return {quot, rem};
  13. // }
  14. #if defined(__MINGW32__)
  15. #define __aeabi_idivmod __rt_sdiv
  16. #endif
  17. .syntax unified
  18. .text
  19. DEFINE_CODE_STATE
  20. .p2align 2
  21. DEFINE_COMPILERRT_FUNCTION(__aeabi_idivmod)
  22. #if defined(USE_THUMB_1)
  23. push {r0, r1, lr}
  24. bl SYMBOL_NAME(__divsi3)
  25. pop {r1, r2, r3} // now r0 = quot, r1 = num, r2 = denom
  26. muls r2, r0, r2 // r2 = quot * denom
  27. subs r1, r1, r2
  28. JMP (r3)
  29. #else // defined(USE_THUMB_1)
  30. push { lr }
  31. sub sp, sp, #4
  32. mov r2, sp
  33. #if defined(__MINGW32__)
  34. mov r3, r0
  35. mov r0, r1
  36. mov r1, r3
  37. #endif
  38. bl SYMBOL_NAME(__divmodsi4)
  39. ldr r1, [sp]
  40. add sp, sp, #4
  41. pop { pc }
  42. #endif // defined(USE_THUMB_1)
  43. END_COMPILERRT_FUNCTION(__aeabi_idivmod)
  44. NO_EXEC_STACK_DIRECTIVE