1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/linkage.h>
5 * modulo operation for 32 bit integers.
6 * Input : op1 in Reg r5
8 * Output: op1 mod op2 in Reg r3
13 .type __modsi3, @function
25 beqi r6, div_by_zero /* div_by_zero division error */
26 beqi r5, result_is_zero /* result is zero */
28 /* get the sign of the result [ depends only on the first arg] */
30 rsubi r5, r5, 0 /* make r5 positive */
33 rsubi r6, r6, 0 /* make r6 positive */
35 addik r3, r0, 0 /* clear mod */
36 addik r30, r0, 0 /* clear div */
37 addik r29, r0, 32 /* initialize the loop count */
38 /* first part try to find the first '1' in the r5 */
40 add r5, r5, r5 /* left shift logical r5 */
44 /* left shift logical r5 get the '1' into the carry */
46 addc r3, r3, r3 /* move that bit into the mod register */
47 rsub r31, r6, r3 /* try to subtract (r30 a r6) */
48 blti r31, mod_too_small
49 /* move the r31 to mod since the result was positive */
55 add r30, r30, r30 /* shift in the '1' into div */
60 rsubi r3, r3, 0 /* negate the result */
63 or r3, r0, r0 /* set result to 0 [both mod as well as div are 0] */
65 /* restore values of csrs and that of r3 and the divisor and the dividend */
73 .size __modsi3, . - __modsi3