drivers/net/stmmac/: add HAS_IOMEM dependency
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / microblaze / lib / memset.c
blobecfb663e1fc159dc33a922b894910f4912d6ed09
1 /*
2 * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2008-2009 PetaLogix
4 * Copyright (C) 2007 John Williams
6 * Reasonably optimised generic C-code for memset on Microblaze
7 * This is generic C code to do efficient, alignment-aware memcpy.
9 * It is based on demo code originally Copyright 2001 by Intel Corp, taken from
10 * http://www.embedded.com/showArticle.jhtml?articleID=19205567
12 * Attempts were made, unsuccessfully, to contact the original
13 * author of this code (Michael Morrow, Intel). Below is the original
14 * copyright notice.
16 * This software has been developed by Intel Corporation.
17 * Intel specifically disclaims all warranties, express or
18 * implied, and all liability, including consequential and
19 * other indirect damages, for the use of this program, including
20 * liability for infringement of any proprietary rights,
21 * and including the warranties of merchantability and fitness
22 * for a particular purpose. Intel does not assume any
23 * responsibility for and errors which may appear in this program
24 * not any responsibility to update it.
27 #include <linux/types.h>
28 #include <linux/stddef.h>
29 #include <linux/compiler.h>
30 #include <linux/module.h>
31 #include <linux/string.h>
33 #ifdef __HAVE_ARCH_MEMSET
34 void *memset(void *v_src, int c, __kernel_size_t n)
36 char *src = v_src;
37 #ifdef CONFIG_OPT_LIB_FUNCTION
38 uint32_t *i_src;
39 uint32_t w32 = 0;
40 #endif
41 /* Truncate c to 8 bits */
42 c = (c & 0xFF);
44 #ifdef CONFIG_OPT_LIB_FUNCTION
45 if (unlikely(c)) {
46 /* Make a repeating word out of it */
47 w32 = c;
48 w32 |= w32 << 8;
49 w32 |= w32 << 16;
52 if (likely(n >= 4)) {
53 /* Align the destination to a word boundary */
54 /* This is done in an endian independant manner */
55 switch ((unsigned) src & 3) {
56 case 1:
57 *src++ = c;
58 --n;
59 case 2:
60 *src++ = c;
61 --n;
62 case 3:
63 *src++ = c;
64 --n;
67 i_src = (void *)src;
69 /* Do as many full-word copies as we can */
70 for (; n >= 4; n -= 4)
71 *i_src++ = w32;
73 src = (void *)i_src;
75 #endif
76 /* Simple, byte oriented memset or the rest of count. */
77 while (n--)
78 *src++ = c;
80 return v_src;
82 EXPORT_SYMBOL(memset);
83 #endif /* __HAVE_ARCH_MEMSET */