MCPcopy Index your code
hub / github.com/dcodeIO/webassembly / memcpy

Function memcpy

lib/memcpy.c:29–134  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27#define RS <<
28
29void *memcpy(void *restrict dest, const void *restrict src, size_t n)
30{
31 unsigned char *d = dest;
32 const unsigned char *s = src;
33
34 typedef uint32_t __attribute__((__may_alias__)) u32;
35 uint32_t w, x;
36
37 for (; (uintptr_t)s % 4 && n; n--) *d++ = *s++;
38
39 if ((uintptr_t)d % 4 == 0) {
40 for (; n>=16; s+=16, d+=16, n-=16) {
41 *(u32 *)(d+0) = *(u32 *)(s+0);
42 *(u32 *)(d+4) = *(u32 *)(s+4);
43 *(u32 *)(d+8) = *(u32 *)(s+8);
44 *(u32 *)(d+12) = *(u32 *)(s+12);
45 }
46 if (n&8) {
47 *(u32 *)(d+0) = *(u32 *)(s+0);
48 *(u32 *)(d+4) = *(u32 *)(s+4);
49 d += 8; s += 8;
50 }
51 if (n&4) {
52 *(u32 *)(d+0) = *(u32 *)(s+0);
53 d += 4; s += 4;
54 }
55 if (n&2) {
56 *d++ = *s++; *d++ = *s++;
57 }
58 if (n&1) {
59 *d = *s;
60 }
61 return dest;
62 }
63
64 if (n >= 32) switch ((uintptr_t)d % 4) {
65 case 1:
66 w = *(u32 *)s;
67 *d++ = *s++;
68 *d++ = *s++;
69 *d++ = *s++;
70 n -= 3;
71 for (; n>=17; s+=16, d+=16, n-=16) {
72 x = *(u32 *)(s+1);
73 *(u32 *)(d+0) = (w LS 24) | (x RS 8);
74 w = *(u32 *)(s+5);
75 *(u32 *)(d+4) = (x LS 24) | (w RS 8);
76 x = *(u32 *)(s+9);
77 *(u32 *)(d+8) = (w LS 24) | (x RS 8);
78 w = *(u32 *)(s+13);
79 *(u32 *)(d+12) = (x LS 24) | (w RS 8);
80 }
81 break;
82 case 2:
83 w = *(u32 *)s;
84 *d++ = *s++;
85 *d++ = *s++;
86 n -= 2;

Callers 3

memmoveFunction · 0.85
dlreallocFunction · 0.85
mspace_reallocFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected