2 * Copyright (C) 1991,1992,1993,1997,1998,2003, 2005 Free Software Foundation, Inc.
3 * This file is part of the GNU C Library.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24 /* From glibc-2.14, sysdeps/i386/memset.c */
29 typedef uint32_t op_t;
31 void *memset(void *dstpp, int c, size_t len)
34 unsigned long int dstp = (unsigned long int) dstpp;
36 /* This explicit register allocation improves code very much indeed. */
37 register op_t x asm("ax");
39 x = (unsigned char) c;
41 /* Clear the direction flag, so filling will move forward. */
44 /* This threshold value is optimal. */
46 /* Fill X with four copies of the char we want to fill with. */
50 /* Adjust LEN for the bytes handled in the first loop. */
51 len -= (-dstp) % sizeof(op_t);
54 * There are at least some bytes to set. No need to test for
55 * LEN == 0 in this alignment loop.
58 /* Fill bytes until DSTP is aligned on a longword boundary. */
61 "stosb" /* %0, %2, %3 */ :
62 "=D" (dstp), "=c" (d0) :
63 "0" (dstp), "1" ((-dstp) % sizeof(op_t)), "a" (x) :
69 "stosl" /* %0, %2, %3 */ :
70 "=D" (dstp), "=c" (d0) :
71 "0" (dstp), "1" (len / sizeof(op_t)), "a" (x) :
76 /* Write the last few bytes. */
79 "stosb" /* %0, %2, %3 */ :
80 "=D" (dstp), "=c" (d0) :
81 "0" (dstp), "1" (len), "a" (x) :