1 /* go-memmove.c -- memmove
3 Copyright 2021 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
9 void gomemmove(void *, void *, uintptr
)
10 __asm__ (GOSYM_PREFIX
"runtime.memmove")
11 __attribute__ ((no_split_stack
));
13 // This implementation is necessary since
14 // the __builtin_memmove might use __libc_memmove
15 // which doesn't require atomicity of 8 byte
19 gomemmove (void *dst
, void *src
, uintptr len
)
21 #if !defined(__PPC64__)
22 __builtin_memmove(dst
, src
, len
);
36 // If src and dst don't have the same 8 byte alignment then
37 // there is no issue with copying pointer atomicity. Use the
39 if (((uint64
)dst
% 8) != ((uint64
)src
% 8) || len
< 8) {
40 __builtin_memmove(dst
, src
, len
);
44 // Length >= 8 && same ptr alignment
45 offset
= (uint64
)dst
% 8;
47 // If not 8 byte alignment, move the intial bytes.
49 __builtin_memmove(dst
, src
, 8-offset
);
55 // Move the tail bytes to make the backward move
59 __builtin_memmove(dst
+rem
-tail
, src
+rem
-tail
, tail
);
67 // Must now be 8 byte alignment and rem is multiple of 8.
70 // Determine if a backwards move is needed
71 // Forward or backward, move all doublewords
73 if ((uint64
)(dst
- src
) < (uint64
)rem
) {
76 for (i
= 0; i
<dwords
; i
++) {
77 *(uint64
*)bdst
= *(uint64
*)bsrc
;
82 for (i
= 0; i
<dwords
; i
++) {
83 *(uint64
*)dst
= *(uint64
*)src
;