ARM application development SDK for MNT ZZ9000 graphics and coprocessor card for classic Amiga computers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

moddi3.S 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Runtime ABI for the ARM Cortex-M0
  2. * ldivmod.S: signed 64 bit division (only remainder)
  3. *
  4. * Copyright (c) 2012 Jörg Mische <bobbl@gmx.de>
  5. *
  6. * Permission to use, copy, modify, and/or distribute this software for any
  7. * purpose with or without fee is hereby granted, provided that the above
  8. * copyright notice and this permission notice appear in all copies.
  9. *
  10. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  11. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  12. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  13. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  14. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  15. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  16. * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  17. */
  18. .syntax unified
  19. .text
  20. .thumb
  21. .cpu cortex-m0
  22. @ long long __moddi3(long long numerator, long long denominator)
  23. @
  24. @ Divide r1:r0 by r3:r2 and return the remainder in r1:r0 (all signed)
  25. @ Special case of __aeabi_ldivmod() that is a lot simpler and moves the
  26. @ remainder to r1:r0.
  27. @
  28. .thumb_func
  29. .global __moddi3
  30. __moddi3:
  31. push {r4, lr}
  32. cmp r3, #0
  33. bge L_dont_neg_den
  34. movs r4, #0 @ den = -den
  35. rsbs r2, r2, #0
  36. sbcs r4, r3
  37. mov r3, r4
  38. L_dont_neg_den:
  39. cmp r1, #0
  40. bge L_pos_result
  41. movs r4, #0 @ num = -num
  42. rsbs r0, r0, #0
  43. sbcs r4, r1
  44. mov r1, r4
  45. bl __aeabi_uldivmod
  46. movs r0, #0 @ rem = -rem
  47. movs r1, #0
  48. subs r0, r2
  49. sbcs r1, r3
  50. pop {r4, pc}
  51. L_pos_result:
  52. bl __aeabi_uldivmod
  53. mov r1, r3
  54. mov r0, r2
  55. pop {r4, pc}