blob: f7026ce1fa0e4fd418ae44da746020e439bbfc10 [file] [log] [blame]
Bryan Wu1394f032007-05-06 14:50:22 -07001/*
Robin Getz96f10502009-09-24 14:11:24 +00002 * This program computes 32 bit signed remainder. It calls div32 function
3 * for quotient estimation.
4 * Registers in: R0, R1 = Numerator/ Denominator
5 * Registers out: R0 = Remainder
Bryan Wu1394f032007-05-06 14:50:22 -07006 *
Robin Getz96f10502009-09-24 14:11:24 +00007 * Copyright 2004-2009 Analog Devices Inc.
Bryan Wu1394f032007-05-06 14:50:22 -07008 *
Sonic Zhangde450832012-05-17 14:45:27 +08009 * Licensed under the Clear BSD license or the GPL-2 (or later)
Bryan Wu1394f032007-05-06 14:50:22 -070010 */
11
12.global ___modsi3;
13.type ___modsi3, STT_FUNC;
14.extern ___divsi3;
15.type ___divsi3, STT_FUNC;
16
17#ifdef CONFIG_ARITHMETIC_OPS_L1
18.section .l1.text
19#else
20.text
21#endif
22
23___modsi3:
24
25 CC=R0==0;
26 IF CC JUMP .LRETURN_R0; /* Return 0, if numerator == 0 */
27 CC=R1==0;
28 IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == 0 */
29 CC=R0==R1;
30 IF CC JUMP .LRETURN_ZERO; /* Return 0, if numerator == denominator */
31 CC = R1 == 1;
32 IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == 1 */
33 CC = R1 == -1;
34 IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == -1 */
35
36 /* Valid input. Use __divsi3() to compute the quotient, and then
37 * derive the remainder from that. */
38
39 [--SP] = (R7:6); /* Push R7 and R6 */
40 [--SP] = RETS; /* and return address */
41 R7 = R0; /* Copy of R0 */
42 R6 = R1; /* Save for later */
43 SP += -12; /* Should always provide this space */
44 CALL ___divsi3; /* Compute signed quotient using ___divsi3()*/
45 SP += 12;
46 R0 *= R6; /* Quotient * divisor */
47 R0 = R7 - R0; /* Dividend - (quotient * divisor) */
48 RETS = [SP++]; /* Get back return address */
49 (R7:6) = [SP++]; /* Pop registers R7 and R4 */
50 RTS; /* Store remainder */
51
52.LRETURN_ZERO:
53 R0 = 0;
54.LRETURN_R0:
55 RTS;
Mike Frysinger51be24c2007-06-11 15:31:30 +080056
57.size ___modsi3, .-___modsi3