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: memmove.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 MEMMOVE |
| 14 | * R0 = To Address (leave unchanged to form result) |
| 15 | * R1 = From Address |
| 16 | * R2 = count |
| 17 | * Data may overlap |
| 18 | */ |
| 19 | |
| 20 | .globl _memmove; |
Mike Frysinger | 6c097ce | 2008-02-19 00:36:14 -0500 | [diff] [blame] | 21 | .type _memmove, STT_FUNC; |
Aubrey.Li | 9da597f | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 22 | _memmove: |
| 23 | I1 = P3; |
| 24 | P0 = R0; /* P0 = To address */ |
| 25 | P3 = R1; /* P3 = From Address */ |
| 26 | P2 = R2 ; /* P2 = count */ |
| 27 | CC = P2 == 0; /* Check zero count*/ |
| 28 | IF CC JUMP .Lfinished; /* very unlikely */ |
| 29 | |
| 30 | CC = R1 < R0 (IU); /* From < To */ |
| 31 | IF !CC JUMP .Lno_overlap; |
| 32 | R3 = R1 + R2; |
| 33 | CC = R0 <= R3 (IU); /* (From+len) >= To */ |
| 34 | IF CC JUMP .Loverlap; |
| 35 | .Lno_overlap: |
| 36 | R3 = 11; |
| 37 | CC = R2 <= R3; |
| 38 | IF CC JUMP .Lbytes; |
| 39 | R3 = R1 | R0; /* OR addresses together */ |
| 40 | R3 <<= 30; /* check bottom two bits */ |
| 41 | CC = AZ; /* AZ set if zero.*/ |
| 42 | IF !CC JUMP .Lbytes ; /* Jump if addrs not aligned.*/ |
| 43 | |
| 44 | I0 = P3; |
| 45 | P1 = P2 >> 2; /* count = n/4 */ |
| 46 | P1 += -1; |
| 47 | R3 = 3; |
| 48 | R2 = R2 & R3; /* remainder */ |
| 49 | P2 = R2; /* set remainder */ |
| 50 | R1 = [I0++]; |
| 51 | |
| 52 | LSETUP (.Lquad_loop , .Lquad_loop) LC0=P1; |
| 53 | .Lquad_loop: MNOP || [P0++] = R1 || R1 = [I0++]; |
| 54 | [P0++] = R1; |
| 55 | |
| 56 | CC = P2 == 0; /* any remaining bytes? */ |
| 57 | P3 = I0; /* Ammend P3 to updated ptr. */ |
| 58 | IF !CC JUMP .Lbytes; |
| 59 | P3 = I1; |
| 60 | RTS; |
| 61 | |
| 62 | .Lbytes: LSETUP (.Lbyte2_s , .Lbyte2_e) LC0=P2; |
| 63 | .Lbyte2_s: R1 = B[P3++](Z); |
| 64 | .Lbyte2_e: B[P0++] = R1; |
| 65 | |
| 66 | .Lfinished: P3 = I1; |
| 67 | RTS; |
| 68 | |
| 69 | .Loverlap: |
| 70 | P2 += -1; |
| 71 | P0 = P0 + P2; |
| 72 | P3 = P3 + P2; |
| 73 | R1 = B[P3--] (Z); |
| 74 | CC = P2 == 0; |
| 75 | IF CC JUMP .Lno_loop; |
| 76 | LSETUP (.Lol_s, .Lol_e) LC0 = P2; |
| 77 | .Lol_s: B[P0--] = R1; |
| 78 | .Lol_e: R1 = B[P3--] (Z); |
| 79 | .Lno_loop: B[P0] = R1; |
| 80 | P3 = I1; |
| 81 | RTS; |
Mike Frysinger | 6c097ce | 2008-02-19 00:36:14 -0500 | [diff] [blame] | 82 | |
| 83 | .size _memmove, .-_memmove |