PS2SDK
PS2 Homebrew Libraries
memmove.c
1 #define SYSCLIB_DISABLE_BUILTINS
2 #include <sysclib.h>
3 #include <stdint.h>
4 
5 #ifdef __GNUC__
6 typedef __attribute__((__may_alias__)) size_t WT;
7 #define WS (sizeof(WT))
8 #endif
9 
10 void *memmove(void *dest, const void *src, size_t n)
11 {
12  char *d = dest;
13  const char *s = src;
14 
15  if (d==s) return d;
16  // cppcheck-suppress signConversion
17  if ((uintptr_t)s-(uintptr_t)d-n <= -2*n) return memcpy(d, s, n);
18 
19  if (d<s) {
20 #ifdef __GNUC__
21  if ((uintptr_t)s % WS == (uintptr_t)d % WS) {
22  while ((uintptr_t)d % WS) {
23  if (!n--) return dest;
24  *d++ = *s++;
25  }
26  for (; n>=WS; n-=WS, d+=WS, s+=WS) *(WT *)d = *(WT *)s;
27  }
28 #endif
29  for (; n; n--) *d++ = *s++;
30  } else {
31 #ifdef __GNUC__
32  if ((uintptr_t)s % WS == (uintptr_t)d % WS) {
33  while ((uintptr_t)(d+n) % WS) {
34  if (!n--) return dest;
35  d[n] = s[n];
36  }
37  while (n>=WS) n-=WS, *(WT *)(d+n) = *(WT *)(s+n);
38  }
39 #endif
40  while (n) n--, d[n] = s[n];
41  }
42 
43  return dest;
44 }
sysclib.h
__attribute__
typedef __attribute__
Definition: tlbfunc.c:60