* sizeof(word) MUST BE A POWER OF TWO
* SO THAT wmask BELOW IS ALL ONES
*/
-typedef int word; /* "word" used for optimal copy speed */
+typedef int word; /* "word" used for optimal copy speed */
-#define wsize sizeof(word)
-#define wmask (wsize - 1)
+#define wsize sizeof(word)
+#define wmask (wsize - 1)
/*
* Copy a block of memory, handling overlap.
*/
__attribute__((visibility("hidden")))
-void * memcpy(void *dst0, const void *src0, size_t length)
+void *
+_libkernel_memmove(void *dst0, const void *src0, size_t length)
{
char *dst = dst0;
const char *src = src0;
size_t t;
-
- if (length == 0 || dst == src) /* nothing to do */
+
+ if (length == 0 || dst == src) { /* nothing to do */
goto done;
-
+ }
+
/*
* Macros: loop-t-times; and loop-t-times, t>0
*/
-#define TLOOP(s) if (t) TLOOP1(s)
-#define TLOOP1(s) do { s; } while (--t)
-
+#define TLOOP(s) if (t) TLOOP1(s)
+#define TLOOP1(s) do { s; } while (--t)
+
if ((unsigned long)dst < (unsigned long)src) {
/*
* Copy forward.
*/
- t = (uintptr_t)src; /* only need low bits */
+ t = (uintptr_t)src; /* only need low bits */
if ((t | (uintptr_t)dst) & wmask) {
/*
* Try to align operands. This cannot be done
* unless the low bits match.
*/
- if ((t ^ (uintptr_t)dst) & wmask || length < wsize)
+ if ((t ^ (uintptr_t)dst) & wmask || length < wsize) {
t = length;
- else
+ } else {
t = wsize - (t & wmask);
+ }
length -= t;
TLOOP1(*dst++ = *src++);
}
dst += length;
t = (uintptr_t)src;
if ((t | (uintptr_t)dst) & wmask) {
- if ((t ^ (uintptr_t)dst) & wmask || length <= wsize)
+ if ((t ^ (uintptr_t)dst) & wmask || length <= wsize) {
t = length;
- else
+ } else {
t &= wmask;
+ }
length -= t;
TLOOP1(*--dst = *--src);
}
TLOOP(*--dst = *--src);
}
done:
- return (dst0);
-}
-
-__attribute__((visibility("hidden")))
-void *
-memmove(void *s1, const void *s2, size_t n)
-{
- return memcpy(s1, s2, n);
+ return dst0;
}
__attribute__((visibility("hidden")))