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