divdi.s 888 B

12345678910111213141516171819202122232425262728293031323334353637
  1. |divdi3 routine copyright (C) 2002, Kevin Kofler
  2. |WARNING: Division by 0 will be handled the same way as in the unsigned variant.
  3. | For my __udivdi3, this means:
  4. | A division by 0 will not cause an exception, but just crash in an
  5. | infinite loop!
  6. |ANOTHER WARNING: This will ONLY work with an __udivdi3 which does NOT destroy a1!
  7. | Mine works of course.
  8. .xdef __divdi3
  9. .text
  10. __divdi3:
  11. tst.b 4(%a7)
  12. blt.s .L__divdi3_numer_negative
  13. tst.b 12(%a7)
  14. blt.s .L__divdi3_denom_negative
  15. .L__divdi3_udivdi3:
  16. jbra __udivdi3
  17. .L__divdi3_numer_negative:
  18. neg.l 8(%a7)
  19. negx.l 4(%a7)
  20. tst.b 12(%a7)
  21. bge.s .L__divdi3_denom_positive
  22. neg.l 16(%a7)
  23. negx.l 12(%a7)
  24. bra.s .L__divdi3_udivdi3
  25. .L__divdi3_denom_negative:
  26. neg.l 16(%a7)
  27. negx.l 12(%a7)
  28. .L__divdi3_denom_positive:
  29. move.l (%a7)+,%a1
  30. bsr.s .L__divdi3_udivdi3
  31. neg.l %d1
  32. negx.l %d0
  33. jmp (%a1)