]>
git.proxmox.com Git - wasi-libc.git/blob - libc-top-half/musl/src/string/memmove.c
5 typedef __attribute__((__may_alias__
)) size_t WT
;
6 #define WS (sizeof(WT))
9 void *memmove(void *dest
, const void *src
, size_t n
)
11 #if defined(__wasm_bulk_memory__)
12 return __builtin_memmove(dest
, src
, n
);
18 if ((uintptr_t)s
-(uintptr_t)d
-n
<= -2*n
) return memcpy(d
, s
, n
);
22 if ((uintptr_t)s
% WS
== (uintptr_t)d
% WS
) {
23 while ((uintptr_t)d
% WS
) {
24 if (!n
--) return dest
;
27 for (; n
>=WS
; n
-=WS
, d
+=WS
, s
+=WS
) *(WT
*)d
= *(WT
*)s
;
30 for (; n
; n
--) *d
++ = *s
++;
33 if ((uintptr_t)s
% WS
== (uintptr_t)d
% WS
) {
34 while ((uintptr_t)(d
+n
) % WS
) {
35 if (!n
--) return dest
;
38 while (n
>=WS
) n
-=WS
, *(WT
*)(d
+n
) = *(WT
*)(s
+n
);
41 while (n
) n
--, d
[n
] = s
[n
];
45 #endif // __wasm_bulk_memory__