]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/i386/i686/memset.S
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / i386 / i686 / memset.S
1 /* memset/bzero -- set memory area to CH/0
2 Highly optimized version for ix86, x>=6.
3 Copyright (C) 1999-2018 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
6
7 The GNU C Library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
11
12 The GNU C Library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, see
19 <http://www.gnu.org/licenses/>. */
20
21 #include <sysdep.h>
22 #include "asm-syntax.h"
23
24 #define PARMS 4+4 /* space for 1 saved reg */
25 #ifdef USE_AS_BZERO
26 # define DEST PARMS
27 # define LEN DEST+4
28 #else
29 # define RTN PARMS
30 # define DEST RTN
31 # define CHR DEST+4
32 # define LEN CHR+4
33 #endif
34
35 .text
36 #if defined SHARED && IS_IN (libc) && !defined USE_AS_BZERO
37 ENTRY_CHK (__memset_chk)
38 movl 12(%esp), %eax
39 cmpl %eax, 16(%esp)
40 jb HIDDEN_JUMPTARGET (__chk_fail)
41 END_CHK (__memset_chk)
42 #endif
43 ENTRY (memset)
44
45 cld
46 pushl %edi
47 cfi_adjust_cfa_offset (4)
48 movl DEST(%esp), %edx
49 movl LEN(%esp), %ecx
50 #ifdef USE_AS_BZERO
51 xorl %eax, %eax /* fill with 0 */
52 #else
53 movzbl CHR(%esp), %eax
54 #endif
55 jecxz 1f
56 movl %edx, %edi
57 cfi_rel_offset (edi, 0)
58 andl $3, %edx
59 jz 2f /* aligned */
60 jp 3f /* misaligned at 3, store just one byte below */
61 stosb /* misaligned at 1 or 2, store two bytes */
62 decl %ecx
63 jz 1f
64 3: stosb
65 decl %ecx
66 jz 1f
67 xorl $1, %edx
68 jnz 2f /* was misaligned at 2 or 3, now aligned */
69 stosb /* was misaligned at 1, store third byte */
70 decl %ecx
71 2: movl %ecx, %edx
72 shrl $2, %ecx
73 andl $3, %edx
74 #ifndef USE_AS_BZERO
75 imul $0x01010101, %eax
76 #endif
77 rep
78 stosl
79 movl %edx, %ecx
80 rep
81 stosb
82
83 1:
84 #ifndef USE_AS_BZERO
85 movl DEST(%esp), %eax /* start address of destination is result */
86 #endif
87 popl %edi
88 cfi_adjust_cfa_offset (-4)
89 cfi_restore (edi)
90
91 ret
92 END (memset)
93 libc_hidden_builtin_def (memset)