1 ;------------------------------------------------------------------------------ 2 ; 3 ; Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR> 4 ; 5 ; This program and the accompanying materials are licensed and made available 6 ; under the terms and conditions of the BSD License which accompanies this 7 ; distribution. The full text of the license may be found at 8 ; http://opensource.org/licenses/bsd-license.php 9 ; 10 ; THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 ; WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 ; 13 ;------------------------------------------------------------------------------ 14 15 EXPORT InternalMemZeroMem 16 EXPORT InternalMemSetMem 17 EXPORT InternalMemSetMem16 18 EXPORT InternalMemSetMem32 19 EXPORT InternalMemSetMem64 20 21 AREA SetMem, CODE, READONLY, CODEALIGN, ALIGN=5 22 THUMB 23 24 InternalMemSetMem16 25 uxth r2, r2 26 lsl r1, r1, #1 27 orr r2, r2, r2, lsl #16 28 b B0 29 30 InternalMemSetMem32 31 lsl r1, r1, #2 32 b B0 33 34 InternalMemSetMem64 35 lsl r1, r1, #3 36 b B1 37 38 ALIGN 32 39 InternalMemSetMem 40 uxtb r2, r2 41 orr r2, r2, r2, lsl #8 42 orr r2, r2, r2, lsl #16 43 b B0 44 45 InternalMemZeroMem 46 movs r2, #0 47 B0 48 mov r3, r2 49 50 B1 51 push {r4, lr} 52 cmp r1, #16 ; fewer than 16 bytes of input? 53 add r1, r1, r0 ; r1 := dst + length 54 add lr, r0, #16 55 blt L2 56 bic lr, lr, #15 ; align output pointer 57 58 str r2, [r0] ; potentially unaligned store of 4 bytes 59 str r3, [r0, #4] ; potentially unaligned store of 4 bytes 60 str r2, [r0, #8] ; potentially unaligned store of 4 bytes 61 str r3, [r0, #12] ; potentially unaligned store of 4 bytes 62 beq L1 63 64 L0 65 add lr, lr, #16 ; advance the output pointer by 16 bytes 66 subs r4, r1, lr ; past the output? 67 blt L3 ; break out of the loop 68 strd r2, r3, [lr, #-16] ; aligned store of 16 bytes 69 strd r2, r3, [lr, #-8] 70 bne L0 ; goto beginning of loop 71 L1 72 pop {r4, pc} 73 74 L2 75 subs r4, r1, lr 76 L3 77 adds r4, r4, #16 78 subs r1, r1, #8 79 cmp r4, #4 ; between 4 and 15 bytes? 80 blt L4 81 cmp r4, #8 ; between 8 and 15 bytes? 82 str r2, [lr, #-16] ; overlapping store of 4 + (4 + 4) + 4 bytes 83 itt gt 84 strgt r3, [lr, #-12] 85 strgt r2, [r1] 86 str r3, [r1, #4] 87 pop {r4, pc} 88 89 L4 90 cmp r4, #2 ; 2 or 3 bytes? 91 strb r2, [lr, #-16] ; store 1 byte 92 it ge 93 strhge r2, [r1, #6] ; store 2 bytes 94 pop {r4, pc} 95 96 END 97