1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
/* memset/bzero -- set memory area to CH/0
Optimized version for x86-64.
Copyright (C) 2002-2013 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; if not, see
<http://www.gnu.org/licenses/>. */
#include <sysdep.h>
#ifndef ALIGN
# define ALIGN(n) .p2align n
#endif
.text
#if !defined NOT_IN_libc
ENTRY(__bzero)
testq %rsi, %rsi
jz L(only_return)
#if defined __CHKP__ && defined __CHKWR__
bndcl (%rdi), %bnd0
bndcu -1(%rdi, %rsi), %bnd0
# endif
mov %rdi, %rax
movq %rdi, %rax /* Set return value. */
movq %rsi, %rdx /* Set n. */
pxor %xmm8, %xmm8
jmp L(entry_from_bzero)
END(__bzero)
weak_alias (__bzero, bzero)
/* Like memset but takes additional parameter with return value. */
ENTRY(__memset_tail)
movq %rcx, %rax /* Set return value. */
movd %esi, %xmm8
punpcklbw %xmm8, %xmm8
punpcklwd %xmm8, %xmm8
pshufd $0, %xmm8, %xmm8
jmp L(entry_from_bzero)
END(__memset_tail)
#endif
#if defined PIC && !defined NOT_IN_libc
ENTRY_CHK (__memset_chk)
cmpq %rdx, %rcx
jb HIDDEN_JUMPTARGET (__chk_fail)
END_CHK (__memset_chk)
#endif
#if defined __CHKP__ && defined __CHKWR__
ENTRY (chkp_memset_nochk)
jmp L(entry_from_chkp_memset_nochk)
END (chkp_memset_nochk)
#endif
ENTRY (memset)
testq %rdx, %rdx
jz L(only_return)
#if defined __CHKP__ && defined __CHKWR__
bndcl (%rdi), %bnd0
bndcu -1(%rdi, %rdx), %bnd0
L(entry_from_chkp_memset_nochk):
#endif
movd %esi, %xmm8
movq %rdi, %rax
punpcklbw %xmm8, %xmm8
punpcklwd %xmm8, %xmm8
pshufd $0, %xmm8, %xmm8
L(entry_from_bzero):
cmpq $64, %rdx
ja L(loop_start)
cmpq $16, %rdx
jbe L(less_16_bytes)
cmpq $32, %rdx
movdqu %xmm8, (%rdi)
movdqu %xmm8, -16(%rdi,%rdx)
ja L(between_32_64_bytes)
L(return):
rep
ret
L(only_return):
movq %rdi, %rax
ret
ALIGN (4)
L(between_32_64_bytes):
movdqu %xmm8, 16(%rdi)
movdqu %xmm8, -32(%rdi,%rdx)
ret
ALIGN (4)
L(loop_start):
leaq 64(%rdi), %rcx
movdqu %xmm8, (%rdi)
andq $-64, %rcx
movdqu %xmm8, -16(%rdi,%rdx)
movdqu %xmm8, 16(%rdi)
movdqu %xmm8, -32(%rdi,%rdx)
movdqu %xmm8, 32(%rdi)
movdqu %xmm8, -48(%rdi,%rdx)
movdqu %xmm8, 48(%rdi)
movdqu %xmm8, -64(%rdi,%rdx)
addq %rdi, %rdx
andq $-64, %rdx
cmpq %rdx, %rcx
je L(return)
ALIGN (4)
L(loop):
movdqa %xmm8, (%rcx)
movdqa %xmm8, 16(%rcx)
movdqa %xmm8, 32(%rcx)
movdqa %xmm8, 48(%rcx)
addq $64, %rcx
cmpq %rcx, %rdx
jne L(loop)
rep
ret
L(less_16_bytes):
movq %xmm8, %rcx
testb $24, %dl
jne L(between8_16bytes)
testb $4, %dl
jne L(between4_7bytes)
testb $1, %dl
je L(odd_byte)
movb %cl, (%rdi)
L(odd_byte):
testb $2, %dl
je L(return)
movw %cx, -2(%rax,%rdx)
ret
L(between4_7bytes):
movl %ecx, (%rdi)
movl %ecx, -4(%rdi,%rdx)
ret
L(between8_16bytes):
movq %rcx, (%rdi)
movq %rcx, -8(%rdi,%rdx)
ret
END (memset)
libc_hidden_builtin_def (memset)
#if defined __CHKP__ && defined __CHKWR__
weak_alias (memset, chkp_memset_nobnd)
weak_alias (chkp_memset_nochk, chkp_memset_nobnd_nochk)
#endif
#if defined PIC && !defined NOT_IN_libc && !defined USE_MULTIARCH
strong_alias (__memset_chk, __memset_zero_constant_len_parameter)
.section .gnu.warning.__memset_zero_constant_len_parameter
.string "memset used with constant zero length parameter; this could be due to transposed parameters"
#endif
|