| 1 | /* Optimized strcpy implementation for PowerPC476. |
| 2 | Copyright (C) 2010-2024 Free Software Foundation, Inc. |
| 3 | This file is part of the GNU C Library. |
| 4 | |
| 5 | The GNU C Library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | The GNU C Library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with the GNU C Library. If not, see |
| 17 | <https://www.gnu.org/licenses/>. */ |
| 18 | |
| 19 | #include <sysdep.h> |
| 20 | |
| 21 | /* strcpy |
| 22 | |
| 23 | Register Use |
| 24 | r3:destination and return address |
| 25 | r4:source address |
| 26 | r10:temp destination address |
| 27 | |
| 28 | Implementation description |
| 29 | Loop by checking 2 words at a time, with dlmzb. Check if there is a null |
| 30 | in the 2 words. If there is a null jump to end checking to determine |
| 31 | where in the last 8 bytes it is. Copy the appropriate bytes of the last |
| 32 | 8 according to the null position. */ |
| 33 | |
| 34 | EALIGN (strcpy, 5, 0) |
| 35 | neg r7,r4 |
| 36 | subi r4,r4,1 |
| 37 | clrlwi. r8,r7,29 |
| 38 | subi r10,r3,1 |
| 39 | beq L(pre_word8_loop) |
| 40 | mtctr r8 |
| 41 | |
| 42 | L(loop): |
| 43 | lbzu r5,0x01(r4) |
| 44 | cmpi cr5,r5,0x0 |
| 45 | stbu r5,0x01(r10) |
| 46 | beq cr5,L(end_strcpy) |
| 47 | bdnz L(loop) |
| 48 | |
| 49 | L(pre_word8_loop): |
| 50 | subi r4,r4,3 |
| 51 | subi r10,r10,3 |
| 52 | |
| 53 | L(word8_loop): |
| 54 | lwzu r5,0x04(r4) |
| 55 | lwzu r6,0x04(r4) |
| 56 | dlmzb. r11,r5,r6 |
| 57 | bne L(byte_copy) |
| 58 | stwu r5,0x04(r10) |
| 59 | stwu r6,0x04(r10) |
| 60 | lwzu r5,0x04(r4) |
| 61 | lwzu r6,0x04(r4) |
| 62 | dlmzb. r11,r5,r6 |
| 63 | bne L(byte_copy) |
| 64 | stwu r5,0x04(r10) |
| 65 | stwu r6,0x04(r10) |
| 66 | lwzu r5,0x04(r4) |
| 67 | lwzu r6,0x04(r4) |
| 68 | dlmzb. r11,r5,r6 |
| 69 | bne L(byte_copy) |
| 70 | stwu r5,0x04(r10) |
| 71 | stwu r6,0x04(r10) |
| 72 | lwzu r5,0x04(r4) |
| 73 | lwzu r6,0x04(r4) |
| 74 | dlmzb. r11,r5,r6 |
| 75 | bne L(byte_copy) |
| 76 | stwu r5,0x04(r10) |
| 77 | stwu r6,0x04(r10) |
| 78 | b L(word8_loop) |
| 79 | |
| 80 | L(last_bytes_copy): |
| 81 | stwu r5,0x04(r10) |
| 82 | subi r11,r11,4 |
| 83 | mtctr r11 |
| 84 | addi r10,r10,3 |
| 85 | subi r4,r4,1 |
| 86 | |
| 87 | L(last_bytes_copy_loop): |
| 88 | lbzu r5,0x01(r4) |
| 89 | stbu r5,0x01(r10) |
| 90 | bdnz L(last_bytes_copy_loop) |
| 91 | blr |
| 92 | |
| 93 | L(byte_copy): |
| 94 | blt L(last_bytes_copy) |
| 95 | mtctr r11 |
| 96 | addi r10,r10,3 |
| 97 | subi r4,r4,5 |
| 98 | |
| 99 | L(last_bytes_copy_loop2): |
| 100 | lbzu r5,0x01(r4) |
| 101 | stbu r5,0x01(r10) |
| 102 | bdnz L(last_bytes_copy_loop2) |
| 103 | |
| 104 | L(end_strcpy): |
| 105 | blr |
| 106 | END (strcpy) |
| 107 | libc_hidden_builtin_def (strcpy) |
| 108 | |