1/* Copyright (C) 1998-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library. If not, see
16 <https://www.gnu.org/licenses/>. */
17
18/* Thumb requires excessive IT insns here. */
19#define NO_THUMB
20#include <sysdep.h>
21
22 .text
23 .syntax unified
24
25/* void *memset (dstpp, c, len) */
26
27ENTRY(memset)
28 mov r3, r0
29 cmp r2, #8
30 bcc 2f @ less than 8 bytes to move
31
321:
33 tst r3, #3 @ aligned yet?
34 strbne r1, [r3], #1
35 subne r2, r2, #1
36 bne 1b
37
38 and r1, r1, #255 @ clear any sign bits
39 orr r1, r1, r1, lsl $8
40 orr r1, r1, r1, lsl $16
41 mov ip, r1
42
431:
44 subs r2, r2, #8
45 stmiacs r3!, {r1, ip} @ store up to 32 bytes per loop iteration
46 subscs r2, r2, #8
47 stmiacs r3!, {r1, ip}
48 subscs r2, r2, #8
49 stmiacs r3!, {r1, ip}
50 subscs r2, r2, #8
51 stmiacs r3!, {r1, ip}
52 bcs 1b
53
54 and r2, r2, #7
552:
56 subs r2, r2, #1 @ store up to 4 bytes per loop iteration
57 strbcs r1, [r3], #1
58 subscs r2, r2, #1
59 strbcs r1, [r3], #1
60 subscs r2, r2, #1
61 strbcs r1, [r3], #1
62 subscs r2, r2, #1
63 strbcs r1, [r3], #1
64 bcs 2b
65
66 DO_RET(lr)
67END(memset)
68libc_hidden_builtin_def (memset)
69

source code of glibc/sysdeps/arm/memset.S