aboutsummaryrefslogtreecommitdiff
path: root/libgo/runtime/go-memclr.c
diff options
context:
space:
mode:
Diffstat (limited to 'libgo/runtime/go-memclr.c')
-rw-r--r--libgo/runtime/go-memclr.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/libgo/runtime/go-memclr.c b/libgo/runtime/go-memclr.c
index 53b8117..84df98d 100644
--- a/libgo/runtime/go-memclr.c
+++ b/libgo/runtime/go-memclr.c
@@ -11,50 +11,39 @@ void memclrNoHeapPointers(void *, uintptr)
__attribute__ ((no_split_stack));
void
-memclrNoHeapPointers (void *p1, uintptr len)
+memclrNoHeapPointers(void *p1, uintptr len)
{
-
-#if !defined(__PPC64__)
- __builtin_memset(p1, 0, len);
-#else
- int64 rem,drem,i;
- uint64 offset;
- volatile uint64 *vp;
+ const uintptr ptr_size = sizeof(p1);
+ uintptr rem,drem,i;
+ uintptr offset;
+ volatile uintptr *vp;
if (len == 0) {
return;
}
rem = len;
- offset = (uint64)p1 % 8;
- // This memset is OK since it can't contain
- // an 8 byte aligned pointer.
- if ((rem < 8) || (offset > 0 && offset+rem <= 16)) {
+ offset = (uintptr)p1 % ptr_size;
+ if (rem < ptr_size || offset > 0) {
+ // This memset is OK since it can't contain
+ // an pointer aligned pointer.
__builtin_memset(p1, 0, rem);
return;
}
- // Move initial bytes to get to 8 byte boundary
- if (offset > 0) {
- __builtin_memset(p1, 0, 8-offset);
- p1 = (void*)((char*)p1+8-offset);
- rem -= 8-offset;
- }
- // If at least 8 bytes left, clear
- drem = rem>>3;
+ drem = rem / ptr_size;
- vp = (volatile uint64*)(p1);
+ vp = (volatile uintptr*)(p1);
// Without the use of volatile here, the compiler
// might convert the loop into a memset.
for (i=0; i<drem; i++) {
*vp = 0;
vp++;
- rem -= 8;
+ rem -= ptr_size;
}
- p1 = (void*)((char*)p1 + 8*drem);
- // Clear any remaining
+ // Clear any remaining bytes.
if (rem > 0) {
- __builtin_memset (p1, 0, rem);
+ p1 = (void*)((char*)p1 + ptr_size*drem);
+ __builtin_memset(p1, 0, rem);
}
-#endif
}