From: Matthew Dempsky Date: Fri, 27 Feb 2015 06:13:05 +0000 (+0900) Subject: cmd/internal/gc, runtime: change growslice to use int instead of int64 X-Git-Tag: go1.5beta1~1724 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=81d4072eb062a6af09e9a36314887a88acd50ebf;p=gostls13.git cmd/internal/gc, runtime: change growslice to use int instead of int64 Gc already calculates n as an int, so converting to int64 to call growslice doesn't serve any purpose except to emit slightly larger code on 32-bit platforms. Passing n as an int shrinks godoc's text segment by 8kB (9472633 => 9464133) when building for ARM. Change-Id: Ief9492c21d01afcb624d3f2a484df741450b788d Reviewed-on: https://go-review.googlesource.com/6231 Reviewed-by: Dmitry Vyukov Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/internal/gc/builtin.go b/src/cmd/internal/gc/builtin.go index a5d27bd762..f1a8ed8a31 100644 --- a/src/cmd/internal/gc/builtin.go +++ b/src/cmd/internal/gc/builtin.go @@ -128,7 +128,7 @@ const runtimeimport = "" + "func @\"\".selectgo (@\"\".sel·1 *byte)\n" + "func @\"\".block ()\n" + "func @\"\".makeslice (@\"\".typ·2 *byte, @\"\".nel·3 int64, @\"\".cap·4 int64) (@\"\".ary·1 []any)\n" + - "func @\"\".growslice (@\"\".typ·2 *byte, @\"\".old·3 []any, @\"\".n·4 int64) (@\"\".ary·1 []any)\n" + + "func @\"\".growslice (@\"\".typ·2 *byte, @\"\".old·3 []any, @\"\".n·4 int) (@\"\".ary·1 []any)\n" + "func @\"\".memmove (@\"\".to·1 *any, @\"\".frm·2 *any, @\"\".length·3 uintptr)\n" + "func @\"\".memclr (@\"\".ptr·1 *byte, @\"\".length·2 uintptr)\n" + "func @\"\".memequal (@\"\".x·2 *any, @\"\".y·3 *any, @\"\".size·4 uintptr) (? bool)\n" + diff --git a/src/cmd/internal/gc/builtins/runtime.go b/src/cmd/internal/gc/builtins/runtime.go index 144d8af3e7..0e1ebea06e 100644 --- a/src/cmd/internal/gc/builtins/runtime.go +++ b/src/cmd/internal/gc/builtins/runtime.go @@ -159,7 +159,7 @@ func selectgo(sel *byte) func block() func makeslice(typ *byte, nel int64, cap int64) (ary []any) -func growslice(typ *byte, old []any, n int64) (ary []any) +func growslice(typ *byte, old []any, n int) (ary []any) func memmove(to *any, frm *any, length uintptr) func memclr(ptr *byte, length uintptr) diff --git a/src/cmd/internal/gc/walk.go b/src/cmd/internal/gc/walk.go index 14396440f7..842deab593 100644 --- a/src/cmd/internal/gc/walk.go +++ b/src/cmd/internal/gc/walk.go @@ -2949,14 +2949,14 @@ func appendslice(n *Node, init **NodeList) *Node { nif.Ntest = Nod(OGT, nt, Nodintconst(0)) - // instantiate growslice(Type*, []any, int64) []any + // instantiate growslice(Type*, []any, int) []any fn := syslook("growslice", 1) argtype(fn, s.Type.Type) argtype(fn, s.Type.Type) // s = growslice(T, s, n) - nif.Nbody = list1(Nod(OAS, s, mkcall1(fn, s.Type, &nif.Ninit, typename(s.Type), s, conv(nt, Types[TINT64])))) + nif.Nbody = list1(Nod(OAS, s, mkcall1(fn, s.Type, &nif.Ninit, typename(s.Type), s, nt))) l = list(l, nif) @@ -3066,11 +3066,11 @@ func walkappend(n *Node, init **NodeList) *Node { nx := Nod(OIF, nil, nil) // if cap(s) - len(s) < argc nx.Ntest = Nod(OLT, Nod(OSUB, Nod(OCAP, ns, nil), Nod(OLEN, ns, nil)), na) - fn := syslook("growslice", 1) // growslice(, old []T, n int64) (ret []T) + fn := syslook("growslice", 1) // growslice(, old []T, n int) (ret []T) argtype(fn, ns.Type.Type) // 1 old []any argtype(fn, ns.Type.Type) // 2 ret []any - nx.Nbody = list1(Nod(OAS, ns, mkcall1(fn, ns.Type, &nx.Ninit, typename(ns.Type), ns, conv(na, Types[TINT64])))) + nx.Nbody = list1(Nod(OAS, ns, mkcall1(fn, ns.Type, &nx.Ninit, typename(ns.Type), ns, na))) l = list(l, nx) diff --git a/src/runtime/slice.go b/src/runtime/slice.go index 62d6b7ce87..7a2eb624b7 100644 --- a/src/runtime/slice.go +++ b/src/runtime/slice.go @@ -33,16 +33,13 @@ func makeslice(t *slicetype, len64 int64, cap64 int64) sliceStruct { return sliceStruct{p, len, cap} } -// TODO: take uintptr instead of int64? -func growslice(t *slicetype, old sliceStruct, n int64) sliceStruct { +func growslice(t *slicetype, old sliceStruct, n int) sliceStruct { if n < 1 { panic(errorString("growslice: invalid n")) } - cap64 := int64(old.cap) + n - cap := int(cap64) - - if int64(cap) != cap64 || cap < old.cap || t.elem.size > 0 && uintptr(cap) > _MaxMem/uintptr(t.elem.size) { + cap := old.cap + n + if cap < old.cap || t.elem.size > 0 && uintptr(cap) > _MaxMem/uintptr(t.elem.size) { panic(errorString("growslice: cap out of range")) }