The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame^] | 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 | .text |
| 29 | |
| 30 | .global memset |
| 31 | .type memset, %function |
| 32 | |
| 33 | .global bzero |
| 34 | .type bzero, %function |
| 35 | |
| 36 | .align |
| 37 | |
| 38 | /* |
| 39 | * Optimized memset() for ARM. |
| 40 | * |
| 41 | * memset() returns its first argument. |
| 42 | */ |
| 43 | |
| 44 | bzero: |
| 45 | mov r2, r1 |
| 46 | mov r1, #0 |
| 47 | |
| 48 | memset: |
| 49 | /* compute the offset to align the destination |
| 50 | * offset = (4-(src&3))&3 = -src & 3 |
| 51 | */ |
| 52 | .fnstart |
| 53 | .save {r0, r4-r7, lr} |
| 54 | stmfd sp!, {r0, r4-r7, lr} |
| 55 | rsb r3, r0, #0 |
| 56 | ands r3, r3, #3 |
| 57 | cmp r3, r2 |
| 58 | movhi r3, r2 |
| 59 | |
| 60 | /* splat r1 */ |
| 61 | mov r1, r1, lsl #24 |
| 62 | orr r1, r1, r1, lsr #8 |
| 63 | orr r1, r1, r1, lsr #16 |
| 64 | |
| 65 | movs r12, r3, lsl #31 |
| 66 | strcsb r1, [r0], #1 /* can't use strh (alignment unknown) */ |
| 67 | strcsb r1, [r0], #1 |
| 68 | strmib r1, [r0], #1 |
| 69 | subs r2, r2, r3 |
| 70 | ldmlsfd sp!, {r0, r4-r7, lr} /* return */ |
| 71 | bxls lr |
| 72 | |
| 73 | /* align the destination to a cache-line */ |
| 74 | mov r12, r1 |
| 75 | mov lr, r1 |
| 76 | mov r4, r1 |
| 77 | mov r5, r1 |
| 78 | mov r6, r1 |
| 79 | mov r7, r1 |
| 80 | |
| 81 | rsb r3, r0, #0 |
| 82 | ands r3, r3, #0x1C |
| 83 | beq aligned32 |
| 84 | cmp r3, r2 |
| 85 | andhi r3, r2, #0x1C |
| 86 | sub r2, r2, r3 |
| 87 | |
| 88 | /* conditionnaly writes 0 to 7 words (length in r3) */ |
| 89 | movs r3, r3, lsl #28 |
| 90 | stmcsia r0!, {r1, lr} |
| 91 | stmcsia r0!, {r1, lr} |
| 92 | stmmiia r0!, {r1, lr} |
| 93 | movs r3, r3, lsl #2 |
| 94 | strcs r1, [r0], #4 |
| 95 | |
| 96 | aligned32: |
| 97 | subs r2, r2, #32 |
| 98 | mov r3, r1 |
| 99 | bmi 2f |
| 100 | 1: subs r2, r2, #32 |
| 101 | stmia r0!, {r1,r3,r4,r5,r6,r7,r12,lr} |
| 102 | bhs 1b |
| 103 | 2: add r2, r2, #32 |
| 104 | |
| 105 | /* conditionnaly stores 0 to 31 bytes */ |
| 106 | movs r2, r2, lsl #28 |
| 107 | stmcsia r0!, {r1,r3,r12,lr} |
| 108 | stmmiia r0!, {r1, lr} |
| 109 | movs r2, r2, lsl #2 |
| 110 | strcs r1, [r0], #4 |
| 111 | strmih r1, [r0], #2 |
| 112 | movs r2, r2, lsl #2 |
| 113 | strcsb r1, [r0] |
| 114 | ldmfd sp!, {r0, r4-r7, lr} |
| 115 | bx lr |
| 116 | .fnend |
| 117 | |