summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-01-21 22:43:02 +0000
committerJens Arnold <amiconn@rockbox.org>2005-01-21 22:43:02 +0000
commit0310f16005a1e98c441221bc0f0f7586d0b19763 (patch)
treec695e2baa4da1bc7fb9381568863e903020335e3
parent948f0b849785b3e727be6584470d1bb32238ec6a (diff)
downloadrockbox-0310f16005a1e98c441221bc0f0f7586d0b19763.tar.gz
rockbox-0310f16005a1e98c441221bc0f0f7586d0b19763.zip
Revived C implementations of memcpy() and memset() for platforms without asm optimized versions (gmini), replacing the intermediate strings.c. Moved the asm optimized versions 'out of the way' for the implicit 'make' rules by renaming them to *_a.S (for assembler/alternative).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5628 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/SOURCES12
-rw-r--r--firmware/common/memcpy.c117
-rw-r--r--firmware/common/memcpy_a.S (renamed from firmware/common/memcpy.S)0
-rw-r--r--firmware/common/memset.c109
-rw-r--r--firmware/common/memset_a.S (renamed from firmware/common/memset.S)0
5 files changed, 233 insertions, 5 deletions
diff --git a/firmware/SOURCES b/firmware/SOURCES
index e6c007c1d0..e08d986ec1 100644
--- a/firmware/SOURCES
+++ b/firmware/SOURCES
@@ -1,6 +1,3 @@
-#ifdef ARCHOS_GMINI120
-common/string.c
-#endif
#ifdef IRIVER_H100
crt0.S
backlight.c
@@ -30,6 +27,13 @@ common/strncpy.c
common/strrchr.c
common/strtok.c
common/timefuncs.c
+#if (CONFIG_CPU == SH7034) || (CONFIG_CPU == MCF5249)
+common/memcpy_a.S
+common/memset_a.S
+#else
+common/memcpy.c
+common/memset.c
+#endif
debug.c
drivers/adc.c
#ifdef HAVE_MMC
@@ -81,8 +85,6 @@ system.c
thread.c
usb.c
bitswap.S
-common/memcpy.S
-common/memset.S
crt0.S
descramble.S
drivers/lcd.S
diff --git a/firmware/common/memcpy.c b/firmware/common/memcpy.c
new file mode 100644
index 0000000000..49678920fa
--- /dev/null
+++ b/firmware/common/memcpy.c
@@ -0,0 +1,117 @@
+/*
+FUNCTION
+ <<memcpy>>---copy memory regions
+
+ANSI_SYNOPSIS
+ #include <string.h>
+ void* memcpy(void *<[out]>, const void *<[in]>, size_t <[n]>);
+
+TRAD_SYNOPSIS
+ void *memcpy(<[out]>, <[in]>, <[n]>
+ void *<[out]>;
+ void *<[in]>;
+ size_t <[n]>;
+
+DESCRIPTION
+ This function copies <[n]> bytes from the memory region
+ pointed to by <[in]> to the memory region pointed to by
+ <[out]>.
+
+ If the regions overlap, the behavior is undefined.
+
+RETURNS
+ <<memcpy>> returns a pointer to the first byte of the <[out]>
+ region.
+
+PORTABILITY
+<<memcpy>> is ANSI C.
+
+<<memcpy>> requires no supporting OS subroutines.
+
+QUICKREF
+ memcpy ansi pure
+ */
+
+#include <_ansi.h>
+#include <stddef.h>
+#include <limits.h>
+
+/* Nonzero if either X or Y is not aligned on a "long" boundary. */
+#define UNALIGNED(X, Y) \
+ (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
+
+/* How many bytes are copied each iteration of the 4X unrolled loop. */
+#define BIGBLOCKSIZE (sizeof (long) << 2)
+
+/* How many bytes are copied each iteration of the word copy loop. */
+#define LITTLEBLOCKSIZE (sizeof (long))
+
+/* Threshhold for punting to the byte copier. */
+#define TOO_SMALL(LEN) ((LEN) < BIGBLOCKSIZE)
+
+_PTR
+_DEFUN (memcpy, (dst0, src0, len0),
+ _PTR dst0 _AND
+ _CONST _PTR src0 _AND
+ size_t len0) __attribute__ ((section (".icode")));
+
+_PTR
+_DEFUN (memcpy, (dst0, src0, len0),
+ _PTR dst0 _AND
+ _CONST _PTR src0 _AND
+ size_t len0)
+{
+#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
+ char *dst = (char *) dst0;
+ char *src = (char *) src0;
+
+ _PTR save = dst0;
+
+ while (len0--)
+ {
+ *dst++ = *src++;
+ }
+
+ return save;
+#else
+ char *dst = dst0;
+ _CONST char *src = src0;
+ long *aligned_dst;
+ _CONST long *aligned_src;
+ unsigned int len = len0;
+
+ /* If the size is small, or either SRC or DST is unaligned,
+ then punt into the byte copy loop. This should be rare. */
+ if (!TOO_SMALL(len) && !UNALIGNED (src, dst))
+ {
+ aligned_dst = (long*)dst;
+ aligned_src = (long*)src;
+
+ /* Copy 4X long words at a time if possible. */
+ while (len >= BIGBLOCKSIZE)
+ {
+ *aligned_dst++ = *aligned_src++;
+ *aligned_dst++ = *aligned_src++;
+ *aligned_dst++ = *aligned_src++;
+ *aligned_dst++ = *aligned_src++;
+ len -= BIGBLOCKSIZE;
+ }
+
+ /* Copy one long word at a time if possible. */
+ while (len >= LITTLEBLOCKSIZE)
+ {
+ *aligned_dst++ = *aligned_src++;
+ len -= LITTLEBLOCKSIZE;
+ }
+
+ /* Pick up any residual with a byte copier. */
+ dst = (char*)aligned_dst;
+ src = (char*)aligned_src;
+ }
+
+ while (len--)
+ *dst++ = *src++;
+
+ return dst0;
+#endif /* not PREFER_SIZE_OVER_SPEED */
+}
diff --git a/firmware/common/memcpy.S b/firmware/common/memcpy_a.S
index e129b99442..e129b99442 100644
--- a/firmware/common/memcpy.S
+++ b/firmware/common/memcpy_a.S
diff --git a/firmware/common/memset.c b/firmware/common/memset.c
new file mode 100644
index 0000000000..c370191cda
--- /dev/null
+++ b/firmware/common/memset.c
@@ -0,0 +1,109 @@
+/*
+FUNCTION
+ <<memset>>---set an area of memory
+
+INDEX
+ memset
+
+ANSI_SYNOPSIS
+ #include <string.h>
+ void *memset(const void *<[dst]>, int <[c]>, size_t <[length]>);
+
+TRAD_SYNOPSIS
+ #include <string.h>
+ void *memset(<[dst]>, <[c]>, <[length]>)
+ void *<[dst]>;
+ int <[c]>;
+ size_t <[length]>;
+
+DESCRIPTION
+ This function converts the argument <[c]> into an unsigned
+ char and fills the first <[length]> characters of the array
+ pointed to by <[dst]> to the value.
+
+RETURNS
+ <<memset>> returns the value of <[m]>.
+
+PORTABILITY
+<<memset>> is ANSI C.
+
+ <<memset>> requires no supporting OS subroutines.
+
+QUICKREF
+ memset ansi pure
+*/
+
+#include <string.h>
+
+#define LBLOCKSIZE (sizeof(long))
+#define UNALIGNED(X) ((long)X & (LBLOCKSIZE - 1))
+#define TOO_SMALL(LEN) ((LEN) < LBLOCKSIZE)
+
+_PTR
+_DEFUN (memset, (m, c, n),
+ _PTR m _AND
+ int c _AND
+ size_t n)
+{
+#if defined(PREFER_SIZE_OVER_SPEED) || defined(__OPTIMIZE_SIZE__)
+ char *s = (char *) m;
+
+ while (n-- != 0)
+ {
+ *s++ = (char) c;
+ }
+
+ return m;
+#else
+ char *s = (char *) m;
+ unsigned int i;
+ unsigned long buffer;
+ unsigned long *aligned_addr;
+
+ if (!TOO_SMALL (n) && !UNALIGNED (m))
+ {
+ /* If we get this far, we know that n is large and m is word-aligned. */
+
+ aligned_addr = (unsigned long*)m;
+
+ /* Store C into each char sized location in BUFFER so that
+ we can set large blocks quickly. */
+ c &= 0xff;
+ if (LBLOCKSIZE == 4)
+ {
+ buffer = (c << 8) | c;
+ buffer |= (buffer << 16);
+ }
+ else
+ {
+ buffer = 0;
+ for (i = 0; i < LBLOCKSIZE; i++)
+ buffer = (buffer << 8) | c;
+ }
+
+ while (n >= LBLOCKSIZE*4)
+ {
+ *aligned_addr++ = buffer;
+ *aligned_addr++ = buffer;
+ *aligned_addr++ = buffer;
+ *aligned_addr++ = buffer;
+ n -= 4*LBLOCKSIZE;
+ }
+
+ while (n >= LBLOCKSIZE)
+ {
+ *aligned_addr++ = buffer;
+ n -= LBLOCKSIZE;
+ }
+ /* Pick up the remainder with a bytewise loop. */
+ s = (char*)aligned_addr;
+ }
+
+ while (n--)
+ {
+ *s++ = (char)c;
+ }
+
+ return m;
+#endif /* not PREFER_SIZE_OVER_SPEED */
+}
diff --git a/firmware/common/memset.S b/firmware/common/memset_a.S
index bce8936089..bce8936089 100644
--- a/firmware/common/memset.S
+++ b/firmware/common/memset_a.S