Update copyright notices with scripts/update-copyrights
[glibc.git] / sysdeps / x86_64 / memset.S
blobdb4fb842ef1435d90d2c480a0783c670181c290f
1 /* memset/bzero -- set memory area to CH/0
2    Optimized version for x86-64.
3    Copyright (C) 2002-2014 Free Software Foundation, Inc.
4    This file is part of the GNU C Library.
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.
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.
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/>.  */
20 #include <sysdep.h>
22         .text
23 #if !defined NOT_IN_libc
24 ENTRY(__bzero)
25         movq    %rdi, %rax /* Set return value.  */
26         movq    %rsi, %rdx /* Set n.  */
27         pxor    %xmm8, %xmm8
28         jmp     L(entry_from_bzero)
29 END(__bzero)
30 weak_alias (__bzero, bzero)
32 /* Like memset but takes additional parameter with return value.  */
33 ENTRY(__memset_tail)
34         movq    %rcx, %rax /* Set return value.  */
36         movd    %esi, %xmm8
37         punpcklbw       %xmm8, %xmm8
38         punpcklwd       %xmm8, %xmm8
39         pshufd  $0, %xmm8, %xmm8
41         jmp     L(entry_from_bzero)
42 END(__memset_tail)
43 #endif
45 #if defined PIC && !defined NOT_IN_libc
46 ENTRY_CHK (__memset_chk)
47         cmpq    %rdx, %rcx
48         jb      HIDDEN_JUMPTARGET (__chk_fail)
49 END_CHK (__memset_chk)
50 #endif
52 ENTRY (memset)
53         movd    %esi, %xmm8
54         movq    %rdi, %rax
55         punpcklbw       %xmm8, %xmm8
56         punpcklwd       %xmm8, %xmm8
57         pshufd  $0, %xmm8, %xmm8
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  %xmm8, (%rdi)
65         movdqu  %xmm8, -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  %xmm8, 16(%rdi)
73         movdqu  %xmm8, -32(%rdi,%rdx)
74         ret
75         .p2align 4
76 L(loop_start):
77         leaq    64(%rdi), %rcx
78         movdqu  %xmm8, (%rdi)
79         andq    $-64, %rcx
80         movdqu  %xmm8, -16(%rdi,%rdx)
81         movdqu  %xmm8, 16(%rdi)
82         movdqu  %xmm8, -32(%rdi,%rdx)
83         movdqu  %xmm8, 32(%rdi)
84         movdqu  %xmm8, -48(%rdi,%rdx)
85         movdqu  %xmm8, 48(%rdi)
86         movdqu  %xmm8, -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  %xmm8, (%rcx)
94         movdqa  %xmm8, 16(%rcx)
95         movdqa  %xmm8, 32(%rcx)
96         movdqa  %xmm8, 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 %xmm8, %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
125 END (memset)
126 libc_hidden_builtin_def (memset)
128 #if defined PIC && !defined NOT_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