modsi3.S 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #include "libgcc.h"
  3. ; numerator in A0/A1
  4. ; denominator in A2/A3
  5. .global __modsi3
  6. __modsi3:
  7. PUSHP S2P
  8. bsr modnorm
  9. bsr __divsi3
  10. mov.l er3,er0
  11. bra exitdiv
  12. .global __umodsi3
  13. __umodsi3:
  14. bsr __udivsi3
  15. mov.l er3,er0
  16. rts
  17. .global __divsi3
  18. __divsi3:
  19. PUSHP S2P
  20. jsr divnorm
  21. bsr __udivsi3
  22. ; examine what the sign should be
  23. exitdiv:
  24. btst #3,S2L
  25. beq reti
  26. ; should be -ve
  27. neg.l A0P
  28. reti:
  29. POPP S2P
  30. rts
  31. divnorm:
  32. mov.l A0P,A0P ; is the numerator -ve
  33. stc ccr,S2L ; keep the sign in bit 3 of S2L
  34. bge postive
  35. neg.l A0P ; negate arg
  36. postive:
  37. mov.l A1P,A1P ; is the denominator -ve
  38. bge postive2
  39. neg.l A1P ; negate arg
  40. xor.b #0x08,S2L ; toggle the result sign
  41. postive2:
  42. rts
  43. ;; Basically the same, except that the sign of the divisor determines
  44. ;; the sign.
  45. modnorm:
  46. mov.l A0P,A0P ; is the numerator -ve
  47. stc ccr,S2L ; keep the sign in bit 3 of S2L
  48. bge mpostive
  49. neg.l A0P ; negate arg
  50. mpostive:
  51. mov.l A1P,A1P ; is the denominator -ve
  52. bge mpostive2
  53. neg.l A1P ; negate arg
  54. mpostive2:
  55. rts
  56. .end