tree: drop last paragraph of GPL copyright header
[coreboot.git] / src / arch / x86 / memset.c
blobc87a3b3996c8b9f99f555a4bd56c51eb0bd68e81
1 /*
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 */
18 #include <string.h>
19 #include <stdint.h>
21 typedef uint32_t op_t;
23 void *memset(void *dstpp, int c, size_t len)
25 int d0;
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. */
34 asm volatile("cld");
36 /* This threshold value is optimal. */
37 if (len >= 12) {
38 /* Fill X with four copies of the char we want to fill with. */
39 x |= (x << 8);
40 x |= (x << 16);
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. */
51 asm volatile(
52 "rep\n"
53 "stosb" /* %0, %2, %3 */ :
54 "=D" (dstp), "=c" (d0) :
55 "0" (dstp), "1" ((-dstp) % sizeof(op_t)), "a" (x) :
56 "memory");
58 /* Fill longwords. */
59 asm volatile(
60 "rep\n"
61 "stosl" /* %0, %2, %3 */ :
62 "=D" (dstp), "=c" (d0) :
63 "0" (dstp), "1" (len / sizeof(op_t)), "a" (x) :
64 "memory");
65 len %= sizeof(op_t);
68 /* Write the last few bytes. */
69 asm volatile(
70 "rep\n"
71 "stosb" /* %0, %2, %3 */ :
72 "=D" (dstp), "=c" (d0) :
73 "0" (dstp), "1" (len), "a" (x) :
74 "memory");
76 return dstpp;