aarch64: Fuse CMP+CSEL and CMP+CSET for -mcpu=neoverse-v2
[official-gcc.git] / libgo / runtime / go-memmove.c
blob1ca3f4822b736fadbe0db35a5784f730b0f5f5b2
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. */
7 #include "runtime.h"
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
16 // moves.
18 void
19 gomemmove (void *dst, void *src, uintptr len)
21 #if !defined(__PPC64__)
22 __builtin_memmove(dst, src, len);
23 #else
24 uint64 offset, tail;
25 int64 rem;
26 uint64 dwords;
27 uint64 i;
28 char *bdst,*bsrc;
30 rem = len;
32 if (len == 0) {
33 return;
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
38 // builtin.
39 if (((uint64)dst % 8) != ((uint64)src % 8) || len < 8) {
40 __builtin_memmove(dst, src, len);
41 return;
44 // Length >= 8 && same ptr alignment
45 offset = (uint64)dst % 8;
47 // If not 8 byte alignment, move the intial bytes.
48 if (offset > 0) {
49 __builtin_memmove(dst, src, 8-offset);
50 dst += (8-offset);
51 src += (8-offset);
52 rem -= (8-offset);
55 // Move the tail bytes to make the backward move
56 // easier.
57 tail = rem % 8;
58 if (tail > 0) {
59 __builtin_memmove(dst+rem-tail, src+rem-tail, tail);
60 rem -= tail;
63 if (rem == 0) {
64 return;
67 // Must now be 8 byte alignment and rem is multiple of 8.
68 dwords = len>>3;
70 // Determine if a backwards move is needed
71 // Forward or backward, move all doublewords
73 if ((uint64)(dst - src) < (uint64)rem) {
74 bdst = dst+rem-8;
75 bsrc = src+rem-8;
76 for (i = 0; i<dwords; i++) {
77 *(uint64*)bdst = *(uint64*)bsrc;
78 bdst -= 8;
79 bsrc -= 8;
81 } else {
82 for (i = 0; i<dwords; i++) {
83 *(uint64*)dst = *(uint64*)src;
84 dst += 8;
85 src += 8;
88 #endif