2 * Copyright (C) 1991,1992,1993,1997,1998,2003, 2005 Free Software Foundation, Inc.
3 * Copyright (c) 2011 The ChromiumOS Authors.
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 */
22 typedef uint32_t op_t
;
24 void *memset(void *dstpp
, int c
, size_t len
)
27 unsigned long int dstp
= (unsigned long int) dstpp
;
29 /* This explicit register allocation improves code very much indeed. */
30 register op_t x
asm("ax");
32 x
= (unsigned char) c
;
34 /* Clear the direction flag, so filling will move forward. */
37 /* This threshold value is optimal. */
39 /* Fill X with four copies of the char we want to fill with. */
43 /* Adjust LEN for the bytes handled in the first loop. */
44 len
-= (-dstp
) % sizeof(op_t
);
47 * There are at least some bytes to set. No need to test for
48 * LEN == 0 in this alignment loop.
51 /* Fill bytes until DSTP is aligned on a longword boundary. */
54 "stosb" /* %0, %2, %3 */ :
55 "=D" (dstp
), "=c" (d0
) :
56 "0" (dstp
), "1" ((-dstp
) % sizeof(op_t
)), "a" (x
) :
62 "stosl" /* %0, %2, %3 */ :
63 "=D" (dstp
), "=c" (d0
) :
64 "0" (dstp
), "1" (len
/ sizeof(op_t
)), "a" (x
) :
69 /* Write the last few bytes. */
72 "stosb" /* %0, %2, %3 */ :
73 "=D" (dstp
), "=c" (d0
) :
74 "0" (dstp
), "1" (len
), "a" (x
) :
80 void *memcpy(void *dest
, const void *src
, size_t n
)
82 unsigned long d0
, d1
, d2
;
84 #if CONFIG(LP_ARCH_X86_64)
89 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
90 : "0" (n
>> 3), "g" (n
& 7), "1" (dest
), "2" (src
)
98 : "=&c" (d0
), "=&D" (d1
), "=&S" (d2
)
99 : "0" (n
>> 2), "g" (n
& 3), "1" (dest
), "2" (src
)