1
0
mirror of https://github.com/golang/go synced 2024-11-05 21:46:13 -07:00
Commit Graph

43672 Commits

Author SHA1 Message Date
Alex Gaynor
c2e0f01598 bufio: optimize bufio.Reader.ReadString to avoid an allocation and copy
name                old time/op    new time/op    delta
ReaderReadString-4     226ns ±12%     161ns ±11%  -28.76%  (p=0.008 n=5+5)

name                old alloc/op   new alloc/op   delta
ReaderReadString-4      288B ± 0%      144B ± 0%  -50.00%  (p=0.008 n=5+5)

name                old allocs/op  new allocs/op  delta
ReaderReadString-4      2.00 ± 0%      1.00 ± 0%  -50.00%  (p=0.008 n=5+5)

Change-Id: I77f330b8340c2bfbfff1f6f1000170b65953a200
GitHub-Last-Rev: 65d65302a7
GitHub-Pull-Request: golang/go#34706
Reviewed-on: https://go-review.googlesource.com/c/go/+/199257
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-28 00:53:32 +00:00
Nigel Tao
42c48998aa image/draw: optimize paletted dst + uniform src
name            old time/op  new time/op  delta
PalettedFill-4  5.74ms ± 1%  0.01ms ± 1%  -99.78%  (p=0.008 n=5+5)
PalettedRGBA-4  3.34ms ± 3%  3.33ms ± 0%     ~     (p=0.690 n=5+5)

Fixes #35938

Thanks to pjbgtnj for the suggestion.

Change-Id: I07b494482cce918f556e196c5a4b481b4c16de3a
Reviewed-on: https://go-review.googlesource.com/c/go/+/230118
Run-TryBot: Nigel Tao <nigeltao@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
2020-04-27 23:05:16 +00:00
smasher164
0a364330a2 strconv: remove redundant conversions to int
IntSize is an untyped constant that does not need explicit conversion.
Annotating IntSize as an int and running github.com/mdempsky/unconvert
reveals these two cases.

Fixes #38682.

Change-Id: I014646b7457ddcde32474810153229dcf0c269c6
Reviewed-on: https://go-review.googlesource.com/c/go/+/230306
Run-TryBot: Akhil Indurti <aindurti@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-27 21:46:18 +00:00
Michael Anthony Knyszek
287d1ec96c runtime: ensure allocToCache updates searchAddr in a valid way
Currently allocToCache assumes it can move the search address past the
block it allocated the cache from, which violates the property that
searchAddr should always point to mapped memory (i.e. memory represented
by pageAlloc.inUse).

This bug was already fixed once for pageAlloc.alloc in the Go 1.14
release via CL 216697, but that changed failed to take into account
allocToCache.

Fixes #38605.

Change-Id: Id08180aa10d19dc0f9f551a1d9e327a295560dff
Reviewed-on: https://go-review.googlesource.com/c/go/+/229577
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
2020-04-27 21:37:31 +00:00
Ruixin(Peter) Bao
9a3f22be7a hash/crc32: simplify hasVX checking on s390x
Originally, we use an assembly function that returns a boolean result to
tell whether the machine has vector facility or not. It is now no longer
needed when we can directly use cpu.S390X.HasVX variable. This CL
also removes the last occurence of hasVectorFacility function on s390x.

Change-Id: Id20cb746c21eacac5e13344b362e2d87adfe4317
Reviewed-on: https://go-review.googlesource.com/c/go/+/230337
Reviewed-by: Michael Munday <mike.munday@ibm.com>
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-27 21:18:58 +00:00
Ruixin(Peter) Bao
a7e9e84716 math/big: simplify hasVX checking on s390x
Originally, we use an assembly function that returns a boolean result to
tell whether the machine has vector facility or not. It is now no longer
needed when we can directly use cpu.S390X.HasVX variable.

Change-Id: Ic1dae851982532bcfd9a9453416c112347f21d87
Reviewed-on: https://go-review.googlesource.com/c/go/+/230318
Reviewed-by: Michael Munday <mike.munday@ibm.com>
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-27 20:20:53 +00:00
Ruixin Bao
d2f5e4e38c math: simplify hasVX checking on s390x
Originally, we use an assembly function that returns a boolean result to
tell whether the machine has vector facility or not. It is now no longer
needed when we can directly use cpu.S390X.HasVX variable.

Change-Id: Ic3ffeb9e63238ef41406d97cdc42502145ddb454
Reviewed-on: https://go-review.googlesource.com/c/go/+/230319
Reviewed-by: Michael Munday <mike.munday@ibm.com>
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-27 20:06:57 +00:00
Ruixin Bao
a637ee1970 crypto/ecdsa: implement ecdsa on s390x for P256/P384/P521 using KDSA instruction
This CL revives CL 174437(also IBM CLA) and adds benchmarks and some simplifications.

The original commit message is as follows:

Utilize KDSA when available. This guarantees constant time operation on all three curves mentioned,
and is faster than conventional assembly.

Benchmarks:
name             old time/op    new time/op    delta
SignP256-8         15.2µs ±14%    14.1µs ±18%     ~     (p=0.356 n=9+10)
SignP384-8         4.28ms ±26%    0.02ms ±30%  -99.43%  (p=0.000 n=10+10)
VerifyP256-8       33.6µs ±13%    13.3µs ±38%  -60.32%  (p=0.000 n=9+10)

name             old alloc/op   new alloc/op   delta
SignP256-8         2.16kB ± 0%    1.60kB ± 0%  -25.63%  (p=0.000 n=9+10)
SignP384-8         1.75MB ± 0%    0.00MB ± 0%  -99.90%  (p=0.000 n=9+10)
VerifyP256-8       1.08kB ± 0%    0.18kB ± 0%  -83.70%  (p=0.000 n=9+10)

name             old allocs/op  new allocs/op  delta
SignP256-8           29.0 ± 0%      22.0 ± 0%  -24.14%  (p=0.000 n=10+10)
SignP384-8          14.4k ± 0%      0.0k ± 0%  -99.85%  (p=0.000 n=9+10)
VerifyP256-8         23.0 ± 0%       7.0 ± 0%  -69.57%  (p=0.000 n=10+10)

Change-Id: Ifa1fc5917fa7592dd592affa7549147dbc9b4169
Reviewed-on: https://go-review.googlesource.com/c/go/+/228580
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Munday <mike.munday@ibm.com>
2020-04-27 19:49:49 +00:00
Ruixin(Peter) Bao
d646c035f9 crypto/ed25519: implement ed25519 on s390x using KDSA instruction
This CL allows the usage of KDSA instruction when it is available.  The
instruction is designed to be resistant to side channel attacks and
offers performance improvement for ed25519.

Benchmarks:
name              old time/op    new time/op    delta
Signing-8            120µs ±20%      62µs ±12%   -48.40%  (p=0.000 n=10+10)
Verification-8       325µs ±17%      69µs ±10%   -78.80%  (p=0.000 n=10+10)

name              old alloc/op   new alloc/op   delta
Signing-8             448B ± 0%        0B       -100.00%  (p=0.000 n=10+10)
Verification-8        288B ± 0%        0B       -100.00%  (p=0.000 n=10+10)

name              old allocs/op  new allocs/op  delta
Signing-8             5.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)
Verification-8        2.00 ± 0%      0.00       -100.00%  (p=0.000 n=10+10)

Change-Id: I0330ce83d807370b419ce638bc2cae4cb3c250dc
Reviewed-on: https://go-review.googlesource.com/c/go/+/202578
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Munday <mike.munday@ibm.com>
2020-04-27 19:49:42 +00:00
Andrew Bonventre
6a4441d6fe Revert "go/types: add UsesCgo config to support _cgo_gotypes.go"
This reverts CL 33677.

Reason for revert: NetBSD is broken

Updates #38649

Change-Id: Id60e3c97d3cb4fb0053dea03b95dbbb0b850c883
Reviewed-on: https://go-review.googlesource.com/c/go/+/230038
Run-TryBot: Andrew Bonventre <andybons@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2020-04-27 19:35:01 +00:00
Dan Scales
1067ab0808 runtime: added several new lock-rank partial order edges
Several new ones came from my testing (long, repeated runs) and one (assistQueue ->
spine) came from the staticlockranking builder (filed as issue 38441).

Fixes #38441

Change-Id: I4268da0d8b8cc51251eba6bd936110c8ab4c4e61
Reviewed-on: https://go-review.googlesource.com/c/go/+/229480
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Pratt <mpratt@google.com>
2020-04-27 19:25:31 +00:00
Michael Anthony Knyszek
08bf64a81e runtime: bound small object sweeping to 100 spans when allocating
Currently, the small object sweeper will sweep until it finds a free
slot or there are no more spans of that size class to sweep. In dense
heaps, this can cause sweeping for a given size class to take
unbounded time, and gets worse with larger heaps.

This CL limits the small object sweeper to try at most 100 spans
before giving up and allocating a fresh span. Since it's already shown
that 100 spans are completely full at that point, the space overhead
of this fresh span is at most 1%.

This CL is based on an experimental CL by Austin Clements (CL 187817)
and is updated to be part of the mcentral implementation, gated by
go115NewMCentralImpl.

Updates #18155.

Change-Id: I37a72c2dcc61dd6f802d1d0eac3683e6642b6ef8
Reviewed-on: https://go-review.googlesource.com/c/go/+/229998
Run-TryBot: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Austin Clements <austin@google.com>
2020-04-27 18:40:56 +00:00
Michael Anthony Knyszek
a13691966a runtime: add new mcentral implementation
Currently mcentral is implemented as a couple of linked lists of spans
protected by a lock. Unfortunately this design leads to significant lock
contention.

The span ownership model is also confusing and complicated. In-use spans
jump between being owned by multiple sources, generally some combination
of a gcSweepBuf, a concurrent sweeper, an mcentral or an mcache.

So first to address contention, this change replaces those linked lists
with gcSweepBufs which have an atomic fast path. Then, we change up the
ownership model: a span may be simultaneously owned only by an mcentral
and the page reclaimer. Otherwise, an mcentral (which now consists of
sweep bufs), a sweeper, or an mcache are the sole owners of a span at
any given time. This dramatically simplifies reasoning about span
ownership in the runtime.

As a result of this new ownership model, sweeping is now driven by
walking over the mcentrals rather than having its own global list of
spans. Because we no longer have a global list and we traditionally
haven't used the mcentrals for large object spans, we no longer have
anywhere to put large objects. So, this change also makes it so that we
keep large object spans in the appropriate mcentral lists.

In terms of the static lock ranking, we add the spanSet spine locks in
pretty much the same place as the mcentral locks, since they have the
potential to be manipulated both on the allocation and sweep paths, like
the mcentral locks.

This new implementation is turned on by default via a feature flag
called go115NewMCentralImpl.

Benchmark results for 1 KiB allocation throughput (5 runs each):

name \ MiB/s  go113       go114       gotip       gotip+this-patch
AllocKiB-1    1.71k ± 1%  1.68k ± 1%  1.59k ± 2%      1.71k ± 1%
AllocKiB-2    2.46k ± 1%  2.51k ± 1%  2.54k ± 1%      2.93k ± 1%
AllocKiB-4    4.27k ± 1%  4.41k ± 2%  4.33k ± 1%      5.01k ± 2%
AllocKiB-8    4.38k ± 3%  5.24k ± 1%  5.46k ± 1%      8.23k ± 1%
AllocKiB-12   4.38k ± 3%  4.49k ± 1%  5.10k ± 1%     10.04k ± 0%
AllocKiB-16   4.31k ± 1%  4.14k ± 3%  4.22k ± 0%     10.42k ± 0%
AllocKiB-20   4.26k ± 1%  3.98k ± 1%  4.09k ± 1%     10.46k ± 3%
AllocKiB-24   4.20k ± 1%  3.97k ± 1%  4.06k ± 1%     10.74k ± 1%
AllocKiB-28   4.15k ± 0%  4.00k ± 0%  4.20k ± 0%     10.76k ± 1%

Fixes #37487.

Change-Id: I92d47355acacf9af2c41bf080c08a8c1638ba210
Reviewed-on: https://go-review.googlesource.com/c/go/+/221182
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2020-04-27 18:19:26 +00:00
Michael Anthony Knyszek
9582b6e8fd runtime: implement the spanSet data structure
This change implements the spanSet data structure which is based off of
the gcSweepBuf data structure. While the general idea is the same (one
has two of these which one switches between every GC cycle; one to push
to and one to pop from), there are some key differences.

Firstly, we never have a need to iterate over this data structure so
delete numBlocks and block. Secondly, we want to be able to pop from the
front of the structure concurrently with pushes to the back. As a result
we need to maintain both a head and a tail and this change introduces an
atomic headTail structure similar to the one used by sync.Pool. It also
implements popfirst in a similar way.

As a result of this headTail, we need to be able to explicitly reset the
length, head, and tail when it goes empty at the end of sweep
termination, so add a reset method.

Updates #37487.

Change-Id: I5b8ad290ec32d591e3c8c05e496c5627018074f6
Reviewed-on: https://go-review.googlesource.com/c/go/+/221181
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2020-04-27 18:16:07 +00:00
Michael Anthony Knyszek
d1798d5aa0 runtime: manage a pool of spanSetBlocks and free them eagerly
This change adds a global pool of spanSetBlocks to the spanSet data
structure and adds support for eagerly freeing these blocks back to the
pool if the block goes empty.

This change prepares us to use this data structure in more places in the
runtime by allowing reuse of spanSetBlock.

Updates #37487.

Change-Id: I0752226e3667a9e3e1d87c9b66edaedeae1ac23f
Reviewed-on: https://go-review.googlesource.com/c/go/+/221180
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2020-04-27 17:50:41 +00:00
Michael Anthony Knyszek
8af8fa9103 runtime: add spanSet data structure
This change copies the gcSweepBuf data structure into a new file and
renames it spanSet. It will serve as the basis for a heavily modified
version of the gcSweepBuf data structure for the new mcentral
implementation.

We move it into a separate file now for two reasons:
1. We will need both implementations as they will coexist simultaneously
   for a time.
2. By creating it now in a new change it'll make future changes which
   modify it easier to review (rather than introducing the new file then).

Updates #37487.

Change-Id: If80603cab6e813a1ee2e5ecd49dcde5d8045a6c7
Reviewed-on: https://go-review.googlesource.com/c/go/+/221179
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2020-04-27 17:49:51 +00:00
Joel Sing
40f2dab0e1 cmd/compile: implement multi-control branches for riscv64
Implement multi-control branches for riscv64, switching to using the BNEZ
pseudo-instruction when rewriting conditionals. This will allow for further
branch optimisations to later be performed via rewrites.

Change-Id: I7f2c69f3c77494b403f26058c6bc8432d8070ad0
Reviewed-on: https://go-review.googlesource.com/c/go/+/226399
Reviewed-by: Keith Randall <khr@golang.org>
Run-TryBot: Joel Sing <joel@sing.id.au>
2020-04-27 17:49:30 +00:00
Daniel Theophanes
1518123114 database/sql/driver: enhance driver package documentation
Change-Id: I455acdb71354f14e0bc4104cbd7abd5c89958dd9
Reviewed-on: https://go-review.googlesource.com/c/go/+/230214
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-27 17:36:02 +00:00
Josh Bleecher Snyder
a3374fa0f8 cmd/compile: convert more generic rules to typed aux
Passes toolstash-check.

Change-Id: I07d79d809babfeda883a49f0b21ab27ede5381cb
Reviewed-on: https://go-review.googlesource.com/c/go/+/230211
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-27 17:34:48 +00:00
Josh Bleecher Snyder
c9591d73ef cmd/compile: eliminate some array equality alg loops
type T [3]string

Prior to this change, we generated this equality alg for T:

func eqT(p, q *T) (r bool) {
    for i := range *p {
        if len(p[i]) == len(q[i]) {
        } else {
            return
        }
    }
    for j := range *p {
        if runtime.memeq(p[j].ptr, q[j].ptr, len(p[j])) {
        } else {
            return
        }
    }
    return true
}

That first loop can be profitably eliminated;
it's cheaper to spell out 3 length equality checks.

We now generate:

func eqT(p, q *T) (r bool) {
    if len(p[0]) == len(q[0]) &&
        len(p[1]) == len(q[1]) &&
        len(p[2]) == len(q[2]) {
    } else {
        return
    }
    for i := 0; i < len(p); i++ {
        if runtime.memeq(p[j].ptr, q[j].ptr, len(p[j])) {
        } else {
            return
        }
    }
    return true
}

We now also eliminate loops for small float arrays as well,
and for any array of size 1.

These cutoffs were selected to minimize code size on amd64
at this moment, for lack of a more compelling methodology.
Any smallish number would do.

The switch from range loops to plain for loops allowed me
to use a temp instead of a named var, which eliminated
a pointless argument to checkAll.
The code to construct them is also a bit clearer, in my opinion.

Change-Id: I1bdd8ee4a2739d00806e66b17a4e76b46e71231a
Reviewed-on: https://go-review.googlesource.com/c/go/+/230210
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-27 17:34:32 +00:00
Josh Bleecher Snyder
1c4e9b2eda cmd/compile: improve equality algs for arrays of strings
type T [8]string

Prior to this change, we generated this equality algorithm for T:

func eqT(p, q *T) (r bool) {
    for i := range *p {
        if p[i] == q[i] {
		} else {
            return
        }
    }
    return true
}

This change splits this into two loops, so that we can do the
cheap (length) half early and only then do the expensive (contents) half.

We now generate:

func eqT(p, q *T) (r bool) {
    for i := range *p {
        if len(p[i]) == len(q[i]) {
        } else {
            return
        }
    }
    for j := range *p {
        if runtime.memeq(p[j].ptr, q[j].ptr, len(p[j])) {
        } else {
            return
        }
    }
    return true
}

The generated code is typically ~17% larger because it contains
two loops instead of one. In the future, we might want to unroll
the first loop when the array is small.

Change-Id: I26b2793b90ec6aff21766a411b15a4ff1096c03f
Reviewed-on: https://go-review.googlesource.com/c/go/+/230209
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-27 17:20:00 +00:00
Josh Bleecher Snyder
7eab9506c9 cmd/compile: improve equality algs for arrays of interfaces
type T [8]interface{}

Prior to this change, we generated this equality algorithm for T:

func eqT(p, q *T) bool {
    for i := range *p {
        if p[i] != q[i] {
            return false
        }
    }
    return true
}

This change splits this into two loops, so that we can do the
cheap (type) half early and only then do the expensive (data) half.

We now generate:

func eqT(p, q *T) (r bool) {
    for i := range *p {
        if p[i].type == q[i].type {
        } else {
            return
        }
    }
    for j := range *p {
        if runtime.efaceeq(p[j].type, p[j].data, q[j].data) {
        } else {
            return
        }
    }
    return true
}

The use of a named return value and a bare return is to work
around some typechecking problems that stymied me.

The structure of using equals and else (instead of not equals and then)
was for implementation convenience and clarity. As a bonus,
it generates slightly shorter code on AMD64, because zeroing a register
to return is cheaper than writing $1 to it.

The generated code is typically ~17% larger because it contains
two loops instead of one. In the future, we might want to unroll
the first loop when the array is small.

Change-Id: I5b2c8dd3384852f085c4f3e1f6ad20bc5ae59062
Reviewed-on: https://go-review.googlesource.com/c/go/+/230208
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-27 17:19:48 +00:00
Josh Bleecher Snyder
1cc7be89a9 cmd/compile: improve generated eq algs for structs containing interfaces
type T struct {
    s interface{}
    i int
}

Prior to this change, we generated this equality algorithm for T:

func eqT(p, q *T) bool {
    return p.s.type == q.s.type &&
      runtime.efaceeq(p.s.type, p.s.data, q.s.data) &&
      p.i == q.i
}

This change splits the two halves of the interface equality,
so that we can do the cheap (type) half early and the expensive
(data) half late. We now generate:

func eqT(p, q *T) bool {
    return p.s.type == q.s.type &&
      p.i == q.i &&
      runtime.efaceeq(p.s.type, p.s.data, q.s.data)
}

The generated code tends to be a bit smaller. Examples:

go/ast
.eq."".ForStmt 306 -> 304  (-0.65%)
.eq."".TypeAssertExpr 221 -> 219  (-0.90%)
.eq."".TypeSwitchStmt 228 -> 226  (-0.88%)
.eq."".ParenExpr 150 -> 148  (-1.33%)
.eq."".IndexExpr 221 -> 219  (-0.90%)
.eq."".SwitchStmt 228 -> 226  (-0.88%)
.eq."".RangeStmt 334 -> 332  (-0.60%)

Change-Id: Iec9e24f214ca772416202b9fb9252e625c22380e
Reviewed-on: https://go-review.googlesource.com/c/go/+/230207
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-27 17:19:38 +00:00
Josh Bleecher Snyder
f4e13b83aa cmd/compile: refactor out eqinterface
Refactor out creating the two Nodes needed to check interface equality.
Preliminary work to other optimizations.

Passes toolstash-check.

Change-Id: Id6b39e8e78f07289193423d0ef905d70826acf89
Reviewed-on: https://go-review.googlesource.com/c/go/+/230206
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-27 17:19:27 +00:00
Josh Bleecher Snyder
5029c3671d cmd/compile: improve generated eq algs for structs containing strings
type T struct {
    s string
    i int
}

Prior to this change, we generated this equality algorithm for T:

func eqT(p, q *T) bool {
    return len(p.s) == len(q.s) &&
      runtime.memequal(p.s.ptr, q.s.ptr, len(p.s)) &&
      p.i == q.i
}

This change splits the two halves of the string equality,
so that we can do the cheap (length) half early and the expensive
(contents) half late. We now generate:

func eqT(p, q *T) bool {
    return len(p.s) == len(q.s) &&
      p.i == q.i &&
      runtime.memequal(p.s.ptr, q.s.ptr, len(p.s))
}

The generated code for these functions tends to be a bit shorter. Examples:

runtime
.eq."".Frame 274 -> 272  (-0.73%)
.eq."".funcinl 249 -> 247  (-0.80%)
.eq."".modulehash 207 -> 205  (-0.97%)

Change-Id: I4efac9f7d410f0a11a94dcee2bf9c0b49b60e301
Reviewed-on: https://go-review.googlesource.com/c/go/+/230205
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-27 17:19:16 +00:00
Josh Bleecher Snyder
daae72e88e cmd/compile: refactor out eqstring
Refactor out creating the two Nodes needed to check string equality.
Preliminary work to other optimizations.

Passes toolstash-check.

Change-Id: I72e824dac904e579b8ba9a3669a94fa1471112d2
Reviewed-on: https://go-review.googlesource.com/c/go/+/230204
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-27 17:19:07 +00:00
Josh Bleecher Snyder
79648bde2d cmd/compile: make runtime calls last in eq algs
type T struct {
    f float64
    a [64]uint64
    g float64
}

Prior to this change, the generated equality algorithm for T was:

func eqT(p, q *T) bool {
    return p.f == q.f && runtime.memequal(p.a, q.a, 512) && p.g == q.g
}

In handwritten code, we would normally put the cheapest checks first.
This change takes a step in that direction. We now generate:

func eqT(p, q *T) bool {
    return p.f == q.f && p.g == q.g && runtime.memequal(p.a, q.a, 512)
}

For most types, this also generates considerably shorter code. Examples:

runtime
.eq."".mstats 406 -> 391  (-3.69%)
.eq.""._func 114 -> 101  (-11.40%)
.eq."".itab 115 -> 102  (-11.30%)
.eq."".scase 125 -> 116  (-7.20%)
.eq."".traceStack 119 -> 102  (-14.29%)
.eq."".gcControllerState 169 -> 161  (-4.73%)
.eq."".sweepdata 121 -> 112  (-7.44%)

However, for types in which we make unwise choices about inlining
memory-only comparisons (#38494), this generates longer code.

Example:

cmd/internal/obj
.eq."".objWriter 211 -> 214  (+1.42%)
.eq."".Addr 185 -> 187  (+1.08%)

Fortunately, such cases are not common.

Change-Id: I47a27da93c1f88ec71fa350c192f36b29548a217
Reviewed-on: https://go-review.googlesource.com/c/go/+/230203
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-27 17:19:01 +00:00
Daniel Martí
1cf357981e cmd/compile: remove If type in rulegen
We only generate if statements via CondBreak, which is nice as the
control flow is simple and easy to work with. It seems like the If type
was added but never used, so remove it to avoid confusion.

We had a TODO about replacing CondBreak with If instead. I gave that a
try, but it doesn't seem worth the effort. The code gets more complex
and we don't really win anything in return.

While at it, don't use op strings as format strings in exprf. This
doesn't cause any issue at the moment, but it's best to be explicit
about the operator not containing any formatting verbs.

Change-Id: Ib59ad72d3628bf91594efc609e222232ad1e8748
Reviewed-on: https://go-review.googlesource.com/c/go/+/230257
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-27 17:08:03 +00:00
Baokun Lee
20ed142861 cmd/go/internal/web: use url.Redacted
Updates #37873

Change-Id: I2228f31fc7bd7daef086cd05d365fa7c68e60a83
Reviewed-on: https://go-review.googlesource.com/c/go/+/223757
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-27 17:07:16 +00:00
Cuong Manh Le
f1a2a0e0bf cmd/compile: rewrite decArgs rules to use typed aux field
Passes toolstash-check.

Change-Id: I386fb9d52709c4844b313f59f62a4f47c10e490d
Reviewed-on: https://go-review.googlesource.com/c/go/+/230117
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-27 16:18:30 +00:00
Meng Zhuo
9b9556f660 cmd/link: use definition from debug/elf for ldelf
Change-Id: I92d0fb3a244d0151fcc4b25a20913ad69a89f198
Reviewed-on: https://go-review.googlesource.com/c/go/+/224977
Run-TryBot: Meng Zhuo <mengzhuo1203@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Cherry Zhang <cherryyz@google.com>
2020-04-27 15:53:46 +00:00
Alberto Donizetti
70d9b72a87 cmd/compile: convert more arm64 lowering rules to typed aux
Passes

  GOARCH=arm64 gotip build -toolexec 'toolstash -cmp' -a std

Change-Id: Idc0ac2638c7a9b840ba2d6f4bba2e9c5df24c807
Reviewed-on: https://go-review.googlesource.com/c/go/+/230177
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-27 15:50:54 +00:00
Nigel Tao
bce1e25b71 image/png: fix some 32-bit int overflows
Fixes #38435

Change-Id: Ib9ae3cf7f338b2860a5688e448a125f257fe624e
Reviewed-on: https://go-review.googlesource.com/c/go/+/230219
Reviewed-by: Andrew Ekstedt <andrew.ekstedt@gmail.com>
Reviewed-by: Rob Pike <r@golang.org>
2020-04-27 11:55:27 +00:00
Michael Munday
b7a5e7ae92 cmd/compile: adopt strong aux typing for some s390x rules
Apply strong aux typing to lowering rules that do not require
modification beyond substituting -> for =>. Other lowering rules
and all the optimization rules will follow. I'm breaking it up
to allow toolstash-check to pass on the big CLs.

Passes toolstash-check -all.

Change-Id: I6f1340058a8eb5a1390411e59fcbea9d7f777e58
Reviewed-on: https://go-review.googlesource.com/c/go/+/229400
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-27 11:13:52 +00:00
Ruixin(Peter) Bao
925d6b31b0 cmd/compile: adopt strong aux typing for some s390x rules
Convert some Move and Zero Lowering rules to strongly-typed versions.

Passes toolstash-check.

Change-Id: Icaabe05e206d59798e5883a90e9a33bb30270b13
Reviewed-on: https://go-review.googlesource.com/c/go/+/229919
Reviewed-by: Michael Munday <mike.munday@ibm.com>
Run-TryBot: Michael Munday <mike.munday@ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-27 10:23:01 +00:00
Daniel Martí
6a569f243e cmd/compile: minor rulegen simplifications
The commuteDepth variable is no longer necessary; remove it.

Else branches after a log.Fatal call are unnecessary.

Also make the unbalanced return an integer, so we can differentiate
positive from negative cases. We only want to continue a rule with the
following lines if this balance is positive, for example.

While at it, make the balance loop stop when it goes negative, to not
let ")(" seem balanced.

Change-Id: I8aa313343ca5a2f07f638b62a0398fdf108fc9eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/228822
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2020-04-26 20:15:41 +00:00
Pierre Carru
8bcf2834af net/http/httputil: make Switching Protocol requests (e.g. Websockets) cancelable
Ensures that a canceled client request for Switching Protocols
(e.g. h2c, Websockets) will cause the underlying connection to
be terminated.

Adds a goroutine in handleUpgradeResponse in order to select on
the incoming client request's context and appropriately cancel it.

Fixes #35559

Change-Id: I1238e18fd4cce457f034f78d9cdce0e7f93b8bf6
GitHub-Last-Rev: 3629c78493
GitHub-Pull-Request: golang/go#38021
Reviewed-on: https://go-review.googlesource.com/c/go/+/224897
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
2020-04-26 09:26:10 +00:00
Tyson Andre
09630172d4 net/http/httputil: fix typo in unit test name
Everywhere else is using "cancellation"

The reasoning is mentioned in 170060

> Though there is variation in the spelling of canceled,
> cancellation is always spelled with a double l.
>
> Reference: https://www.grammarly.com/blog/canceled-vs-cancelled/

Change-Id: Ifc97c6785afb401814af77c377c2e2745ce53c5a
GitHub-Last-Rev: 05edd7477d
GitHub-Pull-Request: golang/go#38662
Reviewed-on: https://go-review.googlesource.com/c/go/+/230200
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-25 23:15:50 +00:00
Qais Patankar
223d31f9fb A: Qais Patankar (individual CLA)
Change-Id: I329a27d73166b70c5c13918a695d58958dbf8604
GitHub-Last-Rev: ca7be2b287
GitHub-Pull-Request: golang/go#38659
Reviewed-on: https://go-review.googlesource.com/c/go/+/230197
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-25 23:01:43 +00:00
Tyson Andre
19648622d2 math/cmplx: fix typo in code comment
Everywhere else is using "cancellation" as of 2019

The reasoning is mentioned in 170060.

> Though there is variation in the spelling of canceled,
> cancellation is always spelled with a double l.
>
> Reference: https://www.grammarly.com/blog/canceled-vs-cancelled/

Change-Id: I933ea68d7251986ce582b92c33b7cb13cee1d207
GitHub-Last-Rev: fc3d5ada2b
GitHub-Pull-Request: golang/go#38661
Reviewed-on: https://go-review.googlesource.com/c/go/+/230199
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-25 21:06:35 +00:00
Brad Fitzpatrick
7ef28cbd12 testing: give short package variable a longer name
(Update to CL 229837)

Change-Id: Ieab46bd384f76f678ef0d6a38dc043bc4b0c458a
Reviewed-on: https://go-review.googlesource.com/c/go/+/230157
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
2020-04-25 18:40:45 +00:00
Mukesh Sharma
a9f8f02f3c cmd/go/internal/cache: fix typing error in errVerifyMode
This change fixes the typing mistake in errVerifyMode error message in cache.

Change-Id: I10c405a06e3396f9932db72d9de418d7f8aa013c
GitHub-Last-Rev: 14ea7c693c
GitHub-Pull-Request: golang/go#38655
Reviewed-on: https://go-review.googlesource.com/c/go/+/230097
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2020-04-25 14:23:05 +00:00
Tobias Klauser
41e925bbcc testing: replace all GOOS-specific path separators in TempDir
For GOOS=windows the path separator characters '\' and ':' also need be
replaced.

Updates #38465

Change-Id: If7c8cf93058c87d7df6cda140e82fd76578fe699
Reviewed-on: https://go-review.googlesource.com/c/go/+/229837
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-25 10:38:47 +00:00
Josh Bleecher Snyder
49f10f3797 cmd/compile: convert another tranch of generic rules to typed aux
Passes toolstash-check.

Change-Id: I27c01f03c5303876bbf6878a81ffdc4e95de3e3e
Reviewed-on: https://go-review.googlesource.com/c/go/+/230031
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-25 02:19:12 +00:00
Ian Lance Taylor
d422f54619 os, net: define and use os.ErrDeadlineExceeded
If an I/O operation fails because a deadline was exceeded,
return os.ErrDeadlineExceeded. We used to return poll.ErrTimeout,
an internal error, and told users to check the Timeout method.
However, there are other errors with a Timeout method that returns true,
notably syscall.ETIMEDOUT which is returned for a keep-alive timeout.
Checking errors.Is(err, os.ErrDeadlineExceeded) should permit code
to reliably tell why it failed.

This change does not affect the handling of net.Dialer.Deadline,
nor does it change the handling of net.DialContext when the context
deadline is exceeded. Those cases continue to return an error
reported as "i/o timeout" for which Timeout is true, but that error
is not os.ErrDeadlineExceeded.

Fixes #31449

Change-Id: I0323f42e944324c6f2578f00c3ac90c24fe81177
Reviewed-on: https://go-review.googlesource.com/c/go/+/228645
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
2020-04-25 00:26:48 +00:00
Josh Bleecher Snyder
396833caef cmd/compile: avoid double-zeroing
This triggers in 131 functions in std+cmd.
In those functions, it often helps considerably
(2-10% text size reduction).

Noticed while working on #38554.

Change-Id: Id0dbb8e7cb21d469ec08ec3d5be9beb9e8291e9c
Reviewed-on: https://go-review.googlesource.com/c/go/+/229707
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-24 23:58:38 +00:00
Josh Bleecher Snyder
4a7e363288 cmd/compile: optimize Move with all-zero ro sym src to Zero
We set up static symbols during walk that
we later make copies of to initialize local variables.
It is difficult to ascertain at that time exactly
when copying a symbol is profitable vs locally
initializing an autotmp.

During SSA, we are much better placed to optimize.
This change recognizes when we are copying from a
global readonly all-zero symbol and replaces it with
direct zeroing.

This often allows the all-zero symbol to be
deadcode eliminated at link time.
This is not ideal--it makes for large object files,
and longer link times--but it is the cleanest fix I could find.

This makes the final binary for the program in #38554
shrink from >500mb to ~2.2mb.

It also shrinks the standard binaries:

file      before    after     Δ       %
addr2line 4412496   4404304   -8192   -0.186%
buildid   2893816   2889720   -4096   -0.142%
cgo       4841048   4832856   -8192   -0.169%
compile   19926480  19922432  -4048   -0.020%
cover     5281816   5277720   -4096   -0.078%
link      6734648   6730552   -4096   -0.061%
nm        4366240   4358048   -8192   -0.188%
objdump   4755968   4747776   -8192   -0.172%
pprof     14653060  14612100  -40960  -0.280%
trace     11805940  11777268  -28672  -0.243%
vet       7185560   7181416   -4144   -0.058%
total     113588440 113465560 -122880 -0.108%

And not just by removing unnecessary symbols;
the program text shrinks a bit as well.

Fixes #38554

Change-Id: I8381ae6084ae145a5e0cd9410c451e52c0dc51c8
Reviewed-on: https://go-review.googlesource.com/c/go/+/229704
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-24 23:58:10 +00:00
Josh Bleecher Snyder
b3e8a00060 cmd/compile: move duffcopy auxint calculation out of rewrite rules
Package amd64 is a more natural home for it.
It also makes it easier to see how many bytes
are being copied in ssa.html.

Passes toolstash-check.

Change-Id: I5ecf0f0f18e8db2faa2caf7a05028c310952bd94
Reviewed-on: https://go-review.googlesource.com/c/go/+/229703
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-24 23:56:54 +00:00
Josh Bleecher Snyder
b0a8754475 cmd/compile: convert race cleanup rule to typed aux
Passes toolstash-check.

Change-Id: I3005210cc156d01a6ac1ccaafb4311c607681bf0
Reviewed-on: https://go-review.googlesource.com/c/go/+/229691
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-24 23:12:43 +00:00
Josh Bleecher Snyder
32467e677f cmd/compile: convert Move and Zero optimizations to typed aux
Passes toolstash-check.

Change-Id: I9bd722ce19b2ef39931658a02663aeb7db575939
Reviewed-on: https://go-review.googlesource.com/c/go/+/229690
Reviewed-by: Keith Randall <khr@golang.org>
2020-04-24 23:12:34 +00:00