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:
yangguangcai
2024-10-22 14:03:24 +08:00
committed by Xiang Xiao
parent cdccce48ac
commit f07aba5c1e
35 changed files with 1841 additions and 1134 deletions
-70
View File
@@ -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;
}