github.com/kidsbmilk/gofronted_all@v0.0.0-20220701224323-6479d5976c5d/libgo/runtime/go-memclr.c (about) 1 /* go-memclr.c -- clear a memory buffer 2 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. */ 6 7 #include "runtime.h" 8 9 void memclrNoHeapPointers(void *, uintptr) 10 __asm__ (GOSYM_PREFIX "runtime.memclrNoHeapPointers") 11 __attribute__ ((no_split_stack)); 12 13 void 14 memclrNoHeapPointers (void *p1, uintptr len) 15 { 16 17 #if !defined(__PPC64__) 18 __builtin_memset(p1, 0, len); 19 #else 20 int64 rem,drem,i; 21 uint64 offset; 22 volatile uint64 *vp; 23 24 if (len == 0) { 25 return; 26 } 27 rem = len; 28 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; 35 } 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; 41 } 42 43 // If at least 8 bytes left, clear 44 drem = rem>>3; 45 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; 53 } 54 p1 = (void*)((char*)p1 + 8*drem); 55 // Clear any remaining 56 if (rem > 0) { 57 __builtin_memset (p1, 0, rem); 58 } 59 #endif 60 }