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