1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
/*
* File: arch/blackfin/lib/modsi3.S
* Based on:
* Author:
*
* Created:
* Description: This program computes 32 bit signed remainder. It calls div32 function
* for quotient estimation.
*
* Registers used :
* Numerator/ Denominator in R0, R1
* R0 - returns remainder.
* R2-R7
*
* Modified:
* Copyright 2004-2006 Analog Devices Inc.
*
* Bugs: Enter bugs at http://blackfin.uclinux.org/
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see the file COPYING, or write
* to the Free Software Foundation, Inc.,
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
.global ___modsi3;
.type ___modsi3, STT_FUNC;
.extern ___divsi3;
.type ___divsi3, STT_FUNC;
#ifdef CONFIG_ARITHMETIC_OPS_L1
.section .l1.text
#else
.text
#endif
___modsi3:
CC=R0==0;
IF CC JUMP .LRETURN_R0; /* Return 0, if numerator == 0 */
CC=R1==0;
IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == 0 */
CC=R0==R1;
IF CC JUMP .LRETURN_ZERO; /* Return 0, if numerator == denominator */
CC = R1 == 1;
IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == 1 */
CC = R1 == -1;
IF CC JUMP .LRETURN_ZERO; /* Return 0, if denominator == -1 */
/* Valid input. Use __divsi3() to compute the quotient, and then
* derive the remainder from that. */
[--SP] = (R7:6); /* Push R7 and R6 */
[--SP] = RETS; /* and return address */
R7 = R0; /* Copy of R0 */
R6 = R1; /* Save for later */
SP += -12; /* Should always provide this space */
CALL ___divsi3; /* Compute signed quotient using ___divsi3()*/
SP += 12;
R0 *= R6; /* Quotient * divisor */
R0 = R7 - R0; /* Dividend - (quotient * divisor) */
RETS = [SP++]; /* Get back return address */
(R7:6) = [SP++]; /* Pop registers R7 and R4 */
RTS; /* Store remainder */
.LRETURN_ZERO:
R0 = 0;
.LRETURN_R0:
RTS;
|