/* SPDX-License-Identifier: GPL-2.0 */1#include <linux/linkage.h>23/*4* modulo operation for 32 bit integers.5* Input : op1 in Reg r56* op2 in Reg r67* Output: op1 mod op2 in Reg r38*/910.text11.globl __modsi312.type __modsi3, @function13.ent __modsi31415__modsi3:16.frame r1, 0, r151718addik r1, r1, -1619swi r28, r1, 020swi r29, r1, 421swi r30, r1, 822swi r31, r1, 122324beqi r6, div_by_zero /* div_by_zero division error */25beqi r5, result_is_zero /* result is zero */26bgeid r5, r5_pos27/* get the sign of the result [ depends only on the first arg] */28add r28, r5, r029rsubi r5, r5, 0 /* make r5 positive */30r5_pos:31bgei r6, r6_pos32rsubi r6, r6, 0 /* make r6 positive */33r6_pos:34addik r3, r0, 0 /* clear mod */35addik r30, r0, 0 /* clear div */36addik r29, r0, 32 /* initialize the loop count */37/* first part try to find the first '1' in the r5 */38div1:39add r5, r5, r5 /* left shift logical r5 */40bgeid r5, div141addik r29, r29, -142div2:43/* left shift logical r5 get the '1' into the carry */44add r5, r5, r545addc r3, r3, r3 /* move that bit into the mod register */46rsub r31, r6, r3 /* try to subtract (r30 a r6) */47blti r31, mod_too_small48/* move the r31 to mod since the result was positive */49or r3, r0, r3150addik r30, r30, 151mod_too_small:52addik r29, r29, -153beqi r29, loop_end54add r30, r30, r30 /* shift in the '1' into div */55bri div2 /* div2 */56loop_end:57bgei r28, return_here58brid return_here59rsubi r3, r3, 0 /* negate the result */60div_by_zero:61result_is_zero:62or r3, r0, r0 /* set result to 0 [both mod as well as div are 0] */63return_here:64/* restore values of csrs and that of r3 and the divisor and the dividend */65lwi r28, r1, 066lwi r29, r1, 467lwi r30, r1, 868lwi r31, r1, 1269rtsd r15, 870addik r1, r1, 167172.size __modsi3, . - __modsi373.end __modsi3747576