blob: bc0c060ac9238d907ac27726570a8a66c9971bf3 [file] [log] [blame]
agl@chromium.org21417a72010-08-13 17:05:28 +00001/*
epoger@google.comfd03db02011-07-28 14:24:55 +00002 * Copyright 2010 The Android Open Source Project
agl@chromium.org21417a72010-08-13 17:05:28 +00003 *
epoger@google.comfd03db02011-07-28 14:24:55 +00004 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
agl@chromium.org21417a72010-08-13 17:05:28 +00006 */
7
8/* Changes:
9 * 2010-08-11 Steve McIntyre <steve.mcintyre@arm.com>
10 * Added small changes to the two functions to make them work on the
11 * specified number of 16- or 32-bit values rather than the original
12 * code which was specified as a count of bytes. More verbose comments
13 * to aid future maintenance.
14 */
15
16 .text
17 .align
18
19 .global arm_memset32
20 .type arm_memset32, %function
21 .global arm_memset16
22 .type arm_memset16, %function
23
24/*
25 * Optimized memset functions for ARM.
26 *
27 * void arm_memset16(uint16_t* dst, uint16_t value, int count);
28 * void arm_memset32(uint32_t* dst, uint32_t value, int count);
29 *
30 */
31arm_memset16:
32 .fnstart
33 push {lr}
34
djsollen@google.coma44e6c62012-01-09 14:38:25 +000035 /* Multiply count by 2 - go from the number of 16-bit shorts
36 * to the number of bytes desired. */
37 mov r2, r2, lsl #1
38
agl@chromium.org21417a72010-08-13 17:05:28 +000039 /* expand the data to 32 bits */
40 orr r1, r1, lsl #16
41
42 /* align to 32 bits */
43 tst r0, #2
44 strneh r1, [r0], #2
45 subne r2, r2, #2
46
agl@chromium.org21417a72010-08-13 17:05:28 +000047 /* Now jump into the main loop below. */
48 b .Lwork_32
49 .fnend
50
51arm_memset32:
52 .fnstart
53 push {lr}
54
55 /* Multiply count by 4 - go from the number of 32-bit words to
56 * the number of bytes desired. */
57 mov r2, r2, lsl #2
58
59.Lwork_32:
60 /* Set up registers ready for writing them out. */
61 mov ip, r1
62 mov lr, r1
63
64 /* Try to align the destination to a cache line. Assume 32
65 * byte (8 word) cache lines, it's the common case. */
66 rsb r3, r0, #0
67 ands r3, r3, #0x1C
68 beq .Laligned32
69 cmp r3, r2
70 andhi r3, r2, #0x1C
71 sub r2, r2, r3
72
73 /* (Optionally) write any unaligned leading bytes.
74 * (0-28 bytes, length in r3) */
75 movs r3, r3, lsl #28
76 stmcsia r0!, {r1, lr}
77 stmcsia r0!, {r1, lr}
78 stmmiia r0!, {r1, lr}
79 movs r3, r3, lsl #2
80 strcs r1, [r0], #4
81
82 /* Now quickly loop through the cache-aligned data. */
83.Laligned32:
84 mov r3, r1
851: subs r2, r2, #32
86 stmhsia r0!, {r1,r3,ip,lr}
87 stmhsia r0!, {r1,r3,ip,lr}
88 bhs 1b
89 add r2, r2, #32
90
91 /* (Optionally) store any remaining trailing bytes.
92 * (0-30 bytes, length in r2) */
93 movs r2, r2, lsl #28
94 stmcsia r0!, {r1,r3,ip,lr}
95 stmmiia r0!, {r1,lr}
96 movs r2, r2, lsl #2
97 strcs r1, [r0], #4
98 strmih lr, [r0], #2
99
100 pop {pc}
101 .fnend