Wolfgang Denk | 83c1585 | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2006 Atmel Corporation |
| 3 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 4 | * SPDX-License-Identifier: GPL-2.0+ |
Wolfgang Denk | 83c1585 | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * r12: void *b |
| 9 | * r11: int c |
| 10 | * r10: size_t len |
| 11 | * |
| 12 | * Returns b in r12 |
| 13 | */ |
Haavard Skinnemoen | 6ab31ce | 2008-05-02 15:24:22 +0200 | [diff] [blame] | 14 | .section .text.memset, "ax", @progbits |
Wolfgang Denk | 83c1585 | 2006-10-24 14:21:16 +0200 | [diff] [blame] | 15 | |
| 16 | .global memset |
| 17 | .type memset, @function |
| 18 | .align 2 |
| 19 | memset: |
| 20 | mov r9, r12 |
| 21 | mov r8, r12 |
| 22 | or r11, r11, r11 << 8 |
| 23 | andl r9, 3, COH |
| 24 | brne 1f |
| 25 | |
| 26 | 2: or r11, r11, r11 << 16 |
| 27 | sub r10, 4 |
| 28 | brlt 5f |
| 29 | |
| 30 | /* Let's do some real work */ |
| 31 | 4: st.w r8++, r11 |
| 32 | sub r10, 4 |
| 33 | brge 4b |
| 34 | |
| 35 | /* |
| 36 | * When we get here, we've got less than 4 bytes to set. r10 |
| 37 | * might be negative. |
| 38 | */ |
| 39 | 5: sub r10, -4 |
| 40 | reteq r12 |
| 41 | |
| 42 | /* Fastpath ends here, exactly 32 bytes from memset */ |
| 43 | |
| 44 | /* Handle unaligned count or pointer */ |
| 45 | bld r10, 1 |
| 46 | brcc 6f |
| 47 | st.b r8++, r11 |
| 48 | st.b r8++, r11 |
| 49 | bld r10, 0 |
| 50 | retcc r12 |
| 51 | 6: st.b r8++, r11 |
| 52 | mov pc, lr |
| 53 | |
| 54 | /* Handle unaligned pointer */ |
| 55 | 1: sub r10, 4 |
| 56 | brlt 5b |
| 57 | add r10, r9 |
| 58 | lsl r9, 1 |
| 59 | add pc, r9 |
| 60 | st.b r8++, r11 |
| 61 | st.b r8++, r11 |
| 62 | st.b r8++, r11 |
| 63 | rjmp 2b |
| 64 | |
| 65 | .size memset, . - memset |