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