login
Header Space

 
 

[PATCH 16/56] microblaze_v2: supported function for memory - kernel/lib

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-kernel@...>
Cc: <arnd@...>, <linux-arch@...>, <stephen.neuendorffer@...>, <John.Linn@...>, <john.williams@...>, <matthew@...>, <will.newton@...>, <drepper@...>, <microblaze-uclinux@...>, <grant.likely@...>, Michal Simek <monstr@...>
Date: Sunday, May 4, 2008 - 7:41 am

From: Michal Simek <monstr@monstr.eu>


Signed-off-by: Michal Simek <monstr@monstr.eu>
---
 arch/microblaze/lib/memcpy.c  |  162 +++++++++++++++++++++++++++++++++++++
 arch/microblaze/lib/memmove.c |  176 +++++++++++++++++++++++++++++++++++++++++
 arch/microblaze/lib/memset.c  |   77 ++++++++++++++++++
 3 files changed, 415 insertions(+), 0 deletions(-)
 create mode 100644 arch/microblaze/lib/memcpy.c
 create mode 100644 arch/microblaze/lib/memmove.c
 create mode 100644 arch/microblaze/lib/memset.c

diff --git a/arch/microblaze/lib/memcpy.c b/arch/microblaze/lib/memcpy.c
new file mode 100644
index 0000000..8dc5b90
--- /dev/null
+++ b/arch/microblaze/lib/memcpy.c
@@ -0,0 +1,162 @@
+/*
+ * arch/microblaze/lib/memcpy.c
+ *
+ * Copyright (C) 2008 Michal Simek <monstr@monstr.eu>
+ *
+ * Reasonably optimised generic C-code for memcpy on Microblaze
+ * This is generic C code to do efficient, alignment-aware memcpy.
+ *
+ * It is based on demo code originally Copyright 2001 by Intel Corp, taken from
+ * http://www.embedded.com/showArticle.jhtml?articleID=19205567
+ *
+ * Attempts were made, unsuccesfully, to contact the original
+ * author of this code (Michael Morrow, Intel).  Below is the original
+ * copyright notice.
+ *
+ * This software has been developed by Intel Corporation.
+ * Intel specifically disclaims all warranties, express or
+ * implied, and all liability, including consequential and
+ * other indirect damages, for the use of this program, including
+ * liability for infringement of any proprietary rights,
+ * and including the warranties of merchantability and fitness
+ * for a particular purpose. Intel does not assume any
+ * responsibility for and errors which may appear in this program
+ * not any responsibility to update it.
+ */
+
+#include <linux/types.h>
+#include <linux/stddef.h>
+#include <linux/compiler.h>
+#include <linux/module.h>
+
+#include <asm/string.h>
+#include <asm/system.h>
+
+#ifdef __HAVE_ARCH_MEMCPY
+void *memcpy(void *v_dst, const void *v_src, __kernel_size_t c)
+{
+	const char *src = v_src;
+	char *dst = v_dst;
+#ifndef CONFIG_OPT_LIB_FUNCTION
+	/* Simple, byte oriented memcpy. */
+	while (c--)
+		*dst++ = *src++;
+
+	return v_dst;
+#else
+	/* The following code tries to optimize the copy by using unsigned
+	 * alignment. This will work fine if both source and destination are
+	 * aligned on the same boundary. However, if they are aligned on
+	 * different boundaries shifts will be necessary. This might result in
+	 * bad performance on MicroBlaze systems without a barrel shifter.
+	 */
+	const uint32_t *i_src;
+	uint32_t *i_dst;
+
+	if (c >= 4) {
+		unsigned  value, buf_hold;
+
+		/* Align the dstination to a word boundry. */
+		/* This is done in an endian independant manner. */
+		switch ((unsigned long)dst & 3) {
+		case 1:
+			*dst++ = *src++;
+			--c;
+		case 2:
+			*dst++ = *src++;
+			--c;
+		case 3:
+			*dst++ = *src++;
+			--c;
+		}
+
+		i_dst = (void *)dst;
+
+		/* Choose a copy scheme based on the source */
+		/* alignment relative to dstination. */
+		switch ((unsigned long)src & 3) {
+		case 0x0:	/* Both byte offsets are aligned */
+			i_src  = (const void *)src;
+
+			for (; c >= 4; c -= 4)
+				*i_dst++ = *i_src++;
+
+			src  = (const void *)i_src;
+			break;
+		case 0x1:	/* Unaligned - Off by 1 */
+			/* Word align the source */
+			i_src = (const void *) ((unsigned)src & ~3);
+
+			/* Load the holding buffer */
+			buf_hold = *i_src++ << 8;
+
+			for (; c >= 4; c -= 4) {
+				value = *i_src++;
+				*i_dst++ = buf_hold | value >> 24;
+				buf_hold = value << 8;
+			}
+
+			/* Realign the source */
+			src = (const void *)i_src;
+			src -= 3;
+			break;
+		case 0x2:	/* Unaligned - Off by 2 */
+			/* Word align the source */
+			i_src = (const void *) ((unsigned)src & ~3);
+
+			/* Load the holding buffer */
+			buf_hold = *i_src++ << 16;
+
+			for (; c >= 4; c -= 4) {
+				value = *i_src++;
+				*i_dst++ = buf_hold | value >> 16;
+				buf_hold = value << 16;
+			}
+
+			/* Realign the source */
+			src = (const void *)i_src;
+			src -= 2;
+			break;
+		case 0x3:	/* Unaligned - Off by 3 */
+			/* Word align the source */
+			i_src = (const void *) ((unsigned)src & ~3);
+
+			/* Load the holding buffer */
+			buf_hold = *i_src++ << 24;
+
+			for (; c >= 4; c -= 4) {
+				value = *i_src++;
+				*i_dst++ = buf_hold | value >> 8;
+				buf_hold = value << 24;
+			}
+
+			/* Realign the source */
+			src = (const void *)i_src;
+			src -= 1;
+			break;
+		}
+		dst = (void *)i_dst;
+	}
+
+	/* Finish off any remaining bytes */
+	/* simple fast copy, ... unless a cache boundry is crossed */
+	switch (c) {
+	case 3:
+		*dst++ = *src++;
+	case 2:
+		*dst++ = *src++;
+	case 1:
+		*dst++ = *src++;
+	}
+
+	return v_dst;
+#endif
+}
+EXPORT_SYMBOL(memcpy);
+#endif /* __HAVE_ARCH_MEMCPY */
+
+
+void *cacheable_memcpy(void *d, const void *s, __kernel_size_t c)
+{
+	return memcpy(d, s, c);
+}
diff --git a/arch/microblaze/lib/memmove.c b/arch/microblaze/lib/memmove.c
new file mode 100644
index 0000000..99233be
--- /dev/null
+++ b/arch/microblaze/lib/memmove.c
@@ -0,0 +1,176 @@
+/*
+ * arch/microblaze/lib/memmove.c
+ *
+ * Copyright (C) 2008 Michal Simek <monstr@monstr.eu>
+ *
+ * Reasonably optimised generic C-code for memcpy on Microblaze
+ * This is generic C code to do efficient, alignment-aware memmove.
+ *
+ * It is based on demo code originally Copyright 2001 by Intel Corp, taken from
+ * http://www.embedded.com/showArticle.jhtml?articleID=19205567
+ *
+ * Attempts were made, unsuccesfully, to contact the original
+ * author of this code (Michael Morrow, Intel).  Below is the original
+ * copyright notice.
+ *
+ * This software has been developed by Intel Corporation.
+ * Intel specifically disclaims all warranties, express or
+ * implied, and all liability, including consequential and
+ * other indirect damages, for the use of this program, including
+ * liability for infringement of any proprietary rights,
+ * and including the warranties of merchantability and fitness
+ * for a particular purpose. Intel does not assume any
+ * responsibility for and errors which may appear in this program
+ * not any responsibility to update it.
+ */
+
+#include <linux/types.h>
+#include <linux/stddef.h>
+#include <linux/compiler.h>
+#include <linux/module.h>
+
+#include <asm/string.h>
+
+#ifdef __HAVE_ARCH_MEMMOVE
+void *memmove(void *v_dst, const void *v_src, __kernel_size_t c)
+{
+	const char *src = v_src;
+	char *dst = v_dst;
+
+#ifdef CONFIG_OPT_LIB_FUNCTION
+	const uint32_t *i_src;
+	uint32_t *i_dst;
+#endif
+
+	if (!c)
+		return v_dst;
+
+	/* Use memcpy when source is higher than dest */
+	if (v_dst <= v_src)
+		return memcpy(v_dst, v_src, c);
+
+#ifndef CONFIG_OPT_LIB_FUNCTION
+	/* copy backwards, from end to beginning */
+	src += c;
+	dst += c;
+
+	/* Simple, byte oriented memmove. */
+	while (c--)
+		*--dst = *--src;
+
+	return v_dst;
+#else
+	/* The following code tries to optimize the copy by using unsigned
+	 * alignment. This will work fine if both source and destination are
+	 * aligned on the same boundary. However, if they are aligned on
+	 * different boundaries shifts will be necessary. This might result in
+	 * bad performance on MicroBlaze systems without a barrel shifter.
+	 */
+	/* FIXME this part needs more test */
+	/* Do a descending copy - this is a bit trickier! */
+	dst += c;
+	src += c;
+
+	if (c >= 4) {
+		unsigned  value, buf_hold;
+
+		/* Align the destination to a word boundry. */
+		/* This is done in an endian independant manner. */
+
+		switch ((unsigned long)dst & 3) {
+		case 3:
+			*--dst = *--src;
+			--c;
+		case 2:
+			*--dst = *--src;
+			--c;
+		case 1:
+			*--dst = *--src;
+			--c;
+		}
+
+		i_dst = (void *)dst;
+		/* Choose a copy scheme based on the source */
+		/* alignment relative to dstination. */
+		switch ((unsigned long)src & 3) {
+		case 0x0:	/* Both byte offsets are aligned */
+
+			i_src  = (const void *)src;
+
+			for (; c >= 4; c -= 4)
+				*--i_dst = *--i_src;
+
+			src  = (const void *)i_src;
+			break;
+		case 0x1:	/* Unaligned - Off by 1 */
+			/* Word align the source */
+			i_src = (const void *) (((unsigned)src + 4) & ~3);
+
+			/* Load the holding buffer */
+			buf_hold = *--i_src >> 24;
+
+			for (; c >= 4; c -= 4) {
+				value = *--i_src;
+				*--i_dst = buf_hold << 8 | value;
+				buf_hold = value >> 24;
+			}
+
+			/* Realign the source */
+			src = (const void *)i_src;
+			src += 1;
+			break;
+		case 0x2:	/* Unaligned - Off by 2 */
+			/* Word align the source */
+			i_src = (const void *) (((unsigned)src + 4) & ~3);
+
+			/* Load the holding buffer */
+			buf_hold = *--i_src >> 16;
+
+			for (; c >= 4; c -= 4) {
+				value = *--i_src;
+				*--i_dst = buf_hold << 16 | value;
+				buf_hold = value >> 16;
+			}
+
+			/* Realign the source */
+			src = (const void *)i_src;
+			src += 2;
+			break;
+		case 0x3:	/* Unaligned - Off by 3 */
+			/* Word align the source */
+			i_src = (const void *) (((unsigned)src + 4) & ~3);
+
+			/* Load the holding buffer */
+			buf_hold = *--i_src >> 8;
+
+			for (; c >= 4; c -= 4) {
+				value = *--i_src;
+				*--i_dst = buf_hold << 24 | value;
+				buf_hold = value >> 8;
+			}
+
+			/* Realign the source */
+			src = (const void *)i_src;
+			src += 3;
+			break;
+		}
+		dst = (void *)i_dst;
+	}
+
+	/* simple fast copy, ... unless a cache boundry is crossed */
+	/* Finish off any remaining bytes */
+	switch (c) {
+	case 4:
+		*--dst = *--src;
+	case 3:
+		*--dst = *--src;
+	case 2:
+		*--dst = *--src;
+	case 1:
+		*--dst = *--src;
+	}
+	return v_dst;
+#endif
+}
+EXPORT_SYMBOL(memmove);
+#endif /* __HAVE_ARCH_MEMMOVE */
diff --git a/arch/microblaze/lib/memset.c b/arch/microblaze/lib/memset.c
new file mode 100644
index 0000000..5697d66
--- /dev/null
+++ b/arch/microblaze/lib/memset.c
@@ -0,0 +1,77 @@
+/*
+ * arch/microblaze/lib/memset.c
+ *
+ * Copyright (C) 2008 Michal Simek <monstr@monstr.eu>
+ *
+ * Reasonably optimised generic C-code for memset on Microblaze
+ * This is generic C code to do efficient, alignment-aware memcpy.
+ *
+ * It is based on demo code originally Copyright 2001 by Intel Corp, taken from
+ * http://www.embedded.com/showArticle.jhtml?articleID=19205567
+ *
+ * Attempts were made, unsuccesfully, to contact the original
+ * author of this code (Michael Morrow, Intel).  Below is the original
+ * copyright notice.
+ *
+ * This software has been developed by Intel Corporation.
+ * Intel specifically disclaims all warranties, express or
+ * implied, and all liability, including consequential and
+ * other indirect damages, for the use of this program, including
+ * liability for infringement of any proprietary rights,
+ * and including the warranties of merchantability and fitness
+ * for a particular purpose. Intel does not assume any
+ * responsibility for and errors which may appear in this program
+ * not any responsibility to update it.
+ */
+
+#include <linux/types.h>
+#include <linux/stddef.h>
+#include <linux/compiler.h>
+#include <linux/module.h>
+
+#include <asm/string.h>
+
+#ifdef __HAVE_ARCH_MEMSET
+void *memset(void *v_src, int c, __kernel_size_t n)
+{
+	char *src = v_src;
+	uint32_t *i_src;
+	uint32_t w32;
+
+	/* Truncate c to 8 bits */
+	w32 = c = (c & 0xFF);
+
+	/* Make a repeating word out of it */
+	w32 |= w32 << 8;
+	w32 |= w32 << 8;
+	w32 |= w32 << 8;
+
+	if (n >= 4) {
+		/* Align the destination to a word boundary */
+		/* This is done in an endian independant manner */
+		switch ((unsigned) src & 3) {
+		case 1: *src++ = c;
+			--n;
+		case 2: *src++ = c;
+			--n;
+		case 3: *src++ = c;
+			--n;
+		}
+
+		i_src  = (void *)src;
+
+		/* Do as many full-word copies as we can */
+		for (; c >= 4; c -= 4)
+			*i_src++ = w32;
+
+		src  = (void *)i_src;
+	}
+
+	/* Finish off the rest as byte sets */
+	while (n--)
+		*src++ = c;
+
+	return v_src;
+}
+EXPORT_SYMBOL(memset);
+#endif /* __HAVE_ARCH_MEMSET */
-- 
1.5.4.GIT

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Microblaze patches V2, , (Sun May 4, 7:40 am)
Re: [PATCH 01/56] microblaze_v2: Kconfig patches, Grant Likely, (Sun May 4, 5:24 pm)
Re: [PATCH 01/56] microblaze_v2: Kconfig patches, Michal Simek, (Mon May 5, 2:36 am)
RE: [microblaze-uclinux] [PATCH 04/56] microblaze_v2: Open f..., Stephen Neuendorffer, (Wed May 7, 12:04 pm)
RE: [microblaze-uclinux] [PATCH 04/56] microblaze_v2: Open f..., Stephen Neuendorffer, (Wed May 7, 4:14 pm)
RE: [PATCH 04/56] microblaze_v2: Open firmware files, Stephen Neuendorffer, (Mon May 5, 5:56 pm)
Re: [PATCH 04/56] microblaze_v2: Open firmware files, Michal Simek, (Tue May 6, 3:27 am)
Re: [PATCH 04/56] microblaze_v2: Open firmware files, Grant Likely, (Mon May 5, 10:24 am)
RE: [PATCH 07/56] microblaze_v2: Signal support, Stephen Neuendorffer, (Mon May 5, 5:32 pm)
RE: [PATCH 07/56] microblaze_v2: Signal support, John Williams, (Mon May 5, 7:33 pm)
RE: [PATCH 07/56] microblaze_v2: Signal support, Stephen Neuendorffer, (Mon May 5, 8:13 pm)
RE: [PATCH 07/56] microblaze_v2: Signal support, John Williams, (Mon May 5, 8:25 pm)
RE: [PATCH 07/56] microblaze_v2: Signal support, Stephen Neuendorffer, (Mon May 5, 8:33 pm)
Re: [PATCH 07/56] microblaze_v2: Signal support, Michal Simek, (Tue May 6, 5:41 am)
RE: [PATCH 09/56] microblaze_v2: cache support, Stephen Neuendorffer, (Mon May 5, 6:37 pm)
RE: [microblaze-uclinux] [PATCH 09/56] microblaze_v2: cache ..., Stephen Neuendorffer, (Mon May 5, 1:37 pm)
RE: [PATCH 10/56] microblaze_v2: Generic dts file for platfo..., Stephen Neuendorffer, (Mon May 5, 1:25 pm)
RE: [PATCH 10/56] microblaze_v2: Generic dts file for platfo..., Stephen Neuendorffer, (Mon May 5, 7:32 pm)
RE: [PATCH 10/56] microblaze_v2: Generic dts file for platfo..., Stephen Neuendorffer, (Mon May 5, 8:17 pm)
[PATCH 16/56] microblaze_v2: supported function for memory -..., , (Sun May 4, 7:41 am)
Re: [PATCH 18/56] microblaze_v2: early_printk support, John Williams, (Mon May 5, 7:22 pm)
Re: [PATCH 18/56] microblaze_v2: early_printk support, Michal Simek, (Tue May 6, 4:14 am)
Re: [PATCH 18/56] microblaze_v2: early_printk support, Grant Likely, (Mon May 5, 10:36 am)
Re: [PATCH 18/56] microblaze_v2: early_printk support, Michal Simek, (Mon May 5, 4:10 pm)
Re: [PATCH 24/56] microblaze_v2: time support, Thomas Gleixner, (Wed May 7, 3:22 am)
Re: [PATCH 37/56] microblaze_v2: headers for irq, Thomas Gleixner, (Wed May 7, 3:26 am)
Re: [PATCH 37/56] microblaze_v2: headers for irq, Michal Simek, (Sun May 11, 9:56 am)
Re: [PATCH 46/56] microblaze_v2: headers files entry.h curre..., Geert Uytterhoeven, (Tue May 6, 4:57 pm)
[PATCH 54/56] microblaze_v2: entry.S, , (Sun May 4, 7:41 am)
Re: [PATCH 52/56] microblaze_v2: pci headers, Arnd Bergmann, (Sun May 4, 6:45 pm)
Re: [PATCH 52/56] microblaze_v2: pci headers, Michal Simek, (Mon May 5, 10:08 am)
Re: [PATCH 48/56] microblaze_v2: pool.h socket.h, Arnd Bergmann, (Sun May 4, 6:39 pm)
Re: [PATCH 43/56] microblaze_v2: termbits.h termios.h, Arnd Bergmann, (Mon May 5, 5:50 am)
Re: [PATCH 42/56] microblaze_v2: stats headers, Arnd Bergmann, (Sun May 4, 6:31 pm)
Re: [PATCH 36/56] microblaze_v2: dma support, John Williams, (Sun May 4, 10:25 pm)
Re: [PATCH 36/56] microblaze_v2: dma support, Geert Uytterhoeven, (Mon May 5, 2:45 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Michal Simek, (Tue May 6, 5:16 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Geert Uytterhoeven, (Tue May 6, 5:48 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Michal Simek, (Tue May 6, 5:53 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Geert Uytterhoeven, (Tue May 6, 7:17 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Arnd Bergmann, (Tue May 6, 7:24 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Michal Simek, (Tue May 6, 9:20 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Arnd Bergmann, (Tue May 6, 11:36 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Michal Simek, (Wed May 7, 2:24 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Geert Uytterhoeven, (Wed May 7, 3:17 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Arnd Bergmann, (Wed May 7, 5:21 am)
Re: [PATCH 36/56] microblaze_v2: dma support, Michal Simek, (Wed May 7, 2:43 pm)
Re: [PATCH 33/56] microblaze_v2: ioctl support, Arnd Bergmann, (Sun May 4, 5:34 pm)
Re: [PATCH 33/56] microblaze_v2: ioctl support, Michal Simek, (Mon May 5, 10:06 am)
Re: [PATCH 32/56] microblaze_v2: definitions of types, Arnd Bergmann, (Sun May 4, 5:28 pm)
Re: [PATCH 30/56] microblaze_v2: includes SHM*, msgbuf, Arnd Bergmann, (Sun May 4, 5:10 pm)
Re: [PATCH 24/56] microblaze_v2: time support, John Williams, (Sun May 4, 10:19 pm)
Re: [PATCH 24/56] microblaze_v2: time support, Michal Simek, (Mon May 5, 10:22 am)
Re: [PATCH 24/56] microblaze_v2: time support, John Williams, (Mon May 5, 8:30 pm)
Re: [PATCH 24/56] microblaze_v2: time support, Michal Simek, (Tue May 6, 6:02 am)
Re: [PATCH 24/56] microblaze_v2: time support, Arnd Bergmann, (Tue May 6, 7:38 am)
RE: [PATCH 24/56] microblaze_v2: time support, Stephen Neuendorffer, (Tue May 6, 12:36 pm)
Re: [PATCH 24/56] microblaze_v2: time support, Grant Likely, (Tue May 6, 10:28 am)
Re: [PATCH 24/56] microblaze_v2: time support, Michal Simek, (Tue May 6, 9:26 am)
Re: [PATCH 24/56] microblaze_v2: time support, John Williams, (Tue May 6, 6:50 pm)
Re: [PATCH 24/56] microblaze_v2: time support, Michal Simek, (Tue May 6, 5:56 am)
Re: [PATCH 21/56] microblaze_v2: setup.c - system setting, John Williams, (Sun May 4, 10:15 pm)
Re: [PATCH 17/56] microblaze_v2: checksum support, Arnd Bergmann, (Sun May 4, 3:59 pm)
Re: [PATCH 17/56] microblaze_v2: checksum support, Michal Simek, (Mon May 5, 10:05 am)
Re: [PATCH 12/56] microblaze_v2: lmb support, John Williams, (Sun May 4, 10:11 pm)
Re: [PATCH 12/56] microblaze_v2: lmb support, Segher Boessenkool, (Mon May 5, 5:32 pm)
Re: [PATCH 09/56] microblaze_v2: cache support, John Williams, (Sun May 4, 10:09 pm)
Re: [PATCH 07/56] microblaze_v2: Signal support, Arnd Bergmann, (Sun May 4, 3:52 pm)
Re: [PATCH 03/56] microblaze_v2: Cpuinfo handling, John Williams, (Sun May 4, 9:52 pm)
Re: [PATCH 03/56] microblaze_v2: Cpuinfo handling, Michal Simek, (Mon May 5, 10:19 am)
Re: [PATCH 01/56] microblaze_v2: Kconfig patches, John Williams, (Sun May 4, 9:42 pm)
Re: [PATCH 01/56] microblaze_v2: Kconfig patches, Michal Simek, (Mon May 5, 10:16 am)
Re: [PATCH 01/56] microblaze_v2: Kconfig patches, Michal Simek, (Mon May 5, 2:46 am)
Re: Microblaze patches V2, John Williams, (Sun May 4, 10:30 pm)
Re: Microblaze patches V2, Michal Simek, (Mon May 5, 3:02 am)
speck-geostationary