Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 1 | /* |
Aubrey Li | 155fd76 | 2007-04-05 18:31:18 +0800 | [diff] [blame] | 2 | * File: memset.S |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 3 | * |
Aubrey Li | 155fd76 | 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 | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 6 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 8 | */ |
| 9 | |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 10 | .align 2 |
| 11 | |
| 12 | /* |
| 13 | * C Library function MEMSET |
| 14 | * R0 = address (leave unchanged to form result) |
| 15 | * R1 = filler byte |
| 16 | * R2 = count |
| 17 | * Favours word aligned data. |
| 18 | */ |
| 19 | |
| 20 | .globl _memset; |
Mike Frysinger | 5b22163 | 2008-02-19 00:36:14 -0500 | [diff] [blame] | 21 | .type _memset, STT_FUNC; |
Aubrey.Li | 3f0606a | 2007-03-09 13:38:44 +0800 | [diff] [blame] | 22 | _memset: |
| 23 | P0 = R0 ; /* P0 = address */ |
| 24 | P2 = R2 ; /* P2 = count */ |
| 25 | R3 = R0 + R2; /* end */ |
| 26 | CC = R2 <= 7(IU); |
| 27 | IF CC JUMP .Ltoo_small; |
| 28 | R1 = R1.B (Z); /* R1 = fill char */ |
| 29 | R2 = 3; |
| 30 | R2 = R0 & R2; /* addr bottom two bits */ |
| 31 | CC = R2 == 0; /* AZ set if zero. */ |
| 32 | IF !CC JUMP .Lforce_align ; /* Jump if addr not aligned. */ |
| 33 | |
| 34 | .Laligned: |
| 35 | P1 = P2 >> 2; /* count = n/4 */ |
| 36 | R2 = R1 << 8; /* create quad filler */ |
| 37 | R2.L = R2.L + R1.L(NS); |
| 38 | R2.H = R2.L + R1.H(NS); |
| 39 | P2 = R3; |
| 40 | |
| 41 | LSETUP (.Lquad_loop , .Lquad_loop) LC0=P1; |
| 42 | .Lquad_loop: |
| 43 | [P0++] = R2; |
| 44 | |
| 45 | CC = P0 == P2; |
| 46 | IF !CC JUMP .Lbytes_left; |
| 47 | RTS; |
| 48 | |
| 49 | .Lbytes_left: |
| 50 | R2 = R3; /* end point */ |
| 51 | R3 = P0; /* current position */ |
| 52 | R2 = R2 - R3; /* bytes left */ |
| 53 | P2 = R2; |
| 54 | |
| 55 | .Ltoo_small: |
| 56 | CC = P2 == 0; /* Check zero count */ |
| 57 | IF CC JUMP .Lfinished; /* Unusual */ |
| 58 | |
| 59 | .Lbytes: |
| 60 | LSETUP (.Lbyte_loop , .Lbyte_loop) LC0=P2; |
| 61 | .Lbyte_loop: |
| 62 | B[P0++] = R1; |
| 63 | |
| 64 | .Lfinished: |
| 65 | RTS; |
| 66 | |
| 67 | .Lforce_align: |
| 68 | CC = BITTST (R0, 0); /* odd byte */ |
| 69 | R0 = 4; |
| 70 | R0 = R0 - R2; |
| 71 | P1 = R0; |
| 72 | R0 = P0; /* Recover return address */ |
| 73 | IF !CC JUMP .Lskip1; |
| 74 | B[P0++] = R1; |
| 75 | .Lskip1: |
| 76 | CC = R2 <= 2; /* 2 bytes */ |
| 77 | P2 -= P1; /* reduce count */ |
| 78 | IF !CC JUMP .Laligned; |
| 79 | B[P0++] = R1; |
| 80 | B[P0++] = R1; |
| 81 | JUMP .Laligned; |
Mike Frysinger | 5b22163 | 2008-02-19 00:36:14 -0500 | [diff] [blame] | 82 | |
| 83 | .size _memset, .-_memset |