1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/linkage.h>
5 * Unsigned modulo operation for 32 bit integers.
6 * Input : op1 in Reg r5
8 * Output: op1 mod op2 in Reg r3
13 .type __umodsi3, @function
24 beqi r6, div_by_zero /* div_by_zero - division error */
25 beqid r5, result_is_zero /* result is zero */
26 addik r3, r0, 0 /* clear div */
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 0 */
34 /* check if (uns)r6 is greater than (uns)r5. in that case, just return r5 */
40 rsub r18, r5, r6 /* microblazecmp */
43 /* if r6 [bit 31] is set, then return result as r5-r6 */
47 addik r18, r0, 0x7fffffff
52 /* first part: try to find the first '1' in the r5 */
56 add r5, r5, r5 /* left shift logical r5 */
60 /* left shift logical r5 get the '1' into the carry */
62 addc r3, r3, r3 /* move that bit into the mod register */
63 rsub r31, r6, r3 /* try to subtract (r3 a r6) */
64 blti r31, mod_too_small
65 /* move the r31 to mod since the result was positive */
71 add r30, r30, r30 /* shift in the '1' into div */
77 or r3, r0, r0 /* set result to 0 */
79 /* restore values of csrs and that of r3 and the divisor and the dividend */
86 .size __umodsi3, . - __umodsi3