diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-10-28 22:34:47 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2016-10-28 22:34:47 +0000 |
commit | 94f56408db96e2e12f6e1322ed2c1c465df934f6 (patch) | |
tree | f5eaac76bc47cc2637e5e30b9ff6c27499fac2d9 /libgo/runtime/go-append.c | |
parent | 21f1031d6cc228e2b468338b3dfa4303d54ac207 (diff) | |
download | gcc-94f56408db96e2e12f6e1322ed2c1c465df934f6.zip gcc-94f56408db96e2e12f6e1322ed2c1c465df934f6.tar.gz gcc-94f56408db96e2e12f6e1322ed2c1c465df934f6.tar.bz2 |
compiler, runtime: copy slice code from Go 1.7 runtime
Change the compiler handle append as the gc compiler does: call a
function to grow the slice, but otherwise assign the new elements
directly to the final slice.
For the current gccgo memory allocator the slice code has to call
runtime_newarray, not mallocgc directly, so that the allocator sets the
TypeInfo_Array bit in the type pointer.
Rename the static function cnew to runtime_docnew, so that the stack
trace ignores it when ignoring runtime functions. This was needed to
fix the runtime/pprof tests on 386.
Reviewed-on: https://go-review.googlesource.com/32218
From-SVN: r241667
Diffstat (limited to 'libgo/runtime/go-append.c')
-rw-r--r-- | libgo/runtime/go-append.c | 74 |
1 files changed, 0 insertions, 74 deletions
diff --git a/libgo/runtime/go-append.c b/libgo/runtime/go-append.c deleted file mode 100644 index 1b2d49e..0000000 --- a/libgo/runtime/go-append.c +++ /dev/null @@ -1,74 +0,0 @@ -/* go-append.c -- the go builtin append function. - - Copyright 2010 The Go Authors. All rights reserved. - Use of this source code is governed by a BSD-style - license that can be found in the LICENSE file. */ - -#include "runtime.h" -#include "go-panic.h" -#include "go-type.h" -#include "array.h" -#include "arch.h" -#include "malloc.h" - -/* We should be OK if we don't split the stack here, since the only - libc functions we call are memcpy and memmove. If we don't do - this, we will always split the stack, because of memcpy and - memmove. */ -extern struct __go_open_array -__go_append (struct __go_open_array, void *, uintptr_t, uintptr_t) - __attribute__ ((no_split_stack)); - -struct __go_open_array -__go_append (struct __go_open_array a, void *bvalues, uintptr_t bcount, - uintptr_t element_size) -{ - uintptr_t ucount; - intgo count; - - if (bvalues == NULL || bcount == 0) - return a; - - ucount = (uintptr_t) a.__count + bcount; - count = (intgo) ucount; - if ((uintptr_t) count != ucount || count <= a.__count) - runtime_panicstring ("append: slice overflow"); - - if (count > a.__capacity) - { - intgo m; - uintptr capmem; - void *n; - - m = a.__capacity; - if (m + m < count) - m = count; - else - { - do - { - if (a.__count < 1024) - m += m; - else - m += m / 4; - } - while (m < count); - } - - if (element_size > 0 && (uintptr) m > MaxMem / element_size) - runtime_panicstring ("growslice: cap out of range"); - - capmem = runtime_roundupsize (m * element_size); - - n = __go_alloc (capmem); - __builtin_memcpy (n, a.__values, a.__count * element_size); - - a.__values = n; - a.__capacity = m; - } - - __builtin_memmove ((char *) a.__values + a.__count * element_size, - bvalues, bcount * element_size); - a.__count = count; - return a; -} |