]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/gc, runtime: change growslice to use int instead of int64
authorMatthew Dempsky <mdempsky@google.com>
Fri, 27 Feb 2015 06:13:05 +0000 (15:13 +0900)
committerDmitry Vyukov <dvyukov@google.com>
Wed, 4 Mar 2015 17:17:17 +0000 (17:17 +0000)
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 <dvyukov@google.com>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/cmd/internal/gc/builtin.go
src/cmd/internal/gc/builtins/runtime.go
src/cmd/internal/gc/walk.go
src/runtime/slice.go

index a5d27bd762e01b05fcb473264e8b88b7d17ba744..f1a8ed8a31fa387f71a406568ce21423664fe0e9 100644 (file)
@@ -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" +
index 144d8af3e7e05a29ce6303b049eaf0f509115af8..0e1ebea06e8c23bffd603dfd21ba10c9b2651ff0 100644 (file)
@@ -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)
 
index 14396440f7e40fd94e9c043224a76f99116a586e..842deab593776f5b42a87a6bf6797924d0b2d369 100644 (file)
@@ -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(<type>, old []T, n int64) (ret []T)
+       fn := syslook("growslice", 1) //   growslice(<type>, 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)
 
index 62d6b7ce87735e16c83cd9d854bde4c9964ef306..7a2eb624b78b7a8f006f4ae3328787c245382b9a 100644 (file)
@@ -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"))
        }