src/arch/arm64/memmove.S
raw| 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <arch/asm.h> |
| 4 | /* |
| 5 | * Move a buffer from src to test (alignment handled by the hardware). |
| 6 | * If dest <= src, call memcpy, otherwise copy in reverse order. |
| 7 | * |
| 8 | * Parameters: |
| 9 | * x0 - dest |
| 10 | * x1 - src |
| 11 | * x2 - n |
| 12 | * Returns: |
| 13 | * x0 - dest |
| 14 | */ |
| 15 | ENTRY(memmove) |
| 16 | cmp x0, x1 |
| 17 | b.ls memcpy |
| 18 | add x4, x0, x2 |
| 19 | add x1, x1, x2 |
| 20 | subs x2, x2, #8 |
| 21 | b.mi 2f |
| 22 | 1: ldr x3, [x1, #-8]! |
| 23 | subs x2, x2, #8 |
| 24 | str x3, [x4, #-8]! |
| 25 | b.pl 1b |
| 26 | 2: adds x2, x2, #4 |
| 27 | b.mi 3f |
| 28 | ldr w3, [x1, #-4]! |
| 29 | sub x2, x2, #4 |
| 30 | str w3, [x4, #-4]! |
| 31 | 3: adds x2, x2, #2 |
| 32 | b.mi 4f |
| 33 | ldrh w3, [x1, #-2]! |
| 34 | sub x2, x2, #2 |
| 35 | strh w3, [x4, #-2]! |
| 36 | 4: adds x2, x2, #1 |
| 37 | b.mi 5f |
| 38 | ldrb w3, [x1, #-1] |
| 39 | strb w3, [x4, #-1] |
| 40 | 5: ret |
| 41 | ENDPROC(memmove) |