tree-optimization/112856 - fix LC SSA after loop header copying
[official-gcc.git] / libgo / runtime / go-memclr.c
blob53b8117853923a32fc364b68d59cd911ef2ada18
1 /* go-memclr.c -- clear a memory buffer
3 Copyright 2016 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 memclrNoHeapPointers(void *, uintptr)
10 __asm__ (GOSYM_PREFIX "runtime.memclrNoHeapPointers")
11 __attribute__ ((no_split_stack));
13 void
14 memclrNoHeapPointers (void *p1, uintptr len)
17 #if !defined(__PPC64__)
18 __builtin_memset(p1, 0, len);
19 #else
20 int64 rem,drem,i;
21 uint64 offset;
22 volatile uint64 *vp;
24 if (len == 0) {
25 return;
27 rem = len;
29 offset = (uint64)p1 % 8;
30 // This memset is OK since it can't contain
31 // an 8 byte aligned pointer.
32 if ((rem < 8) || (offset > 0 && offset+rem <= 16)) {
33 __builtin_memset(p1, 0, rem);
34 return;
36 // Move initial bytes to get to 8 byte boundary
37 if (offset > 0) {
38 __builtin_memset(p1, 0, 8-offset);
39 p1 = (void*)((char*)p1+8-offset);
40 rem -= 8-offset;
43 // If at least 8 bytes left, clear
44 drem = rem>>3;
46 vp = (volatile uint64*)(p1);
47 // Without the use of volatile here, the compiler
48 // might convert the loop into a memset.
49 for (i=0; i<drem; i++) {
50 *vp = 0;
51 vp++;
52 rem -= 8;
54 p1 = (void*)((char*)p1 + 8*drem);
55 // Clear any remaining
56 if (rem > 0) {
57 __builtin_memset (p1, 0, rem);
59 #endif