1 /* SPDX-License-Identifier: GPL-2.0 */
4 ;; This function also computes the remainder and stores it in er3.
7 mov.w A1E,A1E ; denominator top word 0?
10 ; do it the easy way, see page 107 in manual
28 #ifdef CONFIG_CPU_H8300H
31 shlr.l er2 ; make divisor < 2^16
35 shlr.l #2,er2 ; make divisor < 2^16
41 shlr.l #2,er2 ; make divisor < 2^16
55 ;; er0 contains shifted dividend
56 ;; er1 contains divisor
57 ;; er2 contains shifted divisor
58 ;; er3 contains dividend, later remainder
59 divxu.w r2,er0 ; r0 now contains the approximate quotient (AQ)
62 subs #1,er0 ; er0 = AQ - 1
64 mulxu.w r0,er2 ; er2 = upper (AQ - 1) * divisor
65 sub.w r2,e3 ; dividend - 65536 * er2
67 mulxu.w r0,er2 ; compute er3 = remainder (tentative)
68 sub.l er2,er3 ; er3 = dividend - (AQ - 1) * divisor
70 cmp.l er1,er3 ; is divisor < remainder?
73 sub.l er1,er3 ; correct the remainder