Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 1 | /* |
Aubrey Li | 314d22f | 2007-04-05 18:31:18 +0800 | [diff] [blame] | 2 | * File: memcmp.S |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 3 | * |
Aubrey Li | 314d22f | 2007-04-05 18:31:18 +0800 | [diff] [blame] | 4 | * Copyright 2004-2007 Analog Devices Inc. |
| 5 | * Enter bugs at http://blackfin.uclinux.org/ |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | .align 2 |
| 11 | |
| 12 | /* |
| 13 | * C Library function MEMCMP |
| 14 | * R0 = First Address |
| 15 | * R1 = Second Address |
| 16 | * R2 = count |
| 17 | * Favours word aligned data. |
| 18 | */ |
| 19 | |
| 20 | .globl _memcmp; |
Mike Frysinger | 6c097ce | 2008-02-19 00:36:14 -0500 | [diff] [blame] | 21 | .type _memcmp, STT_FUNC; |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 22 | _memcmp: |
| 23 | I1 = P3; |
| 24 | P0 = R0; /* P0 = s1 address */ |
| 25 | P3 = R1; /* P3 = s2 Address */ |
| 26 | P2 = R2 ; /* P2 = count */ |
| 27 | CC = R2 <= 7(IU); |
| 28 | IF CC JUMP .Ltoo_small; |
| 29 | I0 = R1; /* s2 */ |
| 30 | R1 = R1 | R0; /* OR addresses together */ |
| 31 | R1 <<= 30; /* check bottom two bits */ |
| 32 | CC = AZ; /* AZ set if zero. */ |
| 33 | IF !CC JUMP .Lbytes ; /* Jump if addrs not aligned. */ |
| 34 | |
| 35 | P1 = P2 >> 2; /* count = n/4 */ |
| 36 | R3 = 3; |
| 37 | R2 = R2 & R3; /* remainder */ |
| 38 | P2 = R2; /* set remainder */ |
| 39 | |
| 40 | LSETUP (.Lquad_loop_s , .Lquad_loop_e) LC0=P1; |
| 41 | .Lquad_loop_s: |
| 42 | NOP; |
| 43 | R0 = [P0++]; |
| 44 | R1 = [I0++]; |
| 45 | CC = R0 == R1; |
| 46 | IF !CC JUMP .Lquad_different; |
| 47 | .Lquad_loop_e: |
| 48 | NOP; |
| 49 | |
| 50 | P3 = I0; /* s2 */ |
| 51 | .Ltoo_small: |
| 52 | CC = P2 == 0; /* Check zero count*/ |
| 53 | IF CC JUMP .Lfinished; /* very unlikely*/ |
| 54 | |
| 55 | .Lbytes: |
| 56 | LSETUP (.Lbyte_loop_s , .Lbyte_loop_e) LC0=P2; |
| 57 | .Lbyte_loop_s: |
| 58 | R1 = B[P3++](Z); /* *s2 */ |
| 59 | R0 = B[P0++](Z); /* *s1 */ |
| 60 | CC = R0 == R1; |
| 61 | IF !CC JUMP .Ldifferent; |
| 62 | .Lbyte_loop_e: |
| 63 | NOP; |
| 64 | |
| 65 | .Ldifferent: |
| 66 | R0 = R0 - R1; |
| 67 | P3 = I1; |
| 68 | RTS; |
| 69 | |
| 70 | .Lquad_different: |
| 71 | /* We've read two quads which don't match. |
| 72 | * Can't just compare them, because we're |
| 73 | * a little-endian machine, so the MSBs of |
| 74 | * the regs occur at later addresses in the |
| 75 | * string. |
| 76 | * Arrange to re-read those two quads again, |
| 77 | * byte-by-byte. |
| 78 | */ |
| 79 | P0 += -4; /* back up to the start of the */ |
| 80 | P3 = I0; /* quads, and increase the*/ |
| 81 | P2 += 4; /* remainder count*/ |
| 82 | P3 += -4; |
| 83 | JUMP .Lbytes; |
| 84 | |
| 85 | .Lfinished: |
| 86 | R0 = 0; |
| 87 | P3 = I1; |
| 88 | RTS; |
Mike Frysinger | 6c097ce | 2008-02-19 00:36:14 -0500 | [diff] [blame] | 89 | |
| 90 | .size _memcmp, .-_memcmp |