1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/linkage.h>
5 * Unsigned divide operation.
6 * Input : Divisor in Reg r5
8 * Output: Result in Reg r3
13 .type __udivsi3, @function
25 beqi r6, div_by_zero /* div_by_zero /* division error */
26 beqid r5, result_is_zero /* result is zero */
27 addik r30, r0, 0 /* clear mod */
28 addik r29, r0, 32 /* initialize the loop count */
30 /* check if r6 and r5 are equal - if yes, return 1 */
32 beqid r18, return_here
35 /* check if (uns)r6 is greater than (uns)r5. in that case, just return 0 */
38 add r3, r0, r0 /* we would anyways clear r3 */
39 blti r6, return_here /* r6[bit 31 = 1] hence is greater */
41 rsub r18, r6, r5 /* microblazecmp */
44 /* if r6 [bit 31] is set, then return result as 1 */
50 /* first part try to find the first '1' in the r5 */
54 add r5, r5, r5 /* left shift logical r5 */
58 /* left shift logical r5 get the '1' into the carry */
60 addc r30, r30, r30 /* move that bit into the mod register */
61 rsub r31, r6, r30 /* try to subtract (r30 a r6) */
62 blti r31, mod_too_small
63 /* move the r31 to mod since the result was positive */
69 add r3, r3, r3 /* shift in the '1' into div */
75 or r3, r0, r0 /* set result to 0 */
77 /* restore values of csrs and that of r3 and the divisor and the dividend */
84 .size __udivsi3, . - __udivsi3