forked from len0rd/rockbox
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
This commit is contained in:
parent
948f0b8497
commit
0310f16005
5 changed files with 233 additions and 5 deletions
|
|
@ -1,6 +1,3 @@
|
||||||
#ifdef ARCHOS_GMINI120
|
|
||||||
common/string.c
|
|
||||||
#endif
|
|
||||||
#ifdef IRIVER_H100
|
#ifdef IRIVER_H100
|
||||||
crt0.S
|
crt0.S
|
||||||
backlight.c
|
backlight.c
|
||||||
|
|
@ -30,6 +27,13 @@ common/strncpy.c
|
||||||
common/strrchr.c
|
common/strrchr.c
|
||||||
common/strtok.c
|
common/strtok.c
|
||||||
common/timefuncs.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
|
debug.c
|
||||||
drivers/adc.c
|
drivers/adc.c
|
||||||
#ifdef HAVE_MMC
|
#ifdef HAVE_MMC
|
||||||
|
|
@ -81,8 +85,6 @@ system.c
|
||||||
thread.c
|
thread.c
|
||||||
usb.c
|
usb.c
|
||||||
bitswap.S
|
bitswap.S
|
||||||
common/memcpy.S
|
|
||||||
common/memset.S
|
|
||||||
crt0.S
|
crt0.S
|
||||||
descramble.S
|
descramble.S
|
||||||
drivers/lcd.S
|
drivers/lcd.S
|
||||||
|
|
|
||||||
117
firmware/common/memcpy.c
Normal file
117
firmware/common/memcpy.c
Normal file
|
|
@ -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 */
|
||||||
|
}
|
||||||
109
firmware/common/memset.c
Normal file
109
firmware/common/memset.c
Normal file
|
|
@ -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 */
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue