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