Paul Mackerras | 70d64ce | 2005-10-10 21:52:43 +1000 | [diff] [blame] | 1 | /* |
| 2 | * String handling functions for PowerPC. |
| 3 | * |
| 4 | * Copyright (C) 1996 Paul Mackerras. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | */ |
| 11 | #include <asm/processor.h> |
| 12 | #include <asm/errno.h> |
| 13 | #include <asm/ppc_asm.h> |
Al Viro | 9445aa1 | 2016-01-13 23:33:46 -0500 | [diff] [blame^] | 14 | #include <asm/export.h> |
Paul Mackerras | 70d64ce | 2005-10-10 21:52:43 +1000 | [diff] [blame] | 15 | |
| 16 | _GLOBAL(memset) |
| 17 | neg r0,r3 |
| 18 | rlwimi r4,r4,8,16,23 |
| 19 | andi. r0,r0,7 /* # bytes to be 8-byte aligned */ |
| 20 | rlwimi r4,r4,16,0,15 |
| 21 | cmplw cr1,r5,r0 /* do we get that far? */ |
| 22 | rldimi r4,r4,32,0 |
Anton Blanchard | 694caf0 | 2012-04-18 02:21:52 +0000 | [diff] [blame] | 23 | PPC_MTOCRF(1,r0) |
Paul Mackerras | 70d64ce | 2005-10-10 21:52:43 +1000 | [diff] [blame] | 24 | mr r6,r3 |
| 25 | blt cr1,8f |
| 26 | beq+ 3f /* if already 8-byte aligned */ |
| 27 | subf r5,r0,r5 |
| 28 | bf 31,1f |
| 29 | stb r4,0(r6) |
| 30 | addi r6,r6,1 |
| 31 | 1: bf 30,2f |
| 32 | sth r4,0(r6) |
| 33 | addi r6,r6,2 |
| 34 | 2: bf 29,3f |
| 35 | stw r4,0(r6) |
| 36 | addi r6,r6,4 |
| 37 | 3: srdi. r0,r5,6 |
| 38 | clrldi r5,r5,58 |
| 39 | mtctr r0 |
| 40 | beq 5f |
| 41 | 4: std r4,0(r6) |
| 42 | std r4,8(r6) |
| 43 | std r4,16(r6) |
| 44 | std r4,24(r6) |
| 45 | std r4,32(r6) |
| 46 | std r4,40(r6) |
| 47 | std r4,48(r6) |
| 48 | std r4,56(r6) |
| 49 | addi r6,r6,64 |
| 50 | bdnz 4b |
| 51 | 5: srwi. r0,r5,3 |
| 52 | clrlwi r5,r5,29 |
Anton Blanchard | 694caf0 | 2012-04-18 02:21:52 +0000 | [diff] [blame] | 53 | PPC_MTOCRF(1,r0) |
Paul Mackerras | 70d64ce | 2005-10-10 21:52:43 +1000 | [diff] [blame] | 54 | beq 8f |
| 55 | bf 29,6f |
| 56 | std r4,0(r6) |
| 57 | std r4,8(r6) |
| 58 | std r4,16(r6) |
| 59 | std r4,24(r6) |
| 60 | addi r6,r6,32 |
| 61 | 6: bf 30,7f |
| 62 | std r4,0(r6) |
| 63 | std r4,8(r6) |
| 64 | addi r6,r6,16 |
| 65 | 7: bf 31,8f |
| 66 | std r4,0(r6) |
| 67 | addi r6,r6,8 |
| 68 | 8: cmpwi r5,0 |
Anton Blanchard | 694caf0 | 2012-04-18 02:21:52 +0000 | [diff] [blame] | 69 | PPC_MTOCRF(1,r5) |
Paul Mackerras | 70d64ce | 2005-10-10 21:52:43 +1000 | [diff] [blame] | 70 | beqlr+ |
| 71 | bf 29,9f |
| 72 | stw r4,0(r6) |
| 73 | addi r6,r6,4 |
| 74 | 9: bf 30,10f |
| 75 | sth r4,0(r6) |
| 76 | addi r6,r6,2 |
| 77 | 10: bflr 31 |
| 78 | stb r4,0(r6) |
| 79 | blr |
Al Viro | 9445aa1 | 2016-01-13 23:33:46 -0500 | [diff] [blame^] | 80 | EXPORT_SYMBOL(memset) |
Paul Mackerras | 70d64ce | 2005-10-10 21:52:43 +1000 | [diff] [blame] | 81 | |
Li Zhong | 6f5405b | 2014-07-21 17:55:13 +0800 | [diff] [blame] | 82 | _GLOBAL_TOC(memmove) |
Paul Mackerras | 70d64ce | 2005-10-10 21:52:43 +1000 | [diff] [blame] | 83 | cmplw 0,r3,r4 |
Anton Blanchard | b1576fe | 2014-02-04 16:04:35 +1100 | [diff] [blame] | 84 | bgt backwards_memcpy |
| 85 | b memcpy |
Paul Mackerras | 70d64ce | 2005-10-10 21:52:43 +1000 | [diff] [blame] | 86 | |
| 87 | _GLOBAL(backwards_memcpy) |
| 88 | rlwinm. r7,r5,32-3,3,31 /* r0 = r5 >> 3 */ |
| 89 | add r6,r3,r5 |
| 90 | add r4,r4,r5 |
| 91 | beq 2f |
| 92 | andi. r0,r6,3 |
| 93 | mtctr r7 |
| 94 | bne 5f |
| 95 | 1: lwz r7,-4(r4) |
| 96 | lwzu r8,-8(r4) |
| 97 | stw r7,-4(r6) |
| 98 | stwu r8,-8(r6) |
| 99 | bdnz 1b |
| 100 | andi. r5,r5,7 |
| 101 | 2: cmplwi 0,r5,4 |
| 102 | blt 3f |
| 103 | lwzu r0,-4(r4) |
| 104 | subi r5,r5,4 |
| 105 | stwu r0,-4(r6) |
| 106 | 3: cmpwi 0,r5,0 |
| 107 | beqlr |
| 108 | mtctr r5 |
| 109 | 4: lbzu r0,-1(r4) |
| 110 | stbu r0,-1(r6) |
| 111 | bdnz 4b |
| 112 | blr |
| 113 | 5: mtctr r0 |
| 114 | 6: lbzu r7,-1(r4) |
| 115 | stbu r7,-1(r6) |
| 116 | bdnz 6b |
| 117 | subf r5,r0,r5 |
| 118 | rlwinm. r7,r5,32-3,3,31 |
| 119 | beq 2b |
| 120 | mtctr r7 |
| 121 | b 1b |
Al Viro | 9445aa1 | 2016-01-13 23:33:46 -0500 | [diff] [blame^] | 122 | EXPORT_SYMBOL(memmove) |