2017-09-13 15:04:16 +02:00
|
|
|
// Copyright 2017 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.
|
|
|
|
|
|
2020-12-23 01:09:46 -05:00
|
|
|
package test
|
2017-09-13 15:04:16 +02:00
|
|
|
|
|
|
|
|
import (
|
2017-09-14 15:51:18 +01:00
|
|
|
"bufio"
|
2017-09-13 15:04:16 +02:00
|
|
|
"internal/testenv"
|
2017-09-14 15:51:18 +01:00
|
|
|
"io"
|
2019-03-09 17:48:23 +00:00
|
|
|
"math/bits"
|
2017-09-13 15:04:16 +02:00
|
|
|
"os/exec"
|
2017-09-14 15:51:18 +01:00
|
|
|
"regexp"
|
2017-09-20 13:09:08 -05:00
|
|
|
"runtime"
|
2017-09-14 15:51:18 +01:00
|
|
|
"strings"
|
2017-09-13 15:04:16 +02:00
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-11 10:49:55 -08:00
|
|
|
// TestIntendedInlining tests that specific functions are inlined.
|
2017-09-13 15:04:16 +02:00
|
|
|
// This allows refactoring for code clarity and re-use without fear that
|
|
|
|
|
// changes to the compiler will cause silent performance regressions.
|
|
|
|
|
func TestIntendedInlining(t *testing.T) {
|
|
|
|
|
if testing.Short() && testenv.Builder() == "" {
|
|
|
|
|
t.Skip("skipping in short mode")
|
|
|
|
|
}
|
|
|
|
|
testenv.MustHaveGoRun(t)
|
|
|
|
|
t.Parallel()
|
|
|
|
|
|
2017-09-13 21:03:20 +02:00
|
|
|
// want is the list of function names (by package) that should
|
2019-02-22 15:53:52 +00:00
|
|
|
// be inlinable. If they have no callers in their packages, they
|
2018-09-17 14:08:03 -05:00
|
|
|
// might not actually be inlined anywhere.
|
2017-09-13 21:03:20 +02:00
|
|
|
want := map[string][]string{
|
|
|
|
|
"runtime": {
|
|
|
|
|
"add",
|
2017-09-23 21:44:18 +01:00
|
|
|
"acquirem",
|
|
|
|
|
"add1",
|
2017-09-13 21:03:20 +02:00
|
|
|
"addb",
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
"adjustpanics",
|
|
|
|
|
"adjustpointer",
|
2019-06-28 16:44:07 +00:00
|
|
|
"alignDown",
|
|
|
|
|
"alignUp",
|
2017-09-13 21:03:20 +02:00
|
|
|
"bucketMask",
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
"bucketShift",
|
|
|
|
|
"chanbuf",
|
|
|
|
|
"evacuated",
|
|
|
|
|
"fastlog2",
|
2017-09-13 21:03:20 +02:00
|
|
|
"fastrand",
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
"float64bits",
|
2018-03-30 22:54:00 -07:00
|
|
|
"getArgInfoFast",
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
"getm",
|
2020-11-02 16:58:38 +00:00
|
|
|
"getMCache",
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
"isDirectIface",
|
|
|
|
|
"itabHashFunc",
|
2017-09-13 21:03:20 +02:00
|
|
|
"noescape",
|
runtime: reduce linear search through pcvalue cache
This change introduces two optimizations together,
one for recursive and one for non-recursive stacks.
For recursive stacks, we introduce the new entry
at the beginning of the cache, so it can be found first.
This adds an extra read and write.
While we're here, switch from fastrandn, which does a multiply,
to fastrand % n, which does a shift.
For non-recursive stacks, split the cache from [16]pcvalueCacheEnt
into [2][8]pcvalueCacheEnt, and add a very cheap associative lookup.
name old time/op new time/op delta
StackCopyPtr-8 118ms ± 1% 106ms ± 2% -9.56% (p=0.000 n=17+18)
StackCopy-8 95.8ms ± 1% 87.0ms ± 3% -9.11% (p=0.000 n=19+20)
StackCopyNoCache-8 135ms ± 2% 139ms ± 1% +3.06% (p=0.000 n=19+18)
During make.bash, the association function used has this return distribution:
percent count return value
53.23% 678797 1
46.74% 596094 0
It is definitely not perfect, but it is pretty good,
and that's all we need.
Change-Id: I2cabb1d26b99c5111bc28f427016a2a5e6c620fd
Reviewed-on: https://go-review.googlesource.com/c/110564
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
2018-04-01 16:39:34 -07:00
|
|
|
"pcvalueCacheKey",
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
"readUnaligned32",
|
|
|
|
|
"readUnaligned64",
|
2017-09-23 21:44:18 +01:00
|
|
|
"releasem",
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
"roundupsize",
|
2018-04-01 12:21:57 -07:00
|
|
|
"stackmapdata",
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
"stringStructOf",
|
2017-09-23 21:44:18 +01:00
|
|
|
"subtract1",
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
"subtractb",
|
|
|
|
|
"tophash",
|
|
|
|
|
"(*bmap).keys",
|
|
|
|
|
"(*bmap).overflow",
|
|
|
|
|
"(*waitq).enqueue",
|
2021-09-21 14:05:57 -07:00
|
|
|
"(*_func).entry",
|
2017-09-23 21:44:18 +01:00
|
|
|
|
|
|
|
|
// GC-related ones
|
|
|
|
|
"cgoInRange",
|
|
|
|
|
"gclinkptr.ptr",
|
|
|
|
|
"guintptr.ptr",
|
|
|
|
|
"heapBits.bits",
|
|
|
|
|
"heapBits.isPointer",
|
|
|
|
|
"heapBits.morePointers",
|
|
|
|
|
"heapBits.next",
|
|
|
|
|
"heapBitsForAddr",
|
|
|
|
|
"markBits.isMarked",
|
|
|
|
|
"muintptr.ptr",
|
|
|
|
|
"puintptr.ptr",
|
2018-02-16 17:45:21 -05:00
|
|
|
"spanOf",
|
2017-09-23 21:44:18 +01:00
|
|
|
"spanOfUnchecked",
|
2020-10-14 17:18:27 -04:00
|
|
|
"(*gcWork).putFast",
|
2017-09-23 21:44:18 +01:00
|
|
|
"(*gcWork).tryGetFast",
|
|
|
|
|
"(*guintptr).set",
|
|
|
|
|
"(*markBits).advance",
|
|
|
|
|
"(*mspan).allocBitsForIndex",
|
|
|
|
|
"(*mspan).base",
|
|
|
|
|
"(*mspan).markBitsForBase",
|
|
|
|
|
"(*mspan).markBitsForIndex",
|
|
|
|
|
"(*muintptr).set",
|
|
|
|
|
"(*puintptr).set",
|
2017-09-13 21:03:20 +02:00
|
|
|
},
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
"runtime/internal/sys": {},
|
2018-01-27 11:55:34 +01:00
|
|
|
"runtime/internal/math": {
|
|
|
|
|
"MulUintptr",
|
|
|
|
|
},
|
2017-09-24 17:55:19 +01:00
|
|
|
"bytes": {
|
|
|
|
|
"(*Buffer).Bytes",
|
|
|
|
|
"(*Buffer).Cap",
|
|
|
|
|
"(*Buffer).Len",
|
2018-12-01 16:28:27 +00:00
|
|
|
"(*Buffer).Grow",
|
2017-09-24 17:55:19 +01:00
|
|
|
"(*Buffer).Next",
|
|
|
|
|
"(*Buffer).Read",
|
|
|
|
|
"(*Buffer).ReadByte",
|
|
|
|
|
"(*Buffer).Reset",
|
|
|
|
|
"(*Buffer).String",
|
|
|
|
|
"(*Buffer).UnreadByte",
|
|
|
|
|
"(*Buffer).tryGrowByReslice",
|
|
|
|
|
},
|
2018-09-17 14:08:03 -05:00
|
|
|
"compress/flate": {
|
|
|
|
|
"byLiteral.Len",
|
|
|
|
|
"byLiteral.Less",
|
|
|
|
|
"byLiteral.Swap",
|
2020-10-16 15:05:04 +01:00
|
|
|
"(*dictDecoder).tryWriteCopy",
|
2018-09-17 14:08:03 -05:00
|
|
|
},
|
encoding/base64: speed up the decoder
Most of the decoding time is spent in the first Decode loop, since the
rest of the function only deals with the few remaining bytes. Any
unnecessary work done in that loop body matters tremendously.
One such unnecessary bottleneck was the use of the enc.decodeMap table.
Since enc is a pointer receiver, and the field is used within the
non-inlineable function decode64, the decoder must perform a nil check
at every iteration.
To fix that, move the enc.decodeMap uses to the parent function, where
we can lift the nil check outside the loop. That gives roughly a 15%
speed-up. The function no longer performs decoding per se, so rename it.
While at it, remove the now unnecessary receivers.
An unfortunate side effect of this change is that the loop now contains
eight bounds checks on src instead of just one. However, not having to
slice src plus the nil check removal well outweigh the added cost.
The other piece that made decode64 slow was that it wasn't inlined, and
had multiple branches. Use a simple bitwise-or trick suggested by Roger
Peppe, and collapse the rest of the bitwise logic into a single
expression. Inlinability and the reduced branching give a further 10%
speed-up.
Finally, add these two functions to TestIntendedInlining, since we want
them to stay inlinable.
Apply the same refactor to decode32 for consistency, and to let 32-bit
architectures see a similar performance gain for large inputs.
name old time/op new time/op delta
DecodeString/2-8 47.3ns ± 1% 45.8ns ± 0% -3.28% (p=0.002 n=6+6)
DecodeString/4-8 55.8ns ± 2% 51.5ns ± 0% -7.71% (p=0.004 n=5+6)
DecodeString/8-8 64.9ns ± 0% 61.7ns ± 0% -4.99% (p=0.004 n=5+6)
DecodeString/64-8 238ns ± 0% 198ns ± 0% -16.54% (p=0.002 n=6+6)
DecodeString/8192-8 19.5µs ± 0% 14.6µs ± 0% -24.96% (p=0.004 n=6+5)
name old speed new speed delta
DecodeString/2-8 84.6MB/s ± 1% 87.4MB/s ± 0% +3.38% (p=0.002 n=6+6)
DecodeString/4-8 143MB/s ± 2% 155MB/s ± 0% +8.41% (p=0.004 n=5+6)
DecodeString/8-8 185MB/s ± 0% 195MB/s ± 0% +5.29% (p=0.004 n=5+6)
DecodeString/64-8 369MB/s ± 0% 442MB/s ± 0% +19.78% (p=0.002 n=6+6)
DecodeString/8192-8 560MB/s ± 0% 746MB/s ± 0% +33.27% (p=0.004 n=6+5)
Updates #19636.
Change-Id: Ib839577b0e3f5a2bb201f5cae580c61365d92894
Reviewed-on: https://go-review.googlesource.com/c/go/+/151177
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: roger peppe <rogpeppe@gmail.com>
2018-11-25 17:30:36 +00:00
|
|
|
"encoding/base64": {
|
|
|
|
|
"assemble32",
|
|
|
|
|
"assemble64",
|
|
|
|
|
},
|
2017-09-13 21:03:20 +02:00
|
|
|
"unicode/utf8": {
|
|
|
|
|
"FullRune",
|
|
|
|
|
"FullRuneInString",
|
|
|
|
|
"RuneLen",
|
2021-08-11 23:51:09 -07:00
|
|
|
"AppendRune",
|
2017-09-13 21:03:20 +02:00
|
|
|
"ValidRune",
|
|
|
|
|
},
|
2017-09-28 20:44:21 +01:00
|
|
|
"reflect": {
|
|
|
|
|
"Value.CanAddr",
|
|
|
|
|
"Value.CanSet",
|
2019-03-09 17:48:23 +00:00
|
|
|
"Value.CanInterface",
|
2017-09-28 20:44:21 +01:00
|
|
|
"Value.IsValid",
|
2019-03-09 17:48:23 +00:00
|
|
|
"Value.pointer",
|
2017-09-28 20:44:21 +01:00
|
|
|
"add",
|
|
|
|
|
"align",
|
2019-03-09 18:09:10 +00:00
|
|
|
"flag.mustBe",
|
|
|
|
|
"flag.mustBeAssignable",
|
|
|
|
|
"flag.mustBeExported",
|
2017-09-28 20:44:21 +01:00
|
|
|
"flag.kind",
|
|
|
|
|
"flag.ro",
|
|
|
|
|
},
|
2017-09-22 15:15:23 -05:00
|
|
|
"regexp": {
|
|
|
|
|
"(*bitState).push",
|
|
|
|
|
},
|
2018-03-06 09:07:34 +03:00
|
|
|
"math/big": {
|
|
|
|
|
"bigEndianWord",
|
2019-03-04 16:48:28 -08:00
|
|
|
// The following functions require the math_big_pure_go build tag.
|
|
|
|
|
"addVW",
|
|
|
|
|
"subVW",
|
2018-03-06 09:07:34 +03:00
|
|
|
},
|
2019-08-24 08:59:01 +09:00
|
|
|
"math/rand": {
|
|
|
|
|
"(*rngSource).Int63",
|
|
|
|
|
"(*rngSource).Uint64",
|
|
|
|
|
},
|
2021-02-11 10:49:55 -08:00
|
|
|
"net": {
|
|
|
|
|
"(*UDPConn).ReadFromUDP",
|
|
|
|
|
},
|
2017-09-13 15:04:16 +02:00
|
|
|
}
|
|
|
|
|
|
2020-04-14 02:36:36 +10:00
|
|
|
if runtime.GOARCH != "386" && runtime.GOARCH != "mips64" && runtime.GOARCH != "mips64le" && runtime.GOARCH != "riscv64" {
|
2017-09-20 13:09:08 -05:00
|
|
|
// nextFreeFast calls sys.Ctz64, which on 386 is implemented in asm and is not inlinable.
|
|
|
|
|
// We currently don't have midstack inlining so nextFreeFast is also not inlinable on 386.
|
2020-04-14 02:36:36 +10:00
|
|
|
// On mips64x and riscv64, Ctz64 is not intrinsified and causes nextFreeFast too expensive
|
|
|
|
|
// to inline (Issue 22239).
|
2017-09-20 13:09:08 -05:00
|
|
|
want["runtime"] = append(want["runtime"], "nextFreeFast")
|
2017-10-20 10:53:48 -04:00
|
|
|
}
|
|
|
|
|
if runtime.GOARCH != "386" {
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
// As explained above, Ctz64 and Ctz32 are not Go code on 386.
|
|
|
|
|
// The same applies to Bswap32.
|
|
|
|
|
want["runtime/internal/sys"] = append(want["runtime/internal/sys"], "Ctz64")
|
|
|
|
|
want["runtime/internal/sys"] = append(want["runtime/internal/sys"], "Ctz32")
|
|
|
|
|
want["runtime/internal/sys"] = append(want["runtime/internal/sys"], "Bswap32")
|
|
|
|
|
}
|
2019-03-09 17:48:23 +00:00
|
|
|
if bits.UintSize == 64 {
|
2021-04-08 16:08:55 +08:00
|
|
|
// mix is only defined on 64-bit architectures
|
|
|
|
|
want["runtime"] = append(want["runtime"], "mix")
|
2017-09-20 13:09:08 -05:00
|
|
|
}
|
|
|
|
|
|
2019-03-09 17:48:23 +00:00
|
|
|
switch runtime.GOARCH {
|
2020-04-14 02:36:36 +10:00
|
|
|
case "386", "wasm", "arm":
|
2019-03-09 17:48:23 +00:00
|
|
|
default:
|
|
|
|
|
// TODO(mvdan): As explained in /test/inline_sync.go, some
|
|
|
|
|
// architectures don't have atomic intrinsics, so these go over
|
|
|
|
|
// the inlining budget. Move back to the main table once that
|
|
|
|
|
// problem is solved.
|
|
|
|
|
want["sync"] = []string{
|
|
|
|
|
"(*Mutex).Lock",
|
|
|
|
|
"(*Mutex).Unlock",
|
|
|
|
|
"(*RWMutex).RLock",
|
|
|
|
|
"(*RWMutex).RUnlock",
|
|
|
|
|
"(*Once).Do",
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-17 14:08:03 -05:00
|
|
|
// Functions that must actually be inlined; they must have actual callers.
|
|
|
|
|
must := map[string]bool{
|
|
|
|
|
"compress/flate.byLiteral.Len": true,
|
|
|
|
|
"compress/flate.byLiteral.Less": true,
|
|
|
|
|
"compress/flate.byLiteral.Swap": true,
|
|
|
|
|
}
|
|
|
|
|
|
2017-09-14 15:51:18 +01:00
|
|
|
notInlinedReason := make(map[string]string)
|
2017-09-13 21:03:20 +02:00
|
|
|
pkgs := make([]string, 0, len(want))
|
|
|
|
|
for pname, fnames := range want {
|
|
|
|
|
pkgs = append(pkgs, pname)
|
|
|
|
|
for _, fname := range fnames {
|
cmd/compile: add more runtime funcs to inline test
This is based from a list that Keith Randall provided in mid-2016. These
are all funcs that, at the time, were important and small enough that
they should be clearly inlined.
The runtime has changed a bit since then. Ctz16 and Ctz8 were removed,
so don't add them. stringtoslicebytetmp was moved to the backend, so
it's no longer a Go function. And itabhash was moved to itabHashFunc.
The only other outlier is adjustctxt, which is not inlineable at the
moment. I've added a TODO and will address it myself in a separate
commit.
While at it, error if any funcs in the input table are duplicated.
They're never useful and typos could lead to unintentionally thinking a
function is inlineable when it actually isn't.
And, since the lists are getting long, start sorting alphabetically.
Finally, rotl_31 is only defined on 64-bit architectures, and the added
runtime/internal/sys funcs are assembly on 386 and thus non-inlineable
in that case.
Updates #21851.
Change-Id: Ib99ab53d777860270e8fd4aefc41adb448f13662
Reviewed-on: https://go-review.googlesource.com/65351
Run-TryBot: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
2017-09-22 12:21:36 +01:00
|
|
|
fullName := pname + "." + fname
|
|
|
|
|
if _, ok := notInlinedReason[fullName]; ok {
|
|
|
|
|
t.Errorf("duplicate func: %s", fullName)
|
|
|
|
|
}
|
|
|
|
|
notInlinedReason[fullName] = "unknown reason"
|
2017-09-13 21:03:20 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-04 16:48:28 -08:00
|
|
|
args := append([]string{"build", "-a", "-gcflags=all=-m -m", "-tags=math_big_pure_go"}, pkgs...)
|
2017-09-13 21:03:20 +02:00
|
|
|
cmd := testenv.CleanCmdEnv(exec.Command(testenv.GoToolPath(t), args...))
|
2017-09-14 15:51:18 +01:00
|
|
|
pr, pw := io.Pipe()
|
|
|
|
|
cmd.Stdout = pw
|
|
|
|
|
cmd.Stderr = pw
|
|
|
|
|
cmdErr := make(chan error, 1)
|
|
|
|
|
go func() {
|
|
|
|
|
cmdErr <- cmd.Run()
|
|
|
|
|
pw.Close()
|
|
|
|
|
}()
|
|
|
|
|
scanner := bufio.NewScanner(pr)
|
2017-09-13 21:03:20 +02:00
|
|
|
curPkg := ""
|
2017-09-14 15:51:18 +01:00
|
|
|
canInline := regexp.MustCompile(`: can inline ([^ ]*)`)
|
2018-09-17 14:08:03 -05:00
|
|
|
haveInlined := regexp.MustCompile(`: inlining call to ([^ ]*)`)
|
2017-09-14 15:51:18 +01:00
|
|
|
cannotInline := regexp.MustCompile(`: cannot inline ([^ ]*): (.*)`)
|
|
|
|
|
for scanner.Scan() {
|
|
|
|
|
line := scanner.Text()
|
|
|
|
|
if strings.HasPrefix(line, "# ") {
|
|
|
|
|
curPkg = line[2:]
|
|
|
|
|
continue
|
|
|
|
|
}
|
2018-09-17 14:08:03 -05:00
|
|
|
if m := haveInlined.FindStringSubmatch(line); m != nil {
|
2017-09-14 15:51:18 +01:00
|
|
|
fname := m[1]
|
|
|
|
|
delete(notInlinedReason, curPkg+"."+fname)
|
|
|
|
|
continue
|
2017-09-13 21:03:20 +02:00
|
|
|
}
|
2018-09-17 14:08:03 -05:00
|
|
|
if m := canInline.FindStringSubmatch(line); m != nil {
|
|
|
|
|
fname := m[1]
|
|
|
|
|
fullname := curPkg + "." + fname
|
2019-02-22 15:53:52 +00:00
|
|
|
// If function must be inlined somewhere, being inlinable is not enough
|
2018-09-17 14:08:03 -05:00
|
|
|
if _, ok := must[fullname]; !ok {
|
|
|
|
|
delete(notInlinedReason, fullname)
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-14 15:51:18 +01:00
|
|
|
if m := cannotInline.FindStringSubmatch(line); m != nil {
|
|
|
|
|
fname, reason := m[1], m[2]
|
|
|
|
|
fullName := curPkg + "." + fname
|
|
|
|
|
if _, ok := notInlinedReason[fullName]; ok {
|
|
|
|
|
// cmd/compile gave us a reason why
|
|
|
|
|
notInlinedReason[fullName] = reason
|
|
|
|
|
}
|
2017-09-13 15:04:16 +02:00
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-09-14 15:51:18 +01:00
|
|
|
if err := <-cmdErr; err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
if err := scanner.Err(); err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
for fullName, reason := range notInlinedReason {
|
|
|
|
|
t.Errorf("%s was not inlined: %s", fullName, reason)
|
2017-09-13 15:04:16 +02:00
|
|
|
}
|
|
|
|
|
}
|