linux-arch.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: monstr@monstr.eu
To: linux-kernel@vger.kernel.org
Cc: monstr@seznam.cz, arnd@arndb.de, linux-arch@vger.kernel.org,
	stephen.neuendorffer@xilinx.com, John.Linn@xilinx.com,
	john.williams@petalogix.com, matthew@wil.cx,
	will.newton@gmail.com, drepper@redhat.com,
	microblaze-uclinux@itee.uq.edu.au, grant.likely@secretlab.ca,
	vapier.adi@gmail.com, alan@lxorguk.ukuu.org.uk, hpa@zytor.com,
	lethal@linux-sh.org, florian@openwrt.org,
	Michal Simek <monstr@monstr.eu>
Subject: [PATCH 17/58] microblaze_v5: supported function for memory - kernel/lib
Date: Tue,  8 Jul 2008 13:59:17 +0200	[thread overview]
Message-ID: <a967ee4e5a60b410e2810ce0475e8fd04f99e3ae.1215517976.git.monstr@monstr.eu> (raw)
In-Reply-To: <143afcf84af583ab66da7e8acfc9eb03b7f3eaa0.1215517976.git.monstr@monstr.eu>
In-Reply-To: <80a2e46f2fb93812ab12bf79c703e8e2d6b0faa0.1215517976.git.monstr@monstr.eu>

From: Michal Simek <monstr@monstr.eu>

Acked-by: Stephen Neuendorffer <stephen.neuendorffer@xilinx.com>
Signed-off-by: Michal Simek <monstr@monstr.eu>
---
 arch/microblaze/lib/memcpy.c  |  160 +++++++++++++++++++++++++++++++++++++
 arch/microblaze/lib/memmove.c |  174 +++++++++++++++++++++++++++++++++++++++++
 arch/microblaze/lib/memset.c  |   78 ++++++++++++++++++
 3 files changed, 412 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..199668d
--- /dev/null
+++ b/arch/microblaze/lib/memcpy.c
@@ -0,0 +1,160 @@
+/*
+ * 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..4db1ea6
--- /dev/null
+++ b/arch/microblaze/lib/memmove.c
@@ -0,0 +1,174 @@
+/*
+ * 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..6a2f4e5
--- /dev/null
+++ b/arch/microblaze/lib/memset.c
@@ -0,0 +1,78 @@
+/*
+ * 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;
+#ifdef CONFIG_OPT_LIB_FUNCTION
+	uint32_t *i_src;
+	uint32_t w32;
+#endif
+	/* Truncate c to 8 bits */
+	c = (c & 0xFF);
+
+#ifdef CONFIG_OPT_LIB_FUNCTION
+	/* Make a repeating word out of it */
+	w32 = c;
+	w32 |= w32 << 8;
+	w32 |= w32 << 16;
+
+	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 (; n >= 4; n -= 4)
+			*i_src++ = w32;
+
+		src  = (void *)i_src;
+	}
+#endif
+	/* Simple, byte oriented memset or the rest of count. */
+	while (n--)
+		*src++ = c;
+
+	return v_src;
+}
+EXPORT_SYMBOL(memset);
+#endif /* __HAVE_ARCH_MEMSET */
-- 
1.5.4.GIT

  reply	other threads:[~2008-07-08 13:09 UTC|newest]

Thread overview: 62+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-08 11:59 microblaze_v5: Status message monstr
2008-07-08 11:59 ` [PATCH 01/58] microblaze_v5: Kconfig patches monstr
2008-07-08 11:59   ` [PATCH 02/58] microblaze_v5: Makefiles for Microblaze cpu monstr
2008-07-08 11:59     ` [PATCH 03/58] microblaze_v5: Cpuinfo handling monstr
2008-07-08 11:59       ` [PATCH 04/58] microblaze_v5: Open firmware files1 monstr
2008-07-08 11:59         ` [PATCH 05/58] microblaze_v5: Open firmware files2 monstr
2008-07-08 11:59           ` [PATCH 06/58] microblaze_v5: Open firmware common files monstr
2008-07-08 11:59             ` [PATCH 07/58] microblaze_v5: exception handling monstr
2008-07-08 11:59               ` [PATCH 08/58] microblaze_v5: Signal support monstr
2008-07-08 11:59                 ` [PATCH 09/58] microblaze_v5: Interrupt handling, timer support, supported function monstr
2008-07-08 11:59                   ` [PATCH 10/58] microblaze_v5: cache support monstr
2008-07-08 11:59                     ` monstr
2008-07-08 11:59                     ` [PATCH 11/58] microblaze_v5: Generic dts file for platforms monstr
2008-07-08 11:59                       ` [PATCH 12/58] microblaze_v5: kernel modules support monstr
2008-07-08 11:59                         ` [PATCH 13/58] microblaze_v5: lmb support monstr
2008-07-08 11:59                           ` [PATCH 14/58] microblaze_v5: PVR support, cpuinfo support monstr
2008-07-08 11:59                             ` [PATCH 15/58] microblaze_v5: defconfig file monstr
2008-07-08 11:59                               ` [PATCH 16/58] microblaze_v5: head.S + linker script monstr
2008-07-08 11:59                                 ` monstr [this message]
2008-07-08 11:59                                   ` [PATCH 18/58] microblaze_v5: checksum support monstr
2008-07-08 11:59                                     ` [PATCH 19/58] microblaze_v5: early_printk support monstr
2008-07-08 11:59                                       ` [PATCH 20/58] microblaze_v5: uaccess files monstr
2008-07-08 11:59                                         ` [PATCH 21/58] microblaze_v5: heartbeat file monstr
2008-07-08 11:59                                           ` [PATCH 22/58] microblaze_v5: setup.c - system setting monstr
2008-07-08 11:59                                             ` [PATCH 23/58] microblaze_v5: asm-offsets monstr
2008-07-08 11:59                                               ` [PATCH 24/58] microblaze_v5: process and init task function monstr
2008-07-08 11:59                                                 ` [PATCH 25/58] microblaze_v5: time support monstr
2008-07-08 11:59                                                   ` [PATCH 26/58] microblaze_v5: virtualization monstr
2008-07-08 11:59                                                     ` [PATCH 27/58] microblaze_v5: ptrace support monstr
2008-07-08 11:59                                                       ` [PATCH 28/58] microblaze_v5: traps support monstr
2008-07-08 11:59                                                         ` [PATCH 29/58] microblaze_v5: memory inicialization, MMU, TLB monstr
2008-07-08 11:59                                                           ` [PATCH 30/58] microblaze_v5: page.h, segment.h, unaligned.h monstr
2008-07-08 11:59                                                             ` [PATCH 31/58] microblaze_v5: includes SHM*, msgbuf monstr
2008-07-08 11:59                                                               ` [PATCH 32/58] microblaze_v5: bug headers files monstr
2008-07-08 11:59                                                                 ` [PATCH 33/58] microblaze_v5: definitions of types monstr
2008-07-08 11:59                                                                   ` [PATCH 34/58] microblaze_v5: ioctl support monstr
2008-07-08 11:59                                                                     ` [PATCH 35/58] microblaze_v5: io.h IO operations monstr
2008-07-08 11:59                                                                       ` [PATCH 36/58] microblaze_v5: headers for executables format FLAT, ELF monstr
2008-07-08 11:59                                                                         ` [PATCH 37/58] microblaze_v5: dma support monstr
2008-07-08 11:59                                                                           ` [PATCH 38/58] microblaze_v5: headers for irq monstr
2008-07-08 11:59                                                                             ` [PATCH 39/58] microblaze_v5: atomic.h bitops.h byteorder.h monstr
2008-07-08 11:59                                                                               ` [PATCH 40/58] microblaze_v5: headers pgalloc.h pgtable.h monstr
2008-07-08 11:59                                                                                 ` [PATCH 41/58] microblaze_v5: system.h pvr.h processor.h monstr
2008-07-08 11:59                                                                                   ` [PATCH 42/58] microblaze_v5: clinkage.h linkage.h sections.h kmap_types.h monstr
2008-07-08 11:59                                                                                     ` [PATCH 43/58] microblaze_v5: stats headers monstr
2008-07-08 11:59                                                                                       ` [PATCH 44/58] microblaze_v5: termbits.h termios.h monstr
2008-07-08 11:59                                                                                         ` [PATCH 45/58] microblaze_v5: sigcontext.h siginfo.h monstr
2008-07-08 11:59                                                                                           ` [PATCH 46/58] microblaze_v5: headers simple files - empty or redirect to asm-generic monstr
2008-07-08 11:59                                                                                             ` [PATCH 47/58] microblaze_v5: headers files entry.h current.h mman.h registers.h sembuf.h monstr
2008-07-08 11:59                                                                                               ` [PATCH 48/58] microblaze_v5: device.h param.h topology.h monstr
2008-07-08 11:59                                                                                                 ` [PATCH 49/58] microblaze_v5: pool.h socket.h monstr
2008-07-08 11:59                                                                                                   ` [PATCH 50/58] microblaze_v5: generic files sockios.h ucontext.h monstr
2008-07-08 11:59                                                                                                     ` [PATCH 51/58] microblaze_v5: setup.h string.h thread_info.h monstr
2008-07-08 11:59                                                                                                       ` [PATCH 52/58] microblaze_v5: Kbuild file monstr
2008-07-08 11:59                                                                                                         ` [PATCH 53/58] microblaze_v5: pci headers monstr
2008-07-08 11:59                                                                                                           ` [PATCH 54/58] microblaze_v5: IPC headers monstr
2008-07-08 11:59                                                                                                             ` [PATCH 55/58] microblaze_v5: entry.S monstr
2008-07-08 11:59                                                                                                               ` [PATCH 56/58] microblaze_v5: sys_microblaze.c monstr
2008-07-08 11:59                                                                                                                 ` [PATCH 57/58] microblaze_v5: syscall_table.S and unistd.h monstr
2008-07-08 11:59                                                                                                                   ` [PATCH 58/58] microblaze_v5: Enable drivers for Microblaze monstr
2008-07-08 23:47                                       ` [PATCH 19/58] microblaze_v5: early_printk support John Williams
2008-07-08 19:43 ` microblaze_v5: Status message Michal Simek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a967ee4e5a60b410e2810ce0475e8fd04f99e3ae.1215517976.git.monstr@monstr.eu \
    --to=monstr@monstr.eu \
    --cc=John.Linn@xilinx.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arnd@arndb.de \
    --cc=drepper@redhat.com \
    --cc=florian@openwrt.org \
    --cc=grant.likely@secretlab.ca \
    --cc=hpa@zytor.com \
    --cc=john.williams@petalogix.com \
    --cc=lethal@linux-sh.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthew@wil.cx \
    --cc=microblaze-uclinux@itee.uq.edu.au \
    --cc=monstr@seznam.cz \
    --cc=stephen.neuendorffer@xilinx.com \
    --cc=vapier.adi@gmail.com \
    --cc=will.newton@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).