mirror of
https://github.com/apache/nuttx.git
synced 2026-05-26 02:36:11 +08:00
libc string:Separate code.
Separate the code that follows the BSD license into independent files. Signed-off-by: yangguangcai <yangguangcai@xiaomi.com>
This commit is contained in:
@@ -30,30 +30,6 @@
|
||||
|
||||
#include "libc.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_LIBC_STRING_OPTIMIZE
|
||||
/* Nonzero if either x or y is not aligned on a "long" boundary. */
|
||||
|
||||
#define UNALIGNED(x, y) \
|
||||
(((long)(uintptr_t)(x) & (sizeof(long) - 1)) | ((long)(uintptr_t)(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)
|
||||
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
@@ -67,58 +43,12 @@
|
||||
no_builtin("memcpy")
|
||||
FAR void *memcpy(FAR void *dest, FAR const void *src, size_t n)
|
||||
{
|
||||
#ifdef CONFIG_LIBC_STRING_OPTIMIZE
|
||||
FAR char *pout = dest;
|
||||
FAR const char *pin = src;
|
||||
FAR long *paligned_out;
|
||||
FAR const long *paligned_in;
|
||||
|
||||
/* If the size is small, or either pin or pout is unaligned,
|
||||
* then punt into the byte copy loop. This should be rare.
|
||||
*/
|
||||
|
||||
if (!TOO_SMALL(n) && !UNALIGNED(pin, pout))
|
||||
{
|
||||
paligned_out = (FAR long *)pout;
|
||||
paligned_in = (FAR long *)pin;
|
||||
|
||||
/* Copy 4X long words at a time if possible. */
|
||||
|
||||
while (n >= BIGBLOCKSIZE)
|
||||
{
|
||||
*paligned_out++ = *paligned_in++;
|
||||
*paligned_out++ = *paligned_in++;
|
||||
*paligned_out++ = *paligned_in++;
|
||||
*paligned_out++ = *paligned_in++;
|
||||
n -= BIGBLOCKSIZE;
|
||||
}
|
||||
|
||||
/* Copy one long word at a time if possible. */
|
||||
|
||||
while (n >= LITTLEBLOCKSIZE)
|
||||
{
|
||||
*paligned_out++ = *paligned_in++;
|
||||
n -= LITTLEBLOCKSIZE;
|
||||
}
|
||||
|
||||
/* Pick up any residual with a byte copier. */
|
||||
|
||||
pout = (FAR char *)paligned_out;
|
||||
pin = (FAR char *)paligned_in;
|
||||
}
|
||||
|
||||
while (n--)
|
||||
{
|
||||
*pout++ = *pin++;
|
||||
}
|
||||
#else
|
||||
FAR unsigned char *pout = (FAR unsigned char *)dest;
|
||||
FAR unsigned char *pin = (FAR unsigned char *)src;
|
||||
while (n-- > 0)
|
||||
{
|
||||
*pout++ = *pin++;
|
||||
}
|
||||
#endif
|
||||
|
||||
return dest;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user