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.

modsi3.S 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Runtime ABI for the ARM Cortex-M0
  2. * idivmod.S: signed 32 bit division 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. @ int __modsi3(int numerator:r0, int denominator:r1)
  23. @
  24. @ Divide r0 by r1 and return the remainder in r0
  25. @ Special case of __aeabi_idivmod() that is a lot simpler and moves the
  26. @ remainder to r0.
  27. @
  28. .thumb_func
  29. .global __modsi3
  30. __modsi3:
  31. cmp r1, #0
  32. bge L_dont_neg_den
  33. rsbs r1, r1, #0 @ den = -den
  34. L_dont_neg_den:
  35. cmp r0, #0
  36. bge L_pos_result
  37. rsbs r0, r0, #0 @ num = -num
  38. push {lr}
  39. bl __aeabi_uidivmod
  40. rsbs r0, r1, #0 @ return -rem
  41. pop {pc}
  42. L_pos_result:
  43. push {lr}
  44. bl __aeabi_uidivmod
  45. movs r0, r1 @ return rem
  46. pop {pc}