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 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 /* From glibc-2.14, sysdeps/i386/memset.c */
21 typedef uint32_t op_t
;
23 void *memset(void *dstpp
, int c
, size_t len
)
26 unsigned long int dstp
= (unsigned long int) dstpp
;
28 /* This explicit register allocation improves code very much indeed. */
29 register op_t x
asm("ax");
31 x
= (unsigned char) c
;
33 /* Clear the direction flag, so filling will move forward. */
36 /* This threshold value is optimal. */
38 /* Fill X with four copies of the char we want to fill with. */
42 /* Adjust LEN for the bytes handled in the first loop. */
43 len
-= (-dstp
) % sizeof(op_t
);
46 * There are at least some bytes to set. No need to test for
47 * LEN == 0 in this alignment loop.
50 /* Fill bytes until DSTP is aligned on a longword boundary. */
53 "stosb" /* %0, %2, %3 */ :
54 "=D" (dstp
), "=c" (d0
) :
55 "0" (dstp
), "1" ((-dstp
) % sizeof(op_t
)), "a" (x
) :
61 "stosl" /* %0, %2, %3 */ :
62 "=D" (dstp
), "=c" (d0
) :
63 "0" (dstp
), "1" (len
/ sizeof(op_t
)), "a" (x
) :
68 /* Write the last few bytes. */
71 "stosb" /* %0, %2, %3 */ :
72 "=D" (dstp
), "=c" (d0
) :
73 "0" (dstp
), "1" (len
), "a" (x
) :