1/* memset/bzero -- set memory area to CH/0 2 Highly optimized version for ix86, x>=6. 3 Copyright (C) 1999-2021 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 <https://www.gnu.org/licenses/>. */ 19 20#include <sysdep.h> 21#include "asm-syntax.h" 22 23#define PARMS 4+4 /* space for 1 saved reg */ 24#ifdef USE_AS_BZERO 25# define DEST PARMS 26# define LEN DEST+4 27#else 28# define RTN PARMS 29# define DEST RTN 30# define CHR DEST+4 31# define LEN CHR+4 32#endif 33 34 .text 35#if defined SHARED && IS_IN (libc) && !defined USE_AS_BZERO 36ENTRY_CHK (__memset_chk) 37 movl 12(%esp), %eax 38 cmpl %eax, 16(%esp) 39 jb HIDDEN_JUMPTARGET (__chk_fail) 40END_CHK (__memset_chk) 41#endif 42ENTRY (memset) 43 44 cld 45 pushl %edi 46 cfi_adjust_cfa_offset (4) 47 movl DEST(%esp), %edx 48 movl LEN(%esp), %ecx 49#ifdef USE_AS_BZERO 50 xorl %eax, %eax /* fill with 0 */ 51#else 52 movzbl CHR(%esp), %eax 53#endif 54 jecxz 1f 55 movl %edx, %edi 56 cfi_rel_offset (edi, 0) 57 andl $3, %edx 58 jz 2f /* aligned */ 59 jp 3f /* misaligned at 3, store just one byte below */ 60 stosb /* misaligned at 1 or 2, store two bytes */ 61 decl %ecx 62 jz 1f 633: stosb 64 decl %ecx 65 jz 1f 66 xorl $1, %edx 67 jnz 2f /* was misaligned at 2 or 3, now aligned */ 68 stosb /* was misaligned at 1, store third byte */ 69 decl %ecx 702: movl %ecx, %edx 71 shrl $2, %ecx 72 andl $3, %edx 73#ifndef USE_AS_BZERO 74 imul $0x01010101, %eax 75#endif 76 rep 77 stosl 78 movl %edx, %ecx 79 rep 80 stosb 81 821: 83#ifndef USE_AS_BZERO 84 movl DEST(%esp), %eax /* start address of destination is result */ 85#endif 86 popl %edi 87 cfi_adjust_cfa_offset (-4) 88 cfi_restore (edi) 89 90 ret 91END (memset) 92libc_hidden_builtin_def (memset) 93