1 /* memset/bzero -- set memory area to CH/0
2 Optimized version for x86-64.
3 Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
5 Contributed by Andreas Jaeger <aj@suse.de>.
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.
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.
17 You should have received a copy of the GNU Lesser General Public
18 License along with the GNU C Library; if not, write to the Free
19 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
23 #include "asm-syntax.h"
27 /* BEWARE: `#ifdef memset' means that memset is redefined as `bzero' */
28 #define BZERO_P (defined memset)
30 /* This is somehow experimental and could made dependend on the cache
35 #if !BZERO_P && defined PIC && !defined NOT_IN_libc
38 jb HIDDEN_JUMPTARGET (__chk_fail)
43 mov %rsi,%rdx /* Adjust parameter. */
44 xorl %esi,%esi /* Fill with 0s. */
46 cmp $0x7,%rdx /* Check for small length. */
47 mov %rdi,%rcx /* Save ptr as return value. */
51 mov %rsi,%r8 /* Just copy 0. */
53 /* Populate 8 bit data to full 64-bit. */
54 movabs $0x0101010101010101,%r8
58 test $0x7,%edi /* Check for alignment. */
62 1: /* Align ptr to 8 byte. */
69 2: /* Check for really large regions. */
77 3: /* Copy 64 bytes. */
90 4: /* Copy final bytes. */
96 5: /* First in chunks of 8 bytes. */
106 8: /* And finally as bytes (up to 7). */
115 /* Load result (only if used as memset). */
116 mov %rdi,%rax /* start address of destination is result */
121 11: /* Copy 64 bytes without polluting the cache. */
122 /* We could use movntdq %xmm0,(%rcx) here to further
123 speed up for large cases but let's not use XMM registers. */
126 movnti %r8,0x10(%rcx)
127 movnti %r8,0x18(%rcx)
128 movnti %r8,0x20(%rcx)
129 movnti %r8,0x28(%rcx)
130 movnti %r8,0x30(%rcx)
131 movnti %r8,0x38(%rcx)
139 libc_hidden_builtin_def (memset)
142 #if !BZERO_P && defined PIC && !defined NOT_IN_libc
143 strong_alias (__memset_chk, __memset_zero_constant_len_parameter)
144 .section .gnu.warning.__memset_zero_constant_len_parameter
145 .string "memset used with constant zero length parameter; this could be due to transposed parameters"