memset.S revision 7c83a1ed81a15f3e75836c1ac7d500a952f02e10
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * * Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * * Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in 12 * the documentation and/or other materials provided with the 13 * distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29#include <machine/asm.h> 30 31 /* 32 * Optimized memset() for ARM. 33 * 34 * memset() returns its first argument. 35 */ 36 37ENTRY(bzero) 38 mov r2, r1 39 mov r1, #0 40END(bzero) 41 42ENTRY(memset) 43 /* compute the offset to align the destination 44 * offset = (4-(src&3))&3 = -src & 3 45 */ 46 .save {r0, r4-r7, lr} 47 stmfd sp!, {r0, r4-r7, lr} 48 rsb r3, r0, #0 49 ands r3, r3, #3 50 cmp r3, r2 51 movhi r3, r2 52 53 /* splat r1 */ 54 mov r1, r1, lsl #24 55 orr r1, r1, r1, lsr #8 56 orr r1, r1, r1, lsr #16 57 58 movs r12, r3, lsl #31 59 strcsb r1, [r0], #1 /* can't use strh (alignment unknown) */ 60 strcsb r1, [r0], #1 61 strmib r1, [r0], #1 62 subs r2, r2, r3 63 ldmlsfd sp!, {r0, r4-r7, lr} /* return */ 64 bxls lr 65 66 /* align the destination to a cache-line */ 67 mov r12, r1 68 mov lr, r1 69 mov r4, r1 70 mov r5, r1 71 mov r6, r1 72 mov r7, r1 73 74 rsb r3, r0, #0 75 ands r3, r3, #0x1C 76 beq 3f 77 cmp r3, r2 78 andhi r3, r2, #0x1C 79 sub r2, r2, r3 80 81 /* conditionally writes 0 to 7 words (length in r3) */ 82 movs r3, r3, lsl #28 83 stmcsia r0!, {r1, lr} 84 stmcsia r0!, {r1, lr} 85 stmmiia r0!, {r1, lr} 86 movs r3, r3, lsl #2 87 strcs r1, [r0], #4 88 893: 90 subs r2, r2, #32 91 mov r3, r1 92 bmi 2f 931: subs r2, r2, #32 94 stmia r0!, {r1,r3,r4,r5,r6,r7,r12,lr} 95 bhs 1b 962: add r2, r2, #32 97 98 /* conditionally stores 0 to 31 bytes */ 99 movs r2, r2, lsl #28 100 stmcsia r0!, {r1,r3,r12,lr} 101 stmmiia r0!, {r1, lr} 102 movs r2, r2, lsl #2 103 strcs r1, [r0], #4 104 strmih r1, [r0], #2 105 movs r2, r2, lsl #2 106 strcsb r1, [r0] 107 ldmfd sp!, {r0, r4-r7, lr} 108 bx lr 109END(memset) 110