From dc79206aec20b92388e7050d0359dccccd31ef0b Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Sat, 9 Jun 2018 20:43:54 +0300 Subject: [PATCH 0001/1663] net: combine append calls in reverseaddr MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Combined appends lead to fewer machine code and faster performance. Some may even say that it makes code more readable. Running revAddrTests over reverseaddr gives measurable improvements: name old time/op new time/op delta ReverseAddress-8 4.10µs ± 3% 3.94µs ± 1% -3.81% (p=0.000 n=10+9) Change-Id: I9bda7a20f802bcdffc6e948789765d04c6da04e7 Reviewed-on: https://go-review.googlesource.com/117615 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí Reviewed-by: Brad Fitzpatrick --- src/net/dnsclient.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/net/dnsclient.go b/src/net/dnsclient.go index 2e4bffaab8b85..e3524280b6aaf 100644 --- a/src/net/dnsclient.go +++ b/src/net/dnsclient.go @@ -27,10 +27,10 @@ func reverseaddr(addr string) (arpa string, err error) { // Add it, in reverse, to the buffer for i := len(ip) - 1; i >= 0; i-- { v := ip[i] - buf = append(buf, hexDigit[v&0xF]) - buf = append(buf, '.') - buf = append(buf, hexDigit[v>>4]) - buf = append(buf, '.') + buf = append(buf, hexDigit[v&0xF], + '.', + hexDigit[v>>4], + '.') } // Append "ip6.arpa." and return (buf already has the final .) buf = append(buf, "ip6.arpa."...) From 88aa208024f04845381a86f2d5679d2e520b1ff6 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 25 Jun 2018 09:20:14 +0200 Subject: [PATCH 0002/1663] syscall: use private copy of ustat_t on Linux Port CL 120295 from golang.org/x/sys/unix to the syscall package. The ustat syscall has been deprecated on Linux for a long time and the upcoming glibc 2.28 will remove ustat.h and it can no longer be used to to generate the Ustat_t wrapper type. Since Linux still provides the syscall, let's not break this functionality and add a private copy of struct ustat so Ustat_t can still be generated. Fixes golang/go#25990 Change-Id: I0dab2ba1cc76fbd21553b499f9256fd9d59ca409 Reviewed-on: https://go-review.googlesource.com/120563 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/syscall/types_linux.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/syscall/types_linux.go b/src/syscall/types_linux.go index 3c4c2f2cfd767..ccc5c54f0bfd6 100644 --- a/src/syscall/types_linux.go +++ b/src/syscall/types_linux.go @@ -53,7 +53,6 @@ package syscall #include #include #include -#include #include enum { @@ -124,6 +123,15 @@ struct my_epoll_event { int32_t pad; }; +// ustat is deprecated and glibc 2.28 removed ustat.h. Provide the type here for +// backwards compatibility. Copied from /usr/include/bits/ustat.h +struct ustat { + __daddr_t f_tfree; + __ino_t f_tinode; + char f_fname[6]; + char f_fpack[6]; +}; + */ import "C" From b2e66f1aec4d53df3f21245f68d264744688bb31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 1 Jun 2018 11:23:21 +0100 Subject: [PATCH 0003/1663] cmd/vet: rewrite structtag using go/types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This lets us simplify the code considerably. For example, unquoting the tag is no longer necessary, and we can get the field name with a single method call. While at it, fix a typechecking error in testdata/structtag.go, which hadn't been caught since vet still skips past go/types errors in most cases. Using go/types will also let us expand the structtag check more easily if we want to, for example to allow it to check for duplicates in embedded fields. Finally, update one of the test cases to check for regressions when we output invalid tag strings. We also checked that these two changes to testdata/structtag.go didn't fail with the old structtag check. For #25593. Change-Id: Iea4906d0f30a67f36b28c21d8aa96251aae653f5 Reviewed-on: https://go-review.googlesource.com/115676 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Alan Donovan Reviewed-by: Rob Pike --- src/cmd/vet/structtag.go | 37 ++++++++++++------------------- src/cmd/vet/testdata/structtag.go | 4 ++-- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/src/cmd/vet/structtag.go b/src/cmd/vet/structtag.go index 3bc30c47405d8..a2571419c75ad 100644 --- a/src/cmd/vet/structtag.go +++ b/src/cmd/vet/structtag.go @@ -10,6 +10,7 @@ import ( "errors" "go/ast" "go/token" + "go/types" "reflect" "strconv" "strings" @@ -24,9 +25,12 @@ func init() { // checkStructFieldTags checks all the field tags of a struct, including checking for duplicates. func checkStructFieldTags(f *File, node ast.Node) { + styp := f.pkg.types[node.(*ast.StructType)].Type.(*types.Struct) var seen map[[2]string]token.Pos - for _, field := range node.(*ast.StructType).Fields.List { - checkCanonicalFieldTag(f, field, &seen) + for i := 0; i < styp.NumFields(); i++ { + field := styp.Field(i) + tag := styp.Tag(i) + checkCanonicalFieldTag(f, field, tag, &seen) } } @@ -34,20 +38,13 @@ var checkTagDups = []string{"json", "xml"} var checkTagSpaces = map[string]bool{"json": true, "xml": true, "asn1": true} // checkCanonicalFieldTag checks a single struct field tag. -func checkCanonicalFieldTag(f *File, field *ast.Field, seen *map[[2]string]token.Pos) { - if field.Tag == nil { - return - } - - tag, err := strconv.Unquote(field.Tag.Value) - if err != nil { - f.Badf(field.Pos(), "unable to read struct tag %s", field.Tag.Value) +func checkCanonicalFieldTag(f *File, field *types.Var, tag string, seen *map[[2]string]token.Pos) { + if tag == "" { return } if err := validateStructTag(tag); err != nil { - raw, _ := strconv.Unquote(field.Tag.Value) // field.Tag.Value is known to be a quoted string - f.Badf(field.Pos(), "struct field tag %#q not compatible with reflect.StructTag.Get: %s", raw, err) + f.Badf(field.Pos(), "struct field tag %#q not compatible with reflect.StructTag.Get: %s", tag, err) } for _, key := range checkTagDups { @@ -55,7 +52,7 @@ func checkCanonicalFieldTag(f *File, field *ast.Field, seen *map[[2]string]token if val == "" || val == "-" || val[0] == ',' { continue } - if key == "xml" && len(field.Names) > 0 && field.Names[0].Name == "XMLName" { + if key == "xml" && field.Name() == "XMLName" { // XMLName defines the XML element name of the struct being // checked. That name cannot collide with element or attribute // names defined on other fields of the struct. Vet does not have a @@ -79,13 +76,7 @@ func checkCanonicalFieldTag(f *File, field *ast.Field, seen *map[[2]string]token *seen = map[[2]string]token.Pos{} } if pos, ok := (*seen)[[2]string{key, val}]; ok { - var name string - if len(field.Names) > 0 { - name = field.Names[0].Name - } else { - name = field.Type.(*ast.Ident).Name - } - f.Badf(field.Pos(), "struct field %s repeats %s tag %q also at %s", name, key, val, f.loc(pos)) + f.Badf(field.Pos(), "struct field %s repeats %s tag %q also at %s", field.Name(), key, val, f.loc(pos)) } else { (*seen)[[2]string{key, val}] = field.Pos() } @@ -95,17 +86,17 @@ func checkCanonicalFieldTag(f *File, field *ast.Field, seen *map[[2]string]token // Embedded struct. Nothing to do for now, but that // may change, depending on what happens with issue 7363. - if len(field.Names) == 0 { + if field.Anonymous() { return } - if field.Names[0].IsExported() { + if field.Exported() { return } for _, enc := range [...]string{"json", "xml"} { if reflect.StructTag(tag).Get(enc) != "" { - f.Badf(field.Pos(), "struct field %s has %s tag but is not exported", field.Names[0].Name, enc) + f.Badf(field.Pos(), "struct field %s has %s tag but is not exported", field.Name(), enc) return } } diff --git a/src/cmd/vet/testdata/structtag.go b/src/cmd/vet/testdata/structtag.go index ce21e803c802e..34bf9f6599b41 100644 --- a/src/cmd/vet/testdata/structtag.go +++ b/src/cmd/vet/testdata/structtag.go @@ -9,7 +9,7 @@ package testdata import "encoding/xml" type StructTagTest struct { - A int "hello" // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag pair" + A int "hello" // ERROR "`hello` not compatible with reflect.StructTag.Get: bad syntax for struct tag pair" B int "\tx:\"y\"" // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag key" C int "x:\"y\"\tx:\"y\"" // ERROR "not compatible with reflect.StructTag.Get" D int "x:`y`" // ERROR "not compatible with reflect.StructTag.Get: bad syntax for struct tag value" @@ -66,7 +66,7 @@ type DuplicateJSONFields struct { DuplicateOmitXML int `xml:"a,omitempty"` // ERROR "struct field DuplicateOmitXML repeats xml tag .a. also at structtag.go:60" NonXML int `foo:"a"` DuplicateNonXML int `foo:"a"` - Embedded struct { + Embedded2 struct { DuplicateXML int `xml:"a"` // OK because its not in the same struct type } AnonymousXML `xml:"a"` // ERROR "struct field AnonymousXML repeats xml tag .a. also at structtag.go:60" From 0566ab33834f0bd851ff11ad509d33849c7f2b7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 9 Jul 2018 22:40:51 +0100 Subject: [PATCH 0004/1663] strings: add Builder.Cap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To report the capacity of the underlying buffer. The method mirrors bytes.Buffer.Cap. The method can be useful to know whether or not calling write or grow methods will result in an allocation, or to know how much memory has been allocated so far. Fixes #26269. Change-Id: I391db45ae825011566b594836991e28135369a78 Reviewed-on: https://go-review.googlesource.com/122835 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/strings/builder.go | 5 +++++ src/strings/builder_test.go | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/strings/builder.go b/src/strings/builder.go index ac58f34e1dec2..3f33a87508764 100644 --- a/src/strings/builder.go +++ b/src/strings/builder.go @@ -50,6 +50,11 @@ func (b *Builder) String() string { // Len returns the number of accumulated bytes; b.Len() == len(b.String()). func (b *Builder) Len() int { return len(b.buf) } +// Cap returns the capacity of the builder's underlying byte slice. It is the +// total space allocated for the string being built and includes any bytes +// already written. +func (b *Builder) Cap() int { return cap(b.buf) } + // Reset resets the Builder to be empty. func (b *Builder) Reset() { b.addr = nil diff --git a/src/strings/builder_test.go b/src/strings/builder_test.go index 949f214619d5e..9e597015d88f4 100644 --- a/src/strings/builder_test.go +++ b/src/strings/builder_test.go @@ -20,6 +20,9 @@ func check(t *testing.T, b *Builder, want string) { if n := b.Len(); n != len(got) { t.Errorf("Len: got %d; but len(String()) is %d", n, len(got)) } + if n := b.Cap(); n < len(got) { + t.Errorf("Cap: got %d; but len(String()) is %d", n, len(got)) + } } func TestBuilder(t *testing.T) { @@ -89,6 +92,9 @@ func TestBuilderGrow(t *testing.T) { allocs := testing.AllocsPerRun(100, func() { var b Builder b.Grow(growLen) // should be only alloc, when growLen > 0 + if b.Cap() < growLen { + t.Fatalf("growLen=%d: Cap() is lower than growLen", growLen) + } b.Write(p) if b.String() != string(p) { t.Fatalf("growLen=%d: bad data written after Grow", growLen) @@ -226,6 +232,16 @@ func TestBuilderCopyPanic(t *testing.T) { b.Len() }, }, + { + name: "Cap", + wantPanic: false, + fn: func() { + var a Builder + a.WriteByte('x') + b := a + b.Cap() + }, + }, { name: "Reset", wantPanic: false, From 9e4d87d1158a5847dbb94c0fd3f6ab451460d148 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 29 Jun 2018 21:51:10 +0100 Subject: [PATCH 0005/1663] all: update stale test skips MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issues #10043, #15405, and #22660 appear to have been fixed, and whatever tests I could run locally do succeed, so remove the skips. Issue #7237 was closed in favor of #17906, so update its skip line. Issue #7634 was closed as it had not appeared for over three years. Re-enable it for now. An issue should be open if the test starts being skipped again. Change-Id: I67daade906744ed49223291035baddaad9f56dca Reviewed-on: https://go-review.googlesource.com/121735 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/go/go_test.go | 2 -- src/net/http/serve_test.go | 2 +- src/net/http/transport_test.go | 2 -- src/time/sleep_test.go | 4 ---- 4 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 85cae90f87905..ada1ddde3bbb7 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -4008,8 +4008,6 @@ func TestCgoConsistentResults(t *testing.T) { t.Skip("skipping because cgo not enabled") } switch runtime.GOOS { - case "freebsd": - testenv.SkipFlaky(t, 15405) case "solaris": testenv.SkipFlaky(t, 13247) } diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go index a4385419d04b1..8dae95678da29 100644 --- a/src/net/http/serve_test.go +++ b/src/net/http/serve_test.go @@ -2988,7 +2988,7 @@ func testRequestBodyLimit(t *testing.T, h2 bool) { // side of their TCP connection, the server doesn't send a 400 Bad Request. func TestClientWriteShutdown(t *testing.T) { if runtime.GOOS == "plan9" { - t.Skip("skipping test; see https://golang.org/issue/7237") + t.Skip("skipping test; see https://golang.org/issue/17906") } defer afterTest(t) ts := httptest.NewServer(HandlerFunc(func(w ResponseWriter, r *Request) {})) diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index aa8beb9357c88..73e6e3033177f 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -21,7 +21,6 @@ import ( "errors" "fmt" "internal/nettrace" - "internal/testenv" "io" "io/ioutil" "log" @@ -2726,7 +2725,6 @@ func TestTransportTLSHandshakeTimeout(t *testing.T) { // Trying to repro golang.org/issue/3514 func TestTLSServerClosesConnection(t *testing.T) { defer afterTest(t) - testenv.SkipFlaky(t, 7634) closedc := make(chan bool, 1) ts := httptest.NewTLSServer(HandlerFunc(func(w ResponseWriter, r *Request) { diff --git a/src/time/sleep_test.go b/src/time/sleep_test.go index a31494d47b145..c97e6df3991ab 100644 --- a/src/time/sleep_test.go +++ b/src/time/sleep_test.go @@ -425,10 +425,6 @@ func TestOverflowSleep(t *testing.T) { // Test that a panic while deleting a timer does not leave // the timers mutex held, deadlocking a ticker.Stop in a defer. func TestIssue5745(t *testing.T) { - if runtime.GOOS == "darwin" && runtime.GOARCH == "arm" { - t.Skipf("skipping on %s/%s, see issue 10043", runtime.GOOS, runtime.GOARCH) - } - ticker := NewTicker(Hour) defer func() { // would deadlock here before the fix due to From 3b7b9dce43613d22ac58cc61b19268b32a157df0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 11 Jun 2018 09:11:29 +0100 Subject: [PATCH 0006/1663] cmd/compile/internal/gc: various minor cleanups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two funcs and a field were unused. Remove them. A few statements could be made simpler. importsym's pos parameter was unused, so remove it. Finally, don't use printf-like funcs with constant strings that have no formatting directives. Change-Id: I415452249bf2168aa353ac4f3643dfc03017ee53 Reviewed-on: https://go-review.googlesource.com/117699 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Dave Cheney --- src/cmd/compile/internal/gc/bv.go | 11 ----------- src/cmd/compile/internal/gc/const.go | 2 +- src/cmd/compile/internal/gc/dwinl.go | 2 +- src/cmd/compile/internal/gc/export.go | 6 +++--- src/cmd/compile/internal/gc/iexport.go | 2 +- src/cmd/compile/internal/gc/main.go | 4 ++-- src/cmd/compile/internal/gc/mpint.go | 4 ++-- src/cmd/compile/internal/gc/scope_test.go | 1 - src/cmd/compile/internal/gc/walk.go | 8 -------- 9 files changed, 10 insertions(+), 30 deletions(-) diff --git a/src/cmd/compile/internal/gc/bv.go b/src/cmd/compile/internal/gc/bv.go index e9db35ede2a4e..5ddfd5f2caef2 100644 --- a/src/cmd/compile/internal/gc/bv.go +++ b/src/cmd/compile/internal/gc/bv.go @@ -227,17 +227,6 @@ type bvecSet struct { uniq []bvec // unique bvecs, in insertion order } -func newBvecSet(size int) bvecSet { - // bvecSet is a linear probing hash table. - // The hash table has 4n entries to keep the linear - // scan short. - index := make([]int, size*4) - for i := range index { - index[i] = -1 - } - return bvecSet{index, nil} -} - func (m *bvecSet) grow() { // Allocate new index. n := len(m.index) * 2 diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index 2827543e31ebb..ceb124e31e39c 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -766,7 +766,7 @@ func evconst(n *Node) { v.U.(*Mpint).Neg() case OCOM_ | CTINT_: - var et types.EType = Txxx + et := Txxx if nl.Type != nil { et = nl.Type.Etype } diff --git a/src/cmd/compile/internal/gc/dwinl.go b/src/cmd/compile/internal/gc/dwinl.go index f5142810617dc..d191b7ba6c84c 100644 --- a/src/cmd/compile/internal/gc/dwinl.go +++ b/src/cmd/compile/internal/gc/dwinl.go @@ -142,7 +142,7 @@ func assembleInlines(fnsym *obj.LSym, dwVars []*dwarf.Var) dwarf.InlCalls { // return temps (~r%d) that were created during // lowering, or unnamed params ("_"). v.ChildIndex = int32(synthCount) - synthCount += 1 + synthCount++ } } } diff --git a/src/cmd/compile/internal/gc/export.go b/src/cmd/compile/internal/gc/export.go index becc4e1f3b384..3aa7c390675a2 100644 --- a/src/cmd/compile/internal/gc/export.go +++ b/src/cmd/compile/internal/gc/export.go @@ -88,7 +88,7 @@ func dumpexport(bout *bio.Writer) { } } -func importsym(ipkg *types.Pkg, pos src.XPos, s *types.Sym, op Op) *Node { +func importsym(ipkg *types.Pkg, s *types.Sym, op Op) *Node { n := asNode(s.PkgDef()) if n == nil { // iimport should have created a stub ONONAME @@ -113,7 +113,7 @@ func importsym(ipkg *types.Pkg, pos src.XPos, s *types.Sym, op Op) *Node { // If no such type has been declared yet, a forward declaration is returned. // ipkg is the package being imported func importtype(ipkg *types.Pkg, pos src.XPos, s *types.Sym) *types.Type { - n := importsym(ipkg, pos, s, OTYPE) + n := importsym(ipkg, s, OTYPE) if n.Op != OTYPE { t := types.New(TFORW) t.Sym = s @@ -135,7 +135,7 @@ func importtype(ipkg *types.Pkg, pos src.XPos, s *types.Sym) *types.Type { // importobj declares symbol s as an imported object representable by op. // ipkg is the package being imported func importobj(ipkg *types.Pkg, pos src.XPos, s *types.Sym, op Op, ctxt Class, t *types.Type) *Node { - n := importsym(ipkg, pos, s, op) + n := importsym(ipkg, s, op) if n.Op != ONONAME { if n.Op == op && (n.Class() != ctxt || !eqtype(n.Type, t)) { redeclare(lineno, s, fmt.Sprintf("during import %q", ipkg.Path)) diff --git a/src/cmd/compile/internal/gc/iexport.go b/src/cmd/compile/internal/gc/iexport.go index 3abbd15e162ce..5ce284dc732cc 100644 --- a/src/cmd/compile/internal/gc/iexport.go +++ b/src/cmd/compile/internal/gc/iexport.go @@ -595,7 +595,7 @@ func (p *iexporter) typOff(t *types.Type) uint64 { if !ok { w := p.newWriter() w.doTyp(t) - off = predeclReserved + uint64(w.flush()) + off = predeclReserved + w.flush() p.typIndex[t] = off } return off diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 9f1ea2ab4bf77..da6f800ccd5d9 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -341,7 +341,7 @@ func Main(archInit func(*Arch)) { } // display help about the -d option itself and quit if name == "help" { - fmt.Printf(debugHelpHeader) + fmt.Print(debugHelpHeader) maxLen := len("ssa/help") for _, t := range debugtab { if len(t.name) > maxLen { @@ -353,7 +353,7 @@ func Main(archInit func(*Arch)) { } // ssa options have their own help fmt.Printf("\t%-*s\t%s\n", maxLen, "ssa/help", "print help about SSA debugging") - fmt.Printf(debugHelpFooter) + fmt.Print(debugHelpFooter) os.Exit(0) } val, valstring, haveInt := 1, "", true diff --git a/src/cmd/compile/internal/gc/mpint.go b/src/cmd/compile/internal/gc/mpint.go index e9471b2a21cb9..de47205435459 100644 --- a/src/cmd/compile/internal/gc/mpint.go +++ b/src/cmd/compile/internal/gc/mpint.go @@ -299,8 +299,8 @@ func (a *Mpint) SetString(as string) { } } -func (x *Mpint) String() string { - return bconv(x, 0) +func (a *Mpint) String() string { + return bconv(a, 0) } func bconv(xval *Mpint, flag FmtFlag) string { diff --git a/src/cmd/compile/internal/gc/scope_test.go b/src/cmd/compile/internal/gc/scope_test.go index 944a81e6700ff..e327dc02af2df 100644 --- a/src/cmd/compile/internal/gc/scope_test.go +++ b/src/cmd/compile/internal/gc/scope_test.go @@ -350,7 +350,6 @@ type scopexplainContext struct { dwarfData *dwarf.Data dwarfReader *dwarf.Reader scopegen int - lines map[line][]int } // readScope reads the DW_TAG_lexical_block or the DW_TAG_subprogram in diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index df7428a127fd5..f75e729eb5508 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -2220,14 +2220,6 @@ func callnew(t *types.Type) *Node { return v } -func iscallret(n *Node) bool { - if n == nil { - return false - } - n = outervalue(n) - return n.Op == OINDREGSP -} - // isReflectHeaderDataField reports whether l is an expression p.Data // where p has type reflect.SliceHeader or reflect.StringHeader. func isReflectHeaderDataField(l *Node) bool { From 5403b8ecebc37da227dae170f01b6004a66bf2e6 Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Sat, 28 Jul 2018 00:26:42 +0300 Subject: [PATCH 0007/1663] cmd/compile: remove empty branches Change-Id: Id87d9f55d1714fc553f5b1a9cba0f2fe348dad3e Reviewed-on: https://go-review.googlesource.com/126396 Run-TryBot: Yury Smolsky TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/ssa/debug.go | 5 ----- src/cmd/compile/internal/ssa/redblack32_test.go | 2 -- 2 files changed, 7 deletions(-) diff --git a/src/cmd/compile/internal/ssa/debug.go b/src/cmd/compile/internal/ssa/debug.go index becee358b6d50..c1fbdcc5174e4 100644 --- a/src/cmd/compile/internal/ssa/debug.go +++ b/src/cmd/compile/internal/ssa/debug.go @@ -535,8 +535,6 @@ func (state *debugState) mergePredecessors(b *Block, blockLocs []*BlockDebug) ([ } if len(preds) == 0 { - if state.loggingEnabled { - } state.currentState.reset(nil) return nil, true } @@ -854,7 +852,6 @@ func (state *debugState) buildLocationLists(blockLocs []*BlockDebug) { } state.changedVars.clear() } - } if state.loggingEnabled { @@ -914,8 +911,6 @@ func (state *debugState) updateVar(varID VarID, v *Value, curLoc []VarLoc) { for i, slot := range state.varSlots[varID] { pending.pieces[i] = curLoc[slot] } - return - } // writePendingEntry writes out the pending entry for varID, if any, diff --git a/src/cmd/compile/internal/ssa/redblack32_test.go b/src/cmd/compile/internal/ssa/redblack32_test.go index 6d72a3eee5f80..1ec29760728da 100644 --- a/src/cmd/compile/internal/ssa/redblack32_test.go +++ b/src/cmd/compile/internal/ssa/redblack32_test.go @@ -175,8 +175,6 @@ func allRBT32Ops(te *testing.T, x []int32) { if s != "" { te.Errorf("Tree consistency problem at %v", s) return - } else { - // fmt.Printf("%s", t.DebugString()) } } From bd483592a23c5c8964d1af5ca85792db031229ad Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Tue, 19 Jun 2018 03:44:28 +0000 Subject: [PATCH 0008/1663] cmd/compile/internal/x86: simplify 387 with FLDZ and FLZ1 FLD1 pushes +1.0 to the 387 register stack, and FLDZ pushes +0.0 to the 387 regiser stack. They can be used to simplify MOVSSconst/MOVSDconst when the constant is +0.0, -0.0, +1.0, -1.0. The size of the go executable reduces about 62KB and the total size of pkg/linux_386 reduces about 7KB with this optimization. Change-Id: Icc8213b58262e0024a277cf1103812a17dd4b05e Reviewed-on: https://go-review.googlesource.com/119635 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/x86/387.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/cmd/compile/internal/x86/387.go b/src/cmd/compile/internal/x86/387.go index 7a3622405ce8d..ab3d30e76c1a9 100644 --- a/src/cmd/compile/internal/x86/387.go +++ b/src/cmd/compile/internal/x86/387.go @@ -22,11 +22,24 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { switch v.Op { case ssa.Op386MOVSSconst, ssa.Op386MOVSDconst: - p := s.Prog(loadPush(v.Type)) - p.From.Type = obj.TYPE_FCONST - p.From.Val = math.Float64frombits(uint64(v.AuxInt)) - p.To.Type = obj.TYPE_REG - p.To.Reg = x86.REG_F0 + iv := uint64(v.AuxInt) + if iv == 0x0000000000000000 { // +0.0 + s.Prog(x86.AFLDZ) + } else if iv == 0x3ff0000000000000 { // +1.0 + s.Prog(x86.AFLD1) + } else if iv == 0x8000000000000000 { // -0.0 + s.Prog(x86.AFLDZ) + s.Prog(x86.AFCHS) + } else if iv == 0xbff0000000000000 { // -1.0 + s.Prog(x86.AFLD1) + s.Prog(x86.AFCHS) + } else { // others + p := s.Prog(loadPush(v.Type)) + p.From.Type = obj.TYPE_FCONST + p.From.Val = math.Float64frombits(iv) + p.To.Type = obj.TYPE_REG + p.To.Reg = x86.REG_F0 + } popAndSave(s, v) case ssa.Op386MOVSSconst2, ssa.Op386MOVSDconst2: From 285747b900ac8e1b006d8d88d876e8a08452b7ef Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 16 Aug 2018 03:39:43 +0000 Subject: [PATCH 0009/1663] cmd/compile: optimize ARM's comparision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since MULA&MULS cost more CPU cycles than MUL, so MUL Rx, Ry, Rd CMP Ra, Rd cost less cycles than MULA Rx, Ry, Ra, Rd CMP $0, Rd This CL implement that optimization, and the GobEncode-4 of the go1 benchmark got a little improvement, while other cases got little impact (noise excluded). name old time/op new time/op delta BinaryTree17-4 25.2s ± 1% 25.2s ± 0% ~ (p=0.420 n=30+29) Fannkuch11-4 13.3s ± 0% 13.3s ± 0% +0.03% (p=0.003 n=27+30) FmtFprintfEmpty-4 406ns ± 0% 405ns ± 0% ~ (p=0.309 n=30+30) FmtFprintfString-4 672ns ± 0% 670ns ± 0% -0.32% (p=0.000 n=29+29) FmtFprintfInt-4 717ns ± 0% 714ns ± 0% -0.42% (p=0.000 n=27+22) FmtFprintfIntInt-4 1.07µs ± 0% 1.07µs ± 0% +0.11% (p=0.000 n=19+30) FmtFprintfPrefixedInt-4 1.12µs ± 0% 1.12µs ± 0% -0.43% (p=0.000 n=23+30) FmtFprintfFloat-4 2.25µs ± 0% 2.25µs ± 0% ~ (p=0.509 n=29+29) FmtManyArgs-4 4.01µs ± 1% 4.00µs ± 0% -0.35% (p=0.000 n=30+30) GobDecode-4 53.6ms ± 4% 51.9ms ± 2% -3.17% (p=0.000 n=30+30) GobEncode-4 51.1ms ± 2% 50.6ms ± 2% -0.98% (p=0.000 n=30+30) Gzip-4 2.61s ± 0% 2.61s ± 0% ~ (p=0.504 n=30+30) Gunzip-4 312ms ± 0% 312ms ± 0% ~ (p=0.866 n=30+30) HTTPClientServer-4 977µs ± 7% 974µs ± 8% ~ (p=0.804 n=30+29) JSONEncode-4 127ms ± 1% 125ms ± 2% -1.88% (p=0.000 n=29+29) JSONDecode-4 435ms ± 3% 431ms ± 2% -0.80% (p=0.005 n=30+30) Mandelbrot200-4 18.4ms ± 0% 18.4ms ± 0% -0.02% (p=0.006 n=29+25) GoParse-4 22.4ms ± 0% 22.4ms ± 0% ~ (p=0.105 n=27+29) RegexpMatchEasy0_32-4 753ns ± 0% 753ns ± 0% ~ (all equal) RegexpMatchEasy0_1K-4 4.32µs ± 0% 4.32µs ± 0% ~ (p=0.554 n=29+28) RegexpMatchEasy1_32-4 788ns ± 0% 788ns ± 0% ~ (all equal) RegexpMatchEasy1_1K-4 5.54µs ± 0% 5.55µs ± 0% +0.03% (p=0.013 n=29+30) RegexpMatchMedium_32-4 1.08µs ± 0% 1.08µs ± 0% ~ (p=0.443 n=28+28) RegexpMatchMedium_1K-4 258µs ± 0% 258µs ± 0% ~ (p=0.932 n=30+28) RegexpMatchHard_32-4 14.8µs ± 0% 14.8µs ± 0% -0.06% (p=0.021 n=30+30) RegexpMatchHard_1K-4 442µs ± 0% 442µs ± 0% ~ (p=0.554 n=29+30) Revcomp-4 41.7ms ± 1% 41.7ms ± 1% ~ (p=0.763 n=28+30) Template-4 528ms ± 1% 528ms ± 0% ~ (p=0.072 n=30+29) TimeParse-4 3.31µs ± 0% 3.31µs ± 0% ~ (p=0.215 n=30+30) TimeFormat-4 6.07µs ± 0% 6.07µs ± 0% ~ (p=0.733 n=30+30) [Geo mean] 386µs 385µs -0.29% name old speed new speed delta GobDecode-4 14.3MB/s ± 4% 14.8MB/s ± 2% +3.23% (p=0.000 n=30+30) GobEncode-4 15.0MB/s ± 2% 15.2MB/s ± 2% +0.99% (p=0.000 n=30+30) Gzip-4 7.44MB/s ± 0% 7.44MB/s ± 0% ~ (p=0.328 n=29+30) Gunzip-4 62.2MB/s ± 0% 62.2MB/s ± 0% ~ (p=0.905 n=30+30) JSONEncode-4 15.2MB/s ± 1% 15.5MB/s ± 2% +1.93% (p=0.000 n=29+29) JSONDecode-4 4.46MB/s ± 3% 4.50MB/s ± 2% +0.79% (p=0.007 n=30+30) GoParse-4 2.58MB/s ± 1% 2.58MB/s ± 1% ~ (p=0.223 n=29+30) RegexpMatchEasy0_32-4 42.5MB/s ± 0% 42.5MB/s ± 0% ~ (p=0.964 n=30+30) RegexpMatchEasy0_1K-4 237MB/s ± 0% 237MB/s ± 0% ~ (p=0.392 n=29+28) RegexpMatchEasy1_32-4 40.6MB/s ± 0% 40.6MB/s ± 0% ~ (p=0.974 n=30+29) RegexpMatchEasy1_1K-4 185MB/s ± 0% 185MB/s ± 0% -0.03% (p=0.012 n=29+30) RegexpMatchMedium_32-4 920kB/s ± 0% 920kB/s ± 0% ~ (all equal) RegexpMatchMedium_1K-4 3.97MB/s ± 0% 3.97MB/s ± 0% ~ (all equal) RegexpMatchHard_32-4 2.17MB/s ± 0% 2.17MB/s ± 0% +0.18% (p=0.000 n=30+28) RegexpMatchHard_1K-4 2.32MB/s ± 0% 2.32MB/s ± 0% ~ (all equal) Revcomp-4 61.0MB/s ± 1% 61.0MB/s ± 1% ~ (p=0.744 n=28+30) Template-4 3.68MB/s ± 1% 3.67MB/s ± 0% ~ (p=0.147 n=30+29) [Geo mean] 12.7MB/s 12.7MB/s +0.41% Change-Id: Ic6053c350c94e9bf57db16542e1370b848155342 Reviewed-on: https://go-review.googlesource.com/129535 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/gen/ARM.rules | 4 + src/cmd/compile/internal/ssa/rewriteARM.go | 120 +++++++++++++++++++++ 2 files changed, 124 insertions(+) diff --git a/src/cmd/compile/internal/ssa/gen/ARM.rules b/src/cmd/compile/internal/ssa/gen/ARM.rules index 45e68c6aed958..2846ef6d2e835 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM.rules @@ -1337,6 +1337,7 @@ (CMP x (RSBconst [0] y)) -> (CMN x y) (CMN x (RSBconst [0] y)) -> (CMP x y) (EQ (CMPconst [0] (SUB x y)) yes no) -> (EQ (CMP x y) yes no) +(EQ (CMPconst [0] (MULS x y a)) yes no) -> (EQ (CMP a (MUL x y)) yes no) (EQ (CMPconst [0] (SUBconst [c] x)) yes no) -> (EQ (CMPconst [c] x) yes no) (EQ (CMPconst [0] (SUBshiftLL x y [c])) yes no) -> (EQ (CMPshiftLL x y [c]) yes no) (EQ (CMPconst [0] (SUBshiftRL x y [c])) yes no) -> (EQ (CMPshiftRL x y [c]) yes no) @@ -1345,6 +1346,7 @@ (EQ (CMPconst [0] (SUBshiftRLreg x y z)) yes no) -> (EQ (CMPshiftRLreg x y z) yes no) (EQ (CMPconst [0] (SUBshiftRAreg x y z)) yes no) -> (EQ (CMPshiftRAreg x y z) yes no) (NE (CMPconst [0] (SUB x y)) yes no) -> (NE (CMP x y) yes no) +(NE (CMPconst [0] (MULS x y a)) yes no) -> (NE (CMP a (MUL x y)) yes no) (NE (CMPconst [0] (SUBconst [c] x)) yes no) -> (NE (CMPconst [c] x) yes no) (NE (CMPconst [0] (SUBshiftLL x y [c])) yes no) -> (NE (CMPshiftLL x y [c]) yes no) (NE (CMPconst [0] (SUBshiftRL x y [c])) yes no) -> (NE (CMPshiftRL x y [c]) yes no) @@ -1353,6 +1355,7 @@ (NE (CMPconst [0] (SUBshiftRLreg x y z)) yes no) -> (NE (CMPshiftRLreg x y z) yes no) (NE (CMPconst [0] (SUBshiftRAreg x y z)) yes no) -> (NE (CMPshiftRAreg x y z) yes no) (EQ (CMPconst [0] (ADD x y)) yes no) -> (EQ (CMN x y) yes no) +(EQ (CMPconst [0] (MULA x y a)) yes no) -> (EQ (CMN a (MUL x y)) yes no) (EQ (CMPconst [0] (ADDconst [c] x)) yes no) -> (EQ (CMNconst [c] x) yes no) (EQ (CMPconst [0] (ADDshiftLL x y [c])) yes no) -> (EQ (CMNshiftLL x y [c]) yes no) (EQ (CMPconst [0] (ADDshiftRL x y [c])) yes no) -> (EQ (CMNshiftRL x y [c]) yes no) @@ -1361,6 +1364,7 @@ (EQ (CMPconst [0] (ADDshiftRLreg x y z)) yes no) -> (EQ (CMNshiftRLreg x y z) yes no) (EQ (CMPconst [0] (ADDshiftRAreg x y z)) yes no) -> (EQ (CMNshiftRAreg x y z) yes no) (NE (CMPconst [0] (ADD x y)) yes no) -> (NE (CMN x y) yes no) +(NE (CMPconst [0] (MULA x y a)) yes no) -> (NE (CMN a (MUL x y)) yes no) (NE (CMPconst [0] (ADDconst [c] x)) yes no) -> (NE (CMNconst [c] x) yes no) (NE (CMPconst [0] (ADDshiftLL x y [c])) yes no) -> (NE (CMNshiftLL x y [c]) yes no) (NE (CMPconst [0] (ADDshiftRL x y [c])) yes no) -> (NE (CMNshiftRL x y [c]) yes no) diff --git a/src/cmd/compile/internal/ssa/rewriteARM.go b/src/cmd/compile/internal/ssa/rewriteARM.go index 5e9ce5c96c11b..dc1273327917f 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM.go +++ b/src/cmd/compile/internal/ssa/rewriteARM.go @@ -22226,6 +22226,36 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } + // match: (EQ (CMPconst [0] (MULS x y a)) yes no) + // cond: + // result: (EQ (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULS { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMEQ + v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (EQ (CMPconst [0] (SUBconst [c] x)) yes no) // cond: // result: (EQ (CMPconst [c] x) yes no) @@ -22445,6 +22475,36 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } + // match: (EQ (CMPconst [0] (MULA x y a)) yes no) + // cond: + // result: (EQ (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULA { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMEQ + v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (EQ (CMPconst [0] (ADDconst [c] x)) yes no) // cond: // result: (EQ (CMNconst [c] x) yes no) @@ -23879,6 +23939,36 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } + // match: (NE (CMPconst [0] (MULS x y a)) yes no) + // cond: + // result: (NE (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULS { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMNE + v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (NE (CMPconst [0] (SUBconst [c] x)) yes no) // cond: // result: (NE (CMPconst [c] x) yes no) @@ -24098,6 +24188,36 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } + // match: (NE (CMPconst [0] (MULA x y a)) yes no) + // cond: + // result: (NE (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULA { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMNE + v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (NE (CMPconst [0] (ADDconst [c] x)) yes no) // cond: // result: (NE (CMNconst [c] x) yes no) From 26d62b4ca9bb8f7342d337ba43b0cc1aedaf7852 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Wed, 8 Aug 2018 04:10:19 +0000 Subject: [PATCH 0010/1663] cmd/internal/obj/arm64: add SWPALD/SWPALW/SWPALH/SWPALB Those new instructions have acquire/release semantics, besides normal atomic SWPD/SWPW/SWPH/SWPB. Change-Id: I24821a4d21aebc342897ae52903aef612c8d8a4a Reviewed-on: https://go-review.googlesource.com/128476 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/asm/internal/arch/arm64.go | 1 + src/cmd/asm/internal/asm/testdata/arm64.s | 8 ++++++++ src/cmd/internal/obj/arm64/a.out.go | 4 ++++ src/cmd/internal/obj/arm64/anames.go | 4 ++++ src/cmd/internal/obj/arm64/asm7.go | 16 ++++++++++------ 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/cmd/asm/internal/arch/arm64.go b/src/cmd/asm/internal/arch/arm64.go index 475d7da5f9363..7cbc139bced42 100644 --- a/src/cmd/asm/internal/arch/arm64.go +++ b/src/cmd/asm/internal/arch/arm64.go @@ -74,6 +74,7 @@ func IsARM64STLXR(op obj.As) bool { arm64.ASTXRB, arm64.ASTXRH, arm64.ASTXRW, arm64.ASTXR, arm64.ASTXP, arm64.ASTXPW, arm64.ASTLXP, arm64.ASTLXPW, arm64.ASWPB, arm64.ASWPH, arm64.ASWPW, arm64.ASWPD, + arm64.ASWPALB, arm64.ASWPALH, arm64.ASWPALW, arm64.ASWPALD, arm64.ALDADDB, arm64.ALDADDH, arm64.ALDADDW, arm64.ALDADDD, arm64.ALDANDB, arm64.ALDANDH, arm64.ALDANDW, arm64.ALDANDD, arm64.ALDEORB, arm64.ALDEORH, arm64.ALDEORW, arm64.ALDEORD, diff --git a/src/cmd/asm/internal/asm/testdata/arm64.s b/src/cmd/asm/internal/asm/testdata/arm64.s index 3a4410f10b4ad..3a1b2f79beb81 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64.s +++ b/src/cmd/asm/internal/asm/testdata/arm64.s @@ -572,6 +572,14 @@ again: SWPH R5, (RSP), R7 // e7832578 SWPB R5, (R6), R7 // c7802538 SWPB R5, (RSP), R7 // e7832538 + SWPALD R5, (R6), R7 // c780e5f8 + SWPALD R5, (RSP), R7 // e783e5f8 + SWPALW R5, (R6), R7 // c780e5b8 + SWPALW R5, (RSP), R7 // e783e5b8 + SWPALH R5, (R6), R7 // c780e578 + SWPALH R5, (RSP), R7 // e783e578 + SWPALB R5, (R6), R7 // c780e538 + SWPALB R5, (RSP), R7 // e783e538 LDADDD R5, (R6), R7 // c70025f8 LDADDD R5, (RSP), R7 // e70325f8 LDADDW R5, (R6), R7 // c70025b8 diff --git a/src/cmd/internal/obj/arm64/a.out.go b/src/cmd/internal/obj/arm64/a.out.go index 9be0183edf880..2575940f19767 100644 --- a/src/cmd/internal/obj/arm64/a.out.go +++ b/src/cmd/internal/obj/arm64/a.out.go @@ -774,9 +774,13 @@ const ( AMOVPSW AMOVPW ASWPD + ASWPALD ASWPW + ASWPALW ASWPH + ASWPALH ASWPB + ASWPALB ABEQ ABNE ABCS diff --git a/src/cmd/internal/obj/arm64/anames.go b/src/cmd/internal/obj/arm64/anames.go index 84fb40b10260c..f4b3c288975cb 100644 --- a/src/cmd/internal/obj/arm64/anames.go +++ b/src/cmd/internal/obj/arm64/anames.go @@ -275,9 +275,13 @@ var Anames = []string{ "MOVPSW", "MOVPW", "SWPD", + "SWPALD", "SWPW", + "SWPALW", "SWPH", + "SWPALH", "SWPB", + "SWPALB", "BEQ", "BNE", "BCS", diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index e3bcce826594c..f7a3babd198d6 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -2008,9 +2008,13 @@ func buildop(ctxt *obj.Link) { oprangeset(AMOVZW, t) case ASWPD: + oprangeset(ASWPALD, t) oprangeset(ASWPB, t) oprangeset(ASWPH, t) oprangeset(ASWPW, t) + oprangeset(ASWPALB, t) + oprangeset(ASWPALH, t) + oprangeset(ASWPALW, t) oprangeset(ALDADDALD, t) oprangeset(ALDADDALW, t) oprangeset(ALDADDB, t) @@ -3383,19 +3387,19 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { rt := p.RegTo2 rb := p.To.Reg switch p.As { - case ASWPD, ALDADDALD, ALDADDD, ALDANDD, ALDEORD, ALDORD: // 64-bit + case ASWPD, ASWPALD, ALDADDALD, ALDADDD, ALDANDD, ALDEORD, ALDORD: // 64-bit o1 = 3 << 30 - case ASWPW, ALDADDALW, ALDADDW, ALDANDW, ALDEORW, ALDORW: // 32-bit + case ASWPW, ASWPALW, ALDADDALW, ALDADDW, ALDANDW, ALDEORW, ALDORW: // 32-bit o1 = 2 << 30 - case ASWPH, ALDADDH, ALDANDH, ALDEORH, ALDORH: // 16-bit + case ASWPH, ASWPALH, ALDADDH, ALDANDH, ALDEORH, ALDORH: // 16-bit o1 = 1 << 30 - case ASWPB, ALDADDB, ALDANDB, ALDEORB, ALDORB: // 8-bit + case ASWPB, ASWPALB, ALDADDB, ALDANDB, ALDEORB, ALDORB: // 8-bit o1 = 0 << 30 default: c.ctxt.Diag("illegal instruction: %v\n", p) } switch p.As { - case ASWPD, ASWPW, ASWPH, ASWPB: + case ASWPD, ASWPW, ASWPH, ASWPB, ASWPALD, ASWPALW, ASWPALH, ASWPALB: o1 |= 0x20 << 10 case ALDADDALD, ALDADDALW, ALDADDD, ALDADDW, ALDADDH, ALDADDB: o1 |= 0x00 << 10 @@ -3407,7 +3411,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { o1 |= 0x0c << 10 } switch p.As { - case ALDADDALD, ALDADDALW: + case ALDADDALD, ALDADDALW, ASWPALD, ASWPALW, ASWPALH, ASWPALB: o1 |= 3 << 22 } o1 |= 0x1c1<<21 | uint32(rs&31)<<16 | uint32(rb&31)<<5 | uint32(rt&31) From c3533d7a26d659c5ae3af27320a462c602bd25ee Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Sat, 28 Jul 2018 01:22:24 +0300 Subject: [PATCH 0011/1663] cmd/cover: remove unused global var and the unquote function Change-Id: I52a39f2d8f1a296f23624e3ec577d9ad1b8302f1 Reviewed-on: https://go-review.googlesource.com/126555 Run-TryBot: Yury Smolsky TryBot-Result: Gobot Gobot Reviewed-by: Alan Donovan --- src/cmd/cover/cover.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/src/cmd/cover/cover.go b/src/cmd/cover/cover.go index f496f4cff612c..54cf4be25ec7f 100644 --- a/src/cmd/cover/cover.go +++ b/src/cmd/cover/cover.go @@ -16,7 +16,6 @@ import ( "log" "os" "sort" - "strconv" "cmd/internal/edit" "cmd/internal/objabi" @@ -294,17 +293,6 @@ func (f *File) Visit(node ast.Node) ast.Visitor { return f } -// unquote returns the unquoted string. -func unquote(s string) string { - t, err := strconv.Unquote(s) - if err != nil { - log.Fatalf("cover: improperly quoted string %q\n", s) - } - return t -} - -var slashslash = []byte("//") - func annotate(name string) { fset := token.NewFileSet() content, err := ioutil.ReadFile(name) From b40db514382b2efc19c793810185d3d7ceea8b25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Fri, 11 May 2018 08:01:31 +0200 Subject: [PATCH 0012/1663] cmd/compile: split slow 3 operand LEA instructions into two LEAs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit go tool objdump ../bin/go | grep "\.go\:" | grep -c "LEA.*0x.*[(].*[(].*" Before: 1012 After: 20 Updates #21735 Benchmarks thanks to drchase@google.com Intel(R) Xeon(R) CPU E5-1650 v3 @ 3.50GHz benchstat -geomean *.stdout | grep -v pkg: name old time/op new time/op delta FastTest2KB-12 131.0ns ± 0% 131.0ns ± 0% ~ (all equal) BaseTest2KB-12 601.3ns ± 0% 601.3ns ± 0% ~ (p=0.942 n=45+41) Encoding4KBVerySparse-12 15.38µs ± 1% 15.41µs ± 0% +0.24% (p=0.000 n=44+43) Join_8-12 2.117s ± 2% 2.128s ± 2% +0.51% (p=0.007 n=48+48) HashimotoLight-12 1.663ms ± 1% 1.668ms ± 1% +0.35% (p=0.006 n=49+49) Sha3_224_MTU-12 4.843µs ± 0% 4.836µs ± 0% -0.14% (p=0.000 n=45+42) GenSharedKeyP256-12 73.74µs ± 0% 70.92µs ± 0% -3.82% (p=0.000 n=48+47) Run/10k/1-12 24.81s ± 0% 24.88s ± 0% +0.30% (p=0.000 n=48+47) Run/10k/16-12 4.621s ± 2% 4.625s ± 3% ~ (p=0.776 n=50+50) Dnrm2MediumPosInc-12 4.018µs ± 0% 4.019µs ± 0% ~ (p=0.060 n=50+48) DasumMediumUnitaryInc-12 855.3ns ± 0% 855.0ns ± 0% -0.03% (p=0.000 n=47+42) Dgeev/Circulant10-12 40.45µs ± 1% 41.11µs ± 1% +1.62% (p=0.000 n=45+49) Dgeev/Circulant100-12 10.42ms ± 2% 10.61ms ± 1% +1.83% (p=0.000 n=49+48) MulWorkspaceDense1000Hundredth-12 64.69ms ± 1% 64.63ms ± 1% ~ (p=0.718 n=48+48) ScaleVec10000Inc20-12 22.31µs ± 1% 22.29µs ± 1% ~ (p=0.424 n=50+50) ValidateVersionTildeFail-12 737.6ns ± 1% 736.0ns ± 1% -0.22% (p=0.000 n=49+49) StripHTML-12 2.846µs ± 0% 2.806µs ± 1% -1.40% (p=0.000 n=43+50) ReaderContains-12 6.073µs ± 0% 5.999µs ± 0% -1.22% (p=0.000 n=48+48) EncodeCodecFromInternalProtobuf-12 5.817µs ± 2% 5.555µs ± 2% -4.51% (p=0.000 n=47+47) TarjanSCCGnp_10_tenth-12 7.091µs ± 5% 7.132µs ± 7% ~ (p=0.361 n=50+50) TarjanSCCGnp_1000_half-12 82.25ms ± 3% 81.29ms ± 2% -1.16% (p=0.000 n=50+43) AStarUndirectedmallWorld_10_2_2_2_Heur-12 15.18µs ± 8% 15.11µs ± 7% ~ (p=0.511 n=50+49) LouvainDirectedMultiplex-12 20.92ms ± 1% 21.00ms ± 1% +0.36% (p=0.000 n=48+49) WalkAllBreadthFirstGnp_10_tenth-12 2.974µs ± 4% 2.964µs ± 5% ~ (p=0.504 n=50+50) WalkAllBreadthFirstGnp_1000_tenth-12 9.733ms ± 4% 9.741ms ± 4% ~ (p=0.774 n=48+50) TextMovementBetweenSegments-12 432.8µs ± 0% 433.2µs ± 1% ~ (p=0.128 n=50+50) Growth_MultiSegment-12 13.11ms ± 0% 13.19ms ± 1% +0.58% (p=0.000 n=44+46) AddingFields/Zap.Sugar-12 1.296µs ± 1% 1.310µs ± 2% +1.09% (p=0.000 n=43+43) AddingFields/apex/log-12 34.19µs ± 1% 34.31µs ± 1% +0.35% (p=0.000 n=45+45) AddingFields/inconshreveable/log15-12 30.08µs ± 2% 30.07µs ± 2% ~ (p=0.803 n=48+47) AddingFields/sirupsen/logrus-12 6.683µs ± 3% 6.735µs ± 3% +0.78% (p=0.000 n=43+42) [Geo mean] 143.5µs 143.3µs -0.16% Change-Id: I637203c75c837737f1febced75d5985703e51044 Reviewed-on: https://go-review.googlesource.com/114655 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: David Chase Reviewed-by: Ilya Tocar --- src/cmd/compile/internal/amd64/ssa.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/amd64/ssa.go b/src/cmd/compile/internal/amd64/ssa.go index 307cdc5e83e28..de38772cd2844 100644 --- a/src/cmd/compile/internal/amd64/ssa.go +++ b/src/cmd/compile/internal/amd64/ssa.go @@ -524,6 +524,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { case ssa.OpAMD64LEAQ1, ssa.OpAMD64LEAQ2, ssa.OpAMD64LEAQ4, ssa.OpAMD64LEAQ8, ssa.OpAMD64LEAL1, ssa.OpAMD64LEAL2, ssa.OpAMD64LEAL4, ssa.OpAMD64LEAL8, ssa.OpAMD64LEAW1, ssa.OpAMD64LEAW2, ssa.OpAMD64LEAW4, ssa.OpAMD64LEAW8: + o := v.Reg() r := v.Args[0].Reg() i := v.Args[1].Reg() p := s.Prog(v.Op.Asm()) @@ -543,9 +544,24 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.From.Type = obj.TYPE_MEM p.From.Reg = r p.From.Index = i - gc.AddAux(&p.From, v) p.To.Type = obj.TYPE_REG - p.To.Reg = v.Reg() + p.To.Reg = o + if v.AuxInt != 0 && v.Aux == nil { + // Emit an additional LEA to add the displacement instead of creating a slow 3 operand LEA. + switch v.Op { + case ssa.OpAMD64LEAQ1, ssa.OpAMD64LEAQ2, ssa.OpAMD64LEAQ4, ssa.OpAMD64LEAQ8: + p = s.Prog(x86.ALEAQ) + case ssa.OpAMD64LEAL1, ssa.OpAMD64LEAL2, ssa.OpAMD64LEAL4, ssa.OpAMD64LEAL8: + p = s.Prog(x86.ALEAL) + case ssa.OpAMD64LEAW1, ssa.OpAMD64LEAW2, ssa.OpAMD64LEAW4, ssa.OpAMD64LEAW8: + p = s.Prog(x86.ALEAW) + } + p.From.Type = obj.TYPE_MEM + p.From.Reg = o + p.To.Type = obj.TYPE_REG + p.To.Reg = o + } + gc.AddAux(&p.From, v) case ssa.OpAMD64LEAQ, ssa.OpAMD64LEAL, ssa.OpAMD64LEAW: p := s.Prog(v.Op.Asm()) p.From.Type = obj.TYPE_MEM From b75c5c5992686a7eac1a33383e8b9b14b579556e Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Wed, 27 Jun 2018 02:46:17 +0000 Subject: [PATCH 0013/1663] cmd/compile: optimize AMD64 with more read-modify-write operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6 more operations which do read-modify-write with a constant source operand are added. 1. The total size of pkg/linux_amd64 decreases about 3KB, excluding cmd/compile. 2. The go1 benckmark shows a slight improvement. name old time/op new time/op delta BinaryTree17-4 2.61s ± 4% 2.67s ± 2% +2.26% (p=0.000 n=30+29) Fannkuch11-4 2.39s ± 2% 2.32s ± 2% -2.67% (p=0.000 n=30+30) FmtFprintfEmpty-4 44.0ns ± 4% 41.7ns ± 4% -5.15% (p=0.000 n=30+30) FmtFprintfString-4 74.2ns ± 4% 72.3ns ± 4% -2.59% (p=0.000 n=30+30) FmtFprintfInt-4 81.7ns ± 3% 78.8ns ± 4% -3.54% (p=0.000 n=27+30) FmtFprintfIntInt-4 130ns ± 4% 124ns ± 5% -4.60% (p=0.000 n=30+30) FmtFprintfPrefixedInt-4 154ns ± 3% 152ns ± 3% -1.13% (p=0.012 n=30+30) FmtFprintfFloat-4 215ns ± 4% 212ns ± 5% -1.56% (p=0.002 n=30+30) FmtManyArgs-4 522ns ± 3% 512ns ± 3% -1.84% (p=0.001 n=30+30) GobDecode-4 6.42ms ± 5% 6.49ms ± 7% ~ (p=0.070 n=30+30) GobEncode-4 6.07ms ± 8% 5.98ms ± 8% ~ (p=0.150 n=30+30) Gzip-4 236ms ± 4% 223ms ± 4% -5.57% (p=0.000 n=30+30) Gunzip-4 37.4ms ± 3% 36.7ms ± 4% -2.03% (p=0.000 n=30+30) HTTPClientServer-4 58.7µs ± 1% 58.5µs ± 2% -0.37% (p=0.018 n=30+29) JSONEncode-4 12.0ms ± 4% 12.1ms ± 3% ~ (p=0.112 n=30+30) JSONDecode-4 54.5ms ± 3% 55.5ms ± 4% +1.80% (p=0.006 n=30+30) Mandelbrot200-4 3.78ms ± 4% 3.78ms ± 4% ~ (p=0.173 n=30+30) GoParse-4 3.16ms ± 5% 3.22ms ± 5% +1.75% (p=0.010 n=30+30) RegexpMatchEasy0_32-4 76.6ns ± 1% 75.9ns ± 3% ~ (p=0.672 n=25+30) RegexpMatchEasy0_1K-4 252ns ± 3% 253ns ± 3% +0.57% (p=0.027 n=30+30) RegexpMatchEasy1_32-4 69.8ns ± 4% 70.2ns ± 6% ~ (p=0.539 n=30+30) RegexpMatchEasy1_1K-4 374ns ± 3% 373ns ± 5% ~ (p=0.263 n=30+30) RegexpMatchMedium_32-4 107ns ± 4% 109ns ± 3% ~ (p=0.067 n=30+30) RegexpMatchMedium_1K-4 33.9µs ± 5% 34.1µs ± 4% ~ (p=0.297 n=30+30) RegexpMatchHard_32-4 1.54µs ± 3% 1.56µs ± 4% +1.43% (p=0.002 n=30+30) RegexpMatchHard_1K-4 46.6µs ± 3% 47.0µs ± 3% ~ (p=0.055 n=30+30) Revcomp-4 411ms ± 6% 407ms ± 6% ~ (p=0.219 n=30+30) Template-4 66.8ms ± 3% 64.8ms ± 5% -3.01% (p=0.000 n=30+30) TimeParse-4 312ns ± 2% 319ns ± 3% +2.50% (p=0.000 n=30+30) TimeFormat-4 296ns ± 5% 299ns ± 3% +0.93% (p=0.005 n=30+30) [Geo mean] 47.5µs 47.1µs -0.75% name old speed new speed delta GobDecode-4 120MB/s ± 5% 118MB/s ± 6% ~ (p=0.072 n=30+30) GobEncode-4 127MB/s ± 8% 129MB/s ± 8% ~ (p=0.150 n=30+30) Gzip-4 82.1MB/s ± 4% 87.0MB/s ± 4% +5.90% (p=0.000 n=30+30) Gunzip-4 519MB/s ± 4% 529MB/s ± 4% +2.07% (p=0.001 n=30+30) JSONEncode-4 162MB/s ± 4% 161MB/s ± 3% ~ (p=0.110 n=30+30) JSONDecode-4 35.6MB/s ± 3% 35.0MB/s ± 4% -1.77% (p=0.007 n=30+30) GoParse-4 18.3MB/s ± 4% 18.0MB/s ± 4% -1.72% (p=0.009 n=30+30) RegexpMatchEasy0_32-4 418MB/s ± 1% 422MB/s ± 3% ~ (p=0.645 n=25+30) RegexpMatchEasy0_1K-4 4.06GB/s ± 3% 4.04GB/s ± 3% -0.57% (p=0.033 n=30+30) RegexpMatchEasy1_32-4 459MB/s ± 4% 456MB/s ± 6% ~ (p=0.530 n=30+30) RegexpMatchEasy1_1K-4 2.73GB/s ± 3% 2.75GB/s ± 5% ~ (p=0.279 n=30+30) RegexpMatchMedium_32-4 9.28MB/s ± 5% 9.18MB/s ± 4% ~ (p=0.086 n=30+30) RegexpMatchMedium_1K-4 30.2MB/s ± 4% 30.0MB/s ± 4% ~ (p=0.300 n=30+30) RegexpMatchHard_32-4 20.8MB/s ± 3% 20.5MB/s ± 4% -1.41% (p=0.002 n=30+30) RegexpMatchHard_1K-4 22.0MB/s ± 3% 21.8MB/s ± 3% ~ (p=0.051 n=30+30) Revcomp-4 619MB/s ± 7% 625MB/s ± 7% ~ (p=0.219 n=30+30) Template-4 29.0MB/s ± 3% 29.9MB/s ± 4% +3.11% (p=0.000 n=30+30) [Geo mean] 123MB/s 123MB/s +0.28% Change-Id: I850652cfd53329c1af804b7f57f4393d8097bb0d Reviewed-on: https://go-review.googlesource.com/121135 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Ilya Tocar --- src/cmd/compile/internal/amd64/ssa.go | 11 + src/cmd/compile/internal/ssa/gen/AMD64.rules | 21 +- src/cmd/compile/internal/ssa/gen/AMD64Ops.go | 34 +- src/cmd/compile/internal/ssa/opGen.go | 90 +++ src/cmd/compile/internal/ssa/rewriteAMD64.go | 563 ++++++++++++++++++- test/codegen/bits.go | 10 + 6 files changed, 706 insertions(+), 23 deletions(-) diff --git a/src/cmd/compile/internal/amd64/ssa.go b/src/cmd/compile/internal/amd64/ssa.go index de38772cd2844..584cc4c4bd552 100644 --- a/src/cmd/compile/internal/amd64/ssa.go +++ b/src/cmd/compile/internal/amd64/ssa.go @@ -770,6 +770,17 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.To.Reg = v.Args[0].Reg() gc.AddAux2(&p.To, v, off) } + case ssa.OpAMD64ANDQconstmodify, ssa.OpAMD64ANDLconstmodify, ssa.OpAMD64ORQconstmodify, ssa.OpAMD64ORLconstmodify, + ssa.OpAMD64XORQconstmodify, ssa.OpAMD64XORLconstmodify: + sc := v.AuxValAndOff() + off := sc.Off() + val := sc.Val() + p := s.Prog(v.Op.Asm()) + p.From.Type = obj.TYPE_CONST + p.From.Offset = val + p.To.Type = obj.TYPE_MEM + p.To.Reg = v.Args[0].Reg() + gc.AddAux2(&p.To, v, off) case ssa.OpAMD64MOVQstoreconst, ssa.OpAMD64MOVLstoreconst, ssa.OpAMD64MOVWstoreconst, ssa.OpAMD64MOVBstoreconst: p := s.Prog(v.Op.Asm()) p.From.Type = obj.TYPE_CONST diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index 54de6e055debd..db6bbfb0606d9 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -1039,8 +1039,10 @@ ((ADD|SUB|MUL)SSload [off1+off2] {sym} val base mem) ((ADD|SUB|MUL)SDload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> ((ADD|SUB|MUL)SDload [off1+off2] {sym} val base mem) -(ADD(L|Q)constmodify [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> - (ADD(L|Q)constmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) +((ADD|AND|OR|XOR)Qconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> + ((ADD|AND|OR|XOR)Qconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) +((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> + ((ADD|AND|OR|XOR)Lconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) // Fold constants into stores. (MOVQstore [off] {sym} ptr (MOVQconst [c]) mem) && validValAndOff(c,off) -> @@ -1081,9 +1083,12 @@ ((ADD|SUB|MUL)SDload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> ((ADD|SUB|MUL)SDload [off1+off2] {mergeSym(sym1,sym2)} val base mem) -(ADD(L|Q)constmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) +((ADD|AND|OR|XOR)Qconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) && ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) -> - (ADD(L|Q)constmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + ((ADD|AND|OR|XOR)Qconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) +((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + && ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) -> + ((ADD|AND|OR|XOR)Lconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) // generating indexed loads and stores (MOV(B|W|L|Q|SS|SD)load [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> @@ -2352,12 +2357,12 @@ (MOVWQZX (MOVBQZX x)) -> (MOVBQZX x) (MOVBQZX (MOVBQZX x)) -> (MOVBQZX x) -(MOVQstore [off] {sym} ptr a:(ADDQconst [c] l:(MOVQload [off] {sym} ptr2 mem)) mem) +(MOVQstore [off] {sym} ptr a:((ADD|AND|OR|XOR)Qconst [c] l:(MOVQload [off] {sym} ptr2 mem)) mem) && isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) -> - (ADDQconstmodify {sym} [makeValAndOff(c,off)] ptr mem) -(MOVLstore [off] {sym} ptr a:(ADDLconst [c] l:(MOVLload [off] {sym} ptr2 mem)) mem) + ((ADD|AND|OR|XOR)Qconstmodify {sym} [makeValAndOff(c,off)] ptr mem) +(MOVLstore [off] {sym} ptr a:((ADD|AND|OR|XOR)Lconst [c] l:(MOVLload [off] {sym} ptr2 mem)) mem) && isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) -> - (ADDLconstmodify {sym} [makeValAndOff(c,off)] ptr mem) + ((ADD|AND|OR|XOR)Lconstmodify {sym} [makeValAndOff(c,off)] ptr mem) // float <-> int register moves, with no conversion. // These come up when compiling math.{Float{32,64}bits,Float{32,64}frombits}. diff --git a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go index 5a8634abd181f..1140958670d01 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go @@ -225,20 +225,26 @@ func init() { {name: "MULQU2", argLength: 2, reg: regInfo{inputs: []regMask{ax, gpsp}, outputs: []regMask{dx, ax}}, commutative: true, asm: "MULQ", clobberFlags: true}, // arg0 * arg1, returns (hi, lo) {name: "DIVQU2", argLength: 3, reg: regInfo{inputs: []regMask{dx, ax, gpsp}, outputs: []regMask{ax, dx}}, asm: "DIVQ", clobberFlags: true}, // arg0:arg1 / arg2 (128-bit divided by 64-bit), returns (q, r) - {name: "ANDQ", argLength: 2, reg: gp21, asm: "ANDQ", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 & arg1 - {name: "ANDL", argLength: 2, reg: gp21, asm: "ANDL", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 & arg1 - {name: "ANDQconst", argLength: 1, reg: gp11, asm: "ANDQ", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 & auxint - {name: "ANDLconst", argLength: 1, reg: gp11, asm: "ANDL", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 & auxint - - {name: "ORQ", argLength: 2, reg: gp21, asm: "ORQ", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 | arg1 - {name: "ORL", argLength: 2, reg: gp21, asm: "ORL", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 | arg1 - {name: "ORQconst", argLength: 1, reg: gp11, asm: "ORQ", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 | auxint - {name: "ORLconst", argLength: 1, reg: gp11, asm: "ORL", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 | auxint - - {name: "XORQ", argLength: 2, reg: gp21, asm: "XORQ", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 ^ arg1 - {name: "XORL", argLength: 2, reg: gp21, asm: "XORL", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 ^ arg1 - {name: "XORQconst", argLength: 1, reg: gp11, asm: "XORQ", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 ^ auxint - {name: "XORLconst", argLength: 1, reg: gp11, asm: "XORL", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 ^ auxint + {name: "ANDQ", argLength: 2, reg: gp21, asm: "ANDQ", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 & arg1 + {name: "ANDL", argLength: 2, reg: gp21, asm: "ANDL", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 & arg1 + {name: "ANDQconst", argLength: 1, reg: gp11, asm: "ANDQ", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 & auxint + {name: "ANDLconst", argLength: 1, reg: gp11, asm: "ANDL", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 & auxint + {name: "ANDQconstmodify", argLength: 2, reg: gpstoreconst, asm: "ANDQ", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // and ValAndOff(AuxInt).Val() to arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "ANDLconstmodify", argLength: 2, reg: gpstoreconst, asm: "ANDL", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // and ValAndOff(AuxInt).Val() to arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + + {name: "ORQ", argLength: 2, reg: gp21, asm: "ORQ", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 | arg1 + {name: "ORL", argLength: 2, reg: gp21, asm: "ORL", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 | arg1 + {name: "ORQconst", argLength: 1, reg: gp11, asm: "ORQ", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 | auxint + {name: "ORLconst", argLength: 1, reg: gp11, asm: "ORL", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 | auxint + {name: "ORQconstmodify", argLength: 2, reg: gpstoreconst, asm: "ORQ", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // or ValAndOff(AuxInt).Val() to arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "ORLconstmodify", argLength: 2, reg: gpstoreconst, asm: "ORL", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // or ValAndOff(AuxInt).Val() to arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + + {name: "XORQ", argLength: 2, reg: gp21, asm: "XORQ", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 ^ arg1 + {name: "XORL", argLength: 2, reg: gp21, asm: "XORL", commutative: true, resultInArg0: true, clobberFlags: true}, // arg0 ^ arg1 + {name: "XORQconst", argLength: 1, reg: gp11, asm: "XORQ", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 ^ auxint + {name: "XORLconst", argLength: 1, reg: gp11, asm: "XORL", aux: "Int32", resultInArg0: true, clobberFlags: true}, // arg0 ^ auxint + {name: "XORQconstmodify", argLength: 2, reg: gpstoreconst, asm: "XORQ", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // xor ValAndOff(AuxInt).Val() to arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "XORLconstmodify", argLength: 2, reg: gpstoreconst, asm: "XORL", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // xor ValAndOff(AuxInt).Val() to arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem {name: "CMPQ", argLength: 2, reg: gp2flags, asm: "CMPQ", typ: "Flags"}, // arg0 compare to arg1 {name: "CMPL", argLength: 2, reg: gp2flags, asm: "CMPL", typ: "Flags"}, // arg0 compare to arg1 diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index b479bca7ff470..6a14ee080178b 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -487,14 +487,20 @@ const ( OpAMD64ANDL OpAMD64ANDQconst OpAMD64ANDLconst + OpAMD64ANDQconstmodify + OpAMD64ANDLconstmodify OpAMD64ORQ OpAMD64ORL OpAMD64ORQconst OpAMD64ORLconst + OpAMD64ORQconstmodify + OpAMD64ORLconstmodify OpAMD64XORQ OpAMD64XORL OpAMD64XORQconst OpAMD64XORLconst + OpAMD64XORQconstmodify + OpAMD64XORLconstmodify OpAMD64CMPQ OpAMD64CMPL OpAMD64CMPW @@ -5948,6 +5954,34 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "ANDQconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AANDQ, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "ANDLconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AANDL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, { name: "ORQ", argLen: 2, @@ -6014,6 +6048,34 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "ORQconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AORQ, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "ORLconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AORL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, { name: "XORQ", argLen: 2, @@ -6080,6 +6142,34 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "XORQconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AXORQ, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "XORLconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AXORL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, { name: "CMPQ", argLen: 2, diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 47d3f431ab22e..950b926cc1420 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -43,12 +43,16 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64ANDL_0(v) case OpAMD64ANDLconst: return rewriteValueAMD64_OpAMD64ANDLconst_0(v) + case OpAMD64ANDLconstmodify: + return rewriteValueAMD64_OpAMD64ANDLconstmodify_0(v) case OpAMD64ANDLload: return rewriteValueAMD64_OpAMD64ANDLload_0(v) case OpAMD64ANDQ: return rewriteValueAMD64_OpAMD64ANDQ_0(v) case OpAMD64ANDQconst: return rewriteValueAMD64_OpAMD64ANDQconst_0(v) + case OpAMD64ANDQconstmodify: + return rewriteValueAMD64_OpAMD64ANDQconstmodify_0(v) case OpAMD64ANDQload: return rewriteValueAMD64_OpAMD64ANDQload_0(v) case OpAMD64BSFQ: @@ -242,7 +246,7 @@ func rewriteValueAMD64(v *Value) bool { case OpAMD64MOVQloadidx8: return rewriteValueAMD64_OpAMD64MOVQloadidx8_0(v) case OpAMD64MOVQstore: - return rewriteValueAMD64_OpAMD64MOVQstore_0(v) + return rewriteValueAMD64_OpAMD64MOVQstore_0(v) || rewriteValueAMD64_OpAMD64MOVQstore_10(v) case OpAMD64MOVQstoreconst: return rewriteValueAMD64_OpAMD64MOVQstoreconst_0(v) case OpAMD64MOVQstoreconstidx1: @@ -329,12 +333,16 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64ORL_0(v) || rewriteValueAMD64_OpAMD64ORL_10(v) || rewriteValueAMD64_OpAMD64ORL_20(v) || rewriteValueAMD64_OpAMD64ORL_30(v) || rewriteValueAMD64_OpAMD64ORL_40(v) || rewriteValueAMD64_OpAMD64ORL_50(v) || rewriteValueAMD64_OpAMD64ORL_60(v) || rewriteValueAMD64_OpAMD64ORL_70(v) || rewriteValueAMD64_OpAMD64ORL_80(v) || rewriteValueAMD64_OpAMD64ORL_90(v) || rewriteValueAMD64_OpAMD64ORL_100(v) || rewriteValueAMD64_OpAMD64ORL_110(v) || rewriteValueAMD64_OpAMD64ORL_120(v) || rewriteValueAMD64_OpAMD64ORL_130(v) case OpAMD64ORLconst: return rewriteValueAMD64_OpAMD64ORLconst_0(v) + case OpAMD64ORLconstmodify: + return rewriteValueAMD64_OpAMD64ORLconstmodify_0(v) case OpAMD64ORLload: return rewriteValueAMD64_OpAMD64ORLload_0(v) case OpAMD64ORQ: return rewriteValueAMD64_OpAMD64ORQ_0(v) || rewriteValueAMD64_OpAMD64ORQ_10(v) || rewriteValueAMD64_OpAMD64ORQ_20(v) || rewriteValueAMD64_OpAMD64ORQ_30(v) || rewriteValueAMD64_OpAMD64ORQ_40(v) || rewriteValueAMD64_OpAMD64ORQ_50(v) || rewriteValueAMD64_OpAMD64ORQ_60(v) || rewriteValueAMD64_OpAMD64ORQ_70(v) || rewriteValueAMD64_OpAMD64ORQ_80(v) || rewriteValueAMD64_OpAMD64ORQ_90(v) || rewriteValueAMD64_OpAMD64ORQ_100(v) || rewriteValueAMD64_OpAMD64ORQ_110(v) || rewriteValueAMD64_OpAMD64ORQ_120(v) || rewriteValueAMD64_OpAMD64ORQ_130(v) || rewriteValueAMD64_OpAMD64ORQ_140(v) || rewriteValueAMD64_OpAMD64ORQ_150(v) || rewriteValueAMD64_OpAMD64ORQ_160(v) case OpAMD64ORQconst: return rewriteValueAMD64_OpAMD64ORQconst_0(v) + case OpAMD64ORQconstmodify: + return rewriteValueAMD64_OpAMD64ORQconstmodify_0(v) case OpAMD64ORQload: return rewriteValueAMD64_OpAMD64ORQload_0(v) case OpAMD64ROLB: @@ -493,12 +501,16 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64XORL_0(v) || rewriteValueAMD64_OpAMD64XORL_10(v) case OpAMD64XORLconst: return rewriteValueAMD64_OpAMD64XORLconst_0(v) || rewriteValueAMD64_OpAMD64XORLconst_10(v) + case OpAMD64XORLconstmodify: + return rewriteValueAMD64_OpAMD64XORLconstmodify_0(v) case OpAMD64XORLload: return rewriteValueAMD64_OpAMD64XORLload_0(v) case OpAMD64XORQ: return rewriteValueAMD64_OpAMD64XORQ_0(v) || rewriteValueAMD64_OpAMD64XORQ_10(v) case OpAMD64XORQconst: return rewriteValueAMD64_OpAMD64XORQconst_0(v) + case OpAMD64XORQconstmodify: + return rewriteValueAMD64_OpAMD64XORQconstmodify_0(v) case OpAMD64XORQload: return rewriteValueAMD64_OpAMD64XORQload_0(v) case OpAdd16: @@ -3480,6 +3492,58 @@ func rewriteValueAMD64_OpAMD64ANDLconst_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64ANDLconstmodify_0(v *Value) bool { + // match: (ANDLconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (ANDLconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) + for { + valoff1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2)) { + break + } + v.reset(OpAMD64ANDLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (ANDLconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) + // result: (ANDLconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + for { + valoff1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64ANDLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64ANDLload_0(v *Value) bool { b := v.Block _ = b @@ -3893,6 +3957,58 @@ func rewriteValueAMD64_OpAMD64ANDQconst_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64ANDQconstmodify_0(v *Value) bool { + // match: (ANDQconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (ANDQconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) + for { + valoff1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2)) { + break + } + v.reset(OpAMD64ANDQconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (ANDQconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) + // result: (ANDQconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + for { + valoff1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64ANDQconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64ANDQload_0(v *Value) bool { b := v.Block _ = b @@ -14306,6 +14422,123 @@ func rewriteValueAMD64_OpAMD64MOVLstore_10(v *Value) bool { v.AddArg(mem) return true } + // match: (MOVLstore [off] {sym} ptr a:(ANDLconst [c] l:(MOVLload [off] {sym} ptr2 mem)) mem) + // cond: isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) + // result: (ANDLconstmodify {sym} [makeValAndOff(c,off)] ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + a := v.Args[1] + if a.Op != OpAMD64ANDLconst { + break + } + c := a.AuxInt + l := a.Args[0] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + ptr2 := l.Args[0] + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c, off)) { + break + } + v.reset(OpAMD64ANDLconstmodify) + v.AuxInt = makeValAndOff(c, off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVLstore [off] {sym} ptr a:(ORLconst [c] l:(MOVLload [off] {sym} ptr2 mem)) mem) + // cond: isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) + // result: (ORLconstmodify {sym} [makeValAndOff(c,off)] ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + a := v.Args[1] + if a.Op != OpAMD64ORLconst { + break + } + c := a.AuxInt + l := a.Args[0] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + ptr2 := l.Args[0] + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c, off)) { + break + } + v.reset(OpAMD64ORLconstmodify) + v.AuxInt = makeValAndOff(c, off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVLstore [off] {sym} ptr a:(XORLconst [c] l:(MOVLload [off] {sym} ptr2 mem)) mem) + // cond: isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) + // result: (XORLconstmodify {sym} [makeValAndOff(c,off)] ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + a := v.Args[1] + if a.Op != OpAMD64XORLconst { + break + } + c := a.AuxInt + l := a.Args[0] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + ptr2 := l.Args[0] + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c, off)) { + break + } + v.reset(OpAMD64XORLconstmodify) + v.AuxInt = makeValAndOff(c, off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } // match: (MOVLstore [off] {sym} ptr (MOVLf2i val) mem) // cond: // result: (MOVSSstore [off] {sym} ptr val mem) @@ -16292,6 +16525,126 @@ func rewriteValueAMD64_OpAMD64MOVQstore_0(v *Value) bool { v.AddArg(mem) return true } + // match: (MOVQstore [off] {sym} ptr a:(ANDQconst [c] l:(MOVQload [off] {sym} ptr2 mem)) mem) + // cond: isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) + // result: (ANDQconstmodify {sym} [makeValAndOff(c,off)] ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + a := v.Args[1] + if a.Op != OpAMD64ANDQconst { + break + } + c := a.AuxInt + l := a.Args[0] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + ptr2 := l.Args[0] + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c, off)) { + break + } + v.reset(OpAMD64ANDQconstmodify) + v.AuxInt = makeValAndOff(c, off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueAMD64_OpAMD64MOVQstore_10(v *Value) bool { + // match: (MOVQstore [off] {sym} ptr a:(ORQconst [c] l:(MOVQload [off] {sym} ptr2 mem)) mem) + // cond: isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) + // result: (ORQconstmodify {sym} [makeValAndOff(c,off)] ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + a := v.Args[1] + if a.Op != OpAMD64ORQconst { + break + } + c := a.AuxInt + l := a.Args[0] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + ptr2 := l.Args[0] + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c, off)) { + break + } + v.reset(OpAMD64ORQconstmodify) + v.AuxInt = makeValAndOff(c, off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVQstore [off] {sym} ptr a:(XORQconst [c] l:(MOVQload [off] {sym} ptr2 mem)) mem) + // cond: isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) + // result: (XORQconstmodify {sym} [makeValAndOff(c,off)] ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + a := v.Args[1] + if a.Op != OpAMD64XORQconst { + break + } + c := a.AuxInt + l := a.Args[0] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + ptr2 := l.Args[0] + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c, off)) { + break + } + v.reset(OpAMD64XORQconstmodify) + v.AuxInt = makeValAndOff(c, off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } // match: (MOVQstore [off] {sym} ptr (MOVQf2i val) mem) // cond: // result: (MOVSDstore [off] {sym} ptr val mem) @@ -30779,6 +31132,58 @@ func rewriteValueAMD64_OpAMD64ORLconst_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64ORLconstmodify_0(v *Value) bool { + // match: (ORLconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (ORLconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) + for { + valoff1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2)) { + break + } + v.reset(OpAMD64ORLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (ORLconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) + // result: (ORLconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + for { + valoff1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64ORLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64ORLload_0(v *Value) bool { b := v.Block _ = b @@ -41688,6 +42093,58 @@ func rewriteValueAMD64_OpAMD64ORQconst_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64ORQconstmodify_0(v *Value) bool { + // match: (ORQconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (ORQconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) + for { + valoff1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2)) { + break + } + v.reset(OpAMD64ORQconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (ORQconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) + // result: (ORQconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + for { + valoff1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64ORQconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64ORQload_0(v *Value) bool { b := v.Block _ = b @@ -52184,6 +52641,58 @@ func rewriteValueAMD64_OpAMD64XORLconst_10(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64XORLconstmodify_0(v *Value) bool { + // match: (XORLconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (XORLconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) + for { + valoff1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2)) { + break + } + v.reset(OpAMD64XORLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (XORLconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) + // result: (XORLconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + for { + valoff1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64XORLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64XORLload_0(v *Value) bool { b := v.Block _ = b @@ -52598,6 +53107,58 @@ func rewriteValueAMD64_OpAMD64XORQconst_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64XORQconstmodify_0(v *Value) bool { + // match: (XORQconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (XORQconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) + for { + valoff1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2)) { + break + } + v.reset(OpAMD64XORQconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (XORQconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) + // result: (XORQconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + for { + valoff1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64XORQconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64XORQload_0(v *Value) bool { b := v.Block _ = b diff --git a/test/codegen/bits.go b/test/codegen/bits.go index 9de2201cb1b2a..2d1645b5e32f3 100644 --- a/test/codegen/bits.go +++ b/test/codegen/bits.go @@ -262,6 +262,16 @@ func bitcompl32(a, b uint32) (n uint32) { return n } +// check direct operation on memory with constant source +func bitOpOnMem(a []uint32) { + // amd64:`ANDL\s[$]200,\s\([A-Z]+\)` + a[0] &= 200 + // amd64:`ORL\s[$]220,\s4\([A-Z]+\)` + a[1] |= 220 + // amd64:`XORL\s[$]240,\s8\([A-Z]+\)` + a[2] ^= 240 +} + // Check AND masking on arm64 (Issue #19857) func and_mask_1(a uint64) uint64 { From 556971316f363233755283518dfda4b1cf5980d8 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Sun, 29 Jul 2018 12:50:50 +0000 Subject: [PATCH 0014/1663] cmd/compile: optimize 386's comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CMPL/CMPW/CMPB can take a memory operand on 386, and this CL implements that optimization. 1. The total size of pkg/linux_386 decreases about 45KB, excluding cmd/compile. 2. The go1 benchmark shows a little improvement. name old time/op new time/op delta BinaryTree17-4 3.36s ± 2% 3.37s ± 3% ~ (p=0.537 n=40+40) Fannkuch11-4 3.59s ± 1% 3.53s ± 2% -1.58% (p=0.000 n=40+40) FmtFprintfEmpty-4 46.0ns ± 3% 45.8ns ± 3% ~ (p=0.249 n=40+40) FmtFprintfString-4 80.0ns ± 4% 78.8ns ± 3% -1.49% (p=0.001 n=40+40) FmtFprintfInt-4 89.7ns ± 2% 90.3ns ± 2% +0.74% (p=0.003 n=40+40) FmtFprintfIntInt-4 144ns ± 3% 143ns ± 3% -0.95% (p=0.003 n=40+40) FmtFprintfPrefixedInt-4 181ns ± 4% 180ns ± 2% ~ (p=0.103 n=40+40) FmtFprintfFloat-4 412ns ± 3% 408ns ± 4% -0.97% (p=0.018 n=40+40) FmtManyArgs-4 607ns ± 4% 605ns ± 4% ~ (p=0.148 n=40+40) GobDecode-4 7.19ms ± 4% 7.24ms ± 5% ~ (p=0.340 n=40+40) GobEncode-4 7.04ms ± 9% 6.99ms ± 9% ~ (p=0.289 n=40+40) Gzip-4 400ms ± 6% 398ms ± 5% ~ (p=0.168 n=40+40) Gunzip-4 41.2ms ± 3% 41.7ms ± 3% +1.40% (p=0.001 n=40+40) HTTPClientServer-4 62.5µs ± 1% 62.1µs ± 2% -0.61% (p=0.000 n=37+37) JSONEncode-4 20.7ms ± 4% 20.4ms ± 3% -1.60% (p=0.000 n=40+40) JSONDecode-4 69.4ms ± 4% 69.2ms ± 6% ~ (p=0.177 n=40+40) Mandelbrot200-4 5.22ms ± 6% 5.21ms ± 3% ~ (p=0.531 n=40+40) GoParse-4 3.29ms ± 3% 3.28ms ± 3% ~ (p=0.321 n=40+39) RegexpMatchEasy0_32-4 104ns ± 4% 103ns ± 7% -0.89% (p=0.040 n=40+40) RegexpMatchEasy0_1K-4 852ns ± 3% 853ns ± 2% ~ (p=0.357 n=40+40) RegexpMatchEasy1_32-4 113ns ± 8% 113ns ± 3% ~ (p=0.906 n=40+40) RegexpMatchEasy1_1K-4 1.03µs ± 4% 1.03µs ± 5% ~ (p=0.326 n=40+40) RegexpMatchMedium_32-4 136ns ± 3% 133ns ± 3% -2.31% (p=0.000 n=40+40) RegexpMatchMedium_1K-4 44.0µs ± 3% 43.7µs ± 3% ~ (p=0.053 n=40+40) RegexpMatchHard_32-4 2.27µs ± 3% 2.26µs ± 4% ~ (p=0.391 n=40+40) RegexpMatchHard_1K-4 68.0µs ± 3% 68.9µs ± 3% +1.28% (p=0.000 n=40+40) Revcomp-4 1.86s ± 5% 1.86s ± 2% ~ (p=0.950 n=40+40) Template-4 73.4ms ± 4% 69.9ms ± 7% -4.78% (p=0.000 n=40+40) TimeParse-4 449ns ± 4% 441ns ± 5% -1.76% (p=0.000 n=40+40) TimeFormat-4 416ns ± 3% 417ns ± 4% ~ (p=0.304 n=40+40) [Geo mean] 67.7µs 67.3µs -0.55% name old speed new speed delta GobDecode-4 107MB/s ± 4% 106MB/s ± 5% ~ (p=0.336 n=40+40) GobEncode-4 109MB/s ± 5% 110MB/s ± 9% ~ (p=0.142 n=38+40) Gzip-4 48.5MB/s ± 5% 48.8MB/s ± 5% ~ (p=0.172 n=40+40) Gunzip-4 472MB/s ± 3% 465MB/s ± 3% -1.39% (p=0.001 n=40+40) JSONEncode-4 93.6MB/s ± 4% 95.1MB/s ± 3% +1.61% (p=0.000 n=40+40) JSONDecode-4 28.0MB/s ± 3% 28.1MB/s ± 6% ~ (p=0.181 n=40+40) GoParse-4 17.6MB/s ± 3% 17.7MB/s ± 3% ~ (p=0.350 n=40+39) RegexpMatchEasy0_32-4 308MB/s ± 4% 311MB/s ± 6% +0.96% (p=0.025 n=40+40) RegexpMatchEasy0_1K-4 1.20GB/s ± 3% 1.20GB/s ± 2% ~ (p=0.317 n=40+40) RegexpMatchEasy1_32-4 282MB/s ± 7% 282MB/s ± 3% ~ (p=0.516 n=40+40) RegexpMatchEasy1_1K-4 994MB/s ± 4% 991MB/s ± 5% ~ (p=0.319 n=40+40) RegexpMatchMedium_32-4 7.31MB/s ± 3% 7.49MB/s ± 3% +2.46% (p=0.000 n=40+40) RegexpMatchMedium_1K-4 23.3MB/s ± 3% 23.4MB/s ± 3% ~ (p=0.052 n=40+40) RegexpMatchHard_32-4 14.1MB/s ± 3% 14.1MB/s ± 4% ~ (p=0.391 n=40+40) RegexpMatchHard_1K-4 15.1MB/s ± 3% 14.9MB/s ± 3% -1.27% (p=0.000 n=40+40) Revcomp-4 137MB/s ± 5% 137MB/s ± 2% ~ (p=0.942 n=40+40) Template-4 26.5MB/s ± 4% 27.8MB/s ± 7% +5.03% (p=0.000 n=40+40) [Geo mean] 78.6MB/s 79.0MB/s +0.57% Change-Id: Idcacc6881ef57cd7dc33aa87b711282842b72a53 Reviewed-on: https://go-review.googlesource.com/126618 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/flagalloc.go | 68 ++-- src/cmd/compile/internal/ssa/gen/386.rules | 13 + src/cmd/compile/internal/ssa/gen/386Ops.go | 18 +- src/cmd/compile/internal/ssa/opGen.go | 87 ++++++ src/cmd/compile/internal/ssa/rewrite386.go | 341 ++++++++++++++++++++- src/cmd/compile/internal/x86/ssa.go | 15 + test/codegen/comparisons.go | 10 + 7 files changed, 526 insertions(+), 26 deletions(-) diff --git a/src/cmd/compile/internal/ssa/flagalloc.go b/src/cmd/compile/internal/ssa/flagalloc.go index 050595ff8df31..56c12e320adfa 100644 --- a/src/cmd/compile/internal/ssa/flagalloc.go +++ b/src/cmd/compile/internal/ssa/flagalloc.go @@ -4,6 +4,30 @@ package ssa +// When breaking up a combined load-compare to separated load and compare operations, +// opLoad specifies the load operation, and opCmp specifies the compare operation. +type typeCmdLoadMap struct { + opLoad Op + opCmp Op +} + +var opCmpLoadMap = map[Op]typeCmdLoadMap{ + OpAMD64CMPQload: {OpAMD64MOVQload, OpAMD64CMPQ}, + OpAMD64CMPLload: {OpAMD64MOVLload, OpAMD64CMPL}, + OpAMD64CMPWload: {OpAMD64MOVWload, OpAMD64CMPW}, + OpAMD64CMPBload: {OpAMD64MOVBload, OpAMD64CMPB}, + Op386CMPLload: {Op386MOVLload, Op386CMPL}, + Op386CMPWload: {Op386MOVWload, Op386CMPW}, + Op386CMPBload: {Op386MOVBload, Op386CMPB}, + OpAMD64CMPQconstload: {OpAMD64MOVQload, OpAMD64CMPQconst}, + OpAMD64CMPLconstload: {OpAMD64MOVLload, OpAMD64CMPLconst}, + OpAMD64CMPWconstload: {OpAMD64MOVWload, OpAMD64CMPWconst}, + OpAMD64CMPBconstload: {OpAMD64MOVBload, OpAMD64CMPBconst}, + Op386CMPLconstload: {Op386MOVLload, Op386CMPLconst}, + Op386CMPWconstload: {Op386MOVWload, Op386CMPWconst}, + Op386CMPBconstload: {Op386MOVBload, Op386CMPBconst}, +} + // flagalloc allocates the flag register among all the flag-generating // instructions. Flag values are recomputed if they need to be // spilled/restored. @@ -122,55 +146,55 @@ func flagalloc(f *Func) { if spill[v.ID] && v.MemoryArg() != nil { switch v.Op { case OpAMD64CMPQload: - load := b.NewValue2IA(v.Pos, OpAMD64MOVQload, f.Config.Types.UInt64, v.AuxInt, v.Aux, v.Args[0], v.Args[2]) - v.Op = OpAMD64CMPQ + load := b.NewValue2IA(v.Pos, opCmpLoadMap[v.Op].opLoad, f.Config.Types.UInt64, v.AuxInt, v.Aux, v.Args[0], v.Args[2]) + v.Op = opCmpLoadMap[v.Op].opCmp v.AuxInt = 0 v.Aux = nil v.SetArgs2(load, v.Args[1]) - case OpAMD64CMPLload: - load := b.NewValue2IA(v.Pos, OpAMD64MOVLload, f.Config.Types.UInt32, v.AuxInt, v.Aux, v.Args[0], v.Args[2]) - v.Op = OpAMD64CMPL + case OpAMD64CMPLload, Op386CMPLload: + load := b.NewValue2IA(v.Pos, opCmpLoadMap[v.Op].opLoad, f.Config.Types.UInt32, v.AuxInt, v.Aux, v.Args[0], v.Args[2]) + v.Op = opCmpLoadMap[v.Op].opCmp v.AuxInt = 0 v.Aux = nil v.SetArgs2(load, v.Args[1]) - case OpAMD64CMPWload: - load := b.NewValue2IA(v.Pos, OpAMD64MOVWload, f.Config.Types.UInt16, v.AuxInt, v.Aux, v.Args[0], v.Args[2]) - v.Op = OpAMD64CMPW + case OpAMD64CMPWload, Op386CMPWload: + load := b.NewValue2IA(v.Pos, opCmpLoadMap[v.Op].opLoad, f.Config.Types.UInt16, v.AuxInt, v.Aux, v.Args[0], v.Args[2]) + v.Op = opCmpLoadMap[v.Op].opCmp v.AuxInt = 0 v.Aux = nil v.SetArgs2(load, v.Args[1]) - case OpAMD64CMPBload: - load := b.NewValue2IA(v.Pos, OpAMD64MOVBload, f.Config.Types.UInt8, v.AuxInt, v.Aux, v.Args[0], v.Args[2]) - v.Op = OpAMD64CMPB + case OpAMD64CMPBload, Op386CMPBload: + load := b.NewValue2IA(v.Pos, opCmpLoadMap[v.Op].opLoad, f.Config.Types.UInt8, v.AuxInt, v.Aux, v.Args[0], v.Args[2]) + v.Op = opCmpLoadMap[v.Op].opCmp v.AuxInt = 0 v.Aux = nil v.SetArgs2(load, v.Args[1]) case OpAMD64CMPQconstload: vo := v.AuxValAndOff() - load := b.NewValue2IA(v.Pos, OpAMD64MOVQload, f.Config.Types.UInt64, vo.Off(), v.Aux, v.Args[0], v.Args[1]) - v.Op = OpAMD64CMPQconst + load := b.NewValue2IA(v.Pos, opCmpLoadMap[v.Op].opLoad, f.Config.Types.UInt64, vo.Off(), v.Aux, v.Args[0], v.Args[1]) + v.Op = opCmpLoadMap[v.Op].opCmp v.AuxInt = vo.Val() v.Aux = nil v.SetArgs1(load) - case OpAMD64CMPLconstload: + case OpAMD64CMPLconstload, Op386CMPLconstload: vo := v.AuxValAndOff() - load := b.NewValue2IA(v.Pos, OpAMD64MOVLload, f.Config.Types.UInt32, vo.Off(), v.Aux, v.Args[0], v.Args[1]) - v.Op = OpAMD64CMPLconst + load := b.NewValue2IA(v.Pos, opCmpLoadMap[v.Op].opLoad, f.Config.Types.UInt32, vo.Off(), v.Aux, v.Args[0], v.Args[1]) + v.Op = opCmpLoadMap[v.Op].opCmp v.AuxInt = vo.Val() v.Aux = nil v.SetArgs1(load) - case OpAMD64CMPWconstload: + case OpAMD64CMPWconstload, Op386CMPWconstload: vo := v.AuxValAndOff() - load := b.NewValue2IA(v.Pos, OpAMD64MOVWload, f.Config.Types.UInt16, vo.Off(), v.Aux, v.Args[0], v.Args[1]) - v.Op = OpAMD64CMPWconst + load := b.NewValue2IA(v.Pos, opCmpLoadMap[v.Op].opLoad, f.Config.Types.UInt16, vo.Off(), v.Aux, v.Args[0], v.Args[1]) + v.Op = opCmpLoadMap[v.Op].opCmp v.AuxInt = vo.Val() v.Aux = nil v.SetArgs1(load) - case OpAMD64CMPBconstload: + case OpAMD64CMPBconstload, Op386CMPBconstload: vo := v.AuxValAndOff() - load := b.NewValue2IA(v.Pos, OpAMD64MOVBload, f.Config.Types.UInt8, vo.Off(), v.Aux, v.Args[0], v.Args[1]) - v.Op = OpAMD64CMPBconst + load := b.NewValue2IA(v.Pos, opCmpLoadMap[v.Op].opLoad, f.Config.Types.UInt8, vo.Off(), v.Aux, v.Args[0], v.Args[1]) + v.Op = opCmpLoadMap[v.Op].opCmp v.AuxInt = vo.Val() v.Aux = nil v.SetArgs1(load) diff --git a/src/cmd/compile/internal/ssa/gen/386.rules b/src/cmd/compile/internal/ssa/gen/386.rules index 65ac53268976a..94f24a81ef507 100644 --- a/src/cmd/compile/internal/ssa/gen/386.rules +++ b/src/cmd/compile/internal/ssa/gen/386.rules @@ -1262,3 +1262,16 @@ // a register to use for holding the address of the constant pool entry. (MOVSSconst [c]) && config.ctxt.Flag_shared -> (MOVSSconst2 (MOVSSconst1 [c])) (MOVSDconst [c]) && config.ctxt.Flag_shared -> (MOVSDconst2 (MOVSDconst1 [c])) + +(CMP(L|W|B) l:(MOV(L|W|B)load {sym} [off] ptr mem) x) && canMergeLoad(v, l, x) && clobber(l) -> (CMP(L|W|B)load {sym} [off] ptr x mem) +(CMP(L|W|B) x l:(MOV(L|W|B)load {sym} [off] ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> (InvertFlags (CMP(L|W|B)load {sym} [off] ptr x mem)) + +(CMP(L|W|B)const l:(MOV(L|W|B)load {sym} [off] ptr mem) [c]) + && l.Uses == 1 + && validValAndOff(c, off) + && clobber(l) -> + @l.Block (CMP(L|W|B)constload {sym} [makeValAndOff(c,off)] ptr mem) + +(CMPLload {sym} [off] ptr (MOVLconst [c]) mem) && validValAndOff(int64(int32(c)),off) -> (CMPLconstload {sym} [makeValAndOff(int64(int32(c)),off)] ptr mem) +(CMPWload {sym} [off] ptr (MOVLconst [c]) mem) && validValAndOff(int64(int16(c)),off) -> (CMPWconstload {sym} [makeValAndOff(int64(int16(c)),off)] ptr mem) +(CMPBload {sym} [off] ptr (MOVLconst [c]) mem) && validValAndOff(int64(int8(c)),off) -> (CMPBconstload {sym} [makeValAndOff(int64(int8(c)),off)] ptr mem) diff --git a/src/cmd/compile/internal/ssa/gen/386Ops.go b/src/cmd/compile/internal/ssa/gen/386Ops.go index 0a77776b52e77..7a274269d26aa 100644 --- a/src/cmd/compile/internal/ssa/gen/386Ops.go +++ b/src/cmd/compile/internal/ssa/gen/386Ops.go @@ -117,9 +117,11 @@ func init() { gp11mod = regInfo{inputs: []regMask{ax, gpsp &^ dx}, outputs: []regMask{dx}, clobbers: ax} gp21mul = regInfo{inputs: []regMask{ax, gpsp}, outputs: []regMask{dx, ax}} - gp2flags = regInfo{inputs: []regMask{gpsp, gpsp}} - gp1flags = regInfo{inputs: []regMask{gpsp}} - flagsgp = regInfo{inputs: nil, outputs: gponly} + gp2flags = regInfo{inputs: []regMask{gpsp, gpsp}} + gp1flags = regInfo{inputs: []regMask{gpsp}} + gp0flagsLoad = regInfo{inputs: []regMask{gpspsb, 0}} + gp1flagsLoad = regInfo{inputs: []regMask{gpspsb, gpsp, 0}} + flagsgp = regInfo{inputs: nil, outputs: gponly} readflags = regInfo{inputs: nil, outputs: gponly} flagsgpax = regInfo{inputs: nil, clobbers: ax, outputs: []regMask{gp &^ ax}} @@ -235,6 +237,16 @@ func init() { {name: "CMPWconst", argLength: 1, reg: gp1flags, asm: "CMPW", typ: "Flags", aux: "Int16"}, // arg0 compare to auxint {name: "CMPBconst", argLength: 1, reg: gp1flags, asm: "CMPB", typ: "Flags", aux: "Int8"}, // arg0 compare to auxint + // compare *(arg0+auxint+aux) to arg1 (in that order). arg2=mem. + {name: "CMPLload", argLength: 3, reg: gp1flagsLoad, asm: "CMPL", aux: "SymOff", typ: "Flags", symEffect: "Read", faultOnNilArg0: true}, + {name: "CMPWload", argLength: 3, reg: gp1flagsLoad, asm: "CMPW", aux: "SymOff", typ: "Flags", symEffect: "Read", faultOnNilArg0: true}, + {name: "CMPBload", argLength: 3, reg: gp1flagsLoad, asm: "CMPB", aux: "SymOff", typ: "Flags", symEffect: "Read", faultOnNilArg0: true}, + + // compare *(arg0+ValAndOff(AuxInt).Off()+aux) to ValAndOff(AuxInt).Val() (in that order). arg1=mem. + {name: "CMPLconstload", argLength: 2, reg: gp0flagsLoad, asm: "CMPL", aux: "SymValAndOff", typ: "Flags", symEffect: "Read", faultOnNilArg0: true}, + {name: "CMPWconstload", argLength: 2, reg: gp0flagsLoad, asm: "CMPW", aux: "SymValAndOff", typ: "Flags", symEffect: "Read", faultOnNilArg0: true}, + {name: "CMPBconstload", argLength: 2, reg: gp0flagsLoad, asm: "CMPB", aux: "SymValAndOff", typ: "Flags", symEffect: "Read", faultOnNilArg0: true}, + {name: "UCOMISS", argLength: 2, reg: fp2flags, asm: "UCOMISS", typ: "Flags", usesScratch: true}, // arg0 compare to arg1, f32 {name: "UCOMISD", argLength: 2, reg: fp2flags, asm: "UCOMISD", typ: "Flags", usesScratch: true}, // arg0 compare to arg1, f64 diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 6a14ee080178b..34b1d8a4bba22 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -300,6 +300,12 @@ const ( Op386CMPLconst Op386CMPWconst Op386CMPBconst + Op386CMPLload + Op386CMPWload + Op386CMPBload + Op386CMPLconstload + Op386CMPWconstload + Op386CMPBconstload Op386UCOMISS Op386UCOMISD Op386TESTL @@ -3329,6 +3335,87 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "CMPLload", + auxType: auxSymOff, + argLen: 3, + faultOnNilArg0: true, + symEffect: SymRead, + asm: x86.ACMPL, + reg: regInfo{ + inputs: []inputInfo{ + {1, 255}, // AX CX DX BX SP BP SI DI + {0, 65791}, // AX CX DX BX SP BP SI DI SB + }, + }, + }, + { + name: "CMPWload", + auxType: auxSymOff, + argLen: 3, + faultOnNilArg0: true, + symEffect: SymRead, + asm: x86.ACMPW, + reg: regInfo{ + inputs: []inputInfo{ + {1, 255}, // AX CX DX BX SP BP SI DI + {0, 65791}, // AX CX DX BX SP BP SI DI SB + }, + }, + }, + { + name: "CMPBload", + auxType: auxSymOff, + argLen: 3, + faultOnNilArg0: true, + symEffect: SymRead, + asm: x86.ACMPB, + reg: regInfo{ + inputs: []inputInfo{ + {1, 255}, // AX CX DX BX SP BP SI DI + {0, 65791}, // AX CX DX BX SP BP SI DI SB + }, + }, + }, + { + name: "CMPLconstload", + auxType: auxSymValAndOff, + argLen: 2, + faultOnNilArg0: true, + symEffect: SymRead, + asm: x86.ACMPL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 65791}, // AX CX DX BX SP BP SI DI SB + }, + }, + }, + { + name: "CMPWconstload", + auxType: auxSymValAndOff, + argLen: 2, + faultOnNilArg0: true, + symEffect: SymRead, + asm: x86.ACMPW, + reg: regInfo{ + inputs: []inputInfo{ + {0, 65791}, // AX CX DX BX SP BP SI DI SB + }, + }, + }, + { + name: "CMPBconstload", + auxType: auxSymValAndOff, + argLen: 2, + faultOnNilArg0: true, + symEffect: SymRead, + asm: x86.ACMPB, + reg: regInfo{ + inputs: []inputInfo{ + {0, 65791}, // AX CX DX BX SP BP SI DI SB + }, + }, + }, { name: "UCOMISS", argLen: 2, diff --git a/src/cmd/compile/internal/ssa/rewrite386.go b/src/cmd/compile/internal/ssa/rewrite386.go index a204d48d073bb..db2c62089d6de 100644 --- a/src/cmd/compile/internal/ssa/rewrite386.go +++ b/src/cmd/compile/internal/ssa/rewrite386.go @@ -47,14 +47,20 @@ func rewriteValue386(v *Value) bool { return rewriteValue386_Op386CMPB_0(v) case Op386CMPBconst: return rewriteValue386_Op386CMPBconst_0(v) + case Op386CMPBload: + return rewriteValue386_Op386CMPBload_0(v) case Op386CMPL: return rewriteValue386_Op386CMPL_0(v) case Op386CMPLconst: - return rewriteValue386_Op386CMPLconst_0(v) + return rewriteValue386_Op386CMPLconst_0(v) || rewriteValue386_Op386CMPLconst_10(v) + case Op386CMPLload: + return rewriteValue386_Op386CMPLload_0(v) case Op386CMPW: return rewriteValue386_Op386CMPW_0(v) case Op386CMPWconst: return rewriteValue386_Op386CMPWconst_0(v) + case Op386CMPWload: + return rewriteValue386_Op386CMPWload_0(v) case Op386LEAL: return rewriteValue386_Op386LEAL_0(v) case Op386LEAL1: @@ -2216,9 +2222,65 @@ func rewriteValue386_Op386CMPB_0(v *Value) bool { v.AddArg(v0) return true } + // match: (CMPB l:(MOVBload {sym} [off] ptr mem) x) + // cond: canMergeLoad(v, l, x) && clobber(l) + // result: (CMPBload {sym} [off] ptr x mem) + for { + _ = v.Args[1] + l := v.Args[0] + if l.Op != Op386MOVBload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + x := v.Args[1] + if !(canMergeLoad(v, l, x) && clobber(l)) { + break + } + v.reset(Op386CMPBload) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (CMPB x l:(MOVBload {sym} [off] ptr mem)) + // cond: canMergeLoad(v, l, x) && clobber(l) + // result: (InvertFlags (CMPBload {sym} [off] ptr x mem)) + for { + _ = v.Args[1] + x := v.Args[0] + l := v.Args[1] + if l.Op != Op386MOVBload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(canMergeLoad(v, l, x) && clobber(l)) { + break + } + v.reset(Op386InvertFlags) + v0 := b.NewValue0(v.Pos, Op386CMPBload, types.TypeFlags) + v0.AuxInt = off + v0.Aux = sym + v0.AddArg(ptr) + v0.AddArg(x) + v0.AddArg(mem) + v.AddArg(v0) + return true + } return false } func rewriteValue386_Op386CMPBconst_0(v *Value) bool { + b := v.Block + _ = b // match: (CMPBconst (MOVLconst [x]) [y]) // cond: int8(x)==int8(y) // result: (FlagEQ) @@ -2365,6 +2427,60 @@ func rewriteValue386_Op386CMPBconst_0(v *Value) bool { v.AddArg(x) return true } + // match: (CMPBconst l:(MOVBload {sym} [off] ptr mem) [c]) + // cond: l.Uses == 1 && validValAndOff(c, off) && clobber(l) + // result: @l.Block (CMPBconstload {sym} [makeValAndOff(c,off)] ptr mem) + for { + c := v.AuxInt + l := v.Args[0] + if l.Op != Op386MOVBload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(l.Uses == 1 && validValAndOff(c, off) && clobber(l)) { + break + } + b = l.Block + v0 := b.NewValue0(v.Pos, Op386CMPBconstload, types.TypeFlags) + v.reset(OpCopy) + v.AddArg(v0) + v0.AuxInt = makeValAndOff(c, off) + v0.Aux = sym + v0.AddArg(ptr) + v0.AddArg(mem) + return true + } + return false +} +func rewriteValue386_Op386CMPBload_0(v *Value) bool { + // match: (CMPBload {sym} [off] ptr (MOVLconst [c]) mem) + // cond: validValAndOff(int64(int8(c)),off) + // result: (CMPBconstload {sym} [makeValAndOff(int64(int8(c)),off)] ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != Op386MOVLconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + if !(validValAndOff(int64(int8(c)), off)) { + break + } + v.reset(Op386CMPBconstload) + v.AuxInt = makeValAndOff(int64(int8(c)), off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } return false } func rewriteValue386_Op386CMPL_0(v *Value) bool { @@ -2404,6 +2520,60 @@ func rewriteValue386_Op386CMPL_0(v *Value) bool { v.AddArg(v0) return true } + // match: (CMPL l:(MOVLload {sym} [off] ptr mem) x) + // cond: canMergeLoad(v, l, x) && clobber(l) + // result: (CMPLload {sym} [off] ptr x mem) + for { + _ = v.Args[1] + l := v.Args[0] + if l.Op != Op386MOVLload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + x := v.Args[1] + if !(canMergeLoad(v, l, x) && clobber(l)) { + break + } + v.reset(Op386CMPLload) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (CMPL x l:(MOVLload {sym} [off] ptr mem)) + // cond: canMergeLoad(v, l, x) && clobber(l) + // result: (InvertFlags (CMPLload {sym} [off] ptr x mem)) + for { + _ = v.Args[1] + x := v.Args[0] + l := v.Args[1] + if l.Op != Op386MOVLload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(canMergeLoad(v, l, x) && clobber(l)) { + break + } + v.reset(Op386InvertFlags) + v0 := b.NewValue0(v.Pos, Op386CMPLload, types.TypeFlags) + v0.AuxInt = off + v0.Aux = sym + v0.AddArg(ptr) + v0.AddArg(x) + v0.AddArg(mem) + v.AddArg(v0) + return true + } return false } func rewriteValue386_Op386CMPLconst_0(v *Value) bool { @@ -2571,6 +2741,65 @@ func rewriteValue386_Op386CMPLconst_0(v *Value) bool { } return false } +func rewriteValue386_Op386CMPLconst_10(v *Value) bool { + b := v.Block + _ = b + // match: (CMPLconst l:(MOVLload {sym} [off] ptr mem) [c]) + // cond: l.Uses == 1 && validValAndOff(c, off) && clobber(l) + // result: @l.Block (CMPLconstload {sym} [makeValAndOff(c,off)] ptr mem) + for { + c := v.AuxInt + l := v.Args[0] + if l.Op != Op386MOVLload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(l.Uses == 1 && validValAndOff(c, off) && clobber(l)) { + break + } + b = l.Block + v0 := b.NewValue0(v.Pos, Op386CMPLconstload, types.TypeFlags) + v.reset(OpCopy) + v.AddArg(v0) + v0.AuxInt = makeValAndOff(c, off) + v0.Aux = sym + v0.AddArg(ptr) + v0.AddArg(mem) + return true + } + return false +} +func rewriteValue386_Op386CMPLload_0(v *Value) bool { + // match: (CMPLload {sym} [off] ptr (MOVLconst [c]) mem) + // cond: validValAndOff(int64(int32(c)),off) + // result: (CMPLconstload {sym} [makeValAndOff(int64(int32(c)),off)] ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != Op386MOVLconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + if !(validValAndOff(int64(int32(c)), off)) { + break + } + v.reset(Op386CMPLconstload) + v.AuxInt = makeValAndOff(int64(int32(c)), off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} func rewriteValue386_Op386CMPW_0(v *Value) bool { b := v.Block _ = b @@ -2608,9 +2837,65 @@ func rewriteValue386_Op386CMPW_0(v *Value) bool { v.AddArg(v0) return true } + // match: (CMPW l:(MOVWload {sym} [off] ptr mem) x) + // cond: canMergeLoad(v, l, x) && clobber(l) + // result: (CMPWload {sym} [off] ptr x mem) + for { + _ = v.Args[1] + l := v.Args[0] + if l.Op != Op386MOVWload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + x := v.Args[1] + if !(canMergeLoad(v, l, x) && clobber(l)) { + break + } + v.reset(Op386CMPWload) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (CMPW x l:(MOVWload {sym} [off] ptr mem)) + // cond: canMergeLoad(v, l, x) && clobber(l) + // result: (InvertFlags (CMPWload {sym} [off] ptr x mem)) + for { + _ = v.Args[1] + x := v.Args[0] + l := v.Args[1] + if l.Op != Op386MOVWload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(canMergeLoad(v, l, x) && clobber(l)) { + break + } + v.reset(Op386InvertFlags) + v0 := b.NewValue0(v.Pos, Op386CMPWload, types.TypeFlags) + v0.AuxInt = off + v0.Aux = sym + v0.AddArg(ptr) + v0.AddArg(x) + v0.AddArg(mem) + v.AddArg(v0) + return true + } return false } func rewriteValue386_Op386CMPWconst_0(v *Value) bool { + b := v.Block + _ = b // match: (CMPWconst (MOVLconst [x]) [y]) // cond: int16(x)==int16(y) // result: (FlagEQ) @@ -2757,6 +3042,60 @@ func rewriteValue386_Op386CMPWconst_0(v *Value) bool { v.AddArg(x) return true } + // match: (CMPWconst l:(MOVWload {sym} [off] ptr mem) [c]) + // cond: l.Uses == 1 && validValAndOff(c, off) && clobber(l) + // result: @l.Block (CMPWconstload {sym} [makeValAndOff(c,off)] ptr mem) + for { + c := v.AuxInt + l := v.Args[0] + if l.Op != Op386MOVWload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(l.Uses == 1 && validValAndOff(c, off) && clobber(l)) { + break + } + b = l.Block + v0 := b.NewValue0(v.Pos, Op386CMPWconstload, types.TypeFlags) + v.reset(OpCopy) + v.AddArg(v0) + v0.AuxInt = makeValAndOff(c, off) + v0.Aux = sym + v0.AddArg(ptr) + v0.AddArg(mem) + return true + } + return false +} +func rewriteValue386_Op386CMPWload_0(v *Value) bool { + // match: (CMPWload {sym} [off] ptr (MOVLconst [c]) mem) + // cond: validValAndOff(int64(int16(c)),off) + // result: (CMPWconstload {sym} [makeValAndOff(int64(int16(c)),off)] ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != Op386MOVLconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + if !(validValAndOff(int64(int16(c)), off)) { + break + } + v.reset(Op386CMPWconstload) + v.AuxInt = makeValAndOff(int64(int16(c)), off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } return false } func rewriteValue386_Op386LEAL_0(v *Value) bool { diff --git a/src/cmd/compile/internal/x86/ssa.go b/src/cmd/compile/internal/x86/ssa.go index b781d957258a7..d75a55c5659a2 100644 --- a/src/cmd/compile/internal/x86/ssa.go +++ b/src/cmd/compile/internal/x86/ssa.go @@ -417,6 +417,21 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.From.Offset = v.AuxInt p.To.Type = obj.TYPE_REG p.To.Reg = v.Args[0].Reg() + case ssa.Op386CMPLload, ssa.Op386CMPWload, ssa.Op386CMPBload: + p := s.Prog(v.Op.Asm()) + p.From.Type = obj.TYPE_MEM + p.From.Reg = v.Args[0].Reg() + gc.AddAux(&p.From, v) + p.To.Type = obj.TYPE_REG + p.To.Reg = v.Args[1].Reg() + case ssa.Op386CMPLconstload, ssa.Op386CMPWconstload, ssa.Op386CMPBconstload: + sc := v.AuxValAndOff() + p := s.Prog(v.Op.Asm()) + p.From.Type = obj.TYPE_MEM + p.From.Reg = v.Args[0].Reg() + gc.AddAux2(&p.From, v, sc.Off()) + p.To.Type = obj.TYPE_CONST + p.To.Offset = sc.Val() case ssa.Op386MOVLconst: x := v.Reg() diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go index 2f010bcbaefc6..ebd75d85d9178 100644 --- a/test/codegen/comparisons.go +++ b/test/codegen/comparisons.go @@ -122,6 +122,16 @@ func CmpMem5(p **int) { *p = nil } +func CmpMem6(a []int) int { + // 386:`CMPL\s8\([A-Z]+\),` + // amd64:`CMPQ\s16\([A-Z]+\),` + if a[1] > a[2] { + return 1 + } else { + return 2 + } +} + // Check tbz/tbnz are generated when comparing against zero on arm64 func CmpZero1(a int32, ptr *int) { From 2556df0ac0bf7ddb39ece91856ad94f5676b1b07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Mon, 30 Jul 2018 22:37:50 +0200 Subject: [PATCH 0015/1663] internal/cpu: remove parentheses from arm64 feature constants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The parentheses are not required for the definitions and it brings the declaration style in line with other architectures feature bits defined in internal/cpu. Change-Id: I86cc3812c1488216779e0d1f0e7481687502e592 Reviewed-on: https://go-review.googlesource.com/126775 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/internal/cpu/cpu_arm64.go | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/internal/cpu/cpu_arm64.go b/src/internal/cpu/cpu_arm64.go index 487ccf8e424b2..48607575ba947 100644 --- a/src/internal/cpu/cpu_arm64.go +++ b/src/internal/cpu/cpu_arm64.go @@ -14,30 +14,30 @@ var hwcap2 uint // HWCAP/HWCAP2 bits. These are exposed by Linux. const ( - hwcap_FP = (1 << 0) - hwcap_ASIMD = (1 << 1) - hwcap_EVTSTRM = (1 << 2) - hwcap_AES = (1 << 3) - hwcap_PMULL = (1 << 4) - hwcap_SHA1 = (1 << 5) - hwcap_SHA2 = (1 << 6) - hwcap_CRC32 = (1 << 7) - hwcap_ATOMICS = (1 << 8) - hwcap_FPHP = (1 << 9) - hwcap_ASIMDHP = (1 << 10) - hwcap_CPUID = (1 << 11) - hwcap_ASIMDRDM = (1 << 12) - hwcap_JSCVT = (1 << 13) - hwcap_FCMA = (1 << 14) - hwcap_LRCPC = (1 << 15) - hwcap_DCPOP = (1 << 16) - hwcap_SHA3 = (1 << 17) - hwcap_SM3 = (1 << 18) - hwcap_SM4 = (1 << 19) - hwcap_ASIMDDP = (1 << 20) - hwcap_SHA512 = (1 << 21) - hwcap_SVE = (1 << 22) - hwcap_ASIMDFHM = (1 << 23) + hwcap_FP = 1 << 0 + hwcap_ASIMD = 1 << 1 + hwcap_EVTSTRM = 1 << 2 + hwcap_AES = 1 << 3 + hwcap_PMULL = 1 << 4 + hwcap_SHA1 = 1 << 5 + hwcap_SHA2 = 1 << 6 + hwcap_CRC32 = 1 << 7 + hwcap_ATOMICS = 1 << 8 + hwcap_FPHP = 1 << 9 + hwcap_ASIMDHP = 1 << 10 + hwcap_CPUID = 1 << 11 + hwcap_ASIMDRDM = 1 << 12 + hwcap_JSCVT = 1 << 13 + hwcap_FCMA = 1 << 14 + hwcap_LRCPC = 1 << 15 + hwcap_DCPOP = 1 << 16 + hwcap_SHA3 = 1 << 17 + hwcap_SM3 = 1 << 18 + hwcap_SM4 = 1 << 19 + hwcap_ASIMDDP = 1 << 20 + hwcap_SHA512 = 1 << 21 + hwcap_SVE = 1 << 22 + hwcap_ASIMDFHM = 1 << 23 ) func doinit() { From 099498db0e47ba01ec405ca27662d9a87ef921e2 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Sat, 4 Aug 2018 12:04:52 +0200 Subject: [PATCH 0016/1663] time: always run ZoneAbbr test CL 52430 added logic to skip the testZoneAbbr test in locales where the timezone does not have a three-letter name, because the following line Parse(RFC1123, t1.Format(RFC1123)) failed for timezones with only numeric names (like -07). Since Go 1.11, Parse supports the parsing of timezones with numeric names (this was implemented in CL 98157), so we can now run the test unconditionally. Change-Id: I8ed40e1ba325c0c0dc79c4184a9e71209e2e9a02 Reviewed-on: https://go-review.googlesource.com/127757 Run-TryBot: Alberto Donizetti TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/time/zoneinfo_windows_test.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/time/zoneinfo_windows_test.go b/src/time/zoneinfo_windows_test.go index d0f2a444fe8f4..f23d9dcecb83a 100644 --- a/src/time/zoneinfo_windows_test.go +++ b/src/time/zoneinfo_windows_test.go @@ -15,13 +15,6 @@ func testZoneAbbr(t *testing.T) { // discard nsec t1 = Date(t1.Year(), t1.Month(), t1.Day(), t1.Hour(), t1.Minute(), t1.Second(), 0, t1.Location()) - // Skip the test if we're in a timezone with no abbreviation. - // Format will fallback to the numeric abbreviation, and - // Parse(RFC1123, ..) will fail (see Issue 21183). - if tz := t1.Format("MST"); tz[0] == '-' || tz[0] == '+' { - t.Skip("No zone abbreviation") - } - t2, err := Parse(RFC1123, t1.Format(RFC1123)) if err != nil { t.Fatalf("Parse failed: %v", err) From cd0e79d9f136088929f3c7aab53998793bf273ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Sat, 28 Jul 2018 09:08:09 +0200 Subject: [PATCH 0017/1663] all: use internal/cpu feature variables directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid using package specific variables when there is a one to one correspondance to cpu feature support exported by internal/cpu. This makes it clearer which cpu feature is referenced. Another advantage is that internal/cpu variables are padded to avoid false sharing and memory and cache usage is shared by multiple packages. Change-Id: If18fb448a95207cfa6a3376f3b2ddc4b230dd138 Reviewed-on: https://go-review.googlesource.com/126596 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/crypto/sha1/sha1block_arm64.go | 4 +--- src/crypto/sha256/sha256block_arm64.go | 4 +--- src/hash/crc32/crc32_arm64.go | 14 ++++++-------- 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/crypto/sha1/sha1block_arm64.go b/src/crypto/sha1/sha1block_arm64.go index 173c40fec81c7..08d3df0000e68 100644 --- a/src/crypto/sha1/sha1block_arm64.go +++ b/src/crypto/sha1/sha1block_arm64.go @@ -13,13 +13,11 @@ var k = []uint32{ 0xCA62C1D6, } -var hasSHA1 = cpu.ARM64.HasSHA1 - //go:noescape func sha1block(h []uint32, p []byte, k []uint32) func block(dig *digest, p []byte) { - if !hasSHA1 { + if !cpu.ARM64.HasSHA1 { blockGeneric(dig, p) } else { h := dig.h[:] diff --git a/src/crypto/sha256/sha256block_arm64.go b/src/crypto/sha256/sha256block_arm64.go index 75bbcbe0eb7e8..e5da566363155 100644 --- a/src/crypto/sha256/sha256block_arm64.go +++ b/src/crypto/sha256/sha256block_arm64.go @@ -8,13 +8,11 @@ import "internal/cpu" var k = _K -var hasSHA2 = cpu.ARM64.HasSHA2 - //go:noescape func sha256block(h []uint32, p []byte, k []uint32) func block(dig *digest, p []byte) { - if !hasSHA2 { + if !cpu.ARM64.HasSHA2 { blockGeneric(dig, p) } else { h := dig.h[:] diff --git a/src/hash/crc32/crc32_arm64.go b/src/hash/crc32/crc32_arm64.go index 1f8779d506fc6..0242d1d8a774a 100644 --- a/src/hash/crc32/crc32_arm64.go +++ b/src/hash/crc32/crc32_arm64.go @@ -13,20 +13,18 @@ import "internal/cpu" func castagnoliUpdate(crc uint32, p []byte) uint32 func ieeeUpdate(crc uint32, p []byte) uint32 -var hasCRC32 = cpu.ARM64.HasCRC32 - func archAvailableCastagnoli() bool { - return hasCRC32 + return cpu.ARM64.HasCRC32 } func archInitCastagnoli() { - if !hasCRC32 { + if !cpu.ARM64.HasCRC32 { panic("arch-specific crc32 instruction for Catagnoli not available") } } func archUpdateCastagnoli(crc uint32, p []byte) uint32 { - if !hasCRC32 { + if !cpu.ARM64.HasCRC32 { panic("arch-specific crc32 instruction for Castagnoli not available") } @@ -34,17 +32,17 @@ func archUpdateCastagnoli(crc uint32, p []byte) uint32 { } func archAvailableIEEE() bool { - return hasCRC32 + return cpu.ARM64.HasCRC32 } func archInitIEEE() { - if !hasCRC32 { + if !cpu.ARM64.HasCRC32 { panic("arch-specific crc32 instruction for IEEE not available") } } func archUpdateIEEE(crc uint32, p []byte) uint32 { - if !hasCRC32 { + if !cpu.ARM64.HasCRC32 { panic("arch-specific crc32 instruction for IEEE not available") } From 0a382e0b7f9abb39644adcfe65013df200989324 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Wed, 11 Jul 2018 01:30:32 +0000 Subject: [PATCH 0018/1663] cmd/compile: optimize ARMv7 code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "AND $0xffff0000, Rx" will be encoded to 12 bytes. 1. MOVWload from the constant pool to Rtmp 2. AND Rtmp, Rx 3. a 4-byte item in the constant pool It can be simplified to 8 bytes on ARMv7, since ARMv7 has "MOVW $imm-16, Rx". 1. MOVW $0xffff, Rtmp 2. BIC Rtmp, Rx The above optimization also applies to BICconst, ADDconst and SUBconst. 1. The total size of pkg/android_arm (excluding cmd/compile) decreases about 2KB. 2. The go1 benchmark shows no regression, exlcuding noise. name old time/op new time/op delta BinaryTree17-4 25.5s ± 1% 25.2s ± 1% -0.85% (p=0.000 n=30+30) Fannkuch11-4 13.3s ± 0% 13.3s ± 0% +0.16% (p=0.000 n=24+25) FmtFprintfEmpty-4 397ns ± 0% 394ns ± 0% -0.64% (p=0.000 n=30+30) FmtFprintfString-4 679ns ± 0% 678ns ± 0% ~ (p=0.093 n=30+29) FmtFprintfInt-4 708ns ± 0% 707ns ± 0% -0.19% (p=0.000 n=27+28) FmtFprintfIntInt-4 1.05µs ± 0% 1.05µs ± 0% -0.07% (p=0.001 n=18+30) FmtFprintfPrefixedInt-4 1.16µs ± 0% 1.15µs ± 0% -0.41% (p=0.000 n=29+30) FmtFprintfFloat-4 2.26µs ± 0% 2.23µs ± 1% -1.40% (p=0.000 n=30+30) FmtManyArgs-4 3.96µs ± 0% 3.95µs ± 0% -0.29% (p=0.000 n=29+30) GobDecode-4 52.9ms ± 2% 53.4ms ± 2% +0.92% (p=0.004 n=28+30) GobEncode-4 49.7ms ± 2% 49.8ms ± 2% ~ (p=0.890 n=30+26) Gzip-4 2.61s ± 0% 2.60s ± 0% -0.36% (p=0.000 n=29+29) Gunzip-4 312ms ± 0% 311ms ± 0% -0.13% (p=0.000 n=30+28) HTTPClientServer-4 1.02ms ± 8% 1.00ms ± 7% ~ (p=0.224 n=29+26) JSONEncode-4 125ms ± 1% 124ms ± 3% -1.05% (p=0.000 n=25+30) JSONDecode-4 432ms ± 1% 436ms ± 2% ~ (p=0.277 n=26+30) Mandelbrot200-4 18.4ms ± 0% 18.4ms ± 0% +0.02% (p=0.001 n=28+25) GoParse-4 22.4ms ± 1% 22.3ms ± 1% -0.41% (p=0.000 n=28+28) RegexpMatchEasy0_32-4 697ns ± 0% 706ns ± 0% +1.23% (p=0.000 n=19+30) RegexpMatchEasy0_1K-4 4.27µs ± 0% 4.26µs ± 0% -0.06% (p=0.000 n=30+30) RegexpMatchEasy1_32-4 741ns ± 0% 735ns ± 0% -0.86% (p=0.000 n=26+30) RegexpMatchEasy1_1K-4 5.49µs ± 0% 5.49µs ± 0% -0.03% (p=0.023 n=25+30) RegexpMatchMedium_32-4 1.05µs ± 2% 1.04µs ± 2% ~ (p=0.893 n=30+30) RegexpMatchMedium_1K-4 261µs ± 0% 261µs ± 0% -0.11% (p=0.000 n=29+30) RegexpMatchHard_32-4 14.9µs ± 0% 14.9µs ± 0% -0.36% (p=0.000 n=23+29) RegexpMatchHard_1K-4 446µs ± 0% 445µs ± 0% -0.17% (p=0.000 n=30+29) Revcomp-4 41.6ms ± 1% 41.7ms ± 1% +0.27% (p=0.040 n=28+30) Template-4 531ms ± 0% 532ms ± 1% ~ (p=0.059 n=30+30) TimeParse-4 3.40µs ± 0% 3.33µs ± 0% -2.02% (p=0.000 n=30+30) TimeFormat-4 6.14µs ± 0% 6.11µs ± 0% -0.45% (p=0.000 n=27+29) [Geo mean] 384µs 383µs -0.27% name old speed new speed delta GobDecode-4 14.5MB/s ± 2% 14.4MB/s ± 2% -0.90% (p=0.005 n=28+30) GobEncode-4 15.4MB/s ± 2% 15.4MB/s ± 2% ~ (p=0.741 n=30+25) Gzip-4 7.44MB/s ± 0% 7.47MB/s ± 1% +0.37% (p=0.000 n=25+30) Gunzip-4 62.3MB/s ± 0% 62.4MB/s ± 0% +0.13% (p=0.000 n=30+28) JSONEncode-4 15.5MB/s ± 1% 15.6MB/s ± 3% +1.07% (p=0.000 n=25+30) JSONDecode-4 4.48MB/s ± 0% 4.46MB/s ± 2% ~ (p=0.655 n=23+30) GoParse-4 2.58MB/s ± 1% 2.59MB/s ± 1% +0.42% (p=0.000 n=28+29) RegexpMatchEasy0_32-4 45.9MB/s ± 0% 45.3MB/s ± 0% -1.23% (p=0.000 n=28+30) RegexpMatchEasy0_1K-4 240MB/s ± 0% 240MB/s ± 0% +0.07% (p=0.000 n=30+30) RegexpMatchEasy1_32-4 43.2MB/s ± 0% 43.5MB/s ± 0% +0.85% (p=0.000 n=30+28) RegexpMatchEasy1_1K-4 186MB/s ± 0% 186MB/s ± 0% +0.03% (p=0.026 n=25+30) RegexpMatchMedium_32-4 955kB/s ± 2% 960kB/s ± 2% ~ (p=0.084 n=30+30) RegexpMatchMedium_1K-4 3.92MB/s ± 0% 3.93MB/s ± 0% +0.14% (p=0.000 n=29+30) RegexpMatchHard_32-4 2.14MB/s ± 0% 2.15MB/s ± 0% +0.31% (p=0.000 n=30+26) RegexpMatchHard_1K-4 2.30MB/s ± 0% 2.30MB/s ± 0% ~ (all equal) Revcomp-4 61.1MB/s ± 1% 60.9MB/s ± 1% -0.27% (p=0.039 n=28+30) Template-4 3.66MB/s ± 0% 3.65MB/s ± 1% -0.14% (p=0.045 n=30+30) [Geo mean] 12.8MB/s 12.8MB/s +0.04% Change-Id: I02370e2584b4c041fddd324c97628fd6f0c12183 Reviewed-on: https://go-review.googlesource.com/123179 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/gen/ARM.rules | 4 ++ src/cmd/compile/internal/ssa/rewriteARM.go | 56 ++++++++++++++++++++++ test/codegen/bits.go | 5 ++ 3 files changed, 65 insertions(+) diff --git a/src/cmd/compile/internal/ssa/gen/ARM.rules b/src/cmd/compile/internal/ssa/gen/ARM.rules index 2846ef6d2e835..e8a3c27c71bea 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM.rules @@ -812,6 +812,10 @@ (SUBconst [c] x) && !isARMImmRot(uint32(c)) && isARMImmRot(uint32(-c)) -> (ADDconst [int64(int32(-c))] x) (ANDconst [c] x) && !isARMImmRot(uint32(c)) && isARMImmRot(^uint32(c)) -> (BICconst [int64(int32(^uint32(c)))] x) (BICconst [c] x) && !isARMImmRot(uint32(c)) && isARMImmRot(^uint32(c)) -> (ANDconst [int64(int32(^uint32(c)))] x) +(ADDconst [c] x) && objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && uint32(-c)<=0xffff -> (SUBconst [int64(int32(-c))] x) +(SUBconst [c] x) && objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && uint32(-c)<=0xffff -> (ANDconst [int64(int32(-c))] x) +(ANDconst [c] x) && objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && ^uint32(c)<=0xffff -> (BICconst [int64(int32(^uint32(c)))] x) +(BICconst [c] x) && objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && ^uint32(c)<=0xffff -> (ANDconst [int64(int32(^uint32(c)))] x) (ADDconst [c] (MOVWconst [d])) -> (MOVWconst [int64(int32(c+d))]) (ADDconst [c] (ADDconst [d] x)) -> (ADDconst [int64(int32(c+d))] x) (ADDconst [c] (SUBconst [d] x)) -> (ADDconst [int64(int32(c-d))] x) diff --git a/src/cmd/compile/internal/ssa/rewriteARM.go b/src/cmd/compile/internal/ssa/rewriteARM.go index dc1273327917f..e463511f17361 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM.go +++ b/src/cmd/compile/internal/ssa/rewriteARM.go @@ -2850,6 +2850,20 @@ func rewriteValueARM_OpARMADDconst_0(v *Value) bool { v.AddArg(x) return true } + // match: (ADDconst [c] x) + // cond: objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && uint32(-c)<=0xffff + // result: (SUBconst [int64(int32(-c))] x) + for { + c := v.AuxInt + x := v.Args[0] + if !(objabi.GOARM == 7 && !isARMImmRot(uint32(c)) && uint32(c) > 0xffff && uint32(-c) <= 0xffff) { + break + } + v.reset(OpARMSUBconst) + v.AuxInt = int64(int32(-c)) + v.AddArg(x) + return true + } // match: (ADDconst [c] (MOVWconst [d])) // cond: // result: (MOVWconst [int64(int32(c+d))]) @@ -3670,6 +3684,20 @@ func rewriteValueARM_OpARMANDconst_0(v *Value) bool { v.AddArg(x) return true } + // match: (ANDconst [c] x) + // cond: objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && ^uint32(c)<=0xffff + // result: (BICconst [int64(int32(^uint32(c)))] x) + for { + c := v.AuxInt + x := v.Args[0] + if !(objabi.GOARM == 7 && !isARMImmRot(uint32(c)) && uint32(c) > 0xffff && ^uint32(c) <= 0xffff) { + break + } + v.reset(OpARMBICconst) + v.AuxInt = int64(int32(^uint32(c))) + v.AddArg(x) + return true + } // match: (ANDconst [c] (MOVWconst [d])) // cond: // result: (MOVWconst [c&d]) @@ -4243,6 +4271,20 @@ func rewriteValueARM_OpARMBICconst_0(v *Value) bool { v.AddArg(x) return true } + // match: (BICconst [c] x) + // cond: objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && ^uint32(c)<=0xffff + // result: (ANDconst [int64(int32(^uint32(c)))] x) + for { + c := v.AuxInt + x := v.Args[0] + if !(objabi.GOARM == 7 && !isARMImmRot(uint32(c)) && uint32(c) > 0xffff && ^uint32(c) <= 0xffff) { + break + } + v.reset(OpARMANDconst) + v.AuxInt = int64(int32(^uint32(c))) + v.AddArg(x) + return true + } // match: (BICconst [c] (MOVWconst [d])) // cond: // result: (MOVWconst [d&^c]) @@ -15243,6 +15285,20 @@ func rewriteValueARM_OpARMSUBconst_0(v *Value) bool { v.AddArg(x) return true } + // match: (SUBconst [c] x) + // cond: objabi.GOARM==7 && !isARMImmRot(uint32(c)) && uint32(c)>0xffff && uint32(-c)<=0xffff + // result: (ANDconst [int64(int32(-c))] x) + for { + c := v.AuxInt + x := v.Args[0] + if !(objabi.GOARM == 7 && !isARMImmRot(uint32(c)) && uint32(c) > 0xffff && uint32(-c) <= 0xffff) { + break + } + v.reset(OpARMANDconst) + v.AuxInt = int64(int32(-c)) + v.AddArg(x) + return true + } // match: (SUBconst [c] (MOVWconst [d])) // cond: // result: (MOVWconst [int64(int32(d-c))]) diff --git a/test/codegen/bits.go b/test/codegen/bits.go index 2d1645b5e32f3..c46f75845c22e 100644 --- a/test/codegen/bits.go +++ b/test/codegen/bits.go @@ -284,6 +284,11 @@ func and_mask_2(a uint64) uint64 { return a & (1 << 63) } +func and_mask_3(a uint32) uint32 { + // arm/7:`BIC`,-`AND` + return a & 0xffff0000 +} + // Check generation of arm64 BIC/EON/ORN instructions func op_bic(x, y uint32) uint32 { From 21ac81192483e6b8135cec4c47e6f9fce890fb05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Mon, 30 Jul 2018 22:57:25 +0200 Subject: [PATCH 0019/1663] internal/cpu: make all constants for s390x feature detection typed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only the first constant in the function and facility constant declaration blocks were typed constants. Make all other constants used for function codes and named facilities also typed. Change-Id: I1814121de3733094da699c78b7311f99ba4772e1 Reviewed-on: https://go-review.googlesource.com/126776 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/internal/cpu/cpu_s390x.go | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/internal/cpu/cpu_s390x.go b/src/internal/cpu/cpu_s390x.go index 389a058c32aef..0a12922045e4d 100644 --- a/src/internal/cpu/cpu_s390x.go +++ b/src/internal/cpu/cpu_s390x.go @@ -18,16 +18,16 @@ type function uint8 const ( // KM{,A,C,CTR} function codes aes128 function = 18 // AES-128 - aes192 = 19 // AES-192 - aes256 = 20 // AES-256 + aes192 function = 19 // AES-192 + aes256 function = 20 // AES-256 // K{I,L}MD function codes - sha1 = 1 // SHA-1 - sha256 = 2 // SHA-256 - sha512 = 3 // SHA-512 + sha1 function = 1 // SHA-1 + sha256 function = 2 // SHA-256 + sha512 function = 3 // SHA-512 // KLMD function codes - ghash = 65 // GHASH + ghash function = 65 // GHASH ) // queryResult contains the result of a Query function @@ -56,20 +56,20 @@ type facility uint8 const ( // mandatory facilities zarch facility = 1 // z architecture mode is active - stflef = 7 // store-facility-list-extended - ldisp = 18 // long-displacement - eimm = 21 // extended-immediate + stflef facility = 7 // store-facility-list-extended + ldisp facility = 18 // long-displacement + eimm facility = 21 // extended-immediate // miscellaneous facilities - dfp = 42 // decimal-floating-point - etf3eh = 30 // extended-translation 3 enhancement + dfp facility = 42 // decimal-floating-point + etf3eh facility = 30 // extended-translation 3 enhancement // cryptography facilities - msa = 17 // message-security-assist - msa3 = 76 // message-security-assist extension 3 - msa4 = 77 // message-security-assist extension 4 - msa5 = 57 // message-security-assist extension 5 - msa8 = 146 // message-security-assist extension 8 + msa facility = 17 // message-security-assist + msa3 facility = 76 // message-security-assist extension 3 + msa4 facility = 77 // message-security-assist extension 4 + msa5 facility = 57 // message-security-assist extension 5 + msa8 facility = 146 // message-security-assist extension 8 // Note: vx and highgprs are excluded because they require // kernel support and so must be fetched from HWCAP. From 84feb4bbb76c4317652a79f45e3ad2d7c46c5761 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Mon, 16 Jul 2018 13:19:59 +0000 Subject: [PATCH 0020/1663] cmd/internal/obj/arm64: add register indexed FMOVS/FMOVD This CL adds register indexed FMOVS/FMOVD. FMOVS Fx, (Rn)(Rm) FMOVS Fx, (Rn)(Rm<<2) FMOVD Fx, (Rn)(Rm) FMOVD Fx, (Rn)(Rm<<3) FMOVS (Rn)(Rm), Fx FMOVS (Rn)(Rm<<2), Fx FMOVD (Rn)(Rm), Fx FMOVD (Rn)(Rm<<3), Fx Change-Id: Id76de6a4be96b64cf79d7e9a1962d9d49cb462f2 Reviewed-on: https://go-review.googlesource.com/123995 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/asm/internal/asm/testdata/arm64.s | 9 +++++++++ src/cmd/internal/obj/arm64/asm7.go | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cmd/asm/internal/asm/testdata/arm64.s b/src/cmd/asm/internal/asm/testdata/arm64.s index 3a1b2f79beb81..38616bd8376b1 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64.s +++ b/src/cmd/asm/internal/asm/testdata/arm64.s @@ -164,6 +164,15 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8 MOVB (R29)(R30), R14 // MOVB (R29)(R30*1), R14 // ae6bbe38 MOVB R4, (R2)(R6.SXTX) // 44e82638 + FMOVS (R2)(R6), F4 // FMOVS (R2)(R6*1), F4 // 446866bc + FMOVS (R2)(R6<<2), F4 // 447866bc + FMOVD (R2)(R6), F4 // FMOVD (R2)(R6*1), F4 // 446866fc + FMOVD (R2)(R6<<3), F4 // 447866fc + FMOVS F4, (R2)(R6) // FMOVS F4, (R2)(R6*1) // 446826bc + FMOVS F4, (R2)(R6<<2) // 447826bc + FMOVD F4, (R2)(R6) // FMOVD F4, (R2)(R6*1) // 446826fc + FMOVD F4, (R2)(R6<<3) // 447826fc + // LTYPE1 imsr ',' spreg ',' // { // outcode($1, &$2, $4, &nullgen); diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index f7a3babd198d6..4840a969fd665 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -519,12 +519,16 @@ var optab = []Optab{ {AMOVH, C_ROFF, C_NONE, C_NONE, C_REG, 98, 4, 0, 0, 0}, {AMOVB, C_ROFF, C_NONE, C_NONE, C_REG, 98, 4, 0, 0, 0}, {AMOVBU, C_ROFF, C_NONE, C_NONE, C_REG, 98, 4, 0, 0, 0}, + {AFMOVS, C_ROFF, C_NONE, C_NONE, C_FREG, 98, 4, 0, 0, 0}, + {AFMOVD, C_ROFF, C_NONE, C_NONE, C_FREG, 98, 4, 0, 0, 0}, /* store with extended register offset */ {AMOVD, C_REG, C_NONE, C_NONE, C_ROFF, 99, 4, 0, 0, 0}, {AMOVW, C_REG, C_NONE, C_NONE, C_ROFF, 99, 4, 0, 0, 0}, {AMOVH, C_REG, C_NONE, C_NONE, C_ROFF, 99, 4, 0, 0, 0}, {AMOVB, C_REG, C_NONE, C_NONE, C_ROFF, 99, 4, 0, 0, 0}, + {AFMOVS, C_FREG, C_NONE, C_NONE, C_ROFF, 99, 4, 0, 0, 0}, + {AFMOVD, C_FREG, C_NONE, C_NONE, C_ROFF, 99, 4, 0, 0, 0}, /* pre/post-indexed/signed-offset load/store register pair (unscaled, signed 10-bit quad-aligned and long offset) */ @@ -2540,11 +2544,11 @@ func (c *ctxt7) checkShiftAmount(p *obj.Prog, a *obj.Addr) { if amount != 1 && amount != 0 { c.ctxt.Diag("invalid index shift amount: %v", p) } - case AMOVW, AMOVWU: + case AMOVW, AMOVWU, AFMOVS: if amount != 2 && amount != 0 { c.ctxt.Diag("invalid index shift amount: %v", p) } - case AMOVD: + case AMOVD, AFMOVD: if amount != 3 && amount != 0 { c.ctxt.Diag("invalid index shift amount: %v", p) } From 7b9c2c1950c167b16f8b3cda179363ca8df2c1b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Tue, 5 Jun 2018 08:14:57 +0200 Subject: [PATCH 0021/1663] internal/cpu: add and use cpu.CacheLinePad for padding structs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a CacheLinePad struct type to internal/cpu that has a size of CacheLineSize. This can be used for padding structs in order to avoid false sharing. Updates #25203 Change-Id: Icb95ae68d3c711f5f8217140811cad1a1d5be79a Reviewed-on: https://go-review.googlesource.com/116276 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/internal/cpu/cpu.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/internal/cpu/cpu.go b/src/internal/cpu/cpu.go index 2569024245d0f..701584dd3dadd 100644 --- a/src/internal/cpu/cpu.go +++ b/src/internal/cpu/cpu.go @@ -10,6 +10,9 @@ package cpu // and GOOS is Linux or Darwin. This variable is linknamed in runtime/proc.go. var debugOptions bool +// CacheLinePad is used to pad structs to avoid false sharing. +type CacheLinePad struct{ _ [CacheLineSize]byte } + var X86 x86 // The booleans in x86 contain the correspondingly named cpuid feature bit. @@ -17,7 +20,7 @@ var X86 x86 // in addition to the cpuid feature bit being set. // The struct is padded to avoid false sharing. type x86 struct { - _ [CacheLineSize]byte + _ CacheLinePad HasAES bool HasADX bool HasAVX bool @@ -34,7 +37,7 @@ type x86 struct { HasSSSE3 bool HasSSE41 bool HasSSE42 bool - _ [CacheLineSize]byte + _ CacheLinePad } var PPC64 ppc64 @@ -47,7 +50,7 @@ var PPC64 ppc64 // safety. // The struct is padded to avoid false sharing. type ppc64 struct { - _ [CacheLineSize]byte + _ CacheLinePad HasVMX bool // Vector unit (Altivec) HasDFP bool // Decimal Floating Point unit HasVSX bool // Vector-scalar unit @@ -59,7 +62,7 @@ type ppc64 struct { HasSCV bool // Syscall vectored (requires kernel enablement) IsPOWER8 bool // ISA v2.07 (POWER8) IsPOWER9 bool // ISA v3.00 (POWER9) - _ [CacheLineSize]byte + _ CacheLinePad } var ARM64 arm64 @@ -67,7 +70,7 @@ var ARM64 arm64 // The booleans in arm64 contain the correspondingly named cpu feature bit. // The struct is padded to avoid false sharing. type arm64 struct { - _ [CacheLineSize]byte + _ CacheLinePad HasFP bool HasASIMD bool HasEVTSTRM bool @@ -92,13 +95,13 @@ type arm64 struct { HasSHA512 bool HasSVE bool HasASIMDFHM bool - _ [CacheLineSize]byte + _ CacheLinePad } var S390X s390x type s390x struct { - _ [CacheLineSize]byte + _ CacheLinePad HasZArch bool // z architecture mode is active [mandatory] HasSTFLE bool // store facility list extended [mandatory] HasLDisp bool // long (20-bit) displacements [mandatory] @@ -115,7 +118,7 @@ type s390x struct { HasSHA256 bool // K{I,L}MD-SHA-256 functions HasSHA512 bool // K{I,L}MD-SHA-512 functions HasVX bool // vector facility. Note: the runtime sets this when it processes auxv records. - _ [CacheLineSize]byte + _ CacheLinePad } // initialize examines the processor and sets the relevant variables above. From 6c7e199e500d3f81bda4ce383839e7f0336ed63c Mon Sep 17 00:00:00 2001 From: Ben Hoyt Date: Sat, 11 Aug 2018 12:02:52 +0200 Subject: [PATCH 0022/1663] text/scanner: don't allow Float exponents with no mantissa Previously Scanner would allow float literals like "1.5e" and "1e+" that weren't actually valid Go float literals, and also not valid when passed to ParseFloat. This commit fixes that behaviour to match the documentation ("recognizes all literals as defined by the Go language specification"), and Scanner emits an error in these cases. Fixes #26374 Change-Id: I6855402ea43febb448c6dff105b9578e31803c01 Reviewed-on: https://go-review.googlesource.com/129095 Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot --- src/text/scanner/scanner.go | 3 +++ src/text/scanner/scanner_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/text/scanner/scanner.go b/src/text/scanner/scanner.go index 4e76664dc0c81..893a4edbaf92f 100644 --- a/src/text/scanner/scanner.go +++ b/src/text/scanner/scanner.go @@ -384,6 +384,9 @@ func (s *Scanner) scanExponent(ch rune) rune { if ch == '-' || ch == '+' { ch = s.next() } + if !isDecimal(ch) { + s.error("illegal exponent") + } ch = s.scanMantissa(ch) } return ch diff --git a/src/text/scanner/scanner_test.go b/src/text/scanner/scanner_test.go index 9a6b72ef673b0..e26e816f51989 100644 --- a/src/text/scanner/scanner_test.go +++ b/src/text/scanner/scanner_test.go @@ -252,6 +252,14 @@ func checkTok(t *testing.T, s *Scanner, line int, got, want rune, text string) { } } +func checkTokErr(t *testing.T, s *Scanner, line int, want rune, text string) { + prevCount := s.ErrorCount + checkTok(t, s, line, s.Scan(), want, text) + if s.ErrorCount != prevCount+1 { + t.Fatalf("want error for %q", text) + } +} + func countNewlines(s string) int { n := 0 for _, ch := range s { @@ -282,6 +290,21 @@ func TestScan(t *testing.T) { testScan(t, GoTokens&^SkipComments) } +func TestIllegalExponent(t *testing.T) { + const src = "1.5e 1.5E 1e+ 1e- 1.5z" + s := new(Scanner).Init(strings.NewReader(src)) + checkTokErr(t, s, 1, Float, "1.5e") + checkTokErr(t, s, 1, Float, "1.5E") + checkTokErr(t, s, 1, Float, "1e+") + checkTokErr(t, s, 1, Float, "1e-") + checkTok(t, s, 1, s.Scan(), Float, "1.5") + checkTok(t, s, 1, s.Scan(), Ident, "z") + checkTok(t, s, 1, s.Scan(), EOF, "") + if s.ErrorCount != 4 { + t.Errorf("%d errors, want 4", s.ErrorCount) + } +} + func TestPosition(t *testing.T) { src := makeSource("\t\t\t\t%s\n") s := new(Scanner).Init(src) @@ -475,6 +498,10 @@ func TestError(t *testing.T) { testError(t, `0x`, ":1:3", "illegal hexadecimal number", Int) testError(t, `0xg`, ":1:3", "illegal hexadecimal number", Int) testError(t, `'aa'`, ":1:4", "illegal char literal", Char) + testError(t, `1.5e`, ":1:5", "illegal exponent", Float) + testError(t, `1.5E`, ":1:5", "illegal exponent", Float) + testError(t, `1.5e+`, ":1:6", "illegal exponent", Float) + testError(t, `1.5e-`, ":1:6", "illegal exponent", Float) testError(t, `'`, ":1:2", "literal not terminated", Char) testError(t, `'`+"\n", ":1:2", "literal not terminated", Char) From edae0ff8c13d607aee3fca7fb80faa1dfc2a2944 Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Mon, 20 Aug 2018 17:28:55 +0100 Subject: [PATCH 0023/1663] math: use s390x mnemonics rather than binary encodings TMLL, LGDR and LDGR have all been added to the Go assembler previously, so we don't need to encode them using WORD and BYTE directives anymore. This is purely a cosmetic change, it does not change the contents of any object files. Change-Id: I93f815b91be310858297d8a0dc9e6d8e3f09dd65 Reviewed-on: https://go-review.googlesource.com/129895 Run-TryBot: Michael Munday Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/math/acos_s390x.s | 2 +- src/math/acosh_s390x.s | 8 ++++---- src/math/asin_s390x.s | 2 +- src/math/asinh_s390x.s | 8 ++++---- src/math/atan2_s390x.s | 6 +++--- src/math/atan_s390x.s | 2 +- src/math/atanh_s390x.s | 6 +++--- src/math/cbrt_s390x.s | 6 +++--- src/math/erf_s390x.s | 6 +++--- src/math/erfc_s390x.s | 8 ++++---- src/math/exp_s390x.s | 10 +++++----- src/math/expm1_s390x.s | 10 +++++----- src/math/log1p_s390x.s | 10 +++++----- src/math/log_s390x.s | 10 +++++----- src/math/pow_s390x.s | 20 ++++++++++---------- src/math/tan_s390x.s | 4 ++-- 16 files changed, 59 insertions(+), 59 deletions(-) diff --git a/src/math/acos_s390x.s b/src/math/acos_s390x.s index 306f45a406672..d2288b8cd8e6b 100644 --- a/src/math/acos_s390x.s +++ b/src/math/acos_s390x.s @@ -42,7 +42,7 @@ GLOBL ·acosrodataL13<> + 0(SB), RODATA, $200 TEXT ·acosAsm(SB), NOSPLIT, $0-16 FMOVD x+0(FP), F0 MOVD $·acosrodataL13<>+0(SB), R9 - WORD $0xB3CD00C0 //lgdr %r12, %f0 + LGDR F0, R12 FMOVD F0, F10 SRAD $32, R12 WORD $0xC0293FE6 //iilf %r2,1072079005 diff --git a/src/math/acosh_s390x.s b/src/math/acosh_s390x.s index 3575ed6394b7d..87a5d00154dfe 100644 --- a/src/math/acosh_s390x.s +++ b/src/math/acosh_s390x.s @@ -53,7 +53,7 @@ GLOBL ·acoshtab2068<> + 0(SB), RODATA, $128 TEXT ·acoshAsm(SB), NOSPLIT, $0-16 FMOVD x+0(FP), F0 MOVD $·acoshrodataL11<>+0(SB), R9 - WORD $0xB3CD0010 //lgdr %r1, %f0 + LGDR F0, R1 WORD $0xC0295FEF //iilf %r2,1609564159 BYTE $0xFF BYTE $0xFF @@ -85,7 +85,7 @@ L2: WORD $0xC0398006 //iilf %r3,2147909631 BYTE $0x7F BYTE $0xFF - WORD $0xB3CD0050 //lgdr %r5, %f0 + LGDR F0, R5 SRAD $32, R5 MOVH $0x0, R1 SUBW R5, R3 @@ -105,7 +105,7 @@ L2: SRAW $8, R2, R2 ORW $0x45000000, R2 L5: - WORD $0xB3C10001 //ldgr %f0,%r1 + LDGR R1, F0 FMOVD 104(R9), F2 FMADD F8, F0, F2 FMOVD 96(R9), F4 @@ -153,7 +153,7 @@ L4: WORD $0xC0398006 //iilf %r3,2147909631 BYTE $0x7F BYTE $0xFF - WORD $0xB3CD0050 //lgdr %r5, %f0 + LGDR F0, R5 SRAD $32, R5 MOVH $0x0, R1 SUBW R5, R3 diff --git a/src/math/asin_s390x.s b/src/math/asin_s390x.s index fd5ab040a5aeb..dc54d053f1cab 100644 --- a/src/math/asin_s390x.s +++ b/src/math/asin_s390x.s @@ -46,7 +46,7 @@ GLOBL ·asinrodataL15<> + 0(SB), RODATA, $224 TEXT ·asinAsm(SB), NOSPLIT, $0-16 FMOVD x+0(FP), F0 MOVD $·asinrodataL15<>+0(SB), R9 - WORD $0xB3CD0070 //lgdr %r7, %f0 + LGDR F0, R7 FMOVD F0, F8 SRAD $32, R7 WORD $0xC0193FE6 //iilf %r1,1072079005 diff --git a/src/math/asinh_s390x.s b/src/math/asinh_s390x.s index a9cee342d30f0..a3680c661fbd8 100644 --- a/src/math/asinh_s390x.s +++ b/src/math/asinh_s390x.s @@ -64,7 +64,7 @@ GLOBL ·asinhtab2080<> + 0(SB), RODATA, $128 TEXT ·asinhAsm(SB), NOSPLIT, $0-16 FMOVD x+0(FP), F0 MOVD $·asinhrodataL18<>+0(SB), R9 - WORD $0xB3CD00C0 //lgdr %r12, %f0 + LGDR F0, R12 WORD $0xC0293FDF //iilf %r2,1071644671 BYTE $0xFF BYTE $0xFF @@ -93,7 +93,7 @@ L9: WORD $0xC0398006 //iilf %r3,2147909631 BYTE $0x7F BYTE $0xFF - WORD $0xB3CD0050 //lgdr %r5, %f0 + LGDR F0, R5 SRAD $32, R5 MOVH $0x0, R2 SUBW R5, R3 @@ -133,7 +133,7 @@ L5: WORD $0xC0398006 //iilf %r3,2147909631 BYTE $0x7F BYTE $0xFF - WORD $0xB3CD0050 //lgdr %r5, %f0 + LGDR F0, R5 SRAD $32, R5 MOVH $0x0, R2 SUBW R5, R3 @@ -146,7 +146,7 @@ L5: BYTE $0x59 ORW $0x45000000, R1 L6: - WORD $0xB3C10022 //ldgr %f2,%r2 + LDGR R2, F2 FMOVD 184(R9), F0 WFMADB V8, V2, V0, V8 FMOVD 176(R9), F4 diff --git a/src/math/atan2_s390x.s b/src/math/atan2_s390x.s index f37555b07f1bb..c7a8a09d05635 100644 --- a/src/math/atan2_s390x.s +++ b/src/math/atan2_s390x.s @@ -142,8 +142,8 @@ Normal: FMOVD x+0(FP), F0 FMOVD y+8(FP), F2 MOVD $·atan2rodataL25<>+0(SB), R9 - WORD $0xB3CD0020 //lgdr %r2,%f0 - WORD $0xB3CD0012 //lgdr %r1,%f2 + LGDR F0, R2 + LGDR F2, R1 WORD $0xEC2220BF //risbgn %r2,%r2,64-32,128+63,64+0+32 BYTE $0x60 BYTE $0x59 @@ -229,7 +229,7 @@ L18: BYTE $0x55 MOVD $·atan2xpi2h<>+0(SB), R1 MOVD ·atan2xpim<>+0(SB), R3 - WORD $0xB3C10003 //ldgr %f0,%r3 + LDGR R3, F0 WORD $0xED021000 //madb %f4,%f0,0(%r2,%r1) BYTE $0x40 BYTE $0x1E diff --git a/src/math/atan_s390x.s b/src/math/atan_s390x.s index 9f4eaa28d5ae2..713727ddbf809 100644 --- a/src/math/atan_s390x.s +++ b/src/math/atan_s390x.s @@ -54,7 +54,7 @@ TEXT ·atanAsm(SB), NOSPLIT, $0-16 MOVD $·atanrodataL8<>+0(SB), R5 MOVH $0x3FE0, R3 - WORD $0xB3CD0010 //lgdr %r1,%f0 + LGDR F0, R1 WORD $0xEC1120BF //risbgn %r1,%r1,64-32,128+63,64+0+32 BYTE $0x60 BYTE $0x59 diff --git a/src/math/atanh_s390x.s b/src/math/atanh_s390x.s index 57b61a34ff1c9..e7c63597041b9 100644 --- a/src/math/atanh_s390x.s +++ b/src/math/atanh_s390x.s @@ -64,7 +64,7 @@ GLOBL ·atanhtabh2075<> + 0(SB), RODATA, $16 TEXT ·atanhAsm(SB), NOSPLIT, $0-16 FMOVD x+0(FP), F0 MOVD $·atanhrodataL10<>+0(SB), R5 - WORD $0xB3CD0010 //lgdr %r1, %f0 + LGDR F0, R1 WORD $0xC0393FEF //iilf %r3,1072693247 BYTE $0xFF BYTE $0xFF @@ -128,7 +128,7 @@ L9: WORD $0xED405088 //adb %f4,.L12-.L10(%r5) BYTE $0x00 BYTE $0x1A - WORD $0xB3CD0044 //lgdr %r4, %f4 + LGDR F4, R4 SRAD $32, R4 FMOVD F4, F3 WORD $0xED305088 //sdb %f3,.L12-.L10(%r5) @@ -140,7 +140,7 @@ L9: BYTE $0x00 BYTE $0x55 SLD $32, R1, R1 - WORD $0xB3C10021 //ldgr %f2,%r1 + LDGR R1, F2 WFMADB V4, V2, V16, V4 SRAW $8, R2, R1 WFMADB V4, V5, V6, V5 diff --git a/src/math/cbrt_s390x.s b/src/math/cbrt_s390x.s index 85a2fcb576c79..d79b48fc79fd2 100644 --- a/src/math/cbrt_s390x.s +++ b/src/math/cbrt_s390x.s @@ -77,7 +77,7 @@ GLOBL ·cbrttab12067<> + 0(SB), RODATA, $128 TEXT ·cbrtAsm(SB), NOSPLIT, $0-16 FMOVD x+0(FP), F0 MOVD $·cbrtrodataL9<>+0(SB), R9 - WORD $0xB3CD0020 //lgdr %r2, %f0 + LGDR F0, R2 WORD $0xC039000F //iilf %r3,1048575 BYTE $0xFF BYTE $0xFF @@ -103,7 +103,7 @@ L2: BYTE $0x00 BYTE $0x1C MOVH $0x200, R4 - WORD $0xB3CD0022 //lgdr %r2, %f2 + LGDR F2, R2 SRAD $32, R2 L4: WORD $0xEC3239BE //risbg %r3,%r2,57,128+62,64-25 @@ -134,7 +134,7 @@ L4: ADDW R4, R1 SLW $16, R1, R1 SLD $32, R1, R1 - WORD $0xB3C10021 //ldgr %f2,%r1 + LDGR R1, F2 WFMDB V2, V2, V4 WFMDB V4, V0, V6 WFMSDB V4, V6, V2, V4 diff --git a/src/math/erf_s390x.s b/src/math/erf_s390x.s index 5b62bdad76975..5be5d4de16aa4 100644 --- a/src/math/erf_s390x.s +++ b/src/math/erf_s390x.s @@ -100,7 +100,7 @@ GLOBL ·erftab12067<> + 0(SB), RODATA, $16 TEXT ·erfAsm(SB), NOSPLIT, $0-16 FMOVD x+0(FP), F0 MOVD $·erfrodataL13<>+0(SB), R5 - WORD $0xB3CD0010 //lgdr %r1, %f0 + LGDR F0, R1 FMOVD F0, F6 SRAD $48, R1 MOVH $16383, R3 @@ -205,7 +205,7 @@ L9: FMOVD 256(R5), F4 WFMADB V1, V4, V3, V4 FDIV F6, F2 - WORD $0xB3CD0014 //lgdr %r1, %f4 + LGDR F4, R1 FSUB F3, F4 FMOVD 248(R5), F6 WFMSDB V4, V6, V1, V4 @@ -230,7 +230,7 @@ L9: BYTE $0x59 MOVD $·erftab2066<>+0(SB), R1 FMOVD 192(R5), F1 - WORD $0xB3C10033 //ldgr %f3,%r3 + LDGR R3, F3 WORD $0xED221000 //madb %f2,%f2,0(%r2,%r1) BYTE $0x20 BYTE $0x1E diff --git a/src/math/erfc_s390x.s b/src/math/erfc_s390x.s index 57710b254b38e..0cb606d6de7db 100644 --- a/src/math/erfc_s390x.s +++ b/src/math/erfc_s390x.s @@ -219,7 +219,7 @@ L9: WFMADB V0, V5, V3, V5 WFMADB V6, V7, V2, V7 L11: - WORD $0xB3CD0065 //lgdr %r6, %f5 + LGDR F5, R6 WFSDB V0, V0, V2 WORD $0xED509298 //sdb %f5,.L55-.L38(%r9) BYTE $0x00 @@ -253,7 +253,7 @@ L11: BYTE $0x30 BYTE $0x59 WFMADB V4, V0, V2, V4 - WORD $0xB3C10024 //ldgr %f2,%r4 + LDGR R4, F2 FMADD F4, F2, F2 MOVW R2, R6 CMPBLE R6, $0, L20 @@ -504,7 +504,7 @@ L37: CMPBGT R6, R7, L24 WORD $0xA5400010 //iihh %r4,16 - WORD $0xB3C10024 //ldgr %f2,%r4 + LDGR R4, F2 FMUL F2, F2 BR L1 L23: @@ -521,7 +521,7 @@ L18: CMPBGT R6, R7, L25 WORD $0xA5408010 //iihh %r4,32784 FMOVD 568(R9), F2 - WORD $0xB3C10004 //ldgr %f0,%r4 + LDGR R4, F0 FMADD F2, F0, F2 BR L1 L25: diff --git a/src/math/exp_s390x.s b/src/math/exp_s390x.s index 613ec24136491..cef1ce7684815 100644 --- a/src/math/exp_s390x.s +++ b/src/math/exp_s390x.s @@ -84,7 +84,7 @@ L2: FMOVD 32(R5), F4 FMUL F0, F0 WFMADB V2, V4, V1, V4 - WORD $0xB3CD0016 //lgdr %r1,%f6 + LGDR F6, R1 FMOVD 24(R5), F1 WFMADB V2, V3, V1, V3 FMOVD 16(R5), F1 @@ -100,7 +100,7 @@ L2: FMADD F4, F2, F2 SLD $48, R1, R2 WFMADB V2, V0, V4, V2 - WORD $0xB3C10002 //ldgr %f0,%r2 + LDGR R2, F0 FMADD F0, F2, F0 FMOVD F0, ret+8(FP) RET @@ -135,7 +135,7 @@ L6: FMUL F6, F6 WFMADB V4, V1, V5, V1 FMOVD 48(R5), F7 - WORD $0xB3CD0013 //lgdr %r1,%f3 + LGDR F3, R1 FMOVD 24(R5), F5 WFMADB V4, V7, V5, V7 FMOVD 16(R5), F5 @@ -157,7 +157,7 @@ L6: WORD $0xEC21000F //risbgn %r2,%r1,64-64+0,64-64+0+16-1,64-0-16 BYTE $0x30 BYTE $0x59 - WORD $0xB3C10002 //ldgr %f0,%r2 + LDGR R2, F0 FMADD F0, F4, F0 MOVD $·expx4ff<>+0(SB), R3 FMOVD 0(R3), F2 @@ -173,7 +173,7 @@ L21: WORD $0xEC21000F //risbgn %r2,%r1,64-64+0,64-64+0+16-1,64-0-16 BYTE $0x30 BYTE $0x59 - WORD $0xB3C10002 //ldgr %f0,%r2 + LDGR R2, F0 FMADD F0, F4, F0 MOVD $·expx2ff<>+0(SB), R3 FMOVD 0(R3), F2 diff --git a/src/math/expm1_s390x.s b/src/math/expm1_s390x.s index 22e5eb16a9049..c7c793b982b95 100644 --- a/src/math/expm1_s390x.s +++ b/src/math/expm1_s390x.s @@ -89,7 +89,7 @@ L2: FMADD F2, F0, F6 WFMADB V0, V5, V3, V5 WFMDB V0, V0, V2 - WORD $0xB3CD0011 //lgdr %r1,%f1 + LGDR F1, R1 WFMADB V6, V2, V5, V6 FMOVD 40(R5), F3 FMOVD 32(R5), F5 @@ -108,7 +108,7 @@ L2: FMADD F4, F0, F0 SLD $48, R1, R2 WFMSDB V2, V0, V4, V0 - WORD $0xB3C10042 //ldgr %f4,%r2 + LDGR R2, F4 WORD $0xB3130000 //lcdbr %f0,%f0 FSUB F4, F6 WFMSDB V0, V4, V6, V0 @@ -155,7 +155,7 @@ L6: WFMADB V1, V16, V3, V1 FMOVD 16(R5), F6 FMADD F4, F1, F6 - WORD $0xB3CD0015 //lgdr %r1,%f5 + LGDR F5, R1 WORD $0xB3130066 //lcdbr %f6,%f6 WORD $0xEC3139BC //risbg %r3,%r1,57,128+60,3 BYTE $0x03 @@ -171,7 +171,7 @@ L6: WORD $0xEC21000F //risbgn %r2,%r1,64-64+0,64-64+0+16-1,64-0-16 BYTE $0x30 BYTE $0x59 - WORD $0xB3C10002 //ldgr %f0,%r2 + LDGR R2, F0 FMADD F0, F4, F0 MOVD $·expm1x4ff<>+0(SB), R3 FMOVD 0(R5), F4 @@ -189,7 +189,7 @@ L21: WORD $0xEC21000F //risbgn %r2,%r1,64-64+0,64-64+0+16-1,64-0-16 BYTE $0x30 BYTE $0x59 - WORD $0xB3C10002 //ldgr %f0,%r2 + LDGR R2, F0 FMADD F0, F4, F0 MOVD $·expm1x2ff<>+0(SB), R3 FMOVD 0(R5), F4 diff --git a/src/math/log1p_s390x.s b/src/math/log1p_s390x.s index c7e986033f90c..ba4933d5b0cb8 100644 --- a/src/math/log1p_s390x.s +++ b/src/math/log1p_s390x.s @@ -96,7 +96,7 @@ TEXT ·log1pAsm(SB), NOSPLIT, $0-16 MOVD $·log1pc5<>+0(SB), R1 VLEG $0, 0(R1), V16 MOVD R2, R5 - WORD $0xB3CD0034 //lgdr %r3,%f4 + LGDR F4, R3 WORD $0xC0190006 //iilf %r1,425983 BYTE $0x7F BYTE $0xFF @@ -118,7 +118,7 @@ TEXT ·log1pAsm(SB), NOSPLIT, $0-16 MOVD $·log1pxzero<>+0(SB), R1 FMOVD 0(R1), F2 BVS LEXITTAGlog1p - WORD $0xB3130044 + WORD $0xB3130044 // lcdbr %f4,%f4 WFCEDBS V2, V4, V6 BEQ L9 WFCHDBS V4, V2, V2 @@ -129,11 +129,11 @@ TEXT ·log1pAsm(SB), NOSPLIT, $0-16 RET L8: - WORD $0xB3C10022 //ldgr %f2,%r2 + LDGR R2, F2 FSUB F4, F3 FMADD F2, F4, F1 MOVD $·log1pc4<>+0(SB), R2 - WORD $0xB3130041 + WORD $0xB3130041 // lcdbr %f4,%f1 FMOVD 0(R2), F7 FSUB F3, F0 MOVD $·log1pc3<>+0(SB), R2 @@ -164,7 +164,7 @@ L8: FMOVD 0(R3), F2 WFMADB V0, V6, V1, V0 MOVD $·log1pyout<>+0(SB), R1 - WORD $0xB3C10065 //ldgr %f6,%r5 + LDGR R5, F6 FMOVD 0(R1), F4 WFMSDB V2, V6, V4, V2 MOVD $·log1pxl2<>+0(SB), R1 diff --git a/src/math/log_s390x.s b/src/math/log_s390x.s index 3e24ca79bb6f5..7bcfdfcffa727 100644 --- a/src/math/log_s390x.s +++ b/src/math/log_s390x.s @@ -63,7 +63,7 @@ TEXT ·logAsm(SB), NOSPLIT, $0-16 FMOVD x+0(FP), F0 MOVD $·logrodataL21<>+0(SB), R9 MOVH $0x8006, R4 - WORD $0xB3CD0010 //lgdr %r1,%f0 + LGDR F0, R1 MOVD $0x3FF0000000000000, R6 SRAD $48, R1, R1 MOVD $0x40F03E8000000000, R8 @@ -91,7 +91,7 @@ L7: BLEU L3 L15: FMUL F2, F0 - WORD $0xB3CD0010 //lgdr %r1,%f0 + LGDR F0, R1 SRAD $48, R1, R1 SUBW R1, R0, R2 SUBW R1, R12, R3 @@ -114,7 +114,7 @@ L2: MOVH $0x7FEF, R1 CMPW R5, R1 BGT L1 - WORD $0xB3C10026 //ldgr %f2,%r6 + LDGR R6, F2 FMUL F2, F0 WORD $0xEC4439BB //risbg %r4,%r4,57,128+59,3 BYTE $0x03 @@ -148,14 +148,14 @@ L2: WFMADB V6, V4, V1, V4 FMOVD 8(R4), F1 WFMADB V0, V2, V4, V2 - WORD $0xB3C10048 //ldgr %f4,%r8 + LDGR R8, F4 WFMADB V6, V2, V0, V2 WORD $0xED401000 //msdb %f1,%f4,0(%r1) BYTE $0x10 BYTE $0x1F MOVD ·logxl2<>+0(SB), R1 WORD $0xB3130001 //lcdbr %f0,%f1 - WORD $0xB3C10041 //ldgr %f4,%r1 + LDGR R1, F4 WFMADB V0, V4, V2, V0 L1: FMOVD F0, ret+8(FP) diff --git a/src/math/pow_s390x.s b/src/math/pow_s390x.s index fd1961756161f..754b119e24918 100644 --- a/src/math/pow_s390x.s +++ b/src/math/pow_s390x.s @@ -297,7 +297,7 @@ Normal: FMOVD x+0(FP), F0 FMOVD y+8(FP), F2 MOVD $·powrodataL51<>+0(SB), R9 - WORD $0xB3CD0030 //lgdr %r3,%f0 + LGDR F0, R3 WORD $0xC0298009 //iilf %r2,2148095317 BYTE $0x55 BYTE $0x55 @@ -340,7 +340,7 @@ L2: BYTE $0x24 FMOVD 0(R2), F6 FSUBS F1, F3 - WORD $0xB3C10018 //ldgr %f1,%r8 + LDGR R8, F1 WFMSDB V4, V1, V6, V4 FMOVD 152(R9), F6 WFMDB V4, V4, V7 @@ -387,7 +387,7 @@ L2: WFMSDB V2, V3, V5, V3 VLEG $0, 48(R9), V18 WFADB V3, V5, V6 - WORD $0xB3CD0023 //lgdr %r2,%f3 + LGDR F3, R2 WFMSDB V2, V16, V6, V16 FMOVD 40(R9), F1 WFMADB V2, V4, V16, V4 @@ -410,8 +410,8 @@ L2: BYTE $0x30 BYTE $0x59 WFMADB V4, V1, V3, V4 - WORD $0xB3CD0026 //lgdr %r2,%f6 - WORD $0xB3C10015 //ldgr %f1,%r5 + LGDR F6, R2 + LDGR R5, F1 SRAD $48, R2, R2 FMADD F1, F4, F1 RLL $16, R2, R2 @@ -452,7 +452,7 @@ L11: WORD $0xEC1520BF //risbgn %r1,%r5,64-32,128+63,64+0+32 BYTE $0x60 BYTE $0x59 - WORD $0xB3CD0026 //lgdr %r2,%f6 + LGDR F6, R2 MOVD $powiadd<>+0(SB), R3 WORD $0xEC223CBC //risbg %r2,%r2,60,128+60,64-60 BYTE $0x04 @@ -461,7 +461,7 @@ L11: WORD $0xEC51001F //risbgn %r5,%r1,64-64+0,64-64+0+32-1,64-0-32 BYTE $0x20 BYTE $0x59 - WORD $0xB3C10015 //ldgr %f1,%r5 + LDGR R5, F1 FMADD F1, F4, F1 MOVD $powxscale<>+0(SB), R1 WORD $0xED121000 //mdb %f1,0(%r2,%r1) @@ -486,7 +486,7 @@ L3: WORD $0xC0298009 //iilf %r2,2148095317 BYTE $0x55 BYTE $0x55 - WORD $0xB3CD0034 //lgdr %r3,%f4 + LGDR F4, R3 WORD $0xEC3320BF //risbgn %r3,%r3,64-32,128+63,64+0+32 BYTE $0x60 BYTE $0x59 @@ -566,11 +566,11 @@ L47: BVS L49 L16: MOVD ·pow_xnan<>+0(SB), R1 - WORD $0xB3C10001 //ldgr %f0,%r1 + LDGR R1, F0 WFMDB V4, V0, V1 BR L1 L48: - WORD $0xB3CD0030 //lgdr %r3,%f0 + LGDR F0, R3 WORD $0xEC1320BF //risbgn %r1,%r3,64-32,128+63,64+0+32 BYTE $0x60 BYTE $0x59 diff --git a/src/math/tan_s390x.s b/src/math/tan_s390x.s index 7b05ba053e3e0..b6e2295874e6e 100644 --- a/src/math/tan_s390x.s +++ b/src/math/tan_s390x.s @@ -68,7 +68,7 @@ L2: WFMADB V4, V3, V2, V4 FMUL F2, F2 VLEG $0, 48(R5), V18 - WORD $0xB3CD0016 //lgdr %r1,%f6 + LGDR F6, R1 FMOVD 40(R5), F5 FMOVD 32(R5), F3 FMADD F1, F2, F3 @@ -82,7 +82,7 @@ L2: WFLCDB V4, V16 WFMADB V2, V5, V18, V5 WFMADB V1, V0, V7, V0 - WORD $0xA7110001 //tmll %r1,1 + TMLL R1, $1 WFMADB V1, V5, V3, V1 BNE L12 WFDDB V0, V1, V0 From 6570ea3c60c9f3abf3051513f736dd5a972e25e2 Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Sun, 19 Aug 2018 15:42:27 +0100 Subject: [PATCH 0024/1663] container/heap: clarify that Remove returns the removed element Change-Id: I63b59c1ca8265e9af7eb3f9210ee1d17925de891 Reviewed-on: https://go-review.googlesource.com/129779 Reviewed-by: Brad Fitzpatrick --- src/container/heap/heap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/container/heap/heap.go b/src/container/heap/heap.go index 67b5efcac7e37..1ed0da8e6a653 100644 --- a/src/container/heap/heap.go +++ b/src/container/heap/heap.go @@ -66,8 +66,8 @@ func Pop(h Interface) interface{} { return h.Pop() } -// Remove removes the element at index i from the heap. -// The complexity is O(log(n)) where n = h.Len(). +// Remove removes the element at index i from the heap and returns +// the element. The complexity is O(log(n)) where n = h.Len(). // func Remove(h Interface, i int) interface{} { n := h.Len() - 1 From def3280eb4e4bc7fb058f98fa2993cb077db3f95 Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Tue, 24 Jul 2018 15:07:01 -0700 Subject: [PATCH 0025/1663] cmd/dist: support windows/arm Updates #26148 Change-Id: I407481f9c0f8e3565dcfcbbc53e5aa7427d74680 Reviewed-on: https://go-review.googlesource.com/125646 Reviewed-by: Brad Fitzpatrick --- src/cmd/dist/build.go | 1 + src/cmd/dist/sys_windows.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index eed9866ce478e..06adccd9a4a7b 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -1422,6 +1422,7 @@ var cgoEnabled = map[string]bool{ "solaris/amd64": true, "windows/386": true, "windows/amd64": true, + "windows/arm": false, } func needCC() bool { diff --git a/src/cmd/dist/sys_windows.go b/src/cmd/dist/sys_windows.go index 216dc017982fe..2f6a1b0dceb6f 100644 --- a/src/cmd/dist/sys_windows.go +++ b/src/cmd/dist/sys_windows.go @@ -32,6 +32,7 @@ type systeminfo struct { const ( PROCESSOR_ARCHITECTURE_AMD64 = 9 PROCESSOR_ARCHITECTURE_INTEL = 0 + PROCESSOR_ARCHITECTURE_ARM = 5 ) var sysinfo systeminfo @@ -43,6 +44,8 @@ func sysinit() { gohostarch = "amd64" case PROCESSOR_ARCHITECTURE_INTEL: gohostarch = "386" + case PROCESSOR_ARCHITECTURE_ARM: + gohostarch = "arm" default: fatalf("unknown processor architecture") } From 18034e6b9f0f623335e6358e0a4634a4eec04dd1 Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Tue, 24 Jul 2018 15:17:54 -0700 Subject: [PATCH 0026/1663] debug/pe: support windows/arm Enable 'go tool objdump' to disassemble windows/arm images. Updates #26148 Change-Id: I7d11226f01d92288061f8e25980334b9bd82c41f Reviewed-on: https://go-review.googlesource.com/125649 Reviewed-by: Brad Fitzpatrick --- src/debug/pe/file.go | 2 +- src/debug/pe/pe.go | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/debug/pe/file.go b/src/debug/pe/file.go index 2f5efae4e6717..1c308b3dc3b0c 100644 --- a/src/debug/pe/file.go +++ b/src/debug/pe/file.go @@ -91,7 +91,7 @@ func NewFile(r io.ReaderAt) (*File, error) { return nil, err } switch f.FileHeader.Machine { - case IMAGE_FILE_MACHINE_UNKNOWN, IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_I386: + case IMAGE_FILE_MACHINE_UNKNOWN, IMAGE_FILE_MACHINE_ARMNT, IMAGE_FILE_MACHINE_AMD64, IMAGE_FILE_MACHINE_I386: default: return nil, fmt.Errorf("Unrecognised COFF file header machine value of 0x%x.", f.FileHeader.Machine) } diff --git a/src/debug/pe/pe.go b/src/debug/pe/pe.go index e933ae1c2aa66..3f8099dfab18c 100644 --- a/src/debug/pe/pe.go +++ b/src/debug/pe/pe.go @@ -91,6 +91,7 @@ const ( IMAGE_FILE_MACHINE_AM33 = 0x1d3 IMAGE_FILE_MACHINE_AMD64 = 0x8664 IMAGE_FILE_MACHINE_ARM = 0x1c0 + IMAGE_FILE_MACHINE_ARMNT = 0x1c4 IMAGE_FILE_MACHINE_ARM64 = 0xaa64 IMAGE_FILE_MACHINE_EBC = 0xebc IMAGE_FILE_MACHINE_I386 = 0x14c From 723479bc30f998f29ecbba7caea118ac4e2c9afd Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Fri, 3 Aug 2018 02:08:43 +0200 Subject: [PATCH 0027/1663] cmd/go: add graphviz output to graph command This allows to quickly visual inspect dependencies. Change-Id: Ice326ec69d7d57720f608b04cdf3ece153b8c5f1 Reviewed-on: https://go-review.googlesource.com/127599 Run-TryBot: Giovanni Bajo Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/go/internal/modcmd/graph.go | 33 ++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/cmd/go/internal/modcmd/graph.go b/src/cmd/go/internal/modcmd/graph.go index 5825c6d8ca8e0..b123454d60988 100644 --- a/src/cmd/go/internal/modcmd/graph.go +++ b/src/cmd/go/internal/modcmd/graph.go @@ -18,15 +18,25 @@ import ( ) var cmdGraph = &base.Command{ - UsageLine: "go mod graph", + UsageLine: "go mod graph [-dot]", Short: "print module requirement graph", Long: ` Graph prints the module requirement graph (with replacements applied) in text form. Each line in the output has two space-separated fields: a module and one of its requirements. Each module is identified as a string of the form path@version, except for the main module, which has no @version suffix. + +The -dot flag generates the output in graphviz format that can be used +with a tool like dot to visually render the dependency graph. `, - Run: runGraph, +} + +var ( + graphDot = cmdGraph.Flag.Bool("dot", false, "") +) + +func init() { + cmdGraph.Run = runGraph // break init cycle } func runGraph(cmd *base.Command, args []string) { @@ -51,10 +61,21 @@ func runGraph(cmd *base.Command, args []string) { work.Add(modload.Target) work.Do(1, func(item interface{}) { m := item.(module.Version) + if *graphDot { + if m.Version == "" { + out = append(out, "\""+m.Path+"\" [label=<"+m.Path+">]\n") + } else { + out = append(out, "\""+m.Path+"\" [label=<"+m.Path+"
"+m.Version+">]\n") + } + } list, _ := reqs.Required(m) for _, r := range list { work.Add(r) - out = append(out, format(m)+" "+format(r)+"\n") + if *graphDot { + out = append(out, "\""+m.Path+"\" -> \""+r.Path+"\"\n") + } else { + out = append(out, format(m)+" "+format(r)+"\n") + } } if m == modload.Target { deps = len(out) @@ -66,8 +87,14 @@ func runGraph(cmd *base.Command, args []string) { }) w := bufio.NewWriter(os.Stdout) + if *graphDot { + w.WriteString("digraph deps {\nrankdir=LR\n") + } for _, line := range out { w.WriteString(line) } + if *graphDot { + w.WriteString("}\n") + } w.Flush() } From 3578918b6614effaeaa581687d810b74e342e0f8 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 9 Aug 2018 23:47:37 -0400 Subject: [PATCH 0028/1663] runtime: replace manually managed G dequeues with a type There are two manually managed G dequeues. Abstract these both into a shared gQueue type. This also introduces a gList type, which we'll use to replace several manually-managed G lists in follow-up CLs. This makes the code more readable and maintainable. gcFlushBgCredit in particular becomes much easier to follow. It also makes it easier to introduce more G queues in the future. Finally, the gList type clearly distinguishes between lists of Gs and individual Gs; currently both are represented by a *g, which can easily lead to confusion and bugs. Change-Id: Ic7798841b405d311fc8b6aa5a958ffa4c7993c6c Reviewed-on: https://go-review.googlesource.com/129396 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/mgc.go | 4 +- src/runtime/mgcmark.go | 48 ++++---------- src/runtime/proc.go | 141 ++++++++++++++++++++++++++++++++-------- src/runtime/runtime2.go | 3 +- 4 files changed, 128 insertions(+), 68 deletions(-) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 6a3219de73d33..7d4ba9f9cd70b 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -1023,8 +1023,8 @@ var work struct { // there was neither enough credit to steal or enough work to // do. assistQueue struct { - lock mutex - head, tail guintptr + lock mutex + q gQueue } // sweepWaiters is a list of blocked goroutines to wake when diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index e8cfdce4fc1b3..7850f86bb2968 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -602,9 +602,7 @@ func gcAssistAlloc1(gp *g, scanWork int64) { // new assists from going to sleep after this point. func gcWakeAllAssists() { lock(&work.assistQueue.lock) - injectglist(work.assistQueue.head.ptr()) - work.assistQueue.head.set(nil) - work.assistQueue.tail.set(nil) + injectglist(work.assistQueue.q.popList().head.ptr()) unlock(&work.assistQueue.lock) } @@ -625,24 +623,17 @@ func gcParkAssist() bool { } gp := getg() - oldHead, oldTail := work.assistQueue.head, work.assistQueue.tail - if oldHead == 0 { - work.assistQueue.head.set(gp) - } else { - oldTail.ptr().schedlink.set(gp) - } - work.assistQueue.tail.set(gp) - gp.schedlink.set(nil) + oldList := work.assistQueue.q + work.assistQueue.q.pushBack(gp) // Recheck for background credit now that this G is in // the queue, but can still back out. This avoids a // race in case background marking has flushed more // credit since we checked above. if atomic.Loadint64(&gcController.bgScanCredit) > 0 { - work.assistQueue.head = oldHead - work.assistQueue.tail = oldTail - if oldTail != 0 { - oldTail.ptr().schedlink.set(nil) + work.assistQueue.q = oldList + if oldList.tail != 0 { + oldList.tail.ptr().schedlink.set(nil) } unlock(&work.assistQueue.lock) return false @@ -663,7 +654,7 @@ func gcParkAssist() bool { // //go:nowritebarrierrec func gcFlushBgCredit(scanWork int64) { - if work.assistQueue.head == 0 { + if work.assistQueue.q.empty() { // Fast path; there are no blocked assists. There's a // small window here where an assist may add itself to // the blocked queue and park. If that happens, we'll @@ -675,23 +666,21 @@ func gcFlushBgCredit(scanWork int64) { scanBytes := int64(float64(scanWork) * gcController.assistBytesPerWork) lock(&work.assistQueue.lock) - gp := work.assistQueue.head.ptr() - for gp != nil && scanBytes > 0 { + for !work.assistQueue.q.empty() && scanBytes > 0 { + gp := work.assistQueue.q.pop() // Note that gp.gcAssistBytes is negative because gp // is in debt. Think carefully about the signs below. if scanBytes+gp.gcAssistBytes >= 0 { // Satisfy this entire assist debt. scanBytes += gp.gcAssistBytes gp.gcAssistBytes = 0 - xgp := gp - gp = gp.schedlink.ptr() - // It's important that we *not* put xgp in + // It's important that we *not* put gp in // runnext. Otherwise, it's possible for user // code to exploit the GC worker's high // scheduler priority to get itself always run // before other goroutines and always in the // fresh quantum started by GC. - ready(xgp, 0, false) + ready(gp, 0, false) } else { // Partially satisfy this assist. gp.gcAssistBytes += scanBytes @@ -700,23 +689,10 @@ func gcFlushBgCredit(scanWork int64) { // back of the queue so that large assists // can't clog up the assist queue and // substantially delay small assists. - xgp := gp - gp = gp.schedlink.ptr() - if gp == nil { - // gp is the only assist in the queue. - gp = xgp - } else { - xgp.schedlink = 0 - work.assistQueue.tail.ptr().schedlink.set(xgp) - work.assistQueue.tail.set(xgp) - } + work.assistQueue.q.pushBack(gp) break } } - work.assistQueue.head.set(gp) - if gp == nil { - work.assistQueue.tail.set(nil) - } if scanBytes > 0 { // Convert from scan bytes back to work. diff --git a/src/runtime/proc.go b/src/runtime/proc.go index f82014eb92f08..fbb1ce1750698 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -4667,13 +4667,7 @@ func mget() *m { // May run during STW, so write barriers are not allowed. //go:nowritebarrierrec func globrunqput(gp *g) { - gp.schedlink = 0 - if sched.runqtail != 0 { - sched.runqtail.ptr().schedlink.set(gp) - } else { - sched.runqhead.set(gp) - } - sched.runqtail.set(gp) + sched.runq.pushBack(gp) sched.runqsize++ } @@ -4682,25 +4676,17 @@ func globrunqput(gp *g) { // May run during STW, so write barriers are not allowed. //go:nowritebarrierrec func globrunqputhead(gp *g) { - gp.schedlink = sched.runqhead - sched.runqhead.set(gp) - if sched.runqtail == 0 { - sched.runqtail.set(gp) - } + sched.runq.push(gp) sched.runqsize++ } // Put a batch of runnable goroutines on the global runnable queue. +// This clears *batch. // Sched must be locked. -func globrunqputbatch(ghead *g, gtail *g, n int32) { - gtail.schedlink = 0 - if sched.runqtail != 0 { - sched.runqtail.ptr().schedlink.set(ghead) - } else { - sched.runqhead.set(ghead) - } - sched.runqtail.set(gtail) +func globrunqputbatch(batch *gQueue, n int32) { + sched.runq.pushBackAll(*batch) sched.runqsize += n + *batch = gQueue{} } // Try get a batch of G's from the global runnable queue. @@ -4722,16 +4708,11 @@ func globrunqget(_p_ *p, max int32) *g { } sched.runqsize -= n - if sched.runqsize == 0 { - sched.runqtail = 0 - } - gp := sched.runqhead.ptr() - sched.runqhead = gp.schedlink + gp := sched.runq.pop() n-- for ; n > 0; n-- { - gp1 := sched.runqhead.ptr() - sched.runqhead = gp1.schedlink + gp1 := sched.runq.pop() runqput(_p_, gp1, false) } return gp @@ -4859,10 +4840,13 @@ func runqputslow(_p_ *p, gp *g, h, t uint32) bool { for i := uint32(0); i < n; i++ { batch[i].schedlink.set(batch[i+1]) } + var q gQueue + q.head.set(batch[0]) + q.tail.set(batch[n]) // Now put the batch on global queue. lock(&sched.lock) - globrunqputbatch(batch[0], batch[n], int32(n+1)) + globrunqputbatch(&q, int32(n+1)) unlock(&sched.lock) return true } @@ -4974,6 +4958,107 @@ func runqsteal(_p_, p2 *p, stealRunNextG bool) *g { return gp } +// A gQueue is a dequeue of Gs linked through g.schedlink. A G can only +// be on one gQueue or gList at a time. +type gQueue struct { + head guintptr + tail guintptr +} + +// empty returns true if q is empty. +func (q *gQueue) empty() bool { + return q.head == 0 +} + +// push adds gp to the head of q. +func (q *gQueue) push(gp *g) { + gp.schedlink = q.head + q.head.set(gp) + if q.tail == 0 { + q.tail.set(gp) + } +} + +// pushBack adds gp to the tail of q. +func (q *gQueue) pushBack(gp *g) { + gp.schedlink = 0 + if q.tail != 0 { + q.tail.ptr().schedlink.set(gp) + } else { + q.head.set(gp) + } + q.tail.set(gp) +} + +// pushBackAll adds all Gs in l2 to the tail of q. After this q2 must +// not be used. +func (q *gQueue) pushBackAll(q2 gQueue) { + if q2.tail == 0 { + return + } + q2.tail.ptr().schedlink = 0 + if q.tail != 0 { + q.tail.ptr().schedlink = q2.head + } else { + q.head = q2.head + } + q.tail = q2.tail +} + +// pop removes and returns the head of queue q. It returns nil if +// q is empty. +func (q *gQueue) pop() *g { + gp := q.head.ptr() + if gp != nil { + q.head = gp.schedlink + if q.head == 0 { + q.tail = 0 + } + } + return gp +} + +// popList takes all Gs in q and returns them as a gList. +func (q *gQueue) popList() gList { + stack := gList{q.head} + *q = gQueue{} + return stack +} + +// A gList is a list of Gs linked through g.schedlink. A G can only be +// on one gQueue or gList at a time. +type gList struct { + head guintptr +} + +// empty returns true if l is empty. +func (l *gList) empty() bool { + return l.head == 0 +} + +// push adds gp to the head of l. +func (l *gList) push(gp *g) { + gp.schedlink = l.head + l.head.set(gp) +} + +// pushAll prepends all Gs in q to l. +func (l *gList) pushAll(q gQueue) { + if !q.empty() { + q.tail.ptr().schedlink = l.head + l.head = q.head + } +} + +// pop removes and returns the head of l. If l is empty, it returns nil. +func (l *gList) pop() *g { + gp := l.head.ptr() + if gp != nil { + l.head = gp.schedlink + } + return gp +} + //go:linkname setMaxThreads runtime/debug.setMaxThreads func setMaxThreads(in int) (out int) { lock(&sched.lock) diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index ad47d1275ebc4..5bd37e49bec5a 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -574,8 +574,7 @@ type schedt struct { nmspinning uint32 // See "Worker thread parking/unparking" comment in proc.go. // Global runnable queue. - runqhead guintptr - runqtail guintptr + runq gQueue runqsize int32 // Global cache of dead G's. From de990545c3ce65926491c123bb2536168cd21cf3 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 10 Aug 2018 00:09:00 -0400 Subject: [PATCH 0029/1663] runtime: use gList in netpoll netpoll is perhaps one of the most confusing uses of G lists currently since it passes around many lists as bare *g values right now. Switching to gList makes it much clearer what's an individual g and what's a list. Change-Id: I8d8993c4967c5bae049c7a094aad3a657928ba6c Reviewed-on: https://go-review.googlesource.com/129397 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/netpoll.go | 20 +++++++++----------- src/runtime/netpoll_epoll.go | 12 ++++++------ src/runtime/netpoll_fake.go | 4 ++-- src/runtime/netpoll_kqueue.go | 12 ++++++------ src/runtime/netpoll_solaris.go | 12 ++++++------ src/runtime/netpoll_stub.go | 4 ++-- src/runtime/netpoll_windows.go | 22 +++++++++++----------- src/runtime/proc.go | 29 +++++++++++++++-------------- 8 files changed, 57 insertions(+), 58 deletions(-) diff --git a/src/runtime/netpoll.go b/src/runtime/netpoll.go index c8fb95d3aaf5d..f9c422650a164 100644 --- a/src/runtime/netpoll.go +++ b/src/runtime/netpoll.go @@ -289,24 +289,22 @@ func poll_runtime_pollUnblock(pd *pollDesc) { } } -// make pd ready, newly runnable goroutines (if any) are returned in rg/wg +// make pd ready, newly runnable goroutines (if any) are added to toRun. // May run during STW, so write barriers are not allowed. //go:nowritebarrier -func netpollready(gpp *guintptr, pd *pollDesc, mode int32) { - var rg, wg guintptr +func netpollready(toRun *gList, pd *pollDesc, mode int32) { + var rg, wg *g if mode == 'r' || mode == 'r'+'w' { - rg.set(netpollunblock(pd, 'r', true)) + rg = netpollunblock(pd, 'r', true) } if mode == 'w' || mode == 'r'+'w' { - wg.set(netpollunblock(pd, 'w', true)) + wg = netpollunblock(pd, 'w', true) } - if rg != 0 { - rg.ptr().schedlink = *gpp - *gpp = rg + if rg != nil { + toRun.push(rg) } - if wg != 0 { - wg.ptr().schedlink = *gpp - *gpp = wg + if wg != nil { + toRun.push(wg) } } diff --git a/src/runtime/netpoll_epoll.go b/src/runtime/netpoll_epoll.go index 1908220ebbd9b..f764d6ff7c886 100644 --- a/src/runtime/netpoll_epoll.go +++ b/src/runtime/netpoll_epoll.go @@ -58,9 +58,9 @@ func netpollarm(pd *pollDesc, mode int) { // polls for ready network connections // returns list of goroutines that become runnable -func netpoll(block bool) *g { +func netpoll(block bool) gList { if epfd == -1 { - return nil + return gList{} } waitms := int32(-1) if !block { @@ -76,7 +76,7 @@ retry: } goto retry } - var gp guintptr + var toRun gList for i := int32(0); i < n; i++ { ev := &events[i] if ev.events == 0 { @@ -92,11 +92,11 @@ retry: if mode != 0 { pd := *(**pollDesc)(unsafe.Pointer(&ev.data)) - netpollready(&gp, pd, mode) + netpollready(&toRun, pd, mode) } } - if block && gp == 0 { + if block && toRun.empty() { goto retry } - return gp.ptr() + return toRun } diff --git a/src/runtime/netpoll_fake.go b/src/runtime/netpoll_fake.go index aab18dc8468cd..5b1a63a8787d0 100644 --- a/src/runtime/netpoll_fake.go +++ b/src/runtime/netpoll_fake.go @@ -27,6 +27,6 @@ func netpollclose(fd uintptr) int32 { func netpollarm(pd *pollDesc, mode int) { } -func netpoll(block bool) *g { - return nil +func netpoll(block bool) gList { + return gList{} } diff --git a/src/runtime/netpoll_kqueue.go b/src/runtime/netpoll_kqueue.go index 0f73bf385e48d..fdaa1cd80debd 100644 --- a/src/runtime/netpoll_kqueue.go +++ b/src/runtime/netpoll_kqueue.go @@ -59,9 +59,9 @@ func netpollarm(pd *pollDesc, mode int) { // Polls for ready network connections. // Returns list of goroutines that become runnable. -func netpoll(block bool) *g { +func netpoll(block bool) gList { if kq == -1 { - return nil + return gList{} } var tp *timespec var ts timespec @@ -78,7 +78,7 @@ retry: } goto retry } - var gp guintptr + var toRun gList for i := 0; i < int(n); i++ { ev := &events[i] var mode int32 @@ -102,11 +102,11 @@ retry: mode += 'w' } if mode != 0 { - netpollready(&gp, (*pollDesc)(unsafe.Pointer(ev.udata)), mode) + netpollready(&toRun, (*pollDesc)(unsafe.Pointer(ev.udata)), mode) } } - if block && gp == 0 { + if block && toRun.empty() { goto retry } - return gp.ptr() + return toRun } diff --git a/src/runtime/netpoll_solaris.go b/src/runtime/netpoll_solaris.go index 853e5f63e3bed..6bd484afaaec8 100644 --- a/src/runtime/netpoll_solaris.go +++ b/src/runtime/netpoll_solaris.go @@ -180,9 +180,9 @@ func netpollarm(pd *pollDesc, mode int) { // polls for ready network connections // returns list of goroutines that become runnable -func netpoll(block bool) *g { +func netpoll(block bool) gList { if portfd == -1 { - return nil + return gList{} } var wait *timespec @@ -202,7 +202,7 @@ retry: goto retry } - var gp guintptr + var toRun gList for i := 0; i < int(n); i++ { ev := &events[i] @@ -233,12 +233,12 @@ retry: } if mode != 0 { - netpollready(&gp, pd, mode) + netpollready(&toRun, pd, mode) } } - if block && gp == 0 { + if block && toRun.empty() { goto retry } - return gp.ptr() + return toRun } diff --git a/src/runtime/netpoll_stub.go b/src/runtime/netpoll_stub.go index a4d6b4608ac63..f585333579dab 100644 --- a/src/runtime/netpoll_stub.go +++ b/src/runtime/netpoll_stub.go @@ -10,10 +10,10 @@ var netpollWaiters uint32 // Polls for ready network connections. // Returns list of goroutines that become runnable. -func netpoll(block bool) (gp *g) { +func netpoll(block bool) gList { // Implementation for platforms that do not support // integrated network poller. - return + return gList{} } func netpollinited() bool { diff --git a/src/runtime/netpoll_windows.go b/src/runtime/netpoll_windows.go index 134071f5e3ca1..07ef15ce2f389 100644 --- a/src/runtime/netpoll_windows.go +++ b/src/runtime/netpoll_windows.go @@ -63,17 +63,17 @@ func netpollarm(pd *pollDesc, mode int) { // Polls for completed network IO. // Returns list of goroutines that become runnable. -func netpoll(block bool) *g { +func netpoll(block bool) gList { var entries [64]overlappedEntry var wait, qty, key, flags, n, i uint32 var errno int32 var op *net_op - var gp guintptr + var toRun gList mp := getg().m if iocphandle == _INVALID_HANDLE_VALUE { - return nil + return gList{} } wait = 0 if block { @@ -92,7 +92,7 @@ retry: mp.blocked = false errno = int32(getlasterror()) if !block && errno == _WAIT_TIMEOUT { - return nil + return gList{} } println("runtime: GetQueuedCompletionStatusEx failed (errno=", errno, ")") throw("runtime: netpoll failed") @@ -105,7 +105,7 @@ retry: if stdcall5(_WSAGetOverlappedResult, op.pd.fd, uintptr(unsafe.Pointer(op)), uintptr(unsafe.Pointer(&qty)), 0, uintptr(unsafe.Pointer(&flags))) == 0 { errno = int32(getlasterror()) } - handlecompletion(&gp, op, errno, qty) + handlecompletion(&toRun, op, errno, qty) } } else { op = nil @@ -118,7 +118,7 @@ retry: mp.blocked = false errno = int32(getlasterror()) if !block && errno == _WAIT_TIMEOUT { - return nil + return gList{} } if op == nil { println("runtime: GetQueuedCompletionStatus failed (errno=", errno, ")") @@ -127,15 +127,15 @@ retry: // dequeued failed IO packet, so report that } mp.blocked = false - handlecompletion(&gp, op, errno, qty) + handlecompletion(&toRun, op, errno, qty) } - if block && gp == 0 { + if block && toRun.empty() { goto retry } - return gp.ptr() + return toRun } -func handlecompletion(gpp *guintptr, op *net_op, errno int32, qty uint32) { +func handlecompletion(toRun *gList, op *net_op, errno int32, qty uint32) { if op == nil { println("runtime: GetQueuedCompletionStatus returned op == nil") throw("runtime: netpoll failed") @@ -147,5 +147,5 @@ func handlecompletion(gpp *guintptr, op *net_op, errno int32, qty uint32) { } op.errno = errno op.qty = qty - netpollready(gpp, op.pd, mode) + netpollready(toRun, op.pd, mode) } diff --git a/src/runtime/proc.go b/src/runtime/proc.go index fbb1ce1750698..2a780e49ee021 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -1148,8 +1148,8 @@ func startTheWorldWithSema(emitTraceEvent bool) int64 { _g_.m.locks++ // disable preemption because it can be holding p in a local var if netpollinited() { - gp := netpoll(false) // non-blocking - injectglist(gp) + list := netpoll(false) // non-blocking + injectglist(list.head.ptr()) } add := needaddgcproc() lock(&sched.lock) @@ -2312,9 +2312,9 @@ top: // not set lastpoll yet), this thread will do blocking netpoll below // anyway. if netpollinited() && atomic.Load(&netpollWaiters) > 0 && atomic.Load64(&sched.lastpoll) != 0 { - if gp := netpoll(false); gp != nil { // non-blocking - // netpoll returns list of goroutines linked by schedlink. - injectglist(gp.schedlink.ptr()) + if list := netpoll(false); !list.empty() { // non-blocking + gp := list.pop() + injectglist(list.head.ptr()) casgstatus(gp, _Gwaiting, _Grunnable) if trace.enabled { traceGoUnpark(gp, 0) @@ -2466,22 +2466,23 @@ stop: if _g_.m.spinning { throw("findrunnable: netpoll with spinning") } - gp := netpoll(true) // block until new work is available + list := netpoll(true) // block until new work is available atomic.Store64(&sched.lastpoll, uint64(nanotime())) - if gp != nil { + if !list.empty() { lock(&sched.lock) _p_ = pidleget() unlock(&sched.lock) if _p_ != nil { acquirep(_p_) - injectglist(gp.schedlink.ptr()) + gp := list.pop() + injectglist(list.head.ptr()) casgstatus(gp, _Gwaiting, _Grunnable) if trace.enabled { traceGoUnpark(gp, 0) } return gp, false } - injectglist(gp) + injectglist(list.head.ptr()) } } stopm() @@ -2501,8 +2502,8 @@ func pollWork() bool { return true } if netpollinited() && atomic.Load(&netpollWaiters) > 0 && sched.lastpoll != 0 { - if gp := netpoll(false); gp != nil { - injectglist(gp) + if list := netpoll(false); !list.empty() { + injectglist(list.head.ptr()) return true } } @@ -4387,8 +4388,8 @@ func sysmon() { now := nanotime() if netpollinited() && lastpoll != 0 && lastpoll+10*1000*1000 < now { atomic.Cas64(&sched.lastpoll, uint64(lastpoll), uint64(now)) - gp := netpoll(false) // non-blocking - returns list of goroutines - if gp != nil { + list := netpoll(false) // non-blocking - returns list of goroutines + if !list.empty() { // Need to decrement number of idle locked M's // (pretending that one more is running) before injectglist. // Otherwise it can lead to the following situation: @@ -4397,7 +4398,7 @@ func sysmon() { // observes that there is no work to do and no other running M's // and reports deadlock. incidlelocked(-1) - injectglist(gp) + injectglist(list.head.ptr()) incidlelocked(1) } } From 8e8cc9db0fe3c30852d4fc9ad82c9922bff7d26f Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 10 Aug 2018 10:19:03 -0400 Subject: [PATCH 0030/1663] runtime: use gList for gfree lists Change-Id: I3d21587e02264fe5da1cc38d98779facfa09b927 Reviewed-on: https://go-review.googlesource.com/129398 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/mgcmark.go | 25 ++++----- src/runtime/proc.go | 117 +++++++++++++++++++--------------------- src/runtime/runtime2.go | 16 +++--- 3 files changed, 77 insertions(+), 81 deletions(-) diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index 7850f86bb2968..d6ee7ff6fabe4 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -302,26 +302,27 @@ func markrootBlock(b0, n0 uintptr, ptrmask0 *uint8, gcw *gcWork, shard int) { //TODO go:nowritebarrier func markrootFreeGStacks() { // Take list of dead Gs with stacks. - lock(&sched.gflock) - list := sched.gfreeStack - sched.gfreeStack = nil - unlock(&sched.gflock) - if list == nil { + lock(&sched.gFree.lock) + list := sched.gFree.stack + sched.gFree.stack = gList{} + unlock(&sched.gFree.lock) + if list.empty() { return } // Free stacks. - tail := list - for gp := list; gp != nil; gp = gp.schedlink.ptr() { + q := gQueue{list.head, list.head} + for gp := list.head.ptr(); gp != nil; gp = gp.schedlink.ptr() { shrinkstack(gp) - tail = gp + // Manipulate the queue directly since the Gs are + // already all linked the right way. + q.tail.set(gp) } // Put Gs back on the free list. - lock(&sched.gflock) - tail.schedlink.set(sched.gfreeNoStack) - sched.gfreeNoStack = list - unlock(&sched.gflock) + lock(&sched.gFree.lock) + sched.gFree.noStack.pushAll(q) + unlock(&sched.gFree.lock) } // markrootSpans marks roots for one shard of work.spans. diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 2a780e49ee021..5cb7f130169d0 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -3471,25 +3471,21 @@ func gfput(_p_ *p, gp *g) { gp.stackguard0 = 0 } - gp.schedlink.set(_p_.gfree) - _p_.gfree = gp - _p_.gfreecnt++ - if _p_.gfreecnt >= 64 { - lock(&sched.gflock) - for _p_.gfreecnt >= 32 { - _p_.gfreecnt-- - gp = _p_.gfree - _p_.gfree = gp.schedlink.ptr() + _p_.gFree.push(gp) + _p_.gFree.n++ + if _p_.gFree.n >= 64 { + lock(&sched.gFree.lock) + for _p_.gFree.n >= 32 { + _p_.gFree.n-- + gp = _p_.gFree.pop() if gp.stack.lo == 0 { - gp.schedlink.set(sched.gfreeNoStack) - sched.gfreeNoStack = gp + sched.gFree.noStack.push(gp) } else { - gp.schedlink.set(sched.gfreeStack) - sched.gfreeStack = gp + sched.gFree.stack.push(gp) } - sched.ngfree++ + sched.gFree.n++ } - unlock(&sched.gflock) + unlock(&sched.gFree.lock) } } @@ -3497,44 +3493,42 @@ func gfput(_p_ *p, gp *g) { // If local list is empty, grab a batch from global list. func gfget(_p_ *p) *g { retry: - gp := _p_.gfree - if gp == nil && (sched.gfreeStack != nil || sched.gfreeNoStack != nil) { - lock(&sched.gflock) - for _p_.gfreecnt < 32 { - if sched.gfreeStack != nil { - // Prefer Gs with stacks. - gp = sched.gfreeStack - sched.gfreeStack = gp.schedlink.ptr() - } else if sched.gfreeNoStack != nil { - gp = sched.gfreeNoStack - sched.gfreeNoStack = gp.schedlink.ptr() - } else { - break + if _p_.gFree.empty() && (!sched.gFree.stack.empty() || !sched.gFree.noStack.empty()) { + lock(&sched.gFree.lock) + // Move a batch of free Gs to the P. + for _p_.gFree.n < 32 { + // Prefer Gs with stacks. + gp := sched.gFree.stack.pop() + if gp == nil { + gp = sched.gFree.noStack.pop() + if gp == nil { + break + } } - _p_.gfreecnt++ - sched.ngfree-- - gp.schedlink.set(_p_.gfree) - _p_.gfree = gp + sched.gFree.n-- + _p_.gFree.push(gp) + _p_.gFree.n++ } - unlock(&sched.gflock) + unlock(&sched.gFree.lock) goto retry } - if gp != nil { - _p_.gfree = gp.schedlink.ptr() - _p_.gfreecnt-- - if gp.stack.lo == 0 { - // Stack was deallocated in gfput. Allocate a new one. - systemstack(func() { - gp.stack = stackalloc(_FixedStack) - }) - gp.stackguard0 = gp.stack.lo + _StackGuard - } else { - if raceenabled { - racemalloc(unsafe.Pointer(gp.stack.lo), gp.stack.hi-gp.stack.lo) - } - if msanenabled { - msanmalloc(unsafe.Pointer(gp.stack.lo), gp.stack.hi-gp.stack.lo) - } + gp := _p_.gFree.pop() + if gp == nil { + return nil + } + _p_.gFree.n-- + if gp.stack.lo == 0 { + // Stack was deallocated in gfput. Allocate a new one. + systemstack(func() { + gp.stack = stackalloc(_FixedStack) + }) + gp.stackguard0 = gp.stack.lo + _StackGuard + } else { + if raceenabled { + racemalloc(unsafe.Pointer(gp.stack.lo), gp.stack.hi-gp.stack.lo) + } + if msanenabled { + msanmalloc(unsafe.Pointer(gp.stack.lo), gp.stack.hi-gp.stack.lo) } } return gp @@ -3542,21 +3536,18 @@ retry: // Purge all cached G's from gfree list to the global list. func gfpurge(_p_ *p) { - lock(&sched.gflock) - for _p_.gfreecnt != 0 { - _p_.gfreecnt-- - gp := _p_.gfree - _p_.gfree = gp.schedlink.ptr() + lock(&sched.gFree.lock) + for !_p_.gFree.empty() { + gp := _p_.gFree.pop() + _p_.gFree.n-- if gp.stack.lo == 0 { - gp.schedlink.set(sched.gfreeNoStack) - sched.gfreeNoStack = gp + sched.gFree.noStack.push(gp) } else { - gp.schedlink.set(sched.gfreeStack) - sched.gfreeStack = gp + sched.gFree.stack.push(gp) } - sched.ngfree++ + sched.gFree.n++ } - unlock(&sched.gflock) + unlock(&sched.gFree.lock) } // Breakpoint executes a breakpoint trap. @@ -3669,9 +3660,9 @@ func badunlockosthread() { } func gcount() int32 { - n := int32(allglen) - sched.ngfree - int32(atomic.Load(&sched.ngsys)) + n := int32(allglen) - sched.gFree.n - int32(atomic.Load(&sched.ngsys)) for _, _p_ := range allp { - n -= _p_.gfreecnt + n -= _p_.gFree.n } // All these variables can be changed concurrently, so the result can be inconsistent. @@ -4581,7 +4572,7 @@ func schedtrace(detailed bool) { if mp != nil { id = mp.id } - print(" P", i, ": status=", _p_.status, " schedtick=", _p_.schedtick, " syscalltick=", _p_.syscalltick, " m=", id, " runqsize=", t-h, " gfreecnt=", _p_.gfreecnt, "\n") + print(" P", i, ": status=", _p_.status, " schedtick=", _p_.schedtick, " syscalltick=", _p_.syscalltick, " m=", id, " runqsize=", t-h, " gfreecnt=", _p_.gFree.n, "\n") } else { // In non-detailed mode format lengths of per-P run queues as: // [len1 len2 len3 len4] diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 5bd37e49bec5a..bbbe1ee852b94 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -506,8 +506,10 @@ type p struct { runnext guintptr // Available G's (status == Gdead) - gfree *g - gfreecnt int32 + gFree struct { + gList + n int32 + } sudogcache []*sudog sudogbuf [128]*sudog @@ -578,10 +580,12 @@ type schedt struct { runqsize int32 // Global cache of dead G's. - gflock mutex - gfreeStack *g - gfreeNoStack *g - ngfree int32 + gFree struct { + lock mutex + stack gList // Gs with stacks + noStack gList // Gs without stacks + n int32 + } // Central cache of sudog structs. sudoglock mutex From d02169d380a762863147d57b7665cb31de0a4ee7 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 10 Aug 2018 10:28:44 -0400 Subject: [PATCH 0031/1663] runtime: use gList for work.sweepWaiters Change-Id: Ibae474a5c9a3528a042ddf19ddb4a88913a87606 Reviewed-on: https://go-review.googlesource.com/129399 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/mgc.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 7d4ba9f9cd70b..2d67c4d8c4485 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -1031,7 +1031,7 @@ var work struct { // we transition from mark termination to sweep. sweepWaiters struct { lock mutex - head guintptr + list gList } // cycles is the number of completed GC cycles, where a GC @@ -1146,9 +1146,7 @@ func gcWaitOnMark(n uint32) { // Wait until sweep termination, mark, and mark // termination of cycle N complete. - gp := getg() - gp.schedlink = work.sweepWaiters.head - work.sweepWaiters.head.set(gp) + work.sweepWaiters.list.push(getg()) goparkunlock(&work.sweepWaiters.lock, waitReasonWaitForGCCycle, traceEvGoBlock, 1) } } @@ -1632,8 +1630,8 @@ func gcMarkTermination(nextTriggerRatio float64) { // Bump GC cycle count and wake goroutines waiting on sweep. lock(&work.sweepWaiters.lock) memstats.numgc++ - injectglist(work.sweepWaiters.head.ptr()) - work.sweepWaiters.head = 0 + injectglist(work.sweepWaiters.list.head.ptr()) + work.sweepWaiters.list = gList{} unlock(&work.sweepWaiters.lock) // Finish the current heap profiling cycle and start a new From 083938df14c0602a44d055bd3f4427980cf51c27 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 10 Aug 2018 10:33:05 -0400 Subject: [PATCH 0032/1663] runtime: use gList for injectglist Change-Id: Id5af75eaaf41f43bc6baa6d3fe2b852a2f93bb6f Reviewed-on: https://go-review.googlesource.com/129400 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/mgc.go | 3 +-- src/runtime/mgcmark.go | 3 ++- src/runtime/proc.go | 31 ++++++++++++++++--------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index 2d67c4d8c4485..e4c0f5a587629 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -1630,8 +1630,7 @@ func gcMarkTermination(nextTriggerRatio float64) { // Bump GC cycle count and wake goroutines waiting on sweep. lock(&work.sweepWaiters.lock) memstats.numgc++ - injectglist(work.sweepWaiters.list.head.ptr()) - work.sweepWaiters.list = gList{} + injectglist(&work.sweepWaiters.list) unlock(&work.sweepWaiters.lock) // Finish the current heap profiling cycle and start a new diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index d6ee7ff6fabe4..69ff895512faa 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -603,7 +603,8 @@ func gcAssistAlloc1(gp *g, scanWork int64) { // new assists from going to sleep after this point. func gcWakeAllAssists() { lock(&work.assistQueue.lock) - injectglist(work.assistQueue.q.popList().head.ptr()) + list := work.assistQueue.q.popList() + injectglist(&list) unlock(&work.assistQueue.lock) } diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 5cb7f130169d0..7875b38e2e2cf 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -1149,7 +1149,7 @@ func startTheWorldWithSema(emitTraceEvent bool) int64 { _g_.m.locks++ // disable preemption because it can be holding p in a local var if netpollinited() { list := netpoll(false) // non-blocking - injectglist(list.head.ptr()) + injectglist(&list) } add := needaddgcproc() lock(&sched.lock) @@ -2314,7 +2314,7 @@ top: if netpollinited() && atomic.Load(&netpollWaiters) > 0 && atomic.Load64(&sched.lastpoll) != 0 { if list := netpoll(false); !list.empty() { // non-blocking gp := list.pop() - injectglist(list.head.ptr()) + injectglist(&list) casgstatus(gp, _Gwaiting, _Grunnable) if trace.enabled { traceGoUnpark(gp, 0) @@ -2475,14 +2475,14 @@ stop: if _p_ != nil { acquirep(_p_) gp := list.pop() - injectglist(list.head.ptr()) + injectglist(&list) casgstatus(gp, _Gwaiting, _Grunnable) if trace.enabled { traceGoUnpark(gp, 0) } return gp, false } - injectglist(list.head.ptr()) + injectglist(&list) } } stopm() @@ -2503,7 +2503,7 @@ func pollWork() bool { } if netpollinited() && atomic.Load(&netpollWaiters) > 0 && sched.lastpoll != 0 { if list := netpoll(false); !list.empty() { - injectglist(list.head.ptr()) + injectglist(&list) return true } } @@ -2528,22 +2528,21 @@ func resetspinning() { } } -// Injects the list of runnable G's into the scheduler. +// Injects the list of runnable G's into the scheduler and clears glist. // Can run concurrently with GC. -func injectglist(glist *g) { - if glist == nil { +func injectglist(glist *gList) { + if glist.empty() { return } if trace.enabled { - for gp := glist; gp != nil; gp = gp.schedlink.ptr() { + for gp := glist.head.ptr(); gp != nil; gp = gp.schedlink.ptr() { traceGoUnpark(gp, 0) } } lock(&sched.lock) var n int - for n = 0; glist != nil; n++ { - gp := glist - glist = gp.schedlink.ptr() + for n = 0; !glist.empty(); n++ { + gp := glist.pop() casgstatus(gp, _Gwaiting, _Grunnable) globrunqput(gp) } @@ -2551,6 +2550,7 @@ func injectglist(glist *g) { for ; n != 0 && sched.npidle != 0; n-- { startm(nil, false) } + *glist = gList{} } // One round of scheduler: find a runnable goroutine and execute it. @@ -4389,7 +4389,7 @@ func sysmon() { // observes that there is no work to do and no other running M's // and reports deadlock. incidlelocked(-1) - injectglist(list.head.ptr()) + injectglist(&list) incidlelocked(1) } } @@ -4404,8 +4404,9 @@ func sysmon() { if t := (gcTrigger{kind: gcTriggerTime, now: now}); t.test() && atomic.Load(&forcegc.idle) != 0 { lock(&forcegc.lock) forcegc.idle = 0 - forcegc.g.schedlink = 0 - injectglist(forcegc.g) + var list gList + list.push(forcegc.g) + injectglist(&list) unlock(&forcegc.lock) } // scavenge heap once in a while From a034f310b040a4252843683f59555ded07016eae Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 10 Aug 2018 10:34:41 -0400 Subject: [PATCH 0033/1663] runtime: use gList in closechan Change-Id: I8148eb17fe9f2cbb659c35d84cdd212b46dc23bf Reviewed-on: https://go-review.googlesource.com/129401 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/chan.go | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/runtime/chan.go b/src/runtime/chan.go index ce71cee4c5b40..615643e6a60bd 100644 --- a/src/runtime/chan.go +++ b/src/runtime/chan.go @@ -343,7 +343,7 @@ func closechan(c *hchan) { c.closed = 1 - var glist *g + var glist gList // release all readers for { @@ -363,8 +363,7 @@ func closechan(c *hchan) { if raceenabled { raceacquireg(gp, unsafe.Pointer(c)) } - gp.schedlink.set(glist) - glist = gp + glist.push(gp) } // release all writers (they will panic) @@ -382,15 +381,13 @@ func closechan(c *hchan) { if raceenabled { raceacquireg(gp, unsafe.Pointer(c)) } - gp.schedlink.set(glist) - glist = gp + glist.push(gp) } unlock(&c.lock) // Ready all Gs now that we've dropped the channel lock. - for glist != nil { - gp := glist - glist = glist.schedlink.ptr() + for !glist.empty() { + gp := glist.pop() gp.schedlink = 0 goready(gp, 3) } From 09ec523049e3f26cba9b431dcc8ea4820b5dcc89 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 20 Aug 2018 19:11:33 +0000 Subject: [PATCH 0034/1663] Revert "cmd/dist: support windows/arm" This reverts commit def3280eb4e4bc7fb058f98fa2993cb077db3f95. Reason for revert: broke the vetall builder and I (Brad) forgot to run the trybots first. :( Change-Id: I255bedeb28d13e265f357060e57561e593145275 Reviewed-on: https://go-review.googlesource.com/130015 Reviewed-by: Brad Fitzpatrick --- src/cmd/dist/build.go | 1 - src/cmd/dist/sys_windows.go | 3 --- 2 files changed, 4 deletions(-) diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index 06adccd9a4a7b..eed9866ce478e 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -1422,7 +1422,6 @@ var cgoEnabled = map[string]bool{ "solaris/amd64": true, "windows/386": true, "windows/amd64": true, - "windows/arm": false, } func needCC() bool { diff --git a/src/cmd/dist/sys_windows.go b/src/cmd/dist/sys_windows.go index 2f6a1b0dceb6f..216dc017982fe 100644 --- a/src/cmd/dist/sys_windows.go +++ b/src/cmd/dist/sys_windows.go @@ -32,7 +32,6 @@ type systeminfo struct { const ( PROCESSOR_ARCHITECTURE_AMD64 = 9 PROCESSOR_ARCHITECTURE_INTEL = 0 - PROCESSOR_ARCHITECTURE_ARM = 5 ) var sysinfo systeminfo @@ -44,8 +43,6 @@ func sysinit() { gohostarch = "amd64" case PROCESSOR_ARCHITECTURE_INTEL: gohostarch = "386" - case PROCESSOR_ARCHITECTURE_ARM: - gohostarch = "arm" default: fatalf("unknown processor architecture") } From 1ba74448f25fa9e69c4f9ed155dd43eb496cfa70 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Mon, 20 Aug 2018 23:45:34 +0700 Subject: [PATCH 0035/1663] runtime: document all possible values for GOOS and GOARCH The updated list is taken from "src/go/build/syslist.go". Reason: one should not do web search to know the possible values of GOOS and GOARCH. The search result point to stackoverflow page which reference the above source and documentation on installation page [1]. It should available offline (as in local godoc), as part of package documentation. [1] https://golang.org/doc/install/source#environment Change-Id: I736804b8ef4dc11e0260fa862999212ab3f7b3fd Reviewed-on: https://go-review.googlesource.com/129935 Reviewed-by: Brad Fitzpatrick --- src/runtime/extern.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/runtime/extern.go b/src/runtime/extern.go index 7171b139c3239..2788bd354b16c 100644 --- a/src/runtime/extern.go +++ b/src/runtime/extern.go @@ -238,6 +238,7 @@ func Version() string { // GOOS is the running program's operating system target: // one of darwin, freebsd, linux, and so on. +// To view possible combinations of GOOS and GOARCH, run "go tool dist list". const GOOS string = sys.GOOS // GOARCH is the running program's architecture target: From e8f49aa80e659ca3308665b950ee3ce6e2268326 Mon Sep 17 00:00:00 2001 From: Fazlul Shahriar Date: Sat, 18 Aug 2018 15:11:06 -0400 Subject: [PATCH 0036/1663] cmd/go/internal/modload: ignore directories when looking for go.mod file in Plan 9 This fixes builds in Plan 9 under /n. Since directories in /n are automatically created, /n/go.mod always exists. Fixes #27074 Change-Id: Ie9a1155b7c316bdc27655f5b99172550b413838d Reviewed-on: https://go-review.googlesource.com/129804 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/go/internal/modload/init.go | 5 ++- .../go/internal/modload/init_plan9_test.go | 42 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/cmd/go/internal/modload/init_plan9_test.go diff --git a/src/cmd/go/internal/modload/init.go b/src/cmd/go/internal/modload/init.go index f995bad13b543..2bab3eede1387 100644 --- a/src/cmd/go/internal/modload/init.go +++ b/src/cmd/go/internal/modload/init.go @@ -24,6 +24,7 @@ import ( "path" "path/filepath" "regexp" + "runtime" "strconv" "strings" ) @@ -379,7 +380,7 @@ func FindModuleRoot(dir, limit string, legacyConfigOK bool) (root, file string) // Look for enclosing go.mod. for { - if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil { + if fi, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil && !(runtime.GOOS == "plan9" && fi.IsDir()) { return dir, "go.mod" } if dir == limit { @@ -397,7 +398,7 @@ func FindModuleRoot(dir, limit string, legacyConfigOK bool) (root, file string) dir = dir1 for { for _, name := range altConfigs { - if _, err := os.Stat(filepath.Join(dir, name)); err == nil { + if fi, err := os.Stat(filepath.Join(dir, name)); err == nil && !(runtime.GOOS == "plan9" && fi.IsDir()) { return dir, name } } diff --git a/src/cmd/go/internal/modload/init_plan9_test.go b/src/cmd/go/internal/modload/init_plan9_test.go new file mode 100644 index 0000000000000..2df9d8af7df1b --- /dev/null +++ b/src/cmd/go/internal/modload/init_plan9_test.go @@ -0,0 +1,42 @@ +// Copyright 2018 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. + +package modload + +import ( + "io/ioutil" + "os" + "path/filepath" + "testing" +) + +func TestFindModuleRootIgnoreDir(t *testing.T) { + // In Plan 9, directories are automatically created in /n. + // For example, /n/go.mod always exist, but it's a directory. + // Test that we ignore directories when trying to find go.mod and other config files. + + dir, err := ioutil.TempDir("", "gotest") + if err != nil { + t.Fatalf("failed to create temporary directory: %v", err) + } + defer os.RemoveAll(dir) + if err := os.Mkdir(filepath.Join(dir, "go.mod"), os.ModeDir|0755); err != nil { + t.Fatalf("Mkdir failed: %v", err) + } + for _, name := range altConfigs { + if err := os.MkdirAll(filepath.Join(dir, name), os.ModeDir|0755); err != nil { + t.Fatalf("MkdirAll failed: %v", err) + } + } + p := filepath.Join(dir, "example") + if err := os.Mkdir(p, os.ModeDir|0755); err != nil { + t.Fatalf("Mkdir failed: %v", err) + } + if root, _ := FindModuleRoot(p, "", false); root != "" { + t.Errorf("FindModuleRoot(%q, \"\", false): %q, want empty string", p, root) + } + if root, _ := FindModuleRoot(p, "", true); root != "" { + t.Errorf("FindModuleRoot(%q, \"\", true): %q, want empty string", p, root) + } +} From c589b9ec4eaf47e9e4994113d88e073cb695181b Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Mon, 20 Aug 2018 12:46:43 -0700 Subject: [PATCH 0037/1663] cmd/vet: exclude windows/arm from cmd/vet Updates #27103 Change-Id: I1f7d198879e5912661e4156a86e13de2698a5473 Reviewed-on: https://go-review.googlesource.com/130055 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/vet/all/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cmd/vet/all/main.go b/src/cmd/vet/all/main.go index 09181f968950c..e7fe4edc2a41d 100644 --- a/src/cmd/vet/all/main.go +++ b/src/cmd/vet/all/main.go @@ -198,6 +198,12 @@ func (p platform) vet() { return } + if p.os == "windows" && p.arch == "arm" { + // TODO(jordanrh1): enable as soon as the windows/arm port has fully landed + fmt.Println("skipping windows/arm") + return + } + var buf bytes.Buffer fmt.Fprintf(&buf, "go run main.go -p %s\n", p) From 3000795c83336b83608a8104fdb2a4643b43e941 Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Tue, 24 Jul 2018 15:07:01 -0700 Subject: [PATCH 0038/1663] cmd/dist: support windows/arm Updates #26148 Change-Id: I4744ebcc77fda3acc1301a1d8857754c0ee797fa Reviewed-on: https://go-review.googlesource.com/130056 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/dist/build.go | 1 + src/cmd/dist/sys_windows.go | 3 +++ 2 files changed, 4 insertions(+) diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index eed9866ce478e..06adccd9a4a7b 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -1422,6 +1422,7 @@ var cgoEnabled = map[string]bool{ "solaris/amd64": true, "windows/386": true, "windows/amd64": true, + "windows/arm": false, } func needCC() bool { diff --git a/src/cmd/dist/sys_windows.go b/src/cmd/dist/sys_windows.go index 216dc017982fe..2f6a1b0dceb6f 100644 --- a/src/cmd/dist/sys_windows.go +++ b/src/cmd/dist/sys_windows.go @@ -32,6 +32,7 @@ type systeminfo struct { const ( PROCESSOR_ARCHITECTURE_AMD64 = 9 PROCESSOR_ARCHITECTURE_INTEL = 0 + PROCESSOR_ARCHITECTURE_ARM = 5 ) var sysinfo systeminfo @@ -43,6 +44,8 @@ func sysinit() { gohostarch = "amd64" case PROCESSOR_ARCHITECTURE_INTEL: gohostarch = "386" + case PROCESSOR_ARCHITECTURE_ARM: + gohostarch = "arm" default: fatalf("unknown processor architecture") } From c292b32f33d4c466abb769782d9cdfacdb76688b Mon Sep 17 00:00:00 2001 From: Ilya Tocar Date: Wed, 9 May 2018 15:49:22 -0500 Subject: [PATCH 0039/1663] cmd/compile: enable disjoint memmove inlining on amd64 Memmove can use AVX/prefetches/other optional instructions, so only do it for small sizes, when call overhead dominates. Change-Id: Ice5e93deb11462217f7fb5fc350b703109bb4090 Reviewed-on: https://go-review.googlesource.com/112517 Run-TryBot: Ilya Tocar TryBot-Result: Gobot Gobot Reviewed-by: Michael Munday --- src/cmd/compile/internal/ssa/rewrite.go | 2 +- test/codegen/copy.go | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index 5e151b5213d29..e7d1b5c767ece 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -905,7 +905,7 @@ func isInlinableMemmove(dst, src *Value, sz int64, c *Config) bool { // have fast Move ops. switch c.arch { case "amd64", "amd64p32": - return sz <= 16 + return sz <= 16 || (sz < 1024 && disjoint(dst, sz, src, sz)) case "386", "ppc64", "ppc64le", "arm64": return sz <= 8 case "s390x": diff --git a/test/codegen/copy.go b/test/codegen/copy.go index 5c3837bc7c337..dc8ee43f4c7e0 100644 --- a/test/codegen/copy.go +++ b/test/codegen/copy.go @@ -40,19 +40,22 @@ var x [256]byte func moveDisjointStack() { var s [256]byte // s390x:-".*memmove" + // amd64:-".*memmove" copy(s[:], x[:]) runtime.KeepAlive(&s) } -func moveDisjointArg(b *[256]byte) { +func moveDisjointArg(b *[256]byte) { var s [256]byte // s390x:-".*memmove" + // amd64:-".*memmove" copy(s[:], b[:]) runtime.KeepAlive(&s) } func moveDisjointNoOverlap(a *[256]byte) { // s390x:-".*memmove" + // amd64:-".*memmove" copy(a[:], a[128:]) } From a3593685cf4d385bf9edf5306022e001e1eb6586 Mon Sep 17 00:00:00 2001 From: Ilya Tocar Date: Thu, 31 May 2018 16:38:18 -0500 Subject: [PATCH 0040/1663] cmd/compile/internal/ssa: remove useless zero extension We generate MOVBLZX for byte-sized LoadReg, so (MOVBQZX (LoadReg (Arg))) is the same as (LoadReg (Arg)). Remove those zero extension where possible. Triggers several times during all.bash. Fixes #25378 Updates #15300 Change-Id: If50656e66f217832a13ee8f49c47997f4fcc093a Reviewed-on: https://go-review.googlesource.com/115617 Run-TryBot: Ilya Tocar TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/gen/AMD64.rules | 2 + src/cmd/compile/internal/ssa/rewrite.go | 48 ++++++++++++++++++++ src/cmd/compile/internal/ssa/rewriteAMD64.go | 26 +++++++++++ test/codegen/issue25378.go | 22 +++++++++ 4 files changed, 98 insertions(+) create mode 100644 test/codegen/issue25378.go diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index db6bbfb0606d9..bf3a11604595b 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -988,6 +988,8 @@ (MOVLQZX x:(MOVQload [off] {sym} ptr mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVLload [off] {sym} ptr mem) (MOVLQZX x) && zeroUpper32Bits(x,3) -> x +(MOVWQZX x) && zeroUpper48Bits(x,3) -> x +(MOVBQZX x) && zeroUpper56Bits(x,3) -> x (MOVBQZX x:(MOVBloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVBloadidx1 [off] {sym} ptr idx mem) (MOVWQZX x:(MOVWloadidx1 [off] {sym} ptr idx mem)) && x.Uses == 1 && clobber(x) -> @x.Block (MOVWloadidx1 [off] {sym} ptr idx mem) diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index e7d1b5c767ece..2a72b0006f161 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -894,6 +894,54 @@ func zeroUpper32Bits(x *Value, depth int) bool { return false } +// zeroUpper48Bits is similar to zeroUpper32Bits, but for upper 48 bits +func zeroUpper48Bits(x *Value, depth int) bool { + switch x.Op { + case OpAMD64MOVWQZX, OpAMD64MOVWload, OpAMD64MOVWloadidx1, OpAMD64MOVWloadidx2: + return true + case OpArg: + return x.Type.Width == 2 + case OpPhi, OpSelect0, OpSelect1: + // Phis can use each-other as an arguments, instead of tracking visited values, + // just limit recursion depth. + if depth <= 0 { + return false + } + for i := range x.Args { + if !zeroUpper48Bits(x.Args[i], depth-1) { + return false + } + } + return true + + } + return false +} + +// zeroUpper56Bits is similar to zeroUpper32Bits, but for upper 56 bits +func zeroUpper56Bits(x *Value, depth int) bool { + switch x.Op { + case OpAMD64MOVBQZX, OpAMD64MOVBload, OpAMD64MOVBloadidx1: + return true + case OpArg: + return x.Type.Width == 1 + case OpPhi, OpSelect0, OpSelect1: + // Phis can use each-other as an arguments, instead of tracking visited values, + // just limit recursion depth. + if depth <= 0 { + return false + } + for i := range x.Args { + if !zeroUpper56Bits(x.Args[i], depth-1) { + return false + } + } + return true + + } + return false +} + // isInlinableMemmove reports whether the given arch performs a Move of the given size // faster than memmove. It will only return true if replacing the memmove with a Move is // safe, either because Move is small or because the arguments are disjoint. diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 950b926cc1420..4ffd6b5d186b4 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -10270,6 +10270,19 @@ func rewriteValueAMD64_OpAMD64MOVBQZX_0(v *Value) bool { v0.AddArg(mem) return true } + // match: (MOVBQZX x) + // cond: zeroUpper56Bits(x,3) + // result: x + for { + x := v.Args[0] + if !(zeroUpper56Bits(x, 3)) { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } // match: (MOVBQZX x:(MOVBloadidx1 [off] {sym} ptr idx mem)) // cond: x.Uses == 1 && clobber(x) // result: @x.Block (MOVBloadidx1 [off] {sym} ptr idx mem) @@ -18893,6 +18906,19 @@ func rewriteValueAMD64_OpAMD64MOVWQZX_0(v *Value) bool { v0.AddArg(mem) return true } + // match: (MOVWQZX x) + // cond: zeroUpper48Bits(x,3) + // result: x + for { + x := v.Args[0] + if !(zeroUpper48Bits(x, 3)) { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } // match: (MOVWQZX x:(MOVWloadidx1 [off] {sym} ptr idx mem)) // cond: x.Uses == 1 && clobber(x) // result: @x.Block (MOVWloadidx1 [off] {sym} ptr idx mem) diff --git a/test/codegen/issue25378.go b/test/codegen/issue25378.go new file mode 100644 index 0000000000000..14aa2c30f2d83 --- /dev/null +++ b/test/codegen/issue25378.go @@ -0,0 +1,22 @@ +// asmcheck + +// Copyright 2018 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. + +package codegen + +var wsp = [256]bool{ + ' ': true, + '\t': true, + '\n': true, + '\r': true, +} + +func zeroExtArgByte(ch byte) bool { + return wsp[ch] // amd64:-"MOVBLZX\t..,.." +} + +func zeroExtArgUint16(ch uint16) bool { + return wsp[ch] // amd64:-"MOVWLZX\t..,.." +} From d05f31a3c5677467525241d4bacdb287f485d370 Mon Sep 17 00:00:00 2001 From: Shivansh Rai Date: Mon, 4 Jun 2018 17:10:43 +0530 Subject: [PATCH 0041/1663] internal/poll: Avoid evaluating condition for an unreachable branch Change-Id: I868dcaf84767d631bc8f1b6ef6bcb3ec18047259 Reviewed-on: https://go-review.googlesource.com/116135 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/internal/poll/sendfile_bsd.go | 3 +-- src/internal/poll/sendfile_linux.go | 3 +-- src/internal/poll/sendfile_solaris.go | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/internal/poll/sendfile_bsd.go b/src/internal/poll/sendfile_bsd.go index 980a75afa7fc3..40ae3468b0745 100644 --- a/src/internal/poll/sendfile_bsd.go +++ b/src/internal/poll/sendfile_bsd.go @@ -32,8 +32,7 @@ func SendFile(dstFD *FD, src int, pos, remain int64) (int64, error) { pos += int64(n) written += int64(n) remain -= int64(n) - } - if n == 0 && err1 == nil { + } else if n == 0 && err1 == nil { break } if err1 == syscall.EAGAIN { diff --git a/src/internal/poll/sendfile_linux.go b/src/internal/poll/sendfile_linux.go index 52955a19d0b4f..8e938065f17ad 100644 --- a/src/internal/poll/sendfile_linux.go +++ b/src/internal/poll/sendfile_linux.go @@ -29,8 +29,7 @@ func SendFile(dstFD *FD, src int, remain int64) (int64, error) { if n > 0 { written += int64(n) remain -= int64(n) - } - if n == 0 && err1 == nil { + } else if n == 0 && err1 == nil { break } if err1 == syscall.EAGAIN { diff --git a/src/internal/poll/sendfile_solaris.go b/src/internal/poll/sendfile_solaris.go index 9093d464834f4..762992e9eb398 100644 --- a/src/internal/poll/sendfile_solaris.go +++ b/src/internal/poll/sendfile_solaris.go @@ -39,8 +39,7 @@ func SendFile(dstFD *FD, src int, pos, remain int64) (int64, error) { pos += int64(n) written += int64(n) remain -= int64(n) - } - if n == 0 && err1 == nil { + } else if n == 0 && err1 == nil { break } if err1 == syscall.EAGAIN { From c9b018918d461da758e448ac370c2df8c6f77ab3 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 2 Jul 2018 10:36:49 -0700 Subject: [PATCH 0042/1663] testing: exit with error if testing.Short is called before flag.Parse Change-Id: I2fa547d1074ef0931196066678fadd7250a1148d Reviewed-on: https://go-review.googlesource.com/121936 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/testing/testing.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/testing/testing.go b/src/testing/testing.go index a552b363617c6..179987b699aaf 100644 --- a/src/testing/testing.go +++ b/src/testing/testing.go @@ -316,6 +316,13 @@ type common struct { // Short reports whether the -test.short flag is set. func Short() bool { + // Catch code that calls this from TestMain without first + // calling flag.Parse. This shouldn't really be a panic + if !flag.Parsed() { + fmt.Fprintf(os.Stderr, "testing: testing.Short called before flag.Parse\n") + os.Exit(2) + } + return *short } From a1addf15df95418d86fc0d495bc9aa85590d5724 Mon Sep 17 00:00:00 2001 From: nogoegst Date: Tue, 3 Jul 2018 19:49:52 +0000 Subject: [PATCH 0043/1663] bufio: make Reader naming consistent All the readers are denoted as `b` while for `Reader.Size()` it is `r`. Change-Id: Ib6f97306c11b3abb2ff30edbc9f9362cad36d080 GitHub-Last-Rev: 992f88b374b5a309303b7fa1622ee629d0fb741b GitHub-Pull-Request: golang/go#26205 Reviewed-on: https://go-review.googlesource.com/122156 Reviewed-by: Brad Fitzpatrick --- src/bufio/bufio.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bufio/bufio.go b/src/bufio/bufio.go index 72545a7509541..480e929f5812a 100644 --- a/src/bufio/bufio.go +++ b/src/bufio/bufio.go @@ -63,7 +63,7 @@ func NewReader(rd io.Reader) *Reader { } // Size returns the size of the underlying buffer in bytes. -func (r *Reader) Size() int { return len(r.buf) } +func (b *Reader) Size() int { return len(b.buf) } // Reset discards any buffered data, resets all state, and switches // the buffered reader to read from r. From f76eaeb2c840c76c48dc53b834e9a0e005a70421 Mon Sep 17 00:00:00 2001 From: David Symonds Date: Wed, 20 Jun 2018 12:45:48 +1000 Subject: [PATCH 0044/1663] cmd/go/internal/get: more efficient path prefix checking code Splitting the string is unnecessary. Change-Id: I02796cb91602c1b9bf22721b985cd41b18cc92f2 Reviewed-on: https://go-review.googlesource.com/119936 Run-TryBot: David Symonds TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike --- src/cmd/go/internal/get/vcs.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/cmd/go/internal/get/vcs.go b/src/cmd/go/internal/get/vcs.go index 5cd164f2ff3a1..0f7b623ec31e8 100644 --- a/src/cmd/go/internal/get/vcs.go +++ b/src/cmd/go/internal/get/vcs.go @@ -903,16 +903,16 @@ type metaImport struct { Prefix, VCS, RepoRoot string } -func splitPathHasPrefix(path, prefix []string) bool { - if len(path) < len(prefix) { +// pathPrefix reports whether sub is a prefix of s, +// only considering entire path components. +func pathPrefix(s, sub string) bool { + // strings.HasPrefix is necessary but not sufficient. + if !strings.HasPrefix(s, sub) { return false } - for i, p := range prefix { - if path[i] != p { - return false - } - } - return true + // The remainder after the prefix must either be empty or start with a slash. + rem := s[len(sub):] + return rem == "" || rem[0] == '/' } // A ImportMismatchError is returned where metaImport/s are present @@ -935,13 +935,10 @@ func (m ImportMismatchError) Error() string { // errNoMatch is returned if none match. func matchGoImport(imports []metaImport, importPath string) (metaImport, error) { match := -1 - imp := strings.Split(importPath, "/") errImportMismatch := ImportMismatchError{importPath: importPath} for i, im := range imports { - pre := strings.Split(im.Prefix, "/") - - if !splitPathHasPrefix(imp, pre) { + if !pathPrefix(importPath, im.Prefix) { errImportMismatch.mismatches = append(errImportMismatch.mismatches, im.Prefix) continue } From 4201c2077ec3446a4fea5ed768c82aa96df69233 Mon Sep 17 00:00:00 2001 From: Ilya Tocar Date: Wed, 27 Jun 2018 11:40:24 -0500 Subject: [PATCH 0045/1663] cmd/compile: omit racefuncentry/exit when they are not needed When compiling with -race, we insert calls to racefuncentry, into every function. Add a rule that removes them in leaf functions, without instrumented loads/stores. Shaves ~30kb from "-race" version of go tool: file difference: go_old 15626192 go_new 15597520 [-28672 bytes] section differences: global text (code) = -24513 bytes (-0.358598%) read-only data = -5849 bytes (-0.167064%) Total difference -30362 bytes (-0.097928%) Fixes #24662 Change-Id: Ia63bf1827f4cf2c25e3e28dcd097c150994ade0a Reviewed-on: https://go-review.googlesource.com/121235 Run-TryBot: Ilya Tocar TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/racewalk.go | 6 +++- src/cmd/compile/internal/gc/ssa.go | 1 + src/cmd/compile/internal/ssa/config.go | 1 + .../compile/internal/ssa/gen/generic.rules | 2 ++ src/cmd/compile/internal/ssa/rewrite.go | 28 +++++++++++++++++++ .../compile/internal/ssa/rewritegeneric.go | 14 ++++++++++ 6 files changed, 51 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/gc/racewalk.go b/src/cmd/compile/internal/gc/racewalk.go index df0e5f4059035..e8c7fb5b14906 100644 --- a/src/cmd/compile/internal/gc/racewalk.go +++ b/src/cmd/compile/internal/gc/racewalk.go @@ -10,7 +10,7 @@ import ( "cmd/internal/sys" ) -// The racewalk pass is currently handled in two parts. +// The racewalk pass is currently handled in three parts. // // First, for flag_race, it inserts calls to racefuncenter and // racefuncexit at the start and end (respectively) of each @@ -22,6 +22,10 @@ import ( // the Func.InstrumentBody flag as needed. For background on why this // is done during SSA construction rather than a separate SSA pass, // see issue #19054. +// +// Third we remove calls to racefuncenter and racefuncexit, for leaf +// functions without instrumented operations. This is done as part of +// ssa opt pass via special rule. // TODO(dvyukov): do not instrument initialization as writes: // a := make([]int, 10) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index af43da6275461..86b457b75821e 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -131,6 +131,7 @@ func buildssa(fn *Node, worker int) *ssa.Func { s.f.Cache = &ssaCaches[worker] s.f.Cache.Reset() s.f.DebugTest = s.f.DebugHashMatch("GOSSAHASH", name) + s.f.Config.Race = flag_race s.f.Name = name if fn.Func.Pragma&Nosplit != 0 { s.f.NoSplit = true diff --git a/src/cmd/compile/internal/ssa/config.go b/src/cmd/compile/internal/ssa/config.go index af8cccff90bb1..40008bcf8792e 100644 --- a/src/cmd/compile/internal/ssa/config.go +++ b/src/cmd/compile/internal/ssa/config.go @@ -38,6 +38,7 @@ type Config struct { nacl bool // GOOS=nacl use387 bool // GO386=387 SoftFloat bool // + Race bool // race detector enabled NeedsFpScratch bool // No direct move between GP and FP register sets BigEndian bool // } diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index 0b68db7f0465d..b1a0775e4a8f8 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -1791,3 +1791,5 @@ (Store {t4} (OffPtr [o4] dst) d3 (Store {t5} (OffPtr [o5] dst) d4 (Zero {t1} [n] dst mem))))) + +(StaticCall {sym} x) && needRaceCleanup(sym,v) -> x diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index 2a72b0006f161..31195638ab5f8 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -1026,3 +1026,31 @@ func registerizable(b *Block, t interface{}) bool { } return false } + +// needRaceCleanup reports whether this call to racefuncenter/exit isn't needed. +func needRaceCleanup(sym interface{}, v *Value) bool { + f := v.Block.Func + if !f.Config.Race { + return false + } + if !isSameSym(sym, "runtime.racefuncenter") && !isSameSym(sym, "runtime.racefuncexit") { + return false + } + for _, b := range f.Blocks { + for _, v := range b.Values { + if v.Op == OpStaticCall { + switch v.Aux.(fmt.Stringer).String() { + case "runtime.racefuncenter", "runtime.racefuncexit", "runtime.panicindex", + "runtime.panicslice", "runtime.panicdivide", "runtime.panicwrap": + // Check for racefuncenter will encounter racefuncexit and vice versa. + // Allow calls to panic* + default: + // If we encounterd any call, we need to keep racefunc*, + // for accurate stacktraces. + return false + } + } + } + } + return true +} diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index a1c83ea37834e..5ad53dd0b6d38 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -27595,6 +27595,20 @@ func rewriteValuegeneric_OpStaticCall_0(v *Value) bool { v.AddArg(mem) return true } + // match: (StaticCall {sym} x) + // cond: needRaceCleanup(sym,v) + // result: x + for { + sym := v.Aux + x := v.Args[0] + if !(needRaceCleanup(sym, v)) { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } return false } func rewriteValuegeneric_OpStore_0(v *Value) bool { From 328adf9d62b681bf4f7cb0c41a3f16272cf5f4a2 Mon Sep 17 00:00:00 2001 From: isharipo Date: Thu, 17 May 2018 19:50:29 +0300 Subject: [PATCH 0046/1663] cmd/link: fewer allocs in ld.Arch.Archreloc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Archreloc had this signature: func(*Link, *sym.Reloc, *sym.Symbol, *int64) bool The last *int64 argument is used as out parameter. Passed valus could be allocated on stack, but escape analysis fails here, leading to high number of unwanted allocs. If instead 4th arg is passed by value, and modified values is returned, no problems with allocations arise: func(*Link, *sym.Reloc, *sym.Symbol, int64) (int64, bool) There are 2 benefits: 1. code becomes more readable. 2. less allocations. For linking "hello world" example from net/http: name old time/op new time/op delta Linker-4 530ms ± 2% 520ms ± 2% -1.83% (p=0.001 n=17+16) It's top 1 in alloc_objects from memprofile: flat flat% sum% cum cum% 229379 33.05% 33.05% 229379 33.05% cmd/link/internal/ld.relocsym ... list relocsym: 229379 229379 (flat, cum) 33.05% of Total 229379 229379 183: var o int64 After the patch, ~230k of int64 allocs (~ 1.75mb) removed. Passes toolshash-check (toolstash cmp). Change-Id: I25504fe27967bcff70c4b7338790f3921d15473d Reviewed-on: https://go-review.googlesource.com/113637 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/link/internal/amd64/asm.go | 4 +- src/cmd/link/internal/arm/asm.go | 30 +++++---------- src/cmd/link/internal/arm64/asm.go | 60 +++++++++++++---------------- src/cmd/link/internal/ld/data.go | 4 +- src/cmd/link/internal/ld/lib.go | 2 +- src/cmd/link/internal/mips/asm.go | 37 ++++++++---------- src/cmd/link/internal/mips64/asm.go | 28 ++++++-------- src/cmd/link/internal/ppc64/asm.go | 47 ++++++++++------------ src/cmd/link/internal/s390x/asm.go | 12 +++--- src/cmd/link/internal/x86/asm.go | 12 +++--- 10 files changed, 100 insertions(+), 136 deletions(-) diff --git a/src/cmd/link/internal/amd64/asm.go b/src/cmd/link/internal/amd64/asm.go index af274444f36ae..692edf1524ad7 100644 --- a/src/cmd/link/internal/amd64/asm.go +++ b/src/cmd/link/internal/amd64/asm.go @@ -532,8 +532,8 @@ func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, secto return true } -func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { - return false +func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) { + return val, false } func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 { diff --git a/src/cmd/link/internal/arm/asm.go b/src/cmd/link/internal/arm/asm.go index f0a510f1f07fc..5e4ddea88e1fa 100644 --- a/src/cmd/link/internal/arm/asm.go +++ b/src/cmd/link/internal/arm/asm.go @@ -568,7 +568,7 @@ func gentrampdyn(arch *sys.Arch, tramp, target *sym.Symbol, offset int64) { } } -func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { +func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) { if ctxt.LinkMode == ld.LinkExternal { switch r.Type { case objabi.R_CALLARM: @@ -602,20 +602,17 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { ld.Errorf(s, "direct call too far %d", r.Xadd/4) } - *val = int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&uint32(r.Xadd/4)))) - return true + return int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&uint32(r.Xadd/4)))), true } - return false + return -1, false } switch r.Type { case objabi.R_CONST: - *val = r.Add - return true + return r.Add, true case objabi.R_GOTOFF: - *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) - return true + return ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)), true // The following three arch specific relocations are only for generation of // Linux/ARM ELF's PLT entry (3 assembler instruction) @@ -623,16 +620,11 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { if ld.Symaddr(ctxt.Syms.Lookup(".got.plt", 0)) < ld.Symaddr(ctxt.Syms.Lookup(".plt", 0)) { ld.Errorf(s, ".got.plt should be placed after .plt section.") } - *val = 0xe28fc600 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add)) >> 20)) - return true + return 0xe28fc600 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add)) >> 20)), true case objabi.R_PLT1: // add ip, ip, #0xYY000 - *val = 0xe28cca00 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add+4)) >> 12)) - - return true + return 0xe28cca00 + (0xff & (int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add+4)) >> 12)), true case objabi.R_PLT2: // ldr pc, [ip, #0xZZZ]! - *val = 0xe5bcf000 + (0xfff & int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add+8))) - - return true + return 0xe5bcf000 + (0xfff & int64(uint32(ld.Symaddr(r.Sym)-(ld.Symaddr(ctxt.Syms.Lookup(".plt", 0))+int64(r.Off))+r.Add+8))), true case objabi.R_CALLARM: // bl XXXXXX or b YYYYYY // r.Add is the instruction // low 24-bit encodes the target address @@ -640,12 +632,10 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { if t > 0x7fffff || t < -0x800000 { ld.Errorf(s, "direct call too far: %s %x", r.Sym.Name, t) } - *val = int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&t))) - - return true + return int64(braddoff(int32(0xff000000&uint32(r.Add)), int32(0xffffff&t))), true } - return false + return val, false } func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 { diff --git a/src/cmd/link/internal/arm64/asm.go b/src/cmd/link/internal/arm64/asm.go index 5b3b9e588049b..770590fd356a0 100644 --- a/src/cmd/link/internal/arm64/asm.go +++ b/src/cmd/link/internal/arm64/asm.go @@ -234,19 +234,19 @@ func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, se return true } -func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { +func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) { if ctxt.LinkMode == ld.LinkExternal { switch r.Type { default: - return false + return val, false case objabi.R_ARM64_GOTPCREL: var o1, o2 uint32 if ctxt.Arch.ByteOrder == binary.BigEndian { - o1 = uint32(*val >> 32) - o2 = uint32(*val) + o1 = uint32(val >> 32) + o2 = uint32(val) } else { - o1 = uint32(*val) - o2 = uint32(*val >> 32) + o1 = uint32(val) + o2 = uint32(val >> 32) } // Any relocation against a function symbol is redirected to // be against a local symbol instead (see putelfsym in @@ -264,9 +264,9 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { r.Type = objabi.R_ADDRARM64 } if ctxt.Arch.ByteOrder == binary.BigEndian { - *val = int64(o1)<<32 | int64(o2) + val = int64(o1)<<32 | int64(o2) } else { - *val = int64(o2)<<32 | int64(o1) + val = int64(o2)<<32 | int64(o1) } fallthrough case objabi.R_ADDRARM64: @@ -294,11 +294,11 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { var o0, o1 uint32 if ctxt.Arch.ByteOrder == binary.BigEndian { - o0 = uint32(*val >> 32) - o1 = uint32(*val) + o0 = uint32(val >> 32) + o1 = uint32(val) } else { - o0 = uint32(*val) - o1 = uint32(*val >> 32) + o0 = uint32(val) + o1 = uint32(val >> 32) } // Mach-O wants the addend to be encoded in the instruction // Note that although Mach-O supports ARM64_RELOC_ADDEND, it @@ -311,30 +311,28 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { // when laid out, the instruction order must always be o1, o2. if ctxt.Arch.ByteOrder == binary.BigEndian { - *val = int64(o0)<<32 | int64(o1) + val = int64(o0)<<32 | int64(o1) } else { - *val = int64(o1)<<32 | int64(o0) + val = int64(o1)<<32 | int64(o0) } } - return true + return val, true case objabi.R_CALLARM64, objabi.R_ARM64_TLS_LE, objabi.R_ARM64_TLS_IE: r.Done = false r.Xsym = r.Sym r.Xadd = r.Add - return true + return val, true } } switch r.Type { case objabi.R_CONST: - *val = r.Add - return true + return r.Add, true case objabi.R_GOTOFF: - *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) - return true + return ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)), true case objabi.R_ADDRARM64: t := ld.Symaddr(r.Sym) + r.Add - ((s.Value + int64(r.Off)) &^ 0xfff) if t >= 1<<32 || t < -1<<32 { @@ -344,11 +342,11 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { var o0, o1 uint32 if ctxt.Arch.ByteOrder == binary.BigEndian { - o0 = uint32(*val >> 32) - o1 = uint32(*val) + o0 = uint32(val >> 32) + o1 = uint32(val) } else { - o0 = uint32(*val) - o1 = uint32(*val >> 32) + o0 = uint32(val) + o1 = uint32(val >> 32) } o0 |= (uint32((t>>12)&3) << 29) | (uint32((t>>12>>2)&0x7ffff) << 5) @@ -356,11 +354,9 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { // when laid out, the instruction order must always be o1, o2. if ctxt.Arch.ByteOrder == binary.BigEndian { - *val = int64(o0)<<32 | int64(o1) - } else { - *val = int64(o1)<<32 | int64(o0) + return int64(o0)<<32 | int64(o1), true } - return true + return int64(o1)<<32 | int64(o0), true case objabi.R_ARM64_TLS_LE: r.Done = false if ctxt.HeadType != objabi.Hlinux { @@ -372,18 +368,16 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { if v < 0 || v >= 32678 { ld.Errorf(s, "TLS offset out of range %d", v) } - *val |= v << 5 - return true + return val | (v << 5), true case objabi.R_CALLARM64: t := (ld.Symaddr(r.Sym) + r.Add) - (s.Value + int64(r.Off)) if t >= 1<<27 || t < -1<<27 { ld.Errorf(s, "program too large, call relocation distance = %d", t) } - *val |= (t >> 2) & 0x03ffffff - return true + return val | ((t >> 2) & 0x03ffffff), true } - return false + return val, false } func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 { diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 0ae93f1018555..d71b8b6ac7b61 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -198,7 +198,9 @@ func relocsym(ctxt *Link, s *sym.Symbol) { case 8: o = int64(ctxt.Arch.ByteOrder.Uint64(s.P[off:])) } - if !thearch.Archreloc(ctxt, r, s, &o) { + if offset, ok := thearch.Archreloc(ctxt, r, s, o); ok { + o = offset + } else { Errorf(s, "unknown reloc to %v: %d (%s)", r.Sym.Name, r.Type, sym.RelocName(ctxt.Arch, r.Type)) } case objabi.R_TLS_LE: diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 220aab310f06d..9f8945775370d 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -104,7 +104,7 @@ type Arch struct { Solarisdynld string Adddynrel func(*Link, *sym.Symbol, *sym.Reloc) bool Archinit func(*Link) - Archreloc func(*Link, *sym.Reloc, *sym.Symbol, *int64) bool + Archreloc func(*Link, *sym.Reloc, *sym.Symbol, int64) (int64, bool) Archrelocvariant func(*Link, *sym.Reloc, *sym.Symbol, int64) int64 Trampoline func(*Link, *sym.Reloc, *sym.Symbol) Asmb func(*Link) diff --git a/src/cmd/link/internal/mips/asm.go b/src/cmd/link/internal/mips/asm.go index 306d53f571579..8409e43afcbcf 100644 --- a/src/cmd/link/internal/mips/asm.go +++ b/src/cmd/link/internal/mips/asm.go @@ -82,23 +82,25 @@ func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, se return false } -func applyrel(arch *sys.Arch, r *sym.Reloc, s *sym.Symbol, val *int64, t int64) { +func applyrel(arch *sys.Arch, r *sym.Reloc, s *sym.Symbol, val int64, t int64) int64 { o := arch.ByteOrder.Uint32(s.P[r.Off:]) switch r.Type { case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSTLS: - *val = int64(o&0xffff0000 | uint32(t)&0xffff) + return int64(o&0xffff0000 | uint32(t)&0xffff) case objabi.R_ADDRMIPSU: - *val = int64(o&0xffff0000 | uint32((t+(1<<15))>>16)&0xffff) + return int64(o&0xffff0000 | uint32((t+(1<<15))>>16)&0xffff) case objabi.R_CALLMIPS, objabi.R_JMPMIPS: - *val = int64(o&0xfc000000 | uint32(t>>2)&^0xfc000000) + return int64(o&0xfc000000 | uint32(t>>2)&^0xfc000000) + default: + return val } } -func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { +func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) { if ctxt.LinkMode == ld.LinkExternal { switch r.Type { default: - return false + return val, false case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSU: r.Done = false @@ -114,28 +116,23 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { ld.Errorf(s, "missing section for %s", rs.Name) } r.Xsym = rs - applyrel(ctxt.Arch, r, s, val, r.Xadd) - return true + return applyrel(ctxt.Arch, r, s, val, r.Xadd), true case objabi.R_ADDRMIPSTLS, objabi.R_CALLMIPS, objabi.R_JMPMIPS: r.Done = false r.Xsym = r.Sym r.Xadd = r.Add - applyrel(ctxt.Arch, r, s, val, r.Add) - return true + return applyrel(ctxt.Arch, r, s, val, r.Add), true } } switch r.Type { case objabi.R_CONST: - *val = r.Add - return true + return r.Add, true case objabi.R_GOTOFF: - *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) - return true + return ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)), true case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSU: t := ld.Symaddr(r.Sym) + r.Add - applyrel(ctxt.Arch, r, s, val, t) - return true + return applyrel(ctxt.Arch, r, s, val, t), true case objabi.R_CALLMIPS, objabi.R_JMPMIPS: t := ld.Symaddr(r.Sym) + r.Add @@ -148,19 +145,17 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { ld.Errorf(s, "direct call too far: %s %x", r.Sym.Name, t) } - applyrel(ctxt.Arch, r, s, val, t) - return true + return applyrel(ctxt.Arch, r, s, val, t), true case objabi.R_ADDRMIPSTLS: // thread pointer is at 0x7000 offset from the start of TLS data area t := ld.Symaddr(r.Sym) + r.Add - 0x7000 if t < -32768 || t >= 32678 { ld.Errorf(s, "TLS offset out of range %d", t) } - applyrel(ctxt.Arch, r, s, val, t) - return true + return applyrel(ctxt.Arch, r, s, val, t), true } - return false + return val, false } func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 { diff --git a/src/cmd/link/internal/mips64/asm.go b/src/cmd/link/internal/mips64/asm.go index 295a0aafaed71..51eba596dc796 100644 --- a/src/cmd/link/internal/mips64/asm.go +++ b/src/cmd/link/internal/mips64/asm.go @@ -99,11 +99,11 @@ func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, se return false } -func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { +func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) { if ctxt.LinkMode == ld.LinkExternal { switch r.Type { default: - return false + return val, false case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSU: r.Done = false @@ -121,34 +121,30 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { } r.Xsym = rs - return true + return val, true case objabi.R_ADDRMIPSTLS, objabi.R_CALLMIPS, objabi.R_JMPMIPS: r.Done = false r.Xsym = r.Sym r.Xadd = r.Add - return true + return val, true } } switch r.Type { case objabi.R_CONST: - *val = r.Add - return true + return r.Add, true case objabi.R_GOTOFF: - *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) - return true + return ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)), true case objabi.R_ADDRMIPS, objabi.R_ADDRMIPSU: t := ld.Symaddr(r.Sym) + r.Add o1 := ctxt.Arch.ByteOrder.Uint32(s.P[r.Off:]) if r.Type == objabi.R_ADDRMIPS { - *val = int64(o1&0xffff0000 | uint32(t)&0xffff) - } else { - *val = int64(o1&0xffff0000 | uint32((t+1<<15)>>16)&0xffff) + return int64(o1&0xffff0000 | uint32(t)&0xffff), true } - return true + return int64(o1&0xffff0000 | uint32((t+1<<15)>>16)&0xffff), true case objabi.R_ADDRMIPSTLS: // thread pointer is at 0x7000 offset from the start of TLS data area t := ld.Symaddr(r.Sym) + r.Add - 0x7000 @@ -156,18 +152,16 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { ld.Errorf(s, "TLS offset out of range %d", t) } o1 := ctxt.Arch.ByteOrder.Uint32(s.P[r.Off:]) - *val = int64(o1&0xffff0000 | uint32(t)&0xffff) - return true + return int64(o1&0xffff0000 | uint32(t)&0xffff), true case objabi.R_CALLMIPS, objabi.R_JMPMIPS: // Low 26 bits = (S + A) >> 2 t := ld.Symaddr(r.Sym) + r.Add o1 := ctxt.Arch.ByteOrder.Uint32(s.P[r.Off:]) - *val = int64(o1&0xfc000000 | uint32(t>>2)&^0xfc000000) - return true + return int64(o1&0xfc000000 | uint32(t>>2)&^0xfc000000), true } - return false + return val, false } func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 { diff --git a/src/cmd/link/internal/ppc64/asm.go b/src/cmd/link/internal/ppc64/asm.go index 11fdf1fb0501e..825366c567a7a 100644 --- a/src/cmd/link/internal/ppc64/asm.go +++ b/src/cmd/link/internal/ppc64/asm.go @@ -474,14 +474,14 @@ func symtoc(ctxt *ld.Link, s *sym.Symbol) int64 { return toc.Value } -func archrelocaddr(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { +func archrelocaddr(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) int64 { var o1, o2 uint32 if ctxt.Arch.ByteOrder == binary.BigEndian { - o1 = uint32(*val >> 32) - o2 = uint32(*val) + o1 = uint32(val >> 32) + o2 = uint32(val) } else { - o1 = uint32(*val) - o2 = uint32(*val >> 32) + o1 = uint32(val) + o2 = uint32(val >> 32) } // We are spreading a 31-bit address across two instructions, putting the @@ -510,15 +510,13 @@ func archrelocaddr(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool } o2 |= uint32(t) & 0xfffc default: - return false + return -1 } if ctxt.Arch.ByteOrder == binary.BigEndian { - *val = int64(o1)<<32 | int64(o2) - } else { - *val = int64(o2)<<32 | int64(o1) + return int64(o1)<<32 | int64(o2) } - return true + return int64(o2)<<32 | int64(o1) } // resolve direct jump relocation r in s, and add trampoline if necessary @@ -623,17 +621,17 @@ func gentramp(arch *sys.Arch, linkmode ld.LinkMode, tramp, target *sym.Symbol, o arch.ByteOrder.PutUint32(tramp.P[12:], o4) } -func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { +func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) { if ctxt.LinkMode == ld.LinkExternal { switch r.Type { default: - return false + return val, false case objabi.R_POWER_TLS, objabi.R_POWER_TLS_LE, objabi.R_POWER_TLS_IE: r.Done = false // check Outer is nil, Type is TLSBSS? r.Xadd = r.Add r.Xsym = r.Sym - return true + return val, true case objabi.R_ADDRPOWER, objabi.R_ADDRPOWER_DS, objabi.R_ADDRPOWER_TOCREL, @@ -655,24 +653,22 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { } r.Xsym = rs - return true + return val, true case objabi.R_CALLPOWER: r.Done = false r.Xsym = r.Sym r.Xadd = r.Add - return true + return val, true } } switch r.Type { case objabi.R_CONST: - *val = r.Add - return true + return r.Add, true case objabi.R_GOTOFF: - *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) - return true + return ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)), true case objabi.R_ADDRPOWER, objabi.R_ADDRPOWER_DS: - return archrelocaddr(ctxt, r, s, val) + return archrelocaddr(ctxt, r, s, val), true case objabi.R_CALLPOWER: // Bits 6 through 29 = (S + A - P) >> 2 @@ -686,12 +682,10 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { if int64(int32(t<<6)>>6) != t { ld.Errorf(s, "direct call too far: %s %x", r.Sym.Name, t) } - *val |= int64(uint32(t) &^ 0xfc000003) - return true + return val | int64(uint32(t)&^0xfc000003), true case objabi.R_POWER_TOC: // S + A - .TOC. - *val = ld.Symaddr(r.Sym) + r.Add - symtoc(ctxt, s) + return ld.Symaddr(r.Sym) + r.Add - symtoc(ctxt, s), true - return true case objabi.R_POWER_TLS_LE: // The thread pointer points 0x7000 bytes after the start of the // thread local storage area as documented in section "3.7.2 TLS @@ -701,11 +695,10 @@ func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { if int64(int16(v)) != v { ld.Errorf(s, "TLS offset out of range %d", v) } - *val = (*val &^ 0xffff) | (v & 0xffff) - return true + return (val &^ 0xffff) | (v & 0xffff), true } - return false + return val, false } func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 { diff --git a/src/cmd/link/internal/s390x/asm.go b/src/cmd/link/internal/s390x/asm.go index 634ba98dd3b44..215200721cdb7 100644 --- a/src/cmd/link/internal/s390x/asm.go +++ b/src/cmd/link/internal/s390x/asm.go @@ -384,21 +384,19 @@ func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, se return false } -func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { +func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) { if ctxt.LinkMode == ld.LinkExternal { - return false + return val, false } switch r.Type { case objabi.R_CONST: - *val = r.Add - return true + return r.Add, true case objabi.R_GOTOFF: - *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) - return true + return ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)), true } - return false + return val, false } func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 { diff --git a/src/cmd/link/internal/x86/asm.go b/src/cmd/link/internal/x86/asm.go index 3150aac6cfe36..4b45aff6537cc 100644 --- a/src/cmd/link/internal/x86/asm.go +++ b/src/cmd/link/internal/x86/asm.go @@ -491,20 +491,18 @@ func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, secto return true } -func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val *int64) bool { +func archreloc(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, val int64) (int64, bool) { if ctxt.LinkMode == ld.LinkExternal { - return false + return val, false } switch r.Type { case objabi.R_CONST: - *val = r.Add - return true + return r.Add, true case objabi.R_GOTOFF: - *val = ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)) - return true + return ld.Symaddr(r.Sym) + r.Add - ld.Symaddr(ctxt.Syms.Lookup(".got", 0)), true } - return false + return val, false } func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 { From 0fbaf6ca8b4939fbac8081f28aad12a0305afa35 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Wed, 11 Jul 2018 23:42:40 +0300 Subject: [PATCH 0047/1663] math,net: omit explicit true tag expr in switch Performed `switch true {}` => `switch {}` replacement. Found using https://go-critic.github.io/overview.html#switchTrue-ref Change-Id: Ib39ea98531651966a5a56b7bd729b46e4eeb7f7c Reviewed-on: https://go-review.googlesource.com/123378 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/math/sinh.go | 2 +- src/net/ip.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/math/sinh.go b/src/math/sinh.go index 39e7c2047a9ec..573a37e35fa2a 100644 --- a/src/math/sinh.go +++ b/src/math/sinh.go @@ -43,7 +43,7 @@ func sinh(x float64) float64 { } var temp float64 - switch true { + switch { case x > 21: temp = Exp(x) * 0.5 diff --git a/src/net/ip.go b/src/net/ip.go index da8dca588e5c8..410de92ccc2dc 100644 --- a/src/net/ip.go +++ b/src/net/ip.go @@ -222,7 +222,7 @@ func (ip IP) DefaultMask() IPMask { if ip = ip.To4(); ip == nil { return nil } - switch true { + switch { case ip[0] < 0x80: return classAMask case ip[0] < 0xC0: From 477b7e5f4d143c2e8d68e9ef9d4db8ebe84a8489 Mon Sep 17 00:00:00 2001 From: Xia Bin Date: Thu, 12 Jul 2018 18:00:39 +0800 Subject: [PATCH 0048/1663] cmd/internal/obj: remove pointless validation s.Func.Text only can be nil at the moment, otherwise there has some bugs in compiler's Go rumtime. Change-Id: Ib2ff9bb977352838e67f2b98a69468f6f350c1f3 Reviewed-on: https://go-review.googlesource.com/123535 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/internal/obj/plist.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cmd/internal/obj/plist.go b/src/cmd/internal/obj/plist.go index 0658cc73112cb..a8675055d90d4 100644 --- a/src/cmd/internal/obj/plist.go +++ b/src/cmd/internal/obj/plist.go @@ -119,9 +119,6 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int) { ctxt.Diag("InitTextSym double init for %s", s.Name) } s.Func = new(FuncInfo) - if s.Func.Text != nil { - ctxt.Diag("duplicate TEXT for %s", s.Name) - } if s.OnList() { ctxt.Diag("symbol %s listed multiple times", s.Name) } From d169a429c5f9f1d20114e09fb131bc205b5a74f9 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Sat, 4 Aug 2018 10:01:54 -0700 Subject: [PATCH 0049/1663] cmd/go: test whether alldocs.go is up to date A common error is to update the help text for a command in cmd/go, but fail to update alldocs.go, which actually prints the help text for the most common commands. Add a test that the long-form documentation help text matches the contents of alldocs.go, which will fail the build if we fail to keep the documentation in sync. We can get fancier with the test output if this is not sufficient. Fixes golang/go#26735. Change-Id: I2509765315eeb0f362633d812343d1324a01b73b Reviewed-on: https://go-review.googlesource.com/127920 Run-TryBot: Kevin Burke TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/go/alldocs.go | 5 ++++- src/cmd/go/help_test.go | 28 ++++++++++++++++++++++++++++ src/cmd/go/internal/help/help.go | 20 ++++++++++---------- src/cmd/go/main.go | 4 ++-- src/cmd/go/mkalldocs.sh | 2 ++ 5 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 src/cmd/go/help_test.go diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index c67e3f5a1c3bc..1585dd5b1f3f5 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -1003,13 +1003,16 @@ // // Usage: // -// go mod graph +// go mod graph [-dot] // // Graph prints the module requirement graph (with replacements applied) // in text form. Each line in the output has two space-separated fields: a module // and one of its requirements. Each module is identified as a string of the form // path@version, except for the main module, which has no @version suffix. // +// The -dot flag generates the output in graphviz format that can be used +// with a tool like dot to visually render the dependency graph. +// // // Initialize new module in current directory // diff --git a/src/cmd/go/help_test.go b/src/cmd/go/help_test.go new file mode 100644 index 0000000000000..ec6a9d11cbe2e --- /dev/null +++ b/src/cmd/go/help_test.go @@ -0,0 +1,28 @@ +// Copyright 2018 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. + +// +build !nacl + +package main_test + +import ( + "bytes" + "io/ioutil" + "testing" + + "cmd/go/internal/help" +) + +func TestDocsUpToDate(t *testing.T) { + buf := new(bytes.Buffer) + // Match the command in mkalldocs.sh that generates alldocs.go. + help.Help(buf, []string{"documentation"}) + data, err := ioutil.ReadFile("alldocs.go") + if err != nil { + t.Fatalf("error reading alldocs.go: %v", err) + } + if !bytes.Equal(data, buf.Bytes()) { + t.Errorf("alldocs.go is not up to date; run mkalldocs.sh to regenerate it") + } +} diff --git a/src/cmd/go/internal/help/help.go b/src/cmd/go/internal/help/help.go index a80afe36c412c..312a29590f43f 100644 --- a/src/cmd/go/internal/help/help.go +++ b/src/cmd/go/internal/help/help.go @@ -20,16 +20,16 @@ import ( ) // Help implements the 'help' command. -func Help(args []string) { +func Help(w io.Writer, args []string) { // 'go help documentation' generates doc.go. if len(args) == 1 && args[0] == "documentation" { - fmt.Println("// Copyright 2011 The Go Authors. All rights reserved.") - fmt.Println("// Use of this source code is governed by a BSD-style") - fmt.Println("// license that can be found in the LICENSE file.") - fmt.Println() - fmt.Println("// Code generated by mkalldocs.sh; DO NOT EDIT.") - fmt.Println("// Edit the documentation in other files and rerun mkalldocs.sh to generate this one.") - fmt.Println() + fmt.Fprintln(w, "// Copyright 2011 The Go Authors. All rights reserved.") + fmt.Fprintln(w, "// Use of this source code is governed by a BSD-style") + fmt.Fprintln(w, "// license that can be found in the LICENSE file.") + fmt.Fprintln(w) + fmt.Fprintln(w, "// Code generated by mkalldocs.sh; DO NOT EDIT.") + fmt.Fprintln(w, "// Edit the documentation in other files and rerun mkalldocs.sh to generate this one.") + fmt.Fprintln(w) buf := new(bytes.Buffer) PrintUsage(buf, base.Go) usage := &base.Command{Long: buf.String()} @@ -42,8 +42,8 @@ func Help(args []string) { cmds = append(cmds, cmd) cmds = append(cmds, cmd.Commands...) } - tmpl(&commentWriter{W: os.Stdout}, documentationTemplate, cmds) - fmt.Println("package main") + tmpl(&commentWriter{W: w}, documentationTemplate, cmds) + fmt.Fprintln(w, "package main") return } diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index 0639b4d2ca09f..f64ffeb6708f9 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -95,7 +95,7 @@ func main() { cfg.CmdName = args[0] // for error messages if args[0] == "help" { - help.Help(args[1:]) + help.Help(os.Stdout, args[1:]) return } @@ -199,7 +199,7 @@ BigCmdLoop: } if args[0] == "help" { // Accept 'go mod help' and 'go mod help foo' for 'go help mod' and 'go help mod foo'. - help.Help(append(strings.Split(cfg.CmdName, " "), args[1:]...)) + help.Help(os.Stdout, append(strings.Split(cfg.CmdName, " "), args[1:]...)) return } cfg.CmdName += " " + args[0] diff --git a/src/cmd/go/mkalldocs.sh b/src/cmd/go/mkalldocs.sh index 72886db1eac7e..4e7a50980541e 100755 --- a/src/cmd/go/mkalldocs.sh +++ b/src/cmd/go/mkalldocs.sh @@ -6,6 +6,8 @@ set -e go build -o go.latest +# If the command used to generate alldocs.go changes, update TestDocsUpToDate in +# help_test.go. ./go.latest help documentation >alldocs.go gofmt -w alldocs.go rm go.latest From 85a0192b59d8d9be9cb3759d128b43a5ebf2d766 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 20 Aug 2018 21:04:15 +0000 Subject: [PATCH 0050/1663] net/http: add Client.CloseIdleConnections Fixes #26563 Change-Id: I22b0c72d45fab9d3f31fda04da76a8c0b10cd8b6 Reviewed-on: https://go-review.googlesource.com/130115 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Andrew Bonventre --- src/net/http/client.go | 16 ++++++++++++++++ src/net/http/client_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/net/http/client.go b/src/net/http/client.go index 8f69a298e3fcf..a15b3ba2761ed 100644 --- a/src/net/http/client.go +++ b/src/net/http/client.go @@ -833,6 +833,22 @@ func (c *Client) Head(url string) (resp *Response, err error) { return c.Do(req) } +// CloseIdleConnections closes any connections on its Transport which +// were previously connected from previous requests but are now +// sitting idle in a "keep-alive" state. It does not interrupt any +// connections currently in use. +// +// If the Client's Transport does not have a CloseIdleConnections method +// then this method does nothing. +func (c *Client) CloseIdleConnections() { + type closeIdler interface { + CloseIdleConnections() + } + if tr, ok := c.transport().(closeIdler); ok { + tr.CloseIdleConnections() + } +} + // cancelTimerBody is an io.ReadCloser that wraps rc with two features: // 1) on Read error or close, the stop func is called. // 2) On Read failure, if reqDidTimeout is true, the error is wrapped and diff --git a/src/net/http/client_test.go b/src/net/http/client_test.go index bfc793e638cae..12764d3bf1e40 100644 --- a/src/net/http/client_test.go +++ b/src/net/http/client_test.go @@ -1888,3 +1888,27 @@ func TestTransportBodyReadError(t *testing.T) { t.Errorf("close calls = %d; want 1", closeCalls) } } + +type roundTripperWithoutCloseIdle struct{} + +func (roundTripperWithoutCloseIdle) RoundTrip(*Request) (*Response, error) { panic("unused") } + +type roundTripperWithCloseIdle func() // underlying func is CloseIdleConnections func + +func (roundTripperWithCloseIdle) RoundTrip(*Request) (*Response, error) { panic("unused") } +func (f roundTripperWithCloseIdle) CloseIdleConnections() { f() } + +func TestClientCloseIdleConnections(t *testing.T) { + c := &Client{Transport: roundTripperWithoutCloseIdle{}} + c.CloseIdleConnections() // verify we don't crash at least + + closed := false + var tr RoundTripper = roundTripperWithCloseIdle(func() { + closed = true + }) + c = &Client{Transport: tr} + c.CloseIdleConnections() + if !closed { + t.Error("not closed") + } +} From 0b30cf534a03618162d3015c8705dd2231e34703 Mon Sep 17 00:00:00 2001 From: Santhosh Kumar Tekuri Date: Fri, 22 Jun 2018 16:50:31 +0530 Subject: [PATCH 0051/1663] archive/zip: makes receiver name consistent Change-Id: I4d6f7440747d4f935acddc9a5c5928ed911a2fb0 Reviewed-on: https://go-review.googlesource.com/120515 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/archive/zip/struct.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/archive/zip/struct.go b/src/archive/zip/struct.go index c90151d9d44bb..bd637d185b743 100644 --- a/src/archive/zip/struct.go +++ b/src/archive/zip/struct.go @@ -303,8 +303,8 @@ func (h *FileHeader) SetMode(mode os.FileMode) { } // isZip64 reports whether the file size exceeds the 32 bit limit -func (fh *FileHeader) isZip64() bool { - return fh.CompressedSize64 >= uint32max || fh.UncompressedSize64 >= uint32max +func (h *FileHeader) isZip64() bool { + return h.CompressedSize64 >= uint32max || h.UncompressedSize64 >= uint32max } func msdosModeToFileMode(m uint32) (mode os.FileMode) { From 539ff607a70bb6f7f12b1bca6b365ab0af448fcf Mon Sep 17 00:00:00 2001 From: Jeet Parekh Date: Wed, 1 Aug 2018 02:47:01 +0000 Subject: [PATCH 0052/1663] archive/zip: return error from NewReader when negative size is passed Fixes #26589 Change-Id: I180883a13cec229093654004b42c48d76ee20272 GitHub-Last-Rev: 2d9879de43fbcfb413116d69accdade6bc042c97 GitHub-Pull-Request: golang/go#26667 Reviewed-on: https://go-review.googlesource.com/126617 Reviewed-by: Brad Fitzpatrick Run-TryBot: Joe Tsai TryBot-Result: Gobot Gobot --- src/archive/zip/reader.go | 3 +++ src/archive/zip/reader_test.go | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/src/archive/zip/reader.go b/src/archive/zip/reader.go index 2444106ba69e9..2260b398c34e9 100644 --- a/src/archive/zip/reader.go +++ b/src/archive/zip/reader.go @@ -69,6 +69,9 @@ func OpenReader(name string) (*ReadCloser, error) { // NewReader returns a new Reader reading from r, which is assumed to // have the given size in bytes. func NewReader(r io.ReaderAt, size int64) (*Reader, error) { + if size < 0 { + return nil, errors.New("zip: size cannot be negative") + } zr := new(Reader) if err := zr.init(r, size); err != nil { return nil, err diff --git a/src/archive/zip/reader_test.go b/src/archive/zip/reader_test.go index 1e58b26b6e981..6b3f2f33bb4f2 100644 --- a/src/archive/zip/reader_test.go +++ b/src/archive/zip/reader_test.go @@ -658,6 +658,12 @@ func TestInvalidFiles(t *testing.T) { if err != ErrFormat { t.Errorf("sigs: error=%v, want %v", err, ErrFormat) } + + // negative size + _, err = NewReader(bytes.NewReader([]byte("foobar")), -1) + if err == nil { + t.Errorf("archive/zip.NewReader: expected error when negative size is passed") + } } func messWith(fileName string, corrupter func(b []byte)) (r io.ReaderAt, size int64) { From 692307aa839252285ebb91b4072e3c05ff554341 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 19 Aug 2018 13:53:57 +0100 Subject: [PATCH 0053/1663] cmd/go: fix modload infinite directory loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is possible to enter the parent-walking directory loop in a way that it will loop forever - if mdir is empty, and d reaches ".". To avoid this, make sure that the 'd = filepath.Dir(d)' step only happens if the parent directory is actually different than the current directory. This fixes some of the tests like TestImport/golang.org_x_net_context, which were never finishing before. While at it, also fix TestImport/golang.org_x_net, which seems to have the wrong expected error. The root of the x/net repo doesn't have a go.mod file, nor is part of a module itself, so it seems like the expected error should reflect that. After these two changes, 'go test cmd/go/internal/modload' passes on my linux/amd64 machine. Fixes #27080. Change-Id: Ie8bab0f9fbc9f447844cbbc64117420d9087db1b Reviewed-on: https://go-review.googlesource.com/129778 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/go/internal/modload/import.go | 9 ++++++++- src/cmd/go/internal/modload/import_test.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go index 78ae83e4bf3b5..12d9407f6e696 100644 --- a/src/cmd/go/internal/modload/import.go +++ b/src/cmd/go/internal/modload/import.go @@ -181,7 +181,7 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile // So we only check local module trees // (the main module, and any directory trees pointed at by replace directives). if isLocal { - for d := dir; d != mdir && len(d) > len(mdir); d = filepath.Dir(d) { + for d := dir; d != mdir && len(d) > len(mdir); { haveGoMod := haveGoModCache.Do(d, func() interface{} { _, err := os.Stat(filepath.Join(d, "go.mod")) return err == nil @@ -190,6 +190,13 @@ func dirInModule(path, mpath, mdir string, isLocal bool) (dir string, haveGoFile if haveGoMod { return "", false } + parent := filepath.Dir(d) + if parent == d { + // Break the loop, as otherwise we'd loop + // forever if d=="." and mdir=="". + break + } + d = parent } } diff --git a/src/cmd/go/internal/modload/import_test.go b/src/cmd/go/internal/modload/import_test.go index 8e01dc50916a3..3f4ddab436cc4 100644 --- a/src/cmd/go/internal/modload/import_test.go +++ b/src/cmd/go/internal/modload/import_test.go @@ -21,7 +21,7 @@ var importTests = []struct { }, { path: "golang.org/x/net", - err: "missing module for import: golang.org/x/net@.* provides golang.org/x/net", + err: "cannot find module providing package golang.org/x/net", }, { path: "golang.org/x/text", From 89d533e368395a5ba3157d9a89d346dd7b50ba51 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Wed, 11 Jul 2018 23:45:57 +0300 Subject: [PATCH 0054/1663] archive/tar: remore redundant parens in type expressions Simplify `(T)` expressions to `T` where possible. Found using https://go-critic.github.io/overview.html#typeUnparen-ref Change-Id: Ic5ef335e03898f9fea1ff90fd83956376657fe67 Reviewed-on: https://go-review.googlesource.com/123379 Run-TryBot: Iskander Sharipov Run-TryBot: Joe Tsai TryBot-Result: Gobot Gobot Reviewed-by: Joe Tsai --- src/archive/tar/format.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/archive/tar/format.go b/src/archive/tar/format.go index 1f89d0c59a159..cfe24a5e1d339 100644 --- a/src/archive/tar/format.go +++ b/src/archive/tar/format.go @@ -160,7 +160,7 @@ func (b *block) V7() *headerV7 { return (*headerV7)(b) } func (b *block) GNU() *headerGNU { return (*headerGNU)(b) } func (b *block) STAR() *headerSTAR { return (*headerSTAR)(b) } func (b *block) USTAR() *headerUSTAR { return (*headerUSTAR)(b) } -func (b *block) Sparse() sparseArray { return (sparseArray)(b[:]) } +func (b *block) Sparse() sparseArray { return sparseArray(b[:]) } // GetFormat checks that the block is a valid tar header based on the checksum. // It then attempts to guess the specific format based on magic values. @@ -263,7 +263,7 @@ func (h *headerGNU) DevMajor() []byte { return h[329:][:8] } func (h *headerGNU) DevMinor() []byte { return h[337:][:8] } func (h *headerGNU) AccessTime() []byte { return h[345:][:12] } func (h *headerGNU) ChangeTime() []byte { return h[357:][:12] } -func (h *headerGNU) Sparse() sparseArray { return (sparseArray)(h[386:][:24*4+1]) } +func (h *headerGNU) Sparse() sparseArray { return sparseArray(h[386:][:24*4+1]) } func (h *headerGNU) RealSize() []byte { return h[483:][:12] } type headerSTAR [blockSize]byte @@ -293,7 +293,7 @@ func (h *headerUSTAR) Prefix() []byte { return h[345:][:155] } type sparseArray []byte -func (s sparseArray) Entry(i int) sparseElem { return (sparseElem)(s[i*24:]) } +func (s sparseArray) Entry(i int) sparseElem { return sparseElem(s[i*24:]) } func (s sparseArray) IsExtended() []byte { return s[24*s.MaxEntries():][:1] } func (s sparseArray) MaxEntries() int { return len(s) / 24 } From 77c575d2e2cc320b62cbbdefbc6840a8cff2163c Mon Sep 17 00:00:00 2001 From: Tim Cooper Date: Mon, 30 Jul 2018 18:59:08 -0300 Subject: [PATCH 0055/1663] net/http: remove unnecessary return Change-Id: I93bc5de6bcb23c2639d7c2f3f5252fb6f09ca6e4 Reviewed-on: https://go-review.googlesource.com/126797 Reviewed-by: Brad Fitzpatrick --- src/net/http/server.go | 1 - 1 file changed, 1 deletion(-) diff --git a/src/net/http/server.go b/src/net/http/server.go index c24ad750f2114..449cfe51210f4 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -3176,7 +3176,6 @@ func (h *timeoutHandler) ServeHTTP(w ResponseWriter, r *Request) { w.WriteHeader(StatusServiceUnavailable) io.WriteString(w, h.errorBody()) tw.timedOut = true - return } } From 00379be17e63a5b75b3237819392d2dc3b313a27 Mon Sep 17 00:00:00 2001 From: Alan Braithwaite Date: Tue, 21 Aug 2018 01:07:47 +0000 Subject: [PATCH 0056/1663] net/http: fix cookie SameSite docs grammar Change-Id: I76d878343c1cc14b53c700b0476ca050c1f9e6be GitHub-Last-Rev: 148a45f4b63f7f55312112bbbd982f9927ac9e6e GitHub-Pull-Request: golang/go#27107 Reviewed-on: https://go-review.googlesource.com/130235 Reviewed-by: Brad Fitzpatrick --- src/net/http/cookie.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/net/http/cookie.go b/src/net/http/cookie.go index b1a6cef6f700f..382398756bda6 100644 --- a/src/net/http/cookie.go +++ b/src/net/http/cookie.go @@ -36,10 +36,10 @@ type Cookie struct { Unparsed []string // Raw text of unparsed attribute-value pairs } -// SameSite allows a server define a cookie attribute making it impossible to -// the browser send this cookie along with cross-site requests. The main goal -// is mitigate the risk of cross-origin information leakage, and provides some -// protection against cross-site request forgery attacks. +// SameSite allows a server define a cookie attribute making it impossible for +// the browser to send this cookie along with cross-site requests. The main +// goal is mitigate the risk of cross-origin information leakage, and provides +// some protection against cross-site request forgery attacks. // // See https://tools.ietf.org/html/draft-ietf-httpbis-cookie-same-site-00 for details. type SameSite int From 352583ff774d33539aeef4a3ce471406880b586d Mon Sep 17 00:00:00 2001 From: Tim Cooper Date: Tue, 5 Jun 2018 21:05:11 -0300 Subject: [PATCH 0057/1663] encoding/hex: pre-allocate Dump buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old time/op new time/op delta Dump/256-4 7.76µs ± 2% 5.82µs ± 2% -24.91% (p=0.008 n=5+5) Dump/1024-4 28.4µs ± 2% 22.6µs ± 3% -20.58% (p=0.008 n=5+5) Dump/4096-4 112µs ± 2% 88µs ± 0% -20.80% (p=0.016 n=5+4) Dump/16384-4 444µs ± 3% 361µs ± 7% -18.73% (p=0.008 n=5+5) name old alloc/op new alloc/op delta Dump/256-4 4.00kB ± 0% 1.39kB ± 0% -65.20% (p=0.008 n=5+5) Dump/1024-4 16.2kB ± 0% 5.5kB ± 0% -66.04% (p=0.008 n=5+5) Dump/4096-4 63.9kB ± 0% 20.6kB ± 0% -67.78% (p=0.008 n=5+5) Dump/16384-4 265kB ± 0% 82kB ± 0% -69.00% (p=0.008 n=5+5) name old allocs/op new allocs/op delta Dump/256-4 7.00 ± 0% 3.00 ± 0% -57.14% (p=0.008 n=5+5) Dump/1024-4 9.00 ± 0% 3.00 ± 0% -66.67% (p=0.008 n=5+5) Dump/4096-4 11.0 ± 0% 3.0 ± 0% -72.73% (p=0.008 n=5+5) Dump/16384-4 13.0 ± 0% 3.0 ± 0% -76.92% (p=0.008 n=5+5) Change-Id: I0a0d6de315b979142b05e333880da8a5e52b12ef Reviewed-on: https://go-review.googlesource.com/116495 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/encoding/hex/hex.go | 13 +++++++++++-- src/encoding/hex/hex_test.go | 13 +++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/encoding/hex/hex.go b/src/encoding/hex/hex.go index aee5aecb1a757..2bb2b57df9cd9 100644 --- a/src/encoding/hex/hex.go +++ b/src/encoding/hex/hex.go @@ -6,10 +6,10 @@ package hex import ( - "bytes" "errors" "fmt" "io" + "strings" ) const hextable = "0123456789abcdef" @@ -116,7 +116,16 @@ func DecodeString(s string) ([]byte, error) { // Dump returns a string that contains a hex dump of the given data. The format // of the hex dump matches the output of `hexdump -C` on the command line. func Dump(data []byte) string { - var buf bytes.Buffer + if len(data) == 0 { + return "" + } + + var buf strings.Builder + // Dumper will write 79 bytes per complete 16 byte chunk, and at least + // 64 bytes for whatever remains. Round the allocation up, since only a + // maximum of 15 bytes will be wasted. + buf.Grow((1 + ((len(data) - 1) / 16)) * 79) + dumper := Dumper(&buf) dumper.Write(data) dumper.Close() diff --git a/src/encoding/hex/hex_test.go b/src/encoding/hex/hex_test.go index 6ba054ef9a0df..e9f4b3a53adef 100644 --- a/src/encoding/hex/hex_test.go +++ b/src/encoding/hex/hex_test.go @@ -248,3 +248,16 @@ func BenchmarkEncode(b *testing.B) { }) } } + +func BenchmarkDump(b *testing.B) { + for _, size := range []int{256, 1024, 4096, 16384} { + src := bytes.Repeat([]byte{2, 3, 5, 7, 9, 11, 13, 17}, size/8) + sink = make([]byte, 2*size) + + b.Run(fmt.Sprintf("%v", size), func(b *testing.B) { + for i := 0; i < b.N; i++ { + Dump(src) + } + }) + } +} From 0ca3203becb917b17a1a0b1903381b3d9690fcfc Mon Sep 17 00:00:00 2001 From: Jan Lehnardt Date: Wed, 8 Aug 2018 14:27:18 +0000 Subject: [PATCH 0058/1663] syscall: add S_IRWXG and S_IRWXO to FreeBSD types Companion PR to https://github.com/golang/sys/pull/13 Change-Id: I097fc97912840eb69ca232eded6ba939de0fead9 GitHub-Last-Rev: f8a8f7d96c96e3cb03010cb3d9607741f4bbc3a1 GitHub-Pull-Request: golang/go#26675 Reviewed-on: https://go-review.googlesource.com/126621 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/syscall/types_freebsd.go | 2 ++ src/syscall/ztypes_freebsd_386.go | 2 ++ src/syscall/ztypes_freebsd_amd64.go | 2 ++ src/syscall/ztypes_freebsd_arm.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/syscall/types_freebsd.go b/src/syscall/types_freebsd.go index 020045bf84b71..066a4acbd7f90 100644 --- a/src/syscall/types_freebsd.go +++ b/src/syscall/types_freebsd.go @@ -198,6 +198,8 @@ const ( // Directory mode bits S_IRUSR = C.S_IRUSR S_IWUSR = C.S_IWUSR S_IXUSR = C.S_IXUSR + S_IRWXG = C.S_IRWXG + S_IRWXO = C.S_IRWXO ) type Stat_t C.struct_stat8 diff --git a/src/syscall/ztypes_freebsd_386.go b/src/syscall/ztypes_freebsd_386.go index c9c58f9fe7af4..242a73d1de8bc 100644 --- a/src/syscall/ztypes_freebsd_386.go +++ b/src/syscall/ztypes_freebsd_386.go @@ -71,6 +71,8 @@ const ( S_IRUSR = 0x100 S_IWUSR = 0x80 S_IXUSR = 0x40 + S_IRWXG = 0x38 + S_IRWXO = 0x7 ) type Stat_t struct { diff --git a/src/syscall/ztypes_freebsd_amd64.go b/src/syscall/ztypes_freebsd_amd64.go index 847527cdda28a..8b34cde2eec00 100644 --- a/src/syscall/ztypes_freebsd_amd64.go +++ b/src/syscall/ztypes_freebsd_amd64.go @@ -71,6 +71,8 @@ const ( S_IRUSR = 0x100 S_IWUSR = 0x80 S_IXUSR = 0x40 + S_IRWXG = 0x38 + S_IRWXO = 0x7 ) type Stat_t struct { diff --git a/src/syscall/ztypes_freebsd_arm.go b/src/syscall/ztypes_freebsd_arm.go index 83108dd1c43c4..4fd6bd509c7aa 100644 --- a/src/syscall/ztypes_freebsd_arm.go +++ b/src/syscall/ztypes_freebsd_arm.go @@ -73,6 +73,8 @@ const ( S_IRUSR = 0x100 S_IWUSR = 0x80 S_IXUSR = 0x40 + S_IRWXG = 0x38 + S_IRWXO = 0x7 ) type Stat_t struct { From 97c7e0e0ad1be5c4d211e0182ff970a2086e7679 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philip=20B=C3=B8rgesen?= Date: Tue, 21 Aug 2018 00:52:46 +0000 Subject: [PATCH 0059/1663] encoding/json: eliminate superfluous space in Decoder.Token error messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing Decoder.tokenError implementation creates its error messages by concatenating "invalid character " + quoteChar(c) + " " + context. All context values however already start with a space leading to error messages containing two spaces. This change removes " " from the concatenation expression. Fixes #26587 Change-Id: I93d14319396636b2a40d55053bda88c98e94a81a GitHub-Last-Rev: 6db7e1991b15beee601f558be72a2737070d8f68 GitHub-Pull-Request: golang/go#26588 Reviewed-on: https://go-review.googlesource.com/125775 Reviewed-by: Brad Fitzpatrick Reviewed-by: Daniel Martí Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/encoding/json/stream.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/encoding/json/stream.go b/src/encoding/json/stream.go index 75a4270df7de1..63aa0309555ef 100644 --- a/src/encoding/json/stream.go +++ b/src/encoding/json/stream.go @@ -471,7 +471,7 @@ func (dec *Decoder) tokenError(c byte) (Token, error) { case tokenObjectComma: context = " after object key:value pair" } - return nil, &SyntaxError{"invalid character " + quoteChar(c) + " " + context, dec.offset()} + return nil, &SyntaxError{"invalid character " + quoteChar(c) + context, dec.offset()} } // More reports whether there is another element in the From bc276c585b24a5e3adb9c6cdfebc4d69d910cc2e Mon Sep 17 00:00:00 2001 From: isharipo Date: Thu, 17 May 2018 19:47:52 +0300 Subject: [PATCH 0060/1663] cmd/link/internal/ld: avoid Reloc copies in range loops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Copying sym.Reloc in loops hurts performance as it has 48 byte size (on 64-bit platforms). There are quite many symbols and each of them has more than 1 relocation (so, it's possible to have more than 1kk relocs). The're also traversed more than once in some code paths. By using pointers to them, copies are avoided. For linking "hello world" example from net/http: name old time/op new time/op delta Linker-4 530ms ± 2% 521ms ± 3% -1.80% (p=0.000 n=17+20) Change-Id: I6518aec69d6adcd137f84b5c089ceab4cb4ea2dd Reviewed-on: https://go-review.googlesource.com/113636 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/link/internal/ld/ar.go | 3 ++- src/cmd/link/internal/ld/data.go | 3 ++- src/cmd/link/internal/ld/deadcode.go | 4 ++-- src/cmd/link/internal/ld/dwarf.go | 9 ++++++--- src/cmd/link/internal/ld/lib.go | 3 ++- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cmd/link/internal/ld/ar.go b/src/cmd/link/internal/ld/ar.go index ae7554c929609..779f3565f9d3a 100644 --- a/src/cmd/link/internal/ld/ar.go +++ b/src/cmd/link/internal/ld/ar.go @@ -105,7 +105,8 @@ func hostArchive(ctxt *Link, name string) { for any { var load []uint64 for _, s := range ctxt.Syms.Allsym { - for _, r := range s.R { + for i := range s.R { + r := &s.R[i] // Copying sym.Reloc has measurable impact on peformance if r.Sym != nil && r.Sym.Type == sym.SXREF { if off := armap[r.Sym.Name]; off != 0 && !loaded[off] { load = append(load, off) diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index d71b8b6ac7b61..5dd4aac03e376 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -772,7 +772,8 @@ func Datblk(ctxt *Link, addr int64, size int64) { if ctxt.LinkMode != LinkExternal { continue } - for _, r := range sym.R { + for i := range sym.R { + r := &sym.R[i] // Copying sym.Reloc has measurable impact on peformance rsname := "" if r.Sym != nil { rsname = r.Sym.Name diff --git a/src/cmd/link/internal/ld/deadcode.go b/src/cmd/link/internal/ld/deadcode.go index 540f4068cb8ea..df989cc94486a 100644 --- a/src/cmd/link/internal/ld/deadcode.go +++ b/src/cmd/link/internal/ld/deadcode.go @@ -245,8 +245,8 @@ func (d *deadcodepass) init() { // but we do keep the symbols it refers to. exports := d.ctxt.Syms.ROLookup("go.plugin.exports", 0) if exports != nil { - for _, r := range exports.R { - d.mark(r.Sym, nil) + for i := range exports.R { + d.mark(exports.R[i].Sym, nil) } } } diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index ae6f90b079c5c..c803180cadd08 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -1061,7 +1061,8 @@ func getCompilationDir() string { func importInfoSymbol(ctxt *Link, dsym *sym.Symbol) { dsym.Attr |= sym.AttrNotInSymbolTable | sym.AttrReachable dsym.Type = sym.SDWARFINFO - for _, r := range dsym.R { + for i := range dsym.R { + r := &dsym.R[i] // Copying sym.Reloc has measurable impact on peformance if r.Type == objabi.R_DWARFSECREF && r.Sym.Size == 0 { if ctxt.BuildMode == BuildModeShared { // These type symbols may not be present in BuildModeShared. Skip. @@ -1090,7 +1091,8 @@ func collectAbstractFunctions(ctxt *Link, fn *sym.Symbol, dsym *sym.Symbol, absf // Walk the relocations on the primary subprogram DIE and look for // references to abstract funcs. - for _, reloc := range dsym.R { + for i := range dsym.R { + reloc := &dsym.R[i] // Copying sym.Reloc has measurable impact on peformance candsym := reloc.Sym if reloc.Type != objabi.R_DWARFSECREF { continue @@ -1801,7 +1803,8 @@ func collectlocs(ctxt *Link, syms []*sym.Symbol, units []*compilationUnit) []*sy empty := true for _, u := range units { for _, fn := range u.funcDIEs { - for _, reloc := range fn.R { + for i := range fn.R { + reloc := &fn.R[i] // Copying sym.Reloc has measurable impact on peformance if reloc.Type == objabi.R_DWARFSECREF && strings.HasPrefix(reloc.Sym.Name, dwarf.LocPrefix) { reloc.Sym.Attr |= sym.AttrReachable | sym.AttrNotInSymbolTable syms = append(syms, reloc.Sym) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 9f8945775370d..d86b2aa5446ac 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -503,7 +503,8 @@ func (ctxt *Link) loadlib() { // objects, try to read them from the libgcc file. any := false for _, s := range ctxt.Syms.Allsym { - for _, r := range s.R { + for i := range s.R { + r := &s.R[i] // Copying sym.Reloc has measurable impact on peformance if r.Sym != nil && r.Sym.Type == sym.SXREF && r.Sym.Name != ".got" { any = true break From 3333b6407d8bae64cb8bf62de1425abd8714a51c Mon Sep 17 00:00:00 2001 From: Tim Cooper Date: Mon, 18 Jun 2018 12:48:30 -0300 Subject: [PATCH 0061/1663] net/http: use internal/race Change-Id: Iaa5ded13e8ab4753e2e3d04c9fff203d854208ba Reviewed-on: https://go-review.googlesource.com/119435 Reviewed-by: Brad Fitzpatrick --- src/net/http/header.go | 2 -- src/net/http/header_test.go | 3 ++- src/net/http/race.go | 11 ----------- 3 files changed, 2 insertions(+), 14 deletions(-) delete mode 100644 src/net/http/race.go diff --git a/src/net/http/header.go b/src/net/http/header.go index 461ae9368ac15..b28144d8c198c 100644 --- a/src/net/http/header.go +++ b/src/net/http/header.go @@ -14,8 +14,6 @@ import ( "time" ) -var raceEnabled = false // set by race.go - // A Header represents the key-value pairs in an HTTP header. type Header map[string][]string diff --git a/src/net/http/header_test.go b/src/net/http/header_test.go index bbd35c485a4a3..48158d313aeba 100644 --- a/src/net/http/header_test.go +++ b/src/net/http/header_test.go @@ -6,6 +6,7 @@ package http import ( "bytes" + "internal/race" "runtime" "testing" "time" @@ -196,7 +197,7 @@ func TestHeaderWriteSubsetAllocs(t *testing.T) { if testing.Short() { t.Skip("skipping alloc test in short mode") } - if raceEnabled { + if race.Enabled { t.Skip("skipping test under race detector") } if runtime.GOMAXPROCS(0) > 1 { diff --git a/src/net/http/race.go b/src/net/http/race.go deleted file mode 100644 index 766503967c3c4..0000000000000 --- a/src/net/http/race.go +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright 2014 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. - -// +build race - -package http - -func init() { - raceEnabled = true -} From dc272a4393dc2ba5f54f9cc37670d5581b6e774f Mon Sep 17 00:00:00 2001 From: Tim Cooper Date: Tue, 19 Jun 2018 12:34:17 -0300 Subject: [PATCH 0062/1663] encoding/json: call reflect.TypeOf with nil pointers rather than allocating Updates #26775 Change-Id: I83c9eeda59769d2f35e0cc98f3a8579861d5978b Reviewed-on: https://go-review.googlesource.com/119715 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/encoding/json/decode.go | 2 +- src/encoding/json/encode.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go index 0b29249218a32..97fee54f4ebfd 100644 --- a/src/encoding/json/decode.go +++ b/src/encoding/json/decode.go @@ -611,7 +611,7 @@ func (d *decodeState) array(v reflect.Value) error { } var nullLiteral = []byte("null") -var textUnmarshalerType = reflect.TypeOf(new(encoding.TextUnmarshaler)).Elem() +var textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem() // object consumes an object from d.data[d.off-1:], decoding into v. // The first byte ('{') of the object has been read already. diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 28ca5fe9e009f..7ebb04c50a949 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -381,8 +381,8 @@ func typeEncoder(t reflect.Type) encoderFunc { } var ( - marshalerType = reflect.TypeOf(new(Marshaler)).Elem() - textMarshalerType = reflect.TypeOf(new(encoding.TextMarshaler)).Elem() + marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem() + textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem() ) // newTypeEncoder constructs an encoderFunc for a type. From 46033d7639cb1399029b99bb0cdc53d2b8f4bd08 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Sat, 18 Aug 2018 14:16:26 -0400 Subject: [PATCH 0063/1663] cmd/go: add go.sum entries to go mod download -json output Clients of 'go mod download', particularly proxies, may need the hashes of the content they downloaded, for checking against go.sum entries or recording elsewhere. Change-Id: Ic36c882cefc540678e1bc5a3dae1e865d181aa69 Reviewed-on: https://go-review.googlesource.com/129802 Run-TryBot: Russ Cox Reviewed-by: Andrew Bonventre --- src/cmd/go/internal/modcmd/download.go | 38 +++++++++++++-------- src/cmd/go/internal/modfetch/cache.go | 17 +++++++++ src/cmd/go/internal/modfetch/fetch.go | 11 ++++-- src/cmd/go/testdata/script/mod_download.txt | 2 ++ 4 files changed, 51 insertions(+), 17 deletions(-) diff --git a/src/cmd/go/internal/modcmd/download.go b/src/cmd/go/internal/modcmd/download.go index 2f072d73cf306..cf42eff58a1f3 100644 --- a/src/cmd/go/internal/modcmd/download.go +++ b/src/cmd/go/internal/modcmd/download.go @@ -32,13 +32,15 @@ to standard output, describing each downloaded module (or failure), corresponding to this Go struct: type Module struct { - Path string // module path - Version string // module version - Error string // error loading module - Info string // absolute path to cached .info file - GoMod string // absolute path to cached .mod file - Zip string // absolute path to cached .zip file - Dir string // absolute path to cached source root directory + Path string // module path + Version string // module version + Error string // error loading module + Info string // absolute path to cached .info file + GoMod string // absolute path to cached .mod file + Zip string // absolute path to cached .zip file + Dir string // absolute path to cached source root directory + Sum string // checksum for path, version (as in go.sum) + GoModSum string // checksum for go.mod (as in go.sum) } See 'go help modules' for more about module queries. @@ -52,13 +54,15 @@ func init() { } type moduleJSON struct { - Path string `json:",omitempty"` - Version string `json:",omitempty"` - Error string `json:",omitempty"` - Info string `json:",omitempty"` - GoMod string `json:",omitempty"` - Zip string `json:",omitempty"` - Dir string `json:",omitempty"` + Path string `json:",omitempty"` + Version string `json:",omitempty"` + Error string `json:",omitempty"` + Info string `json:",omitempty"` + GoMod string `json:",omitempty"` + Zip string `json:",omitempty"` + Dir string `json:",omitempty"` + Sum string `json:",omitempty"` + GoModSum string `json:",omitempty"` } func runDownload(cmd *base.Command, args []string) { @@ -98,12 +102,18 @@ func runDownload(cmd *base.Command, args []string) { m.Error = err.Error() return } + m.GoModSum, err = modfetch.GoModSum(m.Path, m.Version) + if err != nil { + m.Error = err.Error() + return + } mod := module.Version{Path: m.Path, Version: m.Version} m.Zip, err = modfetch.DownloadZip(mod) if err != nil { m.Error = err.Error() return } + m.Sum = modfetch.Sum(mod) m.Dir, err = modfetch.Download(mod) if err != nil { m.Error = err.Error() diff --git a/src/cmd/go/internal/modfetch/cache.go b/src/cmd/go/internal/modfetch/cache.go index efcd4854e82fa..1f9cc96c3ec80 100644 --- a/src/cmd/go/internal/modfetch/cache.go +++ b/src/cmd/go/internal/modfetch/cache.go @@ -290,6 +290,23 @@ func GoModFile(path, version string) (string, error) { return file, nil } +// GoModSum returns the go.sum entry for the module version's go.mod file. +// (That is, it returns the entry listed in go.sum as "path version/go.mod".) +func GoModSum(path, version string) (string, error) { + if !semver.IsValid(version) { + return "", fmt.Errorf("invalid version %q", version) + } + data, err := GoMod(path, version) + if err != nil { + return "", err + } + sum, err := goModSum(data) + if err != nil { + return "", err + } + return sum, nil +} + var errNotCached = fmt.Errorf("not in cache") // readDiskStat reads a cached stat result from disk, diff --git a/src/cmd/go/internal/modfetch/fetch.go b/src/cmd/go/internal/modfetch/fetch.go index 480579156fefb..2e26bac434da8 100644 --- a/src/cmd/go/internal/modfetch/fetch.go +++ b/src/cmd/go/internal/modfetch/fetch.go @@ -253,12 +253,17 @@ func checkSum(mod module.Version) { checkOneSum(mod, h) } +// goModSum returns the checksum for the go.mod contents. +func goModSum(data []byte) (string, error) { + return dirhash.Hash1([]string{"go.mod"}, func(string) (io.ReadCloser, error) { + return ioutil.NopCloser(bytes.NewReader(data)), nil + }) +} + // checkGoMod checks the given module's go.mod checksum; // data is the go.mod content. func checkGoMod(path, version string, data []byte) { - h, err := dirhash.Hash1([]string{"go.mod"}, func(string) (io.ReadCloser, error) { - return ioutil.NopCloser(bytes.NewReader(data)), nil - }) + h, err := goModSum(data) if err != nil { base.Fatalf("go: verifying %s %s go.mod: %v", path, version, err) } diff --git a/src/cmd/go/testdata/script/mod_download.txt b/src/cmd/go/testdata/script/mod_download.txt index ef931cfd30fd2..6be6acb360c9f 100644 --- a/src/cmd/go/testdata/script/mod_download.txt +++ b/src/cmd/go/testdata/script/mod_download.txt @@ -15,6 +15,8 @@ stdout '^\t"Version": "v1.5.0"' stdout '^\t"Info": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.info"' stdout '^\t"GoMod": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.mod"' stdout '^\t"Zip": ".*(\\\\|/)pkg(\\\\|/)mod(\\\\|/)cache(\\\\|/)download(\\\\|/)rsc.io(\\\\|/)quote(\\\\|/)@v(\\\\|/)v1.5.0.zip"' +stdout '^\t"Sum": "h1:6fJa6E\+wGadANKkUMlZ0DhXFpoKlslOQDCo259XtdIE="' # hash of testdata/mod version, not real version! +stdout '^\t"GoModSum": "h1:LzX7hefJvL54yjefDEDHNONDjII0t9xZLPXsUe\+TKr0="' ! stdout '"Error"' # download queries above should not have added to go.mod. From c652a1b9c041a2d359665f01de21b19d53ba5ce5 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 20 Aug 2018 21:25:01 -0400 Subject: [PATCH 0064/1663] cmd/go: fix modload response for std-vendored packages This fixes a failure when using Go 1.11 to build App Engine code. Change-Id: I008e8cf5ad4c568676d904deddff031a166f2d5d Reviewed-on: https://go-review.googlesource.com/130138 Run-TryBot: Russ Cox Reviewed-by: Ian Lance Taylor --- src/cmd/go/internal/modload/build.go | 16 +++++++++++----- src/cmd/go/internal/modload/load.go | 16 +++++++++++----- src/cmd/go/testdata/script/mod_std_vendor.txt | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 src/cmd/go/testdata/script/mod_std_vendor.txt diff --git a/src/cmd/go/internal/modload/build.go b/src/cmd/go/internal/modload/build.go index 5893db14aa60c..cebb802db9fc9 100644 --- a/src/cmd/go/internal/modload/build.go +++ b/src/cmd/go/internal/modload/build.go @@ -25,15 +25,21 @@ var ( ) func isStandardImportPath(path string) bool { + return findStandardImportPath(path) != "" +} + +func findStandardImportPath(path string) string { if search.IsStandardImportPath(path) { - if _, err := os.Stat(filepath.Join(cfg.GOROOT, "src", path)); err == nil { - return true + dir := filepath.Join(cfg.GOROOT, "src", path) + if _, err := os.Stat(dir); err == nil { + return dir } - if _, err := os.Stat(filepath.Join(cfg.GOROOT, "src/vendor", path)); err == nil { - return true + dir = filepath.Join(cfg.GOROOT, "src/vendor", path) + if _, err := os.Stat(dir); err == nil { + return dir } } - return false + return "" } func PackageModuleInfo(pkgpath string) *modinfo.ModulePublic { diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index 285daa8f4fcb9..e6340b8bfdcd6 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -399,11 +399,17 @@ func ModuleUsedDirectly(path string) bool { func Lookup(path string) (dir, realPath string, err error) { pkg, ok := loaded.pkgCache.Get(path).(*loadPkg) if !ok { - if isStandardImportPath(path) { - dir := filepath.Join(cfg.GOROOT, "src", path) - if _, err := os.Stat(dir); err == nil { - return dir, path, nil - } + // The loader should have found all the relevant paths. + // There are a few exceptions, though: + // - during go list without -test, the p.Resolve calls to process p.TestImports and p.XTestImports + // end up here to canonicalize the import paths. + // - during any load, non-loaded packages like "unsafe" end up here. + // - during any load, build-injected dependencies like "runtime/cgo" end up here. + // - because we ignore appengine/* in the module loader, + // the dependencies of any actual appengine/* library end up here. + dir := findStandardImportPath(path) + if dir != "" { + return dir, path, nil } return "", "", errMissing } diff --git a/src/cmd/go/testdata/script/mod_std_vendor.txt b/src/cmd/go/testdata/script/mod_std_vendor.txt new file mode 100644 index 0000000000000..36d4ffca9eca5 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_std_vendor.txt @@ -0,0 +1,19 @@ +env GO111MODULE=on + +go list -f '{{.TestImports}}' +stdout net/http # from .TestImports + +go list -test -f '{{.Deps}}' +stdout golang_org/x/crypto # dep of .TestImports + +-- go.mod -- +module m + +-- x.go -- +package x + +-- x_test.go -- +package x +import "testing" +import _ "net/http" +func Test(t *testing.T) {} From df6aedb630b3c79ff50147a85278a17702dcff1f Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 20 Aug 2018 21:35:02 -0400 Subject: [PATCH 0065/1663] cmd/go: fix list -compiled of package with only tests Fixes #27097. Change-Id: I6aa48a1c58a21fd320b0e9dcd1f86c90172f0182 Reviewed-on: https://go-review.googlesource.com/130139 Run-TryBot: Russ Cox Reviewed-by: Ian Lance Taylor --- src/cmd/go/internal/list/list.go | 4 +++- src/cmd/go/testdata/script/mod_list_test.txt | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/cmd/go/testdata/script/mod_list_test.txt diff --git a/src/cmd/go/internal/list/list.go b/src/cmd/go/internal/list/list.go index 186b006c12acd..f3cb4e47eccc2 100644 --- a/src/cmd/go/internal/list/list.go +++ b/src/cmd/go/internal/list/list.go @@ -510,7 +510,9 @@ func runList(cmd *base.Command, args []string) { a := &work.Action{} // TODO: Use pkgsFilter? for _, p := range pkgs { - a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p)) + if len(p.GoFiles)+len(p.CgoFiles) > 0 { + a.Deps = append(a.Deps, b.AutoAction(work.ModeInstall, work.ModeInstall, p)) + } } b.Do(a) } diff --git a/src/cmd/go/testdata/script/mod_list_test.txt b/src/cmd/go/testdata/script/mod_list_test.txt new file mode 100644 index 0000000000000..a99e4f36cd587 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_list_test.txt @@ -0,0 +1,16 @@ +env GO111MODULE=on + +# go list -compiled -test must handle test-only packages +# golang.org/issue/27097. +go list -compiled -test +stdout '^m$' +stdout '^m\.test$' +stdout '^m \[m\.test\]$' + +-- go.mod -- +module m + +-- x_test.go -- +package x +import "testing" +func Test(t *testing.T) {} From 27ed675b4bbb63b5b5d84a21be583ef6147a2084 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 20 Aug 2018 21:42:02 -0400 Subject: [PATCH 0066/1663] cmd/go: fix 'go help go.mod' example Dropped the example referred to in the text when copying this text out of 'go help mod fix'. Fixes #27083. Change-Id: I63dfa3033fa2b2408019eef9d8b5a055aa803c57 Reviewed-on: https://go-review.googlesource.com/130140 Run-TryBot: Russ Cox TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/go/alldocs.go | 30 +++++++++++++++++++++-------- src/cmd/go/internal/modload/help.go | 14 +++++++++++++- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 1585dd5b1f3f5..0aa69a0aba7c5 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -905,13 +905,15 @@ // corresponding to this Go struct: // // type Module struct { -// Path string // module path -// Version string // module version -// Error string // error loading module -// Info string // absolute path to cached .info file -// GoMod string // absolute path to cached .mod file -// Zip string // absolute path to cached .zip file -// Dir string // absolute path to cached source root directory +// Path string // module path +// Version string // module version +// Error string // error loading module +// Info string // absolute path to cached .info file +// GoMod string // absolute path to cached .mod file +// Zip string // absolute path to cached .zip file +// Dir string // absolute path to cached source root directory +// Sum string // checksum for path, version (as in go.sum) +// GoModSum string // checksum for go.mod (as in go.sum) // } // // See 'go help modules' for more about module queries. @@ -1617,7 +1619,19 @@ // // The go command automatically updates go.mod each time it uses the // module graph, to make sure go.mod always accurately reflects reality -// and is properly formatted. +// and is properly formatted. For example, consider this go.mod file: +// +// module M +// +// require ( +// A v1 +// B v1.0.0 +// C v1.0.0 +// D v1.2.3 +// E dev +// ) +// +// exclude D v1.2.3 // // The update rewrites non-canonical version identifiers to semver form, // so A's v1 becomes v1.0.0 and E's dev becomes the pseudo-version for the diff --git a/src/cmd/go/internal/modload/help.go b/src/cmd/go/internal/modload/help.go index 9a12b24482070..f2f34197244a4 100644 --- a/src/cmd/go/internal/modload/help.go +++ b/src/cmd/go/internal/modload/help.go @@ -420,7 +420,19 @@ See 'go help mod edit'. The go command automatically updates go.mod each time it uses the module graph, to make sure go.mod always accurately reflects reality -and is properly formatted. +and is properly formatted. For example, consider this go.mod file: + + module M + + require ( + A v1 + B v1.0.0 + C v1.0.0 + D v1.2.3 + E dev + ) + + exclude D v1.2.3 The update rewrites non-canonical version identifiers to semver form, so A's v1 becomes v1.0.0 and E's dev becomes the pseudo-version for the From a0212aa6273395c400092383bbdebc251ebacd2d Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 21 Aug 2018 02:43:45 +0000 Subject: [PATCH 0067/1663] cmd/go: revert "add graphviz output to graph command" This reverts commit 723479bc30f998f29ecbba7caea118ac4e2c9afd. Reason for revert: other tools should convert the graph output to graphviz. Change-Id: Ide5b8f0b061aaff74bb6ba4c2a8f8768d1fbc05a Reviewed-on: https://go-review.googlesource.com/130295 Reviewed-by: Russ Cox --- src/cmd/go/internal/modcmd/graph.go | 33 +++-------------------------- 1 file changed, 3 insertions(+), 30 deletions(-) diff --git a/src/cmd/go/internal/modcmd/graph.go b/src/cmd/go/internal/modcmd/graph.go index b123454d60988..5825c6d8ca8e0 100644 --- a/src/cmd/go/internal/modcmd/graph.go +++ b/src/cmd/go/internal/modcmd/graph.go @@ -18,25 +18,15 @@ import ( ) var cmdGraph = &base.Command{ - UsageLine: "go mod graph [-dot]", + UsageLine: "go mod graph", Short: "print module requirement graph", Long: ` Graph prints the module requirement graph (with replacements applied) in text form. Each line in the output has two space-separated fields: a module and one of its requirements. Each module is identified as a string of the form path@version, except for the main module, which has no @version suffix. - -The -dot flag generates the output in graphviz format that can be used -with a tool like dot to visually render the dependency graph. `, -} - -var ( - graphDot = cmdGraph.Flag.Bool("dot", false, "") -) - -func init() { - cmdGraph.Run = runGraph // break init cycle + Run: runGraph, } func runGraph(cmd *base.Command, args []string) { @@ -61,21 +51,10 @@ func runGraph(cmd *base.Command, args []string) { work.Add(modload.Target) work.Do(1, func(item interface{}) { m := item.(module.Version) - if *graphDot { - if m.Version == "" { - out = append(out, "\""+m.Path+"\" [label=<"+m.Path+">]\n") - } else { - out = append(out, "\""+m.Path+"\" [label=<"+m.Path+"
"+m.Version+">]\n") - } - } list, _ := reqs.Required(m) for _, r := range list { work.Add(r) - if *graphDot { - out = append(out, "\""+m.Path+"\" -> \""+r.Path+"\"\n") - } else { - out = append(out, format(m)+" "+format(r)+"\n") - } + out = append(out, format(m)+" "+format(r)+"\n") } if m == modload.Target { deps = len(out) @@ -87,14 +66,8 @@ func runGraph(cmd *base.Command, args []string) { }) w := bufio.NewWriter(os.Stdout) - if *graphDot { - w.WriteString("digraph deps {\nrankdir=LR\n") - } for _, line := range out { w.WriteString(line) } - if *graphDot { - w.WriteString("}\n") - } w.Flush() } From 9087d13ec3e39e50aae6c6a8cf99dc66225ab132 Mon Sep 17 00:00:00 2001 From: Muhammad Falak R Wani Date: Fri, 15 Jun 2018 00:07:32 +0530 Subject: [PATCH 0068/1663] cmd/objdump: defer closing the file after opening Remove the os.Exit(0) to honor the deferred closing of the file. Change-Id: Iaa9304d8203c8fec0ec728af669a94eadd36905c Reviewed-on: https://go-review.googlesource.com/118915 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick --- src/cmd/objdump/main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/cmd/objdump/main.go b/src/cmd/objdump/main.go index 71636990a1d12..6a60697ebd4d6 100644 --- a/src/cmd/objdump/main.go +++ b/src/cmd/objdump/main.go @@ -75,6 +75,7 @@ func main() { if err != nil { log.Fatal(err) } + defer f.Close() dis, err := f.Disasm() if err != nil { @@ -87,7 +88,6 @@ func main() { case 1: // disassembly of entire object dis.Print(os.Stdout, symRE, 0, ^uint64(0), *printCode) - os.Exit(0) case 3: // disassembly of PC range @@ -100,6 +100,5 @@ func main() { log.Fatalf("invalid end PC: %v", err) } dis.Print(os.Stdout, symRE, start, end, *printCode) - os.Exit(0) } } From c544e0fbdb7344b2025650aaf70bab3b09d72003 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 2 Aug 2018 20:02:24 +0000 Subject: [PATCH 0069/1663] strings: select Replacer algorithm and build machine lazily Saves 22KB of memory in stdlib packages. Updates #26775 Change-Id: Ia19fe7aff61f6e2ddd83cd35969d7ff94526591f Reviewed-on: https://go-review.googlesource.com/127661 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/strings/export_test.go | 2 ++ src/strings/replace.go | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/strings/export_test.go b/src/strings/export_test.go index 17c806aa56373..b39cee6b1ded1 100644 --- a/src/strings/export_test.go +++ b/src/strings/export_test.go @@ -5,10 +5,12 @@ package strings func (r *Replacer) Replacer() interface{} { + r.once.Do(r.buildOnce) return r.r } func (r *Replacer) PrintTrie() string { + r.once.Do(r.buildOnce) gen := r.r.(*genericReplacer) return gen.printNode(&gen.root, 0) } diff --git a/src/strings/replace.go b/src/strings/replace.go index 58a11a63dbeb4..dbda9501945b8 100644 --- a/src/strings/replace.go +++ b/src/strings/replace.go @@ -4,12 +4,17 @@ package strings -import "io" +import ( + "io" + "sync" +) // Replacer replaces a list of strings with replacements. // It is safe for concurrent use by multiple goroutines. type Replacer struct { - r replacer + once sync.Once // guards buildOnce method + r replacer + oldnew []string } // replacer is the interface that a replacement algorithm needs to implement. @@ -25,15 +30,24 @@ func NewReplacer(oldnew ...string) *Replacer { if len(oldnew)%2 == 1 { panic("strings.NewReplacer: odd argument count") } + return &Replacer{oldnew: append([]string(nil), oldnew...)} +} + +func (r *Replacer) buildOnce() { + r.r = r.build() + r.oldnew = nil +} +func (b *Replacer) build() replacer { + oldnew := b.oldnew if len(oldnew) == 2 && len(oldnew[0]) > 1 { - return &Replacer{r: makeSingleStringReplacer(oldnew[0], oldnew[1])} + return makeSingleStringReplacer(oldnew[0], oldnew[1]) } allNewBytes := true for i := 0; i < len(oldnew); i += 2 { if len(oldnew[i]) != 1 { - return &Replacer{r: makeGenericReplacer(oldnew)} + return makeGenericReplacer(oldnew) } if len(oldnew[i+1]) != 1 { allNewBytes = false @@ -52,7 +66,7 @@ func NewReplacer(oldnew ...string) *Replacer { n := oldnew[i+1][0] r[o] = n } - return &Replacer{r: &r} + return &r } r := byteStringReplacer{toReplace: make([]string, 0, len(oldnew)/2)} @@ -71,16 +85,18 @@ func NewReplacer(oldnew ...string) *Replacer { r.replacements[o] = []byte(n) } - return &Replacer{r: &r} + return &r } // Replace returns a copy of s with all replacements performed. func (r *Replacer) Replace(s string) string { + r.once.Do(r.buildOnce) return r.r.Replace(s) } // WriteString writes s to w with all replacements performed. func (r *Replacer) WriteString(w io.Writer, s string) (n int, err error) { + r.once.Do(r.buildOnce) return r.r.WriteString(w, s) } From fc5107c27011e1c1b70eb35a6fb7b3efd0cf3cea Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 3 Aug 2018 19:21:11 +0000 Subject: [PATCH 0070/1663] go/doc: compile regexps lazily Compile go/doc's 4 regexps lazily, on demand. Also, add a test for the one that had no test coverage. This reduces init-time CPU as well as heap by ~20KB when they're not used, which seems to be common enough. As an example, cmd/doc only seems to use 1 of them. (as noted by temporary print statements) Updates #26775 Change-Id: I85df89b836327a53fb8e1ace3f92480374270368 Reviewed-on: https://go-review.googlesource.com/127875 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/go/build/deps_test.go | 2 +- src/go/doc/comment.go | 5 ++-- src/go/doc/doc_test.go | 9 +++++++ src/go/doc/lazyre.go | 51 +++++++++++++++++++++++++++++++++++++++ src/go/doc/reader.go | 7 +++--- 5 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 src/go/doc/lazyre.go diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index 29dbe47d29d47..7a154b08803e9 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -204,7 +204,7 @@ var pkgDeps = map[string][]string{ // Go parser. "go/ast": {"L4", "OS", "go/scanner", "go/token"}, - "go/doc": {"L4", "go/ast", "go/token", "regexp", "text/template"}, + "go/doc": {"L4", "OS", "go/ast", "go/token", "regexp", "text/template"}, "go/parser": {"L4", "OS", "go/ast", "go/scanner", "go/token"}, "go/printer": {"L4", "OS", "go/ast", "go/scanner", "go/token", "text/tabwriter"}, "go/scanner": {"L4", "OS", "go/token"}, diff --git a/src/go/doc/comment.go b/src/go/doc/comment.go index d068d8960c602..d9268b87fb885 100644 --- a/src/go/doc/comment.go +++ b/src/go/doc/comment.go @@ -8,7 +8,6 @@ package doc import ( "io" - "regexp" "strings" "text/template" // for HTMLEscape "unicode" @@ -63,7 +62,7 @@ const ( urlRx = protoPart + `://` + hostPart + pathPart ) -var matchRx = regexp.MustCompile(`(` + urlRx + `)|(` + identRx + `)`) +var matchRx = newLazyRE(`(` + urlRx + `)|(` + identRx + `)`) var ( html_a = []byte(` 0 && strings.HasSuffix(strings.TrimSuffix(os.Args[0], ".exe"), ".test") + +func newLazyRE(str string) *lazyRE { + lr := &lazyRE{str: str} + if inTest { + // In tests, always compile the regexps early. + lr.re() + } + return lr +} diff --git a/src/go/doc/reader.go b/src/go/doc/reader.go index 21c02920ababf..21d5907a03027 100644 --- a/src/go/doc/reader.go +++ b/src/go/doc/reader.go @@ -7,7 +7,6 @@ package doc import ( "go/ast" "go/token" - "regexp" "sort" "strconv" ) @@ -425,9 +424,9 @@ func (r *reader) readFunc(fun *ast.FuncDecl) { } var ( - noteMarker = `([A-Z][A-Z]+)\(([^)]+)\):?` // MARKER(uid), MARKER at least 2 chars, uid at least 1 char - noteMarkerRx = regexp.MustCompile(`^[ \t]*` + noteMarker) // MARKER(uid) at text start - noteCommentRx = regexp.MustCompile(`^/[/*][ \t]*` + noteMarker) // MARKER(uid) at comment start + noteMarker = `([A-Z][A-Z]+)\(([^)]+)\):?` // MARKER(uid), MARKER at least 2 chars, uid at least 1 char + noteMarkerRx = newLazyRE(`^[ \t]*` + noteMarker) // MARKER(uid) at text start + noteCommentRx = newLazyRE(`^/[/*][ \t]*` + noteMarker) // MARKER(uid) at comment start ) // readNote collects a single note from a sequence of comments. From bce1f12225b9a2a3d8e59f3b1f1776e5baec9edf Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Thu, 21 Jun 2018 20:43:10 +0300 Subject: [PATCH 0071/1663] cmd/compile/internal/ssa: use math/bits in countRegs and pickReg MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Makes code simpler and faster (at least on x86). name old time/op new time/op delta CountRegs-8 7.40ns ± 1% 0.59ns ± 0% -92.02% (p=0.000 n=9+9) PickReg/(1<<0)-8 2.07ns ± 0% 0.37ns ± 0% -82.13% (p=0.000 n=9+10) PickReg/(1<<16)-8 11.8ns ± 0% 0.4ns ± 0% -96.86% (p=0.002 n=8+10) Change-Id: Ic780b615b75c25b6e7632a0de93b16a8e9ed0f8f Reviewed-on: https://go-review.googlesource.com/120318 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/regalloc.go | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/cmd/compile/internal/ssa/regalloc.go b/src/cmd/compile/internal/ssa/regalloc.go index bbf1932981458..278da6fe99fd3 100644 --- a/src/cmd/compile/internal/ssa/regalloc.go +++ b/src/cmd/compile/internal/ssa/regalloc.go @@ -119,6 +119,7 @@ import ( "cmd/internal/src" "cmd/internal/sys" "fmt" + "math/bits" "unsafe" ) @@ -183,26 +184,16 @@ func (s *regAllocState) RegMaskString(m regMask) string { // countRegs returns the number of set bits in the register mask. func countRegs(r regMask) int { - n := 0 - for r != 0 { - n += int(r & 1) - r >>= 1 - } - return n + return bits.OnesCount64(uint64(r)) } // pickReg picks an arbitrary register from the register mask. func pickReg(r regMask) register { - // pick the lowest one if r == 0 { panic("can't pick a register from an empty set") } - for i := register(0); ; i++ { - if r&1 != 0 { - return i - } - r >>= 1 - } + // pick the lowest one + return register(bits.TrailingZeros64(uint64(r))) } type use struct { From d58f3e6fea4e4540ad54caf9e141fe213c87d710 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 31 Jul 2018 21:05:26 +0000 Subject: [PATCH 0072/1663] net/http: add test showing that ReverseProxy HTTP/2 bidi streaming works Change-Id: I8361ae33c785e45e3ccc7e9bc2732c887eeb41c4 Reviewed-on: https://go-review.googlesource.com/127015 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Matt Layher Reviewed-by: Brad Fitzpatrick --- src/net/http/clientserver_test.go | 67 +++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/net/http/clientserver_test.go b/src/net/http/clientserver_test.go index c2a2548df11a2..9a05b648e32be 100644 --- a/src/net/http/clientserver_test.go +++ b/src/net/http/clientserver_test.go @@ -9,8 +9,11 @@ package http_test import ( "bytes" "compress/gzip" + "crypto/rand" + "crypto/sha1" "crypto/tls" "fmt" + "hash" "io" "io/ioutil" "log" @@ -1479,3 +1482,67 @@ func testWriteHeaderAfterWrite(t *testing.T, h2, hijack bool) { t.Errorf("stderr output = %q; want %q", gotLog, wantLog) } } + +func TestBidiStreamReverseProxy(t *testing.T) { + setParallel(t) + defer afterTest(t) + backend := newClientServerTest(t, h2Mode, HandlerFunc(func(w ResponseWriter, r *Request) { + if _, err := io.Copy(w, r.Body); err != nil { + log.Printf("bidi backend copy: %v", err) + } + })) + defer backend.close() + + backURL, err := url.Parse(backend.ts.URL) + if err != nil { + t.Fatal(err) + } + rp := httputil.NewSingleHostReverseProxy(backURL) + rp.Transport = backend.tr + proxy := newClientServerTest(t, h2Mode, HandlerFunc(func(w ResponseWriter, r *Request) { + rp.ServeHTTP(w, r) + })) + defer proxy.close() + + bodyRes := make(chan interface{}, 1) // error or hash.Hash + pr, pw := io.Pipe() + req, _ := NewRequest("PUT", proxy.ts.URL, pr) + const size = 4 << 20 + go func() { + h := sha1.New() + _, err := io.CopyN(io.MultiWriter(h, pw), rand.Reader, size) + go pw.Close() + if err != nil { + bodyRes <- err + } else { + bodyRes <- h + } + }() + res, err := backend.c.Do(req) + if err != nil { + t.Fatal(err) + } + defer res.Body.Close() + hgot := sha1.New() + n, err := io.Copy(hgot, res.Body) + if err != nil { + t.Fatal(err) + } + if n != size { + t.Fatalf("got %d bytes; want %d", n, size) + } + select { + case v := <-bodyRes: + switch v := v.(type) { + default: + t.Fatalf("body copy: %v", err) + case hash.Hash: + if !bytes.Equal(v.Sum(nil), hgot.Sum(nil)) { + t.Errorf("written bytes didn't match received bytes") + } + } + case <-time.After(10 * time.Second): + t.Fatal("timeout") + } + +} From 7e64377903b3abd922150e35601e0df597a8af9f Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 29 Jun 2018 21:14:47 -0700 Subject: [PATCH 0073/1663] cmd/compile: only support -race and -msan where they work Consolidate decision about whether -race and -msan options are supported in cmd/internal/sys. Use consolidated functions in cmd/compile and cmd/go. Use a copy of them in cmd/dist; cmd/dist can't import cmd/internal/sys because Go 1.4 doesn't have it. Fixes #24315 Change-Id: I9cecaed4895eb1a2a49379b4848db40de66d32a9 Reviewed-on: https://go-review.googlesource.com/121816 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/gc/main.go | 8 +++-- src/cmd/dist/test.go | 45 ++++++++++++++++++++++++----- src/cmd/go/go_test.go | 17 +++++------ src/cmd/go/internal/work/init.go | 9 ++---- src/cmd/internal/sys/supported.go | 29 +++++++++++++++++++ test/fixedbugs/issue13265.go | 1 + test/fixedbugs/issue15091.go | 1 + test/fixedbugs/issue16008.go | 1 + test/fixedbugs/issue17449.go | 1 + test/fixedbugs/issue24651a.go | 1 + 10 files changed, 89 insertions(+), 24 deletions(-) create mode 100644 src/cmd/internal/sys/supported.go diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index da6f800ccd5d9..3fd89873d1749 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -216,14 +216,18 @@ func Main(archInit func(*Arch)) { flag.StringVar(&linkobj, "linkobj", "", "write linker-specific object to `file`") objabi.Flagcount("live", "debug liveness analysis", &debuglive) objabi.Flagcount("m", "print optimization decisions", &Debug['m']) - flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer") + if sys.MSanSupported(objabi.GOOS, objabi.GOARCH) { + flag.BoolVar(&flag_msan, "msan", false, "build code compatible with C/C++ memory sanitizer") + } flag.BoolVar(&dolinkobj, "dolinkobj", true, "generate linker-specific objects; if false, some invalid code may compile") flag.BoolVar(&nolocalimports, "nolocalimports", false, "reject local (relative) imports") flag.StringVar(&outfile, "o", "", "write output to `file`") flag.StringVar(&myimportpath, "p", "", "set expected package import `path`") flag.BoolVar(&writearchive, "pack", false, "write to file.a instead of file.o") objabi.Flagcount("r", "debug generated wrappers", &Debug['r']) - flag.BoolVar(&flag_race, "race", false, "enable race detector") + if sys.RaceDetectorSupported(objabi.GOOS, objabi.GOARCH) { + flag.BoolVar(&flag_race, "race", false, "enable race detector") + } objabi.Flagcount("s", "warn about composite literals that can be simplified", &Debug['s']) flag.StringVar(&pathPrefix, "trimpath", "", "remove `prefix` from recorded source file paths") flag.BoolVar(&safemode, "u", false, "reject unsafe code") diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 448c7867a143c..3d0ef284484d4 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -705,7 +705,7 @@ func (t *tester) registerTests() { if gohostos == "linux" && goarch == "amd64" { t.registerTest("testasan", "../misc/cgo/testasan", "go", "run", "main.go") } - if goos == "linux" && (goarch == "amd64" || goarch == "arm64") { + if mSanSupported(goos, goarch) { t.registerHostTest("testsanitizers/msan", "../misc/cgo/testsanitizers", "misc/cgo/testsanitizers", ".") } if t.hasBash() && goos != "android" && !t.iOS() && gohostos != "windows" { @@ -1329,13 +1329,21 @@ func (t *tester) hasSwig() bool { } func (t *tester) raceDetectorSupported() bool { - switch gohostos { - case "linux", "darwin", "freebsd", "windows": - // The race detector doesn't work on Alpine Linux: - // golang.org/issue/14481 - return t.cgoEnabled && (goarch == "amd64" || goarch == "ppc64le") && gohostos == goos && !isAlpineLinux() + if gohostos != goos { + return false } - return false + if !t.cgoEnabled { + return false + } + if !raceDetectorSupported(goos, goarch) { + return false + } + // The race detector doesn't work on Alpine Linux: + // golang.org/issue/14481 + if isAlpineLinux() { + return false + } + return true } func isAlpineLinux() bool { @@ -1450,3 +1458,26 @@ func (t *tester) packageHasBenchmarks(pkg string) bool { } return false } + +// raceDetectorSupported is a copy of the function +// cmd/internal/sys.RaceDetectorSupported, which can't be used here +// because cmd/dist has to be buildable by Go 1.4. +func raceDetectorSupported(goos, goarch string) bool { + switch goos { + case "linux", "darwin", "freebsd", "netbsd", "windows": + return goarch == "amd64" || goarch == "ppc64le" + default: + return false + } +} + +// mSanSupported is a copy of the function cmd/internal/sys.MSanSupported, +// which can't be used here because cmd/dist has to be buildable by Go 1.4. +func mSanSupported(goos, goarch string) bool { + switch goos { + case "linux": + return goarch == "amd64" || goarch == "arm64" + default: + return false + } +} diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index ada1ddde3bbb7..6bd0609eaffda 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -6,6 +6,7 @@ package main_test import ( "bytes" + "cmd/internal/sys" "debug/elf" "debug/macho" "flag" @@ -209,15 +210,13 @@ func TestMain(m *testing.M) { } testGOCACHE = strings.TrimSpace(string(out)) - // As of Sept 2017, MSan is only supported on linux/amd64. - // https://github.com/google/sanitizers/wiki/MemorySanitizer#getting-memorysanitizer - canMSan = canCgo && runtime.GOOS == "linux" && runtime.GOARCH == "amd64" - - switch runtime.GOOS { - case "linux", "darwin", "freebsd", "windows": - // The race detector doesn't work on Alpine Linux: - // golang.org/issue/14481 - canRace = canCgo && runtime.GOARCH == "amd64" && !isAlpineLinux() && runtime.Compiler != "gccgo" + canMSan = canCgo && sys.MSanSupported(runtime.GOOS, runtime.GOARCH) + canRace = canCgo && sys.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH) + // The race detector doesn't work on Alpine Linux: + // golang.org/issue/14481 + // gccgo does not support the race detector. + if isAlpineLinux() || runtime.Compiler == "gccgo" { + canRace = false } } // Don't let these environment variables confuse the test. diff --git a/src/cmd/go/internal/work/init.go b/src/cmd/go/internal/work/init.go index eb99815338757..3f6252ed84b7f 100644 --- a/src/cmd/go/internal/work/init.go +++ b/src/cmd/go/internal/work/init.go @@ -10,6 +10,7 @@ import ( "cmd/go/internal/base" "cmd/go/internal/cfg" "cmd/go/internal/load" + "cmd/internal/sys" "flag" "fmt" "os" @@ -42,18 +43,14 @@ func instrumentInit() { fmt.Fprintf(os.Stderr, "go %s: may not use -race and -msan simultaneously\n", flag.Args()[0]) os.Exit(2) } - if cfg.BuildMSan && (cfg.Goos != "linux" || cfg.Goarch != "amd64" && cfg.Goarch != "arm64") { + if cfg.BuildMSan && !sys.MSanSupported(cfg.Goos, cfg.Goarch) { fmt.Fprintf(os.Stderr, "-msan is not supported on %s/%s\n", cfg.Goos, cfg.Goarch) os.Exit(2) } if cfg.BuildRace { - platform := cfg.Goos + "/" + cfg.Goarch - switch platform { - default: + if !sys.RaceDetectorSupported(cfg.Goos, cfg.Goarch) { fmt.Fprintf(os.Stderr, "go %s: -race is only supported on linux/amd64, linux/ppc64le, freebsd/amd64, netbsd/amd64, darwin/amd64 and windows/amd64\n", flag.Args()[0]) os.Exit(2) - case "linux/amd64", "linux/ppc64le", "freebsd/amd64", "netbsd/amd64", "darwin/amd64", "windows/amd64": - // race supported on these platforms } } mode := "race" diff --git a/src/cmd/internal/sys/supported.go b/src/cmd/internal/sys/supported.go new file mode 100644 index 0000000000000..22dec702a576d --- /dev/null +++ b/src/cmd/internal/sys/supported.go @@ -0,0 +1,29 @@ +// Copyright 2018 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. + +package sys + +// RaceDetectorSupported reports whether goos/goarch supports the race +// detector. There is a copy of this function in cmd/dist/test.go. +func RaceDetectorSupported(goos, goarch string) bool { + switch goos { + case "linux": + return goarch == "amd64" || goarch == "ppc64le" + case "darwin", "freebsd", "netbsd", "windows": + return goarch == "amd64" + default: + return false + } +} + +// MSanSupported reports whether goos/goarch supports the memory +// sanitizer option. There is a copy of this function in cmd/dist/test.go. +func MSanSupported(goos, goarch string) bool { + switch goos { + case "linux": + return goarch == "amd64" || goarch == "arm64" + default: + return false + } +} diff --git a/test/fixedbugs/issue13265.go b/test/fixedbugs/issue13265.go index 3036ba7c24408..3e16cee6e75a5 100644 --- a/test/fixedbugs/issue13265.go +++ b/test/fixedbugs/issue13265.go @@ -1,4 +1,5 @@ // errorcheck -0 -race +// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64 // Copyright 2017 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/issue15091.go b/test/fixedbugs/issue15091.go index 00fb473d6a27e..678e7911c8023 100644 --- a/test/fixedbugs/issue15091.go +++ b/test/fixedbugs/issue15091.go @@ -1,4 +1,5 @@ // errorcheck -0 -race +// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64 // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/issue16008.go b/test/fixedbugs/issue16008.go index 0e369efcbbf2a..45457cdb7f568 100644 --- a/test/fixedbugs/issue16008.go +++ b/test/fixedbugs/issue16008.go @@ -1,4 +1,5 @@ // errorcheck -0 -race +// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64 // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/issue17449.go b/test/fixedbugs/issue17449.go index 23029178e8dcf..51cc8eaa06d85 100644 --- a/test/fixedbugs/issue17449.go +++ b/test/fixedbugs/issue17449.go @@ -1,4 +1,5 @@ // errorcheck -0 -race +// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64 // Copyright 2016 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style diff --git a/test/fixedbugs/issue24651a.go b/test/fixedbugs/issue24651a.go index 5f63635a2a814..b12b0cce29b1e 100644 --- a/test/fixedbugs/issue24651a.go +++ b/test/fixedbugs/issue24651a.go @@ -1,4 +1,5 @@ //errorcheck -0 -race -m -m +// +build linux,amd64 linux,ppc64le darwin,amd64 freebsd,amd64 netbsd,amd64 windows,amd64 // Copyright 2018 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style From e8e074d1ba286c3e06847a96fe6aa90e294dfcd9 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 19 Jul 2018 14:03:09 -0700 Subject: [PATCH 0074/1663] cmd/vet: implement old TODO from testdata/print.go MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The code was fixed in CL 108559 but the testing TODO was not implemented. Updates #22936 Change-Id: I20a703260a181bbcf5f87609d6fb8221a182be1a Reviewed-on: https://go-review.googlesource.com/125038 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike Reviewed-by: Daniel Martí --- src/cmd/vet/testdata/print.go | 42 +++++++++-------------------------- src/cmd/vet/vet_test.go | 3 +-- 2 files changed, 12 insertions(+), 33 deletions(-) diff --git a/src/cmd/vet/testdata/print.go b/src/cmd/vet/testdata/print.go index ecafed5fa2f2c..88163b59d949b 100644 --- a/src/cmd/vet/testdata/print.go +++ b/src/cmd/vet/testdata/print.go @@ -4,16 +4,10 @@ // This file contains tests for the printf checker. -// TODO(rsc): The user-defined wrapper tests are commented out -// because they produced too many false positives when vet was -// enabled during go test. See the TODO in ../print.go for a plan -// to fix that; when it's fixed, uncomment the user-defined wrapper tests. - package testdata import ( "fmt" - . "fmt" logpkg "log" // renamed to make it harder to see "math" "os" @@ -103,7 +97,7 @@ func PrintfTests() { fmt.Printf("%s", stringerarrayv) fmt.Printf("%v", notstringerarrayv) fmt.Printf("%T", notstringerarrayv) - fmt.Printf("%d", new(Formatter)) + fmt.Printf("%d", new(fmt.Formatter)) fmt.Printf("%*%", 2) // Ridiculous but allowed. fmt.Printf("%s", interface{}(nil)) // Nothing useful we can say. @@ -250,13 +244,13 @@ func PrintfTests() { t.Logf("%d", 3) t.Logf("%d", "hi") // ERROR "Logf format %d has arg \x22hi\x22 of wrong type string" - // Errorf(1, "%d", 3) // OK - // Errorf(1, "%d", "hi") // no error "Errorf format %d has arg \x22hi\x22 of wrong type string" + Errorf(1, "%d", 3) // OK + Errorf(1, "%d", "hi") // ERROR "Errorf format %d has arg \x22hi\x22 of wrong type string" // Multiple string arguments before variadic args - // errorf("WARNING", "foobar") // OK - // errorf("INFO", "s=%s, n=%d", "foo", 1) // OK - // errorf("ERROR", "%d") // no error "errorf format %d reads arg #1, but call has 0 args" + errorf("WARNING", "foobar") // OK + errorf("INFO", "s=%s, n=%d", "foo", 1) // OK + errorf("ERROR", "%d") // no error "errorf format %d reads arg #1, but call has 0 args" // Printf from external package // externalprintf.Printf("%d", 42) // OK @@ -348,46 +342,32 @@ func (ss *someStruct) log(f func(), args ...interface{}) {} // A function we use as a function value; it has no other purpose. func someFunction() {} -/* // Printf is used by the test so we must declare it. func Printf(format string, args ...interface{}) { - panic("don't call - testing only") + fmt.Printf(format, args...) } // Println is used by the test so we must declare it. func Println(args ...interface{}) { - panic("don't call - testing only") -} - -// Logf is used by the test so we must declare it. -func Logf(format string, args ...interface{}) { - panic("don't call - testing only") + fmt.Println(args...) } -// Log is used by the test so we must declare it. -func Log(args ...interface{}) { - panic("don't call - testing only") -} -*/ - // printf is used by the test so we must declare it. func printf(format string, args ...interface{}) { - panic("don't call - testing only") + fmt.Printf(format, args...) } -/* // Errorf is used by the test for a case in which the first parameter // is not a format string. func Errorf(i int, format string, args ...interface{}) { - panic("don't call - testing only") + _ = fmt.Errorf(format, args...) } // errorf is used by the test for a case in which the function accepts multiple // string parameters before variadic arguments func errorf(level, format string, args ...interface{}) { - panic("don't call - testing only") + _ = fmt.Errorf(format, args...) } -*/ // multi is used by the test. func multi() []interface{} { diff --git a/src/cmd/vet/vet_test.go b/src/cmd/vet/vet_test.go index ecb4ce129566e..90665d77bc655 100644 --- a/src/cmd/vet/vet_test.go +++ b/src/cmd/vet/vet_test.go @@ -95,8 +95,7 @@ func TestVet(t *testing.T) { } batch := make([][]string, wide) for i, file := range gos { - // TODO: Remove print.go exception once we require type checking for everything, - // and then delete TestVetPrint. + // The print.go test is run by TestVetPrint. if strings.HasSuffix(file, "print.go") { continue } From 247b034ac04b753d5e3ca7d0d8a172f63db5dcb4 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 21 Aug 2018 03:46:17 +0000 Subject: [PATCH 0075/1663] cmd/go: run mkalldocs.sh after earlier revert Change-Id: Ie4ed8b3e7d26ae53b2290a7a6e7d9888eb963edc Reviewed-on: https://go-review.googlesource.com/130318 Reviewed-by: Brad Fitzpatrick --- src/cmd/go/alldocs.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 0aa69a0aba7c5..ebbd154f3e6ff 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -1005,16 +1005,13 @@ // // Usage: // -// go mod graph [-dot] +// go mod graph // // Graph prints the module requirement graph (with replacements applied) // in text form. Each line in the output has two space-separated fields: a module // and one of its requirements. Each module is identified as a string of the form // path@version, except for the main module, which has no @version suffix. // -// The -dot flag generates the output in graphviz format that can be used -// with a tool like dot to visually render the dependency graph. -// // // Initialize new module in current directory // From 6417e91962f40ce929a279ac46d958d627c357da Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Mon, 20 Aug 2018 18:42:02 -0700 Subject: [PATCH 0076/1663] cmd/link: pass provided ldflags when testing whether an ldflag is supported It's possible for one of the ldflags to cause the compiler driver to use a different linker than the default, so we need to make sure that the flag is supported by whichever linker is specified. Fixes #27110. Change-Id: Ic0c51b886e34344d324e68cbf6673b168c14992f Reviewed-on: https://go-review.googlesource.com/130316 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/ld/lib.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index d86b2aa5446ac..9be9f5f916506 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1366,7 +1366,12 @@ func linkerFlagSupported(linker, flag string) bool { } }) - cmd := exec.Command(linker, flag, "trivial.c") + var flags []string + flags = append(flags, ldflag...) + flags = append(flags, strings.Fields(*flagExtldflags)...) + flags = append(flags, flag, "trivial.c") + + cmd := exec.Command(linker, flags...) cmd.Dir = *flagTmpdir cmd.Env = append([]string{"LC_ALL=C"}, os.Environ()...) out, err := cmd.CombinedOutput() From 15c362a26081d99ee968f99fb3fc43b2e093a81d Mon Sep 17 00:00:00 2001 From: Sandy Date: Mon, 30 Jul 2018 03:56:46 +0000 Subject: [PATCH 0077/1663] time: use secondsPerMinute instead of 60 It's maybe better. Change-Id: I7929e93a95c96676915bc24f2f7cce4e73b08c59 GitHub-Last-Rev: a8c2bb6cafe78090f35c3b194e270e301255be89 GitHub-Pull-Request: golang/go#26685 Reviewed-on: https://go-review.googlesource.com/126623 Reviewed-by: Ralph Corderoy Reviewed-by: Brad Fitzpatrick --- src/time/time.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/time/time.go b/src/time/time.go index 2374043ea3cc6..5350d2e98b2b2 100644 --- a/src/time/time.go +++ b/src/time/time.go @@ -933,7 +933,7 @@ func (t Time) AddDate(years int, months int, days int) Time { const ( secondsPerMinute = 60 - secondsPerHour = 60 * 60 + secondsPerHour = 60 * secondsPerMinute secondsPerDay = 24 * secondsPerHour secondsPerWeek = 7 * secondsPerDay daysPer400Years = 365*400 + 97 From 827248484004300c52162d55dfa05083862062ed Mon Sep 17 00:00:00 2001 From: Kevin Zita Date: Fri, 3 Aug 2018 18:08:09 +0000 Subject: [PATCH 0078/1663] strings: revise ToUpperSpecial and ToLowerSpecial wording Fixes #26654 Change-Id: I4832c45cad40607b83e1a8a9b562fa12e639b7d9 GitHub-Last-Rev: c9ceedb7d4b4c01f91ea4fe3dc3496e73eed9120 GitHub-Pull-Request: golang/go#26781 Reviewed-on: https://go-review.googlesource.com/127716 Reviewed-by: Brad Fitzpatrick --- src/strings/strings.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/strings/strings.go b/src/strings/strings.go index 20868be269461..9e7d4f0455982 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -616,13 +616,13 @@ func ToLower(s string) string { func ToTitle(s string) string { return Map(unicode.ToTitle, s) } // ToUpperSpecial returns a copy of the string s with all Unicode letters mapped to their -// upper case, giving priority to the special casing rules. +// upper case using the case mapping specified by c. func ToUpperSpecial(c unicode.SpecialCase, s string) string { return Map(func(r rune) rune { return c.ToUpper(r) }, s) } // ToLowerSpecial returns a copy of the string s with all Unicode letters mapped to their -// lower case, giving priority to the special casing rules. +// lower case using the case mapping specified by c. func ToLowerSpecial(c unicode.SpecialCase, s string) string { return Map(func(r rune) rune { return c.ToLower(r) }, s) } From 80fe2e6e37120e665cd523e1edf7eb1401b9b73b Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 2 Aug 2018 19:15:25 +0000 Subject: [PATCH 0079/1663] net: lazily look up the listenerBacklog value on first use Don't open files or do sysctls in init. Updates #26775 Change-Id: I017bed6c24ef1e4bc30040120349fb779f203225 Reviewed-on: https://go-review.googlesource.com/127655 Reviewed-by: Ian Lance Taylor --- src/net/net.go | 11 ++++++++++- src/net/sock_posix.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/net/net.go b/src/net/net.go index c909986269906..77b8f69074e39 100644 --- a/src/net/net.go +++ b/src/net/net.go @@ -357,7 +357,16 @@ type PacketConn interface { SetWriteDeadline(t time.Time) error } -var listenerBacklog = maxListenerBacklog() +var listenerBacklogCache struct { + sync.Once + val int +} + +// listenerBacklog is a caching wrapper around maxListenerBacklog. +func listenerBacklog() int { + listenerBacklogCache.Do(func() { listenerBacklogCache.val = maxListenerBacklog() }) + return listenerBacklogCache.val +} // A Listener is a generic network listener for stream-oriented protocols. // diff --git a/src/net/sock_posix.go b/src/net/sock_posix.go index 677e423ffaff2..1cfd8a58c604b 100644 --- a/src/net/sock_posix.go +++ b/src/net/sock_posix.go @@ -54,7 +54,7 @@ func socket(ctx context.Context, net string, family, sotype, proto int, ipv6only if laddr != nil && raddr == nil { switch sotype { case syscall.SOCK_STREAM, syscall.SOCK_SEQPACKET: - if err := fd.listenStream(laddr, listenerBacklog, ctrlFn); err != nil { + if err := fd.listenStream(laddr, listenerBacklog(), ctrlFn); err != nil { fd.Close() return nil, err } From 2a5df067654970557f5038d238954eb9893e7f31 Mon Sep 17 00:00:00 2001 From: Cholerae Hu Date: Fri, 3 Aug 2018 14:29:37 +0800 Subject: [PATCH 0080/1663] hash/crc64: lazily initialize slice8Tables Saves 36KB of memory in stdlib packages. Updates #26775 Change-Id: I0f9d7b17d9768f6fb980d5fbba7c45920215a5fc Reviewed-on: https://go-review.googlesource.com/127735 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/hash/crc64/crc64.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/hash/crc64/crc64.go b/src/hash/crc64/crc64.go index a799a017c938c..063c63c6a3b09 100644 --- a/src/hash/crc64/crc64.go +++ b/src/hash/crc64/crc64.go @@ -10,6 +10,7 @@ package crc64 import ( "errors" "hash" + "sync" ) // The size of a CRC-64 checksum in bytes. @@ -28,13 +29,24 @@ const ( type Table [256]uint64 var ( - slicing8TableISO = makeSlicingBy8Table(makeTable(ISO)) - slicing8TableECMA = makeSlicingBy8Table(makeTable(ECMA)) + slicing8TablesBuildOnce sync.Once + slicing8TableISO *[8]Table + slicing8TableECMA *[8]Table ) +func buildSlicing8TablesOnce() { + slicing8TablesBuildOnce.Do(buildSlicing8Tables) +} + +func buildSlicing8Tables() { + slicing8TableISO = makeSlicingBy8Table(makeTable(ISO)) + slicing8TableECMA = makeSlicingBy8Table(makeTable(ECMA)) +} + // MakeTable returns a Table constructed from the specified polynomial. // The contents of this Table must not be modified. func MakeTable(poly uint64) *Table { + buildSlicing8TablesOnce() switch poly { case ISO: return &slicing8TableISO[0] @@ -141,6 +153,7 @@ func readUint64(b []byte) uint64 { } func update(crc uint64, tab *Table, p []byte) uint64 { + buildSlicing8TablesOnce() crc = ^crc // Table comparison is somewhat expensive, so avoid it for small sizes for len(p) >= 64 { From 187a41dbf730117bd52f871009466a9679d6b718 Mon Sep 17 00:00:00 2001 From: Marcus Willock Date: Fri, 3 Aug 2018 15:13:14 +0000 Subject: [PATCH 0081/1663] net/http: add an example of creating a custom FileSystem The existing documentation of http.Dir is clear in that, if you want to hide your files and directories that start with a period, you must create a custom FileSystem. However, there are currently no example on how to create a custom FileSystem. This commit provides an example. Fixes #20759 Change-Id: I5a350675536f81412af384d1a316fd6cd6241563 GitHub-Last-Rev: 8b0b644cd02c59fe2461908304c44d64e8be431e GitHub-Pull-Request: golang/go#26768 Reviewed-on: https://go-review.googlesource.com/127576 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/example_filesystem_test.go | 71 +++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 src/net/http/example_filesystem_test.go diff --git a/src/net/http/example_filesystem_test.go b/src/net/http/example_filesystem_test.go new file mode 100644 index 0000000000000..e1fd42d049489 --- /dev/null +++ b/src/net/http/example_filesystem_test.go @@ -0,0 +1,71 @@ +// Copyright 2018 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. + +package http_test + +import ( + "log" + "net/http" + "os" + "strings" +) + +// containsDotFile reports whether name contains a path element starting with a period. +// The name is assumed to be a delimited by forward slashes, as guaranteed +// by the http.FileSystem interface. +func containsDotFile(name string) bool { + parts := strings.Split(name, "/") + for _, part := range parts { + if strings.HasPrefix(part, ".") { + return true + } + } + return false +} + +// dotFileHidingFile is the http.File use in dotFileHidingFileSystem. +// It is used to wrap the Readdir method of http.File so that we can +// remove files and directories that start with a period from its output. +type dotFileHidingFile struct { + http.File +} + +// Readdir is a wrapper around the Readdir method of the embedded File +// that filters out all files that start with a period in their name. +func (f dotFileHidingFile) Readdir(n int) (fis []os.FileInfo, err error) { + files, err := f.File.Readdir(n) + for _, file := range files { // Filters out the dot files + if !strings.HasPrefix(file.Name(), ".") { + fis = append(fis, file) + } + } + return +} + +// dotFileHidingFileSystem is an http.FileSystem that hides +// hidden "dot files" from being served. +type dotFileHidingFileSystem struct { + http.FileSystem +} + +// Open is a wrapper around the Open method of the embedded FileSystem +// that serves a 403 permission error when name has a file or directory +// with whose name starts with a period in its path. +func (fs dotFileHidingFileSystem) Open(name string) (http.File, error) { + if containsDotFile(name) { // If dot file, return 403 response + return nil, os.ErrPermission + } + + file, err := fs.FileSystem.Open(name) + if err != nil { + return nil, err + } + return dotFileHidingFile{file}, err +} + +func ExampleFileServer_dotFileHiding() { + fs := dotFileHidingFileSystem{http.Dir(".")} + http.Handle("/", http.FileServer(fs)) + log.Fatal(http.ListenAndServe(":8080", nil)) +} From d7ab57efda161c1757e591ec469ca4d01976cb66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 15 Aug 2018 12:40:07 +0100 Subject: [PATCH 0082/1663] cmd/go: fix 'go vet -h' to print the right text MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For the last two releases, its output has been the same as 'go -h'. The test and vet sub-commands share their flag logic via the cmdflag package, so fixing it there would mean a larger refactor. Moreover, the test subcommand handles its '-h' flag in a special way; that's #26999. For now, use a much less invasive fix, mirroring the special-casing of 'test -h' to simply print vet's short usage text. Also add a regression test via a cmd/go test script. Fixes #26998. Change-Id: Ie6b866d98116a1bc5f84a204e1c9f1c2f6b48bff Reviewed-on: https://go-review.googlesource.com/129318 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike Reviewed-by: Russ Cox --- src/cmd/go/main.go | 7 +++++++ src/cmd/go/testdata/script/help.txt | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index f64ffeb6708f9..31c554e715530 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -239,6 +239,13 @@ func mainUsage() { if len(os.Args) > 1 && os.Args[1] == "test" { test.Usage() } + // Since vet shares code with test in cmdflag, it doesn't show its + // command usage properly. For now, special case it too. + // TODO(mvdan): fix the cmdflag package instead; see + // golang.org/issue/26999 + if len(os.Args) > 1 && os.Args[1] == "vet" { + vet.CmdVet.Usage() + } help.PrintUsage(os.Stderr, base.Go) os.Exit(2) } diff --git a/src/cmd/go/testdata/script/help.txt b/src/cmd/go/testdata/script/help.txt index cbbd15404b536..939da30283ad2 100644 --- a/src/cmd/go/testdata/script/help.txt +++ b/src/cmd/go/testdata/script/help.txt @@ -28,3 +28,9 @@ stdout 'usage: go mod tidy' # go mod --help doesn't print help but at least suggests it. ! go mod --help stderr 'Run ''go help mod'' for usage.' + +# Earlier versions of Go printed the same as 'go -h' here. +# Also make sure we print the short help line. +! go vet -h +stderr 'usage: go vet' +stderr 'Run ''go help vet'' for details' From e7f59f02841361cbeb75241df6cecb697f47a989 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 20 Aug 2018 10:55:26 +0200 Subject: [PATCH 0083/1663] cmd/compile/internal/gc: unexport Deferproc and Newproc They are no longer used outside the package since CL 38080. Passes toolstash-check -all Change-Id: I30977ed2b233b7c8c53632cc420938bc3b0e37c6 Reviewed-on: https://go-review.googlesource.com/129781 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/gc/go.go | 4 ++-- src/cmd/compile/internal/gc/ssa.go | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/cmd/compile/internal/gc/go.go b/src/cmd/compile/internal/gc/go.go index 95bf562e2c1af..d8ab5eb39cc6b 100644 --- a/src/cmd/compile/internal/gc/go.go +++ b/src/cmd/compile/internal/gc/go.go @@ -281,7 +281,7 @@ var ( assertE2I2, assertI2I, assertI2I2, - Deferproc, + deferproc, Deferreturn, Duffcopy, Duffzero, @@ -290,7 +290,7 @@ var ( growslice, msanread, msanwrite, - Newproc, + newproc, panicdivide, panicdottypeE, panicdottypeI, diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 86b457b75821e..199e4d9072944 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -56,7 +56,7 @@ func initssaconfig() { assertE2I2 = sysfunc("assertE2I2") assertI2I = sysfunc("assertI2I") assertI2I2 = sysfunc("assertI2I2") - Deferproc = sysfunc("deferproc") + deferproc = sysfunc("deferproc") Deferreturn = sysfunc("deferreturn") Duffcopy = sysfunc("duffcopy") Duffzero = sysfunc("duffzero") @@ -65,7 +65,7 @@ func initssaconfig() { growslice = sysfunc("growslice") msanread = sysfunc("msanread") msanwrite = sysfunc("msanwrite") - Newproc = sysfunc("newproc") + newproc = sysfunc("newproc") panicdivide = sysfunc("panicdivide") panicdottypeE = sysfunc("panicdottypeE") panicdottypeI = sysfunc("panicdottypeI") @@ -3578,7 +3578,7 @@ func (s *state) call(n *Node, k callKind) *ssa.Value { // Defer/go args if k != callNormal { - // Write argsize and closure (args to Newproc/Deferproc). + // Write argsize and closure (args to newproc/deferproc). argStart := Ctxt.FixedFrameSize() argsize := s.constInt32(types.Types[TUINT32], int32(stksize)) addr := s.constOffPtrSP(s.f.Config.Types.UInt32Ptr, argStart) @@ -3592,9 +3592,9 @@ func (s *state) call(n *Node, k callKind) *ssa.Value { var call *ssa.Value switch { case k == callDefer: - call = s.newValue1A(ssa.OpStaticCall, types.TypeMem, Deferproc, s.mem()) + call = s.newValue1A(ssa.OpStaticCall, types.TypeMem, deferproc, s.mem()) case k == callGo: - call = s.newValue1A(ssa.OpStaticCall, types.TypeMem, Newproc, s.mem()) + call = s.newValue1A(ssa.OpStaticCall, types.TypeMem, newproc, s.mem()) case closure != nil: // rawLoad because loading the code pointer from a // closure is always safe, but IsSanitizerSafeAddr From 2d3599e57daf5816ee5b74553afd11decc611d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 7 Jul 2018 15:59:20 +0100 Subject: [PATCH 0084/1663] encoding/json: encode struct field names ahead of time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Struct field names are static, so we can run HTMLEscape on them when building each struct type encoder. Then, when running the struct encoder, we can select either the original or the escaped field name to write directly. When the encoder is not escaping HTML, using the original string works because neither Go struct field names nor JSON tags allow any characters that would need to be escaped, like '"', '\\', or '\n'. When the encoder is escaping HTML, the only difference is that '<', '>', and '&' are allowed via JSON struct field tags, hence why we use HTMLEscape to properly escape them. All of the above lets us encode field names with a simple if/else and WriteString calls, which are considerably simpler and faster than encoding an arbitrary string. While at it, also include the quotes and colon in these strings, to avoid three WriteByte calls in the loop hot path. Also added a few tests, to ensure that the behavior in these edge cases is not broken. The output of the tests is the same if this optimization is reverted. name old time/op new time/op delta CodeEncoder-4 7.12ms ± 0% 6.14ms ± 0% -13.85% (p=0.004 n=6+5) name old speed new speed delta CodeEncoder-4 272MB/s ± 0% 316MB/s ± 0% +16.08% (p=0.004 n=6+5) name old alloc/op new alloc/op delta CodeEncoder-4 91.9kB ± 0% 93.2kB ± 0% +1.43% (p=0.002 n=6+6) name old allocs/op new allocs/op delta CodeEncoder-4 0.00 0.00 ~ (all equal) Updates #5683. Change-Id: I6f6a340d0de4670799ce38cf95b2092822d2e3ef Reviewed-on: https://go-review.googlesource.com/122460 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/encoding/json/decode_test.go | 2 +- src/encoding/json/encode.go | 27 +++++++++++++++++++++++---- src/encoding/json/encode_test.go | 15 +++++++++++++++ src/encoding/json/stream_test.go | 9 +++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go index ab83b81bb3958..127bc494e5d46 100644 --- a/src/encoding/json/decode_test.go +++ b/src/encoding/json/decode_test.go @@ -142,7 +142,7 @@ var ( umstructXY = ustructText{unmarshalerText{"x", "y"}} ummapType = map[unmarshalerText]bool{} - ummapXY = map[unmarshalerText]bool{unmarshalerText{"x", "y"}: true} + ummapXY = map[unmarshalerText]bool{{"x", "y"}: true} ) // Test data structures for anonymous fields. diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 7ebb04c50a949..632c12404a677 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -641,8 +641,11 @@ func (se *structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { } else { e.WriteByte(',') } - e.string(f.name, opts.escapeHTML) - e.WriteByte(':') + if opts.escapeHTML { + e.WriteString(f.nameEscHTML) + } else { + e.WriteString(f.nameNonEsc) + } opts.quoted = f.quoted se.fieldEncs[i](e, fv, opts) } @@ -1036,6 +1039,9 @@ type field struct { nameBytes []byte // []byte(name) equalFold func(s, t []byte) bool // bytes.EqualFold or equivalent + nameNonEsc string // `"` + name + `":` + nameEscHTML string // `"` + HTMLEscape(name) + `":` + tag bool index []int typ reflect.Type @@ -1086,6 +1092,9 @@ func typeFields(t reflect.Type) []field { // Fields found. var fields []field + // Buffer to run HTMLEscape on field names. + var nameEscBuf bytes.Buffer + for len(next) > 0 { current, next = next, current[:0] count, nextCount = nextCount, map[reflect.Type]int{} @@ -1152,14 +1161,24 @@ func typeFields(t reflect.Type) []field { if name == "" { name = sf.Name } - fields = append(fields, fillField(field{ + field := fillField(field{ name: name, tag: tagged, index: index, typ: ft, omitEmpty: opts.Contains("omitempty"), quoted: quoted, - })) + }) + + // Build nameEscHTML and nameNonEsc ahead of time. + nameEscBuf.Reset() + nameEscBuf.WriteString(`"`) + HTMLEscape(&nameEscBuf, field.nameBytes) + nameEscBuf.WriteString(`":`) + field.nameEscHTML = nameEscBuf.String() + field.nameNonEsc = `"` + field.name + `":` + + fields = append(fields, field) if count[f.typ] > 1 { // If there were multiple instances, add a second, // so that the annihilation code will see a duplicate. diff --git a/src/encoding/json/encode_test.go b/src/encoding/json/encode_test.go index b90483cf35f91..1b7838c895d11 100644 --- a/src/encoding/json/encode_test.go +++ b/src/encoding/json/encode_test.go @@ -995,3 +995,18 @@ func TestMarshalPanic(t *testing.T) { Marshal(&marshalPanic{}) t.Error("Marshal should have panicked") } + +func TestMarshalUncommonFieldNames(t *testing.T) { + v := struct { + A0, À, Aβ int + }{} + b, err := Marshal(v) + if err != nil { + t.Fatal("Marshal:", err) + } + want := `{"A0":0,"À":0,"Aβ":0}` + got := string(b) + if got != want { + t.Fatalf("Marshal: got %s want %s", got, want) + } +} diff --git a/src/encoding/json/stream_test.go b/src/encoding/json/stream_test.go index 83c01d170c0b3..0ed1c9e974754 100644 --- a/src/encoding/json/stream_test.go +++ b/src/encoding/json/stream_test.go @@ -93,6 +93,10 @@ func TestEncoderIndent(t *testing.T) { func TestEncoderSetEscapeHTML(t *testing.T) { var c C var ct CText + var tagStruct struct { + Valid int `json:"<>&#! "` + Invalid int `json:"\\"` + } for _, tt := range []struct { name string v interface{} @@ -102,6 +106,11 @@ func TestEncoderSetEscapeHTML(t *testing.T) { {"c", c, `"\u003c\u0026\u003e"`, `"<&>"`}, {"ct", ct, `"\"\u003c\u0026\u003e\""`, `"\"<&>\""`}, {`"<&>"`, "<&>", `"\u003c\u0026\u003e"`, `"<&>"`}, + { + "tagStruct", tagStruct, + `{"\u003c\u003e\u0026#! ":0,"Invalid":0}`, + `{"<>&#! ":0,"Invalid":0}`, + }, } { var buf bytes.Buffer enc := NewEncoder(&buf) From 30d3ebe36701b16678a51144eb3c5e958f382bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 7 Jul 2018 21:40:28 +0100 Subject: [PATCH 0085/1663] encoding/json: remove alloc when encoding short byte slices MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the encoded bytes fit in the bootstrap array encodeState.scratch, use that instead of allocating a new byte slice. Also tweaked the Encoding vs Encoder heuristic to use the length of the encoded bytes, not the length of the input bytes. Encoding is used for allocations of up to 1024 bytes, as we measured 2048 to be the point where it no longer provides a noticeable advantage. Also added some benchmarks. Only the first case changes in behavior. name old time/op new time/op delta MarshalBytes/32-4 420ns ± 1% 383ns ± 1% -8.69% (p=0.002 n=6+6) MarshalBytes/256-4 913ns ± 1% 915ns ± 0% ~ (p=0.580 n=5+6) MarshalBytes/4096-4 7.72µs ± 0% 7.74µs ± 0% ~ (p=0.340 n=5+6) name old alloc/op new alloc/op delta MarshalBytes/32-4 112B ± 0% 64B ± 0% -42.86% (p=0.002 n=6+6) MarshalBytes/256-4 736B ± 0% 736B ± 0% ~ (all equal) MarshalBytes/4096-4 7.30kB ± 0% 7.30kB ± 0% ~ (all equal) name old allocs/op new allocs/op delta MarshalBytes/32-4 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.002 n=6+6) MarshalBytes/256-4 2.00 ± 0% 2.00 ± 0% ~ (all equal) MarshalBytes/4096-4 2.00 ± 0% 2.00 ± 0% ~ (all equal) Updates #5683. Change-Id: I5fa55c27bd7728338d770ae7c0756885ba9a5724 Reviewed-on: https://go-review.googlesource.com/122462 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/encoding/json/bench_test.go | 28 ++++++++++++++++++++++++++++ src/encoding/json/encode.go | 18 +++++++++++++----- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/src/encoding/json/bench_test.go b/src/encoding/json/bench_test.go index bd322db2e6ffe..72cb349062c4a 100644 --- a/src/encoding/json/bench_test.go +++ b/src/encoding/json/bench_test.go @@ -114,6 +114,34 @@ func BenchmarkCodeMarshal(b *testing.B) { b.SetBytes(int64(len(codeJSON))) } +func benchMarshalBytes(n int) func(*testing.B) { + sample := []byte("hello world") + // Use a struct pointer, to avoid an allocation when passing it as an + // interface parameter to Marshal. + v := &struct { + Bytes []byte + }{ + bytes.Repeat(sample, (n/len(sample))+1)[:n], + } + return func(b *testing.B) { + for i := 0; i < b.N; i++ { + if _, err := Marshal(v); err != nil { + b.Fatal("Marshal:", err) + } + } + } +} + +func BenchmarkMarshalBytes(b *testing.B) { + // 32 fits within encodeState.scratch. + b.Run("32", benchMarshalBytes(32)) + // 256 doesn't fit in encodeState.scratch, but is small enough to + // allocate and avoid the slower base64.NewEncoder. + b.Run("256", benchMarshalBytes(256)) + // 4096 is large enough that we want to avoid allocating for it. + b.Run("4096", benchMarshalBytes(4096)) +} + func BenchmarkCodeDecoder(b *testing.B) { if codeJSON == nil { b.StopTimer() diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 632c12404a677..d5fe4d6b78b23 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -718,14 +718,22 @@ func encodeByteSlice(e *encodeState, v reflect.Value, _ encOpts) { } s := v.Bytes() e.WriteByte('"') - if len(s) < 1024 { - // for small buffers, using Encode directly is much faster. - dst := make([]byte, base64.StdEncoding.EncodedLen(len(s))) + encodedLen := base64.StdEncoding.EncodedLen(len(s)) + if encodedLen <= len(e.scratch) { + // If the encoded bytes fit in e.scratch, avoid an extra + // allocation and use the cheaper Encoding.Encode. + dst := e.scratch[:encodedLen] + base64.StdEncoding.Encode(dst, s) + e.Write(dst) + } else if encodedLen <= 1024 { + // The encoded bytes are short enough to allocate for, and + // Encoding.Encode is still cheaper. + dst := make([]byte, encodedLen) base64.StdEncoding.Encode(dst, s) e.Write(dst) } else { - // for large buffers, avoid unnecessary extra temporary - // buffer space. + // The encoded bytes are too long to cheaply allocate, and + // Encoding.Encode is no longer noticeably cheaper. enc := base64.NewEncoder(base64.StdEncoding, e) enc.Write(s) enc.Close() From c1807989563e0bafc14c56dba3eb405a099f4495 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 21 Aug 2018 10:26:45 +0100 Subject: [PATCH 0086/1663] cmd/compile: fix racy setting of gc's Config.Race MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ssaConfig.Race was being set by many goroutines concurrently, resulting in a data race seen below. This was very likely introduced by CL 121235. WARNING: DATA RACE Write at 0x00c000344408 by goroutine 12: cmd/compile/internal/gc.buildssa() /workdir/go/src/cmd/compile/internal/gc/ssa.go:134 +0x7a8 cmd/compile/internal/gc.compileSSA() /workdir/go/src/cmd/compile/internal/gc/pgen.go:259 +0x5d cmd/compile/internal/gc.compileFunctions.func2() /workdir/go/src/cmd/compile/internal/gc/pgen.go:323 +0x5a Previous write at 0x00c000344408 by goroutine 11: cmd/compile/internal/gc.buildssa() /workdir/go/src/cmd/compile/internal/gc/ssa.go:134 +0x7a8 cmd/compile/internal/gc.compileSSA() /workdir/go/src/cmd/compile/internal/gc/pgen.go:259 +0x5d cmd/compile/internal/gc.compileFunctions.func2() /workdir/go/src/cmd/compile/internal/gc/pgen.go:323 +0x5a Goroutine 12 (running) created at: cmd/compile/internal/gc.compileFunctions() /workdir/go/src/cmd/compile/internal/gc/pgen.go:321 +0x39b cmd/compile/internal/gc.Main() /workdir/go/src/cmd/compile/internal/gc/main.go:651 +0x437d main.main() /workdir/go/src/cmd/compile/main.go:51 +0x100 Goroutine 11 (running) created at: cmd/compile/internal/gc.compileFunctions() /workdir/go/src/cmd/compile/internal/gc/pgen.go:321 +0x39b cmd/compile/internal/gc.Main() /workdir/go/src/cmd/compile/internal/gc/main.go:651 +0x437d main.main() /workdir/go/src/cmd/compile/main.go:51 +0x100 Instead, set up the field exactly once as part of initssaconfig. Change-Id: I2c30c6b1cf92b8fd98e7cb5c2e10c526467d0b0a Reviewed-on: https://go-review.googlesource.com/130375 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Dave Cheney --- src/cmd/compile/internal/gc/ssa.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 199e4d9072944..7b254698b793c 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -49,6 +49,7 @@ func initssaconfig() { ssaConfig.Set387(thearch.Use387) } ssaConfig.SoftFloat = thearch.SoftFloat + ssaConfig.Race = flag_race ssaCaches = make([]ssa.Cache, nBackendWorkers) // Set up some runtime functions we'll need to call. @@ -131,7 +132,6 @@ func buildssa(fn *Node, worker int) *ssa.Func { s.f.Cache = &ssaCaches[worker] s.f.Cache.Reset() s.f.DebugTest = s.f.DebugHashMatch("GOSSAHASH", name) - s.f.Config.Race = flag_race s.f.Name = name if fn.Func.Pragma&Nosplit != 0 { s.f.NoSplit = true From 94e4aca3e6566671b1140192ab48d48de38ceda8 Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Tue, 21 Aug 2018 14:55:17 +0200 Subject: [PATCH 0087/1663] doc: remove mentions of cloning from GitHub MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Complete CL117178 removing all references to GitHub, and leaving a small note to make sure we remember that it's not supported. Change-Id: Id4257515a864875808fa7a67f002ed52cfd635a3 Reviewed-on: https://go-review.googlesource.com/130395 Reviewed-by: Daniel Martí --- doc/contribute.html | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/doc/contribute.html b/doc/contribute.html index 5dc8a0044d42c..5d8e1163a0407 100644 --- a/doc/contribute.html +++ b/doc/contribute.html @@ -405,7 +405,7 @@

Overview

  • -Step 1: Clone the Go source code from go.googlesource.com +Step 1: Clone the Go source code from go.googlesource.com and make sure it's stable by compiling and testing it once:
     $ git clone https://go.googlesource.com/go
    @@ -469,12 +469,11 @@ 

    Step 1: Clone the Go source code

    checked out from the correct repository. You can check out the Go source repo onto your local file system anywhere you want as long as it's outside your GOPATH. -Either clone from -go.googlesource.com or from GitHub: +Clone from go.googlesource.com (not GitHub):

    -$ git clone https://github.com/golang/go   # or https://go.googlesource.com/go
    +$ git clone https://go.googlesource.com/go
     $ cd go
     
    From 1d1a0277de8c90df72d038e3e2acf84796239bd3 Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Tue, 21 Aug 2018 12:08:27 +0100 Subject: [PATCH 0088/1663] go/build: format with latest gofmt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I172af5c83a0d4d79ad627ba9dfe02dead23bf3a6 Reviewed-on: https://go-review.googlesource.com/130376 Run-TryBot: Michael Munday TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí --- src/go/build/deps_test.go | 86 +++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index 7a154b08803e9..ef1f6604a8737 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -231,49 +231,49 @@ var pkgDeps = map[string][]string{ "go/types": {"L4", "GOPARSER", "container/heap", "go/constant"}, // One of a kind. - "archive/tar": {"L4", "OS", "syscall", "os/user"}, - "archive/zip": {"L4", "OS", "compress/flate"}, - "container/heap": {"sort"}, - "compress/bzip2": {"L4"}, - "compress/flate": {"L4"}, - "compress/gzip": {"L4", "compress/flate"}, - "compress/lzw": {"L4"}, - "compress/zlib": {"L4", "compress/flate"}, - "context": {"errors", "fmt", "reflect", "sync", "time"}, - "database/sql": {"L4", "container/list", "context", "database/sql/driver", "database/sql/internal"}, - "database/sql/driver": {"L4", "context", "time", "database/sql/internal"}, - "debug/dwarf": {"L4"}, - "debug/elf": {"L4", "OS", "debug/dwarf", "compress/zlib"}, - "debug/gosym": {"L4"}, - "debug/macho": {"L4", "OS", "debug/dwarf", "compress/zlib"}, - "debug/pe": {"L4", "OS", "debug/dwarf", "compress/zlib"}, - "debug/plan9obj": {"L4", "OS"}, - "encoding": {"L4"}, - "encoding/ascii85": {"L4"}, - "encoding/asn1": {"L4", "math/big"}, - "encoding/csv": {"L4"}, - "encoding/gob": {"L4", "OS", "encoding"}, - "encoding/hex": {"L4"}, - "encoding/json": {"L4", "encoding"}, - "encoding/pem": {"L4"}, - "encoding/xml": {"L4", "encoding"}, - "flag": {"L4", "OS"}, - "go/build": {"L4", "OS", "GOPARSER"}, - "html": {"L4"}, - "image/draw": {"L4", "image/internal/imageutil"}, - "image/gif": {"L4", "compress/lzw", "image/color/palette", "image/draw"}, - "image/internal/imageutil": {"L4"}, - "image/jpeg": {"L4", "image/internal/imageutil"}, - "image/png": {"L4", "compress/zlib"}, - "index/suffixarray": {"L4", "regexp"}, - "internal/singleflight": {"sync"}, - "internal/trace": {"L4", "OS"}, - "math/big": {"L4"}, - "mime": {"L4", "OS", "syscall", "internal/syscall/windows/registry"}, - "mime/quotedprintable": {"L4"}, - "net/internal/socktest": {"L4", "OS", "syscall", "internal/syscall/windows"}, - "net/url": {"L4"}, - "plugin": {"L0", "OS", "CGO"}, + "archive/tar": {"L4", "OS", "syscall", "os/user"}, + "archive/zip": {"L4", "OS", "compress/flate"}, + "container/heap": {"sort"}, + "compress/bzip2": {"L4"}, + "compress/flate": {"L4"}, + "compress/gzip": {"L4", "compress/flate"}, + "compress/lzw": {"L4"}, + "compress/zlib": {"L4", "compress/flate"}, + "context": {"errors", "fmt", "reflect", "sync", "time"}, + "database/sql": {"L4", "container/list", "context", "database/sql/driver", "database/sql/internal"}, + "database/sql/driver": {"L4", "context", "time", "database/sql/internal"}, + "debug/dwarf": {"L4"}, + "debug/elf": {"L4", "OS", "debug/dwarf", "compress/zlib"}, + "debug/gosym": {"L4"}, + "debug/macho": {"L4", "OS", "debug/dwarf", "compress/zlib"}, + "debug/pe": {"L4", "OS", "debug/dwarf", "compress/zlib"}, + "debug/plan9obj": {"L4", "OS"}, + "encoding": {"L4"}, + "encoding/ascii85": {"L4"}, + "encoding/asn1": {"L4", "math/big"}, + "encoding/csv": {"L4"}, + "encoding/gob": {"L4", "OS", "encoding"}, + "encoding/hex": {"L4"}, + "encoding/json": {"L4", "encoding"}, + "encoding/pem": {"L4"}, + "encoding/xml": {"L4", "encoding"}, + "flag": {"L4", "OS"}, + "go/build": {"L4", "OS", "GOPARSER"}, + "html": {"L4"}, + "image/draw": {"L4", "image/internal/imageutil"}, + "image/gif": {"L4", "compress/lzw", "image/color/palette", "image/draw"}, + "image/internal/imageutil": {"L4"}, + "image/jpeg": {"L4", "image/internal/imageutil"}, + "image/png": {"L4", "compress/zlib"}, + "index/suffixarray": {"L4", "regexp"}, + "internal/singleflight": {"sync"}, + "internal/trace": {"L4", "OS"}, + "math/big": {"L4"}, + "mime": {"L4", "OS", "syscall", "internal/syscall/windows/registry"}, + "mime/quotedprintable": {"L4"}, + "net/internal/socktest": {"L4", "OS", "syscall", "internal/syscall/windows"}, + "net/url": {"L4"}, + "plugin": {"L0", "OS", "CGO"}, "runtime/pprof/internal/profile": {"L4", "OS", "compress/gzip", "regexp"}, "testing/internal/testdeps": {"L4", "internal/testlog", "runtime/pprof", "regexp"}, "text/scanner": {"L4", "OS"}, From 1040626c0ce4a1bc2b312aa0866ffeb2ff53c1ab Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Wed, 7 Mar 2018 10:45:00 +0100 Subject: [PATCH 0089/1663] net/url: escape URL.RawQuery on Parse if it contains invalid characters Fixes #22907 Change-Id: I7abcf53ab92768514e13ce2554a6c25dcde8218e Reviewed-on: https://go-review.googlesource.com/99135 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/net/url/url.go | 51 ++++++++++++++++++++++++++++++++++++++++- src/net/url/url_test.go | 11 +++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/net/url/url.go b/src/net/url/url.go index 80eb7a86c8de2..4943ea6d67ceb 100644 --- a/src/net/url/url.go +++ b/src/net/url/url.go @@ -515,7 +515,13 @@ func parse(rawurl string, viaRequest bool) (*URL, error) { url.ForceQuery = true rest = rest[:len(rest)-1] } else { - rest, url.RawQuery = split(rest, "?", true) + var q string + rest, q = split(rest, "?", true) + if validQuery(q) { + url.RawQuery = q + } else { + url.RawQuery = QueryEscape(q) + } } if !strings.HasPrefix(rest, "/") { @@ -1114,3 +1120,46 @@ func validUserinfo(s string) bool { } return true } + +// validQuery reports whether s is a valid query string per RFC 3986 +// Section 3.4: +// query = *( pchar / "/" / "?" ) +// pchar = unreserved / pct-encoded / sub-delims / ":" / "@" +// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" +// sub-delims = "!" / "$" / "&" / "'" / "(" / ")" +// / "*" / "+" / "," / ";" / "=" +func validQuery(s string) bool { + pctEnc := 0 + + for _, r := range s { + if pctEnc > 0 { + if uint32(r) > 255 || !ishex(byte(r)) { + return false + } + pctEnc-- + continue + } else if r == '%' { + pctEnc = 2 + continue + } + + if 'A' <= r && r <= 'Z' { + continue + } + if 'a' <= r && r <= 'z' { + continue + } + if '0' <= r && r <= '9' { + continue + } + switch r { + case '-', '.', '_', '~', '!', '$', '&', '\'', '(', ')', + '*', '+', ',', ';', '=', ':', '@', '/', '?': + continue + default: + return false + } + } + + return true +} diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go index 9043a844e88f8..19d4d636d6221 100644 --- a/src/net/url/url_test.go +++ b/src/net/url/url_test.go @@ -590,6 +590,16 @@ var urltests = []URLTest{ }, "mailto:?subject=hi", }, + { + "https://example.com/search?q=Фотки собак&source=lnms", + &URL{ + Scheme: "https", + Host: "example.com", + Path: "/search", + RawQuery: "q%3D%D0%A4%D0%BE%D1%82%D0%BA%D0%B8+%D1%81%D0%BE%D0%B1%D0%B0%D0%BA%26source%3Dlnms", + }, + "https://example.com/search?q%3D%D0%A4%D0%BE%D1%82%D0%BA%D0%B8+%D1%81%D0%BE%D0%B1%D0%B0%D0%BA%26source%3Dlnms", + }, } // more useful string for debugging than fmt's struct printer @@ -1439,6 +1449,7 @@ func TestParseErrors(t *testing.T) { {"cache_object:foo", true}, {"cache_object:foo/bar", true}, {"cache_object/:foo/bar", false}, + {"https://example.com/search?q=Фотки собак&source=lnms", false}, } for _, tt := range tests { u, err := Parse(tt.in) From e8daca4c482320cecff9c31bbd60f25351d49756 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 21 Aug 2018 08:28:16 +0200 Subject: [PATCH 0090/1663] syscall: add S_IRWXG and S_IRWXO on DragonflyBSD As discussed in CL 126621, these constants are already defined on Linux, Darwin, FreeBSD and NetBSD. In order to ensure portability of existing code using the syscall package, provide them for DragonflyBSD (and OpenBSD, in a separate CL) as well. Change-Id: I708c60f75f787a410bdfa4ceebd2825874e92511 Reviewed-on: https://go-review.googlesource.com/130335 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/syscall/types_dragonfly.go | 2 ++ src/syscall/ztypes_dragonfly_amd64.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/syscall/types_dragonfly.go b/src/syscall/types_dragonfly.go index 0c060d932ece8..53bc12403b2fa 100644 --- a/src/syscall/types_dragonfly.go +++ b/src/syscall/types_dragonfly.go @@ -113,6 +113,8 @@ const ( // Directory mode bits S_IRUSR = C.S_IRUSR S_IWUSR = C.S_IWUSR S_IXUSR = C.S_IXUSR + S_IRWXG = C.S_IRWXG + S_IRWXO = C.S_IRWXO ) type Stat_t C.struct_stat diff --git a/src/syscall/ztypes_dragonfly_amd64.go b/src/syscall/ztypes_dragonfly_amd64.go index 1cb8608228543..e9e811f77643b 100644 --- a/src/syscall/ztypes_dragonfly_amd64.go +++ b/src/syscall/ztypes_dragonfly_amd64.go @@ -71,6 +71,8 @@ const ( S_IRUSR = 0x100 S_IWUSR = 0x80 S_IXUSR = 0x40 + S_IRWXG = 0x38 + S_IRWXO = 0x7 ) type Stat_t struct { From d865e1fa483d689f1f4afae0b2b6260a5b657959 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 21 Aug 2018 08:31:38 +0200 Subject: [PATCH 0091/1663] syscall: add S_IRWXG and S_IRWXO on OpenBSD As discussed in CL 126621, these constants are already defined on Linux, Darwin, FreeBSD and NetBSD. In order to ensure portability of existing code using the syscall package, provide them for OpenBSD (and DragonflyBSD, in a separate CL) as well. Change-Id: Ia9e07cb01f989d144a620d268daa8ec946788861 Reviewed-on: https://go-review.googlesource.com/130336 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/syscall/types_openbsd.go | 2 ++ src/syscall/ztypes_openbsd_386.go | 2 ++ src/syscall/ztypes_openbsd_amd64.go | 2 ++ src/syscall/ztypes_openbsd_arm.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/src/syscall/types_openbsd.go b/src/syscall/types_openbsd.go index 93456c31a0c29..922864815bc7d 100644 --- a/src/syscall/types_openbsd.go +++ b/src/syscall/types_openbsd.go @@ -114,6 +114,8 @@ const ( // Directory mode bits S_IRUSR = C.S_IRUSR S_IWUSR = C.S_IWUSR S_IXUSR = C.S_IXUSR + S_IRWXG = C.S_IRWXG + S_IRWXO = C.S_IRWXO ) type Stat_t C.struct_stat diff --git a/src/syscall/ztypes_openbsd_386.go b/src/syscall/ztypes_openbsd_386.go index 04d53966f4609..c2a03ebdd8079 100644 --- a/src/syscall/ztypes_openbsd_386.go +++ b/src/syscall/ztypes_openbsd_386.go @@ -71,6 +71,8 @@ const ( S_IRUSR = 0x100 S_IWUSR = 0x80 S_IXUSR = 0x40 + S_IRWXG = 0x38 + S_IRWXO = 0x7 ) type Stat_t struct { diff --git a/src/syscall/ztypes_openbsd_amd64.go b/src/syscall/ztypes_openbsd_amd64.go index aad787a3e497b..1a659ba2feacb 100644 --- a/src/syscall/ztypes_openbsd_amd64.go +++ b/src/syscall/ztypes_openbsd_amd64.go @@ -71,6 +71,8 @@ const ( S_IRUSR = 0x100 S_IWUSR = 0x80 S_IXUSR = 0x40 + S_IRWXG = 0x38 + S_IRWXO = 0x7 ) type Stat_t struct { diff --git a/src/syscall/ztypes_openbsd_arm.go b/src/syscall/ztypes_openbsd_arm.go index 4383b68eae230..e75043f2c67ce 100644 --- a/src/syscall/ztypes_openbsd_arm.go +++ b/src/syscall/ztypes_openbsd_arm.go @@ -71,6 +71,8 @@ const ( S_IRUSR = 0x100 S_IWUSR = 0x80 S_IXUSR = 0x40 + S_IRWXG = 0x38 + S_IRWXO = 0x7 ) type Stat_t struct { From 4e1b11e2c9bdb0ddea1141eed487be1a626ff5be Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 21 Aug 2018 10:48:00 +0200 Subject: [PATCH 0092/1663] syscall: add S_IRWXG and S_IRWXO on Solaris As discussed in CL 126621, these constants are already defined on Linux, Darwin, FreeBSD and NetBSD. In order to ensure portability of existing code using the syscall package, provide them for Solaris as well. Change-Id: Id49f6991f36775b152b9c47b9923cd0a08053bcb Reviewed-on: https://go-review.googlesource.com/130356 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/syscall/types_solaris.go | 2 ++ src/syscall/ztypes_solaris_amd64.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/syscall/types_solaris.go b/src/syscall/types_solaris.go index a219a437d534a..a9e6d6bdd63b7 100644 --- a/src/syscall/types_solaris.go +++ b/src/syscall/types_solaris.go @@ -120,6 +120,8 @@ const ( // Directory mode bits S_IRUSR = C.S_IRUSR S_IWUSR = C.S_IWUSR S_IXUSR = C.S_IXUSR + S_IRWXG = C.S_IRWXG + S_IRWXO = C.S_IRWXO ) type Stat_t C.struct_stat diff --git a/src/syscall/ztypes_solaris_amd64.go b/src/syscall/ztypes_solaris_amd64.go index 12307abfaa6bf..b892cd6612ff0 100644 --- a/src/syscall/ztypes_solaris_amd64.go +++ b/src/syscall/ztypes_solaris_amd64.go @@ -77,6 +77,8 @@ const ( S_IRUSR = 0x100 S_IWUSR = 0x80 S_IXUSR = 0x40 + S_IRWXG = 0x38 + S_IRWXO = 0x7 ) type Stat_t struct { From cd7cb86d8e56d28bfe9bd522baa44c95127028d7 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 8 Aug 2018 17:26:23 -0700 Subject: [PATCH 0093/1663] runtime: don't use linkname to refer to internal/cpu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The runtime package already imports the internal/cpu package, so there is no reason for it to use go:linkname comments to refer to internal/cpu functions and variables. Since internal/cpu is internal, we can just export those names. Removing the obscurity of go:linkname outweighs the minor additional complexity added to the internal/cpu API. Change-Id: Id89951b7f3fc67cd9bce67ac6d01d44a647a10ad Reviewed-on: https://go-review.googlesource.com/128755 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Martin Möhrmann --- src/internal/cpu/cpu.go | 11 ++++--- src/internal/cpu/cpu_arm64.go | 56 ++++++++++++++++----------------- src/internal/cpu/cpu_ppc64x.go | 30 +++++++++--------- src/internal/cpu/export_test.go | 3 +- src/runtime/os_linux_arm64.go | 19 ++++------- src/runtime/os_linux_ppc64x.go | 19 ++++------- src/runtime/proc.go | 12 ++----- 7 files changed, 65 insertions(+), 85 deletions(-) diff --git a/src/internal/cpu/cpu.go b/src/internal/cpu/cpu.go index 701584dd3dadd..f2dfadbff8390 100644 --- a/src/internal/cpu/cpu.go +++ b/src/internal/cpu/cpu.go @@ -6,9 +6,10 @@ // used by the Go standard library. package cpu -// debugOptions is set to true by the runtime if go was compiled with GOEXPERIMENT=debugcpu -// and GOOS is Linux or Darwin. This variable is linknamed in runtime/proc.go. -var debugOptions bool +// DebugOptions is set to true by the runtime if go was compiled with GOEXPERIMENT=debugcpu +// and GOOS is Linux or Darwin. +// This should not be changed after it is initialized. +var DebugOptions bool // CacheLinePad is used to pad structs to avoid false sharing. type CacheLinePad struct{ _ [CacheLineSize]byte } @@ -121,11 +122,11 @@ type s390x struct { _ CacheLinePad } -// initialize examines the processor and sets the relevant variables above. +// Initialize examines the processor and sets the relevant variables above. // This is called by the runtime package early in program initialization, // before normal init functions are run. env is set by runtime on Linux and Darwin // if go was compiled with GOEXPERIMENT=debugcpu. -func initialize(env string) { +func Initialize(env string) { doinit() processOptions(env) } diff --git a/src/internal/cpu/cpu_arm64.go b/src/internal/cpu/cpu_arm64.go index 48607575ba947..77b617e49f18b 100644 --- a/src/internal/cpu/cpu_arm64.go +++ b/src/internal/cpu/cpu_arm64.go @@ -7,10 +7,10 @@ package cpu const CacheLineSize = 64 // arm64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2. -// These are linknamed in runtime/os_linux_arm64.go and are initialized by -// archauxv(). -var hwcap uint -var hwcap2 uint +// These are initialized by archauxv in runtime/os_linux_arm64.go. +// These should not be changed after they are initialized. +var HWCap uint +var HWCap2 uint // HWCAP/HWCAP2 bits. These are exposed by Linux. const ( @@ -71,30 +71,30 @@ func doinit() { } // HWCAP feature bits - ARM64.HasFP = isSet(hwcap, hwcap_FP) - ARM64.HasASIMD = isSet(hwcap, hwcap_ASIMD) - ARM64.HasEVTSTRM = isSet(hwcap, hwcap_EVTSTRM) - ARM64.HasAES = isSet(hwcap, hwcap_AES) - ARM64.HasPMULL = isSet(hwcap, hwcap_PMULL) - ARM64.HasSHA1 = isSet(hwcap, hwcap_SHA1) - ARM64.HasSHA2 = isSet(hwcap, hwcap_SHA2) - ARM64.HasCRC32 = isSet(hwcap, hwcap_CRC32) - ARM64.HasATOMICS = isSet(hwcap, hwcap_ATOMICS) - ARM64.HasFPHP = isSet(hwcap, hwcap_FPHP) - ARM64.HasASIMDHP = isSet(hwcap, hwcap_ASIMDHP) - ARM64.HasCPUID = isSet(hwcap, hwcap_CPUID) - ARM64.HasASIMDRDM = isSet(hwcap, hwcap_ASIMDRDM) - ARM64.HasJSCVT = isSet(hwcap, hwcap_JSCVT) - ARM64.HasFCMA = isSet(hwcap, hwcap_FCMA) - ARM64.HasLRCPC = isSet(hwcap, hwcap_LRCPC) - ARM64.HasDCPOP = isSet(hwcap, hwcap_DCPOP) - ARM64.HasSHA3 = isSet(hwcap, hwcap_SHA3) - ARM64.HasSM3 = isSet(hwcap, hwcap_SM3) - ARM64.HasSM4 = isSet(hwcap, hwcap_SM4) - ARM64.HasASIMDDP = isSet(hwcap, hwcap_ASIMDDP) - ARM64.HasSHA512 = isSet(hwcap, hwcap_SHA512) - ARM64.HasSVE = isSet(hwcap, hwcap_SVE) - ARM64.HasASIMDFHM = isSet(hwcap, hwcap_ASIMDFHM) + ARM64.HasFP = isSet(HWCap, hwcap_FP) + ARM64.HasASIMD = isSet(HWCap, hwcap_ASIMD) + ARM64.HasEVTSTRM = isSet(HWCap, hwcap_EVTSTRM) + ARM64.HasAES = isSet(HWCap, hwcap_AES) + ARM64.HasPMULL = isSet(HWCap, hwcap_PMULL) + ARM64.HasSHA1 = isSet(HWCap, hwcap_SHA1) + ARM64.HasSHA2 = isSet(HWCap, hwcap_SHA2) + ARM64.HasCRC32 = isSet(HWCap, hwcap_CRC32) + ARM64.HasATOMICS = isSet(HWCap, hwcap_ATOMICS) + ARM64.HasFPHP = isSet(HWCap, hwcap_FPHP) + ARM64.HasASIMDHP = isSet(HWCap, hwcap_ASIMDHP) + ARM64.HasCPUID = isSet(HWCap, hwcap_CPUID) + ARM64.HasASIMDRDM = isSet(HWCap, hwcap_ASIMDRDM) + ARM64.HasJSCVT = isSet(HWCap, hwcap_JSCVT) + ARM64.HasFCMA = isSet(HWCap, hwcap_FCMA) + ARM64.HasLRCPC = isSet(HWCap, hwcap_LRCPC) + ARM64.HasDCPOP = isSet(HWCap, hwcap_DCPOP) + ARM64.HasSHA3 = isSet(HWCap, hwcap_SHA3) + ARM64.HasSM3 = isSet(HWCap, hwcap_SM3) + ARM64.HasSM4 = isSet(HWCap, hwcap_SM4) + ARM64.HasASIMDDP = isSet(HWCap, hwcap_ASIMDDP) + ARM64.HasSHA512 = isSet(HWCap, hwcap_SHA512) + ARM64.HasSVE = isSet(HWCap, hwcap_SVE) + ARM64.HasASIMDFHM = isSet(HWCap, hwcap_ASIMDFHM) } func isSet(hwc uint, value uint) bool { diff --git a/src/internal/cpu/cpu_ppc64x.go b/src/internal/cpu/cpu_ppc64x.go index 995cf02081c9a..d3f02efa7ff61 100644 --- a/src/internal/cpu/cpu_ppc64x.go +++ b/src/internal/cpu/cpu_ppc64x.go @@ -9,10 +9,10 @@ package cpu const CacheLineSize = 128 // ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2. -// These are linknamed in runtime/os_linux_ppc64x.go and are initialized by -// archauxv(). -var hwcap uint -var hwcap2 uint +// These are initialized by archauxv in runtime/os_linux_ppc64x.go. +// These should not be changed after they are initialized. +var HWCap uint +var HWCap2 uint // HWCAP/HWCAP2 bits. These are exposed by the kernel. const ( @@ -48,19 +48,19 @@ func doinit() { } // HWCAP feature bits - PPC64.HasVMX = isSet(hwcap, _PPC_FEATURE_HAS_ALTIVEC) - PPC64.HasDFP = isSet(hwcap, _PPC_FEATURE_HAS_DFP) - PPC64.HasVSX = isSet(hwcap, _PPC_FEATURE_HAS_VSX) + PPC64.HasVMX = isSet(HWCap, _PPC_FEATURE_HAS_ALTIVEC) + PPC64.HasDFP = isSet(HWCap, _PPC_FEATURE_HAS_DFP) + PPC64.HasVSX = isSet(HWCap, _PPC_FEATURE_HAS_VSX) // HWCAP2 feature bits - PPC64.IsPOWER8 = isSet(hwcap2, _PPC_FEATURE2_ARCH_2_07) - PPC64.HasHTM = isSet(hwcap2, _PPC_FEATURE2_HAS_HTM) - PPC64.HasISEL = isSet(hwcap2, _PPC_FEATURE2_HAS_ISEL) - PPC64.HasVCRYPTO = isSet(hwcap2, _PPC_FEATURE2_HAS_VEC_CRYPTO) - PPC64.HasHTMNOSC = isSet(hwcap2, _PPC_FEATURE2_HTM_NOSC) - PPC64.IsPOWER9 = isSet(hwcap2, _PPC_FEATURE2_ARCH_3_00) - PPC64.HasDARN = isSet(hwcap2, _PPC_FEATURE2_DARN) - PPC64.HasSCV = isSet(hwcap2, _PPC_FEATURE2_SCV) + PPC64.IsPOWER8 = isSet(HWCap2, _PPC_FEATURE2_ARCH_2_07) + PPC64.HasHTM = isSet(HWCap2, _PPC_FEATURE2_HAS_HTM) + PPC64.HasISEL = isSet(HWCap2, _PPC_FEATURE2_HAS_ISEL) + PPC64.HasVCRYPTO = isSet(HWCap2, _PPC_FEATURE2_HAS_VEC_CRYPTO) + PPC64.HasHTMNOSC = isSet(HWCap2, _PPC_FEATURE2_HTM_NOSC) + PPC64.IsPOWER9 = isSet(HWCap2, _PPC_FEATURE2_ARCH_3_00) + PPC64.HasDARN = isSet(HWCap2, _PPC_FEATURE2_DARN) + PPC64.HasSCV = isSet(HWCap2, _PPC_FEATURE2_SCV) } func isSet(hwc uint, value uint) bool { diff --git a/src/internal/cpu/export_test.go b/src/internal/cpu/export_test.go index 4e53c5a0841f3..91bfc1bbc3b35 100644 --- a/src/internal/cpu/export_test.go +++ b/src/internal/cpu/export_test.go @@ -5,6 +5,5 @@ package cpu var ( - Options = options - DebugOptions = debugOptions + Options = options ) diff --git a/src/runtime/os_linux_arm64.go b/src/runtime/os_linux_arm64.go index 28a0319f10736..cbe528b4aff75 100644 --- a/src/runtime/os_linux_arm64.go +++ b/src/runtime/os_linux_arm64.go @@ -6,20 +6,10 @@ package runtime -// For go:linkname -import _ "unsafe" +import "internal/cpu" var randomNumber uint32 -// arm64 doesn't have a 'cpuid' instruction equivalent and relies on -// HWCAP/HWCAP2 bits for hardware capabilities. - -//go:linkname cpu_hwcap internal/cpu.hwcap -var cpu_hwcap uint - -//go:linkname cpu_hwcap2 internal/cpu.hwcap2 -var cpu_hwcap2 uint - func archauxv(tag, val uintptr) { switch tag { case _AT_RANDOM: @@ -28,10 +18,13 @@ func archauxv(tag, val uintptr) { // it as a byte array. randomNumber = uint32(startupRandomData[4]) | uint32(startupRandomData[5])<<8 | uint32(startupRandomData[6])<<16 | uint32(startupRandomData[7])<<24 + case _AT_HWCAP: - cpu_hwcap = uint(val) + // arm64 doesn't have a 'cpuid' instruction equivalent and relies on + // HWCAP/HWCAP2 bits for hardware capabilities. + cpu.HWCap = uint(val) case _AT_HWCAP2: - cpu_hwcap2 = uint(val) + cpu.HWCap2 = uint(val) } } diff --git a/src/runtime/os_linux_ppc64x.go b/src/runtime/os_linux_ppc64x.go index 2c67864a96df8..cc79cc4a66c31 100644 --- a/src/runtime/os_linux_ppc64x.go +++ b/src/runtime/os_linux_ppc64x.go @@ -7,23 +7,16 @@ package runtime -// For go:linkname -import _ "unsafe" - -// ppc64x doesn't have a 'cpuid' instruction equivalent and relies on -// HWCAP/HWCAP2 bits for hardware capabilities. - -//go:linkname cpu_hwcap internal/cpu.hwcap -var cpu_hwcap uint - -//go:linkname cpu_hwcap2 internal/cpu.hwcap2 -var cpu_hwcap2 uint +import "internal/cpu" func archauxv(tag, val uintptr) { switch tag { case _AT_HWCAP: - cpu_hwcap = uint(val) + // ppc64x doesn't have a 'cpuid' instruction + // equivalent and relies on HWCAP/HWCAP2 bits for + // hardware capabilities. + cpu.HWCap = uint(val) case _AT_HWCAP2: - cpu_hwcap2 = uint(val) + cpu.HWCap2 = uint(val) } } diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 7875b38e2e2cf..31b188efd9ee9 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -477,20 +477,14 @@ const ( _GoidCacheBatch = 16 ) -//go:linkname internal_cpu_initialize internal/cpu.initialize -func internal_cpu_initialize(env string) - -//go:linkname internal_cpu_debugOptions internal/cpu.debugOptions -var internal_cpu_debugOptions bool - // cpuinit extracts the environment variable GODEBUGCPU from the environment on -// Linux and Darwin if the GOEXPERIMENT debugcpu was set and calls internal/cpu.initialize. +// Linux and Darwin if the GOEXPERIMENT debugcpu was set and calls internal/cpu.Initialize. func cpuinit() { const prefix = "GODEBUGCPU=" var env string if haveexperiment("debugcpu") && (GOOS == "linux" || GOOS == "darwin") { - internal_cpu_debugOptions = true + cpu.DebugOptions = true // Similar to goenv_unix but extracts the environment value for // GODEBUGCPU directly. @@ -511,7 +505,7 @@ func cpuinit() { } } - internal_cpu_initialize(env) + cpu.Initialize(env) support_erms = cpu.X86.HasERMS support_popcnt = cpu.X86.HasPOPCNT From 0829e1b757969cc5e22df6c5b5a45cff8f073a38 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 24 Feb 2017 15:46:40 -0800 Subject: [PATCH 0094/1663] misc/cgo/testcarchive: make the tests work when using gccgo Change-Id: I62a7a8ebbbc1f1a266234b53680768da157b2df5 Reviewed-on: https://go-review.googlesource.com/130416 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- misc/cgo/testcarchive/carchive_test.go | 71 ++++++++++++++++++++++---- misc/cgo/testcarchive/main_unix.c | 8 ++- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/misc/cgo/testcarchive/carchive_test.go b/misc/cgo/testcarchive/carchive_test.go index 71232305f60b8..457ac0db091af 100644 --- a/misc/cgo/testcarchive/carchive_test.go +++ b/misc/cgo/testcarchive/carchive_test.go @@ -14,6 +14,7 @@ import ( "os/exec" "path/filepath" "regexp" + "runtime" "strings" "syscall" "testing" @@ -83,13 +84,17 @@ func init() { cc = append(cc, []string{"-framework", "CoreFoundation", "-framework", "Foundation"}...) } libgodir = GOOS + "_" + GOARCH - switch GOOS { - case "darwin": - if GOARCH == "arm" || GOARCH == "arm64" { + if runtime.Compiler == "gccgo" { + libgodir = "gccgo_" + libgodir + "_fPIC" + } else { + switch GOOS { + case "darwin": + if GOARCH == "arm" || GOARCH == "arm64" { + libgodir += "_shared" + } + case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris": libgodir += "_shared" } - case "dragonfly", "freebsd", "linux", "netbsd", "openbsd", "solaris": - libgodir += "_shared" } cc = append(cc, "-I", filepath.Join("pkg", libgodir)) @@ -155,6 +160,9 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) { } else { ccArgs = append(ccArgs, "main_unix.c", libgoa) } + if runtime.Compiler == "gccgo" { + ccArgs = append(ccArgs, "-lgo") + } t.Log(ccArgs) if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil { t.Logf("%s", out) @@ -163,7 +171,11 @@ func testInstall(t *testing.T, exe, libgoa, libgoh string, buildcmd ...string) { defer os.Remove(exe) binArgs := append(cmdToRun(exe), "arg1", "arg2") - if out, err := exec.Command(binArgs[0], binArgs[1:]...).CombinedOutput(); err != nil { + cmd = exec.Command(binArgs[0], binArgs[1:]...) + if runtime.Compiler == "gccgo" { + cmd.Env = append(os.Environ(), "GCCGO=1") + } + if out, err := cmd.CombinedOutput(); err != nil { t.Logf("%s", out) t.Fatal(err) } @@ -194,8 +206,13 @@ func checkLineComments(t *testing.T, hdrname string) { func TestInstall(t *testing.T) { defer os.RemoveAll("pkg") + libgoa := "libgo.a" + if runtime.Compiler == "gccgo" { + libgoa = "liblibgo.a" + } + testInstall(t, "./testp1"+exeSuffix, - filepath.Join("pkg", libgodir, "libgo.a"), + filepath.Join("pkg", libgodir, libgoa), filepath.Join("pkg", libgodir, "libgo.h"), "go", "install", "-i", "-buildmode=c-archive", "libgo") @@ -235,6 +252,9 @@ func TestEarlySignalHandler(t *testing.T) { checkLineComments(t, "libgo2.h") ccArgs := append(cc, "-o", "testp"+exeSuffix, "main2.c", "libgo2.a") + if runtime.Compiler == "gccgo" { + ccArgs = append(ccArgs, "-lgo") + } if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil { t.Logf("%s", out) t.Fatal(err) @@ -265,6 +285,9 @@ func TestSignalForwarding(t *testing.T) { checkLineComments(t, "libgo2.h") ccArgs := append(cc, "-o", "testp"+exeSuffix, "main5.c", "libgo2.a") + if runtime.Compiler == "gccgo" { + ccArgs = append(ccArgs, "-lgo") + } if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil { t.Logf("%s", out) t.Fatal(err) @@ -306,6 +329,9 @@ func TestSignalForwardingExternal(t *testing.T) { checkLineComments(t, "libgo2.h") ccArgs := append(cc, "-o", "testp"+exeSuffix, "main5.c", "libgo2.a") + if runtime.Compiler == "gccgo" { + ccArgs = append(ccArgs, "-lgo") + } if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil { t.Logf("%s", out) t.Fatal(err) @@ -419,6 +445,9 @@ func TestOsSignal(t *testing.T) { checkLineComments(t, "libgo3.h") ccArgs := append(cc, "-o", "testp"+exeSuffix, "main3.c", "libgo3.a") + if runtime.Compiler == "gccgo" { + ccArgs = append(ccArgs, "-lgo") + } if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil { t.Logf("%s", out) t.Fatal(err) @@ -452,6 +481,9 @@ func TestSigaltstack(t *testing.T) { checkLineComments(t, "libgo4.h") ccArgs := append(cc, "-o", "testp"+exeSuffix, "main4.c", "libgo4.a") + if runtime.Compiler == "gccgo" { + ccArgs = append(ccArgs, "-lgo") + } if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil { t.Logf("%s", out) t.Fatal(err) @@ -476,6 +508,9 @@ func TestExtar(t *testing.T) { case "windows": t.Skip("skipping signal test on Windows") } + if runtime.Compiler == "gccgo" { + t.Skip("skipping -extar test when using gccgo") + } defer func() { os.Remove("libgo4.a") @@ -530,14 +565,26 @@ func TestPIE(t *testing.T) { t.Fatal(err) } - ccArgs := append(cc, "-fPIE", "-pie", "-o", "testp"+exeSuffix, "main.c", "main_unix.c", filepath.Join("pkg", libgodir, "libgo.a")) + libgoa := "libgo.a" + if runtime.Compiler == "gccgo" { + libgoa = "liblibgo.a" + } + + ccArgs := append(cc, "-fPIE", "-pie", "-o", "testp"+exeSuffix, "main.c", "main_unix.c", filepath.Join("pkg", libgodir, libgoa)) + if runtime.Compiler == "gccgo" { + ccArgs = append(ccArgs, "-lgo") + } if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil { t.Logf("%s", out) t.Fatal(err) } binArgs := append(bin, "arg1", "arg2") - if out, err := exec.Command(binArgs[0], binArgs[1:]...).CombinedOutput(); err != nil { + cmd = exec.Command(binArgs[0], binArgs[1:]...) + if runtime.Compiler == "gccgo" { + cmd.Env = append(os.Environ(), "GCCGO=1") + } + if out, err := cmd.CombinedOutput(); err != nil { t.Logf("%s", out) t.Fatal(err) } @@ -605,6 +652,9 @@ func TestSIGPROF(t *testing.T) { checkLineComments(t, "libgo6.h") ccArgs := append(cc, "-o", "testp6"+exeSuffix, "main6.c", "libgo6.a") + if runtime.Compiler == "gccgo" { + ccArgs = append(ccArgs, "-lgo") + } if out, err := exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput(); err != nil { t.Logf("%s", out) t.Fatal(err) @@ -648,6 +698,9 @@ func TestCompileWithoutShared(t *testing.T) { // In some cases, -no-pie is needed here, but not accepted everywhere. First try // if -no-pie is accepted. See #22126. ccArgs := append(cc, "-o", exe, "-no-pie", "main5.c", "libgo2.a") + if runtime.Compiler == "gccgo" { + ccArgs = append(ccArgs, "-lgo") + } t.Log(ccArgs) out, err = exec.Command(ccArgs[0], ccArgs[1:]...).CombinedOutput() diff --git a/misc/cgo/testcarchive/main_unix.c b/misc/cgo/testcarchive/main_unix.c index 4d9d16f03b034..b23ac1c2428ba 100644 --- a/misc/cgo/testcarchive/main_unix.c +++ b/misc/cgo/testcarchive/main_unix.c @@ -5,6 +5,7 @@ #include #include #include +#include #include struct sigaction sa; @@ -30,7 +31,12 @@ int install_handler() { perror("sigaction"); return 2; } - if (osa.sa_handler == SIG_DFL || (osa.sa_flags&SA_ONSTACK) == 0) { + if (osa.sa_handler == SIG_DFL) { + fprintf(stderr, "Go runtime did not install signal handler\n"); + return 2; + } + // gccgo does not set SA_ONSTACK for SIGSEGV. + if (getenv("GCCGO") == "" && (osa.sa_flags&SA_ONSTACK) == 0) { fprintf(stderr, "Go runtime did not install signal handler\n"); return 2; } From 3649fe299d452b11a8a458096deda38ed9df5947 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Tue, 21 Aug 2018 14:02:56 +0200 Subject: [PATCH 0095/1663] cmd/gofmt: skip gofmt idempotency check on known issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gofmt's TestAll runs gofmt on all the go files in the tree and checks, among other things, that gofmt is idempotent (i.e. that a second invocation does not change the input again). There's a known bug of gofmt not being idempotent (Issue #24472), and unfortunately the fixedbugs/issue22662.go file triggers it. We can't just gofmt the file, because it tests the effect of various line directives inside weirdly-placed comments, and gofmt moves those comments, making the test useless. Instead, just skip the idempotency check when gofmt-ing the problematic file. This fixes go test on the cmd/gofmt package, and a failure seen on the longtest builder. Updates #24472 Change-Id: Ib06300977cd8fce6c609e688b222e9b2186f5aa7 Reviewed-on: https://go-review.googlesource.com/130377 Reviewed-by: Daniel Martí Reviewed-by: Robert Griesemer Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot --- src/cmd/gofmt/long_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/cmd/gofmt/long_test.go b/src/cmd/gofmt/long_test.go index 237b86021bf35..e2a6208f871ea 100644 --- a/src/cmd/gofmt/long_test.go +++ b/src/cmd/gofmt/long_test.go @@ -85,6 +85,12 @@ func testFile(t *testing.T, b1, b2 *bytes.Buffer, filename string) { // the first and 2nd result should be identical if !bytes.Equal(b1.Bytes(), b2.Bytes()) { + // A known instance of gofmt not being idempotent + // (see Issue #24472) + if strings.HasSuffix(filename, "issue22662.go") { + t.Log("known gofmt idempotency bug (Issue #24472)") + return + } t.Errorf("gofmt %s not idempotent", filename) } } From 4a842f25590fca15a8c564ec6a8edfd9f71bc446 Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Thu, 31 May 2018 13:06:27 +0100 Subject: [PATCH 0096/1663] crypto/{aes,cipher,rand}: use binary.{Big,Little}Endian methods Use the binary.{Big,Little}Endian integer encoding methods rather than unsafe or local implementations. These methods are tested to ensure they inline correctly and don't add unnecessary bounds checks, so it seems better to use them wherever possible. This introduces a dependency on encoding/binary to crypto/cipher. I think this is OK because other "L3" packages already import encoding/binary. Change-Id: I5cf01800d08554ca364e46cfc1d9445cf3c711a0 Reviewed-on: https://go-review.googlesource.com/115555 Run-TryBot: Michael Munday TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/crypto/aes/block.go | 48 ++++++++++++++++++-------------- src/crypto/aes/ctr_s390x.go | 14 +++++----- src/crypto/aes/gcm_s390x.go | 31 ++++----------------- src/crypto/cipher/gcm.go | 54 +++++++++--------------------------- src/crypto/rand/rand_unix.go | 10 ++----- src/go/build/deps_test.go | 2 +- 6 files changed, 56 insertions(+), 103 deletions(-) diff --git a/src/crypto/aes/block.go b/src/crypto/aes/block.go index 8647019d5809a..40bd0d335d3b2 100644 --- a/src/crypto/aes/block.go +++ b/src/crypto/aes/block.go @@ -36,14 +36,17 @@ package aes +import ( + "encoding/binary" +) + // Encrypt one block from src into dst, using the expanded key xk. func encryptBlockGo(xk []uint32, dst, src []byte) { - var s0, s1, s2, s3, t0, t1, t2, t3 uint32 - - s0 = uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3]) - s1 = uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7]) - s2 = uint32(src[8])<<24 | uint32(src[9])<<16 | uint32(src[10])<<8 | uint32(src[11]) - s3 = uint32(src[12])<<24 | uint32(src[13])<<16 | uint32(src[14])<<8 | uint32(src[15]) + _ = src[15] // early bounds check + s0 := binary.BigEndian.Uint32(src[0:4]) + s1 := binary.BigEndian.Uint32(src[4:8]) + s2 := binary.BigEndian.Uint32(src[8:12]) + s3 := binary.BigEndian.Uint32(src[12:16]) // First round just XORs input with key. s0 ^= xk[0] @@ -55,6 +58,7 @@ func encryptBlockGo(xk []uint32, dst, src []byte) { // Number of rounds is set by length of expanded key. nr := len(xk)/4 - 2 // - 2: one above, one more below k := 4 + var t0, t1, t2, t3 uint32 for r := 0; r < nr; r++ { t0 = xk[k+0] ^ te0[uint8(s0>>24)] ^ te1[uint8(s1>>16)] ^ te2[uint8(s2>>8)] ^ te3[uint8(s3)] t1 = xk[k+1] ^ te0[uint8(s1>>24)] ^ te1[uint8(s2>>16)] ^ te2[uint8(s3>>8)] ^ te3[uint8(s0)] @@ -75,20 +79,20 @@ func encryptBlockGo(xk []uint32, dst, src []byte) { s2 ^= xk[k+2] s3 ^= xk[k+3] - dst[0], dst[1], dst[2], dst[3] = byte(s0>>24), byte(s0>>16), byte(s0>>8), byte(s0) - dst[4], dst[5], dst[6], dst[7] = byte(s1>>24), byte(s1>>16), byte(s1>>8), byte(s1) - dst[8], dst[9], dst[10], dst[11] = byte(s2>>24), byte(s2>>16), byte(s2>>8), byte(s2) - dst[12], dst[13], dst[14], dst[15] = byte(s3>>24), byte(s3>>16), byte(s3>>8), byte(s3) + _ = dst[15] // early bounds check + binary.BigEndian.PutUint32(dst[0:4], s0) + binary.BigEndian.PutUint32(dst[4:8], s1) + binary.BigEndian.PutUint32(dst[8:12], s2) + binary.BigEndian.PutUint32(dst[12:16], s3) } // Decrypt one block from src into dst, using the expanded key xk. func decryptBlockGo(xk []uint32, dst, src []byte) { - var s0, s1, s2, s3, t0, t1, t2, t3 uint32 - - s0 = uint32(src[0])<<24 | uint32(src[1])<<16 | uint32(src[2])<<8 | uint32(src[3]) - s1 = uint32(src[4])<<24 | uint32(src[5])<<16 | uint32(src[6])<<8 | uint32(src[7]) - s2 = uint32(src[8])<<24 | uint32(src[9])<<16 | uint32(src[10])<<8 | uint32(src[11]) - s3 = uint32(src[12])<<24 | uint32(src[13])<<16 | uint32(src[14])<<8 | uint32(src[15]) + _ = src[15] // early bounds check + s0 := binary.BigEndian.Uint32(src[0:4]) + s1 := binary.BigEndian.Uint32(src[4:8]) + s2 := binary.BigEndian.Uint32(src[8:12]) + s3 := binary.BigEndian.Uint32(src[12:16]) // First round just XORs input with key. s0 ^= xk[0] @@ -100,6 +104,7 @@ func decryptBlockGo(xk []uint32, dst, src []byte) { // Number of rounds is set by length of expanded key. nr := len(xk)/4 - 2 // - 2: one above, one more below k := 4 + var t0, t1, t2, t3 uint32 for r := 0; r < nr; r++ { t0 = xk[k+0] ^ td0[uint8(s0>>24)] ^ td1[uint8(s3>>16)] ^ td2[uint8(s2>>8)] ^ td3[uint8(s1)] t1 = xk[k+1] ^ td0[uint8(s1>>24)] ^ td1[uint8(s0>>16)] ^ td2[uint8(s3>>8)] ^ td3[uint8(s2)] @@ -120,10 +125,11 @@ func decryptBlockGo(xk []uint32, dst, src []byte) { s2 ^= xk[k+2] s3 ^= xk[k+3] - dst[0], dst[1], dst[2], dst[3] = byte(s0>>24), byte(s0>>16), byte(s0>>8), byte(s0) - dst[4], dst[5], dst[6], dst[7] = byte(s1>>24), byte(s1>>16), byte(s1>>8), byte(s1) - dst[8], dst[9], dst[10], dst[11] = byte(s2>>24), byte(s2>>16), byte(s2>>8), byte(s2) - dst[12], dst[13], dst[14], dst[15] = byte(s3>>24), byte(s3>>16), byte(s3>>8), byte(s3) + _ = dst[15] // early bounds check + binary.BigEndian.PutUint32(dst[0:4], s0) + binary.BigEndian.PutUint32(dst[4:8], s1) + binary.BigEndian.PutUint32(dst[8:12], s2) + binary.BigEndian.PutUint32(dst[12:16], s3) } // Apply sbox0 to each byte in w. @@ -144,7 +150,7 @@ func expandKeyGo(key []byte, enc, dec []uint32) { var i int nk := len(key) / 4 for i = 0; i < nk; i++ { - enc[i] = uint32(key[4*i])<<24 | uint32(key[4*i+1])<<16 | uint32(key[4*i+2])<<8 | uint32(key[4*i+3]) + enc[i] = binary.BigEndian.Uint32(key[4*i:]) } for ; i < len(enc); i++ { t := enc[i-1] diff --git a/src/crypto/aes/ctr_s390x.go b/src/crypto/aes/ctr_s390x.go index 8fa85a3ae8fe7..bfa8cbba7f3c2 100644 --- a/src/crypto/aes/ctr_s390x.go +++ b/src/crypto/aes/ctr_s390x.go @@ -7,7 +7,7 @@ package aes import ( "crypto/cipher" "crypto/internal/subtle" - "unsafe" + "encoding/binary" ) // Assert that aesCipherAsm implements the ctrAble interface. @@ -38,8 +38,8 @@ func (c *aesCipherAsm) NewCTR(iv []byte) cipher.Stream { } var ac aesctr ac.block = c - ac.ctr[0] = *(*uint64)(unsafe.Pointer((&iv[0]))) // high bits - ac.ctr[1] = *(*uint64)(unsafe.Pointer((&iv[8]))) // low bits + ac.ctr[0] = binary.BigEndian.Uint64(iv[0:]) // high bits + ac.ctr[1] = binary.BigEndian.Uint64(iv[8:]) // low bits ac.buffer = ac.storage[:0] return &ac } @@ -48,10 +48,10 @@ func (c *aesctr) refill() { // Fill up the buffer with an incrementing count. c.buffer = c.storage[:streamBufferSize] c0, c1 := c.ctr[0], c.ctr[1] - for i := 0; i < streamBufferSize; i += BlockSize { - b0 := (*uint64)(unsafe.Pointer(&c.buffer[i])) - b1 := (*uint64)(unsafe.Pointer(&c.buffer[i+BlockSize/2])) - *b0, *b1 = c0, c1 + for i := 0; i < streamBufferSize; i += 16 { + binary.BigEndian.PutUint64(c.buffer[i+0:], c0) + binary.BigEndian.PutUint64(c.buffer[i+8:], c1) + // Increment in big endian: c0 is high, c1 is low. c1++ if c1 == 0 { diff --git a/src/crypto/aes/gcm_s390x.go b/src/crypto/aes/gcm_s390x.go index d154ddbaa0834..c58aa2cda8fd1 100644 --- a/src/crypto/aes/gcm_s390x.go +++ b/src/crypto/aes/gcm_s390x.go @@ -8,6 +8,7 @@ import ( "crypto/cipher" subtleoverlap "crypto/internal/subtle" "crypto/subtle" + "encoding/binary" "errors" "internal/cpu" ) @@ -22,35 +23,15 @@ type gcmCount [16]byte // inc increments the rightmost 32-bits of the count value by 1. func (x *gcmCount) inc() { - // The compiler should optimize this to a 32-bit addition. - n := uint32(x[15]) | uint32(x[14])<<8 | uint32(x[13])<<16 | uint32(x[12])<<24 - n += 1 - x[12] = byte(n >> 24) - x[13] = byte(n >> 16) - x[14] = byte(n >> 8) - x[15] = byte(n) + binary.BigEndian.PutUint32(x[len(x)-4:], binary.BigEndian.Uint32(x[len(x)-4:])+1) } // gcmLengths writes len0 || len1 as big-endian values to a 16-byte array. func gcmLengths(len0, len1 uint64) [16]byte { - return [16]byte{ - byte(len0 >> 56), - byte(len0 >> 48), - byte(len0 >> 40), - byte(len0 >> 32), - byte(len0 >> 24), - byte(len0 >> 16), - byte(len0 >> 8), - byte(len0), - byte(len1 >> 56), - byte(len1 >> 48), - byte(len1 >> 40), - byte(len1 >> 32), - byte(len1 >> 24), - byte(len1 >> 16), - byte(len1 >> 8), - byte(len1), - } + v := [16]byte{} + binary.BigEndian.PutUint64(v[0:], len0) + binary.BigEndian.PutUint64(v[8:], len1) + return v } // gcmHashKey represents the 16-byte hash key required by the GHASH algorithm. diff --git a/src/crypto/cipher/gcm.go b/src/crypto/cipher/gcm.go index 6321e9e82d3d6..73d78550f897b 100644 --- a/src/crypto/cipher/gcm.go +++ b/src/crypto/cipher/gcm.go @@ -7,6 +7,7 @@ package cipher import ( subtleoverlap "crypto/internal/subtle" "crypto/subtle" + "encoding/binary" "errors" ) @@ -53,8 +54,8 @@ type gcmAble interface { } // gcmFieldElement represents a value in GF(2¹²⁸). In order to reflect the GCM -// standard and make getUint64 suitable for marshaling these values, the bits -// are stored backwards. For example: +// standard and make binary.BigEndian suitable for marshaling these values, the +// bits are stored in big endian order. For example: // the coefficient of x⁰ can be obtained by v.low >> 63. // the coefficient of x⁶³ can be obtained by v.low & 1. // the coefficient of x⁶⁴ can be obtained by v.high >> 63. @@ -130,8 +131,8 @@ func newGCMWithNonceAndTagSize(cipher Block, nonceSize, tagSize int) (AEAD, erro // would expect, say, 4*key to be in index 4 of the table but due to // this bit ordering it will actually be in index 0010 (base 2) = 2. x := gcmFieldElement{ - getUint64(key[:8]), - getUint64(key[8:]), + binary.BigEndian.Uint64(key[:8]), + binary.BigEndian.Uint64(key[8:]), } g.productTable[reverseBits(1)] = x @@ -316,8 +317,8 @@ func (g *gcm) mul(y *gcmFieldElement) { // Horner's rule. There must be a multiple of gcmBlockSize bytes in blocks. func (g *gcm) updateBlocks(y *gcmFieldElement, blocks []byte) { for len(blocks) > 0 { - y.low ^= getUint64(blocks) - y.high ^= getUint64(blocks[8:]) + y.low ^= binary.BigEndian.Uint64(blocks) + y.high ^= binary.BigEndian.Uint64(blocks[8:]) g.mul(y) blocks = blocks[gcmBlockSize:] } @@ -339,12 +340,8 @@ func (g *gcm) update(y *gcmFieldElement, data []byte) { // gcmInc32 treats the final four bytes of counterBlock as a big-endian value // and increments it. func gcmInc32(counterBlock *[16]byte) { - for i := gcmBlockSize - 1; i >= gcmBlockSize-4; i-- { - counterBlock[i]++ - if counterBlock[i] != 0 { - break - } - } + ctr := counterBlock[len(counterBlock)-4:] + binary.BigEndian.PutUint32(ctr, binary.BigEndian.Uint32(ctr)+1) } // sliceForAppend takes a slice and a requested number of bytes. It returns a @@ -400,8 +397,8 @@ func (g *gcm) deriveCounter(counter *[gcmBlockSize]byte, nonce []byte) { g.update(&y, nonce) y.high ^= uint64(len(nonce)) * 8 g.mul(&y) - putUint64(counter[:8], y.low) - putUint64(counter[8:], y.high) + binary.BigEndian.PutUint64(counter[:8], y.low) + binary.BigEndian.PutUint64(counter[8:], y.high) } } @@ -417,33 +414,8 @@ func (g *gcm) auth(out, ciphertext, additionalData []byte, tagMask *[gcmTagSize] g.mul(&y) - putUint64(out, y.low) - putUint64(out[8:], y.high) + binary.BigEndian.PutUint64(out, y.low) + binary.BigEndian.PutUint64(out[8:], y.high) xorWords(out, out, tagMask[:]) } - -func getUint64(data []byte) uint64 { - _ = data[7] // bounds check hint to compiler; see golang.org/issue/14808 - r := uint64(data[0])<<56 | - uint64(data[1])<<48 | - uint64(data[2])<<40 | - uint64(data[3])<<32 | - uint64(data[4])<<24 | - uint64(data[5])<<16 | - uint64(data[6])<<8 | - uint64(data[7]) - return r -} - -func putUint64(out []byte, v uint64) { - _ = out[7] // bounds check hint to compiler; see golang.org/issue/14808 - out[0] = byte(v >> 56) - out[1] = byte(v >> 48) - out[2] = byte(v >> 40) - out[3] = byte(v >> 32) - out[4] = byte(v >> 24) - out[5] = byte(v >> 16) - out[6] = byte(v >> 8) - out[7] = byte(v) -} diff --git a/src/crypto/rand/rand_unix.go b/src/crypto/rand/rand_unix.go index 631972b92ac5e..cebb7a761cd0d 100644 --- a/src/crypto/rand/rand_unix.go +++ b/src/crypto/rand/rand_unix.go @@ -13,6 +13,7 @@ import ( "bufio" "crypto/aes" "crypto/cipher" + "encoding/binary" "io" "os" "runtime" @@ -137,14 +138,7 @@ func (r *reader) Read(b []byte) (n int, err error) { // dst = encrypt(t^seed) // seed = encrypt(t^dst) ns := time.Now().UnixNano() - r.time[0] = byte(ns >> 56) - r.time[1] = byte(ns >> 48) - r.time[2] = byte(ns >> 40) - r.time[3] = byte(ns >> 32) - r.time[4] = byte(ns >> 24) - r.time[5] = byte(ns >> 16) - r.time[6] = byte(ns >> 8) - r.time[7] = byte(ns) + binary.BigEndian.PutUint64(r.time[:], uint64(ns)) r.cipher.Encrypt(r.time[0:], r.time[0:]) for i := 0; i < aes.BlockSize; i++ { r.dst[i] = r.time[i] ^ r.seed[i] diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index ef1f6604a8737..729d0db51f24b 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -100,7 +100,7 @@ var pkgDeps = map[string][]string{ // and interface definitions, but nothing that makes // system calls. "crypto": {"L2", "hash"}, // interfaces - "crypto/cipher": {"L2", "crypto/subtle", "crypto/internal/subtle"}, + "crypto/cipher": {"L2", "crypto/subtle", "crypto/internal/subtle", "encoding/binary"}, "crypto/internal/subtle": {"unsafe", "reflect"}, // reflect behind a appengine tag "crypto/subtle": {}, "encoding/base32": {"L2"}, From 9a2a34e1c1be53fce0782a0b5e14e6f7ceaad62a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 8 Jul 2018 13:17:56 +0100 Subject: [PATCH 0097/1663] encoding/json: defer error context work until necessary MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Calling Name on a reflect.Type is somewhat expensive, as it involves a number of nested calls and string handling. This cost was showing up when decoding structs, as we were calling it to set up an error context. We can avoid the extra work unless we do encounter an error, which makes decoding via struct types faster. name old time/op new time/op delta CodeDecoder-4 31.0ms ± 1% 29.9ms ± 1% -3.69% (p=0.002 n=6+6) name old speed new speed delta CodeDecoder-4 62.6MB/s ± 1% 65.0MB/s ± 1% +3.83% (p=0.002 n=6+6) Updates #5683. Change-Id: I48a3a85ef0ba96f524b7c3e9096cb2c4589e077a Reviewed-on: https://go-review.googlesource.com/122467 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/encoding/json/decode.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go index 97fee54f4ebfd..16da48617e9ae 100644 --- a/src/encoding/json/decode.go +++ b/src/encoding/json/decode.go @@ -267,7 +267,7 @@ type decodeState struct { opcode int // last read result scan scanner errorContext struct { // provides context for type errors - Struct string + Struct reflect.Type Field string } savedError error @@ -289,7 +289,7 @@ func (d *decodeState) init(data []byte) *decodeState { d.data = data d.off = 0 d.savedError = nil - d.errorContext.Struct = "" + d.errorContext.Struct = nil d.errorContext.Field = "" return d } @@ -304,10 +304,10 @@ func (d *decodeState) saveError(err error) { // addErrorContext returns a new error enhanced with information from d.errorContext func (d *decodeState) addErrorContext(err error) error { - if d.errorContext.Struct != "" || d.errorContext.Field != "" { + if d.errorContext.Struct != nil || d.errorContext.Field != "" { switch err := err.(type) { case *UnmarshalTypeError: - err.Struct = d.errorContext.Struct + err.Struct = d.errorContext.Struct.Name() err.Field = d.errorContext.Field return err } @@ -744,7 +744,7 @@ func (d *decodeState) object(v reflect.Value) error { subv = subv.Field(i) } d.errorContext.Field = f.name - d.errorContext.Struct = v.Type().Name() + d.errorContext.Struct = v.Type() } else if d.disallowUnknownFields { d.saveError(fmt.Errorf("json: unknown field %q", key)) } @@ -832,7 +832,7 @@ func (d *decodeState) object(v reflect.Value) error { return errPhase } - d.errorContext.Struct = "" + d.errorContext.Struct = nil d.errorContext.Field = "" } return nil From 6d4787aff205c242895bb072a18f9066a00d00b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 8 Jul 2018 16:14:35 +0100 Subject: [PATCH 0098/1663] encoding/json: various minor decoder speed-ups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reuse v.Type() and cachedTypeFields(t) when decoding maps and structs. Always use the same data slices when in hot loops, to ensure that the compiler generates good code. "for i < len(data) { use(d.data[i]) }" makes it harder for the compiler. Finally, do other minor clean-ups, such as deduplicating switch cases, and using a switch instead of three chained ifs. The decoder sees a noticeable speed-up, in particular when decoding structs. name old time/op new time/op delta CodeDecoder-4 29.8ms ± 1% 27.5ms ± 0% -7.83% (p=0.002 n=6+6) name old speed new speed delta CodeDecoder-4 65.0MB/s ± 1% 70.6MB/s ± 0% +8.49% (p=0.002 n=6+6) Updates #5683. Change-Id: I9d751e22502221962da696e48996ffdeb777277d Reviewed-on: https://go-review.googlesource.com/122468 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/encoding/json/decode.go | 39 +++++++++++++++++-------------------- src/encoding/json/stream.go | 22 ++++++++++----------- 2 files changed, 29 insertions(+), 32 deletions(-) diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go index 16da48617e9ae..2e734fb39e033 100644 --- a/src/encoding/json/decode.go +++ b/src/encoding/json/decode.go @@ -332,13 +332,12 @@ func (d *decodeState) skip() { // scanNext processes the byte at d.data[d.off]. func (d *decodeState) scanNext() { - s, data, i := &d.scan, d.data, d.off - if i < len(data) { - d.opcode = s.step(s, data[i]) - d.off = i + 1 + if d.off < len(d.data) { + d.opcode = d.scan.step(&d.scan, d.data[d.off]) + d.off++ } else { - d.opcode = s.eof() - d.off = len(data) + 1 // mark processed EOF with len+1 + d.opcode = d.scan.eof() + d.off = len(d.data) + 1 // mark processed EOF with len+1 } } @@ -346,7 +345,7 @@ func (d *decodeState) scanNext() { // receives a scan code not equal to op. func (d *decodeState) scanWhile(op int) { s, data, i := &d.scan, d.data, d.off - for i < len(d.data) { + for i < len(data) { newOp := s.step(s, data[i]) i++ if newOp != op { @@ -356,7 +355,7 @@ func (d *decodeState) scanWhile(op int) { } } - d.off = len(d.data) + 1 // mark processed EOF with len+1 + d.off = len(data) + 1 // mark processed EOF with len+1 d.opcode = d.scan.eof() } @@ -413,11 +412,7 @@ func (d *decodeState) valueQuoted() (interface{}, error) { default: return nil, errPhase - case scanBeginArray: - d.skip() - d.scanNext() - - case scanBeginObject: + case scanBeginArray, scanBeginObject: d.skip() d.scanNext() @@ -629,6 +624,7 @@ func (d *decodeState) object(v reflect.Value) error { return nil } v = pv + t := v.Type() // Decoding into nil interface? Switch to non-reflect code. if v.Kind() == reflect.Interface && v.NumMethod() == 0 { @@ -640,6 +636,8 @@ func (d *decodeState) object(v reflect.Value) error { return nil } + var fields []field + // Check type of target: // struct or // map[T1]T2 where T1 is string, an integer type, @@ -648,14 +646,13 @@ func (d *decodeState) object(v reflect.Value) error { case reflect.Map: // Map key must either have string kind, have an integer kind, // or be an encoding.TextUnmarshaler. - t := v.Type() switch t.Key().Kind() { case reflect.String, reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: default: if !reflect.PtrTo(t.Key()).Implements(textUnmarshalerType) { - d.saveError(&UnmarshalTypeError{Value: "object", Type: v.Type(), Offset: int64(d.off)}) + d.saveError(&UnmarshalTypeError{Value: "object", Type: t, Offset: int64(d.off)}) d.skip() return nil } @@ -664,9 +661,10 @@ func (d *decodeState) object(v reflect.Value) error { v.Set(reflect.MakeMap(t)) } case reflect.Struct: + fields = cachedTypeFields(t) // ok default: - d.saveError(&UnmarshalTypeError{Value: "object", Type: v.Type(), Offset: int64(d.off)}) + d.saveError(&UnmarshalTypeError{Value: "object", Type: t, Offset: int64(d.off)}) d.skip() return nil } @@ -698,7 +696,7 @@ func (d *decodeState) object(v reflect.Value) error { destring := false // whether the value is wrapped in a string to be decoded first if v.Kind() == reflect.Map { - elemType := v.Type().Elem() + elemType := t.Elem() if !mapElem.IsValid() { mapElem = reflect.New(elemType).Elem() } else { @@ -707,7 +705,6 @@ func (d *decodeState) object(v reflect.Value) error { subv = mapElem } else { var f *field - fields := cachedTypeFields(v.Type()) for i := range fields { ff := &fields[i] if bytes.Equal(ff.nameBytes, key) { @@ -744,7 +741,7 @@ func (d *decodeState) object(v reflect.Value) error { subv = subv.Field(i) } d.errorContext.Field = f.name - d.errorContext.Struct = v.Type() + d.errorContext.Struct = t } else if d.disallowUnknownFields { d.saveError(fmt.Errorf("json: unknown field %q", key)) } @@ -785,13 +782,13 @@ func (d *decodeState) object(v reflect.Value) error { // Write value back to map; // if using struct, subv points into struct already. if v.Kind() == reflect.Map { - kt := v.Type().Key() + kt := t.Key() var kv reflect.Value switch { case kt.Kind() == reflect.String: kv = reflect.ValueOf(key).Convert(kt) case reflect.PtrTo(kt).Implements(textUnmarshalerType): - kv = reflect.New(v.Type().Key()) + kv = reflect.New(kt) if err := d.literalStore(item, kv, true); err != nil { return err } diff --git a/src/encoding/json/stream.go b/src/encoding/json/stream.go index 63aa0309555ef..7d5137fbc716f 100644 --- a/src/encoding/json/stream.go +++ b/src/encoding/json/stream.go @@ -96,19 +96,19 @@ Input: // Look in the buffer for a new value. for i, c := range dec.buf[scanp:] { dec.scan.bytes++ - v := dec.scan.step(&dec.scan, c) - if v == scanEnd { + switch dec.scan.step(&dec.scan, c) { + case scanEnd: scanp += i break Input - } - // scanEnd is delayed one byte. - // We might block trying to get that byte from src, - // so instead invent a space byte. - if (v == scanEndObject || v == scanEndArray) && dec.scan.step(&dec.scan, ' ') == scanEnd { - scanp += i + 1 - break Input - } - if v == scanError { + case scanEndObject, scanEndArray: + // scanEnd is delayed one byte. + // We might block trying to get that byte from src, + // so instead invent a space byte. + if stateEndValue(&dec.scan, ' ') == scanEnd { + scanp += i + 1 + break Input + } + case scanError: dec.err = dec.scan.err return 0, dec.scan.err } From 30eda6715c6578de2086f03df36c4a8def838ec2 Mon Sep 17 00:00:00 2001 From: Andreas Auernhammer Date: Tue, 21 Aug 2018 16:12:36 +0200 Subject: [PATCH 0099/1663] crypto/rc4: remove assembler implementations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL removes the RC4 assembler implementations. RC4 is broken and should not be used for encryption anymore. Therefore it's not worth maintaining platform-specific assembler implementations. The native Go implementation may be slower or faster depending on the CPU: name old time/op new time/op delta RC4_128-4 256ns ± 0% 196ns ± 0% -23.78% (p=0.029 n=4+4) RC4_1K-4 2.38µs ± 0% 1.54µs ± 0% -35.22% (p=0.029 n=4+4) RC4_8K-4 19.4µs ± 1% 12.0µs ± 0% -38.35% (p=0.029 n=4+4) name old speed new speed delta RC4_128-4 498MB/s ± 0% 654MB/s ± 0% +31.12% (p=0.029 n=4+4) RC4_1K-4 431MB/s ± 0% 665MB/s ± 0% +54.34% (p=0.029 n=4+4) RC4_8K-4 418MB/s ± 1% 677MB/s ± 0% +62.18% (p=0.029 n=4+4) vendor_id : GenuineIntel cpu family : 6 model : 142 model name : Intel(R) Core(TM) i5-7Y54 CPU @ 1.20GHz stepping : 9 microcode : 0x84 cpu MHz : 800.036 cache size : 4096 KB name old time/op new time/op delta RC4_128-4 235ns ± 1% 431ns ± 0% +83.00% (p=0.000 n=10+10) RC4_1K-4 1.74µs ± 0% 3.41µs ± 0% +96.74% (p=0.000 n=10+10) RC4_8K-4 13.6µs ± 1% 26.8µs ± 0% +97.58% (p=0.000 n=10+9) name old speed new speed delta RC4_128-4 543MB/s ± 0% 297MB/s ± 1% -45.29% (p=0.000 n=10+10) RC4_1K-4 590MB/s ± 0% 300MB/s ± 0% -49.16% (p=0.000 n=10+10) RC4_8K-4 596MB/s ± 1% 302MB/s ± 0% -49.39% (p=0.000 n=10+9) vendor_id : GenuineIntel cpu family : 6 model : 63 model name : Intel(R) Xeon(R) CPU @ 2.30GHz stepping : 0 microcode : 0x1 cpu MHz : 2300.000 cache size : 46080 KB Fixes #25417 Change-Id: I4124037154aaaa8e48d300c23974f125b6055a1c Reviewed-on: https://go-review.googlesource.com/130397 Run-TryBot: Filippo Valsorda Reviewed-by: Brad Fitzpatrick Reviewed-by: Filippo Valsorda TryBot-Result: Gobot Gobot --- src/crypto/rc4/rc4.go | 9 +- src/crypto/rc4/rc4_386.s | 53 ---------- src/crypto/rc4/rc4_amd64.s | 179 ------------------------------- src/crypto/rc4/rc4_amd64p32.s | 192 ---------------------------------- src/crypto/rc4/rc4_arm.s | 62 ----------- src/crypto/rc4/rc4_asm.go | 26 ----- src/crypto/rc4/rc4_ref.go | 13 --- src/crypto/rc4/rc4_test.go | 19 +--- 8 files changed, 7 insertions(+), 546 deletions(-) delete mode 100644 src/crypto/rc4/rc4_386.s delete mode 100644 src/crypto/rc4/rc4_amd64.s delete mode 100644 src/crypto/rc4/rc4_amd64p32.s delete mode 100644 src/crypto/rc4/rc4_arm.s delete mode 100644 src/crypto/rc4/rc4_asm.go delete mode 100644 src/crypto/rc4/rc4_ref.go diff --git a/src/crypto/rc4/rc4.go b/src/crypto/rc4/rc4.go index c445bb078f290..d5e6ebcd712ae 100644 --- a/src/crypto/rc4/rc4.go +++ b/src/crypto/rc4/rc4.go @@ -54,12 +54,9 @@ func (c *Cipher) Reset() { c.i, c.j = 0, 0 } -// xorKeyStreamGeneric sets dst to the result of XORing src with the -// key stream. Dst and src must overlap entirely or not at all. -// -// This is the pure Go version. rc4_{amd64,386,arm}* contain assembly -// implementations. This is here for tests and to prevent bitrot. -func (c *Cipher) xorKeyStreamGeneric(dst, src []byte) { +// XORKeyStream sets dst to the result of XORing src with the key stream. +// Dst and src must overlap entirely or not at all. +func (c *Cipher) XORKeyStream(dst, src []byte) { if len(src) == 0 { return } diff --git a/src/crypto/rc4/rc4_386.s b/src/crypto/rc4/rc4_386.s deleted file mode 100644 index 54221036bac81..0000000000000 --- a/src/crypto/rc4/rc4_386.s +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2013 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 "textflag.h" - -// func xorKeyStream(dst, src *byte, n int, state *[256]byte, i, j *uint8) -TEXT ·xorKeyStream(SB),NOSPLIT,$0 - MOVL dst+0(FP), DI - MOVL src+4(FP), SI - MOVL state+12(FP), BP - - MOVL i+16(FP), AX - MOVBLZX (AX), AX - MOVL j+20(FP), BX - MOVBLZX (BX), BX - CMPL n+8(FP), $0 - JEQ done - -loop: - // i += 1 - INCB AX - - // j += c.s[i] - MOVBLZX (BP)(AX*4), DX - ADDB DX, BX - MOVBLZX BX, BX - - // c.s[i], c.s[j] = c.s[j], c.s[i] - MOVBLZX (BP)(BX*4), CX - MOVB CX, (BP)(AX*4) - MOVB DX, (BP)(BX*4) - - // *dst = *src ^ c.s[c.s[i]+c.s[j]] - ADDB DX, CX - MOVBLZX CX, CX - MOVB (BP)(CX*4), CX - XORB (SI), CX - MOVBLZX CX, CX - MOVB CX, (DI) - - INCL SI - INCL DI - DECL n+8(FP) - JNE loop - -done: - MOVL i+16(FP), CX - MOVB AX, (CX) - MOVL j+20(FP), CX - MOVB BX, (CX) - - RET diff --git a/src/crypto/rc4/rc4_amd64.s b/src/crypto/rc4/rc4_amd64.s deleted file mode 100644 index 57d941c8f3cc7..0000000000000 --- a/src/crypto/rc4/rc4_amd64.s +++ /dev/null @@ -1,179 +0,0 @@ -// Original source: -// http://www.zorinaq.com/papers/rc4-amd64.html -// http://www.zorinaq.com/papers/rc4-amd64.tar.bz2 - -#include "textflag.h" - -// Local modifications: -// -// Transliterated from GNU to 6a assembly syntax by the Go authors. -// The comments and spacing are from the original. -// -// The new EXTEND macros avoid a bad stall on some systems after 8-bit math. -// -// The original code accumulated 64 bits of key stream in an integer -// register and then XOR'ed the key stream into the data 8 bytes at a time. -// Modified to accumulate 128 bits of key stream into an XMM register -// and then XOR the key stream into the data 16 bytes at a time. -// Approximately doubles throughput. - -// NOTE: Changing EXTEND to a no-op makes the code run 1.2x faster on Core i5 -// but makes the code run 2.0x slower on Xeon. -#define EXTEND(r) MOVBLZX r, r - -/* -** RC4 implementation optimized for AMD64. -** -** Author: Marc Bevand -** Licence: I hereby disclaim the copyright on this code and place it -** in the public domain. -** -** The code has been designed to be easily integrated into openssl: -** the exported RC4() function can replace the actual implementations -** openssl already contains. Please note that when linking with openssl, -** it requires that sizeof(RC4_INT) == 8. So openssl must be compiled -** with -DRC4_INT='unsigned long'. -** -** The throughput achieved by this code is about 320 MBytes/sec, on -** a 1.8 GHz AMD Opteron (rev C0) processor. -*/ - -TEXT ·xorKeyStream(SB),NOSPLIT,$0 - MOVQ n+16(FP), BX // rbx = ARG(len) - MOVQ src+8(FP), SI // in = ARG(in) - MOVQ dst+0(FP), DI // out = ARG(out) - MOVQ state+24(FP), BP // d = ARG(data) - MOVQ i+32(FP), AX - MOVBQZX 0(AX), CX // x = *xp - MOVQ j+40(FP), AX - MOVBQZX 0(AX), DX // y = *yp - - LEAQ (SI)(BX*1), R9 // limit = in+len - -l1: CMPQ SI, R9 // cmp in with in+len - JGE finished // jump if (in >= in+len) - - INCB CX - EXTEND(CX) - TESTL $15, CX - JZ wordloop - - MOVBLZX (BP)(CX*4), AX - - ADDB AX, DX // y += tx - EXTEND(DX) - MOVBLZX (BP)(DX*4), BX // ty = d[y] - MOVB BX, (BP)(CX*4) // d[x] = ty - ADDB AX, BX // val = ty+tx - EXTEND(BX) - MOVB AX, (BP)(DX*4) // d[y] = tx - MOVBLZX (BP)(BX*4), R8 // val = d[val] - XORB (SI), R8 // xor 1 byte - MOVB R8, (DI) - INCQ SI // in++ - INCQ DI // out++ - JMP l1 - -wordloop: - SUBQ $16, R9 - CMPQ SI, R9 - JGT end - -start: - ADDQ $16, SI // increment in - ADDQ $16, DI // increment out - - // Each KEYROUND generates one byte of key and - // inserts it into an XMM register at the given 16-bit index. - // The key state array is uint32 words only using the bottom - // byte of each word, so the 16-bit OR only copies 8 useful bits. - // We accumulate alternating bytes into X0 and X1, and then at - // the end we OR X1<<8 into X0 to produce the actual key. - // - // At the beginning of the loop, CX%16 == 0, so the 16 loads - // at state[CX], state[CX+1], ..., state[CX+15] can precompute - // (state+CX) as R12 and then become R12[0], R12[1], ... R12[15], - // without fear of the byte computation CX+15 wrapping around. - // - // The first round needs R12[0], the second needs R12[1], and so on. - // We can avoid memory stalls by starting the load for round n+1 - // before the end of round n, using the LOAD macro. - LEAQ (BP)(CX*4), R12 - -#define KEYROUND(xmm, load, off, r1, r2, index) \ - MOVBLZX (BP)(DX*4), R8; \ - MOVB r1, (BP)(DX*4); \ - load((off+1), r2); \ - MOVB R8, (off*4)(R12); \ - ADDB r1, R8; \ - EXTEND(R8); \ - PINSRW $index, (BP)(R8*4), xmm - -#define LOAD(off, reg) \ - MOVBLZX (off*4)(R12), reg; \ - ADDB reg, DX; \ - EXTEND(DX) - -#define SKIP(off, reg) - - LOAD(0, AX) - KEYROUND(X0, LOAD, 0, AX, BX, 0) - KEYROUND(X1, LOAD, 1, BX, AX, 0) - KEYROUND(X0, LOAD, 2, AX, BX, 1) - KEYROUND(X1, LOAD, 3, BX, AX, 1) - KEYROUND(X0, LOAD, 4, AX, BX, 2) - KEYROUND(X1, LOAD, 5, BX, AX, 2) - KEYROUND(X0, LOAD, 6, AX, BX, 3) - KEYROUND(X1, LOAD, 7, BX, AX, 3) - KEYROUND(X0, LOAD, 8, AX, BX, 4) - KEYROUND(X1, LOAD, 9, BX, AX, 4) - KEYROUND(X0, LOAD, 10, AX, BX, 5) - KEYROUND(X1, LOAD, 11, BX, AX, 5) - KEYROUND(X0, LOAD, 12, AX, BX, 6) - KEYROUND(X1, LOAD, 13, BX, AX, 6) - KEYROUND(X0, LOAD, 14, AX, BX, 7) - KEYROUND(X1, SKIP, 15, BX, AX, 7) - - ADDB $16, CX - - PSLLQ $8, X1 - PXOR X1, X0 - MOVOU -16(SI), X2 - PXOR X0, X2 - MOVOU X2, -16(DI) - - CMPQ SI, R9 // cmp in with in+len-16 - JLE start // jump if (in <= in+len-16) - -end: - DECB CX - ADDQ $16, R9 // tmp = in+len - - // handle the last bytes, one by one -l2: CMPQ SI, R9 // cmp in with in+len - JGE finished // jump if (in >= in+len) - - INCB CX - EXTEND(CX) - MOVBLZX (BP)(CX*4), AX - - ADDB AX, DX // y += tx - EXTEND(DX) - MOVBLZX (BP)(DX*4), BX // ty = d[y] - MOVB BX, (BP)(CX*4) // d[x] = ty - ADDB AX, BX // val = ty+tx - EXTEND(BX) - MOVB AX, (BP)(DX*4) // d[y] = tx - MOVBLZX (BP)(BX*4), R8 // val = d[val] - XORB (SI), R8 // xor 1 byte - MOVB R8, (DI) - INCQ SI // in++ - INCQ DI // out++ - JMP l2 - -finished: - MOVQ j+40(FP), BX - MOVB DX, 0(BX) - MOVQ i+32(FP), AX - MOVB CX, 0(AX) - RET diff --git a/src/crypto/rc4/rc4_amd64p32.s b/src/crypto/rc4/rc4_amd64p32.s deleted file mode 100644 index 970b34e08eff6..0000000000000 --- a/src/crypto/rc4/rc4_amd64p32.s +++ /dev/null @@ -1,192 +0,0 @@ -// Original source: -// http://www.zorinaq.com/papers/rc4-amd64.html -// http://www.zorinaq.com/papers/rc4-amd64.tar.bz2 - -#include "textflag.h" - -// Local modifications: -// -// Transliterated from GNU to 6a assembly syntax by the Go authors. -// The comments and spacing are from the original. -// -// The new EXTEND macros avoid a bad stall on some systems after 8-bit math. -// -// The original code accumulated 64 bits of key stream in an integer -// register and then XOR'ed the key stream into the data 8 bytes at a time. -// Modified to accumulate 128 bits of key stream into an XMM register -// and then XOR the key stream into the data 16 bytes at a time. -// Approximately doubles throughput. -// -// Converted to amd64p32. -// -// To make safe for Native Client, avoid use of BP, R15, -// and two-register addressing modes. - -// NOTE: Changing EXTEND to a no-op makes the code run 1.2x faster on Core i5 -// but makes the code run 2.0x slower on Xeon. -#define EXTEND(r) MOVBLZX r, r - -/* -** RC4 implementation optimized for AMD64. -** -** Author: Marc Bevand -** Licence: I hereby disclaim the copyright on this code and place it -** in the public domain. -** -** The code has been designed to be easily integrated into openssl: -** the exported RC4() function can replace the actual implementations -** openssl already contains. Please note that when linking with openssl, -** it requires that sizeof(RC4_INT) == 8. So openssl must be compiled -** with -DRC4_INT='unsigned long'. -** -** The throughput achieved by this code is about 320 MBytes/sec, on -** a 1.8 GHz AMD Opteron (rev C0) processor. -*/ - -TEXT ·xorKeyStream(SB),NOSPLIT,$0 - MOVL n+8(FP), BX // rbx = ARG(len) - MOVL src+4(FP), SI // in = ARG(in) - MOVL dst+0(FP), DI // out = ARG(out) - MOVL state+12(FP), R10 // d = ARG(data) - MOVL i+16(FP), AX - MOVBQZX 0(AX), CX // x = *xp - MOVL j+20(FP), AX - MOVBQZX 0(AX), DX // y = *yp - - LEAQ (SI)(BX*1), R9 // limit = in+len - -l1: CMPQ SI, R9 // cmp in with in+len - JGE finished // jump if (in >= in+len) - - INCB CX - EXTEND(CX) - TESTL $15, CX - JZ wordloop - LEAL (R10)(CX*4), R12 - - MOVBLZX (R12), AX - - ADDB AX, DX // y += tx - EXTEND(DX) - LEAL (R10)(DX*4), R11 - MOVBLZX (R11), BX // ty = d[y] - MOVB BX, (R12) // d[x] = ty - ADDB AX, BX // val = ty+tx - EXTEND(BX) - LEAL (R10)(BX*4), R13 - MOVB AX, (R11) // d[y] = tx - MOVBLZX (R13), R8 // val = d[val] - XORB (SI), R8 // xor 1 byte - MOVB R8, (DI) - INCQ SI // in++ - INCQ DI // out++ - JMP l1 - -wordloop: - SUBQ $16, R9 - CMPQ SI, R9 - JGT end - -start: - ADDQ $16, SI // increment in - ADDQ $16, DI // increment out - - // Each KEYROUND generates one byte of key and - // inserts it into an XMM register at the given 16-bit index. - // The key state array is uint32 words only using the bottom - // byte of each word, so the 16-bit OR only copies 8 useful bits. - // We accumulate alternating bytes into X0 and X1, and then at - // the end we OR X1<<8 into X0 to produce the actual key. - // - // At the beginning of the loop, CX%16 == 0, so the 16 loads - // at state[CX], state[CX+1], ..., state[CX+15] can precompute - // (state+CX) as R12 and then become R12[0], R12[1], ... R12[15], - // without fear of the byte computation CX+15 wrapping around. - // - // The first round needs R12[0], the second needs R12[1], and so on. - // We can avoid memory stalls by starting the load for round n+1 - // before the end of round n, using the LOAD macro. - LEAQ (R10)(CX*4), R12 - -#define KEYROUND(xmm, load, off, r1, r2, index) \ - LEAL (R10)(DX*4), R11; \ - MOVBLZX (R11), R8; \ - MOVB r1, (R11); \ - load((off+1), r2); \ - MOVB R8, (off*4)(R12); \ - ADDB r1, R8; \ - EXTEND(R8); \ - LEAL (R10)(R8*4), R14; \ - PINSRW $index, (R14), xmm - -#define LOAD(off, reg) \ - MOVBLZX (off*4)(R12), reg; \ - ADDB reg, DX; \ - EXTEND(DX) - -#define SKIP(off, reg) - - LOAD(0, AX) - KEYROUND(X0, LOAD, 0, AX, BX, 0) - KEYROUND(X1, LOAD, 1, BX, AX, 0) - KEYROUND(X0, LOAD, 2, AX, BX, 1) - KEYROUND(X1, LOAD, 3, BX, AX, 1) - KEYROUND(X0, LOAD, 4, AX, BX, 2) - KEYROUND(X1, LOAD, 5, BX, AX, 2) - KEYROUND(X0, LOAD, 6, AX, BX, 3) - KEYROUND(X1, LOAD, 7, BX, AX, 3) - KEYROUND(X0, LOAD, 8, AX, BX, 4) - KEYROUND(X1, LOAD, 9, BX, AX, 4) - KEYROUND(X0, LOAD, 10, AX, BX, 5) - KEYROUND(X1, LOAD, 11, BX, AX, 5) - KEYROUND(X0, LOAD, 12, AX, BX, 6) - KEYROUND(X1, LOAD, 13, BX, AX, 6) - KEYROUND(X0, LOAD, 14, AX, BX, 7) - KEYROUND(X1, SKIP, 15, BX, AX, 7) - - ADDB $16, CX - - PSLLQ $8, X1 - PXOR X1, X0 - MOVOU -16(SI), X2 - PXOR X0, X2 - MOVOU X2, -16(DI) - - CMPQ SI, R9 // cmp in with in+len-16 - JLE start // jump if (in <= in+len-16) - -end: - DECB CX - ADDQ $16, R9 // tmp = in+len - - // handle the last bytes, one by one -l2: CMPQ SI, R9 // cmp in with in+len - JGE finished // jump if (in >= in+len) - - INCB CX - EXTEND(CX) - LEAL (R10)(CX*4), R12 - MOVBLZX (R12), AX - - ADDB AX, DX // y += tx - EXTEND(DX) - LEAL (R10)(DX*4), R11 - MOVBLZX (R11), BX // ty = d[y] - MOVB BX, (R12) // d[x] = ty - ADDB AX, BX // val = ty+tx - EXTEND(BX) - LEAL (R10)(BX*4), R13 - MOVB AX, (R11) // d[y] = tx - MOVBLZX (R13), R8 // val = d[val] - XORB (SI), R8 // xor 1 byte - MOVB R8, (DI) - INCQ SI // in++ - INCQ DI // out++ - JMP l2 - -finished: - MOVL j+20(FP), BX - MOVB DX, 0(BX) - MOVL i+16(FP), AX - MOVB CX, 0(AX) - RET diff --git a/src/crypto/rc4/rc4_arm.s b/src/crypto/rc4/rc4_arm.s deleted file mode 100644 index c726d6d1c04b4..0000000000000 --- a/src/crypto/rc4/rc4_arm.s +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright 2013 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. - -// +build !nacl - -#include "textflag.h" - -// Registers -#define Rdst R0 -#define Rsrc R1 -#define Rn R2 -#define Rstate R3 -#define Rpi R4 -#define Rpj R5 -#define Ri R6 -#define Rj R7 -#define Rk R8 -#define Rt R11 -#define Rt2 R12 - -// func xorKeyStream(dst, src *byte, n int, state *[256]byte, i, j *uint8) -TEXT ·xorKeyStream(SB),NOSPLIT,$0 - MOVW dst+0(FP), Rdst - MOVW src+4(FP), Rsrc - MOVW n+8(FP), Rn - MOVW state+12(FP), Rstate - MOVW i+16(FP), Rpi - MOVW j+20(FP), Rpj - MOVBU (Rpi), Ri - MOVBU (Rpj), Rj - MOVW $0, Rk - -loop: - // i += 1; j += state[i] - ADD $1, Ri - AND $0xff, Ri - MOVBU Ri<<2(Rstate), Rt - ADD Rt, Rj - AND $0xff, Rj - - // swap state[i] <-> state[j] - MOVBU Rj<<2(Rstate), Rt2 - MOVB Rt2, Ri<<2(Rstate) - MOVB Rt, Rj<<2(Rstate) - - // dst[k] = src[k] ^ state[state[i] + state[j]] - ADD Rt2, Rt - AND $0xff, Rt - MOVBU Rt<<2(Rstate), Rt - MOVBU Rk<<0(Rsrc), Rt2 - EOR Rt, Rt2 - MOVB Rt2, Rk<<0(Rdst) - - ADD $1, Rk - CMP Rk, Rn - BNE loop - -done: - MOVB Ri, (Rpi) - MOVB Rj, (Rpj) - RET diff --git a/src/crypto/rc4/rc4_asm.go b/src/crypto/rc4/rc4_asm.go deleted file mode 100644 index fc79e7ffc7834..0000000000000 --- a/src/crypto/rc4/rc4_asm.go +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2013 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. - -// +build amd64 amd64p32 arm,!nacl 386 - -package rc4 - -import "crypto/internal/subtle" - -func xorKeyStream(dst, src *byte, n int, state *[256]uint32, i, j *uint8) - -// XORKeyStream sets dst to the result of XORing src with the key stream. -// Dst and src must overlap entirely or not at all. -func (c *Cipher) XORKeyStream(dst, src []byte) { - if len(src) == 0 { - return - } - if len(dst) < len(src) { - panic("crypto/cipher: output smaller than input") - } - if subtle.InexactOverlap(dst[:len(src)], src) { - panic("crypto/cipher: invalid buffer overlap") - } - xorKeyStream(&dst[0], &src[0], len(src), &c.s, &c.i, &c.j) -} diff --git a/src/crypto/rc4/rc4_ref.go b/src/crypto/rc4/rc4_ref.go deleted file mode 100644 index 9b98fc49e7f29..0000000000000 --- a/src/crypto/rc4/rc4_ref.go +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2013 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. - -// +build !amd64,!amd64p32,!arm,!386 arm,nacl - -package rc4 - -// XORKeyStream sets dst to the result of XORing src with the key stream. -// Dst and src must overlap entirely or not at all. -func (c *Cipher) XORKeyStream(dst, src []byte) { - c.xorKeyStreamGeneric(dst, src) -} diff --git a/src/crypto/rc4/rc4_test.go b/src/crypto/rc4/rc4_test.go index 1fc08b859343a..e7356aa45de1b 100644 --- a/src/crypto/rc4/rc4_test.go +++ b/src/crypto/rc4/rc4_test.go @@ -117,30 +117,19 @@ func TestGolden(t *testing.T) { } func TestBlock(t *testing.T) { - testBlock(t, (*Cipher).XORKeyStream) -} - -// Test the pure Go version. -// Because we have assembly for amd64, 386, and arm, this prevents -// bitrot of the reference implementations. -func TestBlockGeneric(t *testing.T) { - testBlock(t, (*Cipher).xorKeyStreamGeneric) -} - -func testBlock(t *testing.T, xor func(c *Cipher, dst, src []byte)) { c1a, _ := NewCipher(golden[0].key) c1b, _ := NewCipher(golden[1].key) data1 := make([]byte, 1<<20) for i := range data1 { - xor(c1a, data1[i:i+1], data1[i:i+1]) - xor(c1b, data1[i:i+1], data1[i:i+1]) + c1a.XORKeyStream(data1[i:i+1], data1[i:i+1]) + c1b.XORKeyStream(data1[i:i+1], data1[i:i+1]) } c2a, _ := NewCipher(golden[0].key) c2b, _ := NewCipher(golden[1].key) data2 := make([]byte, 1<<20) - xor(c2a, data2, data2) - xor(c2b, data2, data2) + c2a.XORKeyStream(data2, data2) + c2b.XORKeyStream(data2, data2) if !bytes.Equal(data1, data2) { t.Fatalf("bad block") From 08cc3dc5e70986dde114cb5b22d94848ed1b5419 Mon Sep 17 00:00:00 2001 From: Ilya Tocar Date: Tue, 21 Aug 2018 14:40:01 -0500 Subject: [PATCH 0100/1663] time: optimize big4 Use the same load order in big4 as in encoding/binary.BigEndian. This order is recognized by the compiler and converted into single load. This isn't in the hot path, but doesn't hurt readability, so lets do this. Change-Id: Ib1240d0b278e9d667ad419fe91fa52b23d28cfc0 Reviewed-on: https://go-review.googlesource.com/130478 Run-TryBot: Ilya Tocar TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/time/zoneinfo_read.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/time/zoneinfo_read.go b/src/time/zoneinfo_read.go index 20f84f00671bf..29244db29ec67 100644 --- a/src/time/zoneinfo_read.go +++ b/src/time/zoneinfo_read.go @@ -55,7 +55,7 @@ func (d *dataIO) big4() (n uint32, ok bool) { d.error = true return 0, false } - return uint32(p[0])<<24 | uint32(p[1])<<16 | uint32(p[2])<<8 | uint32(p[3]), true + return uint32(p[3]) | uint32(p[2])<<8 | uint32(p[1])<<16 | uint32(p[0])<<24, true } func (d *dataIO) byte() (n byte, ok bool) { From 39e59da76debbe98efdf6e2faa045b8c3804d742 Mon Sep 17 00:00:00 2001 From: Ilya Tocar Date: Tue, 21 Aug 2018 14:50:48 -0500 Subject: [PATCH 0101/1663] net: use internal/bytealg insetad of linkname tricks We are currently using go:linkname for some algorithms from strings/bytes packages, to avoid importing strings/bytes. But strings/bytes are just wrappers around internal/bytealg, so we should use internal/bytealg directly. Change-Id: I2836f779b88bf8876d5fa725043a6042bdda0390 Reviewed-on: https://go-review.googlesource.com/130515 Run-TryBot: Ilya Tocar TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Ian Lance Taylor --- src/net/conf.go | 5 +++-- src/net/dnsconfig_unix.go | 3 ++- src/net/hosts.go | 3 ++- src/net/ip.go | 16 ++++++---------- src/net/ipsock.go | 11 ++++++----- src/net/ipsock_plan9.go | 3 ++- src/net/lookup_plan9.go | 9 +++++---- src/net/lookup_unix.go | 3 ++- src/net/nss.go | 9 +++++---- src/net/parse.go | 24 ++++++------------------ src/net/port_unix.go | 7 +++++-- src/net/sockopt_posix.go | 3 ++- 12 files changed, 46 insertions(+), 50 deletions(-) diff --git a/src/net/conf.go b/src/net/conf.go index 71ed1360c5637..127aba30cb764 100644 --- a/src/net/conf.go +++ b/src/net/conf.go @@ -7,6 +7,7 @@ package net import ( + "internal/bytealg" "os" "runtime" "sync" @@ -132,7 +133,7 @@ func (c *conf) hostLookupOrder(r *Resolver, hostname string) (ret hostLookupOrde if c.forceCgoLookupHost || c.resolv.unknownOpt || c.goos == "android" { return fallbackOrder } - if byteIndex(hostname, '\\') != -1 || byteIndex(hostname, '%') != -1 { + if bytealg.IndexByteString(hostname, '\\') != -1 || bytealg.IndexByteString(hostname, '%') != -1 { // Don't deal with special form hostnames with backslashes // or '%'. return fallbackOrder @@ -301,7 +302,7 @@ func goDebugNetDNS() (dnsMode string, debugLevel int) { dnsMode = s } } - if i := byteIndex(goDebug, '+'); i != -1 { + if i := bytealg.IndexByteString(goDebug, '+'); i != -1 { parsePart(goDebug[:i]) parsePart(goDebug[i+1:]) return diff --git a/src/net/dnsconfig_unix.go b/src/net/dnsconfig_unix.go index 707fd6f6fe841..64c66f96b81e2 100644 --- a/src/net/dnsconfig_unix.go +++ b/src/net/dnsconfig_unix.go @@ -9,6 +9,7 @@ package net import ( + "internal/bytealg" "os" "sync/atomic" "time" @@ -155,7 +156,7 @@ func dnsDefaultSearch() []string { // best effort return nil } - if i := byteIndex(hn, '.'); i >= 0 && i < len(hn)-1 { + if i := bytealg.IndexByteString(hn, '.'); i >= 0 && i < len(hn)-1 { return []string{ensureRooted(hn[i+1:])} } return nil diff --git a/src/net/hosts.go b/src/net/hosts.go index ebc0353a7fb6d..5c560f3756ed1 100644 --- a/src/net/hosts.go +++ b/src/net/hosts.go @@ -5,6 +5,7 @@ package net import ( + "internal/bytealg" "sync" "time" ) @@ -68,7 +69,7 @@ func readHosts() { return } for line, ok := file.readLine(); ok; line, ok = file.readLine() { - if i := byteIndex(line, '#'); i >= 0 { + if i := bytealg.IndexByteString(line, '#'); i >= 0 { // Discard comments. line = line[0:i] } diff --git a/src/net/ip.go b/src/net/ip.go index 410de92ccc2dc..9a6fda00e84b6 100644 --- a/src/net/ip.go +++ b/src/net/ip.go @@ -12,7 +12,7 @@ package net -import _ "unsafe" // for go:linkname +import "internal/bytealg" // IP address lengths (bytes). const ( @@ -246,7 +246,7 @@ func (ip IP) Mask(mask IPMask) IP { if len(mask) == IPv6len && len(ip) == IPv4len && allFF(mask[:12]) { mask = mask[12:] } - if len(mask) == IPv4len && len(ip) == IPv6len && bytesEqual(ip[:12], v4InV6Prefix) { + if len(mask) == IPv4len && len(ip) == IPv6len && bytealg.Equal(ip[:12], v4InV6Prefix) { ip = ip[12:] } n := len(ip) @@ -406,21 +406,17 @@ func (ip *IP) UnmarshalText(text []byte) error { // considered to be equal. func (ip IP) Equal(x IP) bool { if len(ip) == len(x) { - return bytesEqual(ip, x) + return bytealg.Equal(ip, x) } if len(ip) == IPv4len && len(x) == IPv6len { - return bytesEqual(x[0:12], v4InV6Prefix) && bytesEqual(ip, x[12:]) + return bytealg.Equal(x[0:12], v4InV6Prefix) && bytealg.Equal(ip, x[12:]) } if len(ip) == IPv6len && len(x) == IPv4len { - return bytesEqual(ip[0:12], v4InV6Prefix) && bytesEqual(ip[12:], x) + return bytealg.Equal(ip[0:12], v4InV6Prefix) && bytealg.Equal(ip[12:], x) } return false } -// bytes.Equal is implemented in runtime/asm_$goarch.s -//go:linkname bytesEqual bytes.Equal -func bytesEqual(x, y []byte) bool - func (ip IP) matchAddrFamily(x IP) bool { return ip.To4() != nil && x.To4() != nil || ip.To16() != nil && ip.To4() == nil && x.To16() != nil && x.To4() == nil } @@ -711,7 +707,7 @@ func parseIPZone(s string) (IP, string) { // For example, ParseCIDR("192.0.2.1/24") returns the IP address // 192.0.2.1 and the network 192.0.2.0/24. func ParseCIDR(s string) (IP, *IPNet, error) { - i := byteIndex(s, '/') + i := bytealg.IndexByteString(s, '/') if i < 0 { return nil, nil, &ParseError{Type: "CIDR address", Text: s} } diff --git a/src/net/ipsock.go b/src/net/ipsock.go index f4ff82bd75091..84fa0ac0a3270 100644 --- a/src/net/ipsock.go +++ b/src/net/ipsock.go @@ -6,6 +6,7 @@ package net import ( "context" + "internal/bytealg" "sync" ) @@ -170,7 +171,7 @@ func SplitHostPort(hostport string) (host, port string, err error) { if hostport[0] == '[' { // Expect the first ']' just before the last ':'. - end := byteIndex(hostport, ']') + end := bytealg.IndexByteString(hostport, ']') if end < 0 { return addrErr(hostport, "missing ']' in address") } @@ -192,14 +193,14 @@ func SplitHostPort(hostport string) (host, port string, err error) { j, k = 1, end+1 // there can't be a '[' resp. ']' before these positions } else { host = hostport[:i] - if byteIndex(host, ':') >= 0 { + if bytealg.IndexByteString(host, ':') >= 0 { return addrErr(hostport, tooManyColons) } } - if byteIndex(hostport[j:], '[') >= 0 { + if bytealg.IndexByteString(hostport[j:], '[') >= 0 { return addrErr(hostport, "unexpected '[' in address") } - if byteIndex(hostport[k:], ']') >= 0 { + if bytealg.IndexByteString(hostport[k:], ']') >= 0 { return addrErr(hostport, "unexpected ']' in address") } @@ -226,7 +227,7 @@ func splitHostZone(s string) (host, zone string) { func JoinHostPort(host, port string) string { // We assume that host is a literal IPv6 address if host has // colons. - if byteIndex(host, ':') >= 0 { + if bytealg.IndexByteString(host, ':') >= 0 { return "[" + host + "]:" + port } return host + ":" + port diff --git a/src/net/ipsock_plan9.go b/src/net/ipsock_plan9.go index 312e4adb47deb..d226585e086f8 100644 --- a/src/net/ipsock_plan9.go +++ b/src/net/ipsock_plan9.go @@ -6,6 +6,7 @@ package net import ( "context" + "internal/bytealg" "os" "syscall" ) @@ -49,7 +50,7 @@ func probe(filename, query string) bool { // parsePlan9Addr parses address of the form [ip!]port (e.g. 127.0.0.1!80). func parsePlan9Addr(s string) (ip IP, iport int, err error) { addr := IPv4zero // address contains port only - i := byteIndex(s, '!') + i := bytealg.IndexByteString(s, '!') if i >= 0 { addr = ParseIP(s[:i]) if addr == nil { diff --git a/src/net/lookup_plan9.go b/src/net/lookup_plan9.go index 5547f0b0eeb3a..d5ae9b2fd9d98 100644 --- a/src/net/lookup_plan9.go +++ b/src/net/lookup_plan9.go @@ -7,6 +7,7 @@ package net import ( "context" "errors" + "internal/bytealg" "io" "os" ) @@ -135,7 +136,7 @@ func lookupProtocol(ctx context.Context, name string) (proto int, err error) { return 0, UnknownNetworkError(name) } s := f[1] - if n, _, ok := dtoi(s[byteIndex(s, '=')+1:]); ok { + if n, _, ok := dtoi(s[bytealg.IndexByteString(s, '=')+1:]); ok { return n, nil } return 0, UnknownNetworkError(name) @@ -158,7 +159,7 @@ loop: continue } addr := f[1] - if i := byteIndex(addr, '!'); i >= 0 { + if i := bytealg.IndexByteString(addr, '!'); i >= 0 { addr = addr[:i] // remove port } if ParseIP(addr) == nil { @@ -210,7 +211,7 @@ func (*Resolver) lookupPort(ctx context.Context, network, service string) (port return 0, unknownPortError } s := f[1] - if i := byteIndex(s, '!'); i >= 0 { + if i := bytealg.IndexByteString(s, '!'); i >= 0 { s = s[i+1:] // remove address } if n, _, ok := dtoi(s); ok { @@ -304,7 +305,7 @@ func (*Resolver) lookupTXT(ctx context.Context, name string) (txt []string, err return } for _, line := range lines { - if i := byteIndex(line, '\t'); i >= 0 { + if i := bytealg.IndexByteString(line, '\t'); i >= 0 { txt = append(txt, absDomainName([]byte(line[i+1:]))) } } diff --git a/src/net/lookup_unix.go b/src/net/lookup_unix.go index 2c3191aca8a66..04f443bb1aa74 100644 --- a/src/net/lookup_unix.go +++ b/src/net/lookup_unix.go @@ -8,6 +8,7 @@ package net import ( "context" + "internal/bytealg" "sync" "syscall" @@ -27,7 +28,7 @@ func readProtocols() { for line, ok := file.readLine(); ok; line, ok = file.readLine() { // tcp 6 TCP # transmission control protocol - if i := byteIndex(line, '#'); i >= 0 { + if i := bytealg.IndexByteString(line, '#'); i >= 0 { line = line[0:i] } f := getFields(line) diff --git a/src/net/nss.go b/src/net/nss.go index 08c3e6a69fe55..f10bb52e0e2aa 100644 --- a/src/net/nss.go +++ b/src/net/nss.go @@ -8,6 +8,7 @@ package net import ( "errors" + "internal/bytealg" "io" "os" ) @@ -85,7 +86,7 @@ func parseNSSConf(r io.Reader) *nssConf { if len(line) == 0 { return nil } - colon := bytesIndexByte(line, ':') + colon := bytealg.IndexByte(line, ':') if colon == -1 { return errors.New("no colon on line") } @@ -96,7 +97,7 @@ func parseNSSConf(r io.Reader) *nssConf { if len(srcs) == 0 { break } - sp := bytesIndexByte(srcs, ' ') + sp := bytealg.IndexByte(srcs, ' ') var src string if sp == -1 { src = string(srcs) @@ -108,7 +109,7 @@ func parseNSSConf(r io.Reader) *nssConf { var criteria []nssCriterion // See if there's a criteria block in brackets. if len(srcs) > 0 && srcs[0] == '[' { - bclose := bytesIndexByte(srcs, ']') + bclose := bytealg.IndexByte(srcs, ']') if bclose == -1 { return errors.New("unclosed criterion bracket") } @@ -143,7 +144,7 @@ func parseCriteria(x []byte) (c []nssCriterion, err error) { if len(f) < 3 { return errors.New("criterion too short") } - eq := bytesIndexByte(f, '=') + eq := bytealg.IndexByte(f, '=') if eq == -1 { return errors.New("criterion lacks equal sign") } diff --git a/src/net/parse.go b/src/net/parse.go index e356cb1559660..cdb35bb826e0e 100644 --- a/src/net/parse.go +++ b/src/net/parse.go @@ -8,10 +8,10 @@ package net import ( + "internal/bytealg" "io" "os" "time" - _ "unsafe" // For go:linkname ) type file struct { @@ -80,17 +80,11 @@ func stat(name string) (mtime time.Time, size int64, err error) { return st.ModTime(), st.Size(), nil } -// byteIndex is strings.IndexByte. It returns the index of the -// first instance of c in s, or -1 if c is not present in s. -// strings.IndexByte is implemented in runtime/asm_$GOARCH.s -//go:linkname byteIndex strings.IndexByte -func byteIndex(s string, c byte) int - // Count occurrences in s of any bytes in t. func countAnyByte(s string, t string) int { n := 0 for i := 0; i < len(s); i++ { - if byteIndex(t, s[i]) >= 0 { + if bytealg.IndexByteString(t, s[i]) >= 0 { n++ } } @@ -103,7 +97,7 @@ func splitAtBytes(s string, t string) []string { n := 0 last := 0 for i := 0; i < len(s); i++ { - if byteIndex(t, s[i]) >= 0 { + if bytealg.IndexByteString(t, s[i]) >= 0 { if last < i { a[n] = s[last:i] n++ @@ -276,7 +270,7 @@ func isSpace(b byte) bool { // removeComment returns line, removing any '#' byte and any following // bytes. func removeComment(line []byte) []byte { - if i := bytesIndexByte(line, '#'); i != -1 { + if i := bytealg.IndexByte(line, '#'); i != -1 { return line[:i] } return line @@ -287,7 +281,7 @@ func removeComment(line []byte) []byte { // It returns the first non-nil error returned by fn. func foreachLine(x []byte, fn func(line []byte) error) error { for len(x) > 0 { - nl := bytesIndexByte(x, '\n') + nl := bytealg.IndexByte(x, '\n') if nl == -1 { return fn(x) } @@ -305,7 +299,7 @@ func foreachLine(x []byte, fn func(line []byte) error) error { func foreachField(x []byte, fn func(field []byte) error) error { x = trimSpace(x) for len(x) > 0 { - sp := bytesIndexByte(x, ' ') + sp := bytealg.IndexByte(x, ' ') if sp == -1 { return fn(x) } @@ -319,12 +313,6 @@ func foreachField(x []byte, fn func(field []byte) error) error { return nil } -// bytesIndexByte is bytes.IndexByte. It returns the index of the -// first instance of c in s, or -1 if c is not present in s. -// bytes.IndexByte is implemented in runtime/asm_$GOARCH.s -//go:linkname bytesIndexByte bytes.IndexByte -func bytesIndexByte(s []byte, c byte) int - // stringsHasSuffix is strings.HasSuffix. It reports whether s ends in // suffix. func stringsHasSuffix(s, suffix string) bool { diff --git a/src/net/port_unix.go b/src/net/port_unix.go index 64c7f575c7f4d..d0882a2b78a8e 100644 --- a/src/net/port_unix.go +++ b/src/net/port_unix.go @@ -8,7 +8,10 @@ package net -import "sync" +import ( + "internal/bytealg" + "sync" +) var onceReadServices sync.Once @@ -21,7 +24,7 @@ func readServices() { for line, ok := file.readLine(); ok; line, ok = file.readLine() { // "http 80/tcp www www-http # World Wide Web HTTP" - if i := byteIndex(line, '#'); i >= 0 { + if i := bytealg.IndexByteString(line, '#'); i >= 0 { line = line[:i] } f := getFields(line) diff --git a/src/net/sockopt_posix.go b/src/net/sockopt_posix.go index e8af84f418ebe..83ab0125959e4 100644 --- a/src/net/sockopt_posix.go +++ b/src/net/sockopt_posix.go @@ -7,6 +7,7 @@ package net import ( + "internal/bytealg" "runtime" "syscall" ) @@ -94,7 +95,7 @@ func setIPv4MreqToInterface(mreq *syscall.IPMreq, ifi *Interface) error { } } done: - if bytesEqual(mreq.Multiaddr[:], IPv4zero.To4()) { + if bytealg.Equal(mreq.Multiaddr[:], IPv4zero.To4()) { return errNoSuchMulticastInterface } return nil From aa311fecda008d26f97af0a8e7f57dcd04cae6ae Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Tue, 24 Jul 2018 15:13:41 -0700 Subject: [PATCH 0102/1663] cmd/link: support windows/arm Enable the Go linker to generate executables for windows/arm. Generates PE relocation tables, which are used by Windows to dynamically relocate the Go binary in memory. Windows on ARM requires all modules to be relocatable, unlike x86/amd64 which are permitted to have fixed base addresses. Updates #26148 Change-Id: Ie63964ff52c2377e121b2885e9d05ec3ed8dc1cd Reviewed-on: https://go-review.googlesource.com/125648 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/internal/objfile/pe.go | 3 + src/cmd/link/internal/arm/asm.go | 41 +++++ src/cmd/link/internal/arm/obj.go | 5 + src/cmd/link/internal/ld/config.go | 2 +- src/cmd/link/internal/ld/data.go | 8 +- src/cmd/link/internal/ld/pe.go | 265 +++++++++++++++++++++++---- src/cmd/link/internal/loadpe/ldpe.go | 71 +++++-- 7 files changed, 338 insertions(+), 57 deletions(-) diff --git a/src/cmd/internal/objfile/pe.go b/src/cmd/internal/objfile/pe.go index 80db6f0f1872f..259b59a4f4aeb 100644 --- a/src/cmd/internal/objfile/pe.go +++ b/src/cmd/internal/objfile/pe.go @@ -190,6 +190,9 @@ func (f *peFile) goarch() string { if _, err := findPESymbol(f.pe, "_rt0_amd64_windows"); err == nil { return "amd64" } + if _, err := findPESymbol(f.pe, "_rt0_arm_windows"); err == nil { + return "arm" + } return "" } diff --git a/src/cmd/link/internal/arm/asm.go b/src/cmd/link/internal/arm/asm.go index 5e4ddea88e1fa..b1d44b5896fd7 100644 --- a/src/cmd/link/internal/arm/asm.go +++ b/src/cmd/link/internal/arm/asm.go @@ -411,6 +411,35 @@ func machoreloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, se return true } +func pereloc1(arch *sys.Arch, out *ld.OutBuf, s *sym.Symbol, r *sym.Reloc, sectoff int64) bool { + rs := r.Xsym + + if rs.Dynid < 0 { + ld.Errorf(s, "reloc %d (%s) to non-coff symbol %s type=%d (%s)", r.Type, sym.RelocName(arch, r.Type), rs.Name, rs.Type, rs.Type) + return false + } + + out.Write32(uint32(sectoff)) + out.Write32(uint32(rs.Dynid)) + + var v uint32 + switch r.Type { + default: + // unsupported relocation type + return false + + case objabi.R_DWARFSECREF: + v = ld.IMAGE_REL_ARM_SECREL + + case objabi.R_ADDR: + v = ld.IMAGE_REL_ARM_ADDR32 + } + + out.Write16(uint16(v)) + + return true +} + // sign extend a 24-bit integer func signext24(x int64) int32 { return (int32(x) << 8) >> 8 @@ -799,6 +828,10 @@ func asmb(ctxt *ld.Link) { case objabi.Hdarwin: symo = uint32(ld.Segdwarf.Fileoff + uint64(ld.Rnd(int64(ld.Segdwarf.Filelen), int64(*ld.FlagRound))) + uint64(machlink)) + + case objabi.Hwindows: + symo = uint32(ld.Segdwarf.Fileoff + ld.Segdwarf.Filelen) + symo = uint32(ld.Rnd(int64(symo), ld.PEFILEALIGN)) } ctxt.Out.SeekSet(int64(symo)) @@ -828,6 +861,11 @@ func asmb(ctxt *ld.Link) { ctxt.Out.Flush() } + case objabi.Hwindows: + if ctxt.Debugvlog != 0 { + ctxt.Logf("%5.2f dwarf\n", ld.Cputime()) + } + case objabi.Hdarwin: if ctxt.LinkMode == ld.LinkExternal { ld.Machoemitreloc(ctxt) @@ -860,6 +898,9 @@ func asmb(ctxt *ld.Link) { case objabi.Hdarwin: ld.Asmbmacho(ctxt) + + case objabi.Hwindows: + ld.Asmbpe(ctxt) } ctxt.Out.Flush() diff --git a/src/cmd/link/internal/arm/obj.go b/src/cmd/link/internal/arm/obj.go index 788be68522fa5..77716bb954dfd 100644 --- a/src/cmd/link/internal/arm/obj.go +++ b/src/cmd/link/internal/arm/obj.go @@ -57,6 +57,7 @@ func Init() (*sys.Arch, ld.Arch) { Elfsetupplt: elfsetupplt, Gentext: gentext, Machoreloc1: machoreloc1, + PEreloc1: pereloc1, Linuxdynld: "/lib/ld-linux.so.3", // 2 for OABI, 3 for EABI Freebsddynld: "/usr/libexec/ld-elf.so.1", @@ -130,6 +131,10 @@ func archinit(ctxt *ld.Link) { if *ld.FlagRound == -1 { *ld.FlagRound = 4096 } + + case objabi.Hwindows: /* PE executable */ + // ld.HEADR, ld.FlagTextAddr, ld.FlagDataAddr and ld.FlagRound are set in ld.Peinit + return } if *ld.FlagDataAddr != 0 && *ld.FlagRound != 0 { diff --git a/src/cmd/link/internal/ld/config.go b/src/cmd/link/internal/ld/config.go index 18fbea62eef98..77b03b67f9b82 100644 --- a/src/cmd/link/internal/ld/config.go +++ b/src/cmd/link/internal/ld/config.go @@ -60,7 +60,7 @@ func (mode *BuildMode) Set(s string) error { } case "windows": switch objabi.GOARCH { - case "amd64", "386": + case "amd64", "386", "arm": default: return badmode() } diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 5dd4aac03e376..730e9a0bf7612 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -539,13 +539,17 @@ func windynrelocsym(ctxt *Link, s *sym.Symbol) { r.Add = int64(targ.Plt) // jmp *addr - if ctxt.Arch.Family == sys.I386 { + switch ctxt.Arch.Family { + default: + Errorf(s, "unsupported arch %v", ctxt.Arch.Family) + return + case sys.I386: rel.AddUint8(0xff) rel.AddUint8(0x25) rel.AddAddr(ctxt.Arch, targ) rel.AddUint8(0x90) rel.AddUint8(0x90) - } else { + case sys.AMD64: rel.AddUint8(0xff) rel.AddUint8(0x24) rel.AddUint8(0x25) diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go index c81e3d6af5776..0e60ef76d218f 100644 --- a/src/cmd/link/internal/ld/pe.go +++ b/src/cmd/link/internal/ld/pe.go @@ -54,41 +54,45 @@ var ( ) const ( - IMAGE_FILE_MACHINE_I386 = 0x14c - IMAGE_FILE_MACHINE_AMD64 = 0x8664 - IMAGE_FILE_RELOCS_STRIPPED = 0x0001 - IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002 - IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004 - IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020 - IMAGE_FILE_32BIT_MACHINE = 0x0100 - IMAGE_FILE_DEBUG_STRIPPED = 0x0200 - IMAGE_SCN_CNT_CODE = 0x00000020 - IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040 - IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080 - IMAGE_SCN_MEM_EXECUTE = 0x20000000 - IMAGE_SCN_MEM_READ = 0x40000000 - IMAGE_SCN_MEM_WRITE = 0x80000000 - IMAGE_SCN_MEM_DISCARDABLE = 0x2000000 - IMAGE_SCN_LNK_NRELOC_OVFL = 0x1000000 - IMAGE_SCN_ALIGN_32BYTES = 0x600000 - IMAGE_DIRECTORY_ENTRY_EXPORT = 0 - IMAGE_DIRECTORY_ENTRY_IMPORT = 1 - IMAGE_DIRECTORY_ENTRY_RESOURCE = 2 - IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3 - IMAGE_DIRECTORY_ENTRY_SECURITY = 4 - IMAGE_DIRECTORY_ENTRY_BASERELOC = 5 - IMAGE_DIRECTORY_ENTRY_DEBUG = 6 - IMAGE_DIRECTORY_ENTRY_COPYRIGHT = 7 - IMAGE_DIRECTORY_ENTRY_ARCHITECTURE = 7 - IMAGE_DIRECTORY_ENTRY_GLOBALPTR = 8 - IMAGE_DIRECTORY_ENTRY_TLS = 9 - IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG = 10 - IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT = 11 - IMAGE_DIRECTORY_ENTRY_IAT = 12 - IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT = 13 - IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14 - IMAGE_SUBSYSTEM_WINDOWS_GUI = 2 - IMAGE_SUBSYSTEM_WINDOWS_CUI = 3 + IMAGE_FILE_MACHINE_I386 = 0x14c + IMAGE_FILE_MACHINE_AMD64 = 0x8664 + IMAGE_FILE_MACHINE_ARM = 0x1c0 + IMAGE_FILE_MACHINE_ARMNT = 0x1c4 + IMAGE_FILE_RELOCS_STRIPPED = 0x0001 + IMAGE_FILE_EXECUTABLE_IMAGE = 0x0002 + IMAGE_FILE_LINE_NUMS_STRIPPED = 0x0004 + IMAGE_FILE_LARGE_ADDRESS_AWARE = 0x0020 + IMAGE_FILE_32BIT_MACHINE = 0x0100 + IMAGE_FILE_DEBUG_STRIPPED = 0x0200 + IMAGE_SCN_CNT_CODE = 0x00000020 + IMAGE_SCN_CNT_INITIALIZED_DATA = 0x00000040 + IMAGE_SCN_CNT_UNINITIALIZED_DATA = 0x00000080 + IMAGE_SCN_MEM_EXECUTE = 0x20000000 + IMAGE_SCN_MEM_READ = 0x40000000 + IMAGE_SCN_MEM_WRITE = 0x80000000 + IMAGE_SCN_MEM_DISCARDABLE = 0x2000000 + IMAGE_SCN_LNK_NRELOC_OVFL = 0x1000000 + IMAGE_SCN_ALIGN_32BYTES = 0x600000 + IMAGE_DIRECTORY_ENTRY_EXPORT = 0 + IMAGE_DIRECTORY_ENTRY_IMPORT = 1 + IMAGE_DIRECTORY_ENTRY_RESOURCE = 2 + IMAGE_DIRECTORY_ENTRY_EXCEPTION = 3 + IMAGE_DIRECTORY_ENTRY_SECURITY = 4 + IMAGE_DIRECTORY_ENTRY_BASERELOC = 5 + IMAGE_DIRECTORY_ENTRY_DEBUG = 6 + IMAGE_DIRECTORY_ENTRY_COPYRIGHT = 7 + IMAGE_DIRECTORY_ENTRY_ARCHITECTURE = 7 + IMAGE_DIRECTORY_ENTRY_GLOBALPTR = 8 + IMAGE_DIRECTORY_ENTRY_TLS = 9 + IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG = 10 + IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT = 11 + IMAGE_DIRECTORY_ENTRY_IAT = 12 + IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT = 13 + IMAGE_DIRECTORY_ENTRY_COM_DESCRIPTOR = 14 + IMAGE_SUBSYSTEM_WINDOWS_GUI = 2 + IMAGE_SUBSYSTEM_WINDOWS_CUI = 3 + IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE = 0x0040 + IMAGE_DLLCHARACTERISTICS_NX_COMPAT = 0x0100 ) // TODO(crawshaw): add these constants to debug/pe. @@ -109,6 +113,15 @@ const ( IMAGE_REL_AMD64_ADDR32 = 0x0002 IMAGE_REL_AMD64_REL32 = 0x0004 IMAGE_REL_AMD64_SECREL = 0x000B + + IMAGE_REL_ARM_ABSOLUTE = 0x0000 + IMAGE_REL_ARM_ADDR32 = 0x0001 + IMAGE_REL_ARM_ADDR32NB = 0x0002 + IMAGE_REL_ARM_BRANCH24 = 0x0003 + IMAGE_REL_ARM_BRANCH11 = 0x0004 + IMAGE_REL_ARM_SECREL = 0x000F + + IMAGE_REL_BASED_HIGHLOW = 3 ) // Copyright 2009 The Go Authors. All rights reserved. @@ -477,6 +490,8 @@ func (f *peFile) addInitArray(ctxt *Link) *peSection { size = 4 case "amd64": size = 8 + case "arm": + size = 4 } sect := f.addSection(".ctors", size, size) sect.characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ @@ -487,7 +502,7 @@ func (f *peFile) addInitArray(ctxt *Link) *peSection { init_entry := ctxt.Syms.Lookup(*flagEntrySymbol, 0) addr := uint64(init_entry.Value) - init_entry.Sect.Vaddr switch objabi.GOARCH { - case "386": + case "386", "arm": ctxt.Out.Write32(uint32(addr)) case "amd64": ctxt.Out.Write64(addr) @@ -592,6 +607,8 @@ dwarfLoop: ctxt.Out.Write16(IMAGE_REL_I386_DIR32) case "amd64": ctxt.Out.Write16(IMAGE_REL_AMD64_ADDR64) + case "arm": + ctxt.Out.Write16(IMAGE_REL_ARM_ADDR32) } return 1 }) @@ -743,6 +760,8 @@ func (f *peFile) writeFileHeader(arch *sys.Arch, out *OutBuf, linkmode LinkMode) fh.Machine = IMAGE_FILE_MACHINE_AMD64 case sys.I386: fh.Machine = IMAGE_FILE_MACHINE_I386 + case sys.ARM: + fh.Machine = IMAGE_FILE_MACHINE_ARMNT } fh.NumberOfSections = uint16(len(f.sections)) @@ -754,7 +773,14 @@ func (f *peFile) writeFileHeader(arch *sys.Arch, out *OutBuf, linkmode LinkMode) if linkmode == LinkExternal { fh.Characteristics = IMAGE_FILE_LINE_NUMS_STRIPPED } else { - fh.Characteristics = IMAGE_FILE_RELOCS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DEBUG_STRIPPED + switch arch.Family { + default: + Exitf("write COFF(ext): unknown PE architecture: %v", arch.Family) + case sys.AMD64, sys.I386: + fh.Characteristics = IMAGE_FILE_RELOCS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DEBUG_STRIPPED + case sys.ARM: + fh.Characteristics = IMAGE_FILE_EXECUTABLE_IMAGE | IMAGE_FILE_DEBUG_STRIPPED + } } if pe64 != 0 { var oh64 pe.OptionalHeader64 @@ -831,6 +857,12 @@ func (f *peFile) writeOptionalHeader(ctxt *Link) { oh.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI } + switch ctxt.Arch.Family { + case sys.ARM: + oh64.DllCharacteristics = IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE | IMAGE_DLLCHARACTERISTICS_NX_COMPAT + oh.DllCharacteristics = IMAGE_DLLCHARACTERISTICS_DYNAMIC_BASE | IMAGE_DLLCHARACTERISTICS_NX_COMPAT + } + // Disable stack growth as we don't want Windows to // fiddle with the thread stack limits, which we set // ourselves to circumvent the stack checks in the @@ -1271,6 +1303,162 @@ func addexports(ctxt *Link) { sect.pad(out, uint32(size)) } +// peBaseRelocEntry represents a single relocation entry. +type peBaseRelocEntry struct { + typeOff uint16 + rel *sym.Reloc + sym *sym.Symbol // For debug +} + +// peBaseRelocBlock represents a Base Relocation Block. A block +// is a collection of relocation entries in a page, where each +// entry describes a single relocation. +// The block page RVA (Relative Virtual Address) is the index +// into peBaseRelocTable.blocks. +type peBaseRelocBlock struct { + entries []peBaseRelocEntry +} + +// pePages is a type used to store the list of pages for which there +// are base relocation blocks. This is defined as a type so that +// it can be sorted. +type pePages []uint32 + +func (p pePages) Len() int { return len(p) } +func (p pePages) Swap(i, j int) { p[i], p[j] = p[j], p[i] } +func (p pePages) Less(i, j int) bool { return p[i] < p[j] } + +// A PE base relocation table is a list of blocks, where each block +// contains relocation information for a single page. The blocks +// must be emitted in order of page virtual address. +// See https://docs.microsoft.com/en-us/windows/desktop/debug/pe-format#the-reloc-section-image-only +type peBaseRelocTable struct { + blocks map[uint32]peBaseRelocBlock + + // pePages is a list of keys into blocks map. + // It is stored separately for ease of sorting. + pages pePages +} + +func (rt *peBaseRelocTable) init(ctxt *Link) { + rt.blocks = make(map[uint32]peBaseRelocBlock) +} + +func (rt *peBaseRelocTable) addentry(ctxt *Link, s *sym.Symbol, r *sym.Reloc) { + // pageSize is the size in bytes of a page + // described by a base relocation block. + const pageSize = 0x1000 + const pageMask = pageSize - 1 + + addr := s.Value + int64(r.Off) - int64(PEBASE) + page := uint32(addr &^ pageMask) + off := uint32(addr & pageMask) + + b, ok := rt.blocks[page] + if !ok { + rt.pages = append(rt.pages, page) + } + + e := peBaseRelocEntry{ + typeOff: uint16(off & 0xFFF), + rel: r, + sym: s, + } + + // Set entry type + switch r.Siz { + default: + Exitf("unsupported relocation size %d\n", r.Siz) + case 4: + e.typeOff |= uint16(IMAGE_REL_BASED_HIGHLOW << 12) + } + + b.entries = append(b.entries, e) + rt.blocks[page] = b +} + +func (rt *peBaseRelocTable) write(ctxt *Link) { + out := ctxt.Out + + // sort the pages array + sort.Sort(rt.pages) + + for _, p := range rt.pages { + b := rt.blocks[p] + const sizeOfPEbaseRelocBlock = 8 // 2 * sizeof(uint32) + blockSize := uint32(sizeOfPEbaseRelocBlock + len(b.entries)*2) + out.Write32(p) + out.Write32(blockSize) + + for _, e := range b.entries { + out.Write16(e.typeOff) + } + } +} + +func addPEBaseRelocSym(ctxt *Link, s *sym.Symbol, rt *peBaseRelocTable) { + for ri := 0; ri < len(s.R); ri++ { + r := &s.R[ri] + + if r.Sym == nil { + continue + } + if !r.Sym.Attr.Reachable() { + continue + } + if r.Type >= 256 { + continue + } + if r.Siz == 0 { // informational relocation + continue + } + if r.Type == objabi.R_DWARFFILEREF { + continue + } + + switch r.Type { + default: + case objabi.R_ADDR: + rt.addentry(ctxt, s, r) + } + } +} + +func addPEBaseReloc(ctxt *Link) { + // We only generate base relocation table for ARM (and ... ARM64), x86, and AMD64 are marked as legacy + // archs and can use fixed base with no base relocation information + switch ctxt.Arch.Family { + default: + return + case sys.ARM: + } + + var rt peBaseRelocTable + rt.init(ctxt) + + // Get relocation information + for _, s := range ctxt.Textp { + addPEBaseRelocSym(ctxt, s, &rt) + } + for _, s := range datap { + addPEBaseRelocSym(ctxt, s, &rt) + } + + // Write relocation information + startoff := ctxt.Out.Offset() + rt.write(ctxt) + size := ctxt.Out.Offset() - startoff + + // Add a PE section and pad it at the end + rsect := pefile.addSection(".reloc", int(size), int(size)) + rsect.characteristics = IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_DISCARDABLE + rsect.checkOffset(startoff) + rsect.pad(ctxt.Out, uint32(size)) + + pefile.dataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress = rsect.virtualAddress + pefile.dataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = rsect.virtualSize +} + func (ctxt *Link) dope() { /* relocation table */ rel := ctxt.Syms.Lookup(".rel", 0) @@ -1326,7 +1514,7 @@ func Asmbpe(ctxt *Link) { switch ctxt.Arch.Family { default: Exitf("unknown PE architecture: %v", ctxt.Arch.Family) - case sys.AMD64, sys.I386: + case sys.AMD64, sys.I386, sys.ARM: } t := pefile.addSection(".text", int(Segtext.Length), int(Segtext.Length)) @@ -1380,6 +1568,7 @@ func Asmbpe(ctxt *Link) { if ctxt.LinkMode != LinkExternal { addimports(ctxt, d) addexports(ctxt) + addPEBaseReloc(ctxt) } pefile.writeSymbolTableAndStringTable(ctxt) addpersrc(ctxt) diff --git a/src/cmd/link/internal/loadpe/ldpe.go b/src/cmd/link/internal/loadpe/ldpe.go index c8fae3789839e..f78252c283a34 100644 --- a/src/cmd/link/internal/loadpe/ldpe.go +++ b/src/cmd/link/internal/loadpe/ldpe.go @@ -101,6 +101,19 @@ const ( IMAGE_REL_AMD64_SREL32 = 0x000E IMAGE_REL_AMD64_PAIR = 0x000F IMAGE_REL_AMD64_SSPAN32 = 0x0010 + IMAGE_REL_ARM_ABSOLUTE = 0x0000 + IMAGE_REL_ARM_ADDR32 = 0x0001 + IMAGE_REL_ARM_ADDR32NB = 0x0002 + IMAGE_REL_ARM_BRANCH24 = 0x0003 + IMAGE_REL_ARM_BRANCH11 = 0x0004 + IMAGE_REL_ARM_SECTION = 0x000E + IMAGE_REL_ARM_SECREL = 0x000F + IMAGE_REL_ARM_MOV32 = 0x0010 + IMAGE_REL_THUMB_MOV32 = 0x0011 + IMAGE_REL_THUMB_BRANCH20 = 0x0012 + IMAGE_REL_THUMB_BRANCH24 = 0x0014 + IMAGE_REL_THUMB_BLX23 = 0x0015 + IMAGE_REL_ARM_PAIR = 0x0016 ) // TODO(crawshaw): de-duplicate these symbols with cmd/internal/ld, ideally in debug/pe. @@ -241,30 +254,56 @@ func Load(arch *sys.Arch, syms *sym.Symbols, input *bio.Reader, pkg string, leng rp.Sym = gosym rp.Siz = 4 rp.Off = int32(r.VirtualAddress) - switch r.Type { + switch arch.Family { default: - return nil, nil, fmt.Errorf("%s: %v: unknown relocation type %v", pn, sectsyms[rsect], r.Type) + return nil, nil, fmt.Errorf("%s: unsupported arch %v", pn, arch.Family) + case sys.I386, sys.AMD64: + switch r.Type { + default: + return nil, nil, fmt.Errorf("%s: %v: unknown relocation type %v", pn, sectsyms[rsect], r.Type) - case IMAGE_REL_I386_REL32, IMAGE_REL_AMD64_REL32, - IMAGE_REL_AMD64_ADDR32, // R_X86_64_PC32 - IMAGE_REL_AMD64_ADDR32NB: - rp.Type = objabi.R_PCREL + case IMAGE_REL_I386_REL32, IMAGE_REL_AMD64_REL32, + IMAGE_REL_AMD64_ADDR32, // R_X86_64_PC32 + IMAGE_REL_AMD64_ADDR32NB: + rp.Type = objabi.R_PCREL - rp.Add = int64(int32(binary.LittleEndian.Uint32(sectdata[rsect][rp.Off:]))) + rp.Add = int64(int32(binary.LittleEndian.Uint32(sectdata[rsect][rp.Off:]))) - case IMAGE_REL_I386_DIR32NB, IMAGE_REL_I386_DIR32: - rp.Type = objabi.R_ADDR + case IMAGE_REL_I386_DIR32NB, IMAGE_REL_I386_DIR32: + rp.Type = objabi.R_ADDR - // load addend from image - rp.Add = int64(int32(binary.LittleEndian.Uint32(sectdata[rsect][rp.Off:]))) + // load addend from image + rp.Add = int64(int32(binary.LittleEndian.Uint32(sectdata[rsect][rp.Off:]))) - case IMAGE_REL_AMD64_ADDR64: // R_X86_64_64 - rp.Siz = 8 + case IMAGE_REL_AMD64_ADDR64: // R_X86_64_64 + rp.Siz = 8 - rp.Type = objabi.R_ADDR + rp.Type = objabi.R_ADDR - // load addend from image - rp.Add = int64(binary.LittleEndian.Uint64(sectdata[rsect][rp.Off:])) + // load addend from image + rp.Add = int64(binary.LittleEndian.Uint64(sectdata[rsect][rp.Off:])) + } + + case sys.ARM: + switch r.Type { + default: + return nil, nil, fmt.Errorf("%s: %v: unknown ARM relocation type %v", pn, sectsyms[rsect], r.Type) + + case IMAGE_REL_ARM_SECREL: + rp.Type = objabi.R_PCREL + + rp.Add = int64(int32(binary.LittleEndian.Uint32(sectdata[rsect][rp.Off:]))) + + case IMAGE_REL_ARM_ADDR32: + rp.Type = objabi.R_ADDR + + rp.Add = int64(int32(binary.LittleEndian.Uint32(sectdata[rsect][rp.Off:]))) + + case IMAGE_REL_ARM_BRANCH24: + rp.Type = objabi.R_CALLARM + + rp.Add = int64(int32(binary.LittleEndian.Uint32(sectdata[rsect][rp.Off:]))) + } } // ld -r could generate multiple section symbols for the From 1ae2eed0b22023cc06ad7f1a82d2df2b6877b14b Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Wed, 31 Jan 2018 20:40:34 -0800 Subject: [PATCH 0103/1663] math: test for pos/neg zero return of Ceil/Floor/Trunc Ceil and Trunc of -0.2 return -0, not +0, but we didn't test that. Updates #23647 Change-Id: Idbd4699376abfb4ca93f16c73c114d610d86a9f2 Reviewed-on: https://go-review.googlesource.com/91335 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/math/all_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/math/all_test.go b/src/math/all_test.go index bcc20a3917680..00f2058ea68b1 100644 --- a/src/math/all_test.go +++ b/src/math/all_test.go @@ -128,7 +128,7 @@ var cbrt = []float64{ var ceil = []float64{ 5.0000000000000000e+00, 8.0000000000000000e+00, - 0.0000000000000000e+00, + Copysign(0, -1), -5.0000000000000000e+00, 1.0000000000000000e+01, 3.0000000000000000e+00, @@ -644,7 +644,7 @@ var tanh = []float64{ var trunc = []float64{ 4.0000000000000000e+00, 7.0000000000000000e+00, - -0.0000000000000000e+00, + Copysign(0, -1), -5.0000000000000000e+00, 9.0000000000000000e+00, 2.0000000000000000e+00, @@ -2158,7 +2158,7 @@ func TestCbrt(t *testing.T) { func TestCeil(t *testing.T) { for i := 0; i < len(vf); i++ { - if f := Ceil(vf[i]); ceil[i] != f { + if f := Ceil(vf[i]); !alike(ceil[i], f) { t.Errorf("Ceil(%g) = %g, want %g", vf[i], f, ceil[i]) } } @@ -2385,7 +2385,7 @@ func TestDim(t *testing.T) { func TestFloor(t *testing.T) { for i := 0; i < len(vf); i++ { - if f := Floor(vf[i]); floor[i] != f { + if f := Floor(vf[i]); !alike(floor[i], f) { t.Errorf("Floor(%g) = %g, want %g", vf[i], f, floor[i]) } } @@ -2916,7 +2916,7 @@ func TestTanh(t *testing.T) { func TestTrunc(t *testing.T) { for i := 0; i < len(vf); i++ { - if f := Trunc(vf[i]); trunc[i] != f { + if f := Trunc(vf[i]); !alike(trunc[i], f) { t.Errorf("Trunc(%g) = %g, want %g", vf[i], f, trunc[i]) } } From 2ce8411239212b80a0d266dc123bb5b1ec84d211 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Sun, 24 Jun 2018 13:42:59 +0200 Subject: [PATCH 0104/1663] time: accept anything between -23 and 23 as offset namezone name time.Parse currently rejects numeric timezones names with UTC offsets bigger than +12, but this is incorrect: there's a +13 timezone and a +14 timezone: $ zdump Pacific/Kiritimati Pacific/Kiritimati Mon Jun 25 02:15:03 2018 +14 For convenience, this cl changes the ranges of accepted offsets from -14..+12 to -23..+23 (zero still excluded), i.e. every possible offset that makes sense. We don't validate three-letter abbreviations for the timezones names, so there's no need to be too strict on numeric names. This change also fixes a bug in the parseTimeZone, that is currently unconditionally returning true (i.e. valid timezone), without checking the value returned by parseSignedOffset. This fixes 5 of 17 time.Parse() failures listed in Issue #26032. Updates #26032 Change-Id: I2f08ca9aa41ea4c6149ed35ed2dd8f23eeb42bff Reviewed-on: https://go-review.googlesource.com/120558 Reviewed-by: Rob Pike --- src/time/format.go | 9 +++++---- src/time/format_test.go | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/time/format.go b/src/time/format.go index 237f28738b5d2..f9cdbab3b8f31 100644 --- a/src/time/format.go +++ b/src/time/format.go @@ -1120,7 +1120,8 @@ func parseTimeZone(value string) (length int, ok bool) { // Special Case 3: Some time zones are not named, but have +/-00 format if value[0] == '+' || value[0] == '-' { length = parseSignedOffset(value) - return length, true + ok := length > 0 // parseSignedOffset returns 0 in case of bad input + return length, ok } // How many upper-case letters are there? Need at least three, at most five. var nUpper int @@ -1152,7 +1153,7 @@ func parseTimeZone(value string) (length int, ok bool) { // parseGMT parses a GMT time zone. The input string is known to start "GMT". // The function checks whether that is followed by a sign and a number in the -// range -14 through 12 excluding zero. +// range -23 through +23 excluding zero. func parseGMT(value string) int { value = value[3:] if len(value) == 0 { @@ -1163,7 +1164,7 @@ func parseGMT(value string) int { } // parseSignedOffset parses a signed timezone offset (e.g. "+03" or "-04"). -// The function checks for a signed number in the range -14 through +12 excluding zero. +// The function checks for a signed number in the range -23 through +23 excluding zero. // Returns length of the found offset string or 0 otherwise func parseSignedOffset(value string) int { sign := value[0] @@ -1177,7 +1178,7 @@ func parseSignedOffset(value string) int { if sign == '-' { x = -x } - if x == 0 || x < -14 || 12 < x { + if x == 0 || x < -23 || 23 < x { return 0 } return len(value) - len(rem) diff --git a/src/time/format_test.go b/src/time/format_test.go index 68a4d3ddb0e89..c3552f4161361 100644 --- a/src/time/format_test.go +++ b/src/time/format_test.go @@ -427,8 +427,18 @@ var parseTimeZoneTests = []ParseTimeZoneTest{ {"ESASTT hi", 0, false}, // run of upper-case letters too long. {"ESATY hi", 0, false}, // five letters must end in T. {"WITA hi", 4, true}, // Issue #18251 - {"+03 hi", 3, true}, // Issue #24071 - {"-04 hi", 3, true}, // Issue #24071 + // Issue #24071 + {"+03 hi", 3, true}, + {"-04 hi", 3, true}, + // Issue #26032 + {"-11", 3, true}, + {"-12", 3, true}, + {"-23", 3, true}, + {"-24", 0, false}, + {"+13", 3, true}, + {"+14", 3, true}, + {"+23", 3, true}, + {"+24", 0, false}, } func TestParseTimeZone(t *testing.T) { From d2ace0ce5f764a5bfb2c82975a2614c97d569cd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Tue, 21 Aug 2018 05:09:24 +0000 Subject: [PATCH 0105/1663] cmd/cgo: perform explicit conversion in _GoStringLen _GoStringLen performs an implicit conversion from intgo to size_t. Explicitly cast to size_t. This change avoids warnings when using cgo with CFLAGS: -Wconversion. Change-Id: I58f75a35e17f669a67f9805061c041b03eddbb5c GitHub-Last-Rev: b5df1ac0c3c90360fa1d22c069e0f126e9f894d8 GitHub-Pull-Request: golang/go#27092 Reviewed-on: https://go-review.googlesource.com/129820 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/cgo/out.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/cgo/out.go b/src/cmd/cgo/out.go index 89598c96e8300..6217bb17a388a 100644 --- a/src/cmd/cgo/out.go +++ b/src/cmd/cgo/out.go @@ -1432,7 +1432,7 @@ void *CBytes(_GoBytes_); void *_CMalloc(size_t); __attribute__ ((unused)) -static size_t _GoStringLen(_GoString_ s) { return s.n; } +static size_t _GoStringLen(_GoString_ s) { return (size_t)s.n; } __attribute__ ((unused)) static const char *_GoStringPtr(_GoString_ s) { return s.p; } From 45c7d80832dcb93239a1bd48ad7c8328ac6f0532 Mon Sep 17 00:00:00 2001 From: Michael Fraenkel Date: Mon, 9 Jul 2018 22:37:59 -0400 Subject: [PATCH 0106/1663] strings: use Builder in Map MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a builder to avoid the copy when converting the []byte to a string. name old time/op new time/op delta ByteByteMap-8 796ns ± 5% 700ns ± 1% -12.00% (p=0.000 n=9+8) Map/identity/ASCII-8 123ns ± 8% 126ns ± 7% ~ (p=0.194 n=10+10) Map/identity/Greek-8 198ns ± 2% 204ns ± 5% +2.99% (p=0.008 n=9+10) Map/change/ASCII-8 266ns ±10% 202ns ± 3% -24.19% (p=0.000 n=10+10) Map/change/Greek-8 450ns ± 4% 406ns ± 1% -9.73% (p=0.000 n=9+10) MapNoChanges-8 85.4ns ± 3% 90.2ns ±11% +5.67% (p=0.000 n=9+10) name old alloc/op new alloc/op delta ByteByteMap-8 416B ± 0% 208B ± 0% -50.00% (p=0.000 n=10+10) Map/identity/ASCII-8 0.00B 0.00B ~ (all equal) Map/identity/Greek-8 0.00B 0.00B ~ (all equal) Map/change/ASCII-8 128B ± 0% 64B ± 0% -50.00% (p=0.000 n=10+10) Map/change/Greek-8 160B ± 0% 80B ± 0% -50.00% (p=0.000 n=10+10) MapNoChanges-8 0.00B 0.00B ~ (all equal) name old allocs/op new allocs/op delta ByteByteMap-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) Map/identity/ASCII-8 0.00 0.00 ~ (all equal) Map/identity/Greek-8 0.00 0.00 ~ (all equal) Map/change/ASCII-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) Map/change/Greek-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) MapNoChanges-8 0.00 0.00 ~ (all equal) Fixes #26304 Change-Id: Ideec9dfc29b0b8107f34fc634247081d0031777d Reviewed-on: https://go-review.googlesource.com/122875 Reviewed-by: Brad Fitzpatrick --- src/strings/strings.go | 42 +++++++++++++------------------------ src/strings/strings_test.go | 13 ++++++++++++ 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/src/strings/strings.go b/src/strings/strings.go index 9e7d4f0455982..e54f0c2bfa762 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -466,9 +466,7 @@ func Map(mapping func(rune) rune, s string) string { // The output buffer b is initialized on demand, the first // time a character differs. - var b []byte - // nbytes is the number of bytes encoded in b. - var nbytes int + var b Builder for i, c := range s { r := mapping(c) @@ -476,15 +474,10 @@ func Map(mapping func(rune) rune, s string) string { continue } - b = make([]byte, len(s)+utf8.UTFMax) - nbytes = copy(b, s[:i]) + b.Grow(len(s) + utf8.UTFMax) + b.WriteString(s[:i]) if r >= 0 { - if r < utf8.RuneSelf { - b[nbytes] = byte(r) - nbytes++ - } else { - nbytes += utf8.EncodeRune(b[nbytes:], r) - } + b.WriteRune(r) } if c == utf8.RuneError { @@ -501,33 +494,28 @@ func Map(mapping func(rune) rune, s string) string { break } - if b == nil { + // Fast path for unchanged input + if b.Cap() == 0 { // didn't call b.Grow above return s } for _, c := range s { r := mapping(c) - // common case - if (0 <= r && r < utf8.RuneSelf) && nbytes < len(b) { - b[nbytes] = byte(r) - nbytes++ - continue - } - - // b is not big enough or r is not a ASCII rune. if r >= 0 { - if nbytes+utf8.UTFMax >= len(b) { - // Grow the buffer. - nb := make([]byte, 2*len(b)) - copy(nb, b[:nbytes]) - b = nb + // common case + // Due to inlining, it is more performant to determine if WriteByte should be + // invoked rather than always call WriteRune + if r < utf8.RuneSelf { + b.WriteByte(byte(r)) + } else { + // r is not a ASCII rune. + b.WriteRune(r) } - nbytes += utf8.EncodeRune(b[nbytes:], r) } } - return string(b[:nbytes]) + return b.String() } // Repeat returns a new string consisting of count copies of the string s. diff --git a/src/strings/strings_test.go b/src/strings/strings_test.go index 78bc573e5f0bf..bb46e136f26bc 100644 --- a/src/strings/strings_test.go +++ b/src/strings/strings_test.go @@ -673,6 +673,19 @@ func TestMap(t *testing.T) { if m != s { t.Errorf("encoding not handled correctly: expected %q got %q", s, m) } + + // 9. Check mapping occurs in the front, middle and back + trimSpaces := func(r rune) rune { + if unicode.IsSpace(r) { + return -1 + } + return r + } + m = Map(trimSpaces, " abc 123 ") + expect = "abc123" + if m != expect { + t.Errorf("trimSpaces: expected %q got %q", expect, m) + } } func TestToUpper(t *testing.T) { runStringTests(t, ToUpper, "ToUpper", upperTests) } From 64f3d75bc288679e9e18cb9513897e7139f3fc3b Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 21 Aug 2018 07:54:04 +0000 Subject: [PATCH 0107/1663] crypto/rand: use the new getrandom syscall on FreeBSD Since the 12.x branch, the getrandom syscall had been introduced with similar interface as Linux's and consistent syscall id across architectures. Change-Id: I63d6b45dbe9e29f07f1b5b6c2ec8be4fa624b9ee GitHub-Last-Rev: 6fb76e6522ef5ccb96d02445ffa39796dae89016 GitHub-Pull-Request: golang/go#25976 Reviewed-on: https://go-review.googlesource.com/120055 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/crypto/rand/rand.go | 2 +- src/crypto/rand/rand_batched.go | 42 +++++++++++++++ ...and_linux_test.go => rand_batched_test.go} | 2 + src/crypto/rand/rand_freebsd.go | 9 ++++ src/crypto/rand/rand_linux.go | 34 ------------- .../syscall/unix/getrandom_freebsd.go | 51 +++++++++++++++++++ .../syscall/unix/getrandom_linux_generic.go | 2 +- 7 files changed, 106 insertions(+), 36 deletions(-) create mode 100644 src/crypto/rand/rand_batched.go rename src/crypto/rand/{rand_linux_test.go => rand_batched_test.go} (97%) create mode 100644 src/crypto/rand/rand_freebsd.go create mode 100644 src/internal/syscall/unix/getrandom_freebsd.go diff --git a/src/crypto/rand/rand.go b/src/crypto/rand/rand.go index b8df8a3711705..952d20aa16d7c 100644 --- a/src/crypto/rand/rand.go +++ b/src/crypto/rand/rand.go @@ -11,7 +11,7 @@ import "io" // Reader is a global, shared instance of a cryptographically // secure random number generator. // -// On Linux, Reader uses getrandom(2) if available, /dev/urandom otherwise. +// On Linux and FreeBSD, Reader uses getrandom(2) if available, /dev/urandom otherwise. // On OpenBSD, Reader uses getentropy(2). // On other Unix-like systems, Reader reads from /dev/urandom. // On Windows systems, Reader uses the CryptGenRandom API. diff --git a/src/crypto/rand/rand_batched.go b/src/crypto/rand/rand_batched.go new file mode 100644 index 0000000000000..60267fd4bc229 --- /dev/null +++ b/src/crypto/rand/rand_batched.go @@ -0,0 +1,42 @@ +// Copyright 2014 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. + +// +build linux freebsd + +package rand + +import ( + "internal/syscall/unix" +) + +// maxGetRandomRead is platform dependent. +func init() { + altGetRandom = batched(getRandomBatch, maxGetRandomRead) +} + +// batched returns a function that calls f to populate a []byte by chunking it +// into subslices of, at most, readMax bytes. +func batched(f func([]byte) bool, readMax int) func([]byte) bool { + return func(buf []byte) bool { + for len(buf) > readMax { + if !f(buf[:readMax]) { + return false + } + buf = buf[readMax:] + } + return len(buf) == 0 || f(buf) + } +} + +// If the kernel is too old to support the getrandom syscall(), +// unix.GetRandom will immediately return ENOSYS and we will then fall back to +// reading from /dev/urandom in rand_unix.go. unix.GetRandom caches the ENOSYS +// result so we only suffer the syscall overhead once in this case. +// If the kernel supports the getrandom() syscall, unix.GetRandom will block +// until the kernel has sufficient randomness (as we don't use GRND_NONBLOCK). +// In this case, unix.GetRandom will not return an error. +func getRandomBatch(p []byte) (ok bool) { + n, err := unix.GetRandom(p, 0) + return n == len(p) && err == nil +} diff --git a/src/crypto/rand/rand_linux_test.go b/src/crypto/rand/rand_batched_test.go similarity index 97% rename from src/crypto/rand/rand_linux_test.go rename to src/crypto/rand/rand_batched_test.go index 77b7b6ebd7a7b..837db83f77084 100644 --- a/src/crypto/rand/rand_linux_test.go +++ b/src/crypto/rand/rand_batched_test.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build linux freebsd + package rand import ( diff --git a/src/crypto/rand/rand_freebsd.go b/src/crypto/rand/rand_freebsd.go new file mode 100644 index 0000000000000..b4d6653343ac4 --- /dev/null +++ b/src/crypto/rand/rand_freebsd.go @@ -0,0 +1,9 @@ +// Copyright 2018 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. + +package rand + +// maxGetRandomRead is the maximum number of bytes to ask for in one call to the +// getrandom() syscall. In FreeBSD at most 256 bytes will be returned per call. +const maxGetRandomRead = (1 << 8) diff --git a/src/crypto/rand/rand_linux.go b/src/crypto/rand/rand_linux.go index dbd038cc58241..26b93c54d286b 100644 --- a/src/crypto/rand/rand_linux.go +++ b/src/crypto/rand/rand_linux.go @@ -4,14 +4,6 @@ package rand -import ( - "internal/syscall/unix" -) - -func init() { - altGetRandom = batched(getRandomLinux, maxGetRandomRead) -} - // maxGetRandomRead is the maximum number of bytes to ask for in one call to the // getrandom() syscall. In linux at most 2^25-1 bytes will be returned per call. // From the manpage @@ -20,29 +12,3 @@ func init() { // is returned by a single call to getrandom() on systems where int // has a size of 32 bits. const maxGetRandomRead = (1 << 25) - 1 - -// batched returns a function that calls f to populate a []byte by chunking it -// into subslices of, at most, readMax bytes. -func batched(f func([]byte) bool, readMax int) func([]byte) bool { - return func(buf []byte) bool { - for len(buf) > readMax { - if !f(buf[:readMax]) { - return false - } - buf = buf[readMax:] - } - return len(buf) == 0 || f(buf) - } -} - -// If the kernel is too old (before 3.17) to support the getrandom syscall(), -// unix.GetRandom will immediately return ENOSYS and we will then fall back to -// reading from /dev/urandom in rand_unix.go. unix.GetRandom caches the ENOSYS -// result so we only suffer the syscall overhead once in this case. -// If the kernel supports the getrandom() syscall, unix.GetRandom will block -// until the kernel has sufficient randomness (as we don't use GRND_NONBLOCK). -// In this case, unix.GetRandom will not return an error. -func getRandomLinux(p []byte) (ok bool) { - n, err := unix.GetRandom(p, 0) - return n == len(p) && err == nil -} diff --git a/src/internal/syscall/unix/getrandom_freebsd.go b/src/internal/syscall/unix/getrandom_freebsd.go new file mode 100644 index 0000000000000..fc241f23457c2 --- /dev/null +++ b/src/internal/syscall/unix/getrandom_freebsd.go @@ -0,0 +1,51 @@ +// Copyright 2018 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. + +package unix + +import ( + "sync/atomic" + "syscall" + "unsafe" +) + +var randomUnsupported int32 // atomic + +// FreeBSD getrandom system call number. +const randomTrap uintptr = 563 + +// GetRandomFlag is a flag supported by the getrandom system call. +type GetRandomFlag uintptr + +const ( + // GRND_NONBLOCK means return EAGAIN rather than blocking. + GRND_NONBLOCK GetRandomFlag = 0x0001 + + // GRND_RANDOM is only set for portability purpose, no-op on FreeBSD. + GRND_RANDOM GetRandomFlag = 0x0002 +) + +// GetRandom calls the FreeBSD getrandom system call. +func GetRandom(p []byte, flags GetRandomFlag) (n int, err error) { + if randomTrap == 0 { + return 0, syscall.ENOSYS + } + if len(p) == 0 { + return 0, nil + } + if atomic.LoadInt32(&randomUnsupported) != 0 { + return 0, syscall.ENOSYS + } + r1, _, errno := syscall.Syscall(randomTrap, + uintptr(unsafe.Pointer(&p[0])), + uintptr(len(p)), + uintptr(flags)) + if errno != 0 { + if errno == syscall.ENOSYS { + atomic.StoreInt32(&randomUnsupported, 1) + } + return 0, errno + } + return int(r1), nil +} diff --git a/src/internal/syscall/unix/getrandom_linux_generic.go b/src/internal/syscall/unix/getrandom_linux_generic.go index 8425800b6da84..f8490ce97857c 100644 --- a/src/internal/syscall/unix/getrandom_linux_generic.go +++ b/src/internal/syscall/unix/getrandom_linux_generic.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build arm64 +// +build linux,arm64 package unix From 705f3c74e6af802fcf54f402e6d0862832249712 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 21 Jun 2018 10:14:18 +0000 Subject: [PATCH 0108/1663] cmd/compile: optimize AMD64 with DIVSSload and DIVSDload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit DIVSSload & DIVSDload directly operate on a memory operand. And binary size can be reduced by them, while the performance is not affected. The total size of pkg/linux_amd64 (excluding cmd/compile) decreases about 6KB. There is little regression in the go1 benchmark test (excluding noise). name old time/op new time/op delta BinaryTree17-4 2.63s ± 4% 2.62s ± 4% ~ (p=0.809 n=30+30) Fannkuch11-4 2.40s ± 2% 2.40s ± 2% ~ (p=0.109 n=30+30) FmtFprintfEmpty-4 43.1ns ± 4% 43.2ns ± 9% ~ (p=0.168 n=30+30) FmtFprintfString-4 73.6ns ± 4% 74.1ns ± 4% ~ (p=0.069 n=30+30) FmtFprintfInt-4 81.0ns ± 3% 81.4ns ± 5% ~ (p=0.350 n=30+30) FmtFprintfIntInt-4 127ns ± 4% 129ns ± 4% +0.99% (p=0.021 n=30+30) FmtFprintfPrefixedInt-4 156ns ± 4% 155ns ± 4% ~ (p=0.415 n=30+30) FmtFprintfFloat-4 219ns ± 4% 218ns ± 4% ~ (p=0.071 n=30+30) FmtManyArgs-4 522ns ± 3% 518ns ± 3% -0.68% (p=0.034 n=30+30) GobDecode-4 6.49ms ± 6% 6.52ms ± 6% ~ (p=0.832 n=30+30) GobEncode-4 6.10ms ± 9% 6.14ms ± 7% ~ (p=0.485 n=30+30) Gzip-4 227ms ± 1% 224ms ± 4% ~ (p=0.484 n=24+30) Gunzip-4 37.2ms ± 3% 36.8ms ± 4% ~ (p=0.889 n=30+30) HTTPClientServer-4 58.9µs ± 1% 58.7µs ± 2% -0.42% (p=0.003 n=28+28) JSONEncode-4 12.0ms ± 3% 12.0ms ± 4% ~ (p=0.523 n=30+30) JSONDecode-4 54.6ms ± 4% 54.5ms ± 4% ~ (p=0.708 n=30+30) Mandelbrot200-4 3.78ms ± 4% 3.81ms ± 3% +0.99% (p=0.016 n=30+30) GoParse-4 3.20ms ± 4% 3.20ms ± 5% ~ (p=0.994 n=30+30) RegexpMatchEasy0_32-4 77.0ns ± 4% 75.9ns ± 3% -1.39% (p=0.006 n=29+30) RegexpMatchEasy0_1K-4 255ns ± 4% 253ns ± 4% ~ (p=0.091 n=30+30) RegexpMatchEasy1_32-4 69.7ns ± 3% 70.3ns ± 4% ~ (p=0.120 n=30+30) RegexpMatchEasy1_1K-4 373ns ± 2% 378ns ± 3% +1.43% (p=0.000 n=21+26) RegexpMatchMedium_32-4 107ns ± 2% 108ns ± 4% +1.50% (p=0.012 n=22+30) RegexpMatchMedium_1K-4 34.0µs ± 1% 34.3µs ± 3% +1.08% (p=0.008 n=24+30) RegexpMatchHard_32-4 1.53µs ± 3% 1.54µs ± 3% ~ (p=0.234 n=30+30) RegexpMatchHard_1K-4 46.7µs ± 4% 47.0µs ± 4% ~ (p=0.420 n=30+30) Revcomp-4 411ms ± 7% 415ms ± 6% ~ (p=0.059 n=30+30) Template-4 65.5ms ± 5% 66.9ms ± 4% +2.21% (p=0.001 n=30+30) TimeParse-4 317ns ± 3% 311ns ± 3% -1.97% (p=0.000 n=30+30) TimeFormat-4 293ns ± 3% 294ns ± 3% ~ (p=0.243 n=30+30) [Geo mean] 47.4µs 47.5µs +0.17% name old speed new speed delta GobDecode-4 118MB/s ± 5% 118MB/s ± 6% ~ (p=0.832 n=30+30) GobEncode-4 125MB/s ± 7% 125MB/s ± 7% ~ (p=0.625 n=29+30) Gzip-4 85.3MB/s ± 1% 86.6MB/s ± 4% ~ (p=0.486 n=24+30) Gunzip-4 522MB/s ± 3% 527MB/s ± 4% ~ (p=0.889 n=30+30) JSONEncode-4 162MB/s ± 3% 162MB/s ± 4% ~ (p=0.520 n=30+30) JSONDecode-4 35.5MB/s ± 4% 35.6MB/s ± 4% ~ (p=0.701 n=30+30) GoParse-4 18.1MB/s ± 4% 18.1MB/s ± 4% ~ (p=0.891 n=29+30) RegexpMatchEasy0_32-4 416MB/s ± 4% 422MB/s ± 3% +1.43% (p=0.005 n=29+30) RegexpMatchEasy0_1K-4 4.01GB/s ± 4% 4.04GB/s ± 4% ~ (p=0.091 n=30+30) RegexpMatchEasy1_32-4 460MB/s ± 3% 456MB/s ± 5% ~ (p=0.123 n=30+30) RegexpMatchEasy1_1K-4 2.74GB/s ± 2% 2.70GB/s ± 3% -1.33% (p=0.000 n=22+26) RegexpMatchMedium_32-4 9.39MB/s ± 3% 9.19MB/s ± 4% -2.06% (p=0.001 n=28+30) RegexpMatchMedium_1K-4 30.1MB/s ± 1% 29.8MB/s ± 3% -1.04% (p=0.008 n=24+30) RegexpMatchHard_32-4 20.9MB/s ± 3% 20.8MB/s ± 3% ~ (p=0.234 n=30+30) RegexpMatchHard_1K-4 21.9MB/s ± 4% 21.8MB/s ± 4% ~ (p=0.420 n=30+30) Revcomp-4 619MB/s ± 7% 612MB/s ± 7% ~ (p=0.059 n=30+30) Template-4 29.6MB/s ± 4% 29.0MB/s ± 4% -2.16% (p=0.002 n=30+30) [Geo mean] 123MB/s 123MB/s -0.33% Change-Id: Ia59e077feae4f2824df79059daea4d0f678e3e4c Reviewed-on: https://go-review.googlesource.com/120275 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Ilya Tocar --- src/cmd/compile/internal/amd64/ssa.go | 3 +- src/cmd/compile/internal/ssa/gen/AMD64.rules | 20 +-- src/cmd/compile/internal/ssa/gen/AMD64Ops.go | 2 + src/cmd/compile/internal/ssa/opGen.go | 38 ++++ src/cmd/compile/internal/ssa/rewriteAMD64.go | 178 +++++++++++++++++++ test/codegen/arithmetic.go | 5 + 6 files changed, 235 insertions(+), 11 deletions(-) diff --git a/src/cmd/compile/internal/amd64/ssa.go b/src/cmd/compile/internal/amd64/ssa.go index 584cc4c4bd552..4ecdb769f3a46 100644 --- a/src/cmd/compile/internal/amd64/ssa.go +++ b/src/cmd/compile/internal/amd64/ssa.go @@ -837,7 +837,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { case ssa.OpAMD64ADDQload, ssa.OpAMD64ADDLload, ssa.OpAMD64SUBQload, ssa.OpAMD64SUBLload, ssa.OpAMD64ANDQload, ssa.OpAMD64ANDLload, ssa.OpAMD64ORQload, ssa.OpAMD64ORLload, ssa.OpAMD64XORQload, ssa.OpAMD64XORLload, ssa.OpAMD64ADDSDload, ssa.OpAMD64ADDSSload, - ssa.OpAMD64SUBSDload, ssa.OpAMD64SUBSSload, ssa.OpAMD64MULSDload, ssa.OpAMD64MULSSload: + ssa.OpAMD64SUBSDload, ssa.OpAMD64SUBSSload, ssa.OpAMD64MULSDload, ssa.OpAMD64MULSSload, + ssa.OpAMD64DIVSDload, ssa.OpAMD64DIVSSload: p := s.Prog(v.Op.Asm()) p.From.Type = obj.TYPE_MEM p.From.Reg = v.Args[1].Reg() diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index bf3a11604595b..eab66d17abc34 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -1037,10 +1037,10 @@ ((ADD|SUB|AND|OR|XOR)Qload [off1+off2] {sym} val base mem) ((ADD|SUB|AND|OR|XOR)Lload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> ((ADD|SUB|AND|OR|XOR)Lload [off1+off2] {sym} val base mem) -((ADD|SUB|MUL)SSload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> - ((ADD|SUB|MUL)SSload [off1+off2] {sym} val base mem) -((ADD|SUB|MUL)SDload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> - ((ADD|SUB|MUL)SDload [off1+off2] {sym} val base mem) +((ADD|SUB|MUL|DIV)SSload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> + ((ADD|SUB|MUL|DIV)SSload [off1+off2] {sym} val base mem) +((ADD|SUB|MUL|DIV)SDload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> + ((ADD|SUB|MUL|DIV)SDload [off1+off2] {sym} val base mem) ((ADD|AND|OR|XOR)Qconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> ((ADD|AND|OR|XOR)Qconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) ((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> @@ -1079,12 +1079,12 @@ ((ADD|SUB|AND|OR|XOR)Lload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> ((ADD|SUB|AND|OR|XOR)Lload [off1+off2] {mergeSym(sym1,sym2)} val base mem) -((ADD|SUB|MUL)SSload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) +((ADD|SUB|MUL|DIV)SSload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> - ((ADD|SUB|MUL)SSload [off1+off2] {mergeSym(sym1,sym2)} val base mem) -((ADD|SUB|MUL)SDload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) + ((ADD|SUB|MUL|DIV)SSload [off1+off2] {mergeSym(sym1,sym2)} val base mem) +((ADD|SUB|MUL|DIV)SDload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> - ((ADD|SUB|MUL)SDload [off1+off2] {mergeSym(sym1,sym2)} val base mem) + ((ADD|SUB|MUL|DIV)SDload [off1+off2] {mergeSym(sym1,sym2)} val base mem) ((ADD|AND|OR|XOR)Qconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) && ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) -> ((ADD|AND|OR|XOR)Qconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) @@ -2274,8 +2274,8 @@ // TODO: add indexed variants? ((ADD|SUB|AND|OR|XOR)Q x l:(MOVQload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|SUB|AND|OR|XOR)Qload x [off] {sym} ptr mem) ((ADD|SUB|AND|OR|XOR)L x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|SUB|AND|OR|XOR)Lload x [off] {sym} ptr mem) -((ADD|SUB|MUL)SD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|SUB|MUL)SDload x [off] {sym} ptr mem) -((ADD|SUB|MUL)SS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|SUB|MUL)SSload x [off] {sym} ptr mem) +((ADD|SUB|MUL|DIV)SD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|SUB|MUL|DIV)SDload x [off] {sym} ptr mem) +((ADD|SUB|MUL|DIV)SS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|SUB|MUL|DIV)SSload x [off] {sym} ptr mem) // Merge ADDQconst and LEAQ into atomic loads. (MOVQatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> diff --git a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go index 1140958670d01..4735ea1bc08f4 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go @@ -189,6 +189,8 @@ func init() { {name: "SUBSDload", argLength: 3, reg: fp21load, asm: "SUBSD", aux: "SymOff", resultInArg0: true, faultOnNilArg1: true, symEffect: "Read"}, // fp64 arg0 - tmp, tmp loaded from arg1+auxint+aux, arg2 = mem {name: "MULSSload", argLength: 3, reg: fp21load, asm: "MULSS", aux: "SymOff", resultInArg0: true, faultOnNilArg1: true, symEffect: "Read"}, // fp32 arg0 * tmp, tmp loaded from arg1+auxint+aux, arg2 = mem {name: "MULSDload", argLength: 3, reg: fp21load, asm: "MULSD", aux: "SymOff", resultInArg0: true, faultOnNilArg1: true, symEffect: "Read"}, // fp64 arg0 * tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + {name: "DIVSSload", argLength: 3, reg: fp21load, asm: "DIVSS", aux: "SymOff", resultInArg0: true, faultOnNilArg1: true, symEffect: "Read"}, // fp32 arg0 / tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + {name: "DIVSDload", argLength: 3, reg: fp21load, asm: "DIVSD", aux: "SymOff", resultInArg0: true, faultOnNilArg1: true, symEffect: "Read"}, // fp64 arg0 / tmp, tmp loaded from arg1+auxint+aux, arg2 = mem // binary ops {name: "ADDQ", argLength: 2, reg: gp21sp, asm: "ADDQ", commutative: true, clobberFlags: true}, // arg0 + arg1 diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 34b1d8a4bba22..355462384097f 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -462,6 +462,8 @@ const ( OpAMD64SUBSDload OpAMD64MULSSload OpAMD64MULSDload + OpAMD64DIVSSload + OpAMD64DIVSDload OpAMD64ADDQ OpAMD64ADDL OpAMD64ADDQconst @@ -5543,6 +5545,42 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "DIVSSload", + auxType: auxSymOff, + argLen: 3, + resultInArg0: true, + faultOnNilArg1: true, + symEffect: SymRead, + asm: x86.ADIVSS, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4294901760}, // X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 + {1, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + outputs: []outputInfo{ + {0, 4294901760}, // X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 + }, + }, + }, + { + name: "DIVSDload", + auxType: auxSymOff, + argLen: 3, + resultInArg0: true, + faultOnNilArg1: true, + symEffect: SymRead, + asm: x86.ADIVSD, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4294901760}, // X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 + {1, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + outputs: []outputInfo{ + {0, 4294901760}, // X0 X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 + }, + }, + }, { name: "ADDQ", argLen: 2, diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 4ffd6b5d186b4..245f795d90059 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -157,6 +157,14 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64CMPXCHGLlock_0(v) case OpAMD64CMPXCHGQlock: return rewriteValueAMD64_OpAMD64CMPXCHGQlock_0(v) + case OpAMD64DIVSD: + return rewriteValueAMD64_OpAMD64DIVSD_0(v) + case OpAMD64DIVSDload: + return rewriteValueAMD64_OpAMD64DIVSDload_0(v) + case OpAMD64DIVSS: + return rewriteValueAMD64_OpAMD64DIVSS_0(v) + case OpAMD64DIVSSload: + return rewriteValueAMD64_OpAMD64DIVSSload_0(v) case OpAMD64LEAL: return rewriteValueAMD64_OpAMD64LEAL_0(v) case OpAMD64LEAL1: @@ -8808,6 +8816,176 @@ func rewriteValueAMD64_OpAMD64CMPXCHGQlock_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64DIVSD_0(v *Value) bool { + // match: (DIVSD x l:(MOVSDload [off] {sym} ptr mem)) + // cond: canMergeLoad(v, l, x) && clobber(l) + // result: (DIVSDload x [off] {sym} ptr mem) + for { + _ = v.Args[1] + x := v.Args[0] + l := v.Args[1] + if l.Op != OpAMD64MOVSDload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(canMergeLoad(v, l, x) && clobber(l)) { + break + } + v.reset(OpAMD64DIVSDload) + v.AuxInt = off + v.Aux = sym + v.AddArg(x) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueAMD64_OpAMD64DIVSDload_0(v *Value) bool { + // match: (DIVSDload [off1] {sym} val (ADDQconst [off2] base) mem) + // cond: is32Bit(off1+off2) + // result: (DIVSDload [off1+off2] {sym} val base mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + val := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpAMD64ADDQconst { + break + } + off2 := v_1.AuxInt + base := v_1.Args[0] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64DIVSDload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(val) + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (DIVSDload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (DIVSDload [off1+off2] {mergeSym(sym1,sym2)} val base mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + val := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpAMD64LEAQ { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + base := v_1.Args[0] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64DIVSDload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(val) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueAMD64_OpAMD64DIVSS_0(v *Value) bool { + // match: (DIVSS x l:(MOVSSload [off] {sym} ptr mem)) + // cond: canMergeLoad(v, l, x) && clobber(l) + // result: (DIVSSload x [off] {sym} ptr mem) + for { + _ = v.Args[1] + x := v.Args[0] + l := v.Args[1] + if l.Op != OpAMD64MOVSSload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(canMergeLoad(v, l, x) && clobber(l)) { + break + } + v.reset(OpAMD64DIVSSload) + v.AuxInt = off + v.Aux = sym + v.AddArg(x) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueAMD64_OpAMD64DIVSSload_0(v *Value) bool { + // match: (DIVSSload [off1] {sym} val (ADDQconst [off2] base) mem) + // cond: is32Bit(off1+off2) + // result: (DIVSSload [off1+off2] {sym} val base mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + val := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpAMD64ADDQconst { + break + } + off2 := v_1.AuxInt + base := v_1.Args[0] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64DIVSSload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(val) + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (DIVSSload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (DIVSSload [off1+off2] {mergeSym(sym1,sym2)} val base mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + val := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpAMD64LEAQ { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + base := v_1.Args[0] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64DIVSSload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(val) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64LEAL_0(v *Value) bool { // match: (LEAL [c] {s} (ADDLconst [d] x)) // cond: is32Bit(c+d) diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index f358020f5598a..a7f2906db9b1f 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -112,6 +112,11 @@ func ConstDivs(n1 uint, n2 int) (uint, int) { return a, b } +func FloatDivs(a []float32) float32 { + // amd64:`DIVSS\s8\([A-Z]+\),\sX[0-9]+` + return a[1] / a[2] +} + func Pow2Mods(n1 uint, n2 int) (uint, int) { // 386:"ANDL\t[$]31",-"DIVL" // amd64:"ANDQ\t[$]31",-"DIVQ" From 90f2fa003738651b02eb0dcb957a6135772ff289 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Sun, 24 Jun 2018 07:04:21 +0000 Subject: [PATCH 0109/1663] cmd/compile: optimize 386 code with MULLload/DIVSSload/DIVSDload MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit IMULL/DIVSS/DIVSD all can take the source operand from memory directly. And this CL implement that optimization. 1. The total size of pkg/linux_386 decreases about 84KB (excluding cmd/compile). 2. The go1 benchmark shows little regression in total (excluding noise). name old time/op new time/op delta BinaryTree17-4 3.29s ± 2% 3.27s ± 4% ~ (p=0.192 n=30+30) Fannkuch11-4 3.49s ± 2% 3.54s ± 1% +1.48% (p=0.000 n=30+30) FmtFprintfEmpty-4 45.9ns ± 3% 46.3ns ± 4% +0.89% (p=0.037 n=30+30) FmtFprintfString-4 78.8ns ± 3% 78.7ns ± 4% ~ (p=0.209 n=30+27) FmtFprintfInt-4 91.0ns ± 2% 90.3ns ± 2% -0.82% (p=0.031 n=30+27) FmtFprintfIntInt-4 142ns ± 4% 143ns ± 4% ~ (p=0.136 n=30+30) FmtFprintfPrefixedInt-4 181ns ± 3% 183ns ± 4% +1.40% (p=0.005 n=30+30) FmtFprintfFloat-4 404ns ± 4% 408ns ± 3% ~ (p=0.397 n=30+30) FmtManyArgs-4 601ns ± 3% 609ns ± 5% ~ (p=0.059 n=30+30) GobDecode-4 7.21ms ± 5% 7.24ms ± 5% ~ (p=0.612 n=30+30) GobEncode-4 6.91ms ± 6% 6.91ms ± 6% ~ (p=0.797 n=30+30) Gzip-4 398ms ± 6% 399ms ± 4% ~ (p=0.173 n=30+30) Gunzip-4 41.7ms ± 3% 41.8ms ± 3% ~ (p=0.423 n=30+30) HTTPClientServer-4 62.3µs ± 2% 62.7µs ± 3% ~ (p=0.085 n=29+30) JSONEncode-4 21.0ms ± 4% 20.7ms ± 5% -1.39% (p=0.014 n=30+30) JSONDecode-4 66.3ms ± 3% 67.4ms ± 1% +1.71% (p=0.003 n=30+24) Mandelbrot200-4 5.15ms ± 3% 5.16ms ± 3% ~ (p=0.697 n=30+30) GoParse-4 3.24ms ± 3% 3.27ms ± 4% +0.91% (p=0.032 n=30+30) RegexpMatchEasy0_32-4 101ns ± 5% 99ns ± 4% -1.82% (p=0.008 n=29+30) RegexpMatchEasy0_1K-4 848ns ± 4% 841ns ± 2% -0.77% (p=0.043 n=30+30) RegexpMatchEasy1_32-4 106ns ± 6% 106ns ± 3% ~ (p=0.939 n=29+30) RegexpMatchEasy1_1K-4 1.02µs ± 3% 1.03µs ± 4% ~ (p=0.297 n=28+30) RegexpMatchMedium_32-4 129ns ± 4% 127ns ± 4% ~ (p=0.073 n=30+30) RegexpMatchMedium_1K-4 43.9µs ± 3% 43.8µs ± 3% ~ (p=0.186 n=30+30) RegexpMatchHard_32-4 2.24µs ± 4% 2.22µs ± 4% ~ (p=0.332 n=30+29) RegexpMatchHard_1K-4 68.0µs ± 4% 67.5µs ± 3% ~ (p=0.290 n=30+30) Revcomp-4 1.85s ± 3% 1.85s ± 3% ~ (p=0.358 n=30+30) Template-4 69.6ms ± 3% 70.0ms ± 4% ~ (p=0.273 n=30+30) TimeParse-4 445ns ± 3% 441ns ± 3% ~ (p=0.494 n=30+30) TimeFormat-4 412ns ± 3% 412ns ± 6% ~ (p=0.841 n=30+30) [Geo mean] 66.7µs 66.8µs +0.13% name old speed new speed delta GobDecode-4 107MB/s ± 5% 106MB/s ± 5% ~ (p=0.615 n=30+30) GobEncode-4 111MB/s ± 6% 111MB/s ± 6% ~ (p=0.790 n=30+30) Gzip-4 48.8MB/s ± 6% 48.7MB/s ± 4% ~ (p=0.167 n=30+30) Gunzip-4 465MB/s ± 3% 465MB/s ± 3% ~ (p=0.420 n=30+30) JSONEncode-4 92.4MB/s ± 4% 93.7MB/s ± 5% +1.42% (p=0.015 n=30+30) JSONDecode-4 29.3MB/s ± 3% 28.8MB/s ± 1% -1.72% (p=0.003 n=30+24) GoParse-4 17.9MB/s ± 3% 17.7MB/s ± 4% -0.89% (p=0.037 n=30+30) RegexpMatchEasy0_32-4 317MB/s ± 8% 324MB/s ± 4% +2.14% (p=0.006 n=30+30) RegexpMatchEasy0_1K-4 1.21GB/s ± 4% 1.22GB/s ± 2% +0.77% (p=0.036 n=30+30) RegexpMatchEasy1_32-4 298MB/s ± 7% 299MB/s ± 4% ~ (p=0.511 n=30+30) RegexpMatchEasy1_1K-4 1.00GB/s ± 3% 1.00GB/s ± 4% ~ (p=0.304 n=28+30) RegexpMatchMedium_32-4 7.75MB/s ± 4% 7.82MB/s ± 4% ~ (p=0.089 n=30+30) RegexpMatchMedium_1K-4 23.3MB/s ± 3% 23.4MB/s ± 3% ~ (p=0.181 n=30+30) RegexpMatchHard_32-4 14.3MB/s ± 4% 14.4MB/s ± 4% ~ (p=0.320 n=30+29) RegexpMatchHard_1K-4 15.1MB/s ± 4% 15.2MB/s ± 3% ~ (p=0.273 n=30+30) Revcomp-4 137MB/s ± 3% 137MB/s ± 3% ~ (p=0.352 n=30+30) Template-4 27.9MB/s ± 3% 27.7MB/s ± 4% ~ (p=0.277 n=30+30) [Geo mean] 79.9MB/s 80.1MB/s +0.15% Change-Id: I97333cd8ddabb3c7c88ca5aa9e14a005b74d306d Reviewed-on: https://go-review.googlesource.com/120695 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/gen/386.rules | 30 +- src/cmd/compile/internal/ssa/gen/386Ops.go | 13 +- src/cmd/compile/internal/ssa/opGen.go | 58 ++++ src/cmd/compile/internal/ssa/rewrite386.go | 308 +++++++++++++++++++++ src/cmd/compile/internal/x86/ssa.go | 6 +- test/codegen/arithmetic.go | 12 + 6 files changed, 405 insertions(+), 22 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/386.rules b/src/cmd/compile/internal/ssa/gen/386.rules index 94f24a81ef507..127829473b2b3 100644 --- a/src/cmd/compile/internal/ssa/gen/386.rules +++ b/src/cmd/compile/internal/ssa/gen/386.rules @@ -636,12 +636,12 @@ (MOVSSstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSSstore [off1+off2] {sym} ptr val mem) (MOVSDstore [off1] {sym} (ADDLconst [off2] ptr) val mem) && is32Bit(off1+off2) -> (MOVSDstore [off1+off2] {sym} ptr val mem) -((ADD|SUB|AND|OR|XOR)Lload [off1] {sym} val (ADDLconst [off2] base) mem) && is32Bit(off1+off2) -> - ((ADD|SUB|AND|OR|XOR)Lload [off1+off2] {sym} val base mem) -((ADD|SUB|MUL)SSload [off1] {sym} val (ADDLconst [off2] base) mem) && is32Bit(off1+off2) -> - ((ADD|SUB|MUL)SSload [off1+off2] {sym} val base mem) -((ADD|SUB|MUL)SDload [off1] {sym} val (ADDLconst [off2] base) mem) && is32Bit(off1+off2) -> - ((ADD|SUB|MUL)SDload [off1+off2] {sym} val base mem) +((ADD|SUB|MUL|AND|OR|XOR)Lload [off1] {sym} val (ADDLconst [off2] base) mem) && is32Bit(off1+off2) -> + ((ADD|SUB|MUL|AND|OR|XOR)Lload [off1+off2] {sym} val base mem) +((ADD|SUB|MUL|DIV)SSload [off1] {sym} val (ADDLconst [off2] base) mem) && is32Bit(off1+off2) -> + ((ADD|SUB|MUL|DIV)SSload [off1+off2] {sym} val base mem) +((ADD|SUB|MUL|DIV)SDload [off1] {sym} val (ADDLconst [off2] base) mem) && is32Bit(off1+off2) -> + ((ADD|SUB|MUL|DIV)SDload [off1+off2] {sym} val base mem) ((ADD|SUB|AND|OR|XOR)Lmodify [off1] {sym} (ADDLconst [off2] base) val mem) && is32Bit(off1+off2) -> ((ADD|SUB|AND|OR|XOR)Lmodify [off1+off2] {sym} base val mem) @@ -757,15 +757,15 @@ (MOVSDstore [off1] {sym1} (LEAL8 [off2] {sym2} ptr idx) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> (MOVSDstoreidx8 [off1+off2] {mergeSym(sym1,sym2)} ptr idx val mem) -((ADD|SUB|AND|OR|XOR)Lload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) +((ADD|SUB|MUL|AND|OR|XOR)Lload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) -> - ((ADD|SUB|AND|OR|XOR)Lload [off1+off2] {mergeSym(sym1,sym2)} val base mem) -((ADD|SUB|MUL)SSload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) + ((ADD|SUB|MUL|AND|OR|XOR)Lload [off1+off2] {mergeSym(sym1,sym2)} val base mem) +((ADD|SUB|MUL|DIV)SSload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) -> - ((ADD|SUB|MUL)SSload [off1+off2] {mergeSym(sym1,sym2)} val base mem) -((ADD|SUB|MUL)SDload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) + ((ADD|SUB|MUL|DIV)SSload [off1+off2] {mergeSym(sym1,sym2)} val base mem) +((ADD|SUB|MUL|DIV)SDload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) -> - ((ADD|SUB|MUL)SDload [off1+off2] {mergeSym(sym1,sym2)} val base mem) + ((ADD|SUB|MUL|DIV)SDload [off1+off2] {mergeSym(sym1,sym2)} val base mem) ((ADD|SUB|AND|OR|XOR)Lmodify [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) -> ((ADD|SUB|AND|OR|XOR)Lmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) @@ -846,9 +846,9 @@ (MOVSDstoreidx8 [c] {sym} ptr (ADDLconst [d] idx) val mem) -> (MOVSDstoreidx8 [int64(int32(c+8*d))] {sym} ptr idx val mem) // Merge load/store to op -((ADD|AND|OR|XOR|SUB)L x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|AND|OR|XOR|SUB)Lload x [off] {sym} ptr mem) -((ADD|SUB|MUL)SD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && !config.use387 && clobber(l) -> ((ADD|SUB|MUL)SDload x [off] {sym} ptr mem) -((ADD|SUB|MUL)SS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && !config.use387 && clobber(l) -> ((ADD|SUB|MUL)SSload x [off] {sym} ptr mem) +((ADD|AND|OR|XOR|SUB|MUL)L x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|AND|OR|XOR|SUB|MUL)Lload x [off] {sym} ptr mem) +((ADD|SUB|MUL|DIV)SD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && !config.use387 && clobber(l) -> ((ADD|SUB|MUL|DIV)SDload x [off] {sym} ptr mem) +((ADD|SUB|MUL|DIV)SS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && !config.use387 && clobber(l) -> ((ADD|SUB|MUL|DIV)SSload x [off] {sym} ptr mem) (MOVLstore {sym} [off] ptr y:((ADD|AND|OR|XOR)Lload x [off] {sym} ptr mem) mem) && y.Uses==1 && clobber(y) -> ((ADD|AND|OR|XOR)Lmodify [off] {sym} ptr x mem) (MOVLstore {sym} [off] ptr y:((ADD|SUB|AND|OR|XOR)L l:(MOVLload [off] {sym} ptr mem) x) mem) && y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) -> ((ADD|SUB|AND|OR|XOR)Lmodify [off] {sym} ptr x mem) diff --git a/src/cmd/compile/internal/ssa/gen/386Ops.go b/src/cmd/compile/internal/ssa/gen/386Ops.go index 7a274269d26aa..40f4a2b15e3f5 100644 --- a/src/cmd/compile/internal/ssa/gen/386Ops.go +++ b/src/cmd/compile/internal/ssa/gen/386Ops.go @@ -183,6 +183,8 @@ func init() { {name: "SUBSDload", argLength: 3, reg: fp21load, asm: "SUBSD", aux: "SymOff", resultInArg0: true, faultOnNilArg1: true, symEffect: "Read"}, // fp64 arg0 - tmp, tmp loaded from arg1+auxint+aux, arg2 = mem {name: "MULSSload", argLength: 3, reg: fp21load, asm: "MULSS", aux: "SymOff", resultInArg0: true, faultOnNilArg1: true, symEffect: "Read"}, // fp32 arg0 * tmp, tmp loaded from arg1+auxint+aux, arg2 = mem {name: "MULSDload", argLength: 3, reg: fp21load, asm: "MULSD", aux: "SymOff", resultInArg0: true, faultOnNilArg1: true, symEffect: "Read"}, // fp64 arg0 * tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + {name: "DIVSSload", argLength: 3, reg: fp21load, asm: "DIVSS", aux: "SymOff", resultInArg0: true, faultOnNilArg1: true, symEffect: "Read"}, // fp32 arg0 / tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + {name: "DIVSDload", argLength: 3, reg: fp21load, asm: "DIVSD", aux: "SymOff", resultInArg0: true, faultOnNilArg1: true, symEffect: "Read"}, // fp64 arg0 / tmp, tmp loaded from arg1+auxint+aux, arg2 = mem // binary ops {name: "ADDL", argLength: 2, reg: gp21sp, asm: "ADDL", commutative: true, clobberFlags: true}, // arg0 + arg1 @@ -279,11 +281,12 @@ func init() { {name: "ROLWconst", argLength: 1, reg: gp11, asm: "ROLW", aux: "Int16", resultInArg0: true, clobberFlags: true}, // arg0 rotate left auxint, rotate amount 0-15 {name: "ROLBconst", argLength: 1, reg: gp11, asm: "ROLB", aux: "Int8", resultInArg0: true, clobberFlags: true}, // arg0 rotate left auxint, rotate amount 0-7 - {name: "ADDLload", argLength: 3, reg: gp21load, asm: "ADDL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 + tmp, tmp loaded from arg1+auxint+aux, arg2 = mem - {name: "SUBLload", argLength: 3, reg: gp21load, asm: "SUBL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 - tmp, tmp loaded from arg1+auxint+aux, arg2 = mem - {name: "ANDLload", argLength: 3, reg: gp21load, asm: "ANDL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 & tmp, tmp loaded from arg1+auxint+aux, arg2 = mem - {name: "ORLload", argLength: 3, reg: gp21load, asm: "ORL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 | tmp, tmp loaded from arg1+auxint+aux, arg2 = mem - {name: "XORLload", argLength: 3, reg: gp21load, asm: "XORL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 ^ tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + {name: "ADDLload", argLength: 3, reg: gp21load, asm: "ADDL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 + tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + {name: "SUBLload", argLength: 3, reg: gp21load, asm: "SUBL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 - tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + {name: "MULLload", argLength: 3, reg: gp21load, asm: "IMULL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 * tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + {name: "ANDLload", argLength: 3, reg: gp21load, asm: "ANDL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 & tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + {name: "ORLload", argLength: 3, reg: gp21load, asm: "ORL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 | tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + {name: "XORLload", argLength: 3, reg: gp21load, asm: "XORL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 ^ tmp, tmp loaded from arg1+auxint+aux, arg2 = mem // unary ops {name: "NEGL", argLength: 1, reg: gp11, asm: "NEGL", resultInArg0: true, clobberFlags: true}, // -arg0 diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 355462384097f..8ac47cb2d0db2 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -262,6 +262,8 @@ const ( Op386SUBSDload Op386MULSSload Op386MULSDload + Op386DIVSSload + Op386DIVSDload Op386ADDL Op386ADDLconst Op386ADDLcarry @@ -333,6 +335,7 @@ const ( Op386ROLBconst Op386ADDLload Op386SUBLload + Op386MULLload Op386ANDLload Op386ORLload Op386XORLload @@ -2752,6 +2755,42 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "DIVSSload", + auxType: auxSymOff, + argLen: 3, + resultInArg0: true, + faultOnNilArg1: true, + symEffect: SymRead, + asm: x86.ADIVSS, + reg: regInfo{ + inputs: []inputInfo{ + {0, 65280}, // X0 X1 X2 X3 X4 X5 X6 X7 + {1, 65791}, // AX CX DX BX SP BP SI DI SB + }, + outputs: []outputInfo{ + {0, 65280}, // X0 X1 X2 X3 X4 X5 X6 X7 + }, + }, + }, + { + name: "DIVSDload", + auxType: auxSymOff, + argLen: 3, + resultInArg0: true, + faultOnNilArg1: true, + symEffect: SymRead, + asm: x86.ADIVSD, + reg: regInfo{ + inputs: []inputInfo{ + {0, 65280}, // X0 X1 X2 X3 X4 X5 X6 X7 + {1, 65791}, // AX CX DX BX SP BP SI DI SB + }, + outputs: []outputInfo{ + {0, 65280}, // X0 X1 X2 X3 X4 X5 X6 X7 + }, + }, + }, { name: "ADDL", argLen: 2, @@ -3821,6 +3860,25 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "MULLload", + auxType: auxSymOff, + argLen: 3, + resultInArg0: true, + clobberFlags: true, + faultOnNilArg1: true, + symEffect: SymRead, + asm: x86.AIMULL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 239}, // AX CX DX BX BP SI DI + {1, 65791}, // AX CX DX BX SP BP SI DI SB + }, + outputs: []outputInfo{ + {0, 239}, // AX CX DX BX BP SI DI + }, + }, + }, { name: "ANDLload", auxType: auxSymOff, diff --git a/src/cmd/compile/internal/ssa/rewrite386.go b/src/cmd/compile/internal/ssa/rewrite386.go index db2c62089d6de..039538ea7dce5 100644 --- a/src/cmd/compile/internal/ssa/rewrite386.go +++ b/src/cmd/compile/internal/ssa/rewrite386.go @@ -61,6 +61,14 @@ func rewriteValue386(v *Value) bool { return rewriteValue386_Op386CMPWconst_0(v) case Op386CMPWload: return rewriteValue386_Op386CMPWload_0(v) + case Op386DIVSD: + return rewriteValue386_Op386DIVSD_0(v) + case Op386DIVSDload: + return rewriteValue386_Op386DIVSDload_0(v) + case Op386DIVSS: + return rewriteValue386_Op386DIVSS_0(v) + case Op386DIVSSload: + return rewriteValue386_Op386DIVSSload_0(v) case Op386LEAL: return rewriteValue386_Op386LEAL_0(v) case Op386LEAL1: @@ -163,6 +171,8 @@ func rewriteValue386(v *Value) bool { return rewriteValue386_Op386MULL_0(v) case Op386MULLconst: return rewriteValue386_Op386MULLconst_0(v) || rewriteValue386_Op386MULLconst_10(v) || rewriteValue386_Op386MULLconst_20(v) || rewriteValue386_Op386MULLconst_30(v) + case Op386MULLload: + return rewriteValue386_Op386MULLload_0(v) case Op386MULSD: return rewriteValue386_Op386MULSD_0(v) case Op386MULSDload: @@ -3098,6 +3108,192 @@ func rewriteValue386_Op386CMPWload_0(v *Value) bool { } return false } +func rewriteValue386_Op386DIVSD_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (DIVSD x l:(MOVSDload [off] {sym} ptr mem)) + // cond: canMergeLoad(v, l, x) && !config.use387 && clobber(l) + // result: (DIVSDload x [off] {sym} ptr mem) + for { + _ = v.Args[1] + x := v.Args[0] + l := v.Args[1] + if l.Op != Op386MOVSDload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(canMergeLoad(v, l, x) && !config.use387 && clobber(l)) { + break + } + v.reset(Op386DIVSDload) + v.AuxInt = off + v.Aux = sym + v.AddArg(x) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValue386_Op386DIVSDload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (DIVSDload [off1] {sym} val (ADDLconst [off2] base) mem) + // cond: is32Bit(off1+off2) + // result: (DIVSDload [off1+off2] {sym} val base mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + val := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != Op386ADDLconst { + break + } + off2 := v_1.AuxInt + base := v_1.Args[0] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(Op386DIVSDload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(val) + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (DIVSDload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) + // result: (DIVSDload [off1+off2] {mergeSym(sym1,sym2)} val base mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + val := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != Op386LEAL { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + base := v_1.Args[0] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(Op386DIVSDload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(val) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} +func rewriteValue386_Op386DIVSS_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (DIVSS x l:(MOVSSload [off] {sym} ptr mem)) + // cond: canMergeLoad(v, l, x) && !config.use387 && clobber(l) + // result: (DIVSSload x [off] {sym} ptr mem) + for { + _ = v.Args[1] + x := v.Args[0] + l := v.Args[1] + if l.Op != Op386MOVSSload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(canMergeLoad(v, l, x) && !config.use387 && clobber(l)) { + break + } + v.reset(Op386DIVSSload) + v.AuxInt = off + v.Aux = sym + v.AddArg(x) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValue386_Op386DIVSSload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (DIVSSload [off1] {sym} val (ADDLconst [off2] base) mem) + // cond: is32Bit(off1+off2) + // result: (DIVSSload [off1+off2] {sym} val base mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + val := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != Op386ADDLconst { + break + } + off2 := v_1.AuxInt + base := v_1.Args[0] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(Op386DIVSSload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(val) + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (DIVSSload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) + // result: (DIVSSload [off1+off2] {mergeSym(sym1,sym2)} val base mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + val := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != Op386LEAL { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + base := v_1.Args[0] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(Op386DIVSSload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(val) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValue386_Op386LEAL_0(v *Value) bool { // match: (LEAL [c] {s} (ADDLconst [d] x)) // cond: is32Bit(c+d) @@ -9825,6 +10021,58 @@ func rewriteValue386_Op386MULL_0(v *Value) bool { v.AddArg(x) return true } + // match: (MULL x l:(MOVLload [off] {sym} ptr mem)) + // cond: canMergeLoad(v, l, x) && clobber(l) + // result: (MULLload x [off] {sym} ptr mem) + for { + _ = v.Args[1] + x := v.Args[0] + l := v.Args[1] + if l.Op != Op386MOVLload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + if !(canMergeLoad(v, l, x) && clobber(l)) { + break + } + v.reset(Op386MULLload) + v.AuxInt = off + v.Aux = sym + v.AddArg(x) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MULL l:(MOVLload [off] {sym} ptr mem) x) + // cond: canMergeLoad(v, l, x) && clobber(l) + // result: (MULLload x [off] {sym} ptr mem) + for { + _ = v.Args[1] + l := v.Args[0] + if l.Op != Op386MOVLload { + break + } + off := l.AuxInt + sym := l.Aux + _ = l.Args[1] + ptr := l.Args[0] + mem := l.Args[1] + x := v.Args[1] + if !(canMergeLoad(v, l, x) && clobber(l)) { + break + } + v.reset(Op386MULLload) + v.AuxInt = off + v.Aux = sym + v.AddArg(x) + v.AddArg(ptr) + v.AddArg(mem) + return true + } return false } func rewriteValue386_Op386MULLconst_0(v *Value) bool { @@ -10332,6 +10580,66 @@ func rewriteValue386_Op386MULLconst_30(v *Value) bool { } return false } +func rewriteValue386_Op386MULLload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MULLload [off1] {sym} val (ADDLconst [off2] base) mem) + // cond: is32Bit(off1+off2) + // result: (MULLload [off1+off2] {sym} val base mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + val := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != Op386ADDLconst { + break + } + off2 := v_1.AuxInt + base := v_1.Args[0] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(Op386MULLload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(val) + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (MULLload [off1] {sym1} val (LEAL [off2] {sym2} base) mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MULLload [off1+off2] {mergeSym(sym1,sym2)} val base mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + val := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != Op386LEAL { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + base := v_1.Args[0] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(Op386MULLload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(val) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValue386_Op386MULSD_0(v *Value) bool { b := v.Block _ = b diff --git a/src/cmd/compile/internal/x86/ssa.go b/src/cmd/compile/internal/x86/ssa.go index d75a55c5659a2..7cdff863b2b99 100644 --- a/src/cmd/compile/internal/x86/ssa.go +++ b/src/cmd/compile/internal/x86/ssa.go @@ -525,8 +525,10 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { gc.AddAux(&p.From, v) p.To.Type = obj.TYPE_REG p.To.Reg = v.Reg() - case ssa.Op386ADDLload, ssa.Op386SUBLload, ssa.Op386ANDLload, ssa.Op386ORLload, ssa.Op386XORLload, - ssa.Op386ADDSDload, ssa.Op386ADDSSload, ssa.Op386SUBSDload, ssa.Op386SUBSSload, ssa.Op386MULSDload, ssa.Op386MULSSload: + case ssa.Op386ADDLload, ssa.Op386SUBLload, ssa.Op386MULLload, + ssa.Op386ANDLload, ssa.Op386ORLload, ssa.Op386XORLload, + ssa.Op386ADDSDload, ssa.Op386ADDSSload, ssa.Op386SUBSDload, ssa.Op386SUBSSload, + ssa.Op386MULSDload, ssa.Op386MULSSload, ssa.Op386DIVSSload, ssa.Op386DIVSDload: p := s.Prog(v.Op.Asm()) p.From.Type = obj.TYPE_MEM p.From.Reg = v.Args[1].Reg() diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index a7f2906db9b1f..3c063d873605a 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -49,6 +49,13 @@ func Mul_96(n int) int { return n * 96 } +func MulMemSrc(a []uint32, b []float32) { + // 386:`IMULL\s4\([A-Z]+\),\s[A-Z]+` + a[0] *= a[1] + // 386/sse2:`MULSS\s4\([A-Z]+\),\sX[0-9]+` + b[0] *= b[1] +} + // Multiplications merging tests func MergeMuls1(n int) int { @@ -85,6 +92,11 @@ func MergeMuls5(a, n int) int { // Division // // -------------- // +func DivMemSrc(a []float64) { + // 386/sse2:`DIVSD\s8\([A-Z]+\),\sX[0-9]+` + a[0] /= a[1] +} + func Pow2Divs(n1 uint, n2 int) (uint, int) { // 386:"SHRL\t[$]5",-"DIVL" // amd64:"SHRQ\t[$]5",-"DIVQ" From de16b3223375235a823658ab4e84716d7fb62dc4 Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Tue, 21 Aug 2018 14:50:04 -0600 Subject: [PATCH 0110/1663] crypto/tls: make ConnectionState.ExportKeyingMaterial a method The unexported field is hidden from reflect based marshalers, which would break otherwise. Also, make it return an error, as there are multiple reasons it might fail. Fixes #27125 Change-Id: I92adade2fe456103d2d5c0315629ca0256953764 Reviewed-on: https://go-review.googlesource.com/130535 Run-TryBot: Filippo Valsorda TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- api/go1.11.txt | 2 +- doc/go1.11.html | 3 +- src/crypto/tls/common.go | 15 ++- src/crypto/tls/conn.go | 6 +- src/crypto/tls/handshake_client_test.go | 18 ++++ src/crypto/tls/handshake_server_test.go | 18 ++++ src/crypto/tls/prf.go | 16 ++-- src/crypto/tls/prf_test.go | 12 +-- .../Client-TLSv10-ExportKeyingMaterial | 89 ++++++++++++++++++ .../Client-TLSv12-ExportKeyingMaterial | 84 +++++++++++++++++ .../Server-TLSv10-ExportKeyingMaterial | 92 +++++++++++++++++++ .../Server-TLSv12-ExportKeyingMaterial | 92 +++++++++++++++++++ src/crypto/tls/tls_test.go | 9 ++ 13 files changed, 432 insertions(+), 24 deletions(-) create mode 100644 src/crypto/tls/testdata/Client-TLSv10-ExportKeyingMaterial create mode 100644 src/crypto/tls/testdata/Client-TLSv12-ExportKeyingMaterial create mode 100644 src/crypto/tls/testdata/Server-TLSv10-ExportKeyingMaterial create mode 100644 src/crypto/tls/testdata/Server-TLSv12-ExportKeyingMaterial diff --git a/api/go1.11.txt b/api/go1.11.txt index 4c0bcc74795d0..863e1f162551f 100644 --- a/api/go1.11.txt +++ b/api/go1.11.txt @@ -1,7 +1,7 @@ pkg crypto/cipher, func NewGCMWithTagSize(Block, int) (AEAD, error) pkg crypto/rsa, method (*PrivateKey) Size() int pkg crypto/rsa, method (*PublicKey) Size() int -pkg crypto/tls, type ConnectionState struct, ExportKeyingMaterial func(string, []uint8, int) ([]uint8, bool) +pkg crypto/tls, method (*ConnectionState) ExportKeyingMaterial(string, []uint8, int) ([]uint8, error) pkg database/sql, method (IsolationLevel) String() string pkg database/sql, type DBStats struct, Idle int pkg database/sql, type DBStats struct, InUse int diff --git a/doc/go1.11.html b/doc/go1.11.html index fae1c5ff145a6..087dc72f8e195 100644 --- a/doc/go1.11.html +++ b/doc/go1.11.html @@ -500,7 +500,8 @@

    Minor changes to the library

    ConnectionState's new - ExportKeyingMaterial field allows exporting keying material bound to the + ExportKeyingMaterial + method allows exporting keying material bound to the connection according to RFC 5705.

    diff --git a/src/crypto/tls/common.go b/src/crypto/tls/common.go index 729bce6d50c66..7b627fc025384 100644 --- a/src/crypto/tls/common.go +++ b/src/crypto/tls/common.go @@ -164,11 +164,8 @@ type ConnectionState struct { SignedCertificateTimestamps [][]byte // SCTs from the server, if any OCSPResponse []byte // stapled OCSP response from server, if any - // ExportKeyMaterial returns length bytes of exported key material as - // defined in https://tools.ietf.org/html/rfc5705. If context is nil, it is - // not used as part of the seed. If Config.Renegotiation was set to allow - // renegotiation, this function will always return nil, false. - ExportKeyingMaterial func(label string, context []byte, length int) ([]byte, bool) + // ekm is a closure exposed via ExportKeyingMaterial. + ekm func(label string, context []byte, length int) ([]byte, error) // TLSUnique contains the "tls-unique" channel binding value (see RFC // 5929, section 3). For resumed sessions this value will be nil @@ -179,6 +176,14 @@ type ConnectionState struct { TLSUnique []byte } +// ExportKeyingMaterial returns length bytes of exported key material in a new +// slice as defined in https://tools.ietf.org/html/rfc5705. If context is nil, +// it is not used as part of the seed. If the connection was set to allow +// renegotiation via Config.Renegotiation, this function will return an error. +func (cs *ConnectionState) ExportKeyingMaterial(label string, context []byte, length int) ([]byte, error) { + return cs.ekm(label, context, length) +} + // ClientAuthType declares the policy the server will follow for // TLS Client Authentication. type ClientAuthType int diff --git a/src/crypto/tls/conn.go b/src/crypto/tls/conn.go index 2adb967537ccc..6e27e695bd847 100644 --- a/src/crypto/tls/conn.go +++ b/src/crypto/tls/conn.go @@ -56,7 +56,7 @@ type Conn struct { // renegotiation is not supported in that case.) secureRenegotiation bool // ekm is a closure for exporting keying material. - ekm func(label string, context []byte, length int) ([]byte, bool) + ekm func(label string, context []byte, length int) ([]byte, error) // clientFinishedIsFirst is true if the client sent the first Finished // message during the most recent handshake. This is recorded because @@ -1315,9 +1315,9 @@ func (c *Conn) ConnectionState() ConnectionState { } } if c.config.Renegotiation != RenegotiateNever { - state.ExportKeyingMaterial = noExportedKeyingMaterial + state.ekm = noExportedKeyingMaterial } else { - state.ExportKeyingMaterial = c.ekm + state.ekm = c.ekm } } diff --git a/src/crypto/tls/handshake_client_test.go b/src/crypto/tls/handshake_client_test.go index 79fb3421a8c7c..1f1c93d102c2c 100644 --- a/src/crypto/tls/handshake_client_test.go +++ b/src/crypto/tls/handshake_client_test.go @@ -979,6 +979,24 @@ func TestRenegotiateTwiceRejected(t *testing.T) { runClientTestTLS12(t, test) } +func TestHandshakeClientExportKeyingMaterial(t *testing.T) { + test := &clientTest{ + name: "ExportKeyingMaterial", + command: []string{"openssl", "s_server"}, + config: testConfig.Clone(), + validate: func(state ConnectionState) error { + if km, err := state.ExportKeyingMaterial("test", nil, 42); err != nil { + return fmt.Errorf("ExportKeyingMaterial failed: %v", err) + } else if len(km) != 42 { + return fmt.Errorf("Got %d bytes from ExportKeyingMaterial, wanted %d", len(km), 42) + } + return nil + }, + } + runClientTestTLS10(t, test) + runClientTestTLS12(t, test) +} + var hostnameInSNITests = []struct { in, out string }{ diff --git a/src/crypto/tls/handshake_server_test.go b/src/crypto/tls/handshake_server_test.go index 01d7b5ceecd8e..c366f47b17cbb 100644 --- a/src/crypto/tls/handshake_server_test.go +++ b/src/crypto/tls/handshake_server_test.go @@ -998,6 +998,24 @@ func TestFallbackSCSV(t *testing.T) { runServerTestTLS11(t, test) } +func TestHandshakeServerExportKeyingMaterial(t *testing.T) { + test := &serverTest{ + name: "ExportKeyingMaterial", + command: []string{"openssl", "s_client"}, + config: testConfig.Clone(), + validate: func(state ConnectionState) error { + if km, err := state.ExportKeyingMaterial("test", nil, 42); err != nil { + return fmt.Errorf("ExportKeyingMaterial failed: %v", err) + } else if len(km) != 42 { + return fmt.Errorf("Got %d bytes from ExportKeyingMaterial, wanted %d", len(km), 42) + } + return nil + }, + } + runServerTestTLS10(t, test) + runServerTestTLS12(t, test) +} + func benchmarkHandshakeServer(b *testing.B, cipherSuite uint16, curve CurveID, cert []byte, key crypto.PrivateKey) { config := testConfig.Clone() config.CipherSuites = []uint16{cipherSuite} diff --git a/src/crypto/tls/prf.go b/src/crypto/tls/prf.go index 98e9ab42921d5..a8cf21da15fe6 100644 --- a/src/crypto/tls/prf.go +++ b/src/crypto/tls/prf.go @@ -347,20 +347,20 @@ func (h *finishedHash) discardHandshakeBuffer() { } // noExportedKeyingMaterial is used as a value of -// ConnectionState.ExportKeyingMaterial when renegotation is enabled and thus +// ConnectionState.ekm when renegotation is enabled and thus // we wish to fail all key-material export requests. -func noExportedKeyingMaterial(label string, context []byte, length int) ([]byte, bool) { - return nil, false +func noExportedKeyingMaterial(label string, context []byte, length int) ([]byte, error) { + return nil, errors.New("crypto/tls: ExportKeyingMaterial is unavailable when renegotiation is enabled") } // ekmFromMasterSecret generates exported keying material as defined in // https://tools.ietf.org/html/rfc5705. -func ekmFromMasterSecret(version uint16, suite *cipherSuite, masterSecret, clientRandom, serverRandom []byte) func(string, []byte, int) ([]byte, bool) { - return func(label string, context []byte, length int) ([]byte, bool) { +func ekmFromMasterSecret(version uint16, suite *cipherSuite, masterSecret, clientRandom, serverRandom []byte) func(string, []byte, int) ([]byte, error) { + return func(label string, context []byte, length int) ([]byte, error) { switch label { case "client finished", "server finished", "master secret", "key expansion": // These values are reserved and may not be used. - return nil, false + return nil, fmt.Errorf("crypto/tls: reserved ExportKeyingMaterial label: %s", label) } seedLen := len(serverRandom) + len(clientRandom) @@ -374,7 +374,7 @@ func ekmFromMasterSecret(version uint16, suite *cipherSuite, masterSecret, clien if context != nil { if len(context) >= 1<<16 { - return nil, false + return nil, fmt.Errorf("crypto/tls: ExportKeyingMaterial context too long") } seed = append(seed, byte(len(context)>>8), byte(len(context))) seed = append(seed, context...) @@ -382,6 +382,6 @@ func ekmFromMasterSecret(version uint16, suite *cipherSuite, masterSecret, clien keyMaterial := make([]byte, length) prfForVersion(version, suite)(keyMaterial, masterSecret, []byte(label), seed) - return keyMaterial, true + return keyMaterial, nil } } diff --git a/src/crypto/tls/prf_test.go b/src/crypto/tls/prf_test.go index 80af32c6cee95..f201253f72ec1 100644 --- a/src/crypto/tls/prf_test.go +++ b/src/crypto/tls/prf_test.go @@ -70,14 +70,14 @@ func TestKeysFromPreMasterSecret(t *testing.T) { } ekm := ekmFromMasterSecret(test.version, test.suite, masterSecret, clientRandom, serverRandom) - contextKeyingMaterial, ok := ekm("label", []byte("context"), 32) - if !ok { - t.Fatalf("ekmFromMasterSecret failed") + contextKeyingMaterial, err := ekm("label", []byte("context"), 32) + if err != nil { + t.Fatalf("ekmFromMasterSecret failed: %v", err) } - noContextKeyingMaterial, ok := ekm("label", nil, 32) - if !ok { - t.Fatalf("ekmFromMasterSecret failed") + noContextKeyingMaterial, err := ekm("label", nil, 32) + if err != nil { + t.Fatalf("ekmFromMasterSecret failed: %v", err) } if hex.EncodeToString(contextKeyingMaterial) != test.contextKeyingMaterial || diff --git a/src/crypto/tls/testdata/Client-TLSv10-ExportKeyingMaterial b/src/crypto/tls/testdata/Client-TLSv10-ExportKeyingMaterial new file mode 100644 index 0000000000000..571769e125d46 --- /dev/null +++ b/src/crypto/tls/testdata/Client-TLSv10-ExportKeyingMaterial @@ -0,0 +1,89 @@ +>>> Flow 1 (client to server) +00000000 16 03 01 00 95 01 00 00 91 03 03 00 00 00 00 00 |................| +00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 2c cc a8 |.............,..| +00000030 cc a9 c0 2f c0 2b c0 30 c0 2c c0 27 c0 13 c0 23 |.../.+.0.,.'...#| +00000040 c0 09 c0 14 c0 0a 00 9c 00 9d 00 3c 00 2f 00 35 |...........<./.5| +00000050 c0 12 00 0a 00 05 c0 11 c0 07 01 00 00 3c 00 05 |.............<..| +00000060 00 05 01 00 00 00 00 00 0a 00 0a 00 08 00 1d 00 |................| +00000070 17 00 18 00 19 00 0b 00 02 01 00 00 0d 00 12 00 |................| +00000080 10 04 01 04 03 05 01 05 03 06 01 06 03 02 01 02 |................| +00000090 03 ff 01 00 01 00 00 12 00 00 |..........| +>>> Flow 2 (server to client) +00000000 16 03 01 00 59 02 00 00 55 03 01 67 4f 02 da 87 |....Y...U..gO...| +00000010 52 30 9a f0 3b e0 63 42 bf 6c 18 58 00 06 70 cf |R0..;.cB.l.X..p.| +00000020 2a 27 5a 00 a7 57 49 fe 03 dd 3b 20 7c 2c 74 00 |*'Z..WI...; |,t.| +00000030 6e b2 35 ca 1b b5 8c 46 f7 78 ab 11 92 43 8c f6 |n.5....F.x...C..| +00000040 97 d3 b8 07 4c 9c 95 2b 08 fe e8 82 c0 13 00 00 |....L..+........| +00000050 0d ff 01 00 01 00 00 0b 00 04 03 00 01 02 16 03 |................| +00000060 01 02 59 0b 00 02 55 00 02 52 00 02 4f 30 82 02 |..Y...U..R..O0..| +00000070 4b 30 82 01 b4 a0 03 02 01 02 02 09 00 e8 f0 9d |K0..............| +00000080 3f e2 5b ea a6 30 0d 06 09 2a 86 48 86 f7 0d 01 |?.[..0...*.H....| +00000090 01 0b 05 00 30 1f 31 0b 30 09 06 03 55 04 0a 13 |....0.1.0...U...| +000000a0 02 47 6f 31 10 30 0e 06 03 55 04 03 13 07 47 6f |.Go1.0...U....Go| +000000b0 20 52 6f 6f 74 30 1e 17 0d 31 36 30 31 30 31 30 | Root0...1601010| +000000c0 30 30 30 30 30 5a 17 0d 32 35 30 31 30 31 30 30 |00000Z..25010100| +000000d0 30 30 30 30 5a 30 1a 31 0b 30 09 06 03 55 04 0a |0000Z0.1.0...U..| +000000e0 13 02 47 6f 31 0b 30 09 06 03 55 04 03 13 02 47 |..Go1.0...U....G| +000000f0 6f 30 81 9f 30 0d 06 09 2a 86 48 86 f7 0d 01 01 |o0..0...*.H.....| +00000100 01 05 00 03 81 8d 00 30 81 89 02 81 81 00 db 46 |.......0.......F| +00000110 7d 93 2e 12 27 06 48 bc 06 28 21 ab 7e c4 b6 a2 |}...'.H..(!.~...| +00000120 5d fe 1e 52 45 88 7a 36 47 a5 08 0d 92 42 5b c2 |]..RE.z6G....B[.| +00000130 81 c0 be 97 79 98 40 fb 4f 6d 14 fd 2b 13 8b c2 |....y.@.Om..+...| +00000140 a5 2e 67 d8 d4 09 9e d6 22 38 b7 4a 0b 74 73 2b |..g....."8.J.ts+| +00000150 c2 34 f1 d1 93 e5 96 d9 74 7b f3 58 9f 6c 61 3c |.4......t{.X.la<| +00000160 c0 b0 41 d4 d9 2b 2b 24 23 77 5b 1c 3b bd 75 5d |..A..++$#w[.;.u]| +00000170 ce 20 54 cf a1 63 87 1d 1e 24 c4 f3 1d 1a 50 8b |. T..c...$....P.| +00000180 aa b6 14 43 ed 97 a7 75 62 f4 14 c8 52 d7 02 03 |...C...ub...R...| +00000190 01 00 01 a3 81 93 30 81 90 30 0e 06 03 55 1d 0f |......0..0...U..| +000001a0 01 01 ff 04 04 03 02 05 a0 30 1d 06 03 55 1d 25 |.........0...U.%| +000001b0 04 16 30 14 06 08 2b 06 01 05 05 07 03 01 06 08 |..0...+.........| +000001c0 2b 06 01 05 05 07 03 02 30 0c 06 03 55 1d 13 01 |+.......0...U...| +000001d0 01 ff 04 02 30 00 30 19 06 03 55 1d 0e 04 12 04 |....0.0...U.....| +000001e0 10 9f 91 16 1f 43 43 3e 49 a6 de 6d b6 80 d7 9f |.....CC>I..m....| +000001f0 60 30 1b 06 03 55 1d 23 04 14 30 12 80 10 48 13 |`0...U.#..0...H.| +00000200 49 4d 13 7e 16 31 bb a3 01 d5 ac ab 6e 7b 30 19 |IM.~.1......n{0.| +00000210 06 03 55 1d 11 04 12 30 10 82 0e 65 78 61 6d 70 |..U....0...examp| +00000220 6c 65 2e 67 6f 6c 61 6e 67 30 0d 06 09 2a 86 48 |le.golang0...*.H| +00000230 86 f7 0d 01 01 0b 05 00 03 81 81 00 9d 30 cc 40 |.............0.@| +00000240 2b 5b 50 a0 61 cb ba e5 53 58 e1 ed 83 28 a9 58 |+[P.a...SX...(.X| +00000250 1a a9 38 a4 95 a1 ac 31 5a 1a 84 66 3d 43 d3 2d |..8....1Z..f=C.-| +00000260 d9 0b f2 97 df d3 20 64 38 92 24 3a 00 bc cf 9c |...... d8.$:....| +00000270 7d b7 40 20 01 5f aa d3 16 61 09 a2 76 fd 13 c3 |}.@ ._...a..v...| +00000280 cc e1 0c 5c ee b1 87 82 f1 6c 04 ed 73 bb b3 43 |...\.....l..s..C| +00000290 77 8d 0c 1c f1 0f a1 d8 40 83 61 c9 4c 72 2b 9d |w.......@.a.Lr+.| +000002a0 ae db 46 06 06 4d f4 c1 b3 3e c0 d1 bd 42 d4 db |..F..M...>...B..| +000002b0 fe 3d 13 60 84 5c 21 d3 3b e9 fa e7 16 03 01 00 |.=.`.\!.;.......| +000002c0 aa 0c 00 00 a6 03 00 1d 20 a0 0e 1d 92 2d b0 a5 |........ ....-..| +000002d0 f0 ab d5 79 a0 bb 12 ff 23 46 bc 27 0d 73 ff 3e |...y....#F.'.s.>| +000002e0 ad 06 d6 57 6b c2 11 76 2d 00 80 77 bf cd 2b cb |...Wk..v-..w..+.| +000002f0 66 c2 fa 30 ed b1 e7 44 79 1b 28 e6 89 62 17 07 |f..0...Dy.(..b..| +00000300 82 c1 5f dc b2 20 4e 42 ed 54 d6 28 3a 2a e3 a3 |.._.. NB.T.(:*..| +00000310 79 06 e3 08 3c c1 3e b9 c6 41 71 2f d0 29 82 36 |y...<.>..Aq/.).6| +00000320 ef 8d 67 c8 77 d0 32 d3 33 5f 77 92 dd 98 bb 03 |..g.w.2.3_w.....| +00000330 cc 0b a6 75 8f 4a 1d f5 6e 1b 06 5b 4a 8b 16 a4 |...u.J..n..[J...| +00000340 c1 ce 11 9d 70 bc 62 7f 58 a5 86 76 91 3d 3a 04 |....p.b.X..v.=:.| +00000350 93 92 89 42 9b a7 7d 9d 75 25 6d 98 f3 e6 68 7e |...B..}.u%m...h~| +00000360 a8 c6 b1 db a7 95 63 39 94 5a 05 16 03 01 00 04 |......c9.Z......| +00000370 0e 00 00 00 |....| +>>> Flow 3 (client to server) +00000000 16 03 01 00 25 10 00 00 21 20 2f e5 7d a3 47 cd |....%...! /.}.G.| +00000010 62 43 15 28 da ac 5f bb 29 07 30 ff f6 84 af c4 |bC.(.._.).0.....| +00000020 cf c2 ed 90 99 5f 58 cb 3b 74 14 03 01 00 01 01 |....._X.;t......| +00000030 16 03 01 00 30 73 ad 46 66 66 e8 bd 44 e4 bf 71 |....0s.Fff..D..q| +00000040 a2 d4 87 e2 4b a3 4a b2 a0 ca ed ac 61 8c 1e 7f |....K.J.....a...| +00000050 68 bf 6f 98 b1 fb 10 1a 5a e6 36 61 91 ac c4 55 |h.o.....Z.6a...U| +00000060 a3 4d 69 66 6e |.Mifn| +>>> Flow 4 (server to client) +00000000 14 03 01 00 01 01 16 03 01 00 30 57 aa 5c d5 dc |..........0W.\..| +00000010 83 4b 23 80 34 4e 36 e8 d6 f3 40 7e ae 12 44 a6 |.K#.4N6...@~..D.| +00000020 c7 48 99 99 0a 85 3c 59 75 32 4e 88 3c 98 a0 23 |.H....>> Flow 5 (client to server) +00000000 17 03 01 00 20 e4 9c f4 fa 6b e8 85 87 6f 20 45 |.... ....k...o E| +00000010 71 d3 e2 9e e3 14 2a 7c 64 e8 11 53 fd 93 c1 4a |q.....*|d..S...J| +00000020 1b 94 f8 48 78 17 03 01 00 20 b9 41 32 1d e8 70 |...Hx.... .A2..p| +00000030 87 5f 2c c6 67 d1 77 3c 30 83 0c 66 35 eb 1d da |._,.g.w<0..f5...| +00000040 6e dd 30 ff 82 05 5f f1 cd e7 15 03 01 00 20 6c |n.0..._....... l| +00000050 47 82 5e 90 5b 84 15 78 05 bd 48 63 d5 46 2f 7e |G.^.[..x..Hc.F/~| +00000060 83 49 ce 3c 0f 04 92 52 5b e7 d5 cf 2c bf 65 |.I.<...R[...,.e| diff --git a/src/crypto/tls/testdata/Client-TLSv12-ExportKeyingMaterial b/src/crypto/tls/testdata/Client-TLSv12-ExportKeyingMaterial new file mode 100644 index 0000000000000..29964f0d40718 --- /dev/null +++ b/src/crypto/tls/testdata/Client-TLSv12-ExportKeyingMaterial @@ -0,0 +1,84 @@ +>>> Flow 1 (client to server) +00000000 16 03 01 00 95 01 00 00 91 03 03 00 00 00 00 00 |................| +00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 2c cc a8 |.............,..| +00000030 cc a9 c0 2f c0 2b c0 30 c0 2c c0 27 c0 13 c0 23 |.../.+.0.,.'...#| +00000040 c0 09 c0 14 c0 0a 00 9c 00 9d 00 3c 00 2f 00 35 |...........<./.5| +00000050 c0 12 00 0a 00 05 c0 11 c0 07 01 00 00 3c 00 05 |.............<..| +00000060 00 05 01 00 00 00 00 00 0a 00 0a 00 08 00 1d 00 |................| +00000070 17 00 18 00 19 00 0b 00 02 01 00 00 0d 00 12 00 |................| +00000080 10 04 01 04 03 05 01 05 03 06 01 06 03 02 01 02 |................| +00000090 03 ff 01 00 01 00 00 12 00 00 |..........| +>>> Flow 2 (server to client) +00000000 16 03 03 00 59 02 00 00 55 03 03 fc 37 e8 a4 e3 |....Y...U...7...| +00000010 5d da a5 95 0b fb e0 c3 d9 78 8b 91 bd 5c 1c b1 |]........x...\..| +00000020 c6 8d 69 62 f9 c6 0f 12 da 46 ba 20 34 a3 22 f2 |..ib.....F. 4.".| +00000030 a9 f7 da 3a c4 5f 6f f7 4b be df 03 e5 b6 d0 ff |...:._o.K.......| +00000040 ca 54 68 59 57 53 63 a5 2f 91 1d 1e cc a8 00 00 |.ThYWSc./.......| +00000050 0d ff 01 00 01 00 00 0b 00 04 03 00 01 02 16 03 |................| +00000060 03 02 59 0b 00 02 55 00 02 52 00 02 4f 30 82 02 |..Y...U..R..O0..| +00000070 4b 30 82 01 b4 a0 03 02 01 02 02 09 00 e8 f0 9d |K0..............| +00000080 3f e2 5b ea a6 30 0d 06 09 2a 86 48 86 f7 0d 01 |?.[..0...*.H....| +00000090 01 0b 05 00 30 1f 31 0b 30 09 06 03 55 04 0a 13 |....0.1.0...U...| +000000a0 02 47 6f 31 10 30 0e 06 03 55 04 03 13 07 47 6f |.Go1.0...U....Go| +000000b0 20 52 6f 6f 74 30 1e 17 0d 31 36 30 31 30 31 30 | Root0...1601010| +000000c0 30 30 30 30 30 5a 17 0d 32 35 30 31 30 31 30 30 |00000Z..25010100| +000000d0 30 30 30 30 5a 30 1a 31 0b 30 09 06 03 55 04 0a |0000Z0.1.0...U..| +000000e0 13 02 47 6f 31 0b 30 09 06 03 55 04 03 13 02 47 |..Go1.0...U....G| +000000f0 6f 30 81 9f 30 0d 06 09 2a 86 48 86 f7 0d 01 01 |o0..0...*.H.....| +00000100 01 05 00 03 81 8d 00 30 81 89 02 81 81 00 db 46 |.......0.......F| +00000110 7d 93 2e 12 27 06 48 bc 06 28 21 ab 7e c4 b6 a2 |}...'.H..(!.~...| +00000120 5d fe 1e 52 45 88 7a 36 47 a5 08 0d 92 42 5b c2 |]..RE.z6G....B[.| +00000130 81 c0 be 97 79 98 40 fb 4f 6d 14 fd 2b 13 8b c2 |....y.@.Om..+...| +00000140 a5 2e 67 d8 d4 09 9e d6 22 38 b7 4a 0b 74 73 2b |..g....."8.J.ts+| +00000150 c2 34 f1 d1 93 e5 96 d9 74 7b f3 58 9f 6c 61 3c |.4......t{.X.la<| +00000160 c0 b0 41 d4 d9 2b 2b 24 23 77 5b 1c 3b bd 75 5d |..A..++$#w[.;.u]| +00000170 ce 20 54 cf a1 63 87 1d 1e 24 c4 f3 1d 1a 50 8b |. T..c...$....P.| +00000180 aa b6 14 43 ed 97 a7 75 62 f4 14 c8 52 d7 02 03 |...C...ub...R...| +00000190 01 00 01 a3 81 93 30 81 90 30 0e 06 03 55 1d 0f |......0..0...U..| +000001a0 01 01 ff 04 04 03 02 05 a0 30 1d 06 03 55 1d 25 |.........0...U.%| +000001b0 04 16 30 14 06 08 2b 06 01 05 05 07 03 01 06 08 |..0...+.........| +000001c0 2b 06 01 05 05 07 03 02 30 0c 06 03 55 1d 13 01 |+.......0...U...| +000001d0 01 ff 04 02 30 00 30 19 06 03 55 1d 0e 04 12 04 |....0.0...U.....| +000001e0 10 9f 91 16 1f 43 43 3e 49 a6 de 6d b6 80 d7 9f |.....CC>I..m....| +000001f0 60 30 1b 06 03 55 1d 23 04 14 30 12 80 10 48 13 |`0...U.#..0...H.| +00000200 49 4d 13 7e 16 31 bb a3 01 d5 ac ab 6e 7b 30 19 |IM.~.1......n{0.| +00000210 06 03 55 1d 11 04 12 30 10 82 0e 65 78 61 6d 70 |..U....0...examp| +00000220 6c 65 2e 67 6f 6c 61 6e 67 30 0d 06 09 2a 86 48 |le.golang0...*.H| +00000230 86 f7 0d 01 01 0b 05 00 03 81 81 00 9d 30 cc 40 |.............0.@| +00000240 2b 5b 50 a0 61 cb ba e5 53 58 e1 ed 83 28 a9 58 |+[P.a...SX...(.X| +00000250 1a a9 38 a4 95 a1 ac 31 5a 1a 84 66 3d 43 d3 2d |..8....1Z..f=C.-| +00000260 d9 0b f2 97 df d3 20 64 38 92 24 3a 00 bc cf 9c |...... d8.$:....| +00000270 7d b7 40 20 01 5f aa d3 16 61 09 a2 76 fd 13 c3 |}.@ ._...a..v...| +00000280 cc e1 0c 5c ee b1 87 82 f1 6c 04 ed 73 bb b3 43 |...\.....l..s..C| +00000290 77 8d 0c 1c f1 0f a1 d8 40 83 61 c9 4c 72 2b 9d |w.......@.a.Lr+.| +000002a0 ae db 46 06 06 4d f4 c1 b3 3e c0 d1 bd 42 d4 db |..F..M...>...B..| +000002b0 fe 3d 13 60 84 5c 21 d3 3b e9 fa e7 16 03 03 00 |.=.`.\!.;.......| +000002c0 ac 0c 00 00 a8 03 00 1d 20 cc e9 71 f5 36 52 5a |........ ..q.6RZ| +000002d0 d8 19 ce e4 0d 41 8d a6 9b f3 19 56 8d 81 fe 84 |.....A.....V....| +000002e0 71 2f d7 fb e7 86 23 4c 04 04 01 00 80 90 da 29 |q/....#L.......)| +000002f0 79 18 70 e8 81 66 83 70 97 f1 d1 5f dc 1d a2 0a |y.p..f.p..._....| +00000300 94 d8 e8 b8 32 4f 03 34 0b af e8 2d 94 b2 eb 30 |....2O.4...-...0| +00000310 57 b5 a5 92 9e 9a df a6 bc 3e 25 0e 18 cb ea 84 |W........>%.....| +00000320 34 89 08 8a d4 be 16 a3 5d 3a 7d 32 10 9b 41 1c |4.......]:}2..A.| +00000330 2a 1e 05 68 5f fa d9 56 30 b6 44 08 b0 a5 25 5a |*..h_..V0.D...%Z| +00000340 c3 60 c0 9a 98 fd 48 5f a4 18 d0 15 0f fb b3 ea |.`....H_........| +00000350 b9 c4 e3 c6 0c 27 51 64 01 de 65 78 c7 a0 57 df |.....'Qd..ex..W.| +00000360 9b de 2f 74 bc 72 e5 e0 57 7c 59 e6 ae 16 03 03 |../t.r..W|Y.....| +00000370 00 04 0e 00 00 00 |......| +>>> Flow 3 (client to server) +00000000 16 03 03 00 25 10 00 00 21 20 2f e5 7d a3 47 cd |....%...! /.}.G.| +00000010 62 43 15 28 da ac 5f bb 29 07 30 ff f6 84 af c4 |bC.(.._.).0.....| +00000020 cf c2 ed 90 99 5f 58 cb 3b 74 14 03 03 00 01 01 |....._X.;t......| +00000030 16 03 03 00 20 92 0a 4e aa 2d b3 9b c8 b9 80 28 |.... ..N.-.....(| +00000040 f3 22 e2 57 15 ff a1 9a 33 9b e8 4c 5c dc f4 29 |.".W....3..L\..)| +00000050 7d 25 d7 df bc |}%...| +>>> Flow 4 (server to client) +00000000 14 03 03 00 01 01 16 03 03 00 20 91 85 06 0e 00 |.......... .....| +00000010 ad 96 2e 1c a5 4d f7 63 f9 84 1c 6e da 54 0b e0 |.....M.c...n.T..| +00000020 44 37 6a 90 4c fd f5 e8 45 1d ce |D7j.L...E..| +>>> Flow 5 (client to server) +00000000 17 03 03 00 16 4c e8 8a e0 a6 95 f3 df 37 8a 2d |.....L.......7.-| +00000010 4f 11 ce a6 53 16 2c b0 bb c5 7f 15 03 03 00 12 |O...S.,.........| +00000020 4e 91 d8 67 c5 16 d2 4e cc b8 0a 00 76 91 68 7a |N..g...N....v.hz| +00000030 85 2e |..| diff --git a/src/crypto/tls/testdata/Server-TLSv10-ExportKeyingMaterial b/src/crypto/tls/testdata/Server-TLSv10-ExportKeyingMaterial new file mode 100644 index 0000000000000..84e0e37005fba --- /dev/null +++ b/src/crypto/tls/testdata/Server-TLSv10-ExportKeyingMaterial @@ -0,0 +1,92 @@ +>>> Flow 1 (client to server) +00000000 16 03 01 00 61 01 00 00 5d 03 01 f4 ec 99 73 ec |....a...].....s.| +00000010 36 30 c7 0b 26 33 a2 c4 26 8e 9f 04 f7 5b e7 4f |60..&3..&....[.O| +00000020 86 85 14 bf f7 49 96 a4 ae c9 1d 00 00 12 c0 0a |.....I..........| +00000030 c0 14 00 39 c0 09 c0 13 00 33 00 35 00 2f 00 ff |...9.....3.5./..| +00000040 01 00 00 22 00 0b 00 04 03 00 01 02 00 0a 00 0a |..."............| +00000050 00 08 00 1d 00 17 00 19 00 18 00 23 00 00 00 16 |...........#....| +00000060 00 00 00 17 00 00 |......| +>>> Flow 2 (server to client) +00000000 16 03 01 00 35 02 00 00 31 03 01 00 00 00 00 00 |....5...1.......| +00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000020 00 00 00 00 00 00 00 00 00 00 00 00 c0 14 00 00 |................| +00000030 09 00 23 00 00 ff 01 00 01 00 16 03 01 02 59 0b |..#...........Y.| +00000040 00 02 55 00 02 52 00 02 4f 30 82 02 4b 30 82 01 |..U..R..O0..K0..| +00000050 b4 a0 03 02 01 02 02 09 00 e8 f0 9d 3f e2 5b ea |............?.[.| +00000060 a6 30 0d 06 09 2a 86 48 86 f7 0d 01 01 0b 05 00 |.0...*.H........| +00000070 30 1f 31 0b 30 09 06 03 55 04 0a 13 02 47 6f 31 |0.1.0...U....Go1| +00000080 10 30 0e 06 03 55 04 03 13 07 47 6f 20 52 6f 6f |.0...U....Go Roo| +00000090 74 30 1e 17 0d 31 36 30 31 30 31 30 30 30 30 30 |t0...16010100000| +000000a0 30 5a 17 0d 32 35 30 31 30 31 30 30 30 30 30 30 |0Z..250101000000| +000000b0 5a 30 1a 31 0b 30 09 06 03 55 04 0a 13 02 47 6f |Z0.1.0...U....Go| +000000c0 31 0b 30 09 06 03 55 04 03 13 02 47 6f 30 81 9f |1.0...U....Go0..| +000000d0 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 |0...*.H.........| +000000e0 81 8d 00 30 81 89 02 81 81 00 db 46 7d 93 2e 12 |...0.......F}...| +000000f0 27 06 48 bc 06 28 21 ab 7e c4 b6 a2 5d fe 1e 52 |'.H..(!.~...]..R| +00000100 45 88 7a 36 47 a5 08 0d 92 42 5b c2 81 c0 be 97 |E.z6G....B[.....| +00000110 79 98 40 fb 4f 6d 14 fd 2b 13 8b c2 a5 2e 67 d8 |y.@.Om..+.....g.| +00000120 d4 09 9e d6 22 38 b7 4a 0b 74 73 2b c2 34 f1 d1 |...."8.J.ts+.4..| +00000130 93 e5 96 d9 74 7b f3 58 9f 6c 61 3c c0 b0 41 d4 |....t{.X.la<..A.| +00000140 d9 2b 2b 24 23 77 5b 1c 3b bd 75 5d ce 20 54 cf |.++$#w[.;.u]. T.| +00000150 a1 63 87 1d 1e 24 c4 f3 1d 1a 50 8b aa b6 14 43 |.c...$....P....C| +00000160 ed 97 a7 75 62 f4 14 c8 52 d7 02 03 01 00 01 a3 |...ub...R.......| +00000170 81 93 30 81 90 30 0e 06 03 55 1d 0f 01 01 ff 04 |..0..0...U......| +00000180 04 03 02 05 a0 30 1d 06 03 55 1d 25 04 16 30 14 |.....0...U.%..0.| +00000190 06 08 2b 06 01 05 05 07 03 01 06 08 2b 06 01 05 |..+.........+...| +000001a0 05 07 03 02 30 0c 06 03 55 1d 13 01 01 ff 04 02 |....0...U.......| +000001b0 30 00 30 19 06 03 55 1d 0e 04 12 04 10 9f 91 16 |0.0...U.........| +000001c0 1f 43 43 3e 49 a6 de 6d b6 80 d7 9f 60 30 1b 06 |.CC>I..m....`0..| +000001d0 03 55 1d 23 04 14 30 12 80 10 48 13 49 4d 13 7e |.U.#..0...H.IM.~| +000001e0 16 31 bb a3 01 d5 ac ab 6e 7b 30 19 06 03 55 1d |.1......n{0...U.| +000001f0 11 04 12 30 10 82 0e 65 78 61 6d 70 6c 65 2e 67 |...0...example.g| +00000200 6f 6c 61 6e 67 30 0d 06 09 2a 86 48 86 f7 0d 01 |olang0...*.H....| +00000210 01 0b 05 00 03 81 81 00 9d 30 cc 40 2b 5b 50 a0 |.........0.@+[P.| +00000220 61 cb ba e5 53 58 e1 ed 83 28 a9 58 1a a9 38 a4 |a...SX...(.X..8.| +00000230 95 a1 ac 31 5a 1a 84 66 3d 43 d3 2d d9 0b f2 97 |...1Z..f=C.-....| +00000240 df d3 20 64 38 92 24 3a 00 bc cf 9c 7d b7 40 20 |.. d8.$:....}.@ | +00000250 01 5f aa d3 16 61 09 a2 76 fd 13 c3 cc e1 0c 5c |._...a..v......\| +00000260 ee b1 87 82 f1 6c 04 ed 73 bb b3 43 77 8d 0c 1c |.....l..s..Cw...| +00000270 f1 0f a1 d8 40 83 61 c9 4c 72 2b 9d ae db 46 06 |....@.a.Lr+...F.| +00000280 06 4d f4 c1 b3 3e c0 d1 bd 42 d4 db fe 3d 13 60 |.M...>...B...=.`| +00000290 84 5c 21 d3 3b e9 fa e7 16 03 01 00 aa 0c 00 00 |.\!.;...........| +000002a0 a6 03 00 1d 20 2f e5 7d a3 47 cd 62 43 15 28 da |.... /.}.G.bC.(.| +000002b0 ac 5f bb 29 07 30 ff f6 84 af c4 cf c2 ed 90 99 |._.).0..........| +000002c0 5f 58 cb 3b 74 00 80 8e fe 28 f2 06 d8 b9 d6 74 |_X.;t....(.....t| +000002d0 72 34 dc fa 00 38 56 1a fc a1 68 e8 ca 8f 7a 61 |r4...8V...h...za| +000002e0 92 e2 2a 63 ce 4d 96 c6 bb 84 82 41 2d 97 35 13 |..*c.M.....A-.5.| +000002f0 e1 ff 4c ec f2 e6 62 16 15 35 da 8a 57 55 cb 28 |..L...b..5..WU.(| +00000300 26 35 e6 86 00 b0 92 44 b7 40 7b 6a c4 b0 b8 10 |&5.....D.@{j....| +00000310 b7 16 97 a7 26 eb 1e 0b 99 b3 22 4a 6b 7f 0b 69 |....&....."Jk..i| +00000320 0d 21 1e 33 6d fd 78 b5 62 68 53 db 62 69 ba b4 |.!.3m.x.bhS.bi..| +00000330 bc 74 b3 d4 ce a2 41 d7 ba 62 aa cc b2 39 65 86 |.t....A..b...9e.| +00000340 5f 00 68 e2 16 a5 13 16 03 01 00 04 0e 00 00 00 |_.h.............| +>>> Flow 3 (client to server) +00000000 16 03 01 00 25 10 00 00 21 20 81 08 e4 37 1d 03 |....%...! ...7..| +00000010 87 5a 00 68 ae 49 76 08 4a e2 20 82 0b e5 7c 3e |.Z.h.Iv.J. ...|>| +00000020 90 49 9b c3 b9 c7 c9 3c 29 24 14 03 01 00 01 01 |.I.....<)$......| +00000030 16 03 01 00 30 33 07 d5 08 ca ae f9 70 50 93 0a |....03......pP..| +00000040 55 2e e0 df 1d 88 ae 1e 06 17 47 64 a3 52 36 37 |U.........Gd.R67| +00000050 d5 ca f1 b1 d2 76 7b f8 89 59 13 e9 ab b1 cb dc |.....v{..Y......| +00000060 1f a8 89 f4 2f |..../| +>>> Flow 4 (server to client) +00000000 16 03 01 00 82 04 00 00 7e 00 00 00 00 00 78 50 |........~.....xP| +00000010 46 ad c1 db a8 38 86 7b 2b bb fd d0 c3 42 3e 00 |F....8.{+....B>.| +00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 94 |................| +00000030 6d ec a4 83 61 a4 a1 9c 14 de f8 59 c8 c7 f0 10 |m...a......Y....| +00000040 08 fe c9 37 29 ed 47 05 d2 bd a8 4c 05 b9 8c f8 |...7).G....L....| +00000050 b5 4d e4 a6 30 0f 49 4a b1 73 1f 89 73 c8 bb 36 |.M..0.IJ.s..s..6| +00000060 14 9d d2 95 70 33 94 fb 82 e6 fe 3e 64 8c 9d e8 |....p3.....>d...| +00000070 e3 e5 93 3d fe 4e 23 a3 97 8a a3 91 80 c9 00 01 |...=.N#.........| +00000080 a6 f0 47 cf 11 a6 90 14 03 01 00 01 01 16 03 01 |..G.............| +00000090 00 30 1f 70 17 a1 30 82 5a 32 e7 aa a1 7f 1b f6 |.0.p..0.Z2......| +000000a0 d8 aa 6a 51 64 1b 4a f1 94 12 08 2f 5d 95 fe 83 |..jQd.J..../]...| +000000b0 52 c8 3b d4 58 73 50 19 b8 08 61 b3 3a 5d f6 d3 |R.;.XsP...a.:]..| +000000c0 67 e6 17 03 01 00 20 bd 79 44 08 9d 86 cf 5e e9 |g..... .yD....^.| +000000d0 e4 3c 80 ed b7 18 10 07 0f 42 85 ca a4 51 fd 9b |.<.......B...Q..| +000000e0 38 3e 04 7e 72 6e 80 17 03 01 00 30 2c 46 c2 71 |8>.~rn.....0,F.q| +000000f0 4a 83 46 eb 63 87 f5 83 b4 72 70 4f a3 59 b3 ff |J.F.c....rpO.Y..| +00000100 3c 00 74 12 db 33 51 4c 7c e0 c1 27 44 20 68 25 |<.t..3QL|..'D h%| +00000110 95 f1 37 2a 24 f1 85 a3 5a e4 50 fe 15 03 01 00 |..7*$...Z.P.....| +00000120 20 72 01 cc 74 d5 b4 6b 05 ce de f0 b4 fe 4f 6b | r..t..k......Ok| +00000130 a8 8f ad 5a c2 7d 40 65 d6 a2 57 52 b8 8a c5 4f |...Z.}@e..WR...O| +00000140 d9 |.| diff --git a/src/crypto/tls/testdata/Server-TLSv12-ExportKeyingMaterial b/src/crypto/tls/testdata/Server-TLSv12-ExportKeyingMaterial new file mode 100644 index 0000000000000..6415c42928dc0 --- /dev/null +++ b/src/crypto/tls/testdata/Server-TLSv12-ExportKeyingMaterial @@ -0,0 +1,92 @@ +>>> Flow 1 (client to server) +00000000 16 03 01 00 ab 01 00 00 a7 03 03 7a 49 9d 20 62 |...........zI. b| +00000010 45 8d 0c 1e 8e eb b1 5e 73 62 6d 48 61 31 cb 1a |E......^sbmHa1..| +00000020 89 b2 68 1b 2c cb 35 87 2a 17 fb 00 00 38 c0 2c |..h.,.5.*....8.,| +00000030 c0 30 00 9f cc a9 cc a8 cc aa c0 2b c0 2f 00 9e |.0.........+./..| +00000040 c0 24 c0 28 00 6b c0 23 c0 27 00 67 c0 0a c0 14 |.$.(.k.#.'.g....| +00000050 00 39 c0 09 c0 13 00 33 00 9d 00 9c 00 3d 00 3c |.9.....3.....=.<| +00000060 00 35 00 2f 00 ff 01 00 00 46 00 0b 00 04 03 00 |.5./.....F......| +00000070 01 02 00 0a 00 0a 00 08 00 1d 00 17 00 19 00 18 |................| +00000080 00 23 00 00 00 16 00 00 00 17 00 00 00 0d 00 20 |.#............. | +00000090 00 1e 06 01 06 02 06 03 05 01 05 02 05 03 04 01 |................| +000000a0 04 02 04 03 03 01 03 02 03 03 02 01 02 02 02 03 |................| +>>> Flow 2 (server to client) +00000000 16 03 03 00 35 02 00 00 31 03 03 00 00 00 00 00 |....5...1.......| +00000010 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| +00000020 00 00 00 00 00 00 00 00 00 00 00 00 c0 30 00 00 |.............0..| +00000030 09 00 23 00 00 ff 01 00 01 00 16 03 03 02 59 0b |..#...........Y.| +00000040 00 02 55 00 02 52 00 02 4f 30 82 02 4b 30 82 01 |..U..R..O0..K0..| +00000050 b4 a0 03 02 01 02 02 09 00 e8 f0 9d 3f e2 5b ea |............?.[.| +00000060 a6 30 0d 06 09 2a 86 48 86 f7 0d 01 01 0b 05 00 |.0...*.H........| +00000070 30 1f 31 0b 30 09 06 03 55 04 0a 13 02 47 6f 31 |0.1.0...U....Go1| +00000080 10 30 0e 06 03 55 04 03 13 07 47 6f 20 52 6f 6f |.0...U....Go Roo| +00000090 74 30 1e 17 0d 31 36 30 31 30 31 30 30 30 30 30 |t0...16010100000| +000000a0 30 5a 17 0d 32 35 30 31 30 31 30 30 30 30 30 30 |0Z..250101000000| +000000b0 5a 30 1a 31 0b 30 09 06 03 55 04 0a 13 02 47 6f |Z0.1.0...U....Go| +000000c0 31 0b 30 09 06 03 55 04 03 13 02 47 6f 30 81 9f |1.0...U....Go0..| +000000d0 30 0d 06 09 2a 86 48 86 f7 0d 01 01 01 05 00 03 |0...*.H.........| +000000e0 81 8d 00 30 81 89 02 81 81 00 db 46 7d 93 2e 12 |...0.......F}...| +000000f0 27 06 48 bc 06 28 21 ab 7e c4 b6 a2 5d fe 1e 52 |'.H..(!.~...]..R| +00000100 45 88 7a 36 47 a5 08 0d 92 42 5b c2 81 c0 be 97 |E.z6G....B[.....| +00000110 79 98 40 fb 4f 6d 14 fd 2b 13 8b c2 a5 2e 67 d8 |y.@.Om..+.....g.| +00000120 d4 09 9e d6 22 38 b7 4a 0b 74 73 2b c2 34 f1 d1 |...."8.J.ts+.4..| +00000130 93 e5 96 d9 74 7b f3 58 9f 6c 61 3c c0 b0 41 d4 |....t{.X.la<..A.| +00000140 d9 2b 2b 24 23 77 5b 1c 3b bd 75 5d ce 20 54 cf |.++$#w[.;.u]. T.| +00000150 a1 63 87 1d 1e 24 c4 f3 1d 1a 50 8b aa b6 14 43 |.c...$....P....C| +00000160 ed 97 a7 75 62 f4 14 c8 52 d7 02 03 01 00 01 a3 |...ub...R.......| +00000170 81 93 30 81 90 30 0e 06 03 55 1d 0f 01 01 ff 04 |..0..0...U......| +00000180 04 03 02 05 a0 30 1d 06 03 55 1d 25 04 16 30 14 |.....0...U.%..0.| +00000190 06 08 2b 06 01 05 05 07 03 01 06 08 2b 06 01 05 |..+.........+...| +000001a0 05 07 03 02 30 0c 06 03 55 1d 13 01 01 ff 04 02 |....0...U.......| +000001b0 30 00 30 19 06 03 55 1d 0e 04 12 04 10 9f 91 16 |0.0...U.........| +000001c0 1f 43 43 3e 49 a6 de 6d b6 80 d7 9f 60 30 1b 06 |.CC>I..m....`0..| +000001d0 03 55 1d 23 04 14 30 12 80 10 48 13 49 4d 13 7e |.U.#..0...H.IM.~| +000001e0 16 31 bb a3 01 d5 ac ab 6e 7b 30 19 06 03 55 1d |.1......n{0...U.| +000001f0 11 04 12 30 10 82 0e 65 78 61 6d 70 6c 65 2e 67 |...0...example.g| +00000200 6f 6c 61 6e 67 30 0d 06 09 2a 86 48 86 f7 0d 01 |olang0...*.H....| +00000210 01 0b 05 00 03 81 81 00 9d 30 cc 40 2b 5b 50 a0 |.........0.@+[P.| +00000220 61 cb ba e5 53 58 e1 ed 83 28 a9 58 1a a9 38 a4 |a...SX...(.X..8.| +00000230 95 a1 ac 31 5a 1a 84 66 3d 43 d3 2d d9 0b f2 97 |...1Z..f=C.-....| +00000240 df d3 20 64 38 92 24 3a 00 bc cf 9c 7d b7 40 20 |.. d8.$:....}.@ | +00000250 01 5f aa d3 16 61 09 a2 76 fd 13 c3 cc e1 0c 5c |._...a..v......\| +00000260 ee b1 87 82 f1 6c 04 ed 73 bb b3 43 77 8d 0c 1c |.....l..s..Cw...| +00000270 f1 0f a1 d8 40 83 61 c9 4c 72 2b 9d ae db 46 06 |....@.a.Lr+...F.| +00000280 06 4d f4 c1 b3 3e c0 d1 bd 42 d4 db fe 3d 13 60 |.M...>...B...=.`| +00000290 84 5c 21 d3 3b e9 fa e7 16 03 03 00 ac 0c 00 00 |.\!.;...........| +000002a0 a8 03 00 1d 20 2f e5 7d a3 47 cd 62 43 15 28 da |.... /.}.G.bC.(.| +000002b0 ac 5f bb 29 07 30 ff f6 84 af c4 cf c2 ed 90 99 |._.).0..........| +000002c0 5f 58 cb 3b 74 06 01 00 80 7f ee dd 6b 38 23 29 |_X.;t.......k8#)| +000002d0 56 ff d2 c2 08 86 52 b6 e3 8a d5 fe 47 79 5e ef |V.....R.....Gy^.| +000002e0 99 7a 0b d7 44 84 b9 2f 7a 2c 64 4f b3 7c aa 44 |.z..D../z,dO.|.D| +000002f0 aa 38 5d 1b 69 16 9f f2 7d f8 24 43 47 ad 31 bc |.8].i...}.$CG.1.| +00000300 f5 3d b8 c8 33 6e 3f 6f 2b ea 19 a2 30 32 2b 2a |.=..3n?o+...02+*| +00000310 81 64 3c ee ed 78 4c fa 80 fd e7 5f ef 85 98 d4 |.d<..xL...._....| +00000320 48 06 b8 f5 5e 1e e6 f3 42 a8 2f 99 5f ea b3 ba |H...^...B./._...| +00000330 8e a8 31 99 85 f2 46 11 a3 d2 c6 81 4b f1 22 7d |..1...F.....K."}| +00000340 d7 45 04 f1 a6 d6 7e 8f 9d 16 03 03 00 04 0e 00 |.E....~.........| +00000350 00 00 |..| +>>> Flow 3 (client to server) +00000000 16 03 03 00 25 10 00 00 21 20 22 e7 e7 61 a9 27 |....%...! "..a.'| +00000010 7b 93 d1 42 76 dd 16 32 e8 92 37 37 2f fd 0d 92 |{..Bv..2..77/...| +00000020 1f 8e b7 c5 69 40 d3 1a 7d 06 14 03 03 00 01 01 |....i@..}.......| +00000030 16 03 03 00 28 4e 7f b2 a2 20 5d cf a1 5a de 42 |....(N... ]..Z.B| +00000040 c5 72 c3 ef c3 23 a7 2c f3 5b 3d a4 81 21 ac db |.r...#.,.[=..!..| +00000050 44 1c f3 a1 83 aa a1 b7 85 9a c7 23 03 |D..........#.| +>>> Flow 4 (server to client) +00000000 16 03 03 00 82 04 00 00 7e 00 00 00 00 00 78 50 |........~.....xP| +00000010 46 ad c1 db a8 38 86 7b 2b bb fd d0 c3 42 3e 00 |F....8.{+....B>.| +00000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 94 |................| +00000030 6f ec 80 83 61 3f 55 e3 9d ab 39 87 5b d0 ba 44 |o...a?U...9.[..D| +00000040 07 91 a8 d0 37 8a 7e 51 0d 00 97 ec 1b 61 f3 3b |....7.~Q.....a.;| +00000050 9f 29 24 d5 98 f7 4d 3b 80 ef 2f 4d aa 02 98 93 |.)$...M;../M....| +00000060 81 03 87 d8 06 33 94 f5 ed 5d cc 8f 57 97 70 26 |.....3...]..W.p&| +00000070 00 dc 0d d2 96 16 a2 6d fc be 8d 4b fa 5f b3 04 |.......m...K._..| +00000080 ce bb 48 ee c0 75 23 14 03 03 00 01 01 16 03 03 |..H..u#.........| +00000090 00 28 00 00 00 00 00 00 00 00 3a 69 e0 40 e2 d1 |.(........:i.@..| +000000a0 a6 96 33 0f b3 58 5a dc 41 ea d1 80 44 66 9f 2e |..3..XZ.A...Df..| +000000b0 00 e4 9e 10 13 56 b4 1b c9 42 17 03 03 00 25 00 |.....V...B....%.| +000000c0 00 00 00 00 00 00 01 88 f3 d9 5b ed 6b 3c 70 0c |..........[.k Date: Tue, 26 Jun 2018 02:58:54 +0000 Subject: [PATCH 0111/1663] cmd/compile: implement "OPC $imm, (mem)" for 386 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit New read-modify-write operations are introduced in this CL for 386. 1. The total size of pkg/linux_386 decreases about 10KB (excluding cmd/compile). 2. The go1 benchmark shows little regression. name old time/op new time/op delta BinaryTree17-4 3.32s ± 4% 3.29s ± 2% ~ (p=0.059 n=30+30) Fannkuch11-4 3.49s ± 1% 3.46s ± 1% -0.92% (p=0.001 n=30+30) FmtFprintfEmpty-4 47.7ns ± 2% 46.8ns ± 5% -1.93% (p=0.011 n=25+30) FmtFprintfString-4 79.5ns ± 7% 80.2ns ± 3% +0.89% (p=0.001 n=28+29) FmtFprintfInt-4 90.5ns ± 2% 92.1ns ± 2% +1.82% (p=0.014 n=22+30) FmtFprintfIntInt-4 141ns ± 1% 144ns ± 3% +2.23% (p=0.013 n=22+30) FmtFprintfPrefixedInt-4 183ns ± 2% 184ns ± 3% ~ (p=0.080 n=21+30) FmtFprintfFloat-4 409ns ± 3% 412ns ± 3% +0.83% (p=0.040 n=30+30) FmtManyArgs-4 597ns ± 6% 607ns ± 4% +1.71% (p=0.006 n=30+30) GobDecode-4 7.21ms ± 5% 7.18ms ± 6% ~ (p=0.665 n=30+30) GobEncode-4 7.17ms ± 6% 7.09ms ± 7% ~ (p=0.117 n=29+30) Gzip-4 413ms ± 4% 399ms ± 4% -3.48% (p=0.000 n=30+30) Gunzip-4 41.3ms ± 4% 41.7ms ± 3% +1.05% (p=0.011 n=30+30) HTTPClientServer-4 63.5µs ± 3% 62.9µs ± 2% -0.97% (p=0.017 n=30+27) JSONEncode-4 20.3ms ± 5% 20.1ms ± 5% -1.16% (p=0.004 n=30+30) JSONDecode-4 66.2ms ± 4% 67.7ms ± 4% +2.21% (p=0.000 n=30+30) Mandelbrot200-4 5.16ms ± 3% 5.18ms ± 3% ~ (p=0.123 n=30+30) GoParse-4 3.23ms ± 2% 3.27ms ± 2% +1.08% (p=0.006 n=30+30) RegexpMatchEasy0_32-4 98.9ns ± 5% 97.1ns ± 4% -1.83% (p=0.006 n=30+30) RegexpMatchEasy0_1K-4 842ns ± 3% 842ns ± 3% ~ (p=0.550 n=30+30) RegexpMatchEasy1_32-4 107ns ± 4% 105ns ± 4% -1.93% (p=0.012 n=30+30) RegexpMatchEasy1_1K-4 1.03µs ± 4% 1.04µs ± 4% ~ (p=0.304 n=30+30) RegexpMatchMedium_32-4 132ns ± 2% 129ns ± 4% -2.02% (p=0.000 n=21+30) RegexpMatchMedium_1K-4 44.1µs ± 4% 43.8µs ± 3% ~ (p=0.641 n=30+30) RegexpMatchHard_32-4 2.26µs ± 4% 2.23µs ± 4% -1.28% (p=0.023 n=30+30) RegexpMatchHard_1K-4 68.1µs ± 3% 68.6µs ± 4% ~ (p=0.089 n=30+30) Revcomp-4 1.85s ± 2% 1.84s ± 2% ~ (p=0.072 n=30+30) Template-4 69.2ms ± 3% 68.5ms ± 3% -1.04% (p=0.012 n=30+30) TimeParse-4 441ns ± 3% 446ns ± 4% +1.21% (p=0.001 n=30+30) TimeFormat-4 415ns ± 3% 415ns ± 3% ~ (p=0.436 n=30+30) [Geo mean] 67.0µs 66.9µs -0.17% name old speed new speed delta GobDecode-4 107MB/s ± 5% 107MB/s ± 6% ~ (p=0.663 n=30+30) GobEncode-4 107MB/s ± 6% 108MB/s ± 7% ~ (p=0.117 n=29+30) Gzip-4 47.0MB/s ± 4% 48.7MB/s ± 4% +3.61% (p=0.000 n=30+30) Gunzip-4 470MB/s ± 4% 466MB/s ± 4% -1.05% (p=0.011 n=30+30) JSONEncode-4 95.6MB/s ± 5% 96.7MB/s ± 5% +1.16% (p=0.005 n=30+30) JSONDecode-4 29.3MB/s ± 4% 28.7MB/s ± 4% -2.17% (p=0.000 n=30+30) GoParse-4 17.9MB/s ± 2% 17.7MB/s ± 2% -1.06% (p=0.007 n=30+30) RegexpMatchEasy0_32-4 323MB/s ± 5% 329MB/s ± 4% +1.93% (p=0.006 n=30+30) RegexpMatchEasy0_1K-4 1.22GB/s ± 3% 1.22GB/s ± 3% ~ (p=0.496 n=30+30) RegexpMatchEasy1_32-4 298MB/s ± 4% 303MB/s ± 4% +1.84% (p=0.017 n=30+30) RegexpMatchEasy1_1K-4 995MB/s ± 4% 989MB/s ± 4% ~ (p=0.307 n=30+30) RegexpMatchMedium_32-4 7.56MB/s ± 4% 7.74MB/s ± 4% +2.46% (p=0.000 n=22+30) RegexpMatchMedium_1K-4 23.2MB/s ± 4% 23.4MB/s ± 3% ~ (p=0.651 n=30+30) RegexpMatchHard_32-4 14.2MB/s ± 4% 14.3MB/s ± 4% +1.29% (p=0.021 n=30+30) RegexpMatchHard_1K-4 15.0MB/s ± 3% 14.9MB/s ± 4% ~ (p=0.069 n=30+29) Revcomp-4 138MB/s ± 2% 138MB/s ± 2% ~ (p=0.072 n=30+30) Template-4 28.1MB/s ± 3% 28.4MB/s ± 3% +1.05% (p=0.012 n=30+30) [Geo mean] 79.7MB/s 80.2MB/s +0.60% Change-Id: I44a1dfc942c9a385904553c4fe1fa8e509c8aa31 Reviewed-on: https://go-review.googlesource.com/120916 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/gen/386.rules | 8 + src/cmd/compile/internal/ssa/gen/386Ops.go | 6 + src/cmd/compile/internal/ssa/opGen.go | 60 +++ src/cmd/compile/internal/ssa/rewrite386.go | 401 ++++++++++++++++++++- src/cmd/compile/internal/x86/ssa.go | 27 ++ test/codegen/arithmetic.go | 4 + 6 files changed, 505 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/ssa/gen/386.rules b/src/cmd/compile/internal/ssa/gen/386.rules index 127829473b2b3..8131f1117afa4 100644 --- a/src/cmd/compile/internal/ssa/gen/386.rules +++ b/src/cmd/compile/internal/ssa/gen/386.rules @@ -644,6 +644,8 @@ ((ADD|SUB|MUL|DIV)SDload [off1+off2] {sym} val base mem) ((ADD|SUB|AND|OR|XOR)Lmodify [off1] {sym} (ADDLconst [off2] base) val mem) && is32Bit(off1+off2) -> ((ADD|SUB|AND|OR|XOR)Lmodify [off1+off2] {sym} base val mem) +((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym} (ADDLconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> + ((ADD|AND|OR|XOR)Lconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) // Fold constants into stores. (MOVLstore [off] {sym} ptr (MOVLconst [c]) mem) && validOff(off) -> @@ -769,6 +771,9 @@ ((ADD|SUB|AND|OR|XOR)Lmodify [off1] {sym1} (LEAL [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) -> ((ADD|SUB|AND|OR|XOR)Lmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) +((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym1} (LEAL [off2] {sym2} base) mem) + && ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) -> + ((ADD|AND|OR|XOR)Lconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) (MOVBload [off] {sym} (ADDL ptr idx) mem) && ptr.Op != OpSB -> (MOVBloadidx1 [off] {sym} ptr idx mem) (MOVWload [off] {sym} (ADDL ptr idx) mem) && ptr.Op != OpSB -> (MOVWloadidx1 [off] {sym} ptr idx mem) @@ -852,6 +857,9 @@ (MOVLstore {sym} [off] ptr y:((ADD|AND|OR|XOR)Lload x [off] {sym} ptr mem) mem) && y.Uses==1 && clobber(y) -> ((ADD|AND|OR|XOR)Lmodify [off] {sym} ptr x mem) (MOVLstore {sym} [off] ptr y:((ADD|SUB|AND|OR|XOR)L l:(MOVLload [off] {sym} ptr mem) x) mem) && y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) -> ((ADD|SUB|AND|OR|XOR)Lmodify [off] {sym} ptr x mem) +(MOVLstore {sym} [off] ptr y:((ADD|AND|OR|XOR)Lconst [c] l:(MOVLload [off] {sym} ptr mem)) mem) + && y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) && validValAndOff(c,off) -> + ((ADD|AND|OR|XOR)Lconstmodify [makeValAndOff(c,off)] {sym} ptr mem) (MOVBstoreconstidx1 [x] {sym} (ADDLconst [c] ptr) idx mem) -> (MOVBstoreconstidx1 [ValAndOff(x).add(c)] {sym} ptr idx mem) diff --git a/src/cmd/compile/internal/ssa/gen/386Ops.go b/src/cmd/compile/internal/ssa/gen/386Ops.go index 40f4a2b15e3f5..1786eea7cf650 100644 --- a/src/cmd/compile/internal/ssa/gen/386Ops.go +++ b/src/cmd/compile/internal/ssa/gen/386Ops.go @@ -367,6 +367,12 @@ func init() { {name: "ORLmodify", argLength: 3, reg: gpstore, asm: "ORL", aux: "SymOff", typ: "Mem", faultOnNilArg0: true, clobberFlags: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) |= arg1, arg2=mem {name: "XORLmodify", argLength: 3, reg: gpstore, asm: "XORL", aux: "SymOff", typ: "Mem", faultOnNilArg0: true, clobberFlags: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) ^= arg1, arg2=mem + // direct binary-op on memory with a constant (read-modify-write) + {name: "ADDLconstmodify", argLength: 2, reg: gpstoreconst, asm: "ADDL", aux: "SymValAndOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // add ValAndOff(AuxInt).Val() to arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "ANDLconstmodify", argLength: 2, reg: gpstoreconst, asm: "ANDL", aux: "SymValAndOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // and ValAndOff(AuxInt).Val() to arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "ORLconstmodify", argLength: 2, reg: gpstoreconst, asm: "ORL", aux: "SymValAndOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // or ValAndOff(AuxInt).Val() to arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "XORLconstmodify", argLength: 2, reg: gpstoreconst, asm: "XORL", aux: "SymValAndOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // xor ValAndOff(AuxInt).Val() to arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + // indexed loads/stores {name: "MOVBloadidx1", argLength: 3, reg: gploadidx, commutative: true, asm: "MOVBLZX", aux: "SymOff", symEffect: "Read"}, // load a byte from arg0+arg1+auxint+aux. arg2=mem {name: "MOVWloadidx1", argLength: 3, reg: gploadidx, commutative: true, asm: "MOVWLZX", aux: "SymOff", symEffect: "Read"}, // load 2 bytes from arg0+arg1+auxint+aux. arg2=mem diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 8ac47cb2d0db2..704792c9af554 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -394,6 +394,10 @@ const ( Op386ANDLmodify Op386ORLmodify Op386XORLmodify + Op386ADDLconstmodify + Op386ANDLconstmodify + Op386ORLconstmodify + Op386XORLconstmodify Op386MOVBloadidx1 Op386MOVWloadidx1 Op386MOVWloadidx2 @@ -4660,6 +4664,62 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "ADDLconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AADDL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 65791}, // AX CX DX BX SP BP SI DI SB + }, + }, + }, + { + name: "ANDLconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AANDL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 65791}, // AX CX DX BX SP BP SI DI SB + }, + }, + }, + { + name: "ORLconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AORL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 65791}, // AX CX DX BX SP BP SI DI SB + }, + }, + }, + { + name: "XORLconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AXORL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 65791}, // AX CX DX BX SP BP SI DI SB + }, + }, + }, { name: "MOVBloadidx1", auxType: auxSymOff, diff --git a/src/cmd/compile/internal/ssa/rewrite386.go b/src/cmd/compile/internal/ssa/rewrite386.go index 039538ea7dce5..abc1d18309521 100644 --- a/src/cmd/compile/internal/ssa/rewrite386.go +++ b/src/cmd/compile/internal/ssa/rewrite386.go @@ -23,6 +23,8 @@ func rewriteValue386(v *Value) bool { return rewriteValue386_Op386ADDLcarry_0(v) case Op386ADDLconst: return rewriteValue386_Op386ADDLconst_0(v) + case Op386ADDLconstmodify: + return rewriteValue386_Op386ADDLconstmodify_0(v) case Op386ADDLload: return rewriteValue386_Op386ADDLload_0(v) case Op386ADDLmodify: @@ -39,6 +41,8 @@ func rewriteValue386(v *Value) bool { return rewriteValue386_Op386ANDL_0(v) case Op386ANDLconst: return rewriteValue386_Op386ANDLconst_0(v) + case Op386ANDLconstmodify: + return rewriteValue386_Op386ANDLconstmodify_0(v) case Op386ANDLload: return rewriteValue386_Op386ANDLload_0(v) case Op386ANDLmodify: @@ -104,7 +108,7 @@ func rewriteValue386(v *Value) bool { case Op386MOVLloadidx4: return rewriteValue386_Op386MOVLloadidx4_0(v) case Op386MOVLstore: - return rewriteValue386_Op386MOVLstore_0(v) || rewriteValue386_Op386MOVLstore_10(v) + return rewriteValue386_Op386MOVLstore_0(v) || rewriteValue386_Op386MOVLstore_10(v) || rewriteValue386_Op386MOVLstore_20(v) case Op386MOVLstoreconst: return rewriteValue386_Op386MOVLstoreconst_0(v) case Op386MOVLstoreconstidx1: @@ -189,6 +193,8 @@ func rewriteValue386(v *Value) bool { return rewriteValue386_Op386ORL_0(v) || rewriteValue386_Op386ORL_10(v) || rewriteValue386_Op386ORL_20(v) || rewriteValue386_Op386ORL_30(v) || rewriteValue386_Op386ORL_40(v) || rewriteValue386_Op386ORL_50(v) case Op386ORLconst: return rewriteValue386_Op386ORLconst_0(v) + case Op386ORLconstmodify: + return rewriteValue386_Op386ORLconstmodify_0(v) case Op386ORLload: return rewriteValue386_Op386ORLload_0(v) case Op386ORLmodify: @@ -273,6 +279,8 @@ func rewriteValue386(v *Value) bool { return rewriteValue386_Op386XORL_0(v) || rewriteValue386_Op386XORL_10(v) case Op386XORLconst: return rewriteValue386_Op386XORLconst_0(v) + case Op386XORLconstmodify: + return rewriteValue386_Op386XORLconstmodify_0(v) case Op386XORLload: return rewriteValue386_Op386XORLload_0(v) case Op386XORLmodify: @@ -1557,6 +1565,62 @@ func rewriteValue386_Op386ADDLconst_0(v *Value) bool { } return false } +func rewriteValue386_Op386ADDLconstmodify_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (ADDLconstmodify [valoff1] {sym} (ADDLconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (ADDLconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) + for { + valoff1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != Op386ADDLconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2)) { + break + } + v.reset(Op386ADDLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (ADDLconstmodify [valoff1] {sym1} (LEAL [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) + // result: (ADDLconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + for { + valoff1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != Op386LEAL { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(Op386ADDLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValue386_Op386ADDLload_0(v *Value) bool { b := v.Block _ = b @@ -2075,6 +2139,62 @@ func rewriteValue386_Op386ANDLconst_0(v *Value) bool { } return false } +func rewriteValue386_Op386ANDLconstmodify_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (ANDLconstmodify [valoff1] {sym} (ADDLconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (ANDLconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) + for { + valoff1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != Op386ADDLconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2)) { + break + } + v.reset(Op386ANDLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (ANDLconstmodify [valoff1] {sym1} (LEAL [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) + // result: (ANDLconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + for { + valoff1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != Op386LEAL { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(Op386ANDLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValue386_Op386ANDLload_0(v *Value) bool { b := v.Block _ = b @@ -6506,6 +6626,173 @@ func rewriteValue386_Op386MOVLstore_10(v *Value) bool { v.AddArg(mem) return true } + // match: (MOVLstore {sym} [off] ptr y:(ADDLconst [c] l:(MOVLload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) && validValAndOff(c,off) + // result: (ADDLconstmodify [makeValAndOff(c,off)] {sym} ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != Op386ADDLconst { + break + } + c := y.AuxInt + l := y.Args[0] + if l.Op != Op386MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l) && validValAndOff(c, off)) { + break + } + v.reset(Op386ADDLconstmodify) + v.AuxInt = makeValAndOff(c, off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValue386_Op386MOVLstore_20(v *Value) bool { + // match: (MOVLstore {sym} [off] ptr y:(ANDLconst [c] l:(MOVLload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) && validValAndOff(c,off) + // result: (ANDLconstmodify [makeValAndOff(c,off)] {sym} ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != Op386ANDLconst { + break + } + c := y.AuxInt + l := y.Args[0] + if l.Op != Op386MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l) && validValAndOff(c, off)) { + break + } + v.reset(Op386ANDLconstmodify) + v.AuxInt = makeValAndOff(c, off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(ORLconst [c] l:(MOVLload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) && validValAndOff(c,off) + // result: (ORLconstmodify [makeValAndOff(c,off)] {sym} ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != Op386ORLconst { + break + } + c := y.AuxInt + l := y.Args[0] + if l.Op != Op386MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l) && validValAndOff(c, off)) { + break + } + v.reset(Op386ORLconstmodify) + v.AuxInt = makeValAndOff(c, off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(XORLconst [c] l:(MOVLload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) && validValAndOff(c,off) + // result: (XORLconstmodify [makeValAndOff(c,off)] {sym} ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != Op386XORLconst { + break + } + c := y.AuxInt + l := y.Args[0] + if l.Op != Op386MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l) && validValAndOff(c, off)) { + break + } + v.reset(Op386XORLconstmodify) + v.AuxInt = makeValAndOff(c, off) + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } return false } func rewriteValue386_Op386MOVLstoreconst_0(v *Value) bool { @@ -14769,6 +15056,62 @@ func rewriteValue386_Op386ORLconst_0(v *Value) bool { } return false } +func rewriteValue386_Op386ORLconstmodify_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (ORLconstmodify [valoff1] {sym} (ADDLconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (ORLconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) + for { + valoff1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != Op386ADDLconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2)) { + break + } + v.reset(Op386ORLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (ORLconstmodify [valoff1] {sym1} (LEAL [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) + // result: (ORLconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + for { + valoff1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != Op386LEAL { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(Op386ORLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValue386_Op386ORLload_0(v *Value) bool { b := v.Block _ = b @@ -16959,6 +17302,62 @@ func rewriteValue386_Op386XORLconst_0(v *Value) bool { } return false } +func rewriteValue386_Op386XORLconstmodify_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (XORLconstmodify [valoff1] {sym} (ADDLconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (XORLconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) + for { + valoff1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != Op386ADDLconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2)) { + break + } + v.reset(Op386XORLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (XORLconstmodify [valoff1] {sym1} (LEAL [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared) + // result: (XORLconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) + for { + valoff1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != Op386LEAL { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) && (base.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(Op386XORLconstmodify) + v.AuxInt = ValAndOff(valoff1).add(off2) + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValue386_Op386XORLload_0(v *Value) bool { b := v.Block _ = b diff --git a/src/cmd/compile/internal/x86/ssa.go b/src/cmd/compile/internal/x86/ssa.go index 7cdff863b2b99..a53b63ab92e2d 100644 --- a/src/cmd/compile/internal/x86/ssa.go +++ b/src/cmd/compile/internal/x86/ssa.go @@ -546,6 +546,33 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.To.Type = obj.TYPE_MEM p.To.Reg = v.Args[0].Reg() gc.AddAux(&p.To, v) + case ssa.Op386ADDLconstmodify: + var p *obj.Prog = nil + sc := v.AuxValAndOff() + off := sc.Off() + val := sc.Val() + if val == 1 { + p = s.Prog(x86.AINCL) + } else if val == -1 { + p = s.Prog(x86.ADECL) + } else { + p = s.Prog(v.Op.Asm()) + p.From.Type = obj.TYPE_CONST + p.From.Offset = val + } + p.To.Type = obj.TYPE_MEM + p.To.Reg = v.Args[0].Reg() + gc.AddAux2(&p.To, v, off) + case ssa.Op386ANDLconstmodify, ssa.Op386ORLconstmodify, ssa.Op386XORLconstmodify: + sc := v.AuxValAndOff() + off := sc.Off() + val := sc.Val() + p := s.Prog(v.Op.Asm()) + p.From.Type = obj.TYPE_CONST + p.From.Offset = val + p.To.Type = obj.TYPE_MEM + p.To.Reg = v.Args[0].Reg() + gc.AddAux2(&p.To, v, off) case ssa.Op386MOVSDstoreidx8: p := s.Prog(v.Op.Asm()) p.From.Type = obj.TYPE_REG diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index 3c063d873605a..32efcaaa3fb7b 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -19,6 +19,10 @@ func SubMem(arr []int, b int) int { arr[2] -= b // 386:`SUBL\s[A-Z]+,\s12\([A-Z]+\)` arr[3] -= b + // 386:`DECL\s16\([A-Z]+\)` + arr[4]-- + // 386:`ADDL\s[$]-20,\s20\([A-Z]+\)` + arr[5] -= 20 // 386:"SUBL\t4" // amd64:"SUBQ\t8" return arr[0] - arr[1] From f4e4ec2cd09c2f9d821f3cb6f47edd7c41a90b25 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 21 Aug 2018 14:27:07 +0200 Subject: [PATCH 0112/1663] cmd/cover: fix off-by-one error in TestCoverHTML Avoid index out of range if len(goldenLines) == len(outLines) + 1 Change-Id: Ic23a85d2b8dd06a615e35a58331e78abe4ad6703 Reviewed-on: https://go-review.googlesource.com/130396 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/cover/cover_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/cover/cover_test.go b/src/cmd/cover/cover_test.go index c818819c39277..8eb7124aad85b 100644 --- a/src/cmd/cover/cover_test.go +++ b/src/cmd/cover/cover_test.go @@ -314,7 +314,7 @@ func TestCoverHTML(t *testing.T) { // Compare at the line level, stopping at first different line so // we don't generate tons of output if there's an inserted or deleted line. for i, goldenLine := range goldenLines { - if i > len(outLines) { + if i >= len(outLines) { t.Fatalf("output shorter than golden; stops before line %d: %s\n", i+1, goldenLine) } // Convert all white space to simple spaces, for easy comparison. From 8148726676d63c2aebc561717a949135389868b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 22 Jul 2018 12:26:38 +0100 Subject: [PATCH 0113/1663] encoding/json: simplify the structEncoder type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit structEncoder had two slices - the list of fields, and a list containing the encoder for each field. structEncoder.encode then looped over the fields, and indexed into the second slice to grab the field encoder. However, this makes it very hard for the compiler to be able to prove that the two slices always have the same length, and that the index expression doesn't need a bounds check. Merge the two slices into one to completely remove the need for bounds checks in the hot loop. While at it, don't copy the field elements when ranging, which greatly speeds up the hot loop in structEncoder. name old time/op new time/op delta CodeEncoder-4 6.18ms ± 0% 5.56ms ± 0% -10.08% (p=0.002 n=6+6) name old speed new speed delta CodeEncoder-4 314MB/s ± 0% 349MB/s ± 0% +11.21% (p=0.002 n=6+6) name old alloc/op new alloc/op delta CodeEncoder-4 93.2kB ± 0% 62.1kB ± 0% -33.33% (p=0.002 n=6+6) Updates #5683. Change-Id: I0dd47783530f439b125e084aede09dda172eb1e8 Reviewed-on: https://go-review.googlesource.com/125416 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/encoding/json/encode.go | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index d5fe4d6b78b23..40bc060644ff2 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -624,14 +624,14 @@ func unsupportedTypeEncoder(e *encodeState, v reflect.Value, _ encOpts) { } type structEncoder struct { - fields []field - fieldEncs []encoderFunc + fields []field } -func (se *structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { +func (se structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { e.WriteByte('{') first := true - for i, f := range se.fields { + for i := range se.fields { + f := &se.fields[i] fv := fieldByIndex(v, f.index) if !fv.IsValid() || f.omitEmpty && isEmptyValue(fv) { continue @@ -647,20 +647,13 @@ func (se *structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { e.WriteString(f.nameNonEsc) } opts.quoted = f.quoted - se.fieldEncs[i](e, fv, opts) + f.encoder(e, fv, opts) } e.WriteByte('}') } func newStructEncoder(t reflect.Type) encoderFunc { - fields := cachedTypeFields(t) - se := &structEncoder{ - fields: fields, - fieldEncs: make([]encoderFunc, len(fields)), - } - for i, f := range fields { - se.fieldEncs[i] = typeEncoder(typeByIndex(t, f.index)) - } + se := structEncoder{fields: cachedTypeFields(t)} return se.encode } @@ -1055,6 +1048,8 @@ type field struct { typ reflect.Type omitEmpty bool quoted bool + + encoder encoderFunc } func fillField(f field) field { @@ -1254,6 +1249,10 @@ func typeFields(t reflect.Type) []field { fields = out sort.Sort(byIndex(fields)) + for i := range fields { + f := &fields[i] + f.encoder = typeEncoder(typeByIndex(t, f.index)) + } return fields } From 75e7e05aee4c0588a11f79bb5c46290ca753bf20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 22 Jul 2018 12:36:15 +0100 Subject: [PATCH 0114/1663] encoding/json: inline fieldByIndex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This function was only used in a single place - in the field encoding loop within the struct encoder. Inlining the function call manually lets us get rid of the call overhead. But most importantly, it lets us simplify the logic afterward. We no longer need to use reflect.Value{} and !fv.IsValid(), as we can skip the field immediately. The two factors combined (mostly just the latter) give a moderate speed improvement to this hot loop. name old time/op new time/op delta CodeEncoder-4 6.01ms ± 1% 5.91ms ± 1% -1.66% (p=0.002 n=6+6) name old speed new speed delta CodeEncoder-4 323MB/s ± 1% 328MB/s ± 1% +1.69% (p=0.002 n=6+6) Updates #5683. Change-Id: I12757c325a68abb2856026cf719c122612a1f38e Reviewed-on: https://go-review.googlesource.com/125417 Run-TryBot: Daniel Martí Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/encoding/json/encode.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 40bc060644ff2..bb4c54e8d6fd0 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -632,8 +632,21 @@ func (se structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { first := true for i := range se.fields { f := &se.fields[i] - fv := fieldByIndex(v, f.index) - if !fv.IsValid() || f.omitEmpty && isEmptyValue(fv) { + + // Find the nested struct field by following f.index. + fv := v + FieldLoop: + for _, i := range f.index { + if fv.Kind() == reflect.Ptr { + if fv.IsNil() { + continue FieldLoop + } + fv = fv.Elem() + } + fv = fv.Field(i) + } + + if f.omitEmpty && isEmptyValue(fv) { continue } if first { @@ -835,19 +848,6 @@ func isValidTag(s string) bool { return true } -func fieldByIndex(v reflect.Value, index []int) reflect.Value { - for _, i := range index { - if v.Kind() == reflect.Ptr { - if v.IsNil() { - return reflect.Value{} - } - v = v.Elem() - } - v = v.Field(i) - } - return v -} - func typeByIndex(t reflect.Type, index []int) reflect.Type { for _, i := range index { if t.Kind() == reflect.Ptr { From 39eda0dac12a53f7f0c3189e5929d171e8e0b844 Mon Sep 17 00:00:00 2001 From: Cholerae Hu Date: Fri, 3 Aug 2018 14:49:47 +0800 Subject: [PATCH 0115/1663] net/mail: lazily initialize dateLayouts Saves 6KB of memory in stdlib packages. Updates #26775 Change-Id: I1a6184cefa78e9a3c034fa84506fdfe0fec27add Reviewed-on: https://go-review.googlesource.com/127736 Reviewed-by: Brad Fitzpatrick --- src/net/mail/message.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/net/mail/message.go b/src/net/mail/message.go index 5912b9033477e..554377aa1da98 100644 --- a/src/net/mail/message.go +++ b/src/net/mail/message.go @@ -26,6 +26,7 @@ import ( "mime" "net/textproto" "strings" + "sync" "time" "unicode/utf8" ) @@ -65,9 +66,12 @@ func ReadMessage(r io.Reader) (msg *Message, err error) { // Layouts suitable for passing to time.Parse. // These are tried in order. -var dateLayouts []string +var ( + dateLayoutsBuildOnce sync.Once + dateLayouts []string +) -func init() { +func buildDateLayouts() { // Generate layouts based on RFC 5322, section 3.3. dows := [...]string{"", "Mon, "} // day-of-week @@ -93,6 +97,7 @@ func init() { // ParseDate parses an RFC 5322 date string. func ParseDate(date string) (time.Time, error) { + dateLayoutsBuildOnce.Do(buildDateLayouts) for _, layout := range dateLayouts { t, err := time.Parse(layout, date) if err == nil { From 841a9136b3d737d1252f7c5c371f109f23d76b2d Mon Sep 17 00:00:00 2001 From: Johan Brandhorst Date: Sat, 4 Aug 2018 09:45:36 +0100 Subject: [PATCH 0116/1663] strings, bytes: avoid unnecessary function literals A number of explicit function literals found through the unlambda linter are removed. Fixes #26802 Change-Id: I0b122bdd95e9cb804c77efe20483fdf681c8154e Reviewed-on: https://go-review.googlesource.com/127756 Reviewed-by: Joe Tsai --- src/bytes/bytes.go | 6 +++--- src/strings/strings.go | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go index 437a6e12df867..77a7ce98e077c 100644 --- a/src/bytes/bytes.go +++ b/src/bytes/bytes.go @@ -489,19 +489,19 @@ func ToTitle(s []byte) []byte { return Map(unicode.ToTitle, s) } // ToUpperSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their // upper case, giving priority to the special casing rules. func ToUpperSpecial(c unicode.SpecialCase, s []byte) []byte { - return Map(func(r rune) rune { return c.ToUpper(r) }, s) + return Map(c.ToUpper, s) } // ToLowerSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their // lower case, giving priority to the special casing rules. func ToLowerSpecial(c unicode.SpecialCase, s []byte) []byte { - return Map(func(r rune) rune { return c.ToLower(r) }, s) + return Map(c.ToLower, s) } // ToTitleSpecial treats s as UTF-8-encoded bytes and returns a copy with all the Unicode letters mapped to their // title case, giving priority to the special casing rules. func ToTitleSpecial(c unicode.SpecialCase, s []byte) []byte { - return Map(func(r rune) rune { return c.ToTitle(r) }, s) + return Map(c.ToTitle, s) } // isSeparator reports whether the rune could mark a word boundary. diff --git a/src/strings/strings.go b/src/strings/strings.go index e54f0c2bfa762..97d83cfde1110 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -606,19 +606,19 @@ func ToTitle(s string) string { return Map(unicode.ToTitle, s) } // ToUpperSpecial returns a copy of the string s with all Unicode letters mapped to their // upper case using the case mapping specified by c. func ToUpperSpecial(c unicode.SpecialCase, s string) string { - return Map(func(r rune) rune { return c.ToUpper(r) }, s) + return Map(c.ToUpper, s) } // ToLowerSpecial returns a copy of the string s with all Unicode letters mapped to their // lower case using the case mapping specified by c. func ToLowerSpecial(c unicode.SpecialCase, s string) string { - return Map(func(r rune) rune { return c.ToLower(r) }, s) + return Map(c.ToLower, s) } // ToTitleSpecial returns a copy of the string s with all Unicode letters mapped to their // title case, giving priority to the special casing rules. func ToTitleSpecial(c unicode.SpecialCase, s string) string { - return Map(func(r rune) rune { return c.ToTitle(r) }, s) + return Map(c.ToTitle, s) } // isSeparator reports whether the rune could mark a word boundary. From 9d1540b77c3965f1cbaaab753d09974ad7330380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 7 Jul 2018 19:07:14 +0100 Subject: [PATCH 0117/1663] encoding/json: simplify some pieces of the encoder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some WriteByte('\\') calls can be deduplicated. fillField is used in two occasions, but it is unnecessary when adding fields to the "next" stack, as those aren't used for the final encoding. Inline the func with its only remaining call. Finally, unindent a default-if block. The performance of the encoder is unaffected: name old time/op new time/op delta CodeEncoder-4 6.65ms ± 1% 6.65ms ± 0% ~ (p=0.662 n=6+5) Change-Id: Ie55baeab89abad9b9f13e9f6ca886a670c30dba9 Reviewed-on: https://go-review.googlesource.com/122461 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/encoding/json/encode.go | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index bb4c54e8d6fd0..f475d5688ab51 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -839,10 +839,8 @@ func isValidTag(s string) bool { // Backslash and quote chars are reserved, but // otherwise any punctuation chars are allowed // in a tag name. - default: - if !unicode.IsLetter(c) && !unicode.IsDigit(c) { - return false - } + case !unicode.IsLetter(c) && !unicode.IsDigit(c): + return false } } return true @@ -897,18 +895,15 @@ func (e *encodeState) string(s string, escapeHTML bool) { if start < i { e.WriteString(s[start:i]) } + e.WriteByte('\\') switch b { case '\\', '"': - e.WriteByte('\\') e.WriteByte(b) case '\n': - e.WriteByte('\\') e.WriteByte('n') case '\r': - e.WriteByte('\\') e.WriteByte('r') case '\t': - e.WriteByte('\\') e.WriteByte('t') default: // This encodes bytes < 0x20 except for \t, \n and \r. @@ -916,7 +911,7 @@ func (e *encodeState) string(s string, escapeHTML bool) { // because they can lead to security holes when // user-controlled strings are rendered into JSON // and served to some browsers. - e.WriteString(`\u00`) + e.WriteString(`u00`) e.WriteByte(hex[b>>4]) e.WriteByte(hex[b&0xF]) } @@ -972,18 +967,15 @@ func (e *encodeState) stringBytes(s []byte, escapeHTML bool) { if start < i { e.Write(s[start:i]) } + e.WriteByte('\\') switch b { case '\\', '"': - e.WriteByte('\\') e.WriteByte(b) case '\n': - e.WriteByte('\\') e.WriteByte('n') case '\r': - e.WriteByte('\\') e.WriteByte('r') case '\t': - e.WriteByte('\\') e.WriteByte('t') default: // This encodes bytes < 0x20 except for \t, \n and \r. @@ -991,7 +983,7 @@ func (e *encodeState) stringBytes(s []byte, escapeHTML bool) { // because they can lead to security holes when // user-controlled strings are rendered into JSON // and served to some browsers. - e.WriteString(`\u00`) + e.WriteString(`u00`) e.WriteByte(hex[b>>4]) e.WriteByte(hex[b&0xF]) } @@ -1052,12 +1044,6 @@ type field struct { encoder encoderFunc } -func fillField(f field) field { - f.nameBytes = []byte(f.name) - f.equalFold = foldFunc(f.nameBytes) - return f -} - // byIndex sorts field by index sequence. type byIndex []field @@ -1164,14 +1150,16 @@ func typeFields(t reflect.Type) []field { if name == "" { name = sf.Name } - field := fillField(field{ + field := field{ name: name, tag: tagged, index: index, typ: ft, omitEmpty: opts.Contains("omitempty"), quoted: quoted, - }) + } + field.nameBytes = []byte(field.name) + field.equalFold = foldFunc(field.nameBytes) // Build nameEscHTML and nameNonEsc ahead of time. nameEscBuf.Reset() @@ -1195,7 +1183,7 @@ func typeFields(t reflect.Type) []field { // Record new anonymous struct to explore in next round. nextCount[ft]++ if nextCount[ft] == 1 { - next = append(next, fillField(field{name: ft.Name(), index: index, typ: ft})) + next = append(next, field{name: ft.Name(), index: index, typ: ft}) } } } From ed2f84a94e1d0903bc16974dca308a9382b596b6 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Wed, 11 Jul 2018 23:39:49 +0300 Subject: [PATCH 0118/1663] cmd/internal/obj/arm64: simplify some bool expressions Replace `!(o1 != 0)` with `o1 == 0` (for readability). Found using https://go-critic.github.io/overview.html#boolExprSimplify-ref Change-Id: I4fc035458f530973f9be15b38441ec7b5fb591ec Reviewed-on: https://go-review.googlesource.com/123377 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/internal/obj/arm64/asm7.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index 4840a969fd665..1acf9799c626e 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -2752,7 +2752,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { case 13: /* addop $vcon, [R], R (64 bit literal); cmp $lcon,R -> addop $lcon,R, ZR */ o1 = c.omovlit(AMOVD, p, &p.From, REGTMP) - if !(o1 != 0) { + if o1 == 0 { break } rt := int(p.To.Reg) @@ -3013,7 +3013,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { case 28: /* logop $vcon, [R], R (64 bit literal) */ o1 = c.omovlit(AMOVD, p, &p.From, REGTMP) - if !(o1 != 0) { + if o1 == 0 { break } rt := int(p.To.Reg) @@ -3158,7 +3158,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { case 34: /* mov $lacon,R */ o1 = c.omovlit(AMOVD, p, &p.From, REGTMP) - if !(o1 != 0) { + if o1 == 0 { break } o2 = c.opxrrr(p, AADD, false) From 02fecd33f608e3a2f11fcee424d55232f08c28cd Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Sat, 2 Jun 2018 15:53:58 +0300 Subject: [PATCH 0119/1663] test: remove errchk, the perl script gc tests do not depend on errchk. Fixes #25669 Change-Id: I99eb87bb9677897b9167d4fc9a6321fa66cd9116 Reviewed-on: https://go-review.googlesource.com/115955 Reviewed-by: Brad Fitzpatrick --- test/errchk | 161 ---------------------------------------------------- 1 file changed, 161 deletions(-) delete mode 100755 test/errchk diff --git a/test/errchk b/test/errchk deleted file mode 100755 index 1cb57bb961c41..0000000000000 --- a/test/errchk +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env perl -# Copyright 2009 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. - -# This script checks that the compilers emit the errors which we expect. -# Usage: errchk COMPILER [OPTS] SOURCEFILES. This will run the command -# COMPILER [OPTS] SOURCEFILES. The compilation is expected to fail; if -# it succeeds, this script will report an error. The stderr output of -# the compiler will be matched against comments in SOURCEFILES. For each -# line of the source files which should generate an error, there should -# be a comment of the form // ERROR "regexp". If the compiler generates -# an error for a line which has no such comment, this script will report -# an error. Likewise if the compiler does not generate an error for a -# line which has a comment, or if the error message does not match the -# . The syntax is Perl but its best to stick to egrep. - -use POSIX; - -my $exitcode = 1; - -if(@ARGV >= 1 && $ARGV[0] eq "-0") { - $exitcode = 0; - shift; -} - -if(@ARGV < 1) { - print STDERR "Usage: errchk COMPILER [OPTS] SOURCEFILES\n"; - exit 1; -} - -# Grab SOURCEFILES -foreach(reverse 0 .. @ARGV-1) { - unless($ARGV[$_] =~ /\.(go|s)$/) { - @file = @ARGV[$_+1 .. @ARGV-1]; - last; - } -} - -# If no files have been specified try to grab SOURCEFILES from the last -# argument that is an existing directory if any -unless(@file) { - foreach(reverse 0 .. @ARGV-1) { - if(-d $ARGV[$_]) { - @file = glob($ARGV[$_] . "/*.go"); - last; - } - } -} - -foreach $file (@file) { - open(SRC, $file) || die "BUG: errchk: open $file: $!"; - $src{$file} = []; - close(SRC); -} - -# Run command -$cmd = join(' ', @ARGV); -open(CMD, "exec $cmd &1 |") || die "BUG: errchk: run $cmd: $!"; - -# gc error messages continue onto additional lines with leading tabs. -# Split the output at the beginning of each line that doesn't begin with a tab. -$out = join('', ); -@out = split(/^(?!\t)/m, $out); - -close CMD; - -# Remove lines beginning with #, printed by go command to indicate package. -@out = grep {!/^#/} @out; - -if($exitcode != 0 && $? == 0) { - print STDERR "BUG: errchk: command succeeded unexpectedly\n"; - print STDERR @out; - exit 0; -} - -if($exitcode == 0 && $? != 0) { - print STDERR "BUG: errchk: command failed unexpectedly\n"; - print STDERR @out; - exit 0; -} - -if(!WIFEXITED($?)) { - print STDERR "BUG: errchk: compiler crashed\n"; - print STDERR @out, "\n"; - exit 0; -} - -sub bug() { - if(!$bug++) { - print STDERR "BUG: "; - } -} - -sub chk { - my $file = shift; - my $line = 0; - my $regexp; - my @errmsg; - my @match; - foreach my $src (@{$src{$file}}) { - $line++; - next if $src =~ m|////|; # double comment disables ERROR - next unless $src =~ m|// (GC_)?ERROR (.*)|; - my $all = $2; - if($all !~ /^"([^"]*)"/) { - print STDERR "$file:$line: malformed regexp\n"; - next; - } - @errmsg = grep { /$file:$line[:[]/ } @out; - @out = grep { !/$file:$line[:[]/ } @out; - if(@errmsg == 0) { - bug(); - print STDERR "errchk: $file:$line: missing expected error: '$all'\n"; - next; - } - foreach my $regexp ($all =~ /"([^"]*)"/g) { - # Turn relative line number in message into absolute line number. - if($regexp =~ /LINE(([+-])([0-9]+))?/) { - my $n = $line; - if(defined($1)) { - if($2 eq "+") { - $n += int($3); - } else { - $n -= int($3); - } - } - $regexp = "$`$file:$n$'"; - } - - @match = grep { /$regexp/ } @errmsg; - if(@match == 0) { - bug(); - print STDERR "errchk: $file:$line: error messages do not match '$regexp'\n"; - next; - } - @errmsg = grep { !/$regexp/ } @errmsg; - } - if(@errmsg != 0) { - bug(); - print STDERR "errchk: $file:$line: unmatched error messages:\n"; - foreach my $l (@errmsg) { - print STDERR "> $l"; - } - } - } -} - -foreach $file (@file) { - chk($file) -} - -if(@out != 0) { - bug(); - print STDERR "errchk: unmatched error messages:\n"; - print STDERR "==================================================\n"; - print STDERR @out; - print STDERR "==================================================\n"; -} - -exit 0; From bca00def0dcde59312574b98568fd4698a61dfdd Mon Sep 17 00:00:00 2001 From: Diego Siqueira Date: Wed, 1 Aug 2018 10:52:19 +0000 Subject: [PATCH 0120/1663] plugin: remove unused func Change-Id: Ife29464d581f00940af7ef9251bf99661c1350b6 GitHub-Last-Rev: d7747706584b06b619fc78a85b6b9bfe619467c8 GitHub-Pull-Request: golang/go#26740 Reviewed-on: https://go-review.googlesource.com/127195 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/plugin/plugin_dlopen.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/plugin/plugin_dlopen.go b/src/plugin/plugin_dlopen.go index 47f2b29a80b8d..f24093989fd6f 100644 --- a/src/plugin/plugin_dlopen.go +++ b/src/plugin/plugin_dlopen.go @@ -39,16 +39,6 @@ import ( "unsafe" ) -// avoid a dependency on strings -func lastIndexByte(s string, c byte) int { - for i := len(s) - 1; i >= 0; i-- { - if s[i] == c { - return i - } - } - return -1 -} - func open(name string) (*Plugin, error) { cPath := make([]byte, C.PATH_MAX+1) cRelName := make([]byte, len(name)+1) From 6a11e1e8db0e21f2875f20aba1bfd214291c08f8 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Sat, 30 Jun 2018 02:59:37 +0300 Subject: [PATCH 0121/1663] cmd/link/internal/amd64: remove /*fallthrough*/ comments These are artifacts originating from C->Go translation. Change-Id: Ib5cdcaf42f43f3968482892fb4945e19ef38bd6d Reviewed-on: https://go-review.googlesource.com/121795 Reviewed-by: Dave Cheney Reviewed-by: Brad Fitzpatrick --- src/cmd/link/internal/amd64/asm.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/cmd/link/internal/amd64/asm.go b/src/cmd/link/internal/amd64/asm.go index 692edf1524ad7..66aab3f748ee2 100644 --- a/src/cmd/link/internal/amd64/asm.go +++ b/src/cmd/link/internal/amd64/asm.go @@ -196,7 +196,6 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { } fallthrough - // fall through case 512 + ld.MACHO_X86_64_RELOC_UNSIGNED*2 + 1, 512 + ld.MACHO_X86_64_RELOC_SIGNED*2 + 1, 512 + ld.MACHO_X86_64_RELOC_SIGNED_1*2 + 1, @@ -224,7 +223,6 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { } fallthrough - // fall through case 512 + ld.MACHO_X86_64_RELOC_GOT*2 + 1: if targ.Type != sym.SDYNIMPORT { ld.Errorf(s, "unexpected GOT reloc for non-dynamic symbol %s", targ.Name) From 7a178df0bcdfbb3a73ffa9ff2701577f3621a113 Mon Sep 17 00:00:00 2001 From: go101 Date: Wed, 22 Aug 2018 16:12:46 +0000 Subject: [PATCH 0122/1663] strings: use Builder in Repeat to avoid an allocation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit name old time/op new time/op delta Repeat/5x1-4 95.9ns ± 2% 70.1ns ± 2% -26.93% (p=0.000 n=9+10) Repeat/5x2-4 146ns ± 3% 100ns ± 2% -31.99% (p=0.000 n=10+10) Repeat/5x6-4 203ns ± 3% 140ns ± 4% -30.77% (p=0.000 n=10+10) Repeat/10x1-4 139ns ± 3% 92ns ± 4% -34.08% (p=0.000 n=10+10) Repeat/10x2-4 188ns ± 4% 122ns ± 2% -35.34% (p=0.000 n=10+10) Repeat/10x6-4 264ns ± 5% 179ns ± 4% -32.15% (p=0.000 n=10+10) name old alloc/op new alloc/op delta Repeat/5x1-4 10.0B ± 0% 5.0B ± 0% -50.00% (p=0.000 n=10+10) Repeat/5x2-4 32.0B ± 0% 16.0B ± 0% -50.00% (p=0.000 n=10+10) Repeat/5x6-4 64.0B ± 0% 32.0B ± 0% -50.00% (p=0.000 n=10+10) Repeat/10x1-4 32.0B ± 0% 16.0B ± 0% -50.00% (p=0.000 n=10+10) Repeat/10x2-4 64.0B ± 0% 32.0B ± 0% -50.00% (p=0.000 n=10+10) Repeat/10x6-4 128B ± 0% 64B ± 0% -50.00% (p=0.000 n=10+10) Change-Id: I6619336da636df39c560f6cc481519f48c6e8176 GitHub-Last-Rev: 4b2c73f3bfa0b3789268b9ea6e1ecdb984e8087c GitHub-Pull-Request: golang/go#25894 Reviewed-on: https://go-review.googlesource.com/118855 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/strings/strings.go | 24 +++++++++++++++++------- src/strings/strings_test.go | 11 +++++++++-- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/strings/strings.go b/src/strings/strings.go index 97d83cfde1110..e0bebced63f84 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -523,23 +523,33 @@ func Map(mapping func(rune) rune, s string) string { // It panics if count is negative or if // the result of (len(s) * count) overflows. func Repeat(s string, count int) string { + if count == 0 { + return "" + } + // Since we cannot return an error on overflow, // we should panic if the repeat will generate // an overflow. // See Issue golang.org/issue/16237 if count < 0 { panic("strings: negative Repeat count") - } else if count > 0 && len(s)*count/count != len(s) { + } else if len(s)*count/count != len(s) { panic("strings: Repeat count causes overflow") } - b := make([]byte, len(s)*count) - bp := copy(b, s) - for bp < len(b) { - copy(b[bp:], b[:bp]) - bp *= 2 + n := len(s) * count + var b Builder + b.Grow(n) + b.WriteString(s) + for b.Len() < n { + if b.Len() <= n/2 { + b.WriteString(b.String()) + } else { + b.WriteString(b.String()[:n-b.Len()]) + break + } } - return string(b) + return b.String() } // ToUpper returns a copy of the string s with all Unicode letters mapped to their upper case. diff --git a/src/strings/strings_test.go b/src/strings/strings_test.go index bb46e136f26bc..d6197ed895e8b 100644 --- a/src/strings/strings_test.go +++ b/src/strings/strings_test.go @@ -1660,8 +1660,15 @@ func BenchmarkSplitNMultiByteSeparator(b *testing.B) { } func BenchmarkRepeat(b *testing.B) { - for i := 0; i < b.N; i++ { - Repeat("-", 80) + s := "0123456789" + for _, n := range []int{5, 10} { + for _, c := range []int{1, 2, 6} { + b.Run(fmt.Sprintf("%dx%d", n, c), func(b *testing.B) { + for i := 0; i < b.N; i++ { + Repeat(s[:n], c) + } + }) + } } } From c92354f46e468f89fcf1497e7c9e2f3c66025dfa Mon Sep 17 00:00:00 2001 From: Shivansh Rai Date: Sun, 20 May 2018 22:35:02 +0530 Subject: [PATCH 0123/1663] all: use consistent shebang line across all shell scripts Change-Id: I4aac882b1b618a388d0748a427dc998203d3a1b2 Reviewed-on: https://go-review.googlesource.com/113856 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/go/mkalldocs.sh | 2 +- src/naclmake.bash | 2 +- src/nacltest.bash | 2 +- src/runtime/mknacl.sh | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/cmd/go/mkalldocs.sh b/src/cmd/go/mkalldocs.sh index 4e7a50980541e..f37d59d2d7431 100755 --- a/src/cmd/go/mkalldocs.sh +++ b/src/cmd/go/mkalldocs.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2012 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. diff --git a/src/naclmake.bash b/src/naclmake.bash index 74fd802f41784..5e6c3ce05e69c 100755 --- a/src/naclmake.bash +++ b/src/naclmake.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2016 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. diff --git a/src/nacltest.bash b/src/nacltest.bash index 3e929a14a4568..dc245b484cb4c 100755 --- a/src/nacltest.bash +++ b/src/nacltest.bash @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2014 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. diff --git a/src/runtime/mknacl.sh b/src/runtime/mknacl.sh index 3454b624d6ea2..306ae3d9c15f7 100644 --- a/src/runtime/mknacl.sh +++ b/src/runtime/mknacl.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Copyright 2013 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. From d778a371be488312fe43b2d710dfc8c7afb3d29c Mon Sep 17 00:00:00 2001 From: Shivansh Rai Date: Fri, 18 May 2018 06:50:43 +0530 Subject: [PATCH 0124/1663] cmd/gofmt: update error handling when writing to backup file As per commit aa0ae75, handling of io.ErrShortWrite is done in *File.Write() itself. Change-Id: I92924b51e8df2ae88e6e50318348f44973addba8 Reviewed-on: https://go-review.googlesource.com/113696 Reviewed-by: Brad Fitzpatrick --- src/cmd/gofmt/gofmt.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/cmd/gofmt/gofmt.go b/src/cmd/gofmt/gofmt.go index d5b7be327a502..ac6852f2e4e38 100644 --- a/src/cmd/gofmt/gofmt.go +++ b/src/cmd/gofmt/gofmt.go @@ -319,10 +319,7 @@ func backupFile(filename string, data []byte, perm os.FileMode) (string, error) } // write data to backup file - n, err := f.Write(data) - if err == nil && n < len(data) { - err = io.ErrShortWrite - } + _, err = f.Write(data) if err1 := f.Close(); err == nil { err = err1 } From 0c706fddce2066fa0f72df364dd393f74027d753 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Mon, 6 Aug 2018 14:24:13 +0300 Subject: [PATCH 0125/1663] cmd/compile/internal/gc: remove commented-out code from esc.go Also adjust some comments to where they belong. Change-Id: Ifbb38052401b0d33d7bb9800f56a20ce8f39c25f Reviewed-on: https://go-review.googlesource.com/127761 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/esc.go | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go index 0baf7e7441f5f..3df565aea51c6 100644 --- a/src/cmd/compile/internal/gc/esc.go +++ b/src/cmd/compile/internal/gc/esc.go @@ -502,8 +502,6 @@ func escAnalyze(all []*Node, recursive bool) { } } - // print("escapes: %d e.dsts, %d edges\n", e.dstcount, e.edgecount); - // visit the upstream of each dst, mark address nodes with // addrescapes, mark parameters unsafe escapes := make([]uint16, len(e.dsts)) @@ -551,7 +549,6 @@ func escAnalyze(all []*Node, recursive bool) { } func (e *EscState) escfunc(fn *Node) { - // print("escfunc %N %s\n", fn.Func.Nname, e.recursive?"(recursive)":""); if fn.Esc != EscFuncPlanned { Fatalf("repeat escfunc %v", fn.Func.Nname) } @@ -630,8 +627,6 @@ func (e *EscState) escloopdepth(n *Node) { // Walk will complain about this label being already defined, but that's not until // after escape analysis. in the future, maybe pull label & goto analysis out of walk and put before esc - // if(n.Left.Sym.Label != nil) - // fatal("escape analysis messed up analyzing label: %+N", n); n.Left.Sym.Label = asTypesNode(&nonlooping) case OGOTO: @@ -756,10 +751,6 @@ opSwitch: e.loopdepth++ } - // See case OLABEL in escloopdepth above - // else if(n.Left.Sym.Label == nil) - // fatal("escape analysis missed or messed up a label: %+N", n); - n.Left.Sym.Label = nil case ORANGE: @@ -1561,12 +1552,11 @@ func (e *EscState) esccall(call *Node, parent *Node) { cE := e.nodeEscState(call) if fn != nil && fn.Op == ONAME && fn.Class() == PFUNC && fn.Name.Defn != nil && fn.Name.Defn.Nbody.Len() != 0 && fn.Name.Param.Ntype != nil && fn.Name.Defn.Esc < EscFuncTagged { + // function in same mutually recursive group. Incorporate into flow graph. if Debug['m'] > 3 { fmt.Printf("%v::esccall:: %S in recursive group\n", linestr(lineno), call) } - // function in same mutually recursive group. Incorporate into flow graph. - // print("esc local fn: %N\n", fn.Func.Ntype); if fn.Name.Defn.Esc == EscFuncUnknown || cE.Retval.Len() != 0 { Fatalf("graph inconsistency") } @@ -1629,8 +1619,6 @@ func (e *EscState) esccall(call *Node, parent *Node) { // set up out list on this call node with dummy auto ONAMES in the current (calling) function. e.initEscRetval(call, fntype) - // print("esc analyzed fn: %#N (%+T) returning (%+H)\n", fn, fntype, e.nodeEscState(call).Retval); - // Receiver. if call.Op != OCALLFUNC { rf := fntype.Recv() From 5ddecd150821713c53de15f439c7925b28c9f535 Mon Sep 17 00:00:00 2001 From: Tim Cooper Date: Wed, 6 Jun 2018 16:23:44 -0300 Subject: [PATCH 0126/1663] strconv: use bytealg implementation of IndexByteString benchmark old ns/op new ns/op delta BenchmarkUnquoteEasy-4 188 79.5 -57.71% BenchmarkUnquoteHard-4 653 622 -4.75% Fixes #23821 Change-Id: I1ebfab1b7f0248fd313de21396e0f8612076aa6d Reviewed-on: https://go-review.googlesource.com/116755 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/strconv/quote.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/strconv/quote.go b/src/strconv/quote.go index 9b7194a0f041d..6cd2f93068c03 100644 --- a/src/strconv/quote.go +++ b/src/strconv/quote.go @@ -6,7 +6,10 @@ package strconv -import "unicode/utf8" +import ( + "internal/bytealg" + "unicode/utf8" +) const lowerhex = "0123456789abcdef" @@ -424,12 +427,7 @@ func Unquote(s string) (string, error) { // contains reports whether the string contains the byte c. func contains(s string, c byte) bool { - for i := 0; i < len(s); i++ { - if s[i] == c { - return true - } - } - return false + return bytealg.IndexByteString(s, c) != -1 } // bsearch16 returns the smallest i such that a[i] >= x. From a21ae28f39fc5a27bb1391802195d1c6e2993f29 Mon Sep 17 00:00:00 2001 From: andrius4669 Date: Thu, 17 May 2018 14:43:30 +0000 Subject: [PATCH 0127/1663] bufio: avoid rescanning buffer multiple times in ReadSlice When existing data in buffer does not have delimiter, and new data is added with b.fill(), continue search from previous point instead of starting from beginning. Change-Id: Id78332afe2b0281b4a3c86bd1ffe9449cfea7848 GitHub-Last-Rev: 08e7d2f50151a00b22800e3f7020d0de8dee7dcf GitHub-Pull-Request: golang/go#25441 Reviewed-on: https://go-review.googlesource.com/113535 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/bufio/bufio.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bufio/bufio.go b/src/bufio/bufio.go index 480e929f5812a..8d162b34a0677 100644 --- a/src/bufio/bufio.go +++ b/src/bufio/bufio.go @@ -314,9 +314,11 @@ func (b *Reader) Buffered() int { return b.w - b.r } // ReadBytes or ReadString instead. // ReadSlice returns err != nil if and only if line does not end in delim. func (b *Reader) ReadSlice(delim byte) (line []byte, err error) { + s := 0 // search start index for { // Search buffer. - if i := bytes.IndexByte(b.buf[b.r:b.w], delim); i >= 0 { + if i := bytes.IndexByte(b.buf[b.r+s:b.w], delim); i >= 0 { + i += s line = b.buf[b.r : b.r+i+1] b.r += i + 1 break @@ -338,6 +340,8 @@ func (b *Reader) ReadSlice(delim byte) (line []byte, err error) { break } + s = b.w - b.r // do not rescan area we scanned before + b.fill() // buffer is not full } From 3396034155f517a7688f730f5cc9b2d4427093d4 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 21 Aug 2018 07:58:10 -0700 Subject: [PATCH 0128/1663] regexp/syntax: don't do both linear and binary sesarch in MatchRunePos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MatchRunePos is a significant element of regexp performance, so some attention to optimization is appropriate. Before this CL, a non-matching rune would do both a linear search in the first four entries, and a binary search over all the entries. Change the code to optimize for the common case of two runes, to only do a linear search when there are up to four entries, and to only do a binary search when there are more than four entries. Updates #26623 name old time/op new time/op delta Find-12 260ns ± 1% 275ns ± 7% +5.84% (p=0.000 n=8+10) FindAllNoMatches-12 144ns ± 9% 143ns ±12% ~ (p=0.187 n=10+10) FindString-12 256ns ± 4% 254ns ± 1% ~ (p=0.357 n=9+8) FindSubmatch-12 587ns ±12% 593ns ±11% ~ (p=0.516 n=10+10) FindStringSubmatch-12 534ns ±12% 525ns ±14% ~ (p=0.565 n=10+10) Literal-12 104ns ±14% 106ns ±11% ~ (p=0.145 n=10+10) NotLiteral-12 1.51µs ± 8% 1.47µs ± 2% ~ (p=0.508 n=10+9) MatchClass-12 2.47µs ± 1% 2.26µs ± 6% -8.55% (p=0.000 n=8+10) MatchClass_InRange-12 2.18µs ± 5% 2.25µs ±11% +2.85% (p=0.009 n=9+10) ReplaceAll-12 2.35µs ± 6% 2.08µs ±23% -11.59% (p=0.010 n=9+10) AnchoredLiteralShortNonMatch-12 93.2ns ± 9% 93.2ns ±11% ~ (p=0.716 n=10+10) AnchoredLiteralLongNonMatch-12 118ns ±10% 117ns ± 9% ~ (p=0.802 n=10+10) AnchoredShortMatch-12 142ns ± 1% 141ns ± 1% -0.53% (p=0.007 n=8+8) AnchoredLongMatch-12 303ns ± 9% 304ns ± 6% ~ (p=0.724 n=10+10) OnePassShortA-12 620ns ± 1% 618ns ± 9% ~ (p=0.162 n=8+10) NotOnePassShortA-12 599ns ± 8% 568ns ± 1% -5.21% (p=0.000 n=10+8) OnePassShortB-12 525ns ± 7% 489ns ± 1% -6.93% (p=0.000 n=10+8) NotOnePassShortB-12 449ns ± 9% 431ns ±11% -4.05% (p=0.033 n=10+10) OnePassLongPrefix-12 119ns ± 6% 114ns ± 0% -3.88% (p=0.006 n=10+9) OnePassLongNotPrefix-12 420ns ± 9% 410ns ± 7% ~ (p=0.645 n=10+9) MatchParallelShared-12 376ns ± 0% 375ns ± 0% -0.45% (p=0.003 n=8+10) MatchParallelCopied-12 39.4ns ± 1% 39.1ns ± 0% -0.55% (p=0.004 n=10+9) QuoteMetaAll-12 139ns ± 7% 142ns ± 7% ~ (p=0.445 n=10+10) QuoteMetaNone-12 56.7ns ± 0% 61.3ns ± 7% +8.03% (p=0.001 n=8+10) Match/Easy0/32-12 83.4ns ± 7% 83.1ns ± 8% ~ (p=0.541 n=10+10) Match/Easy0/1K-12 417ns ± 8% 394ns ± 6% ~ (p=0.059 n=10+9) Match/Easy0/32K-12 7.05µs ± 8% 7.30µs ± 9% ~ (p=0.190 n=10+10) Match/Easy0/1M-12 291µs ±17% 284µs ±10% ~ (p=0.481 n=10+10) Match/Easy0/32M-12 9.89ms ± 4% 10.27ms ± 8% ~ (p=0.315 n=10+10) Match/Easy0i/32-12 1.13µs ± 1% 1.14µs ± 1% +1.51% (p=0.000 n=8+8) Match/Easy0i/1K-12 35.7µs ±11% 36.8µs ±10% ~ (p=0.143 n=10+10) Match/Easy0i/32K-12 1.70ms ± 7% 1.72ms ± 7% ~ (p=0.776 n=9+6) name old alloc/op new alloc/op delta Find-12 0.00B 0.00B ~ (all equal) FindAllNoMatches-12 0.00B 0.00B ~ (all equal) FindString-12 0.00B 0.00B ~ (all equal) FindSubmatch-12 48.0B ± 0% 48.0B ± 0% ~ (all equal) FindStringSubmatch-12 32.0B ± 0% 32.0B ± 0% ~ (all equal) name old allocs/op new allocs/op delta Find-12 0.00 0.00 ~ (all equal) FindAllNoMatches-12 0.00 0.00 ~ (all equal) FindString-12 0.00 0.00 ~ (all equal) FindSubmatch-12 1.00 ± 0% 1.00 ± 0% ~ (all equal) FindStringSubmatch-12 1.00 ± 0% 1.00 ± 0% ~ (all equal) name old speed new speed delta QuoteMetaAll-12 101MB/s ± 8% 99MB/s ± 7% ~ (p=0.529 n=10+10) QuoteMetaNone-12 458MB/s ± 0% 425MB/s ± 8% -7.22% (p=0.003 n=8+10) Match/Easy0/32-12 385MB/s ± 7% 386MB/s ± 7% ~ (p=0.579 n=10+10) Match/Easy0/1K-12 2.46GB/s ± 8% 2.60GB/s ± 6% ~ (p=0.065 n=10+9) Match/Easy0/32K-12 4.66GB/s ± 7% 4.50GB/s ±10% ~ (p=0.190 n=10+10) Match/Easy0/1M-12 3.63GB/s ±15% 3.70GB/s ± 9% ~ (p=0.481 n=10+10) Match/Easy0/32M-12 3.40GB/s ± 4% 3.28GB/s ± 8% ~ (p=0.315 n=10+10) Match/Easy0i/32-12 28.4MB/s ± 1% 28.0MB/s ± 1% -1.50% (p=0.000 n=8+8) Match/Easy0i/1K-12 28.8MB/s ±10% 27.9MB/s ±11% ~ (p=0.143 n=10+10) Match/Easy0i/32K-12 19.0MB/s ±14% 19.1MB/s ± 8% ~ (p=1.000 n=10+6) Change-Id: I238a451b36ad84b0f5534ff0af5c077a0d52d73a Reviewed-on: https://go-review.googlesource.com/130417 Reviewed-by: Brad Fitzpatrick --- src/regexp/syntax/prog.go | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/src/regexp/syntax/prog.go b/src/regexp/syntax/prog.go index 49a06bbfad4b1..ae7a9a2fe0118 100644 --- a/src/regexp/syntax/prog.go +++ b/src/regexp/syntax/prog.go @@ -201,8 +201,12 @@ func (i *Inst) MatchRune(r rune) bool { func (i *Inst) MatchRunePos(r rune) int { rune := i.Rune - // Special case: single-rune slice is from literal string, not char class. - if len(rune) == 1 { + switch len(rune) { + case 0: + return noMatch + + case 1: + // Special case: single-rune slice is from literal string, not char class. r0 := rune[0] if r == r0 { return 0 @@ -215,17 +219,25 @@ func (i *Inst) MatchRunePos(r rune) int { } } return noMatch - } - // Peek at the first few pairs. - // Should handle ASCII well. - for j := 0; j < len(rune) && j <= 8; j += 2 { - if r < rune[j] { - return noMatch + case 2: + if r >= rune[0] && r <= rune[1] { + return 0 } - if r <= rune[j+1] { - return j / 2 + return noMatch + + case 4, 6, 8: + // Linear search for a few pairs. + // Should handle ASCII well. + for j := 0; j < len(rune); j += 2 { + if r < rune[j] { + return noMatch + } + if r <= rune[j+1] { + return j / 2 + } } + return noMatch } // Otherwise binary search. From 43704759b4a26c4090212e2d63d23579497d5e50 Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Wed, 8 Aug 2018 15:00:56 -0700 Subject: [PATCH 0129/1663] syscall: support windows/arm Updates #26148 Change-Id: I008502232642237270b7c8a2efb4a378345d06fd Reviewed-on: https://go-review.googlesource.com/128716 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Ian Lance Taylor --- src/syscall/syscall_windows.go | 12 ++++++++++-- src/syscall/types_windows_arm.go | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 src/syscall/types_windows_arm.go diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go index b234f3d67d4ce..638a81882af9b 100644 --- a/src/syscall/syscall_windows.go +++ b/src/syscall/syscall_windows.go @@ -9,6 +9,7 @@ package syscall import ( errorspkg "errors" "internal/race" + "runtime" "sync" "unicode/utf16" "unsafe" @@ -340,12 +341,19 @@ const ptrSize = unsafe.Sizeof(uintptr(0)) // See https://msdn.microsoft.com/en-us/library/windows/desktop/aa365542(v=vs.85).aspx func setFilePointerEx(handle Handle, distToMove int64, newFilePointer *int64, whence uint32) error { var e1 Errno - if ptrSize == 8 { + switch runtime.GOARCH { + default: + panic("unsupported architecture") + case "amd64": _, _, e1 = Syscall6(procSetFilePointerEx.Addr(), 4, uintptr(handle), uintptr(distToMove), uintptr(unsafe.Pointer(newFilePointer)), uintptr(whence), 0, 0) - } else { + case "386": // distToMove is a LARGE_INTEGER: // https://msdn.microsoft.com/en-us/library/windows/desktop/aa383713(v=vs.85).aspx _, _, e1 = Syscall6(procSetFilePointerEx.Addr(), 5, uintptr(handle), uintptr(distToMove), uintptr(distToMove>>32), uintptr(unsafe.Pointer(newFilePointer)), uintptr(whence), 0) + case "arm": + // distToMove must be 8-byte aligned per ARM calling convention + // https://msdn.microsoft.com/en-us/library/dn736986.aspx#Anchor_7 + _, _, e1 = Syscall6(procSetFilePointerEx.Addr(), 6, uintptr(handle), 0, uintptr(distToMove), uintptr(distToMove>>32), uintptr(unsafe.Pointer(newFilePointer)), uintptr(whence)) } if e1 != 0 { return errnoErr(e1) diff --git a/src/syscall/types_windows_arm.go b/src/syscall/types_windows_arm.go new file mode 100644 index 0000000000000..e72e9f5ced2bd --- /dev/null +++ b/src/syscall/types_windows_arm.go @@ -0,0 +1,22 @@ +// Copyright 2018 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. + +package syscall + +type WSAData struct { + Version uint16 + HighVersion uint16 + Description [WSADESCRIPTION_LEN + 1]byte + SystemStatus [WSASYS_STATUS_LEN + 1]byte + MaxSockets uint16 + MaxUdpDg uint16 + VendorInfo *byte +} + +type Servent struct { + Name *byte + Aliases **byte + Port uint16 + Proto *byte +} From 1484270aec14b9d971b94832d0fac9d3db382cf9 Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Wed, 18 Jul 2018 13:05:29 +0300 Subject: [PATCH 0130/1663] test: restore tests for the reject unsafe code option Tests in test/safe were neglected after moving to the run.go framework. This change restores them. These tests are skipped for go/types via -+ option. Fixes #25668 Change-Id: I8fe26574a76fa7afa8664c467d7c2e6334f1bba9 Reviewed-on: https://go-review.googlesource.com/124660 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- test/safe/main.go | 14 -------------- test/safe/nousesafe.go | 8 -------- test/safe/pkg.go | 16 ---------------- test/safe/usesafe.go | 8 -------- test/unsafereject1.go | 16 ++++++++++++++++ test/unsafereject2.go | 15 +++++++++++++++ 6 files changed, 31 insertions(+), 46 deletions(-) delete mode 100644 test/safe/main.go delete mode 100644 test/safe/nousesafe.go delete mode 100644 test/safe/pkg.go delete mode 100644 test/safe/usesafe.go create mode 100644 test/unsafereject1.go create mode 100644 test/unsafereject2.go diff --git a/test/safe/main.go b/test/safe/main.go deleted file mode 100644 index d173ed9266395..0000000000000 --- a/test/safe/main.go +++ /dev/null @@ -1,14 +0,0 @@ -// true - -// Copyright 2012 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. - -package main - -// can't use local path with -u, use -I. instead -import "pkg" // ERROR "import unsafe package" - -func main() { - print(pkg.Float32bits(1.0)) -} diff --git a/test/safe/nousesafe.go b/test/safe/nousesafe.go deleted file mode 100644 index fcd25af315481..0000000000000 --- a/test/safe/nousesafe.go +++ /dev/null @@ -1,8 +0,0 @@ -// $G $D/pkg.go && pack grc pkg.a pkg.$A 2> /dev/null && rm pkg.$A && errchk $G -I . -u $D/main.go -// rm -f pkg.a - -// Copyright 2012 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. - -package ignored diff --git a/test/safe/pkg.go b/test/safe/pkg.go deleted file mode 100644 index bebc43a214cb3..0000000000000 --- a/test/safe/pkg.go +++ /dev/null @@ -1,16 +0,0 @@ -// true - -// Copyright 2012 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. - -// a package that uses unsafe on the inside but not in it's api - -package pkg - -import "unsafe" - -// this should be inlinable -func Float32bits(f float32) uint32 { - return *(*uint32)(unsafe.Pointer(&f)) -} \ No newline at end of file diff --git a/test/safe/usesafe.go b/test/safe/usesafe.go deleted file mode 100644 index 5d0829e290b7c..0000000000000 --- a/test/safe/usesafe.go +++ /dev/null @@ -1,8 +0,0 @@ -// $G $D/pkg.go && pack grcS pkg.a pkg.$A 2> /dev/null && rm pkg.$A && $G -I . -u $D/main.go -// rm -f pkg.a - -// Copyright 2012 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. - -package ignored diff --git a/test/unsafereject1.go b/test/unsafereject1.go new file mode 100644 index 0000000000000..12f77f963fc5e --- /dev/null +++ b/test/unsafereject1.go @@ -0,0 +1,16 @@ +// errorcheck -u -+ + +// Copyright 2018 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. + +// Check that we cannot import a package that uses "unsafe" internally +// when -u is supplied. + +package main + +import "syscall" // ERROR "import unsafe package" + +func main() { + print(syscall.Environ()) +} diff --git a/test/unsafereject2.go b/test/unsafereject2.go new file mode 100644 index 0000000000000..04ad0578c93a8 --- /dev/null +++ b/test/unsafereject2.go @@ -0,0 +1,15 @@ +// errorcheck -u -+ + +// Copyright 2018 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. + +// Check that we cannot import the "unsafe" package when -u is supplied. + +package a + +import "unsafe" // ERROR "import package unsafe" + +func Float32bits(f float32) uint32 { + return *(*uint32)(unsafe.Pointer(&f)) +} From 811b187a4f1e8052eb84a03b5fb399af1eefbdbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 18 May 2018 18:31:05 +0100 Subject: [PATCH 0131/1663] encoding/base64: slight decoding speed-up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First, use a dummy slice access on decode64 and decode32 to ensure that there is a single bounds check for src. Second, move the PutUint64/PutUint32 calls out of these functions, meaning that they are simpler and smaller. This may also open the door to inlineability in the future, but for now, they both go past the budget. While at it, get rid of the ilen and olen variables, which have no impact whatsoever on performance. At least, not measurable by any of the benchmarks. name old time/op new time/op delta DecodeString/2-4 54.3ns ± 1% 55.2ns ± 2% +1.60% (p=0.017 n=5+6) DecodeString/4-4 66.6ns ± 1% 66.8ns ± 2% ~ (p=0.903 n=6+6) DecodeString/8-4 79.3ns ± 2% 79.6ns ± 1% ~ (p=0.448 n=6+6) DecodeString/64-4 300ns ± 1% 281ns ± 3% -6.54% (p=0.002 n=6+6) DecodeString/8192-4 27.4µs ± 1% 23.7µs ± 2% -13.47% (p=0.002 n=6+6) name old speed new speed delta DecodeString/2-4 73.7MB/s ± 1% 72.5MB/s ± 2% -1.55% (p=0.026 n=5+6) DecodeString/4-4 120MB/s ± 1% 120MB/s ± 2% ~ (p=0.851 n=6+6) DecodeString/8-4 151MB/s ± 2% 151MB/s ± 1% ~ (p=0.485 n=6+6) DecodeString/64-4 292MB/s ± 1% 313MB/s ± 3% +7.03% (p=0.002 n=6+6) DecodeString/8192-4 399MB/s ± 1% 461MB/s ± 2% +15.58% (p=0.002 n=6+6) For #19636. Change-Id: I0dfbdafa2a41dc4c582f63aef94b90b8e473731c Reviewed-on: https://go-review.googlesource.com/113776 Reviewed-by: Ian Lance Taylor --- src/encoding/base64/base64.go | 66 +++++++++++++++++------------------ 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/src/encoding/base64/base64.go b/src/encoding/base64/base64.go index 9a99370f1e530..e8afc48859182 100644 --- a/src/encoding/base64/base64.go +++ b/src/encoding/base64/base64.go @@ -465,10 +465,9 @@ func (enc *Encoding) Decode(dst, src []byte) (n int, err error) { } si := 0 - ilen := len(src) - olen := len(dst) - for strconv.IntSize >= 64 && ilen-si >= 8 && olen-n >= 8 { - if ok := enc.decode64(dst[n:], src[si:]); ok { + for strconv.IntSize >= 64 && len(src)-si >= 8 && len(dst)-n >= 8 { + if dn, ok := enc.decode64(src[si:]); ok { + binary.BigEndian.PutUint64(dst[n:], dn) n += 6 si += 8 } else { @@ -481,8 +480,9 @@ func (enc *Encoding) Decode(dst, src []byte) (n int, err error) { } } - for ilen-si >= 4 && olen-n >= 4 { - if ok := enc.decode32(dst[n:], src[si:]); ok { + for len(src)-si >= 4 && len(dst)-n >= 4 { + if dn, ok := enc.decode32(src[si:]); ok { + binary.BigEndian.PutUint32(dst[n:], dn) n += 3 si += 4 } else { @@ -506,72 +506,70 @@ func (enc *Encoding) Decode(dst, src []byte) (n int, err error) { return n, err } -// decode32 tries to decode 4 base64 char into 3 bytes. -// len(dst) and len(src) must both be >= 4. -// Returns true if decode succeeded. -func (enc *Encoding) decode32(dst, src []byte) bool { - var dn, n uint32 +// decode32 tries to decode 4 base64 characters into 3 bytes, and returns those +// bytes. len(src) must be >= 4. +// Returns (0, false) if decoding failed. +func (enc *Encoding) decode32(src []byte) (dn uint32, ok bool) { + var n uint32 + _ = src[3] if n = uint32(enc.decodeMap[src[0]]); n == 0xff { - return false + return 0, false } dn |= n << 26 if n = uint32(enc.decodeMap[src[1]]); n == 0xff { - return false + return 0, false } dn |= n << 20 if n = uint32(enc.decodeMap[src[2]]); n == 0xff { - return false + return 0, false } dn |= n << 14 if n = uint32(enc.decodeMap[src[3]]); n == 0xff { - return false + return 0, false } dn |= n << 8 - - binary.BigEndian.PutUint32(dst, dn) - return true + return dn, true } -// decode64 tries to decode 8 base64 char into 6 bytes. -// len(dst) and len(src) must both be >= 8. -// Returns true if decode succeeded. -func (enc *Encoding) decode64(dst, src []byte) bool { - var dn, n uint64 +// decode64 tries to decode 8 base64 characters into 6 bytes, and returns those +// bytes. len(src) must be >= 8. +// Returns (0, false) if decoding failed. +func (enc *Encoding) decode64(src []byte) (dn uint64, ok bool) { + var n uint64 + _ = src[7] if n = uint64(enc.decodeMap[src[0]]); n == 0xff { - return false + return 0, false } dn |= n << 58 if n = uint64(enc.decodeMap[src[1]]); n == 0xff { - return false + return 0, false } dn |= n << 52 if n = uint64(enc.decodeMap[src[2]]); n == 0xff { - return false + return 0, false } dn |= n << 46 if n = uint64(enc.decodeMap[src[3]]); n == 0xff { - return false + return 0, false } dn |= n << 40 if n = uint64(enc.decodeMap[src[4]]); n == 0xff { - return false + return 0, false } dn |= n << 34 if n = uint64(enc.decodeMap[src[5]]); n == 0xff { - return false + return 0, false } dn |= n << 28 if n = uint64(enc.decodeMap[src[6]]); n == 0xff { - return false + return 0, false } dn |= n << 22 if n = uint64(enc.decodeMap[src[7]]); n == 0xff { - return false + return 0, false } dn |= n << 16 - - binary.BigEndian.PutUint64(dst, dn) - return true + return dn, true } type newlineFilteringReader struct { From 2fad8b219ff9f13f10396c97c0a3bca5c6153d78 Mon Sep 17 00:00:00 2001 From: Zhou Peng Date: Mon, 20 Aug 2018 01:13:33 +0000 Subject: [PATCH 0132/1663] runtime: fix typo: there -> the Change-Id: I2ecbd68b1b30ab64e64ae120101761400c22457b Reviewed-on: https://go-review.googlesource.com/129757 Reviewed-by: Brad Fitzpatrick --- src/runtime/mgc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index e4c0f5a587629..f54c8eb14f540 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -407,7 +407,7 @@ type gcControllerState struct { // each P that isn't running a dedicated worker. // // For example, if the utilization goal is 25% and there are - // no dedicated workers, this will be 0.25. If there goal is + // no dedicated workers, this will be 0.25. If the goal is // 25%, there is one dedicated worker, and GOMAXPROCS is 5, // this will be 0.05 to make up the missing 5%. // From b0dc54697ba34494a4d77e8d3e446070fc7b223b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Fri, 1 Jun 2018 19:25:57 +0200 Subject: [PATCH 0133/1663] runtime: replace calls to hasprefix with hasPrefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The hasprefix function is redundant and can be removed since it has the same implementation as hasPrefix modulo variable names. Fixes #25688 Change-Id: I499cc24a2b5c38d1301718a4e66f555fd138386f Reviewed-on: https://go-review.googlesource.com/115835 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Ilya Tocar --- src/runtime/export_debug_test.go | 2 +- src/runtime/os3_plan9.go | 2 +- src/runtime/os_plan9.go | 10 +++++----- src/runtime/proc.go | 4 ++-- src/runtime/string.go | 6 +++--- src/runtime/traceback.go | 4 ++-- src/runtime/type.go | 4 ---- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/runtime/export_debug_test.go b/src/runtime/export_debug_test.go index d34c1fd7dc58d..74f8855de6554 100644 --- a/src/runtime/export_debug_test.go +++ b/src/runtime/export_debug_test.go @@ -115,7 +115,7 @@ func (h *debugCallHandler) handle(info *siginfo, ctxt *sigctxt, gp2 *g) bool { return false } f := findfunc(uintptr(ctxt.rip())) - if !(hasprefix(funcname(f), "runtime.debugCall") || hasprefix(funcname(f), "debugCall")) { + if !(hasPrefix(funcname(f), "runtime.debugCall") || hasPrefix(funcname(f), "debugCall")) { println("trap in unknown function", funcname(f)) return false } diff --git a/src/runtime/os3_plan9.go b/src/runtime/os3_plan9.go index 0e3a4c8024e19..15ca3359d2bf7 100644 --- a/src/runtime/os3_plan9.go +++ b/src/runtime/os3_plan9.go @@ -44,7 +44,7 @@ func sighandler(_ureg *ureg, note *byte, gp *g) int { // level by the program but will otherwise be ignored. flags = _SigNotify for sig, t = range sigtable { - if hasprefix(notestr, t.name) { + if hasPrefix(notestr, t.name) { flags = t.flags break } diff --git a/src/runtime/os_plan9.go b/src/runtime/os_plan9.go index 9f41c5ac83a06..5469114a2b7db 100644 --- a/src/runtime/os_plan9.go +++ b/src/runtime/os_plan9.go @@ -112,20 +112,20 @@ func sigpanic() { } func atolwhex(p string) int64 { - for hasprefix(p, " ") || hasprefix(p, "\t") { + for hasPrefix(p, " ") || hasPrefix(p, "\t") { p = p[1:] } neg := false - if hasprefix(p, "-") || hasprefix(p, "+") { + if hasPrefix(p, "-") || hasPrefix(p, "+") { neg = p[0] == '-' p = p[1:] - for hasprefix(p, " ") || hasprefix(p, "\t") { + for hasPrefix(p, " ") || hasPrefix(p, "\t") { p = p[1:] } } var n int64 switch { - case hasprefix(p, "0x"), hasprefix(p, "0X"): + case hasPrefix(p, "0x"), hasPrefix(p, "0X"): p = p[2:] for ; len(p) > 0; p = p[1:] { if '0' <= p[0] && p[0] <= '9' { @@ -138,7 +138,7 @@ func atolwhex(p string) int64 { break } } - case hasprefix(p, "0"): + case hasPrefix(p, "0"): for ; len(p) > 0 && '0' <= p[0] && p[0] <= '7'; p = p[1:] { n = n*8 + int64(p[0]-'0') } diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 31b188efd9ee9..32467715c44d9 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -498,7 +498,7 @@ func cpuinit() { p := argv_index(argv, argc+1+i) s := *(*string)(unsafe.Pointer(&stringStruct{unsafe.Pointer(p), findnull(p)})) - if hasprefix(s, prefix) { + if hasPrefix(s, prefix) { env = gostring(p)[len(prefix):] break } @@ -3702,7 +3702,7 @@ func sigprof(pc, sp, lr uintptr, gp *g, mp *m) { // received from somewhere else (with _LostSIGPROFDuringAtomic64 as pc). if GOARCH == "mips" || GOARCH == "mipsle" || GOARCH == "arm" { if f := findfunc(pc); f.valid() { - if hasprefix(funcname(f), "runtime/internal/atomic") { + if hasPrefix(funcname(f), "runtime/internal/atomic") { lostAtomic64Count++ return } diff --git a/src/runtime/string.go b/src/runtime/string.go index 6e42483b13d67..d10bd96f434d3 100644 --- a/src/runtime/string.go +++ b/src/runtime/string.go @@ -333,7 +333,7 @@ func index(s, t string) int { return 0 } for i := 0; i < len(s); i++ { - if s[i] == t[0] && hasprefix(s[i:], t) { + if s[i] == t[0] && hasPrefix(s[i:], t) { return i } } @@ -344,8 +344,8 @@ func contains(s, t string) bool { return index(s, t) >= 0 } -func hasprefix(s, t string) bool { - return len(s) >= len(t) && s[:len(t)] == t +func hasPrefix(s, prefix string) bool { + return len(s) >= len(prefix) && s[:len(prefix)] == prefix } const ( diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index d8c225d975fa2..a1f32016b9e52 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -843,7 +843,7 @@ func showfuncinfo(f funcInfo, firstFrame, elideWrapper bool) bool { return true } - return contains(name, ".") && (!hasprefix(name, "runtime.") || isExportedRuntime(name)) + return contains(name, ".") && (!hasPrefix(name, "runtime.") || isExportedRuntime(name)) } // isExportedRuntime reports whether name is an exported runtime function. @@ -1022,7 +1022,7 @@ func isSystemGoroutine(gp *g) bool { // back into user code. return !fingRunning } - return hasprefix(funcname(f), "runtime.") + return hasPrefix(funcname(f), "runtime.") } // SetCgoTraceback records three C functions to use to gather diff --git a/src/runtime/type.go b/src/runtime/type.go index 4b38c351c7ee7..88a44a37ed3da 100644 --- a/src/runtime/type.go +++ b/src/runtime/type.go @@ -112,10 +112,6 @@ func (t *_type) uncommon() *uncommontype { } } -func hasPrefix(s, prefix string) bool { - return len(s) >= len(prefix) && s[:len(prefix)] == prefix -} - func (t *_type) name() string { if t.tflag&tflagNamed == 0 { return "" From 3879ea54ed1f5c266657ffe593e2a8e1b63401ec Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Mon, 6 Aug 2018 14:16:43 +0300 Subject: [PATCH 0134/1663] runtime: fix Go prototypes in amd64 asm code Also adds some missing asmdecl comments for funcs with Go proto. Change-Id: Iabc68e8c0ad936e06ed719e0f030bfc5f6f6e168 Reviewed-on: https://go-review.googlesource.com/127760 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/runtime/asm_amd64.s | 22 +++++++++++++++------- src/runtime/stubs.go | 2 +- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s index 6902ce2c22c02..6c65674b3b0aa 100644 --- a/src/runtime/asm_amd64.s +++ b/src/runtime/asm_amd64.s @@ -228,7 +228,7 @@ TEXT runtime·asminit(SB),NOSPLIT,$0-0 * go-routine */ -// void gosave(Gobuf*) +// func gosave(buf *gobuf) // save state in Gobuf; setjmp TEXT runtime·gosave(SB), NOSPLIT, $0-8 MOVQ buf+0(FP), AX // gobuf @@ -248,7 +248,7 @@ TEXT runtime·gosave(SB), NOSPLIT, $0-8 MOVQ BX, gobuf_g(AX) RET -// void gogo(Gobuf*) +// func gogo(buf *gobuf) // restore state from Gobuf; longjmp TEXT runtime·gogo(SB), NOSPLIT, $16-8 MOVQ buf+0(FP), BX // gobuf @@ -560,7 +560,8 @@ TEXT ·publicationBarrier(SB),NOSPLIT,$0-0 // compile barrier. RET -// void jmpdefer(fn, sp); +// func jmpdefer(fv *funcval, argp uintptr) +// argp is a caller SP. // called from deferreturn. // 1. pop the caller // 2. sub 5 bytes from the callers return @@ -670,7 +671,7 @@ nosave: MOVL AX, ret+16(FP) RET -// cgocallback(void (*fn)(void*), void *frame, uintptr framesize, uintptr ctxt) +// func cgocallback(fn, frame unsafe.Pointer, framesize, ctxt uintptr) // Turn the fn into a Go func (by taking its address) and call // cgocallback_gofunc. TEXT runtime·cgocallback(SB),NOSPLIT,$32-32 @@ -686,7 +687,7 @@ TEXT runtime·cgocallback(SB),NOSPLIT,$32-32 CALL AX RET -// cgocallback_gofunc(FuncVal*, void *frame, uintptr framesize, uintptr ctxt) +// func cgocallback_gofunc(fn, frame, framesize, ctxt uintptr) // See cgocall.go for more details. TEXT ·cgocallback_gofunc(SB),NOSPLIT,$16-32 NO_LOCAL_POINTERS @@ -811,7 +812,8 @@ havem: // Done! RET -// void setg(G*); set g. for use by needm. +// func setg(gg *g) +// set g. for use by needm. TEXT runtime·setg(SB), NOSPLIT, $0-8 MOVQ gg+0(FP), BX #ifdef GOOS_windows @@ -866,6 +868,7 @@ done: MOVQ AX, ret+0(FP) RET +// func aeshash(p unsafe.Pointer, h, s uintptr) uintptr // hash function using AES hardware instructions TEXT runtime·aeshash(SB),NOSPLIT,$0-32 MOVQ p+0(FP), AX // ptr to data @@ -873,6 +876,7 @@ TEXT runtime·aeshash(SB),NOSPLIT,$0-32 LEAQ ret+24(FP), DX JMP runtime·aeshashbody(SB) +// func aeshashstr(p unsafe.Pointer, h uintptr) uintptr TEXT runtime·aeshashstr(SB),NOSPLIT,$0-24 MOVQ p+0(FP), AX // ptr to string struct MOVQ 8(AX), CX // length of string @@ -1210,7 +1214,8 @@ aesloop: PXOR X9, X8 MOVQ X8, (DX) RET - + +// func aeshash32(p unsafe.Pointer, h uintptr) uintptr TEXT runtime·aeshash32(SB),NOSPLIT,$0-24 MOVQ p+0(FP), AX // ptr to data MOVQ h+8(FP), X0 // seed @@ -1221,6 +1226,7 @@ TEXT runtime·aeshash32(SB),NOSPLIT,$0-24 MOVQ X0, ret+16(FP) RET +// func aeshash64(p unsafe.Pointer, h uintptr) uintptr TEXT runtime·aeshash64(SB),NOSPLIT,$0-24 MOVQ p+0(FP), AX // ptr to data MOVQ h+8(FP), X0 // seed @@ -1266,6 +1272,7 @@ DATA masks<>+0xf0(SB)/8, $0xffffffffffffffff DATA masks<>+0xf8(SB)/8, $0x00ffffffffffffff GLOBL masks<>(SB),RODATA,$256 +// func checkASM() bool TEXT ·checkASM(SB),NOSPLIT,$0-1 // check that masks<>(SB) and shifts<>(SB) are aligned to 16-byte MOVQ $masks<>(SB), AX @@ -1616,6 +1623,7 @@ DEBUG_CALL_FN(debugCall16384<>, 16384) DEBUG_CALL_FN(debugCall32768<>, 32768) DEBUG_CALL_FN(debugCall65536<>, 65536) +// func debugCallPanicked(val interface{}) TEXT runtime·debugCallPanicked(SB),NOSPLIT,$16-16 // Copy the panic value to the top of stack. MOVQ val_type+0(FP), AX diff --git a/src/runtime/stubs.go b/src/runtime/stubs.go index 74b385d5960cd..632b1e2293f88 100644 --- a/src/runtime/stubs.go +++ b/src/runtime/stubs.go @@ -178,7 +178,7 @@ func goexit(neverCallThisFunction) // cgocallback_gofunc is not called from go, only from cgocallback, // so the arguments will be found via cgocallback's pointer-declared arguments. // See the assembly implementations for more details. -func cgocallback_gofunc(fv uintptr, frame uintptr, framesize, ctxt uintptr) +func cgocallback_gofunc(fv, frame, framesize, ctxt uintptr) // publicationBarrier performs a store/store barrier (a "publication" // or "export" barrier). Some form of synchronization is required From f2d7e66e98d64941313147c0dfe2f31645830716 Mon Sep 17 00:00:00 2001 From: Roland Illig Date: Mon, 13 Aug 2018 21:28:28 +0200 Subject: [PATCH 0135/1663] runtime/pprof: fix resource leak in documentation Fixes #26970 Change-Id: I0f2695434a53550cf84f702e9d8d02a37448d396 Reviewed-on: https://go-review.googlesource.com/129195 Reviewed-by: Brad Fitzpatrick --- src/runtime/pprof/pprof.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/runtime/pprof/pprof.go b/src/runtime/pprof/pprof.go index c1024c99ed26a..74cdd15cfbd16 100644 --- a/src/runtime/pprof/pprof.go +++ b/src/runtime/pprof/pprof.go @@ -28,6 +28,7 @@ // if err != nil { // log.Fatal("could not create CPU profile: ", err) // } +// defer f.Close() // if err := pprof.StartCPUProfile(f); err != nil { // log.Fatal("could not start CPU profile: ", err) // } @@ -41,11 +42,11 @@ // if err != nil { // log.Fatal("could not create memory profile: ", err) // } +// defer f.Close() // runtime.GC() // get up-to-date statistics // if err := pprof.WriteHeapProfile(f); err != nil { // log.Fatal("could not write memory profile: ", err) // } -// f.Close() // } // } // From cfbe3cfbeb6b2de561fc709b8644d4d7a4e182bb Mon Sep 17 00:00:00 2001 From: Lynn Boger Date: Thu, 16 Aug 2018 10:49:35 -0400 Subject: [PATCH 0136/1663] runtime: fix implementation of cputicks for ppc64x The implementation of cputicks has been wrong for ppc64x. The previous code sequence is for 32 bit, not 64 bit. Change-Id: I308ae6cf9131f53a0100cd3f8ae4e16601f2d553 Reviewed-on: https://go-review.googlesource.com/129595 Run-TryBot: Lynn Boger TryBot-Result: Gobot Gobot Reviewed-by: Carlos Eduardo Seo Reviewed-by: Brad Fitzpatrick --- src/runtime/asm_ppc64x.s | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/runtime/asm_ppc64x.s b/src/runtime/asm_ppc64x.s index 0886de9f2ba7c..57877c0194c7d 100644 --- a/src/runtime/asm_ppc64x.s +++ b/src/runtime/asm_ppc64x.s @@ -723,18 +723,11 @@ TEXT runtime·abort(SB),NOSPLIT|NOFRAME,$0-0 MOVW (R0), R0 UNDEF -#define TBRL 268 -#define TBRU 269 /* Time base Upper/Lower */ +#define TBR 268 // int64 runtime·cputicks(void) TEXT runtime·cputicks(SB),NOSPLIT,$0-8 - MOVW SPR(TBRU), R4 - MOVW SPR(TBRL), R3 - MOVW SPR(TBRU), R5 - CMPW R4, R5 - BNE -4(PC) - SLD $32, R5 - OR R5, R3 + MOVD SPR(TBR), R3 MOVD R3, ret+0(FP) RET From 68527ff4fb32c98b1f15367c65c526c2b2b3a57a Mon Sep 17 00:00:00 2001 From: Thanabodee Charoenpiriyakij Date: Thu, 19 Jul 2018 08:16:44 +0700 Subject: [PATCH 0137/1663] runtime: remove +1-1 when asking PC values Fixes #26437 Change-Id: Id47b3bcc23ea7b7b17b55dd96b5830c48fd8d53d Reviewed-on: https://go-review.googlesource.com/124895 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/runtime/extern.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/extern.go b/src/runtime/extern.go index 2788bd354b16c..1773c8fe7ebe4 100644 --- a/src/runtime/extern.go +++ b/src/runtime/extern.go @@ -176,7 +176,7 @@ func Caller(skip int) (pc uintptr, file string, line int, ok bool) { // what it called, so that CallersFrames can see if it "called" // sigpanic, and possibly a PC for skipPleaseUseCallersFrames. var rpc [3]uintptr - if callers(1+skip-1, rpc[:]) < 2 { + if callers(skip, rpc[:]) < 2 { return } var stackExpander stackExpander From 0a519401651f46a098c5c295943cc1c48e53a48c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 6 Jul 2018 22:57:35 -0700 Subject: [PATCH 0138/1663] runtime: make TestGcSys actually test something The workthegc function was being inlined, and the slice did not escape, so there was no memory allocation. Use a sink variable to force memory allocation, at least for now. Fixes #23343 Change-Id: I02f4618e343c8b6cb552cb4e9f272e112785f7cf Reviewed-on: https://go-review.googlesource.com/122576 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick --- src/runtime/testdata/testprog/gc.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/runtime/testdata/testprog/gc.go b/src/runtime/testdata/testprog/gc.go index 744b6108e2bc3..3ca74ba5feefa 100644 --- a/src/runtime/testdata/testprog/gc.go +++ b/src/runtime/testdata/testprog/gc.go @@ -48,8 +48,11 @@ func GCSys() { fmt.Printf("OK\n") } +var sink []byte + func workthegc() []byte { - return make([]byte, 1029) + sink = make([]byte, 1029) + return sink } func GCFairness() { From fa6639d62664ecd710b112eb1c1e759104c9193c Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Wed, 11 Jul 2018 23:34:18 +0300 Subject: [PATCH 0139/1663] runtime: simplify slice expression to sliced value itself Replace `x[:]` where x is a slice with just `x`. Found using https://go-critic.github.io/overview.html#unslice-ref Change-Id: Ib0ee16e1d49b2a875b6b92a770049acc33208362 Reviewed-on: https://go-review.googlesource.com/123375 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/runtime/trace.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/trace.go b/src/runtime/trace.go index 61f7513ee0e5a..22d8d026dc67c 100644 --- a/src/runtime/trace.go +++ b/src/runtime/trace.go @@ -584,10 +584,10 @@ func traceStackID(mp *m, buf []uintptr, skip int) uint64 { gp := mp.curg var nstk int if gp == _g_ { - nstk = callers(skip+1, buf[:]) + nstk = callers(skip+1, buf) } else if gp != nil { gp = mp.curg - nstk = gcallers(gp, skip, buf[:]) + nstk = gcallers(gp, skip, buf) } if nstk > 0 { nstk-- // skip runtime.goexit From fd7d3259c93e8901f5645fd5de620cd75053c7ca Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Tue, 10 Jul 2018 08:32:56 +0300 Subject: [PATCH 0140/1663] runtime: remove redundant explicit deref in trace.go Replaces legacy Go syntax for pointer struct member access with more modern auto-deref alternative. Found using https://go-critic.github.io/overview#underef-ref Change-Id: I71a3c424126c4ff5d89f9e4bacb6cc01c6fa2ddf Reviewed-on: https://go-review.googlesource.com/122895 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/runtime/trace.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/runtime/trace.go b/src/runtime/trace.go index 22d8d026dc67c..08e92d2efe6b9 100644 --- a/src/runtime/trace.go +++ b/src/runtime/trace.go @@ -532,12 +532,12 @@ func traceEvent(ev byte, skip int, args ...uint64) { } func traceEventLocked(extraBytes int, mp *m, pid int32, bufp *traceBufPtr, ev byte, skip int, args ...uint64) { - buf := (*bufp).ptr() + buf := bufp.ptr() // TODO: test on non-zero extraBytes param. maxSize := 2 + 5*traceBytesPerNumber + extraBytes // event type, length, sequence, timestamp, stack id and two add params if buf == nil || len(buf.arr)-buf.pos < maxSize { buf = traceFlush(traceBufPtrOf(buf), pid).ptr() - (*bufp).set(buf) + bufp.set(buf) } ticks := uint64(cputicks()) / traceTickDiv @@ -689,11 +689,11 @@ func traceString(bufp *traceBufPtr, pid int32, s string) (uint64, *traceBufPtr) // so there must be no memory allocation or any activities // that causes tracing after this point. - buf := (*bufp).ptr() + buf := bufp.ptr() size := 1 + 2*traceBytesPerNumber + len(s) if buf == nil || len(buf.arr)-buf.pos < size { buf = traceFlush(traceBufPtrOf(buf), pid).ptr() - (*bufp).set(buf) + bufp.set(buf) } buf.byte(traceEvString) buf.varint(id) @@ -708,7 +708,7 @@ func traceString(bufp *traceBufPtr, pid int32, s string) (uint64, *traceBufPtr) buf.varint(uint64(slen)) buf.pos += copy(buf.arr[buf.pos:], s[:slen]) - (*bufp).set(buf) + bufp.set(buf) return id, bufp } @@ -1206,7 +1206,7 @@ func trace_userLog(id uint64, category, message string) { traceEventLocked(extraSpace, mp, pid, bufp, traceEvUserLog, 3, id, categoryID) // traceEventLocked reserved extra space for val and len(val) // in buf, so buf now has room for the following. - buf := (*bufp).ptr() + buf := bufp.ptr() // double-check the message and its length can fit. // Otherwise, truncate the message. From 7b8930ed4587a7f423380220be170daedc620c49 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 22 Aug 2018 19:53:45 +0000 Subject: [PATCH 0141/1663] runtime: fix build, rename a since-renamed hasprefix to hasPrefix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit I merged CL 115835 without testing it after a rebase. My bad. Change-Id: I0acc6ed78ea7d718ac2df11d509cfcf4364dfaee Reviewed-on: https://go-review.googlesource.com/130815 Run-TryBot: Brad Fitzpatrick Reviewed-by: Martin Möhrmann --- src/runtime/panic.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/runtime/panic.go b/src/runtime/panic.go index a5287a0b86e41..45be886196cf7 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -37,7 +37,7 @@ var indexError = error(errorString("index out of range")) // entire runtime stack for easier debugging. func panicindex() { - if hasprefix(funcname(findfunc(getcallerpc())), "runtime.") { + if hasPrefix(funcname(findfunc(getcallerpc())), "runtime.") { throw(string(indexError.(errorString))) } panicCheckMalloc(indexError) @@ -47,7 +47,7 @@ func panicindex() { var sliceError = error(errorString("slice bounds out of range")) func panicslice() { - if hasprefix(funcname(findfunc(getcallerpc())), "runtime.") { + if hasPrefix(funcname(findfunc(getcallerpc())), "runtime.") { throw(string(sliceError.(errorString))) } panicCheckMalloc(sliceError) From 8c0425825ced4042eac0439161abe1f22a47d615 Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Thu, 14 Jun 2018 18:20:03 +0300 Subject: [PATCH 0142/1663] cmd/compile: display Go code for a function in ssa.html This CL adds the "sources" column at the beginning of SSA table. This column displays the source code for the function being passed in the GOSSAFUNC env variable. Also UI was extended so that clicking on particular line will highlight all places this line is referenced. JS code was cleaned and formatted. This CL does not handle inlined functions. See issue 25904. Change-Id: Ic7833a0b05e38795f4cf090f3dc82abf62d97026 Reviewed-on: https://go-review.googlesource.com/119035 Run-TryBot: Yury Smolsky TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/ssa.go | 26 +++++- src/cmd/compile/internal/ssa/html.go | 116 +++++++++++++++++++-------- 2 files changed, 107 insertions(+), 35 deletions(-) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 7b254698b793c..9f9fdc07f8d4f 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -5,6 +5,7 @@ package gc import ( + "bufio" "bytes" "encoding/binary" "fmt" @@ -139,9 +140,30 @@ func buildssa(fn *Node, worker int) *ssa.Func { s.panics = map[funcLine]*ssa.Block{} s.softFloat = s.config.SoftFloat - if name == os.Getenv("GOSSAFUNC") { + if printssa { s.f.HTMLWriter = ssa.NewHTMLWriter("ssa.html", s.f.Frontend(), name) // TODO: generate and print a mapping from nodes to values and blocks + + // Read sources for a function fn and format into a column. + fname := Ctxt.PosTable.Pos(fn.Pos).Filename() + f, err := os.Open(fname) + if err != nil { + s.f.HTMLWriter.Logger.Logf("skipping sources column: %v", err) + } else { + defer f.Close() + firstLn := fn.Pos.Line() - 1 + lastLn := fn.Func.Endlineno.Line() + var lines []string + ln := uint(0) + scanner := bufio.NewScanner(f) + for scanner.Scan() && ln < lastLn { + if ln >= firstLn { + lines = append(lines, scanner.Text()) + } + ln++ + } + s.f.HTMLWriter.WriteSources("sources", fname, firstLn+1, lines) + } } // Allocate starting block @@ -5045,7 +5067,7 @@ func genssa(f *ssa.Func, pp *Progs) { } buf.WriteString("") buf.WriteString("
    ") - buf.WriteString(fmt.Sprintf("%.5d (%s) %s", p.Pc, p.InnermostLineNumberHTML(), html.EscapeString(p.InstructionString()))) + buf.WriteString(fmt.Sprintf("%.5d (%s) %s", p.Pc, p.InnermostLineNumber(), p.InnermostLineNumberHTML(), html.EscapeString(p.InstructionString()))) buf.WriteString("
    ") } buf.WriteString("") diff --git a/src/cmd/compile/internal/ssa/html.go b/src/cmd/compile/internal/ssa/html.go index 15d64d63e9b03..812590934920b 100644 --- a/src/cmd/compile/internal/ssa/html.go +++ b/src/cmd/compile/internal/ssa/html.go @@ -54,7 +54,7 @@ body { } .stats { - font-size: 60%; + font-size: 60%; } table { @@ -97,6 +97,26 @@ td.collapsed div { text-align: right; } +code, pre, .lines { + font-family: Menlo, monospace; + font-size: 12px; +} + +.lines { + float: left; + overflow: hidden; + text-align: right; +} + +.lines div { + padding-right: 10px; + color: gray; +} + +div.line-number { + font-size: 12px; +} + td.ssa-prog { width: 600px; word-wrap: break-word; @@ -158,10 +178,14 @@ dd.ssa-prog { } .line-number { - font-style: italic; font-size: 11px; } +.no-line-number { + font-size: 11px; + color: gray; +} + .highlight-aquamarine { background-color: aquamarine; } .highlight-coral { background-color: coral; } .highlight-lightpink { background-color: lightpink; } @@ -235,7 +259,7 @@ for (var i = 0; i < outlines.length; i++) { window.onload = function() { var ssaElemClicked = function(elem, event, selections, selected) { - event.stopPropagation() + event.stopPropagation(); // TODO: pushState with updated state and read it on page load, // so that state can survive across reloads @@ -288,11 +312,11 @@ window.onload = function() { var ssaValueClicked = function(event) { ssaElemClicked(this, event, highlights, highlighted); - } + }; var ssaBlockClicked = function(event) { ssaElemClicked(this, event, outlines, outlined); - } + }; var ssavalues = document.getElementsByClassName("ssa-value"); for (var i = 0; i < ssavalues.length; i++) { @@ -311,7 +335,14 @@ window.onload = function() { for (var i = 0; i < ssablocks.length; i++) { ssablocks[i].addEventListener('click', ssaBlockClicked); } - var expandedDefault = [ + + var lines = document.getElementsByClassName("line-number"); + for (var i = 0; i < lines.length; i++) { + lines[i].addEventListener('click', ssaValueClicked); + } + + // Contains phase names which are expanded by default. Other columns are collapsed. + var expandedDefault = [ "start", "deadcode", "opt", @@ -319,56 +350,53 @@ window.onload = function() { "late deadcode", "regalloc", "genssa", - ] - function isExpDefault(id) { - for (var i = 0; i < expandedDefault.length; i++) { - if (id.startsWith(expandedDefault[i])) { - return true; - } - } - return false; - } + ]; + function toggler(phase) { return function() { toggle_cell(phase+'-col'); toggle_cell(phase+'-exp'); }; } + function toggle_cell(id) { - var e = document.getElementById(id); - if(e.style.display == 'table-cell') - e.style.display = 'none'; - else - e.style.display = 'table-cell'; + var e = document.getElementById(id); + if (e.style.display == 'table-cell') { + e.style.display = 'none'; + } else { + e.style.display = 'table-cell'; + } } + // Go through all columns and collapse needed phases. var td = document.getElementsByTagName("td"); for (var i = 0; i < td.length; i++) { var id = td[i].id; - var def = isExpDefault(id); var phase = id.substr(0, id.length-4); + var show = expandedDefault.indexOf(phase) !== -1 if (id.endsWith("-exp")) { var h2 = td[i].getElementsByTagName("h2"); if (h2 && h2[0]) { h2[0].addEventListener('click', toggler(phase)); } } else { - td[i].addEventListener('click', toggler(phase)); + td[i].addEventListener('click', toggler(phase)); } - if (id.endsWith("-col") && def || id.endsWith("-exp") && !def) { - td[i].style.display = 'none'; - continue + if (id.endsWith("-col") && show || id.endsWith("-exp") && !show) { + td[i].style.display = 'none'; + continue; } td[i].style.display = 'table-cell'; } }; function toggle_visibility(id) { - var e = document.getElementById(id); - if(e.style.display == 'block') - e.style.display = 'none'; - else - e.style.display = 'block'; + var e = document.getElementById(id); + if (e.style.display == 'block') { + e.style.display = 'none'; + } else { + e.style.display = 'block'; + } } @@ -414,6 +442,7 @@ func (w *HTMLWriter) Close() { } // WriteFunc writes f in a column headed by title. +// phase is used for collapsing columns and should be unique across the table. func (w *HTMLWriter) WriteFunc(phase, title string, f *Func) { if w == nil { return // avoid generating HTML just to discard it @@ -422,6 +451,27 @@ func (w *HTMLWriter) WriteFunc(phase, title string, f *Func) { // TODO: Add visual representation of f's CFG. } +// WriteSources writes lines as source code in a column headed by title. +// phase is used for collapsing columns and should be unique across the table. +func (w *HTMLWriter) WriteSources(phase, title string, firstLineno uint, lines []string) { + if w == nil { + return // avoid generating HTML just to discard it + } + var buf bytes.Buffer + fmt.Fprint(&buf, "
    ") + for i, _ := range lines { + ln := int(firstLineno) + i + fmt.Fprintf(&buf, "
    %v
    ", ln, ln) + } + fmt.Fprint(&buf, "
    ")
    +	for i, l := range lines {
    +		ln := int(firstLineno) + i
    +		fmt.Fprintf(&buf, "
    %v
    ", ln, html.EscapeString(l)) + } + fmt.Fprint(&buf, "
    ") + w.WriteColumn(phase, title, "", buf.String()) +} + // WriteColumn writes raw HTML in a column headed by title. // It is intended for pre- and post-compilation log output. func (w *HTMLWriter) WriteColumn(phase, title, class, html string) { @@ -470,9 +520,9 @@ func (v *Value) LongHTML() string { // maybe we could replace some of that with formatting. s := fmt.Sprintf("", v.String()) - linenumber := "(?)" + linenumber := "(?)" if v.Pos.IsKnown() { - linenumber = fmt.Sprintf("(%s)", v.Pos.LineNumberHTML()) + linenumber = fmt.Sprintf("(%s)", v.Pos.LineNumber(), v.Pos.LineNumberHTML()) } s += fmt.Sprintf("%s %s = %s", v.HTML(), linenumber, v.Op.String()) @@ -536,7 +586,7 @@ func (b *Block) LongHTML() string { if b.Pos.IsKnown() { // TODO does not begin to deal with the full complexity of line numbers. // Maybe we want a string/slice instead, of outer-inner when inlining. - s += fmt.Sprintf(" (line %s)", b.Pos.LineNumberHTML()) + s += fmt.Sprintf(" (%s)", b.Pos.LineNumber(), b.Pos.LineNumberHTML()) } return s } From ede59583858bd64a09479f624e989e7c35df0c52 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Wed, 23 Nov 2016 15:34:08 -0500 Subject: [PATCH 0143/1663] reflect: add Value.MapRange method and MapIter type Example of use: iter := reflect.ValueOf(m).MapRange() for iter.Next() { k := iter.Key() v := iter.Value() ... } See issue golang/go#11104 Q. Are there any benchmarks that would exercise the new calls to copyval in existing code? Change-Id: Ic469fcab5f1d9d853e76225f89bde01ee1d36e7a Reviewed-on: https://go-review.googlesource.com/33572 Reviewed-by: Keith Randall --- src/reflect/all_test.go | 121 ++++++++++++++++++++++++++++++++++++++++ src/reflect/value.go | 106 +++++++++++++++++++++++++++++------ src/runtime/map.go | 5 ++ 3 files changed, 215 insertions(+), 17 deletions(-) diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index cf7fe3cf7ae72..33bd75fda5086 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -6576,3 +6576,124 @@ func TestIssue22073(t *testing.T) { // Shouldn't panic. m.Call(nil) } + +func TestMapIterNonEmptyMap(t *testing.T) { + m := map[string]int{"one": 1, "two": 2, "three": 3} + iter := ValueOf(m).MapRange() + if got, want := iterateToString(iter), `[one: 1, three: 3, two: 2]`; got != want { + t.Errorf("iterator returned %s (after sorting), want %s", got, want) + } +} + +func TestMapIterNilMap(t *testing.T) { + var m map[string]int + iter := ValueOf(m).MapRange() + if got, want := iterateToString(iter), `[]`; got != want { + t.Errorf("non-empty result iteratoring nil map: %s", got) + } +} + +func TestMapIterSafety(t *testing.T) { + // Using a zero MapIter causes a panic, but not a crash. + func() { + defer func() { recover() }() + new(MapIter).Key() + t.Fatal("Key did not panic") + }() + func() { + defer func() { recover() }() + new(MapIter).Value() + t.Fatal("Value did not panic") + }() + func() { + defer func() { recover() }() + new(MapIter).Next() + t.Fatal("Next did not panic") + }() + + // Calling Key/Value on a MapIter before Next + // causes a panic, but not a crash. + var m map[string]int + iter := ValueOf(m).MapRange() + + func() { + defer func() { recover() }() + iter.Key() + t.Fatal("Key did not panic") + }() + func() { + defer func() { recover() }() + iter.Value() + t.Fatal("Value did not panic") + }() + + // Calling Next, Key, or Value on an exhausted iterator + // causes a panic, but not a crash. + iter.Next() // -> false + func() { + defer func() { recover() }() + iter.Key() + t.Fatal("Key did not panic") + }() + func() { + defer func() { recover() }() + iter.Value() + t.Fatal("Value did not panic") + }() + func() { + defer func() { recover() }() + iter.Next() + t.Fatal("Next did not panic") + }() +} + +func TestMapIterNext(t *testing.T) { + // The first call to Next should reflect any + // insertions to the map since the iterator was created. + m := map[string]int{} + iter := ValueOf(m).MapRange() + m["one"] = 1 + if got, want := iterateToString(iter), `[one: 1]`; got != want { + t.Errorf("iterator returned deleted elements: got %s, want %s", got, want) + } +} + +func TestMapIterDelete0(t *testing.T) { + // Delete all elements before first iteration. + m := map[string]int{"one": 1, "two": 2, "three": 3} + iter := ValueOf(m).MapRange() + delete(m, "one") + delete(m, "two") + delete(m, "three") + if got, want := iterateToString(iter), `[]`; got != want { + t.Errorf("iterator returned deleted elements: got %s, want %s", got, want) + } +} + +func TestMapIterDelete1(t *testing.T) { + // Delete all elements after first iteration. + m := map[string]int{"one": 1, "two": 2, "three": 3} + iter := ValueOf(m).MapRange() + var got []string + for iter.Next() { + got = append(got, fmt.Sprint(iter.Key(), iter.Value())) + delete(m, "one") + delete(m, "two") + delete(m, "three") + } + if len(got) != 1 { + t.Errorf("iterator returned wrong number of elements: got %d, want 1", len(got)) + } +} + +// iterateToString returns the set of elements +// returned by an iterator in readable form. +func iterateToString(it *MapIter) string { + var got []string + for it.Next() { + line := fmt.Sprintf("%v: %v", it.Key(), it.Value()) + got = append(got, line) + } + sort.Strings(got) + return "[" + strings.Join(got, ", ") + "]" +} diff --git a/src/reflect/value.go b/src/reflect/value.go index 4e7b1d74db3dc..1c3e590377ff6 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -1085,14 +1085,7 @@ func (v Value) MapIndex(key Value) Value { typ := tt.elem fl := (v.flag | key.flag).ro() fl |= flag(typ.Kind()) - if !ifaceIndir(typ) { - return Value{typ, *(*unsafe.Pointer)(e), fl} - } - // Copy result so future changes to the map - // won't change the underlying value. - c := unsafe_New(typ) - typedmemmove(typ, c, e) - return Value{typ, c, fl | flagIndir} + return copyVal(typ, fl, e) } // MapKeys returns a slice containing all the keys present in the map, @@ -1122,20 +1115,96 @@ func (v Value) MapKeys() []Value { // we can do about it. break } - if ifaceIndir(keyType) { - // Copy result so future changes to the map - // won't change the underlying value. - c := unsafe_New(keyType) - typedmemmove(keyType, c, key) - a[i] = Value{keyType, c, fl | flagIndir} - } else { - a[i] = Value{keyType, *(*unsafe.Pointer)(key), fl} - } + a[i] = copyVal(keyType, fl, key) mapiternext(it) } return a[:i] } +// A MapIter is an iterator for ranging over a map. +// See Value.MapRange. +type MapIter struct { + m Value + it unsafe.Pointer +} + +// Key returns the key of the iterator's current map entry. +func (it *MapIter) Key() Value { + if it.it == nil { + panic("MapIter.Key called before Next") + } + if mapiterkey(it.it) == nil { + panic("MapIter.Key called on exhausted iterator") + } + + t := (*mapType)(unsafe.Pointer(it.m.typ)) + ktype := t.key + return copyVal(ktype, it.m.flag.ro()|flag(ktype.Kind()), mapiterkey(it.it)) +} + +// Value returns the value of the iterator's current map entry. +func (it *MapIter) Value() Value { + if it.it == nil { + panic("MapIter.Value called before Next") + } + if mapiterkey(it.it) == nil { + panic("MapIter.Value called on exhausted iterator") + } + + t := (*mapType)(unsafe.Pointer(it.m.typ)) + vtype := t.elem + return copyVal(vtype, it.m.flag.ro()|flag(vtype.Kind()), mapitervalue(it.it)) +} + +// Next advances the map iterator and reports whether there is another +// entry. It returns false when the iterator is exhausted; subsequent +// calls to Key, Value, or Next will panic. +func (it *MapIter) Next() bool { + if it.it == nil { + it.it = mapiterinit(it.m.typ, it.m.pointer()) + } else { + if mapiterkey(it.it) == nil { + panic("MapIter.Next called on exhausted iterator") + } + mapiternext(it.it) + } + return mapiterkey(it.it) != nil +} + +// MapRange returns a range iterator for a map. +// It panics if v's Kind is not Map. +// +// Call Next to advance the iterator, and Key/Value to access each entry. +// Next returns false when the iterator is exhausted. +// MapRange follows the same iteration semantics as a range statement. +// +// Example: +// +// iter := reflect.ValueOf(m).MapRange() +// for iter.Next() { +// k := iter.Key() +// v := iter.Value() +// ... +// } +// +func (v Value) MapRange() *MapIter { + v.mustBe(Map) + return &MapIter{m: v} +} + +// copyVal returns a Value containing the map key or value at ptr, +// allocating a new variable as needed. +func copyVal(typ *rtype, fl flag, ptr unsafe.Pointer) Value { + if ifaceIndir(typ) { + // Copy result so future changes to the map + // won't change the underlying value. + c := unsafe_New(typ) + typedmemmove(typ, c, ptr) + return Value{typ, c, fl | flagIndir} + } + return Value{typ, *(*unsafe.Pointer)(ptr), fl} +} + // Method returns a function value corresponding to v's i'th method. // The arguments to a Call on the returned function should not include // a receiver; the returned function will always use v as the receiver. @@ -2554,6 +2623,9 @@ func mapiterinit(t *rtype, m unsafe.Pointer) unsafe.Pointer //go:noescape func mapiterkey(it unsafe.Pointer) (key unsafe.Pointer) +//go:noescape +func mapitervalue(it unsafe.Pointer) (value unsafe.Pointer) + //go:noescape func mapiternext(it unsafe.Pointer) diff --git a/src/runtime/map.go b/src/runtime/map.go index 208c92cb0d75f..c03e745dc52ad 100644 --- a/src/runtime/map.go +++ b/src/runtime/map.go @@ -1282,6 +1282,11 @@ func reflect_mapiterkey(it *hiter) unsafe.Pointer { return it.key } +//go:linkname reflect_mapitervalue reflect.mapitervalue +func reflect_mapitervalue(it *hiter) unsafe.Pointer { + return it.value +} + //go:linkname reflect_maplen reflect.maplen func reflect_maplen(h *hmap) int { if h == nil { From 28fbf5b831e3c577c2e220daa82a85065047e356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Wed, 22 Aug 2018 22:34:39 +0200 Subject: [PATCH 0144/1663] runtime: skip TestGcSys on Windows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is causing failures on TryBots and BuildBots: --- FAIL: TestGcSys (0.06s) gc_test.go:27: expected "OK\n", but got "using too much memory: 39882752 bytes\n" FAIL Updates #27156 Change-Id: I418bbec89002574cd583c97422e433f042c07492 Reviewed-on: https://go-review.googlesource.com/130875 Run-TryBot: Martin Möhrmann Reviewed-by: Brad Fitzpatrick --- src/runtime/gc_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime/gc_test.go b/src/runtime/gc_test.go index 4895a0e2ac90b..0da19cdf340d9 100644 --- a/src/runtime/gc_test.go +++ b/src/runtime/gc_test.go @@ -21,6 +21,9 @@ func TestGcSys(t *testing.T) { if os.Getenv("GOGC") == "off" { t.Skip("skipping test; GOGC=off in environment") } + if runtime.GOOS == "windows" { + t.Skip("skipping test; GOOS=windows http://golang.org/issue/27156") + } got := runTestProg(t, "testprog", "GCSys") want := "OK\n" if got != want { From 3fd62ce91030f27c5cc28e49fb0101f5f658d3d0 Mon Sep 17 00:00:00 2001 From: Brian Kessler Date: Tue, 8 May 2018 00:07:13 -0600 Subject: [PATCH 0145/1663] math/big: optimize multiplication by 2 and 1/2 in float Sqrt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Sqrt code previously used explicit constants for 2 and 1/2. This change replaces multiplication by these constants with increment and decrement of the floating point exponent directly. This improves performance by ~7-10% for small inputs and minimal improvement for large inputs. name old time/op new time/op delta FloatSqrt/64-4 1.39µs ± 0% 1.29µs ± 3% -7.01% (p=0.016 n=4+5) FloatSqrt/128-4 2.84µs ± 0% 2.60µs ± 1% -8.33% (p=0.008 n=5+5) FloatSqrt/256-4 3.24µs ± 1% 2.91µs ± 2% -10.00% (p=0.008 n=5+5) FloatSqrt/1000-4 7.42µs ± 1% 6.74µs ± 0% -9.16% (p=0.008 n=5+5) FloatSqrt/10000-4 65.9µs ± 1% 65.3µs ± 4% ~ (p=0.310 n=5+5) FloatSqrt/100000-4 1.57ms ± 8% 1.52ms ± 1% ~ (p=0.111 n=5+4) FloatSqrt/1000000-4 127ms ± 1% 126ms ± 1% ~ (p=0.690 n=5+5) Change-Id: Id81ac842a9d64981e001c4ca3ff129eebd227593 Reviewed-on: https://go-review.googlesource.com/130835 Reviewed-by: Robert Griesemer --- src/math/big/sqrt.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/math/big/sqrt.go b/src/math/big/sqrt.go index b989649dcdee4..53403aa41d727 100644 --- a/src/math/big/sqrt.go +++ b/src/math/big/sqrt.go @@ -7,8 +7,6 @@ package big import "math" var ( - half = NewFloat(0.5) - two = NewFloat(2.0) three = NewFloat(3.0) ) @@ -57,9 +55,9 @@ func (z *Float) Sqrt(x *Float) *Float { case 0: // nothing to do case 1: - z.Mul(two, z) + z.exp++ case -1: - z.Mul(half, z) + z.exp-- } // 0.25 <= z < 2.0 @@ -96,7 +94,7 @@ func (z *Float) sqrtDirect(x *Float) { u.prec = t.prec u.Mul(t, t) // u = t² u.Add(u, x) // = t² + x - u.Mul(half, u) // = ½(t² + x) + u.exp-- // = ½(t² + x) return t.Quo(u, t) // = ½(t² + x)/t } @@ -133,11 +131,13 @@ func (z *Float) sqrtInverse(x *Float) { ng := func(t *Float) *Float { u.prec = t.prec v.prec = t.prec - u.Mul(t, t) // u = t² - u.Mul(x, u) // = xt² - v.Sub(three, u) // v = 3 - xt² - u.Mul(t, v) // u = t(3 - xt²) - return t.Mul(half, u) // = ½t(3 - xt²) + u.Mul(t, t) // u = t² + u.Mul(x, u) // = xt² + v.Sub(three, u) // v = 3 - xt² + u.Mul(t, v) // u = t(3 - xt²) + u.exp-- // = ½t(3 - xt²) + return t.Set(u) + } xf, _ := x.Float64() From d35135b9dab7415dc6eafd55597b497d013badb4 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 22 Aug 2018 20:31:37 +0000 Subject: [PATCH 0146/1663] internal/poll, net: fix sendfile on Windows, add test Fixes #27085 Change-Id: I4eb3ff7c76e0b8e4d8fe0298f739b0284d74a031 Reviewed-on: https://go-review.googlesource.com/130855 Reviewed-by: Ian Lance Taylor Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/internal/poll/sendfile_windows.go | 4 +- src/net/sendfile_test.go | 61 +++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/src/internal/poll/sendfile_windows.go b/src/internal/poll/sendfile_windows.go index 1a4d0ca191253..dc93e851d63a4 100644 --- a/src/internal/poll/sendfile_windows.go +++ b/src/internal/poll/sendfile_windows.go @@ -32,8 +32,8 @@ func SendFile(fd *FD, src syscall.Handle, n int64) (int64, error) { return 0, err } - o.o.OffsetHigh = uint32(curpos) - o.o.Offset = uint32(curpos >> 32) + o.o.Offset = uint32(curpos) + o.o.OffsetHigh = uint32(curpos >> 32) done, err := wsrv.ExecIO(o, func(o *operation) error { return syscall.TransmitFile(o.fd.Sysfd, o.handle, o.qty, 0, &o.o, nil, syscall.TF_WRITE_BEHIND) diff --git a/src/net/sendfile_test.go b/src/net/sendfile_test.go index ecc00d3c2a0ca..3b982774b02eb 100644 --- a/src/net/sendfile_test.go +++ b/src/net/sendfile_test.go @@ -149,3 +149,64 @@ func TestSendfileParts(t *testing.T) { t.Error(err) } } + +func TestSendfileSeeked(t *testing.T) { + ln, err := newLocalListener("tcp") + if err != nil { + t.Fatal(err) + } + defer ln.Close() + + const seekTo = 65 << 10 + const sendSize = 10 << 10 + + errc := make(chan error, 1) + go func(ln Listener) { + // Wait for a connection. + conn, err := ln.Accept() + if err != nil { + errc <- err + close(errc) + return + } + + go func() { + defer close(errc) + defer conn.Close() + + f, err := os.Open(twain) + if err != nil { + errc <- err + return + } + defer f.Close() + if _, err := f.Seek(seekTo, os.SEEK_SET); err != nil { + errc <- err + return + } + + _, err = io.CopyN(conn, f, sendSize) + if err != nil { + errc <- err + return + } + }() + }(ln) + + c, err := Dial("tcp", ln.Addr().String()) + if err != nil { + t.Fatal(err) + } + defer c.Close() + + buf := new(bytes.Buffer) + buf.ReadFrom(c) + + if buf.Len() != sendSize { + t.Errorf("Got %d bytes; want %d", buf.Len(), sendSize) + } + + for err := range errc { + t.Error(err) + } +} From e34f660a52b810e7f4d4a186c7502324c67390ea Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Tue, 24 Jul 2018 13:04:35 +0300 Subject: [PATCH 0147/1663] cmd/compile: cache the value of environment variable GOSSAFUNC Store the value of GOSSAFUNC in a global variable to avoid multiple calls to os.Getenv from gc.buildssa and gc.mkinlcall1. The latter is implemented in the CL 126606. Updates #25942 Change-Id: I58caaef2fee23694d80dc5a561a2e809bf077fa4 Reviewed-on: https://go-review.googlesource.com/126604 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/gc/main.go | 2 ++ src/cmd/compile/internal/gc/ssa.go | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 3fd89873d1749..5d074114ec0a5 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -427,6 +427,8 @@ func Main(archInit func(*Arch)) { Debug['l'] = 1 - Debug['l'] } + ssaDump = os.Getenv("GOSSAFUNC") + trackScopes = flagDWARF Widthptr = thearch.LinkArch.PtrSize diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 9f9fdc07f8d4f..cabcf17ed1cdc 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -23,6 +23,9 @@ import ( var ssaConfig *ssa.Config var ssaCaches []ssa.Cache +var ssaDump string // early copy of $GOSSAFUNC; the func name to dump output for +const ssaDumpFile = "ssa.html" + func initssaconfig() { types_ := ssa.NewTypes() @@ -103,7 +106,7 @@ func initssaconfig() { // worker indicates which of the backend workers is doing the processing. func buildssa(fn *Node, worker int) *ssa.Func { name := fn.funcname() - printssa := name == os.Getenv("GOSSAFUNC") + printssa := name == ssaDump if printssa { fmt.Println("generating SSA for", name) dumplist("buildssa-enter", fn.Func.Enter) @@ -141,7 +144,7 @@ func buildssa(fn *Node, worker int) *ssa.Func { s.softFloat = s.config.SoftFloat if printssa { - s.f.HTMLWriter = ssa.NewHTMLWriter("ssa.html", s.f.Frontend(), name) + s.f.HTMLWriter = ssa.NewHTMLWriter(ssaDumpFile, s.f.Frontend(), name) // TODO: generate and print a mapping from nodes to values and blocks // Read sources for a function fn and format into a column. From 34c58fe184fa73ecff0e7142fcf567b1a9abc01b Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Mon, 28 May 2018 13:20:45 +0300 Subject: [PATCH 0148/1663] cmd/compile: use embedlineno instead of lineno in copytype Also remove lineno from typecheckdeftype since copytype was the only user of it and typecheck uses lineno independently. toolstach-check passed. Updates #19683. Change-Id: I1663fdb8cf519d505cc087c8657dcbff3c8b1a0a Reviewed-on: https://go-review.googlesource.com/114875 Run-TryBot: Yury Smolsky Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/gc/typecheck.go | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 51dd0dba87fcb..370f21befbdb6 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -3608,21 +3608,14 @@ func copytype(n *Node, t *types.Type) { } // Double-check use of type as embedded type. - lno := lineno - if embedlineno.IsKnown() { - lineno = embedlineno if t.IsPtr() || t.IsUnsafePtr() { - yyerror("embedded type cannot be a pointer") + yyerrorl(embedlineno, "embedded type cannot be a pointer") } } - - lineno = lno } func typecheckdeftype(n *Node) { - lno := lineno - setlineno(n) n.Type.Sym = n.Sym n.SetTypecheck(1) n.Name.Param.Ntype = typecheck(n.Name.Param.Ntype, Etype) @@ -3637,8 +3630,6 @@ func typecheckdeftype(n *Node) { // that don't come along. copytype(n, t) } - - lineno = lno } func typecheckdef(n *Node) { From 773e89464560833711c2554420d1a1550e0e8ff3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Sun, 19 Aug 2018 07:50:39 +0200 Subject: [PATCH 0149/1663] fmt: print values for map keys with non-reflexive equality Previously fmt would first obtain a list of map keys and then look up the value for each key. Since NaNs can be map keys but cannot be fetched directly, the lookup would fail and return a zero reflect.Value, which formats as . golang.org/cl/33572 added a map iterator to the reflect package that is used in this CL to retrieve the key and value from the map and prints the correct value even for keys that are not equal to themselves. Fixes #14427 Change-Id: I9e1522959760b3de8b7ecf7a6e67cd603339632a Reviewed-on: https://go-review.googlesource.com/129777 Reviewed-by: Alan Donovan --- src/fmt/fmt_test.go | 11 +++-------- src/fmt/print.go | 8 ++++---- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go index 08e46b4e93542..edfd1ee824fd4 100644 --- a/src/fmt/fmt_test.go +++ b/src/fmt/fmt_test.go @@ -861,13 +861,8 @@ var fmtTests = []struct { // Extra argument errors should format without flags set. {"%010.2", "12345", "%!(NOVERB)%!(EXTRA string=12345)"}, - // The "" show up because maps are printed by - // first obtaining a list of keys and then looking up - // each key. Since NaNs can be map keys but cannot - // be fetched directly, the lookup fails and returns a - // zero reflect.Value, which formats as . - // This test is just to check that it shows the two NaNs at all. - {"%v", map[float64]int{NaN: 1, NaN: 2}, "map[NaN: NaN:]"}, + // Test that maps with non-reflexive keys print all keys and values. + {"%v", map[float64]int{NaN: 1, NaN: 1}, "map[NaN:1 NaN:1]"}, // Comparison of padding rules with C printf. /* @@ -1033,7 +1028,7 @@ var fmtTests = []struct { {"%☠", &[]interface{}{I(1), G(2)}, "&[%!☠(fmt_test.I=1) %!☠(fmt_test.G=2)]"}, {"%☠", SI{&[]interface{}{I(1), G(2)}}, "{%!☠(*[]interface {}=&[1 2])}"}, {"%☠", reflect.Value{}, ""}, - {"%☠", map[float64]int{NaN: 1}, "map[%!☠(float64=NaN):%!☠()]"}, + {"%☠", map[float64]int{NaN: 1}, "map[%!☠(float64=NaN):%!☠(int=1)]"}, } // zeroFill generates zero-filled strings of the specified width. The length diff --git a/src/fmt/print.go b/src/fmt/print.go index f67f80560371a..c9d694b07dc88 100644 --- a/src/fmt/print.go +++ b/src/fmt/print.go @@ -743,8 +743,8 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) { } else { p.buf.WriteString(mapString) } - keys := f.MapKeys() - for i, key := range keys { + iter := f.MapRange() + for i := 0; iter.Next(); i++ { if i > 0 { if p.fmt.sharpV { p.buf.WriteString(commaSpaceString) @@ -752,9 +752,9 @@ func (p *pp) printValue(value reflect.Value, verb rune, depth int) { p.buf.WriteByte(' ') } } - p.printValue(key, verb, depth+1) + p.printValue(iter.Key(), verb, depth+1) p.buf.WriteByte(':') - p.printValue(f.MapIndex(key), verb, depth+1) + p.printValue(iter.Value(), verb, depth+1) } if p.fmt.sharpV { p.buf.WriteByte('}') From 37ea182660e31f4e21b2bc34d2438455269e5f78 Mon Sep 17 00:00:00 2001 From: Zachary Amsden Date: Tue, 31 Jul 2018 11:24:37 -0700 Subject: [PATCH 0150/1663] runtime: catch concurrent stacks more often If two goroutines are racing on a map, one of them will exit cleanly, clearing the hashWriting bit, and the other will likely notice and panic. If we use XOR instead of OR to set the bit in the first place, even numbers of racers will hopefully all see the bit cleared and panic simultaneously, giving the full set of available stacks. If a third racer sneaks in, we are no worse than the current code, and the generated code should be no more expensive. In practice, this catches most racing goroutines even in very tight races. See the demonstration program posted on https://github.com/golang/go/issues/26703 for an example. Fixes #26703 Change-Id: Idad17841a3127c24bd0a659b754734f70e307434 Reviewed-on: https://go-review.googlesource.com/126936 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Keith Randall --- src/runtime/map.go | 6 +++--- src/runtime/map_fast32.go | 6 +++--- src/runtime/map_fast64.go | 6 +++--- src/runtime/map_faststr.go | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/runtime/map.go b/src/runtime/map.go index c03e745dc52ad..c3fcfbfdbe405 100644 --- a/src/runtime/map.go +++ b/src/runtime/map.go @@ -567,7 +567,7 @@ func mapassign(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer { // Set hashWriting after calling alg.hash, since alg.hash may panic, // in which case we have not actually done a write. - h.flags |= hashWriting + h.flags ^= hashWriting if h.buckets == nil { h.buckets = newobject(t.bucket) // newarray(t.bucket, 1) @@ -679,7 +679,7 @@ func mapdelete(t *maptype, h *hmap, key unsafe.Pointer) { // Set hashWriting after calling alg.hash, since alg.hash may panic, // in which case we have not actually done a write (delete). - h.flags |= hashWriting + h.flags ^= hashWriting bucket := hash & bucketMask(h.B) if h.growing() { @@ -921,7 +921,7 @@ func mapclear(t *maptype, h *hmap) { throw("concurrent map writes") } - h.flags |= hashWriting + h.flags ^= hashWriting h.flags &^= sameSizeGrow h.oldbuckets = nil diff --git a/src/runtime/map_fast32.go b/src/runtime/map_fast32.go index bf0b23604bb0c..671558545a2ba 100644 --- a/src/runtime/map_fast32.go +++ b/src/runtime/map_fast32.go @@ -103,7 +103,7 @@ func mapassign_fast32(t *maptype, h *hmap, key uint32) unsafe.Pointer { hash := t.key.alg.hash(noescape(unsafe.Pointer(&key)), uintptr(h.hash0)) // Set hashWriting after calling alg.hash for consistency with mapassign. - h.flags |= hashWriting + h.flags ^= hashWriting if h.buckets == nil { h.buckets = newobject(t.bucket) // newarray(t.bucket, 1) @@ -189,7 +189,7 @@ func mapassign_fast32ptr(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer hash := t.key.alg.hash(noescape(unsafe.Pointer(&key)), uintptr(h.hash0)) // Set hashWriting after calling alg.hash for consistency with mapassign. - h.flags |= hashWriting + h.flags ^= hashWriting if h.buckets == nil { h.buckets = newobject(t.bucket) // newarray(t.bucket, 1) @@ -276,7 +276,7 @@ func mapdelete_fast32(t *maptype, h *hmap, key uint32) { hash := t.key.alg.hash(noescape(unsafe.Pointer(&key)), uintptr(h.hash0)) // Set hashWriting after calling alg.hash for consistency with mapdelete - h.flags |= hashWriting + h.flags ^= hashWriting bucket := hash & bucketMask(h.B) if h.growing() { diff --git a/src/runtime/map_fast64.go b/src/runtime/map_fast64.go index 4bde9e2be0726..164a4dd1cef71 100644 --- a/src/runtime/map_fast64.go +++ b/src/runtime/map_fast64.go @@ -103,7 +103,7 @@ func mapassign_fast64(t *maptype, h *hmap, key uint64) unsafe.Pointer { hash := t.key.alg.hash(noescape(unsafe.Pointer(&key)), uintptr(h.hash0)) // Set hashWriting after calling alg.hash for consistency with mapassign. - h.flags |= hashWriting + h.flags ^= hashWriting if h.buckets == nil { h.buckets = newobject(t.bucket) // newarray(t.bucket, 1) @@ -189,7 +189,7 @@ func mapassign_fast64ptr(t *maptype, h *hmap, key unsafe.Pointer) unsafe.Pointer hash := t.key.alg.hash(noescape(unsafe.Pointer(&key)), uintptr(h.hash0)) // Set hashWriting after calling alg.hash for consistency with mapassign. - h.flags |= hashWriting + h.flags ^= hashWriting if h.buckets == nil { h.buckets = newobject(t.bucket) // newarray(t.bucket, 1) @@ -276,7 +276,7 @@ func mapdelete_fast64(t *maptype, h *hmap, key uint64) { hash := t.key.alg.hash(noescape(unsafe.Pointer(&key)), uintptr(h.hash0)) // Set hashWriting after calling alg.hash for consistency with mapdelete - h.flags |= hashWriting + h.flags ^= hashWriting bucket := hash & bucketMask(h.B) if h.growing() { diff --git a/src/runtime/map_faststr.go b/src/runtime/map_faststr.go index 415bbff143ff5..bee62dfb03b98 100644 --- a/src/runtime/map_faststr.go +++ b/src/runtime/map_faststr.go @@ -202,7 +202,7 @@ func mapassign_faststr(t *maptype, h *hmap, s string) unsafe.Pointer { hash := t.key.alg.hash(noescape(unsafe.Pointer(&s)), uintptr(h.hash0)) // Set hashWriting after calling alg.hash for consistency with mapassign. - h.flags |= hashWriting + h.flags ^= hashWriting if h.buckets == nil { h.buckets = newobject(t.bucket) // newarray(t.bucket, 1) @@ -294,7 +294,7 @@ func mapdelete_faststr(t *maptype, h *hmap, ky string) { hash := t.key.alg.hash(noescape(unsafe.Pointer(&ky)), uintptr(h.hash0)) // Set hashWriting after calling alg.hash for consistency with mapdelete - h.flags |= hashWriting + h.flags ^= hashWriting bucket := hash & bucketMask(h.B) if h.growing() { From ccb70bd19c44b90ef4030c6399c884f82a12bc68 Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Thu, 23 Aug 2018 00:02:24 +0200 Subject: [PATCH 0151/1663] context: don't talk about tools that don't exist This comment has been the source of much confusion and broken dreams. We can add it back if a tool ever gets released. Updates #16742 Change-Id: I4b9c179b7c60274e6ff1bcb607b82029dd9a893f Reviewed-on: https://go-review.googlesource.com/130876 Reviewed-by: Matt Layher Reviewed-by: Alan Donovan Reviewed-by: Brad Fitzpatrick --- src/context/context.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/context/context.go b/src/context/context.go index 1b4fa41b8cc32..85f8acf8fa06d 100644 --- a/src/context/context.go +++ b/src/context/context.go @@ -210,8 +210,7 @@ func Background() Context { // TODO returns a non-nil, empty Context. Code should use context.TODO when // it's unclear which Context to use or it is not yet available (because the // surrounding function has not yet been extended to accept a Context -// parameter). TODO is recognized by static analysis tools that determine -// whether Contexts are propagated correctly in a program. +// parameter). func TODO() Context { return todo } From be10ad762289943638efb279fc7e04c73b8d7cee Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Tue, 21 Aug 2018 22:58:08 -0700 Subject: [PATCH 0152/1663] internal/poll: use F_FULLFSYNC fcntl for FD.Fsync on OS X As reported in #26650 and also cautioned on the man page for fsync on OS X, fsync doesn't properly flush content to permanent storage, and might cause corruption of data if the OS crashes or if the drive loses power. Thus it is recommended to use the F_FULLFSYNC fcntl, which flushes all buffered data to permanent storage and is important for applications such as databases that require a strict ordering of writes. Also added a note in syscall_darwin.go that syscall.Fsync is not invoked for os.File.Sync. Fixes #26650. Change-Id: Idecd9adbbdd640b9c5b02e73b60ed254c98b48b6 Reviewed-on: https://go-review.googlesource.com/130676 Run-TryBot: Emmanuel Odeke Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/internal/poll/fd_fsync_darwin.go | 23 +++++++++++++++++++++++ src/internal/poll/fd_fsync_posix.go | 18 ++++++++++++++++++ src/internal/poll/fd_posix.go | 9 --------- src/syscall/syscall_darwin.go | 1 + 4 files changed, 42 insertions(+), 9 deletions(-) create mode 100644 src/internal/poll/fd_fsync_darwin.go create mode 100644 src/internal/poll/fd_fsync_posix.go diff --git a/src/internal/poll/fd_fsync_darwin.go b/src/internal/poll/fd_fsync_darwin.go new file mode 100644 index 0000000000000..23835f6e60aa9 --- /dev/null +++ b/src/internal/poll/fd_fsync_darwin.go @@ -0,0 +1,23 @@ +// Copyright 2018 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. + +package poll + +import "syscall" + +// Fsync invokes SYS_FCNTL with SYS_FULLFSYNC because +// on OS X, SYS_FSYNC doesn't fully flush contents to disk. +// See Issue #26650 as well as the man page for fsync on OS X. +func (fd *FD) Fsync() error { + if err := fd.incref(); err != nil { + return err + } + defer fd.decref() + + _, _, e1 := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fd.Sysfd), syscall.F_FULLFSYNC, 0) + if e1 != 0 { + return e1 + } + return nil +} diff --git a/src/internal/poll/fd_fsync_posix.go b/src/internal/poll/fd_fsync_posix.go new file mode 100644 index 0000000000000..943f59a9ab61d --- /dev/null +++ b/src/internal/poll/fd_fsync_posix.go @@ -0,0 +1,18 @@ +// Copyright 2018 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. + +// +build dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris windows + +package poll + +import "syscall" + +// Fsync wraps syscall.Fsync. +func (fd *FD) Fsync() error { + if err := fd.incref(); err != nil { + return err + } + defer fd.decref() + return syscall.Fsync(fd.Sysfd) +} diff --git a/src/internal/poll/fd_posix.go b/src/internal/poll/fd_posix.go index f178a6fa0ae1b..f899a74876d37 100644 --- a/src/internal/poll/fd_posix.go +++ b/src/internal/poll/fd_posix.go @@ -46,12 +46,3 @@ func (fd *FD) Ftruncate(size int64) error { defer fd.decref() return syscall.Ftruncate(fd.Sysfd, size) } - -// Fsync wraps syscall.Fsync. -func (fd *FD) Fsync() error { - if err := fd.incref(); err != nil { - return err - } - defer fd.decref() - return syscall.Fsync(fd.Sysfd) -} diff --git a/src/syscall/syscall_darwin.go b/src/syscall/syscall_darwin.go index 4d6aa4fcf23e4..98084a521cac0 100644 --- a/src/syscall/syscall_darwin.go +++ b/src/syscall/syscall_darwin.go @@ -252,6 +252,7 @@ func Kill(pid int, signum Signal) (err error) { return kill(pid, int(signum), 1) //sys Fstat(fd int, stat *Stat_t) (err error) = SYS_FSTAT64 //sys Fstatfs(fd int, stat *Statfs_t) (err error) = SYS_FSTATFS64 //sys Fsync(fd int) (err error) +// Fsync is not called for os.File.Sync(). Please see internal/poll/fd_fsync_darwin.go //sys Ftruncate(fd int, length int64) (err error) //sys Getdirentries(fd int, buf []byte, basep *uintptr) (n int, err error) = SYS_GETDIRENTRIES64 //sys Getdtablesize() (size int) From 6ebc31f9fb0ade22c605c146f651f18f9fc0b61d Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 12 Feb 2018 11:22:00 -0800 Subject: [PATCH 0153/1663] runtime: remove unused function casp Change-Id: I7c9c83ba236e1050e04377a7591fef7174df698b Reviewed-on: https://go-review.googlesource.com/130415 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/runtime/atomic_pointer.go | 13 ------------- src/runtime/proc.go | 2 +- src/runtime/runtime1.go | 17 +---------------- 3 files changed, 2 insertions(+), 30 deletions(-) diff --git a/src/runtime/atomic_pointer.go b/src/runtime/atomic_pointer.go index 09cfbda9b1cf2..b8f0c22c63966 100644 --- a/src/runtime/atomic_pointer.go +++ b/src/runtime/atomic_pointer.go @@ -13,8 +13,6 @@ import ( // because while ptr does not escape, new does. // If new is marked as not escaping, the compiler will make incorrect // escape analysis decisions about the pointer value being stored. -// Instead, these are wrappers around the actual atomics (casp1 and so on) -// that use noescape to convey which arguments do not escape. // atomicwb performs a write barrier before an atomic pointer write. // The caller should guard the call with "if writeBarrier.enabled". @@ -37,17 +35,6 @@ func atomicstorep(ptr unsafe.Pointer, new unsafe.Pointer) { atomic.StorepNoWB(noescape(ptr), new) } -//go:nosplit -func casp(ptr *unsafe.Pointer, old, new unsafe.Pointer) bool { - // The write barrier is only necessary if the CAS succeeds, - // but since it needs to happen before the write becomes - // public, we have to do it conservatively all the time. - if writeBarrier.enabled { - atomicwb(ptr, new) - } - return atomic.Casp1((*unsafe.Pointer)(noescape(unsafe.Pointer(ptr))), noescape(old), new) -} - // Like above, but implement in terms of sync/atomic's uintptr operations. // We cannot just call the runtime routines, because the race detector expects // to be able to intercept the sync/atomic forms but not the runtime forms. diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 32467715c44d9..c9cc7544b8297 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -1599,7 +1599,7 @@ func allocm(_p_ *p, fn func()) *m { // the following strategy: there is a stack of available m's // that can be stolen. Using compare-and-swap // to pop from the stack has ABA races, so we simulate -// a lock by doing an exchange (via casp) to steal the stack +// a lock by doing an exchange (via Casuintptr) to steal the stack // head and replace the top pointer with MLOCKED (1). // This serves as a simple spin lock that we can use even // without an m. The thread that locks the stack in this way diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go index a0769bbb67c4f..d5f78badedad6 100644 --- a/src/runtime/runtime1.go +++ b/src/runtime/runtime1.go @@ -145,7 +145,7 @@ func check() { h uint64 i, i1 float32 j, j1 float64 - k, k1 unsafe.Pointer + k unsafe.Pointer l *uint16 m [4]byte ) @@ -234,21 +234,6 @@ func check() { throw("cas6") } - k = unsafe.Pointer(uintptr(0xfedcb123)) - if sys.PtrSize == 8 { - k = unsafe.Pointer(uintptr(k) << 10) - } - if casp(&k, nil, nil) { - throw("casp1") - } - k1 = add(k, 1) - if !casp(&k, k, k1) { - throw("casp2") - } - if k != k1 { - throw("casp3") - } - m = [4]byte{1, 1, 1, 1} atomic.Or8(&m[1], 0xf0) if m[0] != 1 || m[1] != 0xf1 || m[2] != 1 || m[3] != 1 { From ca8ba0675a5a73b4e0ad8ba1c50e244b793934ee Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Tue, 10 Jul 2018 09:27:39 +0300 Subject: [PATCH 0154/1663] cmd/link/internal/sym: uncomment code for ELF cases in RelocName When this code was introduced, there were no R_MIPS, R_PPC64 and R_390 and build would fail with this code uncommented. Now we have those. Change-Id: I18a54eaa250db12e293f8e4d1f080f1dd2e66a4f Reviewed-on: https://go-review.googlesource.com/122896 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/link/internal/sym/reloc.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/link/internal/sym/reloc.go b/src/cmd/link/internal/sym/reloc.go index fc62c385f4025..da696d327b326 100644 --- a/src/cmd/link/internal/sym/reloc.go +++ b/src/cmd/link/internal/sym/reloc.go @@ -83,11 +83,11 @@ func RelocName(arch *sys.Arch, r objabi.RelocType) string { case sys.I386: return elf.R_386(nr).String() case sys.MIPS, sys.MIPS64: - // return elf.R_MIPS(nr).String() + return elf.R_MIPS(nr).String() case sys.PPC64: - // return elf.R_PPC64(nr).String() + return elf.R_PPC64(nr).String() case sys.S390X: - // return elf.R_390(nr).String() + return elf.R_390(nr).String() default: panic("unreachable") } From 48462bb3c04f34c93689c047d4bc5319bc79b31b Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Wed, 11 Jul 2018 23:36:55 +0300 Subject: [PATCH 0155/1663] html/template: use named consts instead of their values Use defined named constants instead of 0 literal in comparisons. Found using https://go-critic.github.io/overview.html#namedConst-ref Change-Id: Ic075cece248f6e51db0b3d9d9eaba7d6409c9eef Reviewed-on: https://go-review.googlesource.com/123376 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/html/template/context.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/html/template/context.go b/src/html/template/context.go index 45be3a6a9f94d..7ab3d1fed674c 100644 --- a/src/html/template/context.go +++ b/src/html/template/context.go @@ -48,19 +48,19 @@ func (c context) mangle(templateName string) string { return templateName } s := templateName + "$htmltemplate_" + c.state.String() - if c.delim != 0 { + if c.delim != delimNone { s += "_" + c.delim.String() } - if c.urlPart != 0 { + if c.urlPart != urlPartNone { s += "_" + c.urlPart.String() } - if c.jsCtx != 0 { + if c.jsCtx != jsCtxRegexp { s += "_" + c.jsCtx.String() } - if c.attr != 0 { + if c.attr != attrNone { s += "_" + c.attr.String() } - if c.element != 0 { + if c.element != elementNone { s += "_" + c.element.String() } return s From a3381faf81e5e9ec0b207d74f29f6c442b2abb73 Mon Sep 17 00:00:00 2001 From: Brian Kessler Date: Mon, 18 Sep 2017 22:02:55 -0700 Subject: [PATCH 0156/1663] math/big: streamline divLarge initialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The divLarge code contained "todo"s about avoiding alias and clear calls in the initialization of variables. By rearranging the order of initialization and always using an auxiliary variable for the shifted divisor, all of these calls can be safely avoided. On average, normalizing the divisor (shift>0) is required 31/32 or 63/64 of the time. If one always performs the shift into an auxiliary variable first, this avoids the need to check for aliasing of vIn in the output variables u and z. The remainder u is initialized via a left shift of uIn and thus needs no alias check against uIn. Since uIn and vIn were both used, z needs no alias checks except against u which is used for storage of the remainder. This change has a minimal impact on performance (see below), but cleans up the initialization code and eliminates the "todo"s. name old time/op new time/op delta Div/20/10-4 86.7ns ± 6% 85.7ns ± 5% ~ (p=0.841 n=5+5) Div/200/100-4 523ns ± 5% 502ns ± 3% -4.13% (p=0.024 n=5+5) Div/2000/1000-4 2.55µs ± 3% 2.59µs ± 5% ~ (p=0.548 n=5+5) Div/20000/10000-4 80.4µs ± 4% 80.0µs ± 2% ~ (p=1.000 n=5+5) Div/200000/100000-4 6.43ms ± 6% 6.35ms ± 4% ~ (p=0.548 n=5+5) Fixes #22928 Change-Id: I30d8498ef1cf8b69b0f827165c517bc25a5c32d7 Reviewed-on: https://go-review.googlesource.com/130775 Reviewed-by: Robert Griesemer --- src/math/big/int_test.go | 26 ++++++++++++++++++++ src/math/big/nat.go | 52 +++++++++++++++++----------------------- 2 files changed, 48 insertions(+), 30 deletions(-) diff --git a/src/math/big/int_test.go b/src/math/big/int_test.go index 9930ed016af13..7ef2b3907f75a 100644 --- a/src/math/big/int_test.go +++ b/src/math/big/int_test.go @@ -1727,3 +1727,29 @@ func BenchmarkIntSqr(b *testing.B) { }) } } + +func benchmarkDiv(b *testing.B, aSize, bSize int) { + var r = rand.New(rand.NewSource(1234)) + aa := randInt(r, uint(aSize)) + bb := randInt(r, uint(bSize)) + if aa.Cmp(bb) < 0 { + aa, bb = bb, aa + } + x := new(Int) + y := new(Int) + + b.ResetTimer() + for i := 0; i < b.N; i++ { + x.DivMod(aa, bb, y) + } +} + +func BenchmarkDiv(b *testing.B) { + min, max, step := 10, 100000, 10 + for i := min; i <= max; i *= step { + j := 2 * i + b.Run(fmt.Sprintf("%d/%d", j, i), func(b *testing.B) { + benchmarkDiv(b, j, i) + }) + } +} diff --git a/src/math/big/nat.go b/src/math/big/nat.go index a6f79edccc439..5f5cf5c3e4f52 100644 --- a/src/math/big/nat.go +++ b/src/math/big/nat.go @@ -680,43 +680,36 @@ func putNat(x *nat) { var natPool sync.Pool -// q = (uIn-r)/v, with 0 <= r < y +// q = (uIn-r)/vIn, with 0 <= r < y // Uses z as storage for q, and u as storage for r if possible. // See Knuth, Volume 2, section 4.3.1, Algorithm D. // Preconditions: -// len(v) >= 2 -// len(uIn) >= len(v) -func (z nat) divLarge(u, uIn, v nat) (q, r nat) { - n := len(v) +// len(vIn) >= 2 +// len(uIn) >= len(vIn) +// u must not alias z +func (z nat) divLarge(u, uIn, vIn nat) (q, r nat) { + n := len(vIn) m := len(uIn) - n - // determine if z can be reused - // TODO(gri) should find a better solution - this if statement - // is very costly (see e.g. time pidigits -s -n 10000) - if alias(z, u) || alias(z, uIn) || alias(z, v) { - z = nil // z is an alias for u or uIn or v - cannot reuse + // D1. + shift := nlz(vIn[n-1]) + // do not modify vIn, it may be used by another goroutine simultaneously + vp := getNat(n) + v := *vp + shlVU(v, vIn, shift) + + // u may safely alias uIn or vIn, the value of uIn is used to set u and vIn was already used + u = u.make(len(uIn) + 1) + u[len(uIn)] = shlVU(u[0:len(uIn)], uIn, shift) + + // z may safely alias uIn or vIn, both values were used already + if alias(z, u) { + z = nil // z is an alias for u - cannot reuse } q = z.make(m + 1) qhatvp := getNat(n + 1) qhatv := *qhatvp - if alias(u, uIn) || alias(u, v) { - u = nil // u is an alias for uIn or v - cannot reuse - } - u = u.make(len(uIn) + 1) - u.clear() // TODO(gri) no need to clear if we allocated a new u - - // D1. - var v1p *nat - shift := nlz(v[n-1]) - if shift > 0 { - // do not modify v, it may be used by another goroutine simultaneously - v1p = getNat(n) - v1 := *v1p - shlVU(v1, v, shift) - v = v1 - } - u[len(uIn)] = shlVU(u[0:len(uIn)], uIn, shift) // D2. vn1 := v[n-1] @@ -756,9 +749,8 @@ func (z nat) divLarge(u, uIn, v nat) (q, r nat) { q[j] = qhat } - if v1p != nil { - putNat(v1p) - } + + putNat(vp) putNat(qhatvp) q = q.norm() From eeb8aebed6d158ad55cea346fdd659f6d6112de5 Mon Sep 17 00:00:00 2001 From: Oryan Moshe Date: Fri, 3 Aug 2018 14:52:39 +0300 Subject: [PATCH 0157/1663] cmd/cgo: pass explicit -O0 to the compiler The current implementation removes all of the optimization flags from the compiler. Added the -O0 optimization flag after the removal loop, so go can compile cgo on every OS consistently. Fixes #26487 Change-Id: Ia98bca90def186dfe10f50b1787c2f40d85533da Reviewed-on: https://go-review.googlesource.com/127755 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/cgo/gcc.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index 20e794b4bea79..019ee64c8e020 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -1693,6 +1693,9 @@ func (p *Package) gccErrors(stdin []byte) string { } } + // Force -O0 optimization + nargs = append(nargs, "-O0") + if *debugGcc { fmt.Fprintf(os.Stderr, "$ %s < Date: Tue, 24 Jul 2018 10:39:00 +0300 Subject: [PATCH 0158/1663] cmd/compile: clean the output of GOSSAFUNC Since we print almost everything to ssa.html in the GOSSAFUNC mode, there is a need to stop spamming stdout when user just wants to see ssa.html. This changes cleans output of the GOSSAFUNC debug mode. To enable the dump of the debug data to stdout, one must put suffix + after the function name like that: GOSSAFUNC=Foo+ Otherwise gc will not print the IR and ASM to stdout after each phase. AST IR is still sent to stdout because it is not included into ssa.html. It will be fixed in a separate change. The change adds printing out the full path to the ssa.html file. Updates #25942 Change-Id: I711e145e05f0443c7df5459ca528dced273a62ee Reviewed-on: https://go-review.googlesource.com/126603 Run-TryBot: Yury Smolsky TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/main.go | 4 ++ src/cmd/compile/internal/gc/ssa.go | 70 ++++++++++++------------- src/cmd/compile/internal/ssa/compile.go | 10 ++-- src/cmd/compile/internal/ssa/html.go | 11 +++- 4 files changed, 53 insertions(+), 42 deletions(-) diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 5d074114ec0a5..44cf75e7c989a 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -428,6 +428,10 @@ func Main(archInit func(*Arch)) { } ssaDump = os.Getenv("GOSSAFUNC") + if strings.HasSuffix(ssaDump, "+") { + ssaDump = ssaDump[:len(ssaDump)-1] + ssaDumpStdout = true + } trackScopes = flagDWARF diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index cabcf17ed1cdc..2abd9448d4ee2 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -23,7 +23,8 @@ import ( var ssaConfig *ssa.Config var ssaCaches []ssa.Cache -var ssaDump string // early copy of $GOSSAFUNC; the func name to dump output for +var ssaDump string // early copy of $GOSSAFUNC; the func name to dump output for +var ssaDumpStdout bool // whether to dump to stdout const ssaDumpFile = "ssa.html" func initssaconfig() { @@ -125,7 +126,7 @@ func buildssa(fn *Node, worker int) *ssa.Func { fe := ssafn{ curfn: fn, - log: printssa, + log: printssa && ssaDumpStdout, } s.curfn = fn @@ -4873,7 +4874,8 @@ func genssa(f *ssa.Func, pp *Progs) { var progToBlock map[*obj.Prog]*ssa.Block var valueToProgAfter []*obj.Prog // The first Prog following computation of a value v; v is visible at this point. var logProgs = e.log - if logProgs { + if f.HTMLWriter != nil { + // logProgs can be false, meaning that we do not dump to the Stdout. progToValue = make(map[*obj.Prog]*ssa.Value, f.NumValues()) progToBlock = make(map[*obj.Prog]*ssa.Block, f.NumBlocks()) f.Logf("genssa %s\n", f.Name) @@ -5042,42 +5044,36 @@ func genssa(f *ssa.Func, pp *Progs) { } f.Logf(" %-6s\t%.5d (%s)\t%s\n", s, p.Pc, p.InnermostLineNumber(), p.InstructionString()) } - if f.HTMLWriter != nil { - // LineHist is defunct now - this code won't do - // anything. - // TODO: fix this (ideally without a global variable) - // saved := pp.Text.Ctxt.LineHist.PrintFilenameOnly - // pp.Text.Ctxt.LineHist.PrintFilenameOnly = true - var buf bytes.Buffer - buf.WriteString("") - buf.WriteString("
    ") - filename := "" - for p := pp.Text; p != nil; p = p.Link { - // Don't spam every line with the file name, which is often huge. - // Only print changes, and "unknown" is not a change. - if p.Pos.IsKnown() && p.InnermostFilename() != filename { - filename = p.InnermostFilename() - buf.WriteString("
    ") - buf.WriteString(html.EscapeString("# " + filename)) - buf.WriteString("
    ") - } - - buf.WriteString("
    ") - if v, ok := progToValue[p]; ok { - buf.WriteString(v.HTML()) - } else if b, ok := progToBlock[p]; ok { - buf.WriteString("" + b.HTML() + "") - } - buf.WriteString("
    ") - buf.WriteString("
    ") - buf.WriteString(fmt.Sprintf("%.5d (%s) %s", p.Pc, p.InnermostLineNumber(), p.InnermostLineNumberHTML(), html.EscapeString(p.InstructionString()))) + } + if f.HTMLWriter != nil { + var buf bytes.Buffer + buf.WriteString("") + buf.WriteString("
    ") + filename := "" + for p := pp.Text; p != nil; p = p.Link { + // Don't spam every line with the file name, which is often huge. + // Only print changes, and "unknown" is not a change. + if p.Pos.IsKnown() && p.InnermostFilename() != filename { + filename = p.InnermostFilename() + buf.WriteString("
    ") + buf.WriteString(html.EscapeString("# " + filename)) buf.WriteString("
    ") } - buf.WriteString("
    ") - buf.WriteString("
    ") - f.HTMLWriter.WriteColumn("genssa", "genssa", "ssa-prog", buf.String()) - // pp.Text.Ctxt.LineHist.PrintFilenameOnly = saved + + buf.WriteString("
    ") + if v, ok := progToValue[p]; ok { + buf.WriteString(v.HTML()) + } else if b, ok := progToBlock[p]; ok { + buf.WriteString("" + b.HTML() + "") + } + buf.WriteString("
    ") + buf.WriteString("
    ") + buf.WriteString(fmt.Sprintf("%.5d (%s) %s", p.Pc, p.InnermostLineNumber(), p.InnermostLineNumberHTML(), html.EscapeString(p.InstructionString()))) + buf.WriteString("
    ") } + buf.WriteString("
    ") + buf.WriteString("
    ") + f.HTMLWriter.WriteColumn("genssa", "genssa", "ssa-prog", buf.String()) } defframe(&s, e) @@ -5435,7 +5431,7 @@ type ssafn struct { scratchFpMem *Node // temp for floating point register / memory moves on some architectures stksize int64 // stack size for current frame stkptrsize int64 // prefix of stack containing pointers - log bool + log bool // print ssa debug to the stdout } // StringData returns a symbol (a *types.Sym wrapped in an interface) which diff --git a/src/cmd/compile/internal/ssa/compile.go b/src/cmd/compile/internal/ssa/compile.go index 7f75dc4a03d5d..8b5d6d94e8d46 100644 --- a/src/cmd/compile/internal/ssa/compile.go +++ b/src/cmd/compile/internal/ssa/compile.go @@ -42,7 +42,9 @@ func Compile(f *Func) { }() // Run all the passes - printFunc(f) + if f.Log() { + printFunc(f) + } f.HTMLWriter.WriteFunc("start", "start", f) if BuildDump != "" && BuildDump == f.Name { f.dumpFile("build") @@ -84,8 +86,10 @@ func Compile(f *Func) { stats = fmt.Sprintf("[%d ns]", time) } - f.Logf(" pass %s end %s\n", p.name, stats) - printFunc(f) + if f.Log() { + f.Logf(" pass %s end %s\n", p.name, stats) + printFunc(f) + } f.HTMLWriter.WriteFunc(phaseName, fmt.Sprintf("%s %s", phaseName, stats), f) } if p.time || p.mem { diff --git a/src/cmd/compile/internal/ssa/html.go b/src/cmd/compile/internal/ssa/html.go index 812590934920b..2e48e8105b146 100644 --- a/src/cmd/compile/internal/ssa/html.go +++ b/src/cmd/compile/internal/ssa/html.go @@ -11,12 +11,14 @@ import ( "html" "io" "os" + "path/filepath" "strings" ) type HTMLWriter struct { Logger - w io.WriteCloser + w io.WriteCloser + path string } func NewHTMLWriter(path string, logger Logger, funcname string) *HTMLWriter { @@ -24,7 +26,11 @@ func NewHTMLWriter(path string, logger Logger, funcname string) *HTMLWriter { if err != nil { logger.Fatalf(src.NoXPos, "%v", err) } - html := HTMLWriter{w: out, Logger: logger} + pwd, err := os.Getwd() + if err != nil { + logger.Fatalf(src.NoXPos, "%v", err) + } + html := HTMLWriter{w: out, Logger: logger, path: filepath.Join(pwd, path)} html.start(funcname) return &html } @@ -439,6 +445,7 @@ func (w *HTMLWriter) Close() { io.WriteString(w.w, "") io.WriteString(w.w, "") w.w.Close() + fmt.Printf("dumped SSA to %v\n", w.path) } // WriteFunc writes f in a column headed by title. From c374984e99888bb2e2dd6c331a1328275debe19d Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Thu, 26 Jul 2018 12:46:50 +0300 Subject: [PATCH 0159/1663] cmd/compile: export the Func.Endlineno field This CL exports the Func.Endlineno value for inlineable functions. It is needed to grab the source code of an imported function inlined into the function specified in $GOSSAFUNC. See CL 126606 for details. Updates #25904 Change-Id: I1e259e20445e4109b4621a95abb5bde1be457af1 Reviewed-on: https://go-review.googlesource.com/126605 Run-TryBot: Yury Smolsky TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/iexport.go | 10 ++++++++++ src/cmd/compile/internal/gc/iimport.go | 1 + 2 files changed, 11 insertions(+) diff --git a/src/cmd/compile/internal/gc/iexport.go b/src/cmd/compile/internal/gc/iexport.go index 5ce284dc732cc..3007c9cabfa57 100644 --- a/src/cmd/compile/internal/gc/iexport.go +++ b/src/cmd/compile/internal/gc/iexport.go @@ -952,6 +952,16 @@ func (w *exportWriter) funcExt(n *Node) { if n.Func.ExportInline() { w.p.doInline(n) } + + // Endlineno for inlined function. + if n.Name.Defn != nil { + w.pos(n.Name.Defn.Func.Endlineno) + } else { + // When the exported node was defined externally, + // e.g. io exports atomic.(*Value).Load or bytes exports errors.New. + // Keep it as we don't distinguish this case in iimport.go. + w.pos(n.Func.Endlineno) + } } else { w.uint64(0) } diff --git a/src/cmd/compile/internal/gc/iimport.go b/src/cmd/compile/internal/gc/iimport.go index 21151b52159e1..6f0fd6b6d2769 100644 --- a/src/cmd/compile/internal/gc/iimport.go +++ b/src/cmd/compile/internal/gc/iimport.go @@ -679,6 +679,7 @@ func (r *importReader) funcExt(n *Node) { n.Func.Inl = &Inline{ Cost: int32(u - 1), } + n.Func.Endlineno = r.pos() } } From 9e2a04d5ebe450defe3435d827ef07ca3c0eae3f Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Thu, 26 Jul 2018 12:51:06 +0300 Subject: [PATCH 0160/1663] cmd/compile: add sources for inlined functions to ssa.html This CL adds the source code of all inlined functions into the function specified in $GOSSAFUNC. The code is appended to the sources column of ssa.html. ssaDumpInlined is populated with references to inlined functions. Then it is used for dumping the sources in buildssa. The source columns contains code in following order: target function, inlined functions sorted by filename, lineno. Fixes #25904 Change-Id: I4f6d4834376f1efdfda1f968a5335c0543ed36bc Reviewed-on: https://go-review.googlesource.com/126606 Run-TryBot: Yury Smolsky TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/inl.go | 4 ++ src/cmd/compile/internal/gc/ssa.go | 78 ++++++++++++++++++++-------- src/cmd/compile/internal/ssa/html.go | 61 +++++++++++++++++++--- 3 files changed, 114 insertions(+), 29 deletions(-) diff --git a/src/cmd/compile/internal/gc/inl.go b/src/cmd/compile/internal/gc/inl.go index feb3c8556acc1..fb5a413b84614 100644 --- a/src/cmd/compile/internal/gc/inl.go +++ b/src/cmd/compile/internal/gc/inl.go @@ -893,6 +893,10 @@ func mkinlcall1(n, fn *Node, maxCost int32) *Node { fmt.Printf("%v: Before inlining: %+v\n", n.Line(), n) } + if ssaDump != "" && ssaDump == Curfn.funcname() { + ssaDumpInlined = append(ssaDumpInlined, fn) + } + ninit := n.Ninit // Make temp names to use instead of the originals. diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 2abd9448d4ee2..bbd2a668a5979 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -27,6 +27,9 @@ var ssaDump string // early copy of $GOSSAFUNC; the func name to dump output var ssaDumpStdout bool // whether to dump to stdout const ssaDumpFile = "ssa.html" +// ssaDumpInlined holds all inlined functions when ssaDump contains a function name. +var ssaDumpInlined []*Node + func initssaconfig() { types_ := ssa.NewTypes() @@ -147,27 +150,7 @@ func buildssa(fn *Node, worker int) *ssa.Func { if printssa { s.f.HTMLWriter = ssa.NewHTMLWriter(ssaDumpFile, s.f.Frontend(), name) // TODO: generate and print a mapping from nodes to values and blocks - - // Read sources for a function fn and format into a column. - fname := Ctxt.PosTable.Pos(fn.Pos).Filename() - f, err := os.Open(fname) - if err != nil { - s.f.HTMLWriter.Logger.Logf("skipping sources column: %v", err) - } else { - defer f.Close() - firstLn := fn.Pos.Line() - 1 - lastLn := fn.Func.Endlineno.Line() - var lines []string - ln := uint(0) - scanner := bufio.NewScanner(f) - for scanner.Scan() && ln < lastLn { - if ln >= firstLn { - lines = append(lines, scanner.Text()) - } - ln++ - } - s.f.HTMLWriter.WriteSources("sources", fname, firstLn+1, lines) - } + dumpSourcesColumn(s.f.HTMLWriter, fn) } // Allocate starting block @@ -239,6 +222,59 @@ func buildssa(fn *Node, worker int) *ssa.Func { return s.f } +func dumpSourcesColumn(writer *ssa.HTMLWriter, fn *Node) { + // Read sources of target function fn. + fname := Ctxt.PosTable.Pos(fn.Pos).Filename() + targetFn, err := readFuncLines(fname, fn.Pos.Line(), fn.Func.Endlineno.Line()) + if err != nil { + writer.Logger.Logf("cannot read sources for function %v: %v", fn, err) + } + + // Read sources of inlined functions. + var inlFns []*ssa.FuncLines + for _, fi := range ssaDumpInlined { + var elno src.XPos + if fi.Name.Defn == nil { + // Endlineno is filled from exported data. + elno = fi.Func.Endlineno + } else { + elno = fi.Name.Defn.Func.Endlineno + } + fname := Ctxt.PosTable.Pos(fi.Pos).Filename() + fnLines, err := readFuncLines(fname, fi.Pos.Line(), elno.Line()) + if err != nil { + writer.Logger.Logf("cannot read sources for function %v: %v", fi, err) + continue + } + inlFns = append(inlFns, fnLines) + } + + sort.Sort(ssa.ByTopo(inlFns)) + if targetFn != nil { + inlFns = append([]*ssa.FuncLines{targetFn}, inlFns...) + } + + writer.WriteSources("sources", inlFns) +} + +func readFuncLines(file string, start, end uint) (*ssa.FuncLines, error) { + f, err := os.Open(os.ExpandEnv(file)) + if err != nil { + return nil, err + } + defer f.Close() + var lines []string + ln := uint(1) + scanner := bufio.NewScanner(f) + for scanner.Scan() && ln <= end { + if ln >= start { + lines = append(lines, scanner.Text()) + } + ln++ + } + return &ssa.FuncLines{Filename: file, StartLineno: start, Lines: lines}, nil +} + // updateUnsetPredPos propagates the earliest-value position information for b // towards all of b's predecessors that need a position, and recurs on that // predecessor if its position is updated. B should have a non-empty position. diff --git a/src/cmd/compile/internal/ssa/html.go b/src/cmd/compile/internal/ssa/html.go index 2e48e8105b146..6943e5ef4031f 100644 --- a/src/cmd/compile/internal/ssa/html.go +++ b/src/cmd/compile/internal/ssa/html.go @@ -458,25 +458,70 @@ func (w *HTMLWriter) WriteFunc(phase, title string, f *Func) { // TODO: Add visual representation of f's CFG. } +// FuncLines contains source code for a function to be displayed +// in sources column. +type FuncLines struct { + Filename string + StartLineno uint + Lines []string +} + +// ByTopo sorts topologically: target function is on top, +// followed by inlined functions sorted by filename and line numbers. +type ByTopo []*FuncLines + +func (x ByTopo) Len() int { return len(x) } +func (x ByTopo) Swap(i, j int) { x[i], x[j] = x[j], x[i] } +func (x ByTopo) Less(i, j int) bool { + a := x[i] + b := x[j] + if a.Filename == a.Filename { + return a.StartLineno < b.StartLineno + } + return a.Filename < b.Filename +} + // WriteSources writes lines as source code in a column headed by title. // phase is used for collapsing columns and should be unique across the table. -func (w *HTMLWriter) WriteSources(phase, title string, firstLineno uint, lines []string) { +func (w *HTMLWriter) WriteSources(phase string, all []*FuncLines) { if w == nil { return // avoid generating HTML just to discard it } var buf bytes.Buffer fmt.Fprint(&buf, "
    ") - for i, _ := range lines { - ln := int(firstLineno) + i - fmt.Fprintf(&buf, "
    %v
    ", ln, ln) + filename := "" + for _, fl := range all { + fmt.Fprint(&buf, "
     
    ") + if filename != fl.Filename { + fmt.Fprint(&buf, "
     
    ") + filename = fl.Filename + } + for i := range fl.Lines { + ln := int(fl.StartLineno) + i + fmt.Fprintf(&buf, "
    %v
    ", ln, ln) + } } fmt.Fprint(&buf, "
    ")
    -	for i, l := range lines {
    -		ln := int(firstLineno) + i
    -		fmt.Fprintf(&buf, "
    %v
    ", ln, html.EscapeString(l)) + filename = "" + for _, fl := range all { + fmt.Fprint(&buf, "
     
    ") + if filename != fl.Filename { + fmt.Fprintf(&buf, "
    %v
    ", fl.Filename) + filename = fl.Filename + } + for i, line := range fl.Lines { + ln := int(fl.StartLineno) + i + var escaped string + if strings.TrimSpace(line) == "" { + escaped = " " + } else { + escaped = html.EscapeString(line) + } + fmt.Fprintf(&buf, "
    %v
    ", ln, escaped) + } } fmt.Fprint(&buf, "
    ") - w.WriteColumn(phase, title, "", buf.String()) + w.WriteColumn(phase, phase, "", buf.String()) } // WriteColumn writes raw HTML in a column headed by title. From c5d38b896df504e3354d7a27f7ad86fa9661ce6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Thu, 10 May 2018 13:25:39 +0200 Subject: [PATCH 0161/1663] cmd/compile: add convnop helper function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Like the conv helper function but for creating OCONVNOP nodes instead of OCONV nodes. passes toolstash -cmp Change-Id: Ib93ffe66590ebaa2b4fa552c81f1a2902e789d8e Reviewed-on: https://go-review.googlesource.com/112597 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Josh Bleecher Snyder --- src/cmd/compile/internal/gc/closure.go | 10 ++-------- src/cmd/compile/internal/gc/range.go | 3 +-- src/cmd/compile/internal/gc/select.go | 13 +++++-------- src/cmd/compile/internal/gc/subr.go | 3 +-- src/cmd/compile/internal/gc/walk.go | 19 ++++++++++++------- 5 files changed, 21 insertions(+), 27 deletions(-) diff --git a/src/cmd/compile/internal/gc/closure.go b/src/cmd/compile/internal/gc/closure.go index ce575a64180e3..834cdc41eb6e5 100644 --- a/src/cmd/compile/internal/gc/closure.go +++ b/src/cmd/compile/internal/gc/closure.go @@ -382,10 +382,7 @@ func walkclosure(clo *Node, init *Nodes) *Node { clos.List.Set(append([]*Node{nod(OCFUNC, xfunc.Func.Nname, nil)}, clo.Func.Enter.Slice()...)) // Force type conversion from *struct to the func type. - clos = nod(OCONVNOP, clos, nil) - clos.Type = clo.Type - - clos = typecheck(clos, Erv) + clos = convnop(clos, clo.Type) // typecheck will insert a PTRLIT node under CONVNOP, // tag it with escape analysis result. @@ -511,10 +508,7 @@ func walkpartialcall(n *Node, init *Nodes) *Node { clos.List.Append(n.Left) // Force type conversion from *struct to the func type. - clos = nod(OCONVNOP, clos, nil) - clos.Type = n.Type - - clos = typecheck(clos, Erv) + clos = convnop(clos, n.Type) // typecheck will insert a PTRLIT node under CONVNOP, // tag it with escape analysis result. diff --git a/src/cmd/compile/internal/gc/range.go b/src/cmd/compile/internal/gc/range.go index 591bd06368770..13f45e164dfcb 100644 --- a/src/cmd/compile/internal/gc/range.go +++ b/src/cmd/compile/internal/gc/range.go @@ -580,8 +580,7 @@ func arrayClear(n, v1, v2, a *Node) bool { tmp := nod(OINDEX, a, nodintconst(0)) tmp.SetBounded(true) tmp = nod(OADDR, tmp, nil) - tmp = nod(OCONVNOP, tmp, nil) - tmp.Type = types.Types[TUNSAFEPTR] + tmp = convnop(tmp, types.Types[TUNSAFEPTR]) n.Nbody.Append(nod(OAS, hp, tmp)) // hn = len(a) * sizeof(elem(a)) diff --git a/src/cmd/compile/internal/gc/select.go b/src/cmd/compile/internal/gc/select.go index 4445edbe92096..c7f39088880f9 100644 --- a/src/cmd/compile/internal/gc/select.go +++ b/src/cmd/compile/internal/gc/select.go @@ -316,13 +316,11 @@ func walkselectcases(cases *Nodes) []*Node { setField("kind", nodintconst(kind)) if c != nil { - c = nod(OCONVNOP, c, nil) - c.Type = types.Types[TUNSAFEPTR] + c = convnop(c, types.Types[TUNSAFEPTR]) setField("c", c) } if elem != nil { - elem = nod(OCONVNOP, elem, nil) - elem.Type = types.Types[TUNSAFEPTR] + elem = convnop(elem, types.Types[TUNSAFEPTR]) setField("elem", elem) } @@ -375,10 +373,9 @@ func walkselectcases(cases *Nodes) []*Node { // bytePtrToIndex returns a Node representing "(*byte)(&n[i])". func bytePtrToIndex(n *Node, i int64) *Node { - s := nod(OCONVNOP, nod(OADDR, nod(OINDEX, n, nodintconst(i)), nil), nil) - s.Type = types.NewPtr(types.Types[TUINT8]) - s = typecheck(s, Erv) - return s + s := nod(OADDR, nod(OINDEX, n, nodintconst(i)), nil) + t := types.NewPtr(types.Types[TUINT8]) + return convnop(s, t) } var scase *types.Type diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index 0af0ff82c4e93..61a3b2385d3a6 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -1674,8 +1674,7 @@ func genwrapper(rcvr *types.Type, method *types.Field, newnam *types.Sym) { if !dotlist[0].field.Type.IsPtr() { dot = nod(OADDR, dot, nil) } - as := nod(OAS, nthis, nod(OCONVNOP, dot, nil)) - as.Right.Type = rcvr + as := nod(OAS, nthis, convnop(dot, rcvr)) fn.Nbody.Append(as) fn.Nbody.Append(nodSym(ORETJMP, nil, methodSym(methodrcvr, method.Sym))) } else { diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index f75e729eb5508..00c3cf287254c 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -1506,9 +1506,7 @@ opswitch: a = typecheck(a, Etop) a = walkexpr(a, init) init.Append(a) - n = nod(OCONVNOP, h, nil) - n.Type = t - n = typecheck(n, Erv) + n = convnop(h, t) } else { // Call runtime.makehmap to allocate an // hmap on the heap and initialize hmap's hash0 field. @@ -2029,8 +2027,7 @@ func ascompatte(call *Node, isddd bool, lhs *types.Type, rhs []*Node, fp int, in // optimization - can do block copy if eqtypenoname(rhs[0].Type, lhs) { nl := nodarg(lhs, fp) - nr := nod(OCONVNOP, rhs[0], nil) - nr.Type = nl.Type + nr := convnop(rhs[0], nl.Type) n := convas(nod(OAS, nl, nr), init) n.SetTypecheck(1) return []*Node{n} @@ -2748,6 +2745,15 @@ func conv(n *Node, t *types.Type) *Node { return n } +// convnop converts node n to type t using the OCONVNOP op +// and typechecks the result with Erv. +func convnop(n *Node, t *types.Type) *Node { + n = nod(OCONVNOP, n, nil) + n.Type = t + n = typecheck(n, Erv) + return n +} + // byteindex converts n, which is byte-sized, to a uint8. // We cannot use conv, because we allow converting bool to uint8 here, // which is forbidden in user code. @@ -3157,8 +3163,7 @@ func extendslice(n *Node, init *Nodes) *Node { hp := nod(OINDEX, s, nod(OLEN, l1, nil)) hp.SetBounded(true) hp = nod(OADDR, hp, nil) - hp = nod(OCONVNOP, hp, nil) - hp.Type = types.Types[TUNSAFEPTR] + hp = convnop(hp, types.Types[TUNSAFEPTR]) // hn := l2 * sizeof(elem(s)) hn := nod(OMUL, l2, nodintconst(elemtype.Width)) From ad644d2e86bab85787879d41c2d2aebbd7c57db8 Mon Sep 17 00:00:00 2001 From: Kazuhiro Sera Date: Thu, 23 Aug 2018 05:06:47 +0000 Subject: [PATCH 0162/1663] all: fix typos detected by github.com/client9/misspell Change-Id: Iadb3c5de8ae9ea45855013997ed70f7929a88661 GitHub-Last-Rev: ae85bcf82be8fee533e2b9901c6133921382c70a GitHub-Pull-Request: golang/go#26920 Reviewed-on: https://go-review.googlesource.com/128955 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- misc/cgo/test/issue9400_linux.go | 2 +- misc/cgo/testshared/shared_test.go | 2 +- src/bytes/buffer_test.go | 2 +- src/cmd/asm/internal/asm/operand_test.go | 2 +- src/cmd/asm/internal/asm/testdata/amd64enc_extra.s | 2 +- src/cmd/compile/internal/gc/ssa.go | 2 +- src/cmd/compile/internal/ssa/deadstore.go | 2 +- src/cmd/go/internal/cache/default_unix_test.go | 2 +- src/cmd/go/internal/modload/load.go | 2 +- src/cmd/go/internal/work/exec.go | 2 +- src/cmd/trace/annotations.go | 1 + src/crypto/aes/gcm_arm64.s | 6 +++--- src/crypto/x509/verify.go | 2 +- src/internal/bytealg/index_arm64.s | 2 +- src/internal/trace/goroutines.go | 2 +- src/os/user/user.go | 2 +- src/runtime/asm_amd64.s | 2 +- src/runtime/sys_windows_amd64.s | 2 +- src/time/time.go | 2 +- test/fixedbugs/issue22662b.go | 2 +- test/live.go | 2 +- test/run.go | 2 +- 22 files changed, 24 insertions(+), 23 deletions(-) diff --git a/misc/cgo/test/issue9400_linux.go b/misc/cgo/test/issue9400_linux.go index 34eb4983a4161..7719535d251fa 100644 --- a/misc/cgo/test/issue9400_linux.go +++ b/misc/cgo/test/issue9400_linux.go @@ -41,7 +41,7 @@ func test9400(t *testing.T) { // Grow the stack and put down a test pattern const pattern = 0x123456789abcdef - var big [1024]uint64 // len must match assmebly + var big [1024]uint64 // len must match assembly for i := range big { big[i] = pattern } diff --git a/misc/cgo/testshared/shared_test.go b/misc/cgo/testshared/shared_test.go index 846a27173e311..529a2c692f8e5 100644 --- a/misc/cgo/testshared/shared_test.go +++ b/misc/cgo/testshared/shared_test.go @@ -560,7 +560,7 @@ func TestNotes(t *testing.T) { abiHashNoteFound = true case 3: // ELF_NOTE_GODEPS_TAG if depsNoteFound { - t.Error("multiple depedency list notes") + t.Error("multiple dependency list notes") } testDepsNote(t, f, note) depsNoteFound = true diff --git a/src/bytes/buffer_test.go b/src/bytes/buffer_test.go index acbe5ca0c49e2..6e9d6952a51a5 100644 --- a/src/bytes/buffer_test.go +++ b/src/bytes/buffer_test.go @@ -293,7 +293,7 @@ func TestReadFromPanicReader(t *testing.T) { } check(t, "TestReadFromPanicReader (1)", &buf, "") - // Confirm that when Reader panics, the emtpy buffer remains empty + // Confirm that when Reader panics, the empty buffer remains empty var buf2 Buffer defer func() { recover() diff --git a/src/cmd/asm/internal/asm/operand_test.go b/src/cmd/asm/internal/asm/operand_test.go index 1d1cf510cb77d..df60b71ebd53d 100644 --- a/src/cmd/asm/internal/asm/operand_test.go +++ b/src/cmd/asm/internal/asm/operand_test.go @@ -33,7 +33,7 @@ func newParser(goarch string) *Parser { // tryParse executes parse func in panicOnError=true context. // parse is expected to call any parsing methods that may panic. -// Returns error gathered from recover; nil if no parse errors occured. +// Returns error gathered from recover; nil if no parse errors occurred. // // For unexpected panics, calls t.Fatal. func tryParse(t *testing.T, parse func()) (err error) { diff --git a/src/cmd/asm/internal/asm/testdata/amd64enc_extra.s b/src/cmd/asm/internal/asm/testdata/amd64enc_extra.s index afd1dfd313705..2f0d9ecf8695f 100644 --- a/src/cmd/asm/internal/asm/testdata/amd64enc_extra.s +++ b/src/cmd/asm/internal/asm/testdata/amd64enc_extra.s @@ -911,7 +911,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$0 VADDPD.BCST.Z (AX), Z2, K1, Z1 // 62f1edd95808 VMAXPD.BCST (AX), Z2, K1, Z1 // 62f1ed595f08 VMAXPD.BCST.Z (AX), Z2, K1, Z1 // 62f1edd95f08 - // EVEX: surpress all exceptions (SAE). + // EVEX: suppress all exceptions (SAE). VMAXPD.SAE Z3, Z2, K1, Z1 // 62f1ed595fcb or 62f1ed195fcb VMAXPD.SAE.Z Z3, Z2, K1, Z1 // 62f1edd95fcb or 62f1ed995fcb VMAXPD (AX), Z2, K1, Z1 // 62f1ed495f08 diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index bbd2a668a5979..7292963799523 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -5710,7 +5710,7 @@ func (n *Node) StorageClass() ssa.StorageClass { case PAUTO: return ssa.ClassAuto default: - Fatalf("untranslateable storage class for %v: %s", n, n.Class()) + Fatalf("untranslatable storage class for %v: %s", n, n.Class()) return 0 } } diff --git a/src/cmd/compile/internal/ssa/deadstore.go b/src/cmd/compile/internal/ssa/deadstore.go index ca6bce972e278..1caa61a96600a 100644 --- a/src/cmd/compile/internal/ssa/deadstore.go +++ b/src/cmd/compile/internal/ssa/deadstore.go @@ -133,7 +133,7 @@ func dse(f *Func) { } } -// elimDeadAutosGeneric deletes autos that are never accessed. To acheive this +// elimDeadAutosGeneric deletes autos that are never accessed. To achieve this // we track the operations that the address of each auto reaches and if it only // reaches stores then we delete all the stores. The other operations will then // be eliminated by the dead code elimination pass. diff --git a/src/cmd/go/internal/cache/default_unix_test.go b/src/cmd/go/internal/cache/default_unix_test.go index a207497a42cc0..1458201f4b32a 100644 --- a/src/cmd/go/internal/cache/default_unix_test.go +++ b/src/cmd/go/internal/cache/default_unix_test.go @@ -62,6 +62,6 @@ func TestDefaultDir(t *testing.T) { os.Setenv("HOME", "/") if _, showWarnings := defaultDir(); showWarnings { // https://golang.org/issue/26280 - t.Error("Cache initalization warnings should be squelched when $GOCACHE and $XDG_CACHE_HOME are unset and $HOME is /") + t.Error("Cache initialization warnings should be squelched when $GOCACHE and $XDG_CACHE_HOME are unset and $HOME is /") } } diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index e6340b8bfdcd6..6c1525da9a4d2 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -758,7 +758,7 @@ func (pkg *loadPkg) stackText() string { } // why returns the text to use in "go mod why" output about the given package. -// It is less ornate than the stackText but conatins the same information. +// It is less ornate than the stackText but contains the same information. func (pkg *loadPkg) why() string { var buf strings.Builder var stack []*loadPkg diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 42fa0e64ac007..2822787e63d12 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -2858,7 +2858,7 @@ func useResponseFile(path string, argLen int) bool { } // On the Go build system, use response files about 10% of the - // time, just to excercise this codepath. + // time, just to exercise this codepath. isBuilder := os.Getenv("GO_BUILDER_NAME") != "" if isBuilder && rand.Intn(10) == 0 { return true diff --git a/src/cmd/trace/annotations.go b/src/cmd/trace/annotations.go index 96c109e0f251a..8071ac887967a 100644 --- a/src/cmd/trace/annotations.go +++ b/src/cmd/trace/annotations.go @@ -439,6 +439,7 @@ func (task *taskDesc) complete() bool { } // descendents returns all the task nodes in the subtree rooted from this task. +// TODO: the method name is misspelled func (task *taskDesc) decendents() []*taskDesc { if task == nil { return nil diff --git a/src/crypto/aes/gcm_arm64.s b/src/crypto/aes/gcm_arm64.s index 98e9f5bbe59dc..61c868cd0ca79 100644 --- a/src/crypto/aes/gcm_arm64.s +++ b/src/crypto/aes/gcm_arm64.s @@ -434,7 +434,7 @@ TEXT ·gcmAesEnc(SB),NOSPLIT,$0 VLD1 (tPtr), [ACC0.B16] VEOR ACC1.B16, ACC1.B16, ACC1.B16 VEOR ACCM.B16, ACCM.B16, ACCM.B16 - // Prepare intial counter, and the increment vector + // Prepare initial counter, and the increment vector VLD1 (ctrPtr), [CTR.B16] VEOR INC.B16, INC.B16, INC.B16 MOVD $1, H0 @@ -733,7 +733,7 @@ TEXT ·gcmAesDec(SB),NOSPLIT,$0 VLD1 (tPtr), [ACC0.B16] VEOR ACC1.B16, ACC1.B16, ACC1.B16 VEOR ACCM.B16, ACCM.B16, ACCM.B16 - // Prepare intial counter, and the increment vector + // Prepare initial counter, and the increment vector VLD1 (ctrPtr), [CTR.B16] VEOR INC.B16, INC.B16, INC.B16 MOVD $1, H0 @@ -969,7 +969,7 @@ tail: tailLast: VEOR KLAST.B16, B0.B16, B0.B16 - // Assuming it is safe to load past dstPtr due to the presense of the tag + // Assuming it is safe to load past dstPtr due to the presence of the tag VLD1 (srcPtr), [B5.B16] VEOR B5.B16, B0.B16, B0.B16 diff --git a/src/crypto/x509/verify.go b/src/crypto/x509/verify.go index 210db4c1d0eb3..4c2ff7b7c4d3d 100644 --- a/src/crypto/x509/verify.go +++ b/src/crypto/x509/verify.go @@ -861,7 +861,7 @@ nextIntermediate: } // validHostname returns whether host is a valid hostname that can be matched or -// matched against according to RFC 6125 2.2, with some leniency to accomodate +// matched against according to RFC 6125 2.2, with some leniency to accommodate // legacy values. func validHostname(host string) bool { host = strings.TrimSuffix(host, ".") diff --git a/src/internal/bytealg/index_arm64.s b/src/internal/bytealg/index_arm64.s index 20d68ba9b8bf8..3a551a72da139 100644 --- a/src/internal/bytealg/index_arm64.s +++ b/src/internal/bytealg/index_arm64.s @@ -32,7 +32,7 @@ TEXT indexbody<>(SB),NOSPLIT,$0-56 // to avoid repeatedly re-load it again and again // for sebsequent substring comparisons SUB R3, R1, R4 - // R4 contains the start of last substring for comparsion + // R4 contains the start of last substring for comparison ADD R0, R4, R4 ADD $1, R0, R8 diff --git a/src/internal/trace/goroutines.go b/src/internal/trace/goroutines.go index 2d7d3aa3ae250..a5fda489bea79 100644 --- a/src/internal/trace/goroutines.go +++ b/src/internal/trace/goroutines.go @@ -37,7 +37,7 @@ type UserRegionDesc struct { // Region end event. Normally EvUserRegion end event or nil, // but can be EvGoStop or EvGoEnd event if the goroutine - // terminated without explicitely ending the region. + // terminated without explicitly ending the region. End *Event GExecutionStat diff --git a/src/os/user/user.go b/src/os/user/user.go index 1f733b80235a5..c1b8101c8629c 100644 --- a/src/os/user/user.go +++ b/src/os/user/user.go @@ -11,7 +11,7 @@ parses /etc/passwd and /etc/group. The other is cgo-based and relies on the standard C library (libc) routines such as getpwuid_r and getgrnam_r. When cgo is available, cgo-based (libc-backed) code is used by default. -This can be overriden by using osusergo build tag, which enforces +This can be overridden by using osusergo build tag, which enforces the pure Go implementation. */ package user diff --git a/src/runtime/asm_amd64.s b/src/runtime/asm_amd64.s index 6c65674b3b0aa..2a15910aea15f 100644 --- a/src/runtime/asm_amd64.s +++ b/src/runtime/asm_amd64.s @@ -1472,7 +1472,7 @@ GLOBL debugCallFrameTooLarge<>(SB), RODATA, $0x14 // Size duplicated below // This function communicates back to the debugger by setting RAX and // invoking INT3 to raise a breakpoint signal. See the comments in the // implementation for the protocol the debugger is expected to -// follow. InjectDebugCall in the runtime tests demonstates this protocol. +// follow. InjectDebugCall in the runtime tests demonstrates this protocol. // // The debugger must ensure that any pointers passed to the function // obey escape analysis requirements. Specifically, it must not pass diff --git a/src/runtime/sys_windows_amd64.s b/src/runtime/sys_windows_amd64.s index c1449dba6006d..c9127ac2d2322 100644 --- a/src/runtime/sys_windows_amd64.s +++ b/src/runtime/sys_windows_amd64.s @@ -363,7 +363,7 @@ TEXT runtime·tstart_stdcall(SB),NOSPLIT,$0 // Layout new m scheduler stack on os stack. MOVQ SP, AX MOVQ AX, (g_stack+stack_hi)(DX) - SUBQ $(64*1024), AX // inital stack size (adjusted later) + SUBQ $(64*1024), AX // initial stack size (adjusted later) MOVQ AX, (g_stack+stack_lo)(DX) ADDQ $const__StackGuard, AX MOVQ AX, g_stackguard0(DX) diff --git a/src/time/time.go b/src/time/time.go index 5350d2e98b2b2..f2da32dbadc8f 100644 --- a/src/time/time.go +++ b/src/time/time.go @@ -1076,7 +1076,7 @@ func (t Time) Local() Time { return t } -// In returns a copy of t representating the same time instant, but +// In returns a copy of t representing the same time instant, but // with the copy's location information set to loc for display // purposes. // diff --git a/test/fixedbugs/issue22662b.go b/test/fixedbugs/issue22662b.go index 3594c0f4ef751..2678383ab0775 100644 --- a/test/fixedbugs/issue22662b.go +++ b/test/fixedbugs/issue22662b.go @@ -18,7 +18,7 @@ import ( ) // Each of these tests is expected to fail (missing package clause) -// at the position determined by the preceeding line directive. +// at the position determined by the preceding line directive. var tests = []struct { src, pos string }{ diff --git a/test/live.go b/test/live.go index 18611f5113d63..13bdc4aae1d24 100644 --- a/test/live.go +++ b/test/live.go @@ -465,7 +465,7 @@ func f29(b bool) { // copy of array of pointers should die at end of range loop var pstructarr [10]pstruct -// Struct size choosen to make pointer to element in pstructarr +// Struct size chosen to make pointer to element in pstructarr // not computable by strength reduction. type pstruct struct { intp *int diff --git a/test/run.go b/test/run.go index 99ef79feb180c..82508d1c1fa53 100644 --- a/test/run.go +++ b/test/run.go @@ -435,7 +435,7 @@ func (ctxt *context) match(name string) bool { func init() { checkShouldTest() } // goGcflags returns the -gcflags argument to use with go build / go run. -// This must match the flags used for building the standard libary, +// This must match the flags used for building the standard library, // or else the commands will rebuild any needed packages (like runtime) // over and over. func goGcflags() string { From e897d43c37c353a35f211384058475a5093f1adf Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Thu, 23 Aug 2018 14:31:32 -0400 Subject: [PATCH 0163/1663] doc/go1.11: remove draft status Change-Id: I3f99083b7d8ab06482c2c22eafda8b0141a872bd Reviewed-on: https://go-review.googlesource.com/131076 Reviewed-by: Brad Fitzpatrick --- doc/go1.11.html | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/doc/go1.11.html b/doc/go1.11.html index 087dc72f8e195..80463c4494954 100644 --- a/doc/go1.11.html +++ b/doc/go1.11.html @@ -15,14 +15,7 @@ ul li { margin: 0.5em 0; } -

    DRAFT RELEASE NOTES - Introduction to Go 1.11

    - -

    - - Go 1.11 is not yet released. These are work-in-progress - release notes. Go 1.11 is expected to be released in August 2018. - -

    +

    Introduction to Go 1.11

    The latest Go release, version 1.11, arrives six months after Go 1.10. @@ -384,7 +377,7 @@

    Gofmt

    time. In general, systems that need consistent formatting of Go source code should use a specific version of the gofmt binary. - See the go/format package godoc for more + See the go/format package documentation for more information.

    From 4b439e41e2cdd78e0eeed05942c93364c5d99b6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Fri, 1 Jun 2018 12:17:41 +0100 Subject: [PATCH 0164/1663] cmd/vet: check embedded field tags too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We can no longer use the field's position for the duplicate field tag warning - since we now check embedded tags, the positions may belong to copmletely different packages. Instead, keep track of the lowest field that's still part of the top-level struct type that we are checking. Finally, be careful to not repeat the independent struct field warnings when checking fields again because they are embedded into another struct. To do this, separate the duplicate tag value logic into a func that recurses into embedded fields on a per-encoding basis. Fixes #25593. Change-Id: I3bd6e01306d8ec63c0314d25e3136d5e067a9517 Reviewed-on: https://go-review.googlesource.com/115677 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Alan Donovan --- src/cmd/vet/structtag.go | 110 ++++++++++++++++++------------ src/cmd/vet/testdata/structtag.go | 29 +++++--- 2 files changed, 87 insertions(+), 52 deletions(-) diff --git a/src/cmd/vet/structtag.go b/src/cmd/vet/structtag.go index a2571419c75ad..32366eab44bac 100644 --- a/src/cmd/vet/structtag.go +++ b/src/cmd/vet/structtag.go @@ -25,12 +25,13 @@ func init() { // checkStructFieldTags checks all the field tags of a struct, including checking for duplicates. func checkStructFieldTags(f *File, node ast.Node) { - styp := f.pkg.types[node.(*ast.StructType)].Type.(*types.Struct) + astType := node.(*ast.StructType) + typ := f.pkg.types[astType].Type.(*types.Struct) var seen map[[2]string]token.Pos - for i := 0; i < styp.NumFields(); i++ { - field := styp.Field(i) - tag := styp.Tag(i) - checkCanonicalFieldTag(f, field, tag, &seen) + for i := 0; i < typ.NumFields(); i++ { + field := typ.Field(i) + tag := typ.Tag(i) + checkCanonicalFieldTag(f, astType, field, tag, &seen) } } @@ -38,50 +39,16 @@ var checkTagDups = []string{"json", "xml"} var checkTagSpaces = map[string]bool{"json": true, "xml": true, "asn1": true} // checkCanonicalFieldTag checks a single struct field tag. -func checkCanonicalFieldTag(f *File, field *types.Var, tag string, seen *map[[2]string]token.Pos) { - if tag == "" { - return +// top is the top-level struct type that is currently being checked. +func checkCanonicalFieldTag(f *File, top *ast.StructType, field *types.Var, tag string, seen *map[[2]string]token.Pos) { + for _, key := range checkTagDups { + checkTagDuplicates(f, tag, key, field, field, seen) } if err := validateStructTag(tag); err != nil { f.Badf(field.Pos(), "struct field tag %#q not compatible with reflect.StructTag.Get: %s", tag, err) } - for _, key := range checkTagDups { - val := reflect.StructTag(tag).Get(key) - if val == "" || val == "-" || val[0] == ',' { - continue - } - if key == "xml" && field.Name() == "XMLName" { - // XMLName defines the XML element name of the struct being - // checked. That name cannot collide with element or attribute - // names defined on other fields of the struct. Vet does not have a - // check for untagged fields of type struct defining their own name - // by containing a field named XMLName; see issue 18256. - continue - } - if i := strings.Index(val, ","); i >= 0 { - if key == "xml" { - // Use a separate namespace for XML attributes. - for _, opt := range strings.Split(val[i:], ",") { - if opt == "attr" { - key += " attribute" // Key is part of the error message. - break - } - } - } - val = val[:i] - } - if *seen == nil { - *seen = map[[2]string]token.Pos{} - } - if pos, ok := (*seen)[[2]string{key, val}]; ok { - f.Badf(field.Pos(), "struct field %s repeats %s tag %q also at %s", field.Name(), key, val, f.loc(pos)) - } else { - (*seen)[[2]string{key, val}] = field.Pos() - } - } - // Check for use of json or xml tags with unexported fields. // Embedded struct. Nothing to do for now, but that @@ -102,6 +69,63 @@ func checkCanonicalFieldTag(f *File, field *types.Var, tag string, seen *map[[2] } } +// checkTagDuplicates checks a single struct field tag to see if any tags are +// duplicated. nearest is the field that's closest to the field being checked, +// while still being part of the top-level struct type. +func checkTagDuplicates(f *File, tag, key string, nearest, field *types.Var, seen *map[[2]string]token.Pos) { + val := reflect.StructTag(tag).Get(key) + if val == "-" { + // Ignored, even if the field is anonymous. + return + } + if val == "" || val[0] == ',' { + if field.Anonymous() { + typ, ok := field.Type().Underlying().(*types.Struct) + if !ok { + return + } + for i := 0; i < typ.NumFields(); i++ { + field := typ.Field(i) + if !field.Exported() { + continue + } + tag := typ.Tag(i) + checkTagDuplicates(f, tag, key, nearest, field, seen) + } + } + // Ignored if the field isn't anonymous. + return + } + if key == "xml" && field.Name() == "XMLName" { + // XMLName defines the XML element name of the struct being + // checked. That name cannot collide with element or attribute + // names defined on other fields of the struct. Vet does not have a + // check for untagged fields of type struct defining their own name + // by containing a field named XMLName; see issue 18256. + return + } + if i := strings.Index(val, ","); i >= 0 { + if key == "xml" { + // Use a separate namespace for XML attributes. + for _, opt := range strings.Split(val[i:], ",") { + if opt == "attr" { + key += " attribute" // Key is part of the error message. + break + } + } + } + val = val[:i] + } + if *seen == nil { + *seen = map[[2]string]token.Pos{} + } + if pos, ok := (*seen)[[2]string{key, val}]; ok { + f.Badf(nearest.Pos(), "struct field %s repeats %s tag %q also at %s", field.Name(), key, val, f.loc(pos)) + } else { + (*seen)[[2]string{key, val}] = field.Pos() + } +} + var ( errTagSyntax = errors.New("bad syntax for struct tag pair") errTagKeySyntax = errors.New("bad syntax for struct tag key") diff --git a/src/cmd/vet/testdata/structtag.go b/src/cmd/vet/testdata/structtag.go index 34bf9f6599b41..ad55c4ab64daa 100644 --- a/src/cmd/vet/testdata/structtag.go +++ b/src/cmd/vet/testdata/structtag.go @@ -42,43 +42,54 @@ type JSONEmbeddedField struct { type AnonymousJSON struct{} type AnonymousXML struct{} +type AnonymousJSONField struct { + DuplicateAnonJSON int `json:"a"` + + A int "hello" // ERROR "`hello` not compatible with reflect.StructTag.Get: bad syntax for struct tag pair" +} + type DuplicateJSONFields struct { JSON int `json:"a"` - DuplicateJSON int `json:"a"` // ERROR "struct field DuplicateJSON repeats json tag .a. also at structtag.go:46" + DuplicateJSON int `json:"a"` // ERROR "struct field DuplicateJSON repeats json tag .a. also at structtag.go:52" IgnoredJSON int `json:"-"` OtherIgnoredJSON int `json:"-"` OmitJSON int `json:",omitempty"` OtherOmitJSON int `json:",omitempty"` - DuplicateOmitJSON int `json:"a,omitempty"` // ERROR "struct field DuplicateOmitJSON repeats json tag .a. also at structtag.go:46" + DuplicateOmitJSON int `json:"a,omitempty"` // ERROR "struct field DuplicateOmitJSON repeats json tag .a. also at structtag.go:52" NonJSON int `foo:"a"` DuplicateNonJSON int `foo:"a"` Embedded struct { DuplicateJSON int `json:"a"` // OK because its not in the same struct type } - AnonymousJSON `json:"a"` // ERROR "struct field AnonymousJSON repeats json tag .a. also at structtag.go:46" + AnonymousJSON `json:"a"` // ERROR "struct field AnonymousJSON repeats json tag .a. also at structtag.go:52" + + AnonymousJSONField // ERROR "struct field DuplicateAnonJSON repeats json tag .a. also at structtag.go:52" XML int `xml:"a"` - DuplicateXML int `xml:"a"` // ERROR "struct field DuplicateXML repeats xml tag .a. also at structtag.go:60" + DuplicateXML int `xml:"a"` // ERROR "struct field DuplicateXML repeats xml tag .a. also at structtag.go:68" IgnoredXML int `xml:"-"` OtherIgnoredXML int `xml:"-"` OmitXML int `xml:",omitempty"` OtherOmitXML int `xml:",omitempty"` - DuplicateOmitXML int `xml:"a,omitempty"` // ERROR "struct field DuplicateOmitXML repeats xml tag .a. also at structtag.go:60" + DuplicateOmitXML int `xml:"a,omitempty"` // ERROR "struct field DuplicateOmitXML repeats xml tag .a. also at structtag.go:68" NonXML int `foo:"a"` DuplicateNonXML int `foo:"a"` Embedded2 struct { DuplicateXML int `xml:"a"` // OK because its not in the same struct type } - AnonymousXML `xml:"a"` // ERROR "struct field AnonymousXML repeats xml tag .a. also at structtag.go:60" + AnonymousXML `xml:"a"` // ERROR "struct field AnonymousXML repeats xml tag .a. also at structtag.go:68" Attribute struct { XMLName xml.Name `xml:"b"` NoDup int `xml:"b"` // OK because XMLName above affects enclosing struct. Attr int `xml:"b,attr"` // OK because 0 is valid. - DupAttr int `xml:"b,attr"` // ERROR "struct field DupAttr repeats xml attribute tag .b. also at structtag.go:76" - DupOmitAttr int `xml:"b,omitempty,attr"` // ERROR "struct field DupOmitAttr repeats xml attribute tag .b. also at structtag.go:76" + DupAttr int `xml:"b,attr"` // ERROR "struct field DupAttr repeats xml attribute tag .b. also at structtag.go:84" + DupOmitAttr int `xml:"b,omitempty,attr"` // ERROR "struct field DupOmitAttr repeats xml attribute tag .b. also at structtag.go:84" - AnonymousXML `xml:"b,attr"` // ERROR "struct field AnonymousXML repeats xml attribute tag .b. also at structtag.go:76" + AnonymousXML `xml:"b,attr"` // ERROR "struct field AnonymousXML repeats xml attribute tag .b. also at structtag.go:84" } + + AnonymousJSONField `json:"not_anon"` // ok; fields aren't embedded in JSON + AnonymousJSONField `json:"-"` // ok; entire field is ignored in JSON } type UnexpectedSpacetest struct { From b15a1e3cfb64aeeb90f74e0748524b38fde5ebf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Bohusl=C3=A1vek?= Date: Thu, 23 Aug 2018 19:51:50 +0200 Subject: [PATCH 0165/1663] text/template: Put bad function name in quotes in panic from (*Template).Funcs This turns panic: function name is not a valid identifier into panic: function name "" is not a valid identifier and also makes it consistent with the func signature check. This CL also makes the testBadFuncName func a test helper. Change-Id: Id967cb61ac28228de81e1cd76a39f5195a5ebd11 Reviewed-on: https://go-review.googlesource.com/130998 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/text/template/exec_test.go | 1 + src/text/template/funcs.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go index 6f40d80635fd0..648ad8ff03d26 100644 --- a/src/text/template/exec_test.go +++ b/src/text/template/exec_test.go @@ -1279,6 +1279,7 @@ func TestBadFuncNames(t *testing.T) { } func testBadFuncName(name string, t *testing.T) { + t.Helper() defer func() { recover() }() diff --git a/src/text/template/funcs.go b/src/text/template/funcs.go index abddfa1141b1f..31fe77a327daf 100644 --- a/src/text/template/funcs.go +++ b/src/text/template/funcs.go @@ -65,7 +65,7 @@ func createValueFuncs(funcMap FuncMap) map[string]reflect.Value { func addValueFuncs(out map[string]reflect.Value, in FuncMap) { for name, fn := range in { if !goodName(name) { - panic(fmt.Errorf("function name %s is not a valid identifier", name)) + panic(fmt.Errorf("function name %q is not a valid identifier", name)) } v := reflect.ValueOf(fn) if v.Kind() != reflect.Func { From c9986d1452f3ef226bfd044fb0f128175a7dff03 Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Fri, 17 Aug 2018 16:32:02 -0400 Subject: [PATCH 0166/1663] runtime: fix use of wrong g in gentraceback gentraceback gets the currently running g to do some sanity checks, but should use gp everywhere to do its actual work. Some noncritical checks later accidentally used g instead of gp. This seems like it could be a problem in many different contexts, but I noticed in Windows profiling, where profilem calls gentraceback on a goroutine from a different thread. Change-Id: I3da27a43e833b257f6411ee6893bdece45a9323f Reviewed-on: https://go-review.googlesource.com/128895 Run-TryBot: Heschi Kreinick Reviewed-by: Austin Clements --- src/runtime/traceback.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index a1f32016b9e52..78589f5ea38c7 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -99,8 +99,9 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in if skip > 0 && callback != nil { throw("gentraceback callback cannot be used with non-zero skip") } - g := getg() - if g == gp && g == g.m.curg { + + // Don't call this "g"; it's too easy get "g" and "gp" confused. + if ourg := getg(); ourg == gp && ourg == ourg.m.curg { // The starting sp has been passed in as a uintptr, and the caller may // have other uintptr-typed stack references as well. // If during one of the calls that got us here or during one of the @@ -200,7 +201,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in // g0, this systemstack is at the top of the stack. // if we're not on g0 or there's a no curg, then this is a regular call. sp := frame.sp - if flags&_TraceJumpStack != 0 && f.funcID == funcID_systemstack && gp == g.m.g0 && gp.m.curg != nil { + if flags&_TraceJumpStack != 0 && f.funcID == funcID_systemstack && gp == gp.m.g0 && gp.m.curg != nil { sp = gp.m.curg.sched.sp frame.sp = sp cgoCtxt = gp.m.curg.cgoCtxt @@ -425,7 +426,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in if frame.pc > f.entry { print(" +", hex(frame.pc-f.entry)) } - if g.m.throwing > 0 && gp == g.m.curg || level >= 2 { + if gp.m != nil && gp.m.throwing > 0 && gp == gp.m.curg || level >= 2 { print(" fp=", hex(frame.fp), " sp=", hex(frame.sp), " pc=", hex(frame.pc)) } print("\n") From ae6361e4bd78b85c284881a16b9b3f81133db1bb Mon Sep 17 00:00:00 2001 From: Heschi Kreinick Date: Fri, 17 Aug 2018 16:32:08 -0400 Subject: [PATCH 0167/1663] runtime: handle morestack system stack transition in gentraceback gentraceback handles system stack transitions, but only when they're done by systemstack(). Handle morestack() too. I tried to do this generically but systemstack and morestack are actually *very* different functions. Most notably, systemstack returns "normally", just messes with $sp along the way. morestack never returns at all -- it calls newstack, and newstack then jumps both stacks and functions back to whoever called morestack. I couldn't think of a way to handle both of them generically. So don't. The current implementation does not include systemstack on the generated traceback. That's partly because I don't know how to find its stack frame reliably, and partly because the current structure of the code wants to do the transition before the call, not after. If we're willing to assume that morestack's stack frame is 0 size, this could probably be fixed. For posterity's sake, alternatives tried: - Have morestack put a dummy function into schedbuf, like systemstack does. This actually worked (see patchset 1) but more by a series of coincidences than by deliberate design. The biggest coincidence was that because morestack_switch was a RET and its stack was 0 size, it actually worked to jump back to it at the end of newstack -- it would just return to the caller of morestack. Way too subtle for me, and also a little slower than just jumping directly. - Put morestack's PC and SP into schedbuf, so that gentraceback could treat it like a normal function except for the changing SP. This was a terrible idea and caused newstack to reenter morestack in a completely unreasonable state. To make testing possible I did a small redesign of testCPUProfile to take a callback that defines how to check if the conditions pass to it are satisfied. This seemed better than making the syntax of the "need" strings even more complicated. Updates #25943 Change-Id: I9271a30a976f80a093a3d4d1c7e9ec226faf74b4 Reviewed-on: https://go-review.googlesource.com/126795 Run-TryBot: Heschi Kreinick TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements --- src/runtime/pprof/pprof_test.go | 110 +++++++++++++++++++++++++------- src/runtime/traceback.go | 31 ++++++--- 2 files changed, 109 insertions(+), 32 deletions(-) diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index 44d514393ea44..095972fa68198 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -73,14 +73,14 @@ func cpuHog2(x int) int { } func TestCPUProfile(t *testing.T) { - testCPUProfile(t, []string{"runtime/pprof.cpuHog1"}, func(dur time.Duration) { + testCPUProfile(t, stackContains, []string{"runtime/pprof.cpuHog1"}, func(dur time.Duration) { cpuHogger(cpuHog1, &salt1, dur) }) } func TestCPUProfileMultithreaded(t *testing.T) { defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2)) - testCPUProfile(t, []string{"runtime/pprof.cpuHog1", "runtime/pprof.cpuHog2"}, func(dur time.Duration) { + testCPUProfile(t, stackContains, []string{"runtime/pprof.cpuHog1", "runtime/pprof.cpuHog2"}, func(dur time.Duration) { c := make(chan int) go func() { cpuHogger(cpuHog1, &salt1, dur) @@ -92,7 +92,7 @@ func TestCPUProfileMultithreaded(t *testing.T) { } func TestCPUProfileInlining(t *testing.T) { - testCPUProfile(t, []string{"runtime/pprof.inlinedCallee", "runtime/pprof.inlinedCaller"}, func(dur time.Duration) { + testCPUProfile(t, stackContains, []string{"runtime/pprof.inlinedCallee", "runtime/pprof.inlinedCaller"}, func(dur time.Duration) { cpuHogger(inlinedCaller, &salt1, dur) }) } @@ -130,7 +130,9 @@ func parseProfile(t *testing.T, valBytes []byte, f func(uintptr, []*profile.Loca } } -func testCPUProfile(t *testing.T, need []string, f func(dur time.Duration)) { +// testCPUProfile runs f under the CPU profiler, checking for some conditions specified by need, +// as interpreted by matches. +func testCPUProfile(t *testing.T, matches matchFunc, need []string, f func(dur time.Duration)) { switch runtime.GOOS { case "darwin": switch runtime.GOARCH { @@ -169,7 +171,7 @@ func testCPUProfile(t *testing.T, need []string, f func(dur time.Duration)) { f(duration) StopCPUProfile() - if profileOk(t, need, prof, duration) { + if profileOk(t, need, matches, prof, duration) { return } @@ -202,7 +204,21 @@ func contains(slice []string, s string) bool { return false } -func profileOk(t *testing.T, need []string, prof bytes.Buffer, duration time.Duration) (ok bool) { +// stackContains matches if a function named spec appears anywhere in the stack trace. +func stackContains(spec string, count uintptr, stk []*profile.Location, labels map[string][]string) bool { + for _, loc := range stk { + for _, line := range loc.Line { + if strings.Contains(line.Function.Name, spec) { + return true + } + } + } + return false +} + +type matchFunc func(spec string, count uintptr, stk []*profile.Location, labels map[string][]string) bool + +func profileOk(t *testing.T, need []string, matches matchFunc, prof bytes.Buffer, duration time.Duration) (ok bool) { ok = true // Check that profile is well formed and contains need. @@ -213,20 +229,9 @@ func profileOk(t *testing.T, need []string, prof bytes.Buffer, duration time.Dur fmt.Fprintf(&buf, "%d:", count) fprintStack(&buf, stk) samples += count - for i, name := range need { - if semi := strings.Index(name, ";"); semi > -1 { - kv := strings.SplitN(name[semi+1:], "=", 2) - if len(kv) != 2 || !contains(labels[kv[0]], kv[1]) { - continue - } - name = name[:semi] - } - for _, loc := range stk { - for _, line := range loc.Line { - if strings.Contains(line.Function.Name, name) { - have[i] += count - } - } + for i, spec := range need { + if matches(spec, count, stk, labels) { + have[i] += count } } fmt.Fprintf(&buf, "\n") @@ -377,7 +382,7 @@ func fprintStack(w io.Writer, stk []*profile.Location) { // Test that profiling of division operations is okay, especially on ARM. See issue 6681. func TestMathBigDivide(t *testing.T) { - testCPUProfile(t, nil, func(duration time.Duration) { + testCPUProfile(t, nil, nil, func(duration time.Duration) { t := time.After(duration) pi := new(big.Int) for { @@ -395,6 +400,48 @@ func TestMathBigDivide(t *testing.T) { }) } +// stackContainsAll matches if all functions in spec (comma-separated) appear somewhere in the stack trace. +func stackContainsAll(spec string, count uintptr, stk []*profile.Location, labels map[string][]string) bool { + for _, f := range strings.Split(spec, ",") { + if !stackContains(f, count, stk, labels) { + return false + } + } + return true +} + +func TestMorestack(t *testing.T) { + testCPUProfile(t, stackContainsAll, []string{"runtime.newstack,runtime/pprof.growstack"}, func(duration time.Duration) { + t := time.After(duration) + c := make(chan bool) + for { + go func() { + growstack1() + c <- true + }() + select { + case <-t: + return + case <-c: + } + } + }) +} + +//go:noinline +func growstack1() { + growstack() +} + +//go:noinline +func growstack() { + var buf [8 << 10]byte + use(buf) +} + +//go:noinline +func use(x [8 << 10]byte) {} + func TestBlockProfile(t *testing.T) { type TestCase struct { name string @@ -848,8 +895,25 @@ func TestEmptyCallStack(t *testing.T) { } } +// stackContainsLabeled takes a spec like funcname;key=value and matches if the stack has that key +// and value and has funcname somewhere in the stack. +func stackContainsLabeled(spec string, count uintptr, stk []*profile.Location, labels map[string][]string) bool { + semi := strings.Index(spec, ";") + if semi == -1 { + panic("no semicolon in key/value spec") + } + kv := strings.SplitN(spec[semi+1:], "=", 2) + if len(kv) != 2 { + panic("missing = in key/value spec") + } + if !contains(labels[kv[0]], kv[1]) { + return false + } + return stackContains(spec[:semi], count, stk, labels) +} + func TestCPUProfileLabel(t *testing.T) { - testCPUProfile(t, []string{"runtime/pprof.cpuHogger;key=value"}, func(dur time.Duration) { + testCPUProfile(t, stackContainsLabeled, []string{"runtime/pprof.cpuHogger;key=value"}, func(dur time.Duration) { Do(context.Background(), Labels("key", "value"), func(context.Context) { cpuHogger(cpuHog1, &salt1, dur) }) @@ -860,7 +924,7 @@ func TestLabelRace(t *testing.T) { // Test the race detector annotations for synchronization // between settings labels and consuming them from the // profile. - testCPUProfile(t, []string{"runtime/pprof.cpuHogger;key=value"}, func(dur time.Duration) { + testCPUProfile(t, stackContainsLabeled, []string{"runtime/pprof.cpuHogger;key=value"}, func(dur time.Duration) { start := time.Now() var wg sync.WaitGroup for time.Since(start) < dur { diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index 78589f5ea38c7..8370fd75937ed 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -197,16 +197,29 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in // Found an actual function. // Derive frame pointer and link register. if frame.fp == 0 { - // We want to jump over the systemstack switch. If we're running on the - // g0, this systemstack is at the top of the stack. - // if we're not on g0 or there's a no curg, then this is a regular call. - sp := frame.sp - if flags&_TraceJumpStack != 0 && f.funcID == funcID_systemstack && gp == gp.m.g0 && gp.m.curg != nil { - sp = gp.m.curg.sched.sp - frame.sp = sp - cgoCtxt = gp.m.curg.cgoCtxt + // Jump over system stack transitions. If we're on g0 and there's a user + // goroutine, try to jump. Otherwise this is a regular call. + if flags&_TraceJumpStack != 0 && gp == gp.m.g0 && gp.m.curg != nil { + switch f.funcID { + case funcID_morestack: + // morestack does not return normally -- newstack() + // gogo's to curg.sched. Match that. + // This keeps morestack() from showing up in the backtrace, + // but that makes some sense since it'll never be returned + // to. + frame.pc = gp.m.curg.sched.pc + frame.fn = findfunc(frame.pc) + f = frame.fn + frame.sp = gp.m.curg.sched.sp + cgoCtxt = gp.m.curg.cgoCtxt + case funcID_systemstack: + // systemstack returns normally, so just follow the + // stack transition. + frame.sp = gp.m.curg.sched.sp + cgoCtxt = gp.m.curg.cgoCtxt + } } - frame.fp = sp + uintptr(funcspdelta(f, frame.pc, &cache)) + frame.fp = frame.sp + uintptr(funcspdelta(f, frame.pc, &cache)) if !usesLR { // On x86, call instruction pushes return PC before entering new function. frame.fp += sys.RegSize From 6e76aeba0bda33f6bd45ac9c8e5c026c1688e846 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Thu, 23 Aug 2018 15:05:19 -0400 Subject: [PATCH 0168/1663] doc/go1.11: add link to new WebAssembly wiki page The wiki page has recently been created, and at this time it's just a stub. It's expected that support for WebAssembly will be evolving over time, and the wiki page can be kept updated with helpful information, how to get started, tips and tricks, etc. Use present tense because it's expected that there will be more general information added by the time Go 1.11 release happens. Also add link to https://webassembly.org/ in first paragraph. Change-Id: I139c2dcec8f0d7fd89401df38a3e12960946693f Reviewed-on: https://go-review.googlesource.com/131078 Reviewed-by: Brad Fitzpatrick Reviewed-by: Ian Lance Taylor --- doc/go1.11.html | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/doc/go1.11.html b/doc/go1.11.html index 80463c4494954..469e111fb8773 100644 --- a/doc/go1.11.html +++ b/doc/go1.11.html @@ -88,7 +88,8 @@

    Ports

    WebAssembly

    - Go 1.11 adds an experimental port to WebAssembly (js/wasm). + Go 1.11 adds an experimental port to WebAssembly + (js/wasm).

    Go programs currently compile to one WebAssembly module that @@ -109,6 +110,10 @@

    WebAssembly

    tools except when those GOOS/GOARCH values are being used. If you have existing filenames matching those patterns, you will need to rename them.

    +

    + More information can be found on the + WebAssembly wiki page. +

    RISC-V GOARCH values reserved

    From 84374d4de52827147b475c481cf2a00b6d6dfc6b Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Mon, 23 Jul 2018 03:16:53 +0000 Subject: [PATCH 0169/1663] cmd/internal/obj: support more arm64 FP instructions ARM64 also supports float point LDP(load pair) & STP (store pair). The CL adds implementation and corresponding test cases for FLDPD/FLDPS/FSTPD/FSTPS. Change-Id: I45f112012a4e097bfaf023d029b36e6cbc7a5859 Reviewed-on: https://go-review.googlesource.com/125438 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/asm/internal/asm/testdata/arm64.s | 72 +++++++++++++++++++ .../asm/internal/asm/testdata/arm64error.s | 3 + src/cmd/internal/obj/arm64/a.out.go | 4 ++ src/cmd/internal/obj/arm64/anames.go | 4 ++ src/cmd/internal/obj/arm64/asm7.go | 34 +++++++-- 5 files changed, 113 insertions(+), 4 deletions(-) diff --git a/src/cmd/asm/internal/asm/testdata/arm64.s b/src/cmd/asm/internal/asm/testdata/arm64.s index 38616bd8376b1..2d55b4b2ad123 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64.s +++ b/src/cmd/asm/internal/asm/testdata/arm64.s @@ -741,6 +741,78 @@ again: UBFIZ $0, R1, $1, R2 // 220040d3 UBFIZW $0, R1, $1, R2 // 22000053 +// FSTPD/FSTPS/FLDPD/FLDPS + FLDPD (R0), (F1, F2) // 0108406d + FLDPD 8(R0), (F1, F2) // 0188406d + FLDPD -8(R0), (F1, F2) // 01887f6d + FLDPD 11(R0), (F1, F2) // 1b2c0091610b406d + FLDPD 1024(R0), (F1, F2) // 1b001091610b406d + FLDPD.W 8(R0), (F1, F2) // 0188c06d + FLDPD.P 8(R0), (F1, F2) // 0188c06c + FLDPD (RSP), (F1, F2) // e10b406d + FLDPD 8(RSP), (F1, F2) // e18b406d + FLDPD -8(RSP), (F1, F2) // e18b7f6d + FLDPD 11(RSP), (F1, F2) // fb2f0091610b406d + FLDPD 1024(RSP), (F1, F2) // fb031091610b406d + FLDPD.W 8(RSP), (F1, F2) // e18bc06d + FLDPD.P 8(RSP), (F1, F2) // e18bc06c + FLDPD -31(R0), (F1, F2) // 1b7c00d1610b406d + FLDPD -4(R0), (F1, F2) // 1b1000d1610b406d + FLDPD -8(R0), (F1, F2) // 01887f6d + FLDPD x(SB), (F1, F2) + FLDPD x+8(SB), (F1, F2) + FLDPS -5(R0), (F1, F2) // 1b1400d1610b402d + FLDPS (R0), (F1, F2) // 0108402d + FLDPS 4(R0), (F1, F2) // 0188402d + FLDPS -4(R0), (F1, F2) // 01887f2d + FLDPS.W 4(R0), (F1, F2) // 0188c02d + FLDPS.P 4(R0), (F1, F2) // 0188c02c + FLDPS 11(R0), (F1, F2) // 1b2c0091610b402d + FLDPS 1024(R0), (F1, F2) // 1b001091610b402d + FLDPS (RSP), (F1, F2) // e10b402d + FLDPS 4(RSP), (F1, F2) // e18b402d + FLDPS -4(RSP), (F1, F2) // e18b7f2d + FLDPS.W 4(RSP), (F1, F2) // e18bc02d + FLDPS.P 4(RSP), (F1, F2) // e18bc02c + FLDPS 11(RSP), (F1, F2) // fb2f0091610b402d + FLDPS 1024(RSP), (F1, F2) // fb031091610b402d + FLDPS x(SB), (F1, F2) + FLDPS x+8(SB), (F1, F2) + FSTPD (F3, F4), (R5) // a310006d + FSTPD (F3, F4), 8(R5) // a390006d + FSTPD.W (F3, F4), 8(R5) // a390806d + FSTPD.P (F3, F4), 8(R5) // a390806c + FSTPD (F3, F4), -8(R5) // a3903f6d + FSTPD (F3, F4), -4(R5) // bb1000d16313006d + FSTPD (F3, F4), 11(R0) // 1b2c00916313006d + FSTPD (F3, F4), 1024(R0) // 1b0010916313006d + FSTPD (F3, F4), (RSP) // e313006d + FSTPD (F3, F4), 8(RSP) // e393006d + FSTPD.W (F3, F4), 8(RSP) // e393806d + FSTPD.P (F3, F4), 8(RSP) // e393806c + FSTPD (F3, F4), -8(RSP) // e3933f6d + FSTPD (F3, F4), 11(RSP) // fb2f00916313006d + FSTPD (F3, F4), 1024(RSP) // fb0310916313006d + FSTPD (F3, F4), x(SB) + FSTPD (F3, F4), x+8(SB) + FSTPS (F3, F4), (R5) // a310002d + FSTPS (F3, F4), 4(R5) // a390002d + FSTPS.W (F3, F4), 4(R5) // a390802d + FSTPS.P (F3, F4), 4(R5) // a390802c + FSTPS (F3, F4), -4(R5) // a3903f2d + FSTPS (F3, F4), -5(R5) // bb1400d16313002d + FSTPS (F3, F4), 11(R0) // 1b2c00916313002d + FSTPS (F3, F4), 1024(R0) // 1b0010916313002d + FSTPS (F3, F4), (RSP) // e313002d + FSTPS (F3, F4), 4(RSP) // e393002d + FSTPS.W (F3, F4), 4(RSP) // e393802d + FSTPS.P (F3, F4), 4(RSP) // e393802c + FSTPS (F3, F4), -4(RSP) // e3933f2d + FSTPS (F3, F4), 11(RSP) // fb2f00916313002d + FSTPS (F3, F4), 1024(RSP) // fb0310916313002d + FSTPS (F3, F4), x(SB) + FSTPS (F3, F4), x+8(SB) + // END // // LTYPEE comma diff --git a/src/cmd/asm/internal/asm/testdata/arm64error.s b/src/cmd/asm/internal/asm/testdata/arm64error.s index 01d23eb527a7c..b2ec0cc42502b 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64error.s +++ b/src/cmd/asm/internal/asm/testdata/arm64error.s @@ -90,5 +90,8 @@ TEXT errors(SB),$0 AND $0x22220000, R2, RSP // ERROR "illegal combination" ANDS $0x22220000, R2, RSP // ERROR "illegal combination" LDP (R0), (F0, F1) // ERROR "invalid register pair" + LDP (R0), (R3, ZR) // ERROR "invalid register pair" STP (F2, F3), (R0) // ERROR "invalid register pair" + FLDPD (R0), (R1, R2) // ERROR "invalid register pair" + FSTPD (R1, R2), (R0) // ERROR "invalid register pair" RET diff --git a/src/cmd/internal/obj/arm64/a.out.go b/src/cmd/internal/obj/arm64/a.out.go index 2575940f19767..a32f973fa22c4 100644 --- a/src/cmd/internal/obj/arm64/a.out.go +++ b/src/cmd/internal/obj/arm64/a.out.go @@ -821,6 +821,8 @@ const ( AFCVTZUSW AFDIVD AFDIVS + AFLDPD + AFLDPS AFMOVD AFMOVS AFMULD @@ -829,6 +831,8 @@ const ( AFNEGS AFSQRTD AFSQRTS + AFSTPD + AFSTPS AFSUBD AFSUBS ASCVTFD diff --git a/src/cmd/internal/obj/arm64/anames.go b/src/cmd/internal/obj/arm64/anames.go index f4b3c288975cb..d9783caff9612 100644 --- a/src/cmd/internal/obj/arm64/anames.go +++ b/src/cmd/internal/obj/arm64/anames.go @@ -322,6 +322,8 @@ var Anames = []string{ "FCVTZUSW", "FDIVD", "FDIVS", + "FLDPD", + "FLDPS", "FMOVD", "FMOVS", "FMULD", @@ -330,6 +332,8 @@ var Anames = []string{ "FNEGS", "FSQRTD", "FSQRTS", + "FSTPD", + "FSTPS", "FSUBD", "FSUBS", "SCVTFD", diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index 1acf9799c626e..ad4f172544671 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -2193,14 +2193,21 @@ func buildop(ctxt *obj.Link) { AWORD, ADWORD, obj.ARET, - obj.ATEXT, - ASTP, - ASTPW, - ALDP: + obj.ATEXT: break + case ALDP: + oprangeset(AFLDPD, t) + + case ASTP: + oprangeset(AFSTPD, t) + + case ASTPW: + oprangeset(AFSTPS, t) + case ALDPW: oprangeset(ALDPSW, t) + oprangeset(AFLDPS, t) case AERET: oprangeset(AWFE, t) @@ -6164,13 +6171,26 @@ func (c *ctxt7) opextr(p *obj.Prog, a obj.As, v int32, rn int, rm int, rt int) u /* genrate instruction encoding for LDP/LDPW/LDPSW/STP/STPW */ func (c *ctxt7) opldpstp(p *obj.Prog, o *Optab, vo int32, rbase, rl, rh, ldp uint32) uint32 { var ret uint32 + // check offset switch p.As { + case AFLDPD, AFSTPD: + if vo < -512 || vo > 504 || vo%8 != 0 { + c.ctxt.Diag("invalid offset %v\n", p) + } + vo /= 8 + ret = 1<<30 | 1<<26 case ALDP, ASTP: if vo < -512 || vo > 504 || vo%8 != 0 { c.ctxt.Diag("invalid offset %v\n", p) } vo /= 8 ret = 2 << 30 + case AFLDPS, AFSTPS: + if vo < -256 || vo > 252 || vo%4 != 0 { + c.ctxt.Diag("invalid offset %v\n", p) + } + vo /= 4 + ret = 1 << 26 case ALDPW, ASTPW: if vo < -256 || vo > 252 || vo%4 != 0 { c.ctxt.Diag("invalid offset %v\n", p) @@ -6186,7 +6206,12 @@ func (c *ctxt7) opldpstp(p *obj.Prog, o *Optab, vo int32, rbase, rl, rh, ldp uin default: c.ctxt.Diag("invalid instruction %v\n", p) } + // check register pair switch p.As { + case AFLDPD, AFLDPS, AFSTPD, AFSTPS: + if rl < REG_F0 || REG_F31 < rl || rh < REG_F0 || REG_F31 < rh { + c.ctxt.Diag("invalid register pair %v\n", p) + } case ALDP, ALDPW, ALDPSW: if rl < REG_R0 || REG_R30 < rl || rh < REG_R0 || REG_R30 < rh { c.ctxt.Diag("invalid register pair %v\n", p) @@ -6196,6 +6221,7 @@ func (c *ctxt7) opldpstp(p *obj.Prog, o *Optab, vo int32, rbase, rl, rh, ldp uin c.ctxt.Diag("invalid register pair %v\n", p) } } + // other conditional flag bits switch o.scond { case C_XPOST: ret |= 1 << 23 From 379d2dea72e475288da97ad6c665105fb731a34d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Sat, 2 Jun 2018 20:55:20 +0200 Subject: [PATCH 0170/1663] cmd/compile: remove superfluous signed right shift used for signed division by 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A signed right shift before an unsigned right shift by register width-1 (extracts the sign bit) is superflous. trigger counts during ./make.bash 0 (Rsh8U (Rsh8 x _) 7 ) -> (Rsh8U x 7 ) 0 (Rsh16U (Rsh16 x _) 15 ) -> (Rsh16U x 15) 2 (Rsh32U (Rsh32 x _) 31 ) -> (Rsh32U x 31) 251 (Rsh64U (Rsh64 x _) 63 ) -> (Rsh64U x 63) Changes the instructions generated on AMD64 for x / 2 where x is a signed integer from: MOVQ AX, CX SARQ $63, AX SHRQ $63, AX ADDQ CX, AX SARQ $1, AX to: MOVQ AX, CX SHRQ $63, AX ADDQ CX, AX SARQ $1, AX Change-Id: I86321ae8fc9dc24b8fa9eb80aa5c7299eff8c9dc Reviewed-on: https://go-review.googlesource.com/115956 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- .../compile/internal/ssa/gen/generic.rules | 6 + .../compile/internal/ssa/rewritegeneric.go | 104 ++++++++++++++++++ 2 files changed, 110 insertions(+) diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index b1a0775e4a8f8..96051414dcb94 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -371,6 +371,12 @@ (Rsh16Ux64 (Rsh16Ux64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Rsh16Ux64 x (Const64 [c+d])) (Rsh8Ux64 (Rsh8Ux64 x (Const64 [c])) (Const64 [d])) && !uaddOvf(c,d) -> (Rsh8Ux64 x (Const64 [c+d])) +// Remove signed right shift before an unsigned right shift that extracts the sign bit. +(Rsh8Ux64 (Rsh8x64 x _) (Const64 [7] )) -> (Rsh8Ux64 x (Const64 [7] )) +(Rsh16Ux64 (Rsh16x64 x _) (Const64 [15])) -> (Rsh16Ux64 x (Const64 [15])) +(Rsh32Ux64 (Rsh32x64 x _) (Const64 [31])) -> (Rsh32Ux64 x (Const64 [31])) +(Rsh64Ux64 (Rsh64x64 x _) (Const64 [63])) -> (Rsh64Ux64 x (Const64 [63])) + // ((x >> c1) << c2) >> c3 (Rsh(64|32|16|8)Ux64 (Lsh(64|32|16|8)x64 (Rsh(64|32|16|8)Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3])) && uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3) diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 5ad53dd0b6d38..343b3581c1908 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -24905,6 +24905,32 @@ func rewriteValuegeneric_OpRsh16Ux64_0(v *Value) bool { v.AddArg(v0) return true } + // match: (Rsh16Ux64 (Rsh16x64 x _) (Const64 [15])) + // cond: + // result: (Rsh16Ux64 x (Const64 [15])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpRsh16x64 { + break + } + _ = v_0.Args[1] + x := v_0.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpConst64 { + break + } + t := v_1.Type + if v_1.AuxInt != 15 { + break + } + v.reset(OpRsh16Ux64) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpConst64, t) + v0.AuxInt = 15 + v.AddArg(v0) + return true + } // match: (Rsh16Ux64 (Lsh16x64 (Rsh16Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3])) // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3) // result: (Rsh16Ux64 x (Const64 [c1-c2+c3])) @@ -25449,6 +25475,32 @@ func rewriteValuegeneric_OpRsh32Ux64_0(v *Value) bool { v.AddArg(v0) return true } + // match: (Rsh32Ux64 (Rsh32x64 x _) (Const64 [31])) + // cond: + // result: (Rsh32Ux64 x (Const64 [31])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpRsh32x64 { + break + } + _ = v_0.Args[1] + x := v_0.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpConst64 { + break + } + t := v_1.Type + if v_1.AuxInt != 31 { + break + } + v.reset(OpRsh32Ux64) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpConst64, t) + v0.AuxInt = 31 + v.AddArg(v0) + return true + } // match: (Rsh32Ux64 (Lsh32x64 (Rsh32Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3])) // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3) // result: (Rsh32Ux64 x (Const64 [c1-c2+c3])) @@ -26055,6 +26107,32 @@ func rewriteValuegeneric_OpRsh64Ux64_0(v *Value) bool { v.AddArg(v0) return true } + // match: (Rsh64Ux64 (Rsh64x64 x _) (Const64 [63])) + // cond: + // result: (Rsh64Ux64 x (Const64 [63])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpRsh64x64 { + break + } + _ = v_0.Args[1] + x := v_0.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpConst64 { + break + } + t := v_1.Type + if v_1.AuxInt != 63 { + break + } + v.reset(OpRsh64Ux64) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpConst64, t) + v0.AuxInt = 63 + v.AddArg(v0) + return true + } // match: (Rsh64Ux64 (Lsh64x64 (Rsh64Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3])) // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3) // result: (Rsh64Ux64 x (Const64 [c1-c2+c3])) @@ -26723,6 +26801,32 @@ func rewriteValuegeneric_OpRsh8Ux64_0(v *Value) bool { v.AddArg(v0) return true } + // match: (Rsh8Ux64 (Rsh8x64 x _) (Const64 [7])) + // cond: + // result: (Rsh8Ux64 x (Const64 [7] )) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpRsh8x64 { + break + } + _ = v_0.Args[1] + x := v_0.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpConst64 { + break + } + t := v_1.Type + if v_1.AuxInt != 7 { + break + } + v.reset(OpRsh8Ux64) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpConst64, t) + v0.AuxInt = 7 + v.AddArg(v0) + return true + } // match: (Rsh8Ux64 (Lsh8x64 (Rsh8Ux64 x (Const64 [c1])) (Const64 [c2])) (Const64 [c3])) // cond: uint64(c1) >= uint64(c2) && uint64(c3) >= uint64(c2) && !uaddOvf(c1-c2, c3) // result: (Rsh8Ux64 x (Const64 [c1-c2+c3])) From c907a75494f0d828a9afa5f849684f3c09c4afa2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Thu, 10 May 2018 09:28:04 +0200 Subject: [PATCH 0171/1663] cmd/compile: refactor appendslice to use newer gc code style MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - add comments with builtin function signatures that are instantiated - use Nodes type from the beginning instead of []*Node with a later conversion to Nodes - use conv(x, y) helper function instead of nod(OCONV, x, y) - factor out repeated calls to Type.Elem() This makes the function style similar to newer functions like extendslice. passes toolstash -cmp Change-Id: Iedab191af9e0884fb6762c9c168430c1d2246979 Reviewed-on: https://go-review.googlesource.com/112598 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/gc/walk.go | 71 +++++++++++++++-------------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 00c3cf287254c..33a95528056ac 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -2950,92 +2950,93 @@ func appendslice(n *Node, init *Nodes) *Node { l1 := n.List.First() l2 := n.List.Second() - var l []*Node + var nodes Nodes // var s []T s := temp(l1.Type) - l = append(l, nod(OAS, s, l1)) // s = l1 + nodes.Append(nod(OAS, s, l1)) // s = l1 + + elemtype := s.Type.Elem() // n := len(s) + len(l2) nn := temp(types.Types[TINT]) - l = append(l, nod(OAS, nn, nod(OADD, nod(OLEN, s, nil), nod(OLEN, l2, nil)))) + nodes.Append(nod(OAS, nn, nod(OADD, nod(OLEN, s, nil), nod(OLEN, l2, nil)))) // if uint(n) > uint(cap(s)) nif := nod(OIF, nil, nil) - nif.Left = nod(OGT, nod(OCONV, nn, nil), nod(OCONV, nod(OCAP, s, nil), nil)) - nif.Left.Left.Type = types.Types[TUINT] - nif.Left.Right.Type = types.Types[TUINT] + nuint := conv(nn, types.Types[TUINT]) + scapuint := conv(nod(OCAP, s, nil), types.Types[TUINT]) + nif.Left = nod(OGT, nuint, scapuint) - // instantiate growslice(Type*, []any, int) []any + // instantiate growslice(typ *type, []any, int) []any fn := syslook("growslice") - fn = substArgTypes(fn, s.Type.Elem(), s.Type.Elem()) + fn = substArgTypes(fn, elemtype, elemtype) // s = growslice(T, s, n) - nif.Nbody.Set1(nod(OAS, s, mkcall1(fn, s.Type, &nif.Ninit, typename(s.Type.Elem()), s, nn))) - l = append(l, nif) + nif.Nbody.Set1(nod(OAS, s, mkcall1(fn, s.Type, &nif.Ninit, typename(elemtype), s, nn))) + nodes.Append(nif) // s = s[:n] nt := nod(OSLICE, s, nil) nt.SetSliceBounds(nil, nn, nil) - l = append(l, nod(OAS, s, nt)) + nodes.Append(nod(OAS, s, nt)) - if l1.Type.Elem().HasHeapPointer() { + var ncopy *Node + if elemtype.HasHeapPointer() { // copy(s[len(l1):], l2) nptr1 := nod(OSLICE, s, nil) nptr1.SetSliceBounds(nod(OLEN, l1, nil), nil, nil) + nptr2 := l2 + Curfn.Func.setWBPos(n.Pos) + + // instantiate typedslicecopy(typ *type, dst any, src any) int fn := syslook("typedslicecopy") fn = substArgTypes(fn, l1.Type, l2.Type) - var ln Nodes - ln.Set(l) - nt := mkcall1(fn, types.Types[TINT], &ln, typename(l1.Type.Elem()), nptr1, nptr2) - l = append(ln.Slice(), nt) + ncopy = mkcall1(fn, types.Types[TINT], &nodes, typename(elemtype), nptr1, nptr2) + } else if instrumenting && !compiling_runtime { // rely on runtime to instrument copy. // copy(s[len(l1):], l2) nptr1 := nod(OSLICE, s, nil) nptr1.SetSliceBounds(nod(OLEN, l1, nil), nil, nil) + nptr2 := l2 - var ln Nodes - ln.Set(l) - var nt *Node if l2.Type.IsString() { + // instantiate func slicestringcopy(to any, fr any) int fn := syslook("slicestringcopy") fn = substArgTypes(fn, l1.Type, l2.Type) - nt = mkcall1(fn, types.Types[TINT], &ln, nptr1, nptr2) + ncopy = mkcall1(fn, types.Types[TINT], &nodes, nptr1, nptr2) } else { + // instantiate func slicecopy(to any, fr any, wid uintptr) int fn := syslook("slicecopy") fn = substArgTypes(fn, l1.Type, l2.Type) - nt = mkcall1(fn, types.Types[TINT], &ln, nptr1, nptr2, nodintconst(s.Type.Elem().Width)) + ncopy = mkcall1(fn, types.Types[TINT], &nodes, nptr1, nptr2, nodintconst(elemtype.Width)) } - l = append(ln.Slice(), nt) } else { // memmove(&s[len(l1)], &l2[0], len(l2)*sizeof(T)) nptr1 := nod(OINDEX, s, nod(OLEN, l1, nil)) nptr1.SetBounded(true) - nptr1 = nod(OADDR, nptr1, nil) nptr2 := nod(OSPTR, l2, nil) - fn := syslook("memmove") - fn = substArgTypes(fn, s.Type.Elem(), s.Type.Elem()) - - var ln Nodes - ln.Set(l) - nwid := cheapexpr(conv(nod(OLEN, l2, nil), types.Types[TUINTPTR]), &ln) + nwid := cheapexpr(conv(nod(OLEN, l2, nil), types.Types[TUINTPTR]), &nodes) + nwid = nod(OMUL, nwid, nodintconst(elemtype.Width)) - nwid = nod(OMUL, nwid, nodintconst(s.Type.Elem().Width)) - nt := mkcall1(fn, nil, &ln, nptr1, nptr2, nwid) - l = append(ln.Slice(), nt) + // instantiate func memmove(to *any, frm *any, length uintptr) + fn := syslook("memmove") + fn = substArgTypes(fn, elemtype, elemtype) + ncopy = mkcall1(fn, nil, &nodes, nptr1, nptr2, nwid) } + ln := append(nodes.Slice(), ncopy) - typecheckslice(l, Etop) - walkstmtlist(l) - init.Append(l...) + typecheckslice(ln, Etop) + walkstmtlist(ln) + init.Append(ln...) return s } From 9cfa41c826ba358dc6f911f72dfbfda8c13d27fe Mon Sep 17 00:00:00 2001 From: Seebs Date: Fri, 3 Aug 2018 11:50:55 -0500 Subject: [PATCH 0172/1663] os: use Println instead of Printf in example This message has no format specifiers and no trailing newline. It should use Println for consistency with other examples. Change-Id: I49bd1652f9449fcbdd79c6b689c123090972aab3 Reviewed-on: https://go-review.googlesource.com/127836 Reviewed-by: Brad Fitzpatrick Reviewed-by: Tobias Klauser Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/os/example_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/os/example_test.go b/src/os/example_test.go index e21415a3fda9e..95a4a678171ca 100644 --- a/src/os/example_test.go +++ b/src/os/example_test.go @@ -70,7 +70,7 @@ func ExampleFileMode() { func ExampleIsNotExist() { filename := "a-nonexistent-file" if _, err := os.Stat(filename); os.IsNotExist(err) { - fmt.Printf("file does not exist") + fmt.Println("file does not exist") } // Output: // file does not exist From d8cf1514cadb512de6972e760ccef76452e3a67c Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 22 Aug 2018 14:01:52 +0200 Subject: [PATCH 0173/1663] internal/syscall/unix: don't use linkname to refer to syscall.fcntl Just open-code the fcntl syscall instead of relying on the obscurity of go:linkname. Change-Id: I3e4ec9db6539e016f56667d7b8b87aa37671d0e7 Reviewed-on: https://go-review.googlesource.com/130736 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/internal/syscall/unix/nonblocking.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/internal/syscall/unix/nonblocking.go b/src/internal/syscall/unix/nonblocking.go index 818e9c91a5699..1db3394432f58 100644 --- a/src/internal/syscall/unix/nonblocking.go +++ b/src/internal/syscall/unix/nonblocking.go @@ -6,18 +6,12 @@ package unix -import ( - "syscall" - _ "unsafe" // for go:linkname -) - -//go:linkname syscall_fcntl syscall.fcntl -func syscall_fcntl(fd int, cmd int, arg int) (val int, err error) +import "syscall" func IsNonblock(fd int) (nonblocking bool, err error) { - flag, err := syscall_fcntl(fd, syscall.F_GETFL, 0) - if err != nil { - return false, err + flag, _, e1 := syscall.Syscall(syscall.SYS_FCNTL, uintptr(fd), uintptr(syscall.F_GETFL), 0) + if e1 != 0 { + return false, e1 } return flag&syscall.O_NONBLOCK != 0, nil } From c15c04d9e85a6a2c46ae57cb830192e0eee276dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Sat, 28 Jul 2018 10:56:48 +0200 Subject: [PATCH 0174/1663] runtime: use internal/cpu variables in assembler code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Using internal/cpu variables has the benefit of avoiding false sharing (as those are padded) and allows memory and cache usage for these variables to be shared by multiple packages. Change-Id: I2bf68d03091bf52b466cf689230d5d25d5950037 Reviewed-on: https://go-review.googlesource.com/126599 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/runtime/asm_386.s | 2 +- src/runtime/cpuflags.go | 17 +++++++++++++++++ src/runtime/cpuflags_amd64.go | 6 ------ src/runtime/memclr_386.s | 3 ++- src/runtime/memclr_amd64.s | 2 +- src/runtime/memmove_386.s | 5 +++-- src/runtime/memmove_amd64.s | 3 ++- src/runtime/proc.go | 3 ++- src/runtime/runtime2.go | 5 ++--- 9 files changed, 30 insertions(+), 16 deletions(-) create mode 100644 src/runtime/cpuflags.go diff --git a/src/runtime/asm_386.s b/src/runtime/asm_386.s index a6a81c3f63d0e..725271eec4deb 100644 --- a/src/runtime/asm_386.s +++ b/src/runtime/asm_386.s @@ -881,7 +881,7 @@ TEXT runtime·stackcheck(SB), NOSPLIT, $0-0 // func cputicks() int64 TEXT runtime·cputicks(SB),NOSPLIT,$0-8 - CMPB runtime·support_sse2(SB), $1 + CMPB internal∕cpu·X86+const_offset_x86_HasSSE2(SB), $1 JNE done CMPB runtime·lfenceBeforeRdtsc(SB), $1 JNE mfence diff --git a/src/runtime/cpuflags.go b/src/runtime/cpuflags.go new file mode 100644 index 0000000000000..dee6116a90b4b --- /dev/null +++ b/src/runtime/cpuflags.go @@ -0,0 +1,17 @@ +// Copyright 2018 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. + +package runtime + +import ( + "internal/cpu" + "unsafe" +) + +// Offsets into internal/cpu records for use in assembly. +const ( + offset_x86_HasAVX2 = unsafe.Offsetof(cpu.X86.HasAVX2) + offset_x86_HasERMS = unsafe.Offsetof(cpu.X86.HasERMS) + offset_x86_HasSSE2 = unsafe.Offsetof(cpu.X86.HasSSE2) +) diff --git a/src/runtime/cpuflags_amd64.go b/src/runtime/cpuflags_amd64.go index 10ab5f5b00561..8cca4bca8f0b5 100644 --- a/src/runtime/cpuflags_amd64.go +++ b/src/runtime/cpuflags_amd64.go @@ -6,12 +6,6 @@ package runtime import ( "internal/cpu" - "unsafe" -) - -// Offsets into internal/cpu records for use in assembly. -const ( - offsetX86HasAVX2 = unsafe.Offsetof(cpu.X86.HasAVX2) ) var useAVXmemmove bool diff --git a/src/runtime/memclr_386.s b/src/runtime/memclr_386.s index a6703b3641114..318f8839640e2 100644 --- a/src/runtime/memclr_386.s +++ b/src/runtime/memclr_386.s @@ -4,6 +4,7 @@ // +build !plan9 +#include "go_asm.h" #include "textflag.h" // NOTE: Windows externalthreadhandler expects memclr to preserve DX. @@ -28,7 +29,7 @@ tail: JBE _5through8 CMPL BX, $16 JBE _9through16 - CMPB runtime·support_sse2(SB), $1 + CMPB internal∕cpu·X86+const_offset_x86_HasSSE2(SB), $1 JNE nosse2 PXOR X0, X0 CMPL BX, $32 diff --git a/src/runtime/memclr_amd64.s b/src/runtime/memclr_amd64.s index d79078fd00bf5..b64b1477f9365 100644 --- a/src/runtime/memclr_amd64.s +++ b/src/runtime/memclr_amd64.s @@ -38,7 +38,7 @@ tail: JBE _65through128 CMPQ BX, $256 JBE _129through256 - CMPB internal∕cpu·X86+const_offsetX86HasAVX2(SB), $1 + CMPB internal∕cpu·X86+const_offset_x86_HasAVX2(SB), $1 JE loop_preheader_avx2 // TODO: for really big clears, use MOVNTDQ, even without AVX2. diff --git a/src/runtime/memmove_386.s b/src/runtime/memmove_386.s index 172ea40820b30..85c622b6b6283 100644 --- a/src/runtime/memmove_386.s +++ b/src/runtime/memmove_386.s @@ -25,6 +25,7 @@ // +build !plan9 +#include "go_asm.h" #include "textflag.h" // func memmove(to, from unsafe.Pointer, n uintptr) @@ -51,7 +52,7 @@ tail: JBE move_5through8 CMPL BX, $16 JBE move_9through16 - CMPB runtime·support_sse2(SB), $1 + CMPB internal∕cpu·X86+const_offset_x86_HasSSE2(SB), $1 JNE nosse2 CMPL BX, $32 JBE move_17through32 @@ -72,7 +73,7 @@ nosse2: */ forward: // If REP MOVSB isn't fast, don't use it - CMPB runtime·support_erms(SB), $1 // enhanced REP MOVSB/STOSB + CMPB internal∕cpu·X86+const_offset_x86_HasERMS(SB), $1 // enhanced REP MOVSB/STOSB JNE fwdBy4 // Check alignment diff --git a/src/runtime/memmove_amd64.s b/src/runtime/memmove_amd64.s index cb5cd02e45b92..c5385a3d4368a 100644 --- a/src/runtime/memmove_amd64.s +++ b/src/runtime/memmove_amd64.s @@ -25,6 +25,7 @@ // +build !plan9 +#include "go_asm.h" #include "textflag.h" // func memmove(to, from unsafe.Pointer, n uintptr) @@ -83,7 +84,7 @@ forward: JLS move_256through2048 // If REP MOVSB isn't fast, don't use it - CMPB runtime·support_erms(SB), $1 // enhanced REP MOVSB/STOSB + CMPB internal∕cpu·X86+const_offset_x86_HasERMS(SB), $1 // enhanced REP MOVSB/STOSB JNE fwdBy8 // Check alignment diff --git a/src/runtime/proc.go b/src/runtime/proc.go index c9cc7544b8297..75d309a9f66d1 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -507,7 +507,8 @@ func cpuinit() { cpu.Initialize(env) - support_erms = cpu.X86.HasERMS + // Support cpu feature variables are used in code generated by the compiler + // to guard execution of instructions that can not be assumed to be always supported. support_popcnt = cpu.X86.HasPOPCNT support_sse2 = cpu.X86.HasSSE2 support_sse41 = cpu.X86.HasSSE41 diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index bbbe1ee852b94..93119249426d9 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -836,16 +836,15 @@ var ( newprocs int32 // Information about what cpu features are available. - // Set on startup in runtime.cpuinit. // Packages outside the runtime should not use these // as they are not an external api. - // TODO: deprecate these; use internal/cpu directly. + // Set on startup in asm_{386,amd64,amd64p32}.s processorVersionInfo uint32 isIntel bool lfenceBeforeRdtsc bool // Set in runtime.cpuinit. - support_erms bool + // TODO: deprecate these; use internal/cpu directly. support_popcnt bool support_sse2 bool support_sse41 bool From 96dcc4457b9aad418abc0eb4316c21fefdbf08e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Fri, 1 Jun 2018 14:30:49 +0200 Subject: [PATCH 0175/1663] runtime: replace typedmemmmove with bulkBarrierPreWrite and memmove in growslice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bulkBarrierPreWrite together with a memmove as used in typedslicecopy is faster than a typedmemmove for each element of the old slice that needs to be copied to the new slice. typedslicecopy is not used here as runtime functions should not call other instrumented runtime functions and some conditions like dst == src or the destination slice not being large enought that are checked for in typedslicecopy can not happen in growslice. Append 13.5ns ± 6% 13.3ns ± 3% ~ (p=0.304 n=10+10) AppendGrowByte 1.18ms ± 2% 1.19ms ± 1% ~ (p=0.113 n=10+9) AppendGrowString 123ms ± 1% 73ms ± 1% -40.39% (p=0.000 n=9+8) AppendSlice/1Bytes 3.81ns ± 1% 3.78ns ± 1% ~ (p=0.116 n=10+10) AppendSlice/4Bytes 3.71ns ± 1% 3.70ns ± 0% ~ (p=0.095 n=10+9) AppendSlice/7Bytes 3.73ns ± 0% 3.75ns ± 1% ~ (p=0.442 n=10+10) AppendSlice/8Bytes 4.00ns ± 1% 4.01ns ± 1% ~ (p=0.330 n=10+10) AppendSlice/15Bytes 4.29ns ± 1% 4.28ns ± 1% ~ (p=0.536 n=10+10) AppendSlice/16Bytes 4.28ns ± 1% 4.31ns ± 1% +0.75% (p=0.019 n=10+10) AppendSlice/32Bytes 4.57ns ± 2% 4.58ns ± 2% ~ (p=0.236 n=10+10) AppendSliceLarge/1024Bytes 305ns ± 2% 306ns ± 1% ~ (p=0.236 n=10+10) AppendSliceLarge/4096Bytes 1.06µs ± 1% 1.06µs ± 0% ~ (p=1.000 n=9+10) AppendSliceLarge/16384Bytes 3.12µs ± 2% 3.11µs ± 1% ~ (p=0.493 n=10+10) AppendSliceLarge/65536Bytes 5.61µs ± 5% 5.36µs ± 2% -4.58% (p=0.003 n=10+8) AppendSliceLarge/262144Bytes 21.0µs ± 1% 19.5µs ± 1% -7.09% (p=0.000 n=8+10) AppendSliceLarge/1048576Bytes 78.4µs ± 1% 78.7µs ± 2% ~ (p=0.315 n=8+10) AppendStr/1Bytes 3.96ns ± 6% 3.99ns ± 9% ~ (p=0.591 n=10+10) AppendStr/4Bytes 3.98ns ± 1% 3.99ns ± 1% ~ (p=0.515 n=9+9) AppendStr/8Bytes 4.27ns ± 1% 4.27ns ± 1% ~ (p=0.633 n=10+10) AppendStr/16Bytes 4.56ns ± 2% 4.55ns ± 1% ~ (p=0.869 n=10+10) AppendStr/32Bytes 4.85ns ± 1% 4.89ns ± 1% +0.71% (p=0.003 n=10+8) AppendSpecialCase 18.7ns ± 1% 18.7ns ± 1% ~ (p=0.144 n=10+10) AppendInPlace/NoGrow/Byte 438ns ± 1% 439ns ± 1% ~ (p=0.135 n=10+8) AppendInPlace/NoGrow/1Ptr 1.05µs ± 2% 1.05µs ± 1% ~ (p=0.469 n=10+10) AppendInPlace/NoGrow/2Ptr 1.77µs ± 1% 1.78µs ± 2% ~ (p=0.469 n=10+10) AppendInPlace/NoGrow/3Ptr 1.94µs ± 1% 1.93µs ± 2% ~ (p=0.517 n=10+10) AppendInPlace/NoGrow/4Ptr 3.18µs ± 1% 3.17µs ± 0% ~ (p=0.483 n=10+9) AppendInPlace/Grow/Byte 382ns ± 2% 383ns ± 2% ~ (p=0.705 n=9+10) AppendInPlace/Grow/1Ptr 383ns ± 1% 384ns ± 1% ~ (p=0.844 n=10+10) AppendInPlace/Grow/2Ptr 459ns ± 2% 467ns ± 2% +1.74% (p=0.001 n=10+10) AppendInPlace/Grow/3Ptr 593ns ± 1% 597ns ± 2% ~ (p=0.195 n=10+10) AppendInPlace/Grow/4Ptr 583ns ± 2% 589ns ± 2% ~ (p=0.084 n=10+10) Change-Id: I629872f065a22b29267c1adbfc578aaedd36d365 Reviewed-on: https://go-review.googlesource.com/115755 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/runtime/mbarrier.go | 2 -- src/runtime/slice.go | 10 +++------- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/src/runtime/mbarrier.go b/src/runtime/mbarrier.go index b6c5ee0658061..5142f4327a2a4 100644 --- a/src/runtime/mbarrier.go +++ b/src/runtime/mbarrier.go @@ -226,8 +226,6 @@ func reflectcallmove(typ *_type, dst, src unsafe.Pointer, size uintptr) { //go:nosplit func typedslicecopy(typ *_type, dst, src slice) int { - // TODO(rsc): If typedslicecopy becomes faster than calling - // typedmemmove repeatedly, consider using during func growslice. n := dst.len if n > src.len { n = src.len diff --git a/src/runtime/slice.go b/src/runtime/slice.go index fd5d08b52c103..737aab5704060 100644 --- a/src/runtime/slice.go +++ b/src/runtime/slice.go @@ -195,21 +195,17 @@ func growslice(et *_type, old slice, cap int) slice { var p unsafe.Pointer if et.kind&kindNoPointers != 0 { p = mallocgc(capmem, nil, false) - memmove(p, old.array, lenmem) // The append() that calls growslice is going to overwrite from old.len to cap (which will be the new length). // Only clear the part that will not be overwritten. memclrNoHeapPointers(add(p, newlenmem), capmem-newlenmem) } else { // Note: can't use rawmem (which avoids zeroing of memory), because then GC can scan uninitialized memory. p = mallocgc(capmem, et, true) - if !writeBarrier.enabled { - memmove(p, old.array, lenmem) - } else { - for i := uintptr(0); i < lenmem; i += et.size { - typedmemmove(et, add(p, i), add(old.array, i)) - } + if writeBarrier.enabled { + bulkBarrierPreWrite(uintptr(p), uintptr(old.array), lenmem) } } + memmove(p, old.array, lenmem) return slice{p, old.len, newcap} } From 4363c98f62e9e315ed20b12d2ce47021fd2bf7bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Sun, 3 Jun 2018 13:00:19 +0200 Subject: [PATCH 0176/1663] runtime: do not execute write barrier on newly allocated slice in growslice MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new slice created in growslice is cleared during malloc for element types containing pointers and therefore can only contain nil pointers. This change avoids executing write barriers for these nil pointers by adding and using a special bulkBarrierPreWriteSrcOnly function that does not enqueue pointers to slots in dst to the write barrier buffer. Change-Id: If9b18248bfeeb6a874b0132d19520adea593bfc4 Reviewed-on: https://go-review.googlesource.com/115996 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/runtime/mbitmap.go | 29 +++++++++++++++++++++++++++++ src/runtime/slice.go | 4 +++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/runtime/mbitmap.go b/src/runtime/mbitmap.go index 75f23a16b413d..e217e7695fdd4 100644 --- a/src/runtime/mbitmap.go +++ b/src/runtime/mbitmap.go @@ -647,6 +647,35 @@ func bulkBarrierPreWrite(dst, src, size uintptr) { } } +// bulkBarrierPreWriteSrcOnly is like bulkBarrierPreWrite but +// does not execute write barriers for [dst, dst+size). +// +// In addition to the requirements of bulkBarrierPreWrite +// callers need to ensure [dst, dst+size) is zeroed. +// +// This is used for special cases where e.g. dst was just +// created and zeroed with malloc. +//go:nosplit +func bulkBarrierPreWriteSrcOnly(dst, src, size uintptr) { + if (dst|src|size)&(sys.PtrSize-1) != 0 { + throw("bulkBarrierPreWrite: unaligned arguments") + } + if !writeBarrier.needed { + return + } + buf := &getg().m.p.ptr().wbBuf + h := heapBitsForAddr(dst) + for i := uintptr(0); i < size; i += sys.PtrSize { + if h.isPointer() { + srcx := (*uintptr)(unsafe.Pointer(src + i)) + if !buf.putFast(0, *srcx) { + wbBufFlush(nil, 0) + } + } + h = h.next() + } +} + // bulkBarrierBitmap executes write barriers for copying from [src, // src+size) to [dst, dst+size) using a 1-bit pointer bitmap. src is // assumed to start maskOffset bytes into the data covered by the diff --git a/src/runtime/slice.go b/src/runtime/slice.go index 737aab5704060..4206f4384af62 100644 --- a/src/runtime/slice.go +++ b/src/runtime/slice.go @@ -202,7 +202,9 @@ func growslice(et *_type, old slice, cap int) slice { // Note: can't use rawmem (which avoids zeroing of memory), because then GC can scan uninitialized memory. p = mallocgc(capmem, et, true) if writeBarrier.enabled { - bulkBarrierPreWrite(uintptr(p), uintptr(old.array), lenmem) + // Only shade the pointers in old.array since we know the destination slice p + // only contains nil pointers because it has been cleared during alloc. + bulkBarrierPreWriteSrcOnly(uintptr(p), uintptr(old.array), lenmem) } } memmove(p, old.array, lenmem) From 2e8c31b3d2afce1c1c7b0c6af9cc4a9f296af299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Sun, 27 May 2018 08:49:36 +0200 Subject: [PATCH 0177/1663] runtime: move arm hardware division support detection to internal/cpu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Assumes mandatory VFP and VFPv3 support to be present by default but not IDIVA if AT_HWCAP is not available. Adds GODEBUGCPU options to disable the use of code paths in the runtime that use hardware support for division. Change-Id: Ida02311bd9b9701de3fc120697e69445bf6c0853 Reviewed-on: https://go-review.googlesource.com/114826 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor Reviewed-by: Keith Randall --- src/internal/cpu/cpu.go | 10 ++++++++++ src/internal/cpu/cpu_arm.go | 25 +++++++++++++++++++++++++ src/internal/cpu/cpu_no_init.go | 1 + src/runtime/cpuflags.go | 2 ++ src/runtime/os_darwin_arm.go | 2 -- src/runtime/os_freebsd.go | 1 + src/runtime/os_freebsd_arm.go | 25 +++++++++++++++++-------- src/runtime/os_linux_arm.go | 19 ++++++++++--------- src/runtime/os_nacl_arm.go | 2 -- src/runtime/os_netbsd_arm.go | 2 -- src/runtime/os_openbsd_arm.go | 2 -- src/runtime/os_plan9_arm.go | 2 -- src/runtime/vlop_arm.s | 2 +- 13 files changed, 67 insertions(+), 28 deletions(-) diff --git a/src/internal/cpu/cpu.go b/src/internal/cpu/cpu.go index f2dfadbff8390..2b5db91fe2b22 100644 --- a/src/internal/cpu/cpu.go +++ b/src/internal/cpu/cpu.go @@ -66,6 +66,16 @@ type ppc64 struct { _ CacheLinePad } +var ARM arm + +// The booleans in arm contain the correspondingly named cpu feature bit. +// The struct is padded to avoid false sharing. +type arm struct { + _ CacheLinePad + HasIDIVA bool + _ CacheLinePad +} + var ARM64 arm64 // The booleans in arm64 contain the correspondingly named cpu feature bit. diff --git a/src/internal/cpu/cpu_arm.go b/src/internal/cpu/cpu_arm.go index 078a6c3b80a28..b9baa44fea6f0 100644 --- a/src/internal/cpu/cpu_arm.go +++ b/src/internal/cpu/cpu_arm.go @@ -5,3 +5,28 @@ package cpu const CacheLineSize = 32 + +// arm doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2. +// These are linknamed in runtime/os_(linux|freebsd)_arm.go and are +// initialized by archauxv(). +// These should not be changed after they are initialized. +var HWCap uint +var HWCap2 uint + +// HWCAP/HWCAP2 bits. These are exposed by Linux and FreeBSD. +const ( + hwcap_IDIVA = 1 << 17 +) + +func doinit() { + options = []option{ + {"idiva", &ARM.HasIDIVA}, + } + + // HWCAP feature bits + ARM.HasIDIVA = isSet(HWCap, hwcap_IDIVA) +} + +func isSet(hwc uint, value uint) bool { + return hwc&value != 0 +} diff --git a/src/internal/cpu/cpu_no_init.go b/src/internal/cpu/cpu_no_init.go index 1be4f29dddd98..777ea9de8bdbf 100644 --- a/src/internal/cpu/cpu_no_init.go +++ b/src/internal/cpu/cpu_no_init.go @@ -5,6 +5,7 @@ // +build !386 // +build !amd64 // +build !amd64p32 +// +build !arm // +build !arm64 // +build !ppc64 // +build !ppc64le diff --git a/src/runtime/cpuflags.go b/src/runtime/cpuflags.go index dee6116a90b4b..050168c2d7303 100644 --- a/src/runtime/cpuflags.go +++ b/src/runtime/cpuflags.go @@ -14,4 +14,6 @@ const ( offset_x86_HasAVX2 = unsafe.Offsetof(cpu.X86.HasAVX2) offset_x86_HasERMS = unsafe.Offsetof(cpu.X86.HasERMS) offset_x86_HasSSE2 = unsafe.Offsetof(cpu.X86.HasSSE2) + + offset_arm_HasIDIVA = unsafe.Offsetof(cpu.ARM.HasIDIVA) ) diff --git a/src/runtime/os_darwin_arm.go b/src/runtime/os_darwin_arm.go index 8eb5655969c71..ee1bd174f1be6 100644 --- a/src/runtime/os_darwin_arm.go +++ b/src/runtime/os_darwin_arm.go @@ -4,8 +4,6 @@ package runtime -var hardDiv bool // TODO: set if a hardware divider is available - func checkgoarm() { // TODO(minux): FP checks like in os_linux_arm.go. diff --git a/src/runtime/os_freebsd.go b/src/runtime/os_freebsd.go index 631dc20ab46ac..08f7b0ecf047f 100644 --- a/src/runtime/os_freebsd.go +++ b/src/runtime/os_freebsd.go @@ -389,6 +389,7 @@ const ( _AT_PAGESZ = 6 // Page size in bytes _AT_TIMEKEEP = 22 // Pointer to timehands. _AT_HWCAP = 25 // CPU feature flags + _AT_HWCAP2 = 26 // CPU feature flags 2 ) func sysauxv(auxv []uintptr) { diff --git a/src/runtime/os_freebsd_arm.go b/src/runtime/os_freebsd_arm.go index d2dc26f0c4f40..eb4de9bc2123d 100644 --- a/src/runtime/os_freebsd_arm.go +++ b/src/runtime/os_freebsd_arm.go @@ -4,22 +4,29 @@ package runtime +import "internal/cpu" + const ( _HWCAP_VFP = 1 << 6 _HWCAP_VFPv3 = 1 << 13 - _HWCAP_IDIVA = 1 << 17 ) -var hwcap = ^uint32(0) // set by archauxv -var hardDiv bool // set if a hardware divider is available +// AT_HWCAP is not available on FreeBSD-11.1-RELEASE or earlier. +// Default to mandatory VFP hardware support for arm being available. +// If AT_HWCAP is available goarmHWCap will be updated in archauxv. +// TODO(moehrmann) remove once all go supported FreeBSD versions support _AT_HWCAP. +var goarmHWCap uint = (_HWCAP_VFP | _HWCAP_VFPv3) func checkgoarm() { - if goarm > 5 && hwcap&_HWCAP_VFP == 0 { + // Update cpu.HWCap to match goarmHWCap in case they were not updated in archauxv. + cpu.HWCap = goarmHWCap + + if goarm > 5 && cpu.HWCap&_HWCAP_VFP == 0 { print("runtime: this CPU has no floating point hardware, so it cannot run\n") print("this GOARM=", goarm, " binary. Recompile using GOARM=5.\n") exit(1) } - if goarm > 6 && hwcap&_HWCAP_VFPv3 == 0 { + if goarm > 6 && cpu.HWCap&_HWCAP_VFPv3 == 0 { print("runtime: this CPU has no VFPv3 floating point hardware, so it cannot run\n") print("this GOARM=", goarm, " binary. Recompile using GOARM=5 or GOARM=6.\n") exit(1) @@ -35,9 +42,11 @@ func checkgoarm() { func archauxv(tag, val uintptr) { switch tag { - case _AT_HWCAP: // CPU capability bit flags - hwcap = uint32(val) - hardDiv = (hwcap & _HWCAP_IDIVA) != 0 + case _AT_HWCAP: + cpu.HWCap = uint(val) + goarmHWCap = cpu.HWCap + case _AT_HWCAP2: + cpu.HWCap2 = uint(val) } } diff --git a/src/runtime/os_linux_arm.go b/src/runtime/os_linux_arm.go index 14f1cfeaefb5d..8f082ba6a0ac4 100644 --- a/src/runtime/os_linux_arm.go +++ b/src/runtime/os_linux_arm.go @@ -4,20 +4,20 @@ package runtime -import "unsafe" +import ( + "internal/cpu" + "unsafe" +) const ( _AT_PLATFORM = 15 // introduced in at least 2.6.11 _HWCAP_VFP = 1 << 6 // introduced in at least 2.6.11 _HWCAP_VFPv3 = 1 << 13 // introduced in 2.6.30 - _HWCAP_IDIVA = 1 << 17 ) var randomNumber uint32 var armArch uint8 = 6 // we default to ARMv6 -var hwcap uint32 // set by archauxv -var hardDiv bool // set if a hardware divider is available func checkgoarm() { // On Android, /proc/self/auxv might be unreadable and hwcap won't @@ -26,12 +26,12 @@ func checkgoarm() { if GOOS == "android" { return } - if goarm > 5 && hwcap&_HWCAP_VFP == 0 { + if goarm > 5 && cpu.HWCap&_HWCAP_VFP == 0 { print("runtime: this CPU has no floating point hardware, so it cannot run\n") print("this GOARM=", goarm, " binary. Recompile using GOARM=5.\n") exit(1) } - if goarm > 6 && hwcap&_HWCAP_VFPv3 == 0 { + if goarm > 6 && cpu.HWCap&_HWCAP_VFPv3 == 0 { print("runtime: this CPU has no VFPv3 floating point hardware, so it cannot run\n") print("this GOARM=", goarm, " binary. Recompile using GOARM=5 or GOARM=6.\n") exit(1) @@ -53,9 +53,10 @@ func archauxv(tag, val uintptr) { armArch = t - '0' } - case _AT_HWCAP: // CPU capability bit flags - hwcap = uint32(val) - hardDiv = (hwcap & _HWCAP_IDIVA) != 0 + case _AT_HWCAP: + cpu.HWCap = uint(val) + case _AT_HWCAP2: + cpu.HWCap2 = uint(val) } } diff --git a/src/runtime/os_nacl_arm.go b/src/runtime/os_nacl_arm.go index c64ebf31d3562..8669ee75b46c9 100644 --- a/src/runtime/os_nacl_arm.go +++ b/src/runtime/os_nacl_arm.go @@ -4,8 +4,6 @@ package runtime -var hardDiv bool // TODO: set if a hardware divider is available - func checkgoarm() { // TODO(minux): FP checks like in os_linux_arm.go. diff --git a/src/runtime/os_netbsd_arm.go b/src/runtime/os_netbsd_arm.go index b02e36a73ab46..95603da64394b 100644 --- a/src/runtime/os_netbsd_arm.go +++ b/src/runtime/os_netbsd_arm.go @@ -6,8 +6,6 @@ package runtime import "unsafe" -var hardDiv bool // TODO: set if a hardware divider is available - func lwp_mcontext_init(mc *mcontextt, stk unsafe.Pointer, mp *m, gp *g, fn uintptr) { // Machine dependent mcontext initialisation for LWP. mc.__gregs[_REG_R15] = uint32(funcPC(lwp_tramp)) diff --git a/src/runtime/os_openbsd_arm.go b/src/runtime/os_openbsd_arm.go index c318578ab50e2..be2e1e9959da6 100644 --- a/src/runtime/os_openbsd_arm.go +++ b/src/runtime/os_openbsd_arm.go @@ -4,8 +4,6 @@ package runtime -var hardDiv bool // TODO: set if a hardware divider is available - func checkgoarm() { // TODO(minux): FP checks like in os_linux_arm.go. diff --git a/src/runtime/os_plan9_arm.go b/src/runtime/os_plan9_arm.go index 1ce0141ce25b8..fdce1e7a352d6 100644 --- a/src/runtime/os_plan9_arm.go +++ b/src/runtime/os_plan9_arm.go @@ -4,8 +4,6 @@ package runtime -var hardDiv bool // TODO: set if a hardware divider is available - func checkgoarm() { return // TODO(minux) } diff --git a/src/runtime/vlop_arm.s b/src/runtime/vlop_arm.s index d48e515d32cb3..8df13abd98820 100644 --- a/src/runtime/vlop_arm.s +++ b/src/runtime/vlop_arm.s @@ -44,7 +44,7 @@ // the RET instruction will clobber R12 on nacl, and the compiler's register // allocator needs to know. TEXT runtime·udiv(SB),NOSPLIT|NOFRAME,$0 - MOVBU runtime·hardDiv(SB), Ra + MOVBU internal∕cpu·ARM+const_offset_arm_HasIDIVA(SB), Ra CMP $0, Ra BNE udiv_hardware From e6c15945dee0661dee6111183d4951853c4c2d98 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 23 Aug 2018 16:33:53 +0200 Subject: [PATCH 0178/1663] syscall, os: use pipe2 syscall on DragonflyBSD instead of pipe Follow the implementation used by the other BSDs ith os.Pipe and syscall.forkExecPipe consisting of a single syscall instead of three. Change-Id: I602187672f244cbd8faaa3397904d71d15452d9f Reviewed-on: https://go-review.googlesource.com/130996 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/os/pipe2_bsd.go | 2 +- src/os/pipe_bsd.go | 2 +- src/syscall/forkpipe.go | 2 +- src/syscall/forkpipe2.go | 2 +- src/syscall/syscall_dragonfly.go | 10 +++++++--- src/syscall/zsyscall_dragonfly_amd64.go | 4 ++-- src/syscall/zsysnum_dragonfly_amd64.go | 1 + 7 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/os/pipe2_bsd.go b/src/os/pipe2_bsd.go index 0ef894b476bed..7d2d9e8ffd9f0 100644 --- a/src/os/pipe2_bsd.go +++ b/src/os/pipe2_bsd.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build freebsd netbsd openbsd +// +build dragonfly freebsd netbsd openbsd package os diff --git a/src/os/pipe_bsd.go b/src/os/pipe_bsd.go index 9735988f324d3..6fd10dbc1a1f9 100644 --- a/src/os/pipe_bsd.go +++ b/src/os/pipe_bsd.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly js,wasm nacl solaris +// +build darwin js,wasm nacl solaris package os diff --git a/src/syscall/forkpipe.go b/src/syscall/forkpipe.go index 71890a29badcc..55777497b1012 100644 --- a/src/syscall/forkpipe.go +++ b/src/syscall/forkpipe.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin dragonfly solaris +// +build darwin solaris package syscall diff --git a/src/syscall/forkpipe2.go b/src/syscall/forkpipe2.go index c9a0c4996e3bb..0078f4bbabd24 100644 --- a/src/syscall/forkpipe2.go +++ b/src/syscall/forkpipe2.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build freebsd netbsd openbsd +// +build dragonfly freebsd netbsd openbsd package syscall diff --git a/src/syscall/syscall_dragonfly.go b/src/syscall/syscall_dragonfly.go index 3dbbe342cfbb2..d59f139446e4f 100644 --- a/src/syscall/syscall_dragonfly.go +++ b/src/syscall/syscall_dragonfly.go @@ -72,13 +72,17 @@ func direntNamlen(buf []byte) (uint64, bool) { return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen)) } -//sysnb pipe() (r int, w int, err error) +func Pipe(p []int) error { + return Pipe2(p, 0) +} + +//sysnb pipe2(flags int) (r int, w int, err error) -func Pipe(p []int) (err error) { +func Pipe2(p []int, flags int) (err error) { if len(p) != 2 { return EINVAL } - p[0], p[1], err = pipe() + p[0], p[1], err = pipe2(flags) return } diff --git a/src/syscall/zsyscall_dragonfly_amd64.go b/src/syscall/zsyscall_dragonfly_amd64.go index 578b5a3e9e4b9..f9ed33aae8032 100644 --- a/src/syscall/zsyscall_dragonfly_amd64.go +++ b/src/syscall/zsyscall_dragonfly_amd64.go @@ -261,8 +261,8 @@ func fcntl(fd int, cmd int, arg int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func pipe() (r int, w int, err error) { - r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) +func pipe2(flags int) (r int, w int, err error) { + r0, r1, e1 := RawSyscall(SYS_PIPE2, uintptr(flags), 0, 0) r = int(r0) w = int(r1) if e1 != 0 { diff --git a/src/syscall/zsysnum_dragonfly_amd64.go b/src/syscall/zsysnum_dragonfly_amd64.go index 9ce11f5899f9f..58582b9e7a485 100644 --- a/src/syscall/zsysnum_dragonfly_amd64.go +++ b/src/syscall/zsysnum_dragonfly_amd64.go @@ -301,6 +301,7 @@ const ( SYS_LPATHCONF = 533 // { int lpathconf(char *path, int name); } SYS_VMM_GUEST_CTL = 534 // { int vmm_guest_ctl(int op, struct vmm_guest_options *options); } SYS_VMM_GUEST_SYNC_ADDR = 535 // { int vmm_guest_sync_addr(long *dstaddr, long *srcaddr); } + SYS_PIPE2 = 538 // { int pipe2(int *fildes, int flags); } SYS_UTIMENSAT = 539 // { int utimensat(int fd, const char *path, const struct timespec *ts, int flags); } SYS_ACCEPT4 = 541 // { int accept4(int s, caddr_t name, int *anamelen, int flags); } ) From 38143badf1d7244f1015286ba2d2d540a3a78d69 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Wed, 22 Aug 2018 10:58:24 +0200 Subject: [PATCH 0179/1663] time: allow +00 as numeric timezone name and GMT offset A timezone with a zero offset from UTC and without a three-letter abbreviation will have a numeric name in timestamps: "+00". There are currently two of them: $ zdump Atlantic/Azores America/Scoresbysund Atlantic/Azores Wed Aug 22 09:01:05 2018 +00 America/Scoresbysund Wed Aug 22 09:01:05 2018 +00 These two timestamp are rejected by Parse, since it doesn't allow for zero offsets: parsing time "Wed Aug 22 09:01:05 2018 +00": extra text: +00 This change modifies Parse to accept a +00 offset in numeric timezone names. As side effect of this change, Parse also now accepts "GMT+00". It was explicitely disallowed (with a unit test ensuring it got rejected), but the restriction seems incorrect. DATE(1), for example, allows it: $ date --debug --date="2009-01-02 03:04:05 GMT+00" date: parsed date part: (Y-M-D) 2009-01-02 date: parsed time part: 03:04:05 date: parsed zone part: UTC+00 date: input timezone: parsed date/time string (+00) date: using specified time as starting value: '03:04:05' date: starting date/time: '(Y-M-D) 2009-01-02 03:04:05 TZ=+00' date: '(Y-M-D) 2009-01-02 03:04:05 TZ=+00' = 1230865445 epoch-seconds date: timezone: system default date: final: 1230865445.000000000 (epoch-seconds) date: final: (Y-M-D) 2009-01-02 03:04:05 (UTC) date: final: (Y-M-D) 2009-01-02 04:04:05 (UTC+01) Fri 2 Jan 04:04:05 CET 2009 This fixes 2 of 17 time.Parse() failures listed in Issue #26032. Updates #26032 Change-Id: I01cd067044371322b7bb1dae452fb3c758ed3cc2 Reviewed-on: https://go-review.googlesource.com/130696 Run-TryBot: Alberto Donizetti TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/time/format.go | 6 ++++-- src/time/format_test.go | 7 ++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/time/format.go b/src/time/format.go index f9cdbab3b8f31..2adbbe07706d8 100644 --- a/src/time/format.go +++ b/src/time/format.go @@ -1172,13 +1172,15 @@ func parseSignedOffset(value string) int { return 0 } x, rem, err := leadingInt(value[1:]) - if err != nil { + + // fail if nothing consumed by leadingInt + if err != nil || value[1:] == rem { return 0 } if sign == '-' { x = -x } - if x == 0 || x < -23 || 23 < x { + if x < -23 || 23 < x { return 0 } return len(value) - len(rem) diff --git a/src/time/format_test.go b/src/time/format_test.go index c3552f4161361..db9d4f495ac93 100644 --- a/src/time/format_test.go +++ b/src/time/format_test.go @@ -416,7 +416,11 @@ var parseTimeZoneTests = []ParseTimeZoneTest{ {"gmt hi there", 0, false}, {"GMT hi there", 3, true}, {"GMT+12 hi there", 6, true}, - {"GMT+00 hi there", 3, true}, // 0 or 00 is not a legal offset. + {"GMT+00 hi there", 6, true}, + {"GMT+", 3, true}, + {"GMT+3", 5, true}, + {"GMT+a", 3, true}, + {"GMT+3a", 5, true}, {"GMT-5 hi there", 5, true}, {"GMT-51 hi there", 3, true}, {"ChST hi there", 4, true}, @@ -431,6 +435,7 @@ var parseTimeZoneTests = []ParseTimeZoneTest{ {"+03 hi", 3, true}, {"-04 hi", 3, true}, // Issue #26032 + {"+00", 3, true}, {"-11", 3, true}, {"-12", 3, true}, {"-23", 3, true}, From 60f83621fc357f9e838bee9811230339b9da493a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Fri, 24 Aug 2018 17:07:20 +0200 Subject: [PATCH 0180/1663] internal/cpu: add a CacheLinePadSize constant The new constant CacheLinePadSize can be used to compute best effort alignment of structs to cache lines. e.g. the runtime can use this in the locktab definition: var locktab [57]struct { l spinlock pad [cpu.CacheLinePadSize - unsafe.Sizeof(spinlock{})]byte } Change-Id: I86f6fbfc5ee7436f742776a7d4a99a1d54ffccc8 Reviewed-on: https://go-review.googlesource.com/131237 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/internal/cpu/cpu.go | 7 ++++++- src/internal/cpu/cpu_arm.go | 2 +- src/internal/cpu/cpu_arm64.go | 2 +- src/internal/cpu/cpu_mips.go | 2 +- src/internal/cpu/cpu_mips64.go | 2 +- src/internal/cpu/cpu_mips64le.go | 2 +- src/internal/cpu/cpu_mipsle.go | 2 +- src/internal/cpu/cpu_ppc64x.go | 2 +- src/internal/cpu/cpu_s390x.go | 2 +- src/internal/cpu/cpu_wasm.go | 2 +- src/internal/cpu/cpu_x86.go | 2 +- 11 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/internal/cpu/cpu.go b/src/internal/cpu/cpu.go index 2b5db91fe2b22..5363f11b90839 100644 --- a/src/internal/cpu/cpu.go +++ b/src/internal/cpu/cpu.go @@ -12,7 +12,12 @@ package cpu var DebugOptions bool // CacheLinePad is used to pad structs to avoid false sharing. -type CacheLinePad struct{ _ [CacheLineSize]byte } +type CacheLinePad struct{ _ [CacheLinePadSize]byte } + +// CacheLineSize is the CPU's assumed cache line size. +// There is currently no runtime detection of the real cache line size +// so we use the constant per GOARCH CacheLinePadSize as an approximation. +var CacheLineSize = CacheLinePadSize var X86 x86 diff --git a/src/internal/cpu/cpu_arm.go b/src/internal/cpu/cpu_arm.go index b9baa44fea6f0..6a5b30580c94e 100644 --- a/src/internal/cpu/cpu_arm.go +++ b/src/internal/cpu/cpu_arm.go @@ -4,7 +4,7 @@ package cpu -const CacheLineSize = 32 +const CacheLinePadSize = 32 // arm doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2. // These are linknamed in runtime/os_(linux|freebsd)_arm.go and are diff --git a/src/internal/cpu/cpu_arm64.go b/src/internal/cpu/cpu_arm64.go index 77b617e49f18b..ad930af005f11 100644 --- a/src/internal/cpu/cpu_arm64.go +++ b/src/internal/cpu/cpu_arm64.go @@ -4,7 +4,7 @@ package cpu -const CacheLineSize = 64 +const CacheLinePadSize = 64 // arm64 doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2. // These are initialized by archauxv in runtime/os_linux_arm64.go. diff --git a/src/internal/cpu/cpu_mips.go b/src/internal/cpu/cpu_mips.go index 078a6c3b80a28..0f821e44e7798 100644 --- a/src/internal/cpu/cpu_mips.go +++ b/src/internal/cpu/cpu_mips.go @@ -4,4 +4,4 @@ package cpu -const CacheLineSize = 32 +const CacheLinePadSize = 32 diff --git a/src/internal/cpu/cpu_mips64.go b/src/internal/cpu/cpu_mips64.go index 078a6c3b80a28..0f821e44e7798 100644 --- a/src/internal/cpu/cpu_mips64.go +++ b/src/internal/cpu/cpu_mips64.go @@ -4,4 +4,4 @@ package cpu -const CacheLineSize = 32 +const CacheLinePadSize = 32 diff --git a/src/internal/cpu/cpu_mips64le.go b/src/internal/cpu/cpu_mips64le.go index 078a6c3b80a28..0f821e44e7798 100644 --- a/src/internal/cpu/cpu_mips64le.go +++ b/src/internal/cpu/cpu_mips64le.go @@ -4,4 +4,4 @@ package cpu -const CacheLineSize = 32 +const CacheLinePadSize = 32 diff --git a/src/internal/cpu/cpu_mipsle.go b/src/internal/cpu/cpu_mipsle.go index 078a6c3b80a28..0f821e44e7798 100644 --- a/src/internal/cpu/cpu_mipsle.go +++ b/src/internal/cpu/cpu_mipsle.go @@ -4,4 +4,4 @@ package cpu -const CacheLineSize = 32 +const CacheLinePadSize = 32 diff --git a/src/internal/cpu/cpu_ppc64x.go b/src/internal/cpu/cpu_ppc64x.go index d3f02efa7ff61..0195e663c60d7 100644 --- a/src/internal/cpu/cpu_ppc64x.go +++ b/src/internal/cpu/cpu_ppc64x.go @@ -6,7 +6,7 @@ package cpu -const CacheLineSize = 128 +const CacheLinePadSize = 128 // ppc64x doesn't have a 'cpuid' equivalent, so we rely on HWCAP/HWCAP2. // These are initialized by archauxv in runtime/os_linux_ppc64x.go. diff --git a/src/internal/cpu/cpu_s390x.go b/src/internal/cpu/cpu_s390x.go index 0a12922045e4d..23484b2950878 100644 --- a/src/internal/cpu/cpu_s390x.go +++ b/src/internal/cpu/cpu_s390x.go @@ -4,7 +4,7 @@ package cpu -const CacheLineSize = 256 +const CacheLinePadSize = 256 // bitIsSet reports whether the bit at index is set. The bit index // is in big endian order, so bit index 0 is the leftmost bit. diff --git a/src/internal/cpu/cpu_wasm.go b/src/internal/cpu/cpu_wasm.go index 1107a7ad6f7ad..b459738770510 100644 --- a/src/internal/cpu/cpu_wasm.go +++ b/src/internal/cpu/cpu_wasm.go @@ -4,4 +4,4 @@ package cpu -const CacheLineSize = 64 +const CacheLinePadSize = 64 diff --git a/src/internal/cpu/cpu_x86.go b/src/internal/cpu/cpu_x86.go index 7d9d3aaf76028..0b00779a90641 100644 --- a/src/internal/cpu/cpu_x86.go +++ b/src/internal/cpu/cpu_x86.go @@ -6,7 +6,7 @@ package cpu -const CacheLineSize = 64 +const CacheLinePadSize = 64 // cpuid is implemented in cpu_x86.s. func cpuid(eaxArg, ecxArg uint32) (eax, ebx, ecx, edx uint32) From 2200b18258874ba61771ea78d5fbee99ba6fe71f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Mon, 20 Aug 2018 21:31:49 +0100 Subject: [PATCH 0181/1663] cmd/compile: cleanup walking OCONV/OCONVNOP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a separate func, which needs less indentation and can use returns instead of labelled breaks. We can also give the types better names, and we don't have to repeat the calls to conv and mkcall. Passes toolstash -cmp on std cmd. Change-Id: I1071c170fa729562d70093a09b7dea003c5fe26e Reviewed-on: https://go-review.googlesource.com/130075 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/gc/walk.go | 107 +++++++++++++--------------- 1 file changed, 51 insertions(+), 56 deletions(-) diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 33a95528056ac..bd936fb70a038 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -1022,64 +1022,13 @@ opswitch: n = walkexpr(n, init) case OCONV, OCONVNOP: - if thearch.SoftFloat { - // For the soft-float case, ssa.go handles these conversions. - n.Left = walkexpr(n.Left, init) + n.Left = walkexpr(n.Left, init) + param, result := rtconvfn(n.Left.Type, n.Type) + if param == Txxx { break } - switch thearch.LinkArch.Family { - case sys.ARM, sys.MIPS: - if n.Left.Type.IsFloat() { - switch n.Type.Etype { - case TINT64: - n = mkcall("float64toint64", n.Type, init, conv(n.Left, types.Types[TFLOAT64])) - break opswitch - case TUINT64: - n = mkcall("float64touint64", n.Type, init, conv(n.Left, types.Types[TFLOAT64])) - break opswitch - } - } - - if n.Type.IsFloat() { - switch n.Left.Type.Etype { - case TINT64: - n = conv(mkcall("int64tofloat64", types.Types[TFLOAT64], init, conv(n.Left, types.Types[TINT64])), n.Type) - break opswitch - case TUINT64: - n = conv(mkcall("uint64tofloat64", types.Types[TFLOAT64], init, conv(n.Left, types.Types[TUINT64])), n.Type) - break opswitch - } - } - - case sys.I386: - if n.Left.Type.IsFloat() { - switch n.Type.Etype { - case TINT64: - n = mkcall("float64toint64", n.Type, init, conv(n.Left, types.Types[TFLOAT64])) - break opswitch - case TUINT64: - n = mkcall("float64touint64", n.Type, init, conv(n.Left, types.Types[TFLOAT64])) - break opswitch - case TUINT32, TUINT, TUINTPTR: - n = mkcall("float64touint32", n.Type, init, conv(n.Left, types.Types[TFLOAT64])) - break opswitch - } - } - if n.Type.IsFloat() { - switch n.Left.Type.Etype { - case TINT64: - n = conv(mkcall("int64tofloat64", types.Types[TFLOAT64], init, conv(n.Left, types.Types[TINT64])), n.Type) - break opswitch - case TUINT64: - n = conv(mkcall("uint64tofloat64", types.Types[TFLOAT64], init, conv(n.Left, types.Types[TUINT64])), n.Type) - break opswitch - case TUINT32, TUINT, TUINTPTR: - n = conv(mkcall("uint32tofloat64", types.Types[TFLOAT64], init, conv(n.Left, types.Types[TUINT32])), n.Type) - break opswitch - } - } - } - n.Left = walkexpr(n.Left, init) + fn := basicnames[param] + "to" + basicnames[result] + n = conv(mkcall(fn, types.Types[result], init, conv(n.Left, types.Types[param])), n.Type) case OANDNOT: n.Left = walkexpr(n.Left, init) @@ -1771,6 +1720,52 @@ opswitch: return n } +// rtconvfn returns the parameter and result types that will be used by a +// runtime function to convert from type src to type dst. The runtime function +// name can be derived from the names of the returned types. +// +// If no such function is necessary, it returns (Txxx, Txxx). +func rtconvfn(src, dst *types.Type) (param, result types.EType) { + if thearch.SoftFloat { + return Txxx, Txxx + } + + switch thearch.LinkArch.Family { + case sys.ARM, sys.MIPS: + if src.IsFloat() { + switch dst.Etype { + case TINT64, TUINT64: + return TFLOAT64, dst.Etype + } + } + if dst.IsFloat() { + switch src.Etype { + case TINT64, TUINT64: + return src.Etype, TFLOAT64 + } + } + + case sys.I386: + if src.IsFloat() { + switch dst.Etype { + case TINT64, TUINT64: + return TFLOAT64, dst.Etype + case TUINT32, TUINT, TUINTPTR: + return TFLOAT64, TUINT32 + } + } + if dst.IsFloat() { + switch src.Etype { + case TINT64, TUINT64: + return src.Etype, TFLOAT64 + case TUINT32, TUINT, TUINTPTR: + return TUINT32, TFLOAT64 + } + } + } + return Txxx, Txxx +} + // TODO(josharian): combine this with its caller and simplify func reduceSlice(n *Node) *Node { low, high, max := n.SliceBounds() From 961eb13b6781907b5bfe4a7b22f68206020c4468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Tue, 5 Jun 2018 08:14:57 +0200 Subject: [PATCH 0182/1663] runtime: replace sys.CacheLineSize by corresponding internal/cpu const and vars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sys here is runtime/internal/sys. Replace uses of sys.CacheLineSize for padding by cpu.CacheLinePad or cpu.CacheLinePadSize. Replace other uses of sys.CacheLineSize by cpu.CacheLineSize. Remove now unused sys.CacheLineSize. Updates #25203 Change-Id: I1daf410fe8f6c0493471c2ceccb9ca0a5a75ed8f Reviewed-on: https://go-review.googlesource.com/126601 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/go/build/deps_test.go | 2 +- src/internal/cpu/cpu.go | 2 +- src/runtime/internal/atomic/atomic_arm.go | 4 ++-- src/runtime/internal/atomic/atomic_mipsx.go | 4 ++-- src/runtime/internal/sys/arch_386.go | 1 - src/runtime/internal/sys/arch_amd64.go | 1 - src/runtime/internal/sys/arch_amd64p32.go | 1 - src/runtime/internal/sys/arch_arm.go | 1 - src/runtime/internal/sys/arch_arm64.go | 1 - src/runtime/internal/sys/arch_mips.go | 1 - src/runtime/internal/sys/arch_mips64.go | 1 - src/runtime/internal/sys/arch_mips64le.go | 1 - src/runtime/internal/sys/arch_mipsle.go | 1 - src/runtime/internal/sys/arch_ppc64.go | 1 - src/runtime/internal/sys/arch_ppc64le.go | 1 - src/runtime/internal/sys/arch_s390x.go | 1 - src/runtime/internal/sys/arch_wasm.go | 1 - src/runtime/mgc.go | 10 +++++----- src/runtime/mgcsweepbuf.go | 5 +++-- src/runtime/mheap.go | 5 +++-- src/runtime/runtime2.go | 3 ++- src/runtime/sema.go | 4 ++-- src/runtime/time.go | 4 ++-- 23 files changed, 23 insertions(+), 33 deletions(-) diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index 729d0db51f24b..244c745d41df1 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -38,7 +38,7 @@ var pkgDeps = map[string][]string{ "io": {"errors", "sync", "sync/atomic"}, "runtime": {"unsafe", "runtime/internal/atomic", "runtime/internal/sys", "internal/cpu", "internal/bytealg"}, "runtime/internal/sys": {}, - "runtime/internal/atomic": {"unsafe", "runtime/internal/sys"}, + "runtime/internal/atomic": {"unsafe", "internal/cpu"}, "internal/race": {"runtime", "unsafe"}, "sync": {"internal/race", "runtime", "sync/atomic", "unsafe"}, "sync/atomic": {"unsafe"}, diff --git a/src/internal/cpu/cpu.go b/src/internal/cpu/cpu.go index 5363f11b90839..bfb016c7f722d 100644 --- a/src/internal/cpu/cpu.go +++ b/src/internal/cpu/cpu.go @@ -17,7 +17,7 @@ type CacheLinePad struct{ _ [CacheLinePadSize]byte } // CacheLineSize is the CPU's assumed cache line size. // There is currently no runtime detection of the real cache line size // so we use the constant per GOARCH CacheLinePadSize as an approximation. -var CacheLineSize = CacheLinePadSize +var CacheLineSize uintptr = CacheLinePadSize var X86 x86 diff --git a/src/runtime/internal/atomic/atomic_arm.go b/src/runtime/internal/atomic/atomic_arm.go index 4ed7e991fe294..1ecdb11db96b3 100644 --- a/src/runtime/internal/atomic/atomic_arm.go +++ b/src/runtime/internal/atomic/atomic_arm.go @@ -7,7 +7,7 @@ package atomic import ( - "runtime/internal/sys" + "internal/cpu" "unsafe" ) @@ -31,7 +31,7 @@ func (l *spinlock) unlock() { var locktab [57]struct { l spinlock - pad [sys.CacheLineSize - unsafe.Sizeof(spinlock{})]byte + pad [cpu.CacheLinePadSize - unsafe.Sizeof(spinlock{})]byte } func addrLock(addr *uint64) *spinlock { diff --git a/src/runtime/internal/atomic/atomic_mipsx.go b/src/runtime/internal/atomic/atomic_mipsx.go index 32be1c779d969..55943f6925c25 100644 --- a/src/runtime/internal/atomic/atomic_mipsx.go +++ b/src/runtime/internal/atomic/atomic_mipsx.go @@ -7,14 +7,14 @@ package atomic import ( - "runtime/internal/sys" + "internal/cpu" "unsafe" ) // TODO implement lock striping var lock struct { state uint32 - pad [sys.CacheLineSize - 4]byte + pad [cpu.CacheLinePadSize - 4]byte } //go:noescape diff --git a/src/runtime/internal/sys/arch_386.go b/src/runtime/internal/sys/arch_386.go index 5fb1fba02b6ef..537570133709d 100644 --- a/src/runtime/internal/sys/arch_386.go +++ b/src/runtime/internal/sys/arch_386.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = I386 BigEndian = false - CacheLineSize = 64 DefaultPhysPageSize = GoosNacl*65536 + (1-GoosNacl)*4096 // 4k normally; 64k on NaCl PCQuantum = 1 Int64Align = 4 diff --git a/src/runtime/internal/sys/arch_amd64.go b/src/runtime/internal/sys/arch_amd64.go index 2f32bc469ffdc..86fed4d53102f 100644 --- a/src/runtime/internal/sys/arch_amd64.go +++ b/src/runtime/internal/sys/arch_amd64.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = AMD64 BigEndian = false - CacheLineSize = 64 DefaultPhysPageSize = 4096 PCQuantum = 1 Int64Align = 8 diff --git a/src/runtime/internal/sys/arch_amd64p32.go b/src/runtime/internal/sys/arch_amd64p32.go index c560907c6784e..749d724809f2b 100644 --- a/src/runtime/internal/sys/arch_amd64p32.go +++ b/src/runtime/internal/sys/arch_amd64p32.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = AMD64 BigEndian = false - CacheLineSize = 64 DefaultPhysPageSize = 65536*GoosNacl + 4096*(1-GoosNacl) PCQuantum = 1 Int64Align = 8 diff --git a/src/runtime/internal/sys/arch_arm.go b/src/runtime/internal/sys/arch_arm.go index f383d82027cf4..2af09e0e35491 100644 --- a/src/runtime/internal/sys/arch_arm.go +++ b/src/runtime/internal/sys/arch_arm.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = ARM BigEndian = false - CacheLineSize = 32 DefaultPhysPageSize = 65536 PCQuantum = 4 Int64Align = 4 diff --git a/src/runtime/internal/sys/arch_arm64.go b/src/runtime/internal/sys/arch_arm64.go index cb83ecc445724..f13d2de129aa9 100644 --- a/src/runtime/internal/sys/arch_arm64.go +++ b/src/runtime/internal/sys/arch_arm64.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = ARM64 BigEndian = false - CacheLineSize = 64 DefaultPhysPageSize = 65536 PCQuantum = 4 Int64Align = 8 diff --git a/src/runtime/internal/sys/arch_mips.go b/src/runtime/internal/sys/arch_mips.go index e12f32d0eeb82..e9bd69c928e48 100644 --- a/src/runtime/internal/sys/arch_mips.go +++ b/src/runtime/internal/sys/arch_mips.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = MIPS BigEndian = true - CacheLineSize = 32 DefaultPhysPageSize = 65536 PCQuantum = 4 Int64Align = 4 diff --git a/src/runtime/internal/sys/arch_mips64.go b/src/runtime/internal/sys/arch_mips64.go index 973ec10e17f9e..5eb7b2b7b1346 100644 --- a/src/runtime/internal/sys/arch_mips64.go +++ b/src/runtime/internal/sys/arch_mips64.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = MIPS64 BigEndian = true - CacheLineSize = 32 DefaultPhysPageSize = 16384 PCQuantum = 4 Int64Align = 8 diff --git a/src/runtime/internal/sys/arch_mips64le.go b/src/runtime/internal/sys/arch_mips64le.go index e96d962f368b9..14c804ed85bb0 100644 --- a/src/runtime/internal/sys/arch_mips64le.go +++ b/src/runtime/internal/sys/arch_mips64le.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = MIPS64 BigEndian = false - CacheLineSize = 32 DefaultPhysPageSize = 16384 PCQuantum = 4 Int64Align = 8 diff --git a/src/runtime/internal/sys/arch_mipsle.go b/src/runtime/internal/sys/arch_mipsle.go index 25742ae9d3f18..91badb17d5175 100644 --- a/src/runtime/internal/sys/arch_mipsle.go +++ b/src/runtime/internal/sys/arch_mipsle.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = MIPS BigEndian = false - CacheLineSize = 32 DefaultPhysPageSize = 65536 PCQuantum = 4 Int64Align = 4 diff --git a/src/runtime/internal/sys/arch_ppc64.go b/src/runtime/internal/sys/arch_ppc64.go index a538bbdec0b53..8cde4e18d0cd6 100644 --- a/src/runtime/internal/sys/arch_ppc64.go +++ b/src/runtime/internal/sys/arch_ppc64.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = PPC64 BigEndian = true - CacheLineSize = 128 DefaultPhysPageSize = 65536 PCQuantum = 4 Int64Align = 8 diff --git a/src/runtime/internal/sys/arch_ppc64le.go b/src/runtime/internal/sys/arch_ppc64le.go index aa506891817e3..10c0066849a95 100644 --- a/src/runtime/internal/sys/arch_ppc64le.go +++ b/src/runtime/internal/sys/arch_ppc64le.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = PPC64 BigEndian = false - CacheLineSize = 128 DefaultPhysPageSize = 65536 PCQuantum = 4 Int64Align = 8 diff --git a/src/runtime/internal/sys/arch_s390x.go b/src/runtime/internal/sys/arch_s390x.go index e42c420a542c1..77fd4bf07d7db 100644 --- a/src/runtime/internal/sys/arch_s390x.go +++ b/src/runtime/internal/sys/arch_s390x.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = S390X BigEndian = true - CacheLineSize = 256 DefaultPhysPageSize = 4096 PCQuantum = 2 Int64Align = 8 diff --git a/src/runtime/internal/sys/arch_wasm.go b/src/runtime/internal/sys/arch_wasm.go index 5463f934d607a..203fc2e472b28 100644 --- a/src/runtime/internal/sys/arch_wasm.go +++ b/src/runtime/internal/sys/arch_wasm.go @@ -7,7 +7,6 @@ package sys const ( ArchFamily = WASM BigEndian = false - CacheLineSize = 64 DefaultPhysPageSize = 65536 PCQuantum = 1 Int64Align = 8 diff --git a/src/runtime/mgc.go b/src/runtime/mgc.go index f54c8eb14f540..c95b5ed37f8ef 100644 --- a/src/runtime/mgc.go +++ b/src/runtime/mgc.go @@ -137,8 +137,8 @@ package runtime import ( + "internal/cpu" "runtime/internal/atomic" - "runtime/internal/sys" "unsafe" ) @@ -414,7 +414,7 @@ type gcControllerState struct { // If this is zero, no fractional workers are needed. fractionalUtilizationGoal float64 - _ [sys.CacheLineSize]byte + _ cpu.CacheLinePad } // startCycle resets the GC controller's state and computes estimates @@ -919,9 +919,9 @@ const gcAssistTimeSlack = 5000 const gcOverAssistWork = 64 << 10 var work struct { - full lfstack // lock-free list of full blocks workbuf - empty lfstack // lock-free list of empty blocks workbuf - pad0 [sys.CacheLineSize]uint8 // prevents false-sharing between full/empty and nproc/nwait + full lfstack // lock-free list of full blocks workbuf + empty lfstack // lock-free list of empty blocks workbuf + pad0 cpu.CacheLinePad // prevents false-sharing between full/empty and nproc/nwait wbufSpans struct { lock mutex diff --git a/src/runtime/mgcsweepbuf.go b/src/runtime/mgcsweepbuf.go index 6c1118e3857cc..0491f7ccf6c98 100644 --- a/src/runtime/mgcsweepbuf.go +++ b/src/runtime/mgcsweepbuf.go @@ -5,6 +5,7 @@ package runtime import ( + "internal/cpu" "runtime/internal/atomic" "runtime/internal/sys" "unsafe" @@ -83,7 +84,7 @@ retry: if newCap == 0 { newCap = gcSweepBufInitSpineCap } - newSpine := persistentalloc(newCap*sys.PtrSize, sys.CacheLineSize, &memstats.gc_sys) + newSpine := persistentalloc(newCap*sys.PtrSize, cpu.CacheLineSize, &memstats.gc_sys) if b.spineCap != 0 { // Blocks are allocated off-heap, so // no write barriers. @@ -102,7 +103,7 @@ retry: } // Allocate a new block and add it to the spine. - block = (*gcSweepBlock)(persistentalloc(unsafe.Sizeof(gcSweepBlock{}), sys.CacheLineSize, &memstats.gc_sys)) + block = (*gcSweepBlock)(persistentalloc(unsafe.Sizeof(gcSweepBlock{}), cpu.CacheLineSize, &memstats.gc_sys)) blockp := add(b.spine, sys.PtrSize*top) // Blocks are allocated off-heap, so no write barrier. atomic.StorepNoWB(blockp, unsafe.Pointer(block)) diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index b11853ca18dcc..00ecfa2d66cb6 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -9,6 +9,7 @@ package runtime import ( + "internal/cpu" "runtime/internal/atomic" "runtime/internal/sys" "unsafe" @@ -137,12 +138,12 @@ type mheap struct { // central free lists for small size classes. // the padding makes sure that the MCentrals are - // spaced CacheLineSize bytes apart, so that each MCentral.lock + // spaced CacheLinePadSize bytes apart, so that each MCentral.lock // gets its own cache line. // central is indexed by spanClass. central [numSpanClasses]struct { mcentral mcentral - pad [sys.CacheLineSize - unsafe.Sizeof(mcentral{})%sys.CacheLineSize]byte + pad [cpu.CacheLinePadSize - unsafe.Sizeof(mcentral{})%cpu.CacheLinePadSize]byte } spanalloc fixalloc // allocator for span* diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index 93119249426d9..e4c6b3b52a7e6 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -5,6 +5,7 @@ package runtime import ( + "internal/cpu" "runtime/internal/atomic" "runtime/internal/sys" "unsafe" @@ -548,7 +549,7 @@ type p struct { runSafePointFn uint32 // if 1, run sched.safePointFn at next safe point - pad [sys.CacheLineSize]byte + pad cpu.CacheLinePad } type schedt struct { diff --git a/src/runtime/sema.go b/src/runtime/sema.go index aba97331275ad..18e0a398ba76c 100644 --- a/src/runtime/sema.go +++ b/src/runtime/sema.go @@ -20,8 +20,8 @@ package runtime import ( + "internal/cpu" "runtime/internal/atomic" - "runtime/internal/sys" "unsafe" ) @@ -48,7 +48,7 @@ const semTabSize = 251 var semtable [semTabSize]struct { root semaRoot - pad [sys.CacheLineSize - unsafe.Sizeof(semaRoot{})]byte + pad [cpu.CacheLinePadSize - unsafe.Sizeof(semaRoot{})]byte } //go:linkname sync_runtime_Semacquire sync.runtime_Semacquire diff --git a/src/runtime/time.go b/src/runtime/time.go index 9de45f5e08e59..790819f25987f 100644 --- a/src/runtime/time.go +++ b/src/runtime/time.go @@ -7,7 +7,7 @@ package runtime import ( - "runtime/internal/sys" + "internal/cpu" "unsafe" ) @@ -50,7 +50,7 @@ var timers [timersLen]struct { // The padding should eliminate false sharing // between timersBucket values. - pad [sys.CacheLineSize - unsafe.Sizeof(timersBucket{})%sys.CacheLineSize]byte + pad [cpu.CacheLinePadSize - unsafe.Sizeof(timersBucket{})%cpu.CacheLinePadSize]byte } func (t *timer) assignBucket() *timersBucket { From 05c02444eb2d8b8d3ecd949c4308d8e2323ae087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Fri, 24 Aug 2018 11:02:00 +0200 Subject: [PATCH 0183/1663] all: align cpu feature variable offset naming MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add an "offset_" prefix to all cpu feature variable offset constants to signify that they are not boolean cpu feature variables. Remove _ from offset constant names. Change-Id: I6e22a79ebcbe6e2ae54c4ac8764f9260bb3223ff Reviewed-on: https://go-review.googlesource.com/131215 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/internal/bytealg/bytealg.go | 11 ++++++----- src/internal/bytealg/compare_amd64.s | 2 +- src/internal/bytealg/count_amd64.s | 6 +++--- src/internal/bytealg/equal_386.s | 2 +- src/internal/bytealg/equal_amd64.s | 2 +- src/internal/bytealg/index_amd64.s | 2 +- src/internal/bytealg/indexbyte_amd64.s | 2 +- src/internal/bytealg/indexbyte_s390x.s | 2 +- src/runtime/asm_386.s | 2 +- src/runtime/cpuflags.go | 8 ++++---- src/runtime/memclr_386.s | 2 +- src/runtime/memclr_amd64.s | 2 +- src/runtime/memmove_386.s | 4 ++-- src/runtime/memmove_amd64.s | 2 +- src/runtime/vlop_arm.s | 2 +- 15 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/internal/bytealg/bytealg.go b/src/internal/bytealg/bytealg.go index 1ab7c30f4ea00..9ecd8eb004b03 100644 --- a/src/internal/bytealg/bytealg.go +++ b/src/internal/bytealg/bytealg.go @@ -11,11 +11,12 @@ import ( // Offsets into internal/cpu records for use in assembly. const ( - x86_HasSSE2 = unsafe.Offsetof(cpu.X86.HasSSE2) - x86_HasSSE42 = unsafe.Offsetof(cpu.X86.HasSSE42) - x86_HasAVX2 = unsafe.Offsetof(cpu.X86.HasAVX2) - x86_HasPOPCNT = unsafe.Offsetof(cpu.X86.HasPOPCNT) - s390x_HasVX = unsafe.Offsetof(cpu.S390X.HasVX) + offsetX86HasSSE2 = unsafe.Offsetof(cpu.X86.HasSSE2) + offsetX86HasSSE42 = unsafe.Offsetof(cpu.X86.HasSSE42) + offsetX86HasAVX2 = unsafe.Offsetof(cpu.X86.HasAVX2) + offsetX86HasPOPCNT = unsafe.Offsetof(cpu.X86.HasPOPCNT) + + offsetS390xHasVX = unsafe.Offsetof(cpu.S390X.HasVX) ) // MaxLen is the maximum length of the string to be searched for (argument b) in Index. diff --git a/src/internal/bytealg/compare_amd64.s b/src/internal/bytealg/compare_amd64.s index 277d77c545ada..05bef4aad938f 100644 --- a/src/internal/bytealg/compare_amd64.s +++ b/src/internal/bytealg/compare_amd64.s @@ -47,7 +47,7 @@ TEXT cmpbody<>(SB),NOSPLIT,$0-0 CMPQ R8, $63 JBE loop - CMPB internal∕cpu·X86+const_x86_HasAVX2(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasAVX2(SB), $1 JEQ big_loop_avx2 JMP big_loop loop: diff --git a/src/internal/bytealg/count_amd64.s b/src/internal/bytealg/count_amd64.s index cecba11cf9ff0..fa864c4c76631 100644 --- a/src/internal/bytealg/count_amd64.s +++ b/src/internal/bytealg/count_amd64.s @@ -6,7 +6,7 @@ #include "textflag.h" TEXT ·Count(SB),NOSPLIT,$0-40 - CMPB internal∕cpu·X86+const_x86_HasPOPCNT(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasPOPCNT(SB), $1 JEQ 2(PC) JMP ·countGeneric(SB) MOVQ b_base+0(FP), SI @@ -16,7 +16,7 @@ TEXT ·Count(SB),NOSPLIT,$0-40 JMP countbody<>(SB) TEXT ·CountString(SB),NOSPLIT,$0-32 - CMPB internal∕cpu·X86+const_x86_HasPOPCNT(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasPOPCNT(SB), $1 JEQ 2(PC) JMP ·countGenericString(SB) MOVQ s_base+0(FP), SI @@ -151,7 +151,7 @@ endofpage: RET avx2: - CMPB internal∕cpu·X86+const_x86_HasAVX2(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasAVX2(SB), $1 JNE sse MOVD AX, X0 LEAQ -32(SI)(BX*1), R11 diff --git a/src/internal/bytealg/equal_386.s b/src/internal/bytealg/equal_386.s index c048b6cebc87c..273389284ef12 100644 --- a/src/internal/bytealg/equal_386.s +++ b/src/internal/bytealg/equal_386.s @@ -80,7 +80,7 @@ TEXT memeqbody<>(SB),NOSPLIT,$0-0 hugeloop: CMPL BX, $64 JB bigloop - CMPB internal∕cpu·X86+const_x86_HasSSE2(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasSSE2(SB), $1 JNE bigloop MOVOU (SI), X0 MOVOU (DI), X1 diff --git a/src/internal/bytealg/equal_amd64.s b/src/internal/bytealg/equal_amd64.s index cbc62dc1d8f3d..5263d3040d561 100644 --- a/src/internal/bytealg/equal_amd64.s +++ b/src/internal/bytealg/equal_amd64.s @@ -77,7 +77,7 @@ TEXT memeqbody<>(SB),NOSPLIT,$0-0 JB small CMPQ BX, $64 JB bigloop - CMPB internal∕cpu·X86+const_x86_HasAVX2(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasAVX2(SB), $1 JE hugeloop_avx2 // 64 bytes at a time using xmm registers diff --git a/src/internal/bytealg/index_amd64.s b/src/internal/bytealg/index_amd64.s index f7297c0cab4eb..4459820801082 100644 --- a/src/internal/bytealg/index_amd64.s +++ b/src/internal/bytealg/index_amd64.s @@ -233,7 +233,7 @@ success_avx2: VZEROUPPER JMP success sse42: - CMPB internal∕cpu·X86+const_x86_HasSSE42(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasSSE42(SB), $1 JNE no_sse42 CMPQ AX, $12 // PCMPESTRI is slower than normal compare, diff --git a/src/internal/bytealg/indexbyte_amd64.s b/src/internal/bytealg/indexbyte_amd64.s index 359f38904b1d3..5bf8866476379 100644 --- a/src/internal/bytealg/indexbyte_amd64.s +++ b/src/internal/bytealg/indexbyte_amd64.s @@ -139,7 +139,7 @@ endofpage: RET avx2: - CMPB internal∕cpu·X86+const_x86_HasAVX2(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasAVX2(SB), $1 JNE sse MOVD AX, X0 LEAQ -32(SI)(BX*1), R11 diff --git a/src/internal/bytealg/indexbyte_s390x.s b/src/internal/bytealg/indexbyte_s390x.s index 15fd2935b4a9e..24f5ce17fa00e 100644 --- a/src/internal/bytealg/indexbyte_s390x.s +++ b/src/internal/bytealg/indexbyte_s390x.s @@ -64,7 +64,7 @@ notfound: RET large: - MOVBZ internal∕cpu·S390X+const_s390x_HasVX(SB), R1 + MOVBZ internal∕cpu·S390X+const_offsetS390xHasVX(SB), R1 CMPBNE R1, $0, vectorimpl srstimpl: // no vector facility diff --git a/src/runtime/asm_386.s b/src/runtime/asm_386.s index 725271eec4deb..7761415ecd5b7 100644 --- a/src/runtime/asm_386.s +++ b/src/runtime/asm_386.s @@ -881,7 +881,7 @@ TEXT runtime·stackcheck(SB), NOSPLIT, $0-0 // func cputicks() int64 TEXT runtime·cputicks(SB),NOSPLIT,$0-8 - CMPB internal∕cpu·X86+const_offset_x86_HasSSE2(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasSSE2(SB), $1 JNE done CMPB runtime·lfenceBeforeRdtsc(SB), $1 JNE mfence diff --git a/src/runtime/cpuflags.go b/src/runtime/cpuflags.go index 050168c2d7303..b65523766af5f 100644 --- a/src/runtime/cpuflags.go +++ b/src/runtime/cpuflags.go @@ -11,9 +11,9 @@ import ( // Offsets into internal/cpu records for use in assembly. const ( - offset_x86_HasAVX2 = unsafe.Offsetof(cpu.X86.HasAVX2) - offset_x86_HasERMS = unsafe.Offsetof(cpu.X86.HasERMS) - offset_x86_HasSSE2 = unsafe.Offsetof(cpu.X86.HasSSE2) + offsetX86HasAVX2 = unsafe.Offsetof(cpu.X86.HasAVX2) + offsetX86HasERMS = unsafe.Offsetof(cpu.X86.HasERMS) + offsetX86HasSSE2 = unsafe.Offsetof(cpu.X86.HasSSE2) - offset_arm_HasIDIVA = unsafe.Offsetof(cpu.ARM.HasIDIVA) + offsetARMHasIDIVA = unsafe.Offsetof(cpu.ARM.HasIDIVA) ) diff --git a/src/runtime/memclr_386.s b/src/runtime/memclr_386.s index 318f8839640e2..65f7196312cec 100644 --- a/src/runtime/memclr_386.s +++ b/src/runtime/memclr_386.s @@ -29,7 +29,7 @@ tail: JBE _5through8 CMPL BX, $16 JBE _9through16 - CMPB internal∕cpu·X86+const_offset_x86_HasSSE2(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasSSE2(SB), $1 JNE nosse2 PXOR X0, X0 CMPL BX, $32 diff --git a/src/runtime/memclr_amd64.s b/src/runtime/memclr_amd64.s index b64b1477f9365..d79078fd00bf5 100644 --- a/src/runtime/memclr_amd64.s +++ b/src/runtime/memclr_amd64.s @@ -38,7 +38,7 @@ tail: JBE _65through128 CMPQ BX, $256 JBE _129through256 - CMPB internal∕cpu·X86+const_offset_x86_HasAVX2(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasAVX2(SB), $1 JE loop_preheader_avx2 // TODO: for really big clears, use MOVNTDQ, even without AVX2. diff --git a/src/runtime/memmove_386.s b/src/runtime/memmove_386.s index 85c622b6b6283..7b54070f595cc 100644 --- a/src/runtime/memmove_386.s +++ b/src/runtime/memmove_386.s @@ -52,7 +52,7 @@ tail: JBE move_5through8 CMPL BX, $16 JBE move_9through16 - CMPB internal∕cpu·X86+const_offset_x86_HasSSE2(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasSSE2(SB), $1 JNE nosse2 CMPL BX, $32 JBE move_17through32 @@ -73,7 +73,7 @@ nosse2: */ forward: // If REP MOVSB isn't fast, don't use it - CMPB internal∕cpu·X86+const_offset_x86_HasERMS(SB), $1 // enhanced REP MOVSB/STOSB + CMPB internal∕cpu·X86+const_offsetX86HasERMS(SB), $1 // enhanced REP MOVSB/STOSB JNE fwdBy4 // Check alignment diff --git a/src/runtime/memmove_amd64.s b/src/runtime/memmove_amd64.s index c5385a3d4368a..b4243a833b6e6 100644 --- a/src/runtime/memmove_amd64.s +++ b/src/runtime/memmove_amd64.s @@ -84,7 +84,7 @@ forward: JLS move_256through2048 // If REP MOVSB isn't fast, don't use it - CMPB internal∕cpu·X86+const_offset_x86_HasERMS(SB), $1 // enhanced REP MOVSB/STOSB + CMPB internal∕cpu·X86+const_offsetX86HasERMS(SB), $1 // enhanced REP MOVSB/STOSB JNE fwdBy8 // Check alignment diff --git a/src/runtime/vlop_arm.s b/src/runtime/vlop_arm.s index 8df13abd98820..729653488ffd0 100644 --- a/src/runtime/vlop_arm.s +++ b/src/runtime/vlop_arm.s @@ -44,7 +44,7 @@ // the RET instruction will clobber R12 on nacl, and the compiler's register // allocator needs to know. TEXT runtime·udiv(SB),NOSPLIT|NOFRAME,$0 - MOVBU internal∕cpu·ARM+const_offset_arm_HasIDIVA(SB), Ra + MOVBU internal∕cpu·ARM+const_offsetARMHasIDIVA(SB), Ra CMP $0, Ra BNE udiv_hardware From 97f153528513e9a7ededf7e0aca7a4e30a3f4fe7 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 24 Aug 2018 11:44:55 -0700 Subject: [PATCH 0184/1663] runtime: mark sigInitIgnored nosplit The sigInitIgnored function can be called by initsig before a shared library is initialized, before the runtime is initialized. Fixes #27183 Change-Id: I7073767938fc011879d47ea951d63a14d1cce878 Reviewed-on: https://go-review.googlesource.com/131277 Run-TryBot: Ian Lance Taylor Reviewed-by: Austin Clements TryBot-Result: Gobot Gobot --- src/runtime/sigqueue.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/runtime/sigqueue.go b/src/runtime/sigqueue.go index 9f5324095448c..a425433b20a8d 100644 --- a/src/runtime/sigqueue.go +++ b/src/runtime/sigqueue.go @@ -237,8 +237,10 @@ func signal_ignore(s uint32) { atomic.Store(&sig.ignored[s/32], i) } -// sigInitIgnored marks the signal as already ignored. This is called at -// program start by siginit. +// sigInitIgnored marks the signal as already ignored. This is called at +// program start by initsig. In a shared library initsig is called by +// libpreinit, so the runtime may not be initialized yet. +//go:nosplit func sigInitIgnored(s uint32) { i := sig.ignored[s/32] i |= 1 << (s & 31) From 4cc027fb55956c001ce486f48538835581bc5197 Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Tue, 31 Jul 2018 18:13:05 +0300 Subject: [PATCH 0185/1663] cmd/compile: display AST IR in ssa.html This change adds a new column, AST IR. That column contains nodes for a function specified in $GOSSAFUNC. Also this CL enables horizontal scrolling of sources and AST columns. Fixes #26662 Change-Id: I3fba39fd998bb05e9c93038e8ec2384c69613b24 Reviewed-on: https://go-review.googlesource.com/126858 Run-TryBot: Yury Smolsky TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/fmt.go | 5 +++ src/cmd/compile/internal/gc/ssa.go | 14 +++++-- src/cmd/compile/internal/ssa/html.go | 55 +++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/gc/fmt.go b/src/cmd/compile/internal/gc/fmt.go index 75194ca6f034d..5b7445d4dbade 100644 --- a/src/cmd/compile/internal/gc/fmt.go +++ b/src/cmd/compile/internal/gc/fmt.go @@ -7,6 +7,7 @@ package gc import ( "cmd/compile/internal/types" "fmt" + "io" "strconv" "strings" "unicode/utf8" @@ -1836,6 +1837,10 @@ func dumplist(s string, l Nodes) { fmt.Printf("%s%+v\n", s, l) } +func fdumplist(w io.Writer, s string, l Nodes) { + fmt.Fprintf(w, "%s%+v\n", s, l) +} + func Dump(s string, n *Node) { fmt.Printf("%s [%p]%+v\n", s, n, n) } diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 7292963799523..2a8927acd69ed 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -111,11 +111,16 @@ func initssaconfig() { func buildssa(fn *Node, worker int) *ssa.Func { name := fn.funcname() printssa := name == ssaDump + var astBuf *bytes.Buffer if printssa { - fmt.Println("generating SSA for", name) - dumplist("buildssa-enter", fn.Func.Enter) - dumplist("buildssa-body", fn.Nbody) - dumplist("buildssa-exit", fn.Func.Exit) + astBuf = &bytes.Buffer{} + fdumplist(astBuf, "buildssa-enter", fn.Func.Enter) + fdumplist(astBuf, "buildssa-body", fn.Nbody) + fdumplist(astBuf, "buildssa-exit", fn.Func.Exit) + if ssaDumpStdout { + fmt.Println("generating SSA for", name) + fmt.Print(astBuf.String()) + } } var s state @@ -151,6 +156,7 @@ func buildssa(fn *Node, worker int) *ssa.Func { s.f.HTMLWriter = ssa.NewHTMLWriter(ssaDumpFile, s.f.Frontend(), name) // TODO: generate and print a mapping from nodes to values and blocks dumpSourcesColumn(s.f.HTMLWriter, fn) + s.f.HTMLWriter.WriteAST("AST", astBuf) } // Allocate starting block diff --git a/src/cmd/compile/internal/ssa/html.go b/src/cmd/compile/internal/ssa/html.go index 6943e5ef4031f..c51ea02262fcd 100644 --- a/src/cmd/compile/internal/ssa/html.go +++ b/src/cmd/compile/internal/ssa/html.go @@ -12,6 +12,7 @@ import ( "io" "os" "path/filepath" + "strconv" "strings" ) @@ -103,11 +104,15 @@ td.collapsed div { text-align: right; } -code, pre, .lines { +code, pre, .lines, .ast { font-family: Menlo, monospace; font-size: 12px; } +.allow-x-scroll { + overflow-x: scroll; +} + .lines { float: left; overflow: hidden; @@ -123,6 +128,10 @@ div.line-number { font-size: 12px; } +.ast { + white-space: nowrap; +} + td.ssa-prog { width: 600px; word-wrap: break-word; @@ -521,7 +530,49 @@ func (w *HTMLWriter) WriteSources(phase string, all []*FuncLines) { } } fmt.Fprint(&buf, "

    ") - w.WriteColumn(phase, phase, "", buf.String()) + w.WriteColumn(phase, phase, "allow-x-scroll", buf.String()) +} + +func (w *HTMLWriter) WriteAST(phase string, buf *bytes.Buffer) { + if w == nil { + return // avoid generating HTML just to discard it + } + lines := strings.Split(buf.String(), "\n") + var out bytes.Buffer + + fmt.Fprint(&out, "
    ") + for _, l := range lines { + l = strings.TrimSpace(l) + var escaped string + var lineNo string + if l == "" { + escaped = " " + } else { + if strings.HasPrefix(l, "buildssa") { + escaped = fmt.Sprintf("%v", l) + } else { + // Parse the line number from the format l(123). + idx := strings.Index(l, " l(") + if idx != -1 { + subl := l[idx+3:] + idxEnd := strings.Index(subl, ")") + if idxEnd != -1 { + if _, err := strconv.Atoi(subl[:idxEnd]); err == nil { + lineNo = subl[:idxEnd] + } + } + } + escaped = html.EscapeString(l) + } + } + if lineNo != "" { + fmt.Fprintf(&out, "
    %v
    ", lineNo, escaped) + } else { + fmt.Fprintf(&out, "
    %v
    ", escaped) + } + } + fmt.Fprint(&out, "
    ") + w.WriteColumn(phase, phase, "allow-x-scroll", out.String()) } // WriteColumn writes raw HTML in a column headed by title. From 97cc4b5123a71193cbb207a40a14b9025e769ec7 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Fri, 24 Aug 2018 15:20:33 -0400 Subject: [PATCH 0186/1663] doc: document Go 1.10.4 Change-Id: I7383e7d37a71defcad79fc662c4b4d1ca02189d1 Reviewed-on: https://go-review.googlesource.com/131336 Reviewed-by: Brad Fitzpatrick --- doc/devel/release.html | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/doc/devel/release.html b/doc/devel/release.html index 584340b005f9b..e5d834e92826c 100644 --- a/doc/devel/release.html +++ b/doc/devel/release.html @@ -57,6 +57,14 @@

    Minor revisions

    1.10.3 milestone on our issue tracker for details.

    +

    +go1.10.4 (released 2018/08/24) includes fixes to the go command, linker, and the +net/http, mime/multipart, ld/macho, +bytes, and strings packages. +See the Go +1.10.4 milestone on our issue tracker for details. +

    +

    go1.9 (released 2017/08/24)

    From 45e7e668440e79717e950162e6d42fb8773a109a Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 31 Jul 2018 12:40:20 -0700 Subject: [PATCH 0187/1663] cmd/compile: unify compilation of compiler tests Before this CL we would build&run each test file individually. Building the test takes most of the time, a significant fraction of a second. Running the tests are really fast. After this CL, we build all the tests at once, then run each individually. We only have to run the compiler&linker once (or twice, for softfloat architectures) instead of once per test. While we're here, organize these tests to fit a bit more into the standard testing framework. This is just the organizational CL that changes the testing framework and migrates 2 tests. Future tests will follow. R=go1.12 Update #26469 Change-Id: I1a1e7338c054b51f0c1c4c539d48d3d046b08b7d Reviewed-on: https://go-review.googlesource.com/126995 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/ssa_test.go | 125 +++++++++++++++++- .../gc/testdata/{break.go => break_test.go} | 17 +-- src/cmd/compile/internal/gc/testdata/short.go | 60 --------- .../internal/gc/testdata/short_test.go | 57 ++++++++ 4 files changed, 184 insertions(+), 75 deletions(-) rename src/cmd/compile/internal/gc/testdata/{break.go => break_test.go} (93%) delete mode 100644 src/cmd/compile/internal/gc/testdata/short.go create mode 100644 src/cmd/compile/internal/gc/testdata/short_test.go diff --git a/src/cmd/compile/internal/gc/ssa_test.go b/src/cmd/compile/internal/gc/ssa_test.go index 73110ea65a7d2..9f927262ca7ed 100644 --- a/src/cmd/compile/internal/gc/ssa_test.go +++ b/src/cmd/compile/internal/gc/ssa_test.go @@ -6,11 +6,16 @@ package gc import ( "bytes" + "fmt" + "go/ast" + "go/parser" + "go/token" "internal/testenv" "io/ioutil" "os" "os/exec" "path/filepath" + "runtime" "strings" "testing" ) @@ -104,11 +109,123 @@ func TestGenFlowGraph(t *testing.T) { runGenTest(t, "flowgraph_generator1.go", "ssa_fg_tmp1") } -// TestShortCircuit tests OANDAND and OOROR expressions and short circuiting. -func TestShortCircuit(t *testing.T) { runTest(t, "short.go") } +// TestCode runs all the tests in the testdata directory as subtests. +// These tests are special because we want to run them with different +// compiler flags set (and thus they can't just be _test.go files in +// this directory). +func TestCode(t *testing.T) { + testenv.MustHaveGoBuild(t) + gotool := testenv.GoToolPath(t) + + // Make a temporary directory to work in. + tmpdir, err := ioutil.TempDir("", "TestCode") + if err != nil { + t.Fatalf("Failed to create temporary directory: %v", err) + } + defer os.RemoveAll(tmpdir) + + // Find all the test functions (and the files containing them). + var srcs []string // files containing Test functions + type test struct { + name string // TestFoo + usesFloat bool // might use float operations + } + var tests []test + files, err := ioutil.ReadDir("testdata") + if err != nil { + t.Fatalf("can't read testdata directory: %v", err) + } + for _, f := range files { + if !strings.HasSuffix(f.Name(), "_test.go") { + continue + } + text, err := ioutil.ReadFile(filepath.Join("testdata", f.Name())) + if err != nil { + t.Fatalf("can't read testdata/%s: %v", f.Name(), err) + } + fset := token.NewFileSet() + code, err := parser.ParseFile(fset, f.Name(), text, 0) + if err != nil { + t.Fatalf("can't parse testdata/%s: %v", f.Name(), err) + } + srcs = append(srcs, filepath.Join("testdata", f.Name())) + foundTest := false + for _, d := range code.Decls { + fd, ok := d.(*ast.FuncDecl) + if !ok { + continue + } + if !strings.HasPrefix(fd.Name.Name, "Test") { + continue + } + if fd.Recv != nil { + continue + } + if fd.Type.Results != nil { + continue + } + if len(fd.Type.Params.List) != 1 { + continue + } + p := fd.Type.Params.List[0] + if len(p.Names) != 1 { + continue + } + s, ok := p.Type.(*ast.StarExpr) + if !ok { + continue + } + sel, ok := s.X.(*ast.SelectorExpr) + if !ok { + continue + } + base, ok := sel.X.(*ast.Ident) + if !ok { + continue + } + if base.Name != "testing" { + continue + } + if sel.Sel.Name != "T" { + continue + } + // Found a testing function. + tests = append(tests, test{name: fd.Name.Name, usesFloat: bytes.Contains(text, []byte("float"))}) + foundTest = true + } + if !foundTest { + t.Fatalf("test file testdata/%s has no tests in it", f.Name()) + } + } -// TestBreakContinue tests that continue and break statements do what they say. -func TestBreakContinue(t *testing.T) { runTest(t, "break.go") } + flags := []string{""} + if runtime.GOARCH == "arm" || runtime.GOARCH == "mips" || runtime.GOARCH == "mips64" { + flags = append(flags, ",softfloat") + } + for _, flag := range flags { + args := []string{"test", "-c", "-gcflags=-d=ssa/check/on" + flag, "-o", filepath.Join(tmpdir, "code.test")} + args = append(args, srcs...) + out, err := exec.Command(gotool, args...).CombinedOutput() + if err != nil || len(out) != 0 { + t.Fatalf("Build failed: %v\n%s\n", err, out) + } + + // Now we have a test binary. Run it with all the tests as subtests of this one. + for _, test := range tests { + test := test + if flag == ",softfloat" && !test.usesFloat { + // No point in running the soft float version if the test doesn't use floats. + continue + } + t.Run(fmt.Sprintf("%s%s", test.name[4:], flag), func(t *testing.T) { + out, err := exec.Command(filepath.Join(tmpdir, "code.test"), "-test.run="+test.name).CombinedOutput() + if err != nil || string(out) != "PASS\n" { + t.Errorf("Failed:\n%s\n", out) + } + }) + } + } +} // TestTypeAssertion tests type assertions. func TestTypeAssertion(t *testing.T) { runTest(t, "assert.go") } diff --git a/src/cmd/compile/internal/gc/testdata/break.go b/src/cmd/compile/internal/gc/testdata/break_test.go similarity index 93% rename from src/cmd/compile/internal/gc/testdata/break.go rename to src/cmd/compile/internal/gc/testdata/break_test.go index 855ef70049c88..50245dfd3186d 100644 --- a/src/cmd/compile/internal/gc/testdata/break.go +++ b/src/cmd/compile/internal/gc/testdata/break_test.go @@ -1,5 +1,3 @@ -// run - // Copyright 2015 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. @@ -8,6 +6,8 @@ package main +import "testing" + func continuePlain_ssa() int { var n int for i := 0; i < 10; i++ { @@ -214,7 +214,8 @@ Done: return n } -func main() { +// TestBreakContinue tests that continue and break statements do what they say. +func TestBreakContinue(t *testing.T) { tests := [...]struct { name string fn func() int @@ -241,15 +242,9 @@ func main() { // no select tests; they're identical to switch } - var failed bool for _, test := range tests { - if got := test.fn(); test.fn() != test.want { - print(test.name, "()=", got, ", want ", test.want, "\n") - failed = true + if got := test.fn(); got != test.want { + t.Errorf("%s()=%d, want %d", test.name, got, test.want) } } - - if failed { - panic("failed") - } } diff --git a/src/cmd/compile/internal/gc/testdata/short.go b/src/cmd/compile/internal/gc/testdata/short.go deleted file mode 100644 index fcec1baf09644..0000000000000 --- a/src/cmd/compile/internal/gc/testdata/short.go +++ /dev/null @@ -1,60 +0,0 @@ -// run - -// Copyright 2015 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. - -// Tests short circuiting. - -package main - -func and_ssa(arg1, arg2 bool) bool { - return arg1 && rightCall(arg2) -} - -func or_ssa(arg1, arg2 bool) bool { - return arg1 || rightCall(arg2) -} - -var rightCalled bool - -//go:noinline -func rightCall(v bool) bool { - rightCalled = true - return v - panic("unreached") -} - -func testAnd(arg1, arg2, wantRes bool) { testShortCircuit("AND", arg1, arg2, and_ssa, arg1, wantRes) } -func testOr(arg1, arg2, wantRes bool) { testShortCircuit("OR", arg1, arg2, or_ssa, !arg1, wantRes) } - -func testShortCircuit(opName string, arg1, arg2 bool, fn func(bool, bool) bool, wantRightCall, wantRes bool) { - rightCalled = false - got := fn(arg1, arg2) - if rightCalled != wantRightCall { - println("failed for", arg1, opName, arg2, "; rightCalled=", rightCalled, "want=", wantRightCall) - failed = true - } - if wantRes != got { - println("failed for", arg1, opName, arg2, "; res=", got, "want=", wantRes) - failed = true - } -} - -var failed = false - -func main() { - testAnd(false, false, false) - testAnd(false, true, false) - testAnd(true, false, false) - testAnd(true, true, true) - - testOr(false, false, false) - testOr(false, true, true) - testOr(true, false, true) - testOr(true, true, true) - - if failed { - panic("failed") - } -} diff --git a/src/cmd/compile/internal/gc/testdata/short_test.go b/src/cmd/compile/internal/gc/testdata/short_test.go new file mode 100644 index 0000000000000..7a743b5d19e52 --- /dev/null +++ b/src/cmd/compile/internal/gc/testdata/short_test.go @@ -0,0 +1,57 @@ +// Copyright 2015 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. + +// Tests short circuiting. + +package main + +import "testing" + +func and_ssa(arg1, arg2 bool) bool { + return arg1 && rightCall(arg2) +} + +func or_ssa(arg1, arg2 bool) bool { + return arg1 || rightCall(arg2) +} + +var rightCalled bool + +//go:noinline +func rightCall(v bool) bool { + rightCalled = true + return v + panic("unreached") +} + +func testAnd(t *testing.T, arg1, arg2, wantRes bool) { + testShortCircuit(t, "AND", arg1, arg2, and_ssa, arg1, wantRes) +} +func testOr(t *testing.T, arg1, arg2, wantRes bool) { + testShortCircuit(t, "OR", arg1, arg2, or_ssa, !arg1, wantRes) +} + +func testShortCircuit(t *testing.T, opName string, arg1, arg2 bool, fn func(bool, bool) bool, wantRightCall, wantRes bool) { + rightCalled = false + got := fn(arg1, arg2) + if rightCalled != wantRightCall { + t.Errorf("failed for %t %s %t; rightCalled=%t want=%t", arg1, opName, arg2, rightCalled, wantRightCall) + } + if wantRes != got { + t.Errorf("failed for %t %s %t; res=%t want=%t", arg1, opName, arg2, got, wantRes) + } +} + +// TestShortCircuit tests OANDAND and OOROR expressions and short circuiting. +func TestShortCircuit(t *testing.T) { + testAnd(t, false, false, false) + testAnd(t, false, true, false) + testAnd(t, true, false, false) + testAnd(t, true, true, true) + + testOr(t, false, false, false) + testOr(t, false, true, true) + testOr(t, true, false, true) + testOr(t, true, true, true) +} From ed21535a60162372ae80b5e4e34be1ffe673eeb8 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 31 Jul 2018 14:20:22 -0700 Subject: [PATCH 0188/1663] cmd/compile: move over more compiler tests to new test infrastructure R=go1.12 Update #26469 Change-Id: Iad75edfc194f8391a8ead09bfa68d446155e84ac Reviewed-on: https://go-review.googlesource.com/127055 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/ssa_test.go | 13 - .../gc/testdata/{arith.go => arith_test.go} | 384 ++++------- .../compile/internal/gc/testdata/assert.go | 147 ----- .../internal/gc/testdata/assert_test.go | 128 ++++ .../gc/testdata/{fp.go => fp_test.go} | 602 ++++++++---------- 5 files changed, 537 insertions(+), 737 deletions(-) rename src/cmd/compile/internal/gc/testdata/{arith.go => arith_test.go} (68%) delete mode 100644 src/cmd/compile/internal/gc/testdata/assert.go create mode 100644 src/cmd/compile/internal/gc/testdata/assert_test.go rename src/cmd/compile/internal/gc/testdata/{fp.go => fp_test.go} (64%) diff --git a/src/cmd/compile/internal/gc/ssa_test.go b/src/cmd/compile/internal/gc/ssa_test.go index 9f927262ca7ed..769ffc4b528c6 100644 --- a/src/cmd/compile/internal/gc/ssa_test.go +++ b/src/cmd/compile/internal/gc/ssa_test.go @@ -227,19 +227,6 @@ func TestCode(t *testing.T) { } } -// TestTypeAssertion tests type assertions. -func TestTypeAssertion(t *testing.T) { runTest(t, "assert.go") } - -// TestArithmetic tests that both backends have the same result for arithmetic expressions. -func TestArithmetic(t *testing.T) { runTest(t, "arith.go") } - -// TestFP tests that both backends have the same result for floating point expressions. -func TestFP(t *testing.T) { runTest(t, "fp.go") } - -func TestFPSoftFloat(t *testing.T) { - runTest(t, "fp.go", "-gcflags=-d=softfloat,ssa/check/on") -} - // TestArithmeticBoundary tests boundary results for arithmetic operations. func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary.go") } diff --git a/src/cmd/compile/internal/gc/testdata/arith.go b/src/cmd/compile/internal/gc/testdata/arith_test.go similarity index 68% rename from src/cmd/compile/internal/gc/testdata/arith.go rename to src/cmd/compile/internal/gc/testdata/arith_test.go index d850ce27b22e3..d30d660b34725 100644 --- a/src/cmd/compile/internal/gc/testdata/arith.go +++ b/src/cmd/compile/internal/gc/testdata/arith_test.go @@ -1,5 +1,3 @@ -// run - // Copyright 2015 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. @@ -8,7 +6,9 @@ package main -import "fmt" +import ( + "testing" +) const ( y = 0x0fffFFFF @@ -56,39 +56,31 @@ func rshNotNop(x uint64) uint64 { return (((x >> 5) << 2) >> 1) } -func testShiftRemoval() { +func testShiftRemoval(t *testing.T) { allSet := ^uint64(0) if want, got := uint64(0x7ffffffffffffff), rshNop1(allSet); want != got { - println("testShiftRemoval rshNop1 failed, wanted", want, "got", got) - failed = true + t.Errorf("testShiftRemoval rshNop1 failed, wanted %d got %d", want, got) } if want, got := uint64(0x3ffffffffffffff), rshNop2(allSet); want != got { - println("testShiftRemoval rshNop2 failed, wanted", want, "got", got) - failed = true + t.Errorf("testShiftRemoval rshNop2 failed, wanted %d got %d", want, got) } if want, got := uint64(0x7fffffffffffff), rshNop3(allSet); want != got { - println("testShiftRemoval rshNop3 failed, wanted", want, "got", got) - failed = true + t.Errorf("testShiftRemoval rshNop3 failed, wanted %d got %d", want, got) } if want, got := uint64(0xffffffffffffffe), rshNotNop(allSet); want != got { - println("testShiftRemoval rshNotNop failed, wanted", want, "got", got) - failed = true + t.Errorf("testShiftRemoval rshNotNop failed, wanted %d got %d", want, got) } if want, got := uint64(0xffffffffffffffe0), lshNop1(allSet); want != got { - println("testShiftRemoval lshNop1 failed, wanted", want, "got", got) - failed = true + t.Errorf("testShiftRemoval lshNop1 failed, wanted %d got %d", want, got) } if want, got := uint64(0xffffffffffffffc0), lshNop2(allSet); want != got { - println("testShiftRemoval lshNop2 failed, wanted", want, "got", got) - failed = true + t.Errorf("testShiftRemoval lshNop2 failed, wanted %d got %d", want, got) } if want, got := uint64(0xfffffffffffffe00), lshNop3(allSet); want != got { - println("testShiftRemoval lshNop3 failed, wanted", want, "got", got) - failed = true + t.Errorf("testShiftRemoval lshNop3 failed, wanted %d got %d", want, got) } if want, got := uint64(0x7ffffffffffffff0), lshNotNop(allSet); want != got { - println("testShiftRemoval lshNotNop failed, wanted", want, "got", got) - failed = true + t.Errorf("testShiftRemoval lshNotNop failed, wanted %d got %d", want, got) } } @@ -110,37 +102,32 @@ func parseLE16(b []byte) uint16 { } // testLoadCombine tests for issue #14694 where load combining didn't respect the pointer offset. -func testLoadCombine() { +func testLoadCombine(t *testing.T) { testData := []byte{0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09} if want, got := uint64(0x0908070605040302), parseLE64(testData); want != got { - println("testLoadCombine failed, wanted", want, "got", got) - failed = true + t.Errorf("testLoadCombine failed, wanted %d got %d", want, got) } if want, got := uint32(0x05040302), parseLE32(testData); want != got { - println("testLoadCombine failed, wanted", want, "got", got) - failed = true + t.Errorf("testLoadCombine failed, wanted %d got %d", want, got) } if want, got := uint16(0x0302), parseLE16(testData); want != got { - println("testLoadCombine failed, wanted", want, "got", got) - failed = true + t.Errorf("testLoadCombine failed, wanted %d got %d", want, got) } } var loadSymData = [...]byte{0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08} -func testLoadSymCombine() { +func testLoadSymCombine(t *testing.T) { w2 := uint16(0x0201) g2 := uint16(loadSymData[0]) | uint16(loadSymData[1])<<8 if g2 != w2 { - println("testLoadSymCombine failed, wanted", w2, "got", g2) - failed = true + t.Errorf("testLoadSymCombine failed, wanted %d got %d", w2, g2) } w4 := uint32(0x04030201) g4 := uint32(loadSymData[0]) | uint32(loadSymData[1])<<8 | uint32(loadSymData[2])<<16 | uint32(loadSymData[3])<<24 if g4 != w4 { - println("testLoadSymCombine failed, wanted", w4, "got", g4) - failed = true + t.Errorf("testLoadSymCombine failed, wanted %d got %d", w4, g4) } w8 := uint64(0x0807060504030201) g8 := uint64(loadSymData[0]) | uint64(loadSymData[1])<<8 | @@ -148,8 +135,7 @@ func testLoadSymCombine() { uint64(loadSymData[4])<<32 | uint64(loadSymData[5])<<40 | uint64(loadSymData[6])<<48 | uint64(loadSymData[7])<<56 if g8 != w8 { - println("testLoadSymCombine failed, wanted", w8, "got", g8) - failed = true + t.Errorf("testLoadSymCombine failed, wanted %d got %d", w8, g8) } } @@ -170,34 +156,29 @@ func invalidMul_ssa(x uint32) uint32 { // testLargeConst tests a situation where larger than 32 bit consts were passed to ADDL // causing an invalid instruction error. -func testLargeConst() { +func testLargeConst(t *testing.T) { if want, got := uint32(268435440), invalidAdd_ssa(1); want != got { - println("testLargeConst add failed, wanted", want, "got", got) - failed = true + t.Errorf("testLargeConst add failed, wanted %d got %d", want, got) } if want, got := uint32(4026531858), invalidSub_ssa(1); want != got { - println("testLargeConst sub failed, wanted", want, "got", got) - failed = true + t.Errorf("testLargeConst sub failed, wanted %d got %d", want, got) } if want, got := uint32(268435455), invalidMul_ssa(1); want != got { - println("testLargeConst mul failed, wanted", want, "got", got) - failed = true + t.Errorf("testLargeConst mul failed, wanted %d got %d", want, got) } } // testArithRshConst ensures that "const >> const" right shifts correctly perform // sign extension on the lhs constant -func testArithRshConst() { +func testArithRshConst(t *testing.T) { wantu := uint64(0x4000000000000000) if got := arithRshuConst_ssa(); got != wantu { - println("arithRshuConst failed, wanted", wantu, "got", got) - failed = true + t.Errorf("arithRshuConst failed, wanted %d got %d", wantu, got) } wants := int64(-0x4000000000000000) if got := arithRshConst_ssa(); got != wants { - println("arithRshuConst failed, wanted", wants, "got", got) - failed = true + t.Errorf("arithRshConst failed, wanted %d got %d", wants, got) } } @@ -222,16 +203,14 @@ func arithConstShift_ssa(x int64) int64 { // testArithConstShift tests that right shift by large constants preserve // the sign of the input. -func testArithConstShift() { +func testArithConstShift(t *testing.T) { want := int64(-1) if got := arithConstShift_ssa(-1); want != got { - println("arithConstShift_ssa(-1) failed, wanted", want, "got", got) - failed = true + t.Errorf("arithConstShift_ssa(-1) failed, wanted %d got %d", want, got) } want = 0 if got := arithConstShift_ssa(1); want != got { - println("arithConstShift_ssa(1) failed, wanted", want, "got", got) - failed = true + t.Errorf("arithConstShift_ssa(1) failed, wanted %d got %d", want, got) } } @@ -257,35 +236,34 @@ func overflowConstShift8_ssa(x int64) int8 { return int8(x) << uint8(0xff) << uint8(1) } -func testOverflowConstShift() { +func testOverflowConstShift(t *testing.T) { want := int64(0) for x := int64(-127); x < int64(127); x++ { got := overflowConstShift64_ssa(x) if want != got { - fmt.Printf("overflowShift64 failed, wanted %d got %d\n", want, got) + t.Errorf("overflowShift64 failed, wanted %d got %d", want, got) } got = int64(overflowConstShift32_ssa(x)) if want != got { - fmt.Printf("overflowShift32 failed, wanted %d got %d\n", want, got) + t.Errorf("overflowShift32 failed, wanted %d got %d", want, got) } got = int64(overflowConstShift16_ssa(x)) if want != got { - fmt.Printf("overflowShift16 failed, wanted %d got %d\n", want, got) + t.Errorf("overflowShift16 failed, wanted %d got %d", want, got) } got = int64(overflowConstShift8_ssa(x)) if want != got { - fmt.Printf("overflowShift8 failed, wanted %d got %d\n", want, got) + t.Errorf("overflowShift8 failed, wanted %d got %d", want, got) } } } // test64BitConstMult tests that rewrite rules don't fold 64 bit constants // into multiply instructions. -func test64BitConstMult() { +func test64BitConstMult(t *testing.T) { want := int64(103079215109) if got := test64BitConstMult_ssa(1, 2); want != got { - println("test64BitConstMult failed, wanted", want, "got", got) - failed = true + t.Errorf("test64BitConstMult failed, wanted %d got %d", want, got) } } @@ -296,11 +274,10 @@ func test64BitConstMult_ssa(a, b int64) int64 { // test64BitConstAdd tests that rewrite rules don't fold 64 bit constants // into add instructions. -func test64BitConstAdd() { +func test64BitConstAdd(t *testing.T) { want := int64(3567671782835376650) if got := test64BitConstAdd_ssa(1, 2); want != got { - println("test64BitConstAdd failed, wanted", want, "got", got) - failed = true + t.Errorf("test64BitConstAdd failed, wanted %d got %d", want, got) } } @@ -311,11 +288,10 @@ func test64BitConstAdd_ssa(a, b int64) int64 { // testRegallocCVSpill tests that regalloc spills a value whose last use is the // current value. -func testRegallocCVSpill() { +func testRegallocCVSpill(t *testing.T) { want := int8(-9) if got := testRegallocCVSpill_ssa(1, 2, 3, 4); want != got { - println("testRegallocCVSpill failed, wanted", want, "got", got) - failed = true + t.Errorf("testRegallocCVSpill failed, wanted %d got %d", want, got) } } @@ -324,55 +300,43 @@ func testRegallocCVSpill_ssa(a, b, c, d int8) int8 { return a + -32 + b + 63*c*-87*d } -func testBitwiseLogic() { +func testBitwiseLogic(t *testing.T) { a, b := uint32(57623283), uint32(1314713839) if want, got := uint32(38551779), testBitwiseAnd_ssa(a, b); want != got { - println("testBitwiseAnd failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseAnd failed, wanted %d got %d", want, got) } if want, got := uint32(1333785343), testBitwiseOr_ssa(a, b); want != got { - println("testBitwiseOr failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseOr failed, wanted %d got %d", want, got) } if want, got := uint32(1295233564), testBitwiseXor_ssa(a, b); want != got { - println("testBitwiseXor failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseXor failed, wanted %d got %d", want, got) } if want, got := int32(832), testBitwiseLsh_ssa(13, 4, 2); want != got { - println("testBitwiseLsh failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseLsh failed, wanted %d got %d", want, got) } if want, got := int32(0), testBitwiseLsh_ssa(13, 25, 15); want != got { - println("testBitwiseLsh failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseLsh failed, wanted %d got %d", want, got) } if want, got := int32(0), testBitwiseLsh_ssa(-13, 25, 15); want != got { - println("testBitwiseLsh failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseLsh failed, wanted %d got %d", want, got) } if want, got := int32(-13), testBitwiseRsh_ssa(-832, 4, 2); want != got { - println("testBitwiseRsh failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseRsh failed, wanted %d got %d", want, got) } if want, got := int32(0), testBitwiseRsh_ssa(13, 25, 15); want != got { - println("testBitwiseRsh failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseRsh failed, wanted %d got %d", want, got) } if want, got := int32(-1), testBitwiseRsh_ssa(-13, 25, 15); want != got { - println("testBitwiseRsh failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseRsh failed, wanted %d got %d", want, got) } if want, got := uint32(0x3ffffff), testBitwiseRshU_ssa(0xffffffff, 4, 2); want != got { - println("testBitwiseRshU failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseRshU failed, wanted %d got %d", want, got) } if want, got := uint32(0), testBitwiseRshU_ssa(13, 25, 15); want != got { - println("testBitwiseRshU failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseRshU failed, wanted %d got %d", want, got) } if want, got := uint32(0), testBitwiseRshU_ssa(0x8aaaaaaa, 25, 15); want != got { - println("testBitwiseRshU failed, wanted", want, "got", got) - failed = true + t.Errorf("testBitwiseRshU failed, wanted %d got %d", want, got) } } @@ -419,20 +383,18 @@ func testShiftCX_ssa() int { return int(uint64(2*1)<<(3-2)<>v7)-2)&v11 | v11 - int(2)<<0>>(2-1)*(v11*0&v11<<1<<(uint8(2)+v4)) } -func testShiftCX() { +func testShiftCX(t *testing.T) { want := 141 if got := testShiftCX_ssa(); want != got { - println("testShiftCX failed, wanted", want, "got", got) - failed = true + t.Errorf("testShiftCX failed, wanted %d got %d", want, got) } } // testSubqToNegq ensures that the SUBQ -> NEGQ translation works correctly. -func testSubqToNegq() { +func testSubqToNegq(t *testing.T) { want := int64(-318294940372190156) if got := testSubqToNegq_ssa(1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2); want != got { - println("testSubqToNegq failed, wanted", want, "got", got) - failed = true + t.Errorf("testSubqToNegq failed, wanted %d got %d", want, got) } } @@ -441,12 +403,10 @@ func testSubqToNegq_ssa(a, b, c, d, e, f, g, h, i, j, k int64) int64 { return a + 8207351403619448057 - b - 1779494519303207690 + c*8810076340510052032*d - 4465874067674546219 - e*4361839741470334295 - f + 8688847565426072650*g*8065564729145417479 } -func testOcom() { +func testOcom(t *testing.T) { want1, want2 := int32(0x55555555), int32(-0x55555556) if got1, got2 := testOcom_ssa(0x55555555, 0x55555555); want1 != got1 || want2 != got2 { - println("testSubqToNegq failed, wanted", want1, "and", want2, - "got", got1, "and", got2) - failed = true + t.Errorf("testOcom failed, wanted %d and %d got %d and %d", want1, want2, got1, got2) } } @@ -479,27 +439,21 @@ func lrot3_ssa(w uint32) uint32 { return (w << 32) | (w >> (32 - 32)) } -func testLrot() { +func testLrot(t *testing.T) { wantA, wantB, wantC, wantD := uint8(0xe1), uint16(0xe001), uint32(0xe0000001), uint64(0xe000000000000001) a, b, c, d := lrot1_ssa(0xf, 0xf, 0xf, 0xf) if a != wantA || b != wantB || c != wantC || d != wantD { - println("lrot1_ssa(0xf, 0xf, 0xf, 0xf)=", - wantA, wantB, wantC, wantD, ", got", a, b, c, d) - failed = true + t.Errorf("lrot1_ssa(0xf, 0xf, 0xf, 0xf)=%d %d %d %d, got %d %d %d %d", wantA, wantB, wantC, wantD, a, b, c, d) } x := lrot2_ssa(0xb0000001, 32) wantX := uint32(0xb0000001) if x != wantX { - println("lrot2_ssa(0xb0000001, 32)=", - wantX, ", got", x) - failed = true + t.Errorf("lrot2_ssa(0xb0000001, 32)=%d, got %d", wantX, x) } x = lrot3_ssa(0xb0000001) if x != wantX { - println("lrot3_ssa(0xb0000001)=", - wantX, ", got", x) - failed = true + t.Errorf("lrot3_ssa(0xb0000001)=%d, got %d", wantX, x) } } @@ -518,18 +472,16 @@ func sub2_ssa() uint8 { return v1 ^ v1*v1 - v3 } -func testSubConst() { +func testSubConst(t *testing.T) { x1 := sub1_ssa() want1 := uint64(6) if x1 != want1 { - println("sub1_ssa()=", want1, ", got", x1) - failed = true + t.Errorf("sub1_ssa()=%d, got %d", want1, x1) } x2 := sub2_ssa() want2 := uint8(251) if x2 != want2 { - println("sub2_ssa()=", want2, ", got", x2) - failed = true + t.Errorf("sub2_ssa()=%d, got %d", want2, x2) } } @@ -544,12 +496,12 @@ func orPhi_ssa(a bool, x int) int { return x | v } -func testOrPhi() { +func testOrPhi(t *testing.T) { if want, got := -1, orPhi_ssa(true, 4); got != want { - println("orPhi_ssa(true, 4)=", got, " want ", want) + t.Errorf("orPhi_ssa(true, 4)=%d, want %d", got, want) } if want, got := -1, orPhi_ssa(false, 0); got != want { - println("orPhi_ssa(false, 0)=", got, " want ", want) + t.Errorf("orPhi_ssa(false, 0)=%d, want %d", got, want) } } @@ -794,227 +746,173 @@ func notshiftRAreg_ssa(a int32, s uint8) int32 { } // test ARM shifted ops -func testShiftedOps() { +func testShiftedOps(t *testing.T) { a, b := uint32(10), uint32(42) if want, got := a+b<<3, addshiftLL_ssa(a, b); got != want { - println("addshiftLL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("addshiftLL_ssa(10, 42) = %d want %d", got, want) } if want, got := a-b<<3, subshiftLL_ssa(a, b); got != want { - println("subshiftLL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("subshiftLL_ssa(10, 42) = %d want %d", got, want) } if want, got := a<<3-b, rsbshiftLL_ssa(a, b); got != want { - println("rsbshiftLL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("rsbshiftLL_ssa(10, 42) = %d want %d", got, want) } if want, got := a&(b<<3), andshiftLL_ssa(a, b); got != want { - println("andshiftLL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("andshiftLL_ssa(10, 42) = %d want %d", got, want) } if want, got := a|b<<3, orshiftLL_ssa(a, b); got != want { - println("orshiftLL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("orshiftLL_ssa(10, 42) = %d want %d", got, want) } if want, got := a^b<<3, xorshiftLL_ssa(a, b); got != want { - println("xorshiftLL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("xorshiftLL_ssa(10, 42) = %d want %d", got, want) } if want, got := a&^(b<<3), bicshiftLL_ssa(a, b); got != want { - println("bicshiftLL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("bicshiftLL_ssa(10, 42) = %d want %d", got, want) } if want, got := ^(a << 3), notshiftLL_ssa(a); got != want { - println("notshiftLL_ssa(10) =", got, " want ", want) - failed = true + t.Errorf("notshiftLL_ssa(10) = %d want %d", got, want) } if want, got := a+b>>3, addshiftRL_ssa(a, b); got != want { - println("addshiftRL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("addshiftRL_ssa(10, 42) = %d want %d", got, want) } if want, got := a-b>>3, subshiftRL_ssa(a, b); got != want { - println("subshiftRL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("subshiftRL_ssa(10, 42) = %d want %d", got, want) } if want, got := a>>3-b, rsbshiftRL_ssa(a, b); got != want { - println("rsbshiftRL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("rsbshiftRL_ssa(10, 42) = %d want %d", got, want) } if want, got := a&(b>>3), andshiftRL_ssa(a, b); got != want { - println("andshiftRL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("andshiftRL_ssa(10, 42) = %d want %d", got, want) } if want, got := a|b>>3, orshiftRL_ssa(a, b); got != want { - println("orshiftRL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("orshiftRL_ssa(10, 42) = %d want %d", got, want) } if want, got := a^b>>3, xorshiftRL_ssa(a, b); got != want { - println("xorshiftRL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("xorshiftRL_ssa(10, 42) = %d want %d", got, want) } if want, got := a&^(b>>3), bicshiftRL_ssa(a, b); got != want { - println("bicshiftRL_ssa(10, 42) =", got, " want ", want) - failed = true + t.Errorf("bicshiftRL_ssa(10, 42) = %d want %d", got, want) } if want, got := ^(a >> 3), notshiftRL_ssa(a); got != want { - println("notshiftRL_ssa(10) =", got, " want ", want) - failed = true + t.Errorf("notshiftRL_ssa(10) = %d want %d", got, want) } c, d := int32(10), int32(-42) if want, got := c+d>>3, addshiftRA_ssa(c, d); got != want { - println("addshiftRA_ssa(10, -42) =", got, " want ", want) - failed = true + t.Errorf("addshiftRA_ssa(10, -42) = %d want %d", got, want) } if want, got := c-d>>3, subshiftRA_ssa(c, d); got != want { - println("subshiftRA_ssa(10, -42) =", got, " want ", want) - failed = true + t.Errorf("subshiftRA_ssa(10, -42) = %d want %d", got, want) } if want, got := c>>3-d, rsbshiftRA_ssa(c, d); got != want { - println("rsbshiftRA_ssa(10, -42) =", got, " want ", want) - failed = true + t.Errorf("rsbshiftRA_ssa(10, -42) = %d want %d", got, want) } if want, got := c&(d>>3), andshiftRA_ssa(c, d); got != want { - println("andshiftRA_ssa(10, -42) =", got, " want ", want) - failed = true + t.Errorf("andshiftRA_ssa(10, -42) = %d want %d", got, want) } if want, got := c|d>>3, orshiftRA_ssa(c, d); got != want { - println("orshiftRA_ssa(10, -42) =", got, " want ", want) - failed = true + t.Errorf("orshiftRA_ssa(10, -42) = %d want %d", got, want) } if want, got := c^d>>3, xorshiftRA_ssa(c, d); got != want { - println("xorshiftRA_ssa(10, -42) =", got, " want ", want) - failed = true + t.Errorf("xorshiftRA_ssa(10, -42) = %d want %d", got, want) } if want, got := c&^(d>>3), bicshiftRA_ssa(c, d); got != want { - println("bicshiftRA_ssa(10, -42) =", got, " want ", want) - failed = true + t.Errorf("bicshiftRA_ssa(10, -42) = %d want %d", got, want) } if want, got := ^(d >> 3), notshiftRA_ssa(d); got != want { - println("notshiftRA_ssa(-42) =", got, " want ", want) - failed = true + t.Errorf("notshiftRA_ssa(-42) = %d want %d", got, want) } s := uint8(3) if want, got := a+b<>s, addshiftRLreg_ssa(a, b, s); got != want { - println("addshiftRLreg_ssa(10, 42, 3) =", got, " want ", want) - failed = true + t.Errorf("addshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want) } if want, got := a-b>>s, subshiftRLreg_ssa(a, b, s); got != want { - println("subshiftRLreg_ssa(10, 42, 3) =", got, " want ", want) - failed = true + t.Errorf("subshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want) } if want, got := a>>s-b, rsbshiftRLreg_ssa(a, b, s); got != want { - println("rsbshiftRLreg_ssa(10, 42, 3) =", got, " want ", want) - failed = true + t.Errorf("rsbshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want) } if want, got := a&(b>>s), andshiftRLreg_ssa(a, b, s); got != want { - println("andshiftRLreg_ssa(10, 42, 3) =", got, " want ", want) - failed = true + t.Errorf("andshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want) } if want, got := a|b>>s, orshiftRLreg_ssa(a, b, s); got != want { - println("orshiftRLreg_ssa(10, 42, 3) =", got, " want ", want) - failed = true + t.Errorf("orshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want) } if want, got := a^b>>s, xorshiftRLreg_ssa(a, b, s); got != want { - println("xorshiftRLreg_ssa(10, 42, 3) =", got, " want ", want) - failed = true + t.Errorf("xorshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want) } if want, got := a&^(b>>s), bicshiftRLreg_ssa(a, b, s); got != want { - println("bicshiftRLreg_ssa(10, 42, 3) =", got, " want ", want) - failed = true + t.Errorf("bicshiftRLreg_ssa(10, 42, 3) = %d want %d", got, want) } if want, got := ^(a >> s), notshiftRLreg_ssa(a, s); got != want { - println("notshiftRLreg_ssa(10) =", got, " want ", want) - failed = true + t.Errorf("notshiftRLreg_ssa(10) = %d want %d", got, want) } if want, got := c+d>>s, addshiftRAreg_ssa(c, d, s); got != want { - println("addshiftRAreg_ssa(10, -42, 3) =", got, " want ", want) - failed = true + t.Errorf("addshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want) } if want, got := c-d>>s, subshiftRAreg_ssa(c, d, s); got != want { - println("subshiftRAreg_ssa(10, -42, 3) =", got, " want ", want) - failed = true + t.Errorf("subshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want) } if want, got := c>>s-d, rsbshiftRAreg_ssa(c, d, s); got != want { - println("rsbshiftRAreg_ssa(10, -42, 3) =", got, " want ", want) - failed = true + t.Errorf("rsbshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want) } if want, got := c&(d>>s), andshiftRAreg_ssa(c, d, s); got != want { - println("andshiftRAreg_ssa(10, -42, 3) =", got, " want ", want) - failed = true + t.Errorf("andshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want) } if want, got := c|d>>s, orshiftRAreg_ssa(c, d, s); got != want { - println("orshiftRAreg_ssa(10, -42, 3) =", got, " want ", want) - failed = true + t.Errorf("orshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want) } if want, got := c^d>>s, xorshiftRAreg_ssa(c, d, s); got != want { - println("xorshiftRAreg_ssa(10, -42, 3) =", got, " want ", want) - failed = true + t.Errorf("xorshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want) } if want, got := c&^(d>>s), bicshiftRAreg_ssa(c, d, s); got != want { - println("bicshiftRAreg_ssa(10, -42, 3) =", got, " want ", want) - failed = true + t.Errorf("bicshiftRAreg_ssa(10, -42, 3) = %d want %d", got, want) } if want, got := ^(d >> s), notshiftRAreg_ssa(d, s); got != want { - println("notshiftRAreg_ssa(-42, 3) =", got, " want ", want) - failed = true - } -} - -var failed = false - -func main() { - - test64BitConstMult() - test64BitConstAdd() - testRegallocCVSpill() - testSubqToNegq() - testBitwiseLogic() - testOcom() - testLrot() - testShiftCX() - testSubConst() - testOverflowConstShift() - testArithConstShift() - testArithRshConst() - testLargeConst() - testLoadCombine() - testLoadSymCombine() - testShiftRemoval() - testShiftedOps() - - if failed { - panic("failed") - } + t.Errorf("notshiftRAreg_ssa(-42, 3) = %d want %d", got, want) + } +} + +// TestArithmetic tests that both backends have the same result for arithmetic expressions. +func TestArithmetic(t *testing.T) { + test64BitConstMult(t) + test64BitConstAdd(t) + testRegallocCVSpill(t) + testSubqToNegq(t) + testBitwiseLogic(t) + testOcom(t) + testLrot(t) + testShiftCX(t) + testSubConst(t) + testOverflowConstShift(t) + testArithConstShift(t) + testArithRshConst(t) + testLargeConst(t) + testLoadCombine(t) + testLoadSymCombine(t) + testShiftRemoval(t) + testShiftedOps(t) } diff --git a/src/cmd/compile/internal/gc/testdata/assert.go b/src/cmd/compile/internal/gc/testdata/assert.go deleted file mode 100644 index d64d4fc35a4d7..0000000000000 --- a/src/cmd/compile/internal/gc/testdata/assert.go +++ /dev/null @@ -1,147 +0,0 @@ -// run - -// Copyright 2015 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. - -// Tests type assertion expressions and statements - -package main - -import ( - "fmt" - "runtime" -) - -type ( - S struct{} - T struct{} - - I interface { - F() - } -) - -var ( - s *S - t *T -) - -func (s *S) F() {} -func (t *T) F() {} - -func e2t_ssa(e interface{}) *T { - return e.(*T) -} - -func i2t_ssa(i I) *T { - return i.(*T) -} - -func testAssertE2TOk() { - if got := e2t_ssa(t); got != t { - fmt.Printf("e2t_ssa(t)=%v want %v", got, t) - failed = true - } -} - -func testAssertE2TPanic() { - var got *T - defer func() { - if got != nil { - fmt.Printf("e2t_ssa(s)=%v want nil", got) - failed = true - } - e := recover() - err, ok := e.(*runtime.TypeAssertionError) - if !ok { - fmt.Printf("e2t_ssa(s) panic type %T", e) - failed = true - } - want := "interface conversion: interface {} is *main.S, not *main.T" - if err.Error() != want { - fmt.Printf("e2t_ssa(s) wrong error, want '%s', got '%s'\n", want, err.Error()) - failed = true - } - }() - got = e2t_ssa(s) - fmt.Printf("e2t_ssa(s) should panic") - failed = true -} - -func testAssertI2TOk() { - if got := i2t_ssa(t); got != t { - fmt.Printf("i2t_ssa(t)=%v want %v", got, t) - failed = true - } -} - -func testAssertI2TPanic() { - var got *T - defer func() { - if got != nil { - fmt.Printf("i2t_ssa(s)=%v want nil", got) - failed = true - } - e := recover() - err, ok := e.(*runtime.TypeAssertionError) - if !ok { - fmt.Printf("i2t_ssa(s) panic type %T", e) - failed = true - } - want := "interface conversion: main.I is *main.S, not *main.T" - if err.Error() != want { - fmt.Printf("i2t_ssa(s) wrong error, want '%s', got '%s'\n", want, err.Error()) - failed = true - } - }() - got = i2t_ssa(s) - fmt.Printf("i2t_ssa(s) should panic") - failed = true -} - -func e2t2_ssa(e interface{}) (*T, bool) { - t, ok := e.(*T) - return t, ok -} - -func i2t2_ssa(i I) (*T, bool) { - t, ok := i.(*T) - return t, ok -} - -func testAssertE2T2() { - if got, ok := e2t2_ssa(t); !ok || got != t { - fmt.Printf("e2t2_ssa(t)=(%v, %v) want (%v, %v)", got, ok, t, true) - failed = true - } - if got, ok := e2t2_ssa(s); ok || got != nil { - fmt.Printf("e2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false) - failed = true - } -} - -func testAssertI2T2() { - if got, ok := i2t2_ssa(t); !ok || got != t { - fmt.Printf("i2t2_ssa(t)=(%v, %v) want (%v, %v)", got, ok, t, true) - failed = true - } - if got, ok := i2t2_ssa(s); ok || got != nil { - fmt.Printf("i2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false) - failed = true - } -} - -var failed = false - -func main() { - testAssertE2TOk() - testAssertE2TPanic() - testAssertI2TOk() - testAssertI2TPanic() - testAssertE2T2() - testAssertI2T2() - if failed { - panic("failed") - } -} diff --git a/src/cmd/compile/internal/gc/testdata/assert_test.go b/src/cmd/compile/internal/gc/testdata/assert_test.go new file mode 100644 index 0000000000000..4326be8079071 --- /dev/null +++ b/src/cmd/compile/internal/gc/testdata/assert_test.go @@ -0,0 +1,128 @@ +// Copyright 2015 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. + +// Tests type assertion expressions and statements + +package main + +import ( + "runtime" + "testing" +) + +type ( + S struct{} + U struct{} + + I interface { + F() + } +) + +var ( + s *S + u *U +) + +func (s *S) F() {} +func (u *U) F() {} + +func e2t_ssa(e interface{}) *U { + return e.(*U) +} + +func i2t_ssa(i I) *U { + return i.(*U) +} + +func testAssertE2TOk(t *testing.T) { + if got := e2t_ssa(u); got != u { + t.Errorf("e2t_ssa(u)=%v want %v", got, u) + } +} + +func testAssertE2TPanic(t *testing.T) { + var got *U + defer func() { + if got != nil { + t.Errorf("e2t_ssa(s)=%v want nil", got) + } + e := recover() + err, ok := e.(*runtime.TypeAssertionError) + if !ok { + t.Errorf("e2t_ssa(s) panic type %T", e) + } + want := "interface conversion: interface {} is *main.S, not *main.U" + if err.Error() != want { + t.Errorf("e2t_ssa(s) wrong error, want '%s', got '%s'", want, err.Error()) + } + }() + got = e2t_ssa(s) + t.Errorf("e2t_ssa(s) should panic") + +} + +func testAssertI2TOk(t *testing.T) { + if got := i2t_ssa(u); got != u { + t.Errorf("i2t_ssa(u)=%v want %v", got, u) + } +} + +func testAssertI2TPanic(t *testing.T) { + var got *U + defer func() { + if got != nil { + t.Errorf("i2t_ssa(s)=%v want nil", got) + } + e := recover() + err, ok := e.(*runtime.TypeAssertionError) + if !ok { + t.Errorf("i2t_ssa(s) panic type %T", e) + } + want := "interface conversion: main.I is *main.S, not *main.U" + if err.Error() != want { + t.Errorf("i2t_ssa(s) wrong error, want '%s', got '%s'", want, err.Error()) + } + }() + got = i2t_ssa(s) + t.Errorf("i2t_ssa(s) should panic") +} + +func e2t2_ssa(e interface{}) (*U, bool) { + u, ok := e.(*U) + return u, ok +} + +func i2t2_ssa(i I) (*U, bool) { + u, ok := i.(*U) + return u, ok +} + +func testAssertE2T2(t *testing.T) { + if got, ok := e2t2_ssa(u); !ok || got != u { + t.Errorf("e2t2_ssa(u)=(%v, %v) want (%v, %v)", got, ok, u, true) + } + if got, ok := e2t2_ssa(s); ok || got != nil { + t.Errorf("e2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false) + } +} + +func testAssertI2T2(t *testing.T) { + if got, ok := i2t2_ssa(u); !ok || got != u { + t.Errorf("i2t2_ssa(u)=(%v, %v) want (%v, %v)", got, ok, u, true) + } + if got, ok := i2t2_ssa(s); ok || got != nil { + t.Errorf("i2t2_ssa(s)=(%v, %v) want (%v, %v)", got, ok, nil, false) + } +} + +// TestTypeAssertion tests type assertions. +func TestTypeAssertion(t *testing.T) { + testAssertE2TOk(t) + testAssertE2TPanic(t) + testAssertI2TOk(t) + testAssertI2TPanic(t) + testAssertE2T2(t) + testAssertI2T2(t) +} diff --git a/src/cmd/compile/internal/gc/testdata/fp.go b/src/cmd/compile/internal/gc/testdata/fp_test.go similarity index 64% rename from src/cmd/compile/internal/gc/testdata/fp.go rename to src/cmd/compile/internal/gc/testdata/fp_test.go index 18082c5634910..daed2b417ad08 100644 --- a/src/cmd/compile/internal/gc/testdata/fp.go +++ b/src/cmd/compile/internal/gc/testdata/fp_test.go @@ -1,5 +1,3 @@ -// run - // Copyright 2015 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. @@ -8,7 +6,10 @@ package main -import "fmt" +import ( + "fmt" + "testing" +) // manysub_ssa is designed to tickle bugs that depend on register // pressure or unfriendly operand ordering in registers (and at @@ -159,81 +160,78 @@ func conv2Float32_ssa(a int8, b uint8, c int16, d uint16, return } -func integer2floatConversions() int { - fails := 0 +func integer2floatConversions(t *testing.T) { { a, b, c, d, e, f, g, h, i := conv2Float64_ssa(0, 0, 0, 0, 0, 0, 0, 0, 0) - fails += expectAll64("zero64", 0, a, b, c, d, e, f, g, h, i) + expectAll64(t, "zero64", 0, a, b, c, d, e, f, g, h, i) } { a, b, c, d, e, f, g, h, i := conv2Float64_ssa(1, 1, 1, 1, 1, 1, 1, 1, 1) - fails += expectAll64("one64", 1, a, b, c, d, e, f, g, h, i) + expectAll64(t, "one64", 1, a, b, c, d, e, f, g, h, i) } { a, b, c, d, e, f, g, h, i := conv2Float32_ssa(0, 0, 0, 0, 0, 0, 0, 0, 0) - fails += expectAll32("zero32", 0, a, b, c, d, e, f, g, h, i) + expectAll32(t, "zero32", 0, a, b, c, d, e, f, g, h, i) } { a, b, c, d, e, f, g, h, i := conv2Float32_ssa(1, 1, 1, 1, 1, 1, 1, 1, 1) - fails += expectAll32("one32", 1, a, b, c, d, e, f, g, h, i) + expectAll32(t, "one32", 1, a, b, c, d, e, f, g, h, i) } { // Check maximum values a, b, c, d, e, f, g, h, i := conv2Float64_ssa(127, 255, 32767, 65535, 0x7fffffff, 0xffffffff, 0x7fffFFFFffffFFFF, 0xffffFFFFffffFFFF, 3.402823E38) - fails += expect64("a", a, 127) - fails += expect64("b", b, 255) - fails += expect64("c", c, 32767) - fails += expect64("d", d, 65535) - fails += expect64("e", e, float64(int32(0x7fffffff))) - fails += expect64("f", f, float64(uint32(0xffffffff))) - fails += expect64("g", g, float64(int64(0x7fffffffffffffff))) - fails += expect64("h", h, float64(uint64(0xffffffffffffffff))) - fails += expect64("i", i, float64(float32(3.402823E38))) + expect64(t, "a", a, 127) + expect64(t, "b", b, 255) + expect64(t, "c", c, 32767) + expect64(t, "d", d, 65535) + expect64(t, "e", e, float64(int32(0x7fffffff))) + expect64(t, "f", f, float64(uint32(0xffffffff))) + expect64(t, "g", g, float64(int64(0x7fffffffffffffff))) + expect64(t, "h", h, float64(uint64(0xffffffffffffffff))) + expect64(t, "i", i, float64(float32(3.402823E38))) } { // Check minimum values (and tweaks for unsigned) a, b, c, d, e, f, g, h, i := conv2Float64_ssa(-128, 254, -32768, 65534, ^0x7fffffff, 0xfffffffe, ^0x7fffFFFFffffFFFF, 0xffffFFFFffffF401, 1.5E-45) - fails += expect64("a", a, -128) - fails += expect64("b", b, 254) - fails += expect64("c", c, -32768) - fails += expect64("d", d, 65534) - fails += expect64("e", e, float64(^int32(0x7fffffff))) - fails += expect64("f", f, float64(uint32(0xfffffffe))) - fails += expect64("g", g, float64(^int64(0x7fffffffffffffff))) - fails += expect64("h", h, float64(uint64(0xfffffffffffff401))) - fails += expect64("i", i, float64(float32(1.5E-45))) + expect64(t, "a", a, -128) + expect64(t, "b", b, 254) + expect64(t, "c", c, -32768) + expect64(t, "d", d, 65534) + expect64(t, "e", e, float64(^int32(0x7fffffff))) + expect64(t, "f", f, float64(uint32(0xfffffffe))) + expect64(t, "g", g, float64(^int64(0x7fffffffffffffff))) + expect64(t, "h", h, float64(uint64(0xfffffffffffff401))) + expect64(t, "i", i, float64(float32(1.5E-45))) } { // Check maximum values a, b, c, d, e, f, g, h, i := conv2Float32_ssa(127, 255, 32767, 65535, 0x7fffffff, 0xffffffff, 0x7fffFFFFffffFFFF, 0xffffFFFFffffFFFF, 3.402823E38) - fails += expect32("a", a, 127) - fails += expect32("b", b, 255) - fails += expect32("c", c, 32767) - fails += expect32("d", d, 65535) - fails += expect32("e", e, float32(int32(0x7fffffff))) - fails += expect32("f", f, float32(uint32(0xffffffff))) - fails += expect32("g", g, float32(int64(0x7fffffffffffffff))) - fails += expect32("h", h, float32(uint64(0xffffffffffffffff))) - fails += expect32("i", i, float32(float64(3.402823E38))) + expect32(t, "a", a, 127) + expect32(t, "b", b, 255) + expect32(t, "c", c, 32767) + expect32(t, "d", d, 65535) + expect32(t, "e", e, float32(int32(0x7fffffff))) + expect32(t, "f", f, float32(uint32(0xffffffff))) + expect32(t, "g", g, float32(int64(0x7fffffffffffffff))) + expect32(t, "h", h, float32(uint64(0xffffffffffffffff))) + expect32(t, "i", i, float32(float64(3.402823E38))) } { // Check minimum values (and tweaks for unsigned) a, b, c, d, e, f, g, h, i := conv2Float32_ssa(-128, 254, -32768, 65534, ^0x7fffffff, 0xfffffffe, ^0x7fffFFFFffffFFFF, 0xffffFFFFffffF401, 1.5E-45) - fails += expect32("a", a, -128) - fails += expect32("b", b, 254) - fails += expect32("c", c, -32768) - fails += expect32("d", d, 65534) - fails += expect32("e", e, float32(^int32(0x7fffffff))) - fails += expect32("f", f, float32(uint32(0xfffffffe))) - fails += expect32("g", g, float32(^int64(0x7fffffffffffffff))) - fails += expect32("h", h, float32(uint64(0xfffffffffffff401))) - fails += expect32("i", i, float32(float64(1.5E-45))) + expect32(t, "a", a, -128) + expect32(t, "b", b, 254) + expect32(t, "c", c, -32768) + expect32(t, "d", d, 65534) + expect32(t, "e", e, float32(^int32(0x7fffffff))) + expect32(t, "f", f, float32(uint32(0xfffffffe))) + expect32(t, "g", g, float32(^int64(0x7fffffffffffffff))) + expect32(t, "h", h, float32(uint64(0xfffffffffffff401))) + expect32(t, "i", i, float32(float64(1.5E-45))) } - return fails } -func multiplyAdd() int { - fails := 0 +func multiplyAdd(t *testing.T) { { // Test that a multiply-accumulate operation with intermediate // rounding forced by a float32() cast produces the expected @@ -252,22 +250,20 @@ func multiplyAdd() int { {0.6280982, 0.12675293, 0.2813303, 0.36094356}, // fused multiply-add result: 0.3609436 {0.29400632, 0.75316125, 0.15096405, 0.3723982}, // fused multiply-add result: 0.37239823 } - check := func(s string, got, expected float32) int { + check := func(s string, got, expected float32) { if got != expected { fmt.Printf("multiplyAdd: %s, expected %g, got %g\n", s, expected, got) - return 1 } - return 0 } for _, t := range tests { - fails += check( + check( fmt.Sprintf("float32(%v * %v) + %v", t.x, t.y, t.z), func(x, y, z float32) float32 { return float32(x*y) + z }(t.x, t.y, t.z), t.res) - fails += check( + check( fmt.Sprintf("%v += float32(%v * %v)", t.z, t.x, t.y), func(x, y, z float32) float32 { z += float32(x * y) @@ -294,22 +290,20 @@ func multiplyAdd() int { {0.3691117091643448, 0.826454125634742, 0.34768170859156955, 0.6527356034505334}, // fused multiply-add result: 0.6527356034505333 {0.16867966833433606, 0.33136826030698385, 0.8279280961505588, 0.8838231843956668}, // fused multiply-add result: 0.8838231843956669 } - check := func(s string, got, expected float64) int { + check := func(s string, got, expected float64) { if got != expected { fmt.Printf("multiplyAdd: %s, expected %g, got %g\n", s, expected, got) - return 1 } - return 0 } for _, t := range tests { - fails += check( + check( fmt.Sprintf("float64(%v * %v) + %v", t.x, t.y, t.z), func(x, y, z float64) float64 { return float64(x*y) + z }(t.x, t.y, t.z), t.res) - fails += check( + check( fmt.Sprintf("%v += float64(%v * %v)", t.z, t.x, t.y), func(x, y, z float64) float64 { z += float64(x * y) @@ -339,22 +333,20 @@ func multiplyAdd() int { {0.8963417453962161, 0.3220839705208817, (3.0111092067095298 + 3i)}, // fused multiply-add result: (3.01110920670953 + 3i) {0.39998376285699544, 0.497868113342702, (1.697819401913688 + 3i)}, // fused multiply-add result: (1.6978194019136883 + 3i) } - check := func(s string, got, expected complex128) int { + check := func(s string, got, expected complex128) { if got != expected { fmt.Printf("multiplyAdd: %s, expected %v, got %v\n", s, expected, got) - return 1 } - return 0 } for _, t := range tests { - fails += check( + check( fmt.Sprintf("complex128(complex(%v, 1)*3) + complex(%v, 0)", t.x, t.y), func(x, y float64) complex128 { return complex128(complex(x, 1)*3) + complex(y, 0) }(t.x, t.y), t.res) - fails += check( + check( fmt.Sprintf("z := complex(%v, 1); z += complex128(complex(%v, 1) * 3)", t.y, t.x), func(x, y float64) complex128 { z := complex(y, 0) @@ -364,7 +356,6 @@ func multiplyAdd() int { t.res) } } - return fails } const ( @@ -1256,48 +1247,43 @@ func F64toI64_ssa(x float64) int64 { return int64(x) } -func floatsToInts(x float64, expected int64) int { +func floatsToInts(t *testing.T, x float64, expected int64) { y := float32(x) - fails := 0 - fails += expectInt64("F64toI8", int64(F64toI8_ssa(x)), expected) - fails += expectInt64("F64toI16", int64(F64toI16_ssa(x)), expected) - fails += expectInt64("F64toI32", int64(F64toI32_ssa(x)), expected) - fails += expectInt64("F64toI64", int64(F64toI64_ssa(x)), expected) - fails += expectInt64("F32toI8", int64(F32toI8_ssa(y)), expected) - fails += expectInt64("F32toI16", int64(F32toI16_ssa(y)), expected) - fails += expectInt64("F32toI32", int64(F32toI32_ssa(y)), expected) - fails += expectInt64("F32toI64", int64(F32toI64_ssa(y)), expected) - return fails -} - -func floatsToUints(x float64, expected uint64) int { + expectInt64(t, "F64toI8", int64(F64toI8_ssa(x)), expected) + expectInt64(t, "F64toI16", int64(F64toI16_ssa(x)), expected) + expectInt64(t, "F64toI32", int64(F64toI32_ssa(x)), expected) + expectInt64(t, "F64toI64", int64(F64toI64_ssa(x)), expected) + expectInt64(t, "F32toI8", int64(F32toI8_ssa(y)), expected) + expectInt64(t, "F32toI16", int64(F32toI16_ssa(y)), expected) + expectInt64(t, "F32toI32", int64(F32toI32_ssa(y)), expected) + expectInt64(t, "F32toI64", int64(F32toI64_ssa(y)), expected) +} + +func floatsToUints(t *testing.T, x float64, expected uint64) { y := float32(x) - fails := 0 - fails += expectUint64("F64toU8", uint64(F64toU8_ssa(x)), expected) - fails += expectUint64("F64toU16", uint64(F64toU16_ssa(x)), expected) - fails += expectUint64("F64toU32", uint64(F64toU32_ssa(x)), expected) - fails += expectUint64("F64toU64", uint64(F64toU64_ssa(x)), expected) - fails += expectUint64("F32toU8", uint64(F32toU8_ssa(y)), expected) - fails += expectUint64("F32toU16", uint64(F32toU16_ssa(y)), expected) - fails += expectUint64("F32toU32", uint64(F32toU32_ssa(y)), expected) - fails += expectUint64("F32toU64", uint64(F32toU64_ssa(y)), expected) - return fails -} - -func floatingToIntegerConversionsTest() int { - fails := 0 - fails += floatsToInts(0.0, 0) - fails += floatsToInts(0.5, 0) - fails += floatsToInts(0.9, 0) - fails += floatsToInts(1.0, 1) - fails += floatsToInts(1.5, 1) - fails += floatsToInts(127.0, 127) - fails += floatsToInts(-1.0, -1) - fails += floatsToInts(-128.0, -128) - - fails += floatsToUints(0.0, 0) - fails += floatsToUints(1.0, 1) - fails += floatsToUints(255.0, 255) + expectUint64(t, "F64toU8", uint64(F64toU8_ssa(x)), expected) + expectUint64(t, "F64toU16", uint64(F64toU16_ssa(x)), expected) + expectUint64(t, "F64toU32", uint64(F64toU32_ssa(x)), expected) + expectUint64(t, "F64toU64", uint64(F64toU64_ssa(x)), expected) + expectUint64(t, "F32toU8", uint64(F32toU8_ssa(y)), expected) + expectUint64(t, "F32toU16", uint64(F32toU16_ssa(y)), expected) + expectUint64(t, "F32toU32", uint64(F32toU32_ssa(y)), expected) + expectUint64(t, "F32toU64", uint64(F32toU64_ssa(y)), expected) +} + +func floatingToIntegerConversionsTest(t *testing.T) { + floatsToInts(t, 0.0, 0) + floatsToInts(t, 0.5, 0) + floatsToInts(t, 0.9, 0) + floatsToInts(t, 1.0, 1) + floatsToInts(t, 1.5, 1) + floatsToInts(t, 127.0, 127) + floatsToInts(t, -1.0, -1) + floatsToInts(t, -128.0, -128) + + floatsToUints(t, 0.0, 0) + floatsToUints(t, 1.0, 1) + floatsToUints(t, 255.0, 255) for j := uint(0); j < 24; j++ { // Avoid hard cases in the construction @@ -1306,17 +1292,17 @@ func floatingToIntegerConversionsTest() int { w := uint64(v) f := float32(v) d := float64(v) - fails += expectUint64("2**62...", F32toU64_ssa(f), w) - fails += expectUint64("2**62...", F64toU64_ssa(d), w) - fails += expectInt64("2**62...", F32toI64_ssa(f), v) - fails += expectInt64("2**62...", F64toI64_ssa(d), v) - fails += expectInt64("2**62...", F32toI64_ssa(-f), -v) - fails += expectInt64("2**62...", F64toI64_ssa(-d), -v) + expectUint64(t, "2**62...", F32toU64_ssa(f), w) + expectUint64(t, "2**62...", F64toU64_ssa(d), w) + expectInt64(t, "2**62...", F32toI64_ssa(f), v) + expectInt64(t, "2**62...", F64toI64_ssa(d), v) + expectInt64(t, "2**62...", F32toI64_ssa(-f), -v) + expectInt64(t, "2**62...", F64toI64_ssa(-d), -v) w += w f += f d += d - fails += expectUint64("2**63...", F32toU64_ssa(f), w) - fails += expectUint64("2**63...", F64toU64_ssa(d), w) + expectUint64(t, "2**63...", F32toU64_ssa(f), w) + expectUint64(t, "2**63...", F64toU64_ssa(d), w) } for j := uint(0); j < 16; j++ { @@ -1326,17 +1312,17 @@ func floatingToIntegerConversionsTest() int { w := uint32(v) f := float32(v) d := float64(v) - fails += expectUint32("2**30...", F32toU32_ssa(f), w) - fails += expectUint32("2**30...", F64toU32_ssa(d), w) - fails += expectInt32("2**30...", F32toI32_ssa(f), v) - fails += expectInt32("2**30...", F64toI32_ssa(d), v) - fails += expectInt32("2**30...", F32toI32_ssa(-f), -v) - fails += expectInt32("2**30...", F64toI32_ssa(-d), -v) + expectUint32(t, "2**30...", F32toU32_ssa(f), w) + expectUint32(t, "2**30...", F64toU32_ssa(d), w) + expectInt32(t, "2**30...", F32toI32_ssa(f), v) + expectInt32(t, "2**30...", F64toI32_ssa(d), v) + expectInt32(t, "2**30...", F32toI32_ssa(-f), -v) + expectInt32(t, "2**30...", F64toI32_ssa(-d), -v) w += w f += f d += d - fails += expectUint32("2**31...", F32toU32_ssa(f), w) - fails += expectUint32("2**31...", F64toU32_ssa(d), w) + expectUint32(t, "2**31...", F32toU32_ssa(f), w) + expectUint32(t, "2**31...", F64toU32_ssa(d), w) } for j := uint(0); j < 15; j++ { @@ -1346,220 +1332,184 @@ func floatingToIntegerConversionsTest() int { w := uint16(v) f := float32(v) d := float64(v) - fails += expectUint16("2**14...", F32toU16_ssa(f), w) - fails += expectUint16("2**14...", F64toU16_ssa(d), w) - fails += expectInt16("2**14...", F32toI16_ssa(f), v) - fails += expectInt16("2**14...", F64toI16_ssa(d), v) - fails += expectInt16("2**14...", F32toI16_ssa(-f), -v) - fails += expectInt16("2**14...", F64toI16_ssa(-d), -v) + expectUint16(t, "2**14...", F32toU16_ssa(f), w) + expectUint16(t, "2**14...", F64toU16_ssa(d), w) + expectInt16(t, "2**14...", F32toI16_ssa(f), v) + expectInt16(t, "2**14...", F64toI16_ssa(d), v) + expectInt16(t, "2**14...", F32toI16_ssa(-f), -v) + expectInt16(t, "2**14...", F64toI16_ssa(-d), -v) w += w f += f d += d - fails += expectUint16("2**15...", F32toU16_ssa(f), w) - fails += expectUint16("2**15...", F64toU16_ssa(d), w) + expectUint16(t, "2**15...", F32toU16_ssa(f), w) + expectUint16(t, "2**15...", F64toU16_ssa(d), w) } - fails += expectInt32("-2147483648", F32toI32_ssa(-2147483648), -2147483648) + expectInt32(t, "-2147483648", F32toI32_ssa(-2147483648), -2147483648) - fails += expectInt32("-2147483648", F64toI32_ssa(-2147483648), -2147483648) - fails += expectInt32("-2147483647", F64toI32_ssa(-2147483647), -2147483647) - fails += expectUint32("4294967295", F64toU32_ssa(4294967295), 4294967295) + expectInt32(t, "-2147483648", F64toI32_ssa(-2147483648), -2147483648) + expectInt32(t, "-2147483647", F64toI32_ssa(-2147483647), -2147483647) + expectUint32(t, "4294967295", F64toU32_ssa(4294967295), 4294967295) - fails += expectInt16("-32768", F64toI16_ssa(-32768), -32768) - fails += expectInt16("-32768", F32toI16_ssa(-32768), -32768) + expectInt16(t, "-32768", F64toI16_ssa(-32768), -32768) + expectInt16(t, "-32768", F32toI16_ssa(-32768), -32768) // NB more of a pain to do these for 32-bit because of lost bits in Float32 mantissa - fails += expectInt16("32767", F64toI16_ssa(32767), 32767) - fails += expectInt16("32767", F32toI16_ssa(32767), 32767) - fails += expectUint16("32767", F64toU16_ssa(32767), 32767) - fails += expectUint16("32767", F32toU16_ssa(32767), 32767) - fails += expectUint16("65535", F64toU16_ssa(65535), 65535) - fails += expectUint16("65535", F32toU16_ssa(65535), 65535) - - return fails + expectInt16(t, "32767", F64toI16_ssa(32767), 32767) + expectInt16(t, "32767", F32toI16_ssa(32767), 32767) + expectUint16(t, "32767", F64toU16_ssa(32767), 32767) + expectUint16(t, "32767", F32toU16_ssa(32767), 32767) + expectUint16(t, "65535", F64toU16_ssa(65535), 65535) + expectUint16(t, "65535", F32toU16_ssa(65535), 65535) } -func fail64(s string, f func(a, b float64) float64, a, b, e float64) int { +func fail64(s string, f func(a, b float64) float64, a, b, e float64) { d := f(a, b) if d != e { fmt.Printf("For (float64) %v %v %v, expected %v, got %v\n", a, s, b, e, d) - return 1 } - return 0 } -func fail64bool(s string, f func(a, b float64) bool, a, b float64, e bool) int { +func fail64bool(s string, f func(a, b float64) bool, a, b float64, e bool) { d := f(a, b) if d != e { fmt.Printf("For (float64) %v %v %v, expected %v, got %v\n", a, s, b, e, d) - return 1 } - return 0 } -func fail32(s string, f func(a, b float32) float32, a, b, e float32) int { +func fail32(s string, f func(a, b float32) float32, a, b, e float32) { d := f(a, b) if d != e { fmt.Printf("For (float32) %v %v %v, expected %v, got %v\n", a, s, b, e, d) - return 1 } - return 0 } -func fail32bool(s string, f func(a, b float32) bool, a, b float32, e bool) int { +func fail32bool(s string, f func(a, b float32) bool, a, b float32, e bool) { d := f(a, b) if d != e { fmt.Printf("For (float32) %v %v %v, expected %v, got %v\n", a, s, b, e, d) - return 1 } - return 0 } -func expect64(s string, x, expected float64) int { +func expect64(t *testing.T, s string, x, expected float64) { if x != expected { println("F64 Expected", expected, "for", s, ", got", x) - return 1 } - return 0 } -func expect32(s string, x, expected float32) int { +func expect32(t *testing.T, s string, x, expected float32) { if x != expected { println("F32 Expected", expected, "for", s, ", got", x) - return 1 } - return 0 } -func expectUint64(s string, x, expected uint64) int { +func expectUint64(t *testing.T, s string, x, expected uint64) { if x != expected { fmt.Printf("U64 Expected 0x%016x for %s, got 0x%016x\n", expected, s, x) - return 1 } - return 0 } -func expectInt64(s string, x, expected int64) int { +func expectInt64(t *testing.T, s string, x, expected int64) { if x != expected { fmt.Printf("%s: Expected 0x%016x, got 0x%016x\n", s, expected, x) - return 1 } - return 0 } -func expectUint32(s string, x, expected uint32) int { +func expectUint32(t *testing.T, s string, x, expected uint32) { if x != expected { fmt.Printf("U32 %s: Expected 0x%08x, got 0x%08x\n", s, expected, x) - return 1 } - return 0 } -func expectInt32(s string, x, expected int32) int { +func expectInt32(t *testing.T, s string, x, expected int32) { if x != expected { fmt.Printf("I32 %s: Expected 0x%08x, got 0x%08x\n", s, expected, x) - return 1 } - return 0 } -func expectUint16(s string, x, expected uint16) int { +func expectUint16(t *testing.T, s string, x, expected uint16) { if x != expected { fmt.Printf("U16 %s: Expected 0x%04x, got 0x%04x\n", s, expected, x) - return 1 } - return 0 } -func expectInt16(s string, x, expected int16) int { +func expectInt16(t *testing.T, s string, x, expected int16) { if x != expected { fmt.Printf("I16 %s: Expected 0x%04x, got 0x%04x\n", s, expected, x) - return 1 } - return 0 } -func expectAll64(s string, expected, a, b, c, d, e, f, g, h, i float64) int { - fails := 0 - fails += expect64(s+":a", a, expected) - fails += expect64(s+":b", b, expected) - fails += expect64(s+":c", c, expected) - fails += expect64(s+":d", d, expected) - fails += expect64(s+":e", e, expected) - fails += expect64(s+":f", f, expected) - fails += expect64(s+":g", g, expected) - return fails +func expectAll64(t *testing.T, s string, expected, a, b, c, d, e, f, g, h, i float64) { + expect64(t, s+":a", a, expected) + expect64(t, s+":b", b, expected) + expect64(t, s+":c", c, expected) + expect64(t, s+":d", d, expected) + expect64(t, s+":e", e, expected) + expect64(t, s+":f", f, expected) + expect64(t, s+":g", g, expected) } -func expectAll32(s string, expected, a, b, c, d, e, f, g, h, i float32) int { - fails := 0 - fails += expect32(s+":a", a, expected) - fails += expect32(s+":b", b, expected) - fails += expect32(s+":c", c, expected) - fails += expect32(s+":d", d, expected) - fails += expect32(s+":e", e, expected) - fails += expect32(s+":f", f, expected) - fails += expect32(s+":g", g, expected) - return fails +func expectAll32(t *testing.T, s string, expected, a, b, c, d, e, f, g, h, i float32) { + expect32(t, s+":a", a, expected) + expect32(t, s+":b", b, expected) + expect32(t, s+":c", c, expected) + expect32(t, s+":d", d, expected) + expect32(t, s+":e", e, expected) + expect32(t, s+":f", f, expected) + expect32(t, s+":g", g, expected) } var ev64 [2]float64 = [2]float64{42.0, 17.0} var ev32 [2]float32 = [2]float32{42.0, 17.0} -func cmpOpTest(s string, +func cmpOpTest(t *testing.T, + s string, f func(a, b float64) bool, g func(a, b float64) float64, ff func(a, b float32) bool, gg func(a, b float32) float32, - zero, one, inf, nan float64, result uint) int { - fails := 0 - fails += fail64bool(s, f, zero, zero, result>>16&1 == 1) - fails += fail64bool(s, f, zero, one, result>>12&1 == 1) - fails += fail64bool(s, f, zero, inf, result>>8&1 == 1) - fails += fail64bool(s, f, zero, nan, result>>4&1 == 1) - fails += fail64bool(s, f, nan, nan, result&1 == 1) - - fails += fail64(s, g, zero, zero, ev64[result>>16&1]) - fails += fail64(s, g, zero, one, ev64[result>>12&1]) - fails += fail64(s, g, zero, inf, ev64[result>>8&1]) - fails += fail64(s, g, zero, nan, ev64[result>>4&1]) - fails += fail64(s, g, nan, nan, ev64[result>>0&1]) + zero, one, inf, nan float64, result uint) { + fail64bool(s, f, zero, zero, result>>16&1 == 1) + fail64bool(s, f, zero, one, result>>12&1 == 1) + fail64bool(s, f, zero, inf, result>>8&1 == 1) + fail64bool(s, f, zero, nan, result>>4&1 == 1) + fail64bool(s, f, nan, nan, result&1 == 1) + + fail64(s, g, zero, zero, ev64[result>>16&1]) + fail64(s, g, zero, one, ev64[result>>12&1]) + fail64(s, g, zero, inf, ev64[result>>8&1]) + fail64(s, g, zero, nan, ev64[result>>4&1]) + fail64(s, g, nan, nan, ev64[result>>0&1]) { zero := float32(zero) one := float32(one) inf := float32(inf) nan := float32(nan) - fails += fail32bool(s, ff, zero, zero, (result>>16)&1 == 1) - fails += fail32bool(s, ff, zero, one, (result>>12)&1 == 1) - fails += fail32bool(s, ff, zero, inf, (result>>8)&1 == 1) - fails += fail32bool(s, ff, zero, nan, (result>>4)&1 == 1) - fails += fail32bool(s, ff, nan, nan, result&1 == 1) + fail32bool(s, ff, zero, zero, (result>>16)&1 == 1) + fail32bool(s, ff, zero, one, (result>>12)&1 == 1) + fail32bool(s, ff, zero, inf, (result>>8)&1 == 1) + fail32bool(s, ff, zero, nan, (result>>4)&1 == 1) + fail32bool(s, ff, nan, nan, result&1 == 1) - fails += fail32(s, gg, zero, zero, ev32[(result>>16)&1]) - fails += fail32(s, gg, zero, one, ev32[(result>>12)&1]) - fails += fail32(s, gg, zero, inf, ev32[(result>>8)&1]) - fails += fail32(s, gg, zero, nan, ev32[(result>>4)&1]) - fails += fail32(s, gg, nan, nan, ev32[(result>>0)&1]) + fail32(s, gg, zero, zero, ev32[(result>>16)&1]) + fail32(s, gg, zero, one, ev32[(result>>12)&1]) + fail32(s, gg, zero, inf, ev32[(result>>8)&1]) + fail32(s, gg, zero, nan, ev32[(result>>4)&1]) + fail32(s, gg, nan, nan, ev32[(result>>0)&1]) } - - return fails } -func expectCx128(s string, x, expected complex128) int { +func expectCx128(t *testing.T, s string, x, expected complex128) { if x != expected { - println("Cx 128 Expected", expected, "for", s, ", got", x) - return 1 + t.Errorf("Cx 128 Expected %f for %s, got %f", expected, s, x) } - return 0 } -func expectCx64(s string, x, expected complex64) int { +func expectCx64(t *testing.T, s string, x, expected complex64) { if x != expected { - println("Cx 64 Expected", expected, "for", s, ", got", x) - return 1 + t.Errorf("Cx 64 Expected %f for %s, got %f", expected, s, x) } - return 0 } //go:noinline @@ -1658,23 +1608,18 @@ func cx64ne_ssa(a, b complex64) bool { return a != b } -func expectTrue(s string, b bool) int { +func expectTrue(t *testing.T, s string, b bool) { if !b { - println("expected true for", s, ", got false") - return 1 + t.Errorf("expected true for %s, got false", s) } - return 0 } -func expectFalse(s string, b bool) int { +func expectFalse(t *testing.T, s string, b bool) { if b { - println("expected false for", s, ", got true") - return 1 + t.Errorf("expected false for %s, got true", s) } - return 0 } -func complexTest128() int { - fails := 0 +func complexTest128(t *testing.T) { var a complex128 = 1 + 2i var b complex128 = 3 + 6i sum := cx128sum_ssa(b, a) @@ -1690,24 +1635,21 @@ func complexTest128() int { c3 := cx128ne_ssa(a, a) c4 := cx128ne_ssa(a, b) - fails += expectCx128("sum", sum, 4+8i) - fails += expectCx128("diff", diff, 2+4i) - fails += expectCx128("prod", prod, -9+12i) - fails += expectCx128("quot", quot, 3+0i) - fails += expectCx128("neg", neg, -1-2i) - fails += expect64("real", r, 1) - fails += expect64("imag", i, 2) - fails += expectCx128("cnst", cnst, -4+7i) - fails += expectTrue(fmt.Sprintf("%v==%v", a, a), c1) - fails += expectFalse(fmt.Sprintf("%v==%v", a, b), c2) - fails += expectFalse(fmt.Sprintf("%v!=%v", a, a), c3) - fails += expectTrue(fmt.Sprintf("%v!=%v", a, b), c4) - - return fails -} - -func complexTest64() int { - fails := 0 + expectCx128(t, "sum", sum, 4+8i) + expectCx128(t, "diff", diff, 2+4i) + expectCx128(t, "prod", prod, -9+12i) + expectCx128(t, "quot", quot, 3+0i) + expectCx128(t, "neg", neg, -1-2i) + expect64(t, "real", r, 1) + expect64(t, "imag", i, 2) + expectCx128(t, "cnst", cnst, -4+7i) + expectTrue(t, fmt.Sprintf("%v==%v", a, a), c1) + expectFalse(t, fmt.Sprintf("%v==%v", a, b), c2) + expectFalse(t, fmt.Sprintf("%v!=%v", a, a), c3) + expectTrue(t, fmt.Sprintf("%v!=%v", a, b), c4) +} + +func complexTest64(t *testing.T) { var a complex64 = 1 + 2i var b complex64 = 3 + 6i sum := cx64sum_ssa(b, a) @@ -1722,23 +1664,21 @@ func complexTest64() int { c3 := cx64ne_ssa(a, a) c4 := cx64ne_ssa(a, b) - fails += expectCx64("sum", sum, 4+8i) - fails += expectCx64("diff", diff, 2+4i) - fails += expectCx64("prod", prod, -9+12i) - fails += expectCx64("quot", quot, 3+0i) - fails += expectCx64("neg", neg, -1-2i) - fails += expect32("real", r, 1) - fails += expect32("imag", i, 2) - fails += expectTrue(fmt.Sprintf("%v==%v", a, a), c1) - fails += expectFalse(fmt.Sprintf("%v==%v", a, b), c2) - fails += expectFalse(fmt.Sprintf("%v!=%v", a, a), c3) - fails += expectTrue(fmt.Sprintf("%v!=%v", a, b), c4) - - return fails -} - -func main() { - + expectCx64(t, "sum", sum, 4+8i) + expectCx64(t, "diff", diff, 2+4i) + expectCx64(t, "prod", prod, -9+12i) + expectCx64(t, "quot", quot, 3+0i) + expectCx64(t, "neg", neg, -1-2i) + expect32(t, "real", r, 1) + expect32(t, "imag", i, 2) + expectTrue(t, fmt.Sprintf("%v==%v", a, a), c1) + expectFalse(t, fmt.Sprintf("%v==%v", a, b), c2) + expectFalse(t, fmt.Sprintf("%v!=%v", a, a), c3) + expectTrue(t, fmt.Sprintf("%v!=%v", a, b), c4) +} + +// TestFP tests that we get the right answer for floating point expressions. +func TestFP(t *testing.T) { a := 3.0 b := 4.0 @@ -1748,92 +1688,86 @@ func main() { tiny := float32(1.5E-45) // smallest f32 denorm = 2**(-149) dtiny := float64(tiny) // well within range of f64 - fails := 0 - fails += fail64("+", add64_ssa, a, b, 7.0) - fails += fail64("*", mul64_ssa, a, b, 12.0) - fails += fail64("-", sub64_ssa, a, b, -1.0) - fails += fail64("/", div64_ssa, a, b, 0.75) - fails += fail64("neg", neg64_ssa, a, b, -7) + fail64("+", add64_ssa, a, b, 7.0) + fail64("*", mul64_ssa, a, b, 12.0) + fail64("-", sub64_ssa, a, b, -1.0) + fail64("/", div64_ssa, a, b, 0.75) + fail64("neg", neg64_ssa, a, b, -7) - fails += fail32("+", add32_ssa, c, d, 7.0) - fails += fail32("*", mul32_ssa, c, d, 12.0) - fails += fail32("-", sub32_ssa, c, d, -1.0) - fails += fail32("/", div32_ssa, c, d, 0.75) - fails += fail32("neg", neg32_ssa, c, d, -7) + fail32("+", add32_ssa, c, d, 7.0) + fail32("*", mul32_ssa, c, d, 12.0) + fail32("-", sub32_ssa, c, d, -1.0) + fail32("/", div32_ssa, c, d, 0.75) + fail32("neg", neg32_ssa, c, d, -7) // denorm-squared should underflow to zero. - fails += fail32("*", mul32_ssa, tiny, tiny, 0) + fail32("*", mul32_ssa, tiny, tiny, 0) // but should not underflow in float and in fact is exactly representable. - fails += fail64("*", mul64_ssa, dtiny, dtiny, 1.9636373861190906e-90) + fail64("*", mul64_ssa, dtiny, dtiny, 1.9636373861190906e-90) // Intended to create register pressure which forces // asymmetric op into different code paths. aa, ab, ac, ad, ba, bb, bc, bd, ca, cb, cc, cd, da, db, dc, dd := manysub_ssa(1000.0, 100.0, 10.0, 1.0) - fails += expect64("aa", aa, 11.0) - fails += expect64("ab", ab, 900.0) - fails += expect64("ac", ac, 990.0) - fails += expect64("ad", ad, 999.0) + expect64(t, "aa", aa, 11.0) + expect64(t, "ab", ab, 900.0) + expect64(t, "ac", ac, 990.0) + expect64(t, "ad", ad, 999.0) - fails += expect64("ba", ba, -900.0) - fails += expect64("bb", bb, 22.0) - fails += expect64("bc", bc, 90.0) - fails += expect64("bd", bd, 99.0) + expect64(t, "ba", ba, -900.0) + expect64(t, "bb", bb, 22.0) + expect64(t, "bc", bc, 90.0) + expect64(t, "bd", bd, 99.0) - fails += expect64("ca", ca, -990.0) - fails += expect64("cb", cb, -90.0) - fails += expect64("cc", cc, 33.0) - fails += expect64("cd", cd, 9.0) + expect64(t, "ca", ca, -990.0) + expect64(t, "cb", cb, -90.0) + expect64(t, "cc", cc, 33.0) + expect64(t, "cd", cd, 9.0) - fails += expect64("da", da, -999.0) - fails += expect64("db", db, -99.0) - fails += expect64("dc", dc, -9.0) - fails += expect64("dd", dd, 44.0) + expect64(t, "da", da, -999.0) + expect64(t, "db", db, -99.0) + expect64(t, "dc", dc, -9.0) + expect64(t, "dd", dd, 44.0) - fails += integer2floatConversions() + integer2floatConversions(t) - fails += multiplyAdd() + multiplyAdd(t) var zero64 float64 = 0.0 var one64 float64 = 1.0 var inf64 float64 = 1.0 / zero64 var nan64 float64 = sub64_ssa(inf64, inf64) - fails += cmpOpTest("!=", ne64_ssa, nebr64_ssa, ne32_ssa, nebr32_ssa, zero64, one64, inf64, nan64, 0x01111) - fails += cmpOpTest("==", eq64_ssa, eqbr64_ssa, eq32_ssa, eqbr32_ssa, zero64, one64, inf64, nan64, 0x10000) - fails += cmpOpTest("<=", le64_ssa, lebr64_ssa, le32_ssa, lebr32_ssa, zero64, one64, inf64, nan64, 0x11100) - fails += cmpOpTest("<", lt64_ssa, ltbr64_ssa, lt32_ssa, ltbr32_ssa, zero64, one64, inf64, nan64, 0x01100) - fails += cmpOpTest(">", gt64_ssa, gtbr64_ssa, gt32_ssa, gtbr32_ssa, zero64, one64, inf64, nan64, 0x00000) - fails += cmpOpTest(">=", ge64_ssa, gebr64_ssa, ge32_ssa, gebr32_ssa, zero64, one64, inf64, nan64, 0x10000) + cmpOpTest(t, "!=", ne64_ssa, nebr64_ssa, ne32_ssa, nebr32_ssa, zero64, one64, inf64, nan64, 0x01111) + cmpOpTest(t, "==", eq64_ssa, eqbr64_ssa, eq32_ssa, eqbr32_ssa, zero64, one64, inf64, nan64, 0x10000) + cmpOpTest(t, "<=", le64_ssa, lebr64_ssa, le32_ssa, lebr32_ssa, zero64, one64, inf64, nan64, 0x11100) + cmpOpTest(t, "<", lt64_ssa, ltbr64_ssa, lt32_ssa, ltbr32_ssa, zero64, one64, inf64, nan64, 0x01100) + cmpOpTest(t, ">", gt64_ssa, gtbr64_ssa, gt32_ssa, gtbr32_ssa, zero64, one64, inf64, nan64, 0x00000) + cmpOpTest(t, ">=", ge64_ssa, gebr64_ssa, ge32_ssa, gebr32_ssa, zero64, one64, inf64, nan64, 0x10000) { lt, le, eq, ne, ge, gt := compares64_ssa(0.0, 1.0, inf64, nan64) - fails += expectUint64("lt", lt, 0x0110001000000000) - fails += expectUint64("le", le, 0x1110011000100000) - fails += expectUint64("eq", eq, 0x1000010000100000) - fails += expectUint64("ne", ne, 0x0111101111011111) - fails += expectUint64("ge", ge, 0x1000110011100000) - fails += expectUint64("gt", gt, 0x0000100011000000) + expectUint64(t, "lt", lt, 0x0110001000000000) + expectUint64(t, "le", le, 0x1110011000100000) + expectUint64(t, "eq", eq, 0x1000010000100000) + expectUint64(t, "ne", ne, 0x0111101111011111) + expectUint64(t, "ge", ge, 0x1000110011100000) + expectUint64(t, "gt", gt, 0x0000100011000000) // fmt.Printf("lt=0x%016x, le=0x%016x, eq=0x%016x, ne=0x%016x, ge=0x%016x, gt=0x%016x\n", // lt, le, eq, ne, ge, gt) } { lt, le, eq, ne, ge, gt := compares32_ssa(0.0, 1.0, float32(inf64), float32(nan64)) - fails += expectUint64("lt", lt, 0x0110001000000000) - fails += expectUint64("le", le, 0x1110011000100000) - fails += expectUint64("eq", eq, 0x1000010000100000) - fails += expectUint64("ne", ne, 0x0111101111011111) - fails += expectUint64("ge", ge, 0x1000110011100000) - fails += expectUint64("gt", gt, 0x0000100011000000) + expectUint64(t, "lt", lt, 0x0110001000000000) + expectUint64(t, "le", le, 0x1110011000100000) + expectUint64(t, "eq", eq, 0x1000010000100000) + expectUint64(t, "ne", ne, 0x0111101111011111) + expectUint64(t, "ge", ge, 0x1000110011100000) + expectUint64(t, "gt", gt, 0x0000100011000000) } - fails += floatingToIntegerConversionsTest() - fails += complexTest128() - fails += complexTest64() - - if fails > 0 { - fmt.Printf("Saw %v failures\n", fails) - panic("Failed.") - } + floatingToIntegerConversionsTest(t) + complexTest128(t) + complexTest64(t) } From 776298abdc59141c0828d44d9427ea73e92a0686 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 31 Jul 2018 14:57:37 -0700 Subject: [PATCH 0189/1663] cmd/compile: move autogenerated tests to new infrastructure Update #26469 R=go1.12 Change-Id: Ib9a00ee5e98371769669bb9cad58320b66127374 Reviewed-on: https://go-review.googlesource.com/127095 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/ssa_test.go | 13 - ...arithBoundary.go => arithBoundary_test.go} | 130 ++--- .../{arithConst.go => arithConst_test.go} | 48 +- .../{cmpConst.go => cmpConst_test.go} | 30 +- .../gc/testdata/{copy.go => copy_test.go} | 274 ++++------ .../gc/testdata/gen/arithBoundaryGen.go | 16 +- .../internal/gc/testdata/gen/arithConstGen.go | 16 +- .../internal/gc/testdata/gen/cmpConstGen.go | 11 +- .../internal/gc/testdata/gen/copyGen.go | 25 +- .../internal/gc/testdata/gen/zeroGen.go | 50 +- .../gc/testdata/{zero.go => zero_test.go} | 496 ++++++++---------- 11 files changed, 455 insertions(+), 654 deletions(-) rename src/cmd/compile/internal/gc/testdata/{arithBoundary.go => arithBoundary_test.go} (88%) rename src/cmd/compile/internal/gc/testdata/{arithConst.go => arithConst_test.go} (99%) rename src/cmd/compile/internal/gc/testdata/{cmpConst.go => cmpConst_test.go} (99%) rename src/cmd/compile/internal/gc/testdata/{copy.go => copy_test.go} (97%) rename src/cmd/compile/internal/gc/testdata/{zero.go => zero_test.go} (81%) diff --git a/src/cmd/compile/internal/gc/ssa_test.go b/src/cmd/compile/internal/gc/ssa_test.go index 769ffc4b528c6..4f7bab9fc5983 100644 --- a/src/cmd/compile/internal/gc/ssa_test.go +++ b/src/cmd/compile/internal/gc/ssa_test.go @@ -227,17 +227,8 @@ func TestCode(t *testing.T) { } } -// TestArithmeticBoundary tests boundary results for arithmetic operations. -func TestArithmeticBoundary(t *testing.T) { runTest(t, "arithBoundary.go") } - -// TestArithmeticConst tests results for arithmetic operations against constants. -func TestArithmeticConst(t *testing.T) { runTest(t, "arithConst.go") } - func TestChan(t *testing.T) { runTest(t, "chan.go") } -// TestComparisonsConst tests results for comparison operations against constants. -func TestComparisonsConst(t *testing.T) { runTest(t, "cmpConst.go") } - func TestCompound(t *testing.T) { runTest(t, "compound.go") } func TestCtl(t *testing.T) { runTest(t, "ctl.go") } @@ -259,12 +250,8 @@ func TestArray(t *testing.T) { runTest(t, "array.go") } func TestAppend(t *testing.T) { runTest(t, "append.go") } -func TestZero(t *testing.T) { runTest(t, "zero.go") } - func TestAddressed(t *testing.T) { runTest(t, "addressed.go") } -func TestCopy(t *testing.T) { runTest(t, "copy.go") } - func TestUnsafe(t *testing.T) { runTest(t, "unsafe.go") } func TestPhi(t *testing.T) { runTest(t, "phi.go") } diff --git a/src/cmd/compile/internal/gc/testdata/arithBoundary.go b/src/cmd/compile/internal/gc/testdata/arithBoundary_test.go similarity index 88% rename from src/cmd/compile/internal/gc/testdata/arithBoundary.go rename to src/cmd/compile/internal/gc/testdata/arithBoundary_test.go index 4a7afe690fcd5..777b7cdd601fc 100644 --- a/src/cmd/compile/internal/gc/testdata/arithBoundary.go +++ b/src/cmd/compile/internal/gc/testdata/arithBoundary_test.go @@ -1,9 +1,8 @@ -// run // Code generated by gen/arithBoundaryGen.go. DO NOT EDIT. package main -import "fmt" +import "testing" type utd64 struct { a, b uint64 @@ -504,235 +503,192 @@ var int8_data []itd8 = []itd8{itd8{a: -128, b: -128, add: 0, sub: 0, mul: 0, div itd8{a: 127, b: 126, add: -3, sub: 1, mul: -126, div: 1, mod: 1}, itd8{a: 127, b: 127, add: -2, sub: 0, mul: 1, div: 1, mod: 0}, } -var failed bool -func main() { +//TestArithmeticBoundary tests boundary results for arithmetic operations. +func TestArithmeticBoundary(t *testing.T) { for _, v := range uint64_data { if got := add_uint64_ssa(v.a, v.b); got != v.add { - fmt.Printf("add_uint64 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) - failed = true + t.Errorf("add_uint64 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) } if got := sub_uint64_ssa(v.a, v.b); got != v.sub { - fmt.Printf("sub_uint64 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) - failed = true + t.Errorf("sub_uint64 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) } if v.b != 0 { if got := div_uint64_ssa(v.a, v.b); got != v.div { - fmt.Printf("div_uint64 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) - failed = true + t.Errorf("div_uint64 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) } } if v.b != 0 { if got := mod_uint64_ssa(v.a, v.b); got != v.mod { - fmt.Printf("mod_uint64 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) - failed = true + t.Errorf("mod_uint64 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) } } if got := mul_uint64_ssa(v.a, v.b); got != v.mul { - fmt.Printf("mul_uint64 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) - failed = true + t.Errorf("mul_uint64 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) } } for _, v := range int64_data { if got := add_int64_ssa(v.a, v.b); got != v.add { - fmt.Printf("add_int64 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) - failed = true + t.Errorf("add_int64 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) } if got := sub_int64_ssa(v.a, v.b); got != v.sub { - fmt.Printf("sub_int64 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) - failed = true + t.Errorf("sub_int64 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) } if v.b != 0 { if got := div_int64_ssa(v.a, v.b); got != v.div { - fmt.Printf("div_int64 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) - failed = true + t.Errorf("div_int64 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) } } if v.b != 0 { if got := mod_int64_ssa(v.a, v.b); got != v.mod { - fmt.Printf("mod_int64 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) - failed = true + t.Errorf("mod_int64 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) } } if got := mul_int64_ssa(v.a, v.b); got != v.mul { - fmt.Printf("mul_int64 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) - failed = true + t.Errorf("mul_int64 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) } } for _, v := range uint32_data { if got := add_uint32_ssa(v.a, v.b); got != v.add { - fmt.Printf("add_uint32 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) - failed = true + t.Errorf("add_uint32 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) } if got := sub_uint32_ssa(v.a, v.b); got != v.sub { - fmt.Printf("sub_uint32 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) - failed = true + t.Errorf("sub_uint32 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) } if v.b != 0 { if got := div_uint32_ssa(v.a, v.b); got != v.div { - fmt.Printf("div_uint32 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) - failed = true + t.Errorf("div_uint32 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) } } if v.b != 0 { if got := mod_uint32_ssa(v.a, v.b); got != v.mod { - fmt.Printf("mod_uint32 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) - failed = true + t.Errorf("mod_uint32 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) } } if got := mul_uint32_ssa(v.a, v.b); got != v.mul { - fmt.Printf("mul_uint32 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) - failed = true + t.Errorf("mul_uint32 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) } } for _, v := range int32_data { if got := add_int32_ssa(v.a, v.b); got != v.add { - fmt.Printf("add_int32 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) - failed = true + t.Errorf("add_int32 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) } if got := sub_int32_ssa(v.a, v.b); got != v.sub { - fmt.Printf("sub_int32 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) - failed = true + t.Errorf("sub_int32 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) } if v.b != 0 { if got := div_int32_ssa(v.a, v.b); got != v.div { - fmt.Printf("div_int32 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) - failed = true + t.Errorf("div_int32 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) } } if v.b != 0 { if got := mod_int32_ssa(v.a, v.b); got != v.mod { - fmt.Printf("mod_int32 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) - failed = true + t.Errorf("mod_int32 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) } } if got := mul_int32_ssa(v.a, v.b); got != v.mul { - fmt.Printf("mul_int32 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) - failed = true + t.Errorf("mul_int32 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) } } for _, v := range uint16_data { if got := add_uint16_ssa(v.a, v.b); got != v.add { - fmt.Printf("add_uint16 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) - failed = true + t.Errorf("add_uint16 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) } if got := sub_uint16_ssa(v.a, v.b); got != v.sub { - fmt.Printf("sub_uint16 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) - failed = true + t.Errorf("sub_uint16 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) } if v.b != 0 { if got := div_uint16_ssa(v.a, v.b); got != v.div { - fmt.Printf("div_uint16 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) - failed = true + t.Errorf("div_uint16 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) } } if v.b != 0 { if got := mod_uint16_ssa(v.a, v.b); got != v.mod { - fmt.Printf("mod_uint16 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) - failed = true + t.Errorf("mod_uint16 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) } } if got := mul_uint16_ssa(v.a, v.b); got != v.mul { - fmt.Printf("mul_uint16 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) - failed = true + t.Errorf("mul_uint16 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) } } for _, v := range int16_data { if got := add_int16_ssa(v.a, v.b); got != v.add { - fmt.Printf("add_int16 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) - failed = true + t.Errorf("add_int16 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) } if got := sub_int16_ssa(v.a, v.b); got != v.sub { - fmt.Printf("sub_int16 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) - failed = true + t.Errorf("sub_int16 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) } if v.b != 0 { if got := div_int16_ssa(v.a, v.b); got != v.div { - fmt.Printf("div_int16 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) - failed = true + t.Errorf("div_int16 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) } } if v.b != 0 { if got := mod_int16_ssa(v.a, v.b); got != v.mod { - fmt.Printf("mod_int16 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) - failed = true + t.Errorf("mod_int16 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) } } if got := mul_int16_ssa(v.a, v.b); got != v.mul { - fmt.Printf("mul_int16 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) - failed = true + t.Errorf("mul_int16 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) } } for _, v := range uint8_data { if got := add_uint8_ssa(v.a, v.b); got != v.add { - fmt.Printf("add_uint8 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) - failed = true + t.Errorf("add_uint8 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) } if got := sub_uint8_ssa(v.a, v.b); got != v.sub { - fmt.Printf("sub_uint8 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) - failed = true + t.Errorf("sub_uint8 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) } if v.b != 0 { if got := div_uint8_ssa(v.a, v.b); got != v.div { - fmt.Printf("div_uint8 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) - failed = true + t.Errorf("div_uint8 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) } } if v.b != 0 { if got := mod_uint8_ssa(v.a, v.b); got != v.mod { - fmt.Printf("mod_uint8 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) - failed = true + t.Errorf("mod_uint8 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) } } if got := mul_uint8_ssa(v.a, v.b); got != v.mul { - fmt.Printf("mul_uint8 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) - failed = true + t.Errorf("mul_uint8 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) } } for _, v := range int8_data { if got := add_int8_ssa(v.a, v.b); got != v.add { - fmt.Printf("add_int8 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) - failed = true + t.Errorf("add_int8 %d+%d = %d, wanted %d\n", v.a, v.b, got, v.add) } if got := sub_int8_ssa(v.a, v.b); got != v.sub { - fmt.Printf("sub_int8 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) - failed = true + t.Errorf("sub_int8 %d-%d = %d, wanted %d\n", v.a, v.b, got, v.sub) } if v.b != 0 { if got := div_int8_ssa(v.a, v.b); got != v.div { - fmt.Printf("div_int8 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) - failed = true + t.Errorf("div_int8 %d/%d = %d, wanted %d\n", v.a, v.b, got, v.div) } } if v.b != 0 { if got := mod_int8_ssa(v.a, v.b); got != v.mod { - fmt.Printf("mod_int8 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) - failed = true + t.Errorf("mod_int8 %d%%%d = %d, wanted %d\n", v.a, v.b, got, v.mod) } } if got := mul_int8_ssa(v.a, v.b); got != v.mul { - fmt.Printf("mul_int8 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) - failed = true + t.Errorf("mul_int8 %d*%d = %d, wanted %d\n", v.a, v.b, got, v.mul) } } - if failed { - panic("tests failed") - } } diff --git a/src/cmd/compile/internal/gc/testdata/arithConst.go b/src/cmd/compile/internal/gc/testdata/arithConst_test.go similarity index 99% rename from src/cmd/compile/internal/gc/testdata/arithConst.go rename to src/cmd/compile/internal/gc/testdata/arithConst_test.go index 4ece5a9cb6fc3..9f5ac61427c40 100644 --- a/src/cmd/compile/internal/gc/testdata/arithConst.go +++ b/src/cmd/compile/internal/gc/testdata/arithConst_test.go @@ -1,10 +1,8 @@ -// run // Code generated by gen/arithConstGen.go. DO NOT EDIT. package main -import "fmt" -import "os" +import "testing" //go:noinline func add_uint64_0(a uint64) uint64 { return a + 0 } @@ -9506,83 +9504,67 @@ var tests_int8 = []test_int8{ test_int8{fn: xor_127_int8, fnname: "xor_127_int8", in: 127, want: 0}, test_int8{fn: xor_int8_127, fnname: "xor_int8_127", in: 127, want: 0}} -var failed bool - -func main() { +// TestArithmeticConst tests results for arithmetic operations against constants. +func TestArithmeticConst(t *testing.T) { for _, test := range tests_uint64 { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_uint64mul { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_int64 { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_int64mul { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_uint32 { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_uint32mul { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_int32 { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_int32mul { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_uint16 { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_int16 { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_uint8 { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } for _, test := range tests_int8 { if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } - if failed { - os.Exit(1) - } } diff --git a/src/cmd/compile/internal/gc/testdata/cmpConst.go b/src/cmd/compile/internal/gc/testdata/cmpConst_test.go similarity index 99% rename from src/cmd/compile/internal/gc/testdata/cmpConst.go rename to src/cmd/compile/internal/gc/testdata/cmpConst_test.go index f7067bea2a5b2..9400ef40ae73e 100644 --- a/src/cmd/compile/internal/gc/testdata/cmpConst.go +++ b/src/cmd/compile/internal/gc/testdata/cmpConst_test.go @@ -1,12 +1,11 @@ -// run // Code generated by gen/cmpConstGen.go. DO NOT EDIT. package main import ( - "fmt" "reflect" "runtime" + "testing" ) // results show the expected result for the elements left of, equal to and right of the index. @@ -2093,7 +2092,8 @@ var int8_tests = []struct { {idx: 6, exp: ne, fn: ne_127_int8}, } -func main() { +// TestComparisonsConst tests results for comparison operations against constants. +func TestComparisonsConst(t *testing.T) { for i, test := range uint64_tests { for j, x := range uint64_vals { want := test.exp.l @@ -2104,8 +2104,7 @@ func main() { } if test.fn(x) != want { fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() - msg := fmt.Sprintf("test failed: %v(%v) != %v [type=uint64 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) - panic(msg) + t.Errorf("test failed: %v(%v) != %v [type=uint64 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) } } } @@ -2119,8 +2118,7 @@ func main() { } if test.fn(x) != want { fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() - msg := fmt.Sprintf("test failed: %v(%v) != %v [type=uint32 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) - panic(msg) + t.Errorf("test failed: %v(%v) != %v [type=uint32 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) } } } @@ -2134,8 +2132,7 @@ func main() { } if test.fn(x) != want { fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() - msg := fmt.Sprintf("test failed: %v(%v) != %v [type=uint16 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) - panic(msg) + t.Errorf("test failed: %v(%v) != %v [type=uint16 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) } } } @@ -2149,8 +2146,7 @@ func main() { } if test.fn(x) != want { fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() - msg := fmt.Sprintf("test failed: %v(%v) != %v [type=uint8 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) - panic(msg) + t.Errorf("test failed: %v(%v) != %v [type=uint8 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) } } } @@ -2164,8 +2160,7 @@ func main() { } if test.fn(x) != want { fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() - msg := fmt.Sprintf("test failed: %v(%v) != %v [type=int64 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) - panic(msg) + t.Errorf("test failed: %v(%v) != %v [type=int64 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) } } } @@ -2179,8 +2174,7 @@ func main() { } if test.fn(x) != want { fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() - msg := fmt.Sprintf("test failed: %v(%v) != %v [type=int32 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) - panic(msg) + t.Errorf("test failed: %v(%v) != %v [type=int32 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) } } } @@ -2194,8 +2188,7 @@ func main() { } if test.fn(x) != want { fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() - msg := fmt.Sprintf("test failed: %v(%v) != %v [type=int16 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) - panic(msg) + t.Errorf("test failed: %v(%v) != %v [type=int16 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) } } } @@ -2209,8 +2202,7 @@ func main() { } if test.fn(x) != want { fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name() - msg := fmt.Sprintf("test failed: %v(%v) != %v [type=int8 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) - panic(msg) + t.Errorf("test failed: %v(%v) != %v [type=int8 i=%v j=%v idx=%v]", fn, x, want, i, j, test.idx) } } } diff --git a/src/cmd/compile/internal/gc/testdata/copy.go b/src/cmd/compile/internal/gc/testdata/copy_test.go similarity index 97% rename from src/cmd/compile/internal/gc/testdata/copy.go rename to src/cmd/compile/internal/gc/testdata/copy_test.go index d8bb26634ed26..c29611d32a22e 100644 --- a/src/cmd/compile/internal/gc/testdata/copy.go +++ b/src/cmd/compile/internal/gc/testdata/copy_test.go @@ -1,9 +1,8 @@ -// run // Code generated by gen/copyGen.go. DO NOT EDIT. package main -import "fmt" +import "testing" type T1 struct { pre [8]byte @@ -15,14 +14,13 @@ type T1 struct { func t1copy_ssa(y, x *[1]byte) { *y = *x } -func testCopy1() { +func testCopy1(t *testing.T) { a := T1{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1]byte{0}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [1]byte{100} t1copy_ssa(&a.mid, &x) want := T1{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1]byte{100}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t1copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t1copy got=%v, want %v\n", a, want) } } @@ -36,14 +34,13 @@ type T2 struct { func t2copy_ssa(y, x *[2]byte) { *y = *x } -func testCopy2() { +func testCopy2(t *testing.T) { a := T2{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [2]byte{0, 1}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [2]byte{100, 101} t2copy_ssa(&a.mid, &x) want := T2{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [2]byte{100, 101}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t2copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t2copy got=%v, want %v\n", a, want) } } @@ -57,14 +54,13 @@ type T3 struct { func t3copy_ssa(y, x *[3]byte) { *y = *x } -func testCopy3() { +func testCopy3(t *testing.T) { a := T3{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [3]byte{0, 1, 2}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [3]byte{100, 101, 102} t3copy_ssa(&a.mid, &x) want := T3{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [3]byte{100, 101, 102}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t3copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t3copy got=%v, want %v\n", a, want) } } @@ -78,14 +74,13 @@ type T4 struct { func t4copy_ssa(y, x *[4]byte) { *y = *x } -func testCopy4() { +func testCopy4(t *testing.T) { a := T4{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [4]byte{0, 1, 2, 3}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [4]byte{100, 101, 102, 103} t4copy_ssa(&a.mid, &x) want := T4{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [4]byte{100, 101, 102, 103}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t4copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t4copy got=%v, want %v\n", a, want) } } @@ -99,14 +94,13 @@ type T5 struct { func t5copy_ssa(y, x *[5]byte) { *y = *x } -func testCopy5() { +func testCopy5(t *testing.T) { a := T5{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [5]byte{0, 1, 2, 3, 4}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [5]byte{100, 101, 102, 103, 104} t5copy_ssa(&a.mid, &x) want := T5{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [5]byte{100, 101, 102, 103, 104}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t5copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t5copy got=%v, want %v\n", a, want) } } @@ -120,14 +114,13 @@ type T6 struct { func t6copy_ssa(y, x *[6]byte) { *y = *x } -func testCopy6() { +func testCopy6(t *testing.T) { a := T6{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [6]byte{0, 1, 2, 3, 4, 5}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [6]byte{100, 101, 102, 103, 104, 105} t6copy_ssa(&a.mid, &x) want := T6{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [6]byte{100, 101, 102, 103, 104, 105}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t6copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t6copy got=%v, want %v\n", a, want) } } @@ -141,14 +134,13 @@ type T7 struct { func t7copy_ssa(y, x *[7]byte) { *y = *x } -func testCopy7() { +func testCopy7(t *testing.T) { a := T7{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [7]byte{0, 1, 2, 3, 4, 5, 6}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [7]byte{100, 101, 102, 103, 104, 105, 106} t7copy_ssa(&a.mid, &x) want := T7{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [7]byte{100, 101, 102, 103, 104, 105, 106}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t7copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t7copy got=%v, want %v\n", a, want) } } @@ -162,14 +154,13 @@ type T8 struct { func t8copy_ssa(y, x *[8]byte) { *y = *x } -func testCopy8() { +func testCopy8(t *testing.T) { a := T8{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [8]byte{0, 1, 2, 3, 4, 5, 6, 7}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [8]byte{100, 101, 102, 103, 104, 105, 106, 107} t8copy_ssa(&a.mid, &x) want := T8{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [8]byte{100, 101, 102, 103, 104, 105, 106, 107}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t8copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t8copy got=%v, want %v\n", a, want) } } @@ -183,14 +174,13 @@ type T9 struct { func t9copy_ssa(y, x *[9]byte) { *y = *x } -func testCopy9() { +func testCopy9(t *testing.T) { a := T9{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [9]byte{0, 1, 2, 3, 4, 5, 6, 7, 8}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [9]byte{100, 101, 102, 103, 104, 105, 106, 107, 108} t9copy_ssa(&a.mid, &x) want := T9{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [9]byte{100, 101, 102, 103, 104, 105, 106, 107, 108}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t9copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t9copy got=%v, want %v\n", a, want) } } @@ -204,14 +194,13 @@ type T10 struct { func t10copy_ssa(y, x *[10]byte) { *y = *x } -func testCopy10() { +func testCopy10(t *testing.T) { a := T10{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [10]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [10]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109} t10copy_ssa(&a.mid, &x) want := T10{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [10]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t10copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t10copy got=%v, want %v\n", a, want) } } @@ -225,14 +214,13 @@ type T15 struct { func t15copy_ssa(y, x *[15]byte) { *y = *x } -func testCopy15() { +func testCopy15(t *testing.T) { a := T15{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [15]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [15]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114} t15copy_ssa(&a.mid, &x) want := T15{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [15]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t15copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t15copy got=%v, want %v\n", a, want) } } @@ -246,14 +234,13 @@ type T16 struct { func t16copy_ssa(y, x *[16]byte) { *y = *x } -func testCopy16() { +func testCopy16(t *testing.T) { a := T16{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [16]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [16]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115} t16copy_ssa(&a.mid, &x) want := T16{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [16]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t16copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t16copy got=%v, want %v\n", a, want) } } @@ -267,14 +254,13 @@ type T17 struct { func t17copy_ssa(y, x *[17]byte) { *y = *x } -func testCopy17() { +func testCopy17(t *testing.T) { a := T17{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [17]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [17]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116} t17copy_ssa(&a.mid, &x) want := T17{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [17]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t17copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t17copy got=%v, want %v\n", a, want) } } @@ -288,14 +274,13 @@ type T23 struct { func t23copy_ssa(y, x *[23]byte) { *y = *x } -func testCopy23() { +func testCopy23(t *testing.T) { a := T23{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [23]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [23]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122} t23copy_ssa(&a.mid, &x) want := T23{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [23]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t23copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t23copy got=%v, want %v\n", a, want) } } @@ -309,14 +294,13 @@ type T24 struct { func t24copy_ssa(y, x *[24]byte) { *y = *x } -func testCopy24() { +func testCopy24(t *testing.T) { a := T24{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [24]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [24]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123} t24copy_ssa(&a.mid, &x) want := T24{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [24]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t24copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t24copy got=%v, want %v\n", a, want) } } @@ -330,14 +314,13 @@ type T25 struct { func t25copy_ssa(y, x *[25]byte) { *y = *x } -func testCopy25() { +func testCopy25(t *testing.T) { a := T25{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [25]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [25]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124} t25copy_ssa(&a.mid, &x) want := T25{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [25]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t25copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t25copy got=%v, want %v\n", a, want) } } @@ -351,14 +334,13 @@ type T31 struct { func t31copy_ssa(y, x *[31]byte) { *y = *x } -func testCopy31() { +func testCopy31(t *testing.T) { a := T31{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [31]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [31]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130} t31copy_ssa(&a.mid, &x) want := T31{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [31]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t31copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t31copy got=%v, want %v\n", a, want) } } @@ -372,14 +354,13 @@ type T32 struct { func t32copy_ssa(y, x *[32]byte) { *y = *x } -func testCopy32() { +func testCopy32(t *testing.T) { a := T32{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [32]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [32]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131} t32copy_ssa(&a.mid, &x) want := T32{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [32]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t32copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t32copy got=%v, want %v\n", a, want) } } @@ -393,14 +374,13 @@ type T33 struct { func t33copy_ssa(y, x *[33]byte) { *y = *x } -func testCopy33() { +func testCopy33(t *testing.T) { a := T33{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [33]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [33]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132} t33copy_ssa(&a.mid, &x) want := T33{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [33]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t33copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t33copy got=%v, want %v\n", a, want) } } @@ -414,14 +394,13 @@ type T63 struct { func t63copy_ssa(y, x *[63]byte) { *y = *x } -func testCopy63() { +func testCopy63(t *testing.T) { a := T63{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [63]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [63]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162} t63copy_ssa(&a.mid, &x) want := T63{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [63]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t63copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t63copy got=%v, want %v\n", a, want) } } @@ -435,14 +414,13 @@ type T64 struct { func t64copy_ssa(y, x *[64]byte) { *y = *x } -func testCopy64() { +func testCopy64(t *testing.T) { a := T64{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [64]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [64]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163} t64copy_ssa(&a.mid, &x) want := T64{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [64]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t64copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t64copy got=%v, want %v\n", a, want) } } @@ -456,14 +434,13 @@ type T65 struct { func t65copy_ssa(y, x *[65]byte) { *y = *x } -func testCopy65() { +func testCopy65(t *testing.T) { a := T65{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [65]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [65]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164} t65copy_ssa(&a.mid, &x) want := T65{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [65]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t65copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t65copy got=%v, want %v\n", a, want) } } @@ -477,14 +454,13 @@ type T1023 struct { func t1023copy_ssa(y, x *[1023]byte) { *y = *x } -func testCopy1023() { +func testCopy1023(t *testing.T) { a := T1023{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1023]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [1023]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122} t1023copy_ssa(&a.mid, &x) want := T1023{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1023]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t1023copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t1023copy got=%v, want %v\n", a, want) } } @@ -498,14 +474,13 @@ type T1024 struct { func t1024copy_ssa(y, x *[1024]byte) { *y = *x } -func testCopy1024() { +func testCopy1024(t *testing.T) { a := T1024{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1024]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [1024]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123} t1024copy_ssa(&a.mid, &x) want := T1024{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1024]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t1024copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t1024copy got=%v, want %v\n", a, want) } } @@ -519,14 +494,13 @@ type T1025 struct { func t1025copy_ssa(y, x *[1025]byte) { *y = *x } -func testCopy1025() { +func testCopy1025(t *testing.T) { a := T1025{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1025]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [1025]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124} t1025copy_ssa(&a.mid, &x) want := T1025{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1025]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t1025copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t1025copy got=%v, want %v\n", a, want) } } @@ -540,14 +514,13 @@ type T1031 struct { func t1031copy_ssa(y, x *[1031]byte) { *y = *x } -func testCopy1031() { +func testCopy1031(t *testing.T) { a := T1031{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1031]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [1031]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130} t1031copy_ssa(&a.mid, &x) want := T1031{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1031]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t1031copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t1031copy got=%v, want %v\n", a, want) } } @@ -561,14 +534,13 @@ type T1032 struct { func t1032copy_ssa(y, x *[1032]byte) { *y = *x } -func testCopy1032() { +func testCopy1032(t *testing.T) { a := T1032{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1032]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [1032]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131} t1032copy_ssa(&a.mid, &x) want := T1032{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1032]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t1032copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t1032copy got=%v, want %v\n", a, want) } } @@ -582,14 +554,13 @@ type T1033 struct { func t1033copy_ssa(y, x *[1033]byte) { *y = *x } -func testCopy1033() { +func testCopy1033(t *testing.T) { a := T1033{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1033]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [1033]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132} t1033copy_ssa(&a.mid, &x) want := T1033{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1033]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t1033copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t1033copy got=%v, want %v\n", a, want) } } @@ -603,14 +574,13 @@ type T1039 struct { func t1039copy_ssa(y, x *[1039]byte) { *y = *x } -func testCopy1039() { +func testCopy1039(t *testing.T) { a := T1039{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1039]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [1039]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138} t1039copy_ssa(&a.mid, &x) want := T1039{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1039]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t1039copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t1039copy got=%v, want %v\n", a, want) } } @@ -624,14 +594,13 @@ type T1040 struct { func t1040copy_ssa(y, x *[1040]byte) { *y = *x } -func testCopy1040() { +func testCopy1040(t *testing.T) { a := T1040{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1040]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [1040]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139} t1040copy_ssa(&a.mid, &x) want := T1040{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1040]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t1040copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t1040copy got=%v, want %v\n", a, want) } } @@ -645,14 +614,13 @@ type T1041 struct { func t1041copy_ssa(y, x *[1041]byte) { *y = *x } -func testCopy1041() { +func testCopy1041(t *testing.T) { a := T1041{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1041]byte{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} x := [1041]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140} t1041copy_ssa(&a.mid, &x) want := T1041{[8]byte{201, 202, 203, 204, 205, 206, 207, 208}, [1041]byte{100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140}, [8]byte{211, 212, 213, 214, 215, 216, 217, 218}} if a != want { - fmt.Printf("t1041copy got=%v, want %v\n", a, want) - failed = true + t.Errorf("t1041copy got=%v, want %v\n", a, want) } } @@ -662,14 +630,13 @@ func tu2copy_ssa(docopy bool, data [2]byte, x *[2]byte) { *x = data } } -func testUnalignedCopy2() { +func testUnalignedCopy2(t *testing.T) { var a [2]byte t2 := [2]byte{2, 3} tu2copy_ssa(true, t2, &a) want2 := [2]byte{2, 3} if a != want2 { - fmt.Printf("tu2copy got=%v, want %v\n", a, want2) - failed = true + t.Errorf("tu2copy got=%v, want %v\n", a, want2) } } @@ -679,14 +646,13 @@ func tu3copy_ssa(docopy bool, data [3]byte, x *[3]byte) { *x = data } } -func testUnalignedCopy3() { +func testUnalignedCopy3(t *testing.T) { var a [3]byte t3 := [3]byte{3, 4, 5} tu3copy_ssa(true, t3, &a) want3 := [3]byte{3, 4, 5} if a != want3 { - fmt.Printf("tu3copy got=%v, want %v\n", a, want3) - failed = true + t.Errorf("tu3copy got=%v, want %v\n", a, want3) } } @@ -696,14 +662,13 @@ func tu4copy_ssa(docopy bool, data [4]byte, x *[4]byte) { *x = data } } -func testUnalignedCopy4() { +func testUnalignedCopy4(t *testing.T) { var a [4]byte t4 := [4]byte{4, 5, 6, 7} tu4copy_ssa(true, t4, &a) want4 := [4]byte{4, 5, 6, 7} if a != want4 { - fmt.Printf("tu4copy got=%v, want %v\n", a, want4) - failed = true + t.Errorf("tu4copy got=%v, want %v\n", a, want4) } } @@ -713,14 +678,13 @@ func tu5copy_ssa(docopy bool, data [5]byte, x *[5]byte) { *x = data } } -func testUnalignedCopy5() { +func testUnalignedCopy5(t *testing.T) { var a [5]byte t5 := [5]byte{5, 6, 7, 8, 9} tu5copy_ssa(true, t5, &a) want5 := [5]byte{5, 6, 7, 8, 9} if a != want5 { - fmt.Printf("tu5copy got=%v, want %v\n", a, want5) - failed = true + t.Errorf("tu5copy got=%v, want %v\n", a, want5) } } @@ -730,14 +694,13 @@ func tu6copy_ssa(docopy bool, data [6]byte, x *[6]byte) { *x = data } } -func testUnalignedCopy6() { +func testUnalignedCopy6(t *testing.T) { var a [6]byte t6 := [6]byte{6, 7, 8, 9, 10, 11} tu6copy_ssa(true, t6, &a) want6 := [6]byte{6, 7, 8, 9, 10, 11} if a != want6 { - fmt.Printf("tu6copy got=%v, want %v\n", a, want6) - failed = true + t.Errorf("tu6copy got=%v, want %v\n", a, want6) } } @@ -747,58 +710,51 @@ func tu7copy_ssa(docopy bool, data [7]byte, x *[7]byte) { *x = data } } -func testUnalignedCopy7() { +func testUnalignedCopy7(t *testing.T) { var a [7]byte t7 := [7]byte{7, 8, 9, 10, 11, 12, 13} tu7copy_ssa(true, t7, &a) want7 := [7]byte{7, 8, 9, 10, 11, 12, 13} if a != want7 { - fmt.Printf("tu7copy got=%v, want %v\n", a, want7) - failed = true - } -} - -var failed bool - -func main() { - testCopy1() - testCopy2() - testCopy3() - testCopy4() - testCopy5() - testCopy6() - testCopy7() - testCopy8() - testCopy9() - testCopy10() - testCopy15() - testCopy16() - testCopy17() - testCopy23() - testCopy24() - testCopy25() - testCopy31() - testCopy32() - testCopy33() - testCopy63() - testCopy64() - testCopy65() - testCopy1023() - testCopy1024() - testCopy1025() - testCopy1031() - testCopy1032() - testCopy1033() - testCopy1039() - testCopy1040() - testCopy1041() - testUnalignedCopy2() - testUnalignedCopy3() - testUnalignedCopy4() - testUnalignedCopy5() - testUnalignedCopy6() - testUnalignedCopy7() - if failed { - panic("failed") - } + t.Errorf("tu7copy got=%v, want %v\n", a, want7) + } +} +func TestCopy(t *testing.T) { + testCopy1(t) + testCopy2(t) + testCopy3(t) + testCopy4(t) + testCopy5(t) + testCopy6(t) + testCopy7(t) + testCopy8(t) + testCopy9(t) + testCopy10(t) + testCopy15(t) + testCopy16(t) + testCopy17(t) + testCopy23(t) + testCopy24(t) + testCopy25(t) + testCopy31(t) + testCopy32(t) + testCopy33(t) + testCopy63(t) + testCopy64(t) + testCopy65(t) + testCopy1023(t) + testCopy1024(t) + testCopy1025(t) + testCopy1031(t) + testCopy1032(t) + testCopy1033(t) + testCopy1039(t) + testCopy1040(t) + testCopy1041(t) + testUnalignedCopy2(t) + testUnalignedCopy3(t) + testUnalignedCopy4(t) + testUnalignedCopy5(t) + testUnalignedCopy6(t) + testUnalignedCopy7(t) } diff --git a/src/cmd/compile/internal/gc/testdata/gen/arithBoundaryGen.go b/src/cmd/compile/internal/gc/testdata/gen/arithBoundaryGen.go index cbdd1626365af..21ad27e88017c 100644 --- a/src/cmd/compile/internal/gc/testdata/gen/arithBoundaryGen.go +++ b/src/cmd/compile/internal/gc/testdata/gen/arithBoundaryGen.go @@ -91,10 +91,9 @@ var ops = []op{op{"add", "+"}, op{"sub", "-"}, op{"div", "/"}, op{"mod", "%%"}, func main() { w := new(bytes.Buffer) - fmt.Fprintf(w, "// run\n") fmt.Fprintf(w, "// Code generated by gen/arithBoundaryGen.go. DO NOT EDIT.\n\n") fmt.Fprintf(w, "package main;\n") - fmt.Fprintf(w, "import \"fmt\"\n") + fmt.Fprintf(w, "import \"testing\"\n") for _, sz := range []int{64, 32, 16, 8} { fmt.Fprintf(w, "type utd%d struct {\n", sz) @@ -160,13 +159,12 @@ func main() { } } - fmt.Fprintf(w, "var failed bool\n\n") - fmt.Fprintf(w, "func main() {\n\n") + fmt.Fprintf(w, "//TestArithmeticBoundary tests boundary results for arithmetic operations.\n") + fmt.Fprintf(w, "func TestArithmeticBoundary(t *testing.T) {\n\n") verify, err := template.New("tst").Parse( `if got := {{.Name}}_{{.Stype}}_ssa(v.a, v.b); got != v.{{.Name}} { - fmt.Printf("{{.Name}}_{{.Stype}} %d{{.Symbol}}%d = %d, wanted %d\n",v.a,v.b,got,v.{{.Name}}) - failed = true + t.Errorf("{{.Name}}_{{.Stype}} %d{{.Symbol}}%d = %d, wanted %d\n",v.a,v.b,got,v.{{.Name}}) } `) @@ -193,10 +191,6 @@ func main() { fmt.Fprint(w, " }\n") } - fmt.Fprintf(w, `if failed { - panic("tests failed") - } -`) fmt.Fprintf(w, "}\n") // gofmt result @@ -208,7 +202,7 @@ func main() { } // write to file - err = ioutil.WriteFile("../arithBoundary.go", src, 0666) + err = ioutil.WriteFile("../arithBoundary_test.go", src, 0666) if err != nil { log.Fatalf("can't write output: %v\n", err) } diff --git a/src/cmd/compile/internal/gc/testdata/gen/arithConstGen.go b/src/cmd/compile/internal/gc/testdata/gen/arithConstGen.go index 7fd5c31a1328b..41b2946480532 100644 --- a/src/cmd/compile/internal/gc/testdata/gen/arithConstGen.go +++ b/src/cmd/compile/internal/gc/testdata/gen/arithConstGen.go @@ -148,11 +148,9 @@ func ansS(i, j int64, t, op string) string { func main() { w := new(bytes.Buffer) - fmt.Fprintf(w, "// run\n") fmt.Fprintf(w, "// Code generated by gen/arithConstGen.go. DO NOT EDIT.\n\n") fmt.Fprintf(w, "package main;\n") - fmt.Fprintf(w, "import \"fmt\"\n") - fmt.Fprintf(w, "import \"os\"\n") + fmt.Fprintf(w, "import \"testing\"\n") fncCnst1 := template.Must(template.New("fnc").Parse( `//go:noinline @@ -313,26 +311,22 @@ type test_%[1]s%[2]s struct { } fmt.Fprint(w, ` -var failed bool -func main() { +// TestArithmeticConst tests results for arithmetic operations against constants. +func TestArithmeticConst(t *testing.T) { `) for _, s := range szs { fmt.Fprintf(w, `for _, test := range tests_%s%s {`, s.name, s.oponly) // Use WriteString here to avoid a vet warning about formatting directives. w.WriteString(`if got := test.fn(test.in); got != test.want { - fmt.Printf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) - failed = true + t.Errorf("%s(%d) = %d, want %d\n", test.fnname, test.in, got, test.want) } } `) } fmt.Fprint(w, ` - if failed { - os.Exit(1) - } } `) @@ -345,7 +339,7 @@ func main() { } // write to file - err = ioutil.WriteFile("../arithConst.go", src, 0666) + err = ioutil.WriteFile("../arithConst_test.go", src, 0666) if err != nil { log.Fatalf("can't write output: %v\n", err) } diff --git a/src/cmd/compile/internal/gc/testdata/gen/cmpConstGen.go b/src/cmd/compile/internal/gc/testdata/gen/cmpConstGen.go index defa4a9f7bfdd..5508e76be5d87 100644 --- a/src/cmd/compile/internal/gc/testdata/gen/cmpConstGen.go +++ b/src/cmd/compile/internal/gc/testdata/gen/cmpConstGen.go @@ -153,10 +153,9 @@ func main() { } w := new(bytes.Buffer) - fmt.Fprintf(w, "// run\n") fmt.Fprintf(w, "// Code generated by gen/cmpConstGen.go. DO NOT EDIT.\n\n") fmt.Fprintf(w, "package main;\n") - fmt.Fprintf(w, "import (\"fmt\"; \"reflect\"; \"runtime\";)\n") + fmt.Fprintf(w, "import (\"testing\"; \"reflect\"; \"runtime\";)\n") fmt.Fprintf(w, "// results show the expected result for the elements left of, equal to and right of the index.\n") fmt.Fprintf(w, "type result struct{l, e, r bool}\n") fmt.Fprintf(w, "var (\n") @@ -215,7 +214,8 @@ func main() { } // emit the main function, looping over all test cases - fmt.Fprintf(w, "func main() {\n") + fmt.Fprintf(w, "// TestComparisonsConst tests results for comparison operations against constants.\n") + fmt.Fprintf(w, "func TestComparisonsConst(t *testing.T) {\n") for _, typ := range types { fmt.Fprintf(w, "for i, test := range %v_tests {\n", typ) fmt.Fprintf(w, " for j, x := range %v_vals {\n", typ) @@ -224,8 +224,7 @@ func main() { fmt.Fprintf(w, " else if j > test.idx {\nwant = test.exp.r\n}\n") fmt.Fprintf(w, " if test.fn(x) != want {\n") fmt.Fprintf(w, " fn := runtime.FuncForPC(reflect.ValueOf(test.fn).Pointer()).Name()\n") - fmt.Fprintf(w, " msg := fmt.Sprintf(\"test failed: %%v(%%v) != %%v [type=%v i=%%v j=%%v idx=%%v]\", fn, x, want, i, j, test.idx)\n", typ) - fmt.Fprintf(w, " panic(msg)\n") + fmt.Fprintf(w, " t.Errorf(\"test failed: %%v(%%v) != %%v [type=%v i=%%v j=%%v idx=%%v]\", fn, x, want, i, j, test.idx)\n", typ) fmt.Fprintf(w, " }\n") fmt.Fprintf(w, " }\n") fmt.Fprintf(w, "}\n") @@ -241,7 +240,7 @@ func main() { } // write to file - err = ioutil.WriteFile("../cmpConst.go", src, 0666) + err = ioutil.WriteFile("../cmpConst_test.go", src, 0666) if err != nil { log.Fatalf("can't write output: %v\n", err) } diff --git a/src/cmd/compile/internal/gc/testdata/gen/copyGen.go b/src/cmd/compile/internal/gc/testdata/gen/copyGen.go index 800d081cec126..4567f2f97ea39 100644 --- a/src/cmd/compile/internal/gc/testdata/gen/copyGen.go +++ b/src/cmd/compile/internal/gc/testdata/gen/copyGen.go @@ -24,10 +24,9 @@ var usizes = [...]int{2, 3, 4, 5, 6, 7} func main() { w := new(bytes.Buffer) - fmt.Fprintf(w, "// run\n") fmt.Fprintf(w, "// Code generated by gen/copyGen.go. DO NOT EDIT.\n\n") fmt.Fprintf(w, "package main\n") - fmt.Fprintf(w, "import \"fmt\"\n") + fmt.Fprintf(w, "import \"testing\"\n") for _, s := range sizes { // type for test @@ -44,7 +43,7 @@ func main() { fmt.Fprintf(w, "}\n") // testing harness - fmt.Fprintf(w, "func testCopy%d() {\n", s) + fmt.Fprintf(w, "func testCopy%d(t *testing.T) {\n", s) fmt.Fprintf(w, " a := T%d{[8]byte{201, 202, 203, 204, 205, 206, 207, 208},[%d]byte{", s, s) for i := 0; i < s; i++ { fmt.Fprintf(w, "%d,", i%100) @@ -62,8 +61,7 @@ func main() { } fmt.Fprintf(w, "},[8]byte{211, 212, 213, 214, 215, 216, 217, 218}}\n") fmt.Fprintf(w, " if a != want {\n") - fmt.Fprintf(w, " fmt.Printf(\"t%dcopy got=%%v, want %%v\\n\", a, want)\n", s) - fmt.Fprintf(w, " failed=true\n") + fmt.Fprintf(w, " t.Errorf(\"t%dcopy got=%%v, want %%v\\n\", a, want)\n", s) fmt.Fprintf(w, " }\n") fmt.Fprintf(w, "}\n") } @@ -78,7 +76,7 @@ func main() { fmt.Fprintf(w, "}\n") // testing harness - fmt.Fprintf(w, "func testUnalignedCopy%d() {\n", s) + fmt.Fprintf(w, "func testUnalignedCopy%d(t *testing.T) {\n", s) fmt.Fprintf(w, " var a [%d]byte\n", s) fmt.Fprintf(w, " t%d := [%d]byte{", s, s) for i := 0; i < s; i++ { @@ -92,24 +90,19 @@ func main() { } fmt.Fprintf(w, "}\n") fmt.Fprintf(w, " if a != want%d {\n", s) - fmt.Fprintf(w, " fmt.Printf(\"tu%dcopy got=%%v, want %%v\\n\", a, want%d)\n", s, s) - fmt.Fprintf(w, " failed=true\n") + fmt.Fprintf(w, " t.Errorf(\"tu%dcopy got=%%v, want %%v\\n\", a, want%d)\n", s, s) fmt.Fprintf(w, " }\n") fmt.Fprintf(w, "}\n") } // boilerplate at end - fmt.Fprintf(w, "var failed bool\n") - fmt.Fprintf(w, "func main() {\n") + fmt.Fprintf(w, "func TestCopy(t *testing.T) {\n") for _, s := range sizes { - fmt.Fprintf(w, " testCopy%d()\n", s) + fmt.Fprintf(w, " testCopy%d(t)\n", s) } for _, s := range usizes { - fmt.Fprintf(w, " testUnalignedCopy%d()\n", s) + fmt.Fprintf(w, " testUnalignedCopy%d(t)\n", s) } - fmt.Fprintf(w, " if failed {\n") - fmt.Fprintf(w, " panic(\"failed\")\n") - fmt.Fprintf(w, " }\n") fmt.Fprintf(w, "}\n") // gofmt result @@ -121,7 +114,7 @@ func main() { } // write to file - err = ioutil.WriteFile("../copy.go", src, 0666) + err = ioutil.WriteFile("../copy_test.go", src, 0666) if err != nil { log.Fatalf("can't write output: %v\n", err) } diff --git a/src/cmd/compile/internal/gc/testdata/gen/zeroGen.go b/src/cmd/compile/internal/gc/testdata/gen/zeroGen.go index c764c369e64b7..7056730cb9883 100644 --- a/src/cmd/compile/internal/gc/testdata/gen/zeroGen.go +++ b/src/cmd/compile/internal/gc/testdata/gen/zeroGen.go @@ -23,14 +23,13 @@ var usizes = [...]int{8, 16, 24, 32, 64, 256} func main() { w := new(bytes.Buffer) - fmt.Fprintf(w, "// run\n") fmt.Fprintf(w, "// Code generated by gen/zeroGen.go. DO NOT EDIT.\n\n") fmt.Fprintf(w, "package main\n") - fmt.Fprintf(w, "import \"fmt\"\n") + fmt.Fprintf(w, "import \"testing\"\n") for _, s := range sizes { // type for test - fmt.Fprintf(w, "type T%d struct {\n", s) + fmt.Fprintf(w, "type Z%d struct {\n", s) fmt.Fprintf(w, " pre [8]byte\n") fmt.Fprintf(w, " mid [%d]byte\n", s) fmt.Fprintf(w, " post [8]byte\n") @@ -43,96 +42,89 @@ func main() { fmt.Fprintf(w, "}\n") // testing harness - fmt.Fprintf(w, "func testZero%d() {\n", s) - fmt.Fprintf(w, " a := T%d{[8]byte{255,255,255,255,255,255,255,255},[%d]byte{", s, s) + fmt.Fprintf(w, "func testZero%d(t *testing.T) {\n", s) + fmt.Fprintf(w, " a := Z%d{[8]byte{255,255,255,255,255,255,255,255},[%d]byte{", s, s) for i := 0; i < s; i++ { fmt.Fprintf(w, "255,") } fmt.Fprintf(w, "},[8]byte{255,255,255,255,255,255,255,255}}\n") fmt.Fprintf(w, " zero%d_ssa(&a.mid)\n", s) - fmt.Fprintf(w, " want := T%d{[8]byte{255,255,255,255,255,255,255,255},[%d]byte{", s, s) + fmt.Fprintf(w, " want := Z%d{[8]byte{255,255,255,255,255,255,255,255},[%d]byte{", s, s) for i := 0; i < s; i++ { fmt.Fprintf(w, "0,") } fmt.Fprintf(w, "},[8]byte{255,255,255,255,255,255,255,255}}\n") fmt.Fprintf(w, " if a != want {\n") - fmt.Fprintf(w, " fmt.Printf(\"zero%d got=%%v, want %%v\\n\", a, want)\n", s) - fmt.Fprintf(w, " failed=true\n") + fmt.Fprintf(w, " t.Errorf(\"zero%d got=%%v, want %%v\\n\", a, want)\n", s) fmt.Fprintf(w, " }\n") fmt.Fprintf(w, "}\n") } for _, s := range usizes { // type for test - fmt.Fprintf(w, "type T%du1 struct {\n", s) + fmt.Fprintf(w, "type Z%du1 struct {\n", s) fmt.Fprintf(w, " b bool\n") fmt.Fprintf(w, " val [%d]byte\n", s) fmt.Fprintf(w, "}\n") - fmt.Fprintf(w, "type T%du2 struct {\n", s) + fmt.Fprintf(w, "type Z%du2 struct {\n", s) fmt.Fprintf(w, " i uint16\n") fmt.Fprintf(w, " val [%d]byte\n", s) fmt.Fprintf(w, "}\n") // function being tested fmt.Fprintf(w, "//go:noinline\n") - fmt.Fprintf(w, "func zero%du1_ssa(t *T%du1) {\n", s, s) + fmt.Fprintf(w, "func zero%du1_ssa(t *Z%du1) {\n", s, s) fmt.Fprintf(w, " t.val = [%d]byte{}\n", s) fmt.Fprintf(w, "}\n") // function being tested fmt.Fprintf(w, "//go:noinline\n") - fmt.Fprintf(w, "func zero%du2_ssa(t *T%du2) {\n", s, s) + fmt.Fprintf(w, "func zero%du2_ssa(t *Z%du2) {\n", s, s) fmt.Fprintf(w, " t.val = [%d]byte{}\n", s) fmt.Fprintf(w, "}\n") // testing harness - fmt.Fprintf(w, "func testZero%du() {\n", s) - fmt.Fprintf(w, " a := T%du1{false, [%d]byte{", s, s) + fmt.Fprintf(w, "func testZero%du(t *testing.T) {\n", s) + fmt.Fprintf(w, " a := Z%du1{false, [%d]byte{", s, s) for i := 0; i < s; i++ { fmt.Fprintf(w, "255,") } fmt.Fprintf(w, "}}\n") fmt.Fprintf(w, " zero%du1_ssa(&a)\n", s) - fmt.Fprintf(w, " want := T%du1{false, [%d]byte{", s, s) + fmt.Fprintf(w, " want := Z%du1{false, [%d]byte{", s, s) for i := 0; i < s; i++ { fmt.Fprintf(w, "0,") } fmt.Fprintf(w, "}}\n") fmt.Fprintf(w, " if a != want {\n") - fmt.Fprintf(w, " fmt.Printf(\"zero%du2 got=%%v, want %%v\\n\", a, want)\n", s) - fmt.Fprintf(w, " failed=true\n") + fmt.Fprintf(w, " t.Errorf(\"zero%du2 got=%%v, want %%v\\n\", a, want)\n", s) fmt.Fprintf(w, " }\n") - fmt.Fprintf(w, " b := T%du2{15, [%d]byte{", s, s) + fmt.Fprintf(w, " b := Z%du2{15, [%d]byte{", s, s) for i := 0; i < s; i++ { fmt.Fprintf(w, "255,") } fmt.Fprintf(w, "}}\n") fmt.Fprintf(w, " zero%du2_ssa(&b)\n", s) - fmt.Fprintf(w, " wantb := T%du2{15, [%d]byte{", s, s) + fmt.Fprintf(w, " wantb := Z%du2{15, [%d]byte{", s, s) for i := 0; i < s; i++ { fmt.Fprintf(w, "0,") } fmt.Fprintf(w, "}}\n") fmt.Fprintf(w, " if b != wantb {\n") - fmt.Fprintf(w, " fmt.Printf(\"zero%du2 got=%%v, want %%v\\n\", b, wantb)\n", s) - fmt.Fprintf(w, " failed=true\n") + fmt.Fprintf(w, " t.Errorf(\"zero%du2 got=%%v, want %%v\\n\", b, wantb)\n", s) fmt.Fprintf(w, " }\n") fmt.Fprintf(w, "}\n") } // boilerplate at end - fmt.Fprintf(w, "var failed bool\n") - fmt.Fprintf(w, "func main() {\n") + fmt.Fprintf(w, "func TestZero(t *testing.T) {\n") for _, s := range sizes { - fmt.Fprintf(w, " testZero%d()\n", s) + fmt.Fprintf(w, " testZero%d(t)\n", s) } for _, s := range usizes { - fmt.Fprintf(w, " testZero%du()\n", s) + fmt.Fprintf(w, " testZero%du(t)\n", s) } - fmt.Fprintf(w, " if failed {\n") - fmt.Fprintf(w, " panic(\"failed\")\n") - fmt.Fprintf(w, " }\n") fmt.Fprintf(w, "}\n") // gofmt result @@ -144,7 +136,7 @@ func main() { } // write to file - err = ioutil.WriteFile("../zero.go", src, 0666) + err = ioutil.WriteFile("../zero_test.go", src, 0666) if err != nil { log.Fatalf("can't write output: %v\n", err) } diff --git a/src/cmd/compile/internal/gc/testdata/zero.go b/src/cmd/compile/internal/gc/testdata/zero_test.go similarity index 81% rename from src/cmd/compile/internal/gc/testdata/zero.go rename to src/cmd/compile/internal/gc/testdata/zero_test.go index 9d261aa401ac9..64fa25eed0693 100644 --- a/src/cmd/compile/internal/gc/testdata/zero.go +++ b/src/cmd/compile/internal/gc/testdata/zero_test.go @@ -1,11 +1,10 @@ -// run // Code generated by gen/zeroGen.go. DO NOT EDIT. package main -import "fmt" +import "testing" -type T1 struct { +type Z1 struct { pre [8]byte mid [1]byte post [8]byte @@ -15,17 +14,16 @@ type T1 struct { func zero1_ssa(x *[1]byte) { *x = [1]byte{} } -func testZero1() { - a := T1{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1]byte{255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero1(t *testing.T) { + a := Z1{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1]byte{255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero1_ssa(&a.mid) - want := T1{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1]byte{0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z1{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1]byte{0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero1 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero1 got=%v, want %v\n", a, want) } } -type T2 struct { +type Z2 struct { pre [8]byte mid [2]byte post [8]byte @@ -35,17 +33,16 @@ type T2 struct { func zero2_ssa(x *[2]byte) { *x = [2]byte{} } -func testZero2() { - a := T2{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [2]byte{255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero2(t *testing.T) { + a := Z2{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [2]byte{255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero2_ssa(&a.mid) - want := T2{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [2]byte{0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z2{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [2]byte{0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero2 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero2 got=%v, want %v\n", a, want) } } -type T3 struct { +type Z3 struct { pre [8]byte mid [3]byte post [8]byte @@ -55,17 +52,16 @@ type T3 struct { func zero3_ssa(x *[3]byte) { *x = [3]byte{} } -func testZero3() { - a := T3{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [3]byte{255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero3(t *testing.T) { + a := Z3{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [3]byte{255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero3_ssa(&a.mid) - want := T3{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [3]byte{0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z3{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [3]byte{0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero3 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero3 got=%v, want %v\n", a, want) } } -type T4 struct { +type Z4 struct { pre [8]byte mid [4]byte post [8]byte @@ -75,17 +71,16 @@ type T4 struct { func zero4_ssa(x *[4]byte) { *x = [4]byte{} } -func testZero4() { - a := T4{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [4]byte{255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero4(t *testing.T) { + a := Z4{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [4]byte{255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero4_ssa(&a.mid) - want := T4{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [4]byte{0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z4{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [4]byte{0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero4 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero4 got=%v, want %v\n", a, want) } } -type T5 struct { +type Z5 struct { pre [8]byte mid [5]byte post [8]byte @@ -95,17 +90,16 @@ type T5 struct { func zero5_ssa(x *[5]byte) { *x = [5]byte{} } -func testZero5() { - a := T5{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [5]byte{255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero5(t *testing.T) { + a := Z5{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [5]byte{255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero5_ssa(&a.mid) - want := T5{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [5]byte{0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z5{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [5]byte{0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero5 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero5 got=%v, want %v\n", a, want) } } -type T6 struct { +type Z6 struct { pre [8]byte mid [6]byte post [8]byte @@ -115,17 +109,16 @@ type T6 struct { func zero6_ssa(x *[6]byte) { *x = [6]byte{} } -func testZero6() { - a := T6{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [6]byte{255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero6(t *testing.T) { + a := Z6{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [6]byte{255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero6_ssa(&a.mid) - want := T6{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [6]byte{0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z6{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [6]byte{0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero6 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero6 got=%v, want %v\n", a, want) } } -type T7 struct { +type Z7 struct { pre [8]byte mid [7]byte post [8]byte @@ -135,17 +128,16 @@ type T7 struct { func zero7_ssa(x *[7]byte) { *x = [7]byte{} } -func testZero7() { - a := T7{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [7]byte{255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero7(t *testing.T) { + a := Z7{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [7]byte{255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero7_ssa(&a.mid) - want := T7{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [7]byte{0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z7{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [7]byte{0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero7 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero7 got=%v, want %v\n", a, want) } } -type T8 struct { +type Z8 struct { pre [8]byte mid [8]byte post [8]byte @@ -155,17 +147,16 @@ type T8 struct { func zero8_ssa(x *[8]byte) { *x = [8]byte{} } -func testZero8() { - a := T8{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero8(t *testing.T) { + a := Z8{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero8_ssa(&a.mid) - want := T8{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z8{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero8 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero8 got=%v, want %v\n", a, want) } } -type T9 struct { +type Z9 struct { pre [8]byte mid [9]byte post [8]byte @@ -175,17 +166,16 @@ type T9 struct { func zero9_ssa(x *[9]byte) { *x = [9]byte{} } -func testZero9() { - a := T9{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [9]byte{255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero9(t *testing.T) { + a := Z9{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [9]byte{255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero9_ssa(&a.mid) - want := T9{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [9]byte{0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z9{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [9]byte{0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero9 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero9 got=%v, want %v\n", a, want) } } -type T10 struct { +type Z10 struct { pre [8]byte mid [10]byte post [8]byte @@ -195,17 +185,16 @@ type T10 struct { func zero10_ssa(x *[10]byte) { *x = [10]byte{} } -func testZero10() { - a := T10{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [10]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero10(t *testing.T) { + a := Z10{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [10]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero10_ssa(&a.mid) - want := T10{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [10]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z10{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [10]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero10 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero10 got=%v, want %v\n", a, want) } } -type T15 struct { +type Z15 struct { pre [8]byte mid [15]byte post [8]byte @@ -215,17 +204,16 @@ type T15 struct { func zero15_ssa(x *[15]byte) { *x = [15]byte{} } -func testZero15() { - a := T15{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [15]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero15(t *testing.T) { + a := Z15{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [15]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero15_ssa(&a.mid) - want := T15{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [15]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z15{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [15]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero15 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero15 got=%v, want %v\n", a, want) } } -type T16 struct { +type Z16 struct { pre [8]byte mid [16]byte post [8]byte @@ -235,17 +223,16 @@ type T16 struct { func zero16_ssa(x *[16]byte) { *x = [16]byte{} } -func testZero16() { - a := T16{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [16]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero16(t *testing.T) { + a := Z16{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [16]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero16_ssa(&a.mid) - want := T16{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z16{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero16 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero16 got=%v, want %v\n", a, want) } } -type T17 struct { +type Z17 struct { pre [8]byte mid [17]byte post [8]byte @@ -255,17 +242,16 @@ type T17 struct { func zero17_ssa(x *[17]byte) { *x = [17]byte{} } -func testZero17() { - a := T17{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [17]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero17(t *testing.T) { + a := Z17{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [17]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero17_ssa(&a.mid) - want := T17{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [17]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z17{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [17]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero17 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero17 got=%v, want %v\n", a, want) } } -type T23 struct { +type Z23 struct { pre [8]byte mid [23]byte post [8]byte @@ -275,17 +261,16 @@ type T23 struct { func zero23_ssa(x *[23]byte) { *x = [23]byte{} } -func testZero23() { - a := T23{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [23]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero23(t *testing.T) { + a := Z23{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [23]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero23_ssa(&a.mid) - want := T23{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [23]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z23{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [23]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero23 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero23 got=%v, want %v\n", a, want) } } -type T24 struct { +type Z24 struct { pre [8]byte mid [24]byte post [8]byte @@ -295,17 +280,16 @@ type T24 struct { func zero24_ssa(x *[24]byte) { *x = [24]byte{} } -func testZero24() { - a := T24{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [24]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero24(t *testing.T) { + a := Z24{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [24]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero24_ssa(&a.mid) - want := T24{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [24]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z24{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [24]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero24 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero24 got=%v, want %v\n", a, want) } } -type T25 struct { +type Z25 struct { pre [8]byte mid [25]byte post [8]byte @@ -315,17 +299,16 @@ type T25 struct { func zero25_ssa(x *[25]byte) { *x = [25]byte{} } -func testZero25() { - a := T25{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [25]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero25(t *testing.T) { + a := Z25{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [25]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero25_ssa(&a.mid) - want := T25{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [25]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z25{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [25]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero25 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero25 got=%v, want %v\n", a, want) } } -type T31 struct { +type Z31 struct { pre [8]byte mid [31]byte post [8]byte @@ -335,17 +318,16 @@ type T31 struct { func zero31_ssa(x *[31]byte) { *x = [31]byte{} } -func testZero31() { - a := T31{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [31]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero31(t *testing.T) { + a := Z31{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [31]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero31_ssa(&a.mid) - want := T31{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [31]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z31{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [31]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero31 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero31 got=%v, want %v\n", a, want) } } -type T32 struct { +type Z32 struct { pre [8]byte mid [32]byte post [8]byte @@ -355,17 +337,16 @@ type T32 struct { func zero32_ssa(x *[32]byte) { *x = [32]byte{} } -func testZero32() { - a := T32{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [32]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero32(t *testing.T) { + a := Z32{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [32]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero32_ssa(&a.mid) - want := T32{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z32{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero32 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero32 got=%v, want %v\n", a, want) } } -type T33 struct { +type Z33 struct { pre [8]byte mid [33]byte post [8]byte @@ -375,17 +356,16 @@ type T33 struct { func zero33_ssa(x *[33]byte) { *x = [33]byte{} } -func testZero33() { - a := T33{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [33]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero33(t *testing.T) { + a := Z33{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [33]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero33_ssa(&a.mid) - want := T33{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [33]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z33{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [33]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero33 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero33 got=%v, want %v\n", a, want) } } -type T63 struct { +type Z63 struct { pre [8]byte mid [63]byte post [8]byte @@ -395,17 +375,16 @@ type T63 struct { func zero63_ssa(x *[63]byte) { *x = [63]byte{} } -func testZero63() { - a := T63{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [63]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero63(t *testing.T) { + a := Z63{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [63]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero63_ssa(&a.mid) - want := T63{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [63]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z63{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [63]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero63 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero63 got=%v, want %v\n", a, want) } } -type T64 struct { +type Z64 struct { pre [8]byte mid [64]byte post [8]byte @@ -415,17 +394,16 @@ type T64 struct { func zero64_ssa(x *[64]byte) { *x = [64]byte{} } -func testZero64() { - a := T64{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [64]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero64(t *testing.T) { + a := Z64{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [64]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero64_ssa(&a.mid) - want := T64{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [64]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z64{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [64]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero64 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero64 got=%v, want %v\n", a, want) } } -type T65 struct { +type Z65 struct { pre [8]byte mid [65]byte post [8]byte @@ -435,17 +413,16 @@ type T65 struct { func zero65_ssa(x *[65]byte) { *x = [65]byte{} } -func testZero65() { - a := T65{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [65]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero65(t *testing.T) { + a := Z65{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [65]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero65_ssa(&a.mid) - want := T65{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [65]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z65{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [65]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero65 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero65 got=%v, want %v\n", a, want) } } -type T1023 struct { +type Z1023 struct { pre [8]byte mid [1023]byte post [8]byte @@ -455,17 +432,16 @@ type T1023 struct { func zero1023_ssa(x *[1023]byte) { *x = [1023]byte{} } -func testZero1023() { - a := T1023{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1023]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero1023(t *testing.T) { + a := Z1023{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1023]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero1023_ssa(&a.mid) - want := T1023{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1023]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z1023{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1023]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero1023 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero1023 got=%v, want %v\n", a, want) } } -type T1024 struct { +type Z1024 struct { pre [8]byte mid [1024]byte post [8]byte @@ -475,17 +451,16 @@ type T1024 struct { func zero1024_ssa(x *[1024]byte) { *x = [1024]byte{} } -func testZero1024() { - a := T1024{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1024]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero1024(t *testing.T) { + a := Z1024{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1024]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero1024_ssa(&a.mid) - want := T1024{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1024]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z1024{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1024]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero1024 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero1024 got=%v, want %v\n", a, want) } } -type T1025 struct { +type Z1025 struct { pre [8]byte mid [1025]byte post [8]byte @@ -495,261 +470,242 @@ type T1025 struct { func zero1025_ssa(x *[1025]byte) { *x = [1025]byte{} } -func testZero1025() { - a := T1025{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1025]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero1025(t *testing.T) { + a := Z1025{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1025]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero1025_ssa(&a.mid) - want := T1025{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1025]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + want := Z1025{[8]byte{255, 255, 255, 255, 255, 255, 255, 255}, [1025]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} if a != want { - fmt.Printf("zero1025 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero1025 got=%v, want %v\n", a, want) } } -type T8u1 struct { +type Z8u1 struct { b bool val [8]byte } -type T8u2 struct { +type Z8u2 struct { i uint16 val [8]byte } //go:noinline -func zero8u1_ssa(t *T8u1) { +func zero8u1_ssa(t *Z8u1) { t.val = [8]byte{} } //go:noinline -func zero8u2_ssa(t *T8u2) { +func zero8u2_ssa(t *Z8u2) { t.val = [8]byte{} } -func testZero8u() { - a := T8u1{false, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} +func testZero8u(t *testing.T) { + a := Z8u1{false, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero8u1_ssa(&a) - want := T8u1{false, [8]byte{0, 0, 0, 0, 0, 0, 0, 0}} + want := Z8u1{false, [8]byte{0, 0, 0, 0, 0, 0, 0, 0}} if a != want { - fmt.Printf("zero8u2 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero8u2 got=%v, want %v\n", a, want) } - b := T8u2{15, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} + b := Z8u2{15, [8]byte{255, 255, 255, 255, 255, 255, 255, 255}} zero8u2_ssa(&b) - wantb := T8u2{15, [8]byte{0, 0, 0, 0, 0, 0, 0, 0}} + wantb := Z8u2{15, [8]byte{0, 0, 0, 0, 0, 0, 0, 0}} if b != wantb { - fmt.Printf("zero8u2 got=%v, want %v\n", b, wantb) - failed = true + t.Errorf("zero8u2 got=%v, want %v\n", b, wantb) } } -type T16u1 struct { +type Z16u1 struct { b bool val [16]byte } -type T16u2 struct { +type Z16u2 struct { i uint16 val [16]byte } //go:noinline -func zero16u1_ssa(t *T16u1) { +func zero16u1_ssa(t *Z16u1) { t.val = [16]byte{} } //go:noinline -func zero16u2_ssa(t *T16u2) { +func zero16u2_ssa(t *Z16u2) { t.val = [16]byte{} } -func testZero16u() { - a := T16u1{false, [16]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} +func testZero16u(t *testing.T) { + a := Z16u1{false, [16]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} zero16u1_ssa(&a) - want := T16u1{false, [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + want := Z16u1{false, [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} if a != want { - fmt.Printf("zero16u2 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero16u2 got=%v, want %v\n", a, want) } - b := T16u2{15, [16]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} + b := Z16u2{15, [16]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} zero16u2_ssa(&b) - wantb := T16u2{15, [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + wantb := Z16u2{15, [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} if b != wantb { - fmt.Printf("zero16u2 got=%v, want %v\n", b, wantb) - failed = true + t.Errorf("zero16u2 got=%v, want %v\n", b, wantb) } } -type T24u1 struct { +type Z24u1 struct { b bool val [24]byte } -type T24u2 struct { +type Z24u2 struct { i uint16 val [24]byte } //go:noinline -func zero24u1_ssa(t *T24u1) { +func zero24u1_ssa(t *Z24u1) { t.val = [24]byte{} } //go:noinline -func zero24u2_ssa(t *T24u2) { +func zero24u2_ssa(t *Z24u2) { t.val = [24]byte{} } -func testZero24u() { - a := T24u1{false, [24]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} +func testZero24u(t *testing.T) { + a := Z24u1{false, [24]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} zero24u1_ssa(&a) - want := T24u1{false, [24]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + want := Z24u1{false, [24]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} if a != want { - fmt.Printf("zero24u2 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero24u2 got=%v, want %v\n", a, want) } - b := T24u2{15, [24]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} + b := Z24u2{15, [24]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} zero24u2_ssa(&b) - wantb := T24u2{15, [24]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + wantb := Z24u2{15, [24]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} if b != wantb { - fmt.Printf("zero24u2 got=%v, want %v\n", b, wantb) - failed = true + t.Errorf("zero24u2 got=%v, want %v\n", b, wantb) } } -type T32u1 struct { +type Z32u1 struct { b bool val [32]byte } -type T32u2 struct { +type Z32u2 struct { i uint16 val [32]byte } //go:noinline -func zero32u1_ssa(t *T32u1) { +func zero32u1_ssa(t *Z32u1) { t.val = [32]byte{} } //go:noinline -func zero32u2_ssa(t *T32u2) { +func zero32u2_ssa(t *Z32u2) { t.val = [32]byte{} } -func testZero32u() { - a := T32u1{false, [32]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} +func testZero32u(t *testing.T) { + a := Z32u1{false, [32]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} zero32u1_ssa(&a) - want := T32u1{false, [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + want := Z32u1{false, [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} if a != want { - fmt.Printf("zero32u2 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero32u2 got=%v, want %v\n", a, want) } - b := T32u2{15, [32]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} + b := Z32u2{15, [32]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} zero32u2_ssa(&b) - wantb := T32u2{15, [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + wantb := Z32u2{15, [32]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} if b != wantb { - fmt.Printf("zero32u2 got=%v, want %v\n", b, wantb) - failed = true + t.Errorf("zero32u2 got=%v, want %v\n", b, wantb) } } -type T64u1 struct { +type Z64u1 struct { b bool val [64]byte } -type T64u2 struct { +type Z64u2 struct { i uint16 val [64]byte } //go:noinline -func zero64u1_ssa(t *T64u1) { +func zero64u1_ssa(t *Z64u1) { t.val = [64]byte{} } //go:noinline -func zero64u2_ssa(t *T64u2) { +func zero64u2_ssa(t *Z64u2) { t.val = [64]byte{} } -func testZero64u() { - a := T64u1{false, [64]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} +func testZero64u(t *testing.T) { + a := Z64u1{false, [64]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} zero64u1_ssa(&a) - want := T64u1{false, [64]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + want := Z64u1{false, [64]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} if a != want { - fmt.Printf("zero64u2 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero64u2 got=%v, want %v\n", a, want) } - b := T64u2{15, [64]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} + b := Z64u2{15, [64]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} zero64u2_ssa(&b) - wantb := T64u2{15, [64]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + wantb := Z64u2{15, [64]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} if b != wantb { - fmt.Printf("zero64u2 got=%v, want %v\n", b, wantb) - failed = true + t.Errorf("zero64u2 got=%v, want %v\n", b, wantb) } } -type T256u1 struct { +type Z256u1 struct { b bool val [256]byte } -type T256u2 struct { +type Z256u2 struct { i uint16 val [256]byte } //go:noinline -func zero256u1_ssa(t *T256u1) { +func zero256u1_ssa(t *Z256u1) { t.val = [256]byte{} } //go:noinline -func zero256u2_ssa(t *T256u2) { +func zero256u2_ssa(t *Z256u2) { t.val = [256]byte{} } -func testZero256u() { - a := T256u1{false, [256]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} +func testZero256u(t *testing.T) { + a := Z256u1{false, [256]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} zero256u1_ssa(&a) - want := T256u1{false, [256]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + want := Z256u1{false, [256]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} if a != want { - fmt.Printf("zero256u2 got=%v, want %v\n", a, want) - failed = true + t.Errorf("zero256u2 got=%v, want %v\n", a, want) } - b := T256u2{15, [256]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} + b := Z256u2{15, [256]byte{255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}} zero256u2_ssa(&b) - wantb := T256u2{15, [256]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} + wantb := Z256u2{15, [256]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}} if b != wantb { - fmt.Printf("zero256u2 got=%v, want %v\n", b, wantb) - failed = true - } -} - -var failed bool - -func main() { - testZero1() - testZero2() - testZero3() - testZero4() - testZero5() - testZero6() - testZero7() - testZero8() - testZero9() - testZero10() - testZero15() - testZero16() - testZero17() - testZero23() - testZero24() - testZero25() - testZero31() - testZero32() - testZero33() - testZero63() - testZero64() - testZero65() - testZero1023() - testZero1024() - testZero1025() - testZero8u() - testZero16u() - testZero24u() - testZero32u() - testZero64u() - testZero256u() - if failed { - panic("failed") - } + t.Errorf("zero256u2 got=%v, want %v\n", b, wantb) + } +} +func TestZero(t *testing.T) { + testZero1(t) + testZero2(t) + testZero3(t) + testZero4(t) + testZero5(t) + testZero6(t) + testZero7(t) + testZero8(t) + testZero9(t) + testZero10(t) + testZero15(t) + testZero16(t) + testZero17(t) + testZero23(t) + testZero24(t) + testZero25(t) + testZero31(t) + testZero32(t) + testZero33(t) + testZero63(t) + testZero64(t) + testZero65(t) + testZero1023(t) + testZero1024(t) + testZero1025(t) + testZero8u(t) + testZero16u(t) + testZero24u(t) + testZero32u(t) + testZero64u(t) + testZero256u(t) } From 78ce3a0368279653d05cbd1003e801363caba75a Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 7 Aug 2018 20:59:04 -0700 Subject: [PATCH 0190/1663] reflect: use a bigger object when we need a finalizer to run If an object is allocated as part of a tinyalloc, then other live objects in the same tinyalloc chunk keep the finalizer from being run, even if the object that has the finalizer is dead. Make sure the object we're setting the finalizer on is big enough to not trigger tinyalloc allocation. Fixes #26857 Update #21717 Change-Id: I56ad8679426283237ebff20a0da6c9cf64eb1c27 Reviewed-on: https://go-review.googlesource.com/128475 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Austin Clements Reviewed-by: Cherry Zhang --- src/reflect/all_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index 33bd75fda5086..c616b37008bad 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -1693,9 +1693,9 @@ func TestCallReturnsEmpty(t *testing.T) { // nonzero-sized frame and zero-sized return value. runtime.GC() var finalized uint32 - f := func() (emptyStruct, *int) { - i := new(int) - runtime.SetFinalizer(i, func(*int) { atomic.StoreUint32(&finalized, 1) }) + f := func() (emptyStruct, *[2]int64) { + i := new([2]int64) // big enough to not be tinyalloc'd, so finalizer always runs when i dies + runtime.SetFinalizer(i, func(*[2]int64) { atomic.StoreUint32(&finalized, 1) }) return emptyStruct{}, i } v := ValueOf(f).Call(nil)[0] // out[0] should not alias out[1]'s memory, so the finalizer should run. From 25ea4e579f44fa28189422b9951c375a5ff36a4e Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 31 Jul 2018 15:26:58 -0700 Subject: [PATCH 0191/1663] cmd/compile: move more compiler tests to new test infrastructure Update #26469 Change-Id: I1188e49cde1bda11506afef6b6e3f34c6ff45ea5 Reviewed-on: https://go-review.googlesource.com/127115 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/ssa_test.go | 20 ---- .../gc/testdata/{chan.go => chan_test.go} | 40 +++---- .../{compound.go => compound_test.go} | 63 +++++------ .../gc/testdata/{ctl.go => ctl_test.go} | 47 ++++---- ...deferNoReturn.go => deferNoReturn_test.go} | 10 +- .../{loadstore.go => loadstore_test.go} | 63 ++++------- .../gc/testdata/{map.go => map_test.go} | 26 ++--- src/cmd/compile/internal/gc/testdata/novet.go | 9 ++ .../{regalloc.go => regalloc_test.go} | 25 ++--- .../gc/testdata/{string.go => string_test.go} | 101 ++++++++---------- 10 files changed, 155 insertions(+), 249 deletions(-) rename src/cmd/compile/internal/gc/testdata/{chan.go => chan_test.go} (53%) rename src/cmd/compile/internal/gc/testdata/{compound.go => compound_test.go} (59%) rename src/cmd/compile/internal/gc/testdata/{ctl.go => ctl_test.go} (73%) rename src/cmd/compile/internal/gc/testdata/{deferNoReturn.go => deferNoReturn_test.go} (72%) rename src/cmd/compile/internal/gc/testdata/{loadstore.go => loadstore_test.go} (75%) rename src/cmd/compile/internal/gc/testdata/{map.go => map_test.go} (55%) create mode 100644 src/cmd/compile/internal/gc/testdata/novet.go rename src/cmd/compile/internal/gc/testdata/{regalloc.go => regalloc_test.go} (76%) rename src/cmd/compile/internal/gc/testdata/{string.go => string_test.go} (58%) diff --git a/src/cmd/compile/internal/gc/ssa_test.go b/src/cmd/compile/internal/gc/ssa_test.go index 4f7bab9fc5983..98230a15c6cb6 100644 --- a/src/cmd/compile/internal/gc/ssa_test.go +++ b/src/cmd/compile/internal/gc/ssa_test.go @@ -26,10 +26,6 @@ func runTest(t *testing.T, filename string, flags ...string) { t.Parallel() doTest(t, filename, "run", flags...) } -func buildTest(t *testing.T, filename string, flags ...string) { - t.Parallel() - doTest(t, filename, "build", flags...) -} func doTest(t *testing.T, filename string, kind string, flags ...string) { testenv.MustHaveGoBuild(t) gotool := testenv.GoToolPath(t) @@ -227,22 +223,6 @@ func TestCode(t *testing.T) { } } -func TestChan(t *testing.T) { runTest(t, "chan.go") } - -func TestCompound(t *testing.T) { runTest(t, "compound.go") } - -func TestCtl(t *testing.T) { runTest(t, "ctl.go") } - -func TestLoadStore(t *testing.T) { runTest(t, "loadstore.go") } - -func TestMap(t *testing.T) { runTest(t, "map.go") } - -func TestRegalloc(t *testing.T) { runTest(t, "regalloc.go") } - -func TestString(t *testing.T) { runTest(t, "string.go") } - -func TestDeferNoReturn(t *testing.T) { buildTest(t, "deferNoReturn.go") } - // TestClosure tests closure related behavior. func TestClosure(t *testing.T) { runTest(t, "closure.go") } diff --git a/src/cmd/compile/internal/gc/testdata/chan.go b/src/cmd/compile/internal/gc/testdata/chan_test.go similarity index 53% rename from src/cmd/compile/internal/gc/testdata/chan.go rename to src/cmd/compile/internal/gc/testdata/chan_test.go index 0766fcda5ba92..628bd8f7f782b 100644 --- a/src/cmd/compile/internal/gc/testdata/chan.go +++ b/src/cmd/compile/internal/gc/testdata/chan_test.go @@ -2,12 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// chan_ssa.go tests chan operations. +// chan.go tests chan operations. package main -import "fmt" - -var failed = false +import "testing" //go:noinline func lenChan_ssa(v chan int) int { @@ -19,7 +17,7 @@ func capChan_ssa(v chan int) int { return cap(v) } -func testLenChan() { +func testLenChan(t *testing.T) { v := make(chan int, 10) v <- 1 @@ -27,47 +25,39 @@ func testLenChan() { v <- 1 if want, got := 3, lenChan_ssa(v); got != want { - fmt.Printf("expected len(chan) = %d, got %d", want, got) - failed = true + t.Errorf("expected len(chan) = %d, got %d", want, got) } } -func testLenNilChan() { +func testLenNilChan(t *testing.T) { var v chan int if want, got := 0, lenChan_ssa(v); got != want { - fmt.Printf("expected len(nil) = %d, got %d", want, got) - failed = true + t.Errorf("expected len(nil) = %d, got %d", want, got) } } -func testCapChan() { +func testCapChan(t *testing.T) { v := make(chan int, 25) if want, got := 25, capChan_ssa(v); got != want { - fmt.Printf("expected cap(chan) = %d, got %d", want, got) - failed = true + t.Errorf("expected cap(chan) = %d, got %d", want, got) } } -func testCapNilChan() { +func testCapNilChan(t *testing.T) { var v chan int if want, got := 0, capChan_ssa(v); got != want { - fmt.Printf("expected cap(nil) = %d, got %d", want, got) - failed = true + t.Errorf("expected cap(nil) = %d, got %d", want, got) } } -func main() { - testLenChan() - testLenNilChan() - - testCapChan() - testCapNilChan() +func TestChan(t *testing.T) { + testLenChan(t) + testLenNilChan(t) - if failed { - panic("failed") - } + testCapChan(t) + testCapNilChan(t) } diff --git a/src/cmd/compile/internal/gc/testdata/compound.go b/src/cmd/compile/internal/gc/testdata/compound_test.go similarity index 59% rename from src/cmd/compile/internal/gc/testdata/compound.go rename to src/cmd/compile/internal/gc/testdata/compound_test.go index de10cdc77910e..4ae464dbe3843 100644 --- a/src/cmd/compile/internal/gc/testdata/compound.go +++ b/src/cmd/compile/internal/gc/testdata/compound_test.go @@ -1,5 +1,3 @@ -// run - // Copyright 2015 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. @@ -8,7 +6,9 @@ package main -import "fmt" +import ( + "testing" +) func string_ssa(a, b string, x bool) string { s := "" @@ -20,16 +20,14 @@ func string_ssa(a, b string, x bool) string { return s } -func testString() { +func testString(t *testing.T) { a := "foo" b := "barz" if want, got := a, string_ssa(a, b, true); got != want { - fmt.Printf("string_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) - failed = true + t.Errorf("string_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) } if want, got := b, string_ssa(a, b, false); got != want { - fmt.Printf("string_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want) - failed = true + t.Errorf("string_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want) } } @@ -55,31 +53,27 @@ func complex128_ssa(a, b complex128, x bool) complex128 { return c } -func testComplex64() { +func testComplex64(t *testing.T) { var a complex64 = 1 + 2i var b complex64 = 3 + 4i if want, got := a, complex64_ssa(a, b, true); got != want { - fmt.Printf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) - failed = true + t.Errorf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) } if want, got := b, complex64_ssa(a, b, false); got != want { - fmt.Printf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) - failed = true + t.Errorf("complex64_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) } } -func testComplex128() { +func testComplex128(t *testing.T) { var a complex128 = 1 + 2i var b complex128 = 3 + 4i if want, got := a, complex128_ssa(a, b, true); got != want { - fmt.Printf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) - failed = true + t.Errorf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) } if want, got := b, complex128_ssa(a, b, false); got != want { - fmt.Printf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) - failed = true + t.Errorf("complex128_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) } } @@ -93,16 +87,14 @@ func slice_ssa(a, b []byte, x bool) []byte { return s } -func testSlice() { +func testSlice(t *testing.T) { a := []byte{3, 4, 5} b := []byte{7, 8, 9} if want, got := byte(3), slice_ssa(a, b, true)[0]; got != want { - fmt.Printf("slice_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) - failed = true + t.Errorf("slice_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) } if want, got := byte(7), slice_ssa(a, b, false)[0]; got != want { - fmt.Printf("slice_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want) - failed = true + t.Errorf("slice_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want) } } @@ -116,28 +108,21 @@ func interface_ssa(a, b interface{}, x bool) interface{} { return s } -func testInterface() { +func testInterface(t *testing.T) { a := interface{}(3) b := interface{}(4) if want, got := 3, interface_ssa(a, b, true).(int); got != want { - fmt.Printf("interface_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) - failed = true + t.Errorf("interface_ssa(%v, %v, true) = %v, want %v\n", a, b, got, want) } if want, got := 4, interface_ssa(a, b, false).(int); got != want { - fmt.Printf("interface_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want) - failed = true + t.Errorf("interface_ssa(%v, %v, false) = %v, want %v\n", a, b, got, want) } } -var failed = false - -func main() { - testString() - testSlice() - testInterface() - testComplex64() - testComplex128() - if failed { - panic("failed") - } +func TestCompound(t *testing.T) { + testString(t) + testSlice(t) + testInterface(t) + testComplex64(t) + testComplex128(t) } diff --git a/src/cmd/compile/internal/gc/testdata/ctl.go b/src/cmd/compile/internal/gc/testdata/ctl_test.go similarity index 73% rename from src/cmd/compile/internal/gc/testdata/ctl.go rename to src/cmd/compile/internal/gc/testdata/ctl_test.go index 0656cb4ddbec8..16d571ce2cbf4 100644 --- a/src/cmd/compile/internal/gc/testdata/ctl.go +++ b/src/cmd/compile/internal/gc/testdata/ctl_test.go @@ -1,5 +1,3 @@ -// run - // Copyright 2015 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. @@ -8,6 +6,8 @@ package main +import "testing" + // nor_ssa calculates NOR(a, b). // It is implemented in a way that generates // phi control values. @@ -25,7 +25,7 @@ func nor_ssa(a, b bool) bool { return true } -func testPhiControl() { +func testPhiControl(t *testing.T) { tests := [...][3]bool{ // a, b, want {false, false, true}, {true, false, false}, @@ -37,8 +37,7 @@ func testPhiControl() { got := nor_ssa(a, b) want := test[2] if want != got { - print("nor(", a, ", ", b, ")=", want, " got ", got, "\n") - failed = true + t.Errorf("nor(%t, %t)=%t got %t", a, b, want, got) } } } @@ -50,10 +49,9 @@ func emptyRange_ssa(b []byte) bool { return true } -func testEmptyRange() { +func testEmptyRange(t *testing.T) { if !emptyRange_ssa([]byte{}) { - println("emptyRange_ssa([]byte{})=false, want true") - failed = true + t.Errorf("emptyRange_ssa([]byte{})=false, want true") } } @@ -97,20 +95,18 @@ func fallthrough_ssa(a int) int { } -func testFallthrough() { +func testFallthrough(t *testing.T) { for i := 0; i < 6; i++ { if got := fallthrough_ssa(i); got != i { - println("fallthrough_ssa(i) =", got, "wanted", i) - failed = true + t.Errorf("fallthrough_ssa(i) = %d, wanted %d", got, i) } } } -func testSwitch() { +func testSwitch(t *testing.T) { for i := 0; i < 6; i++ { if got := switch_ssa(i); got != i { - println("switch_ssa(i) =", got, "wanted", i) - failed = true + t.Errorf("switch_ssa(i) = %d, wanted %d", got, i) } } } @@ -135,26 +131,19 @@ func flagOverwrite_ssa(s *junk, c int) int { return 3 } -func testFlagOverwrite() { +func testFlagOverwrite(t *testing.T) { j := junk{} if got := flagOverwrite_ssa(&j, ' '); got != 3 { - println("flagOverwrite_ssa =", got, "wanted 3") - failed = true + t.Errorf("flagOverwrite_ssa = %d, wanted 3", got) } } -var failed = false - -func main() { - testPhiControl() - testEmptyRange() +func TestCtl(t *testing.T) { + testPhiControl(t) + testEmptyRange(t) - testSwitch() - testFallthrough() + testSwitch(t) + testFallthrough(t) - testFlagOverwrite() - - if failed { - panic("failed") - } + testFlagOverwrite(t) } diff --git a/src/cmd/compile/internal/gc/testdata/deferNoReturn.go b/src/cmd/compile/internal/gc/testdata/deferNoReturn_test.go similarity index 72% rename from src/cmd/compile/internal/gc/testdata/deferNoReturn.go rename to src/cmd/compile/internal/gc/testdata/deferNoReturn_test.go index 7578dd56f22f5..308e8976072e8 100644 --- a/src/cmd/compile/internal/gc/testdata/deferNoReturn.go +++ b/src/cmd/compile/internal/gc/testdata/deferNoReturn_test.go @@ -1,5 +1,3 @@ -// compile - // Copyright 2015 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. @@ -7,7 +5,9 @@ // Test that a defer in a function with no return // statement will compile correctly. -package foo +package main + +import "testing" func deferNoReturn_ssa() { defer func() { println("returned") }() @@ -15,3 +15,7 @@ func deferNoReturn_ssa() { println("loop") } } + +func TestDeferNoReturn(t *testing.T) { + // This is a compile-time test, no runtime testing required. +} diff --git a/src/cmd/compile/internal/gc/testdata/loadstore.go b/src/cmd/compile/internal/gc/testdata/loadstore_test.go similarity index 75% rename from src/cmd/compile/internal/gc/testdata/loadstore.go rename to src/cmd/compile/internal/gc/testdata/loadstore_test.go index dcb61d4b7eb66..57571f5d170ec 100644 --- a/src/cmd/compile/internal/gc/testdata/loadstore.go +++ b/src/cmd/compile/internal/gc/testdata/loadstore_test.go @@ -1,5 +1,3 @@ -// run - // Copyright 2015 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. @@ -8,14 +6,13 @@ package main -import "fmt" +import "testing" // testLoadStoreOrder tests for reordering of stores/loads. -func testLoadStoreOrder() { +func testLoadStoreOrder(t *testing.T) { z := uint32(1000) if testLoadStoreOrder_ssa(&z, 100) == 0 { - println("testLoadStoreOrder failed") - failed = true + t.Errorf("testLoadStoreOrder failed") } } @@ -29,13 +26,12 @@ func testLoadStoreOrder_ssa(z *uint32, prec uint) int { return 0 } -func testStoreSize() { +func testStoreSize(t *testing.T) { a := [4]uint16{11, 22, 33, 44} testStoreSize_ssa(&a[0], &a[2], 77) want := [4]uint16{77, 22, 33, 44} if a != want { - fmt.Println("testStoreSize failed. want =", want, ", got =", a) - failed = true + t.Errorf("testStoreSize failed. want = %d, got = %d", want, a) } } @@ -55,8 +51,6 @@ func testStoreSize_ssa(p *uint16, q *uint16, v uint32) { } } -var failed = false - //go:noinline func testExtStore_ssa(p *byte, b bool) int { x := *p @@ -67,12 +61,11 @@ func testExtStore_ssa(p *byte, b bool) int { return 0 } -func testExtStore() { +func testExtStore(t *testing.T) { const start = 8 var b byte = start if got := testExtStore_ssa(&b, true); got != start { - fmt.Println("testExtStore failed. want =", start, ", got =", got) - failed = true + t.Errorf("testExtStore failed. want = %d, got = %d", start, got) } } @@ -95,10 +88,9 @@ func testDeadStorePanic_ssa(a int) (r int) { return } -func testDeadStorePanic() { +func testDeadStorePanic(t *testing.T) { if want, got := 2, testDeadStorePanic_ssa(1); want != got { - fmt.Println("testDeadStorePanic failed. want =", want, ", got =", got) - failed = true + t.Errorf("testDeadStorePanic failed. want = %d, got = %d", want, got) } } @@ -144,7 +136,7 @@ func loadHitStoreU32(x uint32, p *uint32) uint64 { return uint64(*p) // load and cast } -func testLoadHitStore() { +func testLoadHitStore(t *testing.T) { // Test that sign/zero extensions are kept when a load-hit-store // is replaced by a register-register move. { @@ -153,8 +145,7 @@ func testLoadHitStore() { got := loadHitStore8(in, &p) want := int32(in * in) if got != want { - fmt.Println("testLoadHitStore (int8) failed. want =", want, ", got =", got) - failed = true + t.Errorf("testLoadHitStore (int8) failed. want = %d, got = %d", want, got) } } { @@ -163,8 +154,7 @@ func testLoadHitStore() { got := loadHitStoreU8(in, &p) want := uint32(in * in) if got != want { - fmt.Println("testLoadHitStore (uint8) failed. want =", want, ", got =", got) - failed = true + t.Errorf("testLoadHitStore (uint8) failed. want = %d, got = %d", want, got) } } { @@ -173,8 +163,7 @@ func testLoadHitStore() { got := loadHitStore16(in, &p) want := int32(in * in) if got != want { - fmt.Println("testLoadHitStore (int16) failed. want =", want, ", got =", got) - failed = true + t.Errorf("testLoadHitStore (int16) failed. want = %d, got = %d", want, got) } } { @@ -183,8 +172,7 @@ func testLoadHitStore() { got := loadHitStoreU16(in, &p) want := uint32(in * in) if got != want { - fmt.Println("testLoadHitStore (uint16) failed. want =", want, ", got =", got) - failed = true + t.Errorf("testLoadHitStore (uint16) failed. want = %d, got = %d", want, got) } } { @@ -193,8 +181,7 @@ func testLoadHitStore() { got := loadHitStore32(in, &p) want := int64(in * in) if got != want { - fmt.Println("testLoadHitStore (int32) failed. want =", want, ", got =", got) - failed = true + t.Errorf("testLoadHitStore (int32) failed. want = %d, got = %d", want, got) } } { @@ -203,21 +190,15 @@ func testLoadHitStore() { got := loadHitStoreU32(in, &p) want := uint64(in * in) if got != want { - fmt.Println("testLoadHitStore (uint32) failed. want =", want, ", got =", got) - failed = true + t.Errorf("testLoadHitStore (uint32) failed. want = %d, got = %d", want, got) } } } -func main() { - - testLoadStoreOrder() - testStoreSize() - testExtStore() - testDeadStorePanic() - testLoadHitStore() - - if failed { - panic("failed") - } +func TestLoadStore(t *testing.T) { + testLoadStoreOrder(t) + testStoreSize(t) + testExtStore(t) + testDeadStorePanic(t) + testLoadHitStore(t) } diff --git a/src/cmd/compile/internal/gc/testdata/map.go b/src/cmd/compile/internal/gc/testdata/map_test.go similarity index 55% rename from src/cmd/compile/internal/gc/testdata/map.go rename to src/cmd/compile/internal/gc/testdata/map_test.go index 4a466003c72a9..71dc820c1c9a9 100644 --- a/src/cmd/compile/internal/gc/testdata/map.go +++ b/src/cmd/compile/internal/gc/testdata/map_test.go @@ -2,19 +2,17 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// map_ssa.go tests map operations. +// map.go tests map operations. package main -import "fmt" - -var failed = false +import "testing" //go:noinline func lenMap_ssa(v map[int]int) int { return len(v) } -func testLenMap() { +func testLenMap(t *testing.T) { v := make(map[int]int) v[0] = 0 @@ -22,24 +20,18 @@ func testLenMap() { v[2] = 0 if want, got := 3, lenMap_ssa(v); got != want { - fmt.Printf("expected len(map) = %d, got %d", want, got) - failed = true + t.Errorf("expected len(map) = %d, got %d", want, got) } } -func testLenNilMap() { +func testLenNilMap(t *testing.T) { var v map[int]int if want, got := 0, lenMap_ssa(v); got != want { - fmt.Printf("expected len(nil) = %d, got %d", want, got) - failed = true + t.Errorf("expected len(nil) = %d, got %d", want, got) } } -func main() { - testLenMap() - testLenNilMap() - - if failed { - panic("failed") - } +func TestMap(t *testing.T) { + testLenMap(t) + testLenNilMap(t) } diff --git a/src/cmd/compile/internal/gc/testdata/novet.go b/src/cmd/compile/internal/gc/testdata/novet.go new file mode 100644 index 0000000000000..0fcbba290c462 --- /dev/null +++ b/src/cmd/compile/internal/gc/testdata/novet.go @@ -0,0 +1,9 @@ +// Copyright 2018 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. + +// This file exists just to convince vet not to check this directory. +// (vet will not check a directory with two different packages in it.) +// TODO: remove this hack & add failing tests to the whitelist. + +package foo diff --git a/src/cmd/compile/internal/gc/testdata/regalloc.go b/src/cmd/compile/internal/gc/testdata/regalloc_test.go similarity index 76% rename from src/cmd/compile/internal/gc/testdata/regalloc.go rename to src/cmd/compile/internal/gc/testdata/regalloc_test.go index f752692952dcc..577f8e76842e6 100644 --- a/src/cmd/compile/internal/gc/testdata/regalloc.go +++ b/src/cmd/compile/internal/gc/testdata/regalloc_test.go @@ -1,5 +1,3 @@ -// run - // Copyright 2015 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. @@ -8,6 +6,8 @@ package main +import "testing" + func phiOverwrite_ssa() int { var n int for i := 0; i < 10; i++ { @@ -19,12 +19,11 @@ func phiOverwrite_ssa() int { return n } -func phiOverwrite() { +func phiOverwrite(t *testing.T) { want := 5 got := phiOverwrite_ssa() if got != want { - println("phiOverwrite_ssa()=", want, ", got", got) - failed = true + t.Errorf("phiOverwrite_ssa()= %d, got %d", want, got) } } @@ -37,21 +36,15 @@ func phiOverwriteBig_ssa() int { return a*1 + b*2 + c*3 + d*4 + e*5 + f*6 + g*7 + h*8 + i*9 + j*10 + k*11 + l*12 + m*13 + n*14 + o*15 + p*16 + q*17 + r*18 + s*19 + t*20 + u*21 + v*22 + w*23 + x*24 + y*25 + z*26 } -func phiOverwriteBig() { +func phiOverwriteBig(t *testing.T) { want := 1 got := phiOverwriteBig_ssa() if got != want { - println("phiOverwriteBig_ssa()=", want, ", got", got) - failed = true + t.Errorf("phiOverwriteBig_ssa()= %d, got %d", want, got) } } -var failed = false - -func main() { - phiOverwrite() - phiOverwriteBig() - if failed { - panic("failed") - } +func TestRegalloc(t *testing.T) { + phiOverwrite(t) + phiOverwriteBig(t) } diff --git a/src/cmd/compile/internal/gc/testdata/string.go b/src/cmd/compile/internal/gc/testdata/string_test.go similarity index 58% rename from src/cmd/compile/internal/gc/testdata/string.go rename to src/cmd/compile/internal/gc/testdata/string_test.go index 03053a6134a92..5d086f014733c 100644 --- a/src/cmd/compile/internal/gc/testdata/string.go +++ b/src/cmd/compile/internal/gc/testdata/string_test.go @@ -5,7 +5,7 @@ // string_ssa.go tests string operations. package main -var failed = false +import "testing" //go:noinline func testStringSlice1_ssa(a string, i, j int) string { @@ -22,7 +22,7 @@ func testStringSlice12_ssa(a string, i, j int) string { return a[i:j] } -func testStringSlice() { +func testStringSlice(t *testing.T) { tests := [...]struct { fn func(string, int, int) string s string @@ -44,10 +44,9 @@ func testStringSlice() { {testStringSlice12_ssa, "", 0, 0, ""}, } - for i, t := range tests { - if got := t.fn(t.s, t.low, t.high); t.want != got { - println("#", i, " ", t.s, "[", t.low, ":", t.high, "] = ", got, " want ", t.want) - failed = true + for i, test := range tests { + if got := test.fn(test.s, test.low, test.high); test.want != got { + t.Errorf("#%d %s[%d,%d] = %s, want %s", i, test.s, test.low, test.high, got, test.want) } } } @@ -61,26 +60,23 @@ func (p *prefix) slice_ssa() { } //go:noinline -func testStructSlice() { +func testStructSlice(t *testing.T) { p := &prefix{"prefix"} p.slice_ssa() if "pre" != p.prefix { - println("wrong field slice: wanted %s got %s", "pre", p.prefix) - failed = true + t.Errorf("wrong field slice: wanted %s got %s", "pre", p.prefix) } } -func testStringSlicePanic() { +func testStringSlicePanic(t *testing.T) { defer func() { if r := recover(); r != nil { - println("panicked as expected") + //println("panicked as expected") } }() str := "foobar" - println("got ", testStringSlice12_ssa(str, 3, 9)) - println("expected to panic, but didn't") - failed = true + t.Errorf("got %s and expected to panic, but didn't", testStringSlice12_ssa(str, 3, 9)) } const _Accuracy_name = "BelowExactAbove" @@ -92,7 +88,7 @@ func testSmallIndexType_ssa(i int) string { return _Accuracy_name[_Accuracy_index[i]:_Accuracy_index[i+1]] } -func testSmallIndexType() { +func testSmallIndexType(t *testing.T) { tests := []struct { i int want string @@ -102,10 +98,9 @@ func testSmallIndexType() { {2, "Above"}, } - for i, t := range tests { - if got := testSmallIndexType_ssa(t.i); got != t.want { - println("#", i, "got ", got, ", wanted", t.want) - failed = true + for i, test := range tests { + if got := testSmallIndexType_ssa(test.i); got != test.want { + t.Errorf("#%d got %s wanted %s", i, got, test.want) } } } @@ -120,7 +115,7 @@ func testInt64Slice_ssa(s string, i, j int64) string { return s[i:j] } -func testInt64Index() { +func testInt64Index(t *testing.T) { tests := []struct { i int64 j int64 @@ -133,42 +128,36 @@ func testInt64Index() { } str := "BelowExactAbove" - for i, t := range tests { - if got := testInt64Index_ssa(str, t.i); got != t.b { - println("#", i, "got ", got, ", wanted", t.b) - failed = true + for i, test := range tests { + if got := testInt64Index_ssa(str, test.i); got != test.b { + t.Errorf("#%d got %d wanted %d", i, got, test.b) } - if got := testInt64Slice_ssa(str, t.i, t.j); got != t.s { - println("#", i, "got ", got, ", wanted", t.s) - failed = true + if got := testInt64Slice_ssa(str, test.i, test.j); got != test.s { + t.Errorf("#%d got %s wanted %s", i, got, test.s) } } } -func testInt64IndexPanic() { +func testInt64IndexPanic(t *testing.T) { defer func() { if r := recover(); r != nil { - println("panicked as expected") + //println("panicked as expected") } }() str := "foobar" - println("got ", testInt64Index_ssa(str, 1<<32+1)) - println("expected to panic, but didn't") - failed = true + t.Errorf("got %d and expected to panic, but didn't", testInt64Index_ssa(str, 1<<32+1)) } -func testInt64SlicePanic() { +func testInt64SlicePanic(t *testing.T) { defer func() { if r := recover(); r != nil { - println("panicked as expected") + //println("panicked as expected") } }() str := "foobar" - println("got ", testInt64Slice_ssa(str, 1<<32, 1<<32+1)) - println("expected to panic, but didn't") - failed = true + t.Errorf("got %s and expected to panic, but didn't", testInt64Slice_ssa(str, 1<<32, 1<<32+1)) } //go:noinline @@ -176,7 +165,7 @@ func testStringElem_ssa(s string, i int) byte { return s[i] } -func testStringElem() { +func testStringElem(t *testing.T) { tests := []struct { s string i int @@ -186,10 +175,9 @@ func testStringElem() { {"foobar", 0, 102}, {"foobar", 5, 114}, } - for _, t := range tests { - if got := testStringElem_ssa(t.s, t.i); got != t.n { - print("testStringElem \"", t.s, "\"[", t.i, "]=", got, ", wanted ", t.n, "\n") - failed = true + for _, test := range tests { + if got := testStringElem_ssa(test.s, test.i); got != test.n { + t.Errorf("testStringElem \"%s\"[%d] = %d, wanted %d", test.s, test.i, got, test.n) } } } @@ -200,25 +188,20 @@ func testStringElemConst_ssa(i int) byte { return s[i] } -func testStringElemConst() { +func testStringElemConst(t *testing.T) { if got := testStringElemConst_ssa(3); got != 98 { - println("testStringElemConst=", got, ", wanted 98") - failed = true + t.Errorf("testStringElemConst= %d, wanted 98", got) } } -func main() { - testStringSlice() - testStringSlicePanic() - testStructSlice() - testSmallIndexType() - testStringElem() - testStringElemConst() - testInt64Index() - testInt64IndexPanic() - testInt64SlicePanic() - - if failed { - panic("failed") - } +func TestString(t *testing.T) { + testStringSlice(t) + testStringSlicePanic(t) + testStructSlice(t) + testSmallIndexType(t) + testStringElem(t) + testStringElemConst(t) + testInt64Index(t) + testInt64IndexPanic(t) + testInt64SlicePanic(t) } From dca709da1dd3fb1177c70288a4ec1bf1baa36a5b Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 31 Jul 2018 16:00:10 -0700 Subject: [PATCH 0192/1663] cmd/compile: move last compile tests to new test infrastructure R=go1.12 Fixes #26469 Change-Id: Idbba88ef60f15a0ec9a83c78541a4d4fb63e534a Reviewed-on: https://go-review.googlesource.com/127116 Reviewed-by: David Chase --- src/cmd/compile/internal/gc/ssa_test.go | 54 ---------------- .../{addressed.go => addressed_test.go} | 59 +++++++++--------- .../gc/testdata/{append.go => append_test.go} | 37 +++++------ .../gc/testdata/{array.go => array_test.go} | 62 ++++++++----------- .../testdata/{closure.go => closure_test.go} | 20 +++--- .../testdata/{dupLoad.go => dupLoad_test.go} | 24 +++---- .../{namedReturn.go => namedReturn_test.go} | 44 +++++-------- .../gc/testdata/{phi.go => phi_test.go} | 12 ++-- src/cmd/compile/internal/gc/testdata/slice.go | 50 --------------- .../internal/gc/testdata/slice_test.go | 46 ++++++++++++++ .../{sqrt_const.go => sqrtConst_test.go} | 19 ++---- .../gc/testdata/{unsafe.go => unsafe_test.go} | 35 +++++------ 12 files changed, 175 insertions(+), 287 deletions(-) rename src/cmd/compile/internal/gc/testdata/{addressed.go => addressed_test.go} (83%) rename src/cmd/compile/internal/gc/testdata/{append.go => append_test.go} (60%) rename src/cmd/compile/internal/gc/testdata/{array.go => array_test.go} (62%) rename src/cmd/compile/internal/gc/testdata/{closure.go => closure_test.go} (60%) rename src/cmd/compile/internal/gc/testdata/{dupLoad.go => dupLoad_test.go} (84%) rename src/cmd/compile/internal/gc/testdata/{namedReturn.go => namedReturn_test.go} (69%) rename src/cmd/compile/internal/gc/testdata/{phi.go => phi_test.go} (94%) delete mode 100644 src/cmd/compile/internal/gc/testdata/slice.go create mode 100644 src/cmd/compile/internal/gc/testdata/slice_test.go rename src/cmd/compile/internal/gc/testdata/{sqrt_const.go => sqrtConst_test.go} (73%) rename src/cmd/compile/internal/gc/testdata/{unsafe.go => unsafe_test.go} (88%) diff --git a/src/cmd/compile/internal/gc/ssa_test.go b/src/cmd/compile/internal/gc/ssa_test.go index 98230a15c6cb6..7f7c9464d44fa 100644 --- a/src/cmd/compile/internal/gc/ssa_test.go +++ b/src/cmd/compile/internal/gc/ssa_test.go @@ -20,39 +20,6 @@ import ( "testing" ) -// TODO: move all these tests elsewhere? -// Perhaps teach test/run.go how to run them with a new action verb. -func runTest(t *testing.T, filename string, flags ...string) { - t.Parallel() - doTest(t, filename, "run", flags...) -} -func doTest(t *testing.T, filename string, kind string, flags ...string) { - testenv.MustHaveGoBuild(t) - gotool := testenv.GoToolPath(t) - - var stdout, stderr bytes.Buffer - args := []string{kind} - if len(flags) == 0 { - args = append(args, "-gcflags=-d=ssa/check/on") - } else { - args = append(args, flags...) - } - args = append(args, filepath.Join("testdata", filename)) - cmd := exec.Command(gotool, args...) - cmd.Stdout = &stdout - cmd.Stderr = &stderr - err := cmd.Run() - if err != nil { - t.Fatalf("Failed: %v:\nOut: %s\nStderr: %s\n", err, &stdout, &stderr) - } - if s := stdout.String(); s != "" { - t.Errorf("Stdout = %s\nWant empty", s) - } - if s := stderr.String(); strings.Contains(s, "SSA unimplemented") { - t.Errorf("Unimplemented message found in stderr:\n%s", s) - } -} - // runGenTest runs a test-generator, then runs the generated test. // Generated test can either fail in compilation or execution. // The environment variable parameter(s) is passed to the run @@ -222,24 +189,3 @@ func TestCode(t *testing.T) { } } } - -// TestClosure tests closure related behavior. -func TestClosure(t *testing.T) { runTest(t, "closure.go") } - -func TestArray(t *testing.T) { runTest(t, "array.go") } - -func TestAppend(t *testing.T) { runTest(t, "append.go") } - -func TestAddressed(t *testing.T) { runTest(t, "addressed.go") } - -func TestUnsafe(t *testing.T) { runTest(t, "unsafe.go") } - -func TestPhi(t *testing.T) { runTest(t, "phi.go") } - -func TestSlice(t *testing.T) { runTest(t, "slice.go") } - -func TestNamedReturn(t *testing.T) { runTest(t, "namedReturn.go") } - -func TestDuplicateLoad(t *testing.T) { runTest(t, "dupLoad.go") } - -func TestSqrt(t *testing.T) { runTest(t, "sqrt_const.go") } diff --git a/src/cmd/compile/internal/gc/testdata/addressed.go b/src/cmd/compile/internal/gc/testdata/addressed_test.go similarity index 83% rename from src/cmd/compile/internal/gc/testdata/addressed.go rename to src/cmd/compile/internal/gc/testdata/addressed_test.go index 59cf238c74994..cdabf978f086b 100644 --- a/src/cmd/compile/internal/gc/testdata/addressed.go +++ b/src/cmd/compile/internal/gc/testdata/addressed_test.go @@ -4,48 +4,51 @@ package main -import "fmt" +import ( + "fmt" + "testing" +) var output string -func mypanic(s string) { - fmt.Printf(output) - panic(s) +func mypanic(t *testing.T, s string) { + t.Fatalf(s + "\n" + output) + } -func assertEqual(x, y int) { +func assertEqual(t *testing.T, x, y int) { if x != y { - mypanic("assertEqual failed") + mypanic(t, fmt.Sprintf("assertEqual failed got %d, want %d", x, y)) } } -func main() { +func TestAddressed(t *testing.T) { x := f1_ssa(2, 3) output += fmt.Sprintln("*x is", *x) output += fmt.Sprintln("Gratuitously use some stack") output += fmt.Sprintln("*x is", *x) - assertEqual(*x, 9) + assertEqual(t, *x, 9) w := f3a_ssa(6) output += fmt.Sprintln("*w is", *w) output += fmt.Sprintln("Gratuitously use some stack") output += fmt.Sprintln("*w is", *w) - assertEqual(*w, 6) + assertEqual(t, *w, 6) y := f3b_ssa(12) output += fmt.Sprintln("*y.(*int) is", *y.(*int)) output += fmt.Sprintln("Gratuitously use some stack") output += fmt.Sprintln("*y.(*int) is", *y.(*int)) - assertEqual(*y.(*int), 12) + assertEqual(t, *y.(*int), 12) z := f3c_ssa(8) output += fmt.Sprintln("*z.(*int) is", *z.(*int)) output += fmt.Sprintln("Gratuitously use some stack") output += fmt.Sprintln("*z.(*int) is", *z.(*int)) - assertEqual(*z.(*int), 8) + assertEqual(t, *z.(*int), 8) - args() - test_autos() + args(t) + test_autos(t) } //go:noinline @@ -75,13 +78,13 @@ type V struct { w, x int64 } -func args() { +func args(t *testing.T) { v := V{p: nil, w: 1, x: 1} a := V{p: &v, w: 2, x: 2} b := V{p: &v, w: 0, x: 0} i := v.args_ssa(a, b) output += fmt.Sprintln("i=", i) - assertEqual(int(i), 2) + assertEqual(t, int(i), 2) } //go:noinline @@ -100,32 +103,32 @@ func (v V) args_ssa(a, b V) int64 { return -1 } -func test_autos() { - test(11) - test(12) - test(13) - test(21) - test(22) - test(23) - test(31) - test(32) +func test_autos(t *testing.T) { + test(t, 11) + test(t, 12) + test(t, 13) + test(t, 21) + test(t, 22) + test(t, 23) + test(t, 31) + test(t, 32) } -func test(which int64) { +func test(t *testing.T, which int64) { output += fmt.Sprintln("test", which) v1 := V{w: 30, x: 3, p: nil} v2, v3 := v1.autos_ssa(which, 10, 1, 20, 2) if which != v2.val() { output += fmt.Sprintln("Expected which=", which, "got v2.val()=", v2.val()) - mypanic("Failure of expected V value") + mypanic(t, "Failure of expected V value") } if v2.p.val() != v3.val() { output += fmt.Sprintln("Expected v2.p.val()=", v2.p.val(), "got v3.val()=", v3.val()) - mypanic("Failure of expected V.p value") + mypanic(t, "Failure of expected V.p value") } if which != v3.p.p.p.p.p.p.p.val() { output += fmt.Sprintln("Expected which=", which, "got v3.p.p.p.p.p.p.p.val()=", v3.p.p.p.p.p.p.p.val()) - mypanic("Failure of expected V.p value") + mypanic(t, "Failure of expected V.p value") } } diff --git a/src/cmd/compile/internal/gc/testdata/append.go b/src/cmd/compile/internal/gc/testdata/append_test.go similarity index 60% rename from src/cmd/compile/internal/gc/testdata/append.go rename to src/cmd/compile/internal/gc/testdata/append_test.go index 03cd219c32cbb..6663ce75fa493 100644 --- a/src/cmd/compile/internal/gc/testdata/append.go +++ b/src/cmd/compile/internal/gc/testdata/append_test.go @@ -5,9 +5,7 @@ // append_ssa.go tests append operations. package main -import "fmt" - -var failed = false +import "testing" //go:noinline func appendOne_ssa(a []int, x int) []int { @@ -19,7 +17,7 @@ func appendThree_ssa(a []int, x, y, z int) []int { return append(a, x, y, z) } -func eq(a, b []int) bool { +func eqBytes(a, b []int) bool { if len(a) != len(b) { return false } @@ -31,40 +29,33 @@ func eq(a, b []int) bool { return true } -func expect(got, want []int) { - if eq(got, want) { +func expect(t *testing.T, got, want []int) { + if eqBytes(got, want) { return } - fmt.Printf("expected %v, got %v\n", want, got) - failed = true + t.Errorf("expected %v, got %v\n", want, got) } -func testAppend() { +func testAppend(t *testing.T) { var store [7]int a := store[:0] a = appendOne_ssa(a, 1) - expect(a, []int{1}) + expect(t, a, []int{1}) a = appendThree_ssa(a, 2, 3, 4) - expect(a, []int{1, 2, 3, 4}) + expect(t, a, []int{1, 2, 3, 4}) a = appendThree_ssa(a, 5, 6, 7) - expect(a, []int{1, 2, 3, 4, 5, 6, 7}) + expect(t, a, []int{1, 2, 3, 4, 5, 6, 7}) if &a[0] != &store[0] { - fmt.Println("unnecessary grow") - failed = true + t.Errorf("unnecessary grow") } a = appendOne_ssa(a, 8) - expect(a, []int{1, 2, 3, 4, 5, 6, 7, 8}) + expect(t, a, []int{1, 2, 3, 4, 5, 6, 7, 8}) if &a[0] == &store[0] { - fmt.Println("didn't grow") - failed = true + t.Errorf("didn't grow") } } -func main() { - testAppend() - - if failed { - panic("failed") - } +func TestAppend(t *testing.T) { + testAppend(t) } diff --git a/src/cmd/compile/internal/gc/testdata/array.go b/src/cmd/compile/internal/gc/testdata/array_test.go similarity index 62% rename from src/cmd/compile/internal/gc/testdata/array.go rename to src/cmd/compile/internal/gc/testdata/array_test.go index 6be8d9155ba1f..efa00d0520fca 100644 --- a/src/cmd/compile/internal/gc/testdata/array.go +++ b/src/cmd/compile/internal/gc/testdata/array_test.go @@ -1,6 +1,6 @@ package main -var failed = false +import "testing" //go:noinline func testSliceLenCap12_ssa(a [10]int, i, j int) (int, int) { @@ -20,7 +20,7 @@ func testSliceLenCap2_ssa(a [10]int, i, j int) (int, int) { return len(b), cap(b) } -func testSliceLenCap() { +func testSliceLenCap(t *testing.T) { a := [10]int{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} tests := [...]struct { fn func(a [10]int, i, j int) (int, int) @@ -43,11 +43,9 @@ func testSliceLenCap() { {testSliceLenCap2_ssa, -1, 10, 10, 10}, } - for i, t := range tests { - if l, c := t.fn(a, t.i, t.j); l != t.l && c != t.c { - println("#", i, " len(a[", t.i, ":", t.j, "]), cap(a[", t.i, ":", t.j, "]) =", l, c, - ", want", t.l, t.c) - failed = true + for i, test := range tests { + if l, c := test.fn(a, test.i, test.j); l != test.l && c != test.c { + t.Errorf("#%d len(a[%d:%d]), cap(a[%d:%d]) = %d %d, want %d %d", i, test.i, test.j, test.i, test.j, l, c, test.l, test.c) } } } @@ -57,7 +55,7 @@ func testSliceGetElement_ssa(a [10]int, i, j, p int) int { return a[i:j][p] } -func testSliceGetElement() { +func testSliceGetElement(t *testing.T) { a := [10]int{0, 10, 20, 30, 40, 50, 60, 70, 80, 90} tests := [...]struct { i, j, p int @@ -69,10 +67,9 @@ func testSliceGetElement() { {1, 9, 7, 80}, } - for i, t := range tests { - if got := testSliceGetElement_ssa(a, t.i, t.j, t.p); got != t.want { - println("#", i, " a[", t.i, ":", t.j, "][", t.p, "] = ", got, " wanted ", t.want) - failed = true + for i, test := range tests { + if got := testSliceGetElement_ssa(a, test.i, test.j, test.p); got != test.want { + t.Errorf("#%d a[%d:%d][%d] = %d, wanted %d", i, test.i, test.j, test.p, got, test.want) } } } @@ -82,7 +79,7 @@ func testSliceSetElement_ssa(a *[10]int, i, j, p, x int) { (*a)[i:j][p] = x } -func testSliceSetElement() { +func testSliceSetElement(t *testing.T) { a := [10]int{0, 10, 20, 30, 40, 50, 60, 70, 80, 90} tests := [...]struct { i, j, p int @@ -94,49 +91,42 @@ func testSliceSetElement() { {1, 9, 7, 99}, } - for i, t := range tests { - testSliceSetElement_ssa(&a, t.i, t.j, t.p, t.want) - if got := a[t.i+t.p]; got != t.want { - println("#", i, " a[", t.i, ":", t.j, "][", t.p, "] = ", got, " wanted ", t.want) - failed = true + for i, test := range tests { + testSliceSetElement_ssa(&a, test.i, test.j, test.p, test.want) + if got := a[test.i+test.p]; got != test.want { + t.Errorf("#%d a[%d:%d][%d] = %d, wanted %d", i, test.i, test.j, test.p, got, test.want) } } } -func testSlicePanic1() { +func testSlicePanic1(t *testing.T) { defer func() { if r := recover(); r != nil { - println("panicked as expected") + //println("panicked as expected") } }() a := [10]int{0, 10, 20, 30, 40, 50, 60, 70, 80, 90} testSliceLenCap12_ssa(a, 3, 12) - println("expected to panic, but didn't") - failed = true + t.Errorf("expected to panic, but didn't") } -func testSlicePanic2() { +func testSlicePanic2(t *testing.T) { defer func() { if r := recover(); r != nil { - println("panicked as expected") + //println("panicked as expected") } }() a := [10]int{0, 10, 20, 30, 40, 50, 60, 70, 80, 90} testSliceGetElement_ssa(a, 3, 7, 4) - println("expected to panic, but didn't") - failed = true + t.Errorf("expected to panic, but didn't") } -func main() { - testSliceLenCap() - testSliceGetElement() - testSliceSetElement() - testSlicePanic1() - testSlicePanic2() - - if failed { - panic("failed") - } +func TestArray(t *testing.T) { + testSliceLenCap(t) + testSliceGetElement(t) + testSliceSetElement(t) + testSlicePanic1(t) + testSlicePanic2(t) } diff --git a/src/cmd/compile/internal/gc/testdata/closure.go b/src/cmd/compile/internal/gc/testdata/closure_test.go similarity index 60% rename from src/cmd/compile/internal/gc/testdata/closure.go rename to src/cmd/compile/internal/gc/testdata/closure_test.go index 70181bc24bfc8..6cddc2d16728b 100644 --- a/src/cmd/compile/internal/gc/testdata/closure.go +++ b/src/cmd/compile/internal/gc/testdata/closure_test.go @@ -2,12 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// map_ssa.go tests map operations. +// closure.go tests closure operations. package main -import "fmt" - -var failed = false +import "testing" //go:noinline func testCFunc_ssa() int { @@ -22,17 +20,13 @@ func testCFunc_ssa() int { return a } -func testCFunc() { +func testCFunc(t *testing.T) { if want, got := 2, testCFunc_ssa(); got != want { - fmt.Printf("expected %d, got %d", want, got) - failed = true + t.Errorf("expected %d, got %d", want, got) } } -func main() { - testCFunc() - - if failed { - panic("failed") - } +// TestClosure tests closure related behavior. +func TestClosure(t *testing.T) { + testCFunc(t) } diff --git a/src/cmd/compile/internal/gc/testdata/dupLoad.go b/src/cmd/compile/internal/gc/testdata/dupLoad_test.go similarity index 84% rename from src/cmd/compile/internal/gc/testdata/dupLoad.go rename to src/cmd/compile/internal/gc/testdata/dupLoad_test.go index d18dc733e1bca..9d65f54946d25 100644 --- a/src/cmd/compile/internal/gc/testdata/dupLoad.go +++ b/src/cmd/compile/internal/gc/testdata/dupLoad_test.go @@ -1,5 +1,3 @@ -// run - // Copyright 2016 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. @@ -9,7 +7,7 @@ package main -import "fmt" +import "testing" //go:noinline func read1(b []byte) (uint16, uint16) { @@ -19,9 +17,8 @@ func read1(b []byte) (uint16, uint16) { return uint16(v), uint16(v) | uint16(b[1])<<8 } -const N = 100000 - -func main1() { +func main1(t *testing.T) { + const N = 100000 done := make(chan struct{}) b := make([]byte, 2) go func() { @@ -35,8 +32,7 @@ func main1() { for i := 0; i < N; i++ { x, y := read1(b) if byte(x) != byte(y) { - fmt.Printf("x=%x y=%x\n", x, y) - panic("bad") + t.Fatalf("x=%x y=%x\n", x, y) } } done <- struct{}{} @@ -53,7 +49,8 @@ func read2(b []byte) (uint16, uint16) { return v, uint16(b[0]) | v } -func main2() { +func main2(t *testing.T) { + const N = 100000 done := make(chan struct{}) b := make([]byte, 2) go func() { @@ -67,8 +64,7 @@ func main2() { for i := 0; i < N; i++ { x, y := read2(b) if x&0xff00 != y&0xff00 { - fmt.Printf("x=%x y=%x\n", x, y) - panic("bad") + t.Fatalf("x=%x y=%x\n", x, y) } } done <- struct{}{} @@ -77,7 +73,7 @@ func main2() { <-done } -func main() { - main1() - main2() +func TestDupLoad(t *testing.T) { + main1(t) + main2(t) } diff --git a/src/cmd/compile/internal/gc/testdata/namedReturn.go b/src/cmd/compile/internal/gc/testdata/namedReturn_test.go similarity index 69% rename from src/cmd/compile/internal/gc/testdata/namedReturn.go rename to src/cmd/compile/internal/gc/testdata/namedReturn_test.go index 19ef8a7e43af8..b07e225c1ca65 100644 --- a/src/cmd/compile/internal/gc/testdata/namedReturn.go +++ b/src/cmd/compile/internal/gc/testdata/namedReturn_test.go @@ -1,5 +1,3 @@ -// run - // Copyright 2016 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. @@ -11,8 +9,8 @@ package main import ( - "fmt" "runtime" + "testing" ) // Our heap-allocated object that will be GC'd incorrectly. @@ -21,44 +19,44 @@ import ( type B [4]int // small (SSAable) array -type T1 [3]*B +type A1 [3]*B //go:noinline -func f1() (t T1) { +func f1() (t A1) { t[0] = &B{91, 92, 93, 94} runtime.GC() return t } // large (non-SSAable) array -type T2 [8]*B +type A2 [8]*B //go:noinline -func f2() (t T2) { +func f2() (t A2) { t[0] = &B{91, 92, 93, 94} runtime.GC() return t } // small (SSAable) struct -type T3 struct { +type A3 struct { a, b, c *B } //go:noinline -func f3() (t T3) { +func f3() (t A3) { t.a = &B{91, 92, 93, 94} runtime.GC() return t } // large (non-SSAable) struct -type T4 struct { +type A4 struct { a, b, c, d, e, f *B } //go:noinline -func f4() (t T4) { +func f4() (t A4) { t.a = &B{91, 92, 93, 94} runtime.GC() return t @@ -68,7 +66,7 @@ var sink *B func f5() int { b := &B{91, 92, 93, 94} - t := T4{b, nil, nil, nil, nil, nil} + t := A4{b, nil, nil, nil, nil, nil} sink = b // make sure b is heap allocated ... sink = nil // ... but not live runtime.GC() @@ -76,30 +74,20 @@ func f5() int { return t.a[1] } -func main() { - failed := false - +func TestNamedReturn(t *testing.T) { if v := f1()[0][1]; v != 92 { - fmt.Printf("f1()[0][1]=%d, want 92\n", v) - failed = true + t.Errorf("f1()[0][1]=%d, want 92\n", v) } if v := f2()[0][1]; v != 92 { - fmt.Printf("f2()[0][1]=%d, want 92\n", v) - failed = true + t.Errorf("f2()[0][1]=%d, want 92\n", v) } if v := f3().a[1]; v != 92 { - fmt.Printf("f3().a[1]=%d, want 92\n", v) - failed = true + t.Errorf("f3().a[1]=%d, want 92\n", v) } if v := f4().a[1]; v != 92 { - fmt.Printf("f4().a[1]=%d, want 92\n", v) - failed = true + t.Errorf("f4().a[1]=%d, want 92\n", v) } if v := f5(); v != 92 { - fmt.Printf("f5()=%d, want 92\n", v) - failed = true - } - if failed { - panic("bad") + t.Errorf("f5()=%d, want 92\n", v) } } diff --git a/src/cmd/compile/internal/gc/testdata/phi.go b/src/cmd/compile/internal/gc/testdata/phi_test.go similarity index 94% rename from src/cmd/compile/internal/gc/testdata/phi.go rename to src/cmd/compile/internal/gc/testdata/phi_test.go index 6469bfea4479d..c8a73ffd74689 100644 --- a/src/cmd/compile/internal/gc/testdata/phi.go +++ b/src/cmd/compile/internal/gc/testdata/phi_test.go @@ -9,13 +9,10 @@ package main // of the post-shortened size. import ( - "fmt" "runtime" + "testing" ) -// unfoldable true -var true_ = true - var data1 [26]int32 var data2 [26]int64 @@ -29,7 +26,7 @@ func init() { func foo() int32 { var a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z int32 - if true_ { + if always { a = data1[0] b = data1[1] c = data1[2] @@ -93,11 +90,10 @@ func foo() int32 { return a + b + c + d + e + f + g + h + i + j + k + l + m + n + o + p + q + r + s + t + u + v + w + x + y + z } -func main() { +func TestPhi(t *testing.T) { want := int32(0) got := foo() if got != want { - fmt.Printf("want %d, got %d\n", want, got) - panic("bad") + t.Fatalf("want %d, got %d\n", want, got) } } diff --git a/src/cmd/compile/internal/gc/testdata/slice.go b/src/cmd/compile/internal/gc/testdata/slice.go deleted file mode 100644 index a02e4a442a6e1..0000000000000 --- a/src/cmd/compile/internal/gc/testdata/slice.go +++ /dev/null @@ -1,50 +0,0 @@ -// run - -// This test makes sure that t.s = t.s[0:x] doesn't write -// either the slice pointer or the capacity. -// See issue #14855. - -package main - -import "fmt" - -const N = 1000000 - -type T struct { - s []int -} - -func main() { - done := make(chan struct{}) - a := make([]int, N+10) - - t := &T{a} - - go func() { - for i := 0; i < N; i++ { - t.s = t.s[1:9] - } - done <- struct{}{} - }() - go func() { - for i := 0; i < N; i++ { - t.s = t.s[0:8] // should only write len - } - done <- struct{}{} - }() - <-done - <-done - - ok := true - if cap(t.s) != cap(a)-N { - fmt.Printf("wanted cap=%d, got %d\n", cap(a)-N, cap(t.s)) - ok = false - } - if &t.s[0] != &a[N] { - fmt.Printf("wanted ptr=%p, got %p\n", &a[N], &t.s[0]) - ok = false - } - if !ok { - panic("bad") - } -} diff --git a/src/cmd/compile/internal/gc/testdata/slice_test.go b/src/cmd/compile/internal/gc/testdata/slice_test.go new file mode 100644 index 0000000000000..c1345780347a1 --- /dev/null +++ b/src/cmd/compile/internal/gc/testdata/slice_test.go @@ -0,0 +1,46 @@ +// Copyright 2018 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. + +// This test makes sure that t.s = t.s[0:x] doesn't write +// either the slice pointer or the capacity. +// See issue #14855. + +package main + +import "testing" + +const N = 1000000 + +type X struct { + s []int +} + +func TestSlice(t *testing.T) { + done := make(chan struct{}) + a := make([]int, N+10) + + x := &X{a} + + go func() { + for i := 0; i < N; i++ { + x.s = x.s[1:9] + } + done <- struct{}{} + }() + go func() { + for i := 0; i < N; i++ { + x.s = x.s[0:8] // should only write len + } + done <- struct{}{} + }() + <-done + <-done + + if cap(x.s) != cap(a)-N { + t.Errorf("wanted cap=%d, got %d\n", cap(a)-N, cap(x.s)) + } + if &x.s[0] != &a[N] { + t.Errorf("wanted ptr=%p, got %p\n", &a[N], &x.s[0]) + } +} diff --git a/src/cmd/compile/internal/gc/testdata/sqrt_const.go b/src/cmd/compile/internal/gc/testdata/sqrtConst_test.go similarity index 73% rename from src/cmd/compile/internal/gc/testdata/sqrt_const.go rename to src/cmd/compile/internal/gc/testdata/sqrtConst_test.go index 1f25d9aded158..5b7a149e42c40 100644 --- a/src/cmd/compile/internal/gc/testdata/sqrt_const.go +++ b/src/cmd/compile/internal/gc/testdata/sqrtConst_test.go @@ -5,8 +5,8 @@ package main import ( - "fmt" "math" + "testing" ) var tests = [...]struct { @@ -33,27 +33,18 @@ var nanTests = [...]struct { {"sqrtNegInf", math.Inf(-1), math.Sqrt(math.Inf(-1))}, } -var failed = false - -func main() { +func TestSqrtConst(t *testing.T) { for _, test := range tests { if test.got != test.want { - fmt.Printf("%s: math.Sqrt(%f): got %f, want %f\n", test.name, test.in, test.got, test.want) - failed = true + t.Errorf("%s: math.Sqrt(%f): got %f, want %f\n", test.name, test.in, test.got, test.want) } } for _, test := range nanTests { if math.IsNaN(test.got) != true { - fmt.Printf("%s: math.Sqrt(%f): got %f, want NaN\n", test.name, test.in, test.got) - failed = true + t.Errorf("%s: math.Sqrt(%f): got %f, want NaN\n", test.name, test.in, test.got) } } if got := math.Sqrt(math.Inf(1)); !math.IsInf(got, 1) { - fmt.Printf("math.Sqrt(+Inf), got %f, want +Inf\n", got) - failed = true - } - - if failed { - panic("failed") + t.Errorf("math.Sqrt(+Inf), got %f, want +Inf\n", got) } } diff --git a/src/cmd/compile/internal/gc/testdata/unsafe.go b/src/cmd/compile/internal/gc/testdata/unsafe_test.go similarity index 88% rename from src/cmd/compile/internal/gc/testdata/unsafe.go rename to src/cmd/compile/internal/gc/testdata/unsafe_test.go index a3d9dbcc39b64..37599d3fd4ad2 100644 --- a/src/cmd/compile/internal/gc/testdata/unsafe.go +++ b/src/cmd/compile/internal/gc/testdata/unsafe_test.go @@ -5,8 +5,8 @@ package main import ( - "fmt" "runtime" + "testing" "unsafe" ) @@ -14,7 +14,7 @@ import ( var a *[8]uint // unfoldable true -var b = true +var always = true // Test to make sure that a pointer value which is alive // across a call is retained, even when there are matching @@ -25,7 +25,7 @@ var b = true func f_ssa() *[8]uint { // Make x a uintptr pointing to where a points. var x uintptr - if b { + if always { x = uintptr(unsafe.Pointer(a)) } else { x = 0 @@ -48,7 +48,7 @@ func f_ssa() *[8]uint { // to unsafe.Pointer can't be combined with the // uintptr cast above. var z uintptr - if b { + if always { z = y } else { z = 0 @@ -61,7 +61,7 @@ func f_ssa() *[8]uint { func g_ssa() *[7]uint { // Make x a uintptr pointing to where a points. var x uintptr - if b { + if always { x = uintptr(unsafe.Pointer(a)) } else { x = 0 @@ -87,7 +87,7 @@ func g_ssa() *[7]uint { // to unsafe.Pointer can't be combined with the // uintptr cast above. var z uintptr - if b { + if always { z = y } else { z = 0 @@ -95,7 +95,7 @@ func g_ssa() *[7]uint { return (*[7]uint)(unsafe.Pointer(z)) } -func testf() { +func testf(t *testing.T) { a = new([8]uint) for i := 0; i < 8; i++ { a[i] = 0xabcd @@ -103,13 +103,12 @@ func testf() { c := f_ssa() for i := 0; i < 8; i++ { if c[i] != 0xabcd { - fmt.Printf("%d:%x\n", i, c[i]) - panic("bad c") + t.Fatalf("%d:%x\n", i, c[i]) } } } -func testg() { +func testg(t *testing.T) { a = new([8]uint) for i := 0; i < 8; i++ { a[i] = 0xabcd @@ -117,8 +116,7 @@ func testg() { c := g_ssa() for i := 0; i < 7; i++ { if c[i] != 0xabcd { - fmt.Printf("%d:%x\n", i, c[i]) - panic("bad c") + t.Fatalf("%d:%x\n", i, c[i]) } } } @@ -130,19 +128,18 @@ func alias_ssa(ui64 *uint64, ui32 *uint32) uint32 { *ui64 = 0xffffffffffffffff // store return ret } -func testdse() { +func testdse(t *testing.T) { x := int64(-1) // construct two pointers that alias one another ui64 := (*uint64)(unsafe.Pointer(&x)) ui32 := (*uint32)(unsafe.Pointer(&x)) if want, got := uint32(0), alias_ssa(ui64, ui32); got != want { - fmt.Printf("alias_ssa: wanted %d, got %d\n", want, got) - panic("alias_ssa") + t.Fatalf("alias_ssa: wanted %d, got %d\n", want, got) } } -func main() { - testf() - testg() - testdse() +func TestUnsafe(t *testing.T) { + testf(t) + testg(t) + testdse(t) } From 707fd452e68b8cac4ddc68daf394889c4fd67e24 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 31 Jul 2018 16:06:09 -0700 Subject: [PATCH 0193/1663] cmd/compile: enable two orphaned tests These tests weren't being run. Re-enable them. R=go1.12 Change-Id: I8d3cd09b7f07e4c39f855ddb9be000718ec86494 Reviewed-on: https://go-review.googlesource.com/127117 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- .../gc/testdata/{cmp.go => cmp_test.go} | 27 +++------ .../compile/internal/gc/testdata/divbyzero.go | 58 ------------------- .../internal/gc/testdata/divbyzero_test.go | 48 +++++++++++++++ 3 files changed, 56 insertions(+), 77 deletions(-) rename src/cmd/compile/internal/gc/testdata/{cmp.go => cmp_test.go} (58%) delete mode 100644 src/cmd/compile/internal/gc/testdata/divbyzero.go create mode 100644 src/cmd/compile/internal/gc/testdata/divbyzero_test.go diff --git a/src/cmd/compile/internal/gc/testdata/cmp.go b/src/cmd/compile/internal/gc/testdata/cmp_test.go similarity index 58% rename from src/cmd/compile/internal/gc/testdata/cmp.go rename to src/cmd/compile/internal/gc/testdata/cmp_test.go index ba420f2e4e76f..06b58f2a02620 100644 --- a/src/cmd/compile/internal/gc/testdata/cmp.go +++ b/src/cmd/compile/internal/gc/testdata/cmp_test.go @@ -5,9 +5,7 @@ // cmp_ssa.go tests compare simplification operations. package main -import "fmt" - -var failed = false +import "testing" //go:noinline func eq_ssa(a int64) bool { @@ -19,30 +17,21 @@ func neq_ssa(a int64) bool { return 10 != a+4 } -func testCmp() { +func testCmp(t *testing.T) { if wanted, got := true, eq_ssa(6); wanted != got { - fmt.Printf("eq_ssa: expected %v, got %v\n", wanted, got) - failed = true + t.Errorf("eq_ssa: expected %v, got %v\n", wanted, got) } if wanted, got := false, eq_ssa(7); wanted != got { - fmt.Printf("eq_ssa: expected %v, got %v\n", wanted, got) - failed = true + t.Errorf("eq_ssa: expected %v, got %v\n", wanted, got) } - if wanted, got := false, neq_ssa(6); wanted != got { - fmt.Printf("neq_ssa: expected %v, got %v\n", wanted, got) - failed = true + t.Errorf("neq_ssa: expected %v, got %v\n", wanted, got) } if wanted, got := true, neq_ssa(7); wanted != got { - fmt.Printf("neq_ssa: expected %v, got %v\n", wanted, got) - failed = true + t.Errorf("neq_ssa: expected %v, got %v\n", wanted, got) } } -func main() { - testCmp() - - if failed { - panic("failed") - } +func TestCmp(t *testing.T) { + testCmp(t) } diff --git a/src/cmd/compile/internal/gc/testdata/divbyzero.go b/src/cmd/compile/internal/gc/testdata/divbyzero.go deleted file mode 100644 index 2165a1912db0a..0000000000000 --- a/src/cmd/compile/internal/gc/testdata/divbyzero.go +++ /dev/null @@ -1,58 +0,0 @@ -package main - -import ( - "fmt" - "runtime" -) - -var failed = false - -func checkDivByZero(f func()) (divByZero bool) { - defer func() { - if r := recover(); r != nil { - if e, ok := r.(runtime.Error); ok && e.Error() == "runtime error: integer divide by zero" { - divByZero = true - } - } - }() - f() - return false -} - -//go:noinline -func a(i uint, s []int) int { - return s[i%uint(len(s))] -} - -//go:noinline -func b(i uint, j uint) uint { - return i / j -} - -//go:noinline -func c(i int) int { - return 7 / (i - i) -} - -func main() { - if got := checkDivByZero(func() { b(7, 0) }); !got { - fmt.Printf("expected div by zero for b(7, 0), got no error\n") - failed = true - } - if got := checkDivByZero(func() { b(7, 7) }); got { - fmt.Printf("expected no error for b(7, 7), got div by zero\n") - failed = true - } - if got := checkDivByZero(func() { a(4, nil) }); !got { - fmt.Printf("expected div by zero for a(4, nil), got no error\n") - failed = true - } - if got := checkDivByZero(func() { c(5) }); !got { - fmt.Printf("expected div by zero for c(5), got no error\n") - failed = true - } - - if failed { - panic("tests failed") - } -} diff --git a/src/cmd/compile/internal/gc/testdata/divbyzero_test.go b/src/cmd/compile/internal/gc/testdata/divbyzero_test.go new file mode 100644 index 0000000000000..ee848b3cc09ee --- /dev/null +++ b/src/cmd/compile/internal/gc/testdata/divbyzero_test.go @@ -0,0 +1,48 @@ +package main + +import ( + "runtime" + "testing" +) + +func checkDivByZero(f func()) (divByZero bool) { + defer func() { + if r := recover(); r != nil { + if e, ok := r.(runtime.Error); ok && e.Error() == "runtime error: integer divide by zero" { + divByZero = true + } + } + }() + f() + return false +} + +//go:noinline +func div_a(i uint, s []int) int { + return s[i%uint(len(s))] +} + +//go:noinline +func div_b(i uint, j uint) uint { + return i / j +} + +//go:noinline +func div_c(i int) int { + return 7 / (i - i) +} + +func TestDivByZero(t *testing.T) { + if got := checkDivByZero(func() { div_b(7, 0) }); !got { + t.Errorf("expected div by zero for b(7, 0), got no error\n") + } + if got := checkDivByZero(func() { div_b(7, 7) }); got { + t.Errorf("expected no error for b(7, 7), got div by zero\n") + } + if got := checkDivByZero(func() { div_a(4, nil) }); !got { + t.Errorf("expected div by zero for a(4, nil), got no error\n") + } + if got := checkDivByZero(func() { div_c(5) }); !got { + t.Errorf("expected div by zero for c(5), got no error\n") + } +} From 4a4e3b0bc7e74aa45ac29bf1446e9af69ec13dcd Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 6 Aug 2018 10:42:28 -0700 Subject: [PATCH 0194/1663] cmd/compile: remove vet-blocking hack ...and add the vet failures to the vet whitelist. Change-Id: Idcf4289f39dda561c85f3b0afe396e5299e6495f Reviewed-on: https://go-review.googlesource.com/127995 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/testdata/novet.go | 9 --------- src/cmd/vet/all/whitelist/all.txt | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 9 deletions(-) delete mode 100644 src/cmd/compile/internal/gc/testdata/novet.go diff --git a/src/cmd/compile/internal/gc/testdata/novet.go b/src/cmd/compile/internal/gc/testdata/novet.go deleted file mode 100644 index 0fcbba290c462..0000000000000 --- a/src/cmd/compile/internal/gc/testdata/novet.go +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2018 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. - -// This file exists just to convince vet not to check this directory. -// (vet will not check a directory with two different packages in it.) -// TODO: remove this hack & add failing tests to the whitelist. - -package foo diff --git a/src/cmd/vet/all/whitelist/all.txt b/src/cmd/vet/all/whitelist/all.txt index 397ee4e9875bc..b974d21c6ae23 100644 --- a/src/cmd/vet/all/whitelist/all.txt +++ b/src/cmd/vet/all/whitelist/all.txt @@ -28,6 +28,25 @@ encoding/json/tagkey_test.go: struct field tag `:"BadFormat"` not compatible wit runtime/testdata/testprog/deadlock.go: unreachable code runtime/testdata/testprog/deadlock.go: unreachable code +// Compiler tests that make sure even vet-failing code adheres to the spec. +cmd/compile/internal/gc/testdata/arithConst_test.go: a (64 bits) too small for shift of 4294967296 +cmd/compile/internal/gc/testdata/arithConst_test.go: a (64 bits) too small for shift of 4294967296 +cmd/compile/internal/gc/testdata/arithConst_test.go: a (32 bits) too small for shift of 4294967295 +cmd/compile/internal/gc/testdata/arithConst_test.go: a (32 bits) too small for shift of 4294967295 +cmd/compile/internal/gc/testdata/arithConst_test.go: a (16 bits) too small for shift of 65535 +cmd/compile/internal/gc/testdata/arithConst_test.go: a (16 bits) too small for shift of 65535 +cmd/compile/internal/gc/testdata/arithConst_test.go: a (8 bits) too small for shift of 255 +cmd/compile/internal/gc/testdata/arithConst_test.go: a (8 bits) too small for shift of 255 +cmd/compile/internal/gc/testdata/arith_test.go: x (64 bits) too small for shift of 100 +cmd/compile/internal/gc/testdata/arith_test.go: int32(x) (32 bits) too small for shift of 4294967295 +cmd/compile/internal/gc/testdata/arith_test.go: int16(x) (16 bits) too small for shift of 65535 +cmd/compile/internal/gc/testdata/arith_test.go: int8(x) (8 bits) too small for shift of 255 +cmd/compile/internal/gc/testdata/arith_test.go: w (32 bits) too small for shift of 32 +cmd/compile/internal/gc/testdata/break_test.go: unreachable code +cmd/compile/internal/gc/testdata/break_test.go: unreachable code +cmd/compile/internal/gc/testdata/namedReturn_test.go: self-assignment of t to t +cmd/compile/internal/gc/testdata/short_test.go: unreachable code + // Non-standard method signatures. // These cases are basically ok. // Errors are handled reasonably and there's no clear need for interface satisfaction. From aacc891df29f742a6a128069256436fa369696c2 Mon Sep 17 00:00:00 2001 From: Shenghou Ma Date: Fri, 24 Aug 2018 18:44:17 -0400 Subject: [PATCH 0195/1663] doc/go1.11: fix typo Change-Id: I097bd90f62add7838f8c7baf3b777ad167635354 Reviewed-on: https://go-review.googlesource.com/131357 Reviewed-by: Keith Randall --- doc/go1.11.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/go1.11.html b/doc/go1.11.html index 469e111fb8773..afe19397663af 100644 --- a/doc/go1.11.html +++ b/doc/go1.11.html @@ -396,7 +396,7 @@

    Runtime

    - On macOS and iOS, the runtime now uses libSystem.so instead of + On macOS and iOS, the runtime now uses libSystem.dylib instead of calling the kernel directly. This should make Go binaries more compatible with future versions of macOS and iOS. The syscall package still makes direct From 3bc34385faacbcbefb2b4abc0e280b709aab03c9 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Fri, 29 Jun 2018 02:11:53 +0000 Subject: [PATCH 0196/1663] cmd/compile: introduce more read-modify-write operations for amd64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add suport of read-modify-write for AND/SUB/AND/OR/XOR on amd64. 1. The total size of pkg/linux_amd64 decreases about 4KB, excluding cmd/compile. 2. The go1 benchmark shows a little improvement, excluding noise. name old time/op new time/op delta BinaryTree17-4 2.63s ± 3% 2.65s ± 4% +1.01% (p=0.037 n=35+35) Fannkuch11-4 2.33s ± 2% 2.39s ± 2% +2.49% (p=0.000 n=35+35) FmtFprintfEmpty-4 45.4ns ± 5% 40.8ns ± 6% -10.09% (p=0.000 n=35+35) FmtFprintfString-4 73.3ns ± 4% 70.9ns ± 3% -3.23% (p=0.000 n=30+35) FmtFprintfInt-4 79.9ns ± 4% 79.5ns ± 3% ~ (p=0.736 n=34+35) FmtFprintfIntInt-4 126ns ± 4% 125ns ± 4% ~ (p=0.083 n=35+35) FmtFprintfPrefixedInt-4 152ns ± 6% 152ns ± 3% ~ (p=0.855 n=34+35) FmtFprintfFloat-4 215ns ± 4% 213ns ± 4% ~ (p=0.066 n=35+35) FmtManyArgs-4 522ns ± 3% 506ns ± 3% -3.15% (p=0.000 n=35+35) GobDecode-4 6.45ms ± 8% 6.51ms ± 7% +0.96% (p=0.026 n=35+35) GobEncode-4 6.10ms ± 6% 6.02ms ± 8% ~ (p=0.160 n=35+35) Gzip-4 228ms ± 3% 221ms ± 3% -2.92% (p=0.000 n=35+35) Gunzip-4 37.5ms ± 4% 37.2ms ± 3% -0.78% (p=0.036 n=35+35) HTTPClientServer-4 58.7µs ± 2% 59.2µs ± 1% +0.80% (p=0.000 n=33+33) JSONEncode-4 12.0ms ± 3% 12.2ms ± 3% +1.84% (p=0.008 n=35+35) JSONDecode-4 57.0ms ± 4% 56.6ms ± 3% ~ (p=0.320 n=35+35) Mandelbrot200-4 3.82ms ± 3% 3.79ms ± 3% ~ (p=0.074 n=35+35) GoParse-4 3.21ms ± 5% 3.24ms ± 4% ~ (p=0.119 n=35+35) RegexpMatchEasy0_32-4 76.3ns ± 4% 75.4ns ± 4% -1.14% (p=0.014 n=34+33) RegexpMatchEasy0_1K-4 251ns ± 4% 254ns ± 3% +1.28% (p=0.016 n=35+35) RegexpMatchEasy1_32-4 69.6ns ± 3% 70.1ns ± 3% +0.82% (p=0.005 n=35+35) RegexpMatchEasy1_1K-4 367ns ± 4% 376ns ± 4% +2.47% (p=0.000 n=35+35) RegexpMatchMedium_32-4 108ns ± 5% 104ns ± 4% -3.18% (p=0.000 n=35+35) RegexpMatchMedium_1K-4 33.8µs ± 3% 32.7µs ± 3% -3.27% (p=0.000 n=35+35) RegexpMatchHard_32-4 1.55µs ± 3% 1.52µs ± 3% -1.64% (p=0.000 n=35+35) RegexpMatchHard_1K-4 46.6µs ± 3% 46.6µs ± 4% ~ (p=0.149 n=35+35) Revcomp-4 416ms ± 7% 412ms ± 6% -0.95% (p=0.033 n=33+35) Template-4 64.3ms ± 3% 62.4ms ± 7% -2.94% (p=0.000 n=35+35) TimeParse-4 320ns ± 2% 322ns ± 3% ~ (p=0.589 n=35+35) TimeFormat-4 300ns ± 3% 300ns ± 3% ~ (p=0.597 n=35+35) [Geo mean] 47.4µs 47.0µs -0.86% name old speed new speed delta GobDecode-4 119MB/s ± 7% 118MB/s ± 7% -0.96% (p=0.027 n=35+35) GobEncode-4 126MB/s ± 7% 127MB/s ± 6% ~ (p=0.157 n=34+34) Gzip-4 85.3MB/s ± 3% 87.9MB/s ± 3% +3.02% (p=0.000 n=35+35) Gunzip-4 518MB/s ± 4% 522MB/s ± 3% +0.79% (p=0.037 n=35+35) JSONEncode-4 162MB/s ± 3% 159MB/s ± 3% -1.81% (p=0.009 n=35+35) JSONDecode-4 34.1MB/s ± 4% 34.3MB/s ± 3% ~ (p=0.318 n=35+35) GoParse-4 18.0MB/s ± 5% 17.9MB/s ± 4% ~ (p=0.117 n=35+35) RegexpMatchEasy0_32-4 419MB/s ± 3% 425MB/s ± 4% +1.46% (p=0.003 n=32+33) RegexpMatchEasy0_1K-4 4.07GB/s ± 4% 4.02GB/s ± 3% -1.28% (p=0.014 n=35+35) RegexpMatchEasy1_32-4 460MB/s ± 3% 456MB/s ± 4% -0.82% (p=0.004 n=35+35) RegexpMatchEasy1_1K-4 2.79GB/s ± 4% 2.72GB/s ± 4% -2.39% (p=0.000 n=35+35) RegexpMatchMedium_32-4 9.23MB/s ± 4% 9.53MB/s ± 4% +3.16% (p=0.000 n=35+35) RegexpMatchMedium_1K-4 30.3MB/s ± 3% 31.3MB/s ± 3% +3.38% (p=0.000 n=35+35) RegexpMatchHard_32-4 20.7MB/s ± 3% 21.0MB/s ± 3% +1.67% (p=0.000 n=35+35) RegexpMatchHard_1K-4 22.0MB/s ± 3% 21.9MB/s ± 4% ~ (p=0.277 n=35+33) Revcomp-4 612MB/s ± 7% 618MB/s ± 6% +0.96% (p=0.034 n=33+35) Template-4 30.2MB/s ± 3% 31.1MB/s ± 6% +3.05% (p=0.000 n=35+35) [Geo mean] 123MB/s 124MB/s +0.64% Change-Id: Ia025da272e07d0069413824bfff3471b106d6280 Reviewed-on: https://go-review.googlesource.com/121535 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Ilya Tocar Reviewed-by: Keith Randall --- src/cmd/compile/internal/amd64/ssa.go | 4 +- src/cmd/compile/internal/ssa/gen/AMD64.rules | 16 + src/cmd/compile/internal/ssa/gen/AMD64Ops.go | 12 + src/cmd/compile/internal/ssa/opGen.go | 160 ++ src/cmd/compile/internal/ssa/rewriteAMD64.go | 1677 +++++++++++++++++- test/codegen/arithmetic.go | 2 + 6 files changed, 1865 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/amd64/ssa.go b/src/cmd/compile/internal/amd64/ssa.go index 4ecdb769f3a46..ae6141dd12ebd 100644 --- a/src/cmd/compile/internal/amd64/ssa.go +++ b/src/cmd/compile/internal/amd64/ssa.go @@ -699,7 +699,9 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { gc.AddAux(&p.From, v) p.To.Type = obj.TYPE_REG p.To.Reg = v.Reg() - case ssa.OpAMD64MOVQstore, ssa.OpAMD64MOVSSstore, ssa.OpAMD64MOVSDstore, ssa.OpAMD64MOVLstore, ssa.OpAMD64MOVWstore, ssa.OpAMD64MOVBstore, ssa.OpAMD64MOVOstore: + case ssa.OpAMD64MOVQstore, ssa.OpAMD64MOVSSstore, ssa.OpAMD64MOVSDstore, ssa.OpAMD64MOVLstore, ssa.OpAMD64MOVWstore, ssa.OpAMD64MOVBstore, ssa.OpAMD64MOVOstore, + ssa.OpAMD64ADDQmodify, ssa.OpAMD64SUBQmodify, ssa.OpAMD64ANDQmodify, ssa.OpAMD64ORQmodify, ssa.OpAMD64XORQmodify, + ssa.OpAMD64ADDLmodify, ssa.OpAMD64SUBLmodify, ssa.OpAMD64ANDLmodify, ssa.OpAMD64ORLmodify, ssa.OpAMD64XORLmodify: p := s.Prog(v.Op.Asm()) p.From.Type = obj.TYPE_REG p.From.Reg = v.Args[1].Reg() diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index eab66d17abc34..10d917632e0ce 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -1045,6 +1045,10 @@ ((ADD|AND|OR|XOR)Qconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) ((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> ((ADD|AND|OR|XOR)Lconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) +((ADD|SUB|AND|OR|XOR)Qmodify [off1] {sym} (ADDQconst [off2] base) val mem) && is32Bit(off1+off2) -> + ((ADD|SUB|AND|OR|XOR)Qmodify [off1+off2] {sym} base val mem) +((ADD|SUB|AND|OR|XOR)Lmodify [off1] {sym} (ADDQconst [off2] base) val mem) && is32Bit(off1+off2) -> + ((ADD|SUB|AND|OR|XOR)Lmodify [off1+off2] {sym} base val mem) // Fold constants into stores. (MOVQstore [off] {sym} ptr (MOVQconst [c]) mem) && validValAndOff(c,off) -> @@ -1091,6 +1095,12 @@ ((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) && ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) -> ((ADD|AND|OR|XOR)Lconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) +((ADD|SUB|AND|OR|XOR)Qmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> + ((ADD|SUB|AND|OR|XOR)Qmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) +((ADD|SUB|AND|OR|XOR)Lmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> + ((ADD|SUB|AND|OR|XOR)Lmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) // generating indexed loads and stores (MOV(B|W|L|Q|SS|SD)load [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> @@ -2276,6 +2286,12 @@ ((ADD|SUB|AND|OR|XOR)L x l:(MOVLload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|SUB|AND|OR|XOR)Lload x [off] {sym} ptr mem) ((ADD|SUB|MUL|DIV)SD x l:(MOVSDload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|SUB|MUL|DIV)SDload x [off] {sym} ptr mem) ((ADD|SUB|MUL|DIV)SS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|SUB|MUL|DIV)SSload x [off] {sym} ptr mem) +(MOVLstore {sym} [off] ptr y:((ADD|AND|OR|XOR)Lload x [off] {sym} ptr mem) mem) && y.Uses==1 && clobber(y) -> ((ADD|AND|OR|XOR)Lmodify [off] {sym} ptr x mem) +(MOVLstore {sym} [off] ptr y:((ADD|SUB|AND|OR|XOR)L l:(MOVLload [off] {sym} ptr mem) x) mem) && y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) -> + ((ADD|SUB|AND|OR|XOR)Lmodify [off] {sym} ptr x mem) +(MOVQstore {sym} [off] ptr y:((ADD|AND|OR|XOR)Qload x [off] {sym} ptr mem) mem) && y.Uses==1 && clobber(y) -> ((ADD|AND|OR|XOR)Qmodify [off] {sym} ptr x mem) +(MOVQstore {sym} [off] ptr y:((ADD|SUB|AND|OR|XOR)Q l:(MOVQload [off] {sym} ptr mem) x) mem) && y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) -> + ((ADD|SUB|AND|OR|XOR)Qmodify [off] {sym} ptr x mem) // Merge ADDQconst and LEAQ into atomic loads. (MOVQatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> diff --git a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go index 4735ea1bc08f4..512df99694c9b 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go @@ -346,6 +346,18 @@ func init() { {name: "XORQload", argLength: 3, reg: gp21load, asm: "XORQ", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 ^ tmp, tmp loaded from arg1+auxint+aux, arg2 = mem {name: "XORLload", argLength: 3, reg: gp21load, asm: "XORL", aux: "SymOff", resultInArg0: true, clobberFlags: true, faultOnNilArg1: true, symEffect: "Read"}, // arg0 ^ tmp, tmp loaded from arg1+auxint+aux, arg2 = mem + // direct binary-op on memory (read-modify-write) + {name: "ADDQmodify", argLength: 3, reg: gpstore, asm: "ADDQ", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) += arg1, arg2=mem + {name: "SUBQmodify", argLength: 3, reg: gpstore, asm: "SUBQ", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) -= arg1, arg2=mem + {name: "ANDQmodify", argLength: 3, reg: gpstore, asm: "ANDQ", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) &= arg1, arg2=mem + {name: "ORQmodify", argLength: 3, reg: gpstore, asm: "ORQ", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) |= arg1, arg2=mem + {name: "XORQmodify", argLength: 3, reg: gpstore, asm: "XORQ", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) ^= arg1, arg2=mem + {name: "ADDLmodify", argLength: 3, reg: gpstore, asm: "ADDL", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) += arg1, arg2=mem + {name: "SUBLmodify", argLength: 3, reg: gpstore, asm: "SUBL", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) -= arg1, arg2=mem + {name: "ANDLmodify", argLength: 3, reg: gpstore, asm: "ANDL", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) &= arg1, arg2=mem + {name: "ORLmodify", argLength: 3, reg: gpstore, asm: "ORL", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) |= arg1, arg2=mem + {name: "XORLmodify", argLength: 3, reg: gpstore, asm: "XORL", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // *(arg0+auxint+aux) ^= arg1, arg2=mem + // unary ops {name: "NEGQ", argLength: 1, reg: gp11, asm: "NEGQ", resultInArg0: true, clobberFlags: true}, // -arg0 {name: "NEGL", argLength: 1, reg: gp11, asm: "NEGL", resultInArg0: true, clobberFlags: true}, // -arg0 diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 704792c9af554..374949c60231b 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -600,6 +600,16 @@ const ( OpAMD64ORLload OpAMD64XORQload OpAMD64XORLload + OpAMD64ADDQmodify + OpAMD64SUBQmodify + OpAMD64ANDQmodify + OpAMD64ORQmodify + OpAMD64XORQmodify + OpAMD64ADDLmodify + OpAMD64SUBLmodify + OpAMD64ANDLmodify + OpAMD64ORLmodify + OpAMD64XORLmodify OpAMD64NEGQ OpAMD64NEGL OpAMD64NOTQ @@ -7661,6 +7671,156 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "ADDQmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AADDQ, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "SUBQmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ASUBQ, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "ANDQmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AANDQ, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "ORQmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AORQ, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "XORQmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AXORQ, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "ADDLmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AADDL, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "SUBLmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ASUBL, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "ANDLmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AANDL, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "ORLmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AORL, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "XORLmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.AXORL, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, { name: "NEGQ", argLen: 1, diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 245f795d90059..e592610c26577 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -23,6 +23,8 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64ADDLconstmodify_0(v) case OpAMD64ADDLload: return rewriteValueAMD64_OpAMD64ADDLload_0(v) + case OpAMD64ADDLmodify: + return rewriteValueAMD64_OpAMD64ADDLmodify_0(v) case OpAMD64ADDQ: return rewriteValueAMD64_OpAMD64ADDQ_0(v) || rewriteValueAMD64_OpAMD64ADDQ_10(v) || rewriteValueAMD64_OpAMD64ADDQ_20(v) case OpAMD64ADDQconst: @@ -31,6 +33,8 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64ADDQconstmodify_0(v) case OpAMD64ADDQload: return rewriteValueAMD64_OpAMD64ADDQload_0(v) + case OpAMD64ADDQmodify: + return rewriteValueAMD64_OpAMD64ADDQmodify_0(v) case OpAMD64ADDSD: return rewriteValueAMD64_OpAMD64ADDSD_0(v) case OpAMD64ADDSDload: @@ -47,6 +51,8 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64ANDLconstmodify_0(v) case OpAMD64ANDLload: return rewriteValueAMD64_OpAMD64ANDLload_0(v) + case OpAMD64ANDLmodify: + return rewriteValueAMD64_OpAMD64ANDLmodify_0(v) case OpAMD64ANDQ: return rewriteValueAMD64_OpAMD64ANDQ_0(v) case OpAMD64ANDQconst: @@ -55,6 +61,8 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64ANDQconstmodify_0(v) case OpAMD64ANDQload: return rewriteValueAMD64_OpAMD64ANDQload_0(v) + case OpAMD64ANDQmodify: + return rewriteValueAMD64_OpAMD64ANDQmodify_0(v) case OpAMD64BSFQ: return rewriteValueAMD64_OpAMD64BSFQ_0(v) case OpAMD64BTLconst: @@ -224,7 +232,7 @@ func rewriteValueAMD64(v *Value) bool { case OpAMD64MOVLloadidx8: return rewriteValueAMD64_OpAMD64MOVLloadidx8_0(v) case OpAMD64MOVLstore: - return rewriteValueAMD64_OpAMD64MOVLstore_0(v) || rewriteValueAMD64_OpAMD64MOVLstore_10(v) + return rewriteValueAMD64_OpAMD64MOVLstore_0(v) || rewriteValueAMD64_OpAMD64MOVLstore_10(v) || rewriteValueAMD64_OpAMD64MOVLstore_20(v) || rewriteValueAMD64_OpAMD64MOVLstore_30(v) case OpAMD64MOVLstoreconst: return rewriteValueAMD64_OpAMD64MOVLstoreconst_0(v) case OpAMD64MOVLstoreconstidx1: @@ -254,7 +262,7 @@ func rewriteValueAMD64(v *Value) bool { case OpAMD64MOVQloadidx8: return rewriteValueAMD64_OpAMD64MOVQloadidx8_0(v) case OpAMD64MOVQstore: - return rewriteValueAMD64_OpAMD64MOVQstore_0(v) || rewriteValueAMD64_OpAMD64MOVQstore_10(v) + return rewriteValueAMD64_OpAMD64MOVQstore_0(v) || rewriteValueAMD64_OpAMD64MOVQstore_10(v) || rewriteValueAMD64_OpAMD64MOVQstore_20(v) case OpAMD64MOVQstoreconst: return rewriteValueAMD64_OpAMD64MOVQstoreconst_0(v) case OpAMD64MOVQstoreconstidx1: @@ -345,6 +353,8 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64ORLconstmodify_0(v) case OpAMD64ORLload: return rewriteValueAMD64_OpAMD64ORLload_0(v) + case OpAMD64ORLmodify: + return rewriteValueAMD64_OpAMD64ORLmodify_0(v) case OpAMD64ORQ: return rewriteValueAMD64_OpAMD64ORQ_0(v) || rewriteValueAMD64_OpAMD64ORQ_10(v) || rewriteValueAMD64_OpAMD64ORQ_20(v) || rewriteValueAMD64_OpAMD64ORQ_30(v) || rewriteValueAMD64_OpAMD64ORQ_40(v) || rewriteValueAMD64_OpAMD64ORQ_50(v) || rewriteValueAMD64_OpAMD64ORQ_60(v) || rewriteValueAMD64_OpAMD64ORQ_70(v) || rewriteValueAMD64_OpAMD64ORQ_80(v) || rewriteValueAMD64_OpAMD64ORQ_90(v) || rewriteValueAMD64_OpAMD64ORQ_100(v) || rewriteValueAMD64_OpAMD64ORQ_110(v) || rewriteValueAMD64_OpAMD64ORQ_120(v) || rewriteValueAMD64_OpAMD64ORQ_130(v) || rewriteValueAMD64_OpAMD64ORQ_140(v) || rewriteValueAMD64_OpAMD64ORQ_150(v) || rewriteValueAMD64_OpAMD64ORQ_160(v) case OpAMD64ORQconst: @@ -353,6 +363,8 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64ORQconstmodify_0(v) case OpAMD64ORQload: return rewriteValueAMD64_OpAMD64ORQload_0(v) + case OpAMD64ORQmodify: + return rewriteValueAMD64_OpAMD64ORQmodify_0(v) case OpAMD64ROLB: return rewriteValueAMD64_OpAMD64ROLB_0(v) case OpAMD64ROLBconst: @@ -467,12 +479,16 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64SUBLconst_0(v) case OpAMD64SUBLload: return rewriteValueAMD64_OpAMD64SUBLload_0(v) + case OpAMD64SUBLmodify: + return rewriteValueAMD64_OpAMD64SUBLmodify_0(v) case OpAMD64SUBQ: return rewriteValueAMD64_OpAMD64SUBQ_0(v) case OpAMD64SUBQconst: return rewriteValueAMD64_OpAMD64SUBQconst_0(v) case OpAMD64SUBQload: return rewriteValueAMD64_OpAMD64SUBQload_0(v) + case OpAMD64SUBQmodify: + return rewriteValueAMD64_OpAMD64SUBQmodify_0(v) case OpAMD64SUBSD: return rewriteValueAMD64_OpAMD64SUBSD_0(v) case OpAMD64SUBSDload: @@ -513,6 +529,8 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64XORLconstmodify_0(v) case OpAMD64XORLload: return rewriteValueAMD64_OpAMD64XORLload_0(v) + case OpAMD64XORLmodify: + return rewriteValueAMD64_OpAMD64XORLmodify_0(v) case OpAMD64XORQ: return rewriteValueAMD64_OpAMD64XORQ_0(v) || rewriteValueAMD64_OpAMD64XORQ_10(v) case OpAMD64XORQconst: @@ -521,6 +539,8 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64XORQconstmodify_0(v) case OpAMD64XORQload: return rewriteValueAMD64_OpAMD64XORQload_0(v) + case OpAMD64XORQmodify: + return rewriteValueAMD64_OpAMD64XORQmodify_0(v) case OpAdd16: return rewriteValueAMD64_OpAdd16_0(v) case OpAdd32: @@ -2038,6 +2058,62 @@ func rewriteValueAMD64_OpAMD64ADDLload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64ADDLmodify_0(v *Value) bool { + // match: (ADDLmodify [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (ADDLmodify [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64ADDLmodify) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (ADDLmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (ADDLmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64ADDLmodify) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64ADDQ_0(v *Value) bool { // match: (ADDQ x (MOVQconst [c])) // cond: is32Bit(c) @@ -2902,6 +2978,62 @@ func rewriteValueAMD64_OpAMD64ADDQload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64ADDQmodify_0(v *Value) bool { + // match: (ADDQmodify [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (ADDQmodify [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64ADDQmodify) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (ADDQmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (ADDQmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64ADDQmodify) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64ADDSD_0(v *Value) bool { // match: (ADDSD x l:(MOVSDload [off] {sym} ptr mem)) // cond: canMergeLoad(v, l, x) && clobber(l) @@ -3643,6 +3775,62 @@ func rewriteValueAMD64_OpAMD64ANDLload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64ANDLmodify_0(v *Value) bool { + // match: (ANDLmodify [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (ANDLmodify [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64ANDLmodify) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (ANDLmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (ANDLmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64ANDLmodify) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64ANDQ_0(v *Value) bool { b := v.Block _ = b @@ -4108,6 +4296,62 @@ func rewriteValueAMD64_OpAMD64ANDQload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64ANDQmodify_0(v *Value) bool { + // match: (ANDQmodify [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (ANDQmodify [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64ANDQmodify) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (ANDQmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (ANDQmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64ANDQmodify) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64BSFQ_0(v *Value) bool { b := v.Block _ = b @@ -14574,6 +14818,548 @@ func rewriteValueAMD64_OpAMD64MOVLstore_10(v *Value) bool { v.AddArg(mem) return true } + // match: (MOVLstore {sym} [off] ptr y:(ADDLload x [off] {sym} ptr mem) mem) + // cond: y.Uses==1 && clobber(y) + // result: (ADDLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ADDLload { + break + } + if y.AuxInt != off { + break + } + if y.Aux != sym { + break + } + _ = y.Args[2] + x := y.Args[0] + if ptr != y.Args[1] { + break + } + mem := y.Args[2] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && clobber(y)) { + break + } + v.reset(OpAMD64ADDLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(ANDLload x [off] {sym} ptr mem) mem) + // cond: y.Uses==1 && clobber(y) + // result: (ANDLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ANDLload { + break + } + if y.AuxInt != off { + break + } + if y.Aux != sym { + break + } + _ = y.Args[2] + x := y.Args[0] + if ptr != y.Args[1] { + break + } + mem := y.Args[2] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && clobber(y)) { + break + } + v.reset(OpAMD64ANDLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(ORLload x [off] {sym} ptr mem) mem) + // cond: y.Uses==1 && clobber(y) + // result: (ORLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ORLload { + break + } + if y.AuxInt != off { + break + } + if y.Aux != sym { + break + } + _ = y.Args[2] + x := y.Args[0] + if ptr != y.Args[1] { + break + } + mem := y.Args[2] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && clobber(y)) { + break + } + v.reset(OpAMD64ORLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(XORLload x [off] {sym} ptr mem) mem) + // cond: y.Uses==1 && clobber(y) + // result: (XORLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64XORLload { + break + } + if y.AuxInt != off { + break + } + if y.Aux != sym { + break + } + _ = y.Args[2] + x := y.Args[0] + if ptr != y.Args[1] { + break + } + mem := y.Args[2] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && clobber(y)) { + break + } + v.reset(OpAMD64XORLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(ADDL l:(MOVLload [off] {sym} ptr mem) x) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ADDLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ADDL { + break + } + _ = y.Args[1] + l := y.Args[0] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + x := y.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ADDLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(ADDL x l:(MOVLload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ADDLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ADDL { + break + } + _ = y.Args[1] + x := y.Args[0] + l := y.Args[1] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ADDLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueAMD64_OpAMD64MOVLstore_20(v *Value) bool { + // match: (MOVLstore {sym} [off] ptr y:(SUBL l:(MOVLload [off] {sym} ptr mem) x) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (SUBLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64SUBL { + break + } + _ = y.Args[1] + l := y.Args[0] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + x := y.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64SUBLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(ANDL l:(MOVLload [off] {sym} ptr mem) x) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ANDLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ANDL { + break + } + _ = y.Args[1] + l := y.Args[0] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + x := y.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ANDLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(ANDL x l:(MOVLload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ANDLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ANDL { + break + } + _ = y.Args[1] + x := y.Args[0] + l := y.Args[1] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ANDLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(ORL l:(MOVLload [off] {sym} ptr mem) x) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ORLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ORL { + break + } + _ = y.Args[1] + l := y.Args[0] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + x := y.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ORLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(ORL x l:(MOVLload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ORLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ORL { + break + } + _ = y.Args[1] + x := y.Args[0] + l := y.Args[1] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ORLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(XORL l:(MOVLload [off] {sym} ptr mem) x) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (XORLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64XORL { + break + } + _ = y.Args[1] + l := y.Args[0] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + x := y.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64XORLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVLstore {sym} [off] ptr y:(XORL x l:(MOVLload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (XORLmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64XORL { + break + } + _ = y.Args[1] + x := y.Args[0] + l := y.Args[1] + if l.Op != OpAMD64MOVLload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64XORLmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } // match: (MOVLstore [off] {sym} ptr a:(ADDLconst [c] l:(MOVLload [off] {sym} ptr2 mem)) mem) // cond: isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) // result: (ADDLconstmodify {sym} [makeValAndOff(c,off)] ptr mem) @@ -14691,6 +15477,9 @@ func rewriteValueAMD64_OpAMD64MOVLstore_10(v *Value) bool { v.AddArg(mem) return true } + return false +} +func rewriteValueAMD64_OpAMD64MOVLstore_30(v *Value) bool { // match: (MOVLstore [off] {sym} ptr a:(XORLconst [c] l:(MOVLload [off] {sym} ptr2 mem)) mem) // cond: isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) // result: (XORLconstmodify {sym} [makeValAndOff(c,off)] ptr mem) @@ -16677,6 +17466,551 @@ func rewriteValueAMD64_OpAMD64MOVQstore_0(v *Value) bool { v.AddArg(mem) return true } + // match: (MOVQstore {sym} [off] ptr y:(ADDQload x [off] {sym} ptr mem) mem) + // cond: y.Uses==1 && clobber(y) + // result: (ADDQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ADDQload { + break + } + if y.AuxInt != off { + break + } + if y.Aux != sym { + break + } + _ = y.Args[2] + x := y.Args[0] + if ptr != y.Args[1] { + break + } + mem := y.Args[2] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && clobber(y)) { + break + } + v.reset(OpAMD64ADDQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVQstore {sym} [off] ptr y:(ANDQload x [off] {sym} ptr mem) mem) + // cond: y.Uses==1 && clobber(y) + // result: (ANDQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ANDQload { + break + } + if y.AuxInt != off { + break + } + if y.Aux != sym { + break + } + _ = y.Args[2] + x := y.Args[0] + if ptr != y.Args[1] { + break + } + mem := y.Args[2] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && clobber(y)) { + break + } + v.reset(OpAMD64ANDQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueAMD64_OpAMD64MOVQstore_10(v *Value) bool { + // match: (MOVQstore {sym} [off] ptr y:(ORQload x [off] {sym} ptr mem) mem) + // cond: y.Uses==1 && clobber(y) + // result: (ORQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ORQload { + break + } + if y.AuxInt != off { + break + } + if y.Aux != sym { + break + } + _ = y.Args[2] + x := y.Args[0] + if ptr != y.Args[1] { + break + } + mem := y.Args[2] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && clobber(y)) { + break + } + v.reset(OpAMD64ORQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVQstore {sym} [off] ptr y:(XORQload x [off] {sym} ptr mem) mem) + // cond: y.Uses==1 && clobber(y) + // result: (XORQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64XORQload { + break + } + if y.AuxInt != off { + break + } + if y.Aux != sym { + break + } + _ = y.Args[2] + x := y.Args[0] + if ptr != y.Args[1] { + break + } + mem := y.Args[2] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && clobber(y)) { + break + } + v.reset(OpAMD64XORQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVQstore {sym} [off] ptr y:(ADDQ l:(MOVQload [off] {sym} ptr mem) x) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ADDQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ADDQ { + break + } + _ = y.Args[1] + l := y.Args[0] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + x := y.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ADDQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVQstore {sym} [off] ptr y:(ADDQ x l:(MOVQload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ADDQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ADDQ { + break + } + _ = y.Args[1] + x := y.Args[0] + l := y.Args[1] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ADDQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVQstore {sym} [off] ptr y:(SUBQ l:(MOVQload [off] {sym} ptr mem) x) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (SUBQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64SUBQ { + break + } + _ = y.Args[1] + l := y.Args[0] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + x := y.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64SUBQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVQstore {sym} [off] ptr y:(ANDQ l:(MOVQload [off] {sym} ptr mem) x) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ANDQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ANDQ { + break + } + _ = y.Args[1] + l := y.Args[0] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + x := y.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ANDQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVQstore {sym} [off] ptr y:(ANDQ x l:(MOVQload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ANDQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ANDQ { + break + } + _ = y.Args[1] + x := y.Args[0] + l := y.Args[1] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ANDQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVQstore {sym} [off] ptr y:(ORQ l:(MOVQload [off] {sym} ptr mem) x) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ORQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ORQ { + break + } + _ = y.Args[1] + l := y.Args[0] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + x := y.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ORQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVQstore {sym} [off] ptr y:(ORQ x l:(MOVQload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (ORQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64ORQ { + break + } + _ = y.Args[1] + x := y.Args[0] + l := y.Args[1] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64ORQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVQstore {sym} [off] ptr y:(XORQ l:(MOVQload [off] {sym} ptr mem) x) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (XORQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64XORQ { + break + } + _ = y.Args[1] + l := y.Args[0] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + x := y.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64XORQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueAMD64_OpAMD64MOVQstore_20(v *Value) bool { + // match: (MOVQstore {sym} [off] ptr y:(XORQ x l:(MOVQload [off] {sym} ptr mem)) mem) + // cond: y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) + // result: (XORQmodify [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + y := v.Args[1] + if y.Op != OpAMD64XORQ { + break + } + _ = y.Args[1] + x := y.Args[0] + l := y.Args[1] + if l.Op != OpAMD64MOVQload { + break + } + if l.AuxInt != off { + break + } + if l.Aux != sym { + break + } + _ = l.Args[1] + if ptr != l.Args[0] { + break + } + mem := l.Args[1] + if mem != v.Args[2] { + break + } + if !(y.Uses == 1 && l.Uses == 1 && clobber(y) && clobber(l)) { + break + } + v.reset(OpAMD64XORQmodify) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } // match: (MOVQstore [off] {sym} ptr a:(ADDQconst [c] l:(MOVQload [off] {sym} ptr2 mem)) mem) // cond: isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) // result: (ADDQconstmodify {sym} [makeValAndOff(c,off)] ptr mem) @@ -16755,9 +18089,6 @@ func rewriteValueAMD64_OpAMD64MOVQstore_0(v *Value) bool { v.AddArg(mem) return true } - return false -} -func rewriteValueAMD64_OpAMD64MOVQstore_10(v *Value) bool { // match: (MOVQstore [off] {sym} ptr a:(ORQconst [c] l:(MOVQload [off] {sym} ptr2 mem)) mem) // cond: isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) // result: (ORQconstmodify {sym} [makeValAndOff(c,off)] ptr mem) @@ -31479,6 +32810,62 @@ func rewriteValueAMD64_OpAMD64ORLload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64ORLmodify_0(v *Value) bool { + // match: (ORLmodify [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (ORLmodify [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64ORLmodify) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (ORLmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (ORLmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64ORLmodify) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64ORQ_0(v *Value) bool { b := v.Block _ = b @@ -42440,6 +43827,62 @@ func rewriteValueAMD64_OpAMD64ORQload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64ORQmodify_0(v *Value) bool { + // match: (ORQmodify [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (ORQmodify [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64ORQmodify) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (ORQmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (ORQmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64ORQmodify) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64ROLB_0(v *Value) bool { // match: (ROLB x (NEGQ y)) // cond: @@ -51150,6 +52593,62 @@ func rewriteValueAMD64_OpAMD64SUBLload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64SUBLmodify_0(v *Value) bool { + // match: (SUBLmodify [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (SUBLmodify [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64SUBLmodify) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (SUBLmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (SUBLmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64SUBLmodify) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64SUBQ_0(v *Value) bool { b := v.Block _ = b @@ -51388,6 +52887,62 @@ func rewriteValueAMD64_OpAMD64SUBQload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64SUBQmodify_0(v *Value) bool { + // match: (SUBQmodify [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (SUBQmodify [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64SUBQmodify) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (SUBQmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (SUBQmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64SUBQmodify) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64SUBSD_0(v *Value) bool { // match: (SUBSD x l:(MOVSDload [off] {sym} ptr mem)) // cond: canMergeLoad(v, l, x) && clobber(l) @@ -52988,6 +54543,62 @@ func rewriteValueAMD64_OpAMD64XORLload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64XORLmodify_0(v *Value) bool { + // match: (XORLmodify [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (XORLmodify [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64XORLmodify) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (XORLmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (XORLmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64XORLmodify) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64XORQ_0(v *Value) bool { b := v.Block _ = b @@ -53454,6 +55065,62 @@ func rewriteValueAMD64_OpAMD64XORQload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64XORQmodify_0(v *Value) bool { + // match: (XORQmodify [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (XORQmodify [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64XORQmodify) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (XORQmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (XORQmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64XORQmodify) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAdd16_0(v *Value) bool { // match: (Add16 x y) // cond: diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index 32efcaaa3fb7b..09a2fa091e803 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -16,8 +16,10 @@ package codegen func SubMem(arr []int, b int) int { // 386:`SUBL\s[A-Z]+,\s8\([A-Z]+\)` + // amd64:`SUBQ\s[A-Z]+,\s16\([A-Z]+\)` arr[2] -= b // 386:`SUBL\s[A-Z]+,\s12\([A-Z]+\)` + // amd64:`SUBQ\s[A-Z]+,\s24\([A-Z]+\)` arr[3] -= b // 386:`DECL\s16\([A-Z]+\)` arr[4]-- From e03220a594a1a4b7fa8c901eebddb9ea11ecbece Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 23 Aug 2018 02:08:15 +0000 Subject: [PATCH 0197/1663] cmd/compile: optimize 386 code with FLDPI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit FLDPI pushes the constant pi to 387's register stack, which is more efficient than MOVSSconst/MOVSDconst. 1. This optimization reduces 0.3KB of the total size of pkg/linux_386 (exlcuding cmd/compile). 2. There is little regression in the go1 benchmark. name old time/op new time/op delta BinaryTree17-4 3.30s ± 3% 3.30s ± 2% ~ (p=0.759 n=40+39) Fannkuch11-4 3.53s ± 1% 3.54s ± 1% ~ (p=0.168 n=40+40) FmtFprintfEmpty-4 45.5ns ± 3% 45.6ns ± 3% ~ (p=0.553 n=40+40) FmtFprintfString-4 78.4ns ± 3% 78.3ns ± 3% ~ (p=0.593 n=40+40) FmtFprintfInt-4 88.8ns ± 2% 89.9ns ± 2% ~ (p=0.083 n=40+33) FmtFprintfIntInt-4 140ns ± 4% 140ns ± 4% ~ (p=0.656 n=40+40) FmtFprintfPrefixedInt-4 180ns ± 2% 181ns ± 3% +0.53% (p=0.050 n=40+40) FmtFprintfFloat-4 408ns ± 4% 411ns ± 3% ~ (p=0.112 n=40+40) FmtManyArgs-4 599ns ± 3% 602ns ± 3% ~ (p=0.784 n=40+40) GobDecode-4 7.24ms ± 6% 7.30ms ± 5% ~ (p=0.171 n=40+40) GobEncode-4 6.98ms ± 5% 6.89ms ± 8% ~ (p=0.107 n=40+40) Gzip-4 396ms ± 4% 396ms ± 3% ~ (p=0.852 n=40+40) Gunzip-4 41.3ms ± 3% 41.5ms ± 4% ~ (p=0.221 n=40+40) HTTPClientServer-4 63.4µs ± 3% 63.4µs ± 2% ~ (p=0.895 n=39+40) JSONEncode-4 17.5ms ± 2% 17.5ms ± 3% ~ (p=0.090 n=40+40) JSONDecode-4 60.6ms ± 3% 60.1ms ± 4% ~ (p=0.184 n=40+40) Mandelbrot200-4 7.80ms ± 3% 7.78ms ± 2% ~ (p=0.512 n=40+40) GoParse-4 3.30ms ± 3% 3.28ms ± 2% -0.61% (p=0.034 n=40+40) RegexpMatchEasy0_32-4 104ns ± 4% 103ns ± 4% ~ (p=0.118 n=40+40) RegexpMatchEasy0_1K-4 850ns ± 2% 848ns ± 2% ~ (p=0.370 n=40+40) RegexpMatchEasy1_32-4 112ns ± 4% 112ns ± 4% ~ (p=0.848 n=40+40) RegexpMatchEasy1_1K-4 1.04µs ± 4% 1.03µs ± 4% ~ (p=0.333 n=40+40) RegexpMatchMedium_32-4 132ns ± 4% 131ns ± 3% ~ (p=0.527 n=40+40) RegexpMatchMedium_1K-4 43.4µs ± 3% 43.5µs ± 3% ~ (p=0.111 n=40+40) RegexpMatchHard_32-4 2.24µs ± 4% 2.24µs ± 4% ~ (p=0.441 n=40+40) RegexpMatchHard_1K-4 67.9µs ± 3% 68.0µs ± 3% ~ (p=0.095 n=40+40) Revcomp-4 1.84s ± 2% 1.84s ± 2% ~ (p=0.677 n=40+40) Template-4 68.4ms ± 3% 68.6ms ± 3% ~ (p=0.345 n=40+40) TimeParse-4 433ns ± 3% 433ns ± 3% ~ (p=0.403 n=40+40) TimeFormat-4 407ns ± 3% 406ns ± 3% ~ (p=0.900 n=40+40) [Geo mean] 67.1µs 67.2µs +0.04% name old speed new speed delta GobDecode-4 106MB/s ± 5% 105MB/s ± 5% ~ (p=0.173 n=40+40) GobEncode-4 110MB/s ± 5% 112MB/s ± 9% ~ (p=0.104 n=40+40) Gzip-4 49.0MB/s ± 4% 49.1MB/s ± 4% ~ (p=0.836 n=40+40) Gunzip-4 471MB/s ± 3% 468MB/s ± 4% ~ (p=0.218 n=40+40) JSONEncode-4 111MB/s ± 2% 111MB/s ± 3% ~ (p=0.090 n=40+40) JSONDecode-4 32.0MB/s ± 3% 32.3MB/s ± 4% ~ (p=0.194 n=40+40) GoParse-4 17.6MB/s ± 3% 17.7MB/s ± 2% +0.62% (p=0.035 n=40+40) RegexpMatchEasy0_32-4 307MB/s ± 4% 309MB/s ± 4% +0.70% (p=0.041 n=40+40) RegexpMatchEasy0_1K-4 1.20GB/s ± 3% 1.21GB/s ± 2% ~ (p=0.353 n=40+40) RegexpMatchEasy1_32-4 285MB/s ± 3% 284MB/s ± 4% ~ (p=0.384 n=40+40) RegexpMatchEasy1_1K-4 988MB/s ± 4% 992MB/s ± 3% ~ (p=0.335 n=40+40) RegexpMatchMedium_32-4 7.56MB/s ± 4% 7.57MB/s ± 4% ~ (p=0.314 n=40+40) RegexpMatchMedium_1K-4 23.6MB/s ± 3% 23.6MB/s ± 3% ~ (p=0.107 n=40+40) RegexpMatchHard_32-4 14.3MB/s ± 4% 14.3MB/s ± 4% ~ (p=0.429 n=40+40) RegexpMatchHard_1K-4 15.1MB/s ± 3% 15.1MB/s ± 3% ~ (p=0.099 n=40+40) Revcomp-4 138MB/s ± 2% 138MB/s ± 2% ~ (p=0.658 n=40+40) Template-4 28.4MB/s ± 3% 28.3MB/s ± 3% ~ (p=0.331 n=40+40) [Geo mean] 80.8MB/s 80.8MB/s +0.09% Change-Id: I0cb715eead68ade097a302e7fb80ccbd1d1b511e Reviewed-on: https://go-review.googlesource.com/130975 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/x86/387.go | 5 +++++ test/codegen/floats.go | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/src/cmd/compile/internal/x86/387.go b/src/cmd/compile/internal/x86/387.go index ab3d30e76c1a9..18838fb4ca16d 100644 --- a/src/cmd/compile/internal/x86/387.go +++ b/src/cmd/compile/internal/x86/387.go @@ -33,6 +33,11 @@ func ssaGenValue387(s *gc.SSAGenState, v *ssa.Value) { } else if iv == 0xbff0000000000000 { // -1.0 s.Prog(x86.AFLD1) s.Prog(x86.AFCHS) + } else if iv == 0x400921fb54442d18 { // +pi + s.Prog(x86.AFLDPI) + } else if iv == 0xc00921fb54442d18 { // -pi + s.Prog(x86.AFLDPI) + s.Prog(x86.AFCHS) } else { // others p := s.Prog(loadPush(v.Type)) p.From.Type = obj.TYPE_FCONST diff --git a/test/codegen/floats.go b/test/codegen/floats.go index e0e4d973a3895..b046de8fcde3d 100644 --- a/test/codegen/floats.go +++ b/test/codegen/floats.go @@ -6,6 +6,8 @@ package codegen +import "math" + // This file contains codegen tests related to arithmetic // simplifications and optimizations on float types. // For codegen tests on integer types, see arithmetic.go. @@ -48,6 +50,11 @@ func DivPow2(f1, f2, f3 float64) (float64, float64, float64) { return x, y, z } +func getPi() float64 { + // 386/387:"FLDPI" + return math.Pi +} + // ----------- // // Fused // // ----------- // From f2ed3e1da16ba02543268b14d962e1026257604e Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 25 Aug 2018 10:11:19 -0700 Subject: [PATCH 0198/1663] cmd/go: don't let script grep commands match $WORK If $WORK happens to contain the string that a stdout/stderr/grep command is searching for, a negative grep command will fail incorrectly. Fixes #27170 Fixes #27221 Change-Id: I84454d3c42360fe3295c7235d388381525eb85b4 Reviewed-on: https://go-review.googlesource.com/131398 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- src/cmd/go/script_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go index 389485bc6582e..7c083a87b932f 100644 --- a/src/cmd/go/script_test.go +++ b/src/cmd/go/script_test.go @@ -629,6 +629,9 @@ func scriptMatch(ts *testScript, neg bool, args []string, text, name string) { text = string(data) } + // Matching against workdir would be misleading. + text = strings.Replace(text, ts.workdir, "$WORK", -1) + if neg { if re.MatchString(text) { if isGrep { From d145d923f894f3ef2faae52ca05321ef3d5bee7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florin=20P=C4=83=C8=9Ban?= Date: Thu, 19 Jul 2018 12:05:28 +0000 Subject: [PATCH 0199/1663] cmd/dist: fix compilation on windows Add missing extensions to binary files in order to allow execution. Change-Id: Idfe4c72c80c26b7b938023bc7bbe1ef85e1aa7b0 Change-Id: Idfe4c72c80c26b7b938023bc7bbe1ef85e1aa7b0 GitHub-Last-Rev: ed9d8124270c30b7f25f89656432ef5089466c7e GitHub-Pull-Request: golang/go#26464 Reviewed-on: https://go-review.googlesource.com/124936 Run-TryBot: Brad Fitzpatrick Reviewed-by: Brad Fitzpatrick --- src/make.bat | 4 ++-- src/race.bat | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/make.bat b/src/make.bat index 2e718334a2e47..590e639830db8 100644 --- a/src/make.bat +++ b/src/make.bat @@ -80,7 +80,7 @@ set GOBIN= "%GOROOT_BOOTSTRAP%\bin\go" build -o cmd\dist\dist.exe .\cmd\dist endlocal if errorlevel 1 goto fail -.\cmd\dist\dist env -w -p >env.bat +.\cmd\dist\dist.exe env -w -p >env.bat if errorlevel 1 goto fail call env.bat del env.bat @@ -104,7 +104,7 @@ if x%4==x--no-banner set buildall=%buildall% --no-banner :: Run dist bootstrap to complete make.bash. :: Bootstrap installs a proper cmd/dist, built with the new toolchain. :: Throw ours, built with Go 1.4, away after bootstrap. -.\cmd\dist\dist bootstrap %vflag% %buildall% +.\cmd\dist\dist.exe bootstrap %vflag% %buildall% if errorlevel 1 goto fail del .\cmd\dist\dist.exe goto end diff --git a/src/race.bat b/src/race.bat index e8df480811c88..e1c3fbf5d9c64 100644 --- a/src/race.bat +++ b/src/race.bat @@ -18,7 +18,7 @@ goto end set GOROOT=%CD%\.. call make.bat --dist-tool >NUL if errorlevel 1 goto fail -.\cmd\dist\dist env -w -p >env.bat +.\cmd\dist\dist.exe env -w -p >env.bat if errorlevel 1 goto fail call env.bat del env.bat From 30b080e0600e774516a4f9343d7c5f53a5d012c2 Mon Sep 17 00:00:00 2001 From: Goo Date: Sat, 25 Aug 2018 22:35:38 +0000 Subject: [PATCH 0200/1663] src/make.bat: add missing go.exe extension Got error: 'go' is not an internal or external command, nor is it a runnable program Change-Id: Ie45a3a12252fa01b67ca09ef8fbb5b4bbf728fe7 GitHub-Last-Rev: 451815cacd9bfc509fa0aab3be54303797e605a2 GitHub-Pull-Request: golang/go#27214 Reviewed-on: https://go-review.googlesource.com/131397 Reviewed-by: Brad Fitzpatrick --- src/make.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/make.bat b/src/make.bat index 590e639830db8..9ca7afb5aa979 100644 --- a/src/make.bat +++ b/src/make.bat @@ -77,7 +77,7 @@ set GOROOT=%GOROOT_BOOTSTRAP% set GOOS= set GOARCH= set GOBIN= -"%GOROOT_BOOTSTRAP%\bin\go" build -o cmd\dist\dist.exe .\cmd\dist +"%GOROOT_BOOTSTRAP%\bin\go.exe" build -o cmd\dist\dist.exe .\cmd\dist endlocal if errorlevel 1 goto fail .\cmd\dist\dist.exe env -w -p >env.bat From 541620409dee210c5498cc38433dcf690f58f888 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 24 Aug 2018 19:08:28 +0000 Subject: [PATCH 0201/1663] net/http: make Transport return Writable Response.Body on protocol switch Updates #26937 Updates #17227 Change-Id: I79865938b05c219e1947822e60e4f52bb2604b70 Reviewed-on: https://go-review.googlesource.com/131279 Reviewed-by: Brad Fitzpatrick --- src/net/http/response.go | 25 ++++++++++++++++ src/net/http/transport.go | 52 ++++++++++++++++++++++++++++++++-- src/net/http/transport_test.go | 51 +++++++++++++++++++++++++++++++++ 3 files changed, 126 insertions(+), 2 deletions(-) diff --git a/src/net/http/response.go b/src/net/http/response.go index bf1e13c8ae2f1..b3ca56c4190db 100644 --- a/src/net/http/response.go +++ b/src/net/http/response.go @@ -12,6 +12,7 @@ import ( "crypto/tls" "errors" "fmt" + "golang_org/x/net/http/httpguts" "io" "net/textproto" "net/url" @@ -63,6 +64,10 @@ type Response struct { // // The Body is automatically dechunked if the server replied // with a "chunked" Transfer-Encoding. + // + // As of Go 1.12, the Body will be also implement io.Writer + // on a successful "101 Switching Protocols" responses, + // as used by WebSockets and HTTP/2's "h2c" mode. Body io.ReadCloser // ContentLength records the length of the associated content. The @@ -333,3 +338,23 @@ func (r *Response) closeBody() { r.Body.Close() } } + +// bodyIsWritable reports whether the Body supports writing. The +// Transport returns Writable bodies for 101 Switching Protocols +// responses. +// The Transport uses this method to determine whether a persistent +// connection is done being managed from its perspective. Once we +// return a writable response body to a user, the net/http package is +// done managing that connection. +func (r *Response) bodyIsWritable() bool { + _, ok := r.Body.(io.Writer) + return ok +} + +// isProtocolSwitch reports whether r is a response to a successful +// protocol upgrade. +func (r *Response) isProtocolSwitch() bool { + return r.StatusCode == StatusSwitchingProtocols && + r.Header.Get("Upgrade") != "" && + httpguts.HeaderValuesContainsToken(r.Header["Connection"], "Upgrade") +} diff --git a/src/net/http/transport.go b/src/net/http/transport.go index 40947baf87a42..ffe4cdc0d6dba 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -1607,6 +1607,11 @@ func (pc *persistConn) mapRoundTripError(req *transportRequest, startBytesWritte return err } +// errCallerOwnsConn is an internal sentinel error used when we hand +// off a writable response.Body to the caller. We use this to prevent +// closing a net.Conn that is now owned by the caller. +var errCallerOwnsConn = errors.New("read loop ending; caller owns writable underlying conn") + func (pc *persistConn) readLoop() { closeErr := errReadLoopExiting // default value, if not changed below defer func() { @@ -1681,9 +1686,10 @@ func (pc *persistConn) readLoop() { pc.numExpectedResponses-- pc.mu.Unlock() + bodyWritable := resp.bodyIsWritable() hasBody := rc.req.Method != "HEAD" && resp.ContentLength != 0 - if resp.Close || rc.req.Close || resp.StatusCode <= 199 { + if resp.Close || rc.req.Close || resp.StatusCode <= 199 || bodyWritable { // Don't do keep-alive on error if either party requested a close // or we get an unexpected informational (1xx) response. // StatusCode 100 is already handled above. @@ -1704,6 +1710,10 @@ func (pc *persistConn) readLoop() { pc.wroteRequest() && tryPutIdleConn(trace) + if bodyWritable { + closeErr = errCallerOwnsConn + } + select { case rc.ch <- responseAndError{res: resp}: case <-rc.callerGone: @@ -1848,6 +1858,10 @@ func (pc *persistConn) readResponse(rc requestAndChan, trace *httptrace.ClientTr } break } + if resp.isProtocolSwitch() { + resp.Body = newReadWriteCloserBody(pc.br, pc.conn) + } + resp.TLS = pc.tlsState return } @@ -1874,6 +1888,38 @@ func (pc *persistConn) waitForContinue(continueCh <-chan struct{}) func() bool { } } +func newReadWriteCloserBody(br *bufio.Reader, rwc io.ReadWriteCloser) io.ReadWriteCloser { + body := &readWriteCloserBody{ReadWriteCloser: rwc} + if br.Buffered() != 0 { + body.br = br + } + return body +} + +// readWriteCloserBody is the Response.Body type used when we want to +// give users write access to the Body through the underlying +// connection (TCP, unless using custom dialers). This is then +// the concrete type for a Response.Body on the 101 Switching +// Protocols response, as used by WebSockets, h2c, etc. +type readWriteCloserBody struct { + br *bufio.Reader // used until empty + io.ReadWriteCloser +} + +func (b *readWriteCloserBody) Read(p []byte) (n int, err error) { + if b.br != nil { + if n := b.br.Buffered(); len(p) > n { + p = p[:n] + } + n, err = b.br.Read(p) + if b.br.Buffered() == 0 { + b.br = nil + } + return n, err + } + return b.ReadWriteCloser.Read(p) +} + // nothingWrittenError wraps a write errors which ended up writing zero bytes. type nothingWrittenError struct { error @@ -2193,7 +2239,9 @@ func (pc *persistConn) closeLocked(err error) { // freelist for http2. That's done by the // alternate protocol's RoundTripper. } else { - pc.conn.Close() + if err != errCallerOwnsConn { + pc.conn.Close() + } close(pc.closech) } } diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 73e6e3033177f..327b3b4996c90 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -4836,3 +4836,54 @@ func TestClientTimeoutKillsConn_AfterHeaders(t *testing.T) { t.Fatal("timeout") } } + +func TestTransportResponseBodyWritableOnProtocolSwitch(t *testing.T) { + setParallel(t) + defer afterTest(t) + done := make(chan struct{}) + defer close(done) + cst := newClientServerTest(t, h1Mode, HandlerFunc(func(w ResponseWriter, r *Request) { + conn, _, err := w.(Hijacker).Hijack() + if err != nil { + t.Error(err) + return + } + defer conn.Close() + io.WriteString(conn, "HTTP/1.1 101 Switching Protocols Hi\r\nConnection: upgRADe\r\nUpgrade: foo\r\n\r\nSome buffered data\n") + bs := bufio.NewScanner(conn) + bs.Scan() + fmt.Fprintf(conn, "%s\n", strings.ToUpper(bs.Text())) + <-done + })) + defer cst.close() + + req, _ := NewRequest("GET", cst.ts.URL, nil) + req.Header.Set("Upgrade", "foo") + req.Header.Set("Connection", "upgrade") + res, err := cst.c.Do(req) + if err != nil { + t.Fatal(err) + } + if res.StatusCode != 101 { + t.Fatalf("expected 101 switching protocols; got %v, %v", res.Status, res.Header) + } + rwc, ok := res.Body.(io.ReadWriteCloser) + if !ok { + t.Fatalf("expected a ReadWriteCloser; got a %T", res.Body) + } + defer rwc.Close() + bs := bufio.NewScanner(rwc) + if !bs.Scan() { + t.Fatalf("expected readable input") + } + if got, want := bs.Text(), "Some buffered data"; got != want { + t.Errorf("read %q; want %q", got, want) + } + io.WriteString(rwc, "echo\n") + if !bs.Scan() { + t.Fatalf("expected another line") + } + if got, want := bs.Text(), "ECHO"; got != want { + t.Errorf("read %q; want %q", got, want) + } +} From 88f4bccec503919fad348e7c88c1f2cd0f509464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 25 Aug 2018 15:49:11 +0100 Subject: [PATCH 0202/1663] encoding/json: avoid some more pointer receivers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A few encoder struct types, such as map and slice, only encapsulate other prepared encoder funcs. Using pointer receivers has no advantage, and makes calling these methods slightly more expensive. Not a huge performance win, but certainly an easy one. The struct types used in the benchmark below contain one slice field and one pointer field. name old time/op new time/op delta CodeEncoder-4 5.48ms ± 0% 5.39ms ± 0% -1.66% (p=0.010 n=6+4) name old speed new speed delta CodeEncoder-4 354MB/s ± 0% 360MB/s ± 0% +1.69% (p=0.010 n=6+4) Updates #5683. Change-Id: I9f78dbe07fcc6fbf19a6d96c22f5d6970db9eca4 Reviewed-on: https://go-review.googlesource.com/131400 Run-TryBot: Daniel Martí Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/encoding/json/encode.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index f475d5688ab51..ec49ceb93ee00 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -674,7 +674,7 @@ type mapEncoder struct { elemEnc encoderFunc } -func (me *mapEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { +func (me mapEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { if v.IsNil() { e.WriteString("null") return @@ -713,7 +713,7 @@ func newMapEncoder(t reflect.Type) encoderFunc { return unsupportedTypeEncoder } } - me := &mapEncoder{typeEncoder(t.Elem())} + me := mapEncoder{typeEncoder(t.Elem())} return me.encode } @@ -752,7 +752,7 @@ type sliceEncoder struct { arrayEnc encoderFunc } -func (se *sliceEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { +func (se sliceEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { if v.IsNil() { e.WriteString("null") return @@ -768,7 +768,7 @@ func newSliceEncoder(t reflect.Type) encoderFunc { return encodeByteSlice } } - enc := &sliceEncoder{newArrayEncoder(t)} + enc := sliceEncoder{newArrayEncoder(t)} return enc.encode } @@ -776,7 +776,7 @@ type arrayEncoder struct { elemEnc encoderFunc } -func (ae *arrayEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { +func (ae arrayEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { e.WriteByte('[') n := v.Len() for i := 0; i < n; i++ { @@ -789,7 +789,7 @@ func (ae *arrayEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { } func newArrayEncoder(t reflect.Type) encoderFunc { - enc := &arrayEncoder{typeEncoder(t.Elem())} + enc := arrayEncoder{typeEncoder(t.Elem())} return enc.encode } @@ -797,7 +797,7 @@ type ptrEncoder struct { elemEnc encoderFunc } -func (pe *ptrEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { +func (pe ptrEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { if v.IsNil() { e.WriteString("null") return @@ -806,7 +806,7 @@ func (pe *ptrEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { } func newPtrEncoder(t reflect.Type) encoderFunc { - enc := &ptrEncoder{typeEncoder(t.Elem())} + enc := ptrEncoder{typeEncoder(t.Elem())} return enc.encode } @@ -814,7 +814,7 @@ type condAddrEncoder struct { canAddrEnc, elseEnc encoderFunc } -func (ce *condAddrEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { +func (ce condAddrEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { if v.CanAddr() { ce.canAddrEnc(e, v, opts) } else { @@ -825,7 +825,7 @@ func (ce *condAddrEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) // newCondAddrEncoder returns an encoder that checks whether its value // CanAddr and delegates to canAddrEnc if so, else to elseEnc. func newCondAddrEncoder(canAddrEnc, elseEnc encoderFunc) encoderFunc { - enc := &condAddrEncoder{canAddrEnc: canAddrEnc, elseEnc: elseEnc} + enc := condAddrEncoder{canAddrEnc: canAddrEnc, elseEnc: elseEnc} return enc.encode } From c21ba224ec88c2a5cb01dad54f06819ed29d4ba4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sat, 25 Aug 2018 16:29:01 +0100 Subject: [PATCH 0203/1663] encoding/json: remove a branch in the structEncoder loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Encoders like map and array can use the much cheaper "i > 0" check to see if we're not writing the first element. However, since struct fields support omitempty, we need to keep track of that separately. This is much more expensive - after calling the field encoder itself, and retrieving the field via reflection, this branch was the third most expensive piece of this field loop. Instead, hoist the branch logic outside of the loop. The code doesn't get much more complex, since we just delay the writing of each byte until the next iteration. Yet the performance improvement is noticeable, even when the struct types in CodeEncoder only have 2 and 7 fields, respectively. name old time/op new time/op delta CodeEncoder-4 5.39ms ± 0% 5.31ms ± 0% -1.37% (p=0.010 n=4+6) name old speed new speed delta CodeEncoder-4 360MB/s ± 0% 365MB/s ± 0% +1.39% (p=0.010 n=4+6) Updates #5683. Change-Id: I2662cf459e0dfd68e56fa52bc898a417e84266c2 Reviewed-on: https://go-review.googlesource.com/131401 Run-TryBot: Daniel Martí Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/encoding/json/encode.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index ec49ceb93ee00..7e5e209b4f2b6 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -628,8 +628,7 @@ type structEncoder struct { } func (se structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { - e.WriteByte('{') - first := true + next := byte('{') for i := range se.fields { f := &se.fields[i] @@ -649,11 +648,8 @@ func (se structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { if f.omitEmpty && isEmptyValue(fv) { continue } - if first { - first = false - } else { - e.WriteByte(',') - } + e.WriteByte(next) + next = ',' if opts.escapeHTML { e.WriteString(f.nameEscHTML) } else { @@ -662,7 +658,11 @@ func (se structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { opts.quoted = f.quoted f.encoder(e, fv, opts) } - e.WriteByte('}') + if next == '{' { + e.WriteString("{}") + } else { + e.WriteByte('}') + } } func newStructEncoder(t reflect.Type) encoderFunc { From b7d3e14a5296b17c940983aed0d9d6cb54b912b7 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 20 Aug 2018 10:15:47 +0900 Subject: [PATCH 0204/1663] path/filepath: fix Join with Windows drive letter Join("C:", "", "b") must return relative path "C:b" Fixes #26953 Change-Id: I2f843ce3f9f18a1ce0e2d0f3a15233f237992776 Reviewed-on: https://go-review.googlesource.com/129758 Run-TryBot: Emmanuel Odeke TryBot-Result: Gobot Gobot Reviewed-by: Alex Brainman --- src/path/filepath/path_test.go | 4 ++++ src/path/filepath/path_windows.go | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index dde087253dda3..e50ee97bcb3f7 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -271,6 +271,10 @@ var winjointests = []JoinTest{ {[]string{`C:`, `a`}, `C:a`}, {[]string{`C:`, `a\b`}, `C:a\b`}, {[]string{`C:`, `a`, `b`}, `C:a\b`}, + {[]string{`C:`, ``, `b`}, `C:b`}, + {[]string{`C:`, ``, ``, `b`}, `C:b`}, + {[]string{`C:`, ``}, `C:.`}, + {[]string{`C:`, ``, ``}, `C:.`}, {[]string{`C:.`, `a`}, `C:a`}, {[]string{`C:a`, `b`}, `C:a\b`}, {[]string{`C:a`, `b`, `d`}, `C:a\b\d`}, diff --git a/src/path/filepath/path_windows.go b/src/path/filepath/path_windows.go index 409e8d6466a95..519b6ebc329cc 100644 --- a/src/path/filepath/path_windows.go +++ b/src/path/filepath/path_windows.go @@ -134,7 +134,14 @@ func joinNonEmpty(elem []string) string { if len(elem[0]) == 2 && elem[0][1] == ':' { // First element is drive letter without terminating slash. // Keep path relative to current directory on that drive. - return Clean(elem[0] + strings.Join(elem[1:], string(Separator))) + // Skip empty elements. + i := 1 + for ; i < len(elem); i++ { + if elem[i] != "" { + break + } + } + return Clean(elem[0] + strings.Join(elem[i:], string(Separator))) } // The following logic prevents Join from inadvertently creating a // UNC path on Windows. Unless the first element is a UNC path, Join From eae5fc88c13d6902a7fe9c595fb02155eb037cbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20M=C3=B6hrmann?= Date: Sat, 25 Aug 2018 16:53:23 +0200 Subject: [PATCH 0205/1663] internal/bytealg: replace use of runtime.support_sse2 with cpu.X86.HasSSE2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This makes the runtime.support_sse2 variable unused so it is removed in this CL too. Change-Id: Ia8b9ffee7ac97128179f74ef244b10315e44c234 Reviewed-on: https://go-review.googlesource.com/131455 Run-TryBot: Martin Möhrmann TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/internal/bytealg/compare_386.s | 2 +- src/runtime/proc.go | 1 - src/runtime/runtime2.go | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/internal/bytealg/compare_386.s b/src/internal/bytealg/compare_386.s index 89296e16905e4..f73e3f8b35611 100644 --- a/src/internal/bytealg/compare_386.s +++ b/src/internal/bytealg/compare_386.s @@ -45,7 +45,7 @@ TEXT cmpbody<>(SB),NOSPLIT,$0-0 JEQ allsame CMPL BP, $4 JB small - CMPB runtime·support_sse2(SB), $1 + CMPB internal∕cpu·X86+const_offsetX86HasSSE2(SB), $1 JNE mediumloop largeloop: CMPL BP, $16 diff --git a/src/runtime/proc.go b/src/runtime/proc.go index 75d309a9f66d1..73b4a1d9d62aa 100644 --- a/src/runtime/proc.go +++ b/src/runtime/proc.go @@ -510,7 +510,6 @@ func cpuinit() { // Support cpu feature variables are used in code generated by the compiler // to guard execution of instructions that can not be assumed to be always supported. support_popcnt = cpu.X86.HasPOPCNT - support_sse2 = cpu.X86.HasSSE2 support_sse41 = cpu.X86.HasSSE41 arm64_support_atomics = cpu.ARM64.HasATOMICS diff --git a/src/runtime/runtime2.go b/src/runtime/runtime2.go index e4c6b3b52a7e6..259bb376ae2fd 100644 --- a/src/runtime/runtime2.go +++ b/src/runtime/runtime2.go @@ -847,7 +847,6 @@ var ( // Set in runtime.cpuinit. // TODO: deprecate these; use internal/cpu directly. support_popcnt bool - support_sse2 bool support_sse41 bool arm64_support_atomics bool From 21af0c1699909454baa4fc6890fe9a1d337faf9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 26 Aug 2018 08:35:24 -0600 Subject: [PATCH 0206/1663] encoding/json: get rid of the stream_test.go TODOs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TestRawMessage now passes without the need for the RawMessage field to be a pointer. The TODO dates all the way back to 2010, so I presume the issue has since been fixed. TestNullRawMessage tested the decoding of a JSON null into a *RawMessage. The existing behavior was correct, but for the sake of completeness a non-pointer RawMessage field has been added too. The non-pointer field behaves differently, as one can read in the docs: To unmarshal JSON into a value implementing the Unmarshaler interface, Unmarshal calls that value's UnmarshalJSON method, including when the input is a JSON null. Change-Id: Iabaed75d4ed10ea427d135ee1b80c6e6b83b2e6e Reviewed-on: https://go-review.googlesource.com/131377 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/encoding/json/stream_test.go | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/encoding/json/stream_test.go b/src/encoding/json/stream_test.go index 0ed1c9e974754..aaf32e0a24ce5 100644 --- a/src/encoding/json/stream_test.go +++ b/src/encoding/json/stream_test.go @@ -201,10 +201,9 @@ func nlines(s string, n int) string { } func TestRawMessage(t *testing.T) { - // TODO(rsc): Should not need the * in *RawMessage var data struct { X float64 - Id *RawMessage + Id RawMessage Y float32 } const raw = `["\u0056",null]` @@ -213,8 +212,8 @@ func TestRawMessage(t *testing.T) { if err != nil { t.Fatalf("Unmarshal: %v", err) } - if string([]byte(*data.Id)) != raw { - t.Fatalf("Raw mismatch: have %#q want %#q", []byte(*data.Id), raw) + if string([]byte(data.Id)) != raw { + t.Fatalf("Raw mismatch: have %#q want %#q", []byte(data.Id), raw) } b, err := Marshal(&data) if err != nil { @@ -226,20 +225,22 @@ func TestRawMessage(t *testing.T) { } func TestNullRawMessage(t *testing.T) { - // TODO(rsc): Should not need the * in *RawMessage var data struct { - X float64 - Id *RawMessage - Y float32 + X float64 + Id RawMessage + IdPtr *RawMessage + Y float32 } - data.Id = new(RawMessage) - const msg = `{"X":0.1,"Id":null,"Y":0.2}` + const msg = `{"X":0.1,"Id":null,"IdPtr":null,"Y":0.2}` err := Unmarshal([]byte(msg), &data) if err != nil { t.Fatalf("Unmarshal: %v", err) } - if data.Id != nil { - t.Fatalf("Raw mismatch: have non-nil, want nil") + if want, got := "null", string(data.Id); want != got { + t.Fatalf("Raw mismatch: have %q, want %q", got, want) + } + if data.IdPtr != nil { + t.Fatalf("Raw pointer mismatch: have non-nil, want nil") } b, err := Marshal(&data) if err != nil { From 969b9d8127c0ef3bbffeb1fa7d13a7ec1afccce4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Sun, 26 Aug 2018 06:24:33 -0600 Subject: [PATCH 0207/1663] encoding/json: fix handling of nil anonymous structs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Given the following types: type S2 struct{ Field string } type S struct{ *S2 } Marshalling a value of type T1 should result in "{}", as there's no way to access any value of T2.Field. This is how Go 1.10 and earlier versions behave. However, in the recent refactor golang.org/cl/125417 I broke this logic. When the encoder found an anonymous struct pointer field that was nil, it no longer skipped the embedded fields underneath it. This can be seen in the added test: --- FAIL: TestAnonymousFields/EmbeddedFieldBehindNilPointer (0.00s) encode_test.go:430: Marshal() = "{\"Field\":\"\\u003c*json.S2 Value\\u003e\"}", want "{}" The human error was a misplaced label, meaning we weren't actually skipping the right loop iteration. Fix that. Change-Id: Iba8a4a77d358dac73dcba4018498fe4f81afa263 Reviewed-on: https://go-review.googlesource.com/131376 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/encoding/json/encode.go | 2 +- src/encoding/json/encode_test.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/encoding/json/encode.go b/src/encoding/json/encode.go index 7e5e209b4f2b6..f10124e67d13c 100644 --- a/src/encoding/json/encode.go +++ b/src/encoding/json/encode.go @@ -629,12 +629,12 @@ type structEncoder struct { func (se structEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) { next := byte('{') +FieldLoop: for i := range se.fields { f := &se.fields[i] // Find the nested struct field by following f.index. fv := v - FieldLoop: for _, i := range f.index { if fv.Kind() == reflect.Ptr { if fv.IsNil() { diff --git a/src/encoding/json/encode_test.go b/src/encoding/json/encode_test.go index 1b7838c895d11..cd5eadf3c1cd2 100644 --- a/src/encoding/json/encode_test.go +++ b/src/encoding/json/encode_test.go @@ -405,6 +405,19 @@ func TestAnonymousFields(t *testing.T) { return S{s1{1, 2, s2{3, 4}}, 6} }, want: `{"MyInt1":1,"MyInt2":3}`, + }, { + // If an anonymous struct pointer field is nil, we should ignore + // the embedded fields behind it. Not properly doing so may + // result in the wrong output or reflect panics. + label: "EmbeddedFieldBehindNilPointer", + makeInput: func() interface{} { + type ( + S2 struct{ Field string } + S struct{ *S2 } + ) + return S{} + }, + want: `{}`, }} for _, tt := range tests { From a700ae98630b4e4dd03a0ead627941d6bb1d55bf Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 26 Aug 2018 18:50:33 +0000 Subject: [PATCH 0208/1663] Revert "syscall, os: use pipe2 syscall on DragonflyBSD instead of pipe" This reverts commit e6c15945dee0661dee6111183d4951853c4c2d98. Reason for revert: breaks the Dragonfly builders. Fixes #27245 Change-Id: I2c147a5726aec28647f6ef5eb8f9db5efa3a9fd0 Reviewed-on: https://go-review.googlesource.com/131497 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/os/pipe2_bsd.go | 2 +- src/os/pipe_bsd.go | 2 +- src/syscall/forkpipe.go | 2 +- src/syscall/forkpipe2.go | 2 +- src/syscall/syscall_dragonfly.go | 10 +++------- src/syscall/zsyscall_dragonfly_amd64.go | 4 ++-- src/syscall/zsysnum_dragonfly_amd64.go | 1 - 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/src/os/pipe2_bsd.go b/src/os/pipe2_bsd.go index 7d2d9e8ffd9f0..0ef894b476bed 100644 --- a/src/os/pipe2_bsd.go +++ b/src/os/pipe2_bsd.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build dragonfly freebsd netbsd openbsd +// +build freebsd netbsd openbsd package os diff --git a/src/os/pipe_bsd.go b/src/os/pipe_bsd.go index 6fd10dbc1a1f9..9735988f324d3 100644 --- a/src/os/pipe_bsd.go +++ b/src/os/pipe_bsd.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin js,wasm nacl solaris +// +build darwin dragonfly js,wasm nacl solaris package os diff --git a/src/syscall/forkpipe.go b/src/syscall/forkpipe.go index 55777497b1012..71890a29badcc 100644 --- a/src/syscall/forkpipe.go +++ b/src/syscall/forkpipe.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin solaris +// +build darwin dragonfly solaris package syscall diff --git a/src/syscall/forkpipe2.go b/src/syscall/forkpipe2.go index 0078f4bbabd24..c9a0c4996e3bb 100644 --- a/src/syscall/forkpipe2.go +++ b/src/syscall/forkpipe2.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build dragonfly freebsd netbsd openbsd +// +build freebsd netbsd openbsd package syscall diff --git a/src/syscall/syscall_dragonfly.go b/src/syscall/syscall_dragonfly.go index d59f139446e4f..3dbbe342cfbb2 100644 --- a/src/syscall/syscall_dragonfly.go +++ b/src/syscall/syscall_dragonfly.go @@ -72,17 +72,13 @@ func direntNamlen(buf []byte) (uint64, bool) { return readInt(buf, unsafe.Offsetof(Dirent{}.Namlen), unsafe.Sizeof(Dirent{}.Namlen)) } -func Pipe(p []int) error { - return Pipe2(p, 0) -} - -//sysnb pipe2(flags int) (r int, w int, err error) +//sysnb pipe() (r int, w int, err error) -func Pipe2(p []int, flags int) (err error) { +func Pipe(p []int) (err error) { if len(p) != 2 { return EINVAL } - p[0], p[1], err = pipe2(flags) + p[0], p[1], err = pipe() return } diff --git a/src/syscall/zsyscall_dragonfly_amd64.go b/src/syscall/zsyscall_dragonfly_amd64.go index f9ed33aae8032..578b5a3e9e4b9 100644 --- a/src/syscall/zsyscall_dragonfly_amd64.go +++ b/src/syscall/zsyscall_dragonfly_amd64.go @@ -261,8 +261,8 @@ func fcntl(fd int, cmd int, arg int) (val int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func pipe2(flags int) (r int, w int, err error) { - r0, r1, e1 := RawSyscall(SYS_PIPE2, uintptr(flags), 0, 0) +func pipe() (r int, w int, err error) { + r0, r1, e1 := RawSyscall(SYS_PIPE, 0, 0, 0) r = int(r0) w = int(r1) if e1 != 0 { diff --git a/src/syscall/zsysnum_dragonfly_amd64.go b/src/syscall/zsysnum_dragonfly_amd64.go index 58582b9e7a485..9ce11f5899f9f 100644 --- a/src/syscall/zsysnum_dragonfly_amd64.go +++ b/src/syscall/zsysnum_dragonfly_amd64.go @@ -301,7 +301,6 @@ const ( SYS_LPATHCONF = 533 // { int lpathconf(char *path, int name); } SYS_VMM_GUEST_CTL = 534 // { int vmm_guest_ctl(int op, struct vmm_guest_options *options); } SYS_VMM_GUEST_SYNC_ADDR = 535 // { int vmm_guest_sync_addr(long *dstaddr, long *srcaddr); } - SYS_PIPE2 = 538 // { int pipe2(int *fildes, int flags); } SYS_UTIMENSAT = 539 // { int utimensat(int fd, const char *path, const struct timespec *ts, int flags); } SYS_ACCEPT4 = 541 // { int accept4(int s, caddr_t name, int *anamelen, int flags); } ) From 42cc4ca30a7729a4c6d1bb0bbbc3e4a736ef91c8 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Wed, 22 Aug 2018 14:01:22 +0200 Subject: [PATCH 0209/1663] cmd/compile: prevent overflow in walkinrange MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the compiler frontend, walkinrange indiscriminately calls Int64() on const CTINT nodes, even though Int64's return value is undefined for anything over 2⁶³ (in practise, it'll return a negative number). This causes the introduction of bad constants during rewrites of unsigned expressions, which make the compiler reject valid Go programs. This change introduces a preliminary check that Int64() is safe to call on the consts on hand. If it isn't, walkinrange exits without doing any rewrite. Fixes #27143 Change-Id: I2017073cae65468a521ff3262d4ea8ab0d7098d9 Reviewed-on: https://go-review.googlesource.com/130735 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Josh Bleecher Snyder --- src/cmd/compile/internal/gc/const.go | 11 +++++++++++ src/cmd/compile/internal/gc/walk.go | 6 ++++++ test/fixedbugs/issue27143.go | 17 +++++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 test/fixedbugs/issue27143.go diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index ceb124e31e39c..1403a2be11edf 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -121,6 +121,17 @@ func (n *Node) Int64() int64 { return n.Val().U.(*Mpint).Int64() } +// CanInt64 reports whether it is safe to call Int64() on n. +func (n *Node) CanInt64() bool { + if !Isconst(n, CTINT) { + return false + } + + // if the value inside n cannot be represented as an int64, the + // return value of Int64 is undefined + return n.Val().U.(*Mpint).CmpInt64(n.Int64()) == 0 +} + // Bool returns n as a bool. // n must be a boolean constant. func (n *Node) Bool() bool { diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index bd936fb70a038..2993e08fc2b68 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -3694,6 +3694,12 @@ func walkinrange(n *Node, init *Nodes) *Node { return n } + // Ensure that Int64() does not overflow on a and c (it'll happen + // for any const above 2**63; see issue #27143). + if !a.CanInt64() || !c.CanInt64() { + return n + } + if opl == OLT { // We have a < b && ... // We need a ≤ b && ... to safely use unsigned comparison tricks. diff --git a/test/fixedbugs/issue27143.go b/test/fixedbugs/issue27143.go new file mode 100644 index 0000000000000..009ec9f6c255e --- /dev/null +++ b/test/fixedbugs/issue27143.go @@ -0,0 +1,17 @@ +// compile + +// Copyright 2018 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. + +// Issue 27143: cmd/compile: erroneous application of walkinrange +// optimization for const over 2**63 + +package p + +var c uint64 + +var b1 bool = 0x7fffffffffffffff < c && c < 0x8000000000000000 +var b2 bool = c < 0x8000000000000000 && 0x7fffffffffffffff < c +var b3 bool = 0x8000000000000000 < c && c < 0x8000000000000001 +var b4 bool = c < 0x8000000000000001 && 0x8000000000000000 < c From 7334904e43005f930a776c793d54e03d13e62b30 Mon Sep 17 00:00:00 2001 From: Benny Siegert Date: Mon, 27 Aug 2018 13:16:38 +0000 Subject: [PATCH 0210/1663] cmd/dist: do not run race detector tests on netbsd The race detector is not fully functional on NetBSD yet. Without this change, all.bash fails in TestOutput. This unbreaks the netbsd-amd64 builder. Update #26403 Fixes #27268 Change-Id: I2c7015692d3632aa1037f40155d4fc5c7bb1d8c3 Reviewed-on: https://go-review.googlesource.com/131555 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/dist/test.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 3d0ef284484d4..4cd854773f21d 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -1343,6 +1343,11 @@ func (t *tester) raceDetectorSupported() bool { if isAlpineLinux() { return false } + // NetBSD support is unfinished. + // golang.org/issue/26403 + if goos == "netbsd" { + return false + } return true } From 096229b2ec60c51b65746dfd1a5bf443ac8e5a0f Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Wed, 8 Aug 2018 02:04:49 +0000 Subject: [PATCH 0211/1663] cmd/compile: add missing type information for some arm/arm64 rules Some indexed load/store rules lack of type information, and this CL adds that for them. Change-Id: Icac315ccb83a2f5bf30b056d4667d5b59eb4e5e2 Reviewed-on: https://go-review.googlesource.com/128455 Reviewed-by: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/ssa/gen/ARM64Ops.go | 24 ++++++++-------- src/cmd/compile/internal/ssa/gen/ARMOps.go | 30 ++++++++++---------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go index c87c18f3fb587..648d5a59a6093 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go @@ -324,20 +324,20 @@ func init() { {name: "FMOVDload", argLength: 2, reg: fpload, aux: "SymOff", asm: "FMOVD", typ: "Float64", faultOnNilArg0: true, symEffect: "Read"}, // load from arg0 + auxInt + aux. arg1=mem. // register indexed load - {name: "MOVDloadidx", argLength: 3, reg: gp2load, asm: "MOVD"}, // load 64-bit dword from arg0 + arg1, arg2 = mem. - {name: "MOVWloadidx", argLength: 3, reg: gp2load, asm: "MOVW"}, // load 32-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. - {name: "MOVWUloadidx", argLength: 3, reg: gp2load, asm: "MOVWU"}, // load 32-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. - {name: "MOVHloadidx", argLength: 3, reg: gp2load, asm: "MOVH"}, // load 16-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. - {name: "MOVHUloadidx", argLength: 3, reg: gp2load, asm: "MOVHU"}, // load 16-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. - {name: "MOVBloadidx", argLength: 3, reg: gp2load, asm: "MOVB"}, // load 8-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. - {name: "MOVBUloadidx", argLength: 3, reg: gp2load, asm: "MOVBU"}, // load 8-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. + {name: "MOVDloadidx", argLength: 3, reg: gp2load, asm: "MOVD", typ: "UInt64"}, // load 64-bit dword from arg0 + arg1, arg2 = mem. + {name: "MOVWloadidx", argLength: 3, reg: gp2load, asm: "MOVW", typ: "Int32"}, // load 32-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. + {name: "MOVWUloadidx", argLength: 3, reg: gp2load, asm: "MOVWU", typ: "UInt32"}, // load 32-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. + {name: "MOVHloadidx", argLength: 3, reg: gp2load, asm: "MOVH", typ: "Int16"}, // load 16-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. + {name: "MOVHUloadidx", argLength: 3, reg: gp2load, asm: "MOVHU", typ: "UInt16"}, // load 16-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. + {name: "MOVBloadidx", argLength: 3, reg: gp2load, asm: "MOVB", typ: "Int8"}, // load 8-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. + {name: "MOVBUloadidx", argLength: 3, reg: gp2load, asm: "MOVBU", typ: "UInt8"}, // load 8-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. // shifted register indexed load - {name: "MOVHloadidx2", argLength: 3, reg: gp2load, asm: "MOVH"}, // load 16-bit half-word from arg0 + arg1*2, sign-extended to 64-bit, arg2=mem. - {name: "MOVHUloadidx2", argLength: 3, reg: gp2load, asm: "MOVHU"}, // load 16-bit half-word from arg0 + arg1*2, zero-extended to 64-bit, arg2=mem. - {name: "MOVWloadidx4", argLength: 3, reg: gp2load, asm: "MOVW"}, // load 32-bit word from arg0 + arg1*4, sign-extended to 64-bit, arg2=mem. - {name: "MOVWUloadidx4", argLength: 3, reg: gp2load, asm: "MOVWU"}, // load 32-bit word from arg0 + arg1*4, zero-extended to 64-bit, arg2=mem. - {name: "MOVDloadidx8", argLength: 3, reg: gp2load, asm: "MOVD"}, // load 64-bit double-word from arg0 + arg1*8, arg2 = mem. + {name: "MOVHloadidx2", argLength: 3, reg: gp2load, asm: "MOVH", typ: "Int16"}, // load 16-bit half-word from arg0 + arg1*2, sign-extended to 64-bit, arg2=mem. + {name: "MOVHUloadidx2", argLength: 3, reg: gp2load, asm: "MOVHU", typ: "UInt16"}, // load 16-bit half-word from arg0 + arg1*2, zero-extended to 64-bit, arg2=mem. + {name: "MOVWloadidx4", argLength: 3, reg: gp2load, asm: "MOVW", typ: "Int32"}, // load 32-bit word from arg0 + arg1*4, sign-extended to 64-bit, arg2=mem. + {name: "MOVWUloadidx4", argLength: 3, reg: gp2load, asm: "MOVWU", typ: "UInt32"}, // load 32-bit word from arg0 + arg1*4, zero-extended to 64-bit, arg2=mem. + {name: "MOVDloadidx8", argLength: 3, reg: gp2load, asm: "MOVD", typ: "UInt64"}, // load 64-bit double-word from arg0 + arg1*8, arg2 = mem. {name: "MOVBstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVB", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"}, // store 1 byte of arg1 to arg0 + auxInt + aux. arg2=mem. {name: "MOVHstore", argLength: 3, reg: gpstore, aux: "SymOff", asm: "MOVH", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"}, // store 2 bytes of arg1 to arg0 + auxInt + aux. arg2=mem. diff --git a/src/cmd/compile/internal/ssa/gen/ARMOps.go b/src/cmd/compile/internal/ssa/gen/ARMOps.go index 2df9003247267..4e2b0c5a5da97 100644 --- a/src/cmd/compile/internal/ssa/gen/ARMOps.go +++ b/src/cmd/compile/internal/ssa/gen/ARMOps.go @@ -373,21 +373,21 @@ func init() { {name: "MOVFstore", argLength: 3, reg: fpstore, aux: "SymOff", asm: "MOVF", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"}, // store 4 bytes of arg1 to arg0 + auxInt + aux. arg2=mem. {name: "MOVDstore", argLength: 3, reg: fpstore, aux: "SymOff", asm: "MOVD", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"}, // store 8 bytes of arg1 to arg0 + auxInt + aux. arg2=mem. - {name: "MOVWloadidx", argLength: 3, reg: gp2load, asm: "MOVW"}, // load from arg0 + arg1. arg2=mem - {name: "MOVWloadshiftLL", argLength: 3, reg: gp2load, asm: "MOVW", aux: "Int32"}, // load from arg0 + arg1<>auxInt, unsigned shift. arg2=mem - {name: "MOVWloadshiftRA", argLength: 3, reg: gp2load, asm: "MOVW", aux: "Int32"}, // load from arg0 + arg1>>auxInt, signed shift. arg2=mem - {name: "MOVBUloadidx", argLength: 3, reg: gp2load, asm: "MOVBU"}, // load from arg0 + arg1. arg2=mem - {name: "MOVBloadidx", argLength: 3, reg: gp2load, asm: "MOVB"}, // load from arg0 + arg1. arg2=mem - {name: "MOVHUloadidx", argLength: 3, reg: gp2load, asm: "MOVHU"}, // load from arg0 + arg1. arg2=mem - {name: "MOVHloadidx", argLength: 3, reg: gp2load, asm: "MOVH"}, // load from arg0 + arg1. arg2=mem - - {name: "MOVWstoreidx", argLength: 4, reg: gp2store, asm: "MOVW"}, // store arg2 to arg0 + arg1. arg3=mem - {name: "MOVWstoreshiftLL", argLength: 4, reg: gp2store, asm: "MOVW", aux: "Int32"}, // store arg2 to arg0 + arg1<>auxInt, unsigned shift. arg3=mem - {name: "MOVWstoreshiftRA", argLength: 4, reg: gp2store, asm: "MOVW", aux: "Int32"}, // store arg2 to arg0 + arg1>>auxInt, signed shift. arg3=mem - {name: "MOVBstoreidx", argLength: 4, reg: gp2store, asm: "MOVB"}, // store arg2 to arg0 + arg1. arg3=mem - {name: "MOVHstoreidx", argLength: 4, reg: gp2store, asm: "MOVH"}, // store arg2 to arg0 + arg1. arg3=mem + {name: "MOVWloadidx", argLength: 3, reg: gp2load, asm: "MOVW", typ: "UInt32"}, // load from arg0 + arg1. arg2=mem + {name: "MOVWloadshiftLL", argLength: 3, reg: gp2load, asm: "MOVW", aux: "Int32", typ: "UInt32"}, // load from arg0 + arg1<>auxInt, unsigned shift. arg2=mem + {name: "MOVWloadshiftRA", argLength: 3, reg: gp2load, asm: "MOVW", aux: "Int32", typ: "UInt32"}, // load from arg0 + arg1>>auxInt, signed shift. arg2=mem + {name: "MOVBUloadidx", argLength: 3, reg: gp2load, asm: "MOVBU", typ: "UInt8"}, // load from arg0 + arg1. arg2=mem + {name: "MOVBloadidx", argLength: 3, reg: gp2load, asm: "MOVB", typ: "Int8"}, // load from arg0 + arg1. arg2=mem + {name: "MOVHUloadidx", argLength: 3, reg: gp2load, asm: "MOVHU", typ: "UInt16"}, // load from arg0 + arg1. arg2=mem + {name: "MOVHloadidx", argLength: 3, reg: gp2load, asm: "MOVH", typ: "Int16"}, // load from arg0 + arg1. arg2=mem + + {name: "MOVWstoreidx", argLength: 4, reg: gp2store, asm: "MOVW", typ: "Mem"}, // store arg2 to arg0 + arg1. arg3=mem + {name: "MOVWstoreshiftLL", argLength: 4, reg: gp2store, asm: "MOVW", aux: "Int32", typ: "Mem"}, // store arg2 to arg0 + arg1<>auxInt, unsigned shift. arg3=mem + {name: "MOVWstoreshiftRA", argLength: 4, reg: gp2store, asm: "MOVW", aux: "Int32", typ: "Mem"}, // store arg2 to arg0 + arg1>>auxInt, signed shift. arg3=mem + {name: "MOVBstoreidx", argLength: 4, reg: gp2store, asm: "MOVB", typ: "Mem"}, // store arg2 to arg0 + arg1. arg3=mem + {name: "MOVHstoreidx", argLength: 4, reg: gp2store, asm: "MOVH", typ: "Mem"}, // store arg2 to arg0 + arg1. arg3=mem {name: "MOVBreg", argLength: 1, reg: gp11, asm: "MOVBS"}, // move from arg0, sign-extended from byte {name: "MOVBUreg", argLength: 1, reg: gp11, asm: "MOVBU"}, // move from arg0, unsign-extended from byte From 2b69ad0b3c9770b6b67c4057c565d6f4c4444d26 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Tue, 10 Jul 2018 01:48:55 +0000 Subject: [PATCH 0212/1663] cmd/compile: optimize arm's comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The CMP/CMN/TST/TEQ perform similar to SUB/ADD/AND/XOR except the result is abondoned, and only NZCV flags are affected. This CL implements further optimization with them. 1. A micro benchmark test gets more than 9% improvment. TSTTEQ-4 6.99ms ± 0% 6.35ms ± 0% -9.15% (p=0.000 n=33+36) (https://github.com/benshi001/ugo1/blob/master/tstteq2_test.go) 2. The go1 benckmark shows no regression, excluding noise. name old time/op new time/op delta BinaryTree17-4 25.7s ± 1% 25.7s ± 1% ~ (p=0.830 n=40+40) Fannkuch11-4 13.3s ± 0% 13.2s ± 0% -0.65% (p=0.000 n=40+34) FmtFprintfEmpty-4 394ns ± 0% 394ns ± 0% ~ (p=0.819 n=40+40) FmtFprintfString-4 677ns ± 0% 677ns ± 0% +0.06% (p=0.039 n=39+40) FmtFprintfInt-4 707ns ± 0% 706ns ± 0% -0.14% (p=0.000 n=40+39) FmtFprintfIntInt-4 1.04µs ± 0% 1.04µs ± 0% +0.10% (p=0.000 n=29+31) FmtFprintfPrefixedInt-4 1.10µs ± 0% 1.11µs ± 0% +0.65% (p=0.000 n=39+37) FmtFprintfFloat-4 2.27µs ± 0% 2.26µs ± 0% -0.53% (p=0.000 n=39+40) FmtManyArgs-4 3.96µs ± 0% 3.96µs ± 0% +0.10% (p=0.000 n=39+40) GobDecode-4 53.4ms ± 1% 52.8ms ± 2% -1.10% (p=0.000 n=39+39) GobEncode-4 50.3ms ± 3% 50.4ms ± 2% ~ (p=0.089 n=40+39) Gzip-4 2.62s ± 0% 2.64s ± 0% +0.60% (p=0.000 n=40+39) Gunzip-4 312ms ± 0% 312ms ± 0% +0.02% (p=0.030 n=40+39) HTTPClientServer-4 1.01ms ± 7% 0.98ms ± 7% -2.37% (p=0.000 n=40+39) JSONEncode-4 126ms ± 1% 126ms ± 1% -0.38% (p=0.004 n=39+39) JSONDecode-4 423ms ± 0% 426ms ± 2% +0.72% (p=0.001 n=39+40) Mandelbrot200-4 18.4ms ± 0% 18.4ms ± 0% +0.04% (p=0.000 n=38+40) GoParse-4 22.8ms ± 0% 22.6ms ± 0% -0.68% (p=0.000 n=35+40) RegexpMatchEasy0_32-4 699ns ± 0% 704ns ± 0% +0.73% (p=0.000 n=27+40) RegexpMatchEasy0_1K-4 4.27µs ± 0% 4.26µs ± 0% -0.09% (p=0.000 n=35+38) RegexpMatchEasy1_32-4 741ns ± 0% 735ns ± 0% -0.85% (p=0.000 n=40+35) RegexpMatchEasy1_1K-4 5.53µs ± 0% 5.49µs ± 0% -0.69% (p=0.000 n=39+40) RegexpMatchMedium_32-4 1.07µs ± 0% 1.04µs ± 2% -2.34% (p=0.000 n=40+40) RegexpMatchMedium_1K-4 261µs ± 0% 261µs ± 0% -0.16% (p=0.000 n=40+39) RegexpMatchHard_32-4 14.9µs ± 0% 14.9µs ± 0% -0.18% (p=0.000 n=39+40) RegexpMatchHard_1K-4 445µs ± 0% 446µs ± 0% +0.09% (p=0.000 n=36+34) Revcomp-4 41.8ms ± 1% 41.8ms ± 1% ~ (p=0.595 n=39+38) Template-4 530ms ± 1% 528ms ± 1% -0.49% (p=0.000 n=40+40) TimeParse-4 3.39µs ± 0% 3.42µs ± 0% +0.98% (p=0.000 n=36+38) TimeFormat-4 6.12µs ± 0% 6.07µs ± 0% -0.81% (p=0.000 n=34+38) [Geo mean] 384µs 383µs -0.24% name old speed new speed delta GobDecode-4 14.4MB/s ± 1% 14.5MB/s ± 2% +1.11% (p=0.000 n=39+39) GobEncode-4 15.3MB/s ± 3% 15.2MB/s ± 2% ~ (p=0.104 n=40+39) Gzip-4 7.40MB/s ± 1% 7.36MB/s ± 0% -0.60% (p=0.000 n=40+39) Gunzip-4 62.2MB/s ± 0% 62.1MB/s ± 0% -0.02% (p=0.047 n=40+39) JSONEncode-4 15.4MB/s ± 1% 15.4MB/s ± 2% +0.39% (p=0.002 n=39+39) JSONDecode-4 4.59MB/s ± 0% 4.56MB/s ± 2% -0.71% (p=0.000 n=39+40) GoParse-4 2.54MB/s ± 0% 2.56MB/s ± 0% +0.72% (p=0.000 n=26+40) RegexpMatchEasy0_32-4 45.8MB/s ± 0% 45.4MB/s ± 0% -0.75% (p=0.000 n=38+40) RegexpMatchEasy0_1K-4 240MB/s ± 0% 240MB/s ± 0% +0.09% (p=0.000 n=35+38) RegexpMatchEasy1_32-4 43.1MB/s ± 0% 43.5MB/s ± 0% +0.84% (p=0.000 n=40+39) RegexpMatchEasy1_1K-4 185MB/s ± 0% 186MB/s ± 0% +0.69% (p=0.000 n=39+40) RegexpMatchMedium_32-4 936kB/s ± 1% 959kB/s ± 2% +2.38% (p=0.000 n=40+40) RegexpMatchMedium_1K-4 3.92MB/s ± 0% 3.93MB/s ± 0% +0.18% (p=0.000 n=39+40) RegexpMatchHard_32-4 2.15MB/s ± 0% 2.15MB/s ± 0% +0.19% (p=0.000 n=40+40) RegexpMatchHard_1K-4 2.30MB/s ± 0% 2.30MB/s ± 0% ~ (all equal) Revcomp-4 60.8MB/s ± 1% 60.8MB/s ± 1% ~ (p=0.600 n=39+38) Template-4 3.66MB/s ± 1% 3.68MB/s ± 1% +0.46% (p=0.000 n=40+40) [Geo mean] 12.8MB/s 12.8MB/s +0.27% Change-Id: I849161169ecf0876a04b7c1d3990fa8d1435215e Reviewed-on: https://go-review.googlesource.com/122855 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/gen/ARM.rules | 136 + src/cmd/compile/internal/ssa/rewriteARM.go | 4078 +++++++++++++++++++- test/codegen/comparisons.go | 12 + 3 files changed, 4059 insertions(+), 167 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/ARM.rules b/src/cmd/compile/internal/ssa/gen/ARM.rules index e8a3c27c71bea..8cea322295bdb 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM.rules @@ -1408,3 +1408,139 @@ (NE (CMPconst [0] (XORshiftLLreg x y z)) yes no) -> (NE (TEQshiftLLreg x y z) yes no) (NE (CMPconst [0] (XORshiftRLreg x y z)) yes no) -> (NE (TEQshiftRLreg x y z) yes no) (NE (CMPconst [0] (XORshiftRAreg x y z)) yes no) -> (NE (TEQshiftRAreg x y z) yes no) +(LT (CMPconst [0] l:(SUB x y)) yes no) -> (LT (CMP x y) yes no) +(LT (CMPconst [0] (MULS x y a)) yes no) -> (LT (CMP a (MUL x y)) yes no) +(LT (CMPconst [0] l:(SUBconst [c] x)) yes no) -> (LT (CMPconst [c] x) yes no) +(LT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) -> (LT (CMPshiftLL x y [c]) yes no) +(LT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) -> (LT (CMPshiftRL x y [c]) yes no) +(LT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) -> (LT (CMPshiftRA x y [c]) yes no) +(LT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) -> (LT (CMPshiftLLreg x y z) yes no) +(LT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) -> (LT (CMPshiftRLreg x y z) yes no) +(LT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) -> (LT (CMPshiftRAreg x y z) yes no) +(LE (CMPconst [0] l:(SUB x y)) yes no) -> (LE (CMP x y) yes no) +(LE (CMPconst [0] (MULS x y a)) yes no) -> (LE (CMP a (MUL x y)) yes no) +(LE (CMPconst [0] l:(SUBconst [c] x)) yes no) -> (LE (CMPconst [c] x) yes no) +(LE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) -> (LE (CMPshiftLL x y [c]) yes no) +(LE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) -> (LE (CMPshiftRL x y [c]) yes no) +(LE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) -> (LE (CMPshiftRA x y [c]) yes no) +(LE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) -> (LE (CMPshiftLLreg x y z) yes no) +(LE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) -> (LE (CMPshiftRLreg x y z) yes no) +(LE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) -> (LE (CMPshiftRAreg x y z) yes no) +(LT (CMPconst [0] l:(ADD x y)) yes no) -> (LT (CMN x y) yes no) +(LT (CMPconst [0] (MULA x y a)) yes no) -> (LT (CMN a (MUL x y)) yes no) +(LT (CMPconst [0] l:(ADDconst [c] x)) yes no) -> (LT (CMNconst [c] x) yes no) +(LT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) -> (LT (CMNshiftLL x y [c]) yes no) +(LT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) -> (LT (CMNshiftRL x y [c]) yes no) +(LT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) -> (LT (CMNshiftRA x y [c]) yes no) +(LT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) -> (LT (CMNshiftLLreg x y z) yes no) +(LT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) -> (LT (CMNshiftRLreg x y z) yes no) +(LT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) -> (LT (CMNshiftRAreg x y z) yes no) +(LE (CMPconst [0] l:(ADD x y)) yes no) -> (LE (CMN x y) yes no) +(LE (CMPconst [0] (MULA x y a)) yes no) -> (LE (CMN a (MUL x y)) yes no) +(LE (CMPconst [0] l:(ADDconst [c] x)) yes no) -> (LE (CMNconst [c] x) yes no) +(LE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) -> (LE (CMNshiftLL x y [c]) yes no) +(LE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) -> (LE (CMNshiftRL x y [c]) yes no) +(LE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) -> (LE (CMNshiftRA x y [c]) yes no) +(LE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) -> (LE (CMNshiftLLreg x y z) yes no) +(LE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) -> (LE (CMNshiftRLreg x y z) yes no) +(LE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) -> (LE (CMNshiftRAreg x y z) yes no) +(LT (CMPconst [0] l:(AND x y)) yes no) -> (LT (TST x y) yes no) +(LT (CMPconst [0] l:(ANDconst [c] x)) yes no) -> (LT (TSTconst [c] x) yes no) +(LT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) -> (LT (TSTshiftLL x y [c]) yes no) +(LT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) -> (LT (TSTshiftRL x y [c]) yes no) +(LT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) -> (LT (TSTshiftRA x y [c]) yes no) +(LT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) -> (LT (TSTshiftLLreg x y z) yes no) +(LT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) -> (LT (TSTshiftRLreg x y z) yes no) +(LT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) -> (LT (TSTshiftRAreg x y z) yes no) +(LE (CMPconst [0] l:(AND x y)) yes no) -> (LE (TST x y) yes no) +(LE (CMPconst [0] l:(ANDconst [c] x)) yes no) -> (LE (TSTconst [c] x) yes no) +(LE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) -> (LE (TSTshiftLL x y [c]) yes no) +(LE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) -> (LE (TSTshiftRL x y [c]) yes no) +(LE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) -> (LE (TSTshiftRA x y [c]) yes no) +(LE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) -> (LE (TSTshiftLLreg x y z) yes no) +(LE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) -> (LE (TSTshiftRLreg x y z) yes no) +(LE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) -> (LE (TSTshiftRAreg x y z) yes no) +(LT (CMPconst [0] l:(XOR x y)) yes no) -> (LT (TEQ x y) yes no) +(LT (CMPconst [0] l:(XORconst [c] x)) yes no) -> (LT (TEQconst [c] x) yes no) +(LT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) -> (LT (TEQshiftLL x y [c]) yes no) +(LT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) -> (LT (TEQshiftRL x y [c]) yes no) +(LT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) -> (LT (TEQshiftRA x y [c]) yes no) +(LT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) -> (LT (TEQshiftLLreg x y z) yes no) +(LT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) -> (LT (TEQshiftRLreg x y z) yes no) +(LT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) -> (LT (TEQshiftRAreg x y z) yes no) +(LE (CMPconst [0] l:(XOR x y)) yes no) -> (LE (TEQ x y) yes no) +(LE (CMPconst [0] l:(XORconst [c] x)) yes no) -> (LE (TEQconst [c] x) yes no) +(LE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) -> (LE (TEQshiftLL x y [c]) yes no) +(LE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) -> (LE (TEQshiftRL x y [c]) yes no) +(LE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) -> (LE (TEQshiftRA x y [c]) yes no) +(LE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) -> (LE (TEQshiftLLreg x y z) yes no) +(LE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) -> (LE (TEQshiftRLreg x y z) yes no) +(LE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) -> (LE (TEQshiftRAreg x y z) yes no) +(GT (CMPconst [0] l:(SUB x y)) yes no) -> (GT (CMP x y) yes no) +(GT (CMPconst [0] (MULS x y a)) yes no) -> (GT (CMP a (MUL x y)) yes no) +(GT (CMPconst [0] l:(SUBconst [c] x)) yes no) -> (GT (CMPconst [c] x) yes no) +(GT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) -> (GT (CMPshiftLL x y [c]) yes no) +(GT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) -> (GT (CMPshiftRL x y [c]) yes no) +(GT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) -> (GT (CMPshiftRA x y [c]) yes no) +(GT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) -> (GT (CMPshiftLLreg x y z) yes no) +(GT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) -> (GT (CMPshiftRLreg x y z) yes no) +(GT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) -> (GT (CMPshiftRAreg x y z) yes no) +(GE (CMPconst [0] l:(SUB x y)) yes no) -> (GE (CMP x y) yes no) +(GE (CMPconst [0] (MULS x y a)) yes no) -> (GE (CMP a (MUL x y)) yes no) +(GE (CMPconst [0] l:(SUBconst [c] x)) yes no) -> (GE (CMPconst [c] x) yes no) +(GE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) -> (GE (CMPshiftLL x y [c]) yes no) +(GE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) -> (GE (CMPshiftRL x y [c]) yes no) +(GE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) -> (GE (CMPshiftRA x y [c]) yes no) +(GE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) -> (GE (CMPshiftLLreg x y z) yes no) +(GE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) -> (GE (CMPshiftRLreg x y z) yes no) +(GE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) -> (GE (CMPshiftRAreg x y z) yes no) +(GT (CMPconst [0] l:(ADD x y)) yes no) -> (GT (CMN x y) yes no) +(GT (CMPconst [0] l:(ADDconst [c] x)) yes no) -> (GT (CMNconst [c] x) yes no) +(GT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) -> (GT (CMNshiftLL x y [c]) yes no) +(GT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) -> (GT (CMNshiftRL x y [c]) yes no) +(GT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) -> (GT (CMNshiftRA x y [c]) yes no) +(GT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) -> (GT (CMNshiftLLreg x y z) yes no) +(GT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) -> (GT (CMNshiftRLreg x y z) yes no) +(GT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) -> (GT (CMNshiftRAreg x y z) yes no) +(GE (CMPconst [0] l:(ADD x y)) yes no) -> (GE (CMN x y) yes no) +(GE (CMPconst [0] (MULA x y a)) yes no) -> (GE (CMN a (MUL x y)) yes no) +(GE (CMPconst [0] l:(ADDconst [c] x)) yes no) -> (GE (CMNconst [c] x) yes no) +(GE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) -> (GE (CMNshiftLL x y [c]) yes no) +(GE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) -> (GE (CMNshiftRL x y [c]) yes no) +(GE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) -> (GE (CMNshiftRA x y [c]) yes no) +(GE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) -> (GE (CMNshiftLLreg x y z) yes no) +(GE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) -> (GE (CMNshiftRLreg x y z) yes no) +(GE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) -> (GE (CMNshiftRAreg x y z) yes no) +(GT (CMPconst [0] l:(AND x y)) yes no) -> (GT (TST x y) yes no) +(GT (CMPconst [0] (MULA x y a)) yes no) -> (GT (CMN a (MUL x y)) yes no) +(GT (CMPconst [0] l:(ANDconst [c] x)) yes no) -> (GT (TSTconst [c] x) yes no) +(GT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) -> (GT (TSTshiftLL x y [c]) yes no) +(GT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) -> (GT (TSTshiftRL x y [c]) yes no) +(GT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) -> (GT (TSTshiftRA x y [c]) yes no) +(GT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) -> (GT (TSTshiftLLreg x y z) yes no) +(GT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) -> (GT (TSTshiftRLreg x y z) yes no) +(GT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) -> (GT (TSTshiftRAreg x y z) yes no) +(GE (CMPconst [0] l:(AND x y)) yes no) -> (GE (TST x y) yes no) +(GE (CMPconst [0] l:(ANDconst [c] x)) yes no) -> (GE (TSTconst [c] x) yes no) +(GE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) -> (GE (TSTshiftLL x y [c]) yes no) +(GE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) -> (GE (TSTshiftRL x y [c]) yes no) +(GE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) -> (GE (TSTshiftRA x y [c]) yes no) +(GE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) -> (GE (TSTshiftLLreg x y z) yes no) +(GE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) -> (GE (TSTshiftRLreg x y z) yes no) +(GE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) -> (GE (TSTshiftRAreg x y z) yes no) +(GT (CMPconst [0] l:(XOR x y)) yes no) -> (GT (TEQ x y) yes no) +(GT (CMPconst [0] l:(XORconst [c] x)) yes no) -> (GT (TEQconst [c] x) yes no) +(GT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) -> (GT (TEQshiftLL x y [c]) yes no) +(GT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) -> (GT (TEQshiftRL x y [c]) yes no) +(GT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) -> (GT (TEQshiftRA x y [c]) yes no) +(GT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) -> (GT (TEQshiftLLreg x y z) yes no) +(GT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) -> (GT (TEQshiftRLreg x y z) yes no) +(GT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) -> (GT (TEQshiftRAreg x y z) yes no) +(GE (CMPconst [0] l:(XOR x y)) yes no) -> (GE (TEQ x y) yes no) +(GE (CMPconst [0] l:(XORconst [c] x)) yes no) -> (GE (TEQconst [c] x) yes no) +(GE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) -> (GE (TEQshiftLL x y [c]) yes no) +(GE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) -> (GE (TEQshiftRL x y [c]) yes no) +(GE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) -> (GE (TEQshiftRA x y [c]) yes no) +(GE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) -> (GE (TEQshiftLLreg x y z) yes no) +(GE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) -> (GE (TEQshiftRLreg x y z) yes no) +(GE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) -> (GE (TEQshiftRAreg x y z) yes no) diff --git a/src/cmd/compile/internal/ssa/rewriteARM.go b/src/cmd/compile/internal/ssa/rewriteARM.go index e463511f17361..40d8d7f0b3842 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM.go +++ b/src/cmd/compile/internal/ssa/rewriteARM.go @@ -23274,6 +23274,942 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } + // match: (GE (CMPconst [0] l:(SUB x y)) yes no) + // cond: + // result: (GE (CMP x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUB { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] (MULS x y a)) yes no) + // cond: + // result: (GE (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULS { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(SUBconst [c] x)) yes no) + // cond: + // result: (GE (CMPconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) + // cond: + // result: (GE (CMPshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) + // cond: + // result: (GE (CMPshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) + // cond: + // result: (GE (CMPshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) + // cond: + // result: (GE (CMPshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) + // cond: + // result: (GE (CMPshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) + // cond: + // result: (GE (CMPshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ADD x y)) yes no) + // cond: + // result: (GE (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADD { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] (MULA x y a)) yes no) + // cond: + // result: (GE (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULA { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ADDconst [c] x)) yes no) + // cond: + // result: (GE (CMNconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMNconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) + // cond: + // result: (GE (CMNshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) + // cond: + // result: (GE (CMNshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) + // cond: + // result: (GE (CMNshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) + // cond: + // result: (GE (CMNshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) + // cond: + // result: (GE (CMNshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) + // cond: + // result: (GE (CMNshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(AND x y)) yes no) + // cond: + // result: (GE (TST x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMAND { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTST, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ANDconst [c] x)) yes no) + // cond: + // result: (GE (TSTconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTSTconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) + // cond: + // result: (GE (TSTshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) + // cond: + // result: (GE (TSTshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) + // cond: + // result: (GE (TSTshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) + // cond: + // result: (GE (TSTshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) + // cond: + // result: (GE (TSTshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) + // cond: + // result: (GE (TSTshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(XOR x y)) yes no) + // cond: + // result: (GE (TEQ x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXOR { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTEQ, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(XORconst [c] x)) yes no) + // cond: + // result: (GE (TEQconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTEQconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) + // cond: + // result: (GE (TEQshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) + // cond: + // result: (GE (TEQshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) + // cond: + // result: (GE (TEQshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) + // cond: + // result: (GE (TEQshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) + // cond: + // result: (GE (TEQshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) + // cond: + // result: (GE (TEQshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } case BlockARMGT: // match: (GT (FlagEQ) yes no) // cond: @@ -23283,398 +24219,3206 @@ func rewriteBlockARM(b *Block) bool { if v.Op != OpARMFlagEQ { break } - b.Kind = BlockFirst - b.SetControl(nil) + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + b.swapSuccessors() + return true + } + // match: (GT (FlagLT_ULT) yes no) + // cond: + // result: (First nil no yes) + for { + v := b.Control + if v.Op != OpARMFlagLT_ULT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + b.swapSuccessors() + return true + } + // match: (GT (FlagLT_UGT) yes no) + // cond: + // result: (First nil no yes) + for { + v := b.Control + if v.Op != OpARMFlagLT_UGT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + b.swapSuccessors() + return true + } + // match: (GT (FlagGT_ULT) yes no) + // cond: + // result: (First nil yes no) + for { + v := b.Control + if v.Op != OpARMFlagGT_ULT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + return true + } + // match: (GT (FlagGT_UGT) yes no) + // cond: + // result: (First nil yes no) + for { + v := b.Control + if v.Op != OpARMFlagGT_UGT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + return true + } + // match: (GT (InvertFlags cmp) yes no) + // cond: + // result: (LT cmp yes no) + for { + v := b.Control + if v.Op != OpARMInvertFlags { + break + } + cmp := v.Args[0] + b.Kind = BlockARMLT + b.SetControl(cmp) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(SUB x y)) yes no) + // cond: + // result: (GT (CMP x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUB { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] (MULS x y a)) yes no) + // cond: + // result: (GT (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULS { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(SUBconst [c] x)) yes no) + // cond: + // result: (GT (CMPconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) + // cond: + // result: (GT (CMPshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) + // cond: + // result: (GT (CMPshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) + // cond: + // result: (GT (CMPshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) + // cond: + // result: (GT (CMPshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) + // cond: + // result: (GT (CMPshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) + // cond: + // result: (GT (CMPshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ADD x y)) yes no) + // cond: + // result: (GT (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADD { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ADDconst [c] x)) yes no) + // cond: + // result: (GT (CMNconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMNconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) + // cond: + // result: (GT (CMNshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) + // cond: + // result: (GT (CMNshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) + // cond: + // result: (GT (CMNshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) + // cond: + // result: (GT (CMNshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) + // cond: + // result: (GT (CMNshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) + // cond: + // result: (GT (CMNshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(AND x y)) yes no) + // cond: + // result: (GT (TST x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMAND { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTST, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] (MULA x y a)) yes no) + // cond: + // result: (GT (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULA { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ANDconst [c] x)) yes no) + // cond: + // result: (GT (TSTconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTSTconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) + // cond: + // result: (GT (TSTshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) + // cond: + // result: (GT (TSTshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) + // cond: + // result: (GT (TSTshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) + // cond: + // result: (GT (TSTshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) + // cond: + // result: (GT (TSTshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) + // cond: + // result: (GT (TSTshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(XOR x y)) yes no) + // cond: + // result: (GT (TEQ x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXOR { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTEQ, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(XORconst [c] x)) yes no) + // cond: + // result: (GT (TEQconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTEQconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) + // cond: + // result: (GT (TEQshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) + // cond: + // result: (GT (TEQshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) + // cond: + // result: (GT (TEQshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) + // cond: + // result: (GT (TEQshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) + // cond: + // result: (GT (TEQshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) + // cond: + // result: (GT (TEQshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMGT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + case BlockIf: + // match: (If (Equal cc) yes no) + // cond: + // result: (EQ cc yes no) + for { + v := b.Control + if v.Op != OpARMEqual { + break + } + cc := v.Args[0] + b.Kind = BlockARMEQ + b.SetControl(cc) + b.Aux = nil + return true + } + // match: (If (NotEqual cc) yes no) + // cond: + // result: (NE cc yes no) + for { + v := b.Control + if v.Op != OpARMNotEqual { + break + } + cc := v.Args[0] + b.Kind = BlockARMNE + b.SetControl(cc) + b.Aux = nil + return true + } + // match: (If (LessThan cc) yes no) + // cond: + // result: (LT cc yes no) + for { + v := b.Control + if v.Op != OpARMLessThan { + break + } + cc := v.Args[0] + b.Kind = BlockARMLT + b.SetControl(cc) + b.Aux = nil + return true + } + // match: (If (LessThanU cc) yes no) + // cond: + // result: (ULT cc yes no) + for { + v := b.Control + if v.Op != OpARMLessThanU { + break + } + cc := v.Args[0] + b.Kind = BlockARMULT + b.SetControl(cc) + b.Aux = nil + return true + } + // match: (If (LessEqual cc) yes no) + // cond: + // result: (LE cc yes no) + for { + v := b.Control + if v.Op != OpARMLessEqual { + break + } + cc := v.Args[0] + b.Kind = BlockARMLE + b.SetControl(cc) + b.Aux = nil + return true + } + // match: (If (LessEqualU cc) yes no) + // cond: + // result: (ULE cc yes no) + for { + v := b.Control + if v.Op != OpARMLessEqualU { + break + } + cc := v.Args[0] + b.Kind = BlockARMULE + b.SetControl(cc) + b.Aux = nil + return true + } + // match: (If (GreaterThan cc) yes no) + // cond: + // result: (GT cc yes no) + for { + v := b.Control + if v.Op != OpARMGreaterThan { + break + } + cc := v.Args[0] + b.Kind = BlockARMGT + b.SetControl(cc) + b.Aux = nil + return true + } + // match: (If (GreaterThanU cc) yes no) + // cond: + // result: (UGT cc yes no) + for { + v := b.Control + if v.Op != OpARMGreaterThanU { + break + } + cc := v.Args[0] + b.Kind = BlockARMUGT + b.SetControl(cc) + b.Aux = nil + return true + } + // match: (If (GreaterEqual cc) yes no) + // cond: + // result: (GE cc yes no) + for { + v := b.Control + if v.Op != OpARMGreaterEqual { + break + } + cc := v.Args[0] + b.Kind = BlockARMGE + b.SetControl(cc) + b.Aux = nil + return true + } + // match: (If (GreaterEqualU cc) yes no) + // cond: + // result: (UGE cc yes no) + for { + v := b.Control + if v.Op != OpARMGreaterEqualU { + break + } + cc := v.Args[0] + b.Kind = BlockARMUGE + b.SetControl(cc) + b.Aux = nil + return true + } + // match: (If cond yes no) + // cond: + // result: (NE (CMPconst [0] cond) yes no) + for { + v := b.Control + _ = v + cond := b.Control + b.Kind = BlockARMNE + v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) + v0.AuxInt = 0 + v0.AddArg(cond) + b.SetControl(v0) + b.Aux = nil + return true + } + case BlockARMLE: + // match: (LE (FlagEQ) yes no) + // cond: + // result: (First nil yes no) + for { + v := b.Control + if v.Op != OpARMFlagEQ { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + return true + } + // match: (LE (FlagLT_ULT) yes no) + // cond: + // result: (First nil yes no) + for { + v := b.Control + if v.Op != OpARMFlagLT_ULT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + return true + } + // match: (LE (FlagLT_UGT) yes no) + // cond: + // result: (First nil yes no) + for { + v := b.Control + if v.Op != OpARMFlagLT_UGT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + return true + } + // match: (LE (FlagGT_ULT) yes no) + // cond: + // result: (First nil no yes) + for { + v := b.Control + if v.Op != OpARMFlagGT_ULT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + b.swapSuccessors() + return true + } + // match: (LE (FlagGT_UGT) yes no) + // cond: + // result: (First nil no yes) + for { + v := b.Control + if v.Op != OpARMFlagGT_UGT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + b.swapSuccessors() + return true + } + // match: (LE (InvertFlags cmp) yes no) + // cond: + // result: (GE cmp yes no) + for { + v := b.Control + if v.Op != OpARMInvertFlags { + break + } + cmp := v.Args[0] + b.Kind = BlockARMGE + b.SetControl(cmp) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(SUB x y)) yes no) + // cond: + // result: (LE (CMP x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUB { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] (MULS x y a)) yes no) + // cond: + // result: (LE (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULS { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(SUBconst [c] x)) yes no) + // cond: + // result: (LE (CMPconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) + // cond: + // result: (LE (CMPshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) + // cond: + // result: (LE (CMPshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) + // cond: + // result: (LE (CMPshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) + // cond: + // result: (LE (CMPshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) + // cond: + // result: (LE (CMPshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) + // cond: + // result: (LE (CMPshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ADD x y)) yes no) + // cond: + // result: (LE (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADD { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] (MULA x y a)) yes no) + // cond: + // result: (LE (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULA { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ADDconst [c] x)) yes no) + // cond: + // result: (LE (CMNconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMNconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) + // cond: + // result: (LE (CMNshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) + // cond: + // result: (LE (CMNshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) + // cond: + // result: (LE (CMNshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) + // cond: + // result: (LE (CMNshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) + // cond: + // result: (LE (CMNshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) + // cond: + // result: (LE (CMNshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(AND x y)) yes no) + // cond: + // result: (LE (TST x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMAND { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTST, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ANDconst [c] x)) yes no) + // cond: + // result: (LE (TSTconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTSTconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) + // cond: + // result: (LE (TSTshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) + // cond: + // result: (LE (TSTshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) + // cond: + // result: (LE (TSTshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) + // cond: + // result: (LE (TSTshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) + // cond: + // result: (LE (TSTshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) + // cond: + // result: (LE (TSTshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(XOR x y)) yes no) + // cond: + // result: (LE (TEQ x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXOR { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTEQ, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(XORconst [c] x)) yes no) + // cond: + // result: (LE (TEQconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTEQconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) + // cond: + // result: (LE (TEQshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) + // cond: + // result: (LE (TEQshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) + // cond: + // result: (LE (TEQshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) + // cond: + // result: (LE (TEQshiftLLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) + // cond: + // result: (LE (TEQshiftRLreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) + // cond: + // result: (LE (TEQshiftRAreg x y z) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLE + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) + b.Aux = nil + return true + } + case BlockARMLT: + // match: (LT (FlagEQ) yes no) + // cond: + // result: (First nil no yes) + for { + v := b.Control + if v.Op != OpARMFlagEQ { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + b.swapSuccessors() + return true + } + // match: (LT (FlagLT_ULT) yes no) + // cond: + // result: (First nil yes no) + for { + v := b.Control + if v.Op != OpARMFlagLT_ULT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + return true + } + // match: (LT (FlagLT_UGT) yes no) + // cond: + // result: (First nil yes no) + for { + v := b.Control + if v.Op != OpARMFlagLT_UGT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + return true + } + // match: (LT (FlagGT_ULT) yes no) + // cond: + // result: (First nil no yes) + for { + v := b.Control + if v.Op != OpARMFlagGT_ULT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + b.swapSuccessors() + return true + } + // match: (LT (FlagGT_UGT) yes no) + // cond: + // result: (First nil no yes) + for { + v := b.Control + if v.Op != OpARMFlagGT_UGT { + break + } + b.Kind = BlockFirst + b.SetControl(nil) + b.Aux = nil + b.swapSuccessors() + return true + } + // match: (LT (InvertFlags cmp) yes no) + // cond: + // result: (GT cmp yes no) + for { + v := b.Control + if v.Op != OpARMInvertFlags { + break + } + cmp := v.Args[0] + b.Kind = BlockARMGT + b.SetControl(cmp) + b.Aux = nil + return true + } + // match: (LT (CMPconst [0] l:(SUB x y)) yes no) + // cond: + // result: (LT (CMP x y) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUB { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPconst [0] (MULS x y a)) yes no) + // cond: + // result: (LT (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULS { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPconst [0] l:(SUBconst [c] x)) yes no) + // cond: + // result: (LT (CMPconst [c] x) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) + // cond: + // result: (LT (CMPshiftLL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) + // cond: + // result: (LT (CMPshiftRL x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) + // cond: + // result: (LT (CMPshiftRA x y [c]) yes no) + for { + v := b.Control + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil - b.swapSuccessors() return true } - // match: (GT (FlagLT_ULT) yes no) + // match: (LT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) // cond: - // result: (First nil no yes) + // result: (LT (CMPshiftLLreg x y z) yes no) for { v := b.Control - if v.Op != OpARMFlagLT_ULT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil - b.swapSuccessors() return true } - // match: (GT (FlagLT_UGT) yes no) + // match: (LT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) // cond: - // result: (First nil no yes) + // result: (LT (CMPshiftRLreg x y z) yes no) for { v := b.Control - if v.Op != OpARMFlagLT_UGT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil - b.swapSuccessors() return true } - // match: (GT (FlagGT_ULT) yes no) + // match: (LT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) // cond: - // result: (First nil yes no) + // result: (LT (CMPshiftRAreg x y z) yes no) for { v := b.Control - if v.Op != OpARMFlagGT_ULT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMSUBshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMPshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil return true } - // match: (GT (FlagGT_UGT) yes no) + // match: (LT (CMPconst [0] l:(ADD x y)) yes no) // cond: - // result: (First nil yes no) + // result: (LT (CMN x y) yes no) for { v := b.Control - if v.Op != OpARMFlagGT_UGT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADD { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil return true } - // match: (GT (InvertFlags cmp) yes no) + // match: (LT (CMPconst [0] (MULA x y a)) yes no) // cond: - // result: (LT cmp yes no) + // result: (LT (CMN a (MUL x y)) yes no) for { v := b.Control - if v.Op != OpARMInvertFlags { + if v.Op != OpARMCMPconst { break } - cmp := v.Args[0] + if v.AuxInt != 0 { + break + } + v_0 := v.Args[0] + if v_0.Op != OpARMMULA { + break + } + _ = v_0.Args[2] + x := v_0.Args[0] + y := v_0.Args[1] + a := v_0.Args[2] b.Kind = BlockARMLT - b.SetControl(cmp) + v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARMMUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) b.Aux = nil return true } - case BlockIf: - // match: (If (Equal cc) yes no) + // match: (LT (CMPconst [0] l:(ADDconst [c] x)) yes no) // cond: - // result: (EQ cc yes no) + // result: (LT (CMNconst [c] x) yes no) for { v := b.Control - if v.Op != OpARMEqual { + if v.Op != OpARMCMPconst { break } - cc := v.Args[0] - b.Kind = BlockARMEQ - b.SetControl(cc) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMNconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) b.Aux = nil return true } - // match: (If (NotEqual cc) yes no) + // match: (LT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) // cond: - // result: (NE cc yes no) + // result: (LT (CMNshiftLL x y [c]) yes no) for { v := b.Control - if v.Op != OpARMNotEqual { + if v.Op != OpARMCMPconst { break } - cc := v.Args[0] - b.Kind = BlockARMNE - b.SetControl(cc) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil return true } - // match: (If (LessThan cc) yes no) + // match: (LT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) // cond: - // result: (LT cc yes no) + // result: (LT (CMNshiftRL x y [c]) yes no) for { v := b.Control - if v.Op != OpARMLessThan { + if v.Op != OpARMCMPconst { break } - cc := v.Args[0] + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] b.Kind = BlockARMLT - b.SetControl(cc) + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil return true } - // match: (If (LessThanU cc) yes no) + // match: (LT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) // cond: - // result: (ULT cc yes no) + // result: (LT (CMNshiftRA x y [c]) yes no) for { v := b.Control - if v.Op != OpARMLessThanU { + if v.Op != OpARMCMPconst { break } - cc := v.Args[0] - b.Kind = BlockARMULT - b.SetControl(cc) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil return true } - // match: (If (LessEqual cc) yes no) + // match: (LT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) // cond: - // result: (LE cc yes no) + // result: (LT (CMNshiftLLreg x y z) yes no) for { v := b.Control - if v.Op != OpARMLessEqual { + if v.Op != OpARMCMPconst { break } - cc := v.Args[0] - b.Kind = BlockARMLE - b.SetControl(cc) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil return true } - // match: (If (LessEqualU cc) yes no) + // match: (LT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) // cond: - // result: (ULE cc yes no) + // result: (LT (CMNshiftRLreg x y z) yes no) for { v := b.Control - if v.Op != OpARMLessEqualU { + if v.Op != OpARMCMPconst { break } - cc := v.Args[0] - b.Kind = BlockARMULE - b.SetControl(cc) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil return true } - // match: (If (GreaterThan cc) yes no) + // match: (LT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) // cond: - // result: (GT cc yes no) + // result: (LT (CMNshiftRAreg x y z) yes no) for { v := b.Control - if v.Op != OpARMGreaterThan { + if v.Op != OpARMCMPconst { break } - cc := v.Args[0] - b.Kind = BlockARMGT - b.SetControl(cc) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMADDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMCMNshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil return true } - // match: (If (GreaterThanU cc) yes no) + // match: (LT (CMPconst [0] l:(AND x y)) yes no) // cond: - // result: (UGT cc yes no) + // result: (LT (TST x y) yes no) for { v := b.Control - if v.Op != OpARMGreaterThanU { + if v.Op != OpARMCMPconst { break } - cc := v.Args[0] - b.Kind = BlockARMUGT - b.SetControl(cc) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMAND { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTST, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil return true } - // match: (If (GreaterEqual cc) yes no) + // match: (LT (CMPconst [0] l:(ANDconst [c] x)) yes no) // cond: - // result: (GE cc yes no) + // result: (LT (TSTconst [c] x) yes no) for { v := b.Control - if v.Op != OpARMGreaterEqual { + if v.Op != OpARMCMPconst { break } - cc := v.Args[0] - b.Kind = BlockARMGE - b.SetControl(cc) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTSTconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) b.Aux = nil return true } - // match: (If (GreaterEqualU cc) yes no) + // match: (LT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) // cond: - // result: (UGE cc yes no) + // result: (LT (TSTshiftLL x y [c]) yes no) for { v := b.Control - if v.Op != OpARMGreaterEqualU { + if v.Op != OpARMCMPconst { break } - cc := v.Args[0] - b.Kind = BlockARMUGE - b.SetControl(cc) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil return true } - // match: (If cond yes no) + // match: (LT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) // cond: - // result: (NE (CMPconst [0] cond) yes no) + // result: (LT (TSTshiftRL x y [c]) yes no) for { v := b.Control - _ = v - cond := b.Control - b.Kind = BlockARMNE - v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) - v0.AuxInt = 0 - v0.AddArg(cond) + if v.Op != OpARMCMPconst { + break + } + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) b.SetControl(v0) b.Aux = nil return true } - case BlockARMLE: - // match: (LE (FlagEQ) yes no) + // match: (LT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) // cond: - // result: (First nil yes no) + // result: (LT (TSTshiftRA x y [c]) yes no) for { v := b.Control - if v.Op != OpARMFlagEQ { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil return true } - // match: (LE (FlagLT_ULT) yes no) + // match: (LT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) // cond: - // result: (First nil yes no) + // result: (LT (TSTshiftLLreg x y z) yes no) for { v := b.Control - if v.Op != OpARMFlagLT_ULT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil return true } - // match: (LE (FlagLT_UGT) yes no) + // match: (LT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) // cond: - // result: (First nil yes no) + // result: (LT (TSTshiftRLreg x y z) yes no) for { v := b.Control - if v.Op != OpARMFlagLT_UGT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil return true } - // match: (LE (FlagGT_ULT) yes no) + // match: (LT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) // cond: - // result: (First nil no yes) + // result: (LT (TSTshiftRAreg x y z) yes no) for { v := b.Control - if v.Op != OpARMFlagGT_ULT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMANDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTSTshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil - b.swapSuccessors() return true } - // match: (LE (FlagGT_UGT) yes no) + // match: (LT (CMPconst [0] l:(XOR x y)) yes no) // cond: - // result: (First nil no yes) + // result: (LT (TEQ x y) yes no) for { v := b.Control - if v.Op != OpARMFlagGT_UGT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXOR { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTEQ, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil - b.swapSuccessors() return true } - // match: (LE (InvertFlags cmp) yes no) + // match: (LT (CMPconst [0] l:(XORconst [c] x)) yes no) // cond: - // result: (GE cmp yes no) + // result: (LT (TEQconst [c] x) yes no) for { v := b.Control - if v.Op != OpARMInvertFlags { + if v.Op != OpARMCMPconst { break } - cmp := v.Args[0] - b.Kind = BlockARMGE - b.SetControl(cmp) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORconst { + break + } + c := l.AuxInt + x := l.Args[0] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTEQconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + b.SetControl(v0) b.Aux = nil return true } - case BlockARMLT: - // match: (LT (FlagEQ) yes no) + // match: (LT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) // cond: - // result: (First nil no yes) + // result: (LT (TEQshiftLL x y [c]) yes no) for { v := b.Control - if v.Op != OpARMFlagEQ { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil - b.swapSuccessors() return true } - // match: (LT (FlagLT_ULT) yes no) + // match: (LT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) // cond: - // result: (First nil yes no) + // result: (LT (TEQshiftRL x y [c]) yes no) for { v := b.Control - if v.Op != OpARMFlagLT_ULT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil return true } - // match: (LT (FlagLT_UGT) yes no) + // match: (LT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) // cond: - // result: (First nil yes no) + // result: (LT (TEQshiftRA x y [c]) yes no) for { v := b.Control - if v.Op != OpARMFlagLT_UGT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) b.Aux = nil return true } - // match: (LT (FlagGT_ULT) yes no) + // match: (LT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) // cond: - // result: (First nil no yes) + // result: (LT (TEQshiftLLreg x y z) yes no) for { v := b.Control - if v.Op != OpARMFlagGT_ULT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftLLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil - b.swapSuccessors() return true } - // match: (LT (FlagGT_UGT) yes no) + // match: (LT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) // cond: - // result: (First nil no yes) + // result: (LT (TEQshiftRLreg x y z) yes no) for { v := b.Control - if v.Op != OpARMFlagGT_UGT { + if v.Op != OpARMCMPconst { break } - b.Kind = BlockFirst - b.SetControl(nil) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRLreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil - b.swapSuccessors() return true } - // match: (LT (InvertFlags cmp) yes no) + // match: (LT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) // cond: - // result: (GT cmp yes no) + // result: (LT (TEQshiftRAreg x y z) yes no) for { v := b.Control - if v.Op != OpARMInvertFlags { + if v.Op != OpARMCMPconst { break } - cmp := v.Args[0] - b.Kind = BlockARMGT - b.SetControl(cmp) + if v.AuxInt != 0 { + break + } + l := v.Args[0] + if l.Op != OpARMXORshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + b.Kind = BlockARMLT + v0 := b.NewValue0(v.Pos, OpARMTEQshiftRAreg, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + v0.AddArg(z) + b.SetControl(v0) b.Aux = nil return true } diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go index ebd75d85d9178..22d06363ba182 100644 --- a/test/codegen/comparisons.go +++ b/test/codegen/comparisons.go @@ -157,3 +157,15 @@ func CmpZero4(a int64, ptr *int) { *ptr = 0 } } + +func CmpToZero(a, b int32) int32 { + if a&b < 0 { // arm:`TST`,-`AND` + return 1 + } else if a+b < 0 { // arm:`CMN`,-`ADD` + return 2 + } else if a^b < 0 { // arm:`TEQ`,-`XOR` + return 3 + } else { + return 0 + } +} From be94dac4e945a2921b116761e41f1c22f0af2add Mon Sep 17 00:00:00 2001 From: Guoliang Wang Date: Tue, 28 Aug 2018 01:03:37 +0000 Subject: [PATCH 0213/1663] os: add ExitCode method to ProcessState Fixes #26539 Change-Id: I6d403c1bbb552e1f1bdcc09a7ccd60b50617e0fc GitHub-Last-Rev: 0b5262df5d99504523fd7a4665cb70a3cc6b0a09 GitHub-Pull-Request: golang/go#26544 Reviewed-on: https://go-review.googlesource.com/125443 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/os/exec/exec_test.go | 43 ++++++++++++++++++++++++++++++++++++++++ src/os/exec_plan9.go | 10 ++++++++++ src/os/exec_posix.go | 10 ++++++++++ 3 files changed, 63 insertions(+) diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index 7bb230806f95a..f0bba11c5a38a 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -168,6 +168,49 @@ func TestExitStatus(t *testing.T) { } } +func TestExitCode(t *testing.T) { + // Test that exit code are returned correctly + cmd := helperCommand(t, "exit", "42") + cmd.Run() + want := 42 + got := cmd.ProcessState.ExitCode() + if want != got { + t.Errorf("ExitCode got %d, want %d", got, want) + } + + cmd = helperCommand(t, "/no-exist-executable") + cmd.Run() + want = 2 + got = cmd.ProcessState.ExitCode() + if want != got { + t.Errorf("ExitCode got %d, want %d", got, want) + } + + cmd = helperCommand(t, "exit", "255") + cmd.Run() + want = 255 + got = cmd.ProcessState.ExitCode() + if want != got { + t.Errorf("ExitCode got %d, want %d", got, want) + } + + cmd = helperCommand(t, "cat") + cmd.Run() + want = 0 + got = cmd.ProcessState.ExitCode() + if want != got { + t.Errorf("ExitCode got %d, want %d", got, want) + } + + // Test when command does not call Run(). + cmd = helperCommand(t, "cat") + want = -1 + got = cmd.ProcessState.ExitCode() + if want != got { + t.Errorf("ExitCode got %d, want %d", got, want) + } +} + func TestPipes(t *testing.T) { check := func(what string, err error) { if err != nil { diff --git a/src/os/exec_plan9.go b/src/os/exec_plan9.go index 6b4d28c93da5f..bab16ccad34cc 100644 --- a/src/os/exec_plan9.go +++ b/src/os/exec_plan9.go @@ -136,3 +136,13 @@ func (p *ProcessState) String() string { } return "exit status: " + p.status.Msg } + +// ExitCode returns the exit code of the exited process, or -1 +// if the process hasn't exited or was terminated by a signal. +func (p *ProcessState) ExitCode() int { + // return -1 if the process hasn't started. + if p == nil { + return -1 + } + return p.status.ExitStatus() +} diff --git a/src/os/exec_posix.go b/src/os/exec_posix.go index ec5cf33236068..e837e1c4d998f 100644 --- a/src/os/exec_posix.go +++ b/src/os/exec_posix.go @@ -106,3 +106,13 @@ func (p *ProcessState) String() string { } return res } + +// ExitCode returns the exit code of the exited process, or -1 +// if the process hasn't exited or was terminated by a signal. +func (p *ProcessState) ExitCode() int { + // return -1 if the process hasn't started. + if p == nil { + return -1 + } + return p.status.ExitStatus() +} From 3ca3e89bb6cd158f16600fd793f8544046216330 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Wed, 18 Jul 2018 09:31:35 +0000 Subject: [PATCH 0214/1663] cmd/compile: optimize arm64 with indexed FP load/store MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The FP load/store on arm64 have register indexed forms. And this CL implements this optimization. 1. The total size of pkg/android_arm64 (excluding cmd/compile) decreases about 400 bytes. 2. There is no regression in the go1 benchmark, the test case GobEncode even gets slight improvement, excluding noise. name old time/op new time/op delta BinaryTree17-4 19.0s ± 0% 19.0s ± 1% ~ (p=0.817 n=29+29) Fannkuch11-4 9.94s ± 0% 9.95s ± 0% +0.03% (p=0.010 n=24+30) FmtFprintfEmpty-4 233ns ± 0% 233ns ± 0% ~ (all equal) FmtFprintfString-4 427ns ± 0% 427ns ± 0% ~ (p=0.649 n=30+30) FmtFprintfInt-4 471ns ± 0% 471ns ± 0% ~ (all equal) FmtFprintfIntInt-4 730ns ± 0% 730ns ± 0% ~ (all equal) FmtFprintfPrefixedInt-4 889ns ± 0% 889ns ± 0% ~ (all equal) FmtFprintfFloat-4 1.21µs ± 0% 1.21µs ± 0% +0.04% (p=0.012 n=20+30) FmtManyArgs-4 2.99µs ± 0% 2.99µs ± 0% ~ (p=0.651 n=29+29) GobDecode-4 42.4ms ± 1% 42.3ms ± 1% -0.27% (p=0.001 n=29+28) GobEncode-4 37.8ms ±11% 36.0ms ± 0% -4.67% (p=0.000 n=30+26) Gzip-4 1.98s ± 1% 1.96s ± 1% -1.26% (p=0.000 n=30+30) Gunzip-4 175ms ± 0% 175ms ± 0% ~ (p=0.988 n=29+29) HTTPClientServer-4 854µs ± 5% 860µs ± 5% ~ (p=0.236 n=28+29) JSONEncode-4 88.8ms ± 0% 87.9ms ± 0% -1.00% (p=0.000 n=24+26) JSONDecode-4 390ms ± 1% 392ms ± 2% +0.48% (p=0.025 n=30+30) Mandelbrot200-4 19.5ms ± 0% 19.5ms ± 0% ~ (p=0.894 n=24+29) GoParse-4 20.3ms ± 0% 20.1ms ± 1% -0.94% (p=0.000 n=27+26) RegexpMatchEasy0_32-4 451ns ± 0% 451ns ± 0% ~ (p=0.578 n=30+30) RegexpMatchEasy0_1K-4 1.63µs ± 0% 1.63µs ± 0% ~ (p=0.298 n=30+28) RegexpMatchEasy1_32-4 431ns ± 0% 434ns ± 0% +0.67% (p=0.000 n=30+29) RegexpMatchEasy1_1K-4 2.60µs ± 0% 2.64µs ± 0% +1.36% (p=0.000 n=28+26) RegexpMatchMedium_32-4 744ns ± 0% 744ns ± 0% ~ (p=0.474 n=29+29) RegexpMatchMedium_1K-4 223µs ± 0% 223µs ± 0% -0.08% (p=0.038 n=26+30) RegexpMatchHard_32-4 12.2µs ± 0% 12.3µs ± 0% +0.27% (p=0.000 n=29+30) RegexpMatchHard_1K-4 373µs ± 0% 373µs ± 0% ~ (p=0.219 n=29+28) Revcomp-4 2.84s ± 0% 2.84s ± 0% ~ (p=0.130 n=28+28) Template-4 394ms ± 1% 392ms ± 1% -0.52% (p=0.001 n=30+30) TimeParse-4 1.93µs ± 0% 1.93µs ± 0% ~ (p=0.587 n=29+30) TimeFormat-4 2.00µs ± 0% 2.00µs ± 0% +0.07% (p=0.001 n=28+27) [Geo mean] 306µs 305µs -0.17% name old speed new speed delta GobDecode-4 18.1MB/s ± 1% 18.2MB/s ± 1% +0.27% (p=0.001 n=29+28) GobEncode-4 20.3MB/s ±10% 21.3MB/s ± 0% +4.64% (p=0.000 n=30+26) Gzip-4 9.79MB/s ± 1% 9.91MB/s ± 1% +1.28% (p=0.000 n=30+30) Gunzip-4 111MB/s ± 0% 111MB/s ± 0% ~ (p=0.988 n=29+29) JSONEncode-4 21.8MB/s ± 0% 22.1MB/s ± 0% +1.02% (p=0.000 n=24+26) JSONDecode-4 4.97MB/s ± 1% 4.95MB/s ± 2% -0.45% (p=0.031 n=30+30) GoParse-4 2.85MB/s ± 1% 2.88MB/s ± 1% +1.03% (p=0.000 n=30+26) RegexpMatchEasy0_32-4 70.9MB/s ± 0% 70.9MB/s ± 0% ~ (p=0.904 n=29+28) RegexpMatchEasy0_1K-4 627MB/s ± 0% 627MB/s ± 0% ~ (p=0.156 n=30+30) RegexpMatchEasy1_32-4 74.2MB/s ± 0% 73.7MB/s ± 0% -0.67% (p=0.000 n=30+29) RegexpMatchEasy1_1K-4 393MB/s ± 0% 388MB/s ± 0% -1.34% (p=0.000 n=28+26) RegexpMatchMedium_32-4 1.34MB/s ± 0% 1.34MB/s ± 0% ~ (all equal) RegexpMatchMedium_1K-4 4.59MB/s ± 0% 4.59MB/s ± 0% +0.07% (p=0.035 n=25+30) RegexpMatchHard_32-4 2.61MB/s ± 0% 2.61MB/s ± 0% -0.11% (p=0.002 n=28+30) RegexpMatchHard_1K-4 2.75MB/s ± 0% 2.75MB/s ± 0% +0.15% (p=0.001 n=30+24) Revcomp-4 89.4MB/s ± 0% 89.4MB/s ± 0% ~ (p=0.140 n=28+28) Template-4 4.93MB/s ± 1% 4.95MB/s ± 1% +0.51% (p=0.001 n=30+30) [Geo mean] 18.4MB/s 18.4MB/s +0.37% Change-Id: I9a6b521a971b21cfb51064e8e9b853cef8a1d071 Reviewed-on: https://go-review.googlesource.com/124636 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/arm64/ssa.go | 4 + src/cmd/compile/internal/ssa/gen/ARM64.rules | 12 + src/cmd/compile/internal/ssa/gen/ARM64Ops.go | 28 +- src/cmd/compile/internal/ssa/opGen.go | 56 ++++ src/cmd/compile/internal/ssa/rewriteARM64.go | 272 +++++++++++++++++++ test/codegen/floats.go | 10 + 6 files changed, 371 insertions(+), 11 deletions(-) diff --git a/src/cmd/compile/internal/arm64/ssa.go b/src/cmd/compile/internal/arm64/ssa.go index c396ba06d1a5a..3712a73eb5f4e 100644 --- a/src/cmd/compile/internal/arm64/ssa.go +++ b/src/cmd/compile/internal/arm64/ssa.go @@ -369,6 +369,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ssa.OpARM64MOVWloadidx, ssa.OpARM64MOVWUloadidx, ssa.OpARM64MOVDloadidx, + ssa.OpARM64FMOVSloadidx, + ssa.OpARM64FMOVDloadidx, ssa.OpARM64MOVHloadidx2, ssa.OpARM64MOVHUloadidx2, ssa.OpARM64MOVWloadidx4, @@ -404,6 +406,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ssa.OpARM64MOVHstoreidx, ssa.OpARM64MOVWstoreidx, ssa.OpARM64MOVDstoreidx, + ssa.OpARM64FMOVSstoreidx, + ssa.OpARM64FMOVDstoreidx, ssa.OpARM64MOVHstoreidx2, ssa.OpARM64MOVWstoreidx4, ssa.OpARM64MOVDstoreidx8: diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index 4c5f8c75024d9..d20780681920b 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -650,6 +650,8 @@ (MOVHload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil -> (MOVHloadidx ptr idx mem) (MOVBUload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil -> (MOVBUloadidx ptr idx mem) (MOVBload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil -> (MOVBloadidx ptr idx mem) +(FMOVSload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil -> (FMOVSloadidx ptr idx mem) +(FMOVDload [off] {sym} (ADD ptr idx) mem) && off == 0 && sym == nil -> (FMOVDloadidx ptr idx mem) (MOVDloadidx ptr (MOVDconst [c]) mem) -> (MOVDload [c] ptr mem) (MOVDloadidx (MOVDconst [c]) ptr mem) -> (MOVDload [c] ptr mem) (MOVWUloadidx ptr (MOVDconst [c]) mem) -> (MOVWUload [c] ptr mem) @@ -664,6 +666,10 @@ (MOVBUloadidx (MOVDconst [c]) ptr mem) -> (MOVBUload [c] ptr mem) (MOVBloadidx ptr (MOVDconst [c]) mem) -> (MOVBload [c] ptr mem) (MOVBloadidx (MOVDconst [c]) ptr mem) -> (MOVBload [c] ptr mem) +(FMOVSloadidx ptr (MOVDconst [c]) mem) -> (FMOVSload [c] ptr mem) +(FMOVSloadidx (MOVDconst [c]) ptr mem) -> (FMOVSload [c] ptr mem) +(FMOVDloadidx ptr (MOVDconst [c]) mem) -> (FMOVDload [c] ptr mem) +(FMOVDloadidx (MOVDconst [c]) ptr mem) -> (FMOVDload [c] ptr mem) // shifted register indexed load (MOVDload [off] {sym} (ADDshiftLL [3] ptr idx) mem) && off == 0 && sym == nil -> (MOVDloadidx8 ptr idx mem) @@ -731,6 +737,8 @@ (MOVWstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil -> (MOVWstoreidx ptr idx val mem) (MOVHstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil -> (MOVHstoreidx ptr idx val mem) (MOVBstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil -> (MOVBstoreidx ptr idx val mem) +(FMOVDstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil -> (FMOVDstoreidx ptr idx val mem) +(FMOVSstore [off] {sym} (ADD ptr idx) val mem) && off == 0 && sym == nil -> (FMOVSstoreidx ptr idx val mem) (MOVDstoreidx ptr (MOVDconst [c]) val mem) -> (MOVDstore [c] ptr val mem) (MOVDstoreidx (MOVDconst [c]) idx val mem) -> (MOVDstore [c] idx val mem) (MOVWstoreidx ptr (MOVDconst [c]) val mem) -> (MOVWstore [c] ptr val mem) @@ -739,6 +747,10 @@ (MOVHstoreidx (MOVDconst [c]) idx val mem) -> (MOVHstore [c] idx val mem) (MOVBstoreidx ptr (MOVDconst [c]) val mem) -> (MOVBstore [c] ptr val mem) (MOVBstoreidx (MOVDconst [c]) idx val mem) -> (MOVBstore [c] idx val mem) +(FMOVDstoreidx ptr (MOVDconst [c]) val mem) -> (FMOVDstore [c] ptr val mem) +(FMOVDstoreidx (MOVDconst [c]) idx val mem) -> (FMOVDstore [c] idx val mem) +(FMOVSstoreidx ptr (MOVDconst [c]) val mem) -> (FMOVSstore [c] ptr val mem) +(FMOVSstoreidx (MOVDconst [c]) idx val mem) -> (FMOVSstore [c] idx val mem) // shifted register indexed store (MOVDstore [off] {sym} (ADDshiftLL [3] ptr idx) val mem) && off == 0 && sym == nil -> (MOVDstoreidx8 ptr idx val mem) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go index 648d5a59a6093..96f2ac3ceb37f 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go @@ -158,7 +158,9 @@ func init() { fp31 = regInfo{inputs: []regMask{fp, fp, fp}, outputs: []regMask{fp}} fp2flags = regInfo{inputs: []regMask{fp, fp}} fpload = regInfo{inputs: []regMask{gpspsbg}, outputs: []regMask{fp}} + fp2load = regInfo{inputs: []regMask{gpspsbg, gpg}, outputs: []regMask{fp}} fpstore = regInfo{inputs: []regMask{gpspsbg, fp}} + fpstore2 = regInfo{inputs: []regMask{gpspsbg, gpg, fp}} readflags = regInfo{inputs: nil, outputs: []regMask{gp}} ) ops := []opData{ @@ -324,13 +326,15 @@ func init() { {name: "FMOVDload", argLength: 2, reg: fpload, aux: "SymOff", asm: "FMOVD", typ: "Float64", faultOnNilArg0: true, symEffect: "Read"}, // load from arg0 + auxInt + aux. arg1=mem. // register indexed load - {name: "MOVDloadidx", argLength: 3, reg: gp2load, asm: "MOVD", typ: "UInt64"}, // load 64-bit dword from arg0 + arg1, arg2 = mem. - {name: "MOVWloadidx", argLength: 3, reg: gp2load, asm: "MOVW", typ: "Int32"}, // load 32-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. - {name: "MOVWUloadidx", argLength: 3, reg: gp2load, asm: "MOVWU", typ: "UInt32"}, // load 32-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. - {name: "MOVHloadidx", argLength: 3, reg: gp2load, asm: "MOVH", typ: "Int16"}, // load 16-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. - {name: "MOVHUloadidx", argLength: 3, reg: gp2load, asm: "MOVHU", typ: "UInt16"}, // load 16-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. - {name: "MOVBloadidx", argLength: 3, reg: gp2load, asm: "MOVB", typ: "Int8"}, // load 8-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. - {name: "MOVBUloadidx", argLength: 3, reg: gp2load, asm: "MOVBU", typ: "UInt8"}, // load 8-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. + {name: "MOVDloadidx", argLength: 3, reg: gp2load, asm: "MOVD", typ: "UInt64"}, // load 64-bit dword from arg0 + arg1, arg2 = mem. + {name: "MOVWloadidx", argLength: 3, reg: gp2load, asm: "MOVW", typ: "Int32"}, // load 32-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. + {name: "MOVWUloadidx", argLength: 3, reg: gp2load, asm: "MOVWU", typ: "UInt32"}, // load 32-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. + {name: "MOVHloadidx", argLength: 3, reg: gp2load, asm: "MOVH", typ: "Int16"}, // load 16-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. + {name: "MOVHUloadidx", argLength: 3, reg: gp2load, asm: "MOVHU", typ: "UInt16"}, // load 16-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. + {name: "MOVBloadidx", argLength: 3, reg: gp2load, asm: "MOVB", typ: "Int8"}, // load 8-bit word from arg0 + arg1, sign-extended to 64-bit, arg2=mem. + {name: "MOVBUloadidx", argLength: 3, reg: gp2load, asm: "MOVBU", typ: "UInt8"}, // load 8-bit word from arg0 + arg1, zero-extended to 64-bit, arg2=mem. + {name: "FMOVSloadidx", argLength: 3, reg: fp2load, asm: "FMOVS", typ: "Float32"}, // load 32-bit float from arg0 + arg1, arg2=mem. + {name: "FMOVDloadidx", argLength: 3, reg: fp2load, asm: "FMOVD", typ: "Float64"}, // load 64-bit float from arg0 + arg1, arg2=mem. // shifted register indexed load {name: "MOVHloadidx2", argLength: 3, reg: gp2load, asm: "MOVH", typ: "Int16"}, // load 16-bit half-word from arg0 + arg1*2, sign-extended to 64-bit, arg2=mem. @@ -348,10 +352,12 @@ func init() { {name: "FMOVDstore", argLength: 3, reg: fpstore, aux: "SymOff", asm: "FMOVD", typ: "Mem", faultOnNilArg0: true, symEffect: "Write"}, // store 8 bytes of arg1 to arg0 + auxInt + aux. arg2=mem. // register indexed store - {name: "MOVBstoreidx", argLength: 4, reg: gpstore2, asm: "MOVB", typ: "Mem"}, // store 1 byte of arg2 to arg0 + arg1, arg3 = mem. - {name: "MOVHstoreidx", argLength: 4, reg: gpstore2, asm: "MOVH", typ: "Mem"}, // store 2 bytes of arg2 to arg0 + arg1, arg3 = mem. - {name: "MOVWstoreidx", argLength: 4, reg: gpstore2, asm: "MOVW", typ: "Mem"}, // store 4 bytes of arg2 to arg0 + arg1, arg3 = mem. - {name: "MOVDstoreidx", argLength: 4, reg: gpstore2, asm: "MOVD", typ: "Mem"}, // store 8 bytes of arg2 to arg0 + arg1, arg3 = mem. + {name: "MOVBstoreidx", argLength: 4, reg: gpstore2, asm: "MOVB", typ: "Mem"}, // store 1 byte of arg2 to arg0 + arg1, arg3 = mem. + {name: "MOVHstoreidx", argLength: 4, reg: gpstore2, asm: "MOVH", typ: "Mem"}, // store 2 bytes of arg2 to arg0 + arg1, arg3 = mem. + {name: "MOVWstoreidx", argLength: 4, reg: gpstore2, asm: "MOVW", typ: "Mem"}, // store 4 bytes of arg2 to arg0 + arg1, arg3 = mem. + {name: "MOVDstoreidx", argLength: 4, reg: gpstore2, asm: "MOVD", typ: "Mem"}, // store 8 bytes of arg2 to arg0 + arg1, arg3 = mem. + {name: "FMOVSstoreidx", argLength: 4, reg: fpstore2, asm: "FMOVS", typ: "Mem"}, // store 32-bit float of arg2 to arg0 + arg1, arg3=mem. + {name: "FMOVDstoreidx", argLength: 4, reg: fpstore2, asm: "FMOVD", typ: "Mem"}, // store 64-bit float of arg2 to arg0 + arg1, arg3=mem. // shifted register indexed store {name: "MOVHstoreidx2", argLength: 4, reg: gpstore2, asm: "MOVH", typ: "Mem"}, // store 2 bytes of arg2 to arg0 + arg1*2, arg3 = mem. diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 374949c60231b..b960d96ec74be 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -1206,6 +1206,8 @@ const ( OpARM64MOVHUloadidx OpARM64MOVBloadidx OpARM64MOVBUloadidx + OpARM64FMOVSloadidx + OpARM64FMOVDloadidx OpARM64MOVHloadidx2 OpARM64MOVHUloadidx2 OpARM64MOVWloadidx4 @@ -1222,6 +1224,8 @@ const ( OpARM64MOVHstoreidx OpARM64MOVWstoreidx OpARM64MOVDstoreidx + OpARM64FMOVSstoreidx + OpARM64FMOVDstoreidx OpARM64MOVHstoreidx2 OpARM64MOVWstoreidx4 OpARM64MOVDstoreidx8 @@ -16016,6 +16020,34 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "FMOVSloadidx", + argLen: 3, + asm: arm64.AFMOVS, + reg: regInfo{ + inputs: []inputInfo{ + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {0, 9223372038733561855}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 SP SB + }, + outputs: []outputInfo{ + {0, 9223372034707292160}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 + }, + }, + }, + { + name: "FMOVDloadidx", + argLen: 3, + asm: arm64.AFMOVD, + reg: regInfo{ + inputs: []inputInfo{ + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {0, 9223372038733561855}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 SP SB + }, + outputs: []outputInfo{ + {0, 9223372034707292160}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 + }, + }, + }, { name: "MOVHloadidx2", argLen: 3, @@ -16233,6 +16265,30 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "FMOVSstoreidx", + argLen: 4, + asm: arm64.AFMOVS, + reg: regInfo{ + inputs: []inputInfo{ + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {0, 9223372038733561855}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 SP SB + {2, 9223372034707292160}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 + }, + }, + }, + { + name: "FMOVDstoreidx", + argLen: 4, + asm: arm64.AFMOVD, + reg: regInfo{ + inputs: []inputInfo{ + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {0, 9223372038733561855}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 SP SB + {2, 9223372034707292160}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 + }, + }, + }, { name: "MOVHstoreidx2", argLen: 4, diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index 0715a5347de22..fc93273f361a8 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -89,12 +89,20 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64FMOVDgpfp_0(v) case OpARM64FMOVDload: return rewriteValueARM64_OpARM64FMOVDload_0(v) + case OpARM64FMOVDloadidx: + return rewriteValueARM64_OpARM64FMOVDloadidx_0(v) case OpARM64FMOVDstore: return rewriteValueARM64_OpARM64FMOVDstore_0(v) + case OpARM64FMOVDstoreidx: + return rewriteValueARM64_OpARM64FMOVDstoreidx_0(v) case OpARM64FMOVSload: return rewriteValueARM64_OpARM64FMOVSload_0(v) + case OpARM64FMOVSloadidx: + return rewriteValueARM64_OpARM64FMOVSloadidx_0(v) case OpARM64FMOVSstore: return rewriteValueARM64_OpARM64FMOVSstore_0(v) + case OpARM64FMOVSstoreidx: + return rewriteValueARM64_OpARM64FMOVSstoreidx_0(v) case OpARM64FMULD: return rewriteValueARM64_OpARM64FMULD_0(v) case OpARM64FMULS: @@ -3771,6 +3779,30 @@ func rewriteValueARM64_OpARM64FMOVDload_0(v *Value) bool { v.AddArg(mem) return true } + // match: (FMOVDload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (FMOVDloadidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64FMOVDloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } // match: (FMOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) // result: (FMOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) @@ -3798,6 +3830,45 @@ func rewriteValueARM64_OpARM64FMOVDload_0(v *Value) bool { } return false } +func rewriteValueARM64_OpARM64FMOVDloadidx_0(v *Value) bool { + // match: (FMOVDloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (FMOVDload [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64FMOVDload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (FMOVDloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (FMOVDload [c] ptr mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64FMOVDload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} func rewriteValueARM64_OpARM64FMOVDstore_0(v *Value) bool { b := v.Block _ = b @@ -3847,6 +3918,32 @@ func rewriteValueARM64_OpARM64FMOVDstore_0(v *Value) bool { v.AddArg(mem) return true } + // match: (FMOVDstore [off] {sym} (ADD ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (FMOVDstoreidx ptr idx val mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64FMOVDstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } // match: (FMOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) // result: (FMOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) @@ -3876,6 +3973,49 @@ func rewriteValueARM64_OpARM64FMOVDstore_0(v *Value) bool { } return false } +func rewriteValueARM64_OpARM64FMOVDstoreidx_0(v *Value) bool { + // match: (FMOVDstoreidx ptr (MOVDconst [c]) val mem) + // cond: + // result: (FMOVDstore [c] ptr val mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64FMOVDstore) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (FMOVDstoreidx (MOVDconst [c]) idx val mem) + // cond: + // result: (FMOVDstore [c] idx val mem) + for { + _ = v.Args[3] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + idx := v.Args[1] + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64FMOVDstore) + v.AuxInt = c + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueARM64_OpARM64FMOVSload_0(v *Value) bool { b := v.Block _ = b @@ -3905,6 +4045,30 @@ func rewriteValueARM64_OpARM64FMOVSload_0(v *Value) bool { v.AddArg(mem) return true } + // match: (FMOVSload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (FMOVSloadidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64FMOVSloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } // match: (FMOVSload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) // result: (FMOVSload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) @@ -3932,6 +4096,45 @@ func rewriteValueARM64_OpARM64FMOVSload_0(v *Value) bool { } return false } +func rewriteValueARM64_OpARM64FMOVSloadidx_0(v *Value) bool { + // match: (FMOVSloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (FMOVSload [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64FMOVSload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (FMOVSloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (FMOVSload [c] ptr mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64FMOVSload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} func rewriteValueARM64_OpARM64FMOVSstore_0(v *Value) bool { b := v.Block _ = b @@ -3963,6 +4166,32 @@ func rewriteValueARM64_OpARM64FMOVSstore_0(v *Value) bool { v.AddArg(mem) return true } + // match: (FMOVSstore [off] {sym} (ADD ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (FMOVSstoreidx ptr idx val mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64FMOVSstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } // match: (FMOVSstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) // result: (FMOVSstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) @@ -3992,6 +4221,49 @@ func rewriteValueARM64_OpARM64FMOVSstore_0(v *Value) bool { } return false } +func rewriteValueARM64_OpARM64FMOVSstoreidx_0(v *Value) bool { + // match: (FMOVSstoreidx ptr (MOVDconst [c]) val mem) + // cond: + // result: (FMOVSstore [c] ptr val mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64FMOVSstore) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (FMOVSstoreidx (MOVDconst [c]) idx val mem) + // cond: + // result: (FMOVSstore [c] idx val mem) + for { + _ = v.Args[3] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + idx := v.Args[1] + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64FMOVSstore) + v.AuxInt = c + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} func rewriteValueARM64_OpARM64FMULD_0(v *Value) bool { // match: (FMULD (FNEGD x) y) // cond: diff --git a/test/codegen/floats.go b/test/codegen/floats.go index b046de8fcde3d..4e4f87d574a29 100644 --- a/test/codegen/floats.go +++ b/test/codegen/floats.go @@ -55,6 +55,16 @@ func getPi() float64 { return math.Pi } +func indexLoad(b0 []float32, b1 float32, idx int) float32 { + // arm64:`FMOVS\s\(R[0-9]+\)\(R[0-9]+\),\sF[0-9]+` + return b0[idx] * b1 +} + +func indexStore(b0 []float64, b1 float64, idx int) { + // arm64:`FMOVD\sF[0-9]+,\s\(R[0-9]+\)\(R[0-9]+\)` + b0[idx] = b1 +} + // ----------- // // Fused // // ----------- // From 61318d7ffe8a49e9dedc5aa8195a164a3821465c Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sun, 26 Aug 2018 20:38:43 -0700 Subject: [PATCH 0215/1663] cmd/go: add GOMIPS value to build id for mipsle Strip a trailing "le" from the GOARCH value when calculating the GOxxx environment variable that affects it. Fixes #27260 Change-Id: I081f30d5dc19281901551823f4f56be028b5f71a Reviewed-on: https://go-review.googlesource.com/131379 Reviewed-by: Brad Fitzpatrick --- src/cmd/go/internal/work/exec.go | 4 +- .../go/testdata/script/build_cache_gomips.txt | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/cmd/go/testdata/script/build_cache_gomips.txt diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 2822787e63d12..01414a3d5775b 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -224,7 +224,9 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID { if len(p.SFiles) > 0 { fmt.Fprintf(h, "asm %q %q %q\n", b.toolID("asm"), forcedAsmflags, p.Internal.Asmflags) } - fmt.Fprintf(h, "GO$GOARCH=%s\n", os.Getenv("GO"+strings.ToUpper(cfg.BuildContext.GOARCH))) // GO386, GOARM, etc + // GO386, GOARM, GOMIPS, etc. + baseArch := strings.TrimSuffix(cfg.BuildContext.GOARCH, "le") + fmt.Fprintf(h, "GO$GOARCH=%s\n", os.Getenv("GO"+strings.ToUpper(baseArch))) // TODO(rsc): Convince compiler team not to add more magic environment variables, // or perhaps restrict the environment variables passed to subprocesses. diff --git a/src/cmd/go/testdata/script/build_cache_gomips.txt b/src/cmd/go/testdata/script/build_cache_gomips.txt new file mode 100644 index 0000000000000..c77acc3f2f32d --- /dev/null +++ b/src/cmd/go/testdata/script/build_cache_gomips.txt @@ -0,0 +1,37 @@ +# Set up fresh GOCACHE. +env GOCACHE=$WORK/gocache +mkdir $GOCACHE + +# Building for mipsle without setting GOMIPS will use floating point registers. +env GOARCH=mipsle +env GOOS=linux +go build -gcflags=-S f.go +stderr ADDD.F[0-9]+,.F[0-9]+,.F[0-9]+ + +# Clean cache +go clean -cache + +# Building with GOMIPS=softfloat will not use floating point registers +env GOMIPS=softfloat +go build -gcflags=-S f.go +! stderr ADDD.F[0-9]+,.F[0-9]+,.F[0-9]+ + +# Clean cache +go clean -cache + +# Build without setting GOMIPS +env GOMIPS= +go build -gcflags=-S f.go +stderr ADDD.F[0-9]+,.F[0-9]+,.F[0-9]+ + +# Building with GOMIPS should still not use floating point registers. +env GOMIPS=softfloat +go build -gcflags=-S f.go +! stderr ADDD.F[0-9]+,.F[0-9]+,.F[0-9]+ + +-- f.go -- +package f + +func F(x float64) float64 { + return x + x +} From ded941158042d8b09164a9f8049fd7108b715680 Mon Sep 17 00:00:00 2001 From: Eric Ponce Date: Sun, 26 Aug 2018 19:32:07 +0200 Subject: [PATCH 0216/1663] math: add Round and RoundToEven examples Change-Id: Ibef5f96ea588d17eac1c96ee3992e01943ba0fef Reviewed-on: https://go-review.googlesource.com/131496 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/math/example_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/math/example_test.go b/src/math/example_test.go index a1f764bcdaabc..25d6975903bcb 100644 --- a/src/math/example_test.go +++ b/src/math/example_test.go @@ -113,3 +113,25 @@ func ExamplePow10() { fmt.Printf("%.1f", c) // Output: 100.0 } + +func ExampleRound() { + p := math.Round(10.5) + fmt.Printf("%.1f\n", p) + + n := math.Round(-10.5) + fmt.Printf("%.1f\n", n) + // Output: + // 11.0 + // -11.0 +} + +func ExampleRoundToEven() { + u := math.RoundToEven(11.5) + fmt.Printf("%.1f\n", u) + + d := math.RoundToEven(12.5) + fmt.Printf("%.1f\n", d) + // Output: + // 12.0 + // 12.0 +} From 76c45877c9e72ccc84db787dc08299e0182e0efb Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Mon, 23 Jul 2018 01:47:11 +0900 Subject: [PATCH 0217/1663] syscall: implement Unix Socket for Windows Add implementation of AF_UNIX. This works only on Windows 10. https://blogs.msdn.microsoft.com/commandline/2017/12/19/af_unix-comes-to-windows/ Fixes #26072 Change-Id: I76a96a472385a17901885271622fbe55d66bb720 Reviewed-on: https://go-review.googlesource.com/125456 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Alex Brainman --- api/except.txt | 2 + src/net/unixsock_windows_test.go | 93 ++++++++++++++++++++++++++++++++ src/syscall/syscall_windows.go | 58 ++++++++++++++++++-- src/syscall/types_windows.go | 2 + 4 files changed, 151 insertions(+), 4 deletions(-) create mode 100644 src/net/unixsock_windows_test.go diff --git a/api/except.txt b/api/except.txt index 46dbb458923c1..850724196d249 100644 --- a/api/except.txt +++ b/api/except.txt @@ -370,6 +370,7 @@ pkg syscall (windows-386), type CertContext struct, CertInfo uintptr pkg syscall (windows-386), type CertRevocationInfo struct, CrlInfo uintptr pkg syscall (windows-386), type CertRevocationInfo struct, OidSpecificInfo uintptr pkg syscall (windows-386), type CertSimpleChain struct, TrustListInfo uintptr +pkg syscall (windows-386), type RawSockaddrAny struct, Pad [96]int8 pkg syscall (windows-amd64), const TOKEN_ALL_ACCESS = 983295 pkg syscall (windows-amd64), type AddrinfoW struct, Addr uintptr pkg syscall (windows-amd64), type CertChainPolicyPara struct, ExtraPolicyPara uintptr @@ -378,3 +379,4 @@ pkg syscall (windows-amd64), type CertContext struct, CertInfo uintptr pkg syscall (windows-amd64), type CertRevocationInfo struct, CrlInfo uintptr pkg syscall (windows-amd64), type CertRevocationInfo struct, OidSpecificInfo uintptr pkg syscall (windows-amd64), type CertSimpleChain struct, TrustListInfo uintptr +pkg syscall (windows-amd64), type RawSockaddrAny struct, Pad [96]int8 diff --git a/src/net/unixsock_windows_test.go b/src/net/unixsock_windows_test.go new file mode 100644 index 0000000000000..a1da5d4062d41 --- /dev/null +++ b/src/net/unixsock_windows_test.go @@ -0,0 +1,93 @@ +// Copyright 2018 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. + +// +build windows + +package net + +import ( + "internal/syscall/windows/registry" + "os" + "reflect" + "strconv" + "testing" +) + +func isBuild17063() bool { + k, err := registry.OpenKey(registry.LOCAL_MACHINE, `SOFTWARE\Microsoft\Windows NT\CurrentVersion`, registry.READ) + if err != nil { + return false + } + defer k.Close() + + s, _, err := k.GetStringValue("CurrentBuild") + if err != nil { + return false + } + ver, err := strconv.Atoi(s) + if err != nil { + return false + } + return ver >= 17063 +} + +func TestUnixConnLocalWindows(t *testing.T) { + if !isBuild17063() { + t.Skip("unix test") + } + + handler := func(ls *localServer, ln Listener) {} + for _, laddr := range []string{"", testUnixAddr()} { + laddr := laddr + taddr := testUnixAddr() + ta, err := ResolveUnixAddr("unix", taddr) + if err != nil { + t.Fatal(err) + } + ln, err := ListenUnix("unix", ta) + if err != nil { + t.Fatal(err) + } + ls, err := (&streamListener{Listener: ln}).newLocalServer() + if err != nil { + t.Fatal(err) + } + defer ls.teardown() + if err := ls.buildup(handler); err != nil { + t.Fatal(err) + } + + la, err := ResolveUnixAddr("unix", laddr) + if err != nil { + t.Fatal(err) + } + c, err := DialUnix("unix", la, ta) + if err != nil { + t.Fatal(err) + } + defer func() { + c.Close() + if la != nil { + defer os.Remove(laddr) + } + }() + if _, err := c.Write([]byte("UNIXCONN LOCAL AND REMOTE NAME TEST")); err != nil { + t.Fatal(err) + } + + if laddr == "" { + laddr = "@" + } + var connAddrs = [3]struct{ got, want Addr }{ + {ln.Addr(), ta}, + {c.LocalAddr(), &UnixAddr{Name: laddr, Net: "unix"}}, + {c.RemoteAddr(), ta}, + } + for _, ca := range connAddrs { + if !reflect.DeepEqual(ca.got, ca.want) { + t.Fatalf("got %#v, expected %#v", ca.got, ca.want) + } + } + } +} diff --git a/src/syscall/syscall_windows.go b/src/syscall/syscall_windows.go index 638a81882af9b..528ef4f26dfe6 100644 --- a/src/syscall/syscall_windows.go +++ b/src/syscall/syscall_windows.go @@ -634,7 +634,7 @@ type RawSockaddr struct { type RawSockaddrAny struct { Addr RawSockaddr - Pad [96]int8 + Pad [100]int8 } type Sockaddr interface { @@ -683,19 +683,69 @@ func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, int32, error) { return unsafe.Pointer(&sa.raw), int32(unsafe.Sizeof(sa.raw)), nil } +type RawSockaddrUnix struct { + Family uint16 + Path [UNIX_PATH_MAX]int8 +} + type SockaddrUnix struct { Name string + raw RawSockaddrUnix } func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, int32, error) { - // TODO(brainman): implement SockaddrUnix.sockaddr() - return nil, 0, EWINDOWS + name := sa.Name + n := len(name) + if n > len(sa.raw.Path) { + return nil, 0, EINVAL + } + if n == len(sa.raw.Path) && name[0] != '@' { + return nil, 0, EINVAL + } + sa.raw.Family = AF_UNIX + for i := 0; i < n; i++ { + sa.raw.Path[i] = int8(name[i]) + } + // length is family (uint16), name, NUL. + sl := int32(2) + if n > 0 { + sl += int32(n) + 1 + } + if sa.raw.Path[0] == '@' { + sa.raw.Path[0] = 0 + // Don't count trailing NUL for abstract address. + sl-- + } + + return unsafe.Pointer(&sa.raw), sl, nil } func (rsa *RawSockaddrAny) Sockaddr() (Sockaddr, error) { switch rsa.Addr.Family { case AF_UNIX: - return nil, EWINDOWS + pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa)) + sa := new(SockaddrUnix) + if pp.Path[0] == 0 { + // "Abstract" Unix domain socket. + // Rewrite leading NUL as @ for textual display. + // (This is the standard convention.) + // Not friendly to overwrite in place, + // but the callers below don't care. + pp.Path[0] = '@' + } + + // Assume path ends at NUL. + // This is not technically the Linux semantics for + // abstract Unix domain sockets--they are supposed + // to be uninterpreted fixed-size binary blobs--but + // everyone uses this convention. + n := 0 + for n < len(pp.Path) && pp.Path[n] != 0 { + n++ + } + bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n] + sa.Name = string(bytes) + return sa, nil case AF_INET: pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa)) diff --git a/src/syscall/types_windows.go b/src/syscall/types_windows.go index 6911fe509cbbc..0b839339d2f19 100644 --- a/src/syscall/types_windows.go +++ b/src/syscall/types_windows.go @@ -1139,3 +1139,5 @@ const ( SYMBOLIC_LINK_FLAG_DIRECTORY = 0x1 _SYMLINK_FLAG_RELATIVE = 1 ) + +const UNIX_PATH_MAX = 108 // defined in afunix.h From 975f1afd85bd1de6037e1ba30af0c7ec598f689c Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 28 Aug 2018 14:22:37 +0200 Subject: [PATCH 0218/1663] internal/syscall/unix: remove unnecessary empty.s After CL 130736 there are no empty function declarations this package anymore, so empty.s is no longer needed. Change-Id: Ic4306f10ad8a31777a3337870ce19e14c1510f3b Reviewed-on: https://go-review.googlesource.com/131835 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/internal/syscall/unix/empty.s | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 src/internal/syscall/unix/empty.s diff --git a/src/internal/syscall/unix/empty.s b/src/internal/syscall/unix/empty.s deleted file mode 100644 index 7151ab838bd6e..0000000000000 --- a/src/internal/syscall/unix/empty.s +++ /dev/null @@ -1,7 +0,0 @@ -// Copyright 2018 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. - -// This file is here just to make the go tool happy. It allows -// empty function declarations (no function body). -// It is used with "go:linkname". From 2e234754d7aee07eb00c7133a331e96a75517f9e Mon Sep 17 00:00:00 2001 From: Fazlul Shahriar Date: Tue, 28 Aug 2018 09:55:43 -0400 Subject: [PATCH 0219/1663] os/exec: pass ExitCode tests on Plan 9 Fixes #27294 Change-Id: I8db5ca0f0c690bf532d3d33b8ed7d2633ad1702b Reviewed-on: https://go-review.googlesource.com/131855 Reviewed-by: Brad Fitzpatrick --- src/os/exec/exec_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/os/exec/exec_test.go b/src/os/exec/exec_test.go index f0bba11c5a38a..558345ff632c9 100644 --- a/src/os/exec/exec_test.go +++ b/src/os/exec/exec_test.go @@ -173,6 +173,9 @@ func TestExitCode(t *testing.T) { cmd := helperCommand(t, "exit", "42") cmd.Run() want := 42 + if runtime.GOOS == "plan9" { + want = 1 + } got := cmd.ProcessState.ExitCode() if want != got { t.Errorf("ExitCode got %d, want %d", got, want) @@ -181,6 +184,9 @@ func TestExitCode(t *testing.T) { cmd = helperCommand(t, "/no-exist-executable") cmd.Run() want = 2 + if runtime.GOOS == "plan9" { + want = 1 + } got = cmd.ProcessState.ExitCode() if want != got { t.Errorf("ExitCode got %d, want %d", got, want) @@ -189,6 +195,9 @@ func TestExitCode(t *testing.T) { cmd = helperCommand(t, "exit", "255") cmd.Run() want = 255 + if runtime.GOOS == "plan9" { + want = 1 + } got = cmd.ProcessState.ExitCode() if want != got { t.Errorf("ExitCode got %d, want %d", got, want) From 422151ad50d03e142dc298a83523d7d8e2d515c5 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Mon, 27 Aug 2018 11:49:38 -0400 Subject: [PATCH 0220/1663] cmd/link: fix a few typos in comments Comment changes to fix typos, no code changes. Change-Id: I6c915f183025587fc479d14f5d2c885767348b1b Reviewed-on: https://go-review.googlesource.com/131615 Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/ld/ar.go | 2 +- src/cmd/link/internal/ld/data.go | 2 +- src/cmd/link/internal/ld/dwarf.go | 6 +++--- src/cmd/link/internal/ld/lib.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cmd/link/internal/ld/ar.go b/src/cmd/link/internal/ld/ar.go index 779f3565f9d3a..f41e30d6e73c4 100644 --- a/src/cmd/link/internal/ld/ar.go +++ b/src/cmd/link/internal/ld/ar.go @@ -106,7 +106,7 @@ func hostArchive(ctxt *Link, name string) { var load []uint64 for _, s := range ctxt.Syms.Allsym { for i := range s.R { - r := &s.R[i] // Copying sym.Reloc has measurable impact on peformance + r := &s.R[i] // Copying sym.Reloc has measurable impact on performance if r.Sym != nil && r.Sym.Type == sym.SXREF { if off := armap[r.Sym.Name]; off != 0 && !loaded[off] { load = append(load, off) diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 730e9a0bf7612..4b7680d1da835 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -777,7 +777,7 @@ func Datblk(ctxt *Link, addr int64, size int64) { continue } for i := range sym.R { - r := &sym.R[i] // Copying sym.Reloc has measurable impact on peformance + r := &sym.R[i] // Copying sym.Reloc has measurable impact on performance rsname := "" if r.Sym != nil { rsname = r.Sym.Name diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index c803180cadd08..4cb9295f438de 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -1062,7 +1062,7 @@ func importInfoSymbol(ctxt *Link, dsym *sym.Symbol) { dsym.Attr |= sym.AttrNotInSymbolTable | sym.AttrReachable dsym.Type = sym.SDWARFINFO for i := range dsym.R { - r := &dsym.R[i] // Copying sym.Reloc has measurable impact on peformance + r := &dsym.R[i] // Copying sym.Reloc has measurable impact on performance if r.Type == objabi.R_DWARFSECREF && r.Sym.Size == 0 { if ctxt.BuildMode == BuildModeShared { // These type symbols may not be present in BuildModeShared. Skip. @@ -1092,7 +1092,7 @@ func collectAbstractFunctions(ctxt *Link, fn *sym.Symbol, dsym *sym.Symbol, absf // Walk the relocations on the primary subprogram DIE and look for // references to abstract funcs. for i := range dsym.R { - reloc := &dsym.R[i] // Copying sym.Reloc has measurable impact on peformance + reloc := &dsym.R[i] // Copying sym.Reloc has measurable impact on performance candsym := reloc.Sym if reloc.Type != objabi.R_DWARFSECREF { continue @@ -1804,7 +1804,7 @@ func collectlocs(ctxt *Link, syms []*sym.Symbol, units []*compilationUnit) []*sy for _, u := range units { for _, fn := range u.funcDIEs { for i := range fn.R { - reloc := &fn.R[i] // Copying sym.Reloc has measurable impact on peformance + reloc := &fn.R[i] // Copying sym.Reloc has measurable impact on performance if reloc.Type == objabi.R_DWARFSECREF && strings.HasPrefix(reloc.Sym.Name, dwarf.LocPrefix) { reloc.Sym.Attr |= sym.AttrReachable | sym.AttrNotInSymbolTable syms = append(syms, reloc.Sym) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 9be9f5f916506..6b578d7096204 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -504,7 +504,7 @@ func (ctxt *Link) loadlib() { any := false for _, s := range ctxt.Syms.Allsym { for i := range s.R { - r := &s.R[i] // Copying sym.Reloc has measurable impact on peformance + r := &s.R[i] // Copying sym.Reloc has measurable impact on performance if r.Sym != nil && r.Sym.Type == sym.SXREF && r.Sym.Name != ".got" { any = true break From 21e85c293d02f8cb243b387b37a3d9c1c16305f7 Mon Sep 17 00:00:00 2001 From: Taesu Pyo Date: Tue, 28 Aug 2018 15:56:10 +0000 Subject: [PATCH 0221/1663] encoding/json: fix UnmarshalTypeError without field and struct values MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #26444 Fixes #27275 Change-Id: I9e8cbff79f7643ca8964c572c1a98172b6831730 GitHub-Last-Rev: 7eea2158b67ccab34b45a21e8f4289c36de02d93 GitHub-Pull-Request: golang/go#26719 Reviewed-on: https://go-review.googlesource.com/126897 Reviewed-by: Daniel Martí Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot --- src/encoding/json/decode.go | 6 +++--- src/encoding/json/decode_test.go | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go index 2e734fb39e033..fd2bf92dc24a1 100644 --- a/src/encoding/json/decode.go +++ b/src/encoding/json/decode.go @@ -670,6 +670,7 @@ func (d *decodeState) object(v reflect.Value) error { } var mapElem reflect.Value + originalErrorContext := d.errorContext for { // Read opening " of string key or closing }. @@ -829,8 +830,7 @@ func (d *decodeState) object(v reflect.Value) error { return errPhase } - d.errorContext.Struct = nil - d.errorContext.Field = "" + d.errorContext = originalErrorContext } return nil } @@ -988,7 +988,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool if fromQuoted { return fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()) } - return &UnmarshalTypeError{Value: "number", Type: v.Type(), Offset: int64(d.readIndex())} + d.saveError(&UnmarshalTypeError{Value: "number", Type: v.Type(), Offset: int64(d.readIndex())}) case reflect.Interface: n, err := d.convertNumber(s) if err != nil { diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go index 127bc494e5d46..b84bbabfcd801 100644 --- a/src/encoding/json/decode_test.go +++ b/src/encoding/json/decode_test.go @@ -371,6 +371,10 @@ func (b *intWithPtrMarshalText) UnmarshalText(data []byte) error { return (*intWithMarshalText)(b).UnmarshalText(data) } +type mapStringToStringData struct { + Data map[string]string `json:"data"` +} + type unmarshalTest struct { in string ptr interface{} @@ -401,6 +405,7 @@ var unmarshalTests = []unmarshalTest{ {in: `"invalid: \uD834x\uDD1E"`, ptr: new(string), out: "invalid: \uFFFDx\uFFFD"}, {in: "null", ptr: new(interface{}), out: nil}, {in: `{"X": [1,2,3], "Y": 4}`, ptr: new(T), out: T{Y: 4}, err: &UnmarshalTypeError{"array", reflect.TypeOf(""), 7, "T", "X"}}, + {in: `{"X": 23}`, ptr: new(T), out: T{}, err: &UnmarshalTypeError{"number", reflect.TypeOf(""), 8, "T", "X"}}, {in: `{"x": 1}`, ptr: new(tx), out: tx{}}, {in: `{"x": 1}`, ptr: new(tx), out: tx{}}, {in: `{"x": 1}`, ptr: new(tx), err: fmt.Errorf("json: unknown field \"x\""), disallowUnknownFields: true}, {in: `{"F1":1,"F2":2,"F3":3}`, ptr: new(V), out: V{F1: float64(1), F2: int32(2), F3: Number("3")}}, @@ -866,6 +871,18 @@ var unmarshalTests = []unmarshalTest{ err: fmt.Errorf("json: unknown field \"extra\""), disallowUnknownFields: true, }, + // issue 26444 + // UnmarshalTypeError without field & struct values + { + in: `{"data":{"test1": "bob", "test2": 123}}`, + ptr: new(mapStringToStringData), + err: &UnmarshalTypeError{Value: "number", Type: reflect.TypeOf(""), Offset: 37, Struct: "mapStringToStringData", Field: "data"}, + }, + { + in: `{"data":{"test1": 123, "test2": "bob"}}`, + ptr: new(mapStringToStringData), + err: &UnmarshalTypeError{Value: "number", Type: reflect.TypeOf(""), Offset: 21, Struct: "mapStringToStringData", Field: "data"}, + }, } func TestMarshal(t *testing.T) { From c7271c0c258634982ac4e18cdac287fcc43f93e1 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Fri, 6 Jul 2018 12:45:03 -0400 Subject: [PATCH 0222/1663] cmd/link: improve comments for relocsym This patch contains the remnants of CL (122482), which was intended to reduce memory allocation in 'relocsym'. Another CL (113637) went in first that included pretty much all of the code changes in 122482, however there are some changes to comments that are worth preserving. Change-Id: Iacdbd2bfe3b7ca2656596570f06ce9a646211913 Reviewed-on: https://go-review.googlesource.com/122482 Reviewed-by: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick --- src/cmd/link/internal/ld/data.go | 15 +++++++- src/cmd/link/internal/ld/lib.go | 63 +++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 4b7680d1da835..3070fdbb35591 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -111,7 +111,20 @@ func trampoline(ctxt *Link, s *sym.Symbol) { } -// resolve relocations in s. +// relocsym resolve relocations in "s". The main loop walks through +// the list of relocations attached to "s" and resolves them where +// applicable. Relocations are often architecture-specific, requiring +// calls into the 'archreloc' and/or 'archrelocvariant' functions for +// the architecture. When external linking is in effect, it may not be +// possible to completely resolve the address/offset for a symbol, in +// which case the goal is to lay the groundwork for turning a given +// relocation into an external reloc (to be applied by the external +// linker). For more on how relocations work in general, see +// +// "Linkers and Loaders", by John R. Levine (Morgan Kaufmann, 1999), ch. 7 +// +// This is a performance-critical function for the linker; be careful +// to avoid introducing unnecessary allocations in the main loop. func relocsym(ctxt *Link, s *sym.Symbol) { for ri := int32(0); ri < int32(len(s.R)); ri++ { r := &s.R[ri] diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 6b578d7096204..bfb9d9b772388 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -91,28 +91,47 @@ import ( // THE SOFTWARE. type Arch struct { - Funcalign int - Maxalign int - Minalign int - Dwarfregsp int - Dwarfreglr int - Linuxdynld string - Freebsddynld string - Netbsddynld string - Openbsddynld string - Dragonflydynld string - Solarisdynld string - Adddynrel func(*Link, *sym.Symbol, *sym.Reloc) bool - Archinit func(*Link) - Archreloc func(*Link, *sym.Reloc, *sym.Symbol, int64) (int64, bool) - Archrelocvariant func(*Link, *sym.Reloc, *sym.Symbol, int64) int64 - Trampoline func(*Link, *sym.Reloc, *sym.Symbol) - Asmb func(*Link) - Elfreloc1 func(*Link, *sym.Reloc, int64) bool - Elfsetupplt func(*Link) - Gentext func(*Link) - Machoreloc1 func(*sys.Arch, *OutBuf, *sym.Symbol, *sym.Reloc, int64) bool - PEreloc1 func(*sys.Arch, *OutBuf, *sym.Symbol, *sym.Reloc, int64) bool + Funcalign int + Maxalign int + Minalign int + Dwarfregsp int + Dwarfreglr int + Linuxdynld string + Freebsddynld string + Netbsddynld string + Openbsddynld string + Dragonflydynld string + Solarisdynld string + Adddynrel func(*Link, *sym.Symbol, *sym.Reloc) bool + Archinit func(*Link) + // Archreloc is an arch-specific hook that assists in + // relocation processing (invoked by 'relocsym'); it handles + // target-specific relocation tasks. Here "rel" is the current + // relocation being examined, "sym" is the symbol containing the + // chunk of data to which the relocation applies, and "off" is the + // contents of the to-be-relocated data item (from sym.P). Return + // value is the appropriately relocated value (to be written back + // to the same spot in sym.P) and a boolean indicating + // success/failure (a failing value indicates a fatal error). + Archreloc func(link *Link, rel *sym.Reloc, sym *sym.Symbol, + offset int64) (relocatedOffset int64, success bool) + // Archrelocvariant is a second arch-specific hook used for + // relocation processing; it handles relocations where r.Type is + // insufficient to describe the relocation (r.Variant != + // sym.RV_NONE). Here "rel" is the relocation being applied, "sym" + // is the symbol containing the chunk of data to which the + // relocation applies, and "off" is the contents of the + // to-be-relocated data item (from sym.P). Return is an updated + // offset value. + Archrelocvariant func(link *Link, rel *sym.Reloc, sym *sym.Symbol, + offset int64) (relocatedOffset int64) + Trampoline func(*Link, *sym.Reloc, *sym.Symbol) + Asmb func(*Link) + Elfreloc1 func(*Link, *sym.Reloc, int64) bool + Elfsetupplt func(*Link) + Gentext func(*Link) + Machoreloc1 func(*sys.Arch, *OutBuf, *sym.Symbol, *sym.Reloc, int64) bool + PEreloc1 func(*sys.Arch, *OutBuf, *sym.Symbol, *sym.Reloc, int64) bool // TLSIEtoLE converts a TLS Initial Executable relocation to // a TLS Local Executable relocation. From cb7f9ec4b71e81760fa36ebff60a7e41a07df238 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Fri, 17 Aug 2018 11:12:43 -0400 Subject: [PATCH 0223/1663] cmd/compile: add a test for reproducible build with anonymous interfaces Duplicated anonymous interfaces caused nondeterministic build. The fix is CL 129515. This CL adds a test. Updates #27013. Change-Id: I6b7e1bbfc943c22e8e6f32c145f7aebb567cef15 Reviewed-on: https://go-review.googlesource.com/129680 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- .../internal/gc/reproduciblebuilds_test.go | 55 +++++++++++-------- .../gc/testdata/reproducible/issue27013.go | 15 +++++ 2 files changed, 48 insertions(+), 22 deletions(-) create mode 100644 src/cmd/compile/internal/gc/testdata/reproducible/issue27013.go diff --git a/src/cmd/compile/internal/gc/reproduciblebuilds_test.go b/src/cmd/compile/internal/gc/reproduciblebuilds_test.go index b5f318e7618f6..9173f80ee3133 100644 --- a/src/cmd/compile/internal/gc/reproduciblebuilds_test.go +++ b/src/cmd/compile/internal/gc/reproduciblebuilds_test.go @@ -15,34 +15,45 @@ import ( ) func TestReproducibleBuilds(t *testing.T) { + tests := []string{ + "issue20272.go", + "issue27013.go", + } + testenv.MustHaveGoBuild(t) iters := 10 if testing.Short() { iters = 4 } t.Parallel() - var want []byte - tmp, err := ioutil.TempFile("", "") - if err != nil { - t.Fatalf("temp file creation failed: %v", err) - } - defer os.Remove(tmp.Name()) - defer tmp.Close() - for i := 0; i < iters; i++ { - out, err := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", tmp.Name(), filepath.Join("testdata", "reproducible", "issue20272.go")).CombinedOutput() - if err != nil { - t.Fatalf("failed to compile: %v\n%s", err, out) - } - obj, err := ioutil.ReadFile(tmp.Name()) - if err != nil { - t.Fatalf("failed to read object file: %v", err) - } - if i == 0 { - want = obj - } else { - if !bytes.Equal(want, obj) { - t.Fatalf("builds produced different output after %d iters (%d bytes vs %d bytes)", i, len(want), len(obj)) + for _, test := range tests { + test := test + t.Run(test, func(t *testing.T) { + t.Parallel() + var want []byte + tmp, err := ioutil.TempFile("", "") + if err != nil { + t.Fatalf("temp file creation failed: %v", err) + } + defer os.Remove(tmp.Name()) + defer tmp.Close() + for i := 0; i < iters; i++ { + out, err := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", tmp.Name(), filepath.Join("testdata", "reproducible", test)).CombinedOutput() + if err != nil { + t.Fatalf("failed to compile: %v\n%s", err, out) + } + obj, err := ioutil.ReadFile(tmp.Name()) + if err != nil { + t.Fatalf("failed to read object file: %v", err) + } + if i == 0 { + want = obj + } else { + if !bytes.Equal(want, obj) { + t.Fatalf("builds produced different output after %d iters (%d bytes vs %d bytes)", i, len(want), len(obj)) + } + } } - } + }) } } diff --git a/src/cmd/compile/internal/gc/testdata/reproducible/issue27013.go b/src/cmd/compile/internal/gc/testdata/reproducible/issue27013.go new file mode 100644 index 0000000000000..817f4a640ee95 --- /dev/null +++ b/src/cmd/compile/internal/gc/testdata/reproducible/issue27013.go @@ -0,0 +1,15 @@ +// Copyright 2018 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. + +package p + +func A(arg interface{}) { + _ = arg.(interface{ Func() int32 }) + _ = arg.(interface{ Func() int32 }) + _ = arg.(interface{ Func() int32 }) + _ = arg.(interface{ Func() int32 }) + _ = arg.(interface{ Func() int32 }) + _ = arg.(interface{ Func() int32 }) + _ = arg.(interface{ Func() int32 }) +} From 7c7cecc1846aaaa0ce73931644fe1df2b4559e09 Mon Sep 17 00:00:00 2001 From: Dave Brophy Date: Tue, 28 Aug 2018 18:13:40 +0000 Subject: [PATCH 0224/1663] fmt: fix incorrect format of whole-number floats when using %#v MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the unwanted behaviour where printing a zero float with the #v fmt verb outputs "0" - e.g. missing the trailing decimal. This means that the output would be interpreted as an int rather than a float when parsed as Go source. After this change the the output is "0.0". Fixes #26363 Change-Id: Ic5c060522459cd5ce077675d47c848b22ddc34fa GitHub-Last-Rev: adfb061363f0566acec134c81be9a3dcb1f4cac8 GitHub-Pull-Request: golang/go#26383 Reviewed-on: https://go-review.googlesource.com/123956 Reviewed-by: Daniel Martí Reviewed-by: Rob Pike Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot --- src/fmt/fmt_test.go | 8 ++++++++ src/fmt/format.go | 41 ++++++++++++++++++++++++++--------------- test/switch5.go | 8 ++++---- 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/fmt/fmt_test.go b/src/fmt/fmt_test.go index edfd1ee824fd4..9581becd32c3b 100644 --- a/src/fmt/fmt_test.go +++ b/src/fmt/fmt_test.go @@ -690,6 +690,14 @@ var fmtTests = []struct { {"%#v", []int32(nil), "[]int32(nil)"}, {"%#v", 1.2345678, "1.2345678"}, {"%#v", float32(1.2345678), "1.2345678"}, + + // Whole number floats should have a single trailing zero added, but not + // for exponent notation. + {"%#v", 1.0, "1.0"}, + {"%#v", 1000000.0, "1e+06"}, + {"%#v", float32(1.0), "1.0"}, + {"%#v", float32(1000000.0), "1e+06"}, + // Only print []byte and []uint8 as type []byte if they appear at the top level. {"%#v", []byte(nil), "[]byte(nil)"}, {"%#v", []uint8(nil), "[]byte(nil)"}, diff --git a/src/fmt/format.go b/src/fmt/format.go index 91103f2c07f18..3a3cd8d1a1eb0 100644 --- a/src/fmt/format.go +++ b/src/fmt/format.go @@ -481,15 +481,19 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) { return } // The sharp flag forces printing a decimal point for non-binary formats - // and retains trailing zeros, which we may need to restore. - if f.sharp && verb != 'b' { + // and retains trailing zeros, which we may need to restore. For the sharpV + // flag, we ensure a single trailing zero is present if the output is not + // in exponent notation. + if f.sharpV || (f.sharp && verb != 'b') { digits := 0 - switch verb { - case 'v', 'g', 'G': - digits = prec - // If no precision is set explicitly use a precision of 6. - if digits == -1 { - digits = 6 + if !f.sharpV { + switch verb { + case 'g', 'G': + digits = prec + // If no precision is set explicitly use a precision of 6. + if digits == -1 { + digits = 6 + } } } @@ -498,25 +502,32 @@ func (f *fmt) fmtFloat(v float64, size int, verb rune, prec int) { var tailBuf [5]byte tail := tailBuf[:0] - hasDecimalPoint := false + var hasDecimalPoint, hasExponent bool // Starting from i = 1 to skip sign at num[0]. for i := 1; i < len(num); i++ { switch num[i] { case '.': hasDecimalPoint = true case 'e', 'E': + hasExponent = true tail = append(tail, num[i:]...) num = num[:i] default: digits-- } } - if !hasDecimalPoint { - num = append(num, '.') - } - for digits > 0 { - num = append(num, '0') - digits-- + if f.sharpV { + if !hasDecimalPoint && !hasExponent { + num = append(num, '.', '0') + } + } else { + if !hasDecimalPoint { + num = append(num, '.') + } + for digits > 0 { + num = append(num, '0') + digits-- + } } num = append(num, tail...) } diff --git a/test/switch5.go b/test/switch5.go index ce95bf8d7b1b4..6641d582bcbaf 100644 --- a/test/switch5.go +++ b/test/switch5.go @@ -24,8 +24,8 @@ func f0(x int) { func f1(x float32) { switch x { case 5: - case 5: // ERROR "duplicate case 5 in switch" - case 5.0: // ERROR "duplicate case 5 in switch" + case 5: // ERROR "duplicate case 5 .value 5\.0. in switch" + case 5.0: // ERROR "duplicate case 5 .value 5\.0. in switch" } } @@ -44,9 +44,9 @@ func f3(e interface{}) { case 0: // ERROR "duplicate case 0 in switch" case int64(0): case float32(10): - case float32(10): // ERROR "duplicate case float32\(10\) .value 10. in switch" + case float32(10): // ERROR "duplicate case float32\(10\) .value 10\.0. in switch" case float64(10): - case float64(10): // ERROR "duplicate case float64\(10\) .value 10. in switch" + case float64(10): // ERROR "duplicate case float64\(10\) .value 10\.0. in switch" } } From 618bfb28dc02c410659312f38cd3500352ba15ed Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Thu, 23 Aug 2018 14:01:59 +0200 Subject: [PATCH 0225/1663] cmd/link: move type name mangling after deadcode elimination Moves type name mangling after deadcode elimination. The motivation for doing this is to create a space between deadcode elimination and type name mangling where DWARF generation for types and variables can exist, to fix issue #23733. Change-Id: I9db8ecc0f4efe3df6c1e4025f02642fd452f9a39 Reviewed-on: https://go-review.googlesource.com/111236 Reviewed-by: Heschi Kreinick Reviewed-by: Cherry Zhang Run-TryBot: Heschi Kreinick TryBot-Result: Gobot Gobot --- src/cmd/link/internal/ld/lib.go | 45 +++++++++++++--------------- src/cmd/link/internal/ld/main.go | 1 + src/cmd/link/internal/sym/symbols.go | 10 ++++++- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index bfb9d9b772388..1b6d5d1704712 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -577,27 +577,6 @@ func (ctxt *Link) loadlib() { } } - // If type. symbols are visible in the symbol table, rename them - // using a SHA-1 prefix. This reduces binary size (the full - // string of a type symbol can be multiple kilobytes) and removes - // characters that upset external linkers. - // - // Keep the type.. prefix, which parts of the linker (like the - // DWARF generator) know means the symbol is not decodable. - // - // Leave type.runtime. symbols alone, because other parts of - // the linker manipulates them, and also symbols whose names - // would not be shortened by this process. - if typeSymbolMangling(ctxt) { - *FlagW = true // disable DWARF generation - for _, s := range ctxt.Syms.Allsym { - newName := typeSymbolMangle(s.Name) - if newName != s.Name { - ctxt.Syms.Rename(s.Name, newName, int(s.Version)) - } - } - } - // If package versioning is required, generate a hash of the // packages used in the link. if ctxt.BuildMode == BuildModeShared || ctxt.BuildMode == BuildModePlugin || ctxt.CanUsePlugins() { @@ -657,23 +636,39 @@ func (ctxt *Link) loadlib() { } } -// typeSymbolMangling reports whether the linker should shorten the -// names of symbols that represent Go types. +// mangleTypeSym shortens the names of symbols that represent Go types +// if they are visible in the symbol table. // // As the names of these symbols are derived from the string of // the type, they can run to many kilobytes long. So we shorten // them using a SHA-1 when the name appears in the final binary. +// This also removes characters that upset external linkers. // // These are the symbols that begin with the prefix 'type.' and // contain run-time type information used by the runtime and reflect // packages. All Go binaries contain these symbols, but only only // those programs loaded dynamically in multiple parts need these // symbols to have entries in the symbol table. -func typeSymbolMangling(ctxt *Link) bool { - return ctxt.BuildMode == BuildModeShared || ctxt.linkShared || ctxt.BuildMode == BuildModePlugin || ctxt.Syms.ROLookup("plugin.Open", 0) != nil +func (ctxt *Link) mangleTypeSym() { + if ctxt.BuildMode != BuildModeShared && !ctxt.linkShared && ctxt.BuildMode != BuildModePlugin && ctxt.Syms.ROLookup("plugin.Open", 0) == nil { + return + } + + *FlagW = true // disable DWARF generation + for _, s := range ctxt.Syms.Allsym { + newName := typeSymbolMangle(s.Name) + if newName != s.Name { + ctxt.Syms.Rename(s.Name, newName, int(s.Version), ctxt.Reachparent) + } + } } // typeSymbolMangle mangles the given symbol name into something shorter. +// +// Keep the type.. prefix, which parts of the linker (like the +// DWARF generator) know means the symbol is not decodable. +// Leave type.runtime. symbols alone, because other parts of +// the linker manipulates them. func typeSymbolMangle(name string) string { if !strings.HasPrefix(name, "type.") { return name diff --git a/src/cmd/link/internal/ld/main.go b/src/cmd/link/internal/ld/main.go index 23462f1154b7e..0c5ac470438ad 100644 --- a/src/cmd/link/internal/ld/main.go +++ b/src/cmd/link/internal/ld/main.go @@ -211,6 +211,7 @@ func Main(arch *sys.Arch, theArch Arch) { if objabi.Fieldtrack_enabled != 0 { fieldtrack(ctxt) } + ctxt.mangleTypeSym() ctxt.callgraph() ctxt.doelf() diff --git a/src/cmd/link/internal/sym/symbols.go b/src/cmd/link/internal/sym/symbols.go index 98a5ae67b8bd3..f9405db185373 100644 --- a/src/cmd/link/internal/sym/symbols.go +++ b/src/cmd/link/internal/sym/symbols.go @@ -95,7 +95,7 @@ func (syms *Symbols) IncVersion() int { } // Rename renames a symbol. -func (syms *Symbols) Rename(old, new string, v int) { +func (syms *Symbols) Rename(old, new string, v int, reachparent map[*Symbol]*Symbol) { s := syms.hash[v][old] s.Name = new if s.Extname == old { @@ -108,8 +108,16 @@ func (syms *Symbols) Rename(old, new string, v int) { syms.hash[v][new] = s } else { if s.Type == 0 { + dup.Attr |= s.Attr + if s.Attr.Reachable() && reachparent != nil { + reachparent[dup] = reachparent[s] + } *s = *dup } else if dup.Type == 0 { + s.Attr |= dup.Attr + if dup.Attr.Reachable() && reachparent != nil { + reachparent[s] = reachparent[dup] + } *dup = *s syms.hash[v][new] = s } From 225981f8e78b6755bbe34c2e5d035a534ed1b25d Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Wed, 29 Aug 2018 03:24:13 +0000 Subject: [PATCH 0226/1663] syscall: skip an unsupported test case on android Lookup is not supported on android, and the test syscall/exec_linux_test.go which relies on it will fail on android/arm64. Fixes #27327 Change-Id: I6fdb8992d4634ac7e3689360ff114e9431b5e90c Reviewed-on: https://go-review.googlesource.com/131995 Reviewed-by: Brad Fitzpatrick --- src/syscall/exec_linux_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/syscall/exec_linux_test.go b/src/syscall/exec_linux_test.go index f551e87736d98..ac5745bc80bca 100644 --- a/src/syscall/exec_linux_test.go +++ b/src/syscall/exec_linux_test.go @@ -16,6 +16,7 @@ import ( "os/exec" "os/user" "path/filepath" + "runtime" "strconv" "strings" "syscall" @@ -524,6 +525,11 @@ func TestAmbientCaps(t *testing.T) { t.Skip("skipping test on Kubernetes-based builders; see Issue 12815") } + // skip on android, due to lack of lookup support + if runtime.GOOS == "android" { + t.Skip("skipping test on android; see Issue 27327") + } + caps, err := getCaps() if err != nil { t.Fatal(err) From 7b88b22acf8cb5e32f34e2a396d797c5c0125566 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Tue, 28 Aug 2018 11:27:07 -0400 Subject: [PATCH 0227/1663] cmd/compile: remove var sorting from DWARF inline generation When generation DWARF inline info records, the current implementation includes a sorting pass that reorders a subprogram's child variable DIEs based on class (param/auto) and name. This sorting is no longer needed, and can cause problems for a debugger (if we want to use the DWARF info for creating a call to an optimized function); this patch removes it. Ordering of DWARF subprogram variable/parameter DIEs is still deterministic with this change, since it is keyed off the order in which vars appear in the pre-inlining function "Dcl" list. Updates #27039 Change-Id: I3b91290d11bb3b9b36fb61271d80b801841401ee Reviewed-on: https://go-review.googlesource.com/131895 Reviewed-by: Heschi Kreinick --- src/cmd/compile/internal/gc/dwinl.go | 27 --------------------------- src/cmd/compile/internal/gc/pgen.go | 27 --------------------------- 2 files changed, 54 deletions(-) diff --git a/src/cmd/compile/internal/gc/dwinl.go b/src/cmd/compile/internal/gc/dwinl.go index d191b7ba6c84c..51251c9139fd2 100644 --- a/src/cmd/compile/internal/gc/dwinl.go +++ b/src/cmd/compile/internal/gc/dwinl.go @@ -8,7 +8,6 @@ import ( "cmd/internal/dwarf" "cmd/internal/obj" "cmd/internal/src" - "sort" "strings" ) @@ -96,7 +95,6 @@ func assembleInlines(fnsym *obj.LSym, dwVars []*dwarf.Var) dwarf.InlCalls { // the pre-inlining decls for the target function and assign child // index accordingly. for ii, sl := range vmap { - sort.Sort(byClassThenName(sl)) var m map[varPos]int if ii == 0 { if !fnsym.WasInlined() { @@ -311,31 +309,6 @@ func beginRange(calls []dwarf.InlCall, p *obj.Prog, ii int, imap map[int]int) *d return &call.Ranges[len(call.Ranges)-1] } -func cmpDwarfVar(a, b *dwarf.Var) bool { - // named before artificial - aart := 0 - if strings.HasPrefix(a.Name, "~r") { - aart = 1 - } - bart := 0 - if strings.HasPrefix(b.Name, "~r") { - bart = 1 - } - if aart != bart { - return aart < bart - } - - // otherwise sort by name - return a.Name < b.Name -} - -// byClassThenName implements sort.Interface for []*dwarf.Var using cmpDwarfVar. -type byClassThenName []*dwarf.Var - -func (s byClassThenName) Len() int { return len(s) } -func (s byClassThenName) Less(i, j int) bool { return cmpDwarfVar(s[i], s[j]) } -func (s byClassThenName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - func dumpInlCall(inlcalls dwarf.InlCalls, idx, ilevel int) { for i := 0; i < ilevel; i++ { Ctxt.Logf(" ") diff --git a/src/cmd/compile/internal/gc/pgen.go b/src/cmd/compile/internal/gc/pgen.go index cf1164772b0fc..7f20643ab57fe 100644 --- a/src/cmd/compile/internal/gc/pgen.go +++ b/src/cmd/compile/internal/gc/pgen.go @@ -15,7 +15,6 @@ import ( "fmt" "math/rand" "sort" - "strings" "sync" "time" ) @@ -594,35 +593,9 @@ func preInliningDcls(fnsym *obj.LSym) []*Node { } rdcl = append(rdcl, n) } - sort.Sort(byNodeName(rdcl)) return rdcl } -func cmpNodeName(a, b *Node) bool { - aart := 0 - if strings.HasPrefix(a.Sym.Name, "~") { - aart = 1 - } - bart := 0 - if strings.HasPrefix(b.Sym.Name, "~") { - bart = 1 - } - if aart != bart { - return aart < bart - } - - aname := unversion(a.Sym.Name) - bname := unversion(b.Sym.Name) - return aname < bname -} - -// byNodeName implements sort.Interface for []*Node using cmpNodeName. -type byNodeName []*Node - -func (s byNodeName) Len() int { return len(s) } -func (s byNodeName) Less(i, j int) bool { return cmpNodeName(s[i], s[j]) } -func (s byNodeName) Swap(i, j int) { s[i], s[j] = s[j], s[i] } - // stackOffset returns the stack location of a LocalSlot relative to the // stack pointer, suitable for use in a DWARF location entry. This has nothing // to do with its offset in the user variable. From 8f4fd3f34e8e218cb90435b5a8c6ba9be23a1e1e Mon Sep 17 00:00:00 2001 From: Zheng Xu Date: Wed, 29 Aug 2018 14:55:03 +0800 Subject: [PATCH 0228/1663] build: support frame-pointer for arm64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Supporting frame-pointer makes Linux's perf and other profilers much more useful because it lets them gather a stack trace efficiently on profiling events. Major changes include: 1. save FP on the word below where RSP is pointing to (proposed by Cherry and Austin) 2. adjust some specific offsets in runtime assembly and wrapper code 3. add support to FP in goroutine scheduler 4. adjust link stack overflow check to take the extra word into account 5. adjust nosplit test cases to enable frame sizes which are 16 bytes aligned Performance impacts on go1 benchmarks: Enable frame-pointer (by default) name old time/op new time/op delta BinaryTree17-46 5.94s ± 0% 6.00s ± 0% +1.03% (p=0.029 n=4+4) Fannkuch11-46 2.84s ± 1% 2.77s ± 0% -2.58% (p=0.008 n=5+5) FmtFprintfEmpty-46 55.0ns ± 1% 58.9ns ± 1% +7.06% (p=0.008 n=5+5) FmtFprintfString-46 102ns ± 0% 105ns ± 0% +2.94% (p=0.008 n=5+5) FmtFprintfInt-46 118ns ± 0% 117ns ± 1% -1.19% (p=0.000 n=4+5) FmtFprintfIntInt-46 181ns ± 0% 182ns ± 1% ~ (p=0.444 n=5+5) FmtFprintfPrefixedInt-46 215ns ± 1% 214ns ± 0% ~ (p=0.254 n=5+4) FmtFprintfFloat-46 292ns ± 0% 296ns ± 0% +1.46% (p=0.029 n=4+4) FmtManyArgs-46 720ns ± 0% 732ns ± 0% +1.72% (p=0.008 n=5+5) GobDecode-46 9.82ms ± 1% 10.03ms ± 2% +2.10% (p=0.008 n=5+5) GobEncode-46 8.14ms ± 0% 8.72ms ± 1% +7.14% (p=0.008 n=5+5) Gzip-46 420ms ± 0% 424ms ± 0% +0.92% (p=0.008 n=5+5) Gunzip-46 48.2ms ± 0% 48.4ms ± 0% +0.41% (p=0.008 n=5+5) HTTPClientServer-46 201µs ± 4% 201µs ± 0% ~ (p=0.730 n=5+4) JSONEncode-46 17.1ms ± 0% 17.7ms ± 1% +3.80% (p=0.008 n=5+5) JSONDecode-46 88.0ms ± 0% 90.1ms ± 0% +2.42% (p=0.008 n=5+5) Mandelbrot200-46 5.06ms ± 0% 5.07ms ± 0% ~ (p=0.310 n=5+5) GoParse-46 5.04ms ± 0% 5.12ms ± 0% +1.53% (p=0.008 n=5+5) RegexpMatchEasy0_32-46 117ns ± 0% 117ns ± 0% ~ (all equal) RegexpMatchEasy0_1K-46 332ns ± 0% 329ns ± 0% -0.78% (p=0.008 n=5+5) RegexpMatchEasy1_32-46 104ns ± 0% 113ns ± 0% +8.65% (p=0.029 n=4+4) RegexpMatchEasy1_1K-46 563ns ± 0% 569ns ± 0% +1.10% (p=0.008 n=5+5) RegexpMatchMedium_32-46 167ns ± 2% 177ns ± 1% +5.74% (p=0.008 n=5+5) RegexpMatchMedium_1K-46 49.5µs ± 0% 53.4µs ± 0% +7.81% (p=0.008 n=5+5) RegexpMatchHard_32-46 2.56µs ± 1% 2.72µs ± 0% +6.01% (p=0.008 n=5+5) RegexpMatchHard_1K-46 77.0µs ± 0% 81.8µs ± 0% +6.24% (p=0.016 n=5+4) Revcomp-46 631ms ± 1% 627ms ± 1% ~ (p=0.095 n=5+5) Template-46 81.8ms ± 0% 86.3ms ± 0% +5.55% (p=0.008 n=5+5) TimeParse-46 423ns ± 0% 432ns ± 0% +2.32% (p=0.008 n=5+5) TimeFormat-46 478ns ± 2% 497ns ± 1% +3.89% (p=0.008 n=5+5) [Geo mean] 71.6µs 73.3µs +2.45% name old speed new speed delta GobDecode-46 78.1MB/s ± 1% 76.6MB/s ± 2% -2.04% (p=0.008 n=5+5) GobEncode-46 94.3MB/s ± 0% 88.0MB/s ± 1% -6.67% (p=0.008 n=5+5) Gzip-46 46.2MB/s ± 0% 45.8MB/s ± 0% -0.91% (p=0.008 n=5+5) Gunzip-46 403MB/s ± 0% 401MB/s ± 0% -0.41% (p=0.008 n=5+5) JSONEncode-46 114MB/s ± 0% 109MB/s ± 1% -3.66% (p=0.008 n=5+5) JSONDecode-46 22.0MB/s ± 0% 21.5MB/s ± 0% -2.35% (p=0.008 n=5+5) GoParse-46 11.5MB/s ± 0% 11.3MB/s ± 0% -1.51% (p=0.008 n=5+5) RegexpMatchEasy0_32-46 272MB/s ± 0% 272MB/s ± 1% ~ (p=0.190 n=4+5) RegexpMatchEasy0_1K-46 3.08GB/s ± 0% 3.11GB/s ± 0% +0.77% (p=0.008 n=5+5) RegexpMatchEasy1_32-46 306MB/s ± 0% 283MB/s ± 0% -7.63% (p=0.029 n=4+4) RegexpMatchEasy1_1K-46 1.82GB/s ± 0% 1.80GB/s ± 0% -1.07% (p=0.008 n=5+5) RegexpMatchMedium_32-46 5.99MB/s ± 0% 5.64MB/s ± 1% -5.77% (p=0.016 n=4+5) RegexpMatchMedium_1K-46 20.7MB/s ± 0% 19.2MB/s ± 0% -7.25% (p=0.008 n=5+5) RegexpMatchHard_32-46 12.5MB/s ± 1% 11.8MB/s ± 0% -5.66% (p=0.008 n=5+5) RegexpMatchHard_1K-46 13.3MB/s ± 0% 12.5MB/s ± 1% -6.01% (p=0.008 n=5+5) Revcomp-46 402MB/s ± 1% 405MB/s ± 1% ~ (p=0.095 n=5+5) Template-46 23.7MB/s ± 0% 22.5MB/s ± 0% -5.25% (p=0.008 n=5+5) [Geo mean] 82.2MB/s 79.6MB/s -3.26% Disable frame-pointer (GOEXPERIMENT=noframepointer) name old time/op new time/op delta BinaryTree17-46 5.94s ± 0% 5.96s ± 0% +0.39% (p=0.029 n=4+4) Fannkuch11-46 2.84s ± 1% 2.79s ± 1% -1.68% (p=0.008 n=5+5) FmtFprintfEmpty-46 55.0ns ± 1% 55.2ns ± 3% ~ (p=0.794 n=5+5) FmtFprintfString-46 102ns ± 0% 103ns ± 0% +0.98% (p=0.016 n=5+4) FmtFprintfInt-46 118ns ± 0% 115ns ± 0% -2.54% (p=0.029 n=4+4) FmtFprintfIntInt-46 181ns ± 0% 179ns ± 0% -1.10% (p=0.000 n=5+4) FmtFprintfPrefixedInt-46 215ns ± 1% 213ns ± 0% ~ (p=0.143 n=5+4) FmtFprintfFloat-46 292ns ± 0% 300ns ± 0% +2.83% (p=0.029 n=4+4) FmtManyArgs-46 720ns ± 0% 739ns ± 0% +2.64% (p=0.008 n=5+5) GobDecode-46 9.82ms ± 1% 9.78ms ± 1% ~ (p=0.151 n=5+5) GobEncode-46 8.14ms ± 0% 8.12ms ± 1% ~ (p=0.690 n=5+5) Gzip-46 420ms ± 0% 420ms ± 0% ~ (p=0.548 n=5+5) Gunzip-46 48.2ms ± 0% 48.0ms ± 0% -0.33% (p=0.032 n=5+5) HTTPClientServer-46 201µs ± 4% 199µs ± 3% ~ (p=0.548 n=5+5) JSONEncode-46 17.1ms ± 0% 17.2ms ± 0% ~ (p=0.056 n=5+5) JSONDecode-46 88.0ms ± 0% 88.6ms ± 0% +0.64% (p=0.008 n=5+5) Mandelbrot200-46 5.06ms ± 0% 5.07ms ± 0% ~ (p=0.548 n=5+5) GoParse-46 5.04ms ± 0% 5.07ms ± 0% +0.65% (p=0.008 n=5+5) RegexpMatchEasy0_32-46 117ns ± 0% 112ns ± 4% -4.27% (p=0.016 n=4+5) RegexpMatchEasy0_1K-46 332ns ± 0% 330ns ± 1% ~ (p=0.095 n=5+5) RegexpMatchEasy1_32-46 104ns ± 0% 110ns ± 1% +5.29% (p=0.029 n=4+4) RegexpMatchEasy1_1K-46 563ns ± 0% 567ns ± 2% ~ (p=0.151 n=5+5) RegexpMatchMedium_32-46 167ns ± 2% 166ns ± 0% ~ (p=0.333 n=5+4) RegexpMatchMedium_1K-46 49.5µs ± 0% 49.6µs ± 0% ~ (p=0.841 n=5+5) RegexpMatchHard_32-46 2.56µs ± 1% 2.49µs ± 0% -2.81% (p=0.008 n=5+5) RegexpMatchHard_1K-46 77.0µs ± 0% 75.8µs ± 0% -1.55% (p=0.008 n=5+5) Revcomp-46 631ms ± 1% 628ms ± 0% ~ (p=0.095 n=5+5) Template-46 81.8ms ± 0% 84.3ms ± 1% +3.05% (p=0.008 n=5+5) TimeParse-46 423ns ± 0% 425ns ± 0% +0.52% (p=0.008 n=5+5) TimeFormat-46 478ns ± 2% 478ns ± 1% ~ (p=1.000 n=5+5) [Geo mean] 71.6µs 71.6µs -0.01% name old speed new speed delta GobDecode-46 78.1MB/s ± 1% 78.5MB/s ± 1% ~ (p=0.151 n=5+5) GobEncode-46 94.3MB/s ± 0% 94.5MB/s ± 1% ~ (p=0.690 n=5+5) Gzip-46 46.2MB/s ± 0% 46.2MB/s ± 0% ~ (p=0.571 n=5+5) Gunzip-46 403MB/s ± 0% 404MB/s ± 0% +0.33% (p=0.032 n=5+5) JSONEncode-46 114MB/s ± 0% 113MB/s ± 0% ~ (p=0.056 n=5+5) JSONDecode-46 22.0MB/s ± 0% 21.9MB/s ± 0% -0.64% (p=0.008 n=5+5) GoParse-46 11.5MB/s ± 0% 11.4MB/s ± 0% -0.64% (p=0.008 n=5+5) RegexpMatchEasy0_32-46 272MB/s ± 0% 285MB/s ± 4% +4.74% (p=0.016 n=4+5) RegexpMatchEasy0_1K-46 3.08GB/s ± 0% 3.10GB/s ± 1% ~ (p=0.151 n=5+5) RegexpMatchEasy1_32-46 306MB/s ± 0% 290MB/s ± 1% -5.21% (p=0.029 n=4+4) RegexpMatchEasy1_1K-46 1.82GB/s ± 0% 1.81GB/s ± 2% ~ (p=0.151 n=5+5) RegexpMatchMedium_32-46 5.99MB/s ± 0% 6.02MB/s ± 1% ~ (p=0.063 n=4+5) RegexpMatchMedium_1K-46 20.7MB/s ± 0% 20.7MB/s ± 0% ~ (p=0.659 n=5+5) RegexpMatchHard_32-46 12.5MB/s ± 1% 12.8MB/s ± 0% +2.88% (p=0.008 n=5+5) RegexpMatchHard_1K-46 13.3MB/s ± 0% 13.5MB/s ± 0% +1.58% (p=0.008 n=5+5) Revcomp-46 402MB/s ± 1% 405MB/s ± 0% ~ (p=0.095 n=5+5) Template-46 23.7MB/s ± 0% 23.0MB/s ± 1% -2.95% (p=0.008 n=5+5) [Geo mean] 82.2MB/s 82.3MB/s +0.04% Frame-pointer is enabled on Linux by default but can be disabled by setting: GOEXPERIMENT=noframepointer. Fixes #10110 Change-Id: I1bfaca6dba29a63009d7c6ab04ed7a1413d9479e Reviewed-on: https://go-review.googlesource.com/61511 Reviewed-by: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/arm64/ggen.go | 8 +- src/cmd/compile/internal/gc/pgen.go | 6 +- src/cmd/internal/obj/arm64/asm7.go | 10 +- src/cmd/internal/obj/arm64/obj7.go | 183 ++++++++++++++++++++++--- src/cmd/internal/objabi/util.go | 2 +- src/cmd/link/internal/ld/lib.go | 4 + src/runtime/asm_arm64.s | 34 +++-- src/runtime/cgocall.go | 3 +- src/runtime/rt0_darwin_arm64.s | 2 + src/runtime/rt0_linux_arm64.s | 2 + src/runtime/sys_linux_arm64.s | 8 +- src/runtime/traceback.go | 2 +- test/codegen/stack.go | 10 +- test/nosplit.go | 26 ++-- 14 files changed, 243 insertions(+), 57 deletions(-) diff --git a/src/cmd/compile/internal/arm64/ggen.go b/src/cmd/compile/internal/arm64/ggen.go index f7b3851398f51..204391fef1c77 100644 --- a/src/cmd/compile/internal/arm64/ggen.go +++ b/src/cmd/compile/internal/arm64/ggen.go @@ -14,10 +14,10 @@ import ( var darwin = objabi.GOOS == "darwin" func padframe(frame int64) int64 { - // arm64 requires that the frame size (not counting saved LR) - // be empty or be 8 mod 16. If not, pad it. - if frame != 0 && frame%16 != 8 { - frame += 8 + // arm64 requires that the frame size (not counting saved FP&LR) + // be 16 bytes aligned. If not, pad it. + if frame%16 != 0 { + frame += 16 - (frame % 16) } return frame } diff --git a/src/cmd/compile/internal/gc/pgen.go b/src/cmd/compile/internal/gc/pgen.go index 7f20643ab57fe..563eb9e966388 100644 --- a/src/cmd/compile/internal/gc/pgen.go +++ b/src/cmd/compile/internal/gc/pgen.go @@ -427,7 +427,8 @@ func createSimpleVars(automDecls []*Node) ([]*Node, []*dwarf.Var, map[*Node]bool if Ctxt.FixedFrameSize() == 0 { offs -= int64(Widthptr) } - if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) { + if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) || objabi.GOARCH == "arm64" { + // There is a word space for FP on ARM64 even if the frame pointer is disabled offs -= int64(Widthptr) } @@ -607,7 +608,8 @@ func stackOffset(slot ssa.LocalSlot) int32 { if Ctxt.FixedFrameSize() == 0 { base -= int64(Widthptr) } - if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) { + if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) || objabi.GOARCH == "arm64" { + // There is a word space for FP on ARM64 even if the frame pointer is disabled base -= int64(Widthptr) } case PPARAM, PPARAMOUT: diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index ad4f172544671..2abb8c2c773d9 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -49,6 +49,7 @@ type ctxt7 struct { blitrl *obj.Prog elitrl *obj.Prog autosize int32 + extrasize int32 instoffset int64 pc int64 pool struct { @@ -777,7 +778,8 @@ func span7(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { ctxt.Diag("arm64 ops not initialized, call arm64.buildop first") } - c := ctxt7{ctxt: ctxt, newprog: newprog, cursym: cursym, autosize: int32(p.To.Offset&0xffffffff) + 8} + c := ctxt7{ctxt: ctxt, newprog: newprog, cursym: cursym, autosize: int32(p.To.Offset & 0xffffffff), extrasize: int32(p.To.Offset >> 32)} + p.To.Offset &= 0xffffffff // extrasize is no longer needed bflag := 1 pc := int64(0) @@ -1436,7 +1438,8 @@ func (c *ctxt7) aclass(a *obj.Addr) int { // a.Offset is still relative to pseudo-SP. a.Reg = obj.REG_NONE } - c.instoffset = int64(c.autosize) + a.Offset + // The frame top 8 or 16 bytes are for FP + c.instoffset = int64(c.autosize) + a.Offset - int64(c.extrasize) return autoclass(c.instoffset) case obj.NAME_PARAM: @@ -1536,7 +1539,8 @@ func (c *ctxt7) aclass(a *obj.Addr) int { // a.Offset is still relative to pseudo-SP. a.Reg = obj.REG_NONE } - c.instoffset = int64(c.autosize) + a.Offset + // The frame top 8 or 16 bytes are for FP + c.instoffset = int64(c.autosize) + a.Offset - int64(c.extrasize) case obj.NAME_PARAM: if a.Reg == REGSP { diff --git a/src/cmd/internal/obj/arm64/obj7.go b/src/cmd/internal/obj/arm64/obj7.go index 0d832387d7f7d..97b8f70c9b20e 100644 --- a/src/cmd/internal/obj/arm64/obj7.go +++ b/src/cmd/internal/obj/arm64/obj7.go @@ -542,22 +542,28 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { c.autosize += 8 } - if c.autosize != 0 && c.autosize&(16-1) != 0 { - // The frame includes an LR. - // If the frame size is 8, it's only an LR, - // so there's no potential for breaking references to - // local variables by growing the frame size, - // because there are no local variables. - // But otherwise, if there is a non-empty locals section, - // the author of the code is responsible for making sure - // that the frame size is 8 mod 16. - if c.autosize == 8 { - c.autosize += 8 - c.cursym.Func.Locals += 8 + if c.autosize != 0 { + extrasize := int32(0) + if c.autosize%16 == 8 { + // Allocate extra 8 bytes on the frame top to save FP + extrasize = 8 + } else if c.autosize&(16-1) == 0 { + // Allocate extra 16 bytes to save FP for the old frame whose size is 8 mod 16 + extrasize = 16 } else { - c.ctxt.Diag("%v: unaligned frame size %d - must be 8 mod 16 (or 0)", p, c.autosize-8) + c.ctxt.Diag("%v: unaligned frame size %d - must be 16 aligned", p, c.autosize-8) } + c.autosize += extrasize + c.cursym.Func.Locals += extrasize + + // low 32 bits for autosize + // high 32 bits for extrasize + p.To.Offset = int64(c.autosize) | int64(extrasize)<<32 + } else { + // NOFRAME + p.To.Offset = 0 } + if c.autosize == 0 && c.cursym.Func.Text.Mark&LEAF == 0 { if c.ctxt.Debugvlog { c.ctxt.Logf("save suppressed in: %s\n", c.cursym.Func.Text.From.Sym.Name) @@ -565,9 +571,6 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { c.cursym.Func.Text.Mark |= LEAF } - // FP offsets need an updated p.To.Offset. - p.To.Offset = int64(c.autosize) - 8 - if cursym.Func.Text.Mark&LEAF != 0 { cursym.Set(obj.AttrLeaf, true) if p.From.Sym.NoFrame() { @@ -631,6 +634,26 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { q1.Spadj = aoffset } + if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) { + q1 = obj.Appendp(q1, c.newprog) + q1.Pos = p.Pos + q1.As = AMOVD + q1.From.Type = obj.TYPE_REG + q1.From.Reg = REGFP + q1.To.Type = obj.TYPE_MEM + q1.To.Reg = REGSP + q1.To.Offset = -8 + + q1 = obj.Appendp(q1, c.newprog) + q1.Pos = p.Pos + q1.As = ASUB + q1.From.Type = obj.TYPE_CONST + q1.From.Offset = 8 + q1.Reg = REGSP + q1.To.Type = obj.TYPE_REG + q1.To.Reg = REGFP + } + if c.cursym.Func.Text.From.Sym.Wrapper() { // if(g->panic != nil && g->panic->argp == FP) g->panic->argp = bottom-of-frame // @@ -753,9 +776,30 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { p.To.Type = obj.TYPE_REG p.To.Reg = REGSP p.Spadj = -c.autosize + + if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) { + p = obj.Appendp(p, c.newprog) + p.As = ASUB + p.From.Type = obj.TYPE_CONST + p.From.Offset = 8 + p.Reg = REGSP + p.To.Type = obj.TYPE_REG + p.To.Reg = REGFP + } } } else { /* want write-back pre-indexed SP+autosize -> SP, loading REGLINK*/ + + if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) { + p.As = AMOVD + p.From.Type = obj.TYPE_MEM + p.From.Reg = REGSP + p.From.Offset = -8 + p.To.Type = obj.TYPE_REG + p.To.Reg = REGFP + p = obj.Appendp(p, c.newprog) + } + aoffset := c.autosize if aoffset > 0xF0 { @@ -814,7 +858,6 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { p.Spadj = int32(+p.From.Offset) } } - break case obj.AGETCALLERPC: if cursym.Leaf() { @@ -828,6 +871,112 @@ func preprocess(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { p.From.Type = obj.TYPE_MEM p.From.Reg = REGSP } + + case obj.ADUFFCOPY: + if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) { + // ADR ret_addr, R27 + // STP (FP, R27), -24(SP) + // SUB 24, SP, FP + // DUFFCOPY + // ret_addr: + // SUB 8, SP, FP + + q1 := p + // copy DUFFCOPY from q1 to q4 + q4 := obj.Appendp(p, c.newprog) + q4.Pos = p.Pos + q4.As = obj.ADUFFCOPY + q4.To = p.To + + q1.As = AADR + q1.From.Type = obj.TYPE_BRANCH + q1.To.Type = obj.TYPE_REG + q1.To.Reg = REG_R27 + + q2 := obj.Appendp(q1, c.newprog) + q2.Pos = p.Pos + q2.As = ASTP + q2.From.Type = obj.TYPE_REGREG + q2.From.Reg = REGFP + q2.From.Offset = int64(REG_R27) + q2.To.Type = obj.TYPE_MEM + q2.To.Reg = REGSP + q2.To.Offset = -24 + + // maintaine FP for DUFFCOPY + q3 := obj.Appendp(q2, c.newprog) + q3.Pos = p.Pos + q3.As = ASUB + q3.From.Type = obj.TYPE_CONST + q3.From.Offset = 24 + q3.Reg = REGSP + q3.To.Type = obj.TYPE_REG + q3.To.Reg = REGFP + + q5 := obj.Appendp(q4, c.newprog) + q5.Pos = p.Pos + q5.As = ASUB + q5.From.Type = obj.TYPE_CONST + q5.From.Offset = 8 + q5.Reg = REGSP + q5.To.Type = obj.TYPE_REG + q5.To.Reg = REGFP + q1.Pcond = q5 + p = q5 + } + + case obj.ADUFFZERO: + if objabi.Framepointer_enabled(objabi.GOOS, objabi.GOARCH) { + // ADR ret_addr, R27 + // STP (FP, R27), -24(SP) + // SUB 24, SP, FP + // DUFFZERO + // ret_addr: + // SUB 8, SP, FP + + q1 := p + // copy DUFFZERO from q1 to q4 + q4 := obj.Appendp(p, c.newprog) + q4.Pos = p.Pos + q4.As = obj.ADUFFZERO + q4.To = p.To + + q1.As = AADR + q1.From.Type = obj.TYPE_BRANCH + q1.To.Type = obj.TYPE_REG + q1.To.Reg = REG_R27 + + q2 := obj.Appendp(q1, c.newprog) + q2.Pos = p.Pos + q2.As = ASTP + q2.From.Type = obj.TYPE_REGREG + q2.From.Reg = REGFP + q2.From.Offset = int64(REG_R27) + q2.To.Type = obj.TYPE_MEM + q2.To.Reg = REGSP + q2.To.Offset = -24 + + // maintaine FP for DUFFZERO + q3 := obj.Appendp(q2, c.newprog) + q3.Pos = p.Pos + q3.As = ASUB + q3.From.Type = obj.TYPE_CONST + q3.From.Offset = 24 + q3.Reg = REGSP + q3.To.Type = obj.TYPE_REG + q3.To.Reg = REGFP + + q5 := obj.Appendp(q4, c.newprog) + q5.Pos = p.Pos + q5.As = ASUB + q5.From.Type = obj.TYPE_CONST + q5.From.Offset = 8 + q5.Reg = REGSP + q5.To.Type = obj.TYPE_REG + q5.To.Reg = REGFP + q1.Pcond = q5 + p = q5 + } } } } diff --git a/src/cmd/internal/objabi/util.go b/src/cmd/internal/objabi/util.go index a47e2f93a10e9..ffd1c04d39fcd 100644 --- a/src/cmd/internal/objabi/util.go +++ b/src/cmd/internal/objabi/util.go @@ -76,7 +76,7 @@ func init() { } func Framepointer_enabled(goos, goarch string) bool { - return framepointer_enabled != 0 && goarch == "amd64" && goos != "nacl" + return framepointer_enabled != 0 && (goarch == "amd64" && goos != "nacl" || goarch == "arm64" && goos == "linux") } func addexp(s string) { diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 1b6d5d1704712..ba03cb707b84f 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1815,6 +1815,10 @@ func (ctxt *Link) dostkcheck() { ch.up = nil ch.limit = objabi.StackLimit - callsize(ctxt) + if objabi.GOARCH == "arm64" { + // need extra 8 bytes below SP to save FP + ch.limit -= 8 + } // Check every function, but do the nosplit functions in a first pass, // to make the printed failure chains as short as possible. diff --git a/src/runtime/asm_arm64.s b/src/runtime/asm_arm64.s index af389be9fee33..6a6a699241dc5 100644 --- a/src/runtime/asm_arm64.s +++ b/src/runtime/asm_arm64.s @@ -39,10 +39,9 @@ TEXT runtime·rt0_go(SB),NOSPLIT,$0 #endif MOVD $setg_gcc<>(SB), R1 // arg 1: setg MOVD g, R0 // arg 0: G + SUB $16, RSP // reserve 16 bytes for sp-8 where fp may be saved. BL (R12) - MOVD _cgo_init(SB), R12 - CMP $0, R12 - BEQ nocgo + ADD $16, RSP nocgo: // update stackguard after _cgo_init @@ -107,6 +106,7 @@ TEXT runtime·gosave(SB), NOSPLIT|NOFRAME, $0-8 MOVD buf+0(FP), R3 MOVD RSP, R0 MOVD R0, gobuf_sp(R3) + MOVD R29, gobuf_bp(R3) MOVD LR, gobuf_pc(R3) MOVD g, gobuf_g(R3) MOVD ZR, gobuf_lr(R3) @@ -128,10 +128,12 @@ TEXT runtime·gogo(SB), NOSPLIT, $24-8 MOVD 0(g), R4 // make sure g is not nil MOVD gobuf_sp(R5), R0 MOVD R0, RSP + MOVD gobuf_bp(R5), R29 MOVD gobuf_lr(R5), LR MOVD gobuf_ret(R5), R0 MOVD gobuf_ctxt(R5), R26 MOVD $0, gobuf_sp(R5) + MOVD $0, gobuf_bp(R5) MOVD $0, gobuf_ret(R5) MOVD $0, gobuf_lr(R5) MOVD $0, gobuf_ctxt(R5) @@ -147,6 +149,7 @@ TEXT runtime·mcall(SB), NOSPLIT|NOFRAME, $0-8 // Save caller state in g->sched MOVD RSP, R0 MOVD R0, (g_sched+gobuf_sp)(g) + MOVD R29, (g_sched+gobuf_bp)(g) MOVD LR, (g_sched+gobuf_pc)(g) MOVD $0, (g_sched+gobuf_lr)(g) MOVD g, (g_sched+gobuf_g)(g) @@ -163,6 +166,7 @@ TEXT runtime·mcall(SB), NOSPLIT|NOFRAME, $0-8 MOVD 0(R26), R4 // code pointer MOVD (g_sched+gobuf_sp)(g), R0 MOVD R0, RSP // sp = m->g0->sched.sp + MOVD (g_sched+gobuf_bp)(g), R29 MOVD R3, -8(RSP) MOVD $0, -16(RSP) SUB $16, RSP @@ -211,6 +215,7 @@ switch: MOVD R6, (g_sched+gobuf_pc)(g) MOVD RSP, R0 MOVD R0, (g_sched+gobuf_sp)(g) + MOVD R29, (g_sched+gobuf_bp)(g) MOVD $0, (g_sched+gobuf_lr)(g) MOVD g, (g_sched+gobuf_g)(g) @@ -224,6 +229,7 @@ switch: MOVD $runtime·mstart(SB), R4 MOVD R4, 0(R3) MOVD R3, RSP + MOVD (g_sched+gobuf_bp)(g), R29 // call target function MOVD 0(R26), R3 // code pointer @@ -235,7 +241,9 @@ switch: BL runtime·save_g(SB) MOVD (g_sched+gobuf_sp)(g), R0 MOVD R0, RSP + MOVD (g_sched+gobuf_bp)(g), R29 MOVD $0, (g_sched+gobuf_sp)(g) + MOVD $0, (g_sched+gobuf_bp)(g) RET noswitch: @@ -244,6 +252,7 @@ noswitch: // at an intermediate systemstack. MOVD 0(R26), R3 // code pointer MOVD.P 16(RSP), R30 // restore LR + SUB $8, RSP, R29 // restore FP B (R3) /* @@ -278,6 +287,7 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0 // Set g->sched to context in f MOVD RSP, R0 MOVD R0, (g_sched+gobuf_sp)(g) + MOVD R29, (g_sched+gobuf_bp)(g) MOVD LR, (g_sched+gobuf_pc)(g) MOVD R3, (g_sched+gobuf_lr)(g) MOVD R26, (g_sched+gobuf_ctxt)(g) @@ -294,6 +304,7 @@ TEXT runtime·morestack(SB),NOSPLIT|NOFRAME,$0-0 BL runtime·save_g(SB) MOVD (g_sched+gobuf_sp)(g), R0 MOVD R0, RSP + MOVD (g_sched+gobuf_bp)(g), R29 MOVD.W $0, -16(RSP) // create a call frame on g0 (saved LR; keep 16-aligned) BL runtime·newstack(SB) @@ -843,8 +854,9 @@ TEXT runtime·jmpdefer(SB), NOSPLIT|NOFRAME, $0-16 // Save state of caller into g->sched. Smashes R0. TEXT gosave<>(SB),NOSPLIT|NOFRAME,$0 MOVD LR, (g_sched+gobuf_pc)(g) - MOVD RSP, R0 + MOVD RSP, R0 MOVD R0, (g_sched+gobuf_sp)(g) + MOVD R29, (g_sched+gobuf_bp)(g) MOVD $0, (g_sched+gobuf_lr)(g) MOVD $0, (g_sched+gobuf_ret)(g) // Assert ctxt is zero. See func save. @@ -885,6 +897,7 @@ TEXT ·asmcgocall(SB),NOSPLIT,$0-20 BL runtime·save_g(SB) MOVD (g_sched+gobuf_sp)(g), R0 MOVD R0, RSP + MOVD (g_sched+gobuf_bp)(g), R29 MOVD R9, R0 // Now on a scheduling stack (a pthread-created stack). @@ -996,6 +1009,7 @@ needm: MOVD m_g0(R8), R3 MOVD RSP, R0 MOVD R0, (g_sched+gobuf_sp)(R3) + MOVD R29, (g_sched+gobuf_bp)(R3) havem: // Now there's a valid m, and we're running on its m->g0. @@ -1003,7 +1017,7 @@ havem: // Save current sp in m->g0->sched.sp in preparation for // switch back to m->curg stack. // NOTE: unwindm knows that the saved g->sched.sp is at 16(RSP) aka savedsp-16(SP). - // Beware that the frame size is actually 32. + // Beware that the frame size is actually 32+16. MOVD m_g0(R8), R3 MOVD (g_sched+gobuf_sp)(R3), R4 MOVD R4, savedsp-16(SP) @@ -1030,10 +1044,12 @@ havem: BL runtime·save_g(SB) MOVD (g_sched+gobuf_sp)(g), R4 // prepare stack as R4 MOVD (g_sched+gobuf_pc)(g), R5 - MOVD R5, -(24+8)(R4) + MOVD R5, -48(R4) + MOVD (g_sched+gobuf_bp)(g), R5 + MOVD R5, -56(R4) MOVD ctxt+24(FP), R0 - MOVD R0, -(16+8)(R4) - MOVD $-(24+8)(R4), R0 // maintain 16-byte SP alignment + MOVD R0, -40(R4) + MOVD $-48(R4), R0 // maintain 16-byte SP alignment MOVD R0, RSP BL runtime·cgocallbackg(SB) @@ -1041,7 +1057,7 @@ havem: MOVD 0(RSP), R5 MOVD R5, (g_sched+gobuf_pc)(g) MOVD RSP, R4 - ADD $(24+8), R4, R4 + ADD $48, R4, R4 MOVD R4, (g_sched+gobuf_sp)(g) // Switch back to m->g0's stack and restore m->g0->sched.sp. diff --git a/src/runtime/cgocall.go b/src/runtime/cgocall.go index c85033f4bccff..86bd2fb01c096 100644 --- a/src/runtime/cgocall.go +++ b/src/runtime/cgocall.go @@ -268,7 +268,8 @@ func cgocallbackg1(ctxt uintptr) { case "arm64": // On arm64, stack frame is four words and there's a saved LR between // SP and the stack frame and between the stack frame and the arguments. - cb = (*args)(unsafe.Pointer(sp + 5*sys.PtrSize)) + // Additional two words (16-byte alignment) are for saving FP. + cb = (*args)(unsafe.Pointer(sp + 7*sys.PtrSize)) case "amd64": // On amd64, stack frame is two words, plus caller PC. if framepointer_enabled { diff --git a/src/runtime/rt0_darwin_arm64.s b/src/runtime/rt0_darwin_arm64.s index d039a8e0abab2..e3972f492429a 100644 --- a/src/runtime/rt0_darwin_arm64.s +++ b/src/runtime/rt0_darwin_arm64.s @@ -49,7 +49,9 @@ TEXT _rt0_arm64_darwin_lib(SB),NOSPLIT,$168 MOVD _cgo_sys_thread_create(SB), R4 MOVD $_rt0_arm64_darwin_lib_go(SB), R0 MOVD $0, R1 + SUB $16, RSP // reserve 16 bytes for sp-8 where fp may be saved. BL (R4) + ADD $16, RSP // Restore callee-save registers. MOVD 24(RSP), R19 diff --git a/src/runtime/rt0_linux_arm64.s b/src/runtime/rt0_linux_arm64.s index 458f082159dae..a6bc99df56930 100644 --- a/src/runtime/rt0_linux_arm64.s +++ b/src/runtime/rt0_linux_arm64.s @@ -48,7 +48,9 @@ TEXT _rt0_arm64_linux_lib(SB),NOSPLIT,$184 BEQ nocgo MOVD $_rt0_arm64_linux_lib_go(SB), R0 MOVD $0, R1 + SUB $16, RSP // reserve 16 bytes for sp-8 where fp may be saved. BL (R4) + ADD $16, RSP B restore nocgo: diff --git a/src/runtime/sys_linux_arm64.s b/src/runtime/sys_linux_arm64.s index c6afd76a657e2..1c8fce3db649b 100644 --- a/src/runtime/sys_linux_arm64.s +++ b/src/runtime/sys_linux_arm64.s @@ -239,7 +239,7 @@ TEXT runtime·nanotime(SB),NOSPLIT,$24-8 MOVD (g_sched+gobuf_sp)(R3), R1 // Set RSP to g0 stack noswitch: - SUB $16, R1 + SUB $32, R1 BIC $15, R1 MOVD R1, RSP @@ -298,7 +298,9 @@ TEXT runtime·callCgoSigaction(SB),NOSPLIT,$0 MOVD new+8(FP), R1 MOVD old+16(FP), R2 MOVD _cgo_sigaction(SB), R3 + SUB $16, RSP // reserve 16 bytes for sp-8 where fp may be saved. BL R3 + ADD $16, RSP MOVW R0, ret+24(FP) RET @@ -361,7 +363,9 @@ TEXT runtime·callCgoMmap(SB),NOSPLIT,$0 MOVW fd+24(FP), R4 MOVW off+28(FP), R5 MOVD _cgo_mmap(SB), R9 + SUB $16, RSP // reserve 16 bytes for sp-8 where fp may be saved. BL R9 + ADD $16, RSP MOVD R0, ret+32(FP) RET @@ -382,7 +386,9 @@ TEXT runtime·callCgoMunmap(SB),NOSPLIT,$0 MOVD addr+0(FP), R0 MOVD n+8(FP), R1 MOVD _cgo_munmap(SB), R9 + SUB $16, RSP // reserve 16 bytes for sp-8 where fp may be saved. BL R9 + ADD $16, RSP RET TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0 diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index 8370fd75937ed..4c2010493a76a 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -285,7 +285,7 @@ func gentraceback(pc0, sp0, lr0 uintptr, gp *g, skip int, pcbuf *uintptr, max in // If framepointer_enabled and there's a frame, then // there's a saved bp here. - if framepointer_enabled && GOARCH == "amd64" && frame.varp > frame.sp { + if frame.varp > frame.sp && (framepointer_enabled && GOARCH == "amd64" || GOARCH == "arm64") { frame.varp -= sys.RegSize } diff --git a/test/codegen/stack.go b/test/codegen/stack.go index 7e12dbc0eb6bb..0f2f6178c7f4c 100644 --- a/test/codegen/stack.go +++ b/test/codegen/stack.go @@ -16,7 +16,7 @@ import "runtime" // 386:"TEXT\t.*, [$]0-" // amd64:"TEXT\t.*, [$]0-" // arm:"TEXT\t.*, [$]-4-" -// arm64:"TEXT\t.*, [$]-8-" +// arm64:"TEXT\t.*, [$]0-" // mips:"TEXT\t.*, [$]-4-" // ppc64le:"TEXT\t.*, [$]0-" // s390x:"TEXT\t.*, [$]0-" @@ -35,7 +35,7 @@ type T struct { // 386:"TEXT\t.*, [$]0-" // amd64:"TEXT\t.*, [$]0-" // arm:"TEXT\t.*, [$]0-" (spills return address) -// arm64:"TEXT\t.*, [$]-8-" +// arm64:"TEXT\t.*, [$]0-" // mips:"TEXT\t.*, [$]-4-" // ppc64le:"TEXT\t.*, [$]0-" // s390x:"TEXT\t.*, [$]0-" @@ -50,7 +50,7 @@ func ZeroLargeStruct(x *T) { // - 386 fails due to spilling a register // amd64:"TEXT\t.*, [$]0-" // arm:"TEXT\t.*, [$]0-" (spills return address) -// arm64:"TEXT\t.*, [$]-8-" +// arm64:"TEXT\t.*, [$]0-" // ppc64le:"TEXT\t.*, [$]0-" // s390x:"TEXT\t.*, [$]0-" // Note: that 386 currently has to spill a register. @@ -64,7 +64,7 @@ func KeepWanted(t *T) { // - 386 fails due to spilling a register // - arm & mips fail due to softfloat calls // amd64:"TEXT\t.*, [$]0-" -// arm64:"TEXT\t.*, [$]-8-" +// arm64:"TEXT\t.*, [$]0-" // ppc64le:"TEXT\t.*, [$]0-" // s390x:"TEXT\t.*, [$]0-" func ArrayAdd64(a, b [4]float64) [4]float64 { @@ -76,7 +76,7 @@ func ArrayAdd64(a, b [4]float64) [4]float64 { // 386:"TEXT\t.*, [$]0-" // amd64:"TEXT\t.*, [$]0-" // arm:"TEXT\t.*, [$]0-" (spills return address) -// arm64:"TEXT\t.*, [$]-8-" +// arm64:"TEXT\t.*, [$]0-" // mips:"TEXT\t.*, [$]-4-" // ppc64le:"TEXT\t.*, [$]0-" // s390x:"TEXT\t.*, [$]0-" diff --git a/test/nosplit.go b/test/nosplit.go index e6cd04e563060..8b61c9e96d142 100644 --- a/test/nosplit.go +++ b/test/nosplit.go @@ -118,11 +118,11 @@ main 136 # (CallSize is 32 on ppc64, 8 on amd64 for frame pointer.) main 96 nosplit main 100 nosplit; REJECT ppc64 ppc64le -main 104 nosplit; REJECT ppc64 ppc64le +main 104 nosplit; REJECT ppc64 ppc64le arm64 main 108 nosplit; REJECT ppc64 ppc64le -main 112 nosplit; REJECT ppc64 ppc64le +main 112 nosplit; REJECT ppc64 ppc64le arm64 main 116 nosplit; REJECT ppc64 ppc64le -main 120 nosplit; REJECT ppc64 ppc64le amd64 +main 120 nosplit; REJECT ppc64 ppc64le amd64 arm64 main 124 nosplit; REJECT ppc64 ppc64le amd64 main 128 nosplit; REJECT main 132 nosplit; REJECT @@ -136,11 +136,11 @@ main 136 nosplit; REJECT # Because AMD64 uses frame pointer, it has 8 fewer bytes. main 96 nosplit call f; f 0 nosplit main 100 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le -main 104 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le +main 104 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le arm64 main 108 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le -main 112 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 +main 112 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 arm64 main 116 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 -main 120 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 +main 124 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 arm64 main 124 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 386 main 128 nosplit call f; f 0 nosplit; REJECT main 132 nosplit call f; f 0 nosplit; REJECT @@ -152,11 +152,11 @@ main 136 nosplit call f; f 0 nosplit; REJECT # Architectures differ in the same way as before. main 96 nosplit call f; f 0 call f main 100 nosplit call f; f 0 call f; REJECT ppc64 ppc64le -main 104 nosplit call f; f 0 call f; REJECT ppc64 ppc64le amd64 +main 104 nosplit call f; f 0 call f; REJECT ppc64 ppc64le amd64 arm64 main 108 nosplit call f; f 0 call f; REJECT ppc64 ppc64le amd64 -main 112 nosplit call f; f 0 call f; REJECT ppc64 ppc64le amd64 +main 112 nosplit call f; f 0 call f; REJECT ppc64 ppc64le amd64 arm64 main 116 nosplit call f; f 0 call f; REJECT ppc64 ppc64le amd64 -main 120 nosplit call f; f 0 call f; REJECT ppc64 ppc64le amd64 386 +main 120 nosplit call f; f 0 call f; REJECT ppc64 ppc64le amd64 386 arm64 main 124 nosplit call f; f 0 call f; REJECT ppc64 ppc64le amd64 386 main 128 nosplit call f; f 0 call f; REJECT main 132 nosplit call f; f 0 call f; REJECT @@ -165,11 +165,11 @@ main 136 nosplit call f; f 0 call f; REJECT # Indirect calls are assumed to be splitting functions. main 96 nosplit callind main 100 nosplit callind; REJECT ppc64 ppc64le -main 104 nosplit callind; REJECT ppc64 ppc64le amd64 +main 104 nosplit callind; REJECT ppc64 ppc64le amd64 arm64 main 108 nosplit callind; REJECT ppc64 ppc64le amd64 -main 112 nosplit callind; REJECT ppc64 ppc64le amd64 +main 112 nosplit callind; REJECT ppc64 ppc64le amd64 arm64 main 116 nosplit callind; REJECT ppc64 ppc64le amd64 -main 120 nosplit callind; REJECT ppc64 ppc64le amd64 386 +main 120 nosplit callind; REJECT ppc64 ppc64le amd64 386 arm64 main 124 nosplit callind; REJECT ppc64 ppc64le amd64 386 main 128 nosplit callind; REJECT main 132 nosplit callind; REJECT @@ -319,7 +319,7 @@ TestCases: } } - if size%ptrSize == 4 || goarch == "arm64" && size != 0 && (size+8)%16 != 0 { + if size%ptrSize == 4 { continue TestCases } nosplit := m[3] From 6fa08c0fdbc8435d0a7b0c2576ba2183adfac8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 29 Aug 2018 07:06:31 -0600 Subject: [PATCH 0229/1663] text/template: fix newline counting in raw strings MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lexRawQuote already uses the next method, which keeps track of newlines on a character by character basis. Adding up newlines in emit again results in the newlines being counted twice, which can mean bad position information in error messages. Fix that, and add a test. Fixes #27319. Change-Id: Id803be065c541412dc808d388bc6d8a86a0de41e Reviewed-on: https://go-review.googlesource.com/131996 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/text/template/parse/lex.go | 2 +- src/text/template/parse/parse_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/text/template/parse/lex.go b/src/text/template/parse/lex.go index fc259f351ed5f..c0843af6ede95 100644 --- a/src/text/template/parse/lex.go +++ b/src/text/template/parse/lex.go @@ -155,7 +155,7 @@ func (l *lexer) emit(t itemType) { l.items <- item{t, l.start, l.input[l.start:l.pos], l.line} // Some items contain text internally. If so, count their newlines. switch t { - case itemText, itemRawString, itemLeftDelim, itemRightDelim: + case itemText, itemLeftDelim, itemRightDelim: l.line += strings.Count(l.input[l.start:l.pos], "\n") } l.start = l.pos diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go index c1f80c1326bc3..d03987581c958 100644 --- a/src/text/template/parse/parse_test.go +++ b/src/text/template/parse/parse_test.go @@ -447,6 +447,9 @@ var errorTests = []parseTest{ {"emptypipeline", `{{ ( ) }}`, hasError, `missing value for parenthesized pipeline`}, + {"multilinerawstring", + "{{ $v := `\n` }} {{", + hasError, `multilinerawstring:2: unexpected unclosed action`}, } func TestErrors(t *testing.T) { From c64006ab5d054396bd86c1c2a71931bb4ecce5ca Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Wed, 29 Aug 2018 16:46:19 +0200 Subject: [PATCH 0230/1663] bytes: note that NewBuffer's initial size can change bytes.NewBuffer's documentation says it can be used to set the initial size of the buffer. The current wording is: > It can also be used to size the internal buffer for writing. This may led users to believe that the buffer (its backing array) is fixed in size and won't grow, which isn't true (subsequent Write calls will expand the backing array as needed). Change the doc to make it clearer that NewBuffer just sets the initial size of the buffer. Fixes #27242 Change-Id: I2a8cb5bee02ca2c1657ef59e2cf1434c7a9bd397 Reviewed-on: https://go-review.googlesource.com/132035 Reviewed-by: Dominik Honnef Reviewed-by: Ian Lance Taylor --- src/bytes/buffer.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bytes/buffer.go b/src/bytes/buffer.go index a2eca2ed129bb..14c5bc38d6689 100644 --- a/src/bytes/buffer.go +++ b/src/bytes/buffer.go @@ -441,9 +441,9 @@ func (b *Buffer) ReadString(delim byte) (line string, err error) { // NewBuffer creates and initializes a new Buffer using buf as its // initial contents. The new Buffer takes ownership of buf, and the // caller should not use buf after this call. NewBuffer is intended to -// prepare a Buffer to read existing data. It can also be used to size -// the internal buffer for writing. To do that, buf should have the -// desired capacity but a length of zero. +// prepare a Buffer to read existing data. It can also be used to set +// the initial size of the internal buffer for writing. To do that, +// buf should have the desired capacity but a length of zero. // // In most cases, new(Buffer) (or just declaring a Buffer variable) is // sufficient to initialize a Buffer. From f9a4ae018d99c5afb0e4f128545ff26e01d7b498 Mon Sep 17 00:00:00 2001 From: Alexey Alexandrov Date: Fri, 27 Jul 2018 00:05:50 -0700 Subject: [PATCH 0231/1663] runtime/pprof: compute memory profile block size using sampled values Fixes #26638. Change-Id: I3c18d1298d99af8ea8c00916303efd2b5a5effc7 Reviewed-on: https://go-review.googlesource.com/126336 Reviewed-by: Hyang-Ah Hana Kim Run-TryBot: Hyang-Ah Hana Kim TryBot-Result: Gobot Gobot --- src/runtime/pprof/protomem.go | 4 ++-- src/runtime/pprof/protomem_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runtime/pprof/protomem.go b/src/runtime/pprof/protomem.go index 82565d5245bfe..1c88aae43a0aa 100644 --- a/src/runtime/pprof/protomem.go +++ b/src/runtime/pprof/protomem.go @@ -56,8 +56,8 @@ func writeHeapProto(w io.Writer, p []runtime.MemProfileRecord, rate int64, defau values[0], values[1] = scaleHeapSample(r.AllocObjects, r.AllocBytes, rate) values[2], values[3] = scaleHeapSample(r.InUseObjects(), r.InUseBytes(), rate) var blockSize int64 - if values[0] > 0 { - blockSize = values[1] / values[0] + if r.AllocObjects > 0 { + blockSize = r.AllocBytes / r.AllocObjects } b.pbSample(values, locs, func() { if blockSize != 0 { diff --git a/src/runtime/pprof/protomem_test.go b/src/runtime/pprof/protomem_test.go index 315d5f0b4d800..471b1ae9c3291 100644 --- a/src/runtime/pprof/protomem_test.go +++ b/src/runtime/pprof/protomem_test.go @@ -48,7 +48,7 @@ func TestConvertMemProfile(t *testing.T) { {ID: 3, Mapping: map2, Address: addr2 + 1}, {ID: 4, Mapping: map2, Address: addr2 + 2}, }, - NumLabel: map[string][]int64{"bytes": {829411}}, + NumLabel: map[string][]int64{"bytes": {512 * 1024}}, }, { Value: []int64{1, 829411, 0, 0}, @@ -57,7 +57,7 @@ func TestConvertMemProfile(t *testing.T) { {ID: 6, Mapping: map1, Address: addr1 + 2}, {ID: 7, Mapping: map2, Address: addr2 + 3}, }, - NumLabel: map[string][]int64{"bytes": {829411}}, + NumLabel: map[string][]int64{"bytes": {512 * 1024}}, }, } for _, tc := range []struct { From 54f9c0416a588963cb5a1c10ffb6a88f3956858c Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Tue, 28 Aug 2018 14:52:30 -0400 Subject: [PATCH 0232/1663] cmd/compile: count nil check as use in dead auto elim Nil check is special in that it has no use but we must keep it. Count it as a use of the auto. Fixes #27278. Change-Id: I857c3d0db2ebdca1bc342b4993c0dac5c01e067f Reviewed-on: https://go-review.googlesource.com/131955 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/deadstore.go | 3 +- test/fixedbugs/issue27278.go | 63 +++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue27278.go diff --git a/src/cmd/compile/internal/ssa/deadstore.go b/src/cmd/compile/internal/ssa/deadstore.go index 1caa61a96600a..69616b3a883c1 100644 --- a/src/cmd/compile/internal/ssa/deadstore.go +++ b/src/cmd/compile/internal/ssa/deadstore.go @@ -197,7 +197,8 @@ func elimDeadAutosGeneric(f *Func) { panic("unhandled op with sym effect") } - if v.Uses == 0 || len(args) == 0 { + if v.Uses == 0 && v.Op != OpNilCheck || len(args) == 0 { + // Nil check has no use, but we need to keep it. return } diff --git a/test/fixedbugs/issue27278.go b/test/fixedbugs/issue27278.go new file mode 100644 index 0000000000000..73f7c755e1e3e --- /dev/null +++ b/test/fixedbugs/issue27278.go @@ -0,0 +1,63 @@ +// run + +// Copyright 2018 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. + +// Issue 27278: dead auto elim deletes an auto and its +// initialization, but it is live because of a nil check. + +package main + +type T struct { + _ [3]string + T2 +} + +func (t *T) M() []string { + return t.T2.M() +} + +type T2 struct { + T3 +} + +func (t *T2) M() []string { + return t.T3.M() +} + +type T3 struct { + a string +} + +func (t *T3) M() []string { + return []string{} +} + +func main() { + poison() + f() +} + +//go:noinline +func f() { + (&T{}).M() + grow(10000) +} + +// grow stack, triggers stack copy +func grow(n int) { + if n == 0 { + return + } + grow(n-1) +} + +// put some junk on stack, which cannot be valid address +//go:noinline +func poison() { + x := [10]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10} + g = x +} + +var g [10]int From bfaffb4e23b956caf6b546c49bd1f28c358d9e2d Mon Sep 17 00:00:00 2001 From: Joe Cortopassi Date: Thu, 30 Aug 2018 03:20:00 +0000 Subject: [PATCH 0233/1663] doc: add Go 1.11 to release history page Fixes issue #27359 Change-Id: I048fbd88a08e8b17fcda3872ee4c78935d5075d8 GitHub-Last-Rev: a0751eca094d68e9bf005abeb6616eb5b0050190 GitHub-Pull-Request: golang/go#27359 Reviewed-on: https://go-review.googlesource.com/132117 Reviewed-by: Brad Fitzpatrick --- doc/devel/release.html | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/devel/release.html b/doc/devel/release.html index e5d834e92826c..a6dd5f9d28223 100644 --- a/doc/devel/release.html +++ b/doc/devel/release.html @@ -23,6 +23,13 @@

    Release Policy

    (for example, Go 1.6.1, Go 1.6.2, and so on).

    +

    go1.11 (released 2018/08/24)

    + +

    +Go 1.11 is a major release of Go. +Read the Go 1.11 Release Notes for more information. +

    +

    go1.10 (released 2018/02/16)

    From c624f8ff704cd682c0a66a8213c326510800bd8a Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 30 Aug 2018 10:08:34 +0000 Subject: [PATCH 0234/1663] syscall: skip TestSyscallNoError on rooted android/arm The system call geteuid can not work properly on android, which causes a test case failed on rooted android/arm. This CL disables the test case on android. Fixes #27364 Change-Id: Ibfd33ef8cc1dfe8822c8be4280eae12ee30929c1 Reviewed-on: https://go-review.googlesource.com/132175 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Tobias Klauser --- src/syscall/syscall_linux_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/syscall/syscall_linux_test.go b/src/syscall/syscall_linux_test.go index 99de6ebaf2fcb..1fd70b07e3ef5 100644 --- a/src/syscall/syscall_linux_test.go +++ b/src/syscall/syscall_linux_test.go @@ -302,6 +302,10 @@ func TestSyscallNoError(t *testing.T) { t.Skip("skipping root only test") } + if runtime.GOOS == "android" { + t.Skip("skipping on rooted android, see issue 27364") + } + // Copy the test binary to a location that a non-root user can read/execute // after we drop privileges tempDir, err := ioutil.TempDir("", "TestSyscallNoError") From 289dce24c173fa2e87db83caa675c964c403553f Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Wed, 29 Aug 2018 14:49:42 -0400 Subject: [PATCH 0235/1663] test: fix nosplit test on 386 The 120->124 change in https://go-review.googlesource.com/c/go/+/61511/21/test/nosplit.go#143 looks accidental. Change back to 120. Change-Id: I1690a8ae2d32756ba05544d2ed1baabfa64e1704 Reviewed-on: https://go-review.googlesource.com/131958 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- test/nosplit.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/nosplit.go b/test/nosplit.go index 8b61c9e96d142..b821d23859d53 100644 --- a/test/nosplit.go +++ b/test/nosplit.go @@ -140,7 +140,7 @@ main 104 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le arm64 main 108 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le main 112 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 arm64 main 116 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 -main 124 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 arm64 +main 120 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 arm64 main 124 nosplit call f; f 0 nosplit; REJECT ppc64 ppc64le amd64 386 main 128 nosplit call f; f 0 nosplit; REJECT main 132 nosplit call f; f 0 nosplit; REJECT From 09df9b06a1e5ff07dd349401795c85360743a3fb Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Tue, 17 Jul 2018 11:02:57 -0400 Subject: [PATCH 0236/1663] cmd/link: split out Extname into cold portion of sym.Symbol Create a new "AuxSymbol" struct into which 'cold' or 'infrequently set' symbol fields are located. Move the Extname field from the main Symbol struct to AuxSymbol. Updates #26186 Change-Id: I9e795fb0cc48f978e2818475fa073ed9f2db202d Reviewed-on: https://go-review.googlesource.com/125476 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/cmd/link/internal/ld/elf.go | 6 +-- src/cmd/link/internal/ld/go.go | 12 ++--- src/cmd/link/internal/ld/lib.go | 4 +- src/cmd/link/internal/ld/macho.go | 8 ++-- src/cmd/link/internal/ld/pe.go | 19 ++++---- src/cmd/link/internal/sym/sizeof_test.go | 2 +- src/cmd/link/internal/sym/symbol.go | 57 +++++++++++++++++------- src/cmd/link/internal/sym/symbols.go | 6 +-- 8 files changed, 70 insertions(+), 44 deletions(-) diff --git a/src/cmd/link/internal/ld/elf.go b/src/cmd/link/internal/ld/elf.go index 4ecbff86a9c5d..f61a290e42d2c 100644 --- a/src/cmd/link/internal/ld/elf.go +++ b/src/cmd/link/internal/ld/elf.go @@ -1034,7 +1034,7 @@ func elfdynhash(ctxt *Link) { need[sy.Dynid] = addelflib(&needlib, sy.Dynimplib(), sy.Dynimpvers()) } - name := sy.Extname + name := sy.Extname() hc := elfhash(name) b := hc % uint32(nbucket) @@ -2254,7 +2254,7 @@ func elfadddynsym(ctxt *Link, s *sym.Symbol) { d := ctxt.Syms.Lookup(".dynsym", 0) - name := s.Extname + name := s.Extname() d.AddUint32(ctxt.Arch, uint32(Addstring(ctxt.Syms.Lookup(".dynstr", 0), name))) /* type */ @@ -2297,7 +2297,7 @@ func elfadddynsym(ctxt *Link, s *sym.Symbol) { d := ctxt.Syms.Lookup(".dynsym", 0) /* name */ - name := s.Extname + name := s.Extname() d.AddUint32(ctxt.Arch, uint32(Addstring(ctxt.Syms.Lookup(".dynstr", 0), name))) diff --git a/src/cmd/link/internal/ld/go.go b/src/cmd/link/internal/ld/go.go index 06ee6968c6804..f2dd799922e50 100644 --- a/src/cmd/link/internal/ld/go.go +++ b/src/cmd/link/internal/ld/go.go @@ -156,7 +156,7 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) { s := ctxt.Syms.Lookup(local, 0) if s.Type == 0 || s.Type == sym.SXREF || s.Type == sym.SHOSTOBJ { s.SetDynimplib(lib) - s.Extname = remote + s.SetExtname(remote) s.SetDynimpvers(q) if s.Type != sym.SHOSTOBJ { s.Type = sym.SDYNIMPORT @@ -200,15 +200,15 @@ func loadcgo(ctxt *Link, file string, pkg string, p string) { // see issue 4878. if s.Dynimplib() != "" { s.ResetDyninfo() - s.Extname = "" + s.SetExtname("") s.Type = 0 } if !s.Attr.CgoExport() { - s.Extname = remote + s.SetExtname(remote) dynexp = append(dynexp, s) - } else if s.Extname != remote { - fmt.Fprintf(os.Stderr, "%s: conflicting cgo_export directives: %s as %s and %s\n", os.Args[0], s.Name, s.Extname, remote) + } else if s.Extname() != remote { + fmt.Fprintf(os.Stderr, "%s: conflicting cgo_export directives: %s as %s and %s\n", os.Args[0], s.Name, s.Extname(), remote) nerrors++ return } @@ -276,7 +276,7 @@ func Adddynsym(ctxt *Link, s *sym.Symbol) { if ctxt.IsELF { elfadddynsym(ctxt, s) } else if ctxt.HeadType == objabi.Hdarwin { - Errorf(s, "adddynsym: missed symbol (Extname=%s)", s.Extname) + Errorf(s, "adddynsym: missed symbol (Extname=%s)", s.Extname()) } else if ctxt.HeadType == objabi.Hwindows { // already taken care of } else { diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index ba03cb707b84f..511cdd891a283 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -435,7 +435,7 @@ func (ctxt *Link) loadlib() { // cgo_import_static and cgo_import_dynamic, // then we want to make it cgo_import_dynamic // now. - if s.Extname != "" && s.Dynimplib() != "" && !s.Attr.CgoExport() { + if s.Extname() != "" && s.Dynimplib() != "" && !s.Attr.CgoExport() { s.Type = sym.SDYNIMPORT } else { s.Type = 0 @@ -2116,7 +2116,7 @@ func genasmsym(ctxt *Link, put func(*Link, *sym.Symbol, string, SymbolType, int6 if !s.Attr.Reachable() { continue } - put(ctxt, s, s.Extname, UndefinedSym, 0, nil) + put(ctxt, s, s.Extname(), UndefinedSym, 0, nil) case sym.STLSBSS: if ctxt.LinkMode == LinkExternal { diff --git a/src/cmd/link/internal/ld/macho.go b/src/cmd/link/internal/ld/macho.go index 8315de5152d04..b935814ff0a43 100644 --- a/src/cmd/link/internal/ld/macho.go +++ b/src/cmd/link/internal/ld/macho.go @@ -724,7 +724,7 @@ func (x machoscmp) Less(i, j int) bool { return k1 < k2 } - return s1.Extname < s2.Extname + return s1.Extname() < s2.Extname() } func machogenasmsym(ctxt *Link) { @@ -763,7 +763,7 @@ func machoShouldExport(ctxt *Link, s *sym.Symbol) bool { if !ctxt.DynlinkingGo() || s.Attr.Local() { return false } - if ctxt.BuildMode == BuildModePlugin && strings.HasPrefix(s.Extname, objabi.PathToPrefix(*flagPluginPath)) { + if ctxt.BuildMode == BuildModePlugin && strings.HasPrefix(s.Extname(), objabi.PathToPrefix(*flagPluginPath)) { return true } if strings.HasPrefix(s.Name, "go.itab.") { @@ -798,13 +798,13 @@ func machosymtab(ctxt *Link) { // symbols like crosscall2 are in pclntab and end up // pointing at the host binary, breaking unwinding. // See Issue #18190. - cexport := !strings.Contains(s.Extname, ".") && (ctxt.BuildMode != BuildModePlugin || onlycsymbol(s)) + cexport := !strings.Contains(s.Extname(), ".") && (ctxt.BuildMode != BuildModePlugin || onlycsymbol(s)) if cexport || export { symstr.AddUint8('_') } // replace "·" as ".", because DTrace cannot handle it. - Addstring(symstr, strings.Replace(s.Extname, "·", ".", -1)) + Addstring(symstr, strings.Replace(s.Extname(), "·", ".", -1)) if s.Type == sym.SDYNIMPORT || s.Type == sym.SHOSTOBJ { symtab.AddUint8(0x01) // type N_EXT, external symbol diff --git a/src/cmd/link/internal/ld/pe.go b/src/cmd/link/internal/ld/pe.go index 0e60ef76d218f..db269c78e5313 100644 --- a/src/cmd/link/internal/ld/pe.go +++ b/src/cmd/link/internal/ld/pe.go @@ -1040,14 +1040,15 @@ func initdynimport(ctxt *Link) *Dll { // of uinptrs this function consumes. Store the argsize and discard // the %n suffix if any. m.argsize = -1 - if i := strings.IndexByte(s.Extname, '%'); i >= 0 { + extName := s.Extname() + if i := strings.IndexByte(extName, '%'); i >= 0 { var err error - m.argsize, err = strconv.Atoi(s.Extname[i+1:]) + m.argsize, err = strconv.Atoi(extName[i+1:]) if err != nil { Errorf(s, "failed to parse stdcall decoration: %v", err) } m.argsize *= ctxt.Arch.PtrSize - s.Extname = s.Extname[:i] + s.SetExtname(extName[:i]) } m.s = s @@ -1061,7 +1062,7 @@ func initdynimport(ctxt *Link) *Dll { for m = d.ms; m != nil; m = m.next { m.s.Type = sym.SDATA m.s.Grow(int64(ctxt.Arch.PtrSize)) - dynName := m.s.Extname + dynName := m.s.Extname() // only windows/386 requires stdcall decoration if ctxt.Arch.Family == sys.I386 && m.argsize >= 0 { dynName += fmt.Sprintf("@%d", m.argsize) @@ -1132,7 +1133,7 @@ func addimports(ctxt *Link, datsect *peSection) { for m := d.ms; m != nil; m = m.next { m.off = uint64(pefile.nextSectOffset) + uint64(ctxt.Out.Offset()) - uint64(startoff) ctxt.Out.Write16(0) // hint - strput(ctxt.Out, m.s.Extname) + strput(ctxt.Out, m.s.Extname()) } } @@ -1217,7 +1218,7 @@ type byExtname []*sym.Symbol func (s byExtname) Len() int { return len(s) } func (s byExtname) Swap(i, j int) { s[i], s[j] = s[j], s[i] } -func (s byExtname) Less(i, j int) bool { return s[i].Extname < s[j].Extname } +func (s byExtname) Less(i, j int) bool { return s[i].Extname() < s[j].Extname() } func initdynexport(ctxt *Link) { nexport = 0 @@ -1242,7 +1243,7 @@ func addexports(ctxt *Link) { size := binary.Size(&e) + 10*nexport + len(*flagOutfile) + 1 for i := 0; i < nexport; i++ { - size += len(dexport[i].Extname) + 1 + size += len(dexport[i].Extname()) + 1 } if nexport == 0 { @@ -1286,7 +1287,7 @@ func addexports(ctxt *Link) { for i := 0; i < nexport; i++ { out.Write32(uint32(v)) - v += len(dexport[i].Extname) + 1 + v += len(dexport[i].Extname()) + 1 } // put EXPORT Ordinal Table @@ -1298,7 +1299,7 @@ func addexports(ctxt *Link) { out.WriteStringN(*flagOutfile, len(*flagOutfile)+1) for i := 0; i < nexport; i++ { - out.WriteStringN(dexport[i].Extname, len(dexport[i].Extname)+1) + out.WriteStringN(dexport[i].Extname(), len(dexport[i].Extname())+1) } sect.pad(out, uint32(size)) } diff --git a/src/cmd/link/internal/sym/sizeof_test.go b/src/cmd/link/internal/sym/sizeof_test.go index 2f2dfc79ed0d1..5d501bda499c2 100644 --- a/src/cmd/link/internal/sym/sizeof_test.go +++ b/src/cmd/link/internal/sym/sizeof_test.go @@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) { _32bit uintptr // size on 32bit platforms _64bit uintptr // size on 64bit platforms }{ - {Symbol{}, 132, 216}, + {Symbol{}, 124, 200}, } for _, tt := range tests { diff --git a/src/cmd/link/internal/sym/symbol.go b/src/cmd/link/internal/sym/symbol.go index ea0eb89e2bc99..245d62003baa1 100644 --- a/src/cmd/link/internal/sym/symbol.go +++ b/src/cmd/link/internal/sym/symbol.go @@ -15,7 +15,6 @@ import ( // Symbol is an entry in the symbol table. type Symbol struct { Name string - Extname string Type SymKind Version int16 Attr Attribute @@ -36,7 +35,7 @@ type Symbol struct { Outer *Symbol Gotype *Symbol File string - dyninfo *dynimp + auxinfo *AuxSymbol Sect *Section FuncInfo *FuncInfo Lib *Library // Package defining this symbol @@ -45,7 +44,9 @@ type Symbol struct { R []Reloc } -type dynimp struct { +// AuxSymbol contains less-frequently used sym.Symbol fields. +type AuxSymbol struct { + extname string dynimplib string dynimpvers string } @@ -268,38 +269,62 @@ func (s *Symbol) setUintXX(arch *sys.Arch, off int64, v uint64, wid int64) int64 return off + wid } +func (s *Symbol) makeAuxInfo() { + if s.auxinfo == nil { + s.auxinfo = &AuxSymbol{extname: s.Name} + } +} + +func (s *Symbol) Extname() string { + if s.auxinfo == nil { + return s.Name + } + return s.auxinfo.extname +} + +func (s *Symbol) SetExtname(n string) { + if s.auxinfo == nil { + if s.Name == n { + return + } + s.makeAuxInfo() + } + s.auxinfo.extname = n +} + func (s *Symbol) Dynimplib() string { - if s.dyninfo == nil { + if s.auxinfo == nil { return "" } - return s.dyninfo.dynimplib + return s.auxinfo.dynimplib } func (s *Symbol) Dynimpvers() string { - if s.dyninfo == nil { + if s.auxinfo == nil { return "" } - return s.dyninfo.dynimpvers + return s.auxinfo.dynimpvers } func (s *Symbol) SetDynimplib(lib string) { - if s.dyninfo == nil { - s.dyninfo = &dynimp{dynimplib: lib} - } else { - s.dyninfo.dynimplib = lib + if s.auxinfo == nil { + s.makeAuxInfo() } + s.auxinfo.dynimplib = lib } func (s *Symbol) SetDynimpvers(vers string) { - if s.dyninfo == nil { - s.dyninfo = &dynimp{dynimpvers: vers} - } else { - s.dyninfo.dynimpvers = vers + if s.auxinfo == nil { + s.makeAuxInfo() } + s.auxinfo.dynimpvers = vers } func (s *Symbol) ResetDyninfo() { - s.dyninfo = nil + if s.auxinfo != nil { + s.auxinfo.dynimplib = "" + s.auxinfo.dynimpvers = "" + } } // SortSub sorts a linked-list (by Sub) of *Symbol by Value. diff --git a/src/cmd/link/internal/sym/symbols.go b/src/cmd/link/internal/sym/symbols.go index f9405db185373..7c6137c73c978 100644 --- a/src/cmd/link/internal/sym/symbols.go +++ b/src/cmd/link/internal/sym/symbols.go @@ -77,7 +77,6 @@ func (syms *Symbols) Lookup(name string, v int) *Symbol { return s } s = syms.Newsym(name, v) - s.Extname = s.Name m[name] = s return s } @@ -97,9 +96,10 @@ func (syms *Symbols) IncVersion() int { // Rename renames a symbol. func (syms *Symbols) Rename(old, new string, v int, reachparent map[*Symbol]*Symbol) { s := syms.hash[v][old] + oldExtName := s.Extname() s.Name = new - if s.Extname == old { - s.Extname = new + if oldExtName == old { + s.SetExtname(new) } delete(syms.hash[v], old) From 2975914a1a0b60132352cf0c34a39bea1197d789 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Tue, 17 Jul 2018 14:38:34 -0400 Subject: [PATCH 0237/1663] cmd/link: move Localentry field in sym.Symbol to cold section The sym.Symbol 'Localentry' field is used only with cgo and/or external linking on MachoPPC. Relocate it to sym.AuxSymbol since it is infrequently used, so as to shrink the main Symbol struct. Updates #26186 Change-Id: I5872aa3f059270c2a091016d235a1a732695e411 Reviewed-on: https://go-review.googlesource.com/125477 Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/loadelf/ldelf.go | 2 +- src/cmd/link/internal/ppc64/asm.go | 2 +- src/cmd/link/internal/sym/sizeof_test.go | 2 +- src/cmd/link/internal/sym/symbol.go | 19 ++++++++++++++++++- 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/cmd/link/internal/loadelf/ldelf.go b/src/cmd/link/internal/loadelf/ldelf.go index 8e32e7dee6190..d85d91948a750 100644 --- a/src/cmd/link/internal/loadelf/ldelf.go +++ b/src/cmd/link/internal/loadelf/ldelf.go @@ -820,7 +820,7 @@ func Load(arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, pkg string, length i if elfobj.machine == ElfMachPower64 { flag := int(elfsym.other) >> 5 if 2 <= flag && flag <= 6 { - s.Localentry = 1 << uint(flag-2) + s.SetLocalentry(1 << uint(flag-2)) } else if flag == 7 { return errorf("%v: invalid sym.other 0x%x", s, elfsym.other) } diff --git a/src/cmd/link/internal/ppc64/asm.go b/src/cmd/link/internal/ppc64/asm.go index 825366c567a7a..2baa9c1de191b 100644 --- a/src/cmd/link/internal/ppc64/asm.go +++ b/src/cmd/link/internal/ppc64/asm.go @@ -280,7 +280,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { // callee. Hence, we need to go to the local entry // point. (If we don't do this, the callee will try // to use r12 to compute r2.) - r.Add += int64(r.Sym.Localentry) * 4 + r.Add += int64(r.Sym.Localentry()) * 4 if targ.Type == sym.SDYNIMPORT { // Should have been handled in elfsetupplt diff --git a/src/cmd/link/internal/sym/sizeof_test.go b/src/cmd/link/internal/sym/sizeof_test.go index 5d501bda499c2..814ec42373974 100644 --- a/src/cmd/link/internal/sym/sizeof_test.go +++ b/src/cmd/link/internal/sym/sizeof_test.go @@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) { _32bit uintptr // size on 32bit platforms _64bit uintptr // size on 64bit platforms }{ - {Symbol{}, 124, 200}, + {Symbol{}, 120, 192}, } for _, tt := range tests { diff --git a/src/cmd/link/internal/sym/symbol.go b/src/cmd/link/internal/sym/symbol.go index 245d62003baa1..7739737591a16 100644 --- a/src/cmd/link/internal/sym/symbol.go +++ b/src/cmd/link/internal/sym/symbol.go @@ -18,7 +18,6 @@ type Symbol struct { Type SymKind Version int16 Attr Attribute - Localentry uint8 Dynid int32 Plt int32 Got int32 @@ -49,6 +48,7 @@ type AuxSymbol struct { extname string dynimplib string dynimpvers string + localentry uint8 } func (s *Symbol) String() string { @@ -327,6 +327,23 @@ func (s *Symbol) ResetDyninfo() { } } +func (s *Symbol) Localentry() uint8 { + if s.auxinfo == nil { + return 0 + } + return s.auxinfo.localentry +} + +func (s *Symbol) SetLocalentry(val uint8) { + if s.auxinfo == nil { + if val != 0 { + return + } + s.makeAuxInfo() + } + s.auxinfo.localentry = val +} + // SortSub sorts a linked-list (by Sub) of *Symbol by Value. // Used for sub-symbols when loading host objects (see e.g. ldelf.go). func SortSub(l *Symbol) *Symbol { From f78cc1324a95b964f932b965a82f3c786cb1d932 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Tue, 17 Jul 2018 15:36:30 -0400 Subject: [PATCH 0238/1663] cmd/link: move Plt, Got fields in sym.Symbol to cold section The sym.Symbol 'Plt' and 'Got' field are used only with cgo and/or external linking and are not needed for most symbols. Relocate them to sym.AuxSymbol so as to shrink the main Symbol struct. Updates #26186 Change-Id: I170d628a760be300a0c1f738f0998970e91ce3d6 Reviewed-on: https://go-review.googlesource.com/125478 Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/amd64/asm.go | 28 ++++++++--------- src/cmd/link/internal/arm/asm.go | 32 +++++++++---------- src/cmd/link/internal/ld/data.go | 10 +++--- src/cmd/link/internal/loadpe/ldpe.go | 4 +-- src/cmd/link/internal/ppc64/asm.go | 10 +++--- src/cmd/link/internal/s390x/asm.go | 16 +++++----- src/cmd/link/internal/sym/sizeof_test.go | 2 +- src/cmd/link/internal/sym/symbol.go | 40 ++++++++++++++++++++++-- src/cmd/link/internal/sym/symbols.go | 2 -- src/cmd/link/internal/x86/asm.go | 24 +++++++------- 10 files changed, 100 insertions(+), 68 deletions(-) diff --git a/src/cmd/link/internal/amd64/asm.go b/src/cmd/link/internal/amd64/asm.go index 66aab3f748ee2..829635d219763 100644 --- a/src/cmd/link/internal/amd64/asm.go +++ b/src/cmd/link/internal/amd64/asm.go @@ -139,7 +139,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { if targ.Type == sym.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add += int64(targ.Plt) + r.Add += int64(targ.Plt()) } return true @@ -164,7 +164,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { r.Type = objabi.R_PCREL r.Sym = ctxt.Syms.Lookup(".got", 0) r.Add += 4 - r.Add += int64(targ.Got) + r.Add += int64(targ.Got()) return true case 256 + objabi.RelocType(elf.R_X86_64_64): @@ -190,7 +190,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { if targ.Type == sym.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add = int64(targ.Plt) + r.Add = int64(targ.Plt()) r.Type = objabi.R_PCREL return true } @@ -230,7 +230,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { addgotsym(ctxt, targ) r.Type = objabi.R_PCREL r.Sym = ctxt.Syms.Lookup(".got", 0) - r.Add += int64(targ.Got) + r.Add += int64(targ.Got()) return true } @@ -249,7 +249,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { // Build a PLT entry and change the relocation target to that entry. addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add = int64(targ.Plt) + r.Add = int64(targ.Plt()) return true case objabi.R_ADDR: @@ -257,7 +257,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { if ctxt.HeadType == objabi.Hsolaris { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add += int64(targ.Plt) + r.Add += int64(targ.Plt()) return true } // The code is asking for the address of an external @@ -266,7 +266,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { addgotsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".got", 0) - r.Add += int64(targ.Got) + r.Add += int64(targ.Got()) return true } @@ -567,7 +567,7 @@ func elfsetupplt(ctxt *ld.Link) { } func addpltsym(ctxt *ld.Link, s *sym.Symbol) { - if s.Plt >= 0 { + if s.Plt() >= 0 { return } @@ -606,7 +606,7 @@ func addpltsym(ctxt *ld.Link, s *sym.Symbol) { rela.AddUint64(ctxt.Arch, ld.ELF64_R_INFO(uint32(s.Dynid), uint32(elf.R_X86_64_JMP_SLOT))) rela.AddUint64(ctxt.Arch, 0) - s.Plt = int32(plt.Size - 16) + s.SetPlt(int32(plt.Size - 16)) } else if ctxt.HeadType == objabi.Hdarwin { // To do lazy symbol lookup right, we're supposed // to tell the dynamic loader which library each @@ -624,29 +624,29 @@ func addpltsym(ctxt *ld.Link, s *sym.Symbol) { ctxt.Syms.Lookup(".linkedit.plt", 0).AddUint32(ctxt.Arch, uint32(s.Dynid)) // jmpq *got+size(IP) - s.Plt = int32(plt.Size) + s.SetPlt(int32(plt.Size)) plt.AddUint8(0xff) plt.AddUint8(0x25) - plt.AddPCRelPlus(ctxt.Arch, ctxt.Syms.Lookup(".got", 0), int64(s.Got)) + plt.AddPCRelPlus(ctxt.Arch, ctxt.Syms.Lookup(".got", 0), int64(s.Got())) } else { ld.Errorf(s, "addpltsym: unsupported binary format") } } func addgotsym(ctxt *ld.Link, s *sym.Symbol) { - if s.Got >= 0 { + if s.Got() >= 0 { return } ld.Adddynsym(ctxt, s) got := ctxt.Syms.Lookup(".got", 0) - s.Got = int32(got.Size) + s.SetGot(int32(got.Size)) got.AddUint64(ctxt.Arch, 0) if ctxt.IsELF { rela := ctxt.Syms.Lookup(".rela", 0) - rela.AddAddrPlus(ctxt.Arch, got, int64(s.Got)) + rela.AddAddrPlus(ctxt.Arch, got, int64(s.Got())) rela.AddUint64(ctxt.Arch, ld.ELF64_R_INFO(uint32(s.Dynid), uint32(elf.R_X86_64_GLOB_DAT))) rela.AddUint64(ctxt.Arch, 0) } else if ctxt.HeadType == objabi.Hdarwin { diff --git a/src/cmd/link/internal/arm/asm.go b/src/cmd/link/internal/arm/asm.go index b1d44b5896fd7..efcd41d72b0f6 100644 --- a/src/cmd/link/internal/arm/asm.go +++ b/src/cmd/link/internal/arm/asm.go @@ -132,7 +132,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { if targ.Type == sym.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add = int64(braddoff(int32(r.Add), targ.Plt/4)) + r.Add = int64(braddoff(int32(r.Add), targ.Plt()/4)) } return true @@ -150,7 +150,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { r.Type = objabi.R_CONST // write r->add during relocsym r.Sym = nil - r.Add += int64(targ.Got) + r.Add += int64(targ.Got()) return true case 256 + objabi.RelocType(elf.R_ARM_GOT_PREL): // GOT(nil) + A - nil @@ -162,7 +162,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { r.Type = objabi.R_PCREL r.Sym = ctxt.Syms.Lookup(".got", 0) - r.Add += int64(targ.Got) + 4 + r.Add += int64(targ.Got()) + 4 return true case 256 + objabi.RelocType(elf.R_ARM_GOTOFF): // R_ARM_GOTOFF32 @@ -182,7 +182,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { if targ.Type == sym.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add = int64(braddoff(int32(r.Add), targ.Plt/4)) + r.Add = int64(braddoff(int32(r.Add), targ.Plt()/4)) } return true @@ -216,7 +216,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { if targ.Type == sym.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add = int64(braddoff(int32(r.Add), targ.Plt/4)) + r.Add = int64(braddoff(int32(r.Add), targ.Plt()/4)) } return true @@ -235,7 +235,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { } addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add = int64(targ.Plt) + r.Add = int64(targ.Plt()) return true case objabi.R_ADDR: @@ -678,7 +678,7 @@ func addpltreloc(ctxt *ld.Link, plt *sym.Symbol, got *sym.Symbol, s *sym.Symbol, r.Off = int32(plt.Size) r.Siz = 4 r.Type = typ - r.Add = int64(s.Got) - 8 + r.Add = int64(s.Got()) - 8 plt.Attr |= sym.AttrReachable plt.Size += 4 @@ -686,7 +686,7 @@ func addpltreloc(ctxt *ld.Link, plt *sym.Symbol, got *sym.Symbol, s *sym.Symbol, } func addpltsym(ctxt *ld.Link, s *sym.Symbol) { - if s.Plt >= 0 { + if s.Plt() >= 0 { return } @@ -701,7 +701,7 @@ func addpltsym(ctxt *ld.Link, s *sym.Symbol) { } // .got entry - s.Got = int32(got.Size) + s.SetGot(int32(got.Size)) // In theory, all GOT should point to the first PLT entry, // Linux/ARM's dynamic linker will do that for us, but FreeBSD/ARM's @@ -709,14 +709,14 @@ func addpltsym(ctxt *ld.Link, s *sym.Symbol) { got.AddAddrPlus(ctxt.Arch, plt, 0) // .plt entry, this depends on the .got entry - s.Plt = int32(plt.Size) + s.SetPlt(int32(plt.Size)) addpltreloc(ctxt, plt, got, s, objabi.R_PLT0) // add lr, pc, #0xXX00000 addpltreloc(ctxt, plt, got, s, objabi.R_PLT1) // add lr, lr, #0xYY000 addpltreloc(ctxt, plt, got, s, objabi.R_PLT2) // ldr pc, [lr, #0xZZZ]! // rel - rel.AddAddrPlus(ctxt.Arch, got, int64(s.Got)) + rel.AddAddrPlus(ctxt.Arch, got, int64(s.Got())) rel.AddUint32(ctxt.Arch, ld.ELF32_R_INFO(uint32(s.Dynid), uint32(elf.R_ARM_JUMP_SLOT))) } else { @@ -725,12 +725,12 @@ func addpltsym(ctxt *ld.Link, s *sym.Symbol) { } func addgotsyminternal(ctxt *ld.Link, s *sym.Symbol) { - if s.Got >= 0 { + if s.Got() >= 0 { return } got := ctxt.Syms.Lookup(".got", 0) - s.Got = int32(got.Size) + s.SetGot(int32(got.Size)) got.AddAddrPlus(ctxt.Arch, s, 0) @@ -741,18 +741,18 @@ func addgotsyminternal(ctxt *ld.Link, s *sym.Symbol) { } func addgotsym(ctxt *ld.Link, s *sym.Symbol) { - if s.Got >= 0 { + if s.Got() >= 0 { return } ld.Adddynsym(ctxt, s) got := ctxt.Syms.Lookup(".got", 0) - s.Got = int32(got.Size) + s.SetGot(int32(got.Size)) got.AddUint32(ctxt.Arch, 0) if ctxt.IsELF { rel := ctxt.Syms.Lookup(".rel", 0) - rel.AddAddrPlus(ctxt.Arch, got, int64(s.Got)) + rel.AddAddrPlus(ctxt.Arch, got, int64(s.Got())) rel.AddUint32(ctxt.Arch, ld.ELF32_R_INFO(uint32(s.Dynid), uint32(elf.R_ARM_GLOB_DAT))) } else { ld.Errorf(s, "addgotsym: unsupported binary format") diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index 3070fdbb35591..ff0d3a8d84e55 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -546,10 +546,10 @@ func windynrelocsym(ctxt *Link, s *sym.Symbol) { } Errorf(s, "dynamic relocation to unreachable symbol %s", targ.Name) } - if r.Sym.Plt == -2 && r.Sym.Got != -2 { // make dynimport JMP table for PE object files. - targ.Plt = int32(rel.Size) + if r.Sym.Plt() == -2 && r.Sym.Got() != -2 { // make dynimport JMP table for PE object files. + targ.SetPlt(int32(rel.Size)) r.Sym = rel - r.Add = int64(targ.Plt) + r.Add = int64(targ.Plt()) // jmp *addr switch ctxt.Arch.Family { @@ -569,9 +569,9 @@ func windynrelocsym(ctxt *Link, s *sym.Symbol) { rel.AddAddrPlus4(targ, 0) rel.AddUint8(0x90) } - } else if r.Sym.Plt >= 0 { + } else if r.Sym.Plt() >= 0 { r.Sym = rel - r.Add = int64(targ.Plt) + r.Add = int64(targ.Plt()) } } } diff --git a/src/cmd/link/internal/loadpe/ldpe.go b/src/cmd/link/internal/loadpe/ldpe.go index f78252c283a34..ac07d5c35d20e 100644 --- a/src/cmd/link/internal/loadpe/ldpe.go +++ b/src/cmd/link/internal/loadpe/ldpe.go @@ -358,7 +358,7 @@ func Load(arch *sys.Arch, syms *sym.Symbols, input *bio.Reader, pkg string, leng if pesym.SectionNumber == 0 { // extern if s.Type == sym.SDYNIMPORT { - s.Plt = -2 // flag for dynimport in PE object files. + s.SetPlt(-2) // flag for dynimport in PE object files. } if s.Type == sym.SXREF && pesym.Value > 0 { // global data s.Type = sym.SNOPTRDATA @@ -479,7 +479,7 @@ func readpesym(arch *sys.Arch, syms *sym.Symbols, f *pe.File, pesym *pe.COFFSymb s.Type = sym.SXREF } if strings.HasPrefix(symname, "__imp_") { - s.Got = -2 // flag for __imp_ + s.SetGot(-2) // flag for __imp_ } return s, nil diff --git a/src/cmd/link/internal/ppc64/asm.go b/src/cmd/link/internal/ppc64/asm.go index 2baa9c1de191b..9445fbebcb8d5 100644 --- a/src/cmd/link/internal/ppc64/asm.go +++ b/src/cmd/link/internal/ppc64/asm.go @@ -236,7 +236,7 @@ func gencallstub(ctxt *ld.Link, abicase int, stub *sym.Symbol, targ *sym.Symbol) r.Off = int32(stub.Size) r.Sym = plt - r.Add = int64(targ.Plt) + r.Add = int64(targ.Plt()) r.Siz = 2 if ctxt.Arch.ByteOrder == binary.BigEndian { r.Off += int32(r.Siz) @@ -247,7 +247,7 @@ func gencallstub(ctxt *ld.Link, abicase int, stub *sym.Symbol, targ *sym.Symbol) r = stub.AddRel() r.Off = int32(stub.Size) r.Sym = plt - r.Add = int64(targ.Plt) + r.Add = int64(targ.Plt()) r.Siz = 2 if ctxt.Arch.ByteOrder == binary.BigEndian { r.Off += int32(r.Siz) @@ -793,7 +793,7 @@ overflow: } func addpltsym(ctxt *ld.Link, s *sym.Symbol) { - if s.Plt >= 0 { + if s.Plt() >= 0 { return } @@ -825,11 +825,11 @@ func addpltsym(ctxt *ld.Link, s *sym.Symbol) { // JMP_SLOT dynamic relocation for it. // // TODO(austin): ABI v1 is different - s.Plt = int32(plt.Size) + s.SetPlt(int32(plt.Size)) plt.Size += 8 - rela.AddAddrPlus(ctxt.Arch, plt, int64(s.Plt)) + rela.AddAddrPlus(ctxt.Arch, plt, int64(s.Plt())) rela.AddUint64(ctxt.Arch, ld.ELF64_R_INFO(uint32(s.Dynid), uint32(elf.R_PPC64_JMP_SLOT))) rela.AddUint64(ctxt.Arch, 0) } else { diff --git a/src/cmd/link/internal/s390x/asm.go b/src/cmd/link/internal/s390x/asm.go index 215200721cdb7..245da19d9d861 100644 --- a/src/cmd/link/internal/s390x/asm.go +++ b/src/cmd/link/internal/s390x/asm.go @@ -157,7 +157,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { if targ.Type == sym.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add += int64(targ.Plt) + r.Add += int64(targ.Plt()) } return true @@ -168,7 +168,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { if targ.Type == sym.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add += int64(targ.Plt) + r.Add += int64(targ.Plt()) } return true @@ -224,7 +224,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { r.Type = objabi.R_PCREL r.Variant = sym.RV_390_DBL r.Sym = ctxt.Syms.Lookup(".got", 0) - r.Add += int64(targ.Got) + r.Add += int64(targ.Got()) r.Add += int64(r.Siz) return true } @@ -417,7 +417,7 @@ func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 } func addpltsym(ctxt *ld.Link, s *sym.Symbol) { - if s.Plt >= 0 { + if s.Plt() >= 0 { return } @@ -472,7 +472,7 @@ func addpltsym(ctxt *ld.Link, s *sym.Symbol) { rela.AddUint64(ctxt.Arch, ld.ELF64_R_INFO(uint32(s.Dynid), uint32(elf.R_390_JMP_SLOT))) rela.AddUint64(ctxt.Arch, 0) - s.Plt = int32(plt.Size - 32) + s.SetPlt(int32(plt.Size - 32)) } else { ld.Errorf(s, "addpltsym: unsupported binary format") @@ -480,18 +480,18 @@ func addpltsym(ctxt *ld.Link, s *sym.Symbol) { } func addgotsym(ctxt *ld.Link, s *sym.Symbol) { - if s.Got >= 0 { + if s.Got() >= 0 { return } ld.Adddynsym(ctxt, s) got := ctxt.Syms.Lookup(".got", 0) - s.Got = int32(got.Size) + s.SetGot(int32(got.Size)) got.AddUint64(ctxt.Arch, 0) if ctxt.IsELF { rela := ctxt.Syms.Lookup(".rela", 0) - rela.AddAddrPlus(ctxt.Arch, got, int64(s.Got)) + rela.AddAddrPlus(ctxt.Arch, got, int64(s.Got())) rela.AddUint64(ctxt.Arch, ld.ELF64_R_INFO(uint32(s.Dynid), uint32(elf.R_390_GLOB_DAT))) rela.AddUint64(ctxt.Arch, 0) } else { diff --git a/src/cmd/link/internal/sym/sizeof_test.go b/src/cmd/link/internal/sym/sizeof_test.go index 814ec42373974..a9bc174d59f9d 100644 --- a/src/cmd/link/internal/sym/sizeof_test.go +++ b/src/cmd/link/internal/sym/sizeof_test.go @@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) { _32bit uintptr // size on 32bit platforms _64bit uintptr // size on 64bit platforms }{ - {Symbol{}, 120, 192}, + {Symbol{}, 112, 184}, } for _, tt := range tests { diff --git a/src/cmd/link/internal/sym/symbol.go b/src/cmd/link/internal/sym/symbol.go index 7739737591a16..c05b82a665778 100644 --- a/src/cmd/link/internal/sym/symbol.go +++ b/src/cmd/link/internal/sym/symbol.go @@ -19,8 +19,6 @@ type Symbol struct { Version int16 Attr Attribute Dynid int32 - Plt int32 - Got int32 Align int32 Elfsym int32 LocalElfsym int32 @@ -49,6 +47,8 @@ type AuxSymbol struct { dynimplib string dynimpvers string localentry uint8 + plt int32 + got int32 } func (s *Symbol) String() string { @@ -271,7 +271,7 @@ func (s *Symbol) setUintXX(arch *sys.Arch, off int64, v uint64, wid int64) int64 func (s *Symbol) makeAuxInfo() { if s.auxinfo == nil { - s.auxinfo = &AuxSymbol{extname: s.Name} + s.auxinfo = &AuxSymbol{extname: s.Name, plt: -1, got: -1} } } @@ -344,6 +344,40 @@ func (s *Symbol) SetLocalentry(val uint8) { s.auxinfo.localentry = val } +func (s *Symbol) Plt() int32 { + if s.auxinfo == nil { + return -1 + } + return s.auxinfo.plt +} + +func (s *Symbol) SetPlt(val int32) { + if s.auxinfo == nil { + if val == -1 { + return + } + s.makeAuxInfo() + } + s.auxinfo.plt = val +} + +func (s *Symbol) Got() int32 { + if s.auxinfo == nil { + return -1 + } + return s.auxinfo.got +} + +func (s *Symbol) SetGot(val int32) { + if s.auxinfo == nil { + if val == -1 { + return + } + s.makeAuxInfo() + } + s.auxinfo.got = val +} + // SortSub sorts a linked-list (by Sub) of *Symbol by Value. // Used for sub-symbols when loading host objects (see e.g. ldelf.go). func SortSub(l *Symbol) *Symbol { diff --git a/src/cmd/link/internal/sym/symbols.go b/src/cmd/link/internal/sym/symbols.go index 7c6137c73c978..d79d1d8b1d361 100644 --- a/src/cmd/link/internal/sym/symbols.go +++ b/src/cmd/link/internal/sym/symbols.go @@ -59,8 +59,6 @@ func (syms *Symbols) Newsym(name string, v int) *Symbol { syms.symbolBatch = batch[1:] s.Dynid = -1 - s.Plt = -1 - s.Got = -1 s.Name = name s.Version = int16(v) syms.Allsym = append(syms.Allsym, s) diff --git a/src/cmd/link/internal/x86/asm.go b/src/cmd/link/internal/x86/asm.go index 4b45aff6537cc..1744ab4d9969f 100644 --- a/src/cmd/link/internal/x86/asm.go +++ b/src/cmd/link/internal/x86/asm.go @@ -197,7 +197,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { if targ.Type == sym.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add += int64(targ.Plt) + r.Add += int64(targ.Plt()) } return true @@ -230,7 +230,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { addgotsym(ctxt, targ) r.Type = objabi.R_CONST // write r->add during relocsym r.Sym = nil - r.Add += int64(targ.Got) + r.Add += int64(targ.Got()) return true case 256 + objabi.RelocType(elf.R_386_GOTOFF): @@ -261,7 +261,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { if targ.Type == sym.SDYNIMPORT { addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add = int64(targ.Plt) + r.Add = int64(targ.Plt()) r.Type = objabi.R_PCREL return true } @@ -285,7 +285,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { addgotsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".got", 0) - r.Add += int64(targ.Got) + r.Add += int64(targ.Got()) r.Type = objabi.R_PCREL return true } @@ -303,7 +303,7 @@ func adddynrel(ctxt *ld.Link, s *sym.Symbol, r *sym.Reloc) bool { } addpltsym(ctxt, targ) r.Sym = ctxt.Syms.Lookup(".plt", 0) - r.Add = int64(targ.Plt) + r.Add = int64(targ.Plt()) return true case objabi.R_ADDR: @@ -538,7 +538,7 @@ func elfsetupplt(ctxt *ld.Link) { } func addpltsym(ctxt *ld.Link, s *sym.Symbol) { - if s.Plt >= 0 { + if s.Plt() >= 0 { return } @@ -576,7 +576,7 @@ func addpltsym(ctxt *ld.Link, s *sym.Symbol) { rel.AddUint32(ctxt.Arch, ld.ELF32_R_INFO(uint32(s.Dynid), uint32(elf.R_386_JMP_SLOT))) - s.Plt = int32(plt.Size - 16) + s.SetPlt(int32(plt.Size - 16)) } else if ctxt.HeadType == objabi.Hdarwin { // Same laziness as in 6l. @@ -587,29 +587,29 @@ func addpltsym(ctxt *ld.Link, s *sym.Symbol) { ctxt.Syms.Lookup(".linkedit.plt", 0).AddUint32(ctxt.Arch, uint32(s.Dynid)) // jmpq *got+size(IP) - s.Plt = int32(plt.Size) + s.SetPlt(int32(plt.Size)) plt.AddUint8(0xff) plt.AddUint8(0x25) - plt.AddAddrPlus(ctxt.Arch, ctxt.Syms.Lookup(".got", 0), int64(s.Got)) + plt.AddAddrPlus(ctxt.Arch, ctxt.Syms.Lookup(".got", 0), int64(s.Got())) } else { ld.Errorf(s, "addpltsym: unsupported binary format") } } func addgotsym(ctxt *ld.Link, s *sym.Symbol) { - if s.Got >= 0 { + if s.Got() >= 0 { return } ld.Adddynsym(ctxt, s) got := ctxt.Syms.Lookup(".got", 0) - s.Got = int32(got.Size) + s.SetGot(int32(got.Size)) got.AddUint32(ctxt.Arch, 0) if ctxt.IsELF { rel := ctxt.Syms.Lookup(".rel", 0) - rel.AddAddrPlus(ctxt.Arch, got, int64(s.Got)) + rel.AddAddrPlus(ctxt.Arch, got, int64(s.Got())) rel.AddUint32(ctxt.Arch, ld.ELF32_R_INFO(uint32(s.Dynid), uint32(elf.R_386_GLOB_DAT))) } else if ctxt.HeadType == objabi.Hdarwin { ctxt.Syms.Lookup(".linkedit.got", 0).AddUint32(ctxt.Arch, uint32(s.Dynid)) From dd9e81f678c74550dba7faefe3545d0839f28b65 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Wed, 18 Jul 2018 10:19:35 -0400 Subject: [PATCH 0239/1663] cmd/link: move ElfType field in sym.Symbol to cold section The sym.Symbol 'ElfType' field is used only for symbols corresponding to things in imported shared libraries, hence is not needed in the common case. Relocate it to sym.AuxSymbol so as to shrink the main Symbol struct. Updates #26186 Change-Id: I803efc561c31a0ca1d93eca434fda1c862a7b2c5 Reviewed-on: https://go-review.googlesource.com/125479 Reviewed-by: Ian Lance Taylor --- src/cmd/link/internal/amd64/asm.go | 2 +- src/cmd/link/internal/ld/lib.go | 2 +- src/cmd/link/internal/ld/symtab.go | 2 +- src/cmd/link/internal/s390x/asm.go | 2 +- src/cmd/link/internal/sym/sizeof_test.go | 2 +- src/cmd/link/internal/sym/symbol.go | 41 +++++++++++++++++------- 6 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/cmd/link/internal/amd64/asm.go b/src/cmd/link/internal/amd64/asm.go index 829635d219763..e922fe2db94ee 100644 --- a/src/cmd/link/internal/amd64/asm.go +++ b/src/cmd/link/internal/amd64/asm.go @@ -410,7 +410,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool { } case objabi.R_PCREL: if r.Siz == 4 { - if r.Xsym.Type == sym.SDYNIMPORT && r.Xsym.ElfType == elf.STT_FUNC { + if r.Xsym.Type == sym.SDYNIMPORT && r.Xsym.ElfType() == elf.STT_FUNC { ctxt.Out.Write64(uint64(elf.R_X86_64_PLT32) | uint64(elfsym)<<32) } else { ctxt.Out.Write64(uint64(elf.R_X86_64_PC32) | uint64(elfsym)<<32) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 511cdd891a283..331b6ca6145ed 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1706,7 +1706,7 @@ func ldshlibsyms(ctxt *Link, shlib string) { continue } lsym.Type = sym.SDYNIMPORT - lsym.ElfType = elf.ST_TYPE(elfsym.Info) + lsym.SetElfType(elf.ST_TYPE(elfsym.Info)) lsym.Size = int64(elfsym.Size) if elfsym.Section != elf.SHN_UNDEF { // Set .File for the library that actually defines the symbol. diff --git a/src/cmd/link/internal/ld/symtab.go b/src/cmd/link/internal/ld/symtab.go index 88d476710b937..2a04ef3824eba 100644 --- a/src/cmd/link/internal/ld/symtab.go +++ b/src/cmd/link/internal/ld/symtab.go @@ -93,7 +93,7 @@ func putelfsym(ctxt *Link, x *sym.Symbol, s string, t SymbolType, addr int64, go case UndefinedSym: // ElfType is only set for symbols read from Go shared libraries, but // for other symbols it is left as STT_NOTYPE which is fine. - typ = int(x.ElfType) + typ = int(x.ElfType()) case TLSSym: typ = STT_TLS diff --git a/src/cmd/link/internal/s390x/asm.go b/src/cmd/link/internal/s390x/asm.go index 245da19d9d861..88199f3a562c7 100644 --- a/src/cmd/link/internal/s390x/asm.go +++ b/src/cmd/link/internal/s390x/asm.go @@ -285,7 +285,7 @@ func elfreloc1(ctxt *ld.Link, r *sym.Reloc, sectoff int64) bool { case objabi.R_PCRELDBL, objabi.R_CALL: isdbl = true } - if r.Xsym.Type == sym.SDYNIMPORT && (r.Xsym.ElfType == elf.STT_FUNC || r.Type == objabi.R_CALL) { + if r.Xsym.Type == sym.SDYNIMPORT && (r.Xsym.ElfType() == elf.STT_FUNC || r.Type == objabi.R_CALL) { if isdbl { switch r.Siz { case 2: diff --git a/src/cmd/link/internal/sym/sizeof_test.go b/src/cmd/link/internal/sym/sizeof_test.go index a9bc174d59f9d..da4602a1619e7 100644 --- a/src/cmd/link/internal/sym/sizeof_test.go +++ b/src/cmd/link/internal/sym/sizeof_test.go @@ -23,7 +23,7 @@ func TestSizeof(t *testing.T) { _32bit uintptr // size on 32bit platforms _64bit uintptr // size on 64bit platforms }{ - {Symbol{}, 112, 184}, + {Symbol{}, 108, 176}, } for _, tt := range tests { diff --git a/src/cmd/link/internal/sym/symbol.go b/src/cmd/link/internal/sym/symbol.go index c05b82a665778..95ad8654b5cef 100644 --- a/src/cmd/link/internal/sym/symbol.go +++ b/src/cmd/link/internal/sym/symbol.go @@ -24,18 +24,14 @@ type Symbol struct { LocalElfsym int32 Value int64 Size int64 - // ElfType is set for symbols read from shared libraries by ldshlibsyms. It - // is not set for symbols defined by the packages being linked or by symbols - // read by ldelf (and so is left as elf.STT_NOTYPE). - ElfType elf.SymType - Sub *Symbol - Outer *Symbol - Gotype *Symbol - File string - auxinfo *AuxSymbol - Sect *Section - FuncInfo *FuncInfo - Lib *Library // Package defining this symbol + Sub *Symbol + Outer *Symbol + Gotype *Symbol + File string + auxinfo *AuxSymbol + Sect *Section + FuncInfo *FuncInfo + Lib *Library // Package defining this symbol // P contains the raw symbol data. P []byte R []Reloc @@ -49,6 +45,10 @@ type AuxSymbol struct { localentry uint8 plt int32 got int32 + // ElfType is set for symbols read from shared libraries by ldshlibsyms. It + // is not set for symbols defined by the packages being linked or by symbols + // read by ldelf (and so is left as elf.STT_NOTYPE). + elftype elf.SymType } func (s *Symbol) String() string { @@ -378,6 +378,23 @@ func (s *Symbol) SetGot(val int32) { s.auxinfo.got = val } +func (s *Symbol) ElfType() elf.SymType { + if s.auxinfo == nil { + return elf.STT_NOTYPE + } + return s.auxinfo.elftype +} + +func (s *Symbol) SetElfType(val elf.SymType) { + if s.auxinfo == nil { + if val == elf.STT_NOTYPE { + return + } + s.makeAuxInfo() + } + s.auxinfo.elftype = val +} + // SortSub sorts a linked-list (by Sub) of *Symbol by Value. // Used for sub-symbols when loading host objects (see e.g. ldelf.go). func SortSub(l *Symbol) *Symbol { From 31389254def190938c0cc802f645f958734bc865 Mon Sep 17 00:00:00 2001 From: Alex Kohler Date: Thu, 30 Aug 2018 10:01:54 -0400 Subject: [PATCH 0240/1663] all: fix typos Change-Id: Icded6c786b7b185d5aff055f34e0cfe9e521826a Reviewed-on: https://go-review.googlesource.com/132176 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/ssa/rewrite.go | 2 +- src/cmd/trace/annotations.go | 5 ++--- src/cmd/trace/trace.go | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index 31195638ab5f8..4b12a84cdfec2 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -1045,7 +1045,7 @@ func needRaceCleanup(sym interface{}, v *Value) bool { // Check for racefuncenter will encounter racefuncexit and vice versa. // Allow calls to panic* default: - // If we encounterd any call, we need to keep racefunc*, + // If we encountered any call, we need to keep racefunc*, // for accurate stacktraces. return false } diff --git a/src/cmd/trace/annotations.go b/src/cmd/trace/annotations.go index 8071ac887967a..307da58bd5a4e 100644 --- a/src/cmd/trace/annotations.go +++ b/src/cmd/trace/annotations.go @@ -438,9 +438,8 @@ func (task *taskDesc) complete() bool { return task.create != nil && task.end != nil } -// descendents returns all the task nodes in the subtree rooted from this task. -// TODO: the method name is misspelled -func (task *taskDesc) decendents() []*taskDesc { +// descendants returns all the task nodes in the subtree rooted from this task. +func (task *taskDesc) descendants() []*taskDesc { if task == nil { return nil } diff --git a/src/cmd/trace/trace.go b/src/cmd/trace/trace.go index 62ff4d68c51c5..d986b71f79e0a 100644 --- a/src/cmd/trace/trace.go +++ b/src/cmd/trace/trace.go @@ -220,7 +220,7 @@ func httpJsonTrace(w http.ResponseWriter, r *http.Request) { params.startTime = task.firstTimestamp() - 1 params.endTime = task.lastTimestamp() + 1 params.maing = goid - params.tasks = task.decendents() + params.tasks = task.descendants() gs := map[uint64]bool{} for _, t := range params.tasks { // find only directly involved goroutines @@ -244,7 +244,7 @@ func httpJsonTrace(w http.ResponseWriter, r *http.Request) { params.mode = modeTaskOriented params.startTime = task.firstTimestamp() - 1 params.endTime = task.lastTimestamp() + 1 - params.tasks = task.decendents() + params.tasks = task.descendants() } start := int64(0) From c99687f87aed84342cfe92ae78924f791237c6f6 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 30 Aug 2018 11:33:19 -0400 Subject: [PATCH 0241/1663] go/types: handle nil pointer when panic is written outside of a function The current implementation crashes when someone writes a panic outside of a function, which makes sense since that is broken code. This fix allows one to type-check broken code. Updates #22467 Change-Id: I81b90dbd918162a20c60a821340898eaf02e648d Reviewed-on: https://go-review.googlesource.com/132235 Reviewed-by: Alan Donovan --- src/go/types/api_test.go | 2 ++ src/go/types/builtins.go | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go index 1fe20794ea934..cde07f2b4bba6 100644 --- a/src/go/types/api_test.go +++ b/src/go/types/api_test.go @@ -261,6 +261,8 @@ func TestTypesInfo(t *testing.T) { {`package x0; func _() { var x struct {f string}; x.f := 0 }`, `x.f`, `string`}, {`package x1; func _() { var z string; type x struct {f string}; y := &x{q: z}}`, `z`, `string`}, {`package x2; func _() { var a, b string; type x struct {f string}; z := &x{f: a; f: b;}}`, `b`, `string`}, + {`package x3; var x = panic("");`, `panic`, `func(interface{})`}, + {`package x4; func _() { panic("") }`, `panic`, `func(interface{})`}, } for _, test := range tests { diff --git a/src/go/types/builtins.go b/src/go/types/builtins.go index 05e032423ca2c..d3f0c4d40dfb1 100644 --- a/src/go/types/builtins.go +++ b/src/go/types/builtins.go @@ -476,7 +476,7 @@ func (check *Checker) builtin(x *operand, call *ast.CallExpr, id builtinId) (_ b // panic(x) // record panic call if inside a function with result parameters // (for use in Checker.isTerminating) - if check.sig.results.Len() > 0 { + if check.sig != nil && check.sig.results.Len() > 0 { // function has result parameters p := check.isPanic if p == nil { From c8545722a105f4a21583aeee00adcbd01436b98b Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Wed, 29 Aug 2018 11:55:55 -0400 Subject: [PATCH 0242/1663] cmd/compile: only clobber dead slots at call sites We now have safepoints at nearly all the instructions. When GOEXPERIMENT=clobberdead is on, it inserts clobbers nearly at every instruction. Currently this doesn't work. (Maybe the stack maps at non-call safepoints are still imprecise. I haven't investigated.) For now, only use call-based safepoints if the experiment is on. Updates #27326. Change-Id: I72cda9b422d9637cc5738e681502035af7a5c02d Reviewed-on: https://go-review.googlesource.com/131956 Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/plive.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/gc/plive.go b/src/cmd/compile/internal/gc/plive.go index f78d051b060c7..be53384c1f680 100644 --- a/src/cmd/compile/internal/gc/plive.go +++ b/src/cmd/compile/internal/gc/plive.go @@ -671,7 +671,7 @@ func (lv *Liveness) pointerMap(liveout bvec, vars []*Node, args, locals bvec) { // markUnsafePoints finds unsafe points and computes lv.unsafePoints. func (lv *Liveness) markUnsafePoints() { - if compiling_runtime || lv.f.NoSplit { + if compiling_runtime || lv.f.NoSplit || objabi.Clobberdead_enabled != 0 { // No complex analysis necessary. Do this on the fly // in issafepoint. return @@ -830,7 +830,7 @@ func (lv *Liveness) issafepoint(v *ssa.Value) bool { // go:nosplit functions are similar. Since safe points used to // be coupled with stack checks, go:nosplit often actually // means "no safe points in this function". - if compiling_runtime || lv.f.NoSplit { + if compiling_runtime || lv.f.NoSplit || objabi.Clobberdead_enabled != 0 { return v.Op.IsCall() } switch v.Op { From 360771e422ff0e586963e1dc0818c427b5444379 Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Wed, 29 Aug 2018 12:09:34 -0400 Subject: [PATCH 0243/1663] cmd/compile: don't clobber dead slots in runtime.wbBufFlush runtime.wbBufFlush must not modify its arguments, because the argument slots are also used as spill slots in runtime.gcWriteBarrier. So, GOEXPERIMENT=clobberdead must not clobber them. Updates #27326. Change-Id: Id02bb22a45201eecee748d89e7bdb3df7e4940e4 Reviewed-on: https://go-review.googlesource.com/131957 Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/plive.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/gc/plive.go b/src/cmd/compile/internal/gc/plive.go index be53384c1f680..e070a5cd1af08 100644 --- a/src/cmd/compile/internal/gc/plive.go +++ b/src/cmd/compile/internal/gc/plive.go @@ -1203,13 +1203,16 @@ func (lv *Liveness) clobber() { } fmt.Printf("\t\t\tCLOBBERDEAD %s\n", lv.fn.funcname()) } - if lv.f.Name == "forkAndExecInChild" { + if lv.f.Name == "forkAndExecInChild" || lv.f.Name == "wbBufFlush" { // forkAndExecInChild calls vfork (on linux/amd64, anyway). // The code we add here clobbers parts of the stack in the child. // When the parent resumes, it is using the same stack frame. But the // child has clobbered stack variables that the parent needs. Boom! // In particular, the sys argument gets clobbered. // Note to self: GOCLOBBERDEADHASH=011100101110 + // + // runtime.wbBufFlush must not modify its arguments. See the comments + // in runtime/mwbbuf.go:wbBufFlush. return } From f882d89b768bcfbd02b209acf0d525f4dbdd8f09 Mon Sep 17 00:00:00 2001 From: "G. Hussain Chinoy" Date: Thu, 30 Aug 2018 18:24:53 +0000 Subject: [PATCH 0244/1663] ghchinoy: add example for ioutil.WriteFile Change-Id: I65c3bda498562fdf39994ec1cadce7947e2d84b5 Reviewed-on: https://go-review.googlesource.com/132277 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- src/io/ioutil/example_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/io/ioutil/example_test.go b/src/io/ioutil/example_test.go index 0b24f672eecdb..a7d340b77fa59 100644 --- a/src/io/ioutil/example_test.go +++ b/src/io/ioutil/example_test.go @@ -99,3 +99,11 @@ func ExampleReadFile() { // Output: // File contents: Hello, Gophers! } + +func ExampleWriteFile() { + message := []byte("Hello, Gophers!") + err := ioutil.WriteFile("testdata/hello", message, 0644) + if err != nil { + log.Fatal(err) + } +} From d3b9572759770443d6f89f8e07c1a98eec1cf769 Mon Sep 17 00:00:00 2001 From: Venil Noronha Date: Thu, 30 Aug 2018 12:24:05 -0600 Subject: [PATCH 0245/1663] fmt: add an example for Sprintf Signed-off-by: Venil Noronha Change-Id: Ie5f50bc31db1eee11582b70b0e25c726090d4037 Reviewed-on: https://go-review.googlesource.com/132236 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/fmt/example_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index c77e78809cc56..2d17fc69c7970 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -27,3 +27,14 @@ func ExampleStringer() { fmt.Println(a) // Output: Gopher (2) } + +func ExampleSprintf() { + i := 30 + s := "Aug" + sf := fmt.Sprintf("Today is %d %s", i, s) + fmt.Println(sf) + fmt.Println(len(sf)) + // Output: + // Today is 30 Aug + // 15 +} From 0dac1e2e8743476d266a00a81f8bd64400bd8065 Mon Sep 17 00:00:00 2001 From: David Timm Date: Thu, 30 Aug 2018 12:25:53 -0600 Subject: [PATCH 0246/1663] net/http: add example for http.HandleFunc Change-Id: Id0e2fb2abad5b776ac0ed76e55e36c6b774b5b7a Reviewed-on: https://go-review.googlesource.com/132278 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/net/http/example_test.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/net/http/example_test.go b/src/net/http/example_test.go index 53fb0bbb4e104..f5c47d0bd4461 100644 --- a/src/net/http/example_test.go +++ b/src/net/http/example_test.go @@ -159,3 +159,17 @@ func ExampleListenAndServe() { http.HandleFunc("/hello", helloHandler) log.Fatal(http.ListenAndServe(":8080", nil)) } + +func ExampleHandleFunc() { + h1 := func(w http.ResponseWriter, _ *http.Request) { + io.WriteString(w, "Hello from a HandleFunc #1!\n") + } + h2 := func(w http.ResponseWriter, _ *http.Request) { + io.WriteString(w, "Hello from a HandleFunc #2!\n") + } + + http.HandleFunc("/", h1) + http.HandleFunc("/endpoint", h2) + + log.Fatal(http.ListenAndServe(":8080", nil)) +} From 5e755e9d6d9d5ab1268dc7c2d18a08b543d988c9 Mon Sep 17 00:00:00 2001 From: Erin Masatsugu Date: Thu, 30 Aug 2018 18:27:07 +0000 Subject: [PATCH 0247/1663] bytes: add example for Buffer.Len Change-Id: Ide50aba940727a7b32cd33dea5315050f1a34717 Reviewed-on: https://go-review.googlesource.com/132237 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/bytes/example_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bytes/example_test.go b/src/bytes/example_test.go index 5b7a46058f5c7..4d5cdfa28095e 100644 --- a/src/bytes/example_test.go +++ b/src/bytes/example_test.go @@ -39,6 +39,14 @@ func ExampleBuffer_Grow() { // Output: "64 bytes or fewer" } +func ExampleBuffer_Len() { + var b bytes.Buffer + b.Grow(64) + b.Write([]byte("abcde")) + fmt.Printf("%d", b.Len()) + // Output: 5 +} + func ExampleCompare() { // Interpret Compare's result by comparing it to zero. var a, b []byte From a2a8396f530a481ef2d2ad289bee1c741bc7f34e Mon Sep 17 00:00:00 2001 From: Dmitry Neverov Date: Thu, 30 Aug 2018 20:58:31 +0200 Subject: [PATCH 0248/1663] html/template: add an example for the Delims method Change-Id: I7ba55e3f6ebbaae41188316a66a40f994c037ad9 Reviewed-on: https://go-review.googlesource.com/132240 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/html/template/example_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/html/template/example_test.go b/src/html/template/example_test.go index 3fc982054ef60..533c0dd9616a0 100644 --- a/src/html/template/example_test.go +++ b/src/html/template/example_test.go @@ -123,6 +123,28 @@ func Example_escape() { } +func ExampleTemplate_Delims() { + const text = "<<.Greeting>> {{.Name}}" + + data := struct { + Greeting string + Name string + }{ + Greeting: "Hello", + Name: "Joe", + } + + t := template.Must(template.New("tpl").Delims("<<", ">>").Parse(text)) + + err := t.Execute(os.Stdout, data) + if err != nil { + log.Fatal(err) + } + + // Output: + // Hello {{.Name}} +} + // The following example is duplicated in text/template; keep them in sync. func ExampleTemplate_block() { From e84409ac95d5ed4a9113128c72d8f930f034aebf Mon Sep 17 00:00:00 2001 From: Venil Noronha Date: Thu, 30 Aug 2018 12:44:54 -0600 Subject: [PATCH 0249/1663] time: add example for LoadLocation Change-Id: I8e55e9397eb6844b5856f8bde9c26185c446a80e Reviewed-on: https://go-review.googlesource.com/132238 Reviewed-by: Brad Fitzpatrick --- src/time/example_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/time/example_test.go b/src/time/example_test.go index 494a41680253d..7e303ac5a0016 100644 --- a/src/time/example_test.go +++ b/src/time/example_test.go @@ -429,6 +429,17 @@ func ExampleTime_Truncate() { // t.Truncate(10m0s) = 12:10:00 } +func ExampleLoadLocation() { + location, err := time.LoadLocation("America/Los_Angeles") + if err != nil { + panic(err) + } + + timeInUTC := time.Date(2018, 8, 30, 12, 0, 0, 0, time.UTC) + fmt.Println(timeInUTC.In(location)) + // Output: 2018-08-30 05:00:00 -0700 PDT +} + func ExampleLocation() { // China doesn't have daylight saving. It uses a fixed 8 hour offset from UTC. secondsEastOfUTC := int((8 * time.Hour).Seconds()) From d5c7abf73a3f65cb7d5b9c3193e59ac9e0729c7a Mon Sep 17 00:00:00 2001 From: ianzapolsky Date: Thu, 30 Aug 2018 12:57:16 -0600 Subject: [PATCH 0250/1663] fmt: add an example for Errorf The errors package has an example for Errorf, but the fmt package does not. Copy the Errorf example from errors to fmt. Move existing Stringer example into separate file, so as not to break the assumption that the entire file will be presented as the example. Change-Id: I8a210a69362017fa08615a8c3feccdeee8427e22 Reviewed-on: https://go-review.googlesource.com/132239 Reviewed-by: Brad Fitzpatrick --- src/fmt/example_test.go | 25 +++++++------------------ src/fmt/stringer_example_test.go | 29 +++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 src/fmt/stringer_example_test.go diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index 2d17fc69c7970..5797e48080710 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -8,24 +8,13 @@ import ( "fmt" ) -// Animal has a Name and an Age to represent an animal. -type Animal struct { - Name string - Age uint -} - -// String makes Animal satisfy the Stringer interface. -func (a Animal) String() string { - return fmt.Sprintf("%v (%d)", a.Name, a.Age) -} - -func ExampleStringer() { - a := Animal{ - Name: "Gopher", - Age: 2, - } - fmt.Println(a) - // Output: Gopher (2) +// The Errorf function lets us use formatting features +// to create descriptive error messages. +func ExampleErrorf() { + const name, id = "bueller", 17 + err := fmt.Errorf("user %q (id %d) not found", name, id) + fmt.Println(err.Error()) + // Output: user "bueller" (id 17) not found } func ExampleSprintf() { diff --git a/src/fmt/stringer_example_test.go b/src/fmt/stringer_example_test.go new file mode 100644 index 0000000000000..c77e78809cc56 --- /dev/null +++ b/src/fmt/stringer_example_test.go @@ -0,0 +1,29 @@ +// 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. + +package fmt_test + +import ( + "fmt" +) + +// Animal has a Name and an Age to represent an animal. +type Animal struct { + Name string + Age uint +} + +// String makes Animal satisfy the Stringer interface. +func (a Animal) String() string { + return fmt.Sprintf("%v (%d)", a.Name, a.Age) +} + +func ExampleStringer() { + a := Animal{ + Name: "Gopher", + Age: 2, + } + fmt.Println(a) + // Output: Gopher (2) +} From 796e4bdc6b3edef2d838ddc3c4d35aee3f8e89cc Mon Sep 17 00:00:00 2001 From: Dylan Waits Date: Thu, 30 Aug 2018 13:04:09 -0600 Subject: [PATCH 0251/1663] fmt: add example for Fprintln Change-Id: Idc4aa53e443b89eeba496d00f6b409268e29ec21 Reviewed-on: https://go-review.googlesource.com/132241 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/fmt/example_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index 5797e48080710..7b7eacafb4361 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -6,6 +6,7 @@ package fmt_test import ( "fmt" + "os" ) // The Errorf function lets us use formatting features @@ -27,3 +28,14 @@ func ExampleSprintf() { // Today is 30 Aug // 15 } + +func ExampleFprintln() { + n, err := fmt.Fprintln(os.Stdout, "there", "are", 99, "gophers") + if err != nil { + panic("failed writing to stdout, someting is seriously wrong") + } + fmt.Print(n) + // Output: + // there are 99 gophers + // 21 +} From bd49b3d580731d8f391e40fb9e2f17301651cede Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Tudor=20C=C4=83lin?= Date: Thu, 30 Aug 2018 06:55:05 +0200 Subject: [PATCH 0252/1663] net: refactor readerAtEOF splice test Refactor TestSplice/readerAtEOF to handle cases where we disable splice on older kernels better. If splice is disabled, net.splice and poll.Splice do not get to observe EOF on the reader, because poll.Splice returns immediately with EINVAL. The test fails unexpectedly, because the splice operation is reported as not handled. This change refactors the test to handle the aforementioned case correctly, by not calling net.splice directly, but using a higher level check. Fixes #27355. Change-Id: I0d5606b4775213f2dbbb84ef82ddfc3bab662a31 Reviewed-on: https://go-review.googlesource.com/132096 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/net/splice_test.go | 57 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 7 deletions(-) diff --git a/src/net/splice_test.go b/src/net/splice_test.go index 44a5c00ba872e..ffe71ae38445e 100644 --- a/src/net/splice_test.go +++ b/src/net/splice_test.go @@ -122,6 +122,7 @@ func testSpliceBig(t *testing.T) { func testSpliceHonorsLimitedReader(t *testing.T) { t.Run("stopsAfterN", testSpliceStopsAfterN) t.Run("updatesN", testSpliceUpdatesN) + t.Run("readerAtLimit", testSpliceReaderAtLimit) } func testSpliceStopsAfterN(t *testing.T) { @@ -208,7 +209,7 @@ func testSpliceUpdatesN(t *testing.T) { } } -func testSpliceReaderAtEOF(t *testing.T) { +func testSpliceReaderAtLimit(t *testing.T) { clientUp, serverUp, err := spliceTestSocketPair("tcp") if err != nil { t.Fatal(err) @@ -222,21 +223,63 @@ func testSpliceReaderAtEOF(t *testing.T) { defer clientDown.Close() defer serverDown.Close() - serverUp.Close() - _, err, handled := splice(serverDown.(*TCPConn).fd, serverUp) - if !handled { - t.Errorf("closed connection: got err = %v, handled = %t, want handled = true", err, handled) - } lr := &io.LimitedReader{ N: 0, R: serverUp, } - _, err, handled = splice(serverDown.(*TCPConn).fd, lr) + _, err, handled := splice(serverDown.(*TCPConn).fd, lr) if !handled { t.Errorf("exhausted LimitedReader: got err = %v, handled = %t, want handled = true", err, handled) } } +func testSpliceReaderAtEOF(t *testing.T) { + clientUp, serverUp, err := spliceTestSocketPair("tcp") + if err != nil { + t.Fatal(err) + } + defer clientUp.Close() + clientDown, serverDown, err := spliceTestSocketPair("tcp") + if err != nil { + t.Fatal(err) + } + defer clientDown.Close() + + serverUp.Close() + + // We'd like to call net.splice here and check the handled return + // value, but we disable splice on old Linux kernels. + // + // In that case, poll.Splice and net.splice return a non-nil error + // and handled == false. We'd ideally like to see handled == true + // because the source reader is at EOF, but if we're running on an old + // kernel, and splice is disabled, we won't see EOF from net.splice, + // because we won't touch the reader at all. + // + // Trying to untangle the errors from net.splice and match them + // against the errors created by the poll package would be brittle, + // so this is a higher level test. + // + // The following ReadFrom should return immediately, regardless of + // whether splice is disabled or not. The other side should then + // get a goodbye signal. Test for the goodbye signal. + msg := "bye" + go func() { + serverDown.(*TCPConn).ReadFrom(serverUp) + io.WriteString(serverDown, msg) + serverDown.Close() + }() + + buf := make([]byte, 3) + _, err = io.ReadFull(clientDown, buf) + if err != nil { + t.Errorf("clientDown: %v", err) + } + if string(buf) != msg { + t.Errorf("clientDown got %q, want %q", buf, msg) + } +} + func testSpliceIssue25985(t *testing.T) { front, err := newLocalListener("tcp") if err != nil { From 6c0b8b5f8c74560007ae5929c7a2bfe3b9b875a8 Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Thu, 30 Aug 2018 16:01:15 -0400 Subject: [PATCH 0253/1663] go/types: fix crash following misuse of [...]T in composite literal The type-checker currently crashes when checking code such as: _ = map[string][...]int{"": {1, 2, 3}} In this case, the type checker reports an error for map[string][...]int, then proceeds to type-check the values of the map literal using a hint type of [...]int. When type-checking the inner composite (array) literal, the length of the open array type is computed from the elements, then the array type is recorded, but the literal has no explicit type syntax against which to record the type, so this code causes the type-checker to panic. Add a nil check before calling check.recordTypeAndValue to avoid that. Updates #22467 Change-Id: Ic4453ba485b7b88ede2a89f209365eda9e032abc Reviewed-on: https://go-review.googlesource.com/132355 Reviewed-by: Alan Donovan --- src/go/types/api_test.go | 1 + src/go/types/expr.go | 8 +++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go index cde07f2b4bba6..c34ecbf9d160d 100644 --- a/src/go/types/api_test.go +++ b/src/go/types/api_test.go @@ -263,6 +263,7 @@ func TestTypesInfo(t *testing.T) { {`package x2; func _() { var a, b string; type x struct {f string}; z := &x{f: a; f: b;}}`, `b`, `string`}, {`package x3; var x = panic("");`, `panic`, `func(interface{})`}, {`package x4; func _() { panic("") }`, `panic`, `func(interface{})`}, + {`package x5; func _() { var x map[string][...]int; x = map[string][...]int{"": {1,2,3}} }`, `x`, `map[string][-1]int`}, } for _, test := range tests { diff --git a/src/go/types/expr.go b/src/go/types/expr.go index c1deaf8325aaf..143a9581822ce 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1161,7 +1161,13 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { // not called for [...]). if utyp.len < 0 { utyp.len = n - check.recordTypeAndValue(e.Type, typexpr, utyp, nil) + // e.Type may be missing in case of errors. + // In "map[string][...]int{"": {1, 2, 3}}}, + // an error is reported for the outer literal, + // then [...]int is used as a hint for the inner literal. + if e.Type != nil { + check.recordTypeAndValue(e.Type, typexpr, utyp, nil) + } } case *Slice: From 04bee230145759a8f7eadff29f16d7443b215114 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Fri, 3 Aug 2018 20:51:25 +0530 Subject: [PATCH 0254/1663] cmd/dist: wait for run jobs to finish in case of a compiler error Instead of calling run synchronously, we pass it through bgrun and immediately wait for it to finish. This pushes all jobs to execute through the bgwork channel and therefore causes them to exit cleanly in case of a compiler error. Fixes #25981 Change-Id: I789a85d23fabf32d144ab85a3c9f53546cb7765a Reviewed-on: https://go-review.googlesource.com/127776 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/dist/build.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index 06adccd9a4a7b..d4f9dc4fbb5f4 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -805,10 +805,14 @@ func runInstall(dir string, ch chan struct{}) { compile = append(compile, "-asmhdr", pathf("%s/go_asm.h", workdir)) } compile = append(compile, gofiles...) - run(path, CheckExit|ShowOutput, compile...) + var wg sync.WaitGroup + // We use bgrun and immediately wait for it instead of calling run() synchronously. + // This executes all jobs through the bgwork channel and allows the process + // to exit cleanly in case an error occurs. + bgrun(&wg, path, compile...) + bgwait(&wg) // Compile the files. - var wg sync.WaitGroup for _, p := range files { if !strings.HasSuffix(p, ".s") { continue @@ -858,7 +862,8 @@ func runInstall(dir string, ch chan struct{}) { // Remove target before writing it. xremove(link[targ]) - run("", CheckExit|ShowOutput, link...) + bgrun(&wg, "", link...) + bgwait(&wg) } // matchfield reports whether the field (x,y,z) matches this build. From 3eb0b2e80d39f62ac7561e85215e3e7222dba2db Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Thu, 30 Aug 2018 15:39:45 -0600 Subject: [PATCH 0255/1663] fmt: remove spelling mistake in example MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "someting" is misspelled and the error handling both clobbers the error that occurs and distracts from the point of the example, which is to demonstrate how Printf works. It's better to just panic with the error. Change-Id: I5fb0a4a1a8b4772cbe0302582fa878d95e3a4060 Reviewed-on: https://go-review.googlesource.com/132376 Reviewed-by: Daniel Martí Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot --- src/fmt/example_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index 7b7eacafb4361..a600ebcafb34b 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -32,7 +32,7 @@ func ExampleSprintf() { func ExampleFprintln() { n, err := fmt.Fprintln(os.Stdout, "there", "are", 99, "gophers") if err != nil { - panic("failed writing to stdout, someting is seriously wrong") + panic(err) } fmt.Print(n) // Output: From 8201b92aae7ba51ed2e2645c1f7815bfe845db72 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Thu, 30 Aug 2018 21:45:21 +0000 Subject: [PATCH 0256/1663] crypto/x509: clarify docs for SystemCertPool The sentence in the docs for SystemCertPool that states that mutations to a returned pool do not affect any other pool is ambiguous as to who the any other pools are, because pools can be created in multiple ways that have nothing to do with the system certificate pool. Also the use of the word 'the' instead of 'a' early in the sentence implies there is only one shared pool ever returned. Fixes #27385 Change-Id: I43adbfca26fdd66c4adbf06eb85361139a1dea93 GitHub-Last-Rev: 2f1ba09fa403d31d2d543dca15727c6c2f896ec7 GitHub-Pull-Request: golang/go#27388 Reviewed-on: https://go-review.googlesource.com/132378 Reviewed-by: Filippo Valsorda --- src/crypto/x509/cert_pool.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/crypto/x509/cert_pool.go b/src/crypto/x509/cert_pool.go index a1646b98261de..5381f0d659043 100644 --- a/src/crypto/x509/cert_pool.go +++ b/src/crypto/x509/cert_pool.go @@ -47,8 +47,8 @@ func (s *CertPool) copy() *CertPool { // SystemCertPool returns a copy of the system cert pool. // -// Any mutations to the returned pool are not written to disk and do -// not affect any other pool. +// Any mutations to a returned pool are not written to disk and do +// not affect any other pool returned by SystemCertPool. // // New changes in the the system cert pool might not be reflected // in subsequent calls. From 5ac247674884a93f3a7630649ee00923724e7961 Mon Sep 17 00:00:00 2001 From: Andrew Bonventre Date: Thu, 30 Aug 2018 15:47:04 -0600 Subject: [PATCH 0257/1663] cmd/compile: make math/bits.RotateLeft* an intrinsic on amd64 Previously, pattern matching was good enough to achieve good performance for the RotateLeft* functions, but the inlining cost for them was much too high. Make RotateLeft* intrinsic on amd64 as a stop-gap for now to reduce inlining costs. This should be done (or at least looked at) for other architectures as well. Updates golang/go#17566 Change-Id: I6a106ff00b6c4e3f490650af3e083ed2be00c819 Reviewed-on: https://go-review.googlesource.com/132435 Run-TryBot: Andrew Bonventre TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/ssa.go | 22 +++++++ src/cmd/compile/internal/ssa/gen/AMD64.rules | 5 ++ .../compile/internal/ssa/gen/genericOps.go | 12 ++-- src/cmd/compile/internal/ssa/opGen.go | 24 +++++++ src/cmd/compile/internal/ssa/rewriteAMD64.go | 64 +++++++++++++++++++ test/inline_math_bits_rotate.go | 28 ++++++++ 6 files changed, 151 insertions(+), 4 deletions(-) create mode 100644 test/inline_math_bits_rotate.go diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 2a8927acd69ed..4c2f0098ce6aa 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -3347,6 +3347,28 @@ func init() { return s.newValue1(ssa.OpBitRev64, types.Types[TINT], args[0]) }, sys.ARM64) + addF("math/bits", "RotateLeft8", + func(s *state, n *Node, args []*ssa.Value) *ssa.Value { + return s.newValue2(ssa.OpRotateLeft8, types.Types[TUINT8], args[0], args[1]) + }, + sys.AMD64) + addF("math/bits", "RotateLeft16", + func(s *state, n *Node, args []*ssa.Value) *ssa.Value { + return s.newValue2(ssa.OpRotateLeft16, types.Types[TUINT16], args[0], args[1]) + }, + sys.AMD64) + addF("math/bits", "RotateLeft32", + func(s *state, n *Node, args []*ssa.Value) *ssa.Value { + return s.newValue2(ssa.OpRotateLeft32, types.Types[TUINT32], args[0], args[1]) + }, + sys.AMD64) + addF("math/bits", "RotateLeft64", + func(s *state, n *Node, args []*ssa.Value) *ssa.Value { + return s.newValue2(ssa.OpRotateLeft64, types.Types[TUINT64], args[0], args[1]) + }, + sys.AMD64) + alias("math/bits", "RotateLeft", "math/bits", "RotateLeft64", p8...) + makeOnesCountAMD64 := func(op64 ssa.Op, op32 ssa.Op) func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return func(s *state, n *Node, args []*ssa.Value) *ssa.Value { addr := s.entryNewValue1A(ssa.OpAddr, types.Types[TBOOL].PtrTo(), supportPopcnt, s.sb) diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index 10d917632e0ce..a7474ec46586d 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -768,6 +768,11 @@ (ROLWconst [c] (ROLWconst [d] x)) -> (ROLWconst [(c+d)&15] x) (ROLBconst [c] (ROLBconst [d] x)) -> (ROLBconst [(c+d)& 7] x) +(RotateLeft8 a b) -> (ROLB a b) +(RotateLeft16 a b) -> (ROLW a b) +(RotateLeft32 a b) -> (ROLL a b) +(RotateLeft64 a b) -> (ROLQ a b) + // Non-constant rotates. // We want to issue a rotate when the Go source contains code like // y &= 63 diff --git a/src/cmd/compile/internal/ssa/gen/genericOps.go b/src/cmd/compile/internal/ssa/gen/genericOps.go index a5b80770bb13e..7292012d26751 100644 --- a/src/cmd/compile/internal/ssa/gen/genericOps.go +++ b/src/cmd/compile/internal/ssa/gen/genericOps.go @@ -264,10 +264,14 @@ var genericOps = []opData{ {name: "BitRev32", argLength: 1}, // Reverse the bits in arg[0] {name: "BitRev64", argLength: 1}, // Reverse the bits in arg[0] - {name: "PopCount8", argLength: 1}, // Count bits in arg[0] - {name: "PopCount16", argLength: 1}, // Count bits in arg[0] - {name: "PopCount32", argLength: 1}, // Count bits in arg[0] - {name: "PopCount64", argLength: 1}, // Count bits in arg[0] + {name: "PopCount8", argLength: 1}, // Count bits in arg[0] + {name: "PopCount16", argLength: 1}, // Count bits in arg[0] + {name: "PopCount32", argLength: 1}, // Count bits in arg[0] + {name: "PopCount64", argLength: 1}, // Count bits in arg[0] + {name: "RotateLeft8", argLength: 2}, // Rotate bits in arg[0] left by arg[1] + {name: "RotateLeft16", argLength: 2}, // Rotate bits in arg[0] left by arg[1] + {name: "RotateLeft32", argLength: 2}, // Rotate bits in arg[0] left by arg[1] + {name: "RotateLeft64", argLength: 2}, // Rotate bits in arg[0] left by arg[1] // Square root, float64 only. // Special cases: diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index b960d96ec74be..0689c0ef323dc 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -2182,6 +2182,10 @@ const ( OpPopCount16 OpPopCount32 OpPopCount64 + OpRotateLeft8 + OpRotateLeft16 + OpRotateLeft32 + OpRotateLeft64 OpSqrt OpFloor OpCeil @@ -27644,6 +27648,26 @@ var opcodeTable = [...]opInfo{ argLen: 1, generic: true, }, + { + name: "RotateLeft8", + argLen: 2, + generic: true, + }, + { + name: "RotateLeft16", + argLen: 2, + generic: true, + }, + { + name: "RotateLeft32", + argLen: 2, + generic: true, + }, + { + name: "RotateLeft64", + argLen: 2, + generic: true, + }, { name: "Sqrt", argLen: 1, diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index e592610c26577..9a443ec0c421d 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -941,6 +941,14 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpPopCount64_0(v) case OpPopCount8: return rewriteValueAMD64_OpPopCount8_0(v) + case OpRotateLeft16: + return rewriteValueAMD64_OpRotateLeft16_0(v) + case OpRotateLeft32: + return rewriteValueAMD64_OpRotateLeft32_0(v) + case OpRotateLeft64: + return rewriteValueAMD64_OpRotateLeft64_0(v) + case OpRotateLeft8: + return rewriteValueAMD64_OpRotateLeft8_0(v) case OpRound32F: return rewriteValueAMD64_OpRound32F_0(v) case OpRound64F: @@ -60745,6 +60753,62 @@ func rewriteValueAMD64_OpPopCount8_0(v *Value) bool { return true } } +func rewriteValueAMD64_OpRotateLeft16_0(v *Value) bool { + // match: (RotateLeft16 a b) + // cond: + // result: (ROLW a b) + for { + _ = v.Args[1] + a := v.Args[0] + b := v.Args[1] + v.reset(OpAMD64ROLW) + v.AddArg(a) + v.AddArg(b) + return true + } +} +func rewriteValueAMD64_OpRotateLeft32_0(v *Value) bool { + // match: (RotateLeft32 a b) + // cond: + // result: (ROLL a b) + for { + _ = v.Args[1] + a := v.Args[0] + b := v.Args[1] + v.reset(OpAMD64ROLL) + v.AddArg(a) + v.AddArg(b) + return true + } +} +func rewriteValueAMD64_OpRotateLeft64_0(v *Value) bool { + // match: (RotateLeft64 a b) + // cond: + // result: (ROLQ a b) + for { + _ = v.Args[1] + a := v.Args[0] + b := v.Args[1] + v.reset(OpAMD64ROLQ) + v.AddArg(a) + v.AddArg(b) + return true + } +} +func rewriteValueAMD64_OpRotateLeft8_0(v *Value) bool { + // match: (RotateLeft8 a b) + // cond: + // result: (ROLB a b) + for { + _ = v.Args[1] + a := v.Args[0] + b := v.Args[1] + v.reset(OpAMD64ROLB) + v.AddArg(a) + v.AddArg(b) + return true + } +} func rewriteValueAMD64_OpRound32F_0(v *Value) bool { // match: (Round32F x) // cond: diff --git a/test/inline_math_bits_rotate.go b/test/inline_math_bits_rotate.go new file mode 100644 index 0000000000000..a0341ea4971e9 --- /dev/null +++ b/test/inline_math_bits_rotate.go @@ -0,0 +1,28 @@ +// +build amd64 +// errorcheck -0 -m + +// Copyright 2018 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. + +// Test that inlining of math/bits.RotateLeft* treats those calls as intrinsics. + +package p + +import "math/bits" + +var ( + x8 uint8 + x16 uint16 + x32 uint32 + x64 uint64 + x uint +) + +func f() { // ERROR "can inline f" + x8 = bits.RotateLeft8(x8, 1) + x16 = bits.RotateLeft16(x16, 1) + x32 = bits.RotateLeft32(x32, 1) + x64 = bits.RotateLeft64(x64, 1) + x = bits.RotateLeft(x, 1) +} From ce2e883afc02585188d215cdda265c6a27f14a41 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 21 Aug 2018 09:50:58 -0700 Subject: [PATCH 0258/1663] go/types: track local cycles using same mechanism as for global objects For Go 1.11, cycle tracking of global (package-level) objects was changed to use a Checker-level object path rather than relying on the explicit path parameter that is passed around to some (but not all) type-checker functions. This change now uses the same mechanism for the detection of local type cycles (local non-type objects cannot create cycles by definition of the spec). As a result, local alias cycles are now correctly detected as well (issue #27106). The path parameter that is explicitly passed around to some type-checker methods is still present and will be removed in a follow-up CL. Also: - removed useCycleMarking flag and respective dead code - added a couple more tests - improved documentation Fixes #27106. Updates #25773. Change-Id: I7cbf304bceb43a8d52e6483dcd0fa9ef7e1ea71c Reviewed-on: https://go-review.googlesource.com/130455 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Alan Donovan --- src/go/types/check.go | 2 +- src/go/types/decl.go | 69 +++++++++++++++++++------------- src/go/types/resolver.go | 4 ++ src/go/types/testdata/cycles.src | 6 ++- src/go/types/typexpr.go | 17 +------- 5 files changed, 53 insertions(+), 45 deletions(-) diff --git a/src/go/types/check.go b/src/go/types/check.go index 76d9c8917cb76..5b796be40d4c1 100644 --- a/src/go/types/check.go +++ b/src/go/types/check.go @@ -76,7 +76,7 @@ type Checker struct { fset *token.FileSet pkg *Package *Info - objMap map[Object]*declInfo // maps package-level object to declaration info + objMap map[Object]*declInfo // maps package-level objects and (non-interface) methods to declaration info impMap map[importKey]*Package // maps (import path, source directory) to (complete or fake) package // information collected during type-checking of a set of package files diff --git a/src/go/types/decl.go b/src/go/types/decl.go index 11b68583e38c0..d845789143305 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -64,13 +64,6 @@ func objPathString(path []Object) string { return s } -// useCycleMarking enables the new coloring-based cycle marking scheme -// for package-level objects. Set this flag to false to disable this -// code quickly and revert to the existing mechanism (and comment out -// some of the new tests in cycles5.src that will fail again). -// TODO(gri) remove this for Go 1.12 -const useCycleMarking = true - // objDecl type-checks the declaration of obj in its respective (file) context. // See check.typ for the details on def and path. func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) { @@ -147,7 +140,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) { // order code. switch obj := obj.(type) { case *Const: - if useCycleMarking && check.typeCycle(obj) { + if check.typeCycle(obj) { obj.typ = Typ[Invalid] break } @@ -156,7 +149,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) { } case *Var: - if useCycleMarking && check.typeCycle(obj) { + if check.typeCycle(obj) { obj.typ = Typ[Invalid] break } @@ -190,7 +183,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) { } } - if useCycleMarking && check.typeCycle(obj) { + if check.typeCycle(obj) { // break cycle // (without this, calling underlying() // below may lead to an endless loop @@ -200,7 +193,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) { } case *Func: - if useCycleMarking && check.typeCycle(obj) { + if check.typeCycle(obj) { // Don't set obj.typ to Typ[Invalid] here // because plenty of code type-asserts that // functions have a *Signature type. Grey @@ -273,10 +266,15 @@ var cutCycle = NewTypeName(token.NoPos, nil, "!", nil) // TODO(gri) rename s/typeCycle/cycle/ once we don't need the other // cycle method anymore. func (check *Checker) typeCycle(obj Object) (isCycle bool) { - d := check.objMap[obj] - if d == nil { - check.dump("%v: %s should have been declared", obj.Pos(), obj) - unreachable() + // The object map contains the package scope objects and the non-interface methods. + if debug { + info := check.objMap[obj] + inObjMap := info != nil && (info.fdecl == nil || info.fdecl.Recv == nil) // exclude methods + isPkgObj := obj.Parent() == check.pkg.scope + if isPkgObj != inObjMap { + check.dump("%v: inconsistent object map for %s (isPkgObj = %v, inObjMap = %v)", obj.Pos(), obj, isPkgObj, inObjMap) + unreachable() + } } // Given the number of constants and variables (nval) in the cycle @@ -312,8 +310,25 @@ func (check *Checker) typeCycle(obj Object) (isCycle bool) { // that we type-check methods when we type-check their // receiver base types. return false - case !check.objMap[obj].alias: - hasTDef = true + default: + // Determine if the type name is an alias or not. For + // package-level objects, use the object map which + // provides syntactic information (which doesn't rely + // on the order in which the objects are set up). For + // local objects, we can rely on the order, so use + // the object's predicate. + // TODO(gri) It would be less fragile to always access + // the syntactic information. We should consider storing + // this information explicitly in the object. + var alias bool + if d := check.objMap[obj]; d != nil { + alias = d.alias // package-level object + } else { + alias = obj.IsAlias() // function local object + } + if !alias { + hasTDef = true + } } case *Func: // ignored for now @@ -552,15 +567,13 @@ func (check *Checker) addMethodDecls(obj *TypeName) { } } - if useCycleMarking { - // Suppress detection of type cycles occurring through method - // declarations - they wouldn't exist if methods were type- - // checked separately from their receiver base types. See also - // comment at the end of Checker.typeDecl. - // TODO(gri) Remove this once methods are type-checked separately. - check.push(cutCycle) - defer check.pop() - } + // Suppress detection of type cycles occurring through method + // declarations - they wouldn't exist if methods were type- + // checked separately from their receiver base types. See also + // comment at the end of Checker.typeDecl. + // TODO(gri) Remove this once methods are type-checked separately. + check.push(cutCycle) + defer check.pop() // type-check methods for _, m := range methods { @@ -730,8 +743,10 @@ func (check *Checker) declStmt(decl ast.Decl) { // the innermost containing block." scopePos := s.Name.Pos() check.declare(check.scope, s.Name, obj, scopePos) + // mark and unmark type before calling typeDecl; its type is still nil (see Checker.objDecl) + obj.setColor(grey + color(check.push(obj))) check.typeDecl(obj, s.Type, nil, nil, s.Assign.IsValid()) - + check.pop().setColor(black) default: check.invalidAST(s.Pos(), "const, type, or var declaration expected") } diff --git a/src/go/types/resolver.go b/src/go/types/resolver.go index 5cbaba187b964..a462912cd149c 100644 --- a/src/go/types/resolver.go +++ b/src/go/types/resolver.go @@ -420,6 +420,10 @@ func (check *Checker) collectObjects() { check.recordDef(d.Name, obj) } info := &declInfo{file: fileScope, fdecl: d} + // Methods are not package-level objects but we still track them in the + // object map so that we can handle them like regular functions (if the + // receiver is invalid); also we need their fdecl info when associating + // them with their receiver base type, below. check.objMap[obj] = info obj.setOrder(uint32(len(check.objMap))) diff --git a/src/go/types/testdata/cycles.src b/src/go/types/testdata/cycles.src index 59f112dba1db7..a9af46a9337b1 100644 --- a/src/go/types/testdata/cycles.src +++ b/src/go/types/testdata/cycles.src @@ -158,6 +158,8 @@ type T20 chan [unsafe.Sizeof(func(ch T20){ _ = <-ch })]byte type T22 = chan [unsafe.Sizeof(func(ch T20){ _ = <-ch })]byte func _() { - type T1 chan [unsafe.Sizeof(func(ch T1){ _ = <-ch })]byte - type T2 = chan [unsafe.Sizeof(func(ch T2){ _ = <-ch })]byte + type T0 func(T0) + type T1 /* ERROR cycle */ = func(T1) + type T2 chan [unsafe.Sizeof(func(ch T2){ _ = <-ch })]byte + type T3 /* ERROR cycle */ = chan [unsafe.Sizeof(func(ch T3){ _ = <-ch })]byte } diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index 45ada5874bc19..1da1f01956f86 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -71,17 +71,6 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *Named, path []*TypeNa case *TypeName: x.mode = typexpr - // package-level alias cycles are now checked by Checker.objDecl - if useCycleMarking { - if check.objMap[obj] != nil { - break - } - } - if check.cycle(obj, path, true) { - // maintain x.mode == typexpr despite error - typ = Typ[Invalid] - break - } case *Var: // It's ok to mark non-local variables, but ignore variables @@ -169,10 +158,8 @@ func (check *Checker) typExpr(e ast.Expr, def *Named, path []*TypeName) (T Type) func (check *Checker) typ(e ast.Expr) Type { // typExpr is called with a nil path indicating an indirection: // push indir sentinel on object path - if useCycleMarking { - check.push(indir) - defer check.pop() - } + check.push(indir) + defer check.pop() return check.typExpr(e, nil, nil) } From 43469ddf7450a056edf536494f6a05272662ba94 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 21 Aug 2018 12:01:32 -0700 Subject: [PATCH 0259/1663] go/types: remove explicit path parameter from most type-checker functions (cleanup) Now that most of the type-checker is using the object-coloring mechanism to detect cycles, remove the explicit path parameter from the functions that don't rely on it anymore. Some of the syntactic-based resolver code (for aliases, interfaces) still use an explicit path; leaving those unchanged for now. The function cycle was moved from typexpr.go (where it is not used anymore) to resolver.go (where it's still used). It has not changed. Fixes #25773. Change-Id: I2100adc8d66d5da9de9277dee94a1f08e5a88487 Reviewed-on: https://go-review.googlesource.com/130476 Reviewed-by: Alan Donovan --- src/go/types/check.go | 5 --- src/go/types/decl.go | 20 ++++++------ src/go/types/expr.go | 6 ++-- src/go/types/interfaces.go | 2 +- src/go/types/resolver.go | 25 ++++++++++++--- src/go/types/typexpr.go | 62 ++++++++++++-------------------------- 6 files changed, 54 insertions(+), 66 deletions(-) diff --git a/src/go/types/check.go b/src/go/types/check.go index 5b796be40d4c1..91df94dcbc0db 100644 --- a/src/go/types/check.go +++ b/src/go/types/check.go @@ -160,11 +160,6 @@ func (check *Checker) pop() Object { return obj } -// pathString returns a string of the form a->b-> ... ->g for an object path [a, b, ... g]. -func (check *Checker) pathString() string { - return objPathString(check.objPath) -} - // NewChecker returns a new Checker instance for a given package. // Package files may be added incrementally via checker.Files. func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Checker { diff --git a/src/go/types/decl.go b/src/go/types/decl.go index d845789143305..6eeec40ae661e 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -66,9 +66,9 @@ func objPathString(path []Object) string { // objDecl type-checks the declaration of obj in its respective (file) context. // See check.typ for the details on def and path. -func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) { +func (check *Checker) objDecl(obj Object, def *Named) { if trace { - check.trace(obj.Pos(), "-- checking %s %s (path = %s, objPath = %s)", obj.color(), obj, pathString(path), check.pathString()) + check.trace(obj.Pos(), "-- checking %s %s (objPath = %s)", obj.color(), obj, objPathString(check.objPath)) check.indent++ defer func() { check.indent-- @@ -237,7 +237,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) { check.varDecl(obj, d.lhs, d.typ, d.init) case *TypeName: // invalid recursive types are detected via path - check.typeDecl(obj, d.typ, def, path, d.alias) + check.typeDecl(obj, d.typ, def, d.alias) case *Func: // functions may be recursive - no need to track dependencies check.funcDecl(obj, d) @@ -388,7 +388,7 @@ func (check *Checker) constDecl(obj *Const, typ, init ast.Expr) { // determine type, if any if typ != nil { - t := check.typExpr(typ, nil, nil) + t := check.typExpr(typ, nil) if !isConstType(t) { // don't report an error if the type is an invalid C (defined) type // (issue #22090) @@ -414,7 +414,7 @@ func (check *Checker) varDecl(obj *Var, lhs []*Var, typ, init ast.Expr) { // determine type, if any if typ != nil { - obj.typ = check.typExpr(typ, nil, nil) + obj.typ = check.typExpr(typ, nil) // We cannot spread the type to all lhs variables if there // are more than one since that would mark them as checked // (see Checker.objDecl) and the assignment of init exprs, @@ -489,13 +489,13 @@ func (n *Named) setUnderlying(typ Type) { } } -func (check *Checker) typeDecl(obj *TypeName, typ ast.Expr, def *Named, path []*TypeName, alias bool) { +func (check *Checker) typeDecl(obj *TypeName, typ ast.Expr, def *Named, alias bool) { assert(obj.typ == nil) if alias { obj.typ = Typ[Invalid] - obj.typ = check.typExpr(typ, nil, append(path, obj)) + obj.typ = check.typExpr(typ, nil) } else { @@ -504,7 +504,7 @@ func (check *Checker) typeDecl(obj *TypeName, typ ast.Expr, def *Named, path []* obj.typ = named // make sure recursive type declarations terminate // determine underlying type of named - check.typExpr(typ, named, append(path, obj)) + check.typExpr(typ, named) // The underlying type of named may be itself a named type that is // incomplete: @@ -594,7 +594,7 @@ func (check *Checker) addMethodDecls(obj *TypeName) { } // type-check - check.objDecl(m, nil, nil) + check.objDecl(m, nil) if base != nil { base.methods = append(base.methods, m) @@ -745,7 +745,7 @@ func (check *Checker) declStmt(decl ast.Decl) { check.declare(check.scope, s.Name, obj, scopePos) // mark and unmark type before calling typeDecl; its type is still nil (see Checker.objDecl) obj.setColor(grey + color(check.push(obj))) - check.typeDecl(obj, s.Type, nil, nil, s.Assign.IsValid()) + check.typeDecl(obj, s.Type, nil, s.Assign.IsValid()) check.pop().setColor(black) default: check.invalidAST(s.Pos(), "const, type, or var declaration expected") diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 143a9581822ce..3feb67ee1900f 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1010,7 +1010,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { goto Error // error was reported before case *ast.Ident: - check.ident(x, e, nil, nil) + check.ident(x, e, nil) case *ast.Ellipsis: // ellipses are handled explicitly where they are legal @@ -1064,7 +1064,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { break } } - typ = check.typExpr(e.Type, nil, nil) + typ = check.typExpr(e.Type, nil) base = typ case hint != nil: @@ -1439,7 +1439,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { check.invalidAST(e.Pos(), "use of .(type) outside type switch") goto Error } - T := check.typExpr(e.Type, nil, nil) + T := check.typExpr(e.Type, nil) if T == Typ[Invalid] { goto Error } diff --git a/src/go/types/interfaces.go b/src/go/types/interfaces.go index e4b42dc5a36b9..57dc1bccdcc58 100644 --- a/src/go/types/interfaces.go +++ b/src/go/types/interfaces.go @@ -144,7 +144,7 @@ func (check *Checker) infoFromTypeLit(scope *Scope, iface *ast.InterfaceType, tn } if trace { - check.trace(iface.Pos(), "-- collect methods for %v (path = %s, objPath = %s)", iface, pathString(path), check.pathString()) + check.trace(iface.Pos(), "-- collect methods for %v (path = %s, objPath = %s)", iface, pathString(path), objPathString(check.objPath)) check.indent++ defer func() { check.indent-- diff --git a/src/go/types/resolver.go b/src/go/types/resolver.go index a462912cd149c..ec7e4ed1c5944 100644 --- a/src/go/types/resolver.go +++ b/src/go/types/resolver.go @@ -521,6 +521,26 @@ func (check *Checker) resolveBaseTypeName(name *ast.Ident) *TypeName { } } +// cycle reports whether obj appears in path or not. +// If it does, and report is set, it also reports a cycle error. +func (check *Checker) cycle(obj *TypeName, path []*TypeName, report bool) bool { + // (it's ok to iterate forward because each named type appears at most once in path) + for i, prev := range path { + if prev == obj { + if report { + check.errorf(obj.pos, "illegal cycle in declaration of %s", obj.name) + // print cycle + for _, obj := range path[i:] { + check.errorf(obj.Pos(), "\t%s refers to", obj.Name()) // secondary error, \t indented + } + check.errorf(obj.Pos(), "\t%s", obj.Name()) + } + return true + } + } + return false +} + // packageObjects typechecks all package objects, but not function bodies. func (check *Checker) packageObjects() { // process package objects in source order for reproducible results @@ -539,11 +559,8 @@ func (check *Checker) packageObjects() { } } - // pre-allocate space for type declaration paths so that the underlying array is reused - typePath := make([]*TypeName, 0, 8) - for _, obj := range objList { - check.objDecl(obj, nil, typePath) + check.objDecl(obj, nil) } // At this point we may have a non-empty check.methods map; this means that not all diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index 1da1f01956f86..3ab4702f74ea2 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -16,9 +16,9 @@ import ( // ident type-checks identifier e and initializes x with the value or type of e. // If an error occurred, x.mode is set to invalid. -// For the meaning of def and path, see check.typ, below. +// For the meaning of def, see check.typExpr, below. // -func (check *Checker) ident(x *operand, e *ast.Ident, def *Named, path []*TypeName) { +func (check *Checker) ident(x *operand, e *ast.Ident, def *Named) { x.mode = invalid x.expr = e @@ -35,7 +35,7 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *Named, path []*TypeNa } check.recordUse(e, obj) - check.objDecl(obj, def, path) + check.objDecl(obj, def) typ := obj.Type() assert(typ != nil) @@ -103,37 +103,12 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *Named, path []*TypeNa x.typ = typ } -// cycle reports whether obj appears in path or not. -// If it does, and report is set, it also reports a cycle error. -func (check *Checker) cycle(obj *TypeName, path []*TypeName, report bool) bool { - // (it's ok to iterate forward because each named type appears at most once in path) - for i, prev := range path { - if prev == obj { - if report { - check.errorf(obj.pos, "illegal cycle in declaration of %s", obj.name) - // print cycle - for _, obj := range path[i:] { - check.errorf(obj.Pos(), "\t%s refers to", obj.Name()) // secondary error, \t indented - } - check.errorf(obj.Pos(), "\t%s", obj.Name()) - } - return true - } - } - return false -} - // typExpr type-checks the type expression e and returns its type, or Typ[Invalid]. // If def != nil, e is the type specification for the named type def, declared // in a type declaration, and def.underlying will be set to the type of e before -// any components of e are type-checked. Path contains the path of named types -// referring to this type; i.e. it is the path of named types directly containing -// each other and leading to the current type e. Indirect containment (e.g. via -// pointer indirection, function parameter, etc.) breaks the path (leads to a new -// path, and usually via calling Checker.typ below) and those types are not found -// in the path. +// any components of e are type-checked. // -func (check *Checker) typExpr(e ast.Expr, def *Named, path []*TypeName) (T Type) { +func (check *Checker) typExpr(e ast.Expr, def *Named) (T Type) { if trace { check.trace(e.Pos(), "%s", e) check.indent++ @@ -143,7 +118,7 @@ func (check *Checker) typExpr(e ast.Expr, def *Named, path []*TypeName) (T Type) }() } - T = check.typExprInternal(e, def, path) + T = check.typExprInternal(e, def) assert(isTyped(T)) check.recordTypeAndValue(e, typexpr, T, nil) @@ -156,11 +131,10 @@ func (check *Checker) typExpr(e ast.Expr, def *Named, path []*TypeName) (T Type) // element types, etc. See the comment in typExpr for details. // func (check *Checker) typ(e ast.Expr) Type { - // typExpr is called with a nil path indicating an indirection: - // push indir sentinel on object path + // push indir sentinel on object path to indicate an indirection check.push(indir) defer check.pop() - return check.typExpr(e, nil, nil) + return check.typExpr(e, nil) } // funcType type-checks a function or method type. @@ -231,14 +205,14 @@ func (check *Checker) funcType(sig *Signature, recvPar *ast.FieldList, ftyp *ast // typExprInternal drives type checking of types. // Must only be called by typExpr. // -func (check *Checker) typExprInternal(e ast.Expr, def *Named, path []*TypeName) Type { +func (check *Checker) typExprInternal(e ast.Expr, def *Named) Type { switch e := e.(type) { case *ast.BadExpr: // ignore - error reported before case *ast.Ident: var x operand - check.ident(&x, e, def, path) + check.ident(&x, e, def) switch x.mode { case typexpr: @@ -271,14 +245,14 @@ func (check *Checker) typExprInternal(e ast.Expr, def *Named, path []*TypeName) } case *ast.ParenExpr: - return check.typExpr(e.X, def, path) + return check.typExpr(e.X, def) case *ast.ArrayType: if e.Len != nil { typ := new(Array) def.setUnderlying(typ) typ.len = check.arrayLength(e.Len) - typ.elem = check.typExpr(e.Elt, nil, path) + typ.elem = check.typExpr(e.Elt, nil) return typ } else { @@ -291,7 +265,7 @@ func (check *Checker) typExprInternal(e ast.Expr, def *Named, path []*TypeName) case *ast.StructType: typ := new(Struct) def.setUnderlying(typ) - check.structType(typ, e, path) + check.structType(typ, e) return typ case *ast.StarExpr: @@ -309,7 +283,7 @@ func (check *Checker) typExprInternal(e ast.Expr, def *Named, path []*TypeName) case *ast.InterfaceType: typ := new(Interface) def.setUnderlying(typ) - check.interfaceType(typ, e, def, path) + check.interfaceType(typ, e, def) return typ case *ast.MapType: @@ -479,7 +453,7 @@ func (check *Checker) declareInSet(oset *objset, pos token.Pos, obj Object) bool return true } -func (check *Checker) interfaceType(ityp *Interface, iface *ast.InterfaceType, def *Named, path []*TypeName) { +func (check *Checker) interfaceType(ityp *Interface, iface *ast.InterfaceType, def *Named) { // fast-track empty interface if iface.Methods.List == nil { ityp.allMethods = markComplete @@ -542,8 +516,10 @@ func (check *Checker) interfaceType(ityp *Interface, iface *ast.InterfaceType, d // compute method set var tname *TypeName + var path []*TypeName if def != nil { tname = def.obj + path = []*TypeName{tname} } info := check.infoFromTypeLit(check.scope, iface, tname, path) if info == nil || info == &emptyIfaceInfo { @@ -652,7 +628,7 @@ func (check *Checker) tag(t *ast.BasicLit) string { return "" } -func (check *Checker) structType(styp *Struct, e *ast.StructType, path []*TypeName) { +func (check *Checker) structType(styp *Struct, e *ast.StructType) { list := e.Fields if list == nil { return @@ -696,7 +672,7 @@ func (check *Checker) structType(styp *Struct, e *ast.StructType, path []*TypeNa } for _, f := range list.List { - typ = check.typExpr(f.Type, nil, path) + typ = check.typExpr(f.Type, nil) tag = check.tag(f.Tag) if len(f.Names) > 0 { // named fields From 770e37d24915f481a8ee79d24121eae170a2214d Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 21 Aug 2018 16:02:51 -0700 Subject: [PATCH 0260/1663] go/types: better names for internal helper functions (cleanup) Internal helper functions for type-checking type expressions were renamed to make it clearer when they should be used: typExpr (w/o def) -> typ typExpr (w/ def) -> definedType typ -> indirectType typExprInternal -> typInternal The rename emphasizes that in most cases Checker.typ should be used to compute the types.Type from an ast.Type. If the type is defined, definedType should be used. For composite type elements which are not "inlined" in memory, indirectType should be used. In the process, implicitly changed several uses of indirectType (old: typ) to typ (old: typExpr) by not changing the respective function call source. These implicit changes are ok in those places because either call is fine where we are not concerned about composite type elements. But using typ (old: typExpr) is more efficient than using indirectType (old: typ). Change-Id: I4ad14d5357c5f94b6f1c33173de575c4cd05c703 Reviewed-on: https://go-review.googlesource.com/130595 Reviewed-by: Alan Donovan --- src/go/types/decl.go | 8 +++--- src/go/types/expr.go | 4 +-- src/go/types/typexpr.go | 55 ++++++++++++++++++++++------------------- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/src/go/types/decl.go b/src/go/types/decl.go index 6eeec40ae661e..d37a460a4ee30 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -388,7 +388,7 @@ func (check *Checker) constDecl(obj *Const, typ, init ast.Expr) { // determine type, if any if typ != nil { - t := check.typExpr(typ, nil) + t := check.typ(typ) if !isConstType(t) { // don't report an error if the type is an invalid C (defined) type // (issue #22090) @@ -414,7 +414,7 @@ func (check *Checker) varDecl(obj *Var, lhs []*Var, typ, init ast.Expr) { // determine type, if any if typ != nil { - obj.typ = check.typExpr(typ, nil) + obj.typ = check.typ(typ) // We cannot spread the type to all lhs variables if there // are more than one since that would mark them as checked // (see Checker.objDecl) and the assignment of init exprs, @@ -495,7 +495,7 @@ func (check *Checker) typeDecl(obj *TypeName, typ ast.Expr, def *Named, alias bo if alias { obj.typ = Typ[Invalid] - obj.typ = check.typExpr(typ, nil) + obj.typ = check.typ(typ) } else { @@ -504,7 +504,7 @@ func (check *Checker) typeDecl(obj *TypeName, typ ast.Expr, def *Named, alias bo obj.typ = named // make sure recursive type declarations terminate // determine underlying type of named - check.typExpr(typ, named) + check.definedType(typ, named) // The underlying type of named may be itself a named type that is // incomplete: diff --git a/src/go/types/expr.go b/src/go/types/expr.go index 3feb67ee1900f..f0acc7845d89c 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1064,7 +1064,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { break } } - typ = check.typExpr(e.Type, nil) + typ = check.typ(e.Type) base = typ case hint != nil: @@ -1439,7 +1439,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { check.invalidAST(e.Pos(), "use of .(type) outside type switch") goto Error } - T := check.typExpr(e.Type, nil) + T := check.typ(e.Type) if T == Typ[Invalid] { goto Error } diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index 3ab4702f74ea2..2edd1f5bac31e 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -103,12 +103,17 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *Named) { x.typ = typ } -// typExpr type-checks the type expression e and returns its type, or Typ[Invalid]. -// If def != nil, e is the type specification for the named type def, declared +// typ type-checks the type expression e and returns its type, or Typ[Invalid]. +func (check *Checker) typ(e ast.Expr) Type { + return check.definedType(e, nil) +} + +// definedType is like typ but also accepts a type name def. +// If def != nil, e is the type specification for the defined type def, declared // in a type declaration, and def.underlying will be set to the type of e before // any components of e are type-checked. // -func (check *Checker) typExpr(e ast.Expr, def *Named) (T Type) { +func (check *Checker) definedType(e ast.Expr, def *Named) (T Type) { if trace { check.trace(e.Pos(), "%s", e) check.indent++ @@ -118,23 +123,21 @@ func (check *Checker) typExpr(e ast.Expr, def *Named) (T Type) { }() } - T = check.typExprInternal(e, def) + T = check.typInternal(e, def) assert(isTyped(T)) check.recordTypeAndValue(e, typexpr, T, nil) return } -// typ is like typExpr (with a nil argument for the def parameter), -// but typ breaks type cycles. It should be called for components of -// types that break cycles, such as pointer base types, slice or map -// element types, etc. See the comment in typExpr for details. -// -func (check *Checker) typ(e ast.Expr) Type { - // push indir sentinel on object path to indicate an indirection +// indirectType is like typ but it also breaks the (otherwise) infinite size of recursive +// types by introducing an indirection. It should be called for components of types that +// are not layed out in place in memory, such as pointer base types, slice or map element +// types, function parameter types, etc. +func (check *Checker) indirectType(e ast.Expr) Type { check.push(indir) defer check.pop() - return check.typExpr(e, nil) + return check.definedType(e, nil) } // funcType type-checks a function or method type. @@ -202,10 +205,10 @@ func (check *Checker) funcType(sig *Signature, recvPar *ast.FieldList, ftyp *ast sig.variadic = variadic } -// typExprInternal drives type checking of types. -// Must only be called by typExpr. +// typInternal drives type checking of types. +// Must only be called by definedType. // -func (check *Checker) typExprInternal(e ast.Expr, def *Named) Type { +func (check *Checker) typInternal(e ast.Expr, def *Named) Type { switch e := e.(type) { case *ast.BadExpr: // ignore - error reported before @@ -245,20 +248,20 @@ func (check *Checker) typExprInternal(e ast.Expr, def *Named) Type { } case *ast.ParenExpr: - return check.typExpr(e.X, def) + return check.definedType(e.X, def) case *ast.ArrayType: if e.Len != nil { typ := new(Array) def.setUnderlying(typ) typ.len = check.arrayLength(e.Len) - typ.elem = check.typExpr(e.Elt, nil) + typ.elem = check.typ(e.Elt) return typ } else { typ := new(Slice) def.setUnderlying(typ) - typ.elem = check.typ(e.Elt) + typ.elem = check.indirectType(e.Elt) return typ } @@ -271,7 +274,7 @@ func (check *Checker) typExprInternal(e ast.Expr, def *Named) Type { case *ast.StarExpr: typ := new(Pointer) def.setUnderlying(typ) - typ.base = check.typ(e.X) + typ.base = check.indirectType(e.X) return typ case *ast.FuncType: @@ -290,8 +293,8 @@ func (check *Checker) typExprInternal(e ast.Expr, def *Named) Type { typ := new(Map) def.setUnderlying(typ) - typ.key = check.typ(e.Key) - typ.elem = check.typ(e.Value) + typ.key = check.indirectType(e.Key) + typ.elem = check.indirectType(e.Value) // spec: "The comparison operators == and != must be fully defined // for operands of the key type; thus the key type must not be a @@ -325,7 +328,7 @@ func (check *Checker) typExprInternal(e ast.Expr, def *Named) Type { } typ.dir = dir - typ.elem = check.typ(e.Value) + typ.elem = check.indirectType(e.Value) return typ default: @@ -406,7 +409,7 @@ func (check *Checker) collectParams(scope *Scope, list *ast.FieldList, variadicO // ignore ... and continue } } - typ := check.typ(ftype) + typ := check.indirectType(ftype) // The parser ensures that f.Tag is nil and we don't // care if a constructed AST contains a non-nil tag. if len(field.Names) > 0 { @@ -486,7 +489,7 @@ func (check *Checker) interfaceType(ityp *Interface, iface *ast.InterfaceType, d for _, f := range iface.Methods.List { if len(f.Names) == 0 { - typ := check.typ(f.Type) + typ := check.indirectType(f.Type) // typ should be a named type denoting an interface // (the parser will make sure it's a named type but // constructed ASTs may be wrong). @@ -569,7 +572,7 @@ func (check *Checker) interfaceType(ityp *Interface, iface *ast.InterfaceType, d // (possibly embedded) methods must be type-checked within their scope and // type-checking them must not affect the current context (was issue #23914) check.context = context{scope: minfo.scope} - typ := check.typ(minfo.src.Type) + typ := check.indirectType(minfo.src.Type) sig, _ := typ.(*Signature) if sig == nil { if typ != Typ[Invalid] { @@ -672,7 +675,7 @@ func (check *Checker) structType(styp *Struct, e *ast.StructType) { } for _, f := range list.List { - typ = check.typExpr(f.Type, nil) + typ = check.typ(f.Type) tag = check.tag(f.Tag) if len(f.Names) > 0 { // named fields From eeb2a11eeac2174590cd281c5f48cbec1717e4e6 Mon Sep 17 00:00:00 2001 From: Rodolfo Rodriguez Date: Thu, 30 Aug 2018 18:14:09 -0600 Subject: [PATCH 0261/1663] fmt: add Println example Change-Id: Ifd509c0c6a6ea41094b6ae1f4931414325b152fd Reviewed-on: https://go-review.googlesource.com/132475 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/fmt/example_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index a600ebcafb34b..92d5cd519e543 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -29,6 +29,17 @@ func ExampleSprintf() { // 15 } +func ExamplePrintln() { + n, err := fmt.Println("there", "are", 99, "gophers") + if err != nil { + panic(err) + } + fmt.Print(n) + // Output: + // there are 99 gophers + // 21 +} + func ExampleFprintln() { n, err := fmt.Fprintln(os.Stdout, "there", "are", 99, "gophers") if err != nil { From 7c96f9b527bc3d04eeb0e8d86c8fcf381a5981bb Mon Sep 17 00:00:00 2001 From: Venil Noronha Date: Thu, 30 Aug 2018 17:23:51 -0600 Subject: [PATCH 0262/1663] A+C: add VMware as author, Venil Noronha as contributor Change-Id: I0dd843ac06f1b9987aa2fc90ae62074e668d6d4d Reviewed-on: https://go-review.googlesource.com/132438 Reviewed-by: Brad Fitzpatrick --- AUTHORS | 1 + CONTRIBUTORS | 1 + 2 files changed, 2 insertions(+) diff --git a/AUTHORS b/AUTHORS index 8f0a20a0d7601..8001484e12398 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1404,6 +1404,7 @@ Vladimir Mihailenco Vladimir Nikishenko Vladimir Stefanovic Vladimir Varankin +VMware, Inc. Volker Dobler W. Trevor King Wade Simmons diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 333dff7aa3a66..305f6d8d801ce 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -1738,6 +1738,7 @@ Vadim Grek Vadim Vygonets Val Polouchkine Vega Garcia Luis Alfonso +Venil Noronha Veselkov Konstantin Victor Chudnovsky Victor Vrantchan From 677c4acc98fe22a8be14148f61c0c637a34c01d9 Mon Sep 17 00:00:00 2001 From: Rhys Hiltner Date: Thu, 30 Aug 2018 20:09:08 -0700 Subject: [PATCH 0263/1663] doc: recommend benchstat for performance commits The benchstat tool computes statistics about benchmarks, including whether any differences are statistically significant. Recommend its use in commit messages of performance-related changes rather than the simpler benchcmp tool. Change-Id: I4b35c2d892b48e60c3064489b035774792c19c30 Reviewed-on: https://go-review.googlesource.com/132515 Reviewed-by: Brad Fitzpatrick --- doc/contribute.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/contribute.html b/doc/contribute.html index 5d8e1163a0407..2068ab8a3e343 100644 --- a/doc/contribute.html +++ b/doc/contribute.html @@ -696,7 +696,7 @@

    Main content

    Add any relevant information, such as benchmark data if the change affects performance. -The benchcmp +The benchstat tool is conventionally used to format benchmark data for change descriptions.

    From 58e970ed79807fd9d2a29e1dcd4e44fa867b5540 Mon Sep 17 00:00:00 2001 From: Drew Flower Date: Thu, 30 Aug 2018 14:16:45 -0600 Subject: [PATCH 0264/1663] fmt: add an example for Sprintln Change-Id: I0fcb5e626bf3d6891592c21b912c824743d7eaa0 Reviewed-on: https://go-review.googlesource.com/132280 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/fmt/example_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index 92d5cd519e543..1d2cc0d7574c9 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -40,6 +40,14 @@ func ExamplePrintln() { // 21 } +func ExampleSprintln() { + s := "Aug" + sl := fmt.Sprintln("Today is 30", s) + fmt.Printf("%q", sl) + // Output: + // "Today is 30 Aug\n" +} + func ExampleFprintln() { n, err := fmt.Fprintln(os.Stdout, "there", "are", 99, "gophers") if err != nil { From 8a2b5f1f39152e45e6cfe6264612f00891d0327e Mon Sep 17 00:00:00 2001 From: Dina Garmash Date: Thu, 30 Aug 2018 16:59:29 -0400 Subject: [PATCH 0265/1663] doc: fix os.Pipe() call in the example. Short variable declarations example passes an fd argument to os.Pipe call. However, os.Pipe() takes no arguments and returns 2 Files and an error: https://golang.org/src/os/pipe_linux.go?s=319:360#L1 Fixes: #27384 Change-Id: I0a709f51e0878c57185d901b899d209f001dfcce Reviewed-on: https://go-review.googlesource.com/132284 Reviewed-by: Robert Griesemer --- doc/go_spec.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index f70ff7a02feee..57bb3b53f581d 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -2112,8 +2112,8 @@

    Short variable declarations

    i, j := 0, 10 f := func() int { return 7 } ch := make(chan int) -r, w := os.Pipe(fd) // os.Pipe() returns two values -_, y, _ := coord(p) // coord() returns three values; only interested in y coordinate +r, w, _ := os.Pipe() // os.Pipe() returns a connected pair of Files and an error, if any +_, y, _ := coord(p) // coord() returns three values; only interested in y coordinate

    From 09ea3c08e8fd1915515383f8cb4c0bb237d2b87d Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Fri, 31 Aug 2018 02:15:26 +0200 Subject: [PATCH 0266/1663] cmd/compile: in prove, fix fence-post implications for unsigned domain MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fence-post implications of the form "x-1 >= w && x > min ⇒ x > w" were not correctly handling unsigned domain, by always checking signed limits. This bug was uncovered once we taught prove that len(x) is always >= 0 in the signed domain. In the code being miscompiled (s[len(s)-1]), prove checks whether len(s)-1 >= len(s) in the unsigned domain; if it proves that this is always false, it can remove the bound check. Notice that len(s)-1 >= len(s) can be true for len(s) = 0 because of the wrap-around, so this is something prove should not be able to deduce. But because of the bug, the gate condition for the fence-post implication was len(s) > MinInt64 instead of len(s) > 0; that condition would be good in the signed domain but not in the unsigned domain. And since in CL105635 we taught prove that len(s) >= 0, the condition incorrectly triggered (len(s) >= 0 > MinInt64) and things were going downfall. Fixes #27251 Fixes #27289 Change-Id: I3dbcb1955ac5a66a0dcbee500f41e8d219409be5 Reviewed-on: https://go-review.googlesource.com/132495 Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/prove.go | 9 +++++++-- test/fixedbugs/issue27289.go | 24 ++++++++++++++++++++++++ test/prove.go | 4 +++- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 test/fixedbugs/issue27289.go diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go index c20f8b7ebc24f..af2b9ef0ed79c 100644 --- a/src/cmd/compile/internal/ssa/prove.go +++ b/src/cmd/compile/internal/ssa/prove.go @@ -425,13 +425,13 @@ func (ft *factsTable) update(parent *Block, v, w *Value, d domain, r relation) { // // Useful for i > 0; s[i-1]. lim, ok := ft.limits[x.ID] - if ok && lim.min > opMin[v.Op] { + if ok && ((d == signed && lim.min > opMin[v.Op]) || (d == unsigned && lim.umin > 0)) { ft.update(parent, x, w, d, gt) } } else if x, delta := isConstDelta(w); x != nil && delta == 1 { // v >= x+1 && x < max ⇒ v > x lim, ok := ft.limits[x.ID] - if ok && lim.max < opMax[w.Op] { + if ok && ((d == signed && lim.max < opMax[w.Op]) || (d == unsigned && lim.umax < opUMax[w.Op])) { ft.update(parent, v, x, d, gt) } } @@ -527,6 +527,11 @@ var opMax = map[Op]int64{ OpAdd32: math.MaxInt32, OpSub32: math.MaxInt32, } +var opUMax = map[Op]uint64{ + OpAdd64: math.MaxUint64, OpSub64: math.MaxUint64, + OpAdd32: math.MaxUint32, OpSub32: math.MaxUint32, +} + // isNonNegative reports whether v is known to be non-negative. func (ft *factsTable) isNonNegative(v *Value) bool { if isNonNegative(v) { diff --git a/test/fixedbugs/issue27289.go b/test/fixedbugs/issue27289.go new file mode 100644 index 0000000000000..293b9d005570f --- /dev/null +++ b/test/fixedbugs/issue27289.go @@ -0,0 +1,24 @@ +// run + +// Copyright 2018 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. + +// Make sure we don't prove that the bounds check failure branch is unreachable. + +package main + +//go:noinline +func f(a []int) { + _ = a[len(a)-1] +} + +func main() { + defer func() { + if err := recover(); err != nil { + return + } + panic("f should panic") + }() + f(nil) +} diff --git a/test/prove.go b/test/prove.go index 45cee9e8b5803..79256893b3604 100644 --- a/test/prove.go +++ b/test/prove.go @@ -542,7 +542,7 @@ func fence2(x, y int) { } } -func fence3(b []int, x, y int64) { +func fence3(b, c []int, x, y int64) { if x-1 >= y { if x <= y { // Can't prove because x may have wrapped. return @@ -555,6 +555,8 @@ func fence3(b []int, x, y int64) { } } + c[len(c)-1] = 0 // Can't prove because len(c) might be 0 + if n := len(b); n > 0 { b[n-1] = 0 // ERROR "Proved IsInBounds$" } From 8359b5e134052db0e5f1bc2257d496b0a81aa4fb Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Sun, 26 Aug 2018 16:45:10 +1000 Subject: [PATCH 0267/1663] internal/poll: advance file position in windows sendfile Some versions of Windows (Windows 10 1803) do not set file position after TransmitFile completes. So just use Seek to set file position before returning from sendfile. Fixes #25722 Change-Id: I7a49be10304b5db19dda707b13ac93d338aeb190 Reviewed-on: https://go-review.googlesource.com/131976 Reviewed-by: Brad Fitzpatrick Reviewed-by: Ian Lance Taylor Reviewed-by: Yasuhiro MATSUMOTO Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/internal/poll/sendfile_windows.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/internal/poll/sendfile_windows.go b/src/internal/poll/sendfile_windows.go index dc93e851d63a4..17a3681064b66 100644 --- a/src/internal/poll/sendfile_windows.go +++ b/src/internal/poll/sendfile_windows.go @@ -38,5 +38,11 @@ func SendFile(fd *FD, src syscall.Handle, n int64) (int64, error) { done, err := wsrv.ExecIO(o, func(o *operation) error { return syscall.TransmitFile(o.fd.Sysfd, o.handle, o.qty, 0, &o.o, nil, syscall.TF_WRITE_BEHIND) }) + if err == nil { + // Some versions of Windows (Windows 10 1803) do not set + // file position after TransmitFile completes. + // So just use Seek to set file position. + _, err = syscall.Seek(o.handle, curpos+int64(done), 0) + } return int64(done), err } From dbd8af74723d2c98cbdcc70f7e2801f69b57ac5b Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Seo Date: Thu, 23 Aug 2018 20:16:19 -0300 Subject: [PATCH 0268/1663] runtime: add support for VDSO on ppc64x for use in walltime/nanotime This change adds support for VDSO on ppc64x, making it possible to avoid a syscall in walltime and nanotime. BenchmarkClockVDSOAndFallbackPaths/vDSO-192 20000000 66.0 ns/op BenchmarkClockVDSOAndFallbackPaths/Fallback-192 1000000 1456 ns/op Change-Id: I3373bd804b6f122961de3ae9d034e6ccf35748e6 Reviewed-on: https://go-review.googlesource.com/131135 Run-TryBot: Lynn Boger TryBot-Result: Gobot Gobot Reviewed-by: Lynn Boger --- src/runtime/os_linux_novdso.go | 2 +- src/runtime/sys_linux_ppc64x.s | 94 ++++++++++++++++++++++++++++---- src/runtime/vdso_elf64.go | 2 +- src/runtime/vdso_in_none.go | 2 +- src/runtime/vdso_linux.go | 7 ++- src/runtime/vdso_linux_ppc64x.go | 25 +++++++++ src/runtime/vdso_linux_test.go | 2 +- 7 files changed, 118 insertions(+), 16 deletions(-) create mode 100644 src/runtime/vdso_linux_ppc64x.go diff --git a/src/runtime/os_linux_novdso.go b/src/runtime/os_linux_novdso.go index ee4a7a95c2aff..e54c1c4dc138f 100644 --- a/src/runtime/os_linux_novdso.go +++ b/src/runtime/os_linux_novdso.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // +build linux -// +build !386,!amd64,!arm,!arm64 +// +build !386,!amd64,!arm,!arm64,!ppc64,!ppc64le package runtime diff --git a/src/runtime/sys_linux_ppc64x.s b/src/runtime/sys_linux_ppc64x.s index 483cb8ef9aefd..075adf2368439 100644 --- a/src/runtime/sys_linux_ppc64x.s +++ b/src/runtime/sys_linux_ppc64x.s @@ -154,21 +154,87 @@ TEXT runtime·mincore(SB),NOSPLIT|NOFRAME,$0-28 // func walltime() (sec int64, nsec int32) TEXT runtime·walltime(SB),NOSPLIT,$16 - MOVD $0, R3 // CLOCK_REALTIME - MOVD $0(R1), R4 - SYSCALL $SYS_clock_gettime - MOVD 0(R1), R3 // sec - MOVD 8(R1), R5 // nsec + MOVD R1, R15 // R15 is unchanged by C code + MOVD g_m(g), R21 // R21 = m + + MOVD $0, R3 // CLOCK_REALTIME + + MOVD runtime·vdsoClockgettimeSym(SB), R12 // Check for VDSO availability + CMP R12, R0 + BEQ fallback + + // Set vdsoPC and vdsoSP for SIGPROF traceback. + MOVD LR, R14 + MOVD R14, m_vdsoPC(R21) + MOVD R15, m_vdsoSP(R21) + + MOVD m_curg(R21), R6 + CMP g, R6 + BNE noswitch + + MOVD m_g0(R21), R7 + MOVD (g_sched+gobuf_sp)(R7), R1 // Set SP to g0 stack + +noswitch: + SUB $16, R1 // Space for results + RLDICR $0, R1, $59, R1 // Align for C code + MOVD R12, CTR + MOVD R1, R4 + BL (CTR) // Call from VDSO + MOVD $0, R0 // Restore R0 + MOVD R0, m_vdsoSP(R21) // Clear vdsoSP + MOVD 0(R1), R3 // sec + MOVD 8(R1), R5 // nsec + MOVD R15, R1 // Restore SP + +finish: MOVD R3, sec+0(FP) MOVW R5, nsec+8(FP) RET + // Syscall fallback +fallback: + ADD $32, R1, R4 + SYSCALL $SYS_clock_gettime + MOVD 32(R1), R3 + MOVD 40(R1), R5 + JMP finish + TEXT runtime·nanotime(SB),NOSPLIT,$16 - MOVW $1, R3 // CLOCK_MONOTONIC - MOVD $0(R1), R4 - SYSCALL $SYS_clock_gettime - MOVD 0(R1), R3 // sec - MOVD 8(R1), R5 // nsec + MOVD $1, R3 // CLOCK_MONOTONIC + + MOVD R1, R15 // R15 is unchanged by C code + MOVD g_m(g), R21 // R21 = m + + MOVD runtime·vdsoClockgettimeSym(SB), R12 // Check for VDSO availability + CMP R12, R0 + BEQ fallback + + // Set vdsoPC and vdsoSP for SIGPROF traceback. + MOVD LR, R14 // R14 is unchanged by C code + MOVD R14, m_vdsoPC(R21) + MOVD R15, m_vdsoSP(R21) + + MOVD m_curg(R21), R6 + CMP g, R6 + BNE noswitch + + MOVD m_g0(R21), R7 + MOVD (g_sched+gobuf_sp)(R7), R1 // Set SP to g0 stack + +noswitch: + SUB $16, R1 // Space for results + RLDICR $0, R1, $59, R1 // Align for C code + MOVD R12, CTR + MOVD R1, R4 + BL (CTR) // Call from VDSO + MOVD $0, R0 // Restore R0 + MOVD $0, m_vdsoSP(R21) // Clear vdsoSP + MOVD 0(R1), R3 // sec + MOVD 8(R1), R5 // nsec + MOVD R15, R1 // Restore SP + +finish: // sec is in R3, nsec in R5 // return nsec in R3 MOVD $1000000000, R4 @@ -177,6 +243,14 @@ TEXT runtime·nanotime(SB),NOSPLIT,$16 MOVD R3, ret+0(FP) RET + // Syscall fallback +fallback: + ADD $32, R1, R4 + SYSCALL $SYS_clock_gettime + MOVD 32(R1), R3 + MOVD 48(R1), R5 + JMP finish + TEXT runtime·rtsigprocmask(SB),NOSPLIT|NOFRAME,$0-28 MOVW how+0(FP), R3 MOVD new+8(FP), R4 diff --git a/src/runtime/vdso_elf64.go b/src/runtime/vdso_elf64.go index 851025006586c..7c9bd96277907 100644 --- a/src/runtime/vdso_elf64.go +++ b/src/runtime/vdso_elf64.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // +build linux -// +build amd64 arm64 +// +build amd64 arm64 ppc64 ppc64le package runtime diff --git a/src/runtime/vdso_in_none.go b/src/runtime/vdso_in_none.go index 34cfac56d1245..f2d6bb55d9cba 100644 --- a/src/runtime/vdso_in_none.go +++ b/src/runtime/vdso_in_none.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build linux,!386,!amd64,!arm,!arm64 !linux +// +build linux,!386,!amd64,!arm,!arm64,!ppc64,!ppc64le !linux package runtime diff --git a/src/runtime/vdso_linux.go b/src/runtime/vdso_linux.go index f6a285efd73f2..9827874beabcf 100644 --- a/src/runtime/vdso_linux.go +++ b/src/runtime/vdso_linux.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // +build linux -// +build 386 amd64 arm arm64 +// +build 386 amd64 arm arm64 ppc64 ppc64le package runtime @@ -42,6 +42,8 @@ const ( _STT_FUNC = 2 /* Symbol is a code object */ + _STT_NOTYPE = 0 /* Symbol type is not specified */ + _STB_GLOBAL = 1 /* Global symbol */ _STB_WEAK = 2 /* Weak symbol */ @@ -212,7 +214,8 @@ func vdsoParseSymbols(info *vdsoInfo, version int32) { sym := &info.symtab[symIndex] typ := _ELF_ST_TYPE(sym.st_info) bind := _ELF_ST_BIND(sym.st_info) - if typ != _STT_FUNC || bind != _STB_GLOBAL && bind != _STB_WEAK || sym.st_shndx == _SHN_UNDEF { + // On ppc64x, VDSO functions are of type _STT_NOTYPE. + if typ != _STT_FUNC && typ != _STT_NOTYPE || bind != _STB_GLOBAL && bind != _STB_WEAK || sym.st_shndx == _SHN_UNDEF { return false } if k.name != gostringnocopy(&info.symstrings[sym.st_name]) { diff --git a/src/runtime/vdso_linux_ppc64x.go b/src/runtime/vdso_linux_ppc64x.go new file mode 100644 index 0000000000000..f30946e4c5b31 --- /dev/null +++ b/src/runtime/vdso_linux_ppc64x.go @@ -0,0 +1,25 @@ +// Copyright 2018 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. + +// +build linux +// +build ppc64 ppc64le + +package runtime + +const ( + // vdsoArrayMax is the byte-size of a maximally sized array on this architecture. + // See cmd/compile/internal/ppc64/galign.go arch.MAXWIDTH initialization. + vdsoArrayMax = 1<<50 - 1 +) + +var vdsoLinuxVersion = vdsoVersionKey{"LINUX_2.6.15", 0x75fcba5} + +var vdsoSymbolKeys = []vdsoSymbolKey{ + {"__kernel_clock_gettime", 0xb0cd725, 0xdfa941fd, &vdsoClockgettimeSym}, +} + +// initialize with vsyscall fallbacks +var ( + vdsoClockgettimeSym uintptr = 0 +) diff --git a/src/runtime/vdso_linux_test.go b/src/runtime/vdso_linux_test.go index b5221f90b71e4..ad083c61b443f 100644 --- a/src/runtime/vdso_linux_test.go +++ b/src/runtime/vdso_linux_test.go @@ -3,7 +3,7 @@ // license that can be found in the LICENSE file. // +build linux -// +build 386 amd64 arm arm64 +// +build 386 amd64 arm arm64 ppc64 ppc64le package runtime_test From 88206b89313bd7c143bc0d4946543969255ecc2b Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Fri, 27 Jul 2018 07:21:24 -0400 Subject: [PATCH 0269/1663] test: improve runtime/pprof tests for gccgo In the CPU profile tests for gccgo, check to make sure that the runtime's sigprof handler itself doesn't appear in the profile. Add a "skip if gccgo" guard to one testpoint. Updates #26595 Change-Id: I92a44161d61f17b9305ce09532134edd229745a7 Reviewed-on: https://go-review.googlesource.com/126316 Run-TryBot: Than McIntosh TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/pprof/pprof_test.go | 53 ++++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index 095972fa68198..126ba50054e57 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -72,15 +72,24 @@ func cpuHog2(x int) int { return foo } +// Return a list of functions that we don't want to ever appear in CPU +// profiles. For gccgo, that list includes the sigprof handler itself. +func avoidFunctions() []string { + if runtime.Compiler == "gccgo" { + return []string{"runtime.sigprof"} + } + return nil +} + func TestCPUProfile(t *testing.T) { - testCPUProfile(t, stackContains, []string{"runtime/pprof.cpuHog1"}, func(dur time.Duration) { + testCPUProfile(t, stackContains, []string{"runtime/pprof.cpuHog1"}, avoidFunctions(), func(dur time.Duration) { cpuHogger(cpuHog1, &salt1, dur) }) } func TestCPUProfileMultithreaded(t *testing.T) { defer runtime.GOMAXPROCS(runtime.GOMAXPROCS(2)) - testCPUProfile(t, stackContains, []string{"runtime/pprof.cpuHog1", "runtime/pprof.cpuHog2"}, func(dur time.Duration) { + testCPUProfile(t, stackContains, []string{"runtime/pprof.cpuHog1", "runtime/pprof.cpuHog2"}, avoidFunctions(), func(dur time.Duration) { c := make(chan int) go func() { cpuHogger(cpuHog1, &salt1, dur) @@ -92,7 +101,7 @@ func TestCPUProfileMultithreaded(t *testing.T) { } func TestCPUProfileInlining(t *testing.T) { - testCPUProfile(t, stackContains, []string{"runtime/pprof.inlinedCallee", "runtime/pprof.inlinedCaller"}, func(dur time.Duration) { + testCPUProfile(t, stackContains, []string{"runtime/pprof.inlinedCallee", "runtime/pprof.inlinedCaller"}, avoidFunctions(), func(dur time.Duration) { cpuHogger(inlinedCaller, &salt1, dur) }) } @@ -132,7 +141,7 @@ func parseProfile(t *testing.T, valBytes []byte, f func(uintptr, []*profile.Loca // testCPUProfile runs f under the CPU profiler, checking for some conditions specified by need, // as interpreted by matches. -func testCPUProfile(t *testing.T, matches matchFunc, need []string, f func(dur time.Duration)) { +func testCPUProfile(t *testing.T, matches matchFunc, need []string, avoid []string, f func(dur time.Duration)) { switch runtime.GOOS { case "darwin": switch runtime.GOARCH { @@ -171,7 +180,7 @@ func testCPUProfile(t *testing.T, matches matchFunc, need []string, f func(dur t f(duration) StopCPUProfile() - if profileOk(t, need, matches, prof, duration) { + if profileOk(t, matches, need, avoid, prof, duration) { return } @@ -218,11 +227,13 @@ func stackContains(spec string, count uintptr, stk []*profile.Location, labels m type matchFunc func(spec string, count uintptr, stk []*profile.Location, labels map[string][]string) bool -func profileOk(t *testing.T, need []string, matches matchFunc, prof bytes.Buffer, duration time.Duration) (ok bool) { +func profileOk(t *testing.T, matches matchFunc, need []string, avoid []string, prof bytes.Buffer, duration time.Duration) (ok bool) { ok = true - // Check that profile is well formed and contains need. + // Check that profile is well formed, contains 'need', and does not contain + // anything from 'avoid'. have := make([]uintptr, len(need)) + avoidSamples := make([]uintptr, len(avoid)) var samples uintptr var buf bytes.Buffer parseProfile(t, prof.Bytes(), func(count uintptr, stk []*profile.Location, labels map[string][]string) { @@ -234,6 +245,15 @@ func profileOk(t *testing.T, need []string, matches matchFunc, prof bytes.Buffer have[i] += count } } + for i, name := range avoid { + for _, loc := range stk { + for _, line := range loc.Line { + if strings.Contains(line.Function.Name, name) { + avoidSamples[i] += count + } + } + } + } fmt.Fprintf(&buf, "\n") }) t.Logf("total %d CPU profile samples collected:\n%s", samples, buf.String()) @@ -256,6 +276,14 @@ func profileOk(t *testing.T, need []string, matches matchFunc, prof bytes.Buffer ok = false } + for i, name := range avoid { + bad := avoidSamples[i] + if bad != 0 { + t.Logf("found %d samples in avoid-function %s\n", bad, name) + ok = false + } + } + if len(need) == 0 { return ok } @@ -323,6 +351,9 @@ func TestCPUProfileWithFork(t *testing.T) { // If it did, it would see inconsistent state and would either record an incorrect stack // or crash because the stack was malformed. func TestGoroutineSwitch(t *testing.T) { + if runtime.Compiler == "gccgo" { + t.Skip("not applicable for gccgo") + } // How much to try. These defaults take about 1 seconds // on a 2012 MacBook Pro. The ones in short mode take // about 0.1 seconds. @@ -382,7 +413,7 @@ func fprintStack(w io.Writer, stk []*profile.Location) { // Test that profiling of division operations is okay, especially on ARM. See issue 6681. func TestMathBigDivide(t *testing.T) { - testCPUProfile(t, nil, nil, func(duration time.Duration) { + testCPUProfile(t, nil, nil, nil, func(duration time.Duration) { t := time.After(duration) pi := new(big.Int) for { @@ -411,7 +442,7 @@ func stackContainsAll(spec string, count uintptr, stk []*profile.Location, label } func TestMorestack(t *testing.T) { - testCPUProfile(t, stackContainsAll, []string{"runtime.newstack,runtime/pprof.growstack"}, func(duration time.Duration) { + testCPUProfile(t, stackContainsAll, []string{"runtime.newstack,runtime/pprof.growstack"}, avoidFunctions(), func(duration time.Duration) { t := time.After(duration) c := make(chan bool) for { @@ -913,7 +944,7 @@ func stackContainsLabeled(spec string, count uintptr, stk []*profile.Location, l } func TestCPUProfileLabel(t *testing.T) { - testCPUProfile(t, stackContainsLabeled, []string{"runtime/pprof.cpuHogger;key=value"}, func(dur time.Duration) { + testCPUProfile(t, stackContainsLabeled, []string{"runtime/pprof.cpuHogger;key=value"}, avoidFunctions(), func(dur time.Duration) { Do(context.Background(), Labels("key", "value"), func(context.Context) { cpuHogger(cpuHog1, &salt1, dur) }) @@ -924,7 +955,7 @@ func TestLabelRace(t *testing.T) { // Test the race detector annotations for synchronization // between settings labels and consuming them from the // profile. - testCPUProfile(t, stackContainsLabeled, []string{"runtime/pprof.cpuHogger;key=value"}, func(dur time.Duration) { + testCPUProfile(t, stackContainsLabeled, []string{"runtime/pprof.cpuHogger;key=value"}, nil, func(dur time.Duration) { start := time.Now() var wg sync.WaitGroup for time.Since(start) < dur { From 4d01f9243c6dfcd82993483063421fc8aceeb353 Mon Sep 17 00:00:00 2001 From: Venil Noronha Date: Fri, 31 Aug 2018 10:11:22 -0700 Subject: [PATCH 0270/1663] fmt: add example for Fscanf Change-Id: Ia3dcb3a82e452fdcf0d087e8cd01ac01ca831c84 Reviewed-on: https://go-review.googlesource.com/132597 Reviewed-by: Joe Tsai Reviewed-by: Kevin Burke Run-TryBot: Joe Tsai --- src/fmt/example_test.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index 1d2cc0d7574c9..9b72d7a38376c 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -7,6 +7,7 @@ package fmt_test import ( "fmt" "os" + "strings" ) // The Errorf function lets us use formatting features @@ -18,6 +19,24 @@ func ExampleErrorf() { // Output: user "bueller" (id 17) not found } +func ExampleFscanf() { + var ( + i int + b bool + s string + ) + r := strings.NewReader("5 true gophers") + n, err := fmt.Fscanf(r, "%d %t %s", &i, &b, &s) + if err != nil { + panic(err) + } + fmt.Println(i, b, s) + fmt.Println(n) + // Output: + // 5 true gophers + // 3 +} + func ExampleSprintf() { i := 30 s := "Aug" From 579768e0785f14032e3a971ad03f2deb33427e2d Mon Sep 17 00:00:00 2001 From: Muhammad Falak R Wani Date: Fri, 31 Aug 2018 23:48:15 +0530 Subject: [PATCH 0271/1663] fmt: add example for Fscanln Updates golang/go#27376. Change-Id: I9f33233f1aafa10941a63fcb4e49d351ea7ee246 Reviewed-on: https://go-review.googlesource.com/132675 Reviewed-by: Kevin Burke Run-TryBot: Kevin Burke TryBot-Result: Gobot Gobot --- src/fmt/example_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index 9b72d7a38376c..1479b761b6e0f 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -6,6 +6,7 @@ package fmt_test import ( "fmt" + "io" "os" "strings" ) @@ -77,3 +78,25 @@ func ExampleFprintln() { // there are 99 gophers // 21 } + +func ExampleFscanln() { + s := `dmr 1771 1.61803398875 + ken 271828 3.14159` + r := strings.NewReader(s) + var a string + var b int + var c float64 + for { + n, err := fmt.Fscanln(r, &a, &b, &c) + if err == io.EOF { + break + } + if err != nil { + panic(err) + } + fmt.Printf("%d: %s, %d, %f\n", n, a, b, c) + } + // Output: + // 3: dmr, 1771, 1.618034 + // 3: ken, 271828, 3.141590 +} From 1d15354fb931a81a66fdc4a6101df711bd738a4b Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Fri, 31 Aug 2018 23:34:39 +0200 Subject: [PATCH 0272/1663] os/exec: document how to do special args quoting on Windows Updates #27199 Change-Id: I5cb6540266901697d3558ce75b8de63b1bfc2ce0 Reviewed-on: https://go-review.googlesource.com/132695 Reviewed-by: Alex Brainman --- src/os/exec/exec.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/os/exec/exec.go b/src/os/exec/exec.go index 88b0a916992ed..1aa3ab93dcc12 100644 --- a/src/os/exec/exec.go +++ b/src/os/exec/exec.go @@ -152,6 +152,15 @@ type Cmd struct { // followed by the elements of arg, so arg should not include the // command name itself. For example, Command("echo", "hello"). // Args[0] is always name, not the possibly resolved Path. +// +// On Windows, processes receive the whole command line as a single string +// and do their own parsing. Command combines and quotes Args into a command +// line string with an algorithm compatible with applications using +// CommandLineToArgvW (which is the most common way). Notable exceptions are +// msiexec.exe and cmd.exe (and thus, all batch files), which have a different +// unquoting algorithm. In these or other similar cases, you can do the +// quoting yourself and provide the full command line in SysProcAttr.CmdLine, +// leaving Args empty. func Command(name string, arg ...string) *Cmd { cmd := &Cmd{ Path: name, From c9cc20bd3ad7ab68f620cb650376f1c01dc1167e Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Sat, 1 Sep 2018 15:43:20 +0000 Subject: [PATCH 0273/1663] crypto/x509: revert change of article in SystemCertPool docs The words 'the returned' were changed to 'a returned' in 8201b92aae7ba51ed2e2645c1f7815bfe845db72 when referring to the value returned by SystemCertPool. Brad Fitz pointed out after that commit was merged that it makes the wording of this function doc inconsistent with rest of the stdlib since 'a returned' is not used anywhere, but 'the returned' is frequently used. Fixes #27385 Change-Id: I289b533a5a0b5c63eaf0abb6dec0085388ecf76b GitHub-Last-Rev: 6c83b8025704e291ebe5b15dd2ac3fa65b1b48ff GitHub-Pull-Request: golang/go#27438 Reviewed-on: https://go-review.googlesource.com/132776 Reviewed-by: Brad Fitzpatrick --- src/crypto/x509/cert_pool.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/crypto/x509/cert_pool.go b/src/crypto/x509/cert_pool.go index 5381f0d659043..86aba6710daf8 100644 --- a/src/crypto/x509/cert_pool.go +++ b/src/crypto/x509/cert_pool.go @@ -47,7 +47,7 @@ func (s *CertPool) copy() *CertPool { // SystemCertPool returns a copy of the system cert pool. // -// Any mutations to a returned pool are not written to disk and do +// Any mutations to the returned pool are not written to disk and do // not affect any other pool returned by SystemCertPool. // // New changes in the the system cert pool might not be reflected From f02cc88f46e01c21e550dbf212aefcdad138a91d Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Sat, 19 May 2018 09:42:52 +0200 Subject: [PATCH 0274/1663] test: relax whitespaces matching in codegen tests The codegen testsuite uses regexp to parse the syntax, but it doesn't have a way to tell line comments containing checks from line comments containing English sentences. This means that any syntax error (that is, non-matching regexp) is currently ignored and not reported. There were some tests in memcombine.go that had an extraneous space and were thus effectively disabled. It would be great if we could report it as a syntax error, but for now we just punt and swallow the spaces as a workaround, to avoid the same mistake again. Fixes #25452 Change-Id: Ic7747a2278bc00adffd0c199ce40937acbbc9cf0 Reviewed-on: https://go-review.googlesource.com/113835 Run-TryBot: Giovanni Bajo TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- test/codegen/memcombine.go | 4 ++-- test/run.go | 9 +++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/test/codegen/memcombine.go b/test/codegen/memcombine.go index 0db366250f25b..9c4b36818e270 100644 --- a/test/codegen/memcombine.go +++ b/test/codegen/memcombine.go @@ -503,7 +503,7 @@ func zero_byte_16(b []byte) { /* TODO: enable them when corresponding optimization are implemented func zero_byte_4_idx(b []byte, idx int) { - // arm64: `MOVW\sZR,\s\(R[0-9]+\)\(R[0-9]+<<2\)`,-`MOV[BH]` + // arm64(DISABLED): `MOVW\sZR,\s\(R[0-9]+\)\(R[0-9]+<<2\)`,-`MOV[BH]` b[(idx<<2)+0] = 0 b[(idx<<2)+1] = 0 b[(idx<<2)+2] = 0 @@ -511,7 +511,7 @@ func zero_byte_4_idx(b []byte, idx int) { } func zero_byte_8_idx(b []byte, idx int) { - // arm64: `MOVD\sZR,\s\(R[0-9]+\)\(R[0-9]+<<3\)`,-`MOV[BHW]` + // arm64(DISABLED): `MOVD\sZR,\s\(R[0-9]+\)\(R[0-9]+<<3\)`,-`MOV[BHW]` b[(idx<<3)+0] = 0 b[(idx<<3)+1] = 0 b[(idx<<3)+2] = 0 diff --git a/test/run.go b/test/run.go index 82508d1c1fa53..24a4d4f425fe1 100644 --- a/test/run.go +++ b/test/run.go @@ -1329,11 +1329,12 @@ const ( var ( // Regexp to split a line in code and comment, trimming spaces - rxAsmComment = regexp.MustCompile(`^\s*(.*?)\s*(?:\/\/\s*(.+)\s*)?$`) + rxAsmComment = regexp.MustCompile(`^\s*(.*?)\s*(?://\s*(.+)\s*)?$`) - // Regexp to extract an architecture check: architecture name, followed by semi-colon, - // followed by a comma-separated list of opcode checks. - rxAsmPlatform = regexp.MustCompile(`(\w+)(/\w+)?(/\w*)?:(` + reMatchCheck + `(?:,` + reMatchCheck + `)*)`) + // Regexp to extract an architecture check: architecture name (or triplet), + // followed by semi-colon, followed by a comma-separated list of opcode checks. + // Extraneous spaces are ignored. + rxAsmPlatform = regexp.MustCompile(`(\w+)(/\w+)?(/\w*)?\s*:\s*(` + reMatchCheck + `(?:\s*,\s*` + reMatchCheck + `)*)`) // Regexp to extract a single opcoded check rxAsmCheck = regexp.MustCompile(reMatchCheck) From dd5e9b32ff60f99f993953a74e39d505914c6a56 Mon Sep 17 00:00:00 2001 From: Giovanni Bajo Date: Sun, 15 Apr 2018 23:52:12 +0200 Subject: [PATCH 0275/1663] cmd/compile: add testcase for #24876 This is still not fixed, the testcase reflects that there are still a few boundchecks. Let's fix the good alternative with an explicit test though. Updates #24876 Change-Id: I4da35eb353e19052bd7b69ea6190a69ced8b9b3d Reviewed-on: https://go-review.googlesource.com/107355 Reviewed-by: Brad Fitzpatrick Run-TryBot: Giovanni Bajo TryBot-Result: Gobot Gobot --- test/checkbce.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/checkbce.go b/test/checkbce.go index 430dcf9cbc285..0a2842f10c0b8 100644 --- a/test/checkbce.go +++ b/test/checkbce.go @@ -10,6 +10,8 @@ package main +import "encoding/binary" + func f0(a []int) { a[0] = 1 // ERROR "Found IsInBounds$" a[0] = 1 @@ -142,6 +144,33 @@ func g4(a [100]int) { } } +func decode1(data []byte) (x uint64) { + for len(data) >= 32 { + x += binary.BigEndian.Uint64(data[:8]) + x += binary.BigEndian.Uint64(data[8:16]) + x += binary.BigEndian.Uint64(data[16:24]) + x += binary.BigEndian.Uint64(data[24:32]) + data = data[32:] + } + return x +} + +func decode2(data []byte) (x uint64) { + // TODO(rasky): this should behave like decode1 and compile to no + // boundchecks. We're currently not able to remove all of them. + for len(data) >= 32 { + x += binary.BigEndian.Uint64(data) + data = data[8:] + x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$" + data = data[8:] + x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$" + data = data[8:] + x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$" + data = data[8:] + } + return x +} + //go:noinline func useInt(a int) { } From 317afdc3fbb477f310d9f3e9b2d8e3a381399826 Mon Sep 17 00:00:00 2001 From: Phil Pearl Date: Sun, 2 Sep 2018 17:03:34 +0100 Subject: [PATCH 0276/1663] strings: simplify Join using Builder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing implementation has a bunch of special cases and suffers an additional allocation for longer arrays. We can replace this code with a simple implementation using Builder, improve performance and reduce complexity. name old time/op new time/op delta Join/0-8 3.53ns ± 3% 3.72ns ± 2% +5.56% (p=0.000 n=10+10) Join/1-8 3.94ns ± 4% 3.40ns ± 4% -13.57% (p=0.000 n=10+10) Join/2-8 57.0ns ± 3% 51.0ns ± 1% -10.48% (p=0.000 n=10+9) Join/3-8 74.9ns ± 2% 65.5ns ± 4% -12.60% (p=0.000 n=10+10) Join/4-8 105ns ± 0% 79ns ± 4% -24.63% (p=0.000 n=6+10) Join/5-8 116ns ± 2% 91ns ± 4% -21.95% (p=0.000 n=10+10) Join/6-8 131ns ± 1% 104ns ± 1% -20.66% (p=0.000 n=10+10) Join/7-8 141ns ± 0% 114ns ± 4% -18.82% (p=0.000 n=9+10) name old alloc/op new alloc/op delta Join/0-8 0.00B 0.00B ~ (all equal) Join/1-8 0.00B 0.00B ~ (all equal) Join/2-8 16.0B ± 0% 16.0B ± 0% ~ (all equal) Join/3-8 32.0B ± 0% 32.0B ± 0% ~ (all equal) Join/4-8 96.0B ± 0% 48.0B ± 0% -50.00% (p=0.000 n=10+10) Join/5-8 96.0B ± 0% 48.0B ± 0% -50.00% (p=0.000 n=10+10) Join/6-8 128B ± 0% 64B ± 0% -50.00% (p=0.000 n=10+10) Join/7-8 128B ± 0% 64B ± 0% -50.00% (p=0.000 n=10+10) name old allocs/op new allocs/op delta Join/0-8 0.00 0.00 ~ (all equal) Join/1-8 0.00 0.00 ~ (all equal) Join/2-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) Join/3-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) Join/4-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) Join/5-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) Join/6-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) Join/7-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) Change-Id: I866a50e809c398512cb87648c955eaa4bf4d8606 Reviewed-on: https://go-review.googlesource.com/132895 Reviewed-by: Brad Fitzpatrick --- src/strings/strings.go | 19 ++++++------------- src/strings/strings_test.go | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/strings/strings.go b/src/strings/strings.go index e0bebced63f84..df95715ec859a 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -423,27 +423,20 @@ func Join(a []string, sep string) string { return "" case 1: return a[0] - case 2: - // Special case for common small values. - // Remove if golang.org/issue/6714 is fixed - return a[0] + sep + a[1] - case 3: - // Special case for common small values. - // Remove if golang.org/issue/6714 is fixed - return a[0] + sep + a[1] + sep + a[2] } n := len(sep) * (len(a) - 1) for i := 0; i < len(a); i++ { n += len(a[i]) } - b := make([]byte, n) - bp := copy(b, a[0]) + var b Builder + b.Grow(n) + b.WriteString(a[0]) for _, s := range a[1:] { - bp += copy(b[bp:], sep) - bp += copy(b[bp:], s) + b.WriteString(sep) + b.WriteString(s) } - return string(b) + return b.String() } // HasPrefix tests whether the string s begins with prefix. diff --git a/src/strings/strings_test.go b/src/strings/strings_test.go index d6197ed895e8b..20bc484f3950b 100644 --- a/src/strings/strings_test.go +++ b/src/strings/strings_test.go @@ -10,6 +10,7 @@ import ( "io" "math/rand" "reflect" + "strconv" . "strings" "testing" "unicode" @@ -1711,3 +1712,16 @@ func BenchmarkIndexPeriodic(b *testing.B) { }) } } + +func BenchmarkJoin(b *testing.B) { + vals := []string{"red", "yellow", "pink", "green", "purple", "orange", "blue"} + for l := 0; l <= len(vals); l++ { + b.Run(strconv.Itoa(l), func(b *testing.B) { + b.ReportAllocs() + vals := vals[:l] + for i := 0; i < b.N; i++ { + Join(vals, " and ") + } + }) + } +} From 860484a15f578911e2e92b4857a2229f0a257b45 Mon Sep 17 00:00:00 2001 From: Ankit Goyal Date: Sat, 1 Sep 2018 10:56:00 -0700 Subject: [PATCH 0277/1663] strconv: add example for IsGraphic Change-Id: I58ba1f5d5c942d6a345c19df1bca80b63fb5abf5 Reviewed-on: https://go-review.googlesource.com/132777 Reviewed-by: Brad Fitzpatrick --- src/strconv/example_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/strconv/example_test.go b/src/strconv/example_test.go index 5c2e8a9b5608b..15725456e2633 100644 --- a/src/strconv/example_test.go +++ b/src/strconv/example_test.go @@ -167,6 +167,22 @@ func ExampleFormatUint() { // string, 2a } +func ExampleIsGraphic() { + shamrock := strconv.IsGraphic('☘') + fmt.Println(shamrock) + + a := strconv.IsGraphic('a') + fmt.Println(a) + + bel := strconv.IsGraphic('\007') + fmt.Println(bel) + + // Output: + // true + // true + // false +} + func ExampleIsPrint() { c := strconv.IsPrint('\u263a') fmt.Println(c) From b794ca64d29f3e584cbdf49bde7141d3c12dd2ab Mon Sep 17 00:00:00 2001 From: Charles Kenney Date: Mon, 3 Sep 2018 07:02:03 +0000 Subject: [PATCH 0278/1663] runtime/trace: fix syntax errors in NewTask doc example Fixes #27406 Change-Id: I9c6f5bac5b26558fa7628233c74a62faf676e811 GitHub-Last-Rev: 29d19f719316b486224a15a50556465811985edf GitHub-Pull-Request: golang/go#27437 Reviewed-on: https://go-review.googlesource.com/132775 Reviewed-by: Emmanuel Odeke Run-TryBot: Emmanuel Odeke TryBot-Result: Gobot Gobot --- src/runtime/trace/annotation.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/runtime/trace/annotation.go b/src/runtime/trace/annotation.go index 3545ef3bba571..d5a7d003fe2fc 100644 --- a/src/runtime/trace/annotation.go +++ b/src/runtime/trace/annotation.go @@ -24,13 +24,13 @@ type traceContextKey struct{} // If the end function is called multiple times, only the first // call is used in the latency measurement. // -// ctx, task := trace.NewTask(ctx, "awesome task") -// trace.WithRegion(ctx, prepWork) +// ctx, task := trace.NewTask(ctx, "awesomeTask") +// trace.WithRegion(ctx, "preparation", prepWork) // // preparation of the task // go func() { // continue processing the task in a separate goroutine. // defer task.End() -// trace.WithRegion(ctx, remainingWork) -// } +// trace.WithRegion(ctx, "remainingWork", remainingWork) +// }() func NewTask(pctx context.Context, taskType string) (ctx context.Context, task *Task) { pid := fromContext(pctx).id id := newID() From ff468a43be1740890a0f3b64a6ab920ea92c2c17 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Fri, 27 Jul 2018 19:32:17 +0300 Subject: [PATCH 0279/1663] cmd/compile/internal/gc: better handling of self-assignments in esc.go Teach escape analysis to recognize these assignment patterns as not causing the src to leak: val.x = val.y val.x[i] = val.y[j] val.x1.x2 = val.x1.y2 ... etc Helps to avoid "leaking param" with assignments showed above. The implementation is based on somewhat similiar xs=xs[a:b] special case that is ignored by the escape analysis. We may figure out more generalized version of this, but this one looks like a safe step into that direction. Updates #14858 Change-Id: I6fe5bfedec9c03bdc1d7624883324a523bd11fde Reviewed-on: https://go-review.googlesource.com/126395 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/esc.go | 68 +++++++++++++++++++++++++++ test/escape_param.go | 75 ++++++++++++++++++++++++++++-- 2 files changed, 138 insertions(+), 5 deletions(-) diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go index 3df565aea51c6..a852e0a3d0f77 100644 --- a/src/cmd/compile/internal/gc/esc.go +++ b/src/cmd/compile/internal/gc/esc.go @@ -654,6 +654,58 @@ func (e *EscState) esclist(l Nodes, parent *Node) { } } +// isSelfAssign reports whether assignment from src to dst can +// be ignored by the escape analysis as it's effectively a self-assignment. +func (e *EscState) isSelfAssign(dst, src *Node) bool { + if dst == nil || src == nil || dst.Op != src.Op { + return false + } + + switch dst.Op { + case ODOT, ODOTPTR: + // Safe trailing accessors that are permitted to differ. + case OINDEX: + if e.mayAffectMemory(dst.Right) || e.mayAffectMemory(src.Right) { + return false + } + default: + return false + } + + // The expression prefix must be both "safe" and identical. + return samesafeexpr(dst.Left, src.Left) +} + +// mayAffectMemory reports whether n evaluation may affect program memory state. +// If expression can't affect it, then it can be safely ignored by the escape analysis. +func (e *EscState) mayAffectMemory(n *Node) bool { + // We may want to use "memory safe" black list instead of general + // "side-effect free", which can include all calls and other ops + // that can affect allocate or change global state. + // It's safer to start from a whitelist for now. + // + // We're ignoring things like division by zero, index out of range, + // and nil pointer dereference here. + switch n.Op { + case ONAME, OCLOSUREVAR, OLITERAL: + return false + case ODOT, ODOTPTR: + return e.mayAffectMemory(n.Left) + case OIND, OCONVNOP: + return e.mayAffectMemory(n.Left) + case OCONV: + return e.mayAffectMemory(n.Left) + case OINDEX: + return e.mayAffectMemory(n.Left) && e.mayAffectMemory(n.Right) + case OADD, OSUB, OOR, OXOR, OMUL, OLSH, ORSH, OAND, OANDNOT, ODIV, OMOD: + return e.mayAffectMemory(n.Left) && e.mayAffectMemory(n.Right) + case ONOT, OCOM, OPLUS, OMINUS, OALIGNOF, OOFFSETOF, OSIZEOF: + return e.mayAffectMemory(n.Left) + default: + return true + } +} + func (e *EscState) esc(n *Node, parent *Node) { if n == nil { return @@ -813,6 +865,22 @@ opSwitch: break } + // Also skip trivial assignments that assign back to the same object. + // + // It covers these cases: + // val.x = val.y + // val.x[i] = val.y[j] + // val.x1.x2 = val.x1.y2 + // ... etc + // + // These assignments do not change assigned object lifetime. + if e.isSelfAssign(n.Left, n.Right) { + if Debug['m'] != 0 { + Warnl(n.Pos, "%v ignoring self-assignment in %S", e.curfnSym(n), n) + } + break + } + e.escassign(n.Left, n.Right, e.stepAssignWhere(nil, nil, "", n)) case OAS2: // x,y = a,b diff --git a/test/escape_param.go b/test/escape_param.go index 2c43b96ba0316..4eb96dff9bab7 100644 --- a/test/escape_param.go +++ b/test/escape_param.go @@ -58,20 +58,85 @@ func caller2b() { sink = p // ERROR "p escapes to heap$" } +func paramArraySelfAssign(p *PairOfPairs) { // ERROR "p does not escape" + p.pairs[0] = p.pairs[1] // ERROR "ignoring self-assignment in p.pairs\[0\] = p.pairs\[1\]" +} + +type PairOfPairs struct { + pairs [2]*Pair +} + +type BoxedPair struct { + pair *Pair +} + +type WrappedPair struct { + pair Pair +} + +func leakParam(x interface{}) { // ERROR "leaking param: x" + sink = x +} + +func sinkAfterSelfAssignment1(box *BoxedPair) { // ERROR "leaking param content: box" + box.pair.p1 = box.pair.p2 // ERROR "ignoring self-assignment in box.pair.p1 = box.pair.p2" + sink = box.pair.p2 // ERROR "box.pair.p2 escapes to heap" +} + +func sinkAfterSelfAssignment2(box *BoxedPair) { // ERROR "leaking param content: box" + box.pair.p1 = box.pair.p2 // ERROR "ignoring self-assignment in box.pair.p1 = box.pair.p2" + sink = box.pair // ERROR "box.pair escapes to heap" +} + +func sinkAfterSelfAssignment3(box *BoxedPair) { // ERROR "leaking param content: box" + box.pair.p1 = box.pair.p2 // ERROR "ignoring self-assignment in box.pair.p1 = box.pair.p2" + leakParam(box.pair.p2) // ERROR "box.pair.p2 escapes to heap" +} + +func sinkAfterSelfAssignment4(box *BoxedPair) { // ERROR "leaking param content: box" + box.pair.p1 = box.pair.p2 // ERROR "ignoring self-assignment in box.pair.p1 = box.pair.p2" + leakParam(box.pair) // ERROR "box.pair escapes to heap" +} + +func selfAssignmentAndUnrelated(box1, box2 *BoxedPair) { // ERROR "leaking param content: box2" "box1 does not escape" + box1.pair.p1 = box1.pair.p2 // ERROR "ignoring self-assignment in box1.pair.p1 = box1.pair.p2" + leakParam(box2.pair.p2) // ERROR "box2.pair.p2 escapes to heap" +} + +func notSelfAssignment1(box1, box2 *BoxedPair) { // ERROR "leaking param content: box2" "box1 does not escape" + box1.pair.p1 = box2.pair.p1 +} + +func notSelfAssignment2(p1, p2 *PairOfPairs) { // ERROR "leaking param content: p2" "p1 does not escape" + p1.pairs[0] = p2.pairs[1] +} + +func notSelfAssignment3(p1, p2 *PairOfPairs) { // ERROR "leaking param content: p2" "p1 does not escape" + p1.pairs[0].p1 = p2.pairs[1].p1 +} + +func boxedPairSelfAssign(box *BoxedPair) { // ERROR "box does not escape" + box.pair.p1 = box.pair.p2 // ERROR "ignoring self-assignment in box.pair.p1 = box.pair.p2" +} + +func wrappedPairSelfAssign(w *WrappedPair) { // ERROR "w does not escape" + w.pair.p1 = w.pair.p2 // ERROR "ignoring self-assignment in w.pair.p1 = w.pair.p2" +} + // in -> in type Pair struct { p1 *int p2 *int } -func param3(p *Pair) { // ERROR "leaking param content: p$" - p.p1 = p.p2 +func param3(p *Pair) { // ERROR "param3 p does not escape" + p.p1 = p.p2 // ERROR "param3 ignoring self-assignment in p.p1 = p.p2" } func caller3a() { - i := 0 // ERROR "moved to heap: i$" - j := 0 // ERROR "moved to heap: j$" - p := Pair{&i, &j} // ERROR "&i escapes to heap$" "&j escapes to heap$" + i := 0 + j := 0 + p := Pair{&i, &j} // ERROR "caller3a &i does not escape" "caller3a &j does not escape" param3(&p) // ERROR "caller3a &p does not escape" _ = p } From 6f9b94ab6658bbebe4c89791dc3e5ebe53be3d82 Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Fri, 25 May 2018 17:54:58 +0100 Subject: [PATCH 0280/1663] cmd/compile: implement OnesCount{8,16,32,64} intrinsics on s390x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL implements the math/bits.OnesCount{8,16,32,64} functions as intrinsics on s390x using the 'population count' (popcnt) instruction. This instruction was released as the 'population-count' facility which uses the same facility bit (45) as the 'distinct-operands' facility which is a pre-requisite for Go on s390x. We can therefore use it without a feature check. The s390x popcnt instruction treats a 64 bit register as a vector of 8 bytes, summing the number of ones in each byte individually. It then writes the results to the corresponding bytes in the output register. Therefore to implement OnesCount{16,32,64} we need to sum the individual byte counts using some extra instructions. To do this efficiently I've added some additional pseudo operations to the s390x SSA backend. Unlike other architectures the new instruction sequence is faster for OnesCount8, so that is implemented using the intrinsic. name old time/op new time/op delta OnesCount 3.21ns ± 1% 1.35ns ± 0% -58.00% (p=0.000 n=20+20) OnesCount8 0.91ns ± 1% 0.81ns ± 0% -11.43% (p=0.000 n=20+20) OnesCount16 1.51ns ± 3% 1.21ns ± 0% -19.71% (p=0.000 n=20+17) OnesCount32 1.91ns ± 0% 1.12ns ± 1% -41.60% (p=0.000 n=19+20) OnesCount64 3.18ns ± 4% 1.35ns ± 0% -57.52% (p=0.000 n=20+20) Change-Id: Id54f0bd28b6db9a887ad12c0d72fcc168ef9c4e0 Reviewed-on: https://go-review.googlesource.com/114675 Run-TryBot: Michael Munday TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/asm/internal/asm/testdata/s390x.s | 1 + src/cmd/compile/internal/gc/ssa.go | 12 +- src/cmd/compile/internal/s390x/ssa.go | 5 +- src/cmd/compile/internal/ssa/gen/S390X.rules | 28 ++++ src/cmd/compile/internal/ssa/gen/S390XOps.go | 19 +++ src/cmd/compile/internal/ssa/opGen.go | 33 ++++ src/cmd/compile/internal/ssa/rewriteS390X.go | 149 +++++++++++++++++++ src/cmd/internal/obj/s390x/a.out.go | 3 + src/cmd/internal/obj/s390x/anames.go | 1 + src/cmd/internal/obj/s390x/asmz.go | 6 + test/codegen/mathbits.go | 9 ++ 11 files changed, 261 insertions(+), 5 deletions(-) diff --git a/src/cmd/asm/internal/asm/testdata/s390x.s b/src/cmd/asm/internal/asm/testdata/s390x.s index fce855ee3008e..ad70d2af44822 100644 --- a/src/cmd/asm/internal/asm/testdata/s390x.s +++ b/src/cmd/asm/internal/asm/testdata/s390x.s @@ -115,6 +115,7 @@ TEXT main·foo(SB),DUPOK|NOSPLIT,$16-0 // TEXT main.foo(SB), DUPOK|NOSPLIT, $16- NEGW R1 // b9130011 NEGW R1, R2 // b9130021 FLOGR R2, R2 // b9830022 + POPCNT R3, R4 // b9e10043 AND R1, R2 // b9800021 AND R1, R2, R3 // b9e42031 diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 4c2f0098ce6aa..3aef7e6b6d927 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -3410,7 +3410,7 @@ func init() { func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return s.newValue1(ssa.OpPopCount64, types.Types[TINT], args[0]) }, - sys.PPC64, sys.ARM64) + sys.PPC64, sys.ARM64, sys.S390X) addF("math/bits", "OnesCount32", makeOnesCountAMD64(ssa.OpPopCount32, ssa.OpPopCount32), sys.AMD64) @@ -3418,7 +3418,7 @@ func init() { func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return s.newValue1(ssa.OpPopCount32, types.Types[TINT], args[0]) }, - sys.PPC64, sys.ARM64) + sys.PPC64, sys.ARM64, sys.S390X) addF("math/bits", "OnesCount16", makeOnesCountAMD64(ssa.OpPopCount16, ssa.OpPopCount16), sys.AMD64) @@ -3426,8 +3426,12 @@ func init() { func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return s.newValue1(ssa.OpPopCount16, types.Types[TINT], args[0]) }, - sys.ARM64) - // Note: no OnesCount8, the Go implementation is faster - just a table load. + sys.ARM64, sys.S390X) + addF("math/bits", "OnesCount8", + func(s *state, n *Node, args []*ssa.Value) *ssa.Value { + return s.newValue1(ssa.OpPopCount8, types.Types[TINT], args[0]) + }, + sys.S390X) addF("math/bits", "OnesCount", makeOnesCountAMD64(ssa.OpPopCount64, ssa.OpPopCount32), sys.AMD64) diff --git a/src/cmd/compile/internal/s390x/ssa.go b/src/cmd/compile/internal/s390x/ssa.go index fe206f74e865b..90e61c34fd35c 100644 --- a/src/cmd/compile/internal/s390x/ssa.go +++ b/src/cmd/compile/internal/s390x/ssa.go @@ -513,7 +513,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.To.Type = obj.TYPE_MEM p.To.Name = obj.NAME_EXTERN p.To.Sym = v.Aux.(*obj.LSym) - case ssa.OpS390XFLOGR, ssa.OpS390XNEG, ssa.OpS390XNEGW, + case ssa.OpS390XFLOGR, ssa.OpS390XPOPCNT, + ssa.OpS390XNEG, ssa.OpS390XNEGW, ssa.OpS390XMOVWBR, ssa.OpS390XMOVDBR: p := s.Prog(v.Op.Asm()) p.From.Type = obj.TYPE_REG @@ -522,6 +523,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.To.Reg = v.Reg() case ssa.OpS390XNOT, ssa.OpS390XNOTW: v.Fatalf("NOT/NOTW generated %s", v.LongString()) + case ssa.OpS390XSumBytes2, ssa.OpS390XSumBytes4, ssa.OpS390XSumBytes8: + v.Fatalf("SumBytes generated %s", v.LongString()) case ssa.OpS390XMOVDEQ, ssa.OpS390XMOVDNE, ssa.OpS390XMOVDLT, ssa.OpS390XMOVDLE, ssa.OpS390XMOVDGT, ssa.OpS390XMOVDGE, diff --git a/src/cmd/compile/internal/ssa/gen/S390X.rules b/src/cmd/compile/internal/ssa/gen/S390X.rules index 960d68845f1c3..4fbdef38e7d10 100644 --- a/src/cmd/compile/internal/ssa/gen/S390X.rules +++ b/src/cmd/compile/internal/ssa/gen/S390X.rules @@ -88,6 +88,34 @@ (BitLen64 x) -> (SUB (MOVDconst [64]) (FLOGR x)) +// POPCNT treats the input register as a vector of 8 bytes, producing +// a population count for each individual byte. For inputs larger than +// a single byte we therefore need to sum the individual bytes produced +// by the POPCNT instruction. For example, the following instruction +// sequence could be used to calculate the population count of a 4-byte +// value: +// +// MOVD $0x12345678, R1 // R1=0x12345678 <-- input +// POPCNT R1, R2 // R2=0x02030404 +// SRW $16, R2, R3 // R3=0x00000203 +// ADDW R2, R3, R4 // R4=0x02030607 +// SRW $8, R4, R5 // R5=0x00020306 +// ADDW R4, R5, R6 // R6=0x0205090d +// MOVBZ R6, R7 // R7=0x0000000d <-- result is 13 +// +(PopCount8 x) -> (POPCNT (MOVBZreg x)) +(PopCount16 x) -> (MOVBZreg (SumBytes2 (POPCNT x))) +(PopCount32 x) -> (MOVBZreg (SumBytes4 (POPCNT x))) +(PopCount64 x) -> (MOVBZreg (SumBytes8 (POPCNT x))) + +// SumBytes{2,4,8} pseudo operations sum the values of the rightmost +// 2, 4 or 8 bytes respectively. The result is a single byte however +// other bytes might contain junk so a zero extension is required if +// the desired output type is larger than 1 byte. +(SumBytes2 x) -> (ADDW (SRWconst x [8]) x) +(SumBytes4 x) -> (SumBytes2 (ADDW (SRWconst x [16]) x)) +(SumBytes8 x) -> (SumBytes4 (ADDW (SRDconst x [32]) x)) + (Bswap64 x) -> (MOVDBR x) (Bswap32 x) -> (MOVWBR x) diff --git a/src/cmd/compile/internal/ssa/gen/S390XOps.go b/src/cmd/compile/internal/ssa/gen/S390XOps.go index ae01375473396..9b5f525531a6e 100644 --- a/src/cmd/compile/internal/ssa/gen/S390XOps.go +++ b/src/cmd/compile/internal/ssa/gen/S390XOps.go @@ -530,6 +530,25 @@ func init() { clobberFlags: true, }, + // population count + // + // Counts the number of ones in each byte of arg0 + // and places the result into the corresponding byte + // of the result. + { + name: "POPCNT", + argLength: 1, + reg: gp11, + asm: "POPCNT", + typ: "UInt64", + clobberFlags: true, + }, + + // pseudo operations to sum the output of the POPCNT instruction + {name: "SumBytes2", argLength: 1, typ: "UInt8"}, // sum the rightmost 2 bytes in arg0 ignoring overflow + {name: "SumBytes4", argLength: 1, typ: "UInt8"}, // sum the rightmost 4 bytes in arg0 ignoring overflow + {name: "SumBytes8", argLength: 1, typ: "UInt8"}, // sum all the bytes in arg0 ignoring overflow + // store multiple { name: "STMG2", diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 0689c0ef323dc..1c9d263debd0c 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -1898,6 +1898,10 @@ const ( OpS390XLoweredAtomicExchange32 OpS390XLoweredAtomicExchange64 OpS390XFLOGR + OpS390XPOPCNT + OpS390XSumBytes2 + OpS390XSumBytes4 + OpS390XSumBytes8 OpS390XSTMG2 OpS390XSTMG3 OpS390XSTMG4 @@ -25473,6 +25477,35 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "POPCNT", + argLen: 1, + clobberFlags: true, + asm: s390x.APOPCNT, + reg: regInfo{ + inputs: []inputInfo{ + {0, 23551}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14 + }, + outputs: []outputInfo{ + {0, 23551}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14 + }, + }, + }, + { + name: "SumBytes2", + argLen: 1, + reg: regInfo{}, + }, + { + name: "SumBytes4", + argLen: 1, + reg: regInfo{}, + }, + { + name: "SumBytes8", + argLen: 1, + reg: regInfo{}, + }, { name: "STMG2", auxType: auxSymOff, diff --git a/src/cmd/compile/internal/ssa/rewriteS390X.go b/src/cmd/compile/internal/ssa/rewriteS390X.go index 7125b888bdbfd..768b802ec1f22 100644 --- a/src/cmd/compile/internal/ssa/rewriteS390X.go +++ b/src/cmd/compile/internal/ssa/rewriteS390X.go @@ -383,6 +383,14 @@ func rewriteValueS390X(v *Value) bool { return rewriteValueS390X_OpOr8_0(v) case OpOrB: return rewriteValueS390X_OpOrB_0(v) + case OpPopCount16: + return rewriteValueS390X_OpPopCount16_0(v) + case OpPopCount32: + return rewriteValueS390X_OpPopCount32_0(v) + case OpPopCount64: + return rewriteValueS390X_OpPopCount64_0(v) + case OpPopCount8: + return rewriteValueS390X_OpPopCount8_0(v) case OpRound: return rewriteValueS390X_OpRound_0(v) case OpRound32F: @@ -691,6 +699,12 @@ func rewriteValueS390X(v *Value) bool { return rewriteValueS390X_OpS390XSUBconst_0(v) case OpS390XSUBload: return rewriteValueS390X_OpS390XSUBload_0(v) + case OpS390XSumBytes2: + return rewriteValueS390X_OpS390XSumBytes2_0(v) + case OpS390XSumBytes4: + return rewriteValueS390X_OpS390XSumBytes4_0(v) + case OpS390XSumBytes8: + return rewriteValueS390X_OpS390XSumBytes8_0(v) case OpS390XXOR: return rewriteValueS390X_OpS390XXOR_0(v) || rewriteValueS390X_OpS390XXOR_10(v) case OpS390XXORW: @@ -5311,6 +5325,80 @@ func rewriteValueS390X_OpOrB_0(v *Value) bool { return true } } +func rewriteValueS390X_OpPopCount16_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ + // match: (PopCount16 x) + // cond: + // result: (MOVBZreg (SumBytes2 (POPCNT x))) + for { + x := v.Args[0] + v.reset(OpS390XMOVBZreg) + v0 := b.NewValue0(v.Pos, OpS390XSumBytes2, typ.UInt8) + v1 := b.NewValue0(v.Pos, OpS390XPOPCNT, typ.UInt16) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } +} +func rewriteValueS390X_OpPopCount32_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ + // match: (PopCount32 x) + // cond: + // result: (MOVBZreg (SumBytes4 (POPCNT x))) + for { + x := v.Args[0] + v.reset(OpS390XMOVBZreg) + v0 := b.NewValue0(v.Pos, OpS390XSumBytes4, typ.UInt8) + v1 := b.NewValue0(v.Pos, OpS390XPOPCNT, typ.UInt32) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } +} +func rewriteValueS390X_OpPopCount64_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ + // match: (PopCount64 x) + // cond: + // result: (MOVBZreg (SumBytes8 (POPCNT x))) + for { + x := v.Args[0] + v.reset(OpS390XMOVBZreg) + v0 := b.NewValue0(v.Pos, OpS390XSumBytes8, typ.UInt8) + v1 := b.NewValue0(v.Pos, OpS390XPOPCNT, typ.UInt64) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } +} +func rewriteValueS390X_OpPopCount8_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ + // match: (PopCount8 x) + // cond: + // result: (POPCNT (MOVBZreg x)) + for { + x := v.Args[0] + v.reset(OpS390XPOPCNT) + v0 := b.NewValue0(v.Pos, OpS390XMOVBZreg, typ.UInt64) + v0.AddArg(x) + v.AddArg(v0) + return true + } +} func rewriteValueS390X_OpRound_0(v *Value) bool { // match: (Round x) // cond: @@ -40417,6 +40505,67 @@ func rewriteValueS390X_OpS390XSUBload_0(v *Value) bool { } return false } +func rewriteValueS390X_OpS390XSumBytes2_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ + // match: (SumBytes2 x) + // cond: + // result: (ADDW (SRWconst x [8]) x) + for { + x := v.Args[0] + v.reset(OpS390XADDW) + v0 := b.NewValue0(v.Pos, OpS390XSRWconst, typ.UInt8) + v0.AuxInt = 8 + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(x) + return true + } +} +func rewriteValueS390X_OpS390XSumBytes4_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ + // match: (SumBytes4 x) + // cond: + // result: (SumBytes2 (ADDW (SRWconst x [16]) x)) + for { + x := v.Args[0] + v.reset(OpS390XSumBytes2) + v0 := b.NewValue0(v.Pos, OpS390XADDW, typ.UInt16) + v1 := b.NewValue0(v.Pos, OpS390XSRWconst, typ.UInt16) + v1.AuxInt = 16 + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) + return true + } +} +func rewriteValueS390X_OpS390XSumBytes8_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ + // match: (SumBytes8 x) + // cond: + // result: (SumBytes4 (ADDW (SRDconst x [32]) x)) + for { + x := v.Args[0] + v.reset(OpS390XSumBytes4) + v0 := b.NewValue0(v.Pos, OpS390XADDW, typ.UInt32) + v1 := b.NewValue0(v.Pos, OpS390XSRDconst, typ.UInt32) + v1.AuxInt = 32 + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) + return true + } +} func rewriteValueS390X_OpS390XXOR_0(v *Value) bool { // match: (XOR x (MOVDconst [c])) // cond: isU32Bit(c) diff --git a/src/cmd/internal/obj/s390x/a.out.go b/src/cmd/internal/obj/s390x/a.out.go index babcd2af010b2..9ee02a2d0d72e 100644 --- a/src/cmd/internal/obj/s390x/a.out.go +++ b/src/cmd/internal/obj/s390x/a.out.go @@ -271,6 +271,9 @@ const ( // find leftmost one AFLOGR + // population count + APOPCNT + // integer bitwise AAND AANDW diff --git a/src/cmd/internal/obj/s390x/anames.go b/src/cmd/internal/obj/s390x/anames.go index 7edbdd68dfd02..2d6ea5abb4431 100644 --- a/src/cmd/internal/obj/s390x/anames.go +++ b/src/cmd/internal/obj/s390x/anames.go @@ -45,6 +45,7 @@ var Anames = []string{ "MOVDLT", "MOVDNE", "FLOGR", + "POPCNT", "AND", "ANDW", "OR", diff --git a/src/cmd/internal/obj/s390x/asmz.go b/src/cmd/internal/obj/s390x/asmz.go index ce3fe6af73cf0..359610c41df15 100644 --- a/src/cmd/internal/obj/s390x/asmz.go +++ b/src/cmd/internal/obj/s390x/asmz.go @@ -246,6 +246,9 @@ var optab = []Optab{ // find leftmost one Optab{AFLOGR, C_REG, C_NONE, C_NONE, C_REG, 8, 0}, + // population count + Optab{APOPCNT, C_REG, C_NONE, C_NONE, C_REG, 9, 0}, + // compare Optab{ACMP, C_REG, C_NONE, C_NONE, C_REG, 70, 0}, Optab{ACMP, C_REG, C_NONE, C_NONE, C_LCON, 71, 0}, @@ -2849,6 +2852,9 @@ func (c *ctxtz) asmout(p *obj.Prog, asm *[]byte) { // FLOGR also writes a mask to p.To.Reg+1. zRRE(op_FLOGR, uint32(p.To.Reg), uint32(p.From.Reg), asm) + case 9: // population count + zRRE(op_POPCNT, uint32(p.To.Reg), uint32(p.From.Reg), asm) + case 10: // subtract reg [reg] reg r := int(p.Reg) diff --git a/test/codegen/mathbits.go b/test/codegen/mathbits.go index 85c54ea61b785..ad2c5abb029f6 100644 --- a/test/codegen/mathbits.go +++ b/test/codegen/mathbits.go @@ -103,27 +103,36 @@ func Len8(n uint8) int { func OnesCount(n uint) int { // amd64:"POPCNTQ",".*support_popcnt" // arm64:"VCNT","VUADDLV" + // s390x:"POPCNT" return bits.OnesCount(n) } func OnesCount64(n uint64) int { // amd64:"POPCNTQ",".*support_popcnt" // arm64:"VCNT","VUADDLV" + // s390x:"POPCNT" return bits.OnesCount64(n) } func OnesCount32(n uint32) int { // amd64:"POPCNTL",".*support_popcnt" // arm64:"VCNT","VUADDLV" + // s390x:"POPCNT" return bits.OnesCount32(n) } func OnesCount16(n uint16) int { // amd64:"POPCNTL",".*support_popcnt" // arm64:"VCNT","VUADDLV" + // s390x:"POPCNT" return bits.OnesCount16(n) } +func OnesCount8(n uint8) int { + // s390x:"POPCNT" + return bits.OnesCount8(n) +} + // ----------------------- // // bits.ReverseBytes // // ----------------------- // From 5188c87c955a9caf64a0fb2efd8ea95ee9b30a41 Mon Sep 17 00:00:00 2001 From: Ivan Kutuzov Date: Fri, 31 Aug 2018 09:14:04 -0600 Subject: [PATCH 0281/1663] encoding/pem: fix for TestFuzz, PEM type should not contain a colon Fixes #22238 Change-Id: I8184f789bd4120f3e71c9374c7c2fcbfa95935bf Reviewed-on: https://go-review.googlesource.com/132635 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/encoding/pem/pem_test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/encoding/pem/pem_test.go b/src/encoding/pem/pem_test.go index 6a1751621835f..a1b5afac0866d 100644 --- a/src/encoding/pem/pem_test.go +++ b/src/encoding/pem/pem_test.go @@ -213,7 +213,9 @@ func TestFuzz(t *testing.T) { } testRoundtrip := func(block Block) bool { - if isBad(block.Type) { + // Reject bad Type + // Type with colons will proceed as key/val pair and cause an error. + if isBad(block.Type) || strings.Contains(block.Type, ":") { return true } for key, val := range block.Headers { From 5ed30d82b7ad4d5be12db588f088c34f8c1c0a86 Mon Sep 17 00:00:00 2001 From: Alexey Palazhchenko Date: Mon, 3 Sep 2018 16:24:12 +0000 Subject: [PATCH 0282/1663] database/sql: fix Rows.Columns() documentation Fixes #27202 Change-Id: I83620748a81500e433795c7b2b7f13399d17f777 GitHub-Last-Rev: 64457e12ceaa408efc7f75091f1b30c35b8e5d44 GitHub-Pull-Request: golang/go#27472 Reviewed-on: https://go-review.googlesource.com/133057 Reviewed-by: Daniel Theophanes --- src/database/sql/sql.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index 36179855db2b6..7537f87d47cf5 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -2735,8 +2735,7 @@ func (rs *Rows) Err() error { } // Columns returns the column names. -// Columns returns an error if the rows are closed, or if the rows -// are from QueryRow and there was a deferred error. +// Columns returns an error if the rows are closed. func (rs *Rows) Columns() ([]string, error) { rs.closemu.RLock() defer rs.closemu.RUnlock() From 67ac554d7978eb93f3dfe7a819c67948dd291d88 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Tue, 14 Aug 2018 19:22:16 +0300 Subject: [PATCH 0283/1663] cmd/compile/internal/gc: fix invalid positions for sink nodes in esc.go Make OAS2 and OAS2FUNC sink locations point to the assignment position, not the nth LHS position. Fixes #26987 Change-Id: Ibeb9df2da754da8b6638fe1e49e813f37515c13c Reviewed-on: https://go-review.googlesource.com/129315 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: David Chase Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/gc/esc.go | 6 ++++-- test/escape_because.go | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go index a852e0a3d0f77..99f046ad216df 100644 --- a/src/cmd/compile/internal/gc/esc.go +++ b/src/cmd/compile/internal/gc/esc.go @@ -886,8 +886,9 @@ opSwitch: case OAS2: // x,y = a,b if n.List.Len() == n.Rlist.Len() { rs := n.Rlist.Slice() + where := n for i, n := range n.List.Slice() { - e.escassignWhyWhere(n, rs[i], "assign-pair", n) + e.escassignWhyWhere(n, rs[i], "assign-pair", where) } } @@ -928,11 +929,12 @@ opSwitch: // esccall already done on n.Rlist.First(). tie it's Retval to n.List case OAS2FUNC: // x,y = f() rs := e.nodeEscState(n.Rlist.First()).Retval.Slice() + where := n for i, n := range n.List.Slice() { if i >= len(rs) { break } - e.escassignWhyWhere(n, rs[i], "assign-pair-func-call", n) + e.escassignWhyWhere(n, rs[i], "assign-pair-func-call", where) } if n.List.Len() != len(rs) { Fatalf("esc oas2func") diff --git a/test/escape_because.go b/test/escape_because.go index c7548fc677a5e..0f87f1446f6d6 100644 --- a/test/escape_because.go +++ b/test/escape_because.go @@ -125,6 +125,24 @@ func f14() { _, _ = s1, s2 } +func leakParams(p1, p2 *int) (*int, *int) { // ERROR "leaking param: p1 to result ~r2 level=0$" "from ~r2 \(return\) at escape_because.go:129$" "leaking param: p2 to result ~r3 level=0$" "from ~r3 \(return\) at escape_because.go:129$" + return p1, p2 +} + +func leakThroughOAS2() { + // See #26987. + i := 0 // ERROR "moved to heap: i$" + j := 0 // ERROR "moved to heap: j$" + sink, sink = &i, &j // ERROR "&i escapes to heap$" "from sink \(assign-pair\) at escape_because.go:136$" "from &i \(interface-converted\) at escape_because.go:136$" "&j escapes to heap$" "from &j \(interface-converted\) at escape_because.go:136" +} + +func leakThroughOAS2FUNC() { + // See #26987. + i := 0 // ERROR "moved to heap: i$" + j := 0 + sink, _ = leakParams(&i, &j) // ERROR "&i escapes to heap$" "&j does not escape$" "from .out0 \(passed-to-and-returned-from-call\) at escape_because.go:143$" "from sink \(assign-pair-func-call\) at escape_because.go:143$" +} + // The list below is all of the why-escapes messages seen building the escape analysis tests. /* for i in escape*go ; do echo compile $i; go build -gcflags '-l -m -m' $i >& `basename $i .go`.log ; done From db3f52db8edfa51c76d1e3e1a417d46b85528132 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch Date: Sun, 2 Sep 2018 16:53:03 +0000 Subject: [PATCH 0284/1663] go/types: correct misspelling in function doc The indirectType function comment uses the phrase 'layed out'. In the context of that phrase, where something is being placed or sprawled, the word should be 'laid'. 'Layed' is a misspelling of 'laid'. Change-Id: I05ecb97637276e2252c47e92a0bd678130714889 GitHub-Last-Rev: 6ee67371b42c12ceaf4c6c245319748008ac7e7b GitHub-Pull-Request: golang/go#27444 Reviewed-on: https://go-review.googlesource.com/132779 Reviewed-by: Ian Lance Taylor --- src/go/types/typexpr.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index 2edd1f5bac31e..83848099c2c2f 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -132,7 +132,7 @@ func (check *Checker) definedType(e ast.Expr, def *Named) (T Type) { // indirectType is like typ but it also breaks the (otherwise) infinite size of recursive // types by introducing an indirection. It should be called for components of types that -// are not layed out in place in memory, such as pointer base types, slice or map element +// are not laid out in place in memory, such as pointer base types, slice or map element // types, function parameter types, etc. func (check *Checker) indirectType(e ast.Expr) Type { check.push(indir) From e2e44a5d161d5373f8124997382dd4169c1e8a00 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Mon, 3 Sep 2018 12:02:25 +0530 Subject: [PATCH 0285/1663] misc/wasm: handle error during instantiateStreaming The same catch block is there in wasm_exec.js for node processes. Added it in browser invocations too, to prevent uncaught exceptions. Change-Id: Icab577ec585fa86df3c76db508b49401bcdb52ae Reviewed-on: https://go-review.googlesource.com/132916 Reviewed-by: Richard Musiol Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- misc/wasm/wasm_exec.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/misc/wasm/wasm_exec.html b/misc/wasm/wasm_exec.html index cc37ea73ce5a7..f5e21e40f335b 100644 --- a/misc/wasm/wasm_exec.html +++ b/misc/wasm/wasm_exec.html @@ -27,6 +27,8 @@ mod = result.module; inst = result.instance; document.getElementById("runButton").disabled = false; + }).catch((err) => { + console.error(err); }); async function run() { From 2179e495cec167f42ff7d0007668d9c09ce15958 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 1 Sep 2018 10:43:22 -0700 Subject: [PATCH 0286/1663] encoding/binary: simplify Read and Write MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There's no need to manually manage the backing slice for bs. Removing it simplifies the code, removes some allocations, and speeds it up slightly. Fixes #27403 name old time/op new time/op delta ReadSlice1000Int32s-8 6.39µs ± 1% 6.31µs ± 1% -1.37% (p=0.000 n=27+27) ReadStruct-8 1.25µs ± 2% 1.23µs ± 2% -1.06% (p=0.003 n=30+29) ReadInts-8 301ns ± 0% 297ns ± 1% -1.21% (p=0.000 n=27+30) WriteInts-8 325ns ± 1% 320ns ± 1% -1.59% (p=0.000 n=26+29) WriteSlice1000Int32s-8 6.60µs ± 0% 6.52µs ± 0% -1.23% (p=0.000 n=28+27) PutUint16-8 0.72ns ± 2% 0.71ns ± 2% ~ (p=0.286 n=30+30) PutUint32-8 0.71ns ± 1% 0.71ns ± 0% -0.42% (p=0.003 n=30+25) PutUint64-8 0.78ns ± 2% 0.78ns ± 0% -0.55% (p=0.001 n=30+27) LittleEndianPutUint16-8 0.57ns ± 0% 0.57ns ± 0% ~ (all equal) LittleEndianPutUint32-8 0.57ns ± 0% 0.57ns ± 0% ~ (all equal) LittleEndianPutUint64-8 0.57ns ± 0% 0.57ns ± 0% ~ (all equal) PutUvarint32-8 23.1ns ± 1% 23.1ns ± 1% ~ (p=0.925 n=26+29) PutUvarint64-8 57.5ns ± 2% 57.3ns ± 1% ~ (p=0.338 n=30+26) [Geo mean] 23.0ns 22.9ns -0.61% name old speed new speed delta ReadSlice1000Int32s-8 626MB/s ± 1% 634MB/s ± 1% +1.38% (p=0.000 n=27+27) ReadStruct-8 60.2MB/s ± 2% 60.8MB/s ± 2% +1.08% (p=0.002 n=30+29) ReadInts-8 100MB/s ± 1% 101MB/s ± 1% +1.24% (p=0.000 n=27+30) WriteInts-8 92.2MB/s ± 1% 93.6MB/s ± 1% +1.56% (p=0.000 n=26+29) WriteSlice1000Int32s-8 606MB/s ± 0% 614MB/s ± 0% +1.24% (p=0.000 n=28+27) PutUint16-8 2.80GB/s ± 1% 2.80GB/s ± 1% ~ (p=0.095 n=28+29) PutUint32-8 5.61GB/s ± 1% 5.62GB/s ± 1% ~ (p=0.069 n=27+28) PutUint64-8 10.2GB/s ± 1% 10.2GB/s ± 0% +0.15% (p=0.039 n=27+27) LittleEndianPutUint16-8 3.50GB/s ± 1% 3.50GB/s ± 1% ~ (p=0.552 n=30+29) LittleEndianPutUint32-8 7.01GB/s ± 1% 7.02GB/s ± 1% ~ (p=0.160 n=29+27) LittleEndianPutUint64-8 14.0GB/s ± 1% 14.0GB/s ± 1% ~ (p=0.413 n=29+29) PutUvarint32-8 174MB/s ± 1% 173MB/s ± 1% ~ (p=0.648 n=25+30) PutUvarint64-8 139MB/s ± 2% 140MB/s ± 1% ~ (p=0.271 n=30+26) [Geo mean] 906MB/s 911MB/s +0.55% name old alloc/op new alloc/op delta ReadSlice1000Int32s-8 4.14kB ± 0% 4.13kB ± 0% -0.19% (p=0.000 n=30+30) ReadStruct-8 200B ± 0% 200B ± 0% ~ (all equal) ReadInts-8 64.0B ± 0% 32.0B ± 0% -50.00% (p=0.000 n=30+30) WriteInts-8 112B ± 0% 64B ± 0% -42.86% (p=0.000 n=30+30) WriteSlice1000Int32s-8 4.14kB ± 0% 4.13kB ± 0% -0.19% (p=0.000 n=30+30) PutUint16-8 0.00B 0.00B ~ (all equal) PutUint32-8 0.00B 0.00B ~ (all equal) PutUint64-8 0.00B 0.00B ~ (all equal) LittleEndianPutUint16-8 0.00B 0.00B ~ (all equal) LittleEndianPutUint32-8 0.00B 0.00B ~ (all equal) LittleEndianPutUint64-8 0.00B 0.00B ~ (all equal) PutUvarint32-8 0.00B 0.00B ~ (all equal) PutUvarint64-8 0.00B 0.00B ~ (all equal) [Geo mean] 476B 370B -22.22% name old allocs/op new allocs/op delta ReadSlice1000Int32s-8 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.000 n=30+30) ReadStruct-8 16.0 ± 0% 16.0 ± 0% ~ (all equal) ReadInts-8 8.00 ± 0% 8.00 ± 0% ~ (all equal) WriteInts-8 14.0 ± 0% 14.0 ± 0% ~ (all equal) WriteSlice1000Int32s-8 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.000 n=30+30) PutUint16-8 0.00 0.00 ~ (all equal) PutUint32-8 0.00 0.00 ~ (all equal) PutUint64-8 0.00 0.00 ~ (all equal) LittleEndianPutUint16-8 0.00 0.00 ~ (all equal) LittleEndianPutUint32-8 0.00 0.00 ~ (all equal) LittleEndianPutUint64-8 0.00 0.00 ~ (all equal) PutUvarint32-8 0.00 0.00 ~ (all equal) PutUvarint64-8 0.00 0.00 ~ (all equal) [Geo mean] 6.94 5.90 -14.97% Change-Id: I3790b93e4190d98621d5f2c47e42929a18f56c2e Reviewed-on: https://go-review.googlesource.com/133135 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/encoding/binary/binary.go | 40 ++++++++++++----------------------- 1 file changed, 14 insertions(+), 26 deletions(-) diff --git a/src/encoding/binary/binary.go b/src/encoding/binary/binary.go index 85b3bc2295dc6..8c2d1d9da4719 100644 --- a/src/encoding/binary/binary.go +++ b/src/encoding/binary/binary.go @@ -161,23 +161,17 @@ func (bigEndian) GoString() string { return "binary.BigEndian" } func Read(r io.Reader, order ByteOrder, data interface{}) error { // Fast path for basic types and slices. if n := intDataSize(data); n != 0 { - var b [8]byte - var bs []byte - if n > len(b) { - bs = make([]byte, n) - } else { - bs = b[:n] - } + bs := make([]byte, n) if _, err := io.ReadFull(r, bs); err != nil { return err } switch data := data.(type) { case *bool: - *data = b[0] != 0 + *data = bs[0] != 0 case *int8: - *data = int8(b[0]) + *data = int8(bs[0]) case *uint8: - *data = b[0] + *data = bs[0] case *int16: *data = int16(order.Uint16(bs)) case *uint16: @@ -260,25 +254,19 @@ func Read(r io.Reader, order ByteOrder, data interface{}) error { func Write(w io.Writer, order ByteOrder, data interface{}) error { // Fast path for basic types and slices. if n := intDataSize(data); n != 0 { - var b [8]byte - var bs []byte - if n > len(b) { - bs = make([]byte, n) - } else { - bs = b[:n] - } + bs := make([]byte, n) switch v := data.(type) { case *bool: if *v { - b[0] = 1 + bs[0] = 1 } else { - b[0] = 0 + bs[0] = 0 } case bool: if v { - b[0] = 1 + bs[0] = 1 } else { - b[0] = 0 + bs[0] = 0 } case []bool: for i, x := range v { @@ -289,19 +277,19 @@ func Write(w io.Writer, order ByteOrder, data interface{}) error { } } case *int8: - b[0] = byte(*v) + bs[0] = byte(*v) case int8: - b[0] = byte(v) + bs[0] = byte(v) case []int8: for i, x := range v { bs[i] = byte(x) } case *uint8: - b[0] = *v + bs[0] = *v case uint8: - b[0] = v + bs[0] = v case []uint8: - bs = v + bs = v // TODO(josharian): avoid allocating bs in this case? case *int16: order.PutUint16(bs, uint16(*v)) case int16: From 24e51bbe64b4a534b096a3b0c6bfae6a732eea59 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 16 Jun 2018 06:54:23 -0700 Subject: [PATCH 0287/1663] cmd/compile: prefer rematerializeable arg0 for HMUL This prevents accidental regalloc regressions that otherwise can occur from unrelated changes. Change-Id: Iea356fb1a24766361fce13748dc1b46e57b21cea Reviewed-on: https://go-review.googlesource.com/129375 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/gen/AMD64.rules | 7 ++ src/cmd/compile/internal/ssa/rewriteAMD64.go | 80 ++++++++++++++++++++ 2 files changed, 87 insertions(+) diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index a7474ec46586d..4c11f8d0366cb 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -2430,6 +2430,13 @@ // See issue 22947 for details (ADD(Q|L)const [off] x:(SP)) -> (LEA(Q|L) [off] x) +// HMULx is commutative, but its first argument must go in AX. +// If possible, put a rematerializeable value in the first argument slot, +// to reduce the odds that another value will be have to spilled +// specifically to free up AX. +(HMUL(Q|L) x y) && !x.rematerializeable() && y.rematerializeable() -> (HMUL(Q|L) y x) +(HMUL(Q|L)U x y) && !x.rematerializeable() && y.rematerializeable() -> (HMUL(Q|L)U y x) + // Fold loads into compares // Note: these may be undone by the flagalloc pass. (CMP(Q|L|W|B) l:(MOV(Q|L|W|B)load {sym} [off] ptr mem) x) && canMergeLoad(v, l, x) && clobber(l) -> (CMP(Q|L|W|B)load {sym} [off] ptr x mem) diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 9a443ec0c421d..1b531954dbbbc 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -173,6 +173,14 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64DIVSS_0(v) case OpAMD64DIVSSload: return rewriteValueAMD64_OpAMD64DIVSSload_0(v) + case OpAMD64HMULL: + return rewriteValueAMD64_OpAMD64HMULL_0(v) + case OpAMD64HMULLU: + return rewriteValueAMD64_OpAMD64HMULLU_0(v) + case OpAMD64HMULQ: + return rewriteValueAMD64_OpAMD64HMULQ_0(v) + case OpAMD64HMULQU: + return rewriteValueAMD64_OpAMD64HMULQU_0(v) case OpAMD64LEAL: return rewriteValueAMD64_OpAMD64LEAL_0(v) case OpAMD64LEAL1: @@ -9238,6 +9246,78 @@ func rewriteValueAMD64_OpAMD64DIVSSload_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64HMULL_0(v *Value) bool { + // match: (HMULL x y) + // cond: !x.rematerializeable() && y.rematerializeable() + // result: (HMULL y x) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(!x.rematerializeable() && y.rematerializeable()) { + break + } + v.reset(OpAMD64HMULL) + v.AddArg(y) + v.AddArg(x) + return true + } + return false +} +func rewriteValueAMD64_OpAMD64HMULLU_0(v *Value) bool { + // match: (HMULLU x y) + // cond: !x.rematerializeable() && y.rematerializeable() + // result: (HMULLU y x) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(!x.rematerializeable() && y.rematerializeable()) { + break + } + v.reset(OpAMD64HMULLU) + v.AddArg(y) + v.AddArg(x) + return true + } + return false +} +func rewriteValueAMD64_OpAMD64HMULQ_0(v *Value) bool { + // match: (HMULQ x y) + // cond: !x.rematerializeable() && y.rematerializeable() + // result: (HMULQ y x) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(!x.rematerializeable() && y.rematerializeable()) { + break + } + v.reset(OpAMD64HMULQ) + v.AddArg(y) + v.AddArg(x) + return true + } + return false +} +func rewriteValueAMD64_OpAMD64HMULQU_0(v *Value) bool { + // match: (HMULQU x y) + // cond: !x.rematerializeable() && y.rematerializeable() + // result: (HMULQU y x) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(!x.rematerializeable() && y.rematerializeable()) { + break + } + v.reset(OpAMD64HMULQU) + v.AddArg(y) + v.AddArg(x) + return true + } + return false +} func rewriteValueAMD64_OpAMD64LEAL_0(v *Value) bool { // match: (LEAL [c] {s} (ADDLconst [d] x)) // cond: is32Bit(c+d) From 669fa8f36a298cc0e2d1f817ca30c8d613ce7483 Mon Sep 17 00:00:00 2001 From: Alexey Naidonov Date: Tue, 28 Aug 2018 00:39:34 +0300 Subject: [PATCH 0288/1663] cmd/compile: remove unnecessary nil-check Removes unnecessary nil-check when referencing offset from an address. Suggested by Keith Randall in golang/go#27180. Updates golang/go#27180 Change-Id: I326ed7fda7cfa98b7e4354c811900707fee26021 Reviewed-on: https://go-review.googlesource.com/131735 Reviewed-by: Keith Randall Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/ssa/nilcheck.go | 2 +- test/nilptr3.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/ssa/nilcheck.go b/src/cmd/compile/internal/ssa/nilcheck.go index 0359e25c98735..f2e17c606b50e 100644 --- a/src/cmd/compile/internal/ssa/nilcheck.go +++ b/src/cmd/compile/internal/ssa/nilcheck.go @@ -47,7 +47,7 @@ func nilcheckelim(f *Func) { // a value resulting from taking the address of a // value, or a value constructed from an offset of a // non-nil ptr (OpAddPtr) implies it is non-nil - if v.Op == OpAddr || v.Op == OpLocalAddr || v.Op == OpAddPtr { + if v.Op == OpAddr || v.Op == OpLocalAddr || v.Op == OpAddPtr || v.Op == OpOffPtr { nonNilValues[v.ID] = true } } diff --git a/test/nilptr3.go b/test/nilptr3.go index a22e60ef11f61..6aa718e027cda 100644 --- a/test/nilptr3.go +++ b/test/nilptr3.go @@ -246,8 +246,8 @@ type TT struct { func f(t *TT) *byte { // See issue 17242. - s := &t.SS // ERROR "removed nil check" - return &s.x // ERROR "generated nil check" + s := &t.SS // ERROR "generated nil check" + return &s.x // ERROR "removed nil check" } // make sure not to do nil check for newobject From 9c833831b2bdaa465349194797cf3894cb85f9c4 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Tue, 24 Apr 2018 13:05:10 +0200 Subject: [PATCH 0289/1663] cmd/link: move dwarf part of DWARF generation before type name mangling Splits part of dwarfgeneratedebugsyms into a new function, dwarfGenerateDebugInfo which is called between deadcode elimination and type name mangling. This function takes care of collecting and processing the DIEs for all functions and package-level variables and also generates DIEs for all types used in the program. Fixes #23733 Change-Id: I75ef0608fbed2dffc3be7a477f1b03e7e740ec61 Reviewed-on: https://go-review.googlesource.com/111237 Run-TryBot: Heschi Kreinick TryBot-Result: Gobot Gobot Reviewed-by: Heschi Kreinick --- misc/cgo/testplugin/src/checkdwarf/main.go | 106 +++++++ misc/cgo/testplugin/test.bash | 4 + src/cmd/link/internal/ld/data.go | 2 +- src/cmd/link/internal/ld/dwarf.go | 320 ++++++++++----------- src/cmd/link/internal/ld/lib.go | 1 - src/cmd/link/internal/ld/link.go | 3 + src/cmd/link/internal/ld/main.go | 1 + src/cmd/link/internal/objfile/objfile.go | 2 + src/cmd/link/internal/sym/symbol.go | 1 + 9 files changed, 276 insertions(+), 164 deletions(-) create mode 100644 misc/cgo/testplugin/src/checkdwarf/main.go diff --git a/misc/cgo/testplugin/src/checkdwarf/main.go b/misc/cgo/testplugin/src/checkdwarf/main.go new file mode 100644 index 0000000000000..b689c4af15f47 --- /dev/null +++ b/misc/cgo/testplugin/src/checkdwarf/main.go @@ -0,0 +1,106 @@ +// Copyright 2018 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. + +// Usage: +// +// checkdwarf +// +// Opens , which must be an executable or a library and checks that +// there is an entry in .debug_info whose name ends in + +package main + +import ( + "debug/dwarf" + "debug/elf" + "debug/macho" + "debug/pe" + "fmt" + "os" + "strings" +) + +func usage() { + fmt.Fprintf(os.Stderr, "checkdwarf executable-or-library DIE-suffix\n") +} + +type dwarfer interface { + DWARF() (*dwarf.Data, error) +} + +func openElf(path string) dwarfer { + exe, err := elf.Open(path) + if err != nil { + return nil + } + return exe +} + +func openMacho(path string) dwarfer { + exe, err := macho.Open(path) + if err != nil { + return nil + } + return exe +} + +func openPE(path string) dwarfer { + exe, err := pe.Open(path) + if err != nil { + return nil + } + return exe +} + +func main() { + if len(os.Args) != 3 { + usage() + } + + exePath := os.Args[1] + dieSuffix := os.Args[2] + + var exe dwarfer + + for _, openfn := range []func(string) dwarfer{openMacho, openPE, openElf} { + exe = openfn(exePath) + if exe != nil { + break + } + } + + if exe == nil { + fmt.Fprintf(os.Stderr, "could not open %s", exePath) + os.Exit(1) + } + + data, err := exe.DWARF() + if err != nil { + fmt.Fprintf(os.Stderr, "error opening DWARF: %v", err) + os.Exit(1) + } + + rdr := data.Reader() + for { + e, err := rdr.Next() + if err != nil { + fmt.Fprintf(os.Stderr, "error reading DWARF: %v", err) + os.Exit(1) + } + if e == nil { + break + } + name, hasname := e.Val(dwarf.AttrName).(string) + if !hasname { + continue + } + if strings.HasSuffix(name, dieSuffix) { + // found + os.Exit(0) + } + } + + fmt.Fprintf(os.Stderr, "no entry with a name ending in %q was found", dieSuffix) + os.Exit(1) +} diff --git a/misc/cgo/testplugin/test.bash b/misc/cgo/testplugin/test.bash index bf8ed3cd191ea..5a87f5e74673d 100755 --- a/misc/cgo/testplugin/test.bash +++ b/misc/cgo/testplugin/test.bash @@ -32,6 +32,10 @@ GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o=unnamed1.so u GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o=unnamed2.so unnamed2/main.go GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" host +# test that DWARF sections are emitted for plugins and programs importing "plugin" +go run src/checkdwarf/main.go plugin2.so plugin2.UnexportedNameReuse +go run src/checkdwarf/main.go host main.main + LD_LIBRARY_PATH=$(pwd) ./host # Test that types and itabs get properly uniqified. diff --git a/src/cmd/link/internal/ld/data.go b/src/cmd/link/internal/ld/data.go index ff0d3a8d84e55..ee98aef20dc19 100644 --- a/src/cmd/link/internal/ld/data.go +++ b/src/cmd/link/internal/ld/data.go @@ -1602,7 +1602,7 @@ func (ctxt *Link) dodata() { datap = append(datap, data[symn]...) } - dwarfgeneratedebugsyms(ctxt) + dwarfGenerateDebugSyms(ctxt) var i int for ; i < len(dwarfp); i++ { diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index 4cb9295f438de..959fc8290c08d 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -21,6 +21,7 @@ import ( "cmd/link/internal/sym" "fmt" "log" + "sort" "strings" ) @@ -828,6 +829,16 @@ func synthesizechantypes(ctxt *Link, die *dwarf.DWDie) { } } +func dwarfDefineGlobal(ctxt *Link, s *sym.Symbol, str string, v int64, gotype *sym.Symbol) { + dv := newdie(ctxt, &dwglobals, dwarf.DW_ABRV_VARIABLE, str, int(s.Version)) + newabslocexprattr(dv, v, s) + if s.Version == 0 { + newattr(dv, dwarf.DW_AT_external, dwarf.DW_CLS_FLAG, 1, 0) + } + dt := defgotype(ctxt, gotype) + newrefattr(dv, dwarf.DW_AT_type, dt) +} + // For use with pass.c::genasmsym func defdwsymb(ctxt *Link, s *sym.Symbol, str string, t SymbolType, v int64, gotype *sym.Symbol) { if strings.HasPrefix(str, "go.string.") { @@ -837,32 +848,24 @@ func defdwsymb(ctxt *Link, s *sym.Symbol, str string, t SymbolType, v int64, got return } - if strings.HasPrefix(str, "type.") && str != "type.*" && !strings.HasPrefix(str, "type..") { - defgotype(ctxt, s) - return - } - - var dv *dwarf.DWDie - - var dt *sym.Symbol switch t { - default: - return - case DataSym, BSSSym: - dv = newdie(ctxt, &dwglobals, dwarf.DW_ABRV_VARIABLE, str, int(s.Version)) - newabslocexprattr(dv, v, s) - if s.Version == 0 { - newattr(dv, dwarf.DW_AT_external, dwarf.DW_CLS_FLAG, 1, 0) + switch s.Type { + case sym.SDATA, sym.SNOPTRDATA, sym.STYPE, sym.SBSS, sym.SNOPTRBSS, sym.STLSBSS: + // ok + case sym.SRODATA: + if gotype != nil { + defgotype(ctxt, gotype) + } + return + default: + return } - fallthrough - case AutoSym, ParamSym, DeletedAutoSym: - dt = defgotype(ctxt, gotype) - } + dwarfDefineGlobal(ctxt, s, str, v, gotype) - if dv != nil { - newrefattr(dv, dwarf.DW_AT_type, dt) + case AutoSym, ParamSym, DeletedAutoSym: + defgotype(ctxt, gotype) } } @@ -875,27 +878,17 @@ type compilationUnit struct { dwinfo *dwarf.DWDie // CU root DIE funcDIEs []*sym.Symbol // Function DIE subtrees absFnDIEs []*sym.Symbol // Abstract function DIE subtrees + rangeSyms []*sym.Symbol // symbols for debug_range } -// getCompilationUnits divides the symbols in ctxt.Textp by package. -func getCompilationUnits(ctxt *Link) []*compilationUnit { - units := []*compilationUnit{} - index := make(map[*sym.Library]*compilationUnit) +// calcCompUnitRanges calculates the PC ranges of the compilation units. +func calcCompUnitRanges(ctxt *Link) { var prevUnit *compilationUnit for _, s := range ctxt.Textp { if s.FuncInfo == nil { continue } - unit := index[s.Lib] - if unit == nil { - unit = &compilationUnit{lib: s.Lib} - if s := ctxt.Syms.ROLookup(dwarf.ConstInfoPrefix+s.Lib.Pkg, 0); s != nil { - importInfoSymbol(ctxt, s) - unit.consts = s - } - units = append(units, unit) - index[s.Lib] = unit - } + unit := ctxt.compUnitByPackage[s.Lib] // Update PC ranges. // @@ -910,7 +903,6 @@ func getCompilationUnits(ctxt *Link) []*compilationUnit { } unit.pcs[len(unit.pcs)-1].End = s.Value - unit.lib.Textp[0].Value + s.Size } - return units } func movetomodule(parent *dwarf.DWDie) { @@ -1064,62 +1056,13 @@ func importInfoSymbol(ctxt *Link, dsym *sym.Symbol) { for i := range dsym.R { r := &dsym.R[i] // Copying sym.Reloc has measurable impact on performance if r.Type == objabi.R_DWARFSECREF && r.Sym.Size == 0 { - if ctxt.BuildMode == BuildModeShared { - // These type symbols may not be present in BuildModeShared. Skip. - continue - } n := nameFromDIESym(r.Sym) defgotype(ctxt, ctxt.Syms.Lookup("type."+n, 0)) } } } -// For the specified function, collect symbols corresponding to any -// "abstract" subprogram DIEs referenced. The first case of interest -// is a concrete subprogram DIE, which will refer to its corresponding -// abstract subprogram DIE, and then there can be references from a -// non-abstract subprogram DIE to the abstract subprogram DIEs for any -// functions inlined into this one. -// -// A given abstract subprogram DIE can be referenced in numerous -// places (even within the same DIE), so it is important to make sure -// it gets imported and added to the absfuncs lists only once. - -func collectAbstractFunctions(ctxt *Link, fn *sym.Symbol, dsym *sym.Symbol, absfuncs []*sym.Symbol) []*sym.Symbol { - - var newabsfns []*sym.Symbol - - // Walk the relocations on the primary subprogram DIE and look for - // references to abstract funcs. - for i := range dsym.R { - reloc := &dsym.R[i] // Copying sym.Reloc has measurable impact on performance - candsym := reloc.Sym - if reloc.Type != objabi.R_DWARFSECREF { - continue - } - if !strings.HasPrefix(candsym.Name, dwarf.InfoPrefix) { - continue - } - if !strings.HasSuffix(candsym.Name, dwarf.AbstractFuncSuffix) { - continue - } - if candsym.Attr.OnList() { - continue - } - candsym.Attr |= sym.AttrOnList - newabsfns = append(newabsfns, candsym) - } - - // Import any new symbols that have turned up. - for _, absdsym := range newabsfns { - importInfoSymbol(ctxt, absdsym) - absfuncs = append(absfuncs, absdsym) - } - - return absfuncs -} - -func writelines(ctxt *Link, lib *sym.Library, textp []*sym.Symbol, ls *sym.Symbol) (dwinfo *dwarf.DWDie, funcs []*sym.Symbol, absfuncs []*sym.Symbol) { +func writelines(ctxt *Link, unit *compilationUnit, ls *sym.Symbol) (dwinfo *dwarf.DWDie) { var dwarfctxt dwarf.Context = dwctxt{ctxt} is_stmt := uint8(1) // initially = recommended default_is_stmt = 1, tracks is_stmt toggles. @@ -1130,7 +1073,7 @@ func writelines(ctxt *Link, lib *sym.Library, textp []*sym.Symbol, ls *sym.Symbo lang := dwarf.DW_LANG_Go - dwinfo = newdie(ctxt, &dwroot, dwarf.DW_ABRV_COMPUNIT, lib.Pkg, 0) + dwinfo = newdie(ctxt, &dwroot, dwarf.DW_ABRV_COMPUNIT, unit.lib.Pkg, 0) newattr(dwinfo, dwarf.DW_AT_language, dwarf.DW_CLS_CONSTANT, int64(lang), 0) newattr(dwinfo, dwarf.DW_AT_stmt_list, dwarf.DW_CLS_PTR, ls.Size, ls) // OS X linker requires compilation dir or absolute path in comp unit name to output debug info. @@ -1139,7 +1082,7 @@ func writelines(ctxt *Link, lib *sym.Library, textp []*sym.Symbol, ls *sym.Symbo // the linker directory. If we move CU construction into the // compiler, this should happen naturally. newattr(dwinfo, dwarf.DW_AT_comp_dir, dwarf.DW_CLS_STRING, int64(len(compDir)), compDir) - producerExtra := ctxt.Syms.Lookup(dwarf.CUInfoPrefix+"producer."+lib.Pkg, 0) + producerExtra := ctxt.Syms.Lookup(dwarf.CUInfoPrefix+"producer."+unit.lib.Pkg, 0) producer := "Go cmd/compile " + objabi.Version if len(producerExtra.P) > 0 { // We put a semicolon before the flags to clearly @@ -1183,7 +1126,8 @@ func writelines(ctxt *Link, lib *sym.Library, textp []*sym.Symbol, ls *sym.Symbo // Create the file table. fileNums maps from global file // indexes (created by numberfile) to CU-local indexes. fileNums := make(map[int]int) - for _, s := range textp { // textp has been dead-code-eliminated already. + for _, s := range unit.lib.Textp { // textp has been dead-code-eliminated already. + dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version)) for _, f := range s.FuncInfo.File { if _, ok := fileNums[int(f.Value)]; ok { continue @@ -1195,26 +1139,21 @@ func writelines(ctxt *Link, lib *sym.Library, textp []*sym.Symbol, ls *sym.Symbo ls.AddUint8(0) ls.AddUint8(0) } - - // Look up the .debug_info sym for the function. We do this - // now so that we can walk the sym's relocations to discover - // files that aren't mentioned in S.FuncInfo.File (for - // example, files mentioned only in an inlined subroutine). - dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version)) - importInfoSymbol(ctxt, dsym) - for ri := range dsym.R { + for ri := 0; ri < len(dsym.R); ri++ { r := &dsym.R[ri] if r.Type != objabi.R_DWARFFILEREF { continue } - _, ok := fileNums[int(r.Sym.Value)] - if !ok { - fileNums[int(r.Sym.Value)] = len(fileNums) + 1 - Addstring(ls, r.Sym.Name) - ls.AddUint8(0) - ls.AddUint8(0) - ls.AddUint8(0) + // A file that is only mentioned in an inlined subroutine will appear + // as a R_DWARFFILEREF but not in s.FuncInfo.File + if _, ok := fileNums[int(r.Sym.Value)]; ok { + continue } + fileNums[int(r.Sym.Value)] = len(fileNums) + 1 + Addstring(ls, r.Sym.Name) + ls.AddUint8(0) + ls.AddUint8(0) + ls.AddUint8(0) } } @@ -1227,7 +1166,7 @@ func writelines(ctxt *Link, lib *sym.Library, textp []*sym.Symbol, ls *sym.Symbo dwarf.Uleb128put(dwarfctxt, ls, 1+int64(ctxt.Arch.PtrSize)) ls.AddUint8(dwarf.DW_LNE_set_address) - s := textp[0] + s := unit.lib.Textp[0] pc := s.Value line := 1 file := 1 @@ -1236,19 +1175,12 @@ func writelines(ctxt *Link, lib *sym.Library, textp []*sym.Symbol, ls *sym.Symbo var pcfile Pciter var pcline Pciter var pcstmt Pciter - for i, s := range textp { - dsym := ctxt.Syms.Lookup(dwarf.InfoPrefix+s.Name, int(s.Version)) - funcs = append(funcs, dsym) - absfuncs = collectAbstractFunctions(ctxt, s, dsym, absfuncs) - + for i, s := range unit.lib.Textp { finddebugruntimepath(s) - isStmtsSym := ctxt.Syms.ROLookup(dwarf.IsStmtPrefix+s.Name, int(s.Version)) - pctostmtData := sym.Pcdata{P: isStmtsSym.P} - pciterinit(ctxt, &pcfile, &s.FuncInfo.Pcfile) pciterinit(ctxt, &pcline, &s.FuncInfo.Pcline) - pciterinit(ctxt, &pcstmt, &pctostmtData) + pciterinit(ctxt, &pcstmt, &sym.Pcdata{P: s.FuncInfo.IsStmtSym.P}) if pcstmt.done != 0 { // Assembly files lack a pcstmt section, we assume that every instruction @@ -1312,7 +1244,7 @@ func writelines(ctxt *Link, lib *sym.Library, textp []*sym.Symbol, ls *sym.Symbo pciternext(&pcline) } } - if is_stmt == 0 && i < len(textp)-1 { + if is_stmt == 0 && i < len(unit.lib.Textp)-1 { // If there is more than one function, ensure default value is established. is_stmt = 1 ls.AddUint8(uint8(dwarf.DW_LNS_negate_stmt)) @@ -1333,7 +1265,7 @@ func writelines(ctxt *Link, lib *sym.Library, textp []*sym.Symbol, ls *sym.Symbo // DIE flavors (ex: variables) then those DIEs would need to // be included below. missing := make(map[int]interface{}) - for _, f := range funcs { + for _, f := range unit.funcDIEs { for ri := range f.R { r := &f.R[ri] if r.Type != objabi.R_DWARFFILEREF { @@ -1364,7 +1296,7 @@ func writelines(ctxt *Link, lib *sym.Library, textp []*sym.Symbol, ls *sym.Symbo } } - return dwinfo, funcs, absfuncs + return dwinfo } // writepcranges generates the DW_AT_ranges table for compilation unit cu. @@ -1516,24 +1448,6 @@ func writeframes(ctxt *Link, syms []*sym.Symbol) []*sym.Symbol { return syms } -func writeranges(ctxt *Link, syms []*sym.Symbol) []*sym.Symbol { - for _, s := range ctxt.Textp { - rangeSym := ctxt.Syms.ROLookup(dwarf.RangePrefix+s.Name, int(s.Version)) - if rangeSym == nil || rangeSym.Size == 0 { - continue - } - rangeSym.Attr |= sym.AttrReachable | sym.AttrNotInSymbolTable - rangeSym.Type = sym.SDWARFRANGE - // LLVM doesn't support base address entries. Strip them out so LLDB and dsymutil don't get confused. - if ctxt.HeadType == objabi.Hdarwin { - fn := ctxt.Syms.ROLookup(dwarf.InfoPrefix+s.Name, int(s.Version)) - removeDwarfAddrListBaseAddress(ctxt, fn, rangeSym, false) - } - syms = append(syms, rangeSym) - } - return syms -} - /* * Walk DWarfDebugInfoEntries, and emit .debug_info */ @@ -1672,24 +1586,15 @@ func writegdbscript(ctxt *Link, syms []*sym.Symbol) []*sym.Symbol { var prototypedies map[string]*dwarf.DWDie -/* - * This is the main entry point for generating dwarf. After emitting - * the mandatory debug_abbrev section, it calls writelines() to set up - * the per-compilation unit part of the DIE tree, while simultaneously - * emitting the debug_line section. When the final tree contains - * forward references, it will write the debug_info section in 2 - * passes. - * - */ -func dwarfgeneratedebugsyms(ctxt *Link) { +func dwarfEnabled(ctxt *Link) bool { if *FlagW { // disable dwarf - return + return false } if *FlagS && ctxt.HeadType != objabi.Hdarwin { - return + return false } if ctxt.HeadType == objabi.Hplan9 || ctxt.HeadType == objabi.Hjs { - return + return false } if ctxt.LinkMode == LinkExternal { @@ -1698,14 +1603,27 @@ func dwarfgeneratedebugsyms(ctxt *Link) { case ctxt.HeadType == objabi.Hdarwin: case ctxt.HeadType == objabi.Hwindows: default: - return + return false } } - if ctxt.Debugvlog != 0 { - ctxt.Logf("%5.2f dwarf\n", Cputime()) + return true +} + +// dwarfGenerateDebugInfo generated debug info entries for all types, +// variables and functions in the program. +// Along with dwarfGenerateDebugSyms they are the two main entry points into +// dwarf generation: dwarfGenerateDebugInfo does all the work that should be +// done before symbol names are mangled while dwarfgeneratedebugsyms does +// all the work that can only be done after addresses have been assigned to +// text symbols. +func dwarfGenerateDebugInfo(ctxt *Link) { + if !dwarfEnabled(ctxt) { + return } + ctxt.compUnitByPackage = make(map[*sym.Library]*compilationUnit) + // Forctxt.Diagnostic messages. newattr(&dwtypes, dwarf.DW_AT_name, dwarf.DW_CLS_STRING, int64(len("dwtypes")), "dwtypes") @@ -1748,12 +1666,84 @@ func dwarfgeneratedebugsyms(ctxt *Link) { defgotype(ctxt, lookupOrDiag(ctxt, typ)) } + // Create DIEs for global variables and the types they use. genasmsym(ctxt, defdwsymb) + for _, lib := range ctxt.Library { + if len(lib.Textp) == 0 { + continue + } + unit := &compilationUnit{lib: lib} + if s := ctxt.Syms.ROLookup(dwarf.ConstInfoPrefix+lib.Pkg, 0); s != nil { + importInfoSymbol(ctxt, s) + unit.consts = s + } + ctxt.compUnits = append(ctxt.compUnits, unit) + ctxt.compUnitByPackage[lib] = unit + + // Scan all functions in this compilation unit, create DIEs for all + // referenced types, create the file table for debug_line, find all + // referenced abstract functions. + // Collect all debug_range symbols in unit.rangeSyms + for _, s := range lib.Textp { // textp has been dead-code-eliminated already. + dsym := ctxt.Syms.ROLookup(dwarf.InfoPrefix+s.Name, int(s.Version)) + dsym.Attr |= sym.AttrNotInSymbolTable | sym.AttrReachable + dsym.Type = sym.SDWARFINFO + unit.funcDIEs = append(unit.funcDIEs, dsym) + + rangeSym := ctxt.Syms.ROLookup(dwarf.RangePrefix+s.Name, int(s.Version)) + if rangeSym != nil && rangeSym.Size > 0 { + rangeSym.Attr |= sym.AttrReachable | sym.AttrNotInSymbolTable + rangeSym.Type = sym.SDWARFRANGE + // LLVM doesn't support base address entries. Strip them out so LLDB and dsymutil don't get confused. + if ctxt.HeadType == objabi.Hdarwin { + removeDwarfAddrListBaseAddress(ctxt, dsym, rangeSym, false) + } + unit.rangeSyms = append(unit.rangeSyms, rangeSym) + } + + for ri := 0; ri < len(dsym.R); ri++ { + r := &dsym.R[ri] + if r.Type == objabi.R_DWARFSECREF { + rsym := r.Sym + if strings.HasPrefix(rsym.Name, dwarf.InfoPrefix) && strings.HasSuffix(rsym.Name, dwarf.AbstractFuncSuffix) && !rsym.Attr.OnList() { + // abstract function + rsym.Attr |= sym.AttrOnList + unit.absFnDIEs = append(unit.absFnDIEs, rsym) + importInfoSymbol(ctxt, rsym) + } else if rsym.Size == 0 { + // a type we do not have a DIE for + n := nameFromDIESym(rsym) + defgotype(ctxt, ctxt.Syms.Lookup("type."+n, 0)) + } + } + } + } + } + + synthesizestringtypes(ctxt, dwtypes.Child) + synthesizeslicetypes(ctxt, dwtypes.Child) + synthesizemaptypes(ctxt, dwtypes.Child) + synthesizechantypes(ctxt, dwtypes.Child) +} + +// dwarfGenerateDebugSyms constructs debug_line, debug_frame, debug_loc, +// debug_pubnames and debug_pubtypes. It also writes out the debug_info +// section using symbols generated in dwarfGenerateDebugInfo. +func dwarfGenerateDebugSyms(ctxt *Link) { + if !dwarfEnabled(ctxt) { + return + } + + if ctxt.Debugvlog != 0 { + ctxt.Logf("%5.2f dwarf\n", Cputime()) + } + abbrev := writeabbrev(ctxt) syms := []*sym.Symbol{abbrev} - units := getCompilationUnits(ctxt) + calcCompUnitRanges(ctxt) + sort.Sort(compilationUnitByStartPC(ctxt.compUnits)) // Write per-package line and range tables and start their CU DIEs. debugLine := ctxt.Syms.Lookup(".debug_line", 0) @@ -1762,16 +1752,11 @@ func dwarfgeneratedebugsyms(ctxt *Link) { debugRanges.Type = sym.SDWARFRANGE debugRanges.Attr |= sym.AttrReachable syms = append(syms, debugLine) - for _, u := range units { - u.dwinfo, u.funcDIEs, u.absFnDIEs = writelines(ctxt, u.lib, u.lib.Textp, debugLine) + for _, u := range ctxt.compUnits { + u.dwinfo = writelines(ctxt, u, debugLine) writepcranges(ctxt, u.dwinfo, u.lib.Textp[0], u.pcs, debugRanges) } - synthesizestringtypes(ctxt, dwtypes.Child) - synthesizeslicetypes(ctxt, dwtypes.Child) - synthesizemaptypes(ctxt, dwtypes.Child) - synthesizechantypes(ctxt, dwtypes.Child) - // newdie adds DIEs to the *beginning* of the parent's DIE list. // Now that we're done creating DIEs, reverse the trees so DIEs // appear in the order they were created. @@ -1784,7 +1769,7 @@ func dwarfgeneratedebugsyms(ctxt *Link) { // Need to reorder symbols so sym.SDWARFINFO is after all sym.SDWARFSECT // (but we need to generate dies before writepub) - infosyms := writeinfo(ctxt, nil, units, abbrev) + infosyms := writeinfo(ctxt, nil, ctxt.compUnits, abbrev) syms = writeframes(ctxt, syms) syms = writepub(ctxt, ".debug_pubnames", ispubname, syms) @@ -1793,9 +1778,11 @@ func dwarfgeneratedebugsyms(ctxt *Link) { // Now we're done writing SDWARFSECT symbols, so we can write // other SDWARF* symbols. syms = append(syms, infosyms...) - syms = collectlocs(ctxt, syms, units) + syms = collectlocs(ctxt, syms, ctxt.compUnits) syms = append(syms, debugRanges) - syms = writeranges(ctxt, syms) + for _, unit := range ctxt.compUnits { + syms = append(syms, unit.rangeSyms...) + } dwarfp = syms } @@ -2006,3 +1993,12 @@ func dwarfcompress(ctxt *Link) { } Segdwarf.Length = pos - Segdwarf.Vaddr } + +type compilationUnitByStartPC []*compilationUnit + +func (v compilationUnitByStartPC) Len() int { return len(v) } +func (v compilationUnitByStartPC) Swap(i, j int) { v[i], v[j] = v[j], v[i] } + +func (v compilationUnitByStartPC) Less(i, j int) bool { + return v[i].lib.Textp[0].Value < v[j].lib.Textp[0].Value +} diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 331b6ca6145ed..5e99149d2549c 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -654,7 +654,6 @@ func (ctxt *Link) mangleTypeSym() { return } - *FlagW = true // disable DWARF generation for _, s := range ctxt.Syms.Allsym { newName := typeSymbolMangle(s.Name) if newName != s.Name { diff --git a/src/cmd/link/internal/ld/link.go b/src/cmd/link/internal/ld/link.go index bf5754435786f..48b92724b6fe0 100644 --- a/src/cmd/link/internal/ld/link.go +++ b/src/cmd/link/internal/ld/link.go @@ -89,6 +89,9 @@ type Link struct { // Used to implement field tracking. Reachparent map[*sym.Symbol]*sym.Symbol + + compUnits []*compilationUnit // DWARF compilation units + compUnitByPackage map[*sym.Library]*compilationUnit } type unresolvedSymKey struct { diff --git a/src/cmd/link/internal/ld/main.go b/src/cmd/link/internal/ld/main.go index 0c5ac470438ad..905380a1dbfda 100644 --- a/src/cmd/link/internal/ld/main.go +++ b/src/cmd/link/internal/ld/main.go @@ -208,6 +208,7 @@ func Main(arch *sys.Arch, theArch Arch) { ctxt.dostrdata() deadcode(ctxt) + dwarfGenerateDebugInfo(ctxt) if objabi.Fieldtrack_enabled != 0 { fieldtrack(ctxt) } diff --git a/src/cmd/link/internal/objfile/objfile.go b/src/cmd/link/internal/objfile/objfile.go index 67868be2a1926..e3800de30413b 100644 --- a/src/cmd/link/internal/objfile/objfile.go +++ b/src/cmd/link/internal/objfile/objfile.go @@ -318,6 +318,8 @@ overwrite: pc.InlTree[i].Func = r.readSymIndex() } + s.FuncInfo.IsStmtSym = r.syms.Lookup(dwarf.IsStmtPrefix+s.Name, int(s.Version)) + s.Lib = r.lib if !dupok { if s.Attr.OnList() { diff --git a/src/cmd/link/internal/sym/symbol.go b/src/cmd/link/internal/sym/symbol.go index 95ad8654b5cef..a6c2aaea778f5 100644 --- a/src/cmd/link/internal/sym/symbol.go +++ b/src/cmd/link/internal/sym/symbol.go @@ -478,6 +478,7 @@ type FuncInfo struct { Pcline Pcdata Pcinline Pcdata Pcdata []Pcdata + IsStmtSym *Symbol Funcdata []*Symbol Funcdataoff []int64 File []*Symbol From f7a633aa790c413fc460cdc0901c9ae429cf1175 Mon Sep 17 00:00:00 2001 From: Matthew Dempsky Date: Fri, 24 Aug 2018 12:37:25 -0700 Subject: [PATCH 0290/1663] cmd/compile: use "N variables but M values" error for OAS Makes the error message more consistent between OAS and OAS2. Fixes #26616. Change-Id: I07ab46c5ef8a37efb2cb557632697f5d1bf789f7 Reviewed-on: https://go-review.googlesource.com/131280 Run-TryBot: Matthew Dempsky TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/gc/typecheck.go | 11 +++++++++-- test/fixedbugs/issue26616.go | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/fixedbugs/issue26616.go diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 370f21befbdb6..cc98c3ae69e6c 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -3333,10 +3333,17 @@ func typecheckas(n *Node) { n.Left = typecheck(n.Left, Erv|Easgn) } - n.Right = typecheck(n.Right, Erv) + // Use Efnstruct so we can emit an "N variables but M values" error + // to be consistent with typecheckas2 (#26616). + n.Right = typecheck(n.Right, Erv|Efnstruct) checkassign(n, n.Left) if n.Right != nil && n.Right.Type != nil { - if n.Left.Type != nil { + if n.Right.Type.IsFuncArgStruct() { + yyerror("assignment mismatch: 1 variable but %d values", n.Right.Type.NumFields()) + // Multi-value RHS isn't actually valid for OAS; nil out + // to indicate failed typechecking. + n.Right.Type = nil + } else if n.Left.Type != nil { n.Right = assignconv(n.Right, n.Left.Type, "assignment") } } diff --git a/test/fixedbugs/issue26616.go b/test/fixedbugs/issue26616.go new file mode 100644 index 0000000000000..46136dc68f532 --- /dev/null +++ b/test/fixedbugs/issue26616.go @@ -0,0 +1,20 @@ +// errorcheck + +// Copyright 2018 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. + +package p + +var x int = three() // ERROR "1 variable but 3 values" + +func f() { + var _ int = three() // ERROR "1 variable but 3 values" + var a int = three() // ERROR "1 variable but 3 values" + a = three() // ERROR "1 variable but 3 values" + b := three() // ERROR "1 variable but 3 values" + + _, _ = a, b +} + +func three() (int, int, int) From 55ef446026748bea0e9bd5aa35132a07297ff734 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Tue, 28 Aug 2018 13:10:31 +0530 Subject: [PATCH 0291/1663] cmd/go/internal/modcmd: remove non-existent -dir flag Fixes #27243 Change-Id: If9230244938dabd03b9afaa6600310df8f97fe92 Reviewed-on: https://go-review.googlesource.com/131775 Reviewed-by: Bryan C. Mills --- src/cmd/go/alldocs.go | 2 +- src/cmd/go/internal/modcmd/download.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index ebbd154f3e6ff..35cabcac14373 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -889,7 +889,7 @@ // // Usage: // -// go mod download [-dir] [-json] [modules] +// go mod download [-json] [modules] // // Download downloads the named modules, which can be module patterns selecting // dependencies of the main module or module queries of the form path@version. diff --git a/src/cmd/go/internal/modcmd/download.go b/src/cmd/go/internal/modcmd/download.go index cf42eff58a1f3..8678caea51673 100644 --- a/src/cmd/go/internal/modcmd/download.go +++ b/src/cmd/go/internal/modcmd/download.go @@ -15,7 +15,7 @@ import ( ) var cmdDownload = &base.Command{ - UsageLine: "go mod download [-dir] [-json] [modules]", + UsageLine: "go mod download [-json] [modules]", Short: "download modules to local cache", Long: ` Download downloads the named modules, which can be module patterns selecting From 1018a80fe85746aa440001d5a514ad2ff8abf0d1 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 30 Aug 2018 07:01:10 +0000 Subject: [PATCH 0292/1663] cmd/internal/obj/arm64: support more atomic instructions LDADDALD(64-bit) and LDADDALW(32-bit) are already supported. This CL adds supports of LDADDALH(16-bit) and LDADDALB(8-bit). Change-Id: I4eac61adcec226d618dfce88618a2b98f5f1afe7 Reviewed-on: https://go-review.googlesource.com/132135 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/asm/internal/arch/arm64.go | 2 +- src/cmd/asm/internal/asm/testdata/arm64.s | 4 +++- src/cmd/internal/obj/arm64/a.out.go | 4 +++- src/cmd/internal/obj/arm64/anames.go | 4 +++- src/cmd/internal/obj/arm64/asm7.go | 14 ++++++++------ 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/cmd/asm/internal/arch/arm64.go b/src/cmd/asm/internal/arch/arm64.go index 7cbc139bced42..98858bd181bda 100644 --- a/src/cmd/asm/internal/arch/arm64.go +++ b/src/cmd/asm/internal/arch/arm64.go @@ -79,7 +79,7 @@ func IsARM64STLXR(op obj.As) bool { arm64.ALDANDB, arm64.ALDANDH, arm64.ALDANDW, arm64.ALDANDD, arm64.ALDEORB, arm64.ALDEORH, arm64.ALDEORW, arm64.ALDEORD, arm64.ALDORB, arm64.ALDORH, arm64.ALDORW, arm64.ALDORD, - arm64.ALDADDALD, arm64.ALDADDALW: + arm64.ALDADDALD, arm64.ALDADDALW, arm64.ALDADDALH, arm64.ALDADDALB: return true } return false diff --git a/src/cmd/asm/internal/asm/testdata/arm64.s b/src/cmd/asm/internal/asm/testdata/arm64.s index 2d55b4b2ad123..feb507db8637a 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64.s +++ b/src/cmd/asm/internal/asm/testdata/arm64.s @@ -622,7 +622,9 @@ again: LDORB R5, (R6), R7 // c7302538 LDORB R5, (RSP), R7 // e7332538 LDADDALD R2, (R1), R3 // 2300e2f8 - LDADDALW R5, (R4), R6 // 8600e5b8 + LDADDALW R2, (R1), R3 // 2300e2b8 + LDADDALH R2, (R1), R3 // 2300e278 + LDADDALB R2, (R1), R3 // 2300e238 // RET // diff --git a/src/cmd/internal/obj/arm64/a.out.go b/src/cmd/internal/obj/arm64/a.out.go index a32f973fa22c4..65647c37ae70e 100644 --- a/src/cmd/internal/obj/arm64/a.out.go +++ b/src/cmd/internal/obj/arm64/a.out.go @@ -594,8 +594,10 @@ const ( AHVC AIC AISB - ALDADDALD + ALDADDALB + ALDADDALH ALDADDALW + ALDADDALD ALDADDB ALDADDH ALDADDW diff --git a/src/cmd/internal/obj/arm64/anames.go b/src/cmd/internal/obj/arm64/anames.go index d9783caff9612..55e2b5bafbb1a 100644 --- a/src/cmd/internal/obj/arm64/anames.go +++ b/src/cmd/internal/obj/arm64/anames.go @@ -95,8 +95,10 @@ var Anames = []string{ "HVC", "IC", "ISB", - "LDADDALD", + "LDADDALB", + "LDADDALH", "LDADDALW", + "LDADDALD", "LDADDB", "LDADDH", "LDADDW", diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index 2abb8c2c773d9..00232ccd55588 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -779,7 +779,7 @@ func span7(ctxt *obj.Link, cursym *obj.LSym, newprog obj.ProgAlloc) { } c := ctxt7{ctxt: ctxt, newprog: newprog, cursym: cursym, autosize: int32(p.To.Offset & 0xffffffff), extrasize: int32(p.To.Offset >> 32)} - p.To.Offset &= 0xffffffff // extrasize is no longer needed + p.To.Offset &= 0xffffffff // extrasize is no longer needed bflag := 1 pc := int64(0) @@ -2023,8 +2023,10 @@ func buildop(ctxt *obj.Link) { oprangeset(ASWPALB, t) oprangeset(ASWPALH, t) oprangeset(ASWPALW, t) - oprangeset(ALDADDALD, t) + oprangeset(ALDADDALB, t) + oprangeset(ALDADDALH, t) oprangeset(ALDADDALW, t) + oprangeset(ALDADDALD, t) oprangeset(ALDADDB, t) oprangeset(ALDADDH, t) oprangeset(ALDADDW, t) @@ -3406,9 +3408,9 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { o1 = 3 << 30 case ASWPW, ASWPALW, ALDADDALW, ALDADDW, ALDANDW, ALDEORW, ALDORW: // 32-bit o1 = 2 << 30 - case ASWPH, ASWPALH, ALDADDH, ALDANDH, ALDEORH, ALDORH: // 16-bit + case ASWPH, ASWPALH, ALDADDALH, ALDADDH, ALDANDH, ALDEORH, ALDORH: // 16-bit o1 = 1 << 30 - case ASWPB, ASWPALB, ALDADDB, ALDANDB, ALDEORB, ALDORB: // 8-bit + case ASWPB, ASWPALB, ALDADDALB, ALDADDB, ALDANDB, ALDEORB, ALDORB: // 8-bit o1 = 0 << 30 default: c.ctxt.Diag("illegal instruction: %v\n", p) @@ -3416,7 +3418,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { switch p.As { case ASWPD, ASWPW, ASWPH, ASWPB, ASWPALD, ASWPALW, ASWPALH, ASWPALB: o1 |= 0x20 << 10 - case ALDADDALD, ALDADDALW, ALDADDD, ALDADDW, ALDADDH, ALDADDB: + case ALDADDALD, ALDADDALW, ALDADDALH, ALDADDALB, ALDADDD, ALDADDW, ALDADDH, ALDADDB: o1 |= 0x00 << 10 case ALDANDD, ALDANDW, ALDANDH, ALDANDB: o1 |= 0x04 << 10 @@ -3426,7 +3428,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { o1 |= 0x0c << 10 } switch p.As { - case ALDADDALD, ALDADDALW, ASWPALD, ASWPALW, ASWPALH, ASWPALB: + case ALDADDALD, ALDADDALW, ALDADDALH, ALDADDALB, ASWPALD, ASWPALW, ASWPALH, ASWPALB: o1 |= 3 << 22 } o1 |= 0x1c1<<21 | uint32(rs&31)<<16 | uint32(rb&31)<<5 | uint32(rt&31) From b444215116e8d4a63f70f1a1b5a31f60a41a7f75 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Mon, 13 Aug 2018 10:38:25 +0000 Subject: [PATCH 0293/1663] cmd/compile: optimize ARM64's code with MADD/MSUB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MADD does MUL-ADD in a single instruction, and MSUB does the similiar simplification for MUL-SUB. The CL implements the optimization with MADD/MSUB. 1. The total size of pkg/android_arm64/ decreases about 20KB, excluding cmd/compile/. 2. The go1 benchmark shows a little improvement for RegexpMatchHard_32-4 and Template-4, excluding noise. name old time/op new time/op delta BinaryTree17-4 16.3s ± 1% 16.5s ± 1% +1.41% (p=0.000 n=26+28) Fannkuch11-4 8.79s ± 1% 8.76s ± 0% -0.36% (p=0.000 n=26+28) FmtFprintfEmpty-4 172ns ± 0% 172ns ± 0% ~ (all equal) FmtFprintfString-4 362ns ± 1% 364ns ± 0% +0.55% (p=0.000 n=30+30) FmtFprintfInt-4 416ns ± 0% 416ns ± 0% ~ (p=0.099 n=22+30) FmtFprintfIntInt-4 655ns ± 1% 660ns ± 1% +0.76% (p=0.000 n=30+30) FmtFprintfPrefixedInt-4 810ns ± 0% 809ns ± 0% -0.08% (p=0.009 n=29+29) FmtFprintfFloat-4 1.08µs ± 0% 1.09µs ± 0% +0.61% (p=0.000 n=30+29) FmtManyArgs-4 2.70µs ± 0% 2.69µs ± 0% -0.23% (p=0.000 n=29+28) GobDecode-4 32.2ms ± 1% 32.1ms ± 1% -0.39% (p=0.000 n=27+26) GobEncode-4 27.4ms ± 2% 27.4ms ± 1% ~ (p=0.864 n=28+28) Gzip-4 1.53s ± 1% 1.52s ± 1% -0.30% (p=0.031 n=29+29) Gunzip-4 146ms ± 0% 146ms ± 0% -0.14% (p=0.001 n=25+30) HTTPClientServer-4 1.00ms ± 4% 0.98ms ± 6% -1.65% (p=0.001 n=29+30) JSONEncode-4 67.3ms ± 1% 67.2ms ± 1% ~ (p=0.520 n=28+28) JSONDecode-4 329ms ± 5% 330ms ± 4% ~ (p=0.142 n=30+30) Mandelbrot200-4 17.3ms ± 0% 17.3ms ± 0% ~ (p=0.055 n=26+29) GoParse-4 16.9ms ± 1% 17.0ms ± 1% +0.82% (p=0.000 n=30+30) RegexpMatchEasy0_32-4 382ns ± 0% 382ns ± 0% ~ (all equal) RegexpMatchEasy0_1K-4 1.33µs ± 0% 1.33µs ± 0% -0.25% (p=0.000 n=30+27) RegexpMatchEasy1_32-4 361ns ± 0% 361ns ± 0% -0.08% (p=0.002 n=30+28) RegexpMatchEasy1_1K-4 2.11µs ± 0% 2.09µs ± 0% -0.54% (p=0.000 n=30+29) RegexpMatchMedium_32-4 594ns ± 0% 592ns ± 0% -0.32% (p=0.000 n=30+30) RegexpMatchMedium_1K-4 173µs ± 0% 172µs ± 0% -0.77% (p=0.000 n=29+27) RegexpMatchHard_32-4 10.4µs ± 0% 10.1µs ± 0% -3.63% (p=0.000 n=28+27) RegexpMatchHard_1K-4 306µs ± 0% 301µs ± 0% -1.64% (p=0.000 n=29+30) Revcomp-4 2.51s ± 1% 2.52s ± 0% +0.18% (p=0.017 n=26+27) Template-4 394ms ± 3% 382ms ± 3% -3.22% (p=0.000 n=28+28) TimeParse-4 1.67µs ± 0% 1.67µs ± 0% +0.05% (p=0.030 n=27+30) TimeFormat-4 1.72µs ± 0% 1.70µs ± 0% -0.79% (p=0.000 n=28+26) [Geo mean] 259µs 259µs -0.33% name old speed new speed delta GobDecode-4 23.8MB/s ± 1% 23.9MB/s ± 1% +0.40% (p=0.001 n=27+26) GobEncode-4 28.0MB/s ± 2% 28.0MB/s ± 1% ~ (p=0.863 n=28+28) Gzip-4 12.7MB/s ± 1% 12.7MB/s ± 1% +0.32% (p=0.026 n=29+29) Gunzip-4 133MB/s ± 0% 133MB/s ± 0% +0.15% (p=0.001 n=24+30) JSONEncode-4 28.8MB/s ± 1% 28.9MB/s ± 1% ~ (p=0.475 n=28+28) JSONDecode-4 5.89MB/s ± 4% 5.87MB/s ± 5% ~ (p=0.174 n=29+30) GoParse-4 3.43MB/s ± 0% 3.40MB/s ± 1% -0.83% (p=0.000 n=28+30) RegexpMatchEasy0_32-4 83.6MB/s ± 0% 83.6MB/s ± 0% ~ (p=0.848 n=28+29) RegexpMatchEasy0_1K-4 768MB/s ± 0% 770MB/s ± 0% +0.25% (p=0.000 n=30+27) RegexpMatchEasy1_32-4 88.5MB/s ± 0% 88.5MB/s ± 0% ~ (p=0.086 n=29+29) RegexpMatchEasy1_1K-4 486MB/s ± 0% 489MB/s ± 0% +0.54% (p=0.000 n=30+29) RegexpMatchMedium_32-4 1.68MB/s ± 0% 1.69MB/s ± 0% +0.60% (p=0.000 n=30+23) RegexpMatchMedium_1K-4 5.90MB/s ± 0% 5.95MB/s ± 0% +0.85% (p=0.000 n=18+20) RegexpMatchHard_32-4 3.07MB/s ± 0% 3.18MB/s ± 0% +3.72% (p=0.000 n=29+26) RegexpMatchHard_1K-4 3.35MB/s ± 0% 3.40MB/s ± 0% +1.69% (p=0.000 n=30+30) Revcomp-4 101MB/s ± 0% 101MB/s ± 0% -0.18% (p=0.018 n=26+27) Template-4 4.92MB/s ± 4% 5.09MB/s ± 3% +3.31% (p=0.000 n=28+28) [Geo mean] 22.4MB/s 22.6MB/s +0.62% Change-Id: I8f304b272785739f57b3c8f736316f658f8c1b2a Reviewed-on: https://go-review.googlesource.com/129119 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/arm64/ssa.go | 6 +- src/cmd/compile/internal/ssa/gen/ARM64.rules | 39 + src/cmd/compile/internal/ssa/gen/ARM64Ops.go | 5 + src/cmd/compile/internal/ssa/opGen.go | 64 ++ src/cmd/compile/internal/ssa/rewriteARM64.go | 1066 +++++++++++++++++- test/codegen/arithmetic.go | 6 + 6 files changed, 1183 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/arm64/ssa.go b/src/cmd/compile/internal/arm64/ssa.go index 3712a73eb5f4e..db7064cff0e1b 100644 --- a/src/cmd/compile/internal/arm64/ssa.go +++ b/src/cmd/compile/internal/arm64/ssa.go @@ -212,7 +212,11 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ssa.OpARM64FMSUBS, ssa.OpARM64FMSUBD, ssa.OpARM64FNMSUBS, - ssa.OpARM64FNMSUBD: + ssa.OpARM64FNMSUBD, + ssa.OpARM64MADD, + ssa.OpARM64MADDW, + ssa.OpARM64MSUB, + ssa.OpARM64MSUBW: rt := v.Reg() ra := v.Args[0].Reg() rm := v.Args[1].Reg() diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index d20780681920b..374ece24e581d 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -594,6 +594,34 @@ (EQ (CMPWconst [0] x) yes no) -> (ZW x yes no) (NE (CMPWconst [0] x) yes no) -> (NZW x yes no) +(EQ (CMPconst [0] z:(MADD a x y)) yes no) && z.Uses==1 -> (EQ (CMN a (MUL x y)) yes no) +(NE (CMPconst [0] z:(MADD a x y)) yes no) && z.Uses==1 -> (NE (CMN a (MUL x y)) yes no) +(LT (CMPconst [0] z:(MADD a x y)) yes no) && z.Uses==1 -> (LT (CMN a (MUL x y)) yes no) +(LE (CMPconst [0] z:(MADD a x y)) yes no) && z.Uses==1 -> (LE (CMN a (MUL x y)) yes no) +(GT (CMPconst [0] z:(MADD a x y)) yes no) && z.Uses==1 -> (GT (CMN a (MUL x y)) yes no) +(GE (CMPconst [0] z:(MADD a x y)) yes no) && z.Uses==1 -> (GE (CMN a (MUL x y)) yes no) + +(EQ (CMPconst [0] z:(MSUB a x y)) yes no) && z.Uses==1 -> (EQ (CMP a (MUL x y)) yes no) +(NE (CMPconst [0] z:(MSUB a x y)) yes no) && z.Uses==1 -> (NE (CMP a (MUL x y)) yes no) +(LE (CMPconst [0] z:(MSUB a x y)) yes no) && z.Uses==1 -> (LE (CMP a (MUL x y)) yes no) +(LT (CMPconst [0] z:(MSUB a x y)) yes no) && z.Uses==1 -> (LT (CMP a (MUL x y)) yes no) +(GE (CMPconst [0] z:(MSUB a x y)) yes no) && z.Uses==1 -> (GE (CMP a (MUL x y)) yes no) +(GT (CMPconst [0] z:(MSUB a x y)) yes no) && z.Uses==1 -> (GT (CMP a (MUL x y)) yes no) + +(EQ (CMPWconst [0] z:(MADDW a x y)) yes no) && z.Uses==1 -> (EQ (CMNW a (MULW x y)) yes no) +(NE (CMPWconst [0] z:(MADDW a x y)) yes no) && z.Uses==1 -> (NE (CMNW a (MULW x y)) yes no) +(LE (CMPWconst [0] z:(MADDW a x y)) yes no) && z.Uses==1 -> (LE (CMNW a (MULW x y)) yes no) +(LT (CMPWconst [0] z:(MADDW a x y)) yes no) && z.Uses==1 -> (LT (CMNW a (MULW x y)) yes no) +(GE (CMPWconst [0] z:(MADDW a x y)) yes no) && z.Uses==1 -> (GE (CMNW a (MULW x y)) yes no) +(GT (CMPWconst [0] z:(MADDW a x y)) yes no) && z.Uses==1 -> (GT (CMNW a (MULW x y)) yes no) + +(EQ (CMPWconst [0] z:(MSUBW a x y)) yes no) && z.Uses==1 -> (EQ (CMPW a (MULW x y)) yes no) +(NE (CMPWconst [0] z:(MSUBW a x y)) yes no) && z.Uses==1 -> (NE (CMPW a (MULW x y)) yes no) +(LE (CMPWconst [0] z:(MSUBW a x y)) yes no) && z.Uses==1 -> (LE (CMPW a (MULW x y)) yes no) +(LT (CMPWconst [0] z:(MSUBW a x y)) yes no) && z.Uses==1 -> (LT (CMPW a (MULW x y)) yes no) +(GE (CMPWconst [0] z:(MSUBW a x y)) yes no) && z.Uses==1 -> (GE (CMPW a (MULW x y)) yes no) +(GT (CMPWconst [0] z:(MSUBW a x y)) yes no) && z.Uses==1 -> (GT (CMPW a (MULW x y)) yes no) + // Absorb bit-tests into block (Z (ANDconst [c] x) yes no) && oneBit(c) -> (TBZ {ntz(c)} x yes no) (NZ (ANDconst [c] x) yes no) && oneBit(c) -> (TBNZ {ntz(c)} x yes no) @@ -1058,6 +1086,17 @@ (MUL (NEG x) y) -> (MNEG x y) (MULW (NEG x) y) -> (MNEGW x y) +// madd/msub +(ADD a l:(MUL x y)) && l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MADD a x y) +(SUB a l:(MUL x y)) && l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MSUB a x y) +(ADD a l:(MNEG x y)) && l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MSUB a x y) +(SUB a l:(MNEG x y)) && l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MADD a x y) + +(ADD a l:(MULW x y)) && l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MADDW a x y) +(SUB a l:(MULW x y)) && l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MSUBW a x y) +(ADD a l:(MNEGW x y)) && l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MSUBW a x y) +(SUB a l:(MNEGW x y)) && l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MADDW a x y) + // mul by constant (MUL x (MOVDconst [-1])) -> (NEG x) (MUL _ (MOVDconst [0])) -> (MOVDconst [0]) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go index 96f2ac3ceb37f..2c434f4a740cc 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go @@ -139,6 +139,7 @@ func init() { gp1flags = regInfo{inputs: []regMask{gpg}} gp1flags1 = regInfo{inputs: []regMask{gpg}, outputs: []regMask{gp}} gp21 = regInfo{inputs: []regMask{gpg, gpg}, outputs: []regMask{gp}} + gp31 = regInfo{inputs: []regMask{gpg, gpg, gpg}, outputs: []regMask{gp}} gp21nog = regInfo{inputs: []regMask{gp, gp}, outputs: []regMask{gp}} gp2flags = regInfo{inputs: []regMask{gpg, gpg}} gp2flags1 = regInfo{inputs: []regMask{gp, gp}, outputs: []regMask{gp}} @@ -235,6 +236,10 @@ func init() { {name: "FMSUBD", argLength: 3, reg: fp31, asm: "FMSUBD"}, // +arg0 - (arg1 * arg2) {name: "FNMSUBS", argLength: 3, reg: fp31, asm: "FNMSUBS"}, // -arg0 + (arg1 * arg2) {name: "FNMSUBD", argLength: 3, reg: fp31, asm: "FNMSUBD"}, // -arg0 + (arg1 * arg2) + {name: "MADD", argLength: 3, reg: gp31, asm: "MADD"}, // +arg0 + (arg1 * arg2) + {name: "MADDW", argLength: 3, reg: gp31, asm: "MADDW"}, // +arg0 + (arg1 * arg2), 32-bit + {name: "MSUB", argLength: 3, reg: gp31, asm: "MSUB"}, // +arg0 - (arg1 * arg2) + {name: "MSUBW", argLength: 3, reg: gp31, asm: "MSUBW"}, // +arg0 - (arg1 * arg2), 32-bit // shifts {name: "SLL", argLength: 2, reg: gp21, asm: "LSL"}, // arg0 << arg1, shift amount is mod 64 diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 1c9d263debd0c..6243bfca4dabe 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -1129,6 +1129,10 @@ const ( OpARM64FMSUBD OpARM64FNMSUBS OpARM64FNMSUBD + OpARM64MADD + OpARM64MADDW + OpARM64MSUB + OpARM64MSUBW OpARM64SLL OpARM64SLLconst OpARM64SRL @@ -14954,6 +14958,66 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "MADD", + argLen: 3, + asm: arm64.AMADD, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {2, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, + { + name: "MADDW", + argLen: 3, + asm: arm64.AMADDW, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {2, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, + { + name: "MSUB", + argLen: 3, + asm: arm64.AMSUB, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {2, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, + { + name: "MSUBW", + argLen: 3, + asm: arm64.AMSUBW, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {2, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, { name: "SLL", argLen: 2, diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index fc93273f361a8..a84d1afdf43c0 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -16,7 +16,7 @@ var _ = types.TypeMem // in case not otherwise used func rewriteValueARM64(v *Value) bool { switch v.Op { case OpARM64ADD: - return rewriteValueARM64_OpARM64ADD_0(v) + return rewriteValueARM64_OpARM64ADD_0(v) || rewriteValueARM64_OpARM64ADD_10(v) case OpARM64ADDconst: return rewriteValueARM64_OpARM64ADDconst_0(v) case OpARM64ADDshiftLL: @@ -284,7 +284,7 @@ func rewriteValueARM64(v *Value) bool { case OpARM64STP: return rewriteValueARM64_OpARM64STP_0(v) case OpARM64SUB: - return rewriteValueARM64_OpARM64SUB_0(v) + return rewriteValueARM64_OpARM64SUB_0(v) || rewriteValueARM64_OpARM64SUB_10(v) case OpARM64SUBconst: return rewriteValueARM64_OpARM64SUBconst_0(v) case OpARM64SUBshiftLL: @@ -905,6 +905,185 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { v.AddArg(x) return true } + // match: (ADD a l:(MUL x y)) + // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MADD a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MUL { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MADD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (ADD l:(MUL x y) a) + // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MADD a x y) + for { + _ = v.Args[1] + l := v.Args[0] + if l.Op != OpARM64MUL { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + a := v.Args[1] + if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MADD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (ADD a l:(MNEG x y)) + // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MSUB a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MNEG { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MSUB) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (ADD l:(MNEG x y) a) + // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MSUB a x y) + for { + _ = v.Args[1] + l := v.Args[0] + if l.Op != OpARM64MNEG { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + a := v.Args[1] + if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MSUB) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (ADD a l:(MULW x y)) + // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MADDW a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MULW { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MADDW) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (ADD l:(MULW x y) a) + // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MADDW a x y) + for { + _ = v.Args[1] + l := v.Args[0] + if l.Op != OpARM64MULW { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + a := v.Args[1] + if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MADDW) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (ADD a l:(MNEGW x y)) + // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MSUBW a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MNEGW { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MSUBW) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (ADD l:(MNEGW x y) a) + // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MSUBW a x y) + for { + _ = v.Args[1] + l := v.Args[0] + if l.Op != OpARM64MNEGW { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + a := v.Args[1] + if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MSUBW) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + return false +} +func rewriteValueARM64_OpARM64ADD_10(v *Value) bool { // match: (ADD x (NEG y)) // cond: // result: (SUB x y) @@ -24624,6 +24803,94 @@ func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { v.AddArg(x) return true } + // match: (SUB a l:(MUL x y)) + // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MSUB a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MUL { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MSUB) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (SUB a l:(MNEG x y)) + // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MADD a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MNEG { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MADD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (SUB a l:(MULW x y)) + // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MSUBW a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MULW { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MSUBW) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (SUB a l:(MNEGW x y)) + // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MADDW a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MNEGW { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + break + } + v.reset(OpARM64MADDW) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } // match: (SUB x x) // cond: // result: (MOVDconst [0]) @@ -24721,6 +24988,9 @@ func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { v.AddArg(y) return true } + return false +} +func rewriteValueARM64_OpARM64SUB_10(v *Value) bool { // match: (SUB x0 x1:(SRAconst [c] y)) // cond: clobberIfDead(x1) // result: (SUBshiftRA x0 y [c]) @@ -32608,6 +32878,138 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (EQ (CMPconst [0] z:(MADD a x y)) yes no) + // cond: z.Uses==1 + // result: (EQ (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADD { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64EQ + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (EQ (CMPconst [0] z:(MSUB a x y)) yes no) + // cond: z.Uses==1 + // result: (EQ (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUB { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64EQ + v0 := b.NewValue0(v.Pos, OpARM64CMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (EQ (CMPWconst [0] z:(MADDW a x y)) yes no) + // cond: z.Uses==1 + // result: (EQ (CMNW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADDW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64EQ + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (EQ (CMPWconst [0] z:(MSUBW a x y)) yes no) + // cond: z.Uses==1 + // result: (EQ (CMPW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUBW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64EQ + v0 := b.NewValue0(v.Pos, OpARM64CMPW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (EQ (TSTconst [c] x) yes no) // cond: oneBit(c) // result: (TBZ {ntz(c)} x yes no) @@ -32784,6 +33186,138 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (GE (CMPconst [0] z:(MADD a x y)) yes no) + // cond: z.Uses==1 + // result: (GE (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADD { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] z:(MSUB a x y)) yes no) + // cond: z.Uses==1 + // result: (GE (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUB { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64CMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPWconst [0] z:(MADDW a x y)) yes no) + // cond: z.Uses==1 + // result: (GE (CMNW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADDW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPWconst [0] z:(MSUBW a x y)) yes no) + // cond: z.Uses==1 + // result: (GE (CMPW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUBW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64CMPW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (GE (CMPWconst [0] x) yes no) // cond: // result: (TBZ {int64(31)} x yes no) @@ -32956,6 +33490,138 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (GT (CMPconst [0] z:(MADD a x y)) yes no) + // cond: z.Uses==1 + // result: (GT (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADD { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] z:(MSUB a x y)) yes no) + // cond: z.Uses==1 + // result: (GT (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUB { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64CMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPWconst [0] z:(MADDW a x y)) yes no) + // cond: z.Uses==1 + // result: (GT (CMNW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADDW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPWconst [0] z:(MSUBW a x y)) yes no) + // cond: z.Uses==1 + // result: (GT (CMPW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUBW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64CMPW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (GT (FlagEQ) yes no) // cond: // result: (First nil no yes) @@ -33248,6 +33914,138 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (LE (CMPconst [0] z:(MADD a x y)) yes no) + // cond: z.Uses==1 + // result: (LE (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADD { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] z:(MSUB a x y)) yes no) + // cond: z.Uses==1 + // result: (LE (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUB { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64CMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPWconst [0] z:(MADDW a x y)) yes no) + // cond: z.Uses==1 + // result: (LE (CMNW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADDW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPWconst [0] z:(MSUBW a x y)) yes no) + // cond: z.Uses==1 + // result: (LE (CMPW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUBW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64CMPW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (LE (FlagEQ) yes no) // cond: // result: (First nil yes no) @@ -33386,6 +34184,138 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (LT (CMPconst [0] z:(MADD a x y)) yes no) + // cond: z.Uses==1 + // result: (LT (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADD { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPconst [0] z:(MSUB a x y)) yes no) + // cond: z.Uses==1 + // result: (LT (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUB { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64CMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPWconst [0] z:(MADDW a x y)) yes no) + // cond: z.Uses==1 + // result: (LT (CMNW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADDW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPWconst [0] z:(MSUBW a x y)) yes no) + // cond: z.Uses==1 + // result: (LT (CMPW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUBW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64CMPW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (LT (CMPWconst [0] x) yes no) // cond: // result: (TBNZ {int64(31)} x yes no) @@ -33706,6 +34636,138 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (NE (CMPconst [0] z:(MADD a x y)) yes no) + // cond: z.Uses==1 + // result: (NE (CMN a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADD { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64NE + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (NE (CMPconst [0] z:(MSUB a x y)) yes no) + // cond: z.Uses==1 + // result: (NE (CMP a (MUL x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUB { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64NE + v0 := b.NewValue0(v.Pos, OpARM64CMP, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (NE (CMPWconst [0] z:(MADDW a x y)) yes no) + // cond: z.Uses==1 + // result: (NE (CMNW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MADDW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64NE + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (NE (CMPWconst [0] z:(MSUBW a x y)) yes no) + // cond: z.Uses==1 + // result: (NE (CMPW a (MULW x y)) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64MSUBW { + break + } + _ = z.Args[2] + a := z.Args[0] + x := z.Args[1] + y := z.Args[2] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64NE + v0 := b.NewValue0(v.Pos, OpARM64CMPW, types.TypeFlags) + v0.AddArg(a) + v1 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v1.AddArg(x) + v1.AddArg(y) + v0.AddArg(v1) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (NE (TSTconst [c] x) yes no) // cond: oneBit(c) // result: (TBNZ {ntz(c)} x yes no) diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index 09a2fa091e803..c0539256d52e2 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -205,3 +205,9 @@ func AddMul(x int) int { // amd64:"LEAQ\t1" return 2*x + 1 } + +func MULA(a, b, c uint32) uint32 { + // arm:`MULA` + // arm64:`MADDW` + return a*b + c +} From 0e9f1de0b7c934d9061f05f4781994fbd3ebd301 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 19 Jul 2018 08:09:13 +0000 Subject: [PATCH 0294/1663] cmd/compile: optimize arm64's comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add more optimization with TST/CMN. 1. A tiny benchmark shows more than 12% improvement. TSTCMN-4 378µs ± 0% 332µs ± 0% -12.15% (p=0.000 n=30+27) (https://github.com/benshi001/ugo1/blob/master/tstcmn_test.go) 2. There is little regression in the go1 benchmark, excluding noise. name old time/op new time/op delta BinaryTree17-4 19.1s ± 0% 19.1s ± 0% ~ (p=0.994 n=28+29) Fannkuch11-4 10.0s ± 0% 10.0s ± 0% ~ (p=0.198 n=30+25) FmtFprintfEmpty-4 233ns ± 0% 233ns ± 0% +0.14% (p=0.002 n=24+30) FmtFprintfString-4 428ns ± 0% 428ns ± 0% ~ (all equal) FmtFprintfInt-4 472ns ± 0% 472ns ± 0% ~ (all equal) FmtFprintfIntInt-4 725ns ± 0% 725ns ± 0% ~ (all equal) FmtFprintfPrefixedInt-4 889ns ± 0% 888ns ± 0% ~ (p=0.632 n=28+30) FmtFprintfFloat-4 1.20µs ± 0% 1.20µs ± 0% +0.05% (p=0.001 n=18+30) FmtManyArgs-4 3.00µs ± 0% 2.99µs ± 0% -0.07% (p=0.001 n=27+30) GobDecode-4 42.1ms ± 0% 42.2ms ± 0% +0.29% (p=0.000 n=28+28) GobEncode-4 38.6ms ± 9% 38.8ms ± 9% ~ (p=0.912 n=30+30) Gzip-4 2.07s ± 1% 2.05s ± 1% -0.64% (p=0.000 n=29+30) Gunzip-4 175ms ± 0% 175ms ± 0% -0.15% (p=0.001 n=30+30) HTTPClientServer-4 872µs ± 5% 880µs ± 6% ~ (p=0.196 n=30+29) JSONEncode-4 88.5ms ± 1% 89.8ms ± 1% +1.49% (p=0.000 n=23+24) JSONDecode-4 393ms ± 1% 390ms ± 1% -0.89% (p=0.000 n=28+30) Mandelbrot200-4 19.5ms ± 0% 19.5ms ± 0% ~ (p=0.405 n=29+28) GoParse-4 19.9ms ± 0% 20.0ms ± 0% +0.27% (p=0.000 n=30+30) RegexpMatchEasy0_32-4 431ns ± 0% 431ns ± 0% ~ (p=1.000 n=30+30) RegexpMatchEasy0_1K-4 1.61µs ± 0% 1.61µs ± 0% ~ (p=0.527 n=26+26) RegexpMatchEasy1_32-4 443ns ± 0% 443ns ± 0% ~ (all equal) RegexpMatchEasy1_1K-4 2.58µs ± 1% 2.58µs ± 1% ~ (p=0.578 n=27+25) RegexpMatchMedium_32-4 740ns ± 0% 740ns ± 0% ~ (p=0.357 n=30+30) RegexpMatchMedium_1K-4 223µs ± 0% 223µs ± 0% +0.16% (p=0.000 n=30+29) RegexpMatchHard_32-4 12.3µs ± 0% 12.3µs ± 0% ~ (p=0.236 n=27+27) RegexpMatchHard_1K-4 371µs ± 0% 371µs ± 0% +0.09% (p=0.000 n=30+27) Revcomp-4 2.85s ± 0% 2.85s ± 0% ~ (p=0.057 n=28+25) Template-4 408ms ± 1% 409ms ± 1% ~ (p=0.117 n=29+29) TimeParse-4 1.93µs ± 0% 1.93µs ± 0% ~ (p=0.535 n=29+28) TimeFormat-4 1.99µs ± 0% 1.99µs ± 0% ~ (p=0.168 n=29+28) [Geo mean] 306µs 307µs +0.07% name old speed new speed delta GobDecode-4 18.3MB/s ± 0% 18.2MB/s ± 0% -0.31% (p=0.000 n=28+29) GobEncode-4 19.9MB/s ± 8% 19.8MB/s ± 9% ~ (p=0.923 n=30+30) Gzip-4 9.39MB/s ± 1% 9.45MB/s ± 1% +0.65% (p=0.000 n=29+30) Gunzip-4 111MB/s ± 0% 111MB/s ± 0% +0.15% (p=0.001 n=30+30) JSONEncode-4 21.9MB/s ± 1% 21.6MB/s ± 1% -1.45% (p=0.000 n=23+23) JSONDecode-4 4.94MB/s ± 1% 4.98MB/s ± 1% +0.84% (p=0.000 n=27+30) GoParse-4 2.91MB/s ± 0% 2.90MB/s ± 0% -0.34% (p=0.000 n=21+22) RegexpMatchEasy0_32-4 74.1MB/s ± 0% 74.1MB/s ± 0% ~ (p=0.469 n=29+28) RegexpMatchEasy0_1K-4 634MB/s ± 0% 634MB/s ± 0% ~ (p=0.978 n=24+28) RegexpMatchEasy1_32-4 72.2MB/s ± 0% 72.2MB/s ± 0% ~ (p=0.064 n=27+29) RegexpMatchEasy1_1K-4 396MB/s ± 1% 396MB/s ± 1% ~ (p=0.583 n=27+25) RegexpMatchMedium_32-4 1.35MB/s ± 0% 1.35MB/s ± 0% ~ (all equal) RegexpMatchMedium_1K-4 4.60MB/s ± 0% 4.59MB/s ± 0% -0.14% (p=0.000 n=30+26) RegexpMatchHard_32-4 2.61MB/s ± 0% 2.61MB/s ± 0% ~ (all equal) RegexpMatchHard_1K-4 2.76MB/s ± 0% 2.76MB/s ± 0% ~ (all equal) Revcomp-4 89.1MB/s ± 0% 89.1MB/s ± 0% ~ (p=0.059 n=28+25) Template-4 4.75MB/s ± 1% 4.75MB/s ± 1% ~ (p=0.106 n=29+29) [Geo mean] 18.3MB/s 18.3MB/s -0.07% Change-Id: I3cd76ce63e84b0c3cebabf9fa3573b76a7343899 Reviewed-on: https://go-review.googlesource.com/124935 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/gen/ARM64.rules | 48 + src/cmd/compile/internal/ssa/gen/ARM64Ops.go | 8 +- src/cmd/compile/internal/ssa/opGen.go | 28 +- src/cmd/compile/internal/ssa/rewriteARM64.go | 1224 ++++++++++++++++++ test/codegen/comparisons.go | 34 +- 5 files changed, 1322 insertions(+), 20 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index 374ece24e581d..ede7ed3d7a093 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -574,8 +574,17 @@ (EQ (CMPconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (EQ (TST x y) yes no) (NE (CMPconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (NE (TST x y) yes no) +(LT (CMPconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (LT (TST x y) yes no) +(LE (CMPconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (LE (TST x y) yes no) +(GT (CMPconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (GT (TST x y) yes no) +(GE (CMPconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (GE (TST x y) yes no) + (EQ (CMPWconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (EQ (TSTW x y) yes no) (NE (CMPWconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (NE (TSTW x y) yes no) +(LT (CMPWconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (LT (TSTW x y) yes no) +(LE (CMPWconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (LE (TSTW x y) yes no) +(GT (CMPWconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (GT (TSTW x y) yes no) +(GE (CMPWconst [0] z:(AND x y)) yes no) && z.Uses == 1 -> (GE (TSTW x y) yes no) (EQ (CMPconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 -> (EQ (TSTconst [c] y) yes no) (NE (CMPconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 -> (NE (TSTconst [c] y) yes no) @@ -584,10 +593,47 @@ (GT (CMPconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 -> (GT (TSTconst [c] y) yes no) (GE (CMPconst [0] x:(ANDconst [c] y)) yes no) && x.Uses == 1 -> (GE (TSTconst [c] y) yes no) +(EQ (CMPconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (EQ (CMNconst [c] y) yes no) +(NE (CMPconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (NE (CMNconst [c] y) yes no) +(LT (CMPconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (LT (CMNconst [c] y) yes no) +(LE (CMPconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (LE (CMNconst [c] y) yes no) +(GT (CMPconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (GT (CMNconst [c] y) yes no) +(GE (CMPconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (GE (CMNconst [c] y) yes no) + +(EQ (CMPWconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (EQ (CMNWconst [c] y) yes no) +(NE (CMPWconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (NE (CMNWconst [c] y) yes no) +(LT (CMPWconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (LT (CMNWconst [c] y) yes no) +(LE (CMPWconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (LE (CMNWconst [c] y) yes no) +(GT (CMPWconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (GT (CMNWconst [c] y) yes no) +(GE (CMPWconst [0] x:(ADDconst [c] y)) yes no) && x.Uses == 1 -> (GE (CMNWconst [c] y) yes no) + (EQ (CMPconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (EQ (CMN x y) yes no) (NE (CMPconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (NE (CMN x y) yes no) +(LT (CMPconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (LT (CMN x y) yes no) +(LE (CMPconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (LE (CMN x y) yes no) +(GT (CMPconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (GT (CMN x y) yes no) +(GE (CMPconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (GE (CMN x y) yes no) + +(EQ (CMPWconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (EQ (CMNW x y) yes no) +(NE (CMPWconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (NE (CMNW x y) yes no) +(LT (CMPWconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (LT (CMNW x y) yes no) +(LE (CMPWconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (LE (CMNW x y) yes no) +(GT (CMPWconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (GT (CMNW x y) yes no) +(GE (CMPWconst [0] z:(ADD x y)) yes no) && z.Uses == 1 -> (GE (CMNW x y) yes no) + (EQ (CMP x z:(NEG y)) yes no) && z.Uses == 1 -> (EQ (CMN x y) yes no) (NE (CMP x z:(NEG y)) yes no) && z.Uses == 1 -> (NE (CMN x y) yes no) +(LT (CMP x z:(NEG y)) yes no) && z.Uses == 1 -> (LT (CMN x y) yes no) +(LE (CMP x z:(NEG y)) yes no) && z.Uses == 1 -> (LE (CMN x y) yes no) +(GT (CMP x z:(NEG y)) yes no) && z.Uses == 1 -> (GT (CMN x y) yes no) +(GE (CMP x z:(NEG y)) yes no) && z.Uses == 1 -> (GE (CMN x y) yes no) + +(EQ (CMPW x z:(NEG y)) yes no) && z.Uses == 1 -> (EQ (CMNW x y) yes no) +(NE (CMPW x z:(NEG y)) yes no) && z.Uses == 1 -> (NE (CMNW x y) yes no) +(LT (CMPW x z:(NEG y)) yes no) && z.Uses == 1 -> (LT (CMNW x y) yes no) +(LE (CMPW x z:(NEG y)) yes no) && z.Uses == 1 -> (LE (CMNW x y) yes no) +(GT (CMPW x z:(NEG y)) yes no) && z.Uses == 1 -> (GT (CMNW x y) yes no) +(GE (CMPW x z:(NEG y)) yes no) && z.Uses == 1 -> (GE (CMNW x y) yes no) (EQ (CMPconst [0] x) yes no) -> (Z x yes no) (NE (CMPconst [0] x) yes no) -> (NZ x yes no) @@ -1066,7 +1112,9 @@ (OR x (MOVDconst [c])) -> (ORconst [c] x) (XOR x (MOVDconst [c])) -> (XORconst [c] x) (TST x (MOVDconst [c])) -> (TSTconst [c] x) +(TSTW x (MOVDconst [c])) -> (TSTWconst [c] x) (CMN x (MOVDconst [c])) -> (CMNconst [c] x) +(CMNW x (MOVDconst [c])) -> (CMNWconst [c] x) (BIC x (MOVDconst [c])) -> (ANDconst [^c] x) (EON x (MOVDconst [c])) -> (XORconst [^c] x) (ORN x (MOVDconst [c])) -> (ORconst [^c] x) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go index 2c434f4a740cc..eb0ad530a1a4b 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go @@ -258,13 +258,13 @@ func init() { {name: "CMPconst", argLength: 1, reg: gp1flags, asm: "CMP", aux: "Int64", typ: "Flags"}, // arg0 compare to auxInt {name: "CMPW", argLength: 2, reg: gp2flags, asm: "CMPW", typ: "Flags"}, // arg0 compare to arg1, 32 bit {name: "CMPWconst", argLength: 1, reg: gp1flags, asm: "CMPW", aux: "Int32", typ: "Flags"}, // arg0 compare to auxInt, 32 bit - {name: "CMN", argLength: 2, reg: gp2flags, asm: "CMN", typ: "Flags"}, // arg0 compare to -arg1 + {name: "CMN", argLength: 2, reg: gp2flags, asm: "CMN", typ: "Flags", commutative: true}, // arg0 compare to -arg1 {name: "CMNconst", argLength: 1, reg: gp1flags, asm: "CMN", aux: "Int64", typ: "Flags"}, // arg0 compare to -auxInt - {name: "CMNW", argLength: 2, reg: gp2flags, asm: "CMNW", typ: "Flags"}, // arg0 compare to -arg1, 32 bit + {name: "CMNW", argLength: 2, reg: gp2flags, asm: "CMNW", typ: "Flags", commutative: true}, // arg0 compare to -arg1, 32 bit {name: "CMNWconst", argLength: 1, reg: gp1flags, asm: "CMNW", aux: "Int32", typ: "Flags"}, // arg0 compare to -auxInt, 32 bit - {name: "TST", argLength: 2, reg: gp2flags, asm: "TST", typ: "Flags"}, // arg0 & arg1 compare to 0 + {name: "TST", argLength: 2, reg: gp2flags, asm: "TST", typ: "Flags", commutative: true}, // arg0 & arg1 compare to 0 {name: "TSTconst", argLength: 1, reg: gp1flags, asm: "TST", aux: "Int64", typ: "Flags"}, // arg0 & auxInt compare to 0 - {name: "TSTW", argLength: 2, reg: gp2flags, asm: "TSTW", typ: "Flags"}, // arg0 & arg1 compare to 0, 32 bit + {name: "TSTW", argLength: 2, reg: gp2flags, asm: "TSTW", typ: "Flags", commutative: true}, // arg0 & arg1 compare to 0, 32 bit {name: "TSTWconst", argLength: 1, reg: gp1flags, asm: "TSTW", aux: "Int32", typ: "Flags"}, // arg0 & auxInt compare to 0, 32 bit {name: "FCMPS", argLength: 2, reg: fp2flags, asm: "FCMPS", typ: "Flags"}, // arg0 compare to arg1, float32 {name: "FCMPD", argLength: 2, reg: fp2flags, asm: "FCMPD", typ: "Flags"}, // arg0 compare to arg1, float64 diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 6243bfca4dabe..0ff15db914842 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -15205,9 +15205,10 @@ var opcodeTable = [...]opInfo{ }, }, { - name: "CMN", - argLen: 2, - asm: arm64.ACMN, + name: "CMN", + argLen: 2, + commutative: true, + asm: arm64.ACMN, reg: regInfo{ inputs: []inputInfo{ {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 @@ -15227,9 +15228,10 @@ var opcodeTable = [...]opInfo{ }, }, { - name: "CMNW", - argLen: 2, - asm: arm64.ACMNW, + name: "CMNW", + argLen: 2, + commutative: true, + asm: arm64.ACMNW, reg: regInfo{ inputs: []inputInfo{ {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 @@ -15249,9 +15251,10 @@ var opcodeTable = [...]opInfo{ }, }, { - name: "TST", - argLen: 2, - asm: arm64.ATST, + name: "TST", + argLen: 2, + commutative: true, + asm: arm64.ATST, reg: regInfo{ inputs: []inputInfo{ {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 @@ -15271,9 +15274,10 @@ var opcodeTable = [...]opInfo{ }, }, { - name: "TSTW", - argLen: 2, - asm: arm64.ATSTW, + name: "TSTW", + argLen: 2, + commutative: true, + asm: arm64.ATSTW, reg: regInfo{ inputs: []inputInfo{ {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index a84d1afdf43c0..fbdf3529981a7 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -45,6 +45,8 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64BICshiftRL_0(v) case OpARM64CMN: return rewriteValueARM64_OpARM64CMN_0(v) + case OpARM64CMNW: + return rewriteValueARM64_OpARM64CMNW_0(v) case OpARM64CMNWconst: return rewriteValueARM64_OpARM64CMNWconst_0(v) case OpARM64CMNconst: @@ -295,6 +297,8 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64SUBshiftRL_0(v) case OpARM64TST: return rewriteValueARM64_OpARM64TST_0(v) + case OpARM64TSTW: + return rewriteValueARM64_OpARM64TSTW_0(v) case OpARM64TSTWconst: return rewriteValueARM64_OpARM64TSTWconst_0(v) case OpARM64TSTconst: @@ -2375,6 +2379,57 @@ func rewriteValueARM64_OpARM64CMN_0(v *Value) bool { v.AddArg(x) return true } + // match: (CMN (MOVDconst [c]) x) + // cond: + // result: (CMNconst [c] x) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64CMNconst) + v.AuxInt = c + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64CMNW_0(v *Value) bool { + // match: (CMNW x (MOVDconst [c])) + // cond: + // result: (CMNWconst [c] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64CMNWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (CMNW (MOVDconst [c]) x) + // cond: + // result: (CMNWconst [c] x) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64CMNWconst) + v.AuxInt = c + v.AddArg(x) + return true + } return false } func rewriteValueARM64_OpARM64CMNWconst_0(v *Value) bool { @@ -25219,6 +25274,57 @@ func rewriteValueARM64_OpARM64TST_0(v *Value) bool { v.AddArg(x) return true } + // match: (TST (MOVDconst [c]) x) + // cond: + // result: (TSTconst [c] x) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64TSTconst) + v.AuxInt = c + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64TSTW_0(v *Value) bool { + // match: (TSTW x (MOVDconst [c])) + // cond: + // result: (TSTWconst [c] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64TSTWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (TSTW (MOVDconst [c]) x) + // cond: + // result: (TSTWconst [c] x) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64TSTWconst) + v.AuxInt = c + v.AddArg(x) + return true + } return false } func rewriteValueARM64_OpARM64TSTWconst_0(v *Value) bool { @@ -32789,6 +32895,62 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (EQ (CMPconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (EQ (CMNconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64EQ + v0 := b.NewValue0(v.Pos, OpARM64CMNconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (EQ (CMPWconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (EQ (CMNWconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64EQ + v0 := b.NewValue0(v.Pos, OpARM64CMNWconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (EQ (CMPconst [0] z:(ADD x y)) yes no) // cond: z.Uses == 1 // result: (EQ (CMN x y) yes no) @@ -32818,6 +32980,35 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (EQ (CMPWconst [0] z:(ADD x y)) yes no) + // cond: z.Uses == 1 + // result: (EQ (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64ADD { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64EQ + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (EQ (CMP x z:(NEG y)) yes no) // cond: z.Uses == 1 // result: (EQ (CMN x y) yes no) @@ -32844,6 +33035,32 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (EQ (CMPW x z:(NEG y)) yes no) + // cond: z.Uses == 1 + // result: (EQ (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPW { + break + } + _ = v.Args[1] + x := v.Args[0] + z := v.Args[1] + if z.Op != OpARM64NEG { + break + } + y := z.Args[0] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64EQ + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (EQ (CMPconst [0] x) yes no) // cond: // result: (Z x yes no) @@ -33158,6 +33375,64 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (GE (CMPconst [0] z:(AND x y)) yes no) + // cond: z.Uses == 1 + // result: (GE (TST x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64AND { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64TST, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPWconst [0] z:(AND x y)) yes no) + // cond: z.Uses == 1 + // result: (GE (TSTW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64AND { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64TSTW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (GE (CMPconst [0] x:(ANDconst [c] y)) yes no) // cond: x.Uses == 1 // result: (GE (TSTconst [c] y) yes no) @@ -33186,6 +33461,172 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (GE (CMPconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (GE (CMNconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64CMNconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPWconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (GE (CMNWconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64CMNWconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPconst [0] z:(ADD x y)) yes no) + // cond: z.Uses == 1 + // result: (GE (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64ADD { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPWconst [0] z:(ADD x y)) yes no) + // cond: z.Uses == 1 + // result: (GE (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64ADD { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMP x z:(NEG y)) yes no) + // cond: z.Uses == 1 + // result: (GE (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMP { + break + } + _ = v.Args[1] + x := v.Args[0] + z := v.Args[1] + if z.Op != OpARM64NEG { + break + } + y := z.Args[0] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GE (CMPW x z:(NEG y)) yes no) + // cond: z.Uses == 1 + // result: (GE (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPW { + break + } + _ = v.Args[1] + x := v.Args[0] + z := v.Args[1] + if z.Op != OpARM64NEG { + break + } + y := z.Args[0] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GE + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (GE (CMPconst [0] z:(MADD a x y)) yes no) // cond: z.Uses==1 // result: (GE (CMN a (MUL x y)) yes no) @@ -33462,6 +33903,64 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (GT (CMPconst [0] z:(AND x y)) yes no) + // cond: z.Uses == 1 + // result: (GT (TST x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64AND { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64TST, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPWconst [0] z:(AND x y)) yes no) + // cond: z.Uses == 1 + // result: (GT (TSTW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64AND { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64TSTW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (GT (CMPconst [0] x:(ANDconst [c] y)) yes no) // cond: x.Uses == 1 // result: (GT (TSTconst [c] y) yes no) @@ -33490,6 +33989,172 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (GT (CMPconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (GT (CMNconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64CMNconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPWconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (GT (CMNWconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64CMNWconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPconst [0] z:(ADD x y)) yes no) + // cond: z.Uses == 1 + // result: (GT (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64ADD { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPWconst [0] z:(ADD x y)) yes no) + // cond: z.Uses == 1 + // result: (GT (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64ADD { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMP x z:(NEG y)) yes no) + // cond: z.Uses == 1 + // result: (GT (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMP { + break + } + _ = v.Args[1] + x := v.Args[0] + z := v.Args[1] + if z.Op != OpARM64NEG { + break + } + y := z.Args[0] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (GT (CMPW x z:(NEG y)) yes no) + // cond: z.Uses == 1 + // result: (GT (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPW { + break + } + _ = v.Args[1] + x := v.Args[0] + z := v.Args[1] + if z.Op != OpARM64NEG { + break + } + y := z.Args[0] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64GT + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (GT (CMPconst [0] z:(MADD a x y)) yes no) // cond: z.Uses==1 // result: (GT (CMN a (MUL x y)) yes no) @@ -33886,6 +34551,64 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (LE (CMPconst [0] z:(AND x y)) yes no) + // cond: z.Uses == 1 + // result: (LE (TST x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64AND { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64TST, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPWconst [0] z:(AND x y)) yes no) + // cond: z.Uses == 1 + // result: (LE (TSTW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64AND { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64TSTW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (LE (CMPconst [0] x:(ANDconst [c] y)) yes no) // cond: x.Uses == 1 // result: (LE (TSTconst [c] y) yes no) @@ -33914,6 +34637,172 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (LE (CMPconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (LE (CMNconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64CMNconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPWconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (LE (CMNWconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64CMNWconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPconst [0] z:(ADD x y)) yes no) + // cond: z.Uses == 1 + // result: (LE (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64ADD { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPWconst [0] z:(ADD x y)) yes no) + // cond: z.Uses == 1 + // result: (LE (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64ADD { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMP x z:(NEG y)) yes no) + // cond: z.Uses == 1 + // result: (LE (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMP { + break + } + _ = v.Args[1] + x := v.Args[0] + z := v.Args[1] + if z.Op != OpARM64NEG { + break + } + y := z.Args[0] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LE (CMPW x z:(NEG y)) yes no) + // cond: z.Uses == 1 + // result: (LE (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPW { + break + } + _ = v.Args[1] + x := v.Args[0] + z := v.Args[1] + if z.Op != OpARM64NEG { + break + } + y := z.Args[0] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LE + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (LE (CMPconst [0] z:(MADD a x y)) yes no) // cond: z.Uses==1 // result: (LE (CMN a (MUL x y)) yes no) @@ -34156,6 +35045,64 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (LT (CMPconst [0] z:(AND x y)) yes no) + // cond: z.Uses == 1 + // result: (LT (TST x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64AND { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64TST, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPWconst [0] z:(AND x y)) yes no) + // cond: z.Uses == 1 + // result: (LT (TSTW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64AND { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64TSTW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (LT (CMPconst [0] x:(ANDconst [c] y)) yes no) // cond: x.Uses == 1 // result: (LT (TSTconst [c] y) yes no) @@ -34184,6 +35131,172 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (LT (CMPconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (LT (CMNconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64CMNconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPWconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (LT (CMNWconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64CMNWconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPconst [0] z:(ADD x y)) yes no) + // cond: z.Uses == 1 + // result: (LT (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64ADD { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPWconst [0] z:(ADD x y)) yes no) + // cond: z.Uses == 1 + // result: (LT (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64ADD { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMP x z:(NEG y)) yes no) + // cond: z.Uses == 1 + // result: (LT (CMN x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMP { + break + } + _ = v.Args[1] + x := v.Args[0] + z := v.Args[1] + if z.Op != OpARM64NEG { + break + } + y := z.Args[0] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64CMN, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (LT (CMPW x z:(NEG y)) yes no) + // cond: z.Uses == 1 + // result: (LT (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPW { + break + } + _ = v.Args[1] + x := v.Args[0] + z := v.Args[1] + if z.Op != OpARM64NEG { + break + } + y := z.Args[0] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64LT + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (LT (CMPconst [0] z:(MADD a x y)) yes no) // cond: z.Uses==1 // result: (LT (CMN a (MUL x y)) yes no) @@ -34547,6 +35660,62 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (NE (CMPconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (NE (CMNconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64NE + v0 := b.NewValue0(v.Pos, OpARM64CMNconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } + // match: (NE (CMPWconst [0] x:(ADDconst [c] y)) yes no) + // cond: x.Uses == 1 + // result: (NE (CMNWconst [c] y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + x := v.Args[0] + if x.Op != OpARM64ADDconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(x.Uses == 1) { + break + } + b.Kind = BlockARM64NE + v0 := b.NewValue0(v.Pos, OpARM64CMNWconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (NE (CMPconst [0] z:(ADD x y)) yes no) // cond: z.Uses == 1 // result: (NE (CMN x y) yes no) @@ -34576,6 +35745,35 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (NE (CMPWconst [0] z:(ADD x y)) yes no) + // cond: z.Uses == 1 + // result: (NE (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPWconst { + break + } + if v.AuxInt != 0 { + break + } + z := v.Args[0] + if z.Op != OpARM64ADD { + break + } + _ = z.Args[1] + x := z.Args[0] + y := z.Args[1] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64NE + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (NE (CMP x z:(NEG y)) yes no) // cond: z.Uses == 1 // result: (NE (CMN x y) yes no) @@ -34602,6 +35800,32 @@ func rewriteBlockARM64(b *Block) bool { b.Aux = nil return true } + // match: (NE (CMPW x z:(NEG y)) yes no) + // cond: z.Uses == 1 + // result: (NE (CMNW x y) yes no) + for { + v := b.Control + if v.Op != OpARM64CMPW { + break + } + _ = v.Args[1] + x := v.Args[0] + z := v.Args[1] + if z.Op != OpARM64NEG { + break + } + y := z.Args[0] + if !(z.Uses == 1) { + break + } + b.Kind = BlockARM64NE + v0 := b.NewValue0(v.Pos, OpARM64CMNW, types.TypeFlags) + v0.AddArg(x) + v0.AddArg(y) + b.SetControl(v0) + b.Aux = nil + return true + } // match: (NE (CMPconst [0] x) yes no) // cond: // result: (NZ x yes no) diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go index 22d06363ba182..8475b130c2068 100644 --- a/test/codegen/comparisons.go +++ b/test/codegen/comparisons.go @@ -158,13 +158,39 @@ func CmpZero4(a int64, ptr *int) { } } -func CmpToZero(a, b int32) int32 { - if a&b < 0 { // arm:`TST`,-`AND` +func CmpToZero(a, b, d int32) int32 { + // arm:`TST`,-`AND` + // arm64:`TSTW`,-`AND` + c0 := a&b < 0 + // arm:`CMN`,-`ADD` + // arm64:`CMNW`,-`ADD` + c1 := a+b < 0 + // arm:`TEQ`,-`XOR` + c2 := a^b < 0 + // arm64:`TST`,-`AND` + c3 := int64(a)&int64(b) < 0 + // arm64:`CMN`,-`ADD` + c4 := int64(a)+int64(b) < 0 + // not optimized to CMNW/CMN due to further use of b+d + // arm64:`ADD`,-`CMNW` + c5 := b+d == 0 + // not optimized to TSTW/TST due to further use of a&d + // arm64:`AND`,-`TSTW` + c6 := a&d >= 0 + if c0 { return 1 - } else if a+b < 0 { // arm:`CMN`,-`ADD` + } else if c1 { return 2 - } else if a^b < 0 { // arm:`TEQ`,-`XOR` + } else if c2 { return 3 + } else if c3 { + return 4 + } else if c4 { + return 5 + } else if c5 { + return b + d + } else if c6 { + return a & d } else { return 0 } From f94de9c9fbed2a8d52a84b565c54da6efb015c4d Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Mon, 3 Sep 2018 10:47:58 -0400 Subject: [PATCH 0295/1663] cmd/compile: make math/bits.RotateLeft{32,64} intrinsics on s390x Extends CL 132435 to s390x. s390x has 32- and 64-bit variable rotate left instructions. Change-Id: Ic4f1ebb0e0543207ed2fc8c119e0163b428138a5 Reviewed-on: https://go-review.googlesource.com/133035 Run-TryBot: Michael Munday TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/gc/ssa.go | 4 +- src/cmd/compile/internal/s390x/ssa.go | 3 +- src/cmd/compile/internal/ssa/gen/S390X.rules | 9 ++- src/cmd/compile/internal/ssa/gen/S390XOps.go | 2 + src/cmd/compile/internal/ssa/opGen.go | 30 ++++++++ src/cmd/compile/internal/ssa/rewriteS390X.go | 74 ++++++++++++++++++++ test/codegen/mathbits.go | 23 ++++++ 7 files changed, 141 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 3aef7e6b6d927..00ff7d4bd56bc 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -3361,12 +3361,12 @@ func init() { func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return s.newValue2(ssa.OpRotateLeft32, types.Types[TUINT32], args[0], args[1]) }, - sys.AMD64) + sys.AMD64, sys.S390X) addF("math/bits", "RotateLeft64", func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return s.newValue2(ssa.OpRotateLeft64, types.Types[TUINT64], args[0], args[1]) }, - sys.AMD64) + sys.AMD64, sys.S390X) alias("math/bits", "RotateLeft", "math/bits", "RotateLeft64", p8...) makeOnesCountAMD64 := func(op64 ssa.Op, op32 ssa.Op) func(s *state, n *Node, args []*ssa.Value) *ssa.Value { diff --git a/src/cmd/compile/internal/s390x/ssa.go b/src/cmd/compile/internal/s390x/ssa.go index 90e61c34fd35c..be48e1b23efe5 100644 --- a/src/cmd/compile/internal/s390x/ssa.go +++ b/src/cmd/compile/internal/s390x/ssa.go @@ -160,7 +160,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { switch v.Op { case ssa.OpS390XSLD, ssa.OpS390XSLW, ssa.OpS390XSRD, ssa.OpS390XSRW, - ssa.OpS390XSRAD, ssa.OpS390XSRAW: + ssa.OpS390XSRAD, ssa.OpS390XSRAW, + ssa.OpS390XRLLG, ssa.OpS390XRLL: r := v.Reg() r1 := v.Args[0].Reg() r2 := v.Args[1].Reg() diff --git a/src/cmd/compile/internal/ssa/gen/S390X.rules b/src/cmd/compile/internal/ssa/gen/S390X.rules index 4fbdef38e7d10..47766fa77dd85 100644 --- a/src/cmd/compile/internal/ssa/gen/S390X.rules +++ b/src/cmd/compile/internal/ssa/gen/S390X.rules @@ -233,6 +233,10 @@ (Rsh(16|8)x16 x y) -> (SRAW (MOV(H|B)reg x) (MOVDGE y (MOVDconst [63]) (CMPWUconst (MOVHZreg y) [64]))) (Rsh(16|8)x8 x y) -> (SRAW (MOV(H|B)reg x) (MOVDGE y (MOVDconst [63]) (CMPWUconst (MOVBZreg y) [64]))) +// Lowering rotates +(RotateLeft32 x y) -> (RLL x y) +(RotateLeft64 x y) -> (RLLG x y) + // Lowering comparisons (Less64 x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMP x y)) (Less32 x y) -> (MOVDLT (MOVDconst [0]) (MOVDconst [1]) (CMPW x y)) @@ -532,7 +536,10 @@ (SRW x (MOV(D|W|H|B|WZ|HZ|BZ)reg y)) -> (SRW x y) (SRAW x (MOV(D|W|H|B|WZ|HZ|BZ)reg y)) -> (SRAW x y) -// Rotate generation +// Constant rotate generation +(RLL x (MOVDconst [c])) -> (RLLconst x [c&31]) +(RLLG x (MOVDconst [c])) -> (RLLGconst x [c&63]) + (ADD (SLDconst x [c]) (SRDconst x [d])) && d == 64-c -> (RLLGconst [c] x) ( OR (SLDconst x [c]) (SRDconst x [d])) && d == 64-c -> (RLLGconst [c] x) (XOR (SLDconst x [c]) (SRDconst x [d])) && d == 64-c -> (RLLGconst [c] x) diff --git a/src/cmd/compile/internal/ssa/gen/S390XOps.go b/src/cmd/compile/internal/ssa/gen/S390XOps.go index 9b5f525531a6e..19cb4be41c067 100644 --- a/src/cmd/compile/internal/ssa/gen/S390XOps.go +++ b/src/cmd/compile/internal/ssa/gen/S390XOps.go @@ -321,6 +321,8 @@ func init() { {name: "SRADconst", argLength: 1, reg: gp11, asm: "SRAD", aux: "Int8", clobberFlags: true}, // signed arg0 >> auxint, shift amount 0-63 {name: "SRAWconst", argLength: 1, reg: gp11, asm: "SRAW", aux: "Int8", clobberFlags: true}, // signed int32(arg0) >> auxint, shift amount 0-31 + {name: "RLLG", argLength: 2, reg: sh21, asm: "RLLG"}, // arg0 rotate left arg1, rotate amount 0-63 + {name: "RLL", argLength: 2, reg: sh21, asm: "RLL"}, // arg0 rotate left arg1, rotate amount 0-31 {name: "RLLGconst", argLength: 1, reg: gp11, asm: "RLLG", aux: "Int8"}, // arg0 rotate left auxint, rotate amount 0-63 {name: "RLLconst", argLength: 1, reg: gp11, asm: "RLL", aux: "Int8"}, // arg0 rotate left auxint, rotate amount 0-31 diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 0ff15db914842..5bf7021432699 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -1794,6 +1794,8 @@ const ( OpS390XSRAW OpS390XSRADconst OpS390XSRAWconst + OpS390XRLLG + OpS390XRLL OpS390XRLLGconst OpS390XRLLconst OpS390XNEG @@ -23989,6 +23991,34 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "RLLG", + argLen: 2, + asm: s390x.ARLLG, + reg: regInfo{ + inputs: []inputInfo{ + {1, 23550}, // R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14 + {0, 23551}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14 + }, + outputs: []outputInfo{ + {0, 23551}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14 + }, + }, + }, + { + name: "RLL", + argLen: 2, + asm: s390x.ARLL, + reg: regInfo{ + inputs: []inputInfo{ + {1, 23550}, // R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14 + {0, 23551}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14 + }, + outputs: []outputInfo{ + {0, 23551}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R11 R12 R14 + }, + }, + }, { name: "RLLGconst", auxType: auxInt8, diff --git a/src/cmd/compile/internal/ssa/rewriteS390X.go b/src/cmd/compile/internal/ssa/rewriteS390X.go index 768b802ec1f22..95c9a0d0fc78e 100644 --- a/src/cmd/compile/internal/ssa/rewriteS390X.go +++ b/src/cmd/compile/internal/ssa/rewriteS390X.go @@ -391,6 +391,10 @@ func rewriteValueS390X(v *Value) bool { return rewriteValueS390X_OpPopCount64_0(v) case OpPopCount8: return rewriteValueS390X_OpPopCount8_0(v) + case OpRotateLeft32: + return rewriteValueS390X_OpRotateLeft32_0(v) + case OpRotateLeft64: + return rewriteValueS390X_OpRotateLeft64_0(v) case OpRound: return rewriteValueS390X_OpRound_0(v) case OpRound32F: @@ -665,6 +669,10 @@ func rewriteValueS390X(v *Value) bool { return rewriteValueS390X_OpS390XORconst_0(v) case OpS390XORload: return rewriteValueS390X_OpS390XORload_0(v) + case OpS390XRLL: + return rewriteValueS390X_OpS390XRLL_0(v) + case OpS390XRLLG: + return rewriteValueS390X_OpS390XRLLG_0(v) case OpS390XSLD: return rewriteValueS390X_OpS390XSLD_0(v) || rewriteValueS390X_OpS390XSLD_10(v) case OpS390XSLW: @@ -5399,6 +5407,34 @@ func rewriteValueS390X_OpPopCount8_0(v *Value) bool { return true } } +func rewriteValueS390X_OpRotateLeft32_0(v *Value) bool { + // match: (RotateLeft32 x y) + // cond: + // result: (RLL x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + v.reset(OpS390XRLL) + v.AddArg(x) + v.AddArg(y) + return true + } +} +func rewriteValueS390X_OpRotateLeft64_0(v *Value) bool { + // match: (RotateLeft64 x y) + // cond: + // result: (RLLG x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + v.reset(OpS390XRLLG) + v.AddArg(x) + v.AddArg(y) + return true + } +} func rewriteValueS390X_OpRound_0(v *Value) bool { // match: (Round x) // cond: @@ -38644,6 +38680,44 @@ func rewriteValueS390X_OpS390XORload_0(v *Value) bool { } return false } +func rewriteValueS390X_OpS390XRLL_0(v *Value) bool { + // match: (RLL x (MOVDconst [c])) + // cond: + // result: (RLLconst x [c&31]) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpS390XMOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpS390XRLLconst) + v.AuxInt = c & 31 + v.AddArg(x) + return true + } + return false +} +func rewriteValueS390X_OpS390XRLLG_0(v *Value) bool { + // match: (RLLG x (MOVDconst [c])) + // cond: + // result: (RLLGconst x [c&63]) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpS390XMOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpS390XRLLGconst) + v.AuxInt = c & 63 + v.AddArg(x) + return true + } + return false +} func rewriteValueS390X_OpS390XSLD_0(v *Value) bool { b := v.Block _ = b diff --git a/test/codegen/mathbits.go b/test/codegen/mathbits.go index ad2c5abb029f6..b8844c518f1a0 100644 --- a/test/codegen/mathbits.go +++ b/test/codegen/mathbits.go @@ -171,6 +171,7 @@ func RotateLeft64(n uint64) uint64 { // amd64:"ROLQ" // arm64:"ROR" // ppc64:"ROTL" + // s390x:"RLLG" return bits.RotateLeft64(n, 37) } @@ -178,6 +179,7 @@ func RotateLeft32(n uint32) uint32 { // amd64:"ROLL" 386:"ROLL" // arm64:"RORW" // ppc64:"ROTLW" + // s390x:"RLL" return bits.RotateLeft32(n, 9) } @@ -191,6 +193,27 @@ func RotateLeft8(n uint8) uint8 { return bits.RotateLeft8(n, 5) } +func RotateLeftVariable(n uint, m int) uint { + // amd64:"ROLQ" + // ppc64:"ROTL" + // s390x:"RLLG" + return bits.RotateLeft(n, m) +} + +func RotateLeftVariable64(n uint64, m int) uint64 { + // amd64:"ROLQ" + // ppc64:"ROTL" + // s390x:"RLLG" + return bits.RotateLeft64(n, m) +} + +func RotateLeftVariable32(n uint32, m int) uint32 { + // amd64:"ROLL" + // ppc64:"ROTLW" + // s390x:"RLL" + return bits.RotateLeft32(n, m) +} + // ------------------------ // // bits.TrailingZeros // // ------------------------ // From fc5edaca30801f2d1acb7a9d39943638e6d4c1c1 Mon Sep 17 00:00:00 2001 From: Ben Burkert Date: Mon, 21 May 2018 12:56:02 -0700 Subject: [PATCH 0296/1663] net: use splice(2) on Linux when reading from UnixConn, rework splice tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rework the splice tests and benchmarks. Move the reading and writing of the spliced connections to child processes so that the I/O is not part of benchmarks or profiles. Enable the use of splice(2) when reading from a unix connection and writing to a TCP connection. The updated benchmarks show a performance gain when using splice(2) to copy large chunks of data that the original benchmark did not capture. name old time/op new time/op delta Splice/tcp-to-tcp/1024-8 5.01µs ± 2% 5.08µs ± 3% ~ (p=0.068 n=8+10) Splice/tcp-to-tcp/2048-8 4.76µs ± 5% 4.65µs ± 3% -2.36% (p=0.015 n=9+8) Splice/tcp-to-tcp/4096-8 4.91µs ± 2% 4.98µs ± 5% ~ (p=0.315 n=9+10) Splice/tcp-to-tcp/8192-8 5.50µs ± 4% 5.44µs ± 3% ~ (p=0.758 n=7+9) Splice/tcp-to-tcp/16384-8 7.65µs ± 7% 6.53µs ± 3% -14.65% (p=0.000 n=10+9) Splice/tcp-to-tcp/32768-8 15.3µs ± 7% 8.5µs ± 5% -44.21% (p=0.000 n=10+10) Splice/tcp-to-tcp/65536-8 30.0µs ± 6% 15.7µs ± 1% -47.58% (p=0.000 n=10+8) Splice/tcp-to-tcp/131072-8 59.2µs ± 2% 27.4µs ± 5% -53.75% (p=0.000 n=9+9) Splice/tcp-to-tcp/262144-8 121µs ± 4% 54µs ±19% -55.56% (p=0.000 n=9+10) Splice/tcp-to-tcp/524288-8 247µs ± 6% 108µs ±12% -56.34% (p=0.000 n=10+10) Splice/tcp-to-tcp/1048576-8 490µs ± 4% 199µs ±12% -59.31% (p=0.000 n=8+10) Splice/unix-to-tcp/1024-8 1.20µs ± 2% 1.35µs ± 7% +12.47% (p=0.000 n=10+10) Splice/unix-to-tcp/2048-8 1.33µs ±12% 1.57µs ± 4% +17.85% (p=0.000 n=9+10) Splice/unix-to-tcp/4096-8 2.24µs ± 4% 1.67µs ± 4% -25.14% (p=0.000 n=9+10) Splice/unix-to-tcp/8192-8 4.59µs ± 8% 2.20µs ±10% -52.01% (p=0.000 n=10+10) Splice/unix-to-tcp/16384-8 8.46µs ±13% 3.48µs ± 6% -58.91% (p=0.000 n=10+10) Splice/unix-to-tcp/32768-8 18.5µs ± 9% 6.1µs ± 9% -66.99% (p=0.000 n=10+10) Splice/unix-to-tcp/65536-8 35.9µs ± 7% 13.5µs ± 6% -62.40% (p=0.000 n=10+9) Splice/unix-to-tcp/131072-8 79.4µs ± 6% 25.7µs ± 4% -67.62% (p=0.000 n=10+9) Splice/unix-to-tcp/262144-8 157µs ± 4% 54µs ± 8% -65.63% (p=0.000 n=10+10) Splice/unix-to-tcp/524288-8 311µs ± 3% 107µs ± 8% -65.74% (p=0.000 n=10+10) Splice/unix-to-tcp/1048576-8 643µs ± 4% 185µs ±32% -71.21% (p=0.000 n=10+10) name old speed new speed delta Splice/tcp-to-tcp/1024-8 204MB/s ± 2% 202MB/s ± 3% ~ (p=0.068 n=8+10) Splice/tcp-to-tcp/2048-8 430MB/s ± 5% 441MB/s ± 3% +2.39% (p=0.014 n=9+8) Splice/tcp-to-tcp/4096-8 833MB/s ± 2% 823MB/s ± 5% ~ (p=0.315 n=9+10) Splice/tcp-to-tcp/8192-8 1.49GB/s ± 4% 1.51GB/s ± 3% ~ (p=0.758 n=7+9) Splice/tcp-to-tcp/16384-8 2.14GB/s ± 7% 2.51GB/s ± 3% +17.03% (p=0.000 n=10+9) Splice/tcp-to-tcp/32768-8 2.15GB/s ± 7% 3.85GB/s ± 5% +79.11% (p=0.000 n=10+10) Splice/tcp-to-tcp/65536-8 2.19GB/s ± 5% 4.17GB/s ± 1% +90.65% (p=0.000 n=10+8) Splice/tcp-to-tcp/131072-8 2.22GB/s ± 2% 4.79GB/s ± 4% +116.26% (p=0.000 n=9+9) Splice/tcp-to-tcp/262144-8 2.17GB/s ± 4% 4.93GB/s ±17% +127.25% (p=0.000 n=9+10) Splice/tcp-to-tcp/524288-8 2.13GB/s ± 6% 4.89GB/s ±13% +130.15% (p=0.000 n=10+10) Splice/tcp-to-tcp/1048576-8 2.09GB/s ±10% 5.29GB/s ±11% +153.36% (p=0.000 n=10+10) Splice/unix-to-tcp/1024-8 850MB/s ± 2% 757MB/s ± 7% -10.94% (p=0.000 n=10+10) Splice/unix-to-tcp/2048-8 1.54GB/s ±11% 1.31GB/s ± 3% -15.32% (p=0.000 n=9+10) Splice/unix-to-tcp/4096-8 1.83GB/s ± 4% 2.45GB/s ± 4% +33.59% (p=0.000 n=9+10) Splice/unix-to-tcp/8192-8 1.79GB/s ± 9% 3.73GB/s ± 9% +108.05% (p=0.000 n=10+10) Splice/unix-to-tcp/16384-8 1.95GB/s ±13% 4.68GB/s ± 3% +139.80% (p=0.000 n=10+9) Splice/unix-to-tcp/32768-8 1.78GB/s ± 9% 5.38GB/s ±10% +202.71% (p=0.000 n=10+10) Splice/unix-to-tcp/65536-8 1.83GB/s ± 8% 4.85GB/s ± 6% +165.70% (p=0.000 n=10+9) Splice/unix-to-tcp/131072-8 1.65GB/s ± 6% 5.10GB/s ± 4% +208.77% (p=0.000 n=10+9) Splice/unix-to-tcp/262144-8 1.67GB/s ± 4% 4.87GB/s ± 7% +191.19% (p=0.000 n=10+10) Splice/unix-to-tcp/524288-8 1.69GB/s ± 3% 4.93GB/s ± 7% +192.38% (p=0.000 n=10+10) Splice/unix-to-tcp/1048576-8 1.63GB/s ± 3% 5.60GB/s ±44% +243.26% (p=0.000 n=10+9) Change-Id: I1eae4c3459c918558c70fc42283db22ff7e0442c Reviewed-on: https://go-review.googlesource.com/113997 Reviewed-by: Brad Fitzpatrick --- src/net/splice_linux.go | 14 +- src/net/splice_test.go | 529 +++++++++++++++------------------------- 2 files changed, 200 insertions(+), 343 deletions(-) diff --git a/src/net/splice_linux.go b/src/net/splice_linux.go index b055f9335185d..8a4d55af62a89 100644 --- a/src/net/splice_linux.go +++ b/src/net/splice_linux.go @@ -11,7 +11,7 @@ import ( // splice transfers data from r to c using the splice system call to minimize // copies from and to userspace. c must be a TCP connection. Currently, splice -// is only enabled if r is also a TCP connection. +// is only enabled if r is a TCP or Unix connection. // // If splice returns handled == false, it has performed no work. func splice(c *netFD, r io.Reader) (written int64, err error, handled bool) { @@ -23,11 +23,17 @@ func splice(c *netFD, r io.Reader) (written int64, err error, handled bool) { return 0, nil, true } } - s, ok := r.(*TCPConn) - if !ok { + + var s *netFD + if tc, ok := r.(*TCPConn); ok { + s = tc.fd + } else if uc, ok := r.(*UnixConn); ok { + s = uc.fd + } else { return 0, nil, false } - written, handled, sc, err := poll.Splice(&c.pfd, &s.fd.pfd, remain) + + written, handled, sc, err := poll.Splice(&c.pfd, &s.pfd, remain) if lr != nil { lr.N -= written } diff --git a/src/net/splice_test.go b/src/net/splice_test.go index ffe71ae38445e..3e7fd8251b018 100644 --- a/src/net/splice_test.go +++ b/src/net/splice_test.go @@ -7,239 +7,103 @@ package net import ( - "bytes" - "fmt" "io" "io/ioutil" + "log" + "os" + "os/exec" + "strconv" "sync" "testing" ) func TestSplice(t *testing.T) { - t.Run("simple", testSpliceSimple) - t.Run("multipleWrite", testSpliceMultipleWrite) - t.Run("big", testSpliceBig) - t.Run("honorsLimitedReader", testSpliceHonorsLimitedReader) - t.Run("readerAtEOF", testSpliceReaderAtEOF) - t.Run("issue25985", testSpliceIssue25985) + t.Run("tcp-to-tcp", func(t *testing.T) { testSplice(t, "tcp", "tcp") }) + t.Run("unix-to-tcp", func(t *testing.T) { testSplice(t, "unix", "tcp") }) } -func testSpliceSimple(t *testing.T) { - srv, err := newSpliceTestServer() - if err != nil { - t.Fatal(err) - } - defer srv.Close() - copyDone := srv.Copy() - msg := []byte("splice test") - if _, err := srv.Write(msg); err != nil { - t.Fatal(err) - } - got := make([]byte, len(msg)) - if _, err := io.ReadFull(srv, got); err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, msg) { - t.Errorf("got %q, wrote %q", got, msg) - } - srv.CloseWrite() - srv.CloseRead() - if err := <-copyDone; err != nil { - t.Errorf("splice: %v", err) - } +func testSplice(t *testing.T, upNet, downNet string) { + t.Run("simple", spliceTestCase{upNet, downNet, 128, 128, 0}.test) + t.Run("multipleWrite", spliceTestCase{upNet, downNet, 4096, 1 << 20, 0}.test) + t.Run("big", spliceTestCase{upNet, downNet, 5 << 20, 1 << 30, 0}.test) + t.Run("honorsLimitedReader", spliceTestCase{upNet, downNet, 4096, 1 << 20, 1 << 10}.test) + t.Run("updatesLimitedReaderN", spliceTestCase{upNet, downNet, 1024, 4096, 4096 + 100}.test) + t.Run("limitedReaderAtLimit", spliceTestCase{upNet, downNet, 32, 128, 128}.test) + t.Run("readerAtEOF", func(t *testing.T) { testSpliceReaderAtEOF(t, upNet, downNet) }) + t.Run("issue25985", func(t *testing.T) { testSpliceIssue25985(t, upNet, downNet) }) } -func testSpliceMultipleWrite(t *testing.T) { - srv, err := newSpliceTestServer() - if err != nil { - t.Fatal(err) - } - defer srv.Close() - copyDone := srv.Copy() - msg1 := []byte("splice test part 1 ") - msg2 := []byte(" splice test part 2") - if _, err := srv.Write(msg1); err != nil { - t.Fatalf("Write: %v", err) - } - if _, err := srv.Write(msg2); err != nil { - t.Fatal(err) - } - got := make([]byte, len(msg1)+len(msg2)) - if _, err := io.ReadFull(srv, got); err != nil { - t.Fatal(err) - } - want := append(msg1, msg2...) - if !bytes.Equal(got, want) { - t.Errorf("got %q, wrote %q", got, want) - } - srv.CloseWrite() - srv.CloseRead() - if err := <-copyDone; err != nil { - t.Errorf("splice: %v", err) - } -} +type spliceTestCase struct { + upNet, downNet string -func testSpliceBig(t *testing.T) { - // The maximum amount of data that internal/poll.Splice will use in a - // splice(2) call is 4 << 20. Use a bigger size here so that we test an - // amount that doesn't fit in a single call. - size := 5 << 20 - srv, err := newSpliceTestServer() - if err != nil { - t.Fatal(err) - } - defer srv.Close() - big := make([]byte, size) - copyDone := srv.Copy() - type readResult struct { - b []byte - err error - } - readDone := make(chan readResult) - go func() { - got := make([]byte, len(big)) - _, err := io.ReadFull(srv, got) - readDone <- readResult{got, err} - }() - if _, err := srv.Write(big); err != nil { - t.Fatal(err) - } - res := <-readDone - if res.err != nil { - t.Fatal(res.err) - } - got := res.b - if !bytes.Equal(got, big) { - t.Errorf("input and output differ") - } - srv.CloseWrite() - srv.CloseRead() - if err := <-copyDone; err != nil { - t.Errorf("splice: %v", err) - } -} - -func testSpliceHonorsLimitedReader(t *testing.T) { - t.Run("stopsAfterN", testSpliceStopsAfterN) - t.Run("updatesN", testSpliceUpdatesN) - t.Run("readerAtLimit", testSpliceReaderAtLimit) + chunkSize, totalSize int + limitReadSize int } -func testSpliceStopsAfterN(t *testing.T) { - clientUp, serverUp, err := spliceTestSocketPair("tcp") +func (tc spliceTestCase) test(t *testing.T) { + clientUp, serverUp, err := spliceTestSocketPair(tc.upNet) if err != nil { t.Fatal(err) } - defer clientUp.Close() defer serverUp.Close() - clientDown, serverDown, err := spliceTestSocketPair("tcp") + cleanup, err := startSpliceClient(clientUp, "w", tc.chunkSize, tc.totalSize) if err != nil { t.Fatal(err) } - defer clientDown.Close() - defer serverDown.Close() - count := 128 - copyDone := make(chan error) - lr := &io.LimitedReader{ - N: int64(count), - R: serverUp, - } - go func() { - _, err := io.Copy(serverDown, lr) - serverDown.Close() - copyDone <- err - }() - msg := make([]byte, 2*count) - if _, err := clientUp.Write(msg); err != nil { - t.Fatal(err) - } - clientUp.Close() - var buf bytes.Buffer - if _, err := io.Copy(&buf, clientDown); err != nil { - t.Fatal(err) - } - if buf.Len() != count { - t.Errorf("splice transferred %d bytes, want to stop after %d", buf.Len(), count) - } - clientDown.Close() - if err := <-copyDone; err != nil { - t.Errorf("splice: %v", err) - } -} - -func testSpliceUpdatesN(t *testing.T) { - clientUp, serverUp, err := spliceTestSocketPair("tcp") + defer cleanup() + clientDown, serverDown, err := spliceTestSocketPair(tc.downNet) if err != nil { t.Fatal(err) } - defer clientUp.Close() - defer serverUp.Close() - clientDown, serverDown, err := spliceTestSocketPair("tcp") - if err != nil { - t.Fatal(err) - } - defer clientDown.Close() defer serverDown.Close() - count := 128 - copyDone := make(chan error) - lr := &io.LimitedReader{ - N: int64(100 + count), - R: serverUp, - } - go func() { - _, err := io.Copy(serverDown, lr) - copyDone <- err - }() - msg := make([]byte, count) - if _, err := clientUp.Write(msg); err != nil { - t.Fatal(err) - } - clientUp.Close() - got := make([]byte, count) - if _, err := io.ReadFull(clientDown, got); err != nil { + cleanup, err = startSpliceClient(clientDown, "r", tc.chunkSize, tc.totalSize) + if err != nil { t.Fatal(err) } - clientDown.Close() - if err := <-copyDone; err != nil { - t.Errorf("splice: %v", err) - } - wantN := int64(100) - if lr.N != wantN { - t.Errorf("lr.N = %d, want %d", lr.N, wantN) - } -} + defer cleanup() + var ( + r io.Reader = serverUp + size = tc.totalSize + ) + if tc.limitReadSize > 0 { + if tc.limitReadSize < size { + size = tc.limitReadSize + } -func testSpliceReaderAtLimit(t *testing.T) { - clientUp, serverUp, err := spliceTestSocketPair("tcp") - if err != nil { - t.Fatal(err) + r = &io.LimitedReader{ + N: int64(tc.limitReadSize), + R: serverUp, + } + defer serverUp.Close() } - defer clientUp.Close() - defer serverUp.Close() - clientDown, serverDown, err := spliceTestSocketPair("tcp") + n, err := io.Copy(serverDown, r) + serverDown.Close() if err != nil { t.Fatal(err) } - defer clientDown.Close() - defer serverDown.Close() - - lr := &io.LimitedReader{ - N: 0, - R: serverUp, + if want := int64(size); want != n { + t.Errorf("want %d bytes spliced, got %d", want, n) } - _, err, handled := splice(serverDown.(*TCPConn).fd, lr) - if !handled { - t.Errorf("exhausted LimitedReader: got err = %v, handled = %t, want handled = true", err, handled) + + if tc.limitReadSize > 0 { + wantN := 0 + if tc.limitReadSize > size { + wantN = tc.limitReadSize - size + } + + if n := r.(*io.LimitedReader).N; n != int64(wantN) { + t.Errorf("r.N = %d, want %d", n, wantN) + } } } -func testSpliceReaderAtEOF(t *testing.T) { - clientUp, serverUp, err := spliceTestSocketPair("tcp") +func testSpliceReaderAtEOF(t *testing.T, upNet, downNet string) { + clientUp, serverUp, err := spliceTestSocketPair(upNet) if err != nil { t.Fatal(err) } defer clientUp.Close() - clientDown, serverDown, err := spliceTestSocketPair("tcp") + clientDown, serverDown, err := spliceTestSocketPair(downNet) if err != nil { t.Fatal(err) } @@ -265,7 +129,7 @@ func testSpliceReaderAtEOF(t *testing.T) { // get a goodbye signal. Test for the goodbye signal. msg := "bye" go func() { - serverDown.(*TCPConn).ReadFrom(serverUp) + serverDown.(io.ReaderFrom).ReadFrom(serverUp) io.WriteString(serverDown, msg) serverDown.Close() }() @@ -280,13 +144,13 @@ func testSpliceReaderAtEOF(t *testing.T) { } } -func testSpliceIssue25985(t *testing.T) { - front, err := newLocalListener("tcp") +func testSpliceIssue25985(t *testing.T, upNet, downNet string) { + front, err := newLocalListener(upNet) if err != nil { t.Fatal(err) } defer front.Close() - back, err := newLocalListener("tcp") + back, err := newLocalListener(downNet) if err != nil { t.Fatal(err) } @@ -300,7 +164,7 @@ func testSpliceIssue25985(t *testing.T) { if err != nil { return } - dst, err := Dial("tcp", back.Addr().String()) + dst, err := Dial(downNet, back.Addr().String()) if err != nil { return } @@ -318,7 +182,7 @@ func testSpliceIssue25985(t *testing.T) { go proxy() - toFront, err := Dial("tcp", front.Addr().String()) + toFront, err := Dial(upNet, front.Addr().String()) if err != nil { t.Fatal(err) } @@ -340,166 +204,71 @@ func testSpliceIssue25985(t *testing.T) { wg.Wait() } -func BenchmarkTCPReadFrom(b *testing.B) { +func BenchmarkSplice(b *testing.B) { testHookUninstaller.Do(uninstallTestHooks) - var chunkSizes []int - for i := uint(10); i <= 20; i++ { - chunkSizes = append(chunkSizes, 1< totalSize { + buf = buf[:totalSize-count] + } + + var err error + if n, err = fn(buf); err != nil { + return + } + } +} From d7fc2205d44e5cc2b1b0161bc71084e8f5eea54e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 5 Sep 2018 11:39:59 +0200 Subject: [PATCH 0297/1663] test: fix nilptr3 check for wasm CL 131735 only updated nilptr3.go for the adjusted nil check. Adjust nilptr3_wasm.go as well. Change-Id: I4a6257d32bb212666fe768dac53901ea0b051138 Reviewed-on: https://go-review.googlesource.com/133495 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- test/nilptr3_wasm.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/nilptr3_wasm.go b/test/nilptr3_wasm.go index 9376d42097454..df29cdc5dc5a6 100644 --- a/test/nilptr3_wasm.go +++ b/test/nilptr3_wasm.go @@ -246,8 +246,8 @@ type TT struct { func f(t *TT) *byte { // See issue 17242. - s := &t.SS // ERROR "removed nil check" - return &s.x // ERROR "generated nil check" + s := &t.SS // ERROR "generated nil check" + return &s.x // ERROR "removed nil check" } // make sure not to do nil check for newobject From eee1cfb0b292847d037f57457b3392f67c7bf9a2 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 4 Sep 2018 14:19:53 +0200 Subject: [PATCH 0298/1663] syscall: correct argument order for SyncFileRange syscall on linux/ppc64{,le} On linux/ppc64{,le} the SYS_SYNC_FILE_RANGE2 syscall is used to implement SyncFileRange. This syscall has a different argument order than SYS_SYNC_FILE_RANGE. Apart from that the implementations of both syscalls are the same, so use a simple wrapper to invoke the syscall with the correct argument order. For context see: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=edd5cd4a9424f22b0fa08bef5e299d41befd5622 Updates #27485 Change-Id: Ib94fb98376bf6c879df6f1b68c3bdd11ebcb5a44 Reviewed-on: https://go-review.googlesource.com/133195 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/syscall/syscall_linux_ppc64x.go | 9 ++++++++- src/syscall/zsyscall_linux_ppc64.go | 20 ++++++++++---------- src/syscall/zsyscall_linux_ppc64le.go | 20 ++++++++++---------- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/syscall/syscall_linux_ppc64x.go b/src/syscall/syscall_linux_ppc64x.go index 88a520e3fd613..1cdc5f9a44155 100644 --- a/src/syscall/syscall_linux_ppc64x.go +++ b/src/syscall/syscall_linux_ppc64x.go @@ -45,7 +45,6 @@ const ( //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int64, err error) //sys Stat(path string, stat *Stat_t) (err error) //sys Statfs(path string, buf *Statfs_t) (err error) -//sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) = SYS_SYNC_FILE_RANGE2 //sys Truncate(path string, length int64) (err error) //sys accept(s int, rsa *RawSockaddrAny, addrlen *_Socklen) (fd int, err error) //sys accept4(s int, rsa *RawSockaddrAny, addrlen *_Socklen, flags int) (fd int, err error) @@ -120,3 +119,11 @@ func (cmsg *Cmsghdr) SetLen(length int) { func rawVforkSyscall(trap, a1 uintptr) (r1 uintptr, err Errno) { panic("not implemented") } + +//sys syncFileRange2(fd int, flags int, off int64, n int64) (err error) = SYS_SYNC_FILE_RANGE2 + +func SyncFileRange(fd int, off int64, n int64, flags int) error { + // The sync_file_range and sync_file_range2 syscalls differ only in the + // order of their arguments. + return syncFileRange2(fd, flags, off, n) +} diff --git a/src/syscall/zsyscall_linux_ppc64.go b/src/syscall/zsyscall_linux_ppc64.go index 20c78ef2d285c..74402250ebdb7 100644 --- a/src/syscall/zsyscall_linux_ppc64.go +++ b/src/syscall/zsyscall_linux_ppc64.go @@ -1504,16 +1504,6 @@ func Statfs(path string, buf *Statfs_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func SyncFileRange(fd int, off int64, n int64, flags int) (err error) { - _, _, e1 := Syscall6(SYS_SYNC_FILE_RANGE2, uintptr(fd), uintptr(off), uintptr(n), uintptr(flags), 0, 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Truncate(path string, length int64) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) @@ -1764,3 +1754,13 @@ func pipe2(p *[2]_C_int, flags int) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func syncFileRange2(fd int, flags int, off int64, n int64) (err error) { + _, _, e1 := Syscall6(SYS_SYNC_FILE_RANGE2, uintptr(fd), uintptr(flags), uintptr(off), uintptr(n), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} diff --git a/src/syscall/zsyscall_linux_ppc64le.go b/src/syscall/zsyscall_linux_ppc64le.go index 592934399374f..3b6c283c4b62b 100644 --- a/src/syscall/zsyscall_linux_ppc64le.go +++ b/src/syscall/zsyscall_linux_ppc64le.go @@ -1504,16 +1504,6 @@ func Statfs(path string, buf *Statfs_t) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func SyncFileRange(fd int, off int64, n int64, flags int) (err error) { - _, _, e1 := Syscall6(SYS_SYNC_FILE_RANGE2, uintptr(fd), uintptr(off), uintptr(n), uintptr(flags), 0, 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Truncate(path string, length int64) (err error) { var _p0 *byte _p0, err = BytePtrFromString(path) @@ -1764,3 +1754,13 @@ func pipe2(p *[2]_C_int, flags int) (err error) { } return } + +// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT + +func syncFileRange2(fd int, flags int, off int64, n int64) (err error) { + _, _, e1 := Syscall6(SYS_SYNC_FILE_RANGE2, uintptr(fd), uintptr(flags), uintptr(off), uintptr(n), 0, 0) + if e1 != 0 { + err = errnoErr(e1) + } + return +} From b88e4ad613deec84650fb763bf6005eacee4cf79 Mon Sep 17 00:00:00 2001 From: Milan Knezevic Date: Wed, 29 Aug 2018 13:56:37 +0200 Subject: [PATCH 0299/1663] doc: add GOMIPS64 to source installation docs Fixes #27258 Change-Id: I1ac75087e2b811e6479990e12d71f2c1f4f47b64 Reviewed-on: https://go-review.googlesource.com/132015 Reviewed-by: Brad Fitzpatrick --- doc/install-source.html | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/doc/install-source.html b/doc/install-source.html index f6d9473d9be55..2d12a288694c8 100644 --- a/doc/install-source.html +++ b/doc/install-source.html @@ -639,14 +639,10 @@

    Optional environment variables

  • -
  • $GOMIPS (for mips and mipsle only) +
  • $GOMIPS (for mips and mipsle only)
    $GOMIPS64 (for mips64 and mips64le only)

    -This sets whether to use floating point instructions. + These variables set whether to use floating point instructions. Set to "hardfloat" to use floating point instructions; this is the default. Set to "softfloat" to use soft floating point.

    -
      -
    • GOMIPS=hardfloat: use floating point instructions (the default)
    • -
    • GOMIPS=softfloat: use soft floating point
    • -
From bcf3e063cc332e4c75b99d0102c0f12dd307c0b5 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Tue, 4 Sep 2018 17:35:55 +0300 Subject: [PATCH 0300/1663] test: remove go:noinline from escape_because.go File is compiled with "-l" flag, so go:noinline is redundant. Change-Id: Ia269f3b9de9466857fc578ba5164613393e82369 Reviewed-on: https://go-review.googlesource.com/133295 Reviewed-by: Cherry Zhang --- test/escape_because.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/escape_because.go b/test/escape_because.go index 0f87f1446f6d6..3b67ff9e4bf8b 100644 --- a/test/escape_because.go +++ b/test/escape_because.go @@ -113,8 +113,7 @@ func f13() { escape(c) } -//go:noinline -func transmit(b []byte) []byte { // ERROR "from ~r1 \(return\) at escape_because.go:118$" "leaking param: b to result ~r1 level=0$" +func transmit(b []byte) []byte { // ERROR "from ~r1 \(return\) at escape_because.go:117$" "leaking param: b to result ~r1 level=0$" return b } @@ -125,7 +124,7 @@ func f14() { _, _ = s1, s2 } -func leakParams(p1, p2 *int) (*int, *int) { // ERROR "leaking param: p1 to result ~r2 level=0$" "from ~r2 \(return\) at escape_because.go:129$" "leaking param: p2 to result ~r3 level=0$" "from ~r3 \(return\) at escape_because.go:129$" +func leakParams(p1, p2 *int) (*int, *int) { // ERROR "leaking param: p1 to result ~r2 level=0$" "from ~r2 \(return\) at escape_because.go:128$" "leaking param: p2 to result ~r3 level=0$" "from ~r3 \(return\) at escape_because.go:128$" return p1, p2 } @@ -133,14 +132,14 @@ func leakThroughOAS2() { // See #26987. i := 0 // ERROR "moved to heap: i$" j := 0 // ERROR "moved to heap: j$" - sink, sink = &i, &j // ERROR "&i escapes to heap$" "from sink \(assign-pair\) at escape_because.go:136$" "from &i \(interface-converted\) at escape_because.go:136$" "&j escapes to heap$" "from &j \(interface-converted\) at escape_because.go:136" + sink, sink = &i, &j // ERROR "&i escapes to heap$" "from sink \(assign-pair\) at escape_because.go:135$" "from &i \(interface-converted\) at escape_because.go:135$" "&j escapes to heap$" "from &j \(interface-converted\) at escape_because.go:135" } func leakThroughOAS2FUNC() { // See #26987. i := 0 // ERROR "moved to heap: i$" j := 0 - sink, _ = leakParams(&i, &j) // ERROR "&i escapes to heap$" "&j does not escape$" "from .out0 \(passed-to-and-returned-from-call\) at escape_because.go:143$" "from sink \(assign-pair-func-call\) at escape_because.go:143$" + sink, _ = leakParams(&i, &j) // ERROR "&i escapes to heap$" "&j does not escape$" "from .out0 \(passed-to-and-returned-from-call\) at escape_because.go:142$" "from sink \(assign-pair-func-call\) at escape_because.go:142$" } // The list below is all of the why-escapes messages seen building the escape analysis tests. From 3fd364988ce5dcf3aa1d4eb945d233455db30af6 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Wed, 5 Sep 2018 07:07:56 +0200 Subject: [PATCH 0301/1663] misc/cgo/testplugin: disable DWARF tests on darwin For some reason on darwin the linker still can't add debug sections to plugins. Executables importing "plugin" do have them, however. Because of issue 25841, plugins on darwin would likely have bad debug info anyway so, for now, this isn't a great loss. This disables the check for debug sections in plugins for darwin only. Updates #27502 Change-Id: Ib8f62dac1e485006b0c2b3ba04f86d733db5ee9a Reviewed-on: https://go-review.googlesource.com/133435 Reviewed-by: Brad Fitzpatrick --- misc/cgo/testplugin/src/checkdwarf/main.go | 8 ++++---- misc/cgo/testplugin/test.bash | 6 +++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/misc/cgo/testplugin/src/checkdwarf/main.go b/misc/cgo/testplugin/src/checkdwarf/main.go index b689c4af15f47..7886c834e7ca2 100644 --- a/misc/cgo/testplugin/src/checkdwarf/main.go +++ b/misc/cgo/testplugin/src/checkdwarf/main.go @@ -71,13 +71,13 @@ func main() { } if exe == nil { - fmt.Fprintf(os.Stderr, "could not open %s", exePath) + fmt.Fprintf(os.Stderr, "could not open %s\n", exePath) os.Exit(1) } data, err := exe.DWARF() if err != nil { - fmt.Fprintf(os.Stderr, "error opening DWARF: %v", err) + fmt.Fprintf(os.Stderr, "%s: error opening DWARF: %v\n", exePath, err) os.Exit(1) } @@ -85,7 +85,7 @@ func main() { for { e, err := rdr.Next() if err != nil { - fmt.Fprintf(os.Stderr, "error reading DWARF: %v", err) + fmt.Fprintf(os.Stderr, "%s: error reading DWARF: %v\n", exePath, err) os.Exit(1) } if e == nil { @@ -101,6 +101,6 @@ func main() { } } - fmt.Fprintf(os.Stderr, "no entry with a name ending in %q was found", dieSuffix) + fmt.Fprintf(os.Stderr, "%s: no entry with a name ending in %q was found\n", exePath, dieSuffix) os.Exit(1) } diff --git a/misc/cgo/testplugin/test.bash b/misc/cgo/testplugin/test.bash index 5a87f5e74673d..1b94bc4badbcf 100755 --- a/misc/cgo/testplugin/test.bash +++ b/misc/cgo/testplugin/test.bash @@ -33,7 +33,11 @@ GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" -buildmode=plugin -o=unnamed2.so u GOPATH=$(pwd) go build -gcflags "$GO_GCFLAGS" host # test that DWARF sections are emitted for plugins and programs importing "plugin" -go run src/checkdwarf/main.go plugin2.so plugin2.UnexportedNameReuse +if [ $GOOS != "darwin" ]; then + # On macOS, for some reason, the linker doesn't add debug sections to .so, + # see issue #27502. + go run src/checkdwarf/main.go plugin2.so plugin2.UnexportedNameReuse +fi go run src/checkdwarf/main.go host main.main LD_LIBRARY_PATH=$(pwd) ./host From 4cf33e361ada37d8fee9443a258abd167e31d033 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Tue, 4 Sep 2018 17:17:32 +0300 Subject: [PATCH 0302/1663] cmd/compile/internal/gc: fix mayAffectMemory in esc.go For OINDEX and other Left+Right nodes, we want the whole node to be considered as "may affect memory" if either of Left or Right affect memory. Initial implementation only considered node as such if both Left and Right were non-safe. Change-Id: Icfb965a0b4c24d8f83f3722216db068dad2eba95 Reviewed-on: https://go-review.googlesource.com/133275 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: David Chase --- src/cmd/compile/internal/gc/esc.go | 4 ++-- test/escape_param.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go index 99f046ad216df..9db6c8e0b4b96 100644 --- a/src/cmd/compile/internal/gc/esc.go +++ b/src/cmd/compile/internal/gc/esc.go @@ -696,9 +696,9 @@ func (e *EscState) mayAffectMemory(n *Node) bool { case OCONV: return e.mayAffectMemory(n.Left) case OINDEX: - return e.mayAffectMemory(n.Left) && e.mayAffectMemory(n.Right) + return e.mayAffectMemory(n.Left) || e.mayAffectMemory(n.Right) case OADD, OSUB, OOR, OXOR, OMUL, OLSH, ORSH, OAND, OANDNOT, ODIV, OMOD: - return e.mayAffectMemory(n.Left) && e.mayAffectMemory(n.Right) + return e.mayAffectMemory(n.Left) || e.mayAffectMemory(n.Right) case ONOT, OCOM, OPLUS, OMINUS, OALIGNOF, OOFFSETOF, OSIZEOF: return e.mayAffectMemory(n.Left) default: diff --git a/test/escape_param.go b/test/escape_param.go index 4eb96dff9bab7..dff13b6f7cc9b 100644 --- a/test/escape_param.go +++ b/test/escape_param.go @@ -11,6 +11,8 @@ package escape +func zero() int { return 0 } + var sink interface{} // in -> out @@ -62,6 +64,12 @@ func paramArraySelfAssign(p *PairOfPairs) { // ERROR "p does not escape" p.pairs[0] = p.pairs[1] // ERROR "ignoring self-assignment in p.pairs\[0\] = p.pairs\[1\]" } +func paramArraySelfAssignUnsafeIndex(p *PairOfPairs) { // ERROR "leaking param content: p" + // Function call inside index disables self-assignment case to trigger. + p.pairs[zero()] = p.pairs[1] + p.pairs[zero()+1] = p.pairs[1] +} + type PairOfPairs struct { pairs [2]*Pair } From 5789f838bea28b57cce6b8def426aef933fb1050 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 5 Sep 2018 15:53:30 +0200 Subject: [PATCH 0303/1663] net: skip splice unix-to-tcp tests on android The android builders are failing on the AF_UNIX part of the new splice test from CL 113997. Skip them. Change-Id: Ia0519aae922acb11d2845aa687633935bcd4b1b0 Reviewed-on: https://go-review.googlesource.com/133515 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/net/splice_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/net/splice_test.go b/src/net/splice_test.go index 3e7fd8251b018..656c194094a95 100644 --- a/src/net/splice_test.go +++ b/src/net/splice_test.go @@ -19,6 +19,9 @@ import ( func TestSplice(t *testing.T) { t.Run("tcp-to-tcp", func(t *testing.T) { testSplice(t, "tcp", "tcp") }) + if !testableNetwork("unixgram") { + t.Skip("skipping unix-to-tcp tests") + } t.Run("unix-to-tcp", func(t *testing.T) { testSplice(t, "unix", "tcp") }) } From 81957dd58ee3a4c31f949e49e03d8ff9151ccef5 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 5 Sep 2018 13:34:25 +0000 Subject: [PATCH 0304/1663] net: don't block forever in splice test cleanup on failure The ppc64x builders are failing on the new splice test from CL 113997 but the actual failure is being obscured by a test deadlock. Change-Id: I7747f88bcdba9776a3c0d2f5066cfec572706108 Reviewed-on: https://go-review.googlesource.com/133417 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Tobias Klauser --- src/net/splice_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/net/splice_test.go b/src/net/splice_test.go index 656c194094a95..93e8b1f8cc0a1 100644 --- a/src/net/splice_test.go +++ b/src/net/splice_test.go @@ -15,6 +15,7 @@ import ( "strconv" "sync" "testing" + "time" ) func TestSplice(t *testing.T) { @@ -332,7 +333,19 @@ func startSpliceClient(conn Conn, op string, chunkSize, totalSize int) (func(), close(donec) }() - return func() { <-donec }, nil + return func() { + select { + case <-donec: + case <-time.After(5 * time.Second): + log.Printf("killing splice client after 5 second shutdown timeout") + cmd.Process.Kill() + select { + case <-donec: + case <-time.After(5 * time.Second): + log.Printf("splice client didn't die after 10 seconds") + } + } + }, nil } func init() { From c430adf1362dbe4c150cba98214fd521d0e9933a Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Thu, 12 Jul 2018 03:23:21 +0000 Subject: [PATCH 0305/1663] cmd/internal/obj/arm64: encode float constants into FMOVS/FMOVD instructions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Current assembler rewrites float constants to values stored in memory except 0.0, which is not performant. This patch uses the FMOVS/FMOVD instructions to move some available floating-point immediate constants into SIMD&FP destination registers. These available constants can be encoded into FMOVS/FMOVD instructions, checked by the chipfloat7() function. go1 benchmark results. name old time/op new time/op delta BinaryTree17-8 6.27s ± 1% 6.27s ± 1% ~ (p=0.762 n=10+8) Fannkuch11-8 5.42s ± 1% 5.38s ± 0% -0.63% (p=0.000 n=10+10) FmtFprintfEmpty-8 92.9ns ± 1% 93.4ns ± 0% +0.47% (p=0.004 n=9+8) FmtFprintfString-8 169ns ± 2% 170ns ± 4% ~ (p=0.378 n=10+10) FmtFprintfInt-8 197ns ± 1% 196ns ± 1% -0.77% (p=0.009 n=10+9) FmtFprintfIntInt-8 284ns ± 1% 286ns ± 1% ~ (p=0.051 n=10+10) FmtFprintfPrefixedInt-8 419ns ± 0% 422ns ± 1% +0.69% (p=0.038 n=6+10) FmtFprintfFloat-8 458ns ± 0% 463ns ± 1% +1.14% (p=0.000 n=10+10) FmtManyArgs-8 1.35µs ± 2% 1.36µs ± 1% +0.91% (p=0.043 n=10+10) GobDecode-8 16.0ms ± 2% 15.5ms ± 1% -3.39% (p=0.000 n=10+10) GobEncode-8 11.9ms ± 3% 11.4ms ± 1% -3.98% (p=0.000 n=10+9) Gzip-8 621ms ± 0% 625ms ± 0% +0.59% (p=0.000 n=9+10) Gunzip-8 74.0ms ± 1% 74.3ms ± 0% ~ (p=0.059 n=9+8) HTTPClientServer-8 116µs ± 1% 116µs ± 1% ~ (p=0.165 n=10+10) JSONEncode-8 29.3ms ± 1% 29.5ms ± 0% +0.72% (p=0.001 n=10+10) JSONDecode-8 145ms ± 1% 148ms ± 2% +2.06% (p=0.000 n=10+10) Mandelbrot200-8 9.67ms ± 0% 9.48ms ± 1% -1.92% (p=0.000 n=8+10) GoParse-8 7.55ms ± 0% 7.60ms ± 0% +0.57% (p=0.000 n=9+10) RegexpMatchEasy0_32-8 234ns ± 0% 210ns ± 0% -10.13% (p=0.000 n=8+10) RegexpMatchEasy0_1K-8 753ns ± 1% 729ns ± 0% -3.17% (p=0.000 n=10+8) RegexpMatchEasy1_32-8 225ns ± 0% 224ns ± 0% -0.44% (p=0.000 n=9+9) RegexpMatchEasy1_1K-8 1.03µs ± 0% 1.04µs ± 1% +1.29% (p=0.000 n=10+10) RegexpMatchMedium_32-8 320ns ± 3% 296ns ± 6% -7.50% (p=0.000 n=10+10) RegexpMatchMedium_1K-8 77.0µs ± 5% 73.6µs ± 1% ~ (p=0.393 n=10+10) RegexpMatchHard_32-8 3.93µs ± 0% 3.89µs ± 1% -0.95% (p=0.000 n=10+9) RegexpMatchHard_1K-8 120µs ± 5% 115µs ± 1% ~ (p=0.739 n=10+10) Revcomp-8 1.07s ± 0% 1.08s ± 1% +0.63% (p=0.000 n=10+9) Template-8 165ms ± 1% 163ms ± 1% -1.05% (p=0.001 n=8+10) TimeParse-8 751ns ± 1% 749ns ± 1% ~ (p=0.209 n=10+10) TimeFormat-8 759ns ± 1% 751ns ± 1% -0.96% (p=0.001 n=10+10) name old speed new speed delta GobDecode-8 48.0MB/s ± 2% 49.6MB/s ± 1% +3.50% (p=0.000 n=10+10) GobEncode-8 64.5MB/s ± 3% 67.1MB/s ± 1% +4.08% (p=0.000 n=10+9) Gzip-8 31.2MB/s ± 0% 31.1MB/s ± 0% -0.55% (p=0.000 n=9+8) Gunzip-8 262MB/s ± 1% 261MB/s ± 0% ~ (p=0.059 n=9+8) JSONEncode-8 66.3MB/s ± 1% 65.8MB/s ± 0% -0.72% (p=0.001 n=10+10) JSONDecode-8 13.4MB/s ± 1% 13.2MB/s ± 1% -2.02% (p=0.000 n=10+10) GoParse-8 7.67MB/s ± 0% 7.63MB/s ± 0% -0.57% (p=0.000 n=9+10) RegexpMatchEasy0_32-8 136MB/s ± 0% 152MB/s ± 0% +11.45% (p=0.000 n=10+10) RegexpMatchEasy0_1K-8 1.36GB/s ± 1% 1.40GB/s ± 0% +3.25% (p=0.000 n=10+8) RegexpMatchEasy1_32-8 142MB/s ± 0% 143MB/s ± 0% +0.35% (p=0.000 n=10+9) RegexpMatchEasy1_1K-8 992MB/s ± 0% 980MB/s ± 1% -1.27% (p=0.000 n=10+10) RegexpMatchMedium_32-8 3.12MB/s ± 3% 3.38MB/s ± 6% +8.17% (p=0.000 n=10+10) RegexpMatchMedium_1K-8 13.3MB/s ± 5% 13.9MB/s ± 1% ~ (p=0.362 n=10+10) RegexpMatchHard_32-8 8.14MB/s ± 0% 8.21MB/s ± 1% +0.95% (p=0.000 n=10+9) RegexpMatchHard_1K-8 8.54MB/s ± 5% 8.90MB/s ± 1% ~ (p=0.636 n=10+10) Revcomp-8 238MB/s ± 0% 236MB/s ± 1% -0.63% (p=0.000 n=10+9) Template-8 11.8MB/s ± 1% 11.9MB/s ± 1% +1.07% (p=0.001 n=8+10) Change-Id: I57b372d8dcd47e6aec39893843b20385d5d9c37e Reviewed-on: https://go-review.googlesource.com/129555 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/asm/internal/asm/testdata/arm64.s | 10 +++++-- src/cmd/internal/obj/arm64/asm7.go | 35 ++++++++++++----------- src/cmd/internal/obj/arm64/obj7.go | 9 +++++- 3 files changed, 34 insertions(+), 20 deletions(-) diff --git a/src/cmd/asm/internal/asm/testdata/arm64.s b/src/cmd/asm/internal/asm/testdata/arm64.s index feb507db8637a..361b7a45c0ce1 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64.s +++ b/src/cmd/asm/internal/asm/testdata/arm64.s @@ -163,6 +163,12 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8 MOVB (R29)(R30<<0), R14 // ae7bbe38 MOVB (R29)(R30), R14 // MOVB (R29)(R30*1), R14 // ae6bbe38 MOVB R4, (R2)(R6.SXTX) // 44e82638 + FMOVS $(4.0), F0 // 0010221e + FMOVD $(4.0), F0 // 0010621e + FMOVS $(0.265625), F1 // 01302a1e + FMOVD $(0.1796875), F2 // 02f0681e + FMOVS $(0.96875), F3 // 03f02d1e + FMOVD $(28.0), F4 // 0490671e FMOVS (R2)(R6), F4 // FMOVS (R2)(R6*1), F4 // 446866bc FMOVS (R2)(R6<<2), F4 // 447866bc @@ -479,14 +485,14 @@ again: // { // outcode($1, &$2, NREG, &$4); // } - FADDD $0.5, F1 // FADDD $(0.5), F1 +// FADDD $0.5, F1 // FADDD $(0.5), F1 FADDD F1, F2 // LTYPEK frcon ',' freg ',' freg // { // outcode($1, &$2, $4.reg, &$6); // } - FADDD $0.7, F1, F2 // FADDD $(0.69999999999999996), F1, F2 +// FADDD $0.7, F1, F2 // FADDD $(0.69999999999999996), F1, F2 FADDD F1, F2, F3 // diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index 00232ccd55588..7507976257b92 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -219,8 +219,6 @@ var optab = []Optab{ {AFADDS, C_FREG, C_NONE, C_NONE, C_FREG, 54, 4, 0, 0, 0}, {AFADDS, C_FREG, C_FREG, C_NONE, C_FREG, 54, 4, 0, 0, 0}, - {AFADDS, C_FCON, C_NONE, C_NONE, C_FREG, 54, 4, 0, 0, 0}, - {AFADDS, C_FCON, C_FREG, C_NONE, C_FREG, 54, 4, 0, 0, 0}, {AFMSUBD, C_FREG, C_FREG, C_FREG, C_FREG, 15, 4, 0, 0, 0}, {AFCMPS, C_FREG, C_FREG, C_NONE, C_NONE, 56, 4, 0, 0, 0}, {AFCMPS, C_FCON, C_FREG, C_NONE, C_NONE, 56, 4, 0, 0, 0}, @@ -340,9 +338,9 @@ var optab = []Optab{ {AFMOVS, C_ADDR, C_NONE, C_NONE, C_FREG, 65, 12, 0, 0, 0}, {AFMOVD, C_FREG, C_NONE, C_NONE, C_ADDR, 64, 12, 0, 0, 0}, {AFMOVD, C_ADDR, C_NONE, C_NONE, C_FREG, 65, 12, 0, 0, 0}, - {AFMOVS, C_FCON, C_NONE, C_NONE, C_FREG, 54, 4, 0, 0, 0}, + {AFMOVS, C_FCON, C_NONE, C_NONE, C_FREG, 55, 4, 0, 0, 0}, {AFMOVS, C_FREG, C_NONE, C_NONE, C_FREG, 54, 4, 0, 0, 0}, - {AFMOVD, C_FCON, C_NONE, C_NONE, C_FREG, 54, 4, 0, 0, 0}, + {AFMOVD, C_FCON, C_NONE, C_NONE, C_FREG, 55, 4, 0, 0, 0}, {AFMOVD, C_FREG, C_NONE, C_NONE, C_FREG, 54, 4, 0, 0, 0}, {AFMOVS, C_REG, C_NONE, C_NONE, C_FREG, 29, 4, 0, 0, 0}, {AFMOVS, C_FREG, C_NONE, C_NONE, C_REG, 29, 4, 0, 0, 0}, @@ -2461,6 +2459,9 @@ func buildop(ctxt *obj.Link) { } } +// chipfloat7() checks if the immediate constants available in FMOVS/FMOVD instructions. +// For details of the range of constants available, see +// http://infocenter.arm.com/help/topic/com.arm.doc.dui0473m/dom1359731199385.html. func (c *ctxt7) chipfloat7(e float64) int { ei := math.Float64bits(e) l := uint32(int32(ei)) @@ -3486,19 +3487,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { case 54: /* floating point arith */ o1 = c.oprrr(p, p.As) - - var rf int - if p.From.Type == obj.TYPE_CONST { - rf = c.chipfloat7(p.From.Val.(float64)) - if rf < 0 || true { - c.ctxt.Diag("invalid floating-point immediate\n%v", p) - rf = 0 - } - - rf |= (1 << 3) - } else { - rf = int(p.From.Reg) - } + rf := int(p.From.Reg) rt := int(p.To.Reg) r := int(p.Reg) if (o1&(0x1F<<24)) == (0x1E<<24) && (o1&(1<<11)) == 0 { /* monadic */ @@ -3509,6 +3498,18 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { } o1 |= (uint32(rf&31) << 16) | (uint32(r&31) << 5) | uint32(rt&31) + case 55: /* floating-point constant */ + var rf int + o1 = 0xf<<25 | 1<<21 | 1<<12 + rf = c.chipfloat7(p.From.Val.(float64)) + if rf < 0 { + c.ctxt.Diag("invalid floating-point immediate\n%v", p) + } + if p.As == AFMOVD { + o1 |= 1 << 22 + } + o1 |= (uint32(rf&0xff) << 13) | uint32(p.To.Reg&31) + case 56: /* floating point compare */ o1 = c.oprrr(p, p.As) diff --git a/src/cmd/internal/obj/arm64/obj7.go b/src/cmd/internal/obj/arm64/obj7.go index 97b8f70c9b20e..4476dad071d56 100644 --- a/src/cmd/internal/obj/arm64/obj7.go +++ b/src/cmd/internal/obj/arm64/obj7.go @@ -254,7 +254,11 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { switch p.As { case AFMOVS: if p.From.Type == obj.TYPE_FCONST { - f32 := float32(p.From.Val.(float64)) + f64 := p.From.Val.(float64) + f32 := float32(f64) + if c.chipfloat7(f64) > 0 { + break + } if math.Float32bits(f32) == 0 { p.From.Type = obj.TYPE_REG p.From.Reg = REGZERO @@ -269,6 +273,9 @@ func progedit(ctxt *obj.Link, p *obj.Prog, newprog obj.ProgAlloc) { case AFMOVD: if p.From.Type == obj.TYPE_FCONST { f64 := p.From.Val.(float64) + if c.chipfloat7(f64) > 0 { + break + } if math.Float64bits(f64) == 0 { p.From.Type = obj.TYPE_REG p.From.Reg = REGZERO From 067dfce21f945646b9e6bf2a7559eaaecf40b4d6 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 30 Aug 2018 01:19:58 +0000 Subject: [PATCH 0306/1663] cmd/compile: optimize ARM's comparision MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Optimize (CMPconst [0] (ADD x y)) to (CMN x y) will only get benefits when the result of the addition is no longer used, otherwise there might be even performance drop. And this CL fixes that issue for CMP/CMN/TST/TEQ. There is little regression in the go1 benchmark (excluding noise), and the test case JSONDecode-4 even gets improvement. name old time/op new time/op delta BinaryTree17-4 21.6s ± 1% 21.6s ± 0% -0.22% (p=0.013 n=30+30) Fannkuch11-4 11.1s ± 0% 11.1s ± 0% +0.11% (p=0.000 n=30+29) FmtFprintfEmpty-4 297ns ± 0% 297ns ± 0% +0.08% (p=0.007 n=26+28) FmtFprintfString-4 589ns ± 1% 589ns ± 0% ~ (p=0.659 n=30+25) FmtFprintfInt-4 644ns ± 1% 650ns ± 0% +0.88% (p=0.000 n=30+24) FmtFprintfIntInt-4 964ns ± 0% 977ns ± 0% +1.33% (p=0.000 n=30+30) FmtFprintfPrefixedInt-4 1.06µs ± 0% 1.07µs ± 0% +1.31% (p=0.000 n=29+27) FmtFprintfFloat-4 1.89µs ± 0% 1.92µs ± 0% +1.25% (p=0.000 n=29+29) FmtManyArgs-4 3.63µs ± 0% 3.67µs ± 0% +1.33% (p=0.000 n=29+27) GobDecode-4 38.1ms ± 1% 37.9ms ± 1% -0.60% (p=0.000 n=29+29) GobEncode-4 35.3ms ± 2% 35.2ms ± 1% ~ (p=0.286 n=30+30) Gzip-4 2.36s ± 0% 2.37s ± 2% ~ (p=0.277 n=24+28) Gunzip-4 264ms ± 1% 264ms ± 1% ~ (p=0.104 n=28+30) HTTPClientServer-4 1.04ms ± 4% 1.02ms ± 4% -1.65% (p=0.000 n=28+28) JSONEncode-4 78.5ms ± 1% 79.6ms ± 1% +1.34% (p=0.000 n=27+28) JSONDecode-4 379ms ± 4% 352ms ± 5% -7.09% (p=0.000 n=29+30) Mandelbrot200-4 17.6ms ± 0% 17.6ms ± 0% ~ (p=0.206 n=28+29) GoParse-4 21.9ms ± 1% 22.1ms ± 1% +0.87% (p=0.000 n=28+26) RegexpMatchEasy0_32-4 631ns ± 0% 641ns ± 0% +1.63% (p=0.000 n=29+30) RegexpMatchEasy0_1K-4 4.11µs ± 0% 4.11µs ± 0% ~ (p=0.700 n=30+30) RegexpMatchEasy1_32-4 670ns ± 0% 679ns ± 0% +1.37% (p=0.000 n=21+30) RegexpMatchEasy1_1K-4 5.31µs ± 0% 5.26µs ± 0% -1.03% (p=0.000 n=25+28) RegexpMatchMedium_32-4 905ns ± 0% 906ns ± 0% +0.14% (p=0.001 n=30+30) RegexpMatchMedium_1K-4 192µs ± 0% 191µs ± 0% -0.45% (p=0.000 n=29+27) RegexpMatchHard_32-4 11.8µs ± 0% 11.7µs ± 0% -0.39% (p=0.000 n=29+28) RegexpMatchHard_1K-4 347µs ± 0% 347µs ± 0% ~ (p=0.084 n=29+30) Revcomp-4 37.5ms ± 1% 37.5ms ± 1% ~ (p=0.279 n=29+29) Template-4 519ms ± 2% 519ms ± 2% ~ (p=0.652 n=28+29) TimeParse-4 2.83µs ± 0% 2.78µs ± 0% -1.90% (p=0.000 n=27+28) TimeFormat-4 5.79µs ± 0% 5.60µs ± 0% -3.23% (p=0.000 n=29+29) [Geo mean] 331µs 330µs -0.16% name old speed new speed delta GobDecode-4 20.1MB/s ± 1% 20.3MB/s ± 1% +0.61% (p=0.000 n=29+29) GobEncode-4 21.7MB/s ± 2% 21.8MB/s ± 1% ~ (p=0.294 n=30+30) Gzip-4 8.23MB/s ± 1% 8.20MB/s ± 2% ~ (p=0.099 n=26+28) Gunzip-4 73.5MB/s ± 1% 73.4MB/s ± 1% ~ (p=0.107 n=28+30) JSONEncode-4 24.7MB/s ± 1% 24.4MB/s ± 1% -1.32% (p=0.000 n=27+28) JSONDecode-4 5.13MB/s ± 4% 5.52MB/s ± 5% +7.65% (p=0.000 n=29+30) GoParse-4 2.65MB/s ± 1% 2.63MB/s ± 1% -0.87% (p=0.000 n=28+26) RegexpMatchEasy0_32-4 50.7MB/s ± 0% 49.9MB/s ± 0% -1.58% (p=0.000 n=29+29) RegexpMatchEasy0_1K-4 249MB/s ± 0% 249MB/s ± 0% ~ (p=0.342 n=30+28) RegexpMatchEasy1_32-4 47.7MB/s ± 0% 47.1MB/s ± 0% -1.39% (p=0.000 n=26+30) RegexpMatchEasy1_1K-4 193MB/s ± 0% 195MB/s ± 0% +1.04% (p=0.000 n=25+28) RegexpMatchMedium_32-4 1.10MB/s ± 0% 1.10MB/s ± 0% -0.42% (p=0.000 n=30+26) RegexpMatchMedium_1K-4 5.33MB/s ± 0% 5.36MB/s ± 0% +0.43% (p=0.000 n=29+29) RegexpMatchHard_32-4 2.72MB/s ± 0% 2.73MB/s ± 0% +0.37% (p=0.000 n=29+30) RegexpMatchHard_1K-4 2.95MB/s ± 0% 2.95MB/s ± 0% ~ (all equal) Revcomp-4 67.8MB/s ± 1% 67.7MB/s ± 1% ~ (p=0.273 n=29+29) Template-4 3.74MB/s ± 2% 3.74MB/s ± 2% ~ (p=0.665 n=28+29) [Geo mean] 15.2MB/s 15.2MB/s +0.21% Change-Id: Ifed1fb8cc02d5ca52c8bc6c21b6b5bf6dbb2701a Reviewed-on: https://go-review.googlesource.com/132115 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/gen/ARM.rules | 408 ++-- src/cmd/compile/internal/ssa/rewriteARM.go | 2038 +++++++++++++------- test/codegen/comparisons.go | 15 +- 3 files changed, 1539 insertions(+), 922 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/ARM.rules b/src/cmd/compile/internal/ssa/gen/ARM.rules index 8cea322295bdb..fdf4d1e9007a8 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM.rules @@ -1340,207 +1340,207 @@ // comparison simplification (CMP x (RSBconst [0] y)) -> (CMN x y) (CMN x (RSBconst [0] y)) -> (CMP x y) -(EQ (CMPconst [0] (SUB x y)) yes no) -> (EQ (CMP x y) yes no) -(EQ (CMPconst [0] (MULS x y a)) yes no) -> (EQ (CMP a (MUL x y)) yes no) -(EQ (CMPconst [0] (SUBconst [c] x)) yes no) -> (EQ (CMPconst [c] x) yes no) -(EQ (CMPconst [0] (SUBshiftLL x y [c])) yes no) -> (EQ (CMPshiftLL x y [c]) yes no) -(EQ (CMPconst [0] (SUBshiftRL x y [c])) yes no) -> (EQ (CMPshiftRL x y [c]) yes no) -(EQ (CMPconst [0] (SUBshiftRA x y [c])) yes no) -> (EQ (CMPshiftRA x y [c]) yes no) -(EQ (CMPconst [0] (SUBshiftLLreg x y z)) yes no) -> (EQ (CMPshiftLLreg x y z) yes no) -(EQ (CMPconst [0] (SUBshiftRLreg x y z)) yes no) -> (EQ (CMPshiftRLreg x y z) yes no) -(EQ (CMPconst [0] (SUBshiftRAreg x y z)) yes no) -> (EQ (CMPshiftRAreg x y z) yes no) -(NE (CMPconst [0] (SUB x y)) yes no) -> (NE (CMP x y) yes no) -(NE (CMPconst [0] (MULS x y a)) yes no) -> (NE (CMP a (MUL x y)) yes no) -(NE (CMPconst [0] (SUBconst [c] x)) yes no) -> (NE (CMPconst [c] x) yes no) -(NE (CMPconst [0] (SUBshiftLL x y [c])) yes no) -> (NE (CMPshiftLL x y [c]) yes no) -(NE (CMPconst [0] (SUBshiftRL x y [c])) yes no) -> (NE (CMPshiftRL x y [c]) yes no) -(NE (CMPconst [0] (SUBshiftRA x y [c])) yes no) -> (NE (CMPshiftRA x y [c]) yes no) -(NE (CMPconst [0] (SUBshiftLLreg x y z)) yes no) -> (NE (CMPshiftLLreg x y z) yes no) -(NE (CMPconst [0] (SUBshiftRLreg x y z)) yes no) -> (NE (CMPshiftRLreg x y z) yes no) -(NE (CMPconst [0] (SUBshiftRAreg x y z)) yes no) -> (NE (CMPshiftRAreg x y z) yes no) -(EQ (CMPconst [0] (ADD x y)) yes no) -> (EQ (CMN x y) yes no) -(EQ (CMPconst [0] (MULA x y a)) yes no) -> (EQ (CMN a (MUL x y)) yes no) -(EQ (CMPconst [0] (ADDconst [c] x)) yes no) -> (EQ (CMNconst [c] x) yes no) -(EQ (CMPconst [0] (ADDshiftLL x y [c])) yes no) -> (EQ (CMNshiftLL x y [c]) yes no) -(EQ (CMPconst [0] (ADDshiftRL x y [c])) yes no) -> (EQ (CMNshiftRL x y [c]) yes no) -(EQ (CMPconst [0] (ADDshiftRA x y [c])) yes no) -> (EQ (CMNshiftRA x y [c]) yes no) -(EQ (CMPconst [0] (ADDshiftLLreg x y z)) yes no) -> (EQ (CMNshiftLLreg x y z) yes no) -(EQ (CMPconst [0] (ADDshiftRLreg x y z)) yes no) -> (EQ (CMNshiftRLreg x y z) yes no) -(EQ (CMPconst [0] (ADDshiftRAreg x y z)) yes no) -> (EQ (CMNshiftRAreg x y z) yes no) -(NE (CMPconst [0] (ADD x y)) yes no) -> (NE (CMN x y) yes no) -(NE (CMPconst [0] (MULA x y a)) yes no) -> (NE (CMN a (MUL x y)) yes no) -(NE (CMPconst [0] (ADDconst [c] x)) yes no) -> (NE (CMNconst [c] x) yes no) -(NE (CMPconst [0] (ADDshiftLL x y [c])) yes no) -> (NE (CMNshiftLL x y [c]) yes no) -(NE (CMPconst [0] (ADDshiftRL x y [c])) yes no) -> (NE (CMNshiftRL x y [c]) yes no) -(NE (CMPconst [0] (ADDshiftRA x y [c])) yes no) -> (NE (CMNshiftRA x y [c]) yes no) -(NE (CMPconst [0] (ADDshiftLLreg x y z)) yes no) -> (NE (CMNshiftLLreg x y z) yes no) -(NE (CMPconst [0] (ADDshiftRLreg x y z)) yes no) -> (NE (CMNshiftRLreg x y z) yes no) -(NE (CMPconst [0] (ADDshiftRAreg x y z)) yes no) -> (NE (CMNshiftRAreg x y z) yes no) -(EQ (CMPconst [0] (AND x y)) yes no) -> (EQ (TST x y) yes no) -(EQ (CMPconst [0] (ANDconst [c] x)) yes no) -> (EQ (TSTconst [c] x) yes no) -(EQ (CMPconst [0] (ANDshiftLL x y [c])) yes no) -> (EQ (TSTshiftLL x y [c]) yes no) -(EQ (CMPconst [0] (ANDshiftRL x y [c])) yes no) -> (EQ (TSTshiftRL x y [c]) yes no) -(EQ (CMPconst [0] (ANDshiftRA x y [c])) yes no) -> (EQ (TSTshiftRA x y [c]) yes no) -(EQ (CMPconst [0] (ANDshiftLLreg x y z)) yes no) -> (EQ (TSTshiftLLreg x y z) yes no) -(EQ (CMPconst [0] (ANDshiftRLreg x y z)) yes no) -> (EQ (TSTshiftRLreg x y z) yes no) -(EQ (CMPconst [0] (ANDshiftRAreg x y z)) yes no) -> (EQ (TSTshiftRAreg x y z) yes no) -(NE (CMPconst [0] (AND x y)) yes no) -> (NE (TST x y) yes no) -(NE (CMPconst [0] (ANDconst [c] x)) yes no) -> (NE (TSTconst [c] x) yes no) -(NE (CMPconst [0] (ANDshiftLL x y [c])) yes no) -> (NE (TSTshiftLL x y [c]) yes no) -(NE (CMPconst [0] (ANDshiftRL x y [c])) yes no) -> (NE (TSTshiftRL x y [c]) yes no) -(NE (CMPconst [0] (ANDshiftRA x y [c])) yes no) -> (NE (TSTshiftRA x y [c]) yes no) -(NE (CMPconst [0] (ANDshiftLLreg x y z)) yes no) -> (NE (TSTshiftLLreg x y z) yes no) -(NE (CMPconst [0] (ANDshiftRLreg x y z)) yes no) -> (NE (TSTshiftRLreg x y z) yes no) -(NE (CMPconst [0] (ANDshiftRAreg x y z)) yes no) -> (NE (TSTshiftRAreg x y z) yes no) -(EQ (CMPconst [0] (XOR x y)) yes no) -> (EQ (TEQ x y) yes no) -(EQ (CMPconst [0] (XORconst [c] x)) yes no) -> (EQ (TEQconst [c] x) yes no) -(EQ (CMPconst [0] (XORshiftLL x y [c])) yes no) -> (EQ (TEQshiftLL x y [c]) yes no) -(EQ (CMPconst [0] (XORshiftRL x y [c])) yes no) -> (EQ (TEQshiftRL x y [c]) yes no) -(EQ (CMPconst [0] (XORshiftRA x y [c])) yes no) -> (EQ (TEQshiftRA x y [c]) yes no) -(EQ (CMPconst [0] (XORshiftLLreg x y z)) yes no) -> (EQ (TEQshiftLLreg x y z) yes no) -(EQ (CMPconst [0] (XORshiftRLreg x y z)) yes no) -> (EQ (TEQshiftRLreg x y z) yes no) -(EQ (CMPconst [0] (XORshiftRAreg x y z)) yes no) -> (EQ (TEQshiftRAreg x y z) yes no) -(NE (CMPconst [0] (XOR x y)) yes no) -> (NE (TEQ x y) yes no) -(NE (CMPconst [0] (XORconst [c] x)) yes no) -> (NE (TEQconst [c] x) yes no) -(NE (CMPconst [0] (XORshiftLL x y [c])) yes no) -> (NE (TEQshiftLL x y [c]) yes no) -(NE (CMPconst [0] (XORshiftRL x y [c])) yes no) -> (NE (TEQshiftRL x y [c]) yes no) -(NE (CMPconst [0] (XORshiftRA x y [c])) yes no) -> (NE (TEQshiftRA x y [c]) yes no) -(NE (CMPconst [0] (XORshiftLLreg x y z)) yes no) -> (NE (TEQshiftLLreg x y z) yes no) -(NE (CMPconst [0] (XORshiftRLreg x y z)) yes no) -> (NE (TEQshiftRLreg x y z) yes no) -(NE (CMPconst [0] (XORshiftRAreg x y z)) yes no) -> (NE (TEQshiftRAreg x y z) yes no) -(LT (CMPconst [0] l:(SUB x y)) yes no) -> (LT (CMP x y) yes no) -(LT (CMPconst [0] (MULS x y a)) yes no) -> (LT (CMP a (MUL x y)) yes no) -(LT (CMPconst [0] l:(SUBconst [c] x)) yes no) -> (LT (CMPconst [c] x) yes no) -(LT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) -> (LT (CMPshiftLL x y [c]) yes no) -(LT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) -> (LT (CMPshiftRL x y [c]) yes no) -(LT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) -> (LT (CMPshiftRA x y [c]) yes no) -(LT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) -> (LT (CMPshiftLLreg x y z) yes no) -(LT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) -> (LT (CMPshiftRLreg x y z) yes no) -(LT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) -> (LT (CMPshiftRAreg x y z) yes no) -(LE (CMPconst [0] l:(SUB x y)) yes no) -> (LE (CMP x y) yes no) -(LE (CMPconst [0] (MULS x y a)) yes no) -> (LE (CMP a (MUL x y)) yes no) -(LE (CMPconst [0] l:(SUBconst [c] x)) yes no) -> (LE (CMPconst [c] x) yes no) -(LE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) -> (LE (CMPshiftLL x y [c]) yes no) -(LE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) -> (LE (CMPshiftRL x y [c]) yes no) -(LE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) -> (LE (CMPshiftRA x y [c]) yes no) -(LE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) -> (LE (CMPshiftLLreg x y z) yes no) -(LE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) -> (LE (CMPshiftRLreg x y z) yes no) -(LE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) -> (LE (CMPshiftRAreg x y z) yes no) -(LT (CMPconst [0] l:(ADD x y)) yes no) -> (LT (CMN x y) yes no) -(LT (CMPconst [0] (MULA x y a)) yes no) -> (LT (CMN a (MUL x y)) yes no) -(LT (CMPconst [0] l:(ADDconst [c] x)) yes no) -> (LT (CMNconst [c] x) yes no) -(LT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) -> (LT (CMNshiftLL x y [c]) yes no) -(LT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) -> (LT (CMNshiftRL x y [c]) yes no) -(LT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) -> (LT (CMNshiftRA x y [c]) yes no) -(LT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) -> (LT (CMNshiftLLreg x y z) yes no) -(LT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) -> (LT (CMNshiftRLreg x y z) yes no) -(LT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) -> (LT (CMNshiftRAreg x y z) yes no) -(LE (CMPconst [0] l:(ADD x y)) yes no) -> (LE (CMN x y) yes no) -(LE (CMPconst [0] (MULA x y a)) yes no) -> (LE (CMN a (MUL x y)) yes no) -(LE (CMPconst [0] l:(ADDconst [c] x)) yes no) -> (LE (CMNconst [c] x) yes no) -(LE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) -> (LE (CMNshiftLL x y [c]) yes no) -(LE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) -> (LE (CMNshiftRL x y [c]) yes no) -(LE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) -> (LE (CMNshiftRA x y [c]) yes no) -(LE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) -> (LE (CMNshiftLLreg x y z) yes no) -(LE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) -> (LE (CMNshiftRLreg x y z) yes no) -(LE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) -> (LE (CMNshiftRAreg x y z) yes no) -(LT (CMPconst [0] l:(AND x y)) yes no) -> (LT (TST x y) yes no) -(LT (CMPconst [0] l:(ANDconst [c] x)) yes no) -> (LT (TSTconst [c] x) yes no) -(LT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) -> (LT (TSTshiftLL x y [c]) yes no) -(LT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) -> (LT (TSTshiftRL x y [c]) yes no) -(LT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) -> (LT (TSTshiftRA x y [c]) yes no) -(LT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) -> (LT (TSTshiftLLreg x y z) yes no) -(LT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) -> (LT (TSTshiftRLreg x y z) yes no) -(LT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) -> (LT (TSTshiftRAreg x y z) yes no) -(LE (CMPconst [0] l:(AND x y)) yes no) -> (LE (TST x y) yes no) -(LE (CMPconst [0] l:(ANDconst [c] x)) yes no) -> (LE (TSTconst [c] x) yes no) -(LE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) -> (LE (TSTshiftLL x y [c]) yes no) -(LE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) -> (LE (TSTshiftRL x y [c]) yes no) -(LE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) -> (LE (TSTshiftRA x y [c]) yes no) -(LE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) -> (LE (TSTshiftLLreg x y z) yes no) -(LE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) -> (LE (TSTshiftRLreg x y z) yes no) -(LE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) -> (LE (TSTshiftRAreg x y z) yes no) -(LT (CMPconst [0] l:(XOR x y)) yes no) -> (LT (TEQ x y) yes no) -(LT (CMPconst [0] l:(XORconst [c] x)) yes no) -> (LT (TEQconst [c] x) yes no) -(LT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) -> (LT (TEQshiftLL x y [c]) yes no) -(LT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) -> (LT (TEQshiftRL x y [c]) yes no) -(LT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) -> (LT (TEQshiftRA x y [c]) yes no) -(LT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) -> (LT (TEQshiftLLreg x y z) yes no) -(LT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) -> (LT (TEQshiftRLreg x y z) yes no) -(LT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) -> (LT (TEQshiftRAreg x y z) yes no) -(LE (CMPconst [0] l:(XOR x y)) yes no) -> (LE (TEQ x y) yes no) -(LE (CMPconst [0] l:(XORconst [c] x)) yes no) -> (LE (TEQconst [c] x) yes no) -(LE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) -> (LE (TEQshiftLL x y [c]) yes no) -(LE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) -> (LE (TEQshiftRL x y [c]) yes no) -(LE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) -> (LE (TEQshiftRA x y [c]) yes no) -(LE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) -> (LE (TEQshiftLLreg x y z) yes no) -(LE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) -> (LE (TEQshiftRLreg x y z) yes no) -(LE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) -> (LE (TEQshiftRAreg x y z) yes no) -(GT (CMPconst [0] l:(SUB x y)) yes no) -> (GT (CMP x y) yes no) -(GT (CMPconst [0] (MULS x y a)) yes no) -> (GT (CMP a (MUL x y)) yes no) -(GT (CMPconst [0] l:(SUBconst [c] x)) yes no) -> (GT (CMPconst [c] x) yes no) -(GT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) -> (GT (CMPshiftLL x y [c]) yes no) -(GT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) -> (GT (CMPshiftRL x y [c]) yes no) -(GT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) -> (GT (CMPshiftRA x y [c]) yes no) -(GT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) -> (GT (CMPshiftLLreg x y z) yes no) -(GT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) -> (GT (CMPshiftRLreg x y z) yes no) -(GT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) -> (GT (CMPshiftRAreg x y z) yes no) -(GE (CMPconst [0] l:(SUB x y)) yes no) -> (GE (CMP x y) yes no) -(GE (CMPconst [0] (MULS x y a)) yes no) -> (GE (CMP a (MUL x y)) yes no) -(GE (CMPconst [0] l:(SUBconst [c] x)) yes no) -> (GE (CMPconst [c] x) yes no) -(GE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) -> (GE (CMPshiftLL x y [c]) yes no) -(GE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) -> (GE (CMPshiftRL x y [c]) yes no) -(GE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) -> (GE (CMPshiftRA x y [c]) yes no) -(GE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) -> (GE (CMPshiftLLreg x y z) yes no) -(GE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) -> (GE (CMPshiftRLreg x y z) yes no) -(GE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) -> (GE (CMPshiftRAreg x y z) yes no) -(GT (CMPconst [0] l:(ADD x y)) yes no) -> (GT (CMN x y) yes no) -(GT (CMPconst [0] l:(ADDconst [c] x)) yes no) -> (GT (CMNconst [c] x) yes no) -(GT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) -> (GT (CMNshiftLL x y [c]) yes no) -(GT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) -> (GT (CMNshiftRL x y [c]) yes no) -(GT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) -> (GT (CMNshiftRA x y [c]) yes no) -(GT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) -> (GT (CMNshiftLLreg x y z) yes no) -(GT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) -> (GT (CMNshiftRLreg x y z) yes no) -(GT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) -> (GT (CMNshiftRAreg x y z) yes no) -(GE (CMPconst [0] l:(ADD x y)) yes no) -> (GE (CMN x y) yes no) -(GE (CMPconst [0] (MULA x y a)) yes no) -> (GE (CMN a (MUL x y)) yes no) -(GE (CMPconst [0] l:(ADDconst [c] x)) yes no) -> (GE (CMNconst [c] x) yes no) -(GE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) -> (GE (CMNshiftLL x y [c]) yes no) -(GE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) -> (GE (CMNshiftRL x y [c]) yes no) -(GE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) -> (GE (CMNshiftRA x y [c]) yes no) -(GE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) -> (GE (CMNshiftLLreg x y z) yes no) -(GE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) -> (GE (CMNshiftRLreg x y z) yes no) -(GE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) -> (GE (CMNshiftRAreg x y z) yes no) -(GT (CMPconst [0] l:(AND x y)) yes no) -> (GT (TST x y) yes no) -(GT (CMPconst [0] (MULA x y a)) yes no) -> (GT (CMN a (MUL x y)) yes no) -(GT (CMPconst [0] l:(ANDconst [c] x)) yes no) -> (GT (TSTconst [c] x) yes no) -(GT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) -> (GT (TSTshiftLL x y [c]) yes no) -(GT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) -> (GT (TSTshiftRL x y [c]) yes no) -(GT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) -> (GT (TSTshiftRA x y [c]) yes no) -(GT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) -> (GT (TSTshiftLLreg x y z) yes no) -(GT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) -> (GT (TSTshiftRLreg x y z) yes no) -(GT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) -> (GT (TSTshiftRAreg x y z) yes no) -(GE (CMPconst [0] l:(AND x y)) yes no) -> (GE (TST x y) yes no) -(GE (CMPconst [0] l:(ANDconst [c] x)) yes no) -> (GE (TSTconst [c] x) yes no) -(GE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) -> (GE (TSTshiftLL x y [c]) yes no) -(GE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) -> (GE (TSTshiftRL x y [c]) yes no) -(GE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) -> (GE (TSTshiftRA x y [c]) yes no) -(GE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) -> (GE (TSTshiftLLreg x y z) yes no) -(GE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) -> (GE (TSTshiftRLreg x y z) yes no) -(GE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) -> (GE (TSTshiftRAreg x y z) yes no) -(GT (CMPconst [0] l:(XOR x y)) yes no) -> (GT (TEQ x y) yes no) -(GT (CMPconst [0] l:(XORconst [c] x)) yes no) -> (GT (TEQconst [c] x) yes no) -(GT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) -> (GT (TEQshiftLL x y [c]) yes no) -(GT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) -> (GT (TEQshiftRL x y [c]) yes no) -(GT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) -> (GT (TEQshiftRA x y [c]) yes no) -(GT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) -> (GT (TEQshiftLLreg x y z) yes no) -(GT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) -> (GT (TEQshiftRLreg x y z) yes no) -(GT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) -> (GT (TEQshiftRAreg x y z) yes no) -(GE (CMPconst [0] l:(XOR x y)) yes no) -> (GE (TEQ x y) yes no) -(GE (CMPconst [0] l:(XORconst [c] x)) yes no) -> (GE (TEQconst [c] x) yes no) -(GE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) -> (GE (TEQshiftLL x y [c]) yes no) -(GE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) -> (GE (TEQshiftRL x y [c]) yes no) -(GE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) -> (GE (TEQshiftRA x y [c]) yes no) -(GE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) -> (GE (TEQshiftLLreg x y z) yes no) -(GE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) -> (GE (TEQshiftRLreg x y z) yes no) -(GE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) -> (GE (TEQshiftRAreg x y z) yes no) +(EQ (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (EQ (CMP x y) yes no) +(EQ (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (EQ (CMP a (MUL x y)) yes no) +(EQ (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (EQ (CMPconst [c] x) yes no) +(EQ (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (EQ (CMPshiftLL x y [c]) yes no) +(EQ (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (EQ (CMPshiftRL x y [c]) yes no) +(EQ (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (EQ (CMPshiftRA x y [c]) yes no) +(EQ (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (EQ (CMPshiftLLreg x y z) yes no) +(EQ (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (EQ (CMPshiftRLreg x y z) yes no) +(EQ (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (EQ (CMPshiftRAreg x y z) yes no) +(NE (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (NE (CMP x y) yes no) +(NE (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (NE (CMP a (MUL x y)) yes no) +(NE (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (NE (CMPconst [c] x) yes no) +(NE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (NE (CMPshiftLL x y [c]) yes no) +(NE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (NE (CMPshiftRL x y [c]) yes no) +(NE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (NE (CMPshiftRA x y [c]) yes no) +(NE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (NE (CMPshiftLLreg x y z) yes no) +(NE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (NE (CMPshiftRLreg x y z) yes no) +(NE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (NE (CMPshiftRAreg x y z) yes no) +(EQ (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (EQ (CMN x y) yes no) +(EQ (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (EQ (CMN a (MUL x y)) yes no) +(EQ (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (EQ (CMNconst [c] x) yes no) +(EQ (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (EQ (CMNshiftLL x y [c]) yes no) +(EQ (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (EQ (CMNshiftRL x y [c]) yes no) +(EQ (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (EQ (CMNshiftRA x y [c]) yes no) +(EQ (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (EQ (CMNshiftLLreg x y z) yes no) +(EQ (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (EQ (CMNshiftRLreg x y z) yes no) +(EQ (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (EQ (CMNshiftRAreg x y z) yes no) +(NE (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (NE (CMN x y) yes no) +(NE (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (NE (CMN a (MUL x y)) yes no) +(NE (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (NE (CMNconst [c] x) yes no) +(NE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (NE (CMNshiftLL x y [c]) yes no) +(NE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (NE (CMNshiftRL x y [c]) yes no) +(NE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (NE (CMNshiftRA x y [c]) yes no) +(NE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (NE (CMNshiftLLreg x y z) yes no) +(NE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (NE (CMNshiftRLreg x y z) yes no) +(NE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (NE (CMNshiftRAreg x y z) yes no) +(EQ (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (EQ (TST x y) yes no) +(EQ (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (EQ (TSTconst [c] x) yes no) +(EQ (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (EQ (TSTshiftLL x y [c]) yes no) +(EQ (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (EQ (TSTshiftRL x y [c]) yes no) +(EQ (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (EQ (TSTshiftRA x y [c]) yes no) +(EQ (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (EQ (TSTshiftLLreg x y z) yes no) +(EQ (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (EQ (TSTshiftRLreg x y z) yes no) +(EQ (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (EQ (TSTshiftRAreg x y z) yes no) +(NE (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (NE (TST x y) yes no) +(NE (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (NE (TSTconst [c] x) yes no) +(NE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (NE (TSTshiftLL x y [c]) yes no) +(NE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (NE (TSTshiftRL x y [c]) yes no) +(NE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (NE (TSTshiftRA x y [c]) yes no) +(NE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (NE (TSTshiftLLreg x y z) yes no) +(NE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (NE (TSTshiftRLreg x y z) yes no) +(NE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (NE (TSTshiftRAreg x y z) yes no) +(EQ (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (EQ (TEQ x y) yes no) +(EQ (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (EQ (TEQconst [c] x) yes no) +(EQ (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (EQ (TEQshiftLL x y [c]) yes no) +(EQ (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (EQ (TEQshiftRL x y [c]) yes no) +(EQ (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (EQ (TEQshiftRA x y [c]) yes no) +(EQ (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (EQ (TEQshiftLLreg x y z) yes no) +(EQ (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (EQ (TEQshiftRLreg x y z) yes no) +(EQ (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (EQ (TEQshiftRAreg x y z) yes no) +(NE (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (NE (TEQ x y) yes no) +(NE (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (NE (TEQconst [c] x) yes no) +(NE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (NE (TEQshiftLL x y [c]) yes no) +(NE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (NE (TEQshiftRL x y [c]) yes no) +(NE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (NE (TEQshiftRA x y [c]) yes no) +(NE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (NE (TEQshiftLLreg x y z) yes no) +(NE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (NE (TEQshiftRLreg x y z) yes no) +(NE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (NE (TEQshiftRAreg x y z) yes no) +(LT (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (LT (CMP x y) yes no) +(LT (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (LT (CMP a (MUL x y)) yes no) +(LT (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (LT (CMPconst [c] x) yes no) +(LT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (LT (CMPshiftLL x y [c]) yes no) +(LT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (LT (CMPshiftRL x y [c]) yes no) +(LT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (LT (CMPshiftRA x y [c]) yes no) +(LT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (LT (CMPshiftLLreg x y z) yes no) +(LT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (LT (CMPshiftRLreg x y z) yes no) +(LT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (LT (CMPshiftRAreg x y z) yes no) +(LE (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (LE (CMP x y) yes no) +(LE (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (LE (CMP a (MUL x y)) yes no) +(LE (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (LE (CMPconst [c] x) yes no) +(LE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (LE (CMPshiftLL x y [c]) yes no) +(LE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (LE (CMPshiftRL x y [c]) yes no) +(LE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (LE (CMPshiftRA x y [c]) yes no) +(LE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (LE (CMPshiftLLreg x y z) yes no) +(LE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (LE (CMPshiftRLreg x y z) yes no) +(LE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (LE (CMPshiftRAreg x y z) yes no) +(LT (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (LT (CMN x y) yes no) +(LT (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (LT (CMN a (MUL x y)) yes no) +(LT (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (LT (CMNconst [c] x) yes no) +(LT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (LT (CMNshiftLL x y [c]) yes no) +(LT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (LT (CMNshiftRL x y [c]) yes no) +(LT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (LT (CMNshiftRA x y [c]) yes no) +(LT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (LT (CMNshiftLLreg x y z) yes no) +(LT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (LT (CMNshiftRLreg x y z) yes no) +(LT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (LT (CMNshiftRAreg x y z) yes no) +(LE (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (LE (CMN x y) yes no) +(LE (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (LE (CMN a (MUL x y)) yes no) +(LE (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (LE (CMNconst [c] x) yes no) +(LE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (LE (CMNshiftLL x y [c]) yes no) +(LE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (LE (CMNshiftRL x y [c]) yes no) +(LE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (LE (CMNshiftRA x y [c]) yes no) +(LE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (LE (CMNshiftLLreg x y z) yes no) +(LE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (LE (CMNshiftRLreg x y z) yes no) +(LE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (LE (CMNshiftRAreg x y z) yes no) +(LT (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (LT (TST x y) yes no) +(LT (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (LT (TSTconst [c] x) yes no) +(LT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (LT (TSTshiftLL x y [c]) yes no) +(LT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (LT (TSTshiftRL x y [c]) yes no) +(LT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (LT (TSTshiftRA x y [c]) yes no) +(LT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (LT (TSTshiftLLreg x y z) yes no) +(LT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (LT (TSTshiftRLreg x y z) yes no) +(LT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (LT (TSTshiftRAreg x y z) yes no) +(LE (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (LE (TST x y) yes no) +(LE (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (LE (TSTconst [c] x) yes no) +(LE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (LE (TSTshiftLL x y [c]) yes no) +(LE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (LE (TSTshiftRL x y [c]) yes no) +(LE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (LE (TSTshiftRA x y [c]) yes no) +(LE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (LE (TSTshiftLLreg x y z) yes no) +(LE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (LE (TSTshiftRLreg x y z) yes no) +(LE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (LE (TSTshiftRAreg x y z) yes no) +(LT (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (LT (TEQ x y) yes no) +(LT (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (LT (TEQconst [c] x) yes no) +(LT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (LT (TEQshiftLL x y [c]) yes no) +(LT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (LT (TEQshiftRL x y [c]) yes no) +(LT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (LT (TEQshiftRA x y [c]) yes no) +(LT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (LT (TEQshiftLLreg x y z) yes no) +(LT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (LT (TEQshiftRLreg x y z) yes no) +(LT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (LT (TEQshiftRAreg x y z) yes no) +(LE (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (LE (TEQ x y) yes no) +(LE (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (LE (TEQconst [c] x) yes no) +(LE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (LE (TEQshiftLL x y [c]) yes no) +(LE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (LE (TEQshiftRL x y [c]) yes no) +(LE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (LE (TEQshiftRA x y [c]) yes no) +(LE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (LE (TEQshiftLLreg x y z) yes no) +(LE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (LE (TEQshiftRLreg x y z) yes no) +(LE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (LE (TEQshiftRAreg x y z) yes no) +(GT (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (GT (CMP x y) yes no) +(GT (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (GT (CMP a (MUL x y)) yes no) +(GT (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (GT (CMPconst [c] x) yes no) +(GT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (GT (CMPshiftLL x y [c]) yes no) +(GT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (GT (CMPshiftRL x y [c]) yes no) +(GT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (GT (CMPshiftRA x y [c]) yes no) +(GT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (GT (CMPshiftLLreg x y z) yes no) +(GT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (GT (CMPshiftRLreg x y z) yes no) +(GT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (GT (CMPshiftRAreg x y z) yes no) +(GE (CMPconst [0] l:(SUB x y)) yes no) && l.Uses==1 -> (GE (CMP x y) yes no) +(GE (CMPconst [0] l:(MULS x y a)) yes no) && l.Uses==1 -> (GE (CMP a (MUL x y)) yes no) +(GE (CMPconst [0] l:(SUBconst [c] x)) yes no) && l.Uses==1 -> (GE (CMPconst [c] x) yes no) +(GE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) && l.Uses==1 -> (GE (CMPshiftLL x y [c]) yes no) +(GE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) && l.Uses==1 -> (GE (CMPshiftRL x y [c]) yes no) +(GE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) && l.Uses==1 -> (GE (CMPshiftRA x y [c]) yes no) +(GE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) && l.Uses==1 -> (GE (CMPshiftLLreg x y z) yes no) +(GE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) && l.Uses==1 -> (GE (CMPshiftRLreg x y z) yes no) +(GE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) && l.Uses==1 -> (GE (CMPshiftRAreg x y z) yes no) +(GT (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (GT (CMN x y) yes no) +(GT (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (GT (CMNconst [c] x) yes no) +(GT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (GT (CMNshiftLL x y [c]) yes no) +(GT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (GT (CMNshiftRL x y [c]) yes no) +(GT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (GT (CMNshiftRA x y [c]) yes no) +(GT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (GT (CMNshiftLLreg x y z) yes no) +(GT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (GT (CMNshiftRLreg x y z) yes no) +(GT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (GT (CMNshiftRAreg x y z) yes no) +(GE (CMPconst [0] l:(ADD x y)) yes no) && l.Uses==1 -> (GE (CMN x y) yes no) +(GE (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (GE (CMN a (MUL x y)) yes no) +(GE (CMPconst [0] l:(ADDconst [c] x)) yes no) && l.Uses==1 -> (GE (CMNconst [c] x) yes no) +(GE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) && l.Uses==1 -> (GE (CMNshiftLL x y [c]) yes no) +(GE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) && l.Uses==1 -> (GE (CMNshiftRL x y [c]) yes no) +(GE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) && l.Uses==1 -> (GE (CMNshiftRA x y [c]) yes no) +(GE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) && l.Uses==1 -> (GE (CMNshiftLLreg x y z) yes no) +(GE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) && l.Uses==1 -> (GE (CMNshiftRLreg x y z) yes no) +(GE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) && l.Uses==1 -> (GE (CMNshiftRAreg x y z) yes no) +(GT (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (GT (TST x y) yes no) +(GT (CMPconst [0] l:(MULA x y a)) yes no) && l.Uses==1 -> (GT (CMN a (MUL x y)) yes no) +(GT (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (GT (TSTconst [c] x) yes no) +(GT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (GT (TSTshiftLL x y [c]) yes no) +(GT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (GT (TSTshiftRL x y [c]) yes no) +(GT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (GT (TSTshiftRA x y [c]) yes no) +(GT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (GT (TSTshiftLLreg x y z) yes no) +(GT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (GT (TSTshiftRLreg x y z) yes no) +(GT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (GT (TSTshiftRAreg x y z) yes no) +(GE (CMPconst [0] l:(AND x y)) yes no) && l.Uses==1 -> (GE (TST x y) yes no) +(GE (CMPconst [0] l:(ANDconst [c] x)) yes no) && l.Uses==1 -> (GE (TSTconst [c] x) yes no) +(GE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) && l.Uses==1 -> (GE (TSTshiftLL x y [c]) yes no) +(GE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) && l.Uses==1 -> (GE (TSTshiftRL x y [c]) yes no) +(GE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) && l.Uses==1 -> (GE (TSTshiftRA x y [c]) yes no) +(GE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) && l.Uses==1 -> (GE (TSTshiftLLreg x y z) yes no) +(GE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) && l.Uses==1 -> (GE (TSTshiftRLreg x y z) yes no) +(GE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) && l.Uses==1 -> (GE (TSTshiftRAreg x y z) yes no) +(GT (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (GT (TEQ x y) yes no) +(GT (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (GT (TEQconst [c] x) yes no) +(GT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (GT (TEQshiftLL x y [c]) yes no) +(GT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (GT (TEQshiftRL x y [c]) yes no) +(GT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (GT (TEQshiftRA x y [c]) yes no) +(GT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (GT (TEQshiftLLreg x y z) yes no) +(GT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (GT (TEQshiftRLreg x y z) yes no) +(GT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (GT (TEQshiftRAreg x y z) yes no) +(GE (CMPconst [0] l:(XOR x y)) yes no) && l.Uses==1 -> (GE (TEQ x y) yes no) +(GE (CMPconst [0] l:(XORconst [c] x)) yes no) && l.Uses==1 -> (GE (TEQconst [c] x) yes no) +(GE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) && l.Uses==1 -> (GE (TEQshiftLL x y [c]) yes no) +(GE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) && l.Uses==1 -> (GE (TEQshiftRL x y [c]) yes no) +(GE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) && l.Uses==1 -> (GE (TEQshiftRA x y [c]) yes no) +(GE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) && l.Uses==1 -> (GE (TEQshiftLLreg x y z) yes no) +(GE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) && l.Uses==1 -> (GE (TEQshiftRLreg x y z) yes no) +(GE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) && l.Uses==1 -> (GE (TEQshiftRAreg x y z) yes no) diff --git a/src/cmd/compile/internal/ssa/rewriteARM.go b/src/cmd/compile/internal/ssa/rewriteARM.go index 40d8d7f0b3842..966413ab25ab5 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM.go +++ b/src/cmd/compile/internal/ssa/rewriteARM.go @@ -22256,8 +22256,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (SUB x y)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(SUB x y)) yes no) + // cond: l.Uses==1 // result: (EQ (CMP x y) yes no) for { v := b.Control @@ -22267,13 +22267,16 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUB { + l := v.Args[0] + if l.Op != OpARMSUB { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(x) @@ -22282,8 +22285,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (MULS x y a)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(MULS x y a)) yes no) + // cond: l.Uses==1 // result: (EQ (CMP a (MUL x y)) yes no) for { v := b.Control @@ -22293,14 +22296,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULS { + l := v.Args[0] + if l.Op != OpARMMULS { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(a) @@ -22312,8 +22318,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (SUBconst [c] x)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(SUBconst [c] x)) yes no) + // cond: l.Uses==1 // result: (EQ (CMPconst [c] x) yes no) for { v := b.Control @@ -22323,12 +22329,15 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBconst { + l := v.Args[0] + if l.Op != OpARMSUBconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) v0.AuxInt = c @@ -22337,8 +22346,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (SUBshiftLL x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (CMPshiftLL x y [c]) yes no) for { v := b.Control @@ -22348,14 +22357,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftLL { + l := v.Args[0] + if l.Op != OpARMSUBshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMPshiftLL, types.TypeFlags) v0.AuxInt = c @@ -22365,8 +22377,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (SUBshiftRL x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (CMPshiftRL x y [c]) yes no) for { v := b.Control @@ -22376,14 +22388,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftRL { + l := v.Args[0] + if l.Op != OpARMSUBshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMPshiftRL, types.TypeFlags) v0.AuxInt = c @@ -22393,8 +22408,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (SUBshiftRA x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (CMPshiftRA x y [c]) yes no) for { v := b.Control @@ -22404,14 +22419,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftRA { + l := v.Args[0] + if l.Op != OpARMSUBshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMPshiftRA, types.TypeFlags) v0.AuxInt = c @@ -22421,8 +22439,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (SUBshiftLLreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (CMPshiftLLreg x y z) yes no) for { v := b.Control @@ -22432,14 +22450,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftLLreg { + l := v.Args[0] + if l.Op != OpARMSUBshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMPshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -22449,8 +22470,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (SUBshiftRLreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (CMPshiftRLreg x y z) yes no) for { v := b.Control @@ -22460,14 +22481,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftRLreg { + l := v.Args[0] + if l.Op != OpARMSUBshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMPshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -22477,8 +22501,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (SUBshiftRAreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (CMPshiftRAreg x y z) yes no) for { v := b.Control @@ -22488,14 +22512,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftRAreg { + l := v.Args[0] + if l.Op != OpARMSUBshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMPshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -22505,8 +22532,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ADD x y)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ADD x y)) yes no) + // cond: l.Uses==1 // result: (EQ (CMN x y) yes no) for { v := b.Control @@ -22516,13 +22543,16 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADD { + l := v.Args[0] + if l.Op != OpARMADD { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(x) @@ -22531,8 +22561,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (MULA x y a)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(MULA x y a)) yes no) + // cond: l.Uses==1 // result: (EQ (CMN a (MUL x y)) yes no) for { v := b.Control @@ -22542,14 +22572,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULA { + l := v.Args[0] + if l.Op != OpARMMULA { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(a) @@ -22561,8 +22594,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ADDconst [c] x)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ADDconst [c] x)) yes no) + // cond: l.Uses==1 // result: (EQ (CMNconst [c] x) yes no) for { v := b.Control @@ -22572,12 +22605,15 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDconst { + l := v.Args[0] + if l.Op != OpARMADDconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMNconst, types.TypeFlags) v0.AuxInt = c @@ -22586,8 +22622,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ADDshiftLL x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (CMNshiftLL x y [c]) yes no) for { v := b.Control @@ -22597,14 +22633,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftLL { + l := v.Args[0] + if l.Op != OpARMADDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMNshiftLL, types.TypeFlags) v0.AuxInt = c @@ -22614,8 +22653,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ADDshiftRL x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (CMNshiftRL x y [c]) yes no) for { v := b.Control @@ -22625,14 +22664,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftRL { + l := v.Args[0] + if l.Op != OpARMADDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMNshiftRL, types.TypeFlags) v0.AuxInt = c @@ -22642,8 +22684,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ADDshiftRA x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (CMNshiftRA x y [c]) yes no) for { v := b.Control @@ -22653,14 +22695,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftRA { + l := v.Args[0] + if l.Op != OpARMADDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMNshiftRA, types.TypeFlags) v0.AuxInt = c @@ -22670,8 +22715,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ADDshiftLLreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (CMNshiftLLreg x y z) yes no) for { v := b.Control @@ -22681,14 +22726,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftLLreg { + l := v.Args[0] + if l.Op != OpARMADDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMNshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -22698,8 +22746,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ADDshiftRLreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (CMNshiftRLreg x y z) yes no) for { v := b.Control @@ -22709,14 +22757,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftRLreg { + l := v.Args[0] + if l.Op != OpARMADDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMNshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -22726,8 +22777,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ADDshiftRAreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (CMNshiftRAreg x y z) yes no) for { v := b.Control @@ -22737,14 +22788,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftRAreg { + l := v.Args[0] + if l.Op != OpARMADDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMCMNshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -22754,8 +22808,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (AND x y)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(AND x y)) yes no) + // cond: l.Uses==1 // result: (EQ (TST x y) yes no) for { v := b.Control @@ -22765,13 +22819,16 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMAND { + l := v.Args[0] + if l.Op != OpARMAND { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTST, types.TypeFlags) v0.AddArg(x) @@ -22780,8 +22837,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ANDconst [c] x)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ANDconst [c] x)) yes no) + // cond: l.Uses==1 // result: (EQ (TSTconst [c] x) yes no) for { v := b.Control @@ -22791,12 +22848,15 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDconst { + l := v.Args[0] + if l.Op != OpARMANDconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTSTconst, types.TypeFlags) v0.AuxInt = c @@ -22805,8 +22865,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ANDshiftLL x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (TSTshiftLL x y [c]) yes no) for { v := b.Control @@ -22816,14 +22876,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftLL { + l := v.Args[0] + if l.Op != OpARMANDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTSTshiftLL, types.TypeFlags) v0.AuxInt = c @@ -22833,8 +22896,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ANDshiftRL x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (TSTshiftRL x y [c]) yes no) for { v := b.Control @@ -22844,14 +22907,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftRL { + l := v.Args[0] + if l.Op != OpARMANDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTSTshiftRL, types.TypeFlags) v0.AuxInt = c @@ -22861,8 +22927,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ANDshiftRA x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (TSTshiftRA x y [c]) yes no) for { v := b.Control @@ -22872,14 +22938,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftRA { + l := v.Args[0] + if l.Op != OpARMANDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTSTshiftRA, types.TypeFlags) v0.AuxInt = c @@ -22889,8 +22958,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ANDshiftLLreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (TSTshiftLLreg x y z) yes no) for { v := b.Control @@ -22900,14 +22969,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftLLreg { + l := v.Args[0] + if l.Op != OpARMANDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTSTshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -22917,8 +22989,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ANDshiftRLreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (TSTshiftRLreg x y z) yes no) for { v := b.Control @@ -22928,14 +23000,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftRLreg { + l := v.Args[0] + if l.Op != OpARMANDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTSTshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -22945,8 +23020,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (ANDshiftRAreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (TSTshiftRAreg x y z) yes no) for { v := b.Control @@ -22956,14 +23031,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftRAreg { + l := v.Args[0] + if l.Op != OpARMANDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTSTshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -22973,8 +23051,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (XOR x y)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(XOR x y)) yes no) + // cond: l.Uses==1 // result: (EQ (TEQ x y) yes no) for { v := b.Control @@ -22984,13 +23062,16 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXOR { + l := v.Args[0] + if l.Op != OpARMXOR { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTEQ, types.TypeFlags) v0.AddArg(x) @@ -22999,8 +23080,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (XORconst [c] x)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(XORconst [c] x)) yes no) + // cond: l.Uses==1 // result: (EQ (TEQconst [c] x) yes no) for { v := b.Control @@ -23010,12 +23091,15 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORconst { + l := v.Args[0] + if l.Op != OpARMXORconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTEQconst, types.TypeFlags) v0.AuxInt = c @@ -23024,8 +23108,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (XORshiftLL x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(XORshiftLL x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (TEQshiftLL x y [c]) yes no) for { v := b.Control @@ -23035,14 +23119,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftLL { + l := v.Args[0] + if l.Op != OpARMXORshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTEQshiftLL, types.TypeFlags) v0.AuxInt = c @@ -23052,8 +23139,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (XORshiftRL x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(XORshiftRL x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (TEQshiftRL x y [c]) yes no) for { v := b.Control @@ -23063,14 +23150,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftRL { + l := v.Args[0] + if l.Op != OpARMXORshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTEQshiftRL, types.TypeFlags) v0.AuxInt = c @@ -23080,8 +23170,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (XORshiftRA x y [c])) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(XORshiftRA x y [c])) yes no) + // cond: l.Uses==1 // result: (EQ (TEQshiftRA x y [c]) yes no) for { v := b.Control @@ -23091,14 +23181,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftRA { + l := v.Args[0] + if l.Op != OpARMXORshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTEQshiftRA, types.TypeFlags) v0.AuxInt = c @@ -23108,8 +23201,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (XORshiftLLreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (TEQshiftLLreg x y z) yes no) for { v := b.Control @@ -23119,14 +23212,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftLLreg { + l := v.Args[0] + if l.Op != OpARMXORshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTEQshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -23136,8 +23232,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (XORshiftRLreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (TEQshiftRLreg x y z) yes no) for { v := b.Control @@ -23147,14 +23243,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftRLreg { + l := v.Args[0] + if l.Op != OpARMXORshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTEQshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -23164,8 +23263,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (EQ (CMPconst [0] (XORshiftRAreg x y z)) yes no) - // cond: + // match: (EQ (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) + // cond: l.Uses==1 // result: (EQ (TEQshiftRAreg x y z) yes no) for { v := b.Control @@ -23175,14 +23274,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftRAreg { + l := v.Args[0] + if l.Op != OpARMXORshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMEQ v0 := b.NewValue0(v.Pos, OpARMTEQshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -23275,7 +23377,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(SUB x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMP x y) yes no) for { v := b.Control @@ -23292,6 +23394,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(x) @@ -23300,8 +23405,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (GE (CMPconst [0] (MULS x y a)) yes no) - // cond: + // match: (GE (CMPconst [0] l:(MULS x y a)) yes no) + // cond: l.Uses==1 // result: (GE (CMP a (MUL x y)) yes no) for { v := b.Control @@ -23311,14 +23416,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULS { + l := v.Args[0] + if l.Op != OpARMMULS { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(a) @@ -23331,7 +23439,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(SUBconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMPconst [c] x) yes no) for { v := b.Control @@ -23347,6 +23455,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) v0.AuxInt = c @@ -23356,7 +23467,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMPshiftLL x y [c]) yes no) for { v := b.Control @@ -23374,6 +23485,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMPshiftLL, types.TypeFlags) v0.AuxInt = c @@ -23384,7 +23498,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMPshiftRL x y [c]) yes no) for { v := b.Control @@ -23402,6 +23516,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRL, types.TypeFlags) v0.AuxInt = c @@ -23412,7 +23529,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMPshiftRA x y [c]) yes no) for { v := b.Control @@ -23430,6 +23547,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRA, types.TypeFlags) v0.AuxInt = c @@ -23440,7 +23560,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMPshiftLLreg x y z) yes no) for { v := b.Control @@ -23458,6 +23578,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMPshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -23468,7 +23591,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMPshiftRLreg x y z) yes no) for { v := b.Control @@ -23486,6 +23609,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -23496,7 +23622,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMPshiftRAreg x y z) yes no) for { v := b.Control @@ -23514,6 +23640,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -23524,7 +23653,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ADD x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMN x y) yes no) for { v := b.Control @@ -23541,6 +23670,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(x) @@ -23549,8 +23681,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (GE (CMPconst [0] (MULA x y a)) yes no) - // cond: + // match: (GE (CMPconst [0] l:(MULA x y a)) yes no) + // cond: l.Uses==1 // result: (GE (CMN a (MUL x y)) yes no) for { v := b.Control @@ -23560,14 +23692,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULA { + l := v.Args[0] + if l.Op != OpARMMULA { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(a) @@ -23580,7 +23715,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ADDconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMNconst [c] x) yes no) for { v := b.Control @@ -23596,6 +23731,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMNconst, types.TypeFlags) v0.AuxInt = c @@ -23605,7 +23743,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMNshiftLL x y [c]) yes no) for { v := b.Control @@ -23623,6 +23761,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMNshiftLL, types.TypeFlags) v0.AuxInt = c @@ -23633,7 +23774,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMNshiftRL x y [c]) yes no) for { v := b.Control @@ -23651,6 +23792,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRL, types.TypeFlags) v0.AuxInt = c @@ -23661,7 +23805,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMNshiftRA x y [c]) yes no) for { v := b.Control @@ -23679,6 +23823,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRA, types.TypeFlags) v0.AuxInt = c @@ -23689,7 +23836,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMNshiftLLreg x y z) yes no) for { v := b.Control @@ -23707,6 +23854,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMNshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -23717,7 +23867,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMNshiftRLreg x y z) yes no) for { v := b.Control @@ -23735,6 +23885,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -23745,7 +23898,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (CMNshiftRAreg x y z) yes no) for { v := b.Control @@ -23763,6 +23916,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -23773,7 +23929,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(AND x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TST x y) yes no) for { v := b.Control @@ -23790,6 +23946,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTST, types.TypeFlags) v0.AddArg(x) @@ -23799,7 +23958,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ANDconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TSTconst [c] x) yes no) for { v := b.Control @@ -23815,6 +23974,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTSTconst, types.TypeFlags) v0.AuxInt = c @@ -23824,7 +23986,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TSTshiftLL x y [c]) yes no) for { v := b.Control @@ -23842,6 +24004,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTSTshiftLL, types.TypeFlags) v0.AuxInt = c @@ -23852,7 +24017,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TSTshiftRL x y [c]) yes no) for { v := b.Control @@ -23870,6 +24035,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRL, types.TypeFlags) v0.AuxInt = c @@ -23880,7 +24048,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TSTshiftRA x y [c]) yes no) for { v := b.Control @@ -23898,6 +24066,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRA, types.TypeFlags) v0.AuxInt = c @@ -23908,7 +24079,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TSTshiftLLreg x y z) yes no) for { v := b.Control @@ -23926,6 +24097,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTSTshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -23936,7 +24110,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TSTshiftRLreg x y z) yes no) for { v := b.Control @@ -23954,6 +24128,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -23964,7 +24141,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TSTshiftRAreg x y z) yes no) for { v := b.Control @@ -23982,6 +24159,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -23992,7 +24172,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(XOR x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TEQ x y) yes no) for { v := b.Control @@ -24009,6 +24189,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTEQ, types.TypeFlags) v0.AddArg(x) @@ -24018,7 +24201,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(XORconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TEQconst [c] x) yes no) for { v := b.Control @@ -24034,6 +24217,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTEQconst, types.TypeFlags) v0.AuxInt = c @@ -24043,7 +24229,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TEQshiftLL x y [c]) yes no) for { v := b.Control @@ -24061,6 +24247,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTEQshiftLL, types.TypeFlags) v0.AuxInt = c @@ -24071,7 +24260,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TEQshiftRL x y [c]) yes no) for { v := b.Control @@ -24089,6 +24278,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRL, types.TypeFlags) v0.AuxInt = c @@ -24099,7 +24291,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TEQshiftRA x y [c]) yes no) for { v := b.Control @@ -24117,6 +24309,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRA, types.TypeFlags) v0.AuxInt = c @@ -24127,7 +24322,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TEQshiftLLreg x y z) yes no) for { v := b.Control @@ -24145,6 +24340,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTEQshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -24155,7 +24353,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TEQshiftRLreg x y z) yes no) for { v := b.Control @@ -24173,6 +24371,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -24183,7 +24384,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GE (TEQshiftRAreg x y z) yes no) for { v := b.Control @@ -24201,6 +24402,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -24294,7 +24498,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(SUB x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMP x y) yes no) for { v := b.Control @@ -24311,6 +24515,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(x) @@ -24319,8 +24526,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (GT (CMPconst [0] (MULS x y a)) yes no) - // cond: + // match: (GT (CMPconst [0] l:(MULS x y a)) yes no) + // cond: l.Uses==1 // result: (GT (CMP a (MUL x y)) yes no) for { v := b.Control @@ -24330,14 +24537,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULS { + l := v.Args[0] + if l.Op != OpARMMULS { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(a) @@ -24350,7 +24560,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(SUBconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMPconst [c] x) yes no) for { v := b.Control @@ -24366,6 +24576,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) v0.AuxInt = c @@ -24375,7 +24588,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMPshiftLL x y [c]) yes no) for { v := b.Control @@ -24393,6 +24606,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMPshiftLL, types.TypeFlags) v0.AuxInt = c @@ -24403,7 +24619,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMPshiftRL x y [c]) yes no) for { v := b.Control @@ -24421,6 +24637,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMPshiftRL, types.TypeFlags) v0.AuxInt = c @@ -24431,7 +24650,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMPshiftRA x y [c]) yes no) for { v := b.Control @@ -24449,6 +24668,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMPshiftRA, types.TypeFlags) v0.AuxInt = c @@ -24459,7 +24681,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMPshiftLLreg x y z) yes no) for { v := b.Control @@ -24477,6 +24699,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMPshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -24487,7 +24712,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMPshiftRLreg x y z) yes no) for { v := b.Control @@ -24505,6 +24730,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMPshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -24515,7 +24743,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMPshiftRAreg x y z) yes no) for { v := b.Control @@ -24533,6 +24761,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMPshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -24543,7 +24774,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ADD x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMN x y) yes no) for { v := b.Control @@ -24560,6 +24791,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(x) @@ -24569,7 +24803,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ADDconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMNconst [c] x) yes no) for { v := b.Control @@ -24585,6 +24819,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMNconst, types.TypeFlags) v0.AuxInt = c @@ -24594,7 +24831,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMNshiftLL x y [c]) yes no) for { v := b.Control @@ -24612,6 +24849,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMNshiftLL, types.TypeFlags) v0.AuxInt = c @@ -24622,7 +24862,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMNshiftRL x y [c]) yes no) for { v := b.Control @@ -24640,6 +24880,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMNshiftRL, types.TypeFlags) v0.AuxInt = c @@ -24650,7 +24893,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMNshiftRA x y [c]) yes no) for { v := b.Control @@ -24668,6 +24911,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMNshiftRA, types.TypeFlags) v0.AuxInt = c @@ -24678,7 +24924,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMNshiftLLreg x y z) yes no) for { v := b.Control @@ -24696,6 +24942,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMNshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -24706,7 +24955,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMNshiftRLreg x y z) yes no) for { v := b.Control @@ -24724,6 +24973,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMNshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -24734,7 +24986,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (CMNshiftRAreg x y z) yes no) for { v := b.Control @@ -24752,6 +25004,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMNshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -24762,7 +25017,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(AND x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TST x y) yes no) for { v := b.Control @@ -24779,6 +25034,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTST, types.TypeFlags) v0.AddArg(x) @@ -24787,8 +25045,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (GT (CMPconst [0] (MULA x y a)) yes no) - // cond: + // match: (GT (CMPconst [0] l:(MULA x y a)) yes no) + // cond: l.Uses==1 // result: (GT (CMN a (MUL x y)) yes no) for { v := b.Control @@ -24798,14 +25056,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULA { + l := v.Args[0] + if l.Op != OpARMMULA { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(a) @@ -24818,7 +25079,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ANDconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TSTconst [c] x) yes no) for { v := b.Control @@ -24834,6 +25095,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTSTconst, types.TypeFlags) v0.AuxInt = c @@ -24843,7 +25107,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TSTshiftLL x y [c]) yes no) for { v := b.Control @@ -24861,6 +25125,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTSTshiftLL, types.TypeFlags) v0.AuxInt = c @@ -24871,7 +25138,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TSTshiftRL x y [c]) yes no) for { v := b.Control @@ -24889,6 +25156,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTSTshiftRL, types.TypeFlags) v0.AuxInt = c @@ -24899,7 +25169,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TSTshiftRA x y [c]) yes no) for { v := b.Control @@ -24917,6 +25187,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTSTshiftRA, types.TypeFlags) v0.AuxInt = c @@ -24927,7 +25200,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TSTshiftLLreg x y z) yes no) for { v := b.Control @@ -24945,6 +25218,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTSTshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -24955,7 +25231,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TSTshiftRLreg x y z) yes no) for { v := b.Control @@ -24973,6 +25249,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTSTshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -24983,7 +25262,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TSTshiftRAreg x y z) yes no) for { v := b.Control @@ -25001,6 +25280,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTSTshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -25011,7 +25293,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(XOR x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TEQ x y) yes no) for { v := b.Control @@ -25028,6 +25310,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTEQ, types.TypeFlags) v0.AddArg(x) @@ -25037,7 +25322,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(XORconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TEQconst [c] x) yes no) for { v := b.Control @@ -25053,6 +25338,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTEQconst, types.TypeFlags) v0.AuxInt = c @@ -25062,7 +25350,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TEQshiftLL x y [c]) yes no) for { v := b.Control @@ -25080,6 +25368,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTEQshiftLL, types.TypeFlags) v0.AuxInt = c @@ -25090,7 +25381,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TEQshiftRL x y [c]) yes no) for { v := b.Control @@ -25108,6 +25399,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTEQshiftRL, types.TypeFlags) v0.AuxInt = c @@ -25118,7 +25412,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TEQshiftRA x y [c]) yes no) for { v := b.Control @@ -25136,6 +25430,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTEQshiftRA, types.TypeFlags) v0.AuxInt = c @@ -25146,7 +25443,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TEQshiftLLreg x y z) yes no) for { v := b.Control @@ -25164,6 +25461,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTEQshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -25174,7 +25474,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TEQshiftRLreg x y z) yes no) for { v := b.Control @@ -25192,6 +25492,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTEQshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -25202,7 +25505,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (GT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (GT (TEQshiftRAreg x y z) yes no) for { v := b.Control @@ -25220,6 +25523,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMGT v0 := b.NewValue0(v.Pos, OpARMTEQshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -25468,7 +25774,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(SUB x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMP x y) yes no) for { v := b.Control @@ -25485,6 +25791,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(x) @@ -25493,8 +25802,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (LE (CMPconst [0] (MULS x y a)) yes no) - // cond: + // match: (LE (CMPconst [0] l:(MULS x y a)) yes no) + // cond: l.Uses==1 // result: (LE (CMP a (MUL x y)) yes no) for { v := b.Control @@ -25504,14 +25813,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULS { + l := v.Args[0] + if l.Op != OpARMMULS { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(a) @@ -25524,7 +25836,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(SUBconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMPconst [c] x) yes no) for { v := b.Control @@ -25540,6 +25852,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) v0.AuxInt = c @@ -25549,7 +25864,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMPshiftLL x y [c]) yes no) for { v := b.Control @@ -25567,6 +25882,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMPshiftLL, types.TypeFlags) v0.AuxInt = c @@ -25577,7 +25895,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMPshiftRL x y [c]) yes no) for { v := b.Control @@ -25595,6 +25913,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRL, types.TypeFlags) v0.AuxInt = c @@ -25605,7 +25926,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMPshiftRA x y [c]) yes no) for { v := b.Control @@ -25623,6 +25944,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRA, types.TypeFlags) v0.AuxInt = c @@ -25633,7 +25957,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMPshiftLLreg x y z) yes no) for { v := b.Control @@ -25651,6 +25975,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMPshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -25661,7 +25988,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMPshiftRLreg x y z) yes no) for { v := b.Control @@ -25679,6 +26006,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -25689,7 +26019,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMPshiftRAreg x y z) yes no) for { v := b.Control @@ -25707,6 +26037,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -25717,7 +26050,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ADD x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMN x y) yes no) for { v := b.Control @@ -25734,6 +26067,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(x) @@ -25742,8 +26078,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (LE (CMPconst [0] (MULA x y a)) yes no) - // cond: + // match: (LE (CMPconst [0] l:(MULA x y a)) yes no) + // cond: l.Uses==1 // result: (LE (CMN a (MUL x y)) yes no) for { v := b.Control @@ -25753,14 +26089,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULA { + l := v.Args[0] + if l.Op != OpARMMULA { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(a) @@ -25773,7 +26112,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ADDconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMNconst [c] x) yes no) for { v := b.Control @@ -25789,6 +26128,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMNconst, types.TypeFlags) v0.AuxInt = c @@ -25798,7 +26140,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMNshiftLL x y [c]) yes no) for { v := b.Control @@ -25816,6 +26158,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMNshiftLL, types.TypeFlags) v0.AuxInt = c @@ -25826,7 +26171,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMNshiftRL x y [c]) yes no) for { v := b.Control @@ -25844,6 +26189,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRL, types.TypeFlags) v0.AuxInt = c @@ -25854,7 +26202,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMNshiftRA x y [c]) yes no) for { v := b.Control @@ -25872,6 +26220,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRA, types.TypeFlags) v0.AuxInt = c @@ -25882,7 +26233,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMNshiftLLreg x y z) yes no) for { v := b.Control @@ -25900,6 +26251,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMNshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -25910,7 +26264,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMNshiftRLreg x y z) yes no) for { v := b.Control @@ -25928,6 +26282,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -25938,7 +26295,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (CMNshiftRAreg x y z) yes no) for { v := b.Control @@ -25956,6 +26313,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -25966,7 +26326,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(AND x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TST x y) yes no) for { v := b.Control @@ -25983,6 +26343,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTST, types.TypeFlags) v0.AddArg(x) @@ -25992,7 +26355,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ANDconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TSTconst [c] x) yes no) for { v := b.Control @@ -26008,6 +26371,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTSTconst, types.TypeFlags) v0.AuxInt = c @@ -26017,7 +26383,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TSTshiftLL x y [c]) yes no) for { v := b.Control @@ -26035,6 +26401,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTSTshiftLL, types.TypeFlags) v0.AuxInt = c @@ -26045,7 +26414,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TSTshiftRL x y [c]) yes no) for { v := b.Control @@ -26063,6 +26432,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRL, types.TypeFlags) v0.AuxInt = c @@ -26073,7 +26445,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TSTshiftRA x y [c]) yes no) for { v := b.Control @@ -26091,6 +26463,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRA, types.TypeFlags) v0.AuxInt = c @@ -26101,7 +26476,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TSTshiftLLreg x y z) yes no) for { v := b.Control @@ -26119,6 +26494,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTSTshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -26129,7 +26507,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TSTshiftRLreg x y z) yes no) for { v := b.Control @@ -26147,6 +26525,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -26157,7 +26538,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TSTshiftRAreg x y z) yes no) for { v := b.Control @@ -26175,6 +26556,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -26185,7 +26569,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(XOR x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TEQ x y) yes no) for { v := b.Control @@ -26202,6 +26586,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTEQ, types.TypeFlags) v0.AddArg(x) @@ -26211,7 +26598,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(XORconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TEQconst [c] x) yes no) for { v := b.Control @@ -26227,6 +26614,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTEQconst, types.TypeFlags) v0.AuxInt = c @@ -26236,7 +26626,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TEQshiftLL x y [c]) yes no) for { v := b.Control @@ -26254,6 +26644,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTEQshiftLL, types.TypeFlags) v0.AuxInt = c @@ -26264,7 +26657,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TEQshiftRL x y [c]) yes no) for { v := b.Control @@ -26282,6 +26675,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRL, types.TypeFlags) v0.AuxInt = c @@ -26292,7 +26688,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TEQshiftRA x y [c]) yes no) for { v := b.Control @@ -26310,6 +26706,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRA, types.TypeFlags) v0.AuxInt = c @@ -26320,7 +26719,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TEQshiftLLreg x y z) yes no) for { v := b.Control @@ -26338,6 +26737,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTEQshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -26348,7 +26750,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TEQshiftRLreg x y z) yes no) for { v := b.Control @@ -26366,6 +26768,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -26376,7 +26781,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LE (TEQshiftRAreg x y z) yes no) for { v := b.Control @@ -26394,6 +26799,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -26487,7 +26895,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(SUB x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMP x y) yes no) for { v := b.Control @@ -26504,6 +26912,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(x) @@ -26512,8 +26923,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (LT (CMPconst [0] (MULS x y a)) yes no) - // cond: + // match: (LT (CMPconst [0] l:(MULS x y a)) yes no) + // cond: l.Uses==1 // result: (LT (CMP a (MUL x y)) yes no) for { v := b.Control @@ -26523,14 +26934,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULS { + l := v.Args[0] + if l.Op != OpARMMULS { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(a) @@ -26543,7 +26957,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(SUBconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMPconst [c] x) yes no) for { v := b.Control @@ -26559,6 +26973,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) v0.AuxInt = c @@ -26568,7 +26985,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMPshiftLL x y [c]) yes no) for { v := b.Control @@ -26586,6 +27003,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMPshiftLL, types.TypeFlags) v0.AuxInt = c @@ -26596,7 +27016,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMPshiftRL x y [c]) yes no) for { v := b.Control @@ -26614,6 +27034,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMPshiftRL, types.TypeFlags) v0.AuxInt = c @@ -26624,7 +27047,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMPshiftRA x y [c]) yes no) for { v := b.Control @@ -26642,6 +27065,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMPshiftRA, types.TypeFlags) v0.AuxInt = c @@ -26652,7 +27078,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMPshiftLLreg x y z) yes no) for { v := b.Control @@ -26670,6 +27096,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMPshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -26680,7 +27109,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMPshiftRLreg x y z) yes no) for { v := b.Control @@ -26698,6 +27127,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMPshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -26708,7 +27140,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMPshiftRAreg x y z) yes no) for { v := b.Control @@ -26726,6 +27158,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMPshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -26736,7 +27171,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ADD x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMN x y) yes no) for { v := b.Control @@ -26753,6 +27188,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(x) @@ -26761,8 +27199,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (LT (CMPconst [0] (MULA x y a)) yes no) - // cond: + // match: (LT (CMPconst [0] l:(MULA x y a)) yes no) + // cond: l.Uses==1 // result: (LT (CMN a (MUL x y)) yes no) for { v := b.Control @@ -26772,14 +27210,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULA { + l := v.Args[0] + if l.Op != OpARMMULA { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(a) @@ -26792,7 +27233,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ADDconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMNconst [c] x) yes no) for { v := b.Control @@ -26808,6 +27249,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMNconst, types.TypeFlags) v0.AuxInt = c @@ -26817,7 +27261,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMNshiftLL x y [c]) yes no) for { v := b.Control @@ -26835,6 +27279,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMNshiftLL, types.TypeFlags) v0.AuxInt = c @@ -26845,7 +27292,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMNshiftRL x y [c]) yes no) for { v := b.Control @@ -26863,6 +27310,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMNshiftRL, types.TypeFlags) v0.AuxInt = c @@ -26873,7 +27323,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMNshiftRA x y [c]) yes no) for { v := b.Control @@ -26891,6 +27341,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMNshiftRA, types.TypeFlags) v0.AuxInt = c @@ -26901,7 +27354,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMNshiftLLreg x y z) yes no) for { v := b.Control @@ -26919,6 +27372,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMNshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -26929,7 +27385,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMNshiftRLreg x y z) yes no) for { v := b.Control @@ -26947,6 +27403,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMNshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -26957,7 +27416,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (CMNshiftRAreg x y z) yes no) for { v := b.Control @@ -26975,6 +27434,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMCMNshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -26985,7 +27447,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(AND x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TST x y) yes no) for { v := b.Control @@ -27002,6 +27464,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTST, types.TypeFlags) v0.AddArg(x) @@ -27011,7 +27476,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ANDconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TSTconst [c] x) yes no) for { v := b.Control @@ -27027,6 +27492,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTSTconst, types.TypeFlags) v0.AuxInt = c @@ -27036,7 +27504,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TSTshiftLL x y [c]) yes no) for { v := b.Control @@ -27054,6 +27522,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTSTshiftLL, types.TypeFlags) v0.AuxInt = c @@ -27064,7 +27535,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TSTshiftRL x y [c]) yes no) for { v := b.Control @@ -27082,6 +27553,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTSTshiftRL, types.TypeFlags) v0.AuxInt = c @@ -27092,7 +27566,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TSTshiftRA x y [c]) yes no) for { v := b.Control @@ -27110,6 +27584,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTSTshiftRA, types.TypeFlags) v0.AuxInt = c @@ -27120,7 +27597,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TSTshiftLLreg x y z) yes no) for { v := b.Control @@ -27138,6 +27615,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTSTshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -27148,7 +27628,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TSTshiftRLreg x y z) yes no) for { v := b.Control @@ -27166,6 +27646,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTSTshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -27176,7 +27659,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TSTshiftRAreg x y z) yes no) for { v := b.Control @@ -27194,6 +27677,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTSTshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -27204,7 +27690,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(XOR x y)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TEQ x y) yes no) for { v := b.Control @@ -27221,6 +27707,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTEQ, types.TypeFlags) v0.AddArg(x) @@ -27230,7 +27719,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(XORconst [c] x)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TEQconst [c] x) yes no) for { v := b.Control @@ -27246,6 +27735,9 @@ func rewriteBlockARM(b *Block) bool { } c := l.AuxInt x := l.Args[0] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTEQconst, types.TypeFlags) v0.AuxInt = c @@ -27255,7 +27747,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(XORshiftLL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TEQshiftLL x y [c]) yes no) for { v := b.Control @@ -27273,6 +27765,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTEQshiftLL, types.TypeFlags) v0.AuxInt = c @@ -27283,7 +27778,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(XORshiftRL x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TEQshiftRL x y [c]) yes no) for { v := b.Control @@ -27301,6 +27796,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTEQshiftRL, types.TypeFlags) v0.AuxInt = c @@ -27311,7 +27809,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(XORshiftRA x y [c])) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TEQshiftRA x y [c]) yes no) for { v := b.Control @@ -27329,6 +27827,9 @@ func rewriteBlockARM(b *Block) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTEQshiftRA, types.TypeFlags) v0.AuxInt = c @@ -27339,7 +27840,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TEQshiftLLreg x y z) yes no) for { v := b.Control @@ -27357,6 +27858,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTEQshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -27367,7 +27871,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TEQshiftRLreg x y z) yes no) for { v := b.Control @@ -27385,7 +27889,10 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] - b.Kind = BlockARMLT + if !(l.Uses == 1) { + break + } + b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTEQshiftRLreg, types.TypeFlags) v0.AddArg(x) v0.AddArg(y) @@ -27395,7 +27902,7 @@ func rewriteBlockARM(b *Block) bool { return true } // match: (LT (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) - // cond: + // cond: l.Uses==1 // result: (LT (TEQshiftRAreg x y z) yes no) for { v := b.Control @@ -27413,6 +27920,9 @@ func rewriteBlockARM(b *Block) bool { x := l.Args[0] y := l.Args[1] z := l.Args[2] + if !(l.Uses == 1) { + break + } b.Kind = BlockARMLT v0 := b.NewValue0(v.Pos, OpARMTEQshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -27713,8 +28223,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (SUB x y)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(SUB x y)) yes no) + // cond: l.Uses==1 // result: (NE (CMP x y) yes no) for { v := b.Control @@ -27724,13 +28234,16 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUB { + l := v.Args[0] + if l.Op != OpARMSUB { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(x) @@ -27739,8 +28252,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (MULS x y a)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(MULS x y a)) yes no) + // cond: l.Uses==1 // result: (NE (CMP a (MUL x y)) yes no) for { v := b.Control @@ -27750,14 +28263,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULS { + l := v.Args[0] + if l.Op != OpARMMULS { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMP, types.TypeFlags) v0.AddArg(a) @@ -27769,8 +28285,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (SUBconst [c] x)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(SUBconst [c] x)) yes no) + // cond: l.Uses==1 // result: (NE (CMPconst [c] x) yes no) for { v := b.Control @@ -27780,12 +28296,15 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBconst { + l := v.Args[0] + if l.Op != OpARMSUBconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMPconst, types.TypeFlags) v0.AuxInt = c @@ -27794,8 +28313,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (SUBshiftLL x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(SUBshiftLL x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (CMPshiftLL x y [c]) yes no) for { v := b.Control @@ -27805,14 +28324,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftLL { + l := v.Args[0] + if l.Op != OpARMSUBshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMPshiftLL, types.TypeFlags) v0.AuxInt = c @@ -27822,8 +28344,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (SUBshiftRL x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(SUBshiftRL x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (CMPshiftRL x y [c]) yes no) for { v := b.Control @@ -27833,14 +28355,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftRL { + l := v.Args[0] + if l.Op != OpARMSUBshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRL, types.TypeFlags) v0.AuxInt = c @@ -27850,8 +28375,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (SUBshiftRA x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(SUBshiftRA x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (CMPshiftRA x y [c]) yes no) for { v := b.Control @@ -27861,14 +28386,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftRA { + l := v.Args[0] + if l.Op != OpARMSUBshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRA, types.TypeFlags) v0.AuxInt = c @@ -27878,8 +28406,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (SUBshiftLLreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(SUBshiftLLreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (CMPshiftLLreg x y z) yes no) for { v := b.Control @@ -27889,14 +28417,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftLLreg { + l := v.Args[0] + if l.Op != OpARMSUBshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMPshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -27906,8 +28437,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (SUBshiftRLreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(SUBshiftRLreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (CMPshiftRLreg x y z) yes no) for { v := b.Control @@ -27917,14 +28448,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftRLreg { + l := v.Args[0] + if l.Op != OpARMSUBshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -27934,8 +28468,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (SUBshiftRAreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(SUBshiftRAreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (CMPshiftRAreg x y z) yes no) for { v := b.Control @@ -27945,14 +28479,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMSUBshiftRAreg { + l := v.Args[0] + if l.Op != OpARMSUBshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMPshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -27962,8 +28499,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ADD x y)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ADD x y)) yes no) + // cond: l.Uses==1 // result: (NE (CMN x y) yes no) for { v := b.Control @@ -27973,13 +28510,16 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADD { + l := v.Args[0] + if l.Op != OpARMADD { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(x) @@ -27988,8 +28528,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (MULA x y a)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(MULA x y a)) yes no) + // cond: l.Uses==1 // result: (NE (CMN a (MUL x y)) yes no) for { v := b.Control @@ -27999,14 +28539,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMMULA { + l := v.Args[0] + if l.Op != OpARMMULA { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + a := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - a := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMN, types.TypeFlags) v0.AddArg(a) @@ -28018,8 +28561,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ADDconst [c] x)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ADDconst [c] x)) yes no) + // cond: l.Uses==1 // result: (NE (CMNconst [c] x) yes no) for { v := b.Control @@ -28029,12 +28572,15 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDconst { + l := v.Args[0] + if l.Op != OpARMADDconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMNconst, types.TypeFlags) v0.AuxInt = c @@ -28043,8 +28589,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ADDshiftLL x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ADDshiftLL x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (CMNshiftLL x y [c]) yes no) for { v := b.Control @@ -28054,14 +28600,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftLL { + l := v.Args[0] + if l.Op != OpARMADDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMNshiftLL, types.TypeFlags) v0.AuxInt = c @@ -28071,8 +28620,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ADDshiftRL x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ADDshiftRL x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (CMNshiftRL x y [c]) yes no) for { v := b.Control @@ -28082,14 +28631,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftRL { + l := v.Args[0] + if l.Op != OpARMADDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRL, types.TypeFlags) v0.AuxInt = c @@ -28099,8 +28651,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ADDshiftRA x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ADDshiftRA x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (CMNshiftRA x y [c]) yes no) for { v := b.Control @@ -28110,14 +28662,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftRA { + l := v.Args[0] + if l.Op != OpARMADDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRA, types.TypeFlags) v0.AuxInt = c @@ -28127,8 +28682,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ADDshiftLLreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ADDshiftLLreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (CMNshiftLLreg x y z) yes no) for { v := b.Control @@ -28138,14 +28693,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftLLreg { + l := v.Args[0] + if l.Op != OpARMADDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMNshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -28155,8 +28713,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ADDshiftRLreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ADDshiftRLreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (CMNshiftRLreg x y z) yes no) for { v := b.Control @@ -28166,14 +28724,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftRLreg { + l := v.Args[0] + if l.Op != OpARMADDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -28183,8 +28744,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ADDshiftRAreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ADDshiftRAreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (CMNshiftRAreg x y z) yes no) for { v := b.Control @@ -28194,14 +28755,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMADDshiftRAreg { + l := v.Args[0] + if l.Op != OpARMADDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMCMNshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -28211,8 +28775,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (AND x y)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(AND x y)) yes no) + // cond: l.Uses==1 // result: (NE (TST x y) yes no) for { v := b.Control @@ -28222,13 +28786,16 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMAND { + l := v.Args[0] + if l.Op != OpARMAND { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTST, types.TypeFlags) v0.AddArg(x) @@ -28237,8 +28804,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ANDconst [c] x)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ANDconst [c] x)) yes no) + // cond: l.Uses==1 // result: (NE (TSTconst [c] x) yes no) for { v := b.Control @@ -28248,12 +28815,15 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDconst { + l := v.Args[0] + if l.Op != OpARMANDconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTSTconst, types.TypeFlags) v0.AuxInt = c @@ -28262,8 +28832,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ANDshiftLL x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ANDshiftLL x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (TSTshiftLL x y [c]) yes no) for { v := b.Control @@ -28273,14 +28843,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftLL { + l := v.Args[0] + if l.Op != OpARMANDshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTSTshiftLL, types.TypeFlags) v0.AuxInt = c @@ -28290,8 +28863,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ANDshiftRL x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ANDshiftRL x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (TSTshiftRL x y [c]) yes no) for { v := b.Control @@ -28301,14 +28874,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftRL { + l := v.Args[0] + if l.Op != OpARMANDshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRL, types.TypeFlags) v0.AuxInt = c @@ -28318,8 +28894,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ANDshiftRA x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ANDshiftRA x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (TSTshiftRA x y [c]) yes no) for { v := b.Control @@ -28329,14 +28905,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftRA { + l := v.Args[0] + if l.Op != OpARMANDshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRA, types.TypeFlags) v0.AuxInt = c @@ -28346,8 +28925,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ANDshiftLLreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ANDshiftLLreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (TSTshiftLLreg x y z) yes no) for { v := b.Control @@ -28357,14 +28936,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftLLreg { + l := v.Args[0] + if l.Op != OpARMANDshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTSTshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -28374,8 +28956,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ANDshiftRLreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ANDshiftRLreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (TSTshiftRLreg x y z) yes no) for { v := b.Control @@ -28385,14 +28967,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftRLreg { + l := v.Args[0] + if l.Op != OpARMANDshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -28402,8 +28987,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (ANDshiftRAreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(ANDshiftRAreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (TSTshiftRAreg x y z) yes no) for { v := b.Control @@ -28413,14 +28998,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMANDshiftRAreg { + l := v.Args[0] + if l.Op != OpARMANDshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTSTshiftRAreg, types.TypeFlags) v0.AddArg(x) @@ -28430,8 +29018,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (XOR x y)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(XOR x y)) yes no) + // cond: l.Uses==1 // result: (NE (TEQ x y) yes no) for { v := b.Control @@ -28441,13 +29029,16 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXOR { + l := v.Args[0] + if l.Op != OpARMXOR { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTEQ, types.TypeFlags) v0.AddArg(x) @@ -28456,8 +29047,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (XORconst [c] x)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(XORconst [c] x)) yes no) + // cond: l.Uses==1 // result: (NE (TEQconst [c] x) yes no) for { v := b.Control @@ -28467,12 +29058,15 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORconst { + l := v.Args[0] + if l.Op != OpARMXORconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTEQconst, types.TypeFlags) v0.AuxInt = c @@ -28481,8 +29075,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (XORshiftLL x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(XORshiftLL x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (TEQshiftLL x y [c]) yes no) for { v := b.Control @@ -28492,14 +29086,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftLL { + l := v.Args[0] + if l.Op != OpARMXORshiftLL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTEQshiftLL, types.TypeFlags) v0.AuxInt = c @@ -28509,8 +29106,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (XORshiftRL x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(XORshiftRL x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (TEQshiftRL x y [c]) yes no) for { v := b.Control @@ -28520,14 +29117,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftRL { + l := v.Args[0] + if l.Op != OpARMXORshiftRL { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRL, types.TypeFlags) v0.AuxInt = c @@ -28537,8 +29137,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (XORshiftRA x y [c])) yes no) - // cond: + // match: (NE (CMPconst [0] l:(XORshiftRA x y [c])) yes no) + // cond: l.Uses==1 // result: (NE (TEQshiftRA x y [c]) yes no) for { v := b.Control @@ -28548,14 +29148,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftRA { + l := v.Args[0] + if l.Op != OpARMXORshiftRA { + break + } + c := l.AuxInt + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRA, types.TypeFlags) v0.AuxInt = c @@ -28565,8 +29168,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (XORshiftLLreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(XORshiftLLreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (TEQshiftLLreg x y z) yes no) for { v := b.Control @@ -28576,14 +29179,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftLLreg { + l := v.Args[0] + if l.Op != OpARMXORshiftLLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTEQshiftLLreg, types.TypeFlags) v0.AddArg(x) @@ -28593,8 +29199,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (XORshiftRLreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(XORshiftRLreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (TEQshiftRLreg x y z) yes no) for { v := b.Control @@ -28604,14 +29210,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftRLreg { + l := v.Args[0] + if l.Op != OpARMXORshiftRLreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRLreg, types.TypeFlags) v0.AddArg(x) @@ -28621,8 +29230,8 @@ func rewriteBlockARM(b *Block) bool { b.Aux = nil return true } - // match: (NE (CMPconst [0] (XORshiftRAreg x y z)) yes no) - // cond: + // match: (NE (CMPconst [0] l:(XORshiftRAreg x y z)) yes no) + // cond: l.Uses==1 // result: (NE (TEQshiftRAreg x y z) yes no) for { v := b.Control @@ -28632,14 +29241,17 @@ func rewriteBlockARM(b *Block) bool { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != OpARMXORshiftRAreg { + l := v.Args[0] + if l.Op != OpARMXORshiftRAreg { + break + } + _ = l.Args[2] + x := l.Args[0] + y := l.Args[1] + z := l.Args[2] + if !(l.Uses == 1) { break } - _ = v_0.Args[2] - x := v_0.Args[0] - y := v_0.Args[1] - z := v_0.Args[2] b.Kind = BlockARMNE v0 := b.NewValue0(v.Pos, OpARMTEQshiftRAreg, types.TypeFlags) v0.AddArg(x) diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go index 8475b130c2068..50c9de7626c95 100644 --- a/test/codegen/comparisons.go +++ b/test/codegen/comparisons.go @@ -158,9 +158,11 @@ func CmpZero4(a int64, ptr *int) { } } -func CmpToZero(a, b, d int32) int32 { +func CmpToZero(a, b, d int32, e, f int64) int32 { // arm:`TST`,-`AND` // arm64:`TSTW`,-`AND` + // 386:`TESTL`,-`ANDL` + // amd64:`TESTL`,-`ANDL` c0 := a&b < 0 // arm:`CMN`,-`ADD` // arm64:`CMNW`,-`ADD` @@ -168,14 +170,17 @@ func CmpToZero(a, b, d int32) int32 { // arm:`TEQ`,-`XOR` c2 := a^b < 0 // arm64:`TST`,-`AND` - c3 := int64(a)&int64(b) < 0 + // amd64:`TESTQ`,-`ANDQ` + c3 := e&f < 0 // arm64:`CMN`,-`ADD` - c4 := int64(a)+int64(b) < 0 - // not optimized to CMNW/CMN due to further use of b+d + c4 := e+f < 0 + // not optimized to single CMNW/CMN due to further use of b+d // arm64:`ADD`,-`CMNW` + // arm:`ADD`,-`CMN` c5 := b+d == 0 - // not optimized to TSTW/TST due to further use of a&d + // not optimized to single TSTW/TST due to further use of a&d // arm64:`AND`,-`TSTW` + // arm:`AND`,-`TST` c6 := a&d >= 0 if c0 { return 1 From 48af3a8be593d349d7af8e831e26b5b2798a464e Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Mon, 3 Sep 2018 12:14:31 +0100 Subject: [PATCH 0307/1663] cmd/compile: fix store-to-load forwarding of 32-bit sNaNs Signalling NaNs were being converted to quiet NaNs during constant propagation through integer <-> float store-to-load forwarding. This occurs because we store float32 constants as float64 values and CPU hardware 'quietens' NaNs during conversion between the two. Eventually we want to move to using float32 values to store float32 constants, however this will be a big change since both the compiler and the assembler expect float64 values. So for now this is a small change that will fix the immediate issue. Fixes #27193. Change-Id: Iac54bd8c13abe26f9396712bc71f9b396f842724 Reviewed-on: https://go-review.googlesource.com/132956 Run-TryBot: Michael Munday TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/float_test.go | 111 ++++++++++++++++++ src/cmd/compile/internal/ssa/check.go | 15 ++- .../compile/internal/ssa/gen/generic.rules | 4 +- src/cmd/compile/internal/ssa/rewrite.go | 32 +++++ .../compile/internal/ssa/rewritegeneric.go | 8 +- 5 files changed, 159 insertions(+), 11 deletions(-) diff --git a/src/cmd/compile/internal/gc/float_test.go b/src/cmd/compile/internal/gc/float_test.go index 4cb9532e556fd..c0a8cfc89e6d7 100644 --- a/src/cmd/compile/internal/gc/float_test.go +++ b/src/cmd/compile/internal/gc/float_test.go @@ -362,6 +362,117 @@ func TestFloatConvertFolded(t *testing.T) { } } +func TestFloat32StoreToLoadConstantFold(t *testing.T) { + // Test that math.Float32{,from}bits constant fold correctly. + // In particular we need to be careful that signalling NaN (sNaN) values + // are not converted to quiet NaN (qNaN) values during compilation. + // See issue #27193 for more information. + + // signalling NaNs + { + const nan = uint32(0x7f800001) // sNaN + if x := math.Float32bits(math.Float32frombits(nan)); x != nan { + t.Errorf("got %#x, want %#x", x, nan) + } + } + { + const nan = uint32(0x7fbfffff) // sNaN + if x := math.Float32bits(math.Float32frombits(nan)); x != nan { + t.Errorf("got %#x, want %#x", x, nan) + } + } + { + const nan = uint32(0xff800001) // sNaN + if x := math.Float32bits(math.Float32frombits(nan)); x != nan { + t.Errorf("got %#x, want %#x", x, nan) + } + } + { + const nan = uint32(0xffbfffff) // sNaN + if x := math.Float32bits(math.Float32frombits(nan)); x != nan { + t.Errorf("got %#x, want %#x", x, nan) + } + } + + // quiet NaNs + { + const nan = uint32(0x7fc00000) // qNaN + if x := math.Float32bits(math.Float32frombits(nan)); x != nan { + t.Errorf("got %#x, want %#x", x, nan) + } + } + { + const nan = uint32(0x7fffffff) // qNaN + if x := math.Float32bits(math.Float32frombits(nan)); x != nan { + t.Errorf("got %#x, want %#x", x, nan) + } + } + { + const nan = uint32(0x8fc00000) // qNaN + if x := math.Float32bits(math.Float32frombits(nan)); x != nan { + t.Errorf("got %#x, want %#x", x, nan) + } + } + { + const nan = uint32(0x8fffffff) // qNaN + if x := math.Float32bits(math.Float32frombits(nan)); x != nan { + t.Errorf("got %#x, want %#x", x, nan) + } + } + + // infinities + { + const inf = uint32(0x7f800000) // +∞ + if x := math.Float32bits(math.Float32frombits(inf)); x != inf { + t.Errorf("got %#x, want %#x", x, inf) + } + } + { + const negInf = uint32(0xff800000) // -∞ + if x := math.Float32bits(math.Float32frombits(negInf)); x != negInf { + t.Errorf("got %#x, want %#x", x, negInf) + } + } + + // numbers + { + const zero = uint32(0) // +0.0 + if x := math.Float32bits(math.Float32frombits(zero)); x != zero { + t.Errorf("got %#x, want %#x", x, zero) + } + } + { + const negZero = uint32(1 << 31) // -0.0 + if x := math.Float32bits(math.Float32frombits(negZero)); x != negZero { + t.Errorf("got %#x, want %#x", x, negZero) + } + } + { + const one = uint32(0x3f800000) // 1.0 + if x := math.Float32bits(math.Float32frombits(one)); x != one { + t.Errorf("got %#x, want %#x", x, one) + } + } + { + const negOne = uint32(0xbf800000) // -1.0 + if x := math.Float32bits(math.Float32frombits(negOne)); x != negOne { + t.Errorf("got %#x, want %#x", x, negOne) + } + } + { + const frac = uint32(0x3fc00000) // +1.5 + if x := math.Float32bits(math.Float32frombits(frac)); x != frac { + t.Errorf("got %#x, want %#x", x, frac) + } + } + { + const negFrac = uint32(0xbfc00000) // -1.5 + if x := math.Float32bits(math.Float32frombits(negFrac)); x != negFrac { + t.Errorf("got %#x, want %#x", x, negFrac) + } + } +} + var sinkFloat float64 func BenchmarkMul2(b *testing.B) { diff --git a/src/cmd/compile/internal/ssa/check.go b/src/cmd/compile/internal/ssa/check.go index 556e7fb7f75d0..13e8d7b3de888 100644 --- a/src/cmd/compile/internal/ssa/check.go +++ b/src/cmd/compile/internal/ssa/check.go @@ -6,6 +6,7 @@ package ssa import ( "math" + "math/bits" ) // checkFunc checks invariants of f. @@ -146,7 +147,7 @@ func checkFunc(f *Func) { // AuxInt must be zero, so leave canHaveAuxInt set to false. case auxFloat32: canHaveAuxInt = true - if !isExactFloat32(v) { + if !isExactFloat32(v.AuxFloat()) { f.Fatalf("value %v has an AuxInt value that is not an exact float32", v) } case auxString, auxSym, auxTyp: @@ -508,8 +509,12 @@ func domCheck(f *Func, sdom SparseTree, x, y *Block) bool { return sdom.isAncestorEq(x, y) } -// isExactFloat32 reports whether v has an AuxInt that can be exactly represented as a float32. -func isExactFloat32(v *Value) bool { - x := v.AuxFloat() - return math.Float64bits(x) == math.Float64bits(float64(float32(x))) +// isExactFloat32 reports whether x can be exactly represented as a float32. +func isExactFloat32(x float64) bool { + // Check the mantissa is in range. + if bits.TrailingZeros64(math.Float64bits(x)) < 52-23 { + return false + } + // Check the exponent is in range. The mantissa check above is sufficient for NaN values. + return math.IsNaN(x) || x == float64(float32(x)) } diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index 96051414dcb94..aa944b53798d1 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -572,9 +572,9 @@ // Pass constants through math.Float{32,64}bits and math.Float{32,64}frombits (Load p1 (Store {t2} p2 (Const64 [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 8 && is64BitFloat(t1) -> (Const64F [x]) -(Load p1 (Store {t2} p2 (Const32 [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitFloat(t1) -> (Const32F [f2i(float64(math.Float32frombits(uint32(x))))]) +(Load p1 (Store {t2} p2 (Const32 [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitFloat(t1) -> (Const32F [f2i(extend32Fto64F(math.Float32frombits(uint32(x))))]) (Load p1 (Store {t2} p2 (Const64F [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 8 && is64BitInt(t1) -> (Const64 [x]) -(Load p1 (Store {t2} p2 (Const32F [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitInt(t1) -> (Const32 [int64(int32(math.Float32bits(float32(i2f(x)))))]) +(Load p1 (Store {t2} p2 (Const32F [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitInt(t1) -> (Const32 [int64(int32(math.Float32bits(truncate64Fto32F(i2f(x)))))]) // Float Loads up to Zeros so they can be constant folded. (Load op:(OffPtr [o1] p1) diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index 4b12a84cdfec2..ca6280deb1593 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -418,6 +418,38 @@ func shiftIsBounded(v *Value) bool { return v.AuxInt != 0 } +// truncate64Fto32F converts a float64 value to a float32 preserving the bit pattern +// of the mantissa. It will panic if the truncation results in lost information. +func truncate64Fto32F(f float64) float32 { + if !isExactFloat32(f) { + panic("truncate64Fto32F: truncation is not exact") + } + if !math.IsNaN(f) { + return float32(f) + } + // NaN bit patterns aren't necessarily preserved across conversion + // instructions so we need to do the conversion manually. + b := math.Float64bits(f) + m := b & ((1 << 52) - 1) // mantissa (a.k.a. significand) + // | sign | exponent | mantissa | + r := uint32(((b >> 32) & (1 << 31)) | 0x7f800000 | (m >> (52 - 23))) + return math.Float32frombits(r) +} + +// extend32Fto64F converts a float32 value to a float64 value preserving the bit +// pattern of the mantissa. +func extend32Fto64F(f float32) float64 { + if !math.IsNaN(float64(f)) { + return float64(f) + } + // NaN bit patterns aren't necessarily preserved across conversion + // instructions so we need to do the conversion manually. + b := uint64(math.Float32bits(f)) + // | sign | exponent | mantissa | + r := ((b << 32) & (1 << 63)) | (0x7ff << 52) | ((b & 0x7fffff) << (52 - 23)) + return math.Float64frombits(r) +} + // i2f is used in rules for converting from an AuxInt to a float. func i2f(i int64) float64 { return math.Float64frombits(uint64(i)) diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 343b3581c1908..81bebede4689e 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -13483,7 +13483,7 @@ func rewriteValuegeneric_OpLoad_0(v *Value) bool { } // match: (Load p1 (Store {t2} p2 (Const32 [x]) _)) // cond: isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitFloat(t1) - // result: (Const32F [f2i(float64(math.Float32frombits(uint32(x))))]) + // result: (Const32F [f2i(extend32Fto64F(math.Float32frombits(uint32(x))))]) for { t1 := v.Type _ = v.Args[1] @@ -13504,7 +13504,7 @@ func rewriteValuegeneric_OpLoad_0(v *Value) bool { break } v.reset(OpConst32F) - v.AuxInt = f2i(float64(math.Float32frombits(uint32(x)))) + v.AuxInt = f2i(extend32Fto64F(math.Float32frombits(uint32(x)))) return true } // match: (Load p1 (Store {t2} p2 (Const64F [x]) _)) @@ -13535,7 +13535,7 @@ func rewriteValuegeneric_OpLoad_0(v *Value) bool { } // match: (Load p1 (Store {t2} p2 (Const32F [x]) _)) // cond: isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitInt(t1) - // result: (Const32 [int64(int32(math.Float32bits(float32(i2f(x)))))]) + // result: (Const32 [int64(int32(math.Float32bits(truncate64Fto32F(i2f(x)))))]) for { t1 := v.Type _ = v.Args[1] @@ -13556,7 +13556,7 @@ func rewriteValuegeneric_OpLoad_0(v *Value) bool { break } v.reset(OpConst32) - v.AuxInt = int64(int32(math.Float32bits(float32(i2f(x))))) + v.AuxInt = int64(int32(math.Float32bits(truncate64Fto32F(i2f(x))))) return true } // match: (Load op:(OffPtr [o1] p1) (Store {t2} p2 _ mem:(Zero [n] p3 _))) From 3c1b7bc7212cd894dae684ae064f4e7708b080ec Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 4 Sep 2018 17:18:22 -0700 Subject: [PATCH 0308/1663] go/types: fix internal comments and add additional test case https://go-review.googlesource.com/c/go/+/132355 addressed a crash and inadvertently fixed #27346; however the comment added to the type-checker was incorrect and misleading. This CL fixes the comment, and adds a test case for #27346. Fixes #27346. Updates #22467. Change-Id: Ib6d5caedf302fd42929c4dacc55e973c1aebfe85 Reviewed-on: https://go-review.googlesource.com/133415 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Rebecca Stambler --- src/go/types/expr.go | 19 ++++++++++++------- src/go/types/testdata/issues.src | 8 ++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/go/types/expr.go b/src/go/types/expr.go index f0acc7845d89c..c65c9e7681dfe 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1156,15 +1156,20 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { goto Error } n := check.indexedElts(e.Elts, utyp.elem, utyp.len) - // If we have an "open" [...]T array, set the length now that we know it - // and record the type for [...] (usually done by check.typExpr which is - // not called for [...]). + // If we have an array of unknown length (usually [...]T arrays, but also + // arrays [n]T where n is invalid) set the length now that we know it and + // record the type for the array (usually done by check.typ which is not + // called for [...]T). We handle [...]T arrays and arrays with invalid + // length the same here because it makes sense to "guess" the length for + // the latter if we have a composite literal; e.g. for [n]int{1, 2, 3} + // where n is invalid for some reason, it seems fair to assume it should + // be 3 (see also Checked.arrayLength and issue #27346). if utyp.len < 0 { utyp.len = n - // e.Type may be missing in case of errors. - // In "map[string][...]int{"": {1, 2, 3}}}, - // an error is reported for the outer literal, - // then [...]int is used as a hint for the inner literal. + // e.Type is missing if we have a composite literal element + // that is itself a composite literal with omitted type. In + // that case there is nothing to record (there is no type in + // the source at that point). if e.Type != nil { check.recordTypeAndValue(e.Type, typexpr, utyp, nil) } diff --git a/src/go/types/testdata/issues.src b/src/go/types/testdata/issues.src index d85e04e68cbfa..13f8309c829d7 100644 --- a/src/go/types/testdata/issues.src +++ b/src/go/types/testdata/issues.src @@ -294,3 +294,11 @@ type registry struct { type allocator struct { _ [int(preloadLimit)]int } + +// Test that we don't crash when type-checking composite literals +// containing errors in the type. +var issue27346 = [][n /* ERROR undeclared */ ]int{ + 0: {}, +} + +var issue22467 = map[int][... /* ERROR invalid use of ... */ ]int{0: {}} From 2524ed19946f10a9b0ecc4bf54f1a23c18faa525 Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Wed, 5 Sep 2018 20:05:37 +0100 Subject: [PATCH 0309/1663] cmd/compile: regenerate known formats for TestFormats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The formatting verb '%#x' was used for uint32 values in CL 132956. This fixes TestFormats. Change-Id: I3ab6519bde2cb74410fdca14829689cb46bf7022 Reviewed-on: https://go-review.googlesource.com/133595 Run-TryBot: Michael Munday TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí --- src/cmd/compile/fmt_test.go | 57 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/cmd/compile/fmt_test.go b/src/cmd/compile/fmt_test.go index eb2d3c1918c7e..e28e428a176a6 100644 --- a/src/cmd/compile/fmt_test.go +++ b/src/cmd/compile/fmt_test.go @@ -705,32 +705,33 @@ var knownFormats = map[string]string{ "interface{} %v": "", "map[*cmd/compile/internal/gc.Node]*cmd/compile/internal/ssa.Value %v": "", "map[cmd/compile/internal/ssa.ID]uint32 %v": "", - "reflect.Type %s": "", - "rune %#U": "", - "rune %c": "", - "string %-*s": "", - "string %-16s": "", - "string %-6s": "", - "string %.*s": "", - "string %q": "", - "string %s": "", - "string %v": "", - "time.Duration %d": "", - "time.Duration %v": "", - "uint %04x": "", - "uint %5d": "", - "uint %d": "", - "uint %x": "", - "uint16 %d": "", - "uint16 %v": "", - "uint16 %x": "", - "uint32 %d": "", - "uint32 %v": "", - "uint32 %x": "", - "uint64 %08x": "", - "uint64 %d": "", - "uint64 %x": "", - "uint8 %d": "", - "uint8 %x": "", - "uintptr %d": "", + "reflect.Type %s": "", + "rune %#U": "", + "rune %c": "", + "string %-*s": "", + "string %-16s": "", + "string %-6s": "", + "string %.*s": "", + "string %q": "", + "string %s": "", + "string %v": "", + "time.Duration %d": "", + "time.Duration %v": "", + "uint %04x": "", + "uint %5d": "", + "uint %d": "", + "uint %x": "", + "uint16 %d": "", + "uint16 %v": "", + "uint16 %x": "", + "uint32 %#x": "", + "uint32 %d": "", + "uint32 %v": "", + "uint32 %x": "", + "uint64 %08x": "", + "uint64 %d": "", + "uint64 %x": "", + "uint8 %d": "", + "uint8 %x": "", + "uintptr %d": "", } From 98fd66808fafb6496caeb3e848ae277b734f8ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 30 Aug 2018 11:02:41 -0600 Subject: [PATCH 0310/1663] text/template: simplify line tracking in the lexer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit First, move the strings.Count logic out of emit, since only itemText requires that. Use it in those call sites. itemLeftDelim and itemRightDelim cannot contain newlines, as they're the "{{" and "}}" tokens. Secondly, introduce a startLine lexer field so that we don't have to keep track of it elsewhere. That's also a requirement to move the strings.Count out of emit, as emit modifies the start position field. Change-Id: I69175f403487607a8e5b561b3f1916ee9dc3c0c6 Reviewed-on: https://go-review.googlesource.com/132275 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Rob Pike --- src/text/template/parse/lex.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/text/template/parse/lex.go b/src/text/template/parse/lex.go index c0843af6ede95..94a676c579cb4 100644 --- a/src/text/template/parse/lex.go +++ b/src/text/template/parse/lex.go @@ -117,6 +117,7 @@ type lexer struct { items chan item // channel of scanned items parenDepth int // nesting depth of ( ) exprs line int // 1+number of newlines seen + startLine int // start line of this item } // next returns the next rune in the input. @@ -152,19 +153,16 @@ func (l *lexer) backup() { // emit passes an item back to the client. func (l *lexer) emit(t itemType) { - l.items <- item{t, l.start, l.input[l.start:l.pos], l.line} - // Some items contain text internally. If so, count their newlines. - switch t { - case itemText, itemLeftDelim, itemRightDelim: - l.line += strings.Count(l.input[l.start:l.pos], "\n") - } + l.items <- item{t, l.start, l.input[l.start:l.pos], l.startLine} l.start = l.pos + l.startLine = l.line } // ignore skips over the pending input before this point. func (l *lexer) ignore() { l.line += strings.Count(l.input[l.start:l.pos], "\n") l.start = l.pos + l.startLine = l.line } // accept consumes the next rune if it's from the valid set. @@ -186,7 +184,7 @@ func (l *lexer) acceptRun(valid string) { // errorf returns an error token and terminates the scan by passing // back a nil pointer that will be the next state, terminating l.nextItem. func (l *lexer) errorf(format string, args ...interface{}) stateFn { - l.items <- item{itemError, l.start, fmt.Sprintf(format, args...), l.line} + l.items <- item{itemError, l.start, fmt.Sprintf(format, args...), l.startLine} return nil } @@ -218,6 +216,7 @@ func lex(name, input, left, right string) *lexer { rightDelim: right, items: make(chan item), line: 1, + startLine: 1, } go l.run() return l @@ -252,16 +251,17 @@ func lexText(l *lexer) stateFn { } l.pos -= trimLength if l.pos > l.start { + l.line += strings.Count(l.input[l.start:l.pos], "\n") l.emit(itemText) } l.pos += trimLength l.ignore() return lexLeftDelim - } else { - l.pos = Pos(len(l.input)) } + l.pos = Pos(len(l.input)) // Correctly reached EOF. if l.pos > l.start { + l.line += strings.Count(l.input[l.start:l.pos], "\n") l.emit(itemText) } l.emit(itemEOF) @@ -609,14 +609,10 @@ Loop: // lexRawQuote scans a raw quoted string. func lexRawQuote(l *lexer) stateFn { - startLine := l.line Loop: for { switch l.next() { case eof: - // Restore line number to location of opening quote. - // We will error out so it's ok just to overwrite the field. - l.line = startLine return l.errorf("unterminated raw quoted string") case '`': break Loop From 4a095b87d30f1f6f7ae01e966f1af5ee63b15c1c Mon Sep 17 00:00:00 2001 From: taylorza Date: Sun, 2 Sep 2018 18:09:29 -0400 Subject: [PATCH 0311/1663] cmd/compile: don't crash reporting misuse of shadowed built-in function The existing implementation causes a compiler panic if a function parameter shadows a built-in function, and then calling that shadowed name. Fixes #27356 Change-Id: I1ffb6dc01e63c7f499e5f6f75f77ce2318f35bcd Reviewed-on: https://go-review.googlesource.com/132876 Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/typecheck.go | 2 +- test/fixedbugs/issue27356.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue27356.go diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index cc98c3ae69e6c..bb78d8bf73d8d 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -1263,7 +1263,7 @@ func typecheck1(n *Node, top int) *Node { n.Op = OCALLFUNC if t.Etype != TFUNC { name := l.String() - if isBuiltinFuncName(name) { + if isBuiltinFuncName(name) && l.Name.Defn != nil { // be more specific when the function // name matches a predeclared function yyerror("cannot call non-function %s (type %v), declared at %s", diff --git a/test/fixedbugs/issue27356.go b/test/fixedbugs/issue27356.go new file mode 100644 index 0000000000000..42784876a558a --- /dev/null +++ b/test/fixedbugs/issue27356.go @@ -0,0 +1,19 @@ +// errorcheck + +// Copyright 2018 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. + +// Issue 27356: function parameter hiding built-in function results in compiler crash + +package p + +var a = []int{1,2,3} + +func _(len int) { + _ = len(a) // ERROR "cannot call non-function" +} + +var cap = false +var _ = cap(a) // ERROR "cannot call non-function" + From 262d4f321a885908def68adc4bed68428722b954 Mon Sep 17 00:00:00 2001 From: Warren Fernandes Date: Mon, 3 Sep 2018 12:32:02 -0600 Subject: [PATCH 0312/1663] fmt: add example for GoStringer interface Updates golang/go#27376. Change-Id: Ia8608561eb6a268aa7eae8c39c7098df100b643a Reviewed-on: https://go-review.googlesource.com/133075 Reviewed-by: Kevin Burke Run-TryBot: Kevin Burke TryBot-Result: Gobot Gobot --- src/fmt/gostringer_example_test.go | 59 ++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/fmt/gostringer_example_test.go diff --git a/src/fmt/gostringer_example_test.go b/src/fmt/gostringer_example_test.go new file mode 100644 index 0000000000000..ab19ee3b94d2e --- /dev/null +++ b/src/fmt/gostringer_example_test.go @@ -0,0 +1,59 @@ +// Copyright 2018 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. + +package fmt_test + +import ( + "fmt" +) + +// Address has a City, State and a Country. +type Address struct { + City string + State string + Country string +} + +// Person has a Name, Age and Address. +type Person struct { + Name string + Age uint + Addr *Address +} + +// GoString makes Person satisfy the GoStringer interface. +// The return value is valid Go code that can be used to reproduce the Person struct. +func (p Person) GoString() string { + if p.Addr != nil { + return fmt.Sprintf("Person{Name: %q, Age: %d, Addr: &Address{City: %q, State: %q, Country: %q}}", p.Name, int(p.Age), p.Addr.City, p.Addr.State, p.Addr.Country) + } + return fmt.Sprintf("Person{Name: %q, Age: %d}", p.Name, int(p.Age)) +} + +func ExampleGoStringer() { + p1 := Person{ + Name: "Warren", + Age: 31, + Addr: &Address{ + City: "Denver", + State: "CO", + Country: "U.S.A.", + }, + } + // If GoString() wasn't implemented, the output of `fmt.Printf("%#v", p1)` would be similar to + // Person{Name:"Warren", Age:0x1f, Addr:(*main.Address)(0x10448240)} + fmt.Printf("%#v\n", p1) + + p2 := Person{ + Name: "Theia", + Age: 4, + } + // If GoString() wasn't implemented, the output of `fmt.Printf("%#v", p2)` would be similar to + // Person{Name:"Theia", Age:0x4, Addr:(*main.Address)(nil)} + fmt.Printf("%#v\n", p2) + + // Output: + // Person{Name: "Warren", Age: 31, Addr: &Address{City: "Denver", State: "CO", Country: "U.S.A."}} + // Person{Name: "Theia", Age: 4} +} From 6b7099caa17e50410821f4a66ebb5c48717ad3c7 Mon Sep 17 00:00:00 2001 From: Warren Fernandes Date: Wed, 5 Sep 2018 22:35:01 -0600 Subject: [PATCH 0313/1663] expvar: fix name of Var interface Change-Id: Ibc40237981fdd20316f73f7f6f3dfa918dd0af5d Reviewed-on: https://go-review.googlesource.com/133658 Reviewed-by: Brad Fitzpatrick --- src/expvar/expvar.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/expvar/expvar.go b/src/expvar/expvar.go index 174873a7d47c4..b7928aab1727e 100644 --- a/src/expvar/expvar.go +++ b/src/expvar/expvar.go @@ -221,7 +221,7 @@ func (v *String) Value() string { return p } -// String implements the Val interface. To get the unquoted string +// String implements the Var interface. To get the unquoted string // use Value. func (v *String) String() string { s := v.Value() From 22afb3571c4bb6268664ecc5da4416ec58d3e060 Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Mon, 3 Sep 2018 11:20:23 +0100 Subject: [PATCH 0314/1663] encoding/json: recover saved error context when unmarshalling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes: #27464 Change-Id: I270c56fd0d5ae8787a1293029aff3072f4f52f33 Reviewed-on: https://go-review.googlesource.com/132955 Reviewed-by: Daniel Martí Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot --- src/encoding/json/decode.go | 2 +- src/encoding/json/decode_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go index fd2bf92dc24a1..82dc78083a7ca 100644 --- a/src/encoding/json/decode.go +++ b/src/encoding/json/decode.go @@ -179,7 +179,7 @@ func (d *decodeState) unmarshal(v interface{}) error { // test must be applied at the top level of the value. err := d.value(rv) if err != nil { - return err + return d.addErrorContext(err) } return d.savedError } diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go index b84bbabfcd801..defa97e40fdd0 100644 --- a/src/encoding/json/decode_test.go +++ b/src/encoding/json/decode_test.go @@ -41,6 +41,16 @@ type VOuter struct { V V } +type W struct { + S SS +} + +type SS string + +func (*SS) UnmarshalJSON(data []byte) error { + return &UnmarshalTypeError{Value: "number", Type: reflect.TypeOf(SS(""))} +} + // ifaceNumAsFloat64/ifaceNumAsNumber are used to test unmarshaling with and // without UseNumber var ifaceNumAsFloat64 = map[string]interface{}{ @@ -408,6 +418,7 @@ var unmarshalTests = []unmarshalTest{ {in: `{"X": 23}`, ptr: new(T), out: T{}, err: &UnmarshalTypeError{"number", reflect.TypeOf(""), 8, "T", "X"}}, {in: `{"x": 1}`, ptr: new(tx), out: tx{}}, {in: `{"x": 1}`, ptr: new(tx), out: tx{}}, {in: `{"x": 1}`, ptr: new(tx), err: fmt.Errorf("json: unknown field \"x\""), disallowUnknownFields: true}, + {in: `{"S": 23}`, ptr: new(W), out: W{}, err: &UnmarshalTypeError{"number", reflect.TypeOf(SS("")), 0, "W", "S"}}, {in: `{"F1":1,"F2":2,"F3":3}`, ptr: new(V), out: V{F1: float64(1), F2: int32(2), F3: Number("3")}}, {in: `{"F1":1,"F2":2,"F3":3}`, ptr: new(V), out: V{F1: Number("1"), F2: int32(2), F3: Number("3")}, useNumber: true}, {in: `{"k1":1,"k2":"s","k3":[1,2.0,3e-3],"k4":{"kk1":"s","kk2":2}}`, ptr: new(interface{}), out: ifaceNumAsFloat64}, From 3e5b5d69dcdb82494f550049986426d84dd6b8f8 Mon Sep 17 00:00:00 2001 From: Jake B Date: Wed, 5 Sep 2018 08:52:43 +0000 Subject: [PATCH 0315/1663] net: ensure WriteTo on Windows sends even zero-byte payloads This builds on: https://github.com/golang/go/pull/27445 "...And then send change to fix windows internal/poll.FD.WriteTo - together with making TestUDPZeroBytePayload run again." - alexbrainman - https://github.com/golang/go/issues/26668#issuecomment-408657503 Fixes #26668 Change-Id: Icd9ecb07458f13e580b3e7163a5946ccec342509 GitHub-Last-Rev: 3bf2b8b46bb8cf79903930631433a1f2ce50ec42 GitHub-Pull-Request: golang/go#27446 Reviewed-on: https://go-review.googlesource.com/132781 Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot Reviewed-by: Alex Brainman --- src/internal/poll/fd_windows.go | 3 --- src/net/udpsock_test.go | 12 +++++++----- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go index d04d332696db4..b08cec26256ec 100644 --- a/src/internal/poll/fd_windows.go +++ b/src/internal/poll/fd_windows.go @@ -761,9 +761,6 @@ func (fd *FD) Writev(buf *[][]byte) (int64, error) { // WriteTo wraps the sendto network call. func (fd *FD) WriteTo(buf []byte, sa syscall.Sockaddr) (int, error) { - if len(buf) == 0 { - return 0, nil - } if err := fd.writeLock(); err != nil { return 0, err } diff --git a/src/net/udpsock_test.go b/src/net/udpsock_test.go index 494064444ec15..1f06397ffa38a 100644 --- a/src/net/udpsock_test.go +++ b/src/net/udpsock_test.go @@ -357,13 +357,15 @@ func TestUDPZeroBytePayload(t *testing.T) { var b [1]byte if genericRead { _, err = c.(Conn).Read(b[:]) + // Read may timeout, it depends on the platform. + if err != nil { + if nerr, ok := err.(Error); !ok || !nerr.Timeout() { + t.Fatal(err) + } + } } else { _, _, err = c.ReadFrom(b[:]) - } - switch err { - case nil: // ReadFrom succeeds - default: // Read may timeout, it depends on the platform - if nerr, ok := err.(Error); !ok || !nerr.Timeout() { + if err != nil { t.Fatal(err) } } From 9c2be4c22d78cebc52458ba7298a470a3be0cdce Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Thu, 6 Sep 2018 13:28:17 +0300 Subject: [PATCH 0316/1663] bytes: remove bootstrap array from Buffer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rationale: small buffer optimization does not work and it has made things slower since 2014. Until we can make it work, we should prefer simpler code that also turns out to be more efficient. With this change, it's possible to use NewBuffer(make([]byte, 0, bootstrapSize)) to get the desired stack-allocated initial buffer since escape analysis can prove the created slice to be non-escaping. New implementation key points: - Zero value bytes.Buffer performs better than before - You can have a truly stack-allocated buffer, and it's not even limited to 64 bytes - The unsafe.Sizeof(bytes.Buffer{}) is reduced significantly - Empty writes don't cause allocations Buffer benchmarks from bytes package: name old time/op new time/op delta ReadString-8 9.20µs ± 1% 9.22µs ± 1% ~ (p=0.148 n=10+10) WriteByte-8 28.1µs ± 0% 26.2µs ± 0% -6.78% (p=0.000 n=10+10) WriteRune-8 64.9µs ± 0% 65.0µs ± 0% +0.16% (p=0.000 n=10+10) BufferNotEmptyWriteRead-8 469µs ± 0% 461µs ± 0% -1.76% (p=0.000 n=9+10) BufferFullSmallReads-8 108µs ± 0% 108µs ± 0% -0.21% (p=0.000 n=10+10) name old speed new speed delta ReadString-8 3.56GB/s ± 1% 3.55GB/s ± 1% ~ (p=0.165 n=10+10) WriteByte-8 146MB/s ± 0% 156MB/s ± 0% +7.26% (p=0.000 n=9+10) WriteRune-8 189MB/s ± 0% 189MB/s ± 0% -0.16% (p=0.000 n=10+10) name old alloc/op new alloc/op delta ReadString-8 32.8kB ± 0% 32.8kB ± 0% ~ (all equal) WriteByte-8 0.00B 0.00B ~ (all equal) WriteRune-8 0.00B 0.00B ~ (all equal) BufferNotEmptyWriteRead-8 4.72kB ± 0% 4.67kB ± 0% -1.02% (p=0.000 n=10+10) BufferFullSmallReads-8 3.44kB ± 0% 3.33kB ± 0% -3.26% (p=0.000 n=10+10) name old allocs/op new allocs/op delta ReadString-8 1.00 ± 0% 1.00 ± 0% ~ (all equal) WriteByte-8 0.00 0.00 ~ (all equal) WriteRune-8 0.00 0.00 ~ (all equal) BufferNotEmptyWriteRead-8 3.00 ± 0% 3.00 ± 0% ~ (all equal) BufferFullSmallReads-8 3.00 ± 0% 2.00 ± 0% -33.33% (p=0.000 n=10+10) The most notable thing in go1 benchmarks is reduced allocs in HTTPClientServer (-1 alloc): HTTPClientServer-8 64.0 ± 0% 63.0 ± 0% -1.56% (p=0.000 n=10+10) For more explanations and benchmarks see the referenced issue. Updates #7921 Change-Id: Ica0bf85e1b70fb4f5dc4f6a61045e2cf4ef72aa3 Reviewed-on: https://go-review.googlesource.com/133715 Reviewed-by: Martin Möhrmann Reviewed-by: Robert Griesemer Reviewed-by: Brad Fitzpatrick --- src/bytes/buffer.go | 15 +++++++------- test/fixedbugs/issue7921.go | 39 +++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 test/fixedbugs/issue7921.go diff --git a/src/bytes/buffer.go b/src/bytes/buffer.go index 14c5bc38d6689..087cc0e427561 100644 --- a/src/bytes/buffer.go +++ b/src/bytes/buffer.go @@ -12,13 +12,15 @@ import ( "unicode/utf8" ) +// smallBufferSize is an initial allocation minimal capacity. +const smallBufferSize = 64 + // A Buffer is a variable-sized buffer of bytes with Read and Write methods. // The zero value for Buffer is an empty buffer ready to use. type Buffer struct { - buf []byte // contents are the bytes buf[off : len(buf)] - off int // read at &buf[off], write at &buf[len(buf)] - bootstrap [64]byte // memory to hold first slice; helps small buffers avoid allocation. - lastRead readOp // last read operation, so that Unread* can work correctly. + buf []byte // contents are the bytes buf[off : len(buf)] + off int // read at &buf[off], write at &buf[len(buf)] + lastRead readOp // last read operation, so that Unread* can work correctly. // FIXME: it would be advisable to align Buffer to cachelines to avoid false // sharing. @@ -125,9 +127,8 @@ func (b *Buffer) grow(n int) int { if i, ok := b.tryGrowByReslice(n); ok { return i } - // Check if we can make use of bootstrap array. - if b.buf == nil && n <= len(b.bootstrap) { - b.buf = b.bootstrap[:n] + if b.buf == nil && n <= smallBufferSize { + b.buf = make([]byte, n, smallBufferSize) return 0 } c := cap(b.buf) diff --git a/test/fixedbugs/issue7921.go b/test/fixedbugs/issue7921.go new file mode 100644 index 0000000000000..d32221a209d3b --- /dev/null +++ b/test/fixedbugs/issue7921.go @@ -0,0 +1,39 @@ +// errorcheck -0 -m + +// Copyright 2018 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. + +package foo + +import "bytes" + +// In order to get desired results, we need a combination of +// both escape analysis and inlining. + +func bufferNotEscape() string { + // b itself does not escape, only its buf field will be + // copied during String() call, but object "handle" itself + // can be stack-allocated. + var b bytes.Buffer + b.WriteString("123") // ERROR "b does not escape" + b.Write([]byte{'4'}) // ERROR "b does not escape" "\[\]byte literal does not escape" + return b.String() // ERROR "b does not escape" "inlining call" "string\(bytes\.b\.buf\[bytes.b.off:\]\) escapes to heap" +} + +func bufferNoEscape2(xs []string) int { // ERROR "xs does not escape" + b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "inlining call" "make\(\[\]byte, 0, 64\) does not escape" "&bytes.Buffer literal does not escape" + for _, x := range xs { + b.WriteString(x) + } + return b.Len() // ERROR "inlining call" +} + +func bufferNoEscape3(xs []string) string { // ERROR "xs does not escape" + b := bytes.NewBuffer(make([]byte, 0, 64)) // ERROR "inlining call" "make\(\[\]byte, 0, 64\) does not escape" "&bytes.Buffer literal does not escape" + for _, x := range xs { + b.WriteString(x) + b.WriteByte(',') + } + return b.String() // ERROR "inlining call" "string\(bytes.b.buf\[bytes\.b\.off:\]\) escapes to heap" +} From 7ab4b5586d37513bfa48f769773007ff8e9b732d Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Fri, 15 Jun 2018 10:20:00 +0000 Subject: [PATCH 0317/1663] cmd/internal/obj/arm64: add CONSTRAINED UNPREDICTABLE behavior check for some load/store According to ARM64 manual, it is "constrained unpredictable behavior" if the src and dst registers of some load/store instructions are same. In order to completely prevent such unpredictable behavior, adding the check for load/store instructions that are supported by the assembler in the assembler. Add test cases. Update #25823 Change-Id: I64c14ad99ee543d778e7ec8ae6516a532293dbb3 Reviewed-on: https://go-review.googlesource.com/120660 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/asm/internal/asm/testdata/arm64.s | 1 + src/cmd/asm/internal/asm/testdata/arm64enc.s | 4 +- .../asm/internal/asm/testdata/arm64error.s | 34 +++++++--- src/cmd/internal/obj/arm64/asm7.go | 68 ++++++++++++++++++- 4 files changed, 95 insertions(+), 12 deletions(-) diff --git a/src/cmd/asm/internal/asm/testdata/arm64.s b/src/cmd/asm/internal/asm/testdata/arm64.s index 361b7a45c0ce1..9e2e2b1dc5436 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64.s +++ b/src/cmd/asm/internal/asm/testdata/arm64.s @@ -654,6 +654,7 @@ again: CALL foo(SB) // LDP/STP + LDP (R0), (R0, R1) // 000440a9 LDP (R0), (R1, R2) // 010840a9 LDP 8(R0), (R1, R2) // 018840a9 LDP -8(R0), (R1, R2) // 01887fa9 diff --git a/src/cmd/asm/internal/asm/testdata/arm64enc.s b/src/cmd/asm/internal/asm/testdata/arm64enc.s index ee4673c1ae1e4..432ab74493c20 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64enc.s +++ b/src/cmd/asm/internal/asm/testdata/arm64enc.s @@ -188,8 +188,8 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 MOVBU (R18)(R14<<0), R23 // 577a6e38 MOVBU (R2)(R8.SXTX), R19 // 53e86838 MOVBU (R27)(R23), R14 // MOVBU (R27)(R23*1), R14 // 6e6b7738 - MOVHU.P 107(R13), R13 // adb54678 - MOVHU.W 192(R2), R2 // 420c4c78 + MOVHU.P 107(R14), R13 // cdb54678 + MOVHU.W 192(R3), R2 // 620c4c78 MOVHU 6844(R4), R18 // 92787579 MOVHU (R5)(R25.SXTW), R15 // afc87978 //TODO MOVBW.P 77(R18), R11 // 4bd6c438 diff --git a/src/cmd/asm/internal/asm/testdata/arm64error.s b/src/cmd/asm/internal/asm/testdata/arm64error.s index b2ec0cc42502b..bbdce479c517b 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64error.s +++ b/src/cmd/asm/internal/asm/testdata/arm64error.s @@ -8,7 +8,19 @@ TEXT errors(SB),$0 ADDSW R7->32, R14, R13 // ERROR "shift amount out of range 0 to 31" ADD R1.UXTB<<5, R2, R3 // ERROR "shift amount out of range 0 to 4" ADDS R1.UXTX<<7, R2, R3 // ERROR "shift amount out of range 0 to 4" + AND $0x22220000, R2, RSP // ERROR "illegal combination" + ANDS $0x22220000, R2, RSP // ERROR "illegal combination" + ADD R1, R2, R3, R4 // ERROR "illegal combination" BICW R7@>33, R5, R16 // ERROR "shift amount out of range 0 to 31" + CINC CS, R2, R3, R4 // ERROR "illegal combination" + CSEL LT, R1, R2 // ERROR "illegal combination" + LDP.P 8(R2), (R2, R3) // ERROR "constrained unpredictable behavior" + LDP.W 8(R3), (R2, R3) // ERROR "constrained unpredictable behavior" + LDP (R1), (R2, R2) // ERROR "constrained unpredictable behavior" + LDP (R0), (F0, F1) // ERROR "invalid register pair" + LDP (R0), (R3, ZR) // ERROR "invalid register pair" + LDXPW (RSP), (R2, R2) // ERROR "constrained unpredictable behavior" + LDAXPW (R5), (R2, R2) // ERROR "constrained unpredictable behavior" MOVD.P 300(R2), R3 // ERROR "offset out of range [-255,254]" MOVD.P R3, 344(R2) // ERROR "offset out of range [-255,254]" MOVD (R3)(R7.SXTX<<2), R8 // ERROR "invalid index shift amount" @@ -16,6 +28,17 @@ TEXT errors(SB),$0 MOVWU (R5)(R4<<1), R10 // ERROR "invalid index shift amount" MOVB (R5)(R4.SXTW<<5), R10 // ERROR "invalid index shift amount" MOVH R5, (R6)(R2<<3) // ERROR "invalid index shift amount" + MADD R1, R2, R3 // ERROR "illegal combination" + MOVD.P R1, 8(R1) // ERROR "constrained unpredictable behavior" + MOVD.W 16(R2), R2 // ERROR "constrained unpredictable behavior" + STP (F2, F3), (R0) // ERROR "invalid register pair" + STP.W (R1, R2), 8(R1) // ERROR "constrained unpredictable behavior" + STP.P (R1, R2), 8(R2) // ERROR "constrained unpredictable behavior" + STLXP (R6, R11), (RSP), R6 // ERROR "constrained unpredictable behavior" + STXP (R6, R11), (R2), R2 // ERROR "constrained unpredictable behavior" + STLXR R3, (RSP), R3 // ERROR "constrained unpredictable behavior" + STXR R3, (R4), R4 // ERROR "constrained unpredictable behavior" + STLXRB R2, (R5), R5 // ERROR "constrained unpredictable behavior" VLD1 (R8)(R13), [V2.B16] // ERROR "illegal combination" VLD1 8(R9), [V2.B16] // ERROR "illegal combination" VST1 [V1.B16], (R8)(R13) // ERROR "illegal combination" @@ -83,15 +106,8 @@ TEXT errors(SB),$0 VST1.P [V1.B16], (R8)(R9<<1) // ERROR "invalid extended register" VREV64 V1.H4, V2.H8 // ERROR "invalid arrangement" VREV64 V1.D1, V2.D1 // ERROR "invalid arrangement" - ADD R1, R2, R3, R4 // ERROR "illegal combination" - MADD R1, R2, R3 // ERROR "illegal combination" - CINC CS, R2, R3, R4 // ERROR "illegal combination" - CSEL LT, R1, R2 // ERROR "illegal combination" - AND $0x22220000, R2, RSP // ERROR "illegal combination" - ANDS $0x22220000, R2, RSP // ERROR "illegal combination" - LDP (R0), (F0, F1) // ERROR "invalid register pair" - LDP (R0), (R3, ZR) // ERROR "invalid register pair" - STP (F2, F3), (R0) // ERROR "invalid register pair" FLDPD (R0), (R1, R2) // ERROR "invalid register pair" + FLDPD (R1), (F2, F2) // ERROR "constrained unpredictable behavior" + FLDPS (R2), (F3, F3) // ERROR "constrained unpredictable behavior" FSTPD (R1, R2), (R0) // ERROR "invalid register pair" RET diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index 7507976257b92..09ffc5dccf72e 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -1085,6 +1085,23 @@ func (c *ctxt7) regoff(a *obj.Addr) uint32 { return uint32(c.instoffset) } +func isSTLXRop(op obj.As) bool { + switch op { + case ASTLXR, ASTLXRW, ASTLXRB, ASTLXRH, + ASTXR, ASTXRW, ASTXRB, ASTXRH: + return true + } + return false +} + +func isSTXPop(op obj.As) bool { + switch op { + case ASTXP, ASTLXP, ASTXPW, ASTLXPW: + return true + } + return false +} + func isRegShiftOrExt(a *obj.Addr) bool { return (a.Index-obj.RBaseARM64)®_EXT != 0 || (a.Index-obj.RBaseARM64)®_LSL != 0 } @@ -2502,6 +2519,17 @@ func SYSARG4(op1 int, Cn int, Cm int, op2 int) int { return SYSARG5(0, op1, Cn, Cm, op2) } +// checkUnpredictable checks if the sourse and transfer registers are the same register. +// ARM64 manual says it is "constrained unpredictable" if the src and dst registers of STP/LDP are same. +func (c *ctxt7) checkUnpredictable(p *obj.Prog, isload bool, wback bool, rn int16, rt1 int16, rt2 int16) { + if wback && rn != REGSP && (rn == rt1 || rn == rt2) { + c.ctxt.Diag("constrained unpredictable behavior: %v", p) + } + if isload && rt1 == rt2 { + c.ctxt.Diag("constrained unpredictable behavior: %v", p) + } +} + /* checkindex checks if index >= 0 && index <= maxindex */ func (c *ctxt7) checkindex(p *obj.Prog, index, maxindex int) { if index < 0 || index > maxindex { @@ -2940,6 +2968,10 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { } case 22: /* movT (R)O!,R; movT O(R)!, R -> ldrT */ + if p.As != AFMOVS && p.As != AFMOVD && p.From.Reg != REGSP && p.From.Reg == p.To.Reg { + c.ctxt.Diag("constrained unpredictable behavior: %v", p) + } + v := int32(p.From.Offset) if v < -256 || v > 255 { @@ -2954,6 +2986,10 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { o1 |= ((uint32(v) & 0x1FF) << 12) | (uint32(p.From.Reg&31) << 5) | uint32(p.To.Reg&31) case 23: /* movT R,(R)O!; movT O(R)!, R -> strT */ + if p.As != AFMOVS && p.As != AFMOVD && p.To.Reg != REGSP && p.From.Reg == p.To.Reg { + c.ctxt.Diag("constrained unpredictable behavior: %v", p) + } + v := int32(p.To.Offset) if v < -256 || v > 255 { @@ -3551,6 +3587,9 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { o1 |= 0x1F << 16 o1 |= uint32(p.From.Reg&31) << 5 if p.As == ALDXP || p.As == ALDXPW || p.As == ALDAXP || p.As == ALDAXPW { + if int(p.To.Reg) == int(p.To.Offset) { + c.ctxt.Diag("constrained unpredictable behavior: %v", p) + } o1 |= uint32(p.To.Offset&31) << 10 } else { o1 |= 0x1F << 10 @@ -3558,6 +3597,19 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { o1 |= uint32(p.To.Reg & 31) case 59: /* stxr/stlxr/stxp/stlxp */ + s := p.RegTo2 + n := p.To.Reg + t := p.From.Reg + if isSTLXRop(p.As) { + if s == t || (s == n && n != REGSP) { + c.ctxt.Diag("constrained unpredictable behavior: %v", p) + } + } else if isSTXPop(p.As) { + t2 := int16(p.From.Offset) + if (s == t || s == t2) || (s == n && n != REGSP) { + c.ctxt.Diag("constrained unpredictable behavior: %v", p) + } + } o1 = c.opstore(p, p.As) if p.RegTo2 != obj.REG_NONE { @@ -3565,7 +3617,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { } else { o1 |= 0x1F << 16 } - if p.As == ASTXP || p.As == ASTXPW || p.As == ASTLXP || p.As == ASTLXPW { + if isSTXPop(p.As) { o1 |= uint32(p.From.Offset&31) << 10 } o1 |= uint32(p.To.Reg&31)<<5 | uint32(p.From.Reg&31) @@ -6177,6 +6229,20 @@ func (c *ctxt7) opextr(p *obj.Prog, a obj.As, v int32, rn int, rm int, rt int) u /* genrate instruction encoding for LDP/LDPW/LDPSW/STP/STPW */ func (c *ctxt7) opldpstp(p *obj.Prog, o *Optab, vo int32, rbase, rl, rh, ldp uint32) uint32 { + wback := false + if o.scond == C_XPOST || o.scond == C_XPRE { + wback = true + } + switch p.As { + case ALDP, ALDPW, ALDPSW: + c.checkUnpredictable(p, true, wback, p.From.Reg, p.To.Reg, int16(p.To.Offset)) + case ASTP, ASTPW: + if wback == true { + c.checkUnpredictable(p, false, true, p.To.Reg, p.From.Reg, int16(p.From.Offset)) + } + case AFLDPD, AFLDPS: + c.checkUnpredictable(p, true, false, p.From.Reg, p.To.Reg, int16(p.To.Offset)) + } var ret uint32 // check offset switch p.As { From 2e5c32518ce6facc507862f4156d4e6ac776754f Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Tue, 21 Aug 2018 04:57:03 +0000 Subject: [PATCH 0318/1663] cmd/compile: optimize math.Copysign on arm64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add rewrite rules to optimize math.Copysign() when the second argument is negative floating point constant. For example, math.Copysign(c, -2): The previous compile output is "AND $9223372036854775807, R0, R0; ORR $-9223372036854775808, R0, R0". The optimized compile output is "ORR $-9223372036854775808, R0, R0" Math package benchmark results. name old time/op new time/op delta Copysign-8 2.61ns ± 2% 2.49ns ± 0% -4.55% (p=0.000 n=10+10) Cos-8 43.0ns ± 0% 41.5ns ± 0% -3.49% (p=0.000 n=10+10) Cosh-8 98.6ns ± 0% 98.1ns ± 0% -0.51% (p=0.000 n=10+10) ExpGo-8 107ns ± 0% 105ns ± 0% -1.87% (p=0.000 n=10+10) Exp2Go-8 100ns ± 0% 100ns ± 0% +0.39% (p=0.000 n=10+8) Max-8 6.56ns ± 2% 6.45ns ± 1% -1.63% (p=0.002 n=10+10) Min-8 6.66ns ± 3% 6.47ns ± 2% -2.82% (p=0.006 n=10+10) Mod-8 107ns ± 1% 104ns ± 1% -2.72% (p=0.000 n=10+10) Frexp-8 11.5ns ± 1% 11.0ns ± 0% -4.56% (p=0.000 n=8+10) HypotGo-8 19.4ns ± 0% 19.4ns ± 0% +0.36% (p=0.019 n=10+10) Ilogb-8 8.63ns ± 0% 8.51ns ± 0% -1.36% (p=0.000 n=10+10) Jn-8 584ns ± 0% 585ns ± 0% +0.17% (p=0.000 n=7+8) Ldexp-8 13.8ns ± 0% 13.5ns ± 0% -2.17% (p=0.002 n=8+10) Logb-8 10.2ns ± 0% 9.9ns ± 0% -2.65% (p=0.000 n=10+7) Nextafter64-8 7.54ns ± 0% 7.51ns ± 0% -0.37% (p=0.000 n=10+10) Remainder-8 73.5ns ± 1% 70.4ns ± 1% -4.27% (p=0.000 n=10+10) SqrtGoLatency-8 79.6ns ± 0% 76.2ns ± 0% -4.30% (p=0.000 n=9+10) Yn-8 582ns ± 0% 579ns ± 0% -0.52% (p=0.000 n=10+10) Change-Id: I0c9cd1ea87435e7b8bab94b4e79e6e29785f25b1 Reviewed-on: https://go-review.googlesource.com/132915 Reviewed-by: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/ssa/gen/ARM64.rules | 5 +++ src/cmd/compile/internal/ssa/rewriteARM64.go | 45 ++++++++++++++++++++ test/codegen/math.go | 1 + 3 files changed, 51 insertions(+) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index ede7ed3d7a093..6c8f3860d1867 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -101,6 +101,8 @@ // Load args directly into the register class where it will be used. (FMOVDgpfp (Arg [off] {sym})) -> @b.Func.Entry (Arg [off] {sym}) +(FMOVDfpgp (Arg [off] {sym})) -> @b.Func.Entry (Arg [off] {sym}) + // Similarly for stores, if we see a store after FPR <-> GPR move, then redirect store to use the other register set. (MOVDstore ptr (FMOVDfpgp val) mem) -> (FMOVDstore ptr val mem) (FMOVDstore ptr (FMOVDgpfp val) mem) -> (MOVDstore ptr val mem) @@ -1626,6 +1628,9 @@ (SRLconst [c] (SLLconst [c] x)) && 0 < c && c < 64 -> (ANDconst [1< (ANDconst [^(1< (ORconst [c1] x) + // bitfield ops // sbfiz diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index fbdf3529981a7..219bc3676d8ee 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -87,6 +87,8 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64FADDD_0(v) case OpARM64FADDS: return rewriteValueARM64_OpARM64FADDS_0(v) + case OpARM64FMOVDfpgp: + return rewriteValueARM64_OpARM64FMOVDfpgp_0(v) case OpARM64FMOVDgpfp: return rewriteValueARM64_OpARM64FMOVDgpfp_0(v) case OpARM64FMOVDload: @@ -3960,6 +3962,30 @@ func rewriteValueARM64_OpARM64FADDS_0(v *Value) bool { } return false } +func rewriteValueARM64_OpARM64FMOVDfpgp_0(v *Value) bool { + b := v.Block + _ = b + // match: (FMOVDfpgp (Arg [off] {sym})) + // cond: + // result: @b.Func.Entry (Arg [off] {sym}) + for { + t := v.Type + v_0 := v.Args[0] + if v_0.Op != OpArg { + break + } + off := v_0.AuxInt + sym := v_0.Aux + b = b.Func.Entry + v0 := b.NewValue0(v.Pos, OpArg, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.AuxInt = off + v0.Aux = sym + return true + } + return false +} func rewriteValueARM64_OpARM64FMOVDgpfp_0(v *Value) bool { b := v.Block _ = b @@ -21834,6 +21860,25 @@ func rewriteValueARM64_OpARM64ORconst_0(v *Value) bool { v.AddArg(x) return true } + // match: (ORconst [c1] (ANDconst [c2] x)) + // cond: c2|c1 == ^0 + // result: (ORconst [c1] x) + for { + c1 := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64ANDconst { + break + } + c2 := v_0.AuxInt + x := v_0.Args[0] + if !(c2|c1 == ^0) { + break + } + v.reset(OpARM64ORconst) + v.AuxInt = c1 + v.AddArg(x) + return true + } return false } func rewriteValueARM64_OpARM64ORshiftLL_0(v *Value) bool { diff --git a/test/codegen/math.go b/test/codegen/math.go index 1ecba26847a05..99335d2efc79a 100644 --- a/test/codegen/math.go +++ b/test/codegen/math.go @@ -74,6 +74,7 @@ func copysign(a, b, c float64) { // amd64:"BTSQ\t[$]63" // s390x:"LNDFR\t",-"MOVD\t" (no integer load/store) // ppc64le:"FCPSGN" + // arm64:"ORR\t[$]-9223372036854775808" sink64[1] = math.Copysign(c, -1) // Like math.Copysign(c, -1), but with integer operations. Useful From 031a35ec8471a97fba4f3ab0ff9c0e9eaa54ae1e Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 6 Sep 2018 01:13:14 +0000 Subject: [PATCH 0319/1663] cmd/compile: optimize 386's comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Optimization of "(CMPconst [0] (ANDL x y)) -> (TESTL x y)" only get benefits if there is no further use of the result of x&y. A condition of uses==1 will have slight improvements. 1. The code size of pkg/linux_386 decreases about 300 bytes, excluding cmd/compile/. 2. The go1 benchmark shows no regression, and even a slight improvement in test case FmtFprintfEmpty-4, excluding noise. name old time/op new time/op delta BinaryTree17-4 3.34s ± 3% 3.32s ± 2% ~ (p=0.197 n=30+30) Fannkuch11-4 3.48s ± 2% 3.47s ± 1% -0.33% (p=0.015 n=30+30) FmtFprintfEmpty-4 46.3ns ± 4% 44.8ns ± 4% -3.33% (p=0.000 n=30+30) FmtFprintfString-4 78.8ns ± 7% 77.3ns ± 5% ~ (p=0.098 n=30+26) FmtFprintfInt-4 90.2ns ± 1% 90.0ns ± 7% -0.23% (p=0.027 n=18+30) FmtFprintfIntInt-4 144ns ± 4% 143ns ± 5% ~ (p=0.945 n=30+29) FmtFprintfPrefixedInt-4 180ns ± 4% 180ns ± 5% ~ (p=0.858 n=30+30) FmtFprintfFloat-4 409ns ± 4% 406ns ± 3% -0.87% (p=0.028 n=30+30) FmtManyArgs-4 611ns ± 5% 608ns ± 4% ~ (p=0.812 n=30+30) GobDecode-4 7.30ms ± 5% 7.26ms ± 5% ~ (p=0.522 n=30+29) GobEncode-4 6.90ms ± 7% 6.82ms ± 4% ~ (p=0.086 n=29+28) Gzip-4 396ms ± 4% 400ms ± 4% +0.99% (p=0.026 n=30+30) Gunzip-4 41.1ms ± 3% 41.2ms ± 3% ~ (p=0.495 n=30+30) HTTPClientServer-4 63.7µs ± 3% 63.3µs ± 2% ~ (p=0.113 n=29+29) JSONEncode-4 16.1ms ± 2% 16.1ms ± 2% -0.30% (p=0.041 n=30+30) JSONDecode-4 60.9ms ± 3% 61.2ms ± 6% ~ (p=0.187 n=30+30) Mandelbrot200-4 5.17ms ± 2% 5.19ms ± 3% ~ (p=0.676 n=30+30) GoParse-4 3.28ms ± 3% 3.25ms ± 2% -0.97% (p=0.002 n=30+30) RegexpMatchEasy0_32-4 103ns ± 4% 104ns ± 4% ~ (p=0.352 n=30+30) RegexpMatchEasy0_1K-4 849ns ± 2% 845ns ± 2% ~ (p=0.381 n=30+30) RegexpMatchEasy1_32-4 113ns ± 4% 113ns ± 4% ~ (p=0.795 n=30+30) RegexpMatchEasy1_1K-4 1.03µs ± 3% 1.03µs ± 4% ~ (p=0.275 n=25+30) RegexpMatchMedium_32-4 132ns ± 3% 132ns ± 3% ~ (p=0.970 n=30+30) RegexpMatchMedium_1K-4 41.4µs ± 3% 41.4µs ± 3% ~ (p=0.212 n=30+30) RegexpMatchHard_32-4 2.22µs ± 4% 2.22µs ± 4% ~ (p=0.399 n=30+30) RegexpMatchHard_1K-4 67.2µs ± 3% 67.6µs ± 4% ~ (p=0.359 n=30+30) Revcomp-4 1.84s ± 2% 1.83s ± 2% ~ (p=0.532 n=30+30) Template-4 69.1ms ± 4% 68.8ms ± 3% ~ (p=0.146 n=30+30) TimeParse-4 441ns ± 3% 442ns ± 3% ~ (p=0.154 n=30+30) TimeFormat-4 413ns ± 3% 414ns ± 3% ~ (p=0.275 n=30+30) [Geo mean] 66.2µs 66.0µs -0.28% name old speed new speed delta GobDecode-4 105MB/s ± 5% 106MB/s ± 5% ~ (p=0.514 n=30+29) GobEncode-4 111MB/s ± 5% 113MB/s ± 4% +1.37% (p=0.046 n=28+28) Gzip-4 49.1MB/s ± 4% 48.6MB/s ± 4% -0.98% (p=0.028 n=30+30) Gunzip-4 472MB/s ± 4% 472MB/s ± 3% ~ (p=0.496 n=30+30) JSONEncode-4 120MB/s ± 2% 121MB/s ± 2% +0.29% (p=0.042 n=30+30) JSONDecode-4 31.9MB/s ± 3% 31.7MB/s ± 6% ~ (p=0.186 n=30+30) GoParse-4 17.6MB/s ± 3% 17.8MB/s ± 2% +0.98% (p=0.002 n=30+30) RegexpMatchEasy0_32-4 309MB/s ± 4% 307MB/s ± 4% ~ (p=0.501 n=30+30) RegexpMatchEasy0_1K-4 1.21GB/s ± 2% 1.21GB/s ± 2% ~ (p=0.301 n=30+30) RegexpMatchEasy1_32-4 283MB/s ± 4% 282MB/s ± 3% ~ (p=0.877 n=30+30) RegexpMatchEasy1_1K-4 1.00GB/s ± 3% 0.99GB/s ± 4% ~ (p=0.276 n=25+30) RegexpMatchMedium_32-4 7.54MB/s ± 3% 7.55MB/s ± 3% ~ (p=0.528 n=30+30) RegexpMatchMedium_1K-4 24.7MB/s ± 3% 24.7MB/s ± 3% ~ (p=0.203 n=30+30) RegexpMatchHard_32-4 14.4MB/s ± 4% 14.4MB/s ± 4% ~ (p=0.407 n=30+30) RegexpMatchHard_1K-4 15.3MB/s ± 3% 15.1MB/s ± 4% ~ (p=0.306 n=30+30) Revcomp-4 138MB/s ± 2% 139MB/s ± 2% ~ (p=0.520 n=30+30) Template-4 28.1MB/s ± 4% 28.2MB/s ± 3% ~ (p=0.149 n=30+30) [Geo mean] 81.5MB/s 81.5MB/s +0.06% Change-Id: I7f75425f79eec93cdd8fdd94db13ad4f61b6a2f5 Reviewed-on: https://go-review.googlesource.com/133657 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/gen/386.rules | 8 +- src/cmd/compile/internal/ssa/rewrite386.go | 96 +++++++++++++--------- test/codegen/comparisons.go | 1 + 3 files changed, 62 insertions(+), 43 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/386.rules b/src/cmd/compile/internal/ssa/gen/386.rules index 8131f1117afa4..2a05732c989f2 100644 --- a/src/cmd/compile/internal/ssa/gen/386.rules +++ b/src/cmd/compile/internal/ssa/gen/386.rules @@ -1116,10 +1116,10 @@ (XORL x x) -> (MOVLconst [0]) // checking AND against 0. -(CMP(L|W|B)const (ANDL x y) [0]) -> (TEST(L|W|B) x y) -(CMPLconst (ANDLconst [c] x) [0]) -> (TESTLconst [c] x) -(CMPWconst (ANDLconst [c] x) [0]) -> (TESTWconst [int64(int16(c))] x) -(CMPBconst (ANDLconst [c] x) [0]) -> (TESTBconst [int64(int8(c))] x) +(CMP(L|W|B)const l:(ANDL x y) [0]) && l.Uses==1 -> (TEST(L|W|B) x y) +(CMPLconst l:(ANDLconst [c] x) [0]) && l.Uses==1 -> (TESTLconst [c] x) +(CMPWconst l:(ANDLconst [c] x) [0]) && l.Uses==1 -> (TESTWconst [int64(int16(c))] x) +(CMPBconst l:(ANDLconst [c] x) [0]) && l.Uses==1 -> (TESTBconst [int64(int8(c))] x) // TEST %reg,%reg is shorter than CMP (CMP(L|W|B)const x [0]) -> (TEST(L|W|B) x x) diff --git a/src/cmd/compile/internal/ssa/rewrite386.go b/src/cmd/compile/internal/ssa/rewrite386.go index abc1d18309521..adea486ef5e38 100644 --- a/src/cmd/compile/internal/ssa/rewrite386.go +++ b/src/cmd/compile/internal/ssa/rewrite386.go @@ -2507,38 +2507,44 @@ func rewriteValue386_Op386CMPBconst_0(v *Value) bool { v.reset(Op386FlagLT_ULT) return true } - // match: (CMPBconst (ANDL x y) [0]) - // cond: + // match: (CMPBconst l:(ANDL x y) [0]) + // cond: l.Uses==1 // result: (TESTB x y) for { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != Op386ANDL { + l := v.Args[0] + if l.Op != Op386ANDL { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] v.reset(Op386TESTB) v.AddArg(x) v.AddArg(y) return true } - // match: (CMPBconst (ANDLconst [c] x) [0]) - // cond: + // match: (CMPBconst l:(ANDLconst [c] x) [0]) + // cond: l.Uses==1 // result: (TESTBconst [int64(int8(c))] x) for { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != Op386ANDLconst { + l := v.Args[0] + if l.Op != Op386ANDLconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] v.reset(Op386TESTBconst) v.AuxInt = int64(int8(c)) v.AddArg(x) @@ -2819,38 +2825,44 @@ func rewriteValue386_Op386CMPLconst_0(v *Value) bool { v.reset(Op386FlagLT_ULT) return true } - // match: (CMPLconst (ANDL x y) [0]) - // cond: + // match: (CMPLconst l:(ANDL x y) [0]) + // cond: l.Uses==1 // result: (TESTL x y) for { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != Op386ANDL { + l := v.Args[0] + if l.Op != Op386ANDL { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] v.reset(Op386TESTL) v.AddArg(x) v.AddArg(y) return true } - // match: (CMPLconst (ANDLconst [c] x) [0]) - // cond: + // match: (CMPLconst l:(ANDLconst [c] x) [0]) + // cond: l.Uses==1 // result: (TESTLconst [c] x) for { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != Op386ANDLconst { + l := v.Args[0] + if l.Op != Op386ANDLconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] v.reset(Op386TESTLconst) v.AuxInt = c v.AddArg(x) @@ -3122,38 +3134,44 @@ func rewriteValue386_Op386CMPWconst_0(v *Value) bool { v.reset(Op386FlagLT_ULT) return true } - // match: (CMPWconst (ANDL x y) [0]) - // cond: + // match: (CMPWconst l:(ANDL x y) [0]) + // cond: l.Uses==1 // result: (TESTW x y) for { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != Op386ANDL { + l := v.Args[0] + if l.Op != Op386ANDL { + break + } + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] v.reset(Op386TESTW) v.AddArg(x) v.AddArg(y) return true } - // match: (CMPWconst (ANDLconst [c] x) [0]) - // cond: + // match: (CMPWconst l:(ANDLconst [c] x) [0]) + // cond: l.Uses==1 // result: (TESTWconst [int64(int16(c))] x) for { if v.AuxInt != 0 { break } - v_0 := v.Args[0] - if v_0.Op != Op386ANDLconst { + l := v.Args[0] + if l.Op != Op386ANDLconst { + break + } + c := l.AuxInt + x := l.Args[0] + if !(l.Uses == 1) { break } - c := v_0.AuxInt - x := v_0.Args[0] v.reset(Op386TESTWconst) v.AuxInt = int64(int16(c)) v.AddArg(x) diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go index 50c9de7626c95..d5bade97cce8f 100644 --- a/test/codegen/comparisons.go +++ b/test/codegen/comparisons.go @@ -181,6 +181,7 @@ func CmpToZero(a, b, d int32, e, f int64) int32 { // not optimized to single TSTW/TST due to further use of a&d // arm64:`AND`,-`TSTW` // arm:`AND`,-`TST` + // 386:`ANDL` c6 := a&d >= 0 if c0 { return 1 From 73b8e5f81b992597462d39978bad09c0f88a530e Mon Sep 17 00:00:00 2001 From: Marko Kevac Date: Tue, 5 Jun 2018 22:41:18 +0300 Subject: [PATCH 0320/1663] runtime/pprof: remove "deleted" suffix while parsing maps file If binary file of a running program was deleted or moved, maps file (/proc/pid/maps) will contain lines that have this binary filename suffixed with "(deleted)" string. This suffix stayed as a part of the filename and made remote profiling slightly more difficult by requiring from a user to rename binary file to include this suffix. This change cleans up the filename and removes this suffix and thus simplify debugging. Fixes #25740 Change-Id: Ib3c8c3b9ef536c2ac037fcc14e8037fa5c960036 Reviewed-on: https://go-review.googlesource.com/116395 Run-TryBot: Hyang-Ah Hana Kim TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim --- src/runtime/pprof/proto.go | 8 +++ src/runtime/pprof/proto_test.go | 95 +++++++++++++++++++++++++++------ 2 files changed, 88 insertions(+), 15 deletions(-) diff --git a/src/runtime/pprof/proto.go b/src/runtime/pprof/proto.go index cbd0b83376416..bd5c8f7afcb85 100644 --- a/src/runtime/pprof/proto.go +++ b/src/runtime/pprof/proto.go @@ -524,6 +524,14 @@ func parseProcSelfMaps(data []byte, addMapping func(lo, hi, offset uint64, file, continue } file := string(line) + + // Trim deleted file marker. + deletedStr := " (deleted)" + deletedLen := len(deletedStr) + if len(file) >= deletedLen && file[len(file)-deletedLen:] == deletedStr { + file = file[:len(file)-deletedLen] + } + if len(inode) == 1 && inode[0] == '0' && file == "" { // Huge-page text mappings list the initial fragment of // mapped but unpopulated memory as being inode 0. diff --git a/src/runtime/pprof/proto_test.go b/src/runtime/pprof/proto_test.go index 76bd46da028db..4452d5123158e 100644 --- a/src/runtime/pprof/proto_test.go +++ b/src/runtime/pprof/proto_test.go @@ -216,24 +216,89 @@ c000000000-c000036000 rw-p 00000000 00:00 0 07000000 07093000 06c00000 /path/to/gobench_server_main ` +var profSelfMapsTestsWithDeleted = ` +00400000-0040b000 r-xp 00000000 fc:01 787766 /bin/cat (deleted) +0060a000-0060b000 r--p 0000a000 fc:01 787766 /bin/cat (deleted) +0060b000-0060c000 rw-p 0000b000 fc:01 787766 /bin/cat (deleted) +014ab000-014cc000 rw-p 00000000 00:00 0 [heap] +7f7d76af8000-7f7d7797c000 r--p 00000000 fc:01 1318064 /usr/lib/locale/locale-archive +7f7d7797c000-7f7d77b36000 r-xp 00000000 fc:01 1180226 /lib/x86_64-linux-gnu/libc-2.19.so +7f7d77b36000-7f7d77d36000 ---p 001ba000 fc:01 1180226 /lib/x86_64-linux-gnu/libc-2.19.so +7f7d77d36000-7f7d77d3a000 r--p 001ba000 fc:01 1180226 /lib/x86_64-linux-gnu/libc-2.19.so +7f7d77d3a000-7f7d77d3c000 rw-p 001be000 fc:01 1180226 /lib/x86_64-linux-gnu/libc-2.19.so +7f7d77d3c000-7f7d77d41000 rw-p 00000000 00:00 0 +7f7d77d41000-7f7d77d64000 r-xp 00000000 fc:01 1180217 /lib/x86_64-linux-gnu/ld-2.19.so +7f7d77f3f000-7f7d77f42000 rw-p 00000000 00:00 0 +7f7d77f61000-7f7d77f63000 rw-p 00000000 00:00 0 +7f7d77f63000-7f7d77f64000 r--p 00022000 fc:01 1180217 /lib/x86_64-linux-gnu/ld-2.19.so +7f7d77f64000-7f7d77f65000 rw-p 00023000 fc:01 1180217 /lib/x86_64-linux-gnu/ld-2.19.so +7f7d77f65000-7f7d77f66000 rw-p 00000000 00:00 0 +7ffc342a2000-7ffc342c3000 rw-p 00000000 00:00 0 [stack] +7ffc34343000-7ffc34345000 r-xp 00000000 00:00 0 [vdso] +ffffffffff600000-ffffffffff601000 r-xp 00000090 00:00 0 [vsyscall] +-> +00400000 0040b000 00000000 /bin/cat +7f7d7797c000 7f7d77b36000 00000000 /lib/x86_64-linux-gnu/libc-2.19.so +7f7d77d41000 7f7d77d64000 00000000 /lib/x86_64-linux-gnu/ld-2.19.so +7ffc34343000 7ffc34345000 00000000 [vdso] +ffffffffff600000 ffffffffff601000 00000090 [vsyscall] + +00400000-0040b000 r-xp 00000000 fc:01 787766 /bin/cat with space +0060a000-0060b000 r--p 0000a000 fc:01 787766 /bin/cat with space +0060b000-0060c000 rw-p 0000b000 fc:01 787766 /bin/cat with space +014ab000-014cc000 rw-p 00000000 00:00 0 [heap] +7f7d76af8000-7f7d7797c000 r--p 00000000 fc:01 1318064 /usr/lib/locale/locale-archive +7f7d7797c000-7f7d77b36000 r-xp 00000000 fc:01 1180226 /lib/x86_64-linux-gnu/libc-2.19.so +7f7d77b36000-7f7d77d36000 ---p 001ba000 fc:01 1180226 /lib/x86_64-linux-gnu/libc-2.19.so +7f7d77d36000-7f7d77d3a000 r--p 001ba000 fc:01 1180226 /lib/x86_64-linux-gnu/libc-2.19.so +7f7d77d3a000-7f7d77d3c000 rw-p 001be000 fc:01 1180226 /lib/x86_64-linux-gnu/libc-2.19.so +7f7d77d3c000-7f7d77d41000 rw-p 00000000 00:00 0 +7f7d77d41000-7f7d77d64000 r-xp 00000000 fc:01 1180217 /lib/x86_64-linux-gnu/ld-2.19.so +7f7d77f3f000-7f7d77f42000 rw-p 00000000 00:00 0 +7f7d77f61000-7f7d77f63000 rw-p 00000000 00:00 0 +7f7d77f63000-7f7d77f64000 r--p 00022000 fc:01 1180217 /lib/x86_64-linux-gnu/ld-2.19.so +7f7d77f64000-7f7d77f65000 rw-p 00023000 fc:01 1180217 /lib/x86_64-linux-gnu/ld-2.19.so +7f7d77f65000-7f7d77f66000 rw-p 00000000 00:00 0 +7ffc342a2000-7ffc342c3000 rw-p 00000000 00:00 0 [stack] +7ffc34343000-7ffc34345000 r-xp 00000000 00:00 0 [vdso] +ffffffffff600000-ffffffffff601000 r-xp 00000090 00:00 0 [vsyscall] +-> +00400000 0040b000 00000000 /bin/cat with space +7f7d7797c000 7f7d77b36000 00000000 /lib/x86_64-linux-gnu/libc-2.19.so +7f7d77d41000 7f7d77d64000 00000000 /lib/x86_64-linux-gnu/ld-2.19.so +7ffc34343000 7ffc34345000 00000000 [vdso] +ffffffffff600000 ffffffffff601000 00000090 [vsyscall] +` + func TestProcSelfMaps(t *testing.T) { - for tx, tt := range strings.Split(profSelfMapsTests, "\n\n") { - i := strings.Index(tt, "->\n") - if i < 0 { - t.Fatal("malformed test case") - } - in, out := tt[:i], tt[i+len("->\n"):] - if len(out) > 0 && out[len(out)-1] != '\n' { - out += "\n" - } - var buf bytes.Buffer - parseProcSelfMaps([]byte(in), func(lo, hi, offset uint64, file, buildID string) { - fmt.Fprintf(&buf, "%08x %08x %08x %s\n", lo, hi, offset, file) - }) - if buf.String() != out { - t.Errorf("#%d: have:\n%s\nwant:\n%s\n%q\n%q", tx, buf.String(), out, buf.String(), out) + + f := func(t *testing.T, input string) { + for tx, tt := range strings.Split(input, "\n\n") { + i := strings.Index(tt, "->\n") + if i < 0 { + t.Fatal("malformed test case") + } + in, out := tt[:i], tt[i+len("->\n"):] + if len(out) > 0 && out[len(out)-1] != '\n' { + out += "\n" + } + var buf bytes.Buffer + parseProcSelfMaps([]byte(in), func(lo, hi, offset uint64, file, buildID string) { + fmt.Fprintf(&buf, "%08x %08x %08x %s\n", lo, hi, offset, file) + }) + if buf.String() != out { + t.Errorf("#%d: have:\n%s\nwant:\n%s\n%q\n%q", tx, buf.String(), out, buf.String(), out) + } } } + + t.Run("Normal", func(t *testing.T) { + f(t, profSelfMapsTests) + }) + + t.Run("WithDeletedFile", func(t *testing.T) { + f(t, profSelfMapsTestsWithDeleted) + }) } // TestMapping checkes the mapping section of CPU profiles From f64c0b2a281fd1587c2e2e1c488cec0fa5de6e3e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 7 Sep 2018 12:45:49 +0200 Subject: [PATCH 0321/1663] debug/elf: add R_RISCV_32_PCREL relocation This were missed in CL 107339 as it is not documented (yet) in https://github.com/riscv/riscv-elf-psabi-doc/blob/master/riscv-elf.md But binutils already uses it. See https://github.com/riscv/riscv-elf-psabi-doc/issues/36 Change-Id: I1b084cbf70eb6ac966136bed1bb654883a97b6a9 Reviewed-on: https://go-review.googlesource.com/134015 Run-TryBot: Tobias Klauser Reviewed-by: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/debug/elf/elf.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/debug/elf/elf.go b/src/debug/elf/elf.go index 07c03e79996a9..96a67ce732728 100644 --- a/src/debug/elf/elf.go +++ b/src/debug/elf/elf.go @@ -2424,6 +2424,7 @@ const ( R_RISCV_SET8 R_RISCV = 54 /* Local label subtraction */ R_RISCV_SET16 R_RISCV = 55 /* Local label subtraction */ R_RISCV_SET32 R_RISCV = 56 /* Local label subtraction */ + R_RISCV_32_PCREL R_RISCV = 57 /* 32-bit PC relative */ ) var rriscvStrings = []intName{ @@ -2480,6 +2481,7 @@ var rriscvStrings = []intName{ {54, "R_RISCV_SET8"}, {55, "R_RISCV_SET16"}, {56, "R_RISCV_SET32"}, + {57, "R_RISCV_32_PCREL"}, } func (i R_RISCV) String() string { return stringName(uint32(i), rriscvStrings, false) } From 9facf35592457f0cdd1a9da665fd946002123007 Mon Sep 17 00:00:00 2001 From: Thanabodee Charoenpiriyakij Date: Wed, 5 Sep 2018 13:40:29 +0700 Subject: [PATCH 0322/1663] fmt: add example for Fprint Updates #27376 Change-Id: I0ceb672a9fcd7bbf491be1577d7f135ef35b2561 Reviewed-on: https://go-review.googlesource.com/133455 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/fmt/example_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index 1479b761b6e0f..6aeee03e43a93 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -68,6 +68,17 @@ func ExampleSprintln() { // "Today is 30 Aug\n" } +func ExampleFprint() { + n, err := fmt.Fprint(os.Stdout, "there", "are", 99, "gophers", "\n") + if err != nil { + panic(err) + } + fmt.Print(n) + // Output: + // thereare99gophers + // 18 +} + func ExampleFprintln() { n, err := fmt.Fprintln(os.Stdout, "there", "are", 99, "gophers") if err != nil { From b7182acf6101ba096a25073d8d083cca99ffcd06 Mon Sep 17 00:00:00 2001 From: Thanabodee Charoenpiriyakij Date: Fri, 7 Sep 2018 18:52:41 +0700 Subject: [PATCH 0323/1663] fmt: add example for Print Updates #27376 Change-Id: I2fa63b0d1981a419626072d985e6f3326f6013ff Reviewed-on: https://go-review.googlesource.com/134035 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/fmt/example_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index 6aeee03e43a93..a09af62757911 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -49,6 +49,17 @@ func ExampleSprintf() { // 15 } +func ExamplePrint() { + n, err := fmt.Print("there", "are", 99, "gophers", "\n") + if err != nil { + panic(err) + } + fmt.Print(n) + // Output: + // thereare99gophers + // 18 +} + func ExamplePrintln() { n, err := fmt.Println("there", "are", 99, "gophers") if err != nil { From 7bee8085daa9e8fef7e23c555d72c73ce96d2bfb Mon Sep 17 00:00:00 2001 From: Thanabodee Charoenpiriyakij Date: Fri, 7 Sep 2018 19:02:51 +0700 Subject: [PATCH 0324/1663] fmt: add example for Sprint Updates #27376 Change-Id: I9ce6541a95b5ecd13f3932558427de1f597df07a Reviewed-on: https://go-review.googlesource.com/134036 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/fmt/example_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index a09af62757911..0ec374d217213 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -122,3 +122,12 @@ func ExampleFscanln() { // 3: dmr, 1771, 1.618034 // 3: ken, 271828, 3.141590 } + +func ExampleSprint() { + s := fmt.Sprint("there", "are", "99", "gophers") + fmt.Println(s) + fmt.Println(len(s)) + // Output: + // thereare99gophers + // 17 +} From d8c8a1421837e86d5b5a20f2925b783c594ef9d6 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 30 Aug 2018 10:23:54 +0200 Subject: [PATCH 0325/1663] cmd/dist, go/types: add support for GOARCH=sparc64 This is needed in addition to CL 102555 in order to be able to generate Go type definitions for linux/sparc64 in the golang.org/x/sys/unix package. Change-Id: I928185e320572fecb0c89396f871ea16cba8b9a6 Reviewed-on: https://go-review.googlesource.com/132155 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/dist/build.go | 2 ++ src/cmd/vet/all/main.go | 6 +++--- src/go/types/sizes.go | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index d4f9dc4fbb5f4..b27d3aac4de03 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -69,6 +69,7 @@ var okgoarch = []string{ "ppc64le", "riscv64", "s390x", + "sparc64", "wasm", } @@ -1407,6 +1408,7 @@ var cgoEnabled = map[string]bool{ "linux/mips64le": true, "linux/riscv64": true, "linux/s390x": true, + "linux/sparc64": true, "android/386": true, "android/amd64": true, "android/arm": true, diff --git a/src/cmd/vet/all/main.go b/src/cmd/vet/all/main.go index e7fe4edc2a41d..24dfafd7bf67a 100644 --- a/src/cmd/vet/all/main.go +++ b/src/cmd/vet/all/main.go @@ -192,9 +192,9 @@ func vetPlatforms(pp []platform) { } func (p platform) vet() { - if p.os == "linux" && p.arch == "riscv64" { - // TODO(tklauser): enable as soon as the riscv64 port has fully landed - fmt.Println("skipping linux/riscv64") + if p.os == "linux" && (p.arch == "riscv64" || p.arch == "sparc64") { + // TODO(tklauser): enable as soon as these ports have fully landed + fmt.Printf("skipping %s/%s\n", p.os, p.arch) return } diff --git a/src/go/types/sizes.go b/src/go/types/sizes.go index 7b5410167f99b..f890c303774ae 100644 --- a/src/go/types/sizes.go +++ b/src/go/types/sizes.go @@ -169,6 +169,7 @@ var gcArchSizes = map[string]*StdSizes{ "ppc64le": {8, 8}, "riscv64": {8, 8}, "s390x": {8, 8}, + "sparc64": {8, 8}, "wasm": {8, 8}, // When adding more architectures here, // update the doc string of SizesFor below. @@ -179,7 +180,7 @@ var gcArchSizes = map[string]*StdSizes{ // // Supported architectures for compiler "gc": // "386", "arm", "arm64", "amd64", "amd64p32", "mips", "mipsle", -// "mips64", "mips64le", "ppc64", "ppc64le", "riscv64", "s390x", "wasm". +// "mips64", "mips64le", "ppc64", "ppc64le", "riscv64", "s390x", "sparc64", "wasm". func SizesFor(compiler, arch string) Sizes { if compiler != "gc" { return nil From 204cc14bddf6bdd553fd6139e395b1e203ce1d48 Mon Sep 17 00:00:00 2001 From: erifan01 Date: Sat, 30 Jun 2018 06:48:51 +0000 Subject: [PATCH 0326/1663] cmd/compile: implement non-constant rotates using ROR on arm64 Add some rules to match the Go code like: y &= 63 x << y | x >> (64-y) or y &= 63 x >> y | x << (64-y) as a ROR instruction. Make math/bits.RotateLeft faster on arm64. Extends CL 132435 to arm64. Benchmarks of math/bits.RotateLeftxxN: name old time/op new time/op delta RotateLeft-8 3.548750ns +- 1% 2.003750ns +- 0% -43.54% (p=0.000 n=8+8) RotateLeft8-8 3.925000ns +- 0% 3.925000ns +- 0% ~ (p=1.000 n=8+8) RotateLeft16-8 3.925000ns +- 0% 3.927500ns +- 0% ~ (p=0.608 n=8+8) RotateLeft32-8 3.925000ns +- 0% 2.002500ns +- 0% -48.98% (p=0.000 n=8+8) RotateLeft64-8 3.536250ns +- 0% 2.003750ns +- 0% -43.34% (p=0.000 n=8+8) Change-Id: I77622cd7f39b917427e060647321f5513973232c Reviewed-on: https://go-review.googlesource.com/122542 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/arm64/ssa.go | 4 +- src/cmd/compile/internal/gc/ssa.go | 4 +- src/cmd/compile/internal/ssa/gen/ARM64.rules | 40 +- src/cmd/compile/internal/ssa/gen/ARM64Ops.go | 2 + src/cmd/compile/internal/ssa/opGen.go | 30 + src/cmd/compile/internal/ssa/rewriteARM64.go | 31374 +++++++++-------- test/codegen/mathbits.go | 3 + 7 files changed, 17186 insertions(+), 14271 deletions(-) diff --git a/src/cmd/compile/internal/arm64/ssa.go b/src/cmd/compile/internal/arm64/ssa.go index db7064cff0e1b..192654158276d 100644 --- a/src/cmd/compile/internal/arm64/ssa.go +++ b/src/cmd/compile/internal/arm64/ssa.go @@ -195,7 +195,9 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ssa.OpARM64FNMULS, ssa.OpARM64FNMULD, ssa.OpARM64FDIVS, - ssa.OpARM64FDIVD: + ssa.OpARM64FDIVD, + ssa.OpARM64ROR, + ssa.OpARM64RORW: r := v.Reg() r1 := v.Args[0].Reg() r2 := v.Args[1].Reg() diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 00ff7d4bd56bc..bb076f870849d 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -3361,12 +3361,12 @@ func init() { func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return s.newValue2(ssa.OpRotateLeft32, types.Types[TUINT32], args[0], args[1]) }, - sys.AMD64, sys.S390X) + sys.AMD64, sys.ARM64, sys.S390X) addF("math/bits", "RotateLeft64", func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return s.newValue2(ssa.OpRotateLeft64, types.Types[TUINT64], args[0], args[1]) }, - sys.AMD64, sys.S390X) + sys.AMD64, sys.ARM64, sys.S390X) alias("math/bits", "RotateLeft", "math/bits", "RotateLeft64", p8...) makeOnesCountAMD64 := func(op64 ssa.Op, op32 ssa.Op) func(s *state, n *Node, args []*ssa.Value) *ssa.Value { diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index 6c8f3860d1867..4c9d9a6f7a38f 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -89,6 +89,10 @@ (Round x) -> (FRINTAD x) (Trunc x) -> (FRINTZD x) +// lowering rotates +(RotateLeft32 x y) -> (RORW x (NEG y)) +(RotateLeft64 x y) -> (ROR x (NEG y)) + (Ctz64NonZero x) -> (Ctz64 x) (Ctz32NonZero x) -> (Ctz32 x) @@ -127,6 +131,8 @@ // shifts // hardware instruction uses only the low 6 bits of the shift // we compare to 64 to ensure Go semantics for large shifts +// Rules about rotates with non-const shift are based on the following rules, +// if the following rules change, please also modify the rules based on them. (Lsh64x64 x y) -> (CSEL {OpARM64LessThanU} (SLL x y) (Const64 [0]) (CMPconst [64] y)) (Lsh64x32 x y) -> (CSEL {OpARM64LessThanU} (SLL x (ZeroExt32to64 y)) (Const64 [0]) (CMPconst [64] (ZeroExt32to64 y))) (Lsh64x16 x y) -> (CSEL {OpARM64LessThanU} (SLL x (ZeroExt16to64 y)) (Const64 [0]) (CMPconst [64] (ZeroExt16to64 y))) @@ -1592,7 +1598,7 @@ (ORNshiftRL x (SRLconst x [c]) [d]) && c==d -> (MOVDconst [-1]) (ORNshiftRA x (SRAconst x [c]) [d]) && c==d -> (MOVDconst [-1]) -// Generate rotates +// Generate rotates with const shift (ADDshiftLL [c] (SRLconst x [64-c]) x) -> (RORconst [64-c] x) ( ORshiftLL [c] (SRLconst x [64-c]) x) -> (RORconst [64-c] x) (XORshiftLL [c] (SRLconst x [64-c]) x) -> (RORconst [64-c] x) @@ -1610,6 +1616,38 @@ ( ORshiftRL [c] (SLLconst x [32-c]) (MOVWUreg x)) && c < 32 && t.Size() == 4 -> (RORWconst [c] x) (XORshiftRL [c] (SLLconst x [32-c]) (MOVWUreg x)) && c < 32 && t.Size() == 4 -> (RORWconst [c] x) +(RORconst [c] (RORconst [d] x)) -> (RORconst [(c+d)&63] x) +(RORWconst [c] (RORWconst [d] x)) -> (RORWconst [(c+d)&31] x) + +// Generate rotates with non-const shift. +// These rules match the Go source code like +// y &= 63 +// x << y | x >> (64-y) +// "|" can also be "^" or "+". +// As arm64 does not have a ROL instruction, so ROL(x, y) is replaced by ROR(x, -y). +((ADD|OR|XOR) (SLL x (ANDconst [63] y)) + (CSEL0 {cc} (SRL x (SUB (MOVDconst [64]) (ANDconst [63] y))) + (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y))))) && cc.(Op) == OpARM64LessThanU + -> (ROR x (NEG y)) +((ADD|OR|XOR) (SRL x (ANDconst [63] y)) + (CSEL0 {cc} (SLL x (SUB (MOVDconst [64]) (ANDconst [63] y))) + (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y))))) && cc.(Op) == OpARM64LessThanU + -> (ROR x y) + +// These rules match the Go source code like +// y &= 31 +// x << y | x >> (32-y) +// "|" can also be "^" or "+". +// As arm64 does not have a ROLW instruction, so ROLW(x, y) is replaced by RORW(x, -y). +((ADD|OR|XOR) (SLL x (ANDconst [31] y)) + (CSEL0 {cc} (SRL (MOVWUreg x) (SUB (MOVDconst [32]) (ANDconst [31] y))) + (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y))))) && cc.(Op) == OpARM64LessThanU + -> (RORW x (NEG y)) +((ADD|OR|XOR) (SRL (MOVWUreg x) (ANDconst [31] y)) + (CSEL0 {cc} (SLL x (SUB (MOVDconst [32]) (ANDconst [31] y))) + (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y))))) && cc.(Op) == OpARM64LessThanU + -> (RORW x y) + // Extract from reg pair (ADDshiftLL [c] (SRLconst x [64-c]) x2) -> (EXTRconst [64-c] x2 x) ( ORshiftLL [c] (SRLconst x [64-c]) x2) -> (EXTRconst [64-c] x2 x) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go index eb0ad530a1a4b..43230fbf70faf 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go @@ -248,6 +248,8 @@ func init() { {name: "SRLconst", argLength: 1, reg: gp11, asm: "LSR", aux: "Int64"}, // arg0 >> auxInt, unsigned {name: "SRA", argLength: 2, reg: gp21, asm: "ASR"}, // arg0 >> arg1, signed, shift amount is mod 64 {name: "SRAconst", argLength: 1, reg: gp11, asm: "ASR", aux: "Int64"}, // arg0 >> auxInt, signed + {name: "ROR", argLength: 2, reg: gp21, asm: "ROR"}, // arg0 right rotate by (arg1 mod 64) bits + {name: "RORW", argLength: 2, reg: gp21, asm: "RORW"}, // arg0 right rotate by (arg1 mod 32) bits {name: "RORconst", argLength: 1, reg: gp11, asm: "ROR", aux: "Int64"}, // arg0 right rotate by auxInt bits {name: "RORWconst", argLength: 1, reg: gp11, asm: "RORW", aux: "Int64"}, // uint32(arg0) right rotate by auxInt bits {name: "EXTRconst", argLength: 2, reg: gp21, asm: "EXTR", aux: "Int64"}, // extract 64 bits from arg0:arg1 starting at lsb auxInt diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 5bf7021432699..30c57874f6a17 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -1139,6 +1139,8 @@ const ( OpARM64SRLconst OpARM64SRA OpARM64SRAconst + OpARM64ROR + OpARM64RORW OpARM64RORconst OpARM64RORWconst OpARM64EXTRconst @@ -15104,6 +15106,34 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "ROR", + argLen: 2, + asm: arm64.AROR, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, + { + name: "RORW", + argLen: 2, + asm: arm64.ARORW, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, { name: "RORconst", auxType: auxInt64, diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index 219bc3676d8ee..1dcbd9348099a 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -16,7 +16,7 @@ var _ = types.TypeMem // in case not otherwise used func rewriteValueARM64(v *Value) bool { switch v.Op { case OpARM64ADD: - return rewriteValueARM64_OpARM64ADD_0(v) || rewriteValueARM64_OpARM64ADD_10(v) + return rewriteValueARM64_OpARM64ADD_0(v) || rewriteValueARM64_OpARM64ADD_10(v) || rewriteValueARM64_OpARM64ADD_20(v) case OpARM64ADDconst: return rewriteValueARM64_OpARM64ADDconst_0(v) case OpARM64ADDshiftLL: @@ -256,7 +256,7 @@ func rewriteValueARM64(v *Value) bool { case OpARM64NotEqual: return rewriteValueARM64_OpARM64NotEqual_0(v) case OpARM64OR: - return rewriteValueARM64_OpARM64OR_0(v) || rewriteValueARM64_OpARM64OR_10(v) || rewriteValueARM64_OpARM64OR_20(v) || rewriteValueARM64_OpARM64OR_30(v) + return rewriteValueARM64_OpARM64OR_0(v) || rewriteValueARM64_OpARM64OR_10(v) || rewriteValueARM64_OpARM64OR_20(v) || rewriteValueARM64_OpARM64OR_30(v) || rewriteValueARM64_OpARM64OR_40(v) case OpARM64ORN: return rewriteValueARM64_OpARM64ORN_0(v) case OpARM64ORNshiftLL: @@ -273,6 +273,10 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64ORshiftRA_0(v) case OpARM64ORshiftRL: return rewriteValueARM64_OpARM64ORshiftRL_0(v) + case OpARM64RORWconst: + return rewriteValueARM64_OpARM64RORWconst_0(v) + case OpARM64RORconst: + return rewriteValueARM64_OpARM64RORconst_0(v) case OpARM64SLL: return rewriteValueARM64_OpARM64SLL_0(v) case OpARM64SLLconst: @@ -733,6 +737,10 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpPopCount32_0(v) case OpPopCount64: return rewriteValueARM64_OpPopCount64_0(v) + case OpRotateLeft32: + return rewriteValueARM64_OpRotateLeft32_0(v) + case OpRotateLeft64: + return rewriteValueARM64_OpRotateLeft64_0(v) case OpRound: return rewriteValueARM64_OpRound_0(v) case OpRound32F: @@ -1090,6 +1098,10 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { return false } func rewriteValueARM64_OpARM64ADD_10(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (ADD x (NEG y)) // cond: // result: (SUB x y) @@ -1248,1935 +1260,1013 @@ func rewriteValueARM64_OpARM64ADD_10(v *Value) bool { v.AddArg(y) return true } - return false -} -func rewriteValueARM64_OpARM64ADDconst_0(v *Value) bool { - // match: (ADDconst [off1] (MOVDaddr [off2] {sym} ptr)) - // cond: - // result: (MOVDaddr [off1+off2] {sym} ptr) + // match: (ADD (SLL x (ANDconst [63] y)) (CSEL0 {cc} (SRL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x (NEG y)) for { - off1 := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + if v_0.Op != OpARM64SLL { break } - off2 := v_0.AuxInt - sym := v_0.Aux - ptr := v_0.Args[0] - v.reset(OpARM64MOVDaddr) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - return true - } - // match: (ADDconst [0] x) - // cond: - // result: x - for { - if v.AuxInt != 0 { + _ = v_0.Args[1] + x := v_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { break } - x := v.Args[0] - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (ADDconst [c] (MOVDconst [d])) - // cond: - // result: (MOVDconst [c+d]) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + t := v_0_1.Type + if v_0_1.AuxInt != 63 { break } - d := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = c + d - return true - } - // match: (ADDconst [c] (ADDconst [d] x)) - // cond: - // result: (ADDconst [c+d] x) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + y := v_0_1.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64CSEL0 { break } - d := v_0.AuxInt - x := v_0.Args[0] - v.reset(OpARM64ADDconst) - v.AuxInt = c + d - v.AddArg(x) - return true - } - // match: (ADDconst [c] (SUBconst [d] x)) - // cond: - // result: (ADDconst [c-d] x) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SUBconst { + if v_1.Type != typ.UInt64 { break } - d := v_0.AuxInt - x := v_0.Args[0] - v.reset(OpARM64ADDconst) - v.AuxInt = c - d - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64ADDshiftLL_0(v *Value) bool { - b := v.Block - _ = b - // match: (ADDshiftLL (MOVDconst [c]) x [d]) - // cond: - // result: (ADDconst [c] (SLLconst x [d])) - for { - d := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SRL { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64ADDconst) - v.AuxInt = c - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = d - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (ADDshiftLL x (MOVDconst [c]) [d]) - // cond: - // result: (ADDconst x [int64(uint64(c)< [c] (UBFX [bfc] x) x) - // cond: c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c) - // result: (RORWconst [32-c] x) - for { - t := v.Type - c := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64UBFX { + _ = v_1_0_1.Args[1] + v_1_0_1_0 := v_1_0_1.Args[0] + if v_1_0_1_0.Op != OpARM64MOVDconst { break } - bfc := v_0.AuxInt - x := v_0.Args[0] - if x != v.Args[1] { + if v_1_0_1_0.AuxInt != 64 { break } - if !(c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c)) { + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64RORWconst) - v.AuxInt = 32 - c - v.AddArg(x) - return true - } - // match: (ADDshiftLL [c] (SRLconst x [64-c]) x2) - // cond: - // result: (EXTRconst [64-c] x2 x) - for { - c := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { + if v_1_0_1_1.Type != t { break } - if v_0.AuxInt != 64-c { + if v_1_0_1_1.AuxInt != 63 { break } - x := v_0.Args[0] - x2 := v.Args[1] - v.reset(OpARM64EXTRconst) - v.AuxInt = 64 - c - v.AddArg(x2) - v.AddArg(x) - return true - } - // match: (ADDshiftLL [c] (UBFX [bfc] x) x2) - // cond: c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c) - // result: (EXTRWconst [32-c] x2 x) - for { - t := v.Type - c := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64UBFX { + if y != v_1_0_1_1.Args[0] { break } - bfc := v_0.AuxInt - x := v_0.Args[0] - x2 := v.Args[1] - if !(c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c)) { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64CMPconst { break } - v.reset(OpARM64EXTRWconst) - v.AuxInt = 32 - c - v.AddArg(x2) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64ADDshiftRA_0(v *Value) bool { - b := v.Block - _ = b - // match: (ADDshiftRA (MOVDconst [c]) x [d]) - // cond: - // result: (ADDconst [c] (SRAconst x [d])) - for { - d := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_1_1.AuxInt != 64 { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64ADDconst) - v.AuxInt = c - v0 := b.NewValue0(v.Pos, OpARM64SRAconst, x.Type) - v0.AuxInt = d - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (ADDshiftRA x (MOVDconst [c]) [d]) - // cond: - // result: (ADDconst x [c>>uint64(d)]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { break } - c := v_1.AuxInt - v.reset(OpARM64ADDconst) - v.AuxInt = c >> uint64(d) + if v_1_1_0.Type != t { + break + } + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { + break + } + if v_1_1_0_0.AuxInt != 64 { + break + } + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { + break + } + if v_1_1_0_1.Type != t { + break + } + if v_1_1_0_1.AuxInt != 63 { + break + } + if y != v_1_1_0_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64ROR) v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) + v.AddArg(v0) return true } - return false -} -func rewriteValueARM64_OpARM64ADDshiftRL_0(v *Value) bool { - b := v.Block - _ = b - // match: (ADDshiftRL (MOVDconst [c]) x [d]) - // cond: - // result: (ADDconst [c] (SRLconst x [d])) + // match: (ADD (CSEL0 {cc} (SRL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y)))) (SLL x (ANDconst [63] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x (NEG y)) for { - d := v.AuxInt _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64CSEL0 { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64ADDconst) - v.AuxInt = c - v0 := b.NewValue0(v.Pos, OpARM64SRLconst, x.Type) - v0.AuxInt = d - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (ADDshiftRL x (MOVDconst [c]) [d]) - // cond: - // result: (ADDconst x [int64(uint64(c)>>uint64(d))]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0.Type != typ.UInt64 { break } - c := v_1.AuxInt - v.reset(OpARM64ADDconst) - v.AuxInt = int64(uint64(c) >> uint64(d)) - v.AddArg(x) - return true - } - // match: (ADDshiftRL [c] (SLLconst x [64-c]) x) - // cond: - // result: (RORconst [ c] x) - for { - c := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + cc := v_0.Aux + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SRL { break } - if v_0.AuxInt != 64-c { + if v_0_0.Type != typ.UInt64 { break } - x := v_0.Args[0] - if x != v.Args[1] { + _ = v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { break } - v.reset(OpARM64RORconst) - v.AuxInt = c - v.AddArg(x) - return true - } - // match: (ADDshiftRL [c] (SLLconst x [32-c]) (MOVWUreg x)) - // cond: c < 32 && t.Size() == 4 - // result: (RORWconst [c] x) - for { - t := v.Type - c := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != 32-c { + if v_0_0_1_0.AuxInt != 64 { break } - x := v_0.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWUreg { + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { break } - if x != v_1.Args[0] { + if v_0_0_1_1.Type != t { break } - if !(c < 32 && t.Size() == 4) { + if v_0_0_1_1.AuxInt != 63 { break } - v.reset(OpARM64RORWconst) - v.AuxInt = c - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64AND_0(v *Value) bool { - // match: (AND x (MOVDconst [c])) - // cond: - // result: (ANDconst [c] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + y := v_0_0_1_1.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64CMPconst { break } - c := v_1.AuxInt - v.reset(OpARM64ANDconst) - v.AuxInt = c - v.AddArg(x) - return true - } - // match: (AND (MOVDconst [c]) x) - // cond: - // result: (ANDconst [c] x) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_1.AuxInt != 64 { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64ANDconst) - v.AuxInt = c - v.AddArg(x) - return true - } - // match: (AND x x) - // cond: - // result: x - for { - _ = v.Args[1] - x := v.Args[0] - if x != v.Args[1] { + v_0_1_0 := v_0_1.Args[0] + if v_0_1_0.Op != OpARM64SUB { break } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (AND x (MVN y)) - // cond: - // result: (BIC x y) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MVN { + if v_0_1_0.Type != t { break } - y := v_1.Args[0] - v.reset(OpARM64BIC) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (AND (MVN y) x) - // cond: - // result: (BIC x y) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MVN { + _ = v_0_1_0.Args[1] + v_0_1_0_0 := v_0_1_0.Args[0] + if v_0_1_0_0.Op != OpARM64MOVDconst { break } - y := v_0.Args[0] - x := v.Args[1] - v.reset(OpARM64BIC) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (AND x0 x1:(SLLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (ANDshiftLL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SLLconst { + if v_0_1_0_0.AuxInt != 64 { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + v_0_1_0_1 := v_0_1_0.Args[1] + if v_0_1_0_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64ANDshiftLL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (AND x1:(SLLconst [c] y) x0) - // cond: clobberIfDead(x1) - // result: (ANDshiftLL x0 y [c]) - for { - _ = v.Args[1] - x1 := v.Args[0] - if x1.Op != OpARM64SLLconst { + if v_0_1_0_1.Type != t { break } - c := x1.AuxInt - y := x1.Args[0] - x0 := v.Args[1] - if !(clobberIfDead(x1)) { + if v_0_1_0_1.AuxInt != 63 { break } - v.reset(OpARM64ANDshiftLL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (AND x0 x1:(SRLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (ANDshiftRL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRLconst { + if y != v_0_1_0_1.Args[0] { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + v_1 := v.Args[1] + if v_1.Op != OpARM64SLL { break } - v.reset(OpARM64ANDshiftRL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (AND x1:(SRLconst [c] y) x0) - // cond: clobberIfDead(x1) - // result: (ANDshiftRL x0 y [c]) - for { - _ = v.Args[1] - x1 := v.Args[0] - if x1.Op != OpARM64SRLconst { + _ = v_1.Args[1] + if x != v_1.Args[0] { break } - c := x1.AuxInt - y := x1.Args[0] - x0 := v.Args[1] - if !(clobberIfDead(x1)) { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64ANDshiftRL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (AND x0 x1:(SRAconst [c] y)) - // cond: clobberIfDead(x1) - // result: (ANDshiftRA x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRAconst { + if v_1_1.Type != t { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_1_1.AuxInt != 63 { break } - v.reset(OpARM64ANDshiftRA) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) + if y != v_1_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64ROR) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) + v.AddArg(v0) return true } return false } -func rewriteValueARM64_OpARM64AND_10(v *Value) bool { - // match: (AND x1:(SRAconst [c] y) x0) - // cond: clobberIfDead(x1) - // result: (ANDshiftRA x0 y [c]) +func rewriteValueARM64_OpARM64ADD_20(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ + // match: (ADD (SRL x (ANDconst [63] y)) (CSEL0 {cc} (SLL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x y) for { _ = v.Args[1] - x1 := v.Args[0] - if x1.Op != OpARM64SRAconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64SRL { break } - c := x1.AuxInt - y := x1.Args[0] - x0 := v.Args[1] - if !(clobberIfDead(x1)) { + if v_0.Type != typ.UInt64 { break } - v.reset(OpARM64ANDshiftRA) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - return false -} -func rewriteValueARM64_OpARM64ANDconst_0(v *Value) bool { - // match: (ANDconst [0] _) - // cond: - // result: (MOVDconst [0]) - for { - if v.AuxInt != 0 { + _ = v_0.Args[1] + x := v_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (ANDconst [-1] x) - // cond: - // result: x - for { - if v.AuxInt != -1 { + t := v_0_1.Type + if v_0_1.AuxInt != 63 { break } - x := v.Args[0] - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (ANDconst [c] (MOVDconst [d])) - // cond: - // result: (MOVDconst [c&d]) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + y := v_0_1.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64CSEL0 { break } - d := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = c & d - return true - } - // match: (ANDconst [c] (ANDconst [d] x)) - // cond: - // result: (ANDconst [c&d] x) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64ANDconst { + if v_1.Type != typ.UInt64 { break } - d := v_0.AuxInt - x := v_0.Args[0] - v.reset(OpARM64ANDconst) - v.AuxInt = c & d - v.AddArg(x) - return true - } - // match: (ANDconst [c] (MOVWUreg x)) - // cond: - // result: (ANDconst [c&(1<<32-1)] x) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVWUreg { + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SLL { break } - x := v_0.Args[0] - v.reset(OpARM64ANDconst) - v.AuxInt = c & (1<<32 - 1) - v.AddArg(x) - return true - } - // match: (ANDconst [c] (MOVHUreg x)) - // cond: - // result: (ANDconst [c&(1<<16-1)] x) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVHUreg { + _ = v_1_0.Args[1] + if x != v_1_0.Args[0] { break } - x := v_0.Args[0] - v.reset(OpARM64ANDconst) - v.AuxInt = c & (1<<16 - 1) - v.AddArg(x) - return true - } - // match: (ANDconst [c] (MOVBUreg x)) - // cond: - // result: (ANDconst [c&(1<<8-1)] x) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVBUreg { + v_1_0_1 := v_1_0.Args[1] + if v_1_0_1.Op != OpARM64SUB { break } - x := v_0.Args[0] - v.reset(OpARM64ANDconst) - v.AuxInt = c & (1<<8 - 1) - v.AddArg(x) - return true - } - // match: (ANDconst [ac] (SLLconst [sc] x)) - // cond: isARM64BFMask(sc, ac, sc) - // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(ac, sc))] x) - for { - ac := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_1_0_1.Type != t { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, ac, sc)) { + _ = v_1_0_1.Args[1] + v_1_0_1_0 := v_1_0_1.Args[0] + if v_1_0_1_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64UBFIZ) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(ac, sc)) - v.AddArg(x) - return true - } - // match: (ANDconst [ac] (SRLconst [sc] x)) - // cond: isARM64BFMask(sc, ac, 0) - // result: (UBFX [arm64BFAuxInt(sc, arm64BFWidth(ac, 0))] x) - for { - ac := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { + if v_1_0_1_0.AuxInt != 64 { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, ac, 0)) { + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(ac, 0)) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64ANDshiftLL_0(v *Value) bool { - b := v.Block - _ = b - // match: (ANDshiftLL (MOVDconst [c]) x [d]) - // cond: - // result: (ANDconst [c] (SLLconst x [d])) - for { - d := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_1_0_1_1.Type != t { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64ANDconst) - v.AuxInt = c - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = d - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (ANDshiftLL x (MOVDconst [c]) [d]) - // cond: - // result: (ANDconst x [int64(uint64(c)< x [d])) - for { - d := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64ANDconst) - v.AuxInt = c - v0 := b.NewValue0(v.Pos, OpARM64SRAconst, x.Type) - v0.AuxInt = d - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (ANDshiftRA x (MOVDconst [c]) [d]) - // cond: - // result: (ANDconst x [c>>uint64(d)]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_1_0.Type != t { break } - c := v_1.AuxInt - v.reset(OpARM64ANDconst) - v.AuxInt = c >> uint64(d) - v.AddArg(x) - return true - } - // match: (ANDshiftRA x y:(SRAconst x [c]) [d]) - // cond: c==d - // result: y - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - y := v.Args[1] - if y.Op != OpARM64SRAconst { + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { break } - c := y.AuxInt - if x != y.Args[0] { + if v_1_1_0_0.AuxInt != 64 { break } - if !(c == d) { + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { break } - v.reset(OpCopy) - v.Type = y.Type + if v_1_1_0_1.Type != t { + break + } + if v_1_1_0_1.AuxInt != 63 { + break + } + if y != v_1_1_0_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64ROR) + v.AddArg(x) v.AddArg(y) return true } - return false -} -func rewriteValueARM64_OpARM64ANDshiftRL_0(v *Value) bool { - b := v.Block - _ = b - // match: (ANDshiftRL (MOVDconst [c]) x [d]) - // cond: - // result: (ANDconst [c] (SRLconst x [d])) + // match: (ADD (CSEL0 {cc} (SLL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y)))) (SRL x (ANDconst [63] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x y) for { - d := v.AuxInt _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64CSEL0 { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64ANDconst) - v.AuxInt = c - v0 := b.NewValue0(v.Pos, OpARM64SRLconst, x.Type) - v0.AuxInt = d - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (ANDshiftRL x (MOVDconst [c]) [d]) - // cond: - // result: (ANDconst x [int64(uint64(c)>>uint64(d))]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0.Type != typ.UInt64 { break } - c := v_1.AuxInt - v.reset(OpARM64ANDconst) - v.AuxInt = int64(uint64(c) >> uint64(d)) - v.AddArg(x) - return true - } - // match: (ANDshiftRL x y:(SRLconst x [c]) [d]) - // cond: c==d - // result: y - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - y := v.Args[1] - if y.Op != OpARM64SRLconst { + cc := v_0.Aux + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SLL { break } - c := y.AuxInt - if x != y.Args[0] { + _ = v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { break } - if !(c == d) { + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { break } - v.reset(OpCopy) - v.Type = y.Type - v.AddArg(y) - return true - } - return false -} -func rewriteValueARM64_OpARM64BIC_0(v *Value) bool { - // match: (BIC x (MOVDconst [c])) - // cond: - // result: (ANDconst [^c] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0_0_1_0.AuxInt != 64 { break } - c := v_1.AuxInt - v.reset(OpARM64ANDconst) - v.AuxInt = ^c - v.AddArg(x) - return true - } - // match: (BIC x x) - // cond: - // result: (MOVDconst [0]) - for { - _ = v.Args[1] - x := v.Args[0] - if x != v.Args[1] { + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (BIC x0 x1:(SLLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (BICshiftLL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SLLconst { + if v_0_0_1_1.Type != t { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_0_0_1_1.AuxInt != 63 { break } - v.reset(OpARM64BICshiftLL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (BIC x0 x1:(SRLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (BICshiftRL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRLconst { + y := v_0_0_1_1.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64CMPconst { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_0_1.AuxInt != 64 { break } - v.reset(OpARM64BICshiftRL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (BIC x0 x1:(SRAconst [c] y)) - // cond: clobberIfDead(x1) - // result: (BICshiftRA x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRAconst { + v_0_1_0 := v_0_1.Args[0] + if v_0_1_0.Op != OpARM64SUB { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_0_1_0.Type != t { break } - v.reset(OpARM64BICshiftRA) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - return false -} -func rewriteValueARM64_OpARM64BICshiftLL_0(v *Value) bool { - // match: (BICshiftLL x (MOVDconst [c]) [d]) - // cond: - // result: (ANDconst x [^int64(uint64(c)<>uint64(d))]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0_1_0_1.AuxInt != 63 { + break + } + if y != v_0_1_0_1.Args[0] { break } - c := v_1.AuxInt - v.reset(OpARM64ANDconst) - v.AuxInt = ^(c >> uint64(d)) - v.AddArg(x) - return true - } - // match: (BICshiftRA x (SRAconst x [c]) [d]) - // cond: c==d - // result: (MOVDconst [0]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SRAconst { + if v_1.Op != OpARM64SRL { break } - c := v_1.AuxInt - if x != v_1.Args[0] { + if v_1.Type != typ.UInt64 { break } - if !(c == d) { + _ = v_1.Args[1] + if x != v_1.Args[0] { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - return false -} -func rewriteValueARM64_OpARM64BICshiftRL_0(v *Value) bool { - // match: (BICshiftRL x (MOVDconst [c]) [d]) - // cond: - // result: (ANDconst x [^int64(uint64(c)>>uint64(d))]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64ANDconst { break } - c := v_1.AuxInt - v.reset(OpARM64ANDconst) - v.AuxInt = ^int64(uint64(c) >> uint64(d)) - v.AddArg(x) - return true - } - // match: (BICshiftRL x (SRLconst x [c]) [d]) - // cond: c==d - // result: (MOVDconst [0]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + if v_1_1.Type != t { break } - c := v_1.AuxInt - if x != v_1.Args[0] { + if v_1_1.AuxInt != 63 { break } - if !(c == d) { + if y != v_1_1.Args[0] { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - return false -} -func rewriteValueARM64_OpARM64CMN_0(v *Value) bool { - // match: (CMN x (MOVDconst [c])) - // cond: - // result: (CMNconst [c] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if !(cc.(Op) == OpARM64LessThanU) { break } - c := v_1.AuxInt - v.reset(OpARM64CMNconst) - v.AuxInt = c + v.reset(OpARM64ROR) v.AddArg(x) + v.AddArg(y) return true } - // match: (CMN (MOVDconst [c]) x) - // cond: - // result: (CMNconst [c] x) + // match: (ADD (SLL x (ANDconst [31] y)) (CSEL0 {cc} (SRL (MOVWUreg x) (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x (NEG y)) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64SLL { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64CMNconst) - v.AuxInt = c - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64CMNW_0(v *Value) bool { - // match: (CMNW x (MOVDconst [c])) - // cond: - // result: (CMNWconst [c] x) - for { - _ = v.Args[1] - x := v.Args[0] + _ = v_0.Args[1] + x := v_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { + break + } + t := v_0_1.Type + if v_0_1.AuxInt != 31 { + break + } + y := v_0_1.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64CSEL0 { break } - c := v_1.AuxInt - v.reset(OpARM64CMNWconst) - v.AuxInt = c - v.AddArg(x) - return true - } - // match: (CMNW (MOVDconst [c]) x) - // cond: - // result: (CMNWconst [c] x) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_1.Type != typ.UInt32 { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64CMNWconst) - v.AuxInt = c - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64CMNWconst_0(v *Value) bool { - // match: (CMNWconst (MOVDconst [x]) [y]) - // cond: int32(x)==int32(-y) - // result: (FlagEQ) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SRL { break } - x := v_0.AuxInt - if !(int32(x) == int32(-y)) { + if v_1_0.Type != typ.UInt32 { break } - v.reset(OpARM64FlagEQ) - return true - } - // match: (CMNWconst (MOVDconst [x]) [y]) - // cond: int32(x)uint32(-y) - // result: (FlagLT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_0_1 := v_1_0.Args[1] + if v_1_0_1.Op != OpARM64SUB { break } - x := v_0.AuxInt - if !(int32(x) < int32(-y) && uint32(x) > uint32(-y)) { + if v_1_0_1.Type != t { break } - v.reset(OpARM64FlagLT_UGT) - return true - } - // match: (CMNWconst (MOVDconst [x]) [y]) - // cond: int32(x)>int32(-y) && uint32(x) int32(-y) && uint32(x) < uint32(-y)) { + if v_1_0_1_0.AuxInt != 32 { break } - v.reset(OpARM64FlagGT_ULT) - return true - } - // match: (CMNWconst (MOVDconst [x]) [y]) - // cond: int32(x)>int32(-y) && uint32(x)>uint32(-y) - // result: (FlagGT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { break } - x := v_0.AuxInt - if !(int32(x) > int32(-y) && uint32(x) > uint32(-y)) { + if v_1_0_1_1.Type != t { break } - v.reset(OpARM64FlagGT_UGT) - return true - } - return false -} -func rewriteValueARM64_OpARM64CMNconst_0(v *Value) bool { - // match: (CMNconst (MOVDconst [x]) [y]) - // cond: int64(x)==int64(-y) - // result: (FlagEQ) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_1_0_1_1.AuxInt != 31 { break } - x := v_0.AuxInt - if !(int64(x) == int64(-y)) { + if y != v_1_0_1_1.Args[0] { break } - v.reset(OpARM64FlagEQ) - return true - } - // match: (CMNconst (MOVDconst [x]) [y]) - // cond: int64(x)uint64(-y) - // result: (FlagLT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { break } - x := v_0.AuxInt - if !(int64(x) < int64(-y) && uint64(x) > uint64(-y)) { + if v_1_1_0.Type != t { break } - v.reset(OpARM64FlagLT_UGT) - return true - } - // match: (CMNconst (MOVDconst [x]) [y]) - // cond: int64(x)>int64(-y) && uint64(x) int64(-y) && uint64(x) < uint64(-y)) { + if v_1_1_0_0.AuxInt != 32 { break } - v.reset(OpARM64FlagGT_ULT) - return true - } - // match: (CMNconst (MOVDconst [x]) [y]) - // cond: int64(x)>int64(-y) && uint64(x)>uint64(-y) - // result: (FlagGT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { break } - x := v_0.AuxInt - if !(int64(x) > int64(-y) && uint64(x) > uint64(-y)) { + if v_1_1_0_1.Type != t { break } - v.reset(OpARM64FlagGT_UGT) - return true - } - return false -} -func rewriteValueARM64_OpARM64CMP_0(v *Value) bool { - b := v.Block - _ = b - // match: (CMP x (MOVDconst [c])) - // cond: - // result: (CMPconst [c] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_1_0_1.AuxInt != 31 { break } - c := v_1.AuxInt - v.reset(OpARM64CMPconst) - v.AuxInt = c + if y != v_1_1_0_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64RORW) v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) + v.AddArg(v0) return true } - // match: (CMP (MOVDconst [c]) x) - // cond: - // result: (InvertFlags (CMPconst [c] x)) + // match: (ADD (CSEL0 {cc} (SRL (MOVWUreg x) (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y)))) (SLL x (ANDconst [31] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x (NEG y)) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64CSEL0 { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64InvertFlags) - v0 := b.NewValue0(v.Pos, OpARM64CMPconst, types.TypeFlags) - v0.AuxInt = c - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (CMP x0 x1:(SLLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (CMPshiftLL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SLLconst { + if v_0.Type != typ.UInt32 { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + cc := v_0.Aux + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SRL { break } - v.reset(OpARM64CMPshiftLL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (CMP x0:(SLLconst [c] y) x1) - // cond: clobberIfDead(x0) - // result: (InvertFlags (CMPshiftLL x1 y [c])) - for { - _ = v.Args[1] - x0 := v.Args[0] - if x0.Op != OpARM64SLLconst { + if v_0_0.Type != typ.UInt32 { break } - c := x0.AuxInt - y := x0.Args[0] - x1 := v.Args[1] - if !(clobberIfDead(x0)) { + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + if v_0_0_0.Op != OpARM64MOVWUreg { break } - v.reset(OpARM64InvertFlags) - v0 := b.NewValue0(v.Pos, OpARM64CMPshiftLL, types.TypeFlags) - v0.AuxInt = c - v0.AddArg(x1) - v0.AddArg(y) - v.AddArg(v0) - return true - } - // match: (CMP x0 x1:(SRLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (CMPshiftRL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRLconst { + x := v_0_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64CMPshiftRL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (CMP x0:(SRLconst [c] y) x1) - // cond: clobberIfDead(x0) - // result: (InvertFlags (CMPshiftRL x1 y [c])) - for { - _ = v.Args[1] - x0 := v.Args[0] - if x0.Op != OpARM64SRLconst { + if v_0_0_1_0.AuxInt != 32 { break } - c := x0.AuxInt - y := x0.Args[0] - x1 := v.Args[1] - if !(clobberIfDead(x0)) { + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64InvertFlags) - v0 := b.NewValue0(v.Pos, OpARM64CMPshiftRL, types.TypeFlags) - v0.AuxInt = c - v0.AddArg(x1) - v0.AddArg(y) - v.AddArg(v0) - return true - } - // match: (CMP x0 x1:(SRAconst [c] y)) - // cond: clobberIfDead(x1) - // result: (CMPshiftRA x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRAconst { + if v_0_0_1_1.Type != t { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_0_0_1_1.AuxInt != 31 { break } - v.reset(OpARM64CMPshiftRA) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (CMP x0:(SRAconst [c] y) x1) - // cond: clobberIfDead(x0) - // result: (InvertFlags (CMPshiftRA x1 y [c])) - for { - _ = v.Args[1] - x0 := v.Args[0] - if x0.Op != OpARM64SRAconst { + y := v_0_0_1_1.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64CMPconst { break } - c := x0.AuxInt - y := x0.Args[0] - x1 := v.Args[1] - if !(clobberIfDead(x0)) { + if v_0_1.AuxInt != 64 { break } - v.reset(OpARM64InvertFlags) - v0 := b.NewValue0(v.Pos, OpARM64CMPshiftRA, types.TypeFlags) - v0.AuxInt = c - v0.AddArg(x1) - v0.AddArg(y) - v.AddArg(v0) - return true - } - return false -} -func rewriteValueARM64_OpARM64CMPW_0(v *Value) bool { - b := v.Block - _ = b - // match: (CMPW x (MOVDconst [c])) - // cond: - // result: (CMPWconst [int64(int32(c))] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_0_1_0 := v_0_1.Args[0] + if v_0_1_0.Op != OpARM64SUB { break } - c := v_1.AuxInt - v.reset(OpARM64CMPWconst) - v.AuxInt = int64(int32(c)) - v.AddArg(x) - return true - } - // match: (CMPW (MOVDconst [c]) x) - // cond: - // result: (InvertFlags (CMPWconst [int64(int32(c))] x)) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_1_0.Type != t { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64InvertFlags) - v0 := b.NewValue0(v.Pos, OpARM64CMPWconst, types.TypeFlags) - v0.AuxInt = int64(int32(c)) - v0.AddArg(x) - v.AddArg(v0) - return true - } - return false -} -func rewriteValueARM64_OpARM64CMPWconst_0(v *Value) bool { - // match: (CMPWconst (MOVDconst [x]) [y]) - // cond: int32(x)==int32(y) - // result: (FlagEQ) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v_0_1_0.Args[1] + v_0_1_0_0 := v_0_1_0.Args[0] + if v_0_1_0_0.Op != OpARM64MOVDconst { break } - x := v_0.AuxInt - if !(int32(x) == int32(y)) { + if v_0_1_0_0.AuxInt != 32 { break } - v.reset(OpARM64FlagEQ) - return true - } - // match: (CMPWconst (MOVDconst [x]) [y]) - // cond: int32(x)uint32(y) - // result: (FlagLT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_1_0_1.AuxInt != 31 { break } - x := v_0.AuxInt - if !(int32(x) < int32(y) && uint32(x) > uint32(y)) { + if y != v_0_1_0_1.Args[0] { break } - v.reset(OpARM64FlagLT_UGT) - return true - } - // match: (CMPWconst (MOVDconst [x]) [y]) - // cond: int32(x)>int32(y) && uint32(x) int32(y) && uint32(x) < uint32(y)) { + _ = v_1.Args[1] + if x != v_1.Args[0] { break } - v.reset(OpARM64FlagGT_ULT) - return true - } - // match: (CMPWconst (MOVDconst [x]) [y]) - // cond: int32(x)>int32(y) && uint32(x)>uint32(y) - // result: (FlagGT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64ANDconst { break } - x := v_0.AuxInt - if !(int32(x) > int32(y) && uint32(x) > uint32(y)) { + if v_1_1.Type != t { break } - v.reset(OpARM64FlagGT_UGT) - return true - } - // match: (CMPWconst (MOVBUreg _) [c]) - // cond: 0xff < int32(c) - // result: (FlagLT_ULT) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVBUreg { + if v_1_1.AuxInt != 31 { break } - if !(0xff < int32(c)) { + if y != v_1_1.Args[0] { break } - v.reset(OpARM64FlagLT_ULT) + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64RORW) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) + v.AddArg(v0) return true } - // match: (CMPWconst (MOVHUreg _) [c]) - // cond: 0xffff < int32(c) - // result: (FlagLT_ULT) + // match: (ADD (SRL (MOVWUreg x) (ANDconst [31] y)) (CSEL0 {cc} (SLL x (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x y) for { - c := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVHUreg { + if v_0.Op != OpARM64SRL { break } - if !(0xffff < int32(c)) { + if v_0.Type != typ.UInt32 { break } - v.reset(OpARM64FlagLT_ULT) - return true - } - return false -} -func rewriteValueARM64_OpARM64CMPconst_0(v *Value) bool { - // match: (CMPconst (MOVDconst [x]) [y]) - // cond: x==y - // result: (FlagEQ) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64MOVWUreg { break } - x := v_0.AuxInt - if !(x == y) { + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64FlagEQ) - return true - } - // match: (CMPconst (MOVDconst [x]) [y]) - // cond: xuint64(y) - // result: (FlagLT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_1.Type != typ.UInt32 { break } - x := v_0.AuxInt - if !(x < y && uint64(x) > uint64(y)) { + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SLL { break } - v.reset(OpARM64FlagLT_UGT) - return true - } - // match: (CMPconst (MOVDconst [x]) [y]) - // cond: x>y && uint64(x) y && uint64(x) < uint64(y)) { + v_1_0_1 := v_1_0.Args[1] + if v_1_0_1.Op != OpARM64SUB { break } - v.reset(OpARM64FlagGT_ULT) - return true - } - // match: (CMPconst (MOVDconst [x]) [y]) - // cond: x>y && uint64(x)>uint64(y) - // result: (FlagGT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_1_0_1.Type != t { break } - x := v_0.AuxInt - if !(x > y && uint64(x) > uint64(y)) { + _ = v_1_0_1.Args[1] + v_1_0_1_0 := v_1_0_1.Args[0] + if v_1_0_1_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64FlagGT_UGT) - return true - } - // match: (CMPconst (MOVBUreg _) [c]) - // cond: 0xff < c - // result: (FlagLT_ULT) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVBUreg { + if v_1_0_1_0.AuxInt != 32 { break } - if !(0xff < c) { + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64FlagLT_ULT) - return true - } - // match: (CMPconst (MOVHUreg _) [c]) - // cond: 0xffff < c - // result: (FlagLT_ULT) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVHUreg { + if v_1_0_1_1.Type != t { break } - if !(0xffff < c) { + if v_1_0_1_1.AuxInt != 31 { break } - v.reset(OpARM64FlagLT_ULT) - return true - } - // match: (CMPconst (MOVWUreg _) [c]) - // cond: 0xffffffff < c - // result: (FlagLT_ULT) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVWUreg { + if y != v_1_0_1_1.Args[0] { break } - if !(0xffffffff < c) { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64CMPconst { break } - v.reset(OpARM64FlagLT_ULT) - return true - } - // match: (CMPconst (ANDconst _ [m]) [n]) - // cond: 0 <= m && m < n - // result: (FlagLT_ULT) - for { - n := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64ANDconst { + if v_1_1.AuxInt != 64 { break } - m := v_0.AuxInt - if !(0 <= m && m < n) { + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { break } - v.reset(OpARM64FlagLT_ULT) + if v_1_1_0.Type != t { + break + } + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { + break + } + if v_1_1_0_0.AuxInt != 32 { + break + } + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { + break + } + if v_1_1_0_1.Type != t { + break + } + if v_1_1_0_1.AuxInt != 31 { + break + } + if y != v_1_1_0_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64RORW) + v.AddArg(x) + v.AddArg(y) return true } - // match: (CMPconst (SRLconst _ [c]) [n]) - // cond: 0 <= n && 0 < c && c <= 63 && (1< {cc} (SLL x (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y)))) (SRL (MOVWUreg x) (ANDconst [31] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x y) for { - n := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { + if v_0.Op != OpARM64CSEL0 { break } - c := v_0.AuxInt - if !(0 <= n && 0 < c && c <= 63 && (1< x [d]))) + // result: (MOVDaddr [off1+off2] {sym} ptr) for { - d := v.AuxInt - _ = v.Args[1] + off1 := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64MOVDaddr { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64InvertFlags) - v0 := b.NewValue0(v.Pos, OpARM64CMPconst, types.TypeFlags) - v0.AuxInt = c - v1 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v1.AuxInt = d - v1.AddArg(x) - v0.AddArg(v1) - v.AddArg(v0) + off2 := v_0.AuxInt + sym := v_0.Aux + ptr := v_0.Args[0] + v.reset(OpARM64MOVDaddr) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) return true } - // match: (CMPshiftLL x (MOVDconst [c]) [d]) + // match: (ADDconst [0] x) // cond: - // result: (CMPconst x [int64(uint64(c)< x [d]))) + // result: (MOVDconst [c+d]) for { - d := v.AuxInt - _ = v.Args[1] + c := v.AuxInt v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64InvertFlags) - v0 := b.NewValue0(v.Pos, OpARM64CMPconst, types.TypeFlags) - v0.AuxInt = c - v1 := b.NewValue0(v.Pos, OpARM64SRAconst, x.Type) - v1.AuxInt = d - v1.AddArg(x) - v0.AddArg(v1) - v.AddArg(v0) + d := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = c + d return true } - // match: (CMPshiftRA x (MOVDconst [c]) [d]) + // match: (ADDconst [c] (ADDconst [d] x)) // cond: - // result: (CMPconst x [c>>uint64(d)]) + // result: (ADDconst [c+d] x) for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - c := v_1.AuxInt - v.reset(OpARM64CMPconst) - v.AuxInt = c >> uint64(d) + d := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ADDconst) + v.AuxInt = c + d + v.AddArg(x) + return true + } + // match: (ADDconst [c] (SUBconst [d] x)) + // cond: + // result: (ADDconst [c-d] x) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SUBconst { + break + } + d := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ADDconst) + v.AuxInt = c - d v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64CMPshiftRL_0(v *Value) bool { +func rewriteValueARM64_OpARM64ADDshiftLL_0(v *Value) bool { b := v.Block _ = b - // match: (CMPshiftRL (MOVDconst [c]) x [d]) + // match: (ADDshiftLL (MOVDconst [c]) x [d]) // cond: - // result: (InvertFlags (CMPconst [c] (SRLconst x [d]))) + // result: (ADDconst [c] (SLLconst x [d])) for { d := v.AuxInt _ = v.Args[1] @@ -3186,19 +2276,17 @@ func rewriteValueARM64_OpARM64CMPshiftRL_0(v *Value) bool { } c := v_0.AuxInt x := v.Args[1] - v.reset(OpARM64InvertFlags) - v0 := b.NewValue0(v.Pos, OpARM64CMPconst, types.TypeFlags) - v0.AuxInt = c - v1 := b.NewValue0(v.Pos, OpARM64SRLconst, x.Type) - v1.AuxInt = d - v1.AddArg(x) - v0.AddArg(v1) + v.reset(OpARM64ADDconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) v.AddArg(v0) return true } - // match: (CMPshiftRL x (MOVDconst [c]) [d]) + // match: (ADDshiftLL x (MOVDconst [c]) [d]) // cond: - // result: (CMPconst x [int64(uint64(c)>>uint64(d))]) + // result: (ADDconst x [int64(uint64(c)<> uint64(d)) + v.reset(OpARM64ADDconst) + v.AuxInt = int64(uint64(c) << uint64(d)) v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64CSEL_0(v *Value) bool { - // match: (CSEL {cc} x (MOVDconst [0]) flag) + // match: (ADDshiftLL [c] (SRLconst x [64-c]) x) // cond: - // result: (CSEL0 {cc} x flag) + // result: (RORconst [64-c] x) for { - cc := v.Aux - _ = v.Args[2] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + c := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64SRLconst { break } - if v_1.AuxInt != 0 { + if v_0.AuxInt != 64-c { break } - flag := v.Args[2] - v.reset(OpARM64CSEL0) - v.Aux = cc + x := v_0.Args[0] + if x != v.Args[1] { + break + } + v.reset(OpARM64RORconst) + v.AuxInt = 64 - c v.AddArg(x) - v.AddArg(flag) return true } - // match: (CSEL {cc} (MOVDconst [0]) y flag) - // cond: - // result: (CSEL0 {arm64Negate(cc.(Op))} y flag) + // match: (ADDshiftLL [c] (UBFX [bfc] x) x) + // cond: c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c) + // result: (RORWconst [32-c] x) for { - cc := v.Aux - _ = v.Args[2] + t := v.Type + c := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - if v_0.AuxInt != 0 { + if v_0.Op != OpARM64UBFX { break } - y := v.Args[1] - flag := v.Args[2] - v.reset(OpARM64CSEL0) - v.Aux = arm64Negate(cc.(Op)) - v.AddArg(y) - v.AddArg(flag) - return true - } - // match: (CSEL {cc} x y (InvertFlags cmp)) - // cond: - // result: (CSEL {arm64Invert(cc.(Op))} x y cmp) - for { - cc := v.Aux - _ = v.Args[2] - x := v.Args[0] - y := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64InvertFlags { + bfc := v_0.AuxInt + x := v_0.Args[0] + if x != v.Args[1] { break } - cmp := v_2.Args[0] - v.reset(OpARM64CSEL) - v.Aux = arm64Invert(cc.(Op)) - v.AddArg(x) - v.AddArg(y) - v.AddArg(cmp) - return true - } - // match: (CSEL {cc} x _ flag) - // cond: ccARM64Eval(cc, flag) > 0 - // result: x - for { - cc := v.Aux - _ = v.Args[2] - x := v.Args[0] - flag := v.Args[2] - if !(ccARM64Eval(cc, flag) > 0) { + if !(c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c)) { break } - v.reset(OpCopy) - v.Type = x.Type + v.reset(OpARM64RORWconst) + v.AuxInt = 32 - c v.AddArg(x) return true } - // match: (CSEL {cc} _ y flag) - // cond: ccARM64Eval(cc, flag) < 0 - // result: y - for { - cc := v.Aux - _ = v.Args[2] - y := v.Args[1] - flag := v.Args[2] - if !(ccARM64Eval(cc, flag) < 0) { - break - } - v.reset(OpCopy) - v.Type = y.Type - v.AddArg(y) - return true - } - // match: (CSEL {cc} x y (CMPWconst [0] bool)) - // cond: cc.(Op) == OpARM64NotEqual && flagArg(bool) != nil - // result: (CSEL {bool.Op} x y flagArg(bool)) + // match: (ADDshiftLL [c] (SRLconst x [64-c]) x2) + // cond: + // result: (EXTRconst [64-c] x2 x) for { - cc := v.Aux - _ = v.Args[2] - x := v.Args[0] - y := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64CMPWconst { - break - } - if v_2.AuxInt != 0 { + c := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64SRLconst { break } - bool := v_2.Args[0] - if !(cc.(Op) == OpARM64NotEqual && flagArg(bool) != nil) { + if v_0.AuxInt != 64-c { break } - v.reset(OpARM64CSEL) - v.Aux = bool.Op + x := v_0.Args[0] + x2 := v.Args[1] + v.reset(OpARM64EXTRconst) + v.AuxInt = 64 - c + v.AddArg(x2) v.AddArg(x) - v.AddArg(y) - v.AddArg(flagArg(bool)) return true } - // match: (CSEL {cc} x y (CMPWconst [0] bool)) - // cond: cc.(Op) == OpARM64Equal && flagArg(bool) != nil - // result: (CSEL {arm64Negate(bool.Op)} x y flagArg(bool)) + // match: (ADDshiftLL [c] (UBFX [bfc] x) x2) + // cond: c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c) + // result: (EXTRWconst [32-c] x2 x) for { - cc := v.Aux - _ = v.Args[2] - x := v.Args[0] - y := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64CMPWconst { - break - } - if v_2.AuxInt != 0 { + t := v.Type + c := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64UBFX { break } - bool := v_2.Args[0] - if !(cc.(Op) == OpARM64Equal && flagArg(bool) != nil) { + bfc := v_0.AuxInt + x := v_0.Args[0] + x2 := v.Args[1] + if !(c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c)) { break } - v.reset(OpARM64CSEL) - v.Aux = arm64Negate(bool.Op) + v.reset(OpARM64EXTRWconst) + v.AuxInt = 32 - c + v.AddArg(x2) v.AddArg(x) - v.AddArg(y) - v.AddArg(flagArg(bool)) return true } return false } -func rewriteValueARM64_OpARM64CSEL0_0(v *Value) bool { - // match: (CSEL0 {cc} x (InvertFlags cmp)) +func rewriteValueARM64_OpARM64ADDshiftRA_0(v *Value) bool { + b := v.Block + _ = b + // match: (ADDshiftRA (MOVDconst [c]) x [d]) // cond: - // result: (CSEL0 {arm64Invert(cc.(Op))} x cmp) + // result: (ADDconst [c] (SRAconst x [d])) for { - cc := v.Aux + d := v.AuxInt _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64InvertFlags { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - cmp := v_1.Args[0] - v.reset(OpARM64CSEL0) - v.Aux = arm64Invert(cc.(Op)) - v.AddArg(x) - v.AddArg(cmp) + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64ADDconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SRAconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (CSEL0 {cc} x flag) - // cond: ccARM64Eval(cc, flag) > 0 - // result: x + // match: (ADDshiftRA x (MOVDconst [c]) [d]) + // cond: + // result: (ADDconst x [c>>uint64(d)]) for { - cc := v.Aux + d := v.AuxInt _ = v.Args[1] x := v.Args[0] - flag := v.Args[1] - if !(ccARM64Eval(cc, flag) > 0) { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpCopy) - v.Type = x.Type + c := v_1.AuxInt + v.reset(OpARM64ADDconst) + v.AuxInt = c >> uint64(d) v.AddArg(x) return true } - // match: (CSEL0 {cc} _ flag) - // cond: ccARM64Eval(cc, flag) < 0 - // result: (MOVDconst [0]) + return false +} +func rewriteValueARM64_OpARM64ADDshiftRL_0(v *Value) bool { + b := v.Block + _ = b + // match: (ADDshiftRL (MOVDconst [c]) x [d]) + // cond: + // result: (ADDconst [c] (SRLconst x [d])) for { - cc := v.Aux + d := v.AuxInt _ = v.Args[1] - flag := v.Args[1] - if !(ccARM64Eval(cc, flag) < 0) { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64ADDconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SRLconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (CSEL0 {cc} x (CMPWconst [0] bool)) - // cond: cc.(Op) == OpARM64NotEqual && flagArg(bool) != nil - // result: (CSEL0 {bool.Op} x flagArg(bool)) + // match: (ADDshiftRL x (MOVDconst [c]) [d]) + // cond: + // result: (ADDconst x [int64(uint64(c)>>uint64(d))]) for { - cc := v.Aux + d := v.AuxInt _ = v.Args[1] x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64CMPWconst { - break - } - if v_1.AuxInt != 0 { - break - } - bool := v_1.Args[0] - if !(cc.(Op) == OpARM64NotEqual && flagArg(bool) != nil) { + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64CSEL0) - v.Aux = bool.Op + c := v_1.AuxInt + v.reset(OpARM64ADDconst) + v.AuxInt = int64(uint64(c) >> uint64(d)) v.AddArg(x) - v.AddArg(flagArg(bool)) return true } - // match: (CSEL0 {cc} x (CMPWconst [0] bool)) - // cond: cc.(Op) == OpARM64Equal && flagArg(bool) != nil - // result: (CSEL0 {arm64Negate(bool.Op)} x flagArg(bool)) + // match: (ADDshiftRL [c] (SLLconst x [64-c]) x) + // cond: + // result: (RORconst [ c] x) for { - cc := v.Aux + c := v.AuxInt _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64CMPWconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - if v_1.AuxInt != 0 { + if v_0.AuxInt != 64-c { break } - bool := v_1.Args[0] - if !(cc.(Op) == OpARM64Equal && flagArg(bool) != nil) { + x := v_0.Args[0] + if x != v.Args[1] { break } - v.reset(OpARM64CSEL0) - v.Aux = arm64Negate(bool.Op) + v.reset(OpARM64RORconst) + v.AuxInt = c v.AddArg(x) - v.AddArg(flagArg(bool)) return true } - return false -} -func rewriteValueARM64_OpARM64DIV_0(v *Value) bool { - // match: (DIV (MOVDconst [c]) (MOVDconst [d])) - // cond: - // result: (MOVDconst [c/d]) + // match: (ADDshiftRL [c] (SLLconst x [32-c]) (MOVWUreg x)) + // cond: c < 32 && t.Size() == 4 + // result: (RORWconst [c] x) for { + t := v.Type + c := v.AuxInt _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64SLLconst { break } - c := v_0.AuxInt + if v_0.AuxInt != 32-c { + break + } + x := v_0.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64MOVWUreg { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = c / d + if x != v_1.Args[0] { + break + } + if !(c < 32 && t.Size() == 4) { + break + } + v.reset(OpARM64RORWconst) + v.AuxInt = c + v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64DIVW_0(v *Value) bool { - // match: (DIVW (MOVDconst [c]) (MOVDconst [d])) +func rewriteValueARM64_OpARM64AND_0(v *Value) bool { + // match: (AND x (MOVDconst [c])) // cond: - // result: (MOVDconst [int64(int32(c)/int32(d))]) + // result: (ANDconst [c] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64ANDconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (AND (MOVDconst [c]) x) + // cond: + // result: (ANDconst [c] x) for { _ = v.Args[1] v_0 := v.Args[0] @@ -3496,50 +2556,61 @@ func rewriteValueARM64_OpARM64DIVW_0(v *Value) bool { break } c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + x := v.Args[1] + v.reset(OpARM64ANDconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (AND x x) + // cond: + // result: x + for { + _ = v.Args[1] + x := v.Args[0] + if x != v.Args[1] { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(int32(c) / int32(d)) + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64EON_0(v *Value) bool { - // match: (EON x (MOVDconst [c])) + // match: (AND x (MVN y)) // cond: - // result: (XORconst [^c] x) + // result: (BIC x y) for { _ = v.Args[1] x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64MVN { break } - c := v_1.AuxInt - v.reset(OpARM64XORconst) - v.AuxInt = ^c + y := v_1.Args[0] + v.reset(OpARM64BIC) v.AddArg(x) + v.AddArg(y) return true } - // match: (EON x x) + // match: (AND (MVN y) x) // cond: - // result: (MOVDconst [-1]) + // result: (BIC x y) for { _ = v.Args[1] - x := v.Args[0] - if x != v.Args[1] { + v_0 := v.Args[0] + if v_0.Op != OpARM64MVN { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = -1 + y := v_0.Args[0] + x := v.Args[1] + v.reset(OpARM64BIC) + v.AddArg(x) + v.AddArg(y) return true } - // match: (EON x0 x1:(SLLconst [c] y)) + // match: (AND x0 x1:(SLLconst [c] y)) // cond: clobberIfDead(x1) - // result: (EONshiftLL x0 y [c]) + // result: (ANDshiftLL x0 y [c]) for { _ = v.Args[1] x0 := v.Args[0] @@ -3552,41 +2623,41 @@ func rewriteValueARM64_OpARM64EON_0(v *Value) bool { if !(clobberIfDead(x1)) { break } - v.reset(OpARM64EONshiftLL) + v.reset(OpARM64ANDshiftLL) v.AuxInt = c v.AddArg(x0) v.AddArg(y) return true } - // match: (EON x0 x1:(SRLconst [c] y)) + // match: (AND x1:(SLLconst [c] y) x0) // cond: clobberIfDead(x1) - // result: (EONshiftRL x0 y [c]) + // result: (ANDshiftLL x0 y [c]) for { _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRLconst { + x1 := v.Args[0] + if x1.Op != OpARM64SLLconst { break } c := x1.AuxInt y := x1.Args[0] + x0 := v.Args[1] if !(clobberIfDead(x1)) { break } - v.reset(OpARM64EONshiftRL) + v.reset(OpARM64ANDshiftLL) v.AuxInt = c v.AddArg(x0) v.AddArg(y) return true } - // match: (EON x0 x1:(SRAconst [c] y)) + // match: (AND x0 x1:(SRLconst [c] y)) // cond: clobberIfDead(x1) - // result: (EONshiftRA x0 y [c]) + // result: (ANDshiftRL x0 y [c]) for { _ = v.Args[1] x0 := v.Args[0] x1 := v.Args[1] - if x1.Op != OpARM64SRAconst { + if x1.Op != OpARM64SRLconst { break } c := x1.AuxInt @@ -3594,4570 +2665,7022 @@ func rewriteValueARM64_OpARM64EON_0(v *Value) bool { if !(clobberIfDead(x1)) { break } - v.reset(OpARM64EONshiftRA) + v.reset(OpARM64ANDshiftRL) v.AuxInt = c v.AddArg(x0) v.AddArg(y) return true } - return false -} -func rewriteValueARM64_OpARM64EONshiftLL_0(v *Value) bool { - // match: (EONshiftLL x (MOVDconst [c]) [d]) - // cond: - // result: (XORconst x [^int64(uint64(c)<>uint64(d))]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - c := v_1.AuxInt - v.reset(OpARM64XORconst) - v.AuxInt = ^(c >> uint64(d)) - v.AddArg(x) - return true - } - // match: (EONshiftRA x (SRAconst x [c]) [d]) - // cond: c==d - // result: (MOVDconst [-1]) +func rewriteValueARM64_OpARM64AND_10(v *Value) bool { + // match: (AND x1:(SRAconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (ANDshiftRA x0 y [c]) for { - d := v.AuxInt _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRAconst { - break - } - c := v_1.AuxInt - if x != v_1.Args[0] { + x1 := v.Args[0] + if x1.Op != OpARM64SRAconst { break } - if !(c == d) { + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = -1 + v.reset(OpARM64ANDshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64EONshiftRL_0(v *Value) bool { - // match: (EONshiftRL x (MOVDconst [c]) [d]) +func rewriteValueARM64_OpARM64ANDconst_0(v *Value) bool { + // match: (ANDconst [0] _) // cond: - // result: (XORconst x [^int64(uint64(c)>>uint64(d))]) + // result: (MOVDconst [0]) for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v.AuxInt != 0 { break } - c := v_1.AuxInt - v.reset(OpARM64XORconst) - v.AuxInt = ^int64(uint64(c) >> uint64(d)) - v.AddArg(x) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (EONshiftRL x (SRLconst x [c]) [d]) - // cond: c==d - // result: (MOVDconst [-1]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - c := v_1.AuxInt - if x != v_1.Args[0] { - break - } - if !(c == d) { + // match: (ANDconst [-1] x) + // cond: + // result: x + for { + if v.AuxInt != -1 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = -1 + x := v.Args[0] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64Equal_0(v *Value) bool { - // match: (Equal (FlagEQ)) + // match: (ANDconst [c] (MOVDconst [d])) // cond: - // result: (MOVDconst [1]) + // result: (MOVDconst [c&d]) for { + c := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagEQ { + if v_0.Op != OpARM64MOVDconst { break } + d := v_0.AuxInt v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + v.AuxInt = c & d return true } - // match: (Equal (FlagLT_ULT)) + // match: (ANDconst [c] (ANDconst [d] x)) // cond: - // result: (MOVDconst [0]) + // result: (ANDconst [c&d] x) for { + c := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_ULT { + if v_0.Op != OpARM64ANDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + d := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ANDconst) + v.AuxInt = c & d + v.AddArg(x) return true } - // match: (Equal (FlagLT_UGT)) + // match: (ANDconst [c] (MOVWUreg x)) // cond: - // result: (MOVDconst [0]) + // result: (ANDconst [c&(1<<32-1)] x) for { + c := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_UGT { + if v_0.Op != OpARM64MOVWUreg { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + x := v_0.Args[0] + v.reset(OpARM64ANDconst) + v.AuxInt = c & (1<<32 - 1) + v.AddArg(x) return true } - // match: (Equal (FlagGT_ULT)) + // match: (ANDconst [c] (MOVHUreg x)) // cond: - // result: (MOVDconst [0]) + // result: (ANDconst [c&(1<<16-1)] x) for { + c := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_ULT { + if v_0.Op != OpARM64MOVHUreg { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + x := v_0.Args[0] + v.reset(OpARM64ANDconst) + v.AuxInt = c & (1<<16 - 1) + v.AddArg(x) return true } - // match: (Equal (FlagGT_UGT)) + // match: (ANDconst [c] (MOVBUreg x)) // cond: - // result: (MOVDconst [0]) + // result: (ANDconst [c&(1<<8-1)] x) for { + c := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_UGT { + if v_0.Op != OpARM64MOVBUreg { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + x := v_0.Args[0] + v.reset(OpARM64ANDconst) + v.AuxInt = c & (1<<8 - 1) + v.AddArg(x) return true } - // match: (Equal (InvertFlags x)) - // cond: - // result: (Equal x) + // match: (ANDconst [ac] (SLLconst [sc] x)) + // cond: isARM64BFMask(sc, ac, sc) + // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(ac, sc))] x) for { + ac := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64InvertFlags { + if v_0.Op != OpARM64SLLconst { break } + sc := v_0.AuxInt x := v_0.Args[0] - v.reset(OpARM64Equal) + if !(isARM64BFMask(sc, ac, sc)) { + break + } + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(ac, sc)) v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64FADDD_0(v *Value) bool { - // match: (FADDD a (FMULD x y)) - // cond: - // result: (FMADDD a x y) + // match: (ANDconst [ac] (SRLconst [sc] x)) + // cond: isARM64BFMask(sc, ac, 0) + // result: (UBFX [arm64BFAuxInt(sc, arm64BFWidth(ac, 0))] x) for { - _ = v.Args[1] - a := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64FMULD { + ac := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SRLconst { break } - _ = v_1.Args[1] - x := v_1.Args[0] - y := v_1.Args[1] - v.reset(OpARM64FMADDD) - v.AddArg(a) + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, ac, 0)) { + break + } + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(ac, 0)) v.AddArg(x) - v.AddArg(y) return true } - // match: (FADDD (FMULD x y) a) + return false +} +func rewriteValueARM64_OpARM64ANDshiftLL_0(v *Value) bool { + b := v.Block + _ = b + // match: (ANDshiftLL (MOVDconst [c]) x [d]) // cond: - // result: (FMADDD a x y) + // result: (ANDconst [c] (SLLconst x [d])) for { + d := v.AuxInt _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64FMULD { + if v_0.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - a := v.Args[1] - v.reset(OpARM64FMADDD) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64ANDconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (FADDD a (FNMULD x y)) + // match: (ANDshiftLL x (MOVDconst [c]) [d]) // cond: - // result: (FMSUBD a x y) + // result: (ANDconst x [int64(uint64(c)< x [d])) for { + d := v.AuxInt _ = v.Args[1] - a := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64FMULS { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = v_1.Args[1] - x := v_1.Args[0] - y := v_1.Args[1] - v.reset(OpARM64FMADDS) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64ANDconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SRAconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (FADDS (FMULS x y) a) + // match: (ANDshiftRA x (MOVDconst [c]) [d]) // cond: - // result: (FMADDS a x y) + // result: (ANDconst x [c>>uint64(d)]) for { + d := v.AuxInt _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64FMULS { + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - a := v.Args[1] - v.reset(OpARM64FMADDS) - v.AddArg(a) + c := v_1.AuxInt + v.reset(OpARM64ANDconst) + v.AuxInt = c >> uint64(d) v.AddArg(x) - v.AddArg(y) return true } - // match: (FADDS a (FNMULS x y)) - // cond: - // result: (FMSUBS a x y) + // match: (ANDshiftRA x y:(SRAconst x [c]) [d]) + // cond: c==d + // result: y for { + d := v.AuxInt _ = v.Args[1] - a := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64FNMULS { + x := v.Args[0] + y := v.Args[1] + if y.Op != OpARM64SRAconst { break } - _ = v_1.Args[1] - x := v_1.Args[0] - y := v_1.Args[1] - v.reset(OpARM64FMSUBS) - v.AddArg(a) - v.AddArg(x) + c := y.AuxInt + if x != y.Args[0] { + break + } + if !(c == d) { + break + } + v.reset(OpCopy) + v.Type = y.Type v.AddArg(y) return true } - // match: (FADDS (FNMULS x y) a) + return false +} +func rewriteValueARM64_OpARM64ANDshiftRL_0(v *Value) bool { + b := v.Block + _ = b + // match: (ANDshiftRL (MOVDconst [c]) x [d]) // cond: - // result: (FMSUBS a x y) + // result: (ANDconst [c] (SRLconst x [d])) for { + d := v.AuxInt _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64FNMULS { + if v_0.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - a := v.Args[1] - v.reset(OpARM64FMSUBS) - v.AddArg(a) + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64ANDconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SRLconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (ANDshiftRL x (MOVDconst [c]) [d]) + // cond: + // result: (ANDconst x [int64(uint64(c)>>uint64(d))]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64ANDconst) + v.AuxInt = int64(uint64(c) >> uint64(d)) v.AddArg(x) + return true + } + // match: (ANDshiftRL x y:(SRLconst x [c]) [d]) + // cond: c==d + // result: y + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if y.Op != OpARM64SRLconst { + break + } + c := y.AuxInt + if x != y.Args[0] { + break + } + if !(c == d) { + break + } + v.reset(OpCopy) + v.Type = y.Type v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64FMOVDfpgp_0(v *Value) bool { - b := v.Block - _ = b - // match: (FMOVDfpgp (Arg [off] {sym})) +func rewriteValueARM64_OpARM64BIC_0(v *Value) bool { + // match: (BIC x (MOVDconst [c])) // cond: - // result: @b.Func.Entry (Arg [off] {sym}) + // result: (ANDconst [^c] x) for { - t := v.Type - v_0 := v.Args[0] - if v_0.Op != OpArg { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - off := v_0.AuxInt - sym := v_0.Aux - b = b.Func.Entry - v0 := b.NewValue0(v.Pos, OpArg, t) - v.reset(OpCopy) - v.AddArg(v0) - v0.AuxInt = off - v0.Aux = sym + c := v_1.AuxInt + v.reset(OpARM64ANDconst) + v.AuxInt = ^c + v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64FMOVDgpfp_0(v *Value) bool { - b := v.Block - _ = b - // match: (FMOVDgpfp (Arg [off] {sym})) + // match: (BIC x x) // cond: - // result: @b.Func.Entry (Arg [off] {sym}) + // result: (MOVDconst [0]) for { - t := v.Type - v_0 := v.Args[0] - if v_0.Op != OpArg { + _ = v.Args[1] + x := v.Args[0] + if x != v.Args[1] { break } - off := v_0.AuxInt - sym := v_0.Aux - b = b.Func.Entry - v0 := b.NewValue0(v.Pos, OpArg, t) - v.reset(OpCopy) - v.AddArg(v0) - v0.AuxInt = off - v0.Aux = sym + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - return false -} -func rewriteValueARM64_OpARM64FMOVDload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (FMOVDload [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (FMOVDload [off1+off2] {sym} ptr mem) + // match: (BIC x0 x1:(SLLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (BICshiftLL x0 y [c]) for { - off1 := v.AuxInt - sym := v.Aux _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SLLconst { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - v.reset(OpARM64FMOVDload) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64BICshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } - // match: (FMOVDload [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (FMOVDloadidx ptr idx mem) + // match: (BIC x0 x1:(SRLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (BICshiftRL x0 y [c]) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRLconst { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - v.reset(OpARM64FMOVDloadidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64BICshiftRL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } - // match: (FMOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (FMOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // match: (BIC x0 x1:(SRAconst [c] y)) + // cond: clobberIfDead(x1) + // result: (BICshiftRA x0 y [c]) for { - off1 := v.AuxInt - sym1 := v.Aux _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRAconst { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - v.reset(OpARM64FMOVDload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64BICshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64FMOVDloadidx_0(v *Value) bool { - // match: (FMOVDloadidx ptr (MOVDconst [c]) mem) +func rewriteValueARM64_OpARM64BICshiftLL_0(v *Value) bool { + // match: (BICshiftLL x (MOVDconst [c]) [d]) // cond: - // result: (FMOVDload [c] ptr mem) + // result: (ANDconst x [^int64(uint64(c)<>uint64(d))]) for { - _ = v.Args[2] - ptr := v.Args[0] + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64FMOVDgpfp { + if v_1.Op != OpARM64MOVDconst { break } - val := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVDstore) - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + c := v_1.AuxInt + v.reset(OpARM64ANDconst) + v.AuxInt = ^(c >> uint64(d)) + v.AddArg(x) return true } - // match: (FMOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (FMOVDstore [off1+off2] {sym} ptr val mem) + // match: (BICshiftRA x (SRAconst x [c]) [d]) + // cond: c==d + // result: (MOVDconst [0]) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRAconst { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_1.AuxInt + if x != v_1.Args[0] { break } - v.reset(OpARM64FMOVDstore) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + if !(c == d) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (FMOVDstore [off] {sym} (ADD ptr idx) val mem) - // cond: off == 0 && sym == nil - // result: (FMOVDstoreidx ptr idx val mem) + return false +} +func rewriteValueARM64_OpARM64BICshiftRL_0(v *Value) bool { + // match: (BICshiftRL x (MOVDconst [c]) [d]) + // cond: + // result: (ANDconst x [^int64(uint64(c)>>uint64(d))]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - val := v.Args[1] - mem := v.Args[2] - if !(off == 0 && sym == nil) { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64FMOVDstoreidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + c := v_1.AuxInt + v.reset(OpARM64ANDconst) + v.AuxInt = ^int64(uint64(c) >> uint64(d)) + v.AddArg(x) return true } - // match: (FMOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (FMOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + // match: (BICshiftRL x (SRLconst x [c]) [d]) + // cond: c==d + // result: (MOVDconst [0]) for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_1.AuxInt + if x != v_1.Args[0] { break } - v.reset(OpARM64FMOVDstore) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + if !(c == d) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } return false } -func rewriteValueARM64_OpARM64FMOVDstoreidx_0(v *Value) bool { - // match: (FMOVDstoreidx ptr (MOVDconst [c]) val mem) +func rewriteValueARM64_OpARM64CMN_0(v *Value) bool { + // match: (CMN x (MOVDconst [c])) // cond: - // result: (FMOVDstore [c] ptr val mem) + // result: (CMNconst [c] x) for { - _ = v.Args[3] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64FMOVDstore) + v.reset(OpARM64CMNconst) v.AuxInt = c - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.AddArg(x) return true } - // match: (FMOVDstoreidx (MOVDconst [c]) idx val mem) + // match: (CMN (MOVDconst [c]) x) // cond: - // result: (FMOVDstore [c] idx val mem) + // result: (CMNconst [c] x) for { - _ = v.Args[3] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - idx := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64FMOVDstore) + x := v.Args[1] + v.reset(OpARM64CMNconst) v.AuxInt = c - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64FMOVSload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (FMOVSload [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (FMOVSload [off1+off2] {sym} ptr mem) +func rewriteValueARM64_OpARM64CMNW_0(v *Value) bool { + // match: (CMNW x (MOVDconst [c])) + // cond: + // result: (CMNWconst [c] x) for { - off1 := v.AuxInt - sym := v.Aux _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { - break - } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64FMOVSload) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + c := v_1.AuxInt + v.reset(OpARM64CMNWconst) + v.AuxInt = c + v.AddArg(x) return true } - // match: (FMOVSload [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (FMOVSloadidx ptr idx mem) + // match: (CMNW (MOVDconst [c]) x) + // cond: + // result: (CMNWconst [c] x) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64FMOVSloadidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64CMNWconst) + v.AuxInt = c + v.AddArg(x) + return true } - // match: (FMOVSload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (FMOVSload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + return false +} +func rewriteValueARM64_OpARM64CMNWconst_0(v *Value) bool { + // match: (CMNWconst (MOVDconst [x]) [y]) + // cond: int32(x)==int32(-y) + // result: (FlagEQ) for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] + y := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + if v_0.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + x := v_0.AuxInt + if !(int32(x) == int32(-y)) { break } - v.reset(OpARM64FMOVSload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64FlagEQ) return true } - return false -} -func rewriteValueARM64_OpARM64FMOVSloadidx_0(v *Value) bool { - // match: (FMOVSloadidx ptr (MOVDconst [c]) mem) - // cond: - // result: (FMOVSload [c] ptr mem) + // match: (CMNWconst (MOVDconst [x]) [y]) + // cond: int32(x)uint32(-y) + // result: (FlagLT_UGT) for { - _ = v.Args[2] + y := v.AuxInt v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64FMOVSload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + x := v_0.AuxInt + if !(int32(x) < int32(-y) && uint32(x) > uint32(-y)) { + break + } + v.reset(OpARM64FlagLT_UGT) + return true + } + // match: (CMNWconst (MOVDconst [x]) [y]) + // cond: int32(x)>int32(-y) && uint32(x) int32(-y) && uint32(x) < uint32(-y)) { + break + } + v.reset(OpARM64FlagGT_ULT) + return true + } + // match: (CMNWconst (MOVDconst [x]) [y]) + // cond: int32(x)>int32(-y) && uint32(x)>uint32(-y) + // result: (FlagGT_UGT) + for { + y := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + x := v_0.AuxInt + if !(int32(x) > int32(-y) && uint32(x) > uint32(-y)) { + break + } + v.reset(OpARM64FlagGT_UGT) return true } return false } -func rewriteValueARM64_OpARM64FMOVSstore_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (FMOVSstore [off1] {sym} (ADDconst [off2] ptr) val mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (FMOVSstore [off1+off2] {sym} ptr val mem) +func rewriteValueARM64_OpARM64CMNconst_0(v *Value) bool { + // match: (CMNconst (MOVDconst [x]) [y]) + // cond: int64(x)==int64(-y) + // result: (FlagEQ) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[2] + y := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + if v_0.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + x := v_0.AuxInt + if !(int64(x) == int64(-y)) { break } - v.reset(OpARM64FMOVSstore) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64FlagEQ) return true } - // match: (FMOVSstore [off] {sym} (ADD ptr idx) val mem) - // cond: off == 0 && sym == nil - // result: (FMOVSstoreidx ptr idx val mem) + // match: (CMNconst (MOVDconst [x]) [y]) + // cond: int64(x)uint64(-y) + // result: (FlagLT_UGT) for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[2] + y := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + if v_0.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + x := v_0.AuxInt + if !(int64(x) < int64(-y) && uint64(x) > uint64(-y)) { break } - v.reset(OpARM64FMOVSstore) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64FlagLT_UGT) + return true + } + // match: (CMNconst (MOVDconst [x]) [y]) + // cond: int64(x)>int64(-y) && uint64(x) int64(-y) && uint64(x) < uint64(-y)) { + break + } + v.reset(OpARM64FlagGT_ULT) + return true + } + // match: (CMNconst (MOVDconst [x]) [y]) + // cond: int64(x)>int64(-y) && uint64(x)>uint64(-y) + // result: (FlagGT_UGT) + for { + y := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + x := v_0.AuxInt + if !(int64(x) > int64(-y) && uint64(x) > uint64(-y)) { + break + } + v.reset(OpARM64FlagGT_UGT) return true } return false } -func rewriteValueARM64_OpARM64FMOVSstoreidx_0(v *Value) bool { - // match: (FMOVSstoreidx ptr (MOVDconst [c]) val mem) +func rewriteValueARM64_OpARM64CMP_0(v *Value) bool { + b := v.Block + _ = b + // match: (CMP x (MOVDconst [c])) // cond: - // result: (FMOVSstore [c] ptr val mem) + // result: (CMPconst [c] x) for { - _ = v.Args[3] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64FMOVSstore) + v.reset(OpARM64CMPconst) v.AuxInt = c - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.AddArg(x) return true } - // match: (FMOVSstoreidx (MOVDconst [c]) idx val mem) + // match: (CMP (MOVDconst [c]) x) // cond: - // result: (FMOVSstore [c] idx val mem) + // result: (InvertFlags (CMPconst [c] x)) for { - _ = v.Args[3] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - idx := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64FMOVSstore) - v.AuxInt = c - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + x := v.Args[1] + v.reset(OpARM64InvertFlags) + v0 := b.NewValue0(v.Pos, OpARM64CMPconst, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x) + v.AddArg(v0) return true } - return false -} -func rewriteValueARM64_OpARM64FMULD_0(v *Value) bool { - // match: (FMULD (FNEGD x) y) - // cond: - // result: (FNMULD x y) + // match: (CMP x0 x1:(SLLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (CMPshiftLL x0 y [c]) for { _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64FNEGD { + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SLLconst { break } - x := v_0.Args[0] - y := v.Args[1] - v.reset(OpARM64FNMULD) - v.AddArg(x) + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64CMPshiftLL) + v.AuxInt = c + v.AddArg(x0) v.AddArg(y) return true } - // match: (FMULD y (FNEGD x)) - // cond: - // result: (FNMULD x y) + // match: (CMP x0:(SLLconst [c] y) x1) + // cond: clobberIfDead(x0) + // result: (InvertFlags (CMPshiftLL x1 y [c])) for { _ = v.Args[1] - y := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64FNEGD { + x0 := v.Args[0] + if x0.Op != OpARM64SLLconst { break } - x := v_1.Args[0] - v.reset(OpARM64FNMULD) - v.AddArg(x) - v.AddArg(y) + c := x0.AuxInt + y := x0.Args[0] + x1 := v.Args[1] + if !(clobberIfDead(x0)) { + break + } + v.reset(OpARM64InvertFlags) + v0 := b.NewValue0(v.Pos, OpARM64CMPshiftLL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x1) + v0.AddArg(y) + v.AddArg(v0) return true } - return false -} -func rewriteValueARM64_OpARM64FMULS_0(v *Value) bool { - // match: (FMULS (FNEGS x) y) - // cond: - // result: (FNMULS x y) + // match: (CMP x0 x1:(SRLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (CMPshiftRL x0 y [c]) for { _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64FNEGS { + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRLconst { break } - x := v_0.Args[0] - y := v.Args[1] - v.reset(OpARM64FNMULS) - v.AddArg(x) + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64CMPshiftRL) + v.AuxInt = c + v.AddArg(x0) v.AddArg(y) return true } - // match: (FMULS y (FNEGS x)) - // cond: - // result: (FNMULS x y) + // match: (CMP x0:(SRLconst [c] y) x1) + // cond: clobberIfDead(x0) + // result: (InvertFlags (CMPshiftRL x1 y [c])) for { _ = v.Args[1] - y := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64FNEGS { + x0 := v.Args[0] + if x0.Op != OpARM64SRLconst { break } - x := v_1.Args[0] - v.reset(OpARM64FNMULS) - v.AddArg(x) - v.AddArg(y) - return true - } - return false -} -func rewriteValueARM64_OpARM64FNEGD_0(v *Value) bool { - // match: (FNEGD (FMULD x y)) - // cond: - // result: (FNMULD x y) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FMULD { + c := x0.AuxInt + y := x0.Args[0] + x1 := v.Args[1] + if !(clobberIfDead(x0)) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - v.reset(OpARM64FNMULD) - v.AddArg(x) - v.AddArg(y) + v.reset(OpARM64InvertFlags) + v0 := b.NewValue0(v.Pos, OpARM64CMPshiftRL, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x1) + v0.AddArg(y) + v.AddArg(v0) return true } - // match: (FNEGD (FNMULD x y)) - // cond: - // result: (FMULD x y) + // match: (CMP x0 x1:(SRAconst [c] y)) + // cond: clobberIfDead(x1) + // result: (CMPshiftRA x0 y [c]) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FNMULD { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRAconst { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - v.reset(OpARM64FMULD) - v.AddArg(x) - v.AddArg(y) - return true - } - return false -} -func rewriteValueARM64_OpARM64FNEGS_0(v *Value) bool { - // match: (FNEGS (FMULS x y)) - // cond: - // result: (FNMULS x y) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FMULS { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - v.reset(OpARM64FNMULS) - v.AddArg(x) + v.reset(OpARM64CMPshiftRA) + v.AuxInt = c + v.AddArg(x0) v.AddArg(y) return true } - // match: (FNEGS (FNMULS x y)) - // cond: - // result: (FMULS x y) + // match: (CMP x0:(SRAconst [c] y) x1) + // cond: clobberIfDead(x0) + // result: (InvertFlags (CMPshiftRA x1 y [c])) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FNMULS { + _ = v.Args[1] + x0 := v.Args[0] + if x0.Op != OpARM64SRAconst { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - v.reset(OpARM64FMULS) - v.AddArg(x) - v.AddArg(y) + c := x0.AuxInt + y := x0.Args[0] + x1 := v.Args[1] + if !(clobberIfDead(x0)) { + break + } + v.reset(OpARM64InvertFlags) + v0 := b.NewValue0(v.Pos, OpARM64CMPshiftRA, types.TypeFlags) + v0.AuxInt = c + v0.AddArg(x1) + v0.AddArg(y) + v.AddArg(v0) return true } return false } -func rewriteValueARM64_OpARM64FNMULD_0(v *Value) bool { - // match: (FNMULD (FNEGD x) y) +func rewriteValueARM64_OpARM64CMPW_0(v *Value) bool { + b := v.Block + _ = b + // match: (CMPW x (MOVDconst [c])) // cond: - // result: (FMULD x y) + // result: (CMPWconst [int64(int32(c))] x) for { _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64FNEGD { + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x := v_0.Args[0] - y := v.Args[1] - v.reset(OpARM64FMULD) + c := v_1.AuxInt + v.reset(OpARM64CMPWconst) + v.AuxInt = int64(int32(c)) v.AddArg(x) - v.AddArg(y) return true } - // match: (FNMULD y (FNEGD x)) + // match: (CMPW (MOVDconst [c]) x) // cond: - // result: (FMULD x y) + // result: (InvertFlags (CMPWconst [int64(int32(c))] x)) for { _ = v.Args[1] - y := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64FNEGD { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - x := v_1.Args[0] - v.reset(OpARM64FMULD) - v.AddArg(x) - v.AddArg(y) + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64InvertFlags) + v0 := b.NewValue0(v.Pos, OpARM64CMPWconst, types.TypeFlags) + v0.AuxInt = int64(int32(c)) + v0.AddArg(x) + v.AddArg(v0) return true } return false } -func rewriteValueARM64_OpARM64FNMULS_0(v *Value) bool { - // match: (FNMULS (FNEGS x) y) - // cond: - // result: (FMULS x y) +func rewriteValueARM64_OpARM64CMPWconst_0(v *Value) bool { + // match: (CMPWconst (MOVDconst [x]) [y]) + // cond: int32(x)==int32(y) + // result: (FlagEQ) for { - _ = v.Args[1] + y := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FNEGS { + if v_0.Op != OpARM64MOVDconst { break } - x := v_0.Args[0] - y := v.Args[1] - v.reset(OpARM64FMULS) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (FNMULS y (FNEGS x)) - // cond: - // result: (FMULS x y) - for { - _ = v.Args[1] - y := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64FNEGS { + x := v_0.AuxInt + if !(int32(x) == int32(y)) { break } - x := v_1.Args[0] - v.reset(OpARM64FMULS) - v.AddArg(x) - v.AddArg(y) + v.reset(OpARM64FlagEQ) return true } - return false -} -func rewriteValueARM64_OpARM64FSUBD_0(v *Value) bool { - // match: (FSUBD a (FMULD x y)) - // cond: - // result: (FMSUBD a x y) + // match: (CMPWconst (MOVDconst [x]) [y]) + // cond: int32(x)uint32(y) + // result: (FlagLT_UGT) for { - _ = v.Args[1] + y := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FMULD { + if v_0.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - a := v.Args[1] - v.reset(OpARM64FNMSUBD) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (FSUBD a (FNMULD x y)) - // cond: - // result: (FMADDD a x y) - for { - _ = v.Args[1] - a := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64FNMULD { + x := v_0.AuxInt + if !(int32(x) < int32(y) && uint32(x) > uint32(y)) { break } - _ = v_1.Args[1] - x := v_1.Args[0] - y := v_1.Args[1] - v.reset(OpARM64FMADDD) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) + v.reset(OpARM64FlagLT_UGT) return true } - // match: (FSUBD (FNMULD x y) a) - // cond: - // result: (FNMADDD a x y) + // match: (CMPWconst (MOVDconst [x]) [y]) + // cond: int32(x)>int32(y) && uint32(x) int32(y) && uint32(x) < uint32(y)) { break } - _ = v_1.Args[1] - x := v_1.Args[0] - y := v_1.Args[1] - v.reset(OpARM64FMSUBS) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) + v.reset(OpARM64FlagGT_ULT) return true } - // match: (FSUBS (FMULS x y) a) - // cond: - // result: (FNMSUBS a x y) + // match: (CMPWconst (MOVDconst [x]) [y]) + // cond: int32(x)>int32(y) && uint32(x)>uint32(y) + // result: (FlagGT_UGT) for { - _ = v.Args[1] + y := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FMULS { + if v_0.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - a := v.Args[1] - v.reset(OpARM64FNMSUBS) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) + x := v_0.AuxInt + if !(int32(x) > int32(y) && uint32(x) > uint32(y)) { + break + } + v.reset(OpARM64FlagGT_UGT) return true } - // match: (FSUBS a (FNMULS x y)) - // cond: - // result: (FMADDS a x y) + // match: (CMPWconst (MOVBUreg _) [c]) + // cond: 0xff < int32(c) + // result: (FlagLT_ULT) for { - _ = v.Args[1] - a := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64FNMULS { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVBUreg { break } - _ = v_1.Args[1] - x := v_1.Args[0] - y := v_1.Args[1] - v.reset(OpARM64FMADDS) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) + if !(0xff < int32(c)) { + break + } + v.reset(OpARM64FlagLT_ULT) return true } - // match: (FSUBS (FNMULS x y) a) - // cond: - // result: (FNMADDS a x y) + // match: (CMPWconst (MOVHUreg _) [c]) + // cond: 0xffff < int32(c) + // result: (FlagLT_ULT) for { - _ = v.Args[1] + c := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FNMULS { + if v_0.Op != OpARM64MOVHUreg { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - a := v.Args[1] - v.reset(OpARM64FNMADDS) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) + if !(0xffff < int32(c)) { + break + } + v.reset(OpARM64FlagLT_ULT) return true } return false } -func rewriteValueARM64_OpARM64GreaterEqual_0(v *Value) bool { - // match: (GreaterEqual (FlagEQ)) - // cond: - // result: (MOVDconst [1]) +func rewriteValueARM64_OpARM64CMPconst_0(v *Value) bool { + // match: (CMPconst (MOVDconst [x]) [y]) + // cond: x==y + // result: (FlagEQ) for { + y := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagEQ { + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 - return true - } - // match: (GreaterEqual (FlagLT_ULT)) - // cond: - // result: (MOVDconst [0]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_ULT { + x := v_0.AuxInt + if !(x == y) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64FlagEQ) return true } - // match: (GreaterEqual (FlagLT_UGT)) - // cond: - // result: (MOVDconst [0]) + // match: (CMPconst (MOVDconst [x]) [y]) + // cond: xuint64(y) + // result: (FlagLT_UGT) for { + y := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_ULT { + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + x := v_0.AuxInt + if !(x < y && uint64(x) > uint64(y)) { + break + } + v.reset(OpARM64FlagLT_UGT) return true } - // match: (GreaterEqual (FlagGT_UGT)) - // cond: - // result: (MOVDconst [1]) + // match: (CMPconst (MOVDconst [x]) [y]) + // cond: x>y && uint64(x) y && uint64(x) < uint64(y)) { break } - x := v_0.Args[0] - v.reset(OpARM64LessEqual) - v.AddArg(x) + v.reset(OpARM64FlagGT_ULT) return true } - return false -} -func rewriteValueARM64_OpARM64GreaterEqualU_0(v *Value) bool { - // match: (GreaterEqualU (FlagEQ)) - // cond: - // result: (MOVDconst [1]) + // match: (CMPconst (MOVDconst [x]) [y]) + // cond: x>y && uint64(x)>uint64(y) + // result: (FlagGT_UGT) for { + y := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagEQ { + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + x := v_0.AuxInt + if !(x > y && uint64(x) > uint64(y)) { + break + } + v.reset(OpARM64FlagGT_UGT) return true } - // match: (GreaterEqualU (FlagLT_ULT)) - // cond: - // result: (MOVDconst [0]) + // match: (CMPconst (MOVBUreg _) [c]) + // cond: 0xff < c + // result: (FlagLT_ULT) for { + c := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_ULT { + if v_0.Op != OpARM64MOVBUreg { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + if !(0xff < c) { + break + } + v.reset(OpARM64FlagLT_ULT) return true } - // match: (GreaterEqualU (FlagLT_UGT)) - // cond: - // result: (MOVDconst [1]) + // match: (CMPconst (MOVHUreg _) [c]) + // cond: 0xffff < c + // result: (FlagLT_ULT) for { + c := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_UGT { + if v_0.Op != OpARM64MOVHUreg { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + if !(0xffff < c) { + break + } + v.reset(OpARM64FlagLT_ULT) return true } - // match: (GreaterEqualU (FlagGT_ULT)) - // cond: - // result: (MOVDconst [0]) + // match: (CMPconst (MOVWUreg _) [c]) + // cond: 0xffffffff < c + // result: (FlagLT_ULT) for { + c := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_ULT { + if v_0.Op != OpARM64MOVWUreg { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + if !(0xffffffff < c) { + break + } + v.reset(OpARM64FlagLT_ULT) return true } - // match: (GreaterEqualU (FlagGT_UGT)) - // cond: - // result: (MOVDconst [1]) + // match: (CMPconst (ANDconst _ [m]) [n]) + // cond: 0 <= m && m < n + // result: (FlagLT_ULT) for { + n := v.AuxInt v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_UGT { + if v_0.Op != OpARM64ANDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + m := v_0.AuxInt + if !(0 <= m && m < n) { + break + } + v.reset(OpARM64FlagLT_ULT) return true } - // match: (GreaterEqualU (InvertFlags x)) - // cond: - // result: (LessEqualU x) + // match: (CMPconst (SRLconst _ [c]) [n]) + // cond: 0 <= n && 0 < c && c <= 63 && (1< x [d]))) for { + d := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64FlagEQ { + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64InvertFlags) + v0 := b.NewValue0(v.Pos, OpARM64CMPconst, types.TypeFlags) + v0.AuxInt = c + v1 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v1.AuxInt = d + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) return true } - // match: (GreaterThan (FlagLT_ULT)) + // match: (CMPshiftLL x (MOVDconst [c]) [d]) // cond: - // result: (MOVDconst [0]) + // result: (CMPconst x [int64(uint64(c)< x [d]))) for { + d := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_UGT { + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64InvertFlags) + v0 := b.NewValue0(v.Pos, OpARM64CMPconst, types.TypeFlags) + v0.AuxInt = c + v1 := b.NewValue0(v.Pos, OpARM64SRAconst, x.Type) + v1.AuxInt = d + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) return true } - // match: (GreaterThan (FlagGT_ULT)) + // match: (CMPshiftRA x (MOVDconst [c]) [d]) // cond: - // result: (MOVDconst [1]) + // result: (CMPconst x [c>>uint64(d)]) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_ULT { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + c := v_1.AuxInt + v.reset(OpARM64CMPconst) + v.AuxInt = c >> uint64(d) + v.AddArg(x) return true } - // match: (GreaterThan (FlagGT_UGT)) + return false +} +func rewriteValueARM64_OpARM64CMPshiftRL_0(v *Value) bool { + b := v.Block + _ = b + // match: (CMPshiftRL (MOVDconst [c]) x [d]) // cond: - // result: (MOVDconst [1]) + // result: (InvertFlags (CMPconst [c] (SRLconst x [d]))) for { + d := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_UGT { + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64InvertFlags) + v0 := b.NewValue0(v.Pos, OpARM64CMPconst, types.TypeFlags) + v0.AuxInt = c + v1 := b.NewValue0(v.Pos, OpARM64SRLconst, x.Type) + v1.AuxInt = d + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) return true } - // match: (GreaterThan (InvertFlags x)) + // match: (CMPshiftRL x (MOVDconst [c]) [d]) // cond: - // result: (LessThan x) + // result: (CMPconst x [int64(uint64(c)>>uint64(d))]) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64InvertFlags { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x := v_0.Args[0] - v.reset(OpARM64LessThan) + c := v_1.AuxInt + v.reset(OpARM64CMPconst) + v.AuxInt = int64(uint64(c) >> uint64(d)) v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64GreaterThanU_0(v *Value) bool { - // match: (GreaterThanU (FlagEQ)) +func rewriteValueARM64_OpARM64CSEL_0(v *Value) bool { + // match: (CSEL {cc} x (MOVDconst [0]) flag) // cond: - // result: (MOVDconst [0]) + // result: (CSEL0 {cc} x flag) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagEQ { - break - } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (GreaterThanU (FlagLT_ULT)) - // cond: - // result: (MOVDconst [0]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_ULT { + cc := v.Aux + _ = v.Args[2] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (GreaterThanU (FlagLT_UGT)) - // cond: - // result: (MOVDconst [1]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_UGT { + if v_1.AuxInt != 0 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + flag := v.Args[2] + v.reset(OpARM64CSEL0) + v.Aux = cc + v.AddArg(x) + v.AddArg(flag) return true } - // match: (GreaterThanU (FlagGT_ULT)) + // match: (CSEL {cc} (MOVDconst [0]) y flag) // cond: - // result: (MOVDconst [0]) + // result: (CSEL0 {arm64Negate(cc.(Op))} y flag) for { + cc := v.Aux + _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_ULT { + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (GreaterThanU (FlagGT_UGT)) - // cond: - // result: (MOVDconst [1]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_UGT { + if v_0.AuxInt != 0 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + y := v.Args[1] + flag := v.Args[2] + v.reset(OpARM64CSEL0) + v.Aux = arm64Negate(cc.(Op)) + v.AddArg(y) + v.AddArg(flag) return true } - // match: (GreaterThanU (InvertFlags x)) + // match: (CSEL {cc} x y (InvertFlags cmp)) // cond: - // result: (LessThanU x) + // result: (CSEL {arm64Invert(cc.(Op))} x y cmp) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64InvertFlags { + cc := v.Aux + _ = v.Args[2] + x := v.Args[0] + y := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64InvertFlags { break } - x := v_0.Args[0] - v.reset(OpARM64LessThanU) + cmp := v_2.Args[0] + v.reset(OpARM64CSEL) + v.Aux = arm64Invert(cc.(Op)) v.AddArg(x) + v.AddArg(y) + v.AddArg(cmp) return true } - return false -} -func rewriteValueARM64_OpARM64LessEqual_0(v *Value) bool { - // match: (LessEqual (FlagEQ)) - // cond: - // result: (MOVDconst [1]) + // match: (CSEL {cc} x _ flag) + // cond: ccARM64Eval(cc, flag) > 0 + // result: x for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagEQ { + cc := v.Aux + _ = v.Args[2] + x := v.Args[0] + flag := v.Args[2] + if !(ccARM64Eval(cc, flag) > 0) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - // match: (LessEqual (FlagLT_ULT)) - // cond: - // result: (MOVDconst [1]) + // match: (CSEL {cc} _ y flag) + // cond: ccARM64Eval(cc, flag) < 0 + // result: y for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_ULT { + cc := v.Aux + _ = v.Args[2] + y := v.Args[1] + flag := v.Args[2] + if !(ccARM64Eval(cc, flag) < 0) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + v.reset(OpCopy) + v.Type = y.Type + v.AddArg(y) return true } - // match: (LessEqual (FlagLT_UGT)) - // cond: - // result: (MOVDconst [1]) + // match: (CSEL {cc} x y (CMPWconst [0] bool)) + // cond: cc.(Op) == OpARM64NotEqual && flagArg(bool) != nil + // result: (CSEL {bool.Op} x y flagArg(bool)) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_UGT { + cc := v.Aux + _ = v.Args[2] + x := v.Args[0] + y := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64CMPWconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 - return true - } - // match: (LessEqual (FlagGT_ULT)) - // cond: - // result: (MOVDconst [0]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_ULT { + if v_2.AuxInt != 0 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (LessEqual (FlagGT_UGT)) - // cond: - // result: (MOVDconst [0]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_UGT { + bool := v_2.Args[0] + if !(cc.(Op) == OpARM64NotEqual && flagArg(bool) != nil) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64CSEL) + v.Aux = bool.Op + v.AddArg(x) + v.AddArg(y) + v.AddArg(flagArg(bool)) return true } - // match: (LessEqual (InvertFlags x)) - // cond: - // result: (GreaterEqual x) + // match: (CSEL {cc} x y (CMPWconst [0] bool)) + // cond: cc.(Op) == OpARM64Equal && flagArg(bool) != nil + // result: (CSEL {arm64Negate(bool.Op)} x y flagArg(bool)) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64InvertFlags { + cc := v.Aux + _ = v.Args[2] + x := v.Args[0] + y := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64CMPWconst { break } - x := v_0.Args[0] - v.reset(OpARM64GreaterEqual) + if v_2.AuxInt != 0 { + break + } + bool := v_2.Args[0] + if !(cc.(Op) == OpARM64Equal && flagArg(bool) != nil) { + break + } + v.reset(OpARM64CSEL) + v.Aux = arm64Negate(bool.Op) v.AddArg(x) + v.AddArg(y) + v.AddArg(flagArg(bool)) return true } return false } -func rewriteValueARM64_OpARM64LessEqualU_0(v *Value) bool { - // match: (LessEqualU (FlagEQ)) +func rewriteValueARM64_OpARM64CSEL0_0(v *Value) bool { + // match: (CSEL0 {cc} x (InvertFlags cmp)) // cond: - // result: (MOVDconst [1]) + // result: (CSEL0 {arm64Invert(cc.(Op))} x cmp) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagEQ { + cc := v.Aux + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64InvertFlags { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + cmp := v_1.Args[0] + v.reset(OpARM64CSEL0) + v.Aux = arm64Invert(cc.(Op)) + v.AddArg(x) + v.AddArg(cmp) return true } - // match: (LessEqualU (FlagLT_ULT)) - // cond: - // result: (MOVDconst [1]) + // match: (CSEL0 {cc} x flag) + // cond: ccARM64Eval(cc, flag) > 0 + // result: x for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_ULT { + cc := v.Aux + _ = v.Args[1] + x := v.Args[0] + flag := v.Args[1] + if !(ccARM64Eval(cc, flag) > 0) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - // match: (LessEqualU (FlagLT_UGT)) - // cond: + // match: (CSEL0 {cc} _ flag) + // cond: ccARM64Eval(cc, flag) < 0 // result: (MOVDconst [0]) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_UGT { + cc := v.Aux + _ = v.Args[1] + flag := v.Args[1] + if !(ccARM64Eval(cc, flag) < 0) { break } v.reset(OpARM64MOVDconst) v.AuxInt = 0 return true } - // match: (LessEqualU (FlagGT_ULT)) - // cond: - // result: (MOVDconst [1]) + // match: (CSEL0 {cc} x (CMPWconst [0] bool)) + // cond: cc.(Op) == OpARM64NotEqual && flagArg(bool) != nil + // result: (CSEL0 {bool.Op} x flagArg(bool)) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_ULT { + cc := v.Aux + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64CMPWconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 - return true - } - // match: (LessEqualU (FlagGT_UGT)) - // cond: - // result: (MOVDconst [0]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_UGT { + if v_1.AuxInt != 0 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (LessEqualU (InvertFlags x)) - // cond: - // result: (GreaterEqualU x) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64InvertFlags { + bool := v_1.Args[0] + if !(cc.(Op) == OpARM64NotEqual && flagArg(bool) != nil) { break } - x := v_0.Args[0] - v.reset(OpARM64GreaterEqualU) + v.reset(OpARM64CSEL0) + v.Aux = bool.Op v.AddArg(x) + v.AddArg(flagArg(bool)) return true } - return false -} -func rewriteValueARM64_OpARM64LessThan_0(v *Value) bool { - // match: (LessThan (FlagEQ)) - // cond: - // result: (MOVDconst [0]) + // match: (CSEL0 {cc} x (CMPWconst [0] bool)) + // cond: cc.(Op) == OpARM64Equal && flagArg(bool) != nil + // result: (CSEL0 {arm64Negate(bool.Op)} x flagArg(bool)) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagEQ { + cc := v.Aux + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64CMPWconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (LessThan (FlagLT_ULT)) - // cond: - // result: (MOVDconst [1]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_ULT { + if v_1.AuxInt != 0 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 - return true - } - // match: (LessThan (FlagLT_UGT)) - // cond: - // result: (MOVDconst [1]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_UGT { + bool := v_1.Args[0] + if !(cc.(Op) == OpARM64Equal && flagArg(bool) != nil) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + v.reset(OpARM64CSEL0) + v.Aux = arm64Negate(bool.Op) + v.AddArg(x) + v.AddArg(flagArg(bool)) return true } - // match: (LessThan (FlagGT_ULT)) + return false +} +func rewriteValueARM64_OpARM64DIV_0(v *Value) bool { + // match: (DIV (MOVDconst [c]) (MOVDconst [d])) // cond: - // result: (MOVDconst [0]) + // result: (MOVDconst [c/d]) for { + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_ULT { + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (LessThan (FlagGT_UGT)) - // cond: - // result: (MOVDconst [0]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_UGT { + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } + d := v_1.AuxInt v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.AuxInt = c / d return true } - // match: (LessThan (InvertFlags x)) + return false +} +func rewriteValueARM64_OpARM64DIVW_0(v *Value) bool { + // match: (DIVW (MOVDconst [c]) (MOVDconst [d])) // cond: - // result: (GreaterThan x) + // result: (MOVDconst [int64(int32(c)/int32(d))]) for { + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64InvertFlags { + if v_0.Op != OpARM64MOVDconst { break } - x := v_0.Args[0] - v.reset(OpARM64GreaterThan) - v.AddArg(x) + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(int32(c) / int32(d)) return true } return false } -func rewriteValueARM64_OpARM64LessThanU_0(v *Value) bool { - // match: (LessThanU (FlagEQ)) +func rewriteValueARM64_OpARM64EON_0(v *Value) bool { + // match: (EON x (MOVDconst [c])) // cond: - // result: (MOVDconst [0]) + // result: (XORconst [^c] x) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagEQ { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + c := v_1.AuxInt + v.reset(OpARM64XORconst) + v.AuxInt = ^c + v.AddArg(x) return true } - // match: (LessThanU (FlagLT_ULT)) + // match: (EON x x) // cond: - // result: (MOVDconst [1]) + // result: (MOVDconst [-1]) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_ULT { + _ = v.Args[1] + x := v.Args[0] + if x != v.Args[1] { break } v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + v.AuxInt = -1 return true } - // match: (LessThanU (FlagLT_UGT)) - // cond: - // result: (MOVDconst [0]) + // match: (EON x0 x1:(SLLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (EONshiftLL x0 y [c]) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_UGT { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SLLconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (LessThanU (FlagGT_ULT)) - // cond: - // result: (MOVDconst [1]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_ULT { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 + v.reset(OpARM64EONshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } - // match: (LessThanU (FlagGT_UGT)) - // cond: - // result: (MOVDconst [0]) + // match: (EON x0 x1:(SRLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (EONshiftRL x0 y [c]) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_UGT { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64EONshiftRL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } - // match: (LessThanU (InvertFlags x)) - // cond: - // result: (GreaterThanU x) + // match: (EON x0 x1:(SRAconst [c] y)) + // cond: clobberIfDead(x1) + // result: (EONshiftRA x0 y [c]) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64InvertFlags { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRAconst { break } - x := v_0.Args[0] - v.reset(OpARM64GreaterThanU) - v.AddArg(x) + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64EONshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64MNEG_0(v *Value) bool { - b := v.Block - _ = b - // match: (MNEG x (MOVDconst [-1])) +func rewriteValueARM64_OpARM64EONshiftLL_0(v *Value) bool { + // match: (EONshiftLL x (MOVDconst [c]) [d]) // cond: - // result: x + // result: (XORconst x [^int64(uint64(c)<>uint64(d))]) for { + d := v.AuxInt _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 0 { - break - } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + c := v_1.AuxInt + v.reset(OpARM64XORconst) + v.AuxInt = ^(c >> uint64(d)) + v.AddArg(x) return true } - // match: (MNEG (MOVDconst [0]) _) - // cond: - // result: (MOVDconst [0]) + // match: (EONshiftRA x (SRAconst x [c]) [d]) + // cond: c==d + // result: (MOVDconst [-1]) for { + d := v.AuxInt _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRAconst { break } - if v_0.AuxInt != 0 { + c := v_1.AuxInt + if x != v_1.Args[0] { + break + } + if !(c == d) { break } v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.AuxInt = -1 return true } - // match: (MNEG x (MOVDconst [1])) + return false +} +func rewriteValueARM64_OpARM64EONshiftRL_0(v *Value) bool { + // match: (EONshiftRL x (MOVDconst [c]) [d]) // cond: - // result: (NEG x) + // result: (XORconst x [^int64(uint64(c)>>uint64(d))]) for { + d := v.AuxInt _ = v.Args[1] x := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 1 { - break - } - v.reset(OpARM64NEG) - v.AddArg(x) - return true - } - // match: (MNEG (MOVDconst [1]) x) - // cond: - // result: (NEG x) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - if v_0.AuxInt != 1 { - break - } - x := v.Args[1] - v.reset(OpARM64NEG) + c := v_1.AuxInt + v.reset(OpARM64XORconst) + v.AuxInt = ^int64(uint64(c) >> uint64(d)) v.AddArg(x) return true } - // match: (MNEG x (MOVDconst [c])) - // cond: isPowerOfTwo(c) - // result: (NEG (SLLconst [log2(c)] x)) + // match: (EONshiftRL x (SRLconst x [c]) [d]) + // cond: c==d + // result: (MOVDconst [-1]) for { + d := v.AuxInt _ = v.Args[1] x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64SRLconst { break } c := v_1.AuxInt - if !(isPowerOfTwo(c)) { + if x != v_1.Args[0] { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c) - v0.AddArg(x) - v.AddArg(v0) + if !(c == d) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = -1 return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: isPowerOfTwo(c) - // result: (NEG (SLLconst [log2(c)] x)) + return false +} +func rewriteValueARM64_OpARM64Equal_0(v *Value) bool { + // match: (Equal (FlagEQ)) + // cond: + // result: (MOVDconst [1]) for { - _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64FlagEQ { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c)) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 + return true + } + // match: (Equal (FlagLT_ULT)) + // cond: + // result: (MOVDconst [0]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_ULT { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MNEG x (MOVDconst [c])) - // cond: isPowerOfTwo(c-1) && c >= 3 - // result: (NEG (ADDshiftLL x x [log2(c-1)])) + // match: (Equal (FlagLT_UGT)) + // cond: + // result: (MOVDconst [0]) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_UGT { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c-1) && c >= 3) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (Equal (FlagGT_ULT)) + // cond: + // result: (MOVDconst [0]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_ULT { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c - 1) - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: isPowerOfTwo(c-1) && c >= 3 - // result: (NEG (ADDshiftLL x x [log2(c-1)])) + // match: (Equal (FlagGT_UGT)) + // cond: + // result: (MOVDconst [0]) for { - _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64FlagGT_UGT { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c-1) && c >= 3) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (Equal (InvertFlags x)) + // cond: + // result: (Equal x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64InvertFlags { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c - 1) - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + x := v_0.Args[0] + v.reset(OpARM64Equal) + v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64MNEG_10(v *Value) bool { - b := v.Block - _ = b - // match: (MNEG x (MOVDconst [c])) - // cond: isPowerOfTwo(c+1) && c >= 7 - // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) +func rewriteValueARM64_OpARM64FADDD_0(v *Value) bool { + // match: (FADDD a (FMULD x y)) + // cond: + // result: (FMADDD a x y) for { _ = v.Args[1] - x := v.Args[0] + a := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - c := v_1.AuxInt - if !(isPowerOfTwo(c+1) && c >= 7) { + if v_1.Op != OpARM64FMULD { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c + 1) - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) + _ = v_1.Args[1] + x := v_1.Args[0] + y := v_1.Args[1] + v.reset(OpARM64FMADDD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: isPowerOfTwo(c+1) && c >= 7 - // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) + // match: (FADDD (FMULD x y) a) + // cond: + // result: (FMADDD a x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c+1) && c >= 7) { + if v_0.Op != OpARM64FMULD { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c + 1) - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + a := v.Args[1] + v.reset(OpARM64FMADDD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MNEG x (MOVDconst [c])) - // cond: c%3 == 0 && isPowerOfTwo(c/3) - // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + // match: (FADDD a (FNMULD x y)) + // cond: + // result: (FMSUBD a x y) for { _ = v.Args[1] - x := v.Args[0] + a := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - c := v_1.AuxInt - if !(c%3 == 0 && isPowerOfTwo(c/3)) { + if v_1.Op != OpARM64FNMULD { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + _ = v_1.Args[1] + x := v_1.Args[0] + y := v_1.Args[1] + v.reset(OpARM64FMSUBD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: c%3 == 0 && isPowerOfTwo(c/3) - // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + // match: (FADDD (FNMULD x y) a) + // cond: + // result: (FMSUBD a x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - c := v_0.AuxInt - x := v.Args[1] - if !(c%3 == 0 && isPowerOfTwo(c/3)) { + if v_0.Op != OpARM64FNMULD { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + a := v.Args[1] + v.reset(OpARM64FMSUBD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MNEG x (MOVDconst [c])) - // cond: c%5 == 0 && isPowerOfTwo(c/5) - // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) + return false +} +func rewriteValueARM64_OpARM64FADDS_0(v *Value) bool { + // match: (FADDS a (FMULS x y)) + // cond: + // result: (FMADDS a x y) for { _ = v.Args[1] - x := v.Args[0] + a := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - c := v_1.AuxInt - if !(c%5 == 0 && isPowerOfTwo(c/5)) { + if v_1.Op != OpARM64FMULS { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 5) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 2 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) - v.AddArg(v0) + _ = v_1.Args[1] + x := v_1.Args[0] + y := v_1.Args[1] + v.reset(OpARM64FMADDS) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: c%5 == 0 && isPowerOfTwo(c/5) - // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) + // match: (FADDS (FMULS x y) a) + // cond: + // result: (FMADDS a x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - c := v_0.AuxInt - x := v.Args[1] - if !(c%5 == 0 && isPowerOfTwo(c/5)) { + if v_0.Op != OpARM64FMULS { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 5) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 2 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) - v.AddArg(v0) + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + a := v.Args[1] + v.reset(OpARM64FMADDS) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MNEG x (MOVDconst [c])) - // cond: c%7 == 0 && isPowerOfTwo(c/7) - // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + // match: (FADDS a (FNMULS x y)) + // cond: + // result: (FMSUBS a x y) for { _ = v.Args[1] - x := v.Args[0] + a := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - c := v_1.AuxInt - if !(c%7 == 0 && isPowerOfTwo(c/7)) { + if v_1.Op != OpARM64FNMULS { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 7) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 3 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + _ = v_1.Args[1] + x := v_1.Args[0] + y := v_1.Args[1] + v.reset(OpARM64FMSUBS) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: c%7 == 0 && isPowerOfTwo(c/7) - // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + // match: (FADDS (FNMULS x y) a) + // cond: + // result: (FMSUBS a x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64FNMULS { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%7 == 0 && isPowerOfTwo(c/7)) { + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + a := v.Args[1] + v.reset(OpARM64FMSUBS) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + return false +} +func rewriteValueARM64_OpARM64FMOVDfpgp_0(v *Value) bool { + b := v.Block + _ = b + // match: (FMOVDfpgp (Arg [off] {sym})) + // cond: + // result: @b.Func.Entry (Arg [off] {sym}) + for { + t := v.Type + v_0 := v.Args[0] + if v_0.Op != OpArg { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 7) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 3 - v0.AddArg(x) - v0.AddArg(x) + off := v_0.AuxInt + sym := v_0.Aux + b = b.Func.Entry + v0 := b.NewValue0(v.Pos, OpArg, t) + v.reset(OpCopy) v.AddArg(v0) + v0.AuxInt = off + v0.Aux = sym return true } - // match: (MNEG x (MOVDconst [c])) - // cond: c%9 == 0 && isPowerOfTwo(c/9) - // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + return false +} +func rewriteValueARM64_OpARM64FMOVDgpfp_0(v *Value) bool { + b := v.Block + _ = b + // match: (FMOVDgpfp (Arg [off] {sym})) + // cond: + // result: @b.Func.Entry (Arg [off] {sym}) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - c := v_1.AuxInt - if !(c%9 == 0 && isPowerOfTwo(c/9)) { + t := v.Type + v_0 := v.Args[0] + if v_0.Op != OpArg { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 9) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 3 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) + off := v_0.AuxInt + sym := v_0.Aux + b = b.Func.Entry + v0 := b.NewValue0(v.Pos, OpArg, t) + v.reset(OpCopy) v.AddArg(v0) + v0.AuxInt = off + v0.Aux = sym return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: c%9 == 0 && isPowerOfTwo(c/9) - // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + return false +} +func rewriteValueARM64_OpARM64FMOVDload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (FMOVDload [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (FMOVDload [off1+off2] {sym} ptr mem) for { + off1 := v.AuxInt + sym := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64ADDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%9 == 0 && isPowerOfTwo(c/9)) { + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 9) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 3 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) - v.AddArg(v0) + v.reset(OpARM64FMOVDload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MNEG_20(v *Value) bool { - // match: (MNEG (MOVDconst [c]) (MOVDconst [d])) - // cond: - // result: (MOVDconst [-c*d]) + // match: (FMOVDload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (FMOVDloadidx ptr idx mem) for { + off := v.AuxInt + sym := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64ADD { break } - c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = -c * d + v.reset(OpARM64FMOVDloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) return true } - // match: (MNEG (MOVDconst [d]) (MOVDconst [c])) - // cond: - // result: (MOVDconst [-c*d]) + // match: (FMOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (FMOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) for { + off1 := v.AuxInt + sym1 := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64MOVDaddr { break } - d := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - c := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = -c * d + v.reset(OpARM64FMOVDload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MNEGW_0(v *Value) bool { - b := v.Block - _ = b - // match: (MNEGW x (MOVDconst [c])) - // cond: int32(c)==-1 - // result: x +func rewriteValueARM64_OpARM64FMOVDloadidx_0(v *Value) bool { + // match: (FMOVDloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (FMOVDload [c] ptr mem) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(int32(c) == -1) { - break - } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) + mem := v.Args[2] + v.reset(OpARM64FMOVDload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: int32(c)==-1 - // result: x + // match: (FMOVDloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (FMOVDload [c] ptr mem) for { - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - x := v.Args[1] - if !(int32(c) == -1) { - break - } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64FMOVDload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) return true } - // match: (MNEGW _ (MOVDconst [c])) - // cond: int32(c)==0 - // result: (MOVDconst [0]) + return false +} +func rewriteValueARM64_OpARM64FMOVDstore_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (FMOVDstore ptr (FMOVDgpfp val) mem) + // cond: + // result: (MOVDstore ptr val mem) for { - _ = v.Args[1] + _ = v.Args[2] + ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - c := v_1.AuxInt - if !(int32(c) == 0) { + if v_1.Op != OpARM64FMOVDgpfp { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + val := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVDstore) + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) return true } - // match: (MNEGW (MOVDconst [c]) _) - // cond: int32(c)==0 - // result: (MOVDconst [0]) + // match: (FMOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (FMOVDstore [off1+off2] {sym} ptr val mem) for { - _ = v.Args[1] + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64ADDconst { break } - c := v_0.AuxInt - if !(int32(c) == 0) { + off2 := v_0.AuxInt + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64FMOVDstore) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: int32(c)==1 - // result: (NEG x) + // match: (FMOVDstore [off] {sym} (ADD ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (FMOVDstoreidx ptr idx val mem) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - c := v_1.AuxInt - if !(int32(c) == 1) { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { break } - v.reset(OpARM64NEG) - v.AddArg(x) + v.reset(OpARM64FMOVDstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: int32(c)==1 - // result: (NEG x) + // match: (FMOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (FMOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) for { - _ = v.Args[1] + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64MOVDaddr { break } - c := v_0.AuxInt - x := v.Args[1] - if !(int32(c) == 1) { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64NEG) - v.AddArg(x) + v.reset(OpARM64FMOVDstore) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: isPowerOfTwo(c) - // result: (NEG (SLLconst [log2(c)] x)) + return false +} +func rewriteValueARM64_OpARM64FMOVDstoreidx_0(v *Value) bool { + // match: (FMOVDstoreidx ptr (MOVDconst [c]) val mem) + // cond: + // result: (FMOVDstore [c] ptr val mem) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[3] + ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(isPowerOfTwo(c)) { - break - } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MNEGW (MOVDconst [c]) x) - // cond: isPowerOfTwo(c) - // result: (NEG (SLLconst [log2(c)] x)) + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64FMOVDstore) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (FMOVDstoreidx (MOVDconst [c]) idx val mem) + // cond: + // result: (FMOVDstore [c] idx val mem) for { - _ = v.Args[1] + _ = v.Args[3] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c)) { + idx := v.Args[1] + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64FMOVDstore) + v.AuxInt = c + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64FMOVSload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (FMOVSload [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (FMOVSload [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c) - v0.AddArg(x) - v.AddArg(v0) + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64FMOVSload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: isPowerOfTwo(c-1) && int32(c) >= 3 - // result: (NEG (ADDshiftLL x x [log2(c-1)])) + // match: (FMOVSload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (FMOVSloadidx ptr idx mem) for { + off := v.AuxInt + sym := v.Aux _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c-1) && int32(c) >= 3) { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c - 1) - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpARM64FMOVSloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: isPowerOfTwo(c-1) && int32(c) >= 3 - // result: (NEG (ADDshiftLL x x [log2(c-1)])) + // match: (FMOVSload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (FMOVSload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) for { + off1 := v.AuxInt + sym1 := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64MOVDaddr { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c-1) && int32(c) >= 3) { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c - 1) - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpARM64FMOVSload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MNEGW_10(v *Value) bool { - b := v.Block - _ = b - // match: (MNEGW x (MOVDconst [c])) - // cond: isPowerOfTwo(c+1) && int32(c) >= 7 - // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) +func rewriteValueARM64_OpARM64FMOVSloadidx_0(v *Value) bool { + // match: (FMOVSloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (FMOVSload [c] ptr mem) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(isPowerOfTwo(c+1) && int32(c) >= 7) { - break - } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c + 1) - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) + mem := v.Args[2] + v.reset(OpARM64FMOVSload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: isPowerOfTwo(c+1) && int32(c) >= 7 - // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) + // match: (FMOVSloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (FMOVSload [c] ptr mem) for { - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c+1) && int32(c) >= 7) { - break - } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c + 1) - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64FMOVSload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) - // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + return false +} +func rewriteValueARM64_OpARM64FMOVSstore_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (FMOVSstore [off1] {sym} (ADDconst [off2] ptr) val mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (FMOVSstore [off1+off2] {sym} ptr val mem) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - c := v_1.AuxInt - if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { + off2 := v_0.AuxInt + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpARM64FMOVSstore) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) - // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + // match: (FMOVSstore [off] {sym} (ADD ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (FMOVSstoreidx ptr idx val mem) for { - _ = v.Args[1] + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64ADD { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpARM64FMOVSstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) - // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) + // match: (FMOVSstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (FMOVSstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - c := v_1.AuxInt - if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { - break - } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 5) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 2 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) - v.AddArg(v0) - return true - } - // match: (MNEGW (MOVDconst [c]) x) - // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) - // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) - for { - _ = v.Args[1] + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64MOVDaddr { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 5) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 2 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) - v.AddArg(v0) + v.reset(OpARM64FMOVSstore) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) - // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + return false +} +func rewriteValueARM64_OpARM64FMOVSstoreidx_0(v *Value) bool { + // match: (FMOVSstoreidx ptr (MOVDconst [c]) val mem) + // cond: + // result: (FMOVSstore [c] ptr val mem) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[3] + ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { - break - } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 7) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 3 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64FMOVSstore) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) - // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + // match: (FMOVSstoreidx (MOVDconst [c]) idx val mem) + // cond: + // result: (FMOVSstore [c] idx val mem) for { - _ = v.Args[1] + _ = v.Args[3] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - x := v.Args[1] - if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { - break - } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 7) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 3 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + idx := v.Args[1] + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64FMOVSstore) + v.AuxInt = c + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) - // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + return false +} +func rewriteValueARM64_OpARM64FMULD_0(v *Value) bool { + // match: (FMULD (FNEGD x) y) + // cond: + // result: (FNMULD x y) for { _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - c := v_1.AuxInt - if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { + v_0 := v.Args[0] + if v_0.Op != OpARM64FNEGD { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 9) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 3 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) - v.AddArg(v0) + x := v_0.Args[0] + y := v.Args[1] + v.reset(OpARM64FNMULD) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) - // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + // match: (FMULD y (FNEGD x)) + // cond: + // result: (FNMULD x y) for { _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - c := v_0.AuxInt - x := v.Args[1] - if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { + y := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FNEGD { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 9) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 3 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) - v.AddArg(v0) + x := v_1.Args[0] + v.reset(OpARM64FNMULD) + v.AddArg(x) + v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64MNEGW_20(v *Value) bool { - // match: (MNEGW (MOVDconst [c]) (MOVDconst [d])) +func rewriteValueARM64_OpARM64FMULS_0(v *Value) bool { + // match: (FMULS (FNEGS x) y) // cond: - // result: (MOVDconst [-int64(int32(c)*int32(d))]) + // result: (FNMULS x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64FNEGS { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = -int64(int32(c) * int32(d)) + x := v_0.Args[0] + y := v.Args[1] + v.reset(OpARM64FNMULS) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MNEGW (MOVDconst [d]) (MOVDconst [c])) + // match: (FMULS y (FNEGS x)) // cond: - // result: (MOVDconst [-int64(int32(c)*int32(d))]) + // result: (FNMULS x y) for { _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - d := v_0.AuxInt + y := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64FNEGS { break } - c := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = -int64(int32(c) * int32(d)) + x := v_1.Args[0] + v.reset(OpARM64FNMULS) + v.AddArg(x) + v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64MOD_0(v *Value) bool { - // match: (MOD (MOVDconst [c]) (MOVDconst [d])) +func rewriteValueARM64_OpARM64FNEGD_0(v *Value) bool { + // match: (FNEGD (FMULD x y)) // cond: - // result: (MOVDconst [c%d]) + // result: (FNMULD x y) for { - _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64FMULD { break } - c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + v.reset(OpARM64FNMULD) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (FNEGD (FNMULD x y)) + // cond: + // result: (FMULD x y) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FNMULD { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = c % d + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + v.reset(OpARM64FMULD) + v.AddArg(x) + v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64MODW_0(v *Value) bool { - // match: (MODW (MOVDconst [c]) (MOVDconst [d])) +func rewriteValueARM64_OpARM64FNEGS_0(v *Value) bool { + // match: (FNEGS (FMULS x y)) // cond: - // result: (MOVDconst [int64(int32(c)%int32(d))]) + // result: (FNMULS x y) for { - _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64FMULS { break } - c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + v.reset(OpARM64FNMULS) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (FNEGS (FNMULS x y)) + // cond: + // result: (FMULS x y) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FNMULS { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(int32(c) % int32(d)) + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + v.reset(OpARM64FMULS) + v.AddArg(x) + v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64MOVBUload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVBUload [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBUload [off1+off2] {sym} ptr mem) +func rewriteValueARM64_OpARM64FNMULD_0(v *Value) bool { + // match: (FNMULD (FNEGD x) y) + // cond: + // result: (FMULD x y) for { - off1 := v.AuxInt - sym := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { - break - } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_0.Op != OpARM64FNEGD { break } - v.reset(OpARM64MOVBUload) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + x := v_0.Args[0] + y := v.Args[1] + v.reset(OpARM64FMULD) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVBUload [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVBUloadidx ptr idx mem) + // match: (FNMULD y (FNEGD x)) + // cond: + // result: (FMULD x y) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + y := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FNEGD { break } - v.reset(OpARM64MOVBUloadidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + x := v_1.Args[0] + v.reset(OpARM64FMULD) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVBUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + return false +} +func rewriteValueARM64_OpARM64FNMULS_0(v *Value) bool { + // match: (FNMULS (FNEGS x) y) + // cond: + // result: (FMULS x y) for { - off1 := v.AuxInt - sym1 := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { - break - } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_0.Op != OpARM64FNEGS { break } - v.reset(OpARM64MOVBUload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) + x := v_0.Args[0] + y := v.Args[1] + v.reset(OpARM64FMULS) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVBUload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) - // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) - // result: (MOVDconst [0]) + // match: (FNMULS y (FNEGS x)) + // cond: + // result: (FMULS x y) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[1] - ptr := v.Args[0] + y := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVBstorezero { - break - } - off2 := v_1.AuxInt - sym2 := v_1.Aux - _ = v_1.Args[1] - ptr2 := v_1.Args[0] - if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + if v_1.Op != OpARM64FNEGS { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + x := v_1.Args[0] + v.reset(OpARM64FMULS) + v.AddArg(x) + v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64MOVBUloadidx_0(v *Value) bool { - // match: (MOVBUloadidx ptr (MOVDconst [c]) mem) +func rewriteValueARM64_OpARM64FSUBD_0(v *Value) bool { + // match: (FSUBD a (FMULD x y)) // cond: - // result: (MOVBUload [c] ptr mem) + // result: (FMSUBD a x y) for { - _ = v.Args[2] - ptr := v.Args[0] + _ = v.Args[1] + a := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64FMULD { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVBUload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + _ = v_1.Args[1] + x := v_1.Args[0] + y := v_1.Args[1] + v.reset(OpARM64FMSUBD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVBUloadidx (MOVDconst [c]) ptr mem) + // match: (FSUBD (FMULD x y) a) // cond: - // result: (MOVBUload [c] ptr mem) + // result: (FNMSUBD a x y) for { - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64FMULD { break } - c := v_0.AuxInt - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVBUload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + a := v.Args[1] + v.reset(OpARM64FNMSUBD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVBUloadidx ptr idx (MOVBstorezeroidx ptr2 idx2 _)) - // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) - // result: (MOVDconst [0]) + // match: (FSUBD a (FNMULD x y)) + // cond: + // result: (FMADDD a x y) for { - _ = v.Args[2] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVBstorezeroidx { - break - } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + _ = v.Args[1] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FNMULD { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + _ = v_1.Args[1] + x := v_1.Args[0] + y := v_1.Args[1] + v.reset(OpARM64FMADDD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) return true } - return false -} -func rewriteValueARM64_OpARM64MOVBUreg_0(v *Value) bool { - // match: (MOVBUreg x:(MOVBUload _ _)) + // match: (FSUBD (FNMULD x y) a) // cond: - // result: (MOVDreg x) + // result: (FNMADDD a x y) for { - x := v.Args[0] - if x.Op != OpARM64MOVBUload { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64FNMULD { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + a := v.Args[1] + v.reset(OpARM64FNMADDD) + v.AddArg(a) v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVBUreg x:(MOVBUloadidx _ _ _)) + return false +} +func rewriteValueARM64_OpARM64FSUBS_0(v *Value) bool { + // match: (FSUBS a (FMULS x y)) // cond: - // result: (MOVDreg x) + // result: (FMSUBS a x y) for { - x := v.Args[0] - if x.Op != OpARM64MOVBUloadidx { + _ = v.Args[1] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FMULS { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) + _ = v_1.Args[1] + x := v_1.Args[0] + y := v_1.Args[1] + v.reset(OpARM64FMSUBS) + v.AddArg(a) v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVBUreg x:(MOVBUreg _)) + // match: (FSUBS (FMULS x y) a) // cond: - // result: (MOVDreg x) + // result: (FNMSUBS a x y) for { - x := v.Args[0] - if x.Op != OpARM64MOVBUreg { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64FMULS { break } - v.reset(OpARM64MOVDreg) + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + a := v.Args[1] + v.reset(OpARM64FNMSUBS) + v.AddArg(a) v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVBUreg (ANDconst [c] x)) + // match: (FSUBS a (FNMULS x y)) // cond: - // result: (ANDconst [c&(1<<8-1)] x) + // result: (FMADDS a x y) + for { + _ = v.Args[1] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FNMULS { + break + } + _ = v_1.Args[1] + x := v_1.Args[0] + y := v_1.Args[1] + v.reset(OpARM64FMADDS) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (FSUBS (FNMULS x y) a) + // cond: + // result: (FNMADDS a x y) for { + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ANDconst { + if v_0.Op != OpARM64FNMULS { break } - c := v_0.AuxInt + _ = v_0.Args[1] x := v_0.Args[0] - v.reset(OpARM64ANDconst) - v.AuxInt = c & (1<<8 - 1) + y := v_0.Args[1] + a := v.Args[1] + v.reset(OpARM64FNMADDS) + v.AddArg(a) v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVBUreg (MOVDconst [c])) + return false +} +func rewriteValueARM64_OpARM64GreaterEqual_0(v *Value) bool { + // match: (GreaterEqual (FlagEQ)) // cond: - // result: (MOVDconst [int64(uint8(c))]) + // result: (MOVDconst [1]) for { v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64FlagEQ { break } - c := v_0.AuxInt v.reset(OpARM64MOVDconst) - v.AuxInt = int64(uint8(c)) + v.AuxInt = 1 return true } - // match: (MOVBUreg x) - // cond: x.Type.IsBoolean() - // result: (MOVDreg x) + // match: (GreaterEqual (FlagLT_ULT)) + // cond: + // result: (MOVDconst [0]) for { - x := v.Args[0] - if !(x.Type.IsBoolean()) { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_ULT { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBUreg (SLLconst [sc] x)) - // cond: isARM64BFMask(sc, 1<<8-1, sc) - // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc))] x) + // match: (GreaterEqual (FlagLT_UGT)) + // cond: + // result: (MOVDconst [0]) for { v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_0.Op != OpARM64FlagLT_UGT { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<8-1, sc)) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (GreaterEqual (FlagGT_ULT)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_ULT { break } - v.reset(OpARM64UBFIZ) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc)) - v.AddArg(x) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBUreg (SRLconst [sc] x)) - // cond: isARM64BFMask(sc, 1<<8-1, 0) - // result: (UBFX [arm64BFAuxInt(sc, 8)] x) + // match: (GreaterEqual (FlagGT_UGT)) + // cond: + // result: (MOVDconst [1]) for { v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { + if v_0.Op != OpARM64FlagGT_UGT { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<8-1, 0)) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 + return true + } + // match: (GreaterEqual (InvertFlags x)) + // cond: + // result: (LessEqual x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64InvertFlags { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc, 8) + x := v_0.Args[0] + v.reset(OpARM64LessEqual) v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64MOVBload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVBload [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBload [off1+off2] {sym} ptr mem) +func rewriteValueARM64_OpARM64GreaterEqualU_0(v *Value) bool { + // match: (GreaterEqualU (FlagEQ)) + // cond: + // result: (MOVDconst [1]) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { - break - } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_0.Op != OpARM64FlagEQ { break } - v.reset(OpARM64MOVBload) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBload [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVBloadidx ptr idx mem) + // match: (GreaterEqualU (FlagLT_ULT)) + // cond: + // result: (MOVDconst [0]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + if v_0.Op != OpARM64FlagLT_ULT { break } - v.reset(OpARM64MOVBloadidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // match: (GreaterEqualU (FlagLT_UGT)) + // cond: + // result: (MOVDconst [1]) for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { - break - } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_0.Op != OpARM64FlagLT_UGT { break } - v.reset(OpARM64MOVBload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) - // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) + // match: (GreaterEqualU (FlagGT_ULT)) + // cond: // result: (MOVDconst [0]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVBstorezero { - break - } - off2 := v_1.AuxInt - sym2 := v_1.Aux - _ = v_1.Args[1] - ptr2 := v_1.Args[0] - if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_ULT { break } v.reset(OpARM64MOVDconst) v.AuxInt = 0 return true } - return false -} -func rewriteValueARM64_OpARM64MOVBloadidx_0(v *Value) bool { - // match: (MOVBloadidx ptr (MOVDconst [c]) mem) + // match: (GreaterEqualU (FlagGT_UGT)) // cond: - // result: (MOVBload [c] ptr mem) + // result: (MOVDconst [1]) for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_UGT { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVBload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBloadidx (MOVDconst [c]) ptr mem) + // match: (GreaterEqualU (InvertFlags x)) // cond: - // result: (MOVBload [c] ptr mem) + // result: (LessEqualU x) for { - _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64InvertFlags { break } - c := v_0.AuxInt - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVBload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + x := v_0.Args[0] + v.reset(OpARM64LessEqualU) + v.AddArg(x) return true } - // match: (MOVBloadidx ptr idx (MOVBstorezeroidx ptr2 idx2 _)) - // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + return false +} +func rewriteValueARM64_OpARM64GreaterThan_0(v *Value) bool { + // match: (GreaterThan (FlagEQ)) + // cond: // result: (MOVDconst [0]) for { - _ = v.Args[2] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVBstorezeroidx { - break - } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagEQ { break } v.reset(OpARM64MOVDconst) v.AuxInt = 0 return true } - return false -} -func rewriteValueARM64_OpARM64MOVBreg_0(v *Value) bool { - // match: (MOVBreg x:(MOVBload _ _)) + // match: (GreaterThan (FlagLT_ULT)) // cond: - // result: (MOVDreg x) + // result: (MOVDconst [0]) for { - x := v.Args[0] - if x.Op != OpARM64MOVBload { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_ULT { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBreg x:(MOVBloadidx _ _ _)) + // match: (GreaterThan (FlagLT_UGT)) // cond: - // result: (MOVDreg x) + // result: (MOVDconst [0]) for { - x := v.Args[0] - if x.Op != OpARM64MOVBloadidx { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_UGT { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBreg x:(MOVBreg _)) + // match: (GreaterThan (FlagGT_ULT)) // cond: - // result: (MOVDreg x) + // result: (MOVDconst [1]) for { - x := v.Args[0] - if x.Op != OpARM64MOVBreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_ULT { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBreg (MOVDconst [c])) + // match: (GreaterThan (FlagGT_UGT)) // cond: - // result: (MOVDconst [int64(int8(c))]) + // result: (MOVDconst [1]) for { v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64FlagGT_UGT { break } - c := v_0.AuxInt v.reset(OpARM64MOVDconst) - v.AuxInt = int64(int8(c)) + v.AuxInt = 1 return true } - // match: (MOVBreg (SLLconst [lc] x)) - // cond: lc < 8 - // result: (SBFIZ [arm64BFAuxInt(lc, 8-lc)] x) + // match: (GreaterThan (InvertFlags x)) + // cond: + // result: (LessThan x) for { v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_0.Op != OpARM64InvertFlags { break } - lc := v_0.AuxInt x := v_0.Args[0] - if !(lc < 8) { - break - } - v.reset(OpARM64SBFIZ) - v.AuxInt = arm64BFAuxInt(lc, 8-lc) + v.reset(OpARM64LessThan) v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64MOVBstore_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVBstore [off1] {sym} (ADDconst [off2] ptr) val mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBstore [off1+off2] {sym} ptr val mem) +func rewriteValueARM64_OpARM64GreaterThanU_0(v *Value) bool { + // match: (GreaterThanU (FlagEQ)) + // cond: + // result: (MOVDconst [0]) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { - break - } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_0.Op != OpARM64FlagEQ { break } - v.reset(OpARM64MOVBstore) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBstore [off] {sym} (ADD ptr idx) val mem) - // cond: off == 0 && sym == nil - // result: (MOVBstoreidx ptr idx val mem) + // match: (GreaterThanU (FlagLT_ULT)) + // cond: + // result: (MOVDconst [0]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - val := v.Args[1] - mem := v.Args[2] - if !(off == 0 && sym == nil) { + if v_0.Op != OpARM64FlagLT_ULT { break } - v.reset(OpARM64MOVBstoreidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + // match: (GreaterThanU (FlagLT_UGT)) + // cond: + // result: (MOVDconst [1]) for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { - break - } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_0.Op != OpARM64FlagLT_UGT { break } - v.reset(OpARM64MOVBstore) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBstore [off] {sym} ptr (MOVDconst [0]) mem) + // match: (GreaterThanU (FlagGT_ULT)) // cond: - // result: (MOVBstorezero [off] {sym} ptr mem) + // result: (MOVDconst [0]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - if v_1.AuxInt != 0 { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_ULT { break } - mem := v.Args[2] - v.reset(OpARM64MOVBstorezero) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBstore [off] {sym} ptr (MOVBreg x) mem) + // match: (GreaterThanU (FlagGT_UGT)) // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + // result: (MOVDconst [1]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVBreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_UGT { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) + // match: (GreaterThanU (InvertFlags x)) // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + // result: (LessThanU x) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVBUreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64InvertFlags { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) + x := v_0.Args[0] + v.reset(OpARM64LessThanU) v.AddArg(x) - v.AddArg(mem) return true } - // match: (MOVBstore [off] {sym} ptr (MOVHreg x) mem) - // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + return false +} +func rewriteValueARM64_OpARM64LessEqual_0(v *Value) bool { + // match: (LessEqual (FlagEQ)) + // cond: + // result: (MOVDconst [1]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVHreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagEQ { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) + // match: (LessEqual (FlagLT_ULT)) // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + // result: (MOVDconst [1]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVHUreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_ULT { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBstore [off] {sym} ptr (MOVWreg x) mem) + // match: (LessEqual (FlagLT_UGT)) // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + // result: (MOVDconst [1]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_UGT { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBstore [off] {sym} ptr (MOVWUreg x) mem) + // match: (LessEqual (FlagGT_ULT)) // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + // result: (MOVDconst [0]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWUreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_ULT { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - return false -} -func rewriteValueARM64_OpARM64MOVBstore_10(v *Value) bool { - // match: (MOVBstore [i] {s} ptr0 (SRLconst [8] w) x:(MOVBstore [i-1] {s} ptr1 w mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVHstore [i-1] {s} ptr0 w mem) + // match: (LessEqual (FlagGT_UGT)) + // cond: + // result: (MOVDconst [0]) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_UGT { break } - if v_1.AuxInt != 8 { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (LessEqual (InvertFlags x)) + // cond: + // result: (GreaterEqual x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64InvertFlags { break } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + x := v_0.Args[0] + v.reset(OpARM64GreaterEqual) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64LessEqualU_0(v *Value) bool { + // match: (LessEqualU (FlagEQ)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagEQ { break } - if x.AuxInt != i-1 { + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 + return true + } + // match: (LessEqualU (FlagLT_ULT)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_ULT { break } - if x.Aux != s { + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 + return true + } + // match: (LessEqualU (FlagLT_UGT)) + // cond: + // result: (MOVDconst [0]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_UGT { break } - _ = x.Args[2] - ptr1 := x.Args[0] - if w != x.Args[1] { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (LessEqualU (FlagGT_ULT)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_ULT { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 + return true + } + // match: (LessEqualU (FlagGT_UGT)) + // cond: + // result: (MOVDconst [0]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_UGT { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (SRLconst [8] w) x:(MOVBstoreidx ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr1 idx1 w mem) + // match: (LessEqualU (InvertFlags x)) + // cond: + // result: (GreaterEqualU x) for { - if v.AuxInt != 1 { + v_0 := v.Args[0] + if v_0.Op != OpARM64InvertFlags { break } - s := v.Aux - _ = v.Args[2] + x := v_0.Args[0] + v.reset(OpARM64GreaterEqualU) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64LessThan_0(v *Value) bool { + // match: (LessThan (FlagEQ)) + // cond: + // result: (MOVDconst [0]) + for { v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + if v_0.Op != OpARM64FlagEQ { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (LessThan (FlagLT_ULT)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_ULT { break } - if v_1.AuxInt != 8 { + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 + return true + } + // match: (LessThan (FlagLT_UGT)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_UGT { break } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 + return true + } + // match: (LessThan (FlagGT_ULT)) + // cond: + // result: (MOVDconst [0]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_ULT { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { - break - } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { - break - } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBstore [i] {s} ptr0 (UBFX [arm64BFAuxInt(8, 8)] w) x:(MOVBstore [i-1] {s} ptr1 w mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVHstore [i-1] {s} ptr0 w mem) + // match: (LessThan (FlagGT_UGT)) + // cond: + // result: (MOVDconst [0]) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64UBFX { - break - } - if v_1.AuxInt != arm64BFAuxInt(8, 8) { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_UGT { break } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (LessThan (InvertFlags x)) + // cond: + // result: (GreaterThan x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64InvertFlags { break } - if x.AuxInt != i-1 { + x := v_0.Args[0] + v.reset(OpARM64GreaterThan) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64LessThanU_0(v *Value) bool { + // match: (LessThanU (FlagEQ)) + // cond: + // result: (MOVDconst [0]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagEQ { break } - if x.Aux != s { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (LessThanU (FlagLT_ULT)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_ULT { break } - _ = x.Args[2] - ptr1 := x.Args[0] - if w != x.Args[1] { + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 + return true + } + // match: (LessThanU (FlagLT_UGT)) + // cond: + // result: (MOVDconst [0]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_UGT { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (LessThanU (FlagGT_ULT)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_ULT { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (UBFX [arm64BFAuxInt(8, 8)] w) x:(MOVBstoreidx ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr1 idx1 w mem) + // match: (LessThanU (FlagGT_UGT)) + // cond: + // result: (MOVDconst [0]) for { - if v.AuxInt != 1 { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_UGT { break } - s := v.Aux - _ = v.Args[2] + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (LessThanU (InvertFlags x)) + // cond: + // result: (GreaterThanU x) + for { v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + if v_0.Op != OpARM64InvertFlags { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] + x := v_0.Args[0] + v.reset(OpARM64GreaterThanU) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64MNEG_0(v *Value) bool { + b := v.Block + _ = b + // match: (MNEG x (MOVDconst [-1])) + // cond: + // result: x + for { + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64UBFX { - break - } - if v_1.AuxInt != arm64BFAuxInt(8, 8) { + if v_1.Op != OpARM64MOVDconst { break } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { + if v_1.AuxInt != -1 { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (MNEG (MOVDconst [-1]) x) + // cond: + // result: x + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + if v_0.AuxInt != -1 { break } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w) - v.AddArg(mem) + x := v.Args[1] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - // match: (MOVBstore [i] {s} ptr0 (UBFX [arm64BFAuxInt(8, 24)] w) x:(MOVBstore [i-1] {s} ptr1 w mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVHstore [i-1] {s} ptr0 w mem) + // match: (MNEG _ (MOVDconst [0])) + // cond: + // result: (MOVDconst [0]) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] + _ = v.Args[1] v_1 := v.Args[1] - if v_1.Op != OpARM64UBFX { - break - } - if v_1.AuxInt != arm64BFAuxInt(8, 24) { + if v_1.Op != OpARM64MOVDconst { break } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + if v_1.AuxInt != 0 { break } - if x.AuxInt != i-1 { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (MNEG (MOVDconst [0]) _) + // cond: + // result: (MOVDconst [0]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x.Aux != s { + if v_0.AuxInt != 0 { break } - _ = x.Args[2] - ptr1 := x.Args[0] - if w != x.Args[1] { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (MNEG x (MOVDconst [1])) + // cond: + // result: (NEG x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + if v_1.AuxInt != 1 { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64NEG) + v.AddArg(x) return true } - // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (UBFX [arm64BFAuxInt(8, 24)] w) x:(MOVBstoreidx ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr1 idx1 w mem) + // match: (MNEG (MOVDconst [1]) x) + // cond: + // result: (NEG x) for { - if v.AuxInt != 1 { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - s := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + if v_0.AuxInt != 1 { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] + x := v.Args[1] + v.reset(OpARM64NEG) + v.AddArg(x) + return true + } + // match: (MNEG x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (NEG (SLLconst [log2(c)] x)) + for { + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64UBFX { - break - } - if v_1.AuxInt != arm64BFAuxInt(8, 24) { + if v_1.Op != OpARM64MOVDconst { break } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { + c := v_1.AuxInt + if !(isPowerOfTwo(c)) { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEG (MOVDconst [c]) x) + // cond: isPowerOfTwo(c) + // result: (NEG (SLLconst [log2(c)] x)) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c)) { break } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [i] {s} ptr0 (SRLconst [8] (MOVDreg w)) x:(MOVBstore [i-1] {s} ptr1 w mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVHstore [i-1] {s} ptr0 w mem) + // match: (MNEG x (MOVDconst [c])) + // cond: isPowerOfTwo(c-1) && c >= 3 + // result: (NEG (ADDshiftLL x x [log2(c-1)])) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - if v_1.AuxInt != 8 { - break - } - v_1_0 := v_1.Args[0] - if v_1_0.Op != OpARM64MOVDreg { + if v_1.Op != OpARM64MOVDconst { break } - w := v_1_0.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + c := v_1.AuxInt + if !(isPowerOfTwo(c-1) && c >= 3) { break } - if x.AuxInt != i-1 { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEG (MOVDconst [c]) x) + // cond: isPowerOfTwo(c-1) && c >= 3 + // result: (NEG (ADDshiftLL x x [log2(c-1)])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x.Aux != s { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c-1) && c >= 3) { break } - _ = x.Args[2] - ptr1 := x.Args[0] - if w != x.Args[1] { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + return false +} +func rewriteValueARM64_OpARM64MNEG_10(v *Value) bool { + b := v.Block + _ = b + // match: (MNEG x (MOVDconst [c])) + // cond: isPowerOfTwo(c+1) && c >= 7 + // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + c := v_1.AuxInt + if !(isPowerOfTwo(c+1) && c >= 7) { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (SRLconst [8] (MOVDreg w)) x:(MOVBstoreidx ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr1 idx1 w mem) + // match: (MNEG (MOVDconst [c]) x) + // cond: isPowerOfTwo(c+1) && c >= 7 + // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) for { - if v.AuxInt != 1 { - break - } - s := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + if v_0.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 8 { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c+1) && c >= 7) { break } - v_1_0 := v_1.Args[0] - if v_1_0.Op != OpARM64MOVDreg { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEG x (MOVDconst [c])) + // cond: c%3 == 0 && isPowerOfTwo(c/3) + // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - w := v_1_0.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { + c := v_1.AuxInt + if !(c%3 == 0 && isPowerOfTwo(c/3)) { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEG (MOVDconst [c]) x) + // cond: c%3 == 0 && isPowerOfTwo(c/3) + // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + c := v_0.AuxInt + x := v.Args[1] + if !(c%3 == 0 && isPowerOfTwo(c/3)) { break } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [i] {s} ptr0 (SRLconst [j] w) x:(MOVBstore [i-1] {s} ptr1 w0:(SRLconst [j-8] w) mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVHstore [i-1] {s} ptr0 w0 mem) + // match: (MNEG x (MOVDconst [c])) + // cond: c%5 == 0 && isPowerOfTwo(c/5) + // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + if v_1.Op != OpARM64MOVDconst { break } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + c := v_1.AuxInt + if !(c%5 == 0 && isPowerOfTwo(c/5)) { break } - if x.AuxInt != i-1 { - break + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 5) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 2 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + // match: (MNEG (MOVDconst [c]) x) + // cond: c%5 == 0 && isPowerOfTwo(c/5) + // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break } - if x.Aux != s { + c := v_0.AuxInt + x := v.Args[1] + if !(c%5 == 0 && isPowerOfTwo(c/5)) { break } - _ = x.Args[2] - ptr1 := x.Args[0] - w0 := x.Args[1] - if w0.Op != OpARM64SRLconst { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 5) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 2 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + // match: (MNEG x (MOVDconst [c])) + // cond: c%7 == 0 && isPowerOfTwo(c/7) + // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if w0.AuxInt != j-8 { + c := v_1.AuxInt + if !(c%7 == 0 && isPowerOfTwo(c/7)) { break } - if w != w0.Args[0] { + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEG (MOVDconst [c]) x) + // cond: c%7 == 0 && isPowerOfTwo(c/7) + // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + c := v_0.AuxInt + x := v.Args[1] + if !(c%7 == 0 && isPowerOfTwo(c/7)) { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w0) - v.AddArg(mem) + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (SRLconst [j] w) x:(MOVBstoreidx ptr1 idx1 w0:(SRLconst [j-8] w) mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr1 idx1 w0 mem) + // match: (MNEG x (MOVDconst [c])) + // cond: c%9 == 0 && isPowerOfTwo(c/9) + // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) for { - if v.AuxInt != 1 { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - s := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + c := v_1.AuxInt + if !(c%9 == 0 && isPowerOfTwo(c/9)) { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 9) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 3 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + // match: (MNEG (MOVDconst [c]) x) + // cond: c%9 == 0 && isPowerOfTwo(c/9) + // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { + c := v_0.AuxInt + x := v.Args[1] + if !(c%9 == 0 && isPowerOfTwo(c/9)) { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - w0 := x.Args[2] - if w0.Op != OpARM64SRLconst { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 9) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 3 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + return false +} +func rewriteValueARM64_OpARM64MNEG_20(v *Value) bool { + // match: (MNEG (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [-c*d]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if w0.AuxInt != j-8 { + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if w != w0.Args[0] { + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = -c * d + return true + } + // match: (MNEG (MOVDconst [d]) (MOVDconst [c])) + // cond: + // result: (MOVDconst [-c*d]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + d := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w0) - v.AddArg(mem) + c := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = -c * d return true } return false } -func rewriteValueARM64_OpARM64MOVBstore_20(v *Value) bool { +func rewriteValueARM64_OpARM64MNEGW_0(v *Value) bool { b := v.Block _ = b - // match: (MOVBstore [i] {s} ptr0 (UBFX [bfc] w) x:(MOVBstore [i-1] {s} ptr1 w0:(UBFX [bfc2] w) mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && getARM64BFwidth(bfc) == 32 - getARM64BFlsb(bfc) && getARM64BFwidth(bfc2) == 32 - getARM64BFlsb(bfc2) && getARM64BFlsb(bfc2) == getARM64BFlsb(bfc) - 8 && clobber(x) - // result: (MOVHstore [i-1] {s} ptr0 w0 mem) + // match: (MNEGW x (MOVDconst [c])) + // cond: int32(c)==-1 + // result: x for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64UBFX { - break - } - bfc := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + if v_1.Op != OpARM64MOVDconst { break } - if x.AuxInt != i-1 { + c := v_1.AuxInt + if !(int32(c) == -1) { break } - if x.Aux != s { + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (MNEGW (MOVDconst [c]) x) + // cond: int32(c)==-1 + // result: x + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - ptr1 := x.Args[0] - w0 := x.Args[1] - if w0.Op != OpARM64UBFX { + c := v_0.AuxInt + x := v.Args[1] + if !(int32(c) == -1) { break } - bfc2 := w0.AuxInt - if w != w0.Args[0] { + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (MNEGW _ (MOVDconst [c])) + // cond: int32(c)==0 + // result: (MOVDconst [0]) + for { + _ = v.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && getARM64BFwidth(bfc) == 32-getARM64BFlsb(bfc) && getARM64BFwidth(bfc2) == 32-getARM64BFlsb(bfc2) && getARM64BFlsb(bfc2) == getARM64BFlsb(bfc)-8 && clobber(x)) { + c := v_1.AuxInt + if !(int32(c) == 0) { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w0) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (UBFX [bfc] w) x:(MOVBstoreidx ptr1 idx1 w0:(UBFX [bfc2] w) mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && getARM64BFwidth(bfc) == 32 - getARM64BFlsb(bfc) && getARM64BFwidth(bfc2) == 32 - getARM64BFlsb(bfc2) && getARM64BFlsb(bfc2) == getARM64BFlsb(bfc) - 8 && clobber(x) - // result: (MOVHstoreidx ptr1 idx1 w0 mem) + // match: (MNEGW (MOVDconst [c]) _) + // cond: int32(c)==0 + // result: (MOVDconst [0]) for { - if v.AuxInt != 1 { - break - } - s := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + if v_0.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64UBFX { + c := v_0.AuxInt + if !(int32(c) == 0) { break } - bfc := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (MNEGW x (MOVDconst [c])) + // cond: int32(c)==1 + // result: (NEG x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - w0 := x.Args[2] - if w0.Op != OpARM64UBFX { + c := v_1.AuxInt + if !(int32(c) == 1) { break } - bfc2 := w0.AuxInt - if w != w0.Args[0] { + v.reset(OpARM64NEG) + v.AddArg(x) + return true + } + // match: (MNEGW (MOVDconst [c]) x) + // cond: int32(c)==1 + // result: (NEG x) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && getARM64BFwidth(bfc) == 32-getARM64BFlsb(bfc) && getARM64BFwidth(bfc2) == 32-getARM64BFlsb(bfc2) && getARM64BFlsb(bfc2) == getARM64BFlsb(bfc)-8 && clobber(x)) { + c := v_0.AuxInt + x := v.Args[1] + if !(int32(c) == 1) { break } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w0) - v.AddArg(mem) + v.reset(OpARM64NEG) + v.AddArg(x) return true } - // match: (MOVBstore [i] {s} ptr0 (SRLconst [j] (MOVDreg w)) x:(MOVBstore [i-1] {s} ptr1 w0:(SRLconst [j-8] (MOVDreg w)) mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVHstore [i-1] {s} ptr0 w0 mem) + // match: (MNEGW x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (NEG (SLLconst [log2(c)] x)) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + if v_1.Op != OpARM64MOVDconst { break } - j := v_1.AuxInt - v_1_0 := v_1.Args[0] - if v_1_0.Op != OpARM64MOVDreg { + c := v_1.AuxInt + if !(isPowerOfTwo(c)) { break } - w := v_1_0.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEGW (MOVDconst [c]) x) + // cond: isPowerOfTwo(c) + // result: (NEG (SLLconst [log2(c)] x)) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x.AuxInt != i-1 { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c)) { break } - if x.Aux != s { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEGW x (MOVDconst [c])) + // cond: isPowerOfTwo(c-1) && int32(c) >= 3 + // result: (NEG (ADDshiftLL x x [log2(c-1)])) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - ptr1 := x.Args[0] - w0 := x.Args[1] - if w0.Op != OpARM64SRLconst { + c := v_1.AuxInt + if !(isPowerOfTwo(c-1) && int32(c) >= 3) { break } - if w0.AuxInt != j-8 { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEGW (MOVDconst [c]) x) + // cond: isPowerOfTwo(c-1) && int32(c) >= 3 + // result: (NEG (ADDshiftLL x x [log2(c-1)])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - w0_0 := w0.Args[0] - if w0_0.Op != OpARM64MOVDreg { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c-1) && int32(c) >= 3) { break } - if w != w0_0.Args[0] { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + return false +} +func rewriteValueARM64_OpARM64MNEGW_10(v *Value) bool { + b := v.Block + _ = b + // match: (MNEGW x (MOVDconst [c])) + // cond: isPowerOfTwo(c+1) && int32(c) >= 7 + // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + c := v_1.AuxInt + if !(isPowerOfTwo(c+1) && int32(c) >= 7) { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w0) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (SRLconst [j] (MOVDreg w)) x:(MOVBstoreidx ptr1 idx1 w0:(SRLconst [j-8] (MOVDreg w)) mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr1 idx1 w0 mem) + // match: (MNEGW (MOVDconst [c]) x) + // cond: isPowerOfTwo(c+1) && int32(c) >= 7 + // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) for { - if v.AuxInt != 1 { - break - } - s := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - j := v_1.AuxInt - v_1_0 := v_1.Args[0] - if v_1_0.Op != OpARM64MOVDreg { + if v_0.Op != OpARM64MOVDconst { break } - w := v_1_0.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c+1) && int32(c) >= 7) { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - w0 := x.Args[2] - if w0.Op != OpARM64SRLconst { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEGW x (MOVDconst [c])) + // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) + // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if w0.AuxInt != j-8 { + c := v_1.AuxInt + if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { break } - w0_0 := w0.Args[0] - if w0_0.Op != OpARM64MOVDreg { - break - } - if w != w0_0.Args[0] { - break - } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { - break - } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w0) - v.AddArg(mem) + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [i] {s} ptr w x0:(MOVBstore [i-1] {s} ptr (SRLconst [8] w) x1:(MOVBstore [i-2] {s} ptr (SRLconst [16] w) x2:(MOVBstore [i-3] {s} ptr (SRLconst [24] w) x3:(MOVBstore [i-4] {s} ptr (SRLconst [32] w) x4:(MOVBstore [i-5] {s} ptr (SRLconst [40] w) x5:(MOVBstore [i-6] {s} ptr (SRLconst [48] w) x6:(MOVBstore [i-7] {s} ptr (SRLconst [56] w) mem)))))))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) - // result: (MOVDstore [i-7] {s} ptr (REV w) mem) + // match: (MNEGW (MOVDconst [c]) x) + // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) + // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - w := v.Args[1] - x0 := v.Args[2] - if x0.Op != OpARM64MOVBstore { - break - } - if x0.AuxInt != i-1 { - break - } - if x0.Aux != s { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x0.Args[2] - if ptr != x0.Args[0] { + c := v_0.AuxInt + x := v.Args[1] + if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { break } - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64SRLconst { + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEGW x (MOVDconst [c])) + // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) + // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if x0_1.AuxInt != 8 { + c := v_1.AuxInt + if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { break } - if w != x0_1.Args[0] { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 5) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 2 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + // match: (MNEGW (MOVDconst [c]) x) + // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) + // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - x1 := x0.Args[2] - if x1.Op != OpARM64MOVBstore { + c := v_0.AuxInt + x := v.Args[1] + if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { break } - if x1.AuxInt != i-2 { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 5) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 2 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + // match: (MNEGW x (MOVDconst [c])) + // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) + // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if x1.Aux != s { + c := v_1.AuxInt + if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { break } - _ = x1.Args[2] - if ptr != x1.Args[0] { + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEGW (MOVDconst [c]) x) + // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) + // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64SRLconst { + c := v_0.AuxInt + x := v.Args[1] + if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { break } - if x1_1.AuxInt != 16 { + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEGW x (MOVDconst [c])) + // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) + // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if w != x1_1.Args[0] { + c := v_1.AuxInt + if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { break } - x2 := x1.Args[2] - if x2.Op != OpARM64MOVBstore { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 9) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 3 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + // match: (MNEGW (MOVDconst [c]) x) + // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) + // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x2.AuxInt != i-3 { + c := v_0.AuxInt + x := v.Args[1] + if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { break } - if x2.Aux != s { + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 9) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 3 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + return false +} +func rewriteValueARM64_OpARM64MNEGW_20(v *Value) bool { + // match: (MNEGW (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [-int64(int32(c)*int32(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x2.Args[2] - if ptr != x2.Args[0] { + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64SRLconst { + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = -int64(int32(c) * int32(d)) + return true + } + // match: (MNEGW (MOVDconst [d]) (MOVDconst [c])) + // cond: + // result: (MOVDconst [-int64(int32(c)*int32(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x2_1.AuxInt != 24 { + d := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if w != x2_1.Args[0] { + c := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = -int64(int32(c) * int32(d)) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOD_0(v *Value) bool { + // match: (MOD (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [c%d]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - x3 := x2.Args[2] - if x3.Op != OpARM64MOVBstore { + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if x3.AuxInt != i-4 { + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = c % d + return true + } + return false +} +func rewriteValueARM64_OpARM64MODW_0(v *Value) bool { + // match: (MODW (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [int64(int32(c)%int32(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(int32(c) % int32(d)) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBUload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVBUload [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBUload [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { + break + } + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBUload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBUload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVBUloadidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVBUloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVBUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBUload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBUload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) + // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) + // result: (MOVDconst [0]) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVBstorezero { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + _ = v_1.Args[1] + ptr2 := v_1.Args[0] + if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBUloadidx_0(v *Value) bool { + // match: (MOVBUloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVBUload [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVBUload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBUloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (MOVBUload [c] ptr mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVBUload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBUloadidx ptr idx (MOVBstorezeroidx ptr2 idx2 _)) + // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // result: (MOVDconst [0]) + for { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVBstorezeroidx { + break + } + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBUreg_0(v *Value) bool { + // match: (MOVBUreg x:(MOVBUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBUreg x:(MOVBUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUloadidx { + break + } + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBUreg x:(MOVBUreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUreg { + break + } + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBUreg (ANDconst [c] x)) + // cond: + // result: (ANDconst [c&(1<<8-1)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64ANDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ANDconst) + v.AuxInt = c & (1<<8 - 1) + v.AddArg(x) + return true + } + // match: (MOVBUreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(uint8(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(uint8(c)) + return true + } + // match: (MOVBUreg x) + // cond: x.Type.IsBoolean() + // result: (MOVDreg x) + for { + x := v.Args[0] + if !(x.Type.IsBoolean()) { + break + } + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBUreg (SLLconst [sc] x)) + // cond: isARM64BFMask(sc, 1<<8-1, sc) + // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc))] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { + break + } + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<8-1, sc)) { + break + } + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc)) + v.AddArg(x) + return true + } + // match: (MOVBUreg (SRLconst [sc] x)) + // cond: isARM64BFMask(sc, 1<<8-1, 0) + // result: (UBFX [arm64BFAuxInt(sc, 8)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SRLconst { + break + } + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<8-1, 0)) { + break + } + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc, 8) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVBload [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBload [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { + break + } + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVBloadidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVBloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVBload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) + // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) + // result: (MOVDconst [0]) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVBstorezero { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + _ = v_1.Args[1] + ptr2 := v_1.Args[0] + if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBloadidx_0(v *Value) bool { + // match: (MOVBloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVBload [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVBload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (MOVBload [c] ptr mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVBload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBloadidx ptr idx (MOVBstorezeroidx ptr2 idx2 _)) + // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // result: (MOVDconst [0]) + for { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVBstorezeroidx { + break + } + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBreg_0(v *Value) bool { + // match: (MOVBreg x:(MOVBload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBreg x:(MOVBloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBloadidx { + break + } + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBreg x:(MOVBreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBreg { + break + } + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(int8(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(int8(c)) + return true + } + // match: (MOVBreg (SLLconst [lc] x)) + // cond: lc < 8 + // result: (SBFIZ [arm64BFAuxInt(lc, 8-lc)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { + break + } + lc := v_0.AuxInt + x := v_0.Args[0] + if !(lc < 8) { + break + } + v.reset(OpARM64SBFIZ) + v.AuxInt = arm64BFAuxInt(lc, 8-lc) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBstore_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVBstore [off1] {sym} (ADDconst [off2] ptr) val mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBstore [off1+off2] {sym} ptr val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { + break + } + off2 := v_0.AuxInt + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBstore) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} (ADD ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (MOVBstoreidx ptr idx val mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVBstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBstore) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVDconst [0]) mem) + // cond: + // result: (MOVBstorezero [off] {sym} ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + if v_1.AuxInt != 0 { + break + } + mem := v.Args[2] + v.reset(OpARM64MOVBstorezero) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVBreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVBreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVBUreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVHreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVHreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVHUreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVWreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVWUreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWUreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBstore_10(v *Value) bool { + // match: (MOVBstore [i] {s} ptr0 (SRLconst [8] w) x:(MOVBstore [i-1] {s} ptr1 w mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVHstore [i-1] {s} ptr0 w mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + if v_1.AuxInt != 8 { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstore { + break + } + if x.AuxInt != i-1 { + break + } + if x.Aux != s { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + if w != x.Args[1] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w) + v.AddArg(mem) + return true + } + // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (SRLconst [8] w) x:(MOVBstoreidx ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr1 idx1 w mem) + for { + if v.AuxInt != 1 { + break + } + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + if v_1.AuxInt != 8 { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w) + v.AddArg(mem) + return true + } + // match: (MOVBstore [i] {s} ptr0 (UBFX [arm64BFAuxInt(8, 8)] w) x:(MOVBstore [i-1] {s} ptr1 w mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVHstore [i-1] {s} ptr0 w mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64UBFX { + break + } + if v_1.AuxInt != arm64BFAuxInt(8, 8) { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstore { + break + } + if x.AuxInt != i-1 { + break + } + if x.Aux != s { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + if w != x.Args[1] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w) + v.AddArg(mem) + return true + } + // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (UBFX [arm64BFAuxInt(8, 8)] w) x:(MOVBstoreidx ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr1 idx1 w mem) + for { + if v.AuxInt != 1 { + break + } + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64UBFX { + break + } + if v_1.AuxInt != arm64BFAuxInt(8, 8) { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w) + v.AddArg(mem) + return true + } + // match: (MOVBstore [i] {s} ptr0 (UBFX [arm64BFAuxInt(8, 24)] w) x:(MOVBstore [i-1] {s} ptr1 w mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVHstore [i-1] {s} ptr0 w mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64UBFX { + break + } + if v_1.AuxInt != arm64BFAuxInt(8, 24) { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstore { + break + } + if x.AuxInt != i-1 { + break + } + if x.Aux != s { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + if w != x.Args[1] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w) + v.AddArg(mem) + return true + } + // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (UBFX [arm64BFAuxInt(8, 24)] w) x:(MOVBstoreidx ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr1 idx1 w mem) + for { + if v.AuxInt != 1 { + break + } + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64UBFX { + break + } + if v_1.AuxInt != arm64BFAuxInt(8, 24) { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w) + v.AddArg(mem) + return true + } + // match: (MOVBstore [i] {s} ptr0 (SRLconst [8] (MOVDreg w)) x:(MOVBstore [i-1] {s} ptr1 w mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVHstore [i-1] {s} ptr0 w mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + if v_1.AuxInt != 8 { + break + } + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64MOVDreg { + break + } + w := v_1_0.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstore { + break + } + if x.AuxInt != i-1 { + break + } + if x.Aux != s { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + if w != x.Args[1] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w) + v.AddArg(mem) + return true + } + // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (SRLconst [8] (MOVDreg w)) x:(MOVBstoreidx ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr1 idx1 w mem) + for { + if v.AuxInt != 1 { + break + } + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + if v_1.AuxInt != 8 { + break + } + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64MOVDreg { + break + } + w := v_1_0.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w) + v.AddArg(mem) + return true + } + // match: (MOVBstore [i] {s} ptr0 (SRLconst [j] w) x:(MOVBstore [i-1] {s} ptr1 w0:(SRLconst [j-8] w) mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVHstore [i-1] {s} ptr0 w0 mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstore { + break + } + if x.AuxInt != i-1 { + break + } + if x.Aux != s { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + w0 := x.Args[1] + if w0.Op != OpARM64SRLconst { + break + } + if w0.AuxInt != j-8 { + break + } + if w != w0.Args[0] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (SRLconst [j] w) x:(MOVBstoreidx ptr1 idx1 w0:(SRLconst [j-8] w) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr1 idx1 w0 mem) + for { + if v.AuxInt != 1 { + break + } + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + w0 := x.Args[2] + if w0.Op != OpARM64SRLconst { + break + } + if w0.AuxInt != j-8 { + break + } + if w != w0.Args[0] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w0) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBstore_20(v *Value) bool { + b := v.Block + _ = b + // match: (MOVBstore [i] {s} ptr0 (UBFX [bfc] w) x:(MOVBstore [i-1] {s} ptr1 w0:(UBFX [bfc2] w) mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && getARM64BFwidth(bfc) == 32 - getARM64BFlsb(bfc) && getARM64BFwidth(bfc2) == 32 - getARM64BFlsb(bfc2) && getARM64BFlsb(bfc2) == getARM64BFlsb(bfc) - 8 && clobber(x) + // result: (MOVHstore [i-1] {s} ptr0 w0 mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64UBFX { + break + } + bfc := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstore { + break + } + if x.AuxInt != i-1 { + break + } + if x.Aux != s { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + w0 := x.Args[1] + if w0.Op != OpARM64UBFX { + break + } + bfc2 := w0.AuxInt + if w != w0.Args[0] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && getARM64BFwidth(bfc) == 32-getARM64BFlsb(bfc) && getARM64BFwidth(bfc2) == 32-getARM64BFlsb(bfc2) && getARM64BFlsb(bfc2) == getARM64BFlsb(bfc)-8 && clobber(x)) { + break + } + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (UBFX [bfc] w) x:(MOVBstoreidx ptr1 idx1 w0:(UBFX [bfc2] w) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && getARM64BFwidth(bfc) == 32 - getARM64BFlsb(bfc) && getARM64BFwidth(bfc2) == 32 - getARM64BFlsb(bfc2) && getARM64BFlsb(bfc2) == getARM64BFlsb(bfc) - 8 && clobber(x) + // result: (MOVHstoreidx ptr1 idx1 w0 mem) + for { + if v.AuxInt != 1 { + break + } + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64UBFX { + break + } + bfc := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + w0 := x.Args[2] + if w0.Op != OpARM64UBFX { + break + } + bfc2 := w0.AuxInt + if w != w0.Args[0] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && getARM64BFwidth(bfc) == 32-getARM64BFlsb(bfc) && getARM64BFwidth(bfc2) == 32-getARM64BFlsb(bfc2) && getARM64BFlsb(bfc2) == getARM64BFlsb(bfc)-8 && clobber(x)) { + break + } + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [i] {s} ptr0 (SRLconst [j] (MOVDreg w)) x:(MOVBstore [i-1] {s} ptr1 w0:(SRLconst [j-8] (MOVDreg w)) mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVHstore [i-1] {s} ptr0 w0 mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + j := v_1.AuxInt + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64MOVDreg { + break + } + w := v_1_0.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstore { + break + } + if x.AuxInt != i-1 { + break + } + if x.Aux != s { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + w0 := x.Args[1] + if w0.Op != OpARM64SRLconst { + break + } + if w0.AuxInt != j-8 { + break + } + w0_0 := w0.Args[0] + if w0_0.Op != OpARM64MOVDreg { + break + } + if w != w0_0.Args[0] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [1] {s} (ADD ptr0 idx0) (SRLconst [j] (MOVDreg w)) x:(MOVBstoreidx ptr1 idx1 w0:(SRLconst [j-8] (MOVDreg w)) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr1 idx1 w0 mem) + for { + if v.AuxInt != 1 { + break + } + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + j := v_1.AuxInt + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64MOVDreg { + break + } + w := v_1_0.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + w0 := x.Args[2] + if w0.Op != OpARM64SRLconst { + break + } + if w0.AuxInt != j-8 { + break + } + w0_0 := w0.Args[0] + if w0_0.Op != OpARM64MOVDreg { + break + } + if w != w0_0.Args[0] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [i] {s} ptr w x0:(MOVBstore [i-1] {s} ptr (SRLconst [8] w) x1:(MOVBstore [i-2] {s} ptr (SRLconst [16] w) x2:(MOVBstore [i-3] {s} ptr (SRLconst [24] w) x3:(MOVBstore [i-4] {s} ptr (SRLconst [32] w) x4:(MOVBstore [i-5] {s} ptr (SRLconst [40] w) x5:(MOVBstore [i-6] {s} ptr (SRLconst [48] w) x6:(MOVBstore [i-7] {s} ptr (SRLconst [56] w) mem)))))))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) + // result: (MOVDstore [i-7] {s} ptr (REV w) mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + w := v.Args[1] + x0 := v.Args[2] + if x0.Op != OpARM64MOVBstore { + break + } + if x0.AuxInt != i-1 { + break + } + if x0.Aux != s { + break + } + _ = x0.Args[2] + if ptr != x0.Args[0] { + break + } + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64SRLconst { + break + } + if x0_1.AuxInt != 8 { + break + } + if w != x0_1.Args[0] { + break + } + x1 := x0.Args[2] + if x1.Op != OpARM64MOVBstore { + break + } + if x1.AuxInt != i-2 { + break + } + if x1.Aux != s { + break + } + _ = x1.Args[2] + if ptr != x1.Args[0] { + break + } + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64SRLconst { + break + } + if x1_1.AuxInt != 16 { + break + } + if w != x1_1.Args[0] { + break + } + x2 := x1.Args[2] + if x2.Op != OpARM64MOVBstore { + break + } + if x2.AuxInt != i-3 { + break + } + if x2.Aux != s { + break + } + _ = x2.Args[2] + if ptr != x2.Args[0] { + break + } + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64SRLconst { + break + } + if x2_1.AuxInt != 24 { + break + } + if w != x2_1.Args[0] { + break + } + x3 := x2.Args[2] + if x3.Op != OpARM64MOVBstore { + break + } + if x3.AuxInt != i-4 { + break + } + if x3.Aux != s { + break + } + _ = x3.Args[2] + if ptr != x3.Args[0] { + break + } + x3_1 := x3.Args[1] + if x3_1.Op != OpARM64SRLconst { + break + } + if x3_1.AuxInt != 32 { + break + } + if w != x3_1.Args[0] { + break + } + x4 := x3.Args[2] + if x4.Op != OpARM64MOVBstore { + break + } + if x4.AuxInt != i-5 { + break + } + if x4.Aux != s { + break + } + _ = x4.Args[2] + if ptr != x4.Args[0] { + break + } + x4_1 := x4.Args[1] + if x4_1.Op != OpARM64SRLconst { + break + } + if x4_1.AuxInt != 40 { + break + } + if w != x4_1.Args[0] { + break + } + x5 := x4.Args[2] + if x5.Op != OpARM64MOVBstore { + break + } + if x5.AuxInt != i-6 { + break + } + if x5.Aux != s { + break + } + _ = x5.Args[2] + if ptr != x5.Args[0] { + break + } + x5_1 := x5.Args[1] + if x5_1.Op != OpARM64SRLconst { + break + } + if x5_1.AuxInt != 48 { + break + } + if w != x5_1.Args[0] { + break + } + x6 := x5.Args[2] + if x6.Op != OpARM64MOVBstore { + break + } + if x6.AuxInt != i-7 { + break + } + if x6.Aux != s { + break + } + _ = x6.Args[2] + if ptr != x6.Args[0] { + break + } + x6_1 := x6.Args[1] + if x6_1.Op != OpARM64SRLconst { + break + } + if x6_1.AuxInt != 56 { + break + } + if w != x6_1.Args[0] { + break + } + mem := x6.Args[2] + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6)) { + break + } + v.reset(OpARM64MOVDstore) + v.AuxInt = i - 7 + v.Aux = s + v.AddArg(ptr) + v0 := b.NewValue0(v.Pos, OpARM64REV, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [7] {s} p w x0:(MOVBstore [6] {s} p (SRLconst [8] w) x1:(MOVBstore [5] {s} p (SRLconst [16] w) x2:(MOVBstore [4] {s} p (SRLconst [24] w) x3:(MOVBstore [3] {s} p (SRLconst [32] w) x4:(MOVBstore [2] {s} p (SRLconst [40] w) x5:(MOVBstore [1] {s} p1:(ADD ptr1 idx1) (SRLconst [48] w) x6:(MOVBstoreidx ptr0 idx0 (SRLconst [56] w) mem)))))))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) + // result: (MOVDstoreidx ptr0 idx0 (REV w) mem) + for { + if v.AuxInt != 7 { + break + } + s := v.Aux + _ = v.Args[2] + p := v.Args[0] + w := v.Args[1] + x0 := v.Args[2] + if x0.Op != OpARM64MOVBstore { + break + } + if x0.AuxInt != 6 { + break + } + if x0.Aux != s { + break + } + _ = x0.Args[2] + if p != x0.Args[0] { + break + } + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64SRLconst { + break + } + if x0_1.AuxInt != 8 { + break + } + if w != x0_1.Args[0] { + break + } + x1 := x0.Args[2] + if x1.Op != OpARM64MOVBstore { + break + } + if x1.AuxInt != 5 { + break + } + if x1.Aux != s { + break + } + _ = x1.Args[2] + if p != x1.Args[0] { + break + } + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64SRLconst { + break + } + if x1_1.AuxInt != 16 { + break + } + if w != x1_1.Args[0] { + break + } + x2 := x1.Args[2] + if x2.Op != OpARM64MOVBstore { + break + } + if x2.AuxInt != 4 { + break + } + if x2.Aux != s { + break + } + _ = x2.Args[2] + if p != x2.Args[0] { + break + } + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64SRLconst { + break + } + if x2_1.AuxInt != 24 { + break + } + if w != x2_1.Args[0] { + break + } + x3 := x2.Args[2] + if x3.Op != OpARM64MOVBstore { + break + } + if x3.AuxInt != 3 { + break + } + if x3.Aux != s { + break + } + _ = x3.Args[2] + if p != x3.Args[0] { + break + } + x3_1 := x3.Args[1] + if x3_1.Op != OpARM64SRLconst { + break + } + if x3_1.AuxInt != 32 { + break + } + if w != x3_1.Args[0] { + break + } + x4 := x3.Args[2] + if x4.Op != OpARM64MOVBstore { + break + } + if x4.AuxInt != 2 { + break + } + if x4.Aux != s { + break + } + _ = x4.Args[2] + if p != x4.Args[0] { + break + } + x4_1 := x4.Args[1] + if x4_1.Op != OpARM64SRLconst { + break + } + if x4_1.AuxInt != 40 { + break + } + if w != x4_1.Args[0] { + break + } + x5 := x4.Args[2] + if x5.Op != OpARM64MOVBstore { + break + } + if x5.AuxInt != 1 { + break + } + if x5.Aux != s { + break + } + _ = x5.Args[2] + p1 := x5.Args[0] + if p1.Op != OpARM64ADD { + break + } + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] + x5_1 := x5.Args[1] + if x5_1.Op != OpARM64SRLconst { + break + } + if x5_1.AuxInt != 48 { + break + } + if w != x5_1.Args[0] { + break + } + x6 := x5.Args[2] + if x6.Op != OpARM64MOVBstoreidx { + break + } + _ = x6.Args[3] + ptr0 := x6.Args[0] + idx0 := x6.Args[1] + x6_2 := x6.Args[2] + if x6_2.Op != OpARM64SRLconst { + break + } + if x6_2.AuxInt != 56 { + break + } + if w != x6_2.Args[0] { + break + } + mem := x6.Args[3] + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6)) { + break + } + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr0) + v.AddArg(idx0) + v0 := b.NewValue0(v.Pos, OpARM64REV, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [i] {s} ptr w x0:(MOVBstore [i-1] {s} ptr (UBFX [arm64BFAuxInt(8, 24)] w) x1:(MOVBstore [i-2] {s} ptr (UBFX [arm64BFAuxInt(16, 16)] w) x2:(MOVBstore [i-3] {s} ptr (UBFX [arm64BFAuxInt(24, 8)] w) mem)))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) + // result: (MOVWstore [i-3] {s} ptr (REVW w) mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + w := v.Args[1] + x0 := v.Args[2] + if x0.Op != OpARM64MOVBstore { + break + } + if x0.AuxInt != i-1 { + break + } + if x0.Aux != s { + break + } + _ = x0.Args[2] + if ptr != x0.Args[0] { + break + } + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64UBFX { + break + } + if x0_1.AuxInt != arm64BFAuxInt(8, 24) { + break + } + if w != x0_1.Args[0] { + break + } + x1 := x0.Args[2] + if x1.Op != OpARM64MOVBstore { + break + } + if x1.AuxInt != i-2 { + break + } + if x1.Aux != s { + break + } + _ = x1.Args[2] + if ptr != x1.Args[0] { + break + } + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64UBFX { + break + } + if x1_1.AuxInt != arm64BFAuxInt(16, 16) { + break + } + if w != x1_1.Args[0] { + break + } + x2 := x1.Args[2] + if x2.Op != OpARM64MOVBstore { + break + } + if x2.AuxInt != i-3 { + break + } + if x2.Aux != s { + break + } + _ = x2.Args[2] + if ptr != x2.Args[0] { + break + } + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64UBFX { + break + } + if x2_1.AuxInt != arm64BFAuxInt(24, 8) { + break + } + if w != x2_1.Args[0] { + break + } + mem := x2.Args[2] + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2)) { + break + } + v.reset(OpARM64MOVWstore) + v.AuxInt = i - 3 + v.Aux = s + v.AddArg(ptr) + v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [3] {s} p w x0:(MOVBstore [2] {s} p (UBFX [arm64BFAuxInt(8, 24)] w) x1:(MOVBstore [1] {s} p1:(ADD ptr1 idx1) (UBFX [arm64BFAuxInt(16, 16)] w) x2:(MOVBstoreidx ptr0 idx0 (UBFX [arm64BFAuxInt(24, 8)] w) mem)))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) + // result: (MOVWstoreidx ptr0 idx0 (REVW w) mem) + for { + if v.AuxInt != 3 { + break + } + s := v.Aux + _ = v.Args[2] + p := v.Args[0] + w := v.Args[1] + x0 := v.Args[2] + if x0.Op != OpARM64MOVBstore { + break + } + if x0.AuxInt != 2 { + break + } + if x0.Aux != s { + break + } + _ = x0.Args[2] + if p != x0.Args[0] { + break + } + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64UBFX { + break + } + if x0_1.AuxInt != arm64BFAuxInt(8, 24) { + break + } + if w != x0_1.Args[0] { + break + } + x1 := x0.Args[2] + if x1.Op != OpARM64MOVBstore { + break + } + if x1.AuxInt != 1 { + break + } + if x1.Aux != s { + break + } + _ = x1.Args[2] + p1 := x1.Args[0] + if p1.Op != OpARM64ADD { + break + } + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64UBFX { + break + } + if x1_1.AuxInt != arm64BFAuxInt(16, 16) { + break + } + if w != x1_1.Args[0] { + break + } + x2 := x1.Args[2] + if x2.Op != OpARM64MOVBstoreidx { + break + } + _ = x2.Args[3] + ptr0 := x2.Args[0] + idx0 := x2.Args[1] + x2_2 := x2.Args[2] + if x2_2.Op != OpARM64UBFX { + break + } + if x2_2.AuxInt != arm64BFAuxInt(24, 8) { + break + } + if w != x2_2.Args[0] { + break + } + mem := x2.Args[3] + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2)) { + break + } + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr0) + v.AddArg(idx0) + v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [i] {s} ptr w x0:(MOVBstore [i-1] {s} ptr (SRLconst [8] (MOVDreg w)) x1:(MOVBstore [i-2] {s} ptr (SRLconst [16] (MOVDreg w)) x2:(MOVBstore [i-3] {s} ptr (SRLconst [24] (MOVDreg w)) mem)))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) + // result: (MOVWstore [i-3] {s} ptr (REVW w) mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + w := v.Args[1] + x0 := v.Args[2] + if x0.Op != OpARM64MOVBstore { + break + } + if x0.AuxInt != i-1 { + break + } + if x0.Aux != s { + break + } + _ = x0.Args[2] + if ptr != x0.Args[0] { + break + } + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64SRLconst { + break + } + if x0_1.AuxInt != 8 { + break + } + x0_1_0 := x0_1.Args[0] + if x0_1_0.Op != OpARM64MOVDreg { + break + } + if w != x0_1_0.Args[0] { + break + } + x1 := x0.Args[2] + if x1.Op != OpARM64MOVBstore { break } - if x3.Aux != s { + if x1.AuxInt != i-2 { break } - _ = x3.Args[2] - if ptr != x3.Args[0] { + if x1.Aux != s { break } - x3_1 := x3.Args[1] - if x3_1.Op != OpARM64SRLconst { + _ = x1.Args[2] + if ptr != x1.Args[0] { break } - if x3_1.AuxInt != 32 { + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64SRLconst { break } - if w != x3_1.Args[0] { + if x1_1.AuxInt != 16 { break } - x4 := x3.Args[2] - if x4.Op != OpARM64MOVBstore { + x1_1_0 := x1_1.Args[0] + if x1_1_0.Op != OpARM64MOVDreg { break } - if x4.AuxInt != i-5 { + if w != x1_1_0.Args[0] { break } - if x4.Aux != s { + x2 := x1.Args[2] + if x2.Op != OpARM64MOVBstore { break } - _ = x4.Args[2] - if ptr != x4.Args[0] { + if x2.AuxInt != i-3 { break } - x4_1 := x4.Args[1] - if x4_1.Op != OpARM64SRLconst { + if x2.Aux != s { break } - if x4_1.AuxInt != 40 { + _ = x2.Args[2] + if ptr != x2.Args[0] { break } - if w != x4_1.Args[0] { + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64SRLconst { break } - x5 := x4.Args[2] - if x5.Op != OpARM64MOVBstore { + if x2_1.AuxInt != 24 { break } - if x5.AuxInt != i-6 { + x2_1_0 := x2_1.Args[0] + if x2_1_0.Op != OpARM64MOVDreg { break } - if x5.Aux != s { + if w != x2_1_0.Args[0] { break } - _ = x5.Args[2] - if ptr != x5.Args[0] { + mem := x2.Args[2] + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2)) { break } - x5_1 := x5.Args[1] - if x5_1.Op != OpARM64SRLconst { + v.reset(OpARM64MOVWstore) + v.AuxInt = i - 3 + v.Aux = s + v.AddArg(ptr) + v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [3] {s} p w x0:(MOVBstore [2] {s} p (SRLconst [8] (MOVDreg w)) x1:(MOVBstore [1] {s} p1:(ADD ptr1 idx1) (SRLconst [16] (MOVDreg w)) x2:(MOVBstoreidx ptr0 idx0 (SRLconst [24] (MOVDreg w)) mem)))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) + // result: (MOVWstoreidx ptr0 idx0 (REVW w) mem) + for { + if v.AuxInt != 3 { break } - if x5_1.AuxInt != 48 { + s := v.Aux + _ = v.Args[2] + p := v.Args[0] + w := v.Args[1] + x0 := v.Args[2] + if x0.Op != OpARM64MOVBstore { break } - if w != x5_1.Args[0] { + if x0.AuxInt != 2 { break } - x6 := x5.Args[2] - if x6.Op != OpARM64MOVBstore { + if x0.Aux != s { break } - if x6.AuxInt != i-7 { + _ = x0.Args[2] + if p != x0.Args[0] { break } - if x6.Aux != s { + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64SRLconst { break } - _ = x6.Args[2] - if ptr != x6.Args[0] { + if x0_1.AuxInt != 8 { break } - x6_1 := x6.Args[1] - if x6_1.Op != OpARM64SRLconst { + x0_1_0 := x0_1.Args[0] + if x0_1_0.Op != OpARM64MOVDreg { break } - if x6_1.AuxInt != 56 { + if w != x0_1_0.Args[0] { break } - if w != x6_1.Args[0] { + x1 := x0.Args[2] + if x1.Op != OpARM64MOVBstore { break } - mem := x6.Args[2] - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6)) { + if x1.AuxInt != 1 { break } - v.reset(OpARM64MOVDstore) - v.AuxInt = i - 7 - v.Aux = s - v.AddArg(ptr) - v0 := b.NewValue0(v.Pos, OpARM64REV, w.Type) + if x1.Aux != s { + break + } + _ = x1.Args[2] + p1 := x1.Args[0] + if p1.Op != OpARM64ADD { + break + } + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64SRLconst { + break + } + if x1_1.AuxInt != 16 { + break + } + x1_1_0 := x1_1.Args[0] + if x1_1_0.Op != OpARM64MOVDreg { + break + } + if w != x1_1_0.Args[0] { + break + } + x2 := x1.Args[2] + if x2.Op != OpARM64MOVBstoreidx { + break + } + _ = x2.Args[3] + ptr0 := x2.Args[0] + idx0 := x2.Args[1] + x2_2 := x2.Args[2] + if x2_2.Op != OpARM64SRLconst { + break + } + if x2_2.AuxInt != 24 { + break + } + x2_2_0 := x2_2.Args[0] + if x2_2_0.Op != OpARM64MOVDreg { + break + } + if w != x2_2_0.Args[0] { + break + } + mem := x2.Args[3] + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2)) { + break + } + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr0) + v.AddArg(idx0) + v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) v0.AddArg(w) v.AddArg(v0) v.AddArg(mem) return true } - // match: (MOVBstore [7] {s} p w x0:(MOVBstore [6] {s} p (SRLconst [8] w) x1:(MOVBstore [5] {s} p (SRLconst [16] w) x2:(MOVBstore [4] {s} p (SRLconst [24] w) x3:(MOVBstore [3] {s} p (SRLconst [32] w) x4:(MOVBstore [2] {s} p (SRLconst [40] w) x5:(MOVBstore [1] {s} p1:(ADD ptr1 idx1) (SRLconst [48] w) x6:(MOVBstoreidx ptr0 idx0 (SRLconst [56] w) mem)))))))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) - // result: (MOVDstoreidx ptr0 idx0 (REV w) mem) + return false +} +func rewriteValueARM64_OpARM64MOVBstore_30(v *Value) bool { + b := v.Block + _ = b + // match: (MOVBstore [i] {s} ptr w x0:(MOVBstore [i-1] {s} ptr (SRLconst [8] w) x1:(MOVBstore [i-2] {s} ptr (SRLconst [16] w) x2:(MOVBstore [i-3] {s} ptr (SRLconst [24] w) mem)))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) + // result: (MOVWstore [i-3] {s} ptr (REVW w) mem) for { - if v.AuxInt != 7 { - break - } + i := v.AuxInt s := v.Aux _ = v.Args[2] - p := v.Args[0] + ptr := v.Args[0] w := v.Args[1] x0 := v.Args[2] if x0.Op != OpARM64MOVBstore { break } - if x0.AuxInt != 6 { + if x0.AuxInt != i-1 { break } if x0.Aux != s { break } _ = x0.Args[2] - if p != x0.Args[0] { + if ptr != x0.Args[0] { break } x0_1 := x0.Args[1] @@ -8174,14 +9697,14 @@ func rewriteValueARM64_OpARM64MOVBstore_20(v *Value) bool { if x1.Op != OpARM64MOVBstore { break } - if x1.AuxInt != 5 { + if x1.AuxInt != i-2 { break } if x1.Aux != s { break } _ = x1.Args[2] - if p != x1.Args[0] { + if ptr != x1.Args[0] { break } x1_1 := x1.Args[1] @@ -8198,14 +9721,14 @@ func rewriteValueARM64_OpARM64MOVBstore_20(v *Value) bool { if x2.Op != OpARM64MOVBstore { break } - if x2.AuxInt != 4 { + if x2.AuxInt != i-3 { break } if x2.Aux != s { break } _ = x2.Args[2] - if p != x2.Args[0] { + if ptr != x2.Args[0] { break } x2_1 := x2.Args[1] @@ -8218,870 +9741,1123 @@ func rewriteValueARM64_OpARM64MOVBstore_20(v *Value) bool { if w != x2_1.Args[0] { break } - x3 := x2.Args[2] - if x3.Op != OpARM64MOVBstore { - break - } - if x3.AuxInt != 3 { - break - } - if x3.Aux != s { - break - } - _ = x3.Args[2] - if p != x3.Args[0] { - break - } - x3_1 := x3.Args[1] - if x3_1.Op != OpARM64SRLconst { - break - } - if x3_1.AuxInt != 32 { + mem := x2.Args[2] + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2)) { break } - if w != x3_1.Args[0] { + v.reset(OpARM64MOVWstore) + v.AuxInt = i - 3 + v.Aux = s + v.AddArg(ptr) + v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [3] {s} p w x0:(MOVBstore [2] {s} p (SRLconst [8] w) x1:(MOVBstore [1] {s} p1:(ADD ptr1 idx1) (SRLconst [16] w) x2:(MOVBstoreidx ptr0 idx0 (SRLconst [24] w) mem)))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) + // result: (MOVWstoreidx ptr0 idx0 (REVW w) mem) + for { + if v.AuxInt != 3 { break } - x4 := x3.Args[2] - if x4.Op != OpARM64MOVBstore { + s := v.Aux + _ = v.Args[2] + p := v.Args[0] + w := v.Args[1] + x0 := v.Args[2] + if x0.Op != OpARM64MOVBstore { break } - if x4.AuxInt != 2 { + if x0.AuxInt != 2 { break } - if x4.Aux != s { + if x0.Aux != s { break } - _ = x4.Args[2] - if p != x4.Args[0] { + _ = x0.Args[2] + if p != x0.Args[0] { break } - x4_1 := x4.Args[1] - if x4_1.Op != OpARM64SRLconst { + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64SRLconst { break } - if x4_1.AuxInt != 40 { + if x0_1.AuxInt != 8 { break } - if w != x4_1.Args[0] { + if w != x0_1.Args[0] { break } - x5 := x4.Args[2] - if x5.Op != OpARM64MOVBstore { + x1 := x0.Args[2] + if x1.Op != OpARM64MOVBstore { break } - if x5.AuxInt != 1 { + if x1.AuxInt != 1 { break } - if x5.Aux != s { + if x1.Aux != s { break } - _ = x5.Args[2] - p1 := x5.Args[0] + _ = x1.Args[2] + p1 := x1.Args[0] if p1.Op != OpARM64ADD { break } _ = p1.Args[1] ptr1 := p1.Args[0] idx1 := p1.Args[1] - x5_1 := x5.Args[1] - if x5_1.Op != OpARM64SRLconst { + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64SRLconst { break } - if x5_1.AuxInt != 48 { + if x1_1.AuxInt != 16 { break } - if w != x5_1.Args[0] { + if w != x1_1.Args[0] { break } - x6 := x5.Args[2] - if x6.Op != OpARM64MOVBstoreidx { + x2 := x1.Args[2] + if x2.Op != OpARM64MOVBstoreidx { break } - _ = x6.Args[3] - ptr0 := x6.Args[0] - idx0 := x6.Args[1] - x6_2 := x6.Args[2] - if x6_2.Op != OpARM64SRLconst { + _ = x2.Args[3] + ptr0 := x2.Args[0] + idx0 := x2.Args[1] + x2_2 := x2.Args[2] + if x2_2.Op != OpARM64SRLconst { break } - if x6_2.AuxInt != 56 { + if x2_2.AuxInt != 24 { break } - if w != x6_2.Args[0] { + if w != x2_2.Args[0] { break } - mem := x6.Args[3] - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6)) { + mem := x2.Args[3] + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2)) { break } - v.reset(OpARM64MOVDstoreidx) + v.reset(OpARM64MOVWstoreidx) v.AddArg(ptr0) v.AddArg(idx0) - v0 := b.NewValue0(v.Pos, OpARM64REV, w.Type) + v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) v0.AddArg(w) v.AddArg(v0) v.AddArg(mem) return true } - // match: (MOVBstore [i] {s} ptr w x0:(MOVBstore [i-1] {s} ptr (UBFX [arm64BFAuxInt(8, 24)] w) x1:(MOVBstore [i-2] {s} ptr (UBFX [arm64BFAuxInt(16, 16)] w) x2:(MOVBstore [i-3] {s} ptr (UBFX [arm64BFAuxInt(24, 8)] w) mem)))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) - // result: (MOVWstore [i-3] {s} ptr (REVW w) mem) + // match: (MOVBstore [i] {s} ptr w x:(MOVBstore [i-1] {s} ptr (SRLconst [8] w) mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVHstore [i-1] {s} ptr (REV16W w) mem) for { i := v.AuxInt s := v.Aux _ = v.Args[2] ptr := v.Args[0] w := v.Args[1] - x0 := v.Args[2] - if x0.Op != OpARM64MOVBstore { + x := v.Args[2] + if x.Op != OpARM64MOVBstore { break } - if x0.AuxInt != i-1 { + if x.AuxInt != i-1 { break } - if x0.Aux != s { + if x.Aux != s { break } - _ = x0.Args[2] - if ptr != x0.Args[0] { + _ = x.Args[2] + if ptr != x.Args[0] { break } - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64UBFX { + x_1 := x.Args[1] + if x_1.Op != OpARM64SRLconst { break } - if x0_1.AuxInt != arm64BFAuxInt(8, 24) { + if x_1.AuxInt != 8 { break } - if w != x0_1.Args[0] { + if w != x_1.Args[0] { break } - x1 := x0.Args[2] - if x1.Op != OpARM64MOVBstore { + mem := x.Args[2] + if !(x.Uses == 1 && clobber(x)) { break } - if x1.AuxInt != i-2 { + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 + v.Aux = s + v.AddArg(ptr) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [1] {s} (ADD ptr1 idx1) w x:(MOVBstoreidx ptr0 idx0 (SRLconst [8] w) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr0 idx0 (REV16W w) mem) + for { + if v.AuxInt != 1 { break } - if x1.Aux != s { + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - _ = x1.Args[2] - if ptr != x1.Args[0] { + _ = v_0.Args[1] + ptr1 := v_0.Args[0] + idx1 := v_0.Args[1] + w := v.Args[1] + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { break } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64UBFX { + _ = x.Args[3] + ptr0 := x.Args[0] + idx0 := x.Args[1] + x_2 := x.Args[2] + if x_2.Op != OpARM64SRLconst { break } - if x1_1.AuxInt != arm64BFAuxInt(16, 16) { + if x_2.AuxInt != 8 { break } - if w != x1_1.Args[0] { + if w != x_2.Args[0] { break } - x2 := x1.Args[2] - if x2.Op != OpARM64MOVBstore { + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { break } - if x2.AuxInt != i-3 { + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr0) + v.AddArg(idx0) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [i] {s} ptr w x:(MOVBstore [i-1] {s} ptr (UBFX [arm64BFAuxInt(8, 8)] w) mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVHstore [i-1] {s} ptr (REV16W w) mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + w := v.Args[1] + x := v.Args[2] + if x.Op != OpARM64MOVBstore { break } - if x2.Aux != s { + if x.AuxInt != i-1 { break } - _ = x2.Args[2] - if ptr != x2.Args[0] { + if x.Aux != s { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64UBFX { + _ = x.Args[2] + if ptr != x.Args[0] { break } - if x2_1.AuxInt != arm64BFAuxInt(24, 8) { + x_1 := x.Args[1] + if x_1.Op != OpARM64UBFX { break } - if w != x2_1.Args[0] { + if x_1.AuxInt != arm64BFAuxInt(8, 8) { break } - mem := x2.Args[2] - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2)) { + if w != x_1.Args[0] { break } - v.reset(OpARM64MOVWstore) - v.AuxInt = i - 3 + mem := x.Args[2] + if !(x.Uses == 1 && clobber(x)) { + break + } + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 v.Aux = s v.AddArg(ptr) - v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) v0.AddArg(w) v.AddArg(v0) v.AddArg(mem) return true } - // match: (MOVBstore [3] {s} p w x0:(MOVBstore [2] {s} p (UBFX [arm64BFAuxInt(8, 24)] w) x1:(MOVBstore [1] {s} p1:(ADD ptr1 idx1) (UBFX [arm64BFAuxInt(16, 16)] w) x2:(MOVBstoreidx ptr0 idx0 (UBFX [arm64BFAuxInt(24, 8)] w) mem)))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) - // result: (MOVWstoreidx ptr0 idx0 (REVW w) mem) + // match: (MOVBstore [1] {s} (ADD ptr1 idx1) w x:(MOVBstoreidx ptr0 idx0 (UBFX [arm64BFAuxInt(8, 8)] w) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr0 idx0 (REV16W w) mem) for { - if v.AuxInt != 3 { + if v.AuxInt != 1 { break } s := v.Aux _ = v.Args[2] - p := v.Args[0] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr1 := v_0.Args[0] + idx1 := v_0.Args[1] w := v.Args[1] - x0 := v.Args[2] - if x0.Op != OpARM64MOVBstore { + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { break } - if x0.AuxInt != 2 { + _ = x.Args[3] + ptr0 := x.Args[0] + idx0 := x.Args[1] + x_2 := x.Args[2] + if x_2.Op != OpARM64UBFX { break } - if x0.Aux != s { + if x_2.AuxInt != arm64BFAuxInt(8, 8) { break } - _ = x0.Args[2] - if p != x0.Args[0] { + if w != x_2.Args[0] { break } - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64UBFX { + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { break } - if x0_1.AuxInt != arm64BFAuxInt(8, 24) { + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr0) + v.AddArg(idx0) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [i] {s} ptr w x:(MOVBstore [i-1] {s} ptr (SRLconst [8] (MOVDreg w)) mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVHstore [i-1] {s} ptr (REV16W w) mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + w := v.Args[1] + x := v.Args[2] + if x.Op != OpARM64MOVBstore { break } - if w != x0_1.Args[0] { + if x.AuxInt != i-1 { break } - x1 := x0.Args[2] - if x1.Op != OpARM64MOVBstore { + if x.Aux != s { break } - if x1.AuxInt != 1 { + _ = x.Args[2] + if ptr != x.Args[0] { break } - if x1.Aux != s { + x_1 := x.Args[1] + if x_1.Op != OpARM64SRLconst { break } - _ = x1.Args[2] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + if x_1.AuxInt != 8 { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64UBFX { + x_1_0 := x_1.Args[0] + if x_1_0.Op != OpARM64MOVDreg { + break + } + if w != x_1_0.Args[0] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && clobber(x)) { + break + } + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 + v.Aux = s + v.AddArg(ptr) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [1] {s} (ADD ptr1 idx1) w x:(MOVBstoreidx ptr0 idx0 (SRLconst [8] (MOVDreg w)) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr0 idx0 (REV16W w) mem) + for { + if v.AuxInt != 1 { break } - if x1_1.AuxInt != arm64BFAuxInt(16, 16) { + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - if w != x1_1.Args[0] { + _ = v_0.Args[1] + ptr1 := v_0.Args[0] + idx1 := v_0.Args[1] + w := v.Args[1] + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { break } - x2 := x1.Args[2] - if x2.Op != OpARM64MOVBstoreidx { + _ = x.Args[3] + ptr0 := x.Args[0] + idx0 := x.Args[1] + x_2 := x.Args[2] + if x_2.Op != OpARM64SRLconst { break } - _ = x2.Args[3] - ptr0 := x2.Args[0] - idx0 := x2.Args[1] - x2_2 := x2.Args[2] - if x2_2.Op != OpARM64UBFX { + if x_2.AuxInt != 8 { break } - if x2_2.AuxInt != arm64BFAuxInt(24, 8) { + x_2_0 := x_2.Args[0] + if x_2_0.Op != OpARM64MOVDreg { break } - if w != x2_2.Args[0] { + if w != x_2_0.Args[0] { break } - mem := x2.Args[3] - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2)) { + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { break } - v.reset(OpARM64MOVWstoreidx) + v.reset(OpARM64MOVHstoreidx) v.AddArg(ptr0) v.AddArg(idx0) - v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) v0.AddArg(w) v.AddArg(v0) v.AddArg(mem) return true } - // match: (MOVBstore [i] {s} ptr w x0:(MOVBstore [i-1] {s} ptr (SRLconst [8] (MOVDreg w)) x1:(MOVBstore [i-2] {s} ptr (SRLconst [16] (MOVDreg w)) x2:(MOVBstore [i-3] {s} ptr (SRLconst [24] (MOVDreg w)) mem)))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) - // result: (MOVWstore [i-3] {s} ptr (REVW w) mem) + // match: (MOVBstore [i] {s} ptr w x:(MOVBstore [i-1] {s} ptr (UBFX [arm64BFAuxInt(8, 24)] w) mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVHstore [i-1] {s} ptr (REV16W w) mem) for { i := v.AuxInt s := v.Aux _ = v.Args[2] ptr := v.Args[0] w := v.Args[1] - x0 := v.Args[2] - if x0.Op != OpARM64MOVBstore { - break - } - if x0.AuxInt != i-1 { + x := v.Args[2] + if x.Op != OpARM64MOVBstore { break } - if x0.Aux != s { + if x.AuxInt != i-1 { break } - _ = x0.Args[2] - if ptr != x0.Args[0] { + if x.Aux != s { break } - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64SRLconst { + _ = x.Args[2] + if ptr != x.Args[0] { break } - if x0_1.AuxInt != 8 { + x_1 := x.Args[1] + if x_1.Op != OpARM64UBFX { break } - x0_1_0 := x0_1.Args[0] - if x0_1_0.Op != OpARM64MOVDreg { + if x_1.AuxInt != arm64BFAuxInt(8, 24) { break } - if w != x0_1_0.Args[0] { + if w != x_1.Args[0] { break } - x1 := x0.Args[2] - if x1.Op != OpARM64MOVBstore { + mem := x.Args[2] + if !(x.Uses == 1 && clobber(x)) { break } - if x1.AuxInt != i-2 { + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 + v.Aux = s + v.AddArg(ptr) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + // match: (MOVBstore [1] {s} (ADD ptr1 idx1) w x:(MOVBstoreidx ptr0 idx0 (UBFX [arm64BFAuxInt(8, 24)] w) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr0 idx0 (REV16W w) mem) + for { + if v.AuxInt != 1 { break } - if x1.Aux != s { + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - _ = x1.Args[2] - if ptr != x1.Args[0] { + _ = v_0.Args[1] + ptr1 := v_0.Args[0] + idx1 := v_0.Args[1] + w := v.Args[1] + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { break } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64SRLconst { + _ = x.Args[3] + ptr0 := x.Args[0] + idx0 := x.Args[1] + x_2 := x.Args[2] + if x_2.Op != OpARM64UBFX { break } - if x1_1.AuxInt != 16 { + if x_2.AuxInt != arm64BFAuxInt(8, 24) { break } - x1_1_0 := x1_1.Args[0] - if x1_1_0.Op != OpARM64MOVDreg { + if w != x_2.Args[0] { break } - if w != x1_1_0.Args[0] { + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { break } - x2 := x1.Args[2] - if x2.Op != OpARM64MOVBstore { + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr0) + v.AddArg(idx0) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBstore_40(v *Value) bool { + b := v.Block + _ = b + // match: (MOVBstore [i] {s} ptr w x:(MOVBstore [i-1] {s} ptr (SRLconst [8] (MOVDreg w)) mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVHstore [i-1] {s} ptr (REV16W w) mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + w := v.Args[1] + x := v.Args[2] + if x.Op != OpARM64MOVBstore { break } - if x2.AuxInt != i-3 { + if x.AuxInt != i-1 { break } - if x2.Aux != s { + if x.Aux != s { break } - _ = x2.Args[2] - if ptr != x2.Args[0] { + _ = x.Args[2] + if ptr != x.Args[0] { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64SRLconst { + x_1 := x.Args[1] + if x_1.Op != OpARM64SRLconst { break } - if x2_1.AuxInt != 24 { + if x_1.AuxInt != 8 { break } - x2_1_0 := x2_1.Args[0] - if x2_1_0.Op != OpARM64MOVDreg { + x_1_0 := x_1.Args[0] + if x_1_0.Op != OpARM64MOVDreg { break } - if w != x2_1_0.Args[0] { + if w != x_1_0.Args[0] { break } - mem := x2.Args[2] - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2)) { + mem := x.Args[2] + if !(x.Uses == 1 && clobber(x)) { break } - v.reset(OpARM64MOVWstore) - v.AuxInt = i - 3 + v.reset(OpARM64MOVHstore) + v.AuxInt = i - 1 v.Aux = s v.AddArg(ptr) - v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) v0.AddArg(w) v.AddArg(v0) v.AddArg(mem) return true } - // match: (MOVBstore [3] {s} p w x0:(MOVBstore [2] {s} p (SRLconst [8] (MOVDreg w)) x1:(MOVBstore [1] {s} p1:(ADD ptr1 idx1) (SRLconst [16] (MOVDreg w)) x2:(MOVBstoreidx ptr0 idx0 (SRLconst [24] (MOVDreg w)) mem)))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) - // result: (MOVWstoreidx ptr0 idx0 (REVW w) mem) + // match: (MOVBstore [1] {s} (ADD ptr1 idx1) w x:(MOVBstoreidx ptr0 idx0 (SRLconst [8] (MOVDreg w)) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVHstoreidx ptr0 idx0 (REV16W w) mem) for { - if v.AuxInt != 3 { + if v.AuxInt != 1 { break } s := v.Aux _ = v.Args[2] - p := v.Args[0] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr1 := v_0.Args[0] + idx1 := v_0.Args[1] w := v.Args[1] - x0 := v.Args[2] - if x0.Op != OpARM64MOVBstore { + x := v.Args[2] + if x.Op != OpARM64MOVBstoreidx { break } - if x0.AuxInt != 2 { + _ = x.Args[3] + ptr0 := x.Args[0] + idx0 := x.Args[1] + x_2 := x.Args[2] + if x_2.Op != OpARM64SRLconst { break } - if x0.Aux != s { + if x_2.AuxInt != 8 { break } - _ = x0.Args[2] - if p != x0.Args[0] { + x_2_0 := x_2.Args[0] + if x_2_0.Op != OpARM64MOVDreg { break } - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64SRLconst { + if w != x_2_0.Args[0] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr0) + v.AddArg(idx0) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) + v0.AddArg(w) + v.AddArg(v0) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBstoreidx_0(v *Value) bool { + // match: (MOVBstoreidx ptr (MOVDconst [c]) val mem) + // cond: + // result: (MOVBstore [c] ptr val mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVBstore) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVBstoreidx (MOVDconst [c]) idx val mem) + // cond: + // result: (MOVBstore [c] idx val mem) + for { + _ = v.Args[3] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x0_1.AuxInt != 8 { + c := v_0.AuxInt + idx := v.Args[1] + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVBstore) + v.AuxInt = c + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVBstoreidx ptr idx (MOVDconst [0]) mem) + // cond: + // result: (MOVBstorezeroidx ptr idx mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - x0_1_0 := x0_1.Args[0] - if x0_1_0.Op != OpARM64MOVDreg { + if v_2.AuxInt != 0 { break } - if w != x0_1_0.Args[0] { + mem := v.Args[3] + v.reset(OpARM64MOVBstorezeroidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVBstoreidx ptr idx (MOVBreg x) mem) + // cond: + // result: (MOVBstoreidx ptr idx x mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVBreg { break } - x1 := x0.Args[2] - if x1.Op != OpARM64MOVBstore { + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVBstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstoreidx ptr idx (MOVBUreg x) mem) + // cond: + // result: (MOVBstoreidx ptr idx x mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVBUreg { break } - if x1.AuxInt != 1 { + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVBstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstoreidx ptr idx (MOVHreg x) mem) + // cond: + // result: (MOVBstoreidx ptr idx x mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVHreg { break } - if x1.Aux != s { + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVBstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstoreidx ptr idx (MOVHUreg x) mem) + // cond: + // result: (MOVBstoreidx ptr idx x mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVHUreg { break } - _ = x1.Args[2] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVBstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstoreidx ptr idx (MOVWreg x) mem) + // cond: + // result: (MOVBstoreidx ptr idx x mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWreg { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64SRLconst { + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVBstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstoreidx ptr idx (MOVWUreg x) mem) + // cond: + // result: (MOVBstoreidx ptr idx x mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWUreg { break } - if x1_1.AuxInt != 16 { + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVBstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstoreidx ptr (ADDconst [1] idx) (SRLconst [8] w) x:(MOVBstoreidx ptr idx w mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVHstoreidx ptr idx w mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64ADDconst { break } - x1_1_0 := x1_1.Args[0] - if x1_1_0.Op != OpARM64MOVDreg { + if v_1.AuxInt != 1 { break } - if w != x1_1_0.Args[0] { + idx := v_1.Args[0] + v_2 := v.Args[2] + if v_2.Op != OpARM64SRLconst { break } - x2 := x1.Args[2] - if x2.Op != OpARM64MOVBstoreidx { + if v_2.AuxInt != 8 { break } - _ = x2.Args[3] - ptr0 := x2.Args[0] - idx0 := x2.Args[1] - x2_2 := x2.Args[2] - if x2_2.Op != OpARM64SRLconst { + w := v_2.Args[0] + x := v.Args[3] + if x.Op != OpARM64MOVBstoreidx { break } - if x2_2.AuxInt != 24 { + _ = x.Args[3] + if ptr != x.Args[0] { break } - x2_2_0 := x2_2.Args[0] - if x2_2_0.Op != OpARM64MOVDreg { + if idx != x.Args[1] { break } - if w != x2_2_0.Args[0] { + if w != x.Args[2] { break } - mem := x2.Args[3] - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2)) { + mem := x.Args[3] + if !(x.Uses == 1 && clobber(x)) { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr0) - v.AddArg(idx0) - v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) - v0.AddArg(w) - v.AddArg(v0) + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(w) v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVBstore_30(v *Value) bool { +func rewriteValueARM64_OpARM64MOVBstoreidx_10(v *Value) bool { b := v.Block _ = b - // match: (MOVBstore [i] {s} ptr w x0:(MOVBstore [i-1] {s} ptr (SRLconst [8] w) x1:(MOVBstore [i-2] {s} ptr (SRLconst [16] w) x2:(MOVBstore [i-3] {s} ptr (SRLconst [24] w) mem)))) + // match: (MOVBstoreidx ptr (ADDconst [3] idx) w x0:(MOVBstoreidx ptr (ADDconst [2] idx) (UBFX [arm64BFAuxInt(8, 24)] w) x1:(MOVBstoreidx ptr (ADDconst [1] idx) (UBFX [arm64BFAuxInt(16, 16)] w) x2:(MOVBstoreidx ptr idx (UBFX [arm64BFAuxInt(24, 8)] w) mem)))) // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) - // result: (MOVWstore [i-3] {s} ptr (REVW w) mem) + // result: (MOVWstoreidx ptr idx (REVW w) mem) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] - w := v.Args[1] - x0 := v.Args[2] - if x0.Op != OpARM64MOVBstore { + v_1 := v.Args[1] + if v_1.Op != OpARM64ADDconst { break } - if x0.AuxInt != i-1 { + if v_1.AuxInt != 3 { break } - if x0.Aux != s { + idx := v_1.Args[0] + w := v.Args[2] + x0 := v.Args[3] + if x0.Op != OpARM64MOVBstoreidx { break } - _ = x0.Args[2] + _ = x0.Args[3] if ptr != x0.Args[0] { break } x0_1 := x0.Args[1] - if x0_1.Op != OpARM64SRLconst { + if x0_1.Op != OpARM64ADDconst { break } - if x0_1.AuxInt != 8 { + if x0_1.AuxInt != 2 { break } - if w != x0_1.Args[0] { + if idx != x0_1.Args[0] { break } - x1 := x0.Args[2] - if x1.Op != OpARM64MOVBstore { + x0_2 := x0.Args[2] + if x0_2.Op != OpARM64UBFX { break } - if x1.AuxInt != i-2 { + if x0_2.AuxInt != arm64BFAuxInt(8, 24) { break } - if x1.Aux != s { + if w != x0_2.Args[0] { break } - _ = x1.Args[2] + x1 := x0.Args[3] + if x1.Op != OpARM64MOVBstoreidx { + break + } + _ = x1.Args[3] if ptr != x1.Args[0] { break } x1_1 := x1.Args[1] - if x1_1.Op != OpARM64SRLconst { + if x1_1.Op != OpARM64ADDconst { break } - if x1_1.AuxInt != 16 { + if x1_1.AuxInt != 1 { + break + } + if idx != x1_1.Args[0] { break } - if w != x1_1.Args[0] { + x1_2 := x1.Args[2] + if x1_2.Op != OpARM64UBFX { break } - x2 := x1.Args[2] - if x2.Op != OpARM64MOVBstore { + if x1_2.AuxInt != arm64BFAuxInt(16, 16) { break } - if x2.AuxInt != i-3 { + if w != x1_2.Args[0] { break } - if x2.Aux != s { + x2 := x1.Args[3] + if x2.Op != OpARM64MOVBstoreidx { break } - _ = x2.Args[2] + _ = x2.Args[3] if ptr != x2.Args[0] { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64SRLconst { + if idx != x2.Args[1] { break } - if x2_1.AuxInt != 24 { + x2_2 := x2.Args[2] + if x2_2.Op != OpARM64UBFX { break } - if w != x2_1.Args[0] { + if x2_2.AuxInt != arm64BFAuxInt(24, 8) { break } - mem := x2.Args[2] + if w != x2_2.Args[0] { + break + } + mem := x2.Args[3] if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2)) { break } - v.reset(OpARM64MOVWstore) - v.AuxInt = i - 3 - v.Aux = s + v.reset(OpARM64MOVWstoreidx) v.AddArg(ptr) + v.AddArg(idx) v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) v0.AddArg(w) v.AddArg(v0) v.AddArg(mem) return true } - // match: (MOVBstore [3] {s} p w x0:(MOVBstore [2] {s} p (SRLconst [8] w) x1:(MOVBstore [1] {s} p1:(ADD ptr1 idx1) (SRLconst [16] w) x2:(MOVBstoreidx ptr0 idx0 (SRLconst [24] w) mem)))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) - // result: (MOVWstoreidx ptr0 idx0 (REVW w) mem) + // match: (MOVBstoreidx ptr idx w x0:(MOVBstoreidx ptr (ADDconst [1] idx) (UBFX [arm64BFAuxInt(8, 24)] w) x1:(MOVBstoreidx ptr (ADDconst [2] idx) (UBFX [arm64BFAuxInt(16, 16)] w) x2:(MOVBstoreidx ptr (ADDconst [3] idx) (UBFX [arm64BFAuxInt(24, 8)] w) mem)))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) + // result: (MOVWstoreidx ptr idx w mem) for { - if v.AuxInt != 3 { - break - } - s := v.Aux - _ = v.Args[2] - p := v.Args[0] - w := v.Args[1] - x0 := v.Args[2] - if x0.Op != OpARM64MOVBstore { - break - } - if x0.AuxInt != 2 { - break - } - if x0.Aux != s { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + w := v.Args[2] + x0 := v.Args[3] + if x0.Op != OpARM64MOVBstoreidx { break } - _ = x0.Args[2] - if p != x0.Args[0] { + _ = x0.Args[3] + if ptr != x0.Args[0] { break } x0_1 := x0.Args[1] - if x0_1.Op != OpARM64SRLconst { + if x0_1.Op != OpARM64ADDconst { break } - if x0_1.AuxInt != 8 { + if x0_1.AuxInt != 1 { break } - if w != x0_1.Args[0] { + if idx != x0_1.Args[0] { break } - x1 := x0.Args[2] - if x1.Op != OpARM64MOVBstore { + x0_2 := x0.Args[2] + if x0_2.Op != OpARM64UBFX { break } - if x1.AuxInt != 1 { + if x0_2.AuxInt != arm64BFAuxInt(8, 24) { break } - if x1.Aux != s { + if w != x0_2.Args[0] { break } - _ = x1.Args[2] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + x1 := x0.Args[3] + if x1.Op != OpARM64MOVBstoreidx { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64SRLconst { + _ = x1.Args[3] + if ptr != x1.Args[0] { break } - if x1_1.AuxInt != 16 { + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64ADDconst { break } - if w != x1_1.Args[0] { + if x1_1.AuxInt != 2 { break } - x2 := x1.Args[2] - if x2.Op != OpARM64MOVBstoreidx { + if idx != x1_1.Args[0] { break } - _ = x2.Args[3] - ptr0 := x2.Args[0] - idx0 := x2.Args[1] - x2_2 := x2.Args[2] - if x2_2.Op != OpARM64SRLconst { + x1_2 := x1.Args[2] + if x1_2.Op != OpARM64UBFX { break } - if x2_2.AuxInt != 24 { + if x1_2.AuxInt != arm64BFAuxInt(16, 16) { break } - if w != x2_2.Args[0] { + if w != x1_2.Args[0] { break } - mem := x2.Args[3] - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2)) { + x2 := x1.Args[3] + if x2.Op != OpARM64MOVBstoreidx { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr0) - v.AddArg(idx0) - v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) - v0.AddArg(w) - v.AddArg(v0) - v.AddArg(mem) - return true - } - // match: (MOVBstore [i] {s} ptr w x:(MOVBstore [i-1] {s} ptr (SRLconst [8] w) mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVHstore [i-1] {s} ptr (REV16W w) mem) - for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - w := v.Args[1] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + _ = x2.Args[3] + if ptr != x2.Args[0] { break } - if x.AuxInt != i-1 { + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64ADDconst { break } - if x.Aux != s { + if x2_1.AuxInt != 3 { break } - _ = x.Args[2] - if ptr != x.Args[0] { + if idx != x2_1.Args[0] { break } - x_1 := x.Args[1] - if x_1.Op != OpARM64SRLconst { + x2_2 := x2.Args[2] + if x2_2.Op != OpARM64UBFX { break } - if x_1.AuxInt != 8 { + if x2_2.AuxInt != arm64BFAuxInt(24, 8) { break } - if w != x_1.Args[0] { + if w != x2_2.Args[0] { break } - mem := x.Args[2] - if !(x.Uses == 1 && clobber(x)) { + mem := x2.Args[3] + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2)) { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s + v.reset(OpARM64MOVWstoreidx) v.AddArg(ptr) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) - v0.AddArg(w) - v.AddArg(v0) + v.AddArg(idx) + v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVBstore [1] {s} (ADD ptr1 idx1) w x:(MOVBstoreidx ptr0 idx0 (SRLconst [8] w) mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr0 idx0 (REV16W w) mem) + // match: (MOVBstoreidx ptr (ADDconst [1] idx) w x:(MOVBstoreidx ptr idx (UBFX [arm64BFAuxInt(8, 8)] w) mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVHstoreidx ptr idx (REV16W w) mem) for { - if v.AuxInt != 1 { + _ = v.Args[3] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64ADDconst { break } - s := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + if v_1.AuxInt != 1 { break } - _ = v_0.Args[1] - ptr1 := v_0.Args[0] - idx1 := v_0.Args[1] - w := v.Args[1] - x := v.Args[2] + idx := v_1.Args[0] + w := v.Args[2] + x := v.Args[3] if x.Op != OpARM64MOVBstoreidx { break } _ = x.Args[3] - ptr0 := x.Args[0] - idx0 := x.Args[1] + if ptr != x.Args[0] { + break + } + if idx != x.Args[1] { + break + } x_2 := x.Args[2] - if x_2.Op != OpARM64SRLconst { + if x_2.Op != OpARM64UBFX { break } - if x_2.AuxInt != 8 { + if x_2.AuxInt != arm64BFAuxInt(8, 8) { break } if w != x_2.Args[0] { break } mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + if !(x.Uses == 1 && clobber(x)) { break } v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr0) - v.AddArg(idx0) + v.AddArg(ptr) + v.AddArg(idx) v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) v0.AddArg(w) v.AddArg(v0) v.AddArg(mem) return true } - // match: (MOVBstore [i] {s} ptr w x:(MOVBstore [i-1] {s} ptr (UBFX [arm64BFAuxInt(8, 8)] w) mem)) + // match: (MOVBstoreidx ptr idx w x:(MOVBstoreidx ptr (ADDconst [1] idx) (UBFX [arm64BFAuxInt(8, 8)] w) mem)) // cond: x.Uses == 1 && clobber(x) - // result: (MOVHstore [i-1] {s} ptr (REV16W w) mem) + // result: (MOVHstoreidx ptr idx w mem) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] - w := v.Args[1] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { - break - } - if x.AuxInt != i-1 { - break - } - if x.Aux != s { + idx := v.Args[1] + w := v.Args[2] + x := v.Args[3] + if x.Op != OpARM64MOVBstoreidx { break } - _ = x.Args[2] + _ = x.Args[3] if ptr != x.Args[0] { break } - x_1 := x.Args[1] - if x_1.Op != OpARM64UBFX { - break - } - if x_1.AuxInt != arm64BFAuxInt(8, 8) { - break - } - if w != x_1.Args[0] { - break - } - mem := x.Args[2] - if !(x.Uses == 1 && clobber(x)) { - break - } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s - v.AddArg(ptr) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) - v0.AddArg(w) - v.AddArg(v0) - v.AddArg(mem) - return true - } - // match: (MOVBstore [1] {s} (ADD ptr1 idx1) w x:(MOVBstoreidx ptr0 idx0 (UBFX [arm64BFAuxInt(8, 8)] w) mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr0 idx0 (REV16W w) mem) - for { - if v.AuxInt != 1 { + x_1 := x.Args[1] + if x_1.Op != OpARM64ADDconst { break } - s := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + if x_1.AuxInt != 1 { break } - _ = v_0.Args[1] - ptr1 := v_0.Args[0] - idx1 := v_0.Args[1] - w := v.Args[1] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { + if idx != x_1.Args[0] { break } - _ = x.Args[3] - ptr0 := x.Args[0] - idx0 := x.Args[1] x_2 := x.Args[2] if x_2.Op != OpARM64UBFX { break @@ -9093,871 +10869,1163 @@ func rewriteValueARM64_OpARM64MOVBstore_30(v *Value) bool { break } mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + if !(x.Uses == 1 && clobber(x)) { break } v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr0) - v.AddArg(idx0) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) - v0.AddArg(w) - v.AddArg(v0) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVBstore [i] {s} ptr w x:(MOVBstore [i-1] {s} ptr (SRLconst [8] (MOVDreg w)) mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVHstore [i-1] {s} ptr (REV16W w) mem) + return false +} +func rewriteValueARM64_OpARM64MOVBstorezero_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVBstorezero [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBstorezero [off1+off2] {sym} ptr mem) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - w := v.Args[1] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - if x.AuxInt != i-1 { + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - if x.Aux != s { + v.reset(OpARM64MOVBstorezero) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { break } - _ = x.Args[2] - if ptr != x.Args[0] { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - x_1 := x.Args[1] - if x_1.Op != OpARM64SRLconst { + v.reset(OpARM64MOVBstorezero) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBstorezero [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVBstorezeroidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - if x_1.AuxInt != 8 { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - x_1_0 := x_1.Args[0] - if x_1_0.Op != OpARM64MOVDreg { + v.reset(OpARM64MOVBstorezeroidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVBstorezero [i] {s} ptr0 x:(MOVBstorezero [j] {s} ptr1 mem)) + // cond: x.Uses == 1 && areAdjacentOffsets(i,j,1) && is32Bit(min(i,j)) && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVHstorezero [min(i,j)] {s} ptr0 mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[1] + ptr0 := v.Args[0] + x := v.Args[1] + if x.Op != OpARM64MOVBstorezero { break } - if w != x_1_0.Args[0] { + j := x.AuxInt + if x.Aux != s { break } - mem := x.Args[2] - if !(x.Uses == 1 && clobber(x)) { + _ = x.Args[1] + ptr1 := x.Args[0] + mem := x.Args[1] + if !(x.Uses == 1 && areAdjacentOffsets(i, j, 1) && is32Bit(min(i, j)) && isSamePtr(ptr0, ptr1) && clobber(x)) { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 + v.reset(OpARM64MOVHstorezero) + v.AuxInt = min(i, j) v.Aux = s - v.AddArg(ptr) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) - v0.AddArg(w) - v.AddArg(v0) + v.AddArg(ptr0) v.AddArg(mem) return true } - // match: (MOVBstore [1] {s} (ADD ptr1 idx1) w x:(MOVBstoreidx ptr0 idx0 (SRLconst [8] (MOVDreg w)) mem)) + // match: (MOVBstorezero [1] {s} (ADD ptr0 idx0) x:(MOVBstorezeroidx ptr1 idx1 mem)) // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr0 idx0 (REV16W w) mem) + // result: (MOVHstorezeroidx ptr1 idx1 mem) for { if v.AuxInt != 1 { break } s := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break } _ = v_0.Args[1] - ptr1 := v_0.Args[0] - idx1 := v_0.Args[1] - w := v.Args[1] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { - break - } - _ = x.Args[3] - ptr0 := x.Args[0] - idx0 := x.Args[1] - x_2 := x.Args[2] - if x_2.Op != OpARM64SRLconst { - break - } - if x_2.AuxInt != 8 { + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + x := v.Args[1] + if x.Op != OpARM64MOVBstorezeroidx { break } - x_2_0 := x_2.Args[0] - if x_2_0.Op != OpARM64MOVDreg { + _ = x.Args[2] + ptr1 := x.Args[0] + idx1 := x.Args[1] + mem := x.Args[2] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { break } - if w != x_2_0.Args[0] { + v.reset(OpARM64MOVHstorezeroidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBstorezeroidx_0(v *Value) bool { + // match: (MOVBstorezeroidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVBstorezero [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVBstorezero) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBstorezeroidx (MOVDconst [c]) idx mem) + // cond: + // result: (MOVBstorezero [c] idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr0) - v.AddArg(idx0) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) - v0.AddArg(w) - v.AddArg(v0) + c := v_0.AuxInt + idx := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVBstorezero) + v.AuxInt = c + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVBstore [i] {s} ptr w x:(MOVBstore [i-1] {s} ptr (UBFX [arm64BFAuxInt(8, 24)] w) mem)) + // match: (MOVBstorezeroidx ptr (ADDconst [1] idx) x:(MOVBstorezeroidx ptr idx mem)) // cond: x.Uses == 1 && clobber(x) - // result: (MOVHstore [i-1] {s} ptr (REV16W w) mem) + // result: (MOVHstorezeroidx ptr idx mem) for { - i := v.AuxInt - s := v.Aux _ = v.Args[2] ptr := v.Args[0] - w := v.Args[1] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + v_1 := v.Args[1] + if v_1.Op != OpARM64ADDconst { break } - if x.AuxInt != i-1 { + if v_1.AuxInt != 1 { break } - if x.Aux != s { + idx := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVBstorezeroidx { break } _ = x.Args[2] if ptr != x.Args[0] { break } - x_1 := x.Args[1] - if x_1.Op != OpARM64UBFX { + if idx != x.Args[1] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && clobber(x)) { + break + } + v.reset(OpARM64MOVHstorezeroidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVDload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVDload [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVDload [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - if x_1.AuxInt != arm64BFAuxInt(8, 24) { + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - if w != x_1.Args[0] { + v.reset(OpARM64MOVDload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVDload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVDloadidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - mem := x.Args[2] - if !(x.Uses == 1 && clobber(x)) { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s + v.reset(OpARM64MOVDloadidx) v.AddArg(ptr) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) - v0.AddArg(w) - v.AddArg(v0) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVBstore [1] {s} (ADD ptr1 idx1) w x:(MOVBstoreidx ptr0 idx0 (UBFX [arm64BFAuxInt(8, 24)] w) mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr0 idx0 (REV16W w) mem) + // match: (MOVDload [off] {sym} (ADDshiftLL [3] ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVDloadidx8 ptr idx mem) for { - if v.AuxInt != 1 { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { break } - s := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + if v_0.AuxInt != 3 { break } _ = v_0.Args[1] - ptr1 := v_0.Args[0] - idx1 := v_0.Args[1] - w := v.Args[1] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - _ = x.Args[3] - ptr0 := x.Args[0] - idx0 := x.Args[1] - x_2 := x.Args[2] - if x_2.Op != OpARM64UBFX { + v.reset(OpARM64MOVDloadidx8) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { break } - if x_2.AuxInt != arm64BFAuxInt(8, 24) { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - if w != x_2.Args[0] { + v.reset(OpARM64MOVDload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVDload [off] {sym} ptr (MOVDstorezero [off2] {sym2} ptr2 _)) + // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) + // result: (MOVDconst [0]) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDstorezero { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + off2 := v_1.AuxInt + sym2 := v_1.Aux + _ = v_1.Args[1] + ptr2 := v_1.Args[0] + if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { break } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr0) - v.AddArg(idx0) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) - v0.AddArg(w) - v.AddArg(v0) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } return false } -func rewriteValueARM64_OpARM64MOVBstore_40(v *Value) bool { - b := v.Block - _ = b - // match: (MOVBstore [i] {s} ptr w x:(MOVBstore [i-1] {s} ptr (SRLconst [8] (MOVDreg w)) mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVHstore [i-1] {s} ptr (REV16W w) mem) +func rewriteValueARM64_OpARM64MOVDloadidx_0(v *Value) bool { + // match: (MOVDloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVDload [c] ptr mem) for { - i := v.AuxInt - s := v.Aux _ = v.Args[2] ptr := v.Args[0] - w := v.Args[1] - x := v.Args[2] - if x.Op != OpARM64MOVBstore { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if x.AuxInt != i-1 { + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVDload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVDloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (MOVDload [c] ptr mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x.Aux != s { + c := v_0.AuxInt + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVDload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVDloadidx ptr (SLLconst [3] idx) mem) + // cond: + // result: (MOVDloadidx8 ptr idx mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SLLconst { break } - _ = x.Args[2] - if ptr != x.Args[0] { + if v_1.AuxInt != 3 { break } - x_1 := x.Args[1] - if x_1.Op != OpARM64SRLconst { + idx := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVDloadidx8) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVDloadidx (SLLconst [3] idx) ptr mem) + // cond: + // result: (MOVDloadidx8 ptr idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - if x_1.AuxInt != 8 { + if v_0.AuxInt != 3 { break } - x_1_0 := x_1.Args[0] - if x_1_0.Op != OpARM64MOVDreg { + idx := v_0.Args[0] + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVDloadidx8) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVDloadidx ptr idx (MOVDstorezeroidx ptr2 idx2 _)) + // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // result: (MOVDconst [0]) + for { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDstorezeroidx { break } - if w != x_1_0.Args[0] { + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { break } - mem := x.Args[2] - if !(x.Uses == 1 && clobber(x)) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVDloadidx8_0(v *Value) bool { + // match: (MOVDloadidx8 ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVDload [c<<3] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = i - 1 - v.Aux = s + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVDload) + v.AuxInt = c << 3 v.AddArg(ptr) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) - v0.AddArg(w) - v.AddArg(v0) v.AddArg(mem) return true } - // match: (MOVBstore [1] {s} (ADD ptr1 idx1) w x:(MOVBstoreidx ptr0 idx0 (SRLconst [8] (MOVDreg w)) mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstoreidx ptr0 idx0 (REV16W w) mem) + // match: (MOVDloadidx8 ptr idx (MOVDstorezeroidx8 ptr2 idx2 _)) + // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) + // result: (MOVDconst [0]) for { - if v.AuxInt != 1 { - break - } - s := v.Aux _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr1 := v_0.Args[0] - idx1 := v_0.Args[1] - w := v.Args[1] - x := v.Args[2] - if x.Op != OpARM64MOVBstoreidx { - break - } - _ = x.Args[3] - ptr0 := x.Args[0] - idx0 := x.Args[1] - x_2 := x.Args[2] - if x_2.Op != OpARM64SRLconst { - break - } - if x_2.AuxInt != 8 { + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDstorezeroidx8 { break } - x_2_0 := x_2.Args[0] - if x_2_0.Op != OpARM64MOVDreg { + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { break } - if w != x_2_0.Args[0] { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVDreg_0(v *Value) bool { + // match: (MOVDreg x) + // cond: x.Uses == 1 + // result: (MOVDnop x) + for { + x := v.Args[0] + if !(x.Uses == 1) { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + v.reset(OpARM64MOVDnop) + v.AddArg(x) + return true + } + // match: (MOVDreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [c]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr0) - v.AddArg(idx0) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) - v0.AddArg(w) - v.AddArg(v0) - v.AddArg(mem) + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = c return true } return false } -func rewriteValueARM64_OpARM64MOVBstoreidx_0(v *Value) bool { - // match: (MOVBstoreidx ptr (MOVDconst [c]) val mem) +func rewriteValueARM64_OpARM64MOVDstore_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVDstore ptr (FMOVDfpgp val) mem) // cond: - // result: (MOVBstore [c] ptr val mem) + // result: (FMOVDstore ptr val mem) for { - _ = v.Args[3] + _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64FMOVDfpgp { break } - c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVBstore) - v.AuxInt = c + val := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64FMOVDstore) v.AddArg(ptr) v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVBstoreidx (MOVDconst [c]) idx val mem) - // cond: - // result: (MOVBstore [c] idx val mem) + // match: (MOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVDstore [off1+off2] {sym} ptr val mem) for { - _ = v.Args[3] + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64ADDconst { break } - c := v_0.AuxInt - idx := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVBstore) - v.AuxInt = c - v.AddArg(idx) + off2 := v_0.AuxInt + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVDstore) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr idx (MOVDconst [0]) mem) - // cond: - // result: (MOVBstorezeroidx ptr idx mem) + // match: (MOVDstore [off] {sym} (ADD ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (MOVDstoreidx ptr idx val mem) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDconst { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - if v_2.AuxInt != 0 { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { break } - mem := v.Args[3] - v.reset(OpARM64MOVBstorezeroidx) + v.reset(OpARM64MOVDstoreidx) v.AddArg(ptr) v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr idx (MOVBreg x) mem) - // cond: - // result: (MOVBstoreidx ptr idx x mem) + // match: (MOVDstore [off] {sym} (ADDshiftLL [3] ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (MOVDstoreidx8 ptr idx val mem) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVBreg { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVBstoreidx) + if v_0.AuxInt != 3 { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVDstoreidx8) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(x) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr idx (MOVBUreg x) mem) + // match: (MOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVDstore) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVDstore [off] {sym} ptr (MOVDconst [0]) mem) // cond: - // result: (MOVBstoreidx ptr idx x mem) + // result: (MOVDstorezero [off] {sym} ptr mem) for { - _ = v.Args[3] + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVBUreg { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVBstoreidx) + if v_1.AuxInt != 0 { + break + } + mem := v.Args[2] + v.reset(OpARM64MOVDstorezero) + v.AuxInt = off + v.Aux = sym v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(x) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr idx (MOVHreg x) mem) + return false +} +func rewriteValueARM64_OpARM64MOVDstoreidx_0(v *Value) bool { + // match: (MOVDstoreidx ptr (MOVDconst [c]) val mem) // cond: - // result: (MOVBstoreidx ptr idx x mem) + // result: (MOVDstore [c] ptr val mem) for { _ = v.Args[3] ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVHreg { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x := v_2.Args[0] + c := v_1.AuxInt + val := v.Args[2] mem := v.Args[3] - v.reset(OpARM64MOVBstoreidx) + v.reset(OpARM64MOVDstore) + v.AuxInt = c v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(x) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr idx (MOVHUreg x) mem) + // match: (MOVDstoreidx (MOVDconst [c]) idx val mem) // cond: - // result: (MOVBstoreidx ptr idx x mem) + // result: (MOVDstore [c] idx val mem) for { _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVHUreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - x := v_2.Args[0] + c := v_0.AuxInt + idx := v.Args[1] + val := v.Args[2] mem := v.Args[3] - v.reset(OpARM64MOVBstoreidx) - v.AddArg(ptr) + v.reset(OpARM64MOVDstore) + v.AuxInt = c v.AddArg(idx) - v.AddArg(x) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr idx (MOVWreg x) mem) + // match: (MOVDstoreidx ptr (SLLconst [3] idx) val mem) // cond: - // result: (MOVBstoreidx ptr idx x mem) + // result: (MOVDstoreidx8 ptr idx val mem) for { _ = v.Args[3] ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWreg { + v_1 := v.Args[1] + if v_1.Op != OpARM64SLLconst { break } - x := v_2.Args[0] + if v_1.AuxInt != 3 { + break + } + idx := v_1.Args[0] + val := v.Args[2] mem := v.Args[3] - v.reset(OpARM64MOVBstoreidx) + v.reset(OpARM64MOVDstoreidx8) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(x) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr idx (MOVWUreg x) mem) + // match: (MOVDstoreidx (SLLconst [3] idx) ptr val mem) // cond: - // result: (MOVBstoreidx ptr idx x mem) + // result: (MOVDstoreidx8 ptr idx val mem) for { _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWUreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - x := v_2.Args[0] + if v_0.AuxInt != 3 { + break + } + idx := v_0.Args[0] + ptr := v.Args[1] + val := v.Args[2] mem := v.Args[3] - v.reset(OpARM64MOVBstoreidx) + v.reset(OpARM64MOVDstoreidx8) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(x) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr (ADDconst [1] idx) (SRLconst [8] w) x:(MOVBstoreidx ptr idx w mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVHstoreidx ptr idx w mem) + // match: (MOVDstoreidx ptr idx (MOVDconst [0]) mem) + // cond: + // result: (MOVDstorezeroidx ptr idx mem) for { _ = v.Args[3] ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { - break - } - if v_1.AuxInt != 1 { - break - } - idx := v_1.Args[0] + idx := v.Args[1] v_2 := v.Args[2] - if v_2.Op != OpARM64SRLconst { - break - } - if v_2.AuxInt != 8 { - break - } - w := v_2.Args[0] - x := v.Args[3] - if x.Op != OpARM64MOVBstoreidx { - break - } - _ = x.Args[3] - if ptr != x.Args[0] { - break - } - if idx != x.Args[1] { - break - } - if w != x.Args[2] { + if v_2.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && clobber(x)) { + if v_2.AuxInt != 0 { break } - v.reset(OpARM64MOVHstoreidx) + mem := v.Args[3] + v.reset(OpARM64MOVDstorezeroidx) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(w) v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVBstoreidx_10(v *Value) bool { - b := v.Block - _ = b - // match: (MOVBstoreidx ptr (ADDconst [3] idx) w x0:(MOVBstoreidx ptr (ADDconst [2] idx) (UBFX [arm64BFAuxInt(8, 24)] w) x1:(MOVBstoreidx ptr (ADDconst [1] idx) (UBFX [arm64BFAuxInt(16, 16)] w) x2:(MOVBstoreidx ptr idx (UBFX [arm64BFAuxInt(24, 8)] w) mem)))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) - // result: (MOVWstoreidx ptr idx (REVW w) mem) +func rewriteValueARM64_OpARM64MOVDstoreidx8_0(v *Value) bool { + // match: (MOVDstoreidx8 ptr (MOVDconst [c]) val mem) + // cond: + // result: (MOVDstore [c<<3] ptr val mem) for { _ = v.Args[3] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { - break - } - if v_1.AuxInt != 3 { - break - } - idx := v_1.Args[0] - w := v.Args[2] - x0 := v.Args[3] - if x0.Op != OpARM64MOVBstoreidx { - break - } - _ = x0.Args[3] - if ptr != x0.Args[0] { - break - } - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64ADDconst { - break - } - if x0_1.AuxInt != 2 { - break - } - if idx != x0_1.Args[0] { - break - } - x0_2 := x0.Args[2] - if x0_2.Op != OpARM64UBFX { - break - } - if x0_2.AuxInt != arm64BFAuxInt(8, 24) { - break - } - if w != x0_2.Args[0] { - break - } - x1 := x0.Args[3] - if x1.Op != OpARM64MOVBstoreidx { - break - } - _ = x1.Args[3] - if ptr != x1.Args[0] { - break - } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64ADDconst { - break - } - if x1_1.AuxInt != 1 { - break - } - if idx != x1_1.Args[0] { - break - } - x1_2 := x1.Args[2] - if x1_2.Op != OpARM64UBFX { - break - } - if x1_2.AuxInt != arm64BFAuxInt(16, 16) { - break - } - if w != x1_2.Args[0] { - break - } - x2 := x1.Args[3] - if x2.Op != OpARM64MOVBstoreidx { - break - } - _ = x2.Args[3] - if ptr != x2.Args[0] { - break - } - if idx != x2.Args[1] { - break - } - x2_2 := x2.Args[2] - if x2_2.Op != OpARM64UBFX { - break - } - if x2_2.AuxInt != arm64BFAuxInt(24, 8) { - break - } - if w != x2_2.Args[0] { - break - } - mem := x2.Args[3] - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2)) { + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVWstoreidx) + c := v_1.AuxInt + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVDstore) + v.AuxInt = c << 3 v.AddArg(ptr) - v.AddArg(idx) - v0 := b.NewValue0(v.Pos, OpARM64REVW, w.Type) - v0.AddArg(w) - v.AddArg(v0) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr idx w x0:(MOVBstoreidx ptr (ADDconst [1] idx) (UBFX [arm64BFAuxInt(8, 24)] w) x1:(MOVBstoreidx ptr (ADDconst [2] idx) (UBFX [arm64BFAuxInt(16, 16)] w) x2:(MOVBstoreidx ptr (ADDconst [3] idx) (UBFX [arm64BFAuxInt(24, 8)] w) mem)))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2) - // result: (MOVWstoreidx ptr idx w mem) - for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - w := v.Args[2] - x0 := v.Args[3] - if x0.Op != OpARM64MOVBstoreidx { - break - } - _ = x0.Args[3] - if ptr != x0.Args[0] { - break - } - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64ADDconst { - break - } - if x0_1.AuxInt != 1 { - break - } - if idx != x0_1.Args[0] { - break - } - x0_2 := x0.Args[2] - if x0_2.Op != OpARM64UBFX { - break - } - if x0_2.AuxInt != arm64BFAuxInt(8, 24) { - break - } - if w != x0_2.Args[0] { + // match: (MOVDstoreidx8 ptr idx (MOVDconst [0]) mem) + // cond: + // result: (MOVDstorezeroidx8 ptr idx mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - x1 := x0.Args[3] - if x1.Op != OpARM64MOVBstoreidx { + if v_2.AuxInt != 0 { break } - _ = x1.Args[3] - if ptr != x1.Args[0] { + mem := v.Args[3] + v.reset(OpARM64MOVDstorezeroidx8) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVDstorezero_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVDstorezero [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVDstorezero [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64ADDconst { + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - if x1_1.AuxInt != 2 { + v.reset(OpARM64MOVDstorezero) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVDstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVDstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { break } - if idx != x1_1.Args[0] { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - x1_2 := x1.Args[2] - if x1_2.Op != OpARM64UBFX { + v.reset(OpARM64MOVDstorezero) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVDstorezero [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVDstorezeroidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - if x1_2.AuxInt != arm64BFAuxInt(16, 16) { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - if w != x1_2.Args[0] { + v.reset(OpARM64MOVDstorezeroidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVDstorezero [off] {sym} (ADDshiftLL [3] ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVDstorezeroidx8 ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { break } - x2 := x1.Args[3] - if x2.Op != OpARM64MOVBstoreidx { + if v_0.AuxInt != 3 { break } - _ = x2.Args[3] - if ptr != x2.Args[0] { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64ADDconst { + v.reset(OpARM64MOVDstorezeroidx8) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVDstorezero [i] {s} ptr0 x:(MOVDstorezero [j] {s} ptr1 mem)) + // cond: x.Uses == 1 && areAdjacentOffsets(i,j,8) && is32Bit(min(i,j)) && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVQstorezero [min(i,j)] {s} ptr0 mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[1] + ptr0 := v.Args[0] + x := v.Args[1] + if x.Op != OpARM64MOVDstorezero { break } - if x2_1.AuxInt != 3 { + j := x.AuxInt + if x.Aux != s { break } - if idx != x2_1.Args[0] { + _ = x.Args[1] + ptr1 := x.Args[0] + mem := x.Args[1] + if !(x.Uses == 1 && areAdjacentOffsets(i, j, 8) && is32Bit(min(i, j)) && isSamePtr(ptr0, ptr1) && clobber(x)) { break } - x2_2 := x2.Args[2] - if x2_2.Op != OpARM64UBFX { + v.reset(OpARM64MOVQstorezero) + v.AuxInt = min(i, j) + v.Aux = s + v.AddArg(ptr0) + v.AddArg(mem) + return true + } + // match: (MOVDstorezero [8] {s} p0:(ADD ptr0 idx0) x:(MOVDstorezeroidx ptr1 idx1 mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVQstorezero [0] {s} p0 mem) + for { + if v.AuxInt != 8 { break } - if x2_2.AuxInt != arm64BFAuxInt(24, 8) { + s := v.Aux + _ = v.Args[1] + p0 := v.Args[0] + if p0.Op != OpARM64ADD { break } - if w != x2_2.Args[0] { + _ = p0.Args[1] + ptr0 := p0.Args[0] + idx0 := p0.Args[1] + x := v.Args[1] + if x.Op != OpARM64MOVDstorezeroidx { break } - mem := x2.Args[3] - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && clobber(x0) && clobber(x1) && clobber(x2)) { + _ = x.Args[2] + ptr1 := x.Args[0] + idx1 := x.Args[1] + mem := x.Args[2] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(w) + v.reset(OpARM64MOVQstorezero) + v.AuxInt = 0 + v.Aux = s + v.AddArg(p0) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr (ADDconst [1] idx) w x:(MOVBstoreidx ptr idx (UBFX [arm64BFAuxInt(8, 8)] w) mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVHstoreidx ptr idx (REV16W w) mem) + // match: (MOVDstorezero [8] {s} p0:(ADDshiftLL [3] ptr0 idx0) x:(MOVDstorezeroidx8 ptr1 idx1 mem)) + // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) + // result: (MOVQstorezero [0] {s} p0 mem) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { - break - } - if v_1.AuxInt != 1 { - break - } - idx := v_1.Args[0] - w := v.Args[2] - x := v.Args[3] - if x.Op != OpARM64MOVBstoreidx { + if v.AuxInt != 8 { break } - _ = x.Args[3] - if ptr != x.Args[0] { + s := v.Aux + _ = v.Args[1] + p0 := v.Args[0] + if p0.Op != OpARM64ADDshiftLL { break } - if idx != x.Args[1] { + if p0.AuxInt != 3 { break } - x_2 := x.Args[2] - if x_2.Op != OpARM64UBFX { + _ = p0.Args[1] + ptr0 := p0.Args[0] + idx0 := p0.Args[1] + x := v.Args[1] + if x.Op != OpARM64MOVDstorezeroidx8 { break } - if x_2.AuxInt != arm64BFAuxInt(8, 8) { + _ = x.Args[2] + ptr1 := x.Args[0] + idx1 := x.Args[1] + mem := x.Args[2] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { break } - if w != x_2.Args[0] { + v.reset(OpARM64MOVQstorezero) + v.AuxInt = 0 + v.Aux = s + v.AddArg(p0) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVDstorezeroidx_0(v *Value) bool { + // match: (MOVDstorezeroidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVDstorezero [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && clobber(x)) { + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVDstorezero) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVDstorezeroidx (MOVDconst [c]) idx mem) + // cond: + // result: (MOVDstorezero [c] idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr) + c := v_0.AuxInt + idx := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVDstorezero) + v.AuxInt = c v.AddArg(idx) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, w.Type) - v0.AddArg(w) - v.AddArg(v0) v.AddArg(mem) return true } - // match: (MOVBstoreidx ptr idx w x:(MOVBstoreidx ptr (ADDconst [1] idx) (UBFX [arm64BFAuxInt(8, 8)] w) mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVHstoreidx ptr idx w mem) + // match: (MOVDstorezeroidx ptr (SLLconst [3] idx) mem) + // cond: + // result: (MOVDstorezeroidx8 ptr idx mem) for { - _ = v.Args[3] + _ = v.Args[2] ptr := v.Args[0] - idx := v.Args[1] - w := v.Args[2] - x := v.Args[3] - if x.Op != OpARM64MOVBstoreidx { - break - } - _ = x.Args[3] - if ptr != x.Args[0] { - break - } - x_1 := x.Args[1] - if x_1.Op != OpARM64ADDconst { - break - } - if x_1.AuxInt != 1 { - break - } - if idx != x_1.Args[0] { + v_1 := v.Args[1] + if v_1.Op != OpARM64SLLconst { break } - x_2 := x.Args[2] - if x_2.Op != OpARM64UBFX { + if v_1.AuxInt != 3 { break } - if x_2.AuxInt != arm64BFAuxInt(8, 8) { + idx := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVDstorezeroidx8) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVDstorezeroidx (SLLconst [3] idx) ptr mem) + // cond: + // result: (MOVDstorezeroidx8 ptr idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - if w != x_2.Args[0] { + if v_0.AuxInt != 3 { break } - mem := x.Args[3] - if !(x.Uses == 1 && clobber(x)) { + idx := v_0.Args[0] + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVDstorezeroidx8) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVDstorezeroidx8_0(v *Value) bool { + // match: (MOVDstorezeroidx8 ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVDstorezero [c<<3] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVHstoreidx) + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVDstorezero) + v.AuxInt = c << 3 v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(w) v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVBstorezero_0(v *Value) bool { +func rewriteValueARM64_OpARM64MOVHUload_0(v *Value) bool { b := v.Block _ = b config := b.Func.Config _ = config - // match: (MOVBstorezero [off1] {sym} (ADDconst [off2] ptr) mem) + // match: (MOVHUload [off1] {sym} (ADDconst [off2] ptr) mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBstorezero [off1+off2] {sym} ptr mem) + // result: (MOVHUload [off1+off2] {sym} ptr mem) for { off1 := v.AuxInt sym := v.Aux @@ -9972,16 +12040,67 @@ func rewriteValueARM64_OpARM64MOVBstorezero_0(v *Value) bool { if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVBstorezero) + v.reset(OpARM64MOVHUload) v.AuxInt = off1 + off2 v.Aux = sym v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVBstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // match: (MOVHUload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVHUloadidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVHUloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVHUload [off] {sym} (ADDshiftLL [1] ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVHUloadidx2 ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { + break + } + if v_0.AuxInt != 1 { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVHUloadidx2) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVHUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // result: (MOVHUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) for { off1 := v.AuxInt sym1 := v.Aux @@ -9997,183 +12116,372 @@ func rewriteValueARM64_OpARM64MOVBstorezero_0(v *Value) bool { if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVBstorezero) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) + v.reset(OpARM64MOVHUload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVHUload [off] {sym} ptr (MOVHstorezero [off2] {sym2} ptr2 _)) + // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) + // result: (MOVDconst [0]) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVHstorezero { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + _ = v_1.Args[1] + ptr2 := v_1.Args[0] + if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVHUloadidx_0(v *Value) bool { + // match: (MOVHUloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVHUload [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVHUload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVHUloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (MOVHUload [c] ptr mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVHUload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVHUloadidx ptr (SLLconst [1] idx) mem) + // cond: + // result: (MOVHUloadidx2 ptr idx mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SLLconst { + break + } + if v_1.AuxInt != 1 { + break + } + idx := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVHUloadidx2) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVHUloadidx ptr (ADD idx idx) mem) + // cond: + // result: (MOVHUloadidx2 ptr idx mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64ADD { + break + } + _ = v_1.Args[1] + idx := v_1.Args[0] + if idx != v_1.Args[1] { + break + } + mem := v.Args[2] + v.reset(OpARM64MOVHUloadidx2) v.AddArg(ptr) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVBstorezero [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVBstorezeroidx ptr idx mem) + // match: (MOVHUloadidx (ADD idx idx) ptr mem) + // cond: + // result: (MOVHUloadidx2 ptr idx mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break } _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + idx := v_0.Args[0] + if idx != v_0.Args[1] { break } - v.reset(OpARM64MOVBstorezeroidx) + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVHUloadidx2) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVBstorezero [i] {s} ptr0 x:(MOVBstorezero [j] {s} ptr1 mem)) - // cond: x.Uses == 1 && areAdjacentOffsets(i,j,1) && is32Bit(min(i,j)) && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVHstorezero [min(i,j)] {s} ptr0 mem) + // match: (MOVHUloadidx ptr idx (MOVHstorezeroidx ptr2 idx2 _)) + // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // result: (MOVDconst [0]) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[1] - ptr0 := v.Args[0] - x := v.Args[1] - if x.Op != OpARM64MOVBstorezero { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVHstorezeroidx { break } - j := x.AuxInt - if x.Aux != s { + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { break } - _ = x.Args[1] - ptr1 := x.Args[0] - mem := x.Args[1] - if !(x.Uses == 1 && areAdjacentOffsets(i, j, 1) && is32Bit(min(i, j)) && isSamePtr(ptr0, ptr1) && clobber(x)) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVHUloadidx2_0(v *Value) bool { + // match: (MOVHUloadidx2 ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVHUload [c<<1] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVHstorezero) - v.AuxInt = min(i, j) - v.Aux = s - v.AddArg(ptr0) + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVHUload) + v.AuxInt = c << 1 + v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVBstorezero [1] {s} (ADD ptr0 idx0) x:(MOVBstorezeroidx ptr1 idx1 mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVHstorezeroidx ptr1 idx1 mem) + // match: (MOVHUloadidx2 ptr idx (MOVHstorezeroidx2 ptr2 idx2 _)) + // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) + // result: (MOVDconst [0]) for { - if v.AuxInt != 1 { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVHstorezeroidx2 { break } - s := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - x := v.Args[1] - if x.Op != OpARM64MOVBstorezeroidx { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVHUreg_0(v *Value) bool { + // match: (MOVHUreg x:(MOVBUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVHUreg x:(MOVHUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVHUreg x:(MOVBUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUloadidx { break } _ = x.Args[2] - ptr1 := x.Args[0] - idx1 := x.Args[1] - mem := x.Args[2] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVHUreg x:(MOVHUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUloadidx { break } - v.reset(OpARM64MOVHstorezeroidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(mem) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64MOVBstorezeroidx_0(v *Value) bool { - // match: (MOVBstorezeroidx ptr (MOVDconst [c]) mem) + // match: (MOVHUreg x:(MOVHUloadidx2 _ _ _)) // cond: - // result: (MOVBstorezero [c] ptr mem) + // result: (MOVDreg x) for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + x := v.Args[0] + if x.Op != OpARM64MOVHUloadidx2 { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVBstorezero) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVBstorezeroidx (MOVDconst [c]) idx mem) + // match: (MOVHUreg x:(MOVBUreg _)) // cond: - // result: (MOVBstorezero [c] idx mem) + // result: (MOVDreg x) for { - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + x := v.Args[0] + if x.Op != OpARM64MOVBUreg { break } - c := v_0.AuxInt - idx := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVBstorezero) - v.AuxInt = c - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVBstorezeroidx ptr (ADDconst [1] idx) x:(MOVBstorezeroidx ptr idx mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVHstorezeroidx ptr idx mem) + // match: (MOVHUreg x:(MOVHUreg _)) + // cond: + // result: (MOVDreg x) for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { + x := v.Args[0] + if x.Op != OpARM64MOVHUreg { break } - if v_1.AuxInt != 1 { + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVHUreg (ANDconst [c] x)) + // cond: + // result: (ANDconst [c&(1<<16-1)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64ANDconst { break } - idx := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVBstorezeroidx { + c := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ANDconst) + v.AuxInt = c & (1<<16 - 1) + v.AddArg(x) + return true + } + // match: (MOVHUreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(uint16(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - if ptr != x.Args[0] { + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(uint16(c)) + return true + } + // match: (MOVHUreg (SLLconst [sc] x)) + // cond: isARM64BFMask(sc, 1<<16-1, sc) + // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(1<<16-1, sc))] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { + break + } + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<16-1, sc)) { break } - if idx != x.Args[1] { + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<16-1, sc)) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVHUreg_10(v *Value) bool { + // match: (MOVHUreg (SRLconst [sc] x)) + // cond: isARM64BFMask(sc, 1<<16-1, 0) + // result: (UBFX [arm64BFAuxInt(sc, 16)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SRLconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && clobber(x)) { + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<16-1, 0)) { break } - v.reset(OpARM64MOVHstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc, 16) + v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64MOVDload_0(v *Value) bool { +func rewriteValueARM64_OpARM64MOVHload_0(v *Value) bool { b := v.Block _ = b config := b.Func.Config _ = config - // match: (MOVDload [off1] {sym} (ADDconst [off2] ptr) mem) + // match: (MOVHload [off1] {sym} (ADDconst [off2] ptr) mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVDload [off1+off2] {sym} ptr mem) + // result: (MOVHload [off1+off2] {sym} ptr mem) for { off1 := v.AuxInt sym := v.Aux @@ -10188,16 +12496,16 @@ func rewriteValueARM64_OpARM64MOVDload_0(v *Value) bool { if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVDload) + v.reset(OpARM64MOVHload) v.AuxInt = off1 + off2 v.Aux = sym v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVDload [off] {sym} (ADD ptr idx) mem) + // match: (MOVHload [off] {sym} (ADD ptr idx) mem) // cond: off == 0 && sym == nil - // result: (MOVDloadidx ptr idx mem) + // result: (MOVHloadidx ptr idx mem) for { off := v.AuxInt sym := v.Aux @@ -10213,15 +12521,15 @@ func rewriteValueARM64_OpARM64MOVDload_0(v *Value) bool { if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVDloadidx) + v.reset(OpARM64MOVHloadidx) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVDload [off] {sym} (ADDshiftLL [3] ptr idx) mem) + // match: (MOVHload [off] {sym} (ADDshiftLL [1] ptr idx) mem) // cond: off == 0 && sym == nil - // result: (MOVDloadidx8 ptr idx mem) + // result: (MOVHloadidx2 ptr idx mem) for { off := v.AuxInt sym := v.Aux @@ -10230,7 +12538,7 @@ func rewriteValueARM64_OpARM64MOVDload_0(v *Value) bool { if v_0.Op != OpARM64ADDshiftLL { break } - if v_0.AuxInt != 3 { + if v_0.AuxInt != 1 { break } _ = v_0.Args[1] @@ -10240,15 +12548,15 @@ func rewriteValueARM64_OpARM64MOVDload_0(v *Value) bool { if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVDloadidx8) + v.reset(OpARM64MOVHloadidx2) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVDload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // match: (MOVHload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVDload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // result: (MOVHload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) for { off1 := v.AuxInt sym1 := v.Aux @@ -10264,14 +12572,14 @@ func rewriteValueARM64_OpARM64MOVDload_0(v *Value) bool { if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVDload) + v.reset(OpARM64MOVHload) v.AuxInt = off1 + off2 v.Aux = mergeSym(sym1, sym2) v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVDload [off] {sym} ptr (MOVDstorezero [off2] {sym2} ptr2 _)) + // match: (MOVHload [off] {sym} ptr (MOVHstorezero [off2] {sym2} ptr2 _)) // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) // result: (MOVDconst [0]) for { @@ -10280,7 +12588,7 @@ func rewriteValueARM64_OpARM64MOVDload_0(v *Value) bool { _ = v.Args[1] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDstorezero { + if v_1.Op != OpARM64MOVHstorezero { break } off2 := v_1.AuxInt @@ -10296,10 +12604,10 @@ func rewriteValueARM64_OpARM64MOVDload_0(v *Value) bool { } return false } -func rewriteValueARM64_OpARM64MOVDloadidx_0(v *Value) bool { - // match: (MOVDloadidx ptr (MOVDconst [c]) mem) +func rewriteValueARM64_OpARM64MOVHloadidx_0(v *Value) bool { + // match: (MOVHloadidx ptr (MOVDconst [c]) mem) // cond: - // result: (MOVDload [c] ptr mem) + // result: (MOVHload [c] ptr mem) for { _ = v.Args[2] ptr := v.Args[0] @@ -10309,15 +12617,15 @@ func rewriteValueARM64_OpARM64MOVDloadidx_0(v *Value) bool { } c := v_1.AuxInt mem := v.Args[2] - v.reset(OpARM64MOVDload) + v.reset(OpARM64MOVHload) v.AuxInt = c v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVDloadidx (MOVDconst [c]) ptr mem) + // match: (MOVHloadidx (MOVDconst [c]) ptr mem) // cond: - // result: (MOVDload [c] ptr mem) + // result: (MOVHload [c] ptr mem) for { _ = v.Args[2] v_0 := v.Args[0] @@ -10327,15 +12635,15 @@ func rewriteValueARM64_OpARM64MOVDloadidx_0(v *Value) bool { c := v_0.AuxInt ptr := v.Args[1] mem := v.Args[2] - v.reset(OpARM64MOVDload) + v.reset(OpARM64MOVHload) v.AuxInt = c v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVDloadidx ptr (SLLconst [3] idx) mem) + // match: (MOVHloadidx ptr (SLLconst [1] idx) mem) // cond: - // result: (MOVDloadidx8 ptr idx mem) + // result: (MOVHloadidx2 ptr idx mem) for { _ = v.Args[2] ptr := v.Args[0] @@ -10343,477 +12651,383 @@ func rewriteValueARM64_OpARM64MOVDloadidx_0(v *Value) bool { if v_1.Op != OpARM64SLLconst { break } - if v_1.AuxInt != 3 { + if v_1.AuxInt != 1 { break } idx := v_1.Args[0] mem := v.Args[2] - v.reset(OpARM64MOVDloadidx8) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVDloadidx (SLLconst [3] idx) ptr mem) - // cond: - // result: (MOVDloadidx8 ptr idx mem) - for { - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { - break - } - if v_0.AuxInt != 3 { - break - } - idx := v_0.Args[0] - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVDloadidx8) + v.reset(OpARM64MOVHloadidx2) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVDloadidx ptr idx (MOVDstorezeroidx ptr2 idx2 _)) - // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) - // result: (MOVDconst [0]) - for { - _ = v.Args[2] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDstorezeroidx { - break - } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { - break - } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVDloadidx8_0(v *Value) bool { - // match: (MOVDloadidx8 ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVDload [c<<3] ptr mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVDload) - v.AuxInt = c << 3 - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVDloadidx8 ptr idx (MOVDstorezeroidx8 ptr2 idx2 _)) - // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) - // result: (MOVDconst [0]) - for { - _ = v.Args[2] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDstorezeroidx8 { - break - } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { - break - } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVDreg_0(v *Value) bool { - // match: (MOVDreg x) - // cond: x.Uses == 1 - // result: (MOVDnop x) - for { - x := v.Args[0] - if !(x.Uses == 1) { - break - } - v.reset(OpARM64MOVDnop) - v.AddArg(x) - return true - } - // match: (MOVDreg (MOVDconst [c])) - // cond: - // result: (MOVDconst [c]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - c := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = c - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVDstore_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVDstore ptr (FMOVDfpgp val) mem) + // match: (MOVHloadidx ptr (ADD idx idx) mem) // cond: - // result: (FMOVDstore ptr val mem) + // result: (MOVHloadidx2 ptr idx mem) for { _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64FMOVDfpgp { - break - } - val := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64FMOVDstore) - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) - return true - } - // match: (MOVDstore [off1] {sym} (ADDconst [off2] ptr) val mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVDstore [off1+off2] {sym} ptr val mem) - for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { - break - } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_1.Op != OpARM64ADD { break } - v.reset(OpARM64MOVDstore) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) - return true - } - // match: (MOVDstore [off] {sym} (ADD ptr idx) val mem) - // cond: off == 0 && sym == nil - // result: (MOVDstoreidx ptr idx val mem) - for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + _ = v_1.Args[1] + idx := v_1.Args[0] + if idx != v_1.Args[1] { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - val := v.Args[1] mem := v.Args[2] - if !(off == 0 && sym == nil) { - break - } - v.reset(OpARM64MOVDstoreidx) + v.reset(OpARM64MOVHloadidx2) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVDstore [off] {sym} (ADDshiftLL [3] ptr idx) val mem) - // cond: off == 0 && sym == nil - // result: (MOVDstoreidx8 ptr idx val mem) + // match: (MOVHloadidx (ADD idx idx) ptr mem) + // cond: + // result: (MOVHloadidx2 ptr idx mem) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { - break - } - if v_0.AuxInt != 3 { + if v_0.Op != OpARM64ADD { break } _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - val := v.Args[1] - mem := v.Args[2] - if !(off == 0 && sym == nil) { + idx := v_0.Args[0] + if idx != v_0.Args[1] { break } - v.reset(OpARM64MOVDstoreidx8) + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVHloadidx2) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVDstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVDstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + // match: (MOVHloadidx ptr idx (MOVHstorezeroidx ptr2 idx2 _)) + // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // result: (MOVDconst [0]) for { - off1 := v.AuxInt - sym1 := v.Aux _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVHstorezeroidx { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { break } - v.reset(OpARM64MOVDstore) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVDstore [off] {sym} ptr (MOVDconst [0]) mem) + return false +} +func rewriteValueARM64_OpARM64MOVHloadidx2_0(v *Value) bool { + // match: (MOVHloadidx2 ptr (MOVDconst [c]) mem) // cond: - // result: (MOVDstorezero [off] {sym} ptr mem) + // result: (MOVHload [c<<1] ptr mem) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 0 { - break - } + c := v_1.AuxInt mem := v.Args[2] - v.reset(OpARM64MOVDstorezero) - v.AuxInt = off - v.Aux = sym + v.reset(OpARM64MOVHload) + v.AuxInt = c << 1 v.AddArg(ptr) v.AddArg(mem) return true } + // match: (MOVHloadidx2 ptr idx (MOVHstorezeroidx2 ptr2 idx2 _)) + // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) + // result: (MOVDconst [0]) + for { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVHstorezeroidx2 { + break + } + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } return false } -func rewriteValueARM64_OpARM64MOVDstoreidx_0(v *Value) bool { - // match: (MOVDstoreidx ptr (MOVDconst [c]) val mem) +func rewriteValueARM64_OpARM64MOVHreg_0(v *Value) bool { + // match: (MOVHreg x:(MOVBload _ _)) // cond: - // result: (MOVDstore [c] ptr val mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + x := v.Args[0] + if x.Op != OpARM64MOVBload { break } - c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVDstore) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVDstoreidx (MOVDconst [c]) idx val mem) + // match: (MOVHreg x:(MOVBUload _ _)) // cond: - // result: (MOVDstore [c] idx val mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + x := v.Args[0] + if x.Op != OpARM64MOVBUload { break } - c := v_0.AuxInt - idx := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVDstore) - v.AuxInt = c - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVDstoreidx ptr (SLLconst [3] idx) val mem) + // match: (MOVHreg x:(MOVHload _ _)) // cond: - // result: (MOVDstoreidx8 ptr idx val mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SLLconst { + x := v.Args[0] + if x.Op != OpARM64MOVHload { break } - if v_1.AuxInt != 3 { + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVHreg x:(MOVBloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBloadidx { break } - idx := v_1.Args[0] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVDstoreidx8) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVDstoreidx (SLLconst [3] idx) ptr val mem) + // match: (MOVHreg x:(MOVBUloadidx _ _ _)) // cond: - // result: (MOVDstoreidx8 ptr idx val mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + x := v.Args[0] + if x.Op != OpARM64MOVBUloadidx { break } - if v_0.AuxInt != 3 { + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVHreg x:(MOVHloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHloadidx { break } - idx := v_0.Args[0] - ptr := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVDstoreidx8) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVDstoreidx ptr idx (MOVDconst [0]) mem) + // match: (MOVHreg x:(MOVHloadidx2 _ _ _)) // cond: - // result: (MOVDstorezeroidx ptr idx mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDconst { + x := v.Args[0] + if x.Op != OpARM64MOVHloadidx2 { break } - if v_2.AuxInt != 0 { + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVHreg x:(MOVBreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBreg { + break + } + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVHreg x:(MOVBUreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUreg { + break + } + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVHreg x:(MOVHreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHreg { break } - mem := v.Args[3] - v.reset(OpARM64MOVDstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64MOVDstoreidx8_0(v *Value) bool { - // match: (MOVDstoreidx8 ptr (MOVDconst [c]) val mem) +func rewriteValueARM64_OpARM64MOVHreg_10(v *Value) bool { + // match: (MOVHreg (MOVDconst [c])) // cond: - // result: (MOVDstore [c<<3] ptr val mem) + // result: (MOVDconst [int64(int16(c))]) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVDstore) - v.AuxInt = c << 3 - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(int16(c)) return true } - // match: (MOVDstoreidx8 ptr idx (MOVDconst [0]) mem) - // cond: - // result: (MOVDstorezeroidx8 ptr idx mem) + // match: (MOVHreg (SLLconst [lc] x)) + // cond: lc < 16 + // result: (SBFIZ [arm64BFAuxInt(lc, 16-lc)] x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - if v_2.AuxInt != 0 { + lc := v_0.AuxInt + x := v_0.Args[0] + if !(lc < 16) { break } - mem := v.Args[3] - v.reset(OpARM64MOVDstorezeroidx8) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64SBFIZ) + v.AuxInt = arm64BFAuxInt(lc, 16-lc) + v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64MOVDstorezero_0(v *Value) bool { +func rewriteValueARM64_OpARM64MOVHstore_0(v *Value) bool { b := v.Block _ = b config := b.Func.Config _ = config - // match: (MOVDstorezero [off1] {sym} (ADDconst [off2] ptr) mem) + // match: (MOVHstore [off1] {sym} (ADDconst [off2] ptr) val mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVDstorezero [off1+off2] {sym} ptr mem) + // result: (MOVHstore [off1+off2] {sym} ptr val mem) for { off1 := v.AuxInt sym := v.Aux - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADDconst { break } off2 := v_0.AuxInt ptr := v_0.Args[0] - mem := v.Args[1] + val := v.Args[1] + mem := v.Args[2] if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVDstorezero) + v.reset(OpARM64MOVHstore) v.AuxInt = off1 + off2 v.Aux = sym v.AddArg(ptr) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVDstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // match: (MOVHstore [off] {sym} (ADD ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (MOVHstoreidx ptr idx val mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVHstore [off] {sym} (ADDshiftLL [1] ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (MOVHstoreidx2 ptr idx val mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { + break + } + if v_0.AuxInt != 1 { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVHstoreidx2) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVHstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVDstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // result: (MOVHstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) for { off1 := v.AuxInt sym1 := v.Aux - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDaddr { break @@ -10821,332 +13035,371 @@ func rewriteValueARM64_OpARM64MOVDstorezero_0(v *Value) bool { off2 := v_0.AuxInt sym2 := v_0.Aux ptr := v_0.Args[0] - mem := v.Args[1] + val := v.Args[1] + mem := v.Args[2] if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVDstorezero) + v.reset(OpARM64MOVHstore) v.AuxInt = off1 + off2 v.Aux = mergeSym(sym1, sym2) v.AddArg(ptr) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVDstorezero [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVDstorezeroidx ptr idx mem) + // match: (MOVHstore [off] {sym} ptr (MOVDconst [0]) mem) + // cond: + // result: (MOVHstorezero [off] {sym} ptr mem) for { off := v.AuxInt sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + if v_1.AuxInt != 0 { break } - v.reset(OpARM64MOVDstorezeroidx) + mem := v.Args[2] + v.reset(OpARM64MOVHstorezero) + v.AuxInt = off + v.Aux = sym v.AddArg(ptr) - v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVDstorezero [off] {sym} (ADDshiftLL [3] ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVDstorezeroidx8 ptr idx mem) + // match: (MOVHstore [off] {sym} ptr (MOVHreg x) mem) + // cond: + // result: (MOVHstore [off] {sym} ptr x mem) for { off := v.AuxInt sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVHreg { break } - if v_0.AuxInt != 3 { + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVHstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVHstore [off] {sym} ptr (MOVHUreg x) mem) + // cond: + // result: (MOVHstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVHUreg { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVHstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVHstore [off] {sym} ptr (MOVWreg x) mem) + // cond: + // result: (MOVHstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWreg { break } - v.reset(OpARM64MOVDstorezeroidx8) + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVHstore) + v.AuxInt = off + v.Aux = sym v.AddArg(ptr) - v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVHstore [off] {sym} ptr (MOVWUreg x) mem) + // cond: + // result: (MOVHstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWUreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVHstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) v.AddArg(mem) return true } - // match: (MOVDstorezero [i] {s} ptr0 x:(MOVDstorezero [j] {s} ptr1 mem)) - // cond: x.Uses == 1 && areAdjacentOffsets(i,j,8) && is32Bit(min(i,j)) && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVQstorezero [min(i,j)] {s} ptr0 mem) + // match: (MOVHstore [i] {s} ptr0 (SRLconst [16] w) x:(MOVHstore [i-2] {s} ptr1 w mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVWstore [i-2] {s} ptr0 w mem) for { i := v.AuxInt s := v.Aux - _ = v.Args[1] + _ = v.Args[2] ptr0 := v.Args[0] - x := v.Args[1] - if x.Op != OpARM64MOVDstorezero { + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + if v_1.AuxInt != 16 { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstore { + break + } + if x.AuxInt != i-2 { break } - j := x.AuxInt if x.Aux != s { break } - _ = x.Args[1] + _ = x.Args[2] ptr1 := x.Args[0] - mem := x.Args[1] - if !(x.Uses == 1 && areAdjacentOffsets(i, j, 8) && is32Bit(min(i, j)) && isSamePtr(ptr0, ptr1) && clobber(x)) { + if w != x.Args[1] { break } - v.reset(OpARM64MOVQstorezero) - v.AuxInt = min(i, j) + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVWstore) + v.AuxInt = i - 2 v.Aux = s v.AddArg(ptr0) + v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVDstorezero [8] {s} p0:(ADD ptr0 idx0) x:(MOVDstorezeroidx ptr1 idx1 mem)) + return false +} +func rewriteValueARM64_OpARM64MOVHstore_10(v *Value) bool { + b := v.Block + _ = b + // match: (MOVHstore [2] {s} (ADD ptr0 idx0) (SRLconst [16] w) x:(MOVHstoreidx ptr1 idx1 w mem)) // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVQstorezero [0] {s} p0 mem) + // result: (MOVWstoreidx ptr1 idx1 w mem) for { - if v.AuxInt != 8 { + if v.AuxInt != 2 { break } s := v.Aux - _ = v.Args[1] - p0 := v.Args[0] - if p0.Op != OpARM64ADD { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - _ = p0.Args[1] - ptr0 := p0.Args[0] - idx0 := p0.Args[1] - x := v.Args[1] - if x.Op != OpARM64MOVDstorezeroidx { + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - _ = x.Args[2] + if v_1.AuxInt != 16 { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstoreidx { + break + } + _ = x.Args[3] ptr1 := x.Args[0] idx1 := x.Args[1] - mem := x.Args[2] + if w != x.Args[2] { + break + } + mem := x.Args[3] if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { break } - v.reset(OpARM64MOVQstorezero) - v.AuxInt = 0 - v.Aux = s - v.AddArg(p0) + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVDstorezero [8] {s} p0:(ADDshiftLL [3] ptr0 idx0) x:(MOVDstorezeroidx8 ptr1 idx1 mem)) + // match: (MOVHstore [2] {s} (ADDshiftLL [1] ptr0 idx0) (SRLconst [16] w) x:(MOVHstoreidx2 ptr1 idx1 w mem)) // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVQstorezero [0] {s} p0 mem) + // result: (MOVWstoreidx ptr1 (SLLconst [1] idx1) w mem) for { - if v.AuxInt != 8 { + if v.AuxInt != 2 { break } s := v.Aux - _ = v.Args[1] - p0 := v.Args[0] - if p0.Op != OpARM64ADDshiftLL { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { break } - if p0.AuxInt != 3 { + if v_0.AuxInt != 1 { break } - _ = p0.Args[1] - ptr0 := p0.Args[0] - idx0 := p0.Args[1] - x := v.Args[1] - if x.Op != OpARM64MOVDstorezeroidx8 { + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - _ = x.Args[2] - ptr1 := x.Args[0] - idx1 := x.Args[1] - mem := x.Args[2] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + if v_1.AuxInt != 16 { break } - v.reset(OpARM64MOVQstorezero) - v.AuxInt = 0 - v.Aux = s - v.AddArg(p0) - v.AddArg(mem) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVDstorezeroidx_0(v *Value) bool { - // match: (MOVDstorezeroidx ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVDstorezero [c] ptr mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstoreidx2 { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVDstorezero) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVDstorezeroidx (MOVDconst [c]) idx mem) - // cond: - // result: (MOVDstorezero [c] idx mem) - for { - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { break } - c := v_0.AuxInt - idx := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVDstorezero) - v.AuxInt = c - v.AddArg(idx) + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + break + } + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr1) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) + v0.AuxInt = 1 + v0.AddArg(idx1) + v.AddArg(v0) + v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVDstorezeroidx ptr (SLLconst [3] idx) mem) - // cond: - // result: (MOVDstorezeroidx8 ptr idx mem) + // match: (MOVHstore [i] {s} ptr0 (UBFX [arm64BFAuxInt(16, 16)] w) x:(MOVHstore [i-2] {s} ptr1 w mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVWstore [i-2] {s} ptr0 w mem) for { + i := v.AuxInt + s := v.Aux _ = v.Args[2] - ptr := v.Args[0] + ptr0 := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SLLconst { + if v_1.Op != OpARM64UBFX { break } - if v_1.AuxInt != 3 { + if v_1.AuxInt != arm64BFAuxInt(16, 16) { break } - idx := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVDstorezeroidx8) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVDstorezeroidx (SLLconst [3] idx) ptr mem) - // cond: - // result: (MOVDstorezeroidx8 ptr idx mem) - for { - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstore { break } - if v_0.AuxInt != 3 { + if x.AuxInt != i-2 { break } - idx := v_0.Args[0] - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVDstorezeroidx8) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVDstorezeroidx8_0(v *Value) bool { - // match: (MOVDstorezeroidx8 ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVDstorezero [c<<3] ptr mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if x.Aux != s { break - } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVDstorezero) - v.AuxInt = c << 3 - v.AddArg(ptr) - v.AddArg(mem) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVHUload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVHUload [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVHUload [off1+off2] {sym} ptr mem) - for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + } + _ = x.Args[2] + ptr1 := x.Args[0] + if w != x.Args[1] { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { break } - v.reset(OpARM64MOVHUload) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) + v.reset(OpARM64MOVWstore) + v.AuxInt = i - 2 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVHUload [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVHUloadidx ptr idx mem) + // match: (MOVHstore [2] {s} (ADD ptr0 idx0) (UBFX [arm64BFAuxInt(16, 16)] w) x:(MOVHstoreidx ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVWstoreidx ptr1 idx1 w mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + if v.AuxInt != 2 { + break + } + s := v.Aux + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break } _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64UBFX { break } - v.reset(OpARM64MOVHUloadidx) - v.AddArg(ptr) - v.AddArg(idx) + if v_1.AuxInt != arm64BFAuxInt(16, 16) { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVHUload [off] {sym} (ADDshiftLL [1] ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVHUloadidx2 ptr idx mem) + // match: (MOVHstore [2] {s} (ADDshiftLL [1] ptr0 idx0) (UBFX [arm64BFAuxInt(16, 16)] w) x:(MOVHstoreidx2 ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) + // result: (MOVWstoreidx ptr1 (SLLconst [1] idx1) w mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + if v.AuxInt != 2 { + break + } + s := v.Aux + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADDshiftLL { break @@ -11155,454 +13408,303 @@ func rewriteValueARM64_OpARM64MOVHUload_0(v *Value) bool { break } _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64UBFX { break } - v.reset(OpARM64MOVHUloadidx2) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVHUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVHUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) - for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + if v_1.AuxInt != arm64BFAuxInt(16, 16) { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstoreidx2 { break } - v.reset(OpARM64MOVHUload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVHUload [off] {sym} ptr (MOVHstorezero [off2] {sym2} ptr2 _)) - // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) - // result: (MOVDconst [0]) - for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVHstorezero { + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { break } - off2 := v_1.AuxInt - sym2 := v_1.Aux - _ = v_1.Args[1] - ptr2 := v_1.Args[0] - if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr1) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) + v0.AuxInt = 1 + v0.AddArg(idx1) + v.AddArg(v0) + v.AddArg(w) + v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVHUloadidx_0(v *Value) bool { - // match: (MOVHUloadidx ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVHUload [c] ptr mem) + // match: (MOVHstore [i] {s} ptr0 (SRLconst [16] (MOVDreg w)) x:(MOVHstore [i-2] {s} ptr1 w mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVWstore [i-2] {s} ptr0 w mem) for { + i := v.AuxInt + s := v.Aux _ = v.Args[2] - ptr := v.Args[0] + ptr0 := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64SRLconst { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVHUload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVHUloadidx (MOVDconst [c]) ptr mem) - // cond: - // result: (MOVHUload [c] ptr mem) - for { - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_1.AuxInt != 16 { break } - c := v_0.AuxInt - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVHUload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVHUloadidx ptr (SLLconst [1] idx) mem) - // cond: - // result: (MOVHUloadidx2 ptr idx mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SLLconst { + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64MOVDreg { break } - if v_1.AuxInt != 1 { + w := v_1_0.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstore { break } - idx := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVHUloadidx2) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVHUloadidx ptr (ADD idx idx) mem) - // cond: - // result: (MOVHUloadidx2 ptr idx mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADD { + if x.AuxInt != i-2 { break } - _ = v_1.Args[1] - idx := v_1.Args[0] - if idx != v_1.Args[1] { + if x.Aux != s { break } - mem := v.Args[2] - v.reset(OpARM64MOVHUloadidx2) - v.AddArg(ptr) - v.AddArg(idx) + _ = x.Args[2] + ptr1 := x.Args[0] + if w != x.Args[1] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVWstore) + v.AuxInt = i - 2 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVHUloadidx (ADD idx idx) ptr mem) - // cond: - // result: (MOVHUloadidx2 ptr idx mem) + // match: (MOVHstore [2] {s} (ADD ptr0 idx0) (SRLconst [16] (MOVDreg w)) x:(MOVHstoreidx ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVWstoreidx ptr1 idx1 w mem) for { + if v.AuxInt != 2 { + break + } + s := v.Aux _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break } - _ = v_0.Args[1] - idx := v_0.Args[0] - if idx != v_0.Args[1] { + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + if v_1.AuxInt != 16 { break } - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVHUloadidx2) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVHUloadidx ptr idx (MOVHstorezeroidx ptr2 idx2 _)) - // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) - // result: (MOVDconst [0]) - for { - _ = v.Args[2] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVHstorezeroidx { + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64MOVDreg { break } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + w := v_1_0.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstoreidx { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVHUloadidx2_0(v *Value) bool { - // match: (MOVHUloadidx2 ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVHUload [c<<1] ptr mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVHUload) - v.AuxInt = c << 1 - v.AddArg(ptr) + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVHUloadidx2 ptr idx (MOVHstorezeroidx2 ptr2 idx2 _)) - // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) - // result: (MOVDconst [0]) + // match: (MOVHstore [2] {s} (ADDshiftLL [1] ptr0 idx0) (SRLconst [16] (MOVDreg w)) x:(MOVHstoreidx2 ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) + // result: (MOVWstoreidx ptr1 (SLLconst [1] idx1) w mem) for { - _ = v.Args[2] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVHstorezeroidx2 { + if v.AuxInt != 2 { break } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVHUreg_0(v *Value) bool { - // match: (MOVHUreg x:(MOVBUload _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBUload { + if v_0.AuxInt != 1 { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVHUreg x:(MOVHUload _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHUload { + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVHUreg x:(MOVBUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBUloadidx { + if v_1.AuxInt != 16 { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVHUreg x:(MOVHUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHUloadidx { + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64MOVDreg { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVHUreg x:(MOVHUloadidx2 _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHUloadidx2 { + w := v_1_0.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstoreidx2 { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVHUreg x:(MOVBUreg _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBUreg { + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVHUreg x:(MOVHUreg _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHUreg { + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr1) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) + v0.AuxInt = 1 + v0.AddArg(idx1) + v.AddArg(v0) + v.AddArg(w) + v.AddArg(mem) return true } - // match: (MOVHUreg (ANDconst [c] x)) - // cond: - // result: (ANDconst [c&(1<<16-1)] x) + // match: (MOVHstore [i] {s} ptr0 (SRLconst [j] w) x:(MOVHstore [i-2] {s} ptr1 w0:(SRLconst [j-16] w) mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVWstore [i-2] {s} ptr0 w0 mem) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64ANDconst { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - c := v_0.AuxInt - x := v_0.Args[0] - v.reset(OpARM64ANDconst) - v.AuxInt = c & (1<<16 - 1) - v.AddArg(x) - return true - } - // match: (MOVHUreg (MOVDconst [c])) - // cond: - // result: (MOVDconst [int64(uint16(c))]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstore { break } - c := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(uint16(c)) - return true - } - // match: (MOVHUreg (SLLconst [sc] x)) - // cond: isARM64BFMask(sc, 1<<16-1, sc) - // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(1<<16-1, sc))] x) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if x.AuxInt != i-2 { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<16-1, sc)) { + if x.Aux != s { break } - v.reset(OpARM64UBFIZ) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<16-1, sc)) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVHUreg_10(v *Value) bool { - // match: (MOVHUreg (SRLconst [sc] x)) - // cond: isARM64BFMask(sc, 1<<16-1, 0) - // result: (UBFX [arm64BFAuxInt(sc, 16)] x) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { + _ = x.Args[2] + ptr1 := x.Args[0] + w0 := x.Args[1] + if w0.Op != OpARM64SRLconst { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<16-1, 0)) { + if w0.AuxInt != j-16 { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc, 16) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVHload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVHload [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVHload [off1+off2] {sym} ptr mem) - for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + if w != w0.Args[0] { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { break } - v.reset(OpARM64MOVHload) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) + v.reset(OpARM64MOVWstore) + v.AuxInt = i - 2 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w0) v.AddArg(mem) return true } - // match: (MOVHload [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVHloadidx ptr idx mem) + // match: (MOVHstore [2] {s} (ADD ptr0 idx0) (SRLconst [j] w) x:(MOVHstoreidx ptr1 idx1 w0:(SRLconst [j-16] w) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVWstoreidx ptr1 idx1 w0 mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + if v.AuxInt != 2 { + break + } + s := v.Aux + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break } _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVHloadidx) - v.AddArg(ptr) - v.AddArg(idx) + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + w0 := x.Args[2] + if w0.Op != OpARM64SRLconst { + break + } + if w0.AuxInt != j-16 { + break + } + if w != w0.Args[0] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w0) v.AddArg(mem) return true } - // match: (MOVHload [off] {sym} (ADDshiftLL [1] ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVHloadidx2 ptr idx mem) + return false +} +func rewriteValueARM64_OpARM64MOVHstore_20(v *Value) bool { + b := v.Block + _ = b + // match: (MOVHstore [2] {s} (ADDshiftLL [1] ptr0 idx0) (SRLconst [j] w) x:(MOVHstoreidx2 ptr1 idx1 w0:(SRLconst [j-16] w) mem)) + // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) + // result: (MOVWstoreidx ptr1 (SLLconst [1] idx1) w0 mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + if v.AuxInt != 2 { + break + } + s := v.Aux + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADDshiftLL { break @@ -11611,110 +13713,93 @@ func rewriteValueARM64_OpARM64MOVHload_0(v *Value) bool { break } _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVHloadidx2) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVHload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVHload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) - for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstoreidx2 { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + w0 := x.Args[2] + if w0.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVHload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVHload [off] {sym} ptr (MOVHstorezero [off2] {sym2} ptr2 _)) - // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) - // result: (MOVDconst [0]) - for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVHstorezero { + if w0.AuxInt != j-16 { break } - off2 := v_1.AuxInt - sym2 := v_1.Aux - _ = v_1.Args[1] - ptr2 := v_1.Args[0] - if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + if w != w0.Args[0] { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + break + } + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr1) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) + v0.AuxInt = 1 + v0.AddArg(idx1) + v.AddArg(v0) + v.AddArg(w0) + v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVHloadidx_0(v *Value) bool { - // match: (MOVHloadidx ptr (MOVDconst [c]) mem) +func rewriteValueARM64_OpARM64MOVHstoreidx_0(v *Value) bool { + // match: (MOVHstoreidx ptr (MOVDconst [c]) val mem) // cond: - // result: (MOVHload [c] ptr mem) + // result: (MOVHstore [c] ptr val mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVHload) + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVHstore) v.AuxInt = c v.AddArg(ptr) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHloadidx (MOVDconst [c]) ptr mem) + // match: (MOVHstoreidx (MOVDconst [c]) idx val mem) // cond: - // result: (MOVHload [c] ptr mem) + // result: (MOVHstore [c] idx val mem) for { - _ = v.Args[2] + _ = v.Args[3] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVHload) + idx := v.Args[1] + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVHstore) v.AuxInt = c - v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHloadidx ptr (SLLconst [1] idx) mem) + // match: (MOVHstoreidx ptr (SLLconst [1] idx) val mem) // cond: - // result: (MOVHloadidx2 ptr idx mem) + // result: (MOVHstoreidx2 ptr idx val mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64SLLconst { @@ -11724,18 +13809,20 @@ func rewriteValueARM64_OpARM64MOVHloadidx_0(v *Value) bool { break } idx := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVHloadidx2) + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx2) v.AddArg(ptr) v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHloadidx ptr (ADD idx idx) mem) + // match: (MOVHstoreidx ptr (ADD idx idx) val mem) // cond: - // result: (MOVHloadidx2 ptr idx mem) + // result: (MOVHstoreidx2 ptr idx val mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64ADD { @@ -11746,18 +13833,43 @@ func rewriteValueARM64_OpARM64MOVHloadidx_0(v *Value) bool { if idx != v_1.Args[1] { break } - mem := v.Args[2] - v.reset(OpARM64MOVHloadidx2) + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx2) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVHstoreidx (SLLconst [1] idx) ptr val mem) + // cond: + // result: (MOVHstoreidx2 ptr idx val mem) + for { + _ = v.Args[3] + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { + break + } + if v_0.AuxInt != 1 { + break + } + idx := v_0.Args[0] + ptr := v.Args[1] + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx2) v.AddArg(ptr) v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHloadidx (ADD idx idx) ptr mem) + // match: (MOVHstoreidx (ADD idx idx) ptr val mem) // cond: - // result: (MOVHloadidx2 ptr idx mem) + // result: (MOVHstoreidx2 ptr idx val mem) for { - _ = v.Args[2] + _ = v.Args[3] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break @@ -11768,280 +13880,353 @@ func rewriteValueARM64_OpARM64MOVHloadidx_0(v *Value) bool { break } ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVHloadidx2) + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx2) v.AddArg(ptr) v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHloadidx ptr idx (MOVHstorezeroidx ptr2 idx2 _)) - // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) - // result: (MOVDconst [0]) + // match: (MOVHstoreidx ptr idx (MOVDconst [0]) mem) + // cond: + // result: (MOVHstorezeroidx ptr idx mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] idx := v.Args[1] v_2 := v.Args[2] - if v_2.Op != OpARM64MOVHstorezeroidx { + if v_2.Op != OpARM64MOVDconst { break } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + if v_2.AuxInt != 0 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + mem := v.Args[3] + v.reset(OpARM64MOVHstorezeroidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVHloadidx2_0(v *Value) bool { - // match: (MOVHloadidx2 ptr (MOVDconst [c]) mem) + // match: (MOVHstoreidx ptr idx (MOVHreg x) mem) // cond: - // result: (MOVHload [c<<1] ptr mem) + // result: (MOVHstoreidx ptr idx x mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVHreg { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVHload) - v.AuxInt = c << 1 + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx) v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) v.AddArg(mem) return true } - // match: (MOVHloadidx2 ptr idx (MOVHstorezeroidx2 ptr2 idx2 _)) - // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) - // result: (MOVDconst [0]) + // match: (MOVHstoreidx ptr idx (MOVHUreg x) mem) + // cond: + // result: (MOVHstoreidx ptr idx x mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] idx := v.Args[1] v_2 := v.Args[2] - if v_2.Op != OpARM64MOVHstorezeroidx2 { - break - } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { + if v_2.Op != OpARM64MOVHUreg { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVHreg_0(v *Value) bool { - // match: (MOVHreg x:(MOVBload _ _)) + // match: (MOVHstoreidx ptr idx (MOVWreg x) mem) // cond: - // result: (MOVDreg x) + // result: (MOVHstoreidx ptr idx x mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVBload { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWreg { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(x) + v.AddArg(mem) return true } - // match: (MOVHreg x:(MOVBUload _ _)) + return false +} +func rewriteValueARM64_OpARM64MOVHstoreidx_10(v *Value) bool { + // match: (MOVHstoreidx ptr idx (MOVWUreg x) mem) // cond: - // result: (MOVDreg x) + // result: (MOVHstoreidx ptr idx x mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVBUload { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWUreg { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(x) + v.AddArg(mem) return true } - // match: (MOVHreg x:(MOVHload _ _)) - // cond: - // result: (MOVDreg x) + // match: (MOVHstoreidx ptr (ADDconst [2] idx) (SRLconst [16] w) x:(MOVHstoreidx ptr idx w mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVWstoreidx ptr idx w mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVHload { + _ = v.Args[3] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64ADDconst { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVHreg x:(MOVBloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBloadidx { + if v_1.AuxInt != 2 { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVHreg x:(MOVBUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBUloadidx { + idx := v_1.Args[0] + v_2 := v.Args[2] + if v_2.Op != OpARM64SRLconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVHreg x:(MOVHloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHloadidx { + if v_2.AuxInt != 16 { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + w := v_2.Args[0] + x := v.Args[3] + if x.Op != OpARM64MOVHstoreidx { + break + } + _ = x.Args[3] + if ptr != x.Args[0] { + break + } + if idx != x.Args[1] { + break + } + if w != x.Args[2] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && clobber(x)) { + break + } + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(w) + v.AddArg(mem) return true } - // match: (MOVHreg x:(MOVHloadidx2 _ _ _)) + return false +} +func rewriteValueARM64_OpARM64MOVHstoreidx2_0(v *Value) bool { + // match: (MOVHstoreidx2 ptr (MOVDconst [c]) val mem) // cond: - // result: (MOVDreg x) + // result: (MOVHstore [c<<1] ptr val mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVHloadidx2 { + _ = v.Args[3] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_1.AuxInt + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVHstore) + v.AuxInt = c << 1 + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) return true } - // match: (MOVHreg x:(MOVBreg _)) + // match: (MOVHstoreidx2 ptr idx (MOVDconst [0]) mem) // cond: - // result: (MOVDreg x) + // result: (MOVHstorezeroidx2 ptr idx mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVBreg { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) + if v_2.AuxInt != 0 { + break + } + mem := v.Args[3] + v.reset(OpARM64MOVHstorezeroidx2) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) return true } - // match: (MOVHreg x:(MOVBUreg _)) + // match: (MOVHstoreidx2 ptr idx (MOVHreg x) mem) // cond: - // result: (MOVDreg x) + // result: (MOVHstoreidx2 ptr idx x mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVBUreg { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVHreg { break } - v.reset(OpARM64MOVDreg) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx2) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(x) + v.AddArg(mem) return true } - // match: (MOVHreg x:(MOVHreg _)) + // match: (MOVHstoreidx2 ptr idx (MOVHUreg x) mem) // cond: - // result: (MOVDreg x) + // result: (MOVHstoreidx2 ptr idx x mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVHreg { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVHUreg { break } - v.reset(OpARM64MOVDreg) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx2) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(x) + v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVHreg_10(v *Value) bool { - // match: (MOVHreg (MOVDconst [c])) + // match: (MOVHstoreidx2 ptr idx (MOVWreg x) mem) // cond: - // result: (MOVDconst [int64(int16(c))]) + // result: (MOVHstoreidx2 ptr idx x mem) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWreg { break } - c := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(int16(c)) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx2) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) return true } - // match: (MOVHreg (SLLconst [lc] x)) - // cond: lc < 16 - // result: (SBFIZ [arm64BFAuxInt(lc, 16-lc)] x) + // match: (MOVHstoreidx2 ptr idx (MOVWUreg x) mem) + // cond: + // result: (MOVHstoreidx2 ptr idx x mem) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { - break - } - lc := v_0.AuxInt - x := v_0.Args[0] - if !(lc < 16) { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWUreg { break } - v.reset(OpARM64SBFIZ) - v.AuxInt = arm64BFAuxInt(lc, 16-lc) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVHstoreidx2) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(x) + v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVHstore_0(v *Value) bool { +func rewriteValueARM64_OpARM64MOVHstorezero_0(v *Value) bool { b := v.Block _ = b config := b.Func.Config _ = config - // match: (MOVHstore [off1] {sym} (ADDconst [off2] ptr) val mem) + // match: (MOVHstorezero [off1] {sym} (ADDconst [off2] ptr) mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVHstore [off1+off2] {sym} ptr val mem) + // result: (MOVHstorezero [off1+off2] {sym} ptr mem) for { off1 := v.AuxInt sym := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64ADDconst { break } off2 := v_0.AuxInt ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] + mem := v.Args[1] if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVHstore) + v.reset(OpARM64MOVHstorezero) v.AuxInt = off1 + off2 v.Aux = sym v.AddArg(ptr) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstore [off] {sym} (ADD ptr idx) val mem) + // match: (MOVHstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVHstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVHstorezero) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVHstorezero [off] {sym} (ADD ptr idx) mem) // cond: off == 0 && sym == nil - // result: (MOVHstoreidx ptr idx val mem) + // result: (MOVHstorezeroidx ptr idx mem) for { off := v.AuxInt sym := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break @@ -12049,25 +14234,23 @@ func rewriteValueARM64_OpARM64MOVHstore_0(v *Value) bool { _ = v_0.Args[1] ptr := v_0.Args[0] idx := v_0.Args[1] - val := v.Args[1] - mem := v.Args[2] + mem := v.Args[1] if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVHstoreidx) + v.reset(OpARM64MOVHstorezeroidx) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstore [off] {sym} (ADDshiftLL [1] ptr idx) val mem) + // match: (MOVHstorezero [off] {sym} (ADDshiftLL [1] ptr idx) mem) // cond: off == 0 && sym == nil - // result: (MOVHstoreidx2 ptr idx val mem) + // result: (MOVHstorezeroidx2 ptr idx mem) for { off := v.AuxInt sym := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64ADDshiftLL { break @@ -12078,1224 +14261,1418 @@ func rewriteValueARM64_OpARM64MOVHstore_0(v *Value) bool { _ = v_0.Args[1] ptr := v_0.Args[0] idx := v_0.Args[1] - val := v.Args[1] - mem := v.Args[2] + mem := v.Args[1] if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVHstoreidx2) + v.reset(OpARM64MOVHstorezeroidx2) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVHstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + // match: (MOVHstorezero [i] {s} ptr0 x:(MOVHstorezero [j] {s} ptr1 mem)) + // cond: x.Uses == 1 && areAdjacentOffsets(i,j,2) && is32Bit(min(i,j)) && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVWstorezero [min(i,j)] {s} ptr0 mem) for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[2] + i := v.AuxInt + s := v.Aux + _ = v.Args[1] + ptr0 := v.Args[0] + x := v.Args[1] + if x.Op != OpARM64MOVHstorezero { + break + } + j := x.AuxInt + if x.Aux != s { + break + } + _ = x.Args[1] + ptr1 := x.Args[0] + mem := x.Args[1] + if !(x.Uses == 1 && areAdjacentOffsets(i, j, 2) && is32Bit(min(i, j)) && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVWstorezero) + v.AuxInt = min(i, j) + v.Aux = s + v.AddArg(ptr0) + v.AddArg(mem) + return true + } + // match: (MOVHstorezero [2] {s} (ADD ptr0 idx0) x:(MOVHstorezeroidx ptr1 idx1 mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVWstorezeroidx ptr1 idx1 mem) + for { + if v.AuxInt != 2 { + break + } + s := v.Aux + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + if v_0.Op != OpARM64ADD { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + x := v.Args[1] + if x.Op != OpARM64MOVHstorezeroidx { break } - v.reset(OpARM64MOVHstore) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(val) + _ = x.Args[2] + ptr1 := x.Args[0] + idx1 := x.Args[1] + mem := x.Args[2] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVWstorezeroidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(mem) + return true + } + // match: (MOVHstorezero [2] {s} (ADDshiftLL [1] ptr0 idx0) x:(MOVHstorezeroidx2 ptr1 idx1 mem)) + // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) + // result: (MOVWstorezeroidx ptr1 (SLLconst [1] idx1) mem) + for { + if v.AuxInt != 2 { + break + } + s := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { + break + } + if v_0.AuxInt != 1 { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + x := v.Args[1] + if x.Op != OpARM64MOVHstorezeroidx2 { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + idx1 := x.Args[1] + mem := x.Args[2] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + break + } + v.reset(OpARM64MOVWstorezeroidx) + v.AddArg(ptr1) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) + v0.AuxInt = 1 + v0.AddArg(idx1) + v.AddArg(v0) v.AddArg(mem) return true } - // match: (MOVHstore [off] {sym} ptr (MOVDconst [0]) mem) + return false +} +func rewriteValueARM64_OpARM64MOVHstorezeroidx_0(v *Value) bool { + // match: (MOVHstorezeroidx ptr (MOVDconst [c]) mem) // cond: - // result: (MOVHstorezero [off] {sym} ptr mem) + // result: (MOVHstorezero [c] ptr mem) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 0 { + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVHstorezero) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVHstorezeroidx (MOVDconst [c]) idx mem) + // cond: + // result: (MOVHstorezero [c] idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } + c := v_0.AuxInt + idx := v.Args[1] mem := v.Args[2] v.reset(OpARM64MOVHstorezero) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) + v.AuxInt = c + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstore [off] {sym} ptr (MOVHreg x) mem) + // match: (MOVHstorezeroidx ptr (SLLconst [1] idx) mem) // cond: - // result: (MOVHstore [off] {sym} ptr x mem) + // result: (MOVHstorezeroidx2 ptr idx mem) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVHreg { + if v_1.Op != OpARM64SLLconst { break } - x := v_1.Args[0] + if v_1.AuxInt != 1 { + break + } + idx := v_1.Args[0] mem := v.Args[2] - v.reset(OpARM64MOVHstore) - v.AuxInt = off - v.Aux = sym + v.reset(OpARM64MOVHstorezeroidx2) v.AddArg(ptr) - v.AddArg(x) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstore [off] {sym} ptr (MOVHUreg x) mem) + // match: (MOVHstorezeroidx ptr (ADD idx idx) mem) // cond: - // result: (MOVHstore [off] {sym} ptr x mem) + // result: (MOVHstorezeroidx2 ptr idx mem) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVHUreg { + if v_1.Op != OpARM64ADD { + break + } + _ = v_1.Args[1] + idx := v_1.Args[0] + if idx != v_1.Args[1] { break } - x := v_1.Args[0] mem := v.Args[2] - v.reset(OpARM64MOVHstore) - v.AuxInt = off - v.Aux = sym + v.reset(OpARM64MOVHstorezeroidx2) v.AddArg(ptr) - v.AddArg(x) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstore [off] {sym} ptr (MOVWreg x) mem) + // match: (MOVHstorezeroidx (SLLconst [1] idx) ptr mem) // cond: - // result: (MOVHstore [off] {sym} ptr x mem) + // result: (MOVHstorezeroidx2 ptr idx mem) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - x := v_1.Args[0] + if v_0.AuxInt != 1 { + break + } + idx := v_0.Args[0] + ptr := v.Args[1] mem := v.Args[2] - v.reset(OpARM64MOVHstore) - v.AuxInt = off - v.Aux = sym + v.reset(OpARM64MOVHstorezeroidx2) v.AddArg(ptr) - v.AddArg(x) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstore [off] {sym} ptr (MOVWUreg x) mem) + // match: (MOVHstorezeroidx (ADD idx idx) ptr mem) // cond: - // result: (MOVHstore [off] {sym} ptr x mem) + // result: (MOVHstorezeroidx2 ptr idx mem) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWUreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - x := v_1.Args[0] + _ = v_0.Args[1] + idx := v_0.Args[0] + if idx != v_0.Args[1] { + break + } + ptr := v.Args[1] mem := v.Args[2] - v.reset(OpARM64MOVHstore) - v.AuxInt = off - v.Aux = sym + v.reset(OpARM64MOVHstorezeroidx2) v.AddArg(ptr) - v.AddArg(x) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstore [i] {s} ptr0 (SRLconst [16] w) x:(MOVHstore [i-2] {s} ptr1 w mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVWstore [i-2] {s} ptr0 w mem) + // match: (MOVHstorezeroidx ptr (ADDconst [2] idx) x:(MOVHstorezeroidx ptr idx mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVWstorezeroidx ptr idx mem) for { - i := v.AuxInt - s := v.Aux _ = v.Args[2] - ptr0 := v.Args[0] + ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + if v_1.Op != OpARM64ADDconst { break } - if v_1.AuxInt != 16 { + if v_1.AuxInt != 2 { break } - w := v_1.Args[0] + idx := v_1.Args[0] x := v.Args[2] - if x.Op != OpARM64MOVHstore { - break - } - if x.AuxInt != i-2 { + if x.Op != OpARM64MOVHstorezeroidx { break } - if x.Aux != s { + _ = x.Args[2] + if ptr != x.Args[0] { break } - _ = x.Args[2] - ptr1 := x.Args[0] - if w != x.Args[1] { + if idx != x.Args[1] { break } mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + if !(x.Uses == 1 && clobber(x)) { break } - v.reset(OpARM64MOVWstore) - v.AuxInt = i - 2 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w) + v.reset(OpARM64MOVWstorezeroidx) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVHstore_10(v *Value) bool { - b := v.Block - _ = b - // match: (MOVHstore [2] {s} (ADD ptr0 idx0) (SRLconst [16] w) x:(MOVHstoreidx ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVWstoreidx ptr1 idx1 w mem) +func rewriteValueARM64_OpARM64MOVHstorezeroidx2_0(v *Value) bool { + // match: (MOVHstorezeroidx2 ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVHstorezero [c<<1] ptr mem) for { - if v.AuxInt != 2 { - break - } - s := v.Aux _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] + ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - if v_1.AuxInt != 16 { - break - } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstoreidx { - break - } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { - break - } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w) + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVHstorezero) + v.AuxInt = c << 1 + v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVHstore [2] {s} (ADDshiftLL [1] ptr0 idx0) (SRLconst [16] w) x:(MOVHstoreidx2 ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVWstoreidx ptr1 (SLLconst [1] idx1) w mem) + return false +} +func rewriteValueARM64_OpARM64MOVQstorezero_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVQstorezero [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVQstorezero [off1+off2] {sym} ptr mem) for { - if v.AuxInt != 2 { - break - } - s := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { - break - } - if v_0.AuxInt != 1 { - break - } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - if v_1.AuxInt != 16 { - break - } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstoreidx2 { - break - } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr1) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) - v0.AuxInt = 1 - v0.AddArg(idx1) - v.AddArg(v0) - v.AddArg(w) + v.reset(OpARM64MOVQstorezero) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVHstore [i] {s} ptr0 (UBFX [arm64BFAuxInt(16, 16)] w) x:(MOVHstore [i-2] {s} ptr1 w mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVWstore [i-2] {s} ptr0 w mem) + // match: (MOVQstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVQstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64UBFX { - break - } - if v_1.AuxInt != arm64BFAuxInt(16, 16) { - break - } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstore { - break - } - if x.AuxInt != i-2 { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { break } - if x.Aux != s { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - _ = x.Args[2] - ptr1 := x.Args[0] - if w != x.Args[1] { + v.reset(OpARM64MOVQstorezero) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVWUload [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWUload [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVWstore) - v.AuxInt = i - 2 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w) + v.reset(OpARM64MOVWUload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVHstore [2] {s} (ADD ptr0 idx0) (UBFX [arm64BFAuxInt(16, 16)] w) x:(MOVHstoreidx ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVWstoreidx ptr1 idx1 w mem) + // match: (MOVWUload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVWUloadidx ptr idx mem) for { - if v.AuxInt != 2 { - break - } - s := v.Aux - _ = v.Args[2] + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break } _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64UBFX { - break - } - if v_1.AuxInt != arm64BFAuxInt(16, 16) { + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstoreidx { + v.reset(OpARM64MOVWUloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVWUload [off] {sym} (ADDshiftLL [2] ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVWUloadidx4 ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { + if v_0.AuxInt != 2 { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w) + v.reset(OpARM64MOVWUloadidx4) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstore [2] {s} (ADDshiftLL [1] ptr0 idx0) (UBFX [arm64BFAuxInt(16, 16)] w) x:(MOVHstoreidx2 ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVWstoreidx ptr1 (SLLconst [1] idx1) w mem) + // match: (MOVWUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) for { - if v.AuxInt != 2 { - break - } - s := v.Aux - _ = v.Args[2] + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { + if v_0.Op != OpARM64MOVDaddr { break } - if v_0.AuxInt != 1 { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] + v.reset(OpARM64MOVWUload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVWUload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) + // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) + // result: (MOVDconst [0]) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64UBFX { - break - } - if v_1.AuxInt != arm64BFAuxInt(16, 16) { - break - } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstoreidx2 { + if v_1.Op != OpARM64MOVWstorezero { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { + off2 := v_1.AuxInt + sym2 := v_1.Aux + _ = v_1.Args[1] + ptr2 := v_1.Args[0] + if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWUloadidx_0(v *Value) bool { + // match: (MOVWUloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVWUload [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr1) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) - v0.AuxInt = 1 - v0.AddArg(idx1) - v.AddArg(v0) - v.AddArg(w) + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVWUload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVWUloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (MOVWUload [c] ptr mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVWUload) + v.AuxInt = c + v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVHstore [i] {s} ptr0 (SRLconst [16] (MOVDreg w)) x:(MOVHstore [i-2] {s} ptr1 w mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVWstore [i-2] {s} ptr0 w mem) + // match: (MOVWUloadidx ptr (SLLconst [2] idx) mem) + // cond: + // result: (MOVWUloadidx4 ptr idx mem) for { - i := v.AuxInt - s := v.Aux _ = v.Args[2] - ptr0 := v.Args[0] + ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - if v_1.AuxInt != 16 { - break - } - v_1_0 := v_1.Args[0] - if v_1_0.Op != OpARM64MOVDreg { - break - } - w := v_1_0.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstore { - break - } - if x.AuxInt != i-2 { + if v_1.Op != OpARM64SLLconst { break } - if x.Aux != s { + if v_1.AuxInt != 2 { break } - _ = x.Args[2] - ptr1 := x.Args[0] - if w != x.Args[1] { + idx := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVWUloadidx4) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVWUloadidx (SLLconst [2] idx) ptr mem) + // cond: + // result: (MOVWUloadidx4 ptr idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + if v_0.AuxInt != 2 { break } - v.reset(OpARM64MOVWstore) - v.AuxInt = i - 2 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w) + idx := v_0.Args[0] + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVWUloadidx4) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstore [2] {s} (ADD ptr0 idx0) (SRLconst [16] (MOVDreg w)) x:(MOVHstoreidx ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVWstoreidx ptr1 idx1 w mem) + // match: (MOVWUloadidx ptr idx (MOVWstorezeroidx ptr2 idx2 _)) + // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // result: (MOVDconst [0]) for { - if v.AuxInt != 2 { - break - } - s := v.Aux _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWstorezeroidx { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { break } - if v_1.AuxInt != 16 { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWUloadidx4_0(v *Value) bool { + // match: (MOVWUloadidx4 ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVWUload [c<<2] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v_1_0 := v_1.Args[0] - if v_1_0.Op != OpARM64MOVDreg { + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVWUload) + v.AuxInt = c << 2 + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVWUloadidx4 ptr idx (MOVWstorezeroidx4 ptr2 idx2 _)) + // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) + // result: (MOVDconst [0]) + for { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWstorezeroidx4 { break } - w := v_1_0.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstoreidx { + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWUreg_0(v *Value) bool { + // match: (MOVWUreg x:(MOVBUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUload { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVHUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUload { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w) - v.AddArg(mem) + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVHstore [2] {s} (ADDshiftLL [1] ptr0 idx0) (SRLconst [16] (MOVDreg w)) x:(MOVHstoreidx2 ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVWstoreidx ptr1 (SLLconst [1] idx1) w mem) + // match: (MOVWUreg x:(MOVWUload _ _)) + // cond: + // result: (MOVDreg x) for { - if v.AuxInt != 2 { + x := v.Args[0] + if x.Op != OpARM64MOVWUload { break } - s := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVBUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUloadidx { break } - if v_0.AuxInt != 1 { + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVHUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUloadidx { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVWUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVWUloadidx { break } - if v_1.AuxInt != 16 { + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVHUloadidx2 _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUloadidx2 { break } - v_1_0 := v_1.Args[0] - if v_1_0.Op != OpARM64MOVDreg { + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVWUloadidx4 _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVWUloadidx4 { break } - w := v_1_0.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstoreidx2 { + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVBUreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUreg { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVHUreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUreg { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWUreg_10(v *Value) bool { + // match: (MOVWUreg x:(MOVWUreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVWUreg { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr1) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) - v0.AuxInt = 1 - v0.AddArg(idx1) - v.AddArg(v0) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVHstore [i] {s} ptr0 (SRLconst [j] w) x:(MOVHstore [i-2] {s} ptr1 w0:(SRLconst [j-16] w) mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVWstore [i-2] {s} ptr0 w0 mem) + // match: (MOVWUreg (ANDconst [c] x)) + // cond: + // result: (ANDconst [c&(1<<32-1)] x) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64ANDconst { break } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstore { + c := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ANDconst) + v.AuxInt = c & (1<<32 - 1) + v.AddArg(x) + return true + } + // match: (MOVWUreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(uint32(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x.AuxInt != i-2 { + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(uint32(c)) + return true + } + // match: (MOVWUreg (SLLconst [sc] x)) + // cond: isARM64BFMask(sc, 1<<32-1, sc) + // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc))] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - if x.Aux != s { + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<32-1, sc)) { break } - _ = x.Args[2] - ptr1 := x.Args[0] - w0 := x.Args[1] - if w0.Op != OpARM64SRLconst { + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc)) + v.AddArg(x) + return true + } + // match: (MOVWUreg (SRLconst [sc] x)) + // cond: isARM64BFMask(sc, 1<<32-1, 0) + // result: (UBFX [arm64BFAuxInt(sc, 32)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SRLconst { break } - if w0.AuxInt != j-16 { + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<32-1, 0)) { break } - if w != w0.Args[0] { + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc, 32) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVWload [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWload [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVWstore) - v.AuxInt = i - 2 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w0) + v.reset(OpARM64MOVWload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVHstore [2] {s} (ADD ptr0 idx0) (SRLconst [j] w) x:(MOVHstoreidx ptr1 idx1 w0:(SRLconst [j-16] w) mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVWstoreidx ptr1 idx1 w0 mem) + // match: (MOVWload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVWloadidx ptr idx mem) for { - if v.AuxInt != 2 { - break - } - s := v.Aux - _ = v.Args[2] + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break } _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstoreidx { - break - } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - w0 := x.Args[2] - if w0.Op != OpARM64SRLconst { - break - } - if w0.AuxInt != j-16 { - break - } - if w != w0.Args[0] { - break - } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w0) + v.reset(OpARM64MOVWloadidx) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVHstore_20(v *Value) bool { - b := v.Block - _ = b - // match: (MOVHstore [2] {s} (ADDshiftLL [1] ptr0 idx0) (SRLconst [j] w) x:(MOVHstoreidx2 ptr1 idx1 w0:(SRLconst [j-16] w) mem)) - // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVWstoreidx ptr1 (SLLconst [1] idx1) w0 mem) + // match: (MOVWload [off] {sym} (ADDshiftLL [2] ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVWloadidx4 ptr idx mem) for { - if v.AuxInt != 2 { - break - } - s := v.Aux - _ = v.Args[2] + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64ADDshiftLL { break } - if v_0.AuxInt != 1 { + if v_0.AuxInt != 2 { break } _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstoreidx2 { + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - w0 := x.Args[2] - if w0.Op != OpARM64SRLconst { + v.reset(OpARM64MOVWloadidx4) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVWload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { break } - if w0.AuxInt != j-16 { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - if w != w0.Args[0] { + v.reset(OpARM64MOVWload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVWload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) + // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) + // result: (MOVDconst [0]) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWstorezero { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + off2 := v_1.AuxInt + sym2 := v_1.Aux + _ = v_1.Args[1] + ptr2 := v_1.Args[0] + if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr1) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) - v0.AuxInt = 1 - v0.AddArg(idx1) - v.AddArg(v0) - v.AddArg(w0) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } return false } -func rewriteValueARM64_OpARM64MOVHstoreidx_0(v *Value) bool { - // match: (MOVHstoreidx ptr (MOVDconst [c]) val mem) +func rewriteValueARM64_OpARM64MOVWloadidx_0(v *Value) bool { + // match: (MOVWloadidx ptr (MOVDconst [c]) mem) // cond: - // result: (MOVHstore [c] ptr val mem) + // result: (MOVWload [c] ptr mem) for { - _ = v.Args[3] + _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVHstore) + mem := v.Args[2] + v.reset(OpARM64MOVWload) v.AuxInt = c v.AddArg(ptr) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstoreidx (MOVDconst [c]) idx val mem) + // match: (MOVWloadidx (MOVDconst [c]) ptr mem) // cond: - // result: (MOVHstore [c] idx val mem) + // result: (MOVWload [c] ptr mem) for { - _ = v.Args[3] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - idx := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVHstore) + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVWload) v.AuxInt = c - v.AddArg(idx) - v.AddArg(val) + v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVHstoreidx ptr (SLLconst [1] idx) val mem) + // match: (MOVWloadidx ptr (SLLconst [2] idx) mem) // cond: - // result: (MOVHstoreidx2 ptr idx val mem) + // result: (MOVWloadidx4 ptr idx mem) for { - _ = v.Args[3] + _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64SLLconst { break } - if v_1.AuxInt != 1 { + if v_1.AuxInt != 2 { break } idx := v_1.Args[0] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx2) + mem := v.Args[2] + v.reset(OpARM64MOVWloadidx4) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstoreidx ptr (ADD idx idx) val mem) + // match: (MOVWloadidx (SLLconst [2] idx) ptr mem) // cond: - // result: (MOVHstoreidx2 ptr idx val mem) + // result: (MOVWloadidx4 ptr idx mem) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADD { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - _ = v_1.Args[1] - idx := v_1.Args[0] - if idx != v_1.Args[1] { + if v_0.AuxInt != 2 { break } - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx2) + idx := v_0.Args[0] + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVWloadidx4) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstoreidx (SLLconst [1] idx) ptr val mem) - // cond: - // result: (MOVHstoreidx2 ptr idx val mem) + // match: (MOVWloadidx ptr idx (MOVWstorezeroidx ptr2 idx2 _)) + // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // result: (MOVDconst [0]) for { - _ = v.Args[3] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWstorezeroidx { break } - if v_0.AuxInt != 1 { + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { break } - idx := v_0.Args[0] - ptr := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx2) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWloadidx4_0(v *Value) bool { + // match: (MOVWloadidx4 ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVWload [c<<2] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVWload) + v.AuxInt = c << 2 v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstoreidx (ADD idx idx) ptr val mem) + // match: (MOVWloadidx4 ptr idx (MOVWstorezeroidx4 ptr2 idx2 _)) + // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) + // result: (MOVDconst [0]) + for { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWstorezeroidx4 { + break + } + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWreg_0(v *Value) bool { + // match: (MOVWreg x:(MOVBload _ _)) // cond: - // result: (MOVHstoreidx2 ptr idx val mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + x := v.Args[0] + if x.Op != OpARM64MOVBload { break } - _ = v_0.Args[1] - idx := v_0.Args[0] - if idx != v_0.Args[1] { + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVBUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUload { break } - ptr := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx2) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVHstoreidx ptr idx (MOVDconst [0]) mem) + // match: (MOVWreg x:(MOVHload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVHUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVWload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVWload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVBloadidx _ _ _)) // cond: - // result: (MOVHstorezeroidx ptr idx mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDconst { + x := v.Args[0] + if x.Op != OpARM64MOVBloadidx { break } - if v_2.AuxInt != 0 { + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVBUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUloadidx { break } - mem := v.Args[3] - v.reset(OpARM64MOVHstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVHstoreidx ptr idx (MOVHreg x) mem) + // match: (MOVWreg x:(MOVHloadidx _ _ _)) // cond: - // result: (MOVHstoreidx ptr idx x mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVHreg { + x := v.Args[0] + if x.Op != OpARM64MOVHloadidx { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr) - v.AddArg(idx) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) v.AddArg(x) - v.AddArg(mem) return true } - // match: (MOVHstoreidx ptr idx (MOVHUreg x) mem) + // match: (MOVWreg x:(MOVHUloadidx _ _ _)) // cond: - // result: (MOVHstoreidx ptr idx x mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVHUreg { + x := v.Args[0] + if x.Op != OpARM64MOVHUloadidx { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr) - v.AddArg(idx) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) v.AddArg(x) - v.AddArg(mem) return true } - // match: (MOVHstoreidx ptr idx (MOVWreg x) mem) + // match: (MOVWreg x:(MOVWloadidx _ _ _)) // cond: - // result: (MOVHstoreidx ptr idx x mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWreg { + x := v.Args[0] + if x.Op != OpARM64MOVWloadidx { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr) - v.AddArg(idx) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) v.AddArg(x) - v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVHstoreidx_10(v *Value) bool { - // match: (MOVHstoreidx ptr idx (MOVWUreg x) mem) +func rewriteValueARM64_OpARM64MOVWreg_10(v *Value) bool { + // match: (MOVWreg x:(MOVHloadidx2 _ _ _)) // cond: - // result: (MOVHstoreidx ptr idx x mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWUreg { + x := v.Args[0] + if x.Op != OpARM64MOVHloadidx2 { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx) - v.AddArg(ptr) - v.AddArg(idx) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) v.AddArg(x) - v.AddArg(mem) return true } - // match: (MOVHstoreidx ptr (ADDconst [2] idx) (SRLconst [16] w) x:(MOVHstoreidx ptr idx w mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVWstoreidx ptr idx w mem) + // match: (MOVWreg x:(MOVHUloadidx2 _ _ _)) + // cond: + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { - break - } - if v_1.AuxInt != 2 { - break - } - idx := v_1.Args[0] - v_2 := v.Args[2] - if v_2.Op != OpARM64SRLconst { - break - } - if v_2.AuxInt != 16 { - break - } - w := v_2.Args[0] - x := v.Args[3] - if x.Op != OpARM64MOVHstoreidx { - break - } - _ = x.Args[3] - if ptr != x.Args[0] { - break - } - if idx != x.Args[1] { - break - } - if w != x.Args[2] { - break - } - mem := x.Args[3] - if !(x.Uses == 1 && clobber(x)) { + x := v.Args[0] + if x.Op != OpARM64MOVHUloadidx2 { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(w) - v.AddArg(mem) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64MOVHstoreidx2_0(v *Value) bool { - // match: (MOVHstoreidx2 ptr (MOVDconst [c]) val mem) + // match: (MOVWreg x:(MOVWloadidx4 _ _ _)) // cond: - // result: (MOVHstore [c<<1] ptr val mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + x := v.Args[0] + if x.Op != OpARM64MOVWloadidx4 { break } - c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVHstore) - v.AuxInt = c << 1 - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVHstoreidx2 ptr idx (MOVDconst [0]) mem) + // match: (MOVWreg x:(MOVBreg _)) // cond: - // result: (MOVHstorezeroidx2 ptr idx mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDconst { + x := v.Args[0] + if x.Op != OpARM64MOVBreg { break } - if v_2.AuxInt != 0 { + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVBUreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUreg { break } - mem := v.Args[3] - v.reset(OpARM64MOVHstorezeroidx2) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVHstoreidx2 ptr idx (MOVHreg x) mem) + // match: (MOVWreg x:(MOVHreg _)) // cond: - // result: (MOVHstoreidx2 ptr idx x mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVHreg { + x := v.Args[0] + if x.Op != OpARM64MOVHreg { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx2) - v.AddArg(ptr) - v.AddArg(idx) + v.reset(OpARM64MOVDreg) v.AddArg(x) - v.AddArg(mem) return true } - // match: (MOVHstoreidx2 ptr idx (MOVHUreg x) mem) + // match: (MOVWreg x:(MOVHreg _)) // cond: - // result: (MOVHstoreidx2 ptr idx x mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVHUreg { + x := v.Args[0] + if x.Op != OpARM64MOVHreg { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx2) - v.AddArg(ptr) - v.AddArg(idx) + v.reset(OpARM64MOVDreg) v.AddArg(x) - v.AddArg(mem) return true } - // match: (MOVHstoreidx2 ptr idx (MOVWreg x) mem) + // match: (MOVWreg x:(MOVWreg _)) // cond: - // result: (MOVHstoreidx2 ptr idx x mem) + // result: (MOVDreg x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWreg { + x := v.Args[0] + if x.Op != OpARM64MOVWreg { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx2) - v.AddArg(ptr) - v.AddArg(idx) + v.reset(OpARM64MOVDreg) v.AddArg(x) - v.AddArg(mem) return true } - // match: (MOVHstoreidx2 ptr idx (MOVWUreg x) mem) + // match: (MOVWreg (MOVDconst [c])) // cond: - // result: (MOVHstoreidx2 ptr idx x mem) + // result: (MOVDconst [int64(int32(c))]) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWUreg { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVHstoreidx2) - v.AddArg(ptr) - v.AddArg(idx) + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(int32(c)) + return true + } + // match: (MOVWreg (SLLconst [lc] x)) + // cond: lc < 32 + // result: (SBFIZ [arm64BFAuxInt(lc, 32-lc)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { + break + } + lc := v_0.AuxInt + x := v_0.Args[0] + if !(lc < 32) { + break + } + v.reset(OpARM64SBFIZ) + v.AuxInt = arm64BFAuxInt(lc, 32-lc) v.AddArg(x) - v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVHstorezero_0(v *Value) bool { +func rewriteValueARM64_OpARM64MOVWstore_0(v *Value) bool { b := v.Block _ = b config := b.Func.Config _ = config - // match: (MOVHstorezero [off1] {sym} (ADDconst [off2] ptr) mem) + // match: (MOVWstore [off1] {sym} (ADDconst [off2] ptr) val mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVHstorezero [off1+off2] {sym} ptr mem) + // result: (MOVWstore [off1+off2] {sym} ptr val mem) for { off1 := v.AuxInt sym := v.Aux - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADDconst { break } off2 := v_0.AuxInt ptr := v_0.Args[0] - mem := v.Args[1] + val := v.Args[1] + mem := v.Args[2] if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVHstorezero) + v.reset(OpARM64MOVWstore) v.AuxInt = off1 + off2 v.Aux = sym v.AddArg(ptr) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVHstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) - for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { - break - } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { - break - } - v.reset(OpARM64MOVHstorezero) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVHstorezero [off] {sym} (ADD ptr idx) mem) + // match: (MOVWstore [off] {sym} (ADD ptr idx) val mem) // cond: off == 0 && sym == nil - // result: (MOVHstorezeroidx ptr idx mem) + // result: (MOVWstoreidx ptr idx val mem) for { off := v.AuxInt sym := v.Aux - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break @@ -13303,443 +15680,392 @@ func rewriteValueARM64_OpARM64MOVHstorezero_0(v *Value) bool { _ = v_0.Args[1] ptr := v_0.Args[0] idx := v_0.Args[1] - mem := v.Args[1] + val := v.Args[1] + mem := v.Args[2] if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVHstorezeroidx) + v.reset(OpARM64MOVWstoreidx) v.AddArg(ptr) v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstorezero [off] {sym} (ADDshiftLL [1] ptr idx) mem) + // match: (MOVWstore [off] {sym} (ADDshiftLL [2] ptr idx) val mem) // cond: off == 0 && sym == nil - // result: (MOVHstorezeroidx2 ptr idx mem) + // result: (MOVWstoreidx4 ptr idx val mem) for { off := v.AuxInt sym := v.Aux - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADDshiftLL { break } - if v_0.AuxInt != 1 { + if v_0.AuxInt != 2 { break } _ = v_0.Args[1] ptr := v_0.Args[0] idx := v_0.Args[1] - mem := v.Args[1] + val := v.Args[1] + mem := v.Args[2] if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVHstorezeroidx2) + v.reset(OpARM64MOVWstoreidx4) v.AddArg(ptr) v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstorezero [i] {s} ptr0 x:(MOVHstorezero [j] {s} ptr1 mem)) - // cond: x.Uses == 1 && areAdjacentOffsets(i,j,2) && is32Bit(min(i,j)) && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVWstorezero [min(i,j)] {s} ptr0 mem) - for { - i := v.AuxInt - s := v.Aux - _ = v.Args[1] - ptr0 := v.Args[0] - x := v.Args[1] - if x.Op != OpARM64MOVHstorezero { - break - } - j := x.AuxInt - if x.Aux != s { - break - } - _ = x.Args[1] - ptr1 := x.Args[0] - mem := x.Args[1] - if !(x.Uses == 1 && areAdjacentOffsets(i, j, 2) && is32Bit(min(i, j)) && isSamePtr(ptr0, ptr1) && clobber(x)) { - break - } - v.reset(OpARM64MOVWstorezero) - v.AuxInt = min(i, j) - v.Aux = s - v.AddArg(ptr0) - v.AddArg(mem) - return true - } - // match: (MOVHstorezero [2] {s} (ADD ptr0 idx0) x:(MOVHstorezeroidx ptr1 idx1 mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVWstorezeroidx ptr1 idx1 mem) - for { - if v.AuxInt != 2 { - break - } - s := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - x := v.Args[1] - if x.Op != OpARM64MOVHstorezeroidx { - break - } - _ = x.Args[2] - ptr1 := x.Args[0] - idx1 := x.Args[1] - mem := x.Args[2] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { - break - } - v.reset(OpARM64MOVWstorezeroidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(mem) - return true - } - // match: (MOVHstorezero [2] {s} (ADDshiftLL [1] ptr0 idx0) x:(MOVHstorezeroidx2 ptr1 idx1 mem)) - // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVWstorezeroidx ptr1 (SLLconst [1] idx1) mem) - for { - if v.AuxInt != 2 { - break - } - s := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { - break - } - if v_0.AuxInt != 1 { - break - } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - x := v.Args[1] - if x.Op != OpARM64MOVHstorezeroidx2 { - break - } - _ = x.Args[2] - ptr1 := x.Args[0] - idx1 := x.Args[1] - mem := x.Args[2] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { - break - } - v.reset(OpARM64MOVWstorezeroidx) - v.AddArg(ptr1) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) - v0.AuxInt = 1 - v0.AddArg(idx1) - v.AddArg(v0) - v.AddArg(mem) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVHstorezeroidx_0(v *Value) bool { - // match: (MOVHstorezeroidx ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVHstorezero [c] ptr mem) + // match: (MOVWstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) for { + off1 := v.AuxInt + sym1 := v.Aux _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { break } - c := v_1.AuxInt + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + val := v.Args[1] mem := v.Args[2] - v.reset(OpARM64MOVHstorezero) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVHstorezeroidx (MOVDconst [c]) idx mem) - // cond: - // result: (MOVHstorezero [c] idx mem) - for { - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - c := v_0.AuxInt - idx := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVHstorezero) - v.AuxInt = c - v.AddArg(idx) + v.reset(OpARM64MOVWstore) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVHstorezeroidx ptr (SLLconst [1] idx) mem) + // match: (MOVWstore [off] {sym} ptr (MOVDconst [0]) mem) // cond: - // result: (MOVHstorezeroidx2 ptr idx mem) + // result: (MOVWstorezero [off] {sym} ptr mem) for { + off := v.AuxInt + sym := v.Aux _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SLLconst { + if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 1 { + if v_1.AuxInt != 0 { break } - idx := v_1.Args[0] mem := v.Args[2] - v.reset(OpARM64MOVHstorezeroidx2) + v.reset(OpARM64MOVWstorezero) + v.AuxInt = off + v.Aux = sym v.AddArg(ptr) - v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstorezeroidx ptr (ADD idx idx) mem) + // match: (MOVWstore [off] {sym} ptr (MOVWreg x) mem) // cond: - // result: (MOVHstorezeroidx2 ptr idx mem) + // result: (MOVWstore [off] {sym} ptr x mem) for { + off := v.AuxInt + sym := v.Aux _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64ADD { - break - } - _ = v_1.Args[1] - idx := v_1.Args[0] - if idx != v_1.Args[1] { + if v_1.Op != OpARM64MOVWreg { break } + x := v_1.Args[0] mem := v.Args[2] - v.reset(OpARM64MOVHstorezeroidx2) + v.reset(OpARM64MOVWstore) + v.AuxInt = off + v.Aux = sym v.AddArg(ptr) - v.AddArg(idx) + v.AddArg(x) v.AddArg(mem) return true } - // match: (MOVHstorezeroidx (SLLconst [1] idx) ptr mem) + // match: (MOVWstore [off] {sym} ptr (MOVWUreg x) mem) // cond: - // result: (MOVHstorezeroidx2 ptr idx mem) + // result: (MOVWstore [off] {sym} ptr x mem) for { + off := v.AuxInt + sym := v.Aux _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { - break - } - if v_0.AuxInt != 1 { + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWUreg { break } - idx := v_0.Args[0] - ptr := v.Args[1] + x := v_1.Args[0] mem := v.Args[2] - v.reset(OpARM64MOVHstorezeroidx2) + v.reset(OpARM64MOVWstore) + v.AuxInt = off + v.Aux = sym v.AddArg(ptr) - v.AddArg(idx) + v.AddArg(x) v.AddArg(mem) return true } - // match: (MOVHstorezeroidx (ADD idx idx) ptr mem) - // cond: - // result: (MOVHstorezeroidx2 ptr idx mem) + // match: (MOVWstore [i] {s} ptr0 (SRLconst [32] w) x:(MOVWstore [i-4] {s} ptr1 w mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVDstore [i-4] {s} ptr0 w mem) for { + i := v.AuxInt + s := v.Aux _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - _ = v_0.Args[1] - idx := v_0.Args[0] - if idx != v_0.Args[1] { + if v_1.AuxInt != 32 { break } - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVHstorezeroidx2) - v.AddArg(ptr) - v.AddArg(idx) + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstore { + break + } + if x.AuxInt != i-4 { + break + } + if x.Aux != s { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + if w != x.Args[1] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstore) + v.AuxInt = i - 4 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVHstorezeroidx ptr (ADDconst [2] idx) x:(MOVHstorezeroidx ptr idx mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVWstorezeroidx ptr idx mem) + // match: (MOVWstore [4] {s} (ADD ptr0 idx0) (SRLconst [32] w) x:(MOVWstoreidx ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVDstoreidx ptr1 idx1 w mem) for { + if v.AuxInt != 4 { + break + } + s := v.Aux _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - if v_1.AuxInt != 2 { + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - idx := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstorezeroidx { + if v_1.AuxInt != 32 { break } - _ = x.Args[2] - if ptr != x.Args[0] { + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstoreidx { break } - if idx != x.Args[1] { + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { break } - mem := x.Args[2] - if !(x.Uses == 1 && clobber(x)) { + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { break } - v.reset(OpARM64MOVWstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w) v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVHstorezeroidx2_0(v *Value) bool { - // match: (MOVHstorezeroidx2 ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVHstorezero [c<<1] ptr mem) + // match: (MOVWstore [4] {s} (ADDshiftLL [2] ptr0 idx0) (SRLconst [32] w) x:(MOVWstoreidx4 ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) + // result: (MOVDstoreidx ptr1 (SLLconst [2] idx1) w mem) for { + if v.AuxInt != 4 { + break + } + s := v.Aux _ = v.Args[2] - ptr := v.Args[0] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { + break + } + if v_0.AuxInt != 2 { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64SRLconst { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVHstorezero) - v.AuxInt = c << 1 - v.AddArg(ptr) + if v_1.AuxInt != 32 { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstoreidx4 { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr1) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) + v0.AuxInt = 2 + v0.AddArg(idx1) + v.AddArg(v0) + v.AddArg(w) v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVQstorezero_0(v *Value) bool { +func rewriteValueARM64_OpARM64MOVWstore_10(v *Value) bool { b := v.Block _ = b - config := b.Func.Config - _ = config - // match: (MOVQstorezero [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVQstorezero [off1+off2] {sym} ptr mem) + // match: (MOVWstore [i] {s} ptr0 (SRLconst [j] w) x:(MOVWstore [i-4] {s} ptr1 w0:(SRLconst [j-32] w) mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVDstore [i-4] {s} ptr0 w0 mem) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { - break - } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVQstorezero) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVQstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVQstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) - for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstore { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if x.AuxInt != i-4 { break } - v.reset(OpARM64MOVQstorezero) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVWUload [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWUload [off1+off2] {sym} ptr mem) - for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + if x.Aux != s { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = x.Args[2] + ptr1 := x.Args[0] + w0 := x.Args[1] + if w0.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVWUload) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) + if w0.AuxInt != j-32 { + break + } + if w != w0.Args[0] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstore) + v.AuxInt = i - 4 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w0) v.AddArg(mem) return true } - // match: (MOVWUload [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVWUloadidx ptr idx mem) + // match: (MOVWstore [4] {s} (ADD ptr0 idx0) (SRLconst [j] w) x:(MOVWstoreidx ptr1 idx1 w0:(SRLconst [j-32] w) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVDstoreidx ptr1 idx1 w0 mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + if v.AuxInt != 4 { + break + } + s := v.Aux + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break } _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVWUloadidx) - v.AddArg(ptr) - v.AddArg(idx) + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + w0 := x.Args[2] + if w0.Op != OpARM64SRLconst { + break + } + if w0.AuxInt != j-32 { + break + } + if w != w0.Args[0] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w0) v.AddArg(mem) return true } - // match: (MOVWUload [off] {sym} (ADDshiftLL [2] ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVWUloadidx4 ptr idx mem) + // match: (MOVWstore [4] {s} (ADDshiftLL [2] ptr0 idx0) (SRLconst [j] w) x:(MOVWstoreidx4 ptr1 idx1 w0:(SRLconst [j-32] w) mem)) + // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) + // result: (MOVDstoreidx ptr1 (SLLconst [2] idx1) w0 mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + if v.AuxInt != 4 { + break + } + s := v.Aux + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADDshiftLL { break @@ -13748,556 +16074,656 @@ func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { break } _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVWUloadidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVWUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) - for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstoreidx4 { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + w0 := x.Args[2] + if w0.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVWUload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) + if w0.AuxInt != j-32 { + break + } + if w != w0.Args[0] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr1) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) + v0.AuxInt = 2 + v0.AddArg(idx1) + v.AddArg(v0) + v.AddArg(w0) v.AddArg(mem) return true } - // match: (MOVWUload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) - // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) - // result: (MOVDconst [0]) + return false +} +func rewriteValueARM64_OpARM64MOVWstoreidx_0(v *Value) bool { + // match: (MOVWstoreidx ptr (MOVDconst [c]) val mem) + // cond: + // result: (MOVWstore [c] ptr val mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + _ = v.Args[3] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWstorezero { + if v_1.Op != OpARM64MOVDconst { break } - off2 := v_1.AuxInt - sym2 := v_1.Aux - _ = v_1.Args[1] - ptr2 := v_1.Args[0] - if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + c := v_1.AuxInt + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVWstore) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVWstoreidx (MOVDconst [c]) idx val mem) + // cond: + // result: (MOVWstore [c] idx val mem) + for { + _ = v.Args[3] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + c := v_0.AuxInt + idx := v.Args[1] + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVWstore) + v.AuxInt = c + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVWUloadidx_0(v *Value) bool { - // match: (MOVWUloadidx ptr (MOVDconst [c]) mem) + // match: (MOVWstoreidx ptr (SLLconst [2] idx) val mem) // cond: - // result: (MOVWUload [c] ptr mem) + // result: (MOVWstoreidx4 ptr idx val mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64SLLconst { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVWUload) - v.AuxInt = c + if v_1.AuxInt != 2 { + break + } + idx := v_1.Args[0] + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx4) v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWUloadidx (MOVDconst [c]) ptr mem) + // match: (MOVWstoreidx (SLLconst [2] idx) ptr val mem) // cond: - // result: (MOVWUload [c] ptr mem) + // result: (MOVWstoreidx4 ptr idx val mem) for { - _ = v.Args[2] + _ = v.Args[3] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64SLLconst { break } - c := v_0.AuxInt + if v_0.AuxInt != 2 { + break + } + idx := v_0.Args[0] ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVWUload) - v.AuxInt = c + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx4) v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWUloadidx ptr (SLLconst [2] idx) mem) + // match: (MOVWstoreidx ptr idx (MOVDconst [0]) mem) // cond: - // result: (MOVWUloadidx4 ptr idx mem) + // result: (MOVWstorezeroidx ptr idx mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SLLconst { + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 2 { + if v_2.AuxInt != 0 { break } - idx := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVWUloadidx4) + mem := v.Args[3] + v.reset(OpARM64MOVWstorezeroidx) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWUloadidx (SLLconst [2] idx) ptr mem) + // match: (MOVWstoreidx ptr idx (MOVWreg x) mem) // cond: - // result: (MOVWUloadidx4 ptr idx mem) + // result: (MOVWstoreidx ptr idx x mem) for { - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWreg { break } - if v_0.AuxInt != 2 { + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVWstoreidx ptr idx (MOVWUreg x) mem) + // cond: + // result: (MOVWstoreidx ptr idx x mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWUreg { break } - idx := v_0.Args[0] - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVWUloadidx4) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx) v.AddArg(ptr) v.AddArg(idx) + v.AddArg(x) v.AddArg(mem) return true } - // match: (MOVWUloadidx ptr idx (MOVWstorezeroidx ptr2 idx2 _)) - // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) - // result: (MOVDconst [0]) + // match: (MOVWstoreidx ptr (ADDconst [4] idx) (SRLconst [32] w) x:(MOVWstoreidx ptr idx w mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVDstoreidx ptr idx w mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] - idx := v.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64ADDconst { + break + } + if v_1.AuxInt != 4 { + break + } + idx := v_1.Args[0] v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWstorezeroidx { + if v_2.Op != OpARM64SRLconst { break } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + if v_2.AuxInt != 32 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + w := v_2.Args[0] + x := v.Args[3] + if x.Op != OpARM64MOVWstoreidx { + break + } + _ = x.Args[3] + if ptr != x.Args[0] { + break + } + if idx != x.Args[1] { + break + } + if w != x.Args[2] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && clobber(x)) { + break + } + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(w) + v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVWUloadidx4_0(v *Value) bool { - // match: (MOVWUloadidx4 ptr (MOVDconst [c]) mem) +func rewriteValueARM64_OpARM64MOVWstoreidx4_0(v *Value) bool { + // match: (MOVWstoreidx4 ptr (MOVDconst [c]) val mem) // cond: - // result: (MOVWUload [c<<2] ptr mem) + // result: (MOVWstore [c<<2] ptr val mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVWUload) + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVWstore) v.AuxInt = c << 2 v.AddArg(ptr) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWUloadidx4 ptr idx (MOVWstorezeroidx4 ptr2 idx2 _)) - // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) - // result: (MOVDconst [0]) + // match: (MOVWstoreidx4 ptr idx (MOVDconst [0]) mem) + // cond: + // result: (MOVWstorezeroidx4 ptr idx mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] idx := v.Args[1] v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWstorezeroidx4 { + if v_2.Op != OpARM64MOVDconst { break } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { + if v_2.AuxInt != 0 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + mem := v.Args[3] + v.reset(OpARM64MOVWstorezeroidx4) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVWUreg_0(v *Value) bool { - // match: (MOVWUreg x:(MOVBUload _ _)) + // match: (MOVWstoreidx4 ptr idx (MOVWreg x) mem) // cond: - // result: (MOVDreg x) + // result: (MOVWstoreidx4 ptr idx x mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVBUload { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWreg { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx4) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(x) + v.AddArg(mem) return true } - // match: (MOVWUreg x:(MOVHUload _ _)) + // match: (MOVWstoreidx4 ptr idx (MOVWUreg x) mem) // cond: - // result: (MOVDreg x) + // result: (MOVWstoreidx4 ptr idx x mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVHUload { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWUreg { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx4) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(x) + v.AddArg(mem) return true } - // match: (MOVWUreg x:(MOVWUload _ _)) - // cond: - // result: (MOVDreg x) + return false +} +func rewriteValueARM64_OpARM64MOVWstorezero_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVWstorezero [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWstorezero [off1+off2] {sym} ptr mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVWUload { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVWstorezero) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) return true } - // match: (MOVWUreg x:(MOVBUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MOVWstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVBUloadidx { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + v.reset(OpARM64MOVWstorezero) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) return true } - // match: (MOVWUreg x:(MOVHUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MOVWstorezero [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVWstorezeroidx ptr idx mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVHUloadidx { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWUreg x:(MOVWUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVWUloadidx { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + v.reset(OpARM64MOVWstorezeroidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) return true } - // match: (MOVWUreg x:(MOVHUloadidx2 _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MOVWstorezero [off] {sym} (ADDshiftLL [2] ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVWstorezeroidx4 ptr idx mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVHUloadidx2 { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWUreg x:(MOVWUloadidx4 _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVWUloadidx4 { + if v_0.AuxInt != 2 { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWUreg x:(MOVBUreg _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBUreg { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) + v.reset(OpARM64MOVWstorezeroidx4) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) return true } - // match: (MOVWUreg x:(MOVHUreg _)) - // cond: - // result: (MOVDreg x) + // match: (MOVWstorezero [i] {s} ptr0 x:(MOVWstorezero [j] {s} ptr1 mem)) + // cond: x.Uses == 1 && areAdjacentOffsets(i,j,4) && is32Bit(min(i,j)) && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVDstorezero [min(i,j)] {s} ptr0 mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVHUreg { + i := v.AuxInt + s := v.Aux + _ = v.Args[1] + ptr0 := v.Args[0] + x := v.Args[1] + if x.Op != OpARM64MOVWstorezero { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVWUreg_10(v *Value) bool { - // match: (MOVWUreg x:(MOVWUreg _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVWUreg { + j := x.AuxInt + if x.Aux != s { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWUreg (ANDconst [c] x)) - // cond: - // result: (ANDconst [c&(1<<32-1)] x) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64ANDconst { + _ = x.Args[1] + ptr1 := x.Args[0] + mem := x.Args[1] + if !(x.Uses == 1 && areAdjacentOffsets(i, j, 4) && is32Bit(min(i, j)) && isSamePtr(ptr0, ptr1) && clobber(x)) { break } - c := v_0.AuxInt - x := v_0.Args[0] - v.reset(OpARM64ANDconst) - v.AuxInt = c & (1<<32 - 1) - v.AddArg(x) + v.reset(OpARM64MOVDstorezero) + v.AuxInt = min(i, j) + v.Aux = s + v.AddArg(ptr0) + v.AddArg(mem) return true } - // match: (MOVWUreg (MOVDconst [c])) - // cond: - // result: (MOVDconst [int64(uint32(c))]) + // match: (MOVWstorezero [4] {s} (ADD ptr0 idx0) x:(MOVWstorezeroidx ptr1 idx1 mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVDstorezeroidx ptr1 idx1 mem) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v.AuxInt != 4 { break } - c := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(uint32(c)) - return true - } - // match: (MOVWUreg (SLLconst [sc] x)) - // cond: isARM64BFMask(sc, 1<<32-1, sc) - // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc))] x) - for { + s := v.Aux + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_0.Op != OpARM64ADD { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<32-1, sc)) { + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + x := v.Args[1] + if x.Op != OpARM64MOVWstorezeroidx { break } - v.reset(OpARM64UBFIZ) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc)) - v.AddArg(x) + _ = x.Args[2] + ptr1 := x.Args[0] + idx1 := x.Args[1] + mem := x.Args[2] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstorezeroidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(mem) return true } - // match: (MOVWUreg (SRLconst [sc] x)) - // cond: isARM64BFMask(sc, 1<<32-1, 0) - // result: (UBFX [arm64BFAuxInt(sc, 32)] x) + // match: (MOVWstorezero [4] {s} (ADDshiftLL [2] ptr0 idx0) x:(MOVWstorezeroidx4 ptr1 idx1 mem)) + // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) + // result: (MOVDstorezeroidx ptr1 (SLLconst [2] idx1) mem) for { + if v.AuxInt != 4 { + break + } + s := v.Aux + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { + if v_0.Op != OpARM64ADDshiftLL { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<32-1, 0)) { + if v_0.AuxInt != 2 { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc, 32) - v.AddArg(x) + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + x := v.Args[1] + if x.Op != OpARM64MOVWstorezeroidx4 { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + idx1 := x.Args[1] + mem := x.Args[2] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstorezeroidx) + v.AddArg(ptr1) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) + v0.AuxInt = 2 + v0.AddArg(idx1) + v.AddArg(v0) + v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVWload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVWload [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWload [off1+off2] {sym} ptr mem) +func rewriteValueARM64_OpARM64MOVWstorezeroidx_0(v *Value) bool { + // match: (MOVWstorezeroidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVWstorezero [c] ptr mem) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { - break - } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVWload) - v.AuxInt = off1 + off2 - v.Aux = sym + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVWstorezero) + v.AuxInt = c v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVWload [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVWloadidx ptr idx mem) + // match: (MOVWstorezeroidx (MOVDconst [c]) idx mem) + // cond: + // result: (MOVWstorezero [c] idx mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVWloadidx) - v.AddArg(ptr) + c := v_0.AuxInt + idx := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVWstorezero) + v.AuxInt = c v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWload [off] {sym} (ADDshiftLL [2] ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVWloadidx4 ptr idx mem) + // match: (MOVWstorezeroidx ptr (SLLconst [2] idx) mem) + // cond: + // result: (MOVWstorezeroidx4 ptr idx mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { - break - } - if v_0.AuxInt != 2 { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SLLconst { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + if v_1.AuxInt != 2 { break } - v.reset(OpARM64MOVWloadidx4) + idx := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVWstorezeroidx4) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // match: (MOVWstorezeroidx (SLLconst [2] idx) ptr mem) + // cond: + // result: (MOVWstorezeroidx4 ptr idx mem) for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + if v_0.Op != OpARM64SLLconst { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_0.AuxInt != 2 { break } - v.reset(OpARM64MOVWload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) + idx := v_0.Args[0] + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVWstorezeroidx4) v.AddArg(ptr) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) - // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) - // result: (MOVDconst [0]) + // match: (MOVWstorezeroidx ptr (ADDconst [4] idx) x:(MOVWstorezeroidx ptr idx mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVDstorezeroidx ptr idx mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWstorezero { + if v_1.Op != OpARM64ADDconst { break } - off2 := v_1.AuxInt - sym2 := v_1.Aux - _ = v_1.Args[1] - ptr2 := v_1.Args[0] - if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + if v_1.AuxInt != 4 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + idx := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstorezeroidx { + break + } + _ = x.Args[2] + if ptr != x.Args[0] { + break + } + if idx != x.Args[1] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && clobber(x)) { + break + } + v.reset(OpARM64MOVDstorezeroidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVWloadidx_0(v *Value) bool { - // match: (MOVWloadidx ptr (MOVDconst [c]) mem) +func rewriteValueARM64_OpARM64MOVWstorezeroidx4_0(v *Value) bool { + // match: (MOVWstorezeroidx4 ptr (MOVDconst [c]) mem) // cond: - // result: (MOVWload [c] ptr mem) + // result: (MOVWstorezero [c<<2] ptr mem) for { _ = v.Args[2] ptr := v.Args[0] @@ -14307,2852 +16733,2271 @@ func rewriteValueARM64_OpARM64MOVWloadidx_0(v *Value) bool { } c := v_1.AuxInt mem := v.Args[2] - v.reset(OpARM64MOVWload) - v.AuxInt = c + v.reset(OpARM64MOVWstorezero) + v.AuxInt = c << 2 v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVWloadidx (MOVDconst [c]) ptr mem) + return false +} +func rewriteValueARM64_OpARM64MUL_0(v *Value) bool { + // match: (MUL (NEG x) y) // cond: - // result: (MOVWload [c] ptr mem) + // result: (MNEG x y) for { - _ = v.Args[2] + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64NEG { + break + } + x := v_0.Args[0] + y := v.Args[1] + v.reset(OpARM64MNEG) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (MUL y (NEG x)) + // cond: + // result: (MNEG x y) + for { + _ = v.Args[1] + y := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64NEG { + break + } + x := v_1.Args[0] + v.reset(OpARM64MNEG) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (MUL x (MOVDconst [-1])) + // cond: + // result: (NEG x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + if v_1.AuxInt != -1 { + break + } + v.reset(OpARM64NEG) + v.AddArg(x) + return true + } + // match: (MUL (MOVDconst [-1]) x) + // cond: + // result: (NEG x) + for { + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVWload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + if v_0.AuxInt != -1 { + break + } + x := v.Args[1] + v.reset(OpARM64NEG) + v.AddArg(x) return true } - // match: (MOVWloadidx ptr (SLLconst [2] idx) mem) + // match: (MUL _ (MOVDconst [0])) // cond: - // result: (MOVWloadidx4 ptr idx mem) + // result: (MOVDconst [0]) for { - _ = v.Args[2] - ptr := v.Args[0] + _ = v.Args[1] v_1 := v.Args[1] - if v_1.Op != OpARM64SLLconst { + if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 2 { + if v_1.AuxInt != 0 { break } - idx := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVWloadidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVWloadidx (SLLconst [2] idx) ptr mem) + // match: (MUL (MOVDconst [0]) _) // cond: - // result: (MOVWloadidx4 ptr idx mem) + // result: (MOVDconst [0]) for { - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_0.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != 2 { + if v_0.AuxInt != 0 { break } - idx := v_0.Args[0] - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVWloadidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (MUL x (MOVDconst [1])) + // cond: + // result: x + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + if v_1.AuxInt != 1 { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - // match: (MOVWloadidx ptr idx (MOVWstorezeroidx ptr2 idx2 _)) - // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) - // result: (MOVDconst [0]) + // match: (MUL (MOVDconst [1]) x) + // cond: + // result: x for { - _ = v.Args[2] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWstorezeroidx { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + if v_0.AuxInt != 1 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + x := v.Args[1] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64MOVWloadidx4_0(v *Value) bool { - // match: (MOVWloadidx4 ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVWload [c<<2] ptr mem) + // match: (MUL x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (SLLconst [log2(c)] x) for { - _ = v.Args[2] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVWload) - v.AuxInt = c << 2 - v.AddArg(ptr) - v.AddArg(mem) + if !(isPowerOfTwo(c)) { + break + } + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c) + v.AddArg(x) return true } - // match: (MOVWloadidx4 ptr idx (MOVWstorezeroidx4 ptr2 idx2 _)) - // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) - // result: (MOVDconst [0]) + // match: (MUL (MOVDconst [c]) x) + // cond: isPowerOfTwo(c) + // result: (SLLconst [log2(c)] x) for { - _ = v.Args[2] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWstorezeroidx4 { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c)) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c) + v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64MOVWreg_0(v *Value) bool { - // match: (MOVWreg x:(MOVBload _ _)) - // cond: - // result: (MOVDreg x) +func rewriteValueARM64_OpARM64MUL_10(v *Value) bool { + b := v.Block + _ = b + // match: (MUL x (MOVDconst [c])) + // cond: isPowerOfTwo(c-1) && c >= 3 + // result: (ADDshiftLL x x [log2(c-1)]) for { + _ = v.Args[1] x := v.Args[0] - if x.Op != OpARM64MOVBload { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) + c := v_1.AuxInt + if !(isPowerOfTwo(c-1) && c >= 3) { + break + } + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c - 1) + v.AddArg(x) v.AddArg(x) return true } - // match: (MOVWreg x:(MOVBUload _ _)) - // cond: - // result: (MOVDreg x) + // match: (MUL (MOVDconst [c]) x) + // cond: isPowerOfTwo(c-1) && c >= 3 + // result: (ADDshiftLL x x [log2(c-1)]) for { - x := v.Args[0] - if x.Op != OpARM64MOVBUload { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c-1) && c >= 3) { + break + } + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c - 1) + v.AddArg(x) v.AddArg(x) return true } - // match: (MOVWreg x:(MOVHload _ _)) - // cond: - // result: (MOVDreg x) + // match: (MUL x (MOVDconst [c])) + // cond: isPowerOfTwo(c+1) && c >= 7 + // result: (ADDshiftLL (NEG x) x [log2(c+1)]) for { + _ = v.Args[1] x := v.Args[0] - if x.Op != OpARM64MOVHload { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) + c := v_1.AuxInt + if !(isPowerOfTwo(c+1) && c >= 7) { + break + } + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c + 1) + v0 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v0.AddArg(x) + v.AddArg(v0) v.AddArg(x) return true } - // match: (MOVWreg x:(MOVHUload _ _)) - // cond: - // result: (MOVDreg x) + // match: (MUL (MOVDconst [c]) x) + // cond: isPowerOfTwo(c+1) && c >= 7 + // result: (ADDshiftLL (NEG x) x [log2(c+1)]) for { - x := v.Args[0] - if x.Op != OpARM64MOVHUload { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c+1) && c >= 7) { + break + } + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c + 1) + v0 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v0.AddArg(x) + v.AddArg(v0) v.AddArg(x) return true } - // match: (MOVWreg x:(MOVWload _ _)) - // cond: - // result: (MOVDreg x) + // match: (MUL x (MOVDconst [c])) + // cond: c%3 == 0 && isPowerOfTwo(c/3) + // result: (SLLconst [log2(c/3)] (ADDshiftLL x x [1])) for { + _ = v.Args[1] x := v.Args[0] - if x.Op != OpARM64MOVWload { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_1.AuxInt + if !(c%3 == 0 && isPowerOfTwo(c/3)) { + break + } + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 1 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWreg x:(MOVBloadidx _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MUL (MOVDconst [c]) x) + // cond: c%3 == 0 && isPowerOfTwo(c/3) + // result: (SLLconst [log2(c/3)] (ADDshiftLL x x [1])) for { - x := v.Args[0] - if x.Op != OpARM64MOVBloadidx { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_0.AuxInt + x := v.Args[1] + if !(c%3 == 0 && isPowerOfTwo(c/3)) { + break + } + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 1 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWreg x:(MOVBUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MUL x (MOVDconst [c])) + // cond: c%5 == 0 && isPowerOfTwo(c/5) + // result: (SLLconst [log2(c/5)] (ADDshiftLL x x [2])) for { + _ = v.Args[1] x := v.Args[0] - if x.Op != OpARM64MOVBUloadidx { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_1.AuxInt + if !(c%5 == 0 && isPowerOfTwo(c/5)) { + break + } + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 5) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWreg x:(MOVHloadidx _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MUL (MOVDconst [c]) x) + // cond: c%5 == 0 && isPowerOfTwo(c/5) + // result: (SLLconst [log2(c/5)] (ADDshiftLL x x [2])) for { - x := v.Args[0] - if x.Op != OpARM64MOVHloadidx { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_0.AuxInt + x := v.Args[1] + if !(c%5 == 0 && isPowerOfTwo(c/5)) { + break + } + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 5) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWreg x:(MOVHUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MUL x (MOVDconst [c])) + // cond: c%7 == 0 && isPowerOfTwo(c/7) + // result: (SLLconst [log2(c/7)] (ADDshiftLL (NEG x) x [3])) for { + _ = v.Args[1] x := v.Args[0] - if x.Op != OpARM64MOVHUloadidx { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_1.AuxInt + if !(c%7 == 0 && isPowerOfTwo(c/7)) { + break + } + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWreg x:(MOVWloadidx _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MUL (MOVDconst [c]) x) + // cond: c%7 == 0 && isPowerOfTwo(c/7) + // result: (SLLconst [log2(c/7)] (ADDshiftLL (NEG x) x [3])) for { - x := v.Args[0] - if x.Op != OpARM64MOVWloadidx { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_0.AuxInt + x := v.Args[1] + if !(c%7 == 0 && isPowerOfTwo(c/7)) { + break + } + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) return true } return false } -func rewriteValueARM64_OpARM64MOVWreg_10(v *Value) bool { - // match: (MOVWreg x:(MOVHloadidx2 _ _ _)) - // cond: - // result: (MOVDreg x) +func rewriteValueARM64_OpARM64MUL_20(v *Value) bool { + b := v.Block + _ = b + // match: (MUL x (MOVDconst [c])) + // cond: c%9 == 0 && isPowerOfTwo(c/9) + // result: (SLLconst [log2(c/9)] (ADDshiftLL x x [3])) for { + _ = v.Args[1] x := v.Args[0] - if x.Op != OpARM64MOVHloadidx2 { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVHUloadidx2 _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHUloadidx2 { + c := v_1.AuxInt + if !(c%9 == 0 && isPowerOfTwo(c/9)) { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 9) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWreg x:(MOVWloadidx4 _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MUL (MOVDconst [c]) x) + // cond: c%9 == 0 && isPowerOfTwo(c/9) + // result: (SLLconst [log2(c/9)] (ADDshiftLL x x [3])) for { - x := v.Args[0] - if x.Op != OpARM64MOVWloadidx4 { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_0.AuxInt + x := v.Args[1] + if !(c%9 == 0 && isPowerOfTwo(c/9)) { + break + } + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 9) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWreg x:(MOVBreg _)) + // match: (MUL (MOVDconst [c]) (MOVDconst [d])) // cond: - // result: (MOVDreg x) + // result: (MOVDconst [c*d]) for { - x := v.Args[0] - if x.Op != OpARM64MOVBreg { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = c * d return true } - // match: (MOVWreg x:(MOVBUreg _)) + // match: (MUL (MOVDconst [d]) (MOVDconst [c])) // cond: - // result: (MOVDreg x) + // result: (MOVDconst [c*d]) for { - x := v.Args[0] - if x.Op != OpARM64MOVBUreg { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) + d := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = c * d return true } - // match: (MOVWreg x:(MOVHreg _)) + return false +} +func rewriteValueARM64_OpARM64MULW_0(v *Value) bool { + // match: (MULW (NEG x) y) // cond: - // result: (MOVDreg x) + // result: (MNEGW x y) for { - x := v.Args[0] - if x.Op != OpARM64MOVHreg { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64NEG { break } - v.reset(OpARM64MOVDreg) + x := v_0.Args[0] + y := v.Args[1] + v.reset(OpARM64MNEGW) v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVWreg x:(MOVHreg _)) + // match: (MULW y (NEG x)) // cond: - // result: (MOVDreg x) + // result: (MNEGW x y) for { - x := v.Args[0] - if x.Op != OpARM64MOVHreg { + _ = v.Args[1] + y := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64NEG { break } - v.reset(OpARM64MOVDreg) + x := v_1.Args[0] + v.reset(OpARM64MNEGW) v.AddArg(x) + v.AddArg(y) return true } - // match: (MOVWreg x:(MOVWreg _)) - // cond: - // result: (MOVDreg x) + // match: (MULW x (MOVDconst [c])) + // cond: int32(c)==-1 + // result: (NEG x) for { + _ = v.Args[1] x := v.Args[0] - if x.Op != OpARM64MOVWreg { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDreg) + c := v_1.AuxInt + if !(int32(c) == -1) { + break + } + v.reset(OpARM64NEG) v.AddArg(x) return true } - // match: (MOVWreg (MOVDconst [c])) - // cond: - // result: (MOVDconst [int64(int32(c))]) + // match: (MULW (MOVDconst [c]) x) + // cond: int32(c)==-1 + // result: (NEG x) for { + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(int32(c)) - return true - } - // match: (MOVWreg (SLLconst [lc] x)) - // cond: lc < 32 - // result: (SBFIZ [arm64BFAuxInt(lc, 32-lc)] x) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { - break - } - lc := v_0.AuxInt - x := v_0.Args[0] - if !(lc < 32) { + x := v.Args[1] + if !(int32(c) == -1) { break } - v.reset(OpARM64SBFIZ) - v.AuxInt = arm64BFAuxInt(lc, 32-lc) + v.reset(OpARM64NEG) v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64MOVWstore_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVWstore [off1] {sym} (ADDconst [off2] ptr) val mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWstore [off1+off2] {sym} ptr val mem) + // match: (MULW _ (MOVDconst [c])) + // cond: int32(c)==0 + // result: (MOVDconst [0]) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + _ = v.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_1.AuxInt + if !(int32(c) == 0) { break } - v.reset(OpARM64MOVWstore) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVWstore [off] {sym} (ADD ptr idx) val mem) - // cond: off == 0 && sym == nil - // result: (MOVWstoreidx ptr idx val mem) + // match: (MULW (MOVDconst [c]) _) + // cond: int32(c)==0 + // result: (MOVDconst [0]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + if v_0.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - val := v.Args[1] - mem := v.Args[2] - if !(off == 0 && sym == nil) { + c := v_0.AuxInt + if !(int32(c) == 0) { break } - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVWstore [off] {sym} (ADDshiftLL [2] ptr idx) val mem) - // cond: off == 0 && sym == nil - // result: (MOVWstoreidx4 ptr idx val mem) + // match: (MULW x (MOVDconst [c])) + // cond: int32(c)==1 + // result: x for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { - break - } - if v_0.AuxInt != 2 { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - val := v.Args[1] - mem := v.Args[2] - if !(off == 0 && sym == nil) { + c := v_1.AuxInt + if !(int32(c) == 1) { break } - v.reset(OpARM64MOVWstoreidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - // match: (MOVWstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + // match: (MULW (MOVDconst [c]) x) + // cond: int32(c)==1 + // result: x for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + if v_0.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_0.AuxInt + x := v.Args[1] + if !(int32(c) == 1) { break } - v.reset(OpARM64MOVWstore) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - // match: (MOVWstore [off] {sym} ptr (MOVDconst [0]) mem) - // cond: - // result: (MOVWstorezero [off] {sym} ptr mem) + // match: (MULW x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (SLLconst [log2(c)] x) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 0 { + c := v_1.AuxInt + if !(isPowerOfTwo(c)) { break } - mem := v.Args[2] - v.reset(OpARM64MOVWstorezero) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c) + v.AddArg(x) return true } - // match: (MOVWstore [off] {sym} ptr (MOVWreg x) mem) - // cond: - // result: (MOVWstore [off] {sym} ptr x mem) + // match: (MULW (MOVDconst [c]) x) + // cond: isPowerOfTwo(c) + // result: (SLLconst [log2(c)] x) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWreg { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVWstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c)) { + break + } + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c) v.AddArg(x) - v.AddArg(mem) return true } - // match: (MOVWstore [off] {sym} ptr (MOVWUreg x) mem) - // cond: - // result: (MOVWstore [off] {sym} ptr x mem) + return false +} +func rewriteValueARM64_OpARM64MULW_10(v *Value) bool { + b := v.Block + _ = b + // match: (MULW x (MOVDconst [c])) + // cond: isPowerOfTwo(c-1) && int32(c) >= 3 + // result: (ADDshiftLL x x [log2(c-1)]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWUreg { + if v_1.Op != OpARM64MOVDconst { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVWstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) + c := v_1.AuxInt + if !(isPowerOfTwo(c-1) && int32(c) >= 3) { + break + } + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c - 1) + v.AddArg(x) v.AddArg(x) - v.AddArg(mem) return true } - // match: (MOVWstore [i] {s} ptr0 (SRLconst [32] w) x:(MOVWstore [i-4] {s} ptr1 w mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVDstore [i-4] {s} ptr0 w mem) + // match: (MULW (MOVDconst [c]) x) + // cond: isPowerOfTwo(c-1) && int32(c) >= 3 + // result: (ADDshiftLL x x [log2(c-1)]) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - if v_1.AuxInt != 32 { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstore { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c-1) && int32(c) >= 3) { break } - if x.AuxInt != i-4 { + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c - 1) + v.AddArg(x) + v.AddArg(x) + return true + } + // match: (MULW x (MOVDconst [c])) + // cond: isPowerOfTwo(c+1) && int32(c) >= 7 + // result: (ADDshiftLL (NEG x) x [log2(c+1)]) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if x.Aux != s { + c := v_1.AuxInt + if !(isPowerOfTwo(c+1) && int32(c) >= 7) { break } - _ = x.Args[2] - ptr1 := x.Args[0] - if w != x.Args[1] { + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c + 1) + v0 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(x) + return true + } + // match: (MULW (MOVDconst [c]) x) + // cond: isPowerOfTwo(c+1) && int32(c) >= 7 + // result: (ADDshiftLL (NEG x) x [log2(c+1)]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c+1) && int32(c) >= 7) { break } - v.reset(OpARM64MOVDstore) - v.AuxInt = i - 4 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c + 1) + v0 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(x) return true } - // match: (MOVWstore [4] {s} (ADD ptr0 idx0) (SRLconst [32] w) x:(MOVWstoreidx ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVDstoreidx ptr1 idx1 w mem) + // match: (MULW x (MOVDconst [c])) + // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) + // result: (SLLconst [log2(c/3)] (ADDshiftLL x x [1])) for { - if v.AuxInt != 4 { - break - } - s := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + c := v_1.AuxInt + if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { break } - if v_1.AuxInt != 32 { + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 1 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MULW (MOVDconst [c]) x) + // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) + // result: (SLLconst [log2(c/3)] (ADDshiftLL x x [1])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstoreidx { + c := v_0.AuxInt + x := v.Args[1] + if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 1 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MULW x (MOVDconst [c])) + // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) + // result: (SLLconst [log2(c/5)] (ADDshiftLL x x [2])) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + c := v_1.AuxInt + if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { break } - v.reset(OpARM64MOVDstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 5) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstore [4] {s} (ADDshiftLL [2] ptr0 idx0) (SRLconst [32] w) x:(MOVWstoreidx4 ptr1 idx1 w mem)) - // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVDstoreidx ptr1 (SLLconst [2] idx1) w mem) + // match: (MULW (MOVDconst [c]) x) + // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) + // result: (SLLconst [log2(c/5)] (ADDshiftLL x x [2])) for { - if v.AuxInt != 4 { - break - } - s := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { + if v_0.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != 2 { + c := v_0.AuxInt + x := v.Args[1] + if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 5) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MULW x (MOVDconst [c])) + // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) + // result: (SLLconst [log2(c/7)] (ADDshiftLL (NEG x) x [3])) + for { + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - if v_1.AuxInt != 32 { + if v_1.Op != OpARM64MOVDconst { break } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstoreidx4 { + c := v_1.AuxInt + if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - if w != x.Args[2] { + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MULW (MOVDconst [c]) x) + // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) + // result: (SLLconst [log2(c/7)] (ADDshiftLL (NEG x) x [3])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + c := v_0.AuxInt + x := v.Args[1] + if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { break } - v.reset(OpARM64MOVDstoreidx) - v.AddArg(ptr1) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) - v0.AuxInt = 2 - v0.AddArg(idx1) + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) v.AddArg(v0) - v.AddArg(w) - v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVWstore_10(v *Value) bool { +func rewriteValueARM64_OpARM64MULW_20(v *Value) bool { b := v.Block _ = b - // match: (MOVWstore [i] {s} ptr0 (SRLconst [j] w) x:(MOVWstore [i-4] {s} ptr1 w0:(SRLconst [j-32] w) mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVDstore [i-4] {s} ptr0 w0 mem) + // match: (MULW x (MOVDconst [c])) + // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) + // result: (SLLconst [log2(c/9)] (ADDshiftLL x x [3])) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[2] - ptr0 := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstore { - break - } - if x.AuxInt != i-4 { - break - } - if x.Aux != s { - break - } - _ = x.Args[2] - ptr1 := x.Args[0] - w0 := x.Args[1] - if w0.Op != OpARM64SRLconst { - break - } - if w0.AuxInt != j-32 { - break - } - if w != w0.Args[0] { + if v_1.Op != OpARM64MOVDconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + c := v_1.AuxInt + if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { break } - v.reset(OpARM64MOVDstore) - v.AuxInt = i - 4 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w0) - v.AddArg(mem) + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 9) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstore [4] {s} (ADD ptr0 idx0) (SRLconst [j] w) x:(MOVWstoreidx ptr1 idx1 w0:(SRLconst [j-32] w) mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVDstoreidx ptr1 idx1 w0 mem) + // match: (MULW (MOVDconst [c]) x) + // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) + // result: (SLLconst [log2(c/9)] (ADDshiftLL x x [3])) for { - if v.AuxInt != 4 { - break - } - s := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + if v_0.Op != OpARM64MOVDconst { break } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstoreidx { + c := v_0.AuxInt + x := v.Args[1] + if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - w0 := x.Args[2] - if w0.Op != OpARM64SRLconst { + v.reset(OpARM64SLLconst) + v.AuxInt = log2(c / 9) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MULW (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [int64(int32(c)*int32(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if w0.AuxInt != j-32 { + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if w != w0.Args[0] { + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(int32(c) * int32(d)) + return true + } + // match: (MULW (MOVDconst [d]) (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(int32(c)*int32(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + d := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w0) - v.AddArg(mem) + c := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(int32(c) * int32(d)) return true } - // match: (MOVWstore [4] {s} (ADDshiftLL [2] ptr0 idx0) (SRLconst [j] w) x:(MOVWstoreidx4 ptr1 idx1 w0:(SRLconst [j-32] w) mem)) - // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVDstoreidx ptr1 (SLLconst [2] idx1) w0 mem) + return false +} +func rewriteValueARM64_OpARM64MVN_0(v *Value) bool { + // match: (MVN (MOVDconst [c])) + // cond: + // result: (MOVDconst [^c]) for { - if v.AuxInt != 4 { - break - } - s := v.Aux - _ = v.Args[2] v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { + if v_0.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != 2 { + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = ^c + return true + } + return false +} +func rewriteValueARM64_OpARM64NEG_0(v *Value) bool { + // match: (NEG (MUL x y)) + // cond: + // result: (MNEG x y) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MUL { break } _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + x := v_0.Args[0] + y := v_0.Args[1] + v.reset(OpARM64MNEG) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (NEG (MULW x y)) + // cond: + // result: (MNEGW x y) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MULW { break } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstoreidx4 { + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + v.reset(OpARM64MNEGW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (NEG (MOVDconst [c])) + // cond: + // result: (MOVDconst [-c]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - w0 := x.Args[2] - if w0.Op != OpARM64SRLconst { + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = -c + return true + } + return false +} +func rewriteValueARM64_OpARM64NotEqual_0(v *Value) bool { + // match: (NotEqual (FlagEQ)) + // cond: + // result: (MOVDconst [0]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagEQ { break } - if w0.AuxInt != j-32 { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (NotEqual (FlagLT_ULT)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_ULT { break } - if w != w0.Args[0] { + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 + return true + } + // match: (NotEqual (FlagLT_UGT)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagLT_UGT { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 + return true + } + // match: (NotEqual (FlagGT_ULT)) + // cond: + // result: (MOVDconst [1]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_ULT { break } - v.reset(OpARM64MOVDstoreidx) - v.AddArg(ptr1) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) - v0.AuxInt = 2 - v0.AddArg(idx1) - v.AddArg(v0) - v.AddArg(w0) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - return false -} -func rewriteValueARM64_OpARM64MOVWstoreidx_0(v *Value) bool { - // match: (MOVWstoreidx ptr (MOVDconst [c]) val mem) + // match: (NotEqual (FlagGT_UGT)) // cond: - // result: (MOVWstore [c] ptr val mem) + // result: (MOVDconst [1]) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64FlagGT_UGT { break } - c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVWstore) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 1 return true } - // match: (MOVWstoreidx (MOVDconst [c]) idx val mem) + // match: (NotEqual (InvertFlags x)) // cond: - // result: (MOVWstore [c] idx val mem) + // result: (NotEqual x) for { - _ = v.Args[3] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64InvertFlags { break } - c := v_0.AuxInt - idx := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVWstore) - v.AuxInt = c - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + x := v_0.Args[0] + v.reset(OpARM64NotEqual) + v.AddArg(x) return true } - // match: (MOVWstoreidx ptr (SLLconst [2] idx) val mem) + return false +} +func rewriteValueARM64_OpARM64OR_0(v *Value) bool { + // match: (OR x (MOVDconst [c])) // cond: - // result: (MOVWstoreidx4 ptr idx val mem) + // result: (ORconst [c] x) for { - _ = v.Args[3] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SLLconst { - break - } - if v_1.AuxInt != 2 { + if v_1.Op != OpARM64MOVDconst { break } - idx := v_1.Args[0] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + c := v_1.AuxInt + v.reset(OpARM64ORconst) + v.AuxInt = c + v.AddArg(x) return true } - // match: (MOVWstoreidx (SLLconst [2] idx) ptr val mem) + // match: (OR (MOVDconst [c]) x) // cond: - // result: (MOVWstoreidx4 ptr idx val mem) + // result: (ORconst [c] x) for { - _ = v.Args[3] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { - break - } - if v_0.AuxInt != 2 { + if v_0.Op != OpARM64MOVDconst { break } - idx := v_0.Args[0] - ptr := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64ORconst) + v.AuxInt = c + v.AddArg(x) return true } - // match: (MOVWstoreidx ptr idx (MOVDconst [0]) mem) + // match: (OR x x) // cond: - // result: (MOVWstorezeroidx ptr idx mem) + // result: x for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDconst { - break - } - if v_2.AuxInt != 0 { + _ = v.Args[1] + x := v.Args[0] + if x != v.Args[1] { break } - mem := v.Args[3] - v.reset(OpARM64MOVWstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - // match: (MOVWstoreidx ptr idx (MOVWreg x) mem) + // match: (OR x (MVN y)) // cond: - // result: (MOVWstoreidx ptr idx x mem) + // result: (ORN x y) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWreg { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MVN { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr) - v.AddArg(idx) + y := v_1.Args[0] + v.reset(OpARM64ORN) v.AddArg(x) - v.AddArg(mem) + v.AddArg(y) return true } - // match: (MOVWstoreidx ptr idx (MOVWUreg x) mem) + // match: (OR (MVN y) x) // cond: - // result: (MOVWstoreidx ptr idx x mem) + // result: (ORN x y) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWUreg { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MVN { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr) - v.AddArg(idx) + y := v_0.Args[0] + x := v.Args[1] + v.reset(OpARM64ORN) v.AddArg(x) - v.AddArg(mem) + v.AddArg(y) return true } - // match: (MOVWstoreidx ptr (ADDconst [4] idx) (SRLconst [32] w) x:(MOVWstoreidx ptr idx w mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVDstoreidx ptr idx w mem) + // match: (OR x0 x1:(SLLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (ORshiftLL x0 y [c]) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { - break - } - if v_1.AuxInt != 4 { - break - } - idx := v_1.Args[0] - v_2 := v.Args[2] - if v_2.Op != OpARM64SRLconst { - break - } - if v_2.AuxInt != 32 { - break - } - w := v_2.Args[0] - x := v.Args[3] - if x.Op != OpARM64MOVWstoreidx { - break - } - _ = x.Args[3] - if ptr != x.Args[0] { - break - } - if idx != x.Args[1] { - break - } - if w != x.Args[2] { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SLLconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && clobber(x)) { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - v.reset(OpARM64MOVDstoreidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(w) - v.AddArg(mem) + v.reset(OpARM64ORshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } - return false -} -func rewriteValueARM64_OpARM64MOVWstoreidx4_0(v *Value) bool { - // match: (MOVWstoreidx4 ptr (MOVDconst [c]) val mem) - // cond: - // result: (MOVWstore [c<<2] ptr val mem) + // match: (OR x1:(SLLconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (ORshiftLL x0 y [c]) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[1] + x1 := v.Args[0] + if x1.Op != OpARM64SLLconst { break } - c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVWstore) - v.AuxInt = c << 2 - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64ORshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } - // match: (MOVWstoreidx4 ptr idx (MOVDconst [0]) mem) - // cond: - // result: (MOVWstorezeroidx4 ptr idx mem) + // match: (OR x0 x1:(SRLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (ORshiftRL x0 y [c]) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDconst { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRLconst { break } - if v_2.AuxInt != 0 { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - mem := v.Args[3] - v.reset(OpARM64MOVWstorezeroidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64ORshiftRL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } - // match: (MOVWstoreidx4 ptr idx (MOVWreg x) mem) - // cond: - // result: (MOVWstoreidx4 ptr idx x mem) + // match: (OR x1:(SRLconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (ORshiftRL x0 y [c]) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWreg { + _ = v.Args[1] + x1 := v.Args[0] + if x1.Op != OpARM64SRLconst { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(x) - v.AddArg(mem) + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64ORshiftRL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } - // match: (MOVWstoreidx4 ptr idx (MOVWUreg x) mem) - // cond: - // result: (MOVWstoreidx4 ptr idx x mem) + // match: (OR x0 x1:(SRAconst [c] y)) + // cond: clobberIfDead(x1) + // result: (ORshiftRA x0 y [c]) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWUreg { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRAconst { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(x) - v.AddArg(mem) + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64ORshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64MOVWstorezero_0(v *Value) bool { +func rewriteValueARM64_OpARM64OR_10(v *Value) bool { b := v.Block _ = b - config := b.Func.Config - _ = config - // match: (MOVWstorezero [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWstorezero [off1+off2] {sym} ptr mem) + typ := &b.Func.Config.Types + _ = typ + // match: (OR x1:(SRAconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (ORshiftRA x0 y [c]) for { - off1 := v.AuxInt - sym := v.Aux _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + x1 := v.Args[0] + if x1.Op != OpARM64SRAconst { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { break } - v.reset(OpARM64MOVWstorezero) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64ORshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) return true } - // match: (MOVWstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // match: (OR (SLL x (ANDconst [63] y)) (CSEL0 {cc} (SRL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x (NEG y)) for { - off1 := v.AuxInt - sym1 := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + if v_0.Op != OpARM64SLL { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = v_0.Args[1] + x := v_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64MOVWstorezero) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVWstorezero [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVWstorezeroidx ptr idx mem) - for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + t := v_0_1.Type + if v_0_1.AuxInt != 63 { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + y := v_0_1.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64CSEL0 { break } - v.reset(OpARM64MOVWstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVWstorezero [off] {sym} (ADDshiftLL [2] ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVWstorezeroidx4 ptr idx mem) - for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { + if v_1.Type != typ.UInt64 { break } - if v_0.AuxInt != 2 { + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SRL { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + if v_1_0.Type != typ.UInt64 { break } - v.reset(OpARM64MOVWstorezeroidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVWstorezero [i] {s} ptr0 x:(MOVWstorezero [j] {s} ptr1 mem)) - // cond: x.Uses == 1 && areAdjacentOffsets(i,j,4) && is32Bit(min(i,j)) && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVDstorezero [min(i,j)] {s} ptr0 mem) - for { - i := v.AuxInt - s := v.Aux - _ = v.Args[1] - ptr0 := v.Args[0] - x := v.Args[1] - if x.Op != OpARM64MOVWstorezero { + _ = v_1_0.Args[1] + if x != v_1_0.Args[0] { break } - j := x.AuxInt - if x.Aux != s { + v_1_0_1 := v_1_0.Args[1] + if v_1_0_1.Op != OpARM64SUB { break } - _ = x.Args[1] - ptr1 := x.Args[0] - mem := x.Args[1] - if !(x.Uses == 1 && areAdjacentOffsets(i, j, 4) && is32Bit(min(i, j)) && isSamePtr(ptr0, ptr1) && clobber(x)) { + if v_1_0_1.Type != t { break } - v.reset(OpARM64MOVDstorezero) - v.AuxInt = min(i, j) - v.Aux = s - v.AddArg(ptr0) - v.AddArg(mem) - return true - } - // match: (MOVWstorezero [4] {s} (ADD ptr0 idx0) x:(MOVWstorezeroidx ptr1 idx1 mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVDstorezeroidx ptr1 idx1 mem) - for { - if v.AuxInt != 4 { + _ = v_1_0_1.Args[1] + v_1_0_1_0 := v_1_0_1.Args[0] + if v_1_0_1_0.Op != OpARM64MOVDconst { break } - s := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + if v_1_0_1_0.AuxInt != 64 { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - x := v.Args[1] - if x.Op != OpARM64MOVWstorezeroidx { + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { break } - _ = x.Args[2] - ptr1 := x.Args[0] - idx1 := x.Args[1] - mem := x.Args[2] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + if v_1_0_1_1.Type != t { break } - v.reset(OpARM64MOVDstorezeroidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(mem) - return true - } - // match: (MOVWstorezero [4] {s} (ADDshiftLL [2] ptr0 idx0) x:(MOVWstorezeroidx4 ptr1 idx1 mem)) - // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVDstorezeroidx ptr1 (SLLconst [2] idx1) mem) - for { - if v.AuxInt != 4 { + if v_1_0_1_1.AuxInt != 63 { break } - s := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { + if y != v_1_0_1_1.Args[0] { break } - if v_0.AuxInt != 2 { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64CMPconst { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - x := v.Args[1] - if x.Op != OpARM64MOVWstorezeroidx4 { + if v_1_1.AuxInt != 64 { break } - _ = x.Args[2] - ptr1 := x.Args[0] - idx1 := x.Args[1] - mem := x.Args[2] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { break } - v.reset(OpARM64MOVDstorezeroidx) - v.AddArg(ptr1) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) - v0.AuxInt = 2 - v0.AddArg(idx1) - v.AddArg(v0) - v.AddArg(mem) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVWstorezeroidx_0(v *Value) bool { - // match: (MOVWstorezeroidx ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVWstorezero [c] ptr mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_1_0.Type != t { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVWstorezero) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVWstorezeroidx (MOVDconst [c]) idx mem) - // cond: - // result: (MOVWstorezero [c] idx mem) - for { - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - idx := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVWstorezero) - v.AuxInt = c - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVWstorezeroidx ptr (SLLconst [2] idx) mem) - // cond: - // result: (MOVWstorezeroidx4 ptr idx mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SLLconst { + if v_1_1_0_0.AuxInt != 64 { + break + } + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { + break + } + if v_1_1_0_1.Type != t { + break + } + if v_1_1_0_1.AuxInt != 63 { break } - if v_1.AuxInt != 2 { + if y != v_1_1_0_1.Args[0] { break } - idx := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVWstorezeroidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64ROR) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) + v.AddArg(v0) return true } - // match: (MOVWstorezeroidx (SLLconst [2] idx) ptr mem) - // cond: - // result: (MOVWstorezeroidx4 ptr idx mem) + // match: (OR (CSEL0 {cc} (SRL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y)))) (SLL x (ANDconst [63] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x (NEG y)) for { - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_0.Op != OpARM64CSEL0 { break } - if v_0.AuxInt != 2 { + if v_0.Type != typ.UInt64 { break } - idx := v_0.Args[0] - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVWstorezeroidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVWstorezeroidx ptr (ADDconst [4] idx) x:(MOVWstorezeroidx ptr idx mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVDstorezeroidx ptr idx mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { + cc := v_0.Aux + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SRL { break } - if v_1.AuxInt != 4 { + if v_0_0.Type != typ.UInt64 { break } - idx := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstorezeroidx { + _ = v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { break } - _ = x.Args[2] - if ptr != x.Args[0] { + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { break } - if idx != x.Args[1] { + if v_0_0_1_0.AuxInt != 64 { break } - mem := x.Args[2] - if !(x.Uses == 1 && clobber(x)) { + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64MOVDstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVWstorezeroidx4_0(v *Value) bool { - // match: (MOVWstorezeroidx4 ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVWstorezero [c<<2] ptr mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0_0_1_1.Type != t { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVWstorezero) - v.AuxInt = c << 2 - v.AddArg(ptr) - v.AddArg(mem) - return true - } - return false -} -func rewriteValueARM64_OpARM64MUL_0(v *Value) bool { - // match: (MUL (NEG x) y) - // cond: - // result: (MNEG x y) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64NEG { + if v_0_0_1_1.AuxInt != 63 { break } - x := v_0.Args[0] - y := v.Args[1] - v.reset(OpARM64MNEG) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (MUL y (NEG x)) - // cond: - // result: (MNEG x y) - for { - _ = v.Args[1] - y := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64NEG { + y := v_0_0_1_1.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64CMPconst { break } - x := v_1.Args[0] - v.reset(OpARM64MNEG) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (MUL x (MOVDconst [-1])) - // cond: - // result: (NEG x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0_1.AuxInt != 64 { break } - if v_1.AuxInt != -1 { + v_0_1_0 := v_0_1.Args[0] + if v_0_1_0.Op != OpARM64SUB { break } - v.reset(OpARM64NEG) - v.AddArg(x) - return true - } - // match: (MUL (MOVDconst [-1]) x) - // cond: - // result: (NEG x) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_1_0.Type != t { break } - if v_0.AuxInt != -1 { + _ = v_0_1_0.Args[1] + v_0_1_0_0 := v_0_1_0.Args[0] + if v_0_1_0_0.Op != OpARM64MOVDconst { break } - x := v.Args[1] - v.reset(OpARM64NEG) - v.AddArg(x) - return true - } - // match: (MUL _ (MOVDconst [0])) - // cond: - // result: (MOVDconst [0]) - for { - _ = v.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0_1_0_0.AuxInt != 64 { break } - if v_1.AuxInt != 0 { + v_0_1_0_1 := v_0_1_0.Args[1] + if v_0_1_0_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (MUL (MOVDconst [0]) _) - // cond: - // result: (MOVDconst [0]) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_1_0_1.Type != t { break } - if v_0.AuxInt != 0 { + if v_0_1_0_1.AuxInt != 63 { + break + } + if y != v_0_1_0_1.Args[0] { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (MUL x (MOVDconst [1])) - // cond: - // result: x - for { - _ = v.Args[1] - x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64SLL { break } - if v_1.AuxInt != 1 { + _ = v_1.Args[1] + if x != v_1.Args[0] { break } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (MUL (MOVDconst [1]) x) - // cond: - // result: x - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64ANDconst { break } - if v_0.AuxInt != 1 { + if v_1_1.Type != t { break } - x := v.Args[1] - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (MUL x (MOVDconst [c])) - // cond: isPowerOfTwo(c) - // result: (SLLconst [log2(c)] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_1.AuxInt != 63 { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c)) { + if y != v_1_1.Args[0] { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c) + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64ROR) v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) + v.AddArg(v0) return true } - // match: (MUL (MOVDconst [c]) x) - // cond: isPowerOfTwo(c) - // result: (SLLconst [log2(c)] x) + // match: (OR (SRL x (ANDconst [63] y)) (CSEL0 {cc} (SLL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64SRL { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c)) { + if v_0.Type != typ.UInt64 { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64MUL_10(v *Value) bool { - b := v.Block - _ = b - // match: (MUL x (MOVDconst [c])) - // cond: isPowerOfTwo(c-1) && c >= 3 - // result: (ADDshiftLL x x [log2(c-1)]) - for { - _ = v.Args[1] - x := v.Args[0] + _ = v_0.Args[1] + x := v_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { + break + } + t := v_0_1.Type + if v_0_1.AuxInt != 63 { + break + } + y := v_0_1.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64CSEL0 { + break + } + if v_1.Type != typ.UInt64 { + break + } + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SLL { + break + } + _ = v_1_0.Args[1] + if x != v_1_0.Args[0] { + break + } + v_1_0_1 := v_1_0.Args[1] + if v_1_0_1.Op != OpARM64SUB { + break + } + if v_1_0_1.Type != t { + break + } + _ = v_1_0_1.Args[1] + v_1_0_1_0 := v_1_0_1.Args[0] + if v_1_0_1_0.Op != OpARM64MOVDconst { + break + } + if v_1_0_1_0.AuxInt != 64 { + break + } + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { + break + } + if v_1_0_1_1.Type != t { + break + } + if v_1_0_1_1.AuxInt != 63 { + break + } + if y != v_1_0_1_1.Args[0] { + break + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64CMPconst { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c-1) && c >= 3) { + if v_1_1.AuxInt != 64 { break } - v.reset(OpARM64ADDshiftLL) - v.AuxInt = log2(c - 1) - v.AddArg(x) - v.AddArg(x) - return true - } - // match: (MUL (MOVDconst [c]) x) - // cond: isPowerOfTwo(c-1) && c >= 3 - // result: (ADDshiftLL x x [log2(c-1)]) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c-1) && c >= 3) { + if v_1_1_0.Type != t { break } - v.reset(OpARM64ADDshiftLL) - v.AuxInt = log2(c - 1) - v.AddArg(x) - v.AddArg(x) - return true - } - // match: (MUL x (MOVDconst [c])) - // cond: isPowerOfTwo(c+1) && c >= 7 - // result: (ADDshiftLL (NEG x) x [log2(c+1)]) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c+1) && c >= 7) { + if v_1_1_0_0.AuxInt != 64 { break } - v.reset(OpARM64ADDshiftLL) - v.AuxInt = log2(c + 1) - v0 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v0.AddArg(x) - v.AddArg(v0) + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { + break + } + if v_1_1_0_1.Type != t { + break + } + if v_1_1_0_1.AuxInt != 63 { + break + } + if y != v_1_1_0_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64ROR) v.AddArg(x) + v.AddArg(y) return true } - // match: (MUL (MOVDconst [c]) x) - // cond: isPowerOfTwo(c+1) && c >= 7 - // result: (ADDshiftLL (NEG x) x [log2(c+1)]) + // match: (OR (CSEL0 {cc} (SLL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y)))) (SRL x (ANDconst [63] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64CSEL0 { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c+1) && c >= 7) { + if v_0.Type != typ.UInt64 { break } - v.reset(OpARM64ADDshiftLL) - v.AuxInt = log2(c + 1) - v0 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v0.AddArg(x) - v.AddArg(v0) - v.AddArg(x) - return true - } - // match: (MUL x (MOVDconst [c])) - // cond: c%3 == 0 && isPowerOfTwo(c/3) - // result: (SLLconst [log2(c/3)] (ADDshiftLL x x [1])) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + cc := v_0.Aux + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SLL { break } - c := v_1.AuxInt - if !(c%3 == 0 && isPowerOfTwo(c/3)) { + _ = v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 1 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MUL (MOVDconst [c]) x) - // cond: c%3 == 0 && isPowerOfTwo(c/3) - // result: (SLLconst [log2(c/3)] (ADDshiftLL x x [1])) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%3 == 0 && isPowerOfTwo(c/3)) { + if v_0_0_1_0.AuxInt != 64 { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 1 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MUL x (MOVDconst [c])) - // cond: c%5 == 0 && isPowerOfTwo(c/5) - // result: (SLLconst [log2(c/5)] (ADDshiftLL x x [2])) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { break } - c := v_1.AuxInt - if !(c%5 == 0 && isPowerOfTwo(c/5)) { + if v_0_0_1_1.Type != t { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 5) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MUL (MOVDconst [c]) x) - // cond: c%5 == 0 && isPowerOfTwo(c/5) - // result: (SLLconst [log2(c/5)] (ADDshiftLL x x [2])) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_0_1_1.AuxInt != 63 { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%5 == 0 && isPowerOfTwo(c/5)) { + y := v_0_0_1_1.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64CMPconst { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 5) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MUL x (MOVDconst [c])) - // cond: c%7 == 0 && isPowerOfTwo(c/7) - // result: (SLLconst [log2(c/7)] (ADDshiftLL (NEG x) x [3])) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0_1.AuxInt != 64 { break } - c := v_1.AuxInt - if !(c%7 == 0 && isPowerOfTwo(c/7)) { + v_0_1_0 := v_0_1.Args[0] + if v_0_1_0.Op != OpARM64SUB { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 7) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 3 - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MUL (MOVDconst [c]) x) - // cond: c%7 == 0 && isPowerOfTwo(c/7) - // result: (SLLconst [log2(c/7)] (ADDshiftLL (NEG x) x [3])) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_1_0.Type != t { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%7 == 0 && isPowerOfTwo(c/7)) { + _ = v_0_1_0.Args[1] + v_0_1_0_0 := v_0_1_0.Args[0] + if v_0_1_0_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 7) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 3 - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) - return true - } - return false -} -func rewriteValueARM64_OpARM64MUL_20(v *Value) bool { - b := v.Block - _ = b - // match: (MUL x (MOVDconst [c])) - // cond: c%9 == 0 && isPowerOfTwo(c/9) - // result: (SLLconst [log2(c/9)] (ADDshiftLL x x [3])) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0_1_0_0.AuxInt != 64 { break } - c := v_1.AuxInt - if !(c%9 == 0 && isPowerOfTwo(c/9)) { + v_0_1_0_1 := v_0_1_0.Args[1] + if v_0_1_0_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 9) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 3 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MUL (MOVDconst [c]) x) - // cond: c%9 == 0 && isPowerOfTwo(c/9) - // result: (SLLconst [log2(c/9)] (ADDshiftLL x x [3])) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_1_0_1.Type != t { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%9 == 0 && isPowerOfTwo(c/9)) { + if v_0_1_0_1.AuxInt != 63 { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 9) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 3 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MUL (MOVDconst [c]) (MOVDconst [d])) - // cond: - // result: (MOVDconst [c*d]) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if y != v_0_1_0_1.Args[0] { break } - c := v_0.AuxInt v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64SRL { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = c * d - return true - } - // match: (MUL (MOVDconst [d]) (MOVDconst [c])) - // cond: - // result: (MOVDconst [c*d]) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_1.Type != typ.UInt64 { + break + } + _ = v_1.Args[1] + if x != v_1.Args[0] { + break + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64ANDconst { + break + } + if v_1_1.Type != t { break } - d := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_1.AuxInt != 63 { break } - c := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = c * d - return true - } - return false -} -func rewriteValueARM64_OpARM64MULW_0(v *Value) bool { - // match: (MULW (NEG x) y) - // cond: - // result: (MNEGW x y) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64NEG { + if y != v_1_1.Args[0] { break } - x := v_0.Args[0] - y := v.Args[1] - v.reset(OpARM64MNEGW) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (MULW y (NEG x)) - // cond: - // result: (MNEGW x y) - for { - _ = v.Args[1] - y := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64NEG { + if !(cc.(Op) == OpARM64LessThanU) { break } - x := v_1.Args[0] - v.reset(OpARM64MNEGW) + v.reset(OpARM64ROR) v.AddArg(x) v.AddArg(y) return true } - // match: (MULW x (MOVDconst [c])) - // cond: int32(c)==-1 - // result: (NEG x) + // match: (OR (SLL x (ANDconst [31] y)) (CSEL0 {cc} (SRL (MOVWUreg x) (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x (NEG y)) for { _ = v.Args[1] - x := v.Args[0] + v_0 := v.Args[0] + if v_0.Op != OpARM64SLL { + break + } + _ = v_0.Args[1] + x := v_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { + break + } + t := v_0_1.Type + if v_0_1.AuxInt != 31 { + break + } + y := v_0_1.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64CSEL0 { break } - c := v_1.AuxInt - if !(int32(c) == -1) { + if v_1.Type != typ.UInt32 { break } - v.reset(OpARM64NEG) - v.AddArg(x) - return true - } - // match: (MULW (MOVDconst [c]) x) - // cond: int32(c)==-1 - // result: (NEG x) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SRL { break } - c := v_0.AuxInt - x := v.Args[1] - if !(int32(c) == -1) { + if v_1_0.Type != typ.UInt32 { break } - v.reset(OpARM64NEG) - v.AddArg(x) - return true - } - // match: (MULW _ (MOVDconst [c])) - // cond: int32(c)==0 - // result: (MOVDconst [0]) - for { - _ = v.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_1_0.Args[1] + v_1_0_0 := v_1_0.Args[0] + if v_1_0_0.Op != OpARM64MOVWUreg { break } - c := v_1.AuxInt - if !(int32(c) == 0) { + if x != v_1_0_0.Args[0] { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (MULW (MOVDconst [c]) _) - // cond: int32(c)==0 - // result: (MOVDconst [0]) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_0_1 := v_1_0.Args[1] + if v_1_0_1.Op != OpARM64SUB { break } - c := v_0.AuxInt - if !(int32(c) == 0) { + if v_1_0_1.Type != t { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (MULW x (MOVDconst [c])) - // cond: int32(c)==1 - // result: x - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_1_0_1.Args[1] + v_1_0_1_0 := v_1_0_1.Args[0] + if v_1_0_1_0.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(int32(c) == 1) { + if v_1_0_1_0.AuxInt != 32 { break } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (MULW (MOVDconst [c]) x) - // cond: int32(c)==1 - // result: x - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(int32(c) == 1) { + if v_1_0_1_1.Type != t { break } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (MULW x (MOVDconst [c])) - // cond: isPowerOfTwo(c) - // result: (SLLconst [log2(c)] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_0_1_1.AuxInt != 31 { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c)) { + if y != v_1_0_1_1.Args[0] { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c) - v.AddArg(x) - return true - } - // match: (MULW (MOVDconst [c]) x) - // cond: isPowerOfTwo(c) - // result: (SLLconst [log2(c)] x) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64CMPconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c)) { + if v_1_1.AuxInt != 64 { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64MULW_10(v *Value) bool { - b := v.Block - _ = b - // match: (MULW x (MOVDconst [c])) - // cond: isPowerOfTwo(c-1) && int32(c) >= 3 - // result: (ADDshiftLL x x [log2(c-1)]) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c-1) && int32(c) >= 3) { + if v_1_1_0.Type != t { break } - v.reset(OpARM64ADDshiftLL) - v.AuxInt = log2(c - 1) - v.AddArg(x) - v.AddArg(x) - return true - } - // match: (MULW (MOVDconst [c]) x) - // cond: isPowerOfTwo(c-1) && int32(c) >= 3 - // result: (ADDshiftLL x x [log2(c-1)]) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c-1) && int32(c) >= 3) { + if v_1_1_0_0.AuxInt != 32 { break } - v.reset(OpARM64ADDshiftLL) - v.AuxInt = log2(c - 1) - v.AddArg(x) - v.AddArg(x) - return true - } - // match: (MULW x (MOVDconst [c])) - // cond: isPowerOfTwo(c+1) && int32(c) >= 7 - // result: (ADDshiftLL (NEG x) x [log2(c+1)]) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c+1) && int32(c) >= 7) { + if v_1_1_0_1.Type != t { break } - v.reset(OpARM64ADDshiftLL) - v.AuxInt = log2(c + 1) - v0 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v0.AddArg(x) - v.AddArg(v0) + if v_1_1_0_1.AuxInt != 31 { + break + } + if y != v_1_1_0_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64RORW) v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) + v.AddArg(v0) return true } - // match: (MULW (MOVDconst [c]) x) - // cond: isPowerOfTwo(c+1) && int32(c) >= 7 - // result: (ADDshiftLL (NEG x) x [log2(c+1)]) + // match: (OR (CSEL0 {cc} (SRL (MOVWUreg x) (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y)))) (SLL x (ANDconst [31] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x (NEG y)) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64CSEL0 { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c+1) && int32(c) >= 7) { + if v_0.Type != typ.UInt32 { break } - v.reset(OpARM64ADDshiftLL) - v.AuxInt = log2(c + 1) - v0 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v0.AddArg(x) - v.AddArg(v0) - v.AddArg(x) - return true - } - // match: (MULW x (MOVDconst [c])) - // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) - // result: (SLLconst [log2(c/3)] (ADDshiftLL x x [1])) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + cc := v_0.Aux + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SRL { + break + } + if v_0_0.Type != typ.UInt32 { + break + } + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + if v_0_0_0.Op != OpARM64MOVWUreg { + break + } + x := v_0_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { + break + } + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { + break + } + if v_0_0_1_0.AuxInt != 32 { + break + } + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { + break + } + if v_0_0_1_1.Type != t { break } - c := v_1.AuxInt - if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { + if v_0_0_1_1.AuxInt != 31 { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 1 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MULW (MOVDconst [c]) x) - // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) - // result: (SLLconst [log2(c/3)] (ADDshiftLL x x [1])) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + y := v_0_0_1_1.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64CMPconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { + if v_0_1.AuxInt != 64 { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 1 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MULW x (MOVDconst [c])) - // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) - // result: (SLLconst [log2(c/5)] (ADDshiftLL x x [2])) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_0_1_0 := v_0_1.Args[0] + if v_0_1_0.Op != OpARM64SUB { break } - c := v_1.AuxInt - if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { + if v_0_1_0.Type != t { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 5) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MULW (MOVDconst [c]) x) - // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) - // result: (SLLconst [log2(c/5)] (ADDshiftLL x x [2])) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v_0_1_0.Args[1] + v_0_1_0_0 := v_0_1_0.Args[0] + if v_0_1_0_0.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { + if v_0_1_0_0.AuxInt != 32 { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 5) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MULW x (MOVDconst [c])) - // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) - // result: (SLLconst [log2(c/7)] (ADDshiftLL (NEG x) x [3])) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_0_1_0_1 := v_0_1_0.Args[1] + if v_0_1_0_1.Op != OpARM64ANDconst { break } - c := v_1.AuxInt - if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { + if v_0_1_0_1.Type != t { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 7) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 3 - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MULW (MOVDconst [c]) x) - // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) - // result: (SLLconst [log2(c/7)] (ADDshiftLL (NEG x) x [3])) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_1_0_1.AuxInt != 31 { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { + if y != v_0_1_0_1.Args[0] { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 7) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 3 - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) - return true - } - return false -} -func rewriteValueARM64_OpARM64MULW_20(v *Value) bool { - b := v.Block - _ = b - // match: (MULW x (MOVDconst [c])) - // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) - // result: (SLLconst [log2(c/9)] (ADDshiftLL x x [3])) - for { - _ = v.Args[1] - x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64SLL { break } - c := v_1.AuxInt - if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { + _ = v_1.Args[1] + if x != v_1.Args[0] { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 9) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 3 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (MULW (MOVDconst [c]) x) - // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) - // result: (SLLconst [log2(c/9)] (ADDshiftLL x x [3])) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64ANDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { + if v_1_1.Type != t { break } - v.reset(OpARM64SLLconst) - v.AuxInt = log2(c / 9) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = 3 - v0.AddArg(x) - v0.AddArg(x) + if v_1_1.AuxInt != 31 { + break + } + if y != v_1_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64RORW) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) v.AddArg(v0) return true } - // match: (MULW (MOVDconst [c]) (MOVDconst [d])) - // cond: - // result: (MOVDconst [int64(int32(c)*int32(d))]) + // match: (OR (SRL (MOVWUreg x) (ANDconst [31] y)) (CSEL0 {cc} (SLL x (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64SRL { break } - c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0.Type != typ.UInt32 { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(int32(c) * int32(d)) - return true - } - // match: (MULW (MOVDconst [d]) (MOVDconst [c])) - // cond: - // result: (MOVDconst [int64(int32(c)*int32(d))]) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64MOVWUreg { break } - d := v_0.AuxInt + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { + break + } + t := v_0_1.Type + if v_0_1.AuxInt != 31 { + break + } + y := v_0_1.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64CSEL0 { break } - c := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(int32(c) * int32(d)) - return true - } - return false -} -func rewriteValueARM64_OpARM64MVN_0(v *Value) bool { - // match: (MVN (MOVDconst [c])) - // cond: - // result: (MOVDconst [^c]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_1.Type != typ.UInt32 { break } - c := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = ^c - return true - } - return false -} -func rewriteValueARM64_OpARM64NEG_0(v *Value) bool { - // match: (NEG (MUL x y)) - // cond: - // result: (MNEG x y) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MUL { + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SLL { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - v.reset(OpARM64MNEG) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (NEG (MULW x y)) - // cond: - // result: (MNEGW x y) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MULW { + _ = v_1_0.Args[1] + if x != v_1_0.Args[0] { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - v.reset(OpARM64MNEGW) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (NEG (MOVDconst [c])) - // cond: - // result: (MOVDconst [-c]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_0_1 := v_1_0.Args[1] + if v_1_0_1.Op != OpARM64SUB { + break + } + if v_1_0_1.Type != t { + break + } + _ = v_1_0_1.Args[1] + v_1_0_1_0 := v_1_0_1.Args[0] + if v_1_0_1_0.Op != OpARM64MOVDconst { + break + } + if v_1_0_1_0.AuxInt != 32 { + break + } + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { + break + } + if v_1_0_1_1.Type != t { + break + } + if v_1_0_1_1.AuxInt != 31 { break } - c := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = -c - return true - } - return false -} -func rewriteValueARM64_OpARM64NotEqual_0(v *Value) bool { - // match: (NotEqual (FlagEQ)) - // cond: - // result: (MOVDconst [0]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagEQ { + if y != v_1_0_1_1.Args[0] { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (NotEqual (FlagLT_ULT)) - // cond: - // result: (MOVDconst [1]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_ULT { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64CMPconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 - return true - } - // match: (NotEqual (FlagLT_UGT)) - // cond: - // result: (MOVDconst [1]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagLT_UGT { + if v_1_1.AuxInt != 64 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 - return true - } - // match: (NotEqual (FlagGT_ULT)) - // cond: - // result: (MOVDconst [1]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_ULT { + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 - return true - } - // match: (NotEqual (FlagGT_UGT)) - // cond: - // result: (MOVDconst [1]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64FlagGT_UGT { + if v_1_1_0.Type != t { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 1 - return true - } - // match: (NotEqual (InvertFlags x)) - // cond: - // result: (NotEqual x) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64InvertFlags { + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { break } - x := v_0.Args[0] - v.reset(OpARM64NotEqual) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64OR_0(v *Value) bool { - // match: (OR x (MOVDconst [c])) - // cond: - // result: (ORconst [c] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_1_0_0.AuxInt != 32 { break } - c := v_1.AuxInt - v.reset(OpARM64ORconst) - v.AuxInt = c - v.AddArg(x) - return true - } - // match: (OR (MOVDconst [c]) x) - // cond: - // result: (ORconst [c] x) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64ORconst) - v.AuxInt = c - v.AddArg(x) - return true - } - // match: (OR x x) - // cond: - // result: x - for { - _ = v.Args[1] - x := v.Args[0] - if x != v.Args[1] { + if v_1_1_0_1.Type != t { break } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (OR x (MVN y)) - // cond: - // result: (ORN x y) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MVN { + if v_1_1_0_1.AuxInt != 31 { break } - y := v_1.Args[0] - v.reset(OpARM64ORN) + if y != v_1_1_0_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64RORW) v.AddArg(x) v.AddArg(y) return true } - // match: (OR (MVN y) x) - // cond: - // result: (ORN x y) + // match: (OR (CSEL0 {cc} (SLL x (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y)))) (SRL (MOVWUreg x) (ANDconst [31] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MVN { + if v_0.Op != OpARM64CSEL0 { break } - y := v_0.Args[0] - x := v.Args[1] - v.reset(OpARM64ORN) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (OR x0 x1:(SLLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (ORshiftLL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SLLconst { + if v_0.Type != typ.UInt32 { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + cc := v_0.Aux + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SLL { break } - v.reset(OpARM64ORshiftLL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (OR x1:(SLLconst [c] y) x0) - // cond: clobberIfDead(x1) - // result: (ORshiftLL x0 y [c]) - for { - _ = v.Args[1] - x1 := v.Args[0] - if x1.Op != OpARM64SLLconst { + _ = v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { break } - c := x1.AuxInt - y := x1.Args[0] - x0 := v.Args[1] - if !(clobberIfDead(x1)) { + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64ORshiftLL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (OR x0 x1:(SRLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (ORshiftRL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRLconst { + if v_0_0_1_0.AuxInt != 32 { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64ORshiftRL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (OR x1:(SRLconst [c] y) x0) - // cond: clobberIfDead(x1) - // result: (ORshiftRL x0 y [c]) - for { - _ = v.Args[1] - x1 := v.Args[0] - if x1.Op != OpARM64SRLconst { + if v_0_0_1_1.Type != t { break } - c := x1.AuxInt - y := x1.Args[0] - x0 := v.Args[1] - if !(clobberIfDead(x1)) { + if v_0_0_1_1.AuxInt != 31 { break } - v.reset(OpARM64ORshiftRL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (OR x0 x1:(SRAconst [c] y)) - // cond: clobberIfDead(x1) - // result: (ORshiftRA x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRAconst { + y := v_0_0_1_1.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64CMPconst { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_0_1.AuxInt != 64 { break } - v.reset(OpARM64ORshiftRA) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - return false -} -func rewriteValueARM64_OpARM64OR_10(v *Value) bool { - b := v.Block - _ = b - // match: (OR x1:(SRAconst [c] y) x0) - // cond: clobberIfDead(x1) - // result: (ORshiftRA x0 y [c]) - for { - _ = v.Args[1] - x1 := v.Args[0] - if x1.Op != OpARM64SRAconst { + v_0_1_0 := v_0_1.Args[0] + if v_0_1_0.Op != OpARM64SUB { + break + } + if v_0_1_0.Type != t { + break + } + _ = v_0_1_0.Args[1] + v_0_1_0_0 := v_0_1_0.Args[0] + if v_0_1_0_0.Op != OpARM64MOVDconst { + break + } + if v_0_1_0_0.AuxInt != 32 { + break + } + v_0_1_0_1 := v_0_1_0.Args[1] + if v_0_1_0_1.Op != OpARM64ANDconst { + break + } + if v_0_1_0_1.Type != t { + break + } + if v_0_1_0_1.AuxInt != 31 { + break + } + if y != v_0_1_0_1.Args[0] { + break + } + v_1 := v.Args[1] + if v_1.Op != OpARM64SRL { + break + } + if v_1.Type != typ.UInt32 { + break + } + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64MOVWUreg { break } - c := x1.AuxInt - y := x1.Args[0] - x0 := v.Args[1] - if !(clobberIfDead(x1)) { + if x != v_1_0.Args[0] { break } - v.reset(OpARM64ORshiftRA) - v.AuxInt = c - v.AddArg(x0) + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64ANDconst { + break + } + if v_1_1.Type != t { + break + } + if v_1_1.AuxInt != 31 { + break + } + if y != v_1_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64RORW) + v.AddArg(x) v.AddArg(y) return true } @@ -17182,6 +19027,11 @@ func rewriteValueARM64_OpARM64OR_10(v *Value) bool { v.AddArg(x) return true } + return false +} +func rewriteValueARM64_OpARM64OR_20(v *Value) bool { + b := v.Block + _ = b // match: (OR (ANDconst [ac] y) (UBFIZ [bfc] x)) // cond: ac == ^((1< y3:(MOVDnop x3:(MOVBUloadidx ptr idx mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [1] idx) mem)))) // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) // result: @mergePoint(b,x0,x1,x2,x3) (MOVWUloadidx ptr idx mem) @@ -18173,19 +20018,246 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if y7.Op != OpARM64MOVDnop { break } - x7 := y7.Args[0] - if x7.Op != OpARM64MOVBUload { + x7 := y7.Args[0] + if x7.Op != OpARM64MOVBUload { + break + } + i0 := x7.AuxInt + if x7.Aux != s { + break + } + _ = x7.Args[1] + if p != x7.Args[0] { + break + } + if mem != x7.Args[1] { + break + } + if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + break + } + b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) + v0 := b.NewValue0(v.Pos, OpARM64MOVDload, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.Aux = s + v1 := b.NewValue0(v.Pos, OpOffPtr, p.Type) + v1.AuxInt = i0 + v1.AddArg(p) + v0.AddArg(v1) + v0.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64OR_30(v *Value) bool { + b := v.Block + _ = b + // match: (OR y7:(MOVDnop x7:(MOVBUload [i0] {s} p mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUload [i7] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [i6] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i4] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [i3] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [i2] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [i1] {s} p mem)))) + // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDload {s} (OffPtr [i0] p) mem) + for { + t := v.Type + _ = v.Args[1] + y7 := v.Args[0] + if y7.Op != OpARM64MOVDnop { + break + } + x7 := y7.Args[0] + if x7.Op != OpARM64MOVBUload { + break + } + i0 := x7.AuxInt + s := x7.Aux + _ = x7.Args[1] + p := x7.Args[0] + mem := x7.Args[1] + o0 := v.Args[1] + if o0.Op != OpARM64ORshiftLL { + break + } + if o0.AuxInt != 8 { + break + } + _ = o0.Args[1] + o1 := o0.Args[0] + if o1.Op != OpARM64ORshiftLL { + break + } + if o1.AuxInt != 16 { + break + } + _ = o1.Args[1] + o2 := o1.Args[0] + if o2.Op != OpARM64ORshiftLL { + break + } + if o2.AuxInt != 24 { + break + } + _ = o2.Args[1] + o3 := o2.Args[0] + if o3.Op != OpARM64ORshiftLL { + break + } + if o3.AuxInt != 32 { + break + } + _ = o3.Args[1] + o4 := o3.Args[0] + if o4.Op != OpARM64ORshiftLL { + break + } + if o4.AuxInt != 40 { + break + } + _ = o4.Args[1] + o5 := o4.Args[0] + if o5.Op != OpARM64ORshiftLL { + break + } + if o5.AuxInt != 48 { + break + } + _ = o5.Args[1] + s0 := o5.Args[0] + if s0.Op != OpARM64SLLconst { + break + } + if s0.AuxInt != 56 { + break + } + y0 := s0.Args[0] + if y0.Op != OpARM64MOVDnop { + break + } + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUload { + break + } + i7 := x0.AuxInt + if x0.Aux != s { + break + } + _ = x0.Args[1] + if p != x0.Args[0] { + break + } + if mem != x0.Args[1] { + break + } + y1 := o5.Args[1] + if y1.Op != OpARM64MOVDnop { + break + } + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { + break + } + i6 := x1.AuxInt + if x1.Aux != s { + break + } + _ = x1.Args[1] + if p != x1.Args[0] { + break + } + if mem != x1.Args[1] { + break + } + y2 := o4.Args[1] + if y2.Op != OpARM64MOVDnop { + break + } + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { + break + } + i5 := x2.AuxInt + if x2.Aux != s { + break + } + _ = x2.Args[1] + if p != x2.Args[0] { + break + } + if mem != x2.Args[1] { + break + } + y3 := o3.Args[1] + if y3.Op != OpARM64MOVDnop { + break + } + x3 := y3.Args[0] + if x3.Op != OpARM64MOVBUload { + break + } + i4 := x3.AuxInt + if x3.Aux != s { + break + } + _ = x3.Args[1] + if p != x3.Args[0] { + break + } + if mem != x3.Args[1] { + break + } + y4 := o2.Args[1] + if y4.Op != OpARM64MOVDnop { + break + } + x4 := y4.Args[0] + if x4.Op != OpARM64MOVBUload { + break + } + i3 := x4.AuxInt + if x4.Aux != s { + break + } + _ = x4.Args[1] + if p != x4.Args[0] { + break + } + if mem != x4.Args[1] { + break + } + y5 := o1.Args[1] + if y5.Op != OpARM64MOVDnop { + break + } + x5 := y5.Args[0] + if x5.Op != OpARM64MOVBUload { + break + } + i2 := x5.AuxInt + if x5.Aux != s { + break + } + _ = x5.Args[1] + if p != x5.Args[0] { + break + } + if mem != x5.Args[1] { + break + } + y6 := o0.Args[1] + if y6.Op != OpARM64MOVDnop { + break + } + x6 := y6.Args[0] + if x6.Op != OpARM64MOVBUload { break } - i0 := x7.AuxInt - if x7.Aux != s { + i1 := x6.AuxInt + if x6.Aux != s { break } - _ = x7.Args[1] - if p != x7.Args[0] { + _ = x6.Args[1] + if p != x6.Args[0] { break } - if mem != x7.Args[1] { + if mem != x6.Args[1] { break } if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { @@ -18203,26 +20275,13 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { v0.AddArg(mem) return true } - // match: (OR y7:(MOVDnop x7:(MOVBUload [i0] {s} p mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUload [i7] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [i6] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i4] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [i3] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [i2] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [i1] {s} p mem)))) - // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDload {s} (OffPtr [i0] p) mem) + // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUload [7] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [6] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [4] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [3] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [2] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y7:(MOVDnop x7:(MOVBUloadidx ptr0 idx0 mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDloadidx ptr0 idx0 mem) for { t := v.Type _ = v.Args[1] - y7 := v.Args[0] - if y7.Op != OpARM64MOVDnop { - break - } - x7 := y7.Args[0] - if x7.Op != OpARM64MOVBUload { - break - } - i0 := x7.AuxInt - s := x7.Aux - _ = x7.Args[1] - p := x7.Args[0] - mem := x7.Args[1] - o0 := v.Args[1] + o0 := v.Args[0] if o0.Op != OpARM64ORshiftLL { break } @@ -18285,17 +20344,13 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x0.Op != OpARM64MOVBUload { break } - i7 := x0.AuxInt - if x0.Aux != s { + if x0.AuxInt != 7 { break } + s := x0.Aux _ = x0.Args[1] - if p != x0.Args[0] { - break - } - if mem != x0.Args[1] { - break - } + p := x0.Args[0] + mem := x0.Args[1] y1 := o5.Args[1] if y1.Op != OpARM64MOVDnop { break @@ -18304,7 +20359,9 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x1.Op != OpARM64MOVBUload { break } - i6 := x1.AuxInt + if x1.AuxInt != 6 { + break + } if x1.Aux != s { break } @@ -18323,7 +20380,9 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x2.Op != OpARM64MOVBUload { break } - i5 := x2.AuxInt + if x2.AuxInt != 5 { + break + } if x2.Aux != s { break } @@ -18342,7 +20401,9 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x3.Op != OpARM64MOVBUload { break } - i4 := x3.AuxInt + if x3.AuxInt != 4 { + break + } if x3.Aux != s { break } @@ -18361,7 +20422,9 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x4.Op != OpARM64MOVBUload { break } - i3 := x4.AuxInt + if x4.AuxInt != 3 { + break + } if x4.Aux != s { break } @@ -18380,7 +20443,9 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x5.Op != OpARM64MOVBUload { break } - i2 := x5.AuxInt + if x5.AuxInt != 2 { + break + } if x5.Aux != s { break } @@ -18399,39 +20464,68 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x6.Op != OpARM64MOVBUload { break } - i1 := x6.AuxInt + if x6.AuxInt != 1 { + break + } if x6.Aux != s { break } _ = x6.Args[1] - if p != x6.Args[0] { + p1 := x6.Args[0] + if p1.Op != OpARM64ADD { break } + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] if mem != x6.Args[1] { break } - if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + y7 := v.Args[1] + if y7.Op != OpARM64MOVDnop { + break + } + x7 := y7.Args[0] + if x7.Op != OpARM64MOVBUloadidx { + break + } + _ = x7.Args[2] + ptr0 := x7.Args[0] + idx0 := x7.Args[1] + if mem != x7.Args[2] { + break + } + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { break } b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) - v0 := b.NewValue0(v.Pos, OpARM64MOVDload, t) + v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) v.reset(OpCopy) v.AddArg(v0) - v0.Aux = s - v1 := b.NewValue0(v.Pos, OpOffPtr, p.Type) - v1.AuxInt = i0 - v1.AddArg(p) - v0.AddArg(v1) + v0.AddArg(ptr0) + v0.AddArg(idx0) v0.AddArg(mem) return true } - // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUload [7] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [6] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [4] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [3] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [2] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y7:(MOVDnop x7:(MOVBUloadidx ptr0 idx0 mem))) + // match: (OR y7:(MOVDnop x7:(MOVBUloadidx ptr0 idx0 mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUload [7] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [6] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [4] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [3] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [2] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem)))) // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDloadidx ptr0 idx0 mem) for { t := v.Type _ = v.Args[1] - o0 := v.Args[0] + y7 := v.Args[0] + if y7.Op != OpARM64MOVDnop { + break + } + x7 := y7.Args[0] + if x7.Op != OpARM64MOVBUloadidx { + break + } + _ = x7.Args[2] + ptr0 := x7.Args[0] + idx0 := x7.Args[1] + mem := x7.Args[2] + o0 := v.Args[1] if o0.Op != OpARM64ORshiftLL { break } @@ -18500,7 +20594,9 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { s := x0.Aux _ = x0.Args[1] p := x0.Args[0] - mem := x0.Args[1] + if mem != x0.Args[1] { + break + } y1 := o5.Args[1] if y1.Op != OpARM64MOVDnop { break @@ -18631,20 +20727,6 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if mem != x6.Args[1] { break } - y7 := v.Args[1] - if y7.Op != OpARM64MOVDnop { - break - } - x7 := y7.Args[0] - if x7.Op != OpARM64MOVBUloadidx { - break - } - _ = x7.Args[2] - ptr0 := x7.Args[0] - idx0 := x7.Args[1] - if mem != x7.Args[2] { - break - } if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { break } @@ -18657,25 +20739,13 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { v0.AddArg(mem) return true } - // match: (OR y7:(MOVDnop x7:(MOVBUloadidx ptr0 idx0 mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUload [7] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [6] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [4] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [3] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [2] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem)))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDloadidx ptr0 idx0 mem) + // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr (ADDconst [7] idx) mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [6] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [5] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [4] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y5:(MOVDnop x5:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y6:(MOVDnop x6:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y7:(MOVDnop x7:(MOVBUloadidx ptr idx mem))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDloadidx ptr idx mem) for { t := v.Type _ = v.Args[1] - y7 := v.Args[0] - if y7.Op != OpARM64MOVDnop { - break - } - x7 := y7.Args[0] - if x7.Op != OpARM64MOVBUloadidx { - break - } - _ = x7.Args[2] - ptr0 := x7.Args[0] - idx0 := x7.Args[1] - mem := x7.Args[2] - o0 := v.Args[1] + o0 := v.Args[0] if o0.Op != OpARM64ORshiftLL { break } @@ -18735,37 +20805,43 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUload { + if x0.Op != OpARM64MOVBUloadidx { break } - if x0.AuxInt != 7 { + _ = x0.Args[2] + ptr := x0.Args[0] + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64ADDconst { break } - s := x0.Aux - _ = x0.Args[1] - p := x0.Args[0] - if mem != x0.Args[1] { + if x0_1.AuxInt != 7 { break } + idx := x0_1.Args[0] + mem := x0.Args[2] y1 := o5.Args[1] if y1.Op != OpARM64MOVDnop { break } x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + if x1.Op != OpARM64MOVBUloadidx { break } - if x1.AuxInt != 6 { + _ = x1.Args[2] + if ptr != x1.Args[0] { break } - if x1.Aux != s { + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64ADDconst { break } - _ = x1.Args[1] - if p != x1.Args[0] { + if x1_1.AuxInt != 6 { break } - if mem != x1.Args[1] { + if idx != x1_1.Args[0] { + break + } + if mem != x1.Args[2] { break } y2 := o4.Args[1] @@ -18773,20 +20849,24 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUload { + if x2.Op != OpARM64MOVBUloadidx { break } - if x2.AuxInt != 5 { + _ = x2.Args[2] + if ptr != x2.Args[0] { break } - if x2.Aux != s { + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64ADDconst { break } - _ = x2.Args[1] - if p != x2.Args[0] { + if x2_1.AuxInt != 5 { break } - if mem != x2.Args[1] { + if idx != x2_1.Args[0] { + break + } + if mem != x2.Args[2] { break } y3 := o3.Args[1] @@ -18794,20 +20874,24 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUload { + if x3.Op != OpARM64MOVBUloadidx { break } - if x3.AuxInt != 4 { + _ = x3.Args[2] + if ptr != x3.Args[0] { break } - if x3.Aux != s { + x3_1 := x3.Args[1] + if x3_1.Op != OpARM64ADDconst { break } - _ = x3.Args[1] - if p != x3.Args[0] { + if x3_1.AuxInt != 4 { break } - if mem != x3.Args[1] { + if idx != x3_1.Args[0] { + break + } + if mem != x3.Args[2] { break } y4 := o2.Args[1] @@ -18815,87 +20899,125 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUload { + if x4.Op != OpARM64MOVBUloadidx { break } - if x4.AuxInt != 3 { + _ = x4.Args[2] + if ptr != x4.Args[0] { break } - if x4.Aux != s { + x4_1 := x4.Args[1] + if x4_1.Op != OpARM64ADDconst { + break + } + if x4_1.AuxInt != 3 { + break + } + if idx != x4_1.Args[0] { + break + } + if mem != x4.Args[2] { + break + } + y5 := o1.Args[1] + if y5.Op != OpARM64MOVDnop { + break + } + x5 := y5.Args[0] + if x5.Op != OpARM64MOVBUloadidx { + break + } + _ = x5.Args[2] + if ptr != x5.Args[0] { + break + } + x5_1 := x5.Args[1] + if x5_1.Op != OpARM64ADDconst { + break + } + if x5_1.AuxInt != 2 { break } - _ = x4.Args[1] - if p != x4.Args[0] { + if idx != x5_1.Args[0] { break } - if mem != x4.Args[1] { + if mem != x5.Args[2] { break } - y5 := o1.Args[1] - if y5.Op != OpARM64MOVDnop { + y6 := o0.Args[1] + if y6.Op != OpARM64MOVDnop { break } - x5 := y5.Args[0] - if x5.Op != OpARM64MOVBUload { + x6 := y6.Args[0] + if x6.Op != OpARM64MOVBUloadidx { break } - if x5.AuxInt != 2 { + _ = x6.Args[2] + if ptr != x6.Args[0] { break } - if x5.Aux != s { + x6_1 := x6.Args[1] + if x6_1.Op != OpARM64ADDconst { break } - _ = x5.Args[1] - if p != x5.Args[0] { + if x6_1.AuxInt != 1 { break } - if mem != x5.Args[1] { + if idx != x6_1.Args[0] { break } - y6 := o0.Args[1] - if y6.Op != OpARM64MOVDnop { + if mem != x6.Args[2] { break } - x6 := y6.Args[0] - if x6.Op != OpARM64MOVBUload { + y7 := v.Args[1] + if y7.Op != OpARM64MOVDnop { break } - if x6.AuxInt != 1 { + x7 := y7.Args[0] + if x7.Op != OpARM64MOVBUloadidx { break } - if x6.Aux != s { + _ = x7.Args[2] + if ptr != x7.Args[0] { break } - _ = x6.Args[1] - p1 := x6.Args[0] - if p1.Op != OpARM64ADD { + if idx != x7.Args[1] { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - if mem != x6.Args[1] { + if mem != x7.Args[2] { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { break } b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) v.reset(OpCopy) v.AddArg(v0) - v0.AddArg(ptr0) - v0.AddArg(idx0) + v0.AddArg(ptr) + v0.AddArg(idx) v0.AddArg(mem) return true } - // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr (ADDconst [7] idx) mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [6] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [5] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [4] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y5:(MOVDnop x5:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y6:(MOVDnop x6:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y7:(MOVDnop x7:(MOVBUloadidx ptr idx mem))) + // match: (OR y7:(MOVDnop x7:(MOVBUloadidx ptr idx mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr (ADDconst [7] idx) mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [6] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [5] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [4] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y5:(MOVDnop x5:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y6:(MOVDnop x6:(MOVBUloadidx ptr (ADDconst [1] idx) mem)))) // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDloadidx ptr idx mem) for { t := v.Type _ = v.Args[1] - o0 := v.Args[0] + y7 := v.Args[0] + if y7.Op != OpARM64MOVDnop { + break + } + x7 := y7.Args[0] + if x7.Op != OpARM64MOVBUloadidx { + break + } + _ = x7.Args[2] + ptr := x7.Args[0] + idx := x7.Args[1] + mem := x7.Args[2] + o0 := v.Args[1] if o0.Op != OpARM64ORshiftLL { break } @@ -18959,7 +21081,9 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } _ = x0.Args[2] - ptr := x0.Args[0] + if ptr != x0.Args[0] { + break + } x0_1 := x0.Args[1] if x0_1.Op != OpARM64ADDconst { break @@ -18967,8 +21091,12 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x0_1.AuxInt != 7 { break } - idx := x0_1.Args[0] - mem := x0.Args[2] + if idx != x0_1.Args[0] { + break + } + if mem != x0.Args[2] { + break + } y1 := o5.Args[1] if y1.Op != OpARM64MOVDnop { break @@ -19060,114 +21188,316 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x4_1.Op != OpARM64ADDconst { break } - if x4_1.AuxInt != 3 { + if x4_1.AuxInt != 3 { + break + } + if idx != x4_1.Args[0] { + break + } + if mem != x4.Args[2] { + break + } + y5 := o1.Args[1] + if y5.Op != OpARM64MOVDnop { + break + } + x5 := y5.Args[0] + if x5.Op != OpARM64MOVBUloadidx { + break + } + _ = x5.Args[2] + if ptr != x5.Args[0] { + break + } + x5_1 := x5.Args[1] + if x5_1.Op != OpARM64ADDconst { + break + } + if x5_1.AuxInt != 2 { + break + } + if idx != x5_1.Args[0] { + break + } + if mem != x5.Args[2] { + break + } + y6 := o0.Args[1] + if y6.Op != OpARM64MOVDnop { + break + } + x6 := y6.Args[0] + if x6.Op != OpARM64MOVBUloadidx { + break + } + _ = x6.Args[2] + if ptr != x6.Args[0] { + break + } + x6_1 := x6.Args[1] + if x6_1.Op != OpARM64ADDconst { + break + } + if x6_1.AuxInt != 1 { + break + } + if idx != x6_1.Args[0] { + break + } + if mem != x6.Args[2] { + break + } + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + break + } + b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) + v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.AddArg(ptr) + v0.AddArg(idx) + v0.AddArg(mem) + return true + } + // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i3] {s} p mem))) + // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUload {s} (OffPtr [i0] p) mem)) + for { + t := v.Type + _ = v.Args[1] + o0 := v.Args[0] + if o0.Op != OpARM64ORshiftLL { + break + } + if o0.AuxInt != 8 { + break + } + _ = o0.Args[1] + o1 := o0.Args[0] + if o1.Op != OpARM64ORshiftLL { + break + } + if o1.AuxInt != 16 { + break + } + _ = o1.Args[1] + s0 := o1.Args[0] + if s0.Op != OpARM64SLLconst { + break + } + if s0.AuxInt != 24 { + break + } + y0 := s0.Args[0] + if y0.Op != OpARM64MOVDnop { + break + } + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUload { + break + } + i0 := x0.AuxInt + s := x0.Aux + _ = x0.Args[1] + p := x0.Args[0] + mem := x0.Args[1] + y1 := o1.Args[1] + if y1.Op != OpARM64MOVDnop { + break + } + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { + break + } + i1 := x1.AuxInt + if x1.Aux != s { + break + } + _ = x1.Args[1] + if p != x1.Args[0] { + break + } + if mem != x1.Args[1] { + break + } + y2 := o0.Args[1] + if y2.Op != OpARM64MOVDnop { + break + } + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { + break + } + i2 := x2.AuxInt + if x2.Aux != s { + break + } + _ = x2.Args[1] + if p != x2.Args[0] { + break + } + if mem != x2.Args[1] { + break + } + y3 := v.Args[1] + if y3.Op != OpARM64MOVDnop { + break + } + x3 := y3.Args[0] + if x3.Op != OpARM64MOVBUload { + break + } + i3 := x3.AuxInt + if x3.Aux != s { + break + } + _ = x3.Args[1] + if p != x3.Args[0] { + break + } + if mem != x3.Args[1] { + break + } + if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { + break + } + b = mergePoint(b, x0, x1, x2, x3) + v0 := b.NewValue0(v.Pos, OpARM64REVW, t) + v.reset(OpCopy) + v.AddArg(v0) + v1 := b.NewValue0(v.Pos, OpARM64MOVWUload, t) + v1.Aux = s + v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) + v2.AuxInt = i0 + v2.AddArg(p) + v1.AddArg(v2) + v1.AddArg(mem) + v0.AddArg(v1) + return true + } + // match: (OR y3:(MOVDnop x3:(MOVBUload [i3] {s} p mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem)))) + // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUload {s} (OffPtr [i0] p) mem)) + for { + t := v.Type + _ = v.Args[1] + y3 := v.Args[0] + if y3.Op != OpARM64MOVDnop { + break + } + x3 := y3.Args[0] + if x3.Op != OpARM64MOVBUload { break } - if idx != x4_1.Args[0] { + i3 := x3.AuxInt + s := x3.Aux + _ = x3.Args[1] + p := x3.Args[0] + mem := x3.Args[1] + o0 := v.Args[1] + if o0.Op != OpARM64ORshiftLL { break } - if mem != x4.Args[2] { + if o0.AuxInt != 8 { break } - y5 := o1.Args[1] - if y5.Op != OpARM64MOVDnop { + _ = o0.Args[1] + o1 := o0.Args[0] + if o1.Op != OpARM64ORshiftLL { break } - x5 := y5.Args[0] - if x5.Op != OpARM64MOVBUloadidx { + if o1.AuxInt != 16 { break } - _ = x5.Args[2] - if ptr != x5.Args[0] { + _ = o1.Args[1] + s0 := o1.Args[0] + if s0.Op != OpARM64SLLconst { break } - x5_1 := x5.Args[1] - if x5_1.Op != OpARM64ADDconst { + if s0.AuxInt != 24 { break } - if x5_1.AuxInt != 2 { + y0 := s0.Args[0] + if y0.Op != OpARM64MOVDnop { break } - if idx != x5_1.Args[0] { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUload { break } - if mem != x5.Args[2] { + i0 := x0.AuxInt + if x0.Aux != s { break } - y6 := o0.Args[1] - if y6.Op != OpARM64MOVDnop { + _ = x0.Args[1] + if p != x0.Args[0] { break } - x6 := y6.Args[0] - if x6.Op != OpARM64MOVBUloadidx { + if mem != x0.Args[1] { break } - _ = x6.Args[2] - if ptr != x6.Args[0] { + y1 := o1.Args[1] + if y1.Op != OpARM64MOVDnop { break } - x6_1 := x6.Args[1] - if x6_1.Op != OpARM64ADDconst { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - if x6_1.AuxInt != 1 { + i1 := x1.AuxInt + if x1.Aux != s { break } - if idx != x6_1.Args[0] { + _ = x1.Args[1] + if p != x1.Args[0] { break } - if mem != x6.Args[2] { + if mem != x1.Args[1] { break } - y7 := v.Args[1] - if y7.Op != OpARM64MOVDnop { + y2 := o0.Args[1] + if y2.Op != OpARM64MOVDnop { break } - x7 := y7.Args[0] - if x7.Op != OpARM64MOVBUloadidx { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { break } - _ = x7.Args[2] - if ptr != x7.Args[0] { + i2 := x2.AuxInt + if x2.Aux != s { break } - if idx != x7.Args[1] { + _ = x2.Args[1] + if p != x2.Args[0] { break } - if mem != x7.Args[2] { + if mem != x2.Args[1] { break } - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { break } - b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) - v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + b = mergePoint(b, x0, x1, x2, x3) + v0 := b.NewValue0(v.Pos, OpARM64REVW, t) v.reset(OpCopy) v.AddArg(v0) - v0.AddArg(ptr) - v0.AddArg(idx) - v0.AddArg(mem) + v1 := b.NewValue0(v.Pos, OpARM64MOVWUload, t) + v1.Aux = s + v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) + v2.AuxInt = i0 + v2.AddArg(p) + v1.AddArg(v2) + v1.AddArg(mem) + v0.AddArg(v1) return true } - // match: (OR y7:(MOVDnop x7:(MOVBUloadidx ptr idx mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr (ADDconst [7] idx) mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [6] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [5] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [4] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y5:(MOVDnop x5:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y6:(MOVDnop x6:(MOVBUloadidx ptr (ADDconst [1] idx) mem)))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (MOVDloadidx ptr idx mem) + // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUloadidx ptr0 idx0 mem))) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [3] {s} p mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUloadidx ptr0 idx0 mem)) for { t := v.Type _ = v.Args[1] - y7 := v.Args[0] - if y7.Op != OpARM64MOVDnop { - break - } - x7 := y7.Args[0] - if x7.Op != OpARM64MOVBUloadidx { - break - } - _ = x7.Args[2] - ptr := x7.Args[0] - idx := x7.Args[1] - mem := x7.Args[2] - o0 := v.Args[1] + o0 := v.Args[0] if o0.Op != OpARM64ORshiftLL { break } @@ -19183,43 +21513,11 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } _ = o1.Args[1] - o2 := o1.Args[0] - if o2.Op != OpARM64ORshiftLL { - break - } - if o2.AuxInt != 24 { - break - } - _ = o2.Args[1] - o3 := o2.Args[0] - if o3.Op != OpARM64ORshiftLL { - break - } - if o3.AuxInt != 32 { - break - } - _ = o3.Args[1] - o4 := o3.Args[0] - if o4.Op != OpARM64ORshiftLL { - break - } - if o4.AuxInt != 40 { - break - } - _ = o4.Args[1] - o5 := o4.Args[0] - if o5.Op != OpARM64ORshiftLL { - break - } - if o5.AuxInt != 48 { - break - } - _ = o5.Args[1] - s0 := o5.Args[0] + s0 := o1.Args[0] if s0.Op != OpARM64SLLconst { break } - if s0.AuxInt != 56 { + if s0.AuxInt != 24 { break } y0 := s0.Args[0] @@ -19231,187 +21529,207 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } _ = x0.Args[2] - if ptr != x0.Args[0] { - break - } - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64ADDconst { - break - } - if x0_1.AuxInt != 7 { + ptr0 := x0.Args[0] + idx0 := x0.Args[1] + mem := x0.Args[2] + y1 := o1.Args[1] + if y1.Op != OpARM64MOVDnop { break } - if idx != x0_1.Args[0] { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - if mem != x0.Args[2] { + if x1.AuxInt != 1 { break } - y1 := o5.Args[1] - if y1.Op != OpARM64MOVDnop { + s := x1.Aux + _ = x1.Args[1] + p1 := x1.Args[0] + if p1.Op != OpARM64ADD { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUloadidx { + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] + if mem != x1.Args[1] { break } - _ = x1.Args[2] - if ptr != x1.Args[0] { + y2 := o0.Args[1] + if y2.Op != OpARM64MOVDnop { break } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64ADDconst { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { break } - if x1_1.AuxInt != 6 { + if x2.AuxInt != 2 { break } - if idx != x1_1.Args[0] { + if x2.Aux != s { break } - if mem != x1.Args[2] { + _ = x2.Args[1] + p := x2.Args[0] + if mem != x2.Args[1] { break } - y2 := o4.Args[1] - if y2.Op != OpARM64MOVDnop { + y3 := v.Args[1] + if y3.Op != OpARM64MOVDnop { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUloadidx { + x3 := y3.Args[0] + if x3.Op != OpARM64MOVBUload { break } - _ = x2.Args[2] - if ptr != x2.Args[0] { + if x3.AuxInt != 3 { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64ADDconst { + if x3.Aux != s { break } - if x2_1.AuxInt != 5 { + _ = x3.Args[1] + if p != x3.Args[0] { break } - if idx != x2_1.Args[0] { + if mem != x3.Args[1] { break } - if mem != x2.Args[2] { + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { break } - y3 := o3.Args[1] + b = mergePoint(b, x0, x1, x2, x3) + v0 := b.NewValue0(v.Pos, OpARM64REVW, t) + v.reset(OpCopy) + v.AddArg(v0) + v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + v1.AddArg(ptr0) + v1.AddArg(idx0) + v1.AddArg(mem) + v0.AddArg(v1) + return true + } + // match: (OR y3:(MOVDnop x3:(MOVBUload [3] {s} p mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUloadidx ptr0 idx0 mem))) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [2] {s} p mem)))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUloadidx ptr0 idx0 mem)) + for { + t := v.Type + _ = v.Args[1] + y3 := v.Args[0] if y3.Op != OpARM64MOVDnop { break } x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUloadidx { - break - } - _ = x3.Args[2] - if ptr != x3.Args[0] { - break - } - x3_1 := x3.Args[1] - if x3_1.Op != OpARM64ADDconst { - break - } - if x3_1.AuxInt != 4 { - break - } - if idx != x3_1.Args[0] { + if x3.Op != OpARM64MOVBUload { break } - if mem != x3.Args[2] { + if x3.AuxInt != 3 { break } - y4 := o2.Args[1] - if y4.Op != OpARM64MOVDnop { + s := x3.Aux + _ = x3.Args[1] + p := x3.Args[0] + mem := x3.Args[1] + o0 := v.Args[1] + if o0.Op != OpARM64ORshiftLL { break } - x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUloadidx { + if o0.AuxInt != 8 { break } - _ = x4.Args[2] - if ptr != x4.Args[0] { + _ = o0.Args[1] + o1 := o0.Args[0] + if o1.Op != OpARM64ORshiftLL { break } - x4_1 := x4.Args[1] - if x4_1.Op != OpARM64ADDconst { + if o1.AuxInt != 16 { break } - if x4_1.AuxInt != 3 { + _ = o1.Args[1] + s0 := o1.Args[0] + if s0.Op != OpARM64SLLconst { break } - if idx != x4_1.Args[0] { + if s0.AuxInt != 24 { break } - if mem != x4.Args[2] { + y0 := s0.Args[0] + if y0.Op != OpARM64MOVDnop { break } - y5 := o1.Args[1] - if y5.Op != OpARM64MOVDnop { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUloadidx { break } - x5 := y5.Args[0] - if x5.Op != OpARM64MOVBUloadidx { + _ = x0.Args[2] + ptr0 := x0.Args[0] + idx0 := x0.Args[1] + if mem != x0.Args[2] { break } - _ = x5.Args[2] - if ptr != x5.Args[0] { + y1 := o1.Args[1] + if y1.Op != OpARM64MOVDnop { break } - x5_1 := x5.Args[1] - if x5_1.Op != OpARM64ADDconst { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - if x5_1.AuxInt != 2 { + if x1.AuxInt != 1 { break } - if idx != x5_1.Args[0] { + if x1.Aux != s { break } - if mem != x5.Args[2] { + _ = x1.Args[1] + p1 := x1.Args[0] + if p1.Op != OpARM64ADD { break } - y6 := o0.Args[1] - if y6.Op != OpARM64MOVDnop { + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] + if mem != x1.Args[1] { break } - x6 := y6.Args[0] - if x6.Op != OpARM64MOVBUloadidx { + y2 := o0.Args[1] + if y2.Op != OpARM64MOVDnop { break } - _ = x6.Args[2] - if ptr != x6.Args[0] { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { break } - x6_1 := x6.Args[1] - if x6_1.Op != OpARM64ADDconst { + if x2.AuxInt != 2 { break } - if x6_1.AuxInt != 1 { + if x2.Aux != s { break } - if idx != x6_1.Args[0] { + _ = x2.Args[1] + if p != x2.Args[0] { break } - if mem != x6.Args[2] { + if mem != x2.Args[1] { break } - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { break } - b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) - v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + b = mergePoint(b, x0, x1, x2, x3) + v0 := b.NewValue0(v.Pos, OpARM64REVW, t) v.reset(OpCopy) v.AddArg(v0) - v0.AddArg(ptr) - v0.AddArg(idx) - v0.AddArg(mem) + v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + v1.AddArg(ptr0) + v1.AddArg(idx0) + v1.AddArg(mem) + v0.AddArg(v1) return true } - // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i3] {s} p mem))) - // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUload {s} (OffPtr [i0] p) mem)) + // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUloadidx ptr idx mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUloadidx ptr idx mem)) for { t := v.Type _ = v.Args[1] @@ -19443,31 +21761,36 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUload { + if x0.Op != OpARM64MOVBUloadidx { break } - i0 := x0.AuxInt - s := x0.Aux - _ = x0.Args[1] - p := x0.Args[0] - mem := x0.Args[1] + _ = x0.Args[2] + ptr := x0.Args[0] + idx := x0.Args[1] + mem := x0.Args[2] y1 := o1.Args[1] if y1.Op != OpARM64MOVDnop { break } x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + if x1.Op != OpARM64MOVBUloadidx { break } - i1 := x1.AuxInt - if x1.Aux != s { + _ = x1.Args[2] + if ptr != x1.Args[0] { break } - _ = x1.Args[1] - if p != x1.Args[0] { + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64ADDconst { break } - if mem != x1.Args[1] { + if x1_1.AuxInt != 1 { + break + } + if idx != x1_1.Args[0] { + break + } + if mem != x1.Args[2] { break } y2 := o0.Args[1] @@ -19475,18 +21798,24 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUload { + if x2.Op != OpARM64MOVBUloadidx { break } - i2 := x2.AuxInt - if x2.Aux != s { + _ = x2.Args[2] + if ptr != x2.Args[0] { break } - _ = x2.Args[1] - if p != x2.Args[0] { + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64ADDconst { break } - if mem != x2.Args[1] { + if x2_1.AuxInt != 2 { + break + } + if idx != x2_1.Args[0] { + break + } + if mem != x2.Args[2] { break } y3 := v.Args[1] @@ -19494,40 +21823,48 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUload { + if x3.Op != OpARM64MOVBUloadidx { break } - i3 := x3.AuxInt - if x3.Aux != s { + _ = x3.Args[2] + if ptr != x3.Args[0] { break } - _ = x3.Args[1] - if p != x3.Args[0] { + x3_1 := x3.Args[1] + if x3_1.Op != OpARM64ADDconst { break } - if mem != x3.Args[1] { + if x3_1.AuxInt != 3 { break } - if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { + if idx != x3_1.Args[0] { + break + } + if mem != x3.Args[2] { + break + } + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { break } b = mergePoint(b, x0, x1, x2, x3) v0 := b.NewValue0(v.Pos, OpARM64REVW, t) v.reset(OpCopy) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVWUload, t) - v1.Aux = s - v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) - v2.AuxInt = i0 - v2.AddArg(p) - v1.AddArg(v2) + v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + v1.AddArg(ptr) + v1.AddArg(idx) v1.AddArg(mem) v0.AddArg(v1) return true } - // match: (OR y3:(MOVDnop x3:(MOVBUload [i3] {s} p mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem)))) - // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUload {s} (OffPtr [i0] p) mem)) + return false +} +func rewriteValueARM64_OpARM64OR_40(v *Value) bool { + b := v.Block + _ = b + // match: (OR y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [3] idx) mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUloadidx ptr idx mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [2] idx) mem)))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUloadidx ptr idx mem)) for { t := v.Type _ = v.Args[1] @@ -19536,14 +21873,20 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUload { + if x3.Op != OpARM64MOVBUloadidx { break } - i3 := x3.AuxInt - s := x3.Aux - _ = x3.Args[1] - p := x3.Args[0] - mem := x3.Args[1] + _ = x3.Args[2] + ptr := x3.Args[0] + x3_1 := x3.Args[1] + if x3_1.Op != OpARM64ADDconst { + break + } + if x3_1.AuxInt != 3 { + break + } + idx := x3_1.Args[0] + mem := x3.Args[2] o0 := v.Args[1] if o0.Op != OpARM64ORshiftLL { break @@ -19572,18 +21915,17 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUload { + if x0.Op != OpARM64MOVBUloadidx { break } - i0 := x0.AuxInt - if x0.Aux != s { + _ = x0.Args[2] + if ptr != x0.Args[0] { break } - _ = x0.Args[1] - if p != x0.Args[0] { + if idx != x0.Args[1] { break } - if mem != x0.Args[1] { + if mem != x0.Args[2] { break } y1 := o1.Args[1] @@ -19591,59 +21933,68 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + if x1.Op != OpARM64MOVBUloadidx { break } - i1 := x1.AuxInt - if x1.Aux != s { + _ = x1.Args[2] + if ptr != x1.Args[0] { break } - _ = x1.Args[1] - if p != x1.Args[0] { + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64ADDconst { break } - if mem != x1.Args[1] { + if x1_1.AuxInt != 1 { + break + } + if idx != x1_1.Args[0] { + break + } + if mem != x1.Args[2] { break } y2 := o0.Args[1] if y2.Op != OpARM64MOVDnop { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUload { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUloadidx { + break + } + _ = x2.Args[2] + if ptr != x2.Args[0] { + break + } + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64ADDconst { break } - i2 := x2.AuxInt - if x2.Aux != s { + if x2_1.AuxInt != 2 { break } - _ = x2.Args[1] - if p != x2.Args[0] { + if idx != x2_1.Args[0] { break } - if mem != x2.Args[1] { + if mem != x2.Args[2] { break } - if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { break } b = mergePoint(b, x0, x1, x2, x3) v0 := b.NewValue0(v.Pos, OpARM64REVW, t) v.reset(OpCopy) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVWUload, t) - v1.Aux = s - v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) - v2.AuxInt = i0 - v2.AddArg(p) - v1.AddArg(v2) + v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + v1.AddArg(ptr) + v1.AddArg(idx) v1.AddArg(mem) v0.AddArg(v1) return true } - // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUloadidx ptr0 idx0 mem))) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [3] {s} p mem))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUloadidx ptr0 idx0 mem)) + // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i3] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [i4] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [i5] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [i6] {s} p mem))) y7:(MOVDnop x7:(MOVBUload [i7] {s} p mem))) + // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDload {s} (OffPtr [i0] p) mem)) for { t := v.Type _ = v.Args[1] @@ -19663,11 +22014,43 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } _ = o1.Args[1] - s0 := o1.Args[0] + o2 := o1.Args[0] + if o2.Op != OpARM64ORshiftLL { + break + } + if o2.AuxInt != 24 { + break + } + _ = o2.Args[1] + o3 := o2.Args[0] + if o3.Op != OpARM64ORshiftLL { + break + } + if o3.AuxInt != 32 { + break + } + _ = o3.Args[1] + o4 := o3.Args[0] + if o4.Op != OpARM64ORshiftLL { + break + } + if o4.AuxInt != 40 { + break + } + _ = o4.Args[1] + o5 := o4.Args[0] + if o5.Op != OpARM64ORshiftLL { + break + } + if o5.AuxInt != 48 { + break + } + _ = o5.Args[1] + s0 := o5.Args[0] if s0.Op != OpARM64SLLconst { break } - if s0.AuxInt != 24 { + if s0.AuxInt != 56 { break } y0 := s0.Args[0] @@ -19675,14 +22058,15 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { break } x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUloadidx { + if x0.Op != OpARM64MOVBUload { break } - _ = x0.Args[2] - ptr0 := x0.Args[0] - idx0 := x0.Args[1] - mem := x0.Args[2] - y1 := o1.Args[1] + i0 := x0.AuxInt + s := x0.Aux + _ = x0.Args[1] + p := x0.Args[0] + mem := x0.Args[1] + y1 := o5.Args[1] if y1.Op != OpARM64MOVDnop { break } @@ -19690,22 +22074,18 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x1.Op != OpARM64MOVBUload { break } - if x1.AuxInt != 1 { + i1 := x1.AuxInt + if x1.Aux != s { break } - s := x1.Aux _ = x1.Args[1] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + if p != x1.Args[0] { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] if mem != x1.Args[1] { break } - y2 := o0.Args[1] + y2 := o4.Args[1] if y2.Op != OpARM64MOVDnop { break } @@ -19713,18 +22093,18 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x2.Op != OpARM64MOVBUload { break } - if x2.AuxInt != 2 { - break - } + i2 := x2.AuxInt if x2.Aux != s { break } _ = x2.Args[1] - p := x2.Args[0] + if p != x2.Args[0] { + break + } if mem != x2.Args[1] { break } - y3 := v.Args[1] + y3 := o3.Args[1] if y3.Op != OpARM64MOVDnop { break } @@ -19732,9 +22112,7 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if x3.Op != OpARM64MOVBUload { break } - if x3.AuxInt != 3 { - break - } + i3 := x3.AuxInt if x3.Aux != s { break } @@ -19745,150 +22123,119 @@ func rewriteValueARM64_OpARM64OR_20(v *Value) bool { if mem != x3.Args[1] { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { - break - } - b = mergePoint(b, x0, x1, x2, x3) - v0 := b.NewValue0(v.Pos, OpARM64REVW, t) - v.reset(OpCopy) - v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) - v1.AddArg(ptr0) - v1.AddArg(idx0) - v1.AddArg(mem) - v0.AddArg(v1) - return true - } - return false -} -func rewriteValueARM64_OpARM64OR_30(v *Value) bool { - b := v.Block - _ = b - // match: (OR y3:(MOVDnop x3:(MOVBUload [3] {s} p mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUloadidx ptr0 idx0 mem))) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [2] {s} p mem)))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUloadidx ptr0 idx0 mem)) - for { - t := v.Type - _ = v.Args[1] - y3 := v.Args[0] - if y3.Op != OpARM64MOVDnop { - break - } - x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUload { - break - } - if x3.AuxInt != 3 { - break - } - s := x3.Aux - _ = x3.Args[1] - p := x3.Args[0] - mem := x3.Args[1] - o0 := v.Args[1] - if o0.Op != OpARM64ORshiftLL { - break - } - if o0.AuxInt != 8 { + y4 := o2.Args[1] + if y4.Op != OpARM64MOVDnop { break } - _ = o0.Args[1] - o1 := o0.Args[0] - if o1.Op != OpARM64ORshiftLL { + x4 := y4.Args[0] + if x4.Op != OpARM64MOVBUload { break } - if o1.AuxInt != 16 { + i4 := x4.AuxInt + if x4.Aux != s { break } - _ = o1.Args[1] - s0 := o1.Args[0] - if s0.Op != OpARM64SLLconst { + _ = x4.Args[1] + if p != x4.Args[0] { break } - if s0.AuxInt != 24 { + if mem != x4.Args[1] { break } - y0 := s0.Args[0] - if y0.Op != OpARM64MOVDnop { + y5 := o1.Args[1] + if y5.Op != OpARM64MOVDnop { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUloadidx { + x5 := y5.Args[0] + if x5.Op != OpARM64MOVBUload { break } - _ = x0.Args[2] - ptr0 := x0.Args[0] - idx0 := x0.Args[1] - if mem != x0.Args[2] { + i5 := x5.AuxInt + if x5.Aux != s { break } - y1 := o1.Args[1] - if y1.Op != OpARM64MOVDnop { + _ = x5.Args[1] + if p != x5.Args[0] { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + if mem != x5.Args[1] { break } - if x1.AuxInt != 1 { + y6 := o0.Args[1] + if y6.Op != OpARM64MOVDnop { break } - if x1.Aux != s { + x6 := y6.Args[0] + if x6.Op != OpARM64MOVBUload { break } - _ = x1.Args[1] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + i6 := x6.AuxInt + if x6.Aux != s { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - if mem != x1.Args[1] { + _ = x6.Args[1] + if p != x6.Args[0] { break } - y2 := o0.Args[1] - if y2.Op != OpARM64MOVDnop { + if mem != x6.Args[1] { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUload { + y7 := v.Args[1] + if y7.Op != OpARM64MOVDnop { break } - if x2.AuxInt != 2 { + x7 := y7.Args[0] + if x7.Op != OpARM64MOVBUload { break } - if x2.Aux != s { + i7 := x7.AuxInt + if x7.Aux != s { break } - _ = x2.Args[1] - if p != x2.Args[0] { + _ = x7.Args[1] + if p != x7.Args[0] { break } - if mem != x2.Args[1] { + if mem != x7.Args[1] { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { + if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { break } - b = mergePoint(b, x0, x1, x2, x3) - v0 := b.NewValue0(v.Pos, OpARM64REVW, t) + b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) + v0 := b.NewValue0(v.Pos, OpARM64REV, t) v.reset(OpCopy) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) - v1.AddArg(ptr0) - v1.AddArg(idx0) + v1 := b.NewValue0(v.Pos, OpARM64MOVDload, t) + v1.Aux = s + v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) + v2.AuxInt = i0 + v2.AddArg(p) + v1.AddArg(v2) v1.AddArg(mem) v0.AddArg(v1) return true } - // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUloadidx ptr idx mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUloadidx ptr idx mem)) + // match: (OR y7:(MOVDnop x7:(MOVBUload [i7] {s} p mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i3] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [i4] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [i5] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [i6] {s} p mem)))) + // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDload {s} (OffPtr [i0] p) mem)) for { t := v.Type _ = v.Args[1] - o0 := v.Args[0] + y7 := v.Args[0] + if y7.Op != OpARM64MOVDnop { + break + } + x7 := y7.Args[0] + if x7.Op != OpARM64MOVBUload { + break + } + i7 := x7.AuxInt + s := x7.Aux + _ = x7.Args[1] + p := x7.Args[0] + mem := x7.Args[1] + o0 := v.Args[1] if o0.Op != OpARM64ORshiftLL { break } @@ -19904,247 +22251,198 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } _ = o1.Args[1] - s0 := o1.Args[0] - if s0.Op != OpARM64SLLconst { - break - } - if s0.AuxInt != 24 { + o2 := o1.Args[0] + if o2.Op != OpARM64ORshiftLL { break } - y0 := s0.Args[0] - if y0.Op != OpARM64MOVDnop { + if o2.AuxInt != 24 { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUloadidx { + _ = o2.Args[1] + o3 := o2.Args[0] + if o3.Op != OpARM64ORshiftLL { break } - _ = x0.Args[2] - ptr := x0.Args[0] - idx := x0.Args[1] - mem := x0.Args[2] - y1 := o1.Args[1] - if y1.Op != OpARM64MOVDnop { + if o3.AuxInt != 32 { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUloadidx { + _ = o3.Args[1] + o4 := o3.Args[0] + if o4.Op != OpARM64ORshiftLL { break } - _ = x1.Args[2] - if ptr != x1.Args[0] { + if o4.AuxInt != 40 { break } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64ADDconst { + _ = o4.Args[1] + o5 := o4.Args[0] + if o5.Op != OpARM64ORshiftLL { break } - if x1_1.AuxInt != 1 { + if o5.AuxInt != 48 { break } - if idx != x1_1.Args[0] { + _ = o5.Args[1] + s0 := o5.Args[0] + if s0.Op != OpARM64SLLconst { break } - if mem != x1.Args[2] { + if s0.AuxInt != 56 { break } - y2 := o0.Args[1] - if y2.Op != OpARM64MOVDnop { + y0 := s0.Args[0] + if y0.Op != OpARM64MOVDnop { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUloadidx { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUload { break } - _ = x2.Args[2] - if ptr != x2.Args[0] { + i0 := x0.AuxInt + if x0.Aux != s { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64ADDconst { + _ = x0.Args[1] + if p != x0.Args[0] { break } - if x2_1.AuxInt != 2 { + if mem != x0.Args[1] { break } - if idx != x2_1.Args[0] { + y1 := o5.Args[1] + if y1.Op != OpARM64MOVDnop { break } - if mem != x2.Args[2] { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - y3 := v.Args[1] - if y3.Op != OpARM64MOVDnop { + i1 := x1.AuxInt + if x1.Aux != s { break } - x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUloadidx { + _ = x1.Args[1] + if p != x1.Args[0] { break } - _ = x3.Args[2] - if ptr != x3.Args[0] { + if mem != x1.Args[1] { break } - x3_1 := x3.Args[1] - if x3_1.Op != OpARM64ADDconst { + y2 := o4.Args[1] + if y2.Op != OpARM64MOVDnop { break } - if x3_1.AuxInt != 3 { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { break } - if idx != x3_1.Args[0] { + i2 := x2.AuxInt + if x2.Aux != s { break } - if mem != x3.Args[2] { + _ = x2.Args[1] + if p != x2.Args[0] { break } - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { + if mem != x2.Args[1] { break } - b = mergePoint(b, x0, x1, x2, x3) - v0 := b.NewValue0(v.Pos, OpARM64REVW, t) - v.reset(OpCopy) - v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) - v1.AddArg(ptr) - v1.AddArg(idx) - v1.AddArg(mem) - v0.AddArg(v1) - return true - } - // match: (OR y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [3] idx) mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] s0:(SLLconst [24] y0:(MOVDnop x0:(MOVBUloadidx ptr idx mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [2] idx) mem)))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3) (REVW (MOVWUloadidx ptr idx mem)) - for { - t := v.Type - _ = v.Args[1] - y3 := v.Args[0] + y3 := o3.Args[1] if y3.Op != OpARM64MOVDnop { break } x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUloadidx { - break - } - _ = x3.Args[2] - ptr := x3.Args[0] - x3_1 := x3.Args[1] - if x3_1.Op != OpARM64ADDconst { - break - } - if x3_1.AuxInt != 3 { - break - } - idx := x3_1.Args[0] - mem := x3.Args[2] - o0 := v.Args[1] - if o0.Op != OpARM64ORshiftLL { - break - } - if o0.AuxInt != 8 { - break - } - _ = o0.Args[1] - o1 := o0.Args[0] - if o1.Op != OpARM64ORshiftLL { - break - } - if o1.AuxInt != 16 { - break - } - _ = o1.Args[1] - s0 := o1.Args[0] - if s0.Op != OpARM64SLLconst { - break - } - if s0.AuxInt != 24 { - break - } - y0 := s0.Args[0] - if y0.Op != OpARM64MOVDnop { + if x3.Op != OpARM64MOVBUload { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUloadidx { + i3 := x3.AuxInt + if x3.Aux != s { break } - _ = x0.Args[2] - if ptr != x0.Args[0] { + _ = x3.Args[1] + if p != x3.Args[0] { break } - if idx != x0.Args[1] { + if mem != x3.Args[1] { break } - if mem != x0.Args[2] { + y4 := o2.Args[1] + if y4.Op != OpARM64MOVDnop { break } - y1 := o1.Args[1] - if y1.Op != OpARM64MOVDnop { + x4 := y4.Args[0] + if x4.Op != OpARM64MOVBUload { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUloadidx { + i4 := x4.AuxInt + if x4.Aux != s { break } - _ = x1.Args[2] - if ptr != x1.Args[0] { + _ = x4.Args[1] + if p != x4.Args[0] { break } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64ADDconst { + if mem != x4.Args[1] { break } - if x1_1.AuxInt != 1 { + y5 := o1.Args[1] + if y5.Op != OpARM64MOVDnop { break } - if idx != x1_1.Args[0] { + x5 := y5.Args[0] + if x5.Op != OpARM64MOVBUload { break } - if mem != x1.Args[2] { + i5 := x5.AuxInt + if x5.Aux != s { break } - y2 := o0.Args[1] - if y2.Op != OpARM64MOVDnop { + _ = x5.Args[1] + if p != x5.Args[0] { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUloadidx { + if mem != x5.Args[1] { break } - _ = x2.Args[2] - if ptr != x2.Args[0] { + y6 := o0.Args[1] + if y6.Op != OpARM64MOVDnop { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64ADDconst { + x6 := y6.Args[0] + if x6.Op != OpARM64MOVBUload { break } - if x2_1.AuxInt != 2 { + i6 := x6.AuxInt + if x6.Aux != s { break } - if idx != x2_1.Args[0] { + _ = x6.Args[1] + if p != x6.Args[0] { break } - if mem != x2.Args[2] { + if mem != x6.Args[1] { break } - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(o0) && clobber(o1) && clobber(s0)) { + if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { break } - b = mergePoint(b, x0, x1, x2, x3) - v0 := b.NewValue0(v.Pos, OpARM64REVW, t) + b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) + v0 := b.NewValue0(v.Pos, OpARM64REV, t) v.reset(OpCopy) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) - v1.AddArg(ptr) - v1.AddArg(idx) + v1 := b.NewValue0(v.Pos, OpARM64MOVDload, t) + v1.Aux = s + v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) + v2.AuxInt = i0 + v2.AddArg(p) + v1.AddArg(v2) v1.AddArg(mem) v0.AddArg(v1) return true } - // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i3] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [i4] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [i5] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [i6] {s} p mem))) y7:(MOVDnop x7:(MOVBUload [i7] {s} p mem))) - // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDload {s} (OffPtr [i0] p) mem)) + // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr0 idx0 mem))) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [3] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [4] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [5] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [6] {s} p mem))) y7:(MOVDnop x7:(MOVBUload [7] {s} p mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDloadidx ptr0 idx0 mem)) for { t := v.Type _ = v.Args[1] @@ -20208,14 +22506,13 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUload { + if x0.Op != OpARM64MOVBUloadidx { break } - i0 := x0.AuxInt - s := x0.Aux - _ = x0.Args[1] - p := x0.Args[0] - mem := x0.Args[1] + _ = x0.Args[2] + ptr0 := x0.Args[0] + idx0 := x0.Args[1] + mem := x0.Args[2] y1 := o5.Args[1] if y1.Op != OpARM64MOVDnop { break @@ -20224,14 +22521,18 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x1.Op != OpARM64MOVBUload { break } - i1 := x1.AuxInt - if x1.Aux != s { + if x1.AuxInt != 1 { break } + s := x1.Aux _ = x1.Args[1] - if p != x1.Args[0] { + p1 := x1.Args[0] + if p1.Op != OpARM64ADD { break } + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] if mem != x1.Args[1] { break } @@ -20243,14 +22544,14 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x2.Op != OpARM64MOVBUload { break } - i2 := x2.AuxInt - if x2.Aux != s { + if x2.AuxInt != 2 { break } - _ = x2.Args[1] - if p != x2.Args[0] { + if x2.Aux != s { break } + _ = x2.Args[1] + p := x2.Args[0] if mem != x2.Args[1] { break } @@ -20262,7 +22563,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x3.Op != OpARM64MOVBUload { break } - i3 := x3.AuxInt + if x3.AuxInt != 3 { + break + } if x3.Aux != s { break } @@ -20281,7 +22584,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x4.Op != OpARM64MOVBUload { break } - i4 := x4.AuxInt + if x4.AuxInt != 4 { + break + } if x4.Aux != s { break } @@ -20300,7 +22605,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x5.Op != OpARM64MOVBUload { break } - i5 := x5.AuxInt + if x5.AuxInt != 5 { + break + } if x5.Aux != s { break } @@ -20319,7 +22626,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x6.Op != OpARM64MOVBUload { break } - i6 := x6.AuxInt + if x6.AuxInt != 6 { + break + } if x6.Aux != s { break } @@ -20338,7 +22647,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x7.Op != OpARM64MOVBUload { break } - i7 := x7.AuxInt + if x7.AuxInt != 7 { + break + } if x7.Aux != s { break } @@ -20349,26 +22660,23 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if mem != x7.Args[1] { break } - if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { break } b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) v0 := b.NewValue0(v.Pos, OpARM64REV, t) v.reset(OpCopy) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVDload, t) - v1.Aux = s - v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) - v2.AuxInt = i0 - v2.AddArg(p) - v1.AddArg(v2) + v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v1.AddArg(ptr0) + v1.AddArg(idx0) v1.AddArg(mem) v0.AddArg(v1) return true } - // match: (OR y7:(MOVDnop x7:(MOVBUload [i7] {s} p mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem))) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i3] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [i4] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [i5] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [i6] {s} p mem)))) - // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDload {s} (OffPtr [i0] p) mem)) + // match: (OR y7:(MOVDnop x7:(MOVBUload [7] {s} p mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr0 idx0 mem))) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [3] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [4] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [5] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [6] {s} p mem)))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDloadidx ptr0 idx0 mem)) for { t := v.Type _ = v.Args[1] @@ -20380,7 +22688,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x7.Op != OpARM64MOVBUload { break } - i7 := x7.AuxInt + if x7.AuxInt != 7 { + break + } s := x7.Aux _ = x7.Args[1] p := x7.Args[0] @@ -20445,18 +22755,13 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUload { - break - } - i0 := x0.AuxInt - if x0.Aux != s { - break - } - _ = x0.Args[1] - if p != x0.Args[0] { + if x0.Op != OpARM64MOVBUloadidx { break } - if mem != x0.Args[1] { + _ = x0.Args[2] + ptr0 := x0.Args[0] + idx0 := x0.Args[1] + if mem != x0.Args[2] { break } y1 := o5.Args[1] @@ -20467,14 +22772,20 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x1.Op != OpARM64MOVBUload { break } - i1 := x1.AuxInt + if x1.AuxInt != 1 { + break + } if x1.Aux != s { break } _ = x1.Args[1] - if p != x1.Args[0] { + p1 := x1.Args[0] + if p1.Op != OpARM64ADD { break } + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] if mem != x1.Args[1] { break } @@ -20486,7 +22797,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x2.Op != OpARM64MOVBUload { break } - i2 := x2.AuxInt + if x2.AuxInt != 2 { + break + } if x2.Aux != s { break } @@ -20505,7 +22818,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x3.Op != OpARM64MOVBUload { break } - i3 := x3.AuxInt + if x3.AuxInt != 3 { + break + } if x3.Aux != s { break } @@ -20524,7 +22839,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x4.Op != OpARM64MOVBUload { break } - i4 := x4.AuxInt + if x4.AuxInt != 4 { + break + } if x4.Aux != s { break } @@ -20543,7 +22860,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x5.Op != OpARM64MOVBUload { break } - i5 := x5.AuxInt + if x5.AuxInt != 5 { + break + } if x5.Aux != s { break } @@ -20562,7 +22881,9 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x6.Op != OpARM64MOVBUload { break } - i6 := x6.AuxInt + if x6.AuxInt != 6 { + break + } if x6.Aux != s { break } @@ -20573,26 +22894,23 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if mem != x6.Args[1] { break } - if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { break } b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) v0 := b.NewValue0(v.Pos, OpARM64REV, t) v.reset(OpCopy) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVDload, t) - v1.Aux = s - v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) - v2.AuxInt = i0 - v2.AddArg(p) - v1.AddArg(v2) + v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v1.AddArg(ptr0) + v1.AddArg(idx0) v1.AddArg(mem) v0.AddArg(v1) return true } - // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr0 idx0 mem))) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [3] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [4] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [5] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [6] {s} p mem))) y7:(MOVDnop x7:(MOVBUload [7] {s} p mem))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDloadidx ptr0 idx0 mem)) + // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr idx mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr (ADDconst [4] idx) mem))) y5:(MOVDnop x5:(MOVBUloadidx ptr (ADDconst [5] idx) mem))) y6:(MOVDnop x6:(MOVBUloadidx ptr (ADDconst [6] idx) mem))) y7:(MOVDnop x7:(MOVBUloadidx ptr (ADDconst [7] idx) mem))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDloadidx ptr idx mem)) for { t := v.Type _ = v.Args[1] @@ -20660,30 +22978,32 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } _ = x0.Args[2] - ptr0 := x0.Args[0] - idx0 := x0.Args[1] + ptr := x0.Args[0] + idx := x0.Args[1] mem := x0.Args[2] y1 := o5.Args[1] if y1.Op != OpARM64MOVDnop { break } x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + if x1.Op != OpARM64MOVBUloadidx { break } - if x1.AuxInt != 1 { + _ = x1.Args[2] + if ptr != x1.Args[0] { break } - s := x1.Aux - _ = x1.Args[1] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64ADDconst { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - if mem != x1.Args[1] { + if x1_1.AuxInt != 1 { + break + } + if idx != x1_1.Args[0] { + break + } + if mem != x1.Args[2] { break } y2 := o4.Args[1] @@ -20691,18 +23011,24 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUload { + if x2.Op != OpARM64MOVBUloadidx { break } - if x2.AuxInt != 2 { + _ = x2.Args[2] + if ptr != x2.Args[0] { break } - if x2.Aux != s { + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64ADDconst { break } - _ = x2.Args[1] - p := x2.Args[0] - if mem != x2.Args[1] { + if x2_1.AuxInt != 2 { + break + } + if idx != x2_1.Args[0] { + break + } + if mem != x2.Args[2] { break } y3 := o3.Args[1] @@ -20710,20 +23036,24 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUload { + if x3.Op != OpARM64MOVBUloadidx { break } - if x3.AuxInt != 3 { + _ = x3.Args[2] + if ptr != x3.Args[0] { break } - if x3.Aux != s { + x3_1 := x3.Args[1] + if x3_1.Op != OpARM64ADDconst { break } - _ = x3.Args[1] - if p != x3.Args[0] { + if x3_1.AuxInt != 3 { break } - if mem != x3.Args[1] { + if idx != x3_1.Args[0] { + break + } + if mem != x3.Args[2] { break } y4 := o2.Args[1] @@ -20731,20 +23061,24 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUload { + if x4.Op != OpARM64MOVBUloadidx { break } - if x4.AuxInt != 4 { + _ = x4.Args[2] + if ptr != x4.Args[0] { break } - if x4.Aux != s { + x4_1 := x4.Args[1] + if x4_1.Op != OpARM64ADDconst { break } - _ = x4.Args[1] - if p != x4.Args[0] { + if x4_1.AuxInt != 4 { break } - if mem != x4.Args[1] { + if idx != x4_1.Args[0] { + break + } + if mem != x4.Args[2] { break } y5 := o1.Args[1] @@ -20752,20 +23086,24 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x5 := y5.Args[0] - if x5.Op != OpARM64MOVBUload { + if x5.Op != OpARM64MOVBUloadidx { break } - if x5.AuxInt != 5 { + _ = x5.Args[2] + if ptr != x5.Args[0] { break } - if x5.Aux != s { + x5_1 := x5.Args[1] + if x5_1.Op != OpARM64ADDconst { break } - _ = x5.Args[1] - if p != x5.Args[0] { + if x5_1.AuxInt != 5 { break } - if mem != x5.Args[1] { + if idx != x5_1.Args[0] { + break + } + if mem != x5.Args[2] { break } y6 := o0.Args[1] @@ -20773,20 +23111,24 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x6 := y6.Args[0] - if x6.Op != OpARM64MOVBUload { + if x6.Op != OpARM64MOVBUloadidx { break } - if x6.AuxInt != 6 { + _ = x6.Args[2] + if ptr != x6.Args[0] { break } - if x6.Aux != s { + x6_1 := x6.Args[1] + if x6_1.Op != OpARM64ADDconst { break } - _ = x6.Args[1] - if p != x6.Args[0] { + if x6_1.AuxInt != 6 { break } - if mem != x6.Args[1] { + if idx != x6_1.Args[0] { + break + } + if mem != x6.Args[2] { break } y7 := v.Args[1] @@ -20794,23 +23136,27 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x7 := y7.Args[0] - if x7.Op != OpARM64MOVBUload { + if x7.Op != OpARM64MOVBUloadidx { break } - if x7.AuxInt != 7 { + _ = x7.Args[2] + if ptr != x7.Args[0] { break } - if x7.Aux != s { + x7_1 := x7.Args[1] + if x7_1.Op != OpARM64ADDconst { break } - _ = x7.Args[1] - if p != x7.Args[0] { + if x7_1.AuxInt != 7 { break } - if mem != x7.Args[1] { + if idx != x7_1.Args[0] { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + if mem != x7.Args[2] { + break + } + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { break } b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) @@ -20818,15 +23164,15 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { v.reset(OpCopy) v.AddArg(v0) v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) - v1.AddArg(ptr0) - v1.AddArg(idx0) + v1.AddArg(ptr) + v1.AddArg(idx) v1.AddArg(mem) v0.AddArg(v1) return true } - // match: (OR y7:(MOVDnop x7:(MOVBUload [7] {s} p mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr0 idx0 mem))) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [3] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [4] {s} p mem))) y5:(MOVDnop x5:(MOVBUload [5] {s} p mem))) y6:(MOVDnop x6:(MOVBUload [6] {s} p mem)))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDloadidx ptr0 idx0 mem)) + // match: (OR y7:(MOVDnop x7:(MOVBUloadidx ptr (ADDconst [7] idx) mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr idx mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr (ADDconst [4] idx) mem))) y5:(MOVDnop x5:(MOVBUloadidx ptr (ADDconst [5] idx) mem))) y6:(MOVDnop x6:(MOVBUloadidx ptr (ADDconst [6] idx) mem)))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) + // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDloadidx ptr idx mem)) for { t := v.Type _ = v.Args[1] @@ -20835,16 +23181,20 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x7 := y7.Args[0] - if x7.Op != OpARM64MOVBUload { + if x7.Op != OpARM64MOVBUloadidx { + break + } + _ = x7.Args[2] + ptr := x7.Args[0] + x7_1 := x7.Args[1] + if x7_1.Op != OpARM64ADDconst { break } - if x7.AuxInt != 7 { + if x7_1.AuxInt != 7 { break } - s := x7.Aux - _ = x7.Args[1] - p := x7.Args[0] - mem := x7.Args[1] + idx := x7_1.Args[0] + mem := x7.Args[2] o0 := v.Args[1] if o0.Op != OpARM64ORshiftLL { break @@ -20909,8 +23259,12 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } _ = x0.Args[2] - ptr0 := x0.Args[0] - idx0 := x0.Args[1] + if ptr != x0.Args[0] { + break + } + if idx != x0.Args[1] { + break + } if mem != x0.Args[2] { break } @@ -20919,24 +23273,24 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + if x1.Op != OpARM64MOVBUloadidx { break } - if x1.AuxInt != 1 { + _ = x1.Args[2] + if ptr != x1.Args[0] { break } - if x1.Aux != s { + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64ADDconst { break } - _ = x1.Args[1] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + if x1_1.AuxInt != 1 { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - if mem != x1.Args[1] { + if idx != x1_1.Args[0] { + break + } + if mem != x1.Args[2] { break } y2 := o4.Args[1] @@ -20944,20 +23298,24 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUload { + if x2.Op != OpARM64MOVBUloadidx { break } - if x2.AuxInt != 2 { + _ = x2.Args[2] + if ptr != x2.Args[0] { break } - if x2.Aux != s { + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64ADDconst { break } - _ = x2.Args[1] - if p != x2.Args[0] { + if x2_1.AuxInt != 2 { break } - if mem != x2.Args[1] { + if idx != x2_1.Args[0] { + break + } + if mem != x2.Args[2] { break } y3 := o3.Args[1] @@ -20965,460 +23323,955 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUload { + if x3.Op != OpARM64MOVBUloadidx { break } - if x3.AuxInt != 3 { + _ = x3.Args[2] + if ptr != x3.Args[0] { break } - if x3.Aux != s { + x3_1 := x3.Args[1] + if x3_1.Op != OpARM64ADDconst { break } - _ = x3.Args[1] - if p != x3.Args[0] { + if x3_1.AuxInt != 3 { break } - if mem != x3.Args[1] { + if idx != x3_1.Args[0] { + break + } + if mem != x3.Args[2] { break } y4 := o2.Args[1] if y4.Op != OpARM64MOVDnop { break } - x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUload { + x4 := y4.Args[0] + if x4.Op != OpARM64MOVBUloadidx { + break + } + _ = x4.Args[2] + if ptr != x4.Args[0] { + break + } + x4_1 := x4.Args[1] + if x4_1.Op != OpARM64ADDconst { + break + } + if x4_1.AuxInt != 4 { + break + } + if idx != x4_1.Args[0] { + break + } + if mem != x4.Args[2] { + break + } + y5 := o1.Args[1] + if y5.Op != OpARM64MOVDnop { + break + } + x5 := y5.Args[0] + if x5.Op != OpARM64MOVBUloadidx { + break + } + _ = x5.Args[2] + if ptr != x5.Args[0] { + break + } + x5_1 := x5.Args[1] + if x5_1.Op != OpARM64ADDconst { + break + } + if x5_1.AuxInt != 5 { + break + } + if idx != x5_1.Args[0] { + break + } + if mem != x5.Args[2] { + break + } + y6 := o0.Args[1] + if y6.Op != OpARM64MOVDnop { + break + } + x6 := y6.Args[0] + if x6.Op != OpARM64MOVBUloadidx { + break + } + _ = x6.Args[2] + if ptr != x6.Args[0] { + break + } + x6_1 := x6.Args[1] + if x6_1.Op != OpARM64ADDconst { + break + } + if x6_1.AuxInt != 6 { + break + } + if idx != x6_1.Args[0] { + break + } + if mem != x6.Args[2] { + break + } + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + break + } + b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) + v0 := b.NewValue0(v.Pos, OpARM64REV, t) + v.reset(OpCopy) + v.AddArg(v0) + v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v1.AddArg(ptr) + v1.AddArg(idx) + v1.AddArg(mem) + v0.AddArg(v1) + return true + } + return false +} +func rewriteValueARM64_OpARM64ORN_0(v *Value) bool { + // match: (ORN x (MOVDconst [c])) + // cond: + // result: (ORconst [^c] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64ORconst) + v.AuxInt = ^c + v.AddArg(x) + return true + } + // match: (ORN x x) + // cond: + // result: (MOVDconst [-1]) + for { + _ = v.Args[1] + x := v.Args[0] + if x != v.Args[1] { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = -1 + return true + } + // match: (ORN x0 x1:(SLLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (ORNshiftLL x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SLLconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64ORNshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (ORN x0 x1:(SRLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (ORNshiftRL x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRLconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64ORNshiftRL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (ORN x0 x1:(SRAconst [c] y)) + // cond: clobberIfDead(x1) + // result: (ORNshiftRA x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRAconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64ORNshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + return false +} +func rewriteValueARM64_OpARM64ORNshiftLL_0(v *Value) bool { + // match: (ORNshiftLL x (MOVDconst [c]) [d]) + // cond: + // result: (ORconst x [^int64(uint64(c)<>uint64(d))]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if mem != x4.Args[1] { + c := v_1.AuxInt + v.reset(OpARM64ORconst) + v.AuxInt = ^(c >> uint64(d)) + v.AddArg(x) + return true + } + // match: (ORNshiftRA x (SRAconst x [c]) [d]) + // cond: c==d + // result: (MOVDconst [-1]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRAconst { break } - y5 := o1.Args[1] - if y5.Op != OpARM64MOVDnop { + c := v_1.AuxInt + if x != v_1.Args[0] { break } - x5 := y5.Args[0] - if x5.Op != OpARM64MOVBUload { + if !(c == d) { break } - if x5.AuxInt != 5 { + v.reset(OpARM64MOVDconst) + v.AuxInt = -1 + return true + } + return false +} +func rewriteValueARM64_OpARM64ORNshiftRL_0(v *Value) bool { + // match: (ORNshiftRL x (MOVDconst [c]) [d]) + // cond: + // result: (ORconst x [^int64(uint64(c)>>uint64(d))]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if x5.Aux != s { + c := v_1.AuxInt + v.reset(OpARM64ORconst) + v.AuxInt = ^int64(uint64(c) >> uint64(d)) + v.AddArg(x) + return true + } + // match: (ORNshiftRL x (SRLconst x [c]) [d]) + // cond: c==d + // result: (MOVDconst [-1]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - _ = x5.Args[1] - if p != x5.Args[0] { + c := v_1.AuxInt + if x != v_1.Args[0] { break } - if mem != x5.Args[1] { + if !(c == d) { break } - y6 := o0.Args[1] - if y6.Op != OpARM64MOVDnop { + v.reset(OpARM64MOVDconst) + v.AuxInt = -1 + return true + } + return false +} +func rewriteValueARM64_OpARM64ORconst_0(v *Value) bool { + // match: (ORconst [0] x) + // cond: + // result: x + for { + if v.AuxInt != 0 { break } - x6 := y6.Args[0] - if x6.Op != OpARM64MOVBUload { + x := v.Args[0] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (ORconst [-1] _) + // cond: + // result: (MOVDconst [-1]) + for { + if v.AuxInt != -1 { break } - if x6.AuxInt != 6 { + v.reset(OpARM64MOVDconst) + v.AuxInt = -1 + return true + } + // match: (ORconst [c] (MOVDconst [d])) + // cond: + // result: (MOVDconst [c|d]) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x6.Aux != s { + d := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = c | d + return true + } + // match: (ORconst [c] (ORconst [d] x)) + // cond: + // result: (ORconst [c|d] x) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64ORconst { break } - _ = x6.Args[1] - if p != x6.Args[0] { + d := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ORconst) + v.AuxInt = c | d + v.AddArg(x) + return true + } + // match: (ORconst [c1] (ANDconst [c2] x)) + // cond: c2|c1 == ^0 + // result: (ORconst [c1] x) + for { + c1 := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64ANDconst { break } - if mem != x6.Args[1] { + c2 := v_0.AuxInt + x := v_0.Args[0] + if !(c2|c1 == ^0) { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + v.reset(OpARM64ORconst) + v.AuxInt = c1 + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64ORshiftLL_0(v *Value) bool { + b := v.Block + _ = b + // match: (ORshiftLL (MOVDconst [c]) x [d]) + // cond: + // result: (ORconst [c] (SLLconst x [d])) + for { + d := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) - v0 := b.NewValue0(v.Pos, OpARM64REV, t) - v.reset(OpCopy) + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64ORconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) - v1.AddArg(ptr0) - v1.AddArg(idx0) - v1.AddArg(mem) - v0.AddArg(v1) return true } - // match: (OR o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr idx mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr (ADDconst [4] idx) mem))) y5:(MOVDnop x5:(MOVBUloadidx ptr (ADDconst [5] idx) mem))) y6:(MOVDnop x6:(MOVBUloadidx ptr (ADDconst [6] idx) mem))) y7:(MOVDnop x7:(MOVBUloadidx ptr (ADDconst [7] idx) mem))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDloadidx ptr idx mem)) + // match: (ORshiftLL x (MOVDconst [c]) [d]) + // cond: + // result: (ORconst x [int64(uint64(c)< [c] (UBFX [bfc] x) x) + // cond: c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c) + // result: (RORWconst [32-c] x) + for { + t := v.Type + c := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64UBFX { break } - _ = o5.Args[1] - s0 := o5.Args[0] - if s0.Op != OpARM64SLLconst { + bfc := v_0.AuxInt + x := v_0.Args[0] + if x != v.Args[1] { break } - if s0.AuxInt != 56 { + if !(c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c)) { break } - y0 := s0.Args[0] - if y0.Op != OpARM64MOVDnop { + v.reset(OpARM64RORWconst) + v.AuxInt = 32 - c + v.AddArg(x) + return true + } + // match: (ORshiftLL [c] (SRLconst x [64-c]) x2) + // cond: + // result: (EXTRconst [64-c] x2 x) + for { + c := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64SRLconst { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUloadidx { + if v_0.AuxInt != 64-c { break } - _ = x0.Args[2] - ptr := x0.Args[0] - idx := x0.Args[1] - mem := x0.Args[2] - y1 := o5.Args[1] - if y1.Op != OpARM64MOVDnop { + x := v_0.Args[0] + x2 := v.Args[1] + v.reset(OpARM64EXTRconst) + v.AuxInt = 64 - c + v.AddArg(x2) + v.AddArg(x) + return true + } + // match: (ORshiftLL [c] (UBFX [bfc] x) x2) + // cond: c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c) + // result: (EXTRWconst [32-c] x2 x) + for { + t := v.Type + c := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64UBFX { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUloadidx { + bfc := v_0.AuxInt + x := v_0.Args[0] + x2 := v.Args[1] + if !(c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c)) { break } - _ = x1.Args[2] - if ptr != x1.Args[0] { + v.reset(OpARM64EXTRWconst) + v.AuxInt = 32 - c + v.AddArg(x2) + v.AddArg(x) + return true + } + // match: (ORshiftLL [sc] (UBFX [bfc] x) (SRLconst [sc] y)) + // cond: sc == getARM64BFwidth(bfc) + // result: (BFXIL [bfc] y x) + for { + sc := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64UBFX { break } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64ADDconst { + bfc := v_0.AuxInt + x := v_0.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - if x1_1.AuxInt != 1 { + if v_1.AuxInt != sc { break } - if idx != x1_1.Args[0] { + y := v_1.Args[0] + if !(sc == getARM64BFwidth(bfc)) { break } - if mem != x1.Args[2] { + v.reset(OpARM64BFXIL) + v.AuxInt = bfc + v.AddArg(y) + v.AddArg(x) + return true + } + // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) + // cond: i1 == i0+1 && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) + // result: @mergePoint(b,x0,x1) (MOVHUload {s} (OffPtr [i0] p) mem) + for { + t := v.Type + if v.AuxInt != 8 { break } - y2 := o4.Args[1] - if y2.Op != OpARM64MOVDnop { + _ = v.Args[1] + y0 := v.Args[0] + if y0.Op != OpARM64MOVDnop { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUloadidx { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUload { break } - _ = x2.Args[2] - if ptr != x2.Args[0] { + i0 := x0.AuxInt + s := x0.Aux + _ = x0.Args[1] + p := x0.Args[0] + mem := x0.Args[1] + y1 := v.Args[1] + if y1.Op != OpARM64MOVDnop { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64ADDconst { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - if x2_1.AuxInt != 2 { + i1 := x1.AuxInt + if x1.Aux != s { break } - if idx != x2_1.Args[0] { + _ = x1.Args[1] + if p != x1.Args[0] { break } - if mem != x2.Args[2] { + if mem != x1.Args[1] { break } - y3 := o3.Args[1] - if y3.Op != OpARM64MOVDnop { + if !(i1 == i0+1 && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { break } - x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUloadidx { + b = mergePoint(b, x0, x1) + v0 := b.NewValue0(v.Pos, OpARM64MOVHUload, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.Aux = s + v1 := b.NewValue0(v.Pos, OpOffPtr, p.Type) + v1.AuxInt = i0 + v1.AddArg(p) + v0.AddArg(v1) + v0.AddArg(mem) + return true + } + // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUloadidx ptr0 idx0 mem)) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) + // result: @mergePoint(b,x0,x1) (MOVHUloadidx ptr0 idx0 mem) + for { + t := v.Type + if v.AuxInt != 8 { break } - _ = x3.Args[2] - if ptr != x3.Args[0] { + _ = v.Args[1] + y0 := v.Args[0] + if y0.Op != OpARM64MOVDnop { break } - x3_1 := x3.Args[1] - if x3_1.Op != OpARM64ADDconst { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUloadidx { break } - if x3_1.AuxInt != 3 { + _ = x0.Args[2] + ptr0 := x0.Args[0] + idx0 := x0.Args[1] + mem := x0.Args[2] + y1 := v.Args[1] + if y1.Op != OpARM64MOVDnop { break } - if idx != x3_1.Args[0] { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - if mem != x3.Args[2] { + if x1.AuxInt != 1 { break } - y4 := o2.Args[1] - if y4.Op != OpARM64MOVDnop { + s := x1.Aux + _ = x1.Args[1] + p1 := x1.Args[0] + if p1.Op != OpARM64ADD { break } - x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUloadidx { + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] + if mem != x1.Args[1] { break } - _ = x4.Args[2] - if ptr != x4.Args[0] { + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { break } - x4_1 := x4.Args[1] - if x4_1.Op != OpARM64ADDconst { + b = mergePoint(b, x0, x1) + v0 := b.NewValue0(v.Pos, OpARM64MOVHUloadidx, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.AddArg(ptr0) + v0.AddArg(idx0) + v0.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { + b := v.Block + _ = b + // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUloadidx ptr idx mem)) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) + // cond: x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) + // result: @mergePoint(b,x0,x1) (MOVHUloadidx ptr idx mem) + for { + t := v.Type + if v.AuxInt != 8 { break } - if x4_1.AuxInt != 4 { + _ = v.Args[1] + y0 := v.Args[0] + if y0.Op != OpARM64MOVDnop { break } - if idx != x4_1.Args[0] { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUloadidx { break } - if mem != x4.Args[2] { + _ = x0.Args[2] + ptr := x0.Args[0] + idx := x0.Args[1] + mem := x0.Args[2] + y1 := v.Args[1] + if y1.Op != OpARM64MOVDnop { break } - y5 := o1.Args[1] - if y5.Op != OpARM64MOVDnop { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUloadidx { break } - x5 := y5.Args[0] - if x5.Op != OpARM64MOVBUloadidx { + _ = x1.Args[2] + if ptr != x1.Args[0] { break } - _ = x5.Args[2] - if ptr != x5.Args[0] { + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64ADDconst { break } - x5_1 := x5.Args[1] - if x5_1.Op != OpARM64ADDconst { + if x1_1.AuxInt != 1 { break } - if x5_1.AuxInt != 5 { + if idx != x1_1.Args[0] { break } - if idx != x5_1.Args[0] { + if mem != x1.Args[2] { break } - if mem != x5.Args[2] { + if !(x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { break } - y6 := o0.Args[1] - if y6.Op != OpARM64MOVDnop { + b = mergePoint(b, x0, x1) + v0 := b.NewValue0(v.Pos, OpARM64MOVHUloadidx, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.AddArg(ptr) + v0.AddArg(idx) + v0.AddArg(mem) + return true + } + // match: (ORshiftLL [24] o0:(ORshiftLL [16] x0:(MOVHUload [i0] {s} p mem) y1:(MOVDnop x1:(MOVBUload [i2] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i3] {s} p mem))) + // cond: i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0) + // result: @mergePoint(b,x0,x1,x2) (MOVWUload {s} (OffPtr [i0] p) mem) + for { + t := v.Type + if v.AuxInt != 24 { break } - x6 := y6.Args[0] - if x6.Op != OpARM64MOVBUloadidx { + _ = v.Args[1] + o0 := v.Args[0] + if o0.Op != OpARM64ORshiftLL { break } - _ = x6.Args[2] - if ptr != x6.Args[0] { + if o0.AuxInt != 16 { break } - x6_1 := x6.Args[1] - if x6_1.Op != OpARM64ADDconst { + _ = o0.Args[1] + x0 := o0.Args[0] + if x0.Op != OpARM64MOVHUload { break } - if x6_1.AuxInt != 6 { + i0 := x0.AuxInt + s := x0.Aux + _ = x0.Args[1] + p := x0.Args[0] + mem := x0.Args[1] + y1 := o0.Args[1] + if y1.Op != OpARM64MOVDnop { break } - if idx != x6_1.Args[0] { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - if mem != x6.Args[2] { + i2 := x1.AuxInt + if x1.Aux != s { break } - y7 := v.Args[1] - if y7.Op != OpARM64MOVDnop { + _ = x1.Args[1] + if p != x1.Args[0] { break } - x7 := y7.Args[0] - if x7.Op != OpARM64MOVBUloadidx { + if mem != x1.Args[1] { break } - _ = x7.Args[2] - if ptr != x7.Args[0] { + y2 := v.Args[1] + if y2.Op != OpARM64MOVDnop { break } - x7_1 := x7.Args[1] - if x7_1.Op != OpARM64ADDconst { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { break } - if x7_1.AuxInt != 7 { + i3 := x2.AuxInt + if x2.Aux != s { break } - if idx != x7_1.Args[0] { + _ = x2.Args[1] + if p != x2.Args[0] { break } - if mem != x7.Args[2] { + if mem != x2.Args[1] { break } - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + if !(i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0)) { break } - b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) - v0 := b.NewValue0(v.Pos, OpARM64REV, t) + b = mergePoint(b, x0, x1, x2) + v0 := b.NewValue0(v.Pos, OpARM64MOVWUload, t) v.reset(OpCopy) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) - v1.AddArg(ptr) - v1.AddArg(idx) - v1.AddArg(mem) + v0.Aux = s + v1 := b.NewValue0(v.Pos, OpOffPtr, p.Type) + v1.AuxInt = i0 + v1.AddArg(p) v0.AddArg(v1) + v0.AddArg(mem) return true } - // match: (OR y7:(MOVDnop x7:(MOVBUloadidx ptr (ADDconst [7] idx) mem)) o0:(ORshiftLL [8] o1:(ORshiftLL [16] o2:(ORshiftLL [24] o3:(ORshiftLL [32] o4:(ORshiftLL [40] o5:(ORshiftLL [48] s0:(SLLconst [56] y0:(MOVDnop x0:(MOVBUloadidx ptr idx mem))) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr (ADDconst [4] idx) mem))) y5:(MOVDnop x5:(MOVBUloadidx ptr (ADDconst [5] idx) mem))) y6:(MOVDnop x6:(MOVBUloadidx ptr (ADDconst [6] idx) mem)))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0) - // result: @mergePoint(b,x0,x1,x2,x3,x4,x5,x6,x7) (REV (MOVDloadidx ptr idx mem)) + // match: (ORshiftLL [24] o0:(ORshiftLL [16] x0:(MOVHUloadidx ptr0 idx0 mem) y1:(MOVDnop x1:(MOVBUload [2] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [3] {s} p mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0) + // result: @mergePoint(b,x0,x1,x2) (MOVWUloadidx ptr0 idx0 mem) for { t := v.Type - _ = v.Args[1] - y7 := v.Args[0] - if y7.Op != OpARM64MOVDnop { - break - } - x7 := y7.Args[0] - if x7.Op != OpARM64MOVBUloadidx { - break - } - _ = x7.Args[2] - ptr := x7.Args[0] - x7_1 := x7.Args[1] - if x7_1.Op != OpARM64ADDconst { - break - } - if x7_1.AuxInt != 7 { + if v.AuxInt != 24 { break } - idx := x7_1.Args[0] - mem := x7.Args[2] - o0 := v.Args[1] + _ = v.Args[1] + o0 := v.Args[0] if o0.Op != OpARM64ORshiftLL { break } - if o0.AuxInt != 8 { + if o0.AuxInt != 16 { break } _ = o0.Args[1] - o1 := o0.Args[0] - if o1.Op != OpARM64ORshiftLL { - break - } - if o1.AuxInt != 16 { + x0 := o0.Args[0] + if x0.Op != OpARM64MOVHUloadidx { break } - _ = o1.Args[1] - o2 := o1.Args[0] - if o2.Op != OpARM64ORshiftLL { + _ = x0.Args[2] + ptr0 := x0.Args[0] + idx0 := x0.Args[1] + mem := x0.Args[2] + y1 := o0.Args[1] + if y1.Op != OpARM64MOVDnop { break } - if o2.AuxInt != 24 { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - _ = o2.Args[1] - o3 := o2.Args[0] - if o3.Op != OpARM64ORshiftLL { + if x1.AuxInt != 2 { break } - if o3.AuxInt != 32 { + s := x1.Aux + _ = x1.Args[1] + p1 := x1.Args[0] + if p1.Op != OpARM64ADD { break } - _ = o3.Args[1] - o4 := o3.Args[0] - if o4.Op != OpARM64ORshiftLL { + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] + if mem != x1.Args[1] { break } - if o4.AuxInt != 40 { + y2 := v.Args[1] + if y2.Op != OpARM64MOVDnop { break } - _ = o4.Args[1] - o5 := o4.Args[0] - if o5.Op != OpARM64ORshiftLL { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { break } - if o5.AuxInt != 48 { + if x2.AuxInt != 3 { break } - _ = o5.Args[1] - s0 := o5.Args[0] - if s0.Op != OpARM64SLLconst { + if x2.Aux != s { break } - if s0.AuxInt != 56 { + _ = x2.Args[1] + p := x2.Args[0] + if mem != x2.Args[1] { break } - y0 := s0.Args[0] - if y0.Op != OpARM64MOVDnop { + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0)) { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUloadidx { + b = mergePoint(b, x0, x1, x2) + v0 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.AddArg(ptr0) + v0.AddArg(idx0) + v0.AddArg(mem) + return true + } + // match: (ORshiftLL [24] o0:(ORshiftLL [16] x0:(MOVHUloadidx ptr idx mem) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0) + // result: @mergePoint(b,x0,x1,x2) (MOVWUloadidx ptr idx mem) + for { + t := v.Type + if v.AuxInt != 24 { break } - _ = x0.Args[2] - if ptr != x0.Args[0] { + _ = v.Args[1] + o0 := v.Args[0] + if o0.Op != OpARM64ORshiftLL { break } - if idx != x0.Args[1] { + if o0.AuxInt != 16 { break } - if mem != x0.Args[2] { + _ = o0.Args[1] + x0 := o0.Args[0] + if x0.Op != OpARM64MOVHUloadidx { break } - y1 := o5.Args[1] + _ = x0.Args[2] + ptr := x0.Args[0] + idx := x0.Args[1] + mem := x0.Args[2] + y1 := o0.Args[1] if y1.Op != OpARM64MOVDnop { break } @@ -21434,7 +24287,7 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if x1_1.Op != OpARM64ADDconst { break } - if x1_1.AuxInt != 1 { + if x1_1.AuxInt != 2 { break } if idx != x1_1.Args[0] { @@ -21443,7 +24296,7 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { if mem != x1.Args[2] { break } - y2 := o4.Args[1] + y2 := v.Args[1] if y2.Op != OpARM64MOVDnop { break } @@ -21456,636 +24309,427 @@ func rewriteValueARM64_OpARM64OR_30(v *Value) bool { break } x2_1 := x2.Args[1] - if x2_1.Op != OpARM64ADDconst { - break - } - if x2_1.AuxInt != 2 { - break - } - if idx != x2_1.Args[0] { - break - } - if mem != x2.Args[2] { - break - } - y3 := o3.Args[1] - if y3.Op != OpARM64MOVDnop { + if x2_1.Op != OpARM64ADDconst { break } - x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUloadidx { + if x2_1.AuxInt != 3 { break } - _ = x3.Args[2] - if ptr != x3.Args[0] { + if idx != x2_1.Args[0] { break } - x3_1 := x3.Args[1] - if x3_1.Op != OpARM64ADDconst { + if mem != x2.Args[2] { break } - if x3_1.AuxInt != 3 { + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0)) { break } - if idx != x3_1.Args[0] { + b = mergePoint(b, x0, x1, x2) + v0 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.AddArg(ptr) + v0.AddArg(idx) + v0.AddArg(mem) + return true + } + // match: (ORshiftLL [24] o0:(ORshiftLL [16] x0:(MOVHUloadidx2 ptr0 idx0 mem) y1:(MOVDnop x1:(MOVBUload [2] {s} p1:(ADDshiftLL [1] ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [3] {s} p mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0) + // result: @mergePoint(b,x0,x1,x2) (MOVWUloadidx ptr0 (SLLconst [1] idx0) mem) + for { + t := v.Type + if v.AuxInt != 24 { break } - if mem != x3.Args[2] { + _ = v.Args[1] + o0 := v.Args[0] + if o0.Op != OpARM64ORshiftLL { break } - y4 := o2.Args[1] - if y4.Op != OpARM64MOVDnop { + if o0.AuxInt != 16 { break } - x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUloadidx { + _ = o0.Args[1] + x0 := o0.Args[0] + if x0.Op != OpARM64MOVHUloadidx2 { break } - _ = x4.Args[2] - if ptr != x4.Args[0] { + _ = x0.Args[2] + ptr0 := x0.Args[0] + idx0 := x0.Args[1] + mem := x0.Args[2] + y1 := o0.Args[1] + if y1.Op != OpARM64MOVDnop { break } - x4_1 := x4.Args[1] - if x4_1.Op != OpARM64ADDconst { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - if x4_1.AuxInt != 4 { + if x1.AuxInt != 2 { break } - if idx != x4_1.Args[0] { + s := x1.Aux + _ = x1.Args[1] + p1 := x1.Args[0] + if p1.Op != OpARM64ADDshiftLL { break } - if mem != x4.Args[2] { + if p1.AuxInt != 1 { break } - y5 := o1.Args[1] - if y5.Op != OpARM64MOVDnop { + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] + if mem != x1.Args[1] { break } - x5 := y5.Args[0] - if x5.Op != OpARM64MOVBUloadidx { + y2 := v.Args[1] + if y2.Op != OpARM64MOVDnop { break } - _ = x5.Args[2] - if ptr != x5.Args[0] { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { break } - x5_1 := x5.Args[1] - if x5_1.Op != OpARM64ADDconst { + if x2.AuxInt != 3 { break } - if x5_1.AuxInt != 5 { + if x2.Aux != s { break } - if idx != x5_1.Args[0] { + _ = x2.Args[1] + p := x2.Args[0] + if mem != x2.Args[1] { break } - if mem != x5.Args[2] { + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0)) { break } - y6 := o0.Args[1] - if y6.Op != OpARM64MOVDnop { + b = mergePoint(b, x0, x1, x2) + v0 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.AddArg(ptr0) + v1 := b.NewValue0(v.Pos, OpARM64SLLconst, idx0.Type) + v1.AuxInt = 1 + v1.AddArg(idx0) + v0.AddArg(v1) + v0.AddArg(mem) + return true + } + // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] x0:(MOVWUload [i0] {s} p mem) y1:(MOVDnop x1:(MOVBUload [i4] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i6] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [i7] {s} p mem))) + // cond: i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) + // result: @mergePoint(b,x0,x1,x2,x3,x4) (MOVDload {s} (OffPtr [i0] p) mem) + for { + t := v.Type + if v.AuxInt != 56 { break } - x6 := y6.Args[0] - if x6.Op != OpARM64MOVBUloadidx { + _ = v.Args[1] + o0 := v.Args[0] + if o0.Op != OpARM64ORshiftLL { break } - _ = x6.Args[2] - if ptr != x6.Args[0] { + if o0.AuxInt != 48 { break } - x6_1 := x6.Args[1] - if x6_1.Op != OpARM64ADDconst { + _ = o0.Args[1] + o1 := o0.Args[0] + if o1.Op != OpARM64ORshiftLL { break } - if x6_1.AuxInt != 6 { + if o1.AuxInt != 40 { break } - if idx != x6_1.Args[0] { + _ = o1.Args[1] + o2 := o1.Args[0] + if o2.Op != OpARM64ORshiftLL { break } - if mem != x6.Args[2] { + if o2.AuxInt != 32 { break } - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && x5.Uses == 1 && x6.Uses == 1 && x7.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && y5.Uses == 1 && y6.Uses == 1 && y7.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && o3.Uses == 1 && o4.Uses == 1 && o5.Uses == 1 && s0.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(x5) && clobber(x6) && clobber(x7) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(y5) && clobber(y6) && clobber(y7) && clobber(o0) && clobber(o1) && clobber(o2) && clobber(o3) && clobber(o4) && clobber(o5) && clobber(s0)) { + _ = o2.Args[1] + x0 := o2.Args[0] + if x0.Op != OpARM64MOVWUload { break } - b = mergePoint(b, x0, x1, x2, x3, x4, x5, x6, x7) - v0 := b.NewValue0(v.Pos, OpARM64REV, t) - v.reset(OpCopy) - v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) - v1.AddArg(ptr) - v1.AddArg(idx) - v1.AddArg(mem) - v0.AddArg(v1) - return true - } - return false -} -func rewriteValueARM64_OpARM64ORN_0(v *Value) bool { - // match: (ORN x (MOVDconst [c])) - // cond: - // result: (ORconst [^c] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + i0 := x0.AuxInt + s := x0.Aux + _ = x0.Args[1] + p := x0.Args[0] + mem := x0.Args[1] + y1 := o2.Args[1] + if y1.Op != OpARM64MOVDnop { break } - c := v_1.AuxInt - v.reset(OpARM64ORconst) - v.AuxInt = ^c - v.AddArg(x) - return true - } - // match: (ORN x x) - // cond: - // result: (MOVDconst [-1]) - for { - _ = v.Args[1] - x := v.Args[0] - if x != v.Args[1] { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = -1 - return true - } - // match: (ORN x0 x1:(SLLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (ORNshiftLL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SLLconst { + i4 := x1.AuxInt + if x1.Aux != s { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + _ = x1.Args[1] + if p != x1.Args[0] { break } - v.reset(OpARM64ORNshiftLL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (ORN x0 x1:(SRLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (ORNshiftRL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRLconst { + if mem != x1.Args[1] { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + y2 := o1.Args[1] + if y2.Op != OpARM64MOVDnop { break } - v.reset(OpARM64ORNshiftRL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (ORN x0 x1:(SRAconst [c] y)) - // cond: clobberIfDead(x1) - // result: (ORNshiftRA x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRAconst { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + i5 := x2.AuxInt + if x2.Aux != s { break } - v.reset(OpARM64ORNshiftRA) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - return false -} -func rewriteValueARM64_OpARM64ORNshiftLL_0(v *Value) bool { - // match: (ORNshiftLL x (MOVDconst [c]) [d]) - // cond: - // result: (ORconst x [^int64(uint64(c)<>uint64(d))]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = x3.Args[1] + if p != x3.Args[0] { break } - c := v_1.AuxInt - v.reset(OpARM64ORconst) - v.AuxInt = ^(c >> uint64(d)) - v.AddArg(x) - return true - } - // match: (ORNshiftRA x (SRAconst x [c]) [d]) - // cond: c==d - // result: (MOVDconst [-1]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRAconst { + if mem != x3.Args[1] { break } - c := v_1.AuxInt - if x != v_1.Args[0] { + y4 := v.Args[1] + if y4.Op != OpARM64MOVDnop { break } - if !(c == d) { + x4 := y4.Args[0] + if x4.Op != OpARM64MOVBUload { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = -1 - return true - } - return false -} -func rewriteValueARM64_OpARM64ORNshiftRL_0(v *Value) bool { - // match: (ORNshiftRL x (MOVDconst [c]) [d]) - // cond: - // result: (ORconst x [^int64(uint64(c)>>uint64(d))]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + i7 := x4.AuxInt + if x4.Aux != s { break } - c := v_1.AuxInt - v.reset(OpARM64ORconst) - v.AuxInt = ^int64(uint64(c) >> uint64(d)) - v.AddArg(x) + _ = x4.Args[1] + if p != x4.Args[0] { + break + } + if mem != x4.Args[1] { + break + } + if !(i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { + break + } + b = mergePoint(b, x0, x1, x2, x3, x4) + v0 := b.NewValue0(v.Pos, OpARM64MOVDload, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.Aux = s + v1 := b.NewValue0(v.Pos, OpOffPtr, p.Type) + v1.AuxInt = i0 + v1.AddArg(p) + v0.AddArg(v1) + v0.AddArg(mem) return true } - // match: (ORNshiftRL x (SRLconst x [c]) [d]) - // cond: c==d - // result: (MOVDconst [-1]) + // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] x0:(MOVWUloadidx ptr0 idx0 mem) y1:(MOVDnop x1:(MOVBUload [4] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [6] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [7] {s} p mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) + // result: @mergePoint(b,x0,x1,x2,x3,x4) (MOVDloadidx ptr0 idx0 mem) for { - d := v.AuxInt + t := v.Type + if v.AuxInt != 56 { + break + } _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + o0 := v.Args[0] + if o0.Op != OpARM64ORshiftLL { break } - c := v_1.AuxInt - if x != v_1.Args[0] { + if o0.AuxInt != 48 { break } - if !(c == d) { + _ = o0.Args[1] + o1 := o0.Args[0] + if o1.Op != OpARM64ORshiftLL { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = -1 - return true - } - return false -} -func rewriteValueARM64_OpARM64ORconst_0(v *Value) bool { - // match: (ORconst [0] x) - // cond: - // result: x - for { - if v.AuxInt != 0 { + if o1.AuxInt != 40 { break } - x := v.Args[0] - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (ORconst [-1] _) - // cond: - // result: (MOVDconst [-1]) - for { - if v.AuxInt != -1 { + _ = o1.Args[1] + o2 := o1.Args[0] + if o2.Op != OpARM64ORshiftLL { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = -1 - return true - } - // match: (ORconst [c] (MOVDconst [d])) - // cond: - // result: (MOVDconst [c|d]) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if o2.AuxInt != 32 { break } - d := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = c | d - return true - } - // match: (ORconst [c] (ORconst [d] x)) - // cond: - // result: (ORconst [c|d] x) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64ORconst { + _ = o2.Args[1] + x0 := o2.Args[0] + if x0.Op != OpARM64MOVWUloadidx { break } - d := v_0.AuxInt - x := v_0.Args[0] - v.reset(OpARM64ORconst) - v.AuxInt = c | d - v.AddArg(x) - return true - } - // match: (ORconst [c1] (ANDconst [c2] x)) - // cond: c2|c1 == ^0 - // result: (ORconst [c1] x) - for { - c1 := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64ANDconst { + _ = x0.Args[2] + ptr0 := x0.Args[0] + idx0 := x0.Args[1] + mem := x0.Args[2] + y1 := o2.Args[1] + if y1.Op != OpARM64MOVDnop { break } - c2 := v_0.AuxInt - x := v_0.Args[0] - if !(c2|c1 == ^0) { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - v.reset(OpARM64ORconst) - v.AuxInt = c1 - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64ORshiftLL_0(v *Value) bool { - b := v.Block - _ = b - // match: (ORshiftLL (MOVDconst [c]) x [d]) - // cond: - // result: (ORconst [c] (SLLconst x [d])) - for { - d := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if x1.AuxInt != 4 { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64ORconst) - v.AuxInt = c - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = d - v0.AddArg(x) - v.AddArg(v0) - return true - } - // match: (ORshiftLL x (MOVDconst [c]) [d]) - // cond: - // result: (ORconst x [int64(uint64(c)< [c] (UBFX [bfc] x) x) - // cond: c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c) - // result: (RORWconst [32-c] x) - for { - t := v.Type - c := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64UBFX { + x3 := y3.Args[0] + if x3.Op != OpARM64MOVBUload { break } - bfc := v_0.AuxInt - x := v_0.Args[0] - if x != v.Args[1] { + if x3.AuxInt != 6 { break } - if !(c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c)) { + if x3.Aux != s { break } - v.reset(OpARM64RORWconst) - v.AuxInt = 32 - c - v.AddArg(x) - return true - } - // match: (ORshiftLL [c] (SRLconst x [64-c]) x2) - // cond: - // result: (EXTRconst [64-c] x2 x) - for { - c := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { + _ = x3.Args[1] + if p != x3.Args[0] { break } - if v_0.AuxInt != 64-c { + if mem != x3.Args[1] { break } - x := v_0.Args[0] - x2 := v.Args[1] - v.reset(OpARM64EXTRconst) - v.AuxInt = 64 - c - v.AddArg(x2) - v.AddArg(x) - return true - } - // match: (ORshiftLL [c] (UBFX [bfc] x) x2) - // cond: c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c) - // result: (EXTRWconst [32-c] x2 x) - for { - t := v.Type - c := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64UBFX { + y4 := v.Args[1] + if y4.Op != OpARM64MOVDnop { break } - bfc := v_0.AuxInt - x := v_0.Args[0] - x2 := v.Args[1] - if !(c < 32 && t.Size() == 4 && bfc == arm64BFAuxInt(32-c, c)) { + x4 := y4.Args[0] + if x4.Op != OpARM64MOVBUload { break } - v.reset(OpARM64EXTRWconst) - v.AuxInt = 32 - c - v.AddArg(x2) - v.AddArg(x) - return true - } - // match: (ORshiftLL [sc] (UBFX [bfc] x) (SRLconst [sc] y)) - // cond: sc == getARM64BFwidth(bfc) - // result: (BFXIL [bfc] y x) - for { - sc := v.AuxInt - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64UBFX { + if x4.AuxInt != 7 { break } - bfc := v_0.AuxInt - x := v_0.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + if x4.Aux != s { break } - if v_1.AuxInt != sc { + _ = x4.Args[1] + if p != x4.Args[0] { break } - y := v_1.Args[0] - if !(sc == getARM64BFwidth(bfc)) { + if mem != x4.Args[1] { break } - v.reset(OpARM64BFXIL) - v.AuxInt = bfc - v.AddArg(y) - v.AddArg(x) + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { + break + } + b = mergePoint(b, x0, x1, x2, x3, x4) + v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.AddArg(ptr0) + v0.AddArg(idx0) + v0.AddArg(mem) return true } - // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUload [i0] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) - // cond: i1 == i0+1 && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) - // result: @mergePoint(b,x0,x1) (MOVHUload {s} (OffPtr [i0] p) mem) + // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] x0:(MOVWUloadidx4 ptr0 idx0 mem) y1:(MOVDnop x1:(MOVBUload [4] {s} p1:(ADDshiftLL [2] ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [6] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [7] {s} p mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) + // result: @mergePoint(b,x0,x1,x2,x3,x4) (MOVDloadidx ptr0 (SLLconst [2] idx0) mem) for { t := v.Type - if v.AuxInt != 8 { + if v.AuxInt != 56 { break } _ = v.Args[1] - y0 := v.Args[0] - if y0.Op != OpARM64MOVDnop { + o0 := v.Args[0] + if o0.Op != OpARM64ORshiftLL { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUload { + if o0.AuxInt != 48 { break } - i0 := x0.AuxInt - s := x0.Aux - _ = x0.Args[1] - p := x0.Args[0] - mem := x0.Args[1] - y1 := v.Args[1] + _ = o0.Args[1] + o1 := o0.Args[0] + if o1.Op != OpARM64ORshiftLL { + break + } + if o1.AuxInt != 40 { + break + } + _ = o1.Args[1] + o2 := o1.Args[0] + if o2.Op != OpARM64ORshiftLL { + break + } + if o2.AuxInt != 32 { + break + } + _ = o2.Args[1] + x0 := o2.Args[0] + if x0.Op != OpARM64MOVWUloadidx4 { + break + } + _ = x0.Args[2] + ptr0 := x0.Args[0] + idx0 := x0.Args[1] + mem := x0.Args[2] + y1 := o2.Args[1] if y1.Op != OpARM64MOVDnop { break } @@ -22093,115 +24737,142 @@ func rewriteValueARM64_OpARM64ORshiftLL_0(v *Value) bool { if x1.Op != OpARM64MOVBUload { break } - i1 := x1.AuxInt - if x1.Aux != s { + if x1.AuxInt != 4 { break } + s := x1.Aux _ = x1.Args[1] - if p != x1.Args[0] { + p1 := x1.Args[0] + if p1.Op != OpARM64ADDshiftLL { + break + } + if p1.AuxInt != 2 { break } + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] if mem != x1.Args[1] { break } - if !(i1 == i0+1 && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { + y2 := o1.Args[1] + if y2.Op != OpARM64MOVDnop { break } - b = mergePoint(b, x0, x1) - v0 := b.NewValue0(v.Pos, OpARM64MOVHUload, t) - v.reset(OpCopy) - v.AddArg(v0) - v0.Aux = s - v1 := b.NewValue0(v.Pos, OpOffPtr, p.Type) - v1.AuxInt = i0 - v1.AddArg(p) - v0.AddArg(v1) - v0.AddArg(mem) - return true - } - // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUloadidx ptr0 idx0 mem)) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) - // result: @mergePoint(b,x0,x1) (MOVHUloadidx ptr0 idx0 mem) - for { - t := v.Type - if v.AuxInt != 8 { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUload { + break + } + if x2.AuxInt != 5 { + break + } + if x2.Aux != s { + break + } + _ = x2.Args[1] + p := x2.Args[0] + if mem != x2.Args[1] { + break + } + y3 := o0.Args[1] + if y3.Op != OpARM64MOVDnop { + break + } + x3 := y3.Args[0] + if x3.Op != OpARM64MOVBUload { + break + } + if x3.AuxInt != 6 { break } - _ = v.Args[1] - y0 := v.Args[0] - if y0.Op != OpARM64MOVDnop { + if x3.Aux != s { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUloadidx { + _ = x3.Args[1] + if p != x3.Args[0] { break } - _ = x0.Args[2] - ptr0 := x0.Args[0] - idx0 := x0.Args[1] - mem := x0.Args[2] - y1 := v.Args[1] - if y1.Op != OpARM64MOVDnop { + if mem != x3.Args[1] { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + y4 := v.Args[1] + if y4.Op != OpARM64MOVDnop { break } - if x1.AuxInt != 1 { + x4 := y4.Args[0] + if x4.Op != OpARM64MOVBUload { break } - s := x1.Aux - _ = x1.Args[1] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + if x4.AuxInt != 7 { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - if mem != x1.Args[1] { + if x4.Aux != s { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { + _ = x4.Args[1] + if p != x4.Args[0] { break } - b = mergePoint(b, x0, x1) - v0 := b.NewValue0(v.Pos, OpARM64MOVHUloadidx, t) + if mem != x4.Args[1] { + break + } + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { + break + } + b = mergePoint(b, x0, x1, x2, x3, x4) + v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) v.reset(OpCopy) v.AddArg(v0) v0.AddArg(ptr0) - v0.AddArg(idx0) + v1 := b.NewValue0(v.Pos, OpARM64SLLconst, idx0.Type) + v1.AuxInt = 2 + v1.AddArg(idx0) + v0.AddArg(v1) v0.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { - b := v.Block - _ = b - // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUloadidx ptr idx mem)) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) - // cond: x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) - // result: @mergePoint(b,x0,x1) (MOVHUloadidx ptr idx mem) + // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] x0:(MOVWUloadidx ptr idx mem) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [4] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [5] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [6] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr (ADDconst [7] idx) mem))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) + // result: @mergePoint(b,x0,x1,x2,x3,x4) (MOVDloadidx ptr idx mem) for { t := v.Type - if v.AuxInt != 8 { + if v.AuxInt != 56 { break } _ = v.Args[1] - y0 := v.Args[0] - if y0.Op != OpARM64MOVDnop { + o0 := v.Args[0] + if o0.Op != OpARM64ORshiftLL { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUloadidx { + if o0.AuxInt != 48 { + break + } + _ = o0.Args[1] + o1 := o0.Args[0] + if o1.Op != OpARM64ORshiftLL { + break + } + if o1.AuxInt != 40 { + break + } + _ = o1.Args[1] + o2 := o1.Args[0] + if o2.Op != OpARM64ORshiftLL { + break + } + if o2.AuxInt != 32 { + break + } + _ = o2.Args[1] + x0 := o2.Args[0] + if x0.Op != OpARM64MOVWUloadidx { break } _ = x0.Args[2] ptr := x0.Args[0] idx := x0.Args[1] mem := x0.Args[2] - y1 := v.Args[1] + y1 := o2.Args[1] if y1.Op != OpARM64MOVDnop { break } @@ -22217,7 +24888,7 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x1_1.Op != OpARM64ADDconst { break } - if x1_1.AuxInt != 1 { + if x1_1.AuxInt != 4 { break } if idx != x1_1.Args[0] { @@ -22226,202 +24897,185 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if mem != x1.Args[2] { break } - if !(x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { + y2 := o1.Args[1] + if y2.Op != OpARM64MOVDnop { break } - b = mergePoint(b, x0, x1) - v0 := b.NewValue0(v.Pos, OpARM64MOVHUloadidx, t) - v.reset(OpCopy) - v.AddArg(v0) - v0.AddArg(ptr) - v0.AddArg(idx) - v0.AddArg(mem) - return true - } - // match: (ORshiftLL [24] o0:(ORshiftLL [16] x0:(MOVHUload [i0] {s} p mem) y1:(MOVDnop x1:(MOVBUload [i2] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i3] {s} p mem))) - // cond: i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0) - // result: @mergePoint(b,x0,x1,x2) (MOVWUload {s} (OffPtr [i0] p) mem) - for { - t := v.Type - if v.AuxInt != 24 { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUloadidx { break } - _ = v.Args[1] - o0 := v.Args[0] - if o0.Op != OpARM64ORshiftLL { + _ = x2.Args[2] + if ptr != x2.Args[0] { break } - if o0.AuxInt != 16 { + x2_1 := x2.Args[1] + if x2_1.Op != OpARM64ADDconst { break } - _ = o0.Args[1] - x0 := o0.Args[0] - if x0.Op != OpARM64MOVHUload { + if x2_1.AuxInt != 5 { break } - i0 := x0.AuxInt - s := x0.Aux - _ = x0.Args[1] - p := x0.Args[0] - mem := x0.Args[1] - y1 := o0.Args[1] - if y1.Op != OpARM64MOVDnop { + if idx != x2_1.Args[0] { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + if mem != x2.Args[2] { break } - i2 := x1.AuxInt - if x1.Aux != s { + y3 := o0.Args[1] + if y3.Op != OpARM64MOVDnop { break } - _ = x1.Args[1] - if p != x1.Args[0] { + x3 := y3.Args[0] + if x3.Op != OpARM64MOVBUloadidx { break } - if mem != x1.Args[1] { + _ = x3.Args[2] + if ptr != x3.Args[0] { break } - y2 := v.Args[1] - if y2.Op != OpARM64MOVDnop { + x3_1 := x3.Args[1] + if x3_1.Op != OpARM64ADDconst { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUload { + if x3_1.AuxInt != 6 { break } - i3 := x2.AuxInt - if x2.Aux != s { + if idx != x3_1.Args[0] { break } - _ = x2.Args[1] - if p != x2.Args[0] { + if mem != x3.Args[2] { break } - if mem != x2.Args[1] { + y4 := v.Args[1] + if y4.Op != OpARM64MOVDnop { break } - if !(i2 == i0+2 && i3 == i0+3 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0)) { + x4 := y4.Args[0] + if x4.Op != OpARM64MOVBUloadidx { break } - b = mergePoint(b, x0, x1, x2) - v0 := b.NewValue0(v.Pos, OpARM64MOVWUload, t) - v.reset(OpCopy) - v.AddArg(v0) - v0.Aux = s - v1 := b.NewValue0(v.Pos, OpOffPtr, p.Type) - v1.AuxInt = i0 - v1.AddArg(p) - v0.AddArg(v1) - v0.AddArg(mem) - return true - } - // match: (ORshiftLL [24] o0:(ORshiftLL [16] x0:(MOVHUloadidx ptr0 idx0 mem) y1:(MOVDnop x1:(MOVBUload [2] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [3] {s} p mem))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0) - // result: @mergePoint(b,x0,x1,x2) (MOVWUloadidx ptr0 idx0 mem) - for { - t := v.Type - if v.AuxInt != 24 { + _ = x4.Args[2] + if ptr != x4.Args[0] { break } - _ = v.Args[1] - o0 := v.Args[0] - if o0.Op != OpARM64ORshiftLL { + x4_1 := x4.Args[1] + if x4_1.Op != OpARM64ADDconst { break } - if o0.AuxInt != 16 { + if x4_1.AuxInt != 7 { break } - _ = o0.Args[1] - x0 := o0.Args[0] - if x0.Op != OpARM64MOVHUloadidx { + if idx != x4_1.Args[0] { break } - _ = x0.Args[2] - ptr0 := x0.Args[0] - idx0 := x0.Args[1] - mem := x0.Args[2] - y1 := o0.Args[1] - if y1.Op != OpARM64MOVDnop { + if mem != x4.Args[2] { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { break } - if x1.AuxInt != 2 { + b = mergePoint(b, x0, x1, x2, x3, x4) + v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v.reset(OpCopy) + v.AddArg(v0) + v0.AddArg(ptr) + v0.AddArg(idx) + v0.AddArg(mem) + return true + } + // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUload [i1] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [i0] {s} p mem))) + // cond: i1 == i0+1 && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) + // result: @mergePoint(b,x0,x1) (REV16W (MOVHUload [i0] {s} p mem)) + for { + t := v.Type + if v.AuxInt != 8 { break } - s := x1.Aux - _ = x1.Args[1] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + _ = v.Args[1] + y0 := v.Args[0] + if y0.Op != OpARM64MOVDnop { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - if mem != x1.Args[1] { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUload { break } - y2 := v.Args[1] - if y2.Op != OpARM64MOVDnop { + i1 := x0.AuxInt + s := x0.Aux + _ = x0.Args[1] + p := x0.Args[0] + mem := x0.Args[1] + y1 := v.Args[1] + if y1.Op != OpARM64MOVDnop { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUload { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { break } - if x2.AuxInt != 3 { + i0 := x1.AuxInt + if x1.Aux != s { break } - if x2.Aux != s { + _ = x1.Args[1] + if p != x1.Args[0] { break } - _ = x2.Args[1] - p := x2.Args[0] - if mem != x2.Args[1] { + if mem != x1.Args[1] { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0)) { + if !(i1 == i0+1 && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { break } - b = mergePoint(b, x0, x1, x2) - v0 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + b = mergePoint(b, x0, x1) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, t) v.reset(OpCopy) v.AddArg(v0) - v0.AddArg(ptr0) - v0.AddArg(idx0) - v0.AddArg(mem) + v1 := b.NewValue0(v.Pos, OpARM64MOVHUload, t) + v1.AuxInt = i0 + v1.Aux = s + v1.AddArg(p) + v1.AddArg(mem) + v0.AddArg(v1) return true } - // match: (ORshiftLL [24] o0:(ORshiftLL [16] x0:(MOVHUloadidx ptr idx mem) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0) - // result: @mergePoint(b,x0,x1,x2) (MOVWUloadidx ptr idx mem) + return false +} +func rewriteValueARM64_OpARM64ORshiftLL_20(v *Value) bool { + b := v.Block + _ = b + // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem)) y1:(MOVDnop x1:(MOVBUloadidx ptr0 idx0 mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) + // result: @mergePoint(b,x0,x1) (REV16W (MOVHUloadidx ptr0 idx0 mem)) for { t := v.Type - if v.AuxInt != 24 { + if v.AuxInt != 8 { break } _ = v.Args[1] - o0 := v.Args[0] - if o0.Op != OpARM64ORshiftLL { + y0 := v.Args[0] + if y0.Op != OpARM64MOVDnop { break } - if o0.AuxInt != 16 { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUload { break } - _ = o0.Args[1] - x0 := o0.Args[0] - if x0.Op != OpARM64MOVHUloadidx { + if x0.AuxInt != 1 { break } - _ = x0.Args[2] - ptr := x0.Args[0] - idx := x0.Args[1] - mem := x0.Args[2] - y1 := o0.Args[1] + s := x0.Aux + _ = x0.Args[1] + p1 := x0.Args[0] + if p1.Op != OpARM64ADD { + break + } + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] + mem := x0.Args[1] + y1 := v.Args[1] if y1.Op != OpARM64MOVDnop { break } @@ -22430,62 +25084,88 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { break } _ = x1.Args[2] - if ptr != x1.Args[0] { + ptr0 := x1.Args[0] + idx0 := x1.Args[1] + if mem != x1.Args[2] { break } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64ADDconst { + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { break } - if x1_1.AuxInt != 2 { + b = mergePoint(b, x0, x1) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, t) + v.reset(OpCopy) + v.AddArg(v0) + v1 := b.NewValue0(v.Pos, OpARM64MOVHUloadidx, t) + v1.AddArg(ptr0) + v1.AddArg(idx0) + v1.AddArg(mem) + v0.AddArg(v1) + return true + } + // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUloadidx ptr (ADDconst [1] idx) mem)) y1:(MOVDnop x1:(MOVBUloadidx ptr idx mem))) + // cond: x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) + // result: @mergePoint(b,x0,x1) (REV16W (MOVHUloadidx ptr idx mem)) + for { + t := v.Type + if v.AuxInt != 8 { break } - if idx != x1_1.Args[0] { + _ = v.Args[1] + y0 := v.Args[0] + if y0.Op != OpARM64MOVDnop { break } - if mem != x1.Args[2] { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVBUloadidx { break } - y2 := v.Args[1] - if y2.Op != OpARM64MOVDnop { + _ = x0.Args[2] + ptr := x0.Args[0] + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64ADDconst { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUloadidx { + if x0_1.AuxInt != 1 { break } - _ = x2.Args[2] - if ptr != x2.Args[0] { + idx := x0_1.Args[0] + mem := x0.Args[2] + y1 := v.Args[1] + if y1.Op != OpARM64MOVDnop { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64ADDconst { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUloadidx { break } - if x2_1.AuxInt != 3 { + _ = x1.Args[2] + if ptr != x1.Args[0] { break } - if idx != x2_1.Args[0] { + if idx != x1.Args[1] { break } - if mem != x2.Args[2] { + if mem != x1.Args[2] { break } - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0)) { + if !(x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { break } - b = mergePoint(b, x0, x1, x2) - v0 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + b = mergePoint(b, x0, x1) + v0 := b.NewValue0(v.Pos, OpARM64REV16W, t) v.reset(OpCopy) v.AddArg(v0) - v0.AddArg(ptr) - v0.AddArg(idx) - v0.AddArg(mem) + v1 := b.NewValue0(v.Pos, OpARM64MOVHUloadidx, t) + v1.AddArg(ptr) + v1.AddArg(idx) + v1.AddArg(mem) + v0.AddArg(v1) return true } - // match: (ORshiftLL [24] o0:(ORshiftLL [16] x0:(MOVHUloadidx2 ptr0 idx0 mem) y1:(MOVDnop x1:(MOVBUload [2] {s} p1:(ADDshiftLL [1] ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [3] {s} p mem))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0) - // result: @mergePoint(b,x0,x1,x2) (MOVWUloadidx ptr0 (SLLconst [1] idx0) mem) + // match: (ORshiftLL [24] o0:(ORshiftLL [16] y0:(REV16W x0:(MOVHUload [i2] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i0] {s} p mem))) + // cond: i1 == i0+1 && i2 == i0+2 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0) + // result: @mergePoint(b,x0,x1,x2) (REVW (MOVWUload {s} (OffPtr [i0] p) mem)) for { t := v.Type if v.AuxInt != 24 { @@ -22500,14 +25180,19 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { break } _ = o0.Args[1] - x0 := o0.Args[0] - if x0.Op != OpARM64MOVHUloadidx2 { + y0 := o0.Args[0] + if y0.Op != OpARM64REV16W { break } - _ = x0.Args[2] - ptr0 := x0.Args[0] - idx0 := x0.Args[1] - mem := x0.Args[2] + x0 := y0.Args[0] + if x0.Op != OpARM64MOVHUload { + break + } + i2 := x0.AuxInt + s := x0.Aux + _ = x0.Args[1] + p := x0.Args[0] + mem := x0.Args[1] y1 := o0.Args[1] if y1.Op != OpARM64MOVDnop { break @@ -22516,21 +25201,14 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x1.Op != OpARM64MOVBUload { break } - if x1.AuxInt != 2 { + i1 := x1.AuxInt + if x1.Aux != s { break } - s := x1.Aux _ = x1.Args[1] - p1 := x1.Args[0] - if p1.Op != OpARM64ADDshiftLL { - break - } - if p1.AuxInt != 1 { + if p != x1.Args[0] { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] if mem != x1.Args[1] { break } @@ -22542,38 +25220,40 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x2.Op != OpARM64MOVBUload { break } - if x2.AuxInt != 3 { - break - } + i0 := x2.AuxInt if x2.Aux != s { break } _ = x2.Args[1] - p := x2.Args[0] + if p != x2.Args[0] { + break + } if mem != x2.Args[1] { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y1) && clobber(y2) && clobber(o0)) { + if !(i1 == i0+1 && i2 == i0+2 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0)) { break } b = mergePoint(b, x0, x1, x2) - v0 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + v0 := b.NewValue0(v.Pos, OpARM64REVW, t) v.reset(OpCopy) v.AddArg(v0) - v0.AddArg(ptr0) - v1 := b.NewValue0(v.Pos, OpARM64SLLconst, idx0.Type) - v1.AuxInt = 1 - v1.AddArg(idx0) + v1 := b.NewValue0(v.Pos, OpARM64MOVWUload, t) + v1.Aux = s + v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) + v2.AuxInt = i0 + v2.AddArg(p) + v1.AddArg(v2) + v1.AddArg(mem) v0.AddArg(v1) - v0.AddArg(mem) return true } - // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] x0:(MOVWUload [i0] {s} p mem) y1:(MOVDnop x1:(MOVBUload [i4] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i6] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [i7] {s} p mem))) - // cond: i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) - // result: @mergePoint(b,x0,x1,x2,x3,x4) (MOVDload {s} (OffPtr [i0] p) mem) + // match: (ORshiftLL [24] o0:(ORshiftLL [16] y0:(REV16W x0:(MOVHUload [2] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr0 idx0 mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0) + // result: @mergePoint(b,x0,x1,x2) (REVW (MOVWUloadidx ptr0 idx0 mem)) for { t := v.Type - if v.AuxInt != 56 { + if v.AuxInt != 24 { break } _ = v.Args[1] @@ -22581,129 +25261,174 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if o0.Op != OpARM64ORshiftLL { break } - if o0.AuxInt != 48 { + if o0.AuxInt != 16 { break } _ = o0.Args[1] - o1 := o0.Args[0] - if o1.Op != OpARM64ORshiftLL { - break - } - if o1.AuxInt != 40 { - break - } - _ = o1.Args[1] - o2 := o1.Args[0] - if o2.Op != OpARM64ORshiftLL { + y0 := o0.Args[0] + if y0.Op != OpARM64REV16W { break } - if o2.AuxInt != 32 { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVHUload { break } - _ = o2.Args[1] - x0 := o2.Args[0] - if x0.Op != OpARM64MOVWUload { + if x0.AuxInt != 2 { break } - i0 := x0.AuxInt s := x0.Aux _ = x0.Args[1] p := x0.Args[0] mem := x0.Args[1] - y1 := o2.Args[1] + y1 := o0.Args[1] if y1.Op != OpARM64MOVDnop { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUload { + break + } + if x1.AuxInt != 1 { + break + } + if x1.Aux != s { + break + } + _ = x1.Args[1] + p1 := x1.Args[0] + if p1.Op != OpARM64ADD { + break + } + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] + if mem != x1.Args[1] { + break + } + y2 := v.Args[1] + if y2.Op != OpARM64MOVDnop { + break + } + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUloadidx { + break + } + _ = x2.Args[2] + ptr0 := x2.Args[0] + idx0 := x2.Args[1] + if mem != x2.Args[2] { + break + } + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0)) { break } - i4 := x1.AuxInt - if x1.Aux != s { + b = mergePoint(b, x0, x1, x2) + v0 := b.NewValue0(v.Pos, OpARM64REVW, t) + v.reset(OpCopy) + v.AddArg(v0) + v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + v1.AddArg(ptr0) + v1.AddArg(idx0) + v1.AddArg(mem) + v0.AddArg(v1) + return true + } + // match: (ORshiftLL [24] o0:(ORshiftLL [16] y0:(REV16W x0:(MOVHUloadidx ptr (ADDconst [2] idx) mem)) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr idx mem))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0) + // result: @mergePoint(b,x0,x1,x2) (REVW (MOVWUloadidx ptr idx mem)) + for { + t := v.Type + if v.AuxInt != 24 { break } - _ = x1.Args[1] - if p != x1.Args[0] { + _ = v.Args[1] + o0 := v.Args[0] + if o0.Op != OpARM64ORshiftLL { break } - if mem != x1.Args[1] { + if o0.AuxInt != 16 { break } - y2 := o1.Args[1] - if y2.Op != OpARM64MOVDnop { + _ = o0.Args[1] + y0 := o0.Args[0] + if y0.Op != OpARM64REV16W { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUload { + x0 := y0.Args[0] + if x0.Op != OpARM64MOVHUloadidx { break } - i5 := x2.AuxInt - if x2.Aux != s { + _ = x0.Args[2] + ptr := x0.Args[0] + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64ADDconst { break } - _ = x2.Args[1] - if p != x2.Args[0] { + if x0_1.AuxInt != 2 { break } - if mem != x2.Args[1] { + idx := x0_1.Args[0] + mem := x0.Args[2] + y1 := o0.Args[1] + if y1.Op != OpARM64MOVDnop { break } - y3 := o0.Args[1] - if y3.Op != OpARM64MOVDnop { + x1 := y1.Args[0] + if x1.Op != OpARM64MOVBUloadidx { break } - x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUload { + _ = x1.Args[2] + if ptr != x1.Args[0] { break } - i6 := x3.AuxInt - if x3.Aux != s { + x1_1 := x1.Args[1] + if x1_1.Op != OpARM64ADDconst { break } - _ = x3.Args[1] - if p != x3.Args[0] { + if x1_1.AuxInt != 1 { break } - if mem != x3.Args[1] { + if idx != x1_1.Args[0] { break } - y4 := v.Args[1] - if y4.Op != OpARM64MOVDnop { + if mem != x1.Args[2] { break } - x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUload { + y2 := v.Args[1] + if y2.Op != OpARM64MOVDnop { break } - i7 := x4.AuxInt - if x4.Aux != s { + x2 := y2.Args[0] + if x2.Op != OpARM64MOVBUloadidx { break } - _ = x4.Args[1] - if p != x4.Args[0] { + _ = x2.Args[2] + if ptr != x2.Args[0] { break } - if mem != x4.Args[1] { + if idx != x2.Args[1] { break } - if !(i4 == i0+4 && i5 == i0+5 && i6 == i0+6 && i7 == i0+7 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { + if mem != x2.Args[2] { break } - b = mergePoint(b, x0, x1, x2, x3, x4) - v0 := b.NewValue0(v.Pos, OpARM64MOVDload, t) + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0)) { + break + } + b = mergePoint(b, x0, x1, x2) + v0 := b.NewValue0(v.Pos, OpARM64REVW, t) v.reset(OpCopy) v.AddArg(v0) - v0.Aux = s - v1 := b.NewValue0(v.Pos, OpOffPtr, p.Type) - v1.AuxInt = i0 - v1.AddArg(p) + v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) + v1.AddArg(ptr) + v1.AddArg(idx) + v1.AddArg(mem) v0.AddArg(v1) - v0.AddArg(mem) return true } - // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] x0:(MOVWUloadidx ptr0 idx0 mem) y1:(MOVDnop x1:(MOVBUload [4] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [6] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [7] {s} p mem))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) - // result: @mergePoint(b,x0,x1,x2,x3,x4) (MOVDloadidx ptr0 idx0 mem) + // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] y0:(REVW x0:(MOVWUload [i4] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [i3] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i1] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [i0] {s} p mem))) + // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) + // result: @mergePoint(b,x0,x1,x2,x3,x4) (REV (MOVDload {s} (OffPtr [i0] p) mem)) for { t := v.Type if v.AuxInt != 56 { @@ -22734,14 +25459,19 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { break } _ = o2.Args[1] - x0 := o2.Args[0] - if x0.Op != OpARM64MOVWUloadidx { + y0 := o2.Args[0] + if y0.Op != OpARM64REVW { break } - _ = x0.Args[2] - ptr0 := x0.Args[0] - idx0 := x0.Args[1] - mem := x0.Args[2] + x0 := y0.Args[0] + if x0.Op != OpARM64MOVWUload { + break + } + i4 := x0.AuxInt + s := x0.Aux + _ = x0.Args[1] + p := x0.Args[0] + mem := x0.Args[1] y1 := o2.Args[1] if y1.Op != OpARM64MOVDnop { break @@ -22750,18 +25480,14 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x1.Op != OpARM64MOVBUload { break } - if x1.AuxInt != 4 { + i3 := x1.AuxInt + if x1.Aux != s { break } - s := x1.Aux _ = x1.Args[1] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + if p != x1.Args[0] { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] if mem != x1.Args[1] { break } @@ -22773,14 +25499,14 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x2.Op != OpARM64MOVBUload { break } - if x2.AuxInt != 5 { - break - } + i2 := x2.AuxInt if x2.Aux != s { break } _ = x2.Args[1] - p := x2.Args[0] + if p != x2.Args[0] { + break + } if mem != x2.Args[1] { break } @@ -22792,9 +25518,7 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x3.Op != OpARM64MOVBUload { break } - if x3.AuxInt != 6 { - break - } + i1 := x3.AuxInt if x3.Aux != s { break } @@ -22813,9 +25537,7 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x4.Op != OpARM64MOVBUload { break } - if x4.AuxInt != 7 { - break - } + i0 := x4.AuxInt if x4.Aux != s { break } @@ -22826,21 +25548,26 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if mem != x4.Args[1] { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { + if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { break } b = mergePoint(b, x0, x1, x2, x3, x4) - v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v0 := b.NewValue0(v.Pos, OpARM64REV, t) v.reset(OpCopy) v.AddArg(v0) - v0.AddArg(ptr0) - v0.AddArg(idx0) - v0.AddArg(mem) + v1 := b.NewValue0(v.Pos, OpARM64MOVDload, t) + v1.Aux = s + v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) + v2.AuxInt = i0 + v2.AddArg(p) + v1.AddArg(v2) + v1.AddArg(mem) + v0.AddArg(v1) return true } - // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] x0:(MOVWUloadidx4 ptr0 idx0 mem) y1:(MOVDnop x1:(MOVBUload [4] {s} p1:(ADDshiftLL [2] ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUload [5] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [6] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [7] {s} p mem))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) - // result: @mergePoint(b,x0,x1,x2,x3,x4) (MOVDloadidx ptr0 (SLLconst [2] idx0) mem) + // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] y0:(REVW x0:(MOVWUload [4] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [3] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr0 idx0 mem))) + // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) + // result: @mergePoint(b,x0,x1,x2,x3,x4) (REV (MOVDloadidx ptr0 idx0 mem)) for { t := v.Type if v.AuxInt != 56 { @@ -22871,14 +25598,21 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { break } _ = o2.Args[1] - x0 := o2.Args[0] - if x0.Op != OpARM64MOVWUloadidx4 { + y0 := o2.Args[0] + if y0.Op != OpARM64REVW { break } - _ = x0.Args[2] - ptr0 := x0.Args[0] - idx0 := x0.Args[1] - mem := x0.Args[2] + x0 := y0.Args[0] + if x0.Op != OpARM64MOVWUload { + break + } + if x0.AuxInt != 4 { + break + } + s := x0.Aux + _ = x0.Args[1] + p := x0.Args[0] + mem := x0.Args[1] y1 := o2.Args[1] if y1.Op != OpARM64MOVDnop { break @@ -22887,21 +25621,16 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x1.Op != OpARM64MOVBUload { break } - if x1.AuxInt != 4 { + if x1.AuxInt != 3 { break } - s := x1.Aux - _ = x1.Args[1] - p1 := x1.Args[0] - if p1.Op != OpARM64ADDshiftLL { + if x1.Aux != s { break } - if p1.AuxInt != 2 { + _ = x1.Args[1] + if p != x1.Args[0] { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] if mem != x1.Args[1] { break } @@ -22913,14 +25642,16 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x2.Op != OpARM64MOVBUload { break } - if x2.AuxInt != 5 { + if x2.AuxInt != 2 { break } if x2.Aux != s { break } _ = x2.Args[1] - p := x2.Args[0] + if p != x2.Args[0] { + break + } if mem != x2.Args[1] { break } @@ -22932,16 +25663,20 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x3.Op != OpARM64MOVBUload { break } - if x3.AuxInt != 6 { + if x3.AuxInt != 1 { break } if x3.Aux != s { break } _ = x3.Args[1] - if p != x3.Args[0] { + p1 := x3.Args[0] + if p1.Op != OpARM64ADD { break } + _ = p1.Args[1] + ptr1 := p1.Args[0] + idx1 := p1.Args[1] if mem != x3.Args[1] { break } @@ -22950,40 +25685,32 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { break } x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUload { - break - } - if x4.AuxInt != 7 { - break - } - if x4.Aux != s { - break - } - _ = x4.Args[1] - if p != x4.Args[0] { + if x4.Op != OpARM64MOVBUloadidx { break } - if mem != x4.Args[1] { + _ = x4.Args[2] + ptr0 := x4.Args[0] + idx0 := x4.Args[1] + if mem != x4.Args[2] { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { + if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { break } b = mergePoint(b, x0, x1, x2, x3, x4) - v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v0 := b.NewValue0(v.Pos, OpARM64REV, t) v.reset(OpCopy) v.AddArg(v0) - v0.AddArg(ptr0) - v1 := b.NewValue0(v.Pos, OpARM64SLLconst, idx0.Type) - v1.AuxInt = 2 + v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v1.AddArg(ptr0) v1.AddArg(idx0) + v1.AddArg(mem) v0.AddArg(v1) - v0.AddArg(mem) return true } - // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] x0:(MOVWUloadidx ptr idx mem) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [4] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [5] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [6] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr (ADDconst [7] idx) mem))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) - // result: @mergePoint(b,x0,x1,x2,x3,x4) (MOVDloadidx ptr idx mem) + // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] y0:(REVW x0:(MOVWUloadidx ptr (ADDconst [4] idx) mem)) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr idx mem))) + // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) + // result: @mergePoint(b,x0,x1,x2,x3,x4) (REV (MOVDloadidx ptr idx mem)) for { t := v.Type if v.AuxInt != 56 { @@ -23014,13 +25741,24 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { break } _ = o2.Args[1] - x0 := o2.Args[0] + y0 := o2.Args[0] + if y0.Op != OpARM64REVW { + break + } + x0 := y0.Args[0] if x0.Op != OpARM64MOVWUloadidx { break } _ = x0.Args[2] ptr := x0.Args[0] - idx := x0.Args[1] + x0_1 := x0.Args[1] + if x0_1.Op != OpARM64ADDconst { + break + } + if x0_1.AuxInt != 4 { + break + } + idx := x0_1.Args[0] mem := x0.Args[2] y1 := o2.Args[1] if y1.Op != OpARM64MOVDnop { @@ -23038,7 +25776,7 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x1_1.Op != OpARM64ADDconst { break } - if x1_1.AuxInt != 4 { + if x1_1.AuxInt != 3 { break } if idx != x1_1.Args[0] { @@ -23063,7 +25801,7 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x2_1.Op != OpARM64ADDconst { break } - if x2_1.AuxInt != 5 { + if x2_1.AuxInt != 2 { break } if idx != x2_1.Args[0] { @@ -23088,7 +25826,7 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if x3_1.Op != OpARM64ADDconst { break } - if x3_1.AuxInt != 6 { + if x3_1.AuxInt != 1 { break } if idx != x3_1.Args[0] { @@ -23109,944 +25847,1820 @@ func rewriteValueARM64_OpARM64ORshiftLL_10(v *Value) bool { if ptr != x4.Args[0] { break } - x4_1 := x4.Args[1] - if x4_1.Op != OpARM64ADDconst { - break - } - if x4_1.AuxInt != 7 { - break - } - if idx != x4_1.Args[0] { + if idx != x4.Args[1] { break } if mem != x4.Args[2] { break } - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { + if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { break } b = mergePoint(b, x0, x1, x2, x3, x4) - v0 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v0 := b.NewValue0(v.Pos, OpARM64REV, t) v.reset(OpCopy) v.AddArg(v0) - v0.AddArg(ptr) - v0.AddArg(idx) - v0.AddArg(mem) + v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) + v1.AddArg(ptr) + v1.AddArg(idx) + v1.AddArg(mem) + v0.AddArg(v1) return true } - // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUload [i1] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [i0] {s} p mem))) - // cond: i1 == i0+1 && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) - // result: @mergePoint(b,x0,x1) (REV16W (MOVHUload [i0] {s} p mem)) + return false +} +func rewriteValueARM64_OpARM64ORshiftRA_0(v *Value) bool { + b := v.Block + _ = b + // match: (ORshiftRA (MOVDconst [c]) x [d]) + // cond: + // result: (ORconst [c] (SRAconst x [d])) for { - t := v.Type - if v.AuxInt != 8 { - break - } + d := v.AuxInt _ = v.Args[1] - y0 := v.Args[0] - if y0.Op != OpARM64MOVDnop { - break - } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUload { - break - } - i1 := x0.AuxInt - s := x0.Aux - _ = x0.Args[1] - p := x0.Args[0] - mem := x0.Args[1] - y1 := v.Args[1] - if y1.Op != OpARM64MOVDnop { - break - } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - i0 := x1.AuxInt - if x1.Aux != s { + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64ORconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SRAconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (ORshiftRA x (MOVDconst [c]) [d]) + // cond: + // result: (ORconst x [c>>uint64(d)]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x1.Args[1] - if p != x1.Args[0] { + c := v_1.AuxInt + v.reset(OpARM64ORconst) + v.AuxInt = c >> uint64(d) + v.AddArg(x) + return true + } + // match: (ORshiftRA x y:(SRAconst x [c]) [d]) + // cond: c==d + // result: y + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if y.Op != OpARM64SRAconst { break } - if mem != x1.Args[1] { + c := y.AuxInt + if x != y.Args[0] { break } - if !(i1 == i0+1 && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { + if !(c == d) { break } - b = mergePoint(b, x0, x1) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, t) v.reset(OpCopy) - v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVHUload, t) - v1.AuxInt = i0 - v1.Aux = s - v1.AddArg(p) - v1.AddArg(mem) - v0.AddArg(v1) + v.Type = y.Type + v.AddArg(y) return true } return false } -func rewriteValueARM64_OpARM64ORshiftLL_20(v *Value) bool { +func rewriteValueARM64_OpARM64ORshiftRL_0(v *Value) bool { b := v.Block _ = b - // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem)) y1:(MOVDnop x1:(MOVBUloadidx ptr0 idx0 mem))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) - // result: @mergePoint(b,x0,x1) (REV16W (MOVHUloadidx ptr0 idx0 mem)) + // match: (ORshiftRL (MOVDconst [c]) x [d]) + // cond: + // result: (ORconst [c] (SRLconst x [d])) for { - t := v.Type - if v.AuxInt != 8 { - break - } + d := v.AuxInt _ = v.Args[1] - y0 := v.Args[0] - if y0.Op != OpARM64MOVDnop { - break - } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUload { - break - } - if x0.AuxInt != 1 { - break - } - s := x0.Aux - _ = x0.Args[1] - p1 := x0.Args[0] - if p1.Op != OpARM64ADD { - break - } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - mem := x0.Args[1] - y1 := v.Args[1] - if y1.Op != OpARM64MOVDnop { - break - } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUloadidx { - break - } - _ = x1.Args[2] - ptr0 := x1.Args[0] - idx0 := x1.Args[1] - if mem != x1.Args[2] { - break - } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - b = mergePoint(b, x0, x1) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, t) - v.reset(OpCopy) + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64ORconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SRLconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVHUloadidx, t) - v1.AddArg(ptr0) - v1.AddArg(idx0) - v1.AddArg(mem) - v0.AddArg(v1) return true } - // match: (ORshiftLL [8] y0:(MOVDnop x0:(MOVBUloadidx ptr (ADDconst [1] idx) mem)) y1:(MOVDnop x1:(MOVBUloadidx ptr idx mem))) - // cond: x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b,x0,x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1) - // result: @mergePoint(b,x0,x1) (REV16W (MOVHUloadidx ptr idx mem)) + // match: (ORshiftRL x (MOVDconst [c]) [d]) + // cond: + // result: (ORconst x [int64(uint64(c)>>uint64(d))]) for { - t := v.Type - if v.AuxInt != 8 { - break - } + d := v.AuxInt _ = v.Args[1] - y0 := v.Args[0] - if y0.Op != OpARM64MOVDnop { - break - } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVBUloadidx { - break - } - _ = x0.Args[2] - ptr := x0.Args[0] - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64ADDconst { - break - } - if x0_1.AuxInt != 1 { + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - idx := x0_1.Args[0] - mem := x0.Args[2] - y1 := v.Args[1] - if y1.Op != OpARM64MOVDnop { + c := v_1.AuxInt + v.reset(OpARM64ORconst) + v.AuxInt = int64(uint64(c) >> uint64(d)) + v.AddArg(x) + return true + } + // match: (ORshiftRL x y:(SRLconst x [c]) [d]) + // cond: c==d + // result: y + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if y.Op != OpARM64SRLconst { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUloadidx { + c := y.AuxInt + if x != y.Args[0] { break - } - _ = x1.Args[2] - if ptr != x1.Args[0] { + } + if !(c == d) { break } - if idx != x1.Args[1] { + v.reset(OpCopy) + v.Type = y.Type + v.AddArg(y) + return true + } + // match: (ORshiftRL [c] (SLLconst x [64-c]) x) + // cond: + // result: (RORconst [ c] x) + for { + c := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - if mem != x1.Args[2] { + if v_0.AuxInt != 64-c { break } - if !(x0.Uses == 1 && x1.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && mergePoint(b, x0, x1) != nil && clobber(x0) && clobber(x1) && clobber(y0) && clobber(y1)) { + x := v_0.Args[0] + if x != v.Args[1] { break } - b = mergePoint(b, x0, x1) - v0 := b.NewValue0(v.Pos, OpARM64REV16W, t) - v.reset(OpCopy) - v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVHUloadidx, t) - v1.AddArg(ptr) - v1.AddArg(idx) - v1.AddArg(mem) - v0.AddArg(v1) + v.reset(OpARM64RORconst) + v.AuxInt = c + v.AddArg(x) return true } - // match: (ORshiftLL [24] o0:(ORshiftLL [16] y0:(REV16W x0:(MOVHUload [i2] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [i1] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i0] {s} p mem))) - // cond: i1 == i0+1 && i2 == i0+2 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0) - // result: @mergePoint(b,x0,x1,x2) (REVW (MOVWUload {s} (OffPtr [i0] p) mem)) + // match: (ORshiftRL [c] (SLLconst x [32-c]) (MOVWUreg x)) + // cond: c < 32 && t.Size() == 4 + // result: (RORWconst [c] x) for { t := v.Type - if v.AuxInt != 24 { + c := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - _ = v.Args[1] - o0 := v.Args[0] - if o0.Op != OpARM64ORshiftLL { + if v_0.AuxInt != 32-c { break } - if o0.AuxInt != 16 { + x := v_0.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWUreg { break } - _ = o0.Args[1] - y0 := o0.Args[0] - if y0.Op != OpARM64REV16W { + if x != v_1.Args[0] { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVHUload { + if !(c < 32 && t.Size() == 4) { break } - i2 := x0.AuxInt - s := x0.Aux - _ = x0.Args[1] - p := x0.Args[0] - mem := x0.Args[1] - y1 := o0.Args[1] - if y1.Op != OpARM64MOVDnop { + v.reset(OpARM64RORWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (ORshiftRL [rc] (ANDconst [ac] x) (SLLconst [lc] y)) + // cond: lc > rc && ac == ^((1< rc && ac == ^((1< [24] o0:(ORshiftLL [16] y0:(REV16W x0:(MOVHUload [2] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr0 idx0 mem))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0) - // result: @mergePoint(b,x0,x1,x2) (REVW (MOVWUloadidx ptr0 idx0 mem)) + // match: (SLLconst [sc] (MOVWUreg x)) + // cond: isARM64BFMask(sc, 1<<32-1, 0) + // result: (UBFIZ [arm64BFAuxInt(sc, 32)] x) for { - t := v.Type - if v.AuxInt != 24 { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVWUreg { break } - _ = v.Args[1] - o0 := v.Args[0] - if o0.Op != OpARM64ORshiftLL { + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<32-1, 0)) { break } - if o0.AuxInt != 16 { + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(sc, 32) + v.AddArg(x) + return true + } + // match: (SLLconst [sc] (MOVHUreg x)) + // cond: isARM64BFMask(sc, 1<<16-1, 0) + // result: (UBFIZ [arm64BFAuxInt(sc, 16)] x) + for { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVHUreg { break } - _ = o0.Args[1] - y0 := o0.Args[0] - if y0.Op != OpARM64REV16W { + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<16-1, 0)) { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVHUload { + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(sc, 16) + v.AddArg(x) + return true + } + // match: (SLLconst [sc] (MOVBUreg x)) + // cond: isARM64BFMask(sc, 1<<8-1, 0) + // result: (UBFIZ [arm64BFAuxInt(sc, 8)] x) + for { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVBUreg { break } - if x0.AuxInt != 2 { + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<8-1, 0)) { break } - s := x0.Aux - _ = x0.Args[1] - p := x0.Args[0] - mem := x0.Args[1] - y1 := o0.Args[1] - if y1.Op != OpARM64MOVDnop { + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(sc, 8) + v.AddArg(x) + return true + } + // match: (SLLconst [sc] (UBFIZ [bfc] x)) + // cond: sc+getARM64BFwidth(bfc)+getARM64BFlsb(bfc) < 64 + // result: (UBFIZ [arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc))] x) + for { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64UBFIZ { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + bfc := v_0.AuxInt + x := v_0.Args[0] + if !(sc+getARM64BFwidth(bfc)+getARM64BFlsb(bfc) < 64) { break } - if x1.AuxInt != 1 { + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64SRA_0(v *Value) bool { + // match: (SRA x (MOVDconst [c])) + // cond: + // result: (SRAconst x [c&63]) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if x1.Aux != s { + c := v_1.AuxInt + v.reset(OpARM64SRAconst) + v.AuxInt = c & 63 + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64SRAconst_0(v *Value) bool { + // match: (SRAconst [c] (MOVDconst [d])) + // cond: + // result: (MOVDconst [d>>uint64(c)]) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x1.Args[1] - p1 := x1.Args[0] - if p1.Op != OpARM64ADD { + d := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = d >> uint64(c) + return true + } + // match: (SRAconst [rc] (SLLconst [lc] x)) + // cond: lc > rc + // result: (SBFIZ [arm64BFAuxInt(lc-rc, 64-lc)] x) + for { + rc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - if mem != x1.Args[1] { + lc := v_0.AuxInt + x := v_0.Args[0] + if !(lc > rc) { break } - y2 := v.Args[1] - if y2.Op != OpARM64MOVDnop { + v.reset(OpARM64SBFIZ) + v.AuxInt = arm64BFAuxInt(lc-rc, 64-lc) + v.AddArg(x) + return true + } + // match: (SRAconst [rc] (SLLconst [lc] x)) + // cond: lc <= rc + // result: (SBFX [arm64BFAuxInt(rc-lc, 64-rc)] x) + for { + rc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUloadidx { + lc := v_0.AuxInt + x := v_0.Args[0] + if !(lc <= rc) { break } - _ = x2.Args[2] - ptr0 := x2.Args[0] - idx0 := x2.Args[1] - if mem != x2.Args[2] { + v.reset(OpARM64SBFX) + v.AuxInt = arm64BFAuxInt(rc-lc, 64-rc) + v.AddArg(x) + return true + } + // match: (SRAconst [rc] (MOVWreg x)) + // cond: rc < 32 + // result: (SBFX [arm64BFAuxInt(rc, 32-rc)] x) + for { + rc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVWreg { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0)) { + x := v_0.Args[0] + if !(rc < 32) { break } - b = mergePoint(b, x0, x1, x2) - v0 := b.NewValue0(v.Pos, OpARM64REVW, t) - v.reset(OpCopy) - v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) - v1.AddArg(ptr0) - v1.AddArg(idx0) - v1.AddArg(mem) - v0.AddArg(v1) + v.reset(OpARM64SBFX) + v.AuxInt = arm64BFAuxInt(rc, 32-rc) + v.AddArg(x) return true } - // match: (ORshiftLL [24] o0:(ORshiftLL [16] y0:(REV16W x0:(MOVHUloadidx ptr (ADDconst [2] idx) mem)) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr idx mem))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b,x0,x1,x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0) - // result: @mergePoint(b,x0,x1,x2) (REVW (MOVWUloadidx ptr idx mem)) + // match: (SRAconst [rc] (MOVHreg x)) + // cond: rc < 16 + // result: (SBFX [arm64BFAuxInt(rc, 16-rc)] x) for { - t := v.Type - if v.AuxInt != 24 { + rc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVHreg { break } - _ = v.Args[1] - o0 := v.Args[0] - if o0.Op != OpARM64ORshiftLL { + x := v_0.Args[0] + if !(rc < 16) { break } - if o0.AuxInt != 16 { + v.reset(OpARM64SBFX) + v.AuxInt = arm64BFAuxInt(rc, 16-rc) + v.AddArg(x) + return true + } + // match: (SRAconst [rc] (MOVBreg x)) + // cond: rc < 8 + // result: (SBFX [arm64BFAuxInt(rc, 8-rc)] x) + for { + rc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVBreg { break } - _ = o0.Args[1] - y0 := o0.Args[0] - if y0.Op != OpARM64REV16W { + x := v_0.Args[0] + if !(rc < 8) { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVHUloadidx { + v.reset(OpARM64SBFX) + v.AuxInt = arm64BFAuxInt(rc, 8-rc) + v.AddArg(x) + return true + } + // match: (SRAconst [sc] (SBFIZ [bfc] x)) + // cond: sc < getARM64BFlsb(bfc) + // result: (SBFIZ [arm64BFAuxInt(getARM64BFlsb(bfc)-sc, getARM64BFwidth(bfc))] x) + for { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SBFIZ { break } - _ = x0.Args[2] - ptr := x0.Args[0] - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64ADDconst { + bfc := v_0.AuxInt + x := v_0.Args[0] + if !(sc < getARM64BFlsb(bfc)) { break } - if x0_1.AuxInt != 2 { + v.reset(OpARM64SBFIZ) + v.AuxInt = arm64BFAuxInt(getARM64BFlsb(bfc)-sc, getARM64BFwidth(bfc)) + v.AddArg(x) + return true + } + // match: (SRAconst [sc] (SBFIZ [bfc] x)) + // cond: sc >= getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc) + // result: (SBFX [arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc)] x) + for { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SBFIZ { break } - idx := x0_1.Args[0] - mem := x0.Args[2] - y1 := o0.Args[1] - if y1.Op != OpARM64MOVDnop { + bfc := v_0.AuxInt + x := v_0.Args[0] + if !(sc >= getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc)) { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUloadidx { + v.reset(OpARM64SBFX) + v.AuxInt = arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64SRL_0(v *Value) bool { + // match: (SRL x (MOVDconst [c])) + // cond: + // result: (SRLconst x [c&63]) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x1.Args[2] - if ptr != x1.Args[0] { + c := v_1.AuxInt + v.reset(OpARM64SRLconst) + v.AuxInt = c & 63 + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64SRLconst_0(v *Value) bool { + // match: (SRLconst [c] (MOVDconst [d])) + // cond: + // result: (MOVDconst [int64(uint64(d)>>uint64(c))]) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + d := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(uint64(d) >> uint64(c)) + return true + } + // match: (SRLconst [c] (SLLconst [c] x)) + // cond: 0 < c && c < 64 + // result: (ANDconst [1< rc + // result: (UBFIZ [arm64BFAuxInt(lc-rc, 64-lc)] x) + for { + rc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - if mem != x1.Args[2] { + lc := v_0.AuxInt + x := v_0.Args[0] + if !(lc > rc) { break } - y2 := v.Args[1] - if y2.Op != OpARM64MOVDnop { + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(lc-rc, 64-lc) + v.AddArg(x) + return true + } + // match: (SRLconst [sc] (ANDconst [ac] x)) + // cond: isARM64BFMask(sc, ac, sc) + // result: (UBFX [arm64BFAuxInt(sc, arm64BFWidth(ac, sc))] x) + for { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64ANDconst { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUloadidx { + ac := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, ac, sc)) { break } - _ = x2.Args[2] - if ptr != x2.Args[0] { + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(ac, sc)) + v.AddArg(x) + return true + } + // match: (SRLconst [sc] (MOVWUreg x)) + // cond: isARM64BFMask(sc, 1<<32-1, sc) + // result: (UBFX [arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc))] x) + for { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVWUreg { break } - if idx != x2.Args[1] { + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<32-1, sc)) { break } - if mem != x2.Args[2] { + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc)) + v.AddArg(x) + return true + } + // match: (SRLconst [sc] (MOVHUreg x)) + // cond: isARM64BFMask(sc, 1<<16-1, sc) + // result: (UBFX [arm64BFAuxInt(sc, arm64BFWidth(1<<16-1, sc))] x) + for { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVHUreg { break } - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && o0.Uses == 1 && mergePoint(b, x0, x1, x2) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(o0)) { + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<16-1, sc)) { break } - b = mergePoint(b, x0, x1, x2) - v0 := b.NewValue0(v.Pos, OpARM64REVW, t) - v.reset(OpCopy) - v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVWUloadidx, t) - v1.AddArg(ptr) - v1.AddArg(idx) - v1.AddArg(mem) - v0.AddArg(v1) + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<16-1, sc)) + v.AddArg(x) return true } - // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] y0:(REVW x0:(MOVWUload [i4] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [i3] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [i2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [i1] {s} p mem))) y4:(MOVDnop x4:(MOVBUload [i0] {s} p mem))) - // cond: i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) - // result: @mergePoint(b,x0,x1,x2,x3,x4) (REV (MOVDload {s} (OffPtr [i0] p) mem)) + // match: (SRLconst [sc] (MOVBUreg x)) + // cond: isARM64BFMask(sc, 1<<8-1, sc) + // result: (UBFX [arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc))] x) for { - t := v.Type - if v.AuxInt != 56 { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVBUreg { break } - _ = v.Args[1] - o0 := v.Args[0] - if o0.Op != OpARM64ORshiftLL { + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<8-1, sc)) { break } - if o0.AuxInt != 48 { + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc)) + v.AddArg(x) + return true + } + // match: (SRLconst [rc] (SLLconst [lc] x)) + // cond: lc < rc + // result: (UBFX [arm64BFAuxInt(rc-lc, 64-rc)] x) + for { + rc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - _ = o0.Args[1] - o1 := o0.Args[0] - if o1.Op != OpARM64ORshiftLL { + lc := v_0.AuxInt + x := v_0.Args[0] + if !(lc < rc) { break } - if o1.AuxInt != 40 { + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(rc-lc, 64-rc) + v.AddArg(x) + return true + } + // match: (SRLconst [sc] (UBFX [bfc] x)) + // cond: sc < getARM64BFwidth(bfc) + // result: (UBFX [arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)-sc)] x) + for { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64UBFX { break } - _ = o1.Args[1] - o2 := o1.Args[0] - if o2.Op != OpARM64ORshiftLL { + bfc := v_0.AuxInt + x := v_0.Args[0] + if !(sc < getARM64BFwidth(bfc)) { break } - if o2.AuxInt != 32 { + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)-sc) + v.AddArg(x) + return true + } + // match: (SRLconst [sc] (UBFIZ [bfc] x)) + // cond: sc == getARM64BFlsb(bfc) + // result: (ANDconst [1< getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc) + // result: (UBFX [arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc)] x) + for { + sc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64UBFIZ { break } - i3 := x1.AuxInt - if x1.Aux != s { + bfc := v_0.AuxInt + x := v_0.Args[0] + if !(sc > getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc)) { break } - _ = x1.Args[1] - if p != x1.Args[0] { + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64STP_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (STP [off1] {sym} (ADDconst [off2] ptr) val1 val2 mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (STP [off1+off2] {sym} ptr val1 val2 mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[3] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - if mem != x1.Args[1] { + off2 := v_0.AuxInt + ptr := v_0.Args[0] + val1 := v.Args[1] + val2 := v.Args[2] + mem := v.Args[3] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64STP) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(val1) + v.AddArg(val2) + v.AddArg(mem) + return true + } + // match: (STP [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val1 val2 mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (STP [off1+off2] {mergeSym(sym1,sym2)} ptr val1 val2 mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[3] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { break } - y2 := o1.Args[1] - if y2.Op != OpARM64MOVDnop { + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + val1 := v.Args[1] + val2 := v.Args[2] + mem := v.Args[3] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUload { + v.reset(OpARM64STP) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(val1) + v.AddArg(val2) + v.AddArg(mem) + return true + } + // match: (STP [off] {sym} ptr (MOVDconst [0]) (MOVDconst [0]) mem) + // cond: + // result: (MOVQstorezero [off] {sym} ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[3] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - i2 := x2.AuxInt - if x2.Aux != s { + if v_1.AuxInt != 0 { break } - _ = x2.Args[1] - if p != x2.Args[0] { + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - if mem != x2.Args[1] { + if v_2.AuxInt != 0 { break } - y3 := o0.Args[1] - if y3.Op != OpARM64MOVDnop { + mem := v.Args[3] + v.reset(OpARM64MOVQstorezero) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { + b := v.Block + _ = b + // match: (SUB x (MOVDconst [c])) + // cond: + // result: (SUBconst [c] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUload { + c := v_1.AuxInt + v.reset(OpARM64SUBconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (SUB a l:(MUL x y)) + // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MSUB a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MUL { break } - i1 := x3.AuxInt - if x3.Aux != s { + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { break } - _ = x3.Args[1] - if p != x3.Args[0] { + v.reset(OpARM64MSUB) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (SUB a l:(MNEG x y)) + // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MADD a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MNEG { break } - if mem != x3.Args[1] { + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { break } - y4 := v.Args[1] - if y4.Op != OpARM64MOVDnop { + v.reset(OpARM64MADD) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (SUB a l:(MULW x y)) + // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MSUBW a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MULW { break } - x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUload { + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { break } - i0 := x4.AuxInt - if x4.Aux != s { + v.reset(OpARM64MSUBW) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (SUB a l:(MNEGW x y)) + // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // result: (MADDW a x y) + for { + _ = v.Args[1] + a := v.Args[0] + l := v.Args[1] + if l.Op != OpARM64MNEGW { break } - _ = x4.Args[1] - if p != x4.Args[0] { + _ = l.Args[1] + x := l.Args[0] + y := l.Args[1] + if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { break } - if mem != x4.Args[1] { + v.reset(OpARM64MADDW) + v.AddArg(a) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (SUB x x) + // cond: + // result: (MOVDconst [0]) + for { + _ = v.Args[1] + x := v.Args[0] + if x != v.Args[1] { break } - if !(i1 == i0+1 && i2 == i0+2 && i3 == i0+3 && i4 == i0+4 && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (SUB x (SUB y z)) + // cond: + // result: (SUB (ADD x z) y) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SUB { break } - b = mergePoint(b, x0, x1, x2, x3, x4) - v0 := b.NewValue0(v.Pos, OpARM64REV, t) - v.reset(OpCopy) + _ = v_1.Args[1] + y := v_1.Args[0] + z := v_1.Args[1] + v.reset(OpARM64SUB) + v0 := b.NewValue0(v.Pos, OpARM64ADD, v.Type) + v0.AddArg(x) + v0.AddArg(z) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVDload, t) - v1.Aux = s - v2 := b.NewValue0(v.Pos, OpOffPtr, p.Type) - v2.AuxInt = i0 - v2.AddArg(p) - v1.AddArg(v2) - v1.AddArg(mem) - v0.AddArg(v1) + v.AddArg(y) return true } - // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] y0:(REVW x0:(MOVWUload [4] {s} p mem)) y1:(MOVDnop x1:(MOVBUload [3] {s} p mem))) y2:(MOVDnop x2:(MOVBUload [2] {s} p mem))) y3:(MOVDnop x3:(MOVBUload [1] {s} p1:(ADD ptr1 idx1) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr0 idx0 mem))) - // cond: s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) - // result: @mergePoint(b,x0,x1,x2,x3,x4) (REV (MOVDloadidx ptr0 idx0 mem)) + // match: (SUB (SUB x y) z) + // cond: + // result: (SUB x (ADD y z)) for { - t := v.Type - if v.AuxInt != 56 { - break - } _ = v.Args[1] - o0 := v.Args[0] - if o0.Op != OpARM64ORshiftLL { - break - } - if o0.AuxInt != 48 { - break - } - _ = o0.Args[1] - o1 := o0.Args[0] - if o1.Op != OpARM64ORshiftLL { + v_0 := v.Args[0] + if v_0.Op != OpARM64SUB { break } - if o1.AuxInt != 40 { + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + z := v.Args[1] + v.reset(OpARM64SUB) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64ADD, y.Type) + v0.AddArg(y) + v0.AddArg(z) + v.AddArg(v0) + return true + } + // match: (SUB x0 x1:(SLLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (SUBshiftLL x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SLLconst { break } - _ = o1.Args[1] - o2 := o1.Args[0] - if o2.Op != OpARM64ORshiftLL { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - if o2.AuxInt != 32 { + v.reset(OpARM64SUBshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (SUB x0 x1:(SRLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (SUBshiftRL x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRLconst { break } - _ = o2.Args[1] - y0 := o2.Args[0] - if y0.Op != OpARM64REVW { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVWUload { + v.reset(OpARM64SUBshiftRL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + return false +} +func rewriteValueARM64_OpARM64SUB_10(v *Value) bool { + // match: (SUB x0 x1:(SRAconst [c] y)) + // cond: clobberIfDead(x1) + // result: (SUBshiftRA x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRAconst { break } - if x0.AuxInt != 4 { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - s := x0.Aux - _ = x0.Args[1] - p := x0.Args[0] - mem := x0.Args[1] - y1 := o2.Args[1] - if y1.Op != OpARM64MOVDnop { + v.reset(OpARM64SUBshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + return false +} +func rewriteValueARM64_OpARM64SUBconst_0(v *Value) bool { + // match: (SUBconst [0] x) + // cond: + // result: x + for { + if v.AuxInt != 0 { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUload { + x := v.Args[0] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (SUBconst [c] (MOVDconst [d])) + // cond: + // result: (MOVDconst [d-c]) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x1.AuxInt != 3 { + d := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = d - c + return true + } + // match: (SUBconst [c] (SUBconst [d] x)) + // cond: + // result: (ADDconst [-c-d] x) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SUBconst { break } - if x1.Aux != s { + d := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ADDconst) + v.AuxInt = -c - d + v.AddArg(x) + return true + } + // match: (SUBconst [c] (ADDconst [d] x)) + // cond: + // result: (ADDconst [-c+d] x) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { break } - _ = x1.Args[1] - if p != x1.Args[0] { + d := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ADDconst) + v.AuxInt = -c + d + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64SUBshiftLL_0(v *Value) bool { + // match: (SUBshiftLL x (MOVDconst [c]) [d]) + // cond: + // result: (SUBconst x [int64(uint64(c)<>uint64(d)]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if x2.Aux != s { + c := v_1.AuxInt + v.reset(OpARM64SUBconst) + v.AuxInt = c >> uint64(d) + v.AddArg(x) + return true + } + // match: (SUBshiftRA x (SRAconst x [c]) [d]) + // cond: c==d + // result: (MOVDconst [0]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRAconst { break } - _ = x2.Args[1] - if p != x2.Args[0] { + c := v_1.AuxInt + if x != v_1.Args[0] { break } - if mem != x2.Args[1] { + if !(c == d) { break } - y3 := o0.Args[1] - if y3.Op != OpARM64MOVDnop { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64SUBshiftRL_0(v *Value) bool { + // match: (SUBshiftRL x (MOVDconst [c]) [d]) + // cond: + // result: (SUBconst x [int64(uint64(c)>>uint64(d))]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUload { + c := v_1.AuxInt + v.reset(OpARM64SUBconst) + v.AuxInt = int64(uint64(c) >> uint64(d)) + v.AddArg(x) + return true + } + // match: (SUBshiftRL x (SRLconst x [c]) [d]) + // cond: c==d + // result: (MOVDconst [0]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - if x3.AuxInt != 1 { + c := v_1.AuxInt + if x != v_1.Args[0] { break } - if x3.Aux != s { + if !(c == d) { break } - _ = x3.Args[1] - p1 := x3.Args[0] - if p1.Op != OpARM64ADD { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64TST_0(v *Value) bool { + // match: (TST x (MOVDconst [c])) + // cond: + // result: (TSTconst [c] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = p1.Args[1] - ptr1 := p1.Args[0] - idx1 := p1.Args[1] - if mem != x3.Args[1] { + c := v_1.AuxInt + v.reset(OpARM64TSTconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (TST (MOVDconst [c]) x) + // cond: + // result: (TSTconst [c] x) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - y4 := v.Args[1] - if y4.Op != OpARM64MOVDnop { + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64TSTconst) + v.AuxInt = c + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64TSTW_0(v *Value) bool { + // match: (TSTW x (MOVDconst [c])) + // cond: + // result: (TSTWconst [c] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUloadidx { + c := v_1.AuxInt + v.reset(OpARM64TSTWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (TSTW (MOVDconst [c]) x) + // cond: + // result: (TSTWconst [c] x) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x4.Args[2] - ptr0 := x4.Args[0] - idx0 := x4.Args[1] - if mem != x4.Args[2] { + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64TSTWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64TSTWconst_0(v *Value) bool { + // match: (TSTWconst (MOVDconst [x]) [y]) + // cond: int32(x&y)==0 + // result: (FlagEQ) + for { + y := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if !(s == nil && x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && isSamePtr(p1, p) && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { + x := v_0.AuxInt + if !(int32(x&y) == 0) { break } - b = mergePoint(b, x0, x1, x2, x3, x4) - v0 := b.NewValue0(v.Pos, OpARM64REV, t) - v.reset(OpCopy) - v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) - v1.AddArg(ptr0) - v1.AddArg(idx0) - v1.AddArg(mem) - v0.AddArg(v1) + v.reset(OpARM64FlagEQ) return true } - // match: (ORshiftLL [56] o0:(ORshiftLL [48] o1:(ORshiftLL [40] o2:(ORshiftLL [32] y0:(REVW x0:(MOVWUloadidx ptr (ADDconst [4] idx) mem)) y1:(MOVDnop x1:(MOVBUloadidx ptr (ADDconst [3] idx) mem))) y2:(MOVDnop x2:(MOVBUloadidx ptr (ADDconst [2] idx) mem))) y3:(MOVDnop x3:(MOVBUloadidx ptr (ADDconst [1] idx) mem))) y4:(MOVDnop x4:(MOVBUloadidx ptr idx mem))) - // cond: x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b,x0,x1,x2,x3,x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2) - // result: @mergePoint(b,x0,x1,x2,x3,x4) (REV (MOVDloadidx ptr idx mem)) + // match: (TSTWconst (MOVDconst [x]) [y]) + // cond: int32(x&y)<0 + // result: (FlagLT_UGT) for { - t := v.Type - if v.AuxInt != 56 { + y := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = v.Args[1] - o0 := v.Args[0] - if o0.Op != OpARM64ORshiftLL { + x := v_0.AuxInt + if !(int32(x&y) < 0) { break } - if o0.AuxInt != 48 { + v.reset(OpARM64FlagLT_UGT) + return true + } + // match: (TSTWconst (MOVDconst [x]) [y]) + // cond: int32(x&y)>0 + // result: (FlagGT_UGT) + for { + y := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = o0.Args[1] - o1 := o0.Args[0] - if o1.Op != OpARM64ORshiftLL { + x := v_0.AuxInt + if !(int32(x&y) > 0) { break } - if o1.AuxInt != 40 { + v.reset(OpARM64FlagGT_UGT) + return true + } + return false +} +func rewriteValueARM64_OpARM64TSTconst_0(v *Value) bool { + // match: (TSTconst (MOVDconst [x]) [y]) + // cond: int64(x&y)==0 + // result: (FlagEQ) + for { + y := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = o1.Args[1] - o2 := o1.Args[0] - if o2.Op != OpARM64ORshiftLL { + x := v_0.AuxInt + if !(int64(x&y) == 0) { break } - if o2.AuxInt != 32 { + v.reset(OpARM64FlagEQ) + return true + } + // match: (TSTconst (MOVDconst [x]) [y]) + // cond: int64(x&y)<0 + // result: (FlagLT_UGT) + for { + y := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = o2.Args[1] - y0 := o2.Args[0] - if y0.Op != OpARM64REVW { + x := v_0.AuxInt + if !(int64(x&y) < 0) { break } - x0 := y0.Args[0] - if x0.Op != OpARM64MOVWUloadidx { + v.reset(OpARM64FlagLT_UGT) + return true + } + // match: (TSTconst (MOVDconst [x]) [y]) + // cond: int64(x&y)>0 + // result: (FlagGT_UGT) + for { + y := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x0.Args[2] - ptr := x0.Args[0] - x0_1 := x0.Args[1] - if x0_1.Op != OpARM64ADDconst { + x := v_0.AuxInt + if !(int64(x&y) > 0) { break } - if x0_1.AuxInt != 4 { + v.reset(OpARM64FlagGT_UGT) + return true + } + return false +} +func rewriteValueARM64_OpARM64UBFIZ_0(v *Value) bool { + // match: (UBFIZ [bfc] (SLLconst [sc] x)) + // cond: sc < getARM64BFwidth(bfc) + // result: (UBFIZ [arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)-sc)] x) + for { + bfc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - idx := x0_1.Args[0] - mem := x0.Args[2] - y1 := o2.Args[1] - if y1.Op != OpARM64MOVDnop { + sc := v_0.AuxInt + x := v_0.Args[0] + if !(sc < getARM64BFwidth(bfc)) { break } - x1 := y1.Args[0] - if x1.Op != OpARM64MOVBUloadidx { + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)-sc) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64UBFX_0(v *Value) bool { + // match: (UBFX [bfc] (SRLconst [sc] x)) + // cond: sc+getARM64BFwidth(bfc)+getARM64BFlsb(bfc) < 64 + // result: (UBFX [arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc))] x) + for { + bfc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SRLconst { break } - _ = x1.Args[2] - if ptr != x1.Args[0] { + sc := v_0.AuxInt + x := v_0.Args[0] + if !(sc+getARM64BFwidth(bfc)+getARM64BFlsb(bfc) < 64) { break } - x1_1 := x1.Args[1] - if x1_1.Op != OpARM64ADDconst { + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)) + v.AddArg(x) + return true + } + // match: (UBFX [bfc] (SLLconst [sc] x)) + // cond: sc == getARM64BFlsb(bfc) + // result: (ANDconst [1< getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc) + // result: (UBFIZ [arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc)] x) + for { + bfc := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - x2 := y2.Args[0] - if x2.Op != OpARM64MOVBUloadidx { + sc := v_0.AuxInt + x := v_0.Args[0] + if !(sc > getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc)) { break } - _ = x2.Args[2] - if ptr != x2.Args[0] { + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64UDIV_0(v *Value) bool { + // match: (UDIV x (MOVDconst [1])) + // cond: + // result: x + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x2_1 := x2.Args[1] - if x2_1.Op != OpARM64ADDconst { + if v_1.AuxInt != 1 { break } - if x2_1.AuxInt != 2 { + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (UDIV x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (SRLconst [log2(c)] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if idx != x2_1.Args[0] { + c := v_1.AuxInt + if !(isPowerOfTwo(c)) { break } - if mem != x2.Args[2] { + v.reset(OpARM64SRLconst) + v.AuxInt = log2(c) + v.AddArg(x) + return true + } + // match: (UDIV (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [int64(uint64(c)/uint64(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - y3 := o0.Args[1] - if y3.Op != OpARM64MOVDnop { + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x3 := y3.Args[0] - if x3.Op != OpARM64MOVBUloadidx { + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(uint64(c) / uint64(d)) + return true + } + return false +} +func rewriteValueARM64_OpARM64UDIVW_0(v *Value) bool { + // match: (UDIVW x (MOVDconst [c])) + // cond: uint32(c)==1 + // result: x + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x3.Args[2] - if ptr != x3.Args[0] { + c := v_1.AuxInt + if !(uint32(c) == 1) { break } - x3_1 := x3.Args[1] - if x3_1.Op != OpARM64ADDconst { + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (UDIVW x (MOVDconst [c])) + // cond: isPowerOfTwo(c) && is32Bit(c) + // result: (SRLconst [log2(c)] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if x3_1.AuxInt != 1 { + c := v_1.AuxInt + if !(isPowerOfTwo(c) && is32Bit(c)) { break } - if idx != x3_1.Args[0] { + v.reset(OpARM64SRLconst) + v.AuxInt = log2(c) + v.AddArg(x) + return true + } + // match: (UDIVW (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [int64(uint32(c)/uint32(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if mem != x3.Args[2] { + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - y4 := v.Args[1] - if y4.Op != OpARM64MOVDnop { + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(uint32(c) / uint32(d)) + return true + } + return false +} +func rewriteValueARM64_OpARM64UMOD_0(v *Value) bool { + // match: (UMOD _ (MOVDconst [1])) + // cond: + // result: (MOVDconst [0]) + for { + _ = v.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x4 := y4.Args[0] - if x4.Op != OpARM64MOVBUloadidx { + if v_1.AuxInt != 1 { break } - _ = x4.Args[2] - if ptr != x4.Args[0] { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + // match: (UMOD x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (ANDconst [c-1] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if idx != x4.Args[1] { + c := v_1.AuxInt + if !(isPowerOfTwo(c)) { break } - if mem != x4.Args[2] { + v.reset(OpARM64ANDconst) + v.AuxInt = c - 1 + v.AddArg(x) + return true + } + // match: (UMOD (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [int64(uint64(c)%uint64(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if !(x0.Uses == 1 && x1.Uses == 1 && x2.Uses == 1 && x3.Uses == 1 && x4.Uses == 1 && y0.Uses == 1 && y1.Uses == 1 && y2.Uses == 1 && y3.Uses == 1 && y4.Uses == 1 && o0.Uses == 1 && o1.Uses == 1 && o2.Uses == 1 && mergePoint(b, x0, x1, x2, x3, x4) != nil && clobber(x0) && clobber(x1) && clobber(x2) && clobber(x3) && clobber(x4) && clobber(y0) && clobber(y1) && clobber(y2) && clobber(y3) && clobber(y4) && clobber(o0) && clobber(o1) && clobber(o2)) { + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - b = mergePoint(b, x0, x1, x2, x3, x4) - v0 := b.NewValue0(v.Pos, OpARM64REV, t) - v.reset(OpCopy) - v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpARM64MOVDloadidx, t) - v1.AddArg(ptr) - v1.AddArg(idx) - v1.AddArg(mem) - v0.AddArg(v1) + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(uint64(c) % uint64(d)) return true } return false } -func rewriteValueARM64_OpARM64ORshiftRA_0(v *Value) bool { - b := v.Block - _ = b - // match: (ORshiftRA (MOVDconst [c]) x [d]) - // cond: - // result: (ORconst [c] (SRAconst x [d])) +func rewriteValueARM64_OpARM64UMODW_0(v *Value) bool { + // match: (UMODW _ (MOVDconst [c])) + // cond: uint32(c)==1 + // result: (MOVDconst [0]) for { - d := v.AuxInt _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64ORconst) - v.AuxInt = c - v0 := b.NewValue0(v.Pos, OpARM64SRAconst, x.Type) - v0.AuxInt = d - v0.AddArg(x) - v.AddArg(v0) + c := v_1.AuxInt + if !(uint32(c) == 1) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (ORshiftRA x (MOVDconst [c]) [d]) - // cond: - // result: (ORconst x [c>>uint64(d)]) + // match: (UMODW x (MOVDconst [c])) + // cond: isPowerOfTwo(c) && is32Bit(c) + // result: (ANDconst [c-1] x) for { - d := v.AuxInt _ = v.Args[1] x := v.Args[0] v_1 := v.Args[1] @@ -24054,44 +27668,56 @@ func rewriteValueARM64_OpARM64ORshiftRA_0(v *Value) bool { break } c := v_1.AuxInt - v.reset(OpARM64ORconst) - v.AuxInt = c >> uint64(d) + if !(isPowerOfTwo(c) && is32Bit(c)) { + break + } + v.reset(OpARM64ANDconst) + v.AuxInt = c - 1 v.AddArg(x) return true } - // match: (ORshiftRA x y:(SRAconst x [c]) [d]) - // cond: c==d - // result: y + // match: (UMODW (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [int64(uint32(c)%uint32(d))]) for { - d := v.AuxInt _ = v.Args[1] - x := v.Args[0] - y := v.Args[1] - if y.Op != OpARM64SRAconst { - break - } - c := y.AuxInt - if x != y.Args[0] { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if !(c == d) { + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpCopy) - v.Type = y.Type - v.AddArg(y) + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(uint32(c) % uint32(d)) return true } return false } -func rewriteValueARM64_OpARM64ORshiftRL_0(v *Value) bool { - b := v.Block - _ = b - // match: (ORshiftRL (MOVDconst [c]) x [d]) +func rewriteValueARM64_OpARM64XOR_0(v *Value) bool { + // match: (XOR x (MOVDconst [c])) + // cond: + // result: (XORconst [c] x) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64XORconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (XOR (MOVDconst [c]) x) // cond: - // result: (ORconst [c] (SRLconst x [d])) + // result: (XORconst [c] x) for { - d := v.AuxInt _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { @@ -24099,1920 +27725,1098 @@ func rewriteValueARM64_OpARM64ORshiftRL_0(v *Value) bool { } c := v_0.AuxInt x := v.Args[1] - v.reset(OpARM64ORconst) + v.reset(OpARM64XORconst) v.AuxInt = c - v0 := b.NewValue0(v.Pos, OpARM64SRLconst, x.Type) - v0.AuxInt = d - v0.AddArg(x) - v.AddArg(v0) + v.AddArg(x) return true } - // match: (ORshiftRL x (MOVDconst [c]) [d]) + // match: (XOR x x) // cond: - // result: (ORconst x [int64(uint64(c)>>uint64(d))]) + // result: (MOVDconst [0]) for { - d := v.AuxInt _ = v.Args[1] x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if x != v.Args[1] { break } - c := v_1.AuxInt - v.reset(OpARM64ORconst) - v.AuxInt = int64(uint64(c) >> uint64(d)) - v.AddArg(x) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (ORshiftRL x y:(SRLconst x [c]) [d]) - // cond: c==d - // result: y + // match: (XOR x (MVN y)) + // cond: + // result: (EON x y) for { - d := v.AuxInt _ = v.Args[1] x := v.Args[0] - y := v.Args[1] - if y.Op != OpARM64SRLconst { - break - } - c := y.AuxInt - if x != y.Args[0] { - break - } - if !(c == d) { + v_1 := v.Args[1] + if v_1.Op != OpARM64MVN { break } - v.reset(OpCopy) - v.Type = y.Type + y := v_1.Args[0] + v.reset(OpARM64EON) + v.AddArg(x) v.AddArg(y) return true } - // match: (ORshiftRL [c] (SLLconst x [64-c]) x) + // match: (XOR (MVN y) x) // cond: - // result: (RORconst [ c] x) + // result: (EON x y) for { - c := v.AuxInt _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_0.Op != OpARM64MVN { break } - if v_0.AuxInt != 64-c { + y := v_0.Args[0] + x := v.Args[1] + v.reset(OpARM64EON) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (XOR x0 x1:(SLLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (XORshiftLL x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SLLconst { break } - x := v_0.Args[0] - if x != v.Args[1] { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - v.reset(OpARM64RORconst) + v.reset(OpARM64XORshiftLL) v.AuxInt = c - v.AddArg(x) + v.AddArg(x0) + v.AddArg(y) return true } - // match: (ORshiftRL [c] (SLLconst x [32-c]) (MOVWUreg x)) - // cond: c < 32 && t.Size() == 4 - // result: (RORWconst [c] x) + // match: (XOR x1:(SLLconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (XORshiftLL x0 y [c]) for { - t := v.Type - c := v.AuxInt _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { - break - } - if v_0.AuxInt != 32-c { + x1 := v.Args[0] + if x1.Op != OpARM64SLLconst { break } - x := v_0.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWUreg { + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { break } - if x != v_1.Args[0] { + v.reset(OpARM64XORshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (XOR x0 x1:(SRLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (XORshiftRL x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRLconst { break } - if !(c < 32 && t.Size() == 4) { + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { break } - v.reset(OpARM64RORWconst) + v.reset(OpARM64XORshiftRL) v.AuxInt = c - v.AddArg(x) + v.AddArg(x0) + v.AddArg(y) return true } - // match: (ORshiftRL [rc] (ANDconst [ac] x) (SLLconst [lc] y)) - // cond: lc > rc && ac == ^((1< rc && ac == ^((1< [63] y)) (CSEL0 {cc} (SRL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x (NEG y)) for { - c := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { + if v_0.Op != OpARM64SLL { break } - if v_0.AuxInt != c { + _ = v_0.Args[1] + x := v_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { break } - x := v_0.Args[0] - if !(0 < c && c < 64) { + t := v_0_1.Type + if v_0_1.AuxInt != 63 { break } - v.reset(OpARM64ANDconst) - v.AuxInt = ^(1<>uint64(c)]) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_1_1_0.Type != t { break } - d := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = d >> uint64(c) - return true - } - // match: (SRAconst [rc] (SLLconst [lc] x)) - // cond: lc > rc - // result: (SBFIZ [arm64BFAuxInt(lc-rc, 64-lc)] x) - for { - rc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { break } - lc := v_0.AuxInt - x := v_0.Args[0] - if !(lc > rc) { + if v_1_1_0_0.AuxInt != 64 { break } - v.reset(OpARM64SBFIZ) - v.AuxInt = arm64BFAuxInt(lc-rc, 64-lc) - v.AddArg(x) - return true - } - // match: (SRAconst [rc] (SLLconst [lc] x)) - // cond: lc <= rc - // result: (SBFX [arm64BFAuxInt(rc-lc, 64-rc)] x) - for { - rc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { break } - lc := v_0.AuxInt - x := v_0.Args[0] - if !(lc <= rc) { + if v_1_1_0_1.Type != t { break } - v.reset(OpARM64SBFX) - v.AuxInt = arm64BFAuxInt(rc-lc, 64-rc) - v.AddArg(x) - return true - } - // match: (SRAconst [rc] (MOVWreg x)) - // cond: rc < 32 - // result: (SBFX [arm64BFAuxInt(rc, 32-rc)] x) - for { - rc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVWreg { + if v_1_1_0_1.AuxInt != 63 { break } - x := v_0.Args[0] - if !(rc < 32) { + if y != v_1_1_0_1.Args[0] { break } - v.reset(OpARM64SBFX) - v.AuxInt = arm64BFAuxInt(rc, 32-rc) + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64ROR) v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) + v.AddArg(v0) return true } - // match: (SRAconst [rc] (MOVHreg x)) - // cond: rc < 16 - // result: (SBFX [arm64BFAuxInt(rc, 16-rc)] x) + // match: (XOR (CSEL0 {cc} (SRL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y)))) (SLL x (ANDconst [63] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x (NEG y)) for { - rc := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVHreg { + if v_0.Op != OpARM64CSEL0 { break } - x := v_0.Args[0] - if !(rc < 16) { + if v_0.Type != typ.UInt64 { break } - v.reset(OpARM64SBFX) - v.AuxInt = arm64BFAuxInt(rc, 16-rc) - v.AddArg(x) - return true - } - // match: (SRAconst [rc] (MOVBreg x)) - // cond: rc < 8 - // result: (SBFX [arm64BFAuxInt(rc, 8-rc)] x) - for { - rc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVBreg { + cc := v_0.Aux + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SRL { break } - x := v_0.Args[0] - if !(rc < 8) { + if v_0_0.Type != typ.UInt64 { break } - v.reset(OpARM64SBFX) - v.AuxInt = arm64BFAuxInt(rc, 8-rc) - v.AddArg(x) - return true - } - // match: (SRAconst [sc] (SBFIZ [bfc] x)) - // cond: sc < getARM64BFlsb(bfc) - // result: (SBFIZ [arm64BFAuxInt(getARM64BFlsb(bfc)-sc, getARM64BFwidth(bfc))] x) - for { - sc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SBFIZ { + _ = v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { break } - bfc := v_0.AuxInt - x := v_0.Args[0] - if !(sc < getARM64BFlsb(bfc)) { + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64SBFIZ) - v.AuxInt = arm64BFAuxInt(getARM64BFlsb(bfc)-sc, getARM64BFwidth(bfc)) - v.AddArg(x) - return true - } - // match: (SRAconst [sc] (SBFIZ [bfc] x)) - // cond: sc >= getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc) - // result: (SBFX [arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc)] x) - for { - sc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SBFIZ { + if v_0_0_1_0.AuxInt != 64 { break } - bfc := v_0.AuxInt - x := v_0.Args[0] - if !(sc >= getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc)) { + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64SBFX) - v.AuxInt = arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64SRL_0(v *Value) bool { - // match: (SRL x (MOVDconst [c])) - // cond: - // result: (SRLconst x [c&63]) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0_0_1_1.Type != t { break } - c := v_1.AuxInt - v.reset(OpARM64SRLconst) - v.AuxInt = c & 63 - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64SRLconst_0(v *Value) bool { - // match: (SRLconst [c] (MOVDconst [d])) - // cond: - // result: (MOVDconst [int64(uint64(d)>>uint64(c))]) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_0_1_1.AuxInt != 63 { break } - d := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(uint64(d) >> uint64(c)) - return true - } - // match: (SRLconst [c] (SLLconst [c] x)) - // cond: 0 < c && c < 64 - // result: (ANDconst [1< rc - // result: (UBFIZ [arm64BFAuxInt(lc-rc, 64-lc)] x) - for { - rc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_0_1_0.Type != t { break } - lc := v_0.AuxInt - x := v_0.Args[0] - if !(lc > rc) { + _ = v_0_1_0.Args[1] + v_0_1_0_0 := v_0_1_0.Args[0] + if v_0_1_0_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64UBFIZ) - v.AuxInt = arm64BFAuxInt(lc-rc, 64-lc) - v.AddArg(x) - return true - } - // match: (SRLconst [sc] (ANDconst [ac] x)) - // cond: isARM64BFMask(sc, ac, sc) - // result: (UBFX [arm64BFAuxInt(sc, arm64BFWidth(ac, sc))] x) - for { - sc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64ANDconst { + if v_0_1_0_0.AuxInt != 64 { break } - ac := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, ac, sc)) { + v_0_1_0_1 := v_0_1_0.Args[1] + if v_0_1_0_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(ac, sc)) - v.AddArg(x) - return true - } - // match: (SRLconst [sc] (MOVWUreg x)) - // cond: isARM64BFMask(sc, 1<<32-1, sc) - // result: (UBFX [arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc))] x) - for { - sc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVWUreg { + if v_0_1_0_1.Type != t { break } - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<32-1, sc)) { + if v_0_1_0_1.AuxInt != 63 { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc)) - v.AddArg(x) - return true - } - // match: (SRLconst [sc] (MOVHUreg x)) - // cond: isARM64BFMask(sc, 1<<16-1, sc) - // result: (UBFX [arm64BFAuxInt(sc, arm64BFWidth(1<<16-1, sc))] x) - for { - sc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVHUreg { + if y != v_0_1_0_1.Args[0] { break } - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<16-1, sc)) { + v_1 := v.Args[1] + if v_1.Op != OpARM64SLL { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<16-1, sc)) - v.AddArg(x) - return true - } - // match: (SRLconst [sc] (MOVBUreg x)) - // cond: isARM64BFMask(sc, 1<<8-1, sc) - // result: (UBFX [arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc))] x) - for { - sc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVBUreg { + _ = v_1.Args[1] + if x != v_1.Args[0] { break } - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<8-1, sc)) { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc)) - v.AddArg(x) - return true - } - // match: (SRLconst [rc] (SLLconst [lc] x)) - // cond: lc < rc - // result: (UBFX [arm64BFAuxInt(rc-lc, 64-rc)] x) - for { - rc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_1_1.Type != t { break } - lc := v_0.AuxInt - x := v_0.Args[0] - if !(lc < rc) { + if v_1_1.AuxInt != 63 { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(rc-lc, 64-rc) - v.AddArg(x) - return true - } - // match: (SRLconst [sc] (UBFX [bfc] x)) - // cond: sc < getARM64BFwidth(bfc) - // result: (UBFX [arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)-sc)] x) - for { - sc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64UBFX { + if y != v_1_1.Args[0] { break } - bfc := v_0.AuxInt - x := v_0.Args[0] - if !(sc < getARM64BFwidth(bfc)) { + if !(cc.(Op) == OpARM64LessThanU) { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)-sc) + v.reset(OpARM64ROR) v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) + v.AddArg(v0) return true } - // match: (SRLconst [sc] (UBFIZ [bfc] x)) - // cond: sc == getARM64BFlsb(bfc) - // result: (ANDconst [1< x (ANDconst [63] y)) (CSEL0 {cc} (SLL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x y) for { - sc := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64UBFIZ { + if v_0.Op != OpARM64SRL { break } - bfc := v_0.AuxInt - x := v_0.Args[0] - if !(sc == getARM64BFlsb(bfc)) { + if v_0.Type != typ.UInt64 { break } - v.reset(OpARM64ANDconst) - v.AuxInt = 1< getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc) - // result: (UBFX [arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc)] x) - for { - sc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64UBFIZ { + y := v_0_1.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64CSEL0 { break } - bfc := v_0.AuxInt - x := v_0.Args[0] - if !(sc > getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc)) { + if v_1.Type != typ.UInt64 { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64STP_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (STP [off1] {sym} (ADDconst [off2] ptr) val1 val2 mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (STP [off1+off2] {sym} ptr val1 val2 mem) - for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[3] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SLL { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - val1 := v.Args[1] - val2 := v.Args[2] - mem := v.Args[3] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = v_1_0.Args[1] + if x != v_1_0.Args[0] { break } - v.reset(OpARM64STP) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(val1) - v.AddArg(val2) - v.AddArg(mem) - return true - } - // match: (STP [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val1 val2 mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (STP [off1+off2] {mergeSym(sym1,sym2)} ptr val1 val2 mem) - for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[3] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + v_1_0_1 := v_1_0.Args[1] + if v_1_0_1.Op != OpARM64SUB { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - val1 := v.Args[1] - val2 := v.Args[2] - mem := v.Args[3] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_1_0_1.Type != t { break } - v.reset(OpARM64STP) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(val1) - v.AddArg(val2) - v.AddArg(mem) - return true - } - // match: (STP [off] {sym} ptr (MOVDconst [0]) (MOVDconst [0]) mem) - // cond: - // result: (MOVQstorezero [off] {sym} ptr mem) - for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_1_0_1.Args[1] + v_1_0_1_0 := v_1_0_1.Args[0] + if v_1_0_1_0.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 0 { + if v_1_0_1_0.AuxInt != 64 { break } - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDconst { + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { break } - if v_2.AuxInt != 0 { + if v_1_0_1_1.Type != t { break } - mem := v.Args[3] - v.reset(OpARM64MOVQstorezero) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) - return true - } - return false -} -func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { - b := v.Block - _ = b - // match: (SUB x (MOVDconst [c])) - // cond: - // result: (SUBconst [c] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_0_1_1.AuxInt != 63 { break } - c := v_1.AuxInt - v.reset(OpARM64SUBconst) - v.AuxInt = c - v.AddArg(x) - return true - } - // match: (SUB a l:(MUL x y)) - // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) - // result: (MSUB a x y) - for { - _ = v.Args[1] - a := v.Args[0] - l := v.Args[1] - if l.Op != OpARM64MUL { + if y != v_1_0_1_1.Args[0] { + break + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64CMPconst { break } - _ = l.Args[1] - x := l.Args[0] - y := l.Args[1] - if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if v_1_1.AuxInt != 64 { break } - v.reset(OpARM64MSUB) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (SUB a l:(MNEG x y)) - // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) - // result: (MADD a x y) - for { - _ = v.Args[1] - a := v.Args[0] - l := v.Args[1] - if l.Op != OpARM64MNEG { + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { break } - _ = l.Args[1] - x := l.Args[0] - y := l.Args[1] - if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if v_1_1_0.Type != t { break } - v.reset(OpARM64MADD) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (SUB a l:(MULW x y)) - // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) - // result: (MSUBW a x y) - for { - _ = v.Args[1] - a := v.Args[0] - l := v.Args[1] - if l.Op != OpARM64MULW { + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { break } - _ = l.Args[1] - x := l.Args[0] - y := l.Args[1] - if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if v_1_1_0_0.AuxInt != 64 { break } - v.reset(OpARM64MSUBW) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (SUB a l:(MNEGW x y)) - // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) - // result: (MADDW a x y) - for { - _ = v.Args[1] - a := v.Args[0] - l := v.Args[1] - if l.Op != OpARM64MNEGW { + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { break } - _ = l.Args[1] - x := l.Args[0] - y := l.Args[1] - if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if v_1_1_0_1.Type != t { break } - v.reset(OpARM64MADDW) - v.AddArg(a) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (SUB x x) - // cond: - // result: (MOVDconst [0]) - for { - _ = v.Args[1] - x := v.Args[0] - if x != v.Args[1] { + if v_1_1_0_1.AuxInt != 63 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (SUB x (SUB y z)) - // cond: - // result: (SUB (ADD x z) y) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SUB { + if y != v_1_1_0_1.Args[0] { break } - _ = v_1.Args[1] - y := v_1.Args[0] - z := v_1.Args[1] - v.reset(OpARM64SUB) - v0 := b.NewValue0(v.Pos, OpARM64ADD, v.Type) - v0.AddArg(x) - v0.AddArg(z) - v.AddArg(v0) + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64ROR) + v.AddArg(x) v.AddArg(y) return true } - // match: (SUB (SUB x y) z) - // cond: - // result: (SUB x (ADD y z)) + // match: (XOR (CSEL0 {cc} (SLL x (SUB (MOVDconst [64]) (ANDconst [63] y))) (CMPconst [64] (SUB (MOVDconst [64]) (ANDconst [63] y)))) (SRL x (ANDconst [63] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (ROR x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SUB { + if v_0.Op != OpARM64CSEL0 { + break + } + if v_0.Type != typ.UInt64 { break } + cc := v_0.Aux _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - z := v.Args[1] - v.reset(OpARM64SUB) - v.AddArg(x) - v0 := b.NewValue0(v.Pos, OpARM64ADD, y.Type) - v0.AddArg(y) - v0.AddArg(z) - v.AddArg(v0) - return true - } - // match: (SUB x0 x1:(SLLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (SUBshiftLL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SLLconst { + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SLL { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + _ = v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { break } - v.reset(OpARM64SUBshiftLL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (SUB x0 x1:(SRLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (SUBshiftRL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRLconst { + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_0_0_1_0.AuxInt != 64 { break } - v.reset(OpARM64SUBshiftRL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - return false -} -func rewriteValueARM64_OpARM64SUB_10(v *Value) bool { - // match: (SUB x0 x1:(SRAconst [c] y)) - // cond: clobberIfDead(x1) - // result: (SUBshiftRA x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRAconst { + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_0_0_1_1.Type != t { break } - v.reset(OpARM64SUBshiftRA) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - return false -} -func rewriteValueARM64_OpARM64SUBconst_0(v *Value) bool { - // match: (SUBconst [0] x) - // cond: - // result: x - for { - if v.AuxInt != 0 { + if v_0_0_1_1.AuxInt != 63 { break } - x := v.Args[0] - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (SUBconst [c] (MOVDconst [d])) - // cond: - // result: (MOVDconst [d-c]) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + y := v_0_0_1_1.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64CMPconst { break } - d := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = d - c - return true - } - // match: (SUBconst [c] (SUBconst [d] x)) - // cond: - // result: (ADDconst [-c-d] x) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SUBconst { + if v_0_1.AuxInt != 64 { break } - d := v_0.AuxInt - x := v_0.Args[0] - v.reset(OpARM64ADDconst) - v.AuxInt = -c - d - v.AddArg(x) - return true - } - // match: (SUBconst [c] (ADDconst [d] x)) - // cond: - // result: (ADDconst [-c+d] x) - for { - c := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + v_0_1_0 := v_0_1.Args[0] + if v_0_1_0.Op != OpARM64SUB { break } - d := v_0.AuxInt - x := v_0.Args[0] - v.reset(OpARM64ADDconst) - v.AuxInt = -c + d - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64SUBshiftLL_0(v *Value) bool { - // match: (SUBshiftLL x (MOVDconst [c]) [d]) - // cond: - // result: (SUBconst x [int64(uint64(c)<>uint64(d)]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_1.Type != t { break } - c := v_1.AuxInt - v.reset(OpARM64SUBconst) - v.AuxInt = c >> uint64(d) + if v_1_1.AuxInt != 63 { + break + } + if y != v_1_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64ROR) v.AddArg(x) + v.AddArg(y) return true } - // match: (SUBshiftRA x (SRAconst x [c]) [d]) - // cond: c==d - // result: (MOVDconst [0]) + // match: (XOR (SLL x (ANDconst [31] y)) (CSEL0 {cc} (SRL (MOVWUreg x) (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x (NEG y)) for { - d := v.AuxInt _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRAconst { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLL { break } - c := v_1.AuxInt - if x != v_1.Args[0] { + _ = v_0.Args[1] + x := v_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { break } - if !(c == d) { + t := v_0_1.Type + if v_0_1.AuxInt != 31 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - return false -} -func rewriteValueARM64_OpARM64SUBshiftRL_0(v *Value) bool { - // match: (SUBshiftRL x (MOVDconst [c]) [d]) - // cond: - // result: (SUBconst x [int64(uint64(c)>>uint64(d))]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] + y := v_0_1.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64CSEL0 { break } - c := v_1.AuxInt - v.reset(OpARM64SUBconst) - v.AuxInt = int64(uint64(c) >> uint64(d)) - v.AddArg(x) - return true - } - // match: (SUBshiftRL x (SRLconst x [c]) [d]) - // cond: c==d - // result: (MOVDconst [0]) - for { - d := v.AuxInt - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + if v_1.Type != typ.UInt32 { break } - c := v_1.AuxInt - if x != v_1.Args[0] { + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SRL { break } - if !(c == d) { + if v_1_0.Type != typ.UInt32 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - return false -} -func rewriteValueARM64_OpARM64TST_0(v *Value) bool { - // match: (TST x (MOVDconst [c])) - // cond: - // result: (TSTconst [c] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_1_0.Args[1] + v_1_0_0 := v_1_0.Args[0] + if v_1_0_0.Op != OpARM64MOVWUreg { break } - c := v_1.AuxInt - v.reset(OpARM64TSTconst) - v.AuxInt = c - v.AddArg(x) - return true - } - // match: (TST (MOVDconst [c]) x) - // cond: - // result: (TSTconst [c] x) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if x != v_1_0_0.Args[0] { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64TSTconst) - v.AuxInt = c - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64TSTW_0(v *Value) bool { - // match: (TSTW x (MOVDconst [c])) - // cond: - // result: (TSTWconst [c] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_1_0_1 := v_1_0.Args[1] + if v_1_0_1.Op != OpARM64SUB { break } - c := v_1.AuxInt - v.reset(OpARM64TSTWconst) - v.AuxInt = c + if v_1_0_1.Type != t { + break + } + _ = v_1_0_1.Args[1] + v_1_0_1_0 := v_1_0_1.Args[0] + if v_1_0_1_0.Op != OpARM64MOVDconst { + break + } + if v_1_0_1_0.AuxInt != 32 { + break + } + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { + break + } + if v_1_0_1_1.Type != t { + break + } + if v_1_0_1_1.AuxInt != 31 { + break + } + if y != v_1_0_1_1.Args[0] { + break + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64CMPconst { + break + } + if v_1_1.AuxInt != 64 { + break + } + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { + break + } + if v_1_1_0.Type != t { + break + } + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { + break + } + if v_1_1_0_0.AuxInt != 32 { + break + } + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { + break + } + if v_1_1_0_1.Type != t { + break + } + if v_1_1_0_1.AuxInt != 31 { + break + } + if y != v_1_1_0_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64RORW) v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, t) + v0.AddArg(y) + v.AddArg(v0) return true } - // match: (TSTW (MOVDconst [c]) x) - // cond: - // result: (TSTWconst [c] x) + // match: (XOR (CSEL0 {cc} (SRL (MOVWUreg x) (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y)))) (SLL x (ANDconst [31] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x (NEG y)) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64CSEL0 { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64TSTWconst) - v.AuxInt = c - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64TSTWconst_0(v *Value) bool { - // match: (TSTWconst (MOVDconst [x]) [y]) - // cond: int32(x&y)==0 - // result: (FlagEQ) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Type != typ.UInt32 { break } - x := v_0.AuxInt - if !(int32(x&y) == 0) { + cc := v_0.Aux + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SRL { break } - v.reset(OpARM64FlagEQ) - return true - } - // match: (TSTWconst (MOVDconst [x]) [y]) - // cond: int32(x&y)<0 - // result: (FlagLT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_0.Type != typ.UInt32 { break } - x := v_0.AuxInt - if !(int32(x&y) < 0) { + _ = v_0_0.Args[1] + v_0_0_0 := v_0_0.Args[0] + if v_0_0_0.Op != OpARM64MOVWUreg { break } - v.reset(OpARM64FlagLT_UGT) - return true - } - // match: (TSTWconst (MOVDconst [x]) [y]) - // cond: int32(x&y)>0 - // result: (FlagGT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + x := v_0_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { break } - x := v_0.AuxInt - if !(int32(x&y) > 0) { + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64FlagGT_UGT) - return true - } - return false -} -func rewriteValueARM64_OpARM64TSTconst_0(v *Value) bool { - // match: (TSTconst (MOVDconst [x]) [y]) - // cond: int64(x&y)==0 - // result: (FlagEQ) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_0_1_0.AuxInt != 32 { break } - x := v_0.AuxInt - if !(int64(x&y) == 0) { + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64FlagEQ) - return true - } - // match: (TSTconst (MOVDconst [x]) [y]) - // cond: int64(x&y)<0 - // result: (FlagLT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_0_1_1.Type != t { + break + } + if v_0_0_1_1.AuxInt != 31 { + break + } + y := v_0_0_1_1.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64CMPconst { + break + } + if v_0_1.AuxInt != 64 { + break + } + v_0_1_0 := v_0_1.Args[0] + if v_0_1_0.Op != OpARM64SUB { + break + } + if v_0_1_0.Type != t { + break + } + _ = v_0_1_0.Args[1] + v_0_1_0_0 := v_0_1_0.Args[0] + if v_0_1_0_0.Op != OpARM64MOVDconst { + break + } + if v_0_1_0_0.AuxInt != 32 { break } - x := v_0.AuxInt - if !(int64(x&y) < 0) { + v_0_1_0_1 := v_0_1_0.Args[1] + if v_0_1_0_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64FlagLT_UGT) - return true - } - // match: (TSTconst (MOVDconst [x]) [y]) - // cond: int64(x&y)>0 - // result: (FlagGT_UGT) - for { - y := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0_1_0_1.Type != t { break } - x := v_0.AuxInt - if !(int64(x&y) > 0) { + if v_0_1_0_1.AuxInt != 31 { break } - v.reset(OpARM64FlagGT_UGT) - return true - } - return false -} -func rewriteValueARM64_OpARM64UBFIZ_0(v *Value) bool { - // match: (UBFIZ [bfc] (SLLconst [sc] x)) - // cond: sc < getARM64BFwidth(bfc) - // result: (UBFIZ [arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)-sc)] x) - for { - bfc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if y != v_0_1_0_1.Args[0] { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(sc < getARM64BFwidth(bfc)) { + v_1 := v.Args[1] + if v_1.Op != OpARM64SLL { break } - v.reset(OpARM64UBFIZ) - v.AuxInt = arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)-sc) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64UBFX_0(v *Value) bool { - // match: (UBFX [bfc] (SRLconst [sc] x)) - // cond: sc+getARM64BFwidth(bfc)+getARM64BFlsb(bfc) < 64 - // result: (UBFX [arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc))] x) - for { - bfc := v.AuxInt - v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { + _ = v_1.Args[1] + if x != v_1.Args[0] { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(sc+getARM64BFwidth(bfc)+getARM64BFlsb(bfc) < 64) { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(getARM64BFlsb(bfc)+sc, getARM64BFwidth(bfc)) - v.AddArg(x) - return true - } - // match: (UBFX [bfc] (SLLconst [sc] x)) - // cond: sc == getARM64BFlsb(bfc) - // result: (ANDconst [1< getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc) - // result: (UBFIZ [arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc)] x) + // match: (XOR (SRL (MOVWUreg x) (ANDconst [31] y)) (CSEL0 {cc} (SLL x (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y))))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x y) for { - bfc := v.AuxInt + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_0.Op != OpARM64SRL { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(sc > getARM64BFlsb(bfc) && sc < getARM64BFlsb(bfc)+getARM64BFwidth(bfc)) { + if v_0.Type != typ.UInt32 { break } - v.reset(OpARM64UBFIZ) - v.AuxInt = arm64BFAuxInt(sc-getARM64BFlsb(bfc), getARM64BFlsb(bfc)+getARM64BFwidth(bfc)-sc) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64UDIV_0(v *Value) bool { - // match: (UDIV x (MOVDconst [1])) - // cond: - // result: x - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64MOVWUreg { break } - if v_1.AuxInt != 1 { + x := v_0_0.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64ANDconst { break } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (UDIV x (MOVDconst [c])) - // cond: isPowerOfTwo(c) - // result: (SRLconst [log2(c)] x) - for { - _ = v.Args[1] - x := v.Args[0] + t := v_0_1.Type + if v_0_1.AuxInt != 31 { + break + } + y := v_0_1.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1.Op != OpARM64CSEL0 { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c)) { + if v_1.Type != typ.UInt32 { break } - v.reset(OpARM64SRLconst) - v.AuxInt = log2(c) - v.AddArg(x) - return true - } - // match: (UDIV (MOVDconst [c]) (MOVDconst [d])) - // cond: - // result: (MOVDconst [int64(uint64(c)/uint64(d))]) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + cc := v_1.Aux + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64SLL { break } - c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_1_0.Args[1] + if x != v_1_0.Args[0] { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(uint64(c) / uint64(d)) - return true - } - return false -} -func rewriteValueARM64_OpARM64UDIVW_0(v *Value) bool { - // match: (UDIVW x (MOVDconst [c])) - // cond: uint32(c)==1 - // result: x - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_1_0_1 := v_1_0.Args[1] + if v_1_0_1.Op != OpARM64SUB { break } - c := v_1.AuxInt - if !(uint32(c) == 1) { + if v_1_0_1.Type != t { break } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (UDIVW x (MOVDconst [c])) - // cond: isPowerOfTwo(c) && is32Bit(c) - // result: (SRLconst [log2(c)] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_1_0_1.Args[1] + v_1_0_1_0 := v_1_0_1.Args[0] + if v_1_0_1_0.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c) && is32Bit(c)) { + if v_1_0_1_0.AuxInt != 32 { break } - v.reset(OpARM64SRLconst) - v.AuxInt = log2(c) - v.AddArg(x) - return true - } - // match: (UDIVW (MOVDconst [c]) (MOVDconst [d])) - // cond: - // result: (MOVDconst [int64(uint32(c)/uint32(d))]) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_0_1_1 := v_1_0_1.Args[1] + if v_1_0_1_1.Op != OpARM64ANDconst { break } - c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_0_1_1.Type != t { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(uint32(c) / uint32(d)) - return true - } - return false -} -func rewriteValueARM64_OpARM64UMOD_0(v *Value) bool { - // match: (UMOD _ (MOVDconst [1])) - // cond: - // result: (MOVDconst [0]) - for { - _ = v.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_0_1_1.AuxInt != 31 { break } - if v_1.AuxInt != 1 { + if y != v_1_0_1_1.Args[0] { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (UMOD x (MOVDconst [c])) - // cond: isPowerOfTwo(c) - // result: (ANDconst [c-1] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64CMPconst { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c)) { + if v_1_1.AuxInt != 64 { break } - v.reset(OpARM64ANDconst) - v.AuxInt = c - 1 - v.AddArg(x) - return true - } - // match: (UMOD (MOVDconst [c]) (MOVDconst [d])) - // cond: - // result: (MOVDconst [int64(uint64(c)%uint64(d))]) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + v_1_1_0 := v_1_1.Args[0] + if v_1_1_0.Op != OpARM64SUB { break } - c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_1_0.Type != t { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(uint64(c) % uint64(d)) - return true - } - return false -} -func rewriteValueARM64_OpARM64UMODW_0(v *Value) bool { - // match: (UMODW _ (MOVDconst [c])) - // cond: uint32(c)==1 - // result: (MOVDconst [0]) - for { - _ = v.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v_1_1_0.Args[1] + v_1_1_0_0 := v_1_1_0.Args[0] + if v_1_1_0_0.Op != OpARM64MOVDconst { + break + } + if v_1_1_0_0.AuxInt != 32 { break } - c := v_1.AuxInt - if !(uint32(c) == 1) { + v_1_1_0_1 := v_1_1_0.Args[1] + if v_1_1_0_1.Op != OpARM64ANDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (UMODW x (MOVDconst [c])) - // cond: isPowerOfTwo(c) && is32Bit(c) - // result: (ANDconst [c-1] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_1_1_0_1.Type != t { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c) && is32Bit(c)) { + if v_1_1_0_1.AuxInt != 31 { break } - v.reset(OpARM64ANDconst) - v.AuxInt = c - 1 + if y != v_1_1_0_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64RORW) v.AddArg(x) + v.AddArg(y) return true } - // match: (UMODW (MOVDconst [c]) (MOVDconst [d])) - // cond: - // result: (MOVDconst [int64(uint32(c)%uint32(d))]) + // match: (XOR (CSEL0 {cc} (SLL x (SUB (MOVDconst [32]) (ANDconst [31] y))) (CMPconst [64] (SUB (MOVDconst [32]) (ANDconst [31] y)))) (SRL (MOVWUreg x) (ANDconst [31] y))) + // cond: cc.(Op) == OpARM64LessThanU + // result: (RORW x y) for { _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if v_0.Op != OpARM64CSEL0 { break } - c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0.Type != typ.UInt32 { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(uint32(c) % uint32(d)) - return true - } - return false -} -func rewriteValueARM64_OpARM64XOR_0(v *Value) bool { - // match: (XOR x (MOVDconst [c])) - // cond: - // result: (XORconst [c] x) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + cc := v_0.Aux + _ = v_0.Args[1] + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpARM64SLL { break } - c := v_1.AuxInt - v.reset(OpARM64XORconst) - v.AuxInt = c - v.AddArg(x) - return true - } - // match: (XOR (MOVDconst [c]) x) - // cond: - // result: (XORconst [c] x) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v_0_0.Args[1] + x := v_0_0.Args[0] + v_0_0_1 := v_0_0.Args[1] + if v_0_0_1.Op != OpARM64SUB { break } - c := v_0.AuxInt - x := v.Args[1] - v.reset(OpARM64XORconst) - v.AuxInt = c - v.AddArg(x) - return true - } - // match: (XOR x x) - // cond: - // result: (MOVDconst [0]) - for { - _ = v.Args[1] - x := v.Args[0] - if x != v.Args[1] { + t := v_0_0_1.Type + _ = v_0_0_1.Args[1] + v_0_0_1_0 := v_0_0_1.Args[0] + if v_0_0_1_0.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - // match: (XOR x (MVN y)) - // cond: - // result: (EON x y) - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MVN { + if v_0_0_1_0.AuxInt != 32 { break } - y := v_1.Args[0] - v.reset(OpARM64EON) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (XOR (MVN y) x) - // cond: - // result: (EON x y) - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MVN { + v_0_0_1_1 := v_0_0_1.Args[1] + if v_0_0_1_1.Op != OpARM64ANDconst { break } - y := v_0.Args[0] - x := v.Args[1] - v.reset(OpARM64EON) - v.AddArg(x) - v.AddArg(y) - return true - } - // match: (XOR x0 x1:(SLLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (XORshiftLL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SLLconst { + if v_0_0_1_1.Type != t { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_0_0_1_1.AuxInt != 31 { break } - v.reset(OpARM64XORshiftLL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (XOR x1:(SLLconst [c] y) x0) - // cond: clobberIfDead(x1) - // result: (XORshiftLL x0 y [c]) - for { - _ = v.Args[1] - x1 := v.Args[0] - if x1.Op != OpARM64SLLconst { + y := v_0_0_1_1.Args[0] + v_0_1 := v_0.Args[1] + if v_0_1.Op != OpARM64CMPconst { break } - c := x1.AuxInt - y := x1.Args[0] - x0 := v.Args[1] - if !(clobberIfDead(x1)) { + if v_0_1.AuxInt != 64 { break } - v.reset(OpARM64XORshiftLL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (XOR x0 x1:(SRLconst [c] y)) - // cond: clobberIfDead(x1) - // result: (XORshiftRL x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRLconst { + v_0_1_0 := v_0_1.Args[0] + if v_0_1_0.Op != OpARM64SUB { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_0_1_0.Type != t { break } - v.reset(OpARM64XORshiftRL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (XOR x1:(SRLconst [c] y) x0) - // cond: clobberIfDead(x1) - // result: (XORshiftRL x0 y [c]) - for { - _ = v.Args[1] - x1 := v.Args[0] - if x1.Op != OpARM64SRLconst { + _ = v_0_1_0.Args[1] + v_0_1_0_0 := v_0_1_0.Args[0] + if v_0_1_0_0.Op != OpARM64MOVDconst { break } - c := x1.AuxInt - y := x1.Args[0] - x0 := v.Args[1] - if !(clobberIfDead(x1)) { + if v_0_1_0_0.AuxInt != 32 { break } - v.reset(OpARM64XORshiftRL) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - // match: (XOR x0 x1:(SRAconst [c] y)) - // cond: clobberIfDead(x1) - // result: (XORshiftRA x0 y [c]) - for { - _ = v.Args[1] - x0 := v.Args[0] - x1 := v.Args[1] - if x1.Op != OpARM64SRAconst { + v_0_1_0_1 := v_0_1_0.Args[1] + if v_0_1_0_1.Op != OpARM64ANDconst { break } - c := x1.AuxInt - y := x1.Args[0] - if !(clobberIfDead(x1)) { + if v_0_1_0_1.Type != t { break } - v.reset(OpARM64XORshiftRA) - v.AuxInt = c - v.AddArg(x0) - v.AddArg(y) - return true - } - return false -} -func rewriteValueARM64_OpARM64XOR_10(v *Value) bool { - // match: (XOR x1:(SRAconst [c] y) x0) - // cond: clobberIfDead(x1) - // result: (XORshiftRA x0 y [c]) - for { - _ = v.Args[1] - x1 := v.Args[0] - if x1.Op != OpARM64SRAconst { + if v_0_1_0_1.AuxInt != 31 { break } - c := x1.AuxInt - y := x1.Args[0] - x0 := v.Args[1] - if !(clobberIfDead(x1)) { + if y != v_0_1_0_1.Args[0] { break } - v.reset(OpARM64XORshiftRA) - v.AuxInt = c - v.AddArg(x0) + v_1 := v.Args[1] + if v_1.Op != OpARM64SRL { + break + } + if v_1.Type != typ.UInt32 { + break + } + _ = v_1.Args[1] + v_1_0 := v_1.Args[0] + if v_1_0.Op != OpARM64MOVWUreg { + break + } + if x != v_1_0.Args[0] { + break + } + v_1_1 := v_1.Args[1] + if v_1_1.Op != OpARM64ANDconst { + break + } + if v_1_1.Type != t { + break + } + if v_1_1.AuxInt != 31 { + break + } + if y != v_1_1.Args[0] { + break + } + if !(cc.(Op) == OpARM64LessThanU) { + break + } + v.reset(OpARM64RORW) + v.AddArg(x) v.AddArg(y) return true } @@ -30534,6 +33338,42 @@ func rewriteValueARM64_OpPopCount64_0(v *Value) bool { return true } } +func rewriteValueARM64_OpRotateLeft32_0(v *Value) bool { + b := v.Block + _ = b + // match: (RotateLeft32 x y) + // cond: + // result: (RORW x (NEG y)) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + v.reset(OpARM64RORW) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, y.Type) + v0.AddArg(y) + v.AddArg(v0) + return true + } +} +func rewriteValueARM64_OpRotateLeft64_0(v *Value) bool { + b := v.Block + _ = b + // match: (RotateLeft64 x y) + // cond: + // result: (ROR x (NEG y)) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + v.reset(OpARM64ROR) + v.AddArg(x) + v0 := b.NewValue0(v.Pos, OpARM64NEG, y.Type) + v0.AddArg(y) + v.AddArg(v0) + return true + } +} func rewriteValueARM64_OpRound_0(v *Value) bool { // match: (Round x) // cond: diff --git a/test/codegen/mathbits.go b/test/codegen/mathbits.go index b8844c518f1a0..28354ed65175c 100644 --- a/test/codegen/mathbits.go +++ b/test/codegen/mathbits.go @@ -195,6 +195,7 @@ func RotateLeft8(n uint8) uint8 { func RotateLeftVariable(n uint, m int) uint { // amd64:"ROLQ" + // arm64:"ROR" // ppc64:"ROTL" // s390x:"RLLG" return bits.RotateLeft(n, m) @@ -202,6 +203,7 @@ func RotateLeftVariable(n uint, m int) uint { func RotateLeftVariable64(n uint64, m int) uint64 { // amd64:"ROLQ" + // arm64:"ROR" // ppc64:"ROTL" // s390x:"RLLG" return bits.RotateLeft64(n, m) @@ -209,6 +211,7 @@ func RotateLeftVariable64(n uint64, m int) uint64 { func RotateLeftVariable32(n uint32, m int) uint32 { // amd64:"ROLL" + // arm64:"RORW" // ppc64:"ROTLW" // s390x:"RLL" return bits.RotateLeft32(n, m) From 42257a262c94d839364113f2dbf4057731971fc1 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Wed, 5 Sep 2018 14:36:20 -0700 Subject: [PATCH 0327/1663] runtime: in semasleep, subtract time spent so far from timeout When pthread_cond_timedwait_relative_np gets a spurious wakeup (due to a signal, typically), we used to retry with the same relative timeout. That's incorrect, we should lower the timeout by the time we've spent in this function so far. In the worst case, signals come in and cause spurious wakeups faster than the timeout, causing semasleep to never time out. Also fix nacl and netbsd while we're here. They have similar issues. Fixes #27520 Change-Id: I6601e120e44a4b8ef436eef75a1e7c8cf1d39e39 Reviewed-on: https://go-review.googlesource.com/133655 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/os_darwin.go | 11 ++++++++++- src/runtime/os_nacl.go | 12 ++++++------ src/runtime/os_netbsd.go | 31 ++++++++++++++----------------- 3 files changed, 30 insertions(+), 24 deletions(-) diff --git a/src/runtime/os_darwin.go b/src/runtime/os_darwin.go index d2144edf2ebdf..26b02820cd32c 100644 --- a/src/runtime/os_darwin.go +++ b/src/runtime/os_darwin.go @@ -34,6 +34,10 @@ func semacreate(mp *m) { //go:nosplit func semasleep(ns int64) int32 { + var start int64 + if ns >= 0 { + start = nanotime() + } mp := getg().m pthread_mutex_lock(&mp.mutex) for { @@ -43,8 +47,13 @@ func semasleep(ns int64) int32 { return 0 } if ns >= 0 { + spent := nanotime() - start + if spent >= ns { + pthread_mutex_unlock(&mp.mutex) + return -1 + } var t timespec - t.set_nsec(ns) + t.set_nsec(ns - spent) err := pthread_cond_timedwait_relative_np(&mp.cond, &mp.mutex, &t) if err == _ETIMEDOUT { pthread_mutex_unlock(&mp.mutex) diff --git a/src/runtime/os_nacl.go b/src/runtime/os_nacl.go index 23ab03b953e96..ac7bf69582533 100644 --- a/src/runtime/os_nacl.go +++ b/src/runtime/os_nacl.go @@ -197,23 +197,23 @@ func semacreate(mp *m) { //go:nosplit func semasleep(ns int64) int32 { var ret int32 - systemstack(func() { _g_ := getg() if nacl_mutex_lock(_g_.m.waitsemalock) < 0 { throw("semasleep") } - + var ts timespec + if ns >= 0 { + end := ns + nanotime() + ts.tv_sec = end / 1e9 + ts.tv_nsec = int32(end % 1e9) + } for _g_.m.waitsemacount == 0 { if ns < 0 { if nacl_cond_wait(_g_.m.waitsema, _g_.m.waitsemalock) < 0 { throw("semasleep") } } else { - var ts timespec - end := ns + nanotime() - ts.tv_sec = end / 1e9 - ts.tv_nsec = int32(end % 1e9) r := nacl_cond_timed_wait_abs(_g_.m.waitsema, _g_.m.waitsemalock, &ts) if r == -_ETIMEDOUT { nacl_mutex_unlock(_g_.m.waitsemalock) diff --git a/src/runtime/os_netbsd.go b/src/runtime/os_netbsd.go index a9bf407a36388..7deab3ed03569 100644 --- a/src/runtime/os_netbsd.go +++ b/src/runtime/os_netbsd.go @@ -126,15 +126,9 @@ func semacreate(mp *m) { //go:nosplit func semasleep(ns int64) int32 { _g_ := getg() - - // Compute sleep deadline. - var tsp *timespec - var ts timespec + var deadline int64 if ns >= 0 { - var nsec int32 - ts.set_sec(timediv(ns, 1000000000, &nsec)) - ts.set_nsec(nsec) - tsp = &ts + deadline = nanotime() + ns } for { @@ -147,18 +141,21 @@ func semasleep(ns int64) int32 { } // Sleep until unparked by semawakeup or timeout. + var tsp *timespec + var ts timespec + if ns >= 0 { + wait := deadline - nanotime() + if wait <= 0 { + return -1 + } + var nsec int32 + ts.set_sec(timediv(wait, 1000000000, &nsec)) + ts.set_nsec(nsec) + tsp = &ts + } ret := lwp_park(_CLOCK_MONOTONIC, _TIMER_RELTIME, tsp, 0, unsafe.Pointer(&_g_.m.waitsemacount), nil) if ret == _ETIMEDOUT { return -1 - } else if ret == _EINTR && ns >= 0 { - // Avoid sleeping forever if we keep getting - // interrupted (for example by the profiling - // timer). It would be if tsp upon return had the - // remaining time to sleep, but this is good enough. - var nsec int32 - ns /= 2 - ts.set_sec(timediv(ns, 1000000000, &nsec)) - ts.set_nsec(nsec) } } } From 7a0eb56466eb26704fad49caec228ba21831761e Mon Sep 17 00:00:00 2001 From: Filippo Valsorda Date: Fri, 7 Sep 2018 12:58:14 -0400 Subject: [PATCH 0328/1663] crypto/x509: allow ":" in Common Name hostnames At least one popular service puts a hostname which contains a ":" in the Common Name field. On the other hand, I don't know of any name constrained certificates that only work if we ignore such CNs. Updates #24151 Change-Id: I2d813e3e522ebd65ab5ea5cd83390467a869eea3 Reviewed-on: https://go-review.googlesource.com/134076 Run-TryBot: Filippo Valsorda Reviewed-by: Adam Langley TryBot-Result: Gobot Gobot --- src/crypto/x509/verify.go | 4 ++-- src/crypto/x509/verify_test.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/crypto/x509/verify.go b/src/crypto/x509/verify.go index 4c2ff7b7c4d3d..91be7c05f9a24 100644 --- a/src/crypto/x509/verify.go +++ b/src/crypto/x509/verify.go @@ -894,8 +894,8 @@ func validHostname(host string) bool { if c == '-' && j != 0 { continue } - if c == '_' { - // _ is not a valid character in hostnames, but it's commonly + if c == '_' || c == ':' { + // Not valid characters in hostnames, but commonly // found in deployments outside the WebPKI. continue } diff --git a/src/crypto/x509/verify_test.go b/src/crypto/x509/verify_test.go index 768414583962f..0e24d3b5da3af 100644 --- a/src/crypto/x509/verify_test.go +++ b/src/crypto/x509/verify_test.go @@ -1881,6 +1881,7 @@ func TestValidHostname(t *testing.T) { {"foo.*.example.com", false}, {"exa_mple.com", true}, {"foo,bar", false}, + {"project-dev:us-central1:main", true}, } for _, tt := range tests { if got := validHostname(tt.host); got != tt.want { From b7f9c640b7d4d1ba721dc158a12df0a2d2d69a2f Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Fri, 7 Sep 2018 20:36:56 +0300 Subject: [PATCH 0329/1663] test: extend noescape bytes.Buffer test suite Added some more cases that should be guarded against regression. Change-Id: I9f1dda2fd0be9b6e167ef1cc018fc8cce55c066c Reviewed-on: https://go-review.googlesource.com/134017 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- test/fixedbugs/issue7921.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/fixedbugs/issue7921.go b/test/fixedbugs/issue7921.go index d32221a209d3b..e30e556353b2e 100644 --- a/test/fixedbugs/issue7921.go +++ b/test/fixedbugs/issue7921.go @@ -37,3 +37,20 @@ func bufferNoEscape3(xs []string) string { // ERROR "xs does not escape" } return b.String() // ERROR "inlining call" "string\(bytes.b.buf\[bytes\.b\.off:\]\) escapes to heap" } + +func bufferNoEscape4() []byte { + var b bytes.Buffer + b.Grow(64) // ERROR "b does not escape" + useBuffer(&b) // ERROR "&b does not escape" + return b.Bytes() // ERROR "inlining call" "b does not escape" +} + +func bufferNoEscape5() { + b := bytes.NewBuffer(make([]byte, 0, 128)) // ERROR "inlining call" "make\(\[\]byte, 0, 128\) does not escape" "&bytes.Buffer literal does not escape" + useBuffer(b) +} + +//go:noinline +func useBuffer(b *bytes.Buffer) { // ERROR "b does not escape" + b.WriteString("1234") +} From ceb7745cc846f798531ef019162dd9f1dabfea12 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 7 Sep 2018 04:12:42 -0700 Subject: [PATCH 0330/1663] cmd/go: add -Wl,--export-dynamic to linker flag whitelist Fixes #27496 Change-Id: I53538c7697729294a9e50ace26a6a7183131e837 Reviewed-on: https://go-review.googlesource.com/134016 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Andrew Bonventre --- src/cmd/go/internal/work/security.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cmd/go/internal/work/security.go b/src/cmd/go/internal/work/security.go index d5d126123a4b0..2132c5f3e15f4 100644 --- a/src/cmd/go/internal/work/security.go +++ b/src/cmd/go/internal/work/security.go @@ -170,6 +170,7 @@ var validLinkerFlags = []*regexp.Regexp{ re(`-Wl,-e[=,][a-zA-Z0-9]*`), re(`-Wl,--enable-new-dtags`), re(`-Wl,--end-group`), + re(`-Wl,--(no-)?export-dynamic`), re(`-Wl,-framework,[^,@\-][^,]+`), re(`-Wl,-headerpad_max_install_names`), re(`-Wl,--no-undefined`), From 43f54c8d2e3bddfc6ad7887286eb6564986cb6ad Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Thu, 6 Sep 2018 17:21:59 -0700 Subject: [PATCH 0331/1663] runtime: use tgkill for raise raise uses tkill to send a signal to the current thread. For this use, tgkill is functionally equivalent to tkill expect that it also takes the pid as the first argument. Using tgkill makes it simpler to run a Go program in a strict sandbox. With kill and tgkill, the sandbox policy (e.g., seccomp) can prevent the program from sending signals to other processes by checking that the first argument == getpid(). With tkill, the policy must whitelist all tids in the process, which is effectively impossible given Go's dynamic thread creation. Fixes #27548 Change-Id: I8ed282ef1f7215b02ef46de144493e36454029ea Reviewed-on: https://go-review.googlesource.com/133975 Run-TryBot: Michael Pratt TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/sys_linux_386.s | 11 +++++++---- src/runtime/sys_linux_amd64.s | 12 ++++++++---- src/runtime/sys_linux_arm.s | 12 ++++++++---- src/runtime/sys_linux_arm64.s | 12 ++++++++---- src/runtime/sys_linux_mips64x.s | 12 ++++++++---- src/runtime/sys_linux_mipsx.s | 12 ++++++++---- src/runtime/sys_linux_ppc64x.s | 11 +++++++---- src/runtime/sys_linux_s390x.s | 12 ++++++++---- 8 files changed, 62 insertions(+), 32 deletions(-) diff --git a/src/runtime/sys_linux_386.s b/src/runtime/sys_linux_386.s index 8d5a4ff9772d2..4e914f3e6013d 100644 --- a/src/runtime/sys_linux_386.s +++ b/src/runtime/sys_linux_386.s @@ -48,7 +48,6 @@ #define SYS_mincore 218 #define SYS_madvise 219 #define SYS_gettid 224 -#define SYS_tkill 238 #define SYS_futex 240 #define SYS_sched_getaffinity 242 #define SYS_set_thread_area 243 @@ -57,6 +56,7 @@ #define SYS_epoll_ctl 255 #define SYS_epoll_wait 256 #define SYS_clock_gettime 265 +#define SYS_tgkill 270 #define SYS_epoll_create1 329 TEXT runtime·exit(SB),NOSPLIT,$0 @@ -155,11 +155,14 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4 RET TEXT runtime·raise(SB),NOSPLIT,$12 + MOVL $SYS_getpid, AX + INVOKE_SYSCALL + MOVL AX, BX // arg 1 pid MOVL $SYS_gettid, AX INVOKE_SYSCALL - MOVL AX, BX // arg 1 tid - MOVL sig+0(FP), CX // arg 2 signal - MOVL $SYS_tkill, AX + MOVL AX, CX // arg 2 tid + MOVL sig+0(FP), DX // arg 3 signal + MOVL $SYS_tgkill, AX INVOKE_SYSCALL RET diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s index 62d80247bea52..4492dad02e7a6 100644 --- a/src/runtime/sys_linux_amd64.s +++ b/src/runtime/sys_linux_amd64.s @@ -36,12 +36,12 @@ #define SYS_sigaltstack 131 #define SYS_arch_prctl 158 #define SYS_gettid 186 -#define SYS_tkill 200 #define SYS_futex 202 #define SYS_sched_getaffinity 204 #define SYS_epoll_create 213 #define SYS_exit_group 231 #define SYS_epoll_ctl 233 +#define SYS_tgkill 234 #define SYS_openat 257 #define SYS_faccessat 269 #define SYS_epoll_pwait 281 @@ -137,11 +137,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4 RET TEXT runtime·raise(SB),NOSPLIT,$0 + MOVL $SYS_getpid, AX + SYSCALL + MOVL AX, R12 MOVL $SYS_gettid, AX SYSCALL - MOVL AX, DI // arg 1 tid - MOVL sig+0(FP), SI // arg 2 - MOVL $SYS_tkill, AX + MOVL AX, SI // arg 2 tid + MOVL R12, DI // arg 1 pid + MOVL sig+0(FP), DX // arg 3 + MOVL $SYS_tgkill, AX SYSCALL RET diff --git a/src/runtime/sys_linux_arm.s b/src/runtime/sys_linux_arm.s index aa39732cfb66d..a709c4cbd050b 100644 --- a/src/runtime/sys_linux_arm.s +++ b/src/runtime/sys_linux_arm.s @@ -36,7 +36,7 @@ #define SYS_setitimer (SYS_BASE + 104) #define SYS_mincore (SYS_BASE + 219) #define SYS_gettid (SYS_BASE + 224) -#define SYS_tkill (SYS_BASE + 238) +#define SYS_tgkill (SYS_BASE + 268) #define SYS_sched_yield (SYS_BASE + 158) #define SYS_nanosleep (SYS_BASE + 162) #define SYS_sched_getaffinity (SYS_BASE + 242) @@ -138,11 +138,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4 RET TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0 + MOVW $SYS_getpid, R7 + SWI $0 + MOVW R0, R4 MOVW $SYS_gettid, R7 SWI $0 - // arg 1 tid already in R0 from gettid - MOVW sig+0(FP), R1 // arg 2 - signal - MOVW $SYS_tkill, R7 + MOVW R0, R1 // arg 2 tid + MOVW R4, R0 // arg 1 pid + MOVW sig+0(FP), R2 // arg 3 + MOVW $SYS_tgkill, R7 SWI $0 RET diff --git a/src/runtime/sys_linux_arm64.s b/src/runtime/sys_linux_arm64.s index 1c8fce3db649b..086c8ddc637fe 100644 --- a/src/runtime/sys_linux_arm64.s +++ b/src/runtime/sys_linux_arm64.s @@ -36,7 +36,7 @@ #define SYS_getpid 172 #define SYS_gettid 178 #define SYS_kill 129 -#define SYS_tkill 130 +#define SYS_tgkill 131 #define SYS_futex 98 #define SYS_sched_getaffinity 123 #define SYS_exit_group 94 @@ -143,11 +143,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4 RET TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0 + MOVD $SYS_getpid, R8 + SVC + MOVW R0, R19 MOVD $SYS_gettid, R8 SVC - MOVW R0, R0 // arg 1 tid - MOVW sig+0(FP), R1 // arg 2 - MOVD $SYS_tkill, R8 + MOVW R0, R1 // arg 2 tid + MOVW R19, R0 // arg 1 pid + MOVW sig+0(FP), R2 // arg 3 + MOVD $SYS_tgkill, R8 SVC RET diff --git a/src/runtime/sys_linux_mips64x.s b/src/runtime/sys_linux_mips64x.s index 8e64f1c562e64..337299ba5fe08 100644 --- a/src/runtime/sys_linux_mips64x.s +++ b/src/runtime/sys_linux_mips64x.s @@ -35,12 +35,12 @@ #define SYS_madvise 5027 #define SYS_mincore 5026 #define SYS_gettid 5178 -#define SYS_tkill 5192 #define SYS_futex 5194 #define SYS_sched_getaffinity 5196 #define SYS_exit_group 5205 #define SYS_epoll_create 5207 #define SYS_epoll_ctl 5208 +#define SYS_tgkill 5225 #define SYS_openat 5247 #define SYS_epoll_pwait 5272 #define SYS_clock_gettime 5222 @@ -137,11 +137,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4 RET TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0 + MOVV $SYS_getpid, R2 + SYSCALL + MOVW R2, R16 MOVV $SYS_gettid, R2 SYSCALL - MOVW R2, R4 // arg 1 tid - MOVW sig+0(FP), R5 // arg 2 - MOVV $SYS_tkill, R2 + MOVW R2, R5 // arg 2 tid + MOVW R16, R4 // arg 1 pid + MOVW sig+0(FP), R6 // arg 3 + MOVV $SYS_tgkill, R2 SYSCALL RET diff --git a/src/runtime/sys_linux_mipsx.s b/src/runtime/sys_linux_mipsx.s index a6bca3bebd8b0..dca5f1ee459a8 100644 --- a/src/runtime/sys_linux_mipsx.s +++ b/src/runtime/sys_linux_mipsx.s @@ -35,7 +35,6 @@ #define SYS_madvise 4218 #define SYS_mincore 4217 #define SYS_gettid 4222 -#define SYS_tkill 4236 #define SYS_futex 4238 #define SYS_sched_getaffinity 4240 #define SYS_exit_group 4246 @@ -43,6 +42,7 @@ #define SYS_epoll_ctl 4249 #define SYS_epoll_wait 4250 #define SYS_clock_gettime 4263 +#define SYS_tgkill 4266 #define SYS_epoll_create1 4326 TEXT runtime·exit(SB),NOSPLIT,$0-4 @@ -135,11 +135,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4 RET TEXT runtime·raise(SB),NOSPLIT,$0-4 + MOVW $SYS_getpid, R2 + SYSCALL + MOVW R2, R16 MOVW $SYS_gettid, R2 SYSCALL - MOVW R2, R4 // arg 1 tid - MOVW sig+0(FP), R5 // arg 2 - MOVW $SYS_tkill, R2 + MOVW R2, R5 // arg 2 tid + MOVW R16, R4 // arg 1 pid + MOVW sig+0(FP), R6 // arg 3 + MOVW $SYS_tgkill, R2 SYSCALL RET diff --git a/src/runtime/sys_linux_ppc64x.s b/src/runtime/sys_linux_ppc64x.s index 075adf2368439..7c2f8ea637176 100644 --- a/src/runtime/sys_linux_ppc64x.s +++ b/src/runtime/sys_linux_ppc64x.s @@ -36,7 +36,6 @@ #define SYS_madvise 205 #define SYS_mincore 206 #define SYS_gettid 207 -#define SYS_tkill 208 #define SYS_futex 221 #define SYS_sched_getaffinity 223 #define SYS_exit_group 234 @@ -44,6 +43,7 @@ #define SYS_epoll_ctl 237 #define SYS_epoll_wait 238 #define SYS_clock_gettime 246 +#define SYS_tgkill 250 #define SYS_epoll_create1 315 TEXT runtime·exit(SB),NOSPLIT|NOFRAME,$0-4 @@ -123,10 +123,13 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4 RET TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0 + SYSCALL $SYS_getpid + MOVW R3, R14 SYSCALL $SYS_gettid - MOVW R3, R3 // arg 1 tid - MOVW sig+0(FP), R4 // arg 2 - SYSCALL $SYS_tkill + MOVW R3, R4 // arg 2 tid + MOVW R14, R3 // arg 1 pid + MOVW sig+0(FP), R5 // arg 3 + SYSCALL $SYS_tgkill RET TEXT runtime·raiseproc(SB),NOSPLIT|NOFRAME,$0 diff --git a/src/runtime/sys_linux_s390x.s b/src/runtime/sys_linux_s390x.s index 1ff110c232b87..95401af62ecc2 100644 --- a/src/runtime/sys_linux_s390x.s +++ b/src/runtime/sys_linux_s390x.s @@ -31,9 +31,9 @@ #define SYS_madvise 219 #define SYS_mincore 218 #define SYS_gettid 236 -#define SYS_tkill 237 #define SYS_futex 238 #define SYS_sched_getaffinity 240 +#define SYS_tgkill 241 #define SYS_exit_group 248 #define SYS_epoll_create 249 #define SYS_epoll_ctl 250 @@ -129,11 +129,15 @@ TEXT runtime·gettid(SB),NOSPLIT,$0-4 RET TEXT runtime·raise(SB),NOSPLIT|NOFRAME,$0 + MOVW $SYS_getpid, R1 + SYSCALL + MOVW R2, R10 MOVW $SYS_gettid, R1 SYSCALL - MOVW R2, R2 // arg 1 tid - MOVW sig+0(FP), R3 // arg 2 - MOVW $SYS_tkill, R1 + MOVW R2, R3 // arg 2 tid + MOVW R10, R2 // arg 1 pid + MOVW sig+0(FP), R4 // arg 2 + MOVW $SYS_tgkill, R1 SYSCALL RET From 25b84c01555645ccdc8ca83fe11461f1b450c286 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 28 May 2018 14:47:35 -0700 Subject: [PATCH 0332/1663] cmd/compile: move v.Pos.line check to warnRule This simplifies the rewrite rules. Change-Id: Iff062297d42a23cb31ad55e8c733842ecbc07da2 Reviewed-on: https://go-review.googlesource.com/129377 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/gen/generic.rules | 4 ++-- src/cmd/compile/internal/ssa/rewrite.go | 8 ++++---- src/cmd/compile/internal/ssa/rewritegeneric.go | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index aa944b53798d1..d0d49c7b8fd71 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -1363,12 +1363,12 @@ (NilCheck (Load (OffPtr [c] (SP)) (StaticCall {sym} _)) _) && isSameSym(sym, "runtime.newobject") && c == config.ctxt.FixedFrameSize() + config.RegSize // offset of return value - && warnRule(fe.Debug_checknil() && v.Pos.Line() > 1, v, "removed nil check") + && warnRule(fe.Debug_checknil(), v, "removed nil check") -> (Invalid) (NilCheck (OffPtr (Load (OffPtr [c] (SP)) (StaticCall {sym} _))) _) && isSameSym(sym, "runtime.newobject") && c == config.ctxt.FixedFrameSize() + config.RegSize // offset of return value - && warnRule(fe.Debug_checknil() && v.Pos.Line() > 1, v, "removed nil check") + && warnRule(fe.Debug_checknil(), v, "removed nil check") -> (Invalid) // Evaluate constant address comparisons. diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index ca6280deb1593..18ad7e1e4ad3e 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -646,11 +646,11 @@ func noteRule(s string) bool { return true } -// warnRule generates a compiler debug output with string s when -// cond is true and the rule is fired. +// warnRule generates compiler debug output with string s when +// v is not in autogenerated code, cond is true and the rule has fired. func warnRule(cond bool, v *Value, s string) bool { - if cond { - v.Block.Func.Warnl(v.Pos, s) + if pos := v.Pos; pos.Line() > 1 && cond { + v.Block.Func.Warnl(pos, s) } return true } diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 81bebede4689e..d91900d72f9c0 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -21412,7 +21412,7 @@ func rewriteValuegeneric_OpNilCheck_0(v *Value) bool { return true } // match: (NilCheck (Load (OffPtr [c] (SP)) (StaticCall {sym} _)) _) - // cond: isSameSym(sym, "runtime.newobject") && c == config.ctxt.FixedFrameSize() + config.RegSize && warnRule(fe.Debug_checknil() && v.Pos.Line() > 1, v, "removed nil check") + // cond: isSameSym(sym, "runtime.newobject") && c == config.ctxt.FixedFrameSize() + config.RegSize && warnRule(fe.Debug_checknil(), v, "removed nil check") // result: (Invalid) for { _ = v.Args[1] @@ -21435,14 +21435,14 @@ func rewriteValuegeneric_OpNilCheck_0(v *Value) bool { break } sym := v_0_1.Aux - if !(isSameSym(sym, "runtime.newobject") && c == config.ctxt.FixedFrameSize()+config.RegSize && warnRule(fe.Debug_checknil() && v.Pos.Line() > 1, v, "removed nil check")) { + if !(isSameSym(sym, "runtime.newobject") && c == config.ctxt.FixedFrameSize()+config.RegSize && warnRule(fe.Debug_checknil(), v, "removed nil check")) { break } v.reset(OpInvalid) return true } // match: (NilCheck (OffPtr (Load (OffPtr [c] (SP)) (StaticCall {sym} _))) _) - // cond: isSameSym(sym, "runtime.newobject") && c == config.ctxt.FixedFrameSize() + config.RegSize && warnRule(fe.Debug_checknil() && v.Pos.Line() > 1, v, "removed nil check") + // cond: isSameSym(sym, "runtime.newobject") && c == config.ctxt.FixedFrameSize() + config.RegSize && warnRule(fe.Debug_checknil(), v, "removed nil check") // result: (Invalid) for { _ = v.Args[1] @@ -21469,7 +21469,7 @@ func rewriteValuegeneric_OpNilCheck_0(v *Value) bool { break } sym := v_0_0_1.Aux - if !(isSameSym(sym, "runtime.newobject") && c == config.ctxt.FixedFrameSize()+config.RegSize && warnRule(fe.Debug_checknil() && v.Pos.Line() > 1, v, "removed nil check")) { + if !(isSameSym(sym, "runtime.newobject") && c == config.ctxt.FixedFrameSize()+config.RegSize && warnRule(fe.Debug_checknil(), v, "removed nil check")) { break } v.reset(OpInvalid) From 930e637ee9d7fb7032b82ea4c112f5aa220288f1 Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Sat, 8 Sep 2018 00:57:31 +0100 Subject: [PATCH 0333/1663] doc: make golang-nuts discussion list more prominent The discussion list was buried beneath the developer mailing list. This change puts the discussion list first and gives it a more prominent heading. Change-Id: I8dcb4af98e454ae3a0140f9758a5656909126983 Reviewed-on: https://go-review.googlesource.com/134136 Reviewed-by: Ian Lance Taylor --- doc/contrib.html | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/contrib.html b/doc/contrib.html index df53d480d3856..e63bcce142f93 100644 --- a/doc/contrib.html +++ b/doc/contrib.html @@ -59,6 +59,15 @@

Developer Resources

Source Code

Check out the Go source code.

+

Discussion Mailing List

+

+A mailing list for general discussion of Go programming. +

+

+Questions about using Go or announcements relevant to other Go users should be sent to +golang-nuts. +

+

Developer and Code Review Mailing List

The golang-dev @@ -66,9 +75,6 @@

Develop The golang-codereviews mailing list is for actual reviewing of the code changes (CLs).

-

For general discussion of Go programming, see golang-nuts.

-

Checkins Mailing List

A mailing list that receives a message summarizing each checkin to the Go repository.

@@ -116,7 +122,7 @@

Contributing code

guidelines for information on design, testing, and our code review process.

-Check the tracker for +Check the tracker for open issues that interest you. Those labeled help wanted are particularly in need of outside help. From 4545fea4fc845d481d97e7dac7d6fe0b37048ce2 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Sat, 8 Sep 2018 14:23:14 +0000 Subject: [PATCH 0334/1663] cmd/compile/internal/amd64: simplify assembly generator Merge two case-statements together, since they have similar logic. 1. That makes the assembly generator more clear. 2. The total size of cmd/compile decreases about 0.8KB. Change-Id: I0144a07152202ee7b21e323bcd5dea80a351a6e3 Reviewed-on: https://go-review.googlesource.com/134215 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/amd64/ssa.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/cmd/compile/internal/amd64/ssa.go b/src/cmd/compile/internal/amd64/ssa.go index ae6141dd12ebd..2afb556d80f40 100644 --- a/src/cmd/compile/internal/amd64/ssa.go +++ b/src/cmd/compile/internal/amd64/ssa.go @@ -583,7 +583,11 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.From.Reg = v.Args[0].Reg() p.To.Type = obj.TYPE_CONST p.To.Offset = v.AuxInt - case ssa.OpAMD64BTLconst, ssa.OpAMD64BTQconst: + case ssa.OpAMD64BTLconst, ssa.OpAMD64BTQconst, + ssa.OpAMD64TESTQconst, ssa.OpAMD64TESTLconst, ssa.OpAMD64TESTWconst, ssa.OpAMD64TESTBconst, + ssa.OpAMD64BTSLconst, ssa.OpAMD64BTSQconst, + ssa.OpAMD64BTCLconst, ssa.OpAMD64BTCQconst, + ssa.OpAMD64BTRLconst, ssa.OpAMD64BTRQconst: op := v.Op if op == ssa.OpAMD64BTQconst && v.AuxInt < 32 { // Emit 32-bit version because it's shorter @@ -594,15 +598,6 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.From.Offset = v.AuxInt p.To.Type = obj.TYPE_REG p.To.Reg = v.Args[0].Reg() - case ssa.OpAMD64TESTQconst, ssa.OpAMD64TESTLconst, ssa.OpAMD64TESTWconst, ssa.OpAMD64TESTBconst, - ssa.OpAMD64BTSLconst, ssa.OpAMD64BTSQconst, - ssa.OpAMD64BTCLconst, ssa.OpAMD64BTCQconst, - ssa.OpAMD64BTRLconst, ssa.OpAMD64BTRQconst: - p := s.Prog(v.Op.Asm()) - p.From.Type = obj.TYPE_CONST - p.From.Offset = v.AuxInt - p.To.Type = obj.TYPE_REG - p.To.Reg = v.Args[0].Reg() case ssa.OpAMD64CMPQload, ssa.OpAMD64CMPLload, ssa.OpAMD64CMPWload, ssa.OpAMD64CMPBload: p := s.Prog(v.Op.Asm()) p.From.Type = obj.TYPE_MEM From bbf9e6db0ad4ce951706759d3743dbab2257d033 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Sun, 12 Aug 2018 11:16:26 +1000 Subject: [PATCH 0335/1663] internal/poll: cap reads and writes to 1GB on windows Fixes #26923 Change-Id: I62fec814220ccdf7acd8d79a133d1add3f24cf98 Reviewed-on: https://go-review.googlesource.com/129137 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/internal/poll/fd_windows.go | 144 +++++++++++++++++++++++--------- 1 file changed, 105 insertions(+), 39 deletions(-) diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go index b08cec26256ec..b5aaafda0235a 100644 --- a/src/internal/poll/fd_windows.go +++ b/src/internal/poll/fd_windows.go @@ -116,11 +116,17 @@ func (o *operation) InitBufs(buf *[][]byte) { o.bufs = o.bufs[:0] } for _, b := range *buf { - var p *byte + if len(b) == 0 { + o.bufs = append(o.bufs, syscall.WSABuf{}) + continue + } + for len(b) > maxRW { + o.bufs = append(o.bufs, syscall.WSABuf{Len: maxRW, Buf: &b[0]}) + b = b[maxRW:] + } if len(b) > 0 { - p = &b[0] + o.bufs = append(o.bufs, syscall.WSABuf{Len: uint32(len(b)), Buf: &b[0]}) } - o.bufs = append(o.bufs, syscall.WSABuf{Len: uint32(len(b)), Buf: p}) } } @@ -461,6 +467,11 @@ func (fd *FD) Shutdown(how int) error { return syscall.Shutdown(fd.Sysfd, how) } +// Windows ReadFile and WSARecv use DWORD (uint32) parameter to pass buffer length. +// This prevents us reading blocks larger than 4GB. +// See golang.org/issue/26923. +const maxRW = 1 << 30 // 1GB is large enough and keeps subsequent reads aligned + // Read implements io.Reader. func (fd *FD) Read(buf []byte) (int, error) { if err := fd.readLock(); err != nil { @@ -468,6 +479,10 @@ func (fd *FD) Read(buf []byte) (int, error) { } defer fd.readUnlock() + if len(buf) > maxRW { + buf = buf[:maxRW] + } + var n int var err error if fd.isFile || fd.isDir || fd.isConsole { @@ -581,6 +596,10 @@ func (fd *FD) Pread(b []byte, off int64) (int, error) { } defer fd.decref() + if len(b) > maxRW { + b = b[:maxRW] + } + fd.l.Lock() defer fd.l.Unlock() curoffset, e := syscall.Seek(fd.Sysfd, 0, io.SeekCurrent) @@ -611,6 +630,9 @@ func (fd *FD) ReadFrom(buf []byte) (int, syscall.Sockaddr, error) { if len(buf) == 0 { return 0, nil, nil } + if len(buf) > maxRW { + buf = buf[:maxRW] + } if err := fd.readLock(); err != nil { return 0, nil, err } @@ -639,30 +661,42 @@ func (fd *FD) Write(buf []byte) (int, error) { } defer fd.writeUnlock() - var n int - var err error - if fd.isFile || fd.isDir || fd.isConsole { - fd.l.Lock() - defer fd.l.Unlock() - if fd.isConsole { - n, err = fd.writeConsole(buf) + ntotal := 0 + for len(buf) > 0 { + b := buf + if len(b) > maxRW { + b = b[:maxRW] + } + var n int + var err error + if fd.isFile || fd.isDir || fd.isConsole { + fd.l.Lock() + defer fd.l.Unlock() + if fd.isConsole { + n, err = fd.writeConsole(b) + } else { + n, err = syscall.Write(fd.Sysfd, b) + } + if err != nil { + n = 0 + } } else { - n, err = syscall.Write(fd.Sysfd, buf) + if race.Enabled { + race.ReleaseMerge(unsafe.Pointer(&ioSync)) + } + o := &fd.wop + o.InitBuf(b) + n, err = wsrv.ExecIO(o, func(o *operation) error { + return syscall.WSASend(o.fd.Sysfd, &o.buf, 1, &o.qty, 0, &o.o, nil) + }) } + ntotal += n if err != nil { - n = 0 + return ntotal, err } - } else { - if race.Enabled { - race.ReleaseMerge(unsafe.Pointer(&ioSync)) - } - o := &fd.wop - o.InitBuf(buf) - n, err = wsrv.ExecIO(o, func(o *operation) error { - return syscall.WSASend(o.fd.Sysfd, &o.buf, 1, &o.qty, 0, &o.o, nil) - }) + buf = buf[n:] } - return n, err + return ntotal, nil } // writeConsole writes len(b) bytes to the console File. @@ -709,7 +743,7 @@ func (fd *FD) writeConsole(b []byte) (int, error) { } // Pwrite emulates the Unix pwrite system call. -func (fd *FD) Pwrite(b []byte, off int64) (int, error) { +func (fd *FD) Pwrite(buf []byte, off int64) (int, error) { // Call incref, not writeLock, because since pwrite specifies the // offset it is independent from other writes. if err := fd.incref(); err != nil { @@ -724,16 +758,27 @@ func (fd *FD) Pwrite(b []byte, off int64) (int, error) { return 0, e } defer syscall.Seek(fd.Sysfd, curoffset, io.SeekStart) - o := syscall.Overlapped{ - OffsetHigh: uint32(off >> 32), - Offset: uint32(off), - } - var done uint32 - e = syscall.WriteFile(fd.Sysfd, b, &done, &o) - if e != nil { - return 0, e + + ntotal := 0 + for len(buf) > 0 { + b := buf + if len(b) > maxRW { + b = b[:maxRW] + } + var n uint32 + o := syscall.Overlapped{ + OffsetHigh: uint32(off >> 32), + Offset: uint32(off), + } + e = syscall.WriteFile(fd.Sysfd, b, &n, &o) + ntotal += int(n) + if e != nil { + return ntotal, e + } + buf = buf[n:] + off += int64(n) } - return int(done), nil + return ntotal, nil } // Writev emulates the Unix writev system call. @@ -765,13 +810,26 @@ func (fd *FD) WriteTo(buf []byte, sa syscall.Sockaddr) (int, error) { return 0, err } defer fd.writeUnlock() - o := &fd.wop - o.InitBuf(buf) - o.sa = sa - n, err := wsrv.ExecIO(o, func(o *operation) error { - return syscall.WSASendto(o.fd.Sysfd, &o.buf, 1, &o.qty, 0, o.sa, &o.o, nil) - }) - return n, err + + ntotal := 0 + for len(buf) > 0 { + b := buf + if len(b) > maxRW { + b = b[:maxRW] + } + o := &fd.wop + o.InitBuf(b) + o.sa = sa + n, err := wsrv.ExecIO(o, func(o *operation) error { + return syscall.WSASendto(o.fd.Sysfd, &o.buf, 1, &o.qty, 0, o.sa, &o.o, nil) + }) + ntotal += int(n) + if err != nil { + return ntotal, err + } + buf = buf[n:] + } + return ntotal, nil } // Call ConnectEx. This doesn't need any locking, since it is only @@ -986,6 +1044,10 @@ func (fd *FD) ReadMsg(p []byte, oob []byte) (int, int, int, syscall.Sockaddr, er } defer fd.readUnlock() + if len(p) > maxRW { + p = p[:maxRW] + } + o := &fd.rop o.InitMsg(p, oob) o.rsa = new(syscall.RawSockaddrAny) @@ -1004,6 +1066,10 @@ func (fd *FD) ReadMsg(p []byte, oob []byte) (int, int, int, syscall.Sockaddr, er // WriteMsg wraps the WSASendMsg network call. func (fd *FD) WriteMsg(p []byte, oob []byte, sa syscall.Sockaddr) (int, int, error) { + if len(p) > maxRW { + return 0, 0, errors.New("packet is too large (only 1GB is allowed)") + } + if err := fd.writeLock(); err != nil { return 0, 0, err } From 1705962cf976a001bb9929146e5690a957ed630e Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Sun, 9 Sep 2018 14:21:25 +1000 Subject: [PATCH 0336/1663] internal/poll: handle zero-byte write in FD.WriteTo Zero-byte write was fixed by CL 132781, that was submitted 3 days ago. But I just submitted CL 129137, and the CL broken zero-byte write functionality without me noticing. CL 129137 was based on old commit (older than 3 days ago), and try-bots did not discover the breakage. Fix zero-byte write again. Fixes windows build. Change-Id: Ib403b25fd25cb881963f25706eecca92b924aaa1 Reviewed-on: https://go-review.googlesource.com/134275 Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot Reviewed-by: Alex Brainman --- src/internal/poll/fd_windows.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/internal/poll/fd_windows.go b/src/internal/poll/fd_windows.go index b5aaafda0235a..19d9a12dad83b 100644 --- a/src/internal/poll/fd_windows.go +++ b/src/internal/poll/fd_windows.go @@ -811,6 +811,17 @@ func (fd *FD) WriteTo(buf []byte, sa syscall.Sockaddr) (int, error) { } defer fd.writeUnlock() + if len(buf) == 0 { + // handle zero-byte payload + o := &fd.wop + o.InitBuf(buf) + o.sa = sa + n, err := wsrv.ExecIO(o, func(o *operation) error { + return syscall.WSASendto(o.fd.Sysfd, &o.buf, 1, &o.qty, 0, o.sa, &o.o, nil) + }) + return n, err + } + ntotal := 0 for len(buf) > 0 { b := buf From 3a18f0ecb5748488501c565e995ec12a29e66966 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Sat, 8 Sep 2018 12:35:03 -0700 Subject: [PATCH 0337/1663] os/user: retrieve Current username from /etc/passwd, not $USER Per golang/go#27524 there are situations where the username for the uid does not match the value in the $USER environment variable and it seems sensible to choose the value in /etc/passwd when they disagree. This may make the Current() call slightly more expensive, since we read /etc/passwd with cgo disabled instead of just checking the environment. However, we cache the result of Current() calls, so we only invoke this cost once in the lifetime of the process. Fixes #14626. Fixes #27524. Updates #24884. Change-Id: I0dcd224cf7f61dd5292f3fcc363aa2e9656a2cb1 Reviewed-on: https://go-review.googlesource.com/134218 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/os/user/lookup_stubs.go | 11 +++++++++-- src/os/user/user_test.go | 18 ++---------------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/os/user/lookup_stubs.go b/src/os/user/lookup_stubs.go index f7d138ff46801..9fc03c65d95ac 100644 --- a/src/os/user/lookup_stubs.go +++ b/src/os/user/lookup_stubs.go @@ -19,8 +19,15 @@ func init() { } func current() (*User, error) { - u := &User{ - Uid: currentUID(), + uid := currentUID() + // $USER and /etc/passwd may disagree; prefer the latter if we can get it. + // See issue 27524 for more information. + u, err := lookupUserId(uid) + if err == nil { + return u, nil + } + u = &User{ + Uid: uid, Gid: currentGID(), Username: os.Getenv("USER"), Name: "", // ignored diff --git a/src/os/user/user_test.go b/src/os/user/user_test.go index 8fd760e64981b..2563077eb2e97 100644 --- a/src/os/user/user_test.go +++ b/src/os/user/user_test.go @@ -5,33 +5,18 @@ package user import ( - "internal/testenv" - "os" "runtime" "testing" ) func checkUser(t *testing.T) { + t.Helper() if !userImplemented { t.Skip("user: not implemented; skipping tests") } } func TestCurrent(t *testing.T) { - // The Go builders (in particular the ones using containers) - // often have minimal environments without $HOME or $USER set, - // which breaks Current which relies on those working as a - // fallback. - // TODO: we should fix that (Issue 24884) and remove these - // workarounds. - if testenv.Builder() != "" && runtime.GOOS != "windows" && runtime.GOOS != "plan9" { - if os.Getenv("HOME") == "" { - os.Setenv("HOME", "/tmp") - } - if os.Getenv("USER") == "" { - os.Setenv("USER", "gobuilder") - } - } u, err := Current() if err != nil { t.Fatalf("Current: %v (got %#v)", err, u) @@ -108,6 +93,7 @@ func TestLookupId(t *testing.T) { } func checkGroup(t *testing.T) { + t.Helper() if !groupImplemented { t.Skip("user: group not implemented; skipping test") } From 12c5ca90a00768c6ad5f6d83f7c37964a30256fb Mon Sep 17 00:00:00 2001 From: Dominik Honnef Date: Sun, 9 Sep 2018 11:50:56 +0200 Subject: [PATCH 0338/1663] go/types: fix swapped use of "uses" and "defines" in ObjectOf documentation Change-Id: I855a9c88c379978099ea53c7d28b87cefd7f5d73 Reviewed-on: https://go-review.googlesource.com/134295 Reviewed-by: Robert Griesemer --- src/go/types/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/go/types/api.go b/src/go/types/api.go index fcefddf48835c..4e14f40adef7a 100644 --- a/src/go/types/api.go +++ b/src/go/types/api.go @@ -240,7 +240,7 @@ func (info *Info) TypeOf(e ast.Expr) Type { // or nil if not found. // // If id is an embedded struct field, ObjectOf returns the field (*Var) -// it uses, not the type (*TypeName) it defines. +// it defines, not the type (*TypeName) it uses. // // Precondition: the Uses and Defs maps are populated. // From 0f72e79856d246af85c449f9e5a357ba751cd234 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Fri, 7 Sep 2018 09:54:38 -0400 Subject: [PATCH 0339/1663] go/token: add (*File).LineStart, which returns Pos for a given line LineStart returns the position of the start of a given line. Like MergeLine, it panics if the 1-based line number is invalid. This function is especially useful in programs that occasionally handle non-Go files such as assembly but wish to use the token.Pos mechanism to identify file positions. Change-Id: I5f774c0690074059553cdb38c0f681f5aafc8da1 Reviewed-on: https://go-review.googlesource.com/134075 Reviewed-by: Robert Griesemer --- src/go/token/position.go | 17 ++++++++++++++++- src/go/token/position_test.go | 15 +++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/go/token/position.go b/src/go/token/position.go index 241133fe263b3..3f5a390078d0d 100644 --- a/src/go/token/position.go +++ b/src/go/token/position.go @@ -146,7 +146,7 @@ func (f *File) AddLine(offset int) { // MergeLine will panic if given an invalid line number. // func (f *File) MergeLine(line int) { - if line <= 0 { + if line < 1 { panic("illegal line number (line numbering starts at 1)") } f.mutex.Lock() @@ -209,6 +209,21 @@ func (f *File) SetLinesForContent(content []byte) { f.mutex.Unlock() } +// LineStart returns the Pos value of the start of the specified line. +// It ignores any alternative positions set using AddLineColumnInfo. +// LineStart panics if the 1-based line number is invalid. +func (f *File) LineStart(line int) Pos { + if line < 1 { + panic("illegal line number (line numbering starts at 1)") + } + f.mutex.Lock() + defer f.mutex.Unlock() + if line > len(f.lines) { + panic("illegal line number") + } + return Pos(f.base + f.lines[line-1]) +} + // A lineInfo object describes alternative file, line, and column // number information (such as provided via a //line directive) // for a given file offset. diff --git a/src/go/token/position_test.go b/src/go/token/position_test.go index 63984bc872c82..7d465dffa621f 100644 --- a/src/go/token/position_test.go +++ b/src/go/token/position_test.go @@ -324,3 +324,18 @@ done checkPos(t, "3. Position", got3, want) } } + +func TestLineStart(t *testing.T) { + const src = "one\ntwo\nthree\n" + fset := NewFileSet() + f := fset.AddFile("input", -1, len(src)) + f.SetLinesForContent([]byte(src)) + + for line := 1; line <= 3; line++ { + pos := f.LineStart(line) + position := fset.Position(pos) + if position.Line != line || position.Column != 1 { + t.Errorf("LineStart(%d) returned wrong pos %d: %s", line, pos, position) + } + } +} From 95a11c7381e01fdaaf34e25b82db0632081ab74e Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Mon, 10 Sep 2018 12:13:09 +0100 Subject: [PATCH 0340/1663] net/url: remove an allocation for short strings in escape MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a 64 byte array to avoid an allocation on the assumption that most url escaping is performed on short strings. Also adds a fast path for escaping strings whose only replacements are spaces which is common in query components. Adds benchmarks for QueryEscape, PathEscape, QueryUnescape and PathUnescape but no optimizations are include for the unescape functions so I don't include those benchmark results here. Reduces allocations by 10% in the existing String benchmark with a modest performance increase. name old time/op new time/op delta QueryEscape/#00-8 64.6ns ± 1% 43.8ns ± 0% -32.14% (p=0.000 n=9+9) QueryEscape/#01-8 276ns ± 3% 249ns ± 0% -9.62% (p=0.000 n=10+7) QueryEscape/#02-8 176ns ± 2% 155ns ± 3% -12.21% (p=0.000 n=10+10) QueryEscape/#03-8 388ns ± 1% 362ns ± 0% -6.55% (p=0.000 n=10+8) QueryEscape/#04-8 2.32µs ± 2% 2.27µs ± 2% -2.26% (p=0.001 n=10+10) PathEscape/#00-8 78.0ns ± 3% 63.4ns ± 1% -18.69% (p=0.000 n=10+10) PathEscape/#01-8 276ns ± 2% 260ns ± 0% -6.01% (p=0.000 n=10+10) PathEscape/#02-8 175ns ± 0% 153ns ± 0% -12.53% (p=0.000 n=8+10) PathEscape/#03-8 389ns ± 2% 361ns ± 0% -7.21% (p=0.000 n=10+9) PathEscape/#04-8 2.30µs ± 2% 2.27µs ± 1% -1.33% (p=0.001 n=9+10) String-8 3.56µs ± 4% 3.42µs ± 7% -4.00% (p=0.003 n=10+10) name old alloc/op new alloc/op delta QueryEscape/#00-8 16.0B ± 0% 8.0B ± 0% -50.00% (p=0.000 n=10+10) QueryEscape/#01-8 128B ± 0% 64B ± 0% -50.00% (p=0.000 n=10+10) QueryEscape/#02-8 64.0B ± 0% 32.0B ± 0% -50.00% (p=0.000 n=10+10) QueryEscape/#03-8 128B ± 0% 64B ± 0% -50.00% (p=0.000 n=10+10) QueryEscape/#04-8 832B ± 0% 832B ± 0% ~ (all equal) PathEscape/#00-8 32.0B ± 0% 16.0B ± 0% -50.00% (p=0.000 n=10+10) PathEscape/#01-8 128B ± 0% 64B ± 0% -50.00% (p=0.000 n=10+10) PathEscape/#02-8 64.0B ± 0% 32.0B ± 0% -50.00% (p=0.000 n=10+10) PathEscape/#03-8 128B ± 0% 64B ± 0% -50.00% (p=0.000 n=10+10) PathEscape/#04-8 704B ± 0% 704B ± 0% ~ (all equal) String-8 1.84kB ± 0% 1.66kB ± 0% -9.57% (p=0.000 n=10+10) name old allocs/op new allocs/op delta QueryEscape/#00-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) QueryEscape/#01-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) QueryEscape/#02-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) QueryEscape/#03-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) QueryEscape/#04-8 2.00 ± 0% 2.00 ± 0% ~ (all equal) PathEscape/#00-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) PathEscape/#01-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) PathEscape/#02-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) PathEscape/#03-8 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.000 n=10+10) PathEscape/#04-8 2.00 ± 0% 2.00 ± 0% ~ (all equal) String-8 69.0 ± 0% 61.0 ± 0% -11.59% (p=0.000 n=10+10) Updates #17860 Change-Id: I45c5e9d40b242f874c61f6ccc73bf94c494bb868 Reviewed-on: https://go-review.googlesource.com/134296 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/net/url/url.go | 21 +++++++- src/net/url/url_test.go | 103 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 1 deletion(-) diff --git a/src/net/url/url.go b/src/net/url/url.go index 4943ea6d67ceb..b678b82352e05 100644 --- a/src/net/url/url.go +++ b/src/net/url/url.go @@ -304,7 +304,26 @@ func escape(s string, mode encoding) string { return s } - t := make([]byte, len(s)+2*hexCount) + var buf [64]byte + var t []byte + + required := len(s) + 2*hexCount + if required <= len(buf) { + t = buf[:required] + } else { + t = make([]byte, required) + } + + if hexCount == 0 { + copy(t, s) + for i := 0; i < len(s); i++ { + if s[i] == ' ' { + t[i] = '+' + } + } + return string(t) + } + j := 0 for i := 0; i < len(s); i++ { switch c := s[i]; { diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go index 19d4d636d6221..231340a9eb89d 100644 --- a/src/net/url/url_test.go +++ b/src/net/url/url_test.go @@ -1754,3 +1754,106 @@ func TestInvalidUserPassword(t *testing.T) { t.Errorf("error = %q; want substring %q", got, wantsub) } } + +var escapeBenchmarks = []struct { + unescaped string + query string + path string +}{ + { + unescaped: "one two", + query: "one+two", + path: "one%20two", + }, + { + unescaped: "Фотки собак", + query: "%D0%A4%D0%BE%D1%82%D0%BA%D0%B8+%D1%81%D0%BE%D0%B1%D0%B0%D0%BA", + path: "%D0%A4%D0%BE%D1%82%D0%BA%D0%B8%20%D1%81%D0%BE%D0%B1%D0%B0%D0%BA", + }, + + { + unescaped: "shortrun(break)shortrun", + query: "shortrun%28break%29shortrun", + path: "shortrun%28break%29shortrun", + }, + + { + unescaped: "longerrunofcharacters(break)anotherlongerrunofcharacters", + query: "longerrunofcharacters%28break%29anotherlongerrunofcharacters", + path: "longerrunofcharacters%28break%29anotherlongerrunofcharacters", + }, + + { + unescaped: strings.Repeat("padded/with+various%characters?that=need$some@escaping+paddedsowebreak/256bytes", 4), + query: strings.Repeat("padded%2Fwith%2Bvarious%25characters%3Fthat%3Dneed%24some%40escaping%2Bpaddedsowebreak%2F256bytes", 4), + path: strings.Repeat("padded%2Fwith+various%25characters%3Fthat=need$some@escaping+paddedsowebreak%2F256bytes", 4), + }, +} + +func BenchmarkQueryEscape(b *testing.B) { + for _, tc := range escapeBenchmarks { + b.Run("", func(b *testing.B) { + b.ReportAllocs() + var g string + for i := 0; i < b.N; i++ { + g = QueryEscape(tc.unescaped) + } + b.StopTimer() + if g != tc.query { + b.Errorf("QueryEscape(%q) == %q, want %q", tc.unescaped, g, tc.query) + } + + }) + } +} + +func BenchmarkPathEscape(b *testing.B) { + for _, tc := range escapeBenchmarks { + b.Run("", func(b *testing.B) { + b.ReportAllocs() + var g string + for i := 0; i < b.N; i++ { + g = PathEscape(tc.unescaped) + } + b.StopTimer() + if g != tc.path { + b.Errorf("PathEscape(%q) == %q, want %q", tc.unescaped, g, tc.path) + } + + }) + } +} + +func BenchmarkQueryUnescape(b *testing.B) { + for _, tc := range escapeBenchmarks { + b.Run("", func(b *testing.B) { + b.ReportAllocs() + var g string + for i := 0; i < b.N; i++ { + g, _ = QueryUnescape(tc.query) + } + b.StopTimer() + if g != tc.unescaped { + b.Errorf("QueryUnescape(%q) == %q, want %q", tc.query, g, tc.unescaped) + } + + }) + } +} + +func BenchmarkPathUnescape(b *testing.B) { + for _, tc := range escapeBenchmarks { + b.Run("", func(b *testing.B) { + b.ReportAllocs() + var g string + for i := 0; i < b.N; i++ { + g, _ = PathUnescape(tc.path) + } + b.StopTimer() + if g != tc.unescaped { + b.Errorf("PathUnescape(%q) == %q, want %q", tc.path, g, tc.unescaped) + } + + }) + } +} From 9f2411894ba41d9032623cf637a62846397fec67 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Mon, 10 Sep 2018 08:29:52 +0000 Subject: [PATCH 0341/1663] cmd/compile: optimize arm's bit operation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BFC (Bit Field Clear) was introduced in ARMv7, which can simplify ANDconst and BICconst. And this CL implements that optimization. 1. The total size of pkg/android_arm decreases about 3KB, excluding cmd/compile/. 2. There is no regression in the go1 benchmark result, and some cases (FmtFprintfEmpty-4 and RegexpMatchMedium_32-4) even get slight improvement. name old time/op new time/op delta BinaryTree17-4 25.3s ± 1% 25.2s ± 1% ~ (p=0.072 n=30+29) Fannkuch11-4 13.3s ± 0% 13.3s ± 0% +0.13% (p=0.000 n=30+26) FmtFprintfEmpty-4 407ns ± 0% 394ns ± 0% -3.19% (p=0.000 n=26+28) FmtFprintfString-4 664ns ± 0% 662ns ± 0% -0.22% (p=0.000 n=30+30) FmtFprintfInt-4 712ns ± 0% 706ns ± 0% -0.79% (p=0.000 n=30+30) FmtFprintfIntInt-4 1.06µs ± 0% 1.05µs ± 0% -0.38% (p=0.000 n=30+30) FmtFprintfPrefixedInt-4 1.16µs ± 0% 1.16µs ± 0% -0.13% (p=0.000 n=30+29) FmtFprintfFloat-4 2.24µs ± 0% 2.23µs ± 0% -0.51% (p=0.000 n=29+21) FmtManyArgs-4 4.09µs ± 0% 4.06µs ± 0% -0.83% (p=0.000 n=28+30) GobDecode-4 55.0ms ± 5% 55.4ms ± 5% ~ (p=0.307 n=30+30) GobEncode-4 51.2ms ± 1% 51.9ms ± 1% +1.23% (p=0.000 n=29+30) Gzip-4 2.64s ± 0% 2.60s ± 0% -1.35% (p=0.000 n=30+29) Gunzip-4 309ms ± 0% 308ms ± 0% -0.27% (p=0.000 n=30+30) HTTPClientServer-4 1.03ms ± 5% 1.02ms ± 4% ~ (p=0.117 n=30+29) JSONEncode-4 101ms ± 2% 101ms ± 2% ~ (p=0.338 n=29+29) JSONDecode-4 383ms ± 2% 382ms ± 2% ~ (p=0.751 n=26+30) Mandelbrot200-4 18.4ms ± 0% 18.4ms ± 0% -0.10% (p=0.000 n=29+29) GoParse-4 22.6ms ± 0% 22.5ms ± 0% -0.39% (p=0.000 n=30+30) RegexpMatchEasy0_32-4 761ns ± 0% 750ns ± 0% -1.47% (p=0.000 n=26+29) RegexpMatchEasy0_1K-4 4.33µs ± 0% 4.34µs ± 0% +0.27% (p=0.000 n=25+28) RegexpMatchEasy1_32-4 809ns ± 0% 795ns ± 0% -1.74% (p=0.000 n=27+25) RegexpMatchEasy1_1K-4 5.54µs ± 0% 5.53µs ± 0% -0.18% (p=0.000 n=29+29) RegexpMatchMedium_32-4 1.11µs ± 0% 1.08µs ± 0% -2.78% (p=0.000 n=27+29) RegexpMatchMedium_1K-4 255µs ± 0% 255µs ± 0% -0.02% (p=0.029 n=30+30) RegexpMatchHard_32-4 14.7µs ± 0% 14.7µs ± 0% -0.28% (p=0.000 n=30+29) RegexpMatchHard_1K-4 439µs ± 0% 439µs ± 0% ~ (p=0.907 n=23+27) Revcomp-4 41.9ms ± 1% 41.9ms ± 1% ~ (p=0.230 n=28+30) Template-4 522ms ± 1% 528ms ± 1% +1.25% (p=0.000 n=30+30) TimeParse-4 3.34µs ± 0% 3.35µs ± 0% +0.23% (p=0.000 n=30+27) TimeFormat-4 6.06µs ± 0% 6.13µs ± 0% +1.08% (p=0.000 n=29+29) [Geo mean] 384µs 382µs -0.37% name old speed new speed delta GobDecode-4 14.0MB/s ± 5% 13.9MB/s ± 5% ~ (p=0.308 n=30+30) GobEncode-4 15.0MB/s ± 1% 14.8MB/s ± 1% -1.22% (p=0.000 n=29+30) Gzip-4 7.36MB/s ± 0% 7.46MB/s ± 0% +1.35% (p=0.000 n=30+30) Gunzip-4 62.8MB/s ± 0% 63.0MB/s ± 0% +0.27% (p=0.000 n=30+30) JSONEncode-4 19.2MB/s ± 2% 19.2MB/s ± 2% ~ (p=0.312 n=29+29) JSONDecode-4 5.05MB/s ± 3% 5.08MB/s ± 2% ~ (p=0.356 n=29+30) GoParse-4 2.56MB/s ± 0% 2.57MB/s ± 0% +0.39% (p=0.000 n=23+27) RegexpMatchEasy0_32-4 42.0MB/s ± 0% 42.6MB/s ± 0% +1.50% (p=0.000 n=26+28) RegexpMatchEasy0_1K-4 236MB/s ± 0% 236MB/s ± 0% -0.27% (p=0.000 n=25+28) RegexpMatchEasy1_32-4 39.6MB/s ± 0% 40.2MB/s ± 0% +1.73% (p=0.000 n=27+27) RegexpMatchEasy1_1K-4 185MB/s ± 0% 185MB/s ± 0% +0.18% (p=0.000 n=29+29) RegexpMatchMedium_32-4 900kB/s ± 0% 920kB/s ± 0% +2.22% (p=0.000 n=29+29) RegexpMatchMedium_1K-4 4.02MB/s ± 0% 4.02MB/s ± 0% +0.07% (p=0.004 n=30+27) RegexpMatchHard_32-4 2.17MB/s ± 0% 2.18MB/s ± 0% +0.46% (p=0.000 n=30+26) RegexpMatchHard_1K-4 2.33MB/s ± 0% 2.33MB/s ± 0% ~ (all equal) Revcomp-4 60.6MB/s ± 1% 60.7MB/s ± 1% ~ (p=0.207 n=28+30) Template-4 3.72MB/s ± 1% 3.67MB/s ± 1% -1.23% (p=0.000 n=30+30) [Geo mean] 12.9MB/s 12.9MB/s +0.29% Change-Id: I07f497f8bb476c950dc555491d00c9066fb64a4e Reviewed-on: https://go-review.googlesource.com/134232 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/arm/ssa.go | 49 +++++++++++++++++++++++++++-- test/codegen/bits.go | 7 +++-- 2 files changed, 52 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/arm/ssa.go b/src/cmd/compile/internal/arm/ssa.go index 98627344b8c4a..9a8fabf622589 100644 --- a/src/cmd/compile/internal/arm/ssa.go +++ b/src/cmd/compile/internal/arm/ssa.go @@ -7,6 +7,7 @@ package arm import ( "fmt" "math" + "math/bits" "cmd/compile/internal/gc" "cmd/compile/internal/ssa" @@ -119,6 +120,28 @@ func genregshift(s *gc.SSAGenState, as obj.As, r0, r1, r2, r int16, typ int64) * return p } +// find a (lsb, width) pair for BFC +// lsb must be in [0, 31], width must be in [1, 32 - lsb] +// return (0xffffffff, 0) if v is not a binary like 0...01...10...0 +func getBFC(v uint32) (uint32, uint32) { + var m, l uint32 + // BFC is not applicable with zero + if v == 0 { + return 0xffffffff, 0 + } + // find the lowest set bit, for example l=2 for 0x3ffffffc + l = uint32(bits.TrailingZeros32(v)) + // m-1 represents the highest set bit index, for example m=30 for 0x3ffffffc + m = 32 - uint32(bits.LeadingZeros32(v)) + // check if v is a binary like 0...01...10...0 + if (1< l for non-zero v + return l, m - l + } + // invalid + return 0xffffffff, 0 +} + func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { switch v.Op { case ssa.OpCopy, ssa.OpARMMOVWreg: @@ -267,16 +290,38 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.Reg = v.Args[0].Reg() p.To.Type = obj.TYPE_REG p.To.Reg = v.Reg() + case ssa.OpARMANDconst, ssa.OpARMBICconst: + // try to optimize ANDconst and BICconst to BFC, which saves bytes and ticks + // BFC is only available on ARMv7, and its result and source are in the same register + if objabi.GOARM == 7 && v.Reg() == v.Args[0].Reg() { + var val uint32 + if v.Op == ssa.OpARMANDconst { + val = ^uint32(v.AuxInt) + } else { // BICconst + val = uint32(v.AuxInt) + } + lsb, width := getBFC(val) + // omit BFC for ARM's imm12 + if 8 < width && width < 24 { + p := s.Prog(arm.ABFC) + p.From.Type = obj.TYPE_CONST + p.From.Offset = int64(width) + p.SetFrom3(obj.Addr{Type: obj.TYPE_CONST, Offset: int64(lsb)}) + p.To.Type = obj.TYPE_REG + p.To.Reg = v.Reg() + break + } + } + // fall back to ordinary form + fallthrough case ssa.OpARMADDconst, ssa.OpARMADCconst, ssa.OpARMSUBconst, ssa.OpARMSBCconst, ssa.OpARMRSBconst, ssa.OpARMRSCconst, - ssa.OpARMANDconst, ssa.OpARMORconst, ssa.OpARMXORconst, - ssa.OpARMBICconst, ssa.OpARMSLLconst, ssa.OpARMSRLconst, ssa.OpARMSRAconst: diff --git a/test/codegen/bits.go b/test/codegen/bits.go index c46f75845c22e..e95e3f64cda69 100644 --- a/test/codegen/bits.go +++ b/test/codegen/bits.go @@ -284,9 +284,12 @@ func and_mask_2(a uint64) uint64 { return a & (1 << 63) } -func and_mask_3(a uint32) uint32 { +func and_mask_3(a, b uint32) (uint32, uint32) { // arm/7:`BIC`,-`AND` - return a & 0xffff0000 + a &= 0xffffaaaa + // arm/7:`BFC`,-`AND`,-`BIC` + b &= 0xffc003ff + return a, b } // Check generation of arm64 BIC/EON/ORN instructions From aa4fc0e73654c0a8741d970bfca47c25125633cf Mon Sep 17 00:00:00 2001 From: Lynn Boger Date: Mon, 10 Sep 2018 15:07:09 -0400 Subject: [PATCH 0342/1663] cmd/link,compress/zip,image/png: use binary.{Big,Little}Endian methods Use the binary.{Big,Little}Endian integer encoding methods rather than variations found in local implementations. The functions in the binary package have been tested to ensure they inline correctly and don't add unnecessary bounds checking. Change-Id: Ie10111ca6edb7c11e8e5e21c58a5748ae99b7f87 Reviewed-on: https://go-review.googlesource.com/134375 Run-TryBot: Lynn Boger TryBot-Result: Gobot Gobot Reviewed-by: Michael Munday --- src/cmd/link/internal/ld/lib.go | 20 -------------------- src/cmd/link/internal/ppc64/asm.go | 12 ++++++------ src/compress/zlib/writer.go | 12 +++--------- src/image/png/writer.go | 17 +++++------------ 4 files changed, 14 insertions(+), 47 deletions(-) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 5e99149d2549c..60124e32128cf 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1757,26 +1757,6 @@ func addsection(arch *sys.Arch, seg *sym.Segment, name string, rwx int) *sym.Sec return sect } -func Le16(b []byte) uint16 { - return uint16(b[0]) | uint16(b[1])<<8 -} - -func Le32(b []byte) uint32 { - return uint32(b[0]) | uint32(b[1])<<8 | uint32(b[2])<<16 | uint32(b[3])<<24 -} - -func Le64(b []byte) uint64 { - return uint64(Le32(b)) | uint64(Le32(b[4:]))<<32 -} - -func Be16(b []byte) uint16 { - return uint16(b[0])<<8 | uint16(b[1]) -} - -func Be32(b []byte) uint32 { - return uint32(b[0])<<24 | uint32(b[1])<<16 | uint32(b[2])<<8 | uint32(b[3]) -} - type chain struct { sym *sym.Symbol up *chain diff --git a/src/cmd/link/internal/ppc64/asm.go b/src/cmd/link/internal/ppc64/asm.go index 9445fbebcb8d5..3e833b686eaa1 100644 --- a/src/cmd/link/internal/ppc64/asm.go +++ b/src/cmd/link/internal/ppc64/asm.go @@ -716,9 +716,9 @@ func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 // overflow depends on the instruction var o1 uint32 if ctxt.Arch.ByteOrder == binary.BigEndian { - o1 = ld.Be32(s.P[r.Off-2:]) + o1 = binary.BigEndian.Uint32(s.P[r.Off-2:]) } else { - o1 = ld.Le32(s.P[r.Off:]) + o1 = binary.LittleEndian.Uint32(s.P[r.Off:]) } switch o1 >> 26 { case 24, // ori @@ -750,9 +750,9 @@ func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 // overflow depends on the instruction var o1 uint32 if ctxt.Arch.ByteOrder == binary.BigEndian { - o1 = ld.Be32(s.P[r.Off-2:]) + o1 = binary.BigEndian.Uint32(s.P[r.Off-2:]) } else { - o1 = ld.Le32(s.P[r.Off:]) + o1 = binary.LittleEndian.Uint32(s.P[r.Off:]) } switch o1 >> 26 { case 25, // oris @@ -774,9 +774,9 @@ func archrelocvariant(ctxt *ld.Link, r *sym.Reloc, s *sym.Symbol, t int64) int64 case sym.RV_POWER_DS: var o1 uint32 if ctxt.Arch.ByteOrder == binary.BigEndian { - o1 = uint32(ld.Be16(s.P[r.Off:])) + o1 = uint32(binary.BigEndian.Uint16(s.P[r.Off:])) } else { - o1 = uint32(ld.Le16(s.P[r.Off:])) + o1 = uint32(binary.LittleEndian.Uint16(s.P[r.Off:])) } if t&3 != 0 { ld.Errorf(s, "relocation for %s+%d is not aligned: %d", r.Sym.Name, r.Off, t) diff --git a/src/compress/zlib/writer.go b/src/compress/zlib/writer.go index a7b219467ee00..9986e3834d4d0 100644 --- a/src/compress/zlib/writer.go +++ b/src/compress/zlib/writer.go @@ -6,6 +6,7 @@ package zlib import ( "compress/flate" + "encoding/binary" "fmt" "hash" "hash/adler32" @@ -120,11 +121,7 @@ func (z *Writer) writeHeader() (err error) { } if z.dict != nil { // The next four bytes are the Adler-32 checksum of the dictionary. - checksum := adler32.Checksum(z.dict) - z.scratch[0] = uint8(checksum >> 24) - z.scratch[1] = uint8(checksum >> 16) - z.scratch[2] = uint8(checksum >> 8) - z.scratch[3] = uint8(checksum >> 0) + binary.BigEndian.PutUint32(z.scratch[:], adler32.Checksum(z.dict)) if _, err = z.w.Write(z.scratch[0:4]); err != nil { return err } @@ -190,10 +187,7 @@ func (z *Writer) Close() error { } checksum := z.digest.Sum32() // ZLIB (RFC 1950) is big-endian, unlike GZIP (RFC 1952). - z.scratch[0] = uint8(checksum >> 24) - z.scratch[1] = uint8(checksum >> 16) - z.scratch[2] = uint8(checksum >> 8) - z.scratch[3] = uint8(checksum >> 0) + binary.BigEndian.PutUint32(z.scratch[:], checksum) _, z.err = z.w.Write(z.scratch[0:4]) return z.err } diff --git a/src/image/png/writer.go b/src/image/png/writer.go index 49f1ad2e7fa1f..de8c28e919684 100644 --- a/src/image/png/writer.go +++ b/src/image/png/writer.go @@ -7,6 +7,7 @@ package png import ( "bufio" "compress/zlib" + "encoding/binary" "hash/crc32" "image" "image/color" @@ -62,14 +63,6 @@ const ( // compression level, although that is not implemented yet. ) -// Big-endian. -func writeUint32(b []uint8, u uint32) { - b[0] = uint8(u >> 24) - b[1] = uint8(u >> 16) - b[2] = uint8(u >> 8) - b[3] = uint8(u >> 0) -} - type opaquer interface { Opaque() bool } @@ -108,7 +101,7 @@ func (e *encoder) writeChunk(b []byte, name string) { e.err = UnsupportedError(name + " chunk is too large: " + strconv.Itoa(len(b))) return } - writeUint32(e.header[:4], n) + binary.BigEndian.PutUint32(e.header[:4], n) e.header[4] = name[0] e.header[5] = name[1] e.header[6] = name[2] @@ -116,7 +109,7 @@ func (e *encoder) writeChunk(b []byte, name string) { crc := crc32.NewIEEE() crc.Write(e.header[4:8]) crc.Write(b) - writeUint32(e.footer[:4], crc.Sum32()) + binary.BigEndian.PutUint32(e.footer[:4], crc.Sum32()) _, e.err = e.w.Write(e.header[:8]) if e.err != nil { @@ -131,8 +124,8 @@ func (e *encoder) writeChunk(b []byte, name string) { func (e *encoder) writeIHDR() { b := e.m.Bounds() - writeUint32(e.tmp[0:4], uint32(b.Dx())) - writeUint32(e.tmp[4:8], uint32(b.Dy())) + binary.BigEndian.PutUint32(e.tmp[0:4], uint32(b.Dx())) + binary.BigEndian.PutUint32(e.tmp[4:8], uint32(b.Dy())) // Set bit depth and color type. switch e.cb { case cbG8: From ef7212e2cfc786e5b81a0d3ac55371628177e013 Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Mon, 28 May 2018 17:15:11 +0300 Subject: [PATCH 0343/1663] cmd/compile: use yyerrorl(n.Pos, ...) in typecheckdef n.Pos.IsKnown() is not needed because it is performed in setlineno. toolstash-check passed. Updates #19683. Change-Id: I34d6a0e6dc9970679d99e8f3424f289ebf1e86ba Reviewed-on: https://go-review.googlesource.com/114915 Run-TryBot: Yury Smolsky TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/gc/typecheck.go | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index bb78d8bf73d8d..c2b84541852b5 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -3640,25 +3640,22 @@ func typecheckdeftype(n *Node) { } func typecheckdef(n *Node) { - lno := lineno - setlineno(n) + lno := setlineno(n) if n.Op == ONONAME { if !n.Diag() { n.SetDiag(true) - if n.Pos.IsKnown() { - lineno = n.Pos - } // Note: adderrorname looks for this string and // adds context about the outer expression - yyerror("undefined: %v", n.Sym) + yyerrorl(lineno, "undefined: %v", n.Sym) } - + lineno = lno return } if n.Walkdef() == 1 { + lineno = lno return } @@ -3701,20 +3698,19 @@ func typecheckdef(n *Node) { e := n.Name.Defn n.Name.Defn = nil if e == nil { - lineno = n.Pos Dump("typecheckdef nil defn", n) - yyerror("xxx") + yyerrorl(n.Pos, "xxx") } e = typecheck(e, Erv) if Isconst(e, CTNIL) { - yyerror("const initializer cannot be nil") + yyerrorl(n.Pos, "const initializer cannot be nil") goto ret } if e.Type != nil && e.Op != OLITERAL || !e.isGoConst() { if !e.Diag() { - yyerror("const initializer %v is not a constant", e) + yyerrorl(n.Pos, "const initializer %v is not a constant", e) e.SetDiag(true) } @@ -3724,12 +3720,12 @@ func typecheckdef(n *Node) { t := n.Type if t != nil { if !okforconst[t.Etype] { - yyerror("invalid constant type %v", t) + yyerrorl(n.Pos, "invalid constant type %v", t) goto ret } if !e.Type.IsUntyped() && !eqtype(t, e.Type) { - yyerror("cannot use %L as type %v in const initializer", e, t) + yyerrorl(n.Pos, "cannot use %L as type %v in const initializer", e, t) goto ret } From 13de5e7f7f664011b2c8ecf9b97956a6023e2a4e Mon Sep 17 00:00:00 2001 From: Brian Kessler Date: Tue, 14 Aug 2018 16:39:13 -0600 Subject: [PATCH 0344/1663] math/bits: add extended precision Add, Sub, Mul, Div Port math/big pure go versions of add-with-carry, subtract-with-borrow, full-width multiply, and full-width divide. Updates #24813 Change-Id: Ifae5d2f6ee4237137c9dcba931f69c91b80a4b1c Reviewed-on: https://go-review.googlesource.com/123157 Reviewed-by: Robert Griesemer Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot --- src/math/bits/bits.go | 194 +++++++++++++++++++++++++++ src/math/bits/bits_test.go | 266 +++++++++++++++++++++++++++++++++++++ 2 files changed, 460 insertions(+) diff --git a/src/math/bits/bits.go b/src/math/bits/bits.go index 989baacc13fc1..58cf52d2a7458 100644 --- a/src/math/bits/bits.go +++ b/src/math/bits/bits.go @@ -328,3 +328,197 @@ func Len64(x uint64) (n int) { } return n + int(len8tab[x]) } + +// --- Add with carry --- + +// Add returns the sum with carry of x, y and carry: sum = x + y + carry. +// The carry input must be 0 or 1; otherwise the behavior is undefined. +// The carryOut output is guaranteed to be 0 or 1. +func Add(x, y, carry uint) (sum, carryOut uint) { + yc := y + carry + sum = x + yc + if sum < x || yc < y { + carryOut = 1 + } + return +} + +// Add32 returns the sum with carry of x, y and carry: sum = x + y + carry. +// The carry input must be 0 or 1; otherwise the behavior is undefined. +// The carryOut output is guaranteed to be 0 or 1. +func Add32(x, y, carry uint32) (sum, carryOut uint32) { + yc := y + carry + sum = x + yc + if sum < x || yc < y { + carryOut = 1 + } + return +} + +// Add64 returns the sum with carry of x, y and carry: sum = x + y + carry. +// The carry input must be 0 or 1; otherwise the behavior is undefined. +// The carryOut output is guaranteed to be 0 or 1. +func Add64(x, y, carry uint64) (sum, carryOut uint64) { + yc := y + carry + sum = x + yc + if sum < x || yc < y { + carryOut = 1 + } + return +} + +// --- Subtract with borrow --- + +// Sub returns the difference of x, y and borrow: diff = x - y - borrow. +// The borrow input must be 0 or 1; otherwise the behavior is undefined. +// The borrowOut output is guaranteed to be 0 or 1. +func Sub(x, y, borrow uint) (diff, borrowOut uint) { + yb := y + borrow + diff = x - yb + if diff > x || yb < y { + borrowOut = 1 + } + return +} + +// Sub32 returns the difference of x, y and borrow, diff = x - y - borrow. +// The borrow input must be 0 or 1; otherwise the behavior is undefined. +// The borrowOut output is guaranteed to be 0 or 1. +func Sub32(x, y, borrow uint32) (diff, borrowOut uint32) { + yb := y + borrow + diff = x - yb + if diff > x || yb < y { + borrowOut = 1 + } + return +} + +// Sub64 returns the difference of x, y and borrow: diff = x - y - borrow. +// The borrow input must be 0 or 1; otherwise the behavior is undefined. +// The borrowOut output is guaranteed to be 0 or 1. +func Sub64(x, y, borrow uint64) (diff, borrowOut uint64) { + yb := y + borrow + diff = x - yb + if diff > x || yb < y { + borrowOut = 1 + } + return +} + +// --- Full-width multiply --- + +// Mul returns the full-width product of x and y: (hi, lo) = x * y +// with the product bits' upper half returned in hi and the lower +// half returned in lo. +func Mul(x, y uint) (hi, lo uint) { + if UintSize == 32 { + h, l := Mul32(uint32(x), uint32(y)) + return uint(h), uint(l) + } + h, l := Mul64(uint64(x), uint64(y)) + return uint(h), uint(l) +} + +// Mul32 returns the 64-bit product of x and y: (hi, lo) = x * y +// with the product bits' upper half returned in hi and the lower +// half returned in lo. +func Mul32(x, y uint32) (hi, lo uint32) { + tmp := uint64(x) * uint64(y) + hi, lo = uint32(tmp>>32), uint32(tmp) + return +} + +// Mul64 returns the 128-bit product of x and y: (hi, lo) = x * y +// with the product bits' upper half returned in hi and the lower +// half returned in lo. +func Mul64(x, y uint64) (hi, lo uint64) { + const mask32 = 1<<32 - 1 + x0 := x & mask32 + x1 := x >> 32 + y0 := y & mask32 + y1 := y >> 32 + w0 := x0 * y0 + t := x1*y0 + w0>>32 + w1 := t & mask32 + w2 := t >> 32 + w1 += x0 * y1 + hi = x1*y1 + w2 + w1>>32 + lo = x * y + return +} + +// --- Full-width divide --- + +// Div returns the quotient and remainder of (hi, lo) divided by y: +// quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper +// half in parameter hi and the lower half in parameter lo. +// hi must be < y otherwise the behavior is undefined (the quotient +// won't fit into quo). +func Div(hi, lo, y uint) (quo, rem uint) { + if UintSize == 32 { + q, r := Div32(uint32(hi), uint32(lo), uint32(y)) + return uint(q), uint(r) + } + q, r := Div64(uint64(hi), uint64(lo), uint64(y)) + return uint(q), uint(r) +} + +// Div32 returns the quotient and remainder of (hi, lo) divided by y: +// quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper +// half in parameter hi and the lower half in parameter lo. +// hi must be < y otherwise the behavior is undefined (the quotient +// won't fit into quo). +func Div32(hi, lo, y uint32) (quo, rem uint32) { + z := uint64(hi)<<32 | uint64(lo) + quo, rem = uint32(z/uint64(y)), uint32(z%uint64(y)) + return +} + +// Div64 returns the quotient and remainder of (hi, lo) divided by y: +// quo = (hi, lo)/y, rem = (hi, lo)%y with the dividend bits' upper +// half in parameter hi and the lower half in parameter lo. +// hi must be < y otherwise the behavior is undefined (the quotient +// won't fit into quo). +func Div64(hi, lo, y uint64) (quo, rem uint64) { + const ( + two32 = 1 << 32 + mask32 = two32 - 1 + ) + if hi >= y { + return 1<<64 - 1, 1<<64 - 1 + } + + s := uint(LeadingZeros64(y)) + y <<= s + + yn1 := y >> 32 + yn0 := y & mask32 + un32 := hi<>(64-s) + un10 := lo << s + un1 := un10 >> 32 + un0 := un10 & mask32 + q1 := un32 / yn1 + rhat := un32 - q1*yn1 + + for q1 >= two32 || q1*yn0 > two32*rhat+un1 { + q1-- + rhat += yn1 + if rhat >= two32 { + break + } + } + + un21 := un32*two32 + un1 - q1*y + q0 := un21 / yn1 + rhat = un21 - q0*yn1 + + for q0 >= two32 || q0*yn0 > two32*rhat+un0 { + q0-- + rhat += yn1 + if rhat >= two32 { + break + } + } + + return q1*two32 + q0, (un21*two32 + un0 - q0*y) >> s +} diff --git a/src/math/bits/bits_test.go b/src/math/bits/bits_test.go index 5c34f6dbf7f84..bd6b618f3557d 100644 --- a/src/math/bits/bits_test.go +++ b/src/math/bits/bits_test.go @@ -705,6 +705,272 @@ func TestLen(t *testing.T) { } } +const ( + _M = 1< Date: Thu, 9 Aug 2018 17:54:43 -0400 Subject: [PATCH 0345/1663] cmd/go/testdata/script: fix typos in test comments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2a55cda76f1074b997349dfd6e001dc7277faade Reviewed-on: https://go-review.googlesource.com/134655 Reviewed-by: Daniel Martí --- src/cmd/go/testdata/script/list_bad_import.txt | 2 +- src/cmd/go/testdata/script/mod_list_bad_import.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/testdata/script/list_bad_import.txt b/src/cmd/go/testdata/script/list_bad_import.txt index ba66b0937f84a..3d9cac0d5f549 100644 --- a/src/cmd/go/testdata/script/list_bad_import.txt +++ b/src/cmd/go/testdata/script/list_bad_import.txt @@ -47,7 +47,7 @@ stdout error stdout incomplete -# The pattern "all" should match only packages that acutally exist, +# The pattern "all" should match only packages that actually exist, # ignoring those whose existence is merely implied by imports. go list -e -f '{{.ImportPath}}' all stdout example.com/direct diff --git a/src/cmd/go/testdata/script/mod_list_bad_import.txt b/src/cmd/go/testdata/script/mod_list_bad_import.txt index 258eb6a56711c..8a66e0b72a0a5 100644 --- a/src/cmd/go/testdata/script/mod_list_bad_import.txt +++ b/src/cmd/go/testdata/script/mod_list_bad_import.txt @@ -47,7 +47,7 @@ stdout error stdout incomplete -# The pattern "all" should match only packages that acutally exist, +# The pattern "all" should match only packages that actually exist, # ignoring those whose existence is merely implied by imports. go list -e -f '{{.ImportPath}} {{.Error}}' all stdout example.com/direct From 023dbb188dda6aa49ccc41c8e38f2703700b3f5a Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 7 Sep 2018 12:53:52 -0700 Subject: [PATCH 0346/1663] cmd/link: don't pass all linker args when testing flag Some linker flags can actually be input files, which can cause misleading errors when doing the trial link, which can cause the linker to incorrectly decide that the flag is not supported, which can cause the link to fail. Fixes #27510 Updates #27110 Updates #27293 Change-Id: I70c1e913cee3c813e7b267bf779bcff26d4d194a Reviewed-on: https://go-review.googlesource.com/134057 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Lynn Boger Reviewed-by: Damien Neil --- src/cmd/link/internal/ld/lib.go | 53 ++++++++++++++++++++++++++++++-- src/cmd/link/internal/ld/util.go | 10 ++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/src/cmd/link/internal/ld/lib.go b/src/cmd/link/internal/ld/lib.go index 60124e32128cf..7029ba19c63ea 100644 --- a/src/cmd/link/internal/ld/lib.go +++ b/src/cmd/link/internal/ld/lib.go @@ -1379,9 +1379,58 @@ func linkerFlagSupported(linker, flag string) bool { } }) + flagsWithNextArgSkip := []string{ + "-F", + "-l", + "-L", + "-framework", + "-Wl,-framework", + "-Wl,-rpath", + "-Wl,-undefined", + } + flagsWithNextArgKeep := []string{ + "-arch", + "-isysroot", + "--sysroot", + "-target", + } + prefixesToKeep := []string{ + "-f", + "-m", + "-p", + "-Wl,", + "-arch", + "-isysroot", + "--sysroot", + "-target", + } + var flags []string - flags = append(flags, ldflag...) - flags = append(flags, strings.Fields(*flagExtldflags)...) + keep := false + skip := false + extldflags := strings.Fields(*flagExtldflags) + for _, f := range append(extldflags, ldflag...) { + if keep { + flags = append(flags, f) + keep = false + } else if skip { + skip = false + } else if f == "" || f[0] != '-' { + } else if contains(flagsWithNextArgSkip, f) { + skip = true + } else if contains(flagsWithNextArgKeep, f) { + flags = append(flags, f) + keep = true + } else { + for _, p := range prefixesToKeep { + if strings.HasPrefix(f, p) { + flags = append(flags, f) + break + } + } + } + } + flags = append(flags, flag, "trivial.c") cmd := exec.Command(linker, flags...) diff --git a/src/cmd/link/internal/ld/util.go b/src/cmd/link/internal/ld/util.go index b80e6106ba03e..b5b02296a14d2 100644 --- a/src/cmd/link/internal/ld/util.go +++ b/src/cmd/link/internal/ld/util.go @@ -89,3 +89,13 @@ var start = time.Now() func elapsed() float64 { return time.Since(start).Seconds() } + +// contains reports whether v is in s. +func contains(s []string, v string) bool { + for _, x := range s { + if x == v { + return true + } + } + return false +} From dc3680865a880e4f24ad40474b27c8ca276d8e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Tue, 11 Sep 2018 22:09:00 +0200 Subject: [PATCH 0347/1663] encoding/json: more tests to cover decoding edge cases MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The overall coverage of the json package goes up from 90.8% to 91.3%. While at it, apply two minor code simplifications found while inspecting the HTML coverage report. Change-Id: I0fba968afeedc813b1385e4bde72d93b878854d7 Reviewed-on: https://go-review.googlesource.com/134735 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/vet/all/whitelist/all.txt | 1 + src/encoding/json/decode.go | 23 ++++++++++------------- src/encoding/json/decode_test.go | 19 ++++++++++++++++++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/cmd/vet/all/whitelist/all.txt b/src/cmd/vet/all/whitelist/all.txt index b974d21c6ae23..5425f84fc6e36 100644 --- a/src/cmd/vet/all/whitelist/all.txt +++ b/src/cmd/vet/all/whitelist/all.txt @@ -24,6 +24,7 @@ runtime/asm_ARCHSUFF.s: [GOARCH] gcWriteBarrier: function gcWriteBarrier missing // in bad situations that vet can also detect statically. encoding/json/decode_test.go: struct field m has json tag but is not exported encoding/json/decode_test.go: struct field m2 has json tag but is not exported +encoding/json/decode_test.go: struct field s has json tag but is not exported encoding/json/tagkey_test.go: struct field tag `:"BadFormat"` not compatible with reflect.StructTag.Get: bad syntax for struct tag key runtime/testdata/testprog/deadlock.go: unreachable code runtime/testdata/testprog/deadlock.go: unreachable code diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go index 82dc78083a7ca..dbff2d063137a 100644 --- a/src/encoding/json/decode.go +++ b/src/encoding/json/decode.go @@ -533,8 +533,7 @@ func (d *decodeState) array(v reflect.Value) error { d.saveError(&UnmarshalTypeError{Value: "array", Type: v.Type(), Offset: int64(d.off)}) d.skip() return nil - case reflect.Array: - case reflect.Slice: + case reflect.Array, reflect.Slice: break } @@ -871,18 +870,16 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool if item[0] != '"' { if fromQuoted { d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) - } else { - var val string - switch item[0] { - case 'n': - val = "null" - case 't', 'f': - val = "bool" - default: - val = "number" - } - d.saveError(&UnmarshalTypeError{Value: val, Type: v.Type(), Offset: int64(d.readIndex())}) + return nil + } + val := "number" + switch item[0] { + case 'n': + val = "null" + case 't', 'f': + val = "bool" } + d.saveError(&UnmarshalTypeError{Value: val, Type: v.Type(), Offset: int64(d.readIndex())}) return nil } s, ok := unquoteBytes(item) diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go index defa97e40fdd0..5fbe67a7063b3 100644 --- a/src/encoding/json/decode_test.go +++ b/src/encoding/json/decode_test.go @@ -445,6 +445,7 @@ var unmarshalTests = []unmarshalTest{ {in: `{"X": "foo", "Y"}`, err: &SyntaxError{"invalid character '}' after object key", 17}}, {in: `[1, 2, 3+]`, err: &SyntaxError{"invalid character '+' after array element", 9}}, {in: `{"X":12x}`, err: &SyntaxError{"invalid character 'x' after object key:value pair", 8}, useNumber: true}, + {in: `[2, 3`, err: &SyntaxError{msg: "unexpected end of JSON input", Offset: 5}}, // raw value errors {in: "\x01 42", err: &SyntaxError{"invalid character '\\x01' looking for beginning of value", 1}}, @@ -460,6 +461,7 @@ var unmarshalTests = []unmarshalTest{ {in: `[1, 2, 3]`, ptr: new([3]int), out: [3]int{1, 2, 3}}, {in: `[1, 2, 3]`, ptr: new([1]int), out: [1]int{1}}, {in: `[1, 2, 3]`, ptr: new([5]int), out: [5]int{1, 2, 3, 0, 0}}, + {in: `[1, 2, 3]`, ptr: new(MustNotUnmarshalJSON), err: errors.New("MustNotUnmarshalJSON was used")}, // empty array to interface test {in: `[]`, ptr: new([]interface{}), out: []interface{}{}}, @@ -826,6 +828,7 @@ var unmarshalTests = []unmarshalTest{ {in: `{"B": "False"}`, ptr: new(B), err: errors.New(`json: invalid use of ,string struct tag, trying to unmarshal "False" into bool`)}, {in: `{"B": "null"}`, ptr: new(B), out: B{false}}, {in: `{"B": "nul"}`, ptr: new(B), err: errors.New(`json: invalid use of ,string struct tag, trying to unmarshal "nul" into bool`)}, + {in: `{"B": [2, 3]}`, ptr: new(B), err: errors.New(`json: invalid use of ,string struct tag, trying to unmarshal unquoted value into bool`)}, // additional tests for disallowUnknownFields { @@ -894,6 +897,18 @@ var unmarshalTests = []unmarshalTest{ ptr: new(mapStringToStringData), err: &UnmarshalTypeError{Value: "number", Type: reflect.TypeOf(""), Offset: 21, Struct: "mapStringToStringData", Field: "data"}, }, + + // trying to decode JSON arrays or objects via TextUnmarshaler + { + in: `[1, 2, 3]`, + ptr: new(MustNotUnmarshalText), + err: &UnmarshalTypeError{Value: "array", Type: reflect.TypeOf(&MustNotUnmarshalText{}), Offset: 1}, + }, + { + in: `{"foo": "bar"}`, + ptr: new(MustNotUnmarshalText), + err: &UnmarshalTypeError{Value: "object", Type: reflect.TypeOf(&MustNotUnmarshalText{}), Offset: 1}, + }, } func TestMarshal(t *testing.T) { @@ -1955,10 +1970,12 @@ type unexportedFields struct { Name string m map[string]interface{} `json:"-"` m2 map[string]interface{} `json:"abcd"` + + s []int `json:"-"` } func TestUnmarshalUnexported(t *testing.T) { - input := `{"Name": "Bob", "m": {"x": 123}, "m2": {"y": 456}, "abcd": {"z": 789}}` + input := `{"Name": "Bob", "m": {"x": 123}, "m2": {"y": 456}, "abcd": {"z": 789}, "s": [2, 3]}` want := &unexportedFields{Name: "Bob"} out := &unexportedFields{} From b2fcfc1a50fbd46556f7075f7f1fbf600b5c9e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 12 Sep 2018 09:26:31 +0200 Subject: [PATCH 0348/1663] encoding/json: use panics for phase errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Having these panic-like errors used to be ok, since they were used in the internal decoder state instead of passed around via return parameters. Recently, the decoder was rewritten to use explicit error returns instead. This error is a terrible fit for error returns; a handful of functions must return an error because of it, and their callers must check for an error that should never happen. This is precisely what panics are for, so use them. The test coverage of the package goes up from 91.3% to 91.6%, and performance is unaffected. We can also get rid of some unnecessary verbosity in the code. name old time/op new time/op delta CodeDecoder-4 27.5ms ± 1% 27.5ms ± 1% ~ (p=0.937 n=6+6) Change-Id: I01033b3f5b7c0cf0985082fa272754f96bf6353c Reviewed-on: https://go-review.googlesource.com/134835 Run-TryBot: Daniel Martí Run-TryBot: Joe Tsai TryBot-Result: Gobot Gobot Reviewed-by: Joe Tsai --- src/encoding/json/decode.go | 110 +++++++++++++++--------------------- 1 file changed, 44 insertions(+), 66 deletions(-) diff --git a/src/encoding/json/decode.go b/src/encoding/json/decode.go index dbff2d063137a..cab4616ba337b 100644 --- a/src/encoding/json/decode.go +++ b/src/encoding/json/decode.go @@ -11,7 +11,6 @@ import ( "bytes" "encoding" "encoding/base64" - "errors" "fmt" "reflect" "strconv" @@ -280,10 +279,10 @@ func (d *decodeState) readIndex() int { return d.off - 1 } -// errPhase is used for errors that should not happen unless -// there is a bug in the JSON decoder or something is editing -// the data slice while the decoder executes. -var errPhase = errors.New("JSON decoder out of sync - data changing underfoot?") +// phasePanicMsg is used as a panic message when we end up with something that +// shouldn't happen. It can indicate a bug in the JSON decoder, or that +// something is editing the data slice while the decoder executes. +const phasePanicMsg = "JSON decoder out of sync - data changing underfoot?" func (d *decodeState) init(data []byte) *decodeState { d.data = data @@ -365,7 +364,7 @@ func (d *decodeState) scanWhile(op int) { func (d *decodeState) value(v reflect.Value) error { switch d.opcode { default: - return errPhase + panic(phasePanicMsg) case scanBeginArray: if v.IsValid() { @@ -407,26 +406,23 @@ type unquotedValue struct{} // quoted string literal or literal null into an interface value. // If it finds anything other than a quoted string literal or null, // valueQuoted returns unquotedValue{}. -func (d *decodeState) valueQuoted() (interface{}, error) { +func (d *decodeState) valueQuoted() interface{} { switch d.opcode { default: - return nil, errPhase + panic(phasePanicMsg) case scanBeginArray, scanBeginObject: d.skip() d.scanNext() case scanBeginLiteral: - v, err := d.literalInterface() - if err != nil { - return nil, err - } + v := d.literalInterface() switch v.(type) { case nil, string: - return v, nil + return v } } - return unquotedValue{}, nil + return unquotedValue{} } // indirect walks down v allocating pointers as needed, @@ -520,10 +516,7 @@ func (d *decodeState) array(v reflect.Value) error { case reflect.Interface: if v.NumMethod() == 0 { // Decoding into nil interface? Switch to non-reflect code. - ai, err := d.arrayInterface() - if err != nil { - return err - } + ai := d.arrayInterface() v.Set(reflect.ValueOf(ai)) return nil } @@ -583,7 +576,7 @@ func (d *decodeState) array(v reflect.Value) error { break } if d.opcode != scanArrayValue { - return errPhase + panic(phasePanicMsg) } } @@ -627,10 +620,7 @@ func (d *decodeState) object(v reflect.Value) error { // Decoding into nil interface? Switch to non-reflect code. if v.Kind() == reflect.Interface && v.NumMethod() == 0 { - oi, err := d.objectInterface() - if err != nil { - return err - } + oi := d.objectInterface() v.Set(reflect.ValueOf(oi)) return nil } @@ -679,7 +669,7 @@ func (d *decodeState) object(v reflect.Value) error { break } if d.opcode != scanBeginLiteral { - return errPhase + panic(phasePanicMsg) } // Read key. @@ -688,7 +678,7 @@ func (d *decodeState) object(v reflect.Value) error { item := d.data[start:d.readIndex()] key, ok := unquoteBytes(item) if !ok { - return errPhase + panic(phasePanicMsg) } // Figure out field corresponding to key. @@ -752,16 +742,12 @@ func (d *decodeState) object(v reflect.Value) error { d.scanWhile(scanSkipSpace) } if d.opcode != scanObjectKey { - return errPhase + panic(phasePanicMsg) } d.scanWhile(scanSkipSpace) if destring { - q, err := d.valueQuoted() - if err != nil { - return err - } - switch qv := q.(type) { + switch qv := d.valueQuoted().(type) { case nil: if err := d.literalStore(nullLiteral, subv, false); err != nil { return err @@ -826,7 +812,7 @@ func (d *decodeState) object(v reflect.Value) error { break } if d.opcode != scanObjectValue { - return errPhase + panic(phasePanicMsg) } d.errorContext = originalErrorContext @@ -887,7 +873,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool if fromQuoted { return fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()) } - return errPhase + panic(phasePanicMsg) } return ut.UnmarshalText(s) } @@ -938,7 +924,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool if fromQuoted { return fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()) } - return errPhase + panic(phasePanicMsg) } switch v.Kind() { default: @@ -970,7 +956,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool if fromQuoted { return fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type()) } - return errPhase + panic(phasePanicMsg) } s := string(item) switch v.Kind() { @@ -1031,24 +1017,24 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool // but they avoid the weight of reflection in this common case. // valueInterface is like value but returns interface{} -func (d *decodeState) valueInterface() (val interface{}, err error) { +func (d *decodeState) valueInterface() (val interface{}) { switch d.opcode { default: - err = errPhase + panic(phasePanicMsg) case scanBeginArray: - val, err = d.arrayInterface() + val = d.arrayInterface() d.scanNext() case scanBeginObject: - val, err = d.objectInterface() + val = d.objectInterface() d.scanNext() case scanBeginLiteral: - val, err = d.literalInterface() + val = d.literalInterface() } return } // arrayInterface is like array but returns []interface{}. -func (d *decodeState) arrayInterface() ([]interface{}, error) { +func (d *decodeState) arrayInterface() []interface{} { var v = make([]interface{}, 0) for { // Look ahead for ] - can only happen on first iteration. @@ -1057,11 +1043,7 @@ func (d *decodeState) arrayInterface() ([]interface{}, error) { break } - vi, err := d.valueInterface() - if err != nil { - return nil, err - } - v = append(v, vi) + v = append(v, d.valueInterface()) // Next token must be , or ]. if d.opcode == scanSkipSpace { @@ -1071,14 +1053,14 @@ func (d *decodeState) arrayInterface() ([]interface{}, error) { break } if d.opcode != scanArrayValue { - return nil, errPhase + panic(phasePanicMsg) } } - return v, nil + return v } // objectInterface is like object but returns map[string]interface{}. -func (d *decodeState) objectInterface() (map[string]interface{}, error) { +func (d *decodeState) objectInterface() map[string]interface{} { m := make(map[string]interface{}) for { // Read opening " of string key or closing }. @@ -1088,7 +1070,7 @@ func (d *decodeState) objectInterface() (map[string]interface{}, error) { break } if d.opcode != scanBeginLiteral { - return nil, errPhase + panic(phasePanicMsg) } // Read string key. @@ -1097,7 +1079,7 @@ func (d *decodeState) objectInterface() (map[string]interface{}, error) { item := d.data[start:d.readIndex()] key, ok := unquote(item) if !ok { - return nil, errPhase + panic(phasePanicMsg) } // Read : before value. @@ -1105,16 +1087,12 @@ func (d *decodeState) objectInterface() (map[string]interface{}, error) { d.scanWhile(scanSkipSpace) } if d.opcode != scanObjectKey { - return nil, errPhase + panic(phasePanicMsg) } d.scanWhile(scanSkipSpace) // Read value. - vi, err := d.valueInterface() - if err != nil { - return nil, err - } - m[key] = vi + m[key] = d.valueInterface() // Next token must be , or }. if d.opcode == scanSkipSpace { @@ -1124,16 +1102,16 @@ func (d *decodeState) objectInterface() (map[string]interface{}, error) { break } if d.opcode != scanObjectValue { - return nil, errPhase + panic(phasePanicMsg) } } - return m, nil + return m } // literalInterface consumes and returns a literal from d.data[d.off-1:] and // it reads the following byte ahead. The first byte of the literal has been // read already (that's how the caller knows it's a literal). -func (d *decodeState) literalInterface() (interface{}, error) { +func (d *decodeState) literalInterface() interface{} { // All bytes inside literal return scanContinue op code. start := d.readIndex() d.scanWhile(scanContinue) @@ -1142,27 +1120,27 @@ func (d *decodeState) literalInterface() (interface{}, error) { switch c := item[0]; c { case 'n': // null - return nil, nil + return nil case 't', 'f': // true, false - return c == 't', nil + return c == 't' case '"': // string s, ok := unquote(item) if !ok { - return nil, errPhase + panic(phasePanicMsg) } - return s, nil + return s default: // number if c != '-' && (c < '0' || c > '9') { - return nil, errPhase + panic(phasePanicMsg) } n, err := d.convertNumber(string(item)) if err != nil { d.saveError(err) } - return n, nil + return n } } From d5377c2026b18e1307c6fd243ece98afc6330b71 Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Wed, 12 Sep 2018 01:43:09 +0000 Subject: [PATCH 0349/1663] test: fix the wrong test of math.Copysign(c, -1) for arm64 The CL 132915 added the wrong codegen test for math.Copysign(c, -1), it should test that AND is not emitted. This CL fixes this error. Change-Id: Ida1d3d54ebfc7f238abccbc1f70f914e1b5bfd91 Reviewed-on: https://go-review.googlesource.com/134815 Reviewed-by: Giovanni Bajo Reviewed-by: Cherry Zhang Run-TryBot: Giovanni Bajo TryBot-Result: Gobot Gobot --- test/codegen/math.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/codegen/math.go b/test/codegen/math.go index 99335d2efc79a..3d5f0917ef7bc 100644 --- a/test/codegen/math.go +++ b/test/codegen/math.go @@ -74,7 +74,7 @@ func copysign(a, b, c float64) { // amd64:"BTSQ\t[$]63" // s390x:"LNDFR\t",-"MOVD\t" (no integer load/store) // ppc64le:"FCPSGN" - // arm64:"ORR\t[$]-9223372036854775808" + // arm64:"ORR", -"AND" sink64[1] = math.Copysign(c, -1) // Like math.Copysign(c, -1), but with integer operations. Useful From e7f5f3eca42a98340e4eb4fc5d490a9aa4bd5054 Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Mon, 10 Sep 2018 02:22:48 +0000 Subject: [PATCH 0350/1663] cmd/internal/obj/arm64: add error report for invalid base register The current assembler accepts the non-integer register as the base register, which should be an illegal combination. Add the test cases. Change-Id: Ia21596bbb5b1e212e34bd3a170748ae788860422 Reviewed-on: https://go-review.googlesource.com/134575 Reviewed-by: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- src/cmd/asm/internal/asm/testdata/arm64error.s | 2 ++ src/cmd/internal/obj/arm64/asm7.go | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/cmd/asm/internal/asm/testdata/arm64error.s b/src/cmd/asm/internal/asm/testdata/arm64error.s index bbdce479c517b..357db80222d8d 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64error.s +++ b/src/cmd/asm/internal/asm/testdata/arm64error.s @@ -110,4 +110,6 @@ TEXT errors(SB),$0 FLDPD (R1), (F2, F2) // ERROR "constrained unpredictable behavior" FLDPS (R2), (F3, F3) // ERROR "constrained unpredictable behavior" FSTPD (R1, R2), (R0) // ERROR "invalid register pair" + FMOVS (F2), F0 // ERROR "illegal combination" + FMOVD F0, (F1) // ERROR "illegal combination" RET diff --git a/src/cmd/internal/obj/arm64/asm7.go b/src/cmd/internal/obj/arm64/asm7.go index 09ffc5dccf72e..46fdcdcf7dff5 100644 --- a/src/cmd/internal/obj/arm64/asm7.go +++ b/src/cmd/internal/obj/arm64/asm7.go @@ -1426,6 +1426,10 @@ func (c *ctxt7) aclass(a *obj.Addr) int { return C_LIST case obj.TYPE_MEM: + // The base register should be an integer register. + if int16(REG_F0) <= a.Reg && a.Reg <= int16(REG_V31) { + break + } switch a.Name { case obj.NAME_EXTERN, obj.NAME_STATIC: if a.Sym == nil { @@ -2968,7 +2972,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { } case 22: /* movT (R)O!,R; movT O(R)!, R -> ldrT */ - if p.As != AFMOVS && p.As != AFMOVD && p.From.Reg != REGSP && p.From.Reg == p.To.Reg { + if p.From.Reg != REGSP && p.From.Reg == p.To.Reg { c.ctxt.Diag("constrained unpredictable behavior: %v", p) } @@ -2986,7 +2990,7 @@ func (c *ctxt7) asmout(p *obj.Prog, o *Optab, out []uint32) { o1 |= ((uint32(v) & 0x1FF) << 12) | (uint32(p.From.Reg&31) << 5) | uint32(p.To.Reg&31) case 23: /* movT R,(R)O!; movT O(R)!, R -> strT */ - if p.As != AFMOVS && p.As != AFMOVD && p.To.Reg != REGSP && p.From.Reg == p.To.Reg { + if p.To.Reg != REGSP && p.From.Reg == p.To.Reg { c.ctxt.Diag("constrained unpredictable behavior: %v", p) } From a0fad982b17b8c49c8567867160dee9f021cf1ba Mon Sep 17 00:00:00 2001 From: Lynn Boger Date: Mon, 27 Aug 2018 16:34:53 -0400 Subject: [PATCH 0351/1663] internal/bytealg: implement bytes.Count in asm for ppc64x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds an asm implementation for the Count function in ppc64x. The Go code that manipulates a byte at a time is especially inefficient on ppc64x, so an asm implementation is a significant improvement. bytes: name old time/op new time/op delta CountSingle/10-8 23.1ns ± 0% 18.6ns ± 0% -19.48% (p=1.000 n=1+1) CountSingle/32-8 60.4ns ± 0% 19.0ns ± 0% -68.54% (p=1.000 n=1+1) CountSingle/4K-8 7.29µs ± 0% 0.45µs ± 0% -93.80% (p=1.000 n=1+1) CountSingle/4M-8 7.49ms ± 0% 0.45ms ± 0% -93.97% (p=1.000 n=1+1) CountSingle/64M-8 127ms ± 0% 9ms ± 0% -92.53% (p=1.000 n=1+1) html: name old time/op new time/op delta Escape-8 57.5µs ± 0% 36.1µs ± 0% -37.13% (p=1.000 n=1+1) EscapeNone-8 20.0µs ± 0% 2.0µs ± 0% -90.14% (p=1.000 n=1+1) Change-Id: Iadbf422c0e9a37b47d2d95fb8c778420f3aabb58 Reviewed-on: https://go-review.googlesource.com/131695 Run-TryBot: Lynn Boger TryBot-Result: Gobot Gobot Reviewed-by: Michael Munday --- src/internal/bytealg/count_generic.go | 2 +- src/internal/bytealg/count_native.go | 2 +- src/internal/bytealg/count_ppc64x.s | 97 +++++++++++++++++++++++++++ 3 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 src/internal/bytealg/count_ppc64x.s diff --git a/src/internal/bytealg/count_generic.go b/src/internal/bytealg/count_generic.go index a763b3bc616be..e24b2b7fa076f 100644 --- a/src/internal/bytealg/count_generic.go +++ b/src/internal/bytealg/count_generic.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build !amd64,!arm64 +// +build !amd64,!arm64,!ppc64le,!ppc64 package bytealg diff --git a/src/internal/bytealg/count_native.go b/src/internal/bytealg/count_native.go index a62c4cb5c0963..e6a91b3c0e265 100644 --- a/src/internal/bytealg/count_native.go +++ b/src/internal/bytealg/count_native.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build amd64 arm64 +// +build amd64 arm64 ppc64le ppc64 package bytealg diff --git a/src/internal/bytealg/count_ppc64x.s b/src/internal/bytealg/count_ppc64x.s new file mode 100644 index 0000000000000..7abdce1954f56 --- /dev/null +++ b/src/internal/bytealg/count_ppc64x.s @@ -0,0 +1,97 @@ +// Copyright 2018 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. + +// +build ppc64le ppc64 + +#include "go_asm.h" +#include "textflag.h" + +TEXT ·Count(SB), NOSPLIT|NOFRAME, $0-40 + MOVD b_base+0(FP), R3 // R3 = byte array pointer + MOVD b_len+8(FP), R4 // R4 = length + MOVBZ c+24(FP), R5 // R5 = byte + MOVD $ret+32(FP), R14 // R14 = &ret + BR countbytebody<>(SB) + +TEXT ·CountString(SB), NOSPLIT|NOFRAME, $0-32 + MOVD s_base+0(FP), R3 // R3 = string + MOVD s_len+8(FP), R4 // R4 = length + MOVBZ c+16(FP), R5 // R5 = byte + MOVD $ret+24(FP), R14 // R14 = &ret + BR countbytebody<>(SB) + +// R3: addr of string +// R4: len of string +// R5: byte to count +// R14: addr for return value +// endianness shouldn't matter since we are just counting and order +// is irrelevant +TEXT countbytebody<>(SB), NOSPLIT|NOFRAME, $0-0 + DCBT (R3) // Prepare cache line. + MOVD R0, R18 // byte count + MOVD R3, R19 // Save base address for calculating the index later. + MOVD R4, R16 + + MOVD R5, R6 + RLDIMI $8, R6, $48, R6 + RLDIMI $16, R6, $32, R6 + RLDIMI $32, R6, $0, R6 // fill reg with the byte to count + + VSPLTISW $3, V4 // used for shift + MTVRD R6, V1 // move compare byte + VSPLTB $7, V1, V1 // replicate byte across V1 + + CMPU R4, $32 // Check if it's a small string (<32 bytes) + BLT tail // Jump to the small string case + XXLXOR VS37, VS37, VS37 // clear V5 (aka VS37) to use as accumulator + +cmploop: + LXVW4X (R3), VS32 // load bytes from string + + // when the bytes match, the corresonding byte contains all 1s + VCMPEQUB V1, V0, V2 // compare bytes + VPOPCNTD V2, V3 // each double word contains its count + VADDUDM V3, V5, V5 // accumulate bit count in each double word + ADD $16, R3, R3 // increment pointer + SUB $16, R16, R16 // remaining bytes + CMP R16, $16 // at least 16 remaining? + BGE cmploop + VSRD V5, V4, V5 // shift by 3 to convert bits to bytes + VSLDOI $8, V5, V5, V6 // get the double word values from vector + MFVSRD V5, R9 + MFVSRD V6, R10 + ADD R9, R10, R9 + ADD R9, R18, R18 + +tail: + CMP R16, $8 // 8 bytes left? + BLT small + + MOVD (R3), R12 // load 8 bytes + CMPB R12, R6, R17 // compare bytes + POPCNTD R17, R15 // bit count + SRD $3, R15, R15 // byte count + ADD R15, R18, R18 // add to byte count + +next1: + ADD $8, R3, R3 + SUB $8, R16, R16 // remaining bytes + BR tail + +small: + CMP $0, R16 // any remaining + BEQ done + MOVBZ (R3), R12 // check each remaining byte + CMP R12, R5 + BNE next2 + ADD $1, R18 + +next2: + SUB $1, R16 + ADD $1, R3 // inc address + BR small + +done: + MOVD R18, (R14) // return count + RET From 178a609fed5fba5abaeead485f7b2795b8c4ea3c Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Mon, 10 Sep 2018 01:05:09 -0600 Subject: [PATCH 0352/1663] runtime: convert initial timediv quotient increments to bitsets At the very beginning of timediv, inside a for loop, we reduce the base value by at most (1<<31)-1, while incrementing the quotient result by 1< TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/runtime/runtime1.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/runtime/runtime1.go b/src/runtime/runtime1.go index d5f78badedad6..85a9ba252197a 100644 --- a/src/runtime/runtime1.go +++ b/src/runtime/runtime1.go @@ -416,7 +416,9 @@ func timediv(v int64, div int32, rem *int32) int32 { for bit := 30; bit >= 0; bit-- { if v >= int64(div)<= int64(div) { From c56dcd5fc7cd926b9d4a9c96a699a12f832317f1 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Tue, 11 Sep 2018 14:27:41 +0200 Subject: [PATCH 0353/1663] cmd/dist: make raceDetectorSupported an exact copy of cmd/internal/sys.RaceDetectorSupported The comment states that cmd/internal/sys.RaceDetectorSupported is a copy, so make the two identical. No functional difference, since ppce64le is only supported on linux anyway. Change-Id: Id3e4d445fb700b9b3bb53bf15ea05b8911b4f95e Reviewed-on: https://go-review.googlesource.com/134595 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/dist/test.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/cmd/dist/test.go b/src/cmd/dist/test.go index 4cd854773f21d..2d7f7bd2f9abf 100644 --- a/src/cmd/dist/test.go +++ b/src/cmd/dist/test.go @@ -1469,8 +1469,10 @@ func (t *tester) packageHasBenchmarks(pkg string) bool { // because cmd/dist has to be buildable by Go 1.4. func raceDetectorSupported(goos, goarch string) bool { switch goos { - case "linux", "darwin", "freebsd", "netbsd", "windows": + case "linux": return goarch == "amd64" || goarch == "ppc64le" + case "darwin", "freebsd", "netbsd", "windows": + return goarch == "amd64" default: return false } From b07f60b97ff5ea9ae4cf21b549e9d25ccd695f36 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 12 Sep 2018 14:18:45 +0200 Subject: [PATCH 0354/1663] runtime: use functions from mem_bsd.go on Darwin The implementations of the functions in mem_darwin.go is identical to the ones defined in mem_bsd.go for all other BSD-like GOOSes. Also use them on Darwin. Change-Id: Ie7c170c1a50666475e79599471081cd85f0837ad Reviewed-on: https://go-review.googlesource.com/134875 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/runtime/mem_bsd.go | 2 +- src/runtime/mem_darwin.go | 62 --------------------------------------- 2 files changed, 1 insertion(+), 63 deletions(-) delete mode 100644 src/runtime/mem_darwin.go diff --git a/src/runtime/mem_bsd.go b/src/runtime/mem_bsd.go index cc70e806ead1f..13065b61d48e8 100644 --- a/src/runtime/mem_bsd.go +++ b/src/runtime/mem_bsd.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build dragonfly freebsd nacl netbsd openbsd solaris +// +build darwin dragonfly freebsd nacl netbsd openbsd solaris package runtime diff --git a/src/runtime/mem_darwin.go b/src/runtime/mem_darwin.go deleted file mode 100644 index 75c59f9cdd77e..0000000000000 --- a/src/runtime/mem_darwin.go +++ /dev/null @@ -1,62 +0,0 @@ -// 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. - -package runtime - -import "unsafe" - -// Don't split the stack as this function may be invoked without a valid G, -// which prevents us from allocating more stack. -//go:nosplit -func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer { - v, err := mmap(nil, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_PRIVATE, -1, 0) - if err != 0 { - return nil - } - mSysStatInc(sysStat, n) - return v -} - -func sysUnused(v unsafe.Pointer, n uintptr) { - // Linux's MADV_DONTNEED is like BSD's MADV_FREE. - madvise(v, n, _MADV_FREE) -} - -func sysUsed(v unsafe.Pointer, n uintptr) { -} - -// Don't split the stack as this function may be invoked without a valid G, -// which prevents us from allocating more stack. -//go:nosplit -func sysFree(v unsafe.Pointer, n uintptr, sysStat *uint64) { - mSysStatDec(sysStat, n) - munmap(v, n) -} - -func sysFault(v unsafe.Pointer, n uintptr) { - mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE|_MAP_FIXED, -1, 0) -} - -func sysReserve(v unsafe.Pointer, n uintptr) unsafe.Pointer { - p, err := mmap(v, n, _PROT_NONE, _MAP_ANON|_MAP_PRIVATE, -1, 0) - if err != 0 { - return nil - } - return p -} - -const ( - _ENOMEM = 12 -) - -func sysMap(v unsafe.Pointer, n uintptr, sysStat *uint64) { - mSysStatInc(sysStat, n) - p, err := mmap(v, n, _PROT_READ|_PROT_WRITE, _MAP_ANON|_MAP_FIXED|_MAP_PRIVATE, -1, 0) - if err == _ENOMEM { - throw("runtime: out of memory") - } - if p != v || err != 0 { - throw("runtime: cannot map pages in arena address space") - } -} From 21f3d5816d5dc3556a3ac9a5c91b915848be254b Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Wed, 12 Sep 2018 10:41:29 -0400 Subject: [PATCH 0355/1663] cmd/go: avoid type names in __debug__modinfo__ variable injected in package main If we use the name 'string' to refer to the built-in type, that name can be shadowed by a local declaration. Use a string constant instead, but keep the init function to populate it so that //go:linkname will still work properly. Fixes #27584. Change-Id: I850cad6663e566f70fd123107d2e4e742c93b450 Reviewed-on: https://go-review.googlesource.com/134915 Reviewed-by: Ian Lance Taylor --- src/cmd/go/internal/modload/build.go | 7 ++++++- src/cmd/go/testdata/script/mod_string_alias.txt | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 src/cmd/go/testdata/script/mod_string_alias.txt diff --git a/src/cmd/go/internal/modload/build.go b/src/cmd/go/internal/modload/build.go index cebb802db9fc9..06636c4f4ff42 100644 --- a/src/cmd/go/internal/modload/build.go +++ b/src/cmd/go/internal/modload/build.go @@ -232,11 +232,16 @@ func findModule(target, path string) module.Version { } func ModInfoProg(info string) []byte { + // Inject a variable with the debug information as runtime/debug.modinfo, + // but compile it in package main so that it is specific to the binary. + // Populate it in an init func so that it will work with go:linkname, + // but use a string constant instead of the name 'string' in case + // package main shadows the built-in 'string' with some local declaration. return []byte(fmt.Sprintf(` package main import _ "unsafe" //go:linkname __debug_modinfo__ runtime/debug.modinfo - var __debug_modinfo__ string + var __debug_modinfo__ = "" func init() { __debug_modinfo__ = %q } diff --git a/src/cmd/go/testdata/script/mod_string_alias.txt b/src/cmd/go/testdata/script/mod_string_alias.txt new file mode 100644 index 0000000000000..5c3d4287cc876 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_string_alias.txt @@ -0,0 +1,14 @@ +[short] skip + +env GO111MODULE=on + +go mod init golang.org/issue/27584 + +go build . + +-- main.go -- +package main + +type string = []int + +func main() {} From de28555c0b33fcaa02779d55ea9289135280ae9f Mon Sep 17 00:00:00 2001 From: erifan01 Date: Mon, 7 May 2018 08:08:30 +0000 Subject: [PATCH 0356/1663] internal/bytealg: optimize Equal on arm64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently the 16-byte loop chunk16_loop is implemented with NEON instructions LD1, VMOV and VCMEQ. Using scalar instructions LDP and CMP to achieve this loop can reduce the number of clock cycles. For cases where the length of strings are between 4 to 15 bytes, loading the last 8 or 4 bytes at a time to reduce the number of comparisons. Benchmarks: name old time/op new time/op delta Equal/0-8 5.51ns ± 0% 5.84ns ±14% ~ (p=0.246 n=7+8) Equal/1-8 10.5ns ± 0% 10.5ns ± 0% ~ (all equal) Equal/6-8 14.0ns ± 0% 12.5ns ± 0% -10.71% (p=0.000 n=8+8) Equal/9-8 13.5ns ± 0% 12.5ns ± 0% -7.41% (p=0.000 n=8+8) Equal/15-8 15.5ns ± 0% 12.5ns ± 0% -19.35% (p=0.000 n=8+8) Equal/16-8 14.0ns ± 0% 13.0ns ± 0% -7.14% (p=0.000 n=8+8) Equal/20-8 16.5ns ± 0% 16.0ns ± 0% -3.03% (p=0.000 n=8+8) Equal/32-8 16.5ns ± 0% 15.3ns ± 0% -7.27% (p=0.000 n=8+8) Equal/4K-8 552ns ± 0% 553ns ± 0% ~ (p=0.315 n=8+8) Equal/4M-8 1.13ms ±23% 1.20ms ±27% ~ (p=0.442 n=8+8) Equal/64M-8 32.9ms ± 0% 32.6ms ± 0% -1.15% (p=0.000 n=8+8) CompareBytesEqual-8 12.0ns ± 0% 12.0ns ± 0% ~ (all equal) Change-Id: If317ecdcc98e31883d37fd7d42b113b548c5bd2a Reviewed-on: https://go-review.googlesource.com/112496 Reviewed-by: Cherry Zhang Run-TryBot: Cherry Zhang --- src/internal/bytealg/equal_arm64.s | 44 +++++++++++++++++++----------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/internal/bytealg/equal_arm64.s b/src/internal/bytealg/equal_arm64.s index 30abd980c5166..dd4840dae1339 100644 --- a/src/internal/bytealg/equal_arm64.s +++ b/src/internal/bytealg/equal_arm64.s @@ -67,6 +67,7 @@ TEXT runtime·memequal_varlen(SB),NOSPLIT,$40-17 CMP R3, R4 BEQ eq MOVD 8(R26), R5 // compiler stores size at offset 8 in the closure + CBZ R5, eq MOVD R3, 8(RSP) MOVD R4, 16(RSP) MOVD R5, 24(RSP) @@ -119,30 +120,41 @@ chunk16: CBZ R3, tail ADD R3, R0, R6 // end of chunks chunk16_loop: - VLD1.P (R0), [V0.D2] - VLD1.P (R2), [V1.D2] - VCMEQ V0.D2, V1.D2, V2.D2 + LDP.P 16(R0), (R4, R5) + LDP.P 16(R2), (R7, R9) + EOR R4, R7 + CBNZ R7, not_equal + EOR R5, R9 + CBNZ R9, not_equal CMP R0, R6 - VMOV V2.D[0], R4 - VMOV V2.D[1], R5 - CBZ R4, not_equal - CBZ R5, not_equal BNE chunk16_loop AND $0xf, R1, R1 CBZ R1, equal tail: // special compare of tail with length < 16 TBZ $3, R1, lt_8 - MOVD.P 8(R0), R4 - MOVD.P 8(R2), R5 - CMP R4, R5 - BNE not_equal + MOVD (R0), R4 + MOVD (R2), R5 + EOR R4, R5 + CBNZ R5, not_equal + SUB $8, R1, R6 // offset of the last 8 bytes + MOVD (R0)(R6), R4 + MOVD (R2)(R6), R5 + EOR R4, R5 + CBNZ R5, not_equal + B equal lt_8: TBZ $2, R1, lt_4 - MOVWU.P 4(R0), R4 - MOVWU.P 4(R2), R5 - CMP R4, R5 - BNE not_equal + MOVWU (R0), R4 + MOVWU (R2), R5 + EOR R4, R5 + CBNZ R5, not_equal + SUB $4, R1, R6 // offset of the last 4 bytes + MOVWU (R0)(R6), R4 + MOVWU (R2)(R6), R5 + EOR R4, R5 + CBNZ R5, not_equal + B equal lt_4: TBZ $1, R1, lt_2 MOVHU.P 2(R0), R4 @@ -150,7 +162,7 @@ lt_4: CMP R4, R5 BNE not_equal lt_2: - TBZ $0, R1, equal + TBZ $0, R1, equal one: MOVBU (R0), R4 MOVBU (R2), R5 From 1b9374450bbf3372f18915deb58ed11a072eef4a Mon Sep 17 00:00:00 2001 From: Emmanuel T Odeke Date: Wed, 12 Sep 2018 12:22:42 -0600 Subject: [PATCH 0357/1663] runtime: regression test for semasleep indefinite hang A regression test in which: for a program that invokes semasleep, we send non-terminal signals such as SIGIO. Since the signal wakes up pthread_cond_timedwait_relative_np, after CL 133655, we should only re-spin for the amount of time left, instead of re-spinning with the original duration which would cause an indefinite spin. Updates #27520 Change-Id: I744a6d04cf8923bc4e13649446aff5e42b7de5d8 Reviewed-on: https://go-review.googlesource.com/135015 Run-TryBot: Emmanuel Odeke TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/runtime/semasleep_test.go | 88 +++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 src/runtime/semasleep_test.go diff --git a/src/runtime/semasleep_test.go b/src/runtime/semasleep_test.go new file mode 100644 index 0000000000000..4a8b4db338c74 --- /dev/null +++ b/src/runtime/semasleep_test.go @@ -0,0 +1,88 @@ +// Copyright 2018 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. + +//+build !nacl,!windows,!js + +package runtime_test + +import ( + "internal/testenv" + "io/ioutil" + "os" + "os/exec" + "path/filepath" + "syscall" + "testing" + "time" +) + +// Issue #27250. Spurious wakeups to pthread_cond_timedwait_relative_np +// shouldn't cause semasleep to retry with the same timeout which would +// cause indefinite spinning. +func TestSpuriousWakeupsNeverHangSemasleep(t *testing.T) { + testenv.MustHaveGoBuild(t) + tempDir, err := ioutil.TempDir("", "issue-27250") + if err != nil { + t.Fatalf("Failed to create the temp directory: %v", err) + } + defer os.RemoveAll(tempDir) + + repro := ` + package main + + import "time" + + func main() { + <-time.After(1 * time.Second) + } + ` + mainPath := filepath.Join(tempDir, "main.go") + if err := ioutil.WriteFile(mainPath, []byte(repro), 0644); err != nil { + t.Fatalf("Failed to create temp file for repro.go: %v", err) + } + binaryPath := filepath.Join(tempDir, "binary") + + // Build the binary so that we can send the signal to its PID. + out, err := exec.Command(testenv.GoToolPath(t), "build", "-o", binaryPath, mainPath).CombinedOutput() + if err != nil { + t.Fatalf("Failed to compile the binary: err: %v\nOutput: %s\n", err, out) + } + if err := os.Chmod(binaryPath, 0755); err != nil { + t.Fatalf("Failed to chmod binary: %v", err) + } + + // Now run the binary. + cmd := exec.Command(binaryPath) + if err := cmd.Start(); err != nil { + t.Fatalf("Failed to start command: %v", err) + } + doneCh := make(chan error, 1) + go func() { + doneCh <- cmd.Wait() + }() + + // With the repro running, we can continuously send to it + // a non-terminal signal such as SIGIO, to spuriously + // wakeup pthread_cond_timedwait_relative_np. + unfixedTimer := time.NewTimer(2 * time.Second) + for { + select { + case <-time.After(200 * time.Millisecond): + // Send the pesky signal that toggles spinning + // indefinitely if #27520 is not fixed. + cmd.Process.Signal(syscall.SIGIO) + + case <-unfixedTimer.C: + t.Error("Program failed to return on time and has to be killed, issue #27520 still exists") + cmd.Process.Signal(syscall.SIGKILL) + return + + case err := <-doneCh: + if err != nil { + t.Fatalf("The program returned but unfortunately with an error: %v", err) + } + return + } + } +} From a2a3dd00c934fa15ad880ee5fe1f64308cbc73a7 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Wed, 12 Sep 2018 21:30:09 +0200 Subject: [PATCH 0358/1663] os: add ModeCharDevice to ModeType When masking FileInfo.Mode() from a character device with the ModeType mask, ModeCharDevice cannot be recovered. ModeCharDevice was added https://golang.org/cl/5531052, but nothing indicates why it was omitted from ModeType. Add it now. Fixes #27640 Change-Id: I52f56108b88b1b0a5bc6085c66c3c67e10600619 Reviewed-on: https://go-review.googlesource.com/135075 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- api/except.txt | 1 + src/os/types.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/api/except.txt b/api/except.txt index 850724196d249..9f7f3fe934ad4 100644 --- a/api/except.txt +++ b/api/except.txt @@ -3,6 +3,7 @@ pkg math/big, const MaxBase = 36 pkg math/big, type Word uintptr pkg net, func ListenUnixgram(string, *UnixAddr) (*UDPConn, error) pkg os, const ModeType = 2399141888 +pkg os, const ModeType = 2399666176 pkg os (linux-arm), const O_SYNC = 4096 pkg os (linux-arm-cgo), const O_SYNC = 4096 pkg syscall (darwin-386), const ImplementsGetwd = false diff --git a/src/os/types.go b/src/os/types.go index b0b7d8d94d620..4b6c084838b6b 100644 --- a/src/os/types.go +++ b/src/os/types.go @@ -57,7 +57,7 @@ const ( ModeIrregular // ?: non-regular file; nothing else is known about this file // Mask for the type bits. For regular files, none will be set. - ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice | ModeIrregular + ModeType = ModeDir | ModeSymlink | ModeNamedPipe | ModeSocket | ModeDevice | ModeCharDevice | ModeIrregular ModePerm FileMode = 0777 // Unix permission bits ) From 8149db4f64aa72407d8be2184d0b414b535cd124 Mon Sep 17 00:00:00 2001 From: erifan01 Date: Tue, 22 May 2018 06:58:32 +0000 Subject: [PATCH 0359/1663] cmd/compile: intrinsify math.RoundToEven and math.Abs on arm64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit math.RoundToEven can be done by one arm64 instruction FRINTND, intrinsify it to improve performance. The current pure Go implementation of the function Abs is translated into five instructions on arm64: str, ldr, and, str, ldr. The intrinsic implementation requires only one instruction, so in terms of performance, intrinsify it is worthwhile. Benchmarks: name old time/op new time/op delta Abs-8 3.50ns ± 0% 1.50ns ± 0% -57.14% (p=0.000 n=10+10) RoundToEven-8 9.26ns ± 0% 1.50ns ± 0% -83.80% (p=0.000 n=10+10) Change-Id: I9456b26ab282b544dfac0154fc86f17aed96ac3d Reviewed-on: https://go-review.googlesource.com/116535 Reviewed-by: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/arm64/ssa.go | 2 ++ src/cmd/compile/internal/gc/ssa.go | 4 +-- src/cmd/compile/internal/ssa/gen/ARM64.rules | 2 ++ src/cmd/compile/internal/ssa/gen/ARM64Ops.go | 2 ++ src/cmd/compile/internal/ssa/opGen.go | 28 ++++++++++++++++++++ src/cmd/compile/internal/ssa/rewriteARM64.go | 26 ++++++++++++++++++ test/codegen/math.go | 2 ++ 7 files changed, 64 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/arm64/ssa.go b/src/cmd/compile/internal/arm64/ssa.go index 192654158276d..ce6d32f536fea 100644 --- a/src/cmd/compile/internal/arm64/ssa.go +++ b/src/cmd/compile/internal/arm64/ssa.go @@ -698,6 +698,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { fallthrough case ssa.OpARM64MVN, ssa.OpARM64NEG, + ssa.OpARM64FABSD, ssa.OpARM64FMOVDfpgp, ssa.OpARM64FMOVDgpfp, ssa.OpARM64FNEGS, @@ -730,6 +731,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ssa.OpARM64CLZW, ssa.OpARM64FRINTAD, ssa.OpARM64FRINTMD, + ssa.OpARM64FRINTND, ssa.OpARM64FRINTPD, ssa.OpARM64FRINTZD: p := s.Prog(v.Op.Asm()) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index bb076f870849d..2ee966d890f85 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -3149,12 +3149,12 @@ func init() { func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return s.newValue1(ssa.OpRoundToEven, types.Types[TFLOAT64], args[0]) }, - sys.S390X) + sys.ARM64, sys.S390X) addF("math", "Abs", func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return s.newValue1(ssa.OpAbs, types.Types[TFLOAT64], args[0]) }, - sys.PPC64) + sys.ARM64, sys.PPC64) addF("math", "Copysign", func(s *state, n *Node, args []*ssa.Value) *ssa.Value { return s.newValue2(ssa.OpCopysign, types.Types[TFLOAT64], args[0], args[1]) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index 4c9d9a6f7a38f..b2ce875a057db 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -83,10 +83,12 @@ (Com8 x) -> (MVN x) // math package intrinsics +(Abs x) -> (FABSD x) (Sqrt x) -> (FSQRTD x) (Ceil x) -> (FRINTPD x) (Floor x) -> (FRINTMD x) (Round x) -> (FRINTAD x) +(RoundToEven x) -> (FRINTND x) (Trunc x) -> (FRINTZD x) // lowering rotates diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go index 43230fbf70faf..da078517d44fe 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go @@ -212,6 +212,7 @@ func init() { // unary ops {name: "MVN", argLength: 1, reg: gp11, asm: "MVN"}, // ^arg0 {name: "NEG", argLength: 1, reg: gp11, asm: "NEG"}, // -arg0 + {name: "FABSD", argLength: 1, reg: fp11, asm: "FABSD"}, // abs(arg0), float64 {name: "FNEGS", argLength: 1, reg: fp11, asm: "FNEGS"}, // -arg0, float32 {name: "FNEGD", argLength: 1, reg: fp11, asm: "FNEGD"}, // -arg0, float64 {name: "FSQRTD", argLength: 1, reg: fp11, asm: "FSQRTD"}, // sqrt(arg0), float64 @@ -424,6 +425,7 @@ func init() { // floating-point round to integral {name: "FRINTAD", argLength: 1, reg: fp11, asm: "FRINTAD"}, {name: "FRINTMD", argLength: 1, reg: fp11, asm: "FRINTMD"}, + {name: "FRINTND", argLength: 1, reg: fp11, asm: "FRINTND"}, {name: "FRINTPD", argLength: 1, reg: fp11, asm: "FRINTPD"}, {name: "FRINTZD", argLength: 1, reg: fp11, asm: "FRINTZD"}, diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 30c57874f6a17..b32dca410319a 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -1107,6 +1107,7 @@ const ( OpARM64LoweredMuluhilo OpARM64MVN OpARM64NEG + OpARM64FABSD OpARM64FNEGS OpARM64FNEGD OpARM64FSQRTD @@ -1277,6 +1278,7 @@ const ( OpARM64FCVTDS OpARM64FRINTAD OpARM64FRINTMD + OpARM64FRINTND OpARM64FRINTPD OpARM64FRINTZD OpARM64CSEL @@ -14658,6 +14660,19 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "FABSD", + argLen: 1, + asm: arm64.AFABSD, + reg: regInfo{ + inputs: []inputInfo{ + {0, 9223372034707292160}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 + }, + outputs: []outputInfo{ + {0, 9223372034707292160}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 + }, + }, + }, { name: "FNEGS", argLen: 1, @@ -16965,6 +16980,19 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "FRINTND", + argLen: 1, + asm: arm64.AFRINTND, + reg: regInfo{ + inputs: []inputInfo{ + {0, 9223372034707292160}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 + }, + outputs: []outputInfo{ + {0, 9223372034707292160}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 + }, + }, + }, { name: "FRINTPD", argLen: 1, diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index 1dcbd9348099a..2108452c03b5f 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -331,6 +331,8 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64XORshiftRA_0(v) case OpARM64XORshiftRL: return rewriteValueARM64_OpARM64XORshiftRL_0(v) + case OpAbs: + return rewriteValueARM64_OpAbs_0(v) case OpAdd16: return rewriteValueARM64_OpAdd16_0(v) case OpAdd32: @@ -747,6 +749,8 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpRound32F_0(v) case OpRound64F: return rewriteValueARM64_OpRound64F_0(v) + case OpRoundToEven: + return rewriteValueARM64_OpRoundToEven_0(v) case OpRsh16Ux16: return rewriteValueARM64_OpRsh16Ux16_0(v) case OpRsh16Ux32: @@ -29214,6 +29218,17 @@ func rewriteValueARM64_OpARM64XORshiftRL_0(v *Value) bool { } return false } +func rewriteValueARM64_OpAbs_0(v *Value) bool { + // match: (Abs x) + // cond: + // result: (FABSD x) + for { + x := v.Args[0] + v.reset(OpARM64FABSD) + v.AddArg(x) + return true + } +} func rewriteValueARM64_OpAdd16_0(v *Value) bool { // match: (Add16 x y) // cond: @@ -33407,6 +33422,17 @@ func rewriteValueARM64_OpRound64F_0(v *Value) bool { return true } } +func rewriteValueARM64_OpRoundToEven_0(v *Value) bool { + // match: (RoundToEven x) + // cond: + // result: (FRINTND x) + for { + x := v.Args[0] + v.reset(OpARM64FRINTND) + v.AddArg(x) + return true + } +} func rewriteValueARM64_OpRsh16Ux16_0(v *Value) bool { b := v.Block _ = b diff --git a/test/codegen/math.go b/test/codegen/math.go index 3d5f0917ef7bc..6afe1833459dd 100644 --- a/test/codegen/math.go +++ b/test/codegen/math.go @@ -32,6 +32,7 @@ func approx(x float64) { sink64[3] = math.Trunc(x) // s390x:"FIDBR\t[$]4" + // arm64:"FRINTND" sink64[4] = math.RoundToEven(x) } @@ -48,6 +49,7 @@ func sqrt(x float64) float64 { // Check that it's using integer registers func abs(x, y float64) { // amd64:"BTRQ\t[$]63" + // arm64:"FABSD\t" // s390x:"LPDFR\t",-"MOVD\t" (no integer load/store) // ppc64le:"FABS\t" sink64[0] = math.Abs(x) From 77e503a3224ada21cc84ab9078980a7d4230492a Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 12 Sep 2018 18:07:51 -0700 Subject: [PATCH 0360/1663] cmd/vet: avoid internal error for implicitly declared type switch vars MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For type switches using a short variable declaration of the form switch t := x.(type) { case T1: ... go/types doesn't declare the symbolic variable (t in this example) with the switch; thus such variables are not found in types.Info.Defs. Instead they are implicitly declared with each type switch case, and can be found in types.Info.Implicits. Adjust the shadowing code accordingly. Added a test case to verify that the issue is fixed, and a test case verifying that the shadowing code now considers implicitly declared variables introduces in type switch cases. While at it, also fixed the (internal) error reporting to provide more accurate information. Fixe #26725. Change-Id: If408ed9e692bf47c640f81de8f46bf5eb43415b0 Reviewed-on: https://go-review.googlesource.com/135117 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí Reviewed-by: Alan Donovan --- src/cmd/vet/main.go | 1 + src/cmd/vet/shadow.go | 9 +++------ src/cmd/vet/testdata/shadow.go | 32 ++++++++++++++++++++++++++++++++ src/cmd/vet/types.go | 24 ++++++++++++++++++++++-- 4 files changed, 58 insertions(+), 8 deletions(-) diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go index c50d4885a0787..646adf4d76d5f 100644 --- a/src/cmd/vet/main.go +++ b/src/cmd/vet/main.go @@ -467,6 +467,7 @@ type Package struct { path string defs map[*ast.Ident]types.Object uses map[*ast.Ident]types.Object + implicits map[ast.Node]types.Object selectors map[*ast.SelectorExpr]*types.Selection types map[ast.Expr]types.TypeAndValue spans map[types.Object]Span diff --git a/src/cmd/vet/shadow.go b/src/cmd/vet/shadow.go index 29c952fd8858e..47a48834bfcc0 100644 --- a/src/cmd/vet/shadow.go +++ b/src/cmd/vet/shadow.go @@ -86,14 +86,11 @@ func (s Span) contains(pos token.Pos) bool { return s.min <= pos && pos < s.max } -// growSpan expands the span for the object to contain the instance represented -// by the identifier. -func (pkg *Package) growSpan(ident *ast.Ident, obj types.Object) { +// growSpan expands the span for the object to contain the source range [pos, end). +func (pkg *Package) growSpan(obj types.Object, pos, end token.Pos) { if *strictShadowing { return // No need } - pos := ident.Pos() - end := ident.End() span, ok := pkg.spans[obj] if ok { if span.min > pos { @@ -232,7 +229,7 @@ func checkShadowing(f *File, ident *ast.Ident) { // the shadowing identifier. span, ok := f.pkg.spans[shadowed] if !ok { - f.Badf(ident.Pos(), "internal error: no range for %q", ident.Name) + f.Badf(shadowed.Pos(), "internal error: no range for %q", shadowed.Name()) return } if !span.contains(ident.Pos()) { diff --git a/src/cmd/vet/testdata/shadow.go b/src/cmd/vet/testdata/shadow.go index c55cb2772a9c6..d10fde2b811d0 100644 --- a/src/cmd/vet/testdata/shadow.go +++ b/src/cmd/vet/testdata/shadow.go @@ -57,3 +57,35 @@ func ShadowRead(f *os.File, buf []byte) (err error) { func one() int { return 1 } + +// Must not complain with an internal error for the +// implicitly declared type switch variable v. +func issue26725(x interface{}) int { + switch v := x.(type) { + case int, int32: + if v, ok := x.(int); ok { + return v + } + case int64: + return int(v) + } + return 0 +} + +// Verify that implicitly declared variables from +// type switches are considered in shadowing analysis. +func shadowTypeSwitch(a interface{}) { + switch t := a.(type) { + case int: + { + t := 0 // ERROR "declaration of .t. shadows declaration at shadow.go:78" + _ = t + } + _ = t + case uint: + { + t := uint(0) // OK because t is not mentioned later in this function + _ = t + } + } +} diff --git a/src/cmd/vet/types.go b/src/cmd/vet/types.go index 5f8e481e01b68..3ff4b5966de21 100644 --- a/src/cmd/vet/types.go +++ b/src/cmd/vet/types.go @@ -73,6 +73,7 @@ func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) []error { } pkg.defs = make(map[*ast.Ident]types.Object) pkg.uses = make(map[*ast.Ident]types.Object) + pkg.implicits = make(map[ast.Node]types.Object) pkg.selectors = make(map[*ast.SelectorExpr]*types.Selection) pkg.spans = make(map[types.Object]Span) pkg.types = make(map[ast.Expr]types.TypeAndValue) @@ -95,6 +96,7 @@ func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) []error { Types: pkg.types, Defs: pkg.defs, Uses: pkg.uses, + Implicits: pkg.implicits, } typesPkg, err := config.Check(pkg.path, fs, astFiles, info) if len(allErrors) == 0 && err != nil { @@ -103,10 +105,28 @@ func (pkg *Package) check(fs *token.FileSet, astFiles []*ast.File) []error { pkg.typesPkg = typesPkg // update spans for id, obj := range pkg.defs { - pkg.growSpan(id, obj) + // Ignore identifiers that don't denote objects + // (package names, symbolic variables such as t + // in t := x.(type) of type switch headers). + if obj != nil { + pkg.growSpan(obj, id.Pos(), id.End()) + } } for id, obj := range pkg.uses { - pkg.growSpan(id, obj) + pkg.growSpan(obj, id.Pos(), id.End()) + } + for node, obj := range pkg.implicits { + // A type switch with a short variable declaration + // such as t := x.(type) doesn't declare the symbolic + // variable (t in the example) at the switch header; + // instead a new variable t (with specific type) is + // declared implicitly for each case. Such variables + // are found in the types.Info.Implicits (not Defs) + // map. Add them here, assuming they are declared at + // the type cases' colon ":". + if cc, ok := node.(*ast.CaseClause); ok { + pkg.growSpan(obj, cc.Colon, cc.Colon) + } } return allErrors } From 691f5c34ad7b7d676644dd749bc4ddb5d20b90d0 Mon Sep 17 00:00:00 2001 From: erifan01 Date: Thu, 19 Jul 2018 09:55:17 +0000 Subject: [PATCH 0361/1663] strings, bytes: optimize function Index This change compares the first two characters instead of the first one, and if they match, the entire string is compared. Comparing the first two characters helps to filter out the case where the first character matches but the subsequent characters do not match, thereby improving the substring search speed in this case. Benchmarks with no effect or minimal impact (less than 5%) is not listed, the following are improved benchmarks: On arm64: strings: IndexPeriodic/IndexPeriodic16-8 172890.00ns +- 2% 124156.20ns +- 0% -28.19% (p=0.008 n=5+5) IndexPeriodic/IndexPeriodic32-8 78092.80ns +- 0% 65138.60ns +- 0% -16.59% (p=0.008 n=5+5) IndexPeriodic/IndexPeriodic64-8 42322.20ns +- 0% 34661.60ns +- 0% -18.10% (p=0.008 n=5+5) bytes: IndexPeriodic/IndexPeriodic16-8 183468.20ns +- 6% 123759.00ns +- 0% -32.54% (p=0.008 n=5+5) IndexPeriodic/IndexPeriodic32-8 84776.40ns +- 0% 63907.80ns +- 0% -24.62% (p=0.008 n=5+5) IndexPeriodic/IndexPeriodic64-8 45835.60ns +- 0% 34194.20ns +- 0% -25.40% (p=0.008 n=5+5) On amd64: strings: IndexPeriodic/IndexPeriodic8-16 219499.00ns +- 0% 178123.40ns +- 0% -18.85% (p=0.008 n=5+5) IndexPeriodic/IndexPeriodic16-16 109760.20ns +- 0% 88957.80ns +- 0% -18.95% (p=0.008 n=5+5) IndexPeriodic/IndexPeriodic32-16 54943.00ns +- 0% 44573.80ns +- 0% -18.87% (p=0.008 n=5+5) IndexPeriodic/IndexPeriodic64-16 29804.80ns +- 0% 24417.80ns +- 0% -18.07% (p=0.008 n=5+5) bytes: IndexPeriodic/IndexPeriodic8-16 226592.60ns +- 0% 181183.20ns +- 0% -20.04% (p=0.008 n=5+5) IndexPeriodic/IndexPeriodic16-16 111432.60ns +- 0% 90634.60ns +- 0% -18.66% (p=0.008 n=5+5) IndexPeriodic/IndexPeriodic32-16 55640.60ns +- 0% 45433.00ns +- 0% -18.35% (p=0.008 n=5+5) IndexPeriodic/IndexPeriodic64-16 30833.00ns +- 0% 24784.20ns +- 0% -19.62% (p=0.008 n=5+5) Change-Id: I2d9e7e138d29e960d20a203eb74dc2ec976a9d71 Reviewed-on: https://go-review.googlesource.com/131177 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/bytes/bytes.go | 28 +++++++++++++++------------- src/strings/strings.go | 28 +++++++++++++++------------- 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go index 77a7ce98e077c..876fa3c1edda6 100644 --- a/src/bytes/bytes.go +++ b/src/bytes/bytes.go @@ -849,21 +849,22 @@ func Index(s, sep []byte) int { if len(s) <= bytealg.MaxBruteForce { return bytealg.Index(s, sep) } - c := sep[0] + c0 := sep[0] + c1 := sep[1] i := 0 - t := s[:len(s)-n+1] + t := len(s) - n + 1 fails := 0 - for i < len(t) { - if t[i] != c { + for i < t { + if s[i] != c0 { // IndexByte is faster than bytealg.Index, so use it as long as // we're not getting lots of false positives. - o := IndexByte(t[i:], c) + o := IndexByte(s[i:t], c0) if o < 0 { return -1 } i += o } - if Equal(s[i:i+n], sep) { + if s[i+1] == c1 && Equal(s[i:i+n], sep) { return i } fails++ @@ -879,24 +880,25 @@ func Index(s, sep []byte) int { } return -1 } - c := sep[0] + c0 := sep[0] + c1 := sep[1] i := 0 fails := 0 - t := s[:len(s)-n+1] - for i < len(t) { - if t[i] != c { - o := IndexByte(t[i:], c) + t := len(s) - n + 1 + for i < t { + if s[i] != c0 { + o := IndexByte(s[i:t], c0) if o < 0 { break } i += o } - if Equal(s[i:i+n], sep) { + if s[i+1] == c1 && Equal(s[i:i+n], sep) { return i } i++ fails++ - if fails >= 4+i>>4 && i < len(t) { + if fails >= 4+i>>4 && i < t { // Give up on IndexByte, it isn't skipping ahead // far enough to be better than Rabin-Karp. // Experiments (using IndexPeriodic) suggest diff --git a/src/strings/strings.go b/src/strings/strings.go index df95715ec859a..26aceda2121b1 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -947,21 +947,22 @@ func Index(s, substr string) int { if len(s) <= bytealg.MaxBruteForce { return bytealg.IndexString(s, substr) } - c := substr[0] + c0 := substr[0] + c1 := substr[1] i := 0 - t := s[:len(s)-n+1] + t := len(s) - n + 1 fails := 0 - for i < len(t) { - if t[i] != c { + for i < t { + if s[i] != c0 { // IndexByte is faster than bytealg.IndexString, so use it as long as // we're not getting lots of false positives. - o := IndexByte(t[i:], c) + o := IndexByte(s[i:t], c0) if o < 0 { return -1 } i += o } - if s[i:i+n] == substr { + if s[i+1] == c1 && s[i:i+n] == substr { return i } fails++ @@ -977,24 +978,25 @@ func Index(s, substr string) int { } return -1 } - c := substr[0] + c0 := substr[0] + c1 := substr[1] i := 0 - t := s[:len(s)-n+1] + t := len(s) - n + 1 fails := 0 - for i < len(t) { - if t[i] != c { - o := IndexByte(t[i:], c) + for i < t { + if s[i] != c0 { + o := IndexByte(s[i:t], c0) if o < 0 { return -1 } i += o } - if s[i:i+n] == substr { + if s[i+1] == c1 && s[i:i+n] == substr { return i } i++ fails++ - if fails >= 4+i>>4 && i < len(t) { + if fails >= 4+i>>4 && i < t { // See comment in ../bytes/bytes_generic.go. j := indexRabinKarp(s[i:], substr) if j < 0 { From 8c610aa633167aef27964e314dda35a87d3da58b Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Thu, 13 Sep 2018 11:15:30 -0400 Subject: [PATCH 0362/1663] regexp: fix incorrect name in Match doc comment Change-Id: I628aad9a3abe9cc0c3233f476960e53bd291eca9 Reviewed-on: https://go-review.googlesource.com/135235 Reviewed-by: Ralph Corderoy Reviewed-by: Ian Lance Taylor --- src/regexp/regexp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/regexp/regexp.go b/src/regexp/regexp.go index 61ed9c5059f35..89bb975ac1fd6 100644 --- a/src/regexp/regexp.go +++ b/src/regexp/regexp.go @@ -469,7 +469,7 @@ func MatchString(pattern string, s string) (matched bool, err error) { return re.MatchString(s), nil } -// MatchString reports whether the byte slice b +// Match reports whether the byte slice b // contains any match of the regular expression pattern. // More complicated queries need to use Compile and the full Regexp interface. func Match(pattern string, b []byte) (matched bool, err error) { From 7d27e87d35b4c8948a498711cb34c1f73917535b Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 29 Jun 2018 10:39:44 -0700 Subject: [PATCH 0363/1663] path/filepath: rewrite walkSymlinks Rather than try to work around Clean and Join on intermediate steps, which can remove ".." components unexpectedly, just do everything in walkSymlinks. Use a single loop over path components. Fixes #23444 Change-Id: I4f15e50d0df32349cc4fd55e3d224ec9ab064379 Reviewed-on: https://go-review.googlesource.com/121676 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Alex Brainman --- src/path/filepath/path_test.go | 14 +++ src/path/filepath/symlink.go | 190 ++++++++++++++++++--------------- 2 files changed, 117 insertions(+), 87 deletions(-) diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index e50ee97bcb3f7..a221a3d4fac64 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -771,6 +771,18 @@ var EvalSymlinksTestDirs = []EvalSymlinksTest{ {"test/link1", "../test"}, {"test/link2", "dir"}, {"test/linkabs", "/"}, + {"test/link4", "../test2"}, + {"test2", "test/dir"}, + // Issue 23444. + {"src", ""}, + {"src/pool", ""}, + {"src/pool/test", ""}, + {"src/versions", ""}, + {"src/versions/current", "../../version"}, + {"src/versions/v1", ""}, + {"src/versions/v1/modules", ""}, + {"src/versions/v1/modules/test", "../../../pool/test"}, + {"version", "src/versions/v1"}, } var EvalSymlinksTests = []EvalSymlinksTest{ @@ -784,6 +796,8 @@ var EvalSymlinksTests = []EvalSymlinksTest{ {"test/dir/link3", "."}, {"test/link2/link3/test", "test"}, {"test/linkabs", "/"}, + {"test/link4/..", "test"}, + {"src/versions/current/modules/test", "src/pool/test"}, } // simpleJoin builds a file name from the directory and path. diff --git a/src/path/filepath/symlink.go b/src/path/filepath/symlink.go index 824aee4e49056..57dcbf314d125 100644 --- a/src/path/filepath/symlink.go +++ b/src/path/filepath/symlink.go @@ -10,109 +10,125 @@ import ( "runtime" ) -// isRoot returns true if path is root of file system -// (`/` on unix and `/`, `\`, `c:\` or `c:/` on windows). -func isRoot(path string) bool { - if runtime.GOOS != "windows" { - return path == "/" - } - switch len(path) { - case 1: - return os.IsPathSeparator(path[0]) - case 3: - return path[1] == ':' && os.IsPathSeparator(path[2]) +func walkSymlinks(path string) (string, error) { + volLen := volumeNameLen(path) + if volLen < len(path) && os.IsPathSeparator(path[volLen]) { + volLen++ } - return false -} + vol := path[:volLen] + dest := vol + linksWalked := 0 + for start, end := volLen, volLen; start < len(path); start = end { + for start < len(path) && os.IsPathSeparator(path[start]) { + start++ + } + end = start + for end < len(path) && !os.IsPathSeparator(path[end]) { + end++ + } -// isDriveLetter returns true if path is Windows drive letter (like "c:"). -func isDriveLetter(path string) bool { - if runtime.GOOS != "windows" { - return false - } - return len(path) == 2 && path[1] == ':' -} + // On Windows, "." can be a symlink. + // We look it up, and use the value if it is absolute. + // If not, we just return ".". + isWindowsDot := runtime.GOOS == "windows" && path[volumeNameLen(path):] == "." -func walkLink(path string, linksWalked *int) (newpath string, islink bool, err error) { - if *linksWalked > 255 { - return "", false, errors.New("EvalSymlinks: too many links") - } - fi, err := os.Lstat(path) - if err != nil { - return "", false, err - } - if fi.Mode()&os.ModeSymlink == 0 { - return path, false, nil - } - newpath, err = os.Readlink(path) - if err != nil { - return "", false, err - } - *linksWalked++ - return newpath, true, nil -} - -func walkLinks(path string, linksWalked *int) (string, error) { - switch dir, file := Split(path); { - case dir == "": - newpath, _, err := walkLink(file, linksWalked) - return newpath, err - case file == "": - if isDriveLetter(dir) { - return dir, nil - } - if os.IsPathSeparator(dir[len(dir)-1]) { - if isRoot(dir) { - return dir, nil + // The next path component is in path[start:end]. + if end == start { + // No more path components. + break + } else if path[start:end] == "." && !isWindowsDot { + // Ignore path component ".". + continue + } else if path[start:end] == ".." { + // Back up to previous component if possible. + var r int + for r = len(dest) - 1; r >= 0; r-- { + if os.IsPathSeparator(dest[r]) { + break + } + } + if r < 0 { + if len(dest) > 0 { + dest += string(os.PathSeparator) + } + dest += ".." + } else { + dest = dest[:r] } - return walkLinks(dir[:len(dir)-1], linksWalked) + continue } - newpath, _, err := walkLink(dir, linksWalked) - return newpath, err - default: - newdir, err := walkLinks(dir, linksWalked) - if err != nil { - return "", err + + // Ordinary path component. Add it to result. + + if len(dest) > volumeNameLen(dest) && !os.IsPathSeparator(dest[len(dest)-1]) { + dest += string(os.PathSeparator) } - newpath, islink, err := walkLink(Join(newdir, file), linksWalked) + + dest += path[start:end] + + // Resolve symlink. + + fi, err := os.Lstat(dest) if err != nil { return "", err } - if !islink { - return newpath, nil + + if fi.Mode()&os.ModeSymlink == 0 { + if !fi.Mode().IsDir() && end < len(path) { + return "", os.ErrNotExist + } + continue } - if IsAbs(newpath) || os.IsPathSeparator(newpath[0]) { - return newpath, nil + + // Found symlink. + + linksWalked++ + if linksWalked > 255 { + return "", errors.New("EvalSymlinks: too many links") } - return Join(newdir, newpath), nil - } -} -func walkSymlinks(path string) (string, error) { - if path == "" { - return path, nil - } - var linksWalked int // to protect against cycles - for { - i := linksWalked - newpath, err := walkLinks(path, &linksWalked) + link, err := os.Readlink(dest) if err != nil { return "", err } - if runtime.GOOS == "windows" { - // walkLinks(".", ...) always returns "." on unix. - // But on windows it returns symlink target, if current - // directory is a symlink. Stop the walk, if symlink - // target is not absolute path, and return "." - // to the caller (just like unix does). - // Same for "C:.". - if path[volumeNameLen(path):] == "." && !IsAbs(newpath) { - return path, nil - } + + if isWindowsDot && !IsAbs(link) { + // On Windows, if "." is a relative symlink, + // just return ".". + break } - if i == linksWalked { - return Clean(newpath), nil + + path = link + path[end:] + + v := volumeNameLen(link) + if v > 0 { + // Symlink to drive name is an absolute path. + if v < len(link) && os.IsPathSeparator(link[v]) { + v++ + } + vol = link[:v] + dest = vol + end = len(vol) + } else if len(link) > 0 && os.IsPathSeparator(link[0]) { + // Symlink to absolute path. + dest = link[:1] + end = 1 + } else { + // Symlink to relative path; replace last + // path component in dest. + var r int + for r = len(dest) - 1; r >= 0; r-- { + if os.IsPathSeparator(dest[r]) { + break + } + } + if r < 0 { + dest = vol + } else { + dest = dest[:r] + } + end = 0 } - path = newpath } + return Clean(dest), nil } From 0ef42f4dd6b12821641fe415f16e425bb094137b Mon Sep 17 00:00:00 2001 From: erifan01 Date: Wed, 12 Sep 2018 10:31:04 +0000 Subject: [PATCH 0364/1663] runtime: skip TestGcSys on arm64 This failure occurs randomly on arm64. 13:10:32 --- FAIL: TestGcSys (0.06s) 13:10:32 gc_test.go:30: expected "OK\n", but got "using too much memory: 71401472 bytes\n" 13:10:32 FAIL Updates #27636 Change-Id: Ifd4cfce167d8054dc6f037bd34368d63c7f68ed4 Reviewed-on: https://go-review.googlesource.com/135155 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/gc_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/runtime/gc_test.go b/src/runtime/gc_test.go index 0da19cdf340d9..1f7715c67231e 100644 --- a/src/runtime/gc_test.go +++ b/src/runtime/gc_test.go @@ -24,6 +24,9 @@ func TestGcSys(t *testing.T) { if runtime.GOOS == "windows" { t.Skip("skipping test; GOOS=windows http://golang.org/issue/27156") } + if runtime.GOOS == "linux" && runtime.GOARCH == "arm64" { + t.Skip("skipping test; GOOS=linux GOARCH=arm64 https://github.com/golang/go/issues/27636") + } got := runTestProg(t, "testprog", "GCSys") want := "OK\n" if got != want { From 8e2333b2825d6a58d98845b448d03545e10de43d Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 12 Sep 2018 16:45:10 -0700 Subject: [PATCH 0365/1663] go/types: fix scope printing (debugging support) Printing of scopes was horribly wrong: If a scope contained no object declarations, it would abort printing even if the scope had children scopes. Also, the line breaks were not inserted consistently. The actual test case (ExampleScope) was incorrect as well. Fixed and simplified printing, and adjusted example which tests the printing output. Change-Id: If21c1d4ad71b15a517d4a54da16de5e6228eb4b5 Reviewed-on: https://go-review.googlesource.com/135115 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Alan Donovan --- src/go/types/example_test.go | 21 ++++++++++++++++----- src/go/types/scope.go | 10 ++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/go/types/example_test.go b/src/go/types/example_test.go index 2a2fb3fc591d3..492127bbab576 100644 --- a/src/go/types/example_test.go +++ b/src/go/types/example_test.go @@ -51,6 +51,7 @@ type Celsius float64 func (c Celsius) String() string { return fmt.Sprintf("%g°C", c) } func FToC(f float64) Celsius { return Celsius(f - 32 / 9 * 5) } const Boiling Celsius = 100 +func Unused() { {}; {{ var x int; _ = x }} } // make sure empty block scopes get printed `}, } { f, err := parser.ParseFile(fset, file.name, file.input, 0) @@ -81,23 +82,33 @@ const Boiling Celsius = 100 // . const temperature.Boiling temperature.Celsius // . type temperature.Celsius float64 // . func temperature.FToC(f float64) temperature.Celsius + // . func temperature.Unused() // . func temperature.main() - // // . main.go scope { // . . package fmt - // // . . function scope { // . . . var freezing temperature.Celsius - // . . }. } + // . . } + // . } // . celsius.go scope { // . . package fmt - // // . . function scope { // . . . var c temperature.Celsius // . . } // . . function scope { // . . . var f float64 - // . . }. }} + // . . } + // . . function scope { + // . . . block scope { + // . . . } + // . . . block scope { + // . . . . block scope { + // . . . . . var x int + // . . . . } + // . . . } + // . . } + // . } + // } } // ExampleMethodSet prints the method sets of various types. diff --git a/src/go/types/scope.go b/src/go/types/scope.go index 39e42d758add8..839a60db2e100 100644 --- a/src/go/types/scope.go +++ b/src/go/types/scope.go @@ -161,13 +161,8 @@ func (s *Scope) WriteTo(w io.Writer, n int, recurse bool) { const ind = ". " indn := strings.Repeat(ind, n) - fmt.Fprintf(w, "%s%s scope %p {", indn, s.comment, s) - if len(s.elems) == 0 { - fmt.Fprintf(w, "}\n") - return - } + fmt.Fprintf(w, "%s%s scope %p {\n", indn, s.comment, s) - fmt.Fprintln(w) indn1 := indn + ind for _, name := range s.Names() { fmt.Fprintf(w, "%s%s\n", indn1, s.elems[name]) @@ -175,12 +170,11 @@ func (s *Scope) WriteTo(w io.Writer, n int, recurse bool) { if recurse { for _, s := range s.children { - fmt.Fprintln(w) s.WriteTo(w, n+1, recurse) } } - fmt.Fprintf(w, "%s}", indn) + fmt.Fprintf(w, "%s}\n", indn) } // String returns a string representation of the scope, for debugging. From 8eb36ae9c76d3111afa1bee19b18c0f6cfcfe982 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 12 Sep 2018 17:11:33 -0700 Subject: [PATCH 0366/1663] go/types: be more precise in API comment Change-Id: I24c4b08091bf3b8734f5dcdb9eac1a3582a4daa8 Reviewed-on: https://go-review.googlesource.com/135116 Reviewed-by: Alan Donovan --- src/go/types/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/go/types/api.go b/src/go/types/api.go index 4e14f40adef7a..b1fcb2d10beff 100644 --- a/src/go/types/api.go +++ b/src/go/types/api.go @@ -180,7 +180,7 @@ type Info struct { // // *ast.ImportSpec *PkgName for imports without renames // *ast.CaseClause type-specific *Var for each type switch case clause (incl. default) - // *ast.Field anonymous parameter *Var + // *ast.Field anonymous parameter *Var (incl. unnamed results) // Implicits map[ast.Node]Object From 8dbd9afbb05c77ca8426256d172f9e05fe48a0f0 Mon Sep 17 00:00:00 2001 From: Lynn Boger Date: Wed, 15 Aug 2018 17:34:06 -0400 Subject: [PATCH 0367/1663] cmd/compile: improve rules for PPC64.rules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This adds some improvements to the rules for PPC64 to eliminate unnecessary zero or sign extends, and fix some rule for truncates which were not always using the correct sign instruction. This reduces of size of many functions by 1 or 2 instructions and can improve performance in cases where the execution time depends on small loops where at least 1 instruction was removed and where that loop contributes a significant amount of the total execution time. Included is a testcase for codegen to verify the sign/zero extend instructions are omitted. An example of the improvement (strings): IndexAnyASCII/256:1-16 392ns ± 0% 369ns ± 0% -5.79% (p=0.000 n=1+10) IndexAnyASCII/256:2-16 397ns ± 0% 376ns ± 0% -5.23% (p=0.000 n=1+9) IndexAnyASCII/256:4-16 405ns ± 0% 384ns ± 0% -5.19% (p=1.714 n=1+6) IndexAnyASCII/256:8-16 427ns ± 0% 403ns ± 0% -5.57% (p=0.000 n=1+10) IndexAnyASCII/256:16-16 441ns ± 0% 418ns ± 1% -5.33% (p=0.000 n=1+10) IndexAnyASCII/4096:1-16 5.62µs ± 0% 5.27µs ± 1% -6.31% (p=0.000 n=1+10) IndexAnyASCII/4096:2-16 5.67µs ± 0% 5.29µs ± 0% -6.67% (p=0.222 n=1+8) IndexAnyASCII/4096:4-16 5.66µs ± 0% 5.28µs ± 1% -6.66% (p=0.000 n=1+10) IndexAnyASCII/4096:8-16 5.66µs ± 0% 5.31µs ± 1% -6.10% (p=0.000 n=1+10) IndexAnyASCII/4096:16-16 5.70µs ± 0% 5.33µs ± 1% -6.43% (p=0.182 n=1+10) Change-Id: I739a6132b505936d39001aada5a978ff2a5f0500 Reviewed-on: https://go-review.googlesource.com/129875 Reviewed-by: David Chase --- src/cmd/compile/internal/ssa/gen/PPC64.rules | 77 +- src/cmd/compile/internal/ssa/rewritePPC64.go | 1219 +++++++++++++++++- test/codegen/noextend.go | 213 +++ 3 files changed, 1440 insertions(+), 69 deletions(-) create mode 100644 test/codegen/noextend.go diff --git a/src/cmd/compile/internal/ssa/gen/PPC64.rules b/src/cmd/compile/internal/ssa/gen/PPC64.rules index 6ef8c7b5b9a63..2e06fcd83df35 100644 --- a/src/cmd/compile/internal/ssa/gen/PPC64.rules +++ b/src/cmd/compile/internal/ssa/gen/PPC64.rules @@ -660,14 +660,51 @@ (MOVWreg y:(AND (MOVDconst [c]) _)) && uint64(c) <= 0x7FFFFFFF -> y // small and of zero-extend -> either zero-extend or small and - // degenerate-and (ANDconst [c] y:(MOVBZreg _)) && c&0xFF == 0xFF -> y +(ANDconst [0xFF] y:(MOVBreg _)) -> y (ANDconst [c] y:(MOVHZreg _)) && c&0xFFFF == 0xFFFF -> y -(ANDconst [c] y:(MOVWZreg _)) && c&0xFFFFFFFF == 0xFFFFFFFF -> y - // normal case -(ANDconst [c] (MOVBZreg x)) -> (ANDconst [c&0xFF] x) -(ANDconst [c] (MOVHZreg x)) -> (ANDconst [c&0xFFFF] x) -(ANDconst [c] (MOVWZreg x)) -> (ANDconst [c&0xFFFFFFFF] x) +(ANDconst [0xFFFF] y:(MOVHreg _)) -> y + +(AND (MOVDconst [c]) y:(MOVWZreg _)) && c&0xFFFFFFFF == 0xFFFFFFFF -> y +(AND (MOVDconst [0xFFFFFFFF]) y:(MOVWreg x)) -> (MOVWZreg x) +// normal case +(ANDconst [c] (MOV(B|BZ)reg x)) -> (ANDconst [c&0xFF] x) +(ANDconst [c] (MOV(H|HZ)reg x)) -> (ANDconst [c&0xFFFF] x) +(ANDconst [c] (MOV(W|WZ)reg x)) -> (ANDconst [c&0xFFFFFFFF] x) + +// Eliminate unnecessary sign/zero extend following right shift +(MOV(B|H|W)Zreg (SRWconst [c] (MOVBZreg x))) -> (SRWconst [c] (MOVBZreg x)) +(MOV(H|W)Zreg (SRWconst [c] (MOVHZreg x))) -> (SRWconst [c] (MOVHZreg x)) +(MOVWZreg (SRWconst [c] (MOVWZreg x))) -> (SRWconst [c] (MOVWZreg x)) +(MOV(B|H|W)reg (SRAWconst [c] (MOVBreg x))) -> (SRAWconst [c] (MOVBreg x)) +(MOV(H|W)reg (SRAWconst [c] (MOVHreg x))) -> (SRAWconst [c] (MOVHreg x)) +(MOVWreg (SRAWconst [c] (MOVWreg x))) -> (SRAWconst [c] (MOVWreg x)) + +(MOVWZreg (SRWconst [c] x)) && sizeof(x.Type) <= 32 -> (SRWconst [c] x) +(MOVHZreg (SRWconst [c] x)) && sizeof(x.Type) <= 16 -> (SRWconst [c] x) +(MOVBZreg (SRWconst [c] x)) && sizeof(x.Type) == 8 -> (SRWconst [c] x) +(MOVWreg (SRAWconst [c] x)) && sizeof(x.Type) <= 32 -> (SRAWconst [c] x) +(MOVHreg (SRAWconst [c] x)) && sizeof(x.Type) <= 16 -> (SRAWconst [c] x) +(MOVBreg (SRAWconst [c] x)) && sizeof(x.Type) == 8 -> (SRAWconst [c] x) + +// initial right shift will handle sign/zero extend +(MOVBZreg (SRDconst [c] x)) && c>=56 -> (SRDconst [c] x) +(MOVBreg (SRDconst [c] x)) && c>56 -> (SRDconst [c] x) +(MOVBreg (SRDconst [c] x)) && c==56 -> (SRADconst [c] x) +(MOVBZreg (SRWconst [c] x)) && c>=24 -> (SRWconst [c] x) +(MOVBreg (SRWconst [c] x)) && c>24 -> (SRWconst [c] x) +(MOVBreg (SRWconst [c] x)) && c==24 -> (SRAWconst [c] x) + +(MOVHZreg (SRDconst [c] x)) && c>=48 -> (SRDconst [c] x) +(MOVHreg (SRDconst [c] x)) && c>48 -> (SRDconst [c] x) +(MOVHreg (SRDconst [c] x)) && c==48 -> (SRADconst [c] x) +(MOVHZreg (SRWconst [c] x)) && c>=16 -> (SRWconst [c] x) +(MOVHreg (SRWconst [c] x)) && c>16 -> (SRWconst [c] x) +(MOVHreg (SRWconst [c] x)) && c==16 -> (SRAWconst [c] x) + +(MOVWZreg (SRDconst [c] x)) && c>=32 -> (SRDconst [c] x) +(MOVWreg (SRDconst [c] x)) && c>32 -> (SRDconst [c] x) +(MOVWreg (SRDconst [c] x)) && c==32 -> (SRADconst [c] x) // Various redundant zero/sign extension combinations. (MOVBZreg y:(MOVBZreg _)) -> y // repeat @@ -851,22 +888,38 @@ (ZeroExt16to(32|64) x) -> (MOVHZreg x) (ZeroExt32to64 x) -> (MOVWZreg x) -(Trunc(16|32|64)to8 x) -> (MOVBreg x) -(Trunc(32|64)to16 x) -> (MOVHreg x) -(Trunc64to32 x) -> (MOVWreg x) +(Trunc(16|32|64)to8 x) && isSigned(x.Type) -> (MOVBreg x) +(Trunc(16|32|64)to8 x) -> (MOVBZreg x) +(Trunc(32|64)to16 x) && isSigned(x.Type) -> (MOVHreg x) +(Trunc(32|64)to16 x) -> (MOVHZreg x) +(Trunc64to32 x) && isSigned(x.Type) -> (MOVWreg x) +(Trunc64to32 x) -> (MOVWZreg x) (Slicemask x) -> (SRADconst (NEG x) [63]) // Note that MOV??reg returns a 64-bit int, x is not necessarily that wide // This may interact with other patterns in the future. (Compare with arm64) -(MOVBZreg x:(MOVBZload _ _)) -> x -(MOVHZreg x:(MOVHZload _ _)) -> x -(MOVHreg x:(MOVHload _ _)) -> x +(MOV(B|H|W)Zreg x:(MOVBZload _ _)) -> x +(MOV(H|W)Zreg x:(MOVHZload _ _)) -> x +(MOV(H|W)reg x:(MOVHload _ _)) -> x +(MOVWZreg x:(MOVWZload _ _)) -> x +(MOVWreg x:(MOVWload _ _)) -> x + +// don't extend if argument is already extended +(MOVBreg x:(Arg )) && is8BitInt(t) && isSigned(t) -> x +(MOVBZreg x:(Arg )) && is8BitInt(t) && !isSigned(t) -> x +(MOVHreg x:(Arg )) && (is8BitInt(t) || is16BitInt(t)) && isSigned(t) -> x +(MOVHZreg x:(Arg )) && (is8BitInt(t) || is16BitInt(t)) && !isSigned(t) -> x +(MOVWreg x:(Arg )) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && isSigned(t) -> x +(MOVWZreg x:(Arg )) && (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && !isSigned(t) -> x (MOVBZreg (MOVDconst [c])) -> (MOVDconst [int64(uint8(c))]) (MOVBreg (MOVDconst [c])) -> (MOVDconst [int64(int8(c))]) (MOVHZreg (MOVDconst [c])) -> (MOVDconst [int64(uint16(c))]) (MOVHreg (MOVDconst [c])) -> (MOVDconst [int64(int16(c))]) +(MOVWreg (MOVDconst [c])) -> (MOVDconst [int64(int32(c))]) +(MOVWZreg (MOVDconst [c])) -> (MOVDconst [int64(uint32(c))]) + // Lose widening ops fed to to stores (MOVBstore [off] {sym} ptr (MOV(B|BZ|H|HZ|W|WZ)reg x) mem) -> (MOVBstore [off] {sym} ptr x mem) diff --git a/src/cmd/compile/internal/ssa/rewritePPC64.go b/src/cmd/compile/internal/ssa/rewritePPC64.go index ba6a862989ff6..57738c908ba82 100644 --- a/src/cmd/compile/internal/ssa/rewritePPC64.go +++ b/src/cmd/compile/internal/ssa/rewritePPC64.go @@ -388,9 +388,9 @@ func rewriteValuePPC64(v *Value) bool { case OpPPC64ADDconst: return rewriteValuePPC64_OpPPC64ADDconst_0(v) case OpPPC64AND: - return rewriteValuePPC64_OpPPC64AND_0(v) + return rewriteValuePPC64_OpPPC64AND_0(v) || rewriteValuePPC64_OpPPC64AND_10(v) case OpPPC64ANDconst: - return rewriteValuePPC64_OpPPC64ANDconst_0(v) + return rewriteValuePPC64_OpPPC64ANDconst_0(v) || rewriteValuePPC64_OpPPC64ANDconst_10(v) case OpPPC64CMP: return rewriteValuePPC64_OpPPC64CMP_0(v) case OpPPC64CMPU: @@ -452,7 +452,7 @@ func rewriteValuePPC64(v *Value) bool { case OpPPC64MOVBZreg: return rewriteValuePPC64_OpPPC64MOVBZreg_0(v) case OpPPC64MOVBreg: - return rewriteValuePPC64_OpPPC64MOVBreg_0(v) + return rewriteValuePPC64_OpPPC64MOVBreg_0(v) || rewriteValuePPC64_OpPPC64MOVBreg_10(v) case OpPPC64MOVBstore: return rewriteValuePPC64_OpPPC64MOVBstore_0(v) || rewriteValuePPC64_OpPPC64MOVBstore_10(v) || rewriteValuePPC64_OpPPC64MOVBstore_20(v) case OpPPC64MOVBstorezero: @@ -468,11 +468,11 @@ func rewriteValuePPC64(v *Value) bool { case OpPPC64MOVHZload: return rewriteValuePPC64_OpPPC64MOVHZload_0(v) case OpPPC64MOVHZreg: - return rewriteValuePPC64_OpPPC64MOVHZreg_0(v) + return rewriteValuePPC64_OpPPC64MOVHZreg_0(v) || rewriteValuePPC64_OpPPC64MOVHZreg_10(v) case OpPPC64MOVHload: return rewriteValuePPC64_OpPPC64MOVHload_0(v) case OpPPC64MOVHreg: - return rewriteValuePPC64_OpPPC64MOVHreg_0(v) + return rewriteValuePPC64_OpPPC64MOVHreg_0(v) || rewriteValuePPC64_OpPPC64MOVHreg_10(v) case OpPPC64MOVHstore: return rewriteValuePPC64_OpPPC64MOVHstore_0(v) case OpPPC64MOVHstorezero: @@ -482,11 +482,11 @@ func rewriteValuePPC64(v *Value) bool { case OpPPC64MOVWZload: return rewriteValuePPC64_OpPPC64MOVWZload_0(v) case OpPPC64MOVWZreg: - return rewriteValuePPC64_OpPPC64MOVWZreg_0(v) + return rewriteValuePPC64_OpPPC64MOVWZreg_0(v) || rewriteValuePPC64_OpPPC64MOVWZreg_10(v) case OpPPC64MOVWload: return rewriteValuePPC64_OpPPC64MOVWload_0(v) case OpPPC64MOVWreg: - return rewriteValuePPC64_OpPPC64MOVWreg_0(v) + return rewriteValuePPC64_OpPPC64MOVWreg_0(v) || rewriteValuePPC64_OpPPC64MOVWreg_10(v) case OpPPC64MOVWstore: return rewriteValuePPC64_OpPPC64MOVWstore_0(v) case OpPPC64MOVWstorezero: @@ -5533,6 +5533,95 @@ func rewriteValuePPC64_OpPPC64AND_0(v *Value) bool { v.AddArg(x) return true } + // match: (AND (MOVDconst [c]) y:(MOVWZreg _)) + // cond: c&0xFFFFFFFF == 0xFFFFFFFF + // result: y + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpPPC64MOVDconst { + break + } + c := v_0.AuxInt + y := v.Args[1] + if y.Op != OpPPC64MOVWZreg { + break + } + if !(c&0xFFFFFFFF == 0xFFFFFFFF) { + break + } + v.reset(OpCopy) + v.Type = y.Type + v.AddArg(y) + return true + } + // match: (AND y:(MOVWZreg _) (MOVDconst [c])) + // cond: c&0xFFFFFFFF == 0xFFFFFFFF + // result: y + for { + _ = v.Args[1] + y := v.Args[0] + if y.Op != OpPPC64MOVWZreg { + break + } + v_1 := v.Args[1] + if v_1.Op != OpPPC64MOVDconst { + break + } + c := v_1.AuxInt + if !(c&0xFFFFFFFF == 0xFFFFFFFF) { + break + } + v.reset(OpCopy) + v.Type = y.Type + v.AddArg(y) + return true + } + // match: (AND (MOVDconst [0xFFFFFFFF]) y:(MOVWreg x)) + // cond: + // result: (MOVWZreg x) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpPPC64MOVDconst { + break + } + if v_0.AuxInt != 0xFFFFFFFF { + break + } + y := v.Args[1] + if y.Op != OpPPC64MOVWreg { + break + } + x := y.Args[0] + v.reset(OpPPC64MOVWZreg) + v.AddArg(x) + return true + } + // match: (AND y:(MOVWreg x) (MOVDconst [0xFFFFFFFF])) + // cond: + // result: (MOVWZreg x) + for { + _ = v.Args[1] + y := v.Args[0] + if y.Op != OpPPC64MOVWreg { + break + } + x := y.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpPPC64MOVDconst { + break + } + if v_1.AuxInt != 0xFFFFFFFF { + break + } + v.reset(OpPPC64MOVWZreg) + v.AddArg(x) + return true + } + return false +} +func rewriteValuePPC64_OpPPC64AND_10(v *Value) bool { // match: (AND (MOVDconst [c]) x:(MOVBZload _ _)) // cond: // result: (ANDconst [c&0xFF] x) @@ -5673,6 +5762,22 @@ func rewriteValuePPC64_OpPPC64ANDconst_0(v *Value) bool { v.AddArg(y) return true } + // match: (ANDconst [0xFF] y:(MOVBreg _)) + // cond: + // result: y + for { + if v.AuxInt != 0xFF { + break + } + y := v.Args[0] + if y.Op != OpPPC64MOVBreg { + break + } + v.reset(OpCopy) + v.Type = y.Type + v.AddArg(y) + return true + } // match: (ANDconst [c] y:(MOVHZreg _)) // cond: c&0xFFFF == 0xFFFF // result: y @@ -5690,16 +5795,15 @@ func rewriteValuePPC64_OpPPC64ANDconst_0(v *Value) bool { v.AddArg(y) return true } - // match: (ANDconst [c] y:(MOVWZreg _)) - // cond: c&0xFFFFFFFF == 0xFFFFFFFF + // match: (ANDconst [0xFFFF] y:(MOVHreg _)) + // cond: // result: y for { - c := v.AuxInt - y := v.Args[0] - if y.Op != OpPPC64MOVWZreg { + if v.AuxInt != 0xFFFF { break } - if !(c&0xFFFFFFFF == 0xFFFFFFFF) { + y := v.Args[0] + if y.Op != OpPPC64MOVHreg { break } v.reset(OpCopy) @@ -5707,6 +5811,21 @@ func rewriteValuePPC64_OpPPC64ANDconst_0(v *Value) bool { v.AddArg(y) return true } + // match: (ANDconst [c] (MOVBreg x)) + // cond: + // result: (ANDconst [c&0xFF] x) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpPPC64MOVBreg { + break + } + x := v_0.Args[0] + v.reset(OpPPC64ANDconst) + v.AuxInt = c & 0xFF + v.AddArg(x) + return true + } // match: (ANDconst [c] (MOVBZreg x)) // cond: // result: (ANDconst [c&0xFF] x) @@ -5722,6 +5841,24 @@ func rewriteValuePPC64_OpPPC64ANDconst_0(v *Value) bool { v.AddArg(x) return true } + // match: (ANDconst [c] (MOVHreg x)) + // cond: + // result: (ANDconst [c&0xFFFF] x) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpPPC64MOVHreg { + break + } + x := v_0.Args[0] + v.reset(OpPPC64ANDconst) + v.AuxInt = c & 0xFFFF + v.AddArg(x) + return true + } + return false +} +func rewriteValuePPC64_OpPPC64ANDconst_10(v *Value) bool { // match: (ANDconst [c] (MOVHZreg x)) // cond: // result: (ANDconst [c&0xFFFF] x) @@ -5737,6 +5874,21 @@ func rewriteValuePPC64_OpPPC64ANDconst_0(v *Value) bool { v.AddArg(x) return true } + // match: (ANDconst [c] (MOVWreg x)) + // cond: + // result: (ANDconst [c&0xFFFFFFFF] x) + for { + c := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpPPC64MOVWreg { + break + } + x := v_0.Args[0] + v.reset(OpPPC64ANDconst) + v.AuxInt = c & 0xFFFFFFFF + v.AddArg(x) + return true + } // match: (ANDconst [c] (MOVWZreg x)) // cond: // result: (ANDconst [c&0xFFFFFFFF] x) @@ -7061,6 +7213,10 @@ func rewriteValuePPC64_OpPPC64MOVBZload_0(v *Value) bool { return false } func rewriteValuePPC64_OpPPC64MOVBZreg_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (MOVBZreg y:(ANDconst [c] _)) // cond: uint64(c) <= 0xFF // result: y @@ -7078,6 +7234,81 @@ func rewriteValuePPC64_OpPPC64MOVBZreg_0(v *Value) bool { v.AddArg(y) return true } + // match: (MOVBZreg (SRWconst [c] (MOVBZreg x))) + // cond: + // result: (SRWconst [c] (MOVBZreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVBZreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVBZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVBZreg (SRWconst [c] x)) + // cond: sizeof(x.Type) == 8 + // result: (SRWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(sizeof(x.Type) == 8) { + break + } + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVBZreg (SRDconst [c] x)) + // cond: c>=56 + // result: (SRDconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c >= 56) { + break + } + v.reset(OpPPC64SRDconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVBZreg (SRWconst [c] x)) + // cond: c>=24 + // result: (SRWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c >= 24) { + break + } + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v.AddArg(x) + return true + } // match: (MOVBZreg y:(MOVBZreg _)) // cond: // result: y @@ -7118,6 +7349,23 @@ func rewriteValuePPC64_OpPPC64MOVBZreg_0(v *Value) bool { v.AddArg(x) return true } + // match: (MOVBZreg x:(Arg )) + // cond: is8BitInt(t) && !isSigned(t) + // result: x + for { + x := v.Args[0] + if x.Op != OpArg { + break + } + t := x.Type + if !(is8BitInt(t) && !isSigned(t)) { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } // match: (MOVBZreg (MOVDconst [c])) // cond: // result: (MOVDconst [int64(uint8(c))]) @@ -7134,6 +7382,10 @@ func rewriteValuePPC64_OpPPC64MOVBZreg_0(v *Value) bool { return false } func rewriteValuePPC64_OpPPC64MOVBreg_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (MOVBreg y:(ANDconst [c] _)) // cond: uint64(c) <= 0x7F // result: y @@ -7151,34 +7403,165 @@ func rewriteValuePPC64_OpPPC64MOVBreg_0(v *Value) bool { v.AddArg(y) return true } - // match: (MOVBreg y:(MOVBreg _)) + // match: (MOVBreg (SRAWconst [c] (MOVBreg x))) // cond: - // result: y + // result: (SRAWconst [c] (MOVBreg x)) for { - y := v.Args[0] - if y.Op != OpPPC64MOVBreg { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRAWconst { break } - v.reset(OpCopy) - v.Type = y.Type - v.AddArg(y) + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVBreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRAWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVBreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBreg (MOVBZreg x)) - // cond: - // result: (MOVBreg x) + // match: (MOVBreg (SRAWconst [c] x)) + // cond: sizeof(x.Type) == 8 + // result: (SRAWconst [c] x) for { v_0 := v.Args[0] - if v_0.Op != OpPPC64MOVBZreg { + if v_0.Op != OpPPC64SRAWconst { break } + c := v_0.AuxInt x := v_0.Args[0] - v.reset(OpPPC64MOVBreg) + if !(sizeof(x.Type) == 8) { + break + } + v.reset(OpPPC64SRAWconst) + v.AuxInt = c v.AddArg(x) return true } - // match: (MOVBreg (MOVDconst [c])) - // cond: + // match: (MOVBreg (SRDconst [c] x)) + // cond: c>56 + // result: (SRDconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c > 56) { + break + } + v.reset(OpPPC64SRDconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVBreg (SRDconst [c] x)) + // cond: c==56 + // result: (SRADconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c == 56) { + break + } + v.reset(OpPPC64SRADconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVBreg (SRWconst [c] x)) + // cond: c>24 + // result: (SRWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c > 24) { + break + } + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVBreg (SRWconst [c] x)) + // cond: c==24 + // result: (SRAWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c == 24) { + break + } + v.reset(OpPPC64SRAWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVBreg y:(MOVBreg _)) + // cond: + // result: y + for { + y := v.Args[0] + if y.Op != OpPPC64MOVBreg { + break + } + v.reset(OpCopy) + v.Type = y.Type + v.AddArg(y) + return true + } + // match: (MOVBreg (MOVBZreg x)) + // cond: + // result: (MOVBreg x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64MOVBZreg { + break + } + x := v_0.Args[0] + v.reset(OpPPC64MOVBreg) + v.AddArg(x) + return true + } + // match: (MOVBreg x:(Arg )) + // cond: is8BitInt(t) && isSigned(t) + // result: x + for { + x := v.Args[0] + if x.Op != OpArg { + break + } + t := x.Type + if !(is8BitInt(t) && isSigned(t)) { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + return false +} +func rewriteValuePPC64_OpPPC64MOVBreg_10(v *Value) bool { + // match: (MOVBreg (MOVDconst [c])) + // cond: // result: (MOVDconst [int64(int8(c))]) for { v_0 := v.Args[0] @@ -8591,6 +8974,10 @@ func rewriteValuePPC64_OpPPC64MOVHZload_0(v *Value) bool { return false } func rewriteValuePPC64_OpPPC64MOVHZreg_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (MOVHZreg y:(ANDconst [c] _)) // cond: uint64(c) <= 0xFFFF // result: y @@ -8608,6 +8995,102 @@ func rewriteValuePPC64_OpPPC64MOVHZreg_0(v *Value) bool { v.AddArg(y) return true } + // match: (MOVHZreg (SRWconst [c] (MOVBZreg x))) + // cond: + // result: (SRWconst [c] (MOVBZreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVBZreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVBZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVHZreg (SRWconst [c] (MOVHZreg x))) + // cond: + // result: (SRWconst [c] (MOVHZreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVHZreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVHZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVHZreg (SRWconst [c] x)) + // cond: sizeof(x.Type) <= 16 + // result: (SRWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(sizeof(x.Type) <= 16) { + break + } + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVHZreg (SRDconst [c] x)) + // cond: c>=48 + // result: (SRDconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c >= 48) { + break + } + v.reset(OpPPC64SRDconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVHZreg (SRWconst [c] x)) + // cond: c>=16 + // result: (SRWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c >= 16) { + break + } + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v.AddArg(x) + return true + } // match: (MOVHZreg y:(MOVHZreg _)) // cond: // result: y @@ -8661,6 +9144,23 @@ func rewriteValuePPC64_OpPPC64MOVHZreg_0(v *Value) bool { v.AddArg(x) return true } + return false +} +func rewriteValuePPC64_OpPPC64MOVHZreg_10(v *Value) bool { + // match: (MOVHZreg x:(MOVBZload _ _)) + // cond: + // result: x + for { + x := v.Args[0] + if x.Op != OpPPC64MOVBZload { + break + } + _ = x.Args[1] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } // match: (MOVHZreg x:(MOVHZload _ _)) // cond: // result: x @@ -8675,6 +9175,23 @@ func rewriteValuePPC64_OpPPC64MOVHZreg_0(v *Value) bool { v.AddArg(x) return true } + // match: (MOVHZreg x:(Arg )) + // cond: (is8BitInt(t) || is16BitInt(t)) && !isSigned(t) + // result: x + for { + x := v.Args[0] + if x.Op != OpArg { + break + } + t := x.Type + if !((is8BitInt(t) || is16BitInt(t)) && !isSigned(t)) { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } // match: (MOVHZreg (MOVDconst [c])) // cond: // result: (MOVDconst [int64(uint16(c))]) @@ -8743,6 +9260,10 @@ func rewriteValuePPC64_OpPPC64MOVHload_0(v *Value) bool { return false } func rewriteValuePPC64_OpPPC64MOVHreg_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (MOVHreg y:(ANDconst [c] _)) // cond: uint64(c) <= 0x7FFF // result: y @@ -8760,6 +9281,138 @@ func rewriteValuePPC64_OpPPC64MOVHreg_0(v *Value) bool { v.AddArg(y) return true } + // match: (MOVHreg (SRAWconst [c] (MOVBreg x))) + // cond: + // result: (SRAWconst [c] (MOVBreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRAWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVBreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRAWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVBreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVHreg (SRAWconst [c] (MOVHreg x))) + // cond: + // result: (SRAWconst [c] (MOVHreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRAWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVHreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRAWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVHreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVHreg (SRAWconst [c] x)) + // cond: sizeof(x.Type) <= 16 + // result: (SRAWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRAWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(sizeof(x.Type) <= 16) { + break + } + v.reset(OpPPC64SRAWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVHreg (SRDconst [c] x)) + // cond: c>48 + // result: (SRDconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c > 48) { + break + } + v.reset(OpPPC64SRDconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVHreg (SRDconst [c] x)) + // cond: c==48 + // result: (SRADconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c == 48) { + break + } + v.reset(OpPPC64SRADconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVHreg (SRWconst [c] x)) + // cond: c>16 + // result: (SRWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c > 16) { + break + } + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVHreg (SRWconst [c] x)) + // cond: c==16 + // result: (SRAWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c == 16) { + break + } + v.reset(OpPPC64SRAWconst) + v.AuxInt = c + v.AddArg(x) + return true + } // match: (MOVHreg y:(MOVHreg _)) // cond: // result: y @@ -8786,6 +9439,9 @@ func rewriteValuePPC64_OpPPC64MOVHreg_0(v *Value) bool { v.AddArg(y) return true } + return false +} +func rewriteValuePPC64_OpPPC64MOVHreg_10(v *Value) bool { // match: (MOVHreg y:(MOVHZreg x)) // cond: // result: (MOVHreg x) @@ -8813,6 +9469,23 @@ func rewriteValuePPC64_OpPPC64MOVHreg_0(v *Value) bool { v.AddArg(x) return true } + // match: (MOVHreg x:(Arg )) + // cond: (is8BitInt(t) || is16BitInt(t)) && isSigned(t) + // result: x + for { + x := v.Args[0] + if x.Op != OpArg { + break + } + t := x.Type + if !((is8BitInt(t) || is16BitInt(t)) && isSigned(t)) { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } // match: (MOVHreg (MOVDconst [c])) // cond: // result: (MOVDconst [int64(int16(c))]) @@ -9234,6 +9907,10 @@ func rewriteValuePPC64_OpPPC64MOVWZload_0(v *Value) bool { return false } func rewriteValuePPC64_OpPPC64MOVWZreg_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (MOVWZreg y:(ANDconst [c] _)) // cond: uint64(c) <= 0xFFFFFFFF // result: y @@ -9295,6 +9972,105 @@ func rewriteValuePPC64_OpPPC64MOVWZreg_0(v *Value) bool { v.AddArg(y) return true } + // match: (MOVWZreg (SRWconst [c] (MOVBZreg x))) + // cond: + // result: (SRWconst [c] (MOVBZreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVBZreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVBZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVWZreg (SRWconst [c] (MOVHZreg x))) + // cond: + // result: (SRWconst [c] (MOVHZreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVHZreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVHZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVWZreg (SRWconst [c] (MOVWZreg x))) + // cond: + // result: (SRWconst [c] (MOVWZreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVWZreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVWZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVWZreg (SRWconst [c] x)) + // cond: sizeof(x.Type) <= 32 + // result: (SRWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(sizeof(x.Type) <= 32) { + break + } + v.reset(OpPPC64SRWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVWZreg (SRDconst [c] x)) + // cond: c>=32 + // result: (SRDconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c >= 32) { + break + } + v.reset(OpPPC64SRDconst) + v.AuxInt = c + v.AddArg(x) + return true + } // match: (MOVWZreg y:(MOVWZreg _)) // cond: // result: y @@ -9321,6 +10097,9 @@ func rewriteValuePPC64_OpPPC64MOVWZreg_0(v *Value) bool { v.AddArg(y) return true } + return false +} +func rewriteValuePPC64_OpPPC64MOVWZreg_10(v *Value) bool { // match: (MOVWZreg y:(MOVBZreg _)) // cond: // result: y @@ -9330,49 +10109,121 @@ func rewriteValuePPC64_OpPPC64MOVWZreg_0(v *Value) bool { break } v.reset(OpCopy) - v.Type = y.Type - v.AddArg(y) + v.Type = y.Type + v.AddArg(y) + return true + } + // match: (MOVWZreg y:(MOVHBRload _ _)) + // cond: + // result: y + for { + y := v.Args[0] + if y.Op != OpPPC64MOVHBRload { + break + } + _ = y.Args[1] + v.reset(OpCopy) + v.Type = y.Type + v.AddArg(y) + return true + } + // match: (MOVWZreg y:(MOVWBRload _ _)) + // cond: + // result: y + for { + y := v.Args[0] + if y.Op != OpPPC64MOVWBRload { + break + } + _ = y.Args[1] + v.reset(OpCopy) + v.Type = y.Type + v.AddArg(y) + return true + } + // match: (MOVWZreg y:(MOVWreg x)) + // cond: + // result: (MOVWZreg x) + for { + y := v.Args[0] + if y.Op != OpPPC64MOVWreg { + break + } + x := y.Args[0] + v.reset(OpPPC64MOVWZreg) + v.AddArg(x) + return true + } + // match: (MOVWZreg x:(MOVBZload _ _)) + // cond: + // result: x + for { + x := v.Args[0] + if x.Op != OpPPC64MOVBZload { + break + } + _ = x.Args[1] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (MOVWZreg x:(MOVHZload _ _)) + // cond: + // result: x + for { + x := v.Args[0] + if x.Op != OpPPC64MOVHZload { + break + } + _ = x.Args[1] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - // match: (MOVWZreg y:(MOVHBRload _ _)) + // match: (MOVWZreg x:(MOVWZload _ _)) // cond: - // result: y + // result: x for { - y := v.Args[0] - if y.Op != OpPPC64MOVHBRload { + x := v.Args[0] + if x.Op != OpPPC64MOVWZload { break } - _ = y.Args[1] + _ = x.Args[1] v.reset(OpCopy) - v.Type = y.Type - v.AddArg(y) + v.Type = x.Type + v.AddArg(x) return true } - // match: (MOVWZreg y:(MOVWBRload _ _)) - // cond: - // result: y + // match: (MOVWZreg x:(Arg )) + // cond: (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && !isSigned(t) + // result: x for { - y := v.Args[0] - if y.Op != OpPPC64MOVWBRload { + x := v.Args[0] + if x.Op != OpArg { + break + } + t := x.Type + if !((is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && !isSigned(t)) { break } - _ = y.Args[1] v.reset(OpCopy) - v.Type = y.Type - v.AddArg(y) + v.Type = x.Type + v.AddArg(x) return true } - // match: (MOVWZreg y:(MOVWreg x)) + // match: (MOVWZreg (MOVDconst [c])) // cond: - // result: (MOVWZreg x) + // result: (MOVDconst [int64(uint32(c))]) for { - y := v.Args[0] - if y.Op != OpPPC64MOVWreg { + v_0 := v.Args[0] + if v_0.Op != OpPPC64MOVDconst { break } - x := y.Args[0] - v.reset(OpPPC64MOVWZreg) - v.AddArg(x) + c := v_0.AuxInt + v.reset(OpPPC64MOVDconst) + v.AuxInt = int64(uint32(c)) return true } return false @@ -9430,6 +10281,10 @@ func rewriteValuePPC64_OpPPC64MOVWload_0(v *Value) bool { return false } func rewriteValuePPC64_OpPPC64MOVWreg_0(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (MOVWreg y:(ANDconst [c] _)) // cond: uint64(c) <= 0xFFFF // result: y @@ -9491,6 +10346,123 @@ func rewriteValuePPC64_OpPPC64MOVWreg_0(v *Value) bool { v.AddArg(y) return true } + // match: (MOVWreg (SRAWconst [c] (MOVBreg x))) + // cond: + // result: (SRAWconst [c] (MOVBreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRAWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVBreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRAWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVBreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVWreg (SRAWconst [c] (MOVHreg x))) + // cond: + // result: (SRAWconst [c] (MOVHreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRAWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVHreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRAWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVHreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVWreg (SRAWconst [c] (MOVWreg x))) + // cond: + // result: (SRAWconst [c] (MOVWreg x)) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRAWconst { + break + } + c := v_0.AuxInt + v_0_0 := v_0.Args[0] + if v_0_0.Op != OpPPC64MOVWreg { + break + } + x := v_0_0.Args[0] + v.reset(OpPPC64SRAWconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpPPC64MOVWreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MOVWreg (SRAWconst [c] x)) + // cond: sizeof(x.Type) <= 32 + // result: (SRAWconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRAWconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(sizeof(x.Type) <= 32) { + break + } + v.reset(OpPPC64SRAWconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVWreg (SRDconst [c] x)) + // cond: c>32 + // result: (SRDconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c > 32) { + break + } + v.reset(OpPPC64SRDconst) + v.AuxInt = c + v.AddArg(x) + return true + } + // match: (MOVWreg (SRDconst [c] x)) + // cond: c==32 + // result: (SRADconst [c] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64SRDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + if !(c == 32) { + break + } + v.reset(OpPPC64SRADconst) + v.AuxInt = c + v.AddArg(x) + return true + } // match: (MOVWreg y:(MOVWreg _)) // cond: // result: y @@ -9504,6 +10476,9 @@ func rewriteValuePPC64_OpPPC64MOVWreg_0(v *Value) bool { v.AddArg(y) return true } + return false +} +func rewriteValuePPC64_OpPPC64MOVWreg_10(v *Value) bool { // match: (MOVWreg y:(MOVHreg _)) // cond: // result: y @@ -9543,6 +10518,64 @@ func rewriteValuePPC64_OpPPC64MOVWreg_0(v *Value) bool { v.AddArg(x) return true } + // match: (MOVWreg x:(MOVHload _ _)) + // cond: + // result: x + for { + x := v.Args[0] + if x.Op != OpPPC64MOVHload { + break + } + _ = x.Args[1] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVWload _ _)) + // cond: + // result: x + for { + x := v.Args[0] + if x.Op != OpPPC64MOVWload { + break + } + _ = x.Args[1] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (MOVWreg x:(Arg )) + // cond: (is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && isSigned(t) + // result: x + for { + x := v.Args[0] + if x.Op != OpArg { + break + } + t := x.Type + if !((is8BitInt(t) || is16BitInt(t) || is32BitInt(t)) && isSigned(t)) { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (MOVWreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(int32(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpPPC64MOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpPPC64MOVDconst) + v.AuxInt = int64(int32(c)) + return true + } return false } func rewriteValuePPC64_OpPPC64MOVWstore_0(v *Value) bool { @@ -27043,69 +28076,141 @@ func rewriteValuePPC64_OpTrunc_0(v *Value) bool { } func rewriteValuePPC64_OpTrunc16to8_0(v *Value) bool { // match: (Trunc16to8 x) - // cond: + // cond: isSigned(x.Type) // result: (MOVBreg x) for { x := v.Args[0] + if !(isSigned(x.Type)) { + break + } v.reset(OpPPC64MOVBreg) v.AddArg(x) return true } + // match: (Trunc16to8 x) + // cond: + // result: (MOVBZreg x) + for { + x := v.Args[0] + v.reset(OpPPC64MOVBZreg) + v.AddArg(x) + return true + } } func rewriteValuePPC64_OpTrunc32to16_0(v *Value) bool { // match: (Trunc32to16 x) - // cond: + // cond: isSigned(x.Type) // result: (MOVHreg x) for { x := v.Args[0] + if !(isSigned(x.Type)) { + break + } v.reset(OpPPC64MOVHreg) v.AddArg(x) return true } + // match: (Trunc32to16 x) + // cond: + // result: (MOVHZreg x) + for { + x := v.Args[0] + v.reset(OpPPC64MOVHZreg) + v.AddArg(x) + return true + } } func rewriteValuePPC64_OpTrunc32to8_0(v *Value) bool { // match: (Trunc32to8 x) - // cond: + // cond: isSigned(x.Type) // result: (MOVBreg x) for { x := v.Args[0] + if !(isSigned(x.Type)) { + break + } v.reset(OpPPC64MOVBreg) v.AddArg(x) return true } + // match: (Trunc32to8 x) + // cond: + // result: (MOVBZreg x) + for { + x := v.Args[0] + v.reset(OpPPC64MOVBZreg) + v.AddArg(x) + return true + } } func rewriteValuePPC64_OpTrunc64to16_0(v *Value) bool { // match: (Trunc64to16 x) - // cond: + // cond: isSigned(x.Type) // result: (MOVHreg x) for { x := v.Args[0] + if !(isSigned(x.Type)) { + break + } v.reset(OpPPC64MOVHreg) v.AddArg(x) return true } + // match: (Trunc64to16 x) + // cond: + // result: (MOVHZreg x) + for { + x := v.Args[0] + v.reset(OpPPC64MOVHZreg) + v.AddArg(x) + return true + } } func rewriteValuePPC64_OpTrunc64to32_0(v *Value) bool { // match: (Trunc64to32 x) - // cond: + // cond: isSigned(x.Type) // result: (MOVWreg x) for { x := v.Args[0] + if !(isSigned(x.Type)) { + break + } v.reset(OpPPC64MOVWreg) v.AddArg(x) return true } + // match: (Trunc64to32 x) + // cond: + // result: (MOVWZreg x) + for { + x := v.Args[0] + v.reset(OpPPC64MOVWZreg) + v.AddArg(x) + return true + } } func rewriteValuePPC64_OpTrunc64to8_0(v *Value) bool { // match: (Trunc64to8 x) - // cond: + // cond: isSigned(x.Type) // result: (MOVBreg x) for { x := v.Args[0] + if !(isSigned(x.Type)) { + break + } v.reset(OpPPC64MOVBreg) v.AddArg(x) return true } + // match: (Trunc64to8 x) + // cond: + // result: (MOVBZreg x) + for { + x := v.Args[0] + v.reset(OpPPC64MOVBZreg) + v.AddArg(x) + return true + } } func rewriteValuePPC64_OpWB_0(v *Value) bool { // match: (WB {fn} destptr srcptr mem) diff --git a/test/codegen/noextend.go b/test/codegen/noextend.go new file mode 100644 index 0000000000000..ee4900226c344 --- /dev/null +++ b/test/codegen/noextend.go @@ -0,0 +1,213 @@ +// asmcheck + +// Copyright 2018 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. + +package codegen + +var sval64 [8]int64 +var sval32 [8]int32 +var sval16 [8]int16 +var sval8 [8]int8 +var val64 [8]uint64 +var val32 [8]uint32 +var val16 [8]uint16 +var val8 [8]uint8 + +// ----------------------------- // +// avoid zero/sign extensions // +// ----------------------------- // + +func set16(x8 int8, u8 uint8, y8 int8, z8 uint8) { + // Truncate not needed, load does sign/zero extend + // ppc64le:-"MOVB\tR\\d+,\\sR\\d+" + sval16[0] = int16(x8) + + // ppc64le:-"MOVBZ\tR\\d+,\\sR\\d+" + val16[0] = uint16(u8) + + // AND not needed due to size + // ppc64le:-"ANDCC" + sval16[1] = 255 & int16(x8+y8) + + // ppc64le:-"ANDCC" + val16[1] = 255 & uint16(u8+z8) + +} +func shiftidx(x8 int8, u8 uint8, x16 int16, u16 uint16, x32 int32, u32 uint32) { + // ppc64le:-"MOVB\tR\\d+,\\sR\\d+" + sval16[0] = int16(val16[x8>>1]) + + // ppc64le:-"MOVBZ\tR\\d+,\\sR\\d+" + val16[0] = uint16(sval16[u8>>2]) + + // ppc64le:-"MOVH\tR\\d+,\\sR\\d+" + sval16[1] = int16(val16[x16>>1]) + + // ppc64le:-"MOVHZ\tR\\d+,\\sR\\d+" + val16[1] = uint16(sval16[u16>>2]) + +} + +func setnox(x8 int8, u8 uint8, y8 int8, z8 uint8, x16 int16, u16 uint16, x32 int32, u32 uint32) { + // Truncate not needed due to sign/zero extension on load + + // ppc64le:-"MOVB\tR\\d+,\\sR\\d+" + sval16[0] = int16(x8) + + // ppc64le:-"MOVBZ\tR\\d+,\\sR\\d+" + val16[0] = uint16(u8) + + // AND not needed due to size + // ppc64le:-"ANDCC" + sval16[1] = 255 & int16(x8+y8) + + // ppc64le:-"ANDCC" + val16[1] = 255 & uint16(u8+z8) + + // ppc64le:-"MOVB\tR\\d+,\\sR\\d+" + sval32[0] = int32(x8) + + // ppc64le:-"MOVH\tR\\d+,\\sR\\d+" + sval32[1] = int32(x16) + + //ppc64le:-"MOVBZ\tR\\d+,\\sR\\d+" + val32[0] = uint32(u8) + + // ppc64le:-"MOVHZ\tR\\d+,\\sR\\d+" + val32[1] = uint32(u16) + + // ppc64le:-"MOVB\tR\\d+,\\sR\\d+" + sval64[0] = int64(x8) + + // ppc64le:-"MOVH\tR\\d+,\\sR\\d+" + sval64[1] = int64(x16) + + // ppc64le:-"MOVW\tR\\d+,\\sR\\d+" + sval64[2] = int64(x32) + + //ppc64le:-"MOVBZ\tR\\d+,\\sR\\d+" + val64[0] = uint64(u8) + + // ppc64le:-"MOVHZ\tR\\d+,\\sR\\d+" + val64[1] = uint64(u16) + + // ppc64le:-"MOVWZ\tR\\d+,\\sR\\d+" + val64[2] = uint64(u32) +} + +func cmp16(x8 int8, u8 uint8, x32 int32, u32 uint32, x64 int64, u64 uint64) bool { + // ppc64le:-"MOVB\tR\\d+,\\sR\\d+" + if int16(x8) == sval16[0] { + return true + } + + // ppc64le:-"MOVBZ\tR\\d+,\\sR\\d+" + if uint16(u8) == val16[0] { + return true + } + + // ppc64le:-"MOVHZ\tR\\d+,\\sR\\d+" + if uint16(u32>>16) == val16[0] { + return true + } + + // ppc64le:-"MOVHZ\tR\\d+,\\sR\\d+" + if uint16(u64>>48) == val16[0] { + return true + } + + // Verify the truncates are using the correct sign. + // ppc64le:-"MOVHZ\tR\\d+,\\sR\\d+" + if int16(x32) == sval16[0] { + return true + } + + // ppc64le:-"MOVH\tR\\d+,\\sR\\d+" + if uint16(u32) == val16[0] { + return true + } + + // ppc64le:-"MOVHZ\tR\\d+,\\sR\\d+" + if int16(x64) == sval16[0] { + return true + } + + // ppc64le:-"MOVH\tR\\d+,\\sR\\d+" + if uint16(u64) == val16[0] { + return true + } + + return false +} + +func cmp32(x8 int8, u8 uint8, x16 int16, u16 uint16, x64 int64, u64 uint64) bool { + // ppc64le:-"MOVB\tR\\d+,\\sR\\d+" + if int32(x8) == sval32[0] { + return true + } + + // ppc64le:-"MOVBZ\tR\\d+,\\sR\\d+" + if uint32(u8) == val32[0] { + return true + } + + // ppc64le:-"MOVH\tR\\d+,\\sR\\d+" + if int32(x16) == sval32[0] { + return true + } + + // ppc64le:-"MOVHZ\tR\\d+,\\sR\\d+" + if uint32(u16) == val32[0] { + return true + } + + // Verify the truncates are using the correct sign. + // ppc64le:-"MOVWZ\tR\\d+,\\sR\\d+" + if int32(x64) == sval32[0] { + return true + } + + // ppc64le:-"MOVW\tR\\d+,\\sR\\d+" + if uint32(u64) == val32[0] { + return true + } + + return false +} + + +func cmp64(x8 int8, u8 uint8, x16 int16, u16 uint16, x32 int32, u32 uint32) bool { + // ppc64le:-"MOVB\tR\\d+,\\sR\\d+" + if int64(x8) == sval64[0] { + return true + } + + // ppc64le:-"MOVBZ\tR\\d+,\\sR\\d+" + if uint64(u8) == val64[0] { + return true + } + + // ppc64le:-"MOVH\tR\\d+,\\sR\\d+" + if int64(x16) == sval64[0] { + return true + } + + // ppc64le:-"MOVHZ\tR\\d+,\\sR\\d+" + if uint64(u16) == val64[0] { + return true + } + + // ppc64le:-"MOVW\tR\\d+,\\sR\\d+" + if int64(x32) == sval64[0] { + return true + } + + // ppc64le:-"MOVWZ\tR\\d+,\\sR\\d+" + if uint64(u32) == val64[0] { + return true + } + return false +} + From 56dc1795e756767adb373a5bc151c9c820152025 Mon Sep 17 00:00:00 2001 From: Roberto Selbach Date: Mon, 27 Aug 2018 15:57:32 +0000 Subject: [PATCH 0368/1663] cmd/go/internal/modfetch: stop cutting the last character of versions When a zip archive for a module contains an unexpected file, the error message removes the last character in the version number, e.g. an invalid archive for "somemod@v1.2.3" would generate the following error: "zip for somemod@1.2. has unexpected file..." Change-Id: I366622df16a71fa7467a4bc62cb696e3e83a2942 GitHub-Last-Rev: f172283bcdffd45b485b1e8fd99795eb93fef726 GitHub-Pull-Request: golang/go#27279 Reviewed-on: https://go-review.googlesource.com/131635 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- src/cmd/go/internal/modfetch/fetch.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/go/internal/modfetch/fetch.go b/src/cmd/go/internal/modfetch/fetch.go index 2e26bac434da8..8485932b42fca 100644 --- a/src/cmd/go/internal/modfetch/fetch.go +++ b/src/cmd/go/internal/modfetch/fetch.go @@ -123,7 +123,7 @@ func downloadZip(mod module.Version, target string) error { for _, f := range z.File { if !strings.HasPrefix(f.Name, prefix) { z.Close() - return fmt.Errorf("zip for %s has unexpected file %s", prefix[:len(prefix)-1], f.Name) + return fmt.Errorf("zip for %s has unexpected file %s", prefix, f.Name) } } z.Close() From 7c95703c090757c4ca3f0792357e1595b03d6bca Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Thu, 13 Sep 2018 21:15:34 +0200 Subject: [PATCH 0369/1663] runtime: don't build semasleep_test on Plan 9 CL 135015 added TestSpuriousWakeupsNeverHangSemasleep. However, this test is failing on Plan 9 because syscall.SIGIO is not defined. This change excludes semasleep_test.go on Plan 9 Fixes #27662. Change-Id: I52f9f0fe9ec3c70da5d2f586a95debbc1fe568a1 Reviewed-on: https://go-review.googlesource.com/135315 Run-TryBot: David du Colombier <0intro@gmail.com> Reviewed-by: Emmanuel Odeke TryBot-Result: Gobot Gobot --- src/runtime/semasleep_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/semasleep_test.go b/src/runtime/semasleep_test.go index 4a8b4db338c74..5b2cc64483f95 100644 --- a/src/runtime/semasleep_test.go +++ b/src/runtime/semasleep_test.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//+build !nacl,!windows,!js +//+build !nacl,!plan9,!windows,!js package runtime_test From 9f59918cae5eb23fdf0135b77280907365b52069 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 13 Sep 2018 12:18:09 -0700 Subject: [PATCH 0370/1663] path/filepath: correct symlink eval for symlink at root For a relative symlink in the root directory, such as /tmp -> private/tmp, we were dropping the leading slash. No test because we can't create a symlink in the root directory. The test TestGZIPFilesHaveZeroMTimes was failing on the Darwin builders. Updates #19922 Updates #20506 Change-Id: Ic83cb6d97ad0cb628fc551ac772a44fb3e20f038 Reviewed-on: https://go-review.googlesource.com/135295 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/path/filepath/symlink.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/path/filepath/symlink.go b/src/path/filepath/symlink.go index 57dcbf314d125..98a92357bedb2 100644 --- a/src/path/filepath/symlink.go +++ b/src/path/filepath/symlink.go @@ -41,14 +41,15 @@ func walkSymlinks(path string) (string, error) { continue } else if path[start:end] == ".." { // Back up to previous component if possible. + // Note that volLen includes any leading slash. var r int - for r = len(dest) - 1; r >= 0; r-- { + for r = len(dest) - 1; r >= volLen; r-- { if os.IsPathSeparator(dest[r]) { break } } - if r < 0 { - if len(dest) > 0 { + if r < volLen { + if len(dest) > volLen { dest += string(os.PathSeparator) } dest += ".." @@ -117,12 +118,12 @@ func walkSymlinks(path string) (string, error) { // Symlink to relative path; replace last // path component in dest. var r int - for r = len(dest) - 1; r >= 0; r-- { + for r = len(dest) - 1; r >= volLen; r-- { if os.IsPathSeparator(dest[r]) { break } } - if r < 0 { + if r < volLen { dest = vol } else { dest = dest[:r] From 16687a3bbfa27280d16eaa89e72833b7d7579a79 Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Thu, 13 Sep 2018 13:16:46 +0100 Subject: [PATCH 0371/1663] cmd/compile: skip float32 constant folding test on 387 builder The 387 unit always quietens float64 and float32 signaling NaNs, even when just loading and storing them. This makes it difficult to propagate such values in the compiler. This is a hard problem to fix and it is also very obscure. Updates #27516. Change-Id: I03d88e31f14c86fa682fcea4b6d1fba18968aee8 Reviewed-on: https://go-review.googlesource.com/135195 Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/gc/float_test.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/gc/float_test.go b/src/cmd/compile/internal/gc/float_test.go index c0a8cfc89e6d7..c5c604003ab8d 100644 --- a/src/cmd/compile/internal/gc/float_test.go +++ b/src/cmd/compile/internal/gc/float_test.go @@ -6,6 +6,8 @@ package gc import ( "math" + "os" + "runtime" "testing" ) @@ -364,11 +366,19 @@ func TestFloatConvertFolded(t *testing.T) { func TestFloat32StoreToLoadConstantFold(t *testing.T) { // Test that math.Float32{,from}bits constant fold correctly. - // In particular we need to be careful that signalling NaN (sNaN) values + // In particular we need to be careful that signaling NaN (sNaN) values // are not converted to quiet NaN (qNaN) values during compilation. // See issue #27193 for more information. - // signalling NaNs + // TODO: this method for detecting 387 won't work if the compiler has been + // built using GOARCH=386 GO386=387 and either the target is a different + // architecture or the GO386=387 environment variable is not set when the + // test is run. + if runtime.GOARCH == "386" && os.Getenv("GO386") == "387" { + t.Skip("signaling NaNs are not propagated on 387 (issue #27516)") + } + + // signaling NaNs { const nan = uint32(0x7f800001) // sNaN if x := math.Float32bits(math.Float32frombits(nan)); x != nan { From a708353a0c2c39ce4e8182ea75e5082135ae674f Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 13 Sep 2018 15:02:27 -0700 Subject: [PATCH 0372/1663] cmd/go: correct gccgo buildid file on ARM The GNU assembler for ARM treats @ as a comment character, so section types must be written using % instead. Fixes https://gcc.gnu.org/PR87260. Change-Id: I5461e4bf5b20793db321f540c7f25a9e6e12b6f4 Reviewed-on: https://go-review.googlesource.com/135297 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- src/cmd/go/internal/work/buildid.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/internal/work/buildid.go b/src/cmd/go/internal/work/buildid.go index f6b79711f9d8f..8b97e8b75b885 100644 --- a/src/cmd/go/internal/work/buildid.go +++ b/src/cmd/go/internal/work/buildid.go @@ -348,8 +348,12 @@ func (b *Builder) gccgoBuildIDELFFile(a *Action) (string, error) { } fmt.Fprintf(&buf, "\n") if cfg.Goos != "solaris" { - fmt.Fprintf(&buf, "\t"+`.section .note.GNU-stack,"",@progbits`+"\n") - fmt.Fprintf(&buf, "\t"+`.section .note.GNU-split-stack,"",@progbits`+"\n") + secType := "@progbits" + if cfg.Goarch == "arm" { + secType = "%progbits" + } + fmt.Fprintf(&buf, "\t"+`.section .note.GNU-stack,"",%s`+"\n", secType) + fmt.Fprintf(&buf, "\t"+`.section .note.GNU-split-stack,"",%s`+"\n", secType) } if cfg.BuildN || cfg.BuildX { From b1f656b1ceb09124f2d8ad63ceceb8df20a581c2 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 14 Sep 2018 10:57:57 -0700 Subject: [PATCH 0373/1663] cmd/compile: fold address calculations into CMPload[const] ops Makes go binary smaller by 0.2%. I noticed this in autogenerated equal methods, and there are probably a lot of those. Change-Id: I4e04eb3653fbceb9dd6a4eee97ceab1fa4d10b72 Reviewed-on: https://go-review.googlesource.com/135379 Reviewed-by: Ilya Tocar --- src/cmd/compile/internal/ssa/gen/AMD64.rules | 12 + src/cmd/compile/internal/ssa/rewriteAMD64.go | 428 +++++++++++++++++++ test/codegen/memops.go | 86 ++++ 3 files changed, 526 insertions(+) create mode 100644 test/codegen/memops.go diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index 4c11f8d0366cb..0eba5f03cdbcb 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -1042,6 +1042,11 @@ ((ADD|SUB|AND|OR|XOR)Qload [off1+off2] {sym} val base mem) ((ADD|SUB|AND|OR|XOR)Lload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> ((ADD|SUB|AND|OR|XOR)Lload [off1+off2] {sym} val base mem) +(CMP(Q|L|W|B)load [off1] {sym} (ADDQconst [off2] base) val mem) && is32Bit(off1+off2) -> + (CMP(Q|L|W|B)load [off1+off2] {sym} base val mem) +(CMP(Q|L|W|B)constload [off1] {sym} (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> + (CMP(Q|L|W|B)constload [off1+off2] {sym} base mem) + ((ADD|SUB|MUL|DIV)SSload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> ((ADD|SUB|MUL|DIV)SSload [off1+off2] {sym} val base mem) ((ADD|SUB|MUL|DIV)SDload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> @@ -1088,6 +1093,13 @@ ((ADD|SUB|AND|OR|XOR)Lload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> ((ADD|SUB|AND|OR|XOR)Lload [off1+off2] {mergeSym(sym1,sym2)} val base mem) +(CMP(Q|L|W|B)load [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> + (CMP(Q|L|W|B)load [off1+off2] {mergeSym(sym1,sym2)} base val mem) +(CMP(Q|L|W|B)constload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) + && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> + (CMP(Q|L|W|B)constload [off1+off2] {mergeSym(sym1,sym2)} base mem) + ((ADD|SUB|MUL|DIV)SSload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> ((ADD|SUB|MUL|DIV)SSload [off1+off2] {mergeSym(sym1,sym2)} val base mem) diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 1b531954dbbbc..3dd37088f10b4 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -141,24 +141,32 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64CMPB_0(v) case OpAMD64CMPBconst: return rewriteValueAMD64_OpAMD64CMPBconst_0(v) + case OpAMD64CMPBconstload: + return rewriteValueAMD64_OpAMD64CMPBconstload_0(v) case OpAMD64CMPBload: return rewriteValueAMD64_OpAMD64CMPBload_0(v) case OpAMD64CMPL: return rewriteValueAMD64_OpAMD64CMPL_0(v) case OpAMD64CMPLconst: return rewriteValueAMD64_OpAMD64CMPLconst_0(v) || rewriteValueAMD64_OpAMD64CMPLconst_10(v) + case OpAMD64CMPLconstload: + return rewriteValueAMD64_OpAMD64CMPLconstload_0(v) case OpAMD64CMPLload: return rewriteValueAMD64_OpAMD64CMPLload_0(v) case OpAMD64CMPQ: return rewriteValueAMD64_OpAMD64CMPQ_0(v) case OpAMD64CMPQconst: return rewriteValueAMD64_OpAMD64CMPQconst_0(v) || rewriteValueAMD64_OpAMD64CMPQconst_10(v) + case OpAMD64CMPQconstload: + return rewriteValueAMD64_OpAMD64CMPQconstload_0(v) case OpAMD64CMPQload: return rewriteValueAMD64_OpAMD64CMPQload_0(v) case OpAMD64CMPW: return rewriteValueAMD64_OpAMD64CMPW_0(v) case OpAMD64CMPWconst: return rewriteValueAMD64_OpAMD64CMPWconst_0(v) + case OpAMD64CMPWconstload: + return rewriteValueAMD64_OpAMD64CMPWconstload_0(v) case OpAMD64CMPWload: return rewriteValueAMD64_OpAMD64CMPWload_0(v) case OpAMD64CMPXCHGLlock: @@ -7932,7 +7940,112 @@ func rewriteValueAMD64_OpAMD64CMPBconst_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64CMPBconstload_0(v *Value) bool { + // match: (CMPBconstload [off1] {sym} (ADDQconst [off2] base) mem) + // cond: is32Bit(off1+off2) + // result: (CMPBconstload [off1+off2] {sym} base mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64CMPBconstload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (CMPBconstload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (CMPBconstload [off1+off2] {mergeSym(sym1,sym2)} base mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64CMPBconstload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64CMPBload_0(v *Value) bool { + // match: (CMPBload [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (CMPBload [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64CMPBload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (CMPBload [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (CMPBload [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64CMPBload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } // match: (CMPBload {sym} [off] ptr (MOVLconst [c]) mem) // cond: validValAndOff(int64(int8(c)),off) // result: (CMPBconstload {sym} [makeValAndOff(int64(int8(c)),off)] ptr mem) @@ -8249,7 +8362,112 @@ func rewriteValueAMD64_OpAMD64CMPLconst_10(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64CMPLconstload_0(v *Value) bool { + // match: (CMPLconstload [off1] {sym} (ADDQconst [off2] base) mem) + // cond: is32Bit(off1+off2) + // result: (CMPLconstload [off1+off2] {sym} base mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64CMPLconstload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (CMPLconstload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (CMPLconstload [off1+off2] {mergeSym(sym1,sym2)} base mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64CMPLconstload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64CMPLload_0(v *Value) bool { + // match: (CMPLload [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (CMPLload [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64CMPLload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (CMPLload [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (CMPLload [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64CMPLload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } // match: (CMPLload {sym} [off] ptr (MOVLconst [c]) mem) // cond: validValAndOff(c,off) // result: (CMPLconstload {sym} [makeValAndOff(c,off)] ptr mem) @@ -8689,7 +8907,112 @@ func rewriteValueAMD64_OpAMD64CMPQconst_10(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64CMPQconstload_0(v *Value) bool { + // match: (CMPQconstload [off1] {sym} (ADDQconst [off2] base) mem) + // cond: is32Bit(off1+off2) + // result: (CMPQconstload [off1+off2] {sym} base mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64CMPQconstload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (CMPQconstload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (CMPQconstload [off1+off2] {mergeSym(sym1,sym2)} base mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64CMPQconstload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64CMPQload_0(v *Value) bool { + // match: (CMPQload [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (CMPQload [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64CMPQload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (CMPQload [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (CMPQload [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64CMPQload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } // match: (CMPQload {sym} [off] ptr (MOVQconst [c]) mem) // cond: validValAndOff(c,off) // result: (CMPQconstload {sym} [makeValAndOff(c,off)] ptr mem) @@ -8987,7 +9310,112 @@ func rewriteValueAMD64_OpAMD64CMPWconst_0(v *Value) bool { } return false } +func rewriteValueAMD64_OpAMD64CMPWconstload_0(v *Value) bool { + // match: (CMPWconstload [off1] {sym} (ADDQconst [off2] base) mem) + // cond: is32Bit(off1+off2) + // result: (CMPWconstload [off1+off2] {sym} base mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64CMPWconstload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(mem) + return true + } + // match: (CMPWconstload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (CMPWconstload [off1+off2] {mergeSym(sym1,sym2)} base mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64CMPWconstload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(mem) + return true + } + return false +} func rewriteValueAMD64_OpAMD64CMPWload_0(v *Value) bool { + // match: (CMPWload [off1] {sym} (ADDQconst [off2] base) val mem) + // cond: is32Bit(off1+off2) + // result: (CMPWload [off1+off2] {sym} base val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64ADDQconst { + break + } + off2 := v_0.AuxInt + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1 + off2)) { + break + } + v.reset(OpAMD64CMPWload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (CMPWload [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) + // result: (CMPWload [off1+off2] {mergeSym(sym1,sym2)} base val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpAMD64LEAQ { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + base := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + break + } + v.reset(OpAMD64CMPWload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(base) + v.AddArg(val) + v.AddArg(mem) + return true + } // match: (CMPWload {sym} [off] ptr (MOVLconst [c]) mem) // cond: validValAndOff(int64(int16(c)),off) // result: (CMPWconstload {sym} [makeValAndOff(int64(int16(c)),off)] ptr mem) diff --git a/test/codegen/memops.go b/test/codegen/memops.go new file mode 100644 index 0000000000000..223375ac11fd5 --- /dev/null +++ b/test/codegen/memops.go @@ -0,0 +1,86 @@ +// asmcheck + +// Copyright 2018 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. + +package codegen + +var x [2]bool +var x8 [2]uint8 +var x16 [2]uint16 +var x32 [2]uint32 +var x64 [2]uint64 + +func compMem1() int { + // amd64:`CMPB\t"".x\+1\(SB\), [$]0` + if x[1] { + return 1 + } + // amd64:`CMPB\t"".x8\+1\(SB\), [$]7` + if x8[1] == 7 { + return 1 + } + // amd64:`CMPW\t"".x16\+2\(SB\), [$]7` + if x16[1] == 7 { + return 1 + } + // amd64:`CMPL\t"".x32\+4\(SB\), [$]7` + if x32[1] == 7 { + return 1 + } + // amd64:`CMPQ\t"".x64\+8\(SB\), [$]7` + if x64[1] == 7 { + return 1 + } + return 0 +} + +//go:noinline +func f(x int) bool { + return false +} + +//go:noinline +func f8(x int) int8 { + return 0 +} + +//go:noinline +func f16(x int) int16 { + return 0 +} + +//go:noinline +func f32(x int) int32 { + return 0 +} + +//go:noinline +func f64(x int) int64 { + return 0 +} + +func compMem2() int { + // amd64:`CMPB\t8\(SP\), [$]0` + if f(3) { + return 1 + } + // amd64:`CMPB\t8\(SP\), [$]7` + if f8(3) == 7 { + return 1 + } + // amd64:`CMPW\t8\(SP\), [$]7` + if f16(3) == 7 { + return 1 + } + // amd64:`CMPL\t8\(SP\), [$]7` + if f32(3) == 7 { + return 1 + } + // amd64:`CMPQ\t8\(SP\), [$]7` + if f64(3) == 7 { + return 1 + } + return 0 +} From 0e21cc2ba0823f2130d950eccf7c023b161d1331 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 14 Sep 2018 10:04:12 -0700 Subject: [PATCH 0374/1663] runtime: use CleanCmdEnv in TestRuntimePanic This makes TestRuntimePanic keep most of the existing environment, just as the other runtime tests do. Change-Id: I7944abfeee292d41716dca14483134a50d75f081 Reviewed-on: https://go-review.googlesource.com/135376 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/runtime/crash_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/crash_test.go b/src/runtime/crash_test.go index 2766b8850af33..6835cacb3f782 100644 --- a/src/runtime/crash_test.go +++ b/src/runtime/crash_test.go @@ -686,7 +686,7 @@ func init() { func TestRuntimePanic(t *testing.T) { testenv.MustHaveExec(t) - cmd := exec.Command(os.Args[0], "-test.run=TestRuntimePanic") + cmd := testenv.CleanCmdEnv(exec.Command(os.Args[0], "-test.run=TestRuntimePanic")) cmd.Env = append(cmd.Env, "GO_TEST_RUNTIME_PANIC=1") out, err := cmd.CombinedOutput() t.Logf("%s", out) From 7df585d13d6b85b58045c00460f7c9fed7ecb2ae Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Sun, 1 Jul 2018 01:35:38 +0530 Subject: [PATCH 0375/1663] time: improve error message for LoadLocation Currently, when a tz file was being checked inside a zoneInfo dir, a syscall.ENOENT error was being returned, which caused it to look in the zoneinfo.zip file and return an error for that case. We return a syscall.ENOENT error for the zip file case too, so that it falls through to the end of the loop and returns an uniform error for both cases. Fixes #20969 Change-Id: If1de068022ac7693caabb5cffd1c929878460140 Reviewed-on: https://go-review.googlesource.com/121877 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/time/zoneinfo_read.go | 2 +- src/time/zoneinfo_test.go | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/time/zoneinfo_read.go b/src/time/zoneinfo_read.go index 29244db29ec67..15d6aab1dee2f 100644 --- a/src/time/zoneinfo_read.go +++ b/src/time/zoneinfo_read.go @@ -364,7 +364,7 @@ func loadTzinfoFromZip(zipfile, name string) ([]byte, error) { return buf, nil } - return nil, errors.New("cannot find " + name + " in zip file " + zipfile) + return nil, syscall.ENOENT } // loadTzinfoFromTzdata returns the time zone information of the time zone diff --git a/src/time/zoneinfo_test.go b/src/time/zoneinfo_test.go index 450f5aa114aaa..4458ba8e26e1a 100644 --- a/src/time/zoneinfo_test.go +++ b/src/time/zoneinfo_test.go @@ -5,6 +5,7 @@ package time_test import ( + "errors" "fmt" "os" "reflect" @@ -36,6 +37,16 @@ func TestEnvVarUsage(t *testing.T) { } } +func TestBadLocationErrMsg(t *testing.T) { + time.ResetZoneinfoForTesting() + loc := "Asia/SomethingNotExist" + want := errors.New("unknown time zone " + loc) + _, err := time.LoadLocation(loc) + if err.Error() != want.Error() { + t.Errorf("LoadLocation(%q) error = %v; want %v", loc, err, want) + } +} + func TestLoadLocationValidatesNames(t *testing.T) { time.ResetZoneinfoForTesting() const env = "ZONEINFO" From 58c6afe075d74261dd67750e0aab5a1b8460839f Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Wed, 12 Sep 2018 13:58:18 -0400 Subject: [PATCH 0376/1663] doc/go1.11, cmd/go: elaborate on new GOFLAGS environment variable In Go 1.11, cmd/go gained support for the GOFLAGS environment variable. It was added and described in detail in CL 126656. Mention it in the Go 1.11 release notes, link to the cmd/go documentation, and add more details there. Fixes #27282. Change-Id: Ifc35bfe3e0886a145478d36dde8e80aedd8ec68e Reviewed-on: https://go-review.googlesource.com/135035 Reviewed-by: Bryan C. Mills Reviewed-by: Rob Pike --- doc/go1.11.html | 14 ++++++++++++++ src/cmd/go/alldocs.go | 6 ++++++ src/cmd/go/internal/help/helpdoc.go | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/doc/go1.11.html b/doc/go1.11.html index afe19397663af..16b4c904cb332 100644 --- a/doc/go1.11.html +++ b/doc/go1.11.html @@ -348,6 +348,20 @@

Cgo

details.

+

Go command

+ +

+ The environment variable GOFLAGS may now be used + to set default flags for the go command. + This is useful in certain situations. + Linking can be noticeably slower on underpowered systems due to DWARF, + and users may want to set -ldflags=-w by default. + For modules, some users and CI systems will want vendoring always, + so they should set -mod=vendor by default. + For more information, see the go + command documentation. +

+

Godoc

diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 35cabcac14373..969d51f5ab581 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -1449,6 +1449,12 @@ // The directory where the go command will write // temporary source files, packages, and binaries. // +// Each entry in the GOFLAGS list must be a standalone flag. +// Because the entries are space-separated, flag values must +// not contain spaces. In some cases, you can provide multiple flag +// values instead: for example, to set '-ldflags=-s -w' +// you can use 'GOFLAGS=-ldflags=-s -ldflags=-w'. +// // Environment variables for use with cgo: // // CC diff --git a/src/cmd/go/internal/help/helpdoc.go b/src/cmd/go/internal/help/helpdoc.go index aff4ce12f6c9a..e2c4e61615bcc 100644 --- a/src/cmd/go/internal/help/helpdoc.go +++ b/src/cmd/go/internal/help/helpdoc.go @@ -507,6 +507,12 @@ General-purpose environment variables: The directory where the go command will write temporary source files, packages, and binaries. +Each entry in the GOFLAGS list must be a standalone flag. +Because the entries are space-separated, flag values must +not contain spaces. In some cases, you can provide multiple flag +values instead: for example, to set '-ldflags=-s -w' +you can use 'GOFLAGS=-ldflags=-s -ldflags=-w'. + Environment variables for use with cgo: CC From 1bf5796cae9e8f7b55402f199a1eec82a092abb7 Mon Sep 17 00:00:00 2001 From: Ben Burkert Date: Wed, 5 Sep 2018 10:20:26 -0700 Subject: [PATCH 0377/1663] internal/poll: fall back on unsupported splice from unix socket Gracefully fallback to a userspace copy when the kernel does not support splice(2) on a unix domain socket. EINVAL is returned by the splice syscall if it does not support unix domain sockets. Keeping the handled return value as false when the first splice call fails with EINVAL will cause the caller to fall back to a userspace copy. Fixes #27513 Change-Id: I4b10c1900ba3c096cb32edb7c8a6044f468efb52 Reviewed-on: https://go-review.googlesource.com/133575 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Tobias Klauser --- src/internal/poll/splice_linux.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/internal/poll/splice_linux.go b/src/internal/poll/splice_linux.go index aa237e587adab..9ba94d648b684 100644 --- a/src/internal/poll/splice_linux.go +++ b/src/internal/poll/splice_linux.go @@ -32,8 +32,6 @@ func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string, return 0, false, sc, err } defer destroyTempPipe(prfd, pwfd) - // From here on, the operation should be considered handled, - // even if Splice doesn't transfer any data. var inPipe, n int for err == nil && remain > 0 { max := maxSpliceSize @@ -41,6 +39,12 @@ func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string, max = int(remain) } inPipe, err = spliceDrain(pwfd, src, max) + // the operation is considered handled if splice returns no error, or + // an error other than EINVAL. An EINVAL means the kernel does not + // support splice for the socket type of dst and/or src. The failed + // syscall does not consume any data so it is safe to fall back to a + // generic copy. + handled = handled || (err != syscall.EINVAL) // spliceDrain should never return EAGAIN, so if err != nil, // Splice cannot continue. If inPipe == 0 && err == nil, // src is at EOF, and the transfer is complete. @@ -54,7 +58,7 @@ func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string, } } if err != nil { - return written, true, "splice", err + return written, handled, "splice", err } return written, true, "", nil } From 0670b28bf031c5f33ca9831ee894e67bcd79c64c Mon Sep 17 00:00:00 2001 From: Koichi Shiraishi Date: Sat, 15 Sep 2018 17:06:08 +0900 Subject: [PATCH 0378/1663] runtime: fix TODO comment filepath The cmd/compile/internal/ld/go.go file not exist, actually cmd/link/internal/ld/go.go. Also, write line number is not good because it changes every commit of the file. Change-Id: Id2b9f2c9904390adb011dab357716ee8e2fe84fc Reviewed-on: https://go-review.googlesource.com/135516 Reviewed-by: Ian Lance Taylor --- src/runtime/sys_darwin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/sys_darwin.go b/src/runtime/sys_darwin.go index 7efbef746cd83..9b0cc6f9350a9 100644 --- a/src/runtime/sys_darwin.go +++ b/src/runtime/sys_darwin.go @@ -370,5 +370,5 @@ func closeonexec(fd int32) { //go:cgo_import_dynamic libc_pthread_cond_signal pthread_cond_signal "/usr/lib/libSystem.B.dylib" // Magic incantation to get libSystem actually dynamically linked. -// TODO: Why does the code require this? See cmd/compile/internal/ld/go.go:210 +// TODO: Why does the code require this? See cmd/link/internal/ld/go.go //go:cgo_import_dynamic _ _ "/usr/lib/libSystem.B.dylib" From fb061b5e116d1e176039f0948221e8a107a401cd Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 14 Sep 2018 15:11:51 -0700 Subject: [PATCH 0379/1663] time: return ENOENT from androidLoadTzinfoFromTzdata if zone not found This makes Android consistent with the change in CL 121877. Updates #20969 Change-Id: I1f114556fd1d4654c8e4e6a59513bddd5dc3d1a0 Reviewed-on: https://go-review.googlesource.com/135416 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Elias Naur --- src/time/zoneinfo_android.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/time/zoneinfo_android.go b/src/time/zoneinfo_android.go index 65e0975ab02a1..237ff202f913f 100644 --- a/src/time/zoneinfo_android.go +++ b/src/time/zoneinfo_android.go @@ -11,6 +11,7 @@ package time import ( "errors" "runtime" + "syscall" ) var zoneSources = []string{ @@ -75,5 +76,5 @@ func androidLoadTzinfoFromTzdata(file, name string) ([]byte, error) { } return buf, nil } - return nil, errors.New("cannot find " + name + " in tzdata file " + file) + return nil, syscall.ENOENT } From 83c605fb96b694455ca3c7c3d69bc6e4f526268e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Tudor=20C=C4=83lin?= Date: Sat, 15 Sep 2018 18:31:49 +0200 Subject: [PATCH 0380/1663] internal/poll: improve Splice comments Clarify the behavior of splice on older kernels, merge comments so control flow becomes more obvious, as discussed in CL 133575. Change-Id: I95855991bd0b1fa1c78a900b39c4382f65d83468 Reviewed-on: https://go-review.googlesource.com/135436 Reviewed-by: Ian Lance Taylor --- src/internal/poll/splice_linux.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/internal/poll/splice_linux.go b/src/internal/poll/splice_linux.go index 9ba94d648b684..4f97298417c3d 100644 --- a/src/internal/poll/splice_linux.go +++ b/src/internal/poll/splice_linux.go @@ -39,15 +39,18 @@ func Splice(dst, src *FD, remain int64) (written int64, handled bool, sc string, max = int(remain) } inPipe, err = spliceDrain(pwfd, src, max) - // the operation is considered handled if splice returns no error, or - // an error other than EINVAL. An EINVAL means the kernel does not - // support splice for the socket type of dst and/or src. The failed - // syscall does not consume any data so it is safe to fall back to a - // generic copy. - handled = handled || (err != syscall.EINVAL) + // The operation is considered handled if splice returns no + // error, or an error other than EINVAL. An EINVAL means the + // kernel does not support splice for the socket type of src. + // The failed syscall does not consume any data so it is safe + // to fall back to a generic copy. + // // spliceDrain should never return EAGAIN, so if err != nil, - // Splice cannot continue. If inPipe == 0 && err == nil, - // src is at EOF, and the transfer is complete. + // Splice cannot continue. + // + // If inPipe == 0 && err == nil, src is at EOF, and the + // transfer is complete. + handled = handled || (err != syscall.EINVAL) if err != nil || (inPipe == 0 && err == nil) { break } From adcecbe05ef812bc8ff477dec47720a2cfc273e3 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Sun, 16 Sep 2018 11:14:19 +1000 Subject: [PATCH 0381/1663] doc: add a go/golang entry to the FAQ It's worth clarifying that the language is called "Go". Fixes #27616. Change-Id: Ie4a9cb5e7e6afa437c60e06914125ef7490f27d0 Reviewed-on: https://go-review.googlesource.com/135517 Reviewed-by: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick --- doc/go_faq.html | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/doc/go_faq.html b/doc/go_faq.html index b1c15295d62e2..7c4263b090377 100644 --- a/doc/go_faq.html +++ b/doc/go_faq.html @@ -108,6 +108,26 @@

He has unique features; he's the Go gopher, not just any old gopher.

+

+Is the language called Go or Golang?

+ +

+The language is called Go. +The "golang" moniker arose because the web site is +golang.org, not +go.org, which was not available to us. +Many use the golang name, though, and it is handy as +a label. +For instance, the Twitter tag for the language is "#golang". +The language's name is just plain Go, regardless. +

+ +

+A side note: Although the +official logo +has two capital letters, the language name is written Go, not GO. +

+

Why did you create a new language?

From 930ce09ca3a1ab5f886c2327fc143b9ae075807b Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Mon, 10 Sep 2018 09:27:47 +0100 Subject: [PATCH 0382/1663] image/png: minor cleanup of a few tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes a redundant err check and replaces some returns in a testing loop with continue to prevent skipping unrelated test cases when a failure is encountered. Change-Id: Ic1a560751b95bb0ef8dfa957e057e0fa0c2b281d Reviewed-on: https://go-review.googlesource.com/134236 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Daniel Martí --- src/image/png/reader_test.go | 4 ---- src/image/png/writer_test.go | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/image/png/reader_test.go b/src/image/png/reader_test.go index 66bcfcb437eb2..33dcd3debcc96 100644 --- a/src/image/png/reader_test.go +++ b/src/image/png/reader_test.go @@ -364,10 +364,6 @@ func TestReader(t *testing.T) { } defer sf.Close() sb := bufio.NewScanner(sf) - if err != nil { - t.Error(fn, err) - continue - } // Compare the two, in SNG format, line by line. for { diff --git a/src/image/png/writer_test.go b/src/image/png/writer_test.go index 1107ea0e7fc24..6c5e942310ecd 100644 --- a/src/image/png/writer_test.go +++ b/src/image/png/writer_test.go @@ -61,12 +61,12 @@ func TestWriter(t *testing.T) { m1, err := readPNG(qfn) if err != nil { t.Error(fn, err) - return + continue } m2, err := encodeDecode(m1) if err != nil { t.Error(fn, err) - return + continue } // Compare the two. err = diff(m0, m2) From 2d82465d18520820c52fea6b5e400a692ffdb92a Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Wed, 5 Sep 2018 18:49:52 +0300 Subject: [PATCH 0383/1663] cmd/compile/internal/gc: treat cap/len as safe in mayAffectMemory OLEN and OCAP can't affect memory state as long as their arguments don't. Re-organized case bodies to avoid duplicating same branches for recursive invocations. Change-Id: I30407143429f7dd1891badb70df88969ed267535 Reviewed-on: https://go-review.googlesource.com/133555 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/gc/esc.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go index 9db6c8e0b4b96..254427be4fd92 100644 --- a/src/cmd/compile/internal/gc/esc.go +++ b/src/cmd/compile/internal/gc/esc.go @@ -689,18 +689,16 @@ func (e *EscState) mayAffectMemory(n *Node) bool { switch n.Op { case ONAME, OCLOSUREVAR, OLITERAL: return false - case ODOT, ODOTPTR: - return e.mayAffectMemory(n.Left) - case OIND, OCONVNOP: - return e.mayAffectMemory(n.Left) - case OCONV: - return e.mayAffectMemory(n.Left) - case OINDEX: - return e.mayAffectMemory(n.Left) || e.mayAffectMemory(n.Right) - case OADD, OSUB, OOR, OXOR, OMUL, OLSH, ORSH, OAND, OANDNOT, ODIV, OMOD: + + // Left+Right group. + case OINDEX, OADD, OSUB, OOR, OXOR, OMUL, OLSH, ORSH, OAND, OANDNOT, ODIV, OMOD: return e.mayAffectMemory(n.Left) || e.mayAffectMemory(n.Right) - case ONOT, OCOM, OPLUS, OMINUS, OALIGNOF, OOFFSETOF, OSIZEOF: + + // Left group. + case ODOT, ODOTPTR, OIND, OCONVNOP, OCONV, OLEN, OCAP, + ONOT, OCOM, OPLUS, OMINUS, OALIGNOF, OOFFSETOF, OSIZEOF: return e.mayAffectMemory(n.Left) + default: return true } From 859cf7fc0f4535ab3cdec15c81860f5fd2ae5b01 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Tue, 4 Sep 2018 23:14:53 +0300 Subject: [PATCH 0384/1663] cmd/compile/internal/gc: handle array slice self-assign in esc.go Instead of skipping all OSLICEARR, skip only ones with non-pointer array type. For pointers to arrays, it's safe to apply the self-assignment slicing optimizations. Refactored the matching code into separate function for readability. This is an extension to already existing optimization. On its own, it does not improve any code under std, but it opens some new optimization opportunities. One of them is described in the referenced issue. Updates #7921 Change-Id: I08ac660d3ef80eb15fd7933fb73cf53ded9333ad Reviewed-on: https://go-review.googlesource.com/133375 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/gc/esc.go | 95 +++++++++++++++++++----------- test/escape2.go | 16 +++-- test/escape2n.go | 16 +++-- 3 files changed, 82 insertions(+), 45 deletions(-) diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go index 254427be4fd92..cd85a38eb6c42 100644 --- a/src/cmd/compile/internal/gc/esc.go +++ b/src/cmd/compile/internal/gc/esc.go @@ -654,9 +654,67 @@ func (e *EscState) esclist(l Nodes, parent *Node) { } } +func (e *EscState) isSliceSelfAssign(dst, src *Node) bool { + // Detect the following special case. + // + // func (b *Buffer) Foo() { + // n, m := ... + // b.buf = b.buf[n:m] + // } + // + // This assignment is a no-op for escape analysis, + // it does not store any new pointers into b that were not already there. + // However, without this special case b will escape, because we assign to OIND/ODOTPTR. + // Here we assume that the statement will not contain calls, + // that is, that order will move any calls to init. + // Otherwise base ONAME value could change between the moments + // when we evaluate it for dst and for src. + + // dst is ONAME dereference. + if dst.Op != OIND && dst.Op != ODOTPTR || dst.Left.Op != ONAME { + return false + } + // src is a slice operation. + switch src.Op { + case OSLICE, OSLICE3, OSLICESTR: + // OK. + case OSLICEARR, OSLICE3ARR: + // Since arrays are embedded into containing object, + // slice of non-pointer array will introduce a new pointer into b that was not already there + // (pointer to b itself). After such assignment, if b contents escape, + // b escapes as well. If we ignore such OSLICEARR, we will conclude + // that b does not escape when b contents do. + // + // Pointer to an array is OK since it's not stored inside b directly. + // For slicing an array (not pointer to array), there is an implicit OADDR. + // We check that to determine non-pointer array slicing. + if src.Left.Op == OADDR { + return false + } + default: + return false + } + // slice is applied to ONAME dereference. + if src.Left.Op != OIND && src.Left.Op != ODOTPTR || src.Left.Left.Op != ONAME { + return false + } + // dst and src reference the same base ONAME. + return dst.Left == src.Left.Left +} + // isSelfAssign reports whether assignment from src to dst can // be ignored by the escape analysis as it's effectively a self-assignment. func (e *EscState) isSelfAssign(dst, src *Node) bool { + // Detect trivial assignments that assign back to the same object. + // + // It covers these cases: + // val.x = val.y + // val.x[i] = val.y[j] + // val.x1.x2 = val.x1.y2 + // ... etc + // + // These assignments do not change assigned object lifetime. + if dst == nil || src == nil || dst.Op != src.Op { return false } @@ -830,48 +888,15 @@ opSwitch: } } - // Filter out the following special case. - // - // func (b *Buffer) Foo() { - // n, m := ... - // b.buf = b.buf[n:m] - // } - // - // This assignment is a no-op for escape analysis, - // it does not store any new pointers into b that were not already there. - // However, without this special case b will escape, because we assign to OIND/ODOTPTR. case OAS, OASOP: - if (n.Left.Op == OIND || n.Left.Op == ODOTPTR) && n.Left.Left.Op == ONAME && // dst is ONAME dereference - (n.Right.Op == OSLICE || n.Right.Op == OSLICE3 || n.Right.Op == OSLICESTR) && // src is slice operation - (n.Right.Left.Op == OIND || n.Right.Left.Op == ODOTPTR) && n.Right.Left.Left.Op == ONAME && // slice is applied to ONAME dereference - n.Left.Left == n.Right.Left.Left { // dst and src reference the same base ONAME - - // Here we also assume that the statement will not contain calls, - // that is, that order will move any calls to init. - // Otherwise base ONAME value could change between the moments - // when we evaluate it for dst and for src. - // - // Note, this optimization does not apply to OSLICEARR, - // because it does introduce a new pointer into b that was not already there - // (pointer to b itself). After such assignment, if b contents escape, - // b escapes as well. If we ignore such OSLICEARR, we will conclude - // that b does not escape when b contents do. + // Filter out some no-op assignments for escape analysis. + if e.isSliceSelfAssign(n.Left, n.Right) { if Debug['m'] != 0 { Warnl(n.Pos, "%v ignoring self-assignment to %S", e.curfnSym(n), n.Left) } break } - - // Also skip trivial assignments that assign back to the same object. - // - // It covers these cases: - // val.x = val.y - // val.x[i] = val.y[j] - // val.x1.x2 = val.x1.y2 - // ... etc - // - // These assignments do not change assigned object lifetime. if e.isSelfAssign(n.Left, n.Right) { if Debug['m'] != 0 { Warnl(n.Pos, "%v ignoring self-assignment in %S", e.curfnSym(n), n) diff --git a/test/escape2.go b/test/escape2.go index ef3d6a88bf382..5c4c803249f6d 100644 --- a/test/escape2.go +++ b/test/escape2.go @@ -1593,11 +1593,12 @@ func ptrlitEscape() { // self-assignments type Buffer struct { - arr [64]byte - buf1 []byte - buf2 []byte - str1 string - str2 string + arr [64]byte + arrPtr *[64]byte + buf1 []byte + buf2 []byte + str1 string + str2 string } func (b *Buffer) foo() { // ERROR "\(\*Buffer\).foo b does not escape$" @@ -1611,6 +1612,11 @@ func (b *Buffer) bar() { // ERROR "leaking param: b$" b.buf1 = b.arr[1:2] // ERROR "b.arr escapes to heap$" } +func (b *Buffer) arrayPtr() { // ERROR "\(\*Buffer\).arrayPtr b does not escape" + b.buf1 = b.arrPtr[1:2] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment to b.buf1" + b.buf1 = b.arrPtr[1:2:3] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment to b.buf1" +} + func (b *Buffer) baz() { // ERROR "\(\*Buffer\).baz b does not escape$" b.str1 = b.str1[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment to b.str1$" b.str1 = b.str2[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment to b.str1$" diff --git a/test/escape2n.go b/test/escape2n.go index b1130d3c3c9d3..4b1ca1eab8b7b 100644 --- a/test/escape2n.go +++ b/test/escape2n.go @@ -1593,11 +1593,12 @@ func ptrlitEscape() { // self-assignments type Buffer struct { - arr [64]byte - buf1 []byte - buf2 []byte - str1 string - str2 string + arr [64]byte + arrPtr *[64]byte + buf1 []byte + buf2 []byte + str1 string + str2 string } func (b *Buffer) foo() { // ERROR "\(\*Buffer\).foo b does not escape$" @@ -1611,6 +1612,11 @@ func (b *Buffer) bar() { // ERROR "leaking param: b$" b.buf1 = b.arr[1:2] // ERROR "b.arr escapes to heap$" } +func (b *Buffer) arrayPtr() { // ERROR "\(\*Buffer\).arrayPtr b does not escape" + b.buf1 = b.arrPtr[1:2] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment to b.buf1" + b.buf1 = b.arrPtr[1:2:3] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment to b.buf1" +} + func (b *Buffer) baz() { // ERROR "\(\*Buffer\).baz b does not escape$" b.str1 = b.str1[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment to b.str1$" b.str1 = b.str2[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment to b.str1$" From 2db1a7f929892695696eebf685fc484841c08cb4 Mon Sep 17 00:00:00 2001 From: Michael Munday Date: Wed, 12 Sep 2018 12:16:50 +0100 Subject: [PATCH 0385/1663] cmd/compile: avoid more float32 <-> float64 conversions in compiler Use the new custom truncate/extension code when storing or extracting float32 values from AuxInts to avoid the value being changed by the host platform's floating point conversion instructions (e.g. sNaN -> qNaN). Updates #27516. Change-Id: Id39650f1431ef74af088c895cf4738ea5fa87974 Reviewed-on: https://go-review.googlesource.com/134855 Run-TryBot: Michael Munday TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/gen/386.rules | 4 +- src/cmd/compile/internal/ssa/gen/AMD64.rules | 4 +- src/cmd/compile/internal/ssa/gen/PPC64.rules | 10 +- src/cmd/compile/internal/ssa/gen/Wasm.rules | 4 +- .../compile/internal/ssa/gen/generic.rules | 79 +++--- src/cmd/compile/internal/ssa/rewrite.go | 23 +- src/cmd/compile/internal/ssa/rewrite386.go | 8 +- src/cmd/compile/internal/ssa/rewriteAMD64.go | 8 +- src/cmd/compile/internal/ssa/rewritePPC64.go | 20 +- src/cmd/compile/internal/ssa/rewriteWasm.go | 8 +- .../compile/internal/ssa/rewritegeneric.go | 240 +++++++++--------- src/cmd/compile/internal/ssa/softfloat.go | 2 +- 12 files changed, 209 insertions(+), 201 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/386.rules b/src/cmd/compile/internal/ssa/gen/386.rules index 2a05732c989f2..f6aa37e884c0f 100644 --- a/src/cmd/compile/internal/ssa/gen/386.rules +++ b/src/cmd/compile/internal/ssa/gen/386.rules @@ -44,8 +44,8 @@ (Xor(32|16|8) x y) -> (XORL x y) (Neg(32|16|8) x) -> (NEGL x) -(Neg32F x) && !config.use387 -> (PXOR x (MOVSSconst [f2i(math.Copysign(0, -1))])) -(Neg64F x) && !config.use387 -> (PXOR x (MOVSDconst [f2i(math.Copysign(0, -1))])) +(Neg32F x) && !config.use387 -> (PXOR x (MOVSSconst [auxFrom32F(float32(math.Copysign(0, -1)))])) +(Neg64F x) && !config.use387 -> (PXOR x (MOVSDconst [auxFrom64F(math.Copysign(0, -1))])) (Neg32F x) && config.use387 -> (FCHS x) (Neg64F x) && config.use387 -> (FCHS x) diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index 0eba5f03cdbcb..3247bb72b5b8b 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -41,8 +41,8 @@ (Com(64|32|16|8) x) -> (NOT(Q|L|L|L) x) (Neg(64|32|16|8) x) -> (NEG(Q|L|L|L) x) -(Neg32F x) -> (PXOR x (MOVSSconst [f2i(math.Copysign(0, -1))])) -(Neg64F x) -> (PXOR x (MOVSDconst [f2i(math.Copysign(0, -1))])) +(Neg32F x) -> (PXOR x (MOVSSconst [auxFrom32F(float32(math.Copysign(0, -1)))])) +(Neg64F x) -> (PXOR x (MOVSDconst [auxFrom64F(math.Copysign(0, -1))])) // Lowering boolean ops (AndB x y) -> (ANDL x y) diff --git a/src/cmd/compile/internal/ssa/gen/PPC64.rules b/src/cmd/compile/internal/ssa/gen/PPC64.rules index 2e06fcd83df35..bc218444c0838 100644 --- a/src/cmd/compile/internal/ssa/gen/PPC64.rules +++ b/src/cmd/compile/internal/ssa/gen/PPC64.rules @@ -74,11 +74,11 @@ (ConstBool [b]) -> (MOVDconst [b]) // Constant folding -(FABS (FMOVDconst [x])) -> (FMOVDconst [f2i(math.Abs(i2f(x)))]) -(FSQRT (FMOVDconst [x])) -> (FMOVDconst [f2i(math.Sqrt(i2f(x)))]) -(FFLOOR (FMOVDconst [x])) -> (FMOVDconst [f2i(math.Floor(i2f(x)))]) -(FCEIL (FMOVDconst [x])) -> (FMOVDconst [f2i(math.Ceil(i2f(x)))]) -(FTRUNC (FMOVDconst [x])) -> (FMOVDconst [f2i(math.Trunc(i2f(x)))]) +(FABS (FMOVDconst [x])) -> (FMOVDconst [auxFrom64F(math.Abs(auxTo64F(x)))]) +(FSQRT (FMOVDconst [x])) -> (FMOVDconst [auxFrom64F(math.Sqrt(auxTo64F(x)))]) +(FFLOOR (FMOVDconst [x])) -> (FMOVDconst [auxFrom64F(math.Floor(auxTo64F(x)))]) +(FCEIL (FMOVDconst [x])) -> (FMOVDconst [auxFrom64F(math.Ceil(auxTo64F(x)))]) +(FTRUNC (FMOVDconst [x])) -> (FMOVDconst [auxFrom64F(math.Trunc(auxTo64F(x)))]) // Rotate generation with const shift (ADD (SLDconst x [c]) (SRDconst x [d])) && d == 64-c -> (ROTLconst [c] x) diff --git a/src/cmd/compile/internal/ssa/gen/Wasm.rules b/src/cmd/compile/internal/ssa/gen/Wasm.rules index dc1581362c6d5..64198839d0991 100644 --- a/src/cmd/compile/internal/ssa/gen/Wasm.rules +++ b/src/cmd/compile/internal/ssa/gen/Wasm.rules @@ -363,8 +363,8 @@ (I64And (I64Const [x]) (I64Const [y])) -> (I64Const [x & y]) (I64Or (I64Const [x]) (I64Const [y])) -> (I64Const [x | y]) (I64Xor (I64Const [x]) (I64Const [y])) -> (I64Const [x ^ y]) -(F64Add (F64Const [x]) (F64Const [y])) -> (F64Const [f2i(i2f(x) + i2f(y))]) -(F64Mul (F64Const [x]) (F64Const [y])) -> (F64Const [f2i(i2f(x) * i2f(y))]) +(F64Add (F64Const [x]) (F64Const [y])) -> (F64Const [auxFrom64F(auxTo64F(x) + auxTo64F(y))]) +(F64Mul (F64Const [x]) (F64Const [y])) -> (F64Const [auxFrom64F(auxTo64F(x) * auxTo64F(y))]) (I64Eq (I64Const [x]) (I64Const [y])) && x == y -> (I64Const [1]) (I64Eq (I64Const [x]) (I64Const [y])) && x != y -> (I64Const [0]) (I64Ne (I64Const [x]) (I64Const [y])) && x == y -> (I64Const [0]) diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index d0d49c7b8fd71..e9677b15c7a57 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -44,16 +44,16 @@ (Trunc64to8 (Const64 [c])) -> (Const8 [int64(int8(c))]) (Trunc64to16 (Const64 [c])) -> (Const16 [int64(int16(c))]) (Trunc64to32 (Const64 [c])) -> (Const32 [int64(int32(c))]) -(Cvt64Fto32F (Const64F [c])) -> (Const32F [f2i(float64(i2f32(c)))]) +(Cvt64Fto32F (Const64F [c])) -> (Const32F [auxFrom32F(float32(auxTo64F(c)))]) (Cvt32Fto64F (Const32F [c])) -> (Const64F [c]) // c is already a 64 bit float -(Cvt32to32F (Const32 [c])) -> (Const32F [f2i(float64(float32(int32(c))))]) -(Cvt32to64F (Const32 [c])) -> (Const64F [f2i(float64(int32(c)))]) -(Cvt64to32F (Const64 [c])) -> (Const32F [f2i(float64(float32(c)))]) -(Cvt64to64F (Const64 [c])) -> (Const64F [f2i(float64(c))]) -(Cvt32Fto32 (Const32F [c])) -> (Const32 [int64(int32(i2f(c)))]) -(Cvt32Fto64 (Const32F [c])) -> (Const64 [int64(i2f(c))]) -(Cvt64Fto32 (Const64F [c])) -> (Const32 [int64(int32(i2f(c)))]) -(Cvt64Fto64 (Const64F [c])) -> (Const64 [int64(i2f(c))]) +(Cvt32to32F (Const32 [c])) -> (Const32F [auxFrom32F(float32(int32(c)))]) +(Cvt32to64F (Const32 [c])) -> (Const64F [auxFrom64F(float64(int32(c)))]) +(Cvt64to32F (Const64 [c])) -> (Const32F [auxFrom32F(float32(c))]) +(Cvt64to64F (Const64 [c])) -> (Const64F [auxFrom64F(float64(c))]) +(Cvt32Fto32 (Const32F [c])) -> (Const32 [int64(int32(auxTo32F(c)))]) +(Cvt32Fto64 (Const32F [c])) -> (Const64 [int64(auxTo32F(c))]) +(Cvt64Fto32 (Const64F [c])) -> (Const32 [int64(int32(auxTo64F(c)))]) +(Cvt64Fto64 (Const64F [c])) -> (Const64 [int64(auxTo64F(c))]) (Round32F x:(Const32F)) -> x (Round64F x:(Const64F)) -> x @@ -95,16 +95,15 @@ (Neg16 (Const16 [c])) -> (Const16 [int64(-int16(c))]) (Neg32 (Const32 [c])) -> (Const32 [int64(-int32(c))]) (Neg64 (Const64 [c])) -> (Const64 [-c]) -(Neg32F (Const32F [c])) && i2f(c) != 0 -> (Const32F [f2i(-i2f(c))]) -(Neg64F (Const64F [c])) && i2f(c) != 0 -> (Const64F [f2i(-i2f(c))]) +(Neg32F (Const32F [c])) && auxTo32F(c) != 0 -> (Const32F [auxFrom32F(-auxTo32F(c))]) +(Neg64F (Const64F [c])) && auxTo64F(c) != 0 -> (Const64F [auxFrom64F(-auxTo64F(c))]) (Add8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c+d))]) (Add16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c+d))]) (Add32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c+d))]) (Add64 (Const64 [c]) (Const64 [d])) -> (Const64 [c+d]) -(Add32F (Const32F [c]) (Const32F [d])) -> - (Const32F [f2i(float64(i2f32(c) + i2f32(d)))]) // ensure we combine the operands with 32 bit precision -(Add64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) + i2f(d))]) +(Add32F (Const32F [c]) (Const32F [d])) -> (Const32F [auxFrom32F(auxTo32F(c) + auxTo32F(d))]) +(Add64F (Const64F [c]) (Const64F [d])) -> (Const64F [auxFrom64F(auxTo64F(c) + auxTo64F(d))]) (AddPtr x (Const64 [c])) -> (OffPtr x [c]) (AddPtr x (Const32 [c])) -> (OffPtr x [c]) @@ -112,17 +111,15 @@ (Sub16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c-d))]) (Sub32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c-d))]) (Sub64 (Const64 [c]) (Const64 [d])) -> (Const64 [c-d]) -(Sub32F (Const32F [c]) (Const32F [d])) -> - (Const32F [f2i(float64(i2f32(c) - i2f32(d)))]) -(Sub64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) - i2f(d))]) +(Sub32F (Const32F [c]) (Const32F [d])) -> (Const32F [auxFrom32F(auxTo32F(c) - auxTo32F(d))]) +(Sub64F (Const64F [c]) (Const64F [d])) -> (Const64F [auxFrom64F(auxTo64F(c) - auxTo64F(d))]) (Mul8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c*d))]) (Mul16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c*d))]) (Mul32 (Const32 [c]) (Const32 [d])) -> (Const32 [int64(int32(c*d))]) (Mul64 (Const64 [c]) (Const64 [d])) -> (Const64 [c*d]) -(Mul32F (Const32F [c]) (Const32F [d])) -> - (Const32F [f2i(float64(i2f32(c) * i2f32(d)))]) -(Mul64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) * i2f(d))]) +(Mul32F (Const32F [c]) (Const32F [d])) -> (Const32F [auxFrom32F(auxTo32F(c) * auxTo32F(d))]) +(Mul64F (Const64F [c]) (Const64F [d])) -> (Const64F [auxFrom64F(auxTo64F(c) * auxTo64F(d))]) (And8 (Const8 [c]) (Const8 [d])) -> (Const8 [int64(int8(c&d))]) (And16 (Const16 [c]) (Const16 [d])) -> (Const16 [int64(int16(c&d))]) @@ -147,8 +144,8 @@ (Div16u (Const16 [c]) (Const16 [d])) && d != 0 -> (Const16 [int64(int16(uint16(c)/uint16(d)))]) (Div32u (Const32 [c]) (Const32 [d])) && d != 0 -> (Const32 [int64(int32(uint32(c)/uint32(d)))]) (Div64u (Const64 [c]) (Const64 [d])) && d != 0 -> (Const64 [int64(uint64(c)/uint64(d))]) -(Div32F (Const32F [c]) (Const32F [d])) -> (Const32F [f2i(float64(i2f32(c) / i2f32(d)))]) -(Div64F (Const64F [c]) (Const64F [d])) -> (Const64F [f2i(i2f(c) / i2f(d))]) +(Div32F (Const32F [c]) (Const32F [d])) -> (Const32F [auxFrom32F(auxTo32F(c) / auxTo32F(d))]) +(Div64F (Const64F [c]) (Const64F [d])) -> (Const64F [auxFrom64F(auxTo64F(c) / auxTo64F(d))]) (Not (ConstBool [c])) -> (ConstBool [1-c]) @@ -444,12 +441,18 @@ (Leq8U (Const8 [c]) (Const8 [d])) -> (ConstBool [b2i(uint8(c) <= uint8(d))]) // constant floating point comparisons -(Eq(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) == i2f(d))]) -(Neq(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) != i2f(d))]) -(Greater(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) > i2f(d))]) -(Geq(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) >= i2f(d))]) -(Less(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) < i2f(d))]) -(Leq(64|32)F (Const(64|32)F [c]) (Const(64|32)F [d])) -> (ConstBool [b2i(i2f(c) <= i2f(d))]) +(Eq32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) == auxTo32F(d))]) +(Eq64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) == auxTo64F(d))]) +(Neq32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) != auxTo32F(d))]) +(Neq64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) != auxTo64F(d))]) +(Greater32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) > auxTo32F(d))]) +(Greater64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) > auxTo64F(d))]) +(Geq32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) >= auxTo32F(d))]) +(Geq64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) >= auxTo64F(d))]) +(Less32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) < auxTo32F(d))]) +(Less64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) < auxTo64F(d))]) +(Leq32F (Const32F [c]) (Const32F [d])) -> (ConstBool [b2i(auxTo32F(c) <= auxTo32F(d))]) +(Leq64F (Const64F [c]) (Const64F [d])) -> (ConstBool [b2i(auxTo64F(c) <= auxTo64F(d))]) // simplifications (Or(64|32|16|8) x x) -> x @@ -572,9 +575,9 @@ // Pass constants through math.Float{32,64}bits and math.Float{32,64}frombits (Load p1 (Store {t2} p2 (Const64 [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 8 && is64BitFloat(t1) -> (Const64F [x]) -(Load p1 (Store {t2} p2 (Const32 [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitFloat(t1) -> (Const32F [f2i(extend32Fto64F(math.Float32frombits(uint32(x))))]) +(Load p1 (Store {t2} p2 (Const32 [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitFloat(t1) -> (Const32F [auxFrom32F(math.Float32frombits(uint32(x)))]) (Load p1 (Store {t2} p2 (Const64F [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 8 && is64BitInt(t1) -> (Const64 [x]) -(Load p1 (Store {t2} p2 (Const32F [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitInt(t1) -> (Const32 [int64(int32(math.Float32bits(truncate64Fto32F(i2f(x)))))]) +(Load p1 (Store {t2} p2 (Const32F [x]) _)) && isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitInt(t1) -> (Const32 [int64(int32(math.Float32bits(auxTo32F(x))))]) // Float Loads up to Zeros so they can be constant folded. (Load op:(OffPtr [o1] p1) @@ -1329,16 +1332,16 @@ (Add(32|64)F x (Const(32|64)F [0])) -> x (Sub(32|64)F x (Const(32|64)F [0])) -> x -(Mul(32|64)F x (Const(32|64)F [f2i(1)])) -> x -(Mul32F x (Const32F [f2i(-1)])) -> (Neg32F x) -(Mul64F x (Const64F [f2i(-1)])) -> (Neg64F x) -(Mul32F x (Const32F [f2i(2)])) -> (Add32F x x) -(Mul64F x (Const64F [f2i(2)])) -> (Add64F x x) +(Mul(32|64)F x (Const(32|64)F [auxFrom64F(1)])) -> x +(Mul32F x (Const32F [auxFrom32F(-1)])) -> (Neg32F x) +(Mul64F x (Const64F [auxFrom64F(-1)])) -> (Neg64F x) +(Mul32F x (Const32F [auxFrom32F(2)])) -> (Add32F x x) +(Mul64F x (Const64F [auxFrom64F(2)])) -> (Add64F x x) -(Div32F x (Const32F [c])) && reciprocalExact32(float32(i2f(c))) -> (Mul32F x (Const32F [f2i(1/i2f(c))])) -(Div64F x (Const64F [c])) && reciprocalExact64(i2f(c)) -> (Mul64F x (Const64F [f2i(1/i2f(c))])) +(Div32F x (Const32F [c])) && reciprocalExact32(auxTo32F(c)) -> (Mul32F x (Const32F [auxFrom32F(1/auxTo32F(c))])) +(Div64F x (Const64F [c])) && reciprocalExact64(auxTo64F(c)) -> (Mul64F x (Const64F [auxFrom64F(1/auxTo64F(c))])) -(Sqrt (Const64F [c])) -> (Const64F [f2i(math.Sqrt(i2f(c)))]) +(Sqrt (Const64F [c])) -> (Const64F [auxFrom64F(math.Sqrt(auxTo64F(c)))]) // recognize runtime.newobject and don't Zero/Nilcheck it (Zero (Load (OffPtr [c] (SP)) mem) mem) diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index 18ad7e1e4ad3e..a5b2da4709177 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -450,19 +450,24 @@ func extend32Fto64F(f float32) float64 { return math.Float64frombits(r) } -// i2f is used in rules for converting from an AuxInt to a float. -func i2f(i int64) float64 { - return math.Float64frombits(uint64(i)) +// auxFrom64F encodes a float64 value so it can be stored in an AuxInt. +func auxFrom64F(f float64) int64 { + return int64(math.Float64bits(f)) } -// i2f32 is used in rules for converting from an AuxInt to a float32. -func i2f32(i int64) float32 { - return float32(math.Float64frombits(uint64(i))) +// auxFrom32F encodes a float32 value so it can be stored in an AuxInt. +func auxFrom32F(f float32) int64 { + return int64(math.Float64bits(extend32Fto64F(f))) } -// f2i is used in the rules for storing a float in AuxInt. -func f2i(f float64) int64 { - return int64(math.Float64bits(f)) +// auxTo32F decodes a float32 from the AuxInt value provided. +func auxTo32F(i int64) float32 { + return truncate64Fto32F(math.Float64frombits(uint64(i))) +} + +// auxTo64F decodes a float64 from the AuxInt value provided. +func auxTo64F(i int64) float64 { + return math.Float64frombits(uint64(i)) } // uaddOvf returns true if unsigned a+b would overflow. diff --git a/src/cmd/compile/internal/ssa/rewrite386.go b/src/cmd/compile/internal/ssa/rewrite386.go index adea486ef5e38..5481b4e773ae2 100644 --- a/src/cmd/compile/internal/ssa/rewrite386.go +++ b/src/cmd/compile/internal/ssa/rewrite386.go @@ -19822,7 +19822,7 @@ func rewriteValue386_OpNeg32F_0(v *Value) bool { _ = typ // match: (Neg32F x) // cond: !config.use387 - // result: (PXOR x (MOVSSconst [f2i(math.Copysign(0, -1))])) + // result: (PXOR x (MOVSSconst [auxFrom32F(float32(math.Copysign(0, -1)))])) for { x := v.Args[0] if !(!config.use387) { @@ -19831,7 +19831,7 @@ func rewriteValue386_OpNeg32F_0(v *Value) bool { v.reset(Op386PXOR) v.AddArg(x) v0 := b.NewValue0(v.Pos, Op386MOVSSconst, typ.Float32) - v0.AuxInt = f2i(math.Copysign(0, -1)) + v0.AuxInt = auxFrom32F(float32(math.Copysign(0, -1))) v.AddArg(v0) return true } @@ -19858,7 +19858,7 @@ func rewriteValue386_OpNeg64F_0(v *Value) bool { _ = typ // match: (Neg64F x) // cond: !config.use387 - // result: (PXOR x (MOVSDconst [f2i(math.Copysign(0, -1))])) + // result: (PXOR x (MOVSDconst [auxFrom64F(math.Copysign(0, -1))])) for { x := v.Args[0] if !(!config.use387) { @@ -19867,7 +19867,7 @@ func rewriteValue386_OpNeg64F_0(v *Value) bool { v.reset(Op386PXOR) v.AddArg(x) v0 := b.NewValue0(v.Pos, Op386MOVSDconst, typ.Float64) - v0.AuxInt = f2i(math.Copysign(0, -1)) + v0.AuxInt = auxFrom64F(math.Copysign(0, -1)) v.AddArg(v0) return true } diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 3dd37088f10b4..212e2d6850805 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -60838,13 +60838,13 @@ func rewriteValueAMD64_OpNeg32F_0(v *Value) bool { _ = typ // match: (Neg32F x) // cond: - // result: (PXOR x (MOVSSconst [f2i(math.Copysign(0, -1))])) + // result: (PXOR x (MOVSSconst [auxFrom32F(float32(math.Copysign(0, -1)))])) for { x := v.Args[0] v.reset(OpAMD64PXOR) v.AddArg(x) v0 := b.NewValue0(v.Pos, OpAMD64MOVSSconst, typ.Float32) - v0.AuxInt = f2i(math.Copysign(0, -1)) + v0.AuxInt = auxFrom32F(float32(math.Copysign(0, -1))) v.AddArg(v0) return true } @@ -60867,13 +60867,13 @@ func rewriteValueAMD64_OpNeg64F_0(v *Value) bool { _ = typ // match: (Neg64F x) // cond: - // result: (PXOR x (MOVSDconst [f2i(math.Copysign(0, -1))])) + // result: (PXOR x (MOVSDconst [auxFrom64F(math.Copysign(0, -1))])) for { x := v.Args[0] v.reset(OpAMD64PXOR) v.AddArg(x) v0 := b.NewValue0(v.Pos, OpAMD64MOVSDconst, typ.Float64) - v0.AuxInt = f2i(math.Copysign(0, -1)) + v0.AuxInt = auxFrom64F(math.Copysign(0, -1)) v.AddArg(v0) return true } diff --git a/src/cmd/compile/internal/ssa/rewritePPC64.go b/src/cmd/compile/internal/ssa/rewritePPC64.go index 57738c908ba82..19ee33d9faf1a 100644 --- a/src/cmd/compile/internal/ssa/rewritePPC64.go +++ b/src/cmd/compile/internal/ssa/rewritePPC64.go @@ -6409,7 +6409,7 @@ func rewriteValuePPC64_OpPPC64Equal_0(v *Value) bool { func rewriteValuePPC64_OpPPC64FABS_0(v *Value) bool { // match: (FABS (FMOVDconst [x])) // cond: - // result: (FMOVDconst [f2i(math.Abs(i2f(x)))]) + // result: (FMOVDconst [auxFrom64F(math.Abs(auxTo64F(x)))]) for { v_0 := v.Args[0] if v_0.Op != OpPPC64FMOVDconst { @@ -6417,7 +6417,7 @@ func rewriteValuePPC64_OpPPC64FABS_0(v *Value) bool { } x := v_0.AuxInt v.reset(OpPPC64FMOVDconst) - v.AuxInt = f2i(math.Abs(i2f(x))) + v.AuxInt = auxFrom64F(math.Abs(auxTo64F(x))) return true } return false @@ -6507,7 +6507,7 @@ func rewriteValuePPC64_OpPPC64FADDS_0(v *Value) bool { func rewriteValuePPC64_OpPPC64FCEIL_0(v *Value) bool { // match: (FCEIL (FMOVDconst [x])) // cond: - // result: (FMOVDconst [f2i(math.Ceil(i2f(x)))]) + // result: (FMOVDconst [auxFrom64F(math.Ceil(auxTo64F(x)))]) for { v_0 := v.Args[0] if v_0.Op != OpPPC64FMOVDconst { @@ -6515,7 +6515,7 @@ func rewriteValuePPC64_OpPPC64FCEIL_0(v *Value) bool { } x := v_0.AuxInt v.reset(OpPPC64FMOVDconst) - v.AuxInt = f2i(math.Ceil(i2f(x))) + v.AuxInt = auxFrom64F(math.Ceil(auxTo64F(x))) return true } return false @@ -6523,7 +6523,7 @@ func rewriteValuePPC64_OpPPC64FCEIL_0(v *Value) bool { func rewriteValuePPC64_OpPPC64FFLOOR_0(v *Value) bool { // match: (FFLOOR (FMOVDconst [x])) // cond: - // result: (FMOVDconst [f2i(math.Floor(i2f(x)))]) + // result: (FMOVDconst [auxFrom64F(math.Floor(auxTo64F(x)))]) for { v_0 := v.Args[0] if v_0.Op != OpPPC64FMOVDconst { @@ -6531,7 +6531,7 @@ func rewriteValuePPC64_OpPPC64FFLOOR_0(v *Value) bool { } x := v_0.AuxInt v.reset(OpPPC64FMOVDconst) - v.AuxInt = f2i(math.Floor(i2f(x))) + v.AuxInt = auxFrom64F(math.Floor(auxTo64F(x))) return true } return false @@ -6833,7 +6833,7 @@ func rewriteValuePPC64_OpPPC64FNEG_0(v *Value) bool { func rewriteValuePPC64_OpPPC64FSQRT_0(v *Value) bool { // match: (FSQRT (FMOVDconst [x])) // cond: - // result: (FMOVDconst [f2i(math.Sqrt(i2f(x)))]) + // result: (FMOVDconst [auxFrom64F(math.Sqrt(auxTo64F(x)))]) for { v_0 := v.Args[0] if v_0.Op != OpPPC64FMOVDconst { @@ -6841,7 +6841,7 @@ func rewriteValuePPC64_OpPPC64FSQRT_0(v *Value) bool { } x := v_0.AuxInt v.reset(OpPPC64FMOVDconst) - v.AuxInt = f2i(math.Sqrt(i2f(x))) + v.AuxInt = auxFrom64F(math.Sqrt(auxTo64F(x))) return true } return false @@ -6893,7 +6893,7 @@ func rewriteValuePPC64_OpPPC64FSUBS_0(v *Value) bool { func rewriteValuePPC64_OpPPC64FTRUNC_0(v *Value) bool { // match: (FTRUNC (FMOVDconst [x])) // cond: - // result: (FMOVDconst [f2i(math.Trunc(i2f(x)))]) + // result: (FMOVDconst [auxFrom64F(math.Trunc(auxTo64F(x)))]) for { v_0 := v.Args[0] if v_0.Op != OpPPC64FMOVDconst { @@ -6901,7 +6901,7 @@ func rewriteValuePPC64_OpPPC64FTRUNC_0(v *Value) bool { } x := v_0.AuxInt v.reset(OpPPC64FMOVDconst) - v.AuxInt = f2i(math.Trunc(i2f(x))) + v.AuxInt = auxFrom64F(math.Trunc(auxTo64F(x))) return true } return false diff --git a/src/cmd/compile/internal/ssa/rewriteWasm.go b/src/cmd/compile/internal/ssa/rewriteWasm.go index c07651ef0ecb3..b92556db90b0f 100644 --- a/src/cmd/compile/internal/ssa/rewriteWasm.go +++ b/src/cmd/compile/internal/ssa/rewriteWasm.go @@ -5071,7 +5071,7 @@ func rewriteValueWasm_OpWasmF64Add_0(v *Value) bool { _ = typ // match: (F64Add (F64Const [x]) (F64Const [y])) // cond: - // result: (F64Const [f2i(i2f(x) + i2f(y))]) + // result: (F64Const [auxFrom64F(auxTo64F(x) + auxTo64F(y))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -5085,7 +5085,7 @@ func rewriteValueWasm_OpWasmF64Add_0(v *Value) bool { } y := v_1.AuxInt v.reset(OpWasmF64Const) - v.AuxInt = f2i(i2f(x) + i2f(y)) + v.AuxInt = auxFrom64F(auxTo64F(x) + auxTo64F(y)) return true } // match: (F64Add (F64Const [x]) y) @@ -5115,7 +5115,7 @@ func rewriteValueWasm_OpWasmF64Mul_0(v *Value) bool { _ = typ // match: (F64Mul (F64Const [x]) (F64Const [y])) // cond: - // result: (F64Const [f2i(i2f(x) * i2f(y))]) + // result: (F64Const [auxFrom64F(auxTo64F(x) * auxTo64F(y))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -5129,7 +5129,7 @@ func rewriteValueWasm_OpWasmF64Mul_0(v *Value) bool { } y := v_1.AuxInt v.reset(OpWasmF64Const) - v.AuxInt = f2i(i2f(x) * i2f(y)) + v.AuxInt = auxFrom64F(auxTo64F(x) * auxTo64F(y)) return true } // match: (F64Mul (F64Const [x]) y) diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index d91900d72f9c0..612d57529e0b3 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -2409,7 +2409,7 @@ func rewriteValuegeneric_OpAdd32_30(v *Value) bool { func rewriteValuegeneric_OpAdd32F_0(v *Value) bool { // match: (Add32F (Const32F [c]) (Const32F [d])) // cond: - // result: (Const32F [f2i(float64(i2f32(c) + i2f32(d)))]) + // result: (Const32F [auxFrom32F(auxTo32F(c) + auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -2423,12 +2423,12 @@ func rewriteValuegeneric_OpAdd32F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConst32F) - v.AuxInt = f2i(float64(i2f32(c) + i2f32(d))) + v.AuxInt = auxFrom32F(auxTo32F(c) + auxTo32F(d)) return true } // match: (Add32F (Const32F [d]) (Const32F [c])) // cond: - // result: (Const32F [f2i(float64(i2f32(c) + i2f32(d)))]) + // result: (Const32F [auxFrom32F(auxTo32F(c) + auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -2442,7 +2442,7 @@ func rewriteValuegeneric_OpAdd32F_0(v *Value) bool { } c := v_1.AuxInt v.reset(OpConst32F) - v.AuxInt = f2i(float64(i2f32(c) + i2f32(d))) + v.AuxInt = auxFrom32F(auxTo32F(c) + auxTo32F(d)) return true } // match: (Add32F x (Const32F [0])) @@ -3454,7 +3454,7 @@ func rewriteValuegeneric_OpAdd64_30(v *Value) bool { func rewriteValuegeneric_OpAdd64F_0(v *Value) bool { // match: (Add64F (Const64F [c]) (Const64F [d])) // cond: - // result: (Const64F [f2i(i2f(c) + i2f(d))]) + // result: (Const64F [auxFrom64F(auxTo64F(c) + auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -3468,12 +3468,12 @@ func rewriteValuegeneric_OpAdd64F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConst64F) - v.AuxInt = f2i(i2f(c) + i2f(d)) + v.AuxInt = auxFrom64F(auxTo64F(c) + auxTo64F(d)) return true } // match: (Add64F (Const64F [d]) (Const64F [c])) // cond: - // result: (Const64F [f2i(i2f(c) + i2f(d))]) + // result: (Const64F [auxFrom64F(auxTo64F(c) + auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -3487,7 +3487,7 @@ func rewriteValuegeneric_OpAdd64F_0(v *Value) bool { } c := v_1.AuxInt v.reset(OpConst64F) - v.AuxInt = f2i(i2f(c) + i2f(d)) + v.AuxInt = auxFrom64F(auxTo64F(c) + auxTo64F(d)) return true } // match: (Add64F x (Const64F [0])) @@ -7566,7 +7566,7 @@ func rewriteValuegeneric_OpConvert_0(v *Value) bool { func rewriteValuegeneric_OpCvt32Fto32_0(v *Value) bool { // match: (Cvt32Fto32 (Const32F [c])) // cond: - // result: (Const32 [int64(int32(i2f(c)))]) + // result: (Const32 [int64(int32(auxTo32F(c)))]) for { v_0 := v.Args[0] if v_0.Op != OpConst32F { @@ -7574,7 +7574,7 @@ func rewriteValuegeneric_OpCvt32Fto32_0(v *Value) bool { } c := v_0.AuxInt v.reset(OpConst32) - v.AuxInt = int64(int32(i2f(c))) + v.AuxInt = int64(int32(auxTo32F(c))) return true } return false @@ -7582,7 +7582,7 @@ func rewriteValuegeneric_OpCvt32Fto32_0(v *Value) bool { func rewriteValuegeneric_OpCvt32Fto64_0(v *Value) bool { // match: (Cvt32Fto64 (Const32F [c])) // cond: - // result: (Const64 [int64(i2f(c))]) + // result: (Const64 [int64(auxTo32F(c))]) for { v_0 := v.Args[0] if v_0.Op != OpConst32F { @@ -7590,7 +7590,7 @@ func rewriteValuegeneric_OpCvt32Fto64_0(v *Value) bool { } c := v_0.AuxInt v.reset(OpConst64) - v.AuxInt = int64(i2f(c)) + v.AuxInt = int64(auxTo32F(c)) return true } return false @@ -7614,7 +7614,7 @@ func rewriteValuegeneric_OpCvt32Fto64F_0(v *Value) bool { func rewriteValuegeneric_OpCvt32to32F_0(v *Value) bool { // match: (Cvt32to32F (Const32 [c])) // cond: - // result: (Const32F [f2i(float64(float32(int32(c))))]) + // result: (Const32F [auxFrom32F(float32(int32(c)))]) for { v_0 := v.Args[0] if v_0.Op != OpConst32 { @@ -7622,7 +7622,7 @@ func rewriteValuegeneric_OpCvt32to32F_0(v *Value) bool { } c := v_0.AuxInt v.reset(OpConst32F) - v.AuxInt = f2i(float64(float32(int32(c)))) + v.AuxInt = auxFrom32F(float32(int32(c))) return true } return false @@ -7630,7 +7630,7 @@ func rewriteValuegeneric_OpCvt32to32F_0(v *Value) bool { func rewriteValuegeneric_OpCvt32to64F_0(v *Value) bool { // match: (Cvt32to64F (Const32 [c])) // cond: - // result: (Const64F [f2i(float64(int32(c)))]) + // result: (Const64F [auxFrom64F(float64(int32(c)))]) for { v_0 := v.Args[0] if v_0.Op != OpConst32 { @@ -7638,7 +7638,7 @@ func rewriteValuegeneric_OpCvt32to64F_0(v *Value) bool { } c := v_0.AuxInt v.reset(OpConst64F) - v.AuxInt = f2i(float64(int32(c))) + v.AuxInt = auxFrom64F(float64(int32(c))) return true } return false @@ -7646,7 +7646,7 @@ func rewriteValuegeneric_OpCvt32to64F_0(v *Value) bool { func rewriteValuegeneric_OpCvt64Fto32_0(v *Value) bool { // match: (Cvt64Fto32 (Const64F [c])) // cond: - // result: (Const32 [int64(int32(i2f(c)))]) + // result: (Const32 [int64(int32(auxTo64F(c)))]) for { v_0 := v.Args[0] if v_0.Op != OpConst64F { @@ -7654,7 +7654,7 @@ func rewriteValuegeneric_OpCvt64Fto32_0(v *Value) bool { } c := v_0.AuxInt v.reset(OpConst32) - v.AuxInt = int64(int32(i2f(c))) + v.AuxInt = int64(int32(auxTo64F(c))) return true } return false @@ -7662,7 +7662,7 @@ func rewriteValuegeneric_OpCvt64Fto32_0(v *Value) bool { func rewriteValuegeneric_OpCvt64Fto32F_0(v *Value) bool { // match: (Cvt64Fto32F (Const64F [c])) // cond: - // result: (Const32F [f2i(float64(i2f32(c)))]) + // result: (Const32F [auxFrom32F(float32(auxTo64F(c)))]) for { v_0 := v.Args[0] if v_0.Op != OpConst64F { @@ -7670,7 +7670,7 @@ func rewriteValuegeneric_OpCvt64Fto32F_0(v *Value) bool { } c := v_0.AuxInt v.reset(OpConst32F) - v.AuxInt = f2i(float64(i2f32(c))) + v.AuxInt = auxFrom32F(float32(auxTo64F(c))) return true } return false @@ -7678,7 +7678,7 @@ func rewriteValuegeneric_OpCvt64Fto32F_0(v *Value) bool { func rewriteValuegeneric_OpCvt64Fto64_0(v *Value) bool { // match: (Cvt64Fto64 (Const64F [c])) // cond: - // result: (Const64 [int64(i2f(c))]) + // result: (Const64 [int64(auxTo64F(c))]) for { v_0 := v.Args[0] if v_0.Op != OpConst64F { @@ -7686,7 +7686,7 @@ func rewriteValuegeneric_OpCvt64Fto64_0(v *Value) bool { } c := v_0.AuxInt v.reset(OpConst64) - v.AuxInt = int64(i2f(c)) + v.AuxInt = int64(auxTo64F(c)) return true } return false @@ -7694,7 +7694,7 @@ func rewriteValuegeneric_OpCvt64Fto64_0(v *Value) bool { func rewriteValuegeneric_OpCvt64to32F_0(v *Value) bool { // match: (Cvt64to32F (Const64 [c])) // cond: - // result: (Const32F [f2i(float64(float32(c)))]) + // result: (Const32F [auxFrom32F(float32(c))]) for { v_0 := v.Args[0] if v_0.Op != OpConst64 { @@ -7702,7 +7702,7 @@ func rewriteValuegeneric_OpCvt64to32F_0(v *Value) bool { } c := v_0.AuxInt v.reset(OpConst32F) - v.AuxInt = f2i(float64(float32(c))) + v.AuxInt = auxFrom32F(float32(c)) return true } return false @@ -7710,7 +7710,7 @@ func rewriteValuegeneric_OpCvt64to32F_0(v *Value) bool { func rewriteValuegeneric_OpCvt64to64F_0(v *Value) bool { // match: (Cvt64to64F (Const64 [c])) // cond: - // result: (Const64F [f2i(float64(c))]) + // result: (Const64F [auxFrom64F(float64(c))]) for { v_0 := v.Args[0] if v_0.Op != OpConst64 { @@ -7718,7 +7718,7 @@ func rewriteValuegeneric_OpCvt64to64F_0(v *Value) bool { } c := v_0.AuxInt v.reset(OpConst64F) - v.AuxInt = f2i(float64(c)) + v.AuxInt = auxFrom64F(float64(c)) return true } return false @@ -8342,7 +8342,7 @@ func rewriteValuegeneric_OpDiv32F_0(v *Value) bool { _ = b // match: (Div32F (Const32F [c]) (Const32F [d])) // cond: - // result: (Const32F [f2i(float64(i2f32(c) / i2f32(d)))]) + // result: (Const32F [auxFrom32F(auxTo32F(c) / auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -8356,12 +8356,12 @@ func rewriteValuegeneric_OpDiv32F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConst32F) - v.AuxInt = f2i(float64(i2f32(c) / i2f32(d))) + v.AuxInt = auxFrom32F(auxTo32F(c) / auxTo32F(d)) return true } // match: (Div32F x (Const32F [c])) - // cond: reciprocalExact32(float32(i2f(c))) - // result: (Mul32F x (Const32F [f2i(1/i2f(c))])) + // cond: reciprocalExact32(auxTo32F(c)) + // result: (Mul32F x (Const32F [auxFrom32F(1/auxTo32F(c))])) for { _ = v.Args[1] x := v.Args[0] @@ -8371,13 +8371,13 @@ func rewriteValuegeneric_OpDiv32F_0(v *Value) bool { } t := v_1.Type c := v_1.AuxInt - if !(reciprocalExact32(float32(i2f(c)))) { + if !(reciprocalExact32(auxTo32F(c))) { break } v.reset(OpMul32F) v.AddArg(x) v0 := b.NewValue0(v.Pos, OpConst32F, t) - v0.AuxInt = f2i(1 / i2f(c)) + v0.AuxInt = auxFrom32F(1 / auxTo32F(c)) v.AddArg(v0) return true } @@ -8866,7 +8866,7 @@ func rewriteValuegeneric_OpDiv64F_0(v *Value) bool { _ = b // match: (Div64F (Const64F [c]) (Const64F [d])) // cond: - // result: (Const64F [f2i(i2f(c) / i2f(d))]) + // result: (Const64F [auxFrom64F(auxTo64F(c) / auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -8880,12 +8880,12 @@ func rewriteValuegeneric_OpDiv64F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConst64F) - v.AuxInt = f2i(i2f(c) / i2f(d)) + v.AuxInt = auxFrom64F(auxTo64F(c) / auxTo64F(d)) return true } // match: (Div64F x (Const64F [c])) - // cond: reciprocalExact64(i2f(c)) - // result: (Mul64F x (Const64F [f2i(1/i2f(c))])) + // cond: reciprocalExact64(auxTo64F(c)) + // result: (Mul64F x (Const64F [auxFrom64F(1/auxTo64F(c))])) for { _ = v.Args[1] x := v.Args[0] @@ -8895,13 +8895,13 @@ func rewriteValuegeneric_OpDiv64F_0(v *Value) bool { } t := v_1.Type c := v_1.AuxInt - if !(reciprocalExact64(i2f(c))) { + if !(reciprocalExact64(auxTo64F(c))) { break } v.reset(OpMul64F) v.AddArg(x) v0 := b.NewValue0(v.Pos, OpConst64F, t) - v0.AuxInt = f2i(1 / i2f(c)) + v0.AuxInt = auxFrom64F(1 / auxTo64F(c)) v.AddArg(v0) return true } @@ -9802,7 +9802,7 @@ func rewriteValuegeneric_OpEq32_0(v *Value) bool { func rewriteValuegeneric_OpEq32F_0(v *Value) bool { // match: (Eq32F (Const32F [c]) (Const32F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) == i2f(d))]) + // result: (ConstBool [b2i(auxTo32F(c) == auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -9816,12 +9816,12 @@ func rewriteValuegeneric_OpEq32F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) == i2f(d)) + v.AuxInt = b2i(auxTo32F(c) == auxTo32F(d)) return true } // match: (Eq32F (Const32F [d]) (Const32F [c])) // cond: - // result: (ConstBool [b2i(i2f(c) == i2f(d))]) + // result: (ConstBool [b2i(auxTo32F(c) == auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -9835,7 +9835,7 @@ func rewriteValuegeneric_OpEq32F_0(v *Value) bool { } c := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) == i2f(d)) + v.AuxInt = b2i(auxTo32F(c) == auxTo32F(d)) return true } return false @@ -10081,7 +10081,7 @@ func rewriteValuegeneric_OpEq64_0(v *Value) bool { func rewriteValuegeneric_OpEq64F_0(v *Value) bool { // match: (Eq64F (Const64F [c]) (Const64F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) == i2f(d))]) + // result: (ConstBool [b2i(auxTo64F(c) == auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -10095,12 +10095,12 @@ func rewriteValuegeneric_OpEq64F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) == i2f(d)) + v.AuxInt = b2i(auxTo64F(c) == auxTo64F(d)) return true } // match: (Eq64F (Const64F [d]) (Const64F [c])) // cond: - // result: (ConstBool [b2i(i2f(c) == i2f(d))]) + // result: (ConstBool [b2i(auxTo64F(c) == auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -10114,7 +10114,7 @@ func rewriteValuegeneric_OpEq64F_0(v *Value) bool { } c := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) == i2f(d)) + v.AuxInt = b2i(auxTo64F(c) == auxTo64F(d)) return true } return false @@ -11077,7 +11077,7 @@ func rewriteValuegeneric_OpGeq32_0(v *Value) bool { func rewriteValuegeneric_OpGeq32F_0(v *Value) bool { // match: (Geq32F (Const32F [c]) (Const32F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) >= i2f(d))]) + // result: (ConstBool [b2i(auxTo32F(c) >= auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -11091,7 +11091,7 @@ func rewriteValuegeneric_OpGeq32F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) >= i2f(d)) + v.AuxInt = b2i(auxTo32F(c) >= auxTo32F(d)) return true } return false @@ -11143,7 +11143,7 @@ func rewriteValuegeneric_OpGeq64_0(v *Value) bool { func rewriteValuegeneric_OpGeq64F_0(v *Value) bool { // match: (Geq64F (Const64F [c]) (Const64F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) >= i2f(d))]) + // result: (ConstBool [b2i(auxTo64F(c) >= auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -11157,7 +11157,7 @@ func rewriteValuegeneric_OpGeq64F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) >= i2f(d)) + v.AuxInt = b2i(auxTo64F(c) >= auxTo64F(d)) return true } return false @@ -11297,7 +11297,7 @@ func rewriteValuegeneric_OpGreater32_0(v *Value) bool { func rewriteValuegeneric_OpGreater32F_0(v *Value) bool { // match: (Greater32F (Const32F [c]) (Const32F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) > i2f(d))]) + // result: (ConstBool [b2i(auxTo32F(c) > auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -11311,7 +11311,7 @@ func rewriteValuegeneric_OpGreater32F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) > i2f(d)) + v.AuxInt = b2i(auxTo32F(c) > auxTo32F(d)) return true } return false @@ -11363,7 +11363,7 @@ func rewriteValuegeneric_OpGreater64_0(v *Value) bool { func rewriteValuegeneric_OpGreater64F_0(v *Value) bool { // match: (Greater64F (Const64F [c]) (Const64F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) > i2f(d))]) + // result: (ConstBool [b2i(auxTo64F(c) > auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -11377,7 +11377,7 @@ func rewriteValuegeneric_OpGreater64F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) > i2f(d)) + v.AuxInt = b2i(auxTo64F(c) > auxTo64F(d)) return true } return false @@ -12945,7 +12945,7 @@ func rewriteValuegeneric_OpLeq32_0(v *Value) bool { func rewriteValuegeneric_OpLeq32F_0(v *Value) bool { // match: (Leq32F (Const32F [c]) (Const32F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) <= i2f(d))]) + // result: (ConstBool [b2i(auxTo32F(c) <= auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -12959,7 +12959,7 @@ func rewriteValuegeneric_OpLeq32F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) <= i2f(d)) + v.AuxInt = b2i(auxTo32F(c) <= auxTo32F(d)) return true } return false @@ -13011,7 +13011,7 @@ func rewriteValuegeneric_OpLeq64_0(v *Value) bool { func rewriteValuegeneric_OpLeq64F_0(v *Value) bool { // match: (Leq64F (Const64F [c]) (Const64F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) <= i2f(d))]) + // result: (ConstBool [b2i(auxTo64F(c) <= auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -13025,7 +13025,7 @@ func rewriteValuegeneric_OpLeq64F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) <= i2f(d)) + v.AuxInt = b2i(auxTo64F(c) <= auxTo64F(d)) return true } return false @@ -13165,7 +13165,7 @@ func rewriteValuegeneric_OpLess32_0(v *Value) bool { func rewriteValuegeneric_OpLess32F_0(v *Value) bool { // match: (Less32F (Const32F [c]) (Const32F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) < i2f(d))]) + // result: (ConstBool [b2i(auxTo32F(c) < auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -13179,7 +13179,7 @@ func rewriteValuegeneric_OpLess32F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) < i2f(d)) + v.AuxInt = b2i(auxTo32F(c) < auxTo32F(d)) return true } return false @@ -13231,7 +13231,7 @@ func rewriteValuegeneric_OpLess64_0(v *Value) bool { func rewriteValuegeneric_OpLess64F_0(v *Value) bool { // match: (Less64F (Const64F [c]) (Const64F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) < i2f(d))]) + // result: (ConstBool [b2i(auxTo64F(c) < auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -13245,7 +13245,7 @@ func rewriteValuegeneric_OpLess64F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) < i2f(d)) + v.AuxInt = b2i(auxTo64F(c) < auxTo64F(d)) return true } return false @@ -13483,7 +13483,7 @@ func rewriteValuegeneric_OpLoad_0(v *Value) bool { } // match: (Load p1 (Store {t2} p2 (Const32 [x]) _)) // cond: isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitFloat(t1) - // result: (Const32F [f2i(extend32Fto64F(math.Float32frombits(uint32(x))))]) + // result: (Const32F [auxFrom32F(math.Float32frombits(uint32(x)))]) for { t1 := v.Type _ = v.Args[1] @@ -13504,7 +13504,7 @@ func rewriteValuegeneric_OpLoad_0(v *Value) bool { break } v.reset(OpConst32F) - v.AuxInt = f2i(extend32Fto64F(math.Float32frombits(uint32(x)))) + v.AuxInt = auxFrom32F(math.Float32frombits(uint32(x))) return true } // match: (Load p1 (Store {t2} p2 (Const64F [x]) _)) @@ -13535,7 +13535,7 @@ func rewriteValuegeneric_OpLoad_0(v *Value) bool { } // match: (Load p1 (Store {t2} p2 (Const32F [x]) _)) // cond: isSamePtr(p1,p2) && sizeof(t2) == 4 && is32BitInt(t1) - // result: (Const32 [int64(int32(math.Float32bits(truncate64Fto32F(i2f(x)))))]) + // result: (Const32 [int64(int32(math.Float32bits(auxTo32F(x))))]) for { t1 := v.Type _ = v.Args[1] @@ -13556,7 +13556,7 @@ func rewriteValuegeneric_OpLoad_0(v *Value) bool { break } v.reset(OpConst32) - v.AuxInt = int64(int32(math.Float32bits(truncate64Fto32F(i2f(x))))) + v.AuxInt = int64(int32(math.Float32bits(auxTo32F(x)))) return true } // match: (Load op:(OffPtr [o1] p1) (Store {t2} p2 _ mem:(Zero [n] p3 _))) @@ -18320,7 +18320,7 @@ func rewriteValuegeneric_OpMul32_10(v *Value) bool { func rewriteValuegeneric_OpMul32F_0(v *Value) bool { // match: (Mul32F (Const32F [c]) (Const32F [d])) // cond: - // result: (Const32F [f2i(float64(i2f32(c) * i2f32(d)))]) + // result: (Const32F [auxFrom32F(auxTo32F(c) * auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -18334,12 +18334,12 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConst32F) - v.AuxInt = f2i(float64(i2f32(c) * i2f32(d))) + v.AuxInt = auxFrom32F(auxTo32F(c) * auxTo32F(d)) return true } // match: (Mul32F (Const32F [d]) (Const32F [c])) // cond: - // result: (Const32F [f2i(float64(i2f32(c) * i2f32(d)))]) + // result: (Const32F [auxFrom32F(auxTo32F(c) * auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -18353,10 +18353,10 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { } c := v_1.AuxInt v.reset(OpConst32F) - v.AuxInt = f2i(float64(i2f32(c) * i2f32(d))) + v.AuxInt = auxFrom32F(auxTo32F(c) * auxTo32F(d)) return true } - // match: (Mul32F x (Const32F [f2i(1)])) + // match: (Mul32F x (Const32F [auxFrom64F(1)])) // cond: // result: x for { @@ -18366,7 +18366,7 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { if v_1.Op != OpConst32F { break } - if v_1.AuxInt != f2i(1) { + if v_1.AuxInt != auxFrom64F(1) { break } v.reset(OpCopy) @@ -18374,7 +18374,7 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { v.AddArg(x) return true } - // match: (Mul32F (Const32F [f2i(1)]) x) + // match: (Mul32F (Const32F [auxFrom64F(1)]) x) // cond: // result: x for { @@ -18383,7 +18383,7 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { if v_0.Op != OpConst32F { break } - if v_0.AuxInt != f2i(1) { + if v_0.AuxInt != auxFrom64F(1) { break } x := v.Args[1] @@ -18392,7 +18392,7 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { v.AddArg(x) return true } - // match: (Mul32F x (Const32F [f2i(-1)])) + // match: (Mul32F x (Const32F [auxFrom32F(-1)])) // cond: // result: (Neg32F x) for { @@ -18402,14 +18402,14 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { if v_1.Op != OpConst32F { break } - if v_1.AuxInt != f2i(-1) { + if v_1.AuxInt != auxFrom32F(-1) { break } v.reset(OpNeg32F) v.AddArg(x) return true } - // match: (Mul32F (Const32F [f2i(-1)]) x) + // match: (Mul32F (Const32F [auxFrom32F(-1)]) x) // cond: // result: (Neg32F x) for { @@ -18418,7 +18418,7 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { if v_0.Op != OpConst32F { break } - if v_0.AuxInt != f2i(-1) { + if v_0.AuxInt != auxFrom32F(-1) { break } x := v.Args[1] @@ -18426,7 +18426,7 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { v.AddArg(x) return true } - // match: (Mul32F x (Const32F [f2i(2)])) + // match: (Mul32F x (Const32F [auxFrom32F(2)])) // cond: // result: (Add32F x x) for { @@ -18436,7 +18436,7 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { if v_1.Op != OpConst32F { break } - if v_1.AuxInt != f2i(2) { + if v_1.AuxInt != auxFrom32F(2) { break } v.reset(OpAdd32F) @@ -18444,7 +18444,7 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { v.AddArg(x) return true } - // match: (Mul32F (Const32F [f2i(2)]) x) + // match: (Mul32F (Const32F [auxFrom32F(2)]) x) // cond: // result: (Add32F x x) for { @@ -18453,7 +18453,7 @@ func rewriteValuegeneric_OpMul32F_0(v *Value) bool { if v_0.Op != OpConst32F { break } - if v_0.AuxInt != f2i(2) { + if v_0.AuxInt != auxFrom32F(2) { break } x := v.Args[1] @@ -19001,7 +19001,7 @@ func rewriteValuegeneric_OpMul64_10(v *Value) bool { func rewriteValuegeneric_OpMul64F_0(v *Value) bool { // match: (Mul64F (Const64F [c]) (Const64F [d])) // cond: - // result: (Const64F [f2i(i2f(c) * i2f(d))]) + // result: (Const64F [auxFrom64F(auxTo64F(c) * auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -19015,12 +19015,12 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConst64F) - v.AuxInt = f2i(i2f(c) * i2f(d)) + v.AuxInt = auxFrom64F(auxTo64F(c) * auxTo64F(d)) return true } // match: (Mul64F (Const64F [d]) (Const64F [c])) // cond: - // result: (Const64F [f2i(i2f(c) * i2f(d))]) + // result: (Const64F [auxFrom64F(auxTo64F(c) * auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -19034,10 +19034,10 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { } c := v_1.AuxInt v.reset(OpConst64F) - v.AuxInt = f2i(i2f(c) * i2f(d)) + v.AuxInt = auxFrom64F(auxTo64F(c) * auxTo64F(d)) return true } - // match: (Mul64F x (Const64F [f2i(1)])) + // match: (Mul64F x (Const64F [auxFrom64F(1)])) // cond: // result: x for { @@ -19047,7 +19047,7 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { if v_1.Op != OpConst64F { break } - if v_1.AuxInt != f2i(1) { + if v_1.AuxInt != auxFrom64F(1) { break } v.reset(OpCopy) @@ -19055,7 +19055,7 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { v.AddArg(x) return true } - // match: (Mul64F (Const64F [f2i(1)]) x) + // match: (Mul64F (Const64F [auxFrom64F(1)]) x) // cond: // result: x for { @@ -19064,7 +19064,7 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { if v_0.Op != OpConst64F { break } - if v_0.AuxInt != f2i(1) { + if v_0.AuxInt != auxFrom64F(1) { break } x := v.Args[1] @@ -19073,7 +19073,7 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { v.AddArg(x) return true } - // match: (Mul64F x (Const64F [f2i(-1)])) + // match: (Mul64F x (Const64F [auxFrom64F(-1)])) // cond: // result: (Neg64F x) for { @@ -19083,14 +19083,14 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { if v_1.Op != OpConst64F { break } - if v_1.AuxInt != f2i(-1) { + if v_1.AuxInt != auxFrom64F(-1) { break } v.reset(OpNeg64F) v.AddArg(x) return true } - // match: (Mul64F (Const64F [f2i(-1)]) x) + // match: (Mul64F (Const64F [auxFrom64F(-1)]) x) // cond: // result: (Neg64F x) for { @@ -19099,7 +19099,7 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { if v_0.Op != OpConst64F { break } - if v_0.AuxInt != f2i(-1) { + if v_0.AuxInt != auxFrom64F(-1) { break } x := v.Args[1] @@ -19107,7 +19107,7 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { v.AddArg(x) return true } - // match: (Mul64F x (Const64F [f2i(2)])) + // match: (Mul64F x (Const64F [auxFrom64F(2)])) // cond: // result: (Add64F x x) for { @@ -19117,7 +19117,7 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { if v_1.Op != OpConst64F { break } - if v_1.AuxInt != f2i(2) { + if v_1.AuxInt != auxFrom64F(2) { break } v.reset(OpAdd64F) @@ -19125,7 +19125,7 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { v.AddArg(x) return true } - // match: (Mul64F (Const64F [f2i(2)]) x) + // match: (Mul64F (Const64F [auxFrom64F(2)]) x) // cond: // result: (Add64F x x) for { @@ -19134,7 +19134,7 @@ func rewriteValuegeneric_OpMul64F_0(v *Value) bool { if v_0.Op != OpConst64F { break } - if v_0.AuxInt != f2i(2) { + if v_0.AuxInt != auxFrom64F(2) { break } x := v.Args[1] @@ -19585,19 +19585,19 @@ func rewriteValuegeneric_OpNeg32_0(v *Value) bool { } func rewriteValuegeneric_OpNeg32F_0(v *Value) bool { // match: (Neg32F (Const32F [c])) - // cond: i2f(c) != 0 - // result: (Const32F [f2i(-i2f(c))]) + // cond: auxTo32F(c) != 0 + // result: (Const32F [auxFrom32F(-auxTo32F(c))]) for { v_0 := v.Args[0] if v_0.Op != OpConst32F { break } c := v_0.AuxInt - if !(i2f(c) != 0) { + if !(auxTo32F(c) != 0) { break } v.reset(OpConst32F) - v.AuxInt = f2i(-i2f(c)) + v.AuxInt = auxFrom32F(-auxTo32F(c)) return true } return false @@ -19636,19 +19636,19 @@ func rewriteValuegeneric_OpNeg64_0(v *Value) bool { } func rewriteValuegeneric_OpNeg64F_0(v *Value) bool { // match: (Neg64F (Const64F [c])) - // cond: i2f(c) != 0 - // result: (Const64F [f2i(-i2f(c))]) + // cond: auxTo64F(c) != 0 + // result: (Const64F [auxFrom64F(-auxTo64F(c))]) for { v_0 := v.Args[0] if v_0.Op != OpConst64F { break } c := v_0.AuxInt - if !(i2f(c) != 0) { + if !(auxTo64F(c) != 0) { break } v.reset(OpConst64F) - v.AuxInt = f2i(-i2f(c)) + v.AuxInt = auxFrom64F(-auxTo64F(c)) return true } return false @@ -20164,7 +20164,7 @@ func rewriteValuegeneric_OpNeq32_0(v *Value) bool { func rewriteValuegeneric_OpNeq32F_0(v *Value) bool { // match: (Neq32F (Const32F [c]) (Const32F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) != i2f(d))]) + // result: (ConstBool [b2i(auxTo32F(c) != auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -20178,12 +20178,12 @@ func rewriteValuegeneric_OpNeq32F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) != i2f(d)) + v.AuxInt = b2i(auxTo32F(c) != auxTo32F(d)) return true } // match: (Neq32F (Const32F [d]) (Const32F [c])) // cond: - // result: (ConstBool [b2i(i2f(c) != i2f(d))]) + // result: (ConstBool [b2i(auxTo32F(c) != auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -20197,7 +20197,7 @@ func rewriteValuegeneric_OpNeq32F_0(v *Value) bool { } c := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) != i2f(d)) + v.AuxInt = b2i(auxTo32F(c) != auxTo32F(d)) return true } return false @@ -20443,7 +20443,7 @@ func rewriteValuegeneric_OpNeq64_0(v *Value) bool { func rewriteValuegeneric_OpNeq64F_0(v *Value) bool { // match: (Neq64F (Const64F [c]) (Const64F [d])) // cond: - // result: (ConstBool [b2i(i2f(c) != i2f(d))]) + // result: (ConstBool [b2i(auxTo64F(c) != auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -20457,12 +20457,12 @@ func rewriteValuegeneric_OpNeq64F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) != i2f(d)) + v.AuxInt = b2i(auxTo64F(c) != auxTo64F(d)) return true } // match: (Neq64F (Const64F [d]) (Const64F [c])) // cond: - // result: (ConstBool [b2i(i2f(c) != i2f(d))]) + // result: (ConstBool [b2i(auxTo64F(c) != auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -20476,7 +20476,7 @@ func rewriteValuegeneric_OpNeq64F_0(v *Value) bool { } c := v_1.AuxInt v.reset(OpConstBool) - v.AuxInt = b2i(i2f(c) != i2f(d)) + v.AuxInt = b2i(auxTo64F(c) != auxTo64F(d)) return true } return false @@ -27601,7 +27601,7 @@ func rewriteValuegeneric_OpSlicemask_0(v *Value) bool { func rewriteValuegeneric_OpSqrt_0(v *Value) bool { // match: (Sqrt (Const64F [c])) // cond: - // result: (Const64F [f2i(math.Sqrt(i2f(c)))]) + // result: (Const64F [auxFrom64F(math.Sqrt(auxTo64F(c)))]) for { v_0 := v.Args[0] if v_0.Op != OpConst64F { @@ -27609,7 +27609,7 @@ func rewriteValuegeneric_OpSqrt_0(v *Value) bool { } c := v_0.AuxInt v.reset(OpConst64F) - v.AuxInt = f2i(math.Sqrt(i2f(c))) + v.AuxInt = auxFrom64F(math.Sqrt(auxTo64F(c))) return true } return false @@ -29824,7 +29824,7 @@ func rewriteValuegeneric_OpSub32_10(v *Value) bool { func rewriteValuegeneric_OpSub32F_0(v *Value) bool { // match: (Sub32F (Const32F [c]) (Const32F [d])) // cond: - // result: (Const32F [f2i(float64(i2f32(c) - i2f32(d)))]) + // result: (Const32F [auxFrom32F(auxTo32F(c) - auxTo32F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -29838,7 +29838,7 @@ func rewriteValuegeneric_OpSub32F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConst32F) - v.AuxInt = f2i(float64(i2f32(c) - i2f32(d))) + v.AuxInt = auxFrom32F(auxTo32F(c) - auxTo32F(d)) return true } // match: (Sub32F x (Const32F [0])) @@ -30248,7 +30248,7 @@ func rewriteValuegeneric_OpSub64_10(v *Value) bool { func rewriteValuegeneric_OpSub64F_0(v *Value) bool { // match: (Sub64F (Const64F [c]) (Const64F [d])) // cond: - // result: (Const64F [f2i(i2f(c) - i2f(d))]) + // result: (Const64F [auxFrom64F(auxTo64F(c) - auxTo64F(d))]) for { _ = v.Args[1] v_0 := v.Args[0] @@ -30262,7 +30262,7 @@ func rewriteValuegeneric_OpSub64F_0(v *Value) bool { } d := v_1.AuxInt v.reset(OpConst64F) - v.AuxInt = f2i(i2f(c) - i2f(d)) + v.AuxInt = auxFrom64F(auxTo64F(c) - auxTo64F(d)) return true } // match: (Sub64F x (Const64F [0])) diff --git a/src/cmd/compile/internal/ssa/softfloat.go b/src/cmd/compile/internal/ssa/softfloat.go index 39829b046c5dc..b41819c6ad50a 100644 --- a/src/cmd/compile/internal/ssa/softfloat.go +++ b/src/cmd/compile/internal/ssa/softfloat.go @@ -25,7 +25,7 @@ func softfloat(f *Func) { case OpConst32F: v.Op = OpConst32 v.Type = f.Config.Types.UInt32 - v.AuxInt = int64(int32(math.Float32bits(i2f32(v.AuxInt)))) + v.AuxInt = int64(int32(math.Float32bits(auxTo32F(v.AuxInt)))) case OpConst64F: v.Op = OpConst64 v.Type = f.Config.Types.UInt64 From 4c36bc3dcd0af0b7a94089c049e5a08232c916d7 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 9 Aug 2018 17:56:59 -0400 Subject: [PATCH 0386/1663] cmd/go/testdata/script/mod_test: add missing test invocation for case e MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib0544adc1444a473f8edcb9dd92aefa9fcbc7330 Reviewed-on: https://go-review.googlesource.com/134656 Reviewed-by: Daniel Martí Reviewed-by: Ian Lance Taylor Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot --- src/cmd/go/testdata/script/mod_test.txt | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cmd/go/testdata/script/mod_test.txt b/src/cmd/go/testdata/script/mod_test.txt index caeb25ada8458..af4fd76d706cf 100644 --- a/src/cmd/go/testdata/script/mod_test.txt +++ b/src/cmd/go/testdata/script/mod_test.txt @@ -1,5 +1,8 @@ env GO111MODULE=on +# TODO(bcmills): Convert the 'go test' calls below to 'go list -test' once 'go +# list' is more sensitive to package loading errors. + # A test in the module's root package should work. cd a/ cp go.mod.empty go.mod @@ -48,6 +51,10 @@ cd ../d_test go test stdout PASS +cd ../e +go test +stdout PASS + -- a/go.mod.empty -- module example.com/user/a From 623c772814cdae562afb4c63c62d51a228bc672e Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Sat, 15 Sep 2018 15:30:13 -0700 Subject: [PATCH 0387/1663] cmd/compile: fix CMPconstload rule The CMPconstload opcodes take a ValAndOff as their AuxInt, not just an offset. Originally introduced in CL 135379. Change-Id: I244b2d56ef2e99d2975faa2e97f4291ec97c64b7 Reviewed-on: https://go-review.googlesource.com/135418 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Ilya Tocar --- src/cmd/compile/internal/ssa/gen/AMD64.rules | 10 +- src/cmd/compile/internal/ssa/rewriteAMD64.go | 96 ++++++++++---------- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index 3247bb72b5b8b..803b8896b0a29 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -1044,8 +1044,8 @@ ((ADD|SUB|AND|OR|XOR)Lload [off1+off2] {sym} val base mem) (CMP(Q|L|W|B)load [off1] {sym} (ADDQconst [off2] base) val mem) && is32Bit(off1+off2) -> (CMP(Q|L|W|B)load [off1+off2] {sym} base val mem) -(CMP(Q|L|W|B)constload [off1] {sym} (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> - (CMP(Q|L|W|B)constload [off1+off2] {sym} base mem) +(CMP(Q|L|W|B)constload [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> + (CMP(Q|L|W|B)constload [ValAndOff(valoff1).add(off2)] {sym} base mem) ((ADD|SUB|MUL|DIV)SSload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> ((ADD|SUB|MUL|DIV)SSload [off1+off2] {sym} val base mem) @@ -1096,9 +1096,9 @@ (CMP(Q|L|W|B)load [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> (CMP(Q|L|W|B)load [off1+off2] {mergeSym(sym1,sym2)} base val mem) -(CMP(Q|L|W|B)constload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) - && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> - (CMP(Q|L|W|B)constload [off1+off2] {mergeSym(sym1,sym2)} base mem) +(CMP(Q|L|W|B)constload [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + && ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) -> + (CMP(Q|L|W|B)constload [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) ((ADD|SUB|MUL|DIV)SSload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 212e2d6850805..98b36a96a075a 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -7941,11 +7941,11 @@ func rewriteValueAMD64_OpAMD64CMPBconst_0(v *Value) bool { return false } func rewriteValueAMD64_OpAMD64CMPBconstload_0(v *Value) bool { - // match: (CMPBconstload [off1] {sym} (ADDQconst [off2] base) mem) - // cond: is32Bit(off1+off2) - // result: (CMPBconstload [off1+off2] {sym} base mem) + // match: (CMPBconstload [valoff1] {sym} (ADDQconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (CMPBconstload [ValAndOff(valoff1).add(off2)] {sym} base mem) for { - off1 := v.AuxInt + valoff1 := v.AuxInt sym := v.Aux _ = v.Args[1] v_0 := v.Args[0] @@ -7955,21 +7955,21 @@ func rewriteValueAMD64_OpAMD64CMPBconstload_0(v *Value) bool { off2 := v_0.AuxInt base := v_0.Args[0] mem := v.Args[1] - if !(is32Bit(off1 + off2)) { + if !(ValAndOff(valoff1).canAdd(off2)) { break } v.reset(OpAMD64CMPBconstload) - v.AuxInt = off1 + off2 + v.AuxInt = ValAndOff(valoff1).add(off2) v.Aux = sym v.AddArg(base) v.AddArg(mem) return true } - // match: (CMPBconstload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) - // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) - // result: (CMPBconstload [off1+off2] {mergeSym(sym1,sym2)} base mem) + // match: (CMPBconstload [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) + // result: (CMPBconstload [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) for { - off1 := v.AuxInt + valoff1 := v.AuxInt sym1 := v.Aux _ = v.Args[1] v_0 := v.Args[0] @@ -7980,11 +7980,11 @@ func rewriteValueAMD64_OpAMD64CMPBconstload_0(v *Value) bool { sym2 := v_0.Aux base := v_0.Args[0] mem := v.Args[1] - if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2)) { break } v.reset(OpAMD64CMPBconstload) - v.AuxInt = off1 + off2 + v.AuxInt = ValAndOff(valoff1).add(off2) v.Aux = mergeSym(sym1, sym2) v.AddArg(base) v.AddArg(mem) @@ -8363,11 +8363,11 @@ func rewriteValueAMD64_OpAMD64CMPLconst_10(v *Value) bool { return false } func rewriteValueAMD64_OpAMD64CMPLconstload_0(v *Value) bool { - // match: (CMPLconstload [off1] {sym} (ADDQconst [off2] base) mem) - // cond: is32Bit(off1+off2) - // result: (CMPLconstload [off1+off2] {sym} base mem) + // match: (CMPLconstload [valoff1] {sym} (ADDQconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (CMPLconstload [ValAndOff(valoff1).add(off2)] {sym} base mem) for { - off1 := v.AuxInt + valoff1 := v.AuxInt sym := v.Aux _ = v.Args[1] v_0 := v.Args[0] @@ -8377,21 +8377,21 @@ func rewriteValueAMD64_OpAMD64CMPLconstload_0(v *Value) bool { off2 := v_0.AuxInt base := v_0.Args[0] mem := v.Args[1] - if !(is32Bit(off1 + off2)) { + if !(ValAndOff(valoff1).canAdd(off2)) { break } v.reset(OpAMD64CMPLconstload) - v.AuxInt = off1 + off2 + v.AuxInt = ValAndOff(valoff1).add(off2) v.Aux = sym v.AddArg(base) v.AddArg(mem) return true } - // match: (CMPLconstload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) - // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) - // result: (CMPLconstload [off1+off2] {mergeSym(sym1,sym2)} base mem) + // match: (CMPLconstload [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) + // result: (CMPLconstload [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) for { - off1 := v.AuxInt + valoff1 := v.AuxInt sym1 := v.Aux _ = v.Args[1] v_0 := v.Args[0] @@ -8402,11 +8402,11 @@ func rewriteValueAMD64_OpAMD64CMPLconstload_0(v *Value) bool { sym2 := v_0.Aux base := v_0.Args[0] mem := v.Args[1] - if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2)) { break } v.reset(OpAMD64CMPLconstload) - v.AuxInt = off1 + off2 + v.AuxInt = ValAndOff(valoff1).add(off2) v.Aux = mergeSym(sym1, sym2) v.AddArg(base) v.AddArg(mem) @@ -8908,11 +8908,11 @@ func rewriteValueAMD64_OpAMD64CMPQconst_10(v *Value) bool { return false } func rewriteValueAMD64_OpAMD64CMPQconstload_0(v *Value) bool { - // match: (CMPQconstload [off1] {sym} (ADDQconst [off2] base) mem) - // cond: is32Bit(off1+off2) - // result: (CMPQconstload [off1+off2] {sym} base mem) + // match: (CMPQconstload [valoff1] {sym} (ADDQconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (CMPQconstload [ValAndOff(valoff1).add(off2)] {sym} base mem) for { - off1 := v.AuxInt + valoff1 := v.AuxInt sym := v.Aux _ = v.Args[1] v_0 := v.Args[0] @@ -8922,21 +8922,21 @@ func rewriteValueAMD64_OpAMD64CMPQconstload_0(v *Value) bool { off2 := v_0.AuxInt base := v_0.Args[0] mem := v.Args[1] - if !(is32Bit(off1 + off2)) { + if !(ValAndOff(valoff1).canAdd(off2)) { break } v.reset(OpAMD64CMPQconstload) - v.AuxInt = off1 + off2 + v.AuxInt = ValAndOff(valoff1).add(off2) v.Aux = sym v.AddArg(base) v.AddArg(mem) return true } - // match: (CMPQconstload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) - // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) - // result: (CMPQconstload [off1+off2] {mergeSym(sym1,sym2)} base mem) + // match: (CMPQconstload [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) + // result: (CMPQconstload [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) for { - off1 := v.AuxInt + valoff1 := v.AuxInt sym1 := v.Aux _ = v.Args[1] v_0 := v.Args[0] @@ -8947,11 +8947,11 @@ func rewriteValueAMD64_OpAMD64CMPQconstload_0(v *Value) bool { sym2 := v_0.Aux base := v_0.Args[0] mem := v.Args[1] - if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2)) { break } v.reset(OpAMD64CMPQconstload) - v.AuxInt = off1 + off2 + v.AuxInt = ValAndOff(valoff1).add(off2) v.Aux = mergeSym(sym1, sym2) v.AddArg(base) v.AddArg(mem) @@ -9311,11 +9311,11 @@ func rewriteValueAMD64_OpAMD64CMPWconst_0(v *Value) bool { return false } func rewriteValueAMD64_OpAMD64CMPWconstload_0(v *Value) bool { - // match: (CMPWconstload [off1] {sym} (ADDQconst [off2] base) mem) - // cond: is32Bit(off1+off2) - // result: (CMPWconstload [off1+off2] {sym} base mem) + // match: (CMPWconstload [valoff1] {sym} (ADDQconst [off2] base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) + // result: (CMPWconstload [ValAndOff(valoff1).add(off2)] {sym} base mem) for { - off1 := v.AuxInt + valoff1 := v.AuxInt sym := v.Aux _ = v.Args[1] v_0 := v.Args[0] @@ -9325,21 +9325,21 @@ func rewriteValueAMD64_OpAMD64CMPWconstload_0(v *Value) bool { off2 := v_0.AuxInt base := v_0.Args[0] mem := v.Args[1] - if !(is32Bit(off1 + off2)) { + if !(ValAndOff(valoff1).canAdd(off2)) { break } v.reset(OpAMD64CMPWconstload) - v.AuxInt = off1 + off2 + v.AuxInt = ValAndOff(valoff1).add(off2) v.Aux = sym v.AddArg(base) v.AddArg(mem) return true } - // match: (CMPWconstload [off1] {sym1} (LEAQ [off2] {sym2} base) mem) - // cond: is32Bit(off1+off2) && canMergeSym(sym1, sym2) - // result: (CMPWconstload [off1+off2] {mergeSym(sym1,sym2)} base mem) + // match: (CMPWconstload [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + // cond: ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) + // result: (CMPWconstload [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) for { - off1 := v.AuxInt + valoff1 := v.AuxInt sym1 := v.Aux _ = v.Args[1] v_0 := v.Args[0] @@ -9350,11 +9350,11 @@ func rewriteValueAMD64_OpAMD64CMPWconstload_0(v *Value) bool { sym2 := v_0.Aux base := v_0.Args[0] mem := v.Args[1] - if !(is32Bit(off1+off2) && canMergeSym(sym1, sym2)) { + if !(ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2)) { break } v.reset(OpAMD64CMPWconstload) - v.AuxInt = off1 + off2 + v.AuxInt = ValAndOff(valoff1).add(off2) v.Aux = mergeSym(sym1, sym2) v.AddArg(base) v.AddArg(mem) From 5eec2373e492081132cf374daa494264df923c98 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 17 Sep 2018 17:22:48 +0200 Subject: [PATCH 0388/1663] syscall: enable TestSyscallNoError on all Linux 32-bit architectures Check the size of uintptr instead of listing GOARCHes explicitly. This will make the test also run on linux/mips{,le}. Change-Id: I649f15d293002afc1360b1913910202c3e5188b7 Reviewed-on: https://go-review.googlesource.com/135715 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/syscall/syscall_linux_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/syscall/syscall_linux_test.go b/src/syscall/syscall_linux_test.go index 1fd70b07e3ef5..293549a841d05 100644 --- a/src/syscall/syscall_linux_test.go +++ b/src/syscall/syscall_linux_test.go @@ -19,6 +19,7 @@ import ( "syscall" "testing" "time" + "unsafe" ) // chtmpdir changes the working directory to a new temporary directory and @@ -294,7 +295,7 @@ func TestSyscallNoError(t *testing.T) { // On Linux there are currently no syscalls which don't fail and return // a value larger than 0xfffffffffffff001 so we could test RawSyscall // vs. RawSyscallNoError on 64bit architectures. - if runtime.GOARCH != "386" && runtime.GOARCH != "arm" { + if unsafe.Sizeof(uintptr(0)) != 4 { t.Skip("skipping on non-32bit architecture") } From 8595868ea781a19b765319ce42da5c074c73ae34 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 17 Sep 2018 11:32:04 -0700 Subject: [PATCH 0389/1663] go/types: fix a couple of internal comments Change-Id: If0e8fbb05c09ee7c64e1aa6b0aa2ade35a70df8a Reviewed-on: https://go-review.googlesource.com/135696 Reviewed-by: Alan Donovan --- src/go/types/decl.go | 2 +- src/go/types/typexpr.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/go/types/decl.go b/src/go/types/decl.go index d37a460a4ee30..e248aab4f54c7 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -65,7 +65,7 @@ func objPathString(path []Object) string { } // objDecl type-checks the declaration of obj in its respective (file) context. -// See check.typ for the details on def and path. +// For the meaning of def, see Checker.definedType, in typexpr.go. func (check *Checker) objDecl(obj Object, def *Named) { if trace { check.trace(obj.Pos(), "-- checking %s %s (objPath = %s)", obj.color(), obj, objPathString(check.objPath)) diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index 83848099c2c2f..dab02bc13c9aa 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -16,7 +16,7 @@ import ( // ident type-checks identifier e and initializes x with the value or type of e. // If an error occurred, x.mode is set to invalid. -// For the meaning of def, see check.typExpr, below. +// For the meaning of def, see Checker.definedType, below. // func (check *Checker) ident(x *operand, e *ast.Ident, def *Named) { x.mode = invalid From e57f24ab39ff6e0ea50c84518e7f91b3a40cf547 Mon Sep 17 00:00:00 2001 From: Hana Kim Date: Mon, 17 Sep 2018 14:46:50 -0400 Subject: [PATCH 0390/1663] cmd/trace: don't drop sweep slice details For sweep events, we used to modify the ViewerEvent returned from ctx.emitSlice later in order to embed more details about the sweep operation. The trick no longer works after the change https://golang.org/cl/92375 and caused a regression. ctx.emit method encodes the ViewerEvent, so any modification to the ViewerEvent object after ctx.emit returns will not be reflected. Refactor ctx.emitSlice, so ctx.makeSlice can be used when producing slices for SWEEP. ctx.emit* methods are meant to truely emit ViewerEvents. Fixes #27711 Change-Id: I0b733ebbbfd4facd8714db0535809ec3cab0833d Reviewed-on: https://go-review.googlesource.com/135775 Reviewed-by: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot --- src/cmd/trace/trace.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/cmd/trace/trace.go b/src/cmd/trace/trace.go index d986b71f79e0a..676b9ffa5ab6b 100644 --- a/src/cmd/trace/trace.go +++ b/src/cmd/trace/trace.go @@ -685,13 +685,14 @@ func generateTrace(params *traceParams, consumer traceConsumer) error { } ctx.emitSlice(&fakeMarkStart, text) case trace.EvGCSweepStart: - slice := ctx.emitSlice(ev, "SWEEP") + slice := ctx.makeSlice(ev, "SWEEP") if done := ev.Link; done != nil && done.Args[0] != 0 { slice.Arg = struct { Swept uint64 `json:"Swept bytes"` Reclaimed uint64 `json:"Reclaimed bytes"` }{done.Args[0], done.Args[1]} } + ctx.emit(slice) case trace.EvGoStart, trace.EvGoStartLabel: info := getGInfo(ev.G) if ev.Type == trace.EvGoStartLabel { @@ -846,7 +847,11 @@ func (ctx *traceContext) proc(ev *trace.Event) uint64 { } } -func (ctx *traceContext) emitSlice(ev *trace.Event, name string) *ViewerEvent { +func (ctx *traceContext) emitSlice(ev *trace.Event, name string) { + ctx.emit(ctx.makeSlice(ev, name)) +} + +func (ctx *traceContext) makeSlice(ev *trace.Event, name string) *ViewerEvent { // If ViewerEvent.Dur is not a positive value, // trace viewer handles it as a non-terminating time interval. // Avoid it by setting the field with a small value. @@ -885,7 +890,6 @@ func (ctx *traceContext) emitSlice(ev *trace.Event, name string) *ViewerEvent { sl.Cname = colorLightGrey } } - ctx.emit(sl) return sl } From a19a83c8ef8283e4eacef846823c23ef9f50cf32 Mon Sep 17 00:00:00 2001 From: fanzha02 Date: Mon, 16 Jul 2018 04:45:25 +0000 Subject: [PATCH 0391/1663] cmd/compile: optimize math.Float64(32)bits and math.Float64(32)frombits on arm64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use float <-> int register moves without conversion instead of stores and loads to move float <-> int values. Math package benchmark results. name old time/op new time/op delta Acosh 153ns ± 0% 147ns ± 0% -3.92% (p=0.000 n=10+10) Asinh 183ns ± 0% 177ns ± 0% -3.28% (p=0.000 n=10+10) Atanh 157ns ± 0% 155ns ± 0% -1.27% (p=0.000 n=10+10) Atan2 118ns ± 0% 117ns ± 1% -0.59% (p=0.003 n=10+10) Cbrt 119ns ± 0% 114ns ± 0% -4.20% (p=0.000 n=10+10) Copysign 7.51ns ± 0% 6.51ns ± 0% -13.32% (p=0.000 n=9+10) Cos 73.1ns ± 0% 70.6ns ± 0% -3.42% (p=0.000 n=10+10) Cosh 119ns ± 0% 121ns ± 0% +1.68% (p=0.000 n=10+9) ExpGo 154ns ± 0% 149ns ± 0% -3.05% (p=0.000 n=9+10) Expm1 101ns ± 0% 99ns ± 0% -1.88% (p=0.000 n=10+10) Exp2Go 150ns ± 0% 146ns ± 0% -2.67% (p=0.000 n=10+10) Abs 7.01ns ± 0% 6.01ns ± 0% -14.27% (p=0.000 n=10+9) Mod 234ns ± 0% 212ns ± 0% -9.40% (p=0.000 n=9+10) Frexp 34.5ns ± 0% 30.0ns ± 0% -13.04% (p=0.000 n=10+10) Gamma 112ns ± 0% 111ns ± 0% -0.89% (p=0.000 n=10+10) Hypot 73.6ns ± 0% 68.6ns ± 0% -6.79% (p=0.000 n=10+10) HypotGo 77.1ns ± 0% 72.1ns ± 0% -6.49% (p=0.000 n=10+10) Ilogb 31.0ns ± 0% 28.0ns ± 0% -9.68% (p=0.000 n=10+10) J0 437ns ± 0% 434ns ± 0% -0.62% (p=0.000 n=10+10) J1 433ns ± 0% 431ns ± 0% -0.46% (p=0.000 n=10+10) Jn 927ns ± 0% 922ns ± 0% -0.54% (p=0.000 n=10+10) Ldexp 41.5ns ± 0% 37.0ns ± 0% -10.84% (p=0.000 n=9+10) Log 124ns ± 0% 118ns ± 0% -4.84% (p=0.000 n=10+9) Logb 34.0ns ± 0% 32.0ns ± 0% -5.88% (p=0.000 n=10+10) Log1p 110ns ± 0% 108ns ± 0% -1.82% (p=0.000 n=10+10) Log10 136ns ± 0% 132ns ± 0% -2.94% (p=0.000 n=10+10) Log2 51.6ns ± 0% 47.1ns ± 0% -8.72% (p=0.000 n=10+10) Nextafter32 33.0ns ± 0% 30.5ns ± 0% -7.58% (p=0.000 n=10+10) Nextafter64 29.0ns ± 0% 26.5ns ± 0% -8.62% (p=0.000 n=10+10) PowInt 169ns ± 0% 160ns ± 0% -5.33% (p=0.000 n=10+10) PowFrac 375ns ± 0% 361ns ± 0% -3.73% (p=0.000 n=10+10) RoundToEven 14.0ns ± 0% 12.5ns ± 0% -10.71% (p=0.000 n=10+10) Remainder 206ns ± 0% 192ns ± 0% -6.80% (p=0.000 n=10+9) Signbit 6.01ns ± 0% 5.51ns ± 0% -8.32% (p=0.000 n=10+9) Sin 70.1ns ± 0% 69.6ns ± 0% -0.71% (p=0.000 n=10+10) Sincos 99.1ns ± 0% 99.6ns ± 0% +0.50% (p=0.000 n=9+10) SqrtGoLatency 178ns ± 0% 146ns ± 0% -17.70% (p=0.000 n=8+10) SqrtPrime 9.19µs ± 0% 9.20µs ± 0% +0.01% (p=0.000 n=9+9) Tanh 125ns ± 1% 127ns ± 0% +1.36% (p=0.000 n=10+10) Y0 428ns ± 0% 426ns ± 0% -0.47% (p=0.000 n=10+10) Y1 431ns ± 0% 429ns ± 0% -0.46% (p=0.000 n=10+9) Yn 906ns ± 0% 901ns ± 0% -0.55% (p=0.000 n=10+10) Float64bits 4.50ns ± 0% 3.50ns ± 0% -22.22% (p=0.000 n=10+10) Float64frombits 4.00ns ± 0% 3.50ns ± 0% -12.50% (p=0.000 n=10+9) Float32bits 4.50ns ± 0% 3.50ns ± 0% -22.22% (p=0.002 n=8+10) Float32frombits 4.00ns ± 0% 3.50ns ± 0% -12.50% (p=0.000 n=10+10) Change-Id: Iba829e15d5624962fe0c699139ea783efeefabc2 Reviewed-on: https://go-review.googlesource.com/129715 Reviewed-by: Cherry Zhang Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/arm64/ssa.go | 2 + src/cmd/compile/internal/ssa/gen/ARM64.rules | 13 +- src/cmd/compile/internal/ssa/gen/ARM64Ops.go | 2 + src/cmd/compile/internal/ssa/opGen.go | 28 +++ src/cmd/compile/internal/ssa/rewriteARM64.go | 178 ++++++++++++++++++- src/math/all_test.go | 38 ++++ test/codegen/math.go | 6 + 7 files changed, 256 insertions(+), 11 deletions(-) diff --git a/src/cmd/compile/internal/arm64/ssa.go b/src/cmd/compile/internal/arm64/ssa.go index ce6d32f536fea..482442cd22532 100644 --- a/src/cmd/compile/internal/arm64/ssa.go +++ b/src/cmd/compile/internal/arm64/ssa.go @@ -701,6 +701,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { ssa.OpARM64FABSD, ssa.OpARM64FMOVDfpgp, ssa.OpARM64FMOVDgpfp, + ssa.OpARM64FMOVSfpgp, + ssa.OpARM64FMOVSgpfp, ssa.OpARM64FNEGS, ssa.OpARM64FNEGD, ssa.OpARM64FSQRTD, diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index b2ce875a057db..8fb39538c2a1c 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -110,8 +110,17 @@ (FMOVDfpgp (Arg [off] {sym})) -> @b.Func.Entry (Arg [off] {sym}) // Similarly for stores, if we see a store after FPR <-> GPR move, then redirect store to use the other register set. -(MOVDstore ptr (FMOVDfpgp val) mem) -> (FMOVDstore ptr val mem) -(FMOVDstore ptr (FMOVDgpfp val) mem) -> (MOVDstore ptr val mem) +(MOVDstore [off] {sym} ptr (FMOVDfpgp val) mem) -> (FMOVDstore [off] {sym} ptr val mem) +(FMOVDstore [off] {sym} ptr (FMOVDgpfp val) mem) -> (MOVDstore [off] {sym} ptr val mem) +(MOVWstore [off] {sym} ptr (FMOVSfpgp val) mem) -> (FMOVSstore [off] {sym} ptr val mem) +(FMOVSstore [off] {sym} ptr (FMOVSgpfp val) mem) -> (MOVWstore [off] {sym} ptr val mem) + +// float <-> int register moves, with no conversion. +// These come up when compiling math.{Float64bits, Float64frombits, Float32bits, Float32frombits}. +(MOVDload [off] {sym} ptr (FMOVDstore [off] {sym} ptr val _)) -> (FMOVDfpgp val) +(FMOVDload [off] {sym} ptr (MOVDstore [off] {sym} ptr val _)) -> (FMOVDgpfp val) +(MOVWUload [off] {sym} ptr (FMOVSstore [off] {sym} ptr val _)) -> (FMOVSfpgp val) +(FMOVSload [off] {sym} ptr (MOVWstore [off] {sym} ptr val _)) -> (FMOVSgpfp val) (BitLen64 x) -> (SUB (MOVDconst [64]) (CLZ x)) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go index da078517d44fe..4381c081b7b25 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go @@ -391,6 +391,8 @@ func init() { {name: "FMOVDgpfp", argLength: 1, reg: gpfp, asm: "FMOVD"}, // move int64 to float64 (no conversion) {name: "FMOVDfpgp", argLength: 1, reg: fpgp, asm: "FMOVD"}, // move float64 to int64 (no conversion) + {name: "FMOVSgpfp", argLength: 1, reg: gpfp, asm: "FMOVS"}, // move 32bits from int to float reg (no conversion) + {name: "FMOVSfpgp", argLength: 1, reg: fpgp, asm: "FMOVS"}, // move 32bits from float to int reg, zero extend (no conversion) // conversions {name: "MOVBreg", argLength: 1, reg: gp11, asm: "MOVB"}, // move from arg0, sign-extended from byte diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index b32dca410319a..77b9875fd6291 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -1250,6 +1250,8 @@ const ( OpARM64MOVDstorezeroidx8 OpARM64FMOVDgpfp OpARM64FMOVDfpgp + OpARM64FMOVSgpfp + OpARM64FMOVSfpgp OpARM64MOVBreg OpARM64MOVBUreg OpARM64MOVHreg @@ -16616,6 +16618,32 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "FMOVSgpfp", + argLen: 1, + asm: arm64.AFMOVS, + reg: regInfo{ + inputs: []inputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + outputs: []outputInfo{ + {0, 9223372034707292160}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 + }, + }, + }, + { + name: "FMOVSfpgp", + argLen: 1, + asm: arm64.AFMOVS, + reg: regInfo{ + inputs: []inputInfo{ + {0, 9223372034707292160}, // F0 F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12 F13 F14 F15 F16 F17 F18 F19 F20 F21 F22 F23 F24 F25 F26 F27 F28 F29 F30 F31 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, { name: "MOVBreg", argLen: 1, diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index 2108452c03b5f..5bf165df48f6d 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -4950,6 +4950,33 @@ func rewriteValueARM64_OpARM64FMOVDload_0(v *Value) bool { _ = b config := b.Func.Config _ = config + // match: (FMOVDload [off] {sym} ptr (MOVDstore [off] {sym} ptr val _)) + // cond: + // result: (FMOVDgpfp val) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDstore { + break + } + if v_1.AuxInt != off { + break + } + if v_1.Aux != sym { + break + } + _ = v_1.Args[2] + if ptr != v_1.Args[0] { + break + } + val := v_1.Args[1] + v.reset(OpARM64FMOVDgpfp) + v.AddArg(val) + return true + } // match: (FMOVDload [off1] {sym} (ADDconst [off2] ptr) mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) // result: (FMOVDload [off1+off2] {sym} ptr mem) @@ -5069,10 +5096,12 @@ func rewriteValueARM64_OpARM64FMOVDstore_0(v *Value) bool { _ = b config := b.Func.Config _ = config - // match: (FMOVDstore ptr (FMOVDgpfp val) mem) + // match: (FMOVDstore [off] {sym} ptr (FMOVDgpfp val) mem) // cond: - // result: (MOVDstore ptr val mem) + // result: (MOVDstore [off] {sym} ptr val mem) for { + off := v.AuxInt + sym := v.Aux _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] @@ -5082,6 +5111,8 @@ func rewriteValueARM64_OpARM64FMOVDstore_0(v *Value) bool { val := v_1.Args[0] mem := v.Args[2] v.reset(OpARM64MOVDstore) + v.AuxInt = off + v.Aux = sym v.AddArg(ptr) v.AddArg(val) v.AddArg(mem) @@ -5216,6 +5247,33 @@ func rewriteValueARM64_OpARM64FMOVSload_0(v *Value) bool { _ = b config := b.Func.Config _ = config + // match: (FMOVSload [off] {sym} ptr (MOVWstore [off] {sym} ptr val _)) + // cond: + // result: (FMOVSgpfp val) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWstore { + break + } + if v_1.AuxInt != off { + break + } + if v_1.Aux != sym { + break + } + _ = v_1.Args[2] + if ptr != v_1.Args[0] { + break + } + val := v_1.Args[1] + v.reset(OpARM64FMOVSgpfp) + v.AddArg(val) + return true + } // match: (FMOVSload [off1] {sym} (ADDconst [off2] ptr) mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) // result: (FMOVSload [off1+off2] {sym} ptr mem) @@ -5335,6 +5393,28 @@ func rewriteValueARM64_OpARM64FMOVSstore_0(v *Value) bool { _ = b config := b.Func.Config _ = config + // match: (FMOVSstore [off] {sym} ptr (FMOVSgpfp val) mem) + // cond: + // result: (MOVWstore [off] {sym} ptr val mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FMOVSgpfp { + break + } + val := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVWstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } // match: (FMOVSstore [off1] {sym} (ADDconst [off2] ptr) val mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) // result: (FMOVSstore [off1+off2] {sym} ptr val mem) @@ -11106,6 +11186,33 @@ func rewriteValueARM64_OpARM64MOVDload_0(v *Value) bool { _ = b config := b.Func.Config _ = config + // match: (MOVDload [off] {sym} ptr (FMOVDstore [off] {sym} ptr val _)) + // cond: + // result: (FMOVDfpgp val) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FMOVDstore { + break + } + if v_1.AuxInt != off { + break + } + if v_1.Aux != sym { + break + } + _ = v_1.Args[2] + if ptr != v_1.Args[0] { + break + } + val := v_1.Args[1] + v.reset(OpARM64FMOVDfpgp) + v.AddArg(val) + return true + } // match: (MOVDload [off1] {sym} (ADDconst [off2] ptr) mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) // result: (MOVDload [off1+off2] {sym} ptr mem) @@ -11408,10 +11515,12 @@ func rewriteValueARM64_OpARM64MOVDstore_0(v *Value) bool { _ = b config := b.Func.Config _ = config - // match: (MOVDstore ptr (FMOVDfpgp val) mem) + // match: (MOVDstore [off] {sym} ptr (FMOVDfpgp val) mem) // cond: - // result: (FMOVDstore ptr val mem) + // result: (FMOVDstore [off] {sym} ptr val mem) for { + off := v.AuxInt + sym := v.Aux _ = v.Args[2] ptr := v.Args[0] v_1 := v.Args[1] @@ -11421,6 +11530,8 @@ func rewriteValueARM64_OpARM64MOVDstore_0(v *Value) bool { val := v_1.Args[0] mem := v.Args[2] v.reset(OpARM64FMOVDstore) + v.AuxInt = off + v.Aux = sym v.AddArg(ptr) v.AddArg(val) v.AddArg(mem) @@ -14620,6 +14731,33 @@ func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { _ = b config := b.Func.Config _ = config + // match: (MOVWUload [off] {sym} ptr (FMOVSstore [off] {sym} ptr val _)) + // cond: + // result: (FMOVSfpgp val) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FMOVSstore { + break + } + if v_1.AuxInt != off { + break + } + if v_1.Aux != sym { + break + } + _ = v_1.Args[2] + if ptr != v_1.Args[0] { + break + } + val := v_1.Args[1] + v.reset(OpARM64FMOVSfpgp) + v.AddArg(val) + return true + } // match: (MOVWUload [off1] {sym} (ADDconst [off2] ptr) mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) // result: (MOVWUload [off1+off2] {sym} ptr mem) @@ -15644,6 +15782,28 @@ func rewriteValueARM64_OpARM64MOVWstore_0(v *Value) bool { _ = b config := b.Func.Config _ = config + // match: (MOVWstore [off] {sym} ptr (FMOVSfpgp val) mem) + // cond: + // result: (FMOVSstore [off] {sym} ptr val mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FMOVSfpgp { + break + } + val := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64FMOVSstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } // match: (MOVWstore [off1] {sym} (ADDconst [off2] ptr) val mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) // result: (MOVWstore [off1+off2] {sym} ptr val mem) @@ -15907,6 +16067,11 @@ func rewriteValueARM64_OpARM64MOVWstore_0(v *Value) bool { v.AddArg(mem) return true } + return false +} +func rewriteValueARM64_OpARM64MOVWstore_10(v *Value) bool { + b := v.Block + _ = b // match: (MOVWstore [4] {s} (ADDshiftLL [2] ptr0 idx0) (SRLconst [32] w) x:(MOVWstoreidx4 ptr1 idx1 w mem)) // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) // result: (MOVDstoreidx ptr1 (SLLconst [2] idx1) w mem) @@ -15958,11 +16123,6 @@ func rewriteValueARM64_OpARM64MOVWstore_0(v *Value) bool { v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVWstore_10(v *Value) bool { - b := v.Block - _ = b // match: (MOVWstore [i] {s} ptr0 (SRLconst [j] w) x:(MOVWstore [i-4] {s} ptr1 w0:(SRLconst [j-32] w) mem)) // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) // result: (MOVDstore [i-4] {s} ptr0 w0 mem) diff --git a/src/math/all_test.go b/src/math/all_test.go index 00f2058ea68b1..6a6d8bf6d0a08 100644 --- a/src/math/all_test.go +++ b/src/math/all_test.go @@ -3635,3 +3635,41 @@ func BenchmarkYn(b *testing.B) { } GlobalF = x } + +func BenchmarkFloat64bits(b *testing.B) { + y := uint64(0) + for i := 0; i < b.N; i++ { + y = Float64bits(roundNeg) + } + GlobalI = int(y) +} + +var roundUint64 = uint64(5) + +func BenchmarkFloat64frombits(b *testing.B) { + x := 0.0 + for i := 0; i < b.N; i++ { + x = Float64frombits(roundUint64) + } + GlobalF = x +} + +var roundFloat32 = float32(-2.5) + +func BenchmarkFloat32bits(b *testing.B) { + y := uint32(0) + for i := 0; i < b.N; i++ { + y = Float32bits(roundFloat32) + } + GlobalI = int(y) +} + +var roundUint32 = uint32(5) + +func BenchmarkFloat32frombits(b *testing.B) { + x := float32(0.0) + for i := 0; i < b.N; i++ { + x = Float32frombits(roundUint32) + } + GlobalF = float64(x) +} diff --git a/test/codegen/math.go b/test/codegen/math.go index 6afe1833459dd..78e7bfa1106bc 100644 --- a/test/codegen/math.go +++ b/test/codegen/math.go @@ -92,21 +92,25 @@ func copysign(a, b, c float64) { func fromFloat64(f64 float64) uint64 { // amd64:"MOVQ\tX.*, [^X].*" + // arm64:"FMOVD\tF.*, R.*" return math.Float64bits(f64+1) + 1 } func fromFloat32(f32 float32) uint32 { // amd64:"MOVL\tX.*, [^X].*" + // arm64:"FMOVS\tF.*, R.*" return math.Float32bits(f32+1) + 1 } func toFloat64(u64 uint64) float64 { // amd64:"MOVQ\t[^X].*, X.*" + // arm64:"FMOVD\tR.*, F.*" return math.Float64frombits(u64+1) + 1 } func toFloat32(u32 uint32) float32 { // amd64:"MOVL\t[^X].*, X.*" + // arm64:"FMOVS\tR.*, F.*" return math.Float32frombits(u32+1) + 1 } @@ -132,6 +136,7 @@ func constantConvert32(x float32) float32 { // amd64:"MOVSS\t[$]f32.3f800000\\(SB\\)" // s390x:"FMOVS\t[$]f32.3f800000\\(SB\\)" // ppc64le:"FMOVS\t[$]f32.3f800000\\(SB\\)" + // arm64:"FMOVS\t[$]\\(1.0\\)" if x > math.Float32frombits(0x3f800000) { return -x } @@ -142,6 +147,7 @@ func constantConvertInt32(x uint32) uint32 { // amd64:-"MOVSS" // s390x:-"FMOVS" // ppc64le:-"FMOVS" + // arm64:-"FMOVS" if x > math.Float32bits(1) { return -x } From bc529edc7f43e7e67598e66f4839e1aa6e971063 Mon Sep 17 00:00:00 2001 From: Eric Ponce Date: Thu, 30 Aug 2018 02:27:35 +0200 Subject: [PATCH 0392/1663] cmd/go: display correct options in "go help get" using modules Fixes: #27298 Change-Id: Icfc6992b470136bb25a77912f670a25883642316 Reviewed-on: https://go-review.googlesource.com/132095 Reviewed-by: Bryan C. Mills Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot --- src/cmd/go/main.go | 18 +++++++++--------- src/cmd/go/testdata/script/help.txt | 5 +++++ src/cmd/go/testdata/script/mod_help.txt | 6 ++++++ 3 files changed, 20 insertions(+), 9 deletions(-) create mode 100644 src/cmd/go/testdata/script/mod_help.txt diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index 31c554e715530..d6934ce5e9096 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -93,6 +93,15 @@ func main() { *get.CmdGet = *modget.CmdGet } + if args[0] == "get" || args[0] == "help" { + // Replace get with module-aware get if appropriate. + // Note that if MustUseModules is true, this happened already above, + // but no harm in doing it again. + if modload.Init(); modload.Enabled() { + *get.CmdGet = *modget.CmdGet + } + } + cfg.CmdName = args[0] // for error messages if args[0] == "help" { help.Help(os.Stdout, args[1:]) @@ -161,15 +170,6 @@ func main() { os.Exit(2) } - if args[0] == "get" { - // Replace get with module-aware get if appropriate. - // Note that if MustUseModules is true, this happened already above, - // but no harm in doing it again. - if modload.Init(); modload.Enabled() { - *get.CmdGet = *modget.CmdGet - } - } - // Set environment (GOOS, GOARCH, etc) explicitly. // In theory all the commands we invoke should have // the same default computation of these as we do, diff --git a/src/cmd/go/testdata/script/help.txt b/src/cmd/go/testdata/script/help.txt index 939da30283ad2..656e68010090d 100644 --- a/src/cmd/go/testdata/script/help.txt +++ b/src/cmd/go/testdata/script/help.txt @@ -34,3 +34,8 @@ stderr 'Run ''go help mod'' for usage.' ! go vet -h stderr 'usage: go vet' stderr 'Run ''go help vet'' for details' + +# go help get shows usage for get +go help get +stdout 'usage: go get' +stdout 'get when using GOPATH' \ No newline at end of file diff --git a/src/cmd/go/testdata/script/mod_help.txt b/src/cmd/go/testdata/script/mod_help.txt new file mode 100644 index 0000000000000..b5cd30c5219e8 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_help.txt @@ -0,0 +1,6 @@ +env GO111MODULE=on + +# go help get shows usage for get +go help get +stdout 'usage: go get' +stdout 'get using modules to manage source' \ No newline at end of file From 36531204f4febd614c249e0bbb05cc1a19d3f227 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 17 Sep 2018 12:46:33 -0700 Subject: [PATCH 0393/1663] go/types: simplify some internal code Change-Id: Ia32d40cc272cb049c0a7c9d5f8ef4329bdefc7fe Reviewed-on: https://go-review.googlesource.com/135699 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Alan Donovan --- src/go/types/decl.go | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/go/types/decl.go b/src/go/types/decl.go index e248aab4f54c7..0ff1fb058b8de 100644 --- a/src/go/types/decl.go +++ b/src/go/types/decl.go @@ -140,20 +140,12 @@ func (check *Checker) objDecl(obj Object, def *Named) { // order code. switch obj := obj.(type) { case *Const: - if check.typeCycle(obj) { - obj.typ = Typ[Invalid] - break - } - if obj.typ == nil { + if check.typeCycle(obj) || obj.typ == nil { obj.typ = Typ[Invalid] } case *Var: - if check.typeCycle(obj) { - obj.typ = Typ[Invalid] - break - } - if obj.typ == nil { + if check.typeCycle(obj) || obj.typ == nil { obj.typ = Typ[Invalid] } From d97b11f12fb36ae8117519ee983a8f811360ee1a Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Mon, 17 Sep 2018 13:43:35 -0700 Subject: [PATCH 0394/1663] go/types: don't report cycle error if clearer error follows If a cyclic declaration uses a non-type object where it expects a type, don't report the cycle error in favor of the clearer and more informative error about the missing type. Fixes #25790. Change-Id: If937078383def878efb4c69686e5b4b2a495fd5d Reviewed-on: https://go-review.googlesource.com/135700 Reviewed-by: Alan Donovan --- src/go/types/expr.go | 2 +- src/go/types/testdata/cycles5.src | 21 +++++++++++++++------ src/go/types/testdata/decls0.src | 10 +++++----- src/go/types/typexpr.go | 18 +++++++++++++++--- 4 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/go/types/expr.go b/src/go/types/expr.go index c65c9e7681dfe..fc4de98eb774b 100644 --- a/src/go/types/expr.go +++ b/src/go/types/expr.go @@ -1010,7 +1010,7 @@ func (check *Checker) exprInternal(x *operand, e ast.Expr, hint Type) exprKind { goto Error // error was reported before case *ast.Ident: - check.ident(x, e, nil) + check.ident(x, e, nil, false) case *ast.Ellipsis: // ellipses are handled explicitly where they are legal diff --git a/src/go/types/testdata/cycles5.src b/src/go/types/testdata/cycles5.src index 9c2822e738ac1..aa6528a6312e1 100644 --- a/src/go/types/testdata/cycles5.src +++ b/src/go/types/testdata/cycles5.src @@ -162,20 +162,29 @@ func makeArray() (res T12) { return } var r /* ERROR cycle */ = newReader() func newReader() r -// variations of the theme of #8699 amd #20770 +// variations of the theme of #8699 and #20770 var arr /* ERROR cycle */ = f() func f() [len(arr)]int -// TODO(gri) here we should only get one error -func ff /* ERROR cycle */ (ff /* ERROR not a type */ ) +// issue #25790 +func ff(ff /* ERROR not a type */ ) +func gg((gg /* ERROR not a type */ )) type T13 /* ERROR cycle */ [len(b13)]int var b13 T13 -func g /* ERROR cycle */ () [unsafe.Sizeof(x)]int -var x = g +func g1() [unsafe.Sizeof(g1)]int +func g2() [unsafe.Sizeof(x2)]int +var x2 = g2 -func h /* ERROR cycle */ () [h /* ERROR no value */ ()[0]]int { panic(0) } +// verify that we get the correct sizes for the functions above +// (note: assert is statically evaluated in go/types test mode) +func init() { + assert(unsafe.Sizeof(g1) == 8) + assert(unsafe.Sizeof(x2) == 8) +} + +func h() [h /* ERROR no value */ ()[0]]int { panic(0) } var c14 /* ERROR cycle */ T14 type T14 [uintptr(unsafe.Sizeof(&c14))]byte diff --git a/src/go/types/testdata/decls0.src b/src/go/types/testdata/decls0.src index 162dfeda04e3d..e75216172b83b 100644 --- a/src/go/types/testdata/decls0.src +++ b/src/go/types/testdata/decls0.src @@ -183,11 +183,11 @@ type ( ) // cycles in function/method declarations -// (test cases for issue 5217 and variants) -func f1 /* ERROR cycle */ (x f1 /* ERROR "not a type" */ ) {} -func f2 /* ERROR cycle */ (x *f2 /* ERROR "not a type" */ ) {} -func f3 /* ERROR cycle */ () (x f3 /* ERROR "not a type" */ ) { return } -func f4 /* ERROR cycle */ () (x *f4 /* ERROR "not a type" */ ) { return } +// (test cases for issues #5217, #25790 and variants) +func f1(x f1 /* ERROR "not a type" */ ) {} +func f2(x *f2 /* ERROR "not a type" */ ) {} +func f3() (x f3 /* ERROR "not a type" */ ) { return } +func f4() (x *f4 /* ERROR "not a type" */ ) { return } func (S0) m1(x S0.m1 /* ERROR "field or method" */ ) {} func (S0) m2(x *S0.m2 /* ERROR "field or method" */ ) {} diff --git a/src/go/types/typexpr.go b/src/go/types/typexpr.go index dab02bc13c9aa..12c5c7b0a5503 100644 --- a/src/go/types/typexpr.go +++ b/src/go/types/typexpr.go @@ -17,8 +17,9 @@ import ( // ident type-checks identifier e and initializes x with the value or type of e. // If an error occurred, x.mode is set to invalid. // For the meaning of def, see Checker.definedType, below. +// If wantType is set, the identifier e is expected to denote a type. // -func (check *Checker) ident(x *operand, e *ast.Ident, def *Named) { +func (check *Checker) ident(x *operand, e *ast.Ident, def *Named, wantType bool) { x.mode = invalid x.expr = e @@ -35,8 +36,19 @@ func (check *Checker) ident(x *operand, e *ast.Ident, def *Named) { } check.recordUse(e, obj) - check.objDecl(obj, def) + // Type-check the object. + // Only call Checker.objDecl if the object doesn't have a type yet + // (in which case we must actually determine it) or the object is a + // TypeName and we also want a type (in which case we might detect + // a cycle which needs to be reported). Otherwise we can skip the + // call and avoid a possible cycle error in favor of the more + // informative "not a type/value" error that this function's caller + // will issue (see issue #25790). typ := obj.Type() + if _, gotType := obj.(*TypeName); typ == nil || gotType && wantType { + check.objDecl(obj, def) + typ = obj.Type() // type must have been assigned by Checker.objDecl + } assert(typ != nil) // The object may be dot-imported: If so, remove its package from @@ -215,7 +227,7 @@ func (check *Checker) typInternal(e ast.Expr, def *Named) Type { case *ast.Ident: var x operand - check.ident(&x, e, def) + check.ident(&x, e, def, true) switch x.mode { case typexpr: From f082dbfd4f23b0c95ee1de5c2b091dad2ff6d930 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Sun, 16 Sep 2018 03:05:35 +0000 Subject: [PATCH 0395/1663] cmd/compile: fix wrong comment message in AMD64Ops.go According to AMD64.rules, BTS&BTR&BTC use arg1 as the bit index, while BT uses arg0. This CL fixes the wrong comment message in AMD64Ops.go, which indicates all bit indexes are in arg0. Change-Id: Idb78f4d39f7ef5ea78065ad8bc651324597e2a8a Reviewed-on: https://go-review.googlesource.com/135419 Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/gen/AMD64Ops.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go index 512df99694c9b..68facebe47e7c 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go @@ -272,14 +272,14 @@ func init() { {name: "UCOMISS", argLength: 2, reg: fp2flags, asm: "UCOMISS", typ: "Flags"}, // arg0 compare to arg1, f32 {name: "UCOMISD", argLength: 2, reg: fp2flags, asm: "UCOMISD", typ: "Flags"}, // arg0 compare to arg1, f64 - {name: "BTL", argLength: 2, reg: gp2flags, asm: "BTL", typ: "Flags"}, // test whether bit arg0 % 32 in arg1 is set - {name: "BTQ", argLength: 2, reg: gp2flags, asm: "BTQ", typ: "Flags"}, // test whether bit arg0 % 64 in arg1 is set - {name: "BTCL", argLength: 2, reg: gp21, asm: "BTCL", resultInArg0: true, clobberFlags: true}, // complement bit arg0 % 32 in arg1 - {name: "BTCQ", argLength: 2, reg: gp21, asm: "BTCQ", resultInArg0: true, clobberFlags: true}, // complement bit arg0 % 64 in arg1 - {name: "BTRL", argLength: 2, reg: gp21, asm: "BTRL", resultInArg0: true, clobberFlags: true}, // reset bit arg0 % 32 in arg1 - {name: "BTRQ", argLength: 2, reg: gp21, asm: "BTRQ", resultInArg0: true, clobberFlags: true}, // reset bit arg0 % 64 in arg1 - {name: "BTSL", argLength: 2, reg: gp21, asm: "BTSL", resultInArg0: true, clobberFlags: true}, // set bit arg0 % 32 in arg1 - {name: "BTSQ", argLength: 2, reg: gp21, asm: "BTSQ", resultInArg0: true, clobberFlags: true}, // set bit arg0 % 64 in arg1 + {name: "BTL", argLength: 2, reg: gp2flags, asm: "BTL", typ: "Flags"}, // test whether bit arg0%32 in arg1 is set + {name: "BTQ", argLength: 2, reg: gp2flags, asm: "BTQ", typ: "Flags"}, // test whether bit arg0%64 in arg1 is set + {name: "BTCL", argLength: 2, reg: gp21, asm: "BTCL", resultInArg0: true, clobberFlags: true}, // complement bit arg1%32 in arg0 + {name: "BTCQ", argLength: 2, reg: gp21, asm: "BTCQ", resultInArg0: true, clobberFlags: true}, // complement bit arg1%64 in arg0 + {name: "BTRL", argLength: 2, reg: gp21, asm: "BTRL", resultInArg0: true, clobberFlags: true}, // reset bit arg1%32 in arg0 + {name: "BTRQ", argLength: 2, reg: gp21, asm: "BTRQ", resultInArg0: true, clobberFlags: true}, // reset bit arg1%64 in arg0 + {name: "BTSL", argLength: 2, reg: gp21, asm: "BTSL", resultInArg0: true, clobberFlags: true}, // set bit arg1%32 in arg0 + {name: "BTSQ", argLength: 2, reg: gp21, asm: "BTSQ", resultInArg0: true, clobberFlags: true}, // set bit arg1%64 in arg0 {name: "BTLconst", argLength: 1, reg: gp1flags, asm: "BTL", typ: "Flags", aux: "Int8"}, // test whether bit auxint in arg0 is set, 0 <= auxint < 32 {name: "BTQconst", argLength: 1, reg: gp1flags, asm: "BTQ", typ: "Flags", aux: "Int8"}, // test whether bit auxint in arg0 is set, 0 <= auxint < 64 {name: "BTCLconst", argLength: 1, reg: gp11, asm: "BTCL", resultInArg0: true, clobberFlags: true, aux: "Int8"}, // complement bit auxint in arg0, 0 <= auxint < 32 From 0a8720580983c3a39c6c46fe08a2136a04bc118f Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Tue, 18 Sep 2018 01:13:04 +0300 Subject: [PATCH 0396/1663] cmd/compile/internal/gc: simplify bool expression Change-Id: Idcd79788e64947a927af662b6394ac7218e62ba8 Reviewed-on: https://go-review.googlesource.com/135836 Reviewed-by: Keith Randall Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/gc/walk.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 2993e08fc2b68..2c0bc4b22e74e 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -1418,7 +1418,7 @@ opswitch: // Maximum key and value size is 128 bytes, larger objects // are stored with an indirection. So max bucket size is 2048+eps. if !Isconst(hint, CTINT) || - !(hint.Val().U.(*Mpint).CmpInt64(BUCKETSIZE) > 0) { + hint.Val().U.(*Mpint).CmpInt64(BUCKETSIZE) <= 0 { // var bv bmap bv := temp(bmap(t)) From c381ba86572f568a6d6dccd1b8a6bd583955dc69 Mon Sep 17 00:00:00 2001 From: Ivy Evans Date: Thu, 13 Sep 2018 02:16:27 +0000 Subject: [PATCH 0397/1663] net/http: fix minor typos in Request godoc Fixes missing commas where it wasn't immediately apparent whether "requests" was being used as a verb or a noun. Change-Id: Ic8c99b4f46475f40a6160d26a3cd11c215940dd5 GitHub-Last-Rev: 1becf6fabeb6f928e37526e96297dd60397ccf9b GitHub-Pull-Request: golang/go#27649 Reviewed-on: https://go-review.googlesource.com/135135 Reviewed-by: Emmanuel Odeke --- src/net/http/request.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/net/http/request.go b/src/net/http/request.go index a40b0a3cb8385..ac3302934fe7d 100644 --- a/src/net/http/request.go +++ b/src/net/http/request.go @@ -105,7 +105,7 @@ var reqWriteExcludeHeader = map[string]bool{ // documentation for Request.Write and RoundTripper. type Request struct { // Method specifies the HTTP method (GET, POST, PUT, etc.). - // For client requests an empty string means GET. + // For client requests, an empty string means GET. // // Go's HTTP client does not support sending a request with // the CONNECT method. See the documentation on Transport for @@ -115,7 +115,7 @@ type Request struct { // URL specifies either the URI being requested (for server // requests) or the URL to access (for client requests). // - // For server requests the URL is parsed from the URI + // For server requests, the URL is parsed from the URI // supplied on the Request-Line as stored in RequestURI. For // most requests, fields other than Path and RawQuery will be // empty. (See RFC 7230, Section 5.3) @@ -128,7 +128,7 @@ type Request struct { // The protocol version for incoming server requests. // - // For client requests these fields are ignored. The HTTP + // For client requests, these fields are ignored. The HTTP // client code always uses either HTTP/1.1 or HTTP/2. // See the docs on Transport for details. Proto string // "HTTP/1.0" @@ -170,11 +170,11 @@ type Request struct { // Body is the request's body. // - // For client requests a nil body means the request has no + // For client requests, a nil body means the request has no // body, such as a GET request. The HTTP Client's Transport // is responsible for calling the Close method. // - // For server requests the Request Body is always non-nil + // For server requests, the Request Body is always non-nil // but will return EOF immediately when no body is present. // The Server will close the request body. The ServeHTTP // Handler does not need to. @@ -185,13 +185,14 @@ type Request struct { // reading the body more than once. Use of GetBody still // requires setting Body. // - // For server requests it is unused. + // For server requests, it is unused. GetBody func() (io.ReadCloser, error) // ContentLength records the length of the associated content. // The value -1 indicates that the length is unknown. // Values >= 0 indicate that the given number of bytes may // be read from Body. + // // For client requests, a value of 0 with a non-nil Body is // also treated as unknown. ContentLength int64 @@ -215,7 +216,7 @@ type Request struct { // Transport.DisableKeepAlives were set. Close bool - // For server requests Host specifies the host on which the URL + // For server requests, Host specifies the host on which the URL // is sought. Per RFC 7230, section 5.4, this is either the value // of the "Host" header or the host name given in the URL itself. // It may be of the form "host:port". For international domain @@ -228,7 +229,7 @@ type Request struct { // ServeMux supports patterns registered to particular host // names and thus protects its registered Handlers. // - // For client requests Host optionally overrides the Host + // For client requests, Host optionally overrides the Host // header to send. If empty, the Request.Write method uses // the value of URL.Host. Host may contain an international // domain name. @@ -255,14 +256,14 @@ type Request struct { // Trailer specifies additional headers that are sent after the request // body. // - // For server requests the Trailer map initially contains only the + // For server requests, the Trailer map initially contains only the // trailer keys, with nil values. (The client declares which trailers it // will later send.) While the handler is reading from Body, it must // not reference Trailer. After reading from Body returns EOF, Trailer // can be read again and will contain non-nil values, if they were sent // by the client. // - // For client requests Trailer must be initialized to a map containing + // For client requests, Trailer must be initialized to a map containing // the trailer keys to later send. The values may be nil or their final // values. The ContentLength must be 0 or -1, to send a chunked request. // After the HTTP request is sent the map values can be updated while From d45f24c084ee7f70797ad645f922ea820db28776 Mon Sep 17 00:00:00 2001 From: Lynn Boger Date: Thu, 13 Sep 2018 14:45:23 -0400 Subject: [PATCH 0398/1663] cmd/compile: use bounded shift information on ppc64x Makes use of bounded shift information to generate more efficient shift instructions. Updates #25167 for ppc64x Change-Id: I7fc8d49a3fb3e0f273cc51bc767470b239cbdca7 Reviewed-on: https://go-review.googlesource.com/135380 Run-TryBot: Lynn Boger TryBot-Result: Gobot Gobot Reviewed-by: Michael Munday --- src/cmd/compile/internal/ssa/gen/PPC64.rules | 14 + src/cmd/compile/internal/ssa/rewritePPC64.go | 798 ++++++++++++++++++- 2 files changed, 803 insertions(+), 9 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/PPC64.rules b/src/cmd/compile/internal/ssa/gen/PPC64.rules index bc218444c0838..e9e3cbc5bba68 100644 --- a/src/cmd/compile/internal/ssa/gen/PPC64.rules +++ b/src/cmd/compile/internal/ssa/gen/PPC64.rules @@ -168,6 +168,20 @@ (Rsh8x32 x (MOVDconst [c])) && uint32(c) < 8 -> (SRAWconst (SignExt8to32 x) [c]) (Rsh8Ux32 x (MOVDconst [c])) && uint32(c) < 8 -> (SRWconst (ZeroExt8to32 x) [c]) +// Lower bounded shifts first. No need to check shift value. +(Lsh64x(64|32|16|8) x y) && shiftIsBounded(v) -> (SLD x y) +(Lsh32x(64|32|16|8) x y) && shiftIsBounded(v) -> (SLW x y) +(Lsh16x(64|32|16|8) x y) && shiftIsBounded(v) -> (SLW x y) +(Lsh8x(64|32|16|8) x y) && shiftIsBounded(v) -> (SLW x y) +(Rsh64Ux(64|32|16|8) x y) && shiftIsBounded(v) -> (SRD x y) +(Rsh32Ux(64|32|16|8) x y) && shiftIsBounded(v) -> (SRW x y) +(Rsh16Ux(64|32|16|8) x y) && shiftIsBounded(v) -> (SRW (MOVHZreg x) y) +(Rsh8Ux(64|32|16|8) x y) && shiftIsBounded(v) -> (SRW (MOVBZreg x) y) +(Rsh64x(64|32|16|8) x y) && shiftIsBounded(v) -> (SRAD x y) +(Rsh32x(64|32|16|8) x y) && shiftIsBounded(v) -> (SRAW x y) +(Rsh16x(64|32|16|8) x y) && shiftIsBounded(v) -> (SRAW (MOVHreg x) y) +(Rsh8x(64|32|16|8) x y) && shiftIsBounded(v) -> (SRAW (MOVBreg x) y) + // non-constant rotates // These are subexpressions found in statements that can become rotates // In these cases the shift count is known to be < 64 so the more complicated expressions diff --git a/src/cmd/compile/internal/ssa/rewritePPC64.go b/src/cmd/compile/internal/ssa/rewritePPC64.go index 19ee33d9faf1a..a53db286d45c8 100644 --- a/src/cmd/compile/internal/ssa/rewritePPC64.go +++ b/src/cmd/compile/internal/ssa/rewritePPC64.go @@ -544,7 +544,7 @@ func rewriteValuePPC64(v *Value) bool { case OpRsh32Ux32: return rewriteValuePPC64_OpRsh32Ux32_0(v) case OpRsh32Ux64: - return rewriteValuePPC64_OpRsh32Ux64_0(v) + return rewriteValuePPC64_OpRsh32Ux64_0(v) || rewriteValuePPC64_OpRsh32Ux64_10(v) case OpRsh32Ux8: return rewriteValuePPC64_OpRsh32Ux8_0(v) case OpRsh32x16: @@ -552,7 +552,7 @@ func rewriteValuePPC64(v *Value) bool { case OpRsh32x32: return rewriteValuePPC64_OpRsh32x32_0(v) case OpRsh32x64: - return rewriteValuePPC64_OpRsh32x64_0(v) + return rewriteValuePPC64_OpRsh32x64_0(v) || rewriteValuePPC64_OpRsh32x64_10(v) case OpRsh32x8: return rewriteValuePPC64_OpRsh32x8_0(v) case OpRsh64Ux16: @@ -560,7 +560,7 @@ func rewriteValuePPC64(v *Value) bool { case OpRsh64Ux32: return rewriteValuePPC64_OpRsh64Ux32_0(v) case OpRsh64Ux64: - return rewriteValuePPC64_OpRsh64Ux64_0(v) + return rewriteValuePPC64_OpRsh64Ux64_0(v) || rewriteValuePPC64_OpRsh64Ux64_10(v) case OpRsh64Ux8: return rewriteValuePPC64_OpRsh64Ux8_0(v) case OpRsh64x16: @@ -568,7 +568,7 @@ func rewriteValuePPC64(v *Value) bool { case OpRsh64x32: return rewriteValuePPC64_OpRsh64x32_0(v) case OpRsh64x64: - return rewriteValuePPC64_OpRsh64x64_0(v) + return rewriteValuePPC64_OpRsh64x64_0(v) || rewriteValuePPC64_OpRsh64x64_10(v) case OpRsh64x8: return rewriteValuePPC64_OpRsh64x8_0(v) case OpRsh8Ux16: @@ -3070,6 +3070,21 @@ func rewriteValuePPC64_OpLsh16x16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Lsh16x16 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh16x16 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] (ZeroExt16to64 y))))) for { @@ -3136,6 +3151,21 @@ func rewriteValuePPC64_OpLsh16x32_0(v *Value) bool { return true } // match: (Lsh16x32 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh16x32 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] (ZeroExt32to64 y))))) for { @@ -3219,6 +3249,21 @@ func rewriteValuePPC64_OpLsh16x64_0(v *Value) bool { return true } // match: (Lsh16x64 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh16x64 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] y)))) for { @@ -3245,6 +3290,21 @@ func rewriteValuePPC64_OpLsh16x8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Lsh16x8 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh16x8 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] (ZeroExt8to64 y))))) for { @@ -3273,6 +3333,21 @@ func rewriteValuePPC64_OpLsh32x16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Lsh32x16 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh32x16 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] (ZeroExt16to64 y))))) for { @@ -3339,6 +3414,21 @@ func rewriteValuePPC64_OpLsh32x32_0(v *Value) bool { return true } // match: (Lsh32x32 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh32x32 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] (ZeroExt32to64 y))))) for { @@ -3421,6 +3511,21 @@ func rewriteValuePPC64_OpLsh32x64_0(v *Value) bool { v.AddArg(x) return true } + // match: (Lsh32x64 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } // match: (Lsh32x64 x (AND y (MOVDconst [31]))) // cond: // result: (SLW x (ANDconst [31] y)) @@ -3527,6 +3632,21 @@ func rewriteValuePPC64_OpLsh32x8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Lsh32x8 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh32x8 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] (ZeroExt8to64 y))))) for { @@ -3555,6 +3675,21 @@ func rewriteValuePPC64_OpLsh64x16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Lsh64x16 x y) + // cond: shiftIsBounded(v) + // result: (SLD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLD) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh64x16 x y) // cond: // result: (SLD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] (ZeroExt16to64 y))))) for { @@ -3621,6 +3756,21 @@ func rewriteValuePPC64_OpLsh64x32_0(v *Value) bool { return true } // match: (Lsh64x32 x y) + // cond: shiftIsBounded(v) + // result: (SLD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLD) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh64x32 x y) // cond: // result: (SLD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] (ZeroExt32to64 y))))) for { @@ -3703,6 +3853,21 @@ func rewriteValuePPC64_OpLsh64x64_0(v *Value) bool { v.AddArg(x) return true } + // match: (Lsh64x64 x y) + // cond: shiftIsBounded(v) + // result: (SLD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLD) + v.AddArg(x) + v.AddArg(y) + return true + } // match: (Lsh64x64 x (AND y (MOVDconst [63]))) // cond: // result: (SLD x (ANDconst [63] y)) @@ -3809,6 +3974,21 @@ func rewriteValuePPC64_OpLsh64x8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Lsh64x8 x y) + // cond: shiftIsBounded(v) + // result: (SLD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLD) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh64x8 x y) // cond: // result: (SLD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] (ZeroExt8to64 y))))) for { @@ -3837,6 +4017,21 @@ func rewriteValuePPC64_OpLsh8x16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Lsh8x16 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh8x16 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] (ZeroExt16to64 y))))) for { @@ -3903,6 +4098,21 @@ func rewriteValuePPC64_OpLsh8x32_0(v *Value) bool { return true } // match: (Lsh8x32 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh8x32 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] (ZeroExt32to64 y))))) for { @@ -3986,6 +4196,21 @@ func rewriteValuePPC64_OpLsh8x64_0(v *Value) bool { return true } // match: (Lsh8x64 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh8x64 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] y)))) for { @@ -4012,6 +4237,21 @@ func rewriteValuePPC64_OpLsh8x8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Lsh8x8 x y) + // cond: shiftIsBounded(v) + // result: (SLW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SLW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Lsh8x8 x y) // cond: // result: (SLW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] (ZeroExt8to64 y))))) for { @@ -25137,6 +25377,23 @@ func rewriteValuePPC64_OpRsh16Ux16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh16Ux16 x y) + // cond: shiftIsBounded(v) + // result: (SRW (MOVHZreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVHZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh16Ux16 x y) // cond: // result: (SRW (ZeroExt16to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] (ZeroExt16to64 y))))) for { @@ -25209,6 +25466,23 @@ func rewriteValuePPC64_OpRsh16Ux32_0(v *Value) bool { return true } // match: (Rsh16Ux32 x y) + // cond: shiftIsBounded(v) + // result: (SRW (MOVHZreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVHZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh16Ux32 x y) // cond: // result: (SRW (ZeroExt16to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] (ZeroExt32to64 y))))) for { @@ -25298,6 +25572,23 @@ func rewriteValuePPC64_OpRsh16Ux64_0(v *Value) bool { return true } // match: (Rsh16Ux64 x y) + // cond: shiftIsBounded(v) + // result: (SRW (MOVHZreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVHZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh16Ux64 x y) // cond: // result: (SRW (ZeroExt16to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] y)))) for { @@ -25326,6 +25617,23 @@ func rewriteValuePPC64_OpRsh16Ux8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh16Ux8 x y) + // cond: shiftIsBounded(v) + // result: (SRW (MOVHZreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVHZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh16Ux8 x y) // cond: // result: (SRW (ZeroExt16to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] (ZeroExt8to64 y))))) for { @@ -25356,18 +25664,35 @@ func rewriteValuePPC64_OpRsh16x16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh16x16 x y) - // cond: - // result: (SRAW (SignExt16to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] (ZeroExt16to64 y))))) + // cond: shiftIsBounded(v) + // result: (SRAW (MOVHreg x) y) for { _ = v.Args[1] x := v.Args[0] y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } v.reset(OpPPC64SRAW) - v0 := b.NewValue0(v.Pos, OpSignExt16to32, typ.Int32) + v0 := b.NewValue0(v.Pos, OpPPC64MOVHreg, typ.Int64) v0.AddArg(x) v.AddArg(v0) - v1 := b.NewValue0(v.Pos, OpPPC64ORN, typ.Int64) - v1.AddArg(y) + v.AddArg(y) + return true + } + // match: (Rsh16x16 x y) + // cond: + // result: (SRAW (SignExt16to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] (ZeroExt16to64 y))))) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + v.reset(OpPPC64SRAW) + v0 := b.NewValue0(v.Pos, OpSignExt16to32, typ.Int32) + v0.AddArg(x) + v.AddArg(v0) + v1 := b.NewValue0(v.Pos, OpPPC64ORN, typ.Int64) + v1.AddArg(y) v2 := b.NewValue0(v.Pos, OpPPC64MaskIfNotCarry, typ.Int64) v3 := b.NewValue0(v.Pos, OpPPC64ADDconstForCarry, types.TypeFlags) v3.AuxInt = -16 @@ -25428,6 +25753,23 @@ func rewriteValuePPC64_OpRsh16x32_0(v *Value) bool { return true } // match: (Rsh16x32 x y) + // cond: shiftIsBounded(v) + // result: (SRAW (MOVHreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVHreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh16x32 x y) // cond: // result: (SRAW (SignExt16to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] (ZeroExt32to64 y))))) for { @@ -25521,6 +25863,23 @@ func rewriteValuePPC64_OpRsh16x64_0(v *Value) bool { return true } // match: (Rsh16x64 x y) + // cond: shiftIsBounded(v) + // result: (SRAW (MOVHreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVHreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh16x64 x y) // cond: // result: (SRAW (SignExt16to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] y)))) for { @@ -25549,6 +25908,23 @@ func rewriteValuePPC64_OpRsh16x8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh16x8 x y) + // cond: shiftIsBounded(v) + // result: (SRAW (MOVHreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVHreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh16x8 x y) // cond: // result: (SRAW (SignExt16to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-16] (ZeroExt8to64 y))))) for { @@ -25579,6 +25955,21 @@ func rewriteValuePPC64_OpRsh32Ux16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh32Ux16 x y) + // cond: shiftIsBounded(v) + // result: (SRW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh32Ux16 x y) // cond: // result: (SRW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] (ZeroExt16to64 y))))) for { @@ -25645,6 +26036,21 @@ func rewriteValuePPC64_OpRsh32Ux32_0(v *Value) bool { return true } // match: (Rsh32Ux32 x y) + // cond: shiftIsBounded(v) + // result: (SRW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh32Ux32 x y) // cond: // result: (SRW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] (ZeroExt32to64 y))))) for { @@ -25727,6 +26133,21 @@ func rewriteValuePPC64_OpRsh32Ux64_0(v *Value) bool { v.AddArg(x) return true } + // match: (Rsh32Ux64 x y) + // cond: shiftIsBounded(v) + // result: (SRW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v.AddArg(x) + v.AddArg(y) + return true + } // match: (Rsh32Ux64 x (AND y (MOVDconst [31]))) // cond: // result: (SRW x (ANDconst [31] y)) @@ -25951,6 +26372,13 @@ func rewriteValuePPC64_OpRsh32Ux64_0(v *Value) bool { v.AddArg(v0) return true } + return false +} +func rewriteValuePPC64_OpRsh32Ux64_10(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (Rsh32Ux64 x y) // cond: // result: (SRW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] y)))) @@ -25978,6 +26406,21 @@ func rewriteValuePPC64_OpRsh32Ux8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh32Ux8 x y) + // cond: shiftIsBounded(v) + // result: (SRW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh32Ux8 x y) // cond: // result: (SRW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] (ZeroExt8to64 y))))) for { @@ -26006,6 +26449,21 @@ func rewriteValuePPC64_OpRsh32x16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh32x16 x y) + // cond: shiftIsBounded(v) + // result: (SRAW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh32x16 x y) // cond: // result: (SRAW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] (ZeroExt16to64 y))))) for { @@ -26072,6 +26530,21 @@ func rewriteValuePPC64_OpRsh32x32_0(v *Value) bool { return true } // match: (Rsh32x32 x y) + // cond: shiftIsBounded(v) + // result: (SRAW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh32x32 x y) // cond: // result: (SRAW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] (ZeroExt32to64 y))))) for { @@ -26156,6 +26629,21 @@ func rewriteValuePPC64_OpRsh32x64_0(v *Value) bool { v.AddArg(x) return true } + // match: (Rsh32x64 x y) + // cond: shiftIsBounded(v) + // result: (SRAW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v.AddArg(x) + v.AddArg(y) + return true + } // match: (Rsh32x64 x (AND y (MOVDconst [31]))) // cond: // result: (SRAW x (ANDconst [31] y)) @@ -26380,6 +26868,13 @@ func rewriteValuePPC64_OpRsh32x64_0(v *Value) bool { v.AddArg(v0) return true } + return false +} +func rewriteValuePPC64_OpRsh32x64_10(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (Rsh32x64 x y) // cond: // result: (SRAW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] y)))) @@ -26407,6 +26902,21 @@ func rewriteValuePPC64_OpRsh32x8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh32x8 x y) + // cond: shiftIsBounded(v) + // result: (SRAW x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh32x8 x y) // cond: // result: (SRAW x (ORN y (MaskIfNotCarry (ADDconstForCarry [-32] (ZeroExt8to64 y))))) for { @@ -26435,6 +26945,21 @@ func rewriteValuePPC64_OpRsh64Ux16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh64Ux16 x y) + // cond: shiftIsBounded(v) + // result: (SRD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRD) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh64Ux16 x y) // cond: // result: (SRD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] (ZeroExt16to64 y))))) for { @@ -26501,6 +27026,21 @@ func rewriteValuePPC64_OpRsh64Ux32_0(v *Value) bool { return true } // match: (Rsh64Ux32 x y) + // cond: shiftIsBounded(v) + // result: (SRD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRD) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh64Ux32 x y) // cond: // result: (SRD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] (ZeroExt32to64 y))))) for { @@ -26583,6 +27123,21 @@ func rewriteValuePPC64_OpRsh64Ux64_0(v *Value) bool { v.AddArg(x) return true } + // match: (Rsh64Ux64 x y) + // cond: shiftIsBounded(v) + // result: (SRD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRD) + v.AddArg(x) + v.AddArg(y) + return true + } // match: (Rsh64Ux64 x (AND y (MOVDconst [63]))) // cond: // result: (SRD x (ANDconst [63] y)) @@ -26807,6 +27362,13 @@ func rewriteValuePPC64_OpRsh64Ux64_0(v *Value) bool { v.AddArg(v0) return true } + return false +} +func rewriteValuePPC64_OpRsh64Ux64_10(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (Rsh64Ux64 x y) // cond: // result: (SRD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] y)))) @@ -26834,6 +27396,21 @@ func rewriteValuePPC64_OpRsh64Ux8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh64Ux8 x y) + // cond: shiftIsBounded(v) + // result: (SRD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRD) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh64Ux8 x y) // cond: // result: (SRD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] (ZeroExt8to64 y))))) for { @@ -26862,6 +27439,21 @@ func rewriteValuePPC64_OpRsh64x16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh64x16 x y) + // cond: shiftIsBounded(v) + // result: (SRAD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAD) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh64x16 x y) // cond: // result: (SRAD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] (ZeroExt16to64 y))))) for { @@ -26928,6 +27520,21 @@ func rewriteValuePPC64_OpRsh64x32_0(v *Value) bool { return true } // match: (Rsh64x32 x y) + // cond: shiftIsBounded(v) + // result: (SRAD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAD) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh64x32 x y) // cond: // result: (SRAD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] (ZeroExt32to64 y))))) for { @@ -27012,6 +27619,21 @@ func rewriteValuePPC64_OpRsh64x64_0(v *Value) bool { v.AddArg(x) return true } + // match: (Rsh64x64 x y) + // cond: shiftIsBounded(v) + // result: (SRAD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAD) + v.AddArg(x) + v.AddArg(y) + return true + } // match: (Rsh64x64 x (AND y (MOVDconst [63]))) // cond: // result: (SRAD x (ANDconst [63] y)) @@ -27236,6 +27858,13 @@ func rewriteValuePPC64_OpRsh64x64_0(v *Value) bool { v.AddArg(v0) return true } + return false +} +func rewriteValuePPC64_OpRsh64x64_10(v *Value) bool { + b := v.Block + _ = b + typ := &b.Func.Config.Types + _ = typ // match: (Rsh64x64 x y) // cond: // result: (SRAD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] y)))) @@ -27263,6 +27892,21 @@ func rewriteValuePPC64_OpRsh64x8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh64x8 x y) + // cond: shiftIsBounded(v) + // result: (SRAD x y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAD) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (Rsh64x8 x y) // cond: // result: (SRAD x (ORN y (MaskIfNotCarry (ADDconstForCarry [-64] (ZeroExt8to64 y))))) for { @@ -27291,6 +27935,23 @@ func rewriteValuePPC64_OpRsh8Ux16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh8Ux16 x y) + // cond: shiftIsBounded(v) + // result: (SRW (MOVBZreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVBZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh8Ux16 x y) // cond: // result: (SRW (ZeroExt8to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] (ZeroExt16to64 y))))) for { @@ -27363,6 +28024,23 @@ func rewriteValuePPC64_OpRsh8Ux32_0(v *Value) bool { return true } // match: (Rsh8Ux32 x y) + // cond: shiftIsBounded(v) + // result: (SRW (MOVBZreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVBZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh8Ux32 x y) // cond: // result: (SRW (ZeroExt8to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] (ZeroExt32to64 y))))) for { @@ -27452,6 +28130,23 @@ func rewriteValuePPC64_OpRsh8Ux64_0(v *Value) bool { return true } // match: (Rsh8Ux64 x y) + // cond: shiftIsBounded(v) + // result: (SRW (MOVBZreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVBZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh8Ux64 x y) // cond: // result: (SRW (ZeroExt8to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] y)))) for { @@ -27480,6 +28175,23 @@ func rewriteValuePPC64_OpRsh8Ux8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh8Ux8 x y) + // cond: shiftIsBounded(v) + // result: (SRW (MOVBZreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVBZreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh8Ux8 x y) // cond: // result: (SRW (ZeroExt8to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] (ZeroExt8to64 y))))) for { @@ -27510,6 +28222,23 @@ func rewriteValuePPC64_OpRsh8x16_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh8x16 x y) + // cond: shiftIsBounded(v) + // result: (SRAW (MOVBreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVBreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh8x16 x y) // cond: // result: (SRAW (SignExt8to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] (ZeroExt16to64 y))))) for { @@ -27582,6 +28311,23 @@ func rewriteValuePPC64_OpRsh8x32_0(v *Value) bool { return true } // match: (Rsh8x32 x y) + // cond: shiftIsBounded(v) + // result: (SRAW (MOVBreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVBreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh8x32 x y) // cond: // result: (SRAW (SignExt8to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] (ZeroExt32to64 y))))) for { @@ -27675,6 +28421,23 @@ func rewriteValuePPC64_OpRsh8x64_0(v *Value) bool { return true } // match: (Rsh8x64 x y) + // cond: shiftIsBounded(v) + // result: (SRAW (MOVBreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVBreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh8x64 x y) // cond: // result: (SRAW (SignExt8to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] y)))) for { @@ -27703,6 +28466,23 @@ func rewriteValuePPC64_OpRsh8x8_0(v *Value) bool { typ := &b.Func.Config.Types _ = typ // match: (Rsh8x8 x y) + // cond: shiftIsBounded(v) + // result: (SRAW (MOVBreg x) y) + for { + _ = v.Args[1] + x := v.Args[0] + y := v.Args[1] + if !(shiftIsBounded(v)) { + break + } + v.reset(OpPPC64SRAW) + v0 := b.NewValue0(v.Pos, OpPPC64MOVBreg, typ.Int64) + v0.AddArg(x) + v.AddArg(v0) + v.AddArg(y) + return true + } + // match: (Rsh8x8 x y) // cond: // result: (SRAW (SignExt8to32 x) (ORN y (MaskIfNotCarry (ADDconstForCarry [-8] (ZeroExt8to64 y))))) for { From 014901c5bab2f99af3b1019d5776fa5da6f5bef7 Mon Sep 17 00:00:00 2001 From: Mark Rushakoff Date: Thu, 30 Aug 2018 02:15:39 +0000 Subject: [PATCH 0399/1663] cmd/go: don't mention -mod=release The -mod=release flag is not supported, so this appears to be a documentation mistake. Fixes #27354. Change-Id: I895e8d5b4918adcb1f605361773173f312fa7b65 GitHub-Last-Rev: 42bfe0c11e38c90e76887771654ea81af98d50ec GitHub-Pull-Request: golang/go#27358 Reviewed-on: https://go-review.googlesource.com/132116 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- src/cmd/go/alldocs.go | 2 +- src/cmd/go/internal/work/build.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/alldocs.go b/src/cmd/go/alldocs.go index 969d51f5ab581..9528ca29844ba 100644 --- a/src/cmd/go/alldocs.go +++ b/src/cmd/go/alldocs.go @@ -144,7 +144,7 @@ // link against shared libraries previously created with // -buildmode=shared. // -mod mode -// module download mode to use: readonly, release, or vendor. +// module download mode to use: readonly or vendor. // See 'go help modules' for more. // -pkgdir dir // install and load all packages from dir instead of the usual locations. diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index ed41ce5d0730a..dd482b677d574 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -99,7 +99,7 @@ and test commands: link against shared libraries previously created with -buildmode=shared. -mod mode - module download mode to use: readonly, release, or vendor. + module download mode to use: readonly or vendor. See 'go help modules' for more. -pkgdir dir install and load all packages from dir instead of the usual locations. From 19ac6a82d3be818572881d60026109946a5a69e6 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 18 Sep 2018 07:58:11 -0700 Subject: [PATCH 0400/1663] runtime: ignore EAGAIN from exec in TestCgoExecSignalMask Fixes #27731 Change-Id: Ifb4d57923b1bba0210ec1f623d779d7b5f442812 Reviewed-on: https://go-review.googlesource.com/135995 Run-TryBot: Ian Lance Taylor Reviewed-by: Michael Munday TryBot-Result: Gobot Gobot --- src/runtime/testdata/testprogcgo/exec.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/runtime/testdata/testprogcgo/exec.go b/src/runtime/testdata/testprogcgo/exec.go index 2e948401c87a5..94da5dc526bc2 100644 --- a/src/runtime/testdata/testprogcgo/exec.go +++ b/src/runtime/testdata/testprogcgo/exec.go @@ -75,6 +75,14 @@ func CgoExecSignalMask() { cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { + // An overloaded system + // may fail with EAGAIN. + // This doesn't tell us + // anything useful; ignore it. + // Issue #27731. + if isEAGAIN(err) { + return + } fmt.Printf("iteration %d: %v\n", j, err) os.Exit(1) } @@ -87,3 +95,11 @@ func CgoExecSignalMask() { fmt.Println("OK") } + +// isEAGAIN reports whether err is an EAGAIN error from a process execution. +func isEAGAIN(err error) bool { + if p, ok := err.(*os.PathError); ok { + err = p.Err + } + return err == syscall.EAGAIN +} From a0f5d5f8830e578892c47f7704e6a2616273aac1 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Mon, 10 Sep 2018 15:36:59 +0200 Subject: [PATCH 0401/1663] cmd/link: fix DWARF refs so that they always point to the typedef entry For types defined as: type typename struct { ... } the linker produces two DIEs: (1) a DW_TAG_structure_type DIE and (2) a DW_TAG_typedef_type DIE having (1) as its type attribute. All subsequent references to 'typename' should use the DW_TAG_typedef_type DIE, not the DW_TAG_structure_type. Mostly this is true but sometimes one reference will use the DW_TAG_structure_type directly. In particular, this happens to the 'first' reference to the type in question (where 'first' means whatever happens first in the way the linker scans its symbols). This isn't only true of struct types: pointer types, array types, etc. can also be affected. This fix solves the problem by always returning the typedef DIE in newtype, when one is created. Fixes #27614 Change-Id: Ia65b4a1d8c2b752e33a4ebdb74ccd92faa69526e Reviewed-on: https://go-review.googlesource.com/134555 TryBot-Result: Gobot Gobot Reviewed-by: Than McIntosh --- src/cmd/link/internal/ld/dwarf.go | 29 ++++--- src/cmd/link/internal/ld/dwarf_test.go | 114 +++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 12 deletions(-) diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index 959fc8290c08d..2164fa80a0f2b 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -340,19 +340,19 @@ func lookupOrDiag(ctxt *Link, n string) *sym.Symbol { return s } -func dotypedef(ctxt *Link, parent *dwarf.DWDie, name string, def *dwarf.DWDie) { +func dotypedef(ctxt *Link, parent *dwarf.DWDie, name string, def *dwarf.DWDie) *dwarf.DWDie { // Only emit typedefs for real names. if strings.HasPrefix(name, "map[") { - return + return nil } if strings.HasPrefix(name, "struct {") { - return + return nil } if strings.HasPrefix(name, "chan ") { - return + return nil } if name[0] == '[' || name[0] == '*' { - return + return nil } if def == nil { Errorf(nil, "dwarf: bad def in dotypedef") @@ -370,6 +370,8 @@ func dotypedef(ctxt *Link, parent *dwarf.DWDie, name string, def *dwarf.DWDie) { die := newdie(ctxt, parent, dwarf.DW_ABRV_TYPEDECL, name, 0) newrefattr(die, dwarf.DW_AT_type, s) + + return die } // Define gotype, for composite ones recurse into constituents. @@ -399,7 +401,7 @@ func newtype(ctxt *Link, gotype *sym.Symbol) *dwarf.DWDie { kind := decodetypeKind(ctxt.Arch, gotype) bytesize := decodetypeSize(ctxt.Arch, gotype) - var die *dwarf.DWDie + var die, typedefdie *dwarf.DWDie switch kind { case objabi.KindBool: die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_BASETYPE, name, 0) @@ -439,7 +441,7 @@ func newtype(ctxt *Link, gotype *sym.Symbol) *dwarf.DWDie { case objabi.KindArray: die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_ARRAYTYPE, name, 0) - dotypedef(ctxt, &dwtypes, name, die) + typedefdie = dotypedef(ctxt, &dwtypes, name, die) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) s := decodetypeArrayElem(ctxt.Arch, gotype) newrefattr(die, dwarf.DW_AT_type, defgotype(ctxt, s)) @@ -461,7 +463,7 @@ func newtype(ctxt *Link, gotype *sym.Symbol) *dwarf.DWDie { case objabi.KindFunc: die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_FUNCTYPE, name, 0) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) - dotypedef(ctxt, &dwtypes, name, die) + typedefdie = dotypedef(ctxt, &dwtypes, name, die) nfields := decodetypeFuncInCount(ctxt.Arch, gotype) for i := 0; i < nfields; i++ { s := decodetypeFuncInType(ctxt.Arch, gotype, i) @@ -481,7 +483,7 @@ func newtype(ctxt *Link, gotype *sym.Symbol) *dwarf.DWDie { case objabi.KindInterface: die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_IFACETYPE, name, 0) - dotypedef(ctxt, &dwtypes, name, die) + typedefdie = dotypedef(ctxt, &dwtypes, name, die) nfields := int(decodetypeIfaceMethodCount(ctxt.Arch, gotype)) var s *sym.Symbol if nfields == 0 { @@ -503,13 +505,13 @@ func newtype(ctxt *Link, gotype *sym.Symbol) *dwarf.DWDie { case objabi.KindPtr: die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_PTRTYPE, name, 0) - dotypedef(ctxt, &dwtypes, name, die) + typedefdie = dotypedef(ctxt, &dwtypes, name, die) s := decodetypePtrElem(ctxt.Arch, gotype) newrefattr(die, dwarf.DW_AT_type, defgotype(ctxt, s)) case objabi.KindSlice: die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_SLICETYPE, name, 0) - dotypedef(ctxt, &dwtypes, name, die) + typedefdie = dotypedef(ctxt, &dwtypes, name, die) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) s := decodetypeArrayElem(ctxt.Arch, gotype) elem := defgotype(ctxt, s) @@ -521,7 +523,7 @@ func newtype(ctxt *Link, gotype *sym.Symbol) *dwarf.DWDie { case objabi.KindStruct: die = newdie(ctxt, &dwtypes, dwarf.DW_ABRV_STRUCTTYPE, name, 0) - dotypedef(ctxt, &dwtypes, name, die) + typedefdie = dotypedef(ctxt, &dwtypes, name, die) newattr(die, dwarf.DW_AT_byte_size, dwarf.DW_CLS_CONSTANT, bytesize, 0) nfields := decodetypeStructFieldCount(ctxt.Arch, gotype) for i := 0; i < nfields; i++ { @@ -557,6 +559,9 @@ func newtype(ctxt *Link, gotype *sym.Symbol) *dwarf.DWDie { prototypedies[gotype.Name] = die } + if typedefdie != nil { + return typedefdie + } return die } diff --git a/src/cmd/link/internal/ld/dwarf_test.go b/src/cmd/link/internal/ld/dwarf_test.go index 157bebbb41256..5d2aadf589970 100644 --- a/src/cmd/link/internal/ld/dwarf_test.go +++ b/src/cmd/link/internal/ld/dwarf_test.go @@ -948,3 +948,117 @@ func main() { t.Errorf("DWARF type offset was %#x+%#x, but test program said %#x", rtAttr.(uint64), types.Addr, addr) } } + +func TestIssue27614(t *testing.T) { + // Type references in debug_info should always use the DW_TAG_typedef_type + // for the type, when that's generated. + + testenv.MustHaveGoBuild(t) + + if runtime.GOOS == "plan9" { + t.Skip("skipping on plan9; no DWARF symbol table in executables") + } + + dir, err := ioutil.TempDir("", "go-build") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(dir) + + const prog = `package main + +import "fmt" + +type astruct struct { + X int +} + +type bstruct struct { + X float32 +} + +var globalptr *astruct +var globalvar astruct +var bvar0, bvar1, bvar2 bstruct + +func main() { + fmt.Println(globalptr, globalvar, bvar0, bvar1, bvar2) +} +` + + f := gobuild(t, dir, prog, NoOpt) + + defer f.Close() + + data, err := f.DWARF() + if err != nil { + t.Fatal(err) + } + + rdr := data.Reader() + + var astructTypeDIE, bstructTypeDIE, ptrastructTypeDIE *dwarf.Entry + var globalptrDIE, globalvarDIE *dwarf.Entry + var bvarDIE [3]*dwarf.Entry + + for { + e, err := rdr.Next() + if err != nil { + t.Fatal(err) + } + if e == nil { + break + } + + name, _ := e.Val(dwarf.AttrName).(string) + + switch e.Tag { + case dwarf.TagTypedef: + switch name { + case "main.astruct": + astructTypeDIE = e + case "main.bstruct": + bstructTypeDIE = e + } + case dwarf.TagPointerType: + if name == "*main.astruct" { + ptrastructTypeDIE = e + } + case dwarf.TagVariable: + switch name { + case "main.globalptr": + globalptrDIE = e + case "main.globalvar": + globalvarDIE = e + default: + const bvarprefix = "main.bvar" + if strings.HasPrefix(name, bvarprefix) { + i, _ := strconv.Atoi(name[len(bvarprefix):]) + bvarDIE[i] = e + } + } + } + } + + typedieof := func(e *dwarf.Entry) dwarf.Offset { + return e.Val(dwarf.AttrType).(dwarf.Offset) + } + + if off := typedieof(ptrastructTypeDIE); off != astructTypeDIE.Offset { + t.Errorf("type attribute of *main.astruct references %#x, not main.astruct DIE at %#x\n", off, astructTypeDIE.Offset) + } + + if off := typedieof(globalptrDIE); off != ptrastructTypeDIE.Offset { + t.Errorf("type attribute of main.globalptr references %#x, not *main.astruct DIE at %#x\n", off, ptrastructTypeDIE.Offset) + } + + if off := typedieof(globalvarDIE); off != astructTypeDIE.Offset { + t.Errorf("type attribute of main.globalvar1 references %#x, not main.astruct DIE at %#x\n", off, astructTypeDIE.Offset) + } + + for i := range bvarDIE { + if off := typedieof(bvarDIE[i]); off != bstructTypeDIE.Offset { + t.Errorf("type attribute of main.bvar%d references %#x, not main.bstruct DIE at %#x\n", i, off, bstructTypeDIE.Offset) + } + } +} From 77f9b2728eb08456899e6500328e00ec4829dddf Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 14 Sep 2018 09:57:06 +0200 Subject: [PATCH 0402/1663] runtime: use MADV_FREE on Linux if available On Linux, sysUnused currently uses madvise(MADV_DONTNEED) to signal the kernel that a range of allocated memory contains unneeded data. After a successful call, the range (but not the data it contained before the call to madvise) is still available but the first access to that range will unconditionally incur a page fault (needed to 0-fill the range). A faster alternative is MADV_FREE, available since Linux 4.5. The mechanism is very similar, but the page fault will only be incurred if the kernel, between the call to madvise and the first access, decides to reuse that memory for something else. In sysUnused, test whether MADV_FREE is supported and fall back to MADV_DONTNEED in case it isn't. This requires making the return value of the madvise syscall available to the caller, so change runtime.madvise to return it. Fixes #23687 Change-Id: I962c3429000dd9f4a00846461ad128b71201bb04 Reviewed-on: https://go-review.googlesource.com/135395 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/defs2_linux.go | 5 ++++- src/runtime/defs_linux.go | 5 ++++- src/runtime/defs_linux_386.go | 1 + src/runtime/defs_linux_amd64.go | 1 + src/runtime/defs_linux_arm.go | 1 + src/runtime/defs_linux_arm64.go | 1 + src/runtime/defs_linux_mips64x.go | 1 + src/runtime/defs_linux_mipsx.go | 1 + src/runtime/defs_linux_ppc64.go | 1 + src/runtime/defs_linux_ppc64le.go | 1 + src/runtime/defs_linux_s390x.go | 1 + src/runtime/mem_linux.go | 13 +++++++++++-- src/runtime/stubs2.go | 3 ++- src/runtime/sys_dragonfly_amd64.s | 6 ++++-- src/runtime/sys_freebsd_386.s | 4 +++- src/runtime/sys_freebsd_amd64.s | 6 ++++-- src/runtime/sys_freebsd_arm.s | 15 ++++++++------- src/runtime/sys_linux_386.s | 2 +- src/runtime/sys_linux_amd64.s | 2 +- src/runtime/sys_linux_arm.s | 2 +- src/runtime/sys_linux_arm64.s | 2 +- src/runtime/sys_linux_mips64x.s | 2 +- src/runtime/sys_linux_mipsx.s | 4 ++-- src/runtime/sys_linux_ppc64x.s | 2 +- src/runtime/sys_linux_s390x.s | 2 +- src/runtime/sys_netbsd_386.s | 4 +++- src/runtime/sys_netbsd_amd64.s | 4 +++- src/runtime/sys_netbsd_arm.s | 11 ++++++----- src/runtime/sys_openbsd_386.s | 3 ++- src/runtime/sys_openbsd_amd64.s | 4 +++- src/runtime/sys_openbsd_arm.s | 4 ++-- 31 files changed, 77 insertions(+), 37 deletions(-) diff --git a/src/runtime/defs2_linux.go b/src/runtime/defs2_linux.go index c10dfb8624000..b08c0dafe12f2 100644 --- a/src/runtime/defs2_linux.go +++ b/src/runtime/defs2_linux.go @@ -58,7 +58,10 @@ const ( MAP_PRIVATE = C.MAP_PRIVATE MAP_FIXED = C.MAP_FIXED - MADV_DONTNEED = C.MADV_DONTNEED + MADV_DONTNEED = C.MADV_DONTNEED + MADV_FREE = C.MADV_FREE + MADV_HUGEPAGE = C.MADV_HUGEPAGE + MADV_NOHUGEPAGE = C.MADV_HNOUGEPAGE SA_RESTART = C.SA_RESTART SA_ONSTACK = C.SA_ONSTACK diff --git a/src/runtime/defs_linux.go b/src/runtime/defs_linux.go index 553366a50ba6c..2d810136d9871 100644 --- a/src/runtime/defs_linux.go +++ b/src/runtime/defs_linux.go @@ -47,7 +47,10 @@ const ( MAP_PRIVATE = C.MAP_PRIVATE MAP_FIXED = C.MAP_FIXED - MADV_DONTNEED = C.MADV_DONTNEED + MADV_DONTNEED = C.MADV_DONTNEED + MADV_FREE = C.MADV_FREE + MADV_HUGEPAGE = C.MADV_HUGEPAGE + MADV_NOHUGEPAGE = C.MADV_HNOUGEPAGE SA_RESTART = C.SA_RESTART SA_ONSTACK = C.SA_ONSTACK diff --git a/src/runtime/defs_linux_386.go b/src/runtime/defs_linux_386.go index a7e435f854fe3..0ebac17aefa9e 100644 --- a/src/runtime/defs_linux_386.go +++ b/src/runtime/defs_linux_386.go @@ -18,6 +18,7 @@ const ( _MAP_FIXED = 0x10 _MADV_DONTNEED = 0x4 + _MADV_FREE = 0x8 _MADV_HUGEPAGE = 0xe _MADV_NOHUGEPAGE = 0xf diff --git a/src/runtime/defs_linux_amd64.go b/src/runtime/defs_linux_amd64.go index e8c6a212db770..c0a0ef0dd4ec5 100644 --- a/src/runtime/defs_linux_amd64.go +++ b/src/runtime/defs_linux_amd64.go @@ -18,6 +18,7 @@ const ( _MAP_FIXED = 0x10 _MADV_DONTNEED = 0x4 + _MADV_FREE = 0x8 _MADV_HUGEPAGE = 0xe _MADV_NOHUGEPAGE = 0xf diff --git a/src/runtime/defs_linux_arm.go b/src/runtime/defs_linux_arm.go index 62ec8fab5e9b5..43946bb79ca8e 100644 --- a/src/runtime/defs_linux_arm.go +++ b/src/runtime/defs_linux_arm.go @@ -16,6 +16,7 @@ const ( _MAP_FIXED = 0x10 _MADV_DONTNEED = 0x4 + _MADV_FREE = 0x8 _MADV_HUGEPAGE = 0xe _MADV_NOHUGEPAGE = 0xf diff --git a/src/runtime/defs_linux_arm64.go b/src/runtime/defs_linux_arm64.go index c295bc0257520..c2cc281ab4f5c 100644 --- a/src/runtime/defs_linux_arm64.go +++ b/src/runtime/defs_linux_arm64.go @@ -18,6 +18,7 @@ const ( _MAP_FIXED = 0x10 _MADV_DONTNEED = 0x4 + _MADV_FREE = 0x8 _MADV_HUGEPAGE = 0xe _MADV_NOHUGEPAGE = 0xf diff --git a/src/runtime/defs_linux_mips64x.go b/src/runtime/defs_linux_mips64x.go index df11cb0965d69..9dacd5d1e9bac 100644 --- a/src/runtime/defs_linux_mips64x.go +++ b/src/runtime/defs_linux_mips64x.go @@ -18,6 +18,7 @@ const ( _MAP_FIXED = 0x10 _MADV_DONTNEED = 0x4 + _MADV_FREE = 0x8 _MADV_HUGEPAGE = 0xe _MADV_NOHUGEPAGE = 0xf diff --git a/src/runtime/defs_linux_mipsx.go b/src/runtime/defs_linux_mipsx.go index 702fbb51c861c..9532ac54ee83d 100644 --- a/src/runtime/defs_linux_mipsx.go +++ b/src/runtime/defs_linux_mipsx.go @@ -22,6 +22,7 @@ const ( _MAP_FIXED = 0x10 _MADV_DONTNEED = 0x4 + _MADV_FREE = 0x8 _MADV_HUGEPAGE = 0xe _MADV_NOHUGEPAGE = 0xf diff --git a/src/runtime/defs_linux_ppc64.go b/src/runtime/defs_linux_ppc64.go index 45363d12854be..5a4326da07a94 100644 --- a/src/runtime/defs_linux_ppc64.go +++ b/src/runtime/defs_linux_ppc64.go @@ -18,6 +18,7 @@ const ( _MAP_FIXED = 0x10 _MADV_DONTNEED = 0x4 + _MADV_FREE = 0x8 _MADV_HUGEPAGE = 0xe _MADV_NOHUGEPAGE = 0xf diff --git a/src/runtime/defs_linux_ppc64le.go b/src/runtime/defs_linux_ppc64le.go index 45363d12854be..5a4326da07a94 100644 --- a/src/runtime/defs_linux_ppc64le.go +++ b/src/runtime/defs_linux_ppc64le.go @@ -18,6 +18,7 @@ const ( _MAP_FIXED = 0x10 _MADV_DONTNEED = 0x4 + _MADV_FREE = 0x8 _MADV_HUGEPAGE = 0xe _MADV_NOHUGEPAGE = 0xf diff --git a/src/runtime/defs_linux_s390x.go b/src/runtime/defs_linux_s390x.go index ab90723f75485..a6cc9c48e91de 100644 --- a/src/runtime/defs_linux_s390x.go +++ b/src/runtime/defs_linux_s390x.go @@ -19,6 +19,7 @@ const ( _MAP_FIXED = 0x10 _MADV_DONTNEED = 0x4 + _MADV_FREE = 0x8 _MADV_HUGEPAGE = 0xe _MADV_NOHUGEPAGE = 0xf diff --git a/src/runtime/mem_linux.go b/src/runtime/mem_linux.go index 7aa48170a1164..845f72ded2c16 100644 --- a/src/runtime/mem_linux.go +++ b/src/runtime/mem_linux.go @@ -5,6 +5,7 @@ package runtime import ( + "runtime/internal/atomic" "runtime/internal/sys" "unsafe" ) @@ -34,10 +35,12 @@ func sysAlloc(n uintptr, sysStat *uint64) unsafe.Pointer { return p } +var adviseUnused = uint32(_MADV_FREE) + func sysUnused(v unsafe.Pointer, n uintptr) { // By default, Linux's "transparent huge page" support will // merge pages into a huge page if there's even a single - // present regular page, undoing the effects of the DONTNEED + // present regular page, undoing the effects of madvise(adviseUnused) // below. On amd64, that means khugepaged can turn a single // 4KB page to 2MB, bloating the process's RSS by as much as // 512X. (See issue #8832 and Linux kernel bug @@ -102,7 +105,13 @@ func sysUnused(v unsafe.Pointer, n uintptr) { throw("unaligned sysUnused") } - madvise(v, n, _MADV_DONTNEED) + advise := atomic.Load(&adviseUnused) + if errno := madvise(v, n, int32(advise)); advise == _MADV_FREE && errno != 0 { + // MADV_FREE was added in Linux 4.5. Fall back to MADV_DONTNEED if it is + // not supported. + atomic.Store(&adviseUnused, _MADV_DONTNEED) + madvise(v, n, _MADV_DONTNEED) + } } func sysUsed(v unsafe.Pointer, n uintptr) { diff --git a/src/runtime/stubs2.go b/src/runtime/stubs2.go index 02249d0aadc67..c14db74003fe2 100644 --- a/src/runtime/stubs2.go +++ b/src/runtime/stubs2.go @@ -25,7 +25,8 @@ func write(fd uintptr, p unsafe.Pointer, n int32) int32 //go:noescape func open(name *byte, mode, perm int32) int32 -func madvise(addr unsafe.Pointer, n uintptr, flags int32) +// return value is only set on linux to be used in osinit() +func madvise(addr unsafe.Pointer, n uintptr, flags int32) int32 // exitThread terminates the current thread, writing *wait = 0 when // the stack is safe to reclaim. diff --git a/src/runtime/sys_dragonfly_amd64.s b/src/runtime/sys_dragonfly_amd64.s index f0eb5f4e21614..b18e9676513d7 100644 --- a/src/runtime/sys_dragonfly_amd64.s +++ b/src/runtime/sys_dragonfly_amd64.s @@ -260,9 +260,11 @@ TEXT runtime·madvise(SB),NOSPLIT,$0 MOVL flags+16(FP), DX MOVQ $75, AX // madvise SYSCALL - // ignore failure - maybe pages are locked + JCC 2(PC) + MOVL $-1, AX + MOVL AX, ret+24(FP) RET - + TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 MOVQ new+0(FP), DI MOVQ old+8(FP), SI diff --git a/src/runtime/sys_freebsd_386.s b/src/runtime/sys_freebsd_386.s index b8f685a32374a..754689ba0558b 100644 --- a/src/runtime/sys_freebsd_386.s +++ b/src/runtime/sys_freebsd_386.s @@ -163,7 +163,9 @@ TEXT runtime·munmap(SB),NOSPLIT,$-4 TEXT runtime·madvise(SB),NOSPLIT,$-4 MOVL $75, AX // madvise INT $0x80 - // ignore failure - maybe pages are locked + JAE 2(PC) + MOVL $-1, AX + MOVL AX, ret+12(FP) RET TEXT runtime·setitimer(SB), NOSPLIT, $-4 diff --git a/src/runtime/sys_freebsd_amd64.s b/src/runtime/sys_freebsd_amd64.s index be191a078458f..55959b3e3a333 100644 --- a/src/runtime/sys_freebsd_amd64.s +++ b/src/runtime/sys_freebsd_amd64.s @@ -337,9 +337,11 @@ TEXT runtime·madvise(SB),NOSPLIT,$0 MOVL flags+16(FP), DX MOVQ $75, AX // madvise SYSCALL - // ignore failure - maybe pages are locked + JCC 2(PC) + MOVL $-1, AX + MOVL AX, ret+24(FP) RET - + TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 MOVQ new+0(FP), DI MOVQ old+8(FP), SI diff --git a/src/runtime/sys_freebsd_arm.s b/src/runtime/sys_freebsd_arm.s index 93bf569367e92..f347b9fa961b9 100644 --- a/src/runtime/sys_freebsd_arm.s +++ b/src/runtime/sys_freebsd_arm.s @@ -264,14 +264,15 @@ TEXT runtime·munmap(SB),NOSPLIT,$0 RET TEXT runtime·madvise(SB),NOSPLIT,$0 - MOVW addr+0(FP), R0 // arg 1 addr - MOVW n+4(FP), R1 // arg 2 len - MOVW flags+8(FP), R2 // arg 3 flags - MOVW $SYS_madvise, R7 - SWI $0 - // ignore failure - maybe pages are locked + MOVW addr+0(FP), R0 // arg 1 addr + MOVW n+4(FP), R1 // arg 2 len + MOVW flags+8(FP), R2 // arg 3 flags + MOVW $SYS_madvise, R7 + SWI $0 + MOVW.CS $-1, R0 + MOVW R0, ret+12(FP) RET - + TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0 MOVW new+0(FP), R0 MOVW old+4(FP), R1 diff --git a/src/runtime/sys_linux_386.s b/src/runtime/sys_linux_386.s index 4e914f3e6013d..40b55a67eb879 100644 --- a/src/runtime/sys_linux_386.s +++ b/src/runtime/sys_linux_386.s @@ -427,7 +427,7 @@ TEXT runtime·madvise(SB),NOSPLIT,$0 MOVL n+4(FP), CX MOVL flags+8(FP), DX INVOKE_SYSCALL - // ignore failure - maybe pages are locked + MOVL AX, ret+12(FP) RET // int32 futex(int32 *uaddr, int32 op, int32 val, diff --git a/src/runtime/sys_linux_amd64.s b/src/runtime/sys_linux_amd64.s index 4492dad02e7a6..7e846371e5620 100644 --- a/src/runtime/sys_linux_amd64.s +++ b/src/runtime/sys_linux_amd64.s @@ -519,7 +519,7 @@ TEXT runtime·madvise(SB),NOSPLIT,$0 MOVL flags+16(FP), DX MOVQ $SYS_madvise, AX SYSCALL - // ignore failure - maybe pages are locked + MOVL AX, ret+24(FP) RET // int64 futex(int32 *uaddr, int32 op, int32 val, diff --git a/src/runtime/sys_linux_arm.s b/src/runtime/sys_linux_arm.s index a709c4cbd050b..43a58335c8068 100644 --- a/src/runtime/sys_linux_arm.s +++ b/src/runtime/sys_linux_arm.s @@ -195,7 +195,7 @@ TEXT runtime·madvise(SB),NOSPLIT,$0 MOVW flags+8(FP), R2 MOVW $SYS_madvise, R7 SWI $0 - // ignore failure - maybe pages are locked + MOVW R0, ret+12(FP) RET TEXT runtime·setitimer(SB),NOSPLIT,$0 diff --git a/src/runtime/sys_linux_arm64.s b/src/runtime/sys_linux_arm64.s index 086c8ddc637fe..8b344be8f83b9 100644 --- a/src/runtime/sys_linux_arm64.s +++ b/src/runtime/sys_linux_arm64.s @@ -401,7 +401,7 @@ TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0 MOVW flags+16(FP), R2 MOVD $SYS_madvise, R8 SVC - // ignore failure - maybe pages are locked + MOVW R0, ret+24(FP) RET // int64 futex(int32 *uaddr, int32 op, int32 val, diff --git a/src/runtime/sys_linux_mips64x.s b/src/runtime/sys_linux_mips64x.s index 337299ba5fe08..c45703d22801c 100644 --- a/src/runtime/sys_linux_mips64x.s +++ b/src/runtime/sys_linux_mips64x.s @@ -291,7 +291,7 @@ TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0 MOVW flags+16(FP), R6 MOVV $SYS_madvise, R2 SYSCALL - // ignore failure - maybe pages are locked + MOVW R2, ret+24(FP) RET // int64 futex(int32 *uaddr, int32 op, int32 val, diff --git a/src/runtime/sys_linux_mipsx.s b/src/runtime/sys_linux_mipsx.s index dca5f1ee459a8..f362b0f3f1c95 100644 --- a/src/runtime/sys_linux_mipsx.s +++ b/src/runtime/sys_linux_mipsx.s @@ -302,13 +302,13 @@ TEXT runtime·munmap(SB),NOSPLIT,$0-8 UNDEF // crash RET -TEXT runtime·madvise(SB),NOSPLIT,$0-12 +TEXT runtime·madvise(SB),NOSPLIT,$0-16 MOVW addr+0(FP), R4 MOVW n+4(FP), R5 MOVW flags+8(FP), R6 MOVW $SYS_madvise, R2 SYSCALL - // ignore failure - maybe pages are locked + MOVW R2, ret+12(FP) RET // int32 futex(int32 *uaddr, int32 op, int32 val, struct timespec *timeout, int32 *uaddr2, int32 val2); diff --git a/src/runtime/sys_linux_ppc64x.s b/src/runtime/sys_linux_ppc64x.s index 7c2f8ea637176..ed79b69257848 100644 --- a/src/runtime/sys_linux_ppc64x.s +++ b/src/runtime/sys_linux_ppc64x.s @@ -454,7 +454,7 @@ TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0 MOVD n+8(FP), R4 MOVW flags+16(FP), R5 SYSCALL $SYS_madvise - // ignore failure - maybe pages are locked + MOVW R3, ret+24(FP) RET // int64 futex(int32 *uaddr, int32 op, int32 val, diff --git a/src/runtime/sys_linux_s390x.s b/src/runtime/sys_linux_s390x.s index 95401af62ecc2..c79ceea7512f6 100644 --- a/src/runtime/sys_linux_s390x.s +++ b/src/runtime/sys_linux_s390x.s @@ -290,7 +290,7 @@ TEXT runtime·madvise(SB),NOSPLIT|NOFRAME,$0 MOVW flags+16(FP), R4 MOVW $SYS_madvise, R1 SYSCALL - // ignore failure - maybe pages are locked + MOVW R2, ret+24(FP) RET // int64 futex(int32 *uaddr, int32 op, int32 val, diff --git a/src/runtime/sys_netbsd_386.s b/src/runtime/sys_netbsd_386.s index 4042ab4f8abd8..66f4620cab59a 100644 --- a/src/runtime/sys_netbsd_386.s +++ b/src/runtime/sys_netbsd_386.s @@ -135,7 +135,9 @@ TEXT runtime·munmap(SB),NOSPLIT,$-4 TEXT runtime·madvise(SB),NOSPLIT,$-4 MOVL $75, AX // sys_madvise INT $0x80 - // ignore failure - maybe pages are locked + JAE 2(PC) + MOVL $-1, AX + MOVL AX, ret+12(FP) RET TEXT runtime·setitimer(SB),NOSPLIT,$-4 diff --git a/src/runtime/sys_netbsd_amd64.s b/src/runtime/sys_netbsd_amd64.s index 11b9c1b417375..55236591965cd 100644 --- a/src/runtime/sys_netbsd_amd64.s +++ b/src/runtime/sys_netbsd_amd64.s @@ -319,7 +319,9 @@ TEXT runtime·madvise(SB),NOSPLIT,$0 MOVL flags+16(FP), DX // arg 3 - behav MOVQ $75, AX // sys_madvise SYSCALL - // ignore failure - maybe pages are locked + JCC 2(PC) + MOVL $-1, AX + MOVL AX, ret+24(FP) RET TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 diff --git a/src/runtime/sys_netbsd_arm.s b/src/runtime/sys_netbsd_arm.s index 6b2c5a83572c2..304075f295e31 100644 --- a/src/runtime/sys_netbsd_arm.s +++ b/src/runtime/sys_netbsd_arm.s @@ -284,11 +284,12 @@ TEXT runtime·munmap(SB),NOSPLIT,$0 RET TEXT runtime·madvise(SB),NOSPLIT,$0 - MOVW addr+0(FP), R0 // arg 1 - addr - MOVW n+4(FP), R1 // arg 2 - len - MOVW flags+8(FP), R2 // arg 3 - behav - SWI $0xa0004b // sys_madvise - // ignore failure - maybe pages are locked + MOVW addr+0(FP), R0 // arg 1 - addr + MOVW n+4(FP), R1 // arg 2 - len + MOVW flags+8(FP), R2 // arg 3 - behav + SWI $0xa0004b // sys_madvise + MOVW.CS $-1, R0 + MOVW R0, ret+12(FP) RET TEXT runtime·sigaltstack(SB),NOSPLIT|NOFRAME,$0 diff --git a/src/runtime/sys_openbsd_386.s b/src/runtime/sys_openbsd_386.s index 21f13c806e635..8e34ab497afe1 100644 --- a/src/runtime/sys_openbsd_386.s +++ b/src/runtime/sys_openbsd_386.s @@ -136,7 +136,8 @@ TEXT runtime·madvise(SB),NOSPLIT,$-4 MOVL $75, AX // sys_madvise INT $0x80 JAE 2(PC) - MOVL $0xf1, 0xf1 // crash + MOVL $-1, AX + MOVL AX, ret+12(FP) RET TEXT runtime·setitimer(SB),NOSPLIT,$-4 diff --git a/src/runtime/sys_openbsd_amd64.s b/src/runtime/sys_openbsd_amd64.s index 38ac38d9bf182..227e81869c0f6 100644 --- a/src/runtime/sys_openbsd_amd64.s +++ b/src/runtime/sys_openbsd_amd64.s @@ -305,7 +305,9 @@ TEXT runtime·madvise(SB),NOSPLIT,$0 MOVL flags+16(FP), DX // arg 3 - behav MOVQ $75, AX // sys_madvise SYSCALL - // ignore failure - maybe pages are locked + JCC 2(PC) + MOVL $-1, AX + MOVL AX, ret+24(FP) RET TEXT runtime·sigaltstack(SB),NOSPLIT,$-8 diff --git a/src/runtime/sys_openbsd_arm.s b/src/runtime/sys_openbsd_arm.s index ff1c1da9b97ee..52d3638bc18c1 100644 --- a/src/runtime/sys_openbsd_arm.s +++ b/src/runtime/sys_openbsd_arm.s @@ -143,8 +143,8 @@ TEXT runtime·madvise(SB),NOSPLIT,$0 MOVW flags+8(FP), R2 // arg 2 - flags MOVW $75, R12 // sys_madvise SWI $0 - MOVW.CS $0, R8 // crash on syscall failure - MOVW.CS R8, (R8) + MOVW.CS $-1, R0 + MOVW R0, ret+12(FP) RET TEXT runtime·setitimer(SB),NOSPLIT,$0 From 83dfc3b001245f0b725afdc94c0b540fe1952d21 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 17 Sep 2018 12:25:36 -0700 Subject: [PATCH 0403/1663] runtime: ignore races between close and len/cap They aren't really races, or at least they don't have any observable effect. The spec is silent on whether these are actually races or not. Fix this problem by not using the address of len (or of cap) as the location where channel operations are recorded to occur. Use a random other field of hchan for that. I'm not 100% sure we should in fact fix this. Opinions welcome. Fixes #27070 Change-Id: Ib4efd4b62e0d1ef32fa51e373035ef207a655084 Reviewed-on: https://go-review.googlesource.com/135698 Reviewed-by: Dmitry Vyukov --- src/runtime/chan.go | 23 ++++++++++++++------ src/runtime/race/testdata/chan_test.go | 30 +++++++++++++++++++------- src/runtime/select.go | 4 ++-- 3 files changed, 40 insertions(+), 17 deletions(-) diff --git a/src/runtime/chan.go b/src/runtime/chan.go index 615643e6a60bd..a4ee51ca39d26 100644 --- a/src/runtime/chan.go +++ b/src/runtime/chan.go @@ -92,7 +92,7 @@ func makechan(t *chantype, size int) *hchan { // Queue or element size is zero. c = (*hchan)(mallocgc(hchanSize, nil, true)) // Race detector uses this location for synchronization. - c.buf = unsafe.Pointer(c) + c.buf = c.raceaddr() case elem.kind&kindNoPointers != 0: // Elements do not contain pointers. // Allocate hchan and buf in one call. @@ -151,7 +151,7 @@ func chansend(c *hchan, ep unsafe.Pointer, block bool, callerpc uintptr) bool { } if raceenabled { - racereadpc(unsafe.Pointer(c), callerpc, funcPC(chansend)) + racereadpc(c.raceaddr(), callerpc, funcPC(chansend)) } // Fast path: check for failed non-blocking operation without acquiring the lock. @@ -337,8 +337,8 @@ func closechan(c *hchan) { if raceenabled { callerpc := getcallerpc() - racewritepc(unsafe.Pointer(c), callerpc, funcPC(closechan)) - racerelease(unsafe.Pointer(c)) + racewritepc(c.raceaddr(), callerpc, funcPC(closechan)) + racerelease(c.raceaddr()) } c.closed = 1 @@ -361,7 +361,7 @@ func closechan(c *hchan) { gp := sg.g gp.param = nil if raceenabled { - raceacquireg(gp, unsafe.Pointer(c)) + raceacquireg(gp, c.raceaddr()) } glist.push(gp) } @@ -379,7 +379,7 @@ func closechan(c *hchan) { gp := sg.g gp.param = nil if raceenabled { - raceacquireg(gp, unsafe.Pointer(c)) + raceacquireg(gp, c.raceaddr()) } glist.push(gp) } @@ -454,7 +454,7 @@ func chanrecv(c *hchan, ep unsafe.Pointer, block bool) (selected, received bool) if c.closed != 0 && c.qcount == 0 { if raceenabled { - raceacquire(unsafe.Pointer(c)) + raceacquire(c.raceaddr()) } unlock(&c.lock) if ep != nil { @@ -732,6 +732,15 @@ func (q *waitq) dequeue() *sudog { } } +func (c *hchan) raceaddr() unsafe.Pointer { + // Treat read-like and write-like operations on the channel to + // happen at this address. Avoid using the address of qcount + // or dataqsiz, because the len() and cap() builtins read + // those addresses, and we don't want them racing with + // operations like close(). + return unsafe.Pointer(&c.buf) +} + func racesync(c *hchan, sg *sudog) { racerelease(chanbuf(c, 0)) raceacquireg(sg.g, chanbuf(c, 0)) diff --git a/src/runtime/race/testdata/chan_test.go b/src/runtime/race/testdata/chan_test.go index 7f349c42ed783..60e55ed66a4b0 100644 --- a/src/runtime/race/testdata/chan_test.go +++ b/src/runtime/race/testdata/chan_test.go @@ -577,18 +577,32 @@ func TestRaceChanItselfCap(t *testing.T) { <-compl } -func TestRaceChanCloseLen(t *testing.T) { - v := 0 - _ = v +func TestNoRaceChanCloseLen(t *testing.T) { c := make(chan int, 10) - c <- 0 + r := make(chan int, 10) + go func() { + r <- len(c) + }() go func() { - v = 1 close(c) + r <- 0 }() - time.Sleep(1e7) - _ = len(c) - v = 2 + <-r + <-r +} + +func TestNoRaceChanCloseCap(t *testing.T) { + c := make(chan int, 10) + r := make(chan int, 10) + go func() { + r <- cap(c) + }() + go func() { + close(c) + r <- 0 + }() + <-r + <-r } func TestRaceChanCloseSend(t *testing.T) { diff --git a/src/runtime/select.go b/src/runtime/select.go index 3a3ac6b7ac0bd..2729c2ecf98a2 100644 --- a/src/runtime/select.go +++ b/src/runtime/select.go @@ -245,7 +245,7 @@ loop: case caseSend: if raceenabled { - racereadpc(unsafe.Pointer(c), cas.pc, chansendpc) + racereadpc(c.raceaddr(), cas.pc, chansendpc) } if c.closed != 0 { goto sclose @@ -462,7 +462,7 @@ rclose: typedmemclr(c.elemtype, cas.elem) } if raceenabled { - raceacquire(unsafe.Pointer(c)) + raceacquire(c.raceaddr()) } goto retc From c6118af55864916c2c3b1bca8e216e627f232bf3 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 17 Sep 2018 14:46:07 -0700 Subject: [PATCH 0404/1663] cmd/compile: don't do floating point optimization x+0 -> x That optimization is not valid if x == -0. The test is a bit tricky because 0 == -0. We distinguish 0 from -0 with 1/0 == inf, 1/-0 == -inf. This has been a bug since CL 24790 in Go 1.8. Probably doesn't warrant a backport. Fixes #27718 Note: the optimization x-0 -> x is actually valid. But it's probably best to take it out, so as to not confuse readers. Change-Id: I99f16a93b45f7406ec8053c2dc759a13eba035fa Reviewed-on: https://go-review.googlesource.com/135701 Reviewed-by: Cherry Zhang --- .../compile/internal/ssa/gen/generic.rules | 3 - .../compile/internal/ssa/rewritegeneric.go | 108 ------------------ test/fixedbugs/issue27718.go | 72 ++++++++++++ 3 files changed, 72 insertions(+), 111 deletions(-) create mode 100644 test/fixedbugs/issue27718.go diff --git a/src/cmd/compile/internal/ssa/gen/generic.rules b/src/cmd/compile/internal/ssa/gen/generic.rules index e9677b15c7a57..2df29192a4173 100644 --- a/src/cmd/compile/internal/ssa/gen/generic.rules +++ b/src/cmd/compile/internal/ssa/gen/generic.rules @@ -1329,9 +1329,6 @@ (Mul8 (Const8 [c]) (Mul8 (Const8 [d]) x)) -> (Mul8 (Const8 [int64(int8(c*d))]) x) // floating point optimizations -(Add(32|64)F x (Const(32|64)F [0])) -> x -(Sub(32|64)F x (Const(32|64)F [0])) -> x - (Mul(32|64)F x (Const(32|64)F [auxFrom64F(1)])) -> x (Mul32F x (Const32F [auxFrom32F(-1)])) -> (Neg32F x) (Mul64F x (Const64F [auxFrom64F(-1)])) -> (Neg64F x) diff --git a/src/cmd/compile/internal/ssa/rewritegeneric.go b/src/cmd/compile/internal/ssa/rewritegeneric.go index 612d57529e0b3..422be65f9ae7a 100644 --- a/src/cmd/compile/internal/ssa/rewritegeneric.go +++ b/src/cmd/compile/internal/ssa/rewritegeneric.go @@ -2445,42 +2445,6 @@ func rewriteValuegeneric_OpAdd32F_0(v *Value) bool { v.AuxInt = auxFrom32F(auxTo32F(c) + auxTo32F(d)) return true } - // match: (Add32F x (Const32F [0])) - // cond: - // result: x - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpConst32F { - break - } - if v_1.AuxInt != 0 { - break - } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (Add32F (Const32F [0]) x) - // cond: - // result: x - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpConst32F { - break - } - if v_0.AuxInt != 0 { - break - } - x := v.Args[1] - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } return false } func rewriteValuegeneric_OpAdd64_0(v *Value) bool { @@ -3490,42 +3454,6 @@ func rewriteValuegeneric_OpAdd64F_0(v *Value) bool { v.AuxInt = auxFrom64F(auxTo64F(c) + auxTo64F(d)) return true } - // match: (Add64F x (Const64F [0])) - // cond: - // result: x - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpConst64F { - break - } - if v_1.AuxInt != 0 { - break - } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } - // match: (Add64F (Const64F [0]) x) - // cond: - // result: x - for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpConst64F { - break - } - if v_0.AuxInt != 0 { - break - } - x := v.Args[1] - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } return false } func rewriteValuegeneric_OpAdd8_0(v *Value) bool { @@ -29841,24 +29769,6 @@ func rewriteValuegeneric_OpSub32F_0(v *Value) bool { v.AuxInt = auxFrom32F(auxTo32F(c) - auxTo32F(d)) return true } - // match: (Sub32F x (Const32F [0])) - // cond: - // result: x - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpConst32F { - break - } - if v_1.AuxInt != 0 { - break - } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } return false } func rewriteValuegeneric_OpSub64_0(v *Value) bool { @@ -30265,24 +30175,6 @@ func rewriteValuegeneric_OpSub64F_0(v *Value) bool { v.AuxInt = auxFrom64F(auxTo64F(c) - auxTo64F(d)) return true } - // match: (Sub64F x (Const64F [0])) - // cond: - // result: x - for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpConst64F { - break - } - if v_1.AuxInt != 0 { - break - } - v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) - return true - } return false } func rewriteValuegeneric_OpSub8_0(v *Value) bool { diff --git a/test/fixedbugs/issue27718.go b/test/fixedbugs/issue27718.go new file mode 100644 index 0000000000000..f7794182f588d --- /dev/null +++ b/test/fixedbugs/issue27718.go @@ -0,0 +1,72 @@ +// run + +// Copyright 2018 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. + +// (-0)+0 should be 0, not -0. + +package main + +//go:noinline +func add64(x float64) float64 { + return x + 0 +} + +func testAdd64() { + var zero float64 + inf := 1.0 / zero + negZero := -1 / inf + if 1/add64(negZero) != inf { + panic("negZero+0 != posZero (64 bit)") + } +} + +//go:noinline +func sub64(x float64) float64 { + return x - 0 +} + +func testSub64() { + var zero float64 + inf := 1.0 / zero + negZero := -1 / inf + if 1/sub64(negZero) != -inf { + panic("negZero-0 != negZero (64 bit)") + } +} + +//go:noinline +func add32(x float32) float32 { + return x + 0 +} + +func testAdd32() { + var zero float32 + inf := 1.0 / zero + negZero := -1 / inf + if 1/add32(negZero) != inf { + panic("negZero+0 != posZero (32 bit)") + } +} + +//go:noinline +func sub32(x float32) float32 { + return x - 0 +} + +func testSub32() { + var zero float32 + inf := 1.0 / zero + negZero := -1 / inf + if 1/sub32(negZero) != -inf { + panic("negZero-0 != negZero (32 bit)") + } +} + +func main() { + testAdd64() + testSub64() + testAdd32() + testSub32() +} From 37db664c6cd480b578d6114854bc20c2bc3cddcd Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Mon, 17 Sep 2018 14:25:06 +1000 Subject: [PATCH 0405/1663] builtin: document when len and cap are constant The rules are subtle, but under some circumstances the result can be constant. Mention this and refer to the appropriate section of the specification. Fixes #27588. Change-Id: I4beaad036db87501378fb2ef48d216742d096933 Reviewed-on: https://go-review.googlesource.com/135519 Reviewed-by: Robert Griesemer --- src/builtin/builtin.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/builtin/builtin.go b/src/builtin/builtin.go index 4578c855a9e57..c78fe09ea6602 100644 --- a/src/builtin/builtin.go +++ b/src/builtin/builtin.go @@ -152,6 +152,9 @@ func delete(m map[Type]Type1, key Type) // String: the number of bytes in v. // Channel: the number of elements queued (unread) in the channel buffer; // if v is nil, len(v) is zero. +// For some arguments, such as a string literal or a simple array expression, the +// result can be a constant. See the Go language specification's "Length and +// capacity" section for details. func len(v Type) int // The cap built-in function returns the capacity of v, according to its type: @@ -161,6 +164,9 @@ func len(v Type) int // if v is nil, cap(v) is zero. // Channel: the channel buffer capacity, in units of elements; // if v is nil, cap(v) is zero. +// For some arguments, such as a simple array expression, the result can be a +// constant. See the Go language specification's "Length and capacity" section for +// details. func cap(v Type) int // The make built-in function allocates and initializes an object of type From d24ec86e4f64302e91d8062eabfcd21296bb9b04 Mon Sep 17 00:00:00 2001 From: Jordan Rhee Date: Wed, 8 Aug 2018 14:44:42 -0700 Subject: [PATCH 0406/1663] runtime: support windows/arm Updates #26148 Change-Id: I8f68b2c926c7b11dc86c9664ed7ff2d2f78b64b4 Reviewed-on: https://go-review.googlesource.com/128715 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/vet/all/whitelist/windows_386.txt | 1 - src/cmd/vet/all/whitelist/windows_amd64.txt | 1 - src/runtime/asm_arm.s | 4 + src/runtime/defs_windows_386.go | 3 + src/runtime/defs_windows_amd64.go | 3 + src/runtime/defs_windows_arm.go | 149 + src/runtime/os_windows.go | 30 +- src/runtime/os_windows_arm.go | 18 + src/runtime/rt0_windows_arm.s | 12 + src/runtime/signal_windows.go | 10 +- src/runtime/sys_windows_arm.s | 605 +++ src/runtime/syscall_windows.go | 24 +- src/runtime/tls_arm.s | 43 +- src/runtime/wincallback.go | 42 +- src/runtime/zcallback_windows.go | 2 +- src/runtime/zcallback_windows.s | 4 +- src/runtime/zcallback_windows_arm.s | 4012 +++++++++++++++++++ 17 files changed, 4942 insertions(+), 21 deletions(-) create mode 100644 src/runtime/defs_windows_arm.go create mode 100644 src/runtime/os_windows_arm.go create mode 100644 src/runtime/rt0_windows_arm.s create mode 100644 src/runtime/sys_windows_arm.s create mode 100644 src/runtime/zcallback_windows_arm.s diff --git a/src/cmd/vet/all/whitelist/windows_386.txt b/src/cmd/vet/all/whitelist/windows_386.txt index 788684a49d95b..d910022ef655e 100644 --- a/src/cmd/vet/all/whitelist/windows_386.txt +++ b/src/cmd/vet/all/whitelist/windows_386.txt @@ -3,7 +3,6 @@ runtime/sys_windows_386.s: [386] profileloop: use of 4(SP) points beyond argument frame runtime/sys_windows_386.s: [386] ctrlhandler: 4(SP) should be _type+0(FP) runtime/sys_windows_386.s: [386] setldt: function setldt missing Go declaration -runtime/zcallback_windows.s: [386] callbackasm: function callbackasm missing Go declaration runtime/sys_windows_386.s: [386] callbackasm1+0: function callbackasm1+0 missing Go declaration runtime/sys_windows_386.s: [386] tstart: function tstart missing Go declaration runtime/sys_windows_386.s: [386] tstart_stdcall: RET without writing to 4-byte ret+4(FP) diff --git a/src/cmd/vet/all/whitelist/windows_amd64.txt b/src/cmd/vet/all/whitelist/windows_amd64.txt index 3be4602579eb7..676e6baf71b79 100644 --- a/src/cmd/vet/all/whitelist/windows_amd64.txt +++ b/src/cmd/vet/all/whitelist/windows_amd64.txt @@ -6,4 +6,3 @@ runtime/sys_windows_amd64.s: [amd64] callbackasm1: function callbackasm1 missing runtime/sys_windows_amd64.s: [amd64] tstart_stdcall: RET without writing to 4-byte ret+8(FP) runtime/sys_windows_amd64.s: [amd64] settls: function settls missing Go declaration runtime/sys_windows_amd64.s: [amd64] cannot check cross-package assembly function: now is in package time -runtime/zcallback_windows.s: [amd64] callbackasm: function callbackasm missing Go declaration diff --git a/src/runtime/asm_arm.s b/src/runtime/asm_arm.s index 6722ba760fb54..ace2b6def7055 100644 --- a/src/runtime/asm_arm.s +++ b/src/runtime/asm_arm.s @@ -784,6 +784,9 @@ TEXT setg<>(SB),NOSPLIT|NOFRAME,$0-0 MOVW R0, g // Save g to thread-local storage. +#ifdef GOOS_windows + B runtime·save_g(SB) +#else MOVB runtime·iscgo(SB), R0 CMP $0, R0 B.EQ 2(PC) @@ -791,6 +794,7 @@ TEXT setg<>(SB),NOSPLIT|NOFRAME,$0-0 MOVW g, R0 RET +#endif TEXT runtime·emptyfunc(SB),0,$0-0 RET diff --git a/src/runtime/defs_windows_386.go b/src/runtime/defs_windows_386.go index 589a7884cdaec..38b30b70e3409 100644 --- a/src/runtime/defs_windows_386.go +++ b/src/runtime/defs_windows_386.go @@ -104,6 +104,9 @@ type context struct { func (c *context) ip() uintptr { return uintptr(c.eip) } func (c *context) sp() uintptr { return uintptr(c.esp) } +// 386 does not have link register, so this returns 0. +func (c *context) lr() uintptr { return 0 } + func (c *context) setip(x uintptr) { c.eip = uint32(x) } func (c *context) setsp(x uintptr) { c.esp = uint32(x) } diff --git a/src/runtime/defs_windows_amd64.go b/src/runtime/defs_windows_amd64.go index 1e173e934d67d..37508c09becdc 100644 --- a/src/runtime/defs_windows_amd64.go +++ b/src/runtime/defs_windows_amd64.go @@ -119,6 +119,9 @@ type context struct { func (c *context) ip() uintptr { return uintptr(c.rip) } func (c *context) sp() uintptr { return uintptr(c.rsp) } +// Amd64 does not have link register, so this returns 0. +func (c *context) lr() uintptr { return 0 } + func (c *context) setip(x uintptr) { c.rip = uint64(x) } func (c *context) setsp(x uintptr) { c.rsp = uint64(x) } diff --git a/src/runtime/defs_windows_arm.go b/src/runtime/defs_windows_arm.go new file mode 100644 index 0000000000000..1140f61651f38 --- /dev/null +++ b/src/runtime/defs_windows_arm.go @@ -0,0 +1,149 @@ +// Copyright 2018 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. + +package runtime + +const ( + _PROT_NONE = 0 + _PROT_READ = 1 + _PROT_WRITE = 2 + _PROT_EXEC = 4 + + _MAP_ANON = 1 + _MAP_PRIVATE = 2 + + _DUPLICATE_SAME_ACCESS = 0x2 + _THREAD_PRIORITY_HIGHEST = 0x2 + + _SIGINT = 0x2 + _CTRL_C_EVENT = 0x0 + _CTRL_BREAK_EVENT = 0x1 + + _CONTEXT_CONTROL = 0x10001 + _CONTEXT_FULL = 0x10007 + + _EXCEPTION_ACCESS_VIOLATION = 0xc0000005 + _EXCEPTION_BREAKPOINT = 0x80000003 + _EXCEPTION_FLT_DENORMAL_OPERAND = 0xc000008d + _EXCEPTION_FLT_DIVIDE_BY_ZERO = 0xc000008e + _EXCEPTION_FLT_INEXACT_RESULT = 0xc000008f + _EXCEPTION_FLT_OVERFLOW = 0xc0000091 + _EXCEPTION_FLT_UNDERFLOW = 0xc0000093 + _EXCEPTION_INT_DIVIDE_BY_ZERO = 0xc0000094 + _EXCEPTION_INT_OVERFLOW = 0xc0000095 + + _INFINITE = 0xffffffff + _WAIT_TIMEOUT = 0x102 + + _EXCEPTION_CONTINUE_EXECUTION = -0x1 + _EXCEPTION_CONTINUE_SEARCH = 0x0 +) + +type systeminfo struct { + anon0 [4]byte + dwpagesize uint32 + lpminimumapplicationaddress *byte + lpmaximumapplicationaddress *byte + dwactiveprocessormask uint32 + dwnumberofprocessors uint32 + dwprocessortype uint32 + dwallocationgranularity uint32 + wprocessorlevel uint16 + wprocessorrevision uint16 +} + +type exceptionrecord struct { + exceptioncode uint32 + exceptionflags uint32 + exceptionrecord *exceptionrecord + exceptionaddress *byte + numberparameters uint32 + exceptioninformation [15]uint32 +} + +type neon128 struct { + low uint64 + high int64 +} + +type context struct { + contextflags uint32 + r0 uint32 + r1 uint32 + r2 uint32 + r3 uint32 + r4 uint32 + r5 uint32 + r6 uint32 + r7 uint32 + r8 uint32 + r9 uint32 + r10 uint32 + r11 uint32 + r12 uint32 + + spr uint32 + lrr uint32 + pc uint32 + cpsr uint32 + + fpscr uint32 + padding uint32 + + floatNeon [16]neon128 + + bvr [8]uint32 + bcr [8]uint32 + wvr [1]uint32 + wcr [1]uint32 + padding2 [2]uint32 +} + +func (c *context) ip() uintptr { return uintptr(c.pc) } +func (c *context) sp() uintptr { return uintptr(c.spr) } +func (c *context) lr() uintptr { return uintptr(c.lrr) } + +func (c *context) setip(x uintptr) { c.pc = uint32(x) } +func (c *context) setsp(x uintptr) { c.spr = uint32(x) } + +func dumpregs(r *context) { + print("r0 ", hex(r.r0), "\n") + print("r1 ", hex(r.r1), "\n") + print("r2 ", hex(r.r2), "\n") + print("r3 ", hex(r.r3), "\n") + print("r4 ", hex(r.r4), "\n") + print("r5 ", hex(r.r5), "\n") + print("r6 ", hex(r.r6), "\n") + print("r7 ", hex(r.r7), "\n") + print("r8 ", hex(r.r8), "\n") + print("r9 ", hex(r.r9), "\n") + print("r10 ", hex(r.r10), "\n") + print("r11 ", hex(r.r11), "\n") + print("r12 ", hex(r.r12), "\n") + print("sp ", hex(r.spr), "\n") + print("lr ", hex(r.lrr), "\n") + print("pc ", hex(r.pc), "\n") + print("cpsr ", hex(r.cpsr), "\n") +} + +type overlapped struct { + internal uint32 + internalhigh uint32 + anon0 [8]byte + hevent *byte +} + +type memoryBasicInformation struct { + baseAddress uintptr + allocationBase uintptr + allocationProtect uint32 + regionSize uintptr + state uint32 + protect uint32 + type_ uint32 +} + +func stackcheck() { + // TODO: not implemented on ARM +} diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go index 5607bf95c1d59..409d537839471 100644 --- a/src/runtime/os_windows.go +++ b/src/runtime/os_windows.go @@ -43,6 +43,7 @@ const ( //go:cgo_import_dynamic runtime._SetWaitableTimer SetWaitableTimer%6 "kernel32.dll" //go:cgo_import_dynamic runtime._SuspendThread SuspendThread%1 "kernel32.dll" //go:cgo_import_dynamic runtime._SwitchToThread SwitchToThread%0 "kernel32.dll" +//go:cgo_import_dynamic runtime._TlsAlloc TlsAlloc%0 "kernel32.dll" //go:cgo_import_dynamic runtime._VirtualAlloc VirtualAlloc%4 "kernel32.dll" //go:cgo_import_dynamic runtime._VirtualFree VirtualFree%3 "kernel32.dll" //go:cgo_import_dynamic runtime._VirtualQuery VirtualQuery%3 "kernel32.dll" @@ -91,6 +92,7 @@ var ( _SetWaitableTimer, _SuspendThread, _SwitchToThread, + _TlsAlloc, _VirtualAlloc, _VirtualFree, _VirtualQuery, @@ -860,14 +862,34 @@ func profilem(mp *m) { var r *context rbuf := make([]byte, unsafe.Sizeof(*r)+15) - tls := &mp.tls[0] - gp := *((**g)(unsafe.Pointer(tls))) - // align Context to 16 bytes r = (*context)(unsafe.Pointer((uintptr(unsafe.Pointer(&rbuf[15]))) &^ 15)) r.contextflags = _CONTEXT_CONTROL stdcall2(_GetThreadContext, mp.thread, uintptr(unsafe.Pointer(r))) - sigprof(r.ip(), r.sp(), 0, gp, mp) + + var gp *g + switch GOARCH { + default: + panic("unsupported architecture") + case "arm": + // TODO(jordanrh1): this is incorrect when Go is executing + // on the system or signal stacks because curg returns + // the current user g. The true g is stored in thread + // local storage, which we cannot access from another CPU. + // We cannot pull R10 from the thread context because + // it might be executing C code, in which case R10 + // would not be g. + gp = mp.curg + case "386", "amd64": + tls := &mp.tls[0] + gp = *((**g)(unsafe.Pointer(tls))) + } + + if gp == nil { + sigprofNonGoPC(r.ip()) + } else { + sigprof(r.ip(), r.sp(), 0, gp, mp) + } } func profileloop1(param uintptr) uint32 { diff --git a/src/runtime/os_windows_arm.go b/src/runtime/os_windows_arm.go new file mode 100644 index 0000000000000..3115f7241dbeb --- /dev/null +++ b/src/runtime/os_windows_arm.go @@ -0,0 +1,18 @@ +// Copyright 2018 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. + +package runtime + +//go:nosplit +func cputicks() int64 { + return nanotime() +} + +func checkgoarm() { + if goarm < 7 { + print("Need atomic synchronization instructions, coprocessor ", + "access instructions. Recompile using GOARM=7.\n") + exit(1) + } +} diff --git a/src/runtime/rt0_windows_arm.s b/src/runtime/rt0_windows_arm.s new file mode 100644 index 0000000000000..c5787d0dee003 --- /dev/null +++ b/src/runtime/rt0_windows_arm.s @@ -0,0 +1,12 @@ +// Copyright 2018 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 "go_asm.h" +#include "go_tls.h" +#include "textflag.h" + +// This is the entry point for the program from the +// kernel for an ordinary -buildmode=exe program. +TEXT _rt0_arm_windows(SB),NOSPLIT|NOFRAME,$0 + B ·rt0_go(SB) diff --git a/src/runtime/signal_windows.go b/src/runtime/signal_windows.go index a63450038d818..873ce66abedde 100644 --- a/src/runtime/signal_windows.go +++ b/src/runtime/signal_windows.go @@ -27,7 +27,7 @@ func lastcontinuetramp() func initExceptionHandler() { stdcall2(_AddVectoredExceptionHandler, 1, funcPC(exceptiontramp)) - if _AddVectoredContinueHandler == nil || unsafe.Sizeof(&_AddVectoredContinueHandler) == 4 { + if _AddVectoredContinueHandler == nil || GOARCH == "386" { // use SetUnhandledExceptionFilter for windows-386 or // if VectoredContinueHandler is unavailable. // note: SetUnhandledExceptionFilter handler won't be called, if debugging. @@ -177,9 +177,15 @@ func lastcontinuehandler(info *exceptionrecord, r *context, gp *g) int32 { } print("\n") + // TODO(jordanrh1): This may be needed for 386/AMD64 as well. + if GOARCH == "arm" { + _g_.m.throwing = 1 + _g_.m.caughtsig.set(gp) + } + level, _, docrash := gotraceback() if level > 0 { - tracebacktrap(r.ip(), r.sp(), 0, gp) + tracebacktrap(r.ip(), r.sp(), r.lr(), gp) tracebackothers(gp) dumpregs(r) } diff --git a/src/runtime/sys_windows_arm.s b/src/runtime/sys_windows_arm.s new file mode 100644 index 0000000000000..409c72c5543eb --- /dev/null +++ b/src/runtime/sys_windows_arm.s @@ -0,0 +1,605 @@ +// Copyright 2018 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 "go_asm.h" +#include "go_tls.h" +#include "textflag.h" + +// void runtime·asmstdcall(void *c); +TEXT runtime·asmstdcall(SB),NOSPLIT|NOFRAME,$0 + MOVM.DB.W [R4, R5, R14], (R13) // push {r4, r5, lr} + MOVW R0, R4 // put libcall * in r4 + MOVW R13, R5 // save stack pointer in r5 + + // SetLastError(0) + MOVW $0, R0 + MRC 15, 0, R1, C13, C0, 2 + MOVW R0, 0x34(R1) + + MOVW 8(R4), R12 // libcall->args + + // Do we have more than 4 arguments? + MOVW 4(R4), R0 // libcall->n + SUB.S $4, R0, R2 + BLE loadregs + + // Reserve stack space for remaining args + SUB R2<<2, R13 + BIC $0x7, R13 // alignment for ABI + + // R0: count of arguments + // R1: + // R2: loop counter, from 0 to (n-4) + // R3: scratch + // R4: pointer to libcall struct + // R12: libcall->args + MOVW $0, R2 +stackargs: + ADD $4, R2, R3 // r3 = args[4 + i] + MOVW R3<<2(R12), R3 + MOVW R3, R2<<2(R13) // stack[i] = r3 + + ADD $1, R2 // i++ + SUB $4, R0, R3 // while (i < (n - 4)) + CMP R3, R2 + BLT stackargs + +loadregs: + CMP $3, R0 + MOVW.GT 12(R12), R3 + + CMP $2, R0 + MOVW.GT 8(R12), R2 + + CMP $1, R0 + MOVW.GT 4(R12), R1 + + CMP $0, R0 + MOVW.GT 0(R12), R0 + + BIC $0x7, R13 // alignment for ABI + MOVW 0(R4), R12 // branch to libcall->fn + BL (R12) + + MOVW R5, R13 // free stack space + MOVW R0, 12(R4) // save return value to libcall->r1 + MOVW R1, 16(R4) + + // GetLastError + MRC 15, 0, R1, C13, C0, 2 + MOVW 0x34(R1), R0 + MOVW R0, 20(R4) // store in libcall->err + + MOVM.IA.W (R13), [R4, R5, R15] + +TEXT runtime·badsignal2(SB),NOSPLIT|NOFRAME,$0 + MOVM.DB.W [R4, R14], (R13) // push {r4, lr} + MOVW R13, R4 // save original stack pointer + SUB $8, R13 // space for 2 variables + BIC $0x7, R13 // alignment for ABI + + // stderr + MOVW runtime·_GetStdHandle(SB), R1 + MOVW $-12, R0 + BL (R1) + + MOVW $runtime·badsignalmsg(SB), R1 // lpBuffer + MOVW $runtime·badsignallen(SB), R2 // lpNumberOfBytesToWrite + MOVW (R2), R2 + ADD $0x4, R13, R3 // lpNumberOfBytesWritten + MOVW $0, R12 // lpOverlapped + MOVW R12, (R13) + + MOVW runtime·_WriteFile(SB), R12 + BL (R12) + + MOVW R4, R13 // restore SP + MOVM.IA.W (R13), [R4, R15] // pop {r4, pc} + +TEXT runtime·getlasterror(SB),NOSPLIT,$0 + MRC 15, 0, R0, C13, C0, 2 + MOVW 0x34(R0), R0 + MOVW R0, ret+0(FP) + RET + +TEXT runtime·setlasterror(SB),NOSPLIT|NOFRAME,$0 + MRC 15, 0, R1, C13, C0, 2 + MOVW R0, 0x34(R1) + RET + +// Called by Windows as a Vectored Exception Handler (VEH). +// First argument is pointer to struct containing +// exception record and context pointers. +// Handler function is stored in R1 +// Return 0 for 'not handled', -1 for handled. +// int32_t sigtramp( +// PEXCEPTION_POINTERS ExceptionInfo, +// func *GoExceptionHandler); +TEXT runtime·sigtramp(SB),NOSPLIT|NOFRAME,$0 + MOVM.DB.W [R0, R4-R11, R14], (R13) // push {r0, r4-r11, lr} (SP-=40) + SUB $(8+20), R13 // reserve space for g, sp, and + // parameters/retval to go call + + MOVW R0, R6 // Save param0 + MOVW R1, R7 // Save param1 + + BL runtime·load_g(SB) + CMP $0, g // is there a current g? + BL.EQ runtime·badsignal2(SB) + + // save g and SP in case of stack switch + MOVW R13, 24(R13) + MOVW g, 20(R13) + + // do we need to switch to the g0 stack? + MOVW g, R5 // R5 = g + MOVW g_m(R5), R2 // R2 = m + MOVW m_g0(R2), R4 // R4 = g0 + CMP R5, R4 // if curg == g0 + BEQ g0 + + // switch to g0 stack + MOVW R4, g // g = g0 + MOVW (g_sched+gobuf_sp)(g), R3 // R3 = g->gobuf.sp + BL runtime·save_g(SB) + + // traceback will think that we've done PUSH and SUB + // on this stack, so subtract them here to match. + // (we need room for sighandler arguments anyway). + // and re-save old SP for restoring later. + SUB $(40+8+20), R3 + MOVW R13, 24(R3) // save old stack pointer + MOVW R3, R13 // switch stack + +g0: + MOVW 0(R6), R2 // R2 = ExceptionPointers->ExceptionRecord + MOVW 4(R6), R3 // R3 = ExceptionPointers->ContextRecord + + // make it look like mstart called us on g0, to stop traceback + MOVW $runtime·mstart(SB), R4 + + MOVW R4, 0(R13) // Save link register for traceback + MOVW R2, 4(R13) // Move arg0 (ExceptionRecord) into position + MOVW R3, 8(R13) // Move arg1 (ContextRecord) into position + MOVW R5, 12(R13) // Move arg2 (original g) into position + BL (R7) // Call the go routine + MOVW 16(R13), R4 // Fetch return value from stack + + // Compute the value of the g0 stack pointer after deallocating + // this frame, then allocating 8 bytes. We may need to store + // the resume SP and PC on the g0 stack to work around + // control flow guard when we resume from the exception. + ADD $(40+20), R13, R12 + + // switch back to original stack and g + MOVW 24(R13), R13 + MOVW 20(R13), g + BL runtime·save_g(SB) + +done: + MOVW R4, R0 // move retval into position + ADD $(8 + 20), R13 // free locals + MOVM.IA.W (R13), [R3, R4-R11, R14] // pop {r3, r4-r11, lr} + + // if return value is CONTINUE_SEARCH, do not set up control + // flow guard workaround + CMP $0, R0 + BEQ return + + // Check if we need to set up the control flow guard workaround. + // On Windows/ARM, the stack pointer must lie within system + // stack limits when we resume from exception. + // Store the resume SP and PC on the g0 stack, + // and return to returntramp on the g0 stack. returntramp + // pops the saved PC and SP from the g0 stack, resuming execution + // at the desired location. + // If returntramp has already been set up by a previous exception + // handler, don't clobber the stored SP and PC on the stack. + MOVW 4(R3), R3 // PEXCEPTION_POINTERS->Context + MOVW 0x40(R3), R2 // load PC from context record + MOVW $runtime·returntramp(SB), R1 + CMP R1, R2 + B.EQ return // do not clobber saved SP/PC + + // Save resume SP and PC on g0 stack + MOVW 0x38(R3), R2 // load SP from context record + MOVW R2, 0(R12) // Store resume SP on g0 stack + MOVW 0x40(R3), R2 // load PC from context record + MOVW R2, 4(R12) // Store resume PC on g0 stack + + // Set up context record to return to returntramp on g0 stack + MOVW R12, 0x38(R3) // save g0 stack pointer + // in context record + MOVW $runtime·returntramp(SB), R2 // save resume address + MOVW R2, 0x40(R3) // in context record + +return: + B (R14) // return + +// +// Trampoline to resume execution from exception handler. +// This is part of the control flow guard workaround. +// It switches stacks and jumps to the continuation address. +// +TEXT runtime·returntramp(SB),NOSPLIT|NOFRAME,$0 + MOVM.IA (R13), [R13, R15] // ldm sp, [sp, pc] + +TEXT runtime·exceptiontramp(SB),NOSPLIT|NOFRAME,$0 + MOVW $runtime·exceptionhandler(SB), R1 + B runtime·sigtramp(SB) + +TEXT runtime·firstcontinuetramp(SB),NOSPLIT|NOFRAME,$0 + MOVW $runtime·firstcontinuehandler(SB), R1 + B runtime·sigtramp(SB) + +TEXT runtime·lastcontinuetramp(SB),NOSPLIT|NOFRAME,$0 + MOVW $runtime·lastcontinuehandler(SB), R1 + B runtime·sigtramp(SB) + +TEXT runtime·ctrlhandler(SB),NOSPLIT|NOFRAME,$0 + MOVW $runtime·ctrlhandler1(SB), R1 + B runtime·externalthreadhandler(SB) + +TEXT runtime·profileloop(SB),NOSPLIT|NOFRAME,$0 + MOVW $runtime·profileloop1(SB), R1 + B runtime·externalthreadhandler(SB) + +// int32 externalthreadhandler(uint32 arg, int (*func)(uint32)) +// stack layout: +// +----------------+ +// | callee-save | +// | registers | +// +----------------+ +// | m | +// +----------------+ +// 20| g | +// +----------------+ +// 16| func ptr (r1) | +// +----------------+ +// 12| argument (r0) | +//---+----------------+ +// 8 | param1 | +// +----------------+ +// 4 | param0 | +// +----------------+ +// 0 | retval | +// +----------------+ +// +TEXT runtime·externalthreadhandler(SB),NOSPLIT|NOFRAME,$0 + MOVM.DB.W [R4-R11, R14], (R13) // push {r4-r11, lr} + SUB $(m__size + g__size + 20), R13 // space for locals + MOVW R0, 12(R13) + MOVW R1, 16(R13) + + // zero out m and g structures + ADD $20, R13, R0 // compute pointer to g + MOVW R0, 4(R13) + MOVW $(m__size + g__size), R0 + MOVW R0, 8(R13) + BL runtime·memclrNoHeapPointers(SB) + + // initialize m and g structures + ADD $20, R13, R2 // R2 = g + ADD $(20 + g__size), R13, R3 // R3 = m + MOVW R2, m_g0(R3) // m->g0 = g + MOVW R3, g_m(R2) // g->m = m + MOVW R2, m_curg(R3) // m->curg = g + + MOVW R2, g + BL runtime·save_g(SB) + + // set up stackguard stuff + MOVW R13, R0 + MOVW R0, g_stack+stack_hi(g) + SUB $(32*1024), R0 + MOVW R0, (g_stack+stack_lo)(g) + MOVW R0, g_stackguard0(g) + MOVW R0, g_stackguard1(g) + + // move argument into position and call function + MOVW 12(R13), R0 + MOVW R0, 4(R13) + MOVW 16(R13), R1 + BL (R1) + + // clear g + MOVW $0, g + BL runtime·save_g(SB) + + MOVW 0(R13), R0 // load return value + ADD $(m__size + g__size + 20), R13 // free locals + MOVM.IA.W (R13), [R4-R11, R15] // pop {r4-r11, pc} + +GLOBL runtime·cbctxts(SB), NOPTR, $4 + +TEXT runtime·callbackasm1(SB),NOSPLIT|NOFRAME,$0 + MOVM.DB.W [R4-R11, R14], (R13) // push {r4-r11, lr} + SUB $36, R13 // space for locals + + // save callback arguments to stack. We currently support up to 4 arguments + ADD $16, R13, R4 + MOVM.IA [R0-R3], (R4) + + // load cbctxts[i]. The trampoline in zcallback_windows.s puts the callback + // index in R12 + MOVW runtime·cbctxts(SB), R4 + MOVW R12<<2(R4), R4 // R4 holds pointer to wincallbackcontext structure + + // extract callback context + MOVW wincallbackcontext_argsize(R4), R5 + MOVW wincallbackcontext_gobody(R4), R4 + + // we currently support up to 4 arguments + CMP $(4 * 4), R5 + BL.GT runtime·abort(SB) + + // extend argsize by size of return value + ADD $4, R5 + + // Build 'type args struct' + MOVW R4, 4(R13) // fn + ADD $16, R13, R0 // arg (points to r0-r3, ret on stack) + MOVW R0, 8(R13) + MOVW R5, 12(R13) // argsize + + BL runtime·load_g(SB) + BL runtime·cgocallback_gofunc(SB) + + ADD $16, R13, R0 // load arg + MOVW 12(R13), R1 // load argsize + SUB $4, R1 // offset to return value + MOVW R1<<0(R0), R0 // load return value + + ADD $36, R13 // free locals + MOVM.IA.W (R13), [R4-R11, R15] // pop {r4-r11, pc} + +// uint32 tstart_stdcall(M *newm); +TEXT runtime·tstart_stdcall(SB),NOSPLIT|NOFRAME,$0 + MOVM.DB.W [R4-R11, R14], (R13) // push {r4-r11, lr} + + MOVW m_g0(R0), g + MOVW R0, g_m(g) + BL runtime·save_g(SB) + + // Layout new m scheduler stack on os stack. + MOVW R13, R0 + MOVW R0, g_stack+stack_hi(g) + SUB $(64*1024), R0 + MOVW R0, (g_stack+stack_lo)(g) + MOVW R0, g_stackguard0(g) + MOVW R0, g_stackguard1(g) + + BL runtime·emptyfunc(SB) // fault if stack check is wrong + BL runtime·mstart(SB) + + // Exit the thread. + MOVW $0, R0 + MOVM.IA.W (R13), [R4-R11, R15] // pop {r4-r11, pc} + +// onosstack calls fn on OS stack. +// adapted from asm_arm.s : systemstack +// func onosstack(fn unsafe.Pointer, arg uint32) +TEXT runtime·onosstack(SB),NOSPLIT,$0 + MOVW fn+0(FP), R5 // R5 = fn + MOVW arg+4(FP), R6 // R6 = arg + + // This function can be called when there is no g, + // for example, when we are handling a callback on a non-go thread. + // In this case we're already on the system stack. + CMP $0, g + BEQ noswitch + + MOVW g_m(g), R1 // R1 = m + + MOVW m_gsignal(R1), R2 // R2 = gsignal + CMP g, R2 + B.EQ noswitch + + MOVW m_g0(R1), R2 // R2 = g0 + CMP g, R2 + B.EQ noswitch + + MOVW m_curg(R1), R3 + CMP g, R3 + B.EQ switch + + // Bad: g is not gsignal, not g0, not curg. What is it? + // Hide call from linker nosplit analysis. + MOVW $runtime·badsystemstack(SB), R0 + BL (R0) + B runtime·abort(SB) + +switch: + // save our state in g->sched. Pretend to + // be systemstack_switch if the G stack is scanned. + MOVW $runtime·systemstack_switch(SB), R3 + ADD $4, R3, R3 // get past push {lr} + MOVW R3, (g_sched+gobuf_pc)(g) + MOVW R13, (g_sched+gobuf_sp)(g) + MOVW LR, (g_sched+gobuf_lr)(g) + MOVW g, (g_sched+gobuf_g)(g) + + // switch to g0 + MOVW R2, g + MOVW (g_sched+gobuf_sp)(R2), R3 + // make it look like mstart called systemstack on g0, to stop traceback + SUB $4, R3, R3 + MOVW $runtime·mstart(SB), R4 + MOVW R4, 0(R3) + MOVW R3, R13 + + // call target function + MOVW R6, R0 // arg + BL (R5) + + // switch back to g + MOVW g_m(g), R1 + MOVW m_curg(R1), g + MOVW (g_sched+gobuf_sp)(g), R13 + MOVW $0, R3 + MOVW R3, (g_sched+gobuf_sp)(g) + RET + +noswitch: + // Using a tail call here cleans up tracebacks since we won't stop + // at an intermediate systemstack. + MOVW.P 4(R13), R14 // restore LR + MOVW R6, R0 // arg + B (R5) + +// Runs on OS stack. Duration (in 100ns units) is in R0. +TEXT runtime·usleep2(SB),NOSPLIT|NOFRAME,$0 + MOVM.DB.W [R4, R14], (R13) // push {r4, lr} + MOVW R13, R4 // Save SP + SUB $8, R13 // R13 = R13 - 8 + BIC $0x7, R13 // Align SP for ABI + RSB $0, R0, R3 // R3 = -R0 + MOVW $0, R1 // R1 = FALSE (alertable) + MOVW $-1, R0 // R0 = handle + MOVW R13, R2 // R2 = pTime + MOVW R3, 0(R2) // time_lo + MOVW R0, 4(R2) // time_hi + MOVW runtime·_NtWaitForSingleObject(SB), R3 + BL (R3) + MOVW R4, R13 // Restore SP + MOVM.IA.W (R13), [R4, R15] // pop {R4, pc} + +// Runs on OS stack. +TEXT runtime·switchtothread(SB),NOSPLIT|NOFRAME,$0 + MOVM.DB.W [R4, R14], (R13) // push {R4, lr} + MOVW R13, R4 + BIC $0x7, R13 // alignment for ABI + MOVW runtime·_SwitchToThread(SB), R0 + BL (R0) + MOVW R4, R13 // restore stack pointer + MOVM.IA.W (R13), [R4, R15] // pop {R4, pc} + +TEXT ·publicationBarrier(SB),NOSPLIT|NOFRAME,$0-0 + B runtime·armPublicationBarrier(SB) + +// never called (cgo not supported) +TEXT runtime·read_tls_fallback(SB),NOSPLIT|NOFRAME,$0 + MOVW $0xabcd, R0 + MOVW R0, (R0) + RET + +// See http://www.dcl.hpi.uni-potsdam.de/research/WRK/2007/08/getting-os-information-the-kuser_shared_data-structure/ +// Must read hi1, then lo, then hi2. The snapshot is valid if hi1 == hi2. +#define _INTERRUPT_TIME 0x7ffe0008 +#define _SYSTEM_TIME 0x7ffe0014 +#define time_lo 0 +#define time_hi1 4 +#define time_hi2 8 + +TEXT runtime·nanotime(SB),NOSPLIT,$0-8 + MOVW $0, R0 + MOVB runtime·useQPCTime(SB), R0 + CMP $0, R0 + BNE useQPC + MOVW $_INTERRUPT_TIME, R3 +loop: + MOVW time_hi1(R3), R1 + MOVW time_lo(R3), R0 + MOVW time_hi2(R3), R2 + CMP R1, R2 + BNE loop + + // wintime = R1:R0, multiply by 100 + MOVW $100, R2 + MULLU R0, R2, (R4, R3) // R4:R3 = R1:R0 * R2 + MULA R1, R2, R4, R4 + + // wintime*100 = R4:R3, subtract startNano and return + MOVW runtime·startNano+0(SB), R0 + MOVW runtime·startNano+4(SB), R1 + SUB.S R0, R3 + SBC R1, R4 + MOVW R3, ret_lo+0(FP) + MOVW R4, ret_hi+4(FP) + RET +useQPC: + B runtime·nanotimeQPC(SB) // tail call + RET + +TEXT time·now(SB),NOSPLIT,$0-20 + MOVW $0, R0 + MOVB runtime·useQPCTime(SB), R0 + CMP $0, R0 + BNE useQPC + MOVW $_INTERRUPT_TIME, R3 +loop: + MOVW time_hi1(R3), R1 + MOVW time_lo(R3), R0 + MOVW time_hi2(R3), R2 + CMP R1, R2 + BNE loop + + // wintime = R1:R0, multiply by 100 + MOVW $100, R2 + MULLU R0, R2, (R4, R3) // R4:R3 = R1:R0 * R2 + MULA R1, R2, R4, R4 + + // wintime*100 = R4:R3, subtract startNano and return + MOVW runtime·startNano+0(SB), R0 + MOVW runtime·startNano+4(SB), R1 + SUB.S R0, R3 + SBC R1, R4 + MOVW R3, mono+12(FP) + MOVW R4, mono+16(FP) + + MOVW $_SYSTEM_TIME, R3 +wall: + MOVW time_hi1(R3), R1 + MOVW time_lo(R3), R0 + MOVW time_hi2(R3), R2 + CMP R1, R2 + BNE wall + + // w = R1:R0 in 100ns untis + // convert to Unix epoch (but still 100ns units) + #define delta 116444736000000000 + SUB.S $(delta & 0xFFFFFFFF), R0 + SBC $(delta >> 32), R1 + + // Convert to nSec + MOVW $100, R2 + MULLU R0, R2, (R4, R3) // R4:R3 = R1:R0 * R2 + MULA R1, R2, R4, R4 + // w = R2:R1 in nSec + MOVW R3, R1 // R4:R3 -> R2:R1 + MOVW R4, R2 + + // multiply nanoseconds by reciprocal of 10**9 (scaled by 2**61) + // to get seconds (96 bit scaled result) + MOVW $0x89705f41, R3 // 2**61 * 10**-9 + MULLU R1,R3,(R6,R5) // R7:R6:R5 = R2:R1 * R3 + MOVW $0,R7 + MULALU R2,R3,(R7,R6) + + // unscale by discarding low 32 bits, shifting the rest by 29 + MOVW R6>>29,R6 // R7:R6 = (R7:R6:R5 >> 61) + ORR R7<<3,R6 + MOVW R7>>29,R7 + + // subtract (10**9 * sec) from nsec to get nanosecond remainder + MOVW $1000000000, R5 // 10**9 + MULLU R6,R5,(R9,R8) // R9:R8 = R7:R6 * R5 + MULA R7,R5,R9,R9 + SUB.S R8,R1 // R2:R1 -= R9:R8 + SBC R9,R2 + + // because reciprocal was a truncated repeating fraction, quotient + // may be slightly too small -- adjust to make remainder < 10**9 + CMP R5,R1 // if remainder > 10**9 + SUB.HS R5,R1 // remainder -= 10**9 + ADD.HS $1,R6 // sec += 1 + + MOVW R6,sec_lo+0(FP) + MOVW R7,sec_hi+4(FP) + MOVW R1,nsec+8(FP) + RET +useQPC: + B runtime·nanotimeQPC(SB) // tail call + RET + diff --git a/src/runtime/syscall_windows.go b/src/runtime/syscall_windows.go index 8264070569ff3..0858efaf616f9 100644 --- a/src/runtime/syscall_windows.go +++ b/src/runtime/syscall_windows.go @@ -25,18 +25,32 @@ func (c *wincallbackcontext) setCleanstack(cleanstack bool) { var ( cbs callbacks cbctxts **wincallbackcontext = &cbs.ctxt[0] // to simplify access to cbs.ctxt in sys_windows_*.s - - callbackasm byte // type isn't really byte, it's code in runtime ) +func callbackasm() + // callbackasmAddr returns address of runtime.callbackasm // function adjusted by i. -// runtime.callbackasm is just a series of CALL instructions -// (each is 5 bytes long), and we want callback to arrive at +// On x86 and amd64, runtime.callbackasm is a series of CALL instructions, +// and we want callback to arrive at // correspondent call instruction instead of start of // runtime.callbackasm. +// On ARM, runtime.callbackasm is a series of mov and branch instructions. +// R12 is loaded with the callback index. Each entry is two instructions, +// hence 8 bytes. func callbackasmAddr(i int) uintptr { - return uintptr(add(unsafe.Pointer(&callbackasm), uintptr(i*5))) + var entrySize int + switch GOARCH { + default: + panic("unsupported architecture") + case "386", "amd64": + entrySize = 5 + case "arm": + // On ARM, each entry is a MOV instruction + // followed by a branch instruction + entrySize = 8 + } + return funcPC(callbackasm) + uintptr(i*entrySize) } //go:linkname compileCallback syscall.compileCallback diff --git a/src/runtime/tls_arm.s b/src/runtime/tls_arm.s index cc547a5db1303..e2c945d183a24 100644 --- a/src/runtime/tls_arm.s +++ b/src/runtime/tls_arm.s @@ -23,6 +23,9 @@ #ifdef GOOS_darwin #define TLSG_IS_VARIABLE #endif +#ifdef GOOS_windows +#define TLSG_IS_VARIABLE +#endif // save_g saves the g register into pthread-provided // thread-local memory, so that we can call externally compiled @@ -35,6 +38,17 @@ TEXT runtime·save_g(SB),NOSPLIT|NOFRAME,$0 // nothing to do as nacl/arm does not use TLS at all. MOVW g, R0 // preserve R0 across call to setg<> RET +#else +#ifdef GOOS_windows + // Save the value in the _TEB->TlsSlots array. + // Effectively implements TlsSetValue(). + MRC 15, 0, R0, C13, C0, 2 + ADD $0xe10, R0 + MOVW $runtime·tls_g(SB), R11 + MOVW (R11), R11 + MOVW g, R11<<2(R0) + MOVW g, R0 // preserve R0 accross call to setg<> + RET #else // If the host does not support MRC the linker will replace it with // a call to runtime.read_tls_fallback which jumps to __kuser_get_tls. @@ -47,6 +61,7 @@ TEXT runtime·save_g(SB),NOSPLIT|NOFRAME,$0 MOVW g, R0 // preserve R0 across call to setg<> RET #endif +#endif // load_g loads the g register from pthread-provided // thread-local memory, for use after calling externally compiled @@ -55,6 +70,16 @@ TEXT runtime·load_g(SB),NOSPLIT,$0 #ifdef GOOS_nacl // nothing to do as nacl/arm does not use TLS at all. RET +#else +#ifdef GOOS_windows + // Get the value from the _TEB->TlsSlots array. + // Effectively implements TlsGetValue(). + MRC 15, 0, R0, C13, C0, 2 + ADD $0xe10, R0 + MOVW $runtime·tls_g(SB), g + MOVW (g), g + MOVW g<<2(R0), g + RET #else // See save_g MRC 15, 0, R0, C13, C0, 3 // fetch TLS base pointer @@ -64,6 +89,7 @@ TEXT runtime·load_g(SB),NOSPLIT,$0 MOVW 0(R0), g RET #endif +#endif // This is called from rt0_go, which runs on the system stack // using the initial stack allocated by the OS. @@ -76,6 +102,20 @@ TEXT runtime·load_g(SB),NOSPLIT,$0 // Declare a dummy word ($4, not $0) to make sure the // frame is 8 bytes and stays 8-byte-aligned. TEXT runtime·_initcgo(SB),NOSPLIT,$4 +#ifdef GOOS_windows + MOVW R13, R4 + BIC $0x7, R13 + MOVW $runtime·_TlsAlloc(SB), R0 + MOVW (R0), R0 + BL (R0) + // Assert that slot is less than 64 so we can use _TEB->TlsSlots + CMP $64, R0 + MOVW $runtime·abort(SB), R1 + BL.GE (R1) + MOVW $runtime·tls_g(SB), R1 + MOVW R0, (R1) + MOVW R4, R13 +#else #ifndef GOOS_nacl // if there is an _cgo_init, call it. MOVW _cgo_init(SB), R4 @@ -91,7 +131,8 @@ TEXT runtime·_initcgo(SB),NOSPLIT,$4 MOVW $setg_gcc<>(SB), R1 // arg 1: setg MOVW g, R0 // arg 0: G BL (R4) // will clobber R0-R3 -#endif +#endif // GOOS_nacl +#endif // GOOS_windows nocgo: RET diff --git a/src/runtime/wincallback.go b/src/runtime/wincallback.go index 9f003aed051f9..c022916422de3 100644 --- a/src/runtime/wincallback.go +++ b/src/runtime/wincallback.go @@ -17,11 +17,12 @@ import ( const maxCallback = 2000 -func genasm() { +func genasm386Amd64() { var buf bytes.Buffer - buf.WriteString(`// generated by wincallback.go; run go generate + buf.WriteString(`// Code generated by wincallback.go using 'go generate'. DO NOT EDIT. +// +build 386 amd64 // runtime·callbackasm is called by external code to // execute Go implemented callback function. It is not // called from the start, instead runtime·compilecallback @@ -29,13 +30,43 @@ func genasm() { // appropriately so different callbacks start with different // CALL instruction in runtime·callbackasm. This determines // which Go callback function is executed later on. + TEXT runtime·callbackasm(SB),7,$0 `) for i := 0; i < maxCallback; i++ { buf.WriteString("\tCALL\truntime·callbackasm1(SB)\n") } - err := ioutil.WriteFile("zcallback_windows.s", buf.Bytes(), 0666) + filename := fmt.Sprintf("zcallback_windows.s") + err := ioutil.WriteFile(filename, buf.Bytes(), 0666) + if err != nil { + fmt.Fprintf(os.Stderr, "wincallback: %s\n", err) + os.Exit(2) + } +} + +func genasmArm() { + var buf bytes.Buffer + + buf.WriteString(`// Code generated by wincallback.go using 'go generate'. DO NOT EDIT. + +// External code calls into callbackasm at an offset corresponding +// to the callback index. Callbackasm is a table of MOV and B instructions. +// The MOV instruction loads R12 with the callback index, and the +// B instruction branches to callbackasm1. +// callbackasm1 takes the callback index from R12 and +// indexes into an array that stores information about each callback. +// It then calls the Go implementation for that callback. +#include "textflag.h" + +TEXT runtime·callbackasm(SB),NOSPLIT|NOFRAME,$0 +`) + for i := 0; i < maxCallback; i++ { + buf.WriteString(fmt.Sprintf("\tMOVW\t$%d, R12\n", i)) + buf.WriteString("\tB\truntime·callbackasm1(SB)\n") + } + + err := ioutil.WriteFile("zcallback_windows_arm.s", buf.Bytes(), 0666) if err != nil { fmt.Fprintf(os.Stderr, "wincallback: %s\n", err) os.Exit(2) @@ -45,7 +76,7 @@ TEXT runtime·callbackasm(SB),7,$0 func gengo() { var buf bytes.Buffer - buf.WriteString(fmt.Sprintf(`// generated by wincallback.go; run go generate + buf.WriteString(fmt.Sprintf(`// Code generated by wincallback.go using 'go generate'. DO NOT EDIT. package runtime @@ -59,6 +90,7 @@ const cb_max = %d // maximum number of windows callbacks allowed } func main() { - genasm() + genasm386Amd64() + genasmArm() gengo() } diff --git a/src/runtime/zcallback_windows.go b/src/runtime/zcallback_windows.go index 9908d4ec2370f..2c3cb28518f5d 100644 --- a/src/runtime/zcallback_windows.go +++ b/src/runtime/zcallback_windows.go @@ -1,4 +1,4 @@ -// generated by wincallback.go; run go generate +// Code generated by wincallback.go using 'go generate'. DO NOT EDIT. package runtime diff --git a/src/runtime/zcallback_windows.s b/src/runtime/zcallback_windows.s index b9a3a3081190e..7772eef329f58 100644 --- a/src/runtime/zcallback_windows.s +++ b/src/runtime/zcallback_windows.s @@ -1,5 +1,6 @@ -// generated by wincallback.go; run go generate +// Code generated by wincallback.go using 'go generate'. DO NOT EDIT. +// +build 386 amd64 // runtime·callbackasm is called by external code to // execute Go implemented callback function. It is not // called from the start, instead runtime·compilecallback @@ -7,6 +8,7 @@ // appropriately so different callbacks start with different // CALL instruction in runtime·callbackasm. This determines // which Go callback function is executed later on. + TEXT runtime·callbackasm(SB),7,$0 CALL runtime·callbackasm1(SB) CALL runtime·callbackasm1(SB) diff --git a/src/runtime/zcallback_windows_arm.s b/src/runtime/zcallback_windows_arm.s new file mode 100644 index 0000000000000..f943d84cbfe5f --- /dev/null +++ b/src/runtime/zcallback_windows_arm.s @@ -0,0 +1,4012 @@ +// Code generated by wincallback.go using 'go generate'. DO NOT EDIT. + +// External code calls into callbackasm at an offset corresponding +// to the callback index. Callbackasm is a table of MOV and B instructions. +// The MOV instruction loads R12 with the callback index, and the +// B instruction branches to callbackasm1. +// callbackasm1 takes the callback index from R12 and +// indexes into an array that stores information about each callback. +// It then calls the Go implementation for that callback. +#include "textflag.h" + +TEXT runtime·callbackasm(SB),NOSPLIT|NOFRAME,$0 + MOVW $0, R12 + B runtime·callbackasm1(SB) + MOVW $1, R12 + B runtime·callbackasm1(SB) + MOVW $2, R12 + B runtime·callbackasm1(SB) + MOVW $3, R12 + B runtime·callbackasm1(SB) + MOVW $4, R12 + B runtime·callbackasm1(SB) + MOVW $5, R12 + B runtime·callbackasm1(SB) + MOVW $6, R12 + B runtime·callbackasm1(SB) + MOVW $7, R12 + B runtime·callbackasm1(SB) + MOVW $8, R12 + B runtime·callbackasm1(SB) + MOVW $9, R12 + B runtime·callbackasm1(SB) + MOVW $10, R12 + B runtime·callbackasm1(SB) + MOVW $11, R12 + B runtime·callbackasm1(SB) + MOVW $12, R12 + B runtime·callbackasm1(SB) + MOVW $13, R12 + B runtime·callbackasm1(SB) + MOVW $14, R12 + B runtime·callbackasm1(SB) + MOVW $15, R12 + B runtime·callbackasm1(SB) + MOVW $16, R12 + B runtime·callbackasm1(SB) + MOVW $17, R12 + B runtime·callbackasm1(SB) + MOVW $18, R12 + B runtime·callbackasm1(SB) + MOVW $19, R12 + B runtime·callbackasm1(SB) + MOVW $20, R12 + B runtime·callbackasm1(SB) + MOVW $21, R12 + B runtime·callbackasm1(SB) + MOVW $22, R12 + B runtime·callbackasm1(SB) + MOVW $23, R12 + B runtime·callbackasm1(SB) + MOVW $24, R12 + B runtime·callbackasm1(SB) + MOVW $25, R12 + B runtime·callbackasm1(SB) + MOVW $26, R12 + B runtime·callbackasm1(SB) + MOVW $27, R12 + B runtime·callbackasm1(SB) + MOVW $28, R12 + B runtime·callbackasm1(SB) + MOVW $29, R12 + B runtime·callbackasm1(SB) + MOVW $30, R12 + B runtime·callbackasm1(SB) + MOVW $31, R12 + B runtime·callbackasm1(SB) + MOVW $32, R12 + B runtime·callbackasm1(SB) + MOVW $33, R12 + B runtime·callbackasm1(SB) + MOVW $34, R12 + B runtime·callbackasm1(SB) + MOVW $35, R12 + B runtime·callbackasm1(SB) + MOVW $36, R12 + B runtime·callbackasm1(SB) + MOVW $37, R12 + B runtime·callbackasm1(SB) + MOVW $38, R12 + B runtime·callbackasm1(SB) + MOVW $39, R12 + B runtime·callbackasm1(SB) + MOVW $40, R12 + B runtime·callbackasm1(SB) + MOVW $41, R12 + B runtime·callbackasm1(SB) + MOVW $42, R12 + B runtime·callbackasm1(SB) + MOVW $43, R12 + B runtime·callbackasm1(SB) + MOVW $44, R12 + B runtime·callbackasm1(SB) + MOVW $45, R12 + B runtime·callbackasm1(SB) + MOVW $46, R12 + B runtime·callbackasm1(SB) + MOVW $47, R12 + B runtime·callbackasm1(SB) + MOVW $48, R12 + B runtime·callbackasm1(SB) + MOVW $49, R12 + B runtime·callbackasm1(SB) + MOVW $50, R12 + B runtime·callbackasm1(SB) + MOVW $51, R12 + B runtime·callbackasm1(SB) + MOVW $52, R12 + B runtime·callbackasm1(SB) + MOVW $53, R12 + B runtime·callbackasm1(SB) + MOVW $54, R12 + B runtime·callbackasm1(SB) + MOVW $55, R12 + B runtime·callbackasm1(SB) + MOVW $56, R12 + B runtime·callbackasm1(SB) + MOVW $57, R12 + B runtime·callbackasm1(SB) + MOVW $58, R12 + B runtime·callbackasm1(SB) + MOVW $59, R12 + B runtime·callbackasm1(SB) + MOVW $60, R12 + B runtime·callbackasm1(SB) + MOVW $61, R12 + B runtime·callbackasm1(SB) + MOVW $62, R12 + B runtime·callbackasm1(SB) + MOVW $63, R12 + B runtime·callbackasm1(SB) + MOVW $64, R12 + B runtime·callbackasm1(SB) + MOVW $65, R12 + B runtime·callbackasm1(SB) + MOVW $66, R12 + B runtime·callbackasm1(SB) + MOVW $67, R12 + B runtime·callbackasm1(SB) + MOVW $68, R12 + B runtime·callbackasm1(SB) + MOVW $69, R12 + B runtime·callbackasm1(SB) + MOVW $70, R12 + B runtime·callbackasm1(SB) + MOVW $71, R12 + B runtime·callbackasm1(SB) + MOVW $72, R12 + B runtime·callbackasm1(SB) + MOVW $73, R12 + B runtime·callbackasm1(SB) + MOVW $74, R12 + B runtime·callbackasm1(SB) + MOVW $75, R12 + B runtime·callbackasm1(SB) + MOVW $76, R12 + B runtime·callbackasm1(SB) + MOVW $77, R12 + B runtime·callbackasm1(SB) + MOVW $78, R12 + B runtime·callbackasm1(SB) + MOVW $79, R12 + B runtime·callbackasm1(SB) + MOVW $80, R12 + B runtime·callbackasm1(SB) + MOVW $81, R12 + B runtime·callbackasm1(SB) + MOVW $82, R12 + B runtime·callbackasm1(SB) + MOVW $83, R12 + B runtime·callbackasm1(SB) + MOVW $84, R12 + B runtime·callbackasm1(SB) + MOVW $85, R12 + B runtime·callbackasm1(SB) + MOVW $86, R12 + B runtime·callbackasm1(SB) + MOVW $87, R12 + B runtime·callbackasm1(SB) + MOVW $88, R12 + B runtime·callbackasm1(SB) + MOVW $89, R12 + B runtime·callbackasm1(SB) + MOVW $90, R12 + B runtime·callbackasm1(SB) + MOVW $91, R12 + B runtime·callbackasm1(SB) + MOVW $92, R12 + B runtime·callbackasm1(SB) + MOVW $93, R12 + B runtime·callbackasm1(SB) + MOVW $94, R12 + B runtime·callbackasm1(SB) + MOVW $95, R12 + B runtime·callbackasm1(SB) + MOVW $96, R12 + B runtime·callbackasm1(SB) + MOVW $97, R12 + B runtime·callbackasm1(SB) + MOVW $98, R12 + B runtime·callbackasm1(SB) + MOVW $99, R12 + B runtime·callbackasm1(SB) + MOVW $100, R12 + B runtime·callbackasm1(SB) + MOVW $101, R12 + B runtime·callbackasm1(SB) + MOVW $102, R12 + B runtime·callbackasm1(SB) + MOVW $103, R12 + B runtime·callbackasm1(SB) + MOVW $104, R12 + B runtime·callbackasm1(SB) + MOVW $105, R12 + B runtime·callbackasm1(SB) + MOVW $106, R12 + B runtime·callbackasm1(SB) + MOVW $107, R12 + B runtime·callbackasm1(SB) + MOVW $108, R12 + B runtime·callbackasm1(SB) + MOVW $109, R12 + B runtime·callbackasm1(SB) + MOVW $110, R12 + B runtime·callbackasm1(SB) + MOVW $111, R12 + B runtime·callbackasm1(SB) + MOVW $112, R12 + B runtime·callbackasm1(SB) + MOVW $113, R12 + B runtime·callbackasm1(SB) + MOVW $114, R12 + B runtime·callbackasm1(SB) + MOVW $115, R12 + B runtime·callbackasm1(SB) + MOVW $116, R12 + B runtime·callbackasm1(SB) + MOVW $117, R12 + B runtime·callbackasm1(SB) + MOVW $118, R12 + B runtime·callbackasm1(SB) + MOVW $119, R12 + B runtime·callbackasm1(SB) + MOVW $120, R12 + B runtime·callbackasm1(SB) + MOVW $121, R12 + B runtime·callbackasm1(SB) + MOVW $122, R12 + B runtime·callbackasm1(SB) + MOVW $123, R12 + B runtime·callbackasm1(SB) + MOVW $124, R12 + B runtime·callbackasm1(SB) + MOVW $125, R12 + B runtime·callbackasm1(SB) + MOVW $126, R12 + B runtime·callbackasm1(SB) + MOVW $127, R12 + B runtime·callbackasm1(SB) + MOVW $128, R12 + B runtime·callbackasm1(SB) + MOVW $129, R12 + B runtime·callbackasm1(SB) + MOVW $130, R12 + B runtime·callbackasm1(SB) + MOVW $131, R12 + B runtime·callbackasm1(SB) + MOVW $132, R12 + B runtime·callbackasm1(SB) + MOVW $133, R12 + B runtime·callbackasm1(SB) + MOVW $134, R12 + B runtime·callbackasm1(SB) + MOVW $135, R12 + B runtime·callbackasm1(SB) + MOVW $136, R12 + B runtime·callbackasm1(SB) + MOVW $137, R12 + B runtime·callbackasm1(SB) + MOVW $138, R12 + B runtime·callbackasm1(SB) + MOVW $139, R12 + B runtime·callbackasm1(SB) + MOVW $140, R12 + B runtime·callbackasm1(SB) + MOVW $141, R12 + B runtime·callbackasm1(SB) + MOVW $142, R12 + B runtime·callbackasm1(SB) + MOVW $143, R12 + B runtime·callbackasm1(SB) + MOVW $144, R12 + B runtime·callbackasm1(SB) + MOVW $145, R12 + B runtime·callbackasm1(SB) + MOVW $146, R12 + B runtime·callbackasm1(SB) + MOVW $147, R12 + B runtime·callbackasm1(SB) + MOVW $148, R12 + B runtime·callbackasm1(SB) + MOVW $149, R12 + B runtime·callbackasm1(SB) + MOVW $150, R12 + B runtime·callbackasm1(SB) + MOVW $151, R12 + B runtime·callbackasm1(SB) + MOVW $152, R12 + B runtime·callbackasm1(SB) + MOVW $153, R12 + B runtime·callbackasm1(SB) + MOVW $154, R12 + B runtime·callbackasm1(SB) + MOVW $155, R12 + B runtime·callbackasm1(SB) + MOVW $156, R12 + B runtime·callbackasm1(SB) + MOVW $157, R12 + B runtime·callbackasm1(SB) + MOVW $158, R12 + B runtime·callbackasm1(SB) + MOVW $159, R12 + B runtime·callbackasm1(SB) + MOVW $160, R12 + B runtime·callbackasm1(SB) + MOVW $161, R12 + B runtime·callbackasm1(SB) + MOVW $162, R12 + B runtime·callbackasm1(SB) + MOVW $163, R12 + B runtime·callbackasm1(SB) + MOVW $164, R12 + B runtime·callbackasm1(SB) + MOVW $165, R12 + B runtime·callbackasm1(SB) + MOVW $166, R12 + B runtime·callbackasm1(SB) + MOVW $167, R12 + B runtime·callbackasm1(SB) + MOVW $168, R12 + B runtime·callbackasm1(SB) + MOVW $169, R12 + B runtime·callbackasm1(SB) + MOVW $170, R12 + B runtime·callbackasm1(SB) + MOVW $171, R12 + B runtime·callbackasm1(SB) + MOVW $172, R12 + B runtime·callbackasm1(SB) + MOVW $173, R12 + B runtime·callbackasm1(SB) + MOVW $174, R12 + B runtime·callbackasm1(SB) + MOVW $175, R12 + B runtime·callbackasm1(SB) + MOVW $176, R12 + B runtime·callbackasm1(SB) + MOVW $177, R12 + B runtime·callbackasm1(SB) + MOVW $178, R12 + B runtime·callbackasm1(SB) + MOVW $179, R12 + B runtime·callbackasm1(SB) + MOVW $180, R12 + B runtime·callbackasm1(SB) + MOVW $181, R12 + B runtime·callbackasm1(SB) + MOVW $182, R12 + B runtime·callbackasm1(SB) + MOVW $183, R12 + B runtime·callbackasm1(SB) + MOVW $184, R12 + B runtime·callbackasm1(SB) + MOVW $185, R12 + B runtime·callbackasm1(SB) + MOVW $186, R12 + B runtime·callbackasm1(SB) + MOVW $187, R12 + B runtime·callbackasm1(SB) + MOVW $188, R12 + B runtime·callbackasm1(SB) + MOVW $189, R12 + B runtime·callbackasm1(SB) + MOVW $190, R12 + B runtime·callbackasm1(SB) + MOVW $191, R12 + B runtime·callbackasm1(SB) + MOVW $192, R12 + B runtime·callbackasm1(SB) + MOVW $193, R12 + B runtime·callbackasm1(SB) + MOVW $194, R12 + B runtime·callbackasm1(SB) + MOVW $195, R12 + B runtime·callbackasm1(SB) + MOVW $196, R12 + B runtime·callbackasm1(SB) + MOVW $197, R12 + B runtime·callbackasm1(SB) + MOVW $198, R12 + B runtime·callbackasm1(SB) + MOVW $199, R12 + B runtime·callbackasm1(SB) + MOVW $200, R12 + B runtime·callbackasm1(SB) + MOVW $201, R12 + B runtime·callbackasm1(SB) + MOVW $202, R12 + B runtime·callbackasm1(SB) + MOVW $203, R12 + B runtime·callbackasm1(SB) + MOVW $204, R12 + B runtime·callbackasm1(SB) + MOVW $205, R12 + B runtime·callbackasm1(SB) + MOVW $206, R12 + B runtime·callbackasm1(SB) + MOVW $207, R12 + B runtime·callbackasm1(SB) + MOVW $208, R12 + B runtime·callbackasm1(SB) + MOVW $209, R12 + B runtime·callbackasm1(SB) + MOVW $210, R12 + B runtime·callbackasm1(SB) + MOVW $211, R12 + B runtime·callbackasm1(SB) + MOVW $212, R12 + B runtime·callbackasm1(SB) + MOVW $213, R12 + B runtime·callbackasm1(SB) + MOVW $214, R12 + B runtime·callbackasm1(SB) + MOVW $215, R12 + B runtime·callbackasm1(SB) + MOVW $216, R12 + B runtime·callbackasm1(SB) + MOVW $217, R12 + B runtime·callbackasm1(SB) + MOVW $218, R12 + B runtime·callbackasm1(SB) + MOVW $219, R12 + B runtime·callbackasm1(SB) + MOVW $220, R12 + B runtime·callbackasm1(SB) + MOVW $221, R12 + B runtime·callbackasm1(SB) + MOVW $222, R12 + B runtime·callbackasm1(SB) + MOVW $223, R12 + B runtime·callbackasm1(SB) + MOVW $224, R12 + B runtime·callbackasm1(SB) + MOVW $225, R12 + B runtime·callbackasm1(SB) + MOVW $226, R12 + B runtime·callbackasm1(SB) + MOVW $227, R12 + B runtime·callbackasm1(SB) + MOVW $228, R12 + B runtime·callbackasm1(SB) + MOVW $229, R12 + B runtime·callbackasm1(SB) + MOVW $230, R12 + B runtime·callbackasm1(SB) + MOVW $231, R12 + B runtime·callbackasm1(SB) + MOVW $232, R12 + B runtime·callbackasm1(SB) + MOVW $233, R12 + B runtime·callbackasm1(SB) + MOVW $234, R12 + B runtime·callbackasm1(SB) + MOVW $235, R12 + B runtime·callbackasm1(SB) + MOVW $236, R12 + B runtime·callbackasm1(SB) + MOVW $237, R12 + B runtime·callbackasm1(SB) + MOVW $238, R12 + B runtime·callbackasm1(SB) + MOVW $239, R12 + B runtime·callbackasm1(SB) + MOVW $240, R12 + B runtime·callbackasm1(SB) + MOVW $241, R12 + B runtime·callbackasm1(SB) + MOVW $242, R12 + B runtime·callbackasm1(SB) + MOVW $243, R12 + B runtime·callbackasm1(SB) + MOVW $244, R12 + B runtime·callbackasm1(SB) + MOVW $245, R12 + B runtime·callbackasm1(SB) + MOVW $246, R12 + B runtime·callbackasm1(SB) + MOVW $247, R12 + B runtime·callbackasm1(SB) + MOVW $248, R12 + B runtime·callbackasm1(SB) + MOVW $249, R12 + B runtime·callbackasm1(SB) + MOVW $250, R12 + B runtime·callbackasm1(SB) + MOVW $251, R12 + B runtime·callbackasm1(SB) + MOVW $252, R12 + B runtime·callbackasm1(SB) + MOVW $253, R12 + B runtime·callbackasm1(SB) + MOVW $254, R12 + B runtime·callbackasm1(SB) + MOVW $255, R12 + B runtime·callbackasm1(SB) + MOVW $256, R12 + B runtime·callbackasm1(SB) + MOVW $257, R12 + B runtime·callbackasm1(SB) + MOVW $258, R12 + B runtime·callbackasm1(SB) + MOVW $259, R12 + B runtime·callbackasm1(SB) + MOVW $260, R12 + B runtime·callbackasm1(SB) + MOVW $261, R12 + B runtime·callbackasm1(SB) + MOVW $262, R12 + B runtime·callbackasm1(SB) + MOVW $263, R12 + B runtime·callbackasm1(SB) + MOVW $264, R12 + B runtime·callbackasm1(SB) + MOVW $265, R12 + B runtime·callbackasm1(SB) + MOVW $266, R12 + B runtime·callbackasm1(SB) + MOVW $267, R12 + B runtime·callbackasm1(SB) + MOVW $268, R12 + B runtime·callbackasm1(SB) + MOVW $269, R12 + B runtime·callbackasm1(SB) + MOVW $270, R12 + B runtime·callbackasm1(SB) + MOVW $271, R12 + B runtime·callbackasm1(SB) + MOVW $272, R12 + B runtime·callbackasm1(SB) + MOVW $273, R12 + B runtime·callbackasm1(SB) + MOVW $274, R12 + B runtime·callbackasm1(SB) + MOVW $275, R12 + B runtime·callbackasm1(SB) + MOVW $276, R12 + B runtime·callbackasm1(SB) + MOVW $277, R12 + B runtime·callbackasm1(SB) + MOVW $278, R12 + B runtime·callbackasm1(SB) + MOVW $279, R12 + B runtime·callbackasm1(SB) + MOVW $280, R12 + B runtime·callbackasm1(SB) + MOVW $281, R12 + B runtime·callbackasm1(SB) + MOVW $282, R12 + B runtime·callbackasm1(SB) + MOVW $283, R12 + B runtime·callbackasm1(SB) + MOVW $284, R12 + B runtime·callbackasm1(SB) + MOVW $285, R12 + B runtime·callbackasm1(SB) + MOVW $286, R12 + B runtime·callbackasm1(SB) + MOVW $287, R12 + B runtime·callbackasm1(SB) + MOVW $288, R12 + B runtime·callbackasm1(SB) + MOVW $289, R12 + B runtime·callbackasm1(SB) + MOVW $290, R12 + B runtime·callbackasm1(SB) + MOVW $291, R12 + B runtime·callbackasm1(SB) + MOVW $292, R12 + B runtime·callbackasm1(SB) + MOVW $293, R12 + B runtime·callbackasm1(SB) + MOVW $294, R12 + B runtime·callbackasm1(SB) + MOVW $295, R12 + B runtime·callbackasm1(SB) + MOVW $296, R12 + B runtime·callbackasm1(SB) + MOVW $297, R12 + B runtime·callbackasm1(SB) + MOVW $298, R12 + B runtime·callbackasm1(SB) + MOVW $299, R12 + B runtime·callbackasm1(SB) + MOVW $300, R12 + B runtime·callbackasm1(SB) + MOVW $301, R12 + B runtime·callbackasm1(SB) + MOVW $302, R12 + B runtime·callbackasm1(SB) + MOVW $303, R12 + B runtime·callbackasm1(SB) + MOVW $304, R12 + B runtime·callbackasm1(SB) + MOVW $305, R12 + B runtime·callbackasm1(SB) + MOVW $306, R12 + B runtime·callbackasm1(SB) + MOVW $307, R12 + B runtime·callbackasm1(SB) + MOVW $308, R12 + B runtime·callbackasm1(SB) + MOVW $309, R12 + B runtime·callbackasm1(SB) + MOVW $310, R12 + B runtime·callbackasm1(SB) + MOVW $311, R12 + B runtime·callbackasm1(SB) + MOVW $312, R12 + B runtime·callbackasm1(SB) + MOVW $313, R12 + B runtime·callbackasm1(SB) + MOVW $314, R12 + B runtime·callbackasm1(SB) + MOVW $315, R12 + B runtime·callbackasm1(SB) + MOVW $316, R12 + B runtime·callbackasm1(SB) + MOVW $317, R12 + B runtime·callbackasm1(SB) + MOVW $318, R12 + B runtime·callbackasm1(SB) + MOVW $319, R12 + B runtime·callbackasm1(SB) + MOVW $320, R12 + B runtime·callbackasm1(SB) + MOVW $321, R12 + B runtime·callbackasm1(SB) + MOVW $322, R12 + B runtime·callbackasm1(SB) + MOVW $323, R12 + B runtime·callbackasm1(SB) + MOVW $324, R12 + B runtime·callbackasm1(SB) + MOVW $325, R12 + B runtime·callbackasm1(SB) + MOVW $326, R12 + B runtime·callbackasm1(SB) + MOVW $327, R12 + B runtime·callbackasm1(SB) + MOVW $328, R12 + B runtime·callbackasm1(SB) + MOVW $329, R12 + B runtime·callbackasm1(SB) + MOVW $330, R12 + B runtime·callbackasm1(SB) + MOVW $331, R12 + B runtime·callbackasm1(SB) + MOVW $332, R12 + B runtime·callbackasm1(SB) + MOVW $333, R12 + B runtime·callbackasm1(SB) + MOVW $334, R12 + B runtime·callbackasm1(SB) + MOVW $335, R12 + B runtime·callbackasm1(SB) + MOVW $336, R12 + B runtime·callbackasm1(SB) + MOVW $337, R12 + B runtime·callbackasm1(SB) + MOVW $338, R12 + B runtime·callbackasm1(SB) + MOVW $339, R12 + B runtime·callbackasm1(SB) + MOVW $340, R12 + B runtime·callbackasm1(SB) + MOVW $341, R12 + B runtime·callbackasm1(SB) + MOVW $342, R12 + B runtime·callbackasm1(SB) + MOVW $343, R12 + B runtime·callbackasm1(SB) + MOVW $344, R12 + B runtime·callbackasm1(SB) + MOVW $345, R12 + B runtime·callbackasm1(SB) + MOVW $346, R12 + B runtime·callbackasm1(SB) + MOVW $347, R12 + B runtime·callbackasm1(SB) + MOVW $348, R12 + B runtime·callbackasm1(SB) + MOVW $349, R12 + B runtime·callbackasm1(SB) + MOVW $350, R12 + B runtime·callbackasm1(SB) + MOVW $351, R12 + B runtime·callbackasm1(SB) + MOVW $352, R12 + B runtime·callbackasm1(SB) + MOVW $353, R12 + B runtime·callbackasm1(SB) + MOVW $354, R12 + B runtime·callbackasm1(SB) + MOVW $355, R12 + B runtime·callbackasm1(SB) + MOVW $356, R12 + B runtime·callbackasm1(SB) + MOVW $357, R12 + B runtime·callbackasm1(SB) + MOVW $358, R12 + B runtime·callbackasm1(SB) + MOVW $359, R12 + B runtime·callbackasm1(SB) + MOVW $360, R12 + B runtime·callbackasm1(SB) + MOVW $361, R12 + B runtime·callbackasm1(SB) + MOVW $362, R12 + B runtime·callbackasm1(SB) + MOVW $363, R12 + B runtime·callbackasm1(SB) + MOVW $364, R12 + B runtime·callbackasm1(SB) + MOVW $365, R12 + B runtime·callbackasm1(SB) + MOVW $366, R12 + B runtime·callbackasm1(SB) + MOVW $367, R12 + B runtime·callbackasm1(SB) + MOVW $368, R12 + B runtime·callbackasm1(SB) + MOVW $369, R12 + B runtime·callbackasm1(SB) + MOVW $370, R12 + B runtime·callbackasm1(SB) + MOVW $371, R12 + B runtime·callbackasm1(SB) + MOVW $372, R12 + B runtime·callbackasm1(SB) + MOVW $373, R12 + B runtime·callbackasm1(SB) + MOVW $374, R12 + B runtime·callbackasm1(SB) + MOVW $375, R12 + B runtime·callbackasm1(SB) + MOVW $376, R12 + B runtime·callbackasm1(SB) + MOVW $377, R12 + B runtime·callbackasm1(SB) + MOVW $378, R12 + B runtime·callbackasm1(SB) + MOVW $379, R12 + B runtime·callbackasm1(SB) + MOVW $380, R12 + B runtime·callbackasm1(SB) + MOVW $381, R12 + B runtime·callbackasm1(SB) + MOVW $382, R12 + B runtime·callbackasm1(SB) + MOVW $383, R12 + B runtime·callbackasm1(SB) + MOVW $384, R12 + B runtime·callbackasm1(SB) + MOVW $385, R12 + B runtime·callbackasm1(SB) + MOVW $386, R12 + B runtime·callbackasm1(SB) + MOVW $387, R12 + B runtime·callbackasm1(SB) + MOVW $388, R12 + B runtime·callbackasm1(SB) + MOVW $389, R12 + B runtime·callbackasm1(SB) + MOVW $390, R12 + B runtime·callbackasm1(SB) + MOVW $391, R12 + B runtime·callbackasm1(SB) + MOVW $392, R12 + B runtime·callbackasm1(SB) + MOVW $393, R12 + B runtime·callbackasm1(SB) + MOVW $394, R12 + B runtime·callbackasm1(SB) + MOVW $395, R12 + B runtime·callbackasm1(SB) + MOVW $396, R12 + B runtime·callbackasm1(SB) + MOVW $397, R12 + B runtime·callbackasm1(SB) + MOVW $398, R12 + B runtime·callbackasm1(SB) + MOVW $399, R12 + B runtime·callbackasm1(SB) + MOVW $400, R12 + B runtime·callbackasm1(SB) + MOVW $401, R12 + B runtime·callbackasm1(SB) + MOVW $402, R12 + B runtime·callbackasm1(SB) + MOVW $403, R12 + B runtime·callbackasm1(SB) + MOVW $404, R12 + B runtime·callbackasm1(SB) + MOVW $405, R12 + B runtime·callbackasm1(SB) + MOVW $406, R12 + B runtime·callbackasm1(SB) + MOVW $407, R12 + B runtime·callbackasm1(SB) + MOVW $408, R12 + B runtime·callbackasm1(SB) + MOVW $409, R12 + B runtime·callbackasm1(SB) + MOVW $410, R12 + B runtime·callbackasm1(SB) + MOVW $411, R12 + B runtime·callbackasm1(SB) + MOVW $412, R12 + B runtime·callbackasm1(SB) + MOVW $413, R12 + B runtime·callbackasm1(SB) + MOVW $414, R12 + B runtime·callbackasm1(SB) + MOVW $415, R12 + B runtime·callbackasm1(SB) + MOVW $416, R12 + B runtime·callbackasm1(SB) + MOVW $417, R12 + B runtime·callbackasm1(SB) + MOVW $418, R12 + B runtime·callbackasm1(SB) + MOVW $419, R12 + B runtime·callbackasm1(SB) + MOVW $420, R12 + B runtime·callbackasm1(SB) + MOVW $421, R12 + B runtime·callbackasm1(SB) + MOVW $422, R12 + B runtime·callbackasm1(SB) + MOVW $423, R12 + B runtime·callbackasm1(SB) + MOVW $424, R12 + B runtime·callbackasm1(SB) + MOVW $425, R12 + B runtime·callbackasm1(SB) + MOVW $426, R12 + B runtime·callbackasm1(SB) + MOVW $427, R12 + B runtime·callbackasm1(SB) + MOVW $428, R12 + B runtime·callbackasm1(SB) + MOVW $429, R12 + B runtime·callbackasm1(SB) + MOVW $430, R12 + B runtime·callbackasm1(SB) + MOVW $431, R12 + B runtime·callbackasm1(SB) + MOVW $432, R12 + B runtime·callbackasm1(SB) + MOVW $433, R12 + B runtime·callbackasm1(SB) + MOVW $434, R12 + B runtime·callbackasm1(SB) + MOVW $435, R12 + B runtime·callbackasm1(SB) + MOVW $436, R12 + B runtime·callbackasm1(SB) + MOVW $437, R12 + B runtime·callbackasm1(SB) + MOVW $438, R12 + B runtime·callbackasm1(SB) + MOVW $439, R12 + B runtime·callbackasm1(SB) + MOVW $440, R12 + B runtime·callbackasm1(SB) + MOVW $441, R12 + B runtime·callbackasm1(SB) + MOVW $442, R12 + B runtime·callbackasm1(SB) + MOVW $443, R12 + B runtime·callbackasm1(SB) + MOVW $444, R12 + B runtime·callbackasm1(SB) + MOVW $445, R12 + B runtime·callbackasm1(SB) + MOVW $446, R12 + B runtime·callbackasm1(SB) + MOVW $447, R12 + B runtime·callbackasm1(SB) + MOVW $448, R12 + B runtime·callbackasm1(SB) + MOVW $449, R12 + B runtime·callbackasm1(SB) + MOVW $450, R12 + B runtime·callbackasm1(SB) + MOVW $451, R12 + B runtime·callbackasm1(SB) + MOVW $452, R12 + B runtime·callbackasm1(SB) + MOVW $453, R12 + B runtime·callbackasm1(SB) + MOVW $454, R12 + B runtime·callbackasm1(SB) + MOVW $455, R12 + B runtime·callbackasm1(SB) + MOVW $456, R12 + B runtime·callbackasm1(SB) + MOVW $457, R12 + B runtime·callbackasm1(SB) + MOVW $458, R12 + B runtime·callbackasm1(SB) + MOVW $459, R12 + B runtime·callbackasm1(SB) + MOVW $460, R12 + B runtime·callbackasm1(SB) + MOVW $461, R12 + B runtime·callbackasm1(SB) + MOVW $462, R12 + B runtime·callbackasm1(SB) + MOVW $463, R12 + B runtime·callbackasm1(SB) + MOVW $464, R12 + B runtime·callbackasm1(SB) + MOVW $465, R12 + B runtime·callbackasm1(SB) + MOVW $466, R12 + B runtime·callbackasm1(SB) + MOVW $467, R12 + B runtime·callbackasm1(SB) + MOVW $468, R12 + B runtime·callbackasm1(SB) + MOVW $469, R12 + B runtime·callbackasm1(SB) + MOVW $470, R12 + B runtime·callbackasm1(SB) + MOVW $471, R12 + B runtime·callbackasm1(SB) + MOVW $472, R12 + B runtime·callbackasm1(SB) + MOVW $473, R12 + B runtime·callbackasm1(SB) + MOVW $474, R12 + B runtime·callbackasm1(SB) + MOVW $475, R12 + B runtime·callbackasm1(SB) + MOVW $476, R12 + B runtime·callbackasm1(SB) + MOVW $477, R12 + B runtime·callbackasm1(SB) + MOVW $478, R12 + B runtime·callbackasm1(SB) + MOVW $479, R12 + B runtime·callbackasm1(SB) + MOVW $480, R12 + B runtime·callbackasm1(SB) + MOVW $481, R12 + B runtime·callbackasm1(SB) + MOVW $482, R12 + B runtime·callbackasm1(SB) + MOVW $483, R12 + B runtime·callbackasm1(SB) + MOVW $484, R12 + B runtime·callbackasm1(SB) + MOVW $485, R12 + B runtime·callbackasm1(SB) + MOVW $486, R12 + B runtime·callbackasm1(SB) + MOVW $487, R12 + B runtime·callbackasm1(SB) + MOVW $488, R12 + B runtime·callbackasm1(SB) + MOVW $489, R12 + B runtime·callbackasm1(SB) + MOVW $490, R12 + B runtime·callbackasm1(SB) + MOVW $491, R12 + B runtime·callbackasm1(SB) + MOVW $492, R12 + B runtime·callbackasm1(SB) + MOVW $493, R12 + B runtime·callbackasm1(SB) + MOVW $494, R12 + B runtime·callbackasm1(SB) + MOVW $495, R12 + B runtime·callbackasm1(SB) + MOVW $496, R12 + B runtime·callbackasm1(SB) + MOVW $497, R12 + B runtime·callbackasm1(SB) + MOVW $498, R12 + B runtime·callbackasm1(SB) + MOVW $499, R12 + B runtime·callbackasm1(SB) + MOVW $500, R12 + B runtime·callbackasm1(SB) + MOVW $501, R12 + B runtime·callbackasm1(SB) + MOVW $502, R12 + B runtime·callbackasm1(SB) + MOVW $503, R12 + B runtime·callbackasm1(SB) + MOVW $504, R12 + B runtime·callbackasm1(SB) + MOVW $505, R12 + B runtime·callbackasm1(SB) + MOVW $506, R12 + B runtime·callbackasm1(SB) + MOVW $507, R12 + B runtime·callbackasm1(SB) + MOVW $508, R12 + B runtime·callbackasm1(SB) + MOVW $509, R12 + B runtime·callbackasm1(SB) + MOVW $510, R12 + B runtime·callbackasm1(SB) + MOVW $511, R12 + B runtime·callbackasm1(SB) + MOVW $512, R12 + B runtime·callbackasm1(SB) + MOVW $513, R12 + B runtime·callbackasm1(SB) + MOVW $514, R12 + B runtime·callbackasm1(SB) + MOVW $515, R12 + B runtime·callbackasm1(SB) + MOVW $516, R12 + B runtime·callbackasm1(SB) + MOVW $517, R12 + B runtime·callbackasm1(SB) + MOVW $518, R12 + B runtime·callbackasm1(SB) + MOVW $519, R12 + B runtime·callbackasm1(SB) + MOVW $520, R12 + B runtime·callbackasm1(SB) + MOVW $521, R12 + B runtime·callbackasm1(SB) + MOVW $522, R12 + B runtime·callbackasm1(SB) + MOVW $523, R12 + B runtime·callbackasm1(SB) + MOVW $524, R12 + B runtime·callbackasm1(SB) + MOVW $525, R12 + B runtime·callbackasm1(SB) + MOVW $526, R12 + B runtime·callbackasm1(SB) + MOVW $527, R12 + B runtime·callbackasm1(SB) + MOVW $528, R12 + B runtime·callbackasm1(SB) + MOVW $529, R12 + B runtime·callbackasm1(SB) + MOVW $530, R12 + B runtime·callbackasm1(SB) + MOVW $531, R12 + B runtime·callbackasm1(SB) + MOVW $532, R12 + B runtime·callbackasm1(SB) + MOVW $533, R12 + B runtime·callbackasm1(SB) + MOVW $534, R12 + B runtime·callbackasm1(SB) + MOVW $535, R12 + B runtime·callbackasm1(SB) + MOVW $536, R12 + B runtime·callbackasm1(SB) + MOVW $537, R12 + B runtime·callbackasm1(SB) + MOVW $538, R12 + B runtime·callbackasm1(SB) + MOVW $539, R12 + B runtime·callbackasm1(SB) + MOVW $540, R12 + B runtime·callbackasm1(SB) + MOVW $541, R12 + B runtime·callbackasm1(SB) + MOVW $542, R12 + B runtime·callbackasm1(SB) + MOVW $543, R12 + B runtime·callbackasm1(SB) + MOVW $544, R12 + B runtime·callbackasm1(SB) + MOVW $545, R12 + B runtime·callbackasm1(SB) + MOVW $546, R12 + B runtime·callbackasm1(SB) + MOVW $547, R12 + B runtime·callbackasm1(SB) + MOVW $548, R12 + B runtime·callbackasm1(SB) + MOVW $549, R12 + B runtime·callbackasm1(SB) + MOVW $550, R12 + B runtime·callbackasm1(SB) + MOVW $551, R12 + B runtime·callbackasm1(SB) + MOVW $552, R12 + B runtime·callbackasm1(SB) + MOVW $553, R12 + B runtime·callbackasm1(SB) + MOVW $554, R12 + B runtime·callbackasm1(SB) + MOVW $555, R12 + B runtime·callbackasm1(SB) + MOVW $556, R12 + B runtime·callbackasm1(SB) + MOVW $557, R12 + B runtime·callbackasm1(SB) + MOVW $558, R12 + B runtime·callbackasm1(SB) + MOVW $559, R12 + B runtime·callbackasm1(SB) + MOVW $560, R12 + B runtime·callbackasm1(SB) + MOVW $561, R12 + B runtime·callbackasm1(SB) + MOVW $562, R12 + B runtime·callbackasm1(SB) + MOVW $563, R12 + B runtime·callbackasm1(SB) + MOVW $564, R12 + B runtime·callbackasm1(SB) + MOVW $565, R12 + B runtime·callbackasm1(SB) + MOVW $566, R12 + B runtime·callbackasm1(SB) + MOVW $567, R12 + B runtime·callbackasm1(SB) + MOVW $568, R12 + B runtime·callbackasm1(SB) + MOVW $569, R12 + B runtime·callbackasm1(SB) + MOVW $570, R12 + B runtime·callbackasm1(SB) + MOVW $571, R12 + B runtime·callbackasm1(SB) + MOVW $572, R12 + B runtime·callbackasm1(SB) + MOVW $573, R12 + B runtime·callbackasm1(SB) + MOVW $574, R12 + B runtime·callbackasm1(SB) + MOVW $575, R12 + B runtime·callbackasm1(SB) + MOVW $576, R12 + B runtime·callbackasm1(SB) + MOVW $577, R12 + B runtime·callbackasm1(SB) + MOVW $578, R12 + B runtime·callbackasm1(SB) + MOVW $579, R12 + B runtime·callbackasm1(SB) + MOVW $580, R12 + B runtime·callbackasm1(SB) + MOVW $581, R12 + B runtime·callbackasm1(SB) + MOVW $582, R12 + B runtime·callbackasm1(SB) + MOVW $583, R12 + B runtime·callbackasm1(SB) + MOVW $584, R12 + B runtime·callbackasm1(SB) + MOVW $585, R12 + B runtime·callbackasm1(SB) + MOVW $586, R12 + B runtime·callbackasm1(SB) + MOVW $587, R12 + B runtime·callbackasm1(SB) + MOVW $588, R12 + B runtime·callbackasm1(SB) + MOVW $589, R12 + B runtime·callbackasm1(SB) + MOVW $590, R12 + B runtime·callbackasm1(SB) + MOVW $591, R12 + B runtime·callbackasm1(SB) + MOVW $592, R12 + B runtime·callbackasm1(SB) + MOVW $593, R12 + B runtime·callbackasm1(SB) + MOVW $594, R12 + B runtime·callbackasm1(SB) + MOVW $595, R12 + B runtime·callbackasm1(SB) + MOVW $596, R12 + B runtime·callbackasm1(SB) + MOVW $597, R12 + B runtime·callbackasm1(SB) + MOVW $598, R12 + B runtime·callbackasm1(SB) + MOVW $599, R12 + B runtime·callbackasm1(SB) + MOVW $600, R12 + B runtime·callbackasm1(SB) + MOVW $601, R12 + B runtime·callbackasm1(SB) + MOVW $602, R12 + B runtime·callbackasm1(SB) + MOVW $603, R12 + B runtime·callbackasm1(SB) + MOVW $604, R12 + B runtime·callbackasm1(SB) + MOVW $605, R12 + B runtime·callbackasm1(SB) + MOVW $606, R12 + B runtime·callbackasm1(SB) + MOVW $607, R12 + B runtime·callbackasm1(SB) + MOVW $608, R12 + B runtime·callbackasm1(SB) + MOVW $609, R12 + B runtime·callbackasm1(SB) + MOVW $610, R12 + B runtime·callbackasm1(SB) + MOVW $611, R12 + B runtime·callbackasm1(SB) + MOVW $612, R12 + B runtime·callbackasm1(SB) + MOVW $613, R12 + B runtime·callbackasm1(SB) + MOVW $614, R12 + B runtime·callbackasm1(SB) + MOVW $615, R12 + B runtime·callbackasm1(SB) + MOVW $616, R12 + B runtime·callbackasm1(SB) + MOVW $617, R12 + B runtime·callbackasm1(SB) + MOVW $618, R12 + B runtime·callbackasm1(SB) + MOVW $619, R12 + B runtime·callbackasm1(SB) + MOVW $620, R12 + B runtime·callbackasm1(SB) + MOVW $621, R12 + B runtime·callbackasm1(SB) + MOVW $622, R12 + B runtime·callbackasm1(SB) + MOVW $623, R12 + B runtime·callbackasm1(SB) + MOVW $624, R12 + B runtime·callbackasm1(SB) + MOVW $625, R12 + B runtime·callbackasm1(SB) + MOVW $626, R12 + B runtime·callbackasm1(SB) + MOVW $627, R12 + B runtime·callbackasm1(SB) + MOVW $628, R12 + B runtime·callbackasm1(SB) + MOVW $629, R12 + B runtime·callbackasm1(SB) + MOVW $630, R12 + B runtime·callbackasm1(SB) + MOVW $631, R12 + B runtime·callbackasm1(SB) + MOVW $632, R12 + B runtime·callbackasm1(SB) + MOVW $633, R12 + B runtime·callbackasm1(SB) + MOVW $634, R12 + B runtime·callbackasm1(SB) + MOVW $635, R12 + B runtime·callbackasm1(SB) + MOVW $636, R12 + B runtime·callbackasm1(SB) + MOVW $637, R12 + B runtime·callbackasm1(SB) + MOVW $638, R12 + B runtime·callbackasm1(SB) + MOVW $639, R12 + B runtime·callbackasm1(SB) + MOVW $640, R12 + B runtime·callbackasm1(SB) + MOVW $641, R12 + B runtime·callbackasm1(SB) + MOVW $642, R12 + B runtime·callbackasm1(SB) + MOVW $643, R12 + B runtime·callbackasm1(SB) + MOVW $644, R12 + B runtime·callbackasm1(SB) + MOVW $645, R12 + B runtime·callbackasm1(SB) + MOVW $646, R12 + B runtime·callbackasm1(SB) + MOVW $647, R12 + B runtime·callbackasm1(SB) + MOVW $648, R12 + B runtime·callbackasm1(SB) + MOVW $649, R12 + B runtime·callbackasm1(SB) + MOVW $650, R12 + B runtime·callbackasm1(SB) + MOVW $651, R12 + B runtime·callbackasm1(SB) + MOVW $652, R12 + B runtime·callbackasm1(SB) + MOVW $653, R12 + B runtime·callbackasm1(SB) + MOVW $654, R12 + B runtime·callbackasm1(SB) + MOVW $655, R12 + B runtime·callbackasm1(SB) + MOVW $656, R12 + B runtime·callbackasm1(SB) + MOVW $657, R12 + B runtime·callbackasm1(SB) + MOVW $658, R12 + B runtime·callbackasm1(SB) + MOVW $659, R12 + B runtime·callbackasm1(SB) + MOVW $660, R12 + B runtime·callbackasm1(SB) + MOVW $661, R12 + B runtime·callbackasm1(SB) + MOVW $662, R12 + B runtime·callbackasm1(SB) + MOVW $663, R12 + B runtime·callbackasm1(SB) + MOVW $664, R12 + B runtime·callbackasm1(SB) + MOVW $665, R12 + B runtime·callbackasm1(SB) + MOVW $666, R12 + B runtime·callbackasm1(SB) + MOVW $667, R12 + B runtime·callbackasm1(SB) + MOVW $668, R12 + B runtime·callbackasm1(SB) + MOVW $669, R12 + B runtime·callbackasm1(SB) + MOVW $670, R12 + B runtime·callbackasm1(SB) + MOVW $671, R12 + B runtime·callbackasm1(SB) + MOVW $672, R12 + B runtime·callbackasm1(SB) + MOVW $673, R12 + B runtime·callbackasm1(SB) + MOVW $674, R12 + B runtime·callbackasm1(SB) + MOVW $675, R12 + B runtime·callbackasm1(SB) + MOVW $676, R12 + B runtime·callbackasm1(SB) + MOVW $677, R12 + B runtime·callbackasm1(SB) + MOVW $678, R12 + B runtime·callbackasm1(SB) + MOVW $679, R12 + B runtime·callbackasm1(SB) + MOVW $680, R12 + B runtime·callbackasm1(SB) + MOVW $681, R12 + B runtime·callbackasm1(SB) + MOVW $682, R12 + B runtime·callbackasm1(SB) + MOVW $683, R12 + B runtime·callbackasm1(SB) + MOVW $684, R12 + B runtime·callbackasm1(SB) + MOVW $685, R12 + B runtime·callbackasm1(SB) + MOVW $686, R12 + B runtime·callbackasm1(SB) + MOVW $687, R12 + B runtime·callbackasm1(SB) + MOVW $688, R12 + B runtime·callbackasm1(SB) + MOVW $689, R12 + B runtime·callbackasm1(SB) + MOVW $690, R12 + B runtime·callbackasm1(SB) + MOVW $691, R12 + B runtime·callbackasm1(SB) + MOVW $692, R12 + B runtime·callbackasm1(SB) + MOVW $693, R12 + B runtime·callbackasm1(SB) + MOVW $694, R12 + B runtime·callbackasm1(SB) + MOVW $695, R12 + B runtime·callbackasm1(SB) + MOVW $696, R12 + B runtime·callbackasm1(SB) + MOVW $697, R12 + B runtime·callbackasm1(SB) + MOVW $698, R12 + B runtime·callbackasm1(SB) + MOVW $699, R12 + B runtime·callbackasm1(SB) + MOVW $700, R12 + B runtime·callbackasm1(SB) + MOVW $701, R12 + B runtime·callbackasm1(SB) + MOVW $702, R12 + B runtime·callbackasm1(SB) + MOVW $703, R12 + B runtime·callbackasm1(SB) + MOVW $704, R12 + B runtime·callbackasm1(SB) + MOVW $705, R12 + B runtime·callbackasm1(SB) + MOVW $706, R12 + B runtime·callbackasm1(SB) + MOVW $707, R12 + B runtime·callbackasm1(SB) + MOVW $708, R12 + B runtime·callbackasm1(SB) + MOVW $709, R12 + B runtime·callbackasm1(SB) + MOVW $710, R12 + B runtime·callbackasm1(SB) + MOVW $711, R12 + B runtime·callbackasm1(SB) + MOVW $712, R12 + B runtime·callbackasm1(SB) + MOVW $713, R12 + B runtime·callbackasm1(SB) + MOVW $714, R12 + B runtime·callbackasm1(SB) + MOVW $715, R12 + B runtime·callbackasm1(SB) + MOVW $716, R12 + B runtime·callbackasm1(SB) + MOVW $717, R12 + B runtime·callbackasm1(SB) + MOVW $718, R12 + B runtime·callbackasm1(SB) + MOVW $719, R12 + B runtime·callbackasm1(SB) + MOVW $720, R12 + B runtime·callbackasm1(SB) + MOVW $721, R12 + B runtime·callbackasm1(SB) + MOVW $722, R12 + B runtime·callbackasm1(SB) + MOVW $723, R12 + B runtime·callbackasm1(SB) + MOVW $724, R12 + B runtime·callbackasm1(SB) + MOVW $725, R12 + B runtime·callbackasm1(SB) + MOVW $726, R12 + B runtime·callbackasm1(SB) + MOVW $727, R12 + B runtime·callbackasm1(SB) + MOVW $728, R12 + B runtime·callbackasm1(SB) + MOVW $729, R12 + B runtime·callbackasm1(SB) + MOVW $730, R12 + B runtime·callbackasm1(SB) + MOVW $731, R12 + B runtime·callbackasm1(SB) + MOVW $732, R12 + B runtime·callbackasm1(SB) + MOVW $733, R12 + B runtime·callbackasm1(SB) + MOVW $734, R12 + B runtime·callbackasm1(SB) + MOVW $735, R12 + B runtime·callbackasm1(SB) + MOVW $736, R12 + B runtime·callbackasm1(SB) + MOVW $737, R12 + B runtime·callbackasm1(SB) + MOVW $738, R12 + B runtime·callbackasm1(SB) + MOVW $739, R12 + B runtime·callbackasm1(SB) + MOVW $740, R12 + B runtime·callbackasm1(SB) + MOVW $741, R12 + B runtime·callbackasm1(SB) + MOVW $742, R12 + B runtime·callbackasm1(SB) + MOVW $743, R12 + B runtime·callbackasm1(SB) + MOVW $744, R12 + B runtime·callbackasm1(SB) + MOVW $745, R12 + B runtime·callbackasm1(SB) + MOVW $746, R12 + B runtime·callbackasm1(SB) + MOVW $747, R12 + B runtime·callbackasm1(SB) + MOVW $748, R12 + B runtime·callbackasm1(SB) + MOVW $749, R12 + B runtime·callbackasm1(SB) + MOVW $750, R12 + B runtime·callbackasm1(SB) + MOVW $751, R12 + B runtime·callbackasm1(SB) + MOVW $752, R12 + B runtime·callbackasm1(SB) + MOVW $753, R12 + B runtime·callbackasm1(SB) + MOVW $754, R12 + B runtime·callbackasm1(SB) + MOVW $755, R12 + B runtime·callbackasm1(SB) + MOVW $756, R12 + B runtime·callbackasm1(SB) + MOVW $757, R12 + B runtime·callbackasm1(SB) + MOVW $758, R12 + B runtime·callbackasm1(SB) + MOVW $759, R12 + B runtime·callbackasm1(SB) + MOVW $760, R12 + B runtime·callbackasm1(SB) + MOVW $761, R12 + B runtime·callbackasm1(SB) + MOVW $762, R12 + B runtime·callbackasm1(SB) + MOVW $763, R12 + B runtime·callbackasm1(SB) + MOVW $764, R12 + B runtime·callbackasm1(SB) + MOVW $765, R12 + B runtime·callbackasm1(SB) + MOVW $766, R12 + B runtime·callbackasm1(SB) + MOVW $767, R12 + B runtime·callbackasm1(SB) + MOVW $768, R12 + B runtime·callbackasm1(SB) + MOVW $769, R12 + B runtime·callbackasm1(SB) + MOVW $770, R12 + B runtime·callbackasm1(SB) + MOVW $771, R12 + B runtime·callbackasm1(SB) + MOVW $772, R12 + B runtime·callbackasm1(SB) + MOVW $773, R12 + B runtime·callbackasm1(SB) + MOVW $774, R12 + B runtime·callbackasm1(SB) + MOVW $775, R12 + B runtime·callbackasm1(SB) + MOVW $776, R12 + B runtime·callbackasm1(SB) + MOVW $777, R12 + B runtime·callbackasm1(SB) + MOVW $778, R12 + B runtime·callbackasm1(SB) + MOVW $779, R12 + B runtime·callbackasm1(SB) + MOVW $780, R12 + B runtime·callbackasm1(SB) + MOVW $781, R12 + B runtime·callbackasm1(SB) + MOVW $782, R12 + B runtime·callbackasm1(SB) + MOVW $783, R12 + B runtime·callbackasm1(SB) + MOVW $784, R12 + B runtime·callbackasm1(SB) + MOVW $785, R12 + B runtime·callbackasm1(SB) + MOVW $786, R12 + B runtime·callbackasm1(SB) + MOVW $787, R12 + B runtime·callbackasm1(SB) + MOVW $788, R12 + B runtime·callbackasm1(SB) + MOVW $789, R12 + B runtime·callbackasm1(SB) + MOVW $790, R12 + B runtime·callbackasm1(SB) + MOVW $791, R12 + B runtime·callbackasm1(SB) + MOVW $792, R12 + B runtime·callbackasm1(SB) + MOVW $793, R12 + B runtime·callbackasm1(SB) + MOVW $794, R12 + B runtime·callbackasm1(SB) + MOVW $795, R12 + B runtime·callbackasm1(SB) + MOVW $796, R12 + B runtime·callbackasm1(SB) + MOVW $797, R12 + B runtime·callbackasm1(SB) + MOVW $798, R12 + B runtime·callbackasm1(SB) + MOVW $799, R12 + B runtime·callbackasm1(SB) + MOVW $800, R12 + B runtime·callbackasm1(SB) + MOVW $801, R12 + B runtime·callbackasm1(SB) + MOVW $802, R12 + B runtime·callbackasm1(SB) + MOVW $803, R12 + B runtime·callbackasm1(SB) + MOVW $804, R12 + B runtime·callbackasm1(SB) + MOVW $805, R12 + B runtime·callbackasm1(SB) + MOVW $806, R12 + B runtime·callbackasm1(SB) + MOVW $807, R12 + B runtime·callbackasm1(SB) + MOVW $808, R12 + B runtime·callbackasm1(SB) + MOVW $809, R12 + B runtime·callbackasm1(SB) + MOVW $810, R12 + B runtime·callbackasm1(SB) + MOVW $811, R12 + B runtime·callbackasm1(SB) + MOVW $812, R12 + B runtime·callbackasm1(SB) + MOVW $813, R12 + B runtime·callbackasm1(SB) + MOVW $814, R12 + B runtime·callbackasm1(SB) + MOVW $815, R12 + B runtime·callbackasm1(SB) + MOVW $816, R12 + B runtime·callbackasm1(SB) + MOVW $817, R12 + B runtime·callbackasm1(SB) + MOVW $818, R12 + B runtime·callbackasm1(SB) + MOVW $819, R12 + B runtime·callbackasm1(SB) + MOVW $820, R12 + B runtime·callbackasm1(SB) + MOVW $821, R12 + B runtime·callbackasm1(SB) + MOVW $822, R12 + B runtime·callbackasm1(SB) + MOVW $823, R12 + B runtime·callbackasm1(SB) + MOVW $824, R12 + B runtime·callbackasm1(SB) + MOVW $825, R12 + B runtime·callbackasm1(SB) + MOVW $826, R12 + B runtime·callbackasm1(SB) + MOVW $827, R12 + B runtime·callbackasm1(SB) + MOVW $828, R12 + B runtime·callbackasm1(SB) + MOVW $829, R12 + B runtime·callbackasm1(SB) + MOVW $830, R12 + B runtime·callbackasm1(SB) + MOVW $831, R12 + B runtime·callbackasm1(SB) + MOVW $832, R12 + B runtime·callbackasm1(SB) + MOVW $833, R12 + B runtime·callbackasm1(SB) + MOVW $834, R12 + B runtime·callbackasm1(SB) + MOVW $835, R12 + B runtime·callbackasm1(SB) + MOVW $836, R12 + B runtime·callbackasm1(SB) + MOVW $837, R12 + B runtime·callbackasm1(SB) + MOVW $838, R12 + B runtime·callbackasm1(SB) + MOVW $839, R12 + B runtime·callbackasm1(SB) + MOVW $840, R12 + B runtime·callbackasm1(SB) + MOVW $841, R12 + B runtime·callbackasm1(SB) + MOVW $842, R12 + B runtime·callbackasm1(SB) + MOVW $843, R12 + B runtime·callbackasm1(SB) + MOVW $844, R12 + B runtime·callbackasm1(SB) + MOVW $845, R12 + B runtime·callbackasm1(SB) + MOVW $846, R12 + B runtime·callbackasm1(SB) + MOVW $847, R12 + B runtime·callbackasm1(SB) + MOVW $848, R12 + B runtime·callbackasm1(SB) + MOVW $849, R12 + B runtime·callbackasm1(SB) + MOVW $850, R12 + B runtime·callbackasm1(SB) + MOVW $851, R12 + B runtime·callbackasm1(SB) + MOVW $852, R12 + B runtime·callbackasm1(SB) + MOVW $853, R12 + B runtime·callbackasm1(SB) + MOVW $854, R12 + B runtime·callbackasm1(SB) + MOVW $855, R12 + B runtime·callbackasm1(SB) + MOVW $856, R12 + B runtime·callbackasm1(SB) + MOVW $857, R12 + B runtime·callbackasm1(SB) + MOVW $858, R12 + B runtime·callbackasm1(SB) + MOVW $859, R12 + B runtime·callbackasm1(SB) + MOVW $860, R12 + B runtime·callbackasm1(SB) + MOVW $861, R12 + B runtime·callbackasm1(SB) + MOVW $862, R12 + B runtime·callbackasm1(SB) + MOVW $863, R12 + B runtime·callbackasm1(SB) + MOVW $864, R12 + B runtime·callbackasm1(SB) + MOVW $865, R12 + B runtime·callbackasm1(SB) + MOVW $866, R12 + B runtime·callbackasm1(SB) + MOVW $867, R12 + B runtime·callbackasm1(SB) + MOVW $868, R12 + B runtime·callbackasm1(SB) + MOVW $869, R12 + B runtime·callbackasm1(SB) + MOVW $870, R12 + B runtime·callbackasm1(SB) + MOVW $871, R12 + B runtime·callbackasm1(SB) + MOVW $872, R12 + B runtime·callbackasm1(SB) + MOVW $873, R12 + B runtime·callbackasm1(SB) + MOVW $874, R12 + B runtime·callbackasm1(SB) + MOVW $875, R12 + B runtime·callbackasm1(SB) + MOVW $876, R12 + B runtime·callbackasm1(SB) + MOVW $877, R12 + B runtime·callbackasm1(SB) + MOVW $878, R12 + B runtime·callbackasm1(SB) + MOVW $879, R12 + B runtime·callbackasm1(SB) + MOVW $880, R12 + B runtime·callbackasm1(SB) + MOVW $881, R12 + B runtime·callbackasm1(SB) + MOVW $882, R12 + B runtime·callbackasm1(SB) + MOVW $883, R12 + B runtime·callbackasm1(SB) + MOVW $884, R12 + B runtime·callbackasm1(SB) + MOVW $885, R12 + B runtime·callbackasm1(SB) + MOVW $886, R12 + B runtime·callbackasm1(SB) + MOVW $887, R12 + B runtime·callbackasm1(SB) + MOVW $888, R12 + B runtime·callbackasm1(SB) + MOVW $889, R12 + B runtime·callbackasm1(SB) + MOVW $890, R12 + B runtime·callbackasm1(SB) + MOVW $891, R12 + B runtime·callbackasm1(SB) + MOVW $892, R12 + B runtime·callbackasm1(SB) + MOVW $893, R12 + B runtime·callbackasm1(SB) + MOVW $894, R12 + B runtime·callbackasm1(SB) + MOVW $895, R12 + B runtime·callbackasm1(SB) + MOVW $896, R12 + B runtime·callbackasm1(SB) + MOVW $897, R12 + B runtime·callbackasm1(SB) + MOVW $898, R12 + B runtime·callbackasm1(SB) + MOVW $899, R12 + B runtime·callbackasm1(SB) + MOVW $900, R12 + B runtime·callbackasm1(SB) + MOVW $901, R12 + B runtime·callbackasm1(SB) + MOVW $902, R12 + B runtime·callbackasm1(SB) + MOVW $903, R12 + B runtime·callbackasm1(SB) + MOVW $904, R12 + B runtime·callbackasm1(SB) + MOVW $905, R12 + B runtime·callbackasm1(SB) + MOVW $906, R12 + B runtime·callbackasm1(SB) + MOVW $907, R12 + B runtime·callbackasm1(SB) + MOVW $908, R12 + B runtime·callbackasm1(SB) + MOVW $909, R12 + B runtime·callbackasm1(SB) + MOVW $910, R12 + B runtime·callbackasm1(SB) + MOVW $911, R12 + B runtime·callbackasm1(SB) + MOVW $912, R12 + B runtime·callbackasm1(SB) + MOVW $913, R12 + B runtime·callbackasm1(SB) + MOVW $914, R12 + B runtime·callbackasm1(SB) + MOVW $915, R12 + B runtime·callbackasm1(SB) + MOVW $916, R12 + B runtime·callbackasm1(SB) + MOVW $917, R12 + B runtime·callbackasm1(SB) + MOVW $918, R12 + B runtime·callbackasm1(SB) + MOVW $919, R12 + B runtime·callbackasm1(SB) + MOVW $920, R12 + B runtime·callbackasm1(SB) + MOVW $921, R12 + B runtime·callbackasm1(SB) + MOVW $922, R12 + B runtime·callbackasm1(SB) + MOVW $923, R12 + B runtime·callbackasm1(SB) + MOVW $924, R12 + B runtime·callbackasm1(SB) + MOVW $925, R12 + B runtime·callbackasm1(SB) + MOVW $926, R12 + B runtime·callbackasm1(SB) + MOVW $927, R12 + B runtime·callbackasm1(SB) + MOVW $928, R12 + B runtime·callbackasm1(SB) + MOVW $929, R12 + B runtime·callbackasm1(SB) + MOVW $930, R12 + B runtime·callbackasm1(SB) + MOVW $931, R12 + B runtime·callbackasm1(SB) + MOVW $932, R12 + B runtime·callbackasm1(SB) + MOVW $933, R12 + B runtime·callbackasm1(SB) + MOVW $934, R12 + B runtime·callbackasm1(SB) + MOVW $935, R12 + B runtime·callbackasm1(SB) + MOVW $936, R12 + B runtime·callbackasm1(SB) + MOVW $937, R12 + B runtime·callbackasm1(SB) + MOVW $938, R12 + B runtime·callbackasm1(SB) + MOVW $939, R12 + B runtime·callbackasm1(SB) + MOVW $940, R12 + B runtime·callbackasm1(SB) + MOVW $941, R12 + B runtime·callbackasm1(SB) + MOVW $942, R12 + B runtime·callbackasm1(SB) + MOVW $943, R12 + B runtime·callbackasm1(SB) + MOVW $944, R12 + B runtime·callbackasm1(SB) + MOVW $945, R12 + B runtime·callbackasm1(SB) + MOVW $946, R12 + B runtime·callbackasm1(SB) + MOVW $947, R12 + B runtime·callbackasm1(SB) + MOVW $948, R12 + B runtime·callbackasm1(SB) + MOVW $949, R12 + B runtime·callbackasm1(SB) + MOVW $950, R12 + B runtime·callbackasm1(SB) + MOVW $951, R12 + B runtime·callbackasm1(SB) + MOVW $952, R12 + B runtime·callbackasm1(SB) + MOVW $953, R12 + B runtime·callbackasm1(SB) + MOVW $954, R12 + B runtime·callbackasm1(SB) + MOVW $955, R12 + B runtime·callbackasm1(SB) + MOVW $956, R12 + B runtime·callbackasm1(SB) + MOVW $957, R12 + B runtime·callbackasm1(SB) + MOVW $958, R12 + B runtime·callbackasm1(SB) + MOVW $959, R12 + B runtime·callbackasm1(SB) + MOVW $960, R12 + B runtime·callbackasm1(SB) + MOVW $961, R12 + B runtime·callbackasm1(SB) + MOVW $962, R12 + B runtime·callbackasm1(SB) + MOVW $963, R12 + B runtime·callbackasm1(SB) + MOVW $964, R12 + B runtime·callbackasm1(SB) + MOVW $965, R12 + B runtime·callbackasm1(SB) + MOVW $966, R12 + B runtime·callbackasm1(SB) + MOVW $967, R12 + B runtime·callbackasm1(SB) + MOVW $968, R12 + B runtime·callbackasm1(SB) + MOVW $969, R12 + B runtime·callbackasm1(SB) + MOVW $970, R12 + B runtime·callbackasm1(SB) + MOVW $971, R12 + B runtime·callbackasm1(SB) + MOVW $972, R12 + B runtime·callbackasm1(SB) + MOVW $973, R12 + B runtime·callbackasm1(SB) + MOVW $974, R12 + B runtime·callbackasm1(SB) + MOVW $975, R12 + B runtime·callbackasm1(SB) + MOVW $976, R12 + B runtime·callbackasm1(SB) + MOVW $977, R12 + B runtime·callbackasm1(SB) + MOVW $978, R12 + B runtime·callbackasm1(SB) + MOVW $979, R12 + B runtime·callbackasm1(SB) + MOVW $980, R12 + B runtime·callbackasm1(SB) + MOVW $981, R12 + B runtime·callbackasm1(SB) + MOVW $982, R12 + B runtime·callbackasm1(SB) + MOVW $983, R12 + B runtime·callbackasm1(SB) + MOVW $984, R12 + B runtime·callbackasm1(SB) + MOVW $985, R12 + B runtime·callbackasm1(SB) + MOVW $986, R12 + B runtime·callbackasm1(SB) + MOVW $987, R12 + B runtime·callbackasm1(SB) + MOVW $988, R12 + B runtime·callbackasm1(SB) + MOVW $989, R12 + B runtime·callbackasm1(SB) + MOVW $990, R12 + B runtime·callbackasm1(SB) + MOVW $991, R12 + B runtime·callbackasm1(SB) + MOVW $992, R12 + B runtime·callbackasm1(SB) + MOVW $993, R12 + B runtime·callbackasm1(SB) + MOVW $994, R12 + B runtime·callbackasm1(SB) + MOVW $995, R12 + B runtime·callbackasm1(SB) + MOVW $996, R12 + B runtime·callbackasm1(SB) + MOVW $997, R12 + B runtime·callbackasm1(SB) + MOVW $998, R12 + B runtime·callbackasm1(SB) + MOVW $999, R12 + B runtime·callbackasm1(SB) + MOVW $1000, R12 + B runtime·callbackasm1(SB) + MOVW $1001, R12 + B runtime·callbackasm1(SB) + MOVW $1002, R12 + B runtime·callbackasm1(SB) + MOVW $1003, R12 + B runtime·callbackasm1(SB) + MOVW $1004, R12 + B runtime·callbackasm1(SB) + MOVW $1005, R12 + B runtime·callbackasm1(SB) + MOVW $1006, R12 + B runtime·callbackasm1(SB) + MOVW $1007, R12 + B runtime·callbackasm1(SB) + MOVW $1008, R12 + B runtime·callbackasm1(SB) + MOVW $1009, R12 + B runtime·callbackasm1(SB) + MOVW $1010, R12 + B runtime·callbackasm1(SB) + MOVW $1011, R12 + B runtime·callbackasm1(SB) + MOVW $1012, R12 + B runtime·callbackasm1(SB) + MOVW $1013, R12 + B runtime·callbackasm1(SB) + MOVW $1014, R12 + B runtime·callbackasm1(SB) + MOVW $1015, R12 + B runtime·callbackasm1(SB) + MOVW $1016, R12 + B runtime·callbackasm1(SB) + MOVW $1017, R12 + B runtime·callbackasm1(SB) + MOVW $1018, R12 + B runtime·callbackasm1(SB) + MOVW $1019, R12 + B runtime·callbackasm1(SB) + MOVW $1020, R12 + B runtime·callbackasm1(SB) + MOVW $1021, R12 + B runtime·callbackasm1(SB) + MOVW $1022, R12 + B runtime·callbackasm1(SB) + MOVW $1023, R12 + B runtime·callbackasm1(SB) + MOVW $1024, R12 + B runtime·callbackasm1(SB) + MOVW $1025, R12 + B runtime·callbackasm1(SB) + MOVW $1026, R12 + B runtime·callbackasm1(SB) + MOVW $1027, R12 + B runtime·callbackasm1(SB) + MOVW $1028, R12 + B runtime·callbackasm1(SB) + MOVW $1029, R12 + B runtime·callbackasm1(SB) + MOVW $1030, R12 + B runtime·callbackasm1(SB) + MOVW $1031, R12 + B runtime·callbackasm1(SB) + MOVW $1032, R12 + B runtime·callbackasm1(SB) + MOVW $1033, R12 + B runtime·callbackasm1(SB) + MOVW $1034, R12 + B runtime·callbackasm1(SB) + MOVW $1035, R12 + B runtime·callbackasm1(SB) + MOVW $1036, R12 + B runtime·callbackasm1(SB) + MOVW $1037, R12 + B runtime·callbackasm1(SB) + MOVW $1038, R12 + B runtime·callbackasm1(SB) + MOVW $1039, R12 + B runtime·callbackasm1(SB) + MOVW $1040, R12 + B runtime·callbackasm1(SB) + MOVW $1041, R12 + B runtime·callbackasm1(SB) + MOVW $1042, R12 + B runtime·callbackasm1(SB) + MOVW $1043, R12 + B runtime·callbackasm1(SB) + MOVW $1044, R12 + B runtime·callbackasm1(SB) + MOVW $1045, R12 + B runtime·callbackasm1(SB) + MOVW $1046, R12 + B runtime·callbackasm1(SB) + MOVW $1047, R12 + B runtime·callbackasm1(SB) + MOVW $1048, R12 + B runtime·callbackasm1(SB) + MOVW $1049, R12 + B runtime·callbackasm1(SB) + MOVW $1050, R12 + B runtime·callbackasm1(SB) + MOVW $1051, R12 + B runtime·callbackasm1(SB) + MOVW $1052, R12 + B runtime·callbackasm1(SB) + MOVW $1053, R12 + B runtime·callbackasm1(SB) + MOVW $1054, R12 + B runtime·callbackasm1(SB) + MOVW $1055, R12 + B runtime·callbackasm1(SB) + MOVW $1056, R12 + B runtime·callbackasm1(SB) + MOVW $1057, R12 + B runtime·callbackasm1(SB) + MOVW $1058, R12 + B runtime·callbackasm1(SB) + MOVW $1059, R12 + B runtime·callbackasm1(SB) + MOVW $1060, R12 + B runtime·callbackasm1(SB) + MOVW $1061, R12 + B runtime·callbackasm1(SB) + MOVW $1062, R12 + B runtime·callbackasm1(SB) + MOVW $1063, R12 + B runtime·callbackasm1(SB) + MOVW $1064, R12 + B runtime·callbackasm1(SB) + MOVW $1065, R12 + B runtime·callbackasm1(SB) + MOVW $1066, R12 + B runtime·callbackasm1(SB) + MOVW $1067, R12 + B runtime·callbackasm1(SB) + MOVW $1068, R12 + B runtime·callbackasm1(SB) + MOVW $1069, R12 + B runtime·callbackasm1(SB) + MOVW $1070, R12 + B runtime·callbackasm1(SB) + MOVW $1071, R12 + B runtime·callbackasm1(SB) + MOVW $1072, R12 + B runtime·callbackasm1(SB) + MOVW $1073, R12 + B runtime·callbackasm1(SB) + MOVW $1074, R12 + B runtime·callbackasm1(SB) + MOVW $1075, R12 + B runtime·callbackasm1(SB) + MOVW $1076, R12 + B runtime·callbackasm1(SB) + MOVW $1077, R12 + B runtime·callbackasm1(SB) + MOVW $1078, R12 + B runtime·callbackasm1(SB) + MOVW $1079, R12 + B runtime·callbackasm1(SB) + MOVW $1080, R12 + B runtime·callbackasm1(SB) + MOVW $1081, R12 + B runtime·callbackasm1(SB) + MOVW $1082, R12 + B runtime·callbackasm1(SB) + MOVW $1083, R12 + B runtime·callbackasm1(SB) + MOVW $1084, R12 + B runtime·callbackasm1(SB) + MOVW $1085, R12 + B runtime·callbackasm1(SB) + MOVW $1086, R12 + B runtime·callbackasm1(SB) + MOVW $1087, R12 + B runtime·callbackasm1(SB) + MOVW $1088, R12 + B runtime·callbackasm1(SB) + MOVW $1089, R12 + B runtime·callbackasm1(SB) + MOVW $1090, R12 + B runtime·callbackasm1(SB) + MOVW $1091, R12 + B runtime·callbackasm1(SB) + MOVW $1092, R12 + B runtime·callbackasm1(SB) + MOVW $1093, R12 + B runtime·callbackasm1(SB) + MOVW $1094, R12 + B runtime·callbackasm1(SB) + MOVW $1095, R12 + B runtime·callbackasm1(SB) + MOVW $1096, R12 + B runtime·callbackasm1(SB) + MOVW $1097, R12 + B runtime·callbackasm1(SB) + MOVW $1098, R12 + B runtime·callbackasm1(SB) + MOVW $1099, R12 + B runtime·callbackasm1(SB) + MOVW $1100, R12 + B runtime·callbackasm1(SB) + MOVW $1101, R12 + B runtime·callbackasm1(SB) + MOVW $1102, R12 + B runtime·callbackasm1(SB) + MOVW $1103, R12 + B runtime·callbackasm1(SB) + MOVW $1104, R12 + B runtime·callbackasm1(SB) + MOVW $1105, R12 + B runtime·callbackasm1(SB) + MOVW $1106, R12 + B runtime·callbackasm1(SB) + MOVW $1107, R12 + B runtime·callbackasm1(SB) + MOVW $1108, R12 + B runtime·callbackasm1(SB) + MOVW $1109, R12 + B runtime·callbackasm1(SB) + MOVW $1110, R12 + B runtime·callbackasm1(SB) + MOVW $1111, R12 + B runtime·callbackasm1(SB) + MOVW $1112, R12 + B runtime·callbackasm1(SB) + MOVW $1113, R12 + B runtime·callbackasm1(SB) + MOVW $1114, R12 + B runtime·callbackasm1(SB) + MOVW $1115, R12 + B runtime·callbackasm1(SB) + MOVW $1116, R12 + B runtime·callbackasm1(SB) + MOVW $1117, R12 + B runtime·callbackasm1(SB) + MOVW $1118, R12 + B runtime·callbackasm1(SB) + MOVW $1119, R12 + B runtime·callbackasm1(SB) + MOVW $1120, R12 + B runtime·callbackasm1(SB) + MOVW $1121, R12 + B runtime·callbackasm1(SB) + MOVW $1122, R12 + B runtime·callbackasm1(SB) + MOVW $1123, R12 + B runtime·callbackasm1(SB) + MOVW $1124, R12 + B runtime·callbackasm1(SB) + MOVW $1125, R12 + B runtime·callbackasm1(SB) + MOVW $1126, R12 + B runtime·callbackasm1(SB) + MOVW $1127, R12 + B runtime·callbackasm1(SB) + MOVW $1128, R12 + B runtime·callbackasm1(SB) + MOVW $1129, R12 + B runtime·callbackasm1(SB) + MOVW $1130, R12 + B runtime·callbackasm1(SB) + MOVW $1131, R12 + B runtime·callbackasm1(SB) + MOVW $1132, R12 + B runtime·callbackasm1(SB) + MOVW $1133, R12 + B runtime·callbackasm1(SB) + MOVW $1134, R12 + B runtime·callbackasm1(SB) + MOVW $1135, R12 + B runtime·callbackasm1(SB) + MOVW $1136, R12 + B runtime·callbackasm1(SB) + MOVW $1137, R12 + B runtime·callbackasm1(SB) + MOVW $1138, R12 + B runtime·callbackasm1(SB) + MOVW $1139, R12 + B runtime·callbackasm1(SB) + MOVW $1140, R12 + B runtime·callbackasm1(SB) + MOVW $1141, R12 + B runtime·callbackasm1(SB) + MOVW $1142, R12 + B runtime·callbackasm1(SB) + MOVW $1143, R12 + B runtime·callbackasm1(SB) + MOVW $1144, R12 + B runtime·callbackasm1(SB) + MOVW $1145, R12 + B runtime·callbackasm1(SB) + MOVW $1146, R12 + B runtime·callbackasm1(SB) + MOVW $1147, R12 + B runtime·callbackasm1(SB) + MOVW $1148, R12 + B runtime·callbackasm1(SB) + MOVW $1149, R12 + B runtime·callbackasm1(SB) + MOVW $1150, R12 + B runtime·callbackasm1(SB) + MOVW $1151, R12 + B runtime·callbackasm1(SB) + MOVW $1152, R12 + B runtime·callbackasm1(SB) + MOVW $1153, R12 + B runtime·callbackasm1(SB) + MOVW $1154, R12 + B runtime·callbackasm1(SB) + MOVW $1155, R12 + B runtime·callbackasm1(SB) + MOVW $1156, R12 + B runtime·callbackasm1(SB) + MOVW $1157, R12 + B runtime·callbackasm1(SB) + MOVW $1158, R12 + B runtime·callbackasm1(SB) + MOVW $1159, R12 + B runtime·callbackasm1(SB) + MOVW $1160, R12 + B runtime·callbackasm1(SB) + MOVW $1161, R12 + B runtime·callbackasm1(SB) + MOVW $1162, R12 + B runtime·callbackasm1(SB) + MOVW $1163, R12 + B runtime·callbackasm1(SB) + MOVW $1164, R12 + B runtime·callbackasm1(SB) + MOVW $1165, R12 + B runtime·callbackasm1(SB) + MOVW $1166, R12 + B runtime·callbackasm1(SB) + MOVW $1167, R12 + B runtime·callbackasm1(SB) + MOVW $1168, R12 + B runtime·callbackasm1(SB) + MOVW $1169, R12 + B runtime·callbackasm1(SB) + MOVW $1170, R12 + B runtime·callbackasm1(SB) + MOVW $1171, R12 + B runtime·callbackasm1(SB) + MOVW $1172, R12 + B runtime·callbackasm1(SB) + MOVW $1173, R12 + B runtime·callbackasm1(SB) + MOVW $1174, R12 + B runtime·callbackasm1(SB) + MOVW $1175, R12 + B runtime·callbackasm1(SB) + MOVW $1176, R12 + B runtime·callbackasm1(SB) + MOVW $1177, R12 + B runtime·callbackasm1(SB) + MOVW $1178, R12 + B runtime·callbackasm1(SB) + MOVW $1179, R12 + B runtime·callbackasm1(SB) + MOVW $1180, R12 + B runtime·callbackasm1(SB) + MOVW $1181, R12 + B runtime·callbackasm1(SB) + MOVW $1182, R12 + B runtime·callbackasm1(SB) + MOVW $1183, R12 + B runtime·callbackasm1(SB) + MOVW $1184, R12 + B runtime·callbackasm1(SB) + MOVW $1185, R12 + B runtime·callbackasm1(SB) + MOVW $1186, R12 + B runtime·callbackasm1(SB) + MOVW $1187, R12 + B runtime·callbackasm1(SB) + MOVW $1188, R12 + B runtime·callbackasm1(SB) + MOVW $1189, R12 + B runtime·callbackasm1(SB) + MOVW $1190, R12 + B runtime·callbackasm1(SB) + MOVW $1191, R12 + B runtime·callbackasm1(SB) + MOVW $1192, R12 + B runtime·callbackasm1(SB) + MOVW $1193, R12 + B runtime·callbackasm1(SB) + MOVW $1194, R12 + B runtime·callbackasm1(SB) + MOVW $1195, R12 + B runtime·callbackasm1(SB) + MOVW $1196, R12 + B runtime·callbackasm1(SB) + MOVW $1197, R12 + B runtime·callbackasm1(SB) + MOVW $1198, R12 + B runtime·callbackasm1(SB) + MOVW $1199, R12 + B runtime·callbackasm1(SB) + MOVW $1200, R12 + B runtime·callbackasm1(SB) + MOVW $1201, R12 + B runtime·callbackasm1(SB) + MOVW $1202, R12 + B runtime·callbackasm1(SB) + MOVW $1203, R12 + B runtime·callbackasm1(SB) + MOVW $1204, R12 + B runtime·callbackasm1(SB) + MOVW $1205, R12 + B runtime·callbackasm1(SB) + MOVW $1206, R12 + B runtime·callbackasm1(SB) + MOVW $1207, R12 + B runtime·callbackasm1(SB) + MOVW $1208, R12 + B runtime·callbackasm1(SB) + MOVW $1209, R12 + B runtime·callbackasm1(SB) + MOVW $1210, R12 + B runtime·callbackasm1(SB) + MOVW $1211, R12 + B runtime·callbackasm1(SB) + MOVW $1212, R12 + B runtime·callbackasm1(SB) + MOVW $1213, R12 + B runtime·callbackasm1(SB) + MOVW $1214, R12 + B runtime·callbackasm1(SB) + MOVW $1215, R12 + B runtime·callbackasm1(SB) + MOVW $1216, R12 + B runtime·callbackasm1(SB) + MOVW $1217, R12 + B runtime·callbackasm1(SB) + MOVW $1218, R12 + B runtime·callbackasm1(SB) + MOVW $1219, R12 + B runtime·callbackasm1(SB) + MOVW $1220, R12 + B runtime·callbackasm1(SB) + MOVW $1221, R12 + B runtime·callbackasm1(SB) + MOVW $1222, R12 + B runtime·callbackasm1(SB) + MOVW $1223, R12 + B runtime·callbackasm1(SB) + MOVW $1224, R12 + B runtime·callbackasm1(SB) + MOVW $1225, R12 + B runtime·callbackasm1(SB) + MOVW $1226, R12 + B runtime·callbackasm1(SB) + MOVW $1227, R12 + B runtime·callbackasm1(SB) + MOVW $1228, R12 + B runtime·callbackasm1(SB) + MOVW $1229, R12 + B runtime·callbackasm1(SB) + MOVW $1230, R12 + B runtime·callbackasm1(SB) + MOVW $1231, R12 + B runtime·callbackasm1(SB) + MOVW $1232, R12 + B runtime·callbackasm1(SB) + MOVW $1233, R12 + B runtime·callbackasm1(SB) + MOVW $1234, R12 + B runtime·callbackasm1(SB) + MOVW $1235, R12 + B runtime·callbackasm1(SB) + MOVW $1236, R12 + B runtime·callbackasm1(SB) + MOVW $1237, R12 + B runtime·callbackasm1(SB) + MOVW $1238, R12 + B runtime·callbackasm1(SB) + MOVW $1239, R12 + B runtime·callbackasm1(SB) + MOVW $1240, R12 + B runtime·callbackasm1(SB) + MOVW $1241, R12 + B runtime·callbackasm1(SB) + MOVW $1242, R12 + B runtime·callbackasm1(SB) + MOVW $1243, R12 + B runtime·callbackasm1(SB) + MOVW $1244, R12 + B runtime·callbackasm1(SB) + MOVW $1245, R12 + B runtime·callbackasm1(SB) + MOVW $1246, R12 + B runtime·callbackasm1(SB) + MOVW $1247, R12 + B runtime·callbackasm1(SB) + MOVW $1248, R12 + B runtime·callbackasm1(SB) + MOVW $1249, R12 + B runtime·callbackasm1(SB) + MOVW $1250, R12 + B runtime·callbackasm1(SB) + MOVW $1251, R12 + B runtime·callbackasm1(SB) + MOVW $1252, R12 + B runtime·callbackasm1(SB) + MOVW $1253, R12 + B runtime·callbackasm1(SB) + MOVW $1254, R12 + B runtime·callbackasm1(SB) + MOVW $1255, R12 + B runtime·callbackasm1(SB) + MOVW $1256, R12 + B runtime·callbackasm1(SB) + MOVW $1257, R12 + B runtime·callbackasm1(SB) + MOVW $1258, R12 + B runtime·callbackasm1(SB) + MOVW $1259, R12 + B runtime·callbackasm1(SB) + MOVW $1260, R12 + B runtime·callbackasm1(SB) + MOVW $1261, R12 + B runtime·callbackasm1(SB) + MOVW $1262, R12 + B runtime·callbackasm1(SB) + MOVW $1263, R12 + B runtime·callbackasm1(SB) + MOVW $1264, R12 + B runtime·callbackasm1(SB) + MOVW $1265, R12 + B runtime·callbackasm1(SB) + MOVW $1266, R12 + B runtime·callbackasm1(SB) + MOVW $1267, R12 + B runtime·callbackasm1(SB) + MOVW $1268, R12 + B runtime·callbackasm1(SB) + MOVW $1269, R12 + B runtime·callbackasm1(SB) + MOVW $1270, R12 + B runtime·callbackasm1(SB) + MOVW $1271, R12 + B runtime·callbackasm1(SB) + MOVW $1272, R12 + B runtime·callbackasm1(SB) + MOVW $1273, R12 + B runtime·callbackasm1(SB) + MOVW $1274, R12 + B runtime·callbackasm1(SB) + MOVW $1275, R12 + B runtime·callbackasm1(SB) + MOVW $1276, R12 + B runtime·callbackasm1(SB) + MOVW $1277, R12 + B runtime·callbackasm1(SB) + MOVW $1278, R12 + B runtime·callbackasm1(SB) + MOVW $1279, R12 + B runtime·callbackasm1(SB) + MOVW $1280, R12 + B runtime·callbackasm1(SB) + MOVW $1281, R12 + B runtime·callbackasm1(SB) + MOVW $1282, R12 + B runtime·callbackasm1(SB) + MOVW $1283, R12 + B runtime·callbackasm1(SB) + MOVW $1284, R12 + B runtime·callbackasm1(SB) + MOVW $1285, R12 + B runtime·callbackasm1(SB) + MOVW $1286, R12 + B runtime·callbackasm1(SB) + MOVW $1287, R12 + B runtime·callbackasm1(SB) + MOVW $1288, R12 + B runtime·callbackasm1(SB) + MOVW $1289, R12 + B runtime·callbackasm1(SB) + MOVW $1290, R12 + B runtime·callbackasm1(SB) + MOVW $1291, R12 + B runtime·callbackasm1(SB) + MOVW $1292, R12 + B runtime·callbackasm1(SB) + MOVW $1293, R12 + B runtime·callbackasm1(SB) + MOVW $1294, R12 + B runtime·callbackasm1(SB) + MOVW $1295, R12 + B runtime·callbackasm1(SB) + MOVW $1296, R12 + B runtime·callbackasm1(SB) + MOVW $1297, R12 + B runtime·callbackasm1(SB) + MOVW $1298, R12 + B runtime·callbackasm1(SB) + MOVW $1299, R12 + B runtime·callbackasm1(SB) + MOVW $1300, R12 + B runtime·callbackasm1(SB) + MOVW $1301, R12 + B runtime·callbackasm1(SB) + MOVW $1302, R12 + B runtime·callbackasm1(SB) + MOVW $1303, R12 + B runtime·callbackasm1(SB) + MOVW $1304, R12 + B runtime·callbackasm1(SB) + MOVW $1305, R12 + B runtime·callbackasm1(SB) + MOVW $1306, R12 + B runtime·callbackasm1(SB) + MOVW $1307, R12 + B runtime·callbackasm1(SB) + MOVW $1308, R12 + B runtime·callbackasm1(SB) + MOVW $1309, R12 + B runtime·callbackasm1(SB) + MOVW $1310, R12 + B runtime·callbackasm1(SB) + MOVW $1311, R12 + B runtime·callbackasm1(SB) + MOVW $1312, R12 + B runtime·callbackasm1(SB) + MOVW $1313, R12 + B runtime·callbackasm1(SB) + MOVW $1314, R12 + B runtime·callbackasm1(SB) + MOVW $1315, R12 + B runtime·callbackasm1(SB) + MOVW $1316, R12 + B runtime·callbackasm1(SB) + MOVW $1317, R12 + B runtime·callbackasm1(SB) + MOVW $1318, R12 + B runtime·callbackasm1(SB) + MOVW $1319, R12 + B runtime·callbackasm1(SB) + MOVW $1320, R12 + B runtime·callbackasm1(SB) + MOVW $1321, R12 + B runtime·callbackasm1(SB) + MOVW $1322, R12 + B runtime·callbackasm1(SB) + MOVW $1323, R12 + B runtime·callbackasm1(SB) + MOVW $1324, R12 + B runtime·callbackasm1(SB) + MOVW $1325, R12 + B runtime·callbackasm1(SB) + MOVW $1326, R12 + B runtime·callbackasm1(SB) + MOVW $1327, R12 + B runtime·callbackasm1(SB) + MOVW $1328, R12 + B runtime·callbackasm1(SB) + MOVW $1329, R12 + B runtime·callbackasm1(SB) + MOVW $1330, R12 + B runtime·callbackasm1(SB) + MOVW $1331, R12 + B runtime·callbackasm1(SB) + MOVW $1332, R12 + B runtime·callbackasm1(SB) + MOVW $1333, R12 + B runtime·callbackasm1(SB) + MOVW $1334, R12 + B runtime·callbackasm1(SB) + MOVW $1335, R12 + B runtime·callbackasm1(SB) + MOVW $1336, R12 + B runtime·callbackasm1(SB) + MOVW $1337, R12 + B runtime·callbackasm1(SB) + MOVW $1338, R12 + B runtime·callbackasm1(SB) + MOVW $1339, R12 + B runtime·callbackasm1(SB) + MOVW $1340, R12 + B runtime·callbackasm1(SB) + MOVW $1341, R12 + B runtime·callbackasm1(SB) + MOVW $1342, R12 + B runtime·callbackasm1(SB) + MOVW $1343, R12 + B runtime·callbackasm1(SB) + MOVW $1344, R12 + B runtime·callbackasm1(SB) + MOVW $1345, R12 + B runtime·callbackasm1(SB) + MOVW $1346, R12 + B runtime·callbackasm1(SB) + MOVW $1347, R12 + B runtime·callbackasm1(SB) + MOVW $1348, R12 + B runtime·callbackasm1(SB) + MOVW $1349, R12 + B runtime·callbackasm1(SB) + MOVW $1350, R12 + B runtime·callbackasm1(SB) + MOVW $1351, R12 + B runtime·callbackasm1(SB) + MOVW $1352, R12 + B runtime·callbackasm1(SB) + MOVW $1353, R12 + B runtime·callbackasm1(SB) + MOVW $1354, R12 + B runtime·callbackasm1(SB) + MOVW $1355, R12 + B runtime·callbackasm1(SB) + MOVW $1356, R12 + B runtime·callbackasm1(SB) + MOVW $1357, R12 + B runtime·callbackasm1(SB) + MOVW $1358, R12 + B runtime·callbackasm1(SB) + MOVW $1359, R12 + B runtime·callbackasm1(SB) + MOVW $1360, R12 + B runtime·callbackasm1(SB) + MOVW $1361, R12 + B runtime·callbackasm1(SB) + MOVW $1362, R12 + B runtime·callbackasm1(SB) + MOVW $1363, R12 + B runtime·callbackasm1(SB) + MOVW $1364, R12 + B runtime·callbackasm1(SB) + MOVW $1365, R12 + B runtime·callbackasm1(SB) + MOVW $1366, R12 + B runtime·callbackasm1(SB) + MOVW $1367, R12 + B runtime·callbackasm1(SB) + MOVW $1368, R12 + B runtime·callbackasm1(SB) + MOVW $1369, R12 + B runtime·callbackasm1(SB) + MOVW $1370, R12 + B runtime·callbackasm1(SB) + MOVW $1371, R12 + B runtime·callbackasm1(SB) + MOVW $1372, R12 + B runtime·callbackasm1(SB) + MOVW $1373, R12 + B runtime·callbackasm1(SB) + MOVW $1374, R12 + B runtime·callbackasm1(SB) + MOVW $1375, R12 + B runtime·callbackasm1(SB) + MOVW $1376, R12 + B runtime·callbackasm1(SB) + MOVW $1377, R12 + B runtime·callbackasm1(SB) + MOVW $1378, R12 + B runtime·callbackasm1(SB) + MOVW $1379, R12 + B runtime·callbackasm1(SB) + MOVW $1380, R12 + B runtime·callbackasm1(SB) + MOVW $1381, R12 + B runtime·callbackasm1(SB) + MOVW $1382, R12 + B runtime·callbackasm1(SB) + MOVW $1383, R12 + B runtime·callbackasm1(SB) + MOVW $1384, R12 + B runtime·callbackasm1(SB) + MOVW $1385, R12 + B runtime·callbackasm1(SB) + MOVW $1386, R12 + B runtime·callbackasm1(SB) + MOVW $1387, R12 + B runtime·callbackasm1(SB) + MOVW $1388, R12 + B runtime·callbackasm1(SB) + MOVW $1389, R12 + B runtime·callbackasm1(SB) + MOVW $1390, R12 + B runtime·callbackasm1(SB) + MOVW $1391, R12 + B runtime·callbackasm1(SB) + MOVW $1392, R12 + B runtime·callbackasm1(SB) + MOVW $1393, R12 + B runtime·callbackasm1(SB) + MOVW $1394, R12 + B runtime·callbackasm1(SB) + MOVW $1395, R12 + B runtime·callbackasm1(SB) + MOVW $1396, R12 + B runtime·callbackasm1(SB) + MOVW $1397, R12 + B runtime·callbackasm1(SB) + MOVW $1398, R12 + B runtime·callbackasm1(SB) + MOVW $1399, R12 + B runtime·callbackasm1(SB) + MOVW $1400, R12 + B runtime·callbackasm1(SB) + MOVW $1401, R12 + B runtime·callbackasm1(SB) + MOVW $1402, R12 + B runtime·callbackasm1(SB) + MOVW $1403, R12 + B runtime·callbackasm1(SB) + MOVW $1404, R12 + B runtime·callbackasm1(SB) + MOVW $1405, R12 + B runtime·callbackasm1(SB) + MOVW $1406, R12 + B runtime·callbackasm1(SB) + MOVW $1407, R12 + B runtime·callbackasm1(SB) + MOVW $1408, R12 + B runtime·callbackasm1(SB) + MOVW $1409, R12 + B runtime·callbackasm1(SB) + MOVW $1410, R12 + B runtime·callbackasm1(SB) + MOVW $1411, R12 + B runtime·callbackasm1(SB) + MOVW $1412, R12 + B runtime·callbackasm1(SB) + MOVW $1413, R12 + B runtime·callbackasm1(SB) + MOVW $1414, R12 + B runtime·callbackasm1(SB) + MOVW $1415, R12 + B runtime·callbackasm1(SB) + MOVW $1416, R12 + B runtime·callbackasm1(SB) + MOVW $1417, R12 + B runtime·callbackasm1(SB) + MOVW $1418, R12 + B runtime·callbackasm1(SB) + MOVW $1419, R12 + B runtime·callbackasm1(SB) + MOVW $1420, R12 + B runtime·callbackasm1(SB) + MOVW $1421, R12 + B runtime·callbackasm1(SB) + MOVW $1422, R12 + B runtime·callbackasm1(SB) + MOVW $1423, R12 + B runtime·callbackasm1(SB) + MOVW $1424, R12 + B runtime·callbackasm1(SB) + MOVW $1425, R12 + B runtime·callbackasm1(SB) + MOVW $1426, R12 + B runtime·callbackasm1(SB) + MOVW $1427, R12 + B runtime·callbackasm1(SB) + MOVW $1428, R12 + B runtime·callbackasm1(SB) + MOVW $1429, R12 + B runtime·callbackasm1(SB) + MOVW $1430, R12 + B runtime·callbackasm1(SB) + MOVW $1431, R12 + B runtime·callbackasm1(SB) + MOVW $1432, R12 + B runtime·callbackasm1(SB) + MOVW $1433, R12 + B runtime·callbackasm1(SB) + MOVW $1434, R12 + B runtime·callbackasm1(SB) + MOVW $1435, R12 + B runtime·callbackasm1(SB) + MOVW $1436, R12 + B runtime·callbackasm1(SB) + MOVW $1437, R12 + B runtime·callbackasm1(SB) + MOVW $1438, R12 + B runtime·callbackasm1(SB) + MOVW $1439, R12 + B runtime·callbackasm1(SB) + MOVW $1440, R12 + B runtime·callbackasm1(SB) + MOVW $1441, R12 + B runtime·callbackasm1(SB) + MOVW $1442, R12 + B runtime·callbackasm1(SB) + MOVW $1443, R12 + B runtime·callbackasm1(SB) + MOVW $1444, R12 + B runtime·callbackasm1(SB) + MOVW $1445, R12 + B runtime·callbackasm1(SB) + MOVW $1446, R12 + B runtime·callbackasm1(SB) + MOVW $1447, R12 + B runtime·callbackasm1(SB) + MOVW $1448, R12 + B runtime·callbackasm1(SB) + MOVW $1449, R12 + B runtime·callbackasm1(SB) + MOVW $1450, R12 + B runtime·callbackasm1(SB) + MOVW $1451, R12 + B runtime·callbackasm1(SB) + MOVW $1452, R12 + B runtime·callbackasm1(SB) + MOVW $1453, R12 + B runtime·callbackasm1(SB) + MOVW $1454, R12 + B runtime·callbackasm1(SB) + MOVW $1455, R12 + B runtime·callbackasm1(SB) + MOVW $1456, R12 + B runtime·callbackasm1(SB) + MOVW $1457, R12 + B runtime·callbackasm1(SB) + MOVW $1458, R12 + B runtime·callbackasm1(SB) + MOVW $1459, R12 + B runtime·callbackasm1(SB) + MOVW $1460, R12 + B runtime·callbackasm1(SB) + MOVW $1461, R12 + B runtime·callbackasm1(SB) + MOVW $1462, R12 + B runtime·callbackasm1(SB) + MOVW $1463, R12 + B runtime·callbackasm1(SB) + MOVW $1464, R12 + B runtime·callbackasm1(SB) + MOVW $1465, R12 + B runtime·callbackasm1(SB) + MOVW $1466, R12 + B runtime·callbackasm1(SB) + MOVW $1467, R12 + B runtime·callbackasm1(SB) + MOVW $1468, R12 + B runtime·callbackasm1(SB) + MOVW $1469, R12 + B runtime·callbackasm1(SB) + MOVW $1470, R12 + B runtime·callbackasm1(SB) + MOVW $1471, R12 + B runtime·callbackasm1(SB) + MOVW $1472, R12 + B runtime·callbackasm1(SB) + MOVW $1473, R12 + B runtime·callbackasm1(SB) + MOVW $1474, R12 + B runtime·callbackasm1(SB) + MOVW $1475, R12 + B runtime·callbackasm1(SB) + MOVW $1476, R12 + B runtime·callbackasm1(SB) + MOVW $1477, R12 + B runtime·callbackasm1(SB) + MOVW $1478, R12 + B runtime·callbackasm1(SB) + MOVW $1479, R12 + B runtime·callbackasm1(SB) + MOVW $1480, R12 + B runtime·callbackasm1(SB) + MOVW $1481, R12 + B runtime·callbackasm1(SB) + MOVW $1482, R12 + B runtime·callbackasm1(SB) + MOVW $1483, R12 + B runtime·callbackasm1(SB) + MOVW $1484, R12 + B runtime·callbackasm1(SB) + MOVW $1485, R12 + B runtime·callbackasm1(SB) + MOVW $1486, R12 + B runtime·callbackasm1(SB) + MOVW $1487, R12 + B runtime·callbackasm1(SB) + MOVW $1488, R12 + B runtime·callbackasm1(SB) + MOVW $1489, R12 + B runtime·callbackasm1(SB) + MOVW $1490, R12 + B runtime·callbackasm1(SB) + MOVW $1491, R12 + B runtime·callbackasm1(SB) + MOVW $1492, R12 + B runtime·callbackasm1(SB) + MOVW $1493, R12 + B runtime·callbackasm1(SB) + MOVW $1494, R12 + B runtime·callbackasm1(SB) + MOVW $1495, R12 + B runtime·callbackasm1(SB) + MOVW $1496, R12 + B runtime·callbackasm1(SB) + MOVW $1497, R12 + B runtime·callbackasm1(SB) + MOVW $1498, R12 + B runtime·callbackasm1(SB) + MOVW $1499, R12 + B runtime·callbackasm1(SB) + MOVW $1500, R12 + B runtime·callbackasm1(SB) + MOVW $1501, R12 + B runtime·callbackasm1(SB) + MOVW $1502, R12 + B runtime·callbackasm1(SB) + MOVW $1503, R12 + B runtime·callbackasm1(SB) + MOVW $1504, R12 + B runtime·callbackasm1(SB) + MOVW $1505, R12 + B runtime·callbackasm1(SB) + MOVW $1506, R12 + B runtime·callbackasm1(SB) + MOVW $1507, R12 + B runtime·callbackasm1(SB) + MOVW $1508, R12 + B runtime·callbackasm1(SB) + MOVW $1509, R12 + B runtime·callbackasm1(SB) + MOVW $1510, R12 + B runtime·callbackasm1(SB) + MOVW $1511, R12 + B runtime·callbackasm1(SB) + MOVW $1512, R12 + B runtime·callbackasm1(SB) + MOVW $1513, R12 + B runtime·callbackasm1(SB) + MOVW $1514, R12 + B runtime·callbackasm1(SB) + MOVW $1515, R12 + B runtime·callbackasm1(SB) + MOVW $1516, R12 + B runtime·callbackasm1(SB) + MOVW $1517, R12 + B runtime·callbackasm1(SB) + MOVW $1518, R12 + B runtime·callbackasm1(SB) + MOVW $1519, R12 + B runtime·callbackasm1(SB) + MOVW $1520, R12 + B runtime·callbackasm1(SB) + MOVW $1521, R12 + B runtime·callbackasm1(SB) + MOVW $1522, R12 + B runtime·callbackasm1(SB) + MOVW $1523, R12 + B runtime·callbackasm1(SB) + MOVW $1524, R12 + B runtime·callbackasm1(SB) + MOVW $1525, R12 + B runtime·callbackasm1(SB) + MOVW $1526, R12 + B runtime·callbackasm1(SB) + MOVW $1527, R12 + B runtime·callbackasm1(SB) + MOVW $1528, R12 + B runtime·callbackasm1(SB) + MOVW $1529, R12 + B runtime·callbackasm1(SB) + MOVW $1530, R12 + B runtime·callbackasm1(SB) + MOVW $1531, R12 + B runtime·callbackasm1(SB) + MOVW $1532, R12 + B runtime·callbackasm1(SB) + MOVW $1533, R12 + B runtime·callbackasm1(SB) + MOVW $1534, R12 + B runtime·callbackasm1(SB) + MOVW $1535, R12 + B runtime·callbackasm1(SB) + MOVW $1536, R12 + B runtime·callbackasm1(SB) + MOVW $1537, R12 + B runtime·callbackasm1(SB) + MOVW $1538, R12 + B runtime·callbackasm1(SB) + MOVW $1539, R12 + B runtime·callbackasm1(SB) + MOVW $1540, R12 + B runtime·callbackasm1(SB) + MOVW $1541, R12 + B runtime·callbackasm1(SB) + MOVW $1542, R12 + B runtime·callbackasm1(SB) + MOVW $1543, R12 + B runtime·callbackasm1(SB) + MOVW $1544, R12 + B runtime·callbackasm1(SB) + MOVW $1545, R12 + B runtime·callbackasm1(SB) + MOVW $1546, R12 + B runtime·callbackasm1(SB) + MOVW $1547, R12 + B runtime·callbackasm1(SB) + MOVW $1548, R12 + B runtime·callbackasm1(SB) + MOVW $1549, R12 + B runtime·callbackasm1(SB) + MOVW $1550, R12 + B runtime·callbackasm1(SB) + MOVW $1551, R12 + B runtime·callbackasm1(SB) + MOVW $1552, R12 + B runtime·callbackasm1(SB) + MOVW $1553, R12 + B runtime·callbackasm1(SB) + MOVW $1554, R12 + B runtime·callbackasm1(SB) + MOVW $1555, R12 + B runtime·callbackasm1(SB) + MOVW $1556, R12 + B runtime·callbackasm1(SB) + MOVW $1557, R12 + B runtime·callbackasm1(SB) + MOVW $1558, R12 + B runtime·callbackasm1(SB) + MOVW $1559, R12 + B runtime·callbackasm1(SB) + MOVW $1560, R12 + B runtime·callbackasm1(SB) + MOVW $1561, R12 + B runtime·callbackasm1(SB) + MOVW $1562, R12 + B runtime·callbackasm1(SB) + MOVW $1563, R12 + B runtime·callbackasm1(SB) + MOVW $1564, R12 + B runtime·callbackasm1(SB) + MOVW $1565, R12 + B runtime·callbackasm1(SB) + MOVW $1566, R12 + B runtime·callbackasm1(SB) + MOVW $1567, R12 + B runtime·callbackasm1(SB) + MOVW $1568, R12 + B runtime·callbackasm1(SB) + MOVW $1569, R12 + B runtime·callbackasm1(SB) + MOVW $1570, R12 + B runtime·callbackasm1(SB) + MOVW $1571, R12 + B runtime·callbackasm1(SB) + MOVW $1572, R12 + B runtime·callbackasm1(SB) + MOVW $1573, R12 + B runtime·callbackasm1(SB) + MOVW $1574, R12 + B runtime·callbackasm1(SB) + MOVW $1575, R12 + B runtime·callbackasm1(SB) + MOVW $1576, R12 + B runtime·callbackasm1(SB) + MOVW $1577, R12 + B runtime·callbackasm1(SB) + MOVW $1578, R12 + B runtime·callbackasm1(SB) + MOVW $1579, R12 + B runtime·callbackasm1(SB) + MOVW $1580, R12 + B runtime·callbackasm1(SB) + MOVW $1581, R12 + B runtime·callbackasm1(SB) + MOVW $1582, R12 + B runtime·callbackasm1(SB) + MOVW $1583, R12 + B runtime·callbackasm1(SB) + MOVW $1584, R12 + B runtime·callbackasm1(SB) + MOVW $1585, R12 + B runtime·callbackasm1(SB) + MOVW $1586, R12 + B runtime·callbackasm1(SB) + MOVW $1587, R12 + B runtime·callbackasm1(SB) + MOVW $1588, R12 + B runtime·callbackasm1(SB) + MOVW $1589, R12 + B runtime·callbackasm1(SB) + MOVW $1590, R12 + B runtime·callbackasm1(SB) + MOVW $1591, R12 + B runtime·callbackasm1(SB) + MOVW $1592, R12 + B runtime·callbackasm1(SB) + MOVW $1593, R12 + B runtime·callbackasm1(SB) + MOVW $1594, R12 + B runtime·callbackasm1(SB) + MOVW $1595, R12 + B runtime·callbackasm1(SB) + MOVW $1596, R12 + B runtime·callbackasm1(SB) + MOVW $1597, R12 + B runtime·callbackasm1(SB) + MOVW $1598, R12 + B runtime·callbackasm1(SB) + MOVW $1599, R12 + B runtime·callbackasm1(SB) + MOVW $1600, R12 + B runtime·callbackasm1(SB) + MOVW $1601, R12 + B runtime·callbackasm1(SB) + MOVW $1602, R12 + B runtime·callbackasm1(SB) + MOVW $1603, R12 + B runtime·callbackasm1(SB) + MOVW $1604, R12 + B runtime·callbackasm1(SB) + MOVW $1605, R12 + B runtime·callbackasm1(SB) + MOVW $1606, R12 + B runtime·callbackasm1(SB) + MOVW $1607, R12 + B runtime·callbackasm1(SB) + MOVW $1608, R12 + B runtime·callbackasm1(SB) + MOVW $1609, R12 + B runtime·callbackasm1(SB) + MOVW $1610, R12 + B runtime·callbackasm1(SB) + MOVW $1611, R12 + B runtime·callbackasm1(SB) + MOVW $1612, R12 + B runtime·callbackasm1(SB) + MOVW $1613, R12 + B runtime·callbackasm1(SB) + MOVW $1614, R12 + B runtime·callbackasm1(SB) + MOVW $1615, R12 + B runtime·callbackasm1(SB) + MOVW $1616, R12 + B runtime·callbackasm1(SB) + MOVW $1617, R12 + B runtime·callbackasm1(SB) + MOVW $1618, R12 + B runtime·callbackasm1(SB) + MOVW $1619, R12 + B runtime·callbackasm1(SB) + MOVW $1620, R12 + B runtime·callbackasm1(SB) + MOVW $1621, R12 + B runtime·callbackasm1(SB) + MOVW $1622, R12 + B runtime·callbackasm1(SB) + MOVW $1623, R12 + B runtime·callbackasm1(SB) + MOVW $1624, R12 + B runtime·callbackasm1(SB) + MOVW $1625, R12 + B runtime·callbackasm1(SB) + MOVW $1626, R12 + B runtime·callbackasm1(SB) + MOVW $1627, R12 + B runtime·callbackasm1(SB) + MOVW $1628, R12 + B runtime·callbackasm1(SB) + MOVW $1629, R12 + B runtime·callbackasm1(SB) + MOVW $1630, R12 + B runtime·callbackasm1(SB) + MOVW $1631, R12 + B runtime·callbackasm1(SB) + MOVW $1632, R12 + B runtime·callbackasm1(SB) + MOVW $1633, R12 + B runtime·callbackasm1(SB) + MOVW $1634, R12 + B runtime·callbackasm1(SB) + MOVW $1635, R12 + B runtime·callbackasm1(SB) + MOVW $1636, R12 + B runtime·callbackasm1(SB) + MOVW $1637, R12 + B runtime·callbackasm1(SB) + MOVW $1638, R12 + B runtime·callbackasm1(SB) + MOVW $1639, R12 + B runtime·callbackasm1(SB) + MOVW $1640, R12 + B runtime·callbackasm1(SB) + MOVW $1641, R12 + B runtime·callbackasm1(SB) + MOVW $1642, R12 + B runtime·callbackasm1(SB) + MOVW $1643, R12 + B runtime·callbackasm1(SB) + MOVW $1644, R12 + B runtime·callbackasm1(SB) + MOVW $1645, R12 + B runtime·callbackasm1(SB) + MOVW $1646, R12 + B runtime·callbackasm1(SB) + MOVW $1647, R12 + B runtime·callbackasm1(SB) + MOVW $1648, R12 + B runtime·callbackasm1(SB) + MOVW $1649, R12 + B runtime·callbackasm1(SB) + MOVW $1650, R12 + B runtime·callbackasm1(SB) + MOVW $1651, R12 + B runtime·callbackasm1(SB) + MOVW $1652, R12 + B runtime·callbackasm1(SB) + MOVW $1653, R12 + B runtime·callbackasm1(SB) + MOVW $1654, R12 + B runtime·callbackasm1(SB) + MOVW $1655, R12 + B runtime·callbackasm1(SB) + MOVW $1656, R12 + B runtime·callbackasm1(SB) + MOVW $1657, R12 + B runtime·callbackasm1(SB) + MOVW $1658, R12 + B runtime·callbackasm1(SB) + MOVW $1659, R12 + B runtime·callbackasm1(SB) + MOVW $1660, R12 + B runtime·callbackasm1(SB) + MOVW $1661, R12 + B runtime·callbackasm1(SB) + MOVW $1662, R12 + B runtime·callbackasm1(SB) + MOVW $1663, R12 + B runtime·callbackasm1(SB) + MOVW $1664, R12 + B runtime·callbackasm1(SB) + MOVW $1665, R12 + B runtime·callbackasm1(SB) + MOVW $1666, R12 + B runtime·callbackasm1(SB) + MOVW $1667, R12 + B runtime·callbackasm1(SB) + MOVW $1668, R12 + B runtime·callbackasm1(SB) + MOVW $1669, R12 + B runtime·callbackasm1(SB) + MOVW $1670, R12 + B runtime·callbackasm1(SB) + MOVW $1671, R12 + B runtime·callbackasm1(SB) + MOVW $1672, R12 + B runtime·callbackasm1(SB) + MOVW $1673, R12 + B runtime·callbackasm1(SB) + MOVW $1674, R12 + B runtime·callbackasm1(SB) + MOVW $1675, R12 + B runtime·callbackasm1(SB) + MOVW $1676, R12 + B runtime·callbackasm1(SB) + MOVW $1677, R12 + B runtime·callbackasm1(SB) + MOVW $1678, R12 + B runtime·callbackasm1(SB) + MOVW $1679, R12 + B runtime·callbackasm1(SB) + MOVW $1680, R12 + B runtime·callbackasm1(SB) + MOVW $1681, R12 + B runtime·callbackasm1(SB) + MOVW $1682, R12 + B runtime·callbackasm1(SB) + MOVW $1683, R12 + B runtime·callbackasm1(SB) + MOVW $1684, R12 + B runtime·callbackasm1(SB) + MOVW $1685, R12 + B runtime·callbackasm1(SB) + MOVW $1686, R12 + B runtime·callbackasm1(SB) + MOVW $1687, R12 + B runtime·callbackasm1(SB) + MOVW $1688, R12 + B runtime·callbackasm1(SB) + MOVW $1689, R12 + B runtime·callbackasm1(SB) + MOVW $1690, R12 + B runtime·callbackasm1(SB) + MOVW $1691, R12 + B runtime·callbackasm1(SB) + MOVW $1692, R12 + B runtime·callbackasm1(SB) + MOVW $1693, R12 + B runtime·callbackasm1(SB) + MOVW $1694, R12 + B runtime·callbackasm1(SB) + MOVW $1695, R12 + B runtime·callbackasm1(SB) + MOVW $1696, R12 + B runtime·callbackasm1(SB) + MOVW $1697, R12 + B runtime·callbackasm1(SB) + MOVW $1698, R12 + B runtime·callbackasm1(SB) + MOVW $1699, R12 + B runtime·callbackasm1(SB) + MOVW $1700, R12 + B runtime·callbackasm1(SB) + MOVW $1701, R12 + B runtime·callbackasm1(SB) + MOVW $1702, R12 + B runtime·callbackasm1(SB) + MOVW $1703, R12 + B runtime·callbackasm1(SB) + MOVW $1704, R12 + B runtime·callbackasm1(SB) + MOVW $1705, R12 + B runtime·callbackasm1(SB) + MOVW $1706, R12 + B runtime·callbackasm1(SB) + MOVW $1707, R12 + B runtime·callbackasm1(SB) + MOVW $1708, R12 + B runtime·callbackasm1(SB) + MOVW $1709, R12 + B runtime·callbackasm1(SB) + MOVW $1710, R12 + B runtime·callbackasm1(SB) + MOVW $1711, R12 + B runtime·callbackasm1(SB) + MOVW $1712, R12 + B runtime·callbackasm1(SB) + MOVW $1713, R12 + B runtime·callbackasm1(SB) + MOVW $1714, R12 + B runtime·callbackasm1(SB) + MOVW $1715, R12 + B runtime·callbackasm1(SB) + MOVW $1716, R12 + B runtime·callbackasm1(SB) + MOVW $1717, R12 + B runtime·callbackasm1(SB) + MOVW $1718, R12 + B runtime·callbackasm1(SB) + MOVW $1719, R12 + B runtime·callbackasm1(SB) + MOVW $1720, R12 + B runtime·callbackasm1(SB) + MOVW $1721, R12 + B runtime·callbackasm1(SB) + MOVW $1722, R12 + B runtime·callbackasm1(SB) + MOVW $1723, R12 + B runtime·callbackasm1(SB) + MOVW $1724, R12 + B runtime·callbackasm1(SB) + MOVW $1725, R12 + B runtime·callbackasm1(SB) + MOVW $1726, R12 + B runtime·callbackasm1(SB) + MOVW $1727, R12 + B runtime·callbackasm1(SB) + MOVW $1728, R12 + B runtime·callbackasm1(SB) + MOVW $1729, R12 + B runtime·callbackasm1(SB) + MOVW $1730, R12 + B runtime·callbackasm1(SB) + MOVW $1731, R12 + B runtime·callbackasm1(SB) + MOVW $1732, R12 + B runtime·callbackasm1(SB) + MOVW $1733, R12 + B runtime·callbackasm1(SB) + MOVW $1734, R12 + B runtime·callbackasm1(SB) + MOVW $1735, R12 + B runtime·callbackasm1(SB) + MOVW $1736, R12 + B runtime·callbackasm1(SB) + MOVW $1737, R12 + B runtime·callbackasm1(SB) + MOVW $1738, R12 + B runtime·callbackasm1(SB) + MOVW $1739, R12 + B runtime·callbackasm1(SB) + MOVW $1740, R12 + B runtime·callbackasm1(SB) + MOVW $1741, R12 + B runtime·callbackasm1(SB) + MOVW $1742, R12 + B runtime·callbackasm1(SB) + MOVW $1743, R12 + B runtime·callbackasm1(SB) + MOVW $1744, R12 + B runtime·callbackasm1(SB) + MOVW $1745, R12 + B runtime·callbackasm1(SB) + MOVW $1746, R12 + B runtime·callbackasm1(SB) + MOVW $1747, R12 + B runtime·callbackasm1(SB) + MOVW $1748, R12 + B runtime·callbackasm1(SB) + MOVW $1749, R12 + B runtime·callbackasm1(SB) + MOVW $1750, R12 + B runtime·callbackasm1(SB) + MOVW $1751, R12 + B runtime·callbackasm1(SB) + MOVW $1752, R12 + B runtime·callbackasm1(SB) + MOVW $1753, R12 + B runtime·callbackasm1(SB) + MOVW $1754, R12 + B runtime·callbackasm1(SB) + MOVW $1755, R12 + B runtime·callbackasm1(SB) + MOVW $1756, R12 + B runtime·callbackasm1(SB) + MOVW $1757, R12 + B runtime·callbackasm1(SB) + MOVW $1758, R12 + B runtime·callbackasm1(SB) + MOVW $1759, R12 + B runtime·callbackasm1(SB) + MOVW $1760, R12 + B runtime·callbackasm1(SB) + MOVW $1761, R12 + B runtime·callbackasm1(SB) + MOVW $1762, R12 + B runtime·callbackasm1(SB) + MOVW $1763, R12 + B runtime·callbackasm1(SB) + MOVW $1764, R12 + B runtime·callbackasm1(SB) + MOVW $1765, R12 + B runtime·callbackasm1(SB) + MOVW $1766, R12 + B runtime·callbackasm1(SB) + MOVW $1767, R12 + B runtime·callbackasm1(SB) + MOVW $1768, R12 + B runtime·callbackasm1(SB) + MOVW $1769, R12 + B runtime·callbackasm1(SB) + MOVW $1770, R12 + B runtime·callbackasm1(SB) + MOVW $1771, R12 + B runtime·callbackasm1(SB) + MOVW $1772, R12 + B runtime·callbackasm1(SB) + MOVW $1773, R12 + B runtime·callbackasm1(SB) + MOVW $1774, R12 + B runtime·callbackasm1(SB) + MOVW $1775, R12 + B runtime·callbackasm1(SB) + MOVW $1776, R12 + B runtime·callbackasm1(SB) + MOVW $1777, R12 + B runtime·callbackasm1(SB) + MOVW $1778, R12 + B runtime·callbackasm1(SB) + MOVW $1779, R12 + B runtime·callbackasm1(SB) + MOVW $1780, R12 + B runtime·callbackasm1(SB) + MOVW $1781, R12 + B runtime·callbackasm1(SB) + MOVW $1782, R12 + B runtime·callbackasm1(SB) + MOVW $1783, R12 + B runtime·callbackasm1(SB) + MOVW $1784, R12 + B runtime·callbackasm1(SB) + MOVW $1785, R12 + B runtime·callbackasm1(SB) + MOVW $1786, R12 + B runtime·callbackasm1(SB) + MOVW $1787, R12 + B runtime·callbackasm1(SB) + MOVW $1788, R12 + B runtime·callbackasm1(SB) + MOVW $1789, R12 + B runtime·callbackasm1(SB) + MOVW $1790, R12 + B runtime·callbackasm1(SB) + MOVW $1791, R12 + B runtime·callbackasm1(SB) + MOVW $1792, R12 + B runtime·callbackasm1(SB) + MOVW $1793, R12 + B runtime·callbackasm1(SB) + MOVW $1794, R12 + B runtime·callbackasm1(SB) + MOVW $1795, R12 + B runtime·callbackasm1(SB) + MOVW $1796, R12 + B runtime·callbackasm1(SB) + MOVW $1797, R12 + B runtime·callbackasm1(SB) + MOVW $1798, R12 + B runtime·callbackasm1(SB) + MOVW $1799, R12 + B runtime·callbackasm1(SB) + MOVW $1800, R12 + B runtime·callbackasm1(SB) + MOVW $1801, R12 + B runtime·callbackasm1(SB) + MOVW $1802, R12 + B runtime·callbackasm1(SB) + MOVW $1803, R12 + B runtime·callbackasm1(SB) + MOVW $1804, R12 + B runtime·callbackasm1(SB) + MOVW $1805, R12 + B runtime·callbackasm1(SB) + MOVW $1806, R12 + B runtime·callbackasm1(SB) + MOVW $1807, R12 + B runtime·callbackasm1(SB) + MOVW $1808, R12 + B runtime·callbackasm1(SB) + MOVW $1809, R12 + B runtime·callbackasm1(SB) + MOVW $1810, R12 + B runtime·callbackasm1(SB) + MOVW $1811, R12 + B runtime·callbackasm1(SB) + MOVW $1812, R12 + B runtime·callbackasm1(SB) + MOVW $1813, R12 + B runtime·callbackasm1(SB) + MOVW $1814, R12 + B runtime·callbackasm1(SB) + MOVW $1815, R12 + B runtime·callbackasm1(SB) + MOVW $1816, R12 + B runtime·callbackasm1(SB) + MOVW $1817, R12 + B runtime·callbackasm1(SB) + MOVW $1818, R12 + B runtime·callbackasm1(SB) + MOVW $1819, R12 + B runtime·callbackasm1(SB) + MOVW $1820, R12 + B runtime·callbackasm1(SB) + MOVW $1821, R12 + B runtime·callbackasm1(SB) + MOVW $1822, R12 + B runtime·callbackasm1(SB) + MOVW $1823, R12 + B runtime·callbackasm1(SB) + MOVW $1824, R12 + B runtime·callbackasm1(SB) + MOVW $1825, R12 + B runtime·callbackasm1(SB) + MOVW $1826, R12 + B runtime·callbackasm1(SB) + MOVW $1827, R12 + B runtime·callbackasm1(SB) + MOVW $1828, R12 + B runtime·callbackasm1(SB) + MOVW $1829, R12 + B runtime·callbackasm1(SB) + MOVW $1830, R12 + B runtime·callbackasm1(SB) + MOVW $1831, R12 + B runtime·callbackasm1(SB) + MOVW $1832, R12 + B runtime·callbackasm1(SB) + MOVW $1833, R12 + B runtime·callbackasm1(SB) + MOVW $1834, R12 + B runtime·callbackasm1(SB) + MOVW $1835, R12 + B runtime·callbackasm1(SB) + MOVW $1836, R12 + B runtime·callbackasm1(SB) + MOVW $1837, R12 + B runtime·callbackasm1(SB) + MOVW $1838, R12 + B runtime·callbackasm1(SB) + MOVW $1839, R12 + B runtime·callbackasm1(SB) + MOVW $1840, R12 + B runtime·callbackasm1(SB) + MOVW $1841, R12 + B runtime·callbackasm1(SB) + MOVW $1842, R12 + B runtime·callbackasm1(SB) + MOVW $1843, R12 + B runtime·callbackasm1(SB) + MOVW $1844, R12 + B runtime·callbackasm1(SB) + MOVW $1845, R12 + B runtime·callbackasm1(SB) + MOVW $1846, R12 + B runtime·callbackasm1(SB) + MOVW $1847, R12 + B runtime·callbackasm1(SB) + MOVW $1848, R12 + B runtime·callbackasm1(SB) + MOVW $1849, R12 + B runtime·callbackasm1(SB) + MOVW $1850, R12 + B runtime·callbackasm1(SB) + MOVW $1851, R12 + B runtime·callbackasm1(SB) + MOVW $1852, R12 + B runtime·callbackasm1(SB) + MOVW $1853, R12 + B runtime·callbackasm1(SB) + MOVW $1854, R12 + B runtime·callbackasm1(SB) + MOVW $1855, R12 + B runtime·callbackasm1(SB) + MOVW $1856, R12 + B runtime·callbackasm1(SB) + MOVW $1857, R12 + B runtime·callbackasm1(SB) + MOVW $1858, R12 + B runtime·callbackasm1(SB) + MOVW $1859, R12 + B runtime·callbackasm1(SB) + MOVW $1860, R12 + B runtime·callbackasm1(SB) + MOVW $1861, R12 + B runtime·callbackasm1(SB) + MOVW $1862, R12 + B runtime·callbackasm1(SB) + MOVW $1863, R12 + B runtime·callbackasm1(SB) + MOVW $1864, R12 + B runtime·callbackasm1(SB) + MOVW $1865, R12 + B runtime·callbackasm1(SB) + MOVW $1866, R12 + B runtime·callbackasm1(SB) + MOVW $1867, R12 + B runtime·callbackasm1(SB) + MOVW $1868, R12 + B runtime·callbackasm1(SB) + MOVW $1869, R12 + B runtime·callbackasm1(SB) + MOVW $1870, R12 + B runtime·callbackasm1(SB) + MOVW $1871, R12 + B runtime·callbackasm1(SB) + MOVW $1872, R12 + B runtime·callbackasm1(SB) + MOVW $1873, R12 + B runtime·callbackasm1(SB) + MOVW $1874, R12 + B runtime·callbackasm1(SB) + MOVW $1875, R12 + B runtime·callbackasm1(SB) + MOVW $1876, R12 + B runtime·callbackasm1(SB) + MOVW $1877, R12 + B runtime·callbackasm1(SB) + MOVW $1878, R12 + B runtime·callbackasm1(SB) + MOVW $1879, R12 + B runtime·callbackasm1(SB) + MOVW $1880, R12 + B runtime·callbackasm1(SB) + MOVW $1881, R12 + B runtime·callbackasm1(SB) + MOVW $1882, R12 + B runtime·callbackasm1(SB) + MOVW $1883, R12 + B runtime·callbackasm1(SB) + MOVW $1884, R12 + B runtime·callbackasm1(SB) + MOVW $1885, R12 + B runtime·callbackasm1(SB) + MOVW $1886, R12 + B runtime·callbackasm1(SB) + MOVW $1887, R12 + B runtime·callbackasm1(SB) + MOVW $1888, R12 + B runtime·callbackasm1(SB) + MOVW $1889, R12 + B runtime·callbackasm1(SB) + MOVW $1890, R12 + B runtime·callbackasm1(SB) + MOVW $1891, R12 + B runtime·callbackasm1(SB) + MOVW $1892, R12 + B runtime·callbackasm1(SB) + MOVW $1893, R12 + B runtime·callbackasm1(SB) + MOVW $1894, R12 + B runtime·callbackasm1(SB) + MOVW $1895, R12 + B runtime·callbackasm1(SB) + MOVW $1896, R12 + B runtime·callbackasm1(SB) + MOVW $1897, R12 + B runtime·callbackasm1(SB) + MOVW $1898, R12 + B runtime·callbackasm1(SB) + MOVW $1899, R12 + B runtime·callbackasm1(SB) + MOVW $1900, R12 + B runtime·callbackasm1(SB) + MOVW $1901, R12 + B runtime·callbackasm1(SB) + MOVW $1902, R12 + B runtime·callbackasm1(SB) + MOVW $1903, R12 + B runtime·callbackasm1(SB) + MOVW $1904, R12 + B runtime·callbackasm1(SB) + MOVW $1905, R12 + B runtime·callbackasm1(SB) + MOVW $1906, R12 + B runtime·callbackasm1(SB) + MOVW $1907, R12 + B runtime·callbackasm1(SB) + MOVW $1908, R12 + B runtime·callbackasm1(SB) + MOVW $1909, R12 + B runtime·callbackasm1(SB) + MOVW $1910, R12 + B runtime·callbackasm1(SB) + MOVW $1911, R12 + B runtime·callbackasm1(SB) + MOVW $1912, R12 + B runtime·callbackasm1(SB) + MOVW $1913, R12 + B runtime·callbackasm1(SB) + MOVW $1914, R12 + B runtime·callbackasm1(SB) + MOVW $1915, R12 + B runtime·callbackasm1(SB) + MOVW $1916, R12 + B runtime·callbackasm1(SB) + MOVW $1917, R12 + B runtime·callbackasm1(SB) + MOVW $1918, R12 + B runtime·callbackasm1(SB) + MOVW $1919, R12 + B runtime·callbackasm1(SB) + MOVW $1920, R12 + B runtime·callbackasm1(SB) + MOVW $1921, R12 + B runtime·callbackasm1(SB) + MOVW $1922, R12 + B runtime·callbackasm1(SB) + MOVW $1923, R12 + B runtime·callbackasm1(SB) + MOVW $1924, R12 + B runtime·callbackasm1(SB) + MOVW $1925, R12 + B runtime·callbackasm1(SB) + MOVW $1926, R12 + B runtime·callbackasm1(SB) + MOVW $1927, R12 + B runtime·callbackasm1(SB) + MOVW $1928, R12 + B runtime·callbackasm1(SB) + MOVW $1929, R12 + B runtime·callbackasm1(SB) + MOVW $1930, R12 + B runtime·callbackasm1(SB) + MOVW $1931, R12 + B runtime·callbackasm1(SB) + MOVW $1932, R12 + B runtime·callbackasm1(SB) + MOVW $1933, R12 + B runtime·callbackasm1(SB) + MOVW $1934, R12 + B runtime·callbackasm1(SB) + MOVW $1935, R12 + B runtime·callbackasm1(SB) + MOVW $1936, R12 + B runtime·callbackasm1(SB) + MOVW $1937, R12 + B runtime·callbackasm1(SB) + MOVW $1938, R12 + B runtime·callbackasm1(SB) + MOVW $1939, R12 + B runtime·callbackasm1(SB) + MOVW $1940, R12 + B runtime·callbackasm1(SB) + MOVW $1941, R12 + B runtime·callbackasm1(SB) + MOVW $1942, R12 + B runtime·callbackasm1(SB) + MOVW $1943, R12 + B runtime·callbackasm1(SB) + MOVW $1944, R12 + B runtime·callbackasm1(SB) + MOVW $1945, R12 + B runtime·callbackasm1(SB) + MOVW $1946, R12 + B runtime·callbackasm1(SB) + MOVW $1947, R12 + B runtime·callbackasm1(SB) + MOVW $1948, R12 + B runtime·callbackasm1(SB) + MOVW $1949, R12 + B runtime·callbackasm1(SB) + MOVW $1950, R12 + B runtime·callbackasm1(SB) + MOVW $1951, R12 + B runtime·callbackasm1(SB) + MOVW $1952, R12 + B runtime·callbackasm1(SB) + MOVW $1953, R12 + B runtime·callbackasm1(SB) + MOVW $1954, R12 + B runtime·callbackasm1(SB) + MOVW $1955, R12 + B runtime·callbackasm1(SB) + MOVW $1956, R12 + B runtime·callbackasm1(SB) + MOVW $1957, R12 + B runtime·callbackasm1(SB) + MOVW $1958, R12 + B runtime·callbackasm1(SB) + MOVW $1959, R12 + B runtime·callbackasm1(SB) + MOVW $1960, R12 + B runtime·callbackasm1(SB) + MOVW $1961, R12 + B runtime·callbackasm1(SB) + MOVW $1962, R12 + B runtime·callbackasm1(SB) + MOVW $1963, R12 + B runtime·callbackasm1(SB) + MOVW $1964, R12 + B runtime·callbackasm1(SB) + MOVW $1965, R12 + B runtime·callbackasm1(SB) + MOVW $1966, R12 + B runtime·callbackasm1(SB) + MOVW $1967, R12 + B runtime·callbackasm1(SB) + MOVW $1968, R12 + B runtime·callbackasm1(SB) + MOVW $1969, R12 + B runtime·callbackasm1(SB) + MOVW $1970, R12 + B runtime·callbackasm1(SB) + MOVW $1971, R12 + B runtime·callbackasm1(SB) + MOVW $1972, R12 + B runtime·callbackasm1(SB) + MOVW $1973, R12 + B runtime·callbackasm1(SB) + MOVW $1974, R12 + B runtime·callbackasm1(SB) + MOVW $1975, R12 + B runtime·callbackasm1(SB) + MOVW $1976, R12 + B runtime·callbackasm1(SB) + MOVW $1977, R12 + B runtime·callbackasm1(SB) + MOVW $1978, R12 + B runtime·callbackasm1(SB) + MOVW $1979, R12 + B runtime·callbackasm1(SB) + MOVW $1980, R12 + B runtime·callbackasm1(SB) + MOVW $1981, R12 + B runtime·callbackasm1(SB) + MOVW $1982, R12 + B runtime·callbackasm1(SB) + MOVW $1983, R12 + B runtime·callbackasm1(SB) + MOVW $1984, R12 + B runtime·callbackasm1(SB) + MOVW $1985, R12 + B runtime·callbackasm1(SB) + MOVW $1986, R12 + B runtime·callbackasm1(SB) + MOVW $1987, R12 + B runtime·callbackasm1(SB) + MOVW $1988, R12 + B runtime·callbackasm1(SB) + MOVW $1989, R12 + B runtime·callbackasm1(SB) + MOVW $1990, R12 + B runtime·callbackasm1(SB) + MOVW $1991, R12 + B runtime·callbackasm1(SB) + MOVW $1992, R12 + B runtime·callbackasm1(SB) + MOVW $1993, R12 + B runtime·callbackasm1(SB) + MOVW $1994, R12 + B runtime·callbackasm1(SB) + MOVW $1995, R12 + B runtime·callbackasm1(SB) + MOVW $1996, R12 + B runtime·callbackasm1(SB) + MOVW $1997, R12 + B runtime·callbackasm1(SB) + MOVW $1998, R12 + B runtime·callbackasm1(SB) + MOVW $1999, R12 + B runtime·callbackasm1(SB) From d17ac291584f6f518430ea3123e0ec9a7658c950 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Tue, 18 Sep 2018 01:53:42 +0000 Subject: [PATCH 0407/1663] cmd/compile: simplify AMD64's assembly generator AMD64's ADDQconstmodify/ADDLconstmodify have similar logic with other constmodify like operators, but seperated case statements. This CL simplify them with a fallthrough. Change-Id: Ia73ffeaddc5080182f68c06c9d9b48fe32a14e38 Reviewed-on: https://go-review.googlesource.com/135855 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/amd64/ssa.go | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/cmd/compile/internal/amd64/ssa.go b/src/cmd/compile/internal/amd64/ssa.go index 2afb556d80f40..818bc359414ad 100644 --- a/src/cmd/compile/internal/amd64/ssa.go +++ b/src/cmd/compile/internal/amd64/ssa.go @@ -759,14 +759,9 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.To.Type = obj.TYPE_MEM p.To.Reg = v.Args[0].Reg() gc.AddAux2(&p.To, v, off) - } else { - p := s.Prog(v.Op.Asm()) - p.From.Type = obj.TYPE_CONST - p.From.Offset = val - p.To.Type = obj.TYPE_MEM - p.To.Reg = v.Args[0].Reg() - gc.AddAux2(&p.To, v, off) + break } + fallthrough case ssa.OpAMD64ANDQconstmodify, ssa.OpAMD64ANDLconstmodify, ssa.OpAMD64ORQconstmodify, ssa.OpAMD64ORLconstmodify, ssa.OpAMD64XORQconstmodify, ssa.OpAMD64XORLconstmodify: sc := v.AuxValAndOff() From 713edf8b31de04dce26f603576f074133e95de47 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Tue, 18 Sep 2018 01:04:41 +0300 Subject: [PATCH 0408/1663] cmd/compile/internal/gc: simplify `x = x y` to `x = y` Change-Id: I5afba2c10372252be4b65dae7a95461722de904f Reviewed-on: https://go-review.googlesource.com/135835 Reviewed-by: Keith Randall Reviewed-by: Robert Griesemer Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/gc/esc.go | 4 ++-- src/cmd/compile/internal/gc/walk.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go index cd85a38eb6c42..ad4d11806c84d 100644 --- a/src/cmd/compile/internal/gc/esc.go +++ b/src/cmd/compile/internal/gc/esc.go @@ -1419,7 +1419,7 @@ func describeEscape(em uint16) string { } s += "contentToHeap" } - for em >>= EscReturnBits; em != 0; em = em >> bitsPerOutputInTag { + for em >>= EscReturnBits; em != 0; em >>= bitsPerOutputInTag { // See encoding description above if s != "" { s += " " @@ -1469,7 +1469,7 @@ func (e *EscState) escassignfromtag(note string, dsts Nodes, src, call *Node) ui em0 := em dstsi := 0 - for em >>= EscReturnBits; em != 0 && dstsi < dsts.Len(); em = em >> bitsPerOutputInTag { + for em >>= EscReturnBits; em != 0 && dstsi < dsts.Len(); em >>= bitsPerOutputInTag { // Prefer the lowest-level path to the reference (for escape purposes). // Two-bit encoding (for example. 1, 3, and 4 bits are other options) // 01 = 0-level diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 2c0bc4b22e74e..0b382bbbf047e 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -1312,7 +1312,7 @@ opswitch: b = conv(b, convType) b = nod(OLSH, b, nodintconst(int64(8*offset))) ncsubstr = nod(OOR, ncsubstr, b) - csubstr = csubstr | int64(s[i+offset])< Date: Mon, 17 Sep 2018 02:05:22 +0000 Subject: [PATCH 0409/1663] cmd/compile: optimize AMD64's bit wise operation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently "arr[idx] |= 0x80" is compiled to MOVLload->BTSL->MOVLstore. And this CL optimizes it to a single BTSLconstmodify. Other bit wise operations with a direct memory operand are also implemented. 1. The size of the executable bin/go decreases about 4KB, and the total size of pkg/linux_amd64 (excluding cmd/compile) decreases about 0.6KB. 2. There a little improvement in the go1 benchmark test (excluding noise). name old time/op new time/op delta BinaryTree17-4 2.66s ± 4% 2.66s ± 3% ~ (p=0.596 n=49+49) Fannkuch11-4 2.38s ± 2% 2.32s ± 2% -2.69% (p=0.000 n=50+50) FmtFprintfEmpty-4 42.7ns ± 4% 43.2ns ± 7% +1.31% (p=0.009 n=50+50) FmtFprintfString-4 71.0ns ± 5% 72.0ns ± 3% +1.33% (p=0.000 n=50+50) FmtFprintfInt-4 80.7ns ± 4% 80.6ns ± 3% ~ (p=0.931 n=50+50) FmtFprintfIntInt-4 125ns ± 3% 126ns ± 4% ~ (p=0.051 n=50+50) FmtFprintfPrefixedInt-4 158ns ± 1% 142ns ± 3% -9.84% (p=0.000 n=36+50) FmtFprintfFloat-4 215ns ± 4% 212ns ± 4% -1.23% (p=0.002 n=50+50) FmtManyArgs-4 519ns ± 3% 510ns ± 3% -1.77% (p=0.000 n=50+50) GobDecode-4 6.49ms ± 6% 6.52ms ± 5% ~ (p=0.866 n=50+50) GobEncode-4 5.93ms ± 8% 6.01ms ± 7% ~ (p=0.076 n=50+50) Gzip-4 222ms ± 4% 224ms ± 8% +0.80% (p=0.001 n=50+50) Gunzip-4 36.6ms ± 5% 36.4ms ± 4% ~ (p=0.093 n=50+50) HTTPClientServer-4 59.1µs ± 1% 58.9µs ± 2% -0.24% (p=0.039 n=49+48) JSONEncode-4 9.23ms ± 4% 9.21ms ± 5% ~ (p=0.244 n=50+50) JSONDecode-4 48.8ms ± 4% 48.7ms ± 4% ~ (p=0.653 n=50+50) Mandelbrot200-4 3.81ms ± 4% 3.80ms ± 3% ~ (p=0.834 n=50+50) GoParse-4 3.20ms ± 5% 3.19ms ± 5% ~ (p=0.494 n=50+50) RegexpMatchEasy0_32-4 78.1ns ± 2% 77.4ns ± 3% -0.86% (p=0.005 n=50+50) RegexpMatchEasy0_1K-4 233ns ± 3% 233ns ± 3% ~ (p=0.074 n=50+50) RegexpMatchEasy1_32-4 74.2ns ± 3% 73.4ns ± 3% -1.06% (p=0.000 n=50+50) RegexpMatchEasy1_1K-4 369ns ± 2% 364ns ± 4% -1.41% (p=0.000 n=36+50) RegexpMatchMedium_32-4 109ns ± 4% 107ns ± 3% -2.06% (p=0.001 n=50+50) RegexpMatchMedium_1K-4 31.5µs ± 3% 30.8µs ± 3% -2.20% (p=0.000 n=50+50) RegexpMatchHard_32-4 1.57µs ± 3% 1.56µs ± 2% -0.57% (p=0.016 n=50+50) RegexpMatchHard_1K-4 47.4µs ± 4% 47.0µs ± 3% -0.82% (p=0.008 n=50+50) Revcomp-4 414ms ± 7% 412ms ± 7% ~ (p=0.285 n=50+50) Template-4 64.3ms ± 4% 62.7ms ± 3% -2.44% (p=0.000 n=50+50) TimeParse-4 316ns ± 3% 313ns ± 3% ~ (p=0.122 n=50+50) TimeFormat-4 291ns ± 3% 293ns ± 3% +0.80% (p=0.001 n=50+50) [Geo mean] 46.5µs 46.2µs -0.81% name old speed new speed delta GobDecode-4 118MB/s ± 6% 118MB/s ± 5% ~ (p=0.863 n=50+50) GobEncode-4 130MB/s ± 9% 128MB/s ± 8% ~ (p=0.076 n=50+50) Gzip-4 87.4MB/s ± 4% 86.8MB/s ± 7% -0.78% (p=0.002 n=50+50) Gunzip-4 531MB/s ± 5% 533MB/s ± 4% ~ (p=0.093 n=50+50) JSONEncode-4 210MB/s ± 4% 211MB/s ± 5% ~ (p=0.247 n=50+50) JSONDecode-4 39.8MB/s ± 4% 39.9MB/s ± 4% ~ (p=0.654 n=50+50) GoParse-4 18.1MB/s ± 5% 18.2MB/s ± 5% ~ (p=0.493 n=50+50) RegexpMatchEasy0_32-4 410MB/s ± 2% 413MB/s ± 3% +0.86% (p=0.004 n=50+50) RegexpMatchEasy0_1K-4 4.39GB/s ± 3% 4.38GB/s ± 3% ~ (p=0.063 n=50+50) RegexpMatchEasy1_32-4 432MB/s ± 3% 436MB/s ± 3% +1.07% (p=0.000 n=50+50) RegexpMatchEasy1_1K-4 2.77GB/s ± 2% 2.81GB/s ± 4% +1.46% (p=0.000 n=36+50) RegexpMatchMedium_32-4 9.16MB/s ± 3% 9.35MB/s ± 4% +2.09% (p=0.001 n=50+50) RegexpMatchMedium_1K-4 32.5MB/s ± 3% 33.2MB/s ± 3% +2.25% (p=0.000 n=50+50) RegexpMatchHard_32-4 20.4MB/s ± 3% 20.5MB/s ± 2% +0.56% (p=0.017 n=50+50) RegexpMatchHard_1K-4 21.6MB/s ± 4% 21.8MB/s ± 3% +0.83% (p=0.008 n=50+50) Revcomp-4 613MB/s ± 4% 618MB/s ± 7% ~ (p=0.152 n=48+50) Template-4 30.2MB/s ± 4% 30.9MB/s ± 3% +2.49% (p=0.000 n=50+50) [Geo mean] 127MB/s 128MB/s +0.64% Change-Id: If405198283855d75697f66cf894b2bef458f620e Reviewed-on: https://go-review.googlesource.com/135422 Reviewed-by: Keith Randall --- src/cmd/compile/internal/amd64/ssa.go | 4 +- src/cmd/compile/internal/ssa/gen/AMD64.rules | 68 +- src/cmd/compile/internal/ssa/gen/AMD64Ops.go | 14 + src/cmd/compile/internal/ssa/opGen.go | 186 ++ src/cmd/compile/internal/ssa/rewriteAMD64.go | 1793 ++++++++++++++++-- test/codegen/bits.go | 6 + 6 files changed, 1938 insertions(+), 133 deletions(-) diff --git a/src/cmd/compile/internal/amd64/ssa.go b/src/cmd/compile/internal/amd64/ssa.go index 818bc359414ad..b4c4b1f4cd2f3 100644 --- a/src/cmd/compile/internal/amd64/ssa.go +++ b/src/cmd/compile/internal/amd64/ssa.go @@ -695,6 +695,7 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.To.Type = obj.TYPE_REG p.To.Reg = v.Reg() case ssa.OpAMD64MOVQstore, ssa.OpAMD64MOVSSstore, ssa.OpAMD64MOVSDstore, ssa.OpAMD64MOVLstore, ssa.OpAMD64MOVWstore, ssa.OpAMD64MOVBstore, ssa.OpAMD64MOVOstore, + ssa.OpAMD64BTCQmodify, ssa.OpAMD64BTCLmodify, ssa.OpAMD64BTRQmodify, ssa.OpAMD64BTRLmodify, ssa.OpAMD64BTSQmodify, ssa.OpAMD64BTSLmodify, ssa.OpAMD64ADDQmodify, ssa.OpAMD64SUBQmodify, ssa.OpAMD64ANDQmodify, ssa.OpAMD64ORQmodify, ssa.OpAMD64XORQmodify, ssa.OpAMD64ADDLmodify, ssa.OpAMD64SUBLmodify, ssa.OpAMD64ANDLmodify, ssa.OpAMD64ORLmodify, ssa.OpAMD64XORLmodify: p := s.Prog(v.Op.Asm()) @@ -763,7 +764,8 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { } fallthrough case ssa.OpAMD64ANDQconstmodify, ssa.OpAMD64ANDLconstmodify, ssa.OpAMD64ORQconstmodify, ssa.OpAMD64ORLconstmodify, - ssa.OpAMD64XORQconstmodify, ssa.OpAMD64XORLconstmodify: + ssa.OpAMD64BTCQconstmodify, ssa.OpAMD64BTCLconstmodify, ssa.OpAMD64BTSQconstmodify, ssa.OpAMD64BTSLconstmodify, + ssa.OpAMD64BTRQconstmodify, ssa.OpAMD64BTRLconstmodify, ssa.OpAMD64XORQconstmodify, ssa.OpAMD64XORLconstmodify: sc := v.AuxValAndOff() off := sc.Off() val := sc.Val() diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index 803b8896b0a29..76a4fc9ab7dea 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -709,7 +709,17 @@ (ANDL x (MOVLconst [c])) -> (ANDLconst [c] x) (AND(L|Q)const [c] (AND(L|Q)const [d] x)) -> (AND(L|Q)const [c & d] x) +(BTR(L|Q)const [c] (AND(L|Q)const [d] x)) -> (AND(L|Q)const [d &^ 1< (AND(L|Q)const [c &^ 1< (AND(L|Q)const [^(1< (XOR(L|Q)const [c ^ d] x) +(BTC(L|Q)const [c] (XOR(L|Q)const [d] x)) -> (XOR(L|Q)const [d ^ 1< (XOR(L|Q)const [c ^ 1< (XOR(L|Q)const [1< (OR(L|Q)const [c | d] x) +(OR(L|Q)const [c] (BTS(L|Q)const [d] x)) -> (OR(L|Q)const [c | 1< (OR(L|Q)const [d | 1< (OR(L|Q)const [1< (MULLconst [int64(int32(c * d))] x) (MULQconst [c] (MULQconst [d] x)) && is32Bit(c*d) -> (MULQconst [c * d] x) @@ -1051,14 +1061,14 @@ ((ADD|SUB|MUL|DIV)SSload [off1+off2] {sym} val base mem) ((ADD|SUB|MUL|DIV)SDload [off1] {sym} val (ADDQconst [off2] base) mem) && is32Bit(off1+off2) -> ((ADD|SUB|MUL|DIV)SDload [off1+off2] {sym} val base mem) -((ADD|AND|OR|XOR)Qconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> - ((ADD|AND|OR|XOR)Qconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) -((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> - ((ADD|AND|OR|XOR)Lconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) -((ADD|SUB|AND|OR|XOR)Qmodify [off1] {sym} (ADDQconst [off2] base) val mem) && is32Bit(off1+off2) -> - ((ADD|SUB|AND|OR|XOR)Qmodify [off1+off2] {sym} base val mem) -((ADD|SUB|AND|OR|XOR)Lmodify [off1] {sym} (ADDQconst [off2] base) val mem) && is32Bit(off1+off2) -> - ((ADD|SUB|AND|OR|XOR)Lmodify [off1+off2] {sym} base val mem) +((ADD|AND|OR|XOR|BTC|BTR|BTS)Qconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> + ((ADD|AND|OR|XOR|BTC|BTR|BTS)Qconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) +((ADD|AND|OR|XOR|BTC|BTR|BTS)Lconstmodify [valoff1] {sym} (ADDQconst [off2] base) mem) && ValAndOff(valoff1).canAdd(off2) -> + ((ADD|AND|OR|XOR|BTC|BTR|BTS)Lconstmodify [ValAndOff(valoff1).add(off2)] {sym} base mem) +((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Qmodify [off1] {sym} (ADDQconst [off2] base) val mem) && is32Bit(off1+off2) -> + ((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Qmodify [off1+off2] {sym} base val mem) +((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Lmodify [off1] {sym} (ADDQconst [off2] base) val mem) && is32Bit(off1+off2) -> + ((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Lmodify [off1+off2] {sym} base val mem) // Fold constants into stores. (MOVQstore [off] {sym} ptr (MOVQconst [c]) mem) && validValAndOff(c,off) -> @@ -1106,18 +1116,18 @@ ((ADD|SUB|MUL|DIV)SDload [off1] {sym1} val (LEAQ [off2] {sym2} base) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> ((ADD|SUB|MUL|DIV)SDload [off1+off2] {mergeSym(sym1,sym2)} val base mem) -((ADD|AND|OR|XOR)Qconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) +((ADD|AND|OR|XOR|BTC|BTR|BTS)Qconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) && ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) -> - ((ADD|AND|OR|XOR)Qconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) -((ADD|AND|OR|XOR)Lconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) + ((ADD|AND|OR|XOR|BTC|BTR|BTS)Qconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) +((ADD|AND|OR|XOR|BTC|BTR|BTS)Lconstmodify [valoff1] {sym1} (LEAQ [off2] {sym2} base) mem) && ValAndOff(valoff1).canAdd(off2) && canMergeSym(sym1, sym2) -> - ((ADD|AND|OR|XOR)Lconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) -((ADD|SUB|AND|OR|XOR)Qmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + ((ADD|AND|OR|XOR|BTC|BTR|BTS)Lconstmodify [ValAndOff(valoff1).add(off2)] {mergeSym(sym1,sym2)} base mem) +((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Qmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> - ((ADD|SUB|AND|OR|XOR)Qmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) -((ADD|SUB|AND|OR|XOR)Lmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) + ((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Qmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) +((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Lmodify [off1] {sym1} (LEAQ [off2] {sym2} base) val mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> - ((ADD|SUB|AND|OR|XOR)Lmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) + ((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Lmodify [off1+off2] {mergeSym(sym1,sym2)} base val mem) // generating indexed loads and stores (MOV(B|W|L|Q|SS|SD)load [off1] {sym1} (LEAQ1 [off2] {sym2} ptr idx) mem) && is32Bit(off1+off2) && canMergeSym(sym1, sym2) -> @@ -1424,6 +1434,12 @@ (XORLconst [c] (MOVLconst [d])) -> (MOVLconst [c^d]) (NOTQ (MOVQconst [c])) -> (MOVQconst [^c]) (NOTL (MOVLconst [c])) -> (MOVLconst [^c]) +(BTSQconst [c] (MOVQconst [d])) -> (MOVQconst [d|(1< (MOVLconst [d|(1< (MOVQconst [d&^(1< (MOVLconst [d&^(1< (MOVQconst [d^(1< (MOVLconst [d^(1< ((ADD|SUB|MUL|DIV)SDload x [off] {sym} ptr mem) ((ADD|SUB|MUL|DIV)SS x l:(MOVSSload [off] {sym} ptr mem)) && canMergeLoad(v, l, x) && clobber(l) -> ((ADD|SUB|MUL|DIV)SSload x [off] {sym} ptr mem) (MOVLstore {sym} [off] ptr y:((ADD|AND|OR|XOR)Lload x [off] {sym} ptr mem) mem) && y.Uses==1 && clobber(y) -> ((ADD|AND|OR|XOR)Lmodify [off] {sym} ptr x mem) -(MOVLstore {sym} [off] ptr y:((ADD|SUB|AND|OR|XOR)L l:(MOVLload [off] {sym} ptr mem) x) mem) && y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) -> - ((ADD|SUB|AND|OR|XOR)Lmodify [off] {sym} ptr x mem) +(MOVLstore {sym} [off] ptr y:((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)L l:(MOVLload [off] {sym} ptr mem) x) mem) && y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) -> + ((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Lmodify [off] {sym} ptr x mem) (MOVQstore {sym} [off] ptr y:((ADD|AND|OR|XOR)Qload x [off] {sym} ptr mem) mem) && y.Uses==1 && clobber(y) -> ((ADD|AND|OR|XOR)Qmodify [off] {sym} ptr x mem) -(MOVQstore {sym} [off] ptr y:((ADD|SUB|AND|OR|XOR)Q l:(MOVQload [off] {sym} ptr mem) x) mem) && y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) -> - ((ADD|SUB|AND|OR|XOR)Qmodify [off] {sym} ptr x mem) +(MOVQstore {sym} [off] ptr y:((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Q l:(MOVQload [off] {sym} ptr mem) x) mem) && y.Uses==1 && l.Uses==1 && clobber(y) && clobber(l) -> + ((ADD|SUB|AND|OR|XOR|BTC|BTR|BTS)Qmodify [off] {sym} ptr x mem) // Merge ADDQconst and LEAQ into atomic loads. (MOVQatomicload [off1] {sym} (ADDQconst [off2] ptr) mem) && is32Bit(off1+off2) -> @@ -2392,12 +2408,12 @@ (MOVWQZX (MOVBQZX x)) -> (MOVBQZX x) (MOVBQZX (MOVBQZX x)) -> (MOVBQZX x) -(MOVQstore [off] {sym} ptr a:((ADD|AND|OR|XOR)Qconst [c] l:(MOVQload [off] {sym} ptr2 mem)) mem) - && isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) -> - ((ADD|AND|OR|XOR)Qconstmodify {sym} [makeValAndOff(c,off)] ptr mem) -(MOVLstore [off] {sym} ptr a:((ADD|AND|OR|XOR)Lconst [c] l:(MOVLload [off] {sym} ptr2 mem)) mem) - && isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) -> - ((ADD|AND|OR|XOR)Lconstmodify {sym} [makeValAndOff(c,off)] ptr mem) +(MOVQstore [off] {sym} ptr a:((ADD|AND|OR|XOR|BTC|BTR|BTS)Qconst [c] l:(MOVQload [off] {sym} ptr2 mem)) mem) + && isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) && clobber(l) && clobber(a) -> + ((ADD|AND|OR|XOR|BTC|BTR|BTS)Qconstmodify {sym} [makeValAndOff(c,off)] ptr mem) +(MOVLstore [off] {sym} ptr a:((ADD|AND|OR|XOR|BTC|BTR|BTS)Lconst [c] l:(MOVLload [off] {sym} ptr2 mem)) mem) + && isSamePtr(ptr, ptr2) && a.Uses == 1 && l.Uses == 1 && validValAndOff(c,off) && clobber(l) && clobber(a) -> + ((ADD|AND|OR|XOR|BTC|BTR|BTS)Lconstmodify {sym} [makeValAndOff(c,off)] ptr mem) // float <-> int register moves, with no conversion. // These come up when compiling math.{Float{32,64}bits,Float{32,64}frombits}. diff --git a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go index 68facebe47e7c..017c07071d704 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/AMD64Ops.go @@ -289,6 +289,20 @@ func init() { {name: "BTSLconst", argLength: 1, reg: gp11, asm: "BTSL", resultInArg0: true, clobberFlags: true, aux: "Int8"}, // set bit auxint in arg0, 0 <= auxint < 32 {name: "BTSQconst", argLength: 1, reg: gp11, asm: "BTSQ", resultInArg0: true, clobberFlags: true, aux: "Int8"}, // set bit auxint in arg0, 0 <= auxint < 64 + // direct bit operation on memory operand + {name: "BTCQmodify", argLength: 3, reg: gpstore, asm: "BTCQ", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // complement bit arg1 in 64-bit arg0+auxint+aux, arg2=mem + {name: "BTCLmodify", argLength: 3, reg: gpstore, asm: "BTCL", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // complement bit arg1 in 32-bit arg0+auxint+aux, arg2=mem + {name: "BTSQmodify", argLength: 3, reg: gpstore, asm: "BTSQ", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // set bit arg1 in 64-bit arg0+auxint+aux, arg2=mem + {name: "BTSLmodify", argLength: 3, reg: gpstore, asm: "BTSL", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // set bit arg1 in 32-bit arg0+auxint+aux, arg2=mem + {name: "BTRQmodify", argLength: 3, reg: gpstore, asm: "BTRQ", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // reset bit arg1 in 64-bit arg0+auxint+aux, arg2=mem + {name: "BTRLmodify", argLength: 3, reg: gpstore, asm: "BTRL", aux: "SymOff", typ: "Mem", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // reset bit arg1 in 32-bit arg0+auxint+aux, arg2=mem + {name: "BTCQconstmodify", argLength: 2, reg: gpstoreconst, asm: "BTCQ", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // complement bit ValAndOff(AuxInt).Val() in 64-bit arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "BTCLconstmodify", argLength: 2, reg: gpstoreconst, asm: "BTCL", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // complement bit ValAndOff(AuxInt).Val() in 32-bit arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "BTSQconstmodify", argLength: 2, reg: gpstoreconst, asm: "BTSQ", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // set bit ValAndOff(AuxInt).Val() in 64-bit arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "BTSLconstmodify", argLength: 2, reg: gpstoreconst, asm: "BTSL", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // set bit ValAndOff(AuxInt).Val() in 32-bit arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "BTRQconstmodify", argLength: 2, reg: gpstoreconst, asm: "BTRQ", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // reset bit ValAndOff(AuxInt).Val() in 64-bit arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "BTRLconstmodify", argLength: 2, reg: gpstoreconst, asm: "BTRL", aux: "SymValAndOff", clobberFlags: true, faultOnNilArg0: true, symEffect: "Read,Write"}, // reset bit ValAndOff(AuxInt).Val() in 32-bit arg0+ValAndOff(AuxInt).Off()+aux, arg1=mem + {name: "TESTQ", argLength: 2, reg: gp2flags, commutative: true, asm: "TESTQ", typ: "Flags"}, // (arg0 & arg1) compare to 0 {name: "TESTL", argLength: 2, reg: gp2flags, commutative: true, asm: "TESTL", typ: "Flags"}, // (arg0 & arg1) compare to 0 {name: "TESTW", argLength: 2, reg: gp2flags, commutative: true, asm: "TESTW", typ: "Flags"}, // (arg0 & arg1) compare to 0 diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index 77b9875fd6291..fe63633750dec 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -550,6 +550,18 @@ const ( OpAMD64BTRQconst OpAMD64BTSLconst OpAMD64BTSQconst + OpAMD64BTCQmodify + OpAMD64BTCLmodify + OpAMD64BTSQmodify + OpAMD64BTSLmodify + OpAMD64BTRQmodify + OpAMD64BTRLmodify + OpAMD64BTCQconstmodify + OpAMD64BTCLconstmodify + OpAMD64BTSQconstmodify + OpAMD64BTSLconstmodify + OpAMD64BTRQconstmodify + OpAMD64BTRLconstmodify OpAMD64TESTQ OpAMD64TESTL OpAMD64TESTW @@ -6901,6 +6913,180 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "BTCQmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTCQ, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTCLmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTCL, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTSQmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTSQ, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTSLmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTSL, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTRQmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTRQ, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTRLmodify", + auxType: auxSymOff, + argLen: 3, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTRL, + reg: regInfo{ + inputs: []inputInfo{ + {1, 65535}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTCQconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTCQ, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTCLconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTCL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTSQconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTSQ, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTSLconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTSL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTRQconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTRQ, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, + { + name: "BTRLconstmodify", + auxType: auxSymValAndOff, + argLen: 2, + clobberFlags: true, + faultOnNilArg0: true, + symEffect: SymRead | SymWrite, + asm: x86.ABTRL, + reg: regInfo{ + inputs: []inputInfo{ + {0, 4295032831}, // AX CX DX BX SP BP SI DI R8 R9 R10 R11 R12 R13 R14 R15 SB + }, + }, + }, { name: "TESTQ", argLen: 2, diff --git a/src/cmd/compile/internal/ssa/rewriteAMD64.go b/src/cmd/compile/internal/ssa/rewriteAMD64.go index 98b36a96a075a..cd82a5642c8d8 100644 --- a/src/cmd/compile/internal/ssa/rewriteAMD64.go +++ b/src/cmd/compile/internal/ssa/rewriteAMD64.go @@ -65,18 +65,46 @@ func rewriteValueAMD64(v *Value) bool { return rewriteValueAMD64_OpAMD64ANDQmodify_0(v) case OpAMD64BSFQ: return rewriteValueAMD64_OpAMD64BSFQ_0(v) + case OpAMD64BTCLconst: + return rewriteValueAMD64_OpAMD64BTCLconst_0(v) + case OpAMD64BTCLconstmodify: + return rewriteValueAMD64_OpAMD64BTCLconstmodify_0(v) + case OpAMD64BTCLmodify: + return rewriteValueAMD64_OpAMD64BTCLmodify_0(v) + case OpAMD64BTCQconst: + return rewriteValueAMD64_OpAMD64BTCQconst_0(v) + case OpAMD64BTCQconstmodify: + return rewriteValueAMD64_OpAMD64BTCQconstmodify_0(v) + case OpAMD64BTCQmodify: + return rewriteValueAMD64_OpAMD64BTCQmodify_0(v) case OpAMD64BTLconst: return rewriteValueAMD64_OpAMD64BTLconst_0(v) case OpAMD64BTQconst: return rewriteValueAMD64_OpAMD64BTQconst_0(v) case OpAMD64BTRLconst: return rewriteValueAMD64_OpAMD64BTRLconst_0(v) + case OpAMD64BTRLconstmodify: + return rewriteValueAMD64_OpAMD64BTRLconstmodify_0(v) + case OpAMD64BTRLmodify: + return rewriteValueAMD64_OpAMD64BTRLmodify_0(v) case OpAMD64BTRQconst: return rewriteValueAMD64_OpAMD64BTRQconst_0(v) + case OpAMD64BTRQconstmodify: + return rewriteValueAMD64_OpAMD64BTRQconstmodify_0(v) + case OpAMD64BTRQmodify: + return rewriteValueAMD64_OpAMD64BTRQmodify_0(v) case OpAMD64BTSLconst: return rewriteValueAMD64_OpAMD64BTSLconst_0(v) + case OpAMD64BTSLconstmodify: + return rewriteValueAMD64_OpAMD64BTSLconstmodify_0(v) + case OpAMD64BTSLmodify: + return rewriteValueAMD64_OpAMD64BTSLmodify_0(v) case OpAMD64BTSQconst: return rewriteValueAMD64_OpAMD64BTSQconst_0(v) + case OpAMD64BTSQconstmodify: + return rewriteValueAMD64_OpAMD64BTSQconstmodify_0(v) + case OpAMD64BTSQmodify: + return rewriteValueAMD64_OpAMD64BTSQmodify_0(v) case OpAMD64CMOVLCC: return rewriteValueAMD64_OpAMD64CMOVLCC_0(v) case OpAMD64CMOVLCS: @@ -278,7 +306,7 @@ func rewriteValueAMD64(v *Value) bool { case OpAMD64MOVQloadidx8: return rewriteValueAMD64_OpAMD64MOVQloadidx8_0(v) case OpAMD64MOVQstore: - return rewriteValueAMD64_OpAMD64MOVQstore_0(v) || rewriteValueAMD64_OpAMD64MOVQstore_10(v) || rewriteValueAMD64_OpAMD64MOVQstore_20(v) + return rewriteValueAMD64_OpAMD64MOVQstore_0(v) || rewriteValueAMD64_OpAMD64MOVQstore_10(v) || rewriteValueAMD64_OpAMD64MOVQstore_20(v) || rewriteValueAMD64_OpAMD64MOVQstore_30(v) case OpAMD64MOVQstoreconst: return rewriteValueAMD64_OpAMD64MOVQstoreconst_0(v) case OpAMD64MOVQstoreconstidx1: @@ -3590,6 +3618,22 @@ func rewriteValueAMD64_OpAMD64ANDLconst_0(v *Value) bool { v.AddArg(x) return true } + // match: (ANDLconst [c] (BTRLconst [d] x)) + // cond: + // result: (ANDLconst [c &^ 1< Date: Tue, 18 Sep 2018 01:28:58 +0300 Subject: [PATCH 0410/1663] cmd/compile/internal/ssa: fix `a == a` to `a == b` Change-Id: I4ee4f702e1bfc9ad9ea899c255104d5e18cf2c96 Reviewed-on: https://go-review.googlesource.com/135838 Reviewed-by: Keith Randall Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/ssa/html.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/ssa/html.go b/src/cmd/compile/internal/ssa/html.go index c51ea02262fcd..b7d5f912db32c 100644 --- a/src/cmd/compile/internal/ssa/html.go +++ b/src/cmd/compile/internal/ssa/html.go @@ -484,7 +484,7 @@ func (x ByTopo) Swap(i, j int) { x[i], x[j] = x[j], x[i] } func (x ByTopo) Less(i, j int) bool { a := x[i] b := x[j] - if a.Filename == a.Filename { + if a.Filename == b.Filename { return a.StartLineno < b.StartLineno } return a.Filename < b.Filename From c03d0e4fec6b02c09d286dae5df2f63164d74ea1 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Mon, 17 Sep 2018 21:37:30 +0300 Subject: [PATCH 0411/1663] cmd/compile/internal/gc: handle arith ops in samesafeexpr Teach samesafeexpr to handle arithmetic unary and binary ops. It makes map lookup optimization possible in m[k+1] = append(m[k+1], ...) m[-k] = append(m[-k], ...) ... etc Does not cover "+" for strings (concatenation). Change-Id: Ibbb16ac3faf176958da344be1471b06d7cf33a6c Reviewed-on: https://go-review.googlesource.com/135795 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/typecheck.go | 6 ++++-- test/codegen/mapaccess.go | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index c2b84541852b5..69dced00ac729 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -3298,7 +3298,8 @@ func samesafeexpr(l *Node, r *Node) bool { case ODOT, ODOTPTR: return l.Sym != nil && r.Sym != nil && l.Sym == r.Sym && samesafeexpr(l.Left, r.Left) - case OIND, OCONVNOP: + case OIND, OCONVNOP, + ONOT, OCOM, OPLUS, OMINUS: return samesafeexpr(l.Left, r.Left) case OCONV: @@ -3306,7 +3307,8 @@ func samesafeexpr(l *Node, r *Node) bool { // Allow only numeric-ish types. This is a bit conservative. return issimple[l.Type.Etype] && samesafeexpr(l.Left, r.Left) - case OINDEX, OINDEXMAP: + case OINDEX, OINDEXMAP, + OADD, OSUB, OOR, OXOR, OMUL, OLSH, ORSH, OAND, OANDNOT, ODIV, OMOD: return samesafeexpr(l.Left, r.Left) && samesafeexpr(l.Right, r.Right) case OLITERAL: diff --git a/test/codegen/mapaccess.go b/test/codegen/mapaccess.go index 35620e741cedb..a914a0c766ece 100644 --- a/test/codegen/mapaccess.go +++ b/test/codegen/mapaccess.go @@ -304,6 +304,18 @@ func mapAppendAssignmentInt32() { // arm64:-".*mapaccess" m[k] = append(m[k], a...) + // 386:-".*mapaccess" + // amd64:-".*mapaccess" + // arm:-".*mapaccess" + // arm64:-".*mapaccess" + m[k+1] = append(m[k+1], a...) + + // 386:-".*mapaccess" + // amd64:-".*mapaccess" + // arm:-".*mapaccess" + // arm64:-".*mapaccess" + m[-k] = append(m[-k], a...) + // Exceptions // 386:".*mapaccess" @@ -349,6 +361,18 @@ func mapAppendAssignmentInt64() { // arm64:-".*mapaccess" m[k] = append(m[k], a...) + // 386:-".*mapaccess" + // amd64:-".*mapaccess" + // arm:-".*mapaccess" + // arm64:-".*mapaccess" + m[k+1] = append(m[k+1], a...) + + // 386:-".*mapaccess" + // amd64:-".*mapaccess" + // arm:-".*mapaccess" + // arm64:-".*mapaccess" + m[-k] = append(m[-k], a...) + // Exceptions // 386:".*mapaccess" From 88c1fd642ea0944b50962e1498273fee79d00e5f Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Tue, 18 Sep 2018 01:22:59 +0300 Subject: [PATCH 0412/1663] cmd/compile/internal/gc: remove redundant for label Since there are no nested loops and/or switches, loop label can be removed and "bare continue" can be used. Change-Id: Id642a0859299e4470af544d59884fec51dbb31ee Reviewed-on: https://go-review.googlesource.com/135837 Reviewed-by: Keith Randall Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/ssa/rewrite.go | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index a5b2da4709177..fd5f684edab1b 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -234,7 +234,6 @@ func canMergeLoad(target, load, x *Value) bool { // memPreds contains memory states known to be predecessors of load's // memory state. It is lazily initialized. var memPreds map[*Value]bool -search: for i := 0; len(args) > 0; i++ { const limit = 100 if i >= limit { @@ -246,13 +245,13 @@ search: if target.Block.ID != v.Block.ID { // Since target and load are in the same block // we can stop searching when we leave the block. - continue search + continue } if v.Op == OpPhi { // A Phi implies we have reached the top of the block. // The memory phi, if it exists, is always // the first logical store in the block. - continue search + continue } if v.Type.IsTuple() && v.Type.FieldType(1).IsMemory() { // We could handle this situation however it is likely @@ -296,14 +295,14 @@ search: // load = read ... mem // target = add x load if memPreds[v] { - continue search + continue } return false } if len(v.Args) > 0 && v.Args[len(v.Args)-1] == mem { // If v takes mem as an input then we know mem // is valid at this point. - continue search + continue } for _, a := range v.Args { if target.Block.ID == a.Block.ID { From f40dc5cb50aad720fb3d42b9d69c158dde07d0aa Mon Sep 17 00:00:00 2001 From: Tim Xu Date: Wed, 19 Sep 2018 03:39:46 +0000 Subject: [PATCH 0413/1663] clean: clean mod cache should respect "-n" option. Clean mod cache should print remove commands and not run them when with set "-n" option. Fixes #27458. Change-Id: I97242cb40c062b347784cdb61653c84a3a7eab44 GitHub-Last-Rev: 5a6f10cad8c5f2c3916a74ca5eea27b1fdd1dc38 GitHub-Pull-Request: golang/go#27710 Reviewed-on: https://go-review.googlesource.com/135695 Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- src/cmd/go/internal/clean/clean.go | 14 +++++++---- .../go/testdata/script/mod_clean_cache.txt | 23 +++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/cmd/go/testdata/script/mod_clean_cache.txt diff --git a/src/cmd/go/internal/clean/clean.go b/src/cmd/go/internal/clean/clean.go index d023592eedcea..b12bd981a70a0 100644 --- a/src/cmd/go/internal/clean/clean.go +++ b/src/cmd/go/internal/clean/clean.go @@ -112,9 +112,10 @@ func runClean(cmd *base.Command, args []string) { } } + var b work.Builder + b.Print = fmt.Print + if cleanCache { - var b work.Builder - b.Print = fmt.Print dir := cache.DefaultDir() if dir != "off" { // Remove the cache subdirectories but not the top cache directory. @@ -156,8 +157,13 @@ func runClean(cmd *base.Command, args []string) { if modfetch.PkgMod == "" { base.Fatalf("go clean -modcache: no module cache") } - if err := removeAll(modfetch.PkgMod); err != nil { - base.Errorf("go clean -modcache: %v", err) + if cfg.BuildN || cfg.BuildX { + b.Showcmd("", "rm -rf %s", modfetch.PkgMod) + } + if !cfg.BuildN { + if err := removeAll(modfetch.PkgMod); err != nil { + base.Errorf("go clean -modcache: %v", err) + } } } } diff --git a/src/cmd/go/testdata/script/mod_clean_cache.txt b/src/cmd/go/testdata/script/mod_clean_cache.txt new file mode 100644 index 0000000000000..66a0e9ea7e781 --- /dev/null +++ b/src/cmd/go/testdata/script/mod_clean_cache.txt @@ -0,0 +1,23 @@ +env GO111MODULE=on + +go mod download rsc.io/quote@v1.5.0 +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip + +go clean -modcache -n +stdout '^rm -rf .*pkg.mod$' +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod +exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip + +go clean -modcache +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.info +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.mod +! exists $GOPATH/pkg/mod/cache/download/rsc.io/quote/@v/v1.5.0.zip + +-- go.mod -- +module m + +-- m.go -- +package m \ No newline at end of file From 620bd5a3bc640f60a00d8b49c27c51e8ce67e67b Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Tue, 18 Sep 2018 14:00:25 -0400 Subject: [PATCH 0414/1663] cmd/go: write an hgrc file in TestMoveHG MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some variants of Mercurial respond differently to “permission denied” errors than to “file not found”, and we set HOME to point to an absolute path that may produce the former instead of the latter. To discourage Mercurial from trying HOME, give it an explicit (empty) configuration in the working directory instead. Change-Id: I82ae99a6892bba7fc3d41b77209ca181d24315e2 Reviewed-on: https://go-review.googlesource.com/136135 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/cmd/go/go_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 6bd0609eaffda..e7d96f62360fa 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -1074,6 +1074,8 @@ func testMove(t *testing.T, vcs, url, base, config string) { defer tg.cleanup() tg.parallel() tg.tempDir("src") + tg.must(os.Mkdir(tg.path(".hg"), 0700)) + tg.must(ioutil.WriteFile(filepath.Join(tg.path(".hg"), "hgrc"), nil, 0600)) tg.setenv("GOPATH", tg.path(".")) tg.run("get", "-d", url) tg.run("get", "-d", "-u", url) From e82d152e66e81812a5c6ebf075cc99efd2602b19 Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Tue, 18 Sep 2018 12:52:39 -0700 Subject: [PATCH 0415/1663] fmt: fix usage of sync.Pool The current usage of sync.Pool is leaky because it stores an arbitrary sized buffer into the pool. However, sync.Pool assumes that all items in the pool are interchangeable from a memory cost perspective. Due to the unbounded size of a buffer that may be added, it is possible for the pool to eventually pin arbitrarily large amounts of memory in a live-lock situation. As a simple fix, we just set a maximum size that we permit back into the pool. We do not need to fix the use of a sync.Pool in scan.go since the free method has always enforced a maximum capacity since the first commit of the scan logic. Fixes #27740 Updates #23199 Change-Id: I875278f7dba42625405df36df3e9b028252ce5e3 Reviewed-on: https://go-review.googlesource.com/136116 Reviewed-by: Bryan C. Mills Run-TryBot: Bryan C. Mills TryBot-Result: Gobot Gobot --- src/fmt/print.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/fmt/print.go b/src/fmt/print.go index c9d694b07dc88..32743d07123c1 100644 --- a/src/fmt/print.go +++ b/src/fmt/print.go @@ -139,6 +139,16 @@ func newPrinter() *pp { // free saves used pp structs in ppFree; avoids an allocation per invocation. func (p *pp) free() { + // Proper usage of a sync.Pool requires each entry to have approximately + // the same memory cost. To obtain this property when the stored type + // contains a variably-sized buffer, we add a hard limit on the maximum buffer + // to place back in the pool. + // + // See https://golang.org/issue/23199 + if cap(p.buf) > 64<<10 { + return + } + p.buf = p.buf[:0] p.arg = nil p.value = reflect.Value{} From 919d5aee22d3a56952f936dab63854aa1f141473 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 18 Sep 2018 20:50:04 -0700 Subject: [PATCH 0416/1663] cmd/compiler/internal/gc: remove flag argument from fconv (cleanup) The fconv flag arguments were 0, FmtSharp, and FmtSharp|FmtSign. The 0 value was used for binary representation only, which was readily available via Mpflt.String. Otherwise, FmtSharp was always passed. FmtSign was used to print the '+' sign in case of a positive number and only needed for complex number formatting. Instead implemented cconv and handled it there. Change-Id: I1f77282f995be9cfda05efb71a0e027836a9da26 Reviewed-on: https://go-review.googlesource.com/136195 Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/const.go | 8 ++++---- src/cmd/compile/internal/gc/fmt.go | 13 +++++-------- src/cmd/compile/internal/gc/mpfloat.go | 23 ++++++++++++----------- 3 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index 1403a2be11edf..d87c4980d06d5 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -476,7 +476,7 @@ func toflt(v Val) Val { f := newMpflt() f.Set(&u.Real) if u.Imag.CmpFloat64(0) != 0 { - yyerror("constant %v%vi truncated to real", fconv(&u.Real, FmtSharp), fconv(&u.Imag, FmtSharp|FmtSign)) + yyerror("constant %v truncated to real", cconv(u)) } v.U = f } @@ -509,11 +509,11 @@ func toint(v Val) Val { // value from the error message. // (See issue #11371). var t big.Float - t.Parse(fconv(u, FmtSharp), 10) + t.Parse(fconv(u), 10) if t.IsInt() { yyerror("constant truncated to integer") } else { - yyerror("constant %v truncated to integer", fconv(u, FmtSharp)) + yyerror("constant %v truncated to integer", fconv(u)) } } } @@ -522,7 +522,7 @@ func toint(v Val) Val { case *Mpcplx: i := new(Mpint) if !i.SetFloat(&u.Real) || u.Imag.CmpFloat64(0) != 0 { - yyerror("constant %v%vi truncated to integer", fconv(&u.Real, FmtSharp), fconv(&u.Imag, FmtSharp|FmtSign)) + yyerror("constant %v truncated to integer", cconv(u)) } v.U = i diff --git a/src/cmd/compile/internal/gc/fmt.go b/src/cmd/compile/internal/gc/fmt.go index 5b7445d4dbade..be8a7ef6f58da 100644 --- a/src/cmd/compile/internal/gc/fmt.go +++ b/src/cmd/compile/internal/gc/fmt.go @@ -537,10 +537,10 @@ func (v Val) vconv(s fmt.State, flag FmtFlag) { case *Mpflt: if flag&FmtSharp != 0 { - fmt.Fprint(s, fconv(u, 0)) + fmt.Fprint(s, u.String()) return } - fmt.Fprint(s, fconv(u, FmtSharp)) + fmt.Fprint(s, fconv(u)) return case *Mpcplx: @@ -549,16 +549,13 @@ func (v Val) vconv(s fmt.State, flag FmtFlag) { fmt.Fprintf(s, "(%v+%vi)", &u.Real, &u.Imag) case v.U.(*Mpcplx).Real.CmpFloat64(0) == 0: - fmt.Fprintf(s, "%vi", fconv(&u.Imag, FmtSharp)) + fmt.Fprintf(s, "%vi", fconv(&u.Imag)) case v.U.(*Mpcplx).Imag.CmpFloat64(0) == 0: - fmt.Fprint(s, fconv(&u.Real, FmtSharp)) - - case v.U.(*Mpcplx).Imag.CmpFloat64(0) < 0: - fmt.Fprintf(s, "(%v%vi)", fconv(&u.Real, FmtSharp), fconv(&u.Imag, FmtSharp)) + fmt.Fprint(s, fconv(&u.Real)) default: - fmt.Fprintf(s, "(%v+%vi)", fconv(&u.Real, FmtSharp), fconv(&u.Imag, FmtSharp)) + fmt.Fprintf(s, "(%v)", cconv(u)) } case string: diff --git a/src/cmd/compile/internal/gc/mpfloat.go b/src/cmd/compile/internal/gc/mpfloat.go index 5977ef9748e8a..8837628d86648 100644 --- a/src/cmd/compile/internal/gc/mpfloat.go +++ b/src/cmd/compile/internal/gc/mpfloat.go @@ -201,24 +201,16 @@ func (a *Mpflt) SetString(as string) { } func (f *Mpflt) String() string { - return fconv(f, 0) + return f.Val.Text('b', 0) } -func fconv(fvp *Mpflt, flag FmtFlag) string { - if flag&FmtSharp == 0 { - return fvp.Val.Text('b', 0) - } - - // use decimal format for error messages - +func fconv(fvp *Mpflt) string { // determine sign + sign := "" f := &fvp.Val - var sign string if f.Sign() < 0 { sign = "-" f = new(big.Float).Abs(f) - } else if flag&FmtSign != 0 { - sign = "+" } // Don't try to convert infinities (will not terminate). @@ -334,3 +326,12 @@ func (v *Mpcplx) Div(rv *Mpcplx) bool { return true } + +func cconv(v *Mpcplx) string { + re := fconv(&v.Real) + im := fconv(&v.Imag) + if im[0] == '-' { + return re + im + "i" + } + return re + "+" + im + "i" +} From 3f99d2738d214fdc9aeaaa9ced26431ec1f8166d Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 18 Sep 2018 21:15:19 -0700 Subject: [PATCH 0417/1663] cmd/compiler/internal/gc: remove flag from bconv (cleanup) Change-Id: I863eb8ef491e1d51b83d8dd3061bf11cbdc74a3e Reviewed-on: https://go-review.googlesource.com/136196 Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/fmt.go | 4 ++-- src/cmd/compile/internal/gc/mpint.go | 9 +++------ 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/cmd/compile/internal/gc/fmt.go b/src/cmd/compile/internal/gc/fmt.go index be8a7ef6f58da..0fecb5d595177 100644 --- a/src/cmd/compile/internal/gc/fmt.go +++ b/src/cmd/compile/internal/gc/fmt.go @@ -514,10 +514,10 @@ func (v Val) vconv(s fmt.State, flag FmtFlag) { case *Mpint: if !u.Rune { if flag&FmtSharp != 0 { - fmt.Fprint(s, bconv(u, FmtSharp)) + fmt.Fprint(s, bconv(u)) return } - fmt.Fprint(s, bconv(u, 0)) + fmt.Fprint(s, u.String()) return } diff --git a/src/cmd/compile/internal/gc/mpint.go b/src/cmd/compile/internal/gc/mpint.go index de47205435459..4f49e1505d5e5 100644 --- a/src/cmd/compile/internal/gc/mpint.go +++ b/src/cmd/compile/internal/gc/mpint.go @@ -300,12 +300,9 @@ func (a *Mpint) SetString(as string) { } func (a *Mpint) String() string { - return bconv(a, 0) + return a.Val.String() } -func bconv(xval *Mpint, flag FmtFlag) string { - if flag&FmtSharp != 0 { - return fmt.Sprintf("%#x", &xval.Val) - } - return xval.Val.String() +func bconv(a *Mpint) string { + return fmt.Sprintf("%#x", &a.Val) } From 9c2e5f297136f4fa31e1731313b8c09b7aead108 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 18 Sep 2018 21:55:35 -0700 Subject: [PATCH 0418/1663] cmd/compile/internal/gc: better names for (b|c|f)conf (cleanup) Use String and GoString methods instead of the xconf names for the numeric conversion routines. Also, fixed a couple of comments in fmt.go. Change-Id: I1b8acdd95dbff3fc30273070fbb1ac4860031a3c Reviewed-on: https://go-review.googlesource.com/136197 Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/const.go | 8 +++--- src/cmd/compile/internal/gc/fmt.go | 32 +++++++++-------------- src/cmd/compile/internal/gc/mpfloat.go | 36 +++++++++++++++++++++----- src/cmd/compile/internal/gc/mpint.go | 4 +-- 4 files changed, 47 insertions(+), 33 deletions(-) diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index d87c4980d06d5..3466472aa72f5 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -476,7 +476,7 @@ func toflt(v Val) Val { f := newMpflt() f.Set(&u.Real) if u.Imag.CmpFloat64(0) != 0 { - yyerror("constant %v truncated to real", cconv(u)) + yyerror("constant %v truncated to real", u.GoString()) } v.U = f } @@ -509,11 +509,11 @@ func toint(v Val) Val { // value from the error message. // (See issue #11371). var t big.Float - t.Parse(fconv(u), 10) + t.Parse(u.GoString(), 10) if t.IsInt() { yyerror("constant truncated to integer") } else { - yyerror("constant %v truncated to integer", fconv(u)) + yyerror("constant %v truncated to integer", u.GoString()) } } } @@ -522,7 +522,7 @@ func toint(v Val) Val { case *Mpcplx: i := new(Mpint) if !i.SetFloat(&u.Real) || u.Imag.CmpFloat64(0) != 0 { - yyerror("constant %v truncated to integer", cconv(u)) + yyerror("constant %v truncated to integer", u.GoString()) } v.U = i diff --git a/src/cmd/compile/internal/gc/fmt.go b/src/cmd/compile/internal/gc/fmt.go index 0fecb5d595177..d3d672ea3292a 100644 --- a/src/cmd/compile/internal/gc/fmt.go +++ b/src/cmd/compile/internal/gc/fmt.go @@ -119,7 +119,7 @@ const ( // *types.Type: // %#v Go format // %#L type definition instead of name -// %#S omit"func" and receiver in function signature +// %#S omit "func" and receiver in function signature // // %-v type identifiers // %-S type identifiers without "func" and arg names in type signatures (methodsym) @@ -514,10 +514,10 @@ func (v Val) vconv(s fmt.State, flag FmtFlag) { case *Mpint: if !u.Rune { if flag&FmtSharp != 0 { - fmt.Fprint(s, bconv(u)) + fmt.Fprint(s, u.String()) return } - fmt.Fprint(s, u.String()) + fmt.Fprint(s, u.GoString()) return } @@ -540,23 +540,16 @@ func (v Val) vconv(s fmt.State, flag FmtFlag) { fmt.Fprint(s, u.String()) return } - fmt.Fprint(s, fconv(u)) + fmt.Fprint(s, u.GoString()) return case *Mpcplx: - switch { - case flag&FmtSharp != 0: - fmt.Fprintf(s, "(%v+%vi)", &u.Real, &u.Imag) - - case v.U.(*Mpcplx).Real.CmpFloat64(0) == 0: - fmt.Fprintf(s, "%vi", fconv(&u.Imag)) - - case v.U.(*Mpcplx).Imag.CmpFloat64(0) == 0: - fmt.Fprint(s, fconv(&u.Real)) - - default: - fmt.Fprintf(s, "(%v)", cconv(u)) + if flag&FmtSharp != 0 { + fmt.Fprint(s, u.String()) + return } + fmt.Fprint(s, u.GoString()) + return case string: fmt.Fprint(s, strconv.Quote(u)) @@ -668,7 +661,7 @@ func typefmt(t *types.Type, flag FmtFlag, mode fmtMode, depth int) string { return "error" } - // Unless the 'l' flag was specified, if the type has a name, just print that name. + // Unless the 'L' flag was specified, if the type has a name, just print that name. if flag&FmtLong == 0 && t.Sym != nil && t != types.Types[t.Etype] { switch mode { case FTypeId, FTypeIdName: @@ -1529,9 +1522,8 @@ func (n *Node) exprfmt(s fmt.State, prec int, mode fmtMode) { func (n *Node) nodefmt(s fmt.State, flag FmtFlag, mode fmtMode) { t := n.Type - // We almost always want the original, except in export mode for literals. - // This saves the importer some work, and avoids us having to redo some - // special casing for package unsafe. + // We almost always want the original. + // TODO(gri) Why the special case for OLITERAL? if n.Op != OLITERAL && n.Orig != nil { n = n.Orig } diff --git a/src/cmd/compile/internal/gc/mpfloat.go b/src/cmd/compile/internal/gc/mpfloat.go index 8837628d86648..d1f5cb12001c2 100644 --- a/src/cmd/compile/internal/gc/mpfloat.go +++ b/src/cmd/compile/internal/gc/mpfloat.go @@ -204,7 +204,7 @@ func (f *Mpflt) String() string { return f.Val.Text('b', 0) } -func fconv(fvp *Mpflt) string { +func (fvp *Mpflt) GoString() string { // determine sign sign := "" f := &fvp.Val @@ -327,11 +327,33 @@ func (v *Mpcplx) Div(rv *Mpcplx) bool { return true } -func cconv(v *Mpcplx) string { - re := fconv(&v.Real) - im := fconv(&v.Imag) - if im[0] == '-' { - return re + im + "i" +func (v *Mpcplx) String() string { + return fmt.Sprintf("(%s+%si)", v.Real.String(), v.Imag.String()) +} + +func (v *Mpcplx) GoString() string { + var re string + sre := v.Real.CmpFloat64(0) + if sre != 0 { + re = v.Real.GoString() + } + + var im string + sim := v.Imag.CmpFloat64(0) + if sim != 0 { + im = v.Imag.GoString() + } + + switch { + case sre == 0 && sim == 0: + return "0" + case sre == 0: + return im + "i" + case sim == 0: + return re + case sim < 0: + return fmt.Sprintf("(%s%si)", re, im) + default: + return fmt.Sprintf("(%s+%si)", re, im) } - return re + "+" + im + "i" } diff --git a/src/cmd/compile/internal/gc/mpint.go b/src/cmd/compile/internal/gc/mpint.go index 4f49e1505d5e5..e4dd22d0a02e0 100644 --- a/src/cmd/compile/internal/gc/mpint.go +++ b/src/cmd/compile/internal/gc/mpint.go @@ -299,10 +299,10 @@ func (a *Mpint) SetString(as string) { } } -func (a *Mpint) String() string { +func (a *Mpint) GoString() string { return a.Val.String() } -func bconv(a *Mpint) string { +func (a *Mpint) String() string { return fmt.Sprintf("%#x", &a.Val) } From ae37f5a39721e5cd6177fec4a9c6e32a86c07376 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 19 Sep 2018 15:55:36 -0700 Subject: [PATCH 0419/1663] cmd/compile: fix error message for &T{} literal mismatch See the change and comment in typecheck.go for a detailed explanation. Fixes #26855. Change-Id: I7867f948490fc0873b1bd849048cda6acbc36e76 Reviewed-on: https://go-review.googlesource.com/136395 Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/typecheck.go | 8 +++++++ test/fixedbugs/issue26855.go | 28 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 test/fixedbugs/issue26855.go diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 69dced00ac729..6b4673dbdc651 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -2923,6 +2923,14 @@ func typecheckcomplit(n *Node) *Node { // Save original node (including n.Right) norig := n.copy() + // If n.Orig points to itself, norig.Orig must point to itself, too. + // Otherwise, because n.Op is changed below, n.Orig's Op is changed + // as well because it (and the copy norig) still point to the original + // node n. This caused the wrong complit Op to be used when printing + // error messages (issue #26855). + if n.Orig == n { + norig.Orig = norig + } setlineno(n.Right) n.Right = typecheck(n.Right, Etype|Ecomplit) diff --git a/test/fixedbugs/issue26855.go b/test/fixedbugs/issue26855.go new file mode 100644 index 0000000000000..d5b95ddbf1bb7 --- /dev/null +++ b/test/fixedbugs/issue26855.go @@ -0,0 +1,28 @@ +// errorcheck + +// Copyright 2012 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. + +// Verify that we get the correct (T vs &T) literal specification +// in the error message. + +package p + +type S struct { + f T +} + +type P struct { + f *T +} + +type T struct{} + +var _ = S{ + f: &T{}, // ERROR "cannot use &T literal" +} + +var _ = P{ + f: T{}, // ERROR "cannot use T literal" +} From 048c766e660e70e6e3779e479a2ab535b3865a21 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 19 Sep 2018 16:19:05 -0700 Subject: [PATCH 0420/1663] cmd/compile/internal/gc: minor code reorg (cleanup) Found while tracking down #26855. Change-Id: Ice137fe390820ba351e1c7439b6a9a1b3bdc966b Reviewed-on: https://go-review.googlesource.com/136396 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/fmt.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cmd/compile/internal/gc/fmt.go b/src/cmd/compile/internal/gc/fmt.go index d3d672ea3292a..5d2e36ee51079 100644 --- a/src/cmd/compile/internal/gc/fmt.go +++ b/src/cmd/compile/internal/gc/fmt.go @@ -1304,16 +1304,14 @@ func (n *Node) exprfmt(s fmt.State, prec int, mode fmtMode) { mode.Fprintf(s, "%v { %v }", n.Type, n.Func.Closure.Nbody) case OCOMPLIT: - ptrlit := n.Right != nil && n.Right.Implicit() && n.Right.Type != nil && n.Right.Type.IsPtr() if mode == FErr { if n.Right != nil && n.Right.Type != nil && !n.Implicit() { - if ptrlit { + if n.Right.Implicit() && n.Right.Type.IsPtr() { mode.Fprintf(s, "&%v literal", n.Right.Type.Elem()) return - } else { - mode.Fprintf(s, "%v literal", n.Right.Type) - return } + mode.Fprintf(s, "%v literal", n.Right.Type) + return } fmt.Fprint(s, "composite literal") From 9a033bf9d3f5f7485d82836ec95e51a3fa74a926 Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 20 Sep 2018 01:26:17 +0000 Subject: [PATCH 0421/1663] cmd/compile: optimize 386's assembly generator The ADDconstmodify has similar logic with other constmodify like instructions. This CL optimize them to share code via fallthrough. And the size of pkg/linux_386/cmd/compile/internal/x86.a decreases about 0.3KB. Change-Id: Ibdf06228afde875e8fe8e30851b50ca2be513dd9 Reviewed-on: https://go-review.googlesource.com/136398 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/x86/ssa.go | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/cmd/compile/internal/x86/ssa.go b/src/cmd/compile/internal/x86/ssa.go index a53b63ab92e2d..e0bb4418ecac4 100644 --- a/src/cmd/compile/internal/x86/ssa.go +++ b/src/cmd/compile/internal/x86/ssa.go @@ -547,22 +547,22 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.To.Reg = v.Args[0].Reg() gc.AddAux(&p.To, v) case ssa.Op386ADDLconstmodify: - var p *obj.Prog = nil sc := v.AuxValAndOff() - off := sc.Off() val := sc.Val() - if val == 1 { - p = s.Prog(x86.AINCL) - } else if val == -1 { - p = s.Prog(x86.ADECL) - } else { - p = s.Prog(v.Op.Asm()) - p.From.Type = obj.TYPE_CONST - p.From.Offset = val + if val == 1 || val == -1 { + var p *obj.Prog + if val == 1 { + p = s.Prog(x86.AINCL) + } else { + p = s.Prog(x86.ADECL) + } + off := sc.Off() + p.To.Type = obj.TYPE_MEM + p.To.Reg = v.Args[0].Reg() + gc.AddAux2(&p.To, v, off) + break } - p.To.Type = obj.TYPE_MEM - p.To.Reg = v.Args[0].Reg() - gc.AddAux2(&p.To, v, off) + fallthrough case ssa.Op386ANDLconstmodify, ssa.Op386ORLconstmodify, ssa.Op386XORLconstmodify: sc := v.AuxValAndOff() off := sc.Off() From 499fbb1a8ae20a69aa7f49287c65eec845963a30 Mon Sep 17 00:00:00 2001 From: Iskander Sharipov Date: Wed, 19 Sep 2018 15:53:03 +0300 Subject: [PATCH 0422/1663] cmd/compile/internal/gc: unify self-assignment checks in esc.go Move slice self-assign check into isSelfAssign function. Make debug output consistent for all self-assignment cases. Change-Id: I0e4cc7b3c1fcaeace7226dd80a0dc1ea97347a55 Reviewed-on: https://go-review.googlesource.com/136276 Run-TryBot: Iskander Sharipov TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/gc/esc.go | 11 ++++------- test/escape2.go | 20 ++++++++++---------- test/escape2n.go | 20 ++++++++++---------- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/src/cmd/compile/internal/gc/esc.go b/src/cmd/compile/internal/gc/esc.go index ad4d11806c84d..145007f5e1bb6 100644 --- a/src/cmd/compile/internal/gc/esc.go +++ b/src/cmd/compile/internal/gc/esc.go @@ -705,6 +705,10 @@ func (e *EscState) isSliceSelfAssign(dst, src *Node) bool { // isSelfAssign reports whether assignment from src to dst can // be ignored by the escape analysis as it's effectively a self-assignment. func (e *EscState) isSelfAssign(dst, src *Node) bool { + if e.isSliceSelfAssign(dst, src) { + return true + } + // Detect trivial assignments that assign back to the same object. // // It covers these cases: @@ -890,13 +894,6 @@ opSwitch: case OAS, OASOP: // Filter out some no-op assignments for escape analysis. - if e.isSliceSelfAssign(n.Left, n.Right) { - if Debug['m'] != 0 { - Warnl(n.Pos, "%v ignoring self-assignment to %S", e.curfnSym(n), n.Left) - } - - break - } if e.isSelfAssign(n.Left, n.Right) { if Debug['m'] != 0 { Warnl(n.Pos, "%v ignoring self-assignment in %S", e.curfnSym(n), n) diff --git a/test/escape2.go b/test/escape2.go index 5c4c803249f6d..a39291e85558d 100644 --- a/test/escape2.go +++ b/test/escape2.go @@ -1602,10 +1602,10 @@ type Buffer struct { } func (b *Buffer) foo() { // ERROR "\(\*Buffer\).foo b does not escape$" - b.buf1 = b.buf1[1:2] // ERROR "\(\*Buffer\).foo ignoring self-assignment to b.buf1$" - b.buf1 = b.buf1[1:2:3] // ERROR "\(\*Buffer\).foo ignoring self-assignment to b.buf1$" - b.buf1 = b.buf2[1:2] // ERROR "\(\*Buffer\).foo ignoring self-assignment to b.buf1$" - b.buf1 = b.buf2[1:2:3] // ERROR "\(\*Buffer\).foo ignoring self-assignment to b.buf1$" + b.buf1 = b.buf1[1:2] // ERROR "\(\*Buffer\).foo ignoring self-assignment in b.buf1 = b.buf1\[1:2\]$" + b.buf1 = b.buf1[1:2:3] // ERROR "\(\*Buffer\).foo ignoring self-assignment in b.buf1 = b.buf1\[1:2:3\]$" + b.buf1 = b.buf2[1:2] // ERROR "\(\*Buffer\).foo ignoring self-assignment in b.buf1 = b.buf2\[1:2\]$" + b.buf1 = b.buf2[1:2:3] // ERROR "\(\*Buffer\).foo ignoring self-assignment in b.buf1 = b.buf2\[1:2:3\]$" } func (b *Buffer) bar() { // ERROR "leaking param: b$" @@ -1613,13 +1613,13 @@ func (b *Buffer) bar() { // ERROR "leaking param: b$" } func (b *Buffer) arrayPtr() { // ERROR "\(\*Buffer\).arrayPtr b does not escape" - b.buf1 = b.arrPtr[1:2] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment to b.buf1" - b.buf1 = b.arrPtr[1:2:3] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment to b.buf1" + b.buf1 = b.arrPtr[1:2] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment in b.buf1 = b.arrPtr\[1:2\]$" + b.buf1 = b.arrPtr[1:2:3] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment in b.buf1 = b.arrPtr\[1:2:3\]$" } func (b *Buffer) baz() { // ERROR "\(\*Buffer\).baz b does not escape$" - b.str1 = b.str1[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment to b.str1$" - b.str1 = b.str2[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment to b.str1$" + b.str1 = b.str1[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment in b.str1 = b.str1\[1:2\]$" + b.str1 = b.str2[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment in b.str1 = b.str2\[1:2\]$" } func (b *Buffer) bat() { // ERROR "leaking param content: b$" @@ -1629,8 +1629,8 @@ func (b *Buffer) bat() { // ERROR "leaking param content: b$" } func quux(sp *string, bp *[]byte) { // ERROR "quux bp does not escape$" "quux sp does not escape$" - *sp = (*sp)[1:2] // ERROR "quux ignoring self-assignment to \*sp$" - *bp = (*bp)[1:2] // ERROR "quux ignoring self-assignment to \*bp$" + *sp = (*sp)[1:2] // ERROR "quux ignoring self-assignment in \*sp = \(\*sp\)\[1:2\]$" + *bp = (*bp)[1:2] // ERROR "quux ignoring self-assignment in \*bp = \(\*bp\)\[1:2\]$" } type StructWithString struct { diff --git a/test/escape2n.go b/test/escape2n.go index 4b1ca1eab8b7b..989cf18d35dbe 100644 --- a/test/escape2n.go +++ b/test/escape2n.go @@ -1602,10 +1602,10 @@ type Buffer struct { } func (b *Buffer) foo() { // ERROR "\(\*Buffer\).foo b does not escape$" - b.buf1 = b.buf1[1:2] // ERROR "\(\*Buffer\).foo ignoring self-assignment to b.buf1$" - b.buf1 = b.buf1[1:2:3] // ERROR "\(\*Buffer\).foo ignoring self-assignment to b.buf1$" - b.buf1 = b.buf2[1:2] // ERROR "\(\*Buffer\).foo ignoring self-assignment to b.buf1$" - b.buf1 = b.buf2[1:2:3] // ERROR "\(\*Buffer\).foo ignoring self-assignment to b.buf1$" + b.buf1 = b.buf1[1:2] // ERROR "\(\*Buffer\).foo ignoring self-assignment in b.buf1 = b.buf1\[1:2\]$" + b.buf1 = b.buf1[1:2:3] // ERROR "\(\*Buffer\).foo ignoring self-assignment in b.buf1 = b.buf1\[1:2:3\]$" + b.buf1 = b.buf2[1:2] // ERROR "\(\*Buffer\).foo ignoring self-assignment in b.buf1 = b.buf2\[1:2\]$" + b.buf1 = b.buf2[1:2:3] // ERROR "\(\*Buffer\).foo ignoring self-assignment in b.buf1 = b.buf2\[1:2:3\]$" } func (b *Buffer) bar() { // ERROR "leaking param: b$" @@ -1613,13 +1613,13 @@ func (b *Buffer) bar() { // ERROR "leaking param: b$" } func (b *Buffer) arrayPtr() { // ERROR "\(\*Buffer\).arrayPtr b does not escape" - b.buf1 = b.arrPtr[1:2] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment to b.buf1" - b.buf1 = b.arrPtr[1:2:3] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment to b.buf1" + b.buf1 = b.arrPtr[1:2] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment in b.buf1 = b.arrPtr\[1:2\]$" + b.buf1 = b.arrPtr[1:2:3] // ERROR "\(\*Buffer\).arrayPtr ignoring self-assignment in b.buf1 = b.arrPtr\[1:2:3\]$" } func (b *Buffer) baz() { // ERROR "\(\*Buffer\).baz b does not escape$" - b.str1 = b.str1[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment to b.str1$" - b.str1 = b.str2[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment to b.str1$" + b.str1 = b.str1[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment in b.str1 = b.str1\[1:2\]$" + b.str1 = b.str2[1:2] // ERROR "\(\*Buffer\).baz ignoring self-assignment in b.str1 = b.str2\[1:2\]$" } func (b *Buffer) bat() { // ERROR "leaking param content: b$" @@ -1629,8 +1629,8 @@ func (b *Buffer) bat() { // ERROR "leaking param content: b$" } func quux(sp *string, bp *[]byte) { // ERROR "quux bp does not escape$" "quux sp does not escape$" - *sp = (*sp)[1:2] // ERROR "quux ignoring self-assignment to \*sp$" - *bp = (*bp)[1:2] // ERROR "quux ignoring self-assignment to \*bp$" + *sp = (*sp)[1:2] // ERROR "quux ignoring self-assignment in \*sp = \(\*sp\)\[1:2\]$" + *bp = (*bp)[1:2] // ERROR "quux ignoring self-assignment in \*bp = \(\*bp\)\[1:2\]$" } type StructWithString struct { From ce58a39fca067a19c505220c0c907ccf32793427 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 20 Sep 2018 15:22:33 -0700 Subject: [PATCH 0423/1663] cmd/compile/internal/gc: fix Node.copy and introduce (raw|sep)copy Node.copy used to make a shallow copy of a node. Often, this is not correct: If a node n's Orig field pointed to itself, the copy's Orig field has to be adjusted to point to the copy. Otherwise, if n is modified later, the copy's Orig appears modified as well (because it points to n). This was fixed for one specific case with https://go-review.googlesource.com/c/go/+/136395 (issue #26855). This change instead addresses copy in general: In two cases we don't want the Orig adjustment as it causes escape analysis output to fail (not match the existing error messages). rawcopy is used in those cases. In several cases Orig is set to the copy immediately after making a copy; a new function sepcopy is used there. Updates #26855. Fixes #27765. Change-Id: Idaadeb5c4b9a027daabd46a2361348f7a93f2b00 Reviewed-on: https://go-review.googlesource.com/136540 Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/const.go | 7 +++-- src/cmd/compile/internal/gc/order.go | 12 +++------ src/cmd/compile/internal/gc/sinit.go | 12 +++------ src/cmd/compile/internal/gc/subr.go | 33 +++++++++++++++++++++--- src/cmd/compile/internal/gc/typecheck.go | 8 ------ src/cmd/compile/internal/gc/walk.go | 2 +- 6 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/cmd/compile/internal/gc/const.go b/src/cmd/compile/internal/gc/const.go index 3466472aa72f5..02d51678be060 100644 --- a/src/cmd/compile/internal/gc/const.go +++ b/src/cmd/compile/internal/gc/const.go @@ -234,7 +234,7 @@ func convlit1(n *Node, t *types.Type, explicit bool, reuse canReuseNode) *Node { if n.Op == OLITERAL && !reuse { // Can't always set n.Type directly on OLITERAL nodes. // See discussion on CL 20813. - n = n.copy() + n = n.rawcopy() reuse = true } @@ -1200,8 +1200,7 @@ func setconst(n *Node, v Val) { // Ensure n.Orig still points to a semantically-equivalent // expression after we rewrite n into a constant. if n.Orig == n { - n.Orig = n.copy() - n.Orig.Orig = n.Orig + n.Orig = n.sepcopy() } *n = Node{ @@ -1331,7 +1330,7 @@ func defaultlitreuse(n *Node, t *types.Type, reuse canReuseNode) *Node { } if n.Op == OLITERAL && !reuse { - n = n.copy() + n = n.rawcopy() reuse = true } diff --git a/src/cmd/compile/internal/gc/order.go b/src/cmd/compile/internal/gc/order.go index dce68a6c17ed0..1e22ecfcdf8d8 100644 --- a/src/cmd/compile/internal/gc/order.go +++ b/src/cmd/compile/internal/gc/order.go @@ -109,8 +109,7 @@ func (o *Order) cheapExpr(n *Node) *Node { if l == n.Left { return n } - a := n.copy() - a.Orig = a + a := n.sepcopy() a.Left = l return typecheck(a, Erv) } @@ -135,8 +134,7 @@ func (o *Order) safeExpr(n *Node) *Node { if l == n.Left { return n } - a := n.copy() - a.Orig = a + a := n.sepcopy() a.Left = l return typecheck(a, Erv) @@ -145,8 +143,7 @@ func (o *Order) safeExpr(n *Node) *Node { if l == n.Left { return n } - a := n.copy() - a.Orig = a + a := n.sepcopy() a.Left = l return typecheck(a, Erv) @@ -161,8 +158,7 @@ func (o *Order) safeExpr(n *Node) *Node { if l == n.Left && r == n.Right { return n } - a := n.copy() - a.Orig = a + a := n.sepcopy() a.Left = l a.Right = r return typecheck(a, Erv) diff --git a/src/cmd/compile/internal/gc/sinit.go b/src/cmd/compile/internal/gc/sinit.go index c6455c369318f..f76b02828ff63 100644 --- a/src/cmd/compile/internal/gc/sinit.go +++ b/src/cmd/compile/internal/gc/sinit.go @@ -349,15 +349,13 @@ func staticcopy(l *Node, r *Node, out *[]*Node) bool { gdata(n, e.Expr, int(n.Type.Width)) continue } - ll := n.copy() - ll.Orig = ll // completely separate copy + ll := n.sepcopy() if staticassign(ll, e.Expr, out) { continue } // Requires computation, but we're // copying someone else's computation. - rr := orig.copy() - rr.Orig = rr // completely separate copy + rr := orig.sepcopy() rr.Type = ll.Type rr.Xoffset += e.Xoffset setlineno(rr) @@ -453,8 +451,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool { continue } setlineno(e.Expr) - a := n.copy() - a.Orig = a // completely separate copy + a := n.sepcopy() if !staticassign(a, e.Expr, out) { *out = append(*out, nod(OAS, a, e.Expr)) } @@ -518,8 +515,7 @@ func staticassign(l *Node, r *Node, out *[]*Node) bool { // Copy val directly into n. n.Type = val.Type setlineno(val) - a := n.copy() - a.Orig = a + a := n.sepcopy() if !staticassign(a, val, out) { *out = append(*out, nod(OAS, a, val)) } diff --git a/src/cmd/compile/internal/gc/subr.go b/src/cmd/compile/internal/gc/subr.go index 61a3b2385d3a6..7e450e2e668f5 100644 --- a/src/cmd/compile/internal/gc/subr.go +++ b/src/cmd/compile/internal/gc/subr.go @@ -364,9 +364,35 @@ func nodSym(op Op, left *Node, sym *types.Sym) *Node { return n } +// rawcopy returns a shallow copy of n. +// Note: copy or sepcopy (rather than rawcopy) is usually the +// correct choice (see comment with Node.copy, below). +func (n *Node) rawcopy() *Node { + copy := *n + return © +} + +// sepcopy returns a separate shallow copy of n, with the copy's +// Orig pointing to itself. +func (n *Node) sepcopy() *Node { + copy := *n + copy.Orig = © + return © +} + +// copy returns shallow copy of n and adjusts the copy's Orig if +// necessary: In general, if n.Orig points to itself, the copy's +// Orig should point to itself as well. Otherwise, if n is modified, +// the copy's Orig node appears modified, too, and then doesn't +// represent the original node anymore. +// (This caused the wrong complit Op to be used when printing error +// messages; see issues #26855, #27765). func (n *Node) copy() *Node { - n2 := *n - return &n2 + copy := *n + if n.Orig == n { + copy.Orig = © + } + return © } // methcmp sorts methods by symbol. @@ -412,8 +438,7 @@ func treecopy(n *Node, pos src.XPos) *Node { switch n.Op { default: - m := n.copy() - m.Orig = m + m := n.sepcopy() m.Left = treecopy(n.Left, pos) m.Right = treecopy(n.Right, pos) m.List.Set(listtreecopy(n.List.Slice(), pos)) diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 6b4673dbdc651..69dced00ac729 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -2923,14 +2923,6 @@ func typecheckcomplit(n *Node) *Node { // Save original node (including n.Right) norig := n.copy() - // If n.Orig points to itself, norig.Orig must point to itself, too. - // Otherwise, because n.Op is changed below, n.Orig's Op is changed - // as well because it (and the copy norig) still point to the original - // node n. This caused the wrong complit Op to be used when printing - // error messages (issue #26855). - if n.Orig == n { - norig.Orig = norig - } setlineno(n.Right) n.Right = typecheck(n.Right, Etype|Ecomplit) diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 0b382bbbf047e..1b1d36b61d2f3 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -4052,7 +4052,7 @@ func wrapCall(n *Node, init *Nodes) *Node { // The result of substArgTypes MUST be assigned back to old, e.g. // n.Left = substArgTypes(n.Left, t1, t2) func substArgTypes(old *Node, types_ ...*types.Type) *Node { - n := old.copy() // make shallow copy + n := old.copy() for _, t := range types_ { dowidth(t) From fdefabadf0a2cb99accb2afe49eafce0eaeb53a7 Mon Sep 17 00:00:00 2001 From: Vladimir Varankin Date: Sat, 22 Sep 2018 22:49:45 +0000 Subject: [PATCH 0424/1663] net/http: use Header.clone rather then duplicating functionality cloneHeader duplicates what Header.clone() method is doing. It's used in a single place, which can be replaced with the use of the method. Change-Id: I6e8bbd6c95063f31ca3695f13fa7478873230525 GitHub-Last-Rev: eb08aeae9b4257df5cf08d6d30903ddeec6b6242 GitHub-Pull-Request: golang/go#27817 Reviewed-on: https://go-review.googlesource.com/136762 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/client.go | 2 +- src/net/http/header.go | 10 ---------- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/src/net/http/client.go b/src/net/http/client.go index a15b3ba2761ed..ea6c0719119b1 100644 --- a/src/net/http/client.go +++ b/src/net/http/client.go @@ -238,7 +238,7 @@ func send(ireq *Request, rt RoundTripper, deadline time.Time) (resp *Response, d username := u.Username() password, _ := u.Password() forkReq() - req.Header = cloneHeader(ireq.Header) + req.Header = ireq.Header.clone() req.Header.Set("Authorization", "Basic "+basicAuth(username, password)) } diff --git a/src/net/http/header.go b/src/net/http/header.go index b28144d8c198c..2aa9d6254b1d8 100644 --- a/src/net/http/header.go +++ b/src/net/http/header.go @@ -229,13 +229,3 @@ func hasToken(v, token string) bool { func isTokenBoundary(b byte) bool { return b == ' ' || b == ',' || b == '\t' } - -func cloneHeader(h Header) Header { - h2 := make(Header, len(h)) - for k, vv := range h { - vv2 := make([]string, len(vv)) - copy(vv2, vv) - h2[k] = vv2 - } - return h2 -} From ce536837d8e53f1bf0c7ef450d4580d19f7d6f52 Mon Sep 17 00:00:00 2001 From: Johan Brandhorst Date: Fri, 24 Aug 2018 12:10:01 +0100 Subject: [PATCH 0425/1663] net/http: ensure null body in Fetch response is not read The Fetch API returns a null body if there is no response body, on browsers that support streaming the response body. This change ensures we check for both undefined and null bodies before attempting to read the body. Fixes #27196 Change-Id: I0da86b61284fe394418b4b431495e715a037f335 Reviewed-on: https://go-review.googlesource.com/131236 Reviewed-by: Richard Musiol Run-TryBot: Richard Musiol TryBot-Result: Gobot Gobot --- src/net/http/roundtrip_js.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/net/http/roundtrip_js.go b/src/net/http/roundtrip_js.go index 16b7b891c86b1..38e4f5573e60e 100644 --- a/src/net/http/roundtrip_js.go +++ b/src/net/http/roundtrip_js.go @@ -116,7 +116,9 @@ func (t *Transport) RoundTrip(req *Request) (*Response, error) { b := result.Get("body") var body io.ReadCloser - if b != js.Undefined() { + // The body is undefined when the browser does not support streaming response bodies (Firefox), + // and null in certain error cases, i.e. when the request is blocked because of CORS settings. + if b != js.Undefined() && b != js.Null() { body = &streamReader{stream: b.Call("getReader")} } else { // Fall back to using ArrayBuffer From 3ff28f7d7117713b684014cbf79e858180a45f5d Mon Sep 17 00:00:00 2001 From: Eugene Kalinin Date: Tue, 19 Jun 2018 21:19:47 +0300 Subject: [PATCH 0426/1663] mime: derestrict value backslash unescaping for all encodings Previously consumeValue performed consumption of "unnecessary backslashes" strictly for non-ASCII and non-token runes. Thus if it encountered a backslash before a rune that is out of the ASCII range, it would erroneously skip that backslash. This change now derestricts "unnecessary backslash" unescaping for all character encodings, using "isTSpecial" instead of "!isTokenChar". This change is a follow-up of CL 32175. Fixes #25888 Change-Id: I5e02bbf9c42f753a6eb31399b8d20315af991490 Reviewed-on: https://go-review.googlesource.com/119795 Reviewed-by: Brad Fitzpatrick --- src/mime/mediatype.go | 2 +- src/mime/mediatype_test.go | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/mime/mediatype.go b/src/mime/mediatype.go index ea2bbac1891be..3d480a9d7e7c4 100644 --- a/src/mime/mediatype.go +++ b/src/mime/mediatype.go @@ -280,7 +280,7 @@ func consumeValue(v string) (value, rest string) { // and intended as a literal backslash. This makes Go servers deal better // with MSIE without affecting the way they handle conforming MIME // generators. - if r == '\\' && i+1 < len(v) && !isTokenChar(rune(v[i+1])) { + if r == '\\' && i+1 < len(v) && isTSpecial(rune(v[i+1])) { buffer.WriteByte(v[i+1]) i++ continue diff --git a/src/mime/mediatype_test.go b/src/mime/mediatype_test.go index 88d742f0aab5f..35b311a4a58b1 100644 --- a/src/mime/mediatype_test.go +++ b/src/mime/mediatype_test.go @@ -40,6 +40,8 @@ func TestConsumeValue(t *testing.T) { {`"\\" rest`, "\\", " rest"}, {`"My \" value"end`, "My \" value", "end"}, {`"\" rest`, "", `"\" rest`}, + {`"C:\dev\go\robots.txt"`, `C:\dev\go\robots.txt`, ""}, + {`"C:\新建文件件\中文第二次测试.mp4"`, `C:\新建文件件\中文第二次测试.mp4`, ""}, } for _, test := range tests { value, rest := consumeValue(test[0]) @@ -393,6 +395,7 @@ func TestParseMediaType(t *testing.T) { // Microsoft browers in intranet mode do not think they need to escape \ in file name. {`form-data; name="file"; filename="C:\dev\go\robots.txt"`, "form-data", m("name", "file", "filename", `C:\dev\go\robots.txt`)}, + {`form-data; name="file"; filename="C:\新建文件件\中文第二次测试.mp4"`, "form-data", m("name", "file", "filename", `C:\新建文件件\中文第二次测试.mp4`)}, } for _, test := range tests { mt, params, err := ParseMediaType(test.in) From 6054fef17f2eedf3ef4825b6ca5b97e2ecf53bd6 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Sun, 23 Sep 2018 13:48:46 +0200 Subject: [PATCH 0427/1663] test: fix bcecheck test on noopt builder The noopt builder is configured by setting GO_GCFLAGS=-N -l, but the test/run.go test harness doesn't look at GO_GCFLAGS when processing "errorcheck" files, it just calls compile: cmdline := []string{goTool(), "tool", "compile", /* etc */} This is working as intended, since it makes the tests more robust and independent from the environment; errorcheck files are supposed to set additional building flags, when needed, like in: // errorcheck -0 -N -l The test/bcecheck.go test used to work on the noopt builder (even if bce is not active on -N -l) because the test was auto-contained and the file always compiled with optimizations enabled. In CL 107355, a new bce test dependent on an external package (encoding.binary) was added. On the noopt builder the external package is built using -N -l, and this causes a test failure that broke the noopt builder: https://build.golang.org/log/b2be319536285e5807ee9d66d6d0ec4d57433768 To reproduce the failure, one can do: $ go install -a -gcflags="-N -l" std $ go run run.go -- checkbce.go This change fixes the noopt builder breakage by removing the bce test dependency on encoding/binary by defining a local Uint64() function to be used in the test. Change-Id: Ife71aab662001442e715c32a0b7d758349a63ff1 Reviewed-on: https://go-review.googlesource.com/136855 Reviewed-by: Brad Fitzpatrick --- test/checkbce.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/checkbce.go b/test/checkbce.go index 0a2842f10c0b8..770c4c2a94e71 100644 --- a/test/checkbce.go +++ b/test/checkbce.go @@ -10,8 +10,6 @@ package main -import "encoding/binary" - func f0(a []int) { a[0] = 1 // ERROR "Found IsInBounds$" a[0] = 1 @@ -144,12 +142,18 @@ func g4(a [100]int) { } } +func Uint64(b []byte) uint64 { + _ = b[7] // ERROR "Found IsInBounds$" + return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 | + uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56 +} + func decode1(data []byte) (x uint64) { for len(data) >= 32 { - x += binary.BigEndian.Uint64(data[:8]) - x += binary.BigEndian.Uint64(data[8:16]) - x += binary.BigEndian.Uint64(data[16:24]) - x += binary.BigEndian.Uint64(data[24:32]) + x += Uint64(data[:8]) + x += Uint64(data[8:16]) + x += Uint64(data[16:24]) + x += Uint64(data[24:32]) data = data[32:] } return x @@ -159,13 +163,13 @@ func decode2(data []byte) (x uint64) { // TODO(rasky): this should behave like decode1 and compile to no // boundchecks. We're currently not able to remove all of them. for len(data) >= 32 { - x += binary.BigEndian.Uint64(data) + x += Uint64(data) data = data[8:] - x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$" + x += Uint64(data) // ERROR "Found IsInBounds$" data = data[8:] - x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$" + x += Uint64(data) // ERROR "Found IsInBounds$" data = data[8:] - x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$" + x += Uint64(data) // ERROR "Found IsInBounds$" data = data[8:] } return x From f25656d392b38da362afb997e75bc43af49d514c Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 22 Sep 2018 10:30:05 +0200 Subject: [PATCH 0428/1663] syscall: replace lstat, lchown, stat to please Android O Implement Lstat with fstatat and Lchown with Fchownat on linux/amd64, linux/arm and linux/386. Furthermore, implement Stat with fstatat on linux/arm and linux/386. Linux/arm64 already had similar replacements. The fstatat and fchownat system calls were added in kernel 2.6.16, which is before the Go minimum, 2.6.23. The three syscalls then match the android bionic implementation and avoids the Android O seccomp filter. Fixes #27797 Change-Id: I07fd5506955d454a1a660fef5af0e1ac1ecb0959 Reviewed-on: https://go-review.googlesource.com/136795 TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/syscall/syscall_linux_386.go | 15 ++++++++-- src/syscall/syscall_linux_amd64.go | 10 +++++-- src/syscall/syscall_linux_arm.go | 15 ++++++++-- src/syscall/zsyscall_linux_386.go | 45 ----------------------------- src/syscall/zsyscall_linux_amd64.go | 30 ------------------- src/syscall/zsyscall_linux_arm.go | 45 ----------------------------- 6 files changed, 32 insertions(+), 128 deletions(-) diff --git a/src/syscall/syscall_linux_386.go b/src/syscall/syscall_linux_386.go index 49db72450fbb7..6e162ebb41f34 100644 --- a/src/syscall/syscall_linux_386.go +++ b/src/syscall/syscall_linux_386.go @@ -62,8 +62,6 @@ func Pipe2(p []int, flags int) (err error) { //sysnb InotifyInit() (fd int, err error) //sys Ioperm(from int, num int, on int) (err error) //sys Iopl(level int) (err error) -//sys Lchown(path string, uid int, gid int) (err error) = SYS_LCHOWN32 -//sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64 //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64 @@ -74,7 +72,6 @@ func Pipe2(p []int, flags int) (err error) { //sysnb Setresuid(ruid int, euid int, suid int) (err error) = SYS_SETRESUID32 //sysnb Setreuid(ruid int, euid int) (err error) = SYS_SETREUID32 //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error) -//sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64 //sys SyncFileRange(fd int, off int64, n int64, flags int) (err error) //sys Truncate(path string, length int64) (err error) = SYS_TRUNCATE64 //sysnb getgroups(n int, list *_Gid_t) (nn int, err error) = SYS_GETGROUPS32 @@ -84,6 +81,18 @@ func Pipe2(p []int, flags int) (err error) { //sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error) //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) +func Stat(path string, stat *Stat_t) (err error) { + return fstatat(_AT_FDCWD, path, stat, 0) +} + +func Lchown(path string, uid int, gid int) (err error) { + return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW) +} + +func Lstat(path string, stat *Stat_t) (err error) { + return fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW) +} + func mmap(addr uintptr, length uintptr, prot int, flags int, fd int, offset int64) (xaddr uintptr, err error) { page := uintptr(offset / 4096) if offset != int64(page)*4096 { diff --git a/src/syscall/syscall_linux_amd64.go b/src/syscall/syscall_linux_amd64.go index 1a21d9db6f2b4..f740ab4e72d1a 100644 --- a/src/syscall/syscall_linux_amd64.go +++ b/src/syscall/syscall_linux_amd64.go @@ -22,9 +22,7 @@ const ( //sysnb InotifyInit() (fd int, err error) //sys Ioperm(from int, num int, on int) (err error) //sys Iopl(level int) (err error) -//sys Lchown(path string, uid int, gid int) (err error) //sys Listen(s int, n int) (err error) -//sys Lstat(path string, stat *Stat_t) (err error) //sys Pread(fd int, p []byte, offset int64) (n int, err error) = SYS_PREAD64 //sys Pwrite(fd int, p []byte, offset int64) (n int, err error) = SYS_PWRITE64 //sys Seek(fd int, offset int64, whence int) (off int64, err error) = SYS_LSEEK @@ -66,6 +64,14 @@ func Stat(path string, stat *Stat_t) (err error) { return fstatat(_AT_FDCWD, path, stat, 0) } +func Lchown(path string, uid int, gid int) (err error) { + return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW) +} + +func Lstat(path string, stat *Stat_t) (err error) { + return fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW) +} + //go:noescape func gettimeofday(tv *Timeval) (err Errno) diff --git a/src/syscall/syscall_linux_arm.go b/src/syscall/syscall_linux_arm.go index b0c0ac7c4fae6..65543193e15eb 100644 --- a/src/syscall/syscall_linux_arm.go +++ b/src/syscall/syscall_linux_arm.go @@ -83,9 +83,7 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { //sysnb Getgid() (gid int) = SYS_GETGID32 //sysnb Getuid() (uid int) = SYS_GETUID32 //sysnb InotifyInit() (fd int, err error) -//sys Lchown(path string, uid int, gid int) (err error) = SYS_LCHOWN32 //sys Listen(s int, n int) (err error) -//sys Lstat(path string, stat *Stat_t) (err error) = SYS_LSTAT64 //sys sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) = SYS_SENDFILE64 //sys Select(nfd int, r *FdSet, w *FdSet, e *FdSet, timeout *Timeval) (n int, err error) = SYS__NEWSELECT //sys Setfsgid(gid int) (err error) = SYS_SETFSGID32 @@ -96,7 +94,6 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { //sysnb Setreuid(ruid int, euid int) (err error) = SYS_SETREUID32 //sys Shutdown(fd int, how int) (err error) //sys Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n int, err error) -//sys Stat(path string, stat *Stat_t) (err error) = SYS_STAT64 // Vsyscalls on amd64. //sysnb Gettimeofday(tv *Timeval) (err error) @@ -110,6 +107,18 @@ func Seek(fd int, offset int64, whence int) (newoffset int64, err error) { //sys mmap2(addr uintptr, length uintptr, prot int, flags int, fd int, pageOffset uintptr) (xaddr uintptr, err error) //sys EpollWait(epfd int, events []EpollEvent, msec int) (n int, err error) +func Stat(path string, stat *Stat_t) (err error) { + return fstatat(_AT_FDCWD, path, stat, 0) +} + +func Lchown(path string, uid int, gid int) (err error) { + return Fchownat(_AT_FDCWD, path, uid, gid, _AT_SYMLINK_NOFOLLOW) +} + +func Lstat(path string, stat *Stat_t) (err error) { + return fstatat(_AT_FDCWD, path, stat, _AT_SYMLINK_NOFOLLOW) +} + func Fstatfs(fd int, buf *Statfs_t) (err error) { _, _, e := Syscall(SYS_FSTATFS64, uintptr(fd), unsafe.Sizeof(*buf), uintptr(unsafe.Pointer(buf))) if e != 0 { diff --git a/src/syscall/zsyscall_linux_386.go b/src/syscall/zsyscall_linux_386.go index 62827f16dc346..0882494c470dd 100644 --- a/src/syscall/zsyscall_linux_386.go +++ b/src/syscall/zsyscall_linux_386.go @@ -1276,36 +1276,6 @@ func Iopl(level int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Lchown(path string, uid int, gid int) (err error) { - var _p0 *byte - _p0, err = BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := Syscall(SYS_LCHOWN32, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - -func Lstat(path string, stat *Stat_t) (err error) { - var _p0 *byte - _p0, err = BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := Syscall(SYS_LSTAT64, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { @@ -1422,21 +1392,6 @@ func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n i // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Stat(path string, stat *Stat_t) (err error) { - var _p0 *byte - _p0, err = BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := Syscall(SYS_STAT64, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func SyncFileRange(fd int, off int64, n int64, flags int) (err error) { _, _, e1 := Syscall6(SYS_SYNC_FILE_RANGE, uintptr(fd), uintptr(off), uintptr(off>>32), uintptr(n), uintptr(n>>32), uintptr(flags)) if e1 != 0 { diff --git a/src/syscall/zsyscall_linux_amd64.go b/src/syscall/zsyscall_linux_amd64.go index b6638269bebb8..9f2046bf93fee 100644 --- a/src/syscall/zsyscall_linux_amd64.go +++ b/src/syscall/zsyscall_linux_amd64.go @@ -1261,21 +1261,6 @@ func Iopl(level int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Lchown(path string, uid int, gid int) (err error) { - var _p0 *byte - _p0, err = BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := Syscall(SYS_LCHOWN, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Listen(s int, n int) (err error) { _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(n), 0) if e1 != 0 { @@ -1286,21 +1271,6 @@ func Listen(s int, n int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Lstat(path string, stat *Stat_t) (err error) { - var _p0 *byte - _p0, err = BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := Syscall(SYS_LSTAT, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Pread(fd int, p []byte, offset int64) (n int, err error) { var _p0 unsafe.Pointer if len(p) > 0 { diff --git a/src/syscall/zsyscall_linux_arm.go b/src/syscall/zsyscall_linux_arm.go index bb20d6e9463ea..3d099aa16df65 100644 --- a/src/syscall/zsyscall_linux_arm.go +++ b/src/syscall/zsyscall_linux_arm.go @@ -1415,21 +1415,6 @@ func InotifyInit() (fd int, err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Lchown(path string, uid int, gid int) (err error) { - var _p0 *byte - _p0, err = BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := Syscall(SYS_LCHOWN32, uintptr(unsafe.Pointer(_p0)), uintptr(uid), uintptr(gid)) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Listen(s int, n int) (err error) { _, _, e1 := Syscall(SYS_LISTEN, uintptr(s), uintptr(n), 0) if e1 != 0 { @@ -1440,21 +1425,6 @@ func Listen(s int, n int) (err error) { // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Lstat(path string, stat *Stat_t) (err error) { - var _p0 *byte - _p0, err = BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := Syscall(SYS_LSTAT64, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) { r0, _, e1 := Syscall6(SYS_SENDFILE64, uintptr(outfd), uintptr(infd), uintptr(unsafe.Pointer(offset)), uintptr(count), 0, 0) written = int(r0) @@ -1558,21 +1528,6 @@ func Splice(rfd int, roff *int64, wfd int, woff *int64, len int, flags int) (n i // THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT -func Stat(path string, stat *Stat_t) (err error) { - var _p0 *byte - _p0, err = BytePtrFromString(path) - if err != nil { - return - } - _, _, e1 := Syscall(SYS_STAT64, uintptr(unsafe.Pointer(_p0)), uintptr(unsafe.Pointer(stat)), 0) - if e1 != 0 { - err = errnoErr(e1) - } - return -} - -// THIS FILE IS GENERATED BY THE COMMAND AT THE TOP; DO NOT EDIT - func Gettimeofday(tv *Timeval) (err error) { _, _, e1 := RawSyscall(SYS_GETTIMEOFDAY, uintptr(unsafe.Pointer(tv)), 0, 0) if e1 != 0 { From c22c7607d3657f7945580f5cf5e0f612c694389f Mon Sep 17 00:00:00 2001 From: Jongmin Kim Date: Sat, 22 Sep 2018 23:05:06 +0900 Subject: [PATCH 0429/1663] test/bench/garbage: update Benchmarks Game URL to new page The existing URL in comment points to an Alioth page which was deprecated (and not working), so use the new Benchmarks Game URL. Change-Id: Ifd694382a44a24c44acbed3fe1b17bca6dab998f Reviewed-on: https://go-review.googlesource.com/136835 Reviewed-by: Brad Fitzpatrick --- test/bench/garbage/tree.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/bench/garbage/tree.go b/test/bench/garbage/tree.go index 0a3ec234db803..524cfebc73f29 100644 --- a/test/bench/garbage/tree.go +++ b/test/bench/garbage/tree.go @@ -28,7 +28,7 @@ POSSIBILITY OF SUCH DAMAGE. */ /* The Computer Language Benchmarks Game - * http://shootout.alioth.debian.org/ + * https://benchmarksgame-team.pages.debian.net/benchmarksgame/ * * contributed by The Go Authors. * based on C program by Kevin Carson From 8d6a455df42b016ed2f7071e70718cad940937f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrei=20Tudor=20C=C4=83lin?= Date: Fri, 21 Sep 2018 03:32:47 +0200 Subject: [PATCH 0430/1663] net: don't use splice for unix{packet,gram} connections As pointed out in the aftermath of CL 113997, splice is not supported for SOCK_SEQPACKET or SOCK_DGRAM unix sockets. Don't call poll.Splice in those cases. Change-Id: Ieab18fb0ae706fdeb249e3f54d51a3292e3ead62 Reviewed-on: https://go-review.googlesource.com/136635 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/net/splice_linux.go | 5 +++- src/net/splice_test.go | 52 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/net/splice_linux.go b/src/net/splice_linux.go index 8a4d55af62a89..69c3f65770f8a 100644 --- a/src/net/splice_linux.go +++ b/src/net/splice_linux.go @@ -11,7 +11,7 @@ import ( // splice transfers data from r to c using the splice system call to minimize // copies from and to userspace. c must be a TCP connection. Currently, splice -// is only enabled if r is a TCP or Unix connection. +// is only enabled if r is a TCP or a stream-oriented Unix connection. // // If splice returns handled == false, it has performed no work. func splice(c *netFD, r io.Reader) (written int64, err error, handled bool) { @@ -28,6 +28,9 @@ func splice(c *netFD, r io.Reader) (written int64, err error, handled bool) { if tc, ok := r.(*TCPConn); ok { s = tc.fd } else if uc, ok := r.(*UnixConn); ok { + if uc.fd.net != "unix" { + return 0, nil, false + } s = uc.fd } else { return 0, nil, false diff --git a/src/net/splice_test.go b/src/net/splice_test.go index 93e8b1f8cc0a1..4c300172c5e9e 100644 --- a/src/net/splice_test.go +++ b/src/net/splice_test.go @@ -24,6 +24,8 @@ func TestSplice(t *testing.T) { t.Skip("skipping unix-to-tcp tests") } t.Run("unix-to-tcp", func(t *testing.T) { testSplice(t, "unix", "tcp") }) + t.Run("no-unixpacket", testSpliceNoUnixpacket) + t.Run("no-unixgram", testSpliceNoUnixgram) } func testSplice(t *testing.T, upNet, downNet string) { @@ -208,6 +210,56 @@ func testSpliceIssue25985(t *testing.T, upNet, downNet string) { wg.Wait() } +func testSpliceNoUnixpacket(t *testing.T) { + clientUp, serverUp, err := spliceTestSocketPair("unixpacket") + if err != nil { + t.Fatal(err) + } + defer clientUp.Close() + defer serverUp.Close() + clientDown, serverDown, err := spliceTestSocketPair("tcp") + if err != nil { + t.Fatal(err) + } + defer clientDown.Close() + defer serverDown.Close() + // If splice called poll.Splice here, we'd get err == syscall.EINVAL + // and handled == false. If poll.Splice gets an EINVAL on the first + // try, it assumes the kernel it's running on doesn't support splice + // for unix sockets and returns handled == false. This works for our + // purposes by somewhat of an accident, but is not entirely correct. + // + // What we want is err == nil and handled == false, i.e. we never + // called poll.Splice, because we know the unix socket's network. + _, err, handled := splice(serverDown.(*TCPConn).fd, serverUp) + if err != nil || handled != false { + t.Fatalf("got err = %v, handled = %t, want nil error, handled == false", err, handled) + } +} + +func testSpliceNoUnixgram(t *testing.T) { + addr, err := ResolveUnixAddr("unixgram", testUnixAddr()) + if err != nil { + t.Fatal(err) + } + up, err := ListenUnixgram("unixgram", addr) + if err != nil { + t.Fatal(err) + } + defer up.Close() + clientDown, serverDown, err := spliceTestSocketPair("tcp") + if err != nil { + t.Fatal(err) + } + defer clientDown.Close() + defer serverDown.Close() + // Analogous to testSpliceNoUnixpacket. + _, err, handled := splice(serverDown.(*TCPConn).fd, up) + if err != nil || handled != false { + t.Fatalf("got err = %v, handled = %t, want nil error, handled == false", err, handled) + } +} + func BenchmarkSplice(b *testing.B) { testHookUninstaller.Do(uninstallTestHooks) From 9774fa6f4020dba924d63991f572aa89325e1c9c Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 24 Sep 2018 10:23:53 -0700 Subject: [PATCH 0431/1663] cmd/compile: fix precedence order bug &^ and << have equal precedence. Add some parentheses to make sure we shift before we andnot. Fixes #27829 Change-Id: Iba8576201f0f7c52bf9795aaa75d15d8f9a76811 Reviewed-on: https://go-review.googlesource.com/136899 Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/ssa/gen/AMD64.rules | 4 +-- src/cmd/compile/internal/ssa/rewriteAMD64.go | 16 ++++++------ test/fixedbugs/issue27829.go | 27 ++++++++++++++++++++ 3 files changed, 37 insertions(+), 10 deletions(-) create mode 100644 test/fixedbugs/issue27829.go diff --git a/src/cmd/compile/internal/ssa/gen/AMD64.rules b/src/cmd/compile/internal/ssa/gen/AMD64.rules index 76a4fc9ab7dea..f9ac5e4dcee51 100644 --- a/src/cmd/compile/internal/ssa/gen/AMD64.rules +++ b/src/cmd/compile/internal/ssa/gen/AMD64.rules @@ -709,8 +709,8 @@ (ANDL x (MOVLconst [c])) -> (ANDLconst [c] x) (AND(L|Q)const [c] (AND(L|Q)const [d] x)) -> (AND(L|Q)const [c & d] x) -(BTR(L|Q)const [c] (AND(L|Q)const [d] x)) -> (AND(L|Q)const [d &^ 1< (AND(L|Q)const [c &^ 1< (AND(L|Q)const [d &^ (1< (AND(L|Q)const [c &^ (1< (AND(L|Q)const [^(1< (XOR(L|Q)const [c ^ d] x) (BTC(L|Q)const [c] (XOR(L|Q)const [d] x)) -> (XOR(L|Q)const [d ^ 1<> 48) &^ (uint64(0x4000)) +} + +func main() { + bad := false + if got, want := f(^uint64(0)), uint64(0xbfff); got != want { + fmt.Printf("got %x, want %x\n", got, want) + bad = true + } + if bad { + panic("bad") + } +} From 4039be00a9e77bd4080ac657a940472341fa088f Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Sat, 22 Sep 2018 14:23:38 +0100 Subject: [PATCH 0432/1663] image: add benchmarks for At and Set methods Added in preparation for looking at some optimizations around bounds checks. BenchmarkAt/rgba-8 100000000 18.5 ns/op 4 B/op 1 allocs/op BenchmarkAt/rgba64-8 100000000 22.9 ns/op 8 B/op 1 allocs/op BenchmarkAt/nrgba-8 100000000 18.8 ns/op 4 B/op 1 allocs/op BenchmarkAt/nrgba64-8 100000000 22.1 ns/op 8 B/op 1 allocs/op BenchmarkAt/alpha-8 100000000 14.6 ns/op 1 B/op 1 allocs/op BenchmarkAt/alpha16-8 200000000 6.46 ns/op 0 B/op 0 allocs/op BenchmarkAt/gray-8 100000000 14.3 ns/op 1 B/op 1 allocs/op BenchmarkAt/gray16-8 200000000 6.45 ns/op 0 B/op 0 allocs/op BenchmarkAt/paletted-8 300000000 4.28 ns/op 0 B/op 0 allocs/op BenchmarkSet/rgba-8 50000000 39.2 ns/op 8 B/op 2 allocs/op BenchmarkSet/rgba64-8 30000000 45.8 ns/op 16 B/op 2 allocs/op BenchmarkSet/nrgba-8 50000000 39.3 ns/op 8 B/op 2 allocs/op BenchmarkSet/nrgba64-8 30000000 45.6 ns/op 16 B/op 2 allocs/op BenchmarkSet/alpha-8 50000000 34.5 ns/op 2 B/op 2 allocs/op BenchmarkSet/alpha16-8 50000000 34.9 ns/op 4 B/op 2 allocs/op BenchmarkSet/gray-8 100000000 20.3 ns/op 1 B/op 1 allocs/op BenchmarkSet/gray16-8 50000000 36.2 ns/op 4 B/op 2 allocs/op BenchmarkSet/paletted-8 50000000 39.5 ns/op 1 B/op 1 allocs/op BenchmarkRGBAAt-8 500000000 3.74 ns/op BenchmarkRGBASetRGBA-8 300000000 4.33 ns/op BenchmarkRGBA64At-8 300000000 5.06 ns/op BenchmarkRGBA64SetRGBA64-8 200000000 6.61 ns/op BenchmarkNRGBAAt-8 500000000 3.69 ns/op BenchmarkNRGBASetNRGBA-8 300000000 4.06 ns/op BenchmarkNRGBA64At-8 300000000 4.98 ns/op BenchmarkNRGBA64SetNRGBA64-8 200000000 6.62 ns/op BenchmarkAlphaAt-8 2000000000 1.43 ns/op BenchmarkAlphaSetAlpha-8 2000000000 1.55 ns/op BenchmarkAlpha16At-8 1000000000 2.87 ns/op BenchmarkAlphaSetAlpha16-8 500000000 3.27 ns/op BenchmarkGrayAt-8 2000000000 1.43 ns/op BenchmarkGraySetGray-8 2000000000 1.55 ns/op BenchmarkGray16At-8 1000000000 2.87 ns/op BenchmarkGraySetGray16-8 500000000 3.14 ns/op Updates #14884 Change-Id: I349fb214ee75f13ecbc62ac22a40e3b337648f60 Reviewed-on: https://go-review.googlesource.com/136796 Reviewed-by: Brad Fitzpatrick --- src/image/image_test.go | 210 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 195 insertions(+), 15 deletions(-) diff --git a/src/image/image_test.go b/src/image/image_test.go index 08ba61ea0c704..6f49752a25fb4 100644 --- a/src/image/image_test.go +++ b/src/image/image_test.go @@ -22,22 +22,27 @@ func cmp(cm color.Model, c0, c1 color.Color) bool { return r0 == r1 && g0 == g1 && b0 == b1 && a0 == a1 } +var testImages = []struct { + name string + image image +}{ + {"rgba", NewRGBA(Rect(0, 0, 10, 10))}, + {"rgba64", NewRGBA64(Rect(0, 0, 10, 10))}, + {"nrgba", NewNRGBA(Rect(0, 0, 10, 10))}, + {"nrgba64", NewNRGBA64(Rect(0, 0, 10, 10))}, + {"alpha", NewAlpha(Rect(0, 0, 10, 10))}, + {"alpha16", NewAlpha16(Rect(0, 0, 10, 10))}, + {"gray", NewGray(Rect(0, 0, 10, 10))}, + {"gray16", NewGray16(Rect(0, 0, 10, 10))}, + {"paletted", NewPaletted(Rect(0, 0, 10, 10), color.Palette{ + Transparent, + Opaque, + })}, +} + func TestImage(t *testing.T) { - testImage := []image{ - NewRGBA(Rect(0, 0, 10, 10)), - NewRGBA64(Rect(0, 0, 10, 10)), - NewNRGBA(Rect(0, 0, 10, 10)), - NewNRGBA64(Rect(0, 0, 10, 10)), - NewAlpha(Rect(0, 0, 10, 10)), - NewAlpha16(Rect(0, 0, 10, 10)), - NewGray(Rect(0, 0, 10, 10)), - NewGray16(Rect(0, 0, 10, 10)), - NewPaletted(Rect(0, 0, 10, 10), color.Palette{ - Transparent, - Opaque, - }), - } - for _, m := range testImage { + for _, tc := range testImages { + m := tc.image if !Rect(0, 0, 10, 10).Eq(m.Bounds()) { t.Errorf("%T: want bounds %v, got %v", m, Rect(0, 0, 10, 10), m.Bounds()) continue @@ -111,3 +116,178 @@ func Test16BitsPerColorChannel(t *testing.T) { } } } + +func BenchmarkAt(b *testing.B) { + for _, tc := range testImages { + b.Run(tc.name, func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + tc.image.At(4, 5) + } + }) + } +} + +func BenchmarkSet(b *testing.B) { + c := color.Gray{0xff} + for _, tc := range testImages { + b.Run(tc.name, func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + tc.image.Set(4, 5, c) + } + }) + } +} + +func BenchmarkRGBAAt(b *testing.B) { + m := NewRGBA(Rect(0, 0, 10, 10)) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.RGBAAt(4, 5) + } +} + +func BenchmarkRGBASetRGBA(b *testing.B) { + m := NewRGBA(Rect(0, 0, 10, 10)) + c := color.RGBA{0xff, 0xff, 0xff, 0x13} + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.SetRGBA(4, 5, c) + } +} + +func BenchmarkRGBA64At(b *testing.B) { + m := NewRGBA64(Rect(0, 0, 10, 10)) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.RGBA64At(4, 5) + } +} + +func BenchmarkRGBA64SetRGBA64(b *testing.B) { + m := NewRGBA64(Rect(0, 0, 10, 10)) + c := color.RGBA64{0xffff, 0xffff, 0xffff, 0x1357} + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.SetRGBA64(4, 5, c) + } +} + +func BenchmarkNRGBAAt(b *testing.B) { + m := NewNRGBA(Rect(0, 0, 10, 10)) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.NRGBAAt(4, 5) + } +} + +func BenchmarkNRGBASetNRGBA(b *testing.B) { + m := NewNRGBA(Rect(0, 0, 10, 10)) + c := color.NRGBA{0xff, 0xff, 0xff, 0x13} + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.SetNRGBA(4, 5, c) + } +} + +func BenchmarkNRGBA64At(b *testing.B) { + m := NewNRGBA64(Rect(0, 0, 10, 10)) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.NRGBA64At(4, 5) + } +} + +func BenchmarkNRGBA64SetNRGBA64(b *testing.B) { + m := NewNRGBA64(Rect(0, 0, 10, 10)) + c := color.NRGBA64{0xffff, 0xffff, 0xffff, 0x1357} + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.SetNRGBA64(4, 5, c) + } +} + +func BenchmarkAlphaAt(b *testing.B) { + m := NewAlpha(Rect(0, 0, 10, 10)) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.AlphaAt(4, 5) + } +} + +func BenchmarkAlphaSetAlpha(b *testing.B) { + m := NewAlpha(Rect(0, 0, 10, 10)) + c := color.Alpha{0x13} + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.SetAlpha(4, 5, c) + } +} + +func BenchmarkAlpha16At(b *testing.B) { + m := NewAlpha16(Rect(0, 0, 10, 10)) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.Alpha16At(4, 5) + } +} + +func BenchmarkAlphaSetAlpha16(b *testing.B) { + m := NewAlpha16(Rect(0, 0, 10, 10)) + c := color.Alpha16{0x13} + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.SetAlpha16(4, 5, c) + } +} + +func BenchmarkGrayAt(b *testing.B) { + m := NewGray(Rect(0, 0, 10, 10)) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.GrayAt(4, 5) + } +} + +func BenchmarkGraySetGray(b *testing.B) { + m := NewGray(Rect(0, 0, 10, 10)) + c := color.Gray{0x13} + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.SetGray(4, 5, c) + } +} + +func BenchmarkGray16At(b *testing.B) { + m := NewGray16(Rect(0, 0, 10, 10)) + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.Gray16At(4, 5) + } +} + +func BenchmarkGraySetGray16(b *testing.B) { + m := NewGray16(Rect(0, 0, 10, 10)) + c := color.Gray16{0x13} + b.ResetTimer() + + for i := 0; i < b.N; i++ { + m.SetGray16(4, 5, c) + } +} From 5b3aafe2b51b5455a42a65cca1cf0e8393970c03 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 24 Sep 2018 17:30:48 +0000 Subject: [PATCH 0433/1663] net: don't reject domain names with only numbers and hyphens From https://github.com/golang/go/issues/17659#issuecomment-423113606 ... > In kubernetes , isDomainName reject Pods "A Record" "pod-ip-address", > for example: "172-17-0-16", as RFC 3696 section 2 requires > "top-level domain names not be all-numeric", but this example has > three hyphen, so I think it should not be reject. Updates #17659 Change-Id: Ibd8ffb9473d69c45c91525953c09c6749233ca20 Reviewed-on: https://go-review.googlesource.com/136900 Run-TryBot: Brad Fitzpatrick Reviewed-by: Ian Lance Taylor Reviewed-by: Ian Gudger TryBot-Result: Gobot Gobot --- src/net/dnsclient.go | 7 ++++--- src/net/dnsname_test.go | 1 + 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/net/dnsclient.go b/src/net/dnsclient.go index e3524280b6aaf..2c47bc413013f 100644 --- a/src/net/dnsclient.go +++ b/src/net/dnsclient.go @@ -75,7 +75,7 @@ func isDomainName(s string) bool { } last := byte('.') - ok := false // Ok once we've seen a letter. + nonNumeric := false // true once we've seen a letter or hyphen partlen := 0 for i := 0; i < len(s); i++ { c := s[i] @@ -83,7 +83,7 @@ func isDomainName(s string) bool { default: return false case 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z' || c == '_': - ok = true + nonNumeric = true partlen++ case '0' <= c && c <= '9': // fine @@ -94,6 +94,7 @@ func isDomainName(s string) bool { return false } partlen++ + nonNumeric = true case c == '.': // Byte before dot cannot be dot, dash. if last == '.' || last == '-' { @@ -110,7 +111,7 @@ func isDomainName(s string) bool { return false } - return ok + return nonNumeric } // absDomainName returns an absolute domain name which ends with a diff --git a/src/net/dnsname_test.go b/src/net/dnsname_test.go index 806d8756cb5c5..2964982311ce4 100644 --- a/src/net/dnsname_test.go +++ b/src/net/dnsname_test.go @@ -22,6 +22,7 @@ var dnsNameTests = []dnsNameTest{ {"foo.com", true}, {"1foo.com", true}, {"26.0.0.73.com", true}, + {"10-0-0-1", true}, {"fo-o.com", true}, {"fo1o.com", true}, {"foo1.com", true}, From fdceb2a11bb767ddaa334cb39315ae6982b676aa Mon Sep 17 00:00:00 2001 From: Katie Hockman Date: Fri, 14 Sep 2018 17:07:56 -0400 Subject: [PATCH 0434/1663] compress: reduce copies of new text for compression testing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous book was 387 KiB decompressed and 119 KiB compressed, the new book is 567 KiB decompressed and 132 KiB compressed. Overall, this change will reduce the release binary size by 196 KiB. The new book will allow for slightly more extensive compression testing with a larger text. Command to run the benchmark tests used with benchstat: `../bin/go test -run='^$' -count=4 -bench=. compress/bzip2 compress/flate` When running the benchmarks locally, changed "Newton" to "Twain" and filtered the tests with the -bench flag to include only those which were relevant to these changes. benchstat results below: name old time/op new time/op delta DecodeTwain-8 19.6ms ± 2% 24.1ms ± 1% +23.04% (p=0.029 n=4+4) Decode/Twain/Huffman/1e4-8 140µs ± 3% 139µs ± 5% ~ (p=0.886 n=4+4) Decode/Twain/Huffman/1e5-8 1.27ms ± 3% 1.26ms ± 1% ~ (p=1.000 n=4+4) Decode/Twain/Huffman/1e6-8 12.4ms ± 0% 13.2ms ± 1% +6.42% (p=0.029 n=4+4) Decode/Twain/Speed/1e4-8 133µs ± 1% 123µs ± 1% -7.35% (p=0.029 n=4+4) Decode/Twain/Speed/1e5-8 1.20ms ± 0% 1.02ms ± 3% -15.32% (p=0.029 n=4+4) Decode/Twain/Speed/1e6-8 12.0ms ± 2% 10.1ms ± 3% -15.89% (p=0.029 n=4+4) Decode/Twain/Default/1e4-8 131µs ± 6% 108µs ± 5% -17.84% (p=0.029 n=4+4) Decode/Twain/Default/1e5-8 1.06ms ± 2% 0.80ms ± 1% -24.97% (p=0.029 n=4+4) Decode/Twain/Default/1e6-8 10.0ms ± 3% 8.0ms ± 3% -20.06% (p=0.029 n=4+4) Decode/Twain/Compression/1e4-8 128µs ± 4% 115µs ± 4% -9.70% (p=0.029 n=4+4) Decode/Twain/Compression/1e5-8 1.04ms ± 2% 0.83ms ± 4% -20.37% (p=0.029 n=4+4) Decode/Twain/Compression/1e6-8 10.4ms ± 4% 8.1ms ± 5% -22.25% (p=0.029 n=4+4) Encode/Twain/Huffman/1e4-8 55.7µs ± 2% 55.6µs ± 1% ~ (p=1.000 n=4+4) Encode/Twain/Huffman/1e5-8 441µs ± 0% 435µs ± 2% ~ (p=0.343 n=4+4) Encode/Twain/Huffman/1e6-8 4.31ms ± 4% 4.30ms ± 4% ~ (p=0.886 n=4+4) Encode/Twain/Speed/1e4-8 193µs ± 1% 166µs ± 2% -14.09% (p=0.029 n=4+4) Encode/Twain/Speed/1e5-8 1.54ms ± 1% 1.22ms ± 1% -20.53% (p=0.029 n=4+4) Encode/Twain/Speed/1e6-8 15.3ms ± 1% 12.2ms ± 3% -20.62% (p=0.029 n=4+4) Encode/Twain/Default/1e4-8 393µs ± 1% 390µs ± 1% ~ (p=0.114 n=4+4) Encode/Twain/Default/1e5-8 6.12ms ± 4% 6.02ms ± 5% ~ (p=0.486 n=4+4) Encode/Twain/Default/1e6-8 69.4ms ± 5% 59.0ms ± 4% -15.07% (p=0.029 n=4+4) Encode/Twain/Compression/1e4-8 423µs ± 2% 379µs ± 2% -10.34% (p=0.029 n=4+4) Encode/Twain/Compression/1e5-8 7.00ms ± 1% 7.88ms ± 3% +12.49% (p=0.029 n=4+4) Encode/Twain/Compression/1e6-8 76.6ms ± 5% 80.9ms ± 3% ~ (p=0.114 n=4+4) name old speed new speed delta DecodeTwain-8 19.8MB/s ± 2% 23.6MB/s ± 1% +18.84% (p=0.029 n=4+4) Decode/Twain/Huffman/1e4-8 71.7MB/s ± 3% 72.1MB/s ± 6% ~ (p=0.943 n=4+4) Decode/Twain/Huffman/1e5-8 78.8MB/s ± 3% 79.5MB/s ± 1% ~ (p=1.000 n=4+4) Decode/Twain/Huffman/1e6-8 80.5MB/s ± 0% 75.6MB/s ± 1% -6.03% (p=0.029 n=4+4) Decode/Twain/Speed/1e4-8 75.2MB/s ± 1% 81.2MB/s ± 1% +7.93% (p=0.029 n=4+4) Decode/Twain/Speed/1e5-8 83.4MB/s ± 0% 98.6MB/s ± 3% +18.16% (p=0.029 n=4+4) Decode/Twain/Speed/1e6-8 83.6MB/s ± 2% 99.5MB/s ± 3% +18.91% (p=0.029 n=4+4) Decode/Twain/Default/1e4-8 76.3MB/s ± 6% 92.8MB/s ± 4% +21.62% (p=0.029 n=4+4) Decode/Twain/Default/1e5-8 94.4MB/s ± 3% 125.7MB/s ± 1% +33.24% (p=0.029 n=4+4) Decode/Twain/Default/1e6-8 100MB/s ± 3% 125MB/s ± 3% +25.12% (p=0.029 n=4+4) Decode/Twain/Compression/1e4-8 78.4MB/s ± 4% 86.8MB/s ± 4% +10.73% (p=0.029 n=4+4) Decode/Twain/Compression/1e5-8 95.7MB/s ± 2% 120.3MB/s ± 4% +25.65% (p=0.029 n=4+4) Decode/Twain/Compression/1e6-8 96.4MB/s ± 4% 124.0MB/s ± 5% +28.64% (p=0.029 n=4+4) Encode/Twain/Huffman/1e4-8 179MB/s ± 2% 180MB/s ± 1% ~ (p=1.000 n=4+4) Encode/Twain/Huffman/1e5-8 227MB/s ± 0% 230MB/s ± 2% ~ (p=0.343 n=4+4) Encode/Twain/Huffman/1e6-8 232MB/s ± 4% 233MB/s ± 4% ~ (p=0.886 n=4+4) Encode/Twain/Speed/1e4-8 51.8MB/s ± 1% 60.4MB/s ± 2% +16.43% (p=0.029 n=4+4) Encode/Twain/Speed/1e5-8 65.1MB/s ± 1% 81.9MB/s ± 1% +25.83% (p=0.029 n=4+4) Encode/Twain/Speed/1e6-8 65.2MB/s ± 1% 82.2MB/s ± 3% +26.00% (p=0.029 n=4+4) Encode/Twain/Default/1e4-8 25.4MB/s ± 1% 25.6MB/s ± 1% ~ (p=0.114 n=4+4) Encode/Twain/Default/1e5-8 16.4MB/s ± 4% 16.6MB/s ± 5% ~ (p=0.486 n=4+4) Encode/Twain/Default/1e6-8 14.4MB/s ± 6% 17.0MB/s ± 4% +17.67% (p=0.029 n=4+4) Encode/Twain/Compression/1e4-8 23.6MB/s ± 2% 26.4MB/s ± 2% +11.54% (p=0.029 n=4+4) Encode/Twain/Compression/1e5-8 14.3MB/s ± 1% 12.7MB/s ± 3% -11.08% (p=0.029 n=4+4) Encode/Twain/Compression/1e6-8 13.1MB/s ± 4% 12.4MB/s ± 3% ~ (p=0.114 n=4+4) name old alloc/op new alloc/op delta DecodeTwain-8 3.63MB ± 0% 3.63MB ± 0% +0.15% (p=0.029 n=4+4) Decode/Twain/Huffman/1e4-8 42.0kB ± 0% 41.3kB ± 0% -1.62% (p=0.029 n=4+4) Decode/Twain/Huffman/1e5-8 43.5kB ± 0% 45.1kB ± 0% +3.74% (p=0.029 n=4+4) Decode/Twain/Huffman/1e6-8 71.7kB ± 0% 80.0kB ± 0% +11.55% (p=0.029 n=4+4) Decode/Twain/Speed/1e4-8 41.2kB ± 0% 41.3kB ± 0% ~ (p=0.286 n=4+4) Decode/Twain/Speed/1e5-8 45.1kB ± 0% 43.9kB ± 0% -2.80% (p=0.029 n=4+4) Decode/Twain/Speed/1e6-8 72.8kB ± 0% 81.3kB ± 0% +11.72% (p=0.029 n=4+4) Decode/Twain/Default/1e4-8 41.2kB ± 0% 41.2kB ± 0% -0.22% (p=0.029 n=4+4) Decode/Twain/Default/1e5-8 44.4kB ± 0% 43.0kB ± 0% -3.02% (p=0.029 n=4+4) Decode/Twain/Default/1e6-8 71.0kB ± 0% 61.8kB ± 0% -13.00% (p=0.029 n=4+4) Decode/Twain/Compression/1e4-8 41.3kB ± 0% 41.2kB ± 0% -0.29% (p=0.029 n=4+4) Decode/Twain/Compression/1e5-8 43.3kB ± 0% 43.0kB ± 0% -0.72% (p=0.029 n=4+4) Decode/Twain/Compression/1e6-8 69.1kB ± 0% 63.7kB ± 0% -7.90% (p=0.029 n=4+4) name old allocs/op new allocs/op delta DecodeTwain-8 51.0 ± 0% 51.2 ± 1% ~ (p=1.000 n=4+4) Decode/Twain/Huffman/1e4-8 15.0 ± 0% 14.0 ± 0% -6.67% (p=0.029 n=4+4) Decode/Twain/Huffman/1e5-8 20.0 ± 0% 23.0 ± 0% +15.00% (p=0.029 n=4+4) Decode/Twain/Huffman/1e6-8 134 ± 0% 161 ± 0% +20.15% (p=0.029 n=4+4) Decode/Twain/Speed/1e4-8 17.0 ± 0% 18.0 ± 0% +5.88% (p=0.029 n=4+4) Decode/Twain/Speed/1e5-8 30.0 ± 0% 31.0 ± 0% +3.33% (p=0.029 n=4+4) Decode/Twain/Speed/1e6-8 193 ± 0% 228 ± 0% +18.13% (p=0.029 n=4+4) Decode/Twain/Default/1e4-8 17.0 ± 0% 15.0 ± 0% -11.76% (p=0.029 n=4+4) Decode/Twain/Default/1e5-8 28.0 ± 0% 32.0 ± 0% +14.29% (p=0.029 n=4+4) Decode/Twain/Default/1e6-8 199 ± 0% 158 ± 0% -20.60% (p=0.029 n=4+4) Decode/Twain/Compression/1e4-8 17.0 ± 0% 15.0 ± 0% -11.76% (p=0.029 n=4+4) Decode/Twain/Compression/1e5-8 28.0 ± 0% 32.0 ± 0% +14.29% (p=0.029 n=4+4) Decode/Twain/Compression/1e6-8 196 ± 0% 150 ± 0% -23.47% (p=0.029 n=4+4) Updates #27151 Change-Id: I6c439694ed16a33bb4c63fbfb8570c7de46b4f2d Reviewed-on: https://go-review.googlesource.com/135495 Reviewed-by: Dmitri Shuralyov Reviewed-by: Joe Tsai --- misc/nacl/testzip.proto | 2 + src/compress/bzip2/bzip2_test.go | 4 +- .../testdata/Isaac.Newton-Opticks.txt.bz2 | Bin 0 -> 132469 bytes .../testdata/Mark.Twain-Tom.Sawyer.txt.bz2 | Bin 118509 -> 0 bytes src/compress/flate/deflate_test.go | 8 +- src/compress/flate/reader_test.go | 4 +- .../testdata/Mark.Twain-Tom.Sawyer.txt | 8465 --------------- src/net/sendfile_test.go | 22 +- src/net/testdata/Mark.Twain-Tom.Sawyer.txt | 8465 --------------- src/testdata/Isaac.Newton-Opticks.txt | 9286 +++++++++++++++++ 10 files changed, 9307 insertions(+), 16949 deletions(-) create mode 100644 src/compress/bzip2/testdata/Isaac.Newton-Opticks.txt.bz2 delete mode 100644 src/compress/bzip2/testdata/Mark.Twain-Tom.Sawyer.txt.bz2 delete mode 100644 src/compress/testdata/Mark.Twain-Tom.Sawyer.txt delete mode 100644 src/net/testdata/Mark.Twain-Tom.Sawyer.txt create mode 100644 src/testdata/Isaac.Newton-Opticks.txt diff --git a/misc/nacl/testzip.proto b/misc/nacl/testzip.proto index f15a2ab224636..1e9279e4e0c13 100644 --- a/misc/nacl/testzip.proto +++ b/misc/nacl/testzip.proto @@ -177,6 +177,8 @@ go src=.. strconv testdata + + testdata + + text template testdata diff --git a/src/compress/bzip2/bzip2_test.go b/src/compress/bzip2/bzip2_test.go index 3848603e0ddf0..c432bb5226ff9 100644 --- a/src/compress/bzip2/bzip2_test.go +++ b/src/compress/bzip2/bzip2_test.go @@ -214,7 +214,7 @@ func TestZeroRead(t *testing.T) { var ( digits = mustLoadFile("testdata/e.txt.bz2") - twain = mustLoadFile("testdata/Mark.Twain-Tom.Sawyer.txt.bz2") + newton = mustLoadFile("testdata/Isaac.Newton-Opticks.txt.bz2") random = mustLoadFile("testdata/random.data.bz2") ) @@ -236,5 +236,5 @@ func benchmarkDecode(b *testing.B, compressed []byte) { } func BenchmarkDecodeDigits(b *testing.B) { benchmarkDecode(b, digits) } -func BenchmarkDecodeTwain(b *testing.B) { benchmarkDecode(b, twain) } +func BenchmarkDecodeNewton(b *testing.B) { benchmarkDecode(b, newton) } func BenchmarkDecodeRand(b *testing.B) { benchmarkDecode(b, random) } diff --git a/src/compress/bzip2/testdata/Isaac.Newton-Opticks.txt.bz2 b/src/compress/bzip2/testdata/Isaac.Newton-Opticks.txt.bz2 new file mode 100644 index 0000000000000000000000000000000000000000..6c56de3bc20324882c1a15614b64e9a5f1ed4131 GIT binary patch literal 132469 zcmV)7K*zsAT4*^jL0KkKS+784@Bt6<|NMXd_;JVo|M}0Du9I1c(>_ zV;_F?J*IA=kFTHr3i~kV_hlLY&;S4m3Y7o~1yuzVKmf6aX1=uw0D1r^RV~N9`{Qg9 zYwu#cQd0M`h*0zz_Di{!pL@QKhhtPxR66>7dVN0E4%=)iDOEuF^~#GgB@~MAnnJ70THkBl*6b|mbig|`P-|_FQk7I}(gjIYgAh<#PiCZYEsQ3a04*&w zied`T7*!=okS}JMbmqH^5>-?Q5}=y^&TQLS2A%Bs^Vnn`W~z~+M%W4z7J~pc*l{5Q zh?JEQq(qXELP07rJ<0J`@y0AGE$G-Xu1KB`CnPFJ!;ocZqa zV4EvXyR^lQ$!_xz+4f-hKKZrbyMmP=S8la)uAl$| zee(9Nz4JTi^&MY9zJsxI0Jb*ER_M}n(P#n+b^;{2Rbl`FF63F$p(21OAOL6?+~_KS zM5v?CX(B`f2~wH?l#-}XRSFf7R1d!Jchbd;SnPLq0%ka?9G%wl;)<@aTRCqmwaRdru-92?#^%X*a?f2f~dpFzG?`}KSxKrF1s_FLKz1<;Etd30-b32rG z-+213wNXh_3qh(~_ja*BBoq}wgpa&x-*0ezDbKu%=dY_>?(e-XKKb^qtyNKUP%7*IIs?A+d^Nq-*%i!#gsrmc-^_cHC}_T$~xJJr2y(7U$IXA+w0p=O3?6r-zj<=yw+ zTXpT;o9qAp0GWEvv{kGC01*wnXK6v`joI6*SbfdR`<{2X^Si*?o87j)?>?K=KJML@ zKnhZV8M`YHvEO~FQTD-iy!yO#_q)?+YgMz%02CFwTVxrpz6u{e)mQ)@Ko0j(r`hR3 zIoV^4SGS#r&vUmO-M}=Yr~m*05DHX4RDeA-vl15XR{(nC05XsXA`lP**{To%y$8ML zcd!}(vz?n{F5$?401kpW?ZEr9}bl7s5lB#K4YaPYZnM|Aj1Qa4EDJrOXI3dw{O-_Vqb-OIm>Hs9=__z>tor_s3KHV1tbKNphZfOf=VcmDy6>q(f1TU z4_|u^eRH2p-c7aJcXYQ_&??rg0020U^fja0ZSLDfZEkozlX@Kn`+M8i1EItk^yp5* z0tVSsNukit=eC2^NhI9b;9$fE-|^rak0&X(%l7I z%XU+BbFS{$&Z;Ut?`^s1Lg?L=R%9K_9oPT>r3FP1?~jC?zVAn;s45p{yB+RwyUp*j zzR#C-s)xSw9-iNB=xLB3f*}Dk34{V-XaO2%BA(FHX{qS-G>k)PX!QVS2AD)3kqC-r ziICMdqK%V8&q@uX41fRwKxhB}&=P2rNQt5d(rC~TJyZ2H8hE4B18Ot@p`ZqykN^Mx z&`Ii&i4q9WObty_@}8-^De7o>G=_$Tng9R*0000q0SZVWk3c4-37|}f(+H=ujE0k9 zWXVs}Jv9T#sM<{pqWv<$sM;A#kOV`-w6!q-B$TAA36LlH_5g3}{-53h7}9_2 z@pCd}wd(HGf7)F({IvSgMSr_TBFn) znxr-T3I1La`FA-4&4W)h&SbO~>h1rTXi*?{wy+00Y;4aL;lJF zq6a4@;dKhaweIY4h`F~mDs|geXY*?1B&CyCk9PkBys?d_t?Kxx#+oWBt)Ri1wmZmC z#IOGt4S>VP|1bIMe`EiD`FuaW>7zg5KgMQUIVwe$_*WnKpZrUPVg57Q!1B`mpI@K* zKJWZHa_S%Hg!;evf0+NbUSIa@t?aM-KVPrgvGn(QzDa+;pnk*ldVQY!XYDk-eY5lH z*F*o6{J;47)%;CXX%!B0ghB$rlSV%|NoP6lu`22R;f76Dd3R1NyGi7w`#AYhQb(gqKb2P?>ZVPw3Sfbjb+Yn%-hm%d79#<)^gHSo-bwk1l%1 zeZm*`JM#-?C)I%c7trzRTR!A+`~-t^?(7B+*jJV4Jo4yrhlAvq_&tI>dG|y{v84gM zj^uFI)6Po}r?vJ>77-!bBFK^n8@)GMpZ`yey(2>_oD_ut(~p6d^>!a0pJ|FLN+gl= z{)Y}h`V?UWTR74n7WU@b+qs-O`g{35`Z)RhFX6&#Aa8^_;3Y^uzFx=2#mD9FOayk9 z3)|H{UQX>uj;~eoEzB>8ZV1>Xg0@GGaH)XAvLJ%hKy#$s5I%`~Aq!@~U?ok%jgt1S~qtedm7_VtqTzxzO~=?g2FGH2of= z1SqU=TJ+|)1*GxHA3t}GhrWD990y+I>l_yK^_P!u^>+65_u!5*=@+6s_g_qWAka)0 zA_q|o@P-X;0OXw@H_{06@3X2*@}TUc$LI~h`{>MGc;l$#jyaqF!WclxVd_8$*OCNB zAW6U~MhgI^<*e2$d~L9K)Qc^$AZ#GL$U$z117LwiM$gi;dVttI-wf&*Xr2CMt`Dig zKPJRcme<8Vg%}zjpHEFMR|J~Ng5UxQBWEX#A@K8S7ysgLb%FiG{EOMHU%PNQH zEFiGKXtK_1fxacc$@TAtf{PLf0fn!?^~bukf|Yzoe6Ez{Y$VMasnG1=4dugN_uNf(0J3`v1t>0yH6TWyQMIu z8Xtm2@pEvLb(79Lb?<%+Z(1Z@v#QTLi~@%bLNy{d#O#aEN1RTpkp-z!ix5bi%7(Ir z72st`cW6S78=FVY^Q|0PeJgV4; zf1WTs-*?6SKl}ZklDZ@Qf9mW0abA{&1TT-n|BQa|$)>-^CIp7~7Gicl`5qx|;n@;8 zO^QiF{$FAY;t&K9MG!R{%WwL0nx6RDOpcbB+6w4PTipG9K=wwC;AiQZU^(B@Fw7{h z5nofk7B*ZtffEurGzS-vYNL4jJ<8B8{yLjw@Kd&`D;-YM^CbLtb_=X9JM}VktVmM%#7${=4ULD zwAr5vkVz#(i9EVQTAN{+Z2AGkdY~XS+PBT>D zD>i4o9>@XKPf^YVP3VQPHN3xe`1J9p#bU`Vr0zGUPQelWBKS;s>i^JP;WAuLg7Qd) zE@H=1?=y`rL+KcCuM}}rp}xGW3}1&pu`YQd5Ok{|TFXV{+*_uYgTovh5d=y;Ze|GZ z@#ua0W~>Y{Odx<+(H;?W0(Eo`0QvJF;EHD)pAr@f)=hKU?x(+YfB13ZkA_50@4j*B zCJ<05dV3|5=B4OT4ICI9)wPOypdV>y>eiL$VF zICw4;Y}Lh1=G8MhvQEZu5Vu|!<803`9Kag)*|&$VsAH5 zd>I^(fjXoKi^zJzfl!q?&_rur`NoLStX5)!QS6BEJD8p=4B^KG(_=0Z!-dUUS(}5E zis0MvAO29jI^!www{xjpmHG?wF;WJ>J`?zWv9+@kZ#Q$vUuwqSF9OH@`rua^dxQzQ z5B=i$o@@2R@cq3P@hbjkBM{D&eH;YP;%psg ziR{TQ!3~Gu_=)}co_W(bCZAoI9!pn*$}PuEt?=+q5aG*n+VLw@$=+n&B5{DWcIA2N zLQlZVtX)Up9kuhk)%%vqm(1W$!p5Qepv5$KvPyh9v7#szbU zz?T|$38FzADTOk~`Yik3j$M=i91k-b!BqlCcH?>yZGXXVwR_}%!eHtSzfdumXj9f|Ig4xqsc3kN zn3(kw*RHzetszap5v?GfTY!ssS)?G2aN)ZCf5tTmtB3aj{2G|`bU=a$9uJPZaSn2j zm&TW54JGfXc?OWk^hlG~AyGt#K85ZDZckZr>leG}Uvd)&BOLJO<`Yk%5m5SDKh*(x zA2ntc9;gf$fwr#fc5+)t^fF+jw5cw5^FNe}=0XSBmTU!~a|(I28SBRS8N zL#IPAyH|AOwpSxEO4U{f2g>8X-fU`?{c>+o@K32fL%q)Y-6d2k$$M5wZ$9GxfzH;r7DC*+XN=+B&?Oxo}rZ`!G{3msR_ zH&s>m>v|_wKGj{St5!cGNf&Q6XCeXY>^CFSaG>mr7IU0>9ajTmz)|U=wci-Zkz;os zJiNg7dURZt$oz_U-w%&Qqu%{}qN*~RI_$nUcdc#Ad@>5=sri0!?u((t=vF5&d9y9X za4?mi{1&09#%4S%l6VSn4dwXMZ^0pOFg#CNiv&BIbW-*_?Nr?~1DK4u3q zn8U}uDl?t@rC@*eVyAx!;PQB{Vsp*FrtTZR%~kiy?=I~*LSg8wm!-Vc{CbAt0gYLF zNMwrTOK#3{7>btHRT1-yAAr zu7NDZ`nOg`?3MPoEucSdOYs}`ozJlWXbV3*%=tA%6*)X zZIhmC7s;Z_mrugC8aTzf%dR7n8@J%2lKK=luQVV6IpGHrX|@#bP8tj!nocgy0nr|D z%|oY3z8xGfh2A|?kT-M<9HWjmo7$VpYdhR?XlD-LYfu%1#4EMI!8m|NeK5qi^E6Ix`r|5m(SZ@nGR+A90NEW8ru(` z58QoDwGI)=f`^^2JSNsgGE1qoS~M}heT*-UGWpO+4mGV&e{4Is=T+~DbUUiP>dvuz zzUPrjr0&_oVbH2VNC|FCL7H6HM8U6I#m*ggIG|ADZXI46FLb;7o$fqToB8yx4;8*< z^6zNx(4EL5fwQ93%shYAqVfMeO~lB|IeAnqeLk3ld= z@|Bc9&w`R0of_9~XA|kFt$N@NwHcf{FBrtETnIxL-+8d(R2~YfEeFh9V#>2#vpL(o zs_-m%-sW(%n2uETwYtnBz&9dXOa#Q__;Fi;W&#j*)U?71K^TPFPlwN0t_aZ3MC%=Y z0-EzUGQ8&`f+x=&WxDV9Z+D|wcqsGb+-p``XT0j=g`n6TDH7-6xUK2p-url_fv0!G z?;-xv=~rhssEHb{d=6SXv=Uc}$sb$rbvGf;;qIlRV|Hiu@2SRSa_chpZHC=9)x=sn zeSgv);zB@~Po_8o$jmIl1V)T802M!D{LCpuUhKm$!KSi{EAnI7|36>nKc7Eg&M(i& z@E_%oc*4MM%s=^i^Yz6GB$L~8Tll&h5E_@&6MKHBzxz~cJorX!-kG~0km)cRB$MFb zbDVOb-=AJQFCVMSkNx@PH2psv_a?g>Mg1ces5M%TLGb^G1IYB_jqtjTIS=ZT1AClw zc0Dt{qrm6jTn~4`S_3eT&(?a@jL*A;I6K^Ua~+2sPpvRC4|Xx>Y+Y#_7C<=vyE!$2 z{bKGNiU^sah9GIwQ*GG#k1s!~(e?LhTDSFb&JT|JYi-QvPAvnBULJDZgA+qT>E%zy zV&23$K})wTq!Yd!^nKp^J;M4T#YsX?kwjF@ALi=eO_+CfQo|*gNu61v@dKnd}lXLuw;~9YjokDpo_Fd3T`p@~6aA(;!0zT|!;({rXY`(ht zhtxi@9Ded!<*ql`BtQh69f2}@wJ7y1qr%!wn|!*sGJEjNnyQ|S-=8;&_R8yxb_ z!wx~_{?U$ba@)}(4>CqWXd01h%l&>X0Qt!=io75W(@Dg9|{2_)*CJ@Hmr>7-^(DsXgg{&^)PXSCFKFkfqjx>sN||vq*a7wo!*X_wgIRZ?>TjPmscEZ#O6G`UVJ)?gKI)%M?RMFc9hdL5!A+$Vc*o=>HE&=GmhI>yQRLl4qZZsU+&z%u852bK{et#0qi-P zDFAV~p4qL7S98XDm5mj!37TFfsZD?_y1?t9r=SH`dgwP8WHEuxFv~yJr97-)z~&-; zy*vI{79ff#B#eq78uja52o72@PeZkX(Qd3WZN~tT z8#z8M0W|0kTLK;W?qtRlKFbg1dVDKCco?&OQ~7?c+vkG%($blP?HgjPNKvI@>Q?N0 z$nEGOqOQJRol6sT_a5R+oxMnRHan@GqYu(L#Wd@Xp9p?}f!M-fC54y=2q4m}*+J&; zPpLF5dy{ISVbIUAY*Gq7IO879uFdlfUf*#LV2kDCa3`o4^-@h!N~w`16ex_W)gM@| z6W6W%amT+h*`6S}#}7xG%~0weChZ}GC4!McU5NxM&Z>!jIKY@gQCVMcUWaeAw_ym~ z^3Wp>&w0M3^JiyVwk%DdX5UjHS9t6$IRNPNctkJVclh2Si|KzORVx&n&>?6ifin-a zvJs;O>fD(!4$dcTi&+(6>Nk~k6xzy;Qy~Nbktl*fBT2ogA}FUb>sO5XJ@YJepSSK> zf!S=HyNH0pc^h`t!e(SZ^PdqJ-uS3XT;6gs&TksMymRsON>HMMw2nu@5W*s9T1pBA zlddpFUA67w-&eP%PUjnW^P`T}=?LFCWJ zfy?oD7*}FPqmswa`v*Ci5N}!WB%I6DKTsw_8E8y)SpZ{6v{+CrOjr#YB4-b*$jFH? z%Np%toY_Z?`qvTF(QJlb>E8*8-Bx1!b?$&H!OM+nmnuKuC=~-rS!4_bToS}j=S%jYRiFidDvSHc?g4Sq4i6Iw_;;}D7?0t>4n#+Q# zTHA_F3T5521U5gGcq*;QbO5{ zW{eKdMOg2{)$D*cMGX)cCmh(9xWO&OBZIYbmV@tanpki?CORV01&wllZx71@!&~3m!%WcTkZI&q&`XOps%b`p353ZM z5orK8X_3#S?I2IO#}YsUT?F~t?nVl`#Kg%m10o>;5L-hz3Y_@-W`3W1rBqm_-Pk`J zem{#tt=2jP_G*c$IF@jGAaZl$RRZaZCJR;D#$$)V zrxUfGJJx`b2*@W}_J+{|qq|Ll2cZZM7!fE!=dVg(9MKx{-lvNp!&~<9x_Fesvo+Qz zfgD#}T41S>j06U`5dCPZnr+lM3yB?(MnFcZ1+2kjn={Qkv1tac$x}+rVu6rBe`BJl zhbNQ}uU&c$2g7%x7~){mL7C+8Y}aLw(b>bcO5JJNx!&JuE+L1uDm(c8|IhdmTlN1K z{j>a!@#}n{;BNk}IT6YUXv9XJE8maHujPZAefL{&LPQi|55oS};D;olyn-1ov$!$w zp#r=j2}n1*HMBG`C z_LhKJIMa+m5h=?268?4tMV~;!^!^UgAb8{^Fah={o9`jIBi={1E0*ryP=mxIJw48A zM#Sgc^8bU2BP%$Cv9bHj55`6Ov6oQjH?e5;^vLlNALRa?vP($>u^?!HJw%vjEPdTT zoK%oJ-T_5Db8W-sQ$4Fll>-E{S^=_|`P90WH{$>@DfGGv1>SRVK`g|v#s{&$HmeRu zIDHT$jxwC$qLdKFSMKkfe0=c7FKnjRcILfusgZI}z7g4*LNq!df-_5ah$5n`Kd(mo z?E$gJ#?Hrp^m`ziFSSYW(MpNKOw|fZj@dP+fUAmrH(+mKq{y(SrfReOj1ATbt+4wU z@hJD}zdG=DgmlK}{whC}ictwo$c3Ew-rk3#k&tIS{=~=F8z`db#2feOs{mV7kvI@V` zfU?Yr7Dyhy$pNC>`9No(j-ku);$zbh7a{2nBn=+5Ja=?}&}F3h52i#;k3(Wyv)OXF{VPWj!+1J zF~hR1SSQxX3U8iMl{yFdGhXR=`teit=sXNM9T1EmSVwQCiI4oRc@cT>kl>Nq9?h2} z5)+J(gTh{!#ehibDRl9LA^rNBvkykg}f41T`+Lxf!chJf|1km1WgdmUj*b6(6p z*B_eiB~c{v-FqyOJypm23*6rAU&j6|I#p)=m60*J0J~&?^wBKjjAh0yKIpd%cghM2epdkuD>?-l&5;lGI+*lz_cY zL~E4HIV?0;fTGDJ<2CP(e?07276zIVG5GT$+WMMc+6tVef_hVlmtZSQC!LDlII=Ku zQOQp*VXtbN1LH)C(+u`I%;jAQgMI%m2^UsJIkFh&hsNSLKTi}i@SC+W0pU*x%X}f@ z#ErW3D2Lr@1?}o2@1FHyo51UO(JVDvg`Ltg5kyj$&^e07rQnVYXwX)eMi2^62?S1( z`6vyPJAO2I)4{~&TYXK)!jNU#8~wSRUy+ZmyZPTiz&^I))V9uu5D%TN=5PyNfQYcY zKFQ#@-><7BjXtnFG1n4Y`XERSTKJfOjudRnB4A+p_{@`$FXb&r&hFkhcf@h%>eK_o z2OVc#CPq9iAFU%Z>p)!}cNu01;k(p?!gkuXKai|m`Bw)t~3=ksh#ZRflPnBbe zawMWKJ>Sv3L4o5r^6+cX+>AiF<5woxTGh%pD9Fp? z*f&wmUWbfkCrsZ{VU&jh_q1vtOEG35K@6E!`gigEyA5Qpw6ou@63xgg&DjAE%n<_i znhz{IYr-pL0B~6|rQtv_WUx{Y5+M=^MA3y{d5UQ z;Y~*(r#|E-)d4Ptbljg}AK;V9K&gP=sEYlcXYhG#uMY2~?-{mAl6-k#1PFq9tO^5suC=MyXcryCR4@CV3%HTzHj5wa0P2rLjFev=o;H+L6R z%D)xmjg7wlu0%peXoV#dzCNE<%vaz^U=O|AWU$GM&&%Ib%LRF$`cm-$5Lvbbk^Pta z_<&@^Muwq7&PfHJ+i_uFjS-;Go3NMz-Hv4}gx0Bv~dN6$BL4<%&Z=@J#kAV3w5d$0ty ze2^s|MW$ImsN)fvd0;W2>8B(~9>fL|OXMddk0_AKBkyA~Jjs}e%no2y3z z50~qQtNQa1Hth##BI?KGtsgH;4_!TGoBOY+<)W2Xm*J05O)nWo<`n7Dz-tJXfs*lE zFoP}rzAQ5^Zl##M?jP;yCK#dF9S=`0$zdm4^cXMS=EcS!E;!62_S#na1yFLlR)J ze!|M`-QwmpM7-W$%yQm2d90Epj6#hxddy(WHXDWfm!wtqAP|V@0tw{tJ=#}0cFmBq znHOT@NuL&Uk)Vuf+a;e92#@1W$6ofHAH|c=76&qPXei#}>%22f32BMnIpySylFop1 z2uNtKGy?c=cC|nd?uHUYqEvgEC{?0H64@3*@Q1!Sa%6fSA5$3cdpG}*ht4ak&#cq} zVd%Sv(YXYPzo2jPGYA)Cz3VKJO_WI&m<_6p&g_^u^KBU|;B{DDP;HG~dlFp{?aT)j zL9B;Ga=Db&dJW->PL@#Kh%E@_~4YoLp{_@$WQDidt;XmHT2%`h1RkF%J)`ku|_ndjKRIAVNS z%%SO@Pp}c6%kTav56ymMlPT8py*hT3KN3B)z0cA#axuFzT>7s-;Ts_F$3(ycj1_z^q38BCXb!RZ`kEQN zBoZP!bmN!pQcJ|iEiy(zAgD>@%ekj0S7Om4R-d?Ve083j5 zooE37OoYiWKx8=;+Jg6xKr+rU3^Ywyt0T%Hv}k{OUNKJ>y^@>|Z5(EKh1yNzH{%Cl z0O}Wr?FV8F<9G~*hz;c4Ih~|CLUY|SVEY<6ARiLw@N=2+VY^DX-l4eZ9w0<5xV`-yYPW@%}QNT1;KF@8LQv6_s z$$9Gm5J+^HsG}ym$c|7NAe++136#EF^vx=iYmC4}Q9+H5JLlLJ|uo_!~R+hlzf+|sf+YTJt%n1A+e&)rBLAjw67Ru)F3cT?F2*dN48gHx-zXG)|llX zpbH%8AWPlWORq^7ZCi5SN$7_rmJeqh$(vbsM_6574k-I97Q6z@l6gVNDi5j;2NZex z+P&(5BX?th+?^4vB4$4Cc7#Z9TP4qC%Ze#xf`U*gyK+qtIG^lmr!rVSkhEKjA_1f9 zTpwcw4`7nq>PEV}v9?Ahfly$AmLTF19^P1tizu2Xqi&(&^RIbl#MQi-X3xR(N&S53 zpr;^u!_|J@;q@kbwD_MB;(GaN^zEQl4X1+%#x@^mK5sPftxvCg_;7qaRXz}ZRQ+Ww zwKzi7&wZ9>ekE9MX`e(tXTgR=4o9zv-hLbdl&P>p(Z)PScn6L1Dt71RzT3!i8Q%k# z+IE+Ftm(LyHp3*|4){Zu6M0T8+h7!^fyJ^0;|w(20%^{$Zw}DWEf1MguhqXA;Z1&? z5b^lJzPT$pqs3w=q#N1;C7^*vqRbGjWcS13HKCo6YWH@8$}YR}yVrvbB0E`ktR~cG z+YF*1>f}LKBqUCpgo)Vvt<3UkYJ@7*cGCn_3yea3n-~(4Ud`)Hj=Z{Nho+`wZX!v= zqMJ&^%(sDDxfs{+wSBHo;N_=<#mgIE5^RHM5lGPCrc+RX1VC?ASg~M)IxrSQe1VU+ zF338-!QeUzF~N=-g9wrraF=57-HDkbg3Z{8OD69O#R9y`l&TP@eam8IKMb@Zx7o8* zhN??eP>GTd@eLWUo{qGjhnX1_*#wx}2C^ljf=0`bEWvG1)c}L%j$k&y!2<@NHrU~M zqL9(c9bejGRB976ooE?A;~WkaQ-y}x1_VFKY=*7q(%@a-LW~HfXb2P@sCJ2;ZF(3h0}}{eV~Zm1G^2bFLETXBrv$uhlA}tYwIc=IsS}0pXs)u zeWf7(kInJ(KPuwwHQhlf$fkd~$L-*QfkGEa9vh@#B$CJIxGpr8<%Gyc?`#;HFGZ&4 zkIE7_I<*9oOGZ5zFBP%X&Uvm#)g~!5%JG?hfgEFQ#uG9u{V$lgP4e~rBh*GL{aDE4 z?EHU{uq3q>uY33u0Y#9LgTlFn*#J3Ua_AT9C8Z}WY{U7&9c<79jUJjNs1i2Ab-;I= zb!0a+InSZlA^s}m1AXZ=E&woB_uY&gash+t* z1oAsrnZJJb&=biS1HuTimP70gdjjjmPE4P}`f=}gYVMpKDG@dKQA ztWOU7isA%@ABY8s1c1cQc;yQ`=dQSt$4%CsMU&}h=JcM02kII;W4B}?q5EZ6i_B*# z$VqcPosTU2dvTh%0R1LoJg3-_zKlO3=iH&0-!}0h=D@P2jKUcq;{JPN>rV2VcFj~M zb;pB2v^s|_t|B9`+|Pf957F^(>WhQi3$YVYg=@GJWO3Qe^EEEXkH){n@MS#MwYQ<# zuZowy4{1M=QIL)6ol6TOazY}{V(T>|4}qk-m&i}!F{y2Kuv=XP;uUT&j7<*!+u_F^ zP|F*KZI+HsQpnt*l~rQK3pO7PX|O}<53bwL)Pf1+U^;JWFB|ROarK2j)Si$#&!y|@ zfxI1NwRxMM@53y2y6&L29iUK8nq2raQ!RN$CP%0ZHfH$!^E`)_J#2B zKu|GEIwRH)7PT=@a+IU3Qo*0NjlG2CsY(_taAb0f&hv3 zl^S|T{ztLOf~mHx3LMokA=(eVW+4o8k4z-xO8^MnD0^auidC-^;a1~zr+JnCu@1DK#iSE~=^^N15am)eN zs&VC?gRVN57Y)}M0f*%A!A5hBYL^ovbVnpSl*~wS!eH@kIEivZ5v3i%Bea@*K3fgp zy3O=P$P-NZ^>2C@px)qE5Lkl5WO>m0aPQ!F%e8~^?qLe{LC1>)=6ss-6=eGf6Y9MW zRehp0FJ9US$n8n(hWU6i%3-6E{74;b0MqB%H&cM8!o|)V*HI8mZQ*jU0QFtFV1XnA zPLl0bN{Rptu>rlk^6kOaJM7T#T8L_1(H=V0HnJ#V7ky3z;R`WD8$E{@Tkme-3t1ur z@cu~iN~;K-DiH~<3hxA6CpDNJx(H!8f_1#XtXN|p6}4`SBI5!vFUM~p%#oPFL&@RC zts}`8cXmBNamn@0Ty{1)aJ#`10qIa;Loy%_FqN0Y7uSoln@P0z=f9si`P+nrSVu~^8}hcAKp+)a)v z@*(ipu+Tg7P#2tm%0Y{V!#)1aY*)ZM+>*CLe-#o!;XhBqKRGnvq|qbS*93S1Nd=6h z&m?+y#KK8|zoj5{>XErI^31v1O$TV zW+xoI#O~_|<8G|5jeI(jioCEOVQ`962;Ve>LIe*@p#_|<#M>s=H6UfeA)Rk=Bll+N zY(gTX9n75;9~V_t;c+Vp0hr!3r;|t25R_EJ&FowYt_mmf$cT z3%tz9%+WgtC((MG37T;pwlg5lwek;YNlBFR_ez6d$Fj8scWmB{y!c z!ptK6i_!;X$So~Vrke|1$iW^FD5x8VxM7D>DpHH)ZdBsVEIn>>jPG*>_A<2LUdWnx z|23D8{Gu+Hx&bL#rs00`UwuEhif+YWOfG9EcM^ z#ET&waSyXouJ#tP)`rYK>pE$ri{*a@T?v5jS@C2JcnGgUb#Wc;DmTGp7Z=y7tOGF( z*zx0?cQ}FM&-stuX5mTTL;BtIVe992v@in0YfIDbEw4iZ4)tI>C zQ~~IqdPb=NsFlUqh?0w%Int_{c3_AZ8NiWmWyp(>S`wta=HwGESX$TpH9I4%Z`$qm zgCL!uy;H8m<@)V2XJq7#Z%!`wn48xWrLlq*23*pC#?0XXxd1F`aX2rS#^ZN8BUN?< z3_l!W4S%bLjN-Sbtj7i#quR5e*w?}H3NvxIC$}6`En*{!M4)rnIwsdEP>dJbhgu5@ zAw8(82%S)n4csi6SKA%ClKgg06Z$@PM6UQo!@45(x-zefL;L1(Kci4|F+09Bj{1Q1 zB=y$1;>GjAyGNW#VzU$5^6};FFBZr+2}f6J&#q^igytd_7BwSp#p$6=D7~5p(!{Fc zSUWlB7Ftm6je}%vM)6WM?d=ckZF$xlAn+lB>sXj5*_m6}O?x__qIB&6kgaN7asbkNU!MXiS=?hv>a>>?Gm71ah7fRB6zHedh~F|Csl?~#8wC-7=E~z~#1WJv z@v)}}z#

_{Oo*t&^gX_Rzbai8kLtCfLF`EjovD0ModHj4D}&nE;>9v>RbYIPSV= z^QhvnTp>oRpgS~4damYJhd@aVlbsc6P4ROZ%79BO?-_4HGh+xZ`*B*-y*lGRJFyg3 zzeCSCxrnC~m zSGU2+-0wdz&aDxof+L(Tcb!5HwZB#4ty!c$Bdp1A2Hajy6Gw3U>lwkU3&G7$7f*1U zJkp3D{px%yl1m`4f*@8y7)9Ugbp>)QOe{;*cK6L(3yYo$W5a=IRg^pzrc5!FXGIud z1p65HZeJwudfJMncPOknaJ;yf*_PpJ5f4`v6xoydJawU;2a)?u`V-e6UWXF(9}4Rn zWMd?DPPAR$51gV!h|Yc&U?G1c5f8UR1`eJ1tqyd;%e+oD@(2@$#)}1%JtrMqae3uyab?~KNe8KnHY@{T=!(;(k4u6cefIapaQKud zL0A*67g|{(J;uz!FNhQ}F;N>DGXr48HW$Zth-WAgZ6U^U0S^VA^-m)P$4FW{N ze8?=s&zkLyaP8Ld5orTuYna9)Nw&t~5fY4Pw3i(?I7oqUV`Nw%5U(2~e&_0jh=$}d z9Qk*5Zf&MNn&0x)Zr8c07`H%?U}w}3^vC65t28fM4$b{4nsW3*^@Yez#`Uw~!Mejh zdxw-86{ng-6abRYQ1j*4t89ZX2#TsEmkQzB-%*Rt7UuhpTPQve_i9;s)HTjf0=dQ2 zi-GN$^qP7LN0$mHbow0<64g<@XvS?eCueJWFUeY;;57axl@!?SvDZ{oe ziHy^J*XaM(pRE4x<)&|W14W3!W!HxiTd449{vKVyAwDd^A3{CF@73BqD;UeS8CjIV znSVECn;{O2jjRF&$R9H&1ZtPn+Oxb{jk$2Byar_GIRl91VpJVsQZ02R2_ewTm4VsDZc-% zd4=xt_9vP9i`y(8-TaXJYa?q?QYLesF9%bkBl&ACkVO_`ew+yR{T)g;zJaTHtWRD) zZ9%b|10SQIf2zKtoN^QWcXG6ey6sD%_4q!Lnn9RzwT21_N)W^H;_CC4?19-6gbbr42OR3E;8=-bi#c%RpmU8JCUXDQu&CuW!4ZmGs0)G6S6&p@KnwMUAvmr%Q48S`>w;1_dBSqXDUa!H=k(KPZ8rXz)&DDB8z;>GITx9LCM(z$Vvch*i2DstdI7M0f)VI z>xQ?R$*xb{Tyr}->pEvm&8nz_#$87jY4wAYkAFL+jQ11qU27Z^@%Jqpu&r^o{UNdr(Si}ookMKy^m9-`PY@=N8vb8B`nK8Xe0@$ z*$9A$0r7FuJeB*kRhCc;^Zd)X6;AgNW*I#Ya!E}ANmY7gKvN$0${krzc}6XCgP44w z+Fm2=xr$GVy3Z1CWS!&bA*efSSwP7&n{`9}$pKy3nu^H&7$AxSKqB}_icW?qP_d=!i~P>#kf)RxoZ9wGE@bmBo3qw zRELIPR1FOUH6(|1g+)nIk;gwz5Oq6tc!{Q(19?S<)(bzX!4svj%pkDfhNnY#Lvv_t z;gJ-?BjmTQi(+mVatN{TQ2b`30$bg>@E~Y8!iVj`CR7(i6S9bo>@S$^G$Fs%TZ>%f zKD)-f^L{1lQ4uwDnKVpLo_37P-p?DSi7?8~`P#^SKK^g^e5r<|Z}GB=^MVKf5H2{K zW;r81h#wS`-=SWLpTIYO21^FjAVj7cY@h+TaGg0}m2SZhdM;~;9Pekwz;^GB(Cq=# z4FTc->$dthhgsi9V4xrgg2IaoqA<0XpUfD7fh1&21%!#UZA2d12NoRSUUK{0OtKZR zhgLPqYb3L@tEc&6xK!S9h;!-<5X;t_8CQ>&Vc}iD+$${!iiC!2^22`)t=l zX(|~uj?8Z!Vs=O>j@w5@;WE{JIub4)BO~KNw>#!`t4AqSE+xd243_MP1&P_qo1HWU zuM-1p%g$;~rY;`a5;mRvesRoZvz{zONl-Pyaf!No!ttwn!A1G6<2kGyI%9?eU;5_! z?+y>_Ba+&Q(gzO1(k0yXZWo$Fk9;_kfWjnXQFk4{L;Q#kO+%7s6n^K9Yv1|fvp|eG z$pa`9N!z{(wM0|@IYYE83xs|PuD(1`YqkZAK@(rklE_m&lm3R{wI=O_ikVyo^6xd4$z4W5`C877OpDri0;VCq-&#Wp$o-SUKRwJH+Jl@ zH3_3F*@+3FsVr_{Vi6;|7BeIY7&m&lCiROac8+e)PDk|+J~Ko((JI_LD+EZK>R55` zsI?_o2odpkjQg&{1f)|Tq8!I-2DqUP1v8?0yXPwD0QZ?N^6n^!9ZQK9CCB*8Xm0k~ z@p0#uW>O=*2J7}VbK<2m?BM>5k>r=aMTb191Y)Ld+Zud=Mj_s>yKy=7A~ANke)(+; zaK9H=BV=xgM9dCM7%9*&ph4yAOh=`077UY03_QJ%3HmM{vfd3(-`=|eyX5HpQBRyE z2`1}>#n_Nzmp}s-tj$F2LxMB*W!QeW_Ims@{QXD^>z<*C5I`X0v|pW%#~0D_dOt{* z({+qG!ktKQ1XatLn&iK4eV$Aulbu({-|qs}{O{9z0m20JBRCTxAp%7YXL1b|;;F^St<<;e zGZ=a(jo>UADD9GnOUDr4&h^qZb7mae81=k2yGbYqIth#QV;iv!;&c{wuf}GLo!6g+ zYu@CIB1usPL=QRJ)~U>)WO746`6~}y8;sQfneUn8^qtxWq6a>!$16l@C`2iQNi!V4 zUL-UT)Py?coJ{X(y2Tg0JvIdKKz^k}y5NlQ#MF$*3n^aO(3q`%2ks0nr%EN?Hd|V~ zUktLnA8088VID2p4`$u@EbwLPU1m&PCOI!h%;e$?{?A$~`-jqL%hK+bQoj6{#7YoosL+JV6xN(UOjawsjkxsbBw z8ko~p1>`2M8^s1qV)xg-m&+a$YlLOdyiD!(GGf3qfnqorSs&>*z%uFXw0vki^^Ea- z(mO0=RlzJ$W)J)EM;+7fWbj~#oC=uxDsQdK{>`bDx{z^)2ivoP#x|Qj>i<+1=7QG= zv9w&48cNtwAL~(=A7{}v!6hCY-bLZk>FU2h^8x-FwsPWF((=&Z(`7aW^2}^o+%wCm@h;jS&l9y(1_}026{|`{o$Hq~n3)E+T%&bgiWd zx8AquoQRD4Ni5`cd{W-gJ~~23Y$fUaKiHsP(RHI9XVK3Rqr>;Z4Eia28jO{M(vfC? z-NZ7I@4c^*eW;?u=&cdConKC|oBsr%8C9^AnhbwCqZ^Q)RM3O-uf(SNMl@cK!h#`W&`cIql+xFgSR>Z!o zQRc30l+inE9rK91V;J5z$&hY_EyKzLdErGaeGcXnjm5s>M{|cGynH2h{*SCr5Hr1s zxu3+t@=tI5oT#sNzkvOG6?O4d%03_Xf%wLRb6Usg?eIPsd_kuf$IIPV{I5KIpQ-GR zGsaYRnDl&fY+7$2)IY};Ei5VUtxF1}LxL*n=ASjaZK?7{AHu`lk-w)nkYiq(5cz&p z-ru#Q#n2W(ytD`kfiy{`&=9fX{-XulXj=1hh}Ujqv_T(vZUc1wA+PY@$KyJ{?%a>Iu9cGm8|#j%~oJcb%M7>=VcIlu&ln?TwHDnGN9l`{T3rq!r(}nsN7TII1jc00T zV9Qw2crEU`%S^fGAUqLH-Rlb;ccEaLIS++Tktb*=5I3YV5*?2@@j|#51fDQ6)N4*X z#0-(azIoHeyfxA{+guwX(CvzJmH9~JwbHI9WMKWYsCa;JXdg_5N%wZC@vq0)prhkC^=#)FC~Dp!MtM0|$S7_}I4z)iDODxq;7?B5ri_G4Tnm*zOViB9Q#^n96Jz-jr2iG+65ytx1W;b=4 z%_~3LnXlIv+#@6pZ$-|K-%FU6Ws&dNkWh?vggKHG;r8IQ4mTN-N5cKhP9mEl+#Km} z=pFsNy{uq7o0H`@aYd$7qm&2LR`!=6g=*BqFKXs`IF_ z-UwW4R;ACCvf%4G%wyBdZxxv=odwgmV!}umebG-ipyH@FnWW>}-R+r?n^+~=C-)-i z2>L>O7nX)CveoKZFn+pn?Yora&@1UW*@-rplMG0Z!5R~GiWj&R4z{*IH(_kryOFYE)%sq! zd)0@*#d9%r+$xg#53=cq-5w^YL7uU!Mv$znMu$g>eWZp1p% zzAlHpuMlywfk9H+-P8$|rjtfoCIFTu5Qt=5s=QP`tTK+1E#61~Hri%w|6O3wlONZg z#&$Zv;%&d2!YV}ZzTrU;XrM{g=T24Wxmoyd)tbkjRBSEyMz}Gtp#39-mL;Tzk5i24 zSS@Zd>I>_g`mP*0u8-j^}-9nGXHPF38y&{_)1NRg_ZCAhI>k!tmD! z9G3XQ9>@=vKNdxgAoLj{#1HeydCD$j=xnT@JD2R6sz1SY_ZZ9{DM*NV8@<1em zSWur3F%TWkoIG`2=-c&|K6ts*Pq7qH$W)smWbiTrjv%Pr35+qIWT0`yT*~PRn-Ky@ zm|ib4%CK0q7R~_xFm_=<$mGR_qdVM6x!PFiOxjqv~_||7#QX{at9uW zTn|UtXeVqka%@Un8JKcsht$?7!`5)@^?*DOrt$jmGe5f1#ryRBK+XxVhwI(Yne`-2 zeJ3tMu_XHHebY`p4!RrCM<<_bSup$y&SBYy;$vH*eOTO4x$_NzegqWSVBv_x{;o^F zW~`1M!yWF5_I>cN#ulRlv6ajyIHB&WHRESI%EA;_zHlLfT&CmayBAwJjdKd=ZtHC~ z4mnK7Ffc%Z!R}qMD~~)_zy`4B%xhhZ-*pH+gUhBBlqTSwLW~w+1W+u9qk96AfN7A@?n(OoSaE)y+Q#SI`j=F`7oYL--uzB3x&g<^l}C)n%9llt zfo|sof-G2%^v`a@$BrzA_f;7+X>*nk9Ozm!%H!WN^eBNq(vPO z>B`0kahT2VcRE;dFYs|Lq0aAFsvGJHF$%K|;^=ITV#3Qb;LEm)JNEv?oV1pb!O4ZB zq!w8%3+QMiEIRrZz-~0*WLBMA0=xZ+|4Rg|O(9S3rl~5F2^& zAj$u#@e<^z;QpQXzN?(|*;F(fJ#JIPC+MXwe$A`}osP3@2%WTp4EAUGtf3qU2T+FC+1c48doaZre7-G1!v&*r;D038Va*0Ge51~OA{Pwr~Iz(`1d)VC0kF9zo zZS?6{p~4Xrsai894wqTSm;E(E3O3jpZ0`A7PL!zN8gbc1h@DV#hS(tvG17h{Mcbli zG5~1;8UrR8xo*Nb@^aQ>7pt7x!7xx14UJ4|<;LFa_%1O-vM4~*fOa%x0kqyKi4YO` zrlN(cXI*nQc@3B@g{K*;HG+47V}JJj*yOCd=}B8-l(8`QR|wOA_zw1HQ9p&~&qa1Rm`dQzQteQ+t3}C zgaeV_*z~>qFv%lCE%s_7<=)&w3MkqC@@HPHnu6VC6X=7D$VNTXJWSzh$q}UtEVgyG zH!kuZw@%!VgY3AWV<-%)Lq&2^fDsuiIQW7WJp7-wR_wA-=a;id3>pGT5TN9^$Lh#> zu`9CPuqL5C64V(ac6MJv;Jp#`pR+i}--V7g_C0#QpgF7(OxIXBYxK93H{_;Mv<0EK zKGfy`&SJ-~)!6+HC%;*8K=yr)87v!QFeQ!p3oQajntm0T7(kHKNNo5K^ElMC4`M9j zoh@fot!Ga`1;|g5VbMs03HLxm$1eZGjh>-6>)H;xsNWke5cI{#D}@9+u_Vqf8-lt5 z$&CX(5N2{1N#KE?LzhSpMZ9L2;R%!yA@ja}J5WBJisKCsbe!62FC`@aH-8{lei z{Zo>92eDk^y62!{NnCY<;LI^V!-J~wz0C3SFfixGYK;VoU z3=ihC3DwV)eJkQFBLzVo*yBR5^>`-y)O}^APoK!WfM|mj+Bh29p8m8qo_Pl#YeppZ z9~Tm)hstny*uZ#M8G4*5qCq2y_T0`naNy2;F&9aJ(|f&SezKc-SYFZ@y#X+pndpvo z?PsyEw0m3e^=S2vmSV9X5*g&rfEx*o@07exj$y{&mR-9A(HZFFRX0-f?Q55_4!-yZno%)PWLiK-#W`h{&-_Wp#pFx-qm9iKh6GIC~20~3hLcsGn?<1eYHqglXgBZv(P!=E&)U%V$=yqve@_{0lk zXtyw9t2j?^XARGMn!%rC34vDwc=|J__DP`ei9SrE?5f3oKlFD|6W~_=1H;n zt=^Gr0A0{ywK4lvIug`ic#U~GsMHb$JQU_+wcop*N^zYO8(@(`L!7PytZj&-RgiHkuHw( zMxpF{k8iiKALK_^D1tVdmcjyX{>qiUW=9k)&=!f3MhLf|o)pbRzQ0S2;~G7QXm{XofrUWuf1S( z)>^>G2n;FBMbc0oheVTLt~_xJNRt}n!v>p70U{1}jldllJ@;jSB)D2Yf^ejTQ3tN* zB5E*4bAkujcx@^kI79dNm*n#F9~tg3+F(2(d~N6Du}n)BZzKjxNapXx@b0E)n|y*C zj5klQlsMAA91ynn=!Y~M5G^&75c2? zO}cp8PD%2S?>D&QVh3-CS9-gv2X5%WY%s^KOg<;1I5u=Pc3|f04d3|?Fn8zJPIrS` z{*w=5hkXgrg5co^AQH(0kGC%N!403g{yNoVOh|KrQzhlv7TN1eka7-(&wn_NoSmq4 zag0&HCT~9xnaP&&Ie1coIUk_K8N($4ZTr}@q*zWV2TwGl)x7MH_ zNRecX?Ycg6o^&DpieQdJ=5DE)aw|(Nqmiv0W8oFatSx}7!HRIR5yY|kZ`~K(;bt^! z#An`cGCj?Pbeinelu*~b4q4<&FdkpKRb!6SRyoufkag~5hs#4K8Y-#2y}3n7GhW;8>d9U6k2RP`4&@oR%MGLRw+oo(E5a_aYOE-`WIa!BWK^=F#Rj#ZyRIIIvJ_aRt*UL@a3 z(ylp_FpwHZk{s{p{*mX9wYTZxvbOTgQYFemcX9?sqI=RfFZi}$P49QCyo+dX>4<59 za^wO6MjMBZIj`20gQVY06U2?{1TcrwpM_M3b(;ie` z;!Y|*sc<9e!JM-J2pbLF(CFn_C7HRGbk5QVXq3WWl5BCy2w7))3WQ**5{yT0RhxfYyn+cFlQF@yT%;b-ixDho9h9Gk2Kt*}nQ-gT^`B%q#ozrF7#2}_z z7=|8Fq)ggv5+WwSm(I|^)nwY8%?#;do)#ka4X7BXb5Kg)nRe$<>x*M4T7 z^!1#}(epOqDFd7LqzETcrVVi!>IS0^0!dT`$em7GJ1>W)mXh6$zm8!&t@i+Y9Gq}y zu57fo2zTE$F0kMBz1&>QpCX4Lh4hApNrAo8Vl)gv!HnnKR$X~4?v&!>oQWGDMzE3B zy*pN|LJOZts9vaV(j2KnBy&_DzrFFYxQRx!X7vr!wGCHNOxi zgrj(To6UcwSJV-%^QpsdbOH}$*o<2p&nH&6RL*yYpDT4chXC-%IfEo8@mYkUMVp62 zj}MF>M?+z-Nqg|Vxz#bLvj^3y_X!PC9h!IXA{fKJBK_|0#_YpiL@Pmb=3Zy>Iq-#B z*;(RBTf=aoWh1p$s6jIG12VHdBaVN@ap%?E@PmisaOgP&d!2I*RP!q5qgY2VRaa!1 zgaH4cg@|3$4Sb21N7qOQH9lYT8Mjh#8O*pcSJm%A)C%rah6Y) zDLCpVjZn(BGhh%&0FhEhQQjnA-J}?D21Xf~(A}RHm(F;boIR~BPAvq4y$U}KE7iXl zS+0?RkIclL0b$W%`*afdrhJU74+iLx0OYk7E$5+!cV0*(5%n7og_kf`gkCg{Qq6CP zX=7ZUjMdqC)f-T&1;6()`38vLuS+5nNyfLyyu7--#6}DN+ojprV8V!7$wZMBjnVCW z7J{n;*5N7YZijvKCF=8Z86bxqqTdKKMn%9CB?t!8g0l-qRuoopQTb^-%Oc?i(t8K| zvJuV~zi#aM^W|}qlK;;WphrDnDC;$saf&P;*$vpTpn+$DL!V{5l7X_2uFCGGQ^%Vq z-63s9=k#KqLy&%SFKTE`UzvjOhzaj@P;D+K`P7oj( zr)kfz{+pXy&CXk+Z>?wQRAPx!$%q##PoEi1rEo*_0B!(_<^&7%LI5~C9Y3y0_LW`e?Qh3V8`f~N|#}B$bt{ZqKoLAG2Se?|zS_yd6 zUsFZI0abqfXB!A&;Z4jKWdS*Ir22c}pbF>4G;A-tbQ1#b*JvUU;C;@?svyfS(-ShB zk6i!0>SpWC&5QjLI0&*8{q*-Z+#X&EXqI6lOy;Ig^w*r`&6S*)hiwv@UuU{=>R8a$ zmdKJzNr#E7+1?x8|KW@0JFNX&A$wJYikeB#Qhg)M+=E3hm?GN(Jj!5g2Rn5>lX&L~ zSQw^*E*FdP_qcUt2Dq2gN&)H-_Jk|rbuvwvHRkZSE57%KyfAjQRW_N?zk%`Jox`aJa0r@sVMl4JVd-)eMinz$sbf9 z>I!S};4o+BTg!u+Q`J+}SxvTzISQvh9!RBmMps{3nD0}Cz;{%HCk3BzL2(ath z!#;m@dTu0O)5ea0Ad+=y=#Ns#q8hKBISp*=%_#IUQrY3Iomf`oL+Pubc{diEd#<+# z)#cEhml~HzjggG4_YMsy_e5&3dlWkkhoKxX1b}8S81;^w;%;^z5)p)KiAD{V#q+~& z7edf}aoz%wY7&Rz8)}@P%lX$Ov1&Fmc+L+rhIJDU4QL(jIeeMi!_PU#{=Z$YJNwX& z?fZDV-roFZTXsf&u-TU1vHe|-vw70;(HH38A}<4}vF5r+weHZX&%XTNI1vL}+T3Rv z46~3SZ$An@mM}UTjvtPT^6oBbf~gCAZ&#Ga&Yx3s)bSXaz|r95(5&07k({3uJ80*ah9al#}yp&&D>>GjD8D(KpVXKXCOgFIosqO{HC)Q$0|&Plp*VJsGj^x zX-Lo=V^ulkgsq93u=HnQZ>=m^-I5G(WJrG}9x{Irzo`mN5p~}YQ`I};jE5Z-Zexht z-Ll>A?Y*JYzIm@+BQ>hfr^F1zjd3CQ3vq#*<7vt0|CzY{SWkJUZvgBW2Xj`{`w+0@ zAXp%laT%e(V7i!ui6o32B>4vlPEAjGgY;mBBV$(qBm%s=$4#;Yr+zp~+_6QEXf)bw z5GN3v1Zct!FLegIgYy9gN0_Rw@3!7`!VGz@cU9>RB-7$MYVK*EH798`H4+Bf7EuKB zq&dT-Tk1tIL5(3nHI(*L6MGO z<2&`nF6er`2bq2sYHlP#Kn``)XFdhiCB~A6WC;W!k%BZjh~}w@5QGgVoXkL7u-$|q z0l|_xB0wOMyAO;{gpXi5s`2>L|5jPZ=?zR0c91Mi$Rr?9LQp$GNDub*;1EonNw@m- z=uhtc&)xhr$!&F(%#EpW6sSCMlw6=3$GJ8>yK4~52{IylWym5=#IV*C%K#HT2EA^` z;>5kJJA6J+KM1|)43Dta(@VR^>7uK zPi=yKD<#x@UzaJG6ocEL8l-Bli!=zh*lTE5AbdgZG7gFdc-f)8Tqj7Z9XsB})Ni4pr%Z@ktUB8jkEEfmR@v@-(WF{XIyjN7m$4ke!=ZjuSGOJ$Nieh$T zyAhhHaJJ$~B^8bx@kD2993(*_C4my0X%+B4VPSnHpiiBFfgb&b?)Vmfyxs#}cQRxO zeTaf|aBb%?heJJP)JH9&}we|1F}no7(SJi+IIL-~C4Q1QOD zRwTR3J_`BE4Q`t7TRhq#NH1A0(0OQh@V0aIBL=zc>pE@oPTXltIz<0NVT-(hC`v!K zO~vX@NSFI=09{$MGu)fdV2sf=o}GOC-|2`HNeC}J8q91=U6FaT{1rr9#~OTMVsTb) z_S1`p{SYDGAm@vD>&mUpEyM?>uasRGK+7H!TP;4Hr&y%KN*E%hu4ZB29OpQpDqLI4 zV|OwL)-exLAeD$RLBJD_W!R&P|9h(8@OF4PA0Z|;hI#i8&`D-QR+}bKK)N0p0Vl_@ zgDmJc_FDG0&V0BfnHdGJLj(Z?imD9It0IFmr_FxbQ_gL~N3FklZ2v6Gm@Og7j3Ks~ z!pNA#ktTY=y!s}*s-O0Mfi(^WiiikjIemUOO&WB_Uh(MA|-*Ju1%LEl;ri>8`f(M#k zvABocZH32-5T3Xu&1hOoGSPZ$MbDzci`7p;0VMA!%ZMCdsFuEY^HnA4#EVZ*v&;=u zWv~0GLqO?4kI-lK8FCK1+xPG(3$~v5_fDS$^--*;1dq2yp`d=2-_A2nls zzW5MG@WKti3rns75orkkaK`6?h)hAia=?+v)Ab7cgI{=<< zP+8`d`2$j)Ghy&B3MyZq_bh?`HEfJ+p`a?c&A>o57h^7TsI zRhYqTT?-gON<|`#eV9ntJX)GF#tcI-$UYqwIEU$?MG^`{1WZ2;6=Nd&vAao*DU~az z7?^STG$tXf3}#k>D1!+AkU_5#*A~&>3Fjmuv zB89(*O-rh+0&P`TJ|xW*We3epIOzL|MfKuigdlSI*YUC}pfjYsUxLRr{62h);6U@^ z@y~Mbj2BF?BJ}eT7JqkB1cu_YPGgcX4fobDEKg+|JxI5q?zT@~supCwXW^9qf<%x) zaGffsOk9sXh(*;P#C0$Ta(0h^sdhG4hytAe>xW;r-#5OHQ+Ai0z71>g4}eXMd3AUY zVaF+)G#-%tl)&?Ue73pJI%EaknK^Bi-iSUo?@5w)I(S7~Kr_NWL^HFp3rk1^K~%Y= zWs|;&Wf1}9E*5x26NLf>BS@dYMuWY)fk9}rc$%W_3x*;~C6-v9>Z*Avc6XVRgJr2E zNT}qiJQ)=#VH{F$2_~m&B1tP(5IRQgGm@;dF|ficxAdrJ>Lh3r!|>Bnaete>q&wql zkEAn`M@A$0C>#PKx!Sut%nd{W@vnQq6zr>3XpihjIZt}FQ2!t2>Fup%nIJQXIz_&S zU=U&o!X=TzC<1qEk7B2CNl=BE-#-3q1@enX`F zKfhmCSH$zeiuH;fq3h!h5Gq3tP-O2r7ouIs(!@2PzGL3XgiK9wgko_5-e`!T2&S}I z<5W+cwDYy+aqHo%NRVeItePOZTENoRCMcXb>zXTI<4-(X+Lkx;=QT>~S_iZOHxVG{ z@Mz00VxTOtO<`#UVY5%6=@0}8n5Lu7KubNTNSNTNa|5mBN1Y{lw)XZ zP|XG&rkS>dq(u-2BM@m4dezG^AWn8I?-YOlwh|lC8)03dFwoxc&FU})0Cd?X`j{c? zts05E=?fzWxVgY30k)=%8Z^I_o}v@?`A^QeaG|dUw}%q=cV|SE=ITU)N-M|C#mg-VGFU(Uxs&=wM0T6Ctub+xmL zMrKS5isd#T09k{k+Jj5_ik3eT+@SLe$g0R7m#%Bf{B0E<>L3wBwB2OK zw!`nV<2=&o+v@b>6Pp)*Z*=@}7ddc4-e70GvbrD;Mjbl`Ow|B=Knt@0^1+ps87?0(Vmnj0?xN;0xb8fPJKkI=xl1t01Kpu$_T|TaKBoaRM~1v0Fsoxag6ggBZ+8 zn)G5X3j~VX=V;Pq=FnSJ}Qps<63B&UNI+_J*EsiRykl zv2HLS62!4E0NHasTzq1tGItr7X~7!#q+fn%JY`h(_QQUNb?XMpT$RN$Ec*n7*|$KE z4OtQK-QAEOS7D1)**d?dFw9m)h$HCZBs?b^aon=38d+d}J6@q>JOn6OObW@V;LEJN~`+bLAT>#Z&FOq7olvhKT_WwvSP#u|}jp zl+gPk4?6zMTeLe!84%e&aDv3Nc1p$(@wNd9ytwvp%@Kf|)WWg_8a`+sMT28d*j6O7 zp#hNu7N=1Hf4}-}|5iA5jC(&P#Hc3bX~zSTe5g4vsu|lIDjzhYd3l5`HJHC8Si)OX z{46nWGo^udL5Ljjk}%6{68d4+d|Sk}hHLg?MglCON9?U^yeKrFMgW=svrMHATDzf! zJDE=1tMs8~iD&fx%~ZtV=x)kl!ZIX<-@{;tNwS&AJf8dGmEfz=Uz8hXKJ5u+0G_5if zBrcdpgi}A6zDfePbPGOQ&j8FPtGJO36pXt&7c7->Gc41V9g=%xV^}R(;$i|~M`U3U zq27KSV8XgPBo2WK)qtLd$9~wi*tkavcT!c?L&aUiAemUau&3L~EYw+`yRe0t1lG|ls?!Uy1a-S%PK54%3qnn}Vf)p-SdIvdW7fFV zMn7@Kl^W2Pc=B{C=0pQ#Lx@!sk1EXItc%GXypCWYD-IBUv(jKs;>x3ew76tQFp&cI zjxd@aC$O389cMe7oM}CMJm%VISTAU4!-{&SI|O8Ss=+|Z5FCNVe?QyI8LwIDJ^o4_ zXo?_Eh{SIJ+Mf>>>D^=BI>+-pnBgvQ7tv|z!HU4~-zRRal@bXAj&Xr&QtX~Li0Fgo zHGzOl2Po-aihehCD1w1aZsSgll9o9Fn&TemU}TNEVhs?P0WH4_7#&bBNUbX^W)9~) z5F|v7s$}xRO`_bmof?i!xT4N>d70)jFH}YC4o=RILTgU(KYqraTN-}#%RME>f{CU? zCvEK;+!!}g2_NkHBLgKF-0zw>RKz5lwydb*x6q~89y`J_e81;Ffyc>JV>-yw~Zp zBn4vH0X}EQf3Mvic4V-4P7CC)a6TFzNP^NXQ$!m(9Yen_dXV68y$2zTTVa$FYfFtZ zLO<;(eE(qq&5!airV1TX_r^K+UZNGDd_FxjiL8&8?}!?%xh)ZZhw$Cu07%za(%dxr#$oQL%xA6loR zNzNh%k2y{}nA5l!#xCZk^4*CfL&PV>B9Y&kM|C025VM(B-GKi*Uk7|dem+NjTxP5E zpO*vRBKi1giKPfs(p=lIv2>}pIE|1Il7VZCR2`7JHgtAegQyM!Y8>#K5xPT+EmT}w zD*%#Nwi)5@5a^T93!LN#*9fCUTGAS~6lCCkWCdt}&bxae_@7#JlyrUA&Q2QSVT#YB z_S(~_wS)KBPuU??&v8)%^<8hsIhgt<&V#dPp;S9Nh;|i+2t*Q6G84vPw76@>dg^=J zM{hoM?W1!mQM_1$&NLZ7-4VruBB}u@C2k}jHvnvgMtP1!T_g)aZo*2DaN-~PZs2z?GJ-O5gycx}(r^wvv&2X&UY*IaKkNHvXU=v6 zOJ~CII8A|I(4s?P7}`g;A*3GeD3D$sPui zL3Q{*UkO8kLGdZjFZXwFqB#R$`TjxI`2XLZ@4>G~*#pqh`+@f@pi1P29H~wyfl}&> z5mW67>DlPVTt}hR<6g16Y?IFkALqvo&_^igCVJmaK#}W9Q^fFRA_LhP)=3mtB4#iL zt+k7YFz6tCO*ll0FU1HU4rv33n%Ff6{hF&Z68-l!C-UPXC26&-C;pB)V;9r%9DO{~ zIPO)I#(Wjt)Mp|ScZFsP(em_Odz?rlSVb+`!;Co)(36LW6~Y5$5FrFbFY8RK?;4O{ zAMz-Y0CC^r%tXAB0!Sxy+!&68c-B9)E><622e-MnsNoU2H-(Yydys#~vL%}&Y{^6o zWioWY!KeL;*Gl}H!vVn#KrX*5_jJYc#l(AU59;&reD5P$=7;V>A+7!-*8Ezr0Uvw_ z2u2z=2Hj^_Sf_$LuFh|7e~M&Qim;>Kj88nY z!QYUeedRpBT{|dApEAN;)-6Jl^zhEul4L5=X>#iBS#i|kXwZ9pS;Wkg^Ka3oEh~J6h zH9=FkAd%|Gj_(M7B!E~S9G3p)?*6Y%NY;yjlJxZFx~Kiem%=P_?Q?w5qD$!ubMI(2 zm;)}lmTJU}g3ambE&e0Vo@qiIzAIl}#dQa{-;&9}!NtkB&snIWZa;nNY}WnEJnI)j z5=k_`ki>#m5C*{nq2))?eAI4v4;}3%%wJw2CHz1h#bY-T{PO|!)anQ5^8#%PbOaA8 z$sHaI7VPl_rs0qNiq4$a%c9MkEq}RYO3A?)!-sN4iUf-xe7>AKaBx8)%Q+6c z@eE1vl|88(7G~&joKybQi=jmuaByN82+gy(6&r~>a%I?A$GHh4;2dhx`eitD7m^S* ziVvuF3GoHhq(gFKUS9R%0T=oWzhhX9M=O^akRFC8j^><8I~@dh+%}3Mk_GK9B{lP> zPz|L15hP&(3;5(HBYN&mt=Hp1OHNPo?${&jjUP%8G_1!-pT~;1-C5b}qetuRpIu;} z|2h?^QTNO~*)(^<_IIMC4zm9%bIg@fZ&`Anb1%+6Z^xNGWT>_@vni!0LoR`Wi4qAS zU2dEZSe zFZF8?g2piQsVnw{yJECMW7GO#ksw%Zwc%r!ZN zc?*FogceDPC=f|4Z73DoOud0_*NC%WOY6oSm60Z)75qFP=_=z6*oW0{?!61_5+4O8) zXdYJcXO-#TP-JA1zyd@c%((;^UnRe)@Y?jZmf@|uxluzU5CxoatMsAR$&O|1YtAY| zUGt2_Eedsr3p%l72>)a|{AXZJ``?!VK1iTYbJ+HDL7ry+CiIvs?&iqChz}7i&_h>8P46jaQMR|iXw=Dg|u_mp%&;|3qV^u7(x`va4DKjjD$u` zN;4%3rR+g1L-8v)_0kWO z^&cKe_KK}YS1sx9_|$Ld>8*Hu`}2`P>w-RK0t@qGgUUzWY_T8OVW^1%KOe>Y9Atzw zjPiZ06Vyv|IY0{K+%$r;H+4Csz?qy~s|Q0ir|N;BQeS5lB=ef72NgI;Aw<lHnx4 zp-=fzrm1B{sv~WPBVG4SUcMl(X!Ey$+Y*vegl>b88;)7ct&w^CD1OTxkI>}s@z_Ju z3Nn4mEEEz%A2;^XNQG- zX>xhV4-VkqZ7;U5!l*q*^O>wT{soC}ogy59&1D!Y2?T%<1Kvgip!74=KKHHroQ5s^AjWmJv^U|8wxT%pV6|U}4P<=gov>As&@dD0#I6S33{gU% zN6VqA>tG{!pGT8=(r}CegF)(30MHQ`p%6HfK_UjCd6T!_Z~8N=1Bs*bECMIW2z{tw z%p%KZzNGxJiCbvxZa)9J@$=Kf{dGE+Fc%KHzg!Ooj~s_?d5(P#SclK26N+}IIz9g% z3E=qf-soK0c(4MJfZ&R$$#ubK=?EN@B|Z=!&Eu(zK;H3YiN#}64{g0L-0KCruPIIJ(ZpD|q5Dt^@4e!_-AgPw$nT-Erq6 z-`2OJ#(8{^8TcWR;A&YANT~<~lt^*I0!)a6A1UgGeaK>bkcr4hfaMW(oPsE|-=O+< zXEYOQG9MDow$h5lggPuTg5y}0A-*8%)x-%;{ODoU{ufZTuAhi?eB#ix=|SK0moZ7u z6td#MJzZsoKp-S-i(rAQ>Tl4BoLvi^{8(^J4d*8au4QxGXCR6x?7~7k?4VD&7Ygx* z0Tz&oVkdkN#c{?pO?d=u?{SoHIpE?ckA!=1hu=!4nRjwIAd*5n(#1`KeMAWA;j*nK z3u;7)>h)EgF&eT7ptfzq?-4BWgxbMibexTlNX_8H5)L5#tx4l7IIc(;8mC&U$D-)e z;WOb|>~-54yh`4|X}zae0Re6>ELwyFt*2KJ1ukBv%)&7~g?Jt7yO*)c#ol05S>u`B z2H!bsR%M=q(BV;HV4YsFnmDXloJx7ylJsvo+~YhyoTvB}t zW9`2}2_zF5)xh>5CdI0Cg2QIj@d=%O<^ zMb7LfwrD#V_dZLZntidWs9{HD*)V9J<(_ZIJ9RFwlQ?>wDzQ=hj@bB|n?{$b*!cl{(1X zAbfee1=fzTxsxdC=JMmNP`-Tzggvbm8;)Y01fNJz4JPM7)Oc^|=?Q(1rw+Q? zfw!4;7{cQ#oMs0zcfCR;FYJqo#pkO5a0~So0qx!Cg{0X?;@?p+(NWWEfdD$0Lv_^E zrILHNjM8a3TvbuQTcLM#aQ)$NVPW$RvN1{p*5)u!qrY@MP?LEY%$;E#2#i~oGfNXY zPZJ>H6hS9P9AH{BF!Iw?Of^5Aa4s`gSviaraaK6(P>lTtKsv3UmF)1r+tY-lizbC85g61A-f>C%Vq?|R5Ud+W z+F=mBX9AGf8n1OWp6KM^z^T%5h*CrKXcw!)(io3Pd?AuIeD@mF=ZsZc1D*gXMHWO0 z*d5x>sJkKVW_fYBM3D(UCgD^^l1g4Y#x5Ln(il^mNMFXpMqOZ7ryD7%%GlhkaeefU5cY5mN2x0jAb)$r38$nZ5?m~5l z1AbpWK4i{a+t{)R8Y}FeNvug){u+h*a6S4DPlo-EcC74s2L``=?Sesyme+qb`@p@v zPqP|4$C=cOvhSzyxA80y5(xWggQurFZC0na`R_f@#)g_`Zx%V?-}vK;N5@c2Ero+* zbRUu0U!MFm?7c0asZR-ecM~$_4QY4k(!KQE~DHx|N1t9{?TLw@fzcjpG0R0-rkkWX6MaF8W= zEYr1`|8sves|k!`r|2uK{J;E2R=iQCpST5))P79>q1C}j>a zr>^dwGFL6Aaiq`?dY*5Y3SGtZmg|nTI?^2LRjthKio~I6x}5RNEV^;FLtYofRJb_T zWG>q$Vs`prY9Kt!V!`Ii+K;{6+O4InB5Rg~@e+(mZCdy{PdSLE$G=CdL@!5uyT3P~ zx9@vw3};Ab!I#E&*AqvaTxDtc-OB4zJk{)ZxPIkfV(AssMsK;qAtmwNY4tSfl?)>f zHe{G;$ea(TDU6zj)$nNOB{jY9VK*65t9gYej#ZIB?`i9mBZ+eAZY&ydrCd>&{Po1> zfz_d@)YQwV8(1x(2K2J8#^gXOTMPzkWJ7p+wk4#G1=1TFP~^`zu}<2|<2<+Fe`l*b z6IqL>bp?y39E>MMx^tvD+$8Etm0)lCF^(FCb58wffoGvSZ>Yf8h_T7lgO_^}SPf|D zq~cSOGaSyMds`yG)Vbx3G4C#VyL#j8qkVM5vBkeUJbf$I7YyAzoe`Uwj2N^PZ#l;8 zHA*^Bq)>&Ii71!jRhyw(x5iKtfN4Im;>+$e#Ld-R(w7!nOTrn>zM$;Yo?k_#+y}Ib zBjXH>5Il;K`Fx~($;_P&J{+BdE#B;2joA_5Mz1&I);VI!*&q@xH;>(Jjk+0RmTYnj_~n1J?~B$e1s zAc!(K5Tt^njP^JmqcX*mX%5XJM2jOw1)qfy=LAD*RPn5=7fUoJ3-reE{AU5k!O9TM zptkJf4J1yIA}IjL#4|k3K|0=qI`Lui zMQZ{m(H=Kg(IJI2!abeeF_Qb%y?*dcg4qvt7VRI2 z!-}Nfv}+C>unJ*}1SK#ALX+4luK3;Kf!$s2HOJ6(iUY7FGw=3&)8 z8`n>M{p9Y(cKl;I6VErI5XSR1=4?7+qBftYPkYenbH2U7*G-KisB&A;7{tKfM0`1> z!zO9jJ9)ci^?qgncaJoE+um2}6Io%3Df{8$jt1eZ;pxB=mf%W_M!jLX7qnPvx`D#y zjl>LAxWR<%Wsf*7bX*A)w>rD3B6YznXN)+lRvnKo?#2c1H)R@H{qx6;>0~9aUxIN!f6f^>1^;3xg8QdBo3!G7S2x`yilIGou2Qfr@GYO z&x-01fs8p&-Bmk0uJ)cEi{}OMhCa&Jxm`UuZS&f11+$KnUMc!_uJ@OZwPy2|gG81d z2=gim%3$PCX)a|iBzQBC)1_y5ja22Gr&U)Rj2d`;Gd2jQJQJk@#~8wdJ46i~&lEYb zoU|9$6d<;#@2R+Lz34bgQGz>1e6c;#H{Y5rx*I`wHwowwL_YDx#OS^i*BFX3X_7_| z{ilNjQEd`#=d}%`#v#oLa8I$$R|TA2L$dm{y^6c*8s!a_GUl?`oiyoN7%X&iAvxzE z0ekQvUp{8|BZ3jHDmdPSgmFb6mkmf_=uwWsYIKeB)=bW~3@ITSbhzoU;TC)-aJN3< z&_ozUki)kwDi$qZfxy5Q!W4y8UW_@6 z$r_$P4SGN#!5Ez9d@3Apjja*D?=e|gs9rSx?y1)E*0V5d3d~m%5CKRTUy0Febf_Bi z*J9N}u?zcsdKNr|P3^Iln^WwIjxA^5-f}$WFNCWR)B(*^LNyZoPM%Sh8cPI0Ezw!H z!!xG`-i+(^>z?BVgl|FhwRa==KL5X~=LpO=2SM@?4Wa@dW;4Wq&_p8E zVaE=R*eqaDw*9=Cyc#us7mz}p_|lIvhaV&cGz9RUDVT!WA`Zc^cHBC}uFEJ^k_2tg zLF@4od@5pOy8^q(1+4C&|=(BVMLX9 ze}}vrwe^dv(Sv2W1PTie-+cI&&Wqa>g6NelFkd@qcwlh0MRtVECj-G?GZ}C(7WOFw z-17IX1AxO>L_(TUlVC8=I$TSg*nQzQAsH##iy<4!=|6?f9T6jZ(LZEM_0Jp_Bc1UI z1RQaF^CNsXd@L6Q%kA}xp^Ry=6x;#}h4mG^vKmxRZ`Z?_?h@~!9kck+l_24B1eZ&9P5tN4OTfZ+&)R_dY0kjxT4ab&^1bT?fmck9nD9^JG;5I#S`Mov}`iYfdHEK zr9)uC1Y^;JbDYri@QWuGmhwB z@SjL(Q|5C62A>>bbf_Etc;lN+y4>gygpB5AYbK=8H4X_hWbPn{=>`^CBooss#tU&z ztTWiS?5XE|`)jGn@huzwOwfI{bh;W-E0@Fe zT6#we{8Jxv|(q!GiEa+pSSi7|jiE-z_5f%GC~pDrC3ZEr?3 zx*Qyf2__mW<%wm&Q?%fTph_jMbFDqTHfIp~nC+^vzHu?prJz7m0R&eKQX-2{WLX>d z;y{DmL%Ll$Bu{h3#H3W1;R^(O$Ov!@WM4h**w~*0l&3GjvcNf#tqw2|eN0+Hl)1Z| zi<%!DW4w2@4&vcS458jli$cq%ND3YFtMhfIejy}amNf6DJnK8%Tu0)kMvWd9vGnh1 zuJv#ZaK_Z<(6&5-h{MEBLW4lH%1SBBXhyTDapZ*g~sOS!W6DL zMuG%A38$Uc`*74n_~;`_Mz!JqezNURB_9R4yx~VjHTyS-7$DvpVf+=T$2?6^LQxDwSYb3Z25XM56LvWkG%DXRv|Yg>|D)A%TYx1#x`*bQ zqhxYe1p#b}DW+LNN~O0@iv(SvRvNn~4A}@lV6T^NSp7TN2w-{h&RmV0dUL-_ZtSrh zop-kJ)!Sg;1;g7Zv(>!PO*J{LX=E&?gOk|k;LtrXrVjOp-nb>7Nabn@VCRfYi3gN% z`l5DteH!7fgoa{LAkrlEz^weL*!2wY0jI*{QEt}Vbm?w!l(H)r%p+07#T&IuOj2)? zpdi^pi3l+k3zKwSV|Dh24hydh3TFgQ!nHnbut;4HogxrNw6s=EE!cK&C>Ee)f)Mmv zx>Q=QaPzGM&*|Iuh9!ptD#@7{FxsGsG&u)(P0k$`I^1^p=wLoiJm+n2o01=VlSiBf zuOZ#EVA$u+81rOa5)LlN>y~ecsYY4NZEGDnB6kQg+U8;Z1nliSyb|SZPrs>(n%kN2 zDXC|i{nu77sQAFr?#b|K(5ouEJ2(iK?DdP?5sy7vFFIi5`8Ep&`K=9_BzuJoh_poY z2ZveR?zX*mrQx*qtdnnpTvJ|`?=9*1o@+TCX!nNAzWHq-fFnaVxs{^GkZBA)$jvR5 z+W%%No)4!&T#}GLOiE*$<=E?ZH4^yPB41jLqtKoH%GNZ;Tb4YLx+O+YIh| z%blH<21_aptY&LS3)mo5-kb=627n-#_YQTUd7R$H?fSlRJYQO%oA#l;C+Nio`P279 z9-;qhcAi=_;<3gO__`Gm|*6TQo z<8l%Sl$x7Lp&BudUDXV&7w}eP!oVQ!jr(66caYfZadddDyXFCux$VSuxjf$r;kC3h zs?Q+mHnq+waw{!wjS+)^6S$GA(1Loc>UcG(<>6IFHO_O9T!bHnO`FZOx~UnF!EKNv zhT{&+MhGl83J8BwVcKO47Lzl2xuKbT8{#OEODbc{i^(;FGIiYIVfyc!mKU845|VK5 zUJN@f%aLS2Yan)9w9X(7@y|;$lVoU$xYV8!yzLCP9tTCL)9)0WLlK%XlnuDYQ&wQSqGJvgF^gU^#NxdqMS@Vy_~U^hHHdO^ zx!e&waGdZ`i4f>xkhXc}Sd8q~I^u_+<@7I7aJRk0P9v<;&ngPi$;t!_jjFOn@|`pX z-Ad(;emOlneGd-@H!FF9Yu2YTOlNZU?^~2p!#W+WeVI4vWp}#vJlq3a3qH?4*x{

IwJL0-Qxq5jK3XEWgS^SNWy}BO*>1=>}wAIj}_lBg56|eK-5l; zb}phx(<<*QFC3g#jP<6^-CRUw4skKQ;e@#PS1-YQ*Au`~}?z??x4nx)TQzf4>Rz|TYp*3)q$9TIt+LMalW8*bOt>hCNtqcS4zQY8yFhhhg~nA_bF5|}^qhk`_VMX( zVH)PdvVZkJ(!e`<@&3<6={B7-B&27(%K}8P2QrixckZd6U@FcdzDIbmiv&L#)b*K*d{MKG z`sU}T#<4X7KF;rtEToKEKMa-NUhQrt6Cmf1Nd1~~z9t8?U|+A94)s?qRf3gj>M~<} zFC+&bA++?6jJhC`G%j=qNN~e69=d*785Kz!F3vTJb@e{*fX!euVoG&@RY;N^X6f0* zP^nTIbgnE*#~&C8W^kKH=s7LL7hwF zu_0%t)TMpCYb?1MK=rr8O1l?_#NZV(iXxU5oGL9&t3_gE7bK+Rx{#PJ&j{>y-tS>aP?#xwCRO3otCPA7L!1T zLk9;K{lJYiy!WU)9dm7Xg2<))f|Y zs98fjD77V@3D#UFoplnx@x@i{u}qxYjI&`fFQ>*cS!_qbS^BvZnv(Y|-i50kDn zV;y`;_`ZKnpk3?gGI*5)_BP}Hk5;#t= zsgg+moRE!1=P{meGL&FvS;=xldDFz?d-dRDWPNvd-W8tf4_Pydkc^gb21qwnGQXj| zXP5QlRJW=As{Z-ZepdFN)}fX% z0;TomaZ?tv6N8r`US)cFd%eGRgFo*SJ>e^IBmF&U+PVMT{^^h;oq5}a+e!zXt$&_y z8pqS$rXTMTz8l7|t{m_uBPGpD&#d~tdBdsqde=Xr{gU8(s;GRPK`JNH`2KccU;DEk z>;qq_>^`VCAK1Ph+M25W+m|5y(#!ll%t8L{eSf}x)tesGKjj|^&~^KIxIeS?Jso}N zwb&#;c5xtxGGW#c2<65ldsJp#zhO28s%FMOl3^4Q?QFTHxQad8GyL9pCGdolDku*a z<;6{$f>Y$nvtDc2TY3x*4MGHCLoGYAIGo;4$#YhnuhhF<1htV`z_O(~3oJ<17REP# zxunB$n|S9MUr@7G#^WCb;TgiEu?zs;qdB?O@pkxXSI*t zx1?gZo^`#d$vK&F7ENxMWI}ub^pu!E1M@Q`xp#y|^uEp@8A$k3{N?$lYhJMuI~+N7 zRweIzW$a4EF*_l;q%0=RF=2lS5elTh)Cvw-~{4d1UJmi@iX z2_BOuj?ZLj?Vc@WF*6aFGo10wO#8VSoYD!<;>7@GQY^&o9Fr0-qlt#gCHVpf#Dmiu z_!gnv{5@p8rgJJ&KrSBW)?UA#b_Tv&_ z_QvBz9!$3W=y&Gp_2#tOdhS-C-a#WVo)BMGjAcs!n15_kXboa8AUweEcsdWoiZemf zp~=A+3cx_*wYA{{8mNDaMARhbafUEx*W0~~^LKj%k4oXY{x9LqTRdLGy1O7*v&d9W zL5&E`j$$QgZO@F1bCqE(xH@t@_f{v~QRL_1E?nnSwS*6pMo$hV?k$hYP+ry>w{!28 z3|920U;7d8PXAyBPmWXhr$k8!De{s?uf?op9W^jq}Qv8c2Mph>R{(`?XgGybX0fVShr{Xc1*#pZSvQHZTLNI6R-Q>RawPrr;{ZS|08$J-;sIt*;z1f4Ox=;2ok9pdVhi|m z9AVwLH2OpQv*x(=#wjd$?U08bYsAiP;ASg-z3%#+GkOm`Jp1oky;#0Z zv6tr+j243O?;r-Z#t1E28wu-OH0dCDiwksgAtZ}N6bxjI5Uh)BGi97MpR@cT=a~kP z*!4VYpfN_coXZbxQf(L6%kpyu0sHmuC%;TS`Zx|bK@pDyX0aSd;xsN0FrjfQ zPCx=(9r`2eXz5I@jWYI5$luScXExF2#2FT;B~kVm9J8ZH*PUF|(*w7`po+q}feEOO z1yb%ptS2;BNs|SENRT)!1!pg^(`XdLsnF6VFEcQi&VdemkoZ8&?g81G3kbtQqvweY z8*~~u)S_ycC%|7Qtt${15+iqr5uHeZA2(?ghdf#jtt3s=H5+h6J=yEeyNy z*0nWh-L0t=J`hGVYG%U)hrNa~yaKprEpYE&YW+WdMt(Cq$!(Lw3?9C>%PK1nSEDz! zX^gu3%gB*k^Xrlpxv06dqG!Bpxl%zNlg^-Ol&)Y)i6O!VCwvhk4k|}-CE^eE<2twG z*Tl!WZ%2Wg_nirg5$T_Mok88JJ2v+D(bYUaCq-J6vYp<9?#jkOH=B0G%Yh5H@nl0R zX4G6xjF%Eyzt+FW{rEb}IKerb=JjT?dlfk*(!oWIXr-2+AmW#Z76trbGegOGHZ+j) zJP_~ryYpP1O*y9F<>*`Dr3Lldo!$|;5P`(>YBD^m+JQbGs%uHKagqS{=s{%V7NUp+ z~kOX^wC1kKIbN3s5wk>Ro zBSO|N8dV+Q1c_L6#{v-xUB0AI(I5qr*9!P6fYtW!h1>TC4NB23`TnojjA=+x`QoMs z*qV}}B({@oXWg*1;U0I)W|6O&<_+-Yh$oj_L7y);rc>=#(3021Z#OfRIxOi+&Cb6O z_qKE4x%N|KLPH4x{C^jZg|F$2U}T(^ao#YZyv)uyaL&8R#Dry$9%i2pg@ZnGw+aFB zKfPq>dUp)~j2)KiwhMm;Vl;V{fg)r(5R#6I&OrBE7fB+KT)U0=9M*iNdY*R!1-s#6 z65~azfh102^)IWW2n3LJfb*ur;Rp>R2>%HPa?>r+L9%g>frN-9a3O9H2PHQCzq1Nt z91Mq$4^Q5^!3NL@9RDii;|1JN4@vuD@*I?^7;DPkbyD1h)c7V<~M`?jg44;~^nioYyXo(^9ItCJcx?=Dh+K`#Q0 zs>@Gs@7df=iTHU`^cbO;I$yw z>%EM{53b~#@kC=aEauE?ELzd4$cJKrI(tEhAbjmX#??+4=u9;D)d=`8i*7lORyA;e{B?TOgd%&h{ga=Syyqhz z%AHD5hqq*V%x|W>v;ivEgw5%L4V2QWBc)*w#4WVDwKf|j z;7{@L9iiu=__6z&vruszz9CYh;R2x;}3jhrf12F+q}^DR31`U3UC&QODyw{ z@ppvmXrN-^BwM}FN|Sj9yy{ZC>xi;SiN1s6ZJxD1-P=Fs(C;`nLLHi={ru6le6)8ivf%xZ+=LDp2mP|?o(-ISTaDZ}KhY7(BLxQ+*M$5{X z%YZ22mGFD-m+M!jL6P7P9$cqp(@U44NP)uUxU8Yxpji5KbVg6FH{<((O?;a({(gLm z3a_nOuDGV7V}U=8ZGnrn2(D2i$9@Qr5!QTE^@l(^00xT!KzhsLd~XDtw*x;%89WvQ zj2s*SwQ z5&6$E6B-+TSDQ5FaB-(|5l>O}!?$w&zl4WR?cy?9b~HeOTRUCeF$3YR9&dMjJPtAM zh!88;^zvIcaS|@LzwGHmW9x6&qtEYsdYGI`a1XooJx{{m{S?rQdc*zee>l|LLV`Z0 zLCjk8KIy-x^B>)tIuq~n$I*DPv4qGhgySb-USZL38F!PX1xt@e?`P+q7B|NDdVk7> z^ulot9q;}H@m|*NdofY6N|tx$#w1YE6h;ishyGLWsL93#&BJ_RTx^oy(E|ZkbP93c z=4NR(;&C}cl~a<`eg`IS=CH5qJD6~95ifB`XFmMo-7~wF44+$n>5!=e2udFWZXyR7 z_}Ioji|1%xhz4IsHi`Lr3F;v3!3@mLy?oHa?hPMT8Mf^GU!0kt!UNY!wu6I>U+Ik= zxH3ctJduM1nuwy|CK70qP^LAX7iRe(86js}Z0>K7ACBgmrL7%ef$- zXTFuIb-k}h_t=(Ua3_p|6(2cH+$Ek1YaTXf=_jxl( zkS^w)`M85-rT-bahXUdK4_a5s3h|2Dhvxla4ig%dK%PrS1LYd3=0)&jaFl|z_TlaG z!;3{3Oy_B0M2vmQ=Tb|OxOm2#nWslcG1alfjRk+{YCuZ|#Aoz%AMwv(4A^}pJuY=} z@1Y^=!r~#|_Aw*Q6I061ucBY>-{}RYaq(VA{ZbdAAGEukJf_QfYso}F9~>iIloZSv zHndR%qEBCy!ue|q5=B(Om@kj4n3}45eQiOGEbP=Y8G*gKHVF)XKc#EC|1{m&_~k)8 zdArR%+vikgtT-2?r<`97=ihkmJ@(3fvuc)jHBPHySyQf9;F)!U?l*zc{&3)SQJxz< zyayRJDmlPH2$v5SWrxo?>!%v3j{MEG_XGU!hxlY3keq(JNBpp%#X$2Rw1#%G|K`rN z1H-SoSYLlv_8+MDAAkJMv^)j==v3#o;~(_{=yqMny=2MH^M6jZt?=J5(Wb%660+Vt z-(R-+oGdKQ*Y|5z{onR4z3+_^D9JEs4(Qqo0{2#r%V?}Pe9oYRDCp+D;&>vg+?LrEQ`GnaU*U_gbWF*nYhrSC>-XRYHz z(ZL$LfbmqwDY}dsNBu)_wj)@?7!X)EIwC^ij2^-9p<}_TBF|)L*PG(%S4BM0s8#h=Xf5b5V+xdnc z_=AD}d;f4B?{p{n!T)=w{tx}{{2%z9zi0S9%=^AS`+h$U-)(%)sE@_#{;$RdSN2dp zXZ*icjKAO$6aQcGpHnh@%enu#>FLM#AJ1R+FO3kwkIF0`_R{^PkMSS z?38#xRNEe9IRB+Jk^W!cnuJmQxDGT$xLW@nmQDN<*0AnB9;?&-bJxR-Z>}}ZkB2$) z?bbkp!<4@0dxr(XyY4=&lM?^oQ50W4IJlIjy;O`FpZMVT?(bM6Y2VMe^%Rjqal_2H zeKU79cq=yJu4hm-YiwcNe}j!Y3Bu_hzfO4g+Pz_Cu&PFl6Pu04b&ZtdZxyv4PA4$5 z3KZVH_38P2mt(&v?I3#JFco`OmkT6TaT=le3{hY5_4ewjiXW$o94%S-U znwkWJ-!FH%JTGm1ls=bq zl^~^lWPXzwlIvx7{Y&qm$JOjVgHZQ1AU-;3L-9WOc2=ZG0e`yxJxjfQphgJ;^p96S zU)#L2{cl}d%M5`OEK?xZ;EVyB#|HX(|I@nI7$t$ATaFpq5ElcC5Bcw3yRnRrLmZod z%fV(d&jJ4L`HCEf4Nd&V^N%DF&?Hm(`tirMt3rzpLRtNxn+`ZIKYx+`);_<}{U5*n zk@5V8*l!>EKO6=6zom!s{*TMR{QqwQ_PlsJ-(4RlAKb(Djrt6+^<*i(>5co__j|{; zyYm|3-OU009})dutbD-8_~+&6fk&ar`E|~>mfOAojIzE^t_Vbnkp8AIlm(=Iv_GdX z9^4sl<+4Cmtk z4FAjev5bGHPw+M-TFV`&4tJ@Qitg{;b_V{f3KtRoeVqGmdYo<)A@TRFXOsK7dH8AEenl^j8S1D&ji(OTk>f#J zhuX*UvHhRf{O(JCRj2hs@c#d*Bl!J;$n5<@pH35fZtgw3ees6*?mh8}v_1{jKOFNz zX8`;ox88VvseOl|UHwjuhvBO?@ym~i9AKRNqh1*L5KMJ zN}b;zc0J*&mV&3y5oKNm+$i(h}Jt>y)RB)bFlV*_QYbjg#@i(VHl6v z{l!v0n3ydX{Oh$o`b1pa{^{Tt|J7IMNA~!}wl9t2_7z1@e|!v(@KXGJugU$MemxBP zKwg7k_|E>1(8sM~6NMB}S4;4gm@0{?XzqjQUrBpQ#q$9g9rp3*97bekv^uZDc5o=4 zbU<-sv(H(mJ>IvyeVh-j$HyGl9f|QiI9+=F^p1WO<6plXUzhR7M|dwYd_uTz4iV)aAZn#zO8zDO~B;x>C z>hTdip9iUA(~ZojN+2ox{jcX=*T#?ZZSRG6^v6A)#<}k&cQ7s!$*er66IK5oWM|T1(?B9( ztmH@EQ{$n}f${IeayR-9eeat!bm)=qP2d;G3Q9ecPDq`U?Kf~+3u|wyWogP8HX$;a*{^cK| zX77q zl)VJo;F+ggQ`s6KMkcRyoV*bGo5)8Vj{nS~flhm4m@xmeqh9sTUX_~xX!yqI;798! z#$KV8jw+2T_)7=s!|-#hYf)6ESLgCsch5ca{xK7+%QFij(P-0ry43qh_SZ z<1!}Gi?_Hl8mcHH;Wo`Z1P#E9USA;d^!|5bdm%h%zLN#FN)yRklzqQv=^+27GP!UKec zKAcj3BXcAC{XdRYD!%r?OjrT{9~~k^V5=g?;=F$+#yaB0CPI}EvoxRf!t*N}ASWR? z>r!LP#Y!2ENtw~LJohl#%@x(Rg&T@}P0F*Iwo96B)MsWLdAH{KeC8Gi=X(3t*tm)L z8J@pKceDHNn)+V98x|Dvwh0U0K1rK~KlMTc6wkg*LqwM7zZD)7`;XQ6>}9=oi$0M2 zP)=;5?kyWv>3m^Jd6IMYLtQHIyuu^av&_i+x>$x!lC&Z>o#OSq%G!vHiGO)yEL)tjRVhKea2YJBO*bj3SV9 zNFTYqQXmJw!Ec%H{{c}8*X6r8JzRPI*v!{&t^TWz>;0?WS$@B-r~k|Sf8F;F**~Y} z_kJ;6d-%hA3it?s{+@=S0a5Tm0s8Cq{UiN6364j~HOBQo`~So7 z*W!IJakzoZeu|L_OW^+tJgZoBp=;?n^H#sRA9@m0m8XYX!v%aWCTosde1=$oNIl4Kh>Gi z?}68I$8pR=2|n}w2UyeS_|Ntly|wUEV!fru7!TsMak{U^*>HLAv+L9BLs57(Y!DrI zl1F&Bg-Q+rO#g@N{dqO~tav&wGJfcp?XvgS`BY{JPy5Qv_u^+y#<4ipoS~;0j(s0m z&(}qNK0c$~0@(c>?dW7LzxkH0s#;6iqv^HTszSIwX@A{F=UAaWpQpGGaJUA~%bPD- zUiY=!%qT(hIK$j2!1ujJ+ueQGs@YOClI|bhR}nVz-A!VY2XWD!ij`h1^BvzWG=iKz zi~MNJj7*c!cZTs*cE2A_+~YZ3o{kBRUyrBppX2VnlWs%6@$o_jFyv`0{m8Q*^Btey zYxwJsgm{p5{9186C^ej&D-noxtFIrgRM4sOb7m)k;uKy{&`aS0_&*y&;`f$0uZz8D zRbfgSco9ye1rXq;ht%CxrXTaB%hbkT6f^xB+{@m5rRrZ@2LNPrJ^%e-Fcsvwh=V**DR@ z(Nb}o_}zZ;+sDEC#+`BcHyDS0Pu*Zi>$Qp|C2Q&Oe|_*3{!bD(`zwmb4&uItn(4@` zTuJnFOHm|#7MsEly>srR`mvm@vuz-Y*AQ#-d->|{vJOHeS^Gr1!-D^R=(p0d{ol%Q zE8*>9nP1E8>JOzJY#n|l`n}JH>bfzEnk+@>Vj72{pOV3!;B@1ms6Jp!1Pp&3Ux-*& zXo1M)O(XconEIY=aGlK4gV69IWcV+9Vd^+~f8b^3@IN?M#Y8(>&y}d-5l|dNe%*ez z`@goamhnjQ#~y#3)&DQE_I|C`JHv?QpSl!N&*|+

%lZ#%R{l8p)E)emAetgS)YFpxK!d|FZqnDT6 z3UaHc3LnR#Vx!6!tzqu}1J~CA^Q4Gzm^c!k{_=h0JUfnXsEVXG{2%pdsusss@w&Jv z5c3t|l|C>rW?U3BVw3kCzA+%x@`aJUo%d<)rw~V`p73T4JxU?=hM} zFKeq%LI@@OE7lQ}`@gSV3}gyd!}*jrtbXfNLSo_Z-oI?inlJk?`_8;pUv4nv!>@!7 zkrz}yUmWMJ(NHoL2qF1#=!f0)#*8H>CoG0O>Uf+}vG!bVQ;5JSVJv=s*x|-Rj6?T? zJua(_=NYAy>C3(q<46r+QdcTVpd`5^zn}BszRcrrdFyAKzZZ{K8U0#=C>(u%3_szq z_;z^@kbVo?dC>-+8d%cp#fdlW&b;}kgg+~Th{Q3}Z)h6b`aTK%`VKNg8ClYf-JDq{ z5`s#xdu17@!C6nwet7uh^Zt$B>-+ofhxSf>5HjO;%c0upxbkAp_5de1|5yG1GdKOD z24VpLfwxG;Mhf2>jA=uetfo|r| z;@WvB3uIf?X7#kVGKQdPxCsM#+6RFsyAB@kCm?^ZdV7btzF!~e`hRc1Kx{jY?X*7D zaGGE@->yAE2b=bj!J$D7Kw_i&q0zHhdzZMpcS0(Rlub6A`xetpiu2K)g8(_n75pRd~* zUsJD^9ekc35#`VtetA(Q2q6%m-~2qzAdp2Ta6n5J0Hl^WnFJaAmzWn=`bTBqWdDbR z9%nwEtM04s!_Pb5hE)c8Z{IKWrf@$<&t`iS4nGmM}{ZEJ{g z3yj0h!_xppwX#USg$13*`uTU;e7t;Lx#3%^E=Z1!jRhUL9u8B~TAco&FQlOk{1p`t zOL-`Q2ygC}{2>qyvEXs+0|&XxQc;C~*AKmp(rF z?=~6I2;cO^AW5DkbyXd&ag1Ghf#}~N*=QTuV1d^zw;%4?pO@eF*Xc7qr}K{bJ)V6J zmv-;nzwUaoKy8JE7{Nb09ph11MBm!z2NFsF#)y2wL&Hjja9Ws#kFUqqUR?F<{Tz2+ zKgsj!kf?qY8o#;zyiQ`ioIcy7JSgw}$9Y;I#(`VH5MY8Q?BPa|%q$$7FVz(TMAc(2 zFc;E#oPWIK?s4S*2bmc^s}kRry2%gK@V-y1-CTVi7iO}s&P5~1Q69go{?a3l?)12y zdR~7u$KB_s@Az=<=&Nr3LJ`tS_8<3G(^aAh^-dAKSLg8JCT~%MB0lMuw2ecnxrVLfV=(Bg@$G@xmeq2Y>eh(iaz8!esM8C#rW6IAE-(Gw= z#f-W!yi6Hil71~2g%{$Ybur>_Zrba^&u>5Kt$V(#lk_4yZ0Zt$Nc_xh{|60;vhfCa7G>X zn{wiUlLh|FIFlbKf2u6j)+ZmwZ&~_6!O`M=T|eVo-ZH(-)aZG6hFEJq}iB4VNpdUY?>w z6ur3p6Z<>*kLZumclG;u=KzX6KHK;QjWWGxx_QmIHo&xVP#D_S3m}KhwJVwKXg97=ReEh%5?wF|Et5u_NJR-7)^{N%`TL?8*E!!i)DPB zFI!g2Zn?@Ly>U}do+-TYspZa`al5K_O^#~~vP^-7B2sqyKiD=1G(a?ef4UqYc+>zQ zIAQajtDii7`+tc4-SqnY@;>46t&U}f-fI5$07-0R4e79lUxpk<8};kceYxmwvVqKt zyi#u(I+>EmQ&mJu6)_bp5OrZUW?G_YD4-&Wf=Z4!EZ$``D^xO~EWN%r&hAwZZ73z* zcb!A)pPwI(ip^K?io`Nkk+U9^!IbV{Wmo$@u>WcPGC%kCfc50PxzxPAk{YTC5Eh9h-V100X9e*aWhHe2_uRUbVZ?=_3v@VFeuKoq$mBTACLQz zM)BbO|9?B%u^G9cJWo^F+l&GKj@Elb3>yK!2!IF!`fsd}n3RieTXbhCi-c8TK#`+o z-GRQl3sYoS6`)z(Dr2)4Ol=z|N?nEIvPeD=PpQOt**_VL;WqED~s&XDh}w5HL-2hxUQJ$yc?^nuUDaG-Ud zCw!nD{ZO6dmfmC!j1S|AdI?E9zMJhc5-1omI}RBTb>+iJ0tgU8bOwf4pI1@iJxyIF z_l$MQk_DCo3#L|71Ej;y#Y?{k7!Y}Ozj;y;2{uaL>&JwX4R}CfTtQLjh2q^2lnkTC zR8ajn)XbYBb~8Yk$6^4QjQ$d(XC&79KDOO$tDhg8Q4VCQWaMS$RBwu8QcNd1Vt8%E zdg0a*FP>nX?ZWg8V0ny+ci#h0XU`8Oo^%C+MSzQXfF!VI@SBbhMW@1M8t!j!T3J-5TXQ&AF~rnc~gd{c(OJ`-a}nqw{lXVDTr$O1?d!+HZS5h4#f z1RM^y)I&9b9J3-T4DJEJ_Iz>Yx&TPoGVJ5mgdBz)CPje%K$ll8(aI9yU~A9wckz$e z4ffLvKe_ucUTRuKmJ5Eb_LgA#!fAqPv{>o~AB}ux(_@K!d|}F19j2c}>ef(eBZG}B zkmvqog%3`8jh}}I43=ThVnlcYoI^AglkW9Hlf~)qB|ITuHIURMeJf?OSOi<(z=tD1 z4`Q77$Q*b?jOkFH9OpxUeBCKrbycuwlxv<5*_(G&M2(Bl3?PTbCB|L4*f4@Ai*IJG z`e9KY@B$I4exMmVMPsJXArP0wPwXg=WY_1?ZnQ-XkBz1XvkaW`pujlAM_ljGV~nss z8`(|C&N%1CoA$*JZQZ-)Za5Z;BEBUd9*{CO?nFLiaBCN;i3KE6OY{&Q8rdKE_NJ9K zg;Q$-8pE8?;y#3A^q_%_|+3t_D@Ixd_ER6#N6@QQM&W( zLr0D{uW19=$OJVraNJ@ba)IT`jm5>i+#X_iGV3xsy{8$Pq4UtEG!PC$cq{}pwTWaMU1BxNLQ(dcV;&Bfyv|usfv3tRO=ASz`!-p4XPxhDSk%?tdM=7(E^MR9QMi6pf(4Gb%W17Hn*~} zGDbQ~%p`(Dai{U+29^zKqGzUCqF6yBoSz&ftUUVfYA2`fz4$9bG;Oy4g(c0&-LcZf z5k-1Ra7+xQ5ghQCb$WAnrx4BuIY!8{&mTCg?;Z^AZk3W)W?hN&hu%9Q2L18qyKJyK z2_{7lt(FMop)lv9+w)K(jX=jhJfI*E9)@`#i9{Z!qIsTl@5ARL8?Q``ff>Syz_vIV z>chA1Kq6YBzJQz-qePSm<5In2k~o~iGnyj>7a){E@P-RNeqVfnFXyz6Yi4}kOX|lY z?s307JlkIk$Py3ve}Ql3{J)>||F$51XZZhFU{C!QKja>NbAbQ1u=~+Xf1yTL?;@OM zKjlX@&A~#bz77aO7e4r%WBqxV8X(3yiQ=8-4qSV=qVRk-9&9v!WN;tx_x@aUy@o6D zlT3987M=>`CUS{?fXyV3a{I_Pj?Mf=|u@$8J6Ge0{uQcpvmvo<}pu7>_wo#_H0E=MKNZ zF#q;{l}{M!bFyg|A%C;3xTR|T7y< z?}gLh>rm5b)tJ3rFl>CSC%Ipz8`M5)qA?;J8av#QaS&tUcZv2P_hC4mbj7GxAsAeP z`_2D)@sD#_Fd(v(b*s6#6}b@hcNhe?B}3zg5j^f*#ns$|>Q9?Oe#)o8lh2xe=&v_q z;uUK-m#-M>7uK3J0uZ{xWh@{`f;Dz8og2_vHMc@Y4UQM(A;inb-dlVRnKf zDN6qi7_|zGSlFo4ZK#UDY7$Zf2~8nGU&|ll))WC;`V;ZEA^w#DgomJJ$nz1F#!%3*-u9_=<`6}j1L_`5Z)#bJ*){UT|#*#4*hNmKifuu@Gp$LY8pXsg35wvZhu}0X9V$^7? zVuMDDV#SILv1{2^D<-$j|F!D6QHx-)wk?X3qiqywEJaCT#w|%2iv?dBoXyu51h6C@ zeUJDp5jF67G(?ss`|3-Hl?*~j5XUn$SzISBY#!3}Um;;+;K}{`C z|A_wY_$OSRUKh}CfuchGs`$)-Kk1ZdOM;Oj;PB!#ZzMo7rf00}7dMn@Q1C;<%T5K| zi|rxy?dEls$9WsMf%p=Ji6|N=q@*e~j3KeD8`9hTi_KA3H56lL#xp1)*h81^NdyW)3$zd|#||yRWo_r*17v2`)oaQA=R$Yx z$e$F`Nrs5`kQ|U(MLmZ}6~!XVPEP5>qug6>hoJ$y7`4icqOluArfMkF)mgQ2u~Cx& zZBcBNN}@H3MYiU-im|AoxvIH~M$#D3ulK6uMvY@?BSKP^$+e?YVl_ork|-^sQKJP_ z@vEB~8a6gID;r{>qJW~Q6V~(Re_Hk5zcSxrT|4#D!wTG->XX5F3JfrK4&DIo+A|_c z{fXTKZ2ZU`>7W(sZ_+m3%b?=6z&ykBJ&v>pdQ=pJ3toAEPy2WL5-6Zv5W?x*p<;M>&gm!?$fNc%BZ3F`1mWx12Zs&nkcVQ1YnmZ#!jSxp=_F{w#L>qSlZa5U`UDzXrw6?gQ;>jfEDK$HM~JH_(Xw)c2;Po~)95B~1aX03~2F=y;tob(XM`DQ^Vj~{-&JJ1e#1$MUa z_=Y|Mt+3S*S(#=g79D5}TACu-Fxw83*Zi9BrQ68;J8o|HZhTL1&8^d9W+5H0VLA~_fHr(ajq zkUqipcy4$9G=1LV4*att!|LZ-eLt|Rb5_+E;ec>mA73pg+7RPj`|Jkr za|T~_WzGTaL8u$7a#DvD$w5Y=8%0TrY{a8jQqgKQD8+QsOO{B{yZd&ei9E#`C@A{m z!deZa$O;4WGm}7+)d5sVRLe%NY->rhMzmIwBx^}j3AT(@rjtoIT|ECYetUm-X2EL+ zkfT03ali0CkY699y<{K{$otICya=y(a0rk^AP@kMJ|b;>=a$AA=aA_AI-7ESZD(4F z5`+pykfEW7prAd`jFgnIOww4ODJU?C1}Zj)N~EKy9~(LP_V;Y={nj7WW>HmMfMETn zBZX&>>z$3N3XI1qW%oVjub6&1Ht0T!?(!N`J*+)wKj_0ednxPhzW2@ddeN_qQEL|1 zlMJH9u>ev91q~JG0LD!rNYc_4k}+Gea*8&i1)`+Xb=$7$=`9tDMNw=)N)!zV`4Slo z4G0u0K|}PmkFT71{aNlK(lCyC>ssbG(VE5_lrFnvZhUL%|D9W_Uu$2#TW>bM8s^A}K6b)S59?Fjg&%wHk|2QL7r!1#D_77Kqyw zCbSl@QL#y6D?(r`f9tKvnOB*%Ynv7*jYSesq>EVDHiCdwm7z*z0*w2xJE7XGq{5{= zu;yV;w*IrnJh$zyeC;;hFCB+sZDo*m)A|3y z^w8zL&@X`-^iWzrNRuE0TczKk_#A_{Bkzy$3H*-d2j0Kr{v3CT29SxOh9E27Bakf$ z(ltO0QqU!epsF>Eu~cZ$wTi11L9|;5V$rC!#-kf()Fo&(i((^IEf$K##<8)qZ52gQ z8*EqmG`rkf+R_n4v|B}^1r{ob#>TOdqANv<3AH6r6h)-jGzAnzXLZUgjYh_q8cnDp zV%P~RQH_I8YZ@&SRwEIOj$EkFT;+^oVu>QFyR{ZJE^6hhYic&sRfb~~6^xdXQMM?6 zijlJuC3{tqTKjO`U8PR{lIH)j|Ec|peyCq`LxJRmc|pkdd#U8N+dJ~uY3Kx*zlX=M zsF=DJSmyK028E=cE7DZS5f(!h&+DirstN+a6+lYT7cm*8qQ=xnR2DNejiSYZ5w1F#>U3MjT;uDQH^6nVu;4nZHlq6i&`M7 zMG>*FZ3arwtW_ISRj8=8im+`4)J3tRBWg=yThm*1MMP9hD$tSJ$6uuOu4#W<80K#q z@xFp;ho$j2y&~-s1*#AdAVpP{2}FKMEoiDMkDj;NJ7JF)Y3toIbC{-20DOnx#`@oQ z<^6^Z{+OQHfbWDhgrg8O=DC?JHH*)S+qg^9W zZd~0(43x?GPIb^ZUcXeIYZ5kqs7Kmb*siK;=pmNfySUO$kPmdhKzy zJG!|uI_+0BG+5S6S1zPmhc>^*H%mnks4T*bt?105I)7d|k*DQ-FwY9I@2|QtnIccu zhM}aO^(VlNvi4TVqJT;XV(DM&Yt6Pb8*<*+Ys_}QatdimNT~OarbR14(!*HVKfSJO zSh11au56mcC>26Pr3qBO$0+2qsY#%14MQO@7AQ8pt+-nJYt4Hxh}z|=ksBoiRR~op z6$#zv-|w>9_~Y|pe*SE9Pi_8R(>Lrcq4=RtK@NZG{%leUq7>6q74=~s*@>ih^o@VB zW$Ojxn&MD%h`auHBKbzMDcKT|l|Ss$-4E@*2nV49(Eow`1OVT#xAGu({J%%9;Xa+z zf4llWe}4|WIrRDZYqtNx?Bn)q1$s&0Z)pD97xzh?+&!Pw`Lj#X{=e!!*~R*QyTkiD z_5ad)C;t(s!mgkG&mN`!>i?Z~Yt?J`Ts+_*<;SPlu7{6LPfbs{b^c^eL-L^C&{zid z5CaeS5k;NX{kT&f_W$WTf9sk5$DdEL)1KbT&&l`u-UG$*lai%ChEYB;9&nThdoEDl z4=*>f`^()nRspULbG*G!ptP z4v_0IIQezu`J?dholP+LXWbKl!8-YMRV=+1;CZ}UFe~TZG9ZcAo*&_lf2XGZtFJtt zE{WnYv65;9@>f%xFHylA*ZF*hI&JHQA3noY+vUJkK?fciIDt?A zpbvMo7Gy~TGqeGa-m=06$o?ZAR{g!peF3caP0^2(?a}Tlw(;qAnJ#vw zN2cj!xyDAsPFKI^?%rp2*{u@;@xtoV?qB9dm(%OlFXH|q7ofO4c;LKzJOKP{`Sp=^ z&&B=u@z-6)rhCir@9t#$JuB4udf|q3@~^RR*UN3y$0cp_}r$R<|Nx~qfzE&1V8AMav^`RqX-6pi4Xaai4ro? zF+s)kZw;GPN3HtuZ~djKm(8{Jmr-upV-n`#`ltAw>XEG}1Is6qGW?#iMLRtZY~A(^odcP!zRA0Te(K z1vCNe`*cuiYM+e6Ux^HelBl4enV}h|DLnd>5$=exD4L3>B3dqYTselg=UvlsIUG%N zjie%tcXV#KH)0np-P^KDx|eqAy6Hp{uDkmC&g+^n=DMw~`*z;BOsAWb#uE`>yP2{& z?!*Rp(092nS`Uf=)GVK_#UI<9Z8CdM~PB{O)T9oGx?_m0HY%bH7AR; zt%T4#hWwhl@vfY?;jZ0H)4I28_pa8}<+jrQ)9tGG+Sc_fYAtUyzW#jmQA^Z{ZwaVq zK&1(jP=UO+BCY1;ipJ4xw=HcOe>Tn*L5J@Nv8_!658@wJ_d`ji06c$pY(u#lxht_w z-Q9HChQT@0PyBV}*Q-e)q9!C=N`p#*D5@>BP*wk>Kh|U61NzJOf^z_gsfZBBMephF z$Alj8U9(Sr_wFeGXyQYnApJWW3MVS>!JvQAAcywg1DOMas3@?sswfLVL-L%3Vp>$t zLKw+SC%)haO%Rkc1tkp>C%(zp5xvLwQ~=UUttHk0k}yI`3y|dVP@ix2t!Q?sPv(^M z?i|G}SUfMox=8~w6dQ)n_Kqa4nWy3kT0&wHUB}*iSLFw;qp{&l+(p(b5AYFVanN73 z@qCDrP%nk@A!23cU}Pxty(}!h(m8;Y!aFb4zSAhk3I3^QG`X7Ov!%Bd$(s zySsMmo3}5=9^}B_UxVo-P^8opLV9Ajj$j^aXp^;2nJeW9Y?p|du_oMDfe;?QT zws$Sv&XsbxTddgZzkPE^sC&0}8*XC8*eeSem!M=T`A!${YH|>~Dd7~xg6 zfFkyp025cIcXT&sSQrM2p+UNlz;~2*K)ME^y|l?J@@&v7SYVV-EesdOg@si^O>@6H zZ3M)?iJg41+#WfPygQr8W@NS{Nv-R0XmvrX#R=NXT$A$o#(iyd0dKqb=m~j38$7+hj2hpI_pAQ`@b4R=!Vs-)`=4x+? zz27$ulU-lv?Oxixt@!pfzP2vV27_y+=Q8fGkkN|lF>a;Jp}E9FFq93s#E_z-I7Z$R zV4idwZNDY+JburLr)U@5AT;3#Ld?I>-DuTDv9--tE%kZ4v--Pewk=%N<^|eOJ*#5UT8({b=8agYEfiWbSl^m6ZE`efHnELGim2N~KRUTa zHASOPZAC_-S}SOcMPk@#3J{c>1iJ_zbh-n_O36h~gG!d;B)kfBf7TDS~i(_tXe+s!> zHOjxz*Veq$YKunEjYVTvv{7m{EP-i6qJ=10q-beFo|)Lyg&Uc+*{;sUwRJtJX+z#^ zEOT@8HJ4`rUq$i2A6k%k(o9maRRtmWvXiMLts5<1i(l`u=HAOJBPj$Jd^>$%=5%n@ z*@W)+9?(;B;2#2fLcDZ&-2VS?LHYZj`j1E-5kSJ!Nod+gqZW%rXx1%=D2-zl&}t%* z3ZZHtDCJJ_ADTe85tV1hvUrlJJP30YUR%xb_0Bduo957M2;rl&L`2#RpyCV7^V`|W z_lTT}o*i+Ir_9 z6U_YRhXOw8tE4nil$g<|*5>3|ENCoN#Te0Ct48;C<<^= z7yMD*xX53Dhjb37AjCceg_(tzRo6P@&8DfbJKeX2H_EPB?o?XdRq0&3+`T1CZM`=B z&0O`}qaW;Z%j;h5*Olh;T6N4bQc0<0nAQJ3y0!Z5@0HDs5!&loHpFg9k>3yKk&KHn z(-TUC13*+znimyMhx?#T8Q1h5=KjhdV`WQDY@0SO(st(@iK*3P8jLp7TYAUF-4jYD$_`9m=#8`t)kU@ySAvU@5eHvtIcct z&AMz+s`FPTbyrMVeQPCFgyOc0VluptoeP>5 z=%$0O0Z8|mgg*?)gEKXm`;Up3@fl~Aj_$K>2++tP1|~v6h}jb}NP{yYXrmfv2{e;3 zS_T;o$=7D$?%ea<jJYfFw79X@CkkjJ&vM}+A5v+bqVQ1`VYQC?&hMQT^R&n#`rmp(LG7j^HvOsjJ5mCGeeU3Xy8+G!+dcGImDG!QwkI+gJPipuh0 zDvBtGjwGcFWZ970D3r7}#_jjD^?OqoHSksS=${(iV>DsoL_?UN;uQkEAPXuj^nKY) zrrYm%=2x3^qhwJ99Yji7DAolL9xGu`U~?!V$xsvw)C_@8RYKWSsHM$abEYJzSj^ka zU-GVREwNY5yG8i7rt{+#xp{4QtZnAGRnus#(j!KVu52-yYn=0LF_xQOgthX}lf*bd zUZ)}Uyn65I9}k);kYDif|4nwsOS5-fb&_9w(j4=5YT?qz#A0M_)sjrBtaD9hX02+g z>^|ad{~gWLUJvZQO@q^P6!3ga6HQc>EwU33f;EkRp?;9zCfdVA5)l(ZP*4ceR*Gh| za@)n*)oMfTKu@Kb%Zmm!ma2C4JWPt15X(otwls)5|_4gI-*fBSM&%Px1Cr4YL zb1gpfsOhEdFa!^u-Uif)QIKF&wGplS(*~?!Cwtp^lzFw%&4`(m2}sxYLSa7$9D*iE z0>;laG`0sRyNy=rl7`zR=F(KVv+C`5ZQC~@HT!Db$u(YEV{5F}4PCU&@wv2Xn|HgG zcUMt0r@GcRFE?xp3eB6kZTP)CZeW|FZ6&$ObERUW(F#*Lbt{sKT|0b#p{`#(ZOT-) zE}XfZcG};j-M)L)xSG|!O>3{6NQo+$w))t|y>4pkoeQfp*2cB)q2N+G3L|_g8L_S5}Q>g|;;qteX~Q zp@yPS3T9PCHZ?HVB%Yn_x>F^Lq^{!Iqq~mlb|XM#&TP^W*vqc%Sg~7R)Kz*_*WY)! zMM+%SLTISM(kqqbx2e7O+^_SqhOkY+^gN;b#oXr1emcPowSlyJ!rBFdr~)7Y=>Z}i z-2Z=@23i2M`w(e>LbCK)V2n6wnW_R^v2LqvPC6eC&+L5${0G${4;^cu_G}w@vbmJ^&V8kjF+sB*eSz6|{-@`B0zg~xE+E5ZP zCbV&d_pNg6n%ZgU2CH@z77QeiX)-DH^Syy^XCnHQKD*?eqzmVmddi6rVplBhAT zOd^kE5CeE}N=X}|MjfBO7u_~CJ z_57s|1fyS?xNpXt`T5+w&{_87JvuRWq{$-4LUzW8yPEPHdFPP$-!GQr%-3nj<9M)6$K$Y{ z1LxDh=v??$;C^3Q_Z&$-6&JjnR*D!ryz)b&<|9u4|3d{7gAyuV9RhzEf{K=gB`Am} zYL4$GZTtChe@EZ_A8&G{P!TCbG*uJ|RD`P`B+()3b=&ybc2J{fFr}3OkorJA2pt75 zd{{!0D{f)DxfFq-CLsF$HdFU>^RLB93%xyAB|me;T#^`Jid6*m+)V-Hf@TAqjSzdy zGy(Q$S7M5Qjr{NQ&+!hnT7Mh&O6Uy|i7J$&`Q7}!d(4%rmaCP8{h?1SAGfS+y_IuC0x zN6+w2GM-kV_&ZvZ`?D+Z{a~Z<&_my!DC&ss1Co2>o-^r{f>eX7trf6aT-U|5=Co02G+Rc|YB8(JQL{~bTHaQ%sy5pe)M$#M zYZkWnw&ktOd_rwrRTNQeMvY>=G(^ulzI(0a#i%t#+Qp#SENoP2j9QIFNw!N^3Raee zl9Zq{z2xRlvjC;@*iGc2p=e5JMyiyih+5IDV;VLwqN1rbtXejrv_YV#pxCP##bZ%g zHi{~r&vw^$SUk-W4Jk;J8_Jk?#6wx(i*PuKMumt{kf5b1il(bYL2N>8ixHxTv}z*| zXp081sI?}jV~=PY=TrK$JOJ@TQd2`!)Od!9qymIGDztt26S+{7P^C@%$aaM(Kq(eC z0O=GdNYDio6um}N+pf{zg1kmrFv60Un{8b!-_x%7+B2M8b=^mcPtCKewv`nU+BSni zRw@l+Wj;D*`x|ngjq%)f9oKhsZtmPS&fVuLqFm(5%cjqD9NpY(-1hs|Uz>jG-_P@R z7A;-3%fD~#>#c6k zAVpLI7ZB0~6fGqtRT}28t)e!k{qIF@E^jLHRYtYT8oA4JZdU4CwzoDmHs;%#MWWPg zlN`44^HDWCOBOb-E#B*L*wxA{xowTPQDWM6Tb$uVv94O>vSWFwuQuKsu5E5xYnL^y zTHL7Cv0669#ay*=xo%c9Zflx~qPI=0%DFJFHMyeN^3{r#F;mEIE!eQki2n$021eAf zA)P*74?|T^JOoI+r4y&%>N~*1Elj{W$TWpE#vthn_vhe?4_qux zAc<;%fTj5oBQrnxA(?%UZxYM=qq!b2*q-{8>;$!dk}F88cxvlGi)C=dR&)Hm?4^p84JM z`_+8>>f&rymko2KiqS6XrrqUr8|QZU+Rws{wLUEJ-X__QRbou5Iv~xsTJOk`FeWyA+(R#7A}0 z6&nF@+!>RsDn&&FA5y9>b(BPhKvN&6%@3ue$r4)`6&>Vqa}V_(vu`_XKj?y7V4Z->I{rKZ(?|kwT%%~ zCw8|fpB;sa?zZLoQNDY=Sz+U?7guY%xDf?LDxB415KFCc>qHc+nM}r_tOg1#ZhIRR zwNVgM%~b^j5h0&Dw0B+V|V_20>FdUD}ve}HAV5# zH5$gWK6ckrP;8W1#@l?l?TUT*uy|h+YDGCR2+1ML3XsVHu;)-*jk zb%;R8ppc26nQ5qkCMlwVj;1G0E{szKdFXKsh5?lBM7=x-`-1p^aK5=D^9a_9DLZ+BdGe5>lWUP%^# zAZOn0>!3o{JDJ_x)uUHUV{)01CY-LN-Er4<*DyWY(-L!@o2%c>wO{G|x9e7@65P5G z5zHL|5Y&wW5VX@tK~xkkz^F`yiY6!-e(Og2*IH}I+UZ$!*0^e04P`936S{8ejIx__ zxgl@tuQ6iQF}nTrUd&sz!~wLXh-qq%STaJ21f(=I(;E5C)yo)*a~Cdj(NU8dU!~0y zR(rM5De!F`)yiWx@zU3)M6}bS~Uq2YaxwV__0Kz7vw1ma~irBt@CZA12zn=E*-{se7`R$l$AuLjAfT5-$ zscnahG#u`L8}^bjXgwsWHFi*OiPFP-Sko`@KgyB{yeN z9Jw&2HO}tE6799INwg7=v{H=|SV?xi=2(wi)$ii{Rqgd%jUKpQ^bw^?BbU1)>&IXRhUEE+Dl^8SMY%#n&IJg1fOgRtbh+p>mtGC{; zNVIy<`Dcpx<*;jMt`GF5{SH&5FPGqkjD}-Wqj<#fj5nPoG@skG=J&g|E>GK=2}WB> zNLV7BYXvvf43i|NK2V~2)*i4p5r{g4VuFIIiJIzBQO|=gu!|yk{oBm0XSWzT6ob^?R#dF2@>NK8jqOw` zJ!>RiSu^O%^I-G3=!rg9v9wmO@dFAI5HC7xIop>vEzPTz=Ax3Q#Vab{+4*?cA+)!a zyi9p{#pV=8%LC~Jo*#eoVEi-Szkhd8ML?(9FV?ek_}q-DJ{2o%7TwNQT!!Xa#5|XiIfoq6c3h)3ZD|5G*(CBJjGCc zk!v$P`*fSSj>7uv-tX79ySWwUG;e8v1sJNU0g?%=4xm+H$ctCnW6!Eg#dRs*g+{ga zY%oCt%WIok5DL@hcg`hY_weKAS)m$T*w*C@HITxrlRPt^95c8t zI+YR1G!#Y|shCtx8*K5YWm-GlnL~wr_gdc;>0@b;UuL~6=rB#C^|<2cH)l6VsjHkh zC%s`3@y@GhRJXRow#p+?iV6s+SXB9Kd~b|J z=G@)aS2Z_w*F_9uxy(e!AsSrZZTEt|6PQ)j+Ij6R?UT;1$g|_0Ee}vDJod>ovK0)1 z-DrSsF`GpqfFBTtaYC@9!W$RHw!<)9UA6h4ugA>BEnlXto9gG@tFMQ1H{TfK;km>SacFm3(TbvU$Zb z;%5S+ty^TVT93<<<%i8YaQkYB7^AI6;#!+Vg+t}@P(>enw!XJ6GvgXc z^2u{c=Wd^#_nS=Ha)T6KA6eb)JA=nF;!zbD;}&_W+9Q5P=U1AGSle$c-yV3Y;|!A; zfS@jlfa@iBlPqNL;>n*?!E79%(hS}2)?}E zdk2EiRcjavnbO>FUOS?$?NPjoPdj{4B}%q!Ho)+|Na&CjDm^1B0x z^X2KORw7$iTUrcKs-a(W&S0{}iL0^5^#ygRZqW4W1z!+0uvUC(1M-V1vQ9#Loo5mt zGuSA!=1pkZdLNDT;MSd_E2Q%k%OI@vD)7xUJ|`onPtNZnZ`)Pg?moNfuYxg)8jbo^ zzP8?%*Db`kS3Z06_WG~7RuKUVil$&yPr6urC)4r1`83zZEiconJ=VF6jY49!`rCw; z?RV#Enk<$n`E_$=-XLZfJ|>Ke6FL>{{L&iE@v zje}9{?W5~{E7`R9*CLIRQEE!~)y*cqmvj^bf{^y#o>&=;r^G%diS?2UDAOu5QdVr=oxo~jG?P?pQE$bo zr_Q@Zt@+)4cYI^xZ!NCwgJi4r@4dIy^7nQv<~J6=Y^14I%}uQoLnP|ibRc~D*4yIT zw&h3O?=f7|!&?m2iZvRFsM{8eWTMm+0dLc4{8qi)ZOcZG%wnP*q$&!C4rN1XBfYU_ zrrv6jTdsTFfYtSLS9ew*aFnf4h*pkhlO?5DL{)js;YHbg+m@1f(SWn{Xd~qLpi)DCMr5U2&cfTvI7=vqL3u3 zV#1`1FwlICgeyJqr+Ci?)GG&k(5d5C56?HxEU0J3Qqx3>;%0J6%kw*sK6!px`%e{# zOkhJ+4dFr>%s~*^WLdHqK-qc;QLyy!e~r?`dqSoKvwMsZ0ySD7hB3MxUEF8H^@oJ= z&e|mPceFj zBFTNeUh}SO9au zMkO`UYaq|`YXhN29f9(NC}>iWkSH2PkUgBn-mb#i`>Xo)-^RZ8wynN*C|%qacNgkf z`!@AvMrPK&D%+O!xz`HCX_4jey*Bfu-O6(7P2C%Am0gsKB0D3R9`wX~we|79X=daY^#|?{_Uj-h3w{1t?II^(H|@HnUsa?Xja$ zXxaia1%21w-nPFRYTq~2((`O++ssj7D|Ovb5k}tC`@T-AeeT|Dfhk1oM)myA4>y2YYZRoK`H7Q=@|E*RylhZ8$Tru( zfvqvuuF&}39IKxcS!;J)p{DNY->=p)!RVhavtOFJ4LPsRy^-*cJMzL$!(6$lRi+tX?SBgYB}*N2%9cU~hi3I(KT+zz4w<7>lXOtUD}C1SLd^EWCnL|Qd^wDq;V_OFeK zu?8w5b#JQodzjWV{3u8r5R8gZ*S~O9#MT(4L8UnG6NwzVu zjc7|2q}v*eVxvV|$#O1hmbthVgriY%<#Tc@VlhE$`gr-l*QwD#dVq2VN|u13rKB7l z=b#5!DxM@VRA?!fYM6kEFb;6HA8obihjDyBQAecYgGdDh2|!cjjFVEi57({fPD5d@ zy>-otMOX6PZ5BvPP(he5*b+kxshMV7d6LH1(Ymev4ck@bua&RG+xM`nhve@+A8!ZG z3JRczsvL)vySkWAO|;&2*`Tn!aH@-Zzm)gGwGt}6AbZwwDH#R(?S)p9*C?$O@vU-C z&fvYfvH9IPg{!U{mWtEMTvTXbhp9x{x;JmKeckr9-n+Kd->tWm%F<+*MnMuEfaX$D z;pP(124tI3#)&;UGs1Iv?TFD3Pa9^_;G=U z7^YR0(iYe@eE*AOr-@E5<3};l+r-1EJKhjFyK&Bt*IZ5Y&XwXi%S|c05^oyL{A_P0 z7WuxpfH&=6_?*iC?^^KV$C0 zKNzd{&1=n#el^6e-OjCjVed3X{Zrncob~}pQAzQJU}P`n1mdFi&DgfXw28!~N+#U* z((?hMBsCD(EW@HX)QcOPjSM))8Hh;I+EOBfX!Ies`1IH;8Mntu>y97g%?DV%j~j}y zxJ|5ZUFi3^jvO`Y6cYs zv~(auQy)#&JZx*ys0I=!fPm2yHbCRR4>{v5B2E*h3y;Elkq1c*J1^iIu+;MG&7(jA z^3=t3v1D%;yR10X3gB4k$m;!>TT7%mL44}^6+ZGnda=l%C<<1P5P9C@oWf{qfzBjD zHKSUN0evwtk3Qg)vs9w2RjxC)}ZdhIh>wDQ20VK5FJa8t6*|0(g$e7m0U2d#$upk*oDtu{%Lj{je zk~UOS5(jXj_|pz;ZWBlC_jqV8seWJKDyf4&5oFg)Q1km#J$yNzFVZ=%yoI!2Bsytu z_XuAI^^@ToN=eNTCP0*Xb(@ye?y9)fJV2d^-3i)d$OPbxxa7NU3mO&9^!&eFBfa(KoIn$R4tI zJTVwa`Sza@+IlXe_7b{=2RmJnR4bC$duC}t}WS<0w z+M1B1T<1x(zWQ!z(NV^D(gk&|Urz@YCbfrZwmmd+Egj>SFd=;wcUZ9czL z6H5Ls?qHQ5+^=nf-U8zU;tgg#C$!LNc4VP_Zb_u4YKtSxYgqZ#7Nu0mo&e~;Ez`gf zZvcx)i6;Tz0m)|Fpw@XDrh*f0CcAldziRyVU&-HIy|(7I`}~d|kWr>;g@lI1#bhq0pcEKX%OF6jlJ(RkIBCN{3HyYhEE0yAw5EJcM%`{Qfu}OCWlv3LdgS z@2p<6hdjs}fKWbo$f(pAWJOsWUnKBgZ21&|w1_QJd zsg#__^*P?|9Y%S1Q~Grg6%-jhldPR5VoErJx;Gw}9uI$9$)hGR%*@wOOH(XFKvfBG zgOWvE=C043(pF1YlWFs|;bOi&k3x(NZcfd{WvAD+U1m!`;sYSb%XTrZs<~ct*Xz4t zytnjMDg<>XWShuy4~sV2Ly|tybpmQDnC)qR4khQDdWV7A2bqX=o4DgwXbjOhd*p3c z2T@e1v??6SK$HpQ4kyGLkXm2_%!YFEgYpNe# zk8pfNgjE+Xs?<>vk!5YAmXSpi^{!=kCe4B73js{r%u3~RNjcc&ziQ@6^@{lIh5h#x^6emYnPWpe@?viV#jxPZs#`nFEjDmUQWMfw5)|a z^G{ViJedIT2o?HfNb_VlBoPl>_uVAQhYBh7vApeYz3t}wW@Omz=jCtO{)kQQNOy@(8 zonQ?FYH2yUb;F5G;d94Y4WnzR@o&CWc%ET37lQ+6Dkf>FCWJYWdPwe0N{s~v7W(w_ zI|qJvy5F19HQQ)AX*Ey=tq~ar0NwC5Jd~^6aRqsNmc9jm`R}XC z8=DMGK70d9w>;WCR+HbCzAK!GSH#h`rxjPaM2jpj5c(K!rX_`Z#Pt}%Y$0SU2$n$y zc(icRE49vH#gsxROW=#q>44ciadyL6R?Hmeu*O6uqHV>Fp_>C~fM^EzeYV&(YZ?#`BzV+@0!V5g0Ki1^ zTd`pcCCqiiV&aY4>PQ+fhN0k&n6@@i8K+u9Bp?!w6oN?gFX0QKTCz=9A*y>oDx)p2 zqROLP=pQ}jcR+c4YEnIQ3hTi@7&ho`FL9pnffi?*67K_(&?3Bf&u^~td~uRGN)gNB z_=rmx2ZSIZ_)Wy>nZ-{@Sl~}SI(fFfoW6RhBxn}jX%n&FzypcAd4A(v9}Xmqp>qXH zGtmzrKuGqHV)t~TsjZ=o01jAef?X=IEBuzL@@?410*%3pl zj>uvZ>jOVWe=9GO%xqZ?*XB|pWS*n;UFqZ;oF@G+AVBH0)C|=Rn_DE&t)xLUMXp=w z+V|&g+R>@Yt@Gz^tNFdWI+b~49x#l2^@GV!=H-FJx_WKhzVX=WKxTk4utp5*_vcNS@Co zFtE(c)xNWbY{+h$p@EXAWP!mNoFcWk4imXP(7l`!Tl(~xIC8R_p0P6Q_14P9^0Ih7gtTlT>e)=z5SSr2|L&MJ|9F2ppf@UKn zNC0h>9gu)^1QILGXxn|whh6b;s34cT9=*A=DdWedXP;sCG(j5gdr)wbK$;bL1>huc z7mkoMmq9yS{BO5ww_Z>+Ca$$1)_E|KIM%5V3Xwzx0N*(;O0t<68-jIyk%Un-Ks@U( zy3K$oS`aGLiAR!6<=W0W2DnymfkqP`0WGNyh!niWdR2f>&NzPle2@Z|cX z1QXH_^$&Qb>%)oHZYS39-#X0f6fj6}E}L&G7?6-ef(;HiK7H;@ViV%4dn48gL=rk7 z07(Q9chr?JgaJHIL=Z=BghN?qpne8YCB3)_5~{RSS+1L5QABx?M!*H#4eY7L2wd4} zR|_~@m;g6rm_w1+ZXv0NRd|GJth~i`ngz%WuNhr+z%e6_pIh;(>kJrdhVi_N9|ul4 zG$WT5?w1*&N!pMBazCrkJjTb=l*dMb8(7(pFk$Zf7zhTjQA6Pmnt)!g zGlTGu(Fkh1%5d+JQV{^bgnm%n*d5Q*ct04V1Joz!B+AwW*taMH07qM&C0Y7IdJKI7 zUMnGx7s)6=9M(ca?-Tj;ue$hQ=cjug7Th!dHAw^;MreLf7lSNWUDLeFl!9!Nwc5*wJZoMQLD9yXO1+9l#un=iGh;ndiD{vT9LF^mvTItA zQ_Iuu5Gw}f;yzz&uHwcYLOr51-Rczg0#*SPgzy>gWD=ValRfE=fd#8C=7 zI@ectx%L39njIjL1y#j5h~CA_C`MT#56#t8;=zFm9KM(VDb^xIkXRsy)*u1d4P}^? z7%^ZbSma};sSBPEMz{+zgRcU-*wO6nC`VBiP{^nvdN#oQhJ@nZzZB$SWEDZclFu}Y zgar`Diy&*cLy#e)iz>D-7YcX-X3t>KKG(+o4%5y)uVGKey~k87wkrIyA(TEf@WUcK zch+TY1=JfG*7Pn5*|wCo^^!qQkGu$Gj)vp;w_hj*nDqYX21zkdK-FxD9&dj8Zf(9b z%UVLeQ`3A^^}es>o|t@oW8VlT~_eB%t$sm3tiWCS<&_75{)e7|w9>E16 zb=X4m?C~RyZwHPi8;1-ihHyeFt{gFEX*8I4g$m4HOSr$1_n*eT);HfX++A@iD^W|d zWL0+`Im@m!&jxgF>J(NOFiDOijaMcdF=^(#3(o#!YU35>t{dOrht`<&(*axu6H8b|neRi)o{XzZ$jxL23si27I8j zp%jTEfXxDH)Q3aGa<T#cy023Rswx7=na2-q2{V(BJ|TXSxQEkvq~5S6_!Z z6{dzVr?Q7CcvA~QHMSo6<{mAa_*RzeqPBKJ8OVSm=_rbHNE&!Z*?nd17IqS>3t_Y}QrvHJh`@+|X(wfYEpa z^RV@SR!ph7B4kUA1y6aD31<i%ku{Zi79 zZS*T$3A&*G-l!v*0YcRd7pd3~)pls@;}(lpw6*JwDM(QN$JTTyID4c|WMUe}7PVnqYg23;tLtuafajtM$PDlz147nr|goq%r z-j+yvM* z8Xy8_7ofuk;D(9x(gw%9V9OsrPJXP1(s<6|{SFeL)ZNpO7$jbBD4^TRt{#n6ctRNn zbVHyquuTwXk`IOmXz=vlI`O@fLc|zg+1waw0Umin-9gGE;bfXGk`41Pl0+d`V44-p zj2yx9--@3FvFmnoR)RcMtJh@%>n@t?kWnN(>GNTKnPpcVa+_!IDgpFSRW zc`w&TLyo1`!VWUFMjA^703#!4I!#5IbuXe$7?P~)e&2q+`K%13zh9a{NDdBr=I|tq z9Fo=-i}2?Y-!q~?EK*`o7}I35K-zaIqJ{R0HY7Ke0eaR2=>6iKpU20OEnQ)v-Wm7x z>Ouf$bbBPzN{M71rEHVDCqoqQG=TR-Kjr0It)qF2uKQOhj^*XhDPAlRcmyn{+IUIcA>^09>Z`7NYA##)}|B z72@fP>DYK8$7y&W`ta=n0i>DrC`n}iUrG?i0~Sdxkr9#n2%NXcpHjmf-VG+2^T^xv zsyTOlbG56Rz(ARcfGEu30V~tC<65!E9F?u>rOSyPusi3My0x3`Vz@C7&RNM}@E^kt zT9F^8cpz#V>dEUt2ttT_N%V(Roi`V3E{G)QKGdSNhKTn%))oLb<_OkPXtiW4k;af3 zHdsBBAZcKU(gzy45jeE#zVKn$&XwzpW71`)SwZip2Nkh%ZOFa3UI-PuINM;Bj3HPS z5q=8_b28t1U$zzJG7B9#0Z2K#R zkR6;2B$nutLxg4e`Is*^xPAOC{XriN;_RcMB<7S}H`ys76pREwB#_NTn2($O`UfYoQ=!#b9r_S zj!U>AmWUz~Dp}|ub3?xM;}k~(Q3FqqiEKfaC>aA8&b(Ch-rpMW zd7NY_4USL~F=F^MW(L7$; zUkMpAq&6BtJk)@iF(ZZCL%%M3;>_(e9O>j=Sg8wxn$Jedgmb9xMN5eY4FW-;$SQT~ zQo`-?WNLgmch2==W%PuZ<9zF}4~b!}1nz+ll8`p*z-BCnc5DQ-QO<8p?U8~s6IpNz zXo41&AH4)1AX5rFfa#rlwkg0#uT{F;@PV^X*JMy6n(+h-OZVJ9_1Kc6$w`eBgZccv z>u(kl6nXQ;jJv(0Fg7_&XzkYag*fFh5GHql#^k@G)oCuU`(Pu1Vn}3SNDK)BG_*v; zRY{$ZI#0VgAJEBR` z-O5s3Y2&_LYm=C4&wYepjpzv4h0Y>LG(tO3f(#L3rr0zSdv!oZXq4VD=!3G9a&hZ$zI_BoJfsRa?RE17Be2dlM2;)%dNiO51rLVl54M8{K6g*E!y$>`h=9qXo&nF^W{Wp~KdSuQdQ-lhi*t>og?v=cSC)o-U40 z5`i#n@7!XQk%4xxO|f1nWxhY+%+?WNko` z1TJ^6ThZ*fE+mJp7IFg$=JqpVaPWo>4;W42bnSuCS)Orv%-ay`HO9E5gJrHA&f|^= z&Z`*5Jn$pMSmP7U)|Ffdd!izs+z8U|#En6~HgKljz4O7wyVrLU*13Idn|bBU)(8=! z0OuQIH!oD4R#z3o#$~t8uPV;G9!ojolZ0(B=T#XbC8xz8q)Vrs&7@cOV1T0@SR7WD^;>}L51uQ1imAETgldyMvAMMdFnY$TU`;1ZXFY^xu{Op4*KyQ!t;Hv zXLssl_WDUW5_&I^)D7=gbmJ-OB+mcIF1w7F^y*zu9p#m(cNbUGT7te4iUjhrT>%jUK<)-8eR_o>=DLG)T% zB2INV;o7@w&LGEEMB`jOEi8#b#C481>UqG58g)B;ygpG~b$I4%rIW#p;NmNBSH}Lb z-h~}~GwvEQ$J!dJxf1@lf$gP4cdyI=W4|PCVKs&wvwg${Q4+96y2l}p+8+&lb+&%L z3nHSbiJ%P?1BwEv6!6dqIRwFD_50%rFo>{NFS;|tsHve?Bq$ntv3{`+`X~6|C@Bh3 zngU6XZ7r{cG5BFs7A#=ATajO{(h`r`C}w6(OAwSHLtjAXJ9ij%#eb>$wl@hvJ-el& zT4*vjB}0|3`;P5do^5ou*KL;O?cJ-T^pz-Tls=tIM^FpQ=IFGTd#4>pvRLvmQc%zZ zv-St7oD=v}zmsnFT$6W8w{xpSjY-||z(GG? z|BSx>;{S^oHPff1k)-d^Yqvx+YJNg}e+235`Em2vR68KQiW2%jv?)Qzdq?w+p1=pi zq&&nuPpI`3cSQZfr&HhA1axTlr-TDA0w_qJCWZ)YzHjs&(?9P+ZC?=%Rt1*_Qg)Ue zctfVJdZ{XwqWG$_6%3;$*N~zaibnIz*gh^@+pVnpyRP5mS9M=MH}?H*+j`kA(_?LU zwQ{#V6>{dz)z-J|Z>_$zpE}+rcTv4cypChUCQ8hP+dxs&87t_Z2&%Q}(YE*A;b+@- zxUb!O{oil4-*3WXrIz-uYS#O7d$o(Y?qy9A>Ak3CcvFCZ)6R$Ze<~Fef3qy|r_#Es z`m8!AvlK*;BtN#kP{>kiKYpASMvDYa6Y*E}Rk7Y1Fxkf&5nKK%v&}2L@fwWr5KXO# znu#y$V#bmtB1ssVLh+Vxy8Y;Tc1HK^y}$K53*m$swrac)5PA>fkbYR@RY?Bve7}0Z zj3q5%s73mJhbpQdf@G4}miKhJ>-Fy6*Zgkup6%bux=Y9~3>4Zx02bbbM3y(>0r?V& zbKf%THzMQV#9>_ILkv>=I?|A8+Vs< zcoXE`L*25>Z8O>ts;{@X=7eBg1jpSc&D;?S-&ptb>s&IzQaV1XMw#WzM5eKDipX^~wJyF)hz zf8o~#|>ChsAB-s^d0!0IzvLh{;4A36;5tj}aVkko4-vai&EYc_Ybk5b&Azjt5w3 zw1GJ_P#qz#_##a&at?FGVXvQWXN?{8*By63$t911ARP3XOW^^M1OP{Tj6jM~G{W(g7fOdzh!{v0npIXj5NJIlZ6HgBDEwcgO zIPiG9VO`R7<1t)Uc9Jt?ZBt*yRG zmxk#66%ARH_>08QWzR9>2oHvm88vndQ!D~GH2*R+wL|B$hSN^i^|M;oYN7geG(PPT z!3>9xYkC2LbcM1zVRdX+AC&o)tR_;A1S*vs)j0xR$)OBPKKGF@F>%jczIx7E$SrOc zJuVNVwPO%N~BIDxFD zP7QHBi3!&97KrDc9L{N-WU>M`A;|FA9R zED}arWD}+F*$sMwGBM-`{dmTRhl;GaB$G&lGfB}K+E##ofNNSUKU=dIBmma=9Ctds zmOJ37DT3*Cd}Vdjux+=ZW&_#cB8fIetEVTr0Y_I5#3X?p zrCA7r!J-4Psnfs<)i@-8MO6EGy!2RW#*~UT4!Q_e;KBg+pN9b?(D70PrAo6ijrDtt zw4LDiby~tqt(`hsm*`{)AAw8hU4S_{K&EMG zlBA$&k|?E#pk$;eqLPZM+rPiD!l9?5)imM`-q)X;oh~5H$KkJzWMM!-#g1Tcn=b@y zZWhocwYm3%FE8+gN=A_%NI)qJqM?WrGu$T%3J2&qwfxl^e^&o{-FG#4i038Uv5Zy` ztUmAu+PzUz)c9rx-w5h;7-nHaPyB3dVSy=%|3!t2$V%9$%zIY8g5qfEV zB>h+wN(7|mgZRiFdHg9VJ=5xCl=6F@ocEL9YrywGKzaA4bpeP~=h$v|&m}oyFcq%+~v%H2$NB6%6 z@o3q7Swr&qmuz6A?rq?pTgB*!du^`Re;sTZ$i*wT+o@YDmFq@CMF9p^{6IJA|C^5w zo?xRdvWQ8=3lR|b*?|pduYyTMG4b8nZLq=CP#BLKY{3`b?d}N2g?ta@$-Z$%SzkVh zHtw~{kg5v>pDk56D3`7sYKV#EZ_9cLMCtQLZ)<$|>}IN?X??Pg6i3TKB5Pw9Y8|M3 zI!$Y1&`%RimnQr--o}xotRL)^1%6)D6qzWC_d>EJq^P3koA=yU*%Zl55lu3hyt_>% zlWHhaMWZCml3Tj!WlWlpM5S+cDk*u9F{mL;n8sot;Ea&5%&tB2!+Cw4rtBZ?r2$1q z3|Zkh%ZLPvLP%r)uuf7da4dpkf<;;+{;2PGngi0}cz`m0EoEI1hlotKw&{Q-vk=}M zhzF2pe8BE}etz2xIA}1*TSb9aOaBZU$bUXF{(h9y?e6VV^Bm5KR6*ek5*lW2bX*b-&q#h*X6YQXsHANj&x@^}cyX?WGRvVL2{q7U%o4S=g7gG3L&W z?0SRpyhe2sG2TKn(|}}FEFoo<(2CCWY@zGwCfk#`7kn@tDHtMtPwXU83xH4O`Ttgd z;GbxJtoPsY?nd~TdEk7lfKdQ^UpJ?q^W|PT`|09+ z^=Vlr?6M!+)X;%1&kaw7a_bI0gU>s7xTgaWZMU8E&j%Au`GMvr`ocNsK1i=0Tz-at zAG^@`R4=^b6-rRA0(!4s#Nw09E!(=fm|>Ka8<%K9n+Rfwi9ZjwtKN@)$Q}c{J%PF& ztMWDQ5TH2U*rDoZT%Ya<8fVe z*KOB3cIRhY?v=|+L|cA(-B-W9wOxI;=DJ9094VlpNrIZ9ozyG7^wdC^&WJ2R-JxV{z*m|dN8`Yy`o{Z3 zBC3eRfqs%og6$HuY}LZxgA#ZnXKZm`+{n}v(MgPWdp(xb$gZKq46fonf?ybS;9Y zu*EPUBY(&so5w4dKw}nmy5#GwQO(PREE|75kN35ewJTP(#cO^358?#`9HCXgU%)>= z{*S-U>+lKcJn69ou$*{Pj01I@w#Y5ED-86*+)p9y;s$q3rMbqH%q&AEImjf*Vj4v7 zUg$c%V!wZpUlHqV_%8$ogX7*ZLM+E9?VnC13PklpKG-4HQ{WKTM{m?I*g!TcIP`Tt zLorMsUzk8TPgAr9!W!)fF${uj(zH2U4CQl@!oB@jwwX^H&V0RKu_VP9y8;=DYYhNiFfGuafp7! zD;L@{#+Xg5dvUo>Mxh-65Dd`U13;%k-)^R6P9<_e27v;ym`RceW@5x*!ggXV&;e1@ z8a_`;17?vsK>)UeGu!F1AWLQnOJoXQY!D5yW|JEg4e>oq1avYJ46WvqiC-kUov}6! zrh_DH>^(EmPfjynLMsY3kRUl=G+1B}BsesNu;DPdwJNVuuvX00IY$nsPw8#i8 zOOE4f5t|5Bq$CHI1CzT$ zBJvzyG2RTZV=GffXy|FQZNHHX;>-x{8Z19P^!$E481|+8AXz%uS}FEbKK8P?LI@0| zBvOkzzMzK&QUxH%_9AjL&YO`Ih+IrlM?vQ8_ku|G#wzQ0DqDK3;q@tpfs-QVNU)x9u9xy7KiSN`o{q zA@G1f1d(pH#mud>fgX}+76=`N*nL}~)rvC zixz?)RHl`9!}1Kp@{BZepRMFf@Y#Lf>I5*-`o+So`2yM*5F8^xM+lfvP2YCThA=}O zp3BclFE+zEfZx}h$SQLb78ky|)ag9Fb>-M%Z^VL2UtLQWg0w@_Mgpr#RhMMdQYb_L zL|FqkVw+LT{cYbTABT(CJaM0wD1t2(v~8&7Uj0u@VPWIxIaM_&|i6DoUD# z1OQb6U6n?tlG3r}o%E{5Dzu%}7e&)-(6TL#uL8rKd7+1` zH`cwF@PTAut0PGZUa`Mdx3pe_2^38NNd%%cN3cm^%v5itA%yyoJ}&-2xVlt5VG;Ax zu5`P(TWi2&&yWvnD3c<-95q}cc(|h#WEZU6!N+VqJz24ZDh+Rr?BNJ!UdJy4(#z(N z+LGACz@UUG!WK2sb~{;hoVecI#$=7rgo_B5W)f4lk@3>G?${VY#RzQ?tLgh=kIuPb zaXl%i>u%EQbhJv>63$(}`;JED(Igi)P(*0C=pEvM>?>FGyYv%Et@u)vZT6+Z;qbFVxmuMF%rh%nt zS{hKK0wt7@lf-xF%332g9xAr7Z3Z$JBq0hP3!lKgiaWdedx(arOUiJ9B0?abnwk#m z!lH^IC@1i+ZK`rWAe4%RiL#<&2*^UsDGXCgiL86NLJCIJl(5*1h?P9G#ukiegp|eZ z-LWW2j9Ml!G66v|4J`!={9wr*8y(fF8~e8%eeJQ?X8 zd}V$4)gU~U4ioXZ7zfyHh6+2U?Gh9igZfkn5}wrfp^#cW!7vx8igyRUWlg;6qt$_` zC}=5S0HH!44Ujw|_C|sO%@B-3g_-h&5)gtUqN8u`1_nVUu;W9djtTMT!*oq-1n?rG z3@aNz@c`s93RLbsuTkTg`8-b~VszQK0yOsmh6`?J0Ug*P*(%cn79*xWVMf?NlDTkR z4JTWw8EAqA`>cE*b`k{iL^L7ugXvw=ap`(fw}9M0<~xZzptuSL@Q{d9!x6}tgwdfx zvM-Oe5DuV0a#1(;eSfR3yMG@G(%>qO-2wN+k5tGY5WI6UA?~NNU9)TMQ-UaqI-kuy zMYXNHn3)_FLw=KPD!Y-^W_k|hwWq}W=JJl)T!f!`{|a^pBm>6rrC6zs7#~OUJ^9Ga zbY=2Gk_$LIl5lKV&R^H_v>FL%iji*g6NxRN~{_8?*q-kuH3 z#7~UTnD8kGv(;09m~D6gZBAUR$@a#5QO&mZ7uqBE?07=s4Ov)9zNka7~#PASsTG*8| zQ>8I6ov#M(eH0y_^S;4$^zQOR+xlNy#wnzo;RKmpy8>!d}Mbt>at0tT=I8wvGA|D}En3pt*3sxOgF0{dO$n zfkb4UTEYP$Uz_8OA5=KYN>Lm}2xdM-^C?!l%_M7c}Qn zAx}F{4C_dOMe!55=2Va8}!5Vth!u1=^G(uaWV?q0_zB4 zdCU=xq+y^Nr)70=g;qg@+=sC=Ju*6cJ?O3$y>or)^l&-x)XBC z!)=YvqffW~A@?`c_HT2}&h-4-$?1X4^JCj}ozH4wV^Ui04@79M7(Ma>UG;q!JLvq8P zOwb7cxlP=7Uyt%PdYE4l_OjJe8EuyU_p6_p1 zXLY+0#XD5GySSr3fnh6U=V`2RDwc~YG=ZOFhs+bF0l;ubZnfRpnjLB=ii=|y$*Pz| zm&e=F#WRf0vo?;L^P2SX$LfA~bS@+jtm9LNtJF?g+!HjO4;dT5-T4=y_mVRxZK(oS z6o9$w28H2ZaPB}hl=qN%bwF!>djUR{by?iW9Nw)MuxluA zXpImRsw_(<^7sVGBoim`Nt+1`@owOZ8KePBJxKLo>VtPZeZGHK%jss; zue;!}w<5UAEkzm%0zOfYlu>hL>zB^n- z6SG|B^JR?UJt3t?g>I64+;6722C3yTzM(zvp{~V9h$QP636rL-?aKLl-R$G7`|Gk# zJ96Tb^l0bt^-rYl2K~n>{HIe<@deD0O%FM0NW2b-YH!bNjmGG~50@-KTc;_3~=}rRVFu zx34*GRrXqdEP&%9r(my}AQ1O)SN5TN2l4dBPsL4^XS|dea zBA|wj$f|0yQWW&V6ey|(&O=b@3dA{;X~Z=!OG`)O^#DDr1p=T%fKr7hG$GTE^Xp?p zn%A>)>O}XzQ0HHt*5U9JJfRW(No%dOaqhh?S}||)xfZ>awehv)sw*Xv6(wzQ*Hcx? zUGA-1qg6(d)+}1B|5@JdZOvO;@U?YKs;2qYHHxm9(XFg%KDN&4tZI9$sM?LT+_9@v zTWNQFYP~hnY*(9CX{}zGi(YM4HC(DSb6ncI-fgwHswy;EF>5B;`PWvx@ziSOw@tgc z=A&-*?bl7l<+M(_RF*cx?x%ID8(KB!LFbLzA9VP8!-;mLma5Rk^n| zyxVS<#`n54a^G;4D7)~_ph=GQH+ExG27YY|%V z_8XxkQpTAw=B`R&_tYUbC*t#ev7#?iT}bfVFXb89=c z=Gx|?SkbL=xnowzQEQsn*IeaQ=8IPIUglQFBB+kE$Jd~I!c zUTTePPfY6H73aIFdAY55t<1LMo3&TQ)p@Trii}iy*HLdw{5aLWF&`@W6aVN14={zN`)4`r7zRo ztzO<%U8Y>rpOfDed&C=(w(}*jYd_c4*Da%1v1rza(PAx%(Sm}6p=dy)C{orP(Zo9v zhVZ#7L#xAw17cIA=!3CRfX!H~jZs-NTXveQT(*>mt?JvRx5fM4Ieu?%yL{UE#>Fi( z6wpwVfk=NOg(H%QkS!txT}t*2VFHm5Fde;C&R!urT4EwLk)fj}jL3J&hwX)y+e@Qx zc8BbM9-u7q(iX5h+eWC9L{$|qBO6BAG+P@Qv})MVtrbP1Si>xpjcfch>-YCv zHFevavs(UjYo^(i|5a;Hn{I8nv{pB5^{CQPQqb)j@m-U>K|xDPK;b7)YtNE|pmf7S zb{*j3EKd7^A{hX!03e6bRN18=3qS`@29fyud~atzEspYIU9bW6il9$z)$m&uA_z1N zN`=($iV6xlZMKWQ?pyegKY!BqZ)>}&x4peDa@p0}a=hC1^Jckcbaq_nUEcRO%lSL! zT@J3xySutOuI<@o9oe~j>Uhd*rJJtXv3BK|dD`j?mev%tsd~vk!`Ru4h@hovGf-_y zXsl6slbEM4<5@)p0E?)4%+JDj#1%v$E_~I_1r3QN3a>Xy{4U-6yIaKsIw{%*w5Onc zjyaL(-C>!o?Y7$FH`bf@{+;-<{BE5mVv}yAB{z3)T7rU+Q7sjJe&r()#@i|vyKa_@ zyRJ^{M>Ou}b=t1F;da+;vbbf{*2K)BG@{gLqTtMTCwnI%=Qa*77fAYmrh1#h50 z+Xn4)IOUdfjN;+;$;7SdqA^YG*6RIb&T43}x9zs`Z&6(;uD6wbGP82q1#e9CtG3_W zuf5Ij^|fO~sH|;CpsFOaV$o4!MoKBAp$bxfh@j*S4kCgjVhWR8Nbdkpg#aHAnFM5% z6{OT^2q-HV-4WhklnxGxWfBg;Zc4NgD-jyT(Ipy+(R`|QfDZXV4drzLWPrWsMM*&b z8c3odW~Cm}pe|GsZP)n!(n*^y-}=3(^Lx2Eb1vfUT-qutn%$Ny4yTurn8<}QC@3n9 zYm`*2LRH&lOWU;|!zGgLuF{@l$;l`nRj)4Y?>j0s^wrWVlD*v+)l!>Tn1b-#OM5Zd zn35%=F-_@ixm>N&mnGcmrPX!Iy5p<67gMx_uIrt-uB=^ma^2eETGEMP3Kc3_XrQXm zsj*hc*L1y|a_x2347t%Hq20@t*O#nr=-zKOoyO*!+k|d=)yT0WwHgXGqN-(~Hs;|e zG{zVgmu8gq?KJOpU2W#PHF>UW5u&sjHr?Gc(rS$tG;Z#^x0zmcHqo?Q((839P_(mN zuH#X(YF_Jv9&*xWxtzJnM%dT6*6E^>);2UAmjf~`UiH{rR+XtrsDn}388aJf){#oN zRd=0esw9gQ3P4(*i7Jc}P%;6SWCFDU=A$BIkyx5;?yq%pm^fTE^QKWL=DSSh*6p>< zTIF*uJ7+g7$sKNct`x4i>Xn9oo4S&_r&8v+EcENpyLH@lb=k@jy7#(!j@Nfxy5l>J z-F4m5bsM|5?Xj)bI$gCyZHg6^i%QbO5yLTyX;L0Q~^UDssmoqMa=M!9&Hy(rCBG+N!&-4{ASTz5vh zyOeiM-OfhqmZgP8qe(+mn?-4nOQlfTy+?N3sHnwJh?%M}szY6L1etra>Dk!H9qZfP z?#rW0t_ z&0O4;+ii@gRY=M|*uz_-_I>{vA4|Ot2@s)9KWL32QA1X>-EaA=+N&Ze4Ks3rj^q6)G@_UPzv)4ClXXs6Iqd{a<8wBfm6j$IOtEFsJVyM(=D#q1hwxqQMAx6B~DCk)V{2&JYAv=lw#M3`s>Q1tTG6)E7PX^licO89 zYa1J5M$w|S(XEXb)snTM)f%;ptwCBK)M|~ZV%EhGwHnsNXsc1HQMRfos~X!ITNM>( zv|6!RqS}pZimeukv{sEpZAP}ywYDv>G_|yARBDQdwHAt~wybLw+AXYFwkX?LHMJG7 zt!TB2TN>IUYBg0AwMkV5)h4wYZCKc~7S=^AsH|ISM%vjnwHBg^(X|_26|_}zTSaV^ ztj(emB~{9+oAl*vjl8wD=XSN`+iqO8*)6s<);89RTW)Q)F0wz5XCYfx2ermB-|v{s^`*EXw`HrlvaQ)=d|8m$J^7Uj9CV^M5YEmaoVme%I1 zYOWVHsJnR^Tju;$__sj>>)A3+I1u1Ld6tw$l~kZmFw_Udkw8A5KaD&HB6RjlMC;Vd z(V{cIm!sbAT~g<#ZF#a0NV7WBLs^G5gK8@gL`JuEab-2vaHh$kojTBLOEXM6wapP; za(8sxja<@X)y-Vo+$!n0QN-dqqr0~$VRIKd4X%ZhRszOIxs<6kr4!ozHO*c{lQRfa zbz^laYl^dVy7M-Tcy`yD8`K?yJt6NpeZFXul-J4e2+i0~~Dy`i}P8G?_ z*?~{NV#U8jFLQJs?;cwGMx!%w*{9y$JKgubF38b`TPA`T3FWm2q-Fr_wBWsM_qQ*< zPjdG)yWJ+gj`yx^+kTr~Vq_uAoQ7a51&3FuU-bJAp8R|}>#x&ub8j{R-#eo2>3f%5 zCGM`;_Wie8<$fsXu`2UjHi`_zGfGXh8bk#6*z&CSrzk3ip|c0*|z zP^2PJIso<{h(;tzHZiF%n^0OeZMVfysMKvn(QS)GV_G(gV`Ecgi$!c!NT}5uF!e;Y zJw!=O9EU`W0bUVK7o-g!(2Ge*g({Uug$jX14G2QNRt#$Q{eOo>J#U{9i`$c+;R&A>~T_Nosc=x*oB!0iaSY#OA^wwtP;euQfh-2 zHFD+BtMA~J_#p2|KVje$<#^pRs)L_ESH z)xO_*YnyL>8)mBCEBRMyw%%6W3hYftnzF2$<+d1JuWbfydaD z^XButeci+X{`ULE@|uG%%~(L8N-o3o!_1yLopd6-=j~m+nv>`O+eyY^gOCwZRY1%n zNL;GH>=-+KRqt{*Ju@Aw&8F}09`?I`Lkr%zk(#+)n!9(<2qxuR2%9Sk#YzNdpbh=l zcj-hDa?&3vMjtvdcKmn8@4N+r1lCnj@? zffn&jZx~d>P*7OCYPj*x%qI+)Diaa6yIyy$(o@de-o@2+&nb1fs#|CYQczWhf|435j~r0PjwF%EIiiQw#yX}t;X{lsX2|OTN_N|-fagZ6RA@$&P$pZ zx|w{}e&1Wj=PR!4nEuuG-1`wY zG6vAC2Bi!n6Qmo!8*3fle_q&7XH#6fjxue!+v4qg)wz7VwY`0;{_6j#qY5etH0j_x zMIWEc@AMS+B6`4+D|Y9&0|*ghh9qfV{Tv^)`~80%apS?M-sn{KsH4_Rp$x-99ZAW} zViSEkpP)Ump&AU&mspy8k(GDZQ2{n!bJ5MC`PvW9qf7M?4*yf|38@3^gb$c~qHQo# zgi}ETLZvd>QMQe!qgb|*vQ${V3^7jlGA2lAAf|#*)Q&>YO+iG$*Xl6Xoj-m%5v=hX zQ;UHs(=xnu$ZOO?@FA+DDvD{Ocr)CI@AcTjEdU)V)zetJ)Ef}w@}fuRTVF=eZG37ms}WuIwWO=cx9MA@USn==o`0LS zi+ott=D+HF@9B5T&h5UhZ%uZKCeYWrTIF*2?$z;YmHKVv<61LZizdZ=YUec(wRuHP zcfRocowu0#?%T~9M%8(>xm*OS8_TFpvD$gxIENs3mFYT~H4dWXTjc#Uu4?)%v1qRD z)n67U+U9$s@wMf?HC;+fTDnlkC{3q{9Y7Q&(v+nu*llyl=GfTIx+`)`Xx5EmYZ~a4 zUs|r3yw=G<1dX|5mE?Um7(EU+g1JC%iqfl1(VU7>miIxf| zf5mDEz}EWV%6$6%?6_^f((*{O#58jD{rDQ%PUlDubGDD-Uf0H=7%RMPf!oOlReZ5oFVt2!;f(X7CFU@8G0aE#mk3w_m@P zeQRBv+wQ)1XI%de`EOt2=Gz`a6IZWP5==!^&Q2Bq5k;3bcl2KOZd1Fvw>$oSUhx6f~lW;q|0uGk78 z{ZH0*V+cs(ARKyh_#lx_Tm7>m=f^Pfy;!5`p9acg)1J-0et4(&^=5U$_W9_1SMRqS ziVQy2W&`#5svwiJ3G(p_gn8mUIev&s$sFU(A-wtmgb^fh;oF0yGFhDi=CxjdSA~ z;su!W&yIJX^;<$Z%{mC#K$c>6+k$ifErsK>?$78lp&(k$yo&+&Ehr9oRV=&vgNko;Cf>Mj_<>a1kcAl9Uf1h zR3Dx@LtP?Qb)(T2*k`TRTsw83Q3}T#{{E%>3_q8iIwb}G`yA$J!t^!K+xgGJT+EEy@a!o1HQ7u1-d0)7w0Z9SaY%>1iUQAH5hqPG_aJ@ zg;Q1OtiFiD&SIF4QJNb%^jvL88#Cw6S+;5gus{fm_WVH@bVwtv9qJ^;Iq*R-k&dyt z6T)P~NFYAd7nBCiMYXPnjow=$M<%NC(Rp-ThUVT_6T-XRMm@s-g>I)AvH|s|5a87WyinIjN$_>J7|hQ> z=A!FGsYpBFKKi|CV^H(auA!V=B&|@LO(G^1#Z%*|#9&lDQtV{}U$qXkZtJ|-=+AlK z-T+=Pr$mH+-u(08sCEG?afwQK=bs%vF;f~6G3s1E&pCmNi#c_oD`;#G)_r;dH+%{{ zNOL?SopO|G+=JE=I0A^^w%jJ!4YJNmrVJON@m0hh8N_de0XM70pIoM*OB1|o#Gp)< zIwQslaz%$+5l$De!>L@->bm6*B_XlR?QR3mxYOAaMu)je&HBiGw{}%|gnH zbXs>)c8472I76&Ig>{j1SQ6Q{5W-DviT2#M zlGvv+JV5m*4-+98+Bf+1N4IARY{AH=sBg+lW}>1gB4R2ij_|nx8(hG4m&W)sQDopz zgbqVZEjb3GOx)seE7x&eK70Cfe66f8s!!LE(4$z*fLly+`8o&iz!C@8ao;8E4~edV zSB?kl5ZyYub%>8-#&+Yb<>0MJq`2~>bfNm$k@D@7DzQM6Q1K+qH+KpO}jssrAr z9wFp|2OJb7Q9-i!QT%^NC<29A1R79+&$$h#rYGM4RY^s6af5SPnKX8%b*D?aySFyo zA~nl(ILn(uEfKjD(7AJ5jdynD?(Rff>$_jyHo8}(T|-AMXs+&vu3Lq_ga;|DIw|8o}M=cf2UENnUHI8#e*DPB` z+^2U+u2H^gZT`8t{JUxIK63n-Ra|-wNzA4P$dCJPOn4v_(R^DEODiImFj*P z`X>GSDT%c#C?5$0kWYxO@en^L45Cp?m0W~C{IgJ$`M6_ru2t4u+N-9vHVviOuFa-x z%I-DCV?~OXM1cxYM3q$2vFZ2-^D0t;%}o%M zR768fAw*LIUO+4CNAMqp!SYAmK^~6cBjE(b;{+E({t^|$m>_gOKUvf^VVF1!>+)Dd z>MqC3`sx};zMo3BMG*2r6dig8-_TVl>!uF=oa~;Ejz4Z0R24%-5hdFb+Ptm)#{*Jd z*j%?a8_TYo{BIac(xcK<(FpvY9wZG)fPWMm8sD^U+Va=!zBfK9{C%61%*d~IRqovl zn}u-A{55yy&UzRsZd?!>+yE?Zf3rI!q2$Q8^K zCDt?L8?E`*yWV?#kM8&xpW|vbTquq|q>%opB28D=d-s1B<2-eZBq2)?K^N}8;teEd z{Nme2)~^4r7jwVv_0#C`0lbZn{^QTV@^9R|6o#|3+R^Qf9o#Vof1>wUz_5*_8c~#@ z%UTOiuS=In%AMF9kj}|0`Nr0;H_Xw4k#-J##SB-Q`yX!76Wv2$SEK?RqLZhe`c*rbFc`xiZfL${-4a061!@i5A|JUe|Ts$@up9n%^2RudnhSRyMWg*5&0~ zsIjAB)Dj1*hgj(@(!6E?v^j4NSQB|xwu(DTM-u9xJbWLC+ws8G7=+=8uggC~4bN0P zpcAP@^pD(q+qRL|)@_34D)^|qyS2AXqVnk53v}L?(QSEF`}eDJUw^&%*DJE`=IJm< zD?vIY7ztni82x3jc$~GA6BI+BzOhg}VN#ZXP@oC`Q|$*(jUpKt2?ymNq(JI{D1j%{ ze@8fezfaq+^a!GwBuJsuj1nRyks&2U+jWR5G~O3rq7q5x-F(D0$MW8`0xXSld|S)n z*_R7KZ@15WzMy{N)a+o7KWH!9%iv}M@~J!HASnt#rKARs zqL8A5!)eMkE9K{-Qt<;oOr9Z-sW}ZX?T`+;L^}CF5(*Jy7{N#*rbFCzu$i069$W8z ze7)|x+`j$3Yj4J_eW_pLCbs6Xv=m<_^r(tHXHi8F6%@v@1t0JLfB-!FZV#wUue1wP z;m)kJ7F(3sq{_?98@oXwFoMBr1dE#um`MhKpoqp?r(c(H!Z)CTC>26c3|k6GV_5{u zY;3n?iXh!+WIAl-W8d+)%+zcMUasAPNT{i81ZE-qd8w9*P2sXG!nO>o^@dJ#+46)~&PfBSz$8=JTx? z0a*)f<6|C4Y3DAw81N~RiX5%(f{urrWAWqX@3)-e)KP*fA`jJj?`nz~MvhMBaVgha zf^8wK`k)$)ID4wM8j;^<5^~%%=6MS7TpRKE0v}Ac$bwV%-&sIfR@8R6wp;8uorSRycWlhrM05kP)liASO+o&iqmj(Jd>dZKu-wcqt*}) z2pvyY+R5g~a!ni73$*DC^T#|LmvG+%aa^@yaxQJTM%8}m{uZuZOH?)~{U4{MgV|jt zjbwGlYejiUnTfoe`(hsc{CoTy_H~L%3Vh+hGE5?x3}XE4ZY2}<*PfJAmD8N26oMoi z*eR1t(pCx>yp4()L(al7#*CX@ZciC<$d>C=g!;DIdZO%Q6>n|8c>lLuf2A;SII`cFRSXT?(*|t899{* zq#rF6$Yy0m3a4tF>PV=djcdL;Zffexw9PAgYsxC$74alpPIm3~Hm8)tn-dU;hd;U*c3Y(m#?%bT2hKqBpO;l zZH6^MRy3BQXxc1oVoPY+H5(Su8yjSkCX*V7)RQ36Qewo_6mWA5DS2Wa#-4!SZ2`)A zLGCmV&|w01!9k1xSZ9GLEVA=9J=4N)iued^u}1!S&n-J-KyAv8qlL!CS|tjRQ)(-K9u6lB!TP?!|nSMIBy9FK^Y104j?4G;O+!sP_d{X z4#B%jouonU40;0yG(Zb9Sdh5ecUfPP*IVz|?}x1%hR`voG-nm>0K%|X48yQ!83UAv zl7v!h+?u<5zFK&CZ+Z|91czEw>=e0sdNyW97HS(M)X71CWE;z4CpM(Aglujt194ea zRFRXr)n&$RiWi}#CQOABO-B6(l;MZOEApB7#V5&rzHsW#y9!KEr-)Y!#Z|MaSe4R8 zb~$ipjxdD*WFS8!a#J9qy|#Iqk`TC|%-vBsr9vlJCGaij`7Tz<9?9F3CMi;jGtT1=Y$PqK4^VELhomsjuD9fUmYTK%Y>5B zl*kuygTye38q%R=sjyRl??W>JMJ6?w{I0_kKpC^pfu3Dp%noo8GZSp4#4I(_basqq zBC`6JUL>I6S)vCb=CUbVB5P9bfF(e2?Xn}~=H-ngwXuf?J4Z@_v>6&8n%E`pI^fZs z9$&f}*-we!-~ou+O^$tYp zdHVkTdI&F7^6q^7CD=R1rjd zd#}aH53?Vg+kJk0>h7>VvpDJ&*mu`g3kQmdifhJ+ghOqp=xM4VA-hn^j8+;=3j|+v z&$QMBKa1i%1z<0sI$6L9dW4;s| z@?YH1wkG+fa#OKyAIn$)xfa+t6mKXCs$40Eql{~=};jZBWxieu{-7-wfVma;J_|bz#X#M+ayG}^>=P|ph?}ydBvTKAu z_DGLl*9+!K8xu%+reIRl4*PejLBjfVD?vbF?07)+mV(CGF{s6;*)@%eV*9PhB2s1~ ziXa*Q8@UVGAwUc4lNNZL_`u+W=vK}ik-3yS5VrSDz=TBz*tUJ6S=T~ znu|58QGlpw=eq0G(P|^s=DOoT#w6J&l1QTk7A!*{69l0o!I6k)5*aorH!f|>#qPVi zyq&pcb=0LSlIgh?+`1}mz1@1@v{QWUyyzfJu}$U77ntSU($ut$m5S=R>bhIIb%LnQ z=X~z$^69nBc@`N~>C1CiDizZfNec-zi+tuP$8D=$*DI z)yTDyqTQ~wuCrrV-d8o1ucinG{Qv;*@3bM4D(3QTH$k81S4 zx6ab}-7&WKlU&~QuDgr%>v?=w$2R8YHdT9E%YUI!qSR|eMlGV#D3e+%wO^>7GZ=PkFJlWEAW%VVX;L3S{UqNd0aSXh2t=zi=?n8*ySuvbM z6t*x`kXbftnV;$`9fjtBgCFbn|0|oLJ;+fdJ^E(YxBS3;5`8!J-;@*2Y7ydc@M! zWJ3riB6vavu2lG5Z=^OU#_5ZC58DuV*7C{+xtsFEiCFc>i~9gROZ8DiW~*!snL$OLacd2cys=Y^oU$!WE0SJR$;K+M;V}wg~DgzG_{D z!lru%>8T&h^Mqht2nSkV1jEC?U+jr|Na`y%tV7ChAju%Rl5$uih8!CrLpuv8!NyL0 zGRJEf1F5a%G`M&qMX_^soFeI=)$U&uq)F8vi%uV+&60l3R3My4NOD_35P(ph5b&cm z;zT%k?Qz?9-iA(!jxQYoJ5!B$G|yZ)t6{&ZxuLH$Z)Vcw2V}UBp<0q!9-Il?U1b9X#1&^IXt(|0)p=@#=5&xTT5@7LGGcGK-J88*IVYJg%KZp z?qVck7_S1f4qo(=+P6^kLUe0z@0@cnNL{cR*) zAQsYxtuBO-_)gx@>!GI)ney?_rSWM>S}yZ*JEGbQJ7t;;=BL)no`S%($VDyqtZla| zZkDU#Rn4~b?$xTPB&-843Ak)`X*oF}EM>YbxYkq=kwvLkRvzl$w3f`92~))0c8Z!& z3WY)P*lT6!>n0oB)NgouL7tuGy>|A(swZRv0t^&n)!`J$y7#Xlua6$yO{wVjzF;3O z4z;C9on~cr+H=nqb(==Zdlc2Mv>rn~-V7C`ZE7;U)5oLdo7a`r+WC(YMG*!Zk6dM? z=HwNpxWR|U>g;LfTsO5a+e=MsyS3nGtIwU+U0AYFQdErIASc5ZYi+(Uvwk!b;lDWnQQfoK6J0+c<(*otZU{g;y) ztwx%~-G0}ii=4gPcWtjNzWleU>h{~+zV`7Y}_( zHcL$=Q{8TIz1?4}U&&YBv0?L#8X~B*Zfsi9ZF>Hg3=s|yb=)7IewaEokoBklrCCKp zMz@>NuPYd<7Ak-~T#g#&)N~r;`y|}%8O4EFG{jWW#Yw6t?%eW`DEjD{ClFRXZO^@o z05e0f@n-7@AQ}j<03Fp09yr)HJ6*axzy_ zk?BxINO*Z--uDwBIeF^Ke{AF$B{Tg>szD~{YZh5!IrnyF(jDmro4{v>t=@+W@ z_OzO%Qitp@^Rw9v@%s*Z-eYkGFm@R_O~nq7`yi)7*S_zRH0((Gj=PE+%2PzqvPQNx zD`>TX#xzxpMNw3mjU`1!i){w0t^QiB{Qlfgjb4@N~?BhEilb|f*3i)UNAAm|{Cu>8GVzV_9xmRoBw${}v9QerpQcu5UzuYWVam=a+P zzLT+)lD>8F(wD1on)!C~yN)fcZEuZ4=5ct%A;LP>j-@j0vYHV^N1ISnb=xKmFPe{v zir*=Fp>7uWt7{^g>bpClV1|y|pm~*PD@G!*V$@?=HDASY?wTkmpyFQP>w~ln4N#>k zK*bFVSQ!tADnJLlpM&CG#WdA)c%^448I zSS&%ASz0w6WvR5os zpk`W%Z9XB)QA03Qg8XGfK}XBx^S$0f7InFIb?SB1x!6j<_~`hM_=T>XA~6oNRaI43 zEufSL*bDKSHMIHSP~SFCikN4Iy)2xfwd~KEpPov^(%bIXx7G8pt5TAPt+FFq*FGm1 zEi*eUZK2`egqxWf1=d)ddDFf=yb0EL=Sh!2-O+F8t@j@Yt;LZVp3&0`gUU2~aDaN^9U?+iTFZ<+d%gUM04< zUmq61qicL_YnHoxSHAar?@q56T3z1l?^`q3a=#kf)$yA;botAB7REK@*tPF>>*n8< z`JZd2ehb6w^WF$l>n*aCjVN}Rh++lESY&ctn`+f1kV}dKXec3&x_jLY3Fn>O5HE%1 z)Z~>ZdKiG)t3`_Zq3_EAdGEUgr3#>eqjM^zO{&3Rt&-Z)7|XS|z>GvQD=eV4$}sm{ zZ(HWsJ~kO*_||RfzCFCzhDR2fq^VajY>n2pm7-cwD_JckSTh?3PU2-T8z+iZ5Fkm zk+#;%z_%KV1|_3vg#4kkVx5%8>sz0QZY+jQLm;Giu;!qlpoLKhnlc4R%q2);s2r7x zr%N!$1J?&KXX)e1%&XgXH^5<$7*v@7#Ra_9>*rTaYkZZP9JzMA-pa2qs2EEs6(G9V zmm_j*7OBpW<-6xyywy7OF}Ynf_i>C+%%-m@Z+E8LyZG&OpF6dh2zW7Ic!pu+J0YMl zmUDPyb5Fxi`%gTryp)r@uufP3X82qqiW_> zRKJI4EmY;|6_G*BIWvSRwUJ@1fM^2R(>c|ClD*R84Bl>CNb_&4zBey5^RCEabK>D{ z?c2@uau1KMz1HuYqfYL)Xe=s@-!V}^>rzz`BjY|Ny+_J>uc=@Na27)Zvl1DLSgSlj z$ZOqlZLWnnlBy^uXCm__Gcuqo3WZ^LG_K0l6f;%RZL#rJFHftbyydT|`rqHgI8bJn z_O^IXT%Z8p9f}%Y7!azRaCi?Hi7k#OiVkLsu~KSaqVaf~4%oUse|Nn0drO0qF%emd%xsL9X#)j^1UxBAxe zd3D*_8*FRrHFY-LZTH=xtMj`)b*H;{ZF!%1^4XY&cQGdAqs9h|tS8du` z>$S5LzOSm@XxOrITcuo?O`7dZ_JxU=$X0mHV5AOwVK9^3U@jPKWS+h=I+loCjRVHS zJxak?tM6`vH`bvkOkZ5KHi$D)6;aglsHQ{5#19VPZL)VAOB6W{N#Yd?saPrA7}Y2( zF=Ei0Z%UJ0vbV)@tCp`eudY?2@7|~)yrnr;m1~*qwchS$ooKFHySiMbYUIOf%U3qO ztD5|4!wy7#xAIe1TejrDDP zZAQk-v})DMT-y5D-y24^lx|RS0Z1)mu7Xb=c&1(HgFfFTZpM$7+*uV&t*5(_jQ3#2 zi{O@^qgh1?hrP}uK_`eDgi+=9*4|$m6}Ov~t9@fzU7EKJu`2lA73rwhvQ^G#sVxg2 zqrUZeS1oehZELdJ)$wbTXt8;@ikEJ)ytYUvRqHA$sDecd%T=P06@n#56_6_+s-zp( z=fpWYVj)>l+f^a8oMOW!*M@GOR4}0Syp>s6shfLFNF&TE1FvF;EY_$3oY4*tsAi-OPysgV`LhkEaqg6?_D!k>y1)50S?iqJ+pfX>6^_gDz){42SnAgP>eQLb6 z_$f-tW?U*3Y?){^P_ZCnlVV(v5E2$7-X2%Y;&Bj5M;CW-)qAnmw&te~3Apc2FE)z? zRG@;vXw@aTarfT#h0D9Qb=!O2c2)0ju9Zci*u*)7z4g0WPb&uy=0azF`{lJ}>1e1n zi&x?D{I2?%aZYBfyJE3!5W=G;o)^eZEyVEB3`qlm2*TP?Q5@2D!(hH=vC0K!GToxf z=NB()GpUY;v%($nljnk>Du4(q1y(-Vmi5lpK-lf3BPC^z>)lI8zv5fxyL2~A+-s_5 zcJIB~tIDmS<=w7Jk<3=<(9oCbw_7&zT%5k%uF|~hbGZ%ITZD^9KDXkl7nQe`&whgK^ zS~VL6pxbD+HrqzAtwyy*+A6VANB~k&lp#oUjDnVtiWZ`_HnFT){rhudlVZv#nOP{M zrkmYyEHg!-*tRQkaJB-)HqD=1Z(DTKmdZ)psMKP^3Iy1(0ce5NyRB-=y6hV#PxWg? zG}5$QYo^+{a;U4C?Uv*kt^TchlpQ;H2TKgOM)O#+?kz%O|LfO&WBLiIc#DGuCsVcRlE*LG@@6Z!r$yocjS;KxjC zs-f+cD36w}l!amASUg&Be<#=pPxO6L$LK!+HtgzMk=@_716Or(OHIxk!~}%Bb9b*q zb-exY!N6>Hhk}E!Zgnl>p@TDk(vQz^-gbtO-wXh(77H^(6j0_I$ubqrRs8!omfqi; zOv7T0wMAyKUxiM^F!<~vfOY^pWT0tUDFZ`tNBO`^I(S2}@f=C1)EOpA&a$tq8(R2^ z+|h1Pa;7p0BTd}y+m_|cv}~JLq}DA(7cE%lIbthrTIE5tQdOgEb8@d3rKPxv1_p>I zS`yMH2LL9|oGm|`VaBu?B_gsjQkWEK)#^Z>k?1Gbe{Z~W{7*WSTA#+SEuoY4W2GwA z(0uLR>fTRNysD%QOXq3*<2e=!m{;F*OvFsnl@4+&ilWa_W@a%f!&#Ahv~{C|pEhtE zCF(8juD3Mx+|jf1cCOM$^KPc27W&&!t<8!pGt5$f;#f(w%$WWKHp1o6_9At;LyA_`7}Utkb%` zOszj?WouWjt@Gy9 z^J=ct^|!=hRQBAYwpDRDXOv{zjgJGz%?Quk=rH9YFY z(&mjMQ4_AYL8;eO=D8Z)l$tbc&2}b=DBGKIG(`}V&J<$N5p!4cZRxK!O1WGpwfSq= zwSAfHWb;~l`80a5)!kdV3EQx;zDnEkE2-)#O;i$w)+vUYfiU5^1Fz#av}W-X3E4LsXP( zub>*%?%Z++XaMRV1S1l`b&y>0gUSdZD6alh6x@g*L@87yDEml81xWHwXfngX9Clp>xtsCng(>qa5kkmX8&;H?KGVg&Uo z6V2(|4Fbt&^9Qqe*YG~QuiF*LvYXG<>{|TZzMKm_n#4&uhp*qYw$s4pkACbvF!-6G zEUmZ0A@zd8zF?S$D8-hqE@NBp?hAExjD7C?eAn>XN7E$lX<#EF#5oT~yKAB5A%o~@ z-@>nLd#~f~<@W9UWN^~jriel6jeXzp?fz+uVW8QY3r^Hx%RtGgD@rTaujlUbq@qAl+ ztGeEsmUnN*=Va}E+UM)LQs2?*^KYAOS7)p>-@c0YzAxW*n~U?SqYT{U?wxS1b8hQ! zn_HSTJ6P7gO|{EWQH`vWo_D&gZEE+r+tY5#;@<11tz6Z-wYgQ(Cc0G?v062?7sa-@ zMMY%V5`-z{m%*PMCzkm5Au@Ya*v9m?@`dPD9BTVX%*-O6y`X)G`1_*#*xQ{JGq2Bn zn}09ANqb_o&TpX-fF`v>Q+)YZ6lT;!Riuq6eW`gi>cU#Vt1gY=K%Bt=r`Uv}}ASsMy;^+ha!7EfK3?wHsKqREEW>BHI;4*5)edZDX9(jiXd; zqT1!E=DBN?{XN>et+BDTE^QlgTCu7%7}_zdMyRW9YUb2!cXqY5HA%INMPpiwR?!;R z(Tx;Vjf-uh+Q!(lYZk`YD@HX&*DYMF-P=aSv~3!+TBB(;qQ=^zVxo&{6{J&HI1WfVv37YCW~$6-oqrlTG5gkf{GqKX8b3NZVwSjmxIiN zO4Cg-0Tm<ECdllkfHW-tDJT?y2vU?FPyqsxinJn$+uVMS zcEjo5z8hg-lVOv9L<7vYAOpq~43=zI2!MWB0(USCqyhoJ^8=D~>dRYgjr$;c z`)BN;Dk}w1lCia$6fr4eL1-ho>62*|EK*`^qSr0BC8a8YiI`~uWWFFLa~ef4@f#o; zz?3Zs`F0l$l`x^(n~S=yvw+$zNA3yxRQx*REjx=NWpp>9j|d>E|Sp)iSTn?Y>(24ecyJ zLU22nZ2?GA%;cM#NxNR0G;P<;`mbNEyXR4F`t83JXWrMw+Wczvem?grr}(%v1NLkL0?!g$0JMrJQ#_sDlNe<*HZ zc11d$=!ND0K2eYXNTmQ$1w@o1NK;8lGzP67$(!xyVWlf9KeH!WP(BPF`riA%b1&5| zwPlI%=BwwOV`SVl@orbuYo@sej6NaEmN3GM|FQntr?=wlnl7|ho|xsf8RowT@(-y# zq2M+M?z%;oWOlr{uM0ia>AAVCeb@O{_{xh7d5#p3J=Lp8o>2?=}wQO&5HP4P+R=&@_&p#P)}Z0)7ypa|jeF z6d+Oxog6I#LeWZrM6$FZRVb7ab!)DI7T5fHuBzE(RBFuHT0)`%WeOA9u!p7q|1IzW znP9{Dp-n=lv|CE;cl>{#|C7-Vf5z7Hr#rh0?!evFZMQYQ(|?!cec30$2{)2EpVIFo zFPI0qAZ0k~AA29S5PV62_9{d0^Iuj~2z%>ptx3Dxo*k{Sfu z5x@h*6EQ{aU&Bfw`vv(Z!IwS6prJEKNJUBJG@BJ|2k`#J57{1YI)SGuFe0C)hHV?p z^#Q%w!qyE6tWXi(`c(T#6o)g^hE>g1yRN#sd9GJA5mn7xnjZda(L=}}b(h5Wkf((w ziQ_p^ae|U=q{9V=WIus?z*OK%l*A>x99Wi<~iHBw#3kA^7h|s z3LuF7xaQRFwni*`v_M7&t?E$rlpl<<+cZO}FsY)7Ba8!o)qre9bBgMyVuP4@k**}> z6E`yzvc(80<5_ztnce2SYuwQpcK7@rz3-O3-B8i0(G>_}K|y7)DypHNPQ5{!Bh|j4 zXVFAtm#A5-S3JwF3J#?U?XBgbU&CGfd+|zaUh4Y2lCL^%pL^Q-*B^TBJG$$RXj0pi z&sruDiZ~o6rM6etg@ve1ap{1r#JvkJD#m2A*73C z5u~a{qXub0zIQg!Gzm(W!pUP=Wum00qfsP9Wg00IlT@iqWi?0!2!#rWsU%7WWeG-~ zLUk6ajF$4bCe09IDHI_>Q&cpCM9@(8J7PV@*1P_|JW0A955yjj^8`a)eNaD`9DV;l zz#UaPUpAE1zD!(gR>}u1`-A8la5Mr{Y!1)tMT*HxfnV*rg| zti;Onw=8NkSk{eeX1l%Jc`3U(RIcu7i+e0xnY~?Y3$5Bnsw-!`>fUQJOh&)X+`V*e zh1@Q!&28P^^!u;*7g6BFLwN^WU$bLkf{=uSe+lw{4UGvU8)V2@qC;k&sfZYW=VVWa z2Ra1QQl`TAVC!~-0+kw}A_N$aD2;=HfRm5kkYsZqXv9pNMI=>C+pc-Fd%b&C3hb_J zv~A|MmA5vi+iy#EuJe~>eu`icUG(7*4|gec~+!ERII2**R&4qbfYPA z{K7-;!HgE>L+b;s&cWq-=Yd`s_Zd9CI#<;@;*t>ob^ z`y~2|BEe$8QGdU=xn$fpRFzz#QKY$}T{&`%We0Vr*5=CPblD`@RCA8IiBQc-r9?z* z?%|GenB}>v9Tqa>beLs{VWl)eM#N&}XLUx{sxVlznKVU`<;sA?7=hhfw3(#aZk9DB ztNL4d*yxb&hZo>0<_+g1XcB^gf`p)0grR+={DcRdWIZ-K9>O`*KT@aj!X*!a?IlwA zDD(u-9U)@cqP8kAm+N$59%0vaAASqvdv)g zB9JsUy2$`RUL)6ypfe`Pm+8 zIgPd=%)@)w6x@ot6t}g=q8*$R-Ls1B#-4e6d-VhR&m_qYo>&6bz5W;FpW^Q8y4`fP zvt+Yex=q(zIl8%RPIV@(mpa#X6Log#L~ARmukvC`Sv4iGqhU6rv0f|OI@qKwlRLG{ z(l*AryR|tw>gCI>UC#aghg$k9Uw4~2-dHOBSM%?@_jaW!Ok*W;jNHdb3f0qU?oA^M z)JcdMPkNd{oykljA#XFSD1O>aKs!hjJ4@9DObKBO+(?c>2z$`Kr_Ny5hh?>&E4i34 zeEDVfk2@shqW8xxJQx7m!hZ}Lqjz9x{3R8 zPj?l10FRH{(#;V{Y21xYsI0)vT+$P_@@0FA-0xk}dwaWjZ2ra=8!_e#_Q69cq39uO zIkwcMYINfU3L%`#g0YFV6Krg@+MV4eLVf;ioLZLH9QPPD%685erK4Gf!TF5MpZa~? z_=@~L%o_)9^EiBEiL|_ zQrKvNjL+JL_jlhwe^dv*#=h>!Ye4(U`+ZDKo)|o4B`=D8C*=TCMGaLL82vTPxZ)QAW|e&qeWCyR;012_{_Rpvsl+T zisehIv8K&kmcIL^&DbN!7G*7&M;s@G6%JLv4w}%n^jhmzUADTYt7)ZbzIHp9WMhHJ zxpp4sQ9#}K5b(6_3E7W?LCmCf*zO(25H1kd^VVki3O7yamglx@GkL#Xr_Wg0udUg( zHquzreY(8mc~@Q4qSg1X3Wi3MnFx{cpiX%8Pt^{eMhcBzx?RrQoZSnq?aN(%qX1xP zN&=CIE5fRl*1^e&Z$%NZZ50}eM2bd+f{I>K!J8=S`_x2I)RI^_dmU*#HEBq*gWsoFhw_Vsg}2i%}=F5R^EssbnZ zA$uDTcMn+W)Sc7RL`|2;6-8zS2qQ0ibPiTUIV%GQmhxjur)WbWIkqbc9%psWJk~6P z@X*SKl;%t4XJ0tr%5h6zd2TA5cI>OmknZnw53=SmEzRp9qK|A)*F+uUY9PndTvK!t zi2}e>ST7Q4t(G`y?LwyRZx4Jqu)sM zqz>^&^CDy=4GevDEd>Bgkgx?tptNYQL{J+VO^U-bT1qH=;UXA`hbJSu!^500qRhdD z8YYrW=UW{U7Lf0gfoGB21jlZ1uKU}Tuk%&=kKb`-wfSE*$H33Mg`~+2gVf(!J=<>4 z<(Ra5!aeZ{g3>d3`1KNAZJGOPAI_eoz})q6-s<6f zz#hl!e&0b4@4}RVzeqQV%)|plU^=2{8t3Uy5=Ahxj;abMpe@gne~)bey9iY%8zKkT zU~GxR5_Tz{c>I4lC?cc>(g8o!GcVOK{x2wqEM_WNCgUB|%F|tTsEE>~vZcF278;v0 z)~b!w)y~6iZijW%4lPQhwhYu+rLtf3G+2rou=#oAwbY_7Je=*?aM<-IG)gM9l`C3| zXd;M+T}>5K5D*q8T~@k`7?*b)-JDZw3U^dy9<f(EQfXt|xrK@-oKzH-b)~PKHyVbxDsG&+JB)O@tgj+< ziVG=9luGht7}izRn&8MKOj~T0=oKi2jEJvx&2MO2h1N{!TE%rH1ks$_!d2rn!QJyN z?t1Nc8>LIya$~Wg%#F5=5mD5jQ4Vp6N?1HCYC$_)M7-e?DNIu7Sd|t_v0<~MGm))< zQ8{}@HZWN^HiLDlT}fR!@)*YMlx8*!BE=M8Z4hAFMC+WYs-0xynN@dV1*K)M*hUsK zq{*7dq2fvD)*l=Rr>9>x)s- zH(cE+!9-Z0X;k9X47IymIW_DJI&4mgwCjEK%syX==f=VyS9fa4lbk@_ij!KoAHU_pzIWJRcPD|9b%7Un7Rz-~&Xp*YhRIJWk zvTL?^GIeMv$;$3I=d(?Aqa+Zc6<~nWl~!72EH$G=)Z17!jm4qG(eCe8H<*GklKAPl z%_%z3pw>uX?M~Vob_=Z3g^QZSB39nAj%mq*Zre9n#1oCMyxFH_?Wog+VhU6$nI#ww zp)yK`FJkWMaw>IL3W~Y8w zJ5tdou}YCv294yRQ$+2^m8gpYHF;oEI&?dh)0_ZV##miJV_TBpDhMhGl2L&~>`I2E z(W{o7+-UL?SQ#L@;;ZAD-dme(cXrn=fRqX;p=Zw8?3=nS!cvlVJCGR8a!r-pcX7r= zkr=*rUTz`X*@kyrSaY?SX6dfUC7S{@i(fmCOm8iA$IjieO+)8(jS+b*MM}|CQ4m2< z5lq6W2%XM=UhIik73ow)q$(GSCm@bg<}ow15n7a~N|go-1XXp7q(wJu8Rjra)+o;R zweh`_nAwuMxxQU@b#m=Fbvn^N&jR9e({s*w>gXdoGura2 z%N4th?&)H6-Okq&Q@TrZx11|I&gyqkwNXP!5sxF?bxP4IP_1OVuO91`cWuLNXwj|J z^64nsd)>Y|u3M6Ck2ZUfw>fSRd}!MEx5t~~V@1qsmNB*GCEdK+o>#^1b#f|m zGA}aPPD4_eCV7QNs>+(vTg;Wi3WaFhVO5G`j<<_b3XDb~%JT!6h8cxxCOXQ%$zB*% zO{_UEq6S2A266(CWouahw7s@v+f3F<M zJyrAjU82~3YM%JrG%tJHWuH}ztXxKd0=Z*a>&@ER)!nO`Xw_WX`}PI01m)i3Iq$2t zatfrVj^00`XTkf4Q?xk)Lb?0x8s!8XZMo|zNEH%LQjj7+Q%C{)9jngcBshU;fTog| z-4mpMUZ>mL=X4Xy=8kjZe73O9J!QW1^~O<6Fb3xM8jCffeMr-rTnA~UxlV)}@Nj#~ zI+AORY`=Fo`8Ao=|D%8cpL6l)y(#}AGZooL&}4CjXIH+Gnpea=1W@{tuJL$w?|o*M zMj_ekhP1yF*wn;SFp7{tNlLGkw`o?pR+{W>kK{=pYrq&J3nYjfigZ~uqe&^MQ&h>I z3p=a2Rn3I%-QBrPyO%i3QC-{@I!4`Jb7(A=b<|W%EipulNR}cI9o)uEVs7hmR@~cO zyH#Akkf^YS53eh2*uv!zv@-;4ql&Giu~ew7WioeBcN&Gkkx{k?H6`S8B2Ryhj>yp z#I4CvYqH%9qeE-1zH7SWD7Na`n~cKbV~a*dkh~>lB^E4-Gc-JEh=>TmXIHh=Gp+iU zK`8FJjV6M2>zXq+ww*ch-+OU0b&JMc@4Rhm3rv2>Q%+$F{rC?cb&3SMk;Gi&574(FtJ^i%X3d37+b;G1lH+*U6cIorA+}{GjWH@%9)-xSH_#LTkWc-oY7+T)f@6Bv^Ms6zotH8$m{OA7qZ@UJoDQt zCn(WNEuP)?4XlC5)a@@4QM}vXv|O(ShG&>_ZYS#tsev1`tBP6d_6klYgze?OR=4Zq03|+L}W7n$UstkPp5^ z(WURyJ}O#jjbm#S6&n^KZHi_#Ese3VV1>e1 zK-5r8B&;+wF%v~2G@^Pb&t3;U-8(|BYv9m0XvVX~-kWa0 zT3dWP+X={idyZMyQDn!JF@4*UZOaI#EsP9a$4Al?4xNpK>Qa^}j{))G5(I)3=Nu|m z2Bf=Ym*2n5-2N5jO||G&<*3!fI~p;ge_l;(G^UM+IyXNZkT+f-DI0wetx3|F0tb*# zFjao_>j9}ok~Y}X_iS4nrd3k26u`8Eq4j}+nci4>US$|HQK37~TLjrDeIkMJGy~t^ z<5ADeetdS2s^!SCEX;7m$C<(``E-HQC3sR8&zARG$pXeuXXSdl3#G5TqhhK%fGV6evQ0^TWG8 z0zD>?Q%8ci58=<@e`kN@Pl$+YQ0}M_(o(eja$rppQxOu-l|Z8k5>gskF|msvElUma>*SmmbL{=XARgA&-2E1GqqL1YnK&>~nV7X) z=3ZRXcl!^9uO^^FVMB!^`Vx68Jiuabp67%?`w)OX6~R-Wc}gka<>oEUSDe_q+`{Aqwv|*(XjC$xGAxRuvsUuu$nNWy%oAPR1V9%nb=O^+y5n`+ z*qg5AjWR6K_1vLk8V@x)lSo+Jz3bSoCEc^94KosVT^a9n;+*M?q{Nyn=HX|q+i=r2 zE2`%Yy?edrISMdZsT*rSSXQ+Wfl%r+oz`Sha}k}_2^3zmY-JRd*IJOwQdV*oHAsnC zta&*%mrpKe(3W$qc9KTaW*HEC+|#U+@q@;B1wh)Q6BKd;oG=Eb9I&8kezM#&e;Wy*W5Xx1`h)qbEk6ewji4n$cP6o)4yQ*H4LprqP-?tHbH zQ$=#QNnDEPTN_o4z3lC^Q)_qUw^g>iy-mHg_ib~zO`<6cu|O(g6`3`uTO}5?1}etU zt9{zLdewBNR#s%^pq;`#KMiOeVMW39pGbcrk5rFqvK-Ih^mJ0v9f$E56dxF+DJTFc zAvu9)X`x-Cxvao)_}iNIcTQ}#`+MH(zPEe2`Q2=l{kxr88|h<<30Xa14q-9}so*Lh z5ElFDg*TL41y^i1;c}W<+gIH;Tk>|Qwc!5fY2!9f|7){5I832$E!o;fK%`1eDyFcvqfEYuMY8E; zz`i(0B5edmTDPZ?M~^thv1XsrvHdriAe3S=pKNO(Uf)^XhRZ=aaESy5ls;rD5lgJo+lNQfQd7(TJhX~4`*iZX_ka&ptID-@280fNJU|}!N&P;xotdKCIqvV zTh{Ia&Im=w2(_lY4_9O~G3>9KW78;&u)SmX^Q^#oo@>G{2?#ra4G3?pDzY#Ud6QXz zm5P+@*d|1}(qIx!kB5*bUeLQlGL%?@VJxysOO4Ya=6W!6ZeUpHATLXA@`9ahS1PCOOs#Qh# zY294T^7@mlpr3-PV||~F7v`AYIvnDrK_i7>ssd3pvBE6K8(^SF7w7*{1OoyU=o$6H>&xzvdKr)Ff0SObFv$ODZOWAxB5gQ~l3N^VT_PN|A zfzn$?wa!sQBdh`Opcet(qlP@)b~%o0d-WMaP-={@&9*hn?W1~!j0~|k1DF)?``^>% z$L&4`r7cvcdQ%p|q|8p8c{b_L>B&{loG`dIO#p!@!|?57STazIr=T$T3t-DOyRinr zk^vYff>Yj^wknID=7y**Q=6=zu<*cqJ?qBF_FNr}d#RQ}vC~4BL?T^-w>GV+ClU{9 zRft_)wIRfeL6(vrW{?nS$L1mh@r(z~vI0aRkRu33n?q%FbjV2u0Muj$as1QNq|ao! zqB70Lc0k5BB6R_46_bg`SuZFc6(6Fv0a%|esj7KXop?jb+;aA$n3*-v2s>=EtW~9N z%V1nxmPBbPz^y=tL5PD|A^mO|NsiJ}_y^(|9+@Ll)!S>?FLY zs03%UH1jZZq6UX8unmqkG=|7lRgwuSTVu$E z=!JL!EQaJQIFTDIl`PiFW>og?vAu6#f~*yrd0ArCD`#46&*Y*QARj>Yw?ZYkyY}m` zYPpk#VxP49>O|o??yd1IurF^cV;o|!y3X|=r$<bq_X>rNB|PdXEsJX;7i$`QAG)iJKa$!zKIO5#)*Luw zKx~eKdmCJ1HF9D5fe>TOu4X&L+=5vW)&rJAf?Gwm20bu_HLhc1Dq7JRcM`5*^4k!u z=*Kxiyjp4|aX}b}Qu#A-sFecuo-PjG6>vriU0SgZ@rkJ7poupui5^!zZch-I%%PIt zST?OW_gM zq$A+PT_Lm9`vH}VYL>-XVS7TlhQTGBBW;_u*%$3iQ5S*;aXXgEfPmT?#mp6xkOSs% zz%q8SFx^a=$4s#%NLxZ#0oV{&`kO>~nV_U+rt<%84dpLHXai~#Y%N>{? zlR3_dne#aNIxM?x_3Ms3b{|nPxLC4}f>?0tlzNg1MKd`Xr36QfIIiW$R);&Pc|0gJ zuf_Ivv7ZRz)yZ}m>1dyPeojX}cE<^u=B{LM3Kja;1cj`yW@2+iG@^x#VxG@)T2vlnXw}VlW*w5GE2tUEFT&#DbKTO5B^EaWx=WB9|4z&K{sZ zzTQ2XB7`Rhz23|jUxv&D3h!ueO}u2HNN1d(qBF6lS%Cu8zOGP#D3U$I$~bA0 zR{&^m6-gAALDhqFwV;92U}BWPg!j*xo}#jh(S%GDE76Cj`}yb{%K zC+XZh8yin&oTx>etR6~6iTH@M@W3s69zg4fc#tHPN8zp%NdoP<@umG#nn;oQUotd- z@zNhgH^ev$_z>9)o{2yb5hS9E5&;5^1gm`qs^RQ`yFjxdD})RV%or&i?jTcGtdT>u zN5S=rkwgzZN*x|1k2q$MT8jrG1)47#j?97)WJR42G$8@wFe;K14&C3Z3P^V$4({N? zSxc-@F;cD(=V+0?%i)z+x?qE=`>6;NLfgu?i&1FT-)pn?-xu`nxfG*K!$#x=~0MEyuiTBAo?9IFUUA}Sgp3~Na#^};!q+=A%MU`E*FupnueT` ziCm$F?dXdIuS4COGc!mP;nR2*#VN`}Ack}WkYH(_2!vh$NEfXOB!i0>UEeyfV%SU5 zv%!W~#K@||%Sq-_KsbG3C7k$qu~XpxKI`X?fT(pcE@zGz_%(;KiQYo)D>e?CJoh2+ zV}#<71%#4NVh)=}!*L4)*-fS%jZzP5VU3-d=Nkn2Z>KQsH;_E+U4NHf0+!#)vqV*k zKEIs>Suxl4J(T=@?DN+2%+*DdzFeq%r~BFOSWtZ;#`^x;?yuX=sp$8HjaK#qQxUy$ zZktALzi2(~^>&T(e>xXcvsqy%1*JzP#{N%mAVe0yAR@U+A50Rhl2JB`bm+8JtyzNq zDl&YmVK_|nW!b3-kQF5xeh+wMfJ5^w7!%;?>OzY$*kcg}*yqRH;RIk)MG;{6f=LJal_&^BN;sXsbA1$~U zU~u6Y6f{=i8}ppx`9CgsnYF^MO_!P}sT4SYrwudhIJ`_?upWCFwjv)j5NHmPWIg>C zG?5M=NCPy(qC>$PbqG_k?p}=CJdth+S2fWCx3@i};kVEaMb9V_2Mp5OBy#8;5W`vk z@MALFkxi3QiYS4x*-ypn$siGl;Rzz8fZMV-#9_cT3M6RTm>sxwly_l7D%W!nDf!VZ zV5AQz%*eiT*#fdKO27sjZeePfw@oJODG5QQb%;Vhu8>0sNF8dA&0B*oIk_fgP-HJP zr>>K97W6T(G_v9}LViiw2oeu>uxJCF?2fiJKwg(X5(ddTMN@0XH3Qfq06P)^IVge% zaYef~2w@3uiC04xG~w{~j9DC5x5z9=!5UDbj09#vAmbX$Z>Xh_G>>l=<{ z>vJml7uAEpMRS^oN$$6~XU+kY1X(4>9P=EBJUzLITCx}*_OxuP<}zZkrNe3j;OW$> zEYeA<%iQ5M2!IU^bys#SG+I4I5Mp|Uo|sq-Ad%xqH%NC8mwUDxA@b1h5yypu4%1|4 zA#YhMl!`_#)PHb2`K+=C0w54H-y|#%rL359^l{-0t8BCiqEs2=o%r>jQ_`j|T4Wcc zR}l$mvQ3myue9N|5~F00ey^qnG?0+yuCrFdoy7|h_&}HxlVM#b9m!Z*F0K>V&}tC~ zt(a<88=wcmKVr=dq)6aNSD@@J+KS>9V3>j{0s>vIL0+)GB@hW?0Wt(|Q=oxhPCYS+ z9D`l9Yif053DUBv9GXXj22J-Sh9#nF6Ht;`4^~l78f5gCL0^jl%!nI7U_YV)qidWz z)Fe2=$_QY4LcBd<1AvbX$R3{OP2C(1@OBy)aKbuhnk1TvzA%PwAcdg62zYZ`0bqkj zA_+a)$?`JV%a?a@s1Bb^v zTEO@`<=7yD0nkK-Yeo>3ypja0C9VA_esi1Ws;o(G8lZ3L|0)+5O6U}1dLUhzE4N6mQpjMiYd*BBj#7RE64$&~ zb+8VMV6dyZcs4LOGh*8d3K^ylAHBD3kJk5&^D1_Fj11BjpRr$7c8G^HkVq45&~zps zJT7$AGbVLRDh6c>RvgkmD>n(MSceW6wnjk=(utKs2dMCfJ5>!6!WPw+#Mz8GG&LBj zn;%w*v8(dL+0NElw$BZGx$eHMoV#JD35UcGeqqm-P(2=YM>B|6?HJ|fQMBvrGk5eK zT|urLCi-0p==)=Nm^ZDE zwwVqP-Zq8wbOSzpTDShmanOJisohXMD%k|-YsQv zaejAWHd_aWg8D8vIX9D(GWKU?)`Qcmnc)YOgNcpZR!!7y301GsltqoKnC}Q{jx(Mojb|Je#FeTQHympTOV19|;o^hTj?lJS-0JwqP2!u~ z;hRsb^@8iJiBwsmr*H7p?a01y|H{y#|JsL0!c}jM2f70e3)N^eKT|Agbx7&ly-e0+8ytwWGh6g zQGR^ud*@sZ@r^)fB-r3QFhp{e^^_x8ej(1`I#W^}Mx3e;mw36+&5jVsJxBT@ygl9# zVf(k2@#Uwq99rwQ=^4=Bd+Pd*H&Aww_+if0yVP^xpAPMA(^GIU8fIDo5!tf1@%}Cr zK9bkf@0`ta2n?2_!HqCvAbk*s(L{Q7K>F2Zkb;W$-B6Zr_s~Pk)6Wp^H+*5)B5#Y0 z8@T&n>oPAYNi#TDw$0cCxi8)pt43&PfPB&p9>D|mEFN3t;|BJ!C|Ds1gyV@$)w~B0 z9Bs~&;>rZJrD)u%MrjBg9(^m->oVWf)6tm>(|gA(VGtc2ab#Z)vl!3Po$xo}K&V3P z(jHyI2jIi<)v&S^z9}GjfpxCAJH#-f#l+_J?CR4x*g&O$K&+sNE}V-wBNxl}a@id( zBR<;B4h!1o!5k2qGu|*MP)_JJI$MyaEaovQy38rQ^;#kyq%LC@0m3vmh9#)Xl=XKk zle4f~1fYl~gkh~qE{@+N-_1%B5;irpB}Nr@^&azcTgxEYt>O&VrI5CVej&0tOIxir zY{PbAUiaRH#w$Vf9?a*hkJXgU2$*J+UA%j=HpHgMN)Rm zDK43iN$h-UhU$2SBG(VM#qj94k+nHG<9zFv<;~N%(z=o}0%V3_0|_CMP}&Mp7dWv~ zAs2n?*neK%mvw!-#wcOg~g8T1>ceA$OSO~XC?0JlEz~^t8d8z20O-|h4MNtaWRmsb4 z`)RzlKUlIwCn4@U=H}?$b-mUbntcoP zmPA6Z^;vp!nq;cMw6_ev!`my(&$(j3RwfL|C3*m*d?Kjhi5fB_&~0gwFINNT_=1=uAjj zHkCW3f|O|(g=wVHxit|w9uBFmbVQorN%<74rVe$~44`>tVArom0QEXZ*7B=~Px7NLQljjWs z^p`Jv(9$Of-a3ptlh=37tLFCmZ_V1*e@@xXu2u}rhYyt^847ipM?tkw4J<=Iak!)5 zDa8~^K~#kiI~Iiy$f54i83<&87-^ZUJN5TuKOe=MlismO^pLML^?{xkEzp;SW`Eas z^a$202@U9FfXPDLQ6;23a{avy9yoWyxE^py<5 z@SjOCeIZr?n#4OMK=(O38fFjHvnhRSnLr*u<|lYkB&3Mo4s+j%vkFAD_ODuyxxtqjUtezyUH>Dz5&YPZkN zcb;c&cV6x0sQml)^|j^m=!|0g5-tx2o(!n7l%qy+8PwYc=VzG zcNeLu6skq4UY!DharXLy)k8=eN>ZB$b0|8BqAsZiUy8l#baFrf|o7RHf2dWtFqVq;~Q@+9zgp#m!|~=eoHRSkbV7K|nQBkth{FP@T}>5dl<4F`fI z`=DrDqzXi(N=S;>imtn?6&Gz(^Ixi^@zQt16noC5l(xt>w_{uz^Z?jSDi-hEzZ>)K zwAlDDJySnUN@J zjEM=YjUm~GcPe(R#dl+L4TBpt5R)*YYr5=HO9C|ph)s-GsVI_Yn;0nsL_my46cExG zB8Zs@8VWgeBxxn_)7@N+wACryt=33wmeaWsT~|t&DN`b$n6^n~qBLtJHKSTGV`$s; zd#9G&pEp;PM3vy{wcXODOH;_DrapFc)Ul1CVKGGRHQA=4SGE3Y+tx(@o)&jW0>h+d zC)=s5FaFKuP8XS9nuac6tu@yc%2BADVl32G`SaUe&3A=5aHr2FymDwy6Ee2F;c=#3 zD6@V0arS+;F248I>+jtcO?_{a+a_N<)3143b0lbOuvmiz)s>JOZ%FD(#p)9xhKA;{m>2YMs*A!m4p`w#~lEcK=4NjP2T-qD3ZW zbiFk(t&)*cJ~^KU>F|n9^b*4Cd4rXg8uQ#Etr)3SoUx7)u@#Dlgc%wbff{V z5(L_yQ(H!&{%y^+?&{Y68RmIl3-U$yawx%IV$R8Sd>0UEQ7Avsy56J2?Th zYF%oeh^ksu0Z|o3kr-K;ckIzY!I^y<3o$Mea$-T5sHJufM8OPkIrNRwZIijICs%!U z-`%fO=FNXL>8?l5&D&MxuE1&hv0k+(CkYeNraBeiURQxVvJ?)E&|GANztAr94J?l^ zQ$SVn-^Xjszjc15|);VDwc{`CLer?kp)uZja3CHK+=?*i7SP%Xp$;QjTPU^ zx0u|a2g8xz*3$NhA%h{MGE9+{FI(eC7Kqljy^BZYzr)^*AjUv%y3(a0LSW{2uZg0_k&@=dIdw(07f!=Q$ zSVMCG77?X+bTO;$obF?~NubWj)}$rv0|RN>mX1F5>jn+8uu(RGL23fJwOJ72A(Hb` zZ6rH(CbN4t0T2qO#fX*&E;mwQ&bwL;1EUV(RQ%Gd8Y1RY@)6z^Kl}M7FR%;iRAT*Ih zsIdNcOv45X0g@=Ov^4+?=zbuXE(I9BgYNt1h`IUmZz*3BeiL?b?)QVwz3uh!y{IKB`MEpNrwe)9$XrE@DE8LfFv$>e#PoRDB ze#V7GNO;2Yjg#+#&z5?8_s%>S2j#Dx&^Za}cr~fuQ9Q?Dtng&P5u?2UaGA770uizW zp2%GuG+F0wwB~~iZ-YEbs6PSw4s>n3^WpA~%5jI9DU}=Slk$aSXT;Fs>nImTpNLad z6{pvMNMR=?{8M}Ghlg1{d@d0RiWK?n%NJOAy*|f-o)tt!Ap}F>6uQij_V6nE*C)6u z1+E`2oQZWUL~=u8?Nw+Dq|PjYfnr#ZM3Y8>AQC%BiCnonZ{ZNKQtL}#iSqZ|J)b*z z{rzhJ5e+{{%~nFQ#)? zfkCsUOpSu2LE` zVBoGA1d2l7tP^OkNFm$gP-TTMW^Y;E^+Dnd6V56iN}&Pc-#W`DL>n62@JkDW8>kMg z{51L;WFmnr0kjs)YFT0sFmCiz1HuI`TDC71kp$&z2SZM9V2Xy5;ur_i4Cf~rdzwb( z^}9AkbaY+Aty z$IDG`mnRJ`WuH$A-L2Psb>O{SwWenAy=m2-Uk`(8FV6DPT8w=($?=Wx3Fi78>{vUR z3zivi8n{6=Y%3aWP z=*UK?sN5_nn@U5mAUVp{5T3<|)39Kh5yHFE3lki*prGCjJGHY~x|V?zpn|^!LK@mK zrKH?+X!8Tjt=;+CW4vLn8>zlBHIQimse=Vzh*-t#%sl3BqHPQZXAcP$sA?ug8^X65Mvf_0 z;;jziT8DPFF;#8bu*f##p^PO@-Yt*AI()~8xI4Wz-DfAA3XS}p9({X(^rFGkEQ+A7 zmaR%DkO4{sc7@G#k(Z${NKW0yNNz5o0z&R%b1ykBO2}4*^KPsvCo6AO%-h3GS4o^W zFqaWnb%m|Tt78D1(}HYlSW9CWRxHh>q#DrxwWx!_qOkS5*%M@fK+Q6BjkF1^jV!P* zj1UBJj%yMG9KADoS2L1+e7USSv4x+6eBY00 zC#&o9+*??Mh@!RSLudFU!=nrz;Y9l#0U2CWO1&TX$CIS0uTV^)}0R$lc;ncuIbO^=Ikv-3VGSR+6x26GD@=h3u>rEa;7tV4zuR99g~PYIn#+ zff1}}5n=_Y1;mh?w5QEvTsg8X$Z)EO;v+XmI{dfVSpl7)=gcYJJL(#OPPFy0gAD;- zbAS#F+2~beflLj8s07~mt>QKh2+=JRXzMAe5Y`GdBNaeX4(}hv(|6qy?`(ZfcdlYY zMOFLvGr-iu1~iJw(^fN41*UF-Bq3=@3QStvTx-|5nDb;jzA|FL@?SHGKqP1@G0TY{ zFo39&TEL!@yrFdfHj=B$7XmbaNn(YuDPU^s5p0Ko&~PLip#+kn5~MVOt^^p6UfqET z2FhyNe%O8R&hj0~W@FJQ^Nrq~XkR_PsnF&~E!6SuYrA&3L*>|yzfd{0g_mcLZL3tS za{|rb(FtJ*7?$=Sh9Rt{cK9<@TsDdrMx0`hHLfNy+X`x>$Z#oSBV-a-k^u#u8l*&A z*c8C$IHA4m3K$PTXlGp^TY-&-j*H?HBIgW~XPcRW0F^|5NInor1R3=9GYfM@(DTWE@WZ zV}h0AjMQ9bUATi$NI53zs*pfZiQ zLwIO-cYA_W&khzTK}sBg z$PhZHfpkT^vvZ+Z8C7>#xsf5o>q>zNokMn54+a*4%MJw|8&2K=a3ib8gu_Z+Q%?9q zceAmWS_aCXL1<{yB5Nnhq-Z7XCR8MoG=-6<5U5#w+jjLV)}7|{9Zba)JEgdl~m;j2eyAtR%%ATrf zn^V_LqOjf{Nx*D4Xo)h@R44Yi>g@0}*=UyQ$tKM6*9^A@>2U$+N{cy(}F>#1i} z2Rh^C1Q8h{WOvq{D!v)lEwyY};R^GpH-`40c)ICzYpsLhxnPKPA0|`pdr|2NE%Sk` zSazskg51z8ibkKrBp4!iob)f9bTLObh!RO-#v;tl;ZUjo&=OvtM>G)`dRR){;R)Z( zyf!aLfC>(1t+Q=DdNZ+H;2Z_*R;R>Mn`0HDoM%LJh=f(x!uNn-2!ce!s=8Tl6@`ln zZ!n=_VW0>OAjvEtqTwVUcef&9KQX3G^Ky4vWUDbjr`9Sg`lbalCp+c0efB1zsA&n< zkiud}foBj=0Bc~@h&*0xGF*o)W$c7SUfX+12<5<9tq?HLF)|De6tr!-7GPEN%cE&7K};juC?i%A&*8tw!A&)bnj#? zV@?AOSX*)d7}F;1UwXjyp_d;yPV4 zEOYI)CZtQ3F3(xh?^$}ec7dIPrzSJ1Bm}KB%mVHX47t1!n6}=LM-?%r5=v`%j*P_2MDSP;Af z+TakWTIew>X*u-ZF_(p> zeI;v44z`&arI*=fzoMrw@!K|>N4ESb< zi2e&LA1>SOpPD_~a%iWelz8H0tT7Kk^f^57z&)q8#t+ge>?Ws6@5DNWqH-U$Omh7+ zaWyREan|cELe?KyA^lnL*3oq&ivH+$Y1nu#eki40pO z>+{y~Up4isdi2!;8vw6CD!JdPsimOA>}X6eJ9tx)N}u8S^*2|5{5KYtib|_eqIzpB zu-N5Z{D-e&w6P&2ahQ0+R-$gs-tO~V6l`6V?N=+=yru5qqS(FfUfX9oD>ksws%~?; zosQ}^UESLI-g~k{=Uvvim(1OwQMt?4YrZY7P3CRaE}ZVn$s3$h=DOtW?(dgr{Fgp= z#hu(m8ye(XbFOa02RiQVn)~j_bE0S9)f_ zmPc#7$3?Bdp>+rVbKW(1(CcvhGS4mX``=mXQ4qaLe+I+jB|unnlx@G$@ur_W z_FjcUqKK^KeYtx0&!dZJlQz^ki}`ZC+Qg5`Un~#Hg+&H@qCOaDQ5Z1wiYY~l!geW& z6^bzZWAU%mjl0P~ox&w^iEx^qI`YmRj*5Aa#!%=aNN6CuV2~-*=9sbKt79t29$Km& zZ9ebDvAUR)$v{M(5c@jxPcHq7)}B<`>t9op&3%5Kt|+PPN+{c9v5|s{=DC*2b-X{d z(9HdrlhO6vQ#H{Ph^9b9H2Pg#F7Y$jWN|8}Oh+YH)8_c(@8s2WtM_14L+|Uh#XxKo zEs}u{?$KyK)l)$eChi|f7#6WkE!7g_H$+3*_T1ofK_jGoVc9|kc@Kw>dR@WT9~c@! zAo56|C^ADUlkDSz%*N_TK8qEQ}m-T<0ybT}5-P@bhNA?IGrV@Do zJhOe2sz8VW4jH*2r)@(X4nW|{pb>6v1NVVgc-~bP$oapRUhQq>7J^1Fa4Z=Dpli>Ufh= ztr3@>spAT8zFe9xGE_uCK_JA7A+4TI0v;za8X%2J@k{o6_j_n4AD@@to?t5_6$nKS zwBLVP8ZcSm^@P=Sd@n^4sPep?dFOfIJTxo~8qp%cUv9w%d{tD);h;#Up622uyvdXA zUHJ18o=Lo=PP7uy)aGDDjYC2bK(vQP2ooC=I(nS34jqDuYi)hK)aQF&C{`Wvqx3_d z5$IM(8VqtgTnUPph?$uFh*j#oFO@`5RTvJ4WjuApsOqV@rWO7_Zm;9!?%jp_{k*;X zJ-N3wx34+7jo7;5_Dj%!eu)F~;r!Y3Yi))@GQ;am-9-Lq1$mY-R|i+i$kuz~0;l1)7p25wgvkc6EdQWJ7#E@Tvd5|7ZRm`*9zy>Fzp1hGG_#?t)9-}R<(;M;GW3jUsQF@k124FUoxSU@n9 z0s;|L$TYoQ1OHI==hybW{bNHr)kg8EtM?r8XMB^paW9yeJ%OxqvOAo`1edL-Jp^!m z;FuX31EJC(SHo}(CC_IN%L|NYI@y>B=_sDC)7=1T-K}x0^ai-WHZAAVp5lWv8%+mvCP^BAwtkC$Z`bE}I@Ms4&9qezP*@@{Fu=>Ug#u{mEfn$# z2kW218}|pFc%YlcmIg;;ckLcEV|*Vmo4-fLgd>h0k%`5`$sRo|+RadhLa}fpIg>#l zb?E_0GRL2pO!v{rC|q^gL;S|Y1P#-hfH zY*x`!TNbFJVxp*vV;a$eYKvI54Y6wxYa3!MCfY4xEftMM(X|yu+eNJ!v8-yMENUxk zXd_tLQBk#GqJwK2XsxJ?7A>(_HDt9K(Y7sFH6PZ;*v8aqip675s*<%v+BKw##TL=5 zZLzVmYhzIxXpN0gv8}QdSlb#ZEk>xQ$t4<#V`$neVytS7MYU1|3semX&jTS2!#bZQNRTkSO+BUJaD{NNLSlY#-YBd(vu~slptsz1L z%R)>A2v7%owYjQ|v~7!R6==0)8q!)eHMJJli)?FAR8{3w%8E2lYiw#A+zTwIz*OHlnDaB(^q;Y>~ADRS~TkD@C+Xw%n_hD`Ohi)ncNfYhzSe zjcpNWBD8I&)K-KoM%dCC*x0s8BO26O8)`LSDAh)agKR~yMG;zySg}!)YE4CG)nuZr zjFC~G3|iD`i$S#(sES$?C}?OY3JOApv zjTVbyDAtPEr~+Rs0Nfvx6NjO=%En$;$^kOsXqyxQJdbgf+OidqXf z9aSbNM51*mbt?pB;;#yv%N)9uE0S{}GKf*7ElBN(%Q803Lg4{}%39LGv1M3@?x1rH zoR=ps9=wG$;54{raY6|2g+WD%gB4U38485RJ;FWItO_FL6cc9YIkdE`xI*1WP|0@E zTV@^J?q_h2lMCgSLj+W6h@v!65w7iZ8*er9bB$;$g+R8}xJ#O`K)?2BP~PsNMT~9E zQNB0dN6XhSZk#F1Gz~NXNHir82+}er#x!DxOBy!D#WL$PbfUCsH|sU7YATJQDoVvc zMWUiMw3J5FY;E&f%8O_t=j&^~mQmbCiAoAkh$2>jDF$te7LAQW6qSt_$gwmOp-W0o z1}Wb?K+ub|L{V6Zh|#FpjcD6qqiQP}v8-C7SlTsXMxdi=F}0&x5k?}7jiVU0HLzFY z+T@zCuG2$NYhBjjh|ibtyJov&wBvEfBPVma_;~x>^Dit~HpOJxqK!#fHZ}^$7_4fn zM#iMpEwO0Uh{n|wMW8XGZ5pgvHMDC+sHn9TrJ&o>)2Boa%Z_@hzfY38fSc7zLsp{} zji@#%i(^KOtP!d-gc_pOB(h^vl$A|1(2*fj&?N)GPINiBBo-}l->Yh`&f4>6*)~mz z#*K|d6l&Pj1*2LkL~Tj2Su9|pibjB@ktt|sKJTm60xRELOoOB{!wkb9uxkVU&mV_F zQdkbdq(~0vM>Ib6bw6YNIr4lNAAE*_d#*rslN!`Hn2xPt6uz6P0o*jbJo@Wraw}Am zQl!yrmLkcEVx+ddS@j&hucrY9hskiM{V>p3i%L&kY-1$8YOeLar2TgiJFaaXx>Ae; zgU>J;%re?nl1`1X8``(_NKi_PH#cdKrmkA&bsf2rt;?4=7*g)n%|;FgOn^nuKIi-& z#h_o}o#pR8d=h_d^F#VRpm1=sB2s`1jvMv$`02?1F_@PP)?wBLVkU;@+Qu2(&{u7c z0zae>4(KW&f^Vx}*aRRIrbh%0T6N5C10{%65eG<4Zz~3weU4ZUX?Mq3A`#yEc>(mC zA={1cS7ku%z2nb}ZG5w+?XlsfdSf>FnV9oN-PyZY*KKI)-D@W%XK{|`WIJrNk+xPo z^Fzly9%{})`AOn+=4_hFJwv&#g*FDhB{EFFtzRs?IdrL6>t1`%u8+Dzj98ivOH!_ez(~@hV39TtEmOs2q!LhB0xUbI6%p-j z#_o$@ou2N@?Mu=Y@0*Qk1PN7UHJ5IKO~L>o>AJg$?VvVra@v9&vAtzw_pD7Wu-Y9l z<@L+VUdh#pdRb;LcxW0Yu7oSXhI%K~*row6S%{*j!wz#{*zCJ75ml^Llac`T= z+P3KY?=fLgk8PzJPc1gLQ7&=_nNGDwlW&;2$_}gM+AD9Esj1s+m<53+Ud2y6x8BB& zj!m~t5z8&IAXS6s zdD>u_mzB^9KmY12|s7JF=osgLv-eq-RWQ^3jyTS`XV#sm1&cbX7{KA@i;m zt2(Z)z4P69y9wP}mgc!BNa}RZu>~+MRVwMOMrR_$xBg%cWgWa8d>rP+r(EmgJf#HC zL-#WO$(-7L_-Q0+kO{|zE zWoF#k?B=?X_gl?)g+MUO=QXZtScTeB#j%RCR*J7_SEhTd&L-O%6^ionZRBd) z=S$x0M%OCyNxas{ZE~(!xvQGFq_T5zEu(6tTDivG<=m*zjk0KEiXz@zEs8Zp+|@?d ztZs8rt|iS~Wfe@d6&Sm_T(>rvXtA_bf~03QuBjHgy4vQ&pt)SGA{AW5Hn@?rRo&ET z#v*|=a@&$?N4UP)D@7Bi0iICF>eA znG$9uFr^&^hr%#9v%_t}iD+6HTJ;Vr6H?F{$TDntQDHzIfM7<*Oi?N^aSiy9=K3AH5E}66;)1!9tU9%?mq_N zm63Q36^b5C{^%IQ{{l2T`A+*Mjh(R1Q^puDl$)m#Qap!YV{Z5(w{_V~&GE!k+1|uD z!R-_@B5&Td*UM#YyomOu{`kn%$6f+OX$*C)640`{L?`upe3I3Cc)XI@9BRx}SKGSW4~?J@-WLXa69 z3(gw2GmD0q0?kl5OwcHzuV7TwjBYucTuvReQ{D&f&n8=Xc(oqj+HOAk=CC{wL_j{6 zZm8*Al?aPik^O?t|C_kfwmq>2aA z;u)Uy-gVVcC9N@GiDkFRTq(v0NTLw@lr)EBqxb3f_U_Zg1>~j=!c2O}*ms=cOn^$3 zSjlQck&CQu?C3&OsPDNuAzDVtHItmwydy+vClG~Q@6cQ&hE?D=8mflsXll^{x!gNYu+Qn#48x+vS)-=((x zHAVVuLBV1TOxi(GE1MRZ!&IT5;Lg);Z_8tRAE@CAR8K3?+voF>J?dS&-+s zHkh=@Uc!}2uUc(qYdE*D&2L8?)bHi>{Ouy!SRlDwzb?6Xjm@{04>s)#uAC~&v)~;- z4gGs7@!(KidMyD-N_QlvWD83{K++9RG|&Yg6oElWNKh2508`I{>LfhmzB%K!)SPTS zGCGZmRxxvqB)+g1M`_v)XH7_R1F1Na41hLBd#m&2g3d(`AB;HmQT3p`zcU(QG{qJVH~jaW-0{rA9Xy5|MCXK$@Ua>F%okEl^WLvm4oEicpEIZ@snulk3eMOp8ENX+yf{ zRBeihG+!pMTehaF&F#Iepf-10Bas!mxN(az%Pe8w1mF+t+o5SpmfY#Eb?!P65JYi? zFifZRpXjyseBWS(hl|^E{`v*2kZ#o`qpJn3D*u@O4EJ3E6iU|~*mmkh)8o$#njzdkqzBFRjoF&z-0>noI=4IHFt-Uri% zVrm*x(udrzj@~d1(x)8%0P-2&@X}IM1u^^cASRL&FdI~8#%w77h$tFLQf8*4yl}7T zcoabMc$zz)!e|+!kLN$Opgp}eKFtakum}0e>Gk~uKBXhOZ|Mp4A-KrX94FE(Dfgs^ z9%T{e^w-Mt7xM?ckEV~1MX!ygz-H^Co0xY0gT`L!!YONMZ}|x?^!{2=rPs;Hi(_b` zZgqA?O|IWNuNQWl<=s23>$Dx3<@eVf?sr|L>z&=#In%FDu1cS;lf;#&v20A3KlNwa z6j;b8XepWsLX?X!Uw5c`VC#=ShbzOfzK8S8t*W7``gn_-aW}l zc*fgiLr$k`!i=&tSbIb_4>y3prJ#rw@WnIVfCIE1ivg4Q|9bfrN?(>4XjBqB<5T0T z9YqB+4JGnF4gla16yM?U#W^ITJHD^bA3@n2>J_9pj^0=%%uo~*HYO$Q(uS2bl7z?{ zY6geVAH-j(QS0gvQf)M!Tx3bW4{MnWgvmPS0E72F_sBT-L$V3nsWvFKjT;+iwlrI8 zm7;ZDQKF z%U_DN<(gKh7J#7*N@YkN(a*Rqh~bdd6aLzNAAiZwZ@8vljQ6p+o^g(PZ%-{n>C1jL zuQu14mB6jdUoPl#JCogZNy3X1yRH)r{3Q?w%19g-j6o%zBKFO zL)Pzhx%{@idtW~3++CZytGUwdmEF$ck3di_CbsT!RxCyypRX>1zB4| zui-8d)K^?hy?M(bqqjI++^e{!Db@}KAXG=ak<>|;OxYAus*Ip^NJ6CKMv&= z#81Dx^A7`3-%J$@k=gCnHZcG_4*CxX#7K)X86s*!{#PRY$MyuD(J%Kl(`Qi8f-p?i z_e+LUgjpc!PwT}N6NOcEqvv%I@z|S6GHs&NDR*V3Gbqb~f+j>nO2lF)3hj3-+-|R( z%>{bw<*|)~)`^&Qu>}*31VqLxOSVz-rq$6Wmn_<`d^@yOirO`$e9nlPz9Y2Fd8@Ix zcXsI+o!z;2a=V?^XxDe&d%?9WX=RkOq1KL~hH=d7R$A`su9|b^Uf$hZbGdhSTe}t6 zt>myA$;qhF#8gHxiA5EK5-e4G@dt{6p?e2G?rOvLhop($-#=lC`xb)-%S>5#O84DN ztmHA5fdD~CG{QtR)byAzEE)fEGcT4Z>JzNpF0qBFv&$WB2Yk^^_2s^=v-bTpXtE*OC-jE|kT7^Jq9&q)MV80t^b9!J=WVsbFYC6D zO}St`5>V1nNl)JHd}($dDu$I}S`efSa0&;%PuiqGK&m9EE3Rt(z!5}O{IIJaw?lFhLMN_5$ks`aoS-&@D{mWlYMTq^X;&mRjD$aej8aUUy$^-!qodglhU zYpsvVU&qzO^#@09L_Ue-}Z7H;As)CiXnlAWJ9Zeb}GP*L>Y^>EzBdDx&Ms+Rj6;UfW zT}IX%u4PNqm#v(y;0Zt5K7Fu8J@C%LI%uC9keHnF+p@H!4Fg0BczvG!KJV7{}{hFqhnZ#+9<6UwG~FOvHo72zJ2Y!t#&*NPE-vDS*bmT*LPGd z%}df9X2NDE$4k6a64Hk8MnD-DCc?KnSh>l}ZB^ae=PvFoR8<;^cJ5$vgIjZ4)M}A8 zcR-Gvoz~{&up(QVTcx?SxzUo+T4W8eRTj~zqKeq9ZdI4?!0mqqaj8y_`gN)*Bm5p3 zwZVMjYg7Fh<6jdC%!fWaGAtk|4!km8+2wj#>x!rC|Dp6xxvIuCqSi5} z+eR^{)r}DrqK&A;nzk(#-=?{?Ho>BzsI?VuWx4YgdiLHXE6R?pUCdWuB#j9t_U7N+ z&V1^--JAC96{>iLkON>IBodIMqe5zE8t0&(z8j0hq?O1MP-Ko-VesVMx66HM?QdK3 z+wr0wTd{($d*n-B!ps1@{s^R9Y-X(QI3C+jB<67B(@c+B8IwYX;b&)f&dpY7J3p zh>c>zL1@(!YLgYBDB3Fqwj^Q#l7P&`swi3o<(H8nt>uek+hWFwjYg_VXthSDsM-y* zM$~O#C<;uuPDl{C<5gq`faprqikZLqed(ETbABimWyDu70qwq zwY;~Lb6OxZLAA?9qSs7qv20tF&5I_sO^DhyHVbIAB}Offrj%($g{o*6mVl>}xGUtW zYKr}(CRnaXw{0kh3ZkeA43#!OU(X69B`O8G+BwfVL#SE-sz9Y^B1%dCiiReHr3wlt z8;7DFzQx0r7}H~2hc(Jw)ELDeTxb1$?W$rqvIL}(Dvwyk4saX_hKNKe^wv6uBRAas z%>PYc;_U|lp9uzlVWnXnRepGX$$YnKZSz+4uC;A_yKQfuK3-dTX0-$wwVG|JRiIln zZRxj6TNGVuHO|qZ*019IDSbD?di+#@?>}P^@i7)ms)-UG(@Od6uM*l zhj0tPl>|Z{N&>nK*LL<{28rz5|4@CN8VG}Xb-P~~gq*^JQ-0S!l)NCco|O;T#|z(E zeLpnuGg6Ea%KWvO3l(B7^j<%f*=}os<=-0e*LP~=xB-YKN~|{5`k1#35|vmy+qfxN ztf4@$qaRIlTL~Sp@h6GRV6=otYBQ5DB7i7<&+fp(_t`Yolg@yk{c+u8-G+@taNv~% zAOsc=KN&>BA!^GuOMb$A{Hqt|?e)BW5)~qeoQ-wN!wQm2XbkgV}J z$>7TASPm%z)S9KXY!y9w%Q%%PG0j)wZS}7NlFS$oaRGE8Na^>M7)rtbjA9)P-~xt8fj9)SAp-9jK!Aj9F?Mie4V_x7 z_dtrbq$2@V$dU}Nd60Tr=-}DdtQKk91%fz$DG~>1Ky9{lS{e`wtf6L^7HA{jVY^zO zmRhq@j4&bxO+2CT$Ht52yNGJ8N}am4k;w~yBU!aFkUP>e-X=>=Kx^xmP$DLU@-W-bi(j4nwEA`ajhsSb!5yb61XODM=!|IQT^HQ~e z_SOogx6E$y9(6MX^U<3l%oMHa5D6!6G%6Y(9k7*}x&a^X$znYL;WP1- z36p`DtgMCKzwy(eW_^2pD&IFWEtM6_v>!&H{JQweEz+-i_kg`OK?a) z!l@w6%_1o1{g8vflod8NB~%<@5F7zvz|f!pjfa_R3ut*dl2j$9tk5lJ+SY7CTd8V~ zC)D$|Cx@%fv(6?mUwl2ZqMUpQs;nbJ3OE@g^}wVl>=ngx zo>03 z6~@^DlnKl&C}cVz+B?a$-bhsO4^TgAP1h&Q^Uf56$Sr2_@U3$0_r3amC#yyGEmN-B zCf6uv9F#bMfz)blaLJ_(ZfA%j<5*5+L1CJl!zxqb_vP{Od{2xwosSR7wMI+Sv&+VQ z)gYj%qeUkiWgBNa;GN{yIH2c8h}?r{>S3)l05{%sHE3mvE&@#=27?&tgCh?2$ZT(; z9*tY`P84DH@~s*#g+D$ECyd3iwY;Agj;>E;kwuan-!AxDk| z9~qApN4F-?qb;V+3aasjy<*Jcv8xEt2U39H06N~N0pQPA0aPh(enThN@3imUmMpHu*O^dvE`AZ)!kG>q?d~LO>Z)=7zI{j+Q(;8y~AeU*3AzB3M z2uDdUiJ(FIqy|tul@^vbSuG+~q^LGg(LyZ{jS|CSP7so6kSx?QyH^-UK8jkB1eRb# z;o00=IzFhuWFr^sarM^L!!xX~+y9 z|COr$v;H$pF$-b}f6`Kd!9s}nGwc7tzxmgM6NcjzHsN#r8p53%l~F_nU;8!xA%Er8 zO}F6VFRpd}(f^Cc|I1+K4VV5%?Y90s-}vw3W*_zcyTf7e8w4(!Asvv2VS$@V^bjE3 zfBYZt?|+Z@P)K~?ehc{g(+oVNX8azf_P%(JS?;+LX%BS-sG#{xAMvU56L5e~n??aDfUzBjF$We}c2MbGv`J1(fbn! X|DXiTzlLws|CqayDZ+$>dIK+jjNgr2 literal 0 HcmV?d00001 diff --git a/src/compress/bzip2/testdata/Mark.Twain-Tom.Sawyer.txt.bz2 b/src/compress/bzip2/testdata/Mark.Twain-Tom.Sawyer.txt.bz2 deleted file mode 100644 index eac2b0571b8c2b3df6445e135cd70a8193a9774b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 118509 zcmV)BK*PU6T4*^jL0KkKSy?1ZngG2de}Hfhp~P|bG1$NV|LQ;g|L|g}Ui-iRH``lf z-qNy$dvE{%eFXqgiU0rsKo44>uJ#?;OD}eYk3&~!lUsY8%_%srt!fB*qN5&!{R^?(DF z0)U7jqNt*%D7Gs=0Eh%ek+mhEsU#ujz!bXxXi-#(MO9D$0B-;QF74ZV07IwR?&;qe zA8qz<0000T0+a;+000RJ0000D-Nfp^&;dXI02BbF000BT82}1$_rjFx-){Tt5OAec z49tvH_T4?%)W*?`lA%ZmnS&MpZ%n(UV(#wFozG7zHajfZn{Tu|-g^&ad*18q=`*x3KU|U0tsCyvwUG<%hP>c<$}z&%4eoxg@K#4F+Fp zcXjAG^|R5r=}zsnNeq#$c8()RWaZ7Y+}z5B+OCbowY?s^-sA6ezyJUM&~6^oJK1(k zpAFsN$N&HU00000&!2oy`_6V9+FkAI&zF}keF{F!sw=wnd)Hp?d%F$iYhIg~M=e`x zT@g2rpxidd-Wm0P03F@&Z@zQw+$q|7zPqj6ZdNUw7h$t%TcOtDbgCNN*IPdO&Hx3x z`)+&PfE#t%=rm!#4FElHTy4FqQC&J$E;!AY27m`$Yr8f8bX+%M zKql;E&cRjBcXtubGcQc9InJtd9Io3lXV@}DL#-b^eR}`^00Tim?pN6RZqKKBd$C;u zcdJ-%x~jG<-PN5=c2m+opg~u+x!s;~dLF0&&=v1n1WU>nzJOM~edD{F?Zh?f#ChKU zPys+(-OktC*^RsIofLv^zV(T)WRwRK8$y5cxv^I8_bnaRYt}yd&`4(tq8r&h;+7~b9F;{zyW)D zqt~de?7fZBD}-y@#hx?sn^5vCF-9ON|U2YN_nsUw3=X>+bn4uH-tH;hx@hIYTY=o( zTSHyxwpp#UhhILVpI=U{+9FDgjH4Dr+U;)PYycW-B!-CtOS6&4Zqz~le`4`J%&kZhxd>$iRJr^frP3G`JJ=}y>NUJtjyO6jLs5-N|JvI9?(d>WpBAcP_if(-=8p(Z9Khyc?xh7B-?LJ&Jjoi2fDJJ{On{R~O$Y)YfFUw60%$@TBpNaU)D3(d z3s|R|xO*yzrBvh-4u& z$uo%slM2?RISB>Jvha&m6|E5!lp9VF2Bc6)Z3qeqEl_|crlLlqMJEFdoUS1kR6=DD z!&s7Ka*{Pjww$Xvp%Y1`RG|pN$i2uW(lu(3AB6mg+!tO~w zcWKW>LlCBf(3|lm8$TR1vf;i zm7Zq^DqyRm;BjKJAxTpcos}~E{_C}x2WA2yC?cY2hJvCRVu^>P zDuT^j?qL)c_x-=8{d!mbzy41j`hWKS@&EVlIq7H9|1aP80Dt}$;qSlwxE+`Op+LX? zZ~xc-=^T$=|0$*8|MRUo>J@+auU$>}-;Yoq%2aX@T}q(&!Xfb@qXYDCF@OLh05OdF z>&x%i)VDiCst>^DbDPmUe}Gpt#7y}=|I6>?U60$>UZzJs_My_Au0ubspfEuw9Y7wH zCYf*39F?W!%FNy4wmsc6iL>>*s2C&wNdycZ;@~)-dE{g$JxijsnJnDe)K+wVd{js_npuy0}Gk5DtzjWRYN3qC)$-+zg3xmB2zcN8_7vm_bPCzePg185%_)zBwUO zaz2kAets|Q*|X8@K$!iq+gFzfV!=xpN{2oo}Dw0+g9j2 ziw=;<(aBLa)wYfuV^EJgS#G$P+a`_>ia6+09Vz0I|>bAc_Ah#G|1XP=zQtbk`onA?i0|d6rSC% z-~G##BhN?~P-j0yOC*kd-v`Ejo2I?OjIZP?A|^g~6fQBJN*9RBQ>NFyl{OO2OqFyf zhlo*%h^+MUC_|a!c5to}^i=CK-MzkDt)|y%_^!F|W$BaPWFymrUssyuf5LkqdP+DZ z&%=G`Q}M-Pjz>-qWMu|vx z5Qiw0=6xDf_R-~4+`M%Bl$$!-uA!9{b)_{N83$q->_8ow^daI`&cwCHa_6>9dR~o( zQp6{q{j_kyvY>U~bkaEd^n#v|aF``!nR~P5<}PL3T-&1hMI$VaG*#1To;)9%z41~6 zdS(I@SD76y$e9+m?|&|S8KcbS)OOaVl(ec3k!J}BVkr<)tSPw-_&}Zlk)4&c8*M|> zv(^uYv`-xj=Q)<3hbPabqdz;KjDgT~qzn#XHD1h)vv)Zx=)n}EYuVkPclr2^<<0wR zZ2L`pD=Rt2-T1Hd>!8){*J-C+{}qmDc^3O&VfB)<5?Z@+fc)`({RdTp^4K|af7ybo zI`iZ?dgn-$^oOryB|h_<+F(ZVLB}0~JOvK149v2F@uuZY?ABvb@^L=t&Z7T29S{lF zA!UDe@>SUVJ3cS&{yaoA>sA{0sHju5PjjLo?Q{#wXg_V_e9P^OLVh>ButE|txq_|Z z{hPGX_>9sC$$_&A{I+`T7$>~7 zHehEx*Eu<^@`>cfnt-)|HO~B7hWz>3vwX1H(;vPM^{@G~&p+Ni!9A{r++?{QYWQ&c$C9P@S$<&G=ILy-0Gulo_P2 zvCU=nh(VmUALyiWwV}q^^XIS2XR0B0%_Hr{imEvF`b?PPXSOJd31ZB3RLm_Uka(!% zdR(e>|ANh}POCz9HtzGsp8AM8g{_>%=dzKi#fdiUA>+-}OT$N37Z8YufRoc{!rH*` zc@}&8XI=)>Xy-A`;>Khq)gF^syXk5>FKnuB(|qiE?r=StC`l(Kr)sOHhY=8C#pjIC z3Z?{yH3jcYE^d2NFzELXEzs>Lqoo;l2?A&wF>{}yxo5dGea6z$+N(6C)i zJuWzs`Jv~{KQ>KI)T7(dXyBHo*;6cp@)zSI$S=!&YG4v^y_d_lrcjIH`P06vrl&hB z!t~BZi`3}%nbWA~;(O;!K^J=tc!4vuqP~8V0%-HoD;Pw_opYuPBh4}@eI6DfIw*jK zBQ5JqWW$DFRx@*uJOpzY(C>elqmy(ELFLw~1-aqb`US1xh6RmA=*h5Y!LyI4CAp2)Apl<@Xoj?p^o&UpB1 zRaA9`C$~>s%=OlMFR8rcT3>QBd|?!OMZ%Wu7lj=mKs}(3iPoZ%_1@~L2bSJg9I<#F6|;0vvl!5(I*Kye?#ybJ#wI$S+`)sB@dgg;IZJik9S@SZ&f0}3K; zl*I?GTFo8tmD4Y$#pwdi@l@<;_AUC|DPj|6k*H{u&mDi`*QF3ZLUI1cpYE8Q;1Ec` z@fV)I4fOI1Gd>mCLVFG72)B=Nq8S-KQs8}$k^geM`;=s1nhrqh;QxF0?7YOImi!;} z|Mi9c36R@ydE95mKQDjNp_|uJ><8i>{@?kZo{%|_=gaT(*Zx1{<>Tr2{CgSS??Esz z-}6rYU(a8JMtlh-QviH8jsst&Pu5w0;xm-}GNLRxq}iB_w9LxlQGsKYgAsFR6`F*f zbcYf{zc2E~nJ@O!W!v}b_+&68Ad)Dt3cmcn%*bg@|F4f9epvHATB~^V=hn`CvqsBj z&`FJAkHX;pbIrS<($CP&ev>bAZk2)20F*DJ3=SR#*}$6yg5e)xRq$i$p4tTYKi5i~eTeIO|{BSBb7)IZbz&i&88`hHh$rzOGq zXZmM+8NI~0DktK7kbge@OOJL!5@}2R2LGD^KdJv7mGS)+b?f%}cIviKRc#bKs&BoT z79fn8rvGW}(gS)>|I_~OUtOn0evdzC_RVLEl7EBwZS(yX7sLl9reYhAoUZ zIOs@O0sd*f5C`Yg$shUuet(zm+3yH+a1bA~Ubbn!nmmF1=^0^>@4@`!Ow1W^S@FML zd;jY4d_LZ(vd?K$MT}nj;jp_{?(ydglqp&VQXxnW@_e<(sl~V12fs{W-pWjP;uVud$iad^)0Q=!8WN=vhdUi>{zz=%7#XF#aEF zO81is^wxPP{DNk{e-TVFAd!#pJoBgrpLyG-#m1z+QENDUGRUZ$stBkS0uyu!fDeX5 z(}ni*!w3N%;JaA=p%5H1wqVT6UP!59_oOz1`&?kfK7$Or$vIdO;2l|7W>5 zfD0-@Bch&rjluK|l0#L6NItdZThY0tS%gGDP!1Kw)5~DAXWHZE`$xv{Yl(bfsBsQ5 zUG?oE=!CZQSIYC!OQL)u<5yO*4BOqWV*_M@hMQz0L2chn5&dBMF9{k*LOy1lyQTU- zn}rTrMF}P)6rR1NTOYpiA)>{jEidcU^*&DT`IJGjEIsZbtFz$d`C*3XB}p8q}GWcO%=NJJjR@%=J#TK5?#lL&R%_Vd%H zY24yiQ3V10X(|zG0^pKoYga9{xm?k6%xAA?-)td})o?C*0L&Hp3op0fX5^-wn z!_?pk^ff2(pEs|J<6owG>F|DCbN*iB<7qx^S?M?LU}h*oqu>JU>qq{4U+q!bApcL_ z=m^OF7~oU*mHfMZ8eN86!lI!2*-k$%%cHM9S>cKAq1&F?nj#kzXw*v5{}_oqUN}iO zY#n!@q3dBCty;agV15txEB^c|hiywo z^p8Hi-L>vz!uGpGc5ixPBoxL1&3g6zcl&tp{#?VSQr6m7!rL!P-IHblpUpJWx)4hyj;}{$5 z2haYHuYgGN=qiQR`2TNo!_Wat^&*>~U z>J#}FU-AE&@+%+NQ9=Zw>JxiK2Z{D(6Ao#Ne;en~`=r?*Vgk=hI=I08+wgr}zy8Z_ zWBYd`1=3d=lGBRf9e0#vU=b21LXYw+x{GzPd^h3pRed-?!}5cS~K)Yfw=S67Rq2F zdD|5{I?~;+wnO-!91kpnG6PVJArNFJ&@_giC{rZwA(7<^#0f%BCWvTg0)feJjv?}t z)SHCu3#c_8qzkB!@bJtS8bk6-K-qy(e$VOk3LE?H(~*aXJ*e}ER&OZOdN@)WC;Xv{ zhYS8I$M(H1+6Cz7=cqF8qNlrj|M4&V=7A?ENSO7zP)!MTr`b`eSp@Ejwn%f9r4vXk zkz8?nz47mv^O>?=2nicHJAV}>O^Eie1D_1DFAWe1wInxrN_$#gM#*znpxV!+97E`Y z@r?t~^QgYHeoO3F_nluKjmVnZL(Wein1JhxbK?Wqu8WIIk^UEIHgaJ4xXJ=R#2gNC zU&1n@)D%yNoVv1*X1XcrpS6pio!OL@9(!xKA)!?od&-~R9S;}4$M?# zeE!#O+jEX1OBjl()kc*?D%7QRz|D{N-E`Jf(Me1rN>TJ+X!t;Eb~|17kr)PYzheU* z`gbv66ZK)&=k))gRUP?C##RcTvL9wj4k`{g^RRu9Pz`@BeEw9OsZ=TSj-NyNf5{Xq z$LCPK=Jf~Z8>xp+UQUlcArXla#^XywxUCOS3(Io{(-T*Sr8|_Ql!$FRS0re)687&h zo1gB~0wmY_(i13icxrIdOy1TvFLbpR{qj{aI$XMEMT(D-EFdzH^rk8%Mo=?IS1QTk(ASBnwTNWlx|GU7#JybaDN?Dz zJd}@eyvev4;uJSk0a@w9$>WsaA;x7Wi_13h_aaqwsum3TYE-#SZ$nmdSC&m+w3o|a zO3X28XX>J%9d_zKt!T8GB40`&CUpXpL2iz2xvfKXo6oeyzr`GG1$KGi?{T&lHi#c} zsFsZxbiqgq1oCJ*iX{pmc(DN~0J|MiJ@~#u`z??`O@?a;S+`&R9oo~ORB|YWgBnnPn;@^?zcyI z$e~$72?=?Ljuf`mZo!xsWJ4OXMAH%$u|2XJ@EcyyO@ z2!j8NyhIhBn`oblnHH|9xvv+-Y%k=kDL7I;TrQqY5&mh)L%ytsHR7cSP~10u0T z6x5?cBSE2w752wCvu|n*Zi}%V9-Z%4^`ff*7(<0Z<1HljP4HQCl*rFu#*XVH5QW0~&`^ABh^ z%YGHV~Y7$;*VDDk%`C6~wo#yJrW5LBu61Q#Rfvb5BEiT0`d$>$5`N?|OUc zUBAPuKU$)dmC%_F8G6r$%XOt(`%LS-Gfa3h zxT`2|V*dE7eeZ2WSJ+Vxd6Um3h>}P`gb(@<-g>{THzW5&1mlOV(hg3?aV0< zE4JokT+*zu0pC}2Z0Oe8L~<`)t$_%#h_1*Ve26R{h!UNkSY_#BA~r#nIPjw7oDQ56 z5s)Rar)y4e`PZL~^p`99mEr3IoyI%+m>9?)tG5CK*3jJrS{28%P9;S@w%$D^9y;nA zq5?ru3FlhS&A^eBwOn;bPpb&Sw~lT%MXQGN`wU?b=csjllaOOazNFp9s5yvx?sHgk z&a7{#62S&jXx}B2PS=HXYTr7~0ME1In z;ZV5-xAeh*bU?6>mEFH#%Hf__2^PfGA%*sQ7+eUx-WbeB?h~J#eI=KV3J@Or!Hu zJ6^lqVkUb$6seA$T|RV^^%r3raChEbSP|IWvjll`hYl<=ZQFA3a2~?SaEb7s4EcNK zoQzK@b*Y9Y4@@beg7z8Yr7o{Lt2E1THLKOhWBpI*`kxGursuz1N8@_;+vtF0B2n|z zJXF}=M9KjwhW)OCReLVlbv>YvNfvXKtvKPs5hsFzH0NcUw}}gcLJ-Axwnx@q%1hE{ ztqvG+GVCmj(g`AtwU%sXjZ$eDag85dlkegi>y8=5ZOd4i?57H<&sM`fS=QO~uaj=D zwn-zmWR${*9jy>Fca7DS&7I{CC=S6BA|f@W(gJb@!FI!WgMvMKpsN zA;|2hQ-Ne)oIxApFK?o(RLKvyotAXL0%>aa$=v0-3ZzkKK&jfL_bmc@&i!_swQS;S zAP|UzDyGP{|H19_Zzwz>4QUc3{j1|-Cld?M_NqYCX4@pXF$j2AxHytNl^FZ9=>~Gi zp12w}z0h*VR$DLi)NiEvk9&#ow7fU;t6ui?o3kDweV`F2pb?;mE?9@tw6myGhKDQP z&ZIDjqj?&LESl=uDAVGN8`f1b4KbM=D=UIs0i?C{^_zN-iSVu2L@v5;r)uha>b;kE zIzEbTTP^MRew=a8Gb=4<4bDB(*SF4k(5GWfOx<%{*a|)6RC?E1V~nFyV@%uaM*Z&L z!g-eSFv-@V6Anf_jKdyzmcdu`%aa@1s&UvhUzmK5`%X=)t*AqTDOF06_Gd7I7p&^2 ztb^&0RNDG_ikMGCIZ`~1oYO3F-D@1l`uMF$CeRbu2Ezr%zt?s`t_CRsC!M5 z=F%Oqw!u$Gc45L8lS#YzD0?%UHCx~~HQRfIdasL%I2P$(<1~dm4#Mt3LL zq*^94MjhMgC24CFC!HV~IEu7iXKWGCF^eN4dqi?1z*R(A>ay7PNILYG$&S@BNYjbb zLliEczmfgi5b0<_`^qi9YS;|wm%mXNL?#o)VNN|hy-fNvD_*r$f+14r#FzH0(0V=_ z*~hiXW}0iY!YTnM4$f58-Z>io!2VgagI0t85B>?h)9dX-{Cs-MA}B&UILFZ+XXxYe zC@9X-c9?H5%&TnrE=x&VeAc^}nM}eiKLrWs{c|C+axe>^50{vGkp5E7qi7E?uNvgw)3N@FOP!98Epvx37ve(U8_ z?L96;B4hA%%%|G`mn+(3bq2Pr#y~B93aMp9SG5Xo#2z5jh*4gV8*8Ilwex){GqL~r?KHcK8`W$ZagU12#1U7q<*Kq!zIGp-}TI_;7g>Cq@F@+AxdU1 zN7AkRFMILXuMgSZjjKT<8du`{baCkE zd{5`nt`TOR(C^9rGCA54u%20G@PhFH0jy|s<+jr!X3ozJ77%dcf@Nv6$d4e&421{T z4rj!p;p&PUqWIM|e`MwN-k!Q%T9S6_<68%21??B*vr?wNh8UBpzPEgLwpJaFi8H^P zKee8@N~rRfivrt_$|*iibaz%6tsZJ*{rv?!pn6%-vOLpL4H2asf)B8~Q|?~6+}Rot zD$*8edfNf#T^A6xxe3F78U3%OOk|tTq&(PfEQ2RTxaT`i)Tgc^+SXHD2P1^Hqt2 zH8C%Zqy}JvEo$f=8nmA!X%In76CETx!S)7nh!8e`X`QQ5|o04r*w&vCah zkWmTY>4w4I65&yGlhUzmTs*dydbJvwv~)ymB4x^=%>DTRwiRSrcep*&DAOW@Gpziv zqn{4vfjxYYbLN**=MD6lt|7k=hKOsS%TjpgL%LrpkpU7a(ff7dFjyhVoyZ77GLs(< zSr-uD2@2WhJlGo|$Zr&Ljxb15QEy~1C}9)btw=<8wXFNTK&JV;CC#3O!X>MJPlu_G zWs4~*P=sqPoMqSk=igrW6%>-=!MccZt)dQB+L0P# zGVnygLpffusB1_S-&dP>%%eM=j42)SJ;i5w42OCf{5ZP#KFxad8-1w{&X8|^cVhGm zA~K)4d}-g~dk+!Alah*#Q)uez(lwl#fbUnIk-d43t=ae9!%|;F4#Y5S)3UiAqkkD{ zZM#0}?tuBuFUA(%KSXJh8eCSpMOYeUL!7^Cej?CAUt1qvNF(PT-wnYr?^}28EpZ*Z zvjlLj@Eq~IEll@mR{PucyxvQ#4wX7cd3k3Jq!-UID(FIaeb=4R){Gs}<$}#ZPadRn z@UP6PWeQ`x>0x8ab~f^gL6WaTz&4|Boirm*Y2#@x+uG-Tj&U4A2 zSof$C==78!B78`eiOVvf#S!YRsWWSZk~qQ@s;{#=?VGZ z^-Q8y(hL^b1hMTx+59@XWfHGt%Kz12dNhyAkRh>aLNI!lx(ez3`trb+?FfziscQ6&Q+r-NRldu{xg*ZnKV{^ZmIql}vZl{*74!8XwL^ zHHsb^A(08|Y0$7q*&8&(T~F_3IZ7((V>`4xFuCSlT~6jO59HN-k$v@={~RV88P~yL2jX+N=PLtl3BZajGp{`ne;?2NFBa< zj5v%!S;S4>nrJ-M1uu!fddNxM@sL`3?^9<-;I6)x7gCc|YnZv))>77Cx4zR!8|t&` zIHlbO;7RXisHraVGd7MD<{Hu2dGkTO5aAECQdEuUjzS>5kR0Iy3or_&-04{L+DXi3 zKW_+wnE{V>JAm)}&R4}V#Yse@br=c40ubg-8$nMEoD=jw3PcRRn-ptaSi07M7S>kM zmXQ_Z6r2?awEFe&`S+G%-*c&mysYFPp=oSQq{q>8PUaky8rWa@ab4;_KG*t>TGyn% z9Eba5Zb6mO1bb<}wW)gjtNbkY>f%43pR@f9V~*eG?K+nyy&{A-k-*BWkgJq^{0KdH zv#mOH>n_gk+P`RfNJ8v<=*_M^0%q~ZH|fxxA=bjd_vQXczwh3xK$a9kR~5Ex@uAv&z{SI0LS; z3?Pr~r0$&-HIV_af*$)I{d>To5s(O75zz#zydIeEZ;U<1P~J;8H`TGDF|*(Jo!ID{ zOykka`KM)9Yun&!Q6IbnYrr8_uCKR)!&!?(MLcHwN@uwNRvw+vEfb_dAB=?;zI~{> z3{$jVx;kj>Uvo0YpOnLbUY;}1iTlXc@fx$Mm&L3oUq)0lul$~Q#Nia@ecc&^l+Kp^ zM+p4`1a7LE^OP2h_^tgYBj?LsKN`8C-z$wBBHa6lY8&D?_a8a zcG>HYeYOkjsr;GO=F``AJ_*FstVC4>jm~b0sw)9v!AbV>|3>WW61!-ippT>0U_?P~ zt~1YU!m!r3!%A(L<@eH)b_x%4rwCPID5EFRmGj0E6xD@c)?~7Q^FG-+1Ep?}{SXkP z!#jdOIKR?k*{?~31Z}}I0hl%L*(m%%~>M_*%e;&K2$oB}L&|2%>oIoQ8aq1;Q zn}YqGGpeA25e&Grf2gF2~CiDATApFI>^AQ(l ze|F6usYO`SWuz^GYKmfOD9qKvxxdoee-jP!Gq-PCZRkoMNcjJ~!D0deeF_G2z%f7= zgS{xrc+4XE(xpvxL5JG8Xkn%ec4Hyxhi>HNl!AySo^>M}$ z%U`??eQ7}xNE^Sbu#U}qKW5_@I2c2W0!B1%(guKbnJUUaay^7kEL(ZsPTVw*pTo}N z$zf@_L!%NIcA%1nb4r{q~5IwkYFY(P-*3-qd!;J-$DB(Ar-V*z?SO zmsK0Bw@ZzKE=NT}Aoi+oIwAZ+}ej>$PTQ zg>lp;oY1C{RRK7=Nb@Udd(oMVoplZu>aS~gdfqv1} zASag}sIbx9Jce>2+cJt+bjqOPf@6_?1y&fj-v6f>G`+fpq$jE$-c<9{jd3W#pA3&| zy}M4!rLu)2WIO4TFxu-$^Z6<**6m9o4!Qo^-yj^1yyo3_XUGUeoFkZCD-gIIA`OsJ z=@X5Ds~f-5y3Bf42SFYBQ2b6U!_HmRI-=jAC*oqFpS?D)p^%FA8ye5Pwc{v5hn%K2UoSOs!fU3gOWB(c;PJrs7juq z9}@`RxhAs?@NCHMj)kc*nSa#{x^WX04I*%dR0G^0md14IQ=X@~{GJ25%OeR?4Bcsa zgSJh2^1{DLJm1`O{gm2uY1V@%Q_&LLtKQO?Bc&dT`}BfGL>Hi>Cs;vTqltm5V$$fS zI&RT$y(CEZJ@tlkZFRWn3SBV|q{TDK4^WfO(zGCB*lvpT(7!9V@jFs+>(Z_WVwc(t zp9tzw2Fi2vzrPQA#5Bi$fo5fO`Htd9P-8TWn2-GtV!WRYxrG1QP$Dg zGKuLlwib%9N@jSjyOs+5R$a2$aC5X$BMZ}LH{nNnsA3MaP8eR&>?VpJ)eNb=*HyG9~gq z&z&md)G{gdnCWPoc+gcb4rSP7AQA3eN!Q=^FDfAeG6rek`R}=WMfqV1Ahn2PFY!U` zzJ0}NRsf@gc2G~Fi@h%|v(Ph1AKj)K$(=uc1?7*@OD8;yIE;3(sL8X12Og2sk&pT6 z26d05Bh0V;m&wE4=q9hOaKZ+Syk8e~jf=>th>$~3?LW;z5wn2mEjzK_6htvW{QTQ*Zt)-?^;mmq{!PYZ(Y<4QP8fvF@(| z7!BdZs;n$)iIEqMl|$j!-}HIHVAv;GZmPO?90Xw+9?X2!m^xHWbv@!eU@n*g{#i^K zo5CC?+5{w*KQko5E3^)&olegm`$Q71aY;mWanT=XgW{^CDk&3V1D{d)?r=>LURoFP z9apk2(l&GrDf&@<^X9)3?yVcy`YJsp%V%+}X?_;cW{_m`b+(n;)u8?eZ&{0yZ93Cf z#|W4&0aO@fRChUGdE;gz#iKv?t$XIWGAv~{R+-t7)22yvb47i1KC|lQ(e=ot&V(v2 zv4%~j1tlz@sl%rGh5q!+PpMb;#L>gMkFU8KQ+>;QUZC;@Xo|~A#@`R%;f}x z#GjygW%A3r{8K$MnMMqj%v@$Ebs8;B4lb3Y!i96|EI5oUl3nwsNMH^%_PZ_p$Te2z z-xs2r^_9P@Z=9*51-^eG)`_t`Xhv$?!DO3Gx*`q0pI&Aj5(KxSkMNM;`{!W#&UAua zZ%%qalyGmQw-;MVht)q6B(YD0RkPkvy?VU>pzY> zgMj7_hEAjU!z*!`CO+RPbT^qB+$IAj0~7F*PL6JTvuvxw1GQ)99kv zqtH#NBnTK6?pAu*GU%1`(=_7gg&gu2lU5W#dm`*6wGu7DHi!sHc2c z9zsFI0#5rz8AE#}x>xpD%%gq)VCN}r%k!re$fnh{ZL^86di174L#a%7Pc6lB{=OfbTI<93f?FbY(!JiNV1;*#ZyQY9DZ&?a~6b@5tnQ zA!qL^7URi($A68<{7mH>mdm>j#{IqWKA8hrteaGF{DQ&0m0mqigEtAoS8kEyDkgf) zBt-~L&=k^$c6;bU0H!c+=WRZ)5`bEE8_KR{r$^@0o_jWBkob^0{C8arvKI-SW!tKP z47mF$BURs@mA>sKS;`)z4^k2lpD2q9ghav{oz(AhfwJdBbU`{;koN$6#t1a+E1DmA z`_)b#p5Z$rP8+&Z$D(!ZO$h0_N+2e0Z|6%h5S1ZxBLgysWk_`$B5MD5%TMT)Bm7M% zfvmgM%Ms64A574mzHj!g+xfP($TA!G^R@+?5?2YtWmKkex{=Ggo0whwq z1#i|wS26jigB5gI)=MMYuiGB|L&~2Bogvz$Lg-$zCYggA!g0MrH@*HP0unv;v>(@)?mS3oQV@p7M28H|3^gvql1U>*XDWc&Bsy)! z+l`jqrs+QQ`z-yEMrLu(yxZeNak(39RZl6NHJF!jOhy9I}>ujlqUpGT@) z(|q-7)_8rhqX3iLFy z%4DX6gbWCQ0n13;8_#3b-4cx{_m} z7kLgx(sELHrhKg|{|WV5a#=RSbDM4K&$QCV#`h`B@~E;XZS9-ALegJaws9I(>p>@6 zrq#x@6}661Wb3Nips!C^drj$HmI7&q-$yL*3Ez8Q>y^C$ka2*qJtj72Y6)TBSLpAl z-ssneJl9%l@i3h=?@y-jK#fAyJDBf@61<7$()0ZJpGIurQFr5r;}74V*O#t~s^xgy+$(?9RB}r?WSa{LTi+(+|`heoK&|Bm_KL} zdtChZH4Y%^ju7>0kLXZ<;(DHX`QH5D&U)$)`eonrPJ4I!A|0f5p17WlN(GN0B_Vu( zzso)-c#qtxF-#CIXdL73R*NnYf)^nV^yxw=HyD^}s*D_V>t3qbZ*B7ZQSq5^X=8xH zc_V?yR$TD~wu?SjXZotFpDi)u1PX)K82Z1;%<_L}yW7$Qr6;F$KnQd}Ap@cWK@hn0 zr!B=>l%PEy<2MX)nxAnl$LY1U8avscFj2S3Y|l5*BQVFBvv+FLQDbVgz825*ONz@f z^wh)A{o8%_mFd?}gm1)R0Y;a#_bm?g@}t+h>LJBdLB;m2XuX9mR`OKhR#g?*ekMoq zEt>Ru%i%$NTIjv@>^X7LqCV)fOPhyd{Pw!k<&b$CDBk?g<3SK9jt3LusVG%_B5%z7 zy&W{5reKB+g8H$K>C`pVq-@qCKg-gDK>wT`iR@=ZpK00m;+k#Ek*&W)kgXI=%Ht)7 zbBZ7#1@i36?N1>`2%UhKW=bo?m9?mkaJ)N3>mR3AMnICOq^NIYj(SCn?uQ|epg$h9 zXEPLv0S+gU9462t2$7+>S7{cb;~GqC6OYM&p>xia+RU1EeF9o?!cF~5nEPw^dmQ8V zbD)v?bpkS!LnO>)=@`;dq7AZ*`VJ3SXK$`8Rb6LHdQtc73zW-=>!%P^ng@D}2?eBE zD`0+0keo>!Sv`sBEKC}`kPnd zHjyC+%C2HLWAO|?u`BA`hDruASk7CcQc^H$YM)$@b$T${ zwa`+U$P7OFPajgzR4^FflD?kGMl8!J*gvX5@rQ>bU8>0qgI=NktTrpZBslL!-xM{3 z!Ql3KN7uYce%^*jgNIUbhiy+khQ!^96GrEEGSHt&#`@f}kPv?~kk&RRF;>1LpRTm_ z6DpJbY#qib|opzOZaL3jHPkAJl*! z=9HWeaxyy9>4)U*yAK6fy)zy#_|-a+s%dEd(zG7VIm|-R7h|1 z$4vlcfk~_|K!PF$LMQzu=84T~WsCn!|MHd`<1js+NZLBV!7oXSJ!q>Br1?_rVWam{ z_Cw|u84Nbjx~jZ%(RP!f%?VWba^c9SwHT#$V70xob)Hvv3t&ACc-cW$T;injmnrGm^}zLcgx@{T+y? zqEQg2Z7xFKHuuO9^r+`Wiyip@C_vZ0vBrf+P`#(GKId5c0qJLn*RX?(sNOijk}oOM zplC!t-^|^qZ5I=trO4eeiXwVVOlzNgXw(W_5Njo7Q=A=V9Q^(!?{0X9-Mwb#5!Aj%P&$Ra##5LA!)d#8S&LsM4c^-FxSG z7nvP39eC`gBUMl1G;Opu54NYuQm(V7nan5_nOC#v^+vhT-#Av=#QNjI%QzHgInN%) zc9)rMr3?^-7?RrJBe#Y~r&L=09UqfgU7$Ev!x*(o*#~_|ghaV}2b{^8^3e+;gDYK_ zd4o0Kxni=ayL5dg{m|R2{6dKJp^Ib1Nb6W$mtSyQh3}?1v9_|C^m?&mw+JQ?hKP2C zFSJCYcHQQ{gJm#n2DK-;5~xbvc6;N?OEP`^Z!b$z$iCGF$ADqD$q8l*`zW7=#iEUN ze%09{s|abR4ubI2&c3@3u75a@o%==dM^f;w=X>r+>e`5Y;R`hRAz;Dcsy7)E$j5Wi zjGr$h#>%Kfp<3(ooRoH5K@M|z@3lMsrRWo}$Re}zZtZP6K_}J?Rav1Du0;U~YaRZN zXn{SZbo)VS#hv-5B+|IIv`w~>u4=NcBi zeP1BE#oSE-V}FTlcpRBdrV-R?ksjWNP)sfAphZf1ajy~{&3c^JQlDeU9Ot7?e`_0q? zQ7_Q#;pShvh!k}Rx6@uqG*!DhWkzUkBB9kpGA%;)9{}gX)`5RrZFb{CImyYIYPH9m zc{DZW*_X^#sigWLdO?4A;Dk?W9`fMuuTKz|;-3o(T!wfmm~4b+%{DwBkOxsAX#`)c z(XsJjZsu5`Sro|to+0_`rX=fgb;ov~Hfw065Y%-9(Qh)ChW84j0>KjLs`)!IV?;eAF;l%2~p%?_g7ilz!#oulWp<8tM~B4LOM?7T}|I%J0>(RH;N zn#CD$ClYa}k`(9Mk*_CQOs+_-NPnsK{t?Iq^`-W@_0zI=lQu?ME=_G4%1!iu`&d@E z8J3BR#lDU+$kQXLNJ6A%^9n~s4I)u@NiH+o%u*qiRN<<)WrZiYac&dZDH`jBFOWI6 z7qs%=&yR;IuF_9`6kN@=+4TxN9Au$Mk=u64`PhP~*$lxhEFbi9>n0nAH*2%TRd+3$v{@vC2f^LfNC}@SM%W@EOgk4u0gD7~*+7vz zRGNU{Dj9TIMWm2BGiWW*q@q(VL_{DGVUtNUA@6Nf19_nN1y&D|IpoBibyg#D()e6) zos}6#;m1dZ!;Fy~N?0i^%)Kws5-<2)+b9^E>$V<&fdr9h3E3W$G4fQu5Fvy`B8Ic+ z-i)S_bWxAYgus|Wf}w}2e|xynIM%SFJNG}mY*EJJ&j?}5`7AUn6u&e&Fr9q*=NY=8 z#oB}&qbitgl>nsZQ0R~1BMRX(6wkcN&uTM$FRfj*l;JfN&YgrHlj$+xRVYZ4fSkzX z?qb&AghCP$QWZaZ-W3GXj%n+}eHl~Yc>OSk;VB8diw)rgau@)!~qxEyTT zNv#C*s5Zz|dz-}z^5l%Z<@C5K;VrYkFpM+hg^YMBE&rg}mXQYEI^voh{M zeHr1e>(QR{hPS?Q@gZy6D0MVXLC`f+0^H)!DNdV>G4ia5t%*2wyHjHReu zperl2PxdcPs_{jm0V~K8E+A1=2;tFb6;dW4wnfqq;zcaiiS;8;0x;9V2nRsgd(%Z+ zmCcBhwhT#vhv^`#jjmIcBHyO=hMDN56Jz`9637n$WyTfG_dR&3H&a>Bg=rBQ%2=Zi z)kstRB6AmZEf?K&^&vGn-u#kNI@B58%UNHQhIGK~x7V+(P3GDvlqji4(pAANJc#j9 zE6~d8Hs7>q#95XeWGL+5H4bTaZ$?$7JT^A4?^4_gtE}qZuX6a6B%hla_R(jaPKSS< z+qN&<=qw_1b9Kp9XRnuMzL?@mNR9+-hfyw^gngo#Df_R3t2PUK!{u6D(sXd4mRhC!Jl%+RpbbLdA(lE4z2+q$G@fXW|mB-gbkOvb#+{(eEr4HS%#H3te#-E z+b|yT@#ayqj?CSok&E2!o@D}Pq!38Scuz+iv^o>8_}i6NCgIVTA~{?fK*)cU^Qq~e zX{)S;6tij0O`7BVMq@if`Xj9p-7wQMjjq-%5mEJQqRyfkW9elNa-=wJS$#h9o2Tg( z8x_@DPTFb0?(0$@1QY;fP`bdwxYU38BQE$F6Fq4p&Llv zkw4Ig!6U*raAgH?PcGGm&edUvomyK?jX+Val<=1P;OL5w#~)lynI66EzI;gP70wr` zW%)TR&MYS$$k_L3bd;v|K=iW?72EdF3-Kyz1{TjUTxK?jtISqXz}g>vE=en_iP!la z^4D|lqO$E;i;@vmOGmFWHcsKgN~Tx5hNz$PE>EO~_Cw_W%th+nwRxcB%O6KxYA$Pi z3smQ6LftiJRWeeLWR^*a6u{G)%0w;NtfD!aRwT5IphiMWB7dT&TyIvVB?|DbCBtu@ zP8bt?E&KG!rx4sb9Vps)7U`c&G8s=%{g%qQr)mD%h=o!+l$LRMC0?2r zN&i`LL{dTMf#oJ9|LT}{?at2Ur=R$${&|mjOV;ipU`MalV&cV`l6sK8na-vHDMbVs zRTFN#f1EQolkS~YD9+0cXTRC7#K<6X`Y`#|O-`35dzdhEjv#a?wBi@{QLxzAb^cWR zmVVVWJUQd(K;;OQh>-RBt13YWQ%+$_G9fxQq{_}GpHve&y45SD)>j>CMbtGks%Q3f zV>7PDQ@E+FDtEQ1!n}ag$d55hNtK#7+DvPC69vg7bdWUg5BLvQ$MXH(`?DHhCcYh~zw(zLgB2#Z)Ccmt z`VOr&(ogy1C_r23KfQU*CCBsi+c$ro-WTc&c&FEwPN5)$Ip%m_#ZUA*f_=(SUQ~XW zi;%sJm{UFuM#0d$h&97ZscZ3{%iXSNS7%dRN@Nkd`Z|~C2NPq_VVeZ7zpn>ZZH|<2k@m$P z7`w;}IHZqVqio{IAy4TQXUG7TA-T9hbH}0s&q^+k1Tb+PAV

Q0HldgvL$|8{@XK zqdR)mHC|c;Dj>S#xnKG!;rUDv5F9GUpHN}z77^oY70@;u1(FvDWVB;gbh< zyQ;p^irb`?L1kW9{gytokSW-sdI!=ewP$osv;$JzT(dHz9Rv zK_r4fMnw{8?U6ere39R+u5FUfhIu2?^om5qqOz&{sWDp1&%*Y=>i>XIi*upK*(qH548dh(O>lmYycw`bUf+B6*x7 zIex9Z<>k1DV=AQh$*;q^9Mvs`gyvcCqrj=|{rcpx9_^!TrCO59*7l_6^l+mp>@@4> zx+~}sn_uB+MK7rd?$Cx`wT^yWjK%UiZ{52vI(`-YE${5i3hHpV`YU=*WM$Wlt!8@s zeHj;3vs}n!+a%5Il>$NWFDCfB7aCZJvg!Bv{W-|D+E^FEbQ9K+VN@ve_o^MU!zv_= zeA^zJD5O$2Y`Fa+USW5hb&ALom?rRT0uZVHI>=cac7;Rtocey0XJHIFgN8d$5EYbC z2YFTQsoXfLRf6o;4%~)v?oI|fAYus;Ek1f9=DU!Z63dkVl!qj+DpmPu9@H$Q@26jPw@CZj$?6YXM~&=0(Y4FHV{ z8(x+tXQjpi=`tu{N&2z-{gKljX!(?PU-wHO#;^uQWO|RU>HH|kA_t{JDmDJfG=6jO z^_Tm!U7z7V{(AS?SZxA!euS64U<_ig`av>49kdzPWdvJe{!Zl38-(_f9W3XxSsmva zFWL*stRa?1m_^*YqEZu6oyYB+taoq3OvdLn^6L!BAmJDF+UND!i14u}DOTkE9!?mL zT68EXuwcvmQ9kkV1%CSWqg`*5H~5=|ff`hFJNni1Ht14nxxYfW7|+sM^tZ~k0Rxo6 zxL22XWeLHXX^q@$h1|!=`bcJ+&UW}KDv%u{?EyONF%B^0Bygyy9{peneBKMM(18a; zkAF?j$d8|k5e3CU;S|aAK+%C3UEd=YG3>bey?jEwcYPmyfp!Oa8o9q*-r+&Y5HbC{~bNaIqnN@vlbfVhbLqs;1hla1_ z$zH0%39j4p6|qG5Z6<$4`K*R+sf{FY6b4klLrC74N|NfQRGRC#N{)G&BscZz@Xjy9 z_385~#9DCuGLlJ+{kDtelaoTKbz=iWK}Lp|Z^tXjrb5H5XMCj4EVFF5X2PEv5M7D_ zFZH^BTpb(T#eEsH2-CMK)ChuIhUv5z1ds_~#i#8`pYVF+j%z(^Q^wx2Z1HIIG5LSD z&kMi7PI$EILv*hz`d+soRwqWAcX#^U-yVCSSMpy_5I`f*^TbXtM+biQWs*jIB&TRR z!FIP|XY)&a?s%7EeBvyD6lAIi?&Y7)YN6Z|W~XCRiec1rPzj_qtg=6f1y290%fRex-r@9w<^hpNCodHL^9aM@o&R`caO^bcMian)tbC z%d_9@ucPnT^6!dp(=pOhsqOxmD8u33DSr=N8ycrq1)97w1e&PVqeqEHWFU~}o)E;e zFHIvZeLG##zq)L?+byA8ogHQjpN6`Lq<-557+OjGyWXdpu8!ddT2m!I!=`x<<&{Lz zLt*%p(StZjOz=dgU+9mPX&#tb&>?CYnMvi6yVc+YDhvcj>wL^NkEGm09hU^c8y}_2#1a_}%MVVR?doF-MD+fd@A)Kxs78w88Km}zFgJPg zLm4U+G?2EC;U+Hcd%vA&4_s@eh;<@aLb?RBF`7?Nk7w&m#^?wJS8s#_{M@rdTeA-7 zM38>D)^h=Onkd6t?eNrzlmk5`7Q>WGcv^XsQ?uz)68BDA{#z>LyHMxT%Wfj@OV&Ne zvEi5E56%DK%d^vLI5XFcrB3fMy9m@|b*xy7#*#{yKLucE%lmYMy zjRL4$)qP$0Q8znOp;pGQ&d`M~H%uuZZke7|3lSueRbMqK=sHzA%x5DR>F3Pr9ATZ7-sl?jf9^B}qJ#y$23l}FjU-5mIca=?8UCd<0*--43k=={Me_yY= z=<_xYO~u5lbdieC!5j5{VwR*`Yds*R2Bhrvv$L3Rbjr_5Z3&>ar@MR&7MHePMXjhX zEW?_M5GPn^A&tM>b!;Y$2LG?%FLM(mf9uUHJ_qG%`V{nu0WyJ25Ovbw*)Q`$Y>Dzc z>r-{6=|Vcj-CBO3`hiU={Sjk4VS|VL+`$7slAoU=FqNL;jQ=`=TgSbl*QI7dSqf2T zv+%4VmCY0q%(L5tyVEzT&ZWUE0{?aEJDPo3Ti>}0pou)F2qElB7)v!NZ^iC)xZ?1W z#-Ze8`iORRR=3H^P@@)@wQsleVq@~y`Q3Iv){Wu)a7|mY-onU`NKtARm~=%|l7Bre z82LyvCgYoBx$ne`7bAsKb3ov4pBjkB~XyWO-NZem3Yr=C7nEk+)&dlG?fF7OP?|>!;Yv& zpv@1FDCw%7y5{1(vkEe)_g*ziNIFU^Pm0ka)&E5J{c7~Bdw8~i8G=%fQu|pJlxAiz z4oAY@vRlaqBc<(7bkoh=6G|3H9hFdk%eUAe&RP^tcG8?d1dSK9PS4OG=+>I*+q9Np zTi98$a7g^=1C}x3Dt7ZXoY})c8Ew1~y1bsrveA;?$wIT!tLv6n$9#s{n ze~p4)rQ_*~C$&t7NLy~nH%tD6za_s=k|}Z;$nt^(NK{-%Z+i6eaHy1_x9t;2g;ym? z$}FVEn}EKN<^|JAs(BzaK)S5md>}7p?uR5*nk&@^448L8C0NWlfKi;9AzMNik!qCh z1a|xUFpJa*G+|E6f!;7YTo1gYl6yI%&7CeiZwNph(0b5IoT)_g=)RFBVpx0GTp%EH zbVITcb5im;0UO1H2>!Jw|DqYSfSMLbK!TF4;tcWr?EdGtETi+ublRAhM^Z%3>w#n0qKJyIB!Wsta0cya5>j@o#&q-S6noBHjpyMVQINUIt|dw~e-@O0%1bu? zSF*mNhiRB@Y7p$USz*z3raV`irL*=NFqTAD{{0SD1=V+<+b6VtE6geE;rpTCW*abG zFEq64w1q=Gq8^Ph1YY=#PINLTvJiMg=1zN1_UOkE-m_i&MaB+k7K(-KDNqo0W3Dcm z1J$?h&esk1keN*lmS0{vkIQ@Sm>%G7?KK1187+=@_veN!zvyX6zI zgoi;IL1u`f-iBF+4jAhP;R#v=W~D~-l*o9E1buGZuGt!SYQTp$jG(=;h$9e?gZEWo zgr&;0@&5z9YGn9`8hVcSn&o4k%Q}}2)V9foUHE9;5T4x~->lTgZd*g3gs#an=@?i5 zn5H0+m9Mlo_VgD26W)i`zs9X^wo40!{n8-w#r5mgT}X}a!0iX~dhNNlWahFRWEe-K z63RN%j~?c`t%${a1jdMXPdbHv0STIZog9#FSiIk5aw_FD)GVP_Pu5&U4aY&dAI0f{ zH+&VxmJ-RueNy5d}Z z-Vd6yB2j%wv_8_T@mca);eBgo>o{%SruymMUbC0>{8a;@HpK!cMUZms!SSP{L217x zc{jY&S$-%)m}>B>ZNrAQWqmAV_SlhO(#;85Y~@uxmJDW9;Fw$UO2$BWgkkAh;=`v-_%9+hqdcbWFRLTOvcKDv`~tMdM>mq#Dsfd zl-a0`&G(b2$+k|tX1U1XjwZ4baSBmT;Nj6T5kmg{{Res%!&@B)?Zwlo51y%dukN4+ z2yzhO$P#c#BOdq5_S7M^Ei#$OQSGQnp~5K;2O_V`3x*p14!L3uA6i`>M10o=B|}L1 zHE&7(_LvTc!YiTz#a_-Y&FaB2d8?~`3;3M9m%rBdT-S-`7=JYJsr6~%o{{68~VWbKtB_IcpM~)Ava6EooaUfd2Nt^v10*AOZ1AR@8T^&GJgKs8wUruscno{ zZIr^$9kfW(hLjxj&I-v9DN`75rlAzjIc^p~!Z=gHZY>~;3N>rX?CjLVZa8`CHZF~p zRJ9D1^7Bh*qiFiL)kfC!Iu`T&jhSBhI{#KK$R5pSXaEta9T1Ivm%nok&j`=l=g(Nq z(p*8{5u#BjE8Cvrl@CZ1+Yci|6udvHBK?~D&d)@(7fi)FH>e&mwtu0ldPMkeM{H@1 z5tuJKu(K;)F>h)m5iNZ(+lRxQrD?*xfm6aFy39JBEu-MC#HbZ1@@?Pk%&Q@hcw^SRxY0mUvJQ>arIjj~k+xeHziCeCbo8{{JtW z%;&!!!~4L6R~cIw@a@>S%IyC3p6wUYQswcizI{CYRh_}t4#>Z}tn*z!y`g7mFSTg* zJ2sXsMY{dp^x)E{XzJ6lV_+a-RCI$T)FvhC@ZRl>5v_WcYlV6%zLN-Z{oqdvN#ALw zxUWl964y%zagx8|n*4o>KDSl^A#<#V{*7nqHV@f(@s6;0FE9_r1P(iOD$VlxfN>#Q z*}uY1{P@~n@K6#N6dP@GGMzYyOnOSPL;}6S5%g9R{*IhELm6HL$_dHI<=`%MRZPNT z$;f9+kg1iD*9GOJ;>!!re9_y;RF&`UpjeRDSOm#IlYzXVoCe|r;r_2r{)(KA#C5fZ z$7+T{cBLxMzNK(x5J&N7b^EC^k3~Nv5k8|N$&b58pGWH{)<%_1w$S+ySfE$a1$mH? z`ay3F$dHsSV24CQ49Fytuga#KPqWdpU+QbUxFHBn>aFOm@=5Cs)|fNm!FFL{<4K#~;!;suCxU?Ct*efL;4soI91#3?rnx#1G9tX-TBxy2_ry2uair z@dO3oGdXS2hZ1kp!y{L%<`_k>qch@&A@N_?y?-GHsoE#0Dk)HVU&KSq>`48W$8Q9O zOA!>z-sjqjBlXtIQB_a~I6UD{COPZl3mg2U3iKUr!!c+*DjXRMmV~KL+C(LG zfjw*2E0dYKA-G7j#}Or}Jz5bb$k&kfTKwoSev>tf zJA{Q$SEKBS(SC?xMHV^-29OlQ7M#R7c5vNh7kaQ)!;vsa*3%}{s5DT~q;HIjVk+V5 z#Kgim>g9E414>BAm_R<8(ffqSAAf#>+n_{FL)7dr8Zn;y9BLy3mt z-uJ+6b4L12>=kQiyyi2zRmy5d`M)FUJvlZ>`e^OQ5L@D6>vbZO zc7J*50VY#XicC9(?{eBi4@fqu{(Sf4#pq>3*w2a1PhGnWcg|NO5_9cSP^gd*Jm~~5 z`MyHJj~OxO$pacTzg}AhL_mTS6-VDaY9Mq)1M}wm-W+>Foy|*`(2$^u$r`}85!szc63672!@Im@&nIalP*2mHj3kk!1?sCL^tA`iiV6^#*GjLY61i8_*T2_qT!ItCP^Qo!+4e@t^8X!RQ=uHwxFxK`6Du#!~AC>dPz<}&8YnDf1ea*+J zv*=aw$kGfFpH35``jolf(hThkE?PY8Ne+D?A(&52mY;>kB{)8U+juMZT|#qx+iNeq zAFSP@3j$_3Wj4t7Dwe6!EC{82Dx00<=*wk;D_pZ&nF@Xqddrv53N%9X?Olh|MZovh zfGHj$mho4I$j{0_q=cj&hO!}seDwNZHW@_q&9p=vb-eXDw{CjKx$6sjKu8G46#hE) zxF5kDjgbG3IIKu=5;DH_f}uJ+FSF9adVvzkSEHy&K9X!Vh}^dp++WUDXF&X~%@b>Lb^_J0DFki|~Vy2oLY|EazJKyV@AlD--!LJ1^BZ z_Ci4(&$HsgY2<=`C+z)q9Bk7$WiAOgGd%`xsR&g+#eTa@Af(VVh}8YBWH2%lY3rk; zk4~Vfw+jiu)`He`mAbDG_y4uF|ihWpU&}G$gIJD$~YhLui1n=66|{LbXumZTmr=vAx#H1Wulch+(^J;-@jX0s_N#e4K5w$l-6zjUuC1z}bP>Ee zWM$>6K6o{i>UDG5Ffxg*?HR&=Ws;vKxS<5FNXTYaJ~I2gFd^0(nr5EH5PqHB-9X;i4O_Md7joIl@n`YrJc6* zKdIi3Gs~m6C2)bp+c7*T>eXYtXC}_9*JY;cM%S&R;{T-Ko7w^B##=fu>Ts{cQ+a3c z!x$qZIwii8Uw$cMVwRQP(^}saK{!*lcyF=_YhLbH$VAAnYnIU;Q8m(3r5+u>*8>c{ zs^JS5856%nPo|vjIrpr?nMrt!MZ6S5tMu7z-Gqk55P3Ol=`7N>xGL}P>a<^Lge@r( z;F~@d^A+m?6L)P_m}qL*UTrOFcIg+Y4M;8w7ddDV4+{mX2;~LER~t&XO{->Fb!Jbi zrk{Ivw`)$J%n-IS@7f2X1uNY?^#V6Tayvy-W_S#_NeWQGk`+>CwnmJjv(h#irX0Dq z%Sj4rH1BXS9U^KHp#y1hLcIy?D{OU6rvcOu=U$)JGrAq?N^7-UKH#)M@tC;Xbt-|V zvTG>ADQ@KDeOnNbh~*l=U0melrc}metUlmFDZO z4s+%9S9)LBT9eb^y#CzCIf4DRtPVgs(X(EIV0v*PF#>v3&eRCV_PQ-!)&mAc(`I!U zpmzdcRSf(yoV!z|RVh9X_TS9Nv*E^}3GvBMm)t)y3V2b$g?bdTKBLQOA*PnCe+LS{ zIWy^ax?nb6sYoyIXe@C&h5+=f#I_ zH=WLbiD-UCbxSs~$9BS_fhJ|)%OS12hJ$L18N3aWjEII7LJP!G=Vnx z{7a6znLhQ#=~HBOQ!H)!_vy7qO@{F8Cet-vf>n{9@{X^x4zzpX+Q4=4kr|aE*SG6_ zPc(8$!Ys3e%sbqwx|(IAEU4ia@edm{5BhZzSW78hCPw5f7$Z$?#FZZlw%@HL_vF{S zzdxr?2!1BLKhSQs9(IZbNh6T@M2A>bJA=ly$1b{TG&j8_KZ9C)wi2peZPNG z#*n7Hd*_Y@h}Cy!VWtZ?TgjhR)tJq>NoO&{fiUXPbjOLc^O3BpqAC7{R92Z$J!##Z zImjs3_R%a5h2$ezaNZ@=Q@!Uom>r<+T2*;oD(gGdh^3!QvO~cNp`E%?b8O0j%0Fm` zBQKO(n&f@-vRNikQ#(+Oa!GbEm8C#jI0ZXoRzaJT2cHhV9uFT8!5?GVxrB{ zqPr6si3g+gQP%E_YpsL@h3QdCJ2Ph`K^e+Bze<^O7FnU^*QZ}5WOLImq-JUj-q`8h z^61!Q)8+v21OSjFL_%uSBJzVX@6gq8n|`w(ipd9k7YtcZ!nRcag2Yh?$n+am57tRm z%In69bQ@6>)$+YcZ%n-ziqFVWI3#S# zo+keu)2JSBrWshPSkHWRpK!?Bt_=QBNe!3!yqj5u?Y z%?k%{Pa6+OC49eZES~i{TTesLn%UMODvmW2+c?Qst}M?^Jn8g?4&YSWvm0nZNFPe_G1F4iIl>Gu~~J$%IfUNe7D%*H5Kit-o^qG^;A+*IeJb4iza@?31O3 zW7^6F8%EJ-ko}}s%{5l#vU3u0ltBj5SXm|_G|4!NoAbzqFG-G8U7Wv4zIAl&w|;ey z_u*6(zZG@XffL7Kc!)WK9TgO2wN3cok~?nu(2lH%MVH1_)+yb!m7cAp1Fv1&?4+PV z2@tAQX`8YfXQbGw3d|FEOu-!xnQt51ZDCfKAeXAan8`~ogLVSGz>RAOq&pZv;ht(0-XH?&C z!bDm&T8u<@&nK+rbbj^98mL5{v(-*QfMc&x5S)k5NkASaEA0?3_$Zas7OjOnBtKk}HPjFLRm&`*_0vPEqJYeRsrM1Mb;@~I zFHw8rw47m~zLU~|PW^Rn%gsw`E?8>@Hw%*c_jP=+qcL!qq_k;b@@6z%nWf5ic}mW% z&UoW1yW3{`D?Z6z3@|}$vmJ#OXi+)2CHc^c&Yi!x*t6Z6CSCGH3}!8*6@YkbPWh7q z)r$z<*0lWVwHq~YT@UQRL0`dH6Plk%3Ux46mYdyh&ze$mMwIl)ua+}$3{nb$N!lT9 z5oNui4wHu(KiYy=(!(JPjG;)Q_C{Zvhe_lk4%e+FON-j6dMFAInTWJ@lnze!Usf~z ziSIG6ZRP6zDtGa4ZoBbUy#zk6M_Ktw%%&Y0w2Z?{jb}=o9jdGkeRcR`>srj|`jTZU zT}r@U+iILd8hBQURWHrdy$;kP+cU%e|z; zw5Y$jT!ilAb@};Q;EPIj$}_XF^vmu7_h_jw%~^jOCR>y5d7`&1DdBeXL=gF7`*)uS zp6n(<3qg{>7!UF$Vn4Qn^>Q0wwO89Cu44RWy$bqAbPZEi5s5`l@~0k-&&k>Kmuk!c zM{y8%ByawbF#qN)f+7eL#Bb|NOR%szopZ0+1#V`oGnMq8>Ei*r?ht~tVQ~aQ>NF`B zsVG(`wFVFUe;wOy(^uMM#?k6UZnTa2d`Hi5Ym|Y$uv4JIO9T9iKX;|XX2<6GV3s6a zR5Jry?OC(eeA~xMQPp|f_$5R4ABS)x=!xmoNc7_(eRs7%VA@0w*+^TVGQGE?Nv$%7 zL`74($JKjy`JL~4AZsd4I~bBaQUUiLJWFTi;~of)Uj4Qh;GCZASN!ZH)?85!>$h>N z(Q~p$hRsJ#9CuWkm=LBUkwXBj#(OKIZ00a^!e1oaQNCS z!`~bkW8-%ntv!xqB@y7KgF(cHxDt5Sq*g3IosfjwrM#_?R3%`NN-BNo$api|i@&Uc zt~-pw4iwJ%fP5_AR@>2VIJa$t39)adnVFC2350m8$chUO!Y@g?e${6VlgY@2iZkdO z*!rYTWEM!}rjGjwv6@XTx^&tmh078lEnOKDYDvp9EVl?Byu1X0yCa9PIfsV1|0W}6 z=Hm`O&D5A`*bjcxGS1?BWmH4DgL08Jro2k{vK4}KWHAUGu7%XBkW~A2Td$R2^*Iyi z@Wl5*PM?RkWJSm_lT!h*dNV>x31;cxM%Y6Vo*~&8cf3sZ)}VoLVsV}iUcz(b>}KI) zqM-_w&D6D*irqW6Ml(G|G93fw+O$4cQ;X}qhGi3|s4|ULqrLiLsCT_xWVfj`J9iu? z`OZzZGBw_{{M=_UnaD;|P>Ul{8PtrK%hj7?-seH|^wu=D(^ADUA0v%C_PEi<*EW(9I?^Lu zmkWifoMf^qtmY!%jXOLO@PzJS?rvb0M^q>+T32mukV9p-*1zYhvrlzOei&9LS-R?% zoW(9EhOczv`8xE~d&mpEbiEWrbSAG1r=O0{y=D&D#1Qf7bES*;xi%kbOnzTR3|6$e zbPzy&{dc^-vD(>nq)W?9$e6{SYLw?K4{FK;NQivJo<*GP^H$Rh5x2?f`BCY^TAfYdEtw?&B47f{^shEC@*9Lx!Og@QD$ zlG)JJ8Igqs9RhLde2!#f+A>#c##68Mmk)brN1G*<7-OLto+Wk{sra~CG>^W0WYGFv zr#|N}faM)g1gf4iai6DM^-UiS_;R4JBW8O({&=oOql4v-T7!o|8Wn+QaLniw(p(1` zD-u@o(x9XeZhZ$|PYcJYFNh!4!av5?d6}EIZ_4<%F9lg7A@3B{mQf%cemMn9Rkuos zopl8O+1(G->9q;EL+P2hnA+u9&vy9nFuL5$E5TX*Z1pR2lIkc!jFOB^Hhwz2AY7&j zBB=#c2huSVGMofwSu^;LBFb*`v+ng8{)I54Cyx3C6181FbSgI}D5R5P=UHY?7F8vC z^XH0pVSIRUdv4dRue;X+bitLb>CcV-2ge9jx{2y~W>RPtRg^jYA=Dl8%&DUy2X+_m zphQZcWcb-Rqx$B%%m0p$@S;o!QmXvFlV3)?Qh$j?`b;jNN8hLX`+j+0KwrgW<`NSh zl7&b@q;IW-RKV8~lo4aeE8Grzewkw4V00 zXdSjudPFVnG8u=epzVu~x5|OiD!y^G=7$lstIKa^PK%r-GMf`EXAPwCkP<0AE`1jy@9eNy1&N^+EbIP~tuTq3^Pw-B!$pIwX}MH<$yMHjVtnae0L zEP#mZDnt`@t4ElCx;!f4V@Hmb?}PO@Aj1>mxAki+4vKT_eM^NxcOIi_R7{ifXGv`r zwOh_+8eFVP{_DWfQRC$Zw8oMHPh_C`nw^dOIi;rF{(8;&RhiUvnZY__FoVilWXj{Zb6p^C3JXNT=bIAa zU%AtMy@cTh0np?a!?s4vM20`1Ss%VB}qG zeSSW5rQQ+;ttzWERY>m>u;7~Rx2bydpN+mtcW^=DMM_#YRe#$oQzb9-uB=L!@TDiU8l((dviaH%W?lV9)^l>0 z`u*qK+--p#4-@b--e9Mhg+%`E5|J_PvHceUk2qEOASRExV9<|D`Rj(h_gsr9(JXqle%iC?ws+X*&7ZgWTn`N*!~OZkFHL?r(w}Bs@0M(t$DPji z#^&+H7xAilW9{@t-%n5U-J`B!>iLxW%_txDTI{wEKlee%Q~zaNaS_u=xah3HAI&Fe z+m8rxJF8{^5G^$R_v40v1MGxxKU1Q|1F_oSV*v#IEGrfSo)KNtLyaWqvD79{=czS+ zhzUASt`cvx4&EzyIzL)S2Eu38k(uF|C=LptL2AKKh^9V?LA_kjAA|GNvHjN=@24sd zSAQ6v0YukI*xL{qp8ZUk$E)MdY5cuw+7*D4Ub<|IB!xUEMor3OqvvchWNjUcJe z7ljZ1xV=Q-F%DP*3F|jy3DFOVXS`myQ%pQ2D zjq!Q$Q04_`vG9(r%V6H_nC&ea+8?fl<(>*CB6?h~{(s@uP#A5LZAl+U%9NSONhE?N znYOB|hR5i}ReUR=j))5*k!Z!3T7=8W{CctI%TMo}L~FY^i}A8`E6B3dZ=@NZef6kB zDUqN_hBiD_$FDlu$j-_Qlt!)w1T@QVjNh#S)Q4JKnBLHuCAbWo|CNf~C;dumLc;Lp z>zHSZ+tf#JtAfH{tE7l>6VCq=5mXEkNKf!jZiWM)_LWSllm<4i2hx1by~cgNj}NYK zHw~#LQT04rY*D^O9gok;U@3$MG--LtMDyY~-TN6ZDBJWb74d@4%lYbPMB35gmm3YT z$RDq2!L?xylEeL3K~`~;hJG}f`#ow44Gry3#!r|&)<|<7Bo?84r`lTmyddI@Ju&l0 z6YBuKQQI(xP#+Q(`O=Uv5nmRRH%o)!Rde;G_VMRw-cyDi{~Na#L?A~3K%Jqq*oZAjfiNNymKH)wJyh!g!J&;7IT>K{rzKMN$l6d{+}F09VV#Hkc?Mhyg# zNc}e>7Se&)VkmG>5>o zpqxA@q|kIqNFtTjd#AFkOBPU6p#5#+JME~Wa|ZaF{zyJfms-*(TcJ9 zT^WK)ez^Y5W=J-j@i*>PvYxo=EU!-^O+patkJ66;LOSp4W!lH$ytfWdDZK(oqfCYS zg8U^;o(D3C-@mg%&W1IkqERe%s!CyUqRNUYs?(`y$+S;K%|~hek(26&kfkjA7uWT? zc%!-(*FJfM>COZE`Wr5Hq`*(*-GhifNO)=Q3D%;qcSL(Tv$L`BqTnM?=N%^b^0$+G zrR#Wj;r_$AvN^{Eq9|{jCjEZ-7!A{f#cRl51_;McxI94xJNz}hE-^(Twf#`1{%(X@ zls@^f6T}3d5J{qTwwUWwdIR)>u+Jbc{0 z%b_2-`su3Buf+GzM={yj;AGv5%SlVlMoW%|MRv_ls;vssn)@w9Ac#C@TNBfUF(;# z|7URPey1O#zHBD7#X;(qT*yR%6#@-*vRhNy^l{hPIR)#sPC9j-OE^2}EQwV&3)C*3 zwPpKNw^gl9)HcKtp~9H$JZx%`MUj0UrCw|IyCL}@o3-x+e!QjW#=&-j)dQ&Hv2ur^ z`=jc@lII#nT(_*~EcSW782fPgBQsm)21K+v+I-P$Ola*#u?%!^n58cii{i6|Mp?Q` zW^qSTk(X@B5Sd8-g{ydF>#grEz(F2|dAjVulck+Lm?6<8n5SrA7s;2!uub@$9c2(@ zQZ06M_z(ul?k3w*q394oG*|WfALlRFy7WUhMZYk{MrJge`ql&pAQCQ90%S4g$Wn2? zTc3wzM9}-w+tl9JFtnNzip5 zf(R_hxv~Cx|E#2oT%4RW_P81jgZA19r}43f^Kv2Q(rnrhDQmT-jVc&d`L@TM@?E6T zJ;e<(z!$yE+nqK(jkE9g)X}0&WY^v@G<6A#SEjUV z`XFYaY}tkn3Q>e!;2~rLf@kud-Sj6-Ql5&CsD{vxy{15C!}&6BKezOYw2AzhyOfx= z5c1G18b;NrG;XKIdC>LipV?mhurDv)zH@3y#qjM9v9h;*4fSWE~a zg3+?|{EB6sj+@)*Ry|wLfghM!AG=ll*uN{9>*w-olDpAA@^#2#=^MMR2{g<}C*h9h zdr!F#T-f>Y`}dvhotW77Y%kOs(wYletdj`qI41ED4kE!?oN~HY0#X#xuWD19)8c_j z42oi3kA0A?xV60(?J8n^G52A19)6`e|F}GBmq309txN{uZaU_cPf7L-9N9q(%M9i8 z;?)wsav&I9&|T0&4p<)=BvHrd8nhiUO-$~w(&`d6tN%H?Qo z3-Jqn>ihhC-7aQEpDZ)Ka8ZZR(er0IWt{Y!+E82XuK5;?LhhI8bAPP&JWl>C_2atH z3NzU~@%EDPQ!(Vn_Pn*nn>^llpV!m+KkEDo)|02#@$m=aS+_@Tssq;j!~b7tO{}ds zgiBkB8KSCw-pYGPfBF@i>5h}$bze&1b$R_bWiY4Qt~7tI?Oguv&THftPp_>{=jnPZ zQ{SaUv6)ZHZkZ8O`3Y;(efB6P9WxG(-_66FQR@GB{O;en`ghlz)6ejhW3Ty8P7M!# zhuc}(=j=!QKcC{I4z=EgLn-!G+BRiXdWK`#3o?JF-ajpvMcQ3+=Skmx^m*5gwsP72 zkFQ-{jx`DU=bQ+`!`IJwksf_7Um0PLp0doo5RRGa-6&pvPtKTj51I^j@q5$b>-uRU z`9^+UW)DtSrkoV#SNwhz{#N$?(FW#IcE{w$6?cDnGh7@%0N8AqK+z#QqEmxL!Ha zD3VE{m32x2g*BSRIz`SzQj)OebqkbwE^LlFqDQ1b9%SUvB9wLARn%Pp&0hC#dDEc_ zQNuW$!ft1&8Qe1zV(5BPow|r*5~mBWxCMu4+>?ult#W1RRRfYmD>O9-qKKn}1a&Ty z5k(P6T_~%vX|pqlB}y0dVDwb4miLv!HZRDk`c9Q7A554COS=IWCB$gq+qyB}THi|3~|Oy6~q<@9FvdUmlNq ze4*jJrBzk)Wm1*m!_rDMFd#?I`mik3kb$CYDknGBzP^0lKM*?H2sD`Vs7b*AfujUj z8MR9MJ&;B|w@t8SKYY7c+vhuPYD`N4;25Y{=!7<(>bHs{f;kgo-`)eTk+WI z0Te(fr|ke_G!0S|j72L+NmP^+i9r-W6G{{%6eSS_G*e9?Q$a}65EPC`!h$w-2V8lY)Lfk8ql!4QI~o^`?f zo-q4A@%Jj~@bDRl{!GqUN}nic-8R?W;I0+6Th@kLz67s-_NPjy|=yGai(*~UrnC&&5zzTev_i0f>v!4xSI>g>(Wb!b{8bv@tk|3Tk; z&&mq5Qp~Fq%2Nz;6Z?#ue|B{w?7&bKEGFOEKQqtddHxTM@sEMNK|JlX!Iv<>H#BRR z&(OQ2Qrpz(X@=&OQCX)*zq(J%FVJ^Nx828`1L&~Q+jYhmT2nHI>9SzN|1Qj!#o+Y} z^|7YgoMdlC^yjkwoWB0M1wUJ^g1^`|pWiz^t5Ua+y|wpt089_{LYsH%{3rc={0ccw z>OrWaMG!@lYK1LG(Nb8A>D%zp_5VBfcVBMbo#~{hpVw`_E;N{JmzRXie~xfv;IX=R z&5S<=Z4o~^h#e3_RYf^usZ;Hi0{yw~b`bS`T43nJ88K{Fj*uZ$c?SK>V)M2;fgXsi z5!rgXr?G0sbWnTJ8`BpDj4ekX3|dyaV&q`f&1vad*hsY9rP+qk?P3k^$E=5E^tw&9 z^@m>t-O$6sC5`Z<-?-%p z?9d2kkfxZOwB?n@BzXZ+-b)6ZX%j)3%?nUv*<^fP-dYn#f`J{76cGs#Wevj^<6q+u zJX_i4yS}(!LS@rxqd8dQh4N%5L4kxgywtoS+fyUZ=!bT2$)-qy2%(ltGMwR2GC0`oaQX_@oqGKHn9W zic*uB#kQvA)G;Xo^cfS6vZ()RrtDc zFV_nv?fs#1?PK4x&j)OrX&EkWzh7Pq$GD{L`i}RharLQTomn2cY&c?%#Vd`Jm_qi5 z@|xnPjz69EnZ|jQUnbQVh-OJCrO6vxsYiEh%WJu>_*r8Iy|M8Ug%*dLsN)LYd4M@c zC2UJ{uJG#>napKKMK^NIYLjw-+R9s5gsQY8yV|U=&R+WImvvKNgN>Oqn`9Q(O{x;O zp7p1v(Gv#ab5WU>UvZq*45uQ$(v zJ)QHk=C65wf!IsjT#iY_`m)mi3l|)eW*TX4`J)IEswS5YS#q zUUsd<)?Xm&ORWvO$rorc>1?Uopw%Jh%GudNK3&z)OMk6R^#Qw17YC;;<0;n?aK5TM zfFYMG8dte@?aKNgIn)H5K*B;7QV^k}Sxa8tm)Y?3ow8+{J~wk3Ytch}F%H90>-_(D zh&l+V={*bKragZBrg&$vdTV)Sa+cOfVy^;Njhxu>NDgs`b&!u(<*D%By^2>m0?fnRU{=O z4yBTIH6tf9#%Nw@uRMI3nWDWAu+7zWIm)wEHqB`(o>LbIwBU1Cl%vc~K6r}iE-ND! z-(7OYZ%=DG`oC{^4H2%3E6PRaB41yoU~>xwtS79-o}&~XDnU`Ag`U}jR{Hf8w;Mm_ z$QcPznpO6W=}IsU6HNbqvlIvjy9v>bgj2os6Yz*q0kFU~I+8 zg^bENMzc&qA_pX`k)-A1xtZo69-BDrg^gab7`wAC8)_Q#EGb#j)Sk6U4v&K0#iGM? zq?RZH9NRdxw007a%A?ki7YQeds~YO#Qze&5hH-Nu_6)GajoBv_Fo6Agc&57Ni>|Z0 zR=yoMdo#XYDYj#NO0?^pzP-HV4 zCtKU`%sU}`%nrLFXT}t4X*kxXOpu;2N^c^Ea#E;Bi!Y^MHM9#LBzB}2UY+`dbGPqz zhsop~*DjI>nn*FmwlK0;r4XjIe3-q?imV`Yh-~)&IoE?M&@WwaAi$kzgC|K{Bung| zrc`=&iwSfv|^4XF&Z~#<6yC{&@8`9tVn;BMx=O zQ(=?S#^&{`^!Ym(A%zy1-P`uov;R#X*osiawwqo<+Q+>I>2i)<6B#lh6%o>#7pXa} zW-Tw&31Ecxr1cd`F5M5pr)ekseNd!&UYAr!aq+)$b!qbV9Bg^uW zRW(dkKUUkRTU?a4DB{&Ujcs`_`(SNbDtAn0aB}KsB${YdPjE%7ILw6(-s__A5K1%h zh-D3^W8+Ma)EW$;vI=mE=;Jdd5_uSVVg(y)Kkxq|j(C{J8E5$;6re-Q1Y>x+W`h}p> z{wH!e_u$qBhV+RlIJxxn^C{Dh{Wo$LCnH|-&;9bQn^3;1Jp+$Q>W{6Cb)S+A=ys8$ z<#3JBMqH@sl_;L0iy!;@<&<&A=9eRi*AI?xU4%%!E78n6LQYDvAZ(e^{GX@{M zME3dw#hmNAm(?RS)$Qw~nA9ToZII+3*Dn-xS*vMvfxO$?wWyR4glvXuiUzM&tsw+= z*#$qDk{u~Rl;U%z9WxS(-kkSAcnU(FUY-36td)ROh$ z4Y*0F{&fUPr&_}6tb~!FwypR5SVeqIZ}p#-;rY<${h^L)K4pwvT-Ov{*yD>&MTo2+ z)VKnxH^DBo;Ttckzpg(y9>Ej4y(e=NvA{soK)c#yxWhb^BbLE6 zBZi5Z<-DMaq?mUyU9uDGrp*%w2~d)WPqnUxj{2CNvuAw$CtKcjl=%OMKQGZ*Z8Pyi zN~!I)L+^Q~Fr|VVpjR(Tr$^6aD!!uS1kZAeN*PPAh);*yqhqxSx#~`ftrMy87#Vq-z1XEe zv`S}Dx>vWHr+UbH&lo;ZmSJ8`Z!zAcpd2DS(`$0N+B0Q3m~1CCP{`TKW}6Xcm%3aW(Ies z4~*+CoZ7x>6$sMJ!ZnE2VH0WkY~zzGncFvQ5FRy$+EnYhQFm?G&Ym{=cYU8nz|>RA z95cM;p(o~V$MW1f_0%t#8=#rV;wFlAuoG|msB#B0eH!1%y>n?@G#_u zXI{6~=!E}1f5rg78X!L6pv869{bqd1QS+brd(8Dl?OZxxSS~@0{9datJ@}hs`dB=_ z{xHAwADHHL9?xCxSm))q_qFTi_*V(M>cI@)Be6&hX0PWxAXrl z|Mm0u^q#%>;)ER7>AsRtf;xV2n9EC(%l~R#TD?|~Nn_eVzWk*AC-zUnY5davf~WP$ zYw(!z`%k3ov3>O2gU@o;K}KiK+cm9J&eDW=8RVkAZ%v(`*IH-cs>{}4w4L7aN59&A z>1=OVglxLPeJ8#K=Ds4P+R)=uZB_Hh{K|ZUKkHjikmwuFpQrA!{e5QV?o?YjiHOct z5dEc1#aU#H%%XjDOBzjSsAT)^oJ)1cr+w^qSIZAHiI+LsQI*Qs5DHXNb3Zv+tkQ1b zgOhKjX02sQqxRn2h~NHe)xr<*=yz!!&5^yAnpb1_&)xMO`8ds4KBIg3jQT+dUpYOf zct28|R@r}K?1%5APKWHcLC?o~Tt6i5;J5W&lWC>Y`S0D+-J*WIeCLjkI5VGiK6jhV znC{$1m#n${I{CRiH+6dJF@NhXviH@dUCIYl!nDILhm*eke9WZeAC5Mt*^SAsi4vIU zo90*ZFW-ERi26bHzsJ)kziX_Z$>VvP`eu*HBG3C}yfNmU+V8A)@!9-%`1^7F1F(_+yBe4cbgYEPO>C^Gg9HYgjlk4~4>@g59(BW=&%_?YmvH8oc zr1kiqAh1CeD*zu@7_gyEa7aAz6?zvNHDTux4-T+k7dKv&j8C1Ag!uT)rpVzKlau=# zVZd}95w*h859#Z_R3C(O#eT@pID_yHo(#SXFKXDv2g*pnvP*C8cd|b6rn3AA4`fvb zfoW&uj~IoE=oVC9l60RO~;%{;?#HfyE?ffKE<%?REoDQA7qf9en95UMxmRo$o=s z*x|-o%f^7*Hs1(97{K^&Ec}Tpfy17YryR!VL-X^+6I&}F$;*f%9|Hl0APi>!;7=F@ z0AKmQTzm5Y$*sOIf&JtEr`NwVUA_ACRq)-lpl@yX2haUp9JL@CGB|x0LaSSN>F@EU zg5_45qFtSl3D;6M4(onSk?@i)>8i4^o0E%H`s2TBe?1lo52Q z9f;8vb3&A&_UyI%>n1mx-YybH_3au(o>NnJlO;0&0;aB?yH$py#j+2#Xzckjfv~|4 zDu3`Sr>|j=Z#(WPE0*36X05T#23E>0rCuT()B=De{!lbT8@5ftOH%uvFq z-0lPP4XOnO)PDans3@7NtvN?6<8?*VQO5tm5^pnjg+W&Mb066)DTF(+Eh&~ugm06* zMr4OMSA4+nzL_RV@7S;9sbjsz+$}~>cUyA;cqS2}iF#rs0*Yq$5yIg_1e(3JYTado zQI&1__1>^SF$Q6z{$N?k-{#m=2w z9@&!76`E}ogCpe%W@>%Y_5SaXu$ZiFkY{o{HS?uZ$1W^?pG~B@v~t;n$01YJ^>dn3 zh7Aq^M@8q+yQC!V{Oft$p8jxjDK?eq93Bjy*Dn!irpm5sGG8&+w*xv>z& zi8DeAHW8FZSIO%+U91sJgvG(;r*Ns)NOH@`;h*b%O%V*8_oIb2soQnmPbPJq?bT`3 zrP(8J9-D1w3f^An0z;NYJKjp)cS_I1hO!_fWm=_;Y4xE_*vh~t%C6~UHFuh~Sd8gJ zD#&tJ?oV`MqOoENatD0lsD(U6NWt0s&hWM*K;}E_Np4s zULtG9Y}y@5Gw7|u*~uI-ZZ@27>6q*lT`RWUn|GIEMZ4+Os({i_Rhlfa)Tu<3!ww*; zWoYdO1Zqsr_vPES7FD@wplx0oqGJxIal{-n=oqe@dzhV5f4^^N##(EL*^FT3lIM&9 z0v*XuJ> zZ~ooUn&JjFmKTp~g+mgMku8*IUQ57FCK_#9hd+eGl}8s?bF_z#8Ifdhxiis|=Sz*8 z-jnm?h2^Z$3R{+a)qf|$8oLm#ddcM1cd)5e+$}uXB&@>G>4zHeC9^IgH5MZ_8^c%q z6;$peg(rESUvjF{i~n;hHI!P+3<%G?J=_bAGu;N#c}+v9HKNd0e}$h+rhTV8zo~Z; zT}Q4X7Y~R+^621ChYgIKk;8mgG=>TSveMFI5^7eZfC$$VkWp6B0oa;6Hl}p}u7Zd-A2ibhJm)_R$z1*#L>4N$j z);Z5>sz}nxGWfmkt#ar=*8P=%`ihRBNg3f+N>7b0QlvW`5JZb{G5M6zjkH&pdv} z)gtj!?FB3sqWOOIv!2+_OMyN@Y9b_#YcB5+GDq(-*GRRK#-vC$66rHEwJ5;GwG{a? zb?b|`-NG(-inFcTa$$C5j=p(sh|Ao#8MVs_Rx-~?GtvY3rral^qNnKs4R^hBQ<(8Y zK}s{)FwB+g9|uRZqwPD?o?I{Op?*KcZ&p^BpUlInj=fX_@3n4v>(=d6dqn9vD}pr( z8W9M?q~m69m1o@9dq-(*ZX+DwP5Ykr_k3N!O9;v9Uf?`JZSwD)RJZERKbQmlV0yUW z*QN=q|L2eRBOm*J_W$g^olf<$rA!7y94Z=+)(fdquUW<%Mb%WUv-=oUafL%Rl71K- zCNsvpahQdFIYY#n_Ls|X_RmSaQ1L1U^J@)$C#0ULI=kkfp~_F;fN%VNg|q(^XS|h3 z?mN@KsNx{ZqzDXw|4*&VK}`V6igcuc(x^t$OZ%046HP!l7y~@VkGo$>`Nu-d3 zj$2lpEi+xt`5E0s=g;HElX7nP84Aoza;~e^bFr;OW0TWDwnaXz2IO|SJ83P3OGRe! zxti{l?LV3N{_jh#Cri`0GJ7t#kn?*^dF`@}@JCJkJ&lxie>_~7oJzSC2zPjhk_;%JZ&Cz;D>vX}=mS4wSq7


KQ9C?h!g( zDypiN&G+S8{Zf*@+=FAfa5LzkIh}g*#qY!gBqr}fIL~}aadqTd_1!K}Gqh5pNv@Zs zhs-A_!=xcas{frsv`2B6{3fD%@@12;xz>@dc3x=d!2C^#JDJ*AR(|%YWZ>p^{`%E_ z^c+__EZMg1XXQGl&w0M&&8$?frAY2{@AymnCS@0v4947{}KP_`v*OgBmtlL&UEAd1=11|gn0Jw9YZC?Ya%LU44j5q zC7wii=`5{Y>RK!Y)-& z7cK!x7@Pu%jwxs&Od*0>49CkK`f1N-|2<~5XFv6i`QOJm^#LgAfkn!>Ko<%ViOLX^ zmLxGG|AKRYPDTZSD^mB_j@~dbXrw6;gI02`MG2fPTnm95PB9@Q;YD4fMnN4R{3Xy? z3nG*hXsC#c=6|1w0JVD>`s;8wU4|U#7ebDcYb^qjW|4{{bNk@`8!kvpkiL{ON5uw! z{pEG}>R9IBVC(g~!fPh`zWyHj)Ki7FKSgbvModD|Q$P_JFv8N@mQfDm(lZ2xmC{Znb0KV} zI(Jecsw0Ofm2#?xiVLugsX;(u6-5F_Rd!KD*>O0^E(|efRaHWC#8UPs%<#yAx{xQf3xZ;9Aa>5%TOzfndK$+S_z_JUAm4xW$ zV}X#7XSy&7VRD?*1&SjN)34}HuhF}H=Z*aHh7KaOWi)*KK==89*=OnaeE$!7%~SEi z^*oZVuZ;0M)b?6l@KR8pNHSU)$SI*QoXoN;$tXUOY9^$jnp$ac5YQq!oJB~ukX<6E zp*R-;#N)P+G*MMN`HNmUUOQ7)nHI+B}MRw$%$jVjeoryrs8F#7$?ZM;W_rV?xTey8ltU$5cDzka8usrT#glvs%F zYs%-oH`k9O16bz z7DB2l5=c-9F)>plhxI!jJf3vmQVNMH0T@NryJ|;=&lde$`rq)uq`^#YVGM?nyc61; z`s6t{v=e3?M>!Zp3Dy{Pzs6Pd~ngzxz5VSI%V1L7(ElYxo{)*tpDN8j$f|1aJz_72~l?YCoM z@O96hLXYl1*Pd2qyf4Amh)e6~J=z5wmml305fl^=Hc(M@K(cAue|i>0-Adt4Ai6=E zNQ962;qz~o*Xn*04ZUDG#zPWNPMHxzL|viA!qrIx<10-CB_oB}O+^IAM9@V#Eq*gw zrl|a=Q2i&TY`+D&({z2e)22r!A5-z?$-%k7`1$eL9$LoQsYHX3T=@kd+0}ilXHNMG;Xn z>Hfs-Emez^NZ}zwNmK+$Ll9FSp*s$UY+GN$3$Q7%)vWE8Ng%psNL!OsN9=+=vQ@VnU%SB}e1_-#$3{roGyV-;a#=*1j+^V$+6h_SOvUQ+xQx z2krLn;P=(w|F``qiw&)m`ey%y50}?!9Kqye+WHOi=ZyE~<}uZ&c$|;4WvQVnD6$$Q z5u+=GMMY3`W+c+M5!hT9VyIQk3ZkOr9U)6Hkxf(;5kd9C3Q8cFX{DlyXrPLl0;M$93qZ^GPL2si;f290LrsGm zQAt!&6B1Jp%#^VjvMCsrhLV;bstO2%s%nCYDTOlQI=d6$pno^*RW5VJ%k$yj<5Z}JJoB5;NO#HKY8s^vgfN%1b!5~wVtPhFKv0&j zUzV38C`uM85~d1hqL8YJxipgrsvJs+E>MR9I>Jc^nHiHJiYlU`lyc-jR7WVP4n!qM zHk>Mox@E2Z3!yRYY8(nPA0WGDU%w)G7(z$(GtISg6EB zR8&PF@B6yv=jS}AmHPbG>2~Mot^6O|+v(G61@@4xc9{u}!W9Ed3X&;?p+PFhilSmd zS7dOAlT9?#F;G@vK}-M3SN)&k{|yG<{~U+^coBS|0)aog|IS450H4|pAT=n`kp@GP zO0WXgg~saB%=+3S=dig$qR?kYp__BSS#Yf6@mbLWNyQVy? zjio^l@X6Ej=#6Dg)R`nyMO>@NZi^_cUH$s?*%__7V}%$oYHm^}=X07>UO1?y3ZjBJ zqCQA@2t^0DT=CdNMJQMi{_k!6mVt{d4G2^%xBj&J4z!psiUV8uq?w7K%q!42Q?JX9 z)%f`H4;Dl1XdEEyXX5M_hKyOex;r1)#V|U;_Q_DzLN8oo#s~k}RTnKQxk-sf`-}4p zsiHjNoWZlOSrgD4ExaCS+SC8wWW6Ck_x2NbeR>%u{{-cQ`6q`J=dN!Uk#}^iu*B%= zYqd9|&oT{tFOO5{S%Z+%PDK9ki8RP%*c3UO3#k*omE@Z13G9PJ?rIgq6D$+x1y;YG{6T0=vDan?B$-Mo{BAcd<5 zC`xG^=2JxkO%x>=$SKGQ1f|`-N$jeFy#o=OTJ!~nBb=y!gT&oHxKmKnH3w*Z&ND5b z$*M#pKk%A-ZgzW+4# z?tQotaY4#pkgdkQ^SJ@(1Z($P1>y`uCJXFoVi?0l*JNDrM1CSK`r(y#vj&1Q?atPR z$A{<650S0cQ$EIZ?8BdnKS?xu_;ei!dy(ygE>T4~a5OI?2frSL9G<)3eI&e&gVAZ< z|Bs7$=?~AY;-~FB z7@r7pc2w!&EKOGato@%{ZQ}8`B9)3)d7HF$+*&!Ao^EEdX5Gja*ar#KL--{BRv&s$ zkEwuqlhdpGw5Gj7-u+NNd8KI2$E*5Ur^9+OiZT3>s%LI6&FxJ^5LnzOVh@Qb3NuSZ z7kq9Z%26V0P_Ss)q!2p)co`d($oFyQ`L36K%`!bnZPvAJb((vzcD?gk6Z*ZwZx*1i zxDci#C8JBDOqLK)AGuA{?K52+>@WIlA?KU*T$%Gu$AHTkf3C9kv5YsXFZ#@ww2)1~ zhB!+QUlG|d9BgYp&lwnTHZmZGWt|CUmW6^yBbk!+^3CI$w|2rY>JRX^$CcW-=Bec& zM7wCXLUxVRDrRmHy8c7<4l(mYQwaAo?nED-r|+{w`hioo;kVvn<@8VLz!YgxpAQ_T zZm^yssd^r#Bdxx3_Kb>32C1(VCP->>B$A?}3SDxQKO{f9)q$&d1pb?5Y>?w(*~hdifyNyJl()Hf6kk`oZpPiNJL4_z-IWtEQ>bP2MRx*W1qpaApm6JW425s-zu|5z1Rz+9=%g!c(;Eeq_j+5}5 z{4&jd@~J!;#s?2LpX>Pq5QF;wZ5&B7=iU!g?}8nrHvrJSJ#MDHcK?;X=k+i+g3dFV zn%p?Tq5kAC4IlR~{0j`|bg9U9n{a6UUub@ZH1gvII$%p`mkOY+rCEszF=d1L+%Q?b z^9*@n=5q1w;F1#(Zh1Eg8ZZ0dOxYp#%Qj^>p=MefcK6Lgfos0=EQ14LjzGg44?gjM ztvCdd;x+um-h&6P^!A|nV#Dl)y}>Lync18mRC<>$UNyt78fWH=L1Fwil=ZBGlZIR6xQog^3;bRsczt8~=UKO&GZXt-9K@{=JG#>`{z`=9f*d}*ARq(CLE!7stWB@& zaOyTt!Z1ib$Lvbcm4smmzsvTul=Z!ebIknzeN8+R<(uOJ9(Jaxob|IGJf}4>zdaF$ zXx>?;w+MYCdP;Eu8kA^MH7e={I^r+ZC|VYf{*6Pa{#M}1sp4^hhA<69Dg-)85~ykh9s_u4y2I8hZq;-StfA~ z+emMd$&PWSLzig{qya_WGGOZ1CutXAbb^6E6vPxMOF%S<+Hy)lkf3MN5^O0^ zWoM_vKg;L5hJr)K+Dt6D(ol|l*IWba-oSN1qzU?@c^kbXOE1}r1J=MBEq0if|3=6F>pmV3^xi%tUh
m*38TI`gE|G*I?pm7$BrXd--+`k|O~~ESrxPV{n&U>#=h{_VpI}6wX(ZTz778W4b30lQ3VZcqICDrK%*686=W1rEU@l%@#oj> zb+=AAcnv+q9V9xS3=8Ym_S)_#?EeU`XW8$2VPY9mGxsi?pql8bU?~)fAS#FHgPr;O zbLWR#{P#0Nb$Sfja(O;^hTHLEhlkgl^abjC6OmoPye5U>lLANi2OWB0k6S_txhy6xl-ARc9Q5g8#8I^hIBo5+4B1F{f|qfp}gI&KVNuY9#A6ik=twrTOb~gCn>!U z(05I8UOIEhzVpzm19}h$PW7gfWvdp8LsKn3(^y z!f(-n1z>+o>HPCE^6%?NU-aRbOFuW8zv1YW*25bV6w`C^?CV&T(TJg@H#pK7@x)BQ z@_T4@$B@V5N0AfNR=wMZLec~K7(jZ8F(EK@$BkrDw-UF|X zdzcON8cJdV;;Hq|S^4$DJ`AVwX!%N^rM9t4qRKOj;5hCXmhm{vny8N^N<6hHO5qeN z5(s2NlLB(hkSBOEC(O|nWB#u1E$Aplp*9cxl!*_H%gbN(yX>H|pB>G^&?gxIU76gZpH(tW=B`CgZO=T{k{n-&cZr%4IgQ;59O>jdTYLMw$~+H=~%2gBs^Mprl4px-}!TgEp8iuXv?WOO~i2CqbN_mHrP%=iqzBe5J};dnFg~ zX|TXpwt>xNK*&$=+qW9`pxdf)ll>Cq#Kb<+$INBBVftm%6^dHpyZykN)W6TmJZ7b3 zaN^Lw63`uIB0TsN*+|=OHpQXrZ#MWXOMX%tSnP=qAJKeh3$DZNm zn1vBEB{am*NlEbrL_ALPY*qNV5e6P!SEuO3`SDXV89l*H>{=38b*&BqV zX%dPWp*f6$m>iU$3JC}b5{dwbN!*yU4d5`F9|=?kLpH3>cUKen93rmI6BxQeoeb>G>I*{Zl91xdi=Bnb^(hdvX9!i$%Oa%EhIyfc<^Fp9jJ_+pb47Ay#`b?#RX zQUyKQiXgejIhaS0J!#u=4)V5f-skDlo>*C`v#h8rSuqJv&9WNSai-bioxfc{=1CtzegDj%~WSk{q11i9<`DgMm*&IHaiyO`f-MRqeU8Wv<=y16aOnEu>*i`pNE7XosZ$+KCC3oem^8h_S z!oPTw(@}s{7zqra@ScCQ$Ie`QRu}hUppkdgl@)RhM{K51{aBIJ5)z6z)nyT&X~Lpp z8JZF?K=#NL3BiZm1BZK)5*!i(<5prC)GG*h!2U9;goOZ7 zqj$4#@iuETT-v=CglUGJPUA=&&BM1UVs|>rO9iPuHR@v_j9Cl$Kj}HizrCN5vWTzi z{EgR2DWk6wg6*qIEOm#mWFY5%dAc4U$5T8%Zf0Xo)uR7r=ek}#lQZFj47ouVvNoX@ zB@o1ZvMBy7OYz$oYF;dTzNBLkBjF2ZB1niXw#KqN{eFkz`*oZ2u)!NO3?-DWL(cbu z0Xi6ZLyq(2vcgXr`FY<{?41!8_ORvXcE36C5!gEr_4d;s#EK+feryTEJ#^(eye1~1 z3$?!~T{-Yqr<5{JjQtR)<^A%E;pSvITJnM=PO#Kj{|6WNv|}sz8<+g{VC@o4rQ|wV zjCx|1@OCGYsbLv9b^UY4A9p(nc%VE}4WF97p`X(ahJqiv43h1AhdfcA0u0Q-!7pINV$#Qu(7tv57RYWttd`p{AePg4Y+mMjET zPE~(8xn`cTr#VeM2q!R}KP{+ye)3D;9_^n*w5nCzFNUYrogI5fJ!9V9J4e8L;;=fx za(ur}XEcG{C`wM>%LzHyy$E!Eh(M~Aqe_irsY1AIJlHTcl02S`y-mRNs}2nPvRK7L z6c+|+CFYy6KZSr|Lp5X#_q4Xjw%iQCr}0D0H|t4I$j$Q45T2eLv#FV`xW`oD5{E1> z?GB6Ep{`Iw7nxa+LaO`v{T}uYjc?6&V&xbT16?=!6G?e`93+~fu-hPF;YNcn#G+k4}w*oq&B7b+5y`N2SB4GK`DG<;77 z7(0N7qJiQZsa}rY$KxOLj*wq`2-dJLIA1l`e{wIuh7-~}q8O2h0E0m1`62xI_Wxtj z@2L(OWD%DFB#0F)%gpCDW?EAND=@U~OiU8BP*}ZgoVY!axT|4ccu~|1EzC$dGV4Xv z3mEOGs?{LF3Y}YF=%5L!J>@16A|*>Pedc2geT?0sUuZdI6f5_q#%in6m%(Dk&QHGM z&Qi)F%)Vge82d=F97&RzXC0|^nOym^e4(CGoR?oD&Nn5~KXU2uJIbFdLW+owO{{rm zwraasS;6w=Fi}^~mFJ+xBGws|GS66UfOnEsiB?1via+AuoV(PnbmA#beyzay{hR7z z#FMb9>@n90 zf~24boF&ST;!z2a3|m+HHfC;T_)_ck!vsbsil$Q5{*O|8zS^)+^A`-kQ%#>>Q8s^y zfAZO-85~Ra*nd1fY=slYv)iC9nB3}Lv#bnvfGU~t19Q*iN1Ek#gL6iSdw>PZed(T>4?S*oN0fawBJ zNOLKWr3mP$pqX-C<7x18zXj2nT(z7$YhU~wmaSjSxrMo z7{RnqtdX}p*(FZtzvbsPZo<9H!)mshM8e~3`|eMCp@?xx+4oK|2~jANDikS26qFQ{ zg;fC%(kw#JLQv3@G!&^2G*VI&l%q>PHAhIWr|dcc&l2|yH5b(6b_Szg|4n)4UHdUn7V@R zfjK--xID{;WHCB*h^t}Ql4-F~O2Rhq#N(wU6NIEZ+;s^^STx$SnV{07T;gQf2r}29 za!{g)M5g{Y_j?HPSIqvmZshZlool#`W?FM@CaNm0a-y6v#?4;R77Cz2pm}^EZS!11 zY=DsnrDufnioMDtEV8ildt@$l&b=*+O;D7B-V-6)-tO52WKmaF4ovsC*ngf`_3;k) zcHZKl@*+e;Uw5h7e@J%GG5q43Yf>}Fr%zmS%}9Ui?#lE}j^npGxhk3&{z0z z4y^$u-cIE2-(PRFJj6v{A_9c;m!bSB7;7nztf!+VgR^|;IfbJmDh8Z@$W25a;(zA> zB8{9zh~nIBV@h4xV>)DIS#K85vgbz9@21y(pCE%^P0LiVTdG=>}hZNP70{I$SYG)xGS{xO{R4Yo+h1OSXr8t~!+L$%XK;jzjA&STzTc z$Wx9%5X+aHA&(+D{(Sb+baG~c1b{9i(}^b-Sx`{!jmQhMm~~(jD$->U(~VXIC09kFw}Lho4a1naC4fZWnK2;5=B z)48IW+@@M@9g%xNK2mvJB*6V2;jb4xe!br#g)rxofmI@tqp=Mr*i6)@@qnOeDGdaK zMHG~VO$r}`fXFw-C>oWe3K|LrQk?70Kp85E1`h^eW}kR^+2l^AfhkC_K~#(;A)O=w z1mj!L$a&WB8J~Ke0OosN9=KHxNPl=kCy2|z@%F;u=@^Z`JI$##@<|HFfmMoyDM%EB zj{x*~NS13@#^UmRzL{&q-st#2Vqt)F=jy|lp zTq~cg<#>>iv6L5i=O=r0(aT-Obe)ryiCiQRDy^gET_R#Wwl_8N#Pr43EG@&IdC0=x*JagQQGtVz&Rzjr$Oo=f|i#aGt7_qHdD6LRYZHg+L z^iN4MeKW2L79N9ZmgAeHxk~}v6uG!mdAy!jC-y19I%;ky$_dWLS0HVB5^0}Y?%*=j zZxHUd0qd|~6f_Fa6|&75HWk0FCz==d;o^Pkg=mtY@({bKQp<4d)2%TC1hH0T`tRw? zrZUH)`}xmwa9c`(;&u*>ZrvXG_mUfN-Pp5f#A!o`hL&iRa}CEd^lfl`N_TzVzl$C5 z(l+Oli;mpim*>6TdgG66iifpIu~RtVSeA)x3Y$!wwC8Zw5{z=gyv_ygI4mRUZNNy z;waa>WSejHk?WA|TbRxK`x@hGTQ^}1WD0-*M(Zt#BaeB+-Bq0@X zx-GfNK|Rt)b#7do=;z!K>3O;dL>d|;P+GvdKzYt`ooVho?*jVTd$%_j;mFN*2QWk8 z4ikmT$uDIwbQdsP5DXhHjv?h20zHj^Jo2A;X+cA&)o_Qw2b%2C$

M0RZ!_nQ}?NLFZ4HT4} zdB&8{B^r#sG7p@lq$s7~mhdOD>$Ky>I*YM@X=Dr}#mg9N#uXItfK)$ZA%5J2gweGQuP1 z3%qpRDXzE>62!WKsY*&6Pf)Ya$a0;A>YKFUFHrd>rB2#o`?$)L+e2CoB_c6x=PywYA>`bE zNQtRgL~yzgBVIVVdY)wJ-CpkP-u2!|#mo<{Jnidmam5^!2;@`W(rts9ibcqxpu5LP zmukms4`;8IT!HQ;hj}{PI|?D^z)fHp4Tz!fdR5=gT@8tZJg!1(Lz9wI)E{$ZdE2yS z76wjf4oJ@hg+Swrdna|mmy6%KGYgMWBD6y|he;B5^1n{2V>D(M87l zRPIWGb+f75FNG=7tl-qiS2@lmuL7uM8u&dv<0uOu!}nQ6w|0@;6+eP(1- zK^UY|SinXozGa&4rg~0oL>#tvFBvpcf`Y0eHQ!Y3Z!XYhEgW=lt}}_P?3_&M@}Hocr+e}{&`y)*#>1GpV|Kf-qM~7YJ4VD%H6iULr>{C>L{QdFr!&q5s*u#F!LW0cW<~Vno>Lu%auh0cnj@oY zH7krpjU43-f|6@mAm*bgD1s?zrlKYYAr>0R;$m~RGFCM5;yXOaH8>{n!w{%doNkJ0 z(xn!sI@}%O#^I63E4|X4HaXI!P*HyyqshwPzg^?W@JGs=i=jN#y3yi!wLs$(LE?4s zoI49hCj_2(c}*ZlqTV=;f^fW$zk9b{mIZMIw-Ax5gOi3KNJU zRg&d=u{U+vbKh?^bq>cB=;O`liJ6-P0Yap0%E8Hh6il{(i1 zL`X%7buP7?R22FmSMf152OzsLUF&kHA{jiEnF=67eRJo0uXj4+_q!f{DEV-XWz?gT z6>u~aNUVEmH3~0{O-jR3Rv0~ets?FfGT`#7g;h~SSvB;LE)$_-er3R*sEdxMNy>V# zyyoVd(PVfwF!DwCng6$_^t>v=o!{Cc+e1BFyn{HJj2DK0v z%3zqKrE!$Dq%k%$T;>#2YI)}{6j4W)QyGl&jR(eS9#VqWH!{iN(`-9wcsYH&c=0Tw z>kj2B>kQ$&M`+C3TuRXw5>%*4tiqK=gS6M1MLLF^#K$eEa~6tRscz11bl#MGc}$6~ zUgob;S+|ZijKE-LDVF6i!OKMv8I{A6n;ejbJ<{P)uJ3Q7-!5kR?B>_1IyaF*cUDzs zkQo7xp+tel9c7e^#bbG>wB0jS3?U@S!>6oKOM;E6<|i^hv6$Tf97tA+C+K{fb@F3` zQ}HHFqvd}+WzWzG3MV!3Qr+o%vc1F9@5y%^BB_)V?@TV& z$8w!%t{|XeI9B6DR$1WcX0BbdP!@HD5y!}Un5gq6@0m#5;wWv-X_{O;S~%~P zx!0K4K}}5Mfmpai7YLgvg$bUBeD?KtT~lcUJlV*dcWd+ACntWccL+#)yx2sMOL0qI zJLd>LCq!p#tT>e>D%`^i^C&k8dAu;2ZOLX~ar5=xH-XF3m*QdyV3C%d+Mx6+VN16N zikRT4`DeV`nUzgzFo+?{>bKu}y%R{HKeZc}T2fAnbMkU3Zco7u?&<8RB8l5;T;^_B zqP#7M-ex9=D;S8P(Icn0u;cM3^4?Fqp(kFkIV#ZHGAN>|DwP5%qmiNsA;_Oy*WKJG zeFTV}l43_Zk~l#!sE*5(_2(Rl;W=44IXaoFsn+w^1rYTJsG>EliR3Pbe!QFlt5E#T zQBP6!g02(KlvR8wr374|*A#XB<2ag}OwL@&=bB;#YAB}CgitrtzF@jJcIOfwk0H6pj&PkVQelWj2==!j~oLKU>^STb=@onl) zd$G?bw;^t6s=1X5C_7t5_g#F$gu=4-nBthLEM2@+ zghQH0+_9k)mTSdegK2D%3FcXzS)T86aa9Er8a?%m^DE1p?#F3$IP&u<^UT5H2=u*o zE;CK1S*$T~`0J^NSBg289mk8Io%&N+lw~n}1aw$`z-qKTw@>DAU3L2*y z!tDrf*}^Pm7-4gh&dKM&@8*0fv;016q?% z5Yi&9g=U^&BJgteu5ND4aMaH;#9TOXmhKDGQXXXv#%f%kss{F%w8uNkoZ4nm8=a>2 zlDTSfs8@$`Fl9NIVgknJ%+B|siKX)0wP!axGMsj6BUP@txkqAKPLfZ}7$(~O<%Dja7$S?1HJW|7xOA2fG4$tR8q8+V`>&C(LGJ5c>NxF1PFtm`k)eK?oG?dA$+cLMOthE#Jz z(abWku;V(tsvOQ~yB@AuI+FlWAzPc>(bTN(4a{mzB%EsnC&zZ2xtu`B!B4fnV+$%u z&z{6lRo>%(IBBH>U8C2dp*$LQxfZ;4DX!Cuy9#6!bEf2;=vTY*+~omO=+}~RWfW%I z>n>7fGu<+{g;6r1EJNt!5foRMB$a3(58b${T7?n@z}7_d{A2*B1(mEmB;p1jC?6x$ zLw_E*J{HYZ{I{3&`Q8}FmY5>%#>l*4;#j_*wu~W^&a}XU5&<+#ofEvbmdmzX#=~m_ z$E9+_y?rHjxt#LPNmCN{QxBi5pKPF{WC0R)46+^=DFuPx?U~c0Ki1ypY@RZj(C>uw zlk1ZDg#beX5fM+~77_}OT{cSy z3f|3-w8d+ato4SBhJc}_hq>14=Z!4Kb_%4Kj4$a_d)MFo?oNkWtedXQ=h!Tc` zrKX6MnnH$vaySfbxK+N(Uc5SoSciAZhomiQBBe>0N`)v`6k-d7CXBYqeBAcuzm{v) zF;ehntGQJjvoi7A)Nt3*ZpaAyA5M!ook!hpqY>O#;X$I)nC}Q4zz*^y2vrJFo+P2^A&>#6X-tR8Q&Q7Gs}DrC}$kWd~(A(EPmfvO$@L4sl`l2n0EP*^D8&}Vv8?tV-#={hlFc??)h zDJofIXdzKtut_N*Os$9;hyA3;X#l0=kP3vYV#R|z(4uN@8W@K|I}xPWJtJ@*w3~#a zrX?ucJtHAC3#CsmU1+7`90V6b9H<9JhYm z?y`-hB@SPn!BFA0qsS-A#z+uaSr8&9(2AZB0d`vjM`l_95oRRGNXWoVup>bNWvE02 z8+KtN+F-SGSEw?-czAo<~8VD_SS-wI~~rytdW%Xquw&nXW{ z;U!`XiSWRlI>|)v&HUEp8w^nL!c>?gLNX!8h&gp77^d1P%s#FPg8f2(u0{AH-J>q!28Rvw;U9LSS3} zx&#dH?jR54A56}1(kC>$&-?8(iS)eK&XDw+t~*t9(DtbjANy&HvTb9b4q5}GsBh_2 zeHeY8GS7d05;6=QGJs_IWP>9io8tJ&>JGR& z{9c>hh?TsY*lf>VkJBNfizlmkIg~|7P-w9s=a=J~Pfybh7Ot?V+HNs8!*vP* zgApr?UQkP<;yQEA<(qoN4|iLe&YyRRxIy>6L8RH9M}=DatPq+2fhFW9%;RP}c(qfK|2FQ#ajwJZGS|DPG1E=j0N+cIp+6xx=QR}h0 zcQ^yW2Sj75kma~=zG(0FLd{SkL)R6K`dfpA*PFZz1Z5nIBXO6?oI`9w!c+h>s)GD* zx*8*YTDU8X03s1cz>dg4j5)(iVMaR`24`8+tMPX0FQ<3>G|F>WM)QvN#sx&*dtH#~ zgy{wK4wceF6w|%$cHNB!bk9fetGngBAi8^|c7u1+4Xp`O43n5}Y1D~LL#~n%W%S{O za~x=Pz_3%~95Me-LrbjJF`B&0Fo_u4vFsZf`+fJ$cA3AgI@`}vbUh*2=!ZHi#ODlD z5m3k;p%d4ocK}j_=%jD#uV>-)!T2fy?|F74PfIf5RcD@hsmUiuLfg`+K>9Wb29~56{N5@rgtwX*h|Zr&;Q4^obXuwelH* z?zxv>q1i9N?Y(@RvsX7ZdRx8QzF?`cs=?}&Dj9*Khh}$RdexKD!bz?vB9<5gU@C*B zmh+LU$-J^;j?M=3LKDP6HY&u&Jg#eYsC|8LAGY=Le7yMsiZ7hK?&N#PuXL>M;_s^= zq?4*<+0UJFfzb)e!Uar^5;`L_w9YV9>HLD0PL0l@FUlXz`Otr`tP+eA{K6**DhS zH`kr%UwK1%!_qZ(k2&ctr%dY|A!&R@$Y9CHlDc%mm%GC^_0zV&uY2vzr^^)TKK}eq zt_P>Mh25qn-95F2?Uc%~aNWkZLxw|-r9E|_yCvy(PlihE78V3-ir&V6odS z5ZyW;bxG7sJ26NpjLlH)=(PI%74>cXpxV|T%rvuUZIi$$)LiFkAj5Y|JeO$eflZ2Ec7Tk1zuej9wy}Y-E!-6a8;l;sfzh3l&elVX><>+)IzTE1mO4AR z<)2=BVc9rOJ!$jx?a5JRx6&U-rl(W&-OKz?xnufs%+j+@rX7=`r*!(erZdYgyYD4< zvT24e`>?1lls-4(16JEgki^+puO9vP_}}TO0fEUBLwW@+!VM7im}Ed4jqxx5`uW`) zP6IlKaxW4tFol#MN8hYw3-M||)4HD}-?)6`CO)mO_jh^gc(hotO*{N_`t!GrU0)lx zV^zFIYNT`|>yyw-#?f#of@2tv!08p9Ou#*Q!DWI78n)qBnKa>mvJ_XAeHxdk_|^!p zo4>rjQ6WleTnI;9vX1&pBwCg0N(Mj%(Afd}>}k)0+5&_?m+u|f6`>xLUGa?VFaprH z`dLwWEUtk?-H`+nj7a<9cTn5hbY7?6(2Hh^fSJm}Vs_RTXv(RBF$9K?6B`qH(JZJJ zq`s9S&8+KTvdlPaefITh5uu{~R+<(+HpjvMfQD@)+IsvpNgIVvG(5gYG=yZY;W9>T zM|Oje3ZtgS3lIiES~1e+ZNuZ^R?vzq>(OV)NOo!D^AeRstcZLY=# zDOp~qcHeO^U8&vfnEKS{Z?vyh<=ef7T2-d)3)bdA}HrH8~{l4bR5wJF!u*Cq?_Ba zs>mAB0irP>a;jxEY>!cv@h97q;pZ}%2EaY1#@6Cdu&cSw`)FUdrXdZ%MPH%aK9K8_ zUtMT;_o&`?#CCtAA@;16Q`(%laB4K;OEuf(`gk?v+rBd-C#H^%cS*oiwWqBwnsyZ1 zTI)GboYsah%L^3_j0ACF(|}Cd6t=$z68F<)Z!jvx)IYf+5=I6IE2RJ<5v7KWyFtos z8F@;utAg`wl0G^X&q7gov=U6BN8m1YgXp=5RTvvMl0)>JUptH72@jy-gMD%i3Di*Q zz36~)kzk^MQ|IGvW-`jz_`J(2(fWvbIMk<6Y9NI@LMb6<6hLwowzv_lj;rKh$b*a! zKm>uA)3z9a^lajHbcf2J6ur9dwD6t#-w0^tp5Dl9OD@zLq&%bAhTm%{ZjyUvvbggXi(8 z`#!0`N6T-mFf~{jo2j=oB=*5!#t-XF-Q6=7Vj_6&z6TN4&V2aWN_%-duzO&0iuj5T zAuu*<+455oaf~41EW?E-Gw3kwp2UdJJ2!g|2{?QGvsYmI@qBOV3O@*P zCtG3fvC}IF!e{3Gsfc)-dWAl_fvgQ=D3ZS4;m)ryLZTEnN9XsMpKmMK1lP|MLIr!+ zM`(Mv$;HuP5#a0RUd{~7CYFjd_dC_tfgn5}d1XV&6In^iCGkUNrrCLmD-Rc4hi*RK zpRTo$ne=*bzkMq5%AaXP7Bj0oB;8b^ux%n(^*Yu?)arRnP-dqt+JxRu24pTn1kkBP zalQ;z`|G&Dz}z*|*kibtXqn+!N;pvKA6Qc0-YjryG*{`)uR81Ry>}fV?}4ylzR@{M zqqPw#a#sxs%$AaIBsKX1x0^&^=C_eA3)jStgf39FnD)l?b)~LAYZO5m9X@nf5hE+# z&Ewf_c&dFM38Wpk?Y-0mRGy5jN)?s#M~smAv{tV1X8;gE1(Nc_`b0XJEG2V#K8^NA zaM@5gX3+4G0+GHd-~vZ7INiCV17ss_)9jcajKU0@elQ5@*8ctH%>6BavyLeOs^zhQ zt0icI@$>Yg`oc?uGbz8^zMHQUt`Qb%*mHHiSGYHIhtmd8(1$@>WeMLCtbi*hp=? zK~B}y;k$Z!lou(ti4UcRC%5|}ky!}s7DoQfhiKkgP!F%uN73JXuhUkLG5Enw0OsS< zC^B&4(<+qqNHi&H_50&p1zw2Q$BZ|6&3HoE2oh}DvdHVCL+SC0r`11np3!20_=dU9 zwaq}NjZi?ts^X$YNH5{cnv^^=JiP8I9ZndJ2?!znV^U40@TQM2un5ke~ETKO0rq$&a?Mya3 z^EG-S5Kw{+Hh>D^2zj5iYLu_N_CU?gdjh@;gs=0*4d2QTe>Ohr&pwwKMDKprznAm# z>wj4YSBsQIUxLC)34fy!fTTj_A3Zg~uKk<2@EFPV`ZOrcQbS}9d1N{;`nq7MOzp-7 zcD-GkN$|`=QJ1|9J=?{$DHQysT6NJCRtMpe@!R~E4DCZm{{DTiXOBed>k$BiMvrHN zPGt;%Q2>MXa-lF;2dPlMSy^vtQsgC(%wvRMUFlRXc*nw$j#_^T${}-UqmA?LOLSmb z8Mh(RY+>Ht?cMSBX--Q==aJkFEZh$}g+Uwl1MCn7ll$HWWyfYw5l5uvd4OhxYxiti zYq9h)N#8fNP4Ot5-uNGUg-ODEITx%$Cet7y*!-4AAiWTow95)VIW*<(ns%$QR#xxy z!$;K*A?XzRb@piU=a8Xreh(ry>I54wi4jfeo7E7{zU!Vaf_L{C0m?UmK0A?=(()L( zX*;g!4v=r8Qf1KLyjc4)5bC-?_dB_9e7=tz`AVSm3hbyIZ>xWmYaUXSCDc~$PV2fT zO;ov!s(u!lc93gY*7w6BxEf~5Q#%mB!BBIpPbRjMu1IJ6woT}T6IhpK@3*{8SbtjmicO19ZUI=swN z8fjqkfj&&T#}xWmZ(5p*dtA(wFk5y=p1N$f7P%C!$8bh=zOJt+buDsYN-j`)_3tlT z`xVUVj--!A9`7$dJ$J0=bFQqvLY^7zT9nSYu=#+XgeY{JE1Qesry>(I z9@D5f;9s}r%zUi5>!rt#gTB1;uU;Y}G@(K&c<{wi%UE=v2?Id9QU5I#DBd)u}cPT!*%?WeP~hCUy?Ys1XP84p2K zeJ0i4;@)E~dD)F;By_G-eXF8zP(u1@^WVC%HKYefFF_X&$i5UgNGrYOgO3#&9G^uW z@`I32-=qD3knQ)0`fp&s7e1SGmDRjh7f1~UBk#~|N4x`nG`8AS6Tj)l#4!5M^T)^^ zkxSoSm0dQD?@8M~op`aOSR5{i2#P-o8ARvj7IEM=);iOY|57; z6>o5beP&cJa|V7ih-YM}hl5fr(cj>-64T<=VgnYvv`2d9Ni-m5XsF*hf<4MlZpFIO zW}!$g?LxtA&z?5*9@?ipwux8GzI6lJq>QI!k8etrLa0KCj^TLE?BZ4(rIFH9@dUYa zPB*PM;c3L@(&%@$fbxo*=TEIg45fC@2!uS_%eC%c%H?ECCKMPMTY>6Zq<1tNmFXfq zOvyDX8wj3?FH;o?vByMgqHbJVOjHtMwBw4Oq;?Xs+cUn!ci1#em3a3@C1p?LMu5WzD`^hqXe zbG$wDQi{KdcdOC|$eig4ghrZZhz|&q((%%>A1U>?X(2rs(rFV=5NQt&AJeOI(r~wE zK4@2*d2Nx-(VN=7)61MMiHNB&Ei71tFkALs!#U?(H|6=6_6|pQ7~?)I>~uZ=KSCDL zq52|#vK1Hs?l~7H=lZAju5OKWrE=1`f8#@rsFGTbbqsSYGJK<&=&zH9hgG%p_p~NW z&E|5PoQroIp%jJgF4E?`#NFKbBo^W#|F7$Y8%jyo(L{Nf%nc{2D%5MaAGfRIg+Gf7|)HyuY6O0o# z0MG1y$8MfEME)&0O3~;ZSx4x_fGi49*AinS^)X|K=O{kj*;OH-Dp64VOeIkmaF9Bf z^%JsQD0k~c&A)p8uD>RD>ptf|D$^fXWh8Cwhw|;cn$Vja))3&~Od!z|G7{NAt1x-$ z>=0$)C7%3;&wTON&579PsH?VSc2>K(JHVQdn~ID&hrY$e3o(J6r%@Kbs@tdwxIdiDJG_09_RPi zFYpJt2j}b4`19lE#vWqkV1EJzs)eO=U(5q&e;jf61I!hzz@y_*H_<5w7eVD8~~e;g&qMdCr7&!+m;QzpMnk7#}0cax-U zk*=lntF;uUs*;n~-k}^JMCrnED%pP5bN8J}P`&$V++&AUBiwLp0N-okW+z@VPp$5U zJo=dT=7hSvawu;&KjY~$jUwu#A~{n8A9AtQo5oL7Ci~MS`*mFOt?QxAZsV>(>EoJ3 zbai>okGa^x@5z;G(^OI}*s8CaxUMS(Jw&NvZidlzi@znln&O8l&z`pqn^!(%IG(3}kpH9;+H&@wkT@&L?4M0K0+p+nX z@-^=5PM2Nhr}^)fdF<sAU^Q zwM=U!&1O=b61w}|ZQ-0t1!K- zJoCtK>00UDyp`D!n?v^gKV@KN%C)CSp53;_itnXwncVMg94%?*T zQi5Meuer?66~2?3-pXGtToE~@^x+5;8EYuyS|UHaGuK+rkCPu-U%K72`;iV$iRzoC zBEEgqxIRz6Og%4ob#)cYi-E&;T<_wn$6=2u-kL7lDk#;X{al`h)%Ve8BXd7g;3|A0 zL*q<8v==*7@ur?%+k6iz+Q4gF4??APtcy@^O(s<9=HFS~Z8kMuTCZ=>`Z_xEuBx5; z=CT_xZ_eF&?R&2hb4!qhqOL~P`@k_Kb#wS#JoyJpm_E_UszXnS7ZJ_`)}V@CZ0T*= z&vN2|Tno$nzIqHs>e=ry#KI>QNn*-aNH_B08@ZNO!&SbCqx9`IC%S8U-LD#6X&dUb z0iw2UClfh9ew&#D^uP1uA^Et4GaA5}(5eH~Br?v2nEN2)cL~DEoyoubsCz64n@TlVnYRfRm3Th0vPLc-ZctV^cOJFNxxYSi0%f z!u$H%PZKgIrg9mTw2rUrgo6ZcN$)!(d(){=kd4x0?JKT%sqG3OAKl3JXqPO?RRM9& zHni{Gn;Dxnix9MADf8m?Y?EgzB~w{miffR_m9KN4`HR6B@4dNX93n?{H80IA!)>y} zj#@=KwZFO@50Si-MDZb|Vm3FQJZ?QckZV1tmgVVPE51XXJ)lkU8O6#sc#R^Wo-W^$ zoW?q9$^>A3&y33Xzai54FQ^uJhgv0kZM2asr~7!o?t0y3-5ePWuV};*p7<|OxCD;# zx|!R`sxa^4Hi$`q+kMV{wDm&N=Z)GgsPMf|pQi`gUpIH0`i*ln=@UAt^)ejhJ=JeI z^#h(DXiwOwEleR*@cH%V*Rz4((drpVA7U`54P~ci*o*Yfawz z`OU4M^^_h$dQebD$d9J>{`nrg?yo!PeVA^}y?ycehtoH$@J6@yl{L~R>nezz*Vg)8 zK3-Plk=+u;yGL@6fmA}dN@{@lo&IOINttQdyz|LhBr8N7=YSjbhdBcz4%(EH%(u~J z74IRIy>ujdU!zf|^vHSdO;J;(^DTZxbM+4B>W&TNVsfEe_gv54pI&wGvAy;heS?7K z_{U{t?(oz@(Ryab9#A_Ib4I?=x((8Q2z+_y{OhrZcFL8BXI_&wwNXJp6NIpaU7Q1u zKh41-gY{h;oOvf!Qp2M7w@%6lM-(s^B+Nx5Qvk4vHA`&UjA@~Qv1s5LZmDdJP8Bl z)9@s(=1QhQME8T+y}dO>Zcx>z9wphV0kjQ>W>SA*VxV;iSSrUzrIlE93N0+Nd$gXI zed76-DR|{dIRDz*29X+*cwlE=ziXvDW@QIjy4k3zqA*#kziN8Ia92HdPexN?3^;XK z)nLJ5`vho%|2149l1-nKLG|e}rB!2=_4Hx#oZz=CS#pX?7@J#dQO4(zcidUY4W|LV zp?U7G+wqbd`gEH9f_;bh!cdm@F1}cd4IjqH3R#*m8bNU*sCg>$wEBI0nx{C!W1qz{ z_p`1ndfelGmh&L<<#6U%gpiiVcfXQ;zWH}b;?F}NS|DqH0Gtf`d4H!~^4f^RLugN_B|bYq2glC)A8j9( z;j!!2IdZ98-spLK<*MbC_pYbL7PpXZF|t2C;mD^FDja-+xAM{N zB&{h?w11vIVDt4yhkW3_S(dvr^6*%P+kI?P!?GZUT0n<|g;7HQ&&2_=kro zScM$7b`{b~ss}c3QN6HPrBjh>%)33x{=*REbYQEjn<0kL;X3BDdw+>fiNZ>zkTOgm zrh=7nYJ4L#R+hP|CSf5poEqZgNJ5-XY)vx9<8HSKRXx(m?e# zQHZ;J_Pq}P0l5jkK%nQ3>isvn`=F-`yKSu7TXcs`{QUafZ`>^Y-4J`Qn0fw8D8YwD zA3xbANg;uTA4sG=dIP}s_Eq=wp`gd(`qz;Uh)W7Bl)xj>O$0$7?UBmFpVPV1yYu_A z!?IBcsU>HCZCN5Y@|hY4_JTA+ARI23i}>%fDp{q}@9x>Vq8BKHd`N?cDqG>zU0CY< z8L4by5p_H?lMh@ zLWq4esqY_oGTNx7A9OM8s+{5W-Ny7Bhy-epqk#owx?8r%1_d1JjNCPbp$r<_jE&fW zR$}Kh)r%YM`k^Wz&{#s8v26ElW|Jh3Xe&B%~!u+0;)s)RUo!f23F>zbgh5Vn>qp_`d>7{I2DGLkWh%Foz_1S6Vk` zJw+0kztE%d={jEbb^J6>ecv{D)aS&;08U75R1y0S;3zhTaK##!wiH>Z_TTx8yOa|^ zehM6R$ea0@Rp7pKm`DuphYPd3cH39BCPkCv9p|sFe|hgklljcuGc8pZl?xSMi!q|h zc|7!XpU2nXKiGlej1K3YC$v?sca_?|Nhcl-%N4#(h`Ye^(DddDZ@N`XDR!kDbNIgf zgVpYbh<_KJxyO*?iV7$~zl?=qBvY}}JU?{L2e|KNe@@s;F!zD*S4=>^$s@!=UzN!j zR&f?kJPdy2LjIA@2=|*^f(9LTG-?r9q}OfSdMxGZb43KE%AGNcR8ry!2lwd-mI1qwPJe*3lH{nLrRj6`+ClrWn+N z)llRGjR*wdfBJ{9}%}7WG zVGgs3_R1Kk(U;d|eNkYl3PbQ`UN{ax%c&e7Um-nCeI)jt($aeGlSfG0pN0{8-kj5{ zJK9Bn?|&Y1Syk}@=4WOYM6c-hG$xU)tK~Qa9?-C7ssILkeS*V7U>;%MA8mVhdlSj; z^HcqzkUs{Fc)hP}9ZzBIFEY|Jg$U3u-g2dBP5i`%sKKmY##q<4-&;_pdqDgR}2@=6>Z(iV0@on3S~4yK9n-JPm_QLm(&$3C2CwP*q~lIb5y|f)c0S>>$n81zxH<}@sbx5(*dI8%XYs5aX^Zj&{>BG}13 zsBS0QE=p4KmQ8~qHtnSK_NME+rb^8}34XeFR&a-mT!b<~1LAe&JcwobRkuw|SkAjv zd59kDWCBA8whceZ4o#wZ z>d{-|^?uL5&rNsSxo!Z1MOg%tsT0|=aWDuC``=E<=%Of9of>Cv#I9GV-nzXW$VA87 z&&9Eavn!CWYvnEk?b|UoE{qg5Yl=TofqP$kbol4e9L@$#>SIu)sZzu0!@oH^&v>Vu(Q$EYrBO1j6r)c`volHE!tImajcpU@qN?EDKOI@I zV2dTDVd8j(?_MVcHSI9T9Atu*FE(hVAB^UoIh~}`>#kas6#cCapM)$!w8tRd{tB{V z=*=s(84A)W`SJtysqT40Hg7JvbTdjI%%w4uJlzSCuRJ#{#w3n0<5kWSSu+8Sj=SG4 z-XcpMh3b0PNLOmE;P5J~W%%@&Bm z4LyS79Zp-G&rA0Xof-uMX0inz*72DOyf{k%+bhB7PVNqy~8n?%jqV8El6ClV$ zr($cXnV5`!EenOV%0wfq7fjU{ZfZS>8?UEThQEV|4M#9%?(155xasbQL&}&31|i>? zk4h%TXnVUC$)C3|Lc^grJ?tK5a4hU6YwLPn#)!nQBqqJti$_}QEn{D5#Jm!92S^uzZlNxeht_YbN=M?ETt zT8&+J*w5>#qON6z0*qf$>Ke5+5=K!shwPL2YtP4@!*{NY_NLXlaJ&cJ@+Wb!Pv*#d z5#zokE)xTF@BK~w)%!3_GIGSyNP2x_e1s>>z*|jbUKQ6*bjB(~Zapd)c?m53;fn@3 zv-xaiEMX;1RxRE?W=92)R$A6UgaW)P&~%ZlZ#_OD=$)?Hx%06Z($y8rWk0%l^&Yrs z^Nbw>jNo7#2_SLP4roK?EDvBHf*rHBulKu7jDwMs%@6QHJZ%E?(XF~0+o7C8Q1p>4 zteKECJA(l8yMyyc{mP~TzrNBjewAlEnEpVX<^O&`=m_LSTR$m_j#`)k$e+(dBom)`r! ztjzC+rC!V@biMc8)lUTb%Vt$L>pQNLkSEVIO()!PlfM%)*89v`md=w)3z4!lZ1LjU zis`*_<31&NYRKydnB{3pjb4{^6CLX_+hoB=uO`Q~+2UV78BUX}P#y|TTeWXB4xV?< z6MAM?r54`Xwt3Y;9b|Z#n6SrULSDbiakPNx8cTG97b)hW=O-iH=KXqUYU*A%6O=hB zJFOw+-s%f?HjwPlZ`jfgW-fwx=6QRaR*I#BlYMYWhQqXHu9561c4&p~sqoR<$C>x* zrIlM&{T|=sbAFCz(gEO~Jv*X4o2Qu~o$Fbg%(A!7r%G12*0x z`pra!M3qpbb@QtF&t3SZ^Wsf$Imhqhar>u=jPuenX*1B;-;K5%O)L4CY|npQeEaj0 z^`A)Z+WGa$5v7lw_2~1Ri1iQef?Zl4Y2|LNP?9(I%qS#omeoPtZgB*05ob&3lWngV z4N(Xnw?x*6S_^xGN9DuILspNB=r*G%%YO;IXT}UhU3AoxnxE?i{v%z zA{6kAv#c^`_1{sKG`%8stzL$iWcaJvOep^^=Zp_n3U$(rAGEk^`qf=f9epHG;AW1K z68U%wIS=zmPQXLSEDm{13F*SDx%RN6NIve`h$MZ|iY62)EI?Q_l~hL(M(&Og$~=p? z!h-WGLci&fa(Tq6`N7=1-NDaenHemnL}W=PiVj$@k&5%M8-B=Wo>~~?q{MCdBvT#w z-bOr@dU~FQo0(R6W?_kxET|hGZ9C#b&)2vshJWW@-}nA}5YPJD8Y*7{Y(kfZ@A42t zmLUw00s&bsN24dfa>7q%3~(6YXy*9)hTE-9s}22aiw+Q^X!u6<%7Vh6DOeY2h3b^npr<8muy+6Qut$h&v!h-`2d= zyBMgg$T4Ss=+~d|{$UMicgPyFD3Fv<5mt5SNyEG4H#@VjoJ8H~!{d6u?5JLrdCuwQ z$6rqj&MC5fSJx=7;cg(|wAfDyD22Fe3m?@zzqt9MP*7-W} z#RW2P?>OIiq*WA$)b#7FyK2r!31Fq+D7bu|jcMH^iW)oSZN~jLH#=uIeWB`S=MTu& z{JPu=7_3ELvX=Dy1f3x3%|9QG+{y3zNu!}W7zdsA-Q5n~PQyw>q0vA-nhz}~amnR9 zBlPgQ0P2Du-vZhcfZl(o*TZNHk0V|F+#uQ*Wsr6A@N+-L8cIR;HQYMG+O0{}avC-C z-hH4sP&$k3eWmX^^$*t{ub&?&paf=+WE^hEJ}{r+8P zYw|Pw2bWHU#29&%aCs^qL;X~pLWoiKymB?4Y`SWwip34lR_f1e;WlE62#JX199g48 zVj9dTnV5ODIQ*j*93u9~z0;cN-duiw{}U@7z}TH2X{9L&0V1Y@$}$3d@9?fb{+S@N zbZ`K_hiVtdymqg_jNpVKO%5_zR(T2_U7059Kx{?!t3zktox?|caJjfCUrPIY3~Im z#$){-)G;+RK++UZH+NBjaznr0dSXLRw7=d0_OPiJ91lKd6{0{zNU~sQ4}jkn)s$XCE;5xa#x--njEEoj6OR+< z6nLo~inQ|j0n}I6vLLYSchEGWKL(oiHf<1?M3Z8_RmNRAY1lbc1;T``H=U;*(m*T|EUZukgNQb- zb9Y$;Ns=~Wq&boxrh`)Dr71TER`Y{S+=1jbCdZ|4yXreKThGV~s&ZAGkQpRRjm{J> zrWa+vpt}U`aK)XdW6s_X_B~)z=!_}OH0-AF_dz&#F_A)G>l87bGGibsl)bAab6rtP zLWZG3Qga}hgaVayAW)%0kh`b^+%BXtM`mD=h(gDmr!G8(QAOB(d_G{th+gwuv>{+J z0@qnHofVi(=flcjX$0=vhkAF&xl|VlECmT+gQzF?f32GhVHSdjcsZGsYTRZ|S5qK{ z+WgFzq=>*!M164i^SN1~6iPAe)_eJw{^nf%#Q6xV7C<`a# z{HrUgVCvw8T^Uhgig@l?(xojlDM3}E-yKE;6j0DqWC7DKeLg@`Lc|G6MI{C)pY0AV z<*!b-z5QxhNC-2DYjUUNMx^fnkf$en6*NkxVfAQYiS4$}ZXw1zL#&<*Pz9d%Scykd z+0oHmPLs|qy?Kq?G>2%4X`&HGq{;7sSt$dFFu|D2$|#7cDaaG2P8@+IBr+_d0+H(h`9RJalg?Vr7_msO z<35;qH*sLlYEK>FhK_<_Xq!_UV?uGiT}jM~K>A1>NFq)pWGm5zB=u-Cb3XCG0k}ef zl7Tpp%9Nm>J42~WKm`sGIRr@1(iA09Qk0-%g)~%D)&%Yc(* z04fcaNT`Zn6qQ1QrwDG9EpT)sgui;sv(?Z$Sjn!8;kW42QhdUKMef_+ejFI`nMWWec}lU&wmZtZ9R zrU%u6#SDf|s^mO)tz)nnU%l284L~07DU1kFxm#EO8k9P~ALW>)q&b8+fOP>#p-e!Z z8qSisfK9*wL(?!y9l&HSNDgI0qjDq6E2vY55Y!w>4&zV(Rk(EmYDAznARC?_M~OAT zfs%z8B2tu#NzxJG6+>_U?hp+?=zujQL#TL#6D1sx)B})%k~`$VH#CN`6?JY@IE3e% zd6A-oDFli@A=MTE-WZaUpvfsiCYK;Q zYa_330Rh>p>H?5nA5rZOw9Im278F-^^iIk--p9Cv=hH>osL}VR1r?PZ76N-XewlgA_@p8nk0awDwdLnlxYH* zrjdfEsFaGKiGl*6SduE3f+8XcXrX3`V2FYV2$>*)nkX5HDQF64LLew9plC`0hLRyE zrkW@Qq8N|}SPG?S8d4w>kTZGXhhI=(=(|*pfXH}=eTzxS^l?Gm9s9>V@<6>bJJEi^ z7j6y-%ni^`@RcHvJJPJ|%9P))VEzzOL!j|qihEiDBLg7!S0Hhk4Cx!a~ENa2H`plC>aC$;4XJV30I84G;O z6jY|FVZseSdRcP-Wz0D#RHXyTT9rPK4u&1V6mAsBMvx*Xdc?qTKx!IXk;qyp6C@6j zT3qPz9Q)fOZk4ZGKg%8;Qcq|kv^JQ-Ubt3mh<>te>l@wE+d6S;hX?kMZ>)zwo6+HI@X1g$= zE{9}tB<(YUySqvVxK#apWLgiiCsRxK5%H##d`ot&O)b2#06h*~Kv$Q!BLz|%FE0>Z5TVd$rIh8qr zLUF^*)(P$bRMNRcCsbimK$N-RSIvgbtg+)O^ zNOAC2KJM$SW-6|^;(M(AJf4=ilm&gIdq7UDPp9P5)|%u=OprTvZ!+RXsmFF zTaf6GRmjP%Wldxu9vMKAF7E4&IpmdC4ls(MC<|<#`sly7!y`7(B&dsfb+82!D6*qU8aW>~FZp?KthZ6HP=*PC5 zU?;4&l<{cw$l-=k++#~wYm!b^H+89}Rz*hVxkW80nMNMn4ba5hEXv#WIBP}YW+M9pK7c0ApA(}H%~oS6MPc?B|ns&NS< zsH=GYxIm?SCM`EZ_Btn!aBBGR}p$geelv4tufZmT8fPH3q@CLyMhk)Wmz+YB|@K)p%IAG#LD(0#@y82J{}y>}jT<-~_3>*mkBjmUhH%;(A68Lngw zWF*q2%ETH`46mPYrwqms*-Uvmj^RqNQHgg{A~A$P#L5DTp0?&3q9UTJj!WxEC@2{~ zr6~$Xsj7*fq9E-#4;;tf?US1xcFVhhZ=!L)c{$jerUk}PaEM48;~ePt@oKZ3sjXOq zTtiJK5-vi}6jDi36$LDiL@-oTRFxK7s)~+KR74FS*LEjnhmKD-u>u}Ny1^hDkVgoP zRYC4J=VGH(x!G~VTb@NwlBh!o^W-w+Tpv-tDNM3*5_JlIjbd$purVQs3jjGMZgv!L z^SpwH<;N4GB$*=3j4ok@XDM6>sR3o%Hx3s#fxMVRPzNBOMNz^jW|PTVn^WCfBKhP&5HEvJkpMMfZIZfA2i)SBRe9inh!_1<{K zocp$OpUBk&IA7HmR8P}8R332-^m zFykzoY8*oxhcv635-6gqVQ1x6pg;-JZu+U~Y~8 z&pl5cAg3o^suPTP0nXg*uRwWF)RfUm6H*)231Lr`oE=i_`4G8?Cn=X@U&QW(D*fF% z$fPPDp7{j>^taj&ailY-ys))rEMG-_qKHrX>amb)t@0iPkqSYmBc+7EAjx!Wk zvS7fj@r7abZSRCJA&75jSt5!RBaOs91rrm5(=D>vEDe0q#;MsRkWy3%g(W3*gCuEb zC{}}TnI%y7(j6!9w0=e2<~l_hfXMFp+hC@+_SUj8nSygN8eoa2W@A&NMMIKgoR2yL zF?V(xsH#*VayBOqM5?pg(wxYdCW;BdprNo}pYKY@liFR6jv%o_szqoJ-he-CA+K)F z3LaGfusBg(umcbQ@!JlQ8p9(*RAM5sDLT7`4(j8(U1P4U(F?hiJzf>7E?kZeE01w` zShX&*Z*#>Q$z55|r%Wr8nBjqKL`)S-9o?>ATV=`6``zI=JmBv&9G%xF^EWprQ=Wj1 zPDiCB?(R;x>~qLevT&U8GOtAS#3=Qq;Y4_N73A947hA4WWVAX2-s^G-1|~bdLz6d| z4fQ;0GL<1kD@9zWIZ{akcQPW2)>%cO5m)g7R8u+1yOLy$)a7tUp*dOC?-F^0R8s*1deziKkMMJgTBLLYGmigOAgpUtzmoT>Rr{Nu@&l|^u>iJ_`? za)_VAWOARxe%R!j)ERQfh^5bTf>sxK=Y!Vl3Y|o~(Z>&M#WNY|=F}~9mm5n&m8yb) z>$-2MB=g(h$@yqk2;@-}$_PZwMHEy-!%a<1Q4?6-c)O64{ZJU zt_%f=svP9kDwny42#Yv8cPY^V=?c9beLhKlPjt#FB&gO~VDp%Yv3X@-G?R1<{%sCm z`FccF*RNXf`+L=sVZWcnu?{OsA3433TYZjN=j)eA&8-( zhMGyJqDY`3h^9zsN~ENSr7D7ik|t@TYKmzh8Y-q~NP;1Vq#~k)D5j8` zr(6RkGdCRjeM7O>2hK*7c^;2nmnHyuN^=RoJkGnDID(a>HVAvbaGk1FifL5e5LLXq zv}7=CJ@>pj?obKh3JReGBESk76ews41fWuZrj?~>Qh-VXh*Fin>Dn|V;+k4gn1ZQj z3L2_PqJ^D-h_WIPbhP*y$S4NrnyL`xFev{nd!3gV>KsEnm^nCS0+XdoNw+-Zcwupv zsT~2`VCPQKC~1n>VK8!OJFczIAV{G*6NSnXvg1%vL6}meN)ST6kdC0_Hjkt_>4iwt z(J;d#!fx)QSfxVR8bH!Q3!FLmKd?2lFj7h*zD6y%lLPBf{EDU}3HyNjTBkPrWdpc^>QTW~kS6E_4p$4Z;Z_rA$020OZlfrs=aX(R zHU?L0TTO)OP?73Ksg<5~=u}j~F$tW3$VoaJiY`_G=qUJ*(C!R}Ff{O|24`2nsMs}W3~pePDNNGNu-SgN&}IXUMAM|yGw$e^$g`#fjH7-K_#o>mD% zKodqu!wsR%bqCTzX8gf}iD@Y*7O0!79VFDBQ25Rj15(C83FAm&|4aBb76V{+&7!JGw388PE3bpzXd;az(Bh3&v(KlH~r{n}dp9I2qNaN?f;w za~}@AH^_2-p~S$EbUI-16hR6uhwu?vjgg2tgVU}Vw<+FSvC}@f zYL74S69=1!;H1Sm!1nAMyivZm`60<56b&OJf2nYHA1o+!=pAQLIYe7dn-gP`o0=|R zkNv{DydoA^%XjQ$CRPe z55JcjYM*KvgYuJGOvwQo-=vrLD1C$<&ccgSekJq71_dKET==9A! zK8GJu>_{|)Q%}awIq<%I@{o_WgP*iN9=z-7J=brpALsb&YhfBTT_JLns))6FiJ2AJ zPxNFub>Hubj6}rWi>(>HjdadCZh6I=XD#Kk&UXXGa6r-Gcxm*@hgHuTBrsciGY=is zwW`-#%bUICH!h8wYW>=+5ekj8PBuTHAbIJ}9Z1v6l?5|xl1!#wd4h=Bb(P`o`+M5k z$lk}0c>%@_`K{e|ib5@j>e}vqNBkHfO)?n<^5uRBG(DReS{Q;}gYO%E+7LcEKh&!a zrnGVtudHN-SRW+&B0tIp^NfW|nnW@ZhO$uL_i8@Tf`Xu*i(r{$Se3HV94mX+d7V;y zZ+m@|rJ-%9S7{-wwx7b7XwgeCP^%nq7t18O{d3#ymf9$>f+76_R|D^CU%k;eIwFfS z&%@LF4;bJGGBs_TobRAFpG4ME1LxTLDheO)dz5V^CMATZlmtI}dHoKyyi(ph>rS=3 z+F&SNQ}x4paopZqU6$#UCQ0Ux3(N23ccm{?X5Fxd zM{w884mbk3k}^J&-UKk^&KC@7SKXCW_{`hM!vm|cxGKoj4UTkd&bKhmUwoK71vA&xnTCyMLs>b zgW!2Ffz*#7p!prRg&>?O?qL35qq*VEkK#e?E0E;52}VT*N(M^gj(*=?KC18gDaYZ! z*9Y!W;zF98|88^2a!0KmKH=r<^*UdKrV0vP+4#&f3tNuXNz9g#{ZhorO|tziU{+}b zgu11R#rkgKSri`Ja?n55^bgaNzCI=sb+NVXAy(CXGo^f8dTU3Yf!u%KKfHQdd+=*4-%(Z!2@Z_w@yTBJOu;)#p9s z-+xbF)tQPh)$tA;`@q|P=YTvuxa{ry%sw#v3(wcz?p^)ek?Iyvznht{g*0@7jq&Wb z{O%u*-Wr=8;AJJt6nr6E)CgtN$WUYEL$yN7NhBJ#%5eaHy8+$=`$C$4u4CI+3(Pcu zKx8_A4Qn04sY94U%2$ozI7UH|l}bh8P~u0W#3vA`#2G4aDbiPd|D^pSINQF$89Ub@ zqh}DIN*8Pta%fhN3Iy(&K&G_m%E^d8!wWm;(XK?y-ToiJ_~INLd|=L5FONDrc@4Br zFG~W52x2HrC-cokKD|&!!_#dp;M_R@N$0F}RRscNl2iBsat@cy7bH#^5CXA4KcYg~ zO6XK3$tsV&_Xle)*}a;k%$0)^)v(9DQ2)WwMe3Wd=la-i$ZYC|Ikxs`AZPLYF#8UW zg7UlJ`M~6EDJf}2jO)fwXim}6LuX_=2`f0-%9xzWdS{)RV0&WD&rk8A#FGSFy5jL} z8V9-8G;bV$iD=wDQ=&&uK5&LYJz-i@C@D%7hNvhHIdTA@b;df7st#Z>R)C}_?YvGQ zZ!At-<#rp!svg>m&abRA7;b-EKL~q!e;4ROXU{S6%q!{Ri}E_~s2}1*C_|)ooT(n= z3Xw;(DtAt97#$iVv{Sn#CaMB~qr3(aL{C^;gr~Rljj{c5VTyyf&eQsS3Ti!VeqNaH z7Wq$f@dNw)aM|C~Fn$U8O*H$V@ACAr0w*`^{n7kURQ&vngma1;Oz!SRyS;#Ixk)VK zZg)8HPnPF_e|BAqF%cr5Ii*9CDN)c~20!jaUEcvnP167X?1j4-4VpywKTlKF)O!Cw z**}k(f>X3V6U~cVOv^Z?DTk%T-U^LMG1~q=NK*uj5$x~0+xd{guHg@DO)}5Z|=^weIh1;YDI4|=CbJ1`zlMG<8wv}X%-e*??@aCkacXgbV3o&p+2~e2P(%SM;-_0SO6&%$@`gY}UdumS* zUvGx*eebOe*hQ1P&1_CjDa7Q3%0+Kw2+(~r-R~j@?;~ASNiv%H2#lAZ+b^uT?K}Ip z$`!vgT0Nv^TI~1Lx2%=EEzakz?{OymM`mLq(@W6DM+)1KwhJD4Yt$q@Zda~a-GhPAeOS>OHqO4P$(64dI&dsS`e1a>Y)NbUWi`>k@#r^!N2 zT@#YWWOG?sr5^3sOe>wh{MXFd`Q_HLI-!-x^Qg#@JELVlU~s69%LrSvPYQY}uj3Dm zqsiA2c`KM4@0zrY@aEH{o#SB#uSIvJ@1dakyINDehF)O_w6n17(s$CVgGG(nTft`I zr1ulVPP&&fSzK=YM{~E&&a=?z(i?{T?BL06dW~3fVsmRR&s6@Maf0>Rd(0$yaF6Ly zwwm;T;*@mq5oPt0VIjiI$7`j7Lz_=_kTZ<)Sp?c2IEzL&MdcHHXPOJWEaO4&l0hDI z$ai!ZZ%UFo&G(Kdd1RhTR$C6)^bqHftrd967~H=UyTI$eCs3qyN#AgUKWg!#9W06F zqsFE1vB`9)@5be>XWtW9hL+ViGwE4-Us1!|tSFg%x3uBc$AhS@rT~NI6DiU#fOza@ zLWXALTjgzZuy?IB#598KDEgJJoRIa&NwcBx^%;~1+C*)wX|b7XBV|GnxRiyvIGM_X z_ot|lZJ|-53N%xN7SlPJiHST}Aw?ibL_lydKvO0i29+)l9HpuNZlQqGrw)m1uLQz` zAW&CQMsre@;B9KFP4dv(;X9I!y@qdQ`O^G6wc~Dwew&`6^_9nxgr7OGX)ME|5<+EA z=^b&ife)eSCr`h5c0;#Ie2)rE_E8y@`?*-;)N(>iloC;N?5V8A+KXLja3J2$-^C7U zx?dz4x9nm8*zu1Du3DyC>*j@$ljn2Z_llm8LENf4NpfCQAqPcv-0m>X)DBz?5u=uF z)5OmPTBTf&kDqO>I&_O(?MmoIk!zXrwB9KrtKMVWiW)6#E2lyn!Px~6Yx(0EybiD} z<-?3{E~IGX2JYK!>HsFsW!^TNTh>*HH*T9|&$Ss?y)((tIY8t|`3OrQ7)1mos_l3- z6~cipNv(P6@NV!gA+e9`@YQVeT;Obp={CD4vD)v?A7_a`PE$uldrTfz59EFrKHH;uSl6}}>3%USar`elg*99f8Gh#~n3|b_gz@#mrwl@;$!%&sTkY1Vr{DZ+ ztTEK!2dgH)kf^aiMGt6yw+bjIiKipqlqzfl;wf50p-ModpfzN#8#X;f->;G(k4PBu z*B4jQroxJ%le}O;eW5x+eJzn&havQ_)M0A^esYB2RX~&R+mS&@HlH&%!l4mW#!8ZL zsT5V+z1tNUo?+r06JMN}DM`}F3ZjB)mcN@0R~ss_aD=P@MG=r(&z>@WMD~g~>f)lK zjIYjm*>k+anY_wzDCaA-RoaWkKeOKr4f0^BzB;gqDJFvk_&fd~2@Dik47ImPPa2vN z5dqck--4ZO_-j9J2&8*A_HI-5Wl%tSSS3}h82@gxnNWoA58lQU?hg6LeT{ykQ9PaIU$irkeMP*)nFt6a1(++BwdWs zh@Z|}oe&H_6l6I7#12b9NewOg%HW9-H9@N-p$x+SGC;|R_QA&eEM`cCB|~tgLK!7l zfRrCw^CS)YVg^d_3f*8b7z#Bg7*}aAVgas`k{gsw+O;7|lF;3(sIM7>iaxx+z}r>C zDyj&oh{&jnUgnYlKE^Qm*bu4vd!CPe=J}&k*2o(cof}``7!qjl1(!<@{BBARf;YeK zF3s}q(#bkuy}8S=qlqDapV+;Lw{zd=aDoBf^bzMts~;q$X2J}K{>URv1{U0v_xHZ= z?}yzgwK(Y!Evla~!0-0_^qzS0NX|wb4q@{uwN`y>eOZ&*%G7gZa&<6DP0ILcF^t59k{2)Q8kKFt6epVLY^f$;YjvJD%wM zV{jiiKZNeceS2c@#$i{)2jX6YE=U|*CsX_8beaN$$pg#yVtA7!?GJd|o(X!)%0DZ$ z>h`gBE6l0d7g9UEQu;~6btMiX(oxq(!|m|xuJ~=1aXX?2Pdc(4m>Y3>GJPiy4y5}t zjvjs;(_LqN*WO39>96;J5V1Yju)L(A2W)^XwnDn$rQaSkU~6GRPR_%P)ld?0Bd<(#I4XEuu` zt>_#fDnP`9;&B7p0x9FyP{D-aLyDcs9XZFOkIDe`fjIrhi)JV?ZX_2fNJh=hhzhf+jfumu8keY*?$XX7(> z6PMTP8HmtdfSX$^kJbAfYJMe^azsf;CooeswV;~m%nb+A2ycoWy_{E26Ri@HAR9fX+_?jXWw5cM9lV8IyZyug{~KhA z{AcdCXn7u(i?rO{Y&ce9{Z)}er0wrA`py{`kh~y&p$=LrHFkLd|8qbgqoaU^8EM7v z`2|rHIc;4!+xyydIT)a_$NJ{a&5-}Z$Y|(PH}%Vlrt>|H`Cbzz<`lS_6r)qkpzkKf zQ~IJL@(0xx&l8Ax<6^WoOXp+gAi6@1w(A1T-X45@VfoZmb|WA=*(H7e-|2@N57Z$2 z@8i~zPrkNdaM~S4A*o_QvMiX^9X1dOBH~b*tXUKVCLjWhAxV(rnIL6NQS?0S`OjUY zYTn<*U1`o?ep%Buz2p&*GX{4wVkpHj(e0_;>|EWq?2$_N`Ip9G=Hw4hN3A7D?+)bs zcb=IqN`v^GV#LR-q0)w>#^+d(SVgzdhVj8-Yx)&ANz)qIEcB;PJ(ADyMwY7^b>8 zhyA=Z1w*K>iM@4I8%icHua;;tqmH#%F7->ByN0O64;?~t!!S8S z+}x^LTA7=Y#ejInGVX>_)yms(r!$=ACsS2X9orVLM-!i{av1p!a?jVzcN*(y^%uLY z^S2RAJo64~<{mSQ3Xd!v*{O*3$~;ZJWH+>puu#=!jN)y&Ipna^Ku#vUGq`gRiZ*MG zG%*8h#$~gPI$a+$=We{qm7(0Cj#`CCDVet=?=Z-(Ib>K?VsX5WSDV%tf61MzRT?!= zMO0N)94w4WmB=Wf6P0v;iAh0f)l`iFwX&1fwjIB4srSN{f+Ebpp;5 z#E}S&Qe{?g5N*=m#Q1qI1a<>r9E{0TF>db0! ziXH9a4NKcGhV2t~D-Gu`P}jLZy~1Ynxgc@OqV%>Zn1@k!DuT}Dvtj{x5iUHR7+{Lsj zS|y!jwm)4Rl1)3>P=y88*5Q-$tWeovVb?J$30voxA>*vhQ-)pI_|jr^fUDLMj}iwG zbWBWOoU>S5=P2oUXA<M~OT@)+lz>2yr||x#or-R#YcYJJ)baPO~|<9Z4~U4_-Lp zdCE?5-dOo&@y;7uSjFOusP^*<)H=?fJSv_iaH56nF&ry$nH+4y-Qkb}&XhBj8NjkO z!8=ZKfz1V`()O5!L^^@Tw#F~{(^&xH*V3jZi7}AkRELNaibVy4ILIAZ(;2Ta#d)kE z03|g*rA`G%TDXNx+YKp_N=*u>+%q6}%uxl0Rfdl5H^%PsHq7c2kwi{2nSAZDtvK=E znA=E0h~@ODjKyZzeLgQAB6{=AlWjR^jD|8)k#UtKGWN|}=4xVQT;^vO8OHOL92mID zz&XnfGi?n+tmkRW%n6QVfz~~zFEA%YVjN9ij8mRa*QvynCsV2A%v@GroV2{9Qc5(7 zA!5kF!32yZi#3T%KwOTAh;^M!c&u+LGq%BT3d33=et+pdLvZwOYQ9nP6zd?;6s|); zegg@-_4%k=QeqlITVVYa*- z4ZFmCb@ph>#udPRo{NJ0a$ZT{hH`K826{L;AdKCycDPB$i9FuEN%`+8BC2t2pa;Xf zq?M8^tWqx%-gMzRyPLD&Di!;)-rYtaZ{G9fRk=LQ&NId+buU7m9LKNdo^~HS*J1^hSRkLh*evDSWXh_L*?OL3-Av6v$}%n24>q ztcL*)E<4h!qQ<$WVzgc=1d>ObnzU$;NwOZH3PKYOKN9c^&m~zu+UZjpfkRSeM=g#`KrqC@m7ZIJi|=2t+ov>*duT z$X!+7;oKm~?Vw9K!2p#b3mX){+6|$F1;0*hBS;i0TtWm%q)(y;C5`A_hSJgs*E;KA zj6o!99Tu2E8qxAJX>LiI=Dq5LUqb9b-^IfO?+B%^jR}_taDr-_!66CX7DJ~hY~VBn zLf#99vq7G`SIr=hbV1IoA3|G?Z?_vK8G_uvN@WJq@08ul`t9yq6An|IY1R|q%*z(g z5U8F-Zc{uGme5)G0h)0n`sOEtkuf(JLPL_fL+eRXBz#4$yigX02QDmzvPvQkV3V)U z)07pWos6KkUEc1s<~be*<39UQ5Bueo&~+sn=9I>Maz`iff=_OwX;%=z%^6^Tmo7kD zpvu%Uu$2OE*@gx?x_x)F%se39Pu%XYxWub6N`%hYfs~GPUXma}x9f<;NEAn_kDinA zks@~wBG#cmuLOLSCKZAcjH`mWpOVs)3;-fQdPio45n&MeDyft!mvQ|Hji!gy4~Fxul4a@4 znk=S5jF1}V8ed(BdBRbo?7ze~4Fkd2C2?>dVG|GM<$Y2Qm>u-#@3*_t)V+ND^SSi+ z^MZ+@v`5Qi7zatv)ZF9b)#zb$XP$HjPqGRumA!18c`VrbUmX;@w>l>~cbzcnu_4t3 z1p#CfXcCx|YLK9zqszBm(=*f z=PsE@UIm8NWc$1Cz9Y0e9(1UuCl4kHnHDKVCMUKdm%Y%wy^b|?qmLrt z*%Q>KyM$(4-GPf7Oj7O|YiBai7$XrfF4Mk{I-Z4v^TxZ7Q9CHx3Ua30cU#?axm7qq zcL}&&fmGyG0Fq}MDsmR7%H+lLc|QB@awC-}j)4w4kT0JHd%8mTCxy3rcb59@3Htl2 zn}j7)$at)ck+O?223#q=dEAXqH6ul70m;8Bc>;W{nUe%KDnv6ajzNBWCzx8P74y$5 zi4!ulnUTc9%=JSAqBA;V`-5%Ab_L|pN!NA`?(x&bcNIzK@^Rh87d6B)T$u+d(PpYN z*|_G7OT&od6kXeiJ*p7IXPN0dcvH=;i+8)DRzQls^A0__FyqSM6Q)YmwWSfl43g69 zxf~*h0_Hl%k|~r#q0$^#`?%c9bScvJL^hg+WOXz-5G=~!kxEE?+TB^?pI+*s5!jGc z8<61_md}#lTaL6xNrrBg5D`C91sN8fTi_J?Gst^N*7^CqzHo+Pbw_5?jMmyt_xSgl zKb;}OJQjW|`yDudU>+EK8G<&h-CVr)2At$w-Nf$MbF!c>ZndH>IWQ>O7|Bsl5iBv6 z8Id_cl>-?nshZEZC&A?ENPA#P<~`38UJ`bDWYe`<<#!sq5F% zM|ap83Y~=h)IDAH*5&E$2U$e&jGoU;9er^Fq@l=2hqrDyGfO?$VYjpFb@ktxoXOdT zbc40*tMBqriit54g$3{Jzok}eC6{PZp#*YlW{K1BPPp*lw9YztW?MYuDW9d?yX2p#uEDxJ0v-lO+@PhM&r>Z;@@;MRv9O&i%213~6%=8C2Hli! zppG|T(ox_Sie6!%m+wmEXrk`)W;8;06#pfr6n$LBY*WP%ip7ftrIH?8KcgYR;8Br4 zeC5fu$-2@^!mF1taVK63O&Gi)F@ZXhaSd)u5;GXM4tG6)-65&z^EciAsj*4E`-pSb z(cl>AU33j>4pllBD_AdJX$=xiw%P*np1V$;F5qxHrYIg21NZy+{+V>~ztevHnbXIQ z;j!n%No8eKn_Bvc1_VDT)F2c5_4#cX8CYGa2UAwew4$-LjitTJo%?pxdggF)n)+ww zLgHN~EP@q0c<~JyRXm$}SaO(WbXp_B!-eVDD|*Sz4wEA!M0F>dmt83egwhffP=dl| z;)5S^2cLd!?Lqu&-7eR%i}<=PqwL{5w@5=0$ack|Mp)Fk(@asMrVK>97l}z(LswB2 zL{->+M9Oci)uK%Ltd(>MsgjJ8WtmAKNKy$3c2JvW+lOo(rt&f(y+xD4{7jy z;?Ee_!`Aje-1zIM&WyG3jg^@}PNck>%pitS*}#%Rzi{uDqp}!f%SbljjJeV?T9O~$ zU6vJ4B0H#pJFyZ|rL5Qvj*l+X9o>Nl(>e9`&~<$b_hXj`zh%tR?|XJdyC9p;z!RH!5JeCg}RzPE%w;9B_M%&%o9NIEDiKreXqM6D9tVUpgi8BzY zAft>7VGy*{KU)?zy9H?)4@wawB}6LqW8S>@IDOn4nyoXZ3NF|fY@&-$Dv#`1`MLK5 zUs7RC^~v6O@Rx`eDvc$NtDS|yt`7eJkIXrO-T$$V?;WI!pW&j7MAnO+Je z(~J@V$Swj-m{|fq5gTQ9%3;k+IqSLIXu{VrW?K4cb*go$zFzZk8Ei!n8CX<`3fHH& z>vDD#d5WcuZmxply1?I5FD|Tj%=Jlm%$d(wgEFNkm5MPq?p^OhxzgFjSI0W(f@3)0 ztcGD+rntG=Q_b!g^`?|i!5UuEUAJ=9WO2?@GhI!4v_v^~8YMY_jwxQ|;dIo+ddzoo z4caT3}K>lc9*%W^%V6knb{Vm3p*q?j) zI?ZvpQA9ny`n<`+MSgRbyV?Tj4#;x!4_*_MaM7ViD0TzSgKdZ?DuR>6usVnpAdB|n zsBfyGX`;(&TV$LQ(L!$|W}b*2C<2`u`D-Vb%I)y}PmYJKduK2@F<}-yb%Z?gS4dk_ zs1tYMa?T3PkjB#vUu@i_^jX0xu_vNC+uF(D$)JeLX_m1RV&P`TOS*F%#+ijkbVDRW z_i`yc#3k1p_Z+?4@{$incj~hLU$2Sr%_Kbq%Hcz}Xh`nvXQu8(8s4cB$Zf?h1WrFG+?RQBW^QB@x9q#u6eDn9Gi|+1J zf_XSzpkB`0oD_CV$_c2dDg+afK0Dq=!1CRCZ;)?x9!$@-Exz2YocB|w{X4sx9R8a znC{niU0NLBMZELn@y|`TnH4k3I+Dj+cQe%f&jY@1hUc7eEA-9sa`w2cW_m*Fu1SqW ziA+>*%Yrx~Qp#pxxoXzjam+Ey7JBJn$^;ZA!6Byz9}lly!!sYO#LTlW*5EfV=QU%K ziTmz9*8CSSiGXSv+SLDF!AY z#?qxW%}M=TId?5?r9C>-6c+=qm*@ zN{GQjMpWK56Bz(l9uShVdqc3R;j=8PU{vG}k@LLdG>1L@DUjVr2N)_ccM-FGQ7uRb zAd`NAUHN2^Mf0Z#H44&14NSgba!^^@;(8L66Z?!Q@qjD?;h`*skQohTl&R?1kiU8; zYAfDh869l(M1PV&kGd#2*c`^Y&5nZX*Mp`d34n~k)*pQxWW+5*zncj|NL1Q9<)q`7 z!@N7ldXjz_@jFQ+gfSEXf`O!>iZlm;DvUn?03Fmkvxf>#bg-Tw>NCDjn!;2iWETRM zr~!1CU6%nWE(z_PNFKzJyJ3m3vCAwu`vyvZlYXMzO7ZwJ9*puENyKHkaEX`BCheg2=>fW{E zQP+8Qd?5+4N#z*_liWTkuo_Ae&PP+OnZ&x9PhjjgYEt(sH3?5jElQ;=0ZMUw79So) z5@R7>O;pFKJ3E*rUR zW_K|emyTXE%OSKaRj}+8QYJyTLo``Yzq0Kcq<(Jd^?rSC3HM(Iba3}13x}GfiDDs8 za;l%*P19Ux=Y4-qT<2*z`0d9H+eV1re)oyaVO+15F}ndVX)!3MpeZtN)%${gC}YWj z`>%%IM{{i?f5i6*dWV>?^C~EIu_Dqwz3#Z>{izWSenl>Uar-#8lgCs-a!%s3 z!ou9$G2&F<%D_}&A}!_`)jLiYGUG3Aq`_2iZCT6a7=yascP4bhh81ep&h0y9TMj(O zF`_0mrW}m38?kC)nS5q;oO$y3(_C$MgG!mT9_DWF+lw!!uXq;Mh8=XufvhlH*(hW} zDz&EQoS_OsZ8QZ@*8B5@kEfl}1V>vb&SvD}jbf11Lnj@GNJiDfayM2mVMz;w6JOYi z(T<73sVKVAiB@IWj2bzFF?3NWVR=a2lvDM!HC<_m<66^9a4`ae+{T=OJ4rH$6$utM z1Of$xhAweKbq#YY0!UWe3g{XGVm8c>qSelv7lz|fu)JxA8roj68JlLac9e$mo$B=? zJH!i}p-S%ObXwX}xt*`L<#Atj?mc+mfR7w{@TfUF_&JL2=(m*TN5%0xmsOVsAZ4l( z*4%VV97@(KfyNlm8Cg)&QA2{9w-8m8qN8j)&SA{Q??>m+&QCG&U1=2)=@JlB>7$d} z7JR}ZhjI{$$VlPBe6)fr#BD1}P0prkJ+mTn!-9T^B|P^qJG+(&ZKsq4sc)Q}*KSn!NX z_Q_7xT98{=YRJ@POlU=FFi3@w3osf8(sRtf=M3dE6D|%bgG4c%&CSc(sh5g8hjm}T zJazZp+4OolqE6t6tdz8iiBk)w&hKBZThGb2baiRR-P|fF1iaj!s)vw1>pn_+Uwa3R zj*{tH4seeq=a}oTpyXG6kdu@5tawl!^hmeS2X3K38mwg;sh7{piiWu#% z=akRl`M<-*`i>>ZQb(@lKfbZwx!-YK?y?+7jKa!uT4Pvf<2PtsdEAFaOOW}y6j4BN zwY+9$TztajwPmfd6uU|}!#qd3$8Bb064|;HRQo2w*4bM2hKQpaW;nA5s(LPrH=G3N zYSeiSS9_`FDa^TOt@}HUyq7|Kam$yAMWSxwy3Dk3MOPCOm`mlxX&$^sDMc!tt;4P^ z4e^B-pr=`@l+2)rV3h>55-2LI*VY;)_Lbx7EIIk>GTyH&D9j#vq2lkxFI<5%hkh*5 z4$w^uw#c#>BGbEug@Oo;klab#*$4*AcVg`U$bj?fat&z#?86e@cd3TaYonDYug1PJ zy~9oIt3k69Y+OZT%)Dv=60U0S<%p&v5SKH@x0pI}yU#AZCydV?(-9pSmWySA2Cyzn z2P2tqKu{?mW&+$>yRv1HqJ)q{aLd>nCOn~6`f}@j&%ylYmFVWwzzue|Q4+&!GK*w{xi>HzI1M0aTGLSP6UB*SP__~=s$@15T#={_MQIy!vn)&B z_FkHko%_$-N^{ZjshHOj(k#MF~Y^W`7o>f6($%rY54*BrC42AZE!m8J5f-Oc5ZeHL>qEdgilXm{J)XG)5}L ziv<224>o2U(c0&(G6QlOot8sMsa-=zP#l4$8hMpDT8ty7NJvV_ zmz*ylfllZb7CEr~up!8^m~x zTtKNv@gtK$P_9csKu}N-6qE%eDrRd#abXcK+lrQGFie0kfxWDJgA^_Q%P(GCNgM2Hz)?Bc!YNXb zLa8{*j1pg2;ECsM9Q01|1cy0y-3K5kGq5x{1qiGHgKc5QQPH}SSthV6IFn7V;z@}X zYHcckf+ z5ul#ClDRs&nD1UsXKYNbEyE}FBsy$`vO>JH>j7&d=>YwZ(h>#d-JDdSZb{53ka~m{ z93;-+=Y6~y?(_+3equXk2QK-$MO_yNUCqZx!_C18^95uItn76H+?qt>{T9PzPv{*KPSb`&ULxzXu zsCXl&Y6_rz2cYcbhq^@iw5#u`!-a~yqG5%jMXFk6Qx|i*Kt)C*MP$u3*5$s#)#it- zD*5FwK|@f1Ab?E}zjPe~*Y&rL`df=FMA;wZ-ayLv^|0y@KgEZm5{`$ zQH@$JAG=-9u+xbrDTOCucGIfaOr)65>@G1RhEQC2!jpnPBpnq1WmOPTK_JmY)CQ*~ zR!K>zTQEXtieQ>l!dk$NMC6b#qJ==AiNOxo6$c7qPLQ1>?r;l@Ce#=~lBF(6Y5}0a zMyaJaz;lJt3JPVxiQAbCtSZn@(h(susR}YhH3^cMa2(DQB;1RGbF$)1r(=?UDHy0? zXw)G{VVH}Mr4FYETA-#iiewc8P(-Z}21w+CEFnmaTB{1G8BjGy8qA?uri92$iV?{&eAd$BlTk4`&2BZNnKI(0 zf(9G3S}C_ocP=wQ%=dbZtoidVN1l^*$?D2Y&x51G$4V&|o?dLOgZ%e!ql8dJK~f#L zG3)Mt<@ps=N3pS~7?jBc!PuB+G%V!?w*7By4+8lg!0Qc&=3RDi6TJ2jljH0MeC&t6 z(*x&4eKFi>Poxx-nHqq|qLt67>4nFTBx{i2#LkCfle{_Wh#+Ul?zAq|RP~fZ$jh|Z zV;^bCmDvk+EE}I1Gm07RZ}GkN zL(XlO?YLTv%O*E*u`a5g*Z2dHvtrTw4glfV#F#-cjW0L42d8iEFbBYXlOL+o42apV zC19x&3W_3&O-i683hIff&`FutkX5(w-G_27#cogQQ4QdMyd(lowN&#jMj zf^^|lqVW^ANBMtE_MD&|9i{T6w9KNeF<_$9=DVy|w`Q==7vS7G-mBFgi3Wiy-!KYL z$U`6uA;?-}ldfg~e3A!HpI&}P1F`T))(+=nbjUrN~eiP6wM*+)8F)~XM_Jc0g0TyNn8o?mpMwD=I+Wgdh;reo$H30_q5weC2vB? z^%hnfYH^0n_6^wEjG#zD_t;Iz+~9k>?_-TAAk8qiO9vFgaLQyb1|P=e5Q_+)nQKz8 z+En#wk4BySl0&nbl*Uz0O-*+tSGKuI?cE?tCb;KqXu)3gxDkzTsk11dN~LF3qlfejz!aF3YAM$MJ*IWG%ytj zW@T2LI&z;QFg+@dO8waPcxZ!?9Ex2@lsPi#Io@|D>~cFbfv9pQqLz`RDb*7bLgHo{ zm`s>6B*b0HE-Vv{CJlVm+#W)Agh*06mhMz1&UNM_&l2ii4fNZ zk{D@cr_(qd4wL8c)F5X)@ZMQbiI7T0fxn@mWennDEQMq^zUVk0SemJQWXVjB<`Feh zNNOl`3A~}KlQx`5iHTDcgf);@pd3i9R11gMHx1|W(UP8Ba5Wh@4s$YpLvA;;sANKa zjlJcCafdLq-@ajt4l-g*v@10+JXRBV{?}YP$ana^A0HLsR!IaL(XwHhs4$$Nk@!+yOMIyC(=OXl};Jj=AGVm3)_r_?#E;+KU6gI=@+gLK!kFM z1@HtYadgJ`tHI13qa;zuOAwM8U>ZzdxPjZo!I0yMWjp5G=xo5$Gu8$H)p~%ZTx1Pq z^Xi#8g7K-wLcNF=8mrECZki;=u03JcfjEKN#@X=mkX|xzlg1tG4f(hSjFp1VCzWL1 zo^wJTnw~h4cAs3Q({-FXm}X0!^f8c|5<+^psdICjG6x5rOfGhVGK7@W5m6OjqMg8; z+E!K`kebPzXEFpT0sk9C4zLce_ab}GF|zeBIo8dh)O1%laNFy%{=b*+D^VS&Y zd`>ORh$1M(L_lOcr>78-@{(TjK0`AgXu@F4XlreE+c(AsGQgW|LE<^45H=y9_q&DW z;pXhdOAeYJD6qLFo!DcxbbVS!h4<3~*5xPOvaKi0509iCyvTLQUR){8`|7<*1BVkr zOK6(7o1F*^1R#FYC1w`e_7FTc=awucIENAvYHAPAqEN&(cgA38PxAA))<0>Ju+8V6MO40?dzBrW6TbhQat7$b|WPk6)J$#;!Q=*DG9`j zs=@}c8agKZvaL!h9vVPd%T4UM!_x|JilWY`Y&~ukn!wbaBo46OIi5UM>a5Y}*6l`_ zs^PK~nzKw*<mqgSie|7k(d#@J);eCLIqhPosEUYZ8_d}^ z$zMHA?@pJYrWX*yghPva_4}{kq1F^e!&CSv6bI63Ca<4IzyCg+hmf{2WAm% z)=SOLnJ8D$ss1!P>xqtv?OXsQzJhj|1&E4`5WxVpvBJs_LafwwP&LPkC1$i67nh`! ztks#J5n9$eB?R5IPaM+?BJGbI3FU$1Afg`qycFZV7y0u)f(XV6lY@)=f=r>CoNHxZ zr&VOfF`}4`3O@Q6jCY*Z{KNh~lk2&PI?mV>p2I3KL?67H+1p~%Kgfli+yyNQ52B=0 zQQxa8v*ZN5<*}iTEpM&{A zX8$jUeo&-u3Khv$_LNM4A`QS95DJ|W#&DG4X-~H2kM|j}a&|x4eY>2Qoh5Y<)4qkF z&&D|jaHkm|K&=3jflVVp{@}jQ6pIqHA4y!5DQQp641}VJ3*WYM)*lA*<2-fWu=z(3 z6Zynuw^}xDdBnftw;u8A2)}4(RG}IYgefQzkPk^j$O9qB5|m0;Bw7O@N*X9ug`^q< zq@Vz$0);3_P@uqp$Qq?mngyT_)= zEQpFG8c}4?#}`xY3AiYsIzOP7d^$eAfCPEN^1Yk)taT8OltRy#c}vaCJKTQ$GTzDi zHHI*avI*os+Aj@a^KSM<{K})?1 zsSiS8<$t>*h7p|7W&Z;-p502|Q zN|DCn`WWVUG1&v4OqQq$S1nI0?f{8G-eS;16-rJG!!Zj25fR_0 zaU$eLg3+fIJGkLg&p=sl^vll2Ji?#|LMT3`s;)!Nw*R^GuRk^}xyY%`EYT=D>Zz8h z2j^i&^Dv>Z_`3`E5e)ftC|+U>WCC=MXo`X$tqdlWPf1T-$LZ>c`0jF{pMwGRlqq`?beyuaD#&;qZhG3cAwC-^``mgJFGIJ#o5`H^% zMX{gI^c{LRe%&(YgIggQBsEBqsz*4u%p0_6)XR0tb(QK}@jt`C`*Yt3PkxH$k6XWK za^>y`*s>}DWvU7)D6B*l0>og0U{dSvXGFm0iX`n=j8&f*=MF;yGcY+mU}?kygcN+x zI;JFc<1W%7VtTVh*7iFqAW5nzKIwUOiaav~_dG|X3N zI8<^d?te&kl2g>E?7YgTtCqHlQAA?HD)?}J@+Yp%?WeUz?`Oo{cU)veufrvMJ!a?D z0iOVKXv9o=UD4;G`z)7_c zhG1N)q>~afI;2?_8U{>)qM>aq|C5Mdg|-TeQHcI}d`H{LVQ5tN>zZcC^FPW)=Q+){p=qLWVs_Ga`^W{P<=AbLnefP0c2zu^phEU(;tUk`T@dqi!x|-p8 zhG7b5h9~l2tp3-|Q^fIxvMf2zJ>3NLWf%)F%2J6J9LtN}Kfjy}YDRP4^pNn2rn?|? z8ahZ@jBdm(;n8_#BoOo>xmqx#`g+4yY%vT7ro;^qKd zs?wg%_ovHQevEaVcxrp6vL6V)dHN!Lo@NIptOpR`2L4n4yd{-Y1DQFUp~@L{LyrKi=>MN1aK}vQ6dduaf8vFv;W~dqs;6yCRS(5o@F8 z)DFf^i95`PX-_@O@nVr@(Um?JdQ4!jIBZIRVkjwybE^%y!a5J80pE>=fi*9skTD&g zI-c?$jUsL97y-VAO(Wts^SsQA%#}Zk(5PqUb`NR&d>3Q+TQA{nH*R;lJ0O_SHic#k zqi9tl7`~^YGIoU#iZEWXkk;aQWWanbXFWc1iNQ5IzGU^>$ce!gaALkt=I`R}dp5tc z{`2`AlgJ%mZt3LU~La z5^R?(wPNKeBef~DrM4=;d{bk-+Lw>R#ZIjCqYCHQEH=G2L&_iCGN~~NV~K++iIpx+ zam8rp=d;sX^=aJ6I;mMwq`e=m+p8atp9v0!ga^{-+rIR@NBRoUIE8Z3v_+l5n{K0@ zges>*fl{??E2_?n$(d=EL-Hr=gix8Vq8bA|r?WhIYKd0b_IdC9(jP>TWa&8vnprKZ z2HPK9@W>#D3Ln2PaQJ*+vOA8Y`fslK0sMB^YS9ujwQpl910rtY6clIm){d^Ax}6Nq zNycj+U+|@PWfcuDkz_Q1gmeC|em`oz;MMrIvPVUoltGLB3!`4<`n!gZt*zGOOFVNr z;_LKOo6qedW6$@(5R)%X< zkeynl-`ONs8}OoeGn=(9lqz(y`X=r=n0-IpxPiG(U!|I@eWo!IEakC+P9&+5gpo?j zhD`W_nTUiF09v3VoJb>wT1`=X|DQc`g9!Ry4&gqfvF+jFQ06^oMM~96IurF4RDWK# z9(tx-VStQu)U8=$G;E+FK>|!4u4kCGnm$dY}9;Z*r z?bpgUGYZ7M=WzYIned-!K=g(DUqpm1Pfk&_1qE7#WGYz_e5EkcJ9oc)>gI%Iw%9Zq zNj>mh@cW<#JngJ+heM)X_`CYWSByiBFla8@yj`QwukS5cfj@uq-FQLq1PUdvz<|)o zeTYA^6$?p=1(8DvVhQ}d_+k|R=wLdyy|B#r&bSIBP)-y0xRv?)kGSD??*(ReRl6(IQCBZ zIS1-|Wm_*SnXs)UyLm1*c;0U=$BHPlOtG1+a5v5Y_50@Ps;lpY1N*0?t;qE~x(?FM z$Y->hu|qBCu~bzOfi2@~;DzG)VKIg>P()O=6$VzOMPX1G#U)AJ!xb&LhJN3Zcr-Jf zriYk29o@854HHB~5l!-n>wmU|g|#2Yb0O=ek#k(~;y-4IthFTB5A25MX;}miIMpCy zJ{&;QtkiZf3=VTBp0n0nBU+AaM2fLQWaqP)zS?q>cAL8)l_-w%a6Ms5AvoW+Ynwl- zNP;Am46j&KNW@t?Xt5NGg`ti;u^9KYFA$%1eN}##UqatU_FwLMe-Gwgv++AnWodrY z$ZKQ6n}2RRr-F%0RJ2Q2v%^ynn z_(2j>lx2J+Lb$+DL1dEs+oWRqu)^+Q{WNb;_wwH7>7b#H;voFE^7S7nJdf;;{gO}x z48ny(jWm%`RV5`2B_L7>K}{kw(ooVwgXsoUFtk-PBS1w`gA76L&C*wqhsv4sOGddlo zYnuD6N@#yj9lncXUF4LSaZ->_=2J98*-DiK+wXC3cRG`w9SRggnXMKDW+pP+aT8E6 z#86>(Y}Ng~e+^pfVaEMSPxDdZf3N}QIERrU&)t;iRuLfbER1?|E8=y6zesZJZ{-Aj-V#WOzxS-iOWXcy_oS74`DR>fq#|;KOYmJ=0D>>XF?sG z-``F9fPAt`3A=HG^l^SapYgvIr1h}jwb=cbYt0Yw@A+p5zZ5?%da$Wk@lrXN$5?sG zS9cK?#J>BYCy3N^PaV;QW40 z%|g*@3c{kRZDpdA|1AE0<)fE<1mQJh+EFT)lo9R)Bc11}MN#W10rDK~-n+KR5EhDK z0m!=o<;a>$f++OlS#mfRNU(}1pw`n>6jKnyRa8MqS|qRIrwWhrPUl>m%2s1Bqfn+b zVv8#jq9YceS1cbEI>Rc|ln2*isKX8H?5W;VJZ26+1p!L@8o+d?SPD!vCQtdF z%HR(38b?~;Y~GsR^trw^1%XTm%89UGQb1j45*1oP($f%I zLRkXMAaCTns49s^oIUT^FD{X3C>dxU%>;B}c=7M1Yb`=C@H%V$y zEaGic*wcd1DHEeR*9|j#;fceDbC`8I*O@Y<eF{{kFHexZ@@|`Qfwb z^!#4pa?r#pi6^!N%TwBF3I-0REsAHapIUG5d|*dC!hYX6in&cmj7F{$tjIqSs%6~x zhdDz~Do;c?;g6ln79zo)=Sq`)kp>`~o~O@7X}y@Y>dGv0LflW!@?CWd8o&}3@6sRi z)mEwxVNzOMKp^F-zZ`Jbm_|qa{Nuwt0`f2=da%(=~un&T_IWAygAJx<gvmdbUYs0pP(YL-a|pCANK?We+xe~T z_0fmdJK8w>vrep@TEe9=$^6n`Xct9=67P0+``y!rNON_GI<%aPrTbU9JDbcm>%U$u z@wj7)oO4<0Hx{aLEj;1Zk{h&_C{@c) z+M5;z9M(E8Vp~`fgoR~FoYVd;a+<=08PS5YkSbV0T8vOuZ)#QSga|d7RG;iUgF(fb zTR{xPNujv3aES&cEYl(aNa>=uiCrn4cJ2knDW>jDZGC29bE(3CX91!^DHem;46|59 zMjD9Y=Q+&`5|q=1Hhydrk&L`+IzJ4bf_>40ult+P+WtcJLQLW~fY_usL&Wz;!KZnH zhMuQvQ|i!)Q@v(IS?!aE6%Ke_@`$Lg6ek&2Vkv;)Z1!iSP4!{MLZg(V&~HK6r|FRuwRM!o0N0U~RrJ#^UPN-J;F*H_eA+ zP2|AQe_ zSbZNx?^NsB^m{xToM#QRR?aB699%O%>AbwwsT$M>07xv=y%8AmC@LEde#jU625L#V zvKFvAqKXP@cgKVrCe82_4hNVB$Rv#v2`I z9a+a3f4`+OMGm3dIJ=%r>k~N6#vAYxX(#(3J0N|SXdL?Y^LZ;gWX!Vu1r++3%6Cpq z0?;nl8e#EhWIA!(h~TZiM!l7@ZkHz8Zs%`w$*tj22FlxmGXtP_LLHa|1M{5lpFY^R zeIkJ=?7W=y-=lfQ6c|g|&C+i6VT>hVDh^x8aTJ)IFvd(k`SdNA#l{sHf)CnG zBNQqjjV`u7`X#2In+n6p^|~^!i|N z<_LPi2YG&^yh^WA4*AbG2H7F$Q9urLjBI*BXld@iu;^G+2dh1XQAm$*Un6n6@R+-E zg2Cv-?`3k>RvuN;#EPck8{`yHpcllDJ$B%wF|4$O=L^vjz~u{`xJ6 zIy#)9fg2ylJD7&%nj|vA7&&UHSwG~IV1qcD1Fbqj8niish&==6b)Lx3RE9%NM|>9# zIZXKUHk$96NPP zt5+3I>eH()=p_3ebXAnX$J?C;@XO@l9IA0L4 zD;F3?@LI)KyAR@~>MbWCY!j1!vsDZjqaL>m0!RdhO?@{dXYmIr4deVx5Atx2LBi8POyN)x~ zCSY8p78-$^{S$7EDO9_~HjUWJ^fJ13#Gmm}wrOnGSBuHt)vz2}$5vfk~^M`bD} zxzKaTQlphu8tqCVyc~Cu^B(KE>(6rfMMt2{Noy~9=N;YId{UBW+kr-Ww4kW+dE#d~ zoim_SNrvd>UP%&mB|6eCB9?P9J%vo7Ol8~73!FfOn|54_=e+{$EXbp>fy1N`+M6-NYg30WJ4T` z)?*Fk=VcCMdW1xL`QFaw-4R&#Tf4b*=tL1jRaS|F$v*BcT0(evI(5ppz1~i73vJpt!PiOQ+k=zqKP36QlS)>XqK>%3b2~Ch zVif0`NO|*zyRjh-B;I}R9Ay^`E<1t;JJuy!D!|56H9xh8n$)b~98NQj5an<Jw2sE;%;b-KCSBA0dC zq6n*$RmVT)JlWzXbtf9mur=@cKh%9&{T$1uqcis2dx*d9K&W%JO_Ti)?nWPAc*?%l_OW|#YJS#4!IE<8VLzNH__N>V+d&Q?9eBw^5ZjAW4O{(e zIYV?^gz4Zu=~#(BzbIhAVuzLo(5J5RO?!<%b~UldZc2Mb zK-<jxYZ^N!QEu;eo1A;#q7oC+y2E?vCyo}7TIj7f>Yh6M@4l?p9Ofx?1_Dk!R~laXD{ zIo#<9z_?e9=P03YDEizv&s0vrPNalEOo2Wu3E$`MBgkzEsJrV(qcEdWmkP?;eZRq- zI&l>J>zpw$b00GAGVQ!2zLp#!KX&1D$mEtawW3bAnY(V`p+7Gbf*`Li4i;u*$hZfa zrW=;1Ji3#OimwpQce!HfTb=FXP}bGB&pts{9YCFK?gxx=N)PFZ?z`Se8Xc#l$@ zb=wsxCzG3QwOWYDiLN2M+|jnqb0jYAH9Ms`vNAxe-OFjQIIRYn8Z1ynZc_({>7wqS;;f4qab6T*!1qzN}T z#DONS&e}yXI;T9<3l4!OSV`KbbdnEo%ZHBXCx;y@cJq!JYgKi_j_-Thhq~q7 z=H(wZsZmLvKIzNUqWGp_n`Cc1?iF5Vx;rf$!QFI>AfvUCs%>`3@9EZndP#^Ev|rm_ zj+#Hi(JeHtxMfc-4ZI&SPNu@Z%Jr&_F8|$=OqGfk*S&N=TNrL$*TuvA6Wp(+_}>90Mfr13z>p{f6s@&`29dC9ALz$ zNot57h$4xSf~hn~w4D>lskA(a!UuFJ1~<3IuV;G&xkYXyL}0O)tSqmbvImbxLb0`; z`)9K(1I9z`vXc^j114{=222jkIi3B_kK`)bK`Tnscx9ND%PJZ;`1upC0YMf3Ye1C0 zOC{};oJdW%V&WZ_PX61s81}oi8bx3fFg|wq9c$)@j(++2`tBav!v*OqHxs58r;Z?B zz9F`ol7}qBo5M$04}2Y(!&=bQS9Z8iC3{V_3k2wf39jRAH>$r~`)WYhiKSZICcXgZ z8$wSXuHCwC^X!GfRN}u$QPoy}9fz<@ReG;xs*bLFgM}i3f-v^amKE8Q_p6aW#0uh8 z2&^(9!m?8qokN0lK84m(vFQNKA7cBj#RwRMg5c{JEUF-M*k%7d=SHm7X;UDONwS5# z7LU+E3zutGZkSvJ&baY7&(SntsBhk#VV>;u+jy%_H$9Oojg-QmPK_O{6KIROcg!0n zcn9ubxinvAj~+iRojG8qN9iUxl74@L%!k1`zZ|XD_$$C&h+1U!);27YWD(!z5a24Q zv`T7p9^&`U1vHdD-?w1a!wLBL^flr1=qG#o%?M%G`Xd&WpadQdpf!Mq2d}4$U_LH$ zh2A^g9YfQ={LbUD3{9uXN?ILo?R4hQAAV_QI1;?9_1ZH$u-ga`qV9f`GUYHzr*O4KBJSRq4i6j@sp2&`#l5R7GM5Hd(|&xa5ISr5vR_ zD4!Pd^t~W_hUgv<{%@|3{sIO=9mviBh9EzUJ&w=^x~rs$Hiks`3Jdx&$G|fbXW}8g z-f<3Kp(qkI{W_Zc412@Cf||!sbVR8>(O~(W6YbFaSumxxsZX^DcrqT z>_xQO3NyW3t{mWyXX}b#^^4p)p~)5o98!c$2i!hzJkQ_h*dG&3tm^yEs4up8`tyh9 zp9#WyeAn`Wrz_Sl0pxxpg$;UUUUDOtbXn9u7dY}9XKY%P3NWf9m5UT;-TupY1yguR z&15FYAv$I#D2Rg{>pn&xd%fnA_qa}-I|lhRKBtrzREJK!ZK_+gT)CLmcvdNi`@%dq z%nZwKB|~U=h9)LS)AwvD+0RMxz}TF>%g@nIw4z?#%d8V2o7iaL&$JV`aBw|Mr#o85 zZXaN-Q51-i4KoJJ5y1VKIe?5&9Q<~b2P);k%ZWD+c8fyFi5G6ft~uu&!^?7prNOyLpl1vW@O8Js3zq^pNmGD<1CU3@WlmNd6|;L>gUK#b&x^Vc z5y}ow@(?0|han{C&!`?xATE=K&XM#k6o<}m&RHwo_dcPBP>49a*;kk|*g8G#bbiGX-AS#2y;QTu}{ z4@GISCNkz^<6-`HLSBgTRxKlcgdm94`iKHcN`>u12*fCoq|VYFJU6c}?*fcW&#rg0 zSc^N|?ae$fonuNOh8)|>?o48avoerb4fdA?j8sJmo;c)DSv%opwsD6unZWZiyH2tz zd}=SQW;{AtZUv?_VPl4K&suY~8gyh3`MDv4g~o z#e~VLPiZqT%twyFGY%YVq7~V0=4WV3Bs8ZKsl4uQ1PUJ6a-Kj?T#x-fTwO=+{$u)p z^(<*zmBgNv^q_f@+5W?q^}JDf>v1Xsf3}CYDS63$is@)!5hPEG{%@;c!;GF<10?OG z+o*O72z{O`5sm3GLma-?oZnfJ=wei_eSFIV)^z{me7hvmw8yB)`5pQ5Dq1(|1O^Os z>FFm=M~*OtE8g@EuD>s$4?uO)?IV17ak~WG>~#RJ)-s1}7!V|3tkMAt+sWSsaL$^(%xEc&~a+&7Nn@W$9Y~ZHlsNjD`X4y;fd<7mflD@XFB?2^>TR1i27= zKAk%lF@ymWdj^@V%au_GWIg){;jakaYK9)X=L62o5$eLQR7QEZo-$S#%7V!ej3N~e zoTNnORGB5FvY7Ilce-N0=z+_^5!#r-RT!tIOf;Uf(eh9P^T~47AQE%0Q%B6k6=;hMuH{b8g`!# z*8J2<-=~_i61sFKigKN4hd~owKbn83dg}EoLl&=#g$vSCe#h0j&&Q^f7&zG5dgXf) z?{c|_D%(#djGl>km+jJWJ1~Nzxkci($oFkBcDPO~_~^1b1-@TQ8+5wjxU^-*o*PkbDQ0IL{iy$u6It}*7c7HHYw4`EeVs-)2!JeD_*iK5M*tB7M+ zWrk=X4QuHPBV0!Y5t2&ixGKdwBNue68?+6ni#YK*>$+9nWA|v$=KDC#kw~-59|~cy zebeEIEdDY!FiShPZr&GUR}Q{rR131sqhQcP(ltmgOL9L`Jo>P&n`*P~F1;9f9=u0z zW`MRE3FB=lG`1sI_hukt;QILU#u|Hk%4eOtJ)U@x^07uv34(Fb1(9%Zc}T{2x@RD0 zXGpqYHtB1;5fz02u!vM6`1zHlJMr-E2{bSuk|Dk)u;mLQzVJouQ|2Q?UjuY@fWwA8 z5dO~3Q`ODiu0gJuA*D>3AQY((NQ)q_MFd4yh^M_S6)3u3Q}GWN7HYHT?DYm7w}aBC zNh8@E43rXDeHRy;)jQO#DwA%@m8iPTQm_bC;kgY;?UO8-q+=Ou*~7CftU#djtgDVo zy&_wgTj2!RxNeGg`xab4YN-%)=Bd>HJ%EiP&&R=73X-5&|L;049wIv!ig* ztP(;y@*LHuMM5F3Hh_Iw{gYvW!@F^5>CXL^#h{|WZLxZ|pKhP79abvDV$QV_OlCv6 zWKRo!9+7$VmM2QV*7IDkwXAqRBnwDJcZ#2Oiq5A@HM7e%3Z9wmfz{`Fa>AWx^Vc@* z;C1rR(hAVfYS({LT3TY>oc-e8J)fM1F;3Kwx1Qr3)(Pn5ydem$GaeB5V+xy2ch@LW zps#3{BV|0LBQ0cJsq}3xREH%XgHD~L#(47Q7M#EG#j0&+UUs>==uXEEIdCnDcD1A> zlNEa`femzn8jbo(78Z0+G;`~2NP?>AAbQh4n<}9hiIC0{OfoleIe9PClE)I|;Xq7O2`(HBcYqrMDw20}l zBHft@glP54h^kC^#$0$^P{ODX4rL_pu{tzs#E41sm!z0e=OKF2xW2p9mV(Tp9g+Ni+_qhbL|l zWnXEM9~L11n5Xw&FmS?c*~qqv0T;e{oo zn2aS5Hc1La(G0`&i+WuMhLxQR7D!mipf*KFLNs62>}g;cd+#3wHrPPIiR`Mcs2j|# z`yI4s?O`nFF#AAI`C2JW#{*s59cN4g4t2dRySuviwC`pS3kW8Knqx2J&ojQIXx9O< z^w}nv9vWmem^>&FLxEMP;TnEpAS}8NzVCazVAF5FhP3s($(Q*$ZqWvLuOfFH>4$wJ z_n@N9_7n33oVzAtM<=g5tz2yeA~A%L2?%G>5}<-*8BdC#&4`6eS#5+z)uJ?!!eMPH zBo$bb8IK@~<)>{^RkmN-&GSkR8cnp`{<>zld2WcaJu5Jh2`4k{fewi9v(fz|86F=_ zl%b>eo_O-55r0S_=nypXK3xyC`ITo!+<6K2BP3x+#DWG0*S5Vr6!e)?_172Li&%W1 z;B?UkJf>~DJBfHvBn_=jbxy)glka?8&$Xtss`>;pc{Zp?qDk=kQPTSB#&I#c=65Pg zOXK6o&qFObdAjeMf}I+*beQ4_w)?xTW@scSt(Fb_C+Z*rRBNNg59;@0#u3h4rLR?Xlqw4hy`ctwFS-t7D87dY+*yeJffM3N_+F$nU@5 z3=;LO?|4ljIwM9TsUYVrY}GP|KR&fV5oA!Z2R&~a2jWBRJ07A^W*h!oKEmDaN@KZz zV&1L0NP=daR*`y@$HK*PIjD@4XHydhuj(FC&c{IDkO*+PT;@UIYQk-jdk~07B`0QT z2!LTiY-=-|caT z^ng$zP;?e-^vK=uZk$;t5*?GO_LJWos%twY5N|uqW zBCefT5NR)~&fG+GH#&|`{uRAvrC?;Ms)i>PT(To6%3?;df%~&7zg%BR&za|cPUc9n z&wGZ#k;lunICDNz)O$Fi=%)}1CRDQul*ee9gOi_~ZSFcy;^Vx+ud8#`d(d3;p*Qz; zm*)1p_?%>~GO@(>nN>?{#)+Gh6WsbDhg0UJ#|ZRy%&VR}C2^M`mSs{(1nN}CdS^1< zqnfqyC0M^Q{XX+cE6O=8Nb57>Z(FtueFDc!{--b#rBFv2UF_n_nxyD=-%RW*IS#U zZFLLm#B7aHcb=D&gs!?@g)l-9lO@h1rgmMB$3xE%iIb{9gj7#nFXw+fFw;d3Z=y7D z;>hskIubCRdqqmi-fY2=46a@pwGNBsuMkAWo*ML$xtbd;He3A5Z<>x&|a^y4xMrq6y9xhj1@pHN7zhTdLuKG;(t+4eTX_q%! zSME{d6beZx*Bb;-m_>h7j2jb`%Rc;WZsY7(Y(HuR5zZKXFiXv zpEatN^mXvE`RN%DM=m{=d~bBp+-{FkBYITR1Z^{A&4iseT9(s_O~ZX=1c`)KiFPX#k}nDN=%j z3Jzd05|t=gp(#bG9=w4Vk6A76*7vKu2w5>A$` z8!Pg3YDHyID@S)t<*Hv<=A2&|Y+Gv$4Ta35b9l7TxA6^aBJgs|gJn-YKd$*4>bH@cyn`;qz`Z4HT&7J8iLAxx} zae~t%W^79U1a-OwmC=ReAfgn*dK?zG$rw*dhvvCbx zHF(x>I<$b)jN;L)5vb5*TGQU}(YdS+jHYyI?Lv)|%Cl`iVsBejqoOc}olQO%u$&~7 zASf&WM8NHpG3a)A+MgEN^!&qdrhQpcsmIKu)LFgqJG>#BGUEleNYZUI(J+%k2_p@g zL3{jJm|I88d6`zyp^t86rZpCRyT3j!tFh$Xeb+^wH(3g~u&Dnbep zDv}t&qWMYd2%3_RDw2RQOpq?tLU@N}n9heypP}-Tg!)jWw&gJw5U3NB5PwNH>cZ*9 zsGJp|Ar(dxQl!cu|K!87Ym5kEPGhp1W|M1FdEZj(2FxOWr^mkIC#2@j=5B;WWG?(uKVx1z;22@ z5Z;?bgN9MLr!{W1j$DA8b^ZuZK3OYRb;)?xr+5;B!@M4X9B5?kJAOi8ewR99az&-UHSO7e_88q}5a_ zkc|j9OF#ilQIfysDC$)xr9ERMpr*dd9sb>XHQZep=tKljeAwg{Jlv0+{9!YcWbkC; zEM_3#(M3Yy$3Ba=TWGO3rVc2oi!>BLlN;lHb0brfJFwq%R7bgYw7D{+`UoJes{IX==-)h49L%)oM55T!K=CA>sz4qtYb2A>?A&i(6nJ~}W zSmSD64!rGGmZ`tk^ws7up1d!Bh$@?8%b97*Sl%;oio`p2IB{i2EYu2;;hVJ)ASe{n zd_BVtUh{k1UM@});w1>kL0k;DMH(RsYAB*(6g0{r*;YV;8l^4;5k@s62J;9xcJ1z= zByI~q=sd4iaKYWTP43jkaV?jv*%_w`*0=Ax>)w^Tx~epZAyO*LMvdtY-P^;87D56@ z^4KsZUsqhwBZySyhVy4~n`ze@XttxbtzGjw$=stktTPr{9N z(=wHA7`7X|X@aKWcAJg6UfkZenYM=PHb%I z#8~qEr{m6C{2}>fA}Hc@55nS2^3*mb-36Q>QIk5S2pCNkW_0~^Piu>VJ@>Wnou;ZP zUj69~G$WK~p{m9C6!K9YEm>r(g3-N#0feQZ!*iPe>gJ?%xE=EX4X2EoDCjdyt9oL3YX znNrz#obrPAPB*aH$5v-8E4X3`0)l})a%4StdFXeCM&_jsX zPx3hmq$a5|?y_u{6=CSq7?+B0@*N(5H}P`ChRArZSm#0xS>9uL1x&o^bC|ChsU}H@ z7N9^wI?`b>hO0HKss3sHxn+bVf!RKlUy*riT#G=Euf{iP4i|afPg_p<*6QXcC0M%D z0E|$p7tWNodN?2X%!?iBLBfWjLR=;PT;Lgx-71*5uq-~Ir#n5+aBr&Bk#&biw z@P~3HNMih6$YZSFBr?;sW$5>=E8xu4tYaSX>UGQ0b$43c9+SlWF>?5h#ow20L&3pk zTO!Ko?-3d{)JT%46m_%GXP0oYb8~iMF*ut84ouEv!K@1bHlq~{m`Hkc-%vY5AgvuL zgQ5g+HuIwscFvu!!;93;aJ(UzTFWA1Nf3UBM{8SEgF^5PV8ZocX0LG#1=G;nOznnb zSoPF-z)93=s&ao=^LH5Y&4~w#$TaA&%Y35=F0{s6Y`rp~7IF;+V|&Cfh#I?`lD3c~ zBU>e>V7@%zHSbFqKT%4`ugzvyXsJjA1BH29X;ai~V1PK$SKU8vOtaOst(7ZjRh_W! zj%&5MW@1xNCm9R0l2jG$3q75BL_xl4wiJA^ZKEZyNHR%%TZ7FZUTvE4tcwM5f-@5p z6h8P9zIE43L~!Zpbqp9#Xm1WXooe-0T-BNNyTY`hgAh5?in`>qVH_Te=}uQJ4V!&@ zTg@epuY`;A`i9N6XRW$~6F_)EGl(^#oC!en(*Zgf(u<%uX_5&6DKRGsMx6y^m5iJW z)F@&kge0a=O`{^u5I-lX4l_eJIdwL3P@t80tuR$gZNxfJNh&hRq?5sF;yJr#SE9or zFwp6BWnmgfpiOv-B94jMeGDXUxJ!a4<^7RM&=!*|Hu=g6K%eN3u3yGUi_TN6gOM1%%NO z$iBB7uR#Mu=xA@+g8ICcS+ZKz@;kZ(s@<0tz~hK;;7D{I2XX=iiUWCjaQ!ag#oAP+`|Mt@)?yVUV-sx}*I%qL3_(U5+=lab zYQ412z3-gktIk=E3t4k9W;j;PBei_En9R_0?8!^j?tbP>Ll z3xl#A1c@Y?-H8G`Th_SLKJ=%vbr4@#oIblK5{8mcG>JxQq)jr)5z|mGvhhUXm3Gb5=vTbCM>(tT()2gqtm$}x(vm% z6$}X^yiYvmnbkj9v?5VZa|JR!kO&4a6(XnN4 zg+$e~{(29|omK%X=i0yt}MVcHNdeOb;>Y33L7&Yob#O(w~#1LEt_gd`77GhlMObjG3std%ZvNfU3b>RBU4#m>j1xrS9$YVB zbE&EO15w?^{W|#kB&L6Nu(0l8iQ4$@<~r*WQz-oz3h+~N=aG}ANh7PRri%YKva&C+g z6y>GE!T^Wd<01}|eXfs27kvjdt*wGzUp0oaL_UVEieA7MQ^{KmabW~#fxEeAeXI-N!u;wK>hIXGyZJtED2= z1SswSA$FO1&0?O{Ri?reXH?Pvxz?9cj9ruy5lx4JG@~F6GMq0EZm=9{7R=z96S;$r zmzaPvdy31jEK3<@FVC5~RAk@MnLlP7OcZNDcOG2PP(;M6ebd&QIEtdB28y8N zU9s{DU?zpMICN-hzje&k&s&@u@lRLZPC*YhI7P5&V8*u$JTQ-4jV!y}$R&Mzas{3y z%>(TX-LzE%#E?%IWD6lVrR|6;f(RfKLo9;M*!QKfGF`!E4RYS{{TyS3jO%v?EfUU} z6i(DEDlEaf7Lb&6k4Evoa4RA_iHN2!bTna;wYq!@L;E{| zQu)(y6HDB(b^2lU`k~Bb8lrYM5jyEGTENTKQN!plV2#9!HM~{66{zY&NE;z`ajl$n z%{bQvNe?bA*63y|)!OZZjUqj1kZeP}+`9{=d@U=)o#T2G!lxxMH1{r~hlo*bfy{(s zG2{uRfD?+$7mytg5y)J&5$J*+Ho!S3i0`3X)JIgnbe=?S6j*SpGk7SKlL(w>xuJ@=7B2{yiqvJCg#Lt8hjb1mj+iQp|3~ZA) zuu4Qj4sB{)2OgUcN}k>J@^JgDlBDLHT_-7!$b;WL{2>hwJhhqf+6I@`T57*xt>%^~kY zOlBI{P4XgAVMuLC!lK-=GMpsQsmxmkw#>S*7O4)?4&-H7!E7FpW#kr#eYMVOrZ-s3 z?BbeHtMr1?zj>{QH@faZ@QYc;mI$;113q2kV#Xa?QX~-;SEe4ddQa7>TedLzR@6l! z?^PhyZHWsV746)LyDZcqwTL!ZNn1%Z1i?iXw+QmCnul2(nv}VF+KX_(m>~sed!MfH}ThmGfRu8iO~PG_W1qaT*6*>iD)=VyET^bRm;*; zI?W}PYGq^GT!x~NL`gTLIv1A}X{Fj^Z!df14~qrCtFxthSupm(vQa0bkCuhrnKkEY zplT+@7H>-KV{WHN*=f=}VotOiNGMXvN^)go72>KE3)4$h)w!`phk-|pq2fsmosrQD z_))@6ACPhDjp#%YZ-=8-)`Avc)`5aez2muVQ>kf4o;-MN14v~>Bti=c>?|s9ylt-5 zR=7tPk3&*nR%=ZH(Idl$aq4J}GzP`lV@F1;5>X3}oVIbNq_|KVKMmMRR?di#-HErb zWfiC=abQyeY-9~{)*L}aj3@!2jWPf{E#j{S>*Y_X2kKu;|J6snL3$M@%YkhJ4GN zaLOgO8|$-Z;L`MmyoGqO5}aXKF*9mGLOSP=@Zw)R_fmZF9hr^urb87+P=y#Qf{;-` z6%;BPG{YD^4&?NohE#<95mp2}^Pss7v#2Sl0}xLy&Yi-(Bn$KBvtgnEGe25kyjPyh zlj&Ebg$o1c>UX`no$Zes@yOwk<=}jwp!AOFo@Zm<%_*Hz1rxIxShc9C<3+@y6cH3@ zpjE_#$tY1dR7lp_4s%iuQ1UFOPW$WCqIB1;$7B&#>RCBCM{*P2mh-#X!_*>sxMmeR zPV(H7nwb`u>q4E~*;HSZ^UgWZUi;i_r4gGzY!@5LtEJ}(h^K&lG$|q}6BO=6Axc+0 zNSNw$@$cp`dB=gtkO+OjZqi}s_$95>-8EXv=4wIH!D$36rlu*AGc?jgN+J|S3hVMS z85E>es|+4?WDkLMccs>~HQ~!r<=Q)hF>8o!=vS=Q4SGqXrhwX=!MV{)A=c>}DOG|l z2u#Q2r>l68q=V2!swZaP)w1Fv&rU6@3kc*%jn%$QLtX`t1Q0EfNy=h`7^y?eA*(Db zTMU)fA;|B$$9QuRUFnP{b~LHxk9@c`vmUJl%ekB4-RmS8gJ}t;R{42&!AKP>s+|tb zDeeaVo4}EXLNEdh40?uOPPWD(%?dQBKy6iXG73ES_1iEMA=oon_pjP15K9 z5L7zznx{imgp!9cL-``d@jB6EHCW*6Yd%Hen;5*5NCJKABHG>;`!-=8^ zs=-aZc~0=h9*t>f8(UT!X9_kbBA~L`x$8Nx%*mlkWxpALph(zqXwDWJ`?lJ5mRkN6oG@m zRKx@N%Bnzhdd9cVNj@48+^XOw0C?JNI!yMyDy*qlNR?WMH7Zu2rhGh}=p%05PcZx) z&X5jp;&t0y5GU36T^blRMOMA48#PeKgo=@&>Fl$mC-@<9z>;{G(L1e<9h$R&c2i?=0Dm0~&OLS8s86S9>i%-s0iba*{b`AI=UNl)JlDM|+*d%}UJQPepK5i|f& z6w-l1Kv2?wRD~rqjJQga(gBhtK}{_x6qGF}P*TznG=(lexhX+PQczHVLS|s0LKGzm zWCM{vnF2)!MP0IlmPUXS)dGMMjU?=TeELKl`UZ8Gy$t1Dv%mPDM6s1$T9+jN&fq}>bO#V|3CM;T^AB2?3gv1AnaIZ^6$cQFgg zobV&Nb>_>ILB7PvMLne~-rQ^CmcuvT9_g6<-xKpOK z)bIn}y8&Pe1&R<*iU6h-a)gxxm?Ucg&IW*$kr<$`0Y&pwQ>alg1t_mca-^-uJ9vjkd=O?}DUh^<2Be$>?53QFfoEb&F4&a@9Fm1HS0JiNDL?58k^#95 z%`8ZF>yHua7D1pW3KBB>=lXBsvmBhT<>h*0bcvF2*Bn;jZVqbHp?` z?%?O5s(W1V*DohWa$L#6Yq%#tFI&5(h3?`z-Q?)66!+IL-Zx$Y?LIZ3WN>hDaJ~iN|FM?3j^Gl2;{4f6o60(NTm%06_8{mNshuXP5{h(ADl1L z3A3nq=P*%RIsThUss3fBlTJa(f{64(l$A)Lq6pT*84&}l4E~wxbKJwXmqZUZ1H96y zK>cR2dqQO8e>mrNqiGicfQSS$mhJZrLuRpxh^jDDOKj!xfpLN7dJ&(K4xm9FKa`Wy z_4kpHtg0o2rnka_Bn;}8VCzyyHh$CU*>He~1WZ(#4E>P@R>0oM;iVfWgxHKGfn673 z!aXjuL|~YF$a~z4-VXT&j)T?u^msIMG)sw5Xf~kV$&+3Lc+sk7#$hIJ7M=YAIC|H4M)(<*#2}i@BaTZnH6WsX@^PNili z9hg=gPSSG;%q-kT*==itE!ZEi*gGKi_44iJ^V%b^1zq?r68C(dyWmK{fUWQnJ)&uu zYD=#kTBKb8?yG(p;T(}^>zI@w(hGQ+g>nGN8jx5WO;%!IwB@vTmB|^Yzu-BmMIJvr zX$+J0euOcHSYs$B=O`v?fcV)lD_Bl%4&HDVj<}y*TyZ==#I>ZA6TYxJwx^w{9e&Kl zd&|)miky0eCW)we=dWJQR7b>=H;R{CalY%?baD@;S!kpRQTfY|Eh|G!BkeRMNKs8v zRS86hu24jBstGYTl_zGopa9e>K!poKk_8bfNEs+(rBwk+Qsk5MWPy;WKu`cs zg(y-1iHX|^6SkZc7?lMzN?>MyprWauq%s{#kd!ED3=#z3kkFb#N~md2z^FMb4oaCQ zWC~CXn8YEdbs}m?1SVG@$SI_zf(R*M8fK&@%Lr(vCnl&+%51q1)d;GY911;75(T1# zpsHybSmY8xk~tGlIxs2`NGvfSQU|7_9ay$O?)qU(1QW+NJWK5(W@JR1k*QBe11d^G zL_@&ij7KFw44Vw#=y9$88uL?#bE^>*opd>pL=TsE=}p4%BSkGELNo;$LHa_tuBs62 zm_JxGDX3a$9i(EgsvHu98wE{DK*mn6%D=Qe9ni0aDXrKr>?GyM6S2kPj11J7m~PaS zsmPirHYd{YAZ?#KaScE*2ay>IOOcXOLE=LQ{d^x@j$2MA>!rvNnACPHB0}b3&#fkn zZg#90C{k}CFh{+Uv(^_AU1)P|(B+Vt$YwnFeP)dUL>V_>7DOf$r!TZx8I0hF|zP>~Up79LN{$J3_(osjx{d_7*6_v0}xToqWQ3lajh!E`dq z_{ThiJ?`A|q~_^P>!?#*?(Fs8MO8Dn91x`vb!VoUnN8i|vdg_&mSh>3*$dL;CM7^Y zk{p~tG+ucH$0L)U9p_%&JCcMoBAbzQEJ*GU-0BTvI?YB7#|L5;V?=g})yP*+C1iZV zag2Iq5FNlHC-11rd-Cb4NJ^e7LP^W%;6)N)O=FEDtisX|r22@1m- zNqZQBkQ69ah$`D9MS;I3+pmS~ZEtM1-99ax>YqNi&Io7W4|9^nJ`VJmL(^4H7sYaH}lULJ=rp0gPSFUhg3g&@e*65&@&kxxr%3VBa+8@F3>VY3qCQ zp55}zV7uYQE&)ujRCbxSA)b2nMLtr9sqZP0hVR+m~BJ z<&;&*&-y0_z5dxrCdoE%hohc<+OYR*1ZoNshZ&@W6^EJrnrxF23ban;9HfFZhx}Ly zZUb4088nXJ>+tWk!F~T5#mK`JM|jQ(BE(yJ$b0c>CrKx@5a<)O_w+9(PXSnDr|KoRjX01no<0_QNmya&!?VQQ~=SRcOQRclf>7Wi?Ctp#Rxf9$LXgp-PdBD^c}m zz_4gt+q~1VOhZsT>Kta`0dy+;<(VWGKM4aALiY6H6FYC+L7au|pq>Nc&6hHD*9z%mKnN+(7QYqe2w5N)SXslu}Ys5fm*d(kV#` zA>LP^htvP_5m87VU_d;SrG=b<+)nv)K+eUJ0zUMP=9$u`#5>Wj9IqxR-; zyyV2zK-(zQdi}z<=zY7*EOh1V^UMRnaoFG2$!AX8j_w@(SaQ;D^rS@{w{HLJMSLQ*05$!GzsKYGqc~o$ zJ^XNHy8<9~Z&*Kyj?6+nBzwu3i{1i)grfpe=#A32@hxF z%$%a0f@Oif*SGt04Wg>6Fs9c4`!L%KxwLF`n{5T6nsDb3p3(3@?j7|dKK%DY^jLHT ziQ%YGto1j^_1RD7o<0+#QhiQre1^H=K6?-Sr`eP!SIa26K#;X6NX)RJGH>SS+8#1t zmJ1kiK||0-d!9GFql8umcz<>KbL;3#R96Ue^TqU<2T_m|E<)rwfz&CeDuv|iRgh3r_b1?IfXTl9;_H_(Dx308f@BC!@=x}rIe$^4 z%DeJ{Y=)dbgZgRGb0RE6s1!(}es}q7K;+}%d>j8A%C;y_MhjA*Z$u5x%Y3Fl`WaD^ zE?mNS6-5PoY!12icEv7pUP=j zn6?crvb*}z5P3@PE<_O9F^a@0p-iJ`h-1Vhf}j}cLyW_F-?`_-xvu9S`ESIWZXAT* zI+`cb*U@bu&(wYdKT3$S$kgI(U){;w%{5a6AeGGahbfU%MRSD)=qHewOtiq6OoC(; za=M`f!wRgTPl-IEQ0CnlOd-{xX_ayf7U;e_UAmO=Kq*Hj1L%bG)|5rUhE)+p@Tql< z>nL9{cMnce&Gompc_t)4X5*f@-|{keN%R*$rN=#&W0GWuKOKZaju|xji!N}9%+R_* zR}+PWAwa?TaqnZ3{r(|PPXb=ni0C7rfy%Wku17H2E0w7)t=(*-m z?J!W8(4T~pe?OnHeA-jq2jdOuVeF%k;PQJO@0IjVFC(e`WcL<6XOaBBPgT9#^B7N! zVVG-Aujj$PkqyCzvu;d+hT9R>O^qaSQdF7HS;f2D|4MAEs8g-P_m*i}v8l&U%9IUc zF5S?l6FYi5aCr6O%qU7K3b_@ONe`J*CrIRaz z4ty$zuP!@e;%ZGqIcmGhfy!9FCF@+!s(eQeCW<_sW?y#`)w#nAjor^Bw;Xr8c2U_# zRCGd_bI~=AE7J}|93pp6@-IDG^U%Ip$f*r7{xRQhr!#S4$;LV6x+a1?MezCWX5GUs zv1HC4jPQiaUdmQ+R8LwG`$?O8=4-5d=x7RwThL zjKZ2?O$|J0G=>_m{L{nz)3;s_=-nl`!w)p7VkwCYp`*X_e-*$$jbhYQWKcn?ARrT= z*$@;L5nB_sfD@ABrGp`Gl*n+BCXpfoA*GZsE3k+(4P;tSSC}|*?sOcGpR{wrj*!!d z$F0X7B?cnm*5*i4&$?$e3XE8?F`Q+<%$jW?Ic1axgDrl1HgW=J&cN(F@WECft4dX2 zRS#C-YhfhhUBiXXF_i`85t}LamkD@otcv59l~9HHl)sg6xF~388X1U%@6v9i-&q>7 z8pu`%#Zg5z?~~^}6!T%wJE&vgRI59X`0<_caUOx~&cmG#5aA91NMjL^WE5Be&S^MY zIq|aT>q#Yr9sBnuSLvojrkaX^ zV1k06f+&e7GRaxPFtSZmE>kEXijc^TMQ|noD93+E_hNlM*-iY=oeq*k5!ymg4+tHVmx>sugB2%RRTgF6Dv(Ah!}Yb8-9m${6!M?OShJt< z%ug*%X$i*jjmebm)XA0^nMs%?C*P<%GCg6K z2PT}Bfy-(Kfq8PMmNGg+wd*PSIG)fHClx1-Mz#qtT#sJ>gbmAg#13IXmr@%SkTu8| zBtb;Pn@}A=LKGzfKr}QB6eSdbPy|7UX($Xmq{I&3l!+EENJE)2J5(90(1rWJaGM@Q z*gWl&dQ(&d3+T$GNJJ$oMIca=tU)K1qQg#BP!pE_$5uI~B7uxh6=C8`*R8D{CD<78 z0c!wQ6a+|RO>uURr7h-EubgT$Qxr5z9VFEfP*Bp)Qk0?I1jt%Liy|Q?dP?L44PcQ^ zAaj9CF59z_!67O2EYM>{a7h(BeE62V^&F8<78L943M94nfu_u6A^^BJm(n z6bV95(4_+8p^$}D6sXeB4Il*w9?_K`(Wp#?q{ssyDv$~Wkfq2nQ78&RA*6BxAg3f+ z*$Lb`jYUBf5k!hoG>sGuG^m9mNlH=yR75i^0i)7TC|VMVriGyjiK}6>h>l??C<9Vt z4HPLt6rAQB4Ek?=lI~IRg0O~+mnETcN+w5ruy-v50ZLJ*kf{YC!)Gmlh&gJYc1p?L ziv;fm;V3AeN=jBCC5mic3P|&m?6G=}=9F#Q+k_MzWn*RF0+<7gMQqoA|{lBSv z)R9b)5tmdgO0`NVwADpX89{gO>3B9j%lx;KX+v5fxZ@@&EXYsq5nxGMRiZG6P!R|- z+D3THae}k1-xmo%GV=tGU<9nERuGe3WwdF+1|$LwL+w=m)%nbUqA)=u!kXttt5-I` z>p?f%=-W5`sA=C&Z``<&q@uuQU3HK>VUYeNrdzZzx!ok0Y4@%k6 z;Mu8T#(?(xaTTGRA5X(&cZde#eT^h3SwKDR$;s+3f(4`7+(I3i?7BU4uo4L%#R}~r zdo~Ww-%|}F5;SjV!I{T>To4E5s0TZ7o|mBl>MIj_@K?JHZs82_SGgYHUM-2zck71}g2fs&_6TUi|dloAo1I zk#?e8ZQSgZgQRIvBW-7T$=SD=p>X#_P&PK#Ml+A=xzW929c~M8{G>BqV^eUeJB|=n^WN_GRy^h3!xmqVSo#D&ZYjLwobO6P!SE5JUk83V|vM>}YPfFb#7tRloklg4u$th4mwUJ%3D8gkqumVtxH z2+iYo_HPz&e=jzgBSgu8TXD$@a6y#EHVzDY*0L;sn>U3+Ap$S8W+0>sLrsW(O%2T0 zgJ!pD7K0@IN+4SGi{6&W*GI{8PcbpF0zOI}bqI+~=`IbGp7!M5R|n`%h8%EK+Rjj>`&(#F9^@J%>Yq0{ z&b9`umz_unm;!q3U&@__B)@5uIstK|(h3{H3lLl?R?&NB!*57x4vyOBKW|zlUUDp} zXn20~x88&^MY#;6zd1YRv>1$4onNG<+QCXYbyesi4FYw-wWd13sop2j>^0cuS4}f@ zqr*(n1Oh=r>4+{^AID-%CMkjlBCRa>{FB-nVu2{y@|ZoZtU5T3s@vPkOkOU_t&EKy zcjnHwtzgLT1;bZTg#4H9q>$_R0a z5E|Pn$JVakjOhkqA)J6$aUkBE)#=!oj(4rnVt2Q_x2)D!bBorn`r7#4k(e3pGGcWh zG4zBzvT>TjGp7i>r`!*tF>RV1=kbf+{q+6&w$kF^_Rx(BeKCfPz3cXQ<{IHaG&^(N zCq{C(c9S!+ou`5Fnk)KX6|(Xm^o>wpKt; zAq^WMxtBsnW^sK%)$g`dDN*c#l&i0qlFPvHCOxX=LBoLjHQ!pd$;Pd5tiWPUDf$AQ zq1ZAI<*nn6F(gAK%L)<#Iw=aq@2%L_fX5bc$S+2eAt&5Lty-Ys_$4TjKTT=#|{FAjTpX*+ytTsBk?}D1;^xK9UCIu&Xx|f z;Ve3If+{?8Hu!YQ_QIZK2w|jR9ESutq=h3fZbN-6#T6YZ)sZZlh8BD?7b3D@GHR^Ri#PTuIsy-`ONF}pnuqGa_(D=Jf51x6U$l$U zY=m?`Lq$%%rU-|c*UQ}^e>u|_J9iauK+Q83XG zMI{o%LuO+W0VOp|MKsY7LsC?b)fQZcf`TBXL=mV*0-`FU$SbmwDrFpqs*@N(vdi>d z-Tn@}jsP?8ZkZw}qH2jKW+Gv#sR){(>aea+3{-fZm+?vAKZwITIB{XhqB|m$Uk%2e usc2;m;W1zHO3Ap^y$nU|k#KmFM|v5$8GJDG97iIYH4)?Qx# diff --git a/src/compress/flate/deflate_test.go b/src/compress/flate/deflate_test.go index fbea761721a3e..831be2198cadb 100644 --- a/src/compress/flate/deflate_test.go +++ b/src/compress/flate/deflate_test.go @@ -371,9 +371,9 @@ var deflateInflateStringTests = []deflateInflateStringTest{ [...]int{100018, 50650, 50960, 51150, 50930, 50790, 50790, 50790, 50790, 50790, 43683}, }, { - "../testdata/Mark.Twain-Tom.Sawyer.txt", - "Mark.Twain-Tom.Sawyer", - [...]int{407330, 187598, 180361, 172974, 169160, 163476, 160936, 160506, 160295, 160295, 233460}, + "../../testdata/Isaac.Newton-Opticks.txt", + "Isaac.Newton-Opticks", + [...]int{567248, 218338, 198211, 193152, 181100, 175427, 175427, 173597, 173422, 173422, 325240}, }, } @@ -654,7 +654,7 @@ func (w *failWriter) Write(b []byte) (int, error) { func TestWriterPersistentError(t *testing.T) { t.Parallel() - d, err := ioutil.ReadFile("../testdata/Mark.Twain-Tom.Sawyer.txt") + d, err := ioutil.ReadFile("../../testdata/Isaac.Newton-Opticks.txt") if err != nil { t.Fatalf("ReadFile: %v", err) } diff --git a/src/compress/flate/reader_test.go b/src/compress/flate/reader_test.go index b0a16ce18b98d..9d2943a54077c 100644 --- a/src/compress/flate/reader_test.go +++ b/src/compress/flate/reader_test.go @@ -27,8 +27,8 @@ var suites = []struct{ name, file string }{ // does not repeat, but there are only 10 possible digits, so it should be // reasonably compressible. {"Digits", "../testdata/e.txt"}, - // Twain is Mark Twain's classic English novel. - {"Twain", "../testdata/Mark.Twain-Tom.Sawyer.txt"}, + // Newton is Isaac Newtons's educational text on Opticks. + {"Newton", "../../testdata/Isaac.Newton-Opticks.txt"}, } func BenchmarkDecode(b *testing.B) { diff --git a/src/compress/testdata/Mark.Twain-Tom.Sawyer.txt b/src/compress/testdata/Mark.Twain-Tom.Sawyer.txt deleted file mode 100644 index c9106fd522cec..0000000000000 --- a/src/compress/testdata/Mark.Twain-Tom.Sawyer.txt +++ /dev/null @@ -1,8465 +0,0 @@ -Produced by David Widger. The previous edition was updated by Jose -Menendez. - - - - - - THE ADVENTURES OF TOM SAWYER - BY - MARK TWAIN - (Samuel Langhorne Clemens) - - - - - P R E F A C E - -MOST of the adventures recorded in this book really occurred; one or -two were experiences of my own, the rest those of boys who were -schoolmates of mine. Huck Finn is drawn from life; Tom Sawyer also, but -not from an individual--he is a combination of the characteristics of -three boys whom I knew, and therefore belongs to the composite order of -architecture. - -The odd superstitions touched upon were all prevalent among children -and slaves in the West at the period of this story--that is to say, -thirty or forty years ago. - -Although my book is intended mainly for the entertainment of boys and -girls, I hope it will not be shunned by men and women on that account, -for part of my plan has been to try to pleasantly remind adults of what -they once were themselves, and of how they felt and thought and talked, -and what queer enterprises they sometimes engaged in. - - THE AUTHOR. - -HARTFORD, 1876. - - - - T O M S A W Y E R - - - -CHAPTER I - -"TOM!" - -No answer. - -"TOM!" - -No answer. - -"What's gone with that boy, I wonder? You TOM!" - -No answer. - -The old lady pulled her spectacles down and looked over them about the -room; then she put them up and looked out under them. She seldom or -never looked THROUGH them for so small a thing as a boy; they were her -state pair, the pride of her heart, and were built for "style," not -service--she could have seen through a pair of stove-lids just as well. -She looked perplexed for a moment, and then said, not fiercely, but -still loud enough for the furniture to hear: - -"Well, I lay if I get hold of you I'll--" - -She did not finish, for by this time she was bending down and punching -under the bed with the broom, and so she needed breath to punctuate the -punches with. She resurrected nothing but the cat. - -"I never did see the beat of that boy!" - -She went to the open door and stood in it and looked out among the -tomato vines and "jimpson" weeds that constituted the garden. No Tom. -So she lifted up her voice at an angle calculated for distance and -shouted: - -"Y-o-u-u TOM!" - -There was a slight noise behind her and she turned just in time to -seize a small boy by the slack of his roundabout and arrest his flight. - -"There! I might 'a' thought of that closet. What you been doing in -there?" - -"Nothing." - -"Nothing! Look at your hands. And look at your mouth. What IS that -truck?" - -"I don't know, aunt." - -"Well, I know. It's jam--that's what it is. Forty times I've said if -you didn't let that jam alone I'd skin you. Hand me that switch." - -The switch hovered in the air--the peril was desperate-- - -"My! Look behind you, aunt!" - -The old lady whirled round, and snatched her skirts out of danger. The -lad fled on the instant, scrambled up the high board-fence, and -disappeared over it. - -His aunt Polly stood surprised a moment, and then broke into a gentle -laugh. - -"Hang the boy, can't I never learn anything? Ain't he played me tricks -enough like that for me to be looking out for him by this time? But old -fools is the biggest fools there is. Can't learn an old dog new tricks, -as the saying is. But my goodness, he never plays them alike, two days, -and how is a body to know what's coming? He 'pears to know just how -long he can torment me before I get my dander up, and he knows if he -can make out to put me off for a minute or make me laugh, it's all down -again and I can't hit him a lick. I ain't doing my duty by that boy, -and that's the Lord's truth, goodness knows. Spare the rod and spile -the child, as the Good Book says. I'm a laying up sin and suffering for -us both, I know. He's full of the Old Scratch, but laws-a-me! he's my -own dead sister's boy, poor thing, and I ain't got the heart to lash -him, somehow. Every time I let him off, my conscience does hurt me so, -and every time I hit him my old heart most breaks. Well-a-well, man -that is born of woman is of few days and full of trouble, as the -Scripture says, and I reckon it's so. He'll play hookey this evening, * -and [* Southwestern for "afternoon"] I'll just be obleeged to make him -work, to-morrow, to punish him. It's mighty hard to make him work -Saturdays, when all the boys is having holiday, but he hates work more -than he hates anything else, and I've GOT to do some of my duty by him, -or I'll be the ruination of the child." - -Tom did play hookey, and he had a very good time. He got back home -barely in season to help Jim, the small colored boy, saw next-day's -wood and split the kindlings before supper--at least he was there in -time to tell his adventures to Jim while Jim did three-fourths of the -work. Tom's younger brother (or rather half-brother) Sid was already -through with his part of the work (picking up chips), for he was a -quiet boy, and had no adventurous, troublesome ways. - -While Tom was eating his supper, and stealing sugar as opportunity -offered, Aunt Polly asked him questions that were full of guile, and -very deep--for she wanted to trap him into damaging revealments. Like -many other simple-hearted souls, it was her pet vanity to believe she -was endowed with a talent for dark and mysterious diplomacy, and she -loved to contemplate her most transparent devices as marvels of low -cunning. Said she: - -"Tom, it was middling warm in school, warn't it?" - -"Yes'm." - -"Powerful warm, warn't it?" - -"Yes'm." - -"Didn't you want to go in a-swimming, Tom?" - -A bit of a scare shot through Tom--a touch of uncomfortable suspicion. -He searched Aunt Polly's face, but it told him nothing. So he said: - -"No'm--well, not very much." - -The old lady reached out her hand and felt Tom's shirt, and said: - -"But you ain't too warm now, though." And it flattered her to reflect -that she had discovered that the shirt was dry without anybody knowing -that that was what she had in her mind. But in spite of her, Tom knew -where the wind lay, now. So he forestalled what might be the next move: - -"Some of us pumped on our heads--mine's damp yet. See?" - -Aunt Polly was vexed to think she had overlooked that bit of -circumstantial evidence, and missed a trick. Then she had a new -inspiration: - -"Tom, you didn't have to undo your shirt collar where I sewed it, to -pump on your head, did you? Unbutton your jacket!" - -The trouble vanished out of Tom's face. He opened his jacket. His -shirt collar was securely sewed. - -"Bother! Well, go 'long with you. I'd made sure you'd played hookey -and been a-swimming. But I forgive ye, Tom. I reckon you're a kind of a -singed cat, as the saying is--better'n you look. THIS time." - -She was half sorry her sagacity had miscarried, and half glad that Tom -had stumbled into obedient conduct for once. - -But Sidney said: - -"Well, now, if I didn't think you sewed his collar with white thread, -but it's black." - -"Why, I did sew it with white! Tom!" - -But Tom did not wait for the rest. As he went out at the door he said: - -"Siddy, I'll lick you for that." - -In a safe place Tom examined two large needles which were thrust into -the lapels of his jacket, and had thread bound about them--one needle -carried white thread and the other black. He said: - -"She'd never noticed if it hadn't been for Sid. Confound it! sometimes -she sews it with white, and sometimes she sews it with black. I wish to -geeminy she'd stick to one or t'other--I can't keep the run of 'em. But -I bet you I'll lam Sid for that. I'll learn him!" - -He was not the Model Boy of the village. He knew the model boy very -well though--and loathed him. - -Within two minutes, or even less, he had forgotten all his troubles. -Not because his troubles were one whit less heavy and bitter to him -than a man's are to a man, but because a new and powerful interest bore -them down and drove them out of his mind for the time--just as men's -misfortunes are forgotten in the excitement of new enterprises. This -new interest was a valued novelty in whistling, which he had just -acquired from a negro, and he was suffering to practise it undisturbed. -It consisted in a peculiar bird-like turn, a sort of liquid warble, -produced by touching the tongue to the roof of the mouth at short -intervals in the midst of the music--the reader probably remembers how -to do it, if he has ever been a boy. Diligence and attention soon gave -him the knack of it, and he strode down the street with his mouth full -of harmony and his soul full of gratitude. He felt much as an -astronomer feels who has discovered a new planet--no doubt, as far as -strong, deep, unalloyed pleasure is concerned, the advantage was with -the boy, not the astronomer. - -The summer evenings were long. It was not dark, yet. Presently Tom -checked his whistle. A stranger was before him--a boy a shade larger -than himself. A new-comer of any age or either sex was an impressive -curiosity in the poor little shabby village of St. Petersburg. This boy -was well dressed, too--well dressed on a week-day. This was simply -astounding. His cap was a dainty thing, his close-buttoned blue cloth -roundabout was new and natty, and so were his pantaloons. He had shoes -on--and it was only Friday. He even wore a necktie, a bright bit of -ribbon. He had a citified air about him that ate into Tom's vitals. The -more Tom stared at the splendid marvel, the higher he turned up his -nose at his finery and the shabbier and shabbier his own outfit seemed -to him to grow. Neither boy spoke. If one moved, the other moved--but -only sidewise, in a circle; they kept face to face and eye to eye all -the time. Finally Tom said: - -"I can lick you!" - -"I'd like to see you try it." - -"Well, I can do it." - -"No you can't, either." - -"Yes I can." - -"No you can't." - -"I can." - -"You can't." - -"Can!" - -"Can't!" - -An uncomfortable pause. Then Tom said: - -"What's your name?" - -"'Tisn't any of your business, maybe." - -"Well I 'low I'll MAKE it my business." - -"Well why don't you?" - -"If you say much, I will." - -"Much--much--MUCH. There now." - -"Oh, you think you're mighty smart, DON'T you? I could lick you with -one hand tied behind me, if I wanted to." - -"Well why don't you DO it? You SAY you can do it." - -"Well I WILL, if you fool with me." - -"Oh yes--I've seen whole families in the same fix." - -"Smarty! You think you're SOME, now, DON'T you? Oh, what a hat!" - -"You can lump that hat if you don't like it. I dare you to knock it -off--and anybody that'll take a dare will suck eggs." - -"You're a liar!" - -"You're another." - -"You're a fighting liar and dasn't take it up." - -"Aw--take a walk!" - -"Say--if you give me much more of your sass I'll take and bounce a -rock off'n your head." - -"Oh, of COURSE you will." - -"Well I WILL." - -"Well why don't you DO it then? What do you keep SAYING you will for? -Why don't you DO it? It's because you're afraid." - -"I AIN'T afraid." - -"You are." - -"I ain't." - -"You are." - -Another pause, and more eying and sidling around each other. Presently -they were shoulder to shoulder. Tom said: - -"Get away from here!" - -"Go away yourself!" - -"I won't." - -"I won't either." - -So they stood, each with a foot placed at an angle as a brace, and -both shoving with might and main, and glowering at each other with -hate. But neither could get an advantage. After struggling till both -were hot and flushed, each relaxed his strain with watchful caution, -and Tom said: - -"You're a coward and a pup. I'll tell my big brother on you, and he -can thrash you with his little finger, and I'll make him do it, too." - -"What do I care for your big brother? I've got a brother that's bigger -than he is--and what's more, he can throw him over that fence, too." -[Both brothers were imaginary.] - -"That's a lie." - -"YOUR saying so don't make it so." - -Tom drew a line in the dust with his big toe, and said: - -"I dare you to step over that, and I'll lick you till you can't stand -up. Anybody that'll take a dare will steal sheep." - -The new boy stepped over promptly, and said: - -"Now you said you'd do it, now let's see you do it." - -"Don't you crowd me now; you better look out." - -"Well, you SAID you'd do it--why don't you do it?" - -"By jingo! for two cents I WILL do it." - -The new boy took two broad coppers out of his pocket and held them out -with derision. Tom struck them to the ground. In an instant both boys -were rolling and tumbling in the dirt, gripped together like cats; and -for the space of a minute they tugged and tore at each other's hair and -clothes, punched and scratched each other's nose, and covered -themselves with dust and glory. Presently the confusion took form, and -through the fog of battle Tom appeared, seated astride the new boy, and -pounding him with his fists. "Holler 'nuff!" said he. - -The boy only struggled to free himself. He was crying--mainly from rage. - -"Holler 'nuff!"--and the pounding went on. - -At last the stranger got out a smothered "'Nuff!" and Tom let him up -and said: - -"Now that'll learn you. Better look out who you're fooling with next -time." - -The new boy went off brushing the dust from his clothes, sobbing, -snuffling, and occasionally looking back and shaking his head and -threatening what he would do to Tom the "next time he caught him out." -To which Tom responded with jeers, and started off in high feather, and -as soon as his back was turned the new boy snatched up a stone, threw -it and hit him between the shoulders and then turned tail and ran like -an antelope. Tom chased the traitor home, and thus found out where he -lived. He then held a position at the gate for some time, daring the -enemy to come outside, but the enemy only made faces at him through the -window and declined. At last the enemy's mother appeared, and called -Tom a bad, vicious, vulgar child, and ordered him away. So he went -away; but he said he "'lowed" to "lay" for that boy. - -He got home pretty late that night, and when he climbed cautiously in -at the window, he uncovered an ambuscade, in the person of his aunt; -and when she saw the state his clothes were in her resolution to turn -his Saturday holiday into captivity at hard labor became adamantine in -its firmness. - - - -CHAPTER II - -SATURDAY morning was come, and all the summer world was bright and -fresh, and brimming with life. There was a song in every heart; and if -the heart was young the music issued at the lips. There was cheer in -every face and a spring in every step. The locust-trees were in bloom -and the fragrance of the blossoms filled the air. Cardiff Hill, beyond -the village and above it, was green with vegetation and it lay just far -enough away to seem a Delectable Land, dreamy, reposeful, and inviting. - -Tom appeared on the sidewalk with a bucket of whitewash and a -long-handled brush. He surveyed the fence, and all gladness left him and -a deep melancholy settled down upon his spirit. Thirty yards of board -fence nine feet high. Life to him seemed hollow, and existence but a -burden. Sighing, he dipped his brush and passed it along the topmost -plank; repeated the operation; did it again; compared the insignificant -whitewashed streak with the far-reaching continent of unwhitewashed -fence, and sat down on a tree-box discouraged. Jim came skipping out at -the gate with a tin pail, and singing Buffalo Gals. Bringing water from -the town pump had always been hateful work in Tom's eyes, before, but -now it did not strike him so. He remembered that there was company at -the pump. White, mulatto, and negro boys and girls were always there -waiting their turns, resting, trading playthings, quarrelling, -fighting, skylarking. And he remembered that although the pump was only -a hundred and fifty yards off, Jim never got back with a bucket of -water under an hour--and even then somebody generally had to go after -him. Tom said: - -"Say, Jim, I'll fetch the water if you'll whitewash some." - -Jim shook his head and said: - -"Can't, Mars Tom. Ole missis, she tole me I got to go an' git dis -water an' not stop foolin' roun' wid anybody. She say she spec' Mars -Tom gwine to ax me to whitewash, an' so she tole me go 'long an' 'tend -to my own business--she 'lowed SHE'D 'tend to de whitewashin'." - -"Oh, never you mind what she said, Jim. That's the way she always -talks. Gimme the bucket--I won't be gone only a a minute. SHE won't -ever know." - -"Oh, I dasn't, Mars Tom. Ole missis she'd take an' tar de head off'n -me. 'Deed she would." - -"SHE! She never licks anybody--whacks 'em over the head with her -thimble--and who cares for that, I'd like to know. She talks awful, but -talk don't hurt--anyways it don't if she don't cry. Jim, I'll give you -a marvel. I'll give you a white alley!" - -Jim began to waver. - -"White alley, Jim! And it's a bully taw." - -"My! Dat's a mighty gay marvel, I tell you! But Mars Tom I's powerful -'fraid ole missis--" - -"And besides, if you will I'll show you my sore toe." - -Jim was only human--this attraction was too much for him. He put down -his pail, took the white alley, and bent over the toe with absorbing -interest while the bandage was being unwound. In another moment he was -flying down the street with his pail and a tingling rear, Tom was -whitewashing with vigor, and Aunt Polly was retiring from the field -with a slipper in her hand and triumph in her eye. - -But Tom's energy did not last. He began to think of the fun he had -planned for this day, and his sorrows multiplied. Soon the free boys -would come tripping along on all sorts of delicious expeditions, and -they would make a world of fun of him for having to work--the very -thought of it burnt him like fire. He got out his worldly wealth and -examined it--bits of toys, marbles, and trash; enough to buy an -exchange of WORK, maybe, but not half enough to buy so much as half an -hour of pure freedom. So he returned his straitened means to his -pocket, and gave up the idea of trying to buy the boys. At this dark -and hopeless moment an inspiration burst upon him! Nothing less than a -great, magnificent inspiration. - -He took up his brush and went tranquilly to work. Ben Rogers hove in -sight presently--the very boy, of all boys, whose ridicule he had been -dreading. Ben's gait was the hop-skip-and-jump--proof enough that his -heart was light and his anticipations high. He was eating an apple, and -giving a long, melodious whoop, at intervals, followed by a deep-toned -ding-dong-dong, ding-dong-dong, for he was personating a steamboat. As -he drew near, he slackened speed, took the middle of the street, leaned -far over to starboard and rounded to ponderously and with laborious -pomp and circumstance--for he was personating the Big Missouri, and -considered himself to be drawing nine feet of water. He was boat and -captain and engine-bells combined, so he had to imagine himself -standing on his own hurricane-deck giving the orders and executing them: - -"Stop her, sir! Ting-a-ling-ling!" The headway ran almost out, and he -drew up slowly toward the sidewalk. - -"Ship up to back! Ting-a-ling-ling!" His arms straightened and -stiffened down his sides. - -"Set her back on the stabboard! Ting-a-ling-ling! Chow! ch-chow-wow! -Chow!" His right hand, meantime, describing stately circles--for it was -representing a forty-foot wheel. - -"Let her go back on the labboard! Ting-a-lingling! Chow-ch-chow-chow!" -The left hand began to describe circles. - -"Stop the stabboard! Ting-a-ling-ling! Stop the labboard! Come ahead -on the stabboard! Stop her! Let your outside turn over slow! -Ting-a-ling-ling! Chow-ow-ow! Get out that head-line! LIVELY now! -Come--out with your spring-line--what're you about there! Take a turn -round that stump with the bight of it! Stand by that stage, now--let her -go! Done with the engines, sir! Ting-a-ling-ling! SH'T! S'H'T! SH'T!" -(trying the gauge-cocks). - -Tom went on whitewashing--paid no attention to the steamboat. Ben -stared a moment and then said: "Hi-YI! YOU'RE up a stump, ain't you!" - -No answer. Tom surveyed his last touch with the eye of an artist, then -he gave his brush another gentle sweep and surveyed the result, as -before. Ben ranged up alongside of him. Tom's mouth watered for the -apple, but he stuck to his work. Ben said: - -"Hello, old chap, you got to work, hey?" - -Tom wheeled suddenly and said: - -"Why, it's you, Ben! I warn't noticing." - -"Say--I'm going in a-swimming, I am. Don't you wish you could? But of -course you'd druther WORK--wouldn't you? Course you would!" - -Tom contemplated the boy a bit, and said: - -"What do you call work?" - -"Why, ain't THAT work?" - -Tom resumed his whitewashing, and answered carelessly: - -"Well, maybe it is, and maybe it ain't. All I know, is, it suits Tom -Sawyer." - -"Oh come, now, you don't mean to let on that you LIKE it?" - -The brush continued to move. - -"Like it? Well, I don't see why I oughtn't to like it. Does a boy get -a chance to whitewash a fence every day?" - -That put the thing in a new light. Ben stopped nibbling his apple. Tom -swept his brush daintily back and forth--stepped back to note the -effect--added a touch here and there--criticised the effect again--Ben -watching every move and getting more and more interested, more and more -absorbed. Presently he said: - -"Say, Tom, let ME whitewash a little." - -Tom considered, was about to consent; but he altered his mind: - -"No--no--I reckon it wouldn't hardly do, Ben. You see, Aunt Polly's -awful particular about this fence--right here on the street, you know ---but if it was the back fence I wouldn't mind and SHE wouldn't. Yes, -she's awful particular about this fence; it's got to be done very -careful; I reckon there ain't one boy in a thousand, maybe two -thousand, that can do it the way it's got to be done." - -"No--is that so? Oh come, now--lemme just try. Only just a little--I'd -let YOU, if you was me, Tom." - -"Ben, I'd like to, honest injun; but Aunt Polly--well, Jim wanted to -do it, but she wouldn't let him; Sid wanted to do it, and she wouldn't -let Sid. Now don't you see how I'm fixed? If you was to tackle this -fence and anything was to happen to it--" - -"Oh, shucks, I'll be just as careful. Now lemme try. Say--I'll give -you the core of my apple." - -"Well, here--No, Ben, now don't. I'm afeard--" - -"I'll give you ALL of it!" - -Tom gave up the brush with reluctance in his face, but alacrity in his -heart. And while the late steamer Big Missouri worked and sweated in -the sun, the retired artist sat on a barrel in the shade close by, -dangled his legs, munched his apple, and planned the slaughter of more -innocents. There was no lack of material; boys happened along every -little while; they came to jeer, but remained to whitewash. By the time -Ben was fagged out, Tom had traded the next chance to Billy Fisher for -a kite, in good repair; and when he played out, Johnny Miller bought in -for a dead rat and a string to swing it with--and so on, and so on, -hour after hour. And when the middle of the afternoon came, from being -a poor poverty-stricken boy in the morning, Tom was literally rolling -in wealth. He had besides the things before mentioned, twelve marbles, -part of a jews-harp, a piece of blue bottle-glass to look through, a -spool cannon, a key that wouldn't unlock anything, a fragment of chalk, -a glass stopper of a decanter, a tin soldier, a couple of tadpoles, six -fire-crackers, a kitten with only one eye, a brass doorknob, a -dog-collar--but no dog--the handle of a knife, four pieces of -orange-peel, and a dilapidated old window sash. - -He had had a nice, good, idle time all the while--plenty of company ---and the fence had three coats of whitewash on it! If he hadn't run out -of whitewash he would have bankrupted every boy in the village. - -Tom said to himself that it was not such a hollow world, after all. He -had discovered a great law of human action, without knowing it--namely, -that in order to make a man or a boy covet a thing, it is only -necessary to make the thing difficult to attain. If he had been a great -and wise philosopher, like the writer of this book, he would now have -comprehended that Work consists of whatever a body is OBLIGED to do, -and that Play consists of whatever a body is not obliged to do. And -this would help him to understand why constructing artificial flowers -or performing on a tread-mill is work, while rolling ten-pins or -climbing Mont Blanc is only amusement. There are wealthy gentlemen in -England who drive four-horse passenger-coaches twenty or thirty miles -on a daily line, in the summer, because the privilege costs them -considerable money; but if they were offered wages for the service, -that would turn it into work and then they would resign. - -The boy mused awhile over the substantial change which had taken place -in his worldly circumstances, and then wended toward headquarters to -report. - - - -CHAPTER III - -TOM presented himself before Aunt Polly, who was sitting by an open -window in a pleasant rearward apartment, which was bedroom, -breakfast-room, dining-room, and library, combined. The balmy summer -air, the restful quiet, the odor of the flowers, and the drowsing murmur -of the bees had had their effect, and she was nodding over her knitting ---for she had no company but the cat, and it was asleep in her lap. Her -spectacles were propped up on her gray head for safety. She had thought -that of course Tom had deserted long ago, and she wondered at seeing him -place himself in her power again in this intrepid way. He said: "Mayn't -I go and play now, aunt?" - -"What, a'ready? How much have you done?" - -"It's all done, aunt." - -"Tom, don't lie to me--I can't bear it." - -"I ain't, aunt; it IS all done." - -Aunt Polly placed small trust in such evidence. She went out to see -for herself; and she would have been content to find twenty per cent. -of Tom's statement true. When she found the entire fence whitewashed, -and not only whitewashed but elaborately coated and recoated, and even -a streak added to the ground, her astonishment was almost unspeakable. -She said: - -"Well, I never! There's no getting round it, you can work when you're -a mind to, Tom." And then she diluted the compliment by adding, "But -it's powerful seldom you're a mind to, I'm bound to say. Well, go 'long -and play; but mind you get back some time in a week, or I'll tan you." - -She was so overcome by the splendor of his achievement that she took -him into the closet and selected a choice apple and delivered it to -him, along with an improving lecture upon the added value and flavor a -treat took to itself when it came without sin through virtuous effort. -And while she closed with a happy Scriptural flourish, he "hooked" a -doughnut. - -Then he skipped out, and saw Sid just starting up the outside stairway -that led to the back rooms on the second floor. Clods were handy and -the air was full of them in a twinkling. They raged around Sid like a -hail-storm; and before Aunt Polly could collect her surprised faculties -and sally to the rescue, six or seven clods had taken personal effect, -and Tom was over the fence and gone. There was a gate, but as a general -thing he was too crowded for time to make use of it. His soul was at -peace, now that he had settled with Sid for calling attention to his -black thread and getting him into trouble. - -Tom skirted the block, and came round into a muddy alley that led by -the back of his aunt's cow-stable. He presently got safely beyond the -reach of capture and punishment, and hastened toward the public square -of the village, where two "military" companies of boys had met for -conflict, according to previous appointment. Tom was General of one of -these armies, Joe Harper (a bosom friend) General of the other. These -two great commanders did not condescend to fight in person--that being -better suited to the still smaller fry--but sat together on an eminence -and conducted the field operations by orders delivered through -aides-de-camp. Tom's army won a great victory, after a long and -hard-fought battle. Then the dead were counted, prisoners exchanged, -the terms of the next disagreement agreed upon, and the day for the -necessary battle appointed; after which the armies fell into line and -marched away, and Tom turned homeward alone. - -As he was passing by the house where Jeff Thatcher lived, he saw a new -girl in the garden--a lovely little blue-eyed creature with yellow hair -plaited into two long-tails, white summer frock and embroidered -pantalettes. The fresh-crowned hero fell without firing a shot. A -certain Amy Lawrence vanished out of his heart and left not even a -memory of herself behind. He had thought he loved her to distraction; -he had regarded his passion as adoration; and behold it was only a poor -little evanescent partiality. He had been months winning her; she had -confessed hardly a week ago; he had been the happiest and the proudest -boy in the world only seven short days, and here in one instant of time -she had gone out of his heart like a casual stranger whose visit is -done. - -He worshipped this new angel with furtive eye, till he saw that she -had discovered him; then he pretended he did not know she was present, -and began to "show off" in all sorts of absurd boyish ways, in order to -win her admiration. He kept up this grotesque foolishness for some -time; but by-and-by, while he was in the midst of some dangerous -gymnastic performances, he glanced aside and saw that the little girl -was wending her way toward the house. Tom came up to the fence and -leaned on it, grieving, and hoping she would tarry yet awhile longer. -She halted a moment on the steps and then moved toward the door. Tom -heaved a great sigh as she put her foot on the threshold. But his face -lit up, right away, for she tossed a pansy over the fence a moment -before she disappeared. - -The boy ran around and stopped within a foot or two of the flower, and -then shaded his eyes with his hand and began to look down street as if -he had discovered something of interest going on in that direction. -Presently he picked up a straw and began trying to balance it on his -nose, with his head tilted far back; and as he moved from side to side, -in his efforts, he edged nearer and nearer toward the pansy; finally -his bare foot rested upon it, his pliant toes closed upon it, and he -hopped away with the treasure and disappeared round the corner. But -only for a minute--only while he could button the flower inside his -jacket, next his heart--or next his stomach, possibly, for he was not -much posted in anatomy, and not hypercritical, anyway. - -He returned, now, and hung about the fence till nightfall, "showing -off," as before; but the girl never exhibited herself again, though Tom -comforted himself a little with the hope that she had been near some -window, meantime, and been aware of his attentions. Finally he strode -home reluctantly, with his poor head full of visions. - -All through supper his spirits were so high that his aunt wondered -"what had got into the child." He took a good scolding about clodding -Sid, and did not seem to mind it in the least. He tried to steal sugar -under his aunt's very nose, and got his knuckles rapped for it. He said: - -"Aunt, you don't whack Sid when he takes it." - -"Well, Sid don't torment a body the way you do. You'd be always into -that sugar if I warn't watching you." - -Presently she stepped into the kitchen, and Sid, happy in his -immunity, reached for the sugar-bowl--a sort of glorying over Tom which -was wellnigh unbearable. But Sid's fingers slipped and the bowl dropped -and broke. Tom was in ecstasies. In such ecstasies that he even -controlled his tongue and was silent. He said to himself that he would -not speak a word, even when his aunt came in, but would sit perfectly -still till she asked who did the mischief; and then he would tell, and -there would be nothing so good in the world as to see that pet model -"catch it." He was so brimful of exultation that he could hardly hold -himself when the old lady came back and stood above the wreck -discharging lightnings of wrath from over her spectacles. He said to -himself, "Now it's coming!" And the next instant he was sprawling on -the floor! The potent palm was uplifted to strike again when Tom cried -out: - -"Hold on, now, what 'er you belting ME for?--Sid broke it!" - -Aunt Polly paused, perplexed, and Tom looked for healing pity. But -when she got her tongue again, she only said: - -"Umf! Well, you didn't get a lick amiss, I reckon. You been into some -other audacious mischief when I wasn't around, like enough." - -Then her conscience reproached her, and she yearned to say something -kind and loving; but she judged that this would be construed into a -confession that she had been in the wrong, and discipline forbade that. -So she kept silence, and went about her affairs with a troubled heart. -Tom sulked in a corner and exalted his woes. He knew that in her heart -his aunt was on her knees to him, and he was morosely gratified by the -consciousness of it. He would hang out no signals, he would take notice -of none. He knew that a yearning glance fell upon him, now and then, -through a film of tears, but he refused recognition of it. He pictured -himself lying sick unto death and his aunt bending over him beseeching -one little forgiving word, but he would turn his face to the wall, and -die with that word unsaid. Ah, how would she feel then? And he pictured -himself brought home from the river, dead, with his curls all wet, and -his sore heart at rest. How she would throw herself upon him, and how -her tears would fall like rain, and her lips pray God to give her back -her boy and she would never, never abuse him any more! But he would lie -there cold and white and make no sign--a poor little sufferer, whose -griefs were at an end. He so worked upon his feelings with the pathos -of these dreams, that he had to keep swallowing, he was so like to -choke; and his eyes swam in a blur of water, which overflowed when he -winked, and ran down and trickled from the end of his nose. And such a -luxury to him was this petting of his sorrows, that he could not bear -to have any worldly cheeriness or any grating delight intrude upon it; -it was too sacred for such contact; and so, presently, when his cousin -Mary danced in, all alive with the joy of seeing home again after an -age-long visit of one week to the country, he got up and moved in -clouds and darkness out at one door as she brought song and sunshine in -at the other. - -He wandered far from the accustomed haunts of boys, and sought -desolate places that were in harmony with his spirit. A log raft in the -river invited him, and he seated himself on its outer edge and -contemplated the dreary vastness of the stream, wishing, the while, -that he could only be drowned, all at once and unconsciously, without -undergoing the uncomfortable routine devised by nature. Then he thought -of his flower. He got it out, rumpled and wilted, and it mightily -increased his dismal felicity. He wondered if she would pity him if she -knew? Would she cry, and wish that she had a right to put her arms -around his neck and comfort him? Or would she turn coldly away like all -the hollow world? This picture brought such an agony of pleasurable -suffering that he worked it over and over again in his mind and set it -up in new and varied lights, till he wore it threadbare. At last he -rose up sighing and departed in the darkness. - -About half-past nine or ten o'clock he came along the deserted street -to where the Adored Unknown lived; he paused a moment; no sound fell -upon his listening ear; a candle was casting a dull glow upon the -curtain of a second-story window. Was the sacred presence there? He -climbed the fence, threaded his stealthy way through the plants, till -he stood under that window; he looked up at it long, and with emotion; -then he laid him down on the ground under it, disposing himself upon -his back, with his hands clasped upon his breast and holding his poor -wilted flower. And thus he would die--out in the cold world, with no -shelter over his homeless head, no friendly hand to wipe the -death-damps from his brow, no loving face to bend pityingly over him -when the great agony came. And thus SHE would see him when she looked -out upon the glad morning, and oh! would she drop one little tear upon -his poor, lifeless form, would she heave one little sigh to see a bright -young life so rudely blighted, so untimely cut down? - -The window went up, a maid-servant's discordant voice profaned the -holy calm, and a deluge of water drenched the prone martyr's remains! - -The strangling hero sprang up with a relieving snort. There was a whiz -as of a missile in the air, mingled with the murmur of a curse, a sound -as of shivering glass followed, and a small, vague form went over the -fence and shot away in the gloom. - -Not long after, as Tom, all undressed for bed, was surveying his -drenched garments by the light of a tallow dip, Sid woke up; but if he -had any dim idea of making any "references to allusions," he thought -better of it and held his peace, for there was danger in Tom's eye. - -Tom turned in without the added vexation of prayers, and Sid made -mental note of the omission. - - - -CHAPTER IV - -THE sun rose upon a tranquil world, and beamed down upon the peaceful -village like a benediction. Breakfast over, Aunt Polly had family -worship: it began with a prayer built from the ground up of solid -courses of Scriptural quotations, welded together with a thin mortar of -originality; and from the summit of this she delivered a grim chapter -of the Mosaic Law, as from Sinai. - -Then Tom girded up his loins, so to speak, and went to work to "get -his verses." Sid had learned his lesson days before. Tom bent all his -energies to the memorizing of five verses, and he chose part of the -Sermon on the Mount, because he could find no verses that were shorter. -At the end of half an hour Tom had a vague general idea of his lesson, -but no more, for his mind was traversing the whole field of human -thought, and his hands were busy with distracting recreations. Mary -took his book to hear him recite, and he tried to find his way through -the fog: - -"Blessed are the--a--a--" - -"Poor"-- - -"Yes--poor; blessed are the poor--a--a--" - -"In spirit--" - -"In spirit; blessed are the poor in spirit, for they--they--" - -"THEIRS--" - -"For THEIRS. Blessed are the poor in spirit, for theirs is the kingdom -of heaven. Blessed are they that mourn, for they--they--" - -"Sh--" - -"For they--a--" - -"S, H, A--" - -"For they S, H--Oh, I don't know what it is!" - -"SHALL!" - -"Oh, SHALL! for they shall--for they shall--a--a--shall mourn--a--a-- -blessed are they that shall--they that--a--they that shall mourn, for -they shall--a--shall WHAT? Why don't you tell me, Mary?--what do you -want to be so mean for?" - -"Oh, Tom, you poor thick-headed thing, I'm not teasing you. I wouldn't -do that. You must go and learn it again. Don't you be discouraged, Tom, -you'll manage it--and if you do, I'll give you something ever so nice. -There, now, that's a good boy." - -"All right! What is it, Mary, tell me what it is." - -"Never you mind, Tom. You know if I say it's nice, it is nice." - -"You bet you that's so, Mary. All right, I'll tackle it again." - -And he did "tackle it again"--and under the double pressure of -curiosity and prospective gain he did it with such spirit that he -accomplished a shining success. Mary gave him a brand-new "Barlow" -knife worth twelve and a half cents; and the convulsion of delight that -swept his system shook him to his foundations. True, the knife would -not cut anything, but it was a "sure-enough" Barlow, and there was -inconceivable grandeur in that--though where the Western boys ever got -the idea that such a weapon could possibly be counterfeited to its -injury is an imposing mystery and will always remain so, perhaps. Tom -contrived to scarify the cupboard with it, and was arranging to begin -on the bureau, when he was called off to dress for Sunday-school. - -Mary gave him a tin basin of water and a piece of soap, and he went -outside the door and set the basin on a little bench there; then he -dipped the soap in the water and laid it down; turned up his sleeves; -poured out the water on the ground, gently, and then entered the -kitchen and began to wipe his face diligently on the towel behind the -door. But Mary removed the towel and said: - -"Now ain't you ashamed, Tom. You mustn't be so bad. Water won't hurt -you." - -Tom was a trifle disconcerted. The basin was refilled, and this time -he stood over it a little while, gathering resolution; took in a big -breath and began. When he entered the kitchen presently, with both eyes -shut and groping for the towel with his hands, an honorable testimony -of suds and water was dripping from his face. But when he emerged from -the towel, he was not yet satisfactory, for the clean territory stopped -short at his chin and his jaws, like a mask; below and beyond this line -there was a dark expanse of unirrigated soil that spread downward in -front and backward around his neck. Mary took him in hand, and when she -was done with him he was a man and a brother, without distinction of -color, and his saturated hair was neatly brushed, and its short curls -wrought into a dainty and symmetrical general effect. [He privately -smoothed out the curls, with labor and difficulty, and plastered his -hair close down to his head; for he held curls to be effeminate, and -his own filled his life with bitterness.] Then Mary got out a suit of -his clothing that had been used only on Sundays during two years--they -were simply called his "other clothes"--and so by that we know the -size of his wardrobe. The girl "put him to rights" after he had dressed -himself; she buttoned his neat roundabout up to his chin, turned his -vast shirt collar down over his shoulders, brushed him off and crowned -him with his speckled straw hat. He now looked exceedingly improved and -uncomfortable. He was fully as uncomfortable as he looked; for there -was a restraint about whole clothes and cleanliness that galled him. He -hoped that Mary would forget his shoes, but the hope was blighted; she -coated them thoroughly with tallow, as was the custom, and brought them -out. He lost his temper and said he was always being made to do -everything he didn't want to do. But Mary said, persuasively: - -"Please, Tom--that's a good boy." - -So he got into the shoes snarling. Mary was soon ready, and the three -children set out for Sunday-school--a place that Tom hated with his -whole heart; but Sid and Mary were fond of it. - -Sabbath-school hours were from nine to half-past ten; and then church -service. Two of the children always remained for the sermon -voluntarily, and the other always remained too--for stronger reasons. -The church's high-backed, uncushioned pews would seat about three -hundred persons; the edifice was but a small, plain affair, with a sort -of pine board tree-box on top of it for a steeple. At the door Tom -dropped back a step and accosted a Sunday-dressed comrade: - -"Say, Billy, got a yaller ticket?" - -"Yes." - -"What'll you take for her?" - -"What'll you give?" - -"Piece of lickrish and a fish-hook." - -"Less see 'em." - -Tom exhibited. They were satisfactory, and the property changed hands. -Then Tom traded a couple of white alleys for three red tickets, and -some small trifle or other for a couple of blue ones. He waylaid other -boys as they came, and went on buying tickets of various colors ten or -fifteen minutes longer. He entered the church, now, with a swarm of -clean and noisy boys and girls, proceeded to his seat and started a -quarrel with the first boy that came handy. The teacher, a grave, -elderly man, interfered; then turned his back a moment and Tom pulled a -boy's hair in the next bench, and was absorbed in his book when the boy -turned around; stuck a pin in another boy, presently, in order to hear -him say "Ouch!" and got a new reprimand from his teacher. Tom's whole -class were of a pattern--restless, noisy, and troublesome. When they -came to recite their lessons, not one of them knew his verses -perfectly, but had to be prompted all along. However, they worried -through, and each got his reward--in small blue tickets, each with a -passage of Scripture on it; each blue ticket was pay for two verses of -the recitation. Ten blue tickets equalled a red one, and could be -exchanged for it; ten red tickets equalled a yellow one; for ten yellow -tickets the superintendent gave a very plainly bound Bible (worth forty -cents in those easy times) to the pupil. How many of my readers would -have the industry and application to memorize two thousand verses, even -for a Dore Bible? And yet Mary had acquired two Bibles in this way--it -was the patient work of two years--and a boy of German parentage had -won four or five. He once recited three thousand verses without -stopping; but the strain upon his mental faculties was too great, and -he was little better than an idiot from that day forth--a grievous -misfortune for the school, for on great occasions, before company, the -superintendent (as Tom expressed it) had always made this boy come out -and "spread himself." Only the older pupils managed to keep their -tickets and stick to their tedious work long enough to get a Bible, and -so the delivery of one of these prizes was a rare and noteworthy -circumstance; the successful pupil was so great and conspicuous for -that day that on the spot every scholar's heart was fired with a fresh -ambition that often lasted a couple of weeks. It is possible that Tom's -mental stomach had never really hungered for one of those prizes, but -unquestionably his entire being had for many a day longed for the glory -and the eclat that came with it. - -In due course the superintendent stood up in front of the pulpit, with -a closed hymn-book in his hand and his forefinger inserted between its -leaves, and commanded attention. When a Sunday-school superintendent -makes his customary little speech, a hymn-book in the hand is as -necessary as is the inevitable sheet of music in the hand of a singer -who stands forward on the platform and sings a solo at a concert ---though why, is a mystery: for neither the hymn-book nor the sheet of -music is ever referred to by the sufferer. This superintendent was a -slim creature of thirty-five, with a sandy goatee and short sandy hair; -he wore a stiff standing-collar whose upper edge almost reached his -ears and whose sharp points curved forward abreast the corners of his -mouth--a fence that compelled a straight lookout ahead, and a turning -of the whole body when a side view was required; his chin was propped -on a spreading cravat which was as broad and as long as a bank-note, -and had fringed ends; his boot toes were turned sharply up, in the -fashion of the day, like sleigh-runners--an effect patiently and -laboriously produced by the young men by sitting with their toes -pressed against a wall for hours together. Mr. Walters was very earnest -of mien, and very sincere and honest at heart; and he held sacred -things and places in such reverence, and so separated them from worldly -matters, that unconsciously to himself his Sunday-school voice had -acquired a peculiar intonation which was wholly absent on week-days. He -began after this fashion: - -"Now, children, I want you all to sit up just as straight and pretty -as you can and give me all your attention for a minute or two. There ---that is it. That is the way good little boys and girls should do. I see -one little girl who is looking out of the window--I am afraid she -thinks I am out there somewhere--perhaps up in one of the trees making -a speech to the little birds. [Applausive titter.] I want to tell you -how good it makes me feel to see so many bright, clean little faces -assembled in a place like this, learning to do right and be good." And -so forth and so on. It is not necessary to set down the rest of the -oration. It was of a pattern which does not vary, and so it is familiar -to us all. - -The latter third of the speech was marred by the resumption of fights -and other recreations among certain of the bad boys, and by fidgetings -and whisperings that extended far and wide, washing even to the bases -of isolated and incorruptible rocks like Sid and Mary. But now every -sound ceased suddenly, with the subsidence of Mr. Walters' voice, and -the conclusion of the speech was received with a burst of silent -gratitude. - -A good part of the whispering had been occasioned by an event which -was more or less rare--the entrance of visitors: lawyer Thatcher, -accompanied by a very feeble and aged man; a fine, portly, middle-aged -gentleman with iron-gray hair; and a dignified lady who was doubtless -the latter's wife. The lady was leading a child. Tom had been restless -and full of chafings and repinings; conscience-smitten, too--he could -not meet Amy Lawrence's eye, he could not brook her loving gaze. But -when he saw this small new-comer his soul was all ablaze with bliss in -a moment. The next moment he was "showing off" with all his might ---cuffing boys, pulling hair, making faces--in a word, using every art -that seemed likely to fascinate a girl and win her applause. His -exaltation had but one alloy--the memory of his humiliation in this -angel's garden--and that record in sand was fast washing out, under -the waves of happiness that were sweeping over it now. - -The visitors were given the highest seat of honor, and as soon as Mr. -Walters' speech was finished, he introduced them to the school. The -middle-aged man turned out to be a prodigious personage--no less a one -than the county judge--altogether the most august creation these -children had ever looked upon--and they wondered what kind of material -he was made of--and they half wanted to hear him roar, and were half -afraid he might, too. He was from Constantinople, twelve miles away--so -he had travelled, and seen the world--these very eyes had looked upon -the county court-house--which was said to have a tin roof. The awe -which these reflections inspired was attested by the impressive silence -and the ranks of staring eyes. This was the great Judge Thatcher, -brother of their own lawyer. Jeff Thatcher immediately went forward, to -be familiar with the great man and be envied by the school. It would -have been music to his soul to hear the whisperings: - -"Look at him, Jim! He's a going up there. Say--look! he's a going to -shake hands with him--he IS shaking hands with him! By jings, don't you -wish you was Jeff?" - -Mr. Walters fell to "showing off," with all sorts of official -bustlings and activities, giving orders, delivering judgments, -discharging directions here, there, everywhere that he could find a -target. The librarian "showed off"--running hither and thither with his -arms full of books and making a deal of the splutter and fuss that -insect authority delights in. The young lady teachers "showed off" ---bending sweetly over pupils that were lately being boxed, lifting -pretty warning fingers at bad little boys and patting good ones -lovingly. The young gentlemen teachers "showed off" with small -scoldings and other little displays of authority and fine attention to -discipline--and most of the teachers, of both sexes, found business up -at the library, by the pulpit; and it was business that frequently had -to be done over again two or three times (with much seeming vexation). -The little girls "showed off" in various ways, and the little boys -"showed off" with such diligence that the air was thick with paper wads -and the murmur of scufflings. And above it all the great man sat and -beamed a majestic judicial smile upon all the house, and warmed himself -in the sun of his own grandeur--for he was "showing off," too. - -There was only one thing wanting to make Mr. Walters' ecstasy -complete, and that was a chance to deliver a Bible-prize and exhibit a -prodigy. Several pupils had a few yellow tickets, but none had enough ---he had been around among the star pupils inquiring. He would have given -worlds, now, to have that German lad back again with a sound mind. - -And now at this moment, when hope was dead, Tom Sawyer came forward -with nine yellow tickets, nine red tickets, and ten blue ones, and -demanded a Bible. This was a thunderbolt out of a clear sky. Walters -was not expecting an application from this source for the next ten -years. But there was no getting around it--here were the certified -checks, and they were good for their face. Tom was therefore elevated -to a place with the Judge and the other elect, and the great news was -announced from headquarters. It was the most stunning surprise of the -decade, and so profound was the sensation that it lifted the new hero -up to the judicial one's altitude, and the school had two marvels to -gaze upon in place of one. The boys were all eaten up with envy--but -those that suffered the bitterest pangs were those who perceived too -late that they themselves had contributed to this hated splendor by -trading tickets to Tom for the wealth he had amassed in selling -whitewashing privileges. These despised themselves, as being the dupes -of a wily fraud, a guileful snake in the grass. - -The prize was delivered to Tom with as much effusion as the -superintendent could pump up under the circumstances; but it lacked -somewhat of the true gush, for the poor fellow's instinct taught him -that there was a mystery here that could not well bear the light, -perhaps; it was simply preposterous that this boy had warehoused two -thousand sheaves of Scriptural wisdom on his premises--a dozen would -strain his capacity, without a doubt. - -Amy Lawrence was proud and glad, and she tried to make Tom see it in -her face--but he wouldn't look. She wondered; then she was just a grain -troubled; next a dim suspicion came and went--came again; she watched; -a furtive glance told her worlds--and then her heart broke, and she was -jealous, and angry, and the tears came and she hated everybody. Tom -most of all (she thought). - -Tom was introduced to the Judge; but his tongue was tied, his breath -would hardly come, his heart quaked--partly because of the awful -greatness of the man, but mainly because he was her parent. He would -have liked to fall down and worship him, if it were in the dark. The -Judge put his hand on Tom's head and called him a fine little man, and -asked him what his name was. The boy stammered, gasped, and got it out: - -"Tom." - -"Oh, no, not Tom--it is--" - -"Thomas." - -"Ah, that's it. I thought there was more to it, maybe. That's very -well. But you've another one I daresay, and you'll tell it to me, won't -you?" - -"Tell the gentleman your other name, Thomas," said Walters, "and say -sir. You mustn't forget your manners." - -"Thomas Sawyer--sir." - -"That's it! That's a good boy. Fine boy. Fine, manly little fellow. -Two thousand verses is a great many--very, very great many. And you -never can be sorry for the trouble you took to learn them; for -knowledge is worth more than anything there is in the world; it's what -makes great men and good men; you'll be a great man and a good man -yourself, some day, Thomas, and then you'll look back and say, It's all -owing to the precious Sunday-school privileges of my boyhood--it's all -owing to my dear teachers that taught me to learn--it's all owing to -the good superintendent, who encouraged me, and watched over me, and -gave me a beautiful Bible--a splendid elegant Bible--to keep and have -it all for my own, always--it's all owing to right bringing up! That is -what you will say, Thomas--and you wouldn't take any money for those -two thousand verses--no indeed you wouldn't. And now you wouldn't mind -telling me and this lady some of the things you've learned--no, I know -you wouldn't--for we are proud of little boys that learn. Now, no -doubt you know the names of all the twelve disciples. Won't you tell us -the names of the first two that were appointed?" - -Tom was tugging at a button-hole and looking sheepish. He blushed, -now, and his eyes fell. Mr. Walters' heart sank within him. He said to -himself, it is not possible that the boy can answer the simplest -question--why DID the Judge ask him? Yet he felt obliged to speak up -and say: - -"Answer the gentleman, Thomas--don't be afraid." - -Tom still hung fire. - -"Now I know you'll tell me," said the lady. "The names of the first -two disciples were--" - -"DAVID AND GOLIAH!" - -Let us draw the curtain of charity over the rest of the scene. - - - -CHAPTER V - -ABOUT half-past ten the cracked bell of the small church began to -ring, and presently the people began to gather for the morning sermon. -The Sunday-school children distributed themselves about the house and -occupied pews with their parents, so as to be under supervision. Aunt -Polly came, and Tom and Sid and Mary sat with her--Tom being placed -next the aisle, in order that he might be as far away from the open -window and the seductive outside summer scenes as possible. The crowd -filed up the aisles: the aged and needy postmaster, who had seen better -days; the mayor and his wife--for they had a mayor there, among other -unnecessaries; the justice of the peace; the widow Douglass, fair, -smart, and forty, a generous, good-hearted soul and well-to-do, her -hill mansion the only palace in the town, and the most hospitable and -much the most lavish in the matter of festivities that St. Petersburg -could boast; the bent and venerable Major and Mrs. Ward; lawyer -Riverson, the new notable from a distance; next the belle of the -village, followed by a troop of lawn-clad and ribbon-decked young -heart-breakers; then all the young clerks in town in a body--for they -had stood in the vestibule sucking their cane-heads, a circling wall of -oiled and simpering admirers, till the last girl had run their gantlet; -and last of all came the Model Boy, Willie Mufferson, taking as heedful -care of his mother as if she were cut glass. He always brought his -mother to church, and was the pride of all the matrons. The boys all -hated him, he was so good. And besides, he had been "thrown up to them" -so much. His white handkerchief was hanging out of his pocket behind, as -usual on Sundays--accidentally. Tom had no handkerchief, and he looked -upon boys who had as snobs. - -The congregation being fully assembled, now, the bell rang once more, -to warn laggards and stragglers, and then a solemn hush fell upon the -church which was only broken by the tittering and whispering of the -choir in the gallery. The choir always tittered and whispered all -through service. There was once a church choir that was not ill-bred, -but I have forgotten where it was, now. It was a great many years ago, -and I can scarcely remember anything about it, but I think it was in -some foreign country. - -The minister gave out the hymn, and read it through with a relish, in -a peculiar style which was much admired in that part of the country. -His voice began on a medium key and climbed steadily up till it reached -a certain point, where it bore with strong emphasis upon the topmost -word and then plunged down as if from a spring-board: - - Shall I be car-ri-ed toe the skies, on flow'ry BEDS of ease, - - Whilst others fight to win the prize, and sail thro' BLOODY seas? - -He was regarded as a wonderful reader. At church "sociables" he was -always called upon to read poetry; and when he was through, the ladies -would lift up their hands and let them fall helplessly in their laps, -and "wall" their eyes, and shake their heads, as much as to say, "Words -cannot express it; it is too beautiful, TOO beautiful for this mortal -earth." - -After the hymn had been sung, the Rev. Mr. Sprague turned himself into -a bulletin-board, and read off "notices" of meetings and societies and -things till it seemed that the list would stretch out to the crack of -doom--a queer custom which is still kept up in America, even in cities, -away here in this age of abundant newspapers. Often, the less there is -to justify a traditional custom, the harder it is to get rid of it. - -And now the minister prayed. A good, generous prayer it was, and went -into details: it pleaded for the church, and the little children of the -church; for the other churches of the village; for the village itself; -for the county; for the State; for the State officers; for the United -States; for the churches of the United States; for Congress; for the -President; for the officers of the Government; for poor sailors, tossed -by stormy seas; for the oppressed millions groaning under the heel of -European monarchies and Oriental despotisms; for such as have the light -and the good tidings, and yet have not eyes to see nor ears to hear -withal; for the heathen in the far islands of the sea; and closed with -a supplication that the words he was about to speak might find grace -and favor, and be as seed sown in fertile ground, yielding in time a -grateful harvest of good. Amen. - -There was a rustling of dresses, and the standing congregation sat -down. The boy whose history this book relates did not enjoy the prayer, -he only endured it--if he even did that much. He was restive all -through it; he kept tally of the details of the prayer, unconsciously ---for he was not listening, but he knew the ground of old, and the -clergyman's regular route over it--and when a little trifle of new -matter was interlarded, his ear detected it and his whole nature -resented it; he considered additions unfair, and scoundrelly. In the -midst of the prayer a fly had lit on the back of the pew in front of -him and tortured his spirit by calmly rubbing its hands together, -embracing its head with its arms, and polishing it so vigorously that -it seemed to almost part company with the body, and the slender thread -of a neck was exposed to view; scraping its wings with its hind legs -and smoothing them to its body as if they had been coat-tails; going -through its whole toilet as tranquilly as if it knew it was perfectly -safe. As indeed it was; for as sorely as Tom's hands itched to grab for -it they did not dare--he believed his soul would be instantly destroyed -if he did such a thing while the prayer was going on. But with the -closing sentence his hand began to curve and steal forward; and the -instant the "Amen" was out the fly was a prisoner of war. His aunt -detected the act and made him let it go. - -The minister gave out his text and droned along monotonously through -an argument that was so prosy that many a head by and by began to nod ---and yet it was an argument that dealt in limitless fire and brimstone -and thinned the predestined elect down to a company so small as to be -hardly worth the saving. Tom counted the pages of the sermon; after -church he always knew how many pages there had been, but he seldom knew -anything else about the discourse. However, this time he was really -interested for a little while. The minister made a grand and moving -picture of the assembling together of the world's hosts at the -millennium when the lion and the lamb should lie down together and a -little child should lead them. But the pathos, the lesson, the moral of -the great spectacle were lost upon the boy; he only thought of the -conspicuousness of the principal character before the on-looking -nations; his face lit with the thought, and he said to himself that he -wished he could be that child, if it was a tame lion. - -Now he lapsed into suffering again, as the dry argument was resumed. -Presently he bethought him of a treasure he had and got it out. It was -a large black beetle with formidable jaws--a "pinchbug," he called it. -It was in a percussion-cap box. The first thing the beetle did was to -take him by the finger. A natural fillip followed, the beetle went -floundering into the aisle and lit on its back, and the hurt finger -went into the boy's mouth. The beetle lay there working its helpless -legs, unable to turn over. Tom eyed it, and longed for it; but it was -safe out of his reach. Other people uninterested in the sermon found -relief in the beetle, and they eyed it too. Presently a vagrant poodle -dog came idling along, sad at heart, lazy with the summer softness and -the quiet, weary of captivity, sighing for change. He spied the beetle; -the drooping tail lifted and wagged. He surveyed the prize; walked -around it; smelt at it from a safe distance; walked around it again; -grew bolder, and took a closer smell; then lifted his lip and made a -gingerly snatch at it, just missing it; made another, and another; -began to enjoy the diversion; subsided to his stomach with the beetle -between his paws, and continued his experiments; grew weary at last, -and then indifferent and absent-minded. His head nodded, and little by -little his chin descended and touched the enemy, who seized it. There -was a sharp yelp, a flirt of the poodle's head, and the beetle fell a -couple of yards away, and lit on its back once more. The neighboring -spectators shook with a gentle inward joy, several faces went behind -fans and handkerchiefs, and Tom was entirely happy. The dog looked -foolish, and probably felt so; but there was resentment in his heart, -too, and a craving for revenge. So he went to the beetle and began a -wary attack on it again; jumping at it from every point of a circle, -lighting with his fore-paws within an inch of the creature, making even -closer snatches at it with his teeth, and jerking his head till his -ears flapped again. But he grew tired once more, after a while; tried -to amuse himself with a fly but found no relief; followed an ant -around, with his nose close to the floor, and quickly wearied of that; -yawned, sighed, forgot the beetle entirely, and sat down on it. Then -there was a wild yelp of agony and the poodle went sailing up the -aisle; the yelps continued, and so did the dog; he crossed the house in -front of the altar; he flew down the other aisle; he crossed before the -doors; he clamored up the home-stretch; his anguish grew with his -progress, till presently he was but a woolly comet moving in its orbit -with the gleam and the speed of light. At last the frantic sufferer -sheered from its course, and sprang into its master's lap; he flung it -out of the window, and the voice of distress quickly thinned away and -died in the distance. - -By this time the whole church was red-faced and suffocating with -suppressed laughter, and the sermon had come to a dead standstill. The -discourse was resumed presently, but it went lame and halting, all -possibility of impressiveness being at an end; for even the gravest -sentiments were constantly being received with a smothered burst of -unholy mirth, under cover of some remote pew-back, as if the poor -parson had said a rarely facetious thing. It was a genuine relief to -the whole congregation when the ordeal was over and the benediction -pronounced. - -Tom Sawyer went home quite cheerful, thinking to himself that there -was some satisfaction about divine service when there was a bit of -variety in it. He had but one marring thought; he was willing that the -dog should play with his pinchbug, but he did not think it was upright -in him to carry it off. - - - -CHAPTER VI - -MONDAY morning found Tom Sawyer miserable. Monday morning always found -him so--because it began another week's slow suffering in school. He -generally began that day with wishing he had had no intervening -holiday, it made the going into captivity and fetters again so much -more odious. - -Tom lay thinking. Presently it occurred to him that he wished he was -sick; then he could stay home from school. Here was a vague -possibility. He canvassed his system. No ailment was found, and he -investigated again. This time he thought he could detect colicky -symptoms, and he began to encourage them with considerable hope. But -they soon grew feeble, and presently died wholly away. He reflected -further. Suddenly he discovered something. One of his upper front teeth -was loose. This was lucky; he was about to begin to groan, as a -"starter," as he called it, when it occurred to him that if he came -into court with that argument, his aunt would pull it out, and that -would hurt. So he thought he would hold the tooth in reserve for the -present, and seek further. Nothing offered for some little time, and -then he remembered hearing the doctor tell about a certain thing that -laid up a patient for two or three weeks and threatened to make him -lose a finger. So the boy eagerly drew his sore toe from under the -sheet and held it up for inspection. But now he did not know the -necessary symptoms. However, it seemed well worth while to chance it, -so he fell to groaning with considerable spirit. - -But Sid slept on unconscious. - -Tom groaned louder, and fancied that he began to feel pain in the toe. - -No result from Sid. - -Tom was panting with his exertions by this time. He took a rest and -then swelled himself up and fetched a succession of admirable groans. - -Sid snored on. - -Tom was aggravated. He said, "Sid, Sid!" and shook him. This course -worked well, and Tom began to groan again. Sid yawned, stretched, then -brought himself up on his elbow with a snort, and began to stare at -Tom. Tom went on groaning. Sid said: - -"Tom! Say, Tom!" [No response.] "Here, Tom! TOM! What is the matter, -Tom?" And he shook him and looked in his face anxiously. - -Tom moaned out: - -"Oh, don't, Sid. Don't joggle me." - -"Why, what's the matter, Tom? I must call auntie." - -"No--never mind. It'll be over by and by, maybe. Don't call anybody." - -"But I must! DON'T groan so, Tom, it's awful. How long you been this -way?" - -"Hours. Ouch! Oh, don't stir so, Sid, you'll kill me." - -"Tom, why didn't you wake me sooner? Oh, Tom, DON'T! It makes my -flesh crawl to hear you. Tom, what is the matter?" - -"I forgive you everything, Sid. [Groan.] Everything you've ever done -to me. When I'm gone--" - -"Oh, Tom, you ain't dying, are you? Don't, Tom--oh, don't. Maybe--" - -"I forgive everybody, Sid. [Groan.] Tell 'em so, Sid. And Sid, you -give my window-sash and my cat with one eye to that new girl that's -come to town, and tell her--" - -But Sid had snatched his clothes and gone. Tom was suffering in -reality, now, so handsomely was his imagination working, and so his -groans had gathered quite a genuine tone. - -Sid flew down-stairs and said: - -"Oh, Aunt Polly, come! Tom's dying!" - -"Dying!" - -"Yes'm. Don't wait--come quick!" - -"Rubbage! I don't believe it!" - -But she fled up-stairs, nevertheless, with Sid and Mary at her heels. -And her face grew white, too, and her lip trembled. When she reached -the bedside she gasped out: - -"You, Tom! Tom, what's the matter with you?" - -"Oh, auntie, I'm--" - -"What's the matter with you--what is the matter with you, child?" - -"Oh, auntie, my sore toe's mortified!" - -The old lady sank down into a chair and laughed a little, then cried a -little, then did both together. This restored her and she said: - -"Tom, what a turn you did give me. Now you shut up that nonsense and -climb out of this." - -The groans ceased and the pain vanished from the toe. The boy felt a -little foolish, and he said: - -"Aunt Polly, it SEEMED mortified, and it hurt so I never minded my -tooth at all." - -"Your tooth, indeed! What's the matter with your tooth?" - -"One of them's loose, and it aches perfectly awful." - -"There, there, now, don't begin that groaning again. Open your mouth. -Well--your tooth IS loose, but you're not going to die about that. -Mary, get me a silk thread, and a chunk of fire out of the kitchen." - -Tom said: - -"Oh, please, auntie, don't pull it out. It don't hurt any more. I wish -I may never stir if it does. Please don't, auntie. I don't want to stay -home from school." - -"Oh, you don't, don't you? So all this row was because you thought -you'd get to stay home from school and go a-fishing? Tom, Tom, I love -you so, and you seem to try every way you can to break my old heart -with your outrageousness." By this time the dental instruments were -ready. The old lady made one end of the silk thread fast to Tom's tooth -with a loop and tied the other to the bedpost. Then she seized the -chunk of fire and suddenly thrust it almost into the boy's face. The -tooth hung dangling by the bedpost, now. - -But all trials bring their compensations. As Tom wended to school -after breakfast, he was the envy of every boy he met because the gap in -his upper row of teeth enabled him to expectorate in a new and -admirable way. He gathered quite a following of lads interested in the -exhibition; and one that had cut his finger and had been a centre of -fascination and homage up to this time, now found himself suddenly -without an adherent, and shorn of his glory. His heart was heavy, and -he said with a disdain which he did not feel that it wasn't anything to -spit like Tom Sawyer; but another boy said, "Sour grapes!" and he -wandered away a dismantled hero. - -Shortly Tom came upon the juvenile pariah of the village, Huckleberry -Finn, son of the town drunkard. Huckleberry was cordially hated and -dreaded by all the mothers of the town, because he was idle and lawless -and vulgar and bad--and because all their children admired him so, and -delighted in his forbidden society, and wished they dared to be like -him. Tom was like the rest of the respectable boys, in that he envied -Huckleberry his gaudy outcast condition, and was under strict orders -not to play with him. So he played with him every time he got a chance. -Huckleberry was always dressed in the cast-off clothes of full-grown -men, and they were in perennial bloom and fluttering with rags. His hat -was a vast ruin with a wide crescent lopped out of its brim; his coat, -when he wore one, hung nearly to his heels and had the rearward buttons -far down the back; but one suspender supported his trousers; the seat -of the trousers bagged low and contained nothing, the fringed legs -dragged in the dirt when not rolled up. - -Huckleberry came and went, at his own free will. He slept on doorsteps -in fine weather and in empty hogsheads in wet; he did not have to go to -school or to church, or call any being master or obey anybody; he could -go fishing or swimming when and where he chose, and stay as long as it -suited him; nobody forbade him to fight; he could sit up as late as he -pleased; he was always the first boy that went barefoot in the spring -and the last to resume leather in the fall; he never had to wash, nor -put on clean clothes; he could swear wonderfully. In a word, everything -that goes to make life precious that boy had. So thought every -harassed, hampered, respectable boy in St. Petersburg. - -Tom hailed the romantic outcast: - -"Hello, Huckleberry!" - -"Hello yourself, and see how you like it." - -"What's that you got?" - -"Dead cat." - -"Lemme see him, Huck. My, he's pretty stiff. Where'd you get him?" - -"Bought him off'n a boy." - -"What did you give?" - -"I give a blue ticket and a bladder that I got at the slaughter-house." - -"Where'd you get the blue ticket?" - -"Bought it off'n Ben Rogers two weeks ago for a hoop-stick." - -"Say--what is dead cats good for, Huck?" - -"Good for? Cure warts with." - -"No! Is that so? I know something that's better." - -"I bet you don't. What is it?" - -"Why, spunk-water." - -"Spunk-water! I wouldn't give a dern for spunk-water." - -"You wouldn't, wouldn't you? D'you ever try it?" - -"No, I hain't. But Bob Tanner did." - -"Who told you so!" - -"Why, he told Jeff Thatcher, and Jeff told Johnny Baker, and Johnny -told Jim Hollis, and Jim told Ben Rogers, and Ben told a nigger, and -the nigger told me. There now!" - -"Well, what of it? They'll all lie. Leastways all but the nigger. I -don't know HIM. But I never see a nigger that WOULDN'T lie. Shucks! Now -you tell me how Bob Tanner done it, Huck." - -"Why, he took and dipped his hand in a rotten stump where the -rain-water was." - -"In the daytime?" - -"Certainly." - -"With his face to the stump?" - -"Yes. Least I reckon so." - -"Did he say anything?" - -"I don't reckon he did. I don't know." - -"Aha! Talk about trying to cure warts with spunk-water such a blame -fool way as that! Why, that ain't a-going to do any good. You got to go -all by yourself, to the middle of the woods, where you know there's a -spunk-water stump, and just as it's midnight you back up against the -stump and jam your hand in and say: - - 'Barley-corn, barley-corn, injun-meal shorts, - Spunk-water, spunk-water, swaller these warts,' - -and then walk away quick, eleven steps, with your eyes shut, and then -turn around three times and walk home without speaking to anybody. -Because if you speak the charm's busted." - -"Well, that sounds like a good way; but that ain't the way Bob Tanner -done." - -"No, sir, you can bet he didn't, becuz he's the wartiest boy in this -town; and he wouldn't have a wart on him if he'd knowed how to work -spunk-water. I've took off thousands of warts off of my hands that way, -Huck. I play with frogs so much that I've always got considerable many -warts. Sometimes I take 'em off with a bean." - -"Yes, bean's good. I've done that." - -"Have you? What's your way?" - -"You take and split the bean, and cut the wart so as to get some -blood, and then you put the blood on one piece of the bean and take and -dig a hole and bury it 'bout midnight at the crossroads in the dark of -the moon, and then you burn up the rest of the bean. You see that piece -that's got the blood on it will keep drawing and drawing, trying to -fetch the other piece to it, and so that helps the blood to draw the -wart, and pretty soon off she comes." - -"Yes, that's it, Huck--that's it; though when you're burying it if you -say 'Down bean; off wart; come no more to bother me!' it's better. -That's the way Joe Harper does, and he's been nearly to Coonville and -most everywheres. But say--how do you cure 'em with dead cats?" - -"Why, you take your cat and go and get in the graveyard 'long about -midnight when somebody that was wicked has been buried; and when it's -midnight a devil will come, or maybe two or three, but you can't see -'em, you can only hear something like the wind, or maybe hear 'em talk; -and when they're taking that feller away, you heave your cat after 'em -and say, 'Devil follow corpse, cat follow devil, warts follow cat, I'm -done with ye!' That'll fetch ANY wart." - -"Sounds right. D'you ever try it, Huck?" - -"No, but old Mother Hopkins told me." - -"Well, I reckon it's so, then. Becuz they say she's a witch." - -"Say! Why, Tom, I KNOW she is. She witched pap. Pap says so his own -self. He come along one day, and he see she was a-witching him, so he -took up a rock, and if she hadn't dodged, he'd a got her. Well, that -very night he rolled off'n a shed wher' he was a layin drunk, and broke -his arm." - -"Why, that's awful. How did he know she was a-witching him?" - -"Lord, pap can tell, easy. Pap says when they keep looking at you -right stiddy, they're a-witching you. Specially if they mumble. Becuz -when they mumble they're saying the Lord's Prayer backards." - -"Say, Hucky, when you going to try the cat?" - -"To-night. I reckon they'll come after old Hoss Williams to-night." - -"But they buried him Saturday. Didn't they get him Saturday night?" - -"Why, how you talk! How could their charms work till midnight?--and -THEN it's Sunday. Devils don't slosh around much of a Sunday, I don't -reckon." - -"I never thought of that. That's so. Lemme go with you?" - -"Of course--if you ain't afeard." - -"Afeard! 'Tain't likely. Will you meow?" - -"Yes--and you meow back, if you get a chance. Last time, you kep' me -a-meowing around till old Hays went to throwing rocks at me and says -'Dern that cat!' and so I hove a brick through his window--but don't -you tell." - -"I won't. I couldn't meow that night, becuz auntie was watching me, -but I'll meow this time. Say--what's that?" - -"Nothing but a tick." - -"Where'd you get him?" - -"Out in the woods." - -"What'll you take for him?" - -"I don't know. I don't want to sell him." - -"All right. It's a mighty small tick, anyway." - -"Oh, anybody can run a tick down that don't belong to them. I'm -satisfied with it. It's a good enough tick for me." - -"Sho, there's ticks a plenty. I could have a thousand of 'em if I -wanted to." - -"Well, why don't you? Becuz you know mighty well you can't. This is a -pretty early tick, I reckon. It's the first one I've seen this year." - -"Say, Huck--I'll give you my tooth for him." - -"Less see it." - -Tom got out a bit of paper and carefully unrolled it. Huckleberry -viewed it wistfully. The temptation was very strong. At last he said: - -"Is it genuwyne?" - -Tom lifted his lip and showed the vacancy. - -"Well, all right," said Huckleberry, "it's a trade." - -Tom enclosed the tick in the percussion-cap box that had lately been -the pinchbug's prison, and the boys separated, each feeling wealthier -than before. - -When Tom reached the little isolated frame schoolhouse, he strode in -briskly, with the manner of one who had come with all honest speed. -He hung his hat on a peg and flung himself into his seat with -business-like alacrity. The master, throned on high in his great -splint-bottom arm-chair, was dozing, lulled by the drowsy hum of study. -The interruption roused him. - -"Thomas Sawyer!" - -Tom knew that when his name was pronounced in full, it meant trouble. - -"Sir!" - -"Come up here. Now, sir, why are you late again, as usual?" - -Tom was about to take refuge in a lie, when he saw two long tails of -yellow hair hanging down a back that he recognized by the electric -sympathy of love; and by that form was THE ONLY VACANT PLACE on the -girls' side of the schoolhouse. He instantly said: - -"I STOPPED TO TALK WITH HUCKLEBERRY FINN!" - -The master's pulse stood still, and he stared helplessly. The buzz of -study ceased. The pupils wondered if this foolhardy boy had lost his -mind. The master said: - -"You--you did what?" - -"Stopped to talk with Huckleberry Finn." - -There was no mistaking the words. - -"Thomas Sawyer, this is the most astounding confession I have ever -listened to. No mere ferule will answer for this offence. Take off your -jacket." - -The master's arm performed until it was tired and the stock of -switches notably diminished. Then the order followed: - -"Now, sir, go and sit with the girls! And let this be a warning to you." - -The titter that rippled around the room appeared to abash the boy, but -in reality that result was caused rather more by his worshipful awe of -his unknown idol and the dread pleasure that lay in his high good -fortune. He sat down upon the end of the pine bench and the girl -hitched herself away from him with a toss of her head. Nudges and winks -and whispers traversed the room, but Tom sat still, with his arms upon -the long, low desk before him, and seemed to study his book. - -By and by attention ceased from him, and the accustomed school murmur -rose upon the dull air once more. Presently the boy began to steal -furtive glances at the girl. She observed it, "made a mouth" at him and -gave him the back of her head for the space of a minute. When she -cautiously faced around again, a peach lay before her. She thrust it -away. Tom gently put it back. She thrust it away again, but with less -animosity. Tom patiently returned it to its place. Then she let it -remain. Tom scrawled on his slate, "Please take it--I got more." The -girl glanced at the words, but made no sign. Now the boy began to draw -something on the slate, hiding his work with his left hand. For a time -the girl refused to notice; but her human curiosity presently began to -manifest itself by hardly perceptible signs. The boy worked on, -apparently unconscious. The girl made a sort of noncommittal attempt to -see, but the boy did not betray that he was aware of it. At last she -gave in and hesitatingly whispered: - -"Let me see it." - -Tom partly uncovered a dismal caricature of a house with two gable -ends to it and a corkscrew of smoke issuing from the chimney. Then the -girl's interest began to fasten itself upon the work and she forgot -everything else. When it was finished, she gazed a moment, then -whispered: - -"It's nice--make a man." - -The artist erected a man in the front yard, that resembled a derrick. -He could have stepped over the house; but the girl was not -hypercritical; she was satisfied with the monster, and whispered: - -"It's a beautiful man--now make me coming along." - -Tom drew an hour-glass with a full moon and straw limbs to it and -armed the spreading fingers with a portentous fan. The girl said: - -"It's ever so nice--I wish I could draw." - -"It's easy," whispered Tom, "I'll learn you." - -"Oh, will you? When?" - -"At noon. Do you go home to dinner?" - -"I'll stay if you will." - -"Good--that's a whack. What's your name?" - -"Becky Thatcher. What's yours? Oh, I know. It's Thomas Sawyer." - -"That's the name they lick me by. I'm Tom when I'm good. You call me -Tom, will you?" - -"Yes." - -Now Tom began to scrawl something on the slate, hiding the words from -the girl. But she was not backward this time. She begged to see. Tom -said: - -"Oh, it ain't anything." - -"Yes it is." - -"No it ain't. You don't want to see." - -"Yes I do, indeed I do. Please let me." - -"You'll tell." - -"No I won't--deed and deed and double deed won't." - -"You won't tell anybody at all? Ever, as long as you live?" - -"No, I won't ever tell ANYbody. Now let me." - -"Oh, YOU don't want to see!" - -"Now that you treat me so, I WILL see." And she put her small hand -upon his and a little scuffle ensued, Tom pretending to resist in -earnest but letting his hand slip by degrees till these words were -revealed: "I LOVE YOU." - -"Oh, you bad thing!" And she hit his hand a smart rap, but reddened -and looked pleased, nevertheless. - -Just at this juncture the boy felt a slow, fateful grip closing on his -ear, and a steady lifting impulse. In that wise he was borne across the -house and deposited in his own seat, under a peppering fire of giggles -from the whole school. Then the master stood over him during a few -awful moments, and finally moved away to his throne without saying a -word. But although Tom's ear tingled, his heart was jubilant. - -As the school quieted down Tom made an honest effort to study, but the -turmoil within him was too great. In turn he took his place in the -reading class and made a botch of it; then in the geography class and -turned lakes into mountains, mountains into rivers, and rivers into -continents, till chaos was come again; then in the spelling class, and -got "turned down," by a succession of mere baby words, till he brought -up at the foot and yielded up the pewter medal which he had worn with -ostentation for months. - - - -CHAPTER VII - -THE harder Tom tried to fasten his mind on his book, the more his -ideas wandered. So at last, with a sigh and a yawn, he gave it up. It -seemed to him that the noon recess would never come. The air was -utterly dead. There was not a breath stirring. It was the sleepiest of -sleepy days. The drowsing murmur of the five and twenty studying -scholars soothed the soul like the spell that is in the murmur of bees. -Away off in the flaming sunshine, Cardiff Hill lifted its soft green -sides through a shimmering veil of heat, tinted with the purple of -distance; a few birds floated on lazy wing high in the air; no other -living thing was visible but some cows, and they were asleep. Tom's -heart ached to be free, or else to have something of interest to do to -pass the dreary time. His hand wandered into his pocket and his face -lit up with a glow of gratitude that was prayer, though he did not know -it. Then furtively the percussion-cap box came out. He released the -tick and put him on the long flat desk. The creature probably glowed -with a gratitude that amounted to prayer, too, at this moment, but it -was premature: for when he started thankfully to travel off, Tom turned -him aside with a pin and made him take a new direction. - -Tom's bosom friend sat next him, suffering just as Tom had been, and -now he was deeply and gratefully interested in this entertainment in an -instant. This bosom friend was Joe Harper. The two boys were sworn -friends all the week, and embattled enemies on Saturdays. Joe took a -pin out of his lapel and began to assist in exercising the prisoner. -The sport grew in interest momently. Soon Tom said that they were -interfering with each other, and neither getting the fullest benefit of -the tick. So he put Joe's slate on the desk and drew a line down the -middle of it from top to bottom. - -"Now," said he, "as long as he is on your side you can stir him up and -I'll let him alone; but if you let him get away and get on my side, -you're to leave him alone as long as I can keep him from crossing over." - -"All right, go ahead; start him up." - -The tick escaped from Tom, presently, and crossed the equator. Joe -harassed him awhile, and then he got away and crossed back again. This -change of base occurred often. While one boy was worrying the tick with -absorbing interest, the other would look on with interest as strong, -the two heads bowed together over the slate, and the two souls dead to -all things else. At last luck seemed to settle and abide with Joe. The -tick tried this, that, and the other course, and got as excited and as -anxious as the boys themselves, but time and again just as he would -have victory in his very grasp, so to speak, and Tom's fingers would be -twitching to begin, Joe's pin would deftly head him off, and keep -possession. At last Tom could stand it no longer. The temptation was -too strong. So he reached out and lent a hand with his pin. Joe was -angry in a moment. Said he: - -"Tom, you let him alone." - -"I only just want to stir him up a little, Joe." - -"No, sir, it ain't fair; you just let him alone." - -"Blame it, I ain't going to stir him much." - -"Let him alone, I tell you." - -"I won't!" - -"You shall--he's on my side of the line." - -"Look here, Joe Harper, whose is that tick?" - -"I don't care whose tick he is--he's on my side of the line, and you -sha'n't touch him." - -"Well, I'll just bet I will, though. He's my tick and I'll do what I -blame please with him, or die!" - -A tremendous whack came down on Tom's shoulders, and its duplicate on -Joe's; and for the space of two minutes the dust continued to fly from -the two jackets and the whole school to enjoy it. The boys had been too -absorbed to notice the hush that had stolen upon the school awhile -before when the master came tiptoeing down the room and stood over -them. He had contemplated a good part of the performance before he -contributed his bit of variety to it. - -When school broke up at noon, Tom flew to Becky Thatcher, and -whispered in her ear: - -"Put on your bonnet and let on you're going home; and when you get to -the corner, give the rest of 'em the slip, and turn down through the -lane and come back. I'll go the other way and come it over 'em the same -way." - -So the one went off with one group of scholars, and the other with -another. In a little while the two met at the bottom of the lane, and -when they reached the school they had it all to themselves. Then they -sat together, with a slate before them, and Tom gave Becky the pencil -and held her hand in his, guiding it, and so created another surprising -house. When the interest in art began to wane, the two fell to talking. -Tom was swimming in bliss. He said: - -"Do you love rats?" - -"No! I hate them!" - -"Well, I do, too--LIVE ones. But I mean dead ones, to swing round your -head with a string." - -"No, I don't care for rats much, anyway. What I like is chewing-gum." - -"Oh, I should say so! I wish I had some now." - -"Do you? I've got some. I'll let you chew it awhile, but you must give -it back to me." - -That was agreeable, so they chewed it turn about, and dangled their -legs against the bench in excess of contentment. - -"Was you ever at a circus?" said Tom. - -"Yes, and my pa's going to take me again some time, if I'm good." - -"I been to the circus three or four times--lots of times. Church ain't -shucks to a circus. There's things going on at a circus all the time. -I'm going to be a clown in a circus when I grow up." - -"Oh, are you! That will be nice. They're so lovely, all spotted up." - -"Yes, that's so. And they get slathers of money--most a dollar a day, -Ben Rogers says. Say, Becky, was you ever engaged?" - -"What's that?" - -"Why, engaged to be married." - -"No." - -"Would you like to?" - -"I reckon so. I don't know. What is it like?" - -"Like? Why it ain't like anything. You only just tell a boy you won't -ever have anybody but him, ever ever ever, and then you kiss and that's -all. Anybody can do it." - -"Kiss? What do you kiss for?" - -"Why, that, you know, is to--well, they always do that." - -"Everybody?" - -"Why, yes, everybody that's in love with each other. Do you remember -what I wrote on the slate?" - -"Ye--yes." - -"What was it?" - -"I sha'n't tell you." - -"Shall I tell YOU?" - -"Ye--yes--but some other time." - -"No, now." - -"No, not now--to-morrow." - -"Oh, no, NOW. Please, Becky--I'll whisper it, I'll whisper it ever so -easy." - -Becky hesitating, Tom took silence for consent, and passed his arm -about her waist and whispered the tale ever so softly, with his mouth -close to her ear. And then he added: - -"Now you whisper it to me--just the same." - -She resisted, for a while, and then said: - -"You turn your face away so you can't see, and then I will. But you -mustn't ever tell anybody--WILL you, Tom? Now you won't, WILL you?" - -"No, indeed, indeed I won't. Now, Becky." - -He turned his face away. She bent timidly around till her breath -stirred his curls and whispered, "I--love--you!" - -Then she sprang away and ran around and around the desks and benches, -with Tom after her, and took refuge in a corner at last, with her -little white apron to her face. Tom clasped her about her neck and -pleaded: - -"Now, Becky, it's all done--all over but the kiss. Don't you be afraid -of that--it ain't anything at all. Please, Becky." And he tugged at her -apron and the hands. - -By and by she gave up, and let her hands drop; her face, all glowing -with the struggle, came up and submitted. Tom kissed the red lips and -said: - -"Now it's all done, Becky. And always after this, you know, you ain't -ever to love anybody but me, and you ain't ever to marry anybody but -me, ever never and forever. Will you?" - -"No, I'll never love anybody but you, Tom, and I'll never marry -anybody but you--and you ain't to ever marry anybody but me, either." - -"Certainly. Of course. That's PART of it. And always coming to school -or when we're going home, you're to walk with me, when there ain't -anybody looking--and you choose me and I choose you at parties, because -that's the way you do when you're engaged." - -"It's so nice. I never heard of it before." - -"Oh, it's ever so gay! Why, me and Amy Lawrence--" - -The big eyes told Tom his blunder and he stopped, confused. - -"Oh, Tom! Then I ain't the first you've ever been engaged to!" - -The child began to cry. Tom said: - -"Oh, don't cry, Becky, I don't care for her any more." - -"Yes, you do, Tom--you know you do." - -Tom tried to put his arm about her neck, but she pushed him away and -turned her face to the wall, and went on crying. Tom tried again, with -soothing words in his mouth, and was repulsed again. Then his pride was -up, and he strode away and went outside. He stood about, restless and -uneasy, for a while, glancing at the door, every now and then, hoping -she would repent and come to find him. But she did not. Then he began -to feel badly and fear that he was in the wrong. It was a hard struggle -with him to make new advances, now, but he nerved himself to it and -entered. She was still standing back there in the corner, sobbing, with -her face to the wall. Tom's heart smote him. He went to her and stood a -moment, not knowing exactly how to proceed. Then he said hesitatingly: - -"Becky, I--I don't care for anybody but you." - -No reply--but sobs. - -"Becky"--pleadingly. "Becky, won't you say something?" - -More sobs. - -Tom got out his chiefest jewel, a brass knob from the top of an -andiron, and passed it around her so that she could see it, and said: - -"Please, Becky, won't you take it?" - -She struck it to the floor. Then Tom marched out of the house and over -the hills and far away, to return to school no more that day. Presently -Becky began to suspect. She ran to the door; he was not in sight; she -flew around to the play-yard; he was not there. Then she called: - -"Tom! Come back, Tom!" - -She listened intently, but there was no answer. She had no companions -but silence and loneliness. So she sat down to cry again and upbraid -herself; and by this time the scholars began to gather again, and she -had to hide her griefs and still her broken heart and take up the cross -of a long, dreary, aching afternoon, with none among the strangers -about her to exchange sorrows with. - - - -CHAPTER VIII - -TOM dodged hither and thither through lanes until he was well out of -the track of returning scholars, and then fell into a moody jog. He -crossed a small "branch" two or three times, because of a prevailing -juvenile superstition that to cross water baffled pursuit. Half an hour -later he was disappearing behind the Douglas mansion on the summit of -Cardiff Hill, and the schoolhouse was hardly distinguishable away off -in the valley behind him. He entered a dense wood, picked his pathless -way to the centre of it, and sat down on a mossy spot under a spreading -oak. There was not even a zephyr stirring; the dead noonday heat had -even stilled the songs of the birds; nature lay in a trance that was -broken by no sound but the occasional far-off hammering of a -woodpecker, and this seemed to render the pervading silence and sense -of loneliness the more profound. The boy's soul was steeped in -melancholy; his feelings were in happy accord with his surroundings. He -sat long with his elbows on his knees and his chin in his hands, -meditating. It seemed to him that life was but a trouble, at best, and -he more than half envied Jimmy Hodges, so lately released; it must be -very peaceful, he thought, to lie and slumber and dream forever and -ever, with the wind whispering through the trees and caressing the -grass and the flowers over the grave, and nothing to bother and grieve -about, ever any more. If he only had a clean Sunday-school record he -could be willing to go, and be done with it all. Now as to this girl. -What had he done? Nothing. He had meant the best in the world, and been -treated like a dog--like a very dog. She would be sorry some day--maybe -when it was too late. Ah, if he could only die TEMPORARILY! - -But the elastic heart of youth cannot be compressed into one -constrained shape long at a time. Tom presently began to drift -insensibly back into the concerns of this life again. What if he turned -his back, now, and disappeared mysteriously? What if he went away--ever -so far away, into unknown countries beyond the seas--and never came -back any more! How would she feel then! The idea of being a clown -recurred to him now, only to fill him with disgust. For frivolity and -jokes and spotted tights were an offense, when they intruded themselves -upon a spirit that was exalted into the vague august realm of the -romantic. No, he would be a soldier, and return after long years, all -war-worn and illustrious. No--better still, he would join the Indians, -and hunt buffaloes and go on the warpath in the mountain ranges and the -trackless great plains of the Far West, and away in the future come -back a great chief, bristling with feathers, hideous with paint, and -prance into Sunday-school, some drowsy summer morning, with a -bloodcurdling war-whoop, and sear the eyeballs of all his companions -with unappeasable envy. But no, there was something gaudier even than -this. He would be a pirate! That was it! NOW his future lay plain -before him, and glowing with unimaginable splendor. How his name would -fill the world, and make people shudder! How gloriously he would go -plowing the dancing seas, in his long, low, black-hulled racer, the -Spirit of the Storm, with his grisly flag flying at the fore! And at -the zenith of his fame, how he would suddenly appear at the old village -and stalk into church, brown and weather-beaten, in his black velvet -doublet and trunks, his great jack-boots, his crimson sash, his belt -bristling with horse-pistols, his crime-rusted cutlass at his side, his -slouch hat with waving plumes, his black flag unfurled, with the skull -and crossbones on it, and hear with swelling ecstasy the whisperings, -"It's Tom Sawyer the Pirate!--the Black Avenger of the Spanish Main!" - -Yes, it was settled; his career was determined. He would run away from -home and enter upon it. He would start the very next morning. Therefore -he must now begin to get ready. He would collect his resources -together. He went to a rotten log near at hand and began to dig under -one end of it with his Barlow knife. He soon struck wood that sounded -hollow. He put his hand there and uttered this incantation impressively: - -"What hasn't come here, come! What's here, stay here!" - -Then he scraped away the dirt, and exposed a pine shingle. He took it -up and disclosed a shapely little treasure-house whose bottom and sides -were of shingles. In it lay a marble. Tom's astonishment was boundless! -He scratched his head with a perplexed air, and said: - -"Well, that beats anything!" - -Then he tossed the marble away pettishly, and stood cogitating. The -truth was, that a superstition of his had failed, here, which he and -all his comrades had always looked upon as infallible. If you buried a -marble with certain necessary incantations, and left it alone a -fortnight, and then opened the place with the incantation he had just -used, you would find that all the marbles you had ever lost had -gathered themselves together there, meantime, no matter how widely they -had been separated. But now, this thing had actually and unquestionably -failed. Tom's whole structure of faith was shaken to its foundations. -He had many a time heard of this thing succeeding but never of its -failing before. It did not occur to him that he had tried it several -times before, himself, but could never find the hiding-places -afterward. He puzzled over the matter some time, and finally decided -that some witch had interfered and broken the charm. He thought he -would satisfy himself on that point; so he searched around till he -found a small sandy spot with a little funnel-shaped depression in it. -He laid himself down and put his mouth close to this depression and -called-- - -"Doodle-bug, doodle-bug, tell me what I want to know! Doodle-bug, -doodle-bug, tell me what I want to know!" - -The sand began to work, and presently a small black bug appeared for a -second and then darted under again in a fright. - -"He dasn't tell! So it WAS a witch that done it. I just knowed it." - -He well knew the futility of trying to contend against witches, so he -gave up discouraged. But it occurred to him that he might as well have -the marble he had just thrown away, and therefore he went and made a -patient search for it. But he could not find it. Now he went back to -his treasure-house and carefully placed himself just as he had been -standing when he tossed the marble away; then he took another marble -from his pocket and tossed it in the same way, saying: - -"Brother, go find your brother!" - -He watched where it stopped, and went there and looked. But it must -have fallen short or gone too far; so he tried twice more. The last -repetition was successful. The two marbles lay within a foot of each -other. - -Just here the blast of a toy tin trumpet came faintly down the green -aisles of the forest. Tom flung off his jacket and trousers, turned a -suspender into a belt, raked away some brush behind the rotten log, -disclosing a rude bow and arrow, a lath sword and a tin trumpet, and in -a moment had seized these things and bounded away, barelegged, with -fluttering shirt. He presently halted under a great elm, blew an -answering blast, and then began to tiptoe and look warily out, this way -and that. He said cautiously--to an imaginary company: - -"Hold, my merry men! Keep hid till I blow." - -Now appeared Joe Harper, as airily clad and elaborately armed as Tom. -Tom called: - -"Hold! Who comes here into Sherwood Forest without my pass?" - -"Guy of Guisborne wants no man's pass. Who art thou that--that--" - -"Dares to hold such language," said Tom, prompting--for they talked -"by the book," from memory. - -"Who art thou that dares to hold such language?" - -"I, indeed! I am Robin Hood, as thy caitiff carcase soon shall know." - -"Then art thou indeed that famous outlaw? Right gladly will I dispute -with thee the passes of the merry wood. Have at thee!" - -They took their lath swords, dumped their other traps on the ground, -struck a fencing attitude, foot to foot, and began a grave, careful -combat, "two up and two down." Presently Tom said: - -"Now, if you've got the hang, go it lively!" - -So they "went it lively," panting and perspiring with the work. By and -by Tom shouted: - -"Fall! fall! Why don't you fall?" - -"I sha'n't! Why don't you fall yourself? You're getting the worst of -it." - -"Why, that ain't anything. I can't fall; that ain't the way it is in -the book. The book says, 'Then with one back-handed stroke he slew poor -Guy of Guisborne.' You're to turn around and let me hit you in the -back." - -There was no getting around the authorities, so Joe turned, received -the whack and fell. - -"Now," said Joe, getting up, "you got to let me kill YOU. That's fair." - -"Why, I can't do that, it ain't in the book." - -"Well, it's blamed mean--that's all." - -"Well, say, Joe, you can be Friar Tuck or Much the miller's son, and -lam me with a quarter-staff; or I'll be the Sheriff of Nottingham and -you be Robin Hood a little while and kill me." - -This was satisfactory, and so these adventures were carried out. Then -Tom became Robin Hood again, and was allowed by the treacherous nun to -bleed his strength away through his neglected wound. And at last Joe, -representing a whole tribe of weeping outlaws, dragged him sadly forth, -gave his bow into his feeble hands, and Tom said, "Where this arrow -falls, there bury poor Robin Hood under the greenwood tree." Then he -shot the arrow and fell back and would have died, but he lit on a -nettle and sprang up too gaily for a corpse. - -The boys dressed themselves, hid their accoutrements, and went off -grieving that there were no outlaws any more, and wondering what modern -civilization could claim to have done to compensate for their loss. -They said they would rather be outlaws a year in Sherwood Forest than -President of the United States forever. - - - -CHAPTER IX - -AT half-past nine, that night, Tom and Sid were sent to bed, as usual. -They said their prayers, and Sid was soon asleep. Tom lay awake and -waited, in restless impatience. When it seemed to him that it must be -nearly daylight, he heard the clock strike ten! This was despair. He -would have tossed and fidgeted, as his nerves demanded, but he was -afraid he might wake Sid. So he lay still, and stared up into the dark. -Everything was dismally still. By and by, out of the stillness, little, -scarcely perceptible noises began to emphasize themselves. The ticking -of the clock began to bring itself into notice. Old beams began to -crack mysteriously. The stairs creaked faintly. Evidently spirits were -abroad. A measured, muffled snore issued from Aunt Polly's chamber. And -now the tiresome chirping of a cricket that no human ingenuity could -locate, began. Next the ghastly ticking of a deathwatch in the wall at -the bed's head made Tom shudder--it meant that somebody's days were -numbered. Then the howl of a far-off dog rose on the night air, and was -answered by a fainter howl from a remoter distance. Tom was in an -agony. At last he was satisfied that time had ceased and eternity -begun; he began to doze, in spite of himself; the clock chimed eleven, -but he did not hear it. And then there came, mingling with his -half-formed dreams, a most melancholy caterwauling. The raising of a -neighboring window disturbed him. A cry of "Scat! you devil!" and the -crash of an empty bottle against the back of his aunt's woodshed -brought him wide awake, and a single minute later he was dressed and -out of the window and creeping along the roof of the "ell" on all -fours. He "meow'd" with caution once or twice, as he went; then jumped -to the roof of the woodshed and thence to the ground. Huckleberry Finn -was there, with his dead cat. The boys moved off and disappeared in the -gloom. At the end of half an hour they were wading through the tall -grass of the graveyard. - -It was a graveyard of the old-fashioned Western kind. It was on a -hill, about a mile and a half from the village. It had a crazy board -fence around it, which leaned inward in places, and outward the rest of -the time, but stood upright nowhere. Grass and weeds grew rank over the -whole cemetery. All the old graves were sunken in, there was not a -tombstone on the place; round-topped, worm-eaten boards staggered over -the graves, leaning for support and finding none. "Sacred to the memory -of" So-and-So had been painted on them once, but it could no longer -have been read, on the most of them, now, even if there had been light. - -A faint wind moaned through the trees, and Tom feared it might be the -spirits of the dead, complaining at being disturbed. The boys talked -little, and only under their breath, for the time and the place and the -pervading solemnity and silence oppressed their spirits. They found the -sharp new heap they were seeking, and ensconced themselves within the -protection of three great elms that grew in a bunch within a few feet -of the grave. - -Then they waited in silence for what seemed a long time. The hooting -of a distant owl was all the sound that troubled the dead stillness. -Tom's reflections grew oppressive. He must force some talk. So he said -in a whisper: - -"Hucky, do you believe the dead people like it for us to be here?" - -Huckleberry whispered: - -"I wisht I knowed. It's awful solemn like, AIN'T it?" - -"I bet it is." - -There was a considerable pause, while the boys canvassed this matter -inwardly. Then Tom whispered: - -"Say, Hucky--do you reckon Hoss Williams hears us talking?" - -"O' course he does. Least his sperrit does." - -Tom, after a pause: - -"I wish I'd said Mister Williams. But I never meant any harm. -Everybody calls him Hoss." - -"A body can't be too partic'lar how they talk 'bout these-yer dead -people, Tom." - -This was a damper, and conversation died again. - -Presently Tom seized his comrade's arm and said: - -"Sh!" - -"What is it, Tom?" And the two clung together with beating hearts. - -"Sh! There 'tis again! Didn't you hear it?" - -"I--" - -"There! Now you hear it." - -"Lord, Tom, they're coming! They're coming, sure. What'll we do?" - -"I dono. Think they'll see us?" - -"Oh, Tom, they can see in the dark, same as cats. I wisht I hadn't -come." - -"Oh, don't be afeard. I don't believe they'll bother us. We ain't -doing any harm. If we keep perfectly still, maybe they won't notice us -at all." - -"I'll try to, Tom, but, Lord, I'm all of a shiver." - -"Listen!" - -The boys bent their heads together and scarcely breathed. A muffled -sound of voices floated up from the far end of the graveyard. - -"Look! See there!" whispered Tom. "What is it?" - -"It's devil-fire. Oh, Tom, this is awful." - -Some vague figures approached through the gloom, swinging an -old-fashioned tin lantern that freckled the ground with innumerable -little spangles of light. Presently Huckleberry whispered with a -shudder: - -"It's the devils sure enough. Three of 'em! Lordy, Tom, we're goners! -Can you pray?" - -"I'll try, but don't you be afeard. They ain't going to hurt us. 'Now -I lay me down to sleep, I--'" - -"Sh!" - -"What is it, Huck?" - -"They're HUMANS! One of 'em is, anyway. One of 'em's old Muff Potter's -voice." - -"No--'tain't so, is it?" - -"I bet I know it. Don't you stir nor budge. He ain't sharp enough to -notice us. Drunk, the same as usual, likely--blamed old rip!" - -"All right, I'll keep still. Now they're stuck. Can't find it. Here -they come again. Now they're hot. Cold again. Hot again. Red hot! -They're p'inted right, this time. Say, Huck, I know another o' them -voices; it's Injun Joe." - -"That's so--that murderin' half-breed! I'd druther they was devils a -dern sight. What kin they be up to?" - -The whisper died wholly out, now, for the three men had reached the -grave and stood within a few feet of the boys' hiding-place. - -"Here it is," said the third voice; and the owner of it held the -lantern up and revealed the face of young Doctor Robinson. - -Potter and Injun Joe were carrying a handbarrow with a rope and a -couple of shovels on it. They cast down their load and began to open -the grave. The doctor put the lantern at the head of the grave and came -and sat down with his back against one of the elm trees. He was so -close the boys could have touched him. - -"Hurry, men!" he said, in a low voice; "the moon might come out at any -moment." - -They growled a response and went on digging. For some time there was -no noise but the grating sound of the spades discharging their freight -of mould and gravel. It was very monotonous. Finally a spade struck -upon the coffin with a dull woody accent, and within another minute or -two the men had hoisted it out on the ground. They pried off the lid -with their shovels, got out the body and dumped it rudely on the -ground. The moon drifted from behind the clouds and exposed the pallid -face. The barrow was got ready and the corpse placed on it, covered -with a blanket, and bound to its place with the rope. Potter took out a -large spring-knife and cut off the dangling end of the rope and then -said: - -"Now the cussed thing's ready, Sawbones, and you'll just out with -another five, or here she stays." - -"That's the talk!" said Injun Joe. - -"Look here, what does this mean?" said the doctor. "You required your -pay in advance, and I've paid you." - -"Yes, and you done more than that," said Injun Joe, approaching the -doctor, who was now standing. "Five years ago you drove me away from -your father's kitchen one night, when I come to ask for something to -eat, and you said I warn't there for any good; and when I swore I'd get -even with you if it took a hundred years, your father had me jailed for -a vagrant. Did you think I'd forget? The Injun blood ain't in me for -nothing. And now I've GOT you, and you got to SETTLE, you know!" - -He was threatening the doctor, with his fist in his face, by this -time. The doctor struck out suddenly and stretched the ruffian on the -ground. Potter dropped his knife, and exclaimed: - -"Here, now, don't you hit my pard!" and the next moment he had -grappled with the doctor and the two were struggling with might and -main, trampling the grass and tearing the ground with their heels. -Injun Joe sprang to his feet, his eyes flaming with passion, snatched -up Potter's knife, and went creeping, catlike and stooping, round and -round about the combatants, seeking an opportunity. All at once the -doctor flung himself free, seized the heavy headboard of Williams' -grave and felled Potter to the earth with it--and in the same instant -the half-breed saw his chance and drove the knife to the hilt in the -young man's breast. He reeled and fell partly upon Potter, flooding him -with his blood, and in the same moment the clouds blotted out the -dreadful spectacle and the two frightened boys went speeding away in -the dark. - -Presently, when the moon emerged again, Injun Joe was standing over -the two forms, contemplating them. The doctor murmured inarticulately, -gave a long gasp or two and was still. The half-breed muttered: - -"THAT score is settled--damn you." - -Then he robbed the body. After which he put the fatal knife in -Potter's open right hand, and sat down on the dismantled coffin. Three ---four--five minutes passed, and then Potter began to stir and moan. His -hand closed upon the knife; he raised it, glanced at it, and let it -fall, with a shudder. Then he sat up, pushing the body from him, and -gazed at it, and then around him, confusedly. His eyes met Joe's. - -"Lord, how is this, Joe?" he said. - -"It's a dirty business," said Joe, without moving. - -"What did you do it for?" - -"I! I never done it!" - -"Look here! That kind of talk won't wash." - -Potter trembled and grew white. - -"I thought I'd got sober. I'd no business to drink to-night. But it's -in my head yet--worse'n when we started here. I'm all in a muddle; -can't recollect anything of it, hardly. Tell me, Joe--HONEST, now, old -feller--did I do it? Joe, I never meant to--'pon my soul and honor, I -never meant to, Joe. Tell me how it was, Joe. Oh, it's awful--and him -so young and promising." - -"Why, you two was scuffling, and he fetched you one with the headboard -and you fell flat; and then up you come, all reeling and staggering -like, and snatched the knife and jammed it into him, just as he fetched -you another awful clip--and here you've laid, as dead as a wedge til -now." - -"Oh, I didn't know what I was a-doing. I wish I may die this minute if -I did. It was all on account of the whiskey and the excitement, I -reckon. I never used a weepon in my life before, Joe. I've fought, but -never with weepons. They'll all say that. Joe, don't tell! Say you -won't tell, Joe--that's a good feller. I always liked you, Joe, and -stood up for you, too. Don't you remember? You WON'T tell, WILL you, -Joe?" And the poor creature dropped on his knees before the stolid -murderer, and clasped his appealing hands. - -"No, you've always been fair and square with me, Muff Potter, and I -won't go back on you. There, now, that's as fair as a man can say." - -"Oh, Joe, you're an angel. I'll bless you for this the longest day I -live." And Potter began to cry. - -"Come, now, that's enough of that. This ain't any time for blubbering. -You be off yonder way and I'll go this. Move, now, and don't leave any -tracks behind you." - -Potter started on a trot that quickly increased to a run. The -half-breed stood looking after him. He muttered: - -"If he's as much stunned with the lick and fuddled with the rum as he -had the look of being, he won't think of the knife till he's gone so -far he'll be afraid to come back after it to such a place by himself ---chicken-heart!" - -Two or three minutes later the murdered man, the blanketed corpse, the -lidless coffin, and the open grave were under no inspection but the -moon's. The stillness was complete again, too. - - - -CHAPTER X - -THE two boys flew on and on, toward the village, speechless with -horror. They glanced backward over their shoulders from time to time, -apprehensively, as if they feared they might be followed. Every stump -that started up in their path seemed a man and an enemy, and made them -catch their breath; and as they sped by some outlying cottages that lay -near the village, the barking of the aroused watch-dogs seemed to give -wings to their feet. - -"If we can only get to the old tannery before we break down!" -whispered Tom, in short catches between breaths. "I can't stand it much -longer." - -Huckleberry's hard pantings were his only reply, and the boys fixed -their eyes on the goal of their hopes and bent to their work to win it. -They gained steadily on it, and at last, breast to breast, they burst -through the open door and fell grateful and exhausted in the sheltering -shadows beyond. By and by their pulses slowed down, and Tom whispered: - -"Huckleberry, what do you reckon'll come of this?" - -"If Doctor Robinson dies, I reckon hanging'll come of it." - -"Do you though?" - -"Why, I KNOW it, Tom." - -Tom thought a while, then he said: - -"Who'll tell? We?" - -"What are you talking about? S'pose something happened and Injun Joe -DIDN'T hang? Why, he'd kill us some time or other, just as dead sure as -we're a laying here." - -"That's just what I was thinking to myself, Huck." - -"If anybody tells, let Muff Potter do it, if he's fool enough. He's -generally drunk enough." - -Tom said nothing--went on thinking. Presently he whispered: - -"Huck, Muff Potter don't know it. How can he tell?" - -"What's the reason he don't know it?" - -"Because he'd just got that whack when Injun Joe done it. D'you reckon -he could see anything? D'you reckon he knowed anything?" - -"By hokey, that's so, Tom!" - -"And besides, look-a-here--maybe that whack done for HIM!" - -"No, 'taint likely, Tom. He had liquor in him; I could see that; and -besides, he always has. Well, when pap's full, you might take and belt -him over the head with a church and you couldn't phase him. He says so, -his own self. So it's the same with Muff Potter, of course. But if a -man was dead sober, I reckon maybe that whack might fetch him; I dono." - -After another reflective silence, Tom said: - -"Hucky, you sure you can keep mum?" - -"Tom, we GOT to keep mum. You know that. That Injun devil wouldn't -make any more of drownding us than a couple of cats, if we was to -squeak 'bout this and they didn't hang him. Now, look-a-here, Tom, less -take and swear to one another--that's what we got to do--swear to keep -mum." - -"I'm agreed. It's the best thing. Would you just hold hands and swear -that we--" - -"Oh no, that wouldn't do for this. That's good enough for little -rubbishy common things--specially with gals, cuz THEY go back on you -anyway, and blab if they get in a huff--but there orter be writing -'bout a big thing like this. And blood." - -Tom's whole being applauded this idea. It was deep, and dark, and -awful; the hour, the circumstances, the surroundings, were in keeping -with it. He picked up a clean pine shingle that lay in the moonlight, -took a little fragment of "red keel" out of his pocket, got the moon on -his work, and painfully scrawled these lines, emphasizing each slow -down-stroke by clamping his tongue between his teeth, and letting up -the pressure on the up-strokes. [See next page.] - - "Huck Finn and - Tom Sawyer swears - they will keep mum - about This and They - wish They may Drop - down dead in Their - Tracks if They ever - Tell and Rot." - -Huckleberry was filled with admiration of Tom's facility in writing, -and the sublimity of his language. He at once took a pin from his lapel -and was going to prick his flesh, but Tom said: - -"Hold on! Don't do that. A pin's brass. It might have verdigrease on -it." - -"What's verdigrease?" - -"It's p'ison. That's what it is. You just swaller some of it once ---you'll see." - -So Tom unwound the thread from one of his needles, and each boy -pricked the ball of his thumb and squeezed out a drop of blood. In -time, after many squeezes, Tom managed to sign his initials, using the -ball of his little finger for a pen. Then he showed Huckleberry how to -make an H and an F, and the oath was complete. They buried the shingle -close to the wall, with some dismal ceremonies and incantations, and -the fetters that bound their tongues were considered to be locked and -the key thrown away. - -A figure crept stealthily through a break in the other end of the -ruined building, now, but they did not notice it. - -"Tom," whispered Huckleberry, "does this keep us from EVER telling ---ALWAYS?" - -"Of course it does. It don't make any difference WHAT happens, we got -to keep mum. We'd drop down dead--don't YOU know that?" - -"Yes, I reckon that's so." - -They continued to whisper for some little time. Presently a dog set up -a long, lugubrious howl just outside--within ten feet of them. The boys -clasped each other suddenly, in an agony of fright. - -"Which of us does he mean?" gasped Huckleberry. - -"I dono--peep through the crack. Quick!" - -"No, YOU, Tom!" - -"I can't--I can't DO it, Huck!" - -"Please, Tom. There 'tis again!" - -"Oh, lordy, I'm thankful!" whispered Tom. "I know his voice. It's Bull -Harbison." * - -[* If Mr. Harbison owned a slave named Bull, Tom would have spoken of -him as "Harbison's Bull," but a son or a dog of that name was "Bull -Harbison."] - -"Oh, that's good--I tell you, Tom, I was most scared to death; I'd a -bet anything it was a STRAY dog." - -The dog howled again. The boys' hearts sank once more. - -"Oh, my! that ain't no Bull Harbison!" whispered Huckleberry. "DO, Tom!" - -Tom, quaking with fear, yielded, and put his eye to the crack. His -whisper was hardly audible when he said: - -"Oh, Huck, IT S A STRAY DOG!" - -"Quick, Tom, quick! Who does he mean?" - -"Huck, he must mean us both--we're right together." - -"Oh, Tom, I reckon we're goners. I reckon there ain't no mistake 'bout -where I'LL go to. I been so wicked." - -"Dad fetch it! This comes of playing hookey and doing everything a -feller's told NOT to do. I might a been good, like Sid, if I'd a tried ---but no, I wouldn't, of course. But if ever I get off this time, I lay -I'll just WALLER in Sunday-schools!" And Tom began to snuffle a little. - -"YOU bad!" and Huckleberry began to snuffle too. "Consound it, Tom -Sawyer, you're just old pie, 'longside o' what I am. Oh, LORDY, lordy, -lordy, I wisht I only had half your chance." - -Tom choked off and whispered: - -"Look, Hucky, look! He's got his BACK to us!" - -Hucky looked, with joy in his heart. - -"Well, he has, by jingoes! Did he before?" - -"Yes, he did. But I, like a fool, never thought. Oh, this is bully, -you know. NOW who can he mean?" - -The howling stopped. Tom pricked up his ears. - -"Sh! What's that?" he whispered. - -"Sounds like--like hogs grunting. No--it's somebody snoring, Tom." - -"That IS it! Where 'bouts is it, Huck?" - -"I bleeve it's down at 'tother end. Sounds so, anyway. Pap used to -sleep there, sometimes, 'long with the hogs, but laws bless you, he -just lifts things when HE snores. Besides, I reckon he ain't ever -coming back to this town any more." - -The spirit of adventure rose in the boys' souls once more. - -"Hucky, do you das't to go if I lead?" - -"I don't like to, much. Tom, s'pose it's Injun Joe!" - -Tom quailed. But presently the temptation rose up strong again and the -boys agreed to try, with the understanding that they would take to -their heels if the snoring stopped. So they went tiptoeing stealthily -down, the one behind the other. When they had got to within five steps -of the snorer, Tom stepped on a stick, and it broke with a sharp snap. -The man moaned, writhed a little, and his face came into the moonlight. -It was Muff Potter. The boys' hearts had stood still, and their hopes -too, when the man moved, but their fears passed away now. They tiptoed -out, through the broken weather-boarding, and stopped at a little -distance to exchange a parting word. That long, lugubrious howl rose on -the night air again! They turned and saw the strange dog standing -within a few feet of where Potter was lying, and FACING Potter, with -his nose pointing heavenward. - -"Oh, geeminy, it's HIM!" exclaimed both boys, in a breath. - -"Say, Tom--they say a stray dog come howling around Johnny Miller's -house, 'bout midnight, as much as two weeks ago; and a whippoorwill -come in and lit on the banisters and sung, the very same evening; and -there ain't anybody dead there yet." - -"Well, I know that. And suppose there ain't. Didn't Gracie Miller fall -in the kitchen fire and burn herself terrible the very next Saturday?" - -"Yes, but she ain't DEAD. And what's more, she's getting better, too." - -"All right, you wait and see. She's a goner, just as dead sure as Muff -Potter's a goner. That's what the niggers say, and they know all about -these kind of things, Huck." - -Then they separated, cogitating. When Tom crept in at his bedroom -window the night was almost spent. He undressed with excessive caution, -and fell asleep congratulating himself that nobody knew of his -escapade. He was not aware that the gently-snoring Sid was awake, and -had been so for an hour. - -When Tom awoke, Sid was dressed and gone. There was a late look in the -light, a late sense in the atmosphere. He was startled. Why had he not -been called--persecuted till he was up, as usual? The thought filled -him with bodings. Within five minutes he was dressed and down-stairs, -feeling sore and drowsy. The family were still at table, but they had -finished breakfast. There was no voice of rebuke; but there were -averted eyes; there was a silence and an air of solemnity that struck a -chill to the culprit's heart. He sat down and tried to seem gay, but it -was up-hill work; it roused no smile, no response, and he lapsed into -silence and let his heart sink down to the depths. - -After breakfast his aunt took him aside, and Tom almost brightened in -the hope that he was going to be flogged; but it was not so. His aunt -wept over him and asked him how he could go and break her old heart so; -and finally told him to go on, and ruin himself and bring her gray -hairs with sorrow to the grave, for it was no use for her to try any -more. This was worse than a thousand whippings, and Tom's heart was -sorer now than his body. He cried, he pleaded for forgiveness, promised -to reform over and over again, and then received his dismissal, feeling -that he had won but an imperfect forgiveness and established but a -feeble confidence. - -He left the presence too miserable to even feel revengeful toward Sid; -and so the latter's prompt retreat through the back gate was -unnecessary. He moped to school gloomy and sad, and took his flogging, -along with Joe Harper, for playing hookey the day before, with the air -of one whose heart was busy with heavier woes and wholly dead to -trifles. Then he betook himself to his seat, rested his elbows on his -desk and his jaws in his hands, and stared at the wall with the stony -stare of suffering that has reached the limit and can no further go. -His elbow was pressing against some hard substance. After a long time -he slowly and sadly changed his position, and took up this object with -a sigh. It was in a paper. He unrolled it. A long, lingering, colossal -sigh followed, and his heart broke. It was his brass andiron knob! - -This final feather broke the camel's back. - - - -CHAPTER XI - -CLOSE upon the hour of noon the whole village was suddenly electrified -with the ghastly news. No need of the as yet undreamed-of telegraph; -the tale flew from man to man, from group to group, from house to -house, with little less than telegraphic speed. Of course the -schoolmaster gave holiday for that afternoon; the town would have -thought strangely of him if he had not. - -A gory knife had been found close to the murdered man, and it had been -recognized by somebody as belonging to Muff Potter--so the story ran. -And it was said that a belated citizen had come upon Potter washing -himself in the "branch" about one or two o'clock in the morning, and -that Potter had at once sneaked off--suspicious circumstances, -especially the washing which was not a habit with Potter. It was also -said that the town had been ransacked for this "murderer" (the public -are not slow in the matter of sifting evidence and arriving at a -verdict), but that he could not be found. Horsemen had departed down -all the roads in every direction, and the Sheriff "was confident" that -he would be captured before night. - -All the town was drifting toward the graveyard. Tom's heartbreak -vanished and he joined the procession, not because he would not a -thousand times rather go anywhere else, but because an awful, -unaccountable fascination drew him on. Arrived at the dreadful place, -he wormed his small body through the crowd and saw the dismal -spectacle. It seemed to him an age since he was there before. Somebody -pinched his arm. He turned, and his eyes met Huckleberry's. Then both -looked elsewhere at once, and wondered if anybody had noticed anything -in their mutual glance. But everybody was talking, and intent upon the -grisly spectacle before them. - -"Poor fellow!" "Poor young fellow!" "This ought to be a lesson to -grave robbers!" "Muff Potter'll hang for this if they catch him!" This -was the drift of remark; and the minister said, "It was a judgment; His -hand is here." - -Now Tom shivered from head to heel; for his eye fell upon the stolid -face of Injun Joe. At this moment the crowd began to sway and struggle, -and voices shouted, "It's him! it's him! he's coming himself!" - -"Who? Who?" from twenty voices. - -"Muff Potter!" - -"Hallo, he's stopped!--Look out, he's turning! Don't let him get away!" - -People in the branches of the trees over Tom's head said he wasn't -trying to get away--he only looked doubtful and perplexed. - -"Infernal impudence!" said a bystander; "wanted to come and take a -quiet look at his work, I reckon--didn't expect any company." - -The crowd fell apart, now, and the Sheriff came through, -ostentatiously leading Potter by the arm. The poor fellow's face was -haggard, and his eyes showed the fear that was upon him. When he stood -before the murdered man, he shook as with a palsy, and he put his face -in his hands and burst into tears. - -"I didn't do it, friends," he sobbed; "'pon my word and honor I never -done it." - -"Who's accused you?" shouted a voice. - -This shot seemed to carry home. Potter lifted his face and looked -around him with a pathetic hopelessness in his eyes. He saw Injun Joe, -and exclaimed: - -"Oh, Injun Joe, you promised me you'd never--" - -"Is that your knife?" and it was thrust before him by the Sheriff. - -Potter would have fallen if they had not caught him and eased him to -the ground. Then he said: - -"Something told me 't if I didn't come back and get--" He shuddered; -then waved his nerveless hand with a vanquished gesture and said, "Tell -'em, Joe, tell 'em--it ain't any use any more." - -Then Huckleberry and Tom stood dumb and staring, and heard the -stony-hearted liar reel off his serene statement, they expecting every -moment that the clear sky would deliver God's lightnings upon his head, -and wondering to see how long the stroke was delayed. And when he had -finished and still stood alive and whole, their wavering impulse to -break their oath and save the poor betrayed prisoner's life faded and -vanished away, for plainly this miscreant had sold himself to Satan and -it would be fatal to meddle with the property of such a power as that. - -"Why didn't you leave? What did you want to come here for?" somebody -said. - -"I couldn't help it--I couldn't help it," Potter moaned. "I wanted to -run away, but I couldn't seem to come anywhere but here." And he fell -to sobbing again. - -Injun Joe repeated his statement, just as calmly, a few minutes -afterward on the inquest, under oath; and the boys, seeing that the -lightnings were still withheld, were confirmed in their belief that Joe -had sold himself to the devil. He was now become, to them, the most -balefully interesting object they had ever looked upon, and they could -not take their fascinated eyes from his face. - -They inwardly resolved to watch him nights, when opportunity should -offer, in the hope of getting a glimpse of his dread master. - -Injun Joe helped to raise the body of the murdered man and put it in a -wagon for removal; and it was whispered through the shuddering crowd -that the wound bled a little! The boys thought that this happy -circumstance would turn suspicion in the right direction; but they were -disappointed, for more than one villager remarked: - -"It was within three feet of Muff Potter when it done it." - -Tom's fearful secret and gnawing conscience disturbed his sleep for as -much as a week after this; and at breakfast one morning Sid said: - -"Tom, you pitch around and talk in your sleep so much that you keep me -awake half the time." - -Tom blanched and dropped his eyes. - -"It's a bad sign," said Aunt Polly, gravely. "What you got on your -mind, Tom?" - -"Nothing. Nothing 't I know of." But the boy's hand shook so that he -spilled his coffee. - -"And you do talk such stuff," Sid said. "Last night you said, 'It's -blood, it's blood, that's what it is!' You said that over and over. And -you said, 'Don't torment me so--I'll tell!' Tell WHAT? What is it -you'll tell?" - -Everything was swimming before Tom. There is no telling what might -have happened, now, but luckily the concern passed out of Aunt Polly's -face and she came to Tom's relief without knowing it. She said: - -"Sho! It's that dreadful murder. I dream about it most every night -myself. Sometimes I dream it's me that done it." - -Mary said she had been affected much the same way. Sid seemed -satisfied. Tom got out of the presence as quick as he plausibly could, -and after that he complained of toothache for a week, and tied up his -jaws every night. He never knew that Sid lay nightly watching, and -frequently slipped the bandage free and then leaned on his elbow -listening a good while at a time, and afterward slipped the bandage -back to its place again. Tom's distress of mind wore off gradually and -the toothache grew irksome and was discarded. If Sid really managed to -make anything out of Tom's disjointed mutterings, he kept it to himself. - -It seemed to Tom that his schoolmates never would get done holding -inquests on dead cats, and thus keeping his trouble present to his -mind. Sid noticed that Tom never was coroner at one of these inquiries, -though it had been his habit to take the lead in all new enterprises; -he noticed, too, that Tom never acted as a witness--and that was -strange; and Sid did not overlook the fact that Tom even showed a -marked aversion to these inquests, and always avoided them when he -could. Sid marvelled, but said nothing. However, even inquests went out -of vogue at last, and ceased to torture Tom's conscience. - -Every day or two, during this time of sorrow, Tom watched his -opportunity and went to the little grated jail-window and smuggled such -small comforts through to the "murderer" as he could get hold of. The -jail was a trifling little brick den that stood in a marsh at the edge -of the village, and no guards were afforded for it; indeed, it was -seldom occupied. These offerings greatly helped to ease Tom's -conscience. - -The villagers had a strong desire to tar-and-feather Injun Joe and -ride him on a rail, for body-snatching, but so formidable was his -character that nobody could be found who was willing to take the lead -in the matter, so it was dropped. He had been careful to begin both of -his inquest-statements with the fight, without confessing the -grave-robbery that preceded it; therefore it was deemed wisest not -to try the case in the courts at present. - - - -CHAPTER XII - -ONE of the reasons why Tom's mind had drifted away from its secret -troubles was, that it had found a new and weighty matter to interest -itself about. Becky Thatcher had stopped coming to school. Tom had -struggled with his pride a few days, and tried to "whistle her down the -wind," but failed. He began to find himself hanging around her father's -house, nights, and feeling very miserable. She was ill. What if she -should die! There was distraction in the thought. He no longer took an -interest in war, nor even in piracy. The charm of life was gone; there -was nothing but dreariness left. He put his hoop away, and his bat; -there was no joy in them any more. His aunt was concerned. She began to -try all manner of remedies on him. She was one of those people who are -infatuated with patent medicines and all new-fangled methods of -producing health or mending it. She was an inveterate experimenter in -these things. When something fresh in this line came out she was in a -fever, right away, to try it; not on herself, for she was never ailing, -but on anybody else that came handy. She was a subscriber for all the -"Health" periodicals and phrenological frauds; and the solemn ignorance -they were inflated with was breath to her nostrils. All the "rot" they -contained about ventilation, and how to go to bed, and how to get up, -and what to eat, and what to drink, and how much exercise to take, and -what frame of mind to keep one's self in, and what sort of clothing to -wear, was all gospel to her, and she never observed that her -health-journals of the current month customarily upset everything they -had recommended the month before. She was as simple-hearted and honest -as the day was long, and so she was an easy victim. She gathered -together her quack periodicals and her quack medicines, and thus armed -with death, went about on her pale horse, metaphorically speaking, with -"hell following after." But she never suspected that she was not an -angel of healing and the balm of Gilead in disguise, to the suffering -neighbors. - -The water treatment was new, now, and Tom's low condition was a -windfall to her. She had him out at daylight every morning, stood him -up in the woodshed and drowned him with a deluge of cold water; then -she scrubbed him down with a towel like a file, and so brought him to; -then she rolled him up in a wet sheet and put him away under blankets -till she sweated his soul clean and "the yellow stains of it came -through his pores"--as Tom said. - -Yet notwithstanding all this, the boy grew more and more melancholy -and pale and dejected. She added hot baths, sitz baths, shower baths, -and plunges. The boy remained as dismal as a hearse. She began to -assist the water with a slim oatmeal diet and blister-plasters. She -calculated his capacity as she would a jug's, and filled him up every -day with quack cure-alls. - -Tom had become indifferent to persecution by this time. This phase -filled the old lady's heart with consternation. This indifference must -be broken up at any cost. Now she heard of Pain-killer for the first -time. She ordered a lot at once. She tasted it and was filled with -gratitude. It was simply fire in a liquid form. She dropped the water -treatment and everything else, and pinned her faith to Pain-killer. She -gave Tom a teaspoonful and watched with the deepest anxiety for the -result. Her troubles were instantly at rest, her soul at peace again; -for the "indifference" was broken up. The boy could not have shown a -wilder, heartier interest, if she had built a fire under him. - -Tom felt that it was time to wake up; this sort of life might be -romantic enough, in his blighted condition, but it was getting to have -too little sentiment and too much distracting variety about it. So he -thought over various plans for relief, and finally hit pon that of -professing to be fond of Pain-killer. He asked for it so often that he -became a nuisance, and his aunt ended by telling him to help himself -and quit bothering her. If it had been Sid, she would have had no -misgivings to alloy her delight; but since it was Tom, she watched the -bottle clandestinely. She found that the medicine did really diminish, -but it did not occur to her that the boy was mending the health of a -crack in the sitting-room floor with it. - -One day Tom was in the act of dosing the crack when his aunt's yellow -cat came along, purring, eying the teaspoon avariciously, and begging -for a taste. Tom said: - -"Don't ask for it unless you want it, Peter." - -But Peter signified that he did want it. - -"You better make sure." - -Peter was sure. - -"Now you've asked for it, and I'll give it to you, because there ain't -anything mean about me; but if you find you don't like it, you mustn't -blame anybody but your own self." - -Peter was agreeable. So Tom pried his mouth open and poured down the -Pain-killer. Peter sprang a couple of yards in the air, and then -delivered a war-whoop and set off round and round the room, banging -against furniture, upsetting flower-pots, and making general havoc. -Next he rose on his hind feet and pranced around, in a frenzy of -enjoyment, with his head over his shoulder and his voice proclaiming -his unappeasable happiness. Then he went tearing around the house again -spreading chaos and destruction in his path. Aunt Polly entered in time -to see him throw a few double summersets, deliver a final mighty -hurrah, and sail through the open window, carrying the rest of the -flower-pots with him. The old lady stood petrified with astonishment, -peering over her glasses; Tom lay on the floor expiring with laughter. - -"Tom, what on earth ails that cat?" - -"I don't know, aunt," gasped the boy. - -"Why, I never see anything like it. What did make him act so?" - -"Deed I don't know, Aunt Polly; cats always act so when they're having -a good time." - -"They do, do they?" There was something in the tone that made Tom -apprehensive. - -"Yes'm. That is, I believe they do." - -"You DO?" - -"Yes'm." - -The old lady was bending down, Tom watching, with interest emphasized -by anxiety. Too late he divined her "drift." The handle of the telltale -teaspoon was visible under the bed-valance. Aunt Polly took it, held it -up. Tom winced, and dropped his eyes. Aunt Polly raised him by the -usual handle--his ear--and cracked his head soundly with her thimble. - -"Now, sir, what did you want to treat that poor dumb beast so, for?" - -"I done it out of pity for him--because he hadn't any aunt." - -"Hadn't any aunt!--you numskull. What has that got to do with it?" - -"Heaps. Because if he'd had one she'd a burnt him out herself! She'd a -roasted his bowels out of him 'thout any more feeling than if he was a -human!" - -Aunt Polly felt a sudden pang of remorse. This was putting the thing -in a new light; what was cruelty to a cat MIGHT be cruelty to a boy, -too. She began to soften; she felt sorry. Her eyes watered a little, -and she put her hand on Tom's head and said gently: - -"I was meaning for the best, Tom. And, Tom, it DID do you good." - -Tom looked up in her face with just a perceptible twinkle peeping -through his gravity. - -"I know you was meaning for the best, aunty, and so was I with Peter. -It done HIM good, too. I never see him get around so since--" - -"Oh, go 'long with you, Tom, before you aggravate me again. And you -try and see if you can't be a good boy, for once, and you needn't take -any more medicine." - -Tom reached school ahead of time. It was noticed that this strange -thing had been occurring every day latterly. And now, as usual of late, -he hung about the gate of the schoolyard instead of playing with his -comrades. He was sick, he said, and he looked it. He tried to seem to -be looking everywhere but whither he really was looking--down the road. -Presently Jeff Thatcher hove in sight, and Tom's face lighted; he gazed -a moment, and then turned sorrowfully away. When Jeff arrived, Tom -accosted him; and "led up" warily to opportunities for remark about -Becky, but the giddy lad never could see the bait. Tom watched and -watched, hoping whenever a frisking frock came in sight, and hating the -owner of it as soon as he saw she was not the right one. At last frocks -ceased to appear, and he dropped hopelessly into the dumps; he entered -the empty schoolhouse and sat down to suffer. Then one more frock -passed in at the gate, and Tom's heart gave a great bound. The next -instant he was out, and "going on" like an Indian; yelling, laughing, -chasing boys, jumping over the fence at risk of life and limb, throwing -handsprings, standing on his head--doing all the heroic things he could -conceive of, and keeping a furtive eye out, all the while, to see if -Becky Thatcher was noticing. But she seemed to be unconscious of it -all; she never looked. Could it be possible that she was not aware that -he was there? He carried his exploits to her immediate vicinity; came -war-whooping around, snatched a boy's cap, hurled it to the roof of the -schoolhouse, broke through a group of boys, tumbling them in every -direction, and fell sprawling, himself, under Becky's nose, almost -upsetting her--and she turned, with her nose in the air, and he heard -her say: "Mf! some people think they're mighty smart--always showing -off!" - -Tom's cheeks burned. He gathered himself up and sneaked off, crushed -and crestfallen. - - - -CHAPTER XIII - -TOM'S mind was made up now. He was gloomy and desperate. He was a -forsaken, friendless boy, he said; nobody loved him; when they found -out what they had driven him to, perhaps they would be sorry; he had -tried to do right and get along, but they would not let him; since -nothing would do them but to be rid of him, let it be so; and let them -blame HIM for the consequences--why shouldn't they? What right had the -friendless to complain? Yes, they had forced him to it at last: he -would lead a life of crime. There was no choice. - -By this time he was far down Meadow Lane, and the bell for school to -"take up" tinkled faintly upon his ear. He sobbed, now, to think he -should never, never hear that old familiar sound any more--it was very -hard, but it was forced on him; since he was driven out into the cold -world, he must submit--but he forgave them. Then the sobs came thick -and fast. - -Just at this point he met his soul's sworn comrade, Joe Harper ---hard-eyed, and with evidently a great and dismal purpose in his heart. -Plainly here were "two souls with but a single thought." Tom, wiping -his eyes with his sleeve, began to blubber out something about a -resolution to escape from hard usage and lack of sympathy at home by -roaming abroad into the great world never to return; and ended by -hoping that Joe would not forget him. - -But it transpired that this was a request which Joe had just been -going to make of Tom, and had come to hunt him up for that purpose. His -mother had whipped him for drinking some cream which he had never -tasted and knew nothing about; it was plain that she was tired of him -and wished him to go; if she felt that way, there was nothing for him -to do but succumb; he hoped she would be happy, and never regret having -driven her poor boy out into the unfeeling world to suffer and die. - -As the two boys walked sorrowing along, they made a new compact to -stand by each other and be brothers and never separate till death -relieved them of their troubles. Then they began to lay their plans. -Joe was for being a hermit, and living on crusts in a remote cave, and -dying, some time, of cold and want and grief; but after listening to -Tom, he conceded that there were some conspicuous advantages about a -life of crime, and so he consented to be a pirate. - -Three miles below St. Petersburg, at a point where the Mississippi -River was a trifle over a mile wide, there was a long, narrow, wooded -island, with a shallow bar at the head of it, and this offered well as -a rendezvous. It was not inhabited; it lay far over toward the further -shore, abreast a dense and almost wholly unpeopled forest. So Jackson's -Island was chosen. Who were to be the subjects of their piracies was a -matter that did not occur to them. Then they hunted up Huckleberry -Finn, and he joined them promptly, for all careers were one to him; he -was indifferent. They presently separated to meet at a lonely spot on -the river-bank two miles above the village at the favorite hour--which -was midnight. There was a small log raft there which they meant to -capture. Each would bring hooks and lines, and such provision as he -could steal in the most dark and mysterious way--as became outlaws. And -before the afternoon was done, they had all managed to enjoy the sweet -glory of spreading the fact that pretty soon the town would "hear -something." All who got this vague hint were cautioned to "be mum and -wait." - -About midnight Tom arrived with a boiled ham and a few trifles, -and stopped in a dense undergrowth on a small bluff overlooking the -meeting-place. It was starlight, and very still. The mighty river lay -like an ocean at rest. Tom listened a moment, but no sound disturbed the -quiet. Then he gave a low, distinct whistle. It was answered from under -the bluff. Tom whistled twice more; these signals were answered in the -same way. Then a guarded voice said: - -"Who goes there?" - -"Tom Sawyer, the Black Avenger of the Spanish Main. Name your names." - -"Huck Finn the Red-Handed, and Joe Harper the Terror of the Seas." Tom -had furnished these titles, from his favorite literature. - -"'Tis well. Give the countersign." - -Two hoarse whispers delivered the same awful word simultaneously to -the brooding night: - -"BLOOD!" - -Then Tom tumbled his ham over the bluff and let himself down after it, -tearing both skin and clothes to some extent in the effort. There was -an easy, comfortable path along the shore under the bluff, but it -lacked the advantages of difficulty and danger so valued by a pirate. - -The Terror of the Seas had brought a side of bacon, and had about worn -himself out with getting it there. Finn the Red-Handed had stolen a -skillet and a quantity of half-cured leaf tobacco, and had also brought -a few corn-cobs to make pipes with. But none of the pirates smoked or -"chewed" but himself. The Black Avenger of the Spanish Main said it -would never do to start without some fire. That was a wise thought; -matches were hardly known there in that day. They saw a fire -smouldering upon a great raft a hundred yards above, and they went -stealthily thither and helped themselves to a chunk. They made an -imposing adventure of it, saying, "Hist!" every now and then, and -suddenly halting with finger on lip; moving with hands on imaginary -dagger-hilts; and giving orders in dismal whispers that if "the foe" -stirred, to "let him have it to the hilt," because "dead men tell no -tales." They knew well enough that the raftsmen were all down at the -village laying in stores or having a spree, but still that was no -excuse for their conducting this thing in an unpiratical way. - -They shoved off, presently, Tom in command, Huck at the after oar and -Joe at the forward. Tom stood amidships, gloomy-browed, and with folded -arms, and gave his orders in a low, stern whisper: - -"Luff, and bring her to the wind!" - -"Aye-aye, sir!" - -"Steady, steady-y-y-y!" - -"Steady it is, sir!" - -"Let her go off a point!" - -"Point it is, sir!" - -As the boys steadily and monotonously drove the raft toward mid-stream -it was no doubt understood that these orders were given only for -"style," and were not intended to mean anything in particular. - -"What sail's she carrying?" - -"Courses, tops'ls, and flying-jib, sir." - -"Send the r'yals up! Lay out aloft, there, half a dozen of ye ---foretopmaststuns'l! Lively, now!" - -"Aye-aye, sir!" - -"Shake out that maintogalans'l! Sheets and braces! NOW my hearties!" - -"Aye-aye, sir!" - -"Hellum-a-lee--hard a port! Stand by to meet her when she comes! Port, -port! NOW, men! With a will! Stead-y-y-y!" - -"Steady it is, sir!" - -The raft drew beyond the middle of the river; the boys pointed her -head right, and then lay on their oars. The river was not high, so -there was not more than a two or three mile current. Hardly a word was -said during the next three-quarters of an hour. Now the raft was -passing before the distant town. Two or three glimmering lights showed -where it lay, peacefully sleeping, beyond the vague vast sweep of -star-gemmed water, unconscious of the tremendous event that was happening. -The Black Avenger stood still with folded arms, "looking his last" upon -the scene of his former joys and his later sufferings, and wishing -"she" could see him now, abroad on the wild sea, facing peril and death -with dauntless heart, going to his doom with a grim smile on his lips. -It was but a small strain on his imagination to remove Jackson's Island -beyond eyeshot of the village, and so he "looked his last" with a -broken and satisfied heart. The other pirates were looking their last, -too; and they all looked so long that they came near letting the -current drift them out of the range of the island. But they discovered -the danger in time, and made shift to avert it. About two o'clock in -the morning the raft grounded on the bar two hundred yards above the -head of the island, and they waded back and forth until they had landed -their freight. Part of the little raft's belongings consisted of an old -sail, and this they spread over a nook in the bushes for a tent to -shelter their provisions; but they themselves would sleep in the open -air in good weather, as became outlaws. - -They built a fire against the side of a great log twenty or thirty -steps within the sombre depths of the forest, and then cooked some -bacon in the frying-pan for supper, and used up half of the corn "pone" -stock they had brought. It seemed glorious sport to be feasting in that -wild, free way in the virgin forest of an unexplored and uninhabited -island, far from the haunts of men, and they said they never would -return to civilization. The climbing fire lit up their faces and threw -its ruddy glare upon the pillared tree-trunks of their forest temple, -and upon the varnished foliage and festooning vines. - -When the last crisp slice of bacon was gone, and the last allowance of -corn pone devoured, the boys stretched themselves out on the grass, -filled with contentment. They could have found a cooler place, but they -would not deny themselves such a romantic feature as the roasting -camp-fire. - -"AIN'T it gay?" said Joe. - -"It's NUTS!" said Tom. "What would the boys say if they could see us?" - -"Say? Well, they'd just die to be here--hey, Hucky!" - -"I reckon so," said Huckleberry; "anyways, I'm suited. I don't want -nothing better'n this. I don't ever get enough to eat, gen'ally--and -here they can't come and pick at a feller and bullyrag him so." - -"It's just the life for me," said Tom. "You don't have to get up, -mornings, and you don't have to go to school, and wash, and all that -blame foolishness. You see a pirate don't have to do ANYTHING, Joe, -when he's ashore, but a hermit HE has to be praying considerable, and -then he don't have any fun, anyway, all by himself that way." - -"Oh yes, that's so," said Joe, "but I hadn't thought much about it, -you know. I'd a good deal rather be a pirate, now that I've tried it." - -"You see," said Tom, "people don't go much on hermits, nowadays, like -they used to in old times, but a pirate's always respected. And a -hermit's got to sleep on the hardest place he can find, and put -sackcloth and ashes on his head, and stand out in the rain, and--" - -"What does he put sackcloth and ashes on his head for?" inquired Huck. - -"I dono. But they've GOT to do it. Hermits always do. You'd have to do -that if you was a hermit." - -"Dern'd if I would," said Huck. - -"Well, what would you do?" - -"I dono. But I wouldn't do that." - -"Why, Huck, you'd HAVE to. How'd you get around it?" - -"Why, I just wouldn't stand it. I'd run away." - -"Run away! Well, you WOULD be a nice old slouch of a hermit. You'd be -a disgrace." - -The Red-Handed made no response, being better employed. He had -finished gouging out a cob, and now he fitted a weed stem to it, loaded -it with tobacco, and was pressing a coal to the charge and blowing a -cloud of fragrant smoke--he was in the full bloom of luxurious -contentment. The other pirates envied him this majestic vice, and -secretly resolved to acquire it shortly. Presently Huck said: - -"What does pirates have to do?" - -Tom said: - -"Oh, they have just a bully time--take ships and burn them, and get -the money and bury it in awful places in their island where there's -ghosts and things to watch it, and kill everybody in the ships--make -'em walk a plank." - -"And they carry the women to the island," said Joe; "they don't kill -the women." - -"No," assented Tom, "they don't kill the women--they're too noble. And -the women's always beautiful, too. - -"And don't they wear the bulliest clothes! Oh no! All gold and silver -and di'monds," said Joe, with enthusiasm. - -"Who?" said Huck. - -"Why, the pirates." - -Huck scanned his own clothing forlornly. - -"I reckon I ain't dressed fitten for a pirate," said he, with a -regretful pathos in his voice; "but I ain't got none but these." - -But the other boys told him the fine clothes would come fast enough, -after they should have begun their adventures. They made him understand -that his poor rags would do to begin with, though it was customary for -wealthy pirates to start with a proper wardrobe. - -Gradually their talk died out and drowsiness began to steal upon the -eyelids of the little waifs. The pipe dropped from the fingers of the -Red-Handed, and he slept the sleep of the conscience-free and the -weary. The Terror of the Seas and the Black Avenger of the Spanish Main -had more difficulty in getting to sleep. They said their prayers -inwardly, and lying down, since there was nobody there with authority -to make them kneel and recite aloud; in truth, they had a mind not to -say them at all, but they were afraid to proceed to such lengths as -that, lest they might call down a sudden and special thunderbolt from -heaven. Then at once they reached and hovered upon the imminent verge -of sleep--but an intruder came, now, that would not "down." It was -conscience. They began to feel a vague fear that they had been doing -wrong to run away; and next they thought of the stolen meat, and then -the real torture came. They tried to argue it away by reminding -conscience that they had purloined sweetmeats and apples scores of -times; but conscience was not to be appeased by such thin -plausibilities; it seemed to them, in the end, that there was no -getting around the stubborn fact that taking sweetmeats was only -"hooking," while taking bacon and hams and such valuables was plain -simple stealing--and there was a command against that in the Bible. So -they inwardly resolved that so long as they remained in the business, -their piracies should not again be sullied with the crime of stealing. -Then conscience granted a truce, and these curiously inconsistent -pirates fell peacefully to sleep. - - - -CHAPTER XIV - -WHEN Tom awoke in the morning, he wondered where he was. He sat up and -rubbed his eyes and looked around. Then he comprehended. It was the -cool gray dawn, and there was a delicious sense of repose and peace in -the deep pervading calm and silence of the woods. Not a leaf stirred; -not a sound obtruded upon great Nature's meditation. Beaded dewdrops -stood upon the leaves and grasses. A white layer of ashes covered the -fire, and a thin blue breath of smoke rose straight into the air. Joe -and Huck still slept. - -Now, far away in the woods a bird called; another answered; presently -the hammering of a woodpecker was heard. Gradually the cool dim gray of -the morning whitened, and as gradually sounds multiplied and life -manifested itself. The marvel of Nature shaking off sleep and going to -work unfolded itself to the musing boy. A little green worm came -crawling over a dewy leaf, lifting two-thirds of his body into the air -from time to time and "sniffing around," then proceeding again--for he -was measuring, Tom said; and when the worm approached him, of its own -accord, he sat as still as a stone, with his hopes rising and falling, -by turns, as the creature still came toward him or seemed inclined to -go elsewhere; and when at last it considered a painful moment with its -curved body in the air and then came decisively down upon Tom's leg and -began a journey over him, his whole heart was glad--for that meant that -he was going to have a new suit of clothes--without the shadow of a -doubt a gaudy piratical uniform. Now a procession of ants appeared, -from nowhere in particular, and went about their labors; one struggled -manfully by with a dead spider five times as big as itself in its arms, -and lugged it straight up a tree-trunk. A brown spotted lady-bug -climbed the dizzy height of a grass blade, and Tom bent down close to -it and said, "Lady-bug, lady-bug, fly away home, your house is on fire, -your children's alone," and she took wing and went off to see about it ---which did not surprise the boy, for he knew of old that this insect was -credulous about conflagrations, and he had practised upon its -simplicity more than once. A tumblebug came next, heaving sturdily at -its ball, and Tom touched the creature, to see it shut its legs against -its body and pretend to be dead. The birds were fairly rioting by this -time. A catbird, the Northern mocker, lit in a tree over Tom's head, -and trilled out her imitations of her neighbors in a rapture of -enjoyment; then a shrill jay swept down, a flash of blue flame, and -stopped on a twig almost within the boy's reach, cocked his head to one -side and eyed the strangers with a consuming curiosity; a gray squirrel -and a big fellow of the "fox" kind came skurrying along, sitting up at -intervals to inspect and chatter at the boys, for the wild things had -probably never seen a human being before and scarcely knew whether to -be afraid or not. All Nature was wide awake and stirring, now; long -lances of sunlight pierced down through the dense foliage far and near, -and a few butterflies came fluttering upon the scene. - -Tom stirred up the other pirates and they all clattered away with a -shout, and in a minute or two were stripped and chasing after and -tumbling over each other in the shallow limpid water of the white -sandbar. They felt no longing for the little village sleeping in the -distance beyond the majestic waste of water. A vagrant current or a -slight rise in the river had carried off their raft, but this only -gratified them, since its going was something like burning the bridge -between them and civilization. - -They came back to camp wonderfully refreshed, glad-hearted, and -ravenous; and they soon had the camp-fire blazing up again. Huck found -a spring of clear cold water close by, and the boys made cups of broad -oak or hickory leaves, and felt that water, sweetened with such a -wildwood charm as that, would be a good enough substitute for coffee. -While Joe was slicing bacon for breakfast, Tom and Huck asked him to -hold on a minute; they stepped to a promising nook in the river-bank -and threw in their lines; almost immediately they had reward. Joe had -not had time to get impatient before they were back again with some -handsome bass, a couple of sun-perch and a small catfish--provisions -enough for quite a family. They fried the fish with the bacon, and were -astonished; for no fish had ever seemed so delicious before. They did -not know that the quicker a fresh-water fish is on the fire after he is -caught the better he is; and they reflected little upon what a sauce -open-air sleeping, open-air exercise, bathing, and a large ingredient -of hunger make, too. - -They lay around in the shade, after breakfast, while Huck had a smoke, -and then went off through the woods on an exploring expedition. They -tramped gayly along, over decaying logs, through tangled underbrush, -among solemn monarchs of the forest, hung from their crowns to the -ground with a drooping regalia of grape-vines. Now and then they came -upon snug nooks carpeted with grass and jeweled with flowers. - -They found plenty of things to be delighted with, but nothing to be -astonished at. They discovered that the island was about three miles -long and a quarter of a mile wide, and that the shore it lay closest to -was only separated from it by a narrow channel hardly two hundred yards -wide. They took a swim about every hour, so it was close upon the -middle of the afternoon when they got back to camp. They were too -hungry to stop to fish, but they fared sumptuously upon cold ham, and -then threw themselves down in the shade to talk. But the talk soon -began to drag, and then died. The stillness, the solemnity that brooded -in the woods, and the sense of loneliness, began to tell upon the -spirits of the boys. They fell to thinking. A sort of undefined longing -crept upon them. This took dim shape, presently--it was budding -homesickness. Even Finn the Red-Handed was dreaming of his doorsteps -and empty hogsheads. But they were all ashamed of their weakness, and -none was brave enough to speak his thought. - -For some time, now, the boys had been dully conscious of a peculiar -sound in the distance, just as one sometimes is of the ticking of a -clock which he takes no distinct note of. But now this mysterious sound -became more pronounced, and forced a recognition. The boys started, -glanced at each other, and then each assumed a listening attitude. -There was a long silence, profound and unbroken; then a deep, sullen -boom came floating down out of the distance. - -"What is it!" exclaimed Joe, under his breath. - -"I wonder," said Tom in a whisper. - -"'Tain't thunder," said Huckleberry, in an awed tone, "becuz thunder--" - -"Hark!" said Tom. "Listen--don't talk." - -They waited a time that seemed an age, and then the same muffled boom -troubled the solemn hush. - -"Let's go and see." - -They sprang to their feet and hurried to the shore toward the town. -They parted the bushes on the bank and peered out over the water. The -little steam ferryboat was about a mile below the village, drifting -with the current. Her broad deck seemed crowded with people. There were -a great many skiffs rowing about or floating with the stream in the -neighborhood of the ferryboat, but the boys could not determine what -the men in them were doing. Presently a great jet of white smoke burst -from the ferryboat's side, and as it expanded and rose in a lazy cloud, -that same dull throb of sound was borne to the listeners again. - -"I know now!" exclaimed Tom; "somebody's drownded!" - -"That's it!" said Huck; "they done that last summer, when Bill Turner -got drownded; they shoot a cannon over the water, and that makes him -come up to the top. Yes, and they take loaves of bread and put -quicksilver in 'em and set 'em afloat, and wherever there's anybody -that's drownded, they'll float right there and stop." - -"Yes, I've heard about that," said Joe. "I wonder what makes the bread -do that." - -"Oh, it ain't the bread, so much," said Tom; "I reckon it's mostly -what they SAY over it before they start it out." - -"But they don't say anything over it," said Huck. "I've seen 'em and -they don't." - -"Well, that's funny," said Tom. "But maybe they say it to themselves. -Of COURSE they do. Anybody might know that." - -The other boys agreed that there was reason in what Tom said, because -an ignorant lump of bread, uninstructed by an incantation, could not be -expected to act very intelligently when set upon an errand of such -gravity. - -"By jings, I wish I was over there, now," said Joe. - -"I do too" said Huck "I'd give heaps to know who it is." - -The boys still listened and watched. Presently a revealing thought -flashed through Tom's mind, and he exclaimed: - -"Boys, I know who's drownded--it's us!" - -They felt like heroes in an instant. Here was a gorgeous triumph; they -were missed; they were mourned; hearts were breaking on their account; -tears were being shed; accusing memories of unkindness to these poor -lost lads were rising up, and unavailing regrets and remorse were being -indulged; and best of all, the departed were the talk of the whole -town, and the envy of all the boys, as far as this dazzling notoriety -was concerned. This was fine. It was worth while to be a pirate, after -all. - -As twilight drew on, the ferryboat went back to her accustomed -business and the skiffs disappeared. The pirates returned to camp. They -were jubilant with vanity over their new grandeur and the illustrious -trouble they were making. They caught fish, cooked supper and ate it, -and then fell to guessing at what the village was thinking and saying -about them; and the pictures they drew of the public distress on their -account were gratifying to look upon--from their point of view. But -when the shadows of night closed them in, they gradually ceased to -talk, and sat gazing into the fire, with their minds evidently -wandering elsewhere. The excitement was gone, now, and Tom and Joe -could not keep back thoughts of certain persons at home who were not -enjoying this fine frolic as much as they were. Misgivings came; they -grew troubled and unhappy; a sigh or two escaped, unawares. By and by -Joe timidly ventured upon a roundabout "feeler" as to how the others -might look upon a return to civilization--not right now, but-- - -Tom withered him with derision! Huck, being uncommitted as yet, joined -in with Tom, and the waverer quickly "explained," and was glad to get -out of the scrape with as little taint of chicken-hearted homesickness -clinging to his garments as he could. Mutiny was effectually laid to -rest for the moment. - -As the night deepened, Huck began to nod, and presently to snore. Joe -followed next. Tom lay upon his elbow motionless, for some time, -watching the two intently. At last he got up cautiously, on his knees, -and went searching among the grass and the flickering reflections flung -by the camp-fire. He picked up and inspected several large -semi-cylinders of the thin white bark of a sycamore, and finally chose -two which seemed to suit him. Then he knelt by the fire and painfully -wrote something upon each of these with his "red keel"; one he rolled up -and put in his jacket pocket, and the other he put in Joe's hat and -removed it to a little distance from the owner. And he also put into the -hat certain schoolboy treasures of almost inestimable value--among them -a lump of chalk, an India-rubber ball, three fishhooks, and one of that -kind of marbles known as a "sure 'nough crystal." Then he tiptoed his -way cautiously among the trees till he felt that he was out of hearing, -and straightway broke into a keen run in the direction of the sandbar. - - - -CHAPTER XV - -A FEW minutes later Tom was in the shoal water of the bar, wading -toward the Illinois shore. Before the depth reached his middle he was -half-way over; the current would permit no more wading, now, so he -struck out confidently to swim the remaining hundred yards. He swam -quartering upstream, but still was swept downward rather faster than he -had expected. However, he reached the shore finally, and drifted along -till he found a low place and drew himself out. He put his hand on his -jacket pocket, found his piece of bark safe, and then struck through -the woods, following the shore, with streaming garments. Shortly before -ten o'clock he came out into an open place opposite the village, and -saw the ferryboat lying in the shadow of the trees and the high bank. -Everything was quiet under the blinking stars. He crept down the bank, -watching with all his eyes, slipped into the water, swam three or four -strokes and climbed into the skiff that did "yawl" duty at the boat's -stern. He laid himself down under the thwarts and waited, panting. - -Presently the cracked bell tapped and a voice gave the order to "cast -off." A minute or two later the skiff's head was standing high up, -against the boat's swell, and the voyage was begun. Tom felt happy in -his success, for he knew it was the boat's last trip for the night. At -the end of a long twelve or fifteen minutes the wheels stopped, and Tom -slipped overboard and swam ashore in the dusk, landing fifty yards -downstream, out of danger of possible stragglers. - -He flew along unfrequented alleys, and shortly found himself at his -aunt's back fence. He climbed over, approached the "ell," and looked in -at the sitting-room window, for a light was burning there. There sat -Aunt Polly, Sid, Mary, and Joe Harper's mother, grouped together, -talking. They were by the bed, and the bed was between them and the -door. Tom went to the door and began to softly lift the latch; then he -pressed gently and the door yielded a crack; he continued pushing -cautiously, and quaking every time it creaked, till he judged he might -squeeze through on his knees; so he put his head through and began, -warily. - -"What makes the candle blow so?" said Aunt Polly. Tom hurried up. -"Why, that door's open, I believe. Why, of course it is. No end of -strange things now. Go 'long and shut it, Sid." - -Tom disappeared under the bed just in time. He lay and "breathed" -himself for a time, and then crept to where he could almost touch his -aunt's foot. - -"But as I was saying," said Aunt Polly, "he warn't BAD, so to say ---only mischEEvous. Only just giddy, and harum-scarum, you know. He -warn't any more responsible than a colt. HE never meant any harm, and -he was the best-hearted boy that ever was"--and she began to cry. - -"It was just so with my Joe--always full of his devilment, and up to -every kind of mischief, but he was just as unselfish and kind as he -could be--and laws bless me, to think I went and whipped him for taking -that cream, never once recollecting that I throwed it out myself -because it was sour, and I never to see him again in this world, never, -never, never, poor abused boy!" And Mrs. Harper sobbed as if her heart -would break. - -"I hope Tom's better off where he is," said Sid, "but if he'd been -better in some ways--" - -"SID!" Tom felt the glare of the old lady's eye, though he could not -see it. "Not a word against my Tom, now that he's gone! God'll take -care of HIM--never you trouble YOURself, sir! Oh, Mrs. Harper, I don't -know how to give him up! I don't know how to give him up! He was such a -comfort to me, although he tormented my old heart out of me, 'most." - -"The Lord giveth and the Lord hath taken away--Blessed be the name of -the Lord! But it's so hard--Oh, it's so hard! Only last Saturday my -Joe busted a firecracker right under my nose and I knocked him -sprawling. Little did I know then, how soon--Oh, if it was to do over -again I'd hug him and bless him for it." - -"Yes, yes, yes, I know just how you feel, Mrs. Harper, I know just -exactly how you feel. No longer ago than yesterday noon, my Tom took -and filled the cat full of Pain-killer, and I did think the cretur -would tear the house down. And God forgive me, I cracked Tom's head -with my thimble, poor boy, poor dead boy. But he's out of all his -troubles now. And the last words I ever heard him say was to reproach--" - -But this memory was too much for the old lady, and she broke entirely -down. Tom was snuffling, now, himself--and more in pity of himself than -anybody else. He could hear Mary crying, and putting in a kindly word -for him from time to time. He began to have a nobler opinion of himself -than ever before. Still, he was sufficiently touched by his aunt's -grief to long to rush out from under the bed and overwhelm her with -joy--and the theatrical gorgeousness of the thing appealed strongly to -his nature, too, but he resisted and lay still. - -He went on listening, and gathered by odds and ends that it was -conjectured at first that the boys had got drowned while taking a swim; -then the small raft had been missed; next, certain boys said the -missing lads had promised that the village should "hear something" -soon; the wise-heads had "put this and that together" and decided that -the lads had gone off on that raft and would turn up at the next town -below, presently; but toward noon the raft had been found, lodged -against the Missouri shore some five or six miles below the village ---and then hope perished; they must be drowned, else hunger would have -driven them home by nightfall if not sooner. It was believed that the -search for the bodies had been a fruitless effort merely because the -drowning must have occurred in mid-channel, since the boys, being good -swimmers, would otherwise have escaped to shore. This was Wednesday -night. If the bodies continued missing until Sunday, all hope would be -given over, and the funerals would be preached on that morning. Tom -shuddered. - -Mrs. Harper gave a sobbing good-night and turned to go. Then with a -mutual impulse the two bereaved women flung themselves into each -other's arms and had a good, consoling cry, and then parted. Aunt Polly -was tender far beyond her wont, in her good-night to Sid and Mary. Sid -snuffled a bit and Mary went off crying with all her heart. - -Aunt Polly knelt down and prayed for Tom so touchingly, so -appealingly, and with such measureless love in her words and her old -trembling voice, that he was weltering in tears again, long before she -was through. - -He had to keep still long after she went to bed, for she kept making -broken-hearted ejaculations from time to time, tossing unrestfully, and -turning over. But at last she was still, only moaning a little in her -sleep. Now the boy stole out, rose gradually by the bedside, shaded the -candle-light with his hand, and stood regarding her. His heart was full -of pity for her. He took out his sycamore scroll and placed it by the -candle. But something occurred to him, and he lingered considering. His -face lighted with a happy solution of his thought; he put the bark -hastily in his pocket. Then he bent over and kissed the faded lips, and -straightway made his stealthy exit, latching the door behind him. - -He threaded his way back to the ferry landing, found nobody at large -there, and walked boldly on board the boat, for he knew she was -tenantless except that there was a watchman, who always turned in and -slept like a graven image. He untied the skiff at the stern, slipped -into it, and was soon rowing cautiously upstream. When he had pulled a -mile above the village, he started quartering across and bent himself -stoutly to his work. He hit the landing on the other side neatly, for -this was a familiar bit of work to him. He was moved to capture the -skiff, arguing that it might be considered a ship and therefore -legitimate prey for a pirate, but he knew a thorough search would be -made for it and that might end in revelations. So he stepped ashore and -entered the woods. - -He sat down and took a long rest, torturing himself meanwhile to keep -awake, and then started warily down the home-stretch. The night was far -spent. It was broad daylight before he found himself fairly abreast the -island bar. He rested again until the sun was well up and gilding the -great river with its splendor, and then he plunged into the stream. A -little later he paused, dripping, upon the threshold of the camp, and -heard Joe say: - -"No, Tom's true-blue, Huck, and he'll come back. He won't desert. He -knows that would be a disgrace to a pirate, and Tom's too proud for -that sort of thing. He's up to something or other. Now I wonder what?" - -"Well, the things is ours, anyway, ain't they?" - -"Pretty near, but not yet, Huck. The writing says they are if he ain't -back here to breakfast." - -"Which he is!" exclaimed Tom, with fine dramatic effect, stepping -grandly into camp. - -A sumptuous breakfast of bacon and fish was shortly provided, and as -the boys set to work upon it, Tom recounted (and adorned) his -adventures. They were a vain and boastful company of heroes when the -tale was done. Then Tom hid himself away in a shady nook to sleep till -noon, and the other pirates got ready to fish and explore. - - - -CHAPTER XVI - -AFTER dinner all the gang turned out to hunt for turtle eggs on the -bar. They went about poking sticks into the sand, and when they found a -soft place they went down on their knees and dug with their hands. -Sometimes they would take fifty or sixty eggs out of one hole. They -were perfectly round white things a trifle smaller than an English -walnut. They had a famous fried-egg feast that night, and another on -Friday morning. - -After breakfast they went whooping and prancing out on the bar, and -chased each other round and round, shedding clothes as they went, until -they were naked, and then continued the frolic far away up the shoal -water of the bar, against the stiff current, which latter tripped their -legs from under them from time to time and greatly increased the fun. -And now and then they stooped in a group and splashed water in each -other's faces with their palms, gradually approaching each other, with -averted faces to avoid the strangling sprays, and finally gripping and -struggling till the best man ducked his neighbor, and then they all -went under in a tangle of white legs and arms and came up blowing, -sputtering, laughing, and gasping for breath at one and the same time. - -When they were well exhausted, they would run out and sprawl on the -dry, hot sand, and lie there and cover themselves up with it, and by -and by break for the water again and go through the original -performance once more. Finally it occurred to them that their naked -skin represented flesh-colored "tights" very fairly; so they drew a -ring in the sand and had a circus--with three clowns in it, for none -would yield this proudest post to his neighbor. - -Next they got their marbles and played "knucks" and "ring-taw" and -"keeps" till that amusement grew stale. Then Joe and Huck had another -swim, but Tom would not venture, because he found that in kicking off -his trousers he had kicked his string of rattlesnake rattles off his -ankle, and he wondered how he had escaped cramp so long without the -protection of this mysterious charm. He did not venture again until he -had found it, and by that time the other boys were tired and ready to -rest. They gradually wandered apart, dropped into the "dumps," and fell -to gazing longingly across the wide river to where the village lay -drowsing in the sun. Tom found himself writing "BECKY" in the sand with -his big toe; he scratched it out, and was angry with himself for his -weakness. But he wrote it again, nevertheless; he could not help it. He -erased it once more and then took himself out of temptation by driving -the other boys together and joining them. - -But Joe's spirits had gone down almost beyond resurrection. He was so -homesick that he could hardly endure the misery of it. The tears lay -very near the surface. Huck was melancholy, too. Tom was downhearted, -but tried hard not to show it. He had a secret which he was not ready -to tell, yet, but if this mutinous depression was not broken up soon, -he would have to bring it out. He said, with a great show of -cheerfulness: - -"I bet there's been pirates on this island before, boys. We'll explore -it again. They've hid treasures here somewhere. How'd you feel to light -on a rotten chest full of gold and silver--hey?" - -But it roused only faint enthusiasm, which faded out, with no reply. -Tom tried one or two other seductions; but they failed, too. It was -discouraging work. Joe sat poking up the sand with a stick and looking -very gloomy. Finally he said: - -"Oh, boys, let's give it up. I want to go home. It's so lonesome." - -"Oh no, Joe, you'll feel better by and by," said Tom. "Just think of -the fishing that's here." - -"I don't care for fishing. I want to go home." - -"But, Joe, there ain't such another swimming-place anywhere." - -"Swimming's no good. I don't seem to care for it, somehow, when there -ain't anybody to say I sha'n't go in. I mean to go home." - -"Oh, shucks! Baby! You want to see your mother, I reckon." - -"Yes, I DO want to see my mother--and you would, too, if you had one. -I ain't any more baby than you are." And Joe snuffled a little. - -"Well, we'll let the cry-baby go home to his mother, won't we, Huck? -Poor thing--does it want to see its mother? And so it shall. You like -it here, don't you, Huck? We'll stay, won't we?" - -Huck said, "Y-e-s"--without any heart in it. - -"I'll never speak to you again as long as I live," said Joe, rising. -"There now!" And he moved moodily away and began to dress himself. - -"Who cares!" said Tom. "Nobody wants you to. Go 'long home and get -laughed at. Oh, you're a nice pirate. Huck and me ain't cry-babies. -We'll stay, won't we, Huck? Let him go if he wants to. I reckon we can -get along without him, per'aps." - -But Tom was uneasy, nevertheless, and was alarmed to see Joe go -sullenly on with his dressing. And then it was discomforting to see -Huck eying Joe's preparations so wistfully, and keeping up such an -ominous silence. Presently, without a parting word, Joe began to wade -off toward the Illinois shore. Tom's heart began to sink. He glanced at -Huck. Huck could not bear the look, and dropped his eyes. Then he said: - -"I want to go, too, Tom. It was getting so lonesome anyway, and now -it'll be worse. Let's us go, too, Tom." - -"I won't! You can all go, if you want to. I mean to stay." - -"Tom, I better go." - -"Well, go 'long--who's hendering you." - -Huck began to pick up his scattered clothes. He said: - -"Tom, I wisht you'd come, too. Now you think it over. We'll wait for -you when we get to shore." - -"Well, you'll wait a blame long time, that's all." - -Huck started sorrowfully away, and Tom stood looking after him, with a -strong desire tugging at his heart to yield his pride and go along too. -He hoped the boys would stop, but they still waded slowly on. It -suddenly dawned on Tom that it was become very lonely and still. He -made one final struggle with his pride, and then darted after his -comrades, yelling: - -"Wait! Wait! I want to tell you something!" - -They presently stopped and turned around. When he got to where they -were, he began unfolding his secret, and they listened moodily till at -last they saw the "point" he was driving at, and then they set up a -war-whoop of applause and said it was "splendid!" and said if he had -told them at first, they wouldn't have started away. He made a plausible -excuse; but his real reason had been the fear that not even the secret -would keep them with him any very great length of time, and so he had -meant to hold it in reserve as a last seduction. - -The lads came gayly back and went at their sports again with a will, -chattering all the time about Tom's stupendous plan and admiring the -genius of it. After a dainty egg and fish dinner, Tom said he wanted to -learn to smoke, now. Joe caught at the idea and said he would like to -try, too. So Huck made pipes and filled them. These novices had never -smoked anything before but cigars made of grape-vine, and they "bit" -the tongue, and were not considered manly anyway. - -Now they stretched themselves out on their elbows and began to puff, -charily, and with slender confidence. The smoke had an unpleasant -taste, and they gagged a little, but Tom said: - -"Why, it's just as easy! If I'd a knowed this was all, I'd a learnt -long ago." - -"So would I," said Joe. "It's just nothing." - -"Why, many a time I've looked at people smoking, and thought well I -wish I could do that; but I never thought I could," said Tom. - -"That's just the way with me, hain't it, Huck? You've heard me talk -just that way--haven't you, Huck? I'll leave it to Huck if I haven't." - -"Yes--heaps of times," said Huck. - -"Well, I have too," said Tom; "oh, hundreds of times. Once down by the -slaughter-house. Don't you remember, Huck? Bob Tanner was there, and -Johnny Miller, and Jeff Thatcher, when I said it. Don't you remember, -Huck, 'bout me saying that?" - -"Yes, that's so," said Huck. "That was the day after I lost a white -alley. No, 'twas the day before." - -"There--I told you so," said Tom. "Huck recollects it." - -"I bleeve I could smoke this pipe all day," said Joe. "I don't feel -sick." - -"Neither do I," said Tom. "I could smoke it all day. But I bet you -Jeff Thatcher couldn't." - -"Jeff Thatcher! Why, he'd keel over just with two draws. Just let him -try it once. HE'D see!" - -"I bet he would. And Johnny Miller--I wish could see Johnny Miller -tackle it once." - -"Oh, don't I!" said Joe. "Why, I bet you Johnny Miller couldn't any -more do this than nothing. Just one little snifter would fetch HIM." - -"'Deed it would, Joe. Say--I wish the boys could see us now." - -"So do I." - -"Say--boys, don't say anything about it, and some time when they're -around, I'll come up to you and say, 'Joe, got a pipe? I want a smoke.' -And you'll say, kind of careless like, as if it warn't anything, you'll -say, 'Yes, I got my OLD pipe, and another one, but my tobacker ain't -very good.' And I'll say, 'Oh, that's all right, if it's STRONG -enough.' And then you'll out with the pipes, and we'll light up just as -ca'm, and then just see 'em look!" - -"By jings, that'll be gay, Tom! I wish it was NOW!" - -"So do I! And when we tell 'em we learned when we was off pirating, -won't they wish they'd been along?" - -"Oh, I reckon not! I'll just BET they will!" - -So the talk ran on. But presently it began to flag a trifle, and grow -disjointed. The silences widened; the expectoration marvellously -increased. Every pore inside the boys' cheeks became a spouting -fountain; they could scarcely bail out the cellars under their tongues -fast enough to prevent an inundation; little overflowings down their -throats occurred in spite of all they could do, and sudden retchings -followed every time. Both boys were looking very pale and miserable, -now. Joe's pipe dropped from his nerveless fingers. Tom's followed. -Both fountains were going furiously and both pumps bailing with might -and main. Joe said feebly: - -"I've lost my knife. I reckon I better go and find it." - -Tom said, with quivering lips and halting utterance: - -"I'll help you. You go over that way and I'll hunt around by the -spring. No, you needn't come, Huck--we can find it." - -So Huck sat down again, and waited an hour. Then he found it lonesome, -and went to find his comrades. They were wide apart in the woods, both -very pale, both fast asleep. But something informed him that if they -had had any trouble they had got rid of it. - -They were not talkative at supper that night. They had a humble look, -and when Huck prepared his pipe after the meal and was going to prepare -theirs, they said no, they were not feeling very well--something they -ate at dinner had disagreed with them. - -About midnight Joe awoke, and called the boys. There was a brooding -oppressiveness in the air that seemed to bode something. The boys -huddled themselves together and sought the friendly companionship of -the fire, though the dull dead heat of the breathless atmosphere was -stifling. They sat still, intent and waiting. The solemn hush -continued. Beyond the light of the fire everything was swallowed up in -the blackness of darkness. Presently there came a quivering glow that -vaguely revealed the foliage for a moment and then vanished. By and by -another came, a little stronger. Then another. Then a faint moan came -sighing through the branches of the forest and the boys felt a fleeting -breath upon their cheeks, and shuddered with the fancy that the Spirit -of the Night had gone by. There was a pause. Now a weird flash turned -night into day and showed every little grass-blade, separate and -distinct, that grew about their feet. And it showed three white, -startled faces, too. A deep peal of thunder went rolling and tumbling -down the heavens and lost itself in sullen rumblings in the distance. A -sweep of chilly air passed by, rustling all the leaves and snowing the -flaky ashes broadcast about the fire. Another fierce glare lit up the -forest and an instant crash followed that seemed to rend the tree-tops -right over the boys' heads. They clung together in terror, in the thick -gloom that followed. A few big rain-drops fell pattering upon the -leaves. - -"Quick! boys, go for the tent!" exclaimed Tom. - -They sprang away, stumbling over roots and among vines in the dark, no -two plunging in the same direction. A furious blast roared through the -trees, making everything sing as it went. One blinding flash after -another came, and peal on peal of deafening thunder. And now a -drenching rain poured down and the rising hurricane drove it in sheets -along the ground. The boys cried out to each other, but the roaring -wind and the booming thunder-blasts drowned their voices utterly. -However, one by one they straggled in at last and took shelter under -the tent, cold, scared, and streaming with water; but to have company -in misery seemed something to be grateful for. They could not talk, the -old sail flapped so furiously, even if the other noises would have -allowed them. The tempest rose higher and higher, and presently the -sail tore loose from its fastenings and went winging away on the blast. -The boys seized each others' hands and fled, with many tumblings and -bruises, to the shelter of a great oak that stood upon the river-bank. -Now the battle was at its highest. Under the ceaseless conflagration of -lightning that flamed in the skies, everything below stood out in -clean-cut and shadowless distinctness: the bending trees, the billowy -river, white with foam, the driving spray of spume-flakes, the dim -outlines of the high bluffs on the other side, glimpsed through the -drifting cloud-rack and the slanting veil of rain. Every little while -some giant tree yielded the fight and fell crashing through the younger -growth; and the unflagging thunder-peals came now in ear-splitting -explosive bursts, keen and sharp, and unspeakably appalling. The storm -culminated in one matchless effort that seemed likely to tear the island -to pieces, burn it up, drown it to the tree-tops, blow it away, and -deafen every creature in it, all at one and the same moment. It was a -wild night for homeless young heads to be out in. - -But at last the battle was done, and the forces retired with weaker -and weaker threatenings and grumblings, and peace resumed her sway. The -boys went back to camp, a good deal awed; but they found there was -still something to be thankful for, because the great sycamore, the -shelter of their beds, was a ruin, now, blasted by the lightnings, and -they were not under it when the catastrophe happened. - -Everything in camp was drenched, the camp-fire as well; for they were -but heedless lads, like their generation, and had made no provision -against rain. Here was matter for dismay, for they were soaked through -and chilled. They were eloquent in their distress; but they presently -discovered that the fire had eaten so far up under the great log it had -been built against (where it curved upward and separated itself from -the ground), that a handbreadth or so of it had escaped wetting; so -they patiently wrought until, with shreds and bark gathered from the -under sides of sheltered logs, they coaxed the fire to burn again. Then -they piled on great dead boughs till they had a roaring furnace, and -were glad-hearted once more. They dried their boiled ham and had a -feast, and after that they sat by the fire and expanded and glorified -their midnight adventure until morning, for there was not a dry spot to -sleep on, anywhere around. - -As the sun began to steal in upon the boys, drowsiness came over them, -and they went out on the sandbar and lay down to sleep. They got -scorched out by and by, and drearily set about getting breakfast. After -the meal they felt rusty, and stiff-jointed, and a little homesick once -more. Tom saw the signs, and fell to cheering up the pirates as well as -he could. But they cared nothing for marbles, or circus, or swimming, -or anything. He reminded them of the imposing secret, and raised a ray -of cheer. While it lasted, he got them interested in a new device. This -was to knock off being pirates, for a while, and be Indians for a -change. They were attracted by this idea; so it was not long before -they were stripped, and striped from head to heel with black mud, like -so many zebras--all of them chiefs, of course--and then they went -tearing through the woods to attack an English settlement. - -By and by they separated into three hostile tribes, and darted upon -each other from ambush with dreadful war-whoops, and killed and scalped -each other by thousands. It was a gory day. Consequently it was an -extremely satisfactory one. - -They assembled in camp toward supper-time, hungry and happy; but now a -difficulty arose--hostile Indians could not break the bread of -hospitality together without first making peace, and this was a simple -impossibility without smoking a pipe of peace. There was no other -process that ever they had heard of. Two of the savages almost wished -they had remained pirates. However, there was no other way; so with -such show of cheerfulness as they could muster they called for the pipe -and took their whiff as it passed, in due form. - -And behold, they were glad they had gone into savagery, for they had -gained something; they found that they could now smoke a little without -having to go and hunt for a lost knife; they did not get sick enough to -be seriously uncomfortable. They were not likely to fool away this high -promise for lack of effort. No, they practised cautiously, after -supper, with right fair success, and so they spent a jubilant evening. -They were prouder and happier in their new acquirement than they would -have been in the scalping and skinning of the Six Nations. We will -leave them to smoke and chatter and brag, since we have no further use -for them at present. - - - -CHAPTER XVII - -BUT there was no hilarity in the little town that same tranquil -Saturday afternoon. The Harpers, and Aunt Polly's family, were being -put into mourning, with great grief and many tears. An unusual quiet -possessed the village, although it was ordinarily quiet enough, in all -conscience. The villagers conducted their concerns with an absent air, -and talked little; but they sighed often. The Saturday holiday seemed a -burden to the children. They had no heart in their sports, and -gradually gave them up. - -In the afternoon Becky Thatcher found herself moping about the -deserted schoolhouse yard, and feeling very melancholy. But she found -nothing there to comfort her. She soliloquized: - -"Oh, if I only had a brass andiron-knob again! But I haven't got -anything now to remember him by." And she choked back a little sob. - -Presently she stopped, and said to herself: - -"It was right here. Oh, if it was to do over again, I wouldn't say -that--I wouldn't say it for the whole world. But he's gone now; I'll -never, never, never see him any more." - -This thought broke her down, and she wandered away, with tears rolling -down her cheeks. Then quite a group of boys and girls--playmates of -Tom's and Joe's--came by, and stood looking over the paling fence and -talking in reverent tones of how Tom did so-and-so the last time they -saw him, and how Joe said this and that small trifle (pregnant with -awful prophecy, as they could easily see now!)--and each speaker -pointed out the exact spot where the lost lads stood at the time, and -then added something like "and I was a-standing just so--just as I am -now, and as if you was him--I was as close as that--and he smiled, just -this way--and then something seemed to go all over me, like--awful, you -know--and I never thought what it meant, of course, but I can see now!" - -Then there was a dispute about who saw the dead boys last in life, and -many claimed that dismal distinction, and offered evidences, more or -less tampered with by the witness; and when it was ultimately decided -who DID see the departed last, and exchanged the last words with them, -the lucky parties took upon themselves a sort of sacred importance, and -were gaped at and envied by all the rest. One poor chap, who had no -other grandeur to offer, said with tolerably manifest pride in the -remembrance: - -"Well, Tom Sawyer he licked me once." - -But that bid for glory was a failure. Most of the boys could say that, -and so that cheapened the distinction too much. The group loitered -away, still recalling memories of the lost heroes, in awed voices. - -When the Sunday-school hour was finished, the next morning, the bell -began to toll, instead of ringing in the usual way. It was a very still -Sabbath, and the mournful sound seemed in keeping with the musing hush -that lay upon nature. The villagers began to gather, loitering a moment -in the vestibule to converse in whispers about the sad event. But there -was no whispering in the house; only the funereal rustling of dresses -as the women gathered to their seats disturbed the silence there. None -could remember when the little church had been so full before. There -was finally a waiting pause, an expectant dumbness, and then Aunt Polly -entered, followed by Sid and Mary, and they by the Harper family, all -in deep black, and the whole congregation, the old minister as well, -rose reverently and stood until the mourners were seated in the front -pew. There was another communing silence, broken at intervals by -muffled sobs, and then the minister spread his hands abroad and prayed. -A moving hymn was sung, and the text followed: "I am the Resurrection -and the Life." - -As the service proceeded, the clergyman drew such pictures of the -graces, the winning ways, and the rare promise of the lost lads that -every soul there, thinking he recognized these pictures, felt a pang in -remembering that he had persistently blinded himself to them always -before, and had as persistently seen only faults and flaws in the poor -boys. The minister related many a touching incident in the lives of the -departed, too, which illustrated their sweet, generous natures, and the -people could easily see, now, how noble and beautiful those episodes -were, and remembered with grief that at the time they occurred they had -seemed rank rascalities, well deserving of the cowhide. The -congregation became more and more moved, as the pathetic tale went on, -till at last the whole company broke down and joined the weeping -mourners in a chorus of anguished sobs, the preacher himself giving way -to his feelings, and crying in the pulpit. - -There was a rustle in the gallery, which nobody noticed; a moment -later the church door creaked; the minister raised his streaming eyes -above his handkerchief, and stood transfixed! First one and then -another pair of eyes followed the minister's, and then almost with one -impulse the congregation rose and stared while the three dead boys came -marching up the aisle, Tom in the lead, Joe next, and Huck, a ruin of -drooping rags, sneaking sheepishly in the rear! They had been hid in -the unused gallery listening to their own funeral sermon! - -Aunt Polly, Mary, and the Harpers threw themselves upon their restored -ones, smothered them with kisses and poured out thanksgivings, while -poor Huck stood abashed and uncomfortable, not knowing exactly what to -do or where to hide from so many unwelcoming eyes. He wavered, and -started to slink away, but Tom seized him and said: - -"Aunt Polly, it ain't fair. Somebody's got to be glad to see Huck." - -"And so they shall. I'm glad to see him, poor motherless thing!" And -the loving attentions Aunt Polly lavished upon him were the one thing -capable of making him more uncomfortable than he was before. - -Suddenly the minister shouted at the top of his voice: "Praise God -from whom all blessings flow--SING!--and put your hearts in it!" - -And they did. Old Hundred swelled up with a triumphant burst, and -while it shook the rafters Tom Sawyer the Pirate looked around upon the -envying juveniles about him and confessed in his heart that this was -the proudest moment of his life. - -As the "sold" congregation trooped out they said they would almost be -willing to be made ridiculous again to hear Old Hundred sung like that -once more. - -Tom got more cuffs and kisses that day--according to Aunt Polly's -varying moods--than he had earned before in a year; and he hardly knew -which expressed the most gratefulness to God and affection for himself. - - - -CHAPTER XVIII - -THAT was Tom's great secret--the scheme to return home with his -brother pirates and attend their own funerals. They had paddled over to -the Missouri shore on a log, at dusk on Saturday, landing five or six -miles below the village; they had slept in the woods at the edge of the -town till nearly daylight, and had then crept through back lanes and -alleys and finished their sleep in the gallery of the church among a -chaos of invalided benches. - -At breakfast, Monday morning, Aunt Polly and Mary were very loving to -Tom, and very attentive to his wants. There was an unusual amount of -talk. In the course of it Aunt Polly said: - -"Well, I don't say it wasn't a fine joke, Tom, to keep everybody -suffering 'most a week so you boys had a good time, but it is a pity -you could be so hard-hearted as to let me suffer so. If you could come -over on a log to go to your funeral, you could have come over and give -me a hint some way that you warn't dead, but only run off." - -"Yes, you could have done that, Tom," said Mary; "and I believe you -would if you had thought of it." - -"Would you, Tom?" said Aunt Polly, her face lighting wistfully. "Say, -now, would you, if you'd thought of it?" - -"I--well, I don't know. 'Twould 'a' spoiled everything." - -"Tom, I hoped you loved me that much," said Aunt Polly, with a grieved -tone that discomforted the boy. "It would have been something if you'd -cared enough to THINK of it, even if you didn't DO it." - -"Now, auntie, that ain't any harm," pleaded Mary; "it's only Tom's -giddy way--he is always in such a rush that he never thinks of -anything." - -"More's the pity. Sid would have thought. And Sid would have come and -DONE it, too. Tom, you'll look back, some day, when it's too late, and -wish you'd cared a little more for me when it would have cost you so -little." - -"Now, auntie, you know I do care for you," said Tom. - -"I'd know it better if you acted more like it." - -"I wish now I'd thought," said Tom, with a repentant tone; "but I -dreamt about you, anyway. That's something, ain't it?" - -"It ain't much--a cat does that much--but it's better than nothing. -What did you dream?" - -"Why, Wednesday night I dreamt that you was sitting over there by the -bed, and Sid was sitting by the woodbox, and Mary next to him." - -"Well, so we did. So we always do. I'm glad your dreams could take -even that much trouble about us." - -"And I dreamt that Joe Harper's mother was here." - -"Why, she was here! Did you dream any more?" - -"Oh, lots. But it's so dim, now." - -"Well, try to recollect--can't you?" - -"Somehow it seems to me that the wind--the wind blowed the--the--" - -"Try harder, Tom! The wind did blow something. Come!" - -Tom pressed his fingers on his forehead an anxious minute, and then -said: - -"I've got it now! I've got it now! It blowed the candle!" - -"Mercy on us! Go on, Tom--go on!" - -"And it seems to me that you said, 'Why, I believe that that door--'" - -"Go ON, Tom!" - -"Just let me study a moment--just a moment. Oh, yes--you said you -believed the door was open." - -"As I'm sitting here, I did! Didn't I, Mary! Go on!" - -"And then--and then--well I won't be certain, but it seems like as if -you made Sid go and--and--" - -"Well? Well? What did I make him do, Tom? What did I make him do?" - -"You made him--you--Oh, you made him shut it." - -"Well, for the land's sake! I never heard the beat of that in all my -days! Don't tell ME there ain't anything in dreams, any more. Sereny -Harper shall know of this before I'm an hour older. I'd like to see her -get around THIS with her rubbage 'bout superstition. Go on, Tom!" - -"Oh, it's all getting just as bright as day, now. Next you said I -warn't BAD, only mischeevous and harum-scarum, and not any more -responsible than--than--I think it was a colt, or something." - -"And so it was! Well, goodness gracious! Go on, Tom!" - -"And then you began to cry." - -"So I did. So I did. Not the first time, neither. And then--" - -"Then Mrs. Harper she began to cry, and said Joe was just the same, -and she wished she hadn't whipped him for taking cream when she'd -throwed it out her own self--" - -"Tom! The sperrit was upon you! You was a prophesying--that's what you -was doing! Land alive, go on, Tom!" - -"Then Sid he said--he said--" - -"I don't think I said anything," said Sid. - -"Yes you did, Sid," said Mary. - -"Shut your heads and let Tom go on! What did he say, Tom?" - -"He said--I THINK he said he hoped I was better off where I was gone -to, but if I'd been better sometimes--" - -"THERE, d'you hear that! It was his very words!" - -"And you shut him up sharp." - -"I lay I did! There must 'a' been an angel there. There WAS an angel -there, somewheres!" - -"And Mrs. Harper told about Joe scaring her with a firecracker, and -you told about Peter and the Painkiller--" - -"Just as true as I live!" - -"And then there was a whole lot of talk 'bout dragging the river for -us, and 'bout having the funeral Sunday, and then you and old Miss -Harper hugged and cried, and she went." - -"It happened just so! It happened just so, as sure as I'm a-sitting in -these very tracks. Tom, you couldn't told it more like if you'd 'a' -seen it! And then what? Go on, Tom!" - -"Then I thought you prayed for me--and I could see you and hear every -word you said. And you went to bed, and I was so sorry that I took and -wrote on a piece of sycamore bark, 'We ain't dead--we are only off -being pirates,' and put it on the table by the candle; and then you -looked so good, laying there asleep, that I thought I went and leaned -over and kissed you on the lips." - -"Did you, Tom, DID you! I just forgive you everything for that!" And -she seized the boy in a crushing embrace that made him feel like the -guiltiest of villains. - -"It was very kind, even though it was only a--dream," Sid soliloquized -just audibly. - -"Shut up, Sid! A body does just the same in a dream as he'd do if he -was awake. Here's a big Milum apple I've been saving for you, Tom, if -you was ever found again--now go 'long to school. I'm thankful to the -good God and Father of us all I've got you back, that's long-suffering -and merciful to them that believe on Him and keep His word, though -goodness knows I'm unworthy of it, but if only the worthy ones got His -blessings and had His hand to help them over the rough places, there's -few enough would smile here or ever enter into His rest when the long -night comes. Go 'long Sid, Mary, Tom--take yourselves off--you've -hendered me long enough." - -The children left for school, and the old lady to call on Mrs. Harper -and vanquish her realism with Tom's marvellous dream. Sid had better -judgment than to utter the thought that was in his mind as he left the -house. It was this: "Pretty thin--as long a dream as that, without any -mistakes in it!" - -What a hero Tom was become, now! He did not go skipping and prancing, -but moved with a dignified swagger as became a pirate who felt that the -public eye was on him. And indeed it was; he tried not to seem to see -the looks or hear the remarks as he passed along, but they were food -and drink to him. Smaller boys than himself flocked at his heels, as -proud to be seen with him, and tolerated by him, as if he had been the -drummer at the head of a procession or the elephant leading a menagerie -into town. Boys of his own size pretended not to know he had been away -at all; but they were consuming with envy, nevertheless. They would -have given anything to have that swarthy suntanned skin of his, and his -glittering notoriety; and Tom would not have parted with either for a -circus. - -At school the children made so much of him and of Joe, and delivered -such eloquent admiration from their eyes, that the two heroes were not -long in becoming insufferably "stuck-up." They began to tell their -adventures to hungry listeners--but they only began; it was not a thing -likely to have an end, with imaginations like theirs to furnish -material. And finally, when they got out their pipes and went serenely -puffing around, the very summit of glory was reached. - -Tom decided that he could be independent of Becky Thatcher now. Glory -was sufficient. He would live for glory. Now that he was distinguished, -maybe she would be wanting to "make up." Well, let her--she should see -that he could be as indifferent as some other people. Presently she -arrived. Tom pretended not to see her. He moved away and joined a group -of boys and girls and began to talk. Soon he observed that she was -tripping gayly back and forth with flushed face and dancing eyes, -pretending to be busy chasing schoolmates, and screaming with laughter -when she made a capture; but he noticed that she always made her -captures in his vicinity, and that she seemed to cast a conscious eye -in his direction at such times, too. It gratified all the vicious -vanity that was in him; and so, instead of winning him, it only "set -him up" the more and made him the more diligent to avoid betraying that -he knew she was about. Presently she gave over skylarking, and moved -irresolutely about, sighing once or twice and glancing furtively and -wistfully toward Tom. Then she observed that now Tom was talking more -particularly to Amy Lawrence than to any one else. She felt a sharp -pang and grew disturbed and uneasy at once. She tried to go away, but -her feet were treacherous, and carried her to the group instead. She -said to a girl almost at Tom's elbow--with sham vivacity: - -"Why, Mary Austin! you bad girl, why didn't you come to Sunday-school?" - -"I did come--didn't you see me?" - -"Why, no! Did you? Where did you sit?" - -"I was in Miss Peters' class, where I always go. I saw YOU." - -"Did you? Why, it's funny I didn't see you. I wanted to tell you about -the picnic." - -"Oh, that's jolly. Who's going to give it?" - -"My ma's going to let me have one." - -"Oh, goody; I hope she'll let ME come." - -"Well, she will. The picnic's for me. She'll let anybody come that I -want, and I want you." - -"That's ever so nice. When is it going to be?" - -"By and by. Maybe about vacation." - -"Oh, won't it be fun! You going to have all the girls and boys?" - -"Yes, every one that's friends to me--or wants to be"; and she glanced -ever so furtively at Tom, but he talked right along to Amy Lawrence -about the terrible storm on the island, and how the lightning tore the -great sycamore tree "all to flinders" while he was "standing within -three feet of it." - -"Oh, may I come?" said Grace Miller. - -"Yes." - -"And me?" said Sally Rogers. - -"Yes." - -"And me, too?" said Susy Harper. "And Joe?" - -"Yes." - -And so on, with clapping of joyful hands till all the group had begged -for invitations but Tom and Amy. Then Tom turned coolly away, still -talking, and took Amy with him. Becky's lips trembled and the tears -came to her eyes; she hid these signs with a forced gayety and went on -chattering, but the life had gone out of the picnic, now, and out of -everything else; she got away as soon as she could and hid herself and -had what her sex call "a good cry." Then she sat moody, with wounded -pride, till the bell rang. She roused up, now, with a vindictive cast -in her eye, and gave her plaited tails a shake and said she knew what -SHE'D do. - -At recess Tom continued his flirtation with Amy with jubilant -self-satisfaction. And he kept drifting about to find Becky and lacerate -her with the performance. At last he spied her, but there was a sudden -falling of his mercury. She was sitting cosily on a little bench behind -the schoolhouse looking at a picture-book with Alfred Temple--and so -absorbed were they, and their heads so close together over the book, -that they did not seem to be conscious of anything in the world besides. -Jealousy ran red-hot through Tom's veins. He began to hate himself for -throwing away the chance Becky had offered for a reconciliation. He -called himself a fool, and all the hard names he could think of. He -wanted to cry with vexation. Amy chatted happily along, as they walked, -for her heart was singing, but Tom's tongue had lost its function. He -did not hear what Amy was saying, and whenever she paused expectantly he -could only stammer an awkward assent, which was as often misplaced as -otherwise. He kept drifting to the rear of the schoolhouse, again and -again, to sear his eyeballs with the hateful spectacle there. He could -not help it. And it maddened him to see, as he thought he saw, that -Becky Thatcher never once suspected that he was even in the land of the -living. But she did see, nevertheless; and she knew she was winning her -fight, too, and was glad to see him suffer as she had suffered. - -Amy's happy prattle became intolerable. Tom hinted at things he had to -attend to; things that must be done; and time was fleeting. But in -vain--the girl chirped on. Tom thought, "Oh, hang her, ain't I ever -going to get rid of her?" At last he must be attending to those -things--and she said artlessly that she would be "around" when school -let out. And he hastened away, hating her for it. - -"Any other boy!" Tom thought, grating his teeth. "Any boy in the whole -town but that Saint Louis smarty that thinks he dresses so fine and is -aristocracy! Oh, all right, I licked you the first day you ever saw -this town, mister, and I'll lick you again! You just wait till I catch -you out! I'll just take and--" - -And he went through the motions of thrashing an imaginary boy ---pummelling the air, and kicking and gouging. "Oh, you do, do you? You -holler 'nough, do you? Now, then, let that learn you!" And so the -imaginary flogging was finished to his satisfaction. - -Tom fled home at noon. His conscience could not endure any more of -Amy's grateful happiness, and his jealousy could bear no more of the -other distress. Becky resumed her picture inspections with Alfred, but -as the minutes dragged along and no Tom came to suffer, her triumph -began to cloud and she lost interest; gravity and absent-mindedness -followed, and then melancholy; two or three times she pricked up her -ear at a footstep, but it was a false hope; no Tom came. At last she -grew entirely miserable and wished she hadn't carried it so far. When -poor Alfred, seeing that he was losing her, he did not know how, kept -exclaiming: "Oh, here's a jolly one! look at this!" she lost patience -at last, and said, "Oh, don't bother me! I don't care for them!" and -burst into tears, and got up and walked away. - -Alfred dropped alongside and was going to try to comfort her, but she -said: - -"Go away and leave me alone, can't you! I hate you!" - -So the boy halted, wondering what he could have done--for she had said -she would look at pictures all through the nooning--and she walked on, -crying. Then Alfred went musing into the deserted schoolhouse. He was -humiliated and angry. He easily guessed his way to the truth--the girl -had simply made a convenience of him to vent her spite upon Tom Sawyer. -He was far from hating Tom the less when this thought occurred to him. -He wished there was some way to get that boy into trouble without much -risk to himself. Tom's spelling-book fell under his eye. Here was his -opportunity. He gratefully opened to the lesson for the afternoon and -poured ink upon the page. - -Becky, glancing in at a window behind him at the moment, saw the act, -and moved on, without discovering herself. She started homeward, now, -intending to find Tom and tell him; Tom would be thankful and their -troubles would be healed. Before she was half way home, however, she -had changed her mind. The thought of Tom's treatment of her when she -was talking about her picnic came scorching back and filled her with -shame. She resolved to let him get whipped on the damaged -spelling-book's account, and to hate him forever, into the bargain. - - - -CHAPTER XIX - -TOM arrived at home in a dreary mood, and the first thing his aunt -said to him showed him that he had brought his sorrows to an -unpromising market: - -"Tom, I've a notion to skin you alive!" - -"Auntie, what have I done?" - -"Well, you've done enough. Here I go over to Sereny Harper, like an -old softy, expecting I'm going to make her believe all that rubbage -about that dream, when lo and behold you she'd found out from Joe that -you was over here and heard all the talk we had that night. Tom, I -don't know what is to become of a boy that will act like that. It makes -me feel so bad to think you could let me go to Sereny Harper and make -such a fool of myself and never say a word." - -This was a new aspect of the thing. His smartness of the morning had -seemed to Tom a good joke before, and very ingenious. It merely looked -mean and shabby now. He hung his head and could not think of anything -to say for a moment. Then he said: - -"Auntie, I wish I hadn't done it--but I didn't think." - -"Oh, child, you never think. You never think of anything but your own -selfishness. You could think to come all the way over here from -Jackson's Island in the night to laugh at our troubles, and you could -think to fool me with a lie about a dream; but you couldn't ever think -to pity us and save us from sorrow." - -"Auntie, I know now it was mean, but I didn't mean to be mean. I -didn't, honest. And besides, I didn't come over here to laugh at you -that night." - -"What did you come for, then?" - -"It was to tell you not to be uneasy about us, because we hadn't got -drownded." - -"Tom, Tom, I would be the thankfullest soul in this world if I could -believe you ever had as good a thought as that, but you know you never -did--and I know it, Tom." - -"Indeed and 'deed I did, auntie--I wish I may never stir if I didn't." - -"Oh, Tom, don't lie--don't do it. It only makes things a hundred times -worse." - -"It ain't a lie, auntie; it's the truth. I wanted to keep you from -grieving--that was all that made me come." - -"I'd give the whole world to believe that--it would cover up a power -of sins, Tom. I'd 'most be glad you'd run off and acted so bad. But it -ain't reasonable; because, why didn't you tell me, child?" - -"Why, you see, when you got to talking about the funeral, I just got -all full of the idea of our coming and hiding in the church, and I -couldn't somehow bear to spoil it. So I just put the bark back in my -pocket and kept mum." - -"What bark?" - -"The bark I had wrote on to tell you we'd gone pirating. I wish, now, -you'd waked up when I kissed you--I do, honest." - -The hard lines in his aunt's face relaxed and a sudden tenderness -dawned in her eyes. - -"DID you kiss me, Tom?" - -"Why, yes, I did." - -"Are you sure you did, Tom?" - -"Why, yes, I did, auntie--certain sure." - -"What did you kiss me for, Tom?" - -"Because I loved you so, and you laid there moaning and I was so sorry." - -The words sounded like truth. The old lady could not hide a tremor in -her voice when she said: - -"Kiss me again, Tom!--and be off with you to school, now, and don't -bother me any more." - -The moment he was gone, she ran to a closet and got out the ruin of a -jacket which Tom had gone pirating in. Then she stopped, with it in her -hand, and said to herself: - -"No, I don't dare. Poor boy, I reckon he's lied about it--but it's a -blessed, blessed lie, there's such a comfort come from it. I hope the -Lord--I KNOW the Lord will forgive him, because it was such -goodheartedness in him to tell it. But I don't want to find out it's a -lie. I won't look." - -She put the jacket away, and stood by musing a minute. Twice she put -out her hand to take the garment again, and twice she refrained. Once -more she ventured, and this time she fortified herself with the -thought: "It's a good lie--it's a good lie--I won't let it grieve me." -So she sought the jacket pocket. A moment later she was reading Tom's -piece of bark through flowing tears and saying: "I could forgive the -boy, now, if he'd committed a million sins!" - - - -CHAPTER XX - -THERE was something about Aunt Polly's manner, when she kissed Tom, -that swept away his low spirits and made him lighthearted and happy -again. He started to school and had the luck of coming upon Becky -Thatcher at the head of Meadow Lane. His mood always determined his -manner. Without a moment's hesitation he ran to her and said: - -"I acted mighty mean to-day, Becky, and I'm so sorry. I won't ever, -ever do that way again, as long as ever I live--please make up, won't -you?" - -The girl stopped and looked him scornfully in the face: - -"I'll thank you to keep yourself TO yourself, Mr. Thomas Sawyer. I'll -never speak to you again." - -She tossed her head and passed on. Tom was so stunned that he had not -even presence of mind enough to say "Who cares, Miss Smarty?" until the -right time to say it had gone by. So he said nothing. But he was in a -fine rage, nevertheless. He moped into the schoolyard wishing she were -a boy, and imagining how he would trounce her if she were. He presently -encountered her and delivered a stinging remark as he passed. She -hurled one in return, and the angry breach was complete. It seemed to -Becky, in her hot resentment, that she could hardly wait for school to -"take in," she was so impatient to see Tom flogged for the injured -spelling-book. If she had had any lingering notion of exposing Alfred -Temple, Tom's offensive fling had driven it entirely away. - -Poor girl, she did not know how fast she was nearing trouble herself. -The master, Mr. Dobbins, had reached middle age with an unsatisfied -ambition. The darling of his desires was, to be a doctor, but poverty -had decreed that he should be nothing higher than a village -schoolmaster. Every day he took a mysterious book out of his desk and -absorbed himself in it at times when no classes were reciting. He kept -that book under lock and key. There was not an urchin in school but was -perishing to have a glimpse of it, but the chance never came. Every boy -and girl had a theory about the nature of that book; but no two -theories were alike, and there was no way of getting at the facts in -the case. Now, as Becky was passing by the desk, which stood near the -door, she noticed that the key was in the lock! It was a precious -moment. She glanced around; found herself alone, and the next instant -she had the book in her hands. The title-page--Professor Somebody's -ANATOMY--carried no information to her mind; so she began to turn the -leaves. She came at once upon a handsomely engraved and colored -frontispiece--a human figure, stark naked. At that moment a shadow fell -on the page and Tom Sawyer stepped in at the door and caught a glimpse -of the picture. Becky snatched at the book to close it, and had the -hard luck to tear the pictured page half down the middle. She thrust -the volume into the desk, turned the key, and burst out crying with -shame and vexation. - -"Tom Sawyer, you are just as mean as you can be, to sneak up on a -person and look at what they're looking at." - -"How could I know you was looking at anything?" - -"You ought to be ashamed of yourself, Tom Sawyer; you know you're -going to tell on me, and oh, what shall I do, what shall I do! I'll be -whipped, and I never was whipped in school." - -Then she stamped her little foot and said: - -"BE so mean if you want to! I know something that's going to happen. -You just wait and you'll see! Hateful, hateful, hateful!"--and she -flung out of the house with a new explosion of crying. - -Tom stood still, rather flustered by this onslaught. Presently he said -to himself: - -"What a curious kind of a fool a girl is! Never been licked in school! -Shucks! What's a licking! That's just like a girl--they're so -thin-skinned and chicken-hearted. Well, of course I ain't going to tell -old Dobbins on this little fool, because there's other ways of getting -even on her, that ain't so mean; but what of it? Old Dobbins will ask -who it was tore his book. Nobody'll answer. Then he'll do just the way -he always does--ask first one and then t'other, and when he comes to the -right girl he'll know it, without any telling. Girls' faces always tell -on them. They ain't got any backbone. She'll get licked. Well, it's a -kind of a tight place for Becky Thatcher, because there ain't any way -out of it." Tom conned the thing a moment longer, and then added: "All -right, though; she'd like to see me in just such a fix--let her sweat it -out!" - -Tom joined the mob of skylarking scholars outside. In a few moments -the master arrived and school "took in." Tom did not feel a strong -interest in his studies. Every time he stole a glance at the girls' -side of the room Becky's face troubled him. Considering all things, he -did not want to pity her, and yet it was all he could do to help it. He -could get up no exultation that was really worthy the name. Presently -the spelling-book discovery was made, and Tom's mind was entirely full -of his own matters for a while after that. Becky roused up from her -lethargy of distress and showed good interest in the proceedings. She -did not expect that Tom could get out of his trouble by denying that he -spilt the ink on the book himself; and she was right. The denial only -seemed to make the thing worse for Tom. Becky supposed she would be -glad of that, and she tried to believe she was glad of it, but she -found she was not certain. When the worst came to the worst, she had an -impulse to get up and tell on Alfred Temple, but she made an effort and -forced herself to keep still--because, said she to herself, "he'll tell -about me tearing the picture sure. I wouldn't say a word, not to save -his life!" - -Tom took his whipping and went back to his seat not at all -broken-hearted, for he thought it was possible that he had unknowingly -upset the ink on the spelling-book himself, in some skylarking bout--he -had denied it for form's sake and because it was custom, and had stuck -to the denial from principle. - -A whole hour drifted by, the master sat nodding in his throne, the air -was drowsy with the hum of study. By and by, Mr. Dobbins straightened -himself up, yawned, then unlocked his desk, and reached for his book, -but seemed undecided whether to take it out or leave it. Most of the -pupils glanced up languidly, but there were two among them that watched -his movements with intent eyes. Mr. Dobbins fingered his book absently -for a while, then took it out and settled himself in his chair to read! -Tom shot a glance at Becky. He had seen a hunted and helpless rabbit -look as she did, with a gun levelled at its head. Instantly he forgot -his quarrel with her. Quick--something must be done! done in a flash, -too! But the very imminence of the emergency paralyzed his invention. -Good!--he had an inspiration! He would run and snatch the book, spring -through the door and fly. But his resolution shook for one little -instant, and the chance was lost--the master opened the volume. If Tom -only had the wasted opportunity back again! Too late. There was no help -for Becky now, he said. The next moment the master faced the school. -Every eye sank under his gaze. There was that in it which smote even -the innocent with fear. There was silence while one might count ten ---the master was gathering his wrath. Then he spoke: "Who tore this book?" - -There was not a sound. One could have heard a pin drop. The stillness -continued; the master searched face after face for signs of guilt. - -"Benjamin Rogers, did you tear this book?" - -A denial. Another pause. - -"Joseph Harper, did you?" - -Another denial. Tom's uneasiness grew more and more intense under the -slow torture of these proceedings. The master scanned the ranks of -boys--considered a while, then turned to the girls: - -"Amy Lawrence?" - -A shake of the head. - -"Gracie Miller?" - -The same sign. - -"Susan Harper, did you do this?" - -Another negative. The next girl was Becky Thatcher. Tom was trembling -from head to foot with excitement and a sense of the hopelessness of -the situation. - -"Rebecca Thatcher" [Tom glanced at her face--it was white with terror] ---"did you tear--no, look me in the face" [her hands rose in appeal] ---"did you tear this book?" - -A thought shot like lightning through Tom's brain. He sprang to his -feet and shouted--"I done it!" - -The school stared in perplexity at this incredible folly. Tom stood a -moment, to gather his dismembered faculties; and when he stepped -forward to go to his punishment the surprise, the gratitude, the -adoration that shone upon him out of poor Becky's eyes seemed pay -enough for a hundred floggings. Inspired by the splendor of his own -act, he took without an outcry the most merciless flaying that even Mr. -Dobbins had ever administered; and also received with indifference the -added cruelty of a command to remain two hours after school should be -dismissed--for he knew who would wait for him outside till his -captivity was done, and not count the tedious time as loss, either. - -Tom went to bed that night planning vengeance against Alfred Temple; -for with shame and repentance Becky had told him all, not forgetting -her own treachery; but even the longing for vengeance had to give way, -soon, to pleasanter musings, and he fell asleep at last with Becky's -latest words lingering dreamily in his ear-- - -"Tom, how COULD you be so noble!" - - - -CHAPTER XXI - -VACATION was approaching. The schoolmaster, always severe, grew -severer and more exacting than ever, for he wanted the school to make a -good showing on "Examination" day. His rod and his ferule were seldom -idle now--at least among the smaller pupils. Only the biggest boys, and -young ladies of eighteen and twenty, escaped lashing. Mr. Dobbins' -lashings were very vigorous ones, too; for although he carried, under -his wig, a perfectly bald and shiny head, he had only reached middle -age, and there was no sign of feebleness in his muscle. As the great -day approached, all the tyranny that was in him came to the surface; he -seemed to take a vindictive pleasure in punishing the least -shortcomings. The consequence was, that the smaller boys spent their -days in terror and suffering and their nights in plotting revenge. They -threw away no opportunity to do the master a mischief. But he kept -ahead all the time. The retribution that followed every vengeful -success was so sweeping and majestic that the boys always retired from -the field badly worsted. At last they conspired together and hit upon a -plan that promised a dazzling victory. They swore in the sign-painter's -boy, told him the scheme, and asked his help. He had his own reasons -for being delighted, for the master boarded in his father's family and -had given the boy ample cause to hate him. The master's wife would go -on a visit to the country in a few days, and there would be nothing to -interfere with the plan; the master always prepared himself for great -occasions by getting pretty well fuddled, and the sign-painter's boy -said that when the dominie had reached the proper condition on -Examination Evening he would "manage the thing" while he napped in his -chair; then he would have him awakened at the right time and hurried -away to school. - -In the fulness of time the interesting occasion arrived. At eight in -the evening the schoolhouse was brilliantly lighted, and adorned with -wreaths and festoons of foliage and flowers. The master sat throned in -his great chair upon a raised platform, with his blackboard behind him. -He was looking tolerably mellow. Three rows of benches on each side and -six rows in front of him were occupied by the dignitaries of the town -and by the parents of the pupils. To his left, back of the rows of -citizens, was a spacious temporary platform upon which were seated the -scholars who were to take part in the exercises of the evening; rows of -small boys, washed and dressed to an intolerable state of discomfort; -rows of gawky big boys; snowbanks of girls and young ladies clad in -lawn and muslin and conspicuously conscious of their bare arms, their -grandmothers' ancient trinkets, their bits of pink and blue ribbon and -the flowers in their hair. All the rest of the house was filled with -non-participating scholars. - -The exercises began. A very little boy stood up and sheepishly -recited, "You'd scarce expect one of my age to speak in public on the -stage," etc.--accompanying himself with the painfully exact and -spasmodic gestures which a machine might have used--supposing the -machine to be a trifle out of order. But he got through safely, though -cruelly scared, and got a fine round of applause when he made his -manufactured bow and retired. - -A little shamefaced girl lisped, "Mary had a little lamb," etc., -performed a compassion-inspiring curtsy, got her meed of applause, and -sat down flushed and happy. - -Tom Sawyer stepped forward with conceited confidence and soared into -the unquenchable and indestructible "Give me liberty or give me death" -speech, with fine fury and frantic gesticulation, and broke down in the -middle of it. A ghastly stage-fright seized him, his legs quaked under -him and he was like to choke. True, he had the manifest sympathy of the -house but he had the house's silence, too, which was even worse than -its sympathy. The master frowned, and this completed the disaster. Tom -struggled awhile and then retired, utterly defeated. There was a weak -attempt at applause, but it died early. - -"The Boy Stood on the Burning Deck" followed; also "The Assyrian Came -Down," and other declamatory gems. Then there were reading exercises, -and a spelling fight. The meagre Latin class recited with honor. The -prime feature of the evening was in order, now--original "compositions" -by the young ladies. Each in her turn stepped forward to the edge of -the platform, cleared her throat, held up her manuscript (tied with -dainty ribbon), and proceeded to read, with labored attention to -"expression" and punctuation. The themes were the same that had been -illuminated upon similar occasions by their mothers before them, their -grandmothers, and doubtless all their ancestors in the female line -clear back to the Crusades. "Friendship" was one; "Memories of Other -Days"; "Religion in History"; "Dream Land"; "The Advantages of -Culture"; "Forms of Political Government Compared and Contrasted"; -"Melancholy"; "Filial Love"; "Heart Longings," etc., etc. - -A prevalent feature in these compositions was a nursed and petted -melancholy; another was a wasteful and opulent gush of "fine language"; -another was a tendency to lug in by the ears particularly prized words -and phrases until they were worn entirely out; and a peculiarity that -conspicuously marked and marred them was the inveterate and intolerable -sermon that wagged its crippled tail at the end of each and every one -of them. No matter what the subject might be, a brain-racking effort -was made to squirm it into some aspect or other that the moral and -religious mind could contemplate with edification. The glaring -insincerity of these sermons was not sufficient to compass the -banishment of the fashion from the schools, and it is not sufficient -to-day; it never will be sufficient while the world stands, perhaps. -There is no school in all our land where the young ladies do not feel -obliged to close their compositions with a sermon; and you will find -that the sermon of the most frivolous and the least religious girl in -the school is always the longest and the most relentlessly pious. But -enough of this. Homely truth is unpalatable. - -Let us return to the "Examination." The first composition that was -read was one entitled "Is this, then, Life?" Perhaps the reader can -endure an extract from it: - - "In the common walks of life, with what delightful - emotions does the youthful mind look forward to some - anticipated scene of festivity! Imagination is busy - sketching rose-tinted pictures of joy. In fancy, the - voluptuous votary of fashion sees herself amid the - festive throng, 'the observed of all observers.' Her - graceful form, arrayed in snowy robes, is whirling - through the mazes of the joyous dance; her eye is - brightest, her step is lightest in the gay assembly. - - "In such delicious fancies time quickly glides by, - and the welcome hour arrives for her entrance into - the Elysian world, of which she has had such bright - dreams. How fairy-like does everything appear to - her enchanted vision! Each new scene is more charming - than the last. But after a while she finds that - beneath this goodly exterior, all is vanity, the - flattery which once charmed her soul, now grates - harshly upon her ear; the ball-room has lost its - charms; and with wasted health and imbittered heart, - she turns away with the conviction that earthly - pleasures cannot satisfy the longings of the soul!" - -And so forth and so on. There was a buzz of gratification from time to -time during the reading, accompanied by whispered ejaculations of "How -sweet!" "How eloquent!" "So true!" etc., and after the thing had closed -with a peculiarly afflicting sermon the applause was enthusiastic. - -Then arose a slim, melancholy girl, whose face had the "interesting" -paleness that comes of pills and indigestion, and read a "poem." Two -stanzas of it will do: - - "A MISSOURI MAIDEN'S FAREWELL TO ALABAMA - - "Alabama, good-bye! I love thee well! - But yet for a while do I leave thee now! - Sad, yes, sad thoughts of thee my heart doth swell, - And burning recollections throng my brow! - For I have wandered through thy flowery woods; - Have roamed and read near Tallapoosa's stream; - Have listened to Tallassee's warring floods, - And wooed on Coosa's side Aurora's beam. - - "Yet shame I not to bear an o'er-full heart, - Nor blush to turn behind my tearful eyes; - 'Tis from no stranger land I now must part, - 'Tis to no strangers left I yield these sighs. - Welcome and home were mine within this State, - Whose vales I leave--whose spires fade fast from me - And cold must be mine eyes, and heart, and tete, - When, dear Alabama! they turn cold on thee!" - -There were very few there who knew what "tete" meant, but the poem was -very satisfactory, nevertheless. - -Next appeared a dark-complexioned, black-eyed, black-haired young -lady, who paused an impressive moment, assumed a tragic expression, and -began to read in a measured, solemn tone: - - "A VISION - - "Dark and tempestuous was night. Around the - throne on high not a single star quivered; but - the deep intonations of the heavy thunder - constantly vibrated upon the ear; whilst the - terrific lightning revelled in angry mood - through the cloudy chambers of heaven, seeming - to scorn the power exerted over its terror by - the illustrious Franklin! Even the boisterous - winds unanimously came forth from their mystic - homes, and blustered about as if to enhance by - their aid the wildness of the scene. - - "At such a time, so dark, so dreary, for human - sympathy my very spirit sighed; but instead thereof, - - "'My dearest friend, my counsellor, my comforter - and guide--My joy in grief, my second bliss - in joy,' came to my side. She moved like one of - those bright beings pictured in the sunny walks - of fancy's Eden by the romantic and young, a - queen of beauty unadorned save by her own - transcendent loveliness. So soft was her step, it - failed to make even a sound, and but for the - magical thrill imparted by her genial touch, as - other unobtrusive beauties, she would have glided - away un-perceived--unsought. A strange sadness - rested upon her features, like icy tears upon - the robe of December, as she pointed to the - contending elements without, and bade me contemplate - the two beings presented." - -This nightmare occupied some ten pages of manuscript and wound up with -a sermon so destructive of all hope to non-Presbyterians that it took -the first prize. This composition was considered to be the very finest -effort of the evening. The mayor of the village, in delivering the -prize to the author of it, made a warm speech in which he said that it -was by far the most "eloquent" thing he had ever listened to, and that -Daniel Webster himself might well be proud of it. - -It may be remarked, in passing, that the number of compositions in -which the word "beauteous" was over-fondled, and human experience -referred to as "life's page," was up to the usual average. - -Now the master, mellow almost to the verge of geniality, put his chair -aside, turned his back to the audience, and began to draw a map of -America on the blackboard, to exercise the geography class upon. But he -made a sad business of it with his unsteady hand, and a smothered -titter rippled over the house. He knew what the matter was, and set -himself to right it. He sponged out lines and remade them; but he only -distorted them more than ever, and the tittering was more pronounced. -He threw his entire attention upon his work, now, as if determined not -to be put down by the mirth. He felt that all eyes were fastened upon -him; he imagined he was succeeding, and yet the tittering continued; it -even manifestly increased. And well it might. There was a garret above, -pierced with a scuttle over his head; and down through this scuttle -came a cat, suspended around the haunches by a string; she had a rag -tied about her head and jaws to keep her from mewing; as she slowly -descended she curved upward and clawed at the string, she swung -downward and clawed at the intangible air. The tittering rose higher -and higher--the cat was within six inches of the absorbed teacher's -head--down, down, a little lower, and she grabbed his wig with her -desperate claws, clung to it, and was snatched up into the garret in an -instant with her trophy still in her possession! And how the light did -blaze abroad from the master's bald pate--for the sign-painter's boy -had GILDED it! - -That broke up the meeting. The boys were avenged. Vacation had come. - - NOTE:--The pretended "compositions" quoted in - this chapter are taken without alteration from a - volume entitled "Prose and Poetry, by a Western - Lady"--but they are exactly and precisely after - the schoolgirl pattern, and hence are much - happier than any mere imitations could be. - - - -CHAPTER XXII - -TOM joined the new order of Cadets of Temperance, being attracted by -the showy character of their "regalia." He promised to abstain from -smoking, chewing, and profanity as long as he remained a member. Now he -found out a new thing--namely, that to promise not to do a thing is the -surest way in the world to make a body want to go and do that very -thing. Tom soon found himself tormented with a desire to drink and -swear; the desire grew to be so intense that nothing but the hope of a -chance to display himself in his red sash kept him from withdrawing -from the order. Fourth of July was coming; but he soon gave that up ---gave it up before he had worn his shackles over forty-eight hours--and -fixed his hopes upon old Judge Frazer, justice of the peace, who was -apparently on his deathbed and would have a big public funeral, since -he was so high an official. During three days Tom was deeply concerned -about the Judge's condition and hungry for news of it. Sometimes his -hopes ran high--so high that he would venture to get out his regalia -and practise before the looking-glass. But the Judge had a most -discouraging way of fluctuating. At last he was pronounced upon the -mend--and then convalescent. Tom was disgusted; and felt a sense of -injury, too. He handed in his resignation at once--and that night the -Judge suffered a relapse and died. Tom resolved that he would never -trust a man like that again. - -The funeral was a fine thing. The Cadets paraded in a style calculated -to kill the late member with envy. Tom was a free boy again, however ---there was something in that. He could drink and swear, now--but found -to his surprise that he did not want to. The simple fact that he could, -took the desire away, and the charm of it. - -Tom presently wondered to find that his coveted vacation was beginning -to hang a little heavily on his hands. - -He attempted a diary--but nothing happened during three days, and so -he abandoned it. - -The first of all the negro minstrel shows came to town, and made a -sensation. Tom and Joe Harper got up a band of performers and were -happy for two days. - -Even the Glorious Fourth was in some sense a failure, for it rained -hard, there was no procession in consequence, and the greatest man in -the world (as Tom supposed), Mr. Benton, an actual United States -Senator, proved an overwhelming disappointment--for he was not -twenty-five feet high, nor even anywhere in the neighborhood of it. - -A circus came. The boys played circus for three days afterward in -tents made of rag carpeting--admission, three pins for boys, two for -girls--and then circusing was abandoned. - -A phrenologist and a mesmerizer came--and went again and left the -village duller and drearier than ever. - -There were some boys-and-girls' parties, but they were so few and so -delightful that they only made the aching voids between ache the harder. - -Becky Thatcher was gone to her Constantinople home to stay with her -parents during vacation--so there was no bright side to life anywhere. - -The dreadful secret of the murder was a chronic misery. It was a very -cancer for permanency and pain. - -Then came the measles. - -During two long weeks Tom lay a prisoner, dead to the world and its -happenings. He was very ill, he was interested in nothing. When he got -upon his feet at last and moved feebly down-town, a melancholy change -had come over everything and every creature. There had been a -"revival," and everybody had "got religion," not only the adults, but -even the boys and girls. Tom went about, hoping against hope for the -sight of one blessed sinful face, but disappointment crossed him -everywhere. He found Joe Harper studying a Testament, and turned sadly -away from the depressing spectacle. He sought Ben Rogers, and found him -visiting the poor with a basket of tracts. He hunted up Jim Hollis, who -called his attention to the precious blessing of his late measles as a -warning. Every boy he encountered added another ton to his depression; -and when, in desperation, he flew for refuge at last to the bosom of -Huckleberry Finn and was received with a Scriptural quotation, his -heart broke and he crept home and to bed realizing that he alone of all -the town was lost, forever and forever. - -And that night there came on a terrific storm, with driving rain, -awful claps of thunder and blinding sheets of lightning. He covered his -head with the bedclothes and waited in a horror of suspense for his -doom; for he had not the shadow of a doubt that all this hubbub was -about him. He believed he had taxed the forbearance of the powers above -to the extremity of endurance and that this was the result. It might -have seemed to him a waste of pomp and ammunition to kill a bug with a -battery of artillery, but there seemed nothing incongruous about the -getting up such an expensive thunderstorm as this to knock the turf -from under an insect like himself. - -By and by the tempest spent itself and died without accomplishing its -object. The boy's first impulse was to be grateful, and reform. His -second was to wait--for there might not be any more storms. - -The next day the doctors were back; Tom had relapsed. The three weeks -he spent on his back this time seemed an entire age. When he got abroad -at last he was hardly grateful that he had been spared, remembering how -lonely was his estate, how companionless and forlorn he was. He drifted -listlessly down the street and found Jim Hollis acting as judge in a -juvenile court that was trying a cat for murder, in the presence of her -victim, a bird. He found Joe Harper and Huck Finn up an alley eating a -stolen melon. Poor lads! they--like Tom--had suffered a relapse. - - - -CHAPTER XXIII - -AT last the sleepy atmosphere was stirred--and vigorously: the murder -trial came on in the court. It became the absorbing topic of village -talk immediately. Tom could not get away from it. Every reference to -the murder sent a shudder to his heart, for his troubled conscience and -fears almost persuaded him that these remarks were put forth in his -hearing as "feelers"; he did not see how he could be suspected of -knowing anything about the murder, but still he could not be -comfortable in the midst of this gossip. It kept him in a cold shiver -all the time. He took Huck to a lonely place to have a talk with him. -It would be some relief to unseal his tongue for a little while; to -divide his burden of distress with another sufferer. Moreover, he -wanted to assure himself that Huck had remained discreet. - -"Huck, have you ever told anybody about--that?" - -"'Bout what?" - -"You know what." - -"Oh--'course I haven't." - -"Never a word?" - -"Never a solitary word, so help me. What makes you ask?" - -"Well, I was afeard." - -"Why, Tom Sawyer, we wouldn't be alive two days if that got found out. -YOU know that." - -Tom felt more comfortable. After a pause: - -"Huck, they couldn't anybody get you to tell, could they?" - -"Get me to tell? Why, if I wanted that half-breed devil to drownd me -they could get me to tell. They ain't no different way." - -"Well, that's all right, then. I reckon we're safe as long as we keep -mum. But let's swear again, anyway. It's more surer." - -"I'm agreed." - -So they swore again with dread solemnities. - -"What is the talk around, Huck? I've heard a power of it." - -"Talk? Well, it's just Muff Potter, Muff Potter, Muff Potter all the -time. It keeps me in a sweat, constant, so's I want to hide som'ers." - -"That's just the same way they go on round me. I reckon he's a goner. -Don't you feel sorry for him, sometimes?" - -"Most always--most always. He ain't no account; but then he hain't -ever done anything to hurt anybody. Just fishes a little, to get money -to get drunk on--and loafs around considerable; but lord, we all do -that--leastways most of us--preachers and such like. But he's kind of -good--he give me half a fish, once, when there warn't enough for two; -and lots of times he's kind of stood by me when I was out of luck." - -"Well, he's mended kites for me, Huck, and knitted hooks on to my -line. I wish we could get him out of there." - -"My! we couldn't get him out, Tom. And besides, 'twouldn't do any -good; they'd ketch him again." - -"Yes--so they would. But I hate to hear 'em abuse him so like the -dickens when he never done--that." - -"I do too, Tom. Lord, I hear 'em say he's the bloodiest looking -villain in this country, and they wonder he wasn't ever hung before." - -"Yes, they talk like that, all the time. I've heard 'em say that if he -was to get free they'd lynch him." - -"And they'd do it, too." - -The boys had a long talk, but it brought them little comfort. As the -twilight drew on, they found themselves hanging about the neighborhood -of the little isolated jail, perhaps with an undefined hope that -something would happen that might clear away their difficulties. But -nothing happened; there seemed to be no angels or fairies interested in -this luckless captive. - -The boys did as they had often done before--went to the cell grating -and gave Potter some tobacco and matches. He was on the ground floor -and there were no guards. - -His gratitude for their gifts had always smote their consciences -before--it cut deeper than ever, this time. They felt cowardly and -treacherous to the last degree when Potter said: - -"You've been mighty good to me, boys--better'n anybody else in this -town. And I don't forget it, I don't. Often I says to myself, says I, -'I used to mend all the boys' kites and things, and show 'em where the -good fishin' places was, and befriend 'em what I could, and now they've -all forgot old Muff when he's in trouble; but Tom don't, and Huck -don't--THEY don't forget him, says I, 'and I don't forget them.' Well, -boys, I done an awful thing--drunk and crazy at the time--that's the -only way I account for it--and now I got to swing for it, and it's -right. Right, and BEST, too, I reckon--hope so, anyway. Well, we won't -talk about that. I don't want to make YOU feel bad; you've befriended -me. But what I want to say, is, don't YOU ever get drunk--then you won't -ever get here. Stand a litter furder west--so--that's it; it's a prime -comfort to see faces that's friendly when a body's in such a muck of -trouble, and there don't none come here but yourn. Good friendly -faces--good friendly faces. Git up on one another's backs and let me -touch 'em. That's it. Shake hands--yourn'll come through the bars, but -mine's too big. Little hands, and weak--but they've helped Muff Potter -a power, and they'd help him more if they could." - -Tom went home miserable, and his dreams that night were full of -horrors. The next day and the day after, he hung about the court-room, -drawn by an almost irresistible impulse to go in, but forcing himself -to stay out. Huck was having the same experience. They studiously -avoided each other. Each wandered away, from time to time, but the same -dismal fascination always brought them back presently. Tom kept his -ears open when idlers sauntered out of the court-room, but invariably -heard distressing news--the toils were closing more and more -relentlessly around poor Potter. At the end of the second day the -village talk was to the effect that Injun Joe's evidence stood firm and -unshaken, and that there was not the slightest question as to what the -jury's verdict would be. - -Tom was out late, that night, and came to bed through the window. He -was in a tremendous state of excitement. It was hours before he got to -sleep. All the village flocked to the court-house the next morning, for -this was to be the great day. Both sexes were about equally represented -in the packed audience. After a long wait the jury filed in and took -their places; shortly afterward, Potter, pale and haggard, timid and -hopeless, was brought in, with chains upon him, and seated where all -the curious eyes could stare at him; no less conspicuous was Injun Joe, -stolid as ever. There was another pause, and then the judge arrived and -the sheriff proclaimed the opening of the court. The usual whisperings -among the lawyers and gathering together of papers followed. These -details and accompanying delays worked up an atmosphere of preparation -that was as impressive as it was fascinating. - -Now a witness was called who testified that he found Muff Potter -washing in the brook, at an early hour of the morning that the murder -was discovered, and that he immediately sneaked away. After some -further questioning, counsel for the prosecution said: - -"Take the witness." - -The prisoner raised his eyes for a moment, but dropped them again when -his own counsel said: - -"I have no questions to ask him." - -The next witness proved the finding of the knife near the corpse. -Counsel for the prosecution said: - -"Take the witness." - -"I have no questions to ask him," Potter's lawyer replied. - -A third witness swore he had often seen the knife in Potter's -possession. - -"Take the witness." - -Counsel for Potter declined to question him. The faces of the audience -began to betray annoyance. Did this attorney mean to throw away his -client's life without an effort? - -Several witnesses deposed concerning Potter's guilty behavior when -brought to the scene of the murder. They were allowed to leave the -stand without being cross-questioned. - -Every detail of the damaging circumstances that occurred in the -graveyard upon that morning which all present remembered so well was -brought out by credible witnesses, but none of them were cross-examined -by Potter's lawyer. The perplexity and dissatisfaction of the house -expressed itself in murmurs and provoked a reproof from the bench. -Counsel for the prosecution now said: - -"By the oaths of citizens whose simple word is above suspicion, we -have fastened this awful crime, beyond all possibility of question, -upon the unhappy prisoner at the bar. We rest our case here." - -A groan escaped from poor Potter, and he put his face in his hands and -rocked his body softly to and fro, while a painful silence reigned in -the court-room. Many men were moved, and many women's compassion -testified itself in tears. Counsel for the defence rose and said: - -"Your honor, in our remarks at the opening of this trial, we -foreshadowed our purpose to prove that our client did this fearful deed -while under the influence of a blind and irresponsible delirium -produced by drink. We have changed our mind. We shall not offer that -plea." [Then to the clerk:] "Call Thomas Sawyer!" - -A puzzled amazement awoke in every face in the house, not even -excepting Potter's. Every eye fastened itself with wondering interest -upon Tom as he rose and took his place upon the stand. The boy looked -wild enough, for he was badly scared. The oath was administered. - -"Thomas Sawyer, where were you on the seventeenth of June, about the -hour of midnight?" - -Tom glanced at Injun Joe's iron face and his tongue failed him. The -audience listened breathless, but the words refused to come. After a -few moments, however, the boy got a little of his strength back, and -managed to put enough of it into his voice to make part of the house -hear: - -"In the graveyard!" - -"A little bit louder, please. Don't be afraid. You were--" - -"In the graveyard." - -A contemptuous smile flitted across Injun Joe's face. - -"Were you anywhere near Horse Williams' grave?" - -"Yes, sir." - -"Speak up--just a trifle louder. How near were you?" - -"Near as I am to you." - -"Were you hidden, or not?" - -"I was hid." - -"Where?" - -"Behind the elms that's on the edge of the grave." - -Injun Joe gave a barely perceptible start. - -"Any one with you?" - -"Yes, sir. I went there with--" - -"Wait--wait a moment. Never mind mentioning your companion's name. We -will produce him at the proper time. Did you carry anything there with -you." - -Tom hesitated and looked confused. - -"Speak out, my boy--don't be diffident. The truth is always -respectable. What did you take there?" - -"Only a--a--dead cat." - -There was a ripple of mirth, which the court checked. - -"We will produce the skeleton of that cat. Now, my boy, tell us -everything that occurred--tell it in your own way--don't skip anything, -and don't be afraid." - -Tom began--hesitatingly at first, but as he warmed to his subject his -words flowed more and more easily; in a little while every sound ceased -but his own voice; every eye fixed itself upon him; with parted lips -and bated breath the audience hung upon his words, taking no note of -time, rapt in the ghastly fascinations of the tale. The strain upon -pent emotion reached its climax when the boy said: - -"--and as the doctor fetched the board around and Muff Potter fell, -Injun Joe jumped with the knife and--" - -Crash! Quick as lightning the half-breed sprang for a window, tore his -way through all opposers, and was gone! - - - -CHAPTER XXIV - -TOM was a glittering hero once more--the pet of the old, the envy of -the young. His name even went into immortal print, for the village -paper magnified him. There were some that believed he would be -President, yet, if he escaped hanging. - -As usual, the fickle, unreasoning world took Muff Potter to its bosom -and fondled him as lavishly as it had abused him before. But that sort -of conduct is to the world's credit; therefore it is not well to find -fault with it. - -Tom's days were days of splendor and exultation to him, but his nights -were seasons of horror. Injun Joe infested all his dreams, and always -with doom in his eye. Hardly any temptation could persuade the boy to -stir abroad after nightfall. Poor Huck was in the same state of -wretchedness and terror, for Tom had told the whole story to the lawyer -the night before the great day of the trial, and Huck was sore afraid -that his share in the business might leak out, yet, notwithstanding -Injun Joe's flight had saved him the suffering of testifying in court. -The poor fellow had got the attorney to promise secrecy, but what of -that? Since Tom's harassed conscience had managed to drive him to the -lawyer's house by night and wring a dread tale from lips that had been -sealed with the dismalest and most formidable of oaths, Huck's -confidence in the human race was well-nigh obliterated. - -Daily Muff Potter's gratitude made Tom glad he had spoken; but nightly -he wished he had sealed up his tongue. - -Half the time Tom was afraid Injun Joe would never be captured; the -other half he was afraid he would be. He felt sure he never could draw -a safe breath again until that man was dead and he had seen the corpse. - -Rewards had been offered, the country had been scoured, but no Injun -Joe was found. One of those omniscient and awe-inspiring marvels, a -detective, came up from St. Louis, moused around, shook his head, -looked wise, and made that sort of astounding success which members of -that craft usually achieve. That is to say, he "found a clew." But you -can't hang a "clew" for murder, and so after that detective had got -through and gone home, Tom felt just as insecure as he was before. - -The slow days drifted on, and each left behind it a slightly lightened -weight of apprehension. - - - -CHAPTER XXV - -THERE comes a time in every rightly-constructed boy's life when he has -a raging desire to go somewhere and dig for hidden treasure. This -desire suddenly came upon Tom one day. He sallied out to find Joe -Harper, but failed of success. Next he sought Ben Rogers; he had gone -fishing. Presently he stumbled upon Huck Finn the Red-Handed. Huck -would answer. Tom took him to a private place and opened the matter to -him confidentially. Huck was willing. Huck was always willing to take a -hand in any enterprise that offered entertainment and required no -capital, for he had a troublesome superabundance of that sort of time -which is not money. "Where'll we dig?" said Huck. - -"Oh, most anywhere." - -"Why, is it hid all around?" - -"No, indeed it ain't. It's hid in mighty particular places, Huck ---sometimes on islands, sometimes in rotten chests under the end of a -limb of an old dead tree, just where the shadow falls at midnight; but -mostly under the floor in ha'nted houses." - -"Who hides it?" - -"Why, robbers, of course--who'd you reckon? Sunday-school -sup'rintendents?" - -"I don't know. If 'twas mine I wouldn't hide it; I'd spend it and have -a good time." - -"So would I. But robbers don't do that way. They always hide it and -leave it there." - -"Don't they come after it any more?" - -"No, they think they will, but they generally forget the marks, or -else they die. Anyway, it lays there a long time and gets rusty; and by -and by somebody finds an old yellow paper that tells how to find the -marks--a paper that's got to be ciphered over about a week because it's -mostly signs and hy'roglyphics." - -"Hyro--which?" - -"Hy'roglyphics--pictures and things, you know, that don't seem to mean -anything." - -"Have you got one of them papers, Tom?" - -"No." - -"Well then, how you going to find the marks?" - -"I don't want any marks. They always bury it under a ha'nted house or -on an island, or under a dead tree that's got one limb sticking out. -Well, we've tried Jackson's Island a little, and we can try it again -some time; and there's the old ha'nted house up the Still-House branch, -and there's lots of dead-limb trees--dead loads of 'em." - -"Is it under all of them?" - -"How you talk! No!" - -"Then how you going to know which one to go for?" - -"Go for all of 'em!" - -"Why, Tom, it'll take all summer." - -"Well, what of that? Suppose you find a brass pot with a hundred -dollars in it, all rusty and gray, or rotten chest full of di'monds. -How's that?" - -Huck's eyes glowed. - -"That's bully. Plenty bully enough for me. Just you gimme the hundred -dollars and I don't want no di'monds." - -"All right. But I bet you I ain't going to throw off on di'monds. Some -of 'em's worth twenty dollars apiece--there ain't any, hardly, but's -worth six bits or a dollar." - -"No! Is that so?" - -"Cert'nly--anybody'll tell you so. Hain't you ever seen one, Huck?" - -"Not as I remember." - -"Oh, kings have slathers of them." - -"Well, I don' know no kings, Tom." - -"I reckon you don't. But if you was to go to Europe you'd see a raft -of 'em hopping around." - -"Do they hop?" - -"Hop?--your granny! No!" - -"Well, what did you say they did, for?" - -"Shucks, I only meant you'd SEE 'em--not hopping, of course--what do -they want to hop for?--but I mean you'd just see 'em--scattered around, -you know, in a kind of a general way. Like that old humpbacked Richard." - -"Richard? What's his other name?" - -"He didn't have any other name. Kings don't have any but a given name." - -"No?" - -"But they don't." - -"Well, if they like it, Tom, all right; but I don't want to be a king -and have only just a given name, like a nigger. But say--where you -going to dig first?" - -"Well, I don't know. S'pose we tackle that old dead-limb tree on the -hill t'other side of Still-House branch?" - -"I'm agreed." - -So they got a crippled pick and a shovel, and set out on their -three-mile tramp. They arrived hot and panting, and threw themselves -down in the shade of a neighboring elm to rest and have a smoke. - -"I like this," said Tom. - -"So do I." - -"Say, Huck, if we find a treasure here, what you going to do with your -share?" - -"Well, I'll have pie and a glass of soda every day, and I'll go to -every circus that comes along. I bet I'll have a gay time." - -"Well, ain't you going to save any of it?" - -"Save it? What for?" - -"Why, so as to have something to live on, by and by." - -"Oh, that ain't any use. Pap would come back to thish-yer town some -day and get his claws on it if I didn't hurry up, and I tell you he'd -clean it out pretty quick. What you going to do with yourn, Tom?" - -"I'm going to buy a new drum, and a sure-'nough sword, and a red -necktie and a bull pup, and get married." - -"Married!" - -"That's it." - -"Tom, you--why, you ain't in your right mind." - -"Wait--you'll see." - -"Well, that's the foolishest thing you could do. Look at pap and my -mother. Fight! Why, they used to fight all the time. I remember, mighty -well." - -"That ain't anything. The girl I'm going to marry won't fight." - -"Tom, I reckon they're all alike. They'll all comb a body. Now you -better think 'bout this awhile. I tell you you better. What's the name -of the gal?" - -"It ain't a gal at all--it's a girl." - -"It's all the same, I reckon; some says gal, some says girl--both's -right, like enough. Anyway, what's her name, Tom?" - -"I'll tell you some time--not now." - -"All right--that'll do. Only if you get married I'll be more lonesomer -than ever." - -"No you won't. You'll come and live with me. Now stir out of this and -we'll go to digging." - -They worked and sweated for half an hour. No result. They toiled -another half-hour. Still no result. Huck said: - -"Do they always bury it as deep as this?" - -"Sometimes--not always. Not generally. I reckon we haven't got the -right place." - -So they chose a new spot and began again. The labor dragged a little, -but still they made progress. They pegged away in silence for some -time. Finally Huck leaned on his shovel, swabbed the beaded drops from -his brow with his sleeve, and said: - -"Where you going to dig next, after we get this one?" - -"I reckon maybe we'll tackle the old tree that's over yonder on -Cardiff Hill back of the widow's." - -"I reckon that'll be a good one. But won't the widow take it away from -us, Tom? It's on her land." - -"SHE take it away! Maybe she'd like to try it once. Whoever finds one -of these hid treasures, it belongs to him. It don't make any difference -whose land it's on." - -That was satisfactory. The work went on. By and by Huck said: - -"Blame it, we must be in the wrong place again. What do you think?" - -"It is mighty curious, Huck. I don't understand it. Sometimes witches -interfere. I reckon maybe that's what's the trouble now." - -"Shucks! Witches ain't got no power in the daytime." - -"Well, that's so. I didn't think of that. Oh, I know what the matter -is! What a blamed lot of fools we are! You got to find out where the -shadow of the limb falls at midnight, and that's where you dig!" - -"Then consound it, we've fooled away all this work for nothing. Now -hang it all, we got to come back in the night. It's an awful long way. -Can you get out?" - -"I bet I will. We've got to do it to-night, too, because if somebody -sees these holes they'll know in a minute what's here and they'll go -for it." - -"Well, I'll come around and maow to-night." - -"All right. Let's hide the tools in the bushes." - -The boys were there that night, about the appointed time. They sat in -the shadow waiting. It was a lonely place, and an hour made solemn by -old traditions. Spirits whispered in the rustling leaves, ghosts lurked -in the murky nooks, the deep baying of a hound floated up out of the -distance, an owl answered with his sepulchral note. The boys were -subdued by these solemnities, and talked little. By and by they judged -that twelve had come; they marked where the shadow fell, and began to -dig. Their hopes commenced to rise. Their interest grew stronger, and -their industry kept pace with it. The hole deepened and still deepened, -but every time their hearts jumped to hear the pick strike upon -something, they only suffered a new disappointment. It was only a stone -or a chunk. At last Tom said: - -"It ain't any use, Huck, we're wrong again." - -"Well, but we CAN'T be wrong. We spotted the shadder to a dot." - -"I know it, but then there's another thing." - -"What's that?". - -"Why, we only guessed at the time. Like enough it was too late or too -early." - -Huck dropped his shovel. - -"That's it," said he. "That's the very trouble. We got to give this -one up. We can't ever tell the right time, and besides this kind of -thing's too awful, here this time of night with witches and ghosts -a-fluttering around so. I feel as if something's behind me all the time; -and I'm afeard to turn around, becuz maybe there's others in front -a-waiting for a chance. I been creeping all over, ever since I got here." - -"Well, I've been pretty much so, too, Huck. They most always put in a -dead man when they bury a treasure under a tree, to look out for it." - -"Lordy!" - -"Yes, they do. I've always heard that." - -"Tom, I don't like to fool around much where there's dead people. A -body's bound to get into trouble with 'em, sure." - -"I don't like to stir 'em up, either. S'pose this one here was to -stick his skull out and say something!" - -"Don't Tom! It's awful." - -"Well, it just is. Huck, I don't feel comfortable a bit." - -"Say, Tom, let's give this place up, and try somewheres else." - -"All right, I reckon we better." - -"What'll it be?" - -Tom considered awhile; and then said: - -"The ha'nted house. That's it!" - -"Blame it, I don't like ha'nted houses, Tom. Why, they're a dern sight -worse'n dead people. Dead people might talk, maybe, but they don't come -sliding around in a shroud, when you ain't noticing, and peep over your -shoulder all of a sudden and grit their teeth, the way a ghost does. I -couldn't stand such a thing as that, Tom--nobody could." - -"Yes, but, Huck, ghosts don't travel around only at night. They won't -hender us from digging there in the daytime." - -"Well, that's so. But you know mighty well people don't go about that -ha'nted house in the day nor the night." - -"Well, that's mostly because they don't like to go where a man's been -murdered, anyway--but nothing's ever been seen around that house except -in the night--just some blue lights slipping by the windows--no regular -ghosts." - -"Well, where you see one of them blue lights flickering around, Tom, -you can bet there's a ghost mighty close behind it. It stands to -reason. Becuz you know that they don't anybody but ghosts use 'em." - -"Yes, that's so. But anyway they don't come around in the daytime, so -what's the use of our being afeard?" - -"Well, all right. We'll tackle the ha'nted house if you say so--but I -reckon it's taking chances." - -They had started down the hill by this time. There in the middle of -the moonlit valley below them stood the "ha'nted" house, utterly -isolated, its fences gone long ago, rank weeds smothering the very -doorsteps, the chimney crumbled to ruin, the window-sashes vacant, a -corner of the roof caved in. The boys gazed awhile, half expecting to -see a blue light flit past a window; then talking in a low tone, as -befitted the time and the circumstances, they struck far off to the -right, to give the haunted house a wide berth, and took their way -homeward through the woods that adorned the rearward side of Cardiff -Hill. - - - -CHAPTER XXVI - -ABOUT noon the next day the boys arrived at the dead tree; they had -come for their tools. Tom was impatient to go to the haunted house; -Huck was measurably so, also--but suddenly said: - -"Lookyhere, Tom, do you know what day it is?" - -Tom mentally ran over the days of the week, and then quickly lifted -his eyes with a startled look in them-- - -"My! I never once thought of it, Huck!" - -"Well, I didn't neither, but all at once it popped onto me that it was -Friday." - -"Blame it, a body can't be too careful, Huck. We might 'a' got into an -awful scrape, tackling such a thing on a Friday." - -"MIGHT! Better say we WOULD! There's some lucky days, maybe, but -Friday ain't." - -"Any fool knows that. I don't reckon YOU was the first that found it -out, Huck." - -"Well, I never said I was, did I? And Friday ain't all, neither. I had -a rotten bad dream last night--dreampt about rats." - -"No! Sure sign of trouble. Did they fight?" - -"No." - -"Well, that's good, Huck. When they don't fight it's only a sign that -there's trouble around, you know. All we got to do is to look mighty -sharp and keep out of it. We'll drop this thing for to-day, and play. -Do you know Robin Hood, Huck?" - -"No. Who's Robin Hood?" - -"Why, he was one of the greatest men that was ever in England--and the -best. He was a robber." - -"Cracky, I wisht I was. Who did he rob?" - -"Only sheriffs and bishops and rich people and kings, and such like. -But he never bothered the poor. He loved 'em. He always divided up with -'em perfectly square." - -"Well, he must 'a' been a brick." - -"I bet you he was, Huck. Oh, he was the noblest man that ever was. -They ain't any such men now, I can tell you. He could lick any man in -England, with one hand tied behind him; and he could take his yew bow -and plug a ten-cent piece every time, a mile and a half." - -"What's a YEW bow?" - -"I don't know. It's some kind of a bow, of course. And if he hit that -dime only on the edge he would set down and cry--and curse. But we'll -play Robin Hood--it's nobby fun. I'll learn you." - -"I'm agreed." - -So they played Robin Hood all the afternoon, now and then casting a -yearning eye down upon the haunted house and passing a remark about the -morrow's prospects and possibilities there. As the sun began to sink -into the west they took their way homeward athwart the long shadows of -the trees and soon were buried from sight in the forests of Cardiff -Hill. - -On Saturday, shortly after noon, the boys were at the dead tree again. -They had a smoke and a chat in the shade, and then dug a little in -their last hole, not with great hope, but merely because Tom said there -were so many cases where people had given up a treasure after getting -down within six inches of it, and then somebody else had come along and -turned it up with a single thrust of a shovel. The thing failed this -time, however, so the boys shouldered their tools and went away feeling -that they had not trifled with fortune, but had fulfilled all the -requirements that belong to the business of treasure-hunting. - -When they reached the haunted house there was something so weird and -grisly about the dead silence that reigned there under the baking sun, -and something so depressing about the loneliness and desolation of the -place, that they were afraid, for a moment, to venture in. Then they -crept to the door and took a trembling peep. They saw a weed-grown, -floorless room, unplastered, an ancient fireplace, vacant windows, a -ruinous staircase; and here, there, and everywhere hung ragged and -abandoned cobwebs. They presently entered, softly, with quickened -pulses, talking in whispers, ears alert to catch the slightest sound, -and muscles tense and ready for instant retreat. - -In a little while familiarity modified their fears and they gave the -place a critical and interested examination, rather admiring their own -boldness, and wondering at it, too. Next they wanted to look up-stairs. -This was something like cutting off retreat, but they got to daring -each other, and of course there could be but one result--they threw -their tools into a corner and made the ascent. Up there were the same -signs of decay. In one corner they found a closet that promised -mystery, but the promise was a fraud--there was nothing in it. Their -courage was up now and well in hand. They were about to go down and -begin work when-- - -"Sh!" said Tom. - -"What is it?" whispered Huck, blanching with fright. - -"Sh!... There!... Hear it?" - -"Yes!... Oh, my! Let's run!" - -"Keep still! Don't you budge! They're coming right toward the door." - -The boys stretched themselves upon the floor with their eyes to -knot-holes in the planking, and lay waiting, in a misery of fear. - -"They've stopped.... No--coming.... Here they are. Don't whisper -another word, Huck. My goodness, I wish I was out of this!" - -Two men entered. Each boy said to himself: "There's the old deaf and -dumb Spaniard that's been about town once or twice lately--never saw -t'other man before." - -"T'other" was a ragged, unkempt creature, with nothing very pleasant -in his face. The Spaniard was wrapped in a serape; he had bushy white -whiskers; long white hair flowed from under his sombrero, and he wore -green goggles. When they came in, "t'other" was talking in a low voice; -they sat down on the ground, facing the door, with their backs to the -wall, and the speaker continued his remarks. His manner became less -guarded and his words more distinct as he proceeded: - -"No," said he, "I've thought it all over, and I don't like it. It's -dangerous." - -"Dangerous!" grunted the "deaf and dumb" Spaniard--to the vast -surprise of the boys. "Milksop!" - -This voice made the boys gasp and quake. It was Injun Joe's! There was -silence for some time. Then Joe said: - -"What's any more dangerous than that job up yonder--but nothing's come -of it." - -"That's different. Away up the river so, and not another house about. -'Twon't ever be known that we tried, anyway, long as we didn't succeed." - -"Well, what's more dangerous than coming here in the daytime!--anybody -would suspicion us that saw us." - -"I know that. But there warn't any other place as handy after that -fool of a job. I want to quit this shanty. I wanted to yesterday, only -it warn't any use trying to stir out of here, with those infernal boys -playing over there on the hill right in full view." - -"Those infernal boys" quaked again under the inspiration of this -remark, and thought how lucky it was that they had remembered it was -Friday and concluded to wait a day. They wished in their hearts they -had waited a year. - -The two men got out some food and made a luncheon. After a long and -thoughtful silence, Injun Joe said: - -"Look here, lad--you go back up the river where you belong. Wait there -till you hear from me. I'll take the chances on dropping into this town -just once more, for a look. We'll do that 'dangerous' job after I've -spied around a little and think things look well for it. Then for -Texas! We'll leg it together!" - -This was satisfactory. Both men presently fell to yawning, and Injun -Joe said: - -"I'm dead for sleep! It's your turn to watch." - -He curled down in the weeds and soon began to snore. His comrade -stirred him once or twice and he became quiet. Presently the watcher -began to nod; his head drooped lower and lower, both men began to snore -now. - -The boys drew a long, grateful breath. Tom whispered: - -"Now's our chance--come!" - -Huck said: - -"I can't--I'd die if they was to wake." - -Tom urged--Huck held back. At last Tom rose slowly and softly, and -started alone. But the first step he made wrung such a hideous creak -from the crazy floor that he sank down almost dead with fright. He -never made a second attempt. The boys lay there counting the dragging -moments till it seemed to them that time must be done and eternity -growing gray; and then they were grateful to note that at last the sun -was setting. - -Now one snore ceased. Injun Joe sat up, stared around--smiled grimly -upon his comrade, whose head was drooping upon his knees--stirred him -up with his foot and said: - -"Here! YOU'RE a watchman, ain't you! All right, though--nothing's -happened." - -"My! have I been asleep?" - -"Oh, partly, partly. Nearly time for us to be moving, pard. What'll we -do with what little swag we've got left?" - -"I don't know--leave it here as we've always done, I reckon. No use to -take it away till we start south. Six hundred and fifty in silver's -something to carry." - -"Well--all right--it won't matter to come here once more." - -"No--but I'd say come in the night as we used to do--it's better." - -"Yes: but look here; it may be a good while before I get the right -chance at that job; accidents might happen; 'tain't in such a very good -place; we'll just regularly bury it--and bury it deep." - -"Good idea," said the comrade, who walked across the room, knelt down, -raised one of the rearward hearth-stones and took out a bag that -jingled pleasantly. He subtracted from it twenty or thirty dollars for -himself and as much for Injun Joe, and passed the bag to the latter, -who was on his knees in the corner, now, digging with his bowie-knife. - -The boys forgot all their fears, all their miseries in an instant. -With gloating eyes they watched every movement. Luck!--the splendor of -it was beyond all imagination! Six hundred dollars was money enough to -make half a dozen boys rich! Here was treasure-hunting under the -happiest auspices--there would not be any bothersome uncertainty as to -where to dig. They nudged each other every moment--eloquent nudges and -easily understood, for they simply meant--"Oh, but ain't you glad NOW -we're here!" - -Joe's knife struck upon something. - -"Hello!" said he. - -"What is it?" said his comrade. - -"Half-rotten plank--no, it's a box, I believe. Here--bear a hand and -we'll see what it's here for. Never mind, I've broke a hole." - -He reached his hand in and drew it out-- - -"Man, it's money!" - -The two men examined the handful of coins. They were gold. The boys -above were as excited as themselves, and as delighted. - -Joe's comrade said: - -"We'll make quick work of this. There's an old rusty pick over amongst -the weeds in the corner the other side of the fireplace--I saw it a -minute ago." - -He ran and brought the boys' pick and shovel. Injun Joe took the pick, -looked it over critically, shook his head, muttered something to -himself, and then began to use it. The box was soon unearthed. It was -not very large; it was iron bound and had been very strong before the -slow years had injured it. The men contemplated the treasure awhile in -blissful silence. - -"Pard, there's thousands of dollars here," said Injun Joe. - -"'Twas always said that Murrel's gang used to be around here one -summer," the stranger observed. - -"I know it," said Injun Joe; "and this looks like it, I should say." - -"Now you won't need to do that job." - -The half-breed frowned. Said he: - -"You don't know me. Least you don't know all about that thing. 'Tain't -robbery altogether--it's REVENGE!" and a wicked light flamed in his -eyes. "I'll need your help in it. When it's finished--then Texas. Go -home to your Nance and your kids, and stand by till you hear from me." - -"Well--if you say so; what'll we do with this--bury it again?" - -"Yes. [Ravishing delight overhead.] NO! by the great Sachem, no! -[Profound distress overhead.] I'd nearly forgot. That pick had fresh -earth on it! [The boys were sick with terror in a moment.] What -business has a pick and a shovel here? What business with fresh earth -on them? Who brought them here--and where are they gone? Have you heard -anybody?--seen anybody? What! bury it again and leave them to come and -see the ground disturbed? Not exactly--not exactly. We'll take it to my -den." - -"Why, of course! Might have thought of that before. You mean Number -One?" - -"No--Number Two--under the cross. The other place is bad--too common." - -"All right. It's nearly dark enough to start." - -Injun Joe got up and went about from window to window cautiously -peeping out. Presently he said: - -"Who could have brought those tools here? Do you reckon they can be -up-stairs?" - -The boys' breath forsook them. Injun Joe put his hand on his knife, -halted a moment, undecided, and then turned toward the stairway. The -boys thought of the closet, but their strength was gone. The steps came -creaking up the stairs--the intolerable distress of the situation woke -the stricken resolution of the lads--they were about to spring for the -closet, when there was a crash of rotten timbers and Injun Joe landed -on the ground amid the debris of the ruined stairway. He gathered -himself up cursing, and his comrade said: - -"Now what's the use of all that? If it's anybody, and they're up -there, let them STAY there--who cares? If they want to jump down, now, -and get into trouble, who objects? It will be dark in fifteen minutes ---and then let them follow us if they want to. I'm willing. In my -opinion, whoever hove those things in here caught a sight of us and -took us for ghosts or devils or something. I'll bet they're running -yet." - -Joe grumbled awhile; then he agreed with his friend that what daylight -was left ought to be economized in getting things ready for leaving. -Shortly afterward they slipped out of the house in the deepening -twilight, and moved toward the river with their precious box. - -Tom and Huck rose up, weak but vastly relieved, and stared after them -through the chinks between the logs of the house. Follow? Not they. -They were content to reach ground again without broken necks, and take -the townward track over the hill. They did not talk much. They were too -much absorbed in hating themselves--hating the ill luck that made them -take the spade and the pick there. But for that, Injun Joe never would -have suspected. He would have hidden the silver with the gold to wait -there till his "revenge" was satisfied, and then he would have had the -misfortune to find that money turn up missing. Bitter, bitter luck that -the tools were ever brought there! - -They resolved to keep a lookout for that Spaniard when he should come -to town spying out for chances to do his revengeful job, and follow him -to "Number Two," wherever that might be. Then a ghastly thought -occurred to Tom. - -"Revenge? What if he means US, Huck!" - -"Oh, don't!" said Huck, nearly fainting. - -They talked it all over, and as they entered town they agreed to -believe that he might possibly mean somebody else--at least that he -might at least mean nobody but Tom, since only Tom had testified. - -Very, very small comfort it was to Tom to be alone in danger! Company -would be a palpable improvement, he thought. - - - -CHAPTER XXVII - -THE adventure of the day mightily tormented Tom's dreams that night. -Four times he had his hands on that rich treasure and four times it -wasted to nothingness in his fingers as sleep forsook him and -wakefulness brought back the hard reality of his misfortune. As he lay -in the early morning recalling the incidents of his great adventure, he -noticed that they seemed curiously subdued and far away--somewhat as if -they had happened in another world, or in a time long gone by. Then it -occurred to him that the great adventure itself must be a dream! There -was one very strong argument in favor of this idea--namely, that the -quantity of coin he had seen was too vast to be real. He had never seen -as much as fifty dollars in one mass before, and he was like all boys -of his age and station in life, in that he imagined that all references -to "hundreds" and "thousands" were mere fanciful forms of speech, and -that no such sums really existed in the world. He never had supposed -for a moment that so large a sum as a hundred dollars was to be found -in actual money in any one's possession. If his notions of hidden -treasure had been analyzed, they would have been found to consist of a -handful of real dimes and a bushel of vague, splendid, ungraspable -dollars. - -But the incidents of his adventure grew sensibly sharper and clearer -under the attrition of thinking them over, and so he presently found -himself leaning to the impression that the thing might not have been a -dream, after all. This uncertainty must be swept away. He would snatch -a hurried breakfast and go and find Huck. Huck was sitting on the -gunwale of a flatboat, listlessly dangling his feet in the water and -looking very melancholy. Tom concluded to let Huck lead up to the -subject. If he did not do it, then the adventure would be proved to -have been only a dream. - -"Hello, Huck!" - -"Hello, yourself." - -Silence, for a minute. - -"Tom, if we'd 'a' left the blame tools at the dead tree, we'd 'a' got -the money. Oh, ain't it awful!" - -"'Tain't a dream, then, 'tain't a dream! Somehow I most wish it was. -Dog'd if I don't, Huck." - -"What ain't a dream?" - -"Oh, that thing yesterday. I been half thinking it was." - -"Dream! If them stairs hadn't broke down you'd 'a' seen how much dream -it was! I've had dreams enough all night--with that patch-eyed Spanish -devil going for me all through 'em--rot him!" - -"No, not rot him. FIND him! Track the money!" - -"Tom, we'll never find him. A feller don't have only one chance for -such a pile--and that one's lost. I'd feel mighty shaky if I was to see -him, anyway." - -"Well, so'd I; but I'd like to see him, anyway--and track him out--to -his Number Two." - -"Number Two--yes, that's it. I been thinking 'bout that. But I can't -make nothing out of it. What do you reckon it is?" - -"I dono. It's too deep. Say, Huck--maybe it's the number of a house!" - -"Goody!... No, Tom, that ain't it. If it is, it ain't in this -one-horse town. They ain't no numbers here." - -"Well, that's so. Lemme think a minute. Here--it's the number of a -room--in a tavern, you know!" - -"Oh, that's the trick! They ain't only two taverns. We can find out -quick." - -"You stay here, Huck, till I come." - -Tom was off at once. He did not care to have Huck's company in public -places. He was gone half an hour. He found that in the best tavern, No. -2 had long been occupied by a young lawyer, and was still so occupied. -In the less ostentatious house, No. 2 was a mystery. The -tavern-keeper's young son said it was kept locked all the time, and he -never saw anybody go into it or come out of it except at night; he did -not know any particular reason for this state of things; had had some -little curiosity, but it was rather feeble; had made the most of the -mystery by entertaining himself with the idea that that room was -"ha'nted"; had noticed that there was a light in there the night before. - -"That's what I've found out, Huck. I reckon that's the very No. 2 -we're after." - -"I reckon it is, Tom. Now what you going to do?" - -"Lemme think." - -Tom thought a long time. Then he said: - -"I'll tell you. The back door of that No. 2 is the door that comes out -into that little close alley between the tavern and the old rattle trap -of a brick store. Now you get hold of all the door-keys you can find, -and I'll nip all of auntie's, and the first dark night we'll go there -and try 'em. And mind you, keep a lookout for Injun Joe, because he -said he was going to drop into town and spy around once more for a -chance to get his revenge. If you see him, you just follow him; and if -he don't go to that No. 2, that ain't the place." - -"Lordy, I don't want to foller him by myself!" - -"Why, it'll be night, sure. He mightn't ever see you--and if he did, -maybe he'd never think anything." - -"Well, if it's pretty dark I reckon I'll track him. I dono--I dono. -I'll try." - -"You bet I'll follow him, if it's dark, Huck. Why, he might 'a' found -out he couldn't get his revenge, and be going right after that money." - -"It's so, Tom, it's so. I'll foller him; I will, by jingoes!" - -"Now you're TALKING! Don't you ever weaken, Huck, and I won't." - - - -CHAPTER XXVIII - -THAT night Tom and Huck were ready for their adventure. They hung -about the neighborhood of the tavern until after nine, one watching the -alley at a distance and the other the tavern door. Nobody entered the -alley or left it; nobody resembling the Spaniard entered or left the -tavern door. The night promised to be a fair one; so Tom went home with -the understanding that if a considerable degree of darkness came on, -Huck was to come and "maow," whereupon he would slip out and try the -keys. But the night remained clear, and Huck closed his watch and -retired to bed in an empty sugar hogshead about twelve. - -Tuesday the boys had the same ill luck. Also Wednesday. But Thursday -night promised better. Tom slipped out in good season with his aunt's -old tin lantern, and a large towel to blindfold it with. He hid the -lantern in Huck's sugar hogshead and the watch began. An hour before -midnight the tavern closed up and its lights (the only ones -thereabouts) were put out. No Spaniard had been seen. Nobody had -entered or left the alley. Everything was auspicious. The blackness of -darkness reigned, the perfect stillness was interrupted only by -occasional mutterings of distant thunder. - -Tom got his lantern, lit it in the hogshead, wrapped it closely in the -towel, and the two adventurers crept in the gloom toward the tavern. -Huck stood sentry and Tom felt his way into the alley. Then there was a -season of waiting anxiety that weighed upon Huck's spirits like a -mountain. He began to wish he could see a flash from the lantern--it -would frighten him, but it would at least tell him that Tom was alive -yet. It seemed hours since Tom had disappeared. Surely he must have -fainted; maybe he was dead; maybe his heart had burst under terror and -excitement. In his uneasiness Huck found himself drawing closer and -closer to the alley; fearing all sorts of dreadful things, and -momentarily expecting some catastrophe to happen that would take away -his breath. There was not much to take away, for he seemed only able to -inhale it by thimblefuls, and his heart would soon wear itself out, the -way it was beating. Suddenly there was a flash of light and Tom came -tearing by him: "Run!" said he; "run, for your life!" - -He needn't have repeated it; once was enough; Huck was making thirty -or forty miles an hour before the repetition was uttered. The boys -never stopped till they reached the shed of a deserted slaughter-house -at the lower end of the village. Just as they got within its shelter -the storm burst and the rain poured down. As soon as Tom got his breath -he said: - -"Huck, it was awful! I tried two of the keys, just as soft as I could; -but they seemed to make such a power of racket that I couldn't hardly -get my breath I was so scared. They wouldn't turn in the lock, either. -Well, without noticing what I was doing, I took hold of the knob, and -open comes the door! It warn't locked! I hopped in, and shook off the -towel, and, GREAT CAESAR'S GHOST!" - -"What!--what'd you see, Tom?" - -"Huck, I most stepped onto Injun Joe's hand!" - -"No!" - -"Yes! He was lying there, sound asleep on the floor, with his old -patch on his eye and his arms spread out." - -"Lordy, what did you do? Did he wake up?" - -"No, never budged. Drunk, I reckon. I just grabbed that towel and -started!" - -"I'd never 'a' thought of the towel, I bet!" - -"Well, I would. My aunt would make me mighty sick if I lost it." - -"Say, Tom, did you see that box?" - -"Huck, I didn't wait to look around. I didn't see the box, I didn't -see the cross. I didn't see anything but a bottle and a tin cup on the -floor by Injun Joe; yes, I saw two barrels and lots more bottles in the -room. Don't you see, now, what's the matter with that ha'nted room?" - -"How?" - -"Why, it's ha'nted with whiskey! Maybe ALL the Temperance Taverns have -got a ha'nted room, hey, Huck?" - -"Well, I reckon maybe that's so. Who'd 'a' thought such a thing? But -say, Tom, now's a mighty good time to get that box, if Injun Joe's -drunk." - -"It is, that! You try it!" - -Huck shuddered. - -"Well, no--I reckon not." - -"And I reckon not, Huck. Only one bottle alongside of Injun Joe ain't -enough. If there'd been three, he'd be drunk enough and I'd do it." - -There was a long pause for reflection, and then Tom said: - -"Lookyhere, Huck, less not try that thing any more till we know Injun -Joe's not in there. It's too scary. Now, if we watch every night, we'll -be dead sure to see him go out, some time or other, and then we'll -snatch that box quicker'n lightning." - -"Well, I'm agreed. I'll watch the whole night long, and I'll do it -every night, too, if you'll do the other part of the job." - -"All right, I will. All you got to do is to trot up Hooper Street a -block and maow--and if I'm asleep, you throw some gravel at the window -and that'll fetch me." - -"Agreed, and good as wheat!" - -"Now, Huck, the storm's over, and I'll go home. It'll begin to be -daylight in a couple of hours. You go back and watch that long, will -you?" - -"I said I would, Tom, and I will. I'll ha'nt that tavern every night -for a year! I'll sleep all day and I'll stand watch all night." - -"That's all right. Now, where you going to sleep?" - -"In Ben Rogers' hayloft. He lets me, and so does his pap's nigger man, -Uncle Jake. I tote water for Uncle Jake whenever he wants me to, and -any time I ask him he gives me a little something to eat if he can -spare it. That's a mighty good nigger, Tom. He likes me, becuz I don't -ever act as if I was above him. Sometime I've set right down and eat -WITH him. But you needn't tell that. A body's got to do things when -he's awful hungry he wouldn't want to do as a steady thing." - -"Well, if I don't want you in the daytime, I'll let you sleep. I won't -come bothering around. Any time you see something's up, in the night, -just skip right around and maow." - - - -CHAPTER XXIX - -THE first thing Tom heard on Friday morning was a glad piece of news ---Judge Thatcher's family had come back to town the night before. Both -Injun Joe and the treasure sunk into secondary importance for a moment, -and Becky took the chief place in the boy's interest. He saw her and -they had an exhausting good time playing "hi-spy" and "gully-keeper" -with a crowd of their school-mates. The day was completed and crowned -in a peculiarly satisfactory way: Becky teased her mother to appoint -the next day for the long-promised and long-delayed picnic, and she -consented. The child's delight was boundless; and Tom's not more -moderate. The invitations were sent out before sunset, and straightway -the young folks of the village were thrown into a fever of preparation -and pleasurable anticipation. Tom's excitement enabled him to keep -awake until a pretty late hour, and he had good hopes of hearing Huck's -"maow," and of having his treasure to astonish Becky and the picnickers -with, next day; but he was disappointed. No signal came that night. - -Morning came, eventually, and by ten or eleven o'clock a giddy and -rollicking company were gathered at Judge Thatcher's, and everything -was ready for a start. It was not the custom for elderly people to mar -the picnics with their presence. The children were considered safe -enough under the wings of a few young ladies of eighteen and a few -young gentlemen of twenty-three or thereabouts. The old steam ferryboat -was chartered for the occasion; presently the gay throng filed up the -main street laden with provision-baskets. Sid was sick and had to miss -the fun; Mary remained at home to entertain him. The last thing Mrs. -Thatcher said to Becky, was: - -"You'll not get back till late. Perhaps you'd better stay all night -with some of the girls that live near the ferry-landing, child." - -"Then I'll stay with Susy Harper, mamma." - -"Very well. And mind and behave yourself and don't be any trouble." - -Presently, as they tripped along, Tom said to Becky: - -"Say--I'll tell you what we'll do. 'Stead of going to Joe Harper's -we'll climb right up the hill and stop at the Widow Douglas'. She'll -have ice-cream! She has it most every day--dead loads of it. And she'll -be awful glad to have us." - -"Oh, that will be fun!" - -Then Becky reflected a moment and said: - -"But what will mamma say?" - -"How'll she ever know?" - -The girl turned the idea over in her mind, and said reluctantly: - -"I reckon it's wrong--but--" - -"But shucks! Your mother won't know, and so what's the harm? All she -wants is that you'll be safe; and I bet you she'd 'a' said go there if -she'd 'a' thought of it. I know she would!" - -The Widow Douglas' splendid hospitality was a tempting bait. It and -Tom's persuasions presently carried the day. So it was decided to say -nothing anybody about the night's programme. Presently it occurred to -Tom that maybe Huck might come this very night and give the signal. The -thought took a deal of the spirit out of his anticipations. Still he -could not bear to give up the fun at Widow Douglas'. And why should he -give it up, he reasoned--the signal did not come the night before, so -why should it be any more likely to come to-night? The sure fun of the -evening outweighed the uncertain treasure; and, boy-like, he determined -to yield to the stronger inclination and not allow himself to think of -the box of money another time that day. - -Three miles below town the ferryboat stopped at the mouth of a woody -hollow and tied up. The crowd swarmed ashore and soon the forest -distances and craggy heights echoed far and near with shoutings and -laughter. All the different ways of getting hot and tired were gone -through with, and by-and-by the rovers straggled back to camp fortified -with responsible appetites, and then the destruction of the good things -began. After the feast there was a refreshing season of rest and chat -in the shade of spreading oaks. By-and-by somebody shouted: - -"Who's ready for the cave?" - -Everybody was. Bundles of candles were procured, and straightway there -was a general scamper up the hill. The mouth of the cave was up the -hillside--an opening shaped like a letter A. Its massive oaken door -stood unbarred. Within was a small chamber, chilly as an ice-house, and -walled by Nature with solid limestone that was dewy with a cold sweat. -It was romantic and mysterious to stand here in the deep gloom and look -out upon the green valley shining in the sun. But the impressiveness of -the situation quickly wore off, and the romping began again. The moment -a candle was lighted there was a general rush upon the owner of it; a -struggle and a gallant defence followed, but the candle was soon -knocked down or blown out, and then there was a glad clamor of laughter -and a new chase. But all things have an end. By-and-by the procession -went filing down the steep descent of the main avenue, the flickering -rank of lights dimly revealing the lofty walls of rock almost to their -point of junction sixty feet overhead. This main avenue was not more -than eight or ten feet wide. Every few steps other lofty and still -narrower crevices branched from it on either hand--for McDougal's cave -was but a vast labyrinth of crooked aisles that ran into each other and -out again and led nowhere. It was said that one might wander days and -nights together through its intricate tangle of rifts and chasms, and -never find the end of the cave; and that he might go down, and down, -and still down, into the earth, and it was just the same--labyrinth -under labyrinth, and no end to any of them. No man "knew" the cave. -That was an impossible thing. Most of the young men knew a portion of -it, and it was not customary to venture much beyond this known portion. -Tom Sawyer knew as much of the cave as any one. - -The procession moved along the main avenue some three-quarters of a -mile, and then groups and couples began to slip aside into branch -avenues, fly along the dismal corridors, and take each other by -surprise at points where the corridors joined again. Parties were able -to elude each other for the space of half an hour without going beyond -the "known" ground. - -By-and-by, one group after another came straggling back to the mouth -of the cave, panting, hilarious, smeared from head to foot with tallow -drippings, daubed with clay, and entirely delighted with the success of -the day. Then they were astonished to find that they had been taking no -note of time and that night was about at hand. The clanging bell had -been calling for half an hour. However, this sort of close to the day's -adventures was romantic and therefore satisfactory. When the ferryboat -with her wild freight pushed into the stream, nobody cared sixpence for -the wasted time but the captain of the craft. - -Huck was already upon his watch when the ferryboat's lights went -glinting past the wharf. He heard no noise on board, for the young -people were as subdued and still as people usually are who are nearly -tired to death. He wondered what boat it was, and why she did not stop -at the wharf--and then he dropped her out of his mind and put his -attention upon his business. The night was growing cloudy and dark. Ten -o'clock came, and the noise of vehicles ceased, scattered lights began -to wink out, all straggling foot-passengers disappeared, the village -betook itself to its slumbers and left the small watcher alone with the -silence and the ghosts. Eleven o'clock came, and the tavern lights were -put out; darkness everywhere, now. Huck waited what seemed a weary long -time, but nothing happened. His faith was weakening. Was there any use? -Was there really any use? Why not give it up and turn in? - -A noise fell upon his ear. He was all attention in an instant. The -alley door closed softly. He sprang to the corner of the brick store. -The next moment two men brushed by him, and one seemed to have -something under his arm. It must be that box! So they were going to -remove the treasure. Why call Tom now? It would be absurd--the men -would get away with the box and never be found again. No, he would -stick to their wake and follow them; he would trust to the darkness for -security from discovery. So communing with himself, Huck stepped out -and glided along behind the men, cat-like, with bare feet, allowing -them to keep just far enough ahead not to be invisible. - -They moved up the river street three blocks, then turned to the left -up a cross-street. They went straight ahead, then, until they came to -the path that led up Cardiff Hill; this they took. They passed by the -old Welshman's house, half-way up the hill, without hesitating, and -still climbed upward. Good, thought Huck, they will bury it in the old -quarry. But they never stopped at the quarry. They passed on, up the -summit. They plunged into the narrow path between the tall sumach -bushes, and were at once hidden in the gloom. Huck closed up and -shortened his distance, now, for they would never be able to see him. -He trotted along awhile; then slackened his pace, fearing he was -gaining too fast; moved on a piece, then stopped altogether; listened; -no sound; none, save that he seemed to hear the beating of his own -heart. The hooting of an owl came over the hill--ominous sound! But no -footsteps. Heavens, was everything lost! He was about to spring with -winged feet, when a man cleared his throat not four feet from him! -Huck's heart shot into his throat, but he swallowed it again; and then -he stood there shaking as if a dozen agues had taken charge of him at -once, and so weak that he thought he must surely fall to the ground. He -knew where he was. He knew he was within five steps of the stile -leading into Widow Douglas' grounds. Very well, he thought, let them -bury it there; it won't be hard to find. - -Now there was a voice--a very low voice--Injun Joe's: - -"Damn her, maybe she's got company--there's lights, late as it is." - -"I can't see any." - -This was that stranger's voice--the stranger of the haunted house. A -deadly chill went to Huck's heart--this, then, was the "revenge" job! -His thought was, to fly. Then he remembered that the Widow Douglas had -been kind to him more than once, and maybe these men were going to -murder her. He wished he dared venture to warn her; but he knew he -didn't dare--they might come and catch him. He thought all this and -more in the moment that elapsed between the stranger's remark and Injun -Joe's next--which was-- - -"Because the bush is in your way. Now--this way--now you see, don't -you?" - -"Yes. Well, there IS company there, I reckon. Better give it up." - -"Give it up, and I just leaving this country forever! Give it up and -maybe never have another chance. I tell you again, as I've told you -before, I don't care for her swag--you may have it. But her husband was -rough on me--many times he was rough on me--and mainly he was the -justice of the peace that jugged me for a vagrant. And that ain't all. -It ain't a millionth part of it! He had me HORSEWHIPPED!--horsewhipped -in front of the jail, like a nigger!--with all the town looking on! -HORSEWHIPPED!--do you understand? He took advantage of me and died. But -I'll take it out of HER." - -"Oh, don't kill her! Don't do that!" - -"Kill? Who said anything about killing? I would kill HIM if he was -here; but not her. When you want to get revenge on a woman you don't -kill her--bosh! you go for her looks. You slit her nostrils--you notch -her ears like a sow!" - -"By God, that's--" - -"Keep your opinion to yourself! It will be safest for you. I'll tie -her to the bed. If she bleeds to death, is that my fault? I'll not cry, -if she does. My friend, you'll help me in this thing--for MY sake ---that's why you're here--I mightn't be able alone. If you flinch, I'll -kill you. Do you understand that? And if I have to kill you, I'll kill -her--and then I reckon nobody'll ever know much about who done this -business." - -"Well, if it's got to be done, let's get at it. The quicker the -better--I'm all in a shiver." - -"Do it NOW? And company there? Look here--I'll get suspicious of you, -first thing you know. No--we'll wait till the lights are out--there's -no hurry." - -Huck felt that a silence was going to ensue--a thing still more awful -than any amount of murderous talk; so he held his breath and stepped -gingerly back; planted his foot carefully and firmly, after balancing, -one-legged, in a precarious way and almost toppling over, first on one -side and then on the other. He took another step back, with the same -elaboration and the same risks; then another and another, and--a twig -snapped under his foot! His breath stopped and he listened. There was -no sound--the stillness was perfect. His gratitude was measureless. Now -he turned in his tracks, between the walls of sumach bushes--turned -himself as carefully as if he were a ship--and then stepped quickly but -cautiously along. When he emerged at the quarry he felt secure, and so -he picked up his nimble heels and flew. Down, down he sped, till he -reached the Welshman's. He banged at the door, and presently the heads -of the old man and his two stalwart sons were thrust from windows. - -"What's the row there? Who's banging? What do you want?" - -"Let me in--quick! I'll tell everything." - -"Why, who are you?" - -"Huckleberry Finn--quick, let me in!" - -"Huckleberry Finn, indeed! It ain't a name to open many doors, I -judge! But let him in, lads, and let's see what's the trouble." - -"Please don't ever tell I told you," were Huck's first words when he -got in. "Please don't--I'd be killed, sure--but the widow's been good -friends to me sometimes, and I want to tell--I WILL tell if you'll -promise you won't ever say it was me." - -"By George, he HAS got something to tell, or he wouldn't act so!" -exclaimed the old man; "out with it and nobody here'll ever tell, lad." - -Three minutes later the old man and his sons, well armed, were up the -hill, and just entering the sumach path on tiptoe, their weapons in -their hands. Huck accompanied them no further. He hid behind a great -bowlder and fell to listening. There was a lagging, anxious silence, -and then all of a sudden there was an explosion of firearms and a cry. - -Huck waited for no particulars. He sprang away and sped down the hill -as fast as his legs could carry him. - - - -CHAPTER XXX - -AS the earliest suspicion of dawn appeared on Sunday morning, Huck -came groping up the hill and rapped gently at the old Welshman's door. -The inmates were asleep, but it was a sleep that was set on a -hair-trigger, on account of the exciting episode of the night. A call -came from a window: - -"Who's there!" - -Huck's scared voice answered in a low tone: - -"Please let me in! It's only Huck Finn!" - -"It's a name that can open this door night or day, lad!--and welcome!" - -These were strange words to the vagabond boy's ears, and the -pleasantest he had ever heard. He could not recollect that the closing -word had ever been applied in his case before. The door was quickly -unlocked, and he entered. Huck was given a seat and the old man and his -brace of tall sons speedily dressed themselves. - -"Now, my boy, I hope you're good and hungry, because breakfast will be -ready as soon as the sun's up, and we'll have a piping hot one, too ---make yourself easy about that! I and the boys hoped you'd turn up and -stop here last night." - -"I was awful scared," said Huck, "and I run. I took out when the -pistols went off, and I didn't stop for three mile. I've come now becuz -I wanted to know about it, you know; and I come before daylight becuz I -didn't want to run across them devils, even if they was dead." - -"Well, poor chap, you do look as if you'd had a hard night of it--but -there's a bed here for you when you've had your breakfast. No, they -ain't dead, lad--we are sorry enough for that. You see we knew right -where to put our hands on them, by your description; so we crept along -on tiptoe till we got within fifteen feet of them--dark as a cellar -that sumach path was--and just then I found I was going to sneeze. It -was the meanest kind of luck! I tried to keep it back, but no use ---'twas bound to come, and it did come! I was in the lead with my pistol -raised, and when the sneeze started those scoundrels a-rustling to get -out of the path, I sung out, 'Fire boys!' and blazed away at the place -where the rustling was. So did the boys. But they were off in a jiffy, -those villains, and we after them, down through the woods. I judge we -never touched them. They fired a shot apiece as they started, but their -bullets whizzed by and didn't do us any harm. As soon as we lost the -sound of their feet we quit chasing, and went down and stirred up the -constables. They got a posse together, and went off to guard the river -bank, and as soon as it is light the sheriff and a gang are going to -beat up the woods. My boys will be with them presently. I wish we had -some sort of description of those rascals--'twould help a good deal. -But you couldn't see what they were like, in the dark, lad, I suppose?" - -"Oh yes; I saw them down-town and follered them." - -"Splendid! Describe them--describe them, my boy!" - -"One's the old deaf and dumb Spaniard that's ben around here once or -twice, and t'other's a mean-looking, ragged--" - -"That's enough, lad, we know the men! Happened on them in the woods -back of the widow's one day, and they slunk away. Off with you, boys, -and tell the sheriff--get your breakfast to-morrow morning!" - -The Welshman's sons departed at once. As they were leaving the room -Huck sprang up and exclaimed: - -"Oh, please don't tell ANYbody it was me that blowed on them! Oh, -please!" - -"All right if you say it, Huck, but you ought to have the credit of -what you did." - -"Oh no, no! Please don't tell!" - -When the young men were gone, the old Welshman said: - -"They won't tell--and I won't. But why don't you want it known?" - -Huck would not explain, further than to say that he already knew too -much about one of those men and would not have the man know that he -knew anything against him for the whole world--he would be killed for -knowing it, sure. - -The old man promised secrecy once more, and said: - -"How did you come to follow these fellows, lad? Were they looking -suspicious?" - -Huck was silent while he framed a duly cautious reply. Then he said: - -"Well, you see, I'm a kind of a hard lot,--least everybody says so, -and I don't see nothing agin it--and sometimes I can't sleep much, on -account of thinking about it and sort of trying to strike out a new way -of doing. That was the way of it last night. I couldn't sleep, and so I -come along up-street 'bout midnight, a-turning it all over, and when I -got to that old shackly brick store by the Temperance Tavern, I backed -up agin the wall to have another think. Well, just then along comes -these two chaps slipping along close by me, with something under their -arm, and I reckoned they'd stole it. One was a-smoking, and t'other one -wanted a light; so they stopped right before me and the cigars lit up -their faces and I see that the big one was the deaf and dumb Spaniard, -by his white whiskers and the patch on his eye, and t'other one was a -rusty, ragged-looking devil." - -"Could you see the rags by the light of the cigars?" - -This staggered Huck for a moment. Then he said: - -"Well, I don't know--but somehow it seems as if I did." - -"Then they went on, and you--" - -"Follered 'em--yes. That was it. I wanted to see what was up--they -sneaked along so. I dogged 'em to the widder's stile, and stood in the -dark and heard the ragged one beg for the widder, and the Spaniard -swear he'd spile her looks just as I told you and your two--" - -"What! The DEAF AND DUMB man said all that!" - -Huck had made another terrible mistake! He was trying his best to keep -the old man from getting the faintest hint of who the Spaniard might -be, and yet his tongue seemed determined to get him into trouble in -spite of all he could do. He made several efforts to creep out of his -scrape, but the old man's eye was upon him and he made blunder after -blunder. Presently the Welshman said: - -"My boy, don't be afraid of me. I wouldn't hurt a hair of your head -for all the world. No--I'd protect you--I'd protect you. This Spaniard -is not deaf and dumb; you've let that slip without intending it; you -can't cover that up now. You know something about that Spaniard that -you want to keep dark. Now trust me--tell me what it is, and trust me ---I won't betray you." - -Huck looked into the old man's honest eyes a moment, then bent over -and whispered in his ear: - -"'Tain't a Spaniard--it's Injun Joe!" - -The Welshman almost jumped out of his chair. In a moment he said: - -"It's all plain enough, now. When you talked about notching ears and -slitting noses I judged that that was your own embellishment, because -white men don't take that sort of revenge. But an Injun! That's a -different matter altogether." - -During breakfast the talk went on, and in the course of it the old man -said that the last thing which he and his sons had done, before going -to bed, was to get a lantern and examine the stile and its vicinity for -marks of blood. They found none, but captured a bulky bundle of-- - -"Of WHAT?" - -If the words had been lightning they could not have leaped with a more -stunning suddenness from Huck's blanched lips. His eyes were staring -wide, now, and his breath suspended--waiting for the answer. The -Welshman started--stared in return--three seconds--five seconds--ten ---then replied: - -"Of burglar's tools. Why, what's the MATTER with you?" - -Huck sank back, panting gently, but deeply, unutterably grateful. The -Welshman eyed him gravely, curiously--and presently said: - -"Yes, burglar's tools. That appears to relieve you a good deal. But -what did give you that turn? What were YOU expecting we'd found?" - -Huck was in a close place--the inquiring eye was upon him--he would -have given anything for material for a plausible answer--nothing -suggested itself--the inquiring eye was boring deeper and deeper--a -senseless reply offered--there was no time to weigh it, so at a venture -he uttered it--feebly: - -"Sunday-school books, maybe." - -Poor Huck was too distressed to smile, but the old man laughed loud -and joyously, shook up the details of his anatomy from head to foot, -and ended by saying that such a laugh was money in a-man's pocket, -because it cut down the doctor's bill like everything. Then he added: - -"Poor old chap, you're white and jaded--you ain't well a bit--no -wonder you're a little flighty and off your balance. But you'll come -out of it. Rest and sleep will fetch you out all right, I hope." - -Huck was irritated to think he had been such a goose and betrayed such -a suspicious excitement, for he had dropped the idea that the parcel -brought from the tavern was the treasure, as soon as he had heard the -talk at the widow's stile. He had only thought it was not the treasure, -however--he had not known that it wasn't--and so the suggestion of a -captured bundle was too much for his self-possession. But on the whole -he felt glad the little episode had happened, for now he knew beyond -all question that that bundle was not THE bundle, and so his mind was -at rest and exceedingly comfortable. In fact, everything seemed to be -drifting just in the right direction, now; the treasure must be still -in No. 2, the men would be captured and jailed that day, and he and Tom -could seize the gold that night without any trouble or any fear of -interruption. - -Just as breakfast was completed there was a knock at the door. Huck -jumped for a hiding-place, for he had no mind to be connected even -remotely with the late event. The Welshman admitted several ladies and -gentlemen, among them the Widow Douglas, and noticed that groups of -citizens were climbing up the hill--to stare at the stile. So the news -had spread. The Welshman had to tell the story of the night to the -visitors. The widow's gratitude for her preservation was outspoken. - -"Don't say a word about it, madam. There's another that you're more -beholden to than you are to me and my boys, maybe, but he don't allow -me to tell his name. We wouldn't have been there but for him." - -Of course this excited a curiosity so vast that it almost belittled -the main matter--but the Welshman allowed it to eat into the vitals of -his visitors, and through them be transmitted to the whole town, for he -refused to part with his secret. When all else had been learned, the -widow said: - -"I went to sleep reading in bed and slept straight through all that -noise. Why didn't you come and wake me?" - -"We judged it warn't worth while. Those fellows warn't likely to come -again--they hadn't any tools left to work with, and what was the use of -waking you up and scaring you to death? My three negro men stood guard -at your house all the rest of the night. They've just come back." - -More visitors came, and the story had to be told and retold for a -couple of hours more. - -There was no Sabbath-school during day-school vacation, but everybody -was early at church. The stirring event was well canvassed. News came -that not a sign of the two villains had been yet discovered. When the -sermon was finished, Judge Thatcher's wife dropped alongside of Mrs. -Harper as she moved down the aisle with the crowd and said: - -"Is my Becky going to sleep all day? I just expected she would be -tired to death." - -"Your Becky?" - -"Yes," with a startled look--"didn't she stay with you last night?" - -"Why, no." - -Mrs. Thatcher turned pale, and sank into a pew, just as Aunt Polly, -talking briskly with a friend, passed by. Aunt Polly said: - -"Good-morning, Mrs. Thatcher. Good-morning, Mrs. Harper. I've got a -boy that's turned up missing. I reckon my Tom stayed at your house last -night--one of you. And now he's afraid to come to church. I've got to -settle with him." - -Mrs. Thatcher shook her head feebly and turned paler than ever. - -"He didn't stay with us," said Mrs. Harper, beginning to look uneasy. -A marked anxiety came into Aunt Polly's face. - -"Joe Harper, have you seen my Tom this morning?" - -"No'm." - -"When did you see him last?" - -Joe tried to remember, but was not sure he could say. The people had -stopped moving out of church. Whispers passed along, and a boding -uneasiness took possession of every countenance. Children were -anxiously questioned, and young teachers. They all said they had not -noticed whether Tom and Becky were on board the ferryboat on the -homeward trip; it was dark; no one thought of inquiring if any one was -missing. One young man finally blurted out his fear that they were -still in the cave! Mrs. Thatcher swooned away. Aunt Polly fell to -crying and wringing her hands. - -The alarm swept from lip to lip, from group to group, from street to -street, and within five minutes the bells were wildly clanging and the -whole town was up! The Cardiff Hill episode sank into instant -insignificance, the burglars were forgotten, horses were saddled, -skiffs were manned, the ferryboat ordered out, and before the horror -was half an hour old, two hundred men were pouring down highroad and -river toward the cave. - -All the long afternoon the village seemed empty and dead. Many women -visited Aunt Polly and Mrs. Thatcher and tried to comfort them. They -cried with them, too, and that was still better than words. All the -tedious night the town waited for news; but when the morning dawned at -last, all the word that came was, "Send more candles--and send food." -Mrs. Thatcher was almost crazed; and Aunt Polly, also. Judge Thatcher -sent messages of hope and encouragement from the cave, but they -conveyed no real cheer. - -The old Welshman came home toward daylight, spattered with -candle-grease, smeared with clay, and almost worn out. He found Huck -still in the bed that had been provided for him, and delirious with -fever. The physicians were all at the cave, so the Widow Douglas came -and took charge of the patient. She said she would do her best by him, -because, whether he was good, bad, or indifferent, he was the Lord's, -and nothing that was the Lord's was a thing to be neglected. The -Welshman said Huck had good spots in him, and the widow said: - -"You can depend on it. That's the Lord's mark. He don't leave it off. -He never does. Puts it somewhere on every creature that comes from his -hands." - -Early in the forenoon parties of jaded men began to straggle into the -village, but the strongest of the citizens continued searching. All the -news that could be gained was that remotenesses of the cavern were -being ransacked that had never been visited before; that every corner -and crevice was going to be thoroughly searched; that wherever one -wandered through the maze of passages, lights were to be seen flitting -hither and thither in the distance, and shoutings and pistol-shots sent -their hollow reverberations to the ear down the sombre aisles. In one -place, far from the section usually traversed by tourists, the names -"BECKY & TOM" had been found traced upon the rocky wall with -candle-smoke, and near at hand a grease-soiled bit of ribbon. Mrs. -Thatcher recognized the ribbon and cried over it. She said it was the -last relic she should ever have of her child; and that no other memorial -of her could ever be so precious, because this one parted latest from -the living body before the awful death came. Some said that now and -then, in the cave, a far-away speck of light would glimmer, and then a -glorious shout would burst forth and a score of men go trooping down the -echoing aisle--and then a sickening disappointment always followed; the -children were not there; it was only a searcher's light. - -Three dreadful days and nights dragged their tedious hours along, and -the village sank into a hopeless stupor. No one had heart for anything. -The accidental discovery, just made, that the proprietor of the -Temperance Tavern kept liquor on his premises, scarcely fluttered the -public pulse, tremendous as the fact was. In a lucid interval, Huck -feebly led up to the subject of taverns, and finally asked--dimly -dreading the worst--if anything had been discovered at the Temperance -Tavern since he had been ill. - -"Yes," said the widow. - -Huck started up in bed, wild-eyed: - -"What? What was it?" - -"Liquor!--and the place has been shut up. Lie down, child--what a turn -you did give me!" - -"Only tell me just one thing--only just one--please! Was it Tom Sawyer -that found it?" - -The widow burst into tears. "Hush, hush, child, hush! I've told you -before, you must NOT talk. You are very, very sick!" - -Then nothing but liquor had been found; there would have been a great -powwow if it had been the gold. So the treasure was gone forever--gone -forever! But what could she be crying about? Curious that she should -cry. - -These thoughts worked their dim way through Huck's mind, and under the -weariness they gave him he fell asleep. The widow said to herself: - -"There--he's asleep, poor wreck. Tom Sawyer find it! Pity but somebody -could find Tom Sawyer! Ah, there ain't many left, now, that's got hope -enough, or strength enough, either, to go on searching." - - - -CHAPTER XXXI - -NOW to return to Tom and Becky's share in the picnic. They tripped -along the murky aisles with the rest of the company, visiting the -familiar wonders of the cave--wonders dubbed with rather -over-descriptive names, such as "The Drawing-Room," "The Cathedral," -"Aladdin's Palace," and so on. Presently the hide-and-seek frolicking -began, and Tom and Becky engaged in it with zeal until the exertion -began to grow a trifle wearisome; then they wandered down a sinuous -avenue holding their candles aloft and reading the tangled web-work of -names, dates, post-office addresses, and mottoes with which the rocky -walls had been frescoed (in candle-smoke). Still drifting along and -talking, they scarcely noticed that they were now in a part of the cave -whose walls were not frescoed. They smoked their own names under an -overhanging shelf and moved on. Presently they came to a place where a -little stream of water, trickling over a ledge and carrying a limestone -sediment with it, had, in the slow-dragging ages, formed a laced and -ruffled Niagara in gleaming and imperishable stone. Tom squeezed his -small body behind it in order to illuminate it for Becky's -gratification. He found that it curtained a sort of steep natural -stairway which was enclosed between narrow walls, and at once the -ambition to be a discoverer seized him. Becky responded to his call, -and they made a smoke-mark for future guidance, and started upon their -quest. They wound this way and that, far down into the secret depths of -the cave, made another mark, and branched off in search of novelties to -tell the upper world about. In one place they found a spacious cavern, -from whose ceiling depended a multitude of shining stalactites of the -length and circumference of a man's leg; they walked all about it, -wondering and admiring, and presently left it by one of the numerous -passages that opened into it. This shortly brought them to a bewitching -spring, whose basin was incrusted with a frostwork of glittering -crystals; it was in the midst of a cavern whose walls were supported by -many fantastic pillars which had been formed by the joining of great -stalactites and stalagmites together, the result of the ceaseless -water-drip of centuries. Under the roof vast knots of bats had packed -themselves together, thousands in a bunch; the lights disturbed the -creatures and they came flocking down by hundreds, squeaking and -darting furiously at the candles. Tom knew their ways and the danger of -this sort of conduct. He seized Becky's hand and hurried her into the -first corridor that offered; and none too soon, for a bat struck -Becky's light out with its wing while she was passing out of the -cavern. The bats chased the children a good distance; but the fugitives -plunged into every new passage that offered, and at last got rid of the -perilous things. Tom found a subterranean lake, shortly, which -stretched its dim length away until its shape was lost in the shadows. -He wanted to explore its borders, but concluded that it would be best -to sit down and rest awhile, first. Now, for the first time, the deep -stillness of the place laid a clammy hand upon the spirits of the -children. Becky said: - -"Why, I didn't notice, but it seems ever so long since I heard any of -the others." - -"Come to think, Becky, we are away down below them--and I don't know -how far away north, or south, or east, or whichever it is. We couldn't -hear them here." - -Becky grew apprehensive. - -"I wonder how long we've been down here, Tom? We better start back." - -"Yes, I reckon we better. P'raps we better." - -"Can you find the way, Tom? It's all a mixed-up crookedness to me." - -"I reckon I could find it--but then the bats. If they put our candles -out it will be an awful fix. Let's try some other way, so as not to go -through there." - -"Well. But I hope we won't get lost. It would be so awful!" and the -girl shuddered at the thought of the dreadful possibilities. - -They started through a corridor, and traversed it in silence a long -way, glancing at each new opening, to see if there was anything -familiar about the look of it; but they were all strange. Every time -Tom made an examination, Becky would watch his face for an encouraging -sign, and he would say cheerily: - -"Oh, it's all right. This ain't the one, but we'll come to it right -away!" - -But he felt less and less hopeful with each failure, and presently -began to turn off into diverging avenues at sheer random, in desperate -hope of finding the one that was wanted. He still said it was "all -right," but there was such a leaden dread at his heart that the words -had lost their ring and sounded just as if he had said, "All is lost!" -Becky clung to his side in an anguish of fear, and tried hard to keep -back the tears, but they would come. At last she said: - -"Oh, Tom, never mind the bats, let's go back that way! We seem to get -worse and worse off all the time." - -"Listen!" said he. - -Profound silence; silence so deep that even their breathings were -conspicuous in the hush. Tom shouted. The call went echoing down the -empty aisles and died out in the distance in a faint sound that -resembled a ripple of mocking laughter. - -"Oh, don't do it again, Tom, it is too horrid," said Becky. - -"It is horrid, but I better, Becky; they might hear us, you know," and -he shouted again. - -The "might" was even a chillier horror than the ghostly laughter, it -so confessed a perishing hope. The children stood still and listened; -but there was no result. Tom turned upon the back track at once, and -hurried his steps. It was but a little while before a certain -indecision in his manner revealed another fearful fact to Becky--he -could not find his way back! - -"Oh, Tom, you didn't make any marks!" - -"Becky, I was such a fool! Such a fool! I never thought we might want -to come back! No--I can't find the way. It's all mixed up." - -"Tom, Tom, we're lost! we're lost! We never can get out of this awful -place! Oh, why DID we ever leave the others!" - -She sank to the ground and burst into such a frenzy of crying that Tom -was appalled with the idea that she might die, or lose her reason. He -sat down by her and put his arms around her; she buried her face in his -bosom, she clung to him, she poured out her terrors, her unavailing -regrets, and the far echoes turned them all to jeering laughter. Tom -begged her to pluck up hope again, and she said she could not. He fell -to blaming and abusing himself for getting her into this miserable -situation; this had a better effect. She said she would try to hope -again, she would get up and follow wherever he might lead if only he -would not talk like that any more. For he was no more to blame than -she, she said. - -So they moved on again--aimlessly--simply at random--all they could do -was to move, keep moving. For a little while, hope made a show of -reviving--not with any reason to back it, but only because it is its -nature to revive when the spring has not been taken out of it by age -and familiarity with failure. - -By-and-by Tom took Becky's candle and blew it out. This economy meant -so much! Words were not needed. Becky understood, and her hope died -again. She knew that Tom had a whole candle and three or four pieces in -his pockets--yet he must economize. - -By-and-by, fatigue began to assert its claims; the children tried to -pay attention, for it was dreadful to think of sitting down when time -was grown to be so precious, moving, in some direction, in any -direction, was at least progress and might bear fruit; but to sit down -was to invite death and shorten its pursuit. - -At last Becky's frail limbs refused to carry her farther. She sat -down. Tom rested with her, and they talked of home, and the friends -there, and the comfortable beds and, above all, the light! Becky cried, -and Tom tried to think of some way of comforting her, but all his -encouragements were grown threadbare with use, and sounded like -sarcasms. Fatigue bore so heavily upon Becky that she drowsed off to -sleep. Tom was grateful. He sat looking into her drawn face and saw it -grow smooth and natural under the influence of pleasant dreams; and -by-and-by a smile dawned and rested there. The peaceful face reflected -somewhat of peace and healing into his own spirit, and his thoughts -wandered away to bygone times and dreamy memories. While he was deep in -his musings, Becky woke up with a breezy little laugh--but it was -stricken dead upon her lips, and a groan followed it. - -"Oh, how COULD I sleep! I wish I never, never had waked! No! No, I -don't, Tom! Don't look so! I won't say it again." - -"I'm glad you've slept, Becky; you'll feel rested, now, and we'll find -the way out." - -"We can try, Tom; but I've seen such a beautiful country in my dream. -I reckon we are going there." - -"Maybe not, maybe not. Cheer up, Becky, and let's go on trying." - -They rose up and wandered along, hand in hand and hopeless. They tried -to estimate how long they had been in the cave, but all they knew was -that it seemed days and weeks, and yet it was plain that this could not -be, for their candles were not gone yet. A long time after this--they -could not tell how long--Tom said they must go softly and listen for -dripping water--they must find a spring. They found one presently, and -Tom said it was time to rest again. Both were cruelly tired, yet Becky -said she thought she could go a little farther. She was surprised to -hear Tom dissent. She could not understand it. They sat down, and Tom -fastened his candle to the wall in front of them with some clay. -Thought was soon busy; nothing was said for some time. Then Becky broke -the silence: - -"Tom, I am so hungry!" - -Tom took something out of his pocket. - -"Do you remember this?" said he. - -Becky almost smiled. - -"It's our wedding-cake, Tom." - -"Yes--I wish it was as big as a barrel, for it's all we've got." - -"I saved it from the picnic for us to dream on, Tom, the way grown-up -people do with wedding-cake--but it'll be our--" - -She dropped the sentence where it was. Tom divided the cake and Becky -ate with good appetite, while Tom nibbled at his moiety. There was -abundance of cold water to finish the feast with. By-and-by Becky -suggested that they move on again. Tom was silent a moment. Then he -said: - -"Becky, can you bear it if I tell you something?" - -Becky's face paled, but she thought she could. - -"Well, then, Becky, we must stay here, where there's water to drink. -That little piece is our last candle!" - -Becky gave loose to tears and wailings. Tom did what he could to -comfort her, but with little effect. At length Becky said: - -"Tom!" - -"Well, Becky?" - -"They'll miss us and hunt for us!" - -"Yes, they will! Certainly they will!" - -"Maybe they're hunting for us now, Tom." - -"Why, I reckon maybe they are. I hope they are." - -"When would they miss us, Tom?" - -"When they get back to the boat, I reckon." - -"Tom, it might be dark then--would they notice we hadn't come?" - -"I don't know. But anyway, your mother would miss you as soon as they -got home." - -A frightened look in Becky's face brought Tom to his senses and he saw -that he had made a blunder. Becky was not to have gone home that night! -The children became silent and thoughtful. In a moment a new burst of -grief from Becky showed Tom that the thing in his mind had struck hers -also--that the Sabbath morning might be half spent before Mrs. Thatcher -discovered that Becky was not at Mrs. Harper's. - -The children fastened their eyes upon their bit of candle and watched -it melt slowly and pitilessly away; saw the half inch of wick stand -alone at last; saw the feeble flame rise and fall, climb the thin -column of smoke, linger at its top a moment, and then--the horror of -utter darkness reigned! - -How long afterward it was that Becky came to a slow consciousness that -she was crying in Tom's arms, neither could tell. All that they knew -was, that after what seemed a mighty stretch of time, both awoke out of -a dead stupor of sleep and resumed their miseries once more. Tom said -it might be Sunday, now--maybe Monday. He tried to get Becky to talk, -but her sorrows were too oppressive, all her hopes were gone. Tom said -that they must have been missed long ago, and no doubt the search was -going on. He would shout and maybe some one would come. He tried it; -but in the darkness the distant echoes sounded so hideously that he -tried it no more. - -The hours wasted away, and hunger came to torment the captives again. -A portion of Tom's half of the cake was left; they divided and ate it. -But they seemed hungrier than before. The poor morsel of food only -whetted desire. - -By-and-by Tom said: - -"SH! Did you hear that?" - -Both held their breath and listened. There was a sound like the -faintest, far-off shout. Instantly Tom answered it, and leading Becky -by the hand, started groping down the corridor in its direction. -Presently he listened again; again the sound was heard, and apparently -a little nearer. - -"It's them!" said Tom; "they're coming! Come along, Becky--we're all -right now!" - -The joy of the prisoners was almost overwhelming. Their speed was -slow, however, because pitfalls were somewhat common, and had to be -guarded against. They shortly came to one and had to stop. It might be -three feet deep, it might be a hundred--there was no passing it at any -rate. Tom got down on his breast and reached as far down as he could. -No bottom. They must stay there and wait until the searchers came. They -listened; evidently the distant shoutings were growing more distant! a -moment or two more and they had gone altogether. The heart-sinking -misery of it! Tom whooped until he was hoarse, but it was of no use. He -talked hopefully to Becky; but an age of anxious waiting passed and no -sounds came again. - -The children groped their way back to the spring. The weary time -dragged on; they slept again, and awoke famished and woe-stricken. Tom -believed it must be Tuesday by this time. - -Now an idea struck him. There were some side passages near at hand. It -would be better to explore some of these than bear the weight of the -heavy time in idleness. He took a kite-line from his pocket, tied it to -a projection, and he and Becky started, Tom in the lead, unwinding the -line as he groped along. At the end of twenty steps the corridor ended -in a "jumping-off place." Tom got down on his knees and felt below, and -then as far around the corner as he could reach with his hands -conveniently; he made an effort to stretch yet a little farther to the -right, and at that moment, not twenty yards away, a human hand, holding -a candle, appeared from behind a rock! Tom lifted up a glorious shout, -and instantly that hand was followed by the body it belonged to--Injun -Joe's! Tom was paralyzed; he could not move. He was vastly gratified -the next moment, to see the "Spaniard" take to his heels and get -himself out of sight. Tom wondered that Joe had not recognized his -voice and come over and killed him for testifying in court. But the -echoes must have disguised the voice. Without doubt, that was it, he -reasoned. Tom's fright weakened every muscle in his body. He said to -himself that if he had strength enough to get back to the spring he -would stay there, and nothing should tempt him to run the risk of -meeting Injun Joe again. He was careful to keep from Becky what it was -he had seen. He told her he had only shouted "for luck." - -But hunger and wretchedness rise superior to fears in the long run. -Another tedious wait at the spring and another long sleep brought -changes. The children awoke tortured with a raging hunger. Tom believed -that it must be Wednesday or Thursday or even Friday or Saturday, now, -and that the search had been given over. He proposed to explore another -passage. He felt willing to risk Injun Joe and all other terrors. But -Becky was very weak. She had sunk into a dreary apathy and would not be -roused. She said she would wait, now, where she was, and die--it would -not be long. She told Tom to go with the kite-line and explore if he -chose; but she implored him to come back every little while and speak -to her; and she made him promise that when the awful time came, he -would stay by her and hold her hand until all was over. - -Tom kissed her, with a choking sensation in his throat, and made a -show of being confident of finding the searchers or an escape from the -cave; then he took the kite-line in his hand and went groping down one -of the passages on his hands and knees, distressed with hunger and sick -with bodings of coming doom. - - - -CHAPTER XXXII - -TUESDAY afternoon came, and waned to the twilight. The village of St. -Petersburg still mourned. The lost children had not been found. Public -prayers had been offered up for them, and many and many a private -prayer that had the petitioner's whole heart in it; but still no good -news came from the cave. The majority of the searchers had given up the -quest and gone back to their daily avocations, saying that it was plain -the children could never be found. Mrs. Thatcher was very ill, and a -great part of the time delirious. People said it was heartbreaking to -hear her call her child, and raise her head and listen a whole minute -at a time, then lay it wearily down again with a moan. Aunt Polly had -drooped into a settled melancholy, and her gray hair had grown almost -white. The village went to its rest on Tuesday night, sad and forlorn. - -Away in the middle of the night a wild peal burst from the village -bells, and in a moment the streets were swarming with frantic half-clad -people, who shouted, "Turn out! turn out! they're found! they're -found!" Tin pans and horns were added to the din, the population massed -itself and moved toward the river, met the children coming in an open -carriage drawn by shouting citizens, thronged around it, joined its -homeward march, and swept magnificently up the main street roaring -huzzah after huzzah! - -The village was illuminated; nobody went to bed again; it was the -greatest night the little town had ever seen. During the first half-hour -a procession of villagers filed through Judge Thatcher's house, seized -the saved ones and kissed them, squeezed Mrs. Thatcher's hand, tried to -speak but couldn't--and drifted out raining tears all over the place. - -Aunt Polly's happiness was complete, and Mrs. Thatcher's nearly so. It -would be complete, however, as soon as the messenger dispatched with -the great news to the cave should get the word to her husband. Tom lay -upon a sofa with an eager auditory about him and told the history of -the wonderful adventure, putting in many striking additions to adorn it -withal; and closed with a description of how he left Becky and went on -an exploring expedition; how he followed two avenues as far as his -kite-line would reach; how he followed a third to the fullest stretch of -the kite-line, and was about to turn back when he glimpsed a far-off -speck that looked like daylight; dropped the line and groped toward it, -pushed his head and shoulders through a small hole, and saw the broad -Mississippi rolling by! And if it had only happened to be night he would -not have seen that speck of daylight and would not have explored that -passage any more! He told how he went back for Becky and broke the good -news and she told him not to fret her with such stuff, for she was -tired, and knew she was going to die, and wanted to. He described how he -labored with her and convinced her; and how she almost died for joy when -she had groped to where she actually saw the blue speck of daylight; how -he pushed his way out at the hole and then helped her out; how they sat -there and cried for gladness; how some men came along in a skiff and Tom -hailed them and told them their situation and their famished condition; -how the men didn't believe the wild tale at first, "because," said they, -"you are five miles down the river below the valley the cave is in" ---then took them aboard, rowed to a house, gave them supper, made them -rest till two or three hours after dark and then brought them home. - -Before day-dawn, Judge Thatcher and the handful of searchers with him -were tracked out, in the cave, by the twine clews they had strung -behind them, and informed of the great news. - -Three days and nights of toil and hunger in the cave were not to be -shaken off at once, as Tom and Becky soon discovered. They were -bedridden all of Wednesday and Thursday, and seemed to grow more and -more tired and worn, all the time. Tom got about, a little, on -Thursday, was down-town Friday, and nearly as whole as ever Saturday; -but Becky did not leave her room until Sunday, and then she looked as -if she had passed through a wasting illness. - -Tom learned of Huck's sickness and went to see him on Friday, but -could not be admitted to the bedroom; neither could he on Saturday or -Sunday. He was admitted daily after that, but was warned to keep still -about his adventure and introduce no exciting topic. The Widow Douglas -stayed by to see that he obeyed. At home Tom learned of the Cardiff -Hill event; also that the "ragged man's" body had eventually been found -in the river near the ferry-landing; he had been drowned while trying -to escape, perhaps. - -About a fortnight after Tom's rescue from the cave, he started off to -visit Huck, who had grown plenty strong enough, now, to hear exciting -talk, and Tom had some that would interest him, he thought. Judge -Thatcher's house was on Tom's way, and he stopped to see Becky. The -Judge and some friends set Tom to talking, and some one asked him -ironically if he wouldn't like to go to the cave again. Tom said he -thought he wouldn't mind it. The Judge said: - -"Well, there are others just like you, Tom, I've not the least doubt. -But we have taken care of that. Nobody will get lost in that cave any -more." - -"Why?" - -"Because I had its big door sheathed with boiler iron two weeks ago, -and triple-locked--and I've got the keys." - -Tom turned as white as a sheet. - -"What's the matter, boy! Here, run, somebody! Fetch a glass of water!" - -The water was brought and thrown into Tom's face. - -"Ah, now you're all right. What was the matter with you, Tom?" - -"Oh, Judge, Injun Joe's in the cave!" - - - -CHAPTER XXXIII - -WITHIN a few minutes the news had spread, and a dozen skiff-loads of -men were on their way to McDougal's cave, and the ferryboat, well -filled with passengers, soon followed. Tom Sawyer was in the skiff that -bore Judge Thatcher. - -When the cave door was unlocked, a sorrowful sight presented itself in -the dim twilight of the place. Injun Joe lay stretched upon the ground, -dead, with his face close to the crack of the door, as if his longing -eyes had been fixed, to the latest moment, upon the light and the cheer -of the free world outside. Tom was touched, for he knew by his own -experience how this wretch had suffered. His pity was moved, but -nevertheless he felt an abounding sense of relief and security, now, -which revealed to him in a degree which he had not fully appreciated -before how vast a weight of dread had been lying upon him since the day -he lifted his voice against this bloody-minded outcast. - -Injun Joe's bowie-knife lay close by, its blade broken in two. The -great foundation-beam of the door had been chipped and hacked through, -with tedious labor; useless labor, too, it was, for the native rock -formed a sill outside it, and upon that stubborn material the knife had -wrought no effect; the only damage done was to the knife itself. But if -there had been no stony obstruction there the labor would have been -useless still, for if the beam had been wholly cut away Injun Joe could -not have squeezed his body under the door, and he knew it. So he had -only hacked that place in order to be doing something--in order to pass -the weary time--in order to employ his tortured faculties. Ordinarily -one could find half a dozen bits of candle stuck around in the crevices -of this vestibule, left there by tourists; but there were none now. The -prisoner had searched them out and eaten them. He had also contrived to -catch a few bats, and these, also, he had eaten, leaving only their -claws. The poor unfortunate had starved to death. In one place, near at -hand, a stalagmite had been slowly growing up from the ground for ages, -builded by the water-drip from a stalactite overhead. The captive had -broken off the stalagmite, and upon the stump had placed a stone, -wherein he had scooped a shallow hollow to catch the precious drop -that fell once in every three minutes with the dreary regularity of a -clock-tick--a dessertspoonful once in four and twenty hours. That drop -was falling when the Pyramids were new; when Troy fell; when the -foundations of Rome were laid; when Christ was crucified; when the -Conqueror created the British empire; when Columbus sailed; when the -massacre at Lexington was "news." It is falling now; it will still be -falling when all these things shall have sunk down the afternoon of -history, and the twilight of tradition, and been swallowed up in the -thick night of oblivion. Has everything a purpose and a mission? Did -this drop fall patiently during five thousand years to be ready for -this flitting human insect's need? and has it another important object -to accomplish ten thousand years to come? No matter. It is many and -many a year since the hapless half-breed scooped out the stone to catch -the priceless drops, but to this day the tourist stares longest at that -pathetic stone and that slow-dropping water when he comes to see the -wonders of McDougal's cave. Injun Joe's cup stands first in the list of -the cavern's marvels; even "Aladdin's Palace" cannot rival it. - -Injun Joe was buried near the mouth of the cave; and people flocked -there in boats and wagons from the towns and from all the farms and -hamlets for seven miles around; they brought their children, and all -sorts of provisions, and confessed that they had had almost as -satisfactory a time at the funeral as they could have had at the -hanging. - -This funeral stopped the further growth of one thing--the petition to -the governor for Injun Joe's pardon. The petition had been largely -signed; many tearful and eloquent meetings had been held, and a -committee of sappy women been appointed to go in deep mourning and wail -around the governor, and implore him to be a merciful ass and trample -his duty under foot. Injun Joe was believed to have killed five -citizens of the village, but what of that? If he had been Satan himself -there would have been plenty of weaklings ready to scribble their names -to a pardon-petition, and drip a tear on it from their permanently -impaired and leaky water-works. - -The morning after the funeral Tom took Huck to a private place to have -an important talk. Huck had learned all about Tom's adventure from the -Welshman and the Widow Douglas, by this time, but Tom said he reckoned -there was one thing they had not told him; that thing was what he -wanted to talk about now. Huck's face saddened. He said: - -"I know what it is. You got into No. 2 and never found anything but -whiskey. Nobody told me it was you; but I just knowed it must 'a' ben -you, soon as I heard 'bout that whiskey business; and I knowed you -hadn't got the money becuz you'd 'a' got at me some way or other and -told me even if you was mum to everybody else. Tom, something's always -told me we'd never get holt of that swag." - -"Why, Huck, I never told on that tavern-keeper. YOU know his tavern -was all right the Saturday I went to the picnic. Don't you remember you -was to watch there that night?" - -"Oh yes! Why, it seems 'bout a year ago. It was that very night that I -follered Injun Joe to the widder's." - -"YOU followed him?" - -"Yes--but you keep mum. I reckon Injun Joe's left friends behind him, -and I don't want 'em souring on me and doing me mean tricks. If it -hadn't ben for me he'd be down in Texas now, all right." - -Then Huck told his entire adventure in confidence to Tom, who had only -heard of the Welshman's part of it before. - -"Well," said Huck, presently, coming back to the main question, -"whoever nipped the whiskey in No. 2, nipped the money, too, I reckon ---anyways it's a goner for us, Tom." - -"Huck, that money wasn't ever in No. 2!" - -"What!" Huck searched his comrade's face keenly. "Tom, have you got on -the track of that money again?" - -"Huck, it's in the cave!" - -Huck's eyes blazed. - -"Say it again, Tom." - -"The money's in the cave!" - -"Tom--honest injun, now--is it fun, or earnest?" - -"Earnest, Huck--just as earnest as ever I was in my life. Will you go -in there with me and help get it out?" - -"I bet I will! I will if it's where we can blaze our way to it and not -get lost." - -"Huck, we can do that without the least little bit of trouble in the -world." - -"Good as wheat! What makes you think the money's--" - -"Huck, you just wait till we get in there. If we don't find it I'll -agree to give you my drum and every thing I've got in the world. I -will, by jings." - -"All right--it's a whiz. When do you say?" - -"Right now, if you say it. Are you strong enough?" - -"Is it far in the cave? I ben on my pins a little, three or four days, -now, but I can't walk more'n a mile, Tom--least I don't think I could." - -"It's about five mile into there the way anybody but me would go, -Huck, but there's a mighty short cut that they don't anybody but me -know about. Huck, I'll take you right to it in a skiff. I'll float the -skiff down there, and I'll pull it back again all by myself. You -needn't ever turn your hand over." - -"Less start right off, Tom." - -"All right. We want some bread and meat, and our pipes, and a little -bag or two, and two or three kite-strings, and some of these -new-fangled things they call lucifer matches. I tell you, many's -the time I wished I had some when I was in there before." - -A trifle after noon the boys borrowed a small skiff from a citizen who -was absent, and got under way at once. When they were several miles -below "Cave Hollow," Tom said: - -"Now you see this bluff here looks all alike all the way down from the -cave hollow--no houses, no wood-yards, bushes all alike. But do you see -that white place up yonder where there's been a landslide? Well, that's -one of my marks. We'll get ashore, now." - -They landed. - -"Now, Huck, where we're a-standing you could touch that hole I got out -of with a fishing-pole. See if you can find it." - -Huck searched all the place about, and found nothing. Tom proudly -marched into a thick clump of sumach bushes and said: - -"Here you are! Look at it, Huck; it's the snuggest hole in this -country. You just keep mum about it. All along I've been wanting to be -a robber, but I knew I'd got to have a thing like this, and where to -run across it was the bother. We've got it now, and we'll keep it -quiet, only we'll let Joe Harper and Ben Rogers in--because of course -there's got to be a Gang, or else there wouldn't be any style about it. -Tom Sawyer's Gang--it sounds splendid, don't it, Huck?" - -"Well, it just does, Tom. And who'll we rob?" - -"Oh, most anybody. Waylay people--that's mostly the way." - -"And kill them?" - -"No, not always. Hive them in the cave till they raise a ransom." - -"What's a ransom?" - -"Money. You make them raise all they can, off'n their friends; and -after you've kept them a year, if it ain't raised then you kill them. -That's the general way. Only you don't kill the women. You shut up the -women, but you don't kill them. They're always beautiful and rich, and -awfully scared. You take their watches and things, but you always take -your hat off and talk polite. They ain't anybody as polite as robbers ---you'll see that in any book. Well, the women get to loving you, and -after they've been in the cave a week or two weeks they stop crying and -after that you couldn't get them to leave. If you drove them out they'd -turn right around and come back. It's so in all the books." - -"Why, it's real bully, Tom. I believe it's better'n to be a pirate." - -"Yes, it's better in some ways, because it's close to home and -circuses and all that." - -By this time everything was ready and the boys entered the hole, Tom -in the lead. They toiled their way to the farther end of the tunnel, -then made their spliced kite-strings fast and moved on. A few steps -brought them to the spring, and Tom felt a shudder quiver all through -him. He showed Huck the fragment of candle-wick perched on a lump of -clay against the wall, and described how he and Becky had watched the -flame struggle and expire. - -The boys began to quiet down to whispers, now, for the stillness and -gloom of the place oppressed their spirits. They went on, and presently -entered and followed Tom's other corridor until they reached the -"jumping-off place." The candles revealed the fact that it was not -really a precipice, but only a steep clay hill twenty or thirty feet -high. Tom whispered: - -"Now I'll show you something, Huck." - -He held his candle aloft and said: - -"Look as far around the corner as you can. Do you see that? There--on -the big rock over yonder--done with candle-smoke." - -"Tom, it's a CROSS!" - -"NOW where's your Number Two? 'UNDER THE CROSS,' hey? Right yonder's -where I saw Injun Joe poke up his candle, Huck!" - -Huck stared at the mystic sign awhile, and then said with a shaky voice: - -"Tom, less git out of here!" - -"What! and leave the treasure?" - -"Yes--leave it. Injun Joe's ghost is round about there, certain." - -"No it ain't, Huck, no it ain't. It would ha'nt the place where he -died--away out at the mouth of the cave--five mile from here." - -"No, Tom, it wouldn't. It would hang round the money. I know the ways -of ghosts, and so do you." - -Tom began to fear that Huck was right. Misgivings gathered in his -mind. But presently an idea occurred to him-- - -"Lookyhere, Huck, what fools we're making of ourselves! Injun Joe's -ghost ain't a going to come around where there's a cross!" - -The point was well taken. It had its effect. - -"Tom, I didn't think of that. But that's so. It's luck for us, that -cross is. I reckon we'll climb down there and have a hunt for that box." - -Tom went first, cutting rude steps in the clay hill as he descended. -Huck followed. Four avenues opened out of the small cavern which the -great rock stood in. The boys examined three of them with no result. -They found a small recess in the one nearest the base of the rock, with -a pallet of blankets spread down in it; also an old suspender, some -bacon rind, and the well-gnawed bones of two or three fowls. But there -was no money-box. The lads searched and researched this place, but in -vain. Tom said: - -"He said UNDER the cross. Well, this comes nearest to being under the -cross. It can't be under the rock itself, because that sets solid on -the ground." - -They searched everywhere once more, and then sat down discouraged. -Huck could suggest nothing. By-and-by Tom said: - -"Lookyhere, Huck, there's footprints and some candle-grease on the -clay about one side of this rock, but not on the other sides. Now, -what's that for? I bet you the money IS under the rock. I'm going to -dig in the clay." - -"That ain't no bad notion, Tom!" said Huck with animation. - -Tom's "real Barlow" was out at once, and he had not dug four inches -before he struck wood. - -"Hey, Huck!--you hear that?" - -Huck began to dig and scratch now. Some boards were soon uncovered and -removed. They had concealed a natural chasm which led under the rock. -Tom got into this and held his candle as far under the rock as he -could, but said he could not see to the end of the rift. He proposed to -explore. He stooped and passed under; the narrow way descended -gradually. He followed its winding course, first to the right, then to -the left, Huck at his heels. Tom turned a short curve, by-and-by, and -exclaimed: - -"My goodness, Huck, lookyhere!" - -It was the treasure-box, sure enough, occupying a snug little cavern, -along with an empty powder-keg, a couple of guns in leather cases, two -or three pairs of old moccasins, a leather belt, and some other rubbish -well soaked with the water-drip. - -"Got it at last!" said Huck, ploughing among the tarnished coins with -his hand. "My, but we're rich, Tom!" - -"Huck, I always reckoned we'd get it. It's just too good to believe, -but we HAVE got it, sure! Say--let's not fool around here. Let's snake -it out. Lemme see if I can lift the box." - -It weighed about fifty pounds. Tom could lift it, after an awkward -fashion, but could not carry it conveniently. - -"I thought so," he said; "THEY carried it like it was heavy, that day -at the ha'nted house. I noticed that. I reckon I was right to think of -fetching the little bags along." - -The money was soon in the bags and the boys took it up to the cross -rock. - -"Now less fetch the guns and things," said Huck. - -"No, Huck--leave them there. They're just the tricks to have when we -go to robbing. We'll keep them there all the time, and we'll hold our -orgies there, too. It's an awful snug place for orgies." - -"What orgies?" - -"I dono. But robbers always have orgies, and of course we've got to -have them, too. Come along, Huck, we've been in here a long time. It's -getting late, I reckon. I'm hungry, too. We'll eat and smoke when we -get to the skiff." - -They presently emerged into the clump of sumach bushes, looked warily -out, found the coast clear, and were soon lunching and smoking in the -skiff. As the sun dipped toward the horizon they pushed out and got -under way. Tom skimmed up the shore through the long twilight, chatting -cheerily with Huck, and landed shortly after dark. - -"Now, Huck," said Tom, "we'll hide the money in the loft of the -widow's woodshed, and I'll come up in the morning and we'll count it -and divide, and then we'll hunt up a place out in the woods for it -where it will be safe. Just you lay quiet here and watch the stuff till -I run and hook Benny Taylor's little wagon; I won't be gone a minute." - -He disappeared, and presently returned with the wagon, put the two -small sacks into it, threw some old rags on top of them, and started -off, dragging his cargo behind him. When the boys reached the -Welshman's house, they stopped to rest. Just as they were about to move -on, the Welshman stepped out and said: - -"Hallo, who's that?" - -"Huck and Tom Sawyer." - -"Good! Come along with me, boys, you are keeping everybody waiting. -Here--hurry up, trot ahead--I'll haul the wagon for you. Why, it's not -as light as it might be. Got bricks in it?--or old metal?" - -"Old metal," said Tom. - -"I judged so; the boys in this town will take more trouble and fool -away more time hunting up six bits' worth of old iron to sell to the -foundry than they would to make twice the money at regular work. But -that's human nature--hurry along, hurry along!" - -The boys wanted to know what the hurry was about. - -"Never mind; you'll see, when we get to the Widow Douglas'." - -Huck said with some apprehension--for he was long used to being -falsely accused: - -"Mr. Jones, we haven't been doing nothing." - -The Welshman laughed. - -"Well, I don't know, Huck, my boy. I don't know about that. Ain't you -and the widow good friends?" - -"Yes. Well, she's ben good friends to me, anyway." - -"All right, then. What do you want to be afraid for?" - -This question was not entirely answered in Huck's slow mind before he -found himself pushed, along with Tom, into Mrs. Douglas' drawing-room. -Mr. Jones left the wagon near the door and followed. - -The place was grandly lighted, and everybody that was of any -consequence in the village was there. The Thatchers were there, the -Harpers, the Rogerses, Aunt Polly, Sid, Mary, the minister, the editor, -and a great many more, and all dressed in their best. The widow -received the boys as heartily as any one could well receive two such -looking beings. They were covered with clay and candle-grease. Aunt -Polly blushed crimson with humiliation, and frowned and shook her head -at Tom. Nobody suffered half as much as the two boys did, however. Mr. -Jones said: - -"Tom wasn't at home, yet, so I gave him up; but I stumbled on him and -Huck right at my door, and so I just brought them along in a hurry." - -"And you did just right," said the widow. "Come with me, boys." - -She took them to a bedchamber and said: - -"Now wash and dress yourselves. Here are two new suits of clothes ---shirts, socks, everything complete. They're Huck's--no, no thanks, -Huck--Mr. Jones bought one and I the other. But they'll fit both of you. -Get into them. We'll wait--come down when you are slicked up enough." - -Then she left. - - - -CHAPTER XXXIV - -HUCK said: "Tom, we can slope, if we can find a rope. The window ain't -high from the ground." - -"Shucks! what do you want to slope for?" - -"Well, I ain't used to that kind of a crowd. I can't stand it. I ain't -going down there, Tom." - -"Oh, bother! It ain't anything. I don't mind it a bit. I'll take care -of you." - -Sid appeared. - -"Tom," said he, "auntie has been waiting for you all the afternoon. -Mary got your Sunday clothes ready, and everybody's been fretting about -you. Say--ain't this grease and clay, on your clothes?" - -"Now, Mr. Siddy, you jist 'tend to your own business. What's all this -blow-out about, anyway?" - -"It's one of the widow's parties that she's always having. This time -it's for the Welshman and his sons, on account of that scrape they -helped her out of the other night. And say--I can tell you something, -if you want to know." - -"Well, what?" - -"Why, old Mr. Jones is going to try to spring something on the people -here to-night, but I overheard him tell auntie to-day about it, as a -secret, but I reckon it's not much of a secret now. Everybody knows ---the widow, too, for all she tries to let on she don't. Mr. Jones was -bound Huck should be here--couldn't get along with his grand secret -without Huck, you know!" - -"Secret about what, Sid?" - -"About Huck tracking the robbers to the widow's. I reckon Mr. Jones -was going to make a grand time over his surprise, but I bet you it will -drop pretty flat." - -Sid chuckled in a very contented and satisfied way. - -"Sid, was it you that told?" - -"Oh, never mind who it was. SOMEBODY told--that's enough." - -"Sid, there's only one person in this town mean enough to do that, and -that's you. If you had been in Huck's place you'd 'a' sneaked down the -hill and never told anybody on the robbers. You can't do any but mean -things, and you can't bear to see anybody praised for doing good ones. -There--no thanks, as the widow says"--and Tom cuffed Sid's ears and -helped him to the door with several kicks. "Now go and tell auntie if -you dare--and to-morrow you'll catch it!" - -Some minutes later the widow's guests were at the supper-table, and a -dozen children were propped up at little side-tables in the same room, -after the fashion of that country and that day. At the proper time Mr. -Jones made his little speech, in which he thanked the widow for the -honor she was doing himself and his sons, but said that there was -another person whose modesty-- - -And so forth and so on. He sprung his secret about Huck's share in the -adventure in the finest dramatic manner he was master of, but the -surprise it occasioned was largely counterfeit and not as clamorous and -effusive as it might have been under happier circumstances. However, -the widow made a pretty fair show of astonishment, and heaped so many -compliments and so much gratitude upon Huck that he almost forgot the -nearly intolerable discomfort of his new clothes in the entirely -intolerable discomfort of being set up as a target for everybody's gaze -and everybody's laudations. - -The widow said she meant to give Huck a home under her roof and have -him educated; and that when she could spare the money she would start -him in business in a modest way. Tom's chance was come. He said: - -"Huck don't need it. Huck's rich." - -Nothing but a heavy strain upon the good manners of the company kept -back the due and proper complimentary laugh at this pleasant joke. But -the silence was a little awkward. Tom broke it: - -"Huck's got money. Maybe you don't believe it, but he's got lots of -it. Oh, you needn't smile--I reckon I can show you. You just wait a -minute." - -Tom ran out of doors. The company looked at each other with a -perplexed interest--and inquiringly at Huck, who was tongue-tied. - -"Sid, what ails Tom?" said Aunt Polly. "He--well, there ain't ever any -making of that boy out. I never--" - -Tom entered, struggling with the weight of his sacks, and Aunt Polly -did not finish her sentence. Tom poured the mass of yellow coin upon -the table and said: - -"There--what did I tell you? Half of it's Huck's and half of it's mine!" - -The spectacle took the general breath away. All gazed, nobody spoke -for a moment. Then there was a unanimous call for an explanation. Tom -said he could furnish it, and he did. The tale was long, but brimful of -interest. There was scarcely an interruption from any one to break the -charm of its flow. When he had finished, Mr. Jones said: - -"I thought I had fixed up a little surprise for this occasion, but it -don't amount to anything now. This one makes it sing mighty small, I'm -willing to allow." - -The money was counted. The sum amounted to a little over twelve -thousand dollars. It was more than any one present had ever seen at one -time before, though several persons were there who were worth -considerably more than that in property. - - - -CHAPTER XXXV - -THE reader may rest satisfied that Tom's and Huck's windfall made a -mighty stir in the poor little village of St. Petersburg. So vast a -sum, all in actual cash, seemed next to incredible. It was talked -about, gloated over, glorified, until the reason of many of the -citizens tottered under the strain of the unhealthy excitement. Every -"haunted" house in St. Petersburg and the neighboring villages was -dissected, plank by plank, and its foundations dug up and ransacked for -hidden treasure--and not by boys, but men--pretty grave, unromantic -men, too, some of them. Wherever Tom and Huck appeared they were -courted, admired, stared at. The boys were not able to remember that -their remarks had possessed weight before; but now their sayings were -treasured and repeated; everything they did seemed somehow to be -regarded as remarkable; they had evidently lost the power of doing and -saying commonplace things; moreover, their past history was raked up -and discovered to bear marks of conspicuous originality. The village -paper published biographical sketches of the boys. - -The Widow Douglas put Huck's money out at six per cent., and Judge -Thatcher did the same with Tom's at Aunt Polly's request. Each lad had -an income, now, that was simply prodigious--a dollar for every week-day -in the year and half of the Sundays. It was just what the minister got ---no, it was what he was promised--he generally couldn't collect it. A -dollar and a quarter a week would board, lodge, and school a boy in -those old simple days--and clothe him and wash him, too, for that -matter. - -Judge Thatcher had conceived a great opinion of Tom. He said that no -commonplace boy would ever have got his daughter out of the cave. When -Becky told her father, in strict confidence, how Tom had taken her -whipping at school, the Judge was visibly moved; and when she pleaded -grace for the mighty lie which Tom had told in order to shift that -whipping from her shoulders to his own, the Judge said with a fine -outburst that it was a noble, a generous, a magnanimous lie--a lie that -was worthy to hold up its head and march down through history breast to -breast with George Washington's lauded Truth about the hatchet! Becky -thought her father had never looked so tall and so superb as when he -walked the floor and stamped his foot and said that. She went straight -off and told Tom about it. - -Judge Thatcher hoped to see Tom a great lawyer or a great soldier some -day. He said he meant to look to it that Tom should be admitted to the -National Military Academy and afterward trained in the best law school -in the country, in order that he might be ready for either career or -both. - -Huck Finn's wealth and the fact that he was now under the Widow -Douglas' protection introduced him into society--no, dragged him into -it, hurled him into it--and his sufferings were almost more than he -could bear. The widow's servants kept him clean and neat, combed and -brushed, and they bedded him nightly in unsympathetic sheets that had -not one little spot or stain which he could press to his heart and know -for a friend. He had to eat with a knife and fork; he had to use -napkin, cup, and plate; he had to learn his book, he had to go to -church; he had to talk so properly that speech was become insipid in -his mouth; whithersoever he turned, the bars and shackles of -civilization shut him in and bound him hand and foot. - -He bravely bore his miseries three weeks, and then one day turned up -missing. For forty-eight hours the widow hunted for him everywhere in -great distress. The public were profoundly concerned; they searched -high and low, they dragged the river for his body. Early the third -morning Tom Sawyer wisely went poking among some old empty hogsheads -down behind the abandoned slaughter-house, and in one of them he found -the refugee. Huck had slept there; he had just breakfasted upon some -stolen odds and ends of food, and was lying off, now, in comfort, with -his pipe. He was unkempt, uncombed, and clad in the same old ruin of -rags that had made him picturesque in the days when he was free and -happy. Tom routed him out, told him the trouble he had been causing, -and urged him to go home. Huck's face lost its tranquil content, and -took a melancholy cast. He said: - -"Don't talk about it, Tom. I've tried it, and it don't work; it don't -work, Tom. It ain't for me; I ain't used to it. The widder's good to -me, and friendly; but I can't stand them ways. She makes me get up just -at the same time every morning; she makes me wash, they comb me all to -thunder; she won't let me sleep in the woodshed; I got to wear them -blamed clothes that just smothers me, Tom; they don't seem to any air -git through 'em, somehow; and they're so rotten nice that I can't set -down, nor lay down, nor roll around anywher's; I hain't slid on a -cellar-door for--well, it 'pears to be years; I got to go to church and -sweat and sweat--I hate them ornery sermons! I can't ketch a fly in -there, I can't chaw. I got to wear shoes all Sunday. The widder eats by -a bell; she goes to bed by a bell; she gits up by a bell--everything's -so awful reg'lar a body can't stand it." - -"Well, everybody does that way, Huck." - -"Tom, it don't make no difference. I ain't everybody, and I can't -STAND it. It's awful to be tied up so. And grub comes too easy--I don't -take no interest in vittles, that way. I got to ask to go a-fishing; I -got to ask to go in a-swimming--dern'd if I hain't got to ask to do -everything. Well, I'd got to talk so nice it wasn't no comfort--I'd got -to go up in the attic and rip out awhile, every day, to git a taste in -my mouth, or I'd a died, Tom. The widder wouldn't let me smoke; she -wouldn't let me yell, she wouldn't let me gape, nor stretch, nor -scratch, before folks--" [Then with a spasm of special irritation and -injury]--"And dad fetch it, she prayed all the time! I never see such a -woman! I HAD to shove, Tom--I just had to. And besides, that school's -going to open, and I'd a had to go to it--well, I wouldn't stand THAT, -Tom. Looky here, Tom, being rich ain't what it's cracked up to be. It's -just worry and worry, and sweat and sweat, and a-wishing you was dead -all the time. Now these clothes suits me, and this bar'l suits me, and -I ain't ever going to shake 'em any more. Tom, I wouldn't ever got into -all this trouble if it hadn't 'a' ben for that money; now you just take -my sheer of it along with your'n, and gimme a ten-center sometimes--not -many times, becuz I don't give a dern for a thing 'thout it's tollable -hard to git--and you go and beg off for me with the widder." - -"Oh, Huck, you know I can't do that. 'Tain't fair; and besides if -you'll try this thing just a while longer you'll come to like it." - -"Like it! Yes--the way I'd like a hot stove if I was to set on it long -enough. No, Tom, I won't be rich, and I won't live in them cussed -smothery houses. I like the woods, and the river, and hogsheads, and -I'll stick to 'em, too. Blame it all! just as we'd got guns, and a -cave, and all just fixed to rob, here this dern foolishness has got to -come up and spile it all!" - -Tom saw his opportunity-- - -"Lookyhere, Huck, being rich ain't going to keep me back from turning -robber." - -"No! Oh, good-licks; are you in real dead-wood earnest, Tom?" - -"Just as dead earnest as I'm sitting here. But Huck, we can't let you -into the gang if you ain't respectable, you know." - -Huck's joy was quenched. - -"Can't let me in, Tom? Didn't you let me go for a pirate?" - -"Yes, but that's different. A robber is more high-toned than what a -pirate is--as a general thing. In most countries they're awful high up -in the nobility--dukes and such." - -"Now, Tom, hain't you always ben friendly to me? You wouldn't shet me -out, would you, Tom? You wouldn't do that, now, WOULD you, Tom?" - -"Huck, I wouldn't want to, and I DON'T want to--but what would people -say? Why, they'd say, 'Mph! Tom Sawyer's Gang! pretty low characters in -it!' They'd mean you, Huck. You wouldn't like that, and I wouldn't." - -Huck was silent for some time, engaged in a mental struggle. Finally -he said: - -"Well, I'll go back to the widder for a month and tackle it and see if -I can come to stand it, if you'll let me b'long to the gang, Tom." - -"All right, Huck, it's a whiz! Come along, old chap, and I'll ask the -widow to let up on you a little, Huck." - -"Will you, Tom--now will you? That's good. If she'll let up on some of -the roughest things, I'll smoke private and cuss private, and crowd -through or bust. When you going to start the gang and turn robbers?" - -"Oh, right off. We'll get the boys together and have the initiation -to-night, maybe." - -"Have the which?" - -"Have the initiation." - -"What's that?" - -"It's to swear to stand by one another, and never tell the gang's -secrets, even if you're chopped all to flinders, and kill anybody and -all his family that hurts one of the gang." - -"That's gay--that's mighty gay, Tom, I tell you." - -"Well, I bet it is. And all that swearing's got to be done at -midnight, in the lonesomest, awfulest place you can find--a ha'nted -house is the best, but they're all ripped up now." - -"Well, midnight's good, anyway, Tom." - -"Yes, so it is. And you've got to swear on a coffin, and sign it with -blood." - -"Now, that's something LIKE! Why, it's a million times bullier than -pirating. I'll stick to the widder till I rot, Tom; and if I git to be -a reg'lar ripper of a robber, and everybody talking 'bout it, I reckon -she'll be proud she snaked me in out of the wet." - - - -CONCLUSION - -SO endeth this chronicle. It being strictly a history of a BOY, it -must stop here; the story could not go much further without becoming -the history of a MAN. When one writes a novel about grown people, he -knows exactly where to stop--that is, with a marriage; but when he -writes of juveniles, he must stop where he best can. - -Most of the characters that perform in this book still live, and are -prosperous and happy. Some day it may seem worth while to take up the -story of the younger ones again and see what sort of men and women they -turned out to be; therefore it will be wisest not to reveal any of that -part of their lives at present. diff --git a/src/net/sendfile_test.go b/src/net/sendfile_test.go index 3b982774b02eb..f133744a66545 100644 --- a/src/net/sendfile_test.go +++ b/src/net/sendfile_test.go @@ -17,9 +17,9 @@ import ( ) const ( - twain = "testdata/Mark.Twain-Tom.Sawyer.txt" - twainLen = 387851 - twainSHA256 = "461eb7cb2d57d293fc680c836464c9125e4382be3596f7d415093ae9db8fcb0e" + newton = "../testdata/Isaac.Newton-Opticks.txt" + newtonLen = 567198 + newtonSHA256 = "d4a9ac22462b35e7821a4f2706c211093da678620a8f9997989ee7cf8d507bbd" ) func TestSendfile(t *testing.T) { @@ -43,7 +43,7 @@ func TestSendfile(t *testing.T) { defer close(errc) defer conn.Close() - f, err := os.Open(twain) + f, err := os.Open(newton) if err != nil { errc <- err return @@ -58,8 +58,8 @@ func TestSendfile(t *testing.T) { return } - if sbytes != twainLen { - errc <- fmt.Errorf("sent %d bytes; expected %d", sbytes, twainLen) + if sbytes != newtonLen { + errc <- fmt.Errorf("sent %d bytes; expected %d", sbytes, newtonLen) return } }() @@ -79,11 +79,11 @@ func TestSendfile(t *testing.T) { t.Error(err) } - if rbytes != twainLen { - t.Errorf("received %d bytes; expected %d", rbytes, twainLen) + if rbytes != newtonLen { + t.Errorf("received %d bytes; expected %d", rbytes, newtonLen) } - if res := hex.EncodeToString(h.Sum(nil)); res != twainSHA256 { + if res := hex.EncodeToString(h.Sum(nil)); res != newtonSHA256 { t.Error("retrieved data hash did not match") } @@ -113,7 +113,7 @@ func TestSendfileParts(t *testing.T) { defer close(errc) defer conn.Close() - f, err := os.Open(twain) + f, err := os.Open(newton) if err != nil { errc <- err return @@ -174,7 +174,7 @@ func TestSendfileSeeked(t *testing.T) { defer close(errc) defer conn.Close() - f, err := os.Open(twain) + f, err := os.Open(newton) if err != nil { errc <- err return diff --git a/src/net/testdata/Mark.Twain-Tom.Sawyer.txt b/src/net/testdata/Mark.Twain-Tom.Sawyer.txt deleted file mode 100644 index c9106fd522cec..0000000000000 --- a/src/net/testdata/Mark.Twain-Tom.Sawyer.txt +++ /dev/null @@ -1,8465 +0,0 @@ -Produced by David Widger. The previous edition was updated by Jose -Menendez. - - - - - - THE ADVENTURES OF TOM SAWYER - BY - MARK TWAIN - (Samuel Langhorne Clemens) - - - - - P R E F A C E - -MOST of the adventures recorded in this book really occurred; one or -two were experiences of my own, the rest those of boys who were -schoolmates of mine. Huck Finn is drawn from life; Tom Sawyer also, but -not from an individual--he is a combination of the characteristics of -three boys whom I knew, and therefore belongs to the composite order of -architecture. - -The odd superstitions touched upon were all prevalent among children -and slaves in the West at the period of this story--that is to say, -thirty or forty years ago. - -Although my book is intended mainly for the entertainment of boys and -girls, I hope it will not be shunned by men and women on that account, -for part of my plan has been to try to pleasantly remind adults of what -they once were themselves, and of how they felt and thought and talked, -and what queer enterprises they sometimes engaged in. - - THE AUTHOR. - -HARTFORD, 1876. - - - - T O M S A W Y E R - - - -CHAPTER I - -"TOM!" - -No answer. - -"TOM!" - -No answer. - -"What's gone with that boy, I wonder? You TOM!" - -No answer. - -The old lady pulled her spectacles down and looked over them about the -room; then she put them up and looked out under them. She seldom or -never looked THROUGH them for so small a thing as a boy; they were her -state pair, the pride of her heart, and were built for "style," not -service--she could have seen through a pair of stove-lids just as well. -She looked perplexed for a moment, and then said, not fiercely, but -still loud enough for the furniture to hear: - -"Well, I lay if I get hold of you I'll--" - -She did not finish, for by this time she was bending down and punching -under the bed with the broom, and so she needed breath to punctuate the -punches with. She resurrected nothing but the cat. - -"I never did see the beat of that boy!" - -She went to the open door and stood in it and looked out among the -tomato vines and "jimpson" weeds that constituted the garden. No Tom. -So she lifted up her voice at an angle calculated for distance and -shouted: - -"Y-o-u-u TOM!" - -There was a slight noise behind her and she turned just in time to -seize a small boy by the slack of his roundabout and arrest his flight. - -"There! I might 'a' thought of that closet. What you been doing in -there?" - -"Nothing." - -"Nothing! Look at your hands. And look at your mouth. What IS that -truck?" - -"I don't know, aunt." - -"Well, I know. It's jam--that's what it is. Forty times I've said if -you didn't let that jam alone I'd skin you. Hand me that switch." - -The switch hovered in the air--the peril was desperate-- - -"My! Look behind you, aunt!" - -The old lady whirled round, and snatched her skirts out of danger. The -lad fled on the instant, scrambled up the high board-fence, and -disappeared over it. - -His aunt Polly stood surprised a moment, and then broke into a gentle -laugh. - -"Hang the boy, can't I never learn anything? Ain't he played me tricks -enough like that for me to be looking out for him by this time? But old -fools is the biggest fools there is. Can't learn an old dog new tricks, -as the saying is. But my goodness, he never plays them alike, two days, -and how is a body to know what's coming? He 'pears to know just how -long he can torment me before I get my dander up, and he knows if he -can make out to put me off for a minute or make me laugh, it's all down -again and I can't hit him a lick. I ain't doing my duty by that boy, -and that's the Lord's truth, goodness knows. Spare the rod and spile -the child, as the Good Book says. I'm a laying up sin and suffering for -us both, I know. He's full of the Old Scratch, but laws-a-me! he's my -own dead sister's boy, poor thing, and I ain't got the heart to lash -him, somehow. Every time I let him off, my conscience does hurt me so, -and every time I hit him my old heart most breaks. Well-a-well, man -that is born of woman is of few days and full of trouble, as the -Scripture says, and I reckon it's so. He'll play hookey this evening, * -and [* Southwestern for "afternoon"] I'll just be obleeged to make him -work, to-morrow, to punish him. It's mighty hard to make him work -Saturdays, when all the boys is having holiday, but he hates work more -than he hates anything else, and I've GOT to do some of my duty by him, -or I'll be the ruination of the child." - -Tom did play hookey, and he had a very good time. He got back home -barely in season to help Jim, the small colored boy, saw next-day's -wood and split the kindlings before supper--at least he was there in -time to tell his adventures to Jim while Jim did three-fourths of the -work. Tom's younger brother (or rather half-brother) Sid was already -through with his part of the work (picking up chips), for he was a -quiet boy, and had no adventurous, troublesome ways. - -While Tom was eating his supper, and stealing sugar as opportunity -offered, Aunt Polly asked him questions that were full of guile, and -very deep--for she wanted to trap him into damaging revealments. Like -many other simple-hearted souls, it was her pet vanity to believe she -was endowed with a talent for dark and mysterious diplomacy, and she -loved to contemplate her most transparent devices as marvels of low -cunning. Said she: - -"Tom, it was middling warm in school, warn't it?" - -"Yes'm." - -"Powerful warm, warn't it?" - -"Yes'm." - -"Didn't you want to go in a-swimming, Tom?" - -A bit of a scare shot through Tom--a touch of uncomfortable suspicion. -He searched Aunt Polly's face, but it told him nothing. So he said: - -"No'm--well, not very much." - -The old lady reached out her hand and felt Tom's shirt, and said: - -"But you ain't too warm now, though." And it flattered her to reflect -that she had discovered that the shirt was dry without anybody knowing -that that was what she had in her mind. But in spite of her, Tom knew -where the wind lay, now. So he forestalled what might be the next move: - -"Some of us pumped on our heads--mine's damp yet. See?" - -Aunt Polly was vexed to think she had overlooked that bit of -circumstantial evidence, and missed a trick. Then she had a new -inspiration: - -"Tom, you didn't have to undo your shirt collar where I sewed it, to -pump on your head, did you? Unbutton your jacket!" - -The trouble vanished out of Tom's face. He opened his jacket. His -shirt collar was securely sewed. - -"Bother! Well, go 'long with you. I'd made sure you'd played hookey -and been a-swimming. But I forgive ye, Tom. I reckon you're a kind of a -singed cat, as the saying is--better'n you look. THIS time." - -She was half sorry her sagacity had miscarried, and half glad that Tom -had stumbled into obedient conduct for once. - -But Sidney said: - -"Well, now, if I didn't think you sewed his collar with white thread, -but it's black." - -"Why, I did sew it with white! Tom!" - -But Tom did not wait for the rest. As he went out at the door he said: - -"Siddy, I'll lick you for that." - -In a safe place Tom examined two large needles which were thrust into -the lapels of his jacket, and had thread bound about them--one needle -carried white thread and the other black. He said: - -"She'd never noticed if it hadn't been for Sid. Confound it! sometimes -she sews it with white, and sometimes she sews it with black. I wish to -geeminy she'd stick to one or t'other--I can't keep the run of 'em. But -I bet you I'll lam Sid for that. I'll learn him!" - -He was not the Model Boy of the village. He knew the model boy very -well though--and loathed him. - -Within two minutes, or even less, he had forgotten all his troubles. -Not because his troubles were one whit less heavy and bitter to him -than a man's are to a man, but because a new and powerful interest bore -them down and drove them out of his mind for the time--just as men's -misfortunes are forgotten in the excitement of new enterprises. This -new interest was a valued novelty in whistling, which he had just -acquired from a negro, and he was suffering to practise it undisturbed. -It consisted in a peculiar bird-like turn, a sort of liquid warble, -produced by touching the tongue to the roof of the mouth at short -intervals in the midst of the music--the reader probably remembers how -to do it, if he has ever been a boy. Diligence and attention soon gave -him the knack of it, and he strode down the street with his mouth full -of harmony and his soul full of gratitude. He felt much as an -astronomer feels who has discovered a new planet--no doubt, as far as -strong, deep, unalloyed pleasure is concerned, the advantage was with -the boy, not the astronomer. - -The summer evenings were long. It was not dark, yet. Presently Tom -checked his whistle. A stranger was before him--a boy a shade larger -than himself. A new-comer of any age or either sex was an impressive -curiosity in the poor little shabby village of St. Petersburg. This boy -was well dressed, too--well dressed on a week-day. This was simply -astounding. His cap was a dainty thing, his close-buttoned blue cloth -roundabout was new and natty, and so were his pantaloons. He had shoes -on--and it was only Friday. He even wore a necktie, a bright bit of -ribbon. He had a citified air about him that ate into Tom's vitals. The -more Tom stared at the splendid marvel, the higher he turned up his -nose at his finery and the shabbier and shabbier his own outfit seemed -to him to grow. Neither boy spoke. If one moved, the other moved--but -only sidewise, in a circle; they kept face to face and eye to eye all -the time. Finally Tom said: - -"I can lick you!" - -"I'd like to see you try it." - -"Well, I can do it." - -"No you can't, either." - -"Yes I can." - -"No you can't." - -"I can." - -"You can't." - -"Can!" - -"Can't!" - -An uncomfortable pause. Then Tom said: - -"What's your name?" - -"'Tisn't any of your business, maybe." - -"Well I 'low I'll MAKE it my business." - -"Well why don't you?" - -"If you say much, I will." - -"Much--much--MUCH. There now." - -"Oh, you think you're mighty smart, DON'T you? I could lick you with -one hand tied behind me, if I wanted to." - -"Well why don't you DO it? You SAY you can do it." - -"Well I WILL, if you fool with me." - -"Oh yes--I've seen whole families in the same fix." - -"Smarty! You think you're SOME, now, DON'T you? Oh, what a hat!" - -"You can lump that hat if you don't like it. I dare you to knock it -off--and anybody that'll take a dare will suck eggs." - -"You're a liar!" - -"You're another." - -"You're a fighting liar and dasn't take it up." - -"Aw--take a walk!" - -"Say--if you give me much more of your sass I'll take and bounce a -rock off'n your head." - -"Oh, of COURSE you will." - -"Well I WILL." - -"Well why don't you DO it then? What do you keep SAYING you will for? -Why don't you DO it? It's because you're afraid." - -"I AIN'T afraid." - -"You are." - -"I ain't." - -"You are." - -Another pause, and more eying and sidling around each other. Presently -they were shoulder to shoulder. Tom said: - -"Get away from here!" - -"Go away yourself!" - -"I won't." - -"I won't either." - -So they stood, each with a foot placed at an angle as a brace, and -both shoving with might and main, and glowering at each other with -hate. But neither could get an advantage. After struggling till both -were hot and flushed, each relaxed his strain with watchful caution, -and Tom said: - -"You're a coward and a pup. I'll tell my big brother on you, and he -can thrash you with his little finger, and I'll make him do it, too." - -"What do I care for your big brother? I've got a brother that's bigger -than he is--and what's more, he can throw him over that fence, too." -[Both brothers were imaginary.] - -"That's a lie." - -"YOUR saying so don't make it so." - -Tom drew a line in the dust with his big toe, and said: - -"I dare you to step over that, and I'll lick you till you can't stand -up. Anybody that'll take a dare will steal sheep." - -The new boy stepped over promptly, and said: - -"Now you said you'd do it, now let's see you do it." - -"Don't you crowd me now; you better look out." - -"Well, you SAID you'd do it--why don't you do it?" - -"By jingo! for two cents I WILL do it." - -The new boy took two broad coppers out of his pocket and held them out -with derision. Tom struck them to the ground. In an instant both boys -were rolling and tumbling in the dirt, gripped together like cats; and -for the space of a minute they tugged and tore at each other's hair and -clothes, punched and scratched each other's nose, and covered -themselves with dust and glory. Presently the confusion took form, and -through the fog of battle Tom appeared, seated astride the new boy, and -pounding him with his fists. "Holler 'nuff!" said he. - -The boy only struggled to free himself. He was crying--mainly from rage. - -"Holler 'nuff!"--and the pounding went on. - -At last the stranger got out a smothered "'Nuff!" and Tom let him up -and said: - -"Now that'll learn you. Better look out who you're fooling with next -time." - -The new boy went off brushing the dust from his clothes, sobbing, -snuffling, and occasionally looking back and shaking his head and -threatening what he would do to Tom the "next time he caught him out." -To which Tom responded with jeers, and started off in high feather, and -as soon as his back was turned the new boy snatched up a stone, threw -it and hit him between the shoulders and then turned tail and ran like -an antelope. Tom chased the traitor home, and thus found out where he -lived. He then held a position at the gate for some time, daring the -enemy to come outside, but the enemy only made faces at him through the -window and declined. At last the enemy's mother appeared, and called -Tom a bad, vicious, vulgar child, and ordered him away. So he went -away; but he said he "'lowed" to "lay" for that boy. - -He got home pretty late that night, and when he climbed cautiously in -at the window, he uncovered an ambuscade, in the person of his aunt; -and when she saw the state his clothes were in her resolution to turn -his Saturday holiday into captivity at hard labor became adamantine in -its firmness. - - - -CHAPTER II - -SATURDAY morning was come, and all the summer world was bright and -fresh, and brimming with life. There was a song in every heart; and if -the heart was young the music issued at the lips. There was cheer in -every face and a spring in every step. The locust-trees were in bloom -and the fragrance of the blossoms filled the air. Cardiff Hill, beyond -the village and above it, was green with vegetation and it lay just far -enough away to seem a Delectable Land, dreamy, reposeful, and inviting. - -Tom appeared on the sidewalk with a bucket of whitewash and a -long-handled brush. He surveyed the fence, and all gladness left him and -a deep melancholy settled down upon his spirit. Thirty yards of board -fence nine feet high. Life to him seemed hollow, and existence but a -burden. Sighing, he dipped his brush and passed it along the topmost -plank; repeated the operation; did it again; compared the insignificant -whitewashed streak with the far-reaching continent of unwhitewashed -fence, and sat down on a tree-box discouraged. Jim came skipping out at -the gate with a tin pail, and singing Buffalo Gals. Bringing water from -the town pump had always been hateful work in Tom's eyes, before, but -now it did not strike him so. He remembered that there was company at -the pump. White, mulatto, and negro boys and girls were always there -waiting their turns, resting, trading playthings, quarrelling, -fighting, skylarking. And he remembered that although the pump was only -a hundred and fifty yards off, Jim never got back with a bucket of -water under an hour--and even then somebody generally had to go after -him. Tom said: - -"Say, Jim, I'll fetch the water if you'll whitewash some." - -Jim shook his head and said: - -"Can't, Mars Tom. Ole missis, she tole me I got to go an' git dis -water an' not stop foolin' roun' wid anybody. She say she spec' Mars -Tom gwine to ax me to whitewash, an' so she tole me go 'long an' 'tend -to my own business--she 'lowed SHE'D 'tend to de whitewashin'." - -"Oh, never you mind what she said, Jim. That's the way she always -talks. Gimme the bucket--I won't be gone only a a minute. SHE won't -ever know." - -"Oh, I dasn't, Mars Tom. Ole missis she'd take an' tar de head off'n -me. 'Deed she would." - -"SHE! She never licks anybody--whacks 'em over the head with her -thimble--and who cares for that, I'd like to know. She talks awful, but -talk don't hurt--anyways it don't if she don't cry. Jim, I'll give you -a marvel. I'll give you a white alley!" - -Jim began to waver. - -"White alley, Jim! And it's a bully taw." - -"My! Dat's a mighty gay marvel, I tell you! But Mars Tom I's powerful -'fraid ole missis--" - -"And besides, if you will I'll show you my sore toe." - -Jim was only human--this attraction was too much for him. He put down -his pail, took the white alley, and bent over the toe with absorbing -interest while the bandage was being unwound. In another moment he was -flying down the street with his pail and a tingling rear, Tom was -whitewashing with vigor, and Aunt Polly was retiring from the field -with a slipper in her hand and triumph in her eye. - -But Tom's energy did not last. He began to think of the fun he had -planned for this day, and his sorrows multiplied. Soon the free boys -would come tripping along on all sorts of delicious expeditions, and -they would make a world of fun of him for having to work--the very -thought of it burnt him like fire. He got out his worldly wealth and -examined it--bits of toys, marbles, and trash; enough to buy an -exchange of WORK, maybe, but not half enough to buy so much as half an -hour of pure freedom. So he returned his straitened means to his -pocket, and gave up the idea of trying to buy the boys. At this dark -and hopeless moment an inspiration burst upon him! Nothing less than a -great, magnificent inspiration. - -He took up his brush and went tranquilly to work. Ben Rogers hove in -sight presently--the very boy, of all boys, whose ridicule he had been -dreading. Ben's gait was the hop-skip-and-jump--proof enough that his -heart was light and his anticipations high. He was eating an apple, and -giving a long, melodious whoop, at intervals, followed by a deep-toned -ding-dong-dong, ding-dong-dong, for he was personating a steamboat. As -he drew near, he slackened speed, took the middle of the street, leaned -far over to starboard and rounded to ponderously and with laborious -pomp and circumstance--for he was personating the Big Missouri, and -considered himself to be drawing nine feet of water. He was boat and -captain and engine-bells combined, so he had to imagine himself -standing on his own hurricane-deck giving the orders and executing them: - -"Stop her, sir! Ting-a-ling-ling!" The headway ran almost out, and he -drew up slowly toward the sidewalk. - -"Ship up to back! Ting-a-ling-ling!" His arms straightened and -stiffened down his sides. - -"Set her back on the stabboard! Ting-a-ling-ling! Chow! ch-chow-wow! -Chow!" His right hand, meantime, describing stately circles--for it was -representing a forty-foot wheel. - -"Let her go back on the labboard! Ting-a-lingling! Chow-ch-chow-chow!" -The left hand began to describe circles. - -"Stop the stabboard! Ting-a-ling-ling! Stop the labboard! Come ahead -on the stabboard! Stop her! Let your outside turn over slow! -Ting-a-ling-ling! Chow-ow-ow! Get out that head-line! LIVELY now! -Come--out with your spring-line--what're you about there! Take a turn -round that stump with the bight of it! Stand by that stage, now--let her -go! Done with the engines, sir! Ting-a-ling-ling! SH'T! S'H'T! SH'T!" -(trying the gauge-cocks). - -Tom went on whitewashing--paid no attention to the steamboat. Ben -stared a moment and then said: "Hi-YI! YOU'RE up a stump, ain't you!" - -No answer. Tom surveyed his last touch with the eye of an artist, then -he gave his brush another gentle sweep and surveyed the result, as -before. Ben ranged up alongside of him. Tom's mouth watered for the -apple, but he stuck to his work. Ben said: - -"Hello, old chap, you got to work, hey?" - -Tom wheeled suddenly and said: - -"Why, it's you, Ben! I warn't noticing." - -"Say--I'm going in a-swimming, I am. Don't you wish you could? But of -course you'd druther WORK--wouldn't you? Course you would!" - -Tom contemplated the boy a bit, and said: - -"What do you call work?" - -"Why, ain't THAT work?" - -Tom resumed his whitewashing, and answered carelessly: - -"Well, maybe it is, and maybe it ain't. All I know, is, it suits Tom -Sawyer." - -"Oh come, now, you don't mean to let on that you LIKE it?" - -The brush continued to move. - -"Like it? Well, I don't see why I oughtn't to like it. Does a boy get -a chance to whitewash a fence every day?" - -That put the thing in a new light. Ben stopped nibbling his apple. Tom -swept his brush daintily back and forth--stepped back to note the -effect--added a touch here and there--criticised the effect again--Ben -watching every move and getting more and more interested, more and more -absorbed. Presently he said: - -"Say, Tom, let ME whitewash a little." - -Tom considered, was about to consent; but he altered his mind: - -"No--no--I reckon it wouldn't hardly do, Ben. You see, Aunt Polly's -awful particular about this fence--right here on the street, you know ---but if it was the back fence I wouldn't mind and SHE wouldn't. Yes, -she's awful particular about this fence; it's got to be done very -careful; I reckon there ain't one boy in a thousand, maybe two -thousand, that can do it the way it's got to be done." - -"No--is that so? Oh come, now--lemme just try. Only just a little--I'd -let YOU, if you was me, Tom." - -"Ben, I'd like to, honest injun; but Aunt Polly--well, Jim wanted to -do it, but she wouldn't let him; Sid wanted to do it, and she wouldn't -let Sid. Now don't you see how I'm fixed? If you was to tackle this -fence and anything was to happen to it--" - -"Oh, shucks, I'll be just as careful. Now lemme try. Say--I'll give -you the core of my apple." - -"Well, here--No, Ben, now don't. I'm afeard--" - -"I'll give you ALL of it!" - -Tom gave up the brush with reluctance in his face, but alacrity in his -heart. And while the late steamer Big Missouri worked and sweated in -the sun, the retired artist sat on a barrel in the shade close by, -dangled his legs, munched his apple, and planned the slaughter of more -innocents. There was no lack of material; boys happened along every -little while; they came to jeer, but remained to whitewash. By the time -Ben was fagged out, Tom had traded the next chance to Billy Fisher for -a kite, in good repair; and when he played out, Johnny Miller bought in -for a dead rat and a string to swing it with--and so on, and so on, -hour after hour. And when the middle of the afternoon came, from being -a poor poverty-stricken boy in the morning, Tom was literally rolling -in wealth. He had besides the things before mentioned, twelve marbles, -part of a jews-harp, a piece of blue bottle-glass to look through, a -spool cannon, a key that wouldn't unlock anything, a fragment of chalk, -a glass stopper of a decanter, a tin soldier, a couple of tadpoles, six -fire-crackers, a kitten with only one eye, a brass doorknob, a -dog-collar--but no dog--the handle of a knife, four pieces of -orange-peel, and a dilapidated old window sash. - -He had had a nice, good, idle time all the while--plenty of company ---and the fence had three coats of whitewash on it! If he hadn't run out -of whitewash he would have bankrupted every boy in the village. - -Tom said to himself that it was not such a hollow world, after all. He -had discovered a great law of human action, without knowing it--namely, -that in order to make a man or a boy covet a thing, it is only -necessary to make the thing difficult to attain. If he had been a great -and wise philosopher, like the writer of this book, he would now have -comprehended that Work consists of whatever a body is OBLIGED to do, -and that Play consists of whatever a body is not obliged to do. And -this would help him to understand why constructing artificial flowers -or performing on a tread-mill is work, while rolling ten-pins or -climbing Mont Blanc is only amusement. There are wealthy gentlemen in -England who drive four-horse passenger-coaches twenty or thirty miles -on a daily line, in the summer, because the privilege costs them -considerable money; but if they were offered wages for the service, -that would turn it into work and then they would resign. - -The boy mused awhile over the substantial change which had taken place -in his worldly circumstances, and then wended toward headquarters to -report. - - - -CHAPTER III - -TOM presented himself before Aunt Polly, who was sitting by an open -window in a pleasant rearward apartment, which was bedroom, -breakfast-room, dining-room, and library, combined. The balmy summer -air, the restful quiet, the odor of the flowers, and the drowsing murmur -of the bees had had their effect, and she was nodding over her knitting ---for she had no company but the cat, and it was asleep in her lap. Her -spectacles were propped up on her gray head for safety. She had thought -that of course Tom had deserted long ago, and she wondered at seeing him -place himself in her power again in this intrepid way. He said: "Mayn't -I go and play now, aunt?" - -"What, a'ready? How much have you done?" - -"It's all done, aunt." - -"Tom, don't lie to me--I can't bear it." - -"I ain't, aunt; it IS all done." - -Aunt Polly placed small trust in such evidence. She went out to see -for herself; and she would have been content to find twenty per cent. -of Tom's statement true. When she found the entire fence whitewashed, -and not only whitewashed but elaborately coated and recoated, and even -a streak added to the ground, her astonishment was almost unspeakable. -She said: - -"Well, I never! There's no getting round it, you can work when you're -a mind to, Tom." And then she diluted the compliment by adding, "But -it's powerful seldom you're a mind to, I'm bound to say. Well, go 'long -and play; but mind you get back some time in a week, or I'll tan you." - -She was so overcome by the splendor of his achievement that she took -him into the closet and selected a choice apple and delivered it to -him, along with an improving lecture upon the added value and flavor a -treat took to itself when it came without sin through virtuous effort. -And while she closed with a happy Scriptural flourish, he "hooked" a -doughnut. - -Then he skipped out, and saw Sid just starting up the outside stairway -that led to the back rooms on the second floor. Clods were handy and -the air was full of them in a twinkling. They raged around Sid like a -hail-storm; and before Aunt Polly could collect her surprised faculties -and sally to the rescue, six or seven clods had taken personal effect, -and Tom was over the fence and gone. There was a gate, but as a general -thing he was too crowded for time to make use of it. His soul was at -peace, now that he had settled with Sid for calling attention to his -black thread and getting him into trouble. - -Tom skirted the block, and came round into a muddy alley that led by -the back of his aunt's cow-stable. He presently got safely beyond the -reach of capture and punishment, and hastened toward the public square -of the village, where two "military" companies of boys had met for -conflict, according to previous appointment. Tom was General of one of -these armies, Joe Harper (a bosom friend) General of the other. These -two great commanders did not condescend to fight in person--that being -better suited to the still smaller fry--but sat together on an eminence -and conducted the field operations by orders delivered through -aides-de-camp. Tom's army won a great victory, after a long and -hard-fought battle. Then the dead were counted, prisoners exchanged, -the terms of the next disagreement agreed upon, and the day for the -necessary battle appointed; after which the armies fell into line and -marched away, and Tom turned homeward alone. - -As he was passing by the house where Jeff Thatcher lived, he saw a new -girl in the garden--a lovely little blue-eyed creature with yellow hair -plaited into two long-tails, white summer frock and embroidered -pantalettes. The fresh-crowned hero fell without firing a shot. A -certain Amy Lawrence vanished out of his heart and left not even a -memory of herself behind. He had thought he loved her to distraction; -he had regarded his passion as adoration; and behold it was only a poor -little evanescent partiality. He had been months winning her; she had -confessed hardly a week ago; he had been the happiest and the proudest -boy in the world only seven short days, and here in one instant of time -she had gone out of his heart like a casual stranger whose visit is -done. - -He worshipped this new angel with furtive eye, till he saw that she -had discovered him; then he pretended he did not know she was present, -and began to "show off" in all sorts of absurd boyish ways, in order to -win her admiration. He kept up this grotesque foolishness for some -time; but by-and-by, while he was in the midst of some dangerous -gymnastic performances, he glanced aside and saw that the little girl -was wending her way toward the house. Tom came up to the fence and -leaned on it, grieving, and hoping she would tarry yet awhile longer. -She halted a moment on the steps and then moved toward the door. Tom -heaved a great sigh as she put her foot on the threshold. But his face -lit up, right away, for she tossed a pansy over the fence a moment -before she disappeared. - -The boy ran around and stopped within a foot or two of the flower, and -then shaded his eyes with his hand and began to look down street as if -he had discovered something of interest going on in that direction. -Presently he picked up a straw and began trying to balance it on his -nose, with his head tilted far back; and as he moved from side to side, -in his efforts, he edged nearer and nearer toward the pansy; finally -his bare foot rested upon it, his pliant toes closed upon it, and he -hopped away with the treasure and disappeared round the corner. But -only for a minute--only while he could button the flower inside his -jacket, next his heart--or next his stomach, possibly, for he was not -much posted in anatomy, and not hypercritical, anyway. - -He returned, now, and hung about the fence till nightfall, "showing -off," as before; but the girl never exhibited herself again, though Tom -comforted himself a little with the hope that she had been near some -window, meantime, and been aware of his attentions. Finally he strode -home reluctantly, with his poor head full of visions. - -All through supper his spirits were so high that his aunt wondered -"what had got into the child." He took a good scolding about clodding -Sid, and did not seem to mind it in the least. He tried to steal sugar -under his aunt's very nose, and got his knuckles rapped for it. He said: - -"Aunt, you don't whack Sid when he takes it." - -"Well, Sid don't torment a body the way you do. You'd be always into -that sugar if I warn't watching you." - -Presently she stepped into the kitchen, and Sid, happy in his -immunity, reached for the sugar-bowl--a sort of glorying over Tom which -was wellnigh unbearable. But Sid's fingers slipped and the bowl dropped -and broke. Tom was in ecstasies. In such ecstasies that he even -controlled his tongue and was silent. He said to himself that he would -not speak a word, even when his aunt came in, but would sit perfectly -still till she asked who did the mischief; and then he would tell, and -there would be nothing so good in the world as to see that pet model -"catch it." He was so brimful of exultation that he could hardly hold -himself when the old lady came back and stood above the wreck -discharging lightnings of wrath from over her spectacles. He said to -himself, "Now it's coming!" And the next instant he was sprawling on -the floor! The potent palm was uplifted to strike again when Tom cried -out: - -"Hold on, now, what 'er you belting ME for?--Sid broke it!" - -Aunt Polly paused, perplexed, and Tom looked for healing pity. But -when she got her tongue again, she only said: - -"Umf! Well, you didn't get a lick amiss, I reckon. You been into some -other audacious mischief when I wasn't around, like enough." - -Then her conscience reproached her, and she yearned to say something -kind and loving; but she judged that this would be construed into a -confession that she had been in the wrong, and discipline forbade that. -So she kept silence, and went about her affairs with a troubled heart. -Tom sulked in a corner and exalted his woes. He knew that in her heart -his aunt was on her knees to him, and he was morosely gratified by the -consciousness of it. He would hang out no signals, he would take notice -of none. He knew that a yearning glance fell upon him, now and then, -through a film of tears, but he refused recognition of it. He pictured -himself lying sick unto death and his aunt bending over him beseeching -one little forgiving word, but he would turn his face to the wall, and -die with that word unsaid. Ah, how would she feel then? And he pictured -himself brought home from the river, dead, with his curls all wet, and -his sore heart at rest. How she would throw herself upon him, and how -her tears would fall like rain, and her lips pray God to give her back -her boy and she would never, never abuse him any more! But he would lie -there cold and white and make no sign--a poor little sufferer, whose -griefs were at an end. He so worked upon his feelings with the pathos -of these dreams, that he had to keep swallowing, he was so like to -choke; and his eyes swam in a blur of water, which overflowed when he -winked, and ran down and trickled from the end of his nose. And such a -luxury to him was this petting of his sorrows, that he could not bear -to have any worldly cheeriness or any grating delight intrude upon it; -it was too sacred for such contact; and so, presently, when his cousin -Mary danced in, all alive with the joy of seeing home again after an -age-long visit of one week to the country, he got up and moved in -clouds and darkness out at one door as she brought song and sunshine in -at the other. - -He wandered far from the accustomed haunts of boys, and sought -desolate places that were in harmony with his spirit. A log raft in the -river invited him, and he seated himself on its outer edge and -contemplated the dreary vastness of the stream, wishing, the while, -that he could only be drowned, all at once and unconsciously, without -undergoing the uncomfortable routine devised by nature. Then he thought -of his flower. He got it out, rumpled and wilted, and it mightily -increased his dismal felicity. He wondered if she would pity him if she -knew? Would she cry, and wish that she had a right to put her arms -around his neck and comfort him? Or would she turn coldly away like all -the hollow world? This picture brought such an agony of pleasurable -suffering that he worked it over and over again in his mind and set it -up in new and varied lights, till he wore it threadbare. At last he -rose up sighing and departed in the darkness. - -About half-past nine or ten o'clock he came along the deserted street -to where the Adored Unknown lived; he paused a moment; no sound fell -upon his listening ear; a candle was casting a dull glow upon the -curtain of a second-story window. Was the sacred presence there? He -climbed the fence, threaded his stealthy way through the plants, till -he stood under that window; he looked up at it long, and with emotion; -then he laid him down on the ground under it, disposing himself upon -his back, with his hands clasped upon his breast and holding his poor -wilted flower. And thus he would die--out in the cold world, with no -shelter over his homeless head, no friendly hand to wipe the -death-damps from his brow, no loving face to bend pityingly over him -when the great agony came. And thus SHE would see him when she looked -out upon the glad morning, and oh! would she drop one little tear upon -his poor, lifeless form, would she heave one little sigh to see a bright -young life so rudely blighted, so untimely cut down? - -The window went up, a maid-servant's discordant voice profaned the -holy calm, and a deluge of water drenched the prone martyr's remains! - -The strangling hero sprang up with a relieving snort. There was a whiz -as of a missile in the air, mingled with the murmur of a curse, a sound -as of shivering glass followed, and a small, vague form went over the -fence and shot away in the gloom. - -Not long after, as Tom, all undressed for bed, was surveying his -drenched garments by the light of a tallow dip, Sid woke up; but if he -had any dim idea of making any "references to allusions," he thought -better of it and held his peace, for there was danger in Tom's eye. - -Tom turned in without the added vexation of prayers, and Sid made -mental note of the omission. - - - -CHAPTER IV - -THE sun rose upon a tranquil world, and beamed down upon the peaceful -village like a benediction. Breakfast over, Aunt Polly had family -worship: it began with a prayer built from the ground up of solid -courses of Scriptural quotations, welded together with a thin mortar of -originality; and from the summit of this she delivered a grim chapter -of the Mosaic Law, as from Sinai. - -Then Tom girded up his loins, so to speak, and went to work to "get -his verses." Sid had learned his lesson days before. Tom bent all his -energies to the memorizing of five verses, and he chose part of the -Sermon on the Mount, because he could find no verses that were shorter. -At the end of half an hour Tom had a vague general idea of his lesson, -but no more, for his mind was traversing the whole field of human -thought, and his hands were busy with distracting recreations. Mary -took his book to hear him recite, and he tried to find his way through -the fog: - -"Blessed are the--a--a--" - -"Poor"-- - -"Yes--poor; blessed are the poor--a--a--" - -"In spirit--" - -"In spirit; blessed are the poor in spirit, for they--they--" - -"THEIRS--" - -"For THEIRS. Blessed are the poor in spirit, for theirs is the kingdom -of heaven. Blessed are they that mourn, for they--they--" - -"Sh--" - -"For they--a--" - -"S, H, A--" - -"For they S, H--Oh, I don't know what it is!" - -"SHALL!" - -"Oh, SHALL! for they shall--for they shall--a--a--shall mourn--a--a-- -blessed are they that shall--they that--a--they that shall mourn, for -they shall--a--shall WHAT? Why don't you tell me, Mary?--what do you -want to be so mean for?" - -"Oh, Tom, you poor thick-headed thing, I'm not teasing you. I wouldn't -do that. You must go and learn it again. Don't you be discouraged, Tom, -you'll manage it--and if you do, I'll give you something ever so nice. -There, now, that's a good boy." - -"All right! What is it, Mary, tell me what it is." - -"Never you mind, Tom. You know if I say it's nice, it is nice." - -"You bet you that's so, Mary. All right, I'll tackle it again." - -And he did "tackle it again"--and under the double pressure of -curiosity and prospective gain he did it with such spirit that he -accomplished a shining success. Mary gave him a brand-new "Barlow" -knife worth twelve and a half cents; and the convulsion of delight that -swept his system shook him to his foundations. True, the knife would -not cut anything, but it was a "sure-enough" Barlow, and there was -inconceivable grandeur in that--though where the Western boys ever got -the idea that such a weapon could possibly be counterfeited to its -injury is an imposing mystery and will always remain so, perhaps. Tom -contrived to scarify the cupboard with it, and was arranging to begin -on the bureau, when he was called off to dress for Sunday-school. - -Mary gave him a tin basin of water and a piece of soap, and he went -outside the door and set the basin on a little bench there; then he -dipped the soap in the water and laid it down; turned up his sleeves; -poured out the water on the ground, gently, and then entered the -kitchen and began to wipe his face diligently on the towel behind the -door. But Mary removed the towel and said: - -"Now ain't you ashamed, Tom. You mustn't be so bad. Water won't hurt -you." - -Tom was a trifle disconcerted. The basin was refilled, and this time -he stood over it a little while, gathering resolution; took in a big -breath and began. When he entered the kitchen presently, with both eyes -shut and groping for the towel with his hands, an honorable testimony -of suds and water was dripping from his face. But when he emerged from -the towel, he was not yet satisfactory, for the clean territory stopped -short at his chin and his jaws, like a mask; below and beyond this line -there was a dark expanse of unirrigated soil that spread downward in -front and backward around his neck. Mary took him in hand, and when she -was done with him he was a man and a brother, without distinction of -color, and his saturated hair was neatly brushed, and its short curls -wrought into a dainty and symmetrical general effect. [He privately -smoothed out the curls, with labor and difficulty, and plastered his -hair close down to his head; for he held curls to be effeminate, and -his own filled his life with bitterness.] Then Mary got out a suit of -his clothing that had been used only on Sundays during two years--they -were simply called his "other clothes"--and so by that we know the -size of his wardrobe. The girl "put him to rights" after he had dressed -himself; she buttoned his neat roundabout up to his chin, turned his -vast shirt collar down over his shoulders, brushed him off and crowned -him with his speckled straw hat. He now looked exceedingly improved and -uncomfortable. He was fully as uncomfortable as he looked; for there -was a restraint about whole clothes and cleanliness that galled him. He -hoped that Mary would forget his shoes, but the hope was blighted; she -coated them thoroughly with tallow, as was the custom, and brought them -out. He lost his temper and said he was always being made to do -everything he didn't want to do. But Mary said, persuasively: - -"Please, Tom--that's a good boy." - -So he got into the shoes snarling. Mary was soon ready, and the three -children set out for Sunday-school--a place that Tom hated with his -whole heart; but Sid and Mary were fond of it. - -Sabbath-school hours were from nine to half-past ten; and then church -service. Two of the children always remained for the sermon -voluntarily, and the other always remained too--for stronger reasons. -The church's high-backed, uncushioned pews would seat about three -hundred persons; the edifice was but a small, plain affair, with a sort -of pine board tree-box on top of it for a steeple. At the door Tom -dropped back a step and accosted a Sunday-dressed comrade: - -"Say, Billy, got a yaller ticket?" - -"Yes." - -"What'll you take for her?" - -"What'll you give?" - -"Piece of lickrish and a fish-hook." - -"Less see 'em." - -Tom exhibited. They were satisfactory, and the property changed hands. -Then Tom traded a couple of white alleys for three red tickets, and -some small trifle or other for a couple of blue ones. He waylaid other -boys as they came, and went on buying tickets of various colors ten or -fifteen minutes longer. He entered the church, now, with a swarm of -clean and noisy boys and girls, proceeded to his seat and started a -quarrel with the first boy that came handy. The teacher, a grave, -elderly man, interfered; then turned his back a moment and Tom pulled a -boy's hair in the next bench, and was absorbed in his book when the boy -turned around; stuck a pin in another boy, presently, in order to hear -him say "Ouch!" and got a new reprimand from his teacher. Tom's whole -class were of a pattern--restless, noisy, and troublesome. When they -came to recite their lessons, not one of them knew his verses -perfectly, but had to be prompted all along. However, they worried -through, and each got his reward--in small blue tickets, each with a -passage of Scripture on it; each blue ticket was pay for two verses of -the recitation. Ten blue tickets equalled a red one, and could be -exchanged for it; ten red tickets equalled a yellow one; for ten yellow -tickets the superintendent gave a very plainly bound Bible (worth forty -cents in those easy times) to the pupil. How many of my readers would -have the industry and application to memorize two thousand verses, even -for a Dore Bible? And yet Mary had acquired two Bibles in this way--it -was the patient work of two years--and a boy of German parentage had -won four or five. He once recited three thousand verses without -stopping; but the strain upon his mental faculties was too great, and -he was little better than an idiot from that day forth--a grievous -misfortune for the school, for on great occasions, before company, the -superintendent (as Tom expressed it) had always made this boy come out -and "spread himself." Only the older pupils managed to keep their -tickets and stick to their tedious work long enough to get a Bible, and -so the delivery of one of these prizes was a rare and noteworthy -circumstance; the successful pupil was so great and conspicuous for -that day that on the spot every scholar's heart was fired with a fresh -ambition that often lasted a couple of weeks. It is possible that Tom's -mental stomach had never really hungered for one of those prizes, but -unquestionably his entire being had for many a day longed for the glory -and the eclat that came with it. - -In due course the superintendent stood up in front of the pulpit, with -a closed hymn-book in his hand and his forefinger inserted between its -leaves, and commanded attention. When a Sunday-school superintendent -makes his customary little speech, a hymn-book in the hand is as -necessary as is the inevitable sheet of music in the hand of a singer -who stands forward on the platform and sings a solo at a concert ---though why, is a mystery: for neither the hymn-book nor the sheet of -music is ever referred to by the sufferer. This superintendent was a -slim creature of thirty-five, with a sandy goatee and short sandy hair; -he wore a stiff standing-collar whose upper edge almost reached his -ears and whose sharp points curved forward abreast the corners of his -mouth--a fence that compelled a straight lookout ahead, and a turning -of the whole body when a side view was required; his chin was propped -on a spreading cravat which was as broad and as long as a bank-note, -and had fringed ends; his boot toes were turned sharply up, in the -fashion of the day, like sleigh-runners--an effect patiently and -laboriously produced by the young men by sitting with their toes -pressed against a wall for hours together. Mr. Walters was very earnest -of mien, and very sincere and honest at heart; and he held sacred -things and places in such reverence, and so separated them from worldly -matters, that unconsciously to himself his Sunday-school voice had -acquired a peculiar intonation which was wholly absent on week-days. He -began after this fashion: - -"Now, children, I want you all to sit up just as straight and pretty -as you can and give me all your attention for a minute or two. There ---that is it. That is the way good little boys and girls should do. I see -one little girl who is looking out of the window--I am afraid she -thinks I am out there somewhere--perhaps up in one of the trees making -a speech to the little birds. [Applausive titter.] I want to tell you -how good it makes me feel to see so many bright, clean little faces -assembled in a place like this, learning to do right and be good." And -so forth and so on. It is not necessary to set down the rest of the -oration. It was of a pattern which does not vary, and so it is familiar -to us all. - -The latter third of the speech was marred by the resumption of fights -and other recreations among certain of the bad boys, and by fidgetings -and whisperings that extended far and wide, washing even to the bases -of isolated and incorruptible rocks like Sid and Mary. But now every -sound ceased suddenly, with the subsidence of Mr. Walters' voice, and -the conclusion of the speech was received with a burst of silent -gratitude. - -A good part of the whispering had been occasioned by an event which -was more or less rare--the entrance of visitors: lawyer Thatcher, -accompanied by a very feeble and aged man; a fine, portly, middle-aged -gentleman with iron-gray hair; and a dignified lady who was doubtless -the latter's wife. The lady was leading a child. Tom had been restless -and full of chafings and repinings; conscience-smitten, too--he could -not meet Amy Lawrence's eye, he could not brook her loving gaze. But -when he saw this small new-comer his soul was all ablaze with bliss in -a moment. The next moment he was "showing off" with all his might ---cuffing boys, pulling hair, making faces--in a word, using every art -that seemed likely to fascinate a girl and win her applause. His -exaltation had but one alloy--the memory of his humiliation in this -angel's garden--and that record in sand was fast washing out, under -the waves of happiness that were sweeping over it now. - -The visitors were given the highest seat of honor, and as soon as Mr. -Walters' speech was finished, he introduced them to the school. The -middle-aged man turned out to be a prodigious personage--no less a one -than the county judge--altogether the most august creation these -children had ever looked upon--and they wondered what kind of material -he was made of--and they half wanted to hear him roar, and were half -afraid he might, too. He was from Constantinople, twelve miles away--so -he had travelled, and seen the world--these very eyes had looked upon -the county court-house--which was said to have a tin roof. The awe -which these reflections inspired was attested by the impressive silence -and the ranks of staring eyes. This was the great Judge Thatcher, -brother of their own lawyer. Jeff Thatcher immediately went forward, to -be familiar with the great man and be envied by the school. It would -have been music to his soul to hear the whisperings: - -"Look at him, Jim! He's a going up there. Say--look! he's a going to -shake hands with him--he IS shaking hands with him! By jings, don't you -wish you was Jeff?" - -Mr. Walters fell to "showing off," with all sorts of official -bustlings and activities, giving orders, delivering judgments, -discharging directions here, there, everywhere that he could find a -target. The librarian "showed off"--running hither and thither with his -arms full of books and making a deal of the splutter and fuss that -insect authority delights in. The young lady teachers "showed off" ---bending sweetly over pupils that were lately being boxed, lifting -pretty warning fingers at bad little boys and patting good ones -lovingly. The young gentlemen teachers "showed off" with small -scoldings and other little displays of authority and fine attention to -discipline--and most of the teachers, of both sexes, found business up -at the library, by the pulpit; and it was business that frequently had -to be done over again two or three times (with much seeming vexation). -The little girls "showed off" in various ways, and the little boys -"showed off" with such diligence that the air was thick with paper wads -and the murmur of scufflings. And above it all the great man sat and -beamed a majestic judicial smile upon all the house, and warmed himself -in the sun of his own grandeur--for he was "showing off," too. - -There was only one thing wanting to make Mr. Walters' ecstasy -complete, and that was a chance to deliver a Bible-prize and exhibit a -prodigy. Several pupils had a few yellow tickets, but none had enough ---he had been around among the star pupils inquiring. He would have given -worlds, now, to have that German lad back again with a sound mind. - -And now at this moment, when hope was dead, Tom Sawyer came forward -with nine yellow tickets, nine red tickets, and ten blue ones, and -demanded a Bible. This was a thunderbolt out of a clear sky. Walters -was not expecting an application from this source for the next ten -years. But there was no getting around it--here were the certified -checks, and they were good for their face. Tom was therefore elevated -to a place with the Judge and the other elect, and the great news was -announced from headquarters. It was the most stunning surprise of the -decade, and so profound was the sensation that it lifted the new hero -up to the judicial one's altitude, and the school had two marvels to -gaze upon in place of one. The boys were all eaten up with envy--but -those that suffered the bitterest pangs were those who perceived too -late that they themselves had contributed to this hated splendor by -trading tickets to Tom for the wealth he had amassed in selling -whitewashing privileges. These despised themselves, as being the dupes -of a wily fraud, a guileful snake in the grass. - -The prize was delivered to Tom with as much effusion as the -superintendent could pump up under the circumstances; but it lacked -somewhat of the true gush, for the poor fellow's instinct taught him -that there was a mystery here that could not well bear the light, -perhaps; it was simply preposterous that this boy had warehoused two -thousand sheaves of Scriptural wisdom on his premises--a dozen would -strain his capacity, without a doubt. - -Amy Lawrence was proud and glad, and she tried to make Tom see it in -her face--but he wouldn't look. She wondered; then she was just a grain -troubled; next a dim suspicion came and went--came again; she watched; -a furtive glance told her worlds--and then her heart broke, and she was -jealous, and angry, and the tears came and she hated everybody. Tom -most of all (she thought). - -Tom was introduced to the Judge; but his tongue was tied, his breath -would hardly come, his heart quaked--partly because of the awful -greatness of the man, but mainly because he was her parent. He would -have liked to fall down and worship him, if it were in the dark. The -Judge put his hand on Tom's head and called him a fine little man, and -asked him what his name was. The boy stammered, gasped, and got it out: - -"Tom." - -"Oh, no, not Tom--it is--" - -"Thomas." - -"Ah, that's it. I thought there was more to it, maybe. That's very -well. But you've another one I daresay, and you'll tell it to me, won't -you?" - -"Tell the gentleman your other name, Thomas," said Walters, "and say -sir. You mustn't forget your manners." - -"Thomas Sawyer--sir." - -"That's it! That's a good boy. Fine boy. Fine, manly little fellow. -Two thousand verses is a great many--very, very great many. And you -never can be sorry for the trouble you took to learn them; for -knowledge is worth more than anything there is in the world; it's what -makes great men and good men; you'll be a great man and a good man -yourself, some day, Thomas, and then you'll look back and say, It's all -owing to the precious Sunday-school privileges of my boyhood--it's all -owing to my dear teachers that taught me to learn--it's all owing to -the good superintendent, who encouraged me, and watched over me, and -gave me a beautiful Bible--a splendid elegant Bible--to keep and have -it all for my own, always--it's all owing to right bringing up! That is -what you will say, Thomas--and you wouldn't take any money for those -two thousand verses--no indeed you wouldn't. And now you wouldn't mind -telling me and this lady some of the things you've learned--no, I know -you wouldn't--for we are proud of little boys that learn. Now, no -doubt you know the names of all the twelve disciples. Won't you tell us -the names of the first two that were appointed?" - -Tom was tugging at a button-hole and looking sheepish. He blushed, -now, and his eyes fell. Mr. Walters' heart sank within him. He said to -himself, it is not possible that the boy can answer the simplest -question--why DID the Judge ask him? Yet he felt obliged to speak up -and say: - -"Answer the gentleman, Thomas--don't be afraid." - -Tom still hung fire. - -"Now I know you'll tell me," said the lady. "The names of the first -two disciples were--" - -"DAVID AND GOLIAH!" - -Let us draw the curtain of charity over the rest of the scene. - - - -CHAPTER V - -ABOUT half-past ten the cracked bell of the small church began to -ring, and presently the people began to gather for the morning sermon. -The Sunday-school children distributed themselves about the house and -occupied pews with their parents, so as to be under supervision. Aunt -Polly came, and Tom and Sid and Mary sat with her--Tom being placed -next the aisle, in order that he might be as far away from the open -window and the seductive outside summer scenes as possible. The crowd -filed up the aisles: the aged and needy postmaster, who had seen better -days; the mayor and his wife--for they had a mayor there, among other -unnecessaries; the justice of the peace; the widow Douglass, fair, -smart, and forty, a generous, good-hearted soul and well-to-do, her -hill mansion the only palace in the town, and the most hospitable and -much the most lavish in the matter of festivities that St. Petersburg -could boast; the bent and venerable Major and Mrs. Ward; lawyer -Riverson, the new notable from a distance; next the belle of the -village, followed by a troop of lawn-clad and ribbon-decked young -heart-breakers; then all the young clerks in town in a body--for they -had stood in the vestibule sucking their cane-heads, a circling wall of -oiled and simpering admirers, till the last girl had run their gantlet; -and last of all came the Model Boy, Willie Mufferson, taking as heedful -care of his mother as if she were cut glass. He always brought his -mother to church, and was the pride of all the matrons. The boys all -hated him, he was so good. And besides, he had been "thrown up to them" -so much. His white handkerchief was hanging out of his pocket behind, as -usual on Sundays--accidentally. Tom had no handkerchief, and he looked -upon boys who had as snobs. - -The congregation being fully assembled, now, the bell rang once more, -to warn laggards and stragglers, and then a solemn hush fell upon the -church which was only broken by the tittering and whispering of the -choir in the gallery. The choir always tittered and whispered all -through service. There was once a church choir that was not ill-bred, -but I have forgotten where it was, now. It was a great many years ago, -and I can scarcely remember anything about it, but I think it was in -some foreign country. - -The minister gave out the hymn, and read it through with a relish, in -a peculiar style which was much admired in that part of the country. -His voice began on a medium key and climbed steadily up till it reached -a certain point, where it bore with strong emphasis upon the topmost -word and then plunged down as if from a spring-board: - - Shall I be car-ri-ed toe the skies, on flow'ry BEDS of ease, - - Whilst others fight to win the prize, and sail thro' BLOODY seas? - -He was regarded as a wonderful reader. At church "sociables" he was -always called upon to read poetry; and when he was through, the ladies -would lift up their hands and let them fall helplessly in their laps, -and "wall" their eyes, and shake their heads, as much as to say, "Words -cannot express it; it is too beautiful, TOO beautiful for this mortal -earth." - -After the hymn had been sung, the Rev. Mr. Sprague turned himself into -a bulletin-board, and read off "notices" of meetings and societies and -things till it seemed that the list would stretch out to the crack of -doom--a queer custom which is still kept up in America, even in cities, -away here in this age of abundant newspapers. Often, the less there is -to justify a traditional custom, the harder it is to get rid of it. - -And now the minister prayed. A good, generous prayer it was, and went -into details: it pleaded for the church, and the little children of the -church; for the other churches of the village; for the village itself; -for the county; for the State; for the State officers; for the United -States; for the churches of the United States; for Congress; for the -President; for the officers of the Government; for poor sailors, tossed -by stormy seas; for the oppressed millions groaning under the heel of -European monarchies and Oriental despotisms; for such as have the light -and the good tidings, and yet have not eyes to see nor ears to hear -withal; for the heathen in the far islands of the sea; and closed with -a supplication that the words he was about to speak might find grace -and favor, and be as seed sown in fertile ground, yielding in time a -grateful harvest of good. Amen. - -There was a rustling of dresses, and the standing congregation sat -down. The boy whose history this book relates did not enjoy the prayer, -he only endured it--if he even did that much. He was restive all -through it; he kept tally of the details of the prayer, unconsciously ---for he was not listening, but he knew the ground of old, and the -clergyman's regular route over it--and when a little trifle of new -matter was interlarded, his ear detected it and his whole nature -resented it; he considered additions unfair, and scoundrelly. In the -midst of the prayer a fly had lit on the back of the pew in front of -him and tortured his spirit by calmly rubbing its hands together, -embracing its head with its arms, and polishing it so vigorously that -it seemed to almost part company with the body, and the slender thread -of a neck was exposed to view; scraping its wings with its hind legs -and smoothing them to its body as if they had been coat-tails; going -through its whole toilet as tranquilly as if it knew it was perfectly -safe. As indeed it was; for as sorely as Tom's hands itched to grab for -it they did not dare--he believed his soul would be instantly destroyed -if he did such a thing while the prayer was going on. But with the -closing sentence his hand began to curve and steal forward; and the -instant the "Amen" was out the fly was a prisoner of war. His aunt -detected the act and made him let it go. - -The minister gave out his text and droned along monotonously through -an argument that was so prosy that many a head by and by began to nod ---and yet it was an argument that dealt in limitless fire and brimstone -and thinned the predestined elect down to a company so small as to be -hardly worth the saving. Tom counted the pages of the sermon; after -church he always knew how many pages there had been, but he seldom knew -anything else about the discourse. However, this time he was really -interested for a little while. The minister made a grand and moving -picture of the assembling together of the world's hosts at the -millennium when the lion and the lamb should lie down together and a -little child should lead them. But the pathos, the lesson, the moral of -the great spectacle were lost upon the boy; he only thought of the -conspicuousness of the principal character before the on-looking -nations; his face lit with the thought, and he said to himself that he -wished he could be that child, if it was a tame lion. - -Now he lapsed into suffering again, as the dry argument was resumed. -Presently he bethought him of a treasure he had and got it out. It was -a large black beetle with formidable jaws--a "pinchbug," he called it. -It was in a percussion-cap box. The first thing the beetle did was to -take him by the finger. A natural fillip followed, the beetle went -floundering into the aisle and lit on its back, and the hurt finger -went into the boy's mouth. The beetle lay there working its helpless -legs, unable to turn over. Tom eyed it, and longed for it; but it was -safe out of his reach. Other people uninterested in the sermon found -relief in the beetle, and they eyed it too. Presently a vagrant poodle -dog came idling along, sad at heart, lazy with the summer softness and -the quiet, weary of captivity, sighing for change. He spied the beetle; -the drooping tail lifted and wagged. He surveyed the prize; walked -around it; smelt at it from a safe distance; walked around it again; -grew bolder, and took a closer smell; then lifted his lip and made a -gingerly snatch at it, just missing it; made another, and another; -began to enjoy the diversion; subsided to his stomach with the beetle -between his paws, and continued his experiments; grew weary at last, -and then indifferent and absent-minded. His head nodded, and little by -little his chin descended and touched the enemy, who seized it. There -was a sharp yelp, a flirt of the poodle's head, and the beetle fell a -couple of yards away, and lit on its back once more. The neighboring -spectators shook with a gentle inward joy, several faces went behind -fans and handkerchiefs, and Tom was entirely happy. The dog looked -foolish, and probably felt so; but there was resentment in his heart, -too, and a craving for revenge. So he went to the beetle and began a -wary attack on it again; jumping at it from every point of a circle, -lighting with his fore-paws within an inch of the creature, making even -closer snatches at it with his teeth, and jerking his head till his -ears flapped again. But he grew tired once more, after a while; tried -to amuse himself with a fly but found no relief; followed an ant -around, with his nose close to the floor, and quickly wearied of that; -yawned, sighed, forgot the beetle entirely, and sat down on it. Then -there was a wild yelp of agony and the poodle went sailing up the -aisle; the yelps continued, and so did the dog; he crossed the house in -front of the altar; he flew down the other aisle; he crossed before the -doors; he clamored up the home-stretch; his anguish grew with his -progress, till presently he was but a woolly comet moving in its orbit -with the gleam and the speed of light. At last the frantic sufferer -sheered from its course, and sprang into its master's lap; he flung it -out of the window, and the voice of distress quickly thinned away and -died in the distance. - -By this time the whole church was red-faced and suffocating with -suppressed laughter, and the sermon had come to a dead standstill. The -discourse was resumed presently, but it went lame and halting, all -possibility of impressiveness being at an end; for even the gravest -sentiments were constantly being received with a smothered burst of -unholy mirth, under cover of some remote pew-back, as if the poor -parson had said a rarely facetious thing. It was a genuine relief to -the whole congregation when the ordeal was over and the benediction -pronounced. - -Tom Sawyer went home quite cheerful, thinking to himself that there -was some satisfaction about divine service when there was a bit of -variety in it. He had but one marring thought; he was willing that the -dog should play with his pinchbug, but he did not think it was upright -in him to carry it off. - - - -CHAPTER VI - -MONDAY morning found Tom Sawyer miserable. Monday morning always found -him so--because it began another week's slow suffering in school. He -generally began that day with wishing he had had no intervening -holiday, it made the going into captivity and fetters again so much -more odious. - -Tom lay thinking. Presently it occurred to him that he wished he was -sick; then he could stay home from school. Here was a vague -possibility. He canvassed his system. No ailment was found, and he -investigated again. This time he thought he could detect colicky -symptoms, and he began to encourage them with considerable hope. But -they soon grew feeble, and presently died wholly away. He reflected -further. Suddenly he discovered something. One of his upper front teeth -was loose. This was lucky; he was about to begin to groan, as a -"starter," as he called it, when it occurred to him that if he came -into court with that argument, his aunt would pull it out, and that -would hurt. So he thought he would hold the tooth in reserve for the -present, and seek further. Nothing offered for some little time, and -then he remembered hearing the doctor tell about a certain thing that -laid up a patient for two or three weeks and threatened to make him -lose a finger. So the boy eagerly drew his sore toe from under the -sheet and held it up for inspection. But now he did not know the -necessary symptoms. However, it seemed well worth while to chance it, -so he fell to groaning with considerable spirit. - -But Sid slept on unconscious. - -Tom groaned louder, and fancied that he began to feel pain in the toe. - -No result from Sid. - -Tom was panting with his exertions by this time. He took a rest and -then swelled himself up and fetched a succession of admirable groans. - -Sid snored on. - -Tom was aggravated. He said, "Sid, Sid!" and shook him. This course -worked well, and Tom began to groan again. Sid yawned, stretched, then -brought himself up on his elbow with a snort, and began to stare at -Tom. Tom went on groaning. Sid said: - -"Tom! Say, Tom!" [No response.] "Here, Tom! TOM! What is the matter, -Tom?" And he shook him and looked in his face anxiously. - -Tom moaned out: - -"Oh, don't, Sid. Don't joggle me." - -"Why, what's the matter, Tom? I must call auntie." - -"No--never mind. It'll be over by and by, maybe. Don't call anybody." - -"But I must! DON'T groan so, Tom, it's awful. How long you been this -way?" - -"Hours. Ouch! Oh, don't stir so, Sid, you'll kill me." - -"Tom, why didn't you wake me sooner? Oh, Tom, DON'T! It makes my -flesh crawl to hear you. Tom, what is the matter?" - -"I forgive you everything, Sid. [Groan.] Everything you've ever done -to me. When I'm gone--" - -"Oh, Tom, you ain't dying, are you? Don't, Tom--oh, don't. Maybe--" - -"I forgive everybody, Sid. [Groan.] Tell 'em so, Sid. And Sid, you -give my window-sash and my cat with one eye to that new girl that's -come to town, and tell her--" - -But Sid had snatched his clothes and gone. Tom was suffering in -reality, now, so handsomely was his imagination working, and so his -groans had gathered quite a genuine tone. - -Sid flew down-stairs and said: - -"Oh, Aunt Polly, come! Tom's dying!" - -"Dying!" - -"Yes'm. Don't wait--come quick!" - -"Rubbage! I don't believe it!" - -But she fled up-stairs, nevertheless, with Sid and Mary at her heels. -And her face grew white, too, and her lip trembled. When she reached -the bedside she gasped out: - -"You, Tom! Tom, what's the matter with you?" - -"Oh, auntie, I'm--" - -"What's the matter with you--what is the matter with you, child?" - -"Oh, auntie, my sore toe's mortified!" - -The old lady sank down into a chair and laughed a little, then cried a -little, then did both together. This restored her and she said: - -"Tom, what a turn you did give me. Now you shut up that nonsense and -climb out of this." - -The groans ceased and the pain vanished from the toe. The boy felt a -little foolish, and he said: - -"Aunt Polly, it SEEMED mortified, and it hurt so I never minded my -tooth at all." - -"Your tooth, indeed! What's the matter with your tooth?" - -"One of them's loose, and it aches perfectly awful." - -"There, there, now, don't begin that groaning again. Open your mouth. -Well--your tooth IS loose, but you're not going to die about that. -Mary, get me a silk thread, and a chunk of fire out of the kitchen." - -Tom said: - -"Oh, please, auntie, don't pull it out. It don't hurt any more. I wish -I may never stir if it does. Please don't, auntie. I don't want to stay -home from school." - -"Oh, you don't, don't you? So all this row was because you thought -you'd get to stay home from school and go a-fishing? Tom, Tom, I love -you so, and you seem to try every way you can to break my old heart -with your outrageousness." By this time the dental instruments were -ready. The old lady made one end of the silk thread fast to Tom's tooth -with a loop and tied the other to the bedpost. Then she seized the -chunk of fire and suddenly thrust it almost into the boy's face. The -tooth hung dangling by the bedpost, now. - -But all trials bring their compensations. As Tom wended to school -after breakfast, he was the envy of every boy he met because the gap in -his upper row of teeth enabled him to expectorate in a new and -admirable way. He gathered quite a following of lads interested in the -exhibition; and one that had cut his finger and had been a centre of -fascination and homage up to this time, now found himself suddenly -without an adherent, and shorn of his glory. His heart was heavy, and -he said with a disdain which he did not feel that it wasn't anything to -spit like Tom Sawyer; but another boy said, "Sour grapes!" and he -wandered away a dismantled hero. - -Shortly Tom came upon the juvenile pariah of the village, Huckleberry -Finn, son of the town drunkard. Huckleberry was cordially hated and -dreaded by all the mothers of the town, because he was idle and lawless -and vulgar and bad--and because all their children admired him so, and -delighted in his forbidden society, and wished they dared to be like -him. Tom was like the rest of the respectable boys, in that he envied -Huckleberry his gaudy outcast condition, and was under strict orders -not to play with him. So he played with him every time he got a chance. -Huckleberry was always dressed in the cast-off clothes of full-grown -men, and they were in perennial bloom and fluttering with rags. His hat -was a vast ruin with a wide crescent lopped out of its brim; his coat, -when he wore one, hung nearly to his heels and had the rearward buttons -far down the back; but one suspender supported his trousers; the seat -of the trousers bagged low and contained nothing, the fringed legs -dragged in the dirt when not rolled up. - -Huckleberry came and went, at his own free will. He slept on doorsteps -in fine weather and in empty hogsheads in wet; he did not have to go to -school or to church, or call any being master or obey anybody; he could -go fishing or swimming when and where he chose, and stay as long as it -suited him; nobody forbade him to fight; he could sit up as late as he -pleased; he was always the first boy that went barefoot in the spring -and the last to resume leather in the fall; he never had to wash, nor -put on clean clothes; he could swear wonderfully. In a word, everything -that goes to make life precious that boy had. So thought every -harassed, hampered, respectable boy in St. Petersburg. - -Tom hailed the romantic outcast: - -"Hello, Huckleberry!" - -"Hello yourself, and see how you like it." - -"What's that you got?" - -"Dead cat." - -"Lemme see him, Huck. My, he's pretty stiff. Where'd you get him?" - -"Bought him off'n a boy." - -"What did you give?" - -"I give a blue ticket and a bladder that I got at the slaughter-house." - -"Where'd you get the blue ticket?" - -"Bought it off'n Ben Rogers two weeks ago for a hoop-stick." - -"Say--what is dead cats good for, Huck?" - -"Good for? Cure warts with." - -"No! Is that so? I know something that's better." - -"I bet you don't. What is it?" - -"Why, spunk-water." - -"Spunk-water! I wouldn't give a dern for spunk-water." - -"You wouldn't, wouldn't you? D'you ever try it?" - -"No, I hain't. But Bob Tanner did." - -"Who told you so!" - -"Why, he told Jeff Thatcher, and Jeff told Johnny Baker, and Johnny -told Jim Hollis, and Jim told Ben Rogers, and Ben told a nigger, and -the nigger told me. There now!" - -"Well, what of it? They'll all lie. Leastways all but the nigger. I -don't know HIM. But I never see a nigger that WOULDN'T lie. Shucks! Now -you tell me how Bob Tanner done it, Huck." - -"Why, he took and dipped his hand in a rotten stump where the -rain-water was." - -"In the daytime?" - -"Certainly." - -"With his face to the stump?" - -"Yes. Least I reckon so." - -"Did he say anything?" - -"I don't reckon he did. I don't know." - -"Aha! Talk about trying to cure warts with spunk-water such a blame -fool way as that! Why, that ain't a-going to do any good. You got to go -all by yourself, to the middle of the woods, where you know there's a -spunk-water stump, and just as it's midnight you back up against the -stump and jam your hand in and say: - - 'Barley-corn, barley-corn, injun-meal shorts, - Spunk-water, spunk-water, swaller these warts,' - -and then walk away quick, eleven steps, with your eyes shut, and then -turn around three times and walk home without speaking to anybody. -Because if you speak the charm's busted." - -"Well, that sounds like a good way; but that ain't the way Bob Tanner -done." - -"No, sir, you can bet he didn't, becuz he's the wartiest boy in this -town; and he wouldn't have a wart on him if he'd knowed how to work -spunk-water. I've took off thousands of warts off of my hands that way, -Huck. I play with frogs so much that I've always got considerable many -warts. Sometimes I take 'em off with a bean." - -"Yes, bean's good. I've done that." - -"Have you? What's your way?" - -"You take and split the bean, and cut the wart so as to get some -blood, and then you put the blood on one piece of the bean and take and -dig a hole and bury it 'bout midnight at the crossroads in the dark of -the moon, and then you burn up the rest of the bean. You see that piece -that's got the blood on it will keep drawing and drawing, trying to -fetch the other piece to it, and so that helps the blood to draw the -wart, and pretty soon off she comes." - -"Yes, that's it, Huck--that's it; though when you're burying it if you -say 'Down bean; off wart; come no more to bother me!' it's better. -That's the way Joe Harper does, and he's been nearly to Coonville and -most everywheres. But say--how do you cure 'em with dead cats?" - -"Why, you take your cat and go and get in the graveyard 'long about -midnight when somebody that was wicked has been buried; and when it's -midnight a devil will come, or maybe two or three, but you can't see -'em, you can only hear something like the wind, or maybe hear 'em talk; -and when they're taking that feller away, you heave your cat after 'em -and say, 'Devil follow corpse, cat follow devil, warts follow cat, I'm -done with ye!' That'll fetch ANY wart." - -"Sounds right. D'you ever try it, Huck?" - -"No, but old Mother Hopkins told me." - -"Well, I reckon it's so, then. Becuz they say she's a witch." - -"Say! Why, Tom, I KNOW she is. She witched pap. Pap says so his own -self. He come along one day, and he see she was a-witching him, so he -took up a rock, and if she hadn't dodged, he'd a got her. Well, that -very night he rolled off'n a shed wher' he was a layin drunk, and broke -his arm." - -"Why, that's awful. How did he know she was a-witching him?" - -"Lord, pap can tell, easy. Pap says when they keep looking at you -right stiddy, they're a-witching you. Specially if they mumble. Becuz -when they mumble they're saying the Lord's Prayer backards." - -"Say, Hucky, when you going to try the cat?" - -"To-night. I reckon they'll come after old Hoss Williams to-night." - -"But they buried him Saturday. Didn't they get him Saturday night?" - -"Why, how you talk! How could their charms work till midnight?--and -THEN it's Sunday. Devils don't slosh around much of a Sunday, I don't -reckon." - -"I never thought of that. That's so. Lemme go with you?" - -"Of course--if you ain't afeard." - -"Afeard! 'Tain't likely. Will you meow?" - -"Yes--and you meow back, if you get a chance. Last time, you kep' me -a-meowing around till old Hays went to throwing rocks at me and says -'Dern that cat!' and so I hove a brick through his window--but don't -you tell." - -"I won't. I couldn't meow that night, becuz auntie was watching me, -but I'll meow this time. Say--what's that?" - -"Nothing but a tick." - -"Where'd you get him?" - -"Out in the woods." - -"What'll you take for him?" - -"I don't know. I don't want to sell him." - -"All right. It's a mighty small tick, anyway." - -"Oh, anybody can run a tick down that don't belong to them. I'm -satisfied with it. It's a good enough tick for me." - -"Sho, there's ticks a plenty. I could have a thousand of 'em if I -wanted to." - -"Well, why don't you? Becuz you know mighty well you can't. This is a -pretty early tick, I reckon. It's the first one I've seen this year." - -"Say, Huck--I'll give you my tooth for him." - -"Less see it." - -Tom got out a bit of paper and carefully unrolled it. Huckleberry -viewed it wistfully. The temptation was very strong. At last he said: - -"Is it genuwyne?" - -Tom lifted his lip and showed the vacancy. - -"Well, all right," said Huckleberry, "it's a trade." - -Tom enclosed the tick in the percussion-cap box that had lately been -the pinchbug's prison, and the boys separated, each feeling wealthier -than before. - -When Tom reached the little isolated frame schoolhouse, he strode in -briskly, with the manner of one who had come with all honest speed. -He hung his hat on a peg and flung himself into his seat with -business-like alacrity. The master, throned on high in his great -splint-bottom arm-chair, was dozing, lulled by the drowsy hum of study. -The interruption roused him. - -"Thomas Sawyer!" - -Tom knew that when his name was pronounced in full, it meant trouble. - -"Sir!" - -"Come up here. Now, sir, why are you late again, as usual?" - -Tom was about to take refuge in a lie, when he saw two long tails of -yellow hair hanging down a back that he recognized by the electric -sympathy of love; and by that form was THE ONLY VACANT PLACE on the -girls' side of the schoolhouse. He instantly said: - -"I STOPPED TO TALK WITH HUCKLEBERRY FINN!" - -The master's pulse stood still, and he stared helplessly. The buzz of -study ceased. The pupils wondered if this foolhardy boy had lost his -mind. The master said: - -"You--you did what?" - -"Stopped to talk with Huckleberry Finn." - -There was no mistaking the words. - -"Thomas Sawyer, this is the most astounding confession I have ever -listened to. No mere ferule will answer for this offence. Take off your -jacket." - -The master's arm performed until it was tired and the stock of -switches notably diminished. Then the order followed: - -"Now, sir, go and sit with the girls! And let this be a warning to you." - -The titter that rippled around the room appeared to abash the boy, but -in reality that result was caused rather more by his worshipful awe of -his unknown idol and the dread pleasure that lay in his high good -fortune. He sat down upon the end of the pine bench and the girl -hitched herself away from him with a toss of her head. Nudges and winks -and whispers traversed the room, but Tom sat still, with his arms upon -the long, low desk before him, and seemed to study his book. - -By and by attention ceased from him, and the accustomed school murmur -rose upon the dull air once more. Presently the boy began to steal -furtive glances at the girl. She observed it, "made a mouth" at him and -gave him the back of her head for the space of a minute. When she -cautiously faced around again, a peach lay before her. She thrust it -away. Tom gently put it back. She thrust it away again, but with less -animosity. Tom patiently returned it to its place. Then she let it -remain. Tom scrawled on his slate, "Please take it--I got more." The -girl glanced at the words, but made no sign. Now the boy began to draw -something on the slate, hiding his work with his left hand. For a time -the girl refused to notice; but her human curiosity presently began to -manifest itself by hardly perceptible signs. The boy worked on, -apparently unconscious. The girl made a sort of noncommittal attempt to -see, but the boy did not betray that he was aware of it. At last she -gave in and hesitatingly whispered: - -"Let me see it." - -Tom partly uncovered a dismal caricature of a house with two gable -ends to it and a corkscrew of smoke issuing from the chimney. Then the -girl's interest began to fasten itself upon the work and she forgot -everything else. When it was finished, she gazed a moment, then -whispered: - -"It's nice--make a man." - -The artist erected a man in the front yard, that resembled a derrick. -He could have stepped over the house; but the girl was not -hypercritical; she was satisfied with the monster, and whispered: - -"It's a beautiful man--now make me coming along." - -Tom drew an hour-glass with a full moon and straw limbs to it and -armed the spreading fingers with a portentous fan. The girl said: - -"It's ever so nice--I wish I could draw." - -"It's easy," whispered Tom, "I'll learn you." - -"Oh, will you? When?" - -"At noon. Do you go home to dinner?" - -"I'll stay if you will." - -"Good--that's a whack. What's your name?" - -"Becky Thatcher. What's yours? Oh, I know. It's Thomas Sawyer." - -"That's the name they lick me by. I'm Tom when I'm good. You call me -Tom, will you?" - -"Yes." - -Now Tom began to scrawl something on the slate, hiding the words from -the girl. But she was not backward this time. She begged to see. Tom -said: - -"Oh, it ain't anything." - -"Yes it is." - -"No it ain't. You don't want to see." - -"Yes I do, indeed I do. Please let me." - -"You'll tell." - -"No I won't--deed and deed and double deed won't." - -"You won't tell anybody at all? Ever, as long as you live?" - -"No, I won't ever tell ANYbody. Now let me." - -"Oh, YOU don't want to see!" - -"Now that you treat me so, I WILL see." And she put her small hand -upon his and a little scuffle ensued, Tom pretending to resist in -earnest but letting his hand slip by degrees till these words were -revealed: "I LOVE YOU." - -"Oh, you bad thing!" And she hit his hand a smart rap, but reddened -and looked pleased, nevertheless. - -Just at this juncture the boy felt a slow, fateful grip closing on his -ear, and a steady lifting impulse. In that wise he was borne across the -house and deposited in his own seat, under a peppering fire of giggles -from the whole school. Then the master stood over him during a few -awful moments, and finally moved away to his throne without saying a -word. But although Tom's ear tingled, his heart was jubilant. - -As the school quieted down Tom made an honest effort to study, but the -turmoil within him was too great. In turn he took his place in the -reading class and made a botch of it; then in the geography class and -turned lakes into mountains, mountains into rivers, and rivers into -continents, till chaos was come again; then in the spelling class, and -got "turned down," by a succession of mere baby words, till he brought -up at the foot and yielded up the pewter medal which he had worn with -ostentation for months. - - - -CHAPTER VII - -THE harder Tom tried to fasten his mind on his book, the more his -ideas wandered. So at last, with a sigh and a yawn, he gave it up. It -seemed to him that the noon recess would never come. The air was -utterly dead. There was not a breath stirring. It was the sleepiest of -sleepy days. The drowsing murmur of the five and twenty studying -scholars soothed the soul like the spell that is in the murmur of bees. -Away off in the flaming sunshine, Cardiff Hill lifted its soft green -sides through a shimmering veil of heat, tinted with the purple of -distance; a few birds floated on lazy wing high in the air; no other -living thing was visible but some cows, and they were asleep. Tom's -heart ached to be free, or else to have something of interest to do to -pass the dreary time. His hand wandered into his pocket and his face -lit up with a glow of gratitude that was prayer, though he did not know -it. Then furtively the percussion-cap box came out. He released the -tick and put him on the long flat desk. The creature probably glowed -with a gratitude that amounted to prayer, too, at this moment, but it -was premature: for when he started thankfully to travel off, Tom turned -him aside with a pin and made him take a new direction. - -Tom's bosom friend sat next him, suffering just as Tom had been, and -now he was deeply and gratefully interested in this entertainment in an -instant. This bosom friend was Joe Harper. The two boys were sworn -friends all the week, and embattled enemies on Saturdays. Joe took a -pin out of his lapel and began to assist in exercising the prisoner. -The sport grew in interest momently. Soon Tom said that they were -interfering with each other, and neither getting the fullest benefit of -the tick. So he put Joe's slate on the desk and drew a line down the -middle of it from top to bottom. - -"Now," said he, "as long as he is on your side you can stir him up and -I'll let him alone; but if you let him get away and get on my side, -you're to leave him alone as long as I can keep him from crossing over." - -"All right, go ahead; start him up." - -The tick escaped from Tom, presently, and crossed the equator. Joe -harassed him awhile, and then he got away and crossed back again. This -change of base occurred often. While one boy was worrying the tick with -absorbing interest, the other would look on with interest as strong, -the two heads bowed together over the slate, and the two souls dead to -all things else. At last luck seemed to settle and abide with Joe. The -tick tried this, that, and the other course, and got as excited and as -anxious as the boys themselves, but time and again just as he would -have victory in his very grasp, so to speak, and Tom's fingers would be -twitching to begin, Joe's pin would deftly head him off, and keep -possession. At last Tom could stand it no longer. The temptation was -too strong. So he reached out and lent a hand with his pin. Joe was -angry in a moment. Said he: - -"Tom, you let him alone." - -"I only just want to stir him up a little, Joe." - -"No, sir, it ain't fair; you just let him alone." - -"Blame it, I ain't going to stir him much." - -"Let him alone, I tell you." - -"I won't!" - -"You shall--he's on my side of the line." - -"Look here, Joe Harper, whose is that tick?" - -"I don't care whose tick he is--he's on my side of the line, and you -sha'n't touch him." - -"Well, I'll just bet I will, though. He's my tick and I'll do what I -blame please with him, or die!" - -A tremendous whack came down on Tom's shoulders, and its duplicate on -Joe's; and for the space of two minutes the dust continued to fly from -the two jackets and the whole school to enjoy it. The boys had been too -absorbed to notice the hush that had stolen upon the school awhile -before when the master came tiptoeing down the room and stood over -them. He had contemplated a good part of the performance before he -contributed his bit of variety to it. - -When school broke up at noon, Tom flew to Becky Thatcher, and -whispered in her ear: - -"Put on your bonnet and let on you're going home; and when you get to -the corner, give the rest of 'em the slip, and turn down through the -lane and come back. I'll go the other way and come it over 'em the same -way." - -So the one went off with one group of scholars, and the other with -another. In a little while the two met at the bottom of the lane, and -when they reached the school they had it all to themselves. Then they -sat together, with a slate before them, and Tom gave Becky the pencil -and held her hand in his, guiding it, and so created another surprising -house. When the interest in art began to wane, the two fell to talking. -Tom was swimming in bliss. He said: - -"Do you love rats?" - -"No! I hate them!" - -"Well, I do, too--LIVE ones. But I mean dead ones, to swing round your -head with a string." - -"No, I don't care for rats much, anyway. What I like is chewing-gum." - -"Oh, I should say so! I wish I had some now." - -"Do you? I've got some. I'll let you chew it awhile, but you must give -it back to me." - -That was agreeable, so they chewed it turn about, and dangled their -legs against the bench in excess of contentment. - -"Was you ever at a circus?" said Tom. - -"Yes, and my pa's going to take me again some time, if I'm good." - -"I been to the circus three or four times--lots of times. Church ain't -shucks to a circus. There's things going on at a circus all the time. -I'm going to be a clown in a circus when I grow up." - -"Oh, are you! That will be nice. They're so lovely, all spotted up." - -"Yes, that's so. And they get slathers of money--most a dollar a day, -Ben Rogers says. Say, Becky, was you ever engaged?" - -"What's that?" - -"Why, engaged to be married." - -"No." - -"Would you like to?" - -"I reckon so. I don't know. What is it like?" - -"Like? Why it ain't like anything. You only just tell a boy you won't -ever have anybody but him, ever ever ever, and then you kiss and that's -all. Anybody can do it." - -"Kiss? What do you kiss for?" - -"Why, that, you know, is to--well, they always do that." - -"Everybody?" - -"Why, yes, everybody that's in love with each other. Do you remember -what I wrote on the slate?" - -"Ye--yes." - -"What was it?" - -"I sha'n't tell you." - -"Shall I tell YOU?" - -"Ye--yes--but some other time." - -"No, now." - -"No, not now--to-morrow." - -"Oh, no, NOW. Please, Becky--I'll whisper it, I'll whisper it ever so -easy." - -Becky hesitating, Tom took silence for consent, and passed his arm -about her waist and whispered the tale ever so softly, with his mouth -close to her ear. And then he added: - -"Now you whisper it to me--just the same." - -She resisted, for a while, and then said: - -"You turn your face away so you can't see, and then I will. But you -mustn't ever tell anybody--WILL you, Tom? Now you won't, WILL you?" - -"No, indeed, indeed I won't. Now, Becky." - -He turned his face away. She bent timidly around till her breath -stirred his curls and whispered, "I--love--you!" - -Then she sprang away and ran around and around the desks and benches, -with Tom after her, and took refuge in a corner at last, with her -little white apron to her face. Tom clasped her about her neck and -pleaded: - -"Now, Becky, it's all done--all over but the kiss. Don't you be afraid -of that--it ain't anything at all. Please, Becky." And he tugged at her -apron and the hands. - -By and by she gave up, and let her hands drop; her face, all glowing -with the struggle, came up and submitted. Tom kissed the red lips and -said: - -"Now it's all done, Becky. And always after this, you know, you ain't -ever to love anybody but me, and you ain't ever to marry anybody but -me, ever never and forever. Will you?" - -"No, I'll never love anybody but you, Tom, and I'll never marry -anybody but you--and you ain't to ever marry anybody but me, either." - -"Certainly. Of course. That's PART of it. And always coming to school -or when we're going home, you're to walk with me, when there ain't -anybody looking--and you choose me and I choose you at parties, because -that's the way you do when you're engaged." - -"It's so nice. I never heard of it before." - -"Oh, it's ever so gay! Why, me and Amy Lawrence--" - -The big eyes told Tom his blunder and he stopped, confused. - -"Oh, Tom! Then I ain't the first you've ever been engaged to!" - -The child began to cry. Tom said: - -"Oh, don't cry, Becky, I don't care for her any more." - -"Yes, you do, Tom--you know you do." - -Tom tried to put his arm about her neck, but she pushed him away and -turned her face to the wall, and went on crying. Tom tried again, with -soothing words in his mouth, and was repulsed again. Then his pride was -up, and he strode away and went outside. He stood about, restless and -uneasy, for a while, glancing at the door, every now and then, hoping -she would repent and come to find him. But she did not. Then he began -to feel badly and fear that he was in the wrong. It was a hard struggle -with him to make new advances, now, but he nerved himself to it and -entered. She was still standing back there in the corner, sobbing, with -her face to the wall. Tom's heart smote him. He went to her and stood a -moment, not knowing exactly how to proceed. Then he said hesitatingly: - -"Becky, I--I don't care for anybody but you." - -No reply--but sobs. - -"Becky"--pleadingly. "Becky, won't you say something?" - -More sobs. - -Tom got out his chiefest jewel, a brass knob from the top of an -andiron, and passed it around her so that she could see it, and said: - -"Please, Becky, won't you take it?" - -She struck it to the floor. Then Tom marched out of the house and over -the hills and far away, to return to school no more that day. Presently -Becky began to suspect. She ran to the door; he was not in sight; she -flew around to the play-yard; he was not there. Then she called: - -"Tom! Come back, Tom!" - -She listened intently, but there was no answer. She had no companions -but silence and loneliness. So she sat down to cry again and upbraid -herself; and by this time the scholars began to gather again, and she -had to hide her griefs and still her broken heart and take up the cross -of a long, dreary, aching afternoon, with none among the strangers -about her to exchange sorrows with. - - - -CHAPTER VIII - -TOM dodged hither and thither through lanes until he was well out of -the track of returning scholars, and then fell into a moody jog. He -crossed a small "branch" two or three times, because of a prevailing -juvenile superstition that to cross water baffled pursuit. Half an hour -later he was disappearing behind the Douglas mansion on the summit of -Cardiff Hill, and the schoolhouse was hardly distinguishable away off -in the valley behind him. He entered a dense wood, picked his pathless -way to the centre of it, and sat down on a mossy spot under a spreading -oak. There was not even a zephyr stirring; the dead noonday heat had -even stilled the songs of the birds; nature lay in a trance that was -broken by no sound but the occasional far-off hammering of a -woodpecker, and this seemed to render the pervading silence and sense -of loneliness the more profound. The boy's soul was steeped in -melancholy; his feelings were in happy accord with his surroundings. He -sat long with his elbows on his knees and his chin in his hands, -meditating. It seemed to him that life was but a trouble, at best, and -he more than half envied Jimmy Hodges, so lately released; it must be -very peaceful, he thought, to lie and slumber and dream forever and -ever, with the wind whispering through the trees and caressing the -grass and the flowers over the grave, and nothing to bother and grieve -about, ever any more. If he only had a clean Sunday-school record he -could be willing to go, and be done with it all. Now as to this girl. -What had he done? Nothing. He had meant the best in the world, and been -treated like a dog--like a very dog. She would be sorry some day--maybe -when it was too late. Ah, if he could only die TEMPORARILY! - -But the elastic heart of youth cannot be compressed into one -constrained shape long at a time. Tom presently began to drift -insensibly back into the concerns of this life again. What if he turned -his back, now, and disappeared mysteriously? What if he went away--ever -so far away, into unknown countries beyond the seas--and never came -back any more! How would she feel then! The idea of being a clown -recurred to him now, only to fill him with disgust. For frivolity and -jokes and spotted tights were an offense, when they intruded themselves -upon a spirit that was exalted into the vague august realm of the -romantic. No, he would be a soldier, and return after long years, all -war-worn and illustrious. No--better still, he would join the Indians, -and hunt buffaloes and go on the warpath in the mountain ranges and the -trackless great plains of the Far West, and away in the future come -back a great chief, bristling with feathers, hideous with paint, and -prance into Sunday-school, some drowsy summer morning, with a -bloodcurdling war-whoop, and sear the eyeballs of all his companions -with unappeasable envy. But no, there was something gaudier even than -this. He would be a pirate! That was it! NOW his future lay plain -before him, and glowing with unimaginable splendor. How his name would -fill the world, and make people shudder! How gloriously he would go -plowing the dancing seas, in his long, low, black-hulled racer, the -Spirit of the Storm, with his grisly flag flying at the fore! And at -the zenith of his fame, how he would suddenly appear at the old village -and stalk into church, brown and weather-beaten, in his black velvet -doublet and trunks, his great jack-boots, his crimson sash, his belt -bristling with horse-pistols, his crime-rusted cutlass at his side, his -slouch hat with waving plumes, his black flag unfurled, with the skull -and crossbones on it, and hear with swelling ecstasy the whisperings, -"It's Tom Sawyer the Pirate!--the Black Avenger of the Spanish Main!" - -Yes, it was settled; his career was determined. He would run away from -home and enter upon it. He would start the very next morning. Therefore -he must now begin to get ready. He would collect his resources -together. He went to a rotten log near at hand and began to dig under -one end of it with his Barlow knife. He soon struck wood that sounded -hollow. He put his hand there and uttered this incantation impressively: - -"What hasn't come here, come! What's here, stay here!" - -Then he scraped away the dirt, and exposed a pine shingle. He took it -up and disclosed a shapely little treasure-house whose bottom and sides -were of shingles. In it lay a marble. Tom's astonishment was boundless! -He scratched his head with a perplexed air, and said: - -"Well, that beats anything!" - -Then he tossed the marble away pettishly, and stood cogitating. The -truth was, that a superstition of his had failed, here, which he and -all his comrades had always looked upon as infallible. If you buried a -marble with certain necessary incantations, and left it alone a -fortnight, and then opened the place with the incantation he had just -used, you would find that all the marbles you had ever lost had -gathered themselves together there, meantime, no matter how widely they -had been separated. But now, this thing had actually and unquestionably -failed. Tom's whole structure of faith was shaken to its foundations. -He had many a time heard of this thing succeeding but never of its -failing before. It did not occur to him that he had tried it several -times before, himself, but could never find the hiding-places -afterward. He puzzled over the matter some time, and finally decided -that some witch had interfered and broken the charm. He thought he -would satisfy himself on that point; so he searched around till he -found a small sandy spot with a little funnel-shaped depression in it. -He laid himself down and put his mouth close to this depression and -called-- - -"Doodle-bug, doodle-bug, tell me what I want to know! Doodle-bug, -doodle-bug, tell me what I want to know!" - -The sand began to work, and presently a small black bug appeared for a -second and then darted under again in a fright. - -"He dasn't tell! So it WAS a witch that done it. I just knowed it." - -He well knew the futility of trying to contend against witches, so he -gave up discouraged. But it occurred to him that he might as well have -the marble he had just thrown away, and therefore he went and made a -patient search for it. But he could not find it. Now he went back to -his treasure-house and carefully placed himself just as he had been -standing when he tossed the marble away; then he took another marble -from his pocket and tossed it in the same way, saying: - -"Brother, go find your brother!" - -He watched where it stopped, and went there and looked. But it must -have fallen short or gone too far; so he tried twice more. The last -repetition was successful. The two marbles lay within a foot of each -other. - -Just here the blast of a toy tin trumpet came faintly down the green -aisles of the forest. Tom flung off his jacket and trousers, turned a -suspender into a belt, raked away some brush behind the rotten log, -disclosing a rude bow and arrow, a lath sword and a tin trumpet, and in -a moment had seized these things and bounded away, barelegged, with -fluttering shirt. He presently halted under a great elm, blew an -answering blast, and then began to tiptoe and look warily out, this way -and that. He said cautiously--to an imaginary company: - -"Hold, my merry men! Keep hid till I blow." - -Now appeared Joe Harper, as airily clad and elaborately armed as Tom. -Tom called: - -"Hold! Who comes here into Sherwood Forest without my pass?" - -"Guy of Guisborne wants no man's pass. Who art thou that--that--" - -"Dares to hold such language," said Tom, prompting--for they talked -"by the book," from memory. - -"Who art thou that dares to hold such language?" - -"I, indeed! I am Robin Hood, as thy caitiff carcase soon shall know." - -"Then art thou indeed that famous outlaw? Right gladly will I dispute -with thee the passes of the merry wood. Have at thee!" - -They took their lath swords, dumped their other traps on the ground, -struck a fencing attitude, foot to foot, and began a grave, careful -combat, "two up and two down." Presently Tom said: - -"Now, if you've got the hang, go it lively!" - -So they "went it lively," panting and perspiring with the work. By and -by Tom shouted: - -"Fall! fall! Why don't you fall?" - -"I sha'n't! Why don't you fall yourself? You're getting the worst of -it." - -"Why, that ain't anything. I can't fall; that ain't the way it is in -the book. The book says, 'Then with one back-handed stroke he slew poor -Guy of Guisborne.' You're to turn around and let me hit you in the -back." - -There was no getting around the authorities, so Joe turned, received -the whack and fell. - -"Now," said Joe, getting up, "you got to let me kill YOU. That's fair." - -"Why, I can't do that, it ain't in the book." - -"Well, it's blamed mean--that's all." - -"Well, say, Joe, you can be Friar Tuck or Much the miller's son, and -lam me with a quarter-staff; or I'll be the Sheriff of Nottingham and -you be Robin Hood a little while and kill me." - -This was satisfactory, and so these adventures were carried out. Then -Tom became Robin Hood again, and was allowed by the treacherous nun to -bleed his strength away through his neglected wound. And at last Joe, -representing a whole tribe of weeping outlaws, dragged him sadly forth, -gave his bow into his feeble hands, and Tom said, "Where this arrow -falls, there bury poor Robin Hood under the greenwood tree." Then he -shot the arrow and fell back and would have died, but he lit on a -nettle and sprang up too gaily for a corpse. - -The boys dressed themselves, hid their accoutrements, and went off -grieving that there were no outlaws any more, and wondering what modern -civilization could claim to have done to compensate for their loss. -They said they would rather be outlaws a year in Sherwood Forest than -President of the United States forever. - - - -CHAPTER IX - -AT half-past nine, that night, Tom and Sid were sent to bed, as usual. -They said their prayers, and Sid was soon asleep. Tom lay awake and -waited, in restless impatience. When it seemed to him that it must be -nearly daylight, he heard the clock strike ten! This was despair. He -would have tossed and fidgeted, as his nerves demanded, but he was -afraid he might wake Sid. So he lay still, and stared up into the dark. -Everything was dismally still. By and by, out of the stillness, little, -scarcely perceptible noises began to emphasize themselves. The ticking -of the clock began to bring itself into notice. Old beams began to -crack mysteriously. The stairs creaked faintly. Evidently spirits were -abroad. A measured, muffled snore issued from Aunt Polly's chamber. And -now the tiresome chirping of a cricket that no human ingenuity could -locate, began. Next the ghastly ticking of a deathwatch in the wall at -the bed's head made Tom shudder--it meant that somebody's days were -numbered. Then the howl of a far-off dog rose on the night air, and was -answered by a fainter howl from a remoter distance. Tom was in an -agony. At last he was satisfied that time had ceased and eternity -begun; he began to doze, in spite of himself; the clock chimed eleven, -but he did not hear it. And then there came, mingling with his -half-formed dreams, a most melancholy caterwauling. The raising of a -neighboring window disturbed him. A cry of "Scat! you devil!" and the -crash of an empty bottle against the back of his aunt's woodshed -brought him wide awake, and a single minute later he was dressed and -out of the window and creeping along the roof of the "ell" on all -fours. He "meow'd" with caution once or twice, as he went; then jumped -to the roof of the woodshed and thence to the ground. Huckleberry Finn -was there, with his dead cat. The boys moved off and disappeared in the -gloom. At the end of half an hour they were wading through the tall -grass of the graveyard. - -It was a graveyard of the old-fashioned Western kind. It was on a -hill, about a mile and a half from the village. It had a crazy board -fence around it, which leaned inward in places, and outward the rest of -the time, but stood upright nowhere. Grass and weeds grew rank over the -whole cemetery. All the old graves were sunken in, there was not a -tombstone on the place; round-topped, worm-eaten boards staggered over -the graves, leaning for support and finding none. "Sacred to the memory -of" So-and-So had been painted on them once, but it could no longer -have been read, on the most of them, now, even if there had been light. - -A faint wind moaned through the trees, and Tom feared it might be the -spirits of the dead, complaining at being disturbed. The boys talked -little, and only under their breath, for the time and the place and the -pervading solemnity and silence oppressed their spirits. They found the -sharp new heap they were seeking, and ensconced themselves within the -protection of three great elms that grew in a bunch within a few feet -of the grave. - -Then they waited in silence for what seemed a long time. The hooting -of a distant owl was all the sound that troubled the dead stillness. -Tom's reflections grew oppressive. He must force some talk. So he said -in a whisper: - -"Hucky, do you believe the dead people like it for us to be here?" - -Huckleberry whispered: - -"I wisht I knowed. It's awful solemn like, AIN'T it?" - -"I bet it is." - -There was a considerable pause, while the boys canvassed this matter -inwardly. Then Tom whispered: - -"Say, Hucky--do you reckon Hoss Williams hears us talking?" - -"O' course he does. Least his sperrit does." - -Tom, after a pause: - -"I wish I'd said Mister Williams. But I never meant any harm. -Everybody calls him Hoss." - -"A body can't be too partic'lar how they talk 'bout these-yer dead -people, Tom." - -This was a damper, and conversation died again. - -Presently Tom seized his comrade's arm and said: - -"Sh!" - -"What is it, Tom?" And the two clung together with beating hearts. - -"Sh! There 'tis again! Didn't you hear it?" - -"I--" - -"There! Now you hear it." - -"Lord, Tom, they're coming! They're coming, sure. What'll we do?" - -"I dono. Think they'll see us?" - -"Oh, Tom, they can see in the dark, same as cats. I wisht I hadn't -come." - -"Oh, don't be afeard. I don't believe they'll bother us. We ain't -doing any harm. If we keep perfectly still, maybe they won't notice us -at all." - -"I'll try to, Tom, but, Lord, I'm all of a shiver." - -"Listen!" - -The boys bent their heads together and scarcely breathed. A muffled -sound of voices floated up from the far end of the graveyard. - -"Look! See there!" whispered Tom. "What is it?" - -"It's devil-fire. Oh, Tom, this is awful." - -Some vague figures approached through the gloom, swinging an -old-fashioned tin lantern that freckled the ground with innumerable -little spangles of light. Presently Huckleberry whispered with a -shudder: - -"It's the devils sure enough. Three of 'em! Lordy, Tom, we're goners! -Can you pray?" - -"I'll try, but don't you be afeard. They ain't going to hurt us. 'Now -I lay me down to sleep, I--'" - -"Sh!" - -"What is it, Huck?" - -"They're HUMANS! One of 'em is, anyway. One of 'em's old Muff Potter's -voice." - -"No--'tain't so, is it?" - -"I bet I know it. Don't you stir nor budge. He ain't sharp enough to -notice us. Drunk, the same as usual, likely--blamed old rip!" - -"All right, I'll keep still. Now they're stuck. Can't find it. Here -they come again. Now they're hot. Cold again. Hot again. Red hot! -They're p'inted right, this time. Say, Huck, I know another o' them -voices; it's Injun Joe." - -"That's so--that murderin' half-breed! I'd druther they was devils a -dern sight. What kin they be up to?" - -The whisper died wholly out, now, for the three men had reached the -grave and stood within a few feet of the boys' hiding-place. - -"Here it is," said the third voice; and the owner of it held the -lantern up and revealed the face of young Doctor Robinson. - -Potter and Injun Joe were carrying a handbarrow with a rope and a -couple of shovels on it. They cast down their load and began to open -the grave. The doctor put the lantern at the head of the grave and came -and sat down with his back against one of the elm trees. He was so -close the boys could have touched him. - -"Hurry, men!" he said, in a low voice; "the moon might come out at any -moment." - -They growled a response and went on digging. For some time there was -no noise but the grating sound of the spades discharging their freight -of mould and gravel. It was very monotonous. Finally a spade struck -upon the coffin with a dull woody accent, and within another minute or -two the men had hoisted it out on the ground. They pried off the lid -with their shovels, got out the body and dumped it rudely on the -ground. The moon drifted from behind the clouds and exposed the pallid -face. The barrow was got ready and the corpse placed on it, covered -with a blanket, and bound to its place with the rope. Potter took out a -large spring-knife and cut off the dangling end of the rope and then -said: - -"Now the cussed thing's ready, Sawbones, and you'll just out with -another five, or here she stays." - -"That's the talk!" said Injun Joe. - -"Look here, what does this mean?" said the doctor. "You required your -pay in advance, and I've paid you." - -"Yes, and you done more than that," said Injun Joe, approaching the -doctor, who was now standing. "Five years ago you drove me away from -your father's kitchen one night, when I come to ask for something to -eat, and you said I warn't there for any good; and when I swore I'd get -even with you if it took a hundred years, your father had me jailed for -a vagrant. Did you think I'd forget? The Injun blood ain't in me for -nothing. And now I've GOT you, and you got to SETTLE, you know!" - -He was threatening the doctor, with his fist in his face, by this -time. The doctor struck out suddenly and stretched the ruffian on the -ground. Potter dropped his knife, and exclaimed: - -"Here, now, don't you hit my pard!" and the next moment he had -grappled with the doctor and the two were struggling with might and -main, trampling the grass and tearing the ground with their heels. -Injun Joe sprang to his feet, his eyes flaming with passion, snatched -up Potter's knife, and went creeping, catlike and stooping, round and -round about the combatants, seeking an opportunity. All at once the -doctor flung himself free, seized the heavy headboard of Williams' -grave and felled Potter to the earth with it--and in the same instant -the half-breed saw his chance and drove the knife to the hilt in the -young man's breast. He reeled and fell partly upon Potter, flooding him -with his blood, and in the same moment the clouds blotted out the -dreadful spectacle and the two frightened boys went speeding away in -the dark. - -Presently, when the moon emerged again, Injun Joe was standing over -the two forms, contemplating them. The doctor murmured inarticulately, -gave a long gasp or two and was still. The half-breed muttered: - -"THAT score is settled--damn you." - -Then he robbed the body. After which he put the fatal knife in -Potter's open right hand, and sat down on the dismantled coffin. Three ---four--five minutes passed, and then Potter began to stir and moan. His -hand closed upon the knife; he raised it, glanced at it, and let it -fall, with a shudder. Then he sat up, pushing the body from him, and -gazed at it, and then around him, confusedly. His eyes met Joe's. - -"Lord, how is this, Joe?" he said. - -"It's a dirty business," said Joe, without moving. - -"What did you do it for?" - -"I! I never done it!" - -"Look here! That kind of talk won't wash." - -Potter trembled and grew white. - -"I thought I'd got sober. I'd no business to drink to-night. But it's -in my head yet--worse'n when we started here. I'm all in a muddle; -can't recollect anything of it, hardly. Tell me, Joe--HONEST, now, old -feller--did I do it? Joe, I never meant to--'pon my soul and honor, I -never meant to, Joe. Tell me how it was, Joe. Oh, it's awful--and him -so young and promising." - -"Why, you two was scuffling, and he fetched you one with the headboard -and you fell flat; and then up you come, all reeling and staggering -like, and snatched the knife and jammed it into him, just as he fetched -you another awful clip--and here you've laid, as dead as a wedge til -now." - -"Oh, I didn't know what I was a-doing. I wish I may die this minute if -I did. It was all on account of the whiskey and the excitement, I -reckon. I never used a weepon in my life before, Joe. I've fought, but -never with weepons. They'll all say that. Joe, don't tell! Say you -won't tell, Joe--that's a good feller. I always liked you, Joe, and -stood up for you, too. Don't you remember? You WON'T tell, WILL you, -Joe?" And the poor creature dropped on his knees before the stolid -murderer, and clasped his appealing hands. - -"No, you've always been fair and square with me, Muff Potter, and I -won't go back on you. There, now, that's as fair as a man can say." - -"Oh, Joe, you're an angel. I'll bless you for this the longest day I -live." And Potter began to cry. - -"Come, now, that's enough of that. This ain't any time for blubbering. -You be off yonder way and I'll go this. Move, now, and don't leave any -tracks behind you." - -Potter started on a trot that quickly increased to a run. The -half-breed stood looking after him. He muttered: - -"If he's as much stunned with the lick and fuddled with the rum as he -had the look of being, he won't think of the knife till he's gone so -far he'll be afraid to come back after it to such a place by himself ---chicken-heart!" - -Two or three minutes later the murdered man, the blanketed corpse, the -lidless coffin, and the open grave were under no inspection but the -moon's. The stillness was complete again, too. - - - -CHAPTER X - -THE two boys flew on and on, toward the village, speechless with -horror. They glanced backward over their shoulders from time to time, -apprehensively, as if they feared they might be followed. Every stump -that started up in their path seemed a man and an enemy, and made them -catch their breath; and as they sped by some outlying cottages that lay -near the village, the barking of the aroused watch-dogs seemed to give -wings to their feet. - -"If we can only get to the old tannery before we break down!" -whispered Tom, in short catches between breaths. "I can't stand it much -longer." - -Huckleberry's hard pantings were his only reply, and the boys fixed -their eyes on the goal of their hopes and bent to their work to win it. -They gained steadily on it, and at last, breast to breast, they burst -through the open door and fell grateful and exhausted in the sheltering -shadows beyond. By and by their pulses slowed down, and Tom whispered: - -"Huckleberry, what do you reckon'll come of this?" - -"If Doctor Robinson dies, I reckon hanging'll come of it." - -"Do you though?" - -"Why, I KNOW it, Tom." - -Tom thought a while, then he said: - -"Who'll tell? We?" - -"What are you talking about? S'pose something happened and Injun Joe -DIDN'T hang? Why, he'd kill us some time or other, just as dead sure as -we're a laying here." - -"That's just what I was thinking to myself, Huck." - -"If anybody tells, let Muff Potter do it, if he's fool enough. He's -generally drunk enough." - -Tom said nothing--went on thinking. Presently he whispered: - -"Huck, Muff Potter don't know it. How can he tell?" - -"What's the reason he don't know it?" - -"Because he'd just got that whack when Injun Joe done it. D'you reckon -he could see anything? D'you reckon he knowed anything?" - -"By hokey, that's so, Tom!" - -"And besides, look-a-here--maybe that whack done for HIM!" - -"No, 'taint likely, Tom. He had liquor in him; I could see that; and -besides, he always has. Well, when pap's full, you might take and belt -him over the head with a church and you couldn't phase him. He says so, -his own self. So it's the same with Muff Potter, of course. But if a -man was dead sober, I reckon maybe that whack might fetch him; I dono." - -After another reflective silence, Tom said: - -"Hucky, you sure you can keep mum?" - -"Tom, we GOT to keep mum. You know that. That Injun devil wouldn't -make any more of drownding us than a couple of cats, if we was to -squeak 'bout this and they didn't hang him. Now, look-a-here, Tom, less -take and swear to one another--that's what we got to do--swear to keep -mum." - -"I'm agreed. It's the best thing. Would you just hold hands and swear -that we--" - -"Oh no, that wouldn't do for this. That's good enough for little -rubbishy common things--specially with gals, cuz THEY go back on you -anyway, and blab if they get in a huff--but there orter be writing -'bout a big thing like this. And blood." - -Tom's whole being applauded this idea. It was deep, and dark, and -awful; the hour, the circumstances, the surroundings, were in keeping -with it. He picked up a clean pine shingle that lay in the moonlight, -took a little fragment of "red keel" out of his pocket, got the moon on -his work, and painfully scrawled these lines, emphasizing each slow -down-stroke by clamping his tongue between his teeth, and letting up -the pressure on the up-strokes. [See next page.] - - "Huck Finn and - Tom Sawyer swears - they will keep mum - about This and They - wish They may Drop - down dead in Their - Tracks if They ever - Tell and Rot." - -Huckleberry was filled with admiration of Tom's facility in writing, -and the sublimity of his language. He at once took a pin from his lapel -and was going to prick his flesh, but Tom said: - -"Hold on! Don't do that. A pin's brass. It might have verdigrease on -it." - -"What's verdigrease?" - -"It's p'ison. That's what it is. You just swaller some of it once ---you'll see." - -So Tom unwound the thread from one of his needles, and each boy -pricked the ball of his thumb and squeezed out a drop of blood. In -time, after many squeezes, Tom managed to sign his initials, using the -ball of his little finger for a pen. Then he showed Huckleberry how to -make an H and an F, and the oath was complete. They buried the shingle -close to the wall, with some dismal ceremonies and incantations, and -the fetters that bound their tongues were considered to be locked and -the key thrown away. - -A figure crept stealthily through a break in the other end of the -ruined building, now, but they did not notice it. - -"Tom," whispered Huckleberry, "does this keep us from EVER telling ---ALWAYS?" - -"Of course it does. It don't make any difference WHAT happens, we got -to keep mum. We'd drop down dead--don't YOU know that?" - -"Yes, I reckon that's so." - -They continued to whisper for some little time. Presently a dog set up -a long, lugubrious howl just outside--within ten feet of them. The boys -clasped each other suddenly, in an agony of fright. - -"Which of us does he mean?" gasped Huckleberry. - -"I dono--peep through the crack. Quick!" - -"No, YOU, Tom!" - -"I can't--I can't DO it, Huck!" - -"Please, Tom. There 'tis again!" - -"Oh, lordy, I'm thankful!" whispered Tom. "I know his voice. It's Bull -Harbison." * - -[* If Mr. Harbison owned a slave named Bull, Tom would have spoken of -him as "Harbison's Bull," but a son or a dog of that name was "Bull -Harbison."] - -"Oh, that's good--I tell you, Tom, I was most scared to death; I'd a -bet anything it was a STRAY dog." - -The dog howled again. The boys' hearts sank once more. - -"Oh, my! that ain't no Bull Harbison!" whispered Huckleberry. "DO, Tom!" - -Tom, quaking with fear, yielded, and put his eye to the crack. His -whisper was hardly audible when he said: - -"Oh, Huck, IT S A STRAY DOG!" - -"Quick, Tom, quick! Who does he mean?" - -"Huck, he must mean us both--we're right together." - -"Oh, Tom, I reckon we're goners. I reckon there ain't no mistake 'bout -where I'LL go to. I been so wicked." - -"Dad fetch it! This comes of playing hookey and doing everything a -feller's told NOT to do. I might a been good, like Sid, if I'd a tried ---but no, I wouldn't, of course. But if ever I get off this time, I lay -I'll just WALLER in Sunday-schools!" And Tom began to snuffle a little. - -"YOU bad!" and Huckleberry began to snuffle too. "Consound it, Tom -Sawyer, you're just old pie, 'longside o' what I am. Oh, LORDY, lordy, -lordy, I wisht I only had half your chance." - -Tom choked off and whispered: - -"Look, Hucky, look! He's got his BACK to us!" - -Hucky looked, with joy in his heart. - -"Well, he has, by jingoes! Did he before?" - -"Yes, he did. But I, like a fool, never thought. Oh, this is bully, -you know. NOW who can he mean?" - -The howling stopped. Tom pricked up his ears. - -"Sh! What's that?" he whispered. - -"Sounds like--like hogs grunting. No--it's somebody snoring, Tom." - -"That IS it! Where 'bouts is it, Huck?" - -"I bleeve it's down at 'tother end. Sounds so, anyway. Pap used to -sleep there, sometimes, 'long with the hogs, but laws bless you, he -just lifts things when HE snores. Besides, I reckon he ain't ever -coming back to this town any more." - -The spirit of adventure rose in the boys' souls once more. - -"Hucky, do you das't to go if I lead?" - -"I don't like to, much. Tom, s'pose it's Injun Joe!" - -Tom quailed. But presently the temptation rose up strong again and the -boys agreed to try, with the understanding that they would take to -their heels if the snoring stopped. So they went tiptoeing stealthily -down, the one behind the other. When they had got to within five steps -of the snorer, Tom stepped on a stick, and it broke with a sharp snap. -The man moaned, writhed a little, and his face came into the moonlight. -It was Muff Potter. The boys' hearts had stood still, and their hopes -too, when the man moved, but their fears passed away now. They tiptoed -out, through the broken weather-boarding, and stopped at a little -distance to exchange a parting word. That long, lugubrious howl rose on -the night air again! They turned and saw the strange dog standing -within a few feet of where Potter was lying, and FACING Potter, with -his nose pointing heavenward. - -"Oh, geeminy, it's HIM!" exclaimed both boys, in a breath. - -"Say, Tom--they say a stray dog come howling around Johnny Miller's -house, 'bout midnight, as much as two weeks ago; and a whippoorwill -come in and lit on the banisters and sung, the very same evening; and -there ain't anybody dead there yet." - -"Well, I know that. And suppose there ain't. Didn't Gracie Miller fall -in the kitchen fire and burn herself terrible the very next Saturday?" - -"Yes, but she ain't DEAD. And what's more, she's getting better, too." - -"All right, you wait and see. She's a goner, just as dead sure as Muff -Potter's a goner. That's what the niggers say, and they know all about -these kind of things, Huck." - -Then they separated, cogitating. When Tom crept in at his bedroom -window the night was almost spent. He undressed with excessive caution, -and fell asleep congratulating himself that nobody knew of his -escapade. He was not aware that the gently-snoring Sid was awake, and -had been so for an hour. - -When Tom awoke, Sid was dressed and gone. There was a late look in the -light, a late sense in the atmosphere. He was startled. Why had he not -been called--persecuted till he was up, as usual? The thought filled -him with bodings. Within five minutes he was dressed and down-stairs, -feeling sore and drowsy. The family were still at table, but they had -finished breakfast. There was no voice of rebuke; but there were -averted eyes; there was a silence and an air of solemnity that struck a -chill to the culprit's heart. He sat down and tried to seem gay, but it -was up-hill work; it roused no smile, no response, and he lapsed into -silence and let his heart sink down to the depths. - -After breakfast his aunt took him aside, and Tom almost brightened in -the hope that he was going to be flogged; but it was not so. His aunt -wept over him and asked him how he could go and break her old heart so; -and finally told him to go on, and ruin himself and bring her gray -hairs with sorrow to the grave, for it was no use for her to try any -more. This was worse than a thousand whippings, and Tom's heart was -sorer now than his body. He cried, he pleaded for forgiveness, promised -to reform over and over again, and then received his dismissal, feeling -that he had won but an imperfect forgiveness and established but a -feeble confidence. - -He left the presence too miserable to even feel revengeful toward Sid; -and so the latter's prompt retreat through the back gate was -unnecessary. He moped to school gloomy and sad, and took his flogging, -along with Joe Harper, for playing hookey the day before, with the air -of one whose heart was busy with heavier woes and wholly dead to -trifles. Then he betook himself to his seat, rested his elbows on his -desk and his jaws in his hands, and stared at the wall with the stony -stare of suffering that has reached the limit and can no further go. -His elbow was pressing against some hard substance. After a long time -he slowly and sadly changed his position, and took up this object with -a sigh. It was in a paper. He unrolled it. A long, lingering, colossal -sigh followed, and his heart broke. It was his brass andiron knob! - -This final feather broke the camel's back. - - - -CHAPTER XI - -CLOSE upon the hour of noon the whole village was suddenly electrified -with the ghastly news. No need of the as yet undreamed-of telegraph; -the tale flew from man to man, from group to group, from house to -house, with little less than telegraphic speed. Of course the -schoolmaster gave holiday for that afternoon; the town would have -thought strangely of him if he had not. - -A gory knife had been found close to the murdered man, and it had been -recognized by somebody as belonging to Muff Potter--so the story ran. -And it was said that a belated citizen had come upon Potter washing -himself in the "branch" about one or two o'clock in the morning, and -that Potter had at once sneaked off--suspicious circumstances, -especially the washing which was not a habit with Potter. It was also -said that the town had been ransacked for this "murderer" (the public -are not slow in the matter of sifting evidence and arriving at a -verdict), but that he could not be found. Horsemen had departed down -all the roads in every direction, and the Sheriff "was confident" that -he would be captured before night. - -All the town was drifting toward the graveyard. Tom's heartbreak -vanished and he joined the procession, not because he would not a -thousand times rather go anywhere else, but because an awful, -unaccountable fascination drew him on. Arrived at the dreadful place, -he wormed his small body through the crowd and saw the dismal -spectacle. It seemed to him an age since he was there before. Somebody -pinched his arm. He turned, and his eyes met Huckleberry's. Then both -looked elsewhere at once, and wondered if anybody had noticed anything -in their mutual glance. But everybody was talking, and intent upon the -grisly spectacle before them. - -"Poor fellow!" "Poor young fellow!" "This ought to be a lesson to -grave robbers!" "Muff Potter'll hang for this if they catch him!" This -was the drift of remark; and the minister said, "It was a judgment; His -hand is here." - -Now Tom shivered from head to heel; for his eye fell upon the stolid -face of Injun Joe. At this moment the crowd began to sway and struggle, -and voices shouted, "It's him! it's him! he's coming himself!" - -"Who? Who?" from twenty voices. - -"Muff Potter!" - -"Hallo, he's stopped!--Look out, he's turning! Don't let him get away!" - -People in the branches of the trees over Tom's head said he wasn't -trying to get away--he only looked doubtful and perplexed. - -"Infernal impudence!" said a bystander; "wanted to come and take a -quiet look at his work, I reckon--didn't expect any company." - -The crowd fell apart, now, and the Sheriff came through, -ostentatiously leading Potter by the arm. The poor fellow's face was -haggard, and his eyes showed the fear that was upon him. When he stood -before the murdered man, he shook as with a palsy, and he put his face -in his hands and burst into tears. - -"I didn't do it, friends," he sobbed; "'pon my word and honor I never -done it." - -"Who's accused you?" shouted a voice. - -This shot seemed to carry home. Potter lifted his face and looked -around him with a pathetic hopelessness in his eyes. He saw Injun Joe, -and exclaimed: - -"Oh, Injun Joe, you promised me you'd never--" - -"Is that your knife?" and it was thrust before him by the Sheriff. - -Potter would have fallen if they had not caught him and eased him to -the ground. Then he said: - -"Something told me 't if I didn't come back and get--" He shuddered; -then waved his nerveless hand with a vanquished gesture and said, "Tell -'em, Joe, tell 'em--it ain't any use any more." - -Then Huckleberry and Tom stood dumb and staring, and heard the -stony-hearted liar reel off his serene statement, they expecting every -moment that the clear sky would deliver God's lightnings upon his head, -and wondering to see how long the stroke was delayed. And when he had -finished and still stood alive and whole, their wavering impulse to -break their oath and save the poor betrayed prisoner's life faded and -vanished away, for plainly this miscreant had sold himself to Satan and -it would be fatal to meddle with the property of such a power as that. - -"Why didn't you leave? What did you want to come here for?" somebody -said. - -"I couldn't help it--I couldn't help it," Potter moaned. "I wanted to -run away, but I couldn't seem to come anywhere but here." And he fell -to sobbing again. - -Injun Joe repeated his statement, just as calmly, a few minutes -afterward on the inquest, under oath; and the boys, seeing that the -lightnings were still withheld, were confirmed in their belief that Joe -had sold himself to the devil. He was now become, to them, the most -balefully interesting object they had ever looked upon, and they could -not take their fascinated eyes from his face. - -They inwardly resolved to watch him nights, when opportunity should -offer, in the hope of getting a glimpse of his dread master. - -Injun Joe helped to raise the body of the murdered man and put it in a -wagon for removal; and it was whispered through the shuddering crowd -that the wound bled a little! The boys thought that this happy -circumstance would turn suspicion in the right direction; but they were -disappointed, for more than one villager remarked: - -"It was within three feet of Muff Potter when it done it." - -Tom's fearful secret and gnawing conscience disturbed his sleep for as -much as a week after this; and at breakfast one morning Sid said: - -"Tom, you pitch around and talk in your sleep so much that you keep me -awake half the time." - -Tom blanched and dropped his eyes. - -"It's a bad sign," said Aunt Polly, gravely. "What you got on your -mind, Tom?" - -"Nothing. Nothing 't I know of." But the boy's hand shook so that he -spilled his coffee. - -"And you do talk such stuff," Sid said. "Last night you said, 'It's -blood, it's blood, that's what it is!' You said that over and over. And -you said, 'Don't torment me so--I'll tell!' Tell WHAT? What is it -you'll tell?" - -Everything was swimming before Tom. There is no telling what might -have happened, now, but luckily the concern passed out of Aunt Polly's -face and she came to Tom's relief without knowing it. She said: - -"Sho! It's that dreadful murder. I dream about it most every night -myself. Sometimes I dream it's me that done it." - -Mary said she had been affected much the same way. Sid seemed -satisfied. Tom got out of the presence as quick as he plausibly could, -and after that he complained of toothache for a week, and tied up his -jaws every night. He never knew that Sid lay nightly watching, and -frequently slipped the bandage free and then leaned on his elbow -listening a good while at a time, and afterward slipped the bandage -back to its place again. Tom's distress of mind wore off gradually and -the toothache grew irksome and was discarded. If Sid really managed to -make anything out of Tom's disjointed mutterings, he kept it to himself. - -It seemed to Tom that his schoolmates never would get done holding -inquests on dead cats, and thus keeping his trouble present to his -mind. Sid noticed that Tom never was coroner at one of these inquiries, -though it had been his habit to take the lead in all new enterprises; -he noticed, too, that Tom never acted as a witness--and that was -strange; and Sid did not overlook the fact that Tom even showed a -marked aversion to these inquests, and always avoided them when he -could. Sid marvelled, but said nothing. However, even inquests went out -of vogue at last, and ceased to torture Tom's conscience. - -Every day or two, during this time of sorrow, Tom watched his -opportunity and went to the little grated jail-window and smuggled such -small comforts through to the "murderer" as he could get hold of. The -jail was a trifling little brick den that stood in a marsh at the edge -of the village, and no guards were afforded for it; indeed, it was -seldom occupied. These offerings greatly helped to ease Tom's -conscience. - -The villagers had a strong desire to tar-and-feather Injun Joe and -ride him on a rail, for body-snatching, but so formidable was his -character that nobody could be found who was willing to take the lead -in the matter, so it was dropped. He had been careful to begin both of -his inquest-statements with the fight, without confessing the -grave-robbery that preceded it; therefore it was deemed wisest not -to try the case in the courts at present. - - - -CHAPTER XII - -ONE of the reasons why Tom's mind had drifted away from its secret -troubles was, that it had found a new and weighty matter to interest -itself about. Becky Thatcher had stopped coming to school. Tom had -struggled with his pride a few days, and tried to "whistle her down the -wind," but failed. He began to find himself hanging around her father's -house, nights, and feeling very miserable. She was ill. What if she -should die! There was distraction in the thought. He no longer took an -interest in war, nor even in piracy. The charm of life was gone; there -was nothing but dreariness left. He put his hoop away, and his bat; -there was no joy in them any more. His aunt was concerned. She began to -try all manner of remedies on him. She was one of those people who are -infatuated with patent medicines and all new-fangled methods of -producing health or mending it. She was an inveterate experimenter in -these things. When something fresh in this line came out she was in a -fever, right away, to try it; not on herself, for she was never ailing, -but on anybody else that came handy. She was a subscriber for all the -"Health" periodicals and phrenological frauds; and the solemn ignorance -they were inflated with was breath to her nostrils. All the "rot" they -contained about ventilation, and how to go to bed, and how to get up, -and what to eat, and what to drink, and how much exercise to take, and -what frame of mind to keep one's self in, and what sort of clothing to -wear, was all gospel to her, and she never observed that her -health-journals of the current month customarily upset everything they -had recommended the month before. She was as simple-hearted and honest -as the day was long, and so she was an easy victim. She gathered -together her quack periodicals and her quack medicines, and thus armed -with death, went about on her pale horse, metaphorically speaking, with -"hell following after." But she never suspected that she was not an -angel of healing and the balm of Gilead in disguise, to the suffering -neighbors. - -The water treatment was new, now, and Tom's low condition was a -windfall to her. She had him out at daylight every morning, stood him -up in the woodshed and drowned him with a deluge of cold water; then -she scrubbed him down with a towel like a file, and so brought him to; -then she rolled him up in a wet sheet and put him away under blankets -till she sweated his soul clean and "the yellow stains of it came -through his pores"--as Tom said. - -Yet notwithstanding all this, the boy grew more and more melancholy -and pale and dejected. She added hot baths, sitz baths, shower baths, -and plunges. The boy remained as dismal as a hearse. She began to -assist the water with a slim oatmeal diet and blister-plasters. She -calculated his capacity as she would a jug's, and filled him up every -day with quack cure-alls. - -Tom had become indifferent to persecution by this time. This phase -filled the old lady's heart with consternation. This indifference must -be broken up at any cost. Now she heard of Pain-killer for the first -time. She ordered a lot at once. She tasted it and was filled with -gratitude. It was simply fire in a liquid form. She dropped the water -treatment and everything else, and pinned her faith to Pain-killer. She -gave Tom a teaspoonful and watched with the deepest anxiety for the -result. Her troubles were instantly at rest, her soul at peace again; -for the "indifference" was broken up. The boy could not have shown a -wilder, heartier interest, if she had built a fire under him. - -Tom felt that it was time to wake up; this sort of life might be -romantic enough, in his blighted condition, but it was getting to have -too little sentiment and too much distracting variety about it. So he -thought over various plans for relief, and finally hit pon that of -professing to be fond of Pain-killer. He asked for it so often that he -became a nuisance, and his aunt ended by telling him to help himself -and quit bothering her. If it had been Sid, she would have had no -misgivings to alloy her delight; but since it was Tom, she watched the -bottle clandestinely. She found that the medicine did really diminish, -but it did not occur to her that the boy was mending the health of a -crack in the sitting-room floor with it. - -One day Tom was in the act of dosing the crack when his aunt's yellow -cat came along, purring, eying the teaspoon avariciously, and begging -for a taste. Tom said: - -"Don't ask for it unless you want it, Peter." - -But Peter signified that he did want it. - -"You better make sure." - -Peter was sure. - -"Now you've asked for it, and I'll give it to you, because there ain't -anything mean about me; but if you find you don't like it, you mustn't -blame anybody but your own self." - -Peter was agreeable. So Tom pried his mouth open and poured down the -Pain-killer. Peter sprang a couple of yards in the air, and then -delivered a war-whoop and set off round and round the room, banging -against furniture, upsetting flower-pots, and making general havoc. -Next he rose on his hind feet and pranced around, in a frenzy of -enjoyment, with his head over his shoulder and his voice proclaiming -his unappeasable happiness. Then he went tearing around the house again -spreading chaos and destruction in his path. Aunt Polly entered in time -to see him throw a few double summersets, deliver a final mighty -hurrah, and sail through the open window, carrying the rest of the -flower-pots with him. The old lady stood petrified with astonishment, -peering over her glasses; Tom lay on the floor expiring with laughter. - -"Tom, what on earth ails that cat?" - -"I don't know, aunt," gasped the boy. - -"Why, I never see anything like it. What did make him act so?" - -"Deed I don't know, Aunt Polly; cats always act so when they're having -a good time." - -"They do, do they?" There was something in the tone that made Tom -apprehensive. - -"Yes'm. That is, I believe they do." - -"You DO?" - -"Yes'm." - -The old lady was bending down, Tom watching, with interest emphasized -by anxiety. Too late he divined her "drift." The handle of the telltale -teaspoon was visible under the bed-valance. Aunt Polly took it, held it -up. Tom winced, and dropped his eyes. Aunt Polly raised him by the -usual handle--his ear--and cracked his head soundly with her thimble. - -"Now, sir, what did you want to treat that poor dumb beast so, for?" - -"I done it out of pity for him--because he hadn't any aunt." - -"Hadn't any aunt!--you numskull. What has that got to do with it?" - -"Heaps. Because if he'd had one she'd a burnt him out herself! She'd a -roasted his bowels out of him 'thout any more feeling than if he was a -human!" - -Aunt Polly felt a sudden pang of remorse. This was putting the thing -in a new light; what was cruelty to a cat MIGHT be cruelty to a boy, -too. She began to soften; she felt sorry. Her eyes watered a little, -and she put her hand on Tom's head and said gently: - -"I was meaning for the best, Tom. And, Tom, it DID do you good." - -Tom looked up in her face with just a perceptible twinkle peeping -through his gravity. - -"I know you was meaning for the best, aunty, and so was I with Peter. -It done HIM good, too. I never see him get around so since--" - -"Oh, go 'long with you, Tom, before you aggravate me again. And you -try and see if you can't be a good boy, for once, and you needn't take -any more medicine." - -Tom reached school ahead of time. It was noticed that this strange -thing had been occurring every day latterly. And now, as usual of late, -he hung about the gate of the schoolyard instead of playing with his -comrades. He was sick, he said, and he looked it. He tried to seem to -be looking everywhere but whither he really was looking--down the road. -Presently Jeff Thatcher hove in sight, and Tom's face lighted; he gazed -a moment, and then turned sorrowfully away. When Jeff arrived, Tom -accosted him; and "led up" warily to opportunities for remark about -Becky, but the giddy lad never could see the bait. Tom watched and -watched, hoping whenever a frisking frock came in sight, and hating the -owner of it as soon as he saw she was not the right one. At last frocks -ceased to appear, and he dropped hopelessly into the dumps; he entered -the empty schoolhouse and sat down to suffer. Then one more frock -passed in at the gate, and Tom's heart gave a great bound. The next -instant he was out, and "going on" like an Indian; yelling, laughing, -chasing boys, jumping over the fence at risk of life and limb, throwing -handsprings, standing on his head--doing all the heroic things he could -conceive of, and keeping a furtive eye out, all the while, to see if -Becky Thatcher was noticing. But she seemed to be unconscious of it -all; she never looked. Could it be possible that she was not aware that -he was there? He carried his exploits to her immediate vicinity; came -war-whooping around, snatched a boy's cap, hurled it to the roof of the -schoolhouse, broke through a group of boys, tumbling them in every -direction, and fell sprawling, himself, under Becky's nose, almost -upsetting her--and she turned, with her nose in the air, and he heard -her say: "Mf! some people think they're mighty smart--always showing -off!" - -Tom's cheeks burned. He gathered himself up and sneaked off, crushed -and crestfallen. - - - -CHAPTER XIII - -TOM'S mind was made up now. He was gloomy and desperate. He was a -forsaken, friendless boy, he said; nobody loved him; when they found -out what they had driven him to, perhaps they would be sorry; he had -tried to do right and get along, but they would not let him; since -nothing would do them but to be rid of him, let it be so; and let them -blame HIM for the consequences--why shouldn't they? What right had the -friendless to complain? Yes, they had forced him to it at last: he -would lead a life of crime. There was no choice. - -By this time he was far down Meadow Lane, and the bell for school to -"take up" tinkled faintly upon his ear. He sobbed, now, to think he -should never, never hear that old familiar sound any more--it was very -hard, but it was forced on him; since he was driven out into the cold -world, he must submit--but he forgave them. Then the sobs came thick -and fast. - -Just at this point he met his soul's sworn comrade, Joe Harper ---hard-eyed, and with evidently a great and dismal purpose in his heart. -Plainly here were "two souls with but a single thought." Tom, wiping -his eyes with his sleeve, began to blubber out something about a -resolution to escape from hard usage and lack of sympathy at home by -roaming abroad into the great world never to return; and ended by -hoping that Joe would not forget him. - -But it transpired that this was a request which Joe had just been -going to make of Tom, and had come to hunt him up for that purpose. His -mother had whipped him for drinking some cream which he had never -tasted and knew nothing about; it was plain that she was tired of him -and wished him to go; if she felt that way, there was nothing for him -to do but succumb; he hoped she would be happy, and never regret having -driven her poor boy out into the unfeeling world to suffer and die. - -As the two boys walked sorrowing along, they made a new compact to -stand by each other and be brothers and never separate till death -relieved them of their troubles. Then they began to lay their plans. -Joe was for being a hermit, and living on crusts in a remote cave, and -dying, some time, of cold and want and grief; but after listening to -Tom, he conceded that there were some conspicuous advantages about a -life of crime, and so he consented to be a pirate. - -Three miles below St. Petersburg, at a point where the Mississippi -River was a trifle over a mile wide, there was a long, narrow, wooded -island, with a shallow bar at the head of it, and this offered well as -a rendezvous. It was not inhabited; it lay far over toward the further -shore, abreast a dense and almost wholly unpeopled forest. So Jackson's -Island was chosen. Who were to be the subjects of their piracies was a -matter that did not occur to them. Then they hunted up Huckleberry -Finn, and he joined them promptly, for all careers were one to him; he -was indifferent. They presently separated to meet at a lonely spot on -the river-bank two miles above the village at the favorite hour--which -was midnight. There was a small log raft there which they meant to -capture. Each would bring hooks and lines, and such provision as he -could steal in the most dark and mysterious way--as became outlaws. And -before the afternoon was done, they had all managed to enjoy the sweet -glory of spreading the fact that pretty soon the town would "hear -something." All who got this vague hint were cautioned to "be mum and -wait." - -About midnight Tom arrived with a boiled ham and a few trifles, -and stopped in a dense undergrowth on a small bluff overlooking the -meeting-place. It was starlight, and very still. The mighty river lay -like an ocean at rest. Tom listened a moment, but no sound disturbed the -quiet. Then he gave a low, distinct whistle. It was answered from under -the bluff. Tom whistled twice more; these signals were answered in the -same way. Then a guarded voice said: - -"Who goes there?" - -"Tom Sawyer, the Black Avenger of the Spanish Main. Name your names." - -"Huck Finn the Red-Handed, and Joe Harper the Terror of the Seas." Tom -had furnished these titles, from his favorite literature. - -"'Tis well. Give the countersign." - -Two hoarse whispers delivered the same awful word simultaneously to -the brooding night: - -"BLOOD!" - -Then Tom tumbled his ham over the bluff and let himself down after it, -tearing both skin and clothes to some extent in the effort. There was -an easy, comfortable path along the shore under the bluff, but it -lacked the advantages of difficulty and danger so valued by a pirate. - -The Terror of the Seas had brought a side of bacon, and had about worn -himself out with getting it there. Finn the Red-Handed had stolen a -skillet and a quantity of half-cured leaf tobacco, and had also brought -a few corn-cobs to make pipes with. But none of the pirates smoked or -"chewed" but himself. The Black Avenger of the Spanish Main said it -would never do to start without some fire. That was a wise thought; -matches were hardly known there in that day. They saw a fire -smouldering upon a great raft a hundred yards above, and they went -stealthily thither and helped themselves to a chunk. They made an -imposing adventure of it, saying, "Hist!" every now and then, and -suddenly halting with finger on lip; moving with hands on imaginary -dagger-hilts; and giving orders in dismal whispers that if "the foe" -stirred, to "let him have it to the hilt," because "dead men tell no -tales." They knew well enough that the raftsmen were all down at the -village laying in stores or having a spree, but still that was no -excuse for their conducting this thing in an unpiratical way. - -They shoved off, presently, Tom in command, Huck at the after oar and -Joe at the forward. Tom stood amidships, gloomy-browed, and with folded -arms, and gave his orders in a low, stern whisper: - -"Luff, and bring her to the wind!" - -"Aye-aye, sir!" - -"Steady, steady-y-y-y!" - -"Steady it is, sir!" - -"Let her go off a point!" - -"Point it is, sir!" - -As the boys steadily and monotonously drove the raft toward mid-stream -it was no doubt understood that these orders were given only for -"style," and were not intended to mean anything in particular. - -"What sail's she carrying?" - -"Courses, tops'ls, and flying-jib, sir." - -"Send the r'yals up! Lay out aloft, there, half a dozen of ye ---foretopmaststuns'l! Lively, now!" - -"Aye-aye, sir!" - -"Shake out that maintogalans'l! Sheets and braces! NOW my hearties!" - -"Aye-aye, sir!" - -"Hellum-a-lee--hard a port! Stand by to meet her when she comes! Port, -port! NOW, men! With a will! Stead-y-y-y!" - -"Steady it is, sir!" - -The raft drew beyond the middle of the river; the boys pointed her -head right, and then lay on their oars. The river was not high, so -there was not more than a two or three mile current. Hardly a word was -said during the next three-quarters of an hour. Now the raft was -passing before the distant town. Two or three glimmering lights showed -where it lay, peacefully sleeping, beyond the vague vast sweep of -star-gemmed water, unconscious of the tremendous event that was happening. -The Black Avenger stood still with folded arms, "looking his last" upon -the scene of his former joys and his later sufferings, and wishing -"she" could see him now, abroad on the wild sea, facing peril and death -with dauntless heart, going to his doom with a grim smile on his lips. -It was but a small strain on his imagination to remove Jackson's Island -beyond eyeshot of the village, and so he "looked his last" with a -broken and satisfied heart. The other pirates were looking their last, -too; and they all looked so long that they came near letting the -current drift them out of the range of the island. But they discovered -the danger in time, and made shift to avert it. About two o'clock in -the morning the raft grounded on the bar two hundred yards above the -head of the island, and they waded back and forth until they had landed -their freight. Part of the little raft's belongings consisted of an old -sail, and this they spread over a nook in the bushes for a tent to -shelter their provisions; but they themselves would sleep in the open -air in good weather, as became outlaws. - -They built a fire against the side of a great log twenty or thirty -steps within the sombre depths of the forest, and then cooked some -bacon in the frying-pan for supper, and used up half of the corn "pone" -stock they had brought. It seemed glorious sport to be feasting in that -wild, free way in the virgin forest of an unexplored and uninhabited -island, far from the haunts of men, and they said they never would -return to civilization. The climbing fire lit up their faces and threw -its ruddy glare upon the pillared tree-trunks of their forest temple, -and upon the varnished foliage and festooning vines. - -When the last crisp slice of bacon was gone, and the last allowance of -corn pone devoured, the boys stretched themselves out on the grass, -filled with contentment. They could have found a cooler place, but they -would not deny themselves such a romantic feature as the roasting -camp-fire. - -"AIN'T it gay?" said Joe. - -"It's NUTS!" said Tom. "What would the boys say if they could see us?" - -"Say? Well, they'd just die to be here--hey, Hucky!" - -"I reckon so," said Huckleberry; "anyways, I'm suited. I don't want -nothing better'n this. I don't ever get enough to eat, gen'ally--and -here they can't come and pick at a feller and bullyrag him so." - -"It's just the life for me," said Tom. "You don't have to get up, -mornings, and you don't have to go to school, and wash, and all that -blame foolishness. You see a pirate don't have to do ANYTHING, Joe, -when he's ashore, but a hermit HE has to be praying considerable, and -then he don't have any fun, anyway, all by himself that way." - -"Oh yes, that's so," said Joe, "but I hadn't thought much about it, -you know. I'd a good deal rather be a pirate, now that I've tried it." - -"You see," said Tom, "people don't go much on hermits, nowadays, like -they used to in old times, but a pirate's always respected. And a -hermit's got to sleep on the hardest place he can find, and put -sackcloth and ashes on his head, and stand out in the rain, and--" - -"What does he put sackcloth and ashes on his head for?" inquired Huck. - -"I dono. But they've GOT to do it. Hermits always do. You'd have to do -that if you was a hermit." - -"Dern'd if I would," said Huck. - -"Well, what would you do?" - -"I dono. But I wouldn't do that." - -"Why, Huck, you'd HAVE to. How'd you get around it?" - -"Why, I just wouldn't stand it. I'd run away." - -"Run away! Well, you WOULD be a nice old slouch of a hermit. You'd be -a disgrace." - -The Red-Handed made no response, being better employed. He had -finished gouging out a cob, and now he fitted a weed stem to it, loaded -it with tobacco, and was pressing a coal to the charge and blowing a -cloud of fragrant smoke--he was in the full bloom of luxurious -contentment. The other pirates envied him this majestic vice, and -secretly resolved to acquire it shortly. Presently Huck said: - -"What does pirates have to do?" - -Tom said: - -"Oh, they have just a bully time--take ships and burn them, and get -the money and bury it in awful places in their island where there's -ghosts and things to watch it, and kill everybody in the ships--make -'em walk a plank." - -"And they carry the women to the island," said Joe; "they don't kill -the women." - -"No," assented Tom, "they don't kill the women--they're too noble. And -the women's always beautiful, too. - -"And don't they wear the bulliest clothes! Oh no! All gold and silver -and di'monds," said Joe, with enthusiasm. - -"Who?" said Huck. - -"Why, the pirates." - -Huck scanned his own clothing forlornly. - -"I reckon I ain't dressed fitten for a pirate," said he, with a -regretful pathos in his voice; "but I ain't got none but these." - -But the other boys told him the fine clothes would come fast enough, -after they should have begun their adventures. They made him understand -that his poor rags would do to begin with, though it was customary for -wealthy pirates to start with a proper wardrobe. - -Gradually their talk died out and drowsiness began to steal upon the -eyelids of the little waifs. The pipe dropped from the fingers of the -Red-Handed, and he slept the sleep of the conscience-free and the -weary. The Terror of the Seas and the Black Avenger of the Spanish Main -had more difficulty in getting to sleep. They said their prayers -inwardly, and lying down, since there was nobody there with authority -to make them kneel and recite aloud; in truth, they had a mind not to -say them at all, but they were afraid to proceed to such lengths as -that, lest they might call down a sudden and special thunderbolt from -heaven. Then at once they reached and hovered upon the imminent verge -of sleep--but an intruder came, now, that would not "down." It was -conscience. They began to feel a vague fear that they had been doing -wrong to run away; and next they thought of the stolen meat, and then -the real torture came. They tried to argue it away by reminding -conscience that they had purloined sweetmeats and apples scores of -times; but conscience was not to be appeased by such thin -plausibilities; it seemed to them, in the end, that there was no -getting around the stubborn fact that taking sweetmeats was only -"hooking," while taking bacon and hams and such valuables was plain -simple stealing--and there was a command against that in the Bible. So -they inwardly resolved that so long as they remained in the business, -their piracies should not again be sullied with the crime of stealing. -Then conscience granted a truce, and these curiously inconsistent -pirates fell peacefully to sleep. - - - -CHAPTER XIV - -WHEN Tom awoke in the morning, he wondered where he was. He sat up and -rubbed his eyes and looked around. Then he comprehended. It was the -cool gray dawn, and there was a delicious sense of repose and peace in -the deep pervading calm and silence of the woods. Not a leaf stirred; -not a sound obtruded upon great Nature's meditation. Beaded dewdrops -stood upon the leaves and grasses. A white layer of ashes covered the -fire, and a thin blue breath of smoke rose straight into the air. Joe -and Huck still slept. - -Now, far away in the woods a bird called; another answered; presently -the hammering of a woodpecker was heard. Gradually the cool dim gray of -the morning whitened, and as gradually sounds multiplied and life -manifested itself. The marvel of Nature shaking off sleep and going to -work unfolded itself to the musing boy. A little green worm came -crawling over a dewy leaf, lifting two-thirds of his body into the air -from time to time and "sniffing around," then proceeding again--for he -was measuring, Tom said; and when the worm approached him, of its own -accord, he sat as still as a stone, with his hopes rising and falling, -by turns, as the creature still came toward him or seemed inclined to -go elsewhere; and when at last it considered a painful moment with its -curved body in the air and then came decisively down upon Tom's leg and -began a journey over him, his whole heart was glad--for that meant that -he was going to have a new suit of clothes--without the shadow of a -doubt a gaudy piratical uniform. Now a procession of ants appeared, -from nowhere in particular, and went about their labors; one struggled -manfully by with a dead spider five times as big as itself in its arms, -and lugged it straight up a tree-trunk. A brown spotted lady-bug -climbed the dizzy height of a grass blade, and Tom bent down close to -it and said, "Lady-bug, lady-bug, fly away home, your house is on fire, -your children's alone," and she took wing and went off to see about it ---which did not surprise the boy, for he knew of old that this insect was -credulous about conflagrations, and he had practised upon its -simplicity more than once. A tumblebug came next, heaving sturdily at -its ball, and Tom touched the creature, to see it shut its legs against -its body and pretend to be dead. The birds were fairly rioting by this -time. A catbird, the Northern mocker, lit in a tree over Tom's head, -and trilled out her imitations of her neighbors in a rapture of -enjoyment; then a shrill jay swept down, a flash of blue flame, and -stopped on a twig almost within the boy's reach, cocked his head to one -side and eyed the strangers with a consuming curiosity; a gray squirrel -and a big fellow of the "fox" kind came skurrying along, sitting up at -intervals to inspect and chatter at the boys, for the wild things had -probably never seen a human being before and scarcely knew whether to -be afraid or not. All Nature was wide awake and stirring, now; long -lances of sunlight pierced down through the dense foliage far and near, -and a few butterflies came fluttering upon the scene. - -Tom stirred up the other pirates and they all clattered away with a -shout, and in a minute or two were stripped and chasing after and -tumbling over each other in the shallow limpid water of the white -sandbar. They felt no longing for the little village sleeping in the -distance beyond the majestic waste of water. A vagrant current or a -slight rise in the river had carried off their raft, but this only -gratified them, since its going was something like burning the bridge -between them and civilization. - -They came back to camp wonderfully refreshed, glad-hearted, and -ravenous; and they soon had the camp-fire blazing up again. Huck found -a spring of clear cold water close by, and the boys made cups of broad -oak or hickory leaves, and felt that water, sweetened with such a -wildwood charm as that, would be a good enough substitute for coffee. -While Joe was slicing bacon for breakfast, Tom and Huck asked him to -hold on a minute; they stepped to a promising nook in the river-bank -and threw in their lines; almost immediately they had reward. Joe had -not had time to get impatient before they were back again with some -handsome bass, a couple of sun-perch and a small catfish--provisions -enough for quite a family. They fried the fish with the bacon, and were -astonished; for no fish had ever seemed so delicious before. They did -not know that the quicker a fresh-water fish is on the fire after he is -caught the better he is; and they reflected little upon what a sauce -open-air sleeping, open-air exercise, bathing, and a large ingredient -of hunger make, too. - -They lay around in the shade, after breakfast, while Huck had a smoke, -and then went off through the woods on an exploring expedition. They -tramped gayly along, over decaying logs, through tangled underbrush, -among solemn monarchs of the forest, hung from their crowns to the -ground with a drooping regalia of grape-vines. Now and then they came -upon snug nooks carpeted with grass and jeweled with flowers. - -They found plenty of things to be delighted with, but nothing to be -astonished at. They discovered that the island was about three miles -long and a quarter of a mile wide, and that the shore it lay closest to -was only separated from it by a narrow channel hardly two hundred yards -wide. They took a swim about every hour, so it was close upon the -middle of the afternoon when they got back to camp. They were too -hungry to stop to fish, but they fared sumptuously upon cold ham, and -then threw themselves down in the shade to talk. But the talk soon -began to drag, and then died. The stillness, the solemnity that brooded -in the woods, and the sense of loneliness, began to tell upon the -spirits of the boys. They fell to thinking. A sort of undefined longing -crept upon them. This took dim shape, presently--it was budding -homesickness. Even Finn the Red-Handed was dreaming of his doorsteps -and empty hogsheads. But they were all ashamed of their weakness, and -none was brave enough to speak his thought. - -For some time, now, the boys had been dully conscious of a peculiar -sound in the distance, just as one sometimes is of the ticking of a -clock which he takes no distinct note of. But now this mysterious sound -became more pronounced, and forced a recognition. The boys started, -glanced at each other, and then each assumed a listening attitude. -There was a long silence, profound and unbroken; then a deep, sullen -boom came floating down out of the distance. - -"What is it!" exclaimed Joe, under his breath. - -"I wonder," said Tom in a whisper. - -"'Tain't thunder," said Huckleberry, in an awed tone, "becuz thunder--" - -"Hark!" said Tom. "Listen--don't talk." - -They waited a time that seemed an age, and then the same muffled boom -troubled the solemn hush. - -"Let's go and see." - -They sprang to their feet and hurried to the shore toward the town. -They parted the bushes on the bank and peered out over the water. The -little steam ferryboat was about a mile below the village, drifting -with the current. Her broad deck seemed crowded with people. There were -a great many skiffs rowing about or floating with the stream in the -neighborhood of the ferryboat, but the boys could not determine what -the men in them were doing. Presently a great jet of white smoke burst -from the ferryboat's side, and as it expanded and rose in a lazy cloud, -that same dull throb of sound was borne to the listeners again. - -"I know now!" exclaimed Tom; "somebody's drownded!" - -"That's it!" said Huck; "they done that last summer, when Bill Turner -got drownded; they shoot a cannon over the water, and that makes him -come up to the top. Yes, and they take loaves of bread and put -quicksilver in 'em and set 'em afloat, and wherever there's anybody -that's drownded, they'll float right there and stop." - -"Yes, I've heard about that," said Joe. "I wonder what makes the bread -do that." - -"Oh, it ain't the bread, so much," said Tom; "I reckon it's mostly -what they SAY over it before they start it out." - -"But they don't say anything over it," said Huck. "I've seen 'em and -they don't." - -"Well, that's funny," said Tom. "But maybe they say it to themselves. -Of COURSE they do. Anybody might know that." - -The other boys agreed that there was reason in what Tom said, because -an ignorant lump of bread, uninstructed by an incantation, could not be -expected to act very intelligently when set upon an errand of such -gravity. - -"By jings, I wish I was over there, now," said Joe. - -"I do too" said Huck "I'd give heaps to know who it is." - -The boys still listened and watched. Presently a revealing thought -flashed through Tom's mind, and he exclaimed: - -"Boys, I know who's drownded--it's us!" - -They felt like heroes in an instant. Here was a gorgeous triumph; they -were missed; they were mourned; hearts were breaking on their account; -tears were being shed; accusing memories of unkindness to these poor -lost lads were rising up, and unavailing regrets and remorse were being -indulged; and best of all, the departed were the talk of the whole -town, and the envy of all the boys, as far as this dazzling notoriety -was concerned. This was fine. It was worth while to be a pirate, after -all. - -As twilight drew on, the ferryboat went back to her accustomed -business and the skiffs disappeared. The pirates returned to camp. They -were jubilant with vanity over their new grandeur and the illustrious -trouble they were making. They caught fish, cooked supper and ate it, -and then fell to guessing at what the village was thinking and saying -about them; and the pictures they drew of the public distress on their -account were gratifying to look upon--from their point of view. But -when the shadows of night closed them in, they gradually ceased to -talk, and sat gazing into the fire, with their minds evidently -wandering elsewhere. The excitement was gone, now, and Tom and Joe -could not keep back thoughts of certain persons at home who were not -enjoying this fine frolic as much as they were. Misgivings came; they -grew troubled and unhappy; a sigh or two escaped, unawares. By and by -Joe timidly ventured upon a roundabout "feeler" as to how the others -might look upon a return to civilization--not right now, but-- - -Tom withered him with derision! Huck, being uncommitted as yet, joined -in with Tom, and the waverer quickly "explained," and was glad to get -out of the scrape with as little taint of chicken-hearted homesickness -clinging to his garments as he could. Mutiny was effectually laid to -rest for the moment. - -As the night deepened, Huck began to nod, and presently to snore. Joe -followed next. Tom lay upon his elbow motionless, for some time, -watching the two intently. At last he got up cautiously, on his knees, -and went searching among the grass and the flickering reflections flung -by the camp-fire. He picked up and inspected several large -semi-cylinders of the thin white bark of a sycamore, and finally chose -two which seemed to suit him. Then he knelt by the fire and painfully -wrote something upon each of these with his "red keel"; one he rolled up -and put in his jacket pocket, and the other he put in Joe's hat and -removed it to a little distance from the owner. And he also put into the -hat certain schoolboy treasures of almost inestimable value--among them -a lump of chalk, an India-rubber ball, three fishhooks, and one of that -kind of marbles known as a "sure 'nough crystal." Then he tiptoed his -way cautiously among the trees till he felt that he was out of hearing, -and straightway broke into a keen run in the direction of the sandbar. - - - -CHAPTER XV - -A FEW minutes later Tom was in the shoal water of the bar, wading -toward the Illinois shore. Before the depth reached his middle he was -half-way over; the current would permit no more wading, now, so he -struck out confidently to swim the remaining hundred yards. He swam -quartering upstream, but still was swept downward rather faster than he -had expected. However, he reached the shore finally, and drifted along -till he found a low place and drew himself out. He put his hand on his -jacket pocket, found his piece of bark safe, and then struck through -the woods, following the shore, with streaming garments. Shortly before -ten o'clock he came out into an open place opposite the village, and -saw the ferryboat lying in the shadow of the trees and the high bank. -Everything was quiet under the blinking stars. He crept down the bank, -watching with all his eyes, slipped into the water, swam three or four -strokes and climbed into the skiff that did "yawl" duty at the boat's -stern. He laid himself down under the thwarts and waited, panting. - -Presently the cracked bell tapped and a voice gave the order to "cast -off." A minute or two later the skiff's head was standing high up, -against the boat's swell, and the voyage was begun. Tom felt happy in -his success, for he knew it was the boat's last trip for the night. At -the end of a long twelve or fifteen minutes the wheels stopped, and Tom -slipped overboard and swam ashore in the dusk, landing fifty yards -downstream, out of danger of possible stragglers. - -He flew along unfrequented alleys, and shortly found himself at his -aunt's back fence. He climbed over, approached the "ell," and looked in -at the sitting-room window, for a light was burning there. There sat -Aunt Polly, Sid, Mary, and Joe Harper's mother, grouped together, -talking. They were by the bed, and the bed was between them and the -door. Tom went to the door and began to softly lift the latch; then he -pressed gently and the door yielded a crack; he continued pushing -cautiously, and quaking every time it creaked, till he judged he might -squeeze through on his knees; so he put his head through and began, -warily. - -"What makes the candle blow so?" said Aunt Polly. Tom hurried up. -"Why, that door's open, I believe. Why, of course it is. No end of -strange things now. Go 'long and shut it, Sid." - -Tom disappeared under the bed just in time. He lay and "breathed" -himself for a time, and then crept to where he could almost touch his -aunt's foot. - -"But as I was saying," said Aunt Polly, "he warn't BAD, so to say ---only mischEEvous. Only just giddy, and harum-scarum, you know. He -warn't any more responsible than a colt. HE never meant any harm, and -he was the best-hearted boy that ever was"--and she began to cry. - -"It was just so with my Joe--always full of his devilment, and up to -every kind of mischief, but he was just as unselfish and kind as he -could be--and laws bless me, to think I went and whipped him for taking -that cream, never once recollecting that I throwed it out myself -because it was sour, and I never to see him again in this world, never, -never, never, poor abused boy!" And Mrs. Harper sobbed as if her heart -would break. - -"I hope Tom's better off where he is," said Sid, "but if he'd been -better in some ways--" - -"SID!" Tom felt the glare of the old lady's eye, though he could not -see it. "Not a word against my Tom, now that he's gone! God'll take -care of HIM--never you trouble YOURself, sir! Oh, Mrs. Harper, I don't -know how to give him up! I don't know how to give him up! He was such a -comfort to me, although he tormented my old heart out of me, 'most." - -"The Lord giveth and the Lord hath taken away--Blessed be the name of -the Lord! But it's so hard--Oh, it's so hard! Only last Saturday my -Joe busted a firecracker right under my nose and I knocked him -sprawling. Little did I know then, how soon--Oh, if it was to do over -again I'd hug him and bless him for it." - -"Yes, yes, yes, I know just how you feel, Mrs. Harper, I know just -exactly how you feel. No longer ago than yesterday noon, my Tom took -and filled the cat full of Pain-killer, and I did think the cretur -would tear the house down. And God forgive me, I cracked Tom's head -with my thimble, poor boy, poor dead boy. But he's out of all his -troubles now. And the last words I ever heard him say was to reproach--" - -But this memory was too much for the old lady, and she broke entirely -down. Tom was snuffling, now, himself--and more in pity of himself than -anybody else. He could hear Mary crying, and putting in a kindly word -for him from time to time. He began to have a nobler opinion of himself -than ever before. Still, he was sufficiently touched by his aunt's -grief to long to rush out from under the bed and overwhelm her with -joy--and the theatrical gorgeousness of the thing appealed strongly to -his nature, too, but he resisted and lay still. - -He went on listening, and gathered by odds and ends that it was -conjectured at first that the boys had got drowned while taking a swim; -then the small raft had been missed; next, certain boys said the -missing lads had promised that the village should "hear something" -soon; the wise-heads had "put this and that together" and decided that -the lads had gone off on that raft and would turn up at the next town -below, presently; but toward noon the raft had been found, lodged -against the Missouri shore some five or six miles below the village ---and then hope perished; they must be drowned, else hunger would have -driven them home by nightfall if not sooner. It was believed that the -search for the bodies had been a fruitless effort merely because the -drowning must have occurred in mid-channel, since the boys, being good -swimmers, would otherwise have escaped to shore. This was Wednesday -night. If the bodies continued missing until Sunday, all hope would be -given over, and the funerals would be preached on that morning. Tom -shuddered. - -Mrs. Harper gave a sobbing good-night and turned to go. Then with a -mutual impulse the two bereaved women flung themselves into each -other's arms and had a good, consoling cry, and then parted. Aunt Polly -was tender far beyond her wont, in her good-night to Sid and Mary. Sid -snuffled a bit and Mary went off crying with all her heart. - -Aunt Polly knelt down and prayed for Tom so touchingly, so -appealingly, and with such measureless love in her words and her old -trembling voice, that he was weltering in tears again, long before she -was through. - -He had to keep still long after she went to bed, for she kept making -broken-hearted ejaculations from time to time, tossing unrestfully, and -turning over. But at last she was still, only moaning a little in her -sleep. Now the boy stole out, rose gradually by the bedside, shaded the -candle-light with his hand, and stood regarding her. His heart was full -of pity for her. He took out his sycamore scroll and placed it by the -candle. But something occurred to him, and he lingered considering. His -face lighted with a happy solution of his thought; he put the bark -hastily in his pocket. Then he bent over and kissed the faded lips, and -straightway made his stealthy exit, latching the door behind him. - -He threaded his way back to the ferry landing, found nobody at large -there, and walked boldly on board the boat, for he knew she was -tenantless except that there was a watchman, who always turned in and -slept like a graven image. He untied the skiff at the stern, slipped -into it, and was soon rowing cautiously upstream. When he had pulled a -mile above the village, he started quartering across and bent himself -stoutly to his work. He hit the landing on the other side neatly, for -this was a familiar bit of work to him. He was moved to capture the -skiff, arguing that it might be considered a ship and therefore -legitimate prey for a pirate, but he knew a thorough search would be -made for it and that might end in revelations. So he stepped ashore and -entered the woods. - -He sat down and took a long rest, torturing himself meanwhile to keep -awake, and then started warily down the home-stretch. The night was far -spent. It was broad daylight before he found himself fairly abreast the -island bar. He rested again until the sun was well up and gilding the -great river with its splendor, and then he plunged into the stream. A -little later he paused, dripping, upon the threshold of the camp, and -heard Joe say: - -"No, Tom's true-blue, Huck, and he'll come back. He won't desert. He -knows that would be a disgrace to a pirate, and Tom's too proud for -that sort of thing. He's up to something or other. Now I wonder what?" - -"Well, the things is ours, anyway, ain't they?" - -"Pretty near, but not yet, Huck. The writing says they are if he ain't -back here to breakfast." - -"Which he is!" exclaimed Tom, with fine dramatic effect, stepping -grandly into camp. - -A sumptuous breakfast of bacon and fish was shortly provided, and as -the boys set to work upon it, Tom recounted (and adorned) his -adventures. They were a vain and boastful company of heroes when the -tale was done. Then Tom hid himself away in a shady nook to sleep till -noon, and the other pirates got ready to fish and explore. - - - -CHAPTER XVI - -AFTER dinner all the gang turned out to hunt for turtle eggs on the -bar. They went about poking sticks into the sand, and when they found a -soft place they went down on their knees and dug with their hands. -Sometimes they would take fifty or sixty eggs out of one hole. They -were perfectly round white things a trifle smaller than an English -walnut. They had a famous fried-egg feast that night, and another on -Friday morning. - -After breakfast they went whooping and prancing out on the bar, and -chased each other round and round, shedding clothes as they went, until -they were naked, and then continued the frolic far away up the shoal -water of the bar, against the stiff current, which latter tripped their -legs from under them from time to time and greatly increased the fun. -And now and then they stooped in a group and splashed water in each -other's faces with their palms, gradually approaching each other, with -averted faces to avoid the strangling sprays, and finally gripping and -struggling till the best man ducked his neighbor, and then they all -went under in a tangle of white legs and arms and came up blowing, -sputtering, laughing, and gasping for breath at one and the same time. - -When they were well exhausted, they would run out and sprawl on the -dry, hot sand, and lie there and cover themselves up with it, and by -and by break for the water again and go through the original -performance once more. Finally it occurred to them that their naked -skin represented flesh-colored "tights" very fairly; so they drew a -ring in the sand and had a circus--with three clowns in it, for none -would yield this proudest post to his neighbor. - -Next they got their marbles and played "knucks" and "ring-taw" and -"keeps" till that amusement grew stale. Then Joe and Huck had another -swim, but Tom would not venture, because he found that in kicking off -his trousers he had kicked his string of rattlesnake rattles off his -ankle, and he wondered how he had escaped cramp so long without the -protection of this mysterious charm. He did not venture again until he -had found it, and by that time the other boys were tired and ready to -rest. They gradually wandered apart, dropped into the "dumps," and fell -to gazing longingly across the wide river to where the village lay -drowsing in the sun. Tom found himself writing "BECKY" in the sand with -his big toe; he scratched it out, and was angry with himself for his -weakness. But he wrote it again, nevertheless; he could not help it. He -erased it once more and then took himself out of temptation by driving -the other boys together and joining them. - -But Joe's spirits had gone down almost beyond resurrection. He was so -homesick that he could hardly endure the misery of it. The tears lay -very near the surface. Huck was melancholy, too. Tom was downhearted, -but tried hard not to show it. He had a secret which he was not ready -to tell, yet, but if this mutinous depression was not broken up soon, -he would have to bring it out. He said, with a great show of -cheerfulness: - -"I bet there's been pirates on this island before, boys. We'll explore -it again. They've hid treasures here somewhere. How'd you feel to light -on a rotten chest full of gold and silver--hey?" - -But it roused only faint enthusiasm, which faded out, with no reply. -Tom tried one or two other seductions; but they failed, too. It was -discouraging work. Joe sat poking up the sand with a stick and looking -very gloomy. Finally he said: - -"Oh, boys, let's give it up. I want to go home. It's so lonesome." - -"Oh no, Joe, you'll feel better by and by," said Tom. "Just think of -the fishing that's here." - -"I don't care for fishing. I want to go home." - -"But, Joe, there ain't such another swimming-place anywhere." - -"Swimming's no good. I don't seem to care for it, somehow, when there -ain't anybody to say I sha'n't go in. I mean to go home." - -"Oh, shucks! Baby! You want to see your mother, I reckon." - -"Yes, I DO want to see my mother--and you would, too, if you had one. -I ain't any more baby than you are." And Joe snuffled a little. - -"Well, we'll let the cry-baby go home to his mother, won't we, Huck? -Poor thing--does it want to see its mother? And so it shall. You like -it here, don't you, Huck? We'll stay, won't we?" - -Huck said, "Y-e-s"--without any heart in it. - -"I'll never speak to you again as long as I live," said Joe, rising. -"There now!" And he moved moodily away and began to dress himself. - -"Who cares!" said Tom. "Nobody wants you to. Go 'long home and get -laughed at. Oh, you're a nice pirate. Huck and me ain't cry-babies. -We'll stay, won't we, Huck? Let him go if he wants to. I reckon we can -get along without him, per'aps." - -But Tom was uneasy, nevertheless, and was alarmed to see Joe go -sullenly on with his dressing. And then it was discomforting to see -Huck eying Joe's preparations so wistfully, and keeping up such an -ominous silence. Presently, without a parting word, Joe began to wade -off toward the Illinois shore. Tom's heart began to sink. He glanced at -Huck. Huck could not bear the look, and dropped his eyes. Then he said: - -"I want to go, too, Tom. It was getting so lonesome anyway, and now -it'll be worse. Let's us go, too, Tom." - -"I won't! You can all go, if you want to. I mean to stay." - -"Tom, I better go." - -"Well, go 'long--who's hendering you." - -Huck began to pick up his scattered clothes. He said: - -"Tom, I wisht you'd come, too. Now you think it over. We'll wait for -you when we get to shore." - -"Well, you'll wait a blame long time, that's all." - -Huck started sorrowfully away, and Tom stood looking after him, with a -strong desire tugging at his heart to yield his pride and go along too. -He hoped the boys would stop, but they still waded slowly on. It -suddenly dawned on Tom that it was become very lonely and still. He -made one final struggle with his pride, and then darted after his -comrades, yelling: - -"Wait! Wait! I want to tell you something!" - -They presently stopped and turned around. When he got to where they -were, he began unfolding his secret, and they listened moodily till at -last they saw the "point" he was driving at, and then they set up a -war-whoop of applause and said it was "splendid!" and said if he had -told them at first, they wouldn't have started away. He made a plausible -excuse; but his real reason had been the fear that not even the secret -would keep them with him any very great length of time, and so he had -meant to hold it in reserve as a last seduction. - -The lads came gayly back and went at their sports again with a will, -chattering all the time about Tom's stupendous plan and admiring the -genius of it. After a dainty egg and fish dinner, Tom said he wanted to -learn to smoke, now. Joe caught at the idea and said he would like to -try, too. So Huck made pipes and filled them. These novices had never -smoked anything before but cigars made of grape-vine, and they "bit" -the tongue, and were not considered manly anyway. - -Now they stretched themselves out on their elbows and began to puff, -charily, and with slender confidence. The smoke had an unpleasant -taste, and they gagged a little, but Tom said: - -"Why, it's just as easy! If I'd a knowed this was all, I'd a learnt -long ago." - -"So would I," said Joe. "It's just nothing." - -"Why, many a time I've looked at people smoking, and thought well I -wish I could do that; but I never thought I could," said Tom. - -"That's just the way with me, hain't it, Huck? You've heard me talk -just that way--haven't you, Huck? I'll leave it to Huck if I haven't." - -"Yes--heaps of times," said Huck. - -"Well, I have too," said Tom; "oh, hundreds of times. Once down by the -slaughter-house. Don't you remember, Huck? Bob Tanner was there, and -Johnny Miller, and Jeff Thatcher, when I said it. Don't you remember, -Huck, 'bout me saying that?" - -"Yes, that's so," said Huck. "That was the day after I lost a white -alley. No, 'twas the day before." - -"There--I told you so," said Tom. "Huck recollects it." - -"I bleeve I could smoke this pipe all day," said Joe. "I don't feel -sick." - -"Neither do I," said Tom. "I could smoke it all day. But I bet you -Jeff Thatcher couldn't." - -"Jeff Thatcher! Why, he'd keel over just with two draws. Just let him -try it once. HE'D see!" - -"I bet he would. And Johnny Miller--I wish could see Johnny Miller -tackle it once." - -"Oh, don't I!" said Joe. "Why, I bet you Johnny Miller couldn't any -more do this than nothing. Just one little snifter would fetch HIM." - -"'Deed it would, Joe. Say--I wish the boys could see us now." - -"So do I." - -"Say--boys, don't say anything about it, and some time when they're -around, I'll come up to you and say, 'Joe, got a pipe? I want a smoke.' -And you'll say, kind of careless like, as if it warn't anything, you'll -say, 'Yes, I got my OLD pipe, and another one, but my tobacker ain't -very good.' And I'll say, 'Oh, that's all right, if it's STRONG -enough.' And then you'll out with the pipes, and we'll light up just as -ca'm, and then just see 'em look!" - -"By jings, that'll be gay, Tom! I wish it was NOW!" - -"So do I! And when we tell 'em we learned when we was off pirating, -won't they wish they'd been along?" - -"Oh, I reckon not! I'll just BET they will!" - -So the talk ran on. But presently it began to flag a trifle, and grow -disjointed. The silences widened; the expectoration marvellously -increased. Every pore inside the boys' cheeks became a spouting -fountain; they could scarcely bail out the cellars under their tongues -fast enough to prevent an inundation; little overflowings down their -throats occurred in spite of all they could do, and sudden retchings -followed every time. Both boys were looking very pale and miserable, -now. Joe's pipe dropped from his nerveless fingers. Tom's followed. -Both fountains were going furiously and both pumps bailing with might -and main. Joe said feebly: - -"I've lost my knife. I reckon I better go and find it." - -Tom said, with quivering lips and halting utterance: - -"I'll help you. You go over that way and I'll hunt around by the -spring. No, you needn't come, Huck--we can find it." - -So Huck sat down again, and waited an hour. Then he found it lonesome, -and went to find his comrades. They were wide apart in the woods, both -very pale, both fast asleep. But something informed him that if they -had had any trouble they had got rid of it. - -They were not talkative at supper that night. They had a humble look, -and when Huck prepared his pipe after the meal and was going to prepare -theirs, they said no, they were not feeling very well--something they -ate at dinner had disagreed with them. - -About midnight Joe awoke, and called the boys. There was a brooding -oppressiveness in the air that seemed to bode something. The boys -huddled themselves together and sought the friendly companionship of -the fire, though the dull dead heat of the breathless atmosphere was -stifling. They sat still, intent and waiting. The solemn hush -continued. Beyond the light of the fire everything was swallowed up in -the blackness of darkness. Presently there came a quivering glow that -vaguely revealed the foliage for a moment and then vanished. By and by -another came, a little stronger. Then another. Then a faint moan came -sighing through the branches of the forest and the boys felt a fleeting -breath upon their cheeks, and shuddered with the fancy that the Spirit -of the Night had gone by. There was a pause. Now a weird flash turned -night into day and showed every little grass-blade, separate and -distinct, that grew about their feet. And it showed three white, -startled faces, too. A deep peal of thunder went rolling and tumbling -down the heavens and lost itself in sullen rumblings in the distance. A -sweep of chilly air passed by, rustling all the leaves and snowing the -flaky ashes broadcast about the fire. Another fierce glare lit up the -forest and an instant crash followed that seemed to rend the tree-tops -right over the boys' heads. They clung together in terror, in the thick -gloom that followed. A few big rain-drops fell pattering upon the -leaves. - -"Quick! boys, go for the tent!" exclaimed Tom. - -They sprang away, stumbling over roots and among vines in the dark, no -two plunging in the same direction. A furious blast roared through the -trees, making everything sing as it went. One blinding flash after -another came, and peal on peal of deafening thunder. And now a -drenching rain poured down and the rising hurricane drove it in sheets -along the ground. The boys cried out to each other, but the roaring -wind and the booming thunder-blasts drowned their voices utterly. -However, one by one they straggled in at last and took shelter under -the tent, cold, scared, and streaming with water; but to have company -in misery seemed something to be grateful for. They could not talk, the -old sail flapped so furiously, even if the other noises would have -allowed them. The tempest rose higher and higher, and presently the -sail tore loose from its fastenings and went winging away on the blast. -The boys seized each others' hands and fled, with many tumblings and -bruises, to the shelter of a great oak that stood upon the river-bank. -Now the battle was at its highest. Under the ceaseless conflagration of -lightning that flamed in the skies, everything below stood out in -clean-cut and shadowless distinctness: the bending trees, the billowy -river, white with foam, the driving spray of spume-flakes, the dim -outlines of the high bluffs on the other side, glimpsed through the -drifting cloud-rack and the slanting veil of rain. Every little while -some giant tree yielded the fight and fell crashing through the younger -growth; and the unflagging thunder-peals came now in ear-splitting -explosive bursts, keen and sharp, and unspeakably appalling. The storm -culminated in one matchless effort that seemed likely to tear the island -to pieces, burn it up, drown it to the tree-tops, blow it away, and -deafen every creature in it, all at one and the same moment. It was a -wild night for homeless young heads to be out in. - -But at last the battle was done, and the forces retired with weaker -and weaker threatenings and grumblings, and peace resumed her sway. The -boys went back to camp, a good deal awed; but they found there was -still something to be thankful for, because the great sycamore, the -shelter of their beds, was a ruin, now, blasted by the lightnings, and -they were not under it when the catastrophe happened. - -Everything in camp was drenched, the camp-fire as well; for they were -but heedless lads, like their generation, and had made no provision -against rain. Here was matter for dismay, for they were soaked through -and chilled. They were eloquent in their distress; but they presently -discovered that the fire had eaten so far up under the great log it had -been built against (where it curved upward and separated itself from -the ground), that a handbreadth or so of it had escaped wetting; so -they patiently wrought until, with shreds and bark gathered from the -under sides of sheltered logs, they coaxed the fire to burn again. Then -they piled on great dead boughs till they had a roaring furnace, and -were glad-hearted once more. They dried their boiled ham and had a -feast, and after that they sat by the fire and expanded and glorified -their midnight adventure until morning, for there was not a dry spot to -sleep on, anywhere around. - -As the sun began to steal in upon the boys, drowsiness came over them, -and they went out on the sandbar and lay down to sleep. They got -scorched out by and by, and drearily set about getting breakfast. After -the meal they felt rusty, and stiff-jointed, and a little homesick once -more. Tom saw the signs, and fell to cheering up the pirates as well as -he could. But they cared nothing for marbles, or circus, or swimming, -or anything. He reminded them of the imposing secret, and raised a ray -of cheer. While it lasted, he got them interested in a new device. This -was to knock off being pirates, for a while, and be Indians for a -change. They were attracted by this idea; so it was not long before -they were stripped, and striped from head to heel with black mud, like -so many zebras--all of them chiefs, of course--and then they went -tearing through the woods to attack an English settlement. - -By and by they separated into three hostile tribes, and darted upon -each other from ambush with dreadful war-whoops, and killed and scalped -each other by thousands. It was a gory day. Consequently it was an -extremely satisfactory one. - -They assembled in camp toward supper-time, hungry and happy; but now a -difficulty arose--hostile Indians could not break the bread of -hospitality together without first making peace, and this was a simple -impossibility without smoking a pipe of peace. There was no other -process that ever they had heard of. Two of the savages almost wished -they had remained pirates. However, there was no other way; so with -such show of cheerfulness as they could muster they called for the pipe -and took their whiff as it passed, in due form. - -And behold, they were glad they had gone into savagery, for they had -gained something; they found that they could now smoke a little without -having to go and hunt for a lost knife; they did not get sick enough to -be seriously uncomfortable. They were not likely to fool away this high -promise for lack of effort. No, they practised cautiously, after -supper, with right fair success, and so they spent a jubilant evening. -They were prouder and happier in their new acquirement than they would -have been in the scalping and skinning of the Six Nations. We will -leave them to smoke and chatter and brag, since we have no further use -for them at present. - - - -CHAPTER XVII - -BUT there was no hilarity in the little town that same tranquil -Saturday afternoon. The Harpers, and Aunt Polly's family, were being -put into mourning, with great grief and many tears. An unusual quiet -possessed the village, although it was ordinarily quiet enough, in all -conscience. The villagers conducted their concerns with an absent air, -and talked little; but they sighed often. The Saturday holiday seemed a -burden to the children. They had no heart in their sports, and -gradually gave them up. - -In the afternoon Becky Thatcher found herself moping about the -deserted schoolhouse yard, and feeling very melancholy. But she found -nothing there to comfort her. She soliloquized: - -"Oh, if I only had a brass andiron-knob again! But I haven't got -anything now to remember him by." And she choked back a little sob. - -Presently she stopped, and said to herself: - -"It was right here. Oh, if it was to do over again, I wouldn't say -that--I wouldn't say it for the whole world. But he's gone now; I'll -never, never, never see him any more." - -This thought broke her down, and she wandered away, with tears rolling -down her cheeks. Then quite a group of boys and girls--playmates of -Tom's and Joe's--came by, and stood looking over the paling fence and -talking in reverent tones of how Tom did so-and-so the last time they -saw him, and how Joe said this and that small trifle (pregnant with -awful prophecy, as they could easily see now!)--and each speaker -pointed out the exact spot where the lost lads stood at the time, and -then added something like "and I was a-standing just so--just as I am -now, and as if you was him--I was as close as that--and he smiled, just -this way--and then something seemed to go all over me, like--awful, you -know--and I never thought what it meant, of course, but I can see now!" - -Then there was a dispute about who saw the dead boys last in life, and -many claimed that dismal distinction, and offered evidences, more or -less tampered with by the witness; and when it was ultimately decided -who DID see the departed last, and exchanged the last words with them, -the lucky parties took upon themselves a sort of sacred importance, and -were gaped at and envied by all the rest. One poor chap, who had no -other grandeur to offer, said with tolerably manifest pride in the -remembrance: - -"Well, Tom Sawyer he licked me once." - -But that bid for glory was a failure. Most of the boys could say that, -and so that cheapened the distinction too much. The group loitered -away, still recalling memories of the lost heroes, in awed voices. - -When the Sunday-school hour was finished, the next morning, the bell -began to toll, instead of ringing in the usual way. It was a very still -Sabbath, and the mournful sound seemed in keeping with the musing hush -that lay upon nature. The villagers began to gather, loitering a moment -in the vestibule to converse in whispers about the sad event. But there -was no whispering in the house; only the funereal rustling of dresses -as the women gathered to their seats disturbed the silence there. None -could remember when the little church had been so full before. There -was finally a waiting pause, an expectant dumbness, and then Aunt Polly -entered, followed by Sid and Mary, and they by the Harper family, all -in deep black, and the whole congregation, the old minister as well, -rose reverently and stood until the mourners were seated in the front -pew. There was another communing silence, broken at intervals by -muffled sobs, and then the minister spread his hands abroad and prayed. -A moving hymn was sung, and the text followed: "I am the Resurrection -and the Life." - -As the service proceeded, the clergyman drew such pictures of the -graces, the winning ways, and the rare promise of the lost lads that -every soul there, thinking he recognized these pictures, felt a pang in -remembering that he had persistently blinded himself to them always -before, and had as persistently seen only faults and flaws in the poor -boys. The minister related many a touching incident in the lives of the -departed, too, which illustrated their sweet, generous natures, and the -people could easily see, now, how noble and beautiful those episodes -were, and remembered with grief that at the time they occurred they had -seemed rank rascalities, well deserving of the cowhide. The -congregation became more and more moved, as the pathetic tale went on, -till at last the whole company broke down and joined the weeping -mourners in a chorus of anguished sobs, the preacher himself giving way -to his feelings, and crying in the pulpit. - -There was a rustle in the gallery, which nobody noticed; a moment -later the church door creaked; the minister raised his streaming eyes -above his handkerchief, and stood transfixed! First one and then -another pair of eyes followed the minister's, and then almost with one -impulse the congregation rose and stared while the three dead boys came -marching up the aisle, Tom in the lead, Joe next, and Huck, a ruin of -drooping rags, sneaking sheepishly in the rear! They had been hid in -the unused gallery listening to their own funeral sermon! - -Aunt Polly, Mary, and the Harpers threw themselves upon their restored -ones, smothered them with kisses and poured out thanksgivings, while -poor Huck stood abashed and uncomfortable, not knowing exactly what to -do or where to hide from so many unwelcoming eyes. He wavered, and -started to slink away, but Tom seized him and said: - -"Aunt Polly, it ain't fair. Somebody's got to be glad to see Huck." - -"And so they shall. I'm glad to see him, poor motherless thing!" And -the loving attentions Aunt Polly lavished upon him were the one thing -capable of making him more uncomfortable than he was before. - -Suddenly the minister shouted at the top of his voice: "Praise God -from whom all blessings flow--SING!--and put your hearts in it!" - -And they did. Old Hundred swelled up with a triumphant burst, and -while it shook the rafters Tom Sawyer the Pirate looked around upon the -envying juveniles about him and confessed in his heart that this was -the proudest moment of his life. - -As the "sold" congregation trooped out they said they would almost be -willing to be made ridiculous again to hear Old Hundred sung like that -once more. - -Tom got more cuffs and kisses that day--according to Aunt Polly's -varying moods--than he had earned before in a year; and he hardly knew -which expressed the most gratefulness to God and affection for himself. - - - -CHAPTER XVIII - -THAT was Tom's great secret--the scheme to return home with his -brother pirates and attend their own funerals. They had paddled over to -the Missouri shore on a log, at dusk on Saturday, landing five or six -miles below the village; they had slept in the woods at the edge of the -town till nearly daylight, and had then crept through back lanes and -alleys and finished their sleep in the gallery of the church among a -chaos of invalided benches. - -At breakfast, Monday morning, Aunt Polly and Mary were very loving to -Tom, and very attentive to his wants. There was an unusual amount of -talk. In the course of it Aunt Polly said: - -"Well, I don't say it wasn't a fine joke, Tom, to keep everybody -suffering 'most a week so you boys had a good time, but it is a pity -you could be so hard-hearted as to let me suffer so. If you could come -over on a log to go to your funeral, you could have come over and give -me a hint some way that you warn't dead, but only run off." - -"Yes, you could have done that, Tom," said Mary; "and I believe you -would if you had thought of it." - -"Would you, Tom?" said Aunt Polly, her face lighting wistfully. "Say, -now, would you, if you'd thought of it?" - -"I--well, I don't know. 'Twould 'a' spoiled everything." - -"Tom, I hoped you loved me that much," said Aunt Polly, with a grieved -tone that discomforted the boy. "It would have been something if you'd -cared enough to THINK of it, even if you didn't DO it." - -"Now, auntie, that ain't any harm," pleaded Mary; "it's only Tom's -giddy way--he is always in such a rush that he never thinks of -anything." - -"More's the pity. Sid would have thought. And Sid would have come and -DONE it, too. Tom, you'll look back, some day, when it's too late, and -wish you'd cared a little more for me when it would have cost you so -little." - -"Now, auntie, you know I do care for you," said Tom. - -"I'd know it better if you acted more like it." - -"I wish now I'd thought," said Tom, with a repentant tone; "but I -dreamt about you, anyway. That's something, ain't it?" - -"It ain't much--a cat does that much--but it's better than nothing. -What did you dream?" - -"Why, Wednesday night I dreamt that you was sitting over there by the -bed, and Sid was sitting by the woodbox, and Mary next to him." - -"Well, so we did. So we always do. I'm glad your dreams could take -even that much trouble about us." - -"And I dreamt that Joe Harper's mother was here." - -"Why, she was here! Did you dream any more?" - -"Oh, lots. But it's so dim, now." - -"Well, try to recollect--can't you?" - -"Somehow it seems to me that the wind--the wind blowed the--the--" - -"Try harder, Tom! The wind did blow something. Come!" - -Tom pressed his fingers on his forehead an anxious minute, and then -said: - -"I've got it now! I've got it now! It blowed the candle!" - -"Mercy on us! Go on, Tom--go on!" - -"And it seems to me that you said, 'Why, I believe that that door--'" - -"Go ON, Tom!" - -"Just let me study a moment--just a moment. Oh, yes--you said you -believed the door was open." - -"As I'm sitting here, I did! Didn't I, Mary! Go on!" - -"And then--and then--well I won't be certain, but it seems like as if -you made Sid go and--and--" - -"Well? Well? What did I make him do, Tom? What did I make him do?" - -"You made him--you--Oh, you made him shut it." - -"Well, for the land's sake! I never heard the beat of that in all my -days! Don't tell ME there ain't anything in dreams, any more. Sereny -Harper shall know of this before I'm an hour older. I'd like to see her -get around THIS with her rubbage 'bout superstition. Go on, Tom!" - -"Oh, it's all getting just as bright as day, now. Next you said I -warn't BAD, only mischeevous and harum-scarum, and not any more -responsible than--than--I think it was a colt, or something." - -"And so it was! Well, goodness gracious! Go on, Tom!" - -"And then you began to cry." - -"So I did. So I did. Not the first time, neither. And then--" - -"Then Mrs. Harper she began to cry, and said Joe was just the same, -and she wished she hadn't whipped him for taking cream when she'd -throwed it out her own self--" - -"Tom! The sperrit was upon you! You was a prophesying--that's what you -was doing! Land alive, go on, Tom!" - -"Then Sid he said--he said--" - -"I don't think I said anything," said Sid. - -"Yes you did, Sid," said Mary. - -"Shut your heads and let Tom go on! What did he say, Tom?" - -"He said--I THINK he said he hoped I was better off where I was gone -to, but if I'd been better sometimes--" - -"THERE, d'you hear that! It was his very words!" - -"And you shut him up sharp." - -"I lay I did! There must 'a' been an angel there. There WAS an angel -there, somewheres!" - -"And Mrs. Harper told about Joe scaring her with a firecracker, and -you told about Peter and the Painkiller--" - -"Just as true as I live!" - -"And then there was a whole lot of talk 'bout dragging the river for -us, and 'bout having the funeral Sunday, and then you and old Miss -Harper hugged and cried, and she went." - -"It happened just so! It happened just so, as sure as I'm a-sitting in -these very tracks. Tom, you couldn't told it more like if you'd 'a' -seen it! And then what? Go on, Tom!" - -"Then I thought you prayed for me--and I could see you and hear every -word you said. And you went to bed, and I was so sorry that I took and -wrote on a piece of sycamore bark, 'We ain't dead--we are only off -being pirates,' and put it on the table by the candle; and then you -looked so good, laying there asleep, that I thought I went and leaned -over and kissed you on the lips." - -"Did you, Tom, DID you! I just forgive you everything for that!" And -she seized the boy in a crushing embrace that made him feel like the -guiltiest of villains. - -"It was very kind, even though it was only a--dream," Sid soliloquized -just audibly. - -"Shut up, Sid! A body does just the same in a dream as he'd do if he -was awake. Here's a big Milum apple I've been saving for you, Tom, if -you was ever found again--now go 'long to school. I'm thankful to the -good God and Father of us all I've got you back, that's long-suffering -and merciful to them that believe on Him and keep His word, though -goodness knows I'm unworthy of it, but if only the worthy ones got His -blessings and had His hand to help them over the rough places, there's -few enough would smile here or ever enter into His rest when the long -night comes. Go 'long Sid, Mary, Tom--take yourselves off--you've -hendered me long enough." - -The children left for school, and the old lady to call on Mrs. Harper -and vanquish her realism with Tom's marvellous dream. Sid had better -judgment than to utter the thought that was in his mind as he left the -house. It was this: "Pretty thin--as long a dream as that, without any -mistakes in it!" - -What a hero Tom was become, now! He did not go skipping and prancing, -but moved with a dignified swagger as became a pirate who felt that the -public eye was on him. And indeed it was; he tried not to seem to see -the looks or hear the remarks as he passed along, but they were food -and drink to him. Smaller boys than himself flocked at his heels, as -proud to be seen with him, and tolerated by him, as if he had been the -drummer at the head of a procession or the elephant leading a menagerie -into town. Boys of his own size pretended not to know he had been away -at all; but they were consuming with envy, nevertheless. They would -have given anything to have that swarthy suntanned skin of his, and his -glittering notoriety; and Tom would not have parted with either for a -circus. - -At school the children made so much of him and of Joe, and delivered -such eloquent admiration from their eyes, that the two heroes were not -long in becoming insufferably "stuck-up." They began to tell their -adventures to hungry listeners--but they only began; it was not a thing -likely to have an end, with imaginations like theirs to furnish -material. And finally, when they got out their pipes and went serenely -puffing around, the very summit of glory was reached. - -Tom decided that he could be independent of Becky Thatcher now. Glory -was sufficient. He would live for glory. Now that he was distinguished, -maybe she would be wanting to "make up." Well, let her--she should see -that he could be as indifferent as some other people. Presently she -arrived. Tom pretended not to see her. He moved away and joined a group -of boys and girls and began to talk. Soon he observed that she was -tripping gayly back and forth with flushed face and dancing eyes, -pretending to be busy chasing schoolmates, and screaming with laughter -when she made a capture; but he noticed that she always made her -captures in his vicinity, and that she seemed to cast a conscious eye -in his direction at such times, too. It gratified all the vicious -vanity that was in him; and so, instead of winning him, it only "set -him up" the more and made him the more diligent to avoid betraying that -he knew she was about. Presently she gave over skylarking, and moved -irresolutely about, sighing once or twice and glancing furtively and -wistfully toward Tom. Then she observed that now Tom was talking more -particularly to Amy Lawrence than to any one else. She felt a sharp -pang and grew disturbed and uneasy at once. She tried to go away, but -her feet were treacherous, and carried her to the group instead. She -said to a girl almost at Tom's elbow--with sham vivacity: - -"Why, Mary Austin! you bad girl, why didn't you come to Sunday-school?" - -"I did come--didn't you see me?" - -"Why, no! Did you? Where did you sit?" - -"I was in Miss Peters' class, where I always go. I saw YOU." - -"Did you? Why, it's funny I didn't see you. I wanted to tell you about -the picnic." - -"Oh, that's jolly. Who's going to give it?" - -"My ma's going to let me have one." - -"Oh, goody; I hope she'll let ME come." - -"Well, she will. The picnic's for me. She'll let anybody come that I -want, and I want you." - -"That's ever so nice. When is it going to be?" - -"By and by. Maybe about vacation." - -"Oh, won't it be fun! You going to have all the girls and boys?" - -"Yes, every one that's friends to me--or wants to be"; and she glanced -ever so furtively at Tom, but he talked right along to Amy Lawrence -about the terrible storm on the island, and how the lightning tore the -great sycamore tree "all to flinders" while he was "standing within -three feet of it." - -"Oh, may I come?" said Grace Miller. - -"Yes." - -"And me?" said Sally Rogers. - -"Yes." - -"And me, too?" said Susy Harper. "And Joe?" - -"Yes." - -And so on, with clapping of joyful hands till all the group had begged -for invitations but Tom and Amy. Then Tom turned coolly away, still -talking, and took Amy with him. Becky's lips trembled and the tears -came to her eyes; she hid these signs with a forced gayety and went on -chattering, but the life had gone out of the picnic, now, and out of -everything else; she got away as soon as she could and hid herself and -had what her sex call "a good cry." Then she sat moody, with wounded -pride, till the bell rang. She roused up, now, with a vindictive cast -in her eye, and gave her plaited tails a shake and said she knew what -SHE'D do. - -At recess Tom continued his flirtation with Amy with jubilant -self-satisfaction. And he kept drifting about to find Becky and lacerate -her with the performance. At last he spied her, but there was a sudden -falling of his mercury. She was sitting cosily on a little bench behind -the schoolhouse looking at a picture-book with Alfred Temple--and so -absorbed were they, and their heads so close together over the book, -that they did not seem to be conscious of anything in the world besides. -Jealousy ran red-hot through Tom's veins. He began to hate himself for -throwing away the chance Becky had offered for a reconciliation. He -called himself a fool, and all the hard names he could think of. He -wanted to cry with vexation. Amy chatted happily along, as they walked, -for her heart was singing, but Tom's tongue had lost its function. He -did not hear what Amy was saying, and whenever she paused expectantly he -could only stammer an awkward assent, which was as often misplaced as -otherwise. He kept drifting to the rear of the schoolhouse, again and -again, to sear his eyeballs with the hateful spectacle there. He could -not help it. And it maddened him to see, as he thought he saw, that -Becky Thatcher never once suspected that he was even in the land of the -living. But she did see, nevertheless; and she knew she was winning her -fight, too, and was glad to see him suffer as she had suffered. - -Amy's happy prattle became intolerable. Tom hinted at things he had to -attend to; things that must be done; and time was fleeting. But in -vain--the girl chirped on. Tom thought, "Oh, hang her, ain't I ever -going to get rid of her?" At last he must be attending to those -things--and she said artlessly that she would be "around" when school -let out. And he hastened away, hating her for it. - -"Any other boy!" Tom thought, grating his teeth. "Any boy in the whole -town but that Saint Louis smarty that thinks he dresses so fine and is -aristocracy! Oh, all right, I licked you the first day you ever saw -this town, mister, and I'll lick you again! You just wait till I catch -you out! I'll just take and--" - -And he went through the motions of thrashing an imaginary boy ---pummelling the air, and kicking and gouging. "Oh, you do, do you? You -holler 'nough, do you? Now, then, let that learn you!" And so the -imaginary flogging was finished to his satisfaction. - -Tom fled home at noon. His conscience could not endure any more of -Amy's grateful happiness, and his jealousy could bear no more of the -other distress. Becky resumed her picture inspections with Alfred, but -as the minutes dragged along and no Tom came to suffer, her triumph -began to cloud and she lost interest; gravity and absent-mindedness -followed, and then melancholy; two or three times she pricked up her -ear at a footstep, but it was a false hope; no Tom came. At last she -grew entirely miserable and wished she hadn't carried it so far. When -poor Alfred, seeing that he was losing her, he did not know how, kept -exclaiming: "Oh, here's a jolly one! look at this!" she lost patience -at last, and said, "Oh, don't bother me! I don't care for them!" and -burst into tears, and got up and walked away. - -Alfred dropped alongside and was going to try to comfort her, but she -said: - -"Go away and leave me alone, can't you! I hate you!" - -So the boy halted, wondering what he could have done--for she had said -she would look at pictures all through the nooning--and she walked on, -crying. Then Alfred went musing into the deserted schoolhouse. He was -humiliated and angry. He easily guessed his way to the truth--the girl -had simply made a convenience of him to vent her spite upon Tom Sawyer. -He was far from hating Tom the less when this thought occurred to him. -He wished there was some way to get that boy into trouble without much -risk to himself. Tom's spelling-book fell under his eye. Here was his -opportunity. He gratefully opened to the lesson for the afternoon and -poured ink upon the page. - -Becky, glancing in at a window behind him at the moment, saw the act, -and moved on, without discovering herself. She started homeward, now, -intending to find Tom and tell him; Tom would be thankful and their -troubles would be healed. Before she was half way home, however, she -had changed her mind. The thought of Tom's treatment of her when she -was talking about her picnic came scorching back and filled her with -shame. She resolved to let him get whipped on the damaged -spelling-book's account, and to hate him forever, into the bargain. - - - -CHAPTER XIX - -TOM arrived at home in a dreary mood, and the first thing his aunt -said to him showed him that he had brought his sorrows to an -unpromising market: - -"Tom, I've a notion to skin you alive!" - -"Auntie, what have I done?" - -"Well, you've done enough. Here I go over to Sereny Harper, like an -old softy, expecting I'm going to make her believe all that rubbage -about that dream, when lo and behold you she'd found out from Joe that -you was over here and heard all the talk we had that night. Tom, I -don't know what is to become of a boy that will act like that. It makes -me feel so bad to think you could let me go to Sereny Harper and make -such a fool of myself and never say a word." - -This was a new aspect of the thing. His smartness of the morning had -seemed to Tom a good joke before, and very ingenious. It merely looked -mean and shabby now. He hung his head and could not think of anything -to say for a moment. Then he said: - -"Auntie, I wish I hadn't done it--but I didn't think." - -"Oh, child, you never think. You never think of anything but your own -selfishness. You could think to come all the way over here from -Jackson's Island in the night to laugh at our troubles, and you could -think to fool me with a lie about a dream; but you couldn't ever think -to pity us and save us from sorrow." - -"Auntie, I know now it was mean, but I didn't mean to be mean. I -didn't, honest. And besides, I didn't come over here to laugh at you -that night." - -"What did you come for, then?" - -"It was to tell you not to be uneasy about us, because we hadn't got -drownded." - -"Tom, Tom, I would be the thankfullest soul in this world if I could -believe you ever had as good a thought as that, but you know you never -did--and I know it, Tom." - -"Indeed and 'deed I did, auntie--I wish I may never stir if I didn't." - -"Oh, Tom, don't lie--don't do it. It only makes things a hundred times -worse." - -"It ain't a lie, auntie; it's the truth. I wanted to keep you from -grieving--that was all that made me come." - -"I'd give the whole world to believe that--it would cover up a power -of sins, Tom. I'd 'most be glad you'd run off and acted so bad. But it -ain't reasonable; because, why didn't you tell me, child?" - -"Why, you see, when you got to talking about the funeral, I just got -all full of the idea of our coming and hiding in the church, and I -couldn't somehow bear to spoil it. So I just put the bark back in my -pocket and kept mum." - -"What bark?" - -"The bark I had wrote on to tell you we'd gone pirating. I wish, now, -you'd waked up when I kissed you--I do, honest." - -The hard lines in his aunt's face relaxed and a sudden tenderness -dawned in her eyes. - -"DID you kiss me, Tom?" - -"Why, yes, I did." - -"Are you sure you did, Tom?" - -"Why, yes, I did, auntie--certain sure." - -"What did you kiss me for, Tom?" - -"Because I loved you so, and you laid there moaning and I was so sorry." - -The words sounded like truth. The old lady could not hide a tremor in -her voice when she said: - -"Kiss me again, Tom!--and be off with you to school, now, and don't -bother me any more." - -The moment he was gone, she ran to a closet and got out the ruin of a -jacket which Tom had gone pirating in. Then she stopped, with it in her -hand, and said to herself: - -"No, I don't dare. Poor boy, I reckon he's lied about it--but it's a -blessed, blessed lie, there's such a comfort come from it. I hope the -Lord--I KNOW the Lord will forgive him, because it was such -goodheartedness in him to tell it. But I don't want to find out it's a -lie. I won't look." - -She put the jacket away, and stood by musing a minute. Twice she put -out her hand to take the garment again, and twice she refrained. Once -more she ventured, and this time she fortified herself with the -thought: "It's a good lie--it's a good lie--I won't let it grieve me." -So she sought the jacket pocket. A moment later she was reading Tom's -piece of bark through flowing tears and saying: "I could forgive the -boy, now, if he'd committed a million sins!" - - - -CHAPTER XX - -THERE was something about Aunt Polly's manner, when she kissed Tom, -that swept away his low spirits and made him lighthearted and happy -again. He started to school and had the luck of coming upon Becky -Thatcher at the head of Meadow Lane. His mood always determined his -manner. Without a moment's hesitation he ran to her and said: - -"I acted mighty mean to-day, Becky, and I'm so sorry. I won't ever, -ever do that way again, as long as ever I live--please make up, won't -you?" - -The girl stopped and looked him scornfully in the face: - -"I'll thank you to keep yourself TO yourself, Mr. Thomas Sawyer. I'll -never speak to you again." - -She tossed her head and passed on. Tom was so stunned that he had not -even presence of mind enough to say "Who cares, Miss Smarty?" until the -right time to say it had gone by. So he said nothing. But he was in a -fine rage, nevertheless. He moped into the schoolyard wishing she were -a boy, and imagining how he would trounce her if she were. He presently -encountered her and delivered a stinging remark as he passed. She -hurled one in return, and the angry breach was complete. It seemed to -Becky, in her hot resentment, that she could hardly wait for school to -"take in," she was so impatient to see Tom flogged for the injured -spelling-book. If she had had any lingering notion of exposing Alfred -Temple, Tom's offensive fling had driven it entirely away. - -Poor girl, she did not know how fast she was nearing trouble herself. -The master, Mr. Dobbins, had reached middle age with an unsatisfied -ambition. The darling of his desires was, to be a doctor, but poverty -had decreed that he should be nothing higher than a village -schoolmaster. Every day he took a mysterious book out of his desk and -absorbed himself in it at times when no classes were reciting. He kept -that book under lock and key. There was not an urchin in school but was -perishing to have a glimpse of it, but the chance never came. Every boy -and girl had a theory about the nature of that book; but no two -theories were alike, and there was no way of getting at the facts in -the case. Now, as Becky was passing by the desk, which stood near the -door, she noticed that the key was in the lock! It was a precious -moment. She glanced around; found herself alone, and the next instant -she had the book in her hands. The title-page--Professor Somebody's -ANATOMY--carried no information to her mind; so she began to turn the -leaves. She came at once upon a handsomely engraved and colored -frontispiece--a human figure, stark naked. At that moment a shadow fell -on the page and Tom Sawyer stepped in at the door and caught a glimpse -of the picture. Becky snatched at the book to close it, and had the -hard luck to tear the pictured page half down the middle. She thrust -the volume into the desk, turned the key, and burst out crying with -shame and vexation. - -"Tom Sawyer, you are just as mean as you can be, to sneak up on a -person and look at what they're looking at." - -"How could I know you was looking at anything?" - -"You ought to be ashamed of yourself, Tom Sawyer; you know you're -going to tell on me, and oh, what shall I do, what shall I do! I'll be -whipped, and I never was whipped in school." - -Then she stamped her little foot and said: - -"BE so mean if you want to! I know something that's going to happen. -You just wait and you'll see! Hateful, hateful, hateful!"--and she -flung out of the house with a new explosion of crying. - -Tom stood still, rather flustered by this onslaught. Presently he said -to himself: - -"What a curious kind of a fool a girl is! Never been licked in school! -Shucks! What's a licking! That's just like a girl--they're so -thin-skinned and chicken-hearted. Well, of course I ain't going to tell -old Dobbins on this little fool, because there's other ways of getting -even on her, that ain't so mean; but what of it? Old Dobbins will ask -who it was tore his book. Nobody'll answer. Then he'll do just the way -he always does--ask first one and then t'other, and when he comes to the -right girl he'll know it, without any telling. Girls' faces always tell -on them. They ain't got any backbone. She'll get licked. Well, it's a -kind of a tight place for Becky Thatcher, because there ain't any way -out of it." Tom conned the thing a moment longer, and then added: "All -right, though; she'd like to see me in just such a fix--let her sweat it -out!" - -Tom joined the mob of skylarking scholars outside. In a few moments -the master arrived and school "took in." Tom did not feel a strong -interest in his studies. Every time he stole a glance at the girls' -side of the room Becky's face troubled him. Considering all things, he -did not want to pity her, and yet it was all he could do to help it. He -could get up no exultation that was really worthy the name. Presently -the spelling-book discovery was made, and Tom's mind was entirely full -of his own matters for a while after that. Becky roused up from her -lethargy of distress and showed good interest in the proceedings. She -did not expect that Tom could get out of his trouble by denying that he -spilt the ink on the book himself; and she was right. The denial only -seemed to make the thing worse for Tom. Becky supposed she would be -glad of that, and she tried to believe she was glad of it, but she -found she was not certain. When the worst came to the worst, she had an -impulse to get up and tell on Alfred Temple, but she made an effort and -forced herself to keep still--because, said she to herself, "he'll tell -about me tearing the picture sure. I wouldn't say a word, not to save -his life!" - -Tom took his whipping and went back to his seat not at all -broken-hearted, for he thought it was possible that he had unknowingly -upset the ink on the spelling-book himself, in some skylarking bout--he -had denied it for form's sake and because it was custom, and had stuck -to the denial from principle. - -A whole hour drifted by, the master sat nodding in his throne, the air -was drowsy with the hum of study. By and by, Mr. Dobbins straightened -himself up, yawned, then unlocked his desk, and reached for his book, -but seemed undecided whether to take it out or leave it. Most of the -pupils glanced up languidly, but there were two among them that watched -his movements with intent eyes. Mr. Dobbins fingered his book absently -for a while, then took it out and settled himself in his chair to read! -Tom shot a glance at Becky. He had seen a hunted and helpless rabbit -look as she did, with a gun levelled at its head. Instantly he forgot -his quarrel with her. Quick--something must be done! done in a flash, -too! But the very imminence of the emergency paralyzed his invention. -Good!--he had an inspiration! He would run and snatch the book, spring -through the door and fly. But his resolution shook for one little -instant, and the chance was lost--the master opened the volume. If Tom -only had the wasted opportunity back again! Too late. There was no help -for Becky now, he said. The next moment the master faced the school. -Every eye sank under his gaze. There was that in it which smote even -the innocent with fear. There was silence while one might count ten ---the master was gathering his wrath. Then he spoke: "Who tore this book?" - -There was not a sound. One could have heard a pin drop. The stillness -continued; the master searched face after face for signs of guilt. - -"Benjamin Rogers, did you tear this book?" - -A denial. Another pause. - -"Joseph Harper, did you?" - -Another denial. Tom's uneasiness grew more and more intense under the -slow torture of these proceedings. The master scanned the ranks of -boys--considered a while, then turned to the girls: - -"Amy Lawrence?" - -A shake of the head. - -"Gracie Miller?" - -The same sign. - -"Susan Harper, did you do this?" - -Another negative. The next girl was Becky Thatcher. Tom was trembling -from head to foot with excitement and a sense of the hopelessness of -the situation. - -"Rebecca Thatcher" [Tom glanced at her face--it was white with terror] ---"did you tear--no, look me in the face" [her hands rose in appeal] ---"did you tear this book?" - -A thought shot like lightning through Tom's brain. He sprang to his -feet and shouted--"I done it!" - -The school stared in perplexity at this incredible folly. Tom stood a -moment, to gather his dismembered faculties; and when he stepped -forward to go to his punishment the surprise, the gratitude, the -adoration that shone upon him out of poor Becky's eyes seemed pay -enough for a hundred floggings. Inspired by the splendor of his own -act, he took without an outcry the most merciless flaying that even Mr. -Dobbins had ever administered; and also received with indifference the -added cruelty of a command to remain two hours after school should be -dismissed--for he knew who would wait for him outside till his -captivity was done, and not count the tedious time as loss, either. - -Tom went to bed that night planning vengeance against Alfred Temple; -for with shame and repentance Becky had told him all, not forgetting -her own treachery; but even the longing for vengeance had to give way, -soon, to pleasanter musings, and he fell asleep at last with Becky's -latest words lingering dreamily in his ear-- - -"Tom, how COULD you be so noble!" - - - -CHAPTER XXI - -VACATION was approaching. The schoolmaster, always severe, grew -severer and more exacting than ever, for he wanted the school to make a -good showing on "Examination" day. His rod and his ferule were seldom -idle now--at least among the smaller pupils. Only the biggest boys, and -young ladies of eighteen and twenty, escaped lashing. Mr. Dobbins' -lashings were very vigorous ones, too; for although he carried, under -his wig, a perfectly bald and shiny head, he had only reached middle -age, and there was no sign of feebleness in his muscle. As the great -day approached, all the tyranny that was in him came to the surface; he -seemed to take a vindictive pleasure in punishing the least -shortcomings. The consequence was, that the smaller boys spent their -days in terror and suffering and their nights in plotting revenge. They -threw away no opportunity to do the master a mischief. But he kept -ahead all the time. The retribution that followed every vengeful -success was so sweeping and majestic that the boys always retired from -the field badly worsted. At last they conspired together and hit upon a -plan that promised a dazzling victory. They swore in the sign-painter's -boy, told him the scheme, and asked his help. He had his own reasons -for being delighted, for the master boarded in his father's family and -had given the boy ample cause to hate him. The master's wife would go -on a visit to the country in a few days, and there would be nothing to -interfere with the plan; the master always prepared himself for great -occasions by getting pretty well fuddled, and the sign-painter's boy -said that when the dominie had reached the proper condition on -Examination Evening he would "manage the thing" while he napped in his -chair; then he would have him awakened at the right time and hurried -away to school. - -In the fulness of time the interesting occasion arrived. At eight in -the evening the schoolhouse was brilliantly lighted, and adorned with -wreaths and festoons of foliage and flowers. The master sat throned in -his great chair upon a raised platform, with his blackboard behind him. -He was looking tolerably mellow. Three rows of benches on each side and -six rows in front of him were occupied by the dignitaries of the town -and by the parents of the pupils. To his left, back of the rows of -citizens, was a spacious temporary platform upon which were seated the -scholars who were to take part in the exercises of the evening; rows of -small boys, washed and dressed to an intolerable state of discomfort; -rows of gawky big boys; snowbanks of girls and young ladies clad in -lawn and muslin and conspicuously conscious of their bare arms, their -grandmothers' ancient trinkets, their bits of pink and blue ribbon and -the flowers in their hair. All the rest of the house was filled with -non-participating scholars. - -The exercises began. A very little boy stood up and sheepishly -recited, "You'd scarce expect one of my age to speak in public on the -stage," etc.--accompanying himself with the painfully exact and -spasmodic gestures which a machine might have used--supposing the -machine to be a trifle out of order. But he got through safely, though -cruelly scared, and got a fine round of applause when he made his -manufactured bow and retired. - -A little shamefaced girl lisped, "Mary had a little lamb," etc., -performed a compassion-inspiring curtsy, got her meed of applause, and -sat down flushed and happy. - -Tom Sawyer stepped forward with conceited confidence and soared into -the unquenchable and indestructible "Give me liberty or give me death" -speech, with fine fury and frantic gesticulation, and broke down in the -middle of it. A ghastly stage-fright seized him, his legs quaked under -him and he was like to choke. True, he had the manifest sympathy of the -house but he had the house's silence, too, which was even worse than -its sympathy. The master frowned, and this completed the disaster. Tom -struggled awhile and then retired, utterly defeated. There was a weak -attempt at applause, but it died early. - -"The Boy Stood on the Burning Deck" followed; also "The Assyrian Came -Down," and other declamatory gems. Then there were reading exercises, -and a spelling fight. The meagre Latin class recited with honor. The -prime feature of the evening was in order, now--original "compositions" -by the young ladies. Each in her turn stepped forward to the edge of -the platform, cleared her throat, held up her manuscript (tied with -dainty ribbon), and proceeded to read, with labored attention to -"expression" and punctuation. The themes were the same that had been -illuminated upon similar occasions by their mothers before them, their -grandmothers, and doubtless all their ancestors in the female line -clear back to the Crusades. "Friendship" was one; "Memories of Other -Days"; "Religion in History"; "Dream Land"; "The Advantages of -Culture"; "Forms of Political Government Compared and Contrasted"; -"Melancholy"; "Filial Love"; "Heart Longings," etc., etc. - -A prevalent feature in these compositions was a nursed and petted -melancholy; another was a wasteful and opulent gush of "fine language"; -another was a tendency to lug in by the ears particularly prized words -and phrases until they were worn entirely out; and a peculiarity that -conspicuously marked and marred them was the inveterate and intolerable -sermon that wagged its crippled tail at the end of each and every one -of them. No matter what the subject might be, a brain-racking effort -was made to squirm it into some aspect or other that the moral and -religious mind could contemplate with edification. The glaring -insincerity of these sermons was not sufficient to compass the -banishment of the fashion from the schools, and it is not sufficient -to-day; it never will be sufficient while the world stands, perhaps. -There is no school in all our land where the young ladies do not feel -obliged to close their compositions with a sermon; and you will find -that the sermon of the most frivolous and the least religious girl in -the school is always the longest and the most relentlessly pious. But -enough of this. Homely truth is unpalatable. - -Let us return to the "Examination." The first composition that was -read was one entitled "Is this, then, Life?" Perhaps the reader can -endure an extract from it: - - "In the common walks of life, with what delightful - emotions does the youthful mind look forward to some - anticipated scene of festivity! Imagination is busy - sketching rose-tinted pictures of joy. In fancy, the - voluptuous votary of fashion sees herself amid the - festive throng, 'the observed of all observers.' Her - graceful form, arrayed in snowy robes, is whirling - through the mazes of the joyous dance; her eye is - brightest, her step is lightest in the gay assembly. - - "In such delicious fancies time quickly glides by, - and the welcome hour arrives for her entrance into - the Elysian world, of which she has had such bright - dreams. How fairy-like does everything appear to - her enchanted vision! Each new scene is more charming - than the last. But after a while she finds that - beneath this goodly exterior, all is vanity, the - flattery which once charmed her soul, now grates - harshly upon her ear; the ball-room has lost its - charms; and with wasted health and imbittered heart, - she turns away with the conviction that earthly - pleasures cannot satisfy the longings of the soul!" - -And so forth and so on. There was a buzz of gratification from time to -time during the reading, accompanied by whispered ejaculations of "How -sweet!" "How eloquent!" "So true!" etc., and after the thing had closed -with a peculiarly afflicting sermon the applause was enthusiastic. - -Then arose a slim, melancholy girl, whose face had the "interesting" -paleness that comes of pills and indigestion, and read a "poem." Two -stanzas of it will do: - - "A MISSOURI MAIDEN'S FAREWELL TO ALABAMA - - "Alabama, good-bye! I love thee well! - But yet for a while do I leave thee now! - Sad, yes, sad thoughts of thee my heart doth swell, - And burning recollections throng my brow! - For I have wandered through thy flowery woods; - Have roamed and read near Tallapoosa's stream; - Have listened to Tallassee's warring floods, - And wooed on Coosa's side Aurora's beam. - - "Yet shame I not to bear an o'er-full heart, - Nor blush to turn behind my tearful eyes; - 'Tis from no stranger land I now must part, - 'Tis to no strangers left I yield these sighs. - Welcome and home were mine within this State, - Whose vales I leave--whose spires fade fast from me - And cold must be mine eyes, and heart, and tete, - When, dear Alabama! they turn cold on thee!" - -There were very few there who knew what "tete" meant, but the poem was -very satisfactory, nevertheless. - -Next appeared a dark-complexioned, black-eyed, black-haired young -lady, who paused an impressive moment, assumed a tragic expression, and -began to read in a measured, solemn tone: - - "A VISION - - "Dark and tempestuous was night. Around the - throne on high not a single star quivered; but - the deep intonations of the heavy thunder - constantly vibrated upon the ear; whilst the - terrific lightning revelled in angry mood - through the cloudy chambers of heaven, seeming - to scorn the power exerted over its terror by - the illustrious Franklin! Even the boisterous - winds unanimously came forth from their mystic - homes, and blustered about as if to enhance by - their aid the wildness of the scene. - - "At such a time, so dark, so dreary, for human - sympathy my very spirit sighed; but instead thereof, - - "'My dearest friend, my counsellor, my comforter - and guide--My joy in grief, my second bliss - in joy,' came to my side. She moved like one of - those bright beings pictured in the sunny walks - of fancy's Eden by the romantic and young, a - queen of beauty unadorned save by her own - transcendent loveliness. So soft was her step, it - failed to make even a sound, and but for the - magical thrill imparted by her genial touch, as - other unobtrusive beauties, she would have glided - away un-perceived--unsought. A strange sadness - rested upon her features, like icy tears upon - the robe of December, as she pointed to the - contending elements without, and bade me contemplate - the two beings presented." - -This nightmare occupied some ten pages of manuscript and wound up with -a sermon so destructive of all hope to non-Presbyterians that it took -the first prize. This composition was considered to be the very finest -effort of the evening. The mayor of the village, in delivering the -prize to the author of it, made a warm speech in which he said that it -was by far the most "eloquent" thing he had ever listened to, and that -Daniel Webster himself might well be proud of it. - -It may be remarked, in passing, that the number of compositions in -which the word "beauteous" was over-fondled, and human experience -referred to as "life's page," was up to the usual average. - -Now the master, mellow almost to the verge of geniality, put his chair -aside, turned his back to the audience, and began to draw a map of -America on the blackboard, to exercise the geography class upon. But he -made a sad business of it with his unsteady hand, and a smothered -titter rippled over the house. He knew what the matter was, and set -himself to right it. He sponged out lines and remade them; but he only -distorted them more than ever, and the tittering was more pronounced. -He threw his entire attention upon his work, now, as if determined not -to be put down by the mirth. He felt that all eyes were fastened upon -him; he imagined he was succeeding, and yet the tittering continued; it -even manifestly increased. And well it might. There was a garret above, -pierced with a scuttle over his head; and down through this scuttle -came a cat, suspended around the haunches by a string; she had a rag -tied about her head and jaws to keep her from mewing; as she slowly -descended she curved upward and clawed at the string, she swung -downward and clawed at the intangible air. The tittering rose higher -and higher--the cat was within six inches of the absorbed teacher's -head--down, down, a little lower, and she grabbed his wig with her -desperate claws, clung to it, and was snatched up into the garret in an -instant with her trophy still in her possession! And how the light did -blaze abroad from the master's bald pate--for the sign-painter's boy -had GILDED it! - -That broke up the meeting. The boys were avenged. Vacation had come. - - NOTE:--The pretended "compositions" quoted in - this chapter are taken without alteration from a - volume entitled "Prose and Poetry, by a Western - Lady"--but they are exactly and precisely after - the schoolgirl pattern, and hence are much - happier than any mere imitations could be. - - - -CHAPTER XXII - -TOM joined the new order of Cadets of Temperance, being attracted by -the showy character of their "regalia." He promised to abstain from -smoking, chewing, and profanity as long as he remained a member. Now he -found out a new thing--namely, that to promise not to do a thing is the -surest way in the world to make a body want to go and do that very -thing. Tom soon found himself tormented with a desire to drink and -swear; the desire grew to be so intense that nothing but the hope of a -chance to display himself in his red sash kept him from withdrawing -from the order. Fourth of July was coming; but he soon gave that up ---gave it up before he had worn his shackles over forty-eight hours--and -fixed his hopes upon old Judge Frazer, justice of the peace, who was -apparently on his deathbed and would have a big public funeral, since -he was so high an official. During three days Tom was deeply concerned -about the Judge's condition and hungry for news of it. Sometimes his -hopes ran high--so high that he would venture to get out his regalia -and practise before the looking-glass. But the Judge had a most -discouraging way of fluctuating. At last he was pronounced upon the -mend--and then convalescent. Tom was disgusted; and felt a sense of -injury, too. He handed in his resignation at once--and that night the -Judge suffered a relapse and died. Tom resolved that he would never -trust a man like that again. - -The funeral was a fine thing. The Cadets paraded in a style calculated -to kill the late member with envy. Tom was a free boy again, however ---there was something in that. He could drink and swear, now--but found -to his surprise that he did not want to. The simple fact that he could, -took the desire away, and the charm of it. - -Tom presently wondered to find that his coveted vacation was beginning -to hang a little heavily on his hands. - -He attempted a diary--but nothing happened during three days, and so -he abandoned it. - -The first of all the negro minstrel shows came to town, and made a -sensation. Tom and Joe Harper got up a band of performers and were -happy for two days. - -Even the Glorious Fourth was in some sense a failure, for it rained -hard, there was no procession in consequence, and the greatest man in -the world (as Tom supposed), Mr. Benton, an actual United States -Senator, proved an overwhelming disappointment--for he was not -twenty-five feet high, nor even anywhere in the neighborhood of it. - -A circus came. The boys played circus for three days afterward in -tents made of rag carpeting--admission, three pins for boys, two for -girls--and then circusing was abandoned. - -A phrenologist and a mesmerizer came--and went again and left the -village duller and drearier than ever. - -There were some boys-and-girls' parties, but they were so few and so -delightful that they only made the aching voids between ache the harder. - -Becky Thatcher was gone to her Constantinople home to stay with her -parents during vacation--so there was no bright side to life anywhere. - -The dreadful secret of the murder was a chronic misery. It was a very -cancer for permanency and pain. - -Then came the measles. - -During two long weeks Tom lay a prisoner, dead to the world and its -happenings. He was very ill, he was interested in nothing. When he got -upon his feet at last and moved feebly down-town, a melancholy change -had come over everything and every creature. There had been a -"revival," and everybody had "got religion," not only the adults, but -even the boys and girls. Tom went about, hoping against hope for the -sight of one blessed sinful face, but disappointment crossed him -everywhere. He found Joe Harper studying a Testament, and turned sadly -away from the depressing spectacle. He sought Ben Rogers, and found him -visiting the poor with a basket of tracts. He hunted up Jim Hollis, who -called his attention to the precious blessing of his late measles as a -warning. Every boy he encountered added another ton to his depression; -and when, in desperation, he flew for refuge at last to the bosom of -Huckleberry Finn and was received with a Scriptural quotation, his -heart broke and he crept home and to bed realizing that he alone of all -the town was lost, forever and forever. - -And that night there came on a terrific storm, with driving rain, -awful claps of thunder and blinding sheets of lightning. He covered his -head with the bedclothes and waited in a horror of suspense for his -doom; for he had not the shadow of a doubt that all this hubbub was -about him. He believed he had taxed the forbearance of the powers above -to the extremity of endurance and that this was the result. It might -have seemed to him a waste of pomp and ammunition to kill a bug with a -battery of artillery, but there seemed nothing incongruous about the -getting up such an expensive thunderstorm as this to knock the turf -from under an insect like himself. - -By and by the tempest spent itself and died without accomplishing its -object. The boy's first impulse was to be grateful, and reform. His -second was to wait--for there might not be any more storms. - -The next day the doctors were back; Tom had relapsed. The three weeks -he spent on his back this time seemed an entire age. When he got abroad -at last he was hardly grateful that he had been spared, remembering how -lonely was his estate, how companionless and forlorn he was. He drifted -listlessly down the street and found Jim Hollis acting as judge in a -juvenile court that was trying a cat for murder, in the presence of her -victim, a bird. He found Joe Harper and Huck Finn up an alley eating a -stolen melon. Poor lads! they--like Tom--had suffered a relapse. - - - -CHAPTER XXIII - -AT last the sleepy atmosphere was stirred--and vigorously: the murder -trial came on in the court. It became the absorbing topic of village -talk immediately. Tom could not get away from it. Every reference to -the murder sent a shudder to his heart, for his troubled conscience and -fears almost persuaded him that these remarks were put forth in his -hearing as "feelers"; he did not see how he could be suspected of -knowing anything about the murder, but still he could not be -comfortable in the midst of this gossip. It kept him in a cold shiver -all the time. He took Huck to a lonely place to have a talk with him. -It would be some relief to unseal his tongue for a little while; to -divide his burden of distress with another sufferer. Moreover, he -wanted to assure himself that Huck had remained discreet. - -"Huck, have you ever told anybody about--that?" - -"'Bout what?" - -"You know what." - -"Oh--'course I haven't." - -"Never a word?" - -"Never a solitary word, so help me. What makes you ask?" - -"Well, I was afeard." - -"Why, Tom Sawyer, we wouldn't be alive two days if that got found out. -YOU know that." - -Tom felt more comfortable. After a pause: - -"Huck, they couldn't anybody get you to tell, could they?" - -"Get me to tell? Why, if I wanted that half-breed devil to drownd me -they could get me to tell. They ain't no different way." - -"Well, that's all right, then. I reckon we're safe as long as we keep -mum. But let's swear again, anyway. It's more surer." - -"I'm agreed." - -So they swore again with dread solemnities. - -"What is the talk around, Huck? I've heard a power of it." - -"Talk? Well, it's just Muff Potter, Muff Potter, Muff Potter all the -time. It keeps me in a sweat, constant, so's I want to hide som'ers." - -"That's just the same way they go on round me. I reckon he's a goner. -Don't you feel sorry for him, sometimes?" - -"Most always--most always. He ain't no account; but then he hain't -ever done anything to hurt anybody. Just fishes a little, to get money -to get drunk on--and loafs around considerable; but lord, we all do -that--leastways most of us--preachers and such like. But he's kind of -good--he give me half a fish, once, when there warn't enough for two; -and lots of times he's kind of stood by me when I was out of luck." - -"Well, he's mended kites for me, Huck, and knitted hooks on to my -line. I wish we could get him out of there." - -"My! we couldn't get him out, Tom. And besides, 'twouldn't do any -good; they'd ketch him again." - -"Yes--so they would. But I hate to hear 'em abuse him so like the -dickens when he never done--that." - -"I do too, Tom. Lord, I hear 'em say he's the bloodiest looking -villain in this country, and they wonder he wasn't ever hung before." - -"Yes, they talk like that, all the time. I've heard 'em say that if he -was to get free they'd lynch him." - -"And they'd do it, too." - -The boys had a long talk, but it brought them little comfort. As the -twilight drew on, they found themselves hanging about the neighborhood -of the little isolated jail, perhaps with an undefined hope that -something would happen that might clear away their difficulties. But -nothing happened; there seemed to be no angels or fairies interested in -this luckless captive. - -The boys did as they had often done before--went to the cell grating -and gave Potter some tobacco and matches. He was on the ground floor -and there were no guards. - -His gratitude for their gifts had always smote their consciences -before--it cut deeper than ever, this time. They felt cowardly and -treacherous to the last degree when Potter said: - -"You've been mighty good to me, boys--better'n anybody else in this -town. And I don't forget it, I don't. Often I says to myself, says I, -'I used to mend all the boys' kites and things, and show 'em where the -good fishin' places was, and befriend 'em what I could, and now they've -all forgot old Muff when he's in trouble; but Tom don't, and Huck -don't--THEY don't forget him, says I, 'and I don't forget them.' Well, -boys, I done an awful thing--drunk and crazy at the time--that's the -only way I account for it--and now I got to swing for it, and it's -right. Right, and BEST, too, I reckon--hope so, anyway. Well, we won't -talk about that. I don't want to make YOU feel bad; you've befriended -me. But what I want to say, is, don't YOU ever get drunk--then you won't -ever get here. Stand a litter furder west--so--that's it; it's a prime -comfort to see faces that's friendly when a body's in such a muck of -trouble, and there don't none come here but yourn. Good friendly -faces--good friendly faces. Git up on one another's backs and let me -touch 'em. That's it. Shake hands--yourn'll come through the bars, but -mine's too big. Little hands, and weak--but they've helped Muff Potter -a power, and they'd help him more if they could." - -Tom went home miserable, and his dreams that night were full of -horrors. The next day and the day after, he hung about the court-room, -drawn by an almost irresistible impulse to go in, but forcing himself -to stay out. Huck was having the same experience. They studiously -avoided each other. Each wandered away, from time to time, but the same -dismal fascination always brought them back presently. Tom kept his -ears open when idlers sauntered out of the court-room, but invariably -heard distressing news--the toils were closing more and more -relentlessly around poor Potter. At the end of the second day the -village talk was to the effect that Injun Joe's evidence stood firm and -unshaken, and that there was not the slightest question as to what the -jury's verdict would be. - -Tom was out late, that night, and came to bed through the window. He -was in a tremendous state of excitement. It was hours before he got to -sleep. All the village flocked to the court-house the next morning, for -this was to be the great day. Both sexes were about equally represented -in the packed audience. After a long wait the jury filed in and took -their places; shortly afterward, Potter, pale and haggard, timid and -hopeless, was brought in, with chains upon him, and seated where all -the curious eyes could stare at him; no less conspicuous was Injun Joe, -stolid as ever. There was another pause, and then the judge arrived and -the sheriff proclaimed the opening of the court. The usual whisperings -among the lawyers and gathering together of papers followed. These -details and accompanying delays worked up an atmosphere of preparation -that was as impressive as it was fascinating. - -Now a witness was called who testified that he found Muff Potter -washing in the brook, at an early hour of the morning that the murder -was discovered, and that he immediately sneaked away. After some -further questioning, counsel for the prosecution said: - -"Take the witness." - -The prisoner raised his eyes for a moment, but dropped them again when -his own counsel said: - -"I have no questions to ask him." - -The next witness proved the finding of the knife near the corpse. -Counsel for the prosecution said: - -"Take the witness." - -"I have no questions to ask him," Potter's lawyer replied. - -A third witness swore he had often seen the knife in Potter's -possession. - -"Take the witness." - -Counsel for Potter declined to question him. The faces of the audience -began to betray annoyance. Did this attorney mean to throw away his -client's life without an effort? - -Several witnesses deposed concerning Potter's guilty behavior when -brought to the scene of the murder. They were allowed to leave the -stand without being cross-questioned. - -Every detail of the damaging circumstances that occurred in the -graveyard upon that morning which all present remembered so well was -brought out by credible witnesses, but none of them were cross-examined -by Potter's lawyer. The perplexity and dissatisfaction of the house -expressed itself in murmurs and provoked a reproof from the bench. -Counsel for the prosecution now said: - -"By the oaths of citizens whose simple word is above suspicion, we -have fastened this awful crime, beyond all possibility of question, -upon the unhappy prisoner at the bar. We rest our case here." - -A groan escaped from poor Potter, and he put his face in his hands and -rocked his body softly to and fro, while a painful silence reigned in -the court-room. Many men were moved, and many women's compassion -testified itself in tears. Counsel for the defence rose and said: - -"Your honor, in our remarks at the opening of this trial, we -foreshadowed our purpose to prove that our client did this fearful deed -while under the influence of a blind and irresponsible delirium -produced by drink. We have changed our mind. We shall not offer that -plea." [Then to the clerk:] "Call Thomas Sawyer!" - -A puzzled amazement awoke in every face in the house, not even -excepting Potter's. Every eye fastened itself with wondering interest -upon Tom as he rose and took his place upon the stand. The boy looked -wild enough, for he was badly scared. The oath was administered. - -"Thomas Sawyer, where were you on the seventeenth of June, about the -hour of midnight?" - -Tom glanced at Injun Joe's iron face and his tongue failed him. The -audience listened breathless, but the words refused to come. After a -few moments, however, the boy got a little of his strength back, and -managed to put enough of it into his voice to make part of the house -hear: - -"In the graveyard!" - -"A little bit louder, please. Don't be afraid. You were--" - -"In the graveyard." - -A contemptuous smile flitted across Injun Joe's face. - -"Were you anywhere near Horse Williams' grave?" - -"Yes, sir." - -"Speak up--just a trifle louder. How near were you?" - -"Near as I am to you." - -"Were you hidden, or not?" - -"I was hid." - -"Where?" - -"Behind the elms that's on the edge of the grave." - -Injun Joe gave a barely perceptible start. - -"Any one with you?" - -"Yes, sir. I went there with--" - -"Wait--wait a moment. Never mind mentioning your companion's name. We -will produce him at the proper time. Did you carry anything there with -you." - -Tom hesitated and looked confused. - -"Speak out, my boy--don't be diffident. The truth is always -respectable. What did you take there?" - -"Only a--a--dead cat." - -There was a ripple of mirth, which the court checked. - -"We will produce the skeleton of that cat. Now, my boy, tell us -everything that occurred--tell it in your own way--don't skip anything, -and don't be afraid." - -Tom began--hesitatingly at first, but as he warmed to his subject his -words flowed more and more easily; in a little while every sound ceased -but his own voice; every eye fixed itself upon him; with parted lips -and bated breath the audience hung upon his words, taking no note of -time, rapt in the ghastly fascinations of the tale. The strain upon -pent emotion reached its climax when the boy said: - -"--and as the doctor fetched the board around and Muff Potter fell, -Injun Joe jumped with the knife and--" - -Crash! Quick as lightning the half-breed sprang for a window, tore his -way through all opposers, and was gone! - - - -CHAPTER XXIV - -TOM was a glittering hero once more--the pet of the old, the envy of -the young. His name even went into immortal print, for the village -paper magnified him. There were some that believed he would be -President, yet, if he escaped hanging. - -As usual, the fickle, unreasoning world took Muff Potter to its bosom -and fondled him as lavishly as it had abused him before. But that sort -of conduct is to the world's credit; therefore it is not well to find -fault with it. - -Tom's days were days of splendor and exultation to him, but his nights -were seasons of horror. Injun Joe infested all his dreams, and always -with doom in his eye. Hardly any temptation could persuade the boy to -stir abroad after nightfall. Poor Huck was in the same state of -wretchedness and terror, for Tom had told the whole story to the lawyer -the night before the great day of the trial, and Huck was sore afraid -that his share in the business might leak out, yet, notwithstanding -Injun Joe's flight had saved him the suffering of testifying in court. -The poor fellow had got the attorney to promise secrecy, but what of -that? Since Tom's harassed conscience had managed to drive him to the -lawyer's house by night and wring a dread tale from lips that had been -sealed with the dismalest and most formidable of oaths, Huck's -confidence in the human race was well-nigh obliterated. - -Daily Muff Potter's gratitude made Tom glad he had spoken; but nightly -he wished he had sealed up his tongue. - -Half the time Tom was afraid Injun Joe would never be captured; the -other half he was afraid he would be. He felt sure he never could draw -a safe breath again until that man was dead and he had seen the corpse. - -Rewards had been offered, the country had been scoured, but no Injun -Joe was found. One of those omniscient and awe-inspiring marvels, a -detective, came up from St. Louis, moused around, shook his head, -looked wise, and made that sort of astounding success which members of -that craft usually achieve. That is to say, he "found a clew." But you -can't hang a "clew" for murder, and so after that detective had got -through and gone home, Tom felt just as insecure as he was before. - -The slow days drifted on, and each left behind it a slightly lightened -weight of apprehension. - - - -CHAPTER XXV - -THERE comes a time in every rightly-constructed boy's life when he has -a raging desire to go somewhere and dig for hidden treasure. This -desire suddenly came upon Tom one day. He sallied out to find Joe -Harper, but failed of success. Next he sought Ben Rogers; he had gone -fishing. Presently he stumbled upon Huck Finn the Red-Handed. Huck -would answer. Tom took him to a private place and opened the matter to -him confidentially. Huck was willing. Huck was always willing to take a -hand in any enterprise that offered entertainment and required no -capital, for he had a troublesome superabundance of that sort of time -which is not money. "Where'll we dig?" said Huck. - -"Oh, most anywhere." - -"Why, is it hid all around?" - -"No, indeed it ain't. It's hid in mighty particular places, Huck ---sometimes on islands, sometimes in rotten chests under the end of a -limb of an old dead tree, just where the shadow falls at midnight; but -mostly under the floor in ha'nted houses." - -"Who hides it?" - -"Why, robbers, of course--who'd you reckon? Sunday-school -sup'rintendents?" - -"I don't know. If 'twas mine I wouldn't hide it; I'd spend it and have -a good time." - -"So would I. But robbers don't do that way. They always hide it and -leave it there." - -"Don't they come after it any more?" - -"No, they think they will, but they generally forget the marks, or -else they die. Anyway, it lays there a long time and gets rusty; and by -and by somebody finds an old yellow paper that tells how to find the -marks--a paper that's got to be ciphered over about a week because it's -mostly signs and hy'roglyphics." - -"Hyro--which?" - -"Hy'roglyphics--pictures and things, you know, that don't seem to mean -anything." - -"Have you got one of them papers, Tom?" - -"No." - -"Well then, how you going to find the marks?" - -"I don't want any marks. They always bury it under a ha'nted house or -on an island, or under a dead tree that's got one limb sticking out. -Well, we've tried Jackson's Island a little, and we can try it again -some time; and there's the old ha'nted house up the Still-House branch, -and there's lots of dead-limb trees--dead loads of 'em." - -"Is it under all of them?" - -"How you talk! No!" - -"Then how you going to know which one to go for?" - -"Go for all of 'em!" - -"Why, Tom, it'll take all summer." - -"Well, what of that? Suppose you find a brass pot with a hundred -dollars in it, all rusty and gray, or rotten chest full of di'monds. -How's that?" - -Huck's eyes glowed. - -"That's bully. Plenty bully enough for me. Just you gimme the hundred -dollars and I don't want no di'monds." - -"All right. But I bet you I ain't going to throw off on di'monds. Some -of 'em's worth twenty dollars apiece--there ain't any, hardly, but's -worth six bits or a dollar." - -"No! Is that so?" - -"Cert'nly--anybody'll tell you so. Hain't you ever seen one, Huck?" - -"Not as I remember." - -"Oh, kings have slathers of them." - -"Well, I don' know no kings, Tom." - -"I reckon you don't. But if you was to go to Europe you'd see a raft -of 'em hopping around." - -"Do they hop?" - -"Hop?--your granny! No!" - -"Well, what did you say they did, for?" - -"Shucks, I only meant you'd SEE 'em--not hopping, of course--what do -they want to hop for?--but I mean you'd just see 'em--scattered around, -you know, in a kind of a general way. Like that old humpbacked Richard." - -"Richard? What's his other name?" - -"He didn't have any other name. Kings don't have any but a given name." - -"No?" - -"But they don't." - -"Well, if they like it, Tom, all right; but I don't want to be a king -and have only just a given name, like a nigger. But say--where you -going to dig first?" - -"Well, I don't know. S'pose we tackle that old dead-limb tree on the -hill t'other side of Still-House branch?" - -"I'm agreed." - -So they got a crippled pick and a shovel, and set out on their -three-mile tramp. They arrived hot and panting, and threw themselves -down in the shade of a neighboring elm to rest and have a smoke. - -"I like this," said Tom. - -"So do I." - -"Say, Huck, if we find a treasure here, what you going to do with your -share?" - -"Well, I'll have pie and a glass of soda every day, and I'll go to -every circus that comes along. I bet I'll have a gay time." - -"Well, ain't you going to save any of it?" - -"Save it? What for?" - -"Why, so as to have something to live on, by and by." - -"Oh, that ain't any use. Pap would come back to thish-yer town some -day and get his claws on it if I didn't hurry up, and I tell you he'd -clean it out pretty quick. What you going to do with yourn, Tom?" - -"I'm going to buy a new drum, and a sure-'nough sword, and a red -necktie and a bull pup, and get married." - -"Married!" - -"That's it." - -"Tom, you--why, you ain't in your right mind." - -"Wait--you'll see." - -"Well, that's the foolishest thing you could do. Look at pap and my -mother. Fight! Why, they used to fight all the time. I remember, mighty -well." - -"That ain't anything. The girl I'm going to marry won't fight." - -"Tom, I reckon they're all alike. They'll all comb a body. Now you -better think 'bout this awhile. I tell you you better. What's the name -of the gal?" - -"It ain't a gal at all--it's a girl." - -"It's all the same, I reckon; some says gal, some says girl--both's -right, like enough. Anyway, what's her name, Tom?" - -"I'll tell you some time--not now." - -"All right--that'll do. Only if you get married I'll be more lonesomer -than ever." - -"No you won't. You'll come and live with me. Now stir out of this and -we'll go to digging." - -They worked and sweated for half an hour. No result. They toiled -another half-hour. Still no result. Huck said: - -"Do they always bury it as deep as this?" - -"Sometimes--not always. Not generally. I reckon we haven't got the -right place." - -So they chose a new spot and began again. The labor dragged a little, -but still they made progress. They pegged away in silence for some -time. Finally Huck leaned on his shovel, swabbed the beaded drops from -his brow with his sleeve, and said: - -"Where you going to dig next, after we get this one?" - -"I reckon maybe we'll tackle the old tree that's over yonder on -Cardiff Hill back of the widow's." - -"I reckon that'll be a good one. But won't the widow take it away from -us, Tom? It's on her land." - -"SHE take it away! Maybe she'd like to try it once. Whoever finds one -of these hid treasures, it belongs to him. It don't make any difference -whose land it's on." - -That was satisfactory. The work went on. By and by Huck said: - -"Blame it, we must be in the wrong place again. What do you think?" - -"It is mighty curious, Huck. I don't understand it. Sometimes witches -interfere. I reckon maybe that's what's the trouble now." - -"Shucks! Witches ain't got no power in the daytime." - -"Well, that's so. I didn't think of that. Oh, I know what the matter -is! What a blamed lot of fools we are! You got to find out where the -shadow of the limb falls at midnight, and that's where you dig!" - -"Then consound it, we've fooled away all this work for nothing. Now -hang it all, we got to come back in the night. It's an awful long way. -Can you get out?" - -"I bet I will. We've got to do it to-night, too, because if somebody -sees these holes they'll know in a minute what's here and they'll go -for it." - -"Well, I'll come around and maow to-night." - -"All right. Let's hide the tools in the bushes." - -The boys were there that night, about the appointed time. They sat in -the shadow waiting. It was a lonely place, and an hour made solemn by -old traditions. Spirits whispered in the rustling leaves, ghosts lurked -in the murky nooks, the deep baying of a hound floated up out of the -distance, an owl answered with his sepulchral note. The boys were -subdued by these solemnities, and talked little. By and by they judged -that twelve had come; they marked where the shadow fell, and began to -dig. Their hopes commenced to rise. Their interest grew stronger, and -their industry kept pace with it. The hole deepened and still deepened, -but every time their hearts jumped to hear the pick strike upon -something, they only suffered a new disappointment. It was only a stone -or a chunk. At last Tom said: - -"It ain't any use, Huck, we're wrong again." - -"Well, but we CAN'T be wrong. We spotted the shadder to a dot." - -"I know it, but then there's another thing." - -"What's that?". - -"Why, we only guessed at the time. Like enough it was too late or too -early." - -Huck dropped his shovel. - -"That's it," said he. "That's the very trouble. We got to give this -one up. We can't ever tell the right time, and besides this kind of -thing's too awful, here this time of night with witches and ghosts -a-fluttering around so. I feel as if something's behind me all the time; -and I'm afeard to turn around, becuz maybe there's others in front -a-waiting for a chance. I been creeping all over, ever since I got here." - -"Well, I've been pretty much so, too, Huck. They most always put in a -dead man when they bury a treasure under a tree, to look out for it." - -"Lordy!" - -"Yes, they do. I've always heard that." - -"Tom, I don't like to fool around much where there's dead people. A -body's bound to get into trouble with 'em, sure." - -"I don't like to stir 'em up, either. S'pose this one here was to -stick his skull out and say something!" - -"Don't Tom! It's awful." - -"Well, it just is. Huck, I don't feel comfortable a bit." - -"Say, Tom, let's give this place up, and try somewheres else." - -"All right, I reckon we better." - -"What'll it be?" - -Tom considered awhile; and then said: - -"The ha'nted house. That's it!" - -"Blame it, I don't like ha'nted houses, Tom. Why, they're a dern sight -worse'n dead people. Dead people might talk, maybe, but they don't come -sliding around in a shroud, when you ain't noticing, and peep over your -shoulder all of a sudden and grit their teeth, the way a ghost does. I -couldn't stand such a thing as that, Tom--nobody could." - -"Yes, but, Huck, ghosts don't travel around only at night. They won't -hender us from digging there in the daytime." - -"Well, that's so. But you know mighty well people don't go about that -ha'nted house in the day nor the night." - -"Well, that's mostly because they don't like to go where a man's been -murdered, anyway--but nothing's ever been seen around that house except -in the night--just some blue lights slipping by the windows--no regular -ghosts." - -"Well, where you see one of them blue lights flickering around, Tom, -you can bet there's a ghost mighty close behind it. It stands to -reason. Becuz you know that they don't anybody but ghosts use 'em." - -"Yes, that's so. But anyway they don't come around in the daytime, so -what's the use of our being afeard?" - -"Well, all right. We'll tackle the ha'nted house if you say so--but I -reckon it's taking chances." - -They had started down the hill by this time. There in the middle of -the moonlit valley below them stood the "ha'nted" house, utterly -isolated, its fences gone long ago, rank weeds smothering the very -doorsteps, the chimney crumbled to ruin, the window-sashes vacant, a -corner of the roof caved in. The boys gazed awhile, half expecting to -see a blue light flit past a window; then talking in a low tone, as -befitted the time and the circumstances, they struck far off to the -right, to give the haunted house a wide berth, and took their way -homeward through the woods that adorned the rearward side of Cardiff -Hill. - - - -CHAPTER XXVI - -ABOUT noon the next day the boys arrived at the dead tree; they had -come for their tools. Tom was impatient to go to the haunted house; -Huck was measurably so, also--but suddenly said: - -"Lookyhere, Tom, do you know what day it is?" - -Tom mentally ran over the days of the week, and then quickly lifted -his eyes with a startled look in them-- - -"My! I never once thought of it, Huck!" - -"Well, I didn't neither, but all at once it popped onto me that it was -Friday." - -"Blame it, a body can't be too careful, Huck. We might 'a' got into an -awful scrape, tackling such a thing on a Friday." - -"MIGHT! Better say we WOULD! There's some lucky days, maybe, but -Friday ain't." - -"Any fool knows that. I don't reckon YOU was the first that found it -out, Huck." - -"Well, I never said I was, did I? And Friday ain't all, neither. I had -a rotten bad dream last night--dreampt about rats." - -"No! Sure sign of trouble. Did they fight?" - -"No." - -"Well, that's good, Huck. When they don't fight it's only a sign that -there's trouble around, you know. All we got to do is to look mighty -sharp and keep out of it. We'll drop this thing for to-day, and play. -Do you know Robin Hood, Huck?" - -"No. Who's Robin Hood?" - -"Why, he was one of the greatest men that was ever in England--and the -best. He was a robber." - -"Cracky, I wisht I was. Who did he rob?" - -"Only sheriffs and bishops and rich people and kings, and such like. -But he never bothered the poor. He loved 'em. He always divided up with -'em perfectly square." - -"Well, he must 'a' been a brick." - -"I bet you he was, Huck. Oh, he was the noblest man that ever was. -They ain't any such men now, I can tell you. He could lick any man in -England, with one hand tied behind him; and he could take his yew bow -and plug a ten-cent piece every time, a mile and a half." - -"What's a YEW bow?" - -"I don't know. It's some kind of a bow, of course. And if he hit that -dime only on the edge he would set down and cry--and curse. But we'll -play Robin Hood--it's nobby fun. I'll learn you." - -"I'm agreed." - -So they played Robin Hood all the afternoon, now and then casting a -yearning eye down upon the haunted house and passing a remark about the -morrow's prospects and possibilities there. As the sun began to sink -into the west they took their way homeward athwart the long shadows of -the trees and soon were buried from sight in the forests of Cardiff -Hill. - -On Saturday, shortly after noon, the boys were at the dead tree again. -They had a smoke and a chat in the shade, and then dug a little in -their last hole, not with great hope, but merely because Tom said there -were so many cases where people had given up a treasure after getting -down within six inches of it, and then somebody else had come along and -turned it up with a single thrust of a shovel. The thing failed this -time, however, so the boys shouldered their tools and went away feeling -that they had not trifled with fortune, but had fulfilled all the -requirements that belong to the business of treasure-hunting. - -When they reached the haunted house there was something so weird and -grisly about the dead silence that reigned there under the baking sun, -and something so depressing about the loneliness and desolation of the -place, that they were afraid, for a moment, to venture in. Then they -crept to the door and took a trembling peep. They saw a weed-grown, -floorless room, unplastered, an ancient fireplace, vacant windows, a -ruinous staircase; and here, there, and everywhere hung ragged and -abandoned cobwebs. They presently entered, softly, with quickened -pulses, talking in whispers, ears alert to catch the slightest sound, -and muscles tense and ready for instant retreat. - -In a little while familiarity modified their fears and they gave the -place a critical and interested examination, rather admiring their own -boldness, and wondering at it, too. Next they wanted to look up-stairs. -This was something like cutting off retreat, but they got to daring -each other, and of course there could be but one result--they threw -their tools into a corner and made the ascent. Up there were the same -signs of decay. In one corner they found a closet that promised -mystery, but the promise was a fraud--there was nothing in it. Their -courage was up now and well in hand. They were about to go down and -begin work when-- - -"Sh!" said Tom. - -"What is it?" whispered Huck, blanching with fright. - -"Sh!... There!... Hear it?" - -"Yes!... Oh, my! Let's run!" - -"Keep still! Don't you budge! They're coming right toward the door." - -The boys stretched themselves upon the floor with their eyes to -knot-holes in the planking, and lay waiting, in a misery of fear. - -"They've stopped.... No--coming.... Here they are. Don't whisper -another word, Huck. My goodness, I wish I was out of this!" - -Two men entered. Each boy said to himself: "There's the old deaf and -dumb Spaniard that's been about town once or twice lately--never saw -t'other man before." - -"T'other" was a ragged, unkempt creature, with nothing very pleasant -in his face. The Spaniard was wrapped in a serape; he had bushy white -whiskers; long white hair flowed from under his sombrero, and he wore -green goggles. When they came in, "t'other" was talking in a low voice; -they sat down on the ground, facing the door, with their backs to the -wall, and the speaker continued his remarks. His manner became less -guarded and his words more distinct as he proceeded: - -"No," said he, "I've thought it all over, and I don't like it. It's -dangerous." - -"Dangerous!" grunted the "deaf and dumb" Spaniard--to the vast -surprise of the boys. "Milksop!" - -This voice made the boys gasp and quake. It was Injun Joe's! There was -silence for some time. Then Joe said: - -"What's any more dangerous than that job up yonder--but nothing's come -of it." - -"That's different. Away up the river so, and not another house about. -'Twon't ever be known that we tried, anyway, long as we didn't succeed." - -"Well, what's more dangerous than coming here in the daytime!--anybody -would suspicion us that saw us." - -"I know that. But there warn't any other place as handy after that -fool of a job. I want to quit this shanty. I wanted to yesterday, only -it warn't any use trying to stir out of here, with those infernal boys -playing over there on the hill right in full view." - -"Those infernal boys" quaked again under the inspiration of this -remark, and thought how lucky it was that they had remembered it was -Friday and concluded to wait a day. They wished in their hearts they -had waited a year. - -The two men got out some food and made a luncheon. After a long and -thoughtful silence, Injun Joe said: - -"Look here, lad--you go back up the river where you belong. Wait there -till you hear from me. I'll take the chances on dropping into this town -just once more, for a look. We'll do that 'dangerous' job after I've -spied around a little and think things look well for it. Then for -Texas! We'll leg it together!" - -This was satisfactory. Both men presently fell to yawning, and Injun -Joe said: - -"I'm dead for sleep! It's your turn to watch." - -He curled down in the weeds and soon began to snore. His comrade -stirred him once or twice and he became quiet. Presently the watcher -began to nod; his head drooped lower and lower, both men began to snore -now. - -The boys drew a long, grateful breath. Tom whispered: - -"Now's our chance--come!" - -Huck said: - -"I can't--I'd die if they was to wake." - -Tom urged--Huck held back. At last Tom rose slowly and softly, and -started alone. But the first step he made wrung such a hideous creak -from the crazy floor that he sank down almost dead with fright. He -never made a second attempt. The boys lay there counting the dragging -moments till it seemed to them that time must be done and eternity -growing gray; and then they were grateful to note that at last the sun -was setting. - -Now one snore ceased. Injun Joe sat up, stared around--smiled grimly -upon his comrade, whose head was drooping upon his knees--stirred him -up with his foot and said: - -"Here! YOU'RE a watchman, ain't you! All right, though--nothing's -happened." - -"My! have I been asleep?" - -"Oh, partly, partly. Nearly time for us to be moving, pard. What'll we -do with what little swag we've got left?" - -"I don't know--leave it here as we've always done, I reckon. No use to -take it away till we start south. Six hundred and fifty in silver's -something to carry." - -"Well--all right--it won't matter to come here once more." - -"No--but I'd say come in the night as we used to do--it's better." - -"Yes: but look here; it may be a good while before I get the right -chance at that job; accidents might happen; 'tain't in such a very good -place; we'll just regularly bury it--and bury it deep." - -"Good idea," said the comrade, who walked across the room, knelt down, -raised one of the rearward hearth-stones and took out a bag that -jingled pleasantly. He subtracted from it twenty or thirty dollars for -himself and as much for Injun Joe, and passed the bag to the latter, -who was on his knees in the corner, now, digging with his bowie-knife. - -The boys forgot all their fears, all their miseries in an instant. -With gloating eyes they watched every movement. Luck!--the splendor of -it was beyond all imagination! Six hundred dollars was money enough to -make half a dozen boys rich! Here was treasure-hunting under the -happiest auspices--there would not be any bothersome uncertainty as to -where to dig. They nudged each other every moment--eloquent nudges and -easily understood, for they simply meant--"Oh, but ain't you glad NOW -we're here!" - -Joe's knife struck upon something. - -"Hello!" said he. - -"What is it?" said his comrade. - -"Half-rotten plank--no, it's a box, I believe. Here--bear a hand and -we'll see what it's here for. Never mind, I've broke a hole." - -He reached his hand in and drew it out-- - -"Man, it's money!" - -The two men examined the handful of coins. They were gold. The boys -above were as excited as themselves, and as delighted. - -Joe's comrade said: - -"We'll make quick work of this. There's an old rusty pick over amongst -the weeds in the corner the other side of the fireplace--I saw it a -minute ago." - -He ran and brought the boys' pick and shovel. Injun Joe took the pick, -looked it over critically, shook his head, muttered something to -himself, and then began to use it. The box was soon unearthed. It was -not very large; it was iron bound and had been very strong before the -slow years had injured it. The men contemplated the treasure awhile in -blissful silence. - -"Pard, there's thousands of dollars here," said Injun Joe. - -"'Twas always said that Murrel's gang used to be around here one -summer," the stranger observed. - -"I know it," said Injun Joe; "and this looks like it, I should say." - -"Now you won't need to do that job." - -The half-breed frowned. Said he: - -"You don't know me. Least you don't know all about that thing. 'Tain't -robbery altogether--it's REVENGE!" and a wicked light flamed in his -eyes. "I'll need your help in it. When it's finished--then Texas. Go -home to your Nance and your kids, and stand by till you hear from me." - -"Well--if you say so; what'll we do with this--bury it again?" - -"Yes. [Ravishing delight overhead.] NO! by the great Sachem, no! -[Profound distress overhead.] I'd nearly forgot. That pick had fresh -earth on it! [The boys were sick with terror in a moment.] What -business has a pick and a shovel here? What business with fresh earth -on them? Who brought them here--and where are they gone? Have you heard -anybody?--seen anybody? What! bury it again and leave them to come and -see the ground disturbed? Not exactly--not exactly. We'll take it to my -den." - -"Why, of course! Might have thought of that before. You mean Number -One?" - -"No--Number Two--under the cross. The other place is bad--too common." - -"All right. It's nearly dark enough to start." - -Injun Joe got up and went about from window to window cautiously -peeping out. Presently he said: - -"Who could have brought those tools here? Do you reckon they can be -up-stairs?" - -The boys' breath forsook them. Injun Joe put his hand on his knife, -halted a moment, undecided, and then turned toward the stairway. The -boys thought of the closet, but their strength was gone. The steps came -creaking up the stairs--the intolerable distress of the situation woke -the stricken resolution of the lads--they were about to spring for the -closet, when there was a crash of rotten timbers and Injun Joe landed -on the ground amid the debris of the ruined stairway. He gathered -himself up cursing, and his comrade said: - -"Now what's the use of all that? If it's anybody, and they're up -there, let them STAY there--who cares? If they want to jump down, now, -and get into trouble, who objects? It will be dark in fifteen minutes ---and then let them follow us if they want to. I'm willing. In my -opinion, whoever hove those things in here caught a sight of us and -took us for ghosts or devils or something. I'll bet they're running -yet." - -Joe grumbled awhile; then he agreed with his friend that what daylight -was left ought to be economized in getting things ready for leaving. -Shortly afterward they slipped out of the house in the deepening -twilight, and moved toward the river with their precious box. - -Tom and Huck rose up, weak but vastly relieved, and stared after them -through the chinks between the logs of the house. Follow? Not they. -They were content to reach ground again without broken necks, and take -the townward track over the hill. They did not talk much. They were too -much absorbed in hating themselves--hating the ill luck that made them -take the spade and the pick there. But for that, Injun Joe never would -have suspected. He would have hidden the silver with the gold to wait -there till his "revenge" was satisfied, and then he would have had the -misfortune to find that money turn up missing. Bitter, bitter luck that -the tools were ever brought there! - -They resolved to keep a lookout for that Spaniard when he should come -to town spying out for chances to do his revengeful job, and follow him -to "Number Two," wherever that might be. Then a ghastly thought -occurred to Tom. - -"Revenge? What if he means US, Huck!" - -"Oh, don't!" said Huck, nearly fainting. - -They talked it all over, and as they entered town they agreed to -believe that he might possibly mean somebody else--at least that he -might at least mean nobody but Tom, since only Tom had testified. - -Very, very small comfort it was to Tom to be alone in danger! Company -would be a palpable improvement, he thought. - - - -CHAPTER XXVII - -THE adventure of the day mightily tormented Tom's dreams that night. -Four times he had his hands on that rich treasure and four times it -wasted to nothingness in his fingers as sleep forsook him and -wakefulness brought back the hard reality of his misfortune. As he lay -in the early morning recalling the incidents of his great adventure, he -noticed that they seemed curiously subdued and far away--somewhat as if -they had happened in another world, or in a time long gone by. Then it -occurred to him that the great adventure itself must be a dream! There -was one very strong argument in favor of this idea--namely, that the -quantity of coin he had seen was too vast to be real. He had never seen -as much as fifty dollars in one mass before, and he was like all boys -of his age and station in life, in that he imagined that all references -to "hundreds" and "thousands" were mere fanciful forms of speech, and -that no such sums really existed in the world. He never had supposed -for a moment that so large a sum as a hundred dollars was to be found -in actual money in any one's possession. If his notions of hidden -treasure had been analyzed, they would have been found to consist of a -handful of real dimes and a bushel of vague, splendid, ungraspable -dollars. - -But the incidents of his adventure grew sensibly sharper and clearer -under the attrition of thinking them over, and so he presently found -himself leaning to the impression that the thing might not have been a -dream, after all. This uncertainty must be swept away. He would snatch -a hurried breakfast and go and find Huck. Huck was sitting on the -gunwale of a flatboat, listlessly dangling his feet in the water and -looking very melancholy. Tom concluded to let Huck lead up to the -subject. If he did not do it, then the adventure would be proved to -have been only a dream. - -"Hello, Huck!" - -"Hello, yourself." - -Silence, for a minute. - -"Tom, if we'd 'a' left the blame tools at the dead tree, we'd 'a' got -the money. Oh, ain't it awful!" - -"'Tain't a dream, then, 'tain't a dream! Somehow I most wish it was. -Dog'd if I don't, Huck." - -"What ain't a dream?" - -"Oh, that thing yesterday. I been half thinking it was." - -"Dream! If them stairs hadn't broke down you'd 'a' seen how much dream -it was! I've had dreams enough all night--with that patch-eyed Spanish -devil going for me all through 'em--rot him!" - -"No, not rot him. FIND him! Track the money!" - -"Tom, we'll never find him. A feller don't have only one chance for -such a pile--and that one's lost. I'd feel mighty shaky if I was to see -him, anyway." - -"Well, so'd I; but I'd like to see him, anyway--and track him out--to -his Number Two." - -"Number Two--yes, that's it. I been thinking 'bout that. But I can't -make nothing out of it. What do you reckon it is?" - -"I dono. It's too deep. Say, Huck--maybe it's the number of a house!" - -"Goody!... No, Tom, that ain't it. If it is, it ain't in this -one-horse town. They ain't no numbers here." - -"Well, that's so. Lemme think a minute. Here--it's the number of a -room--in a tavern, you know!" - -"Oh, that's the trick! They ain't only two taverns. We can find out -quick." - -"You stay here, Huck, till I come." - -Tom was off at once. He did not care to have Huck's company in public -places. He was gone half an hour. He found that in the best tavern, No. -2 had long been occupied by a young lawyer, and was still so occupied. -In the less ostentatious house, No. 2 was a mystery. The -tavern-keeper's young son said it was kept locked all the time, and he -never saw anybody go into it or come out of it except at night; he did -not know any particular reason for this state of things; had had some -little curiosity, but it was rather feeble; had made the most of the -mystery by entertaining himself with the idea that that room was -"ha'nted"; had noticed that there was a light in there the night before. - -"That's what I've found out, Huck. I reckon that's the very No. 2 -we're after." - -"I reckon it is, Tom. Now what you going to do?" - -"Lemme think." - -Tom thought a long time. Then he said: - -"I'll tell you. The back door of that No. 2 is the door that comes out -into that little close alley between the tavern and the old rattle trap -of a brick store. Now you get hold of all the door-keys you can find, -and I'll nip all of auntie's, and the first dark night we'll go there -and try 'em. And mind you, keep a lookout for Injun Joe, because he -said he was going to drop into town and spy around once more for a -chance to get his revenge. If you see him, you just follow him; and if -he don't go to that No. 2, that ain't the place." - -"Lordy, I don't want to foller him by myself!" - -"Why, it'll be night, sure. He mightn't ever see you--and if he did, -maybe he'd never think anything." - -"Well, if it's pretty dark I reckon I'll track him. I dono--I dono. -I'll try." - -"You bet I'll follow him, if it's dark, Huck. Why, he might 'a' found -out he couldn't get his revenge, and be going right after that money." - -"It's so, Tom, it's so. I'll foller him; I will, by jingoes!" - -"Now you're TALKING! Don't you ever weaken, Huck, and I won't." - - - -CHAPTER XXVIII - -THAT night Tom and Huck were ready for their adventure. They hung -about the neighborhood of the tavern until after nine, one watching the -alley at a distance and the other the tavern door. Nobody entered the -alley or left it; nobody resembling the Spaniard entered or left the -tavern door. The night promised to be a fair one; so Tom went home with -the understanding that if a considerable degree of darkness came on, -Huck was to come and "maow," whereupon he would slip out and try the -keys. But the night remained clear, and Huck closed his watch and -retired to bed in an empty sugar hogshead about twelve. - -Tuesday the boys had the same ill luck. Also Wednesday. But Thursday -night promised better. Tom slipped out in good season with his aunt's -old tin lantern, and a large towel to blindfold it with. He hid the -lantern in Huck's sugar hogshead and the watch began. An hour before -midnight the tavern closed up and its lights (the only ones -thereabouts) were put out. No Spaniard had been seen. Nobody had -entered or left the alley. Everything was auspicious. The blackness of -darkness reigned, the perfect stillness was interrupted only by -occasional mutterings of distant thunder. - -Tom got his lantern, lit it in the hogshead, wrapped it closely in the -towel, and the two adventurers crept in the gloom toward the tavern. -Huck stood sentry and Tom felt his way into the alley. Then there was a -season of waiting anxiety that weighed upon Huck's spirits like a -mountain. He began to wish he could see a flash from the lantern--it -would frighten him, but it would at least tell him that Tom was alive -yet. It seemed hours since Tom had disappeared. Surely he must have -fainted; maybe he was dead; maybe his heart had burst under terror and -excitement. In his uneasiness Huck found himself drawing closer and -closer to the alley; fearing all sorts of dreadful things, and -momentarily expecting some catastrophe to happen that would take away -his breath. There was not much to take away, for he seemed only able to -inhale it by thimblefuls, and his heart would soon wear itself out, the -way it was beating. Suddenly there was a flash of light and Tom came -tearing by him: "Run!" said he; "run, for your life!" - -He needn't have repeated it; once was enough; Huck was making thirty -or forty miles an hour before the repetition was uttered. The boys -never stopped till they reached the shed of a deserted slaughter-house -at the lower end of the village. Just as they got within its shelter -the storm burst and the rain poured down. As soon as Tom got his breath -he said: - -"Huck, it was awful! I tried two of the keys, just as soft as I could; -but they seemed to make such a power of racket that I couldn't hardly -get my breath I was so scared. They wouldn't turn in the lock, either. -Well, without noticing what I was doing, I took hold of the knob, and -open comes the door! It warn't locked! I hopped in, and shook off the -towel, and, GREAT CAESAR'S GHOST!" - -"What!--what'd you see, Tom?" - -"Huck, I most stepped onto Injun Joe's hand!" - -"No!" - -"Yes! He was lying there, sound asleep on the floor, with his old -patch on his eye and his arms spread out." - -"Lordy, what did you do? Did he wake up?" - -"No, never budged. Drunk, I reckon. I just grabbed that towel and -started!" - -"I'd never 'a' thought of the towel, I bet!" - -"Well, I would. My aunt would make me mighty sick if I lost it." - -"Say, Tom, did you see that box?" - -"Huck, I didn't wait to look around. I didn't see the box, I didn't -see the cross. I didn't see anything but a bottle and a tin cup on the -floor by Injun Joe; yes, I saw two barrels and lots more bottles in the -room. Don't you see, now, what's the matter with that ha'nted room?" - -"How?" - -"Why, it's ha'nted with whiskey! Maybe ALL the Temperance Taverns have -got a ha'nted room, hey, Huck?" - -"Well, I reckon maybe that's so. Who'd 'a' thought such a thing? But -say, Tom, now's a mighty good time to get that box, if Injun Joe's -drunk." - -"It is, that! You try it!" - -Huck shuddered. - -"Well, no--I reckon not." - -"And I reckon not, Huck. Only one bottle alongside of Injun Joe ain't -enough. If there'd been three, he'd be drunk enough and I'd do it." - -There was a long pause for reflection, and then Tom said: - -"Lookyhere, Huck, less not try that thing any more till we know Injun -Joe's not in there. It's too scary. Now, if we watch every night, we'll -be dead sure to see him go out, some time or other, and then we'll -snatch that box quicker'n lightning." - -"Well, I'm agreed. I'll watch the whole night long, and I'll do it -every night, too, if you'll do the other part of the job." - -"All right, I will. All you got to do is to trot up Hooper Street a -block and maow--and if I'm asleep, you throw some gravel at the window -and that'll fetch me." - -"Agreed, and good as wheat!" - -"Now, Huck, the storm's over, and I'll go home. It'll begin to be -daylight in a couple of hours. You go back and watch that long, will -you?" - -"I said I would, Tom, and I will. I'll ha'nt that tavern every night -for a year! I'll sleep all day and I'll stand watch all night." - -"That's all right. Now, where you going to sleep?" - -"In Ben Rogers' hayloft. He lets me, and so does his pap's nigger man, -Uncle Jake. I tote water for Uncle Jake whenever he wants me to, and -any time I ask him he gives me a little something to eat if he can -spare it. That's a mighty good nigger, Tom. He likes me, becuz I don't -ever act as if I was above him. Sometime I've set right down and eat -WITH him. But you needn't tell that. A body's got to do things when -he's awful hungry he wouldn't want to do as a steady thing." - -"Well, if I don't want you in the daytime, I'll let you sleep. I won't -come bothering around. Any time you see something's up, in the night, -just skip right around and maow." - - - -CHAPTER XXIX - -THE first thing Tom heard on Friday morning was a glad piece of news ---Judge Thatcher's family had come back to town the night before. Both -Injun Joe and the treasure sunk into secondary importance for a moment, -and Becky took the chief place in the boy's interest. He saw her and -they had an exhausting good time playing "hi-spy" and "gully-keeper" -with a crowd of their school-mates. The day was completed and crowned -in a peculiarly satisfactory way: Becky teased her mother to appoint -the next day for the long-promised and long-delayed picnic, and she -consented. The child's delight was boundless; and Tom's not more -moderate. The invitations were sent out before sunset, and straightway -the young folks of the village were thrown into a fever of preparation -and pleasurable anticipation. Tom's excitement enabled him to keep -awake until a pretty late hour, and he had good hopes of hearing Huck's -"maow," and of having his treasure to astonish Becky and the picnickers -with, next day; but he was disappointed. No signal came that night. - -Morning came, eventually, and by ten or eleven o'clock a giddy and -rollicking company were gathered at Judge Thatcher's, and everything -was ready for a start. It was not the custom for elderly people to mar -the picnics with their presence. The children were considered safe -enough under the wings of a few young ladies of eighteen and a few -young gentlemen of twenty-three or thereabouts. The old steam ferryboat -was chartered for the occasion; presently the gay throng filed up the -main street laden with provision-baskets. Sid was sick and had to miss -the fun; Mary remained at home to entertain him. The last thing Mrs. -Thatcher said to Becky, was: - -"You'll not get back till late. Perhaps you'd better stay all night -with some of the girls that live near the ferry-landing, child." - -"Then I'll stay with Susy Harper, mamma." - -"Very well. And mind and behave yourself and don't be any trouble." - -Presently, as they tripped along, Tom said to Becky: - -"Say--I'll tell you what we'll do. 'Stead of going to Joe Harper's -we'll climb right up the hill and stop at the Widow Douglas'. She'll -have ice-cream! She has it most every day--dead loads of it. And she'll -be awful glad to have us." - -"Oh, that will be fun!" - -Then Becky reflected a moment and said: - -"But what will mamma say?" - -"How'll she ever know?" - -The girl turned the idea over in her mind, and said reluctantly: - -"I reckon it's wrong--but--" - -"But shucks! Your mother won't know, and so what's the harm? All she -wants is that you'll be safe; and I bet you she'd 'a' said go there if -she'd 'a' thought of it. I know she would!" - -The Widow Douglas' splendid hospitality was a tempting bait. It and -Tom's persuasions presently carried the day. So it was decided to say -nothing anybody about the night's programme. Presently it occurred to -Tom that maybe Huck might come this very night and give the signal. The -thought took a deal of the spirit out of his anticipations. Still he -could not bear to give up the fun at Widow Douglas'. And why should he -give it up, he reasoned--the signal did not come the night before, so -why should it be any more likely to come to-night? The sure fun of the -evening outweighed the uncertain treasure; and, boy-like, he determined -to yield to the stronger inclination and not allow himself to think of -the box of money another time that day. - -Three miles below town the ferryboat stopped at the mouth of a woody -hollow and tied up. The crowd swarmed ashore and soon the forest -distances and craggy heights echoed far and near with shoutings and -laughter. All the different ways of getting hot and tired were gone -through with, and by-and-by the rovers straggled back to camp fortified -with responsible appetites, and then the destruction of the good things -began. After the feast there was a refreshing season of rest and chat -in the shade of spreading oaks. By-and-by somebody shouted: - -"Who's ready for the cave?" - -Everybody was. Bundles of candles were procured, and straightway there -was a general scamper up the hill. The mouth of the cave was up the -hillside--an opening shaped like a letter A. Its massive oaken door -stood unbarred. Within was a small chamber, chilly as an ice-house, and -walled by Nature with solid limestone that was dewy with a cold sweat. -It was romantic and mysterious to stand here in the deep gloom and look -out upon the green valley shining in the sun. But the impressiveness of -the situation quickly wore off, and the romping began again. The moment -a candle was lighted there was a general rush upon the owner of it; a -struggle and a gallant defence followed, but the candle was soon -knocked down or blown out, and then there was a glad clamor of laughter -and a new chase. But all things have an end. By-and-by the procession -went filing down the steep descent of the main avenue, the flickering -rank of lights dimly revealing the lofty walls of rock almost to their -point of junction sixty feet overhead. This main avenue was not more -than eight or ten feet wide. Every few steps other lofty and still -narrower crevices branched from it on either hand--for McDougal's cave -was but a vast labyrinth of crooked aisles that ran into each other and -out again and led nowhere. It was said that one might wander days and -nights together through its intricate tangle of rifts and chasms, and -never find the end of the cave; and that he might go down, and down, -and still down, into the earth, and it was just the same--labyrinth -under labyrinth, and no end to any of them. No man "knew" the cave. -That was an impossible thing. Most of the young men knew a portion of -it, and it was not customary to venture much beyond this known portion. -Tom Sawyer knew as much of the cave as any one. - -The procession moved along the main avenue some three-quarters of a -mile, and then groups and couples began to slip aside into branch -avenues, fly along the dismal corridors, and take each other by -surprise at points where the corridors joined again. Parties were able -to elude each other for the space of half an hour without going beyond -the "known" ground. - -By-and-by, one group after another came straggling back to the mouth -of the cave, panting, hilarious, smeared from head to foot with tallow -drippings, daubed with clay, and entirely delighted with the success of -the day. Then they were astonished to find that they had been taking no -note of time and that night was about at hand. The clanging bell had -been calling for half an hour. However, this sort of close to the day's -adventures was romantic and therefore satisfactory. When the ferryboat -with her wild freight pushed into the stream, nobody cared sixpence for -the wasted time but the captain of the craft. - -Huck was already upon his watch when the ferryboat's lights went -glinting past the wharf. He heard no noise on board, for the young -people were as subdued and still as people usually are who are nearly -tired to death. He wondered what boat it was, and why she did not stop -at the wharf--and then he dropped her out of his mind and put his -attention upon his business. The night was growing cloudy and dark. Ten -o'clock came, and the noise of vehicles ceased, scattered lights began -to wink out, all straggling foot-passengers disappeared, the village -betook itself to its slumbers and left the small watcher alone with the -silence and the ghosts. Eleven o'clock came, and the tavern lights were -put out; darkness everywhere, now. Huck waited what seemed a weary long -time, but nothing happened. His faith was weakening. Was there any use? -Was there really any use? Why not give it up and turn in? - -A noise fell upon his ear. He was all attention in an instant. The -alley door closed softly. He sprang to the corner of the brick store. -The next moment two men brushed by him, and one seemed to have -something under his arm. It must be that box! So they were going to -remove the treasure. Why call Tom now? It would be absurd--the men -would get away with the box and never be found again. No, he would -stick to their wake and follow them; he would trust to the darkness for -security from discovery. So communing with himself, Huck stepped out -and glided along behind the men, cat-like, with bare feet, allowing -them to keep just far enough ahead not to be invisible. - -They moved up the river street three blocks, then turned to the left -up a cross-street. They went straight ahead, then, until they came to -the path that led up Cardiff Hill; this they took. They passed by the -old Welshman's house, half-way up the hill, without hesitating, and -still climbed upward. Good, thought Huck, they will bury it in the old -quarry. But they never stopped at the quarry. They passed on, up the -summit. They plunged into the narrow path between the tall sumach -bushes, and were at once hidden in the gloom. Huck closed up and -shortened his distance, now, for they would never be able to see him. -He trotted along awhile; then slackened his pace, fearing he was -gaining too fast; moved on a piece, then stopped altogether; listened; -no sound; none, save that he seemed to hear the beating of his own -heart. The hooting of an owl came over the hill--ominous sound! But no -footsteps. Heavens, was everything lost! He was about to spring with -winged feet, when a man cleared his throat not four feet from him! -Huck's heart shot into his throat, but he swallowed it again; and then -he stood there shaking as if a dozen agues had taken charge of him at -once, and so weak that he thought he must surely fall to the ground. He -knew where he was. He knew he was within five steps of the stile -leading into Widow Douglas' grounds. Very well, he thought, let them -bury it there; it won't be hard to find. - -Now there was a voice--a very low voice--Injun Joe's: - -"Damn her, maybe she's got company--there's lights, late as it is." - -"I can't see any." - -This was that stranger's voice--the stranger of the haunted house. A -deadly chill went to Huck's heart--this, then, was the "revenge" job! -His thought was, to fly. Then he remembered that the Widow Douglas had -been kind to him more than once, and maybe these men were going to -murder her. He wished he dared venture to warn her; but he knew he -didn't dare--they might come and catch him. He thought all this and -more in the moment that elapsed between the stranger's remark and Injun -Joe's next--which was-- - -"Because the bush is in your way. Now--this way--now you see, don't -you?" - -"Yes. Well, there IS company there, I reckon. Better give it up." - -"Give it up, and I just leaving this country forever! Give it up and -maybe never have another chance. I tell you again, as I've told you -before, I don't care for her swag--you may have it. But her husband was -rough on me--many times he was rough on me--and mainly he was the -justice of the peace that jugged me for a vagrant. And that ain't all. -It ain't a millionth part of it! He had me HORSEWHIPPED!--horsewhipped -in front of the jail, like a nigger!--with all the town looking on! -HORSEWHIPPED!--do you understand? He took advantage of me and died. But -I'll take it out of HER." - -"Oh, don't kill her! Don't do that!" - -"Kill? Who said anything about killing? I would kill HIM if he was -here; but not her. When you want to get revenge on a woman you don't -kill her--bosh! you go for her looks. You slit her nostrils--you notch -her ears like a sow!" - -"By God, that's--" - -"Keep your opinion to yourself! It will be safest for you. I'll tie -her to the bed. If she bleeds to death, is that my fault? I'll not cry, -if she does. My friend, you'll help me in this thing--for MY sake ---that's why you're here--I mightn't be able alone. If you flinch, I'll -kill you. Do you understand that? And if I have to kill you, I'll kill -her--and then I reckon nobody'll ever know much about who done this -business." - -"Well, if it's got to be done, let's get at it. The quicker the -better--I'm all in a shiver." - -"Do it NOW? And company there? Look here--I'll get suspicious of you, -first thing you know. No--we'll wait till the lights are out--there's -no hurry." - -Huck felt that a silence was going to ensue--a thing still more awful -than any amount of murderous talk; so he held his breath and stepped -gingerly back; planted his foot carefully and firmly, after balancing, -one-legged, in a precarious way and almost toppling over, first on one -side and then on the other. He took another step back, with the same -elaboration and the same risks; then another and another, and--a twig -snapped under his foot! His breath stopped and he listened. There was -no sound--the stillness was perfect. His gratitude was measureless. Now -he turned in his tracks, between the walls of sumach bushes--turned -himself as carefully as if he were a ship--and then stepped quickly but -cautiously along. When he emerged at the quarry he felt secure, and so -he picked up his nimble heels and flew. Down, down he sped, till he -reached the Welshman's. He banged at the door, and presently the heads -of the old man and his two stalwart sons were thrust from windows. - -"What's the row there? Who's banging? What do you want?" - -"Let me in--quick! I'll tell everything." - -"Why, who are you?" - -"Huckleberry Finn--quick, let me in!" - -"Huckleberry Finn, indeed! It ain't a name to open many doors, I -judge! But let him in, lads, and let's see what's the trouble." - -"Please don't ever tell I told you," were Huck's first words when he -got in. "Please don't--I'd be killed, sure--but the widow's been good -friends to me sometimes, and I want to tell--I WILL tell if you'll -promise you won't ever say it was me." - -"By George, he HAS got something to tell, or he wouldn't act so!" -exclaimed the old man; "out with it and nobody here'll ever tell, lad." - -Three minutes later the old man and his sons, well armed, were up the -hill, and just entering the sumach path on tiptoe, their weapons in -their hands. Huck accompanied them no further. He hid behind a great -bowlder and fell to listening. There was a lagging, anxious silence, -and then all of a sudden there was an explosion of firearms and a cry. - -Huck waited for no particulars. He sprang away and sped down the hill -as fast as his legs could carry him. - - - -CHAPTER XXX - -AS the earliest suspicion of dawn appeared on Sunday morning, Huck -came groping up the hill and rapped gently at the old Welshman's door. -The inmates were asleep, but it was a sleep that was set on a -hair-trigger, on account of the exciting episode of the night. A call -came from a window: - -"Who's there!" - -Huck's scared voice answered in a low tone: - -"Please let me in! It's only Huck Finn!" - -"It's a name that can open this door night or day, lad!--and welcome!" - -These were strange words to the vagabond boy's ears, and the -pleasantest he had ever heard. He could not recollect that the closing -word had ever been applied in his case before. The door was quickly -unlocked, and he entered. Huck was given a seat and the old man and his -brace of tall sons speedily dressed themselves. - -"Now, my boy, I hope you're good and hungry, because breakfast will be -ready as soon as the sun's up, and we'll have a piping hot one, too ---make yourself easy about that! I and the boys hoped you'd turn up and -stop here last night." - -"I was awful scared," said Huck, "and I run. I took out when the -pistols went off, and I didn't stop for three mile. I've come now becuz -I wanted to know about it, you know; and I come before daylight becuz I -didn't want to run across them devils, even if they was dead." - -"Well, poor chap, you do look as if you'd had a hard night of it--but -there's a bed here for you when you've had your breakfast. No, they -ain't dead, lad--we are sorry enough for that. You see we knew right -where to put our hands on them, by your description; so we crept along -on tiptoe till we got within fifteen feet of them--dark as a cellar -that sumach path was--and just then I found I was going to sneeze. It -was the meanest kind of luck! I tried to keep it back, but no use ---'twas bound to come, and it did come! I was in the lead with my pistol -raised, and when the sneeze started those scoundrels a-rustling to get -out of the path, I sung out, 'Fire boys!' and blazed away at the place -where the rustling was. So did the boys. But they were off in a jiffy, -those villains, and we after them, down through the woods. I judge we -never touched them. They fired a shot apiece as they started, but their -bullets whizzed by and didn't do us any harm. As soon as we lost the -sound of their feet we quit chasing, and went down and stirred up the -constables. They got a posse together, and went off to guard the river -bank, and as soon as it is light the sheriff and a gang are going to -beat up the woods. My boys will be with them presently. I wish we had -some sort of description of those rascals--'twould help a good deal. -But you couldn't see what they were like, in the dark, lad, I suppose?" - -"Oh yes; I saw them down-town and follered them." - -"Splendid! Describe them--describe them, my boy!" - -"One's the old deaf and dumb Spaniard that's ben around here once or -twice, and t'other's a mean-looking, ragged--" - -"That's enough, lad, we know the men! Happened on them in the woods -back of the widow's one day, and they slunk away. Off with you, boys, -and tell the sheriff--get your breakfast to-morrow morning!" - -The Welshman's sons departed at once. As they were leaving the room -Huck sprang up and exclaimed: - -"Oh, please don't tell ANYbody it was me that blowed on them! Oh, -please!" - -"All right if you say it, Huck, but you ought to have the credit of -what you did." - -"Oh no, no! Please don't tell!" - -When the young men were gone, the old Welshman said: - -"They won't tell--and I won't. But why don't you want it known?" - -Huck would not explain, further than to say that he already knew too -much about one of those men and would not have the man know that he -knew anything against him for the whole world--he would be killed for -knowing it, sure. - -The old man promised secrecy once more, and said: - -"How did you come to follow these fellows, lad? Were they looking -suspicious?" - -Huck was silent while he framed a duly cautious reply. Then he said: - -"Well, you see, I'm a kind of a hard lot,--least everybody says so, -and I don't see nothing agin it--and sometimes I can't sleep much, on -account of thinking about it and sort of trying to strike out a new way -of doing. That was the way of it last night. I couldn't sleep, and so I -come along up-street 'bout midnight, a-turning it all over, and when I -got to that old shackly brick store by the Temperance Tavern, I backed -up agin the wall to have another think. Well, just then along comes -these two chaps slipping along close by me, with something under their -arm, and I reckoned they'd stole it. One was a-smoking, and t'other one -wanted a light; so they stopped right before me and the cigars lit up -their faces and I see that the big one was the deaf and dumb Spaniard, -by his white whiskers and the patch on his eye, and t'other one was a -rusty, ragged-looking devil." - -"Could you see the rags by the light of the cigars?" - -This staggered Huck for a moment. Then he said: - -"Well, I don't know--but somehow it seems as if I did." - -"Then they went on, and you--" - -"Follered 'em--yes. That was it. I wanted to see what was up--they -sneaked along so. I dogged 'em to the widder's stile, and stood in the -dark and heard the ragged one beg for the widder, and the Spaniard -swear he'd spile her looks just as I told you and your two--" - -"What! The DEAF AND DUMB man said all that!" - -Huck had made another terrible mistake! He was trying his best to keep -the old man from getting the faintest hint of who the Spaniard might -be, and yet his tongue seemed determined to get him into trouble in -spite of all he could do. He made several efforts to creep out of his -scrape, but the old man's eye was upon him and he made blunder after -blunder. Presently the Welshman said: - -"My boy, don't be afraid of me. I wouldn't hurt a hair of your head -for all the world. No--I'd protect you--I'd protect you. This Spaniard -is not deaf and dumb; you've let that slip without intending it; you -can't cover that up now. You know something about that Spaniard that -you want to keep dark. Now trust me--tell me what it is, and trust me ---I won't betray you." - -Huck looked into the old man's honest eyes a moment, then bent over -and whispered in his ear: - -"'Tain't a Spaniard--it's Injun Joe!" - -The Welshman almost jumped out of his chair. In a moment he said: - -"It's all plain enough, now. When you talked about notching ears and -slitting noses I judged that that was your own embellishment, because -white men don't take that sort of revenge. But an Injun! That's a -different matter altogether." - -During breakfast the talk went on, and in the course of it the old man -said that the last thing which he and his sons had done, before going -to bed, was to get a lantern and examine the stile and its vicinity for -marks of blood. They found none, but captured a bulky bundle of-- - -"Of WHAT?" - -If the words had been lightning they could not have leaped with a more -stunning suddenness from Huck's blanched lips. His eyes were staring -wide, now, and his breath suspended--waiting for the answer. The -Welshman started--stared in return--three seconds--five seconds--ten ---then replied: - -"Of burglar's tools. Why, what's the MATTER with you?" - -Huck sank back, panting gently, but deeply, unutterably grateful. The -Welshman eyed him gravely, curiously--and presently said: - -"Yes, burglar's tools. That appears to relieve you a good deal. But -what did give you that turn? What were YOU expecting we'd found?" - -Huck was in a close place--the inquiring eye was upon him--he would -have given anything for material for a plausible answer--nothing -suggested itself--the inquiring eye was boring deeper and deeper--a -senseless reply offered--there was no time to weigh it, so at a venture -he uttered it--feebly: - -"Sunday-school books, maybe." - -Poor Huck was too distressed to smile, but the old man laughed loud -and joyously, shook up the details of his anatomy from head to foot, -and ended by saying that such a laugh was money in a-man's pocket, -because it cut down the doctor's bill like everything. Then he added: - -"Poor old chap, you're white and jaded--you ain't well a bit--no -wonder you're a little flighty and off your balance. But you'll come -out of it. Rest and sleep will fetch you out all right, I hope." - -Huck was irritated to think he had been such a goose and betrayed such -a suspicious excitement, for he had dropped the idea that the parcel -brought from the tavern was the treasure, as soon as he had heard the -talk at the widow's stile. He had only thought it was not the treasure, -however--he had not known that it wasn't--and so the suggestion of a -captured bundle was too much for his self-possession. But on the whole -he felt glad the little episode had happened, for now he knew beyond -all question that that bundle was not THE bundle, and so his mind was -at rest and exceedingly comfortable. In fact, everything seemed to be -drifting just in the right direction, now; the treasure must be still -in No. 2, the men would be captured and jailed that day, and he and Tom -could seize the gold that night without any trouble or any fear of -interruption. - -Just as breakfast was completed there was a knock at the door. Huck -jumped for a hiding-place, for he had no mind to be connected even -remotely with the late event. The Welshman admitted several ladies and -gentlemen, among them the Widow Douglas, and noticed that groups of -citizens were climbing up the hill--to stare at the stile. So the news -had spread. The Welshman had to tell the story of the night to the -visitors. The widow's gratitude for her preservation was outspoken. - -"Don't say a word about it, madam. There's another that you're more -beholden to than you are to me and my boys, maybe, but he don't allow -me to tell his name. We wouldn't have been there but for him." - -Of course this excited a curiosity so vast that it almost belittled -the main matter--but the Welshman allowed it to eat into the vitals of -his visitors, and through them be transmitted to the whole town, for he -refused to part with his secret. When all else had been learned, the -widow said: - -"I went to sleep reading in bed and slept straight through all that -noise. Why didn't you come and wake me?" - -"We judged it warn't worth while. Those fellows warn't likely to come -again--they hadn't any tools left to work with, and what was the use of -waking you up and scaring you to death? My three negro men stood guard -at your house all the rest of the night. They've just come back." - -More visitors came, and the story had to be told and retold for a -couple of hours more. - -There was no Sabbath-school during day-school vacation, but everybody -was early at church. The stirring event was well canvassed. News came -that not a sign of the two villains had been yet discovered. When the -sermon was finished, Judge Thatcher's wife dropped alongside of Mrs. -Harper as she moved down the aisle with the crowd and said: - -"Is my Becky going to sleep all day? I just expected she would be -tired to death." - -"Your Becky?" - -"Yes," with a startled look--"didn't she stay with you last night?" - -"Why, no." - -Mrs. Thatcher turned pale, and sank into a pew, just as Aunt Polly, -talking briskly with a friend, passed by. Aunt Polly said: - -"Good-morning, Mrs. Thatcher. Good-morning, Mrs. Harper. I've got a -boy that's turned up missing. I reckon my Tom stayed at your house last -night--one of you. And now he's afraid to come to church. I've got to -settle with him." - -Mrs. Thatcher shook her head feebly and turned paler than ever. - -"He didn't stay with us," said Mrs. Harper, beginning to look uneasy. -A marked anxiety came into Aunt Polly's face. - -"Joe Harper, have you seen my Tom this morning?" - -"No'm." - -"When did you see him last?" - -Joe tried to remember, but was not sure he could say. The people had -stopped moving out of church. Whispers passed along, and a boding -uneasiness took possession of every countenance. Children were -anxiously questioned, and young teachers. They all said they had not -noticed whether Tom and Becky were on board the ferryboat on the -homeward trip; it was dark; no one thought of inquiring if any one was -missing. One young man finally blurted out his fear that they were -still in the cave! Mrs. Thatcher swooned away. Aunt Polly fell to -crying and wringing her hands. - -The alarm swept from lip to lip, from group to group, from street to -street, and within five minutes the bells were wildly clanging and the -whole town was up! The Cardiff Hill episode sank into instant -insignificance, the burglars were forgotten, horses were saddled, -skiffs were manned, the ferryboat ordered out, and before the horror -was half an hour old, two hundred men were pouring down highroad and -river toward the cave. - -All the long afternoon the village seemed empty and dead. Many women -visited Aunt Polly and Mrs. Thatcher and tried to comfort them. They -cried with them, too, and that was still better than words. All the -tedious night the town waited for news; but when the morning dawned at -last, all the word that came was, "Send more candles--and send food." -Mrs. Thatcher was almost crazed; and Aunt Polly, also. Judge Thatcher -sent messages of hope and encouragement from the cave, but they -conveyed no real cheer. - -The old Welshman came home toward daylight, spattered with -candle-grease, smeared with clay, and almost worn out. He found Huck -still in the bed that had been provided for him, and delirious with -fever. The physicians were all at the cave, so the Widow Douglas came -and took charge of the patient. She said she would do her best by him, -because, whether he was good, bad, or indifferent, he was the Lord's, -and nothing that was the Lord's was a thing to be neglected. The -Welshman said Huck had good spots in him, and the widow said: - -"You can depend on it. That's the Lord's mark. He don't leave it off. -He never does. Puts it somewhere on every creature that comes from his -hands." - -Early in the forenoon parties of jaded men began to straggle into the -village, but the strongest of the citizens continued searching. All the -news that could be gained was that remotenesses of the cavern were -being ransacked that had never been visited before; that every corner -and crevice was going to be thoroughly searched; that wherever one -wandered through the maze of passages, lights were to be seen flitting -hither and thither in the distance, and shoutings and pistol-shots sent -their hollow reverberations to the ear down the sombre aisles. In one -place, far from the section usually traversed by tourists, the names -"BECKY & TOM" had been found traced upon the rocky wall with -candle-smoke, and near at hand a grease-soiled bit of ribbon. Mrs. -Thatcher recognized the ribbon and cried over it. She said it was the -last relic she should ever have of her child; and that no other memorial -of her could ever be so precious, because this one parted latest from -the living body before the awful death came. Some said that now and -then, in the cave, a far-away speck of light would glimmer, and then a -glorious shout would burst forth and a score of men go trooping down the -echoing aisle--and then a sickening disappointment always followed; the -children were not there; it was only a searcher's light. - -Three dreadful days and nights dragged their tedious hours along, and -the village sank into a hopeless stupor. No one had heart for anything. -The accidental discovery, just made, that the proprietor of the -Temperance Tavern kept liquor on his premises, scarcely fluttered the -public pulse, tremendous as the fact was. In a lucid interval, Huck -feebly led up to the subject of taverns, and finally asked--dimly -dreading the worst--if anything had been discovered at the Temperance -Tavern since he had been ill. - -"Yes," said the widow. - -Huck started up in bed, wild-eyed: - -"What? What was it?" - -"Liquor!--and the place has been shut up. Lie down, child--what a turn -you did give me!" - -"Only tell me just one thing--only just one--please! Was it Tom Sawyer -that found it?" - -The widow burst into tears. "Hush, hush, child, hush! I've told you -before, you must NOT talk. You are very, very sick!" - -Then nothing but liquor had been found; there would have been a great -powwow if it had been the gold. So the treasure was gone forever--gone -forever! But what could she be crying about? Curious that she should -cry. - -These thoughts worked their dim way through Huck's mind, and under the -weariness they gave him he fell asleep. The widow said to herself: - -"There--he's asleep, poor wreck. Tom Sawyer find it! Pity but somebody -could find Tom Sawyer! Ah, there ain't many left, now, that's got hope -enough, or strength enough, either, to go on searching." - - - -CHAPTER XXXI - -NOW to return to Tom and Becky's share in the picnic. They tripped -along the murky aisles with the rest of the company, visiting the -familiar wonders of the cave--wonders dubbed with rather -over-descriptive names, such as "The Drawing-Room," "The Cathedral," -"Aladdin's Palace," and so on. Presently the hide-and-seek frolicking -began, and Tom and Becky engaged in it with zeal until the exertion -began to grow a trifle wearisome; then they wandered down a sinuous -avenue holding their candles aloft and reading the tangled web-work of -names, dates, post-office addresses, and mottoes with which the rocky -walls had been frescoed (in candle-smoke). Still drifting along and -talking, they scarcely noticed that they were now in a part of the cave -whose walls were not frescoed. They smoked their own names under an -overhanging shelf and moved on. Presently they came to a place where a -little stream of water, trickling over a ledge and carrying a limestone -sediment with it, had, in the slow-dragging ages, formed a laced and -ruffled Niagara in gleaming and imperishable stone. Tom squeezed his -small body behind it in order to illuminate it for Becky's -gratification. He found that it curtained a sort of steep natural -stairway which was enclosed between narrow walls, and at once the -ambition to be a discoverer seized him. Becky responded to his call, -and they made a smoke-mark for future guidance, and started upon their -quest. They wound this way and that, far down into the secret depths of -the cave, made another mark, and branched off in search of novelties to -tell the upper world about. In one place they found a spacious cavern, -from whose ceiling depended a multitude of shining stalactites of the -length and circumference of a man's leg; they walked all about it, -wondering and admiring, and presently left it by one of the numerous -passages that opened into it. This shortly brought them to a bewitching -spring, whose basin was incrusted with a frostwork of glittering -crystals; it was in the midst of a cavern whose walls were supported by -many fantastic pillars which had been formed by the joining of great -stalactites and stalagmites together, the result of the ceaseless -water-drip of centuries. Under the roof vast knots of bats had packed -themselves together, thousands in a bunch; the lights disturbed the -creatures and they came flocking down by hundreds, squeaking and -darting furiously at the candles. Tom knew their ways and the danger of -this sort of conduct. He seized Becky's hand and hurried her into the -first corridor that offered; and none too soon, for a bat struck -Becky's light out with its wing while she was passing out of the -cavern. The bats chased the children a good distance; but the fugitives -plunged into every new passage that offered, and at last got rid of the -perilous things. Tom found a subterranean lake, shortly, which -stretched its dim length away until its shape was lost in the shadows. -He wanted to explore its borders, but concluded that it would be best -to sit down and rest awhile, first. Now, for the first time, the deep -stillness of the place laid a clammy hand upon the spirits of the -children. Becky said: - -"Why, I didn't notice, but it seems ever so long since I heard any of -the others." - -"Come to think, Becky, we are away down below them--and I don't know -how far away north, or south, or east, or whichever it is. We couldn't -hear them here." - -Becky grew apprehensive. - -"I wonder how long we've been down here, Tom? We better start back." - -"Yes, I reckon we better. P'raps we better." - -"Can you find the way, Tom? It's all a mixed-up crookedness to me." - -"I reckon I could find it--but then the bats. If they put our candles -out it will be an awful fix. Let's try some other way, so as not to go -through there." - -"Well. But I hope we won't get lost. It would be so awful!" and the -girl shuddered at the thought of the dreadful possibilities. - -They started through a corridor, and traversed it in silence a long -way, glancing at each new opening, to see if there was anything -familiar about the look of it; but they were all strange. Every time -Tom made an examination, Becky would watch his face for an encouraging -sign, and he would say cheerily: - -"Oh, it's all right. This ain't the one, but we'll come to it right -away!" - -But he felt less and less hopeful with each failure, and presently -began to turn off into diverging avenues at sheer random, in desperate -hope of finding the one that was wanted. He still said it was "all -right," but there was such a leaden dread at his heart that the words -had lost their ring and sounded just as if he had said, "All is lost!" -Becky clung to his side in an anguish of fear, and tried hard to keep -back the tears, but they would come. At last she said: - -"Oh, Tom, never mind the bats, let's go back that way! We seem to get -worse and worse off all the time." - -"Listen!" said he. - -Profound silence; silence so deep that even their breathings were -conspicuous in the hush. Tom shouted. The call went echoing down the -empty aisles and died out in the distance in a faint sound that -resembled a ripple of mocking laughter. - -"Oh, don't do it again, Tom, it is too horrid," said Becky. - -"It is horrid, but I better, Becky; they might hear us, you know," and -he shouted again. - -The "might" was even a chillier horror than the ghostly laughter, it -so confessed a perishing hope. The children stood still and listened; -but there was no result. Tom turned upon the back track at once, and -hurried his steps. It was but a little while before a certain -indecision in his manner revealed another fearful fact to Becky--he -could not find his way back! - -"Oh, Tom, you didn't make any marks!" - -"Becky, I was such a fool! Such a fool! I never thought we might want -to come back! No--I can't find the way. It's all mixed up." - -"Tom, Tom, we're lost! we're lost! We never can get out of this awful -place! Oh, why DID we ever leave the others!" - -She sank to the ground and burst into such a frenzy of crying that Tom -was appalled with the idea that she might die, or lose her reason. He -sat down by her and put his arms around her; she buried her face in his -bosom, she clung to him, she poured out her terrors, her unavailing -regrets, and the far echoes turned them all to jeering laughter. Tom -begged her to pluck up hope again, and she said she could not. He fell -to blaming and abusing himself for getting her into this miserable -situation; this had a better effect. She said she would try to hope -again, she would get up and follow wherever he might lead if only he -would not talk like that any more. For he was no more to blame than -she, she said. - -So they moved on again--aimlessly--simply at random--all they could do -was to move, keep moving. For a little while, hope made a show of -reviving--not with any reason to back it, but only because it is its -nature to revive when the spring has not been taken out of it by age -and familiarity with failure. - -By-and-by Tom took Becky's candle and blew it out. This economy meant -so much! Words were not needed. Becky understood, and her hope died -again. She knew that Tom had a whole candle and three or four pieces in -his pockets--yet he must economize. - -By-and-by, fatigue began to assert its claims; the children tried to -pay attention, for it was dreadful to think of sitting down when time -was grown to be so precious, moving, in some direction, in any -direction, was at least progress and might bear fruit; but to sit down -was to invite death and shorten its pursuit. - -At last Becky's frail limbs refused to carry her farther. She sat -down. Tom rested with her, and they talked of home, and the friends -there, and the comfortable beds and, above all, the light! Becky cried, -and Tom tried to think of some way of comforting her, but all his -encouragements were grown threadbare with use, and sounded like -sarcasms. Fatigue bore so heavily upon Becky that she drowsed off to -sleep. Tom was grateful. He sat looking into her drawn face and saw it -grow smooth and natural under the influence of pleasant dreams; and -by-and-by a smile dawned and rested there. The peaceful face reflected -somewhat of peace and healing into his own spirit, and his thoughts -wandered away to bygone times and dreamy memories. While he was deep in -his musings, Becky woke up with a breezy little laugh--but it was -stricken dead upon her lips, and a groan followed it. - -"Oh, how COULD I sleep! I wish I never, never had waked! No! No, I -don't, Tom! Don't look so! I won't say it again." - -"I'm glad you've slept, Becky; you'll feel rested, now, and we'll find -the way out." - -"We can try, Tom; but I've seen such a beautiful country in my dream. -I reckon we are going there." - -"Maybe not, maybe not. Cheer up, Becky, and let's go on trying." - -They rose up and wandered along, hand in hand and hopeless. They tried -to estimate how long they had been in the cave, but all they knew was -that it seemed days and weeks, and yet it was plain that this could not -be, for their candles were not gone yet. A long time after this--they -could not tell how long--Tom said they must go softly and listen for -dripping water--they must find a spring. They found one presently, and -Tom said it was time to rest again. Both were cruelly tired, yet Becky -said she thought she could go a little farther. She was surprised to -hear Tom dissent. She could not understand it. They sat down, and Tom -fastened his candle to the wall in front of them with some clay. -Thought was soon busy; nothing was said for some time. Then Becky broke -the silence: - -"Tom, I am so hungry!" - -Tom took something out of his pocket. - -"Do you remember this?" said he. - -Becky almost smiled. - -"It's our wedding-cake, Tom." - -"Yes--I wish it was as big as a barrel, for it's all we've got." - -"I saved it from the picnic for us to dream on, Tom, the way grown-up -people do with wedding-cake--but it'll be our--" - -She dropped the sentence where it was. Tom divided the cake and Becky -ate with good appetite, while Tom nibbled at his moiety. There was -abundance of cold water to finish the feast with. By-and-by Becky -suggested that they move on again. Tom was silent a moment. Then he -said: - -"Becky, can you bear it if I tell you something?" - -Becky's face paled, but she thought she could. - -"Well, then, Becky, we must stay here, where there's water to drink. -That little piece is our last candle!" - -Becky gave loose to tears and wailings. Tom did what he could to -comfort her, but with little effect. At length Becky said: - -"Tom!" - -"Well, Becky?" - -"They'll miss us and hunt for us!" - -"Yes, they will! Certainly they will!" - -"Maybe they're hunting for us now, Tom." - -"Why, I reckon maybe they are. I hope they are." - -"When would they miss us, Tom?" - -"When they get back to the boat, I reckon." - -"Tom, it might be dark then--would they notice we hadn't come?" - -"I don't know. But anyway, your mother would miss you as soon as they -got home." - -A frightened look in Becky's face brought Tom to his senses and he saw -that he had made a blunder. Becky was not to have gone home that night! -The children became silent and thoughtful. In a moment a new burst of -grief from Becky showed Tom that the thing in his mind had struck hers -also--that the Sabbath morning might be half spent before Mrs. Thatcher -discovered that Becky was not at Mrs. Harper's. - -The children fastened their eyes upon their bit of candle and watched -it melt slowly and pitilessly away; saw the half inch of wick stand -alone at last; saw the feeble flame rise and fall, climb the thin -column of smoke, linger at its top a moment, and then--the horror of -utter darkness reigned! - -How long afterward it was that Becky came to a slow consciousness that -she was crying in Tom's arms, neither could tell. All that they knew -was, that after what seemed a mighty stretch of time, both awoke out of -a dead stupor of sleep and resumed their miseries once more. Tom said -it might be Sunday, now--maybe Monday. He tried to get Becky to talk, -but her sorrows were too oppressive, all her hopes were gone. Tom said -that they must have been missed long ago, and no doubt the search was -going on. He would shout and maybe some one would come. He tried it; -but in the darkness the distant echoes sounded so hideously that he -tried it no more. - -The hours wasted away, and hunger came to torment the captives again. -A portion of Tom's half of the cake was left; they divided and ate it. -But they seemed hungrier than before. The poor morsel of food only -whetted desire. - -By-and-by Tom said: - -"SH! Did you hear that?" - -Both held their breath and listened. There was a sound like the -faintest, far-off shout. Instantly Tom answered it, and leading Becky -by the hand, started groping down the corridor in its direction. -Presently he listened again; again the sound was heard, and apparently -a little nearer. - -"It's them!" said Tom; "they're coming! Come along, Becky--we're all -right now!" - -The joy of the prisoners was almost overwhelming. Their speed was -slow, however, because pitfalls were somewhat common, and had to be -guarded against. They shortly came to one and had to stop. It might be -three feet deep, it might be a hundred--there was no passing it at any -rate. Tom got down on his breast and reached as far down as he could. -No bottom. They must stay there and wait until the searchers came. They -listened; evidently the distant shoutings were growing more distant! a -moment or two more and they had gone altogether. The heart-sinking -misery of it! Tom whooped until he was hoarse, but it was of no use. He -talked hopefully to Becky; but an age of anxious waiting passed and no -sounds came again. - -The children groped their way back to the spring. The weary time -dragged on; they slept again, and awoke famished and woe-stricken. Tom -believed it must be Tuesday by this time. - -Now an idea struck him. There were some side passages near at hand. It -would be better to explore some of these than bear the weight of the -heavy time in idleness. He took a kite-line from his pocket, tied it to -a projection, and he and Becky started, Tom in the lead, unwinding the -line as he groped along. At the end of twenty steps the corridor ended -in a "jumping-off place." Tom got down on his knees and felt below, and -then as far around the corner as he could reach with his hands -conveniently; he made an effort to stretch yet a little farther to the -right, and at that moment, not twenty yards away, a human hand, holding -a candle, appeared from behind a rock! Tom lifted up a glorious shout, -and instantly that hand was followed by the body it belonged to--Injun -Joe's! Tom was paralyzed; he could not move. He was vastly gratified -the next moment, to see the "Spaniard" take to his heels and get -himself out of sight. Tom wondered that Joe had not recognized his -voice and come over and killed him for testifying in court. But the -echoes must have disguised the voice. Without doubt, that was it, he -reasoned. Tom's fright weakened every muscle in his body. He said to -himself that if he had strength enough to get back to the spring he -would stay there, and nothing should tempt him to run the risk of -meeting Injun Joe again. He was careful to keep from Becky what it was -he had seen. He told her he had only shouted "for luck." - -But hunger and wretchedness rise superior to fears in the long run. -Another tedious wait at the spring and another long sleep brought -changes. The children awoke tortured with a raging hunger. Tom believed -that it must be Wednesday or Thursday or even Friday or Saturday, now, -and that the search had been given over. He proposed to explore another -passage. He felt willing to risk Injun Joe and all other terrors. But -Becky was very weak. She had sunk into a dreary apathy and would not be -roused. She said she would wait, now, where she was, and die--it would -not be long. She told Tom to go with the kite-line and explore if he -chose; but she implored him to come back every little while and speak -to her; and she made him promise that when the awful time came, he -would stay by her and hold her hand until all was over. - -Tom kissed her, with a choking sensation in his throat, and made a -show of being confident of finding the searchers or an escape from the -cave; then he took the kite-line in his hand and went groping down one -of the passages on his hands and knees, distressed with hunger and sick -with bodings of coming doom. - - - -CHAPTER XXXII - -TUESDAY afternoon came, and waned to the twilight. The village of St. -Petersburg still mourned. The lost children had not been found. Public -prayers had been offered up for them, and many and many a private -prayer that had the petitioner's whole heart in it; but still no good -news came from the cave. The majority of the searchers had given up the -quest and gone back to their daily avocations, saying that it was plain -the children could never be found. Mrs. Thatcher was very ill, and a -great part of the time delirious. People said it was heartbreaking to -hear her call her child, and raise her head and listen a whole minute -at a time, then lay it wearily down again with a moan. Aunt Polly had -drooped into a settled melancholy, and her gray hair had grown almost -white. The village went to its rest on Tuesday night, sad and forlorn. - -Away in the middle of the night a wild peal burst from the village -bells, and in a moment the streets were swarming with frantic half-clad -people, who shouted, "Turn out! turn out! they're found! they're -found!" Tin pans and horns were added to the din, the population massed -itself and moved toward the river, met the children coming in an open -carriage drawn by shouting citizens, thronged around it, joined its -homeward march, and swept magnificently up the main street roaring -huzzah after huzzah! - -The village was illuminated; nobody went to bed again; it was the -greatest night the little town had ever seen. During the first half-hour -a procession of villagers filed through Judge Thatcher's house, seized -the saved ones and kissed them, squeezed Mrs. Thatcher's hand, tried to -speak but couldn't--and drifted out raining tears all over the place. - -Aunt Polly's happiness was complete, and Mrs. Thatcher's nearly so. It -would be complete, however, as soon as the messenger dispatched with -the great news to the cave should get the word to her husband. Tom lay -upon a sofa with an eager auditory about him and told the history of -the wonderful adventure, putting in many striking additions to adorn it -withal; and closed with a description of how he left Becky and went on -an exploring expedition; how he followed two avenues as far as his -kite-line would reach; how he followed a third to the fullest stretch of -the kite-line, and was about to turn back when he glimpsed a far-off -speck that looked like daylight; dropped the line and groped toward it, -pushed his head and shoulders through a small hole, and saw the broad -Mississippi rolling by! And if it had only happened to be night he would -not have seen that speck of daylight and would not have explored that -passage any more! He told how he went back for Becky and broke the good -news and she told him not to fret her with such stuff, for she was -tired, and knew she was going to die, and wanted to. He described how he -labored with her and convinced her; and how she almost died for joy when -she had groped to where she actually saw the blue speck of daylight; how -he pushed his way out at the hole and then helped her out; how they sat -there and cried for gladness; how some men came along in a skiff and Tom -hailed them and told them their situation and their famished condition; -how the men didn't believe the wild tale at first, "because," said they, -"you are five miles down the river below the valley the cave is in" ---then took them aboard, rowed to a house, gave them supper, made them -rest till two or three hours after dark and then brought them home. - -Before day-dawn, Judge Thatcher and the handful of searchers with him -were tracked out, in the cave, by the twine clews they had strung -behind them, and informed of the great news. - -Three days and nights of toil and hunger in the cave were not to be -shaken off at once, as Tom and Becky soon discovered. They were -bedridden all of Wednesday and Thursday, and seemed to grow more and -more tired and worn, all the time. Tom got about, a little, on -Thursday, was down-town Friday, and nearly as whole as ever Saturday; -but Becky did not leave her room until Sunday, and then she looked as -if she had passed through a wasting illness. - -Tom learned of Huck's sickness and went to see him on Friday, but -could not be admitted to the bedroom; neither could he on Saturday or -Sunday. He was admitted daily after that, but was warned to keep still -about his adventure and introduce no exciting topic. The Widow Douglas -stayed by to see that he obeyed. At home Tom learned of the Cardiff -Hill event; also that the "ragged man's" body had eventually been found -in the river near the ferry-landing; he had been drowned while trying -to escape, perhaps. - -About a fortnight after Tom's rescue from the cave, he started off to -visit Huck, who had grown plenty strong enough, now, to hear exciting -talk, and Tom had some that would interest him, he thought. Judge -Thatcher's house was on Tom's way, and he stopped to see Becky. The -Judge and some friends set Tom to talking, and some one asked him -ironically if he wouldn't like to go to the cave again. Tom said he -thought he wouldn't mind it. The Judge said: - -"Well, there are others just like you, Tom, I've not the least doubt. -But we have taken care of that. Nobody will get lost in that cave any -more." - -"Why?" - -"Because I had its big door sheathed with boiler iron two weeks ago, -and triple-locked--and I've got the keys." - -Tom turned as white as a sheet. - -"What's the matter, boy! Here, run, somebody! Fetch a glass of water!" - -The water was brought and thrown into Tom's face. - -"Ah, now you're all right. What was the matter with you, Tom?" - -"Oh, Judge, Injun Joe's in the cave!" - - - -CHAPTER XXXIII - -WITHIN a few minutes the news had spread, and a dozen skiff-loads of -men were on their way to McDougal's cave, and the ferryboat, well -filled with passengers, soon followed. Tom Sawyer was in the skiff that -bore Judge Thatcher. - -When the cave door was unlocked, a sorrowful sight presented itself in -the dim twilight of the place. Injun Joe lay stretched upon the ground, -dead, with his face close to the crack of the door, as if his longing -eyes had been fixed, to the latest moment, upon the light and the cheer -of the free world outside. Tom was touched, for he knew by his own -experience how this wretch had suffered. His pity was moved, but -nevertheless he felt an abounding sense of relief and security, now, -which revealed to him in a degree which he had not fully appreciated -before how vast a weight of dread had been lying upon him since the day -he lifted his voice against this bloody-minded outcast. - -Injun Joe's bowie-knife lay close by, its blade broken in two. The -great foundation-beam of the door had been chipped and hacked through, -with tedious labor; useless labor, too, it was, for the native rock -formed a sill outside it, and upon that stubborn material the knife had -wrought no effect; the only damage done was to the knife itself. But if -there had been no stony obstruction there the labor would have been -useless still, for if the beam had been wholly cut away Injun Joe could -not have squeezed his body under the door, and he knew it. So he had -only hacked that place in order to be doing something--in order to pass -the weary time--in order to employ his tortured faculties. Ordinarily -one could find half a dozen bits of candle stuck around in the crevices -of this vestibule, left there by tourists; but there were none now. The -prisoner had searched them out and eaten them. He had also contrived to -catch a few bats, and these, also, he had eaten, leaving only their -claws. The poor unfortunate had starved to death. In one place, near at -hand, a stalagmite had been slowly growing up from the ground for ages, -builded by the water-drip from a stalactite overhead. The captive had -broken off the stalagmite, and upon the stump had placed a stone, -wherein he had scooped a shallow hollow to catch the precious drop -that fell once in every three minutes with the dreary regularity of a -clock-tick--a dessertspoonful once in four and twenty hours. That drop -was falling when the Pyramids were new; when Troy fell; when the -foundations of Rome were laid; when Christ was crucified; when the -Conqueror created the British empire; when Columbus sailed; when the -massacre at Lexington was "news." It is falling now; it will still be -falling when all these things shall have sunk down the afternoon of -history, and the twilight of tradition, and been swallowed up in the -thick night of oblivion. Has everything a purpose and a mission? Did -this drop fall patiently during five thousand years to be ready for -this flitting human insect's need? and has it another important object -to accomplish ten thousand years to come? No matter. It is many and -many a year since the hapless half-breed scooped out the stone to catch -the priceless drops, but to this day the tourist stares longest at that -pathetic stone and that slow-dropping water when he comes to see the -wonders of McDougal's cave. Injun Joe's cup stands first in the list of -the cavern's marvels; even "Aladdin's Palace" cannot rival it. - -Injun Joe was buried near the mouth of the cave; and people flocked -there in boats and wagons from the towns and from all the farms and -hamlets for seven miles around; they brought their children, and all -sorts of provisions, and confessed that they had had almost as -satisfactory a time at the funeral as they could have had at the -hanging. - -This funeral stopped the further growth of one thing--the petition to -the governor for Injun Joe's pardon. The petition had been largely -signed; many tearful and eloquent meetings had been held, and a -committee of sappy women been appointed to go in deep mourning and wail -around the governor, and implore him to be a merciful ass and trample -his duty under foot. Injun Joe was believed to have killed five -citizens of the village, but what of that? If he had been Satan himself -there would have been plenty of weaklings ready to scribble their names -to a pardon-petition, and drip a tear on it from their permanently -impaired and leaky water-works. - -The morning after the funeral Tom took Huck to a private place to have -an important talk. Huck had learned all about Tom's adventure from the -Welshman and the Widow Douglas, by this time, but Tom said he reckoned -there was one thing they had not told him; that thing was what he -wanted to talk about now. Huck's face saddened. He said: - -"I know what it is. You got into No. 2 and never found anything but -whiskey. Nobody told me it was you; but I just knowed it must 'a' ben -you, soon as I heard 'bout that whiskey business; and I knowed you -hadn't got the money becuz you'd 'a' got at me some way or other and -told me even if you was mum to everybody else. Tom, something's always -told me we'd never get holt of that swag." - -"Why, Huck, I never told on that tavern-keeper. YOU know his tavern -was all right the Saturday I went to the picnic. Don't you remember you -was to watch there that night?" - -"Oh yes! Why, it seems 'bout a year ago. It was that very night that I -follered Injun Joe to the widder's." - -"YOU followed him?" - -"Yes--but you keep mum. I reckon Injun Joe's left friends behind him, -and I don't want 'em souring on me and doing me mean tricks. If it -hadn't ben for me he'd be down in Texas now, all right." - -Then Huck told his entire adventure in confidence to Tom, who had only -heard of the Welshman's part of it before. - -"Well," said Huck, presently, coming back to the main question, -"whoever nipped the whiskey in No. 2, nipped the money, too, I reckon ---anyways it's a goner for us, Tom." - -"Huck, that money wasn't ever in No. 2!" - -"What!" Huck searched his comrade's face keenly. "Tom, have you got on -the track of that money again?" - -"Huck, it's in the cave!" - -Huck's eyes blazed. - -"Say it again, Tom." - -"The money's in the cave!" - -"Tom--honest injun, now--is it fun, or earnest?" - -"Earnest, Huck--just as earnest as ever I was in my life. Will you go -in there with me and help get it out?" - -"I bet I will! I will if it's where we can blaze our way to it and not -get lost." - -"Huck, we can do that without the least little bit of trouble in the -world." - -"Good as wheat! What makes you think the money's--" - -"Huck, you just wait till we get in there. If we don't find it I'll -agree to give you my drum and every thing I've got in the world. I -will, by jings." - -"All right--it's a whiz. When do you say?" - -"Right now, if you say it. Are you strong enough?" - -"Is it far in the cave? I ben on my pins a little, three or four days, -now, but I can't walk more'n a mile, Tom--least I don't think I could." - -"It's about five mile into there the way anybody but me would go, -Huck, but there's a mighty short cut that they don't anybody but me -know about. Huck, I'll take you right to it in a skiff. I'll float the -skiff down there, and I'll pull it back again all by myself. You -needn't ever turn your hand over." - -"Less start right off, Tom." - -"All right. We want some bread and meat, and our pipes, and a little -bag or two, and two or three kite-strings, and some of these -new-fangled things they call lucifer matches. I tell you, many's -the time I wished I had some when I was in there before." - -A trifle after noon the boys borrowed a small skiff from a citizen who -was absent, and got under way at once. When they were several miles -below "Cave Hollow," Tom said: - -"Now you see this bluff here looks all alike all the way down from the -cave hollow--no houses, no wood-yards, bushes all alike. But do you see -that white place up yonder where there's been a landslide? Well, that's -one of my marks. We'll get ashore, now." - -They landed. - -"Now, Huck, where we're a-standing you could touch that hole I got out -of with a fishing-pole. See if you can find it." - -Huck searched all the place about, and found nothing. Tom proudly -marched into a thick clump of sumach bushes and said: - -"Here you are! Look at it, Huck; it's the snuggest hole in this -country. You just keep mum about it. All along I've been wanting to be -a robber, but I knew I'd got to have a thing like this, and where to -run across it was the bother. We've got it now, and we'll keep it -quiet, only we'll let Joe Harper and Ben Rogers in--because of course -there's got to be a Gang, or else there wouldn't be any style about it. -Tom Sawyer's Gang--it sounds splendid, don't it, Huck?" - -"Well, it just does, Tom. And who'll we rob?" - -"Oh, most anybody. Waylay people--that's mostly the way." - -"And kill them?" - -"No, not always. Hive them in the cave till they raise a ransom." - -"What's a ransom?" - -"Money. You make them raise all they can, off'n their friends; and -after you've kept them a year, if it ain't raised then you kill them. -That's the general way. Only you don't kill the women. You shut up the -women, but you don't kill them. They're always beautiful and rich, and -awfully scared. You take their watches and things, but you always take -your hat off and talk polite. They ain't anybody as polite as robbers ---you'll see that in any book. Well, the women get to loving you, and -after they've been in the cave a week or two weeks they stop crying and -after that you couldn't get them to leave. If you drove them out they'd -turn right around and come back. It's so in all the books." - -"Why, it's real bully, Tom. I believe it's better'n to be a pirate." - -"Yes, it's better in some ways, because it's close to home and -circuses and all that." - -By this time everything was ready and the boys entered the hole, Tom -in the lead. They toiled their way to the farther end of the tunnel, -then made their spliced kite-strings fast and moved on. A few steps -brought them to the spring, and Tom felt a shudder quiver all through -him. He showed Huck the fragment of candle-wick perched on a lump of -clay against the wall, and described how he and Becky had watched the -flame struggle and expire. - -The boys began to quiet down to whispers, now, for the stillness and -gloom of the place oppressed their spirits. They went on, and presently -entered and followed Tom's other corridor until they reached the -"jumping-off place." The candles revealed the fact that it was not -really a precipice, but only a steep clay hill twenty or thirty feet -high. Tom whispered: - -"Now I'll show you something, Huck." - -He held his candle aloft and said: - -"Look as far around the corner as you can. Do you see that? There--on -the big rock over yonder--done with candle-smoke." - -"Tom, it's a CROSS!" - -"NOW where's your Number Two? 'UNDER THE CROSS,' hey? Right yonder's -where I saw Injun Joe poke up his candle, Huck!" - -Huck stared at the mystic sign awhile, and then said with a shaky voice: - -"Tom, less git out of here!" - -"What! and leave the treasure?" - -"Yes--leave it. Injun Joe's ghost is round about there, certain." - -"No it ain't, Huck, no it ain't. It would ha'nt the place where he -died--away out at the mouth of the cave--five mile from here." - -"No, Tom, it wouldn't. It would hang round the money. I know the ways -of ghosts, and so do you." - -Tom began to fear that Huck was right. Misgivings gathered in his -mind. But presently an idea occurred to him-- - -"Lookyhere, Huck, what fools we're making of ourselves! Injun Joe's -ghost ain't a going to come around where there's a cross!" - -The point was well taken. It had its effect. - -"Tom, I didn't think of that. But that's so. It's luck for us, that -cross is. I reckon we'll climb down there and have a hunt for that box." - -Tom went first, cutting rude steps in the clay hill as he descended. -Huck followed. Four avenues opened out of the small cavern which the -great rock stood in. The boys examined three of them with no result. -They found a small recess in the one nearest the base of the rock, with -a pallet of blankets spread down in it; also an old suspender, some -bacon rind, and the well-gnawed bones of two or three fowls. But there -was no money-box. The lads searched and researched this place, but in -vain. Tom said: - -"He said UNDER the cross. Well, this comes nearest to being under the -cross. It can't be under the rock itself, because that sets solid on -the ground." - -They searched everywhere once more, and then sat down discouraged. -Huck could suggest nothing. By-and-by Tom said: - -"Lookyhere, Huck, there's footprints and some candle-grease on the -clay about one side of this rock, but not on the other sides. Now, -what's that for? I bet you the money IS under the rock. I'm going to -dig in the clay." - -"That ain't no bad notion, Tom!" said Huck with animation. - -Tom's "real Barlow" was out at once, and he had not dug four inches -before he struck wood. - -"Hey, Huck!--you hear that?" - -Huck began to dig and scratch now. Some boards were soon uncovered and -removed. They had concealed a natural chasm which led under the rock. -Tom got into this and held his candle as far under the rock as he -could, but said he could not see to the end of the rift. He proposed to -explore. He stooped and passed under; the narrow way descended -gradually. He followed its winding course, first to the right, then to -the left, Huck at his heels. Tom turned a short curve, by-and-by, and -exclaimed: - -"My goodness, Huck, lookyhere!" - -It was the treasure-box, sure enough, occupying a snug little cavern, -along with an empty powder-keg, a couple of guns in leather cases, two -or three pairs of old moccasins, a leather belt, and some other rubbish -well soaked with the water-drip. - -"Got it at last!" said Huck, ploughing among the tarnished coins with -his hand. "My, but we're rich, Tom!" - -"Huck, I always reckoned we'd get it. It's just too good to believe, -but we HAVE got it, sure! Say--let's not fool around here. Let's snake -it out. Lemme see if I can lift the box." - -It weighed about fifty pounds. Tom could lift it, after an awkward -fashion, but could not carry it conveniently. - -"I thought so," he said; "THEY carried it like it was heavy, that day -at the ha'nted house. I noticed that. I reckon I was right to think of -fetching the little bags along." - -The money was soon in the bags and the boys took it up to the cross -rock. - -"Now less fetch the guns and things," said Huck. - -"No, Huck--leave them there. They're just the tricks to have when we -go to robbing. We'll keep them there all the time, and we'll hold our -orgies there, too. It's an awful snug place for orgies." - -"What orgies?" - -"I dono. But robbers always have orgies, and of course we've got to -have them, too. Come along, Huck, we've been in here a long time. It's -getting late, I reckon. I'm hungry, too. We'll eat and smoke when we -get to the skiff." - -They presently emerged into the clump of sumach bushes, looked warily -out, found the coast clear, and were soon lunching and smoking in the -skiff. As the sun dipped toward the horizon they pushed out and got -under way. Tom skimmed up the shore through the long twilight, chatting -cheerily with Huck, and landed shortly after dark. - -"Now, Huck," said Tom, "we'll hide the money in the loft of the -widow's woodshed, and I'll come up in the morning and we'll count it -and divide, and then we'll hunt up a place out in the woods for it -where it will be safe. Just you lay quiet here and watch the stuff till -I run and hook Benny Taylor's little wagon; I won't be gone a minute." - -He disappeared, and presently returned with the wagon, put the two -small sacks into it, threw some old rags on top of them, and started -off, dragging his cargo behind him. When the boys reached the -Welshman's house, they stopped to rest. Just as they were about to move -on, the Welshman stepped out and said: - -"Hallo, who's that?" - -"Huck and Tom Sawyer." - -"Good! Come along with me, boys, you are keeping everybody waiting. -Here--hurry up, trot ahead--I'll haul the wagon for you. Why, it's not -as light as it might be. Got bricks in it?--or old metal?" - -"Old metal," said Tom. - -"I judged so; the boys in this town will take more trouble and fool -away more time hunting up six bits' worth of old iron to sell to the -foundry than they would to make twice the money at regular work. But -that's human nature--hurry along, hurry along!" - -The boys wanted to know what the hurry was about. - -"Never mind; you'll see, when we get to the Widow Douglas'." - -Huck said with some apprehension--for he was long used to being -falsely accused: - -"Mr. Jones, we haven't been doing nothing." - -The Welshman laughed. - -"Well, I don't know, Huck, my boy. I don't know about that. Ain't you -and the widow good friends?" - -"Yes. Well, she's ben good friends to me, anyway." - -"All right, then. What do you want to be afraid for?" - -This question was not entirely answered in Huck's slow mind before he -found himself pushed, along with Tom, into Mrs. Douglas' drawing-room. -Mr. Jones left the wagon near the door and followed. - -The place was grandly lighted, and everybody that was of any -consequence in the village was there. The Thatchers were there, the -Harpers, the Rogerses, Aunt Polly, Sid, Mary, the minister, the editor, -and a great many more, and all dressed in their best. The widow -received the boys as heartily as any one could well receive two such -looking beings. They were covered with clay and candle-grease. Aunt -Polly blushed crimson with humiliation, and frowned and shook her head -at Tom. Nobody suffered half as much as the two boys did, however. Mr. -Jones said: - -"Tom wasn't at home, yet, so I gave him up; but I stumbled on him and -Huck right at my door, and so I just brought them along in a hurry." - -"And you did just right," said the widow. "Come with me, boys." - -She took them to a bedchamber and said: - -"Now wash and dress yourselves. Here are two new suits of clothes ---shirts, socks, everything complete. They're Huck's--no, no thanks, -Huck--Mr. Jones bought one and I the other. But they'll fit both of you. -Get into them. We'll wait--come down when you are slicked up enough." - -Then she left. - - - -CHAPTER XXXIV - -HUCK said: "Tom, we can slope, if we can find a rope. The window ain't -high from the ground." - -"Shucks! what do you want to slope for?" - -"Well, I ain't used to that kind of a crowd. I can't stand it. I ain't -going down there, Tom." - -"Oh, bother! It ain't anything. I don't mind it a bit. I'll take care -of you." - -Sid appeared. - -"Tom," said he, "auntie has been waiting for you all the afternoon. -Mary got your Sunday clothes ready, and everybody's been fretting about -you. Say--ain't this grease and clay, on your clothes?" - -"Now, Mr. Siddy, you jist 'tend to your own business. What's all this -blow-out about, anyway?" - -"It's one of the widow's parties that she's always having. This time -it's for the Welshman and his sons, on account of that scrape they -helped her out of the other night. And say--I can tell you something, -if you want to know." - -"Well, what?" - -"Why, old Mr. Jones is going to try to spring something on the people -here to-night, but I overheard him tell auntie to-day about it, as a -secret, but I reckon it's not much of a secret now. Everybody knows ---the widow, too, for all she tries to let on she don't. Mr. Jones was -bound Huck should be here--couldn't get along with his grand secret -without Huck, you know!" - -"Secret about what, Sid?" - -"About Huck tracking the robbers to the widow's. I reckon Mr. Jones -was going to make a grand time over his surprise, but I bet you it will -drop pretty flat." - -Sid chuckled in a very contented and satisfied way. - -"Sid, was it you that told?" - -"Oh, never mind who it was. SOMEBODY told--that's enough." - -"Sid, there's only one person in this town mean enough to do that, and -that's you. If you had been in Huck's place you'd 'a' sneaked down the -hill and never told anybody on the robbers. You can't do any but mean -things, and you can't bear to see anybody praised for doing good ones. -There--no thanks, as the widow says"--and Tom cuffed Sid's ears and -helped him to the door with several kicks. "Now go and tell auntie if -you dare--and to-morrow you'll catch it!" - -Some minutes later the widow's guests were at the supper-table, and a -dozen children were propped up at little side-tables in the same room, -after the fashion of that country and that day. At the proper time Mr. -Jones made his little speech, in which he thanked the widow for the -honor she was doing himself and his sons, but said that there was -another person whose modesty-- - -And so forth and so on. He sprung his secret about Huck's share in the -adventure in the finest dramatic manner he was master of, but the -surprise it occasioned was largely counterfeit and not as clamorous and -effusive as it might have been under happier circumstances. However, -the widow made a pretty fair show of astonishment, and heaped so many -compliments and so much gratitude upon Huck that he almost forgot the -nearly intolerable discomfort of his new clothes in the entirely -intolerable discomfort of being set up as a target for everybody's gaze -and everybody's laudations. - -The widow said she meant to give Huck a home under her roof and have -him educated; and that when she could spare the money she would start -him in business in a modest way. Tom's chance was come. He said: - -"Huck don't need it. Huck's rich." - -Nothing but a heavy strain upon the good manners of the company kept -back the due and proper complimentary laugh at this pleasant joke. But -the silence was a little awkward. Tom broke it: - -"Huck's got money. Maybe you don't believe it, but he's got lots of -it. Oh, you needn't smile--I reckon I can show you. You just wait a -minute." - -Tom ran out of doors. The company looked at each other with a -perplexed interest--and inquiringly at Huck, who was tongue-tied. - -"Sid, what ails Tom?" said Aunt Polly. "He--well, there ain't ever any -making of that boy out. I never--" - -Tom entered, struggling with the weight of his sacks, and Aunt Polly -did not finish her sentence. Tom poured the mass of yellow coin upon -the table and said: - -"There--what did I tell you? Half of it's Huck's and half of it's mine!" - -The spectacle took the general breath away. All gazed, nobody spoke -for a moment. Then there was a unanimous call for an explanation. Tom -said he could furnish it, and he did. The tale was long, but brimful of -interest. There was scarcely an interruption from any one to break the -charm of its flow. When he had finished, Mr. Jones said: - -"I thought I had fixed up a little surprise for this occasion, but it -don't amount to anything now. This one makes it sing mighty small, I'm -willing to allow." - -The money was counted. The sum amounted to a little over twelve -thousand dollars. It was more than any one present had ever seen at one -time before, though several persons were there who were worth -considerably more than that in property. - - - -CHAPTER XXXV - -THE reader may rest satisfied that Tom's and Huck's windfall made a -mighty stir in the poor little village of St. Petersburg. So vast a -sum, all in actual cash, seemed next to incredible. It was talked -about, gloated over, glorified, until the reason of many of the -citizens tottered under the strain of the unhealthy excitement. Every -"haunted" house in St. Petersburg and the neighboring villages was -dissected, plank by plank, and its foundations dug up and ransacked for -hidden treasure--and not by boys, but men--pretty grave, unromantic -men, too, some of them. Wherever Tom and Huck appeared they were -courted, admired, stared at. The boys were not able to remember that -their remarks had possessed weight before; but now their sayings were -treasured and repeated; everything they did seemed somehow to be -regarded as remarkable; they had evidently lost the power of doing and -saying commonplace things; moreover, their past history was raked up -and discovered to bear marks of conspicuous originality. The village -paper published biographical sketches of the boys. - -The Widow Douglas put Huck's money out at six per cent., and Judge -Thatcher did the same with Tom's at Aunt Polly's request. Each lad had -an income, now, that was simply prodigious--a dollar for every week-day -in the year and half of the Sundays. It was just what the minister got ---no, it was what he was promised--he generally couldn't collect it. A -dollar and a quarter a week would board, lodge, and school a boy in -those old simple days--and clothe him and wash him, too, for that -matter. - -Judge Thatcher had conceived a great opinion of Tom. He said that no -commonplace boy would ever have got his daughter out of the cave. When -Becky told her father, in strict confidence, how Tom had taken her -whipping at school, the Judge was visibly moved; and when she pleaded -grace for the mighty lie which Tom had told in order to shift that -whipping from her shoulders to his own, the Judge said with a fine -outburst that it was a noble, a generous, a magnanimous lie--a lie that -was worthy to hold up its head and march down through history breast to -breast with George Washington's lauded Truth about the hatchet! Becky -thought her father had never looked so tall and so superb as when he -walked the floor and stamped his foot and said that. She went straight -off and told Tom about it. - -Judge Thatcher hoped to see Tom a great lawyer or a great soldier some -day. He said he meant to look to it that Tom should be admitted to the -National Military Academy and afterward trained in the best law school -in the country, in order that he might be ready for either career or -both. - -Huck Finn's wealth and the fact that he was now under the Widow -Douglas' protection introduced him into society--no, dragged him into -it, hurled him into it--and his sufferings were almost more than he -could bear. The widow's servants kept him clean and neat, combed and -brushed, and they bedded him nightly in unsympathetic sheets that had -not one little spot or stain which he could press to his heart and know -for a friend. He had to eat with a knife and fork; he had to use -napkin, cup, and plate; he had to learn his book, he had to go to -church; he had to talk so properly that speech was become insipid in -his mouth; whithersoever he turned, the bars and shackles of -civilization shut him in and bound him hand and foot. - -He bravely bore his miseries three weeks, and then one day turned up -missing. For forty-eight hours the widow hunted for him everywhere in -great distress. The public were profoundly concerned; they searched -high and low, they dragged the river for his body. Early the third -morning Tom Sawyer wisely went poking among some old empty hogsheads -down behind the abandoned slaughter-house, and in one of them he found -the refugee. Huck had slept there; he had just breakfasted upon some -stolen odds and ends of food, and was lying off, now, in comfort, with -his pipe. He was unkempt, uncombed, and clad in the same old ruin of -rags that had made him picturesque in the days when he was free and -happy. Tom routed him out, told him the trouble he had been causing, -and urged him to go home. Huck's face lost its tranquil content, and -took a melancholy cast. He said: - -"Don't talk about it, Tom. I've tried it, and it don't work; it don't -work, Tom. It ain't for me; I ain't used to it. The widder's good to -me, and friendly; but I can't stand them ways. She makes me get up just -at the same time every morning; she makes me wash, they comb me all to -thunder; she won't let me sleep in the woodshed; I got to wear them -blamed clothes that just smothers me, Tom; they don't seem to any air -git through 'em, somehow; and they're so rotten nice that I can't set -down, nor lay down, nor roll around anywher's; I hain't slid on a -cellar-door for--well, it 'pears to be years; I got to go to church and -sweat and sweat--I hate them ornery sermons! I can't ketch a fly in -there, I can't chaw. I got to wear shoes all Sunday. The widder eats by -a bell; she goes to bed by a bell; she gits up by a bell--everything's -so awful reg'lar a body can't stand it." - -"Well, everybody does that way, Huck." - -"Tom, it don't make no difference. I ain't everybody, and I can't -STAND it. It's awful to be tied up so. And grub comes too easy--I don't -take no interest in vittles, that way. I got to ask to go a-fishing; I -got to ask to go in a-swimming--dern'd if I hain't got to ask to do -everything. Well, I'd got to talk so nice it wasn't no comfort--I'd got -to go up in the attic and rip out awhile, every day, to git a taste in -my mouth, or I'd a died, Tom. The widder wouldn't let me smoke; she -wouldn't let me yell, she wouldn't let me gape, nor stretch, nor -scratch, before folks--" [Then with a spasm of special irritation and -injury]--"And dad fetch it, she prayed all the time! I never see such a -woman! I HAD to shove, Tom--I just had to. And besides, that school's -going to open, and I'd a had to go to it--well, I wouldn't stand THAT, -Tom. Looky here, Tom, being rich ain't what it's cracked up to be. It's -just worry and worry, and sweat and sweat, and a-wishing you was dead -all the time. Now these clothes suits me, and this bar'l suits me, and -I ain't ever going to shake 'em any more. Tom, I wouldn't ever got into -all this trouble if it hadn't 'a' ben for that money; now you just take -my sheer of it along with your'n, and gimme a ten-center sometimes--not -many times, becuz I don't give a dern for a thing 'thout it's tollable -hard to git--and you go and beg off for me with the widder." - -"Oh, Huck, you know I can't do that. 'Tain't fair; and besides if -you'll try this thing just a while longer you'll come to like it." - -"Like it! Yes--the way I'd like a hot stove if I was to set on it long -enough. No, Tom, I won't be rich, and I won't live in them cussed -smothery houses. I like the woods, and the river, and hogsheads, and -I'll stick to 'em, too. Blame it all! just as we'd got guns, and a -cave, and all just fixed to rob, here this dern foolishness has got to -come up and spile it all!" - -Tom saw his opportunity-- - -"Lookyhere, Huck, being rich ain't going to keep me back from turning -robber." - -"No! Oh, good-licks; are you in real dead-wood earnest, Tom?" - -"Just as dead earnest as I'm sitting here. But Huck, we can't let you -into the gang if you ain't respectable, you know." - -Huck's joy was quenched. - -"Can't let me in, Tom? Didn't you let me go for a pirate?" - -"Yes, but that's different. A robber is more high-toned than what a -pirate is--as a general thing. In most countries they're awful high up -in the nobility--dukes and such." - -"Now, Tom, hain't you always ben friendly to me? You wouldn't shet me -out, would you, Tom? You wouldn't do that, now, WOULD you, Tom?" - -"Huck, I wouldn't want to, and I DON'T want to--but what would people -say? Why, they'd say, 'Mph! Tom Sawyer's Gang! pretty low characters in -it!' They'd mean you, Huck. You wouldn't like that, and I wouldn't." - -Huck was silent for some time, engaged in a mental struggle. Finally -he said: - -"Well, I'll go back to the widder for a month and tackle it and see if -I can come to stand it, if you'll let me b'long to the gang, Tom." - -"All right, Huck, it's a whiz! Come along, old chap, and I'll ask the -widow to let up on you a little, Huck." - -"Will you, Tom--now will you? That's good. If she'll let up on some of -the roughest things, I'll smoke private and cuss private, and crowd -through or bust. When you going to start the gang and turn robbers?" - -"Oh, right off. We'll get the boys together and have the initiation -to-night, maybe." - -"Have the which?" - -"Have the initiation." - -"What's that?" - -"It's to swear to stand by one another, and never tell the gang's -secrets, even if you're chopped all to flinders, and kill anybody and -all his family that hurts one of the gang." - -"That's gay--that's mighty gay, Tom, I tell you." - -"Well, I bet it is. And all that swearing's got to be done at -midnight, in the lonesomest, awfulest place you can find--a ha'nted -house is the best, but they're all ripped up now." - -"Well, midnight's good, anyway, Tom." - -"Yes, so it is. And you've got to swear on a coffin, and sign it with -blood." - -"Now, that's something LIKE! Why, it's a million times bullier than -pirating. I'll stick to the widder till I rot, Tom; and if I git to be -a reg'lar ripper of a robber, and everybody talking 'bout it, I reckon -she'll be proud she snaked me in out of the wet." - - - -CONCLUSION - -SO endeth this chronicle. It being strictly a history of a BOY, it -must stop here; the story could not go much further without becoming -the history of a MAN. When one writes a novel about grown people, he -knows exactly where to stop--that is, with a marriage; but when he -writes of juveniles, he must stop where he best can. - -Most of the characters that perform in this book still live, and are -prosperous and happy. Some day it may seem worth while to take up the -story of the younger ones again and see what sort of men and women they -turned out to be; therefore it will be wisest not to reveal any of that -part of their lives at present. diff --git a/src/testdata/Isaac.Newton-Opticks.txt b/src/testdata/Isaac.Newton-Opticks.txt new file mode 100644 index 0000000000000..15bb4c54d0b75 --- /dev/null +++ b/src/testdata/Isaac.Newton-Opticks.txt @@ -0,0 +1,9286 @@ +Produced by Suzanne Lybarger, steve harris, Josephine +Paolucci and the Online Distributed Proofreading Team at +http://www.pgdp.net. + + + + + + +OPTICKS: + +OR, A + +TREATISE + +OF THE + +_Reflections_, _Refractions_, +_Inflections_ and _Colours_ + +OF + +LIGHT. + +_The_ FOURTH EDITION, _corrected_. + +By Sir _ISAAC NEWTON_, Knt. + +LONDON: + +Printed for WILLIAM INNYS at the West-End of St. _Paul's_. MDCCXXX. + +TITLE PAGE OF THE 1730 EDITION + + + + +SIR ISAAC NEWTON'S ADVERTISEMENTS + + + + +Advertisement I + + +_Part of the ensuing Discourse about Light was written at the Desire of +some Gentlemen of the_ Royal-Society, _in the Year 1675, and then sent +to their Secretary, and read at their Meetings, and the rest was added +about twelve Years after to complete the Theory; except the third Book, +and the last Proposition of the Second, which were since put together +out of scatter'd Papers. To avoid being engaged in Disputes about these +Matters, I have hitherto delayed the printing, and should still have +delayed it, had not the Importunity of Friends prevailed upon me. If any +other Papers writ on this Subject are got out of my Hands they are +imperfect, and were perhaps written before I had tried all the +Experiments here set down, and fully satisfied my self about the Laws of +Refractions and Composition of Colours. I have here publish'd what I +think proper to come abroad, wishing that it may not be translated into +another Language without my Consent._ + +_The Crowns of Colours, which sometimes appear about the Sun and Moon, I +have endeavoured to give an Account of; but for want of sufficient +Observations leave that Matter to be farther examined. The Subject of +the Third Book I have also left imperfect, not having tried all the +Experiments which I intended when I was about these Matters, nor +repeated some of those which I did try, until I had satisfied my self +about all their Circumstances. To communicate what I have tried, and +leave the rest to others for farther Enquiry, is all my Design in +publishing these Papers._ + +_In a Letter written to Mr._ Leibnitz _in the year 1679, and published +by Dr._ Wallis, _I mention'd a Method by which I had found some general +Theorems about squaring Curvilinear Figures, or comparing them with the +Conic Sections, or other the simplest Figures with which they may be +compared. And some Years ago I lent out a Manuscript containing such +Theorems, and having since met with some Things copied out of it, I have +on this Occasion made it publick, prefixing to it an_ Introduction, _and +subjoining a_ Scholium _concerning that Method. And I have joined with +it another small Tract concerning the Curvilinear Figures of the Second +Kind, which was also written many Years ago, and made known to some +Friends, who have solicited the making it publick._ + + _I. N._ + +April 1, 1704. + + +Advertisement II + +_In this Second Edition of these Opticks I have omitted the Mathematical +Tracts publish'd at the End of the former Edition, as not belonging to +the Subject. And at the End of the Third Book I have added some +Questions. And to shew that I do not take Gravity for an essential +Property of Bodies, I have added one Question concerning its Cause, +chusing to propose it by way of a Question, because I am not yet +satisfied about it for want of Experiments._ + + _I. N._ + +July 16, 1717. + + +Advertisement to this Fourth Edition + +_This new Edition of Sir_ Isaac Newton's Opticks _is carefully printed +from the Third Edition, as it was corrected by the Author's own Hand, +and left before his Death with the Bookseller. Since Sir_ Isaac's +Lectiones Opticæ, _which he publickly read in the University of_ +Cambridge _in the Years 1669, 1670, and 1671, are lately printed, it has +been thought proper to make at the bottom of the Pages several Citations +from thence, where may be found the Demonstrations, which the Author +omitted in these_ Opticks. + + * * * * * + +Transcriber's Note: There are several greek letters used in the +descriptions of the illustrations. They are signified by [Greek: +letter]. Square roots are noted by the letters sqrt before the equation. + + * * * * * + +THE FIRST BOOK OF OPTICKS + + + + +_PART I._ + + +My Design in this Book is not to explain the Properties of Light by +Hypotheses, but to propose and prove them by Reason and Experiments: In +order to which I shall premise the following Definitions and Axioms. + + + + +_DEFINITIONS_ + + +DEFIN. I. + +_By the Rays of Light I understand its least Parts, and those as well +Successive in the same Lines, as Contemporary in several Lines._ For it +is manifest that Light consists of Parts, both Successive and +Contemporary; because in the same place you may stop that which comes +one moment, and let pass that which comes presently after; and in the +same time you may stop it in any one place, and let it pass in any +other. For that part of Light which is stopp'd cannot be the same with +that which is let pass. The least Light or part of Light, which may be +stopp'd alone without the rest of the Light, or propagated alone, or do +or suffer any thing alone, which the rest of the Light doth not or +suffers not, I call a Ray of Light. + + +DEFIN. II. + +_Refrangibility of the Rays of Light, is their Disposition to be +refracted or turned out of their Way in passing out of one transparent +Body or Medium into another. And a greater or less Refrangibility of +Rays, is their Disposition to be turned more or less out of their Way in +like Incidences on the same Medium._ Mathematicians usually consider the +Rays of Light to be Lines reaching from the luminous Body to the Body +illuminated, and the refraction of those Rays to be the bending or +breaking of those lines in their passing out of one Medium into another. +And thus may Rays and Refractions be considered, if Light be propagated +in an instant. But by an Argument taken from the Æquations of the times +of the Eclipses of _Jupiter's Satellites_, it seems that Light is +propagated in time, spending in its passage from the Sun to us about +seven Minutes of time: And therefore I have chosen to define Rays and +Refractions in such general terms as may agree to Light in both cases. + + +DEFIN. III. + +_Reflexibility of Rays, is their Disposition to be reflected or turned +back into the same Medium from any other Medium upon whose Surface they +fall. And Rays are more or less reflexible, which are turned back more +or less easily._ As if Light pass out of a Glass into Air, and by being +inclined more and more to the common Surface of the Glass and Air, +begins at length to be totally reflected by that Surface; those sorts of +Rays which at like Incidences are reflected most copiously, or by +inclining the Rays begin soonest to be totally reflected, are most +reflexible. + + +DEFIN. IV. + +_The Angle of Incidence is that Angle, which the Line described by the +incident Ray contains with the Perpendicular to the reflecting or +refracting Surface at the Point of Incidence._ + + +DEFIN. V. + +_The Angle of Reflexion or Refraction, is the Angle which the line +described by the reflected or refracted Ray containeth with the +Perpendicular to the reflecting or refracting Surface at the Point of +Incidence._ + + +DEFIN. VI. + +_The Sines of Incidence, Reflexion, and Refraction, are the Sines of the +Angles of Incidence, Reflexion, and Refraction._ + + +DEFIN. VII + +_The Light whose Rays are all alike Refrangible, I call Simple, +Homogeneal and Similar; and that whose Rays are some more Refrangible +than others, I call Compound, Heterogeneal and Dissimilar._ The former +Light I call Homogeneal, not because I would affirm it so in all +respects, but because the Rays which agree in Refrangibility, agree at +least in all those their other Properties which I consider in the +following Discourse. + + +DEFIN. VIII. + +_The Colours of Homogeneal Lights, I call Primary, Homogeneal and +Simple; and those of Heterogeneal Lights, Heterogeneal and Compound._ +For these are always compounded of the colours of Homogeneal Lights; as +will appear in the following Discourse. + + + + +_AXIOMS._ + + +AX. I. + +_The Angles of Reflexion and Refraction, lie in one and the same Plane +with the Angle of Incidence._ + + +AX. II. + +_The Angle of Reflexion is equal to the Angle of Incidence._ + + +AX. III. + +_If the refracted Ray be returned directly back to the Point of +Incidence, it shall be refracted into the Line before described by the +incident Ray._ + + +AX. IV. + +_Refraction out of the rarer Medium into the denser, is made towards the +Perpendicular; that is, so that the Angle of Refraction be less than the +Angle of Incidence._ + + +AX. V. + +_The Sine of Incidence is either accurately or very nearly in a given +Ratio to the Sine of Refraction._ + +Whence if that Proportion be known in any one Inclination of the +incident Ray, 'tis known in all the Inclinations, and thereby the +Refraction in all cases of Incidence on the same refracting Body may be +determined. Thus if the Refraction be made out of Air into Water, the +Sine of Incidence of the red Light is to the Sine of its Refraction as 4 +to 3. If out of Air into Glass, the Sines are as 17 to 11. In Light of +other Colours the Sines have other Proportions: but the difference is so +little that it need seldom be considered. + +[Illustration: FIG. 1] + +Suppose therefore, that RS [in _Fig._ 1.] represents the Surface of +stagnating Water, and that C is the point of Incidence in which any Ray +coming in the Air from A in the Line AC is reflected or refracted, and I +would know whither this Ray shall go after Reflexion or Refraction: I +erect upon the Surface of the Water from the point of Incidence the +Perpendicular CP and produce it downwards to Q, and conclude by the +first Axiom, that the Ray after Reflexion and Refraction, shall be +found somewhere in the Plane of the Angle of Incidence ACP produced. I +let fall therefore upon the Perpendicular CP the Sine of Incidence AD; +and if the reflected Ray be desired, I produce AD to B so that DB be +equal to AD, and draw CB. For this Line CB shall be the reflected Ray; +the Angle of Reflexion BCP and its Sine BD being equal to the Angle and +Sine of Incidence, as they ought to be by the second Axiom, But if the +refracted Ray be desired, I produce AD to H, so that DH may be to AD as +the Sine of Refraction to the Sine of Incidence, that is, (if the Light +be red) as 3 to 4; and about the Center C and in the Plane ACP with the +Radius CA describing a Circle ABE, I draw a parallel to the +Perpendicular CPQ, the Line HE cutting the Circumference in E, and +joining CE, this Line CE shall be the Line of the refracted Ray. For if +EF be let fall perpendicularly on the Line PQ, this Line EF shall be the +Sine of Refraction of the Ray CE, the Angle of Refraction being ECQ; and +this Sine EF is equal to DH, and consequently in Proportion to the Sine +of Incidence AD as 3 to 4. + +In like manner, if there be a Prism of Glass (that is, a Glass bounded +with two Equal and Parallel Triangular ends, and three plain and well +polished Sides, which meet in three Parallel Lines running from the +three Angles of one end to the three Angles of the other end) and if the +Refraction of the Light in passing cross this Prism be desired: Let ACB +[in _Fig._ 2.] represent a Plane cutting this Prism transversly to its +three Parallel lines or edges there where the Light passeth through it, +and let DE be the Ray incident upon the first side of the Prism AC where +the Light goes into the Glass; and by putting the Proportion of the Sine +of Incidence to the Sine of Refraction as 17 to 11 find EF the first +refracted Ray. Then taking this Ray for the Incident Ray upon the second +side of the Glass BC where the Light goes out, find the next refracted +Ray FG by putting the Proportion of the Sine of Incidence to the Sine of +Refraction as 11 to 17. For if the Sine of Incidence out of Air into +Glass be to the Sine of Refraction as 17 to 11, the Sine of Incidence +out of Glass into Air must on the contrary be to the Sine of Refraction +as 11 to 17, by the third Axiom. + +[Illustration: FIG. 2.] + +Much after the same manner, if ACBD [in _Fig._ 3.] represent a Glass +spherically convex on both sides (usually called a _Lens_, such as is a +Burning-glass, or Spectacle-glass, or an Object-glass of a Telescope) +and it be required to know how Light falling upon it from any lucid +point Q shall be refracted, let QM represent a Ray falling upon any +point M of its first spherical Surface ACB, and by erecting a +Perpendicular to the Glass at the point M, find the first refracted Ray +MN by the Proportion of the Sines 17 to 11. Let that Ray in going out of +the Glass be incident upon N, and then find the second refracted Ray +N_q_ by the Proportion of the Sines 11 to 17. And after the same manner +may the Refraction be found when the Lens is convex on one side and +plane or concave on the other, or concave on both sides. + +[Illustration: FIG. 3.] + + +AX. VI. + +_Homogeneal Rays which flow from several Points of any Object, and fall +perpendicularly or almost perpendicularly on any reflecting or +refracting Plane or spherical Surface, shall afterwards diverge from so +many other Points, or be parallel to so many other Lines, or converge to +so many other Points, either accurately or without any sensible Error. +And the same thing will happen, if the Rays be reflected or refracted +successively by two or three or more Plane or Spherical Surfaces._ + +The Point from which Rays diverge or to which they converge may be +called their _Focus_. And the Focus of the incident Rays being given, +that of the reflected or refracted ones may be found by finding the +Refraction of any two Rays, as above; or more readily thus. + +_Cas._ 1. Let ACB [in _Fig._ 4.] be a reflecting or refracting Plane, +and Q the Focus of the incident Rays, and Q_q_C a Perpendicular to that +Plane. And if this Perpendicular be produced to _q_, so that _q_C be +equal to QC, the Point _q_ shall be the Focus of the reflected Rays: Or +if _q_C be taken on the same side of the Plane with QC, and in +proportion to QC as the Sine of Incidence to the Sine of Refraction, the +Point _q_ shall be the Focus of the refracted Rays. + +[Illustration: FIG. 4.] + +_Cas._ 2. Let ACB [in _Fig._ 5.] be the reflecting Surface of any Sphere +whose Centre is E. Bisect any Radius thereof, (suppose EC) in T, and if +in that Radius on the same side the Point T you take the Points Q and +_q_, so that TQ, TE, and T_q_, be continual Proportionals, and the Point +Q be the Focus of the incident Rays, the Point _q_ shall be the Focus of +the reflected ones. + +[Illustration: FIG. 5.] + +_Cas._ 3. Let ACB [in _Fig._ 6.] be the refracting Surface of any Sphere +whose Centre is E. In any Radius thereof EC produced both ways take ET +and C_t_ equal to one another and severally in such Proportion to that +Radius as the lesser of the Sines of Incidence and Refraction hath to +the difference of those Sines. And then if in the same Line you find any +two Points Q and _q_, so that TQ be to ET as E_t_ to _tq_, taking _tq_ +the contrary way from _t_ which TQ lieth from T, and if the Point Q be +the Focus of any incident Rays, the Point _q_ shall be the Focus of the +refracted ones. + +[Illustration: FIG. 6.] + +And by the same means the Focus of the Rays after two or more Reflexions +or Refractions may be found. + +[Illustration: FIG. 7.] + +_Cas._ 4. Let ACBD [in _Fig._ 7.] be any refracting Lens, spherically +Convex or Concave or Plane on either side, and let CD be its Axis (that +is, the Line which cuts both its Surfaces perpendicularly, and passes +through the Centres of the Spheres,) and in this Axis produced let F and +_f_ be the Foci of the refracted Rays found as above, when the incident +Rays on both sides the Lens are parallel to the same Axis; and upon the +Diameter F_f_ bisected in E, describe a Circle. Suppose now that any +Point Q be the Focus of any incident Rays. Draw QE cutting the said +Circle in T and _t_, and therein take _tq_ in such proportion to _t_E as +_t_E or TE hath to TQ. Let _tq_ lie the contrary way from _t_ which TQ +doth from T, and _q_ shall be the Focus of the refracted Rays without +any sensible Error, provided the Point Q be not so remote from the Axis, +nor the Lens so broad as to make any of the Rays fall too obliquely on +the refracting Surfaces.[A] + +And by the like Operations may the reflecting or refracting Surfaces be +found when the two Foci are given, and thereby a Lens be formed, which +shall make the Rays flow towards or from what Place you please.[B] + +So then the Meaning of this Axiom is, that if Rays fall upon any Plane +or Spherical Surface or Lens, and before their Incidence flow from or +towards any Point Q, they shall after Reflexion or Refraction flow from +or towards the Point _q_ found by the foregoing Rules. And if the +incident Rays flow from or towards several points Q, the reflected or +refracted Rays shall flow from or towards so many other Points _q_ +found by the same Rules. Whether the reflected and refracted Rays flow +from or towards the Point _q_ is easily known by the situation of that +Point. For if that Point be on the same side of the reflecting or +refracting Surface or Lens with the Point Q, and the incident Rays flow +from the Point Q, the reflected flow towards the Point _q_ and the +refracted from it; and if the incident Rays flow towards Q, the +reflected flow from _q_, and the refracted towards it. And the contrary +happens when _q_ is on the other side of the Surface. + + +AX. VII. + +_Wherever the Rays which come from all the Points of any Object meet +again in so many Points after they have been made to converge by +Reflection or Refraction, there they will make a Picture of the Object +upon any white Body on which they fall._ + +So if PR [in _Fig._ 3.] represent any Object without Doors, and AB be a +Lens placed at a hole in the Window-shut of a dark Chamber, whereby the +Rays that come from any Point Q of that Object are made to converge and +meet again in the Point _q_; and if a Sheet of white Paper be held at +_q_ for the Light there to fall upon it, the Picture of that Object PR +will appear upon the Paper in its proper shape and Colours. For as the +Light which comes from the Point Q goes to the Point _q_, so the Light +which comes from other Points P and R of the Object, will go to so many +other correspondent Points _p_ and _r_ (as is manifest by the sixth +Axiom;) so that every Point of the Object shall illuminate a +correspondent Point of the Picture, and thereby make a Picture like the +Object in Shape and Colour, this only excepted, that the Picture shall +be inverted. And this is the Reason of that vulgar Experiment of casting +the Species of Objects from abroad upon a Wall or Sheet of white Paper +in a dark Room. + +In like manner, when a Man views any Object PQR, [in _Fig._ 8.] the +Light which comes from the several Points of the Object is so refracted +by the transparent skins and humours of the Eye, (that is, by the +outward coat EFG, called the _Tunica Cornea_, and by the crystalline +humour AB which is beyond the Pupil _mk_) as to converge and meet again +in so many Points in the bottom of the Eye, and there to paint the +Picture of the Object upon that skin (called the _Tunica Retina_) with +which the bottom of the Eye is covered. For Anatomists, when they have +taken off from the bottom of the Eye that outward and most thick Coat +called the _Dura Mater_, can then see through the thinner Coats, the +Pictures of Objects lively painted thereon. And these Pictures, +propagated by Motion along the Fibres of the Optick Nerves into the +Brain, are the cause of Vision. For accordingly as these Pictures are +perfect or imperfect, the Object is seen perfectly or imperfectly. If +the Eye be tinged with any colour (as in the Disease of the _Jaundice_) +so as to tinge the Pictures in the bottom of the Eye with that Colour, +then all Objects appear tinged with the same Colour. If the Humours of +the Eye by old Age decay, so as by shrinking to make the _Cornea_ and +Coat of the _Crystalline Humour_ grow flatter than before, the Light +will not be refracted enough, and for want of a sufficient Refraction +will not converge to the bottom of the Eye but to some place beyond it, +and by consequence paint in the bottom of the Eye a confused Picture, +and according to the Indistinctness of this Picture the Object will +appear confused. This is the reason of the decay of sight in old Men, +and shews why their Sight is mended by Spectacles. For those Convex +glasses supply the defect of plumpness in the Eye, and by increasing the +Refraction make the Rays converge sooner, so as to convene distinctly at +the bottom of the Eye if the Glass have a due degree of convexity. And +the contrary happens in short-sighted Men whose Eyes are too plump. For +the Refraction being now too great, the Rays converge and convene in the +Eyes before they come at the bottom; and therefore the Picture made in +the bottom and the Vision caused thereby will not be distinct, unless +the Object be brought so near the Eye as that the place where the +converging Rays convene may be removed to the bottom, or that the +plumpness of the Eye be taken off and the Refractions diminished by a +Concave-glass of a due degree of Concavity, or lastly that by Age the +Eye grow flatter till it come to a due Figure: For short-sighted Men see +remote Objects best in Old Age, and therefore they are accounted to have +the most lasting Eyes. + +[Illustration: FIG. 8.] + + +AX. VIII. + +_An Object seen by Reflexion or Refraction, appears in that place from +whence the Rays after their last Reflexion or Refraction diverge in +falling on the Spectator's Eye._ + +[Illustration: FIG. 9.] + +If the Object A [in FIG. 9.] be seen by Reflexion of a Looking-glass +_mn_, it shall appear, not in its proper place A, but behind the Glass +at _a_, from whence any Rays AB, AC, AD, which flow from one and the +same Point of the Object, do after their Reflexion made in the Points B, +C, D, diverge in going from the Glass to E, F, G, where they are +incident on the Spectator's Eyes. For these Rays do make the same +Picture in the bottom of the Eyes as if they had come from the Object +really placed at _a_ without the Interposition of the Looking-glass; and +all Vision is made according to the place and shape of that Picture. + +In like manner the Object D [in FIG. 2.] seen through a Prism, appears +not in its proper place D, but is thence translated to some other place +_d_ situated in the last refracted Ray FG drawn backward from F to _d_. + +[Illustration: FIG. 10.] + +And so the Object Q [in FIG. 10.] seen through the Lens AB, appears at +the place _q_ from whence the Rays diverge in passing from the Lens to +the Eye. Now it is to be noted, that the Image of the Object at _q_ is +so much bigger or lesser than the Object it self at Q, as the distance +of the Image at _q_ from the Lens AB is bigger or less than the distance +of the Object at Q from the same Lens. And if the Object be seen through +two or more such Convex or Concave-glasses, every Glass shall make a new +Image, and the Object shall appear in the place of the bigness of the +last Image. Which consideration unfolds the Theory of Microscopes and +Telescopes. For that Theory consists in almost nothing else than the +describing such Glasses as shall make the last Image of any Object as +distinct and large and luminous as it can conveniently be made. + +I have now given in Axioms and their Explications the sum of what hath +hitherto been treated of in Opticks. For what hath been generally +agreed on I content my self to assume under the notion of Principles, in +order to what I have farther to write. And this may suffice for an +Introduction to Readers of quick Wit and good Understanding not yet +versed in Opticks: Although those who are already acquainted with this +Science, and have handled Glasses, will more readily apprehend what +followeth. + +FOOTNOTES: + +[A] In our Author's _Lectiones Opticæ_, Part I. Sect. IV. Prop 29, 30, +there is an elegant Method of determining these _Foci_; not only in +spherical Surfaces, but likewise in any other curved Figure whatever: +And in Prop. 32, 33, the same thing is done for any Ray lying out of the +Axis. + +[B] _Ibid._ Prop. 34. + + + + +_PROPOSITIONS._ + + + +_PROP._ I. THEOR. I. + +_Lights which differ in Colour, differ also in Degrees of +Refrangibility._ + +The PROOF by Experiments. + +_Exper._ 1. + +I took a black oblong stiff Paper terminated by Parallel Sides, and with +a Perpendicular right Line drawn cross from one Side to the other, +distinguished it into two equal Parts. One of these parts I painted with +a red colour and the other with a blue. The Paper was very black, and +the Colours intense and thickly laid on, that the Phænomenon might be +more conspicuous. This Paper I view'd through a Prism of solid Glass, +whose two Sides through which the Light passed to the Eye were plane and +well polished, and contained an Angle of about sixty degrees; which +Angle I call the refracting Angle of the Prism. And whilst I view'd it, +I held it and the Prism before a Window in such manner that the Sides of +the Paper were parallel to the Prism, and both those Sides and the Prism +were parallel to the Horizon, and the cross Line was also parallel to +it: and that the Light which fell from the Window upon the Paper made an +Angle with the Paper, equal to that Angle which was made with the same +Paper by the Light reflected from it to the Eye. Beyond the Prism was +the Wall of the Chamber under the Window covered over with black Cloth, +and the Cloth was involved in Darkness that no Light might be reflected +from thence, which in passing by the Edges of the Paper to the Eye, +might mingle itself with the Light of the Paper, and obscure the +Phænomenon thereof. These things being thus ordered, I found that if the +refracting Angle of the Prism be turned upwards, so that the Paper may +seem to be lifted upwards by the Refraction, its blue half will be +lifted higher by the Refraction than its red half. But if the refracting +Angle of the Prism be turned downward, so that the Paper may seem to be +carried lower by the Refraction, its blue half will be carried something +lower thereby than its red half. Wherefore in both Cases the Light which +comes from the blue half of the Paper through the Prism to the Eye, does +in like Circumstances suffer a greater Refraction than the Light which +comes from the red half, and by consequence is more refrangible. + +_Illustration._ In the eleventh Figure, MN represents the Window, and DE +the Paper terminated with parallel Sides DJ and HE, and by the +transverse Line FG distinguished into two halfs, the one DG of an +intensely blue Colour, the other FE of an intensely red. And BAC_cab_ +represents the Prism whose refracting Planes AB_ba_ and AC_ca_ meet in +the Edge of the refracting Angle A_a_. This Edge A_a_ being upward, is +parallel both to the Horizon, and to the Parallel-Edges of the Paper DJ +and HE, and the transverse Line FG is perpendicular to the Plane of the +Window. And _de_ represents the Image of the Paper seen by Refraction +upwards in such manner, that the blue half DG is carried higher to _dg_ +than the red half FE is to _fe_, and therefore suffers a greater +Refraction. If the Edge of the refracting Angle be turned downward, the +Image of the Paper will be refracted downward; suppose to [Greek: de], +and the blue half will be refracted lower to [Greek: dg] than the red +half is to [Greek: pe]. + +[Illustration: FIG. 11.] + +_Exper._ 2. About the aforesaid Paper, whose two halfs were painted over +with red and blue, and which was stiff like thin Pasteboard, I lapped +several times a slender Thred of very black Silk, in such manner that +the several parts of the Thred might appear upon the Colours like so +many black Lines drawn over them, or like long and slender dark Shadows +cast upon them. I might have drawn black Lines with a Pen, but the +Threds were smaller and better defined. This Paper thus coloured and +lined I set against a Wall perpendicularly to the Horizon, so that one +of the Colours might stand to the Right Hand, and the other to the Left. +Close before the Paper, at the Confine of the Colours below, I placed a +Candle to illuminate the Paper strongly: For the Experiment was tried in +the Night. The Flame of the Candle reached up to the lower edge of the +Paper, or a very little higher. Then at the distance of six Feet, and +one or two Inches from the Paper upon the Floor I erected a Glass Lens +four Inches and a quarter broad, which might collect the Rays coming +from the several Points of the Paper, and make them converge towards so +many other Points at the same distance of six Feet, and one or two +Inches on the other side of the Lens, and so form the Image of the +coloured Paper upon a white Paper placed there, after the same manner +that a Lens at a Hole in a Window casts the Images of Objects abroad +upon a Sheet of white Paper in a dark Room. The aforesaid white Paper, +erected perpendicular to the Horizon, and to the Rays which fell upon it +from the Lens, I moved sometimes towards the Lens, sometimes from it, to +find the Places where the Images of the blue and red Parts of the +coloured Paper appeared most distinct. Those Places I easily knew by the +Images of the black Lines which I had made by winding the Silk about the +Paper. For the Images of those fine and slender Lines (which by reason +of their Blackness were like Shadows on the Colours) were confused and +scarce visible, unless when the Colours on either side of each Line were +terminated most distinctly, Noting therefore, as diligently as I could, +the Places where the Images of the red and blue halfs of the coloured +Paper appeared most distinct, I found that where the red half of the +Paper appeared distinct, the blue half appeared confused, so that the +black Lines drawn upon it could scarce be seen; and on the contrary, +where the blue half appeared most distinct, the red half appeared +confused, so that the black Lines upon it were scarce visible. And +between the two Places where these Images appeared distinct there was +the distance of an Inch and a half; the distance of the white Paper from +the Lens, when the Image of the red half of the coloured Paper appeared +most distinct, being greater by an Inch and an half than the distance of +the same white Paper from the Lens, when the Image of the blue half +appeared most distinct. In like Incidences therefore of the blue and red +upon the Lens, the blue was refracted more by the Lens than the red, so +as to converge sooner by an Inch and a half, and therefore is more +refrangible. + +_Illustration._ In the twelfth Figure (p. 27), DE signifies the coloured +Paper, DG the blue half, FE the red half, MN the Lens, HJ the white +Paper in that Place where the red half with its black Lines appeared +distinct, and _hi_ the same Paper in that Place where the blue half +appeared distinct. The Place _hi_ was nearer to the Lens MN than the +Place HJ by an Inch and an half. + +_Scholium._ The same Things succeed, notwithstanding that some of the +Circumstances be varied; as in the first Experiment when the Prism and +Paper are any ways inclined to the Horizon, and in both when coloured +Lines are drawn upon very black Paper. But in the Description of these +Experiments, I have set down such Circumstances, by which either the +Phænomenon might be render'd more conspicuous, or a Novice might more +easily try them, or by which I did try them only. The same Thing, I have +often done in the following Experiments: Concerning all which, this one +Admonition may suffice. Now from these Experiments it follows not, that +all the Light of the blue is more refrangible than all the Light of the +red: For both Lights are mixed of Rays differently refrangible, so that +in the red there are some Rays not less refrangible than those of the +blue, and in the blue there are some Rays not more refrangible than +those of the red: But these Rays, in proportion to the whole Light, are +but few, and serve to diminish the Event of the Experiment, but are not +able to destroy it. For, if the red and blue Colours were more dilute +and weak, the distance of the Images would be less than an Inch and a +half; and if they were more intense and full, that distance would be +greater, as will appear hereafter. These Experiments may suffice for the +Colours of Natural Bodies. For in the Colours made by the Refraction of +Prisms, this Proposition will appear by the Experiments which are now to +follow in the next Proposition. + + +_PROP._ II. THEOR. II. + +_The Light of the Sun consists of Rays differently Refrangible._ + +The PROOF by Experiments. + +[Illustration: FIG. 12.] + +[Illustration: FIG. 13.] + +_Exper._ 3. + +In a very dark Chamber, at a round Hole, about one third Part of an Inch +broad, made in the Shut of a Window, I placed a Glass Prism, whereby the +Beam of the Sun's Light, which came in at that Hole, might be refracted +upwards toward the opposite Wall of the Chamber, and there form a +colour'd Image of the Sun. The Axis of the Prism (that is, the Line +passing through the middle of the Prism from one end of it to the other +end parallel to the edge of the Refracting Angle) was in this and the +following Experiments perpendicular to the incident Rays. About this +Axis I turned the Prism slowly, and saw the refracted Light on the Wall, +or coloured Image of the Sun, first to descend, and then to ascend. +Between the Descent and Ascent, when the Image seemed Stationary, I +stopp'd the Prism, and fix'd it in that Posture, that it should be moved +no more. For in that Posture the Refractions of the Light at the two +Sides of the refracting Angle, that is, at the Entrance of the Rays into +the Prism, and at their going out of it, were equal to one another.[C] +So also in other Experiments, as often as I would have the Refractions +on both sides the Prism to be equal to one another, I noted the Place +where the Image of the Sun formed by the refracted Light stood still +between its two contrary Motions, in the common Period of its Progress +and Regress; and when the Image fell upon that Place, I made fast the +Prism. And in this Posture, as the most convenient, it is to be +understood that all the Prisms are placed in the following Experiments, +unless where some other Posture is described. The Prism therefore being +placed in this Posture, I let the refracted Light fall perpendicularly +upon a Sheet of white Paper at the opposite Wall of the Chamber, and +observed the Figure and Dimensions of the Solar Image formed on the +Paper by that Light. This Image was Oblong and not Oval, but terminated +with two Rectilinear and Parallel Sides, and two Semicircular Ends. On +its Sides it was bounded pretty distinctly, but on its Ends very +confusedly and indistinctly, the Light there decaying and vanishing by +degrees. The Breadth of this Image answered to the Sun's Diameter, and +was about two Inches and the eighth Part of an Inch, including the +Penumbra. For the Image was eighteen Feet and an half distant from the +Prism, and at this distance that Breadth, if diminished by the Diameter +of the Hole in the Window-shut, that is by a quarter of an Inch, +subtended an Angle at the Prism of about half a Degree, which is the +Sun's apparent Diameter. But the Length of the Image was about ten +Inches and a quarter, and the Length of the Rectilinear Sides about +eight Inches; and the refracting Angle of the Prism, whereby so great a +Length was made, was 64 degrees. With a less Angle the Length of the +Image was less, the Breadth remaining the same. If the Prism was turned +about its Axis that way which made the Rays emerge more obliquely out of +the second refracting Surface of the Prism, the Image soon became an +Inch or two longer, or more; and if the Prism was turned about the +contrary way, so as to make the Rays fall more obliquely on the first +refracting Surface, the Image soon became an Inch or two shorter. And +therefore in trying this Experiment, I was as curious as I could be in +placing the Prism by the above-mention'd Rule exactly in such a Posture, +that the Refractions of the Rays at their Emergence out of the Prism +might be equal to that at their Incidence on it. This Prism had some +Veins running along within the Glass from one end to the other, which +scattered some of the Sun's Light irregularly, but had no sensible +Effect in increasing the Length of the coloured Spectrum. For I tried +the same Experiment with other Prisms with the same Success. And +particularly with a Prism which seemed free from such Veins, and whose +refracting Angle was 62-1/2 Degrees, I found the Length of the Image +9-3/4 or 10 Inches at the distance of 18-1/2 Feet from the Prism, the +Breadth of the Hole in the Window-shut being 1/4 of an Inch, as before. +And because it is easy to commit a Mistake in placing the Prism in its +due Posture, I repeated the Experiment four or five Times, and always +found the Length of the Image that which is set down above. With another +Prism of clearer Glass and better Polish, which seemed free from Veins, +and whose refracting Angle was 63-1/2 Degrees, the Length of this Image +at the same distance of 18-1/2 Feet was also about 10 Inches, or 10-1/8. +Beyond these Measures for about a 1/4 or 1/3 of an Inch at either end of +the Spectrum the Light of the Clouds seemed to be a little tinged with +red and violet, but so very faintly, that I suspected that Tincture +might either wholly, or in great Measure arise from some Rays of the +Spectrum scattered irregularly by some Inequalities in the Substance and +Polish of the Glass, and therefore I did not include it in these +Measures. Now the different Magnitude of the hole in the Window-shut, +and different thickness of the Prism where the Rays passed through it, +and different inclinations of the Prism to the Horizon, made no sensible +changes in the length of the Image. Neither did the different matter of +the Prisms make any: for in a Vessel made of polished Plates of Glass +cemented together in the shape of a Prism and filled with Water, there +is the like Success of the Experiment according to the quantity of the +Refraction. It is farther to be observed, that the Rays went on in right +Lines from the Prism to the Image, and therefore at their very going out +of the Prism had all that Inclination to one another from which the +length of the Image proceeded, that is, the Inclination of more than two +degrees and an half. And yet according to the Laws of Opticks vulgarly +received, they could not possibly be so much inclined to one another.[D] +For let EG [_Fig._ 13. (p. 27)] represent the Window-shut, F the hole +made therein through which a beam of the Sun's Light was transmitted +into the darkened Chamber, and ABC a Triangular Imaginary Plane whereby +the Prism is feigned to be cut transversely through the middle of the +Light. Or if you please, let ABC represent the Prism it self, looking +directly towards the Spectator's Eye with its nearer end: And let XY be +the Sun, MN the Paper upon which the Solar Image or Spectrum is cast, +and PT the Image it self whose sides towards _v_ and _w_ are Rectilinear +and Parallel, and ends towards P and T Semicircular. YKHP and XLJT are +two Rays, the first of which comes from the lower part of the Sun to the +higher part of the Image, and is refracted in the Prism at K and H, and +the latter comes from the higher part of the Sun to the lower part of +the Image, and is refracted at L and J. Since the Refractions on both +sides the Prism are equal to one another, that is, the Refraction at K +equal to the Refraction at J, and the Refraction at L equal to the +Refraction at H, so that the Refractions of the incident Rays at K and L +taken together, are equal to the Refractions of the emergent Rays at H +and J taken together: it follows by adding equal things to equal things, +that the Refractions at K and H taken together, are equal to the +Refractions at J and L taken together, and therefore the two Rays being +equally refracted, have the same Inclination to one another after +Refraction which they had before; that is, the Inclination of half a +Degree answering to the Sun's Diameter. For so great was the inclination +of the Rays to one another before Refraction. So then, the length of the +Image PT would by the Rules of Vulgar Opticks subtend an Angle of half a +Degree at the Prism, and by Consequence be equal to the breadth _vw_; +and therefore the Image would be round. Thus it would be were the two +Rays XLJT and YKHP, and all the rest which form the Image P_w_T_v_, +alike refrangible. And therefore seeing by Experience it is found that +the Image is not round, but about five times longer than broad, the Rays +which going to the upper end P of the Image suffer the greatest +Refraction, must be more refrangible than those which go to the lower +end T, unless the Inequality of Refraction be casual. + +This Image or Spectrum PT was coloured, being red at its least refracted +end T, and violet at its most refracted end P, and yellow green and +blue in the intermediate Spaces. Which agrees with the first +Proposition, that Lights which differ in Colour, do also differ in +Refrangibility. The length of the Image in the foregoing Experiments, I +measured from the faintest and outmost red at one end, to the faintest +and outmost blue at the other end, excepting only a little Penumbra, +whose breadth scarce exceeded a quarter of an Inch, as was said above. + +_Exper._ 4. In the Sun's Beam which was propagated into the Room through +the hole in the Window-shut, at the distance of some Feet from the hole, +I held the Prism in such a Posture, that its Axis might be perpendicular +to that Beam. Then I looked through the Prism upon the hole, and turning +the Prism to and fro about its Axis, to make the Image of the Hole +ascend and descend, when between its two contrary Motions it seemed +Stationary, I stopp'd the Prism, that the Refractions of both sides of +the refracting Angle might be equal to each other, as in the former +Experiment. In this situation of the Prism viewing through it the said +Hole, I observed the length of its refracted Image to be many times +greater than its breadth, and that the most refracted part thereof +appeared violet, the least refracted red, the middle parts blue, green +and yellow in order. The same thing happen'd when I removed the Prism +out of the Sun's Light, and looked through it upon the hole shining by +the Light of the Clouds beyond it. And yet if the Refraction were done +regularly according to one certain Proportion of the Sines of Incidence +and Refraction as is vulgarly supposed, the refracted Image ought to +have appeared round. + +So then, by these two Experiments it appears, that in Equal Incidences +there is a considerable inequality of Refractions. But whence this +inequality arises, whether it be that some of the incident Rays are +refracted more, and others less, constantly, or by chance, or that one +and the same Ray is by Refraction disturbed, shatter'd, dilated, and as +it were split and spread into many diverging Rays, as _Grimaldo_ +supposes, does not yet appear by these Experiments, but will appear by +those that follow. + +_Exper._ 5. Considering therefore, that if in the third Experiment the +Image of the Sun should be drawn out into an oblong Form, either by a +Dilatation of every Ray, or by any other casual inequality of the +Refractions, the same oblong Image would by a second Refraction made +sideways be drawn out as much in breadth by the like Dilatation of the +Rays, or other casual inequality of the Refractions sideways, I tried +what would be the Effects of such a second Refraction. For this end I +ordered all things as in the third Experiment, and then placed a second +Prism immediately after the first in a cross Position to it, that it +might again refract the beam of the Sun's Light which came to it through +the first Prism. In the first Prism this beam was refracted upwards, and +in the second sideways. And I found that by the Refraction of the second +Prism, the breadth of the Image was not increased, but its superior +part, which in the first Prism suffered the greater Refraction, and +appeared violet and blue, did again in the second Prism suffer a greater +Refraction than its inferior part, which appeared red and yellow, and +this without any Dilatation of the Image in breadth. + +[Illustration: FIG. 14] + +_Illustration._ Let S [_Fig._ 14, 15.] represent the Sun, F the hole in +the Window, ABC the first Prism, DH the second Prism, Y the round Image +of the Sun made by a direct beam of Light when the Prisms are taken +away, PT the oblong Image of the Sun made by that beam passing through +the first Prism alone, when the second Prism is taken away, and _pt_ the +Image made by the cross Refractions of both Prisms together. Now if the +Rays which tend towards the several Points of the round Image Y were +dilated and spread by the Refraction of the first Prism, so that they +should not any longer go in single Lines to single Points, but that +every Ray being split, shattered, and changed from a Linear Ray to a +Superficies of Rays diverging from the Point of Refraction, and lying in +the Plane of the Angles of Incidence and Refraction, they should go in +those Planes to so many Lines reaching almost from one end of the Image +PT to the other, and if that Image should thence become oblong: those +Rays and their several parts tending towards the several Points of the +Image PT ought to be again dilated and spread sideways by the transverse +Refraction of the second Prism, so as to compose a four square Image, +such as is represented at [Greek: pt]. For the better understanding of +which, let the Image PT be distinguished into five equal parts PQK, +KQRL, LRSM, MSVN, NVT. And by the same irregularity that the orbicular +Light Y is by the Refraction of the first Prism dilated and drawn out +into a long Image PT, the Light PQK which takes up a space of the same +length and breadth with the Light Y ought to be by the Refraction of the +second Prism dilated and drawn out into the long Image _[Greek: p]qkp_, +and the Light KQRL into the long Image _kqrl_, and the Lights LRSM, +MSVN, NVT, into so many other long Images _lrsm_, _msvn_, _nvt[Greek: +t]_; and all these long Images would compose the four square Images +_[Greek: pt]_. Thus it ought to be were every Ray dilated by Refraction, +and spread into a triangular Superficies of Rays diverging from the +Point of Refraction. For the second Refraction would spread the Rays one +way as much as the first doth another, and so dilate the Image in +breadth as much as the first doth in length. And the same thing ought to +happen, were some rays casually refracted more than others. But the +Event is otherwise. The Image PT was not made broader by the Refraction +of the second Prism, but only became oblique, as 'tis represented at +_pt_, its upper end P being by the Refraction translated to a greater +distance than its lower end T. So then the Light which went towards the +upper end P of the Image, was (at equal Incidences) more refracted in +the second Prism, than the Light which tended towards the lower end T, +that is the blue and violet, than the red and yellow; and therefore was +more refrangible. The same Light was by the Refraction of the first +Prism translated farther from the place Y to which it tended before +Refraction; and therefore suffered as well in the first Prism as in the +second a greater Refraction than the rest of the Light, and by +consequence was more refrangible than the rest, even before its +incidence on the first Prism. + +Sometimes I placed a third Prism after the second, and sometimes also a +fourth after the third, by all which the Image might be often refracted +sideways: but the Rays which were more refracted than the rest in the +first Prism were also more refracted in all the rest, and that without +any Dilatation of the Image sideways: and therefore those Rays for their +constancy of a greater Refraction are deservedly reputed more +refrangible. + +[Illustration: FIG. 15] + +But that the meaning of this Experiment may more clearly appear, it is +to be considered that the Rays which are equally refrangible do fall +upon a Circle answering to the Sun's Disque. For this was proved in the +third Experiment. By a Circle I understand not here a perfect +geometrical Circle, but any orbicular Figure whose length is equal to +its breadth, and which, as to Sense, may seem circular. Let therefore AG +[in _Fig._ 15.] represent the Circle which all the most refrangible Rays +propagated from the whole Disque of the Sun, would illuminate and paint +upon the opposite Wall if they were alone; EL the Circle which all the +least refrangible Rays would in like manner illuminate and paint if they +were alone; BH, CJ, DK, the Circles which so many intermediate sorts of +Rays would successively paint upon the Wall, if they were singly +propagated from the Sun in successive order, the rest being always +intercepted; and conceive that there are other intermediate Circles +without Number, which innumerable other intermediate sorts of Rays would +successively paint upon the Wall if the Sun should successively emit +every sort apart. And seeing the Sun emits all these sorts at once, they +must all together illuminate and paint innumerable equal Circles, of all +which, being according to their degrees of Refrangibility placed in +order in a continual Series, that oblong Spectrum PT is composed which I +described in the third Experiment. Now if the Sun's circular Image Y [in +_Fig._ 15.] which is made by an unrefracted beam of Light was by any +Dilation of the single Rays, or by any other irregularity in the +Refraction of the first Prism, converted into the oblong Spectrum, PT: +then ought every Circle AG, BH, CJ, &c. in that Spectrum, by the cross +Refraction of the second Prism again dilating or otherwise scattering +the Rays as before, to be in like manner drawn out and transformed into +an oblong Figure, and thereby the breadth of the Image PT would be now +as much augmented as the length of the Image Y was before by the +Refraction of the first Prism; and thus by the Refractions of both +Prisms together would be formed a four square Figure _p[Greek: +p]t[Greek: t]_, as I described above. Wherefore since the breadth of the +Spectrum PT is not increased by the Refraction sideways, it is certain +that the Rays are not split or dilated, or otherways irregularly +scatter'd by that Refraction, but that every Circle is by a regular and +uniform Refraction translated entire into another Place, as the Circle +AG by the greatest Refraction into the place _ag_, the Circle BH by a +less Refraction into the place _bh_, the Circle CJ by a Refraction still +less into the place _ci_, and so of the rest; by which means a new +Spectrum _pt_ inclined to the former PT is in like manner composed of +Circles lying in a right Line; and these Circles must be of the same +bigness with the former, because the breadths of all the Spectrums Y, PT +and _pt_ at equal distances from the Prisms are equal. + +I considered farther, that by the breadth of the hole F through which +the Light enters into the dark Chamber, there is a Penumbra made in the +Circuit of the Spectrum Y, and that Penumbra remains in the rectilinear +Sides of the Spectrums PT and _pt_. I placed therefore at that hole a +Lens or Object-glass of a Telescope which might cast the Image of the +Sun distinctly on Y without any Penumbra at all, and found that the +Penumbra of the rectilinear Sides of the oblong Spectrums PT and _pt_ +was also thereby taken away, so that those Sides appeared as distinctly +defined as did the Circumference of the first Image Y. Thus it happens +if the Glass of the Prisms be free from Veins, and their sides be +accurately plane and well polished without those numberless Waves or +Curles which usually arise from Sand-holes a little smoothed in +polishing with Putty. If the Glass be only well polished and free from +Veins, and the Sides not accurately plane, but a little Convex or +Concave, as it frequently happens; yet may the three Spectrums Y, PT and +_pt_ want Penumbras, but not in equal distances from the Prisms. Now +from this want of Penumbras, I knew more certainly that every one of the +Circles was refracted according to some most regular, uniform and +constant Law. For if there were any irregularity in the Refraction, the +right Lines AE and GL, which all the Circles in the Spectrum PT do +touch, could not by that Refraction be translated into the Lines _ae_ +and _gl_ as distinct and straight as they were before, but there would +arise in those translated Lines some Penumbra or Crookedness or +Undulation, or other sensible Perturbation contrary to what is found by +Experience. Whatsoever Penumbra or Perturbation should be made in the +Circles by the cross Refraction of the second Prism, all that Penumbra +or Perturbation would be conspicuous in the right Lines _ae_ and _gl_ +which touch those Circles. And therefore since there is no such Penumbra +or Perturbation in those right Lines, there must be none in the +Circles. Since the distance between those Tangents or breadth of the +Spectrum is not increased by the Refractions, the Diameters of the +Circles are not increased thereby. Since those Tangents continue to be +right Lines, every Circle which in the first Prism is more or less +refracted, is exactly in the same proportion more or less refracted in +the second. And seeing all these things continue to succeed after the +same manner when the Rays are again in a third Prism, and again in a +fourth refracted sideways, it is evident that the Rays of one and the +same Circle, as to their degree of Refrangibility, continue always +uniform and homogeneal to one another, and that those of several Circles +do differ in degree of Refrangibility, and that in some certain and +constant Proportion. Which is the thing I was to prove. + +There is yet another Circumstance or two of this Experiment by which it +becomes still more plain and convincing. Let the second Prism DH [in +_Fig._ 16.] be placed not immediately after the first, but at some +distance from it; suppose in the mid-way between it and the Wall on +which the oblong Spectrum PT is cast, so that the Light from the first +Prism may fall upon it in the form of an oblong Spectrum [Greek: pt] +parallel to this second Prism, and be refracted sideways to form the +oblong Spectrum _pt_ upon the Wall. And you will find as before, that +this Spectrum _pt_ is inclined to that Spectrum PT, which the first +Prism forms alone without the second; the blue ends P and _p_ being +farther distant from one another than the red ones T and _t_, and by +consequence that the Rays which go to the blue end [Greek: p] of the +Image [Greek: pt], and which therefore suffer the greatest Refraction in +the first Prism, are again in the second Prism more refracted than the +rest. + +[Illustration: FIG. 16.] + +[Illustration: FIG. 17.] + +The same thing I try'd also by letting the Sun's Light into a dark Room +through two little round holes F and [Greek: ph] [in _Fig._ 17.] made in +the Window, and with two parallel Prisms ABC and [Greek: abg] placed at +those holes (one at each) refracting those two beams of Light to the +opposite Wall of the Chamber, in such manner that the two colour'd +Images PT and MN which they there painted were joined end to end and lay +in one straight Line, the red end T of the one touching the blue end M +of the other. For if these two refracted Beams were again by a third +Prism DH placed cross to the two first, refracted sideways, and the +Spectrums thereby translated to some other part of the Wall of the +Chamber, suppose the Spectrum PT to _pt_ and the Spectrum MN to _mn_, +these translated Spectrums _pt_ and _mn_ would not lie in one straight +Line with their ends contiguous as before, but be broken off from one +another and become parallel, the blue end _m_ of the Image _mn_ being by +a greater Refraction translated farther from its former place MT, than +the red end _t_ of the other Image _pt_ from the same place MT; which +puts the Proposition past Dispute. And this happens whether the third +Prism DH be placed immediately after the two first, or at a great +distance from them, so that the Light refracted in the two first Prisms +be either white and circular, or coloured and oblong when it falls on +the third. + +_Exper._ 6. In the middle of two thin Boards I made round holes a third +part of an Inch in diameter, and in the Window-shut a much broader hole +being made to let into my darkned Chamber a large Beam of the Sun's +Light; I placed a Prism behind the Shut in that beam to refract it +towards the opposite Wall, and close behind the Prism I fixed one of the +Boards, in such manner that the middle of the refracted Light might pass +through the hole made in it, and the rest be intercepted by the Board. +Then at the distance of about twelve Feet from the first Board I fixed +the other Board in such manner that the middle of the refracted Light +which came through the hole in the first Board, and fell upon the +opposite Wall, might pass through the hole in this other Board, and the +rest being intercepted by the Board might paint upon it the coloured +Spectrum of the Sun. And close behind this Board I fixed another Prism +to refract the Light which came through the hole. Then I returned +speedily to the first Prism, and by turning it slowly to and fro about +its Axis, I caused the Image which fell upon the second Board to move up +and down upon that Board, that all its parts might successively pass +through the hole in that Board and fall upon the Prism behind it. And in +the mean time, I noted the places on the opposite Wall to which that +Light after its Refraction in the second Prism did pass; and by the +difference of the places I found that the Light which being most +refracted in the first Prism did go to the blue end of the Image, was +again more refracted in the second Prism than the Light which went to +the red end of that Image, which proves as well the first Proposition as +the second. And this happened whether the Axis of the two Prisms were +parallel, or inclined to one another, and to the Horizon in any given +Angles. + +_Illustration._ Let F [in _Fig._ 18.] be the wide hole in the +Window-shut, through which the Sun shines upon the first Prism ABC, and +let the refracted Light fall upon the middle of the Board DE, and the +middle part of that Light upon the hole G made in the middle part of +that Board. Let this trajected part of that Light fall again upon the +middle of the second Board _de_, and there paint such an oblong coloured +Image of the Sun as was described in the third Experiment. By turning +the Prism ABC slowly to and fro about its Axis, this Image will be made +to move up and down the Board _de_, and by this means all its parts from +one end to the other may be made to pass successively through the hole +_g_ which is made in the middle of that Board. In the mean while another +Prism _abc_ is to be fixed next after that hole _g_, to refract the +trajected Light a second time. And these things being thus ordered, I +marked the places M and N of the opposite Wall upon which the refracted +Light fell, and found that whilst the two Boards and second Prism +remained unmoved, those places by turning the first Prism about its Axis +were changed perpetually. For when the lower part of the Light which +fell upon the second Board _de_ was cast through the hole _g_, it went +to a lower place M on the Wall and when the higher part of that Light +was cast through the same hole _g_, it went to a higher place N on the +Wall, and when any intermediate part of the Light was cast through that +hole, it went to some place on the Wall between M and N. The unchanged +Position of the holes in the Boards, made the Incidence of the Rays upon +the second Prism to be the same in all cases. And yet in that common +Incidence some of the Rays were more refracted, and others less. And +those were more refracted in this Prism, which by a greater Refraction +in the first Prism were more turned out of the way, and therefore for +their Constancy of being more refracted are deservedly called more +refrangible. + +[Illustration: FIG. 18.] + +[Illustration: FIG. 20.] + +_Exper._ 7. At two holes made near one another in my Window-shut I +placed two Prisms, one at each, which might cast upon the opposite Wall +(after the manner of the third Experiment) two oblong coloured Images of +the Sun. And at a little distance from the Wall I placed a long slender +Paper with straight and parallel edges, and ordered the Prisms and Paper +so, that the red Colour of one Image might fall directly upon one half +of the Paper, and the violet Colour of the other Image upon the other +half of the same Paper; so that the Paper appeared of two Colours, red +and violet, much after the manner of the painted Paper in the first and +second Experiments. Then with a black Cloth I covered the Wall behind +the Paper, that no Light might be reflected from it to disturb the +Experiment, and viewing the Paper through a third Prism held parallel +to it, I saw that half of it which was illuminated by the violet Light +to be divided from the other half by a greater Refraction, especially +when I went a good way off from the Paper. For when I viewed it too near +at hand, the two halfs of the Paper did not appear fully divided from +one another, but seemed contiguous at one of their Angles like the +painted Paper in the first Experiment. Which also happened when the +Paper was too broad. + +[Illustration: FIG. 19.] + +Sometimes instead of the Paper I used a white Thred, and this appeared +through the Prism divided into two parallel Threds as is represented in +the nineteenth Figure, where DG denotes the Thred illuminated with +violet Light from D to E and with red Light from F to G, and _defg_ are +the parts of the Thred seen by Refraction. If one half of the Thred be +constantly illuminated with red, and the other half be illuminated with +all the Colours successively, (which may be done by causing one of the +Prisms to be turned about its Axis whilst the other remains unmoved) +this other half in viewing the Thred through the Prism, will appear in +a continual right Line with the first half when illuminated with red, +and begin to be a little divided from it when illuminated with Orange, +and remove farther from it when illuminated with yellow, and still +farther when with green, and farther when with blue, and go yet farther +off when illuminated with Indigo, and farthest when with deep violet. +Which plainly shews, that the Lights of several Colours are more and +more refrangible one than another, in this Order of their Colours, red, +orange, yellow, green, blue, indigo, deep violet; and so proves as well +the first Proposition as the second. + +I caused also the coloured Spectrums PT [in _Fig._ 17.] and MN made in a +dark Chamber by the Refractions of two Prisms to lie in a Right Line end +to end, as was described above in the fifth Experiment, and viewing them +through a third Prism held parallel to their Length, they appeared no +longer in a Right Line, but became broken from one another, as they are +represented at _pt_ and _mn_, the violet end _m_ of the Spectrum _mn_ +being by a greater Refraction translated farther from its former Place +MT than the red end _t_ of the other Spectrum _pt_. + +I farther caused those two Spectrums PT [in _Fig._ 20.] and MN to become +co-incident in an inverted Order of their Colours, the red end of each +falling on the violet end of the other, as they are represented in the +oblong Figure PTMN; and then viewing them through a Prism DH held +parallel to their Length, they appeared not co-incident, as when view'd +with the naked Eye, but in the form of two distinct Spectrums _pt_ and +_mn_ crossing one another in the middle after the manner of the Letter +X. Which shews that the red of the one Spectrum and violet of the other, +which were co-incident at PN and MT, being parted from one another by a +greater Refraction of the violet to _p_ and _m_ than of the red to _n_ +and _t_, do differ in degrees of Refrangibility. + +I illuminated also a little Circular Piece of white Paper all over with +the Lights of both Prisms intermixed, and when it was illuminated with +the red of one Spectrum, and deep violet of the other, so as by the +Mixture of those Colours to appear all over purple, I viewed the Paper, +first at a less distance, and then at a greater, through a third Prism; +and as I went from the Paper, the refracted Image thereof became more +and more divided by the unequal Refraction of the two mixed Colours, and +at length parted into two distinct Images, a red one and a violet one, +whereof the violet was farthest from the Paper, and therefore suffered +the greatest Refraction. And when that Prism at the Window, which cast +the violet on the Paper was taken away, the violet Image disappeared; +but when the other Prism was taken away the red vanished; which shews, +that these two Images were nothing else than the Lights of the two +Prisms, which had been intermixed on the purple Paper, but were parted +again by their unequal Refractions made in the third Prism, through +which the Paper was view'd. This also was observable, that if one of the +Prisms at the Window, suppose that which cast the violet on the Paper, +was turned about its Axis to make all the Colours in this order, +violet, indigo, blue, green, yellow, orange, red, fall successively on +the Paper from that Prism, the violet Image changed Colour accordingly, +turning successively to indigo, blue, green, yellow and red, and in +changing Colour came nearer and nearer to the red Image made by the +other Prism, until when it was also red both Images became fully +co-incident. + +I placed also two Paper Circles very near one another, the one in the +red Light of one Prism, and the other in the violet Light of the other. +The Circles were each of them an Inch in diameter, and behind them the +Wall was dark, that the Experiment might not be disturbed by any Light +coming from thence. These Circles thus illuminated, I viewed through a +Prism, so held, that the Refraction might be made towards the red +Circle, and as I went from them they came nearer and nearer together, +and at length became co-incident; and afterwards when I went still +farther off, they parted again in a contrary Order, the violet by a +greater Refraction being carried beyond the red. + +_Exper._ 8. In Summer, when the Sun's Light uses to be strongest, I +placed a Prism at the Hole of the Window-shut, as in the third +Experiment, yet so that its Axis might be parallel to the Axis of the +World, and at the opposite Wall in the Sun's refracted Light, I placed +an open Book. Then going six Feet and two Inches from the Book, I placed +there the above-mentioned Lens, by which the Light reflected from the +Book might be made to converge and meet again at the distance of six +Feet and two Inches behind the Lens, and there paint the Species of the +Book upon a Sheet of white Paper much after the manner of the second +Experiment. The Book and Lens being made fast, I noted the Place where +the Paper was, when the Letters of the Book, illuminated by the fullest +red Light of the Solar Image falling upon it, did cast their Species on +that Paper most distinctly: And then I stay'd till by the Motion of the +Sun, and consequent Motion of his Image on the Book, all the Colours +from that red to the middle of the blue pass'd over those Letters; and +when those Letters were illuminated by that blue, I noted again the +Place of the Paper when they cast their Species most distinctly upon it: +And I found that this last Place of the Paper was nearer to the Lens +than its former Place by about two Inches and an half, or two and three +quarters. So much sooner therefore did the Light in the violet end of +the Image by a greater Refraction converge and meet, than the Light in +the red end. But in trying this, the Chamber was as dark as I could make +it. For, if these Colours be diluted and weakned by the Mixture of any +adventitious Light, the distance between the Places of the Paper will +not be so great. This distance in the second Experiment, where the +Colours of natural Bodies were made use of, was but an Inch and an half, +by reason of the Imperfection of those Colours. Here in the Colours of +the Prism, which are manifestly more full, intense, and lively than +those of natural Bodies, the distance is two Inches and three quarters. +And were the Colours still more full, I question not but that the +distance would be considerably greater. For the coloured Light of the +Prism, by the interfering of the Circles described in the second Figure +of the fifth Experiment, and also by the Light of the very bright Clouds +next the Sun's Body intermixing with these Colours, and by the Light +scattered by the Inequalities in the Polish of the Prism, was so very +much compounded, that the Species which those faint and dark Colours, +the indigo and violet, cast upon the Paper were not distinct enough to +be well observed. + +_Exper._ 9. A Prism, whose two Angles at its Base were equal to one +another, and half right ones, and the third a right one, I placed in a +Beam of the Sun's Light let into a dark Chamber through a Hole in the +Window-shut, as in the third Experiment. And turning the Prism slowly +about its Axis, until all the Light which went through one of its +Angles, and was refracted by it began to be reflected by its Base, at +which till then it went out of the Glass, I observed that those Rays +which had suffered the greatest Refraction were sooner reflected than +the rest. I conceived therefore, that those Rays of the reflected Light, +which were most refrangible, did first of all by a total Reflexion +become more copious in that Light than the rest, and that afterwards the +rest also, by a total Reflexion, became as copious as these. To try +this, I made the reflected Light pass through another Prism, and being +refracted by it to fall afterwards upon a Sheet of white Paper placed +at some distance behind it, and there by that Refraction to paint the +usual Colours of the Prism. And then causing the first Prism to be +turned about its Axis as above, I observed that when those Rays, which +in this Prism had suffered the greatest Refraction, and appeared of a +blue and violet Colour began to be totally reflected, the blue and +violet Light on the Paper, which was most refracted in the second Prism, +received a sensible Increase above that of the red and yellow, which was +least refracted; and afterwards, when the rest of the Light which was +green, yellow, and red, began to be totally reflected in the first +Prism, the Light of those Colours on the Paper received as great an +Increase as the violet and blue had done before. Whence 'tis manifest, +that the Beam of Light reflected by the Base of the Prism, being +augmented first by the more refrangible Rays, and afterwards by the less +refrangible ones, is compounded of Rays differently refrangible. And +that all such reflected Light is of the same Nature with the Sun's Light +before its Incidence on the Base of the Prism, no Man ever doubted; it +being generally allowed, that Light by such Reflexions suffers no +Alteration in its Modifications and Properties. I do not here take +Notice of any Refractions made in the sides of the first Prism, because +the Light enters it perpendicularly at the first side, and goes out +perpendicularly at the second side, and therefore suffers none. So then, +the Sun's incident Light being of the same Temper and Constitution with +his emergent Light, and the last being compounded of Rays differently +refrangible, the first must be in like manner compounded. + +[Illustration: FIG. 21.] + +_Illustration._ In the twenty-first Figure, ABC is the first Prism, BC +its Base, B and C its equal Angles at the Base, each of 45 Degrees, A +its rectangular Vertex, FM a beam of the Sun's Light let into a dark +Room through a hole F one third part of an Inch broad, M its Incidence +on the Base of the Prism, MG a less refracted Ray, MH a more refracted +Ray, MN the beam of Light reflected from the Base, VXY the second Prism +by which this beam in passing through it is refracted, N_t_ the less +refracted Light of this beam, and N_p_ the more refracted part thereof. +When the first Prism ABC is turned about its Axis according to the order +of the Letters ABC, the Rays MH emerge more and more obliquely out of +that Prism, and at length after their most oblique Emergence are +reflected towards N, and going on to _p_ do increase the Number of the +Rays N_p_. Afterwards by continuing the Motion of the first Prism, the +Rays MG are also reflected to N and increase the number of the Rays +N_t_. And therefore the Light MN admits into its Composition, first the +more refrangible Rays, and then the less refrangible Rays, and yet after +this Composition is of the same Nature with the Sun's immediate Light +FM, the Reflexion of the specular Base BC causing no Alteration therein. + +_Exper._ 10. Two Prisms, which were alike in Shape, I tied so together, +that their Axis and opposite Sides being parallel, they composed a +Parallelopiped. And, the Sun shining into my dark Chamber through a +little hole in the Window-shut, I placed that Parallelopiped in his beam +at some distance from the hole, in such a Posture, that the Axes of the +Prisms might be perpendicular to the incident Rays, and that those Rays +being incident upon the first Side of one Prism, might go on through the +two contiguous Sides of both Prisms, and emerge out of the last Side of +the second Prism. This Side being parallel to the first Side of the +first Prism, caused the emerging Light to be parallel to the incident. +Then, beyond these two Prisms I placed a third, which might refract that +emergent Light, and by that Refraction cast the usual Colours of the +Prism upon the opposite Wall, or upon a sheet of white Paper held at a +convenient Distance behind the Prism for that refracted Light to fall +upon it. After this I turned the Parallelopiped about its Axis, and +found that when the contiguous Sides of the two Prisms became so oblique +to the incident Rays, that those Rays began all of them to be +reflected, those Rays which in the third Prism had suffered the greatest +Refraction, and painted the Paper with violet and blue, were first of +all by a total Reflexion taken out of the transmitted Light, the rest +remaining and on the Paper painting their Colours of green, yellow, +orange and red, as before; and afterwards by continuing the Motion of +the two Prisms, the rest of the Rays also by a total Reflexion vanished +in order, according to their degrees of Refrangibility. The Light +therefore which emerged out of the two Prisms is compounded of Rays +differently refrangible, seeing the more refrangible Rays may be taken +out of it, while the less refrangible remain. But this Light being +trajected only through the parallel Superficies of the two Prisms, if it +suffer'd any change by the Refraction of one Superficies it lost that +Impression by the contrary Refraction of the other Superficies, and so +being restor'd to its pristine Constitution, became of the same Nature +and Condition as at first before its Incidence on those Prisms; and +therefore, before its Incidence, was as much compounded of Rays +differently refrangible, as afterwards. + +[Illustration: FIG. 22.] + +_Illustration._ In the twenty second Figure ABC and BCD are the two +Prisms tied together in the form of a Parallelopiped, their Sides BC and +CB being contiguous, and their Sides AB and CD parallel. And HJK is the +third Prism, by which the Sun's Light propagated through the hole F into +the dark Chamber, and there passing through those sides of the Prisms +AB, BC, CB and CD, is refracted at O to the white Paper PT, falling +there partly upon P by a greater Refraction, partly upon T by a less +Refraction, and partly upon R and other intermediate places by +intermediate Refractions. By turning the Parallelopiped ACBD about its +Axis, according to the order of the Letters A, C, D, B, at length when +the contiguous Planes BC and CB become sufficiently oblique to the Rays +FM, which are incident upon them at M, there will vanish totally out of +the refracted Light OPT, first of all the most refracted Rays OP, (the +rest OR and OT remaining as before) then the Rays OR and other +intermediate ones, and lastly, the least refracted Rays OT. For when +the Plane BC becomes sufficiently oblique to the Rays incident upon it, +those Rays will begin to be totally reflected by it towards N; and first +the most refrangible Rays will be totally reflected (as was explained in +the preceding Experiment) and by Consequence must first disappear at P, +and afterwards the rest as they are in order totally reflected to N, +they must disappear in the same order at R and T. So then the Rays which +at O suffer the greatest Refraction, may be taken out of the Light MO +whilst the rest of the Rays remain in it, and therefore that Light MO is +compounded of Rays differently refrangible. And because the Planes AB +and CD are parallel, and therefore by equal and contrary Refractions +destroy one anothers Effects, the incident Light FM must be of the same +Kind and Nature with the emergent Light MO, and therefore doth also +consist of Rays differently refrangible. These two Lights FM and MO, +before the most refrangible Rays are separated out of the emergent Light +MO, agree in Colour, and in all other Properties so far as my +Observation reaches, and therefore are deservedly reputed of the same +Nature and Constitution, and by Consequence the one is compounded as +well as the other. But after the most refrangible Rays begin to be +totally reflected, and thereby separated out of the emergent Light MO, +that Light changes its Colour from white to a dilute and faint yellow, a +pretty good orange, a very full red successively, and then totally +vanishes. For after the most refrangible Rays which paint the Paper at +P with a purple Colour, are by a total Reflexion taken out of the beam +of Light MO, the rest of the Colours which appear on the Paper at R and +T being mix'd in the Light MO compound there a faint yellow, and after +the blue and part of the green which appear on the Paper between P and R +are taken away, the rest which appear between R and T (that is the +yellow, orange, red and a little green) being mixed in the beam MO +compound there an orange; and when all the Rays are by Reflexion taken +out of the beam MO, except the least refrangible, which at T appear of a +full red, their Colour is the same in that beam MO as afterwards at T, +the Refraction of the Prism HJK serving only to separate the differently +refrangible Rays, without making any Alteration in their Colours, as +shall be more fully proved hereafter. All which confirms as well the +first Proposition as the second. + +_Scholium._ If this Experiment and the former be conjoined and made one +by applying a fourth Prism VXY [in _Fig._ 22.] to refract the reflected +beam MN towards _tp_, the Conclusion will be clearer. For then the Light +N_p_ which in the fourth Prism is more refracted, will become fuller and +stronger when the Light OP, which in the third Prism HJK is more +refracted, vanishes at P; and afterwards when the less refracted Light +OT vanishes at T, the less refracted Light N_t_ will become increased +whilst the more refracted Light at _p_ receives no farther increase. And +as the trajected beam MO in vanishing is always of such a Colour as +ought to result from the mixture of the Colours which fall upon the +Paper PT, so is the reflected beam MN always of such a Colour as ought +to result from the mixture of the Colours which fall upon the Paper +_pt_. For when the most refrangible Rays are by a total Reflexion taken +out of the beam MO, and leave that beam of an orange Colour, the Excess +of those Rays in the reflected Light, does not only make the violet, +indigo and blue at _p_ more full, but also makes the beam MN change from +the yellowish Colour of the Sun's Light, to a pale white inclining to +blue, and afterward recover its yellowish Colour again, so soon as all +the rest of the transmitted Light MOT is reflected. + +Now seeing that in all this variety of Experiments, whether the Trial be +made in Light reflected, and that either from natural Bodies, as in the +first and second Experiment, or specular, as in the ninth; or in Light +refracted, and that either before the unequally refracted Rays are by +diverging separated from one another, and losing their whiteness which +they have altogether, appear severally of several Colours, as in the +fifth Experiment; or after they are separated from one another, and +appear colour'd as in the sixth, seventh, and eighth Experiments; or in +Light trajected through parallel Superficies, destroying each others +Effects, as in the tenth Experiment; there are always found Rays, which +at equal Incidences on the same Medium suffer unequal Refractions, and +that without any splitting or dilating of single Rays, or contingence in +the inequality of the Refractions, as is proved in the fifth and sixth +Experiments. And seeing the Rays which differ in Refrangibility may be +parted and sorted from one another, and that either by Refraction as in +the third Experiment, or by Reflexion as in the tenth, and then the +several sorts apart at equal Incidences suffer unequal Refractions, and +those sorts are more refracted than others after Separation, which were +more refracted before it, as in the sixth and following Experiments, and +if the Sun's Light be trajected through three or more cross Prisms +successively, those Rays which in the first Prism are refracted more +than others, are in all the following Prisms refracted more than others +in the same Rate and Proportion, as appears by the fifth Experiment; +it's manifest that the Sun's Light is an heterogeneous Mixture of Rays, +some of which are constantly more refrangible than others, as was +proposed. + + +_PROP._ III. THEOR. III. + +_The Sun's Light consists of Rays differing in Reflexibility, and those +Rays are more reflexible than others which are more refrangible._ + +This is manifest by the ninth and tenth Experiments: For in the ninth +Experiment, by turning the Prism about its Axis, until the Rays within +it which in going out into the Air were refracted by its Base, became so +oblique to that Base, as to begin to be totally reflected thereby; those +Rays became first of all totally reflected, which before at equal +Incidences with the rest had suffered the greatest Refraction. And the +same thing happens in the Reflexion made by the common Base of the two +Prisms in the tenth Experiment. + + +_PROP._ IV. PROB. I. + +_To separate from one another the heterogeneous Rays of compound Light._ + +[Illustration: FIG. 23.] + +The heterogeneous Rays are in some measure separated from one another by +the Refraction of the Prism in the third Experiment, and in the fifth +Experiment, by taking away the Penumbra from the rectilinear sides of +the coloured Image, that Separation in those very rectilinear sides or +straight edges of the Image becomes perfect. But in all places between +those rectilinear edges, those innumerable Circles there described, +which are severally illuminated by homogeneal Rays, by interfering with +one another, and being every where commix'd, do render the Light +sufficiently compound. But if these Circles, whilst their Centers keep +their Distances and Positions, could be made less in Diameter, their +interfering one with another, and by Consequence the Mixture of the +heterogeneous Rays would be proportionally diminish'd. In the twenty +third Figure let AG, BH, CJ, DK, EL, FM be the Circles which so many +sorts of Rays flowing from the same disque of the Sun, do in the third +Experiment illuminate; of all which and innumerable other intermediate +ones lying in a continual Series between the two rectilinear and +parallel edges of the Sun's oblong Image PT, that Image is compos'd, as +was explained in the fifth Experiment. And let _ag_, _bh_, _ci_, _dk_, +_el_, _fm_ be so many less Circles lying in a like continual Series +between two parallel right Lines _af_ and _gm_ with the same distances +between their Centers, and illuminated by the same sorts of Rays, that +is the Circle _ag_ with the same sort by which the corresponding Circle +AG was illuminated, and the Circle _bh_ with the same sort by which the +corresponding Circle BH was illuminated, and the rest of the Circles +_ci_, _dk_, _el_, _fm_ respectively, with the same sorts of Rays by +which the several corresponding Circles CJ, DK, EL, FM were illuminated. +In the Figure PT composed of the greater Circles, three of those Circles +AG, BH, CJ, are so expanded into one another, that the three sorts of +Rays by which those Circles are illuminated, together with other +innumerable sorts of intermediate Rays, are mixed at QR in the middle +of the Circle BH. And the like Mixture happens throughout almost the +whole length of the Figure PT. But in the Figure _pt_ composed of the +less Circles, the three less Circles _ag_, _bh_, _ci_, which answer to +those three greater, do not extend into one another; nor are there any +where mingled so much as any two of the three sorts of Rays by which +those Circles are illuminated, and which in the Figure PT are all of +them intermingled at BH. + +Now he that shall thus consider it, will easily understand that the +Mixture is diminished in the same Proportion with the Diameters of the +Circles. If the Diameters of the Circles whilst their Centers remain the +same, be made three times less than before, the Mixture will be also +three times less; if ten times less, the Mixture will be ten times less, +and so of other Proportions. That is, the Mixture of the Rays in the +greater Figure PT will be to their Mixture in the less _pt_, as the +Latitude of the greater Figure is to the Latitude of the less. For the +Latitudes of these Figures are equal to the Diameters of their Circles. +And hence it easily follows, that the Mixture of the Rays in the +refracted Spectrum _pt_ is to the Mixture of the Rays in the direct and +immediate Light of the Sun, as the breadth of that Spectrum is to the +difference between the length and breadth of the same Spectrum. + +So then, if we would diminish the Mixture of the Rays, we are to +diminish the Diameters of the Circles. Now these would be diminished if +the Sun's Diameter to which they answer could be made less than it is, +or (which comes to the same Purpose) if without Doors, at a great +distance from the Prism towards the Sun, some opake Body were placed, +with a round hole in the middle of it, to intercept all the Sun's Light, +excepting so much as coming from the middle of his Body could pass +through that Hole to the Prism. For so the Circles AG, BH, and the rest, +would not any longer answer to the whole Disque of the Sun, but only to +that Part of it which could be seen from the Prism through that Hole, +that it is to the apparent Magnitude of that Hole view'd from the Prism. +But that these Circles may answer more distinctly to that Hole, a Lens +is to be placed by the Prism to cast the Image of the Hole, (that is, +every one of the Circles AG, BH, &c.) distinctly upon the Paper at PT, +after such a manner, as by a Lens placed at a Window, the Species of +Objects abroad are cast distinctly upon a Paper within the Room, and the +rectilinear Sides of the oblong Solar Image in the fifth Experiment +became distinct without any Penumbra. If this be done, it will not be +necessary to place that Hole very far off, no not beyond the Window. And +therefore instead of that Hole, I used the Hole in the Window-shut, as +follows. + +_Exper._ 11. In the Sun's Light let into my darken'd Chamber through a +small round Hole in my Window-shut, at about ten or twelve Feet from the +Window, I placed a Lens, by which the Image of the Hole might be +distinctly cast upon a Sheet of white Paper, placed at the distance of +six, eight, ten, or twelve Feet from the Lens. For, according to the +difference of the Lenses I used various distances, which I think not +worth the while to describe. Then immediately after the Lens I placed a +Prism, by which the trajected Light might be refracted either upwards or +sideways, and thereby the round Image, which the Lens alone did cast +upon the Paper might be drawn out into a long one with Parallel Sides, +as in the third Experiment. This oblong Image I let fall upon another +Paper at about the same distance from the Prism as before, moving the +Paper either towards the Prism or from it, until I found the just +distance where the Rectilinear Sides of the Image became most distinct. +For in this Case, the Circular Images of the Hole, which compose that +Image after the same manner that the Circles _ag_, _bh_, _ci_, &c. do +the Figure _pt_ [in _Fig._ 23.] were terminated most distinctly without +any Penumbra, and therefore extended into one another the least that +they could, and by consequence the Mixture of the heterogeneous Rays was +now the least of all. By this means I used to form an oblong Image (such +as is _pt_) [in _Fig._ 23, and 24.] of Circular Images of the Hole, +(such as are _ag_, _bh_, _ci_, &c.) and by using a greater or less Hole +in the Window-shut, I made the Circular Images _ag_, _bh_, _ci_, &c. of +which it was formed, to become greater or less at pleasure, and thereby +the Mixture of the Rays in the Image _pt_ to be as much, or as little as +I desired. + +[Illustration: FIG. 24.] + +_Illustration._ In the twenty-fourth Figure, F represents the Circular +Hole in the Window-shut, MN the Lens, whereby the Image or Species of +that Hole is cast distinctly upon a Paper at J, ABC the Prism, whereby +the Rays are at their emerging out of the Lens refracted from J towards +another Paper at _pt_, and the round Image at J is turned into an oblong +Image _pt_ falling on that other Paper. This Image _pt_ consists of +Circles placed one after another in a Rectilinear Order, as was +sufficiently explained in the fifth Experiment; and these Circles are +equal to the Circle J, and consequently answer in magnitude to the Hole +F; and therefore by diminishing that Hole they may be at pleasure +diminished, whilst their Centers remain in their Places. By this means I +made the Breadth of the Image _pt_ to be forty times, and sometimes +sixty or seventy times less than its Length. As for instance, if the +Breadth of the Hole F be one tenth of an Inch, and MF the distance of +the Lens from the Hole be 12 Feet; and if _p_B or _p_M the distance of +the Image _pt_ from the Prism or Lens be 10 Feet, and the refracting +Angle of the Prism be 62 Degrees, the Breadth of the Image _pt_ will be +one twelfth of an Inch, and the Length about six Inches, and therefore +the Length to the Breadth as 72 to 1, and by consequence the Light of +this Image 71 times less compound than the Sun's direct Light. And Light +thus far simple and homogeneal, is sufficient for trying all the +Experiments in this Book about simple Light. For the Composition of +heterogeneal Rays is in this Light so little, that it is scarce to be +discovered and perceiv'd by Sense, except perhaps in the indigo and +violet. For these being dark Colours do easily suffer a sensible Allay +by that little scattering Light which uses to be refracted irregularly +by the Inequalities of the Prism. + +Yet instead of the Circular Hole F, 'tis better to substitute an oblong +Hole shaped like a long Parallelogram with its Length parallel to the +Prism ABC. For if this Hole be an Inch or two long, and but a tenth or +twentieth Part of an Inch broad, or narrower; the Light of the Image +_pt_ will be as simple as before, or simpler, and the Image will become +much broader, and therefore more fit to have Experiments try'd in its +Light than before. + +Instead of this Parallelogram Hole may be substituted a triangular one +of equal Sides, whose Base, for instance, is about the tenth Part of an +Inch, and its Height an Inch or more. For by this means, if the Axis of +the Prism be parallel to the Perpendicular of the Triangle, the Image +_pt_ [in _Fig._ 25.] will now be form'd of equicrural Triangles _ag_, +_bh_, _ci_, _dk_, _el_, _fm_, &c. and innumerable other intermediate +ones answering to the triangular Hole in Shape and Bigness, and lying +one after another in a continual Series between two Parallel Lines _af_ +and _gm_. These Triangles are a little intermingled at their Bases, but +not at their Vertices; and therefore the Light on the brighter Side _af_ +of the Image, where the Bases of the Triangles are, is a little +compounded, but on the darker Side _gm_ is altogether uncompounded, and +in all Places between the Sides the Composition is proportional to the +distances of the Places from that obscurer Side _gm_. And having a +Spectrum _pt_ of such a Composition, we may try Experiments either in +its stronger and less simple Light near the Side _af_, or in its weaker +and simpler Light near the other Side _gm_, as it shall seem most +convenient. + +[Illustration: FIG. 25.] + +But in making Experiments of this kind, the Chamber ought to be made as +dark as can be, lest any Foreign Light mingle it self with the Light of +the Spectrum _pt_, and render it compound; especially if we would try +Experiments in the more simple Light next the Side _gm_ of the Spectrum; +which being fainter, will have a less proportion to the Foreign Light; +and so by the mixture of that Light be more troubled, and made more +compound. The Lens also ought to be good, such as may serve for optical +Uses, and the Prism ought to have a large Angle, suppose of 65 or 70 +Degrees, and to be well wrought, being made of Glass free from Bubbles +and Veins, with its Sides not a little convex or concave, as usually +happens, but truly plane, and its Polish elaborate, as in working +Optick-glasses, and not such as is usually wrought with Putty, whereby +the edges of the Sand-holes being worn away, there are left all over the +Glass a numberless Company of very little convex polite Risings like +Waves. The edges also of the Prism and Lens, so far as they may make any +irregular Refraction, must be covered with a black Paper glewed on. And +all the Light of the Sun's Beam let into the Chamber, which is useless +and unprofitable to the Experiment, ought to be intercepted with black +Paper, or other black Obstacles. For otherwise the useless Light being +reflected every way in the Chamber, will mix with the oblong Spectrum, +and help to disturb it. In trying these Things, so much diligence is not +altogether necessary, but it will promote the Success of the +Experiments, and by a very scrupulous Examiner of Things deserves to be +apply'd. It's difficult to get Glass Prisms fit for this Purpose, and +therefore I used sometimes prismatick Vessels made with pieces of broken +Looking-glasses, and filled with Rain Water. And to increase the +Refraction, I sometimes impregnated the Water strongly with _Saccharum +Saturni_. + + +_PROP._ V. THEOR. IV. + +_Homogeneal Light is refracted regularly without any Dilatation +splitting or shattering of the Rays, and the confused Vision of Objects +seen through refracting Bodies by heterogeneal Light arises from the +different Refrangibility of several sorts of Rays._ + +The first Part of this Proposition has been already sufficiently proved +in the fifth Experiment, and will farther appear by the Experiments +which follow. + +_Exper._ 12. In the middle of a black Paper I made a round Hole about a +fifth or sixth Part of an Inch in diameter. Upon this Paper I caused the +Spectrum of homogeneal Light described in the former Proposition, so to +fall, that some part of the Light might pass through the Hole of the +Paper. This transmitted part of the Light I refracted with a Prism +placed behind the Paper, and letting this refracted Light fall +perpendicularly upon a white Paper two or three Feet distant from the +Prism, I found that the Spectrum formed on the Paper by this Light was +not oblong, as when 'tis made (in the third Experiment) by refracting +the Sun's compound Light, but was (so far as I could judge by my Eye) +perfectly circular, the Length being no greater than the Breadth. Which +shews, that this Light is refracted regularly without any Dilatation of +the Rays. + +_Exper._ 13. In the homogeneal Light I placed a Paper Circle of a +quarter of an Inch in diameter, and in the Sun's unrefracted +heterogeneal white Light I placed another Paper Circle of the same +Bigness. And going from the Papers to the distance of some Feet, I +viewed both Circles through a Prism. The Circle illuminated by the Sun's +heterogeneal Light appeared very oblong, as in the fourth Experiment, +the Length being many times greater than the Breadth; but the other +Circle, illuminated with homogeneal Light, appeared circular and +distinctly defined, as when 'tis view'd with the naked Eye. Which proves +the whole Proposition. + +_Exper._ 14. In the homogeneal Light I placed Flies, and such-like +minute Objects, and viewing them through a Prism, I saw their Parts as +distinctly defined, as if I had viewed them with the naked Eye. The same +Objects placed in the Sun's unrefracted heterogeneal Light, which was +white, I viewed also through a Prism, and saw them most confusedly +defined, so that I could not distinguish their smaller Parts from one +another. I placed also the Letters of a small print, one while in the +homogeneal Light, and then in the heterogeneal, and viewing them through +a Prism, they appeared in the latter Case so confused and indistinct, +that I could not read them; but in the former they appeared so distinct, +that I could read readily, and thought I saw them as distinct, as when I +view'd them with my naked Eye. In both Cases I view'd the same Objects, +through the same Prism at the same distance from me, and in the same +Situation. There was no difference, but in the Light by which the +Objects were illuminated, and which in one Case was simple, and in the +other compound; and therefore, the distinct Vision in the former Case, +and confused in the latter, could arise from nothing else than from that +difference of the Lights. Which proves the whole Proposition. + +And in these three Experiments it is farther very remarkable, that the +Colour of homogeneal Light was never changed by the Refraction. + + +_PROP._ VI. THEOR. V. + +_The Sine of Incidence of every Ray considered apart, is to its Sine of +Refraction in a given Ratio._ + +That every Ray consider'd apart, is constant to it self in some degree +of Refrangibility, is sufficiently manifest out of what has been said. +Those Rays, which in the first Refraction, are at equal Incidences most +refracted, are also in the following Refractions at equal Incidences +most refracted; and so of the least refrangible, and the rest which have +any mean Degree of Refrangibility, as is manifest by the fifth, sixth, +seventh, eighth, and ninth Experiments. And those which the first Time +at like Incidences are equally refracted, are again at like Incidences +equally and uniformly refracted, and that whether they be refracted +before they be separated from one another, as in the fifth Experiment, +or whether they be refracted apart, as in the twelfth, thirteenth and +fourteenth Experiments. The Refraction therefore of every Ray apart is +regular, and what Rule that Refraction observes we are now to shew.[E] + +The late Writers in Opticks teach, that the Sines of Incidence are in a +given Proportion to the Sines of Refraction, as was explained in the +fifth Axiom, and some by Instruments fitted for measuring of +Refractions, or otherwise experimentally examining this Proportion, do +acquaint us that they have found it accurate. But whilst they, not +understanding the different Refrangibility of several Rays, conceived +them all to be refracted according to one and the same Proportion, 'tis +to be presumed that they adapted their Measures only to the middle of +the refracted Light; so that from their Measures we may conclude only +that the Rays which have a mean Degree of Refrangibility, that is, those +which when separated from the rest appear green, are refracted according +to a given Proportion of their Sines. And therefore we are now to shew, +that the like given Proportions obtain in all the rest. That it should +be so is very reasonable, Nature being ever conformable to her self; but +an experimental Proof is desired. And such a Proof will be had, if we +can shew that the Sines of Refraction of Rays differently refrangible +are one to another in a given Proportion when their Sines of Incidence +are equal. For, if the Sines of Refraction of all the Rays are in given +Proportions to the Sine of Refractions of a Ray which has a mean Degree +of Refrangibility, and this Sine is in a given Proportion to the equal +Sines of Incidence, those other Sines of Refraction will also be in +given Proportions to the equal Sines of Incidence. Now, when the Sines +of Incidence are equal, it will appear by the following Experiment, that +the Sines of Refraction are in a given Proportion to one another. + +[Illustration: FIG. 26.] + +_Exper._ 15. The Sun shining into a dark Chamber through a little round +Hole in the Window-shut, let S [in _Fig._ 26.] represent his round white +Image painted on the opposite Wall by his direct Light, PT his oblong +coloured Image made by refracting that Light with a Prism placed at the +Window; and _pt_, or _2p 2t_, _3p 3t_, his oblong colour'd Image made by +refracting again the same Light sideways with a second Prism placed +immediately after the first in a cross Position to it, as was explained +in the fifth Experiment; that is to say, _pt_ when the Refraction of the +second Prism is small, _2p 2t_ when its Refraction is greater, and _3p +3t_ when it is greatest. For such will be the diversity of the +Refractions, if the refracting Angle of the second Prism be of various +Magnitudes; suppose of fifteen or twenty Degrees to make the Image _pt_, +of thirty or forty to make the Image _2p 2t_, and of sixty to make the +Image _3p 3t_. But for want of solid Glass Prisms with Angles of +convenient Bignesses, there may be Vessels made of polished Plates of +Glass cemented together in the form of Prisms and filled with Water. +These things being thus ordered, I observed that all the solar Images or +coloured Spectrums PT, _pt_, _2p 2t_, _3p 3t_ did very nearly converge +to the place S on which the direct Light of the Sun fell and painted his +white round Image when the Prisms were taken away. The Axis of the +Spectrum PT, that is the Line drawn through the middle of it parallel to +its rectilinear Sides, did when produced pass exactly through the middle +of that white round Image S. And when the Refraction of the second Prism +was equal to the Refraction of the first, the refracting Angles of them +both being about 60 Degrees, the Axis of the Spectrum _3p 3t_ made by +that Refraction, did when produced pass also through the middle of the +same white round Image S. But when the Refraction of the second Prism +was less than that of the first, the produced Axes of the Spectrums _tp_ +or _2t 2p_ made by that Refraction did cut the produced Axis of the +Spectrum TP in the points _m_ and _n_, a little beyond the Center of +that white round Image S. Whence the proportion of the Line 3_t_T to the +Line 3_p_P was a little greater than the Proportion of 2_t_T or 2_p_P, +and this Proportion a little greater than that of _t_T to _p_P. Now when +the Light of the Spectrum PT falls perpendicularly upon the Wall, those +Lines 3_t_T, 3_p_P, and 2_t_T, and 2_p_P, and _t_T, _p_P, are the +Tangents of the Refractions, and therefore by this Experiment the +Proportions of the Tangents of the Refractions are obtained, from whence +the Proportions of the Sines being derived, they come out equal, so far +as by viewing the Spectrums, and using some mathematical Reasoning I +could estimate. For I did not make an accurate Computation. So then the +Proposition holds true in every Ray apart, so far as appears by +Experiment. And that it is accurately true, may be demonstrated upon +this Supposition. _That Bodies refract Light by acting upon its Rays in +Lines perpendicular to their Surfaces._ But in order to this +Demonstration, I must distinguish the Motion of every Ray into two +Motions, the one perpendicular to the refracting Surface, the other +parallel to it, and concerning the perpendicular Motion lay down the +following Proposition. + +If any Motion or moving thing whatsoever be incident with any Velocity +on any broad and thin space terminated on both sides by two parallel +Planes, and in its Passage through that space be urged perpendicularly +towards the farther Plane by any force which at given distances from the +Plane is of given Quantities; the perpendicular velocity of that Motion +or Thing, at its emerging out of that space, shall be always equal to +the square Root of the sum of the square of the perpendicular velocity +of that Motion or Thing at its Incidence on that space; and of the +square of the perpendicular velocity which that Motion or Thing would +have at its Emergence, if at its Incidence its perpendicular velocity +was infinitely little. + +And the same Proposition holds true of any Motion or Thing +perpendicularly retarded in its passage through that space, if instead +of the sum of the two Squares you take their difference. The +Demonstration Mathematicians will easily find out, and therefore I shall +not trouble the Reader with it. + +Suppose now that a Ray coming most obliquely in the Line MC [in _Fig._ +1.] be refracted at C by the Plane RS into the Line CN, and if it be +required to find the Line CE, into which any other Ray AC shall be +refracted; let MC, AD, be the Sines of Incidence of the two Rays, and +NG, EF, their Sines of Refraction, and let the equal Motions of the +incident Rays be represented by the equal Lines MC and AC, and the +Motion MC being considered as parallel to the refracting Plane, let the +other Motion AC be distinguished into two Motions AD and DC, one of +which AD is parallel, and the other DC perpendicular to the refracting +Surface. In like manner, let the Motions of the emerging Rays be +distinguish'd into two, whereof the perpendicular ones are MC/NG × CG +and AD/EF × CF. And if the force of the refracting Plane begins to act +upon the Rays either in that Plane or at a certain distance from it on +the one side, and ends at a certain distance from it on the other side, +and in all places between those two limits acts upon the Rays in Lines +perpendicular to that refracting Plane, and the Actions upon the Rays at +equal distances from the refracting Plane be equal, and at unequal ones +either equal or unequal according to any rate whatever; that Motion of +the Ray which is parallel to the refracting Plane, will suffer no +Alteration by that Force; and that Motion which is perpendicular to it +will be altered according to the rule of the foregoing Proposition. If +therefore for the perpendicular velocity of the emerging Ray CN you +write MC/NG × CG as above, then the perpendicular velocity of any other +emerging Ray CE which was AD/EF × CF, will be equal to the square Root +of CD_q_ + (_MCq/NGq_ × CG_q_). And by squaring these Equals, and adding +to them the Equals AD_q_ and MC_q_ - CD_q_, and dividing the Sums by the +Equals CF_q_ + EF_q_ and CG_q_ + NG_q_, you will have _MCq/NGq_ equal to +_ADq/EFq_. Whence AD, the Sine of Incidence, is to EF the Sine of +Refraction, as MC to NG, that is, in a given _ratio_. And this +Demonstration being general, without determining what Light is, or by +what kind of Force it is refracted, or assuming any thing farther than +that the refracting Body acts upon the Rays in Lines perpendicular to +its Surface; I take it to be a very convincing Argument of the full +truth of this Proposition. + +So then, if the _ratio_ of the Sines of Incidence and Refraction of any +sort of Rays be found in any one case, 'tis given in all cases; and this +may be readily found by the Method in the following Proposition. + + +_PROP._ VII. THEOR. VI. + +_The Perfection of Telescopes is impeded by the different Refrangibility +of the Rays of Light._ + +The Imperfection of Telescopes is vulgarly attributed to the spherical +Figures of the Glasses, and therefore Mathematicians have propounded to +figure them by the conical Sections. To shew that they are mistaken, I +have inserted this Proposition; the truth of which will appear by the +measure of the Refractions of the several sorts of Rays; and these +measures I thus determine. + +In the third Experiment of this first Part, where the refracting Angle +of the Prism was 62-1/2 Degrees, the half of that Angle 31 deg. 15 min. +is the Angle of Incidence of the Rays at their going out of the Glass +into the Air[F]; and the Sine of this Angle is 5188, the Radius being +10000. When the Axis of this Prism was parallel to the Horizon, and the +Refraction of the Rays at their Incidence on this Prism equal to that at +their Emergence out of it, I observed with a Quadrant the Angle which +the mean refrangible Rays, (that is those which went to the middle of +the Sun's coloured Image) made with the Horizon, and by this Angle and +the Sun's altitude observed at the same time, I found the Angle which +the emergent Rays contained with the incident to be 44 deg. and 40 min. +and the half of this Angle added to the Angle of Incidence 31 deg. 15 +min. makes the Angle of Refraction, which is therefore 53 deg. 35 min. +and its Sine 8047. These are the Sines of Incidence and Refraction of +the mean refrangible Rays, and their Proportion in round Numbers is 20 +to 31. This Glass was of a Colour inclining to green. The last of the +Prisms mentioned in the third Experiment was of clear white Glass. Its +refracting Angle 63-1/2 Degrees. The Angle which the emergent Rays +contained, with the incident 45 deg. 50 min. The Sine of half the first +Angle 5262. The Sine of half the Sum of the Angles 8157. And their +Proportion in round Numbers 20 to 31, as before. + +From the Length of the Image, which was about 9-3/4 or 10 Inches, +subduct its Breadth, which was 2-1/8 Inches, and the Remainder 7-3/4 +Inches would be the Length of the Image were the Sun but a Point, and +therefore subtends the Angle which the most and least refrangible Rays, +when incident on the Prism in the same Lines, do contain with one +another after their Emergence. Whence this Angle is 2 deg. 0´. 7´´. For +the distance between the Image and the Prism where this Angle is made, +was 18-1/2 Feet, and at that distance the Chord 7-3/4 Inches subtends an +Angle of 2 deg. 0´. 7´´. Now half this Angle is the Angle which these +emergent Rays contain with the emergent mean refrangible Rays, and a +quarter thereof, that is 30´. 2´´. may be accounted the Angle which they +would contain with the same emergent mean refrangible Rays, were they +co-incident to them within the Glass, and suffered no other Refraction +than that at their Emergence. For, if two equal Refractions, the one at +the Incidence of the Rays on the Prism, the other at their Emergence, +make half the Angle 2 deg. 0´. 7´´. then one of those Refractions will +make about a quarter of that Angle, and this quarter added to, and +subducted from the Angle of Refraction of the mean refrangible Rays, +which was 53 deg. 35´, gives the Angles of Refraction of the most and +least refrangible Rays 54 deg. 5´ 2´´, and 53 deg. 4´ 58´´, whose Sines +are 8099 and 7995, the common Angle of Incidence being 31 deg. 15´, and +its Sine 5188; and these Sines in the least round Numbers are in +proportion to one another, as 78 and 77 to 50. + +Now, if you subduct the common Sine of Incidence 50 from the Sines of +Refraction 77 and 78, the Remainders 27 and 28 shew, that in small +Refractions the Refraction of the least refrangible Rays is to the +Refraction of the most refrangible ones, as 27 to 28 very nearly, and +that the difference of the Refractions of the least refrangible and most +refrangible Rays is about the 27-1/2th Part of the whole Refraction of +the mean refrangible Rays. + +Whence they that are skilled in Opticks will easily understand,[G] that +the Breadth of the least circular Space, into which Object-glasses of +Telescopes can collect all sorts of Parallel Rays, is about the 27-1/2th +Part of half the Aperture of the Glass, or 55th Part of the whole +Aperture; and that the Focus of the most refrangible Rays is nearer to +the Object-glass than the Focus of the least refrangible ones, by about +the 27-1/2th Part of the distance between the Object-glass and the Focus +of the mean refrangible ones. + +And if Rays of all sorts, flowing from any one lucid Point in the Axis +of any convex Lens, be made by the Refraction of the Lens to converge to +Points not too remote from the Lens, the Focus of the most refrangible +Rays shall be nearer to the Lens than the Focus of the least refrangible +ones, by a distance which is to the 27-1/2th Part of the distance of the +Focus of the mean refrangible Rays from the Lens, as the distance +between that Focus and the lucid Point, from whence the Rays flow, is to +the distance between that lucid Point and the Lens very nearly. + +Now to examine whether the Difference between the Refractions, which the +most refrangible and the least refrangible Rays flowing from the same +Point suffer in the Object-glasses of Telescopes and such-like Glasses, +be so great as is here described, I contrived the following Experiment. + +_Exper._ 16. The Lens which I used in the second and eighth Experiments, +being placed six Feet and an Inch distant from any Object, collected the +Species of that Object by the mean refrangible Rays at the distance of +six Feet and an Inch from the Lens on the other side. And therefore by +the foregoing Rule, it ought to collect the Species of that Object by +the least refrangible Rays at the distance of six Feet and 3-2/3 Inches +from the Lens, and by the most refrangible ones at the distance of five +Feet and 10-1/3 Inches from it: So that between the two Places, where +these least and most refrangible Rays collect the Species, there may be +the distance of about 5-1/3 Inches. For by that Rule, as six Feet and an +Inch (the distance of the Lens from the lucid Object) is to twelve Feet +and two Inches (the distance of the lucid Object from the Focus of the +mean refrangible Rays) that is, as One is to Two; so is the 27-1/2th +Part of six Feet and an Inch (the distance between the Lens and the same +Focus) to the distance between the Focus of the most refrangible Rays +and the Focus of the least refrangible ones, which is therefore 5-17/55 +Inches, that is very nearly 5-1/3 Inches. Now to know whether this +Measure was true, I repeated the second and eighth Experiment with +coloured Light, which was less compounded than that I there made use of: +For I now separated the heterogeneous Rays from one another by the +Method I described in the eleventh Experiment, so as to make a coloured +Spectrum about twelve or fifteen Times longer than broad. This Spectrum +I cast on a printed Book, and placing the above-mentioned Lens at the +distance of six Feet and an Inch from this Spectrum to collect the +Species of the illuminated Letters at the same distance on the other +side, I found that the Species of the Letters illuminated with blue were +nearer to the Lens than those illuminated with deep red by about three +Inches, or three and a quarter; but the Species of the Letters +illuminated with indigo and violet appeared so confused and indistinct, +that I could not read them: Whereupon viewing the Prism, I found it was +full of Veins running from one end of the Glass to the other; so that +the Refraction could not be regular. I took another Prism therefore +which was free from Veins, and instead of the Letters I used two or +three Parallel black Lines a little broader than the Strokes of the +Letters, and casting the Colours upon these Lines in such manner, that +the Lines ran along the Colours from one end of the Spectrum to the +other, I found that the Focus where the indigo, or confine of this +Colour and violet cast the Species of the black Lines most distinctly, +to be about four Inches, or 4-1/4 nearer to the Lens than the Focus, +where the deepest red cast the Species of the same black Lines most +distinctly. The violet was so faint and dark, that I could not discern +the Species of the Lines distinctly by that Colour; and therefore +considering that the Prism was made of a dark coloured Glass inclining +to green, I took another Prism of clear white Glass; but the Spectrum of +Colours which this Prism made had long white Streams of faint Light +shooting out from both ends of the Colours, which made me conclude that +something was amiss; and viewing the Prism, I found two or three little +Bubbles in the Glass, which refracted the Light irregularly. Wherefore I +covered that Part of the Glass with black Paper, and letting the Light +pass through another Part of it which was free from such Bubbles, the +Spectrum of Colours became free from those irregular Streams of Light, +and was now such as I desired. But still I found the violet so dark and +faint, that I could scarce see the Species of the Lines by the violet, +and not at all by the deepest Part of it, which was next the end of the +Spectrum. I suspected therefore, that this faint and dark Colour might +be allayed by that scattering Light which was refracted, and reflected +irregularly, partly by some very small Bubbles in the Glasses, and +partly by the Inequalities of their Polish; which Light, tho' it was but +little, yet it being of a white Colour, might suffice to affect the +Sense so strongly as to disturb the Phænomena of that weak and dark +Colour the violet, and therefore I tried, as in the 12th, 13th, and 14th +Experiments, whether the Light of this Colour did not consist of a +sensible Mixture of heterogeneous Rays, but found it did not. Nor did +the Refractions cause any other sensible Colour than violet to emerge +out of this Light, as they would have done out of white Light, and by +consequence out of this violet Light had it been sensibly compounded +with white Light. And therefore I concluded, that the reason why I could +not see the Species of the Lines distinctly by this Colour, was only +the Darkness of this Colour, and Thinness of its Light, and its distance +from the Axis of the Lens; I divided therefore those Parallel black +Lines into equal Parts, by which I might readily know the distances of +the Colours in the Spectrum from one another, and noted the distances of +the Lens from the Foci of such Colours, as cast the Species of the Lines +distinctly, and then considered whether the difference of those +distances bear such proportion to 5-1/3 Inches, the greatest Difference +of the distances, which the Foci of the deepest red and violet ought to +have from the Lens, as the distance of the observed Colours from one +another in the Spectrum bear to the greatest distance of the deepest red +and violet measured in the Rectilinear Sides of the Spectrum, that is, +to the Length of those Sides, or Excess of the Length of the Spectrum +above its Breadth. And my Observations were as follows. + +When I observed and compared the deepest sensible red, and the Colour in +the Confine of green and blue, which at the Rectilinear Sides of the +Spectrum was distant from it half the Length of those Sides, the Focus +where the Confine of green and blue cast the Species of the Lines +distinctly on the Paper, was nearer to the Lens than the Focus, where +the red cast those Lines distinctly on it by about 2-1/2 or 2-3/4 +Inches. For sometimes the Measures were a little greater, sometimes a +little less, but seldom varied from one another above 1/3 of an Inch. +For it was very difficult to define the Places of the Foci, without some +little Errors. Now, if the Colours distant half the Length of the +Image, (measured at its Rectilinear Sides) give 2-1/2 or 2-3/4 +Difference of the distances of their Foci from the Lens, then the +Colours distant the whole Length ought to give 5 or 5-1/2 Inches +difference of those distances. + +But here it's to be noted, that I could not see the red to the full end +of the Spectrum, but only to the Center of the Semicircle which bounded +that end, or a little farther; and therefore I compared this red not +with that Colour which was exactly in the middle of the Spectrum, or +Confine of green and blue, but with that which verged a little more to +the blue than to the green: And as I reckoned the whole Length of the +Colours not to be the whole Length of the Spectrum, but the Length of +its Rectilinear Sides, so compleating the semicircular Ends into +Circles, when either of the observed Colours fell within those Circles, +I measured the distance of that Colour from the semicircular End of the +Spectrum, and subducting half this distance from the measured distance +of the two Colours, I took the Remainder for their corrected distance; +and in these Observations set down this corrected distance for the +difference of the distances of their Foci from the Lens. For, as the +Length of the Rectilinear Sides of the Spectrum would be the whole +Length of all the Colours, were the Circles of which (as we shewed) that +Spectrum consists contracted and reduced to Physical Points, so in that +Case this corrected distance would be the real distance of the two +observed Colours. + +When therefore I farther observed the deepest sensible red, and that +blue whose corrected distance from it was 7/12 Parts of the Length of +the Rectilinear Sides of the Spectrum, the difference of the distances +of their Foci from the Lens was about 3-1/4 Inches, and as 7 to 12, so +is 3-1/4 to 5-4/7. + +When I observed the deepest sensible red, and that indigo whose +corrected distance was 8/12 or 2/3 of the Length of the Rectilinear +Sides of the Spectrum, the difference of the distances of their Foci +from the Lens, was about 3-2/3 Inches, and as 2 to 3, so is 3-2/3 to +5-1/2. + +When I observed the deepest sensible red, and that deep indigo whose +corrected distance from one another was 9/12 or 3/4 of the Length of the +Rectilinear Sides of the Spectrum, the difference of the distances of +their Foci from the Lens was about 4 Inches; and as 3 to 4, so is 4 to +5-1/3. + +When I observed the deepest sensible red, and that Part of the violet +next the indigo, whose corrected distance from the red was 10/12 or 5/6 +of the Length of the Rectilinear Sides of the Spectrum, the difference +of the distances of their Foci from the Lens was about 4-1/2 Inches, and +as 5 to 6, so is 4-1/2 to 5-2/5. For sometimes, when the Lens was +advantageously placed, so that its Axis respected the blue, and all +Things else were well ordered, and the Sun shone clear, and I held my +Eye very near to the Paper on which the Lens cast the Species of the +Lines, I could see pretty distinctly the Species of those Lines by that +Part of the violet which was next the indigo; and sometimes I could see +them by above half the violet, For in making these Experiments I had +observed, that the Species of those Colours only appear distinct, which +were in or near the Axis of the Lens: So that if the blue or indigo were +in the Axis, I could see their Species distinctly; and then the red +appeared much less distinct than before. Wherefore I contrived to make +the Spectrum of Colours shorter than before, so that both its Ends might +be nearer to the Axis of the Lens. And now its Length was about 2-1/2 +Inches, and Breadth about 1/5 or 1/6 of an Inch. Also instead of the +black Lines on which the Spectrum was cast, I made one black Line +broader than those, that I might see its Species more easily; and this +Line I divided by short cross Lines into equal Parts, for measuring the +distances of the observed Colours. And now I could sometimes see the +Species of this Line with its Divisions almost as far as the Center of +the semicircular violet End of the Spectrum, and made these farther +Observations. + +When I observed the deepest sensible red, and that Part of the violet, +whose corrected distance from it was about 8/9 Parts of the Rectilinear +Sides of the Spectrum, the Difference of the distances of the Foci of +those Colours from the Lens, was one time 4-2/3, another time 4-3/4, +another time 4-7/8 Inches; and as 8 to 9, so are 4-2/3, 4-3/4, 4-7/8, to +5-1/4, 5-11/32, 5-31/64 respectively. + +When I observed the deepest sensible red, and deepest sensible violet, +(the corrected distance of which Colours, when all Things were ordered +to the best Advantage, and the Sun shone very clear, was about 11/12 or +15/16 Parts of the Length of the Rectilinear Sides of the coloured +Spectrum) I found the Difference of the distances of their Foci from the +Lens sometimes 4-3/4 sometimes 5-1/4, and for the most part 5 Inches or +thereabouts; and as 11 to 12, or 15 to 16, so is five Inches to 5-2/2 or +5-1/3 Inches. + +And by this Progression of Experiments I satisfied my self, that had the +Light at the very Ends of the Spectrum been strong enough to make the +Species of the black Lines appear plainly on the Paper, the Focus of the +deepest violet would have been found nearer to the Lens, than the Focus +of the deepest red, by about 5-1/3 Inches at least. And this is a +farther Evidence, that the Sines of Incidence and Refraction of the +several sorts of Rays, hold the same Proportion to one another in the +smallest Refractions which they do in the greatest. + +My Progress in making this nice and troublesome Experiment I have set +down more at large, that they that shall try it after me may be aware of +the Circumspection requisite to make it succeed well. And if they cannot +make it succeed so well as I did, they may notwithstanding collect by +the Proportion of the distance of the Colours of the Spectrum, to the +Difference of the distances of their Foci from the Lens, what would be +the Success in the more distant Colours by a better trial. And yet, if +they use a broader Lens than I did, and fix it to a long strait Staff, +by means of which it may be readily and truly directed to the Colour +whose Focus is desired, I question not but the Experiment will succeed +better with them than it did with me. For I directed the Axis as nearly +as I could to the middle of the Colours, and then the faint Ends of the +Spectrum being remote from the Axis, cast their Species less distinctly +on the Paper than they would have done, had the Axis been successively +directed to them. + +Now by what has been said, it's certain that the Rays which differ in +Refrangibility do not converge to the same Focus; but if they flow from +a lucid Point, as far from the Lens on one side as their Foci are on the +other, the Focus of the most refrangible Rays shall be nearer to the +Lens than that of the least refrangible, by above the fourteenth Part of +the whole distance; and if they flow from a lucid Point, so very remote +from the Lens, that before their Incidence they may be accounted +parallel, the Focus of the most refrangible Rays shall be nearer to the +Lens than the Focus of the least refrangible, by about the 27th or 28th +Part of their whole distance from it. And the Diameter of the Circle in +the middle Space between those two Foci which they illuminate, when they +fall there on any Plane, perpendicular to the Axis (which Circle is the +least into which they can all be gathered) is about the 55th Part of the +Diameter of the Aperture of the Glass. So that 'tis a wonder, that +Telescopes represent Objects so distinct as they do. But were all the +Rays of Light equally refrangible, the Error arising only from the +Sphericalness of the Figures of Glasses would be many hundred times +less. For, if the Object-glass of a Telescope be Plano-convex, and the +Plane side be turned towards the Object, and the Diameter of the +Sphere, whereof this Glass is a Segment, be called D, and the +Semi-diameter of the Aperture of the Glass be called S, and the Sine of +Incidence out of Glass into Air, be to the Sine of Refraction as I to R; +the Rays which come parallel to the Axis of the Glass, shall in the +Place where the Image of the Object is most distinctly made, be +scattered all over a little Circle, whose Diameter is _(Rq/Iq) × (S +cub./D quad.)_ very nearly,[H] as I gather by computing the Errors of +the Rays by the Method of infinite Series, and rejecting the Terms, +whose Quantities are inconsiderable. As for instance, if the Sine of +Incidence I, be to the Sine of Refraction R, as 20 to 31, and if D the +Diameter of the Sphere, to which the Convex-side of the Glass is ground, +be 100 Feet or 1200 Inches, and S the Semi-diameter of the Aperture be +two Inches, the Diameter of the little Circle, (that is (_Rq × S +cub.)/(Iq × D quad._)) will be (31 × 31 × 8)/(20 × 20 × 1200 × 1200) (or +961/72000000) Parts of an Inch. But the Diameter of the little Circle, +through which these Rays are scattered by unequal Refrangibility, will +be about the 55th Part of the Aperture of the Object-glass, which here +is four Inches. And therefore, the Error arising from the Spherical +Figure of the Glass, is to the Error arising from the different +Refrangibility of the Rays, as 961/72000000 to 4/55, that is as 1 to +5449; and therefore being in comparison so very little, deserves not to +be considered. + +[Illustration: FIG. 27.] + +But you will say, if the Errors caused by the different Refrangibility +be so very great, how comes it to pass, that Objects appear through +Telescopes so distinct as they do? I answer, 'tis because the erring +Rays are not scattered uniformly over all that Circular Space, but +collected infinitely more densely in the Center than in any other Part +of the Circle, and in the Way from the Center to the Circumference, grow +continually rarer and rarer, so as at the Circumference to become +infinitely rare; and by reason of their Rarity are not strong enough to +be visible, unless in the Center and very near it. Let ADE [in _Fig._ +27.] represent one of those Circles described with the Center C, and +Semi-diameter AC, and let BFG be a smaller Circle concentrick to the +former, cutting with its Circumference the Diameter AC in B, and bisect +AC in N; and by my reckoning, the Density of the Light in any Place B, +will be to its Density in N, as AB to BC; and the whole Light within the +lesser Circle BFG, will be to the whole Light within the greater AED, as +the Excess of the Square of AC above the Square of AB, is to the Square +of AC. As if BC be the fifth Part of AC, the Light will be four times +denser in B than in N, and the whole Light within the less Circle, will +be to the whole Light within the greater, as nine to twenty-five. Whence +it's evident, that the Light within the less Circle, must strike the +Sense much more strongly, than that faint and dilated Light round about +between it and the Circumference of the greater. + +But it's farther to be noted, that the most luminous of the Prismatick +Colours are the yellow and orange. These affect the Senses more strongly +than all the rest together, and next to these in strength are the red +and green. The blue compared with these is a faint and dark Colour, and +the indigo and violet are much darker and fainter, so that these +compared with the stronger Colours are little to be regarded. The Images +of Objects are therefore to be placed, not in the Focus of the mean +refrangible Rays, which are in the Confine of green and blue, but in the +Focus of those Rays which are in the middle of the orange and yellow; +there where the Colour is most luminous and fulgent, that is in the +brightest yellow, that yellow which inclines more to orange than to +green. And by the Refraction of these Rays (whose Sines of Incidence and +Refraction in Glass are as 17 and 11) the Refraction of Glass and +Crystal for Optical Uses is to be measured. Let us therefore place the +Image of the Object in the Focus of these Rays, and all the yellow and +orange will fall within a Circle, whose Diameter is about the 250th +Part of the Diameter of the Aperture of the Glass. And if you add the +brighter half of the red, (that half which is next the orange) and the +brighter half of the green, (that half which is next the yellow) about +three fifth Parts of the Light of these two Colours will fall within the +same Circle, and two fifth Parts will fall without it round about; and +that which falls without will be spread through almost as much more +space as that which falls within, and so in the gross be almost three +times rarer. Of the other half of the red and green, (that is of the +deep dark red and willow green) about one quarter will fall within this +Circle, and three quarters without, and that which falls without will be +spread through about four or five times more space than that which falls +within; and so in the gross be rarer, and if compared with the whole +Light within it, will be about 25 times rarer than all that taken in the +gross; or rather more than 30 or 40 times rarer, because the deep red in +the end of the Spectrum of Colours made by a Prism is very thin and +rare, and the willow green is something rarer than the orange and +yellow. The Light of these Colours therefore being so very much rarer +than that within the Circle, will scarce affect the Sense, especially +since the deep red and willow green of this Light, are much darker +Colours than the rest. And for the same reason the blue and violet being +much darker Colours than these, and much more rarified, may be +neglected. For the dense and bright Light of the Circle, will obscure +the rare and weak Light of these dark Colours round about it, and +render them almost insensible. The sensible Image of a lucid Point is +therefore scarce broader than a Circle, whose Diameter is the 250th Part +of the Diameter of the Aperture of the Object-glass of a good Telescope, +or not much broader, if you except a faint and dark misty Light round +about it, which a Spectator will scarce regard. And therefore in a +Telescope, whose Aperture is four Inches, and Length an hundred Feet, it +exceeds not 2´´ 45´´´, or 3´´. And in a Telescope whose Aperture is two +Inches, and Length 20 or 30 Feet, it may be 5´´ or 6´´, and scarce +above. And this answers well to Experience: For some Astronomers have +found the Diameters of the fix'd Stars, in Telescopes of between 20 and +60 Feet in length, to be about 5´´ or 6´´, or at most 8´´ or 10´´ in +diameter. But if the Eye-Glass be tincted faintly with the Smoak of a +Lamp or Torch, to obscure the Light of the Star, the fainter Light in +the Circumference of the Star ceases to be visible, and the Star (if the +Glass be sufficiently soiled with Smoak) appears something more like a +mathematical Point. And for the same Reason, the enormous Part of the +Light in the Circumference of every lucid Point ought to be less +discernible in shorter Telescopes than in longer, because the shorter +transmit less Light to the Eye. + +Now, that the fix'd Stars, by reason of their immense Distance, appear +like Points, unless so far as their Light is dilated by Refraction, may +appear from hence; that when the Moon passes over them and eclipses +them, their Light vanishes, not gradually like that of the Planets, but +all at once; and in the end of the Eclipse it returns into Sight all at +once, or certainly in less time than the second of a Minute; the +Refraction of the Moon's Atmosphere a little protracting the time in +which the Light of the Star first vanishes, and afterwards returns into +Sight. + +Now, if we suppose the sensible Image of a lucid Point, to be even 250 +times narrower than the Aperture of the Glass; yet this Image would be +still much greater than if it were only from the spherical Figure of the +Glass. For were it not for the different Refrangibility of the Rays, its +breadth in an 100 Foot Telescope whose aperture is 4 Inches, would be +but 961/72000000 parts of an Inch, as is manifest by the foregoing +Computation. And therefore in this case the greatest Errors arising from +the spherical Figure of the Glass, would be to the greatest sensible +Errors arising from the different Refrangibility of the Rays as +961/72000000 to 4/250 at most, that is only as 1 to 1200. And this +sufficiently shews that it is not the spherical Figures of Glasses, but +the different Refrangibility of the Rays which hinders the perfection of +Telescopes. + +There is another Argument by which it may appear that the different +Refrangibility of Rays, is the true cause of the imperfection of +Telescopes. For the Errors of the Rays arising from the spherical +Figures of Object-glasses, are as the Cubes of the Apertures of the +Object Glasses; and thence to make Telescopes of various Lengths magnify +with equal distinctness, the Apertures of the Object-glasses, and the +Charges or magnifying Powers ought to be as the Cubes of the square +Roots of their lengths; which doth not answer to Experience. But the +Errors of the Rays arising from the different Refrangibility, are as the +Apertures of the Object-glasses; and thence to make Telescopes of +various lengths, magnify with equal distinctness, their Apertures and +Charges ought to be as the square Roots of their lengths; and this +answers to Experience, as is well known. For Instance, a Telescope of 64 +Feet in length, with an Aperture of 2-2/3 Inches, magnifies about 120 +times, with as much distinctness as one of a Foot in length, with 1/3 of +an Inch aperture, magnifies 15 times. + +[Illustration: FIG. 28.] + +Now were it not for this different Refrangibility of Rays, Telescopes +might be brought to a greater perfection than we have yet describ'd, by +composing the Object-glass of two Glasses with Water between them. Let +ADFC [in _Fig._ 28.] represent the Object-glass composed of two Glasses +ABED and BEFC, alike convex on the outsides AGD and CHF, and alike +concave on the insides BME, BNE, with Water in the concavity BMEN. Let +the Sine of Incidence out of Glass into Air be as I to R, and out of +Water into Air, as K to R, and by consequence out of Glass into Water, +as I to K: and let the Diameter of the Sphere to which the convex sides +AGD and CHF are ground be D, and the Diameter of the Sphere to which the +concave sides BME and BNE, are ground be to D, as the Cube Root of +KK--KI to the Cube Root of RK--RI: and the Refractions on the concave +sides of the Glasses, will very much correct the Errors of the +Refractions on the convex sides, so far as they arise from the +sphericalness of the Figure. And by this means might Telescopes be +brought to sufficient perfection, were it not for the different +Refrangibility of several sorts of Rays. But by reason of this different +Refrangibility, I do not yet see any other means of improving Telescopes +by Refractions alone, than that of increasing their lengths, for which +end the late Contrivance of _Hugenius_ seems well accommodated. For very +long Tubes are cumbersome, and scarce to be readily managed, and by +reason of their length are very apt to bend, and shake by bending, so as +to cause a continual trembling in the Objects, whereby it becomes +difficult to see them distinctly: whereas by his Contrivance the Glasses +are readily manageable, and the Object-glass being fix'd upon a strong +upright Pole becomes more steady. + +Seeing therefore the Improvement of Telescopes of given lengths by +Refractions is desperate; I contrived heretofore a Perspective by +Reflexion, using instead of an Object-glass a concave Metal. The +diameter of the Sphere to which the Metal was ground concave was about +25 _English_ Inches, and by consequence the length of the Instrument +about six Inches and a quarter. The Eye-glass was Plano-convex, and the +diameter of the Sphere to which the convex side was ground was about 1/5 +of an Inch, or a little less, and by consequence it magnified between 30 +and 40 times. By another way of measuring I found that it magnified +about 35 times. The concave Metal bore an Aperture of an Inch and a +third part; but the Aperture was limited not by an opake Circle, +covering the Limb of the Metal round about, but by an opake Circle +placed between the Eyeglass and the Eye, and perforated in the middle +with a little round hole for the Rays to pass through to the Eye. For +this Circle by being placed here, stopp'd much of the erroneous Light, +which otherwise would have disturbed the Vision. By comparing it with a +pretty good Perspective of four Feet in length, made with a concave +Eye-glass, I could read at a greater distance with my own Instrument +than with the Glass. Yet Objects appeared much darker in it than in the +Glass, and that partly because more Light was lost by Reflexion in the +Metal, than by Refraction in the Glass, and partly because my Instrument +was overcharged. Had it magnified but 30 or 25 times, it would have made +the Object appear more brisk and pleasant. Two of these I made about 16 +Years ago, and have one of them still by me, by which I can prove the +truth of what I write. Yet it is not so good as at the first. For the +concave has been divers times tarnished and cleared again, by rubbing +it with very soft Leather. When I made these an Artist in _London_ +undertook to imitate it; but using another way of polishing them than I +did, he fell much short of what I had attained to, as I afterwards +understood by discoursing the Under-workman he had employed. The Polish +I used was in this manner. I had two round Copper Plates, each six +Inches in Diameter, the one convex, the other concave, ground very true +to one another. On the convex I ground the Object-Metal or Concave which +was to be polish'd, 'till it had taken the Figure of the Convex and was +ready for a Polish. Then I pitched over the convex very thinly, by +dropping melted Pitch upon it, and warming it to keep the Pitch soft, +whilst I ground it with the concave Copper wetted to make it spread +eavenly all over the convex. Thus by working it well I made it as thin +as a Groat, and after the convex was cold I ground it again to give it +as true a Figure as I could. Then I took Putty which I had made very +fine by washing it from all its grosser Particles, and laying a little +of this upon the Pitch, I ground it upon the Pitch with the concave +Copper, till it had done making a Noise; and then upon the Pitch I +ground the Object-Metal with a brisk motion, for about two or three +Minutes of time, leaning hard upon it. Then I put fresh Putty upon the +Pitch, and ground it again till it had done making a noise, and +afterwards ground the Object-Metal upon it as before. And this Work I +repeated till the Metal was polished, grinding it the last time with all +my strength for a good while together, and frequently breathing upon +the Pitch, to keep it moist without laying on any more fresh Putty. The +Object-Metal was two Inches broad, and about one third part of an Inch +thick, to keep it from bending. I had two of these Metals, and when I +had polished them both, I tried which was best, and ground the other +again, to see if I could make it better than that which I kept. And thus +by many Trials I learn'd the way of polishing, till I made those two +reflecting Perspectives I spake of above. For this Art of polishing will +be better learn'd by repeated Practice than by my Description. Before I +ground the Object-Metal on the Pitch, I always ground the Putty on it +with the concave Copper, till it had done making a noise, because if the +Particles of the Putty were not by this means made to stick fast in the +Pitch, they would by rolling up and down grate and fret the Object-Metal +and fill it full of little holes. + +But because Metal is more difficult to polish than Glass, and is +afterwards very apt to be spoiled by tarnishing, and reflects not so +much Light as Glass quick-silver'd over does: I would propound to use +instead of the Metal, a Glass ground concave on the foreside, and as +much convex on the backside, and quick-silver'd over on the convex side. +The Glass must be every where of the same thickness exactly. Otherwise +it will make Objects look colour'd and indistinct. By such a Glass I +tried about five or six Years ago to make a reflecting Telescope of four +Feet in length to magnify about 150 times, and I satisfied my self that +there wants nothing but a good Artist to bring the Design to +perfection. For the Glass being wrought by one of our _London_ Artists +after such a manner as they grind Glasses for Telescopes, though it +seemed as well wrought as the Object-glasses use to be, yet when it was +quick-silver'd, the Reflexion discovered innumerable Inequalities all +over the Glass. And by reason of these Inequalities, Objects appeared +indistinct in this Instrument. For the Errors of reflected Rays caused +by any Inequality of the Glass, are about six times greater than the +Errors of refracted Rays caused by the like Inequalities. Yet by this +Experiment I satisfied my self that the Reflexion on the concave side of +the Glass, which I feared would disturb the Vision, did no sensible +prejudice to it, and by consequence that nothing is wanting to perfect +these Telescopes, but good Workmen who can grind and polish Glasses +truly spherical. An Object-glass of a fourteen Foot Telescope, made by +an Artificer at _London_, I once mended considerably, by grinding it on +Pitch with Putty, and leaning very easily on it in the grinding, lest +the Putty should scratch it. Whether this way may not do well enough for +polishing these reflecting Glasses, I have not yet tried. But he that +shall try either this or any other way of polishing which he may think +better, may do well to make his Glasses ready for polishing, by grinding +them without that Violence, wherewith our _London_ Workmen press their +Glasses in grinding. For by such violent pressure, Glasses are apt to +bend a little in the grinding, and such bending will certainly spoil +their Figure. To recommend therefore the consideration of these +reflecting Glasses to such Artists as are curious in figuring Glasses, I +shall describe this optical Instrument in the following Proposition. + + +_PROP._ VIII. PROB. II. + +_To shorten Telescopes._ + +Let ABCD [in _Fig._ 29.] represent a Glass spherically concave on the +foreside AB, and as much convex on the backside CD, so that it be every +where of an equal thickness. Let it not be thicker on one side than on +the other, lest it make Objects appear colour'd and indistinct, and let +it be very truly wrought and quick-silver'd over on the backside; and +set in the Tube VXYZ which must be very black within. Let EFG represent +a Prism of Glass or Crystal placed near the other end of the Tube, in +the middle of it, by means of a handle of Brass or Iron FGK, to the end +of which made flat it is cemented. Let this Prism be rectangular at E, +and let the other two Angles at F and G be accurately equal to each +other, and by consequence equal to half right ones, and let the plane +sides FE and GE be square, and by consequence the third side FG a +rectangular Parallelogram, whose length is to its breadth in a +subduplicate proportion of two to one. Let it be so placed in the Tube, +that the Axis of the Speculum may pass through the middle of the square +side EF perpendicularly and by consequence through the middle of the +side FG at an Angle of 45 Degrees, and let the side EF be turned towards +the Speculum, and the distance of this Prism from the Speculum be such +that the Rays of the Light PQ, RS, &c. which are incident upon the +Speculum in Lines parallel to the Axis thereof, may enter the Prism at +the side EF, and be reflected by the side FG, and thence go out of it +through the side GE, to the Point T, which must be the common Focus of +the Speculum ABDC, and of a Plano-convex Eye-glass H, through which +those Rays must pass to the Eye. And let the Rays at their coming out of +the Glass pass through a small round hole, or aperture made in a little +plate of Lead, Brass, or Silver, wherewith the Glass is to be covered, +which hole must be no bigger than is necessary for Light enough to pass +through. For so it will render the Object distinct, the Plate in which +'tis made intercepting all the erroneous part of the Light which comes +from the verges of the Speculum AB. Such an Instrument well made, if it +be six Foot long, (reckoning the length from the Speculum to the Prism, +and thence to the Focus T) will bear an aperture of six Inches at the +Speculum, and magnify between two and three hundred times. But the hole +H here limits the aperture with more advantage, than if the aperture was +placed at the Speculum. If the Instrument be made longer or shorter, the +aperture must be in proportion as the Cube of the square-square Root of +the length, and the magnifying as the aperture. But it's convenient that +the Speculum be an Inch or two broader than the aperture at the least, +and that the Glass of the Speculum be thick, that it bend not in the +working. The Prism EFG must be no bigger than is necessary, and its back +side FG must not be quick-silver'd over. For without quicksilver it will +reflect all the Light incident on it from the Speculum. + +[Illustration: FIG. 29.] + +In this Instrument the Object will be inverted, but may be erected by +making the square sides FF and EG of the Prism EFG not plane but +spherically convex, that the Rays may cross as well before they come at +it as afterwards between it and the Eye-glass. If it be desired that the +Instrument bear a larger aperture, that may be also done by composing +the Speculum of two Glasses with Water between them. + +If the Theory of making Telescopes could at length be fully brought into +Practice, yet there would be certain Bounds beyond which Telescopes +could not perform. For the Air through which we look upon the Stars, is +in a perpetual Tremor; as may be seen by the tremulous Motion of Shadows +cast from high Towers, and by the twinkling of the fix'd Stars. But +these Stars do not twinkle when viewed through Telescopes which have +large apertures. For the Rays of Light which pass through divers parts +of the aperture, tremble each of them apart, and by means of their +various and sometimes contrary Tremors, fall at one and the same time +upon different points in the bottom of the Eye, and their trembling +Motions are too quick and confused to be perceived severally. And all +these illuminated Points constitute one broad lucid Point, composed of +those many trembling Points confusedly and insensibly mixed with one +another by very short and swift Tremors, and thereby cause the Star to +appear broader than it is, and without any trembling of the whole. Long +Telescopes may cause Objects to appear brighter and larger than short +ones can do, but they cannot be so formed as to take away that confusion +of the Rays which arises from the Tremors of the Atmosphere. The only +Remedy is a most serene and quiet Air, such as may perhaps be found on +the tops of the highest Mountains above the grosser Clouds. + +FOOTNOTES: + +[C] _See our_ Author's Lectiones Opticæ § 10. _Sect. II. § 29. and Sect. +III. Prop. 25._ + +[D] See our Author's _Lectiones Opticæ_, Part. I. Sect. 1. §5. + +[E] _This is very fully treated of in our_ Author's Lect. Optic. _Part_ +I. _Sect._ II. + +[F] _See our_ Author's Lect. Optic. Part I. Sect. II. § 29. + +[G] _This is demonstrated in our_ Author's Lect. Optic. _Part_ I. +_Sect._ IV. _Prop._ 37. + +[H] _How to do this, is shewn in our_ Author's Lect. Optic. _Part_ I. +_Sect._ IV. _Prop._ 31. + + + + +THE FIRST BOOK OF OPTICKS + + + + +_PART II._ + + +_PROP._ I. THEOR. I. + +_The Phænomena of Colours in refracted or reflected Light are not caused +by new Modifications of the Light variously impress'd, according to the +various Terminations of the Light and Shadow_. + +The PROOF by Experiments. + +_Exper._ 1. For if the Sun shine into a very dark Chamber through an +oblong hole F, [in _Fig._ 1.] whose breadth is the sixth or eighth part +of an Inch, or something less; and his beam FH do afterwards pass first +through a very large Prism ABC, distant about 20 Feet from the hole, and +parallel to it, and then (with its white part) through an oblong hole H, +whose breadth is about the fortieth or sixtieth part of an Inch, and +which is made in a black opake Body GI, and placed at the distance of +two or three Feet from the Prism, in a parallel Situation both to the +Prism and to the former hole, and if this white Light thus transmitted +through the hole H, fall afterwards upon a white Paper _pt_, placed +after that hole H, at the distance of three or four Feet from it, and +there paint the usual Colours of the Prism, suppose red at _t_, yellow +at _s_, green at _r_, blue at _q_, and violet at _p_; you may with an +Iron Wire, or any such like slender opake Body, whose breadth is about +the tenth part of an Inch, by intercepting the Rays at _k_, _l_, _m_, +_n_ or _o_, take away any one of the Colours at _t_, _s_, _r_, _q_ or +_p_, whilst the other Colours remain upon the Paper as before; or with +an Obstacle something bigger you may take away any two, or three, or +four Colours together, the rest remaining: So that any one of the +Colours as well as violet may become outmost in the Confine of the +Shadow towards _p_, and any one of them as well as red may become +outmost in the Confine of the Shadow towards _t_, and any one of them +may also border upon the Shadow made within the Colours by the Obstacle +R intercepting some intermediate part of the Light; and, lastly, any one +of them by being left alone, may border upon the Shadow on either hand. +All the Colours have themselves indifferently to any Confines of Shadow, +and therefore the differences of these Colours from one another, do not +arise from the different Confines of Shadow, whereby Light is variously +modified, as has hitherto been the Opinion of Philosophers. In trying +these things 'tis to be observed, that by how much the holes F and H are +narrower, and the Intervals between them and the Prism greater, and the +Chamber darker, by so much the better doth the Experiment succeed; +provided the Light be not so far diminished, but that the Colours at +_pt_ be sufficiently visible. To procure a Prism of solid Glass large +enough for this Experiment will be difficult, and therefore a prismatick +Vessel must be made of polish'd Glass Plates cemented together, and +filled with salt Water or clear Oil. + +[Illustration: FIG. 1.] + +_Exper._ 2. The Sun's Light let into a dark Chamber through the round +hole F, [in _Fig._ 2.] half an Inch wide, passed first through the Prism +ABC placed at the hole, and then through a Lens PT something more than +four Inches broad, and about eight Feet distant from the Prism, and +thence converged to O the Focus of the Lens distant from it about three +Feet, and there fell upon a white Paper DE. If that Paper was +perpendicular to that Light incident upon it, as 'tis represented in the +posture DE, all the Colours upon it at O appeared white. But if the +Paper being turned about an Axis parallel to the Prism, became very much +inclined to the Light, as 'tis represented in the Positions _de_ and +_[Greek: de]_; the same Light in the one case appeared yellow and red, +in the other blue. Here one and the same part of the Light in one and +the same place, according to the various Inclinations of the Paper, +appeared in one case white, in another yellow or red, in a third blue, +whilst the Confine of Light and shadow, and the Refractions of the Prism +in all these cases remained the same. + +[Illustration: FIG. 2.] + +[Illustration: FIG. 3.] + +_Exper._ 3. Such another Experiment may be more easily tried as follows. +Let a broad beam of the Sun's Light coming into a dark Chamber through a +hole in the Window-shut be refracted by a large Prism ABC, [in _Fig._ +3.] whose refracting Angle C is more than 60 Degrees, and so soon as it +comes out of the Prism, let it fall upon the white Paper DE glewed upon +a stiff Plane; and this Light, when the Paper is perpendicular to it, as +'tis represented in DE, will appear perfectly white upon the Paper; but +when the Paper is very much inclin'd to it in such a manner as to keep +always parallel to the Axis of the Prism, the whiteness of the whole +Light upon the Paper will according to the inclination of the Paper this +way or that way, change either into yellow and red, as in the posture +_de_, or into blue and violet, as in the posture [Greek: de]. And if the +Light before it fall upon the Paper be twice refracted the same way by +two parallel Prisms, these Colours will become the more conspicuous. +Here all the middle parts of the broad beam of white Light which fell +upon the Paper, did without any Confine of Shadow to modify it, become +colour'd all over with one uniform Colour, the Colour being always the +same in the middle of the Paper as at the edges, and this Colour changed +according to the various Obliquity of the reflecting Paper, without any +change in the Refractions or Shadow, or in the Light which fell upon the +Paper. And therefore these Colours are to be derived from some other +Cause than the new Modifications of Light by Refractions and Shadows. + +If it be asked, what then is their Cause? I answer, That the Paper in +the posture _de_, being more oblique to the more refrangible Rays than +to the less refrangible ones, is more strongly illuminated by the latter +than by the former, and therefore the less refrangible Rays are +predominant in the reflected Light. And where-ever they are predominant +in any Light, they tinge it with red or yellow, as may in some measure +appear by the first Proposition of the first Part of this Book, and will +more fully appear hereafter. And the contrary happens in the posture of +the Paper [Greek: de], the more refrangible Rays being then predominant +which always tinge Light with blues and violets. + +_Exper._ 4. The Colours of Bubbles with which Children play are various, +and change their Situation variously, without any respect to any Confine +or Shadow. If such a Bubble be cover'd with a concave Glass, to keep it +from being agitated by any Wind or Motion of the Air, the Colours will +slowly and regularly change their situation, even whilst the Eye and the +Bubble, and all Bodies which emit any Light, or cast any Shadow, remain +unmoved. And therefore their Colours arise from some regular Cause which +depends not on any Confine of Shadow. What this Cause is will be shewed +in the next Book. + +To these Experiments may be added the tenth Experiment of the first Part +of this first Book, where the Sun's Light in a dark Room being +trajected through the parallel Superficies of two Prisms tied together +in the form of a Parallelopipede, became totally of one uniform yellow +or red Colour, at its emerging out of the Prisms. Here, in the +production of these Colours, the Confine of Shadow can have nothing to +do. For the Light changes from white to yellow, orange and red +successively, without any alteration of the Confine of Shadow: And at +both edges of the emerging Light where the contrary Confines of Shadow +ought to produce different Effects, the Colour is one and the same, +whether it be white, yellow, orange or red: And in the middle of the +emerging Light, where there is no Confine of Shadow at all, the Colour +is the very same as at the edges, the whole Light at its very first +Emergence being of one uniform Colour, whether white, yellow, orange or +red, and going on thence perpetually without any change of Colour, such +as the Confine of Shadow is vulgarly supposed to work in refracted Light +after its Emergence. Neither can these Colours arise from any new +Modifications of the Light by Refractions, because they change +successively from white to yellow, orange and red, while the Refractions +remain the same, and also because the Refractions are made contrary ways +by parallel Superficies which destroy one another's Effects. They arise +not therefore from any Modifications of Light made by Refractions and +Shadows, but have some other Cause. What that Cause is we shewed above +in this tenth Experiment, and need not here repeat it. + +There is yet another material Circumstance of this Experiment. For this +emerging Light being by a third Prism HIK [in _Fig._ 22. _Part_ I.][I] +refracted towards the Paper PT, and there painting the usual Colours of +the Prism, red, yellow, green, blue, violet: If these Colours arose from +the Refractions of that Prism modifying the Light, they would not be in +the Light before its Incidence on that Prism. And yet in that Experiment +we found, that when by turning the two first Prisms about their common +Axis all the Colours were made to vanish but the red; the Light which +makes that red being left alone, appeared of the very same red Colour +before its Incidence on the third Prism. And in general we find by other +Experiments, that when the Rays which differ in Refrangibility are +separated from one another, and any one Sort of them is considered +apart, the Colour of the Light which they compose cannot be changed by +any Refraction or Reflexion whatever, as it ought to be were Colours +nothing else than Modifications of Light caused by Refractions, and +Reflexions, and Shadows. This Unchangeableness of Colour I am now to +describe in the following Proposition. + + +_PROP._ II. THEOR. II. + +_All homogeneal Light has its proper Colour answering to its Degree of +Refrangibility, and that Colour cannot be changed by Reflexions and +Refractions._ + +In the Experiments of the fourth Proposition of the first Part of this +first Book, when I had separated the heterogeneous Rays from one +another, the Spectrum _pt_ formed by the separated Rays, did in the +Progress from its End _p_, on which the most refrangible Rays fell, unto +its other End _t_, on which the least refrangible Rays fell, appear +tinged with this Series of Colours, violet, indigo, blue, green, yellow, +orange, red, together with all their intermediate Degrees in a continual +Succession perpetually varying. So that there appeared as many Degrees +of Colours, as there were sorts of Rays differing in Refrangibility. + +_Exper._ 5. Now, that these Colours could not be changed by Refraction, +I knew by refracting with a Prism sometimes one very little Part of this +Light, sometimes another very little Part, as is described in the +twelfth Experiment of the first Part of this Book. For by this +Refraction the Colour of the Light was never changed in the least. If +any Part of the red Light was refracted, it remained totally of the same +red Colour as before. No orange, no yellow, no green or blue, no other +new Colour was produced by that Refraction. Neither did the Colour any +ways change by repeated Refractions, but continued always the same red +entirely as at first. The like Constancy and Immutability I found also +in the blue, green, and other Colours. So also, if I looked through a +Prism upon any Body illuminated with any part of this homogeneal Light, +as in the fourteenth Experiment of the first Part of this Book is +described; I could not perceive any new Colour generated this way. All +Bodies illuminated with compound Light appear through Prisms confused, +(as was said above) and tinged with various new Colours, but those +illuminated with homogeneal Light appeared through Prisms neither less +distinct, nor otherwise colour'd, than when viewed with the naked Eyes. +Their Colours were not in the least changed by the Refraction of the +interposed Prism. I speak here of a sensible Change of Colour: For the +Light which I here call homogeneal, being not absolutely homogeneal, +there ought to arise some little Change of Colour from its +Heterogeneity. But, if that Heterogeneity was so little as it might be +made by the said Experiments of the fourth Proposition, that Change was +not sensible, and therefore in Experiments, where Sense is Judge, ought +to be accounted none at all. + +_Exper._ 6. And as these Colours were not changeable by Refractions, so +neither were they by Reflexions. For all white, grey, red, yellow, +green, blue, violet Bodies, as Paper, Ashes, red Lead, Orpiment, Indico +Bise, Gold, Silver, Copper, Grass, blue Flowers, Violets, Bubbles of +Water tinged with various Colours, Peacock's Feathers, the Tincture of +_Lignum Nephriticum_, and such-like, in red homogeneal Light appeared +totally red, in blue Light totally blue, in green Light totally green, +and so of other Colours. In the homogeneal Light of any Colour they all +appeared totally of that same Colour, with this only Difference, that +some of them reflected that Light more strongly, others more faintly. I +never yet found any Body, which by reflecting homogeneal Light could +sensibly change its Colour. + +From all which it is manifest, that if the Sun's Light consisted of but +one sort of Rays, there would be but one Colour in the whole World, nor +would it be possible to produce any new Colour by Reflexions and +Refractions, and by consequence that the variety of Colours depends upon +the Composition of Light. + + +_DEFINITION._ + +The homogeneal Light and Rays which appear red, or rather make Objects +appear so, I call Rubrifick or Red-making; those which make Objects +appear yellow, green, blue, and violet, I call Yellow-making, +Green-making, Blue-making, Violet-making, and so of the rest. And if at +any time I speak of Light and Rays as coloured or endued with Colours, I +would be understood to speak not philosophically and properly, but +grossly, and accordingly to such Conceptions as vulgar People in seeing +all these Experiments would be apt to frame. For the Rays to speak +properly are not coloured. In them there is nothing else than a certain +Power and Disposition to stir up a Sensation of this or that Colour. +For as Sound in a Bell or musical String, or other sounding Body, is +nothing but a trembling Motion, and in the Air nothing but that Motion +propagated from the Object, and in the Sensorium 'tis a Sense of that +Motion under the Form of Sound; so Colours in the Object are nothing but +a Disposition to reflect this or that sort of Rays more copiously than +the rest; in the Rays they are nothing but their Dispositions to +propagate this or that Motion into the Sensorium, and in the Sensorium +they are Sensations of those Motions under the Forms of Colours. + + +_PROP._ III. PROB. I. + +_To define the Refrangibility of the several sorts of homogeneal Light +answering to the several Colours._ + +For determining this Problem I made the following Experiment.[J] + +_Exper._ 7. When I had caused the Rectilinear Sides AF, GM, [in _Fig._ +4.] of the Spectrum of Colours made by the Prism to be distinctly +defined, as in the fifth Experiment of the first Part of this Book is +described, there were found in it all the homogeneal Colours in the same +Order and Situation one among another as in the Spectrum of simple +Light, described in the fourth Proposition of that Part. For the Circles +of which the Spectrum of compound Light PT is composed, and which in +the middle Parts of the Spectrum interfere, and are intermix'd with one +another, are not intermix'd in their outmost Parts where they touch +those Rectilinear Sides AF and GM. And therefore, in those Rectilinear +Sides when distinctly defined, there is no new Colour generated by +Refraction. I observed also, that if any where between the two outmost +Circles TMF and PGA a Right Line, as [Greek: gd], was cross to the +Spectrum, so as both Ends to fall perpendicularly upon its Rectilinear +Sides, there appeared one and the same Colour, and degree of Colour from +one End of this Line to the other. I delineated therefore in a Paper the +Perimeter of the Spectrum FAP GMT, and in trying the third Experiment of +the first Part of this Book, I held the Paper so that the Spectrum might +fall upon this delineated Figure, and agree with it exactly, whilst an +Assistant, whose Eyes for distinguishing Colours were more critical than +mine, did by Right Lines [Greek: ab, gd, ez,] &c. drawn cross the +Spectrum, note the Confines of the Colours, that is of the red M[Greek: +ab]F, of the orange [Greek: agdb], of the yellow [Greek: gezd], of the +green [Greek: eêthz], of the blue [Greek: êikth], of the indico [Greek: +ilmk], and of the violet [Greek: l]GA[Greek: m]. And this Operation +being divers times repeated both in the same, and in several Papers, I +found that the Observations agreed well enough with one another, and +that the Rectilinear Sides MG and FA were by the said cross Lines +divided after the manner of a Musical Chord. Let GM be produced to X, +that MX may be equal to GM, and conceive GX, [Greek: l]X, [Greek: i]X, +[Greek: ê]X, [Greek: e]X, [Greek: g]X, [Greek: a]X, MX, to be in +proportion to one another, as the Numbers, 1, 8/9, 5/6, 3/4, 2/3, 3/5, +9/16, 1/2, and so to represent the Chords of the Key, and of a Tone, a +third Minor, a fourth, a fifth, a sixth Major, a seventh and an eighth +above that Key: And the Intervals M[Greek: a], [Greek: ag], [Greek: ge], +[Greek: eê], [Greek: êi], [Greek: il], and [Greek: l]G, will be the +Spaces which the several Colours (red, orange, yellow, green, blue, +indigo, violet) take up. + +[Illustration: FIG. 4.] + +[Illustration: FIG. 5.] + +Now these Intervals or Spaces subtending the Differences of the +Refractions of the Rays going to the Limits of those Colours, that is, +to the Points M, [Greek: a], [Greek: g], [Greek: e], [Greek: ê], [Greek: +i], [Greek: l], G, may without any sensible Error be accounted +proportional to the Differences of the Sines of Refraction of those Rays +having one common Sine of Incidence, and therefore since the common Sine +of Incidence of the most and least refrangible Rays out of Glass into +Air was (by a Method described above) found in proportion to their Sines +of Refraction, as 50 to 77 and 78, divide the Difference between the +Sines of Refraction 77 and 78, as the Line GM is divided by those +Intervals, and you will have 77, 77-1/8, 77-1/5, 77-1/3, 77-1/2, 77-2/3, +77-7/9, 78, the Sines of Refraction of those Rays out of Glass into Air, +their common Sine of Incidence being 50. So then the Sines of the +Incidences of all the red-making Rays out of Glass into Air, were to the +Sines of their Refractions, not greater than 50 to 77, nor less than 50 +to 77-1/8, but they varied from one another according to all +intermediate Proportions. And the Sines of the Incidences of the +green-making Rays were to the Sines of their Refractions in all +Proportions from that of 50 to 77-1/3, unto that of 50 to 77-1/2. And +by the like Limits above-mentioned were the Refractions of the Rays +belonging to the rest of the Colours defined, the Sines of the +red-making Rays extending from 77 to 77-1/8, those of the orange-making +from 77-1/8 to 77-1/5, those of the yellow-making from 77-1/5 to 77-1/3, +those of the green-making from 77-1/3 to 77-1/2, those of the +blue-making from 77-1/2 to 77-2/3, those of the indigo-making from +77-2/3 to 77-7/9, and those of the violet from 77-7/9, to 78. + +These are the Laws of the Refractions made out of Glass into Air, and +thence by the third Axiom of the first Part of this Book, the Laws of +the Refractions made out of Air into Glass are easily derived. + +_Exper._ 8. I found moreover, that when Light goes out of Air through +several contiguous refracting Mediums as through Water and Glass, and +thence goes out again into Air, whether the refracting Superficies be +parallel or inclin'd to one another, that Light as often as by contrary +Refractions 'tis so corrected, that it emergeth in Lines parallel to +those in which it was incident, continues ever after to be white. But if +the emergent Rays be inclined to the incident, the Whiteness of the +emerging Light will by degrees in passing on from the Place of +Emergence, become tinged in its Edges with Colours. This I try'd by +refracting Light with Prisms of Glass placed within a Prismatick Vessel +of Water. Now those Colours argue a diverging and separation of the +heterogeneous Rays from one another by means of their unequal +Refractions, as in what follows will more fully appear. And, on the +contrary, the permanent whiteness argues, that in like Incidences of the +Rays there is no such separation of the emerging Rays, and by +consequence no inequality of their whole Refractions. Whence I seem to +gather the two following Theorems. + +1. The Excesses of the Sines of Refraction of several sorts of Rays +above their common Sine of Incidence when the Refractions are made out +of divers denser Mediums immediately into one and the same rarer Medium, +suppose of Air, are to one another in a given Proportion. + +2. The Proportion of the Sine of Incidence to the Sine of Refraction of +one and the same sort of Rays out of one Medium into another, is +composed of the Proportion of the Sine of Incidence to the Sine of +Refraction out of the first Medium into any third Medium, and of the +Proportion of the Sine of Incidence to the Sine of Refraction out of +that third Medium into the second Medium. + +By the first Theorem the Refractions of the Rays of every sort made out +of any Medium into Air are known by having the Refraction of the Rays of +any one sort. As for instance, if the Refractions of the Rays of every +sort out of Rain-water into Air be desired, let the common Sine of +Incidence out of Glass into Air be subducted from the Sines of +Refraction, and the Excesses will be 27, 27-1/8, 27-1/5, 27-1/3, 27-1/2, +27-2/3, 27-7/9, 28. Suppose now that the Sine of Incidence of the least +refrangible Rays be to their Sine of Refraction out of Rain-water into +Air as 3 to 4, and say as 1 the difference of those Sines is to 3 the +Sine of Incidence, so is 27 the least of the Excesses above-mentioned to +a fourth Number 81; and 81 will be the common Sine of Incidence out of +Rain-water into Air, to which Sine if you add all the above-mentioned +Excesses, you will have the desired Sines of the Refractions 108, +108-1/8, 108-1/5, 108-1/3, 108-1/2, 108-2/3, 108-7/9, 109. + +By the latter Theorem the Refraction out of one Medium into another is +gathered as often as you have the Refractions out of them both into any +third Medium. As if the Sine of Incidence of any Ray out of Glass into +Air be to its Sine of Refraction, as 20 to 31, and the Sine of Incidence +of the same Ray out of Air into Water, be to its Sine of Refraction as 4 +to 3; the Sine of Incidence of that Ray out of Glass into Water will be +to its Sine of Refraction as 20 to 31 and 4 to 3 jointly, that is, as +the Factum of 20 and 4 to the Factum of 31 and 3, or as 80 to 93. + +And these Theorems being admitted into Opticks, there would be scope +enough of handling that Science voluminously after a new manner,[K] not +only by teaching those things which tend to the perfection of Vision, +but also by determining mathematically all kinds of Phænomena of Colours +which could be produced by Refractions. For to do this, there is nothing +else requisite than to find out the Separations of heterogeneous Rays, +and their various Mixtures and Proportions in every Mixture. By this +way of arguing I invented almost all the Phænomena described in these +Books, beside some others less necessary to the Argument; and by the +successes I met with in the Trials, I dare promise, that to him who +shall argue truly, and then try all things with good Glasses and +sufficient Circumspection, the expected Event will not be wanting. But +he is first to know what Colours will arise from any others mix'd in any +assigned Proportion. + + +_PROP._ IV. THEOR. III. + +_Colours may be produced by Composition which shall be like to the +Colours of homogeneal Light as to the Appearance of Colour, but not as +to the Immutability of Colour and Constitution of Light. And those +Colours by how much they are more compounded by so much are they less +full and intense, and by too much Composition they maybe diluted and +weaken'd till they cease, and the Mixture becomes white or grey. There +may be also Colours produced by Composition, which are not fully like +any of the Colours of homogeneal Light._ + +For a Mixture of homogeneal red and yellow compounds an Orange, like in +appearance of Colour to that orange which in the series of unmixed +prismatick Colours lies between them; but the Light of one orange is +homogeneal as to Refrangibility, and that of the other is heterogeneal, +and the Colour of the one, if viewed through a Prism, remains unchanged, +that of the other is changed and resolved into its component Colours red +and yellow. And after the same manner other neighbouring homogeneal +Colours may compound new Colours, like the intermediate homogeneal ones, +as yellow and green, the Colour between them both, and afterwards, if +blue be added, there will be made a green the middle Colour of the three +which enter the Composition. For the yellow and blue on either hand, if +they are equal in quantity they draw the intermediate green equally +towards themselves in Composition, and so keep it as it were in +Æquilibrion, that it verge not more to the yellow on the one hand, and +to the blue on the other, but by their mix'd Actions remain still a +middle Colour. To this mix'd green there may be farther added some red +and violet, and yet the green will not presently cease, but only grow +less full and vivid, and by increasing the red and violet, it will grow +more and more dilute, until by the prevalence of the added Colours it be +overcome and turned into whiteness, or some other Colour. So if to the +Colour of any homogeneal Light, the Sun's white Light composed of all +sorts of Rays be added, that Colour will not vanish or change its +Species, but be diluted, and by adding more and more white it will be +diluted more and more perpetually. Lastly, If red and violet be mingled, +there will be generated according to their various Proportions various +Purples, such as are not like in appearance to the Colour of any +homogeneal Light, and of these Purples mix'd with yellow and blue may be +made other new Colours. + + +_PROP._ V. THEOR. IV. + +_Whiteness and all grey Colours between white and black, may be +compounded of Colours, and the whiteness of the Sun's Light is +compounded of all the primary Colours mix'd in a due Proportion._ + +The PROOF by Experiments. + +_Exper._ 9. The Sun shining into a dark Chamber through a little round +hole in the Window-shut, and his Light being there refracted by a Prism +to cast his coloured Image PT [in _Fig._ 5.] upon the opposite Wall: I +held a white Paper V to that image in such manner that it might be +illuminated by the colour'd Light reflected from thence, and yet not +intercept any part of that Light in its passage from the Prism to the +Spectrum. And I found that when the Paper was held nearer to any Colour +than to the rest, it appeared of that Colour to which it approached +nearest; but when it was equally or almost equally distant from all the +Colours, so that it might be equally illuminated by them all it appeared +white. And in this last situation of the Paper, if some Colours were +intercepted, the Paper lost its white Colour, and appeared of the Colour +of the rest of the Light which was not intercepted. So then the Paper +was illuminated with Lights of various Colours, namely, red, yellow, +green, blue and violet, and every part of the Light retained its proper +Colour, until it was incident on the Paper, and became reflected thence +to the Eye; so that if it had been either alone (the rest of the Light +being intercepted) or if it had abounded most, and been predominant in +the Light reflected from the Paper, it would have tinged the Paper with +its own Colour; and yet being mixed with the rest of the Colours in a +due proportion, it made the Paper look white, and therefore by a +Composition with the rest produced that Colour. The several parts of the +coloured Light reflected from the Spectrum, whilst they are propagated +from thence through the Air, do perpetually retain their proper Colours, +because wherever they fall upon the Eyes of any Spectator, they make the +several parts of the Spectrum to appear under their proper Colours. They +retain therefore their proper Colours when they fall upon the Paper V, +and so by the confusion and perfect mixture of those Colours compound +the whiteness of the Light reflected from thence. + +_Exper._ 10. Let that Spectrum or solar Image PT [in _Fig._ 6.] fall now +upon the Lens MN above four Inches broad, and about six Feet distant +from the Prism ABC and so figured that it may cause the coloured Light +which divergeth from the Prism to converge and meet again at its Focus +G, about six or eight Feet distant from the Lens, and there to fall +perpendicularly upon a white Paper DE. And if you move this Paper to and +fro, you will perceive that near the Lens, as at _de_, the whole solar +Image (suppose at _pt_) will appear upon it intensely coloured after the +manner above-explained, and that by receding from the Lens those Colours +will perpetually come towards one another, and by mixing more and more +dilute one another continually, until at length the Paper come to the +Focus G, where by a perfect mixture they will wholly vanish and be +converted into whiteness, the whole Light appearing now upon the Paper +like a little white Circle. And afterwards by receding farther from the +Lens, the Rays which before converged will now cross one another in the +Focus G, and diverge from thence, and thereby make the Colours to appear +again, but yet in a contrary order; suppose at [Greek: de], where the +red _t_ is now above which before was below, and the violet _p_ is below +which before was above. + +Let us now stop the Paper at the Focus G, where the Light appears +totally white and circular, and let us consider its whiteness. I say, +that this is composed of the converging Colours. For if any of those +Colours be intercepted at the Lens, the whiteness will cease and +degenerate into that Colour which ariseth from the composition of the +other Colours which are not intercepted. And then if the intercepted +Colours be let pass and fall upon that compound Colour, they mix with +it, and by their mixture restore the whiteness. So if the violet, blue +and green be intercepted, the remaining yellow, orange and red will +compound upon the Paper an orange, and then if the intercepted Colours +be let pass, they will fall upon this compounded orange, and together +with it decompound a white. So also if the red and violet be +intercepted, the remaining yellow, green and blue, will compound a green +upon the Paper, and then the red and violet being let pass will fall +upon this green, and together with it decompound a white. And that in +this Composition of white the several Rays do not suffer any Change in +their colorific Qualities by acting upon one another, but are only +mixed, and by a mixture of their Colours produce white, may farther +appear by these Arguments. + +[Illustration: FIG. 6.] + +If the Paper be placed beyond the Focus G, suppose at [Greek: de], and +then the red Colour at the Lens be alternately intercepted, and let pass +again, the violet Colour on the Paper will not suffer any Change +thereby, as it ought to do if the several sorts of Rays acted upon one +another in the Focus G, where they cross. Neither will the red upon the +Paper be changed by any alternate stopping, and letting pass the violet +which crosseth it. + +And if the Paper be placed at the Focus G, and the white round Image at +G be viewed through the Prism HIK, and by the Refraction of that Prism +be translated to the place _rv_, and there appear tinged with various +Colours, namely, the violet at _v_ and red at _r_, and others between, +and then the red Colours at the Lens be often stopp'd and let pass by +turns, the red at _r_ will accordingly disappear, and return as often, +but the violet at _v_ will not thereby suffer any Change. And so by +stopping and letting pass alternately the blue at the Lens, the blue at +_v_ will accordingly disappear and return, without any Change made in +the red at _r_. The red therefore depends on one sort of Rays, and the +blue on another sort, which in the Focus G where they are commix'd, do +not act on one another. And there is the same Reason of the other +Colours. + +I considered farther, that when the most refrangible Rays P_p_, and the +least refrangible ones T_t_, are by converging inclined to one another, +the Paper, if held very oblique to those Rays in the Focus G, might +reflect one sort of them more copiously than the other sort, and by that +Means the reflected Light would be tinged in that Focus with the Colour +of the predominant Rays, provided those Rays severally retained their +Colours, or colorific Qualities in the Composition of White made by them +in that Focus. But if they did not retain them in that White, but became +all of them severally endued there with a Disposition to strike the +Sense with the Perception of White, then they could never lose their +Whiteness by such Reflexions. I inclined therefore the Paper to the Rays +very obliquely, as in the second Experiment of this second Part of the +first Book, that the most refrangible Rays, might be more copiously +reflected than the rest, and the Whiteness at Length changed +successively into blue, indigo, and violet. Then I inclined it the +contrary Way, that the least refrangible Rays might be more copious in +the reflected Light than the rest, and the Whiteness turned successively +to yellow, orange, and red. + +Lastly, I made an Instrument XY in fashion of a Comb, whose Teeth being +in number sixteen, were about an Inch and a half broad, and the +Intervals of the Teeth about two Inches wide. Then by interposing +successively the Teeth of this Instrument near the Lens, I intercepted +Part of the Colours by the interposed Tooth, whilst the rest of them +went on through the Interval of the Teeth to the Paper DE, and there +painted a round Solar Image. But the Paper I had first placed so, that +the Image might appear white as often as the Comb was taken away; and +then the Comb being as was said interposed, that Whiteness by reason of +the intercepted Part of the Colours at the Lens did always change into +the Colour compounded of those Colours which were not intercepted, and +that Colour was by the Motion of the Comb perpetually varied so, that in +the passing of every Tooth over the Lens all these Colours, red, yellow, +green, blue, and purple, did always succeed one another. I caused +therefore all the Teeth to pass successively over the Lens, and when the +Motion was slow, there appeared a perpetual Succession of the Colours +upon the Paper: But if I so much accelerated the Motion, that the +Colours by reason of their quick Succession could not be distinguished +from one another, the Appearance of the single Colours ceased. There was +no red, no yellow, no green, no blue, nor purple to be seen any longer, +but from a Confusion of them all there arose one uniform white Colour. +Of the Light which now by the Mixture of all the Colours appeared white, +there was no Part really white. One Part was red, another yellow, a +third green, a fourth blue, a fifth purple, and every Part retains its +proper Colour till it strike the Sensorium. If the Impressions follow +one another slowly, so that they may be severally perceived, there is +made a distinct Sensation of all the Colours one after another in a +continual Succession. But if the Impressions follow one another so +quickly, that they cannot be severally perceived, there ariseth out of +them all one common Sensation, which is neither of this Colour alone nor +of that alone, but hath it self indifferently to 'em all, and this is a +Sensation of Whiteness. By the Quickness of the Successions, the +Impressions of the several Colours are confounded in the Sensorium, and +out of that Confusion ariseth a mix'd Sensation. If a burning Coal be +nimbly moved round in a Circle with Gyrations continually repeated, the +whole Circle will appear like Fire; the reason of which is, that the +Sensation of the Coal in the several Places of that Circle remains +impress'd on the Sensorium, until the Coal return again to the same +Place. And so in a quick Consecution of the Colours the Impression of +every Colour remains in the Sensorium, until a Revolution of all the +Colours be compleated, and that first Colour return again. The +Impressions therefore of all the successive Colours are at once in the +Sensorium, and jointly stir up a Sensation of them all; and so it is +manifest by this Experiment, that the commix'd Impressions of all the +Colours do stir up and beget a Sensation of white, that is, that +Whiteness is compounded of all the Colours. + +And if the Comb be now taken away, that all the Colours may at once pass +from the Lens to the Paper, and be there intermixed, and together +reflected thence to the Spectator's Eyes; their Impressions on the +Sensorium being now more subtilly and perfectly commixed there, ought +much more to stir up a Sensation of Whiteness. + +You may instead of the Lens use two Prisms HIK and LMN, which by +refracting the coloured Light the contrary Way to that of the first +Refraction, may make the diverging Rays converge and meet again in G, as +you see represented in the seventh Figure. For where they meet and mix, +they will compose a white Light, as when a Lens is used. + +_Exper._ 11. Let the Sun's coloured Image PT [in _Fig._ 8.] fall upon +the Wall of a dark Chamber, as in the third Experiment of the first +Book, and let the same be viewed through a Prism _abc_, held parallel to +the Prism ABC, by whose Refraction that Image was made, and let it now +appear lower than before, suppose in the Place S over-against the red +Colour T. And if you go near to the Image PT, the Spectrum S will appear +oblong and coloured like the Image PT; but if you recede from it, the +Colours of the spectrum S will be contracted more and more, and at +length vanish, that Spectrum S becoming perfectly round and white; and +if you recede yet farther, the Colours will emerge again, but in a +contrary Order. Now that Spectrum S appears white in that Case, when the +Rays of several sorts which converge from the several Parts of the Image +PT, to the Prism _abc_, are so refracted unequally by it, that in their +Passage from the Prism to the Eye they may diverge from one and the same +Point of the Spectrum S, and so fall afterwards upon one and the same +Point in the bottom of the Eye, and there be mingled. + +[Illustration: FIG. 7.] + +[Illustration: FIG. 8.] + +And farther, if the Comb be here made use of, by whose Teeth the Colours +at the Image PT may be successively intercepted; the Spectrum S, when +the Comb is moved slowly, will be perpetually tinged with successive +Colours: But when by accelerating the Motion of the Comb, the Succession +of the Colours is so quick that they cannot be severally seen, that +Spectrum S, by a confused and mix'd Sensation of them all, will appear +white. + +_Exper._ 12. The Sun shining through a large Prism ABC [in _Fig._ 9.] +upon a Comb XY, placed immediately behind the Prism, his Light which +passed through the Interstices of the Teeth fell upon a white Paper DE. +The Breadths of the Teeth were equal to their Interstices, and seven +Teeth together with their Interstices took up an Inch in Breadth. Now, +when the Paper was about two or three Inches distant from the Comb, the +Light which passed through its several Interstices painted so many +Ranges of Colours, _kl_, _mn_, _op_, _qr_, &c. which were parallel to +one another, and contiguous, and without any Mixture of white. And these +Ranges of Colours, if the Comb was moved continually up and down with a +reciprocal Motion, ascended and descended in the Paper, and when the +Motion of the Comb was so quick, that the Colours could not be +distinguished from one another, the whole Paper by their Confusion and +Mixture in the Sensorium appeared white. + +[Illustration: FIG. 9.] + +Let the Comb now rest, and let the Paper be removed farther from the +Prism, and the several Ranges of Colours will be dilated and expanded +into one another more and more, and by mixing their Colours will dilute +one another, and at length, when the distance of the Paper from the Comb +is about a Foot, or a little more (suppose in the Place 2D 2E) they will +so far dilute one another, as to become white. + +With any Obstacle, let all the Light be now stopp'd which passes through +any one Interval of the Teeth, so that the Range of Colours which comes +from thence may be taken away, and you will see the Light of the rest of +the Ranges to be expanded into the Place of the Range taken away, and +there to be coloured. Let the intercepted Range pass on as before, and +its Colours falling upon the Colours of the other Ranges, and mixing +with them, will restore the Whiteness. + +Let the Paper 2D 2E be now very much inclined to the Rays, so that the +most refrangible Rays may be more copiously reflected than the rest, and +the white Colour of the Paper through the Excess of those Rays will be +changed into blue and violet. Let the Paper be as much inclined the +contrary way, that the least refrangible Rays may be now more copiously +reflected than the rest, and by their Excess the Whiteness will be +changed into yellow and red. The several Rays therefore in that white +Light do retain their colorific Qualities, by which those of any sort, +whenever they become more copious than the rest, do by their Excess and +Predominance cause their proper Colour to appear. + +And by the same way of arguing, applied to the third Experiment of this +second Part of the first Book, it may be concluded, that the white +Colour of all refracted Light at its very first Emergence, where it +appears as white as before its Incidence, is compounded of various +Colours. + +[Illustration: FIG. 10.] + +_Exper._ 13. In the foregoing Experiment the several Intervals of the +Teeth of the Comb do the Office of so many Prisms, every Interval +producing the Phænomenon of one Prism. Whence instead of those Intervals +using several Prisms, I try'd to compound Whiteness by mixing their +Colours, and did it by using only three Prisms, as also by using only +two as follows. Let two Prisms ABC and _abc_, [in _Fig._ 10.] whose +refracting Angles B and _b_ are equal, be so placed parallel to one +another, that the refracting Angle B of the one may touch the Angle _c_ +at the Base of the other, and their Planes CB and _cb_, at which the +Rays emerge, may lie in Directum. Then let the Light trajected through +them fall upon the Paper MN, distant about 8 or 12 Inches from the +Prisms. And the Colours generated by the interior Limits B and _c_ of +the two Prisms, will be mingled at PT, and there compound white. For if +either Prism be taken away, the Colours made by the other will appear in +that Place PT, and when the Prism is restored to its Place again, so +that its Colours may there fall upon the Colours of the other, the +Mixture of them both will restore the Whiteness. + +This Experiment succeeds also, as I have tried, when the Angle _b_ of +the lower Prism, is a little greater than the Angle B of the upper, and +between the interior Angles B and _c_, there intercedes some Space B_c_, +as is represented in the Figure, and the refracting Planes BC and _bc_, +are neither in Directum, nor parallel to one another. For there is +nothing more requisite to the Success of this Experiment, than that the +Rays of all sorts may be uniformly mixed upon the Paper in the Place PT. +If the most refrangible Rays coming from the superior Prism take up all +the Space from M to P, the Rays of the same sort which come from the +inferior Prism ought to begin at P, and take up all the rest of the +Space from thence towards N. If the least refrangible Rays coming from +the superior Prism take up the Space MT, the Rays of the same kind which +come from the other Prism ought to begin at T, and take up the +remaining Space TN. If one sort of the Rays which have intermediate +Degrees of Refrangibility, and come from the superior Prism be extended +through the Space MQ, and another sort of those Rays through the Space +MR, and a third sort of them through the Space MS, the same sorts of +Rays coming from the lower Prism, ought to illuminate the remaining +Spaces QN, RN, SN, respectively. And the same is to be understood of all +the other sorts of Rays. For thus the Rays of every sort will be +scattered uniformly and evenly through the whole Space MN, and so being +every where mix'd in the same Proportion, they must every where produce +the same Colour. And therefore, since by this Mixture they produce white +in the Exterior Spaces MP and TN, they must also produce white in the +Interior Space PT. This is the reason of the Composition by which +Whiteness was produced in this Experiment, and by what other way soever +I made the like Composition, the Result was Whiteness. + +Lastly, If with the Teeth of a Comb of a due Size, the coloured Lights +of the two Prisms which fall upon the Space PT be alternately +intercepted, that Space PT, when the Motion of the Comb is slow, will +always appear coloured, but by accelerating the Motion of the Comb so +much that the successive Colours cannot be distinguished from one +another, it will appear white. + +_Exper._ 14. Hitherto I have produced Whiteness by mixing the Colours of +Prisms. If now the Colours of natural Bodies are to be mingled, let +Water a little thicken'd with Soap be agitated to raise a Froth, and +after that Froth has stood a little, there will appear to one that shall +view it intently various Colours every where in the Surfaces of the +several Bubbles; but to one that shall go so far off, that he cannot +distinguish the Colours from one another, the whole Froth will grow +white with a perfect Whiteness. + +_Exper._ 15. Lastly, In attempting to compound a white, by mixing the +coloured Powders which Painters use, I consider'd that all colour'd +Powders do suppress and stop in them a very considerable Part of the +Light by which they are illuminated. For they become colour'd by +reflecting the Light of their own Colours more copiously, and that of +all other Colours more sparingly, and yet they do not reflect the Light +of their own Colours so copiously as white Bodies do. If red Lead, for +instance, and a white Paper, be placed in the red Light of the colour'd +Spectrum made in a dark Chamber by the Refraction of a Prism, as is +described in the third Experiment of the first Part of this Book; the +Paper will appear more lucid than the red Lead, and therefore reflects +the red-making Rays more copiously than red Lead doth. And if they be +held in the Light of any other Colour, the Light reflected by the Paper +will exceed the Light reflected by the red Lead in a much greater +Proportion. And the like happens in Powders of other Colours. And +therefore by mixing such Powders, we are not to expect a strong and +full White, such as is that of Paper, but some dusky obscure one, such +as might arise from a Mixture of Light and Darkness, or from white and +black, that is, a grey, or dun, or russet brown, such as are the Colours +of a Man's Nail, of a Mouse, of Ashes, of ordinary Stones, of Mortar, of +Dust and Dirt in High-ways, and the like. And such a dark white I have +often produced by mixing colour'd Powders. For thus one Part of red +Lead, and five Parts of _Viride Æris_, composed a dun Colour like that +of a Mouse. For these two Colours were severally so compounded of +others, that in both together were a Mixture of all Colours; and there +was less red Lead used than _Viride Æris_, because of the Fulness of its +Colour. Again, one Part of red Lead, and four Parts of blue Bise, +composed a dun Colour verging a little to purple, and by adding to this +a certain Mixture of Orpiment and _Viride Æris_ in a due Proportion, the +Mixture lost its purple Tincture, and became perfectly dun. But the +Experiment succeeded best without Minium thus. To Orpiment I added by +little and little a certain full bright purple, which Painters use, +until the Orpiment ceased to be yellow, and became of a pale red. Then I +diluted that red by adding a little _Viride Æris_, and a little more +blue Bise than _Viride Æris_, until it became of such a grey or pale +white, as verged to no one of the Colours more than to another. For thus +it became of a Colour equal in Whiteness to that of Ashes, or of Wood +newly cut, or of a Man's Skin. The Orpiment reflected more Light than +did any other of the Powders, and therefore conduced more to the +Whiteness of the compounded Colour than they. To assign the Proportions +accurately may be difficult, by reason of the different Goodness of +Powders of the same kind. Accordingly, as the Colour of any Powder is +more or less full and luminous, it ought to be used in a less or greater +Proportion. + +Now, considering that these grey and dun Colours may be also produced by +mixing Whites and Blacks, and by consequence differ from perfect Whites, +not in Species of Colours, but only in degree of Luminousness, it is +manifest that there is nothing more requisite to make them perfectly +white than to increase their Light sufficiently; and, on the contrary, +if by increasing their Light they can be brought to perfect Whiteness, +it will thence also follow, that they are of the same Species of Colour +with the best Whites, and differ from them only in the Quantity of +Light. And this I tried as follows. I took the third of the +above-mention'd grey Mixtures, (that which was compounded of Orpiment, +Purple, Bise, and _Viride Æris_) and rubbed it thickly upon the Floor of +my Chamber, where the Sun shone upon it through the opened Casement; and +by it, in the shadow, I laid a Piece of white Paper of the same Bigness. +Then going from them to the distance of 12 or 18 Feet, so that I could +not discern the Unevenness of the Surface of the Powder, nor the little +Shadows let fall from the gritty Particles thereof; the Powder appeared +intensely white, so as to transcend even the Paper it self in Whiteness, +especially if the Paper were a little shaded from the Light of the +Clouds, and then the Paper compared with the Powder appeared of such a +grey Colour as the Powder had done before. But by laying the Paper where +the Sun shines through the Glass of the Window, or by shutting the +Window that the Sun might shine through the Glass upon the Powder, and +by such other fit Means of increasing or decreasing the Lights wherewith +the Powder and Paper were illuminated, the Light wherewith the Powder is +illuminated may be made stronger in such a due Proportion than the Light +wherewith the Paper is illuminated, that they shall both appear exactly +alike in Whiteness. For when I was trying this, a Friend coming to visit +me, I stopp'd him at the Door, and before I told him what the Colours +were, or what I was doing; I asked him, Which of the two Whites were the +best, and wherein they differed? And after he had at that distance +viewed them well, he answer'd, that they were both good Whites, and that +he could not say which was best, nor wherein their Colours differed. +Now, if you consider, that this White of the Powder in the Sun-shine was +compounded of the Colours which the component Powders (Orpiment, Purple, +Bise, and _Viride Æris_) have in the same Sun-shine, you must +acknowledge by this Experiment, as well as by the former, that perfect +Whiteness may be compounded of Colours. + +From what has been said it is also evident, that the Whiteness of the +Sun's Light is compounded of all the Colours wherewith the several sorts +of Rays whereof that Light consists, when by their several +Refrangibilities they are separated from one another, do tinge Paper or +any other white Body whereon they fall. For those Colours (by _Prop._ +II. _Part_ 2.) are unchangeable, and whenever all those Rays with those +their Colours are mix'd again, they reproduce the same white Light as +before. + + +_PROP._ VI. PROB. II. + +_In a mixture of Primary Colours, the Quantity and Quality of each being +given, to know the Colour of the Compound._ + +[Illustration: FIG. 11.] + +With the Center O [in _Fig._ 11.] and Radius OD describe a Circle ADF, +and distinguish its Circumference into seven Parts DE, EF, FG, GA, AB, +BC, CD, proportional to the seven Musical Tones or Intervals of the +eight Sounds, _Sol_, _la_, _fa_, _sol_, _la_, _mi_, _fa_, _sol_, +contained in an eight, that is, proportional to the Number 1/9, 1/16, +1/10, 1/9, 1/16, 1/16, 1/9. Let the first Part DE represent a red +Colour, the second EF orange, the third FG yellow, the fourth CA green, +the fifth AB blue, the sixth BC indigo, and the seventh CD violet. And +conceive that these are all the Colours of uncompounded Light gradually +passing into one another, as they do when made by Prisms; the +Circumference DEFGABCD, representing the whole Series of Colours from +one end of the Sun's colour'd Image to the other, so that from D to E be +all degrees of red, at E the mean Colour between red and orange, from E +to F all degrees of orange, at F the mean between orange and yellow, +from F to G all degrees of yellow, and so on. Let _p_ be the Center of +Gravity of the Arch DE, and _q_, _r_, _s_, _t_, _u_, _x_, the Centers of +Gravity of the Arches EF, FG, GA, AB, BC, and CD respectively, and about +those Centers of Gravity let Circles proportional to the Number of Rays +of each Colour in the given Mixture be describ'd: that is, the Circle +_p_ proportional to the Number of the red-making Rays in the Mixture, +the Circle _q_ proportional to the Number of the orange-making Rays in +the Mixture, and so of the rest. Find the common Center of Gravity of +all those Circles, _p_, _q_, _r_, _s_, _t_, _u_, _x_. Let that Center be +Z; and from the Center of the Circle ADF, through Z to the +Circumference, drawing the Right Line OY, the Place of the Point Y in +the Circumference shall shew the Colour arising from the Composition of +all the Colours in the given Mixture, and the Line OZ shall be +proportional to the Fulness or Intenseness of the Colour, that is, to +its distance from Whiteness. As if Y fall in the middle between F and G, +the compounded Colour shall be the best yellow; if Y verge from the +middle towards F or G, the compound Colour shall accordingly be a +yellow, verging towards orange or green. If Z fall upon the +Circumference, the Colour shall be intense and florid in the highest +Degree; if it fall in the mid-way between the Circumference and Center, +it shall be but half so intense, that is, it shall be such a Colour as +would be made by diluting the intensest yellow with an equal quantity of +whiteness; and if it fall upon the center O, the Colour shall have lost +all its intenseness, and become a white. But it is to be noted, That if +the point Z fall in or near the line OD, the main ingredients being the +red and violet, the Colour compounded shall not be any of the prismatick +Colours, but a purple, inclining to red or violet, accordingly as the +point Z lieth on the side of the line DO towards E or towards C, and in +general the compounded violet is more bright and more fiery than the +uncompounded. Also if only two of the primary Colours which in the +circle are opposite to one another be mixed in an equal proportion, the +point Z shall fall upon the center O, and yet the Colour compounded of +those two shall not be perfectly white, but some faint anonymous Colour. +For I could never yet by mixing only two primary Colours produce a +perfect white. Whether it may be compounded of a mixture of three taken +at equal distances in the circumference I do not know, but of four or +five I do not much question but it may. But these are Curiosities of +little or no moment to the understanding the Phænomena of Nature. For in +all whites produced by Nature, there uses to be a mixture of all sorts +of Rays, and by consequence a composition of all Colours. + +To give an instance of this Rule; suppose a Colour is compounded of +these homogeneal Colours, of violet one part, of indigo one part, of +blue two parts, of green three parts, of yellow five parts, of orange +six parts, and of red ten parts. Proportional to these parts describe +the Circles _x_, _v_, _t_, _s_, _r_, _q_, _p_, respectively, that is, so +that if the Circle _x_ be one, the Circle _v_ may be one, the Circle _t_ +two, the Circle _s_ three, and the Circles _r_, _q_ and _p_, five, six +and ten. Then I find Z the common center of gravity of these Circles, +and through Z drawing the Line OY, the Point Y falls upon the +circumference between E and F, something nearer to E than to F, and +thence I conclude, that the Colour compounded of these Ingredients will +be an orange, verging a little more to red than to yellow. Also I find +that OZ is a little less than one half of OY, and thence I conclude, +that this orange hath a little less than half the fulness or intenseness +of an uncompounded orange; that is to say, that it is such an orange as +may be made by mixing an homogeneal orange with a good white in the +proportion of the Line OZ to the Line ZY, this Proportion being not of +the quantities of mixed orange and white Powders, but of the quantities +of the Lights reflected from them. + +This Rule I conceive accurate enough for practice, though not +mathematically accurate; and the truth of it may be sufficiently proved +to Sense, by stopping any of the Colours at the Lens in the tenth +Experiment of this Book. For the rest of the Colours which are not +stopp'd, but pass on to the Focus of the Lens, will there compound +either accurately or very nearly such a Colour, as by this Rule ought to +result from their Mixture. + + +_PROP._ VII. THEOR. V. + +_All the Colours in the Universe which are made by Light, and depend not +on the Power of Imagination, are either the Colours of homogeneal +Lights, or compounded of these, and that either accurately or very +nearly, according to the Rule of the foregoing Problem._ + +For it has been proved (in _Prop. 1. Part 2._) that the changes of +Colours made by Refractions do not arise from any new Modifications of +the Rays impress'd by those Refractions, and by the various Terminations +of Light and Shadow, as has been the constant and general Opinion of +Philosophers. It has also been proved that the several Colours of the +homogeneal Rays do constantly answer to their degrees of Refrangibility, +(_Prop._ 1. _Part_ 1. and _Prop._ 2. _Part_ 2.) and that their degrees +of Refrangibility cannot be changed by Refractions and Reflexions +(_Prop._ 2. _Part_ 1.) and by consequence that those their Colours are +likewise immutable. It has also been proved directly by refracting and +reflecting homogeneal Lights apart, that their Colours cannot be +changed, (_Prop._ 2. _Part_ 2.) It has been proved also, that when the +several sorts of Rays are mixed, and in crossing pass through the same +space, they do not act on one another so as to change each others +colorific qualities. (_Exper._ 10. _Part_ 2.) but by mixing their +Actions in the Sensorium beget a Sensation differing from what either +would do apart, that is a Sensation of a mean Colour between their +proper Colours; and particularly when by the concourse and mixtures of +all sorts of Rays, a white Colour is produced, the white is a mixture of +all the Colours which the Rays would have apart, (_Prop._ 5. _Part_ 2.) +The Rays in that mixture do not lose or alter their several colorific +qualities, but by all their various kinds of Actions mix'd in the +Sensorium, beget a Sensation of a middling Colour between all their +Colours, which is whiteness. For whiteness is a mean between all +Colours, having it self indifferently to them all, so as with equal +facility to be tinged with any of them. A red Powder mixed with a little +blue, or a blue with a little red, doth not presently lose its Colour, +but a white Powder mix'd with any Colour is presently tinged with that +Colour, and is equally capable of being tinged with any Colour whatever. +It has been shewed also, that as the Sun's Light is mix'd of all sorts +of Rays, so its whiteness is a mixture of the Colours of all sorts of +Rays; those Rays having from the beginning their several colorific +qualities as well as their several Refrangibilities, and retaining them +perpetually unchanged notwithstanding any Refractions or Reflexions they +may at any time suffer, and that whenever any sort of the Sun's Rays is +by any means (as by Reflexion in _Exper._ 9, and 10. _Part_ 1. or by +Refraction as happens in all Refractions) separated from the rest, they +then manifest their proper Colours. These things have been prov'd, and +the sum of all this amounts to the Proposition here to be proved. For if +the Sun's Light is mix'd of several sorts of Rays, each of which have +originally their several Refrangibilities and colorific Qualities, and +notwithstanding their Refractions and Reflexions, and their various +Separations or Mixtures, keep those their original Properties +perpetually the same without alteration; then all the Colours in the +World must be such as constantly ought to arise from the original +colorific qualities of the Rays whereof the Lights consist by which +those Colours are seen. And therefore if the reason of any Colour +whatever be required, we have nothing else to do than to consider how +the Rays in the Sun's Light have by Reflexions or Refractions, or other +causes, been parted from one another, or mixed together; or otherwise to +find out what sorts of Rays are in the Light by which that Colour is +made, and in what Proportion; and then by the last Problem to learn the +Colour which ought to arise by mixing those Rays (or their Colours) in +that proportion. I speak here of Colours so far as they arise from +Light. For they appear sometimes by other Causes, as when by the power +of Phantasy we see Colours in a Dream, or a Mad-man sees things before +him which are not there; or when we see Fire by striking the Eye, or see +Colours like the Eye of a Peacock's Feather, by pressing our Eyes in +either corner whilst we look the other way. Where these and such like +Causes interpose not, the Colour always answers to the sort or sorts of +the Rays whereof the Light consists, as I have constantly found in +whatever Phænomena of Colours I have hitherto been able to examine. I +shall in the following Propositions give instances of this in the +Phænomena of chiefest note. + + +_PROP._ VIII. PROB. III. + +_By the discovered Properties of Light to explain the Colours made by +Prisms._ + +Let ABC [in _Fig._ 12.] represent a Prism refracting the Light of the +Sun, which comes into a dark Chamber through a hole F[Greek: ph] almost +as broad as the Prism, and let MN represent a white Paper on which the +refracted Light is cast, and suppose the most refrangible or deepest +violet-making Rays fall upon the Space P[Greek: p], the least +refrangible or deepest red-making Rays upon the Space T[Greek: t], the +middle sort between the indigo-making and blue-making Rays upon the +Space Q[Greek: ch], the middle sort of the green-making Rays upon the +Space R, the middle sort between the yellow-making and orange-making +Rays upon the Space S[Greek: s], and other intermediate sorts upon +intermediate Spaces. For so the Spaces upon which the several sorts +adequately fall will by reason of the different Refrangibility of those +sorts be one lower than another. Now if the Paper MN be so near the +Prism that the Spaces PT and [Greek: pt] do not interfere with one +another, the distance between them T[Greek: p] will be illuminated by +all the sorts of Rays in that proportion to one another which they have +at their very first coming out of the Prism, and consequently be white. +But the Spaces PT and [Greek: pt] on either hand, will not be +illuminated by them all, and therefore will appear coloured. And +particularly at P, where the outmost violet-making Rays fall alone, the +Colour must be the deepest violet. At Q where the violet-making and +indigo-making Rays are mixed, it must be a violet inclining much to +indigo. At R where the violet-making, indigo-making, blue-making, and +one half of the green-making Rays are mixed, their Colours must (by the +construction of the second Problem) compound a middle Colour between +indigo and blue. At S where all the Rays are mixed, except the +red-making and orange-making, their Colours ought by the same Rule to +compound a faint blue, verging more to green than indigo. And in the +progress from S to T, this blue will grow more and more faint and +dilute, till at T, where all the Colours begin to be mixed, it ends in +whiteness. + +[Illustration: FIG. 12.] + +So again, on the other side of the white at [Greek: t], where the least +refrangible or utmost red-making Rays are alone, the Colour must be the +deepest red. At [Greek: s] the mixture of red and orange will compound a +red inclining to orange. At [Greek: r] the mixture of red, orange, +yellow, and one half of the green must compound a middle Colour between +orange and yellow. At [Greek: ch] the mixture of all Colours but violet +and indigo will compound a faint yellow, verging more to green than to +orange. And this yellow will grow more faint and dilute continually in +its progress from [Greek: ch] to [Greek: p], where by a mixture of all +sorts of Rays it will become white. + +These Colours ought to appear were the Sun's Light perfectly white: But +because it inclines to yellow, the Excess of the yellow-making Rays +whereby 'tis tinged with that Colour, being mixed with the faint blue +between S and T, will draw it to a faint green. And so the Colours in +order from P to [Greek: t] ought to be violet, indigo, blue, very faint +green, white, faint yellow, orange, red. Thus it is by the computation: +And they that please to view the Colours made by a Prism will find it so +in Nature. + +These are the Colours on both sides the white when the Paper is held +between the Prism and the Point X where the Colours meet, and the +interjacent white vanishes. For if the Paper be held still farther off +from the Prism, the most refrangible and least refrangible Rays will be +wanting in the middle of the Light, and the rest of the Rays which are +found there, will by mixture produce a fuller green than before. Also +the yellow and blue will now become less compounded, and by consequence +more intense than before. And this also agrees with experience. + +And if one look through a Prism upon a white Object encompassed with +blackness or darkness, the reason of the Colours arising on the edges is +much the same, as will appear to one that shall a little consider it. If +a black Object be encompassed with a white one, the Colours which appear +through the Prism are to be derived from the Light of the white one, +spreading into the Regions of the black, and therefore they appear in a +contrary order to that, when a white Object is surrounded with black. +And the same is to be understood when an Object is viewed, whose parts +are some of them less luminous than others. For in the borders of the +more and less luminous Parts, Colours ought always by the same +Principles to arise from the Excess of the Light of the more luminous, +and to be of the same kind as if the darker parts were black, but yet to +be more faint and dilute. + +What is said of Colours made by Prisms may be easily applied to Colours +made by the Glasses of Telescopes or Microscopes, or by the Humours of +the Eye. For if the Object-glass of a Telescope be thicker on one side +than on the other, or if one half of the Glass, or one half of the Pupil +of the Eye be cover'd with any opake substance; the Object-glass, or +that part of it or of the Eye which is not cover'd, may be consider'd as +a Wedge with crooked Sides, and every Wedge of Glass or other pellucid +Substance has the effect of a Prism in refracting the Light which passes +through it.[L] + +How the Colours in the ninth and tenth Experiments of the first Part +arise from the different Reflexibility of Light, is evident by what was +there said. But it is observable in the ninth Experiment, that whilst +the Sun's direct Light is yellow, the Excess of the blue-making Rays in +the reflected beam of Light MN, suffices only to bring that yellow to a +pale white inclining to blue, and not to tinge it with a manifestly blue +Colour. To obtain therefore a better blue, I used instead of the yellow +Light of the Sun the white Light of the Clouds, by varying a little the +Experiment, as follows. + +[Illustration: FIG. 13.] + +_Exper._ 16 Let HFG [in _Fig._ 13.] represent a Prism in the open Air, +and S the Eye of the Spectator, viewing the Clouds by their Light coming +into the Prism at the Plane Side FIGK, and reflected in it by its Base +HEIG, and thence going out through its Plane Side HEFK to the Eye. And +when the Prism and Eye are conveniently placed, so that the Angles of +Incidence and Reflexion at the Base may be about 40 Degrees, the +Spectator will see a Bow MN of a blue Colour, running from one End of +the Base to the other, with the Concave Side towards him, and the Part +of the Base IMNG beyond this Bow will be brighter than the other Part +EMNH on the other Side of it. This blue Colour MN being made by nothing +else than by Reflexion of a specular Superficies, seems so odd a +Phænomenon, and so difficult to be explained by the vulgar Hypothesis of +Philosophers, that I could not but think it deserved to be taken Notice +of. Now for understanding the Reason of it, suppose the Plane ABC to cut +the Plane Sides and Base of the Prism perpendicularly. From the Eye to +the Line BC, wherein that Plane cuts the Base, draw the Lines S_p_ and +S_t_, in the Angles S_pc_ 50 degr. 1/9, and S_tc_ 49 degr. 1/28, and the +Point _p_ will be the Limit beyond which none of the most refrangible +Rays can pass through the Base of the Prism, and be refracted, whose +Incidence is such that they may be reflected to the Eye; and the Point +_t_ will be the like Limit for the least refrangible Rays, that is, +beyond which none of them can pass through the Base, whose Incidence is +such that by Reflexion they may come to the Eye. And the Point _r_ taken +in the middle Way between _p_ and _t_, will be the like Limit for the +meanly refrangible Rays. And therefore all the least refrangible Rays +which fall upon the Base beyond _t_, that is, between _t_ and B, and can +come from thence to the Eye, will be reflected thither: But on this side +_t_, that is, between _t_ and _c_, many of these Rays will be +transmitted through the Base. And all the most refrangible Rays which +fall upon the Base beyond _p_, that is, between, _p_ and B, and can by +Reflexion come from thence to the Eye, will be reflected thither, but +every where between _p_ and _c_, many of these Rays will get through the +Base, and be refracted; and the same is to be understood of the meanly +refrangible Rays on either side of the Point _r_. Whence it follows, +that the Base of the Prism must every where between _t_ and B, by a +total Reflexion of all sorts of Rays to the Eye, look white and bright. +And every where between _p_ and C, by reason of the Transmission of many +Rays of every sort, look more pale, obscure, and dark. But at _r_, and +in other Places between _p_ and _t_, where all the more refrangible Rays +are reflected to the Eye, and many of the less refrangible are +transmitted, the Excess of the most refrangible in the reflected Light +will tinge that Light with their Colour, which is violet and blue. And +this happens by taking the Line C _prt_ B any where between the Ends of +the Prism HG and EI. + + +_PROP._ IX. PROB. IV. + +_By the discovered Properties of Light to explain the Colours of the +Rain-bow._ + +[Illustration: FIG. 14.] + +This Bow never appears, but where it rains in the Sun-shine, and may be +made artificially by spouting up Water which may break aloft, and +scatter into Drops, and fall down like Rain. For the Sun shining upon +these Drops certainly causes the Bow to appear to a Spectator standing +in a due Position to the Rain and Sun. And hence it is now agreed upon, +that this Bow is made by Refraction of the Sun's Light in drops of +falling Rain. This was understood by some of the Antients, and of late +more fully discover'd and explain'd by the famous _Antonius de Dominis_ +Archbishop of _Spalato_, in his book _De Radiis Visûs & Lucis_, +published by his Friend _Bartolus_ at _Venice_, in the Year 1611, and +written above 20 Years before. For he teaches there how the interior Bow +is made in round Drops of Rain by two Refractions of the Sun's Light, +and one Reflexion between them, and the exterior by two Refractions, and +two sorts of Reflexions between them in each Drop of Water, and proves +his Explications by Experiments made with a Phial full of Water, and +with Globes of Glass filled with Water, and placed in the Sun to make +the Colours of the two Bows appear in them. The same Explication +_Des-Cartes_ hath pursued in his Meteors, and mended that of the +exterior Bow. But whilst they understood not the true Origin of Colours, +it's necessary to pursue it here a little farther. For understanding +therefore how the Bow is made, let a Drop of Rain, or any other +spherical transparent Body be represented by the Sphere BNFG, [in _Fig._ +14.] described with the Center C, and Semi-diameter CN. And let AN be +one of the Sun's Rays incident upon it at N, and thence refracted to F, +where let it either go out of the Sphere by Refraction towards V, or be +reflected to G; and at G let it either go out by Refraction to R, or be +reflected to H; and at H let it go out by Refraction towards S, cutting +the incident Ray in Y. Produce AN and RG, till they meet in X, and upon +AX and NF, let fall the Perpendiculars CD and CE, and produce CD till it +fall upon the Circumference at L. Parallel to the incident Ray AN draw +the Diameter BQ, and let the Sine of Incidence out of Air into Water be +to the Sine of Refraction as I to R. Now, if you suppose the Point of +Incidence N to move from the Point B, continually till it come to L, the +Arch QF will first increase and then decrease, and so will the Angle AXR +which the Rays AN and GR contain; and the Arch QF and Angle AXR will be +biggest when ND is to CN as sqrt(II - RR) to sqrt(3)RR, in which +case NE will be to ND as 2R to I. Also the Angle AYS, which the Rays AN +and HS contain will first decrease, and then increase and grow least +when ND is to CN as sqrt(II - RR) to sqrt(8)RR, in which case NE +will be to ND, as 3R to I. And so the Angle which the next emergent Ray +(that is, the emergent Ray after three Reflexions) contains with the +incident Ray AN will come to its Limit when ND is to CN as sqrt(II - +RR) to sqrt(15)RR, in which case NE will be to ND as 4R to I. And the +Angle which the Ray next after that Emergent, that is, the Ray emergent +after four Reflexions, contains with the Incident, will come to its +Limit, when ND is to CN as sqrt(II - RR) to sqrt(24)RR, in which +case NE will be to ND as 5R to I; and so on infinitely, the Numbers 3, +8, 15, 24, &c. being gather'd by continual Addition of the Terms of the +arithmetical Progression 3, 5, 7, 9, &c. The Truth of all this +Mathematicians will easily examine.[M] + +Now it is to be observed, that as when the Sun comes to his Tropicks, +Days increase and decrease but a very little for a great while together; +so when by increasing the distance CD, these Angles come to their +Limits, they vary their quantity but very little for some time together, +and therefore a far greater number of the Rays which fall upon all the +Points N in the Quadrant BL, shall emerge in the Limits of these Angles, +than in any other Inclinations. And farther it is to be observed, that +the Rays which differ in Refrangibility will have different Limits of +their Angles of Emergence, and by consequence according to their +different Degrees of Refrangibility emerge most copiously in different +Angles, and being separated from one another appear each in their proper +Colours. And what those Angles are may be easily gather'd from the +foregoing Theorem by Computation. + +For in the least refrangible Rays the Sines I and R (as was found above) +are 108 and 81, and thence by Computation the greatest Angle AXR will be +found 42 Degrees and 2 Minutes, and the least Angle AYS, 50 Degrees and +57 Minutes. And in the most refrangible Rays the Sines I and R are 109 +and 81, and thence by Computation the greatest Angle AXR will be found +40 Degrees and 17 Minutes, and the least Angle AYS 54 Degrees and 7 +Minutes. + +Suppose now that O [in _Fig._ 15.] is the Spectator's Eye, and OP a Line +drawn parallel to the Sun's Rays and let POE, POF, POG, POH, be Angles +of 40 Degr. 17 Min. 42 Degr. 2 Min. 50 Degr. 57 Min. and 54 Degr. 7 Min. +respectively, and these Angles turned about their common Side OP, shall +with their other Sides OE, OF; OG, OH, describe the Verges of two +Rain-bows AF, BE and CHDG. For if E, F, G, H, be drops placed any where +in the conical Superficies described by OE, OF, OG, OH, and be +illuminated by the Sun's Rays SE, SF, SG, SH; the Angle SEO being equal +to the Angle POE, or 40 Degr. 17 Min. shall be the greatest Angle in +which the most refrangible Rays can after one Reflexion be refracted to +the Eye, and therefore all the Drops in the Line OE shall send the most +refrangible Rays most copiously to the Eye, and thereby strike the +Senses with the deepest violet Colour in that Region. And in like +manner the Angle SFO being equal to the Angle POF, or 42 Degr. 2 Min. +shall be the greatest in which the least refrangible Rays after one +Reflexion can emerge out of the Drops, and therefore those Rays shall +come most copiously to the Eye from the Drops in the Line OF, and strike +the Senses with the deepest red Colour in that Region. And by the same +Argument, the Rays which have intermediate Degrees of Refrangibility +shall come most copiously from Drops between E and F, and strike the +Senses with the intermediate Colours, in the Order which their Degrees +of Refrangibility require, that is in the Progress from E to F, or from +the inside of the Bow to the outside in this order, violet, indigo, +blue, green, yellow, orange, red. But the violet, by the mixture of the +white Light of the Clouds, will appear faint and incline to purple. + +[Illustration: FIG. 15.] + +Again, the Angle SGO being equal to the Angle POG, or 50 Gr. 51 Min. +shall be the least Angle in which the least refrangible Rays can after +two Reflexions emerge out of the Drops, and therefore the least +refrangible Rays shall come most copiously to the Eye from the Drops in +the Line OG, and strike the Sense with the deepest red in that Region. +And the Angle SHO being equal to the Angle POH, or 54 Gr. 7 Min. shall +be the least Angle, in which the most refrangible Rays after two +Reflexions can emerge out of the Drops; and therefore those Rays shall +come most copiously to the Eye from the Drops in the Line OH, and strike +the Senses with the deepest violet in that Region. And by the same +Argument, the Drops in the Regions between G and H shall strike the +Sense with the intermediate Colours in the Order which their Degrees of +Refrangibility require, that is, in the Progress from G to H, or from +the inside of the Bow to the outside in this order, red, orange, yellow, +green, blue, indigo, violet. And since these four Lines OE, OF, OG, OH, +may be situated any where in the above-mention'd conical Superficies; +what is said of the Drops and Colours in these Lines is to be understood +of the Drops and Colours every where in those Superficies. + +Thus shall there be made two Bows of Colours, an interior and stronger, +by one Reflexion in the Drops, and an exterior and fainter by two; for +the Light becomes fainter by every Reflexion. And their Colours shall +lie in a contrary Order to one another, the red of both Bows bordering +upon the Space GF, which is between the Bows. The Breadth of the +interior Bow EOF measured cross the Colours shall be 1 Degr. 45 Min. and +the Breadth of the exterior GOH shall be 3 Degr. 10 Min. and the +distance between them GOF shall be 8 Gr. 15 Min. the greatest +Semi-diameter of the innermost, that is, the Angle POF being 42 Gr. 2 +Min. and the least Semi-diameter of the outermost POG, being 50 Gr. 57 +Min. These are the Measures of the Bows, as they would be were the Sun +but a Point; for by the Breadth of his Body, the Breadth of the Bows +will be increased, and their Distance decreased by half a Degree, and so +the breadth of the interior Iris will be 2 Degr. 15 Min. that of the +exterior 3 Degr. 40 Min. their distance 8 Degr. 25 Min. the greatest +Semi-diameter of the interior Bow 42 Degr. 17 Min. and the least of the +exterior 50 Degr. 42 Min. And such are the Dimensions of the Bows in the +Heavens found to be very nearly, when their Colours appear strong and +perfect. For once, by such means as I then had, I measured the greatest +Semi-diameter of the interior Iris about 42 Degrees, and the breadth of +the red, yellow and green in that Iris 63 or 64 Minutes, besides the +outmost faint red obscured by the brightness of the Clouds, for which we +may allow 3 or 4 Minutes more. The breadth of the blue was about 40 +Minutes more besides the violet, which was so much obscured by the +brightness of the Clouds, that I could not measure its breadth. But +supposing the breadth of the blue and violet together to equal that of +the red, yellow and green together, the whole breadth of this Iris will +be about 2-1/4 Degrees, as above. The least distance between this Iris +and the exterior Iris was about 8 Degrees and 30 Minutes. The exterior +Iris was broader than the interior, but so faint, especially on the blue +side, that I could not measure its breadth distinctly. At another time +when both Bows appeared more distinct, I measured the breadth of the +interior Iris 2 Gr. 10´, and the breadth of the red, yellow and green in +the exterior Iris, was to the breadth of the same Colours in the +interior as 3 to 2. + +This Explication of the Rain-bow is yet farther confirmed by the known +Experiment (made by _Antonius de Dominis_ and _Des-Cartes_) of hanging +up any where in the Sun-shine a Glass Globe filled with Water, and +viewing it in such a posture, that the Rays which come from the Globe to +the Eye may contain with the Sun's Rays an Angle of either 42 or 50 +Degrees. For if the Angle be about 42 or 43 Degrees, the Spectator +(suppose at O) shall see a full red Colour in that side of the Globe +opposed to the Sun as 'tis represented at F, and if that Angle become +less (suppose by depressing the Globe to E) there will appear other +Colours, yellow, green and blue successive in the same side of the +Globe. But if the Angle be made about 50 Degrees (suppose by lifting up +the Globe to G) there will appear a red Colour in that side of the Globe +towards the Sun, and if the Angle be made greater (suppose by lifting +up the Globe to H) the red will turn successively to the other Colours, +yellow, green and blue. The same thing I have tried, by letting a Globe +rest, and raising or depressing the Eye, or otherwise moving it to make +the Angle of a just magnitude. + +I have heard it represented, that if the Light of a Candle be refracted +by a Prism to the Eye; when the blue Colour falls upon the Eye, the +Spectator shall see red in the Prism, and when the red falls upon the +Eye he shall see blue; and if this were certain, the Colours of the +Globe and Rain-bow ought to appear in a contrary order to what we find. +But the Colours of the Candle being very faint, the mistake seems to +arise from the difficulty of discerning what Colours fall on the Eye. +For, on the contrary, I have sometimes had occasion to observe in the +Sun's Light refracted by a Prism, that the Spectator always sees that +Colour in the Prism which falls upon his Eye. And the same I have found +true also in Candle-light. For when the Prism is moved slowly from the +Line which is drawn directly from the Candle to the Eye, the red appears +first in the Prism and then the blue, and therefore each of them is seen +when it falls upon the Eye. For the red passes over the Eye first, and +then the blue. + +The Light which comes through drops of Rain by two Refractions without +any Reflexion, ought to appear strongest at the distance of about 26 +Degrees from the Sun, and to decay gradually both ways as the distance +from him increases and decreases. And the same is to be understood of +Light transmitted through spherical Hail-stones. And if the Hail be a +little flatted, as it often is, the Light transmitted may grow so strong +at a little less distance than that of 26 Degrees, as to form a Halo +about the Sun or Moon; which Halo, as often as the Hail-stones are duly +figured may be colour'd, and then it must be red within by the least +refrangible Rays, and blue without by the most refrangible ones, +especially if the Hail-stones have opake Globules of Snow in their +center to intercept the Light within the Halo (as _Hugenius_ has +observ'd) and make the inside thereof more distinctly defined than it +would otherwise be. For such Hail-stones, though spherical, by +terminating the Light by the Snow, may make a Halo red within and +colourless without, and darker in the red than without, as Halos used to +be. For of those Rays which pass close by the Snow the Rubriform will be +least refracted, and so come to the Eye in the directest Lines. + +The Light which passes through a drop of Rain after two Refractions, and +three or more Reflexions, is scarce strong enough to cause a sensible +Bow; but in those Cylinders of Ice by which _Hugenius_ explains the +_Parhelia_, it may perhaps be sensible. + + +_PROP._ X. PROB. V. + +_By the discovered Properties of Light to explain the permanent Colours +of Natural Bodies._ + +These Colours arise from hence, that some natural Bodies reflect some +sorts of Rays, others other sorts more copiously than the rest. Minium +reflects the least refrangible or red-making Rays most copiously, and +thence appears red. Violets reflect the most refrangible most copiously, +and thence have their Colour, and so of other Bodies. Every Body +reflects the Rays of its own Colour more copiously than the rest, and +from their excess and predominance in the reflected Light has its +Colour. + +_Exper._ 17. For if in the homogeneal Lights obtained by the solution of +the Problem proposed in the fourth Proposition of the first Part of this +Book, you place Bodies of several Colours, you will find, as I have +done, that every Body looks most splendid and luminous in the Light of +its own Colour. Cinnaber in the homogeneal red Light is most +resplendent, in the green Light it is manifestly less resplendent, and +in the blue Light still less. Indigo in the violet blue Light is most +resplendent, and its splendor is gradually diminish'd, as it is removed +thence by degrees through the green and yellow Light to the red. By a +Leek the green Light, and next that the blue and yellow which compound +green, are more strongly reflected than the other Colours red and +violet, and so of the rest. But to make these Experiments the more +manifest, such Bodies ought to be chosen as have the fullest and most +vivid Colours, and two of those Bodies are to be compared together. +Thus, for instance, if Cinnaber and _ultra_-marine blue, or some other +full blue be held together in the red homogeneal Light, they will both +appear red, but the Cinnaber will appear of a strongly luminous and +resplendent red, and the _ultra_-marine blue of a faint obscure and dark +red; and if they be held together in the blue homogeneal Light, they +will both appear blue, but the _ultra_-marine will appear of a strongly +luminous and resplendent blue, and the Cinnaber of a faint and dark +blue. Which puts it out of dispute that the Cinnaber reflects the red +Light much more copiously than the _ultra_-marine doth, and the +_ultra_-marine reflects the blue Light much more copiously than the +Cinnaber doth. The same Experiment may be tried successfully with red +Lead and Indigo, or with any other two colour'd Bodies, if due allowance +be made for the different strength or weakness of their Colour and +Light. + +And as the reason of the Colours of natural Bodies is evident by these +Experiments, so it is farther confirmed and put past dispute by the two +first Experiments of the first Part, whereby 'twas proved in such Bodies +that the reflected Lights which differ in Colours do differ also in +degrees of Refrangibility. For thence it's certain, that some Bodies +reflect the more refrangible, others the less refrangible Rays more +copiously. + +And that this is not only a true reason of these Colours, but even the +only reason, may appear farther from this Consideration, that the Colour +of homogeneal Light cannot be changed by the Reflexion of natural +Bodies. + +For if Bodies by Reflexion cannot in the least change the Colour of any +one sort of Rays, they cannot appear colour'd by any other means than by +reflecting those which either are of their own Colour, or which by +mixture must produce it. + +But in trying Experiments of this kind care must be had that the Light +be sufficiently homogeneal. For if Bodies be illuminated by the ordinary +prismatick Colours, they will appear neither of their own Day-light +Colours, nor of the Colour of the Light cast on them, but of some middle +Colour between both, as I have found by Experience. Thus red Lead (for +instance) illuminated with the ordinary prismatick green will not appear +either red or green, but orange or yellow, or between yellow and green, +accordingly as the green Light by which 'tis illuminated is more or less +compounded. For because red Lead appears red when illuminated with white +Light, wherein all sorts of Rays are equally mix'd, and in the green +Light all sorts of Rays are not equally mix'd, the Excess of the +yellow-making, green-making and blue-making Rays in the incident green +Light, will cause those Rays to abound so much in the reflected Light, +as to draw the Colour from red towards their Colour. And because the red +Lead reflects the red-making Rays most copiously in proportion to their +number, and next after them the orange-making and yellow-making Rays; +these Rays in the reflected Light will be more in proportion to the +Light than they were in the incident green Light, and thereby will draw +the reflected Light from green towards their Colour. And therefore the +red Lead will appear neither red nor green, but of a Colour between +both. + +In transparently colour'd Liquors 'tis observable, that their Colour +uses to vary with their thickness. Thus, for instance, a red Liquor in a +conical Glass held between the Light and the Eye, looks of a pale and +dilute yellow at the bottom where 'tis thin, and a little higher where +'tis thicker grows orange, and where 'tis still thicker becomes red, and +where 'tis thickest the red is deepest and darkest. For it is to be +conceiv'd that such a Liquor stops the indigo-making and violet-making +Rays most easily, the blue-making Rays more difficultly, the +green-making Rays still more difficultly, and the red-making most +difficultly: And that if the thickness of the Liquor be only so much as +suffices to stop a competent number of the violet-making and +indigo-making Rays, without diminishing much the number of the rest, the +rest must (by _Prop._ 6. _Part_ 2.) compound a pale yellow. But if the +Liquor be so much thicker as to stop also a great number of the +blue-making Rays, and some of the green-making, the rest must compound +an orange; and where it is so thick as to stop also a great number of +the green-making and a considerable number of the yellow-making, the +rest must begin to compound a red, and this red must grow deeper and +darker as the yellow-making and orange-making Rays are more and more +stopp'd by increasing the thickness of the Liquor, so that few Rays +besides the red-making can get through. + +Of this kind is an Experiment lately related to me by Mr. _Halley_, who, +in diving deep into the Sea in a diving Vessel, found in a clear +Sun-shine Day, that when he was sunk many Fathoms deep into the Water +the upper part of his Hand on which the Sun shone directly through the +Water and through a small Glass Window in the Vessel appeared of a red +Colour, like that of a Damask Rose, and the Water below and the under +part of his Hand illuminated by Light reflected from the Water below +look'd green. For thence it may be gather'd, that the Sea-Water reflects +back the violet and blue-making Rays most easily, and lets the +red-making Rays pass most freely and copiously to great Depths. For +thereby the Sun's direct Light at all great Depths, by reason of the +predominating red-making Rays, must appear red; and the greater the +Depth is, the fuller and intenser must that red be. And at such Depths +as the violet-making Rays scarce penetrate unto, the blue-making, +green-making, and yellow-making Rays being reflected from below more +copiously than the red-making ones, must compound a green. + +Now, if there be two Liquors of full Colours, suppose a red and blue, +and both of them so thick as suffices to make their Colours sufficiently +full; though either Liquor be sufficiently transparent apart, yet will +you not be able to see through both together. For, if only the +red-making Rays pass through one Liquor, and only the blue-making +through the other, no Rays can pass through both. This Mr. _Hook_ tried +casually with Glass Wedges filled with red and blue Liquors, and was +surprized at the unexpected Event, the reason of it being then unknown; +which makes me trust the more to his Experiment, though I have not tried +it my self. But he that would repeat it, must take care the Liquors be +of very good and full Colours. + +Now, whilst Bodies become coloured by reflecting or transmitting this or +that sort of Rays more copiously than the rest, it is to be conceived +that they stop and stifle in themselves the Rays which they do not +reflect or transmit. For, if Gold be foliated and held between your Eye +and the Light, the Light looks of a greenish blue, and therefore massy +Gold lets into its Body the blue-making Rays to be reflected to and fro +within it till they be stopp'd and stifled, whilst it reflects the +yellow-making outwards, and thereby looks yellow. And much after the +same manner that Leaf Gold is yellow by reflected, and blue by +transmitted Light, and massy Gold is yellow in all Positions of the Eye; +there are some Liquors, as the Tincture of _Lignum Nephriticum_, and +some sorts of Glass which transmit one sort of Light most copiously, and +reflect another sort, and thereby look of several Colours, according to +the Position of the Eye to the Light. But, if these Liquors or Glasses +were so thick and massy that no Light could get through them, I question +not but they would like all other opake Bodies appear of one and the +same Colour in all Positions of the Eye, though this I cannot yet affirm +by Experience. For all colour'd Bodies, so far as my Observation +reaches, may be seen through if made sufficiently thin, and therefore +are in some measure transparent, and differ only in degrees of +Transparency from tinged transparent Liquors; these Liquors, as well as +those Bodies, by a sufficient Thickness becoming opake. A transparent +Body which looks of any Colour by transmitted Light, may also look of +the same Colour by reflected Light, the Light of that Colour being +reflected by the farther Surface of the Body, or by the Air beyond it. +And then the reflected Colour will be diminished, and perhaps cease, by +making the Body very thick, and pitching it on the backside to diminish +the Reflexion of its farther Surface, so that the Light reflected from +the tinging Particles may predominate. In such Cases, the Colour of the +reflected Light will be apt to vary from that of the Light transmitted. +But whence it is that tinged Bodies and Liquors reflect some sort of +Rays, and intromit or transmit other sorts, shall be said in the next +Book. In this Proposition I content my self to have put it past dispute, +that Bodies have such Properties, and thence appear colour'd. + + +_PROP._ XI. PROB. VI. + +_By mixing colour'd Lights to compound a beam of Light of the same +Colour and Nature with a beam of the Sun's direct Light, and therein to +experience the Truth of the foregoing Propositions._ + +[Illustration: FIG. 16.] + +Let ABC _abc_ [in _Fig._ 16.] represent a Prism, by which the Sun's +Light let into a dark Chamber through the Hole F, may be refracted +towards the Lens MN, and paint upon it at _p_, _q_, _r_, _s_, and _t_, +the usual Colours violet, blue, green, yellow, and red, and let the +diverging Rays by the Refraction of this Lens converge again towards X, +and there, by the mixture of all those their Colours, compound a white +according to what was shewn above. Then let another Prism DEG _deg_, +parallel to the former, be placed at X, to refract that white Light +upwards towards Y. Let the refracting Angles of the Prisms, and their +distances from the Lens be equal, so that the Rays which converged from +the Lens towards X, and without Refraction, would there have crossed and +diverged again, may by the Refraction of the second Prism be reduced +into Parallelism and diverge no more. For then those Rays will recompose +a beam of white Light XY. If the refracting Angle of either Prism be the +bigger, that Prism must be so much the nearer to the Lens. You will know +when the Prisms and the Lens are well set together, by observing if the +beam of Light XY, which comes out of the second Prism be perfectly white +to the very edges of the Light, and at all distances from the Prism +continue perfectly and totally white like a beam of the Sun's Light. For +till this happens, the Position of the Prisms and Lens to one another +must be corrected; and then if by the help of a long beam of Wood, as is +represented in the Figure, or by a Tube, or some other such Instrument, +made for that Purpose, they be made fast in that Situation, you may try +all the same Experiments in this compounded beam of Light XY, which have +been made in the Sun's direct Light. For this compounded beam of Light +has the same appearance, and is endow'd with all the same Properties +with a direct beam of the Sun's Light, so far as my Observation reaches. +And in trying Experiments in this beam you may by stopping any of the +Colours, _p_, _q_, _r_, _s_, and _t_, at the Lens, see how the Colours +produced in the Experiments are no other than those which the Rays had +at the Lens before they entered the Composition of this Beam: And by +consequence, that they arise not from any new Modifications of the Light +by Refractions and Reflexions, but from the various Separations and +Mixtures of the Rays originally endow'd with their colour-making +Qualities. + +So, for instance, having with a Lens 4-1/4 Inches broad, and two Prisms +on either hand 6-1/4 Feet distant from the Lens, made such a beam of +compounded Light; to examine the reason of the Colours made by Prisms, I +refracted this compounded beam of Light XY with another Prism HIK _kh_, +and thereby cast the usual Prismatick Colours PQRST upon the Paper LV +placed behind. And then by stopping any of the Colours _p_, _q_, _r_, +_s_, _t_, at the Lens, I found that the same Colour would vanish at the +Paper. So if the Purple _p_ was stopp'd at the Lens, the Purple P upon +the Paper would vanish, and the rest of the Colours would remain +unalter'd, unless perhaps the blue, so far as some purple latent in it +at the Lens might be separated from it by the following Refractions. And +so by intercepting the green upon the Lens, the green R upon the Paper +would vanish, and so of the rest; which plainly shews, that as the white +beam of Light XY was compounded of several Lights variously colour'd at +the Lens, so the Colours which afterwards emerge out of it by new +Refractions are no other than those of which its Whiteness was +compounded. The Refraction of the Prism HIK _kh_ generates the Colours +PQRST upon the Paper, not by changing the colorific Qualities of the +Rays, but by separating the Rays which had the very same colorific +Qualities before they enter'd the Composition of the refracted beam of +white Light XY. For otherwise the Rays which were of one Colour at the +Lens might be of another upon the Paper, contrary to what we find. + +So again, to examine the reason of the Colours of natural Bodies, I +placed such Bodies in the Beam of Light XY, and found that they all +appeared there of those their own Colours which they have in Day-light, +and that those Colours depend upon the Rays which had the same Colours +at the Lens before they enter'd the Composition of that beam. Thus, for +instance, Cinnaber illuminated by this beam appears of the same red +Colour as in Day-light; and if at the Lens you intercept the +green-making and blue-making Rays, its redness will become more full and +lively: But if you there intercept the red-making Rays, it will not any +longer appear red, but become yellow or green, or of some other Colour, +according to the sorts of Rays which you do not intercept. So Gold in +this Light XY appears of the same yellow Colour as in Day-light, but by +intercepting at the Lens a due Quantity of the yellow-making Rays it +will appear white like Silver (as I have tried) which shews that its +yellowness arises from the Excess of the intercepted Rays tinging that +Whiteness with their Colour when they are let pass. So the Infusion of +_Lignum Nephriticum_ (as I have also tried) when held in this beam of +Light XY, looks blue by the reflected Part of the Light, and red by the +transmitted Part of it, as when 'tis view'd in Day-light; but if you +intercept the blue at the Lens the Infusion will lose its reflected blue +Colour, whilst its transmitted red remains perfect, and by the loss of +some blue-making Rays, wherewith it was allay'd, becomes more intense +and full. And, on the contrary, if the red and orange-making Rays be +intercepted at the Lens, the Infusion will lose its transmitted red, +whilst its blue will remain and become more full and perfect. Which +shews, that the Infusion does not tinge the Rays with blue and red, but +only transmits those most copiously which were red-making before, and +reflects those most copiously which were blue-making before. And after +the same manner may the Reasons of other Phænomena be examined, by +trying them in this artificial beam of Light XY. + +FOOTNOTES: + +[I] See p. 59. + +[J] _See our_ Author's Lect. Optic. _Part_ II. _Sect._ II. _p._ 239. + +[K] _As is done in our_ Author's Lect. Optic. _Part_ I. _Sect._ III. +_and_ IV. _and Part_ II. _Sect._ II. + +[L] _See our_ Author's Lect. Optic. _Part_ II. _Sect._ II. _pag._ 269, +&c. + +[M] _This is demonstrated in our_ Author's Lect. Optic. _Part_ I. +_Sect._ IV. _Prop._ 35 _and_ 36. + + + + +THE + +SECOND BOOK + +OF + +OPTICKS + + + + +_PART I._ + +_Observations concerning the Reflexions, Refractions, and Colours of +thin transparent Bodies._ + + +It has been observed by others, that transparent Substances, as Glass, +Water, Air, &c. when made very thin by being blown into Bubbles, or +otherwise formed into Plates, do exhibit various Colours according to +their various thinness, altho' at a greater thickness they appear very +clear and colourless. In the former Book I forbore to treat of these +Colours, because they seemed of a more difficult Consideration, and were +not necessary for establishing the Properties of Light there discoursed +of. But because they may conduce to farther Discoveries for compleating +the Theory of Light, especially as to the constitution of the parts of +natural Bodies, on which their Colours or Transparency depend; I have +here set down an account of them. To render this Discourse short and +distinct, I have first described the principal of my Observations, and +then consider'd and made use of them. The Observations are these. + +_Obs._ 1. Compressing two Prisms hard together that their sides (which +by chance were a very little convex) might somewhere touch one another: +I found the place in which they touched to become absolutely +transparent, as if they had there been one continued piece of Glass. For +when the Light fell so obliquely on the Air, which in other places was +between them, as to be all reflected; it seemed in that place of contact +to be wholly transmitted, insomuch that when look'd upon, it appeared +like a black or dark spot, by reason that little or no sensible Light +was reflected from thence, as from other places; and when looked through +it seemed (as it were) a hole in that Air which was formed into a thin +Plate, by being compress'd between the Glasses. And through this hole +Objects that were beyond might be seen distinctly, which could not at +all be seen through other parts of the Glasses where the Air was +interjacent. Although the Glasses were a little convex, yet this +transparent spot was of a considerable breadth, which breadth seemed +principally to proceed from the yielding inwards of the parts of the +Glasses, by reason of their mutual pressure. For by pressing them very +hard together it would become much broader than otherwise. + +_Obs._ 2. When the Plate of Air, by turning the Prisms about their +common Axis, became so little inclined to the incident Rays, that some +of them began to be transmitted, there arose in it many slender Arcs of +Colours which at first were shaped almost like the Conchoid, as you see +them delineated in the first Figure. And by continuing the Motion of the +Prisms, these Arcs increased and bended more and more about the said +transparent spot, till they were compleated into Circles or Rings +incompassing it, and afterwards continually grew more and more +contracted. + +[Illustration: FIG. 1.] + +These Arcs at their first appearance were of a violet and blue Colour, +and between them were white Arcs of Circles, which presently by +continuing the Motion of the Prisms became a little tinged in their +inward Limbs with red and yellow, and to their outward Limbs the blue +was adjacent. So that the order of these Colours from the central dark +spot, was at that time white, blue, violet; black, red, orange, yellow, +white, blue, violet, &c. But the yellow and red were much fainter than +the blue and violet. + +The Motion of the Prisms about their Axis being continued, these Colours +contracted more and more, shrinking towards the whiteness on either +side of it, until they totally vanished into it. And then the Circles in +those parts appear'd black and white, without any other Colours +intermix'd. But by farther moving the Prisms about, the Colours again +emerged out of the whiteness, the violet and blue at its inward Limb, +and at its outward Limb the red and yellow. So that now their order from +the central Spot was white, yellow, red; black; violet, blue, white, +yellow, red, &c. contrary to what it was before. + +_Obs._ 3. When the Rings or some parts of them appeared only black and +white, they were very distinct and well defined, and the blackness +seemed as intense as that of the central Spot. Also in the Borders of +the Rings, where the Colours began to emerge out of the whiteness, they +were pretty distinct, which made them visible to a very great multitude. +I have sometimes number'd above thirty Successions (reckoning every +black and white Ring for one Succession) and seen more of them, which by +reason of their smalness I could not number. But in other Positions of +the Prisms, at which the Rings appeared of many Colours, I could not +distinguish above eight or nine of them, and the Exterior of those were +very confused and dilute. + +In these two Observations to see the Rings distinct, and without any +other Colour than Black and white, I found it necessary to hold my Eye +at a good distance from them. For by approaching nearer, although in the +same inclination of my Eye to the Plane of the Rings, there emerged a +bluish Colour out of the white, which by dilating it self more and more +into the black, render'd the Circles less distinct, and left the white a +little tinged with red and yellow. I found also by looking through a +slit or oblong hole, which was narrower than the pupil of my Eye, and +held close to it parallel to the Prisms, I could see the Circles much +distincter and visible to a far greater number than otherwise. + +_Obs._ 4. To observe more nicely the order of the Colours which arose +out of the white Circles as the Rays became less and less inclined to +the Plate of Air; I took two Object-glasses, the one a Plano-convex for +a fourteen Foot Telescope, and the other a large double Convex for one +of about fifty Foot; and upon this, laying the other with its plane side +downwards, I pressed them slowly together, to make the Colours +successively emerge in the middle of the Circles, and then slowly lifted +the upper Glass from the lower to make them successively vanish again in +the same place. The Colour, which by pressing the Glasses together, +emerged last in the middle of the other Colours, would upon its first +appearance look like a Circle of a Colour almost uniform from the +circumference to the center and by compressing the Glasses still more, +grow continually broader until a new Colour emerged in its center, and +thereby it became a Ring encompassing that new Colour. And by +compressing the Glasses still more, the diameter of this Ring would +increase, and the breadth of its Orbit or Perimeter decrease until +another new Colour emerged in the center of the last: And so on until a +third, a fourth, a fifth, and other following new Colours successively +emerged there, and became Rings encompassing the innermost Colour, the +last of which was the black Spot. And, on the contrary, by lifting up +the upper Glass from the lower, the diameter of the Rings would +decrease, and the breadth of their Orbit increase, until their Colours +reached successively to the center; and then they being of a +considerable breadth, I could more easily discern and distinguish their +Species than before. And by this means I observ'd their Succession and +Quantity to be as followeth. + +Next to the pellucid central Spot made by the contact of the Glasses +succeeded blue, white, yellow, and red. The blue was so little in +quantity, that I could not discern it in the Circles made by the Prisms, +nor could I well distinguish any violet in it, but the yellow and red +were pretty copious, and seemed about as much in extent as the white, +and four or five times more than the blue. The next Circuit in order of +Colours immediately encompassing these were violet, blue, green, yellow, +and red: and these were all of them copious and vivid, excepting the +green, which was very little in quantity, and seemed much more faint and +dilute than the other Colours. Of the other four, the violet was the +least in extent, and the blue less than the yellow or red. The third +Circuit or Order was purple, blue, green, yellow, and red; in which the +purple seemed more reddish than the violet in the former Circuit, and +the green was much more conspicuous, being as brisk and copious as any +of the other Colours, except the yellow, but the red began to be a +little faded, inclining very much to purple. After this succeeded the +fourth Circuit of green and red. The green was very copious and lively, +inclining on the one side to blue, and on the other side to yellow. But +in this fourth Circuit there was neither violet, blue, nor yellow, and +the red was very imperfect and dirty. Also the succeeding Colours became +more and more imperfect and dilute, till after three or four revolutions +they ended in perfect whiteness. Their form, when the Glasses were most +compress'd so as to make the black Spot appear in the center, is +delineated in the second Figure; where _a_, _b_, _c_, _d_, _e_: _f_, +_g_, _h_, _i_, _k_: _l_, _m_, _n_, _o_, _p_: _q_, _r_: _s_, _t_: _v_, +_x_: _y_, _z_, denote the Colours reckon'd in order from the center, +black, blue, white, yellow, red: violet, blue, green, yellow, red: +purple, blue, green, yellow, red: green, red: greenish blue, red: +greenish blue, pale red: greenish blue, reddish white. + +[Illustration: FIG. 2.] + +_Obs._ 5. To determine the interval of the Glasses, or thickness of the +interjacent Air, by which each Colour was produced, I measured the +Diameters of the first six Rings at the most lucid part of their Orbits, +and squaring them, I found their Squares to be in the arithmetical +Progression of the odd Numbers, 1, 3, 5, 7, 9, 11. And since one of +these Glasses was plane, and the other spherical, their Intervals at +those Rings must be in the same Progression. I measured also the +Diameters of the dark or faint Rings between the more lucid Colours, and +found their Squares to be in the arithmetical Progression of the even +Numbers, 2, 4, 6, 8, 10, 12. And it being very nice and difficult to +take these measures exactly; I repeated them divers times at divers +parts of the Glasses, that by their Agreement I might be confirmed in +them. And the same method I used in determining some others of the +following Observations. + +_Obs._ 6. The Diameter of the sixth Ring at the most lucid part of its +Orbit was 58/100 parts of an Inch, and the Diameter of the Sphere on +which the double convex Object-glass was ground was about 102 Feet, and +hence I gathered the thickness of the Air or Aereal Interval of the +Glasses at that Ring. But some time after, suspecting that in making +this Observation I had not determined the Diameter of the Sphere with +sufficient accurateness, and being uncertain whether the Plano-convex +Glass was truly plane, and not something concave or convex on that side +which I accounted plane; and whether I had not pressed the Glasses +together, as I often did, to make them touch; (For by pressing such +Glasses together their parts easily yield inwards, and the Rings thereby +become sensibly broader than they would be, did the Glasses keep their +Figures.) I repeated the Experiment, and found the Diameter of the sixth +lucid Ring about 55/100 parts of an Inch. I repeated the Experiment also +with such an Object-glass of another Telescope as I had at hand. This +was a double Convex ground on both sides to one and the same Sphere, and +its Focus was distant from it 83-2/5 Inches. And thence, if the Sines of +Incidence and Refraction of the bright yellow Light be assumed in +proportion as 11 to 17, the Diameter of the Sphere to which the Glass +was figured will by computation be found 182 Inches. This Glass I laid +upon a flat one, so that the black Spot appeared in the middle of the +Rings of Colours without any other Pressure than that of the weight of +the Glass. And now measuring the Diameter of the fifth dark Circle as +accurately as I could, I found it the fifth part of an Inch precisely. +This Measure was taken with the points of a pair of Compasses on the +upper Surface on the upper Glass, and my Eye was about eight or nine +Inches distance from the Glass, almost perpendicularly over it, and the +Glass was 1/6 of an Inch thick, and thence it is easy to collect that +the true Diameter of the Ring between the Glasses was greater than its +measur'd Diameter above the Glasses in the Proportion of 80 to 79, or +thereabouts, and by consequence equal to 16/79 parts of an Inch, and its +true Semi-diameter equal to 8/79 parts. Now as the Diameter of the +Sphere (182 Inches) is to the Semi-diameter of this fifth dark Ring +(8/79 parts of an Inch) so is this Semi-diameter to the thickness of the +Air at this fifth dark Ring; which is therefore 32/567931 or +100/1774784. Parts of an Inch; and the fifth Part thereof, _viz._ the +1/88739 Part of an Inch, is the Thickness of the Air at the first of +these dark Rings. + +The same Experiment I repeated with another double convex Object-glass +ground on both sides to one and the same Sphere. Its Focus was distant +from it 168-1/2 Inches, and therefore the Diameter of that Sphere was +184 Inches. This Glass being laid upon the same plain Glass, the +Diameter of the fifth of the dark Rings, when the black Spot in their +Center appear'd plainly without pressing the Glasses, was by the measure +of the Compasses upon the upper Glass 121/600 Parts of an Inch, and by +consequence between the Glasses it was 1222/6000: For the upper Glass +was 1/8 of an Inch thick, and my Eye was distant from it 8 Inches. And a +third proportional to half this from the Diameter of the Sphere is +5/88850 Parts of an Inch. This is therefore the Thickness of the Air at +this Ring, and a fifth Part thereof, _viz._ the 1/88850th Part of an +Inch is the Thickness thereof at the first of the Rings, as above. + +I tried the same Thing, by laying these Object-glasses upon flat Pieces +of a broken Looking-glass, and found the same Measures of the Rings: +Which makes me rely upon them till they can be determin'd more +accurately by Glasses ground to larger Spheres, though in such Glasses +greater care must be taken of a true Plane. + +These Dimensions were taken, when my Eye was placed almost +perpendicularly over the Glasses, being about an Inch, or an Inch and a +quarter, distant from the incident Rays, and eight Inches distant from +the Glass; so that the Rays were inclined to the Glass in an Angle of +about four Degrees. Whence by the following Observation you will +understand, that had the Rays been perpendicular to the Glasses, the +Thickness of the Air at these Rings would have been less in the +Proportion of the Radius to the Secant of four Degrees, that is, of +10000 to 10024. Let the Thicknesses found be therefore diminish'd in +this Proportion, and they will become 1/88952 and 1/89063, or (to use +the nearest round Number) the 1/89000th Part of an Inch. This is the +Thickness of the Air at the darkest Part of the first dark Ring made by +perpendicular Rays; and half this Thickness multiplied by the +Progression, 1, 3, 5, 7, 9, 11, &c. gives the Thicknesses of the Air at +the most luminous Parts of all the brightest Rings, _viz._ 1/178000, +3/178000, 5/178000, 7/178000, &c. their arithmetical Means 2/178000, +4/178000, 6/178000, &c. being its Thicknesses at the darkest Parts of +all the dark ones. + +_Obs._ 7. The Rings were least, when my Eye was placed perpendicularly +over the Glasses in the Axis of the Rings: And when I view'd them +obliquely they became bigger, continually swelling as I removed my Eye +farther from the Axis. And partly by measuring the Diameter of the same +Circle at several Obliquities of my Eye, partly by other Means, as also +by making use of the two Prisms for very great Obliquities, I found its +Diameter, and consequently the Thickness of the Air at its Perimeter in +all those Obliquities to be very nearly in the Proportions express'd in +this Table. + +-------------------+--------------------+----------+---------- +Angle of Incidence |Angle of Refraction |Diameter |Thickness + on | into | of the | of the + the Air. | the Air. | Ring. | Air. +-------------------+--------------------+----------+---------- + Deg. Min. | | | + | | | + 00 00 | 00 00 | 10 | 10 + | | | + 06 26 | 10 00 | 10-1/13 | 10-2/13 + | | | + 12 45 | 20 00 | 10-1/3 | 10-2/3 + | | | + 18 49 | 30 00 | 10-3/4 | 11-1/2 + | | | + 24 30 | 40 00 | 11-2/5 | 13 + | | | + 29 37 | 50 00 | 12-1/2 | 15-1/2 + | | | + 33 58 | 60 00 | 14 | 20 + | | | + 35 47 | 65 00 | 15-1/4 | 23-1/4 + | | | + 37 19 | 70 00 | 16-4/5 | 28-1/4 + | | | + 38 33 | 75 00 | 19-1/4 | 37 + | | | + 39 27 | 80 00 | 22-6/7 | 52-1/4 + | | | + 40 00 | 85 00 | 29 | 84-1/12 + | | | + 40 11 | 90 00 | 35 | 122-1/2 +-------------------+--------------------+----------+---------- + +In the two first Columns are express'd the Obliquities of the incident +and emergent Rays to the Plate of the Air, that is, their Angles of +Incidence and Refraction. In the third Column the Diameter of any +colour'd Ring at those Obliquities is expressed in Parts, of which ten +constitute that Diameter when the Rays are perpendicular. And in the +fourth Column the Thickness of the Air at the Circumference of that Ring +is expressed in Parts, of which also ten constitute its Thickness when +the Rays are perpendicular. + +And from these Measures I seem to gather this Rule: That the Thickness +of the Air is proportional to the Secant of an Angle, whose Sine is a +certain mean Proportional between the Sines of Incidence and Refraction. +And that mean Proportional, so far as by these Measures I can determine +it, is the first of an hundred and six arithmetical mean Proportionals +between those Sines counted from the bigger Sine, that is, from the Sine +of Refraction when the Refraction is made out of the Glass into the +Plate of Air, or from the Sine of Incidence when the Refraction is made +out of the Plate of Air into the Glass. + +_Obs._ 8. The dark Spot in the middle of the Rings increased also by the +Obliquation of the Eye, although almost insensibly. But, if instead of +the Object-glasses the Prisms were made use of, its Increase was more +manifest when viewed so obliquely that no Colours appear'd about it. It +was least when the Rays were incident most obliquely on the interjacent +Air, and as the obliquity decreased it increased more and more until the +colour'd Rings appear'd, and then decreased again, but not so much as it +increased before. And hence it is evident, that the Transparency was +not only at the absolute Contact of the Glasses, but also where they had +some little Interval. I have sometimes observed the Diameter of that +Spot to be between half and two fifth parts of the Diameter of the +exterior Circumference of the red in the first Circuit or Revolution of +Colours when view'd almost perpendicularly; whereas when view'd +obliquely it hath wholly vanish'd and become opake and white like the +other parts of the Glass; whence it may be collected that the Glasses +did then scarcely, or not at all, touch one another, and that their +Interval at the perimeter of that Spot when view'd perpendicularly was +about a fifth or sixth part of their Interval at the circumference of +the said red. + +_Obs._ 9. By looking through the two contiguous Object-glasses, I found +that the interjacent Air exhibited Rings of Colours, as well by +transmitting Light as by reflecting it. The central Spot was now white, +and from it the order of the Colours were yellowish red; black, violet, +blue, white, yellow, red; violet, blue, green, yellow, red, &c. But +these Colours were very faint and dilute, unless when the Light was +trajected very obliquely through the Glasses: For by that means they +became pretty vivid. Only the first yellowish red, like the blue in the +fourth Observation, was so little and faint as scarcely to be discern'd. +Comparing the colour'd Rings made by Reflexion, with these made by +transmission of the Light; I found that white was opposite to black, red +to blue, yellow to violet, and green to a Compound of red and violet. +That is, those parts of the Glass were black when looked through, which +when looked upon appeared white, and on the contrary. And so those which +in one case exhibited blue, did in the other case exhibit red. And the +like of the other Colours. The manner you have represented in the third +Figure, where AB, CD, are the Surfaces of the Glasses contiguous at E, +and the black Lines between them are their Distances in arithmetical +Progression, and the Colours written above are seen by reflected Light, +and those below by Light transmitted (p. 209). + +_Obs._ 10. Wetting the Object-glasses a little at their edges, the Water +crept in slowly between them, and the Circles thereby became less and +the Colours more faint: Insomuch that as the Water crept along, one half +of them at which it first arrived would appear broken off from the other +half, and contracted into a less Room. By measuring them I found the +Proportions of their Diameters to the Diameters of the like Circles made +by Air to be about seven to eight, and consequently the Intervals of the +Glasses at like Circles, caused by those two Mediums Water and Air, are +as about three to four. Perhaps it may be a general Rule, That if any +other Medium more or less dense than Water be compress'd between the +Glasses, their Intervals at the Rings caused thereby will be to their +Intervals caused by interjacent Air, as the Sines are which measure the +Refraction made out of that Medium into Air. + +_Obs._ 11. When the Water was between the Glasses, if I pressed the +upper Glass variously at its edges to make the Rings move nimbly from +one place to another, a little white Spot would immediately follow the +center of them, which upon creeping in of the ambient Water into that +place would presently vanish. Its appearance was such as interjacent Air +would have caused, and it exhibited the same Colours. But it was not +air, for where any Bubbles of Air were in the Water they would not +vanish. The Reflexion must have rather been caused by a subtiler Medium, +which could recede through the Glasses at the creeping in of the Water. + +_Obs._ 12. These Observations were made in the open Air. But farther to +examine the Effects of colour'd Light falling on the Glasses, I darken'd +the Room, and view'd them by Reflexion of the Colours of a Prism cast on +a Sheet of white Paper, my Eye being so placed that I could see the +colour'd Paper by Reflexion in the Glasses, as in a Looking-glass. And +by this means the Rings became distincter and visible to a far greater +number than in the open Air. I have sometimes seen more than twenty of +them, whereas in the open Air I could not discern above eight or nine. + +[Illustration: FIG. 3.] + +_Obs._ 13. Appointing an Assistant to move the Prism to and fro about +its Axis, that all the Colours might successively fall on that part of +the Paper which I saw by Reflexion from that part of the Glasses, where +the Circles appear'd, so that all the Colours might be successively +reflected from the Circles to my Eye, whilst I held it immovable, I +found the Circles which the red Light made to be manifestly bigger than +those which were made by the blue and violet. And it was very pleasant +to see them gradually swell or contract accordingly as the Colour of the +Light was changed. The Interval of the Glasses at any of the Rings when +they were made by the utmost red Light, was to their Interval at the +same Ring when made by the utmost violet, greater than as 3 to 2, and +less than as 13 to 8. By the most of my Observations it was as 14 to 9. +And this Proportion seem'd very nearly the same in all Obliquities of my +Eye; unless when two Prisms were made use of instead of the +Object-glasses. For then at a certain great obliquity of my Eye, the +Rings made by the several Colours seem'd equal, and at a greater +obliquity those made by the violet would be greater than the same Rings +made by the red: the Refraction of the Prism in this case causing the +most refrangible Rays to fall more obliquely on that plate of the Air +than the least refrangible ones. Thus the Experiment succeeded in the +colour'd Light, which was sufficiently strong and copious to make the +Rings sensible. And thence it may be gather'd, that if the most +refrangible and least refrangible Rays had been copious enough to make +the Rings sensible without the mixture of other Rays, the Proportion +which here was 14 to 9 would have been a little greater, suppose 14-1/4 +or 14-1/3 to 9. + +_Obs._ 14. Whilst the Prism was turn'd about its Axis with an uniform +Motion, to make all the several Colours fall successively upon the +Object-glasses, and thereby to make the Rings contract and dilate: The +Contraction or Dilatation of each Ring thus made by the variation of its +Colour was swiftest in the red, and slowest in the violet, and in the +intermediate Colours it had intermediate degrees of Celerity. Comparing +the quantity of Contraction and Dilatation made by all the degrees of +each Colour, I found that it was greatest in the red; less in the +yellow, still less in the blue, and least in the violet. And to make as +just an Estimation as I could of the Proportions of their Contractions +or Dilatations, I observ'd that the whole Contraction or Dilatation of +the Diameter of any Ring made by all the degrees of red, was to that of +the Diameter of the same Ring made by all the degrees of violet, as +about four to three, or five to four, and that when the Light was of the +middle Colour between yellow and green, the Diameter of the Ring was +very nearly an arithmetical Mean between the greatest Diameter of the +same Ring made by the outmost red, and the least Diameter thereof made +by the outmost violet: Contrary to what happens in the Colours of the +oblong Spectrum made by the Refraction of a Prism, where the red is most +contracted, the violet most expanded, and in the midst of all the +Colours is the Confine of green and blue. And hence I seem to collect +that the thicknesses of the Air between the Glasses there, where the +Ring is successively made by the limits of the five principal Colours +(red, yellow, green, blue, violet) in order (that is, by the extreme +red, by the limit of red and yellow in the middle of the orange, by the +limit of yellow and green, by the limit of green and blue, by the limit +of blue and violet in the middle of the indigo, and by the extreme +violet) are to one another very nearly as the sixth lengths of a Chord +which found the Notes in a sixth Major, _sol_, _la_, _mi_, _fa_, _sol_, +_la_. But it agrees something better with the Observation to say, that +the thicknesses of the Air between the Glasses there, where the Rings +are successively made by the limits of the seven Colours, red, orange, +yellow, green, blue, indigo, violet in order, are to one another as the +Cube Roots of the Squares of the eight lengths of a Chord, which found +the Notes in an eighth, _sol_, _la_, _fa_, _sol_, _la_, _mi_, _fa_, +_sol_; that is, as the Cube Roots of the Squares of the Numbers, 1, 8/9, +5/6, 3/4, 2/3, 3/5, 9/16, 1/2. + +_Obs._ 15. These Rings were not of various Colours like those made in +the open Air, but appeared all over of that prismatick Colour only with +which they were illuminated. And by projecting the prismatick Colours +immediately upon the Glasses, I found that the Light which fell on the +dark Spaces which were between the Colour'd Rings was transmitted +through the Glasses without any variation of Colour. For on a white +Paper placed behind, it would paint Rings of the same Colour with those +which were reflected, and of the bigness of their immediate Spaces. And +from thence the origin of these Rings is manifest; namely, that the Air +between the Glasses, according to its various thickness, is disposed in +some places to reflect, and in others to transmit the Light of any one +Colour (as you may see represented in the fourth Figure) and in the same +place to reflect that of one Colour where it transmits that of another. + +[Illustration: FIG. 4.] + +_Obs._ 16. The Squares of the Diameters of these Rings made by any +prismatick Colour were in arithmetical Progression, as in the fifth +Observation. And the Diameter of the sixth Circle, when made by the +citrine yellow, and viewed almost perpendicularly was about 58/100 parts +of an Inch, or a little less, agreeable to the sixth Observation. + +The precedent Observations were made with a rarer thin Medium, +terminated by a denser, such as was Air or Water compress'd between two +Glasses. In those that follow are set down the Appearances of a denser +Medium thin'd within a rarer, such as are Plates of Muscovy Glass, +Bubbles of Water, and some other thin Substances terminated on all sides +with air. + +_Obs._ 17. If a Bubble be blown with Water first made tenacious by +dissolving a little Soap in it, 'tis a common Observation, that after a +while it will appear tinged with a great variety of Colours. To defend +these Bubbles from being agitated by the external Air (whereby their +Colours are irregularly moved one among another, so that no accurate +Observation can be made of them,) as soon as I had blown any of them I +cover'd it with a clear Glass, and by that means its Colours emerged in +a very regular order, like so many concentrick Rings encompassing the +top of the Bubble. And as the Bubble grew thinner by the continual +subsiding of the Water, these Rings dilated slowly and overspread the +whole Bubble, descending in order to the bottom of it, where they +vanish'd successively. In the mean while, after all the Colours were +emerged at the top, there grew in the center of the Rings a small round +black Spot, like that in the first Observation, which continually +dilated it self till it became sometimes more than 1/2 or 3/4 of an Inch +in breadth before the Bubble broke. At first I thought there had been no +Light reflected from the Water in that place, but observing it more +curiously, I saw within it several smaller round Spots, which appeared +much blacker and darker than the rest, whereby I knew that there was +some Reflexion at the other places which were not so dark as those +Spots. And by farther Tryal I found that I could see the Images of some +things (as of a Candle or the Sun) very faintly reflected, not only from +the great black Spot, but also from the little darker Spots which were +within it. + +Besides the aforesaid colour'd Rings there would often appear small +Spots of Colours, ascending and descending up and down the sides of the +Bubble, by reason of some Inequalities in the subsiding of the Water. +And sometimes small black Spots generated at the sides would ascend up +to the larger black Spot at the top of the Bubble, and unite with it. + +_Obs._ 18. Because the Colours of these Bubbles were more extended and +lively than those of the Air thinn'd between two Glasses, and so more +easy to be distinguish'd, I shall here give you a farther description of +their order, as they were observ'd in viewing them by Reflexion of the +Skies when of a white Colour, whilst a black substance was placed +behind the Bubble. And they were these, red, blue; red, blue; red, blue; +red, green; red, yellow, green, blue, purple; red, yellow, green, blue, +violet; red, yellow, white, blue, black. + +The three first Successions of red and blue were very dilute and dirty, +especially the first, where the red seem'd in a manner to be white. +Among these there was scarce any other Colour sensible besides red and +blue, only the blues (and principally the second blue) inclined a little +to green. + +The fourth red was also dilute and dirty, but not so much as the former +three; after that succeeded little or no yellow, but a copious green, +which at first inclined a little to yellow, and then became a pretty +brisk and good willow green, and afterwards changed to a bluish Colour; +but there succeeded neither blue nor violet. + +The fifth red at first inclined very much to purple, and afterwards +became more bright and brisk, but yet not very pure. This was succeeded +with a very bright and intense yellow, which was but little in quantity, +and soon chang'd to green: But that green was copious and something more +pure, deep and lively, than the former green. After that follow'd an +excellent blue of a bright Sky-colour, and then a purple, which was less +in quantity than the blue, and much inclined to red. + +The sixth red was at first of a very fair and lively scarlet, and soon +after of a brighter Colour, being very pure and brisk, and the best of +all the reds. Then after a lively orange follow'd an intense bright and +copious yellow, which was also the best of all the yellows, and this +changed first to a greenish yellow, and then to a greenish blue; but the +green between the yellow and the blue, was very little and dilute, +seeming rather a greenish white than a green. The blue which succeeded +became very good, and of a very bright Sky-colour, but yet something +inferior to the former blue; and the violet was intense and deep with +little or no redness in it. And less in quantity than the blue. + +In the last red appeared a tincture of scarlet next to violet, which +soon changed to a brighter Colour, inclining to an orange; and the +yellow which follow'd was at first pretty good and lively, but +afterwards it grew more dilute until by degrees it ended in perfect +whiteness. And this whiteness, if the Water was very tenacious and +well-temper'd, would slowly spread and dilate it self over the greater +part of the Bubble; continually growing paler at the top, where at +length it would crack in many places, and those cracks, as they dilated, +would appear of a pretty good, but yet obscure and dark Sky-colour; the +white between the blue Spots diminishing, until it resembled the Threds +of an irregular Net-work, and soon after vanish'd, and left all the +upper part of the Bubble of the said dark blue Colour. And this Colour, +after the aforesaid manner, dilated it self downwards, until sometimes +it hath overspread the whole Bubble. In the mean while at the top, which +was of a darker blue than the bottom, and appear'd also full of many +round blue Spots, something darker than the rest, there would emerge +one or more very black Spots, and within those, other Spots of an +intenser blackness, which I mention'd in the former Observation; and +these continually dilated themselves until the Bubble broke. + +If the Water was not very tenacious, the black Spots would break forth +in the white, without any sensible intervention of the blue. And +sometimes they would break forth within the precedent yellow, or red, or +perhaps within the blue of the second order, before the intermediate +Colours had time to display themselves. + +By this description you may perceive how great an affinity these Colours +have with those of Air described in the fourth Observation, although set +down in a contrary order, by reason that they begin to appear when the +Bubble is thickest, and are most conveniently reckon'd from the lowest +and thickest part of the Bubble upwards. + +_Obs._ 19. Viewing in several oblique Positions of my Eye the Rings of +Colours emerging on the top of the Bubble, I found that they were +sensibly dilated by increasing the obliquity, but yet not so much by far +as those made by thinn'd Air in the seventh Observation. For there they +were dilated so much as, when view'd most obliquely, to arrive at a part +of the Plate more than twelve times thicker than that where they +appear'd when viewed perpendicularly; whereas in this case the thickness +of the Water, at which they arrived when viewed most obliquely, was to +that thickness which exhibited them by perpendicular Rays, something +less than as 8 to 5. By the best of my Observations it was between 15 +and 15-1/2 to 10; an increase about 24 times less than in the other +case. + +Sometimes the Bubble would become of an uniform thickness all over, +except at the top of it near the black Spot, as I knew, because it would +exhibit the same appearance of Colours in all Positions of the Eye. And +then the Colours which were seen at its apparent circumference by the +obliquest Rays, would be different from those that were seen in other +places, by Rays less oblique to it. And divers Spectators might see the +same part of it of differing Colours, by viewing it at very differing +Obliquities. Now observing how much the Colours at the same places of +the Bubble, or at divers places of equal thickness, were varied by the +several Obliquities of the Rays; by the assistance of the 4th, 14th, +16th and 18th Observations, as they are hereafter explain'd, I collect +the thickness of the Water requisite to exhibit any one and the same +Colour, at several Obliquities, to be very nearly in the Proportion +expressed in this Table. + +-----------------+------------------+---------------- + Incidence on | Refraction into | Thickness of + the Water. | the Water. | the Water. +-----------------+------------------+---------------- + Deg. Min. | Deg. Min. | + | | + 00 00 | 00 00 | 10 + | | + 15 00 | 11 11 | 10-1/4 + | | + 30 00 | 22 1 | 10-4/5 + | | + 45 00 | 32 2 | 11-4/5 + | | + 60 00 | 40 30 | 13 + | | + 75 00 | 46 25 | 14-1/2 + | | + 90 00 | 48 35 | 15-1/5 +-----------------+------------------+---------------- + +In the two first Columns are express'd the Obliquities of the Rays to +the Superficies of the Water, that is, their Angles of Incidence and +Refraction. Where I suppose, that the Sines which measure them are in +round Numbers, as 3 to 4, though probably the Dissolution of Soap in the +Water, may a little alter its refractive Virtue. In the third Column, +the Thickness of the Bubble, at which any one Colour is exhibited in +those several Obliquities, is express'd in Parts, of which ten +constitute its Thickness when the Rays are perpendicular. And the Rule +found by the seventh Observation agrees well with these Measures, if +duly apply'd; namely, that the Thickness of a Plate of Water requisite +to exhibit one and the same Colour at several Obliquities of the Eye, is +proportional to the Secant of an Angle, whose Sine is the first of an +hundred and six arithmetical mean Proportionals between the Sines of +Incidence and Refraction counted from the lesser Sine, that is, from the +Sine of Refraction when the Refraction is made out of Air into Water, +otherwise from the Sine of Incidence. + +I have sometimes observ'd, that the Colours which arise on polish'd +Steel by heating it, or on Bell-metal, and some other metalline +Substances, when melted and pour'd on the Ground, where they may cool in +the open Air, have, like the Colours of Water-bubbles, been a little +changed by viewing them at divers Obliquities, and particularly that a +deep blue, or violet, when view'd very obliquely, hath been changed to a +deep red. But the Changes of these Colours are not so great and +sensible as of those made by Water. For the Scoria, or vitrified Part of +the Metal, which most Metals when heated or melted do continually +protrude, and send out to their Surface, and which by covering the +Metals in form of a thin glassy Skin, causes these Colours, is much +denser than Water; and I find that the Change made by the Obliquation of +the Eye is least in Colours of the densest thin Substances. + +_Obs._ 20. As in the ninth Observation, so here, the Bubble, by +transmitted Light, appear'd of a contrary Colour to that, which it +exhibited by Reflexion. Thus when the Bubble being look'd on by the +Light of the Clouds reflected from it, seemed red at its apparent +Circumference, if the Clouds at the same time, or immediately after, +were view'd through it, the Colour at its Circumference would be blue. +And, on the contrary, when by reflected Light it appeared blue, it would +appear red by transmitted Light. + +_Obs._ 21. By wetting very thin Plates of _Muscovy_ Glass, whose +thinness made the like Colours appear, the Colours became more faint and +languid, especially by wetting the Plates on that side opposite to the +Eye: But I could not perceive any variation of their Species. So then +the thickness of a Plate requisite to produce any Colour, depends only +on the density of the Plate, and not on that of the ambient Medium. And +hence, by the 10th and 16th Observations, may be known the thickness +which Bubbles of Water, or Plates of _Muscovy_ Glass, or other +Substances, have at any Colour produced by them. + +_Obs._ 22. A thin transparent Body, which is denser than its ambient +Medium, exhibits more brisk and vivid Colours than that which is so much +rarer; as I have particularly observed in the Air and Glass. For blowing +Glass very thin at a Lamp Furnace, those Plates encompassed with Air did +exhibit Colours much more vivid than those of Air made thin between two +Glasses. + +_Obs._ 23. Comparing the quantity of Light reflected from the several +Rings, I found that it was most copious from the first or inmost, and in +the exterior Rings became gradually less and less. Also the whiteness of +the first Ring was stronger than that reflected from those parts of the +thin Medium or Plate which were without the Rings; as I could manifestly +perceive by viewing at a distance the Rings made by the two +Object-glasses; or by comparing two Bubbles of Water blown at distant +Times, in the first of which the Whiteness appear'd, which succeeded all +the Colours, and in the other, the Whiteness which preceded them all. + +_Obs._ 24. When the two Object-glasses were lay'd upon one another, so +as to make the Rings of the Colours appear, though with my naked Eye I +could not discern above eight or nine of those Rings, yet by viewing +them through a Prism I have seen a far greater Multitude, insomuch that +I could number more than forty, besides many others, that were so very +small and close together, that I could not keep my Eye steady on them +severally so as to number them, but by their Extent I have sometimes +estimated them to be more than an hundred. And I believe the Experiment +may be improved to the Discovery of far greater Numbers. For they seem +to be really unlimited, though visible only so far as they can be +separated by the Refraction of the Prism, as I shall hereafter explain. + +[Illustration: FIG. 5.] + +But it was but one side of these Rings, namely, that towards which the +Refraction was made, which by that Refraction was render'd distinct, and +the other side became more confused than when view'd by the naked Eye, +insomuch that there I could not discern above one or two, and sometimes +none of those Rings, of which I could discern eight or nine with my +naked Eye. And their Segments or Arcs, which on the other side appear'd +so numerous, for the most part exceeded not the third Part of a Circle. +If the Refraction was very great, or the Prism very distant from the +Object-glasses, the middle Part of those Arcs became also confused, so +as to disappear and constitute an even Whiteness, whilst on either side +their Ends, as also the whole Arcs farthest from the Center, became +distincter than before, appearing in the Form as you see them design'd +in the fifth Figure. + +The Arcs, where they seem'd distinctest, were only white and black +successively, without any other Colours intermix'd. But in other Places +there appeared Colours, whose Order was inverted by the refraction in +such manner, that if I first held the Prism very near the +Object-glasses, and then gradually removed it farther off towards my +Eye, the Colours of the 2d, 3d, 4th, and following Rings, shrunk towards +the white that emerged between them, until they wholly vanish'd into it +at the middle of the Arcs, and afterwards emerged again in a contrary +Order. But at the Ends of the Arcs they retain'd their Order unchanged. + +I have sometimes so lay'd one Object-glass upon the other, that to the +naked Eye they have all over seem'd uniformly white, without the least +Appearance of any of the colour'd Rings; and yet by viewing them through +a Prism, great Multitudes of those Rings have discover'd themselves. And +in like manner Plates of _Muscovy_ Glass, and Bubbles of Glass blown at +a Lamp-Furnace, which were not so thin as to exhibit any Colours to the +naked Eye, have through the Prism exhibited a great Variety of them +ranged irregularly up and down in the Form of Waves. And so Bubbles of +Water, before they began to exhibit their Colours to the naked Eye of a +Bystander, have appeared through a Prism, girded about with many +parallel and horizontal Rings; to produce which Effect, it was necessary +to hold the Prism parallel, or very nearly parallel to the Horizon, and +to dispose it so that the Rays might be refracted upwards. + + + + +THE + +SECOND BOOK + +OF + +OPTICKS + + +_PART II._ + +_Remarks upon the foregoing Observations._ + + +Having given my Observations of these Colours, before I make use of them +to unfold the Causes of the Colours of natural Bodies, it is convenient +that by the simplest of them, such as are the 2d, 3d, 4th, 9th, 12th, +18th, 20th, and 24th, I first explain the more compounded. And first to +shew how the Colours in the fourth and eighteenth Observations are +produced, let there be taken in any Right Line from the Point Y, [in +_Fig._ 6.] the Lengths YA, YB, YC, YD, YE, YF, YG, YH, in proportion to +one another, as the Cube-Roots of the Squares of the Numbers, 1/2, 9/16, +3/5, 2/3, 3/4, 5/6, 8/9, 1, whereby the Lengths of a Musical Chord to +sound all the Notes in an eighth are represented; that is, in the +Proportion of the Numbers 6300, 6814, 7114, 7631, 8255, 8855, 9243, +10000. And at the Points A, B, C, D, E, F, G, H, let Perpendiculars +A[Greek: a], B[Greek: b], &c. be erected, by whose Intervals the Extent +of the several Colours set underneath against them, is to be +represented. Then divide the Line _A[Greek: a]_ in such Proportion as +the Numbers 1, 2, 3, 5, 6, 7, 9, 10, 11, &c. set at the Points of +Division denote. And through those Divisions from Y draw Lines 1I, 2K, +3L, 5M, 6N, 7O, &c. + +Now, if A2 be supposed to represent the Thickness of any thin +transparent Body, at which the outmost Violet is most copiously +reflected in the first Ring, or Series of Colours, then by the 13th +Observation, HK will represent its Thickness, at which the utmost Red is +most copiously reflected in the same Series. Also by the 5th and 16th +Observations, A6 and HN will denote the Thicknesses at which those +extreme Colours are most copiously reflected in the second Series, and +A10 and HQ the Thicknesses at which they are most copiously reflected in +the third Series, and so on. And the Thickness at which any of the +intermediate Colours are reflected most copiously, will, according to +the 14th Observation, be defined by the distance of the Line AH from the +intermediate parts of the Lines 2K, 6N, 10Q, &c. against which the Names +of those Colours are written below. + +[Illustration: FIG. 6.] + +But farther, to define the Latitude of these Colours in each Ring or +Series, let A1 design the least thickness, and A3 the greatest +thickness, at which the extreme violet in the first Series is reflected, +and let HI, and HL, design the like limits for the extreme red, and let +the intermediate Colours be limited by the intermediate parts of the +Lines 1I, and 3L, against which the Names of those Colours are written, +and so on: But yet with this caution, that the Reflexions be supposed +strongest at the intermediate Spaces, 2K, 6N, 10Q, &c. and from thence +to decrease gradually towards these limits, 1I, 3L, 5M, 7O, &c. on +either side; where you must not conceive them to be precisely limited, +but to decay indefinitely. And whereas I have assign'd the same Latitude +to every Series, I did it, because although the Colours in the first +Series seem to be a little broader than the rest, by reason of a +stronger Reflexion there, yet that inequality is so insensible as +scarcely to be determin'd by Observation. + +Now according to this Description, conceiving that the Rays originally +of several Colours are by turns reflected at the Spaces 1I, L3, 5M, O7, +9PR11, &c. and transmitted at the Spaces AHI1, 3LM5, 7OP9, &c. it is +easy to know what Colour must in the open Air be exhibited at any +thickness of a transparent thin Body. For if a Ruler be applied parallel +to AH, at that distance from it by which the thickness of the Body is +represented, the alternate Spaces 1IL3, 5MO7, &c. which it crosseth will +denote the reflected original Colours, of which the Colour exhibited in +the open Air is compounded. Thus if the constitution of the green in the +third Series of Colours be desired, apply the Ruler as you see at +[Greek: prsph], and by its passing through some of the blue at [Greek: +p] and yellow at [Greek: s], as well as through the green at [Greek: r], +you may conclude that the green exhibited at that thickness of the Body +is principally constituted of original green, but not without a mixture +of some blue and yellow. + +By this means you may know how the Colours from the center of the Rings +outward ought to succeed in order as they were described in the 4th and +18th Observations. For if you move the Ruler gradually from AH through +all distances, having pass'd over the first Space which denotes little +or no Reflexion to be made by thinnest Substances, it will first arrive +at 1 the violet, and then very quickly at the blue and green, which +together with that violet compound blue, and then at the yellow and red, +by whose farther addition that blue is converted into whiteness, which +whiteness continues during the transit of the edge of the Ruler from I +to 3, and after that by the successive deficience of its component +Colours, turns first to compound yellow, and then to red, and last of +all the red ceaseth at L. Then begin the Colours of the second Series, +which succeed in order during the transit of the edge of the Ruler from +5 to O, and are more lively than before, because more expanded and +severed. And for the same reason instead of the former white there +intercedes between the blue and yellow a mixture of orange, yellow, +green, blue and indigo, all which together ought to exhibit a dilute and +imperfect green. So the Colours of the third Series all succeed in +order; first, the violet, which a little interferes with the red of the +second order, and is thereby inclined to a reddish purple; then the blue +and green, which are less mix'd with other Colours, and consequently +more lively than before, especially the green: Then follows the yellow, +some of which towards the green is distinct and good, but that part of +it towards the succeeding red, as also that red is mix'd with the violet +and blue of the fourth Series, whereby various degrees of red very much +inclining to purple are compounded. This violet and blue, which should +succeed this red, being mixed with, and hidden in it, there succeeds a +green. And this at first is much inclined to blue, but soon becomes a +good green, the only unmix'd and lively Colour in this fourth Series. +For as it verges towards the yellow, it begins to interfere with the +Colours of the fifth Series, by whose mixture the succeeding yellow and +red are very much diluted and made dirty, especially the yellow, which +being the weaker Colour is scarce able to shew it self. After this the +several Series interfere more and more, and their Colours become more +and more intermix'd, till after three or four more revolutions (in which +the red and blue predominate by turns) all sorts of Colours are in all +places pretty equally blended, and compound an even whiteness. + +And since by the 15th Observation the Rays endued with one Colour are +transmitted, where those of another Colour are reflected, the reason of +the Colours made by the transmitted Light in the 9th and 20th +Observations is from hence evident. + +If not only the Order and Species of these Colours, but also the precise +thickness of the Plate, or thin Body at which they are exhibited, be +desired in parts of an Inch, that may be also obtained by assistance of +the 6th or 16th Observations. For according to those Observations the +thickness of the thinned Air, which between two Glasses exhibited the +most luminous parts of the first six Rings were 1/178000, 3/178000, +5/178000, 7/178000, 9/178000, 11/178000 parts of an Inch. Suppose the +Light reflected most copiously at these thicknesses be the bright +citrine yellow, or confine of yellow and orange, and these thicknesses +will be F[Greek: l], F[Greek: m], F[Greek: u], F[Greek: x], F[Greek: o], +F[Greek: t]. And this being known, it is easy to determine what +thickness of Air is represented by G[Greek: ph], or by any other +distance of the Ruler from AH. + +But farther, since by the 10th Observation the thickness of Air was to +the thickness of Water, which between the same Glasses exhibited the +same Colour, as 4 to 3, and by the 21st Observation the Colours of thin +Bodies are not varied by varying the ambient Medium; the thickness of a +Bubble of Water, exhibiting any Colour, will be 3/4 of the thickness of +Air producing the same Colour. And so according to the same 10th and +21st Observations, the thickness of a Plate of Glass, whose Refraction +of the mean refrangible Ray, is measured by the proportion of the Sines +31 to 20, may be 20/31 of the thickness of Air producing the same +Colours; and the like of other Mediums. I do not affirm, that this +proportion of 20 to 31, holds in all the Rays; for the Sines of other +sorts of Rays have other Proportions. But the differences of those +Proportions are so little that I do not here consider them. On these +Grounds I have composed the following Table, wherein the thickness of +Air, Water, and Glass, at which each Colour is most intense and +specifick, is expressed in parts of an Inch divided into ten hundred +thousand equal parts. + +Now if this Table be compared with the 6th Scheme, you will there see +the constitution of each Colour, as to its Ingredients, or the original +Colours of which it is compounded, and thence be enabled to judge of its +Intenseness or Imperfection; which may suffice in explication of the 4th +and 18th Observations, unless it be farther desired to delineate the +manner how the Colours appear, when the two Object-glasses are laid upon +one another. To do which, let there be described a large Arc of a +Circle, and a streight Line which may touch that Arc, and parallel to +that Tangent several occult Lines, at such distances from it, as the +Numbers set against the several Colours in the Table denote. For the +Arc, and its Tangent, will represent the Superficies of the Glasses +terminating the interjacent Air; and the places where the occult Lines +cut the Arc will show at what distances from the center, or Point of +contact, each Colour is reflected. + +_The thickness of colour'd Plates and Particles of_ + _____________|_______________ + / \ + Air. Water. Glass. + |---------+----------+----------+ + {Very black | 1/2 | 3/8 | 10/31 | + {Black | 1 | 3/4 | 20/31 | + {Beginning of | | | | + { Black | 2 | 1-1/2 | 1-2/7 | +Their Colours of the {Blue | 2-2/5 | 1-4/5 | 1-11/22 | +first Order, {White | 5-1/4 | 3-7/8 | 3-2/5 | + {Yellow | 7-1/9 | 5-1/3 | 4-3/5 | + {Orange | 8 | 6 | 5-1/6 | + {Red | 9 | 6-3/4 | 5-4/5 | + |---------+----------+----------| + {Violet | 11-1/6 | 8-3/8 | 7-1/5 | + {Indigo | 12-5/6 | 9-5/8 | 8-2/11 | + {Blue | 14 | 10-1/2 | 9 | + {Green | 15-1/8 | 11-2/3 | 9-5/7 | +Of the second order, {Yellow | 16-2/7 | 12-1/5 | 10-2/5 | + {Orange | 17-2/9 | 13 | 11-1/9 | + {Bright red | 18-1/3 | 13-3/4 | 11-5/6 | + {Scarlet | 19-2/3 | 14-3/4 | 12-2/3 | + |---------+----------+----------| + {Purple | 21 | 15-3/4 | 13-11/20 | + {Indigo | 22-1/10 | 16-4/7 | 14-1/4 | + {Blue | 23-2/5 | 17-11/20 | 15-1/10 | +Of the third Order, {Green | 25-1/5 | 18-9/10 | 16-1/4 | + {Yellow | 27-1/7 | 20-1/3 | 17-1/2 | + {Red | 29 | 21-3/4 | 18-5/7 | + {Bluish red | 32 | 24 | 20-2/3 | + |---------+----------+----------| + {Bluish green | 34 | 25-1/2 | 22 | + {Green | 35-2/7 | 26-1/2 | 22-3/4 | +Of the fourth Order, {Yellowish green | 36 | 27 | 23-2/9 | + {Red | 40-1/3 | 30-1/4 | 26 | + |---------+----------+----------| + {Greenish blue | 46 | 34-1/2 | 29-2/3 | +Of the fifth Order, {Red | 52-1/2 | 39-3/8 | 34 | + |---------+----------+----------| + {Greenish blue | 58-3/4 | 44 | 38 | +Of the sixth Order, {Red | 65 | 48-3/4 | 42 | + |---------+----------+----------| +Of the seventh Order, {Greenish blue | 71 | 53-1/4 | 45-4/5 | + {Ruddy White | 77 | 57-3/4 | 49-2/3 | + |---------+----------+----------| + +There are also other Uses of this Table: For by its assistance the +thickness of the Bubble in the 19th Observation was determin'd by the +Colours which it exhibited. And so the bigness of the parts of natural +Bodies may be conjectured by their Colours, as shall be hereafter shewn. +Also, if two or more very thin Plates be laid one upon another, so as to +compose one Plate equalling them all in thickness, the resulting Colour +may be hereby determin'd. For instance, Mr. _Hook_ observed, as is +mentioned in his _Micrographia_, that a faint yellow Plate of _Muscovy_ +Glass laid upon a blue one, constituted a very deep purple. The yellow +of the first Order is a faint one, and the thickness of the Plate +exhibiting it, according to the Table is 4-3/5, to which add 9, the +thickness exhibiting blue of the second Order, and the Sum will be +13-3/5, which is the thickness exhibiting the purple of the third Order. + +To explain, in the next place, the circumstances of the 2d and 3d +Observations; that is, how the Rings of the Colours may (by turning the +Prisms about their common Axis the contrary way to that expressed in +those Observations) be converted into white and black Rings, and +afterwards into Rings of Colours again, the Colours of each Ring lying +now in an inverted order; it must be remember'd, that those Rings of +Colours are dilated by the obliquation of the Rays to the Air which +intercedes the Glasses, and that according to the Table in the 7th +Observation, their Dilatation or Increase of their Diameter is most +manifest and speedy when they are obliquest. Now the Rays of yellow +being more refracted by the first Superficies of the said Air than those +of red, are thereby made more oblique to the second Superficies, at +which they are reflected to produce the colour'd Rings, and consequently +the yellow Circle in each Ring will be more dilated than the red; and +the Excess of its Dilatation will be so much the greater, by how much +the greater is the obliquity of the Rays, until at last it become of +equal extent with the red of the same Ring. And for the same reason the +green, blue and violet, will be also so much dilated by the still +greater obliquity of their Rays, as to become all very nearly of equal +extent with the red, that is, equally distant from the center of the +Rings. And then all the Colours of the same Ring must be co-incident, +and by their mixture exhibit a white Ring. And these white Rings must +have black and dark Rings between them, because they do not spread and +interfere with one another, as before. And for that reason also they +must become distincter, and visible to far greater numbers. But yet the +violet being obliquest will be something more dilated, in proportion to +its extent, than the other Colours, and so very apt to appear at the +exterior Verges of the white. + +Afterwards, by a greater obliquity of the Rays, the violet and blue +become more sensibly dilated than the red and yellow, and so being +farther removed from the center of the Rings, the Colours must emerge +out of the white in an order contrary to that which they had before; the +violet and blue at the exterior Limbs of each Ring, and the red and +yellow at the interior. And the violet, by reason of the greatest +obliquity of its Rays, being in proportion most of all expanded, will +soonest appear at the exterior Limb of each white Ring, and become more +conspicuous than the rest. And the several Series of Colours belonging +to the several Rings, will, by their unfolding and spreading, begin +again to interfere, and thereby render the Rings less distinct, and not +visible to so great numbers. + +If instead of the Prisms the Object-glasses be made use of, the Rings +which they exhibit become not white and distinct by the obliquity of the +Eye, by reason that the Rays in their passage through that Air which +intercedes the Glasses are very nearly parallel to those Lines in which +they were first incident on the Glasses, and consequently the Rays +endued with several Colours are not inclined one more than another to +that Air, as it happens in the Prisms. + +There is yet another circumstance of these Experiments to be consider'd, +and that is why the black and white Rings which when view'd at a +distance appear distinct, should not only become confused by viewing +them near at hand, but also yield a violet Colour at both the edges of +every white Ring. And the reason is, that the Rays which enter the Eye +at several parts of the Pupil, have several Obliquities to the Glasses, +and those which are most oblique, if consider'd apart, would represent +the Rings bigger than those which are the least oblique. Whence the +breadth of the Perimeter of every white Ring is expanded outwards by the +obliquest Rays, and inwards by the least oblique. And this Expansion is +so much the greater by how much the greater is the difference of the +Obliquity; that is, by how much the Pupil is wider, or the Eye nearer to +the Glasses. And the breadth of the violet must be most expanded, +because the Rays apt to excite a Sensation of that Colour are most +oblique to a second or farther Superficies of the thinn'd Air at which +they are reflected, and have also the greatest variation of Obliquity, +which makes that Colour soonest emerge out of the edges of the white. +And as the breadth of every Ring is thus augmented, the dark Intervals +must be diminish'd, until the neighbouring Rings become continuous, and +are blended, the exterior first, and then those nearer the center; so +that they can no longer be distinguish'd apart, but seem to constitute +an even and uniform whiteness. + +Among all the Observations there is none accompanied with so odd +circumstances as the twenty-fourth. Of those the principal are, that in +thin Plates, which to the naked Eye seem of an even and uniform +transparent whiteness, without any terminations of Shadows, the +Refraction of a Prism should make Rings of Colours appear, whereas it +usually makes Objects appear colour'd only there where they are +terminated with Shadows, or have parts unequally luminous; and that it +should make those Rings exceedingly distinct and white, although it +usually renders Objects confused and coloured. The Cause of these things +you will understand by considering, that all the Rings of Colours are +really in the Plate, when view'd with the naked Eye, although by reason +of the great breadth of their Circumferences they so much interfere and +are blended together, that they seem to constitute an uniform whiteness. +But when the Rays pass through the Prism to the Eye, the Orbits of the +several Colours in every Ring are refracted, some more than others, +according to their degrees of Refrangibility: By which means the Colours +on one side of the Ring (that is in the circumference on one side of its +center), become more unfolded and dilated, and those on the other side +more complicated and contracted. And where by a due Refraction they are +so much contracted, that the several Rings become narrower than to +interfere with one another, they must appear distinct, and also white, +if the constituent Colours be so much contracted as to be wholly +co-incident. But on the other side, where the Orbit of every Ring is +made broader by the farther unfolding of its Colours, it must interfere +more with other Rings than before, and so become less distinct. + +[Illustration: FIG. 7.] + +To explain this a little farther, suppose the concentrick Circles AV, +and BX, [in _Fig._ 7.] represent the red and violet of any Order, which, +together with the intermediate Colours, constitute any one of these +Rings. Now these being view'd through a Prism, the violet Circle BX, +will, by a greater Refraction, be farther translated from its place than +the red AV, and so approach nearer to it on that side of the Circles, +towards which the Refractions are made. For instance, if the red be +translated to _av_, the violet may be translated to _bx_, so as to +approach nearer to it at _x_ than before; and if the red be farther +translated to av, the violet may be so much farther translated to bx as +to convene with it at x; and if the red be yet farther translated to +[Greek: aY], the violet may be still so much farther translated to +[Greek: bx] as to pass beyond it at [Greek: x], and convene with it at +_e_ and _f_. And this being understood not only of the red and violet, +but of all the other intermediate Colours, and also of every revolution +of those Colours, you will easily perceive how those of the same +revolution or order, by their nearness at _xv_ and [Greek: Yx], and +their coincidence at xv, _e_ and _f_, ought to constitute pretty +distinct Arcs of Circles, especially at xv, or at _e_ and _f_; and that +they will appear severally at _x_[Greek: u] and at xv exhibit whiteness +by their coincidence, and again appear severally at [Greek: Yx], but yet +in a contrary order to that which they had before, and still retain +beyond _e_ and _f_. But on the other side, at _ab_, ab, or [Greek: ab], +these Colours must become much more confused by being dilated and spread +so as to interfere with those of other Orders. And the same confusion +will happen at [Greek: Ux] between _e_ and _f_, if the Refraction be +very great, or the Prism very distant from the Object-glasses: In which +case no parts of the Rings will be seen, save only two little Arcs at +_e_ and _f_, whose distance from one another will be augmented by +removing the Prism still farther from the Object-glasses: And these +little Arcs must be distinctest and whitest at their middle, and at +their ends, where they begin to grow confused, they must be colour'd. +And the Colours at one end of every Arc must be in a contrary order to +those at the other end, by reason that they cross in the intermediate +white; namely, their ends, which verge towards [Greek: Ux], will be red +and yellow on that side next the center, and blue and violet on the +other side. But their other ends which verge from [Greek: Ux], will on +the contrary be blue and violet on that side towards the center, and on +the other side red and yellow. + +Now as all these things follow from the properties of Light by a +mathematical way of reasoning, so the truth of them may be manifested by +Experiments. For in a dark Room, by viewing these Rings through a Prism, +by reflexion of the several prismatick Colours, which an assistant +causes to move to and fro upon a Wall or Paper from whence they are +reflected, whilst the Spectator's Eye, the Prism, and the +Object-glasses, (as in the 13th Observation,) are placed steady; the +Position of the Circles made successively by the several Colours, will +be found such, in respect of one another, as I have described in the +Figures _abxv_, or abxv, or _[Greek: abxU]_. And by the same method the +truth of the Explications of other Observations may be examined. + +By what hath been said, the like Phænomena of Water and thin Plates of +Glass may be understood. But in small fragments of those Plates there is +this farther observable, that where they lie flat upon a Table, and are +turned about their centers whilst they are view'd through a Prism, they +will in some postures exhibit Waves of various Colours; and some of them +exhibit these Waves in one or two Positions only, but the most of them +do in all Positions exhibit them, and make them for the most part appear +almost all over the Plates. The reason is, that the Superficies of such +Plates are not even, but have many Cavities and Swellings, which, how +shallow soever, do a little vary the thickness of the Plate. For at the +several sides of those Cavities, for the Reasons newly described, there +ought to be produced Waves in several postures of the Prism. Now though +it be but some very small and narrower parts of the Glass, by which +these Waves for the most part are caused, yet they may seem to extend +themselves over the whole Glass, because from the narrowest of those +parts there are Colours of several Orders, that is, of several Rings, +confusedly reflected, which by Refraction of the Prism are unfolded, +separated, and, according to their degrees of Refraction, dispersed to +several places, so as to constitute so many several Waves, as there were +divers orders of Colours promiscuously reflected from that part of the +Glass. + +These are the principal Phænomena of thin Plates or Bubbles, whose +Explications depend on the properties of Light, which I have heretofore +deliver'd. And these you see do necessarily follow from them, and agree +with them, even to their very least circumstances; and not only so, but +do very much tend to their proof. Thus, by the 24th Observation it +appears, that the Rays of several Colours, made as well by thin Plates +or Bubbles, as by Refractions of a Prism, have several degrees of +Refrangibility; whereby those of each order, which at the reflexion from +the Plate or Bubble are intermix'd with those of other orders, are +separated from them by Refraction, and associated together so as to +become visible by themselves like Arcs of Circles. For if the Rays were +all alike refrangible, 'tis impossible that the whiteness, which to the +naked Sense appears uniform, should by Refraction have its parts +transposed and ranged into those black and white Arcs. + +It appears also that the unequal Refractions of difform Rays proceed not +from any contingent irregularities; such as are Veins, an uneven Polish, +or fortuitous Position of the Pores of Glass; unequal and casual Motions +in the Air or Æther, the spreading, breaking, or dividing the same Ray +into many diverging parts; or the like. For, admitting any such +irregularities, it would be impossible for Refractions to render those +Rings so very distinct, and well defined, as they do in the 24th +Observation. It is necessary therefore that every Ray have its proper +and constant degree of Refrangibility connate with it, according to +which its refraction is ever justly and regularly perform'd; and that +several Rays have several of those degrees. + +And what is said of their Refrangibility may be also understood of their +Reflexibility, that is, of their Dispositions to be reflected, some at a +greater, and others at a less thickness of thin Plates or Bubbles; +namely, that those Dispositions are also connate with the Rays, and +immutable; as may appear by the 13th, 14th, and 15th Observations, +compared with the fourth and eighteenth. + +By the Precedent Observations it appears also, that whiteness is a +dissimilar mixture of all Colours, and that Light is a mixture of Rays +endued with all those Colours. For, considering the multitude of the +Rings of Colours in the 3d, 12th, and 24th Observations, it is manifest, +that although in the 4th and 18th Observations there appear no more than +eight or nine of those Rings, yet there are really a far greater number, +which so much interfere and mingle with one another, as after those +eight or nine revolutions to dilute one another wholly, and constitute +an even and sensibly uniform whiteness. And consequently that whiteness +must be allow'd a mixture of all Colours, and the Light which conveys it +to the Eye must be a mixture of Rays endued with all those Colours. + +But farther; by the 24th Observation it appears, that there is a +constant relation between Colours and Refrangibility; the most +refrangible Rays being violet, the least refrangible red, and those of +intermediate Colours having proportionably intermediate degrees of +Refrangibility. And by the 13th, 14th, and 15th Observations, compared +with the 4th or 18th there appears to be the same constant relation +between Colour and Reflexibility; the violet being in like circumstances +reflected at least thicknesses of any thin Plate or Bubble, the red at +greatest thicknesses, and the intermediate Colours at intermediate +thicknesses. Whence it follows, that the colorifick Dispositions of +Rays are also connate with them, and immutable; and by consequence, that +all the Productions and Appearances of Colours in the World are derived, +not from any physical Change caused in Light by Refraction or Reflexion, +but only from the various Mixtures or Separations of Rays, by virtue of +their different Refrangibility or Reflexibility. And in this respect the +Science of Colours becomes a Speculation as truly mathematical as any +other part of Opticks. I mean, so far as they depend on the Nature of +Light, and are not produced or alter'd by the Power of Imagination, or +by striking or pressing the Eye. + + + + +THE + +SECOND BOOK + +OF + +OPTICKS + + +_PART III._ + +_Of the permanent Colours of natural Bodies, and the Analogy between +them and the Colours of thin transparent Plates._ + +I am now come to another part of this Design, which is to consider how +the Phænomena of thin transparent Plates stand related to those of all +other natural Bodies. Of these Bodies I have already told you that they +appear of divers Colours, accordingly as they are disposed to reflect +most copiously the Rays originally endued with those Colours. But their +Constitutions, whereby they reflect some Rays more copiously than +others, remain to be discover'd; and these I shall endeavour to manifest +in the following Propositions. + + +PROP. I. + +_Those Superficies of transparent Bodies reflect the greatest quantity +of Light, which have the greatest refracting Power; that is, which +intercede Mediums that differ most in their refractive Densities. And in +the Confines of equally refracting Mediums there is no Reflexion._ + +The Analogy between Reflexion and Refraction will appear by considering, +that when Light passeth obliquely out of one Medium into another which +refracts from the perpendicular, the greater is the difference of their +refractive Density, the less Obliquity of Incidence is requisite to +cause a total Reflexion. For as the Sines are which measure the +Refraction, so is the Sine of Incidence at which the total Reflexion +begins, to the Radius of the Circle; and consequently that Angle of +Incidence is least where there is the greatest difference of the Sines. +Thus in the passing of Light out of Water into Air, where the Refraction +is measured by the Ratio of the Sines 3 to 4, the total Reflexion begins +when the Angle of Incidence is about 48 Degrees 35 Minutes. In passing +out of Glass into Air, where the Refraction is measured by the Ratio of +the Sines 20 to 31, the total Reflexion begins when the Angle of +Incidence is 40 Degrees 10 Minutes; and so in passing out of Crystal, or +more strongly refracting Mediums into Air, there is still a less +obliquity requisite to cause a total reflexion. Superficies therefore +which refract most do soonest reflect all the Light which is incident on +them, and so must be allowed most strongly reflexive. + +But the truth of this Proposition will farther appear by observing, that +in the Superficies interceding two transparent Mediums, (such as are +Air, Water, Oil, common Glass, Crystal, metalline Glasses, Island +Glasses, white transparent Arsenick, Diamonds, &c.) the Reflexion is +stronger or weaker accordingly, as the Superficies hath a greater or +less refracting Power. For in the Confine of Air and Sal-gem 'tis +stronger than in the Confine of Air and Water, and still stronger in the +Confine of Air and common Glass or Crystal, and stronger in the Confine +of Air and a Diamond. If any of these, and such like transparent Solids, +be immerged in Water, its Reflexion becomes, much weaker than before; +and still weaker if they be immerged in the more strongly refracting +Liquors of well rectified Oil of Vitriol or Spirit of Turpentine. If +Water be distinguish'd into two parts by any imaginary Surface, the +Reflexion in the Confine of those two parts is none at all. In the +Confine of Water and Ice 'tis very little; in that of Water and Oil 'tis +something greater; in that of Water and Sal-gem still greater; and in +that of Water and Glass, or Crystal or other denser Substances still +greater, accordingly as those Mediums differ more or less in their +refracting Powers. Hence in the Confine of common Glass and Crystal, +there ought to be a weak Reflexion, and a stronger Reflexion in the +Confine of common and metalline Glass; though I have not yet tried +this. But in the Confine of two Glasses of equal density, there is not +any sensible Reflexion; as was shewn in the first Observation. And the +same may be understood of the Superficies interceding two Crystals, or +two Liquors, or any other Substances in which no Refraction is caused. +So then the reason why uniform pellucid Mediums (such as Water, Glass, +or Crystal,) have no sensible Reflexion but in their external +Superficies, where they are adjacent to other Mediums of a different +density, is because all their contiguous parts have one and the same +degree of density. + + +PROP. II. + +_The least parts of almost all natural Bodies are in some measure +transparent: And the Opacity of those Bodies ariseth from the multitude +of Reflexions caused in their internal Parts._ + +That this is so has been observed by others, and will easily be granted +by them that have been conversant with Microscopes. And it may be also +tried by applying any substance to a hole through which some Light is +immitted into a dark Room. For how opake soever that Substance may seem +in the open Air, it will by that means appear very manifestly +transparent, if it be of a sufficient thinness. Only white metalline +Bodies must be excepted, which by reason of their excessive density seem +to reflect almost all the Light incident on their first Superficies; +unless by solution in Menstruums they be reduced into very small +Particles, and then they become transparent. + + +PROP. III. + +_Between the parts of opake and colour'd Bodies are many Spaces, either +empty, or replenish'd with Mediums of other Densities; as Water between +the tinging Corpuscles wherewith any Liquor is impregnated, Air between +the aqueous Globules that constitute Clouds or Mists; and for the most +part Spaces void of both Air and Water, but yet perhaps not wholly void +of all Substance, between the parts of hard Bodies._ + +The truth of this is evinced by the two precedent Propositions: For by +the second Proposition there are many Reflexions made by the internal +parts of Bodies, which, by the first Proposition, would not happen if +the parts of those Bodies were continued without any such Interstices +between them; because Reflexions are caused only in Superficies, which +intercede Mediums of a differing density, by _Prop._ 1. + +But farther, that this discontinuity of parts is the principal Cause of +the opacity of Bodies, will appear by considering, that opake Substances +become transparent by filling their Pores with any Substance of equal or +almost equal density with their parts. Thus Paper dipped in Water or +Oil, the _Oculus Mundi_ Stone steep'd in Water, Linnen Cloth oiled or +varnish'd, and many other Substances soaked in such Liquors as will +intimately pervade their little Pores, become by that means more +transparent than otherwise; so, on the contrary, the most transparent +Substances, may, by evacuating their Pores, or separating their parts, +be render'd sufficiently opake; as Salts or wet Paper, or the _Oculus +Mundi_ Stone by being dried, Horn by being scraped, Glass by being +reduced to Powder, or otherwise flawed; Turpentine by being stirred +about with Water till they mix imperfectly, and Water by being form'd +into many small Bubbles, either alone in the form of Froth, or by +shaking it together with Oil of Turpentine, or Oil Olive, or with some +other convenient Liquor, with which it will not perfectly incorporate. +And to the increase of the opacity of these Bodies, it conduces +something, that by the 23d Observation the Reflexions of very thin +transparent Substances are considerably stronger than those made by the +same Substances of a greater thickness. + + +PROP. IV. + +_The Parts of Bodies and their Interstices must not be less than of some +definite bigness, to render them opake and colour'd._ + +For the opakest Bodies, if their parts be subtilly divided, (as Metals, +by being dissolved in acid Menstruums, &c.) become perfectly +transparent. And you may also remember, that in the eighth Observation +there was no sensible reflexion at the Superficies of the +Object-glasses, where they were very near one another, though they did +not absolutely touch. And in the 17th Observation the Reflexion of the +Water-bubble where it became thinnest was almost insensible, so as to +cause very black Spots to appear on the top of the Bubble, by the want +of reflected Light. + +On these grounds I perceive it is that Water, Salt, Glass, Stones, and +such like Substances, are transparent. For, upon divers Considerations, +they seem to be as full of Pores or Interstices between their parts as +other Bodies are, but yet their Parts and Interstices to be too small to +cause Reflexions in their common Surfaces. + + +PROP. V. + +_The transparent parts of Bodies, according to their several sizes, +reflect Rays of one Colour, and transmit those of another, on the same +grounds that thin Plates or Bubbles do reflect or transmit those Rays. +And this I take to be the ground of all their Colours._ + +For if a thinn'd or plated Body, which being of an even thickness, +appears all over of one uniform Colour, should be slit into Threads, or +broken into Fragments, of the same thickness with the Plate; I see no +reason why every Thread or Fragment should not keep its Colour, and by +consequence why a heap of those Threads or Fragments should not +constitute a Mass or Powder of the same Colour, which the Plate +exhibited before it was broken. And the parts of all natural Bodies +being like so many Fragments of a Plate, must on the same grounds +exhibit the same Colours. + +Now, that they do so will appear by the affinity of their Properties. +The finely colour'd Feathers of some Birds, and particularly those of +Peacocks Tails, do, in the very same part of the Feather, appear of +several Colours in several Positions of the Eye, after the very same +manner that thin Plates were found to do in the 7th and 19th +Observations, and therefore their Colours arise from the thinness of the +transparent parts of the Feathers; that is, from the slenderness of the +very fine Hairs, or _Capillamenta_, which grow out of the sides of the +grosser lateral Branches or Fibres of those Feathers. And to the same +purpose it is, that the Webs of some Spiders, by being spun very fine, +have appeared colour'd, as some have observ'd, and that the colour'd +Fibres of some Silks, by varying the Position of the Eye, do vary their +Colour. Also the Colours of Silks, Cloths, and other Substances, which +Water or Oil can intimately penetrate, become more faint and obscure by +being immerged in those Liquors, and recover their Vigor again by being +dried; much after the manner declared of thin Bodies in the 10th and +21st Observations. Leaf-Gold, some sorts of painted Glass, the Infusion +of _Lignum Nephriticum_, and some other Substances, reflect one Colour, +and transmit another; like thin Bodies in the 9th and 20th Observations. +And some of those colour'd Powders which Painters use, may have their +Colours a little changed, by being very elaborately and finely ground. +Where I see not what can be justly pretended for those changes, besides +the breaking of their parts into less parts by that contrition, after +the same manner that the Colour of a thin Plate is changed by varying +its thickness. For which reason also it is that the colour'd Flowers of +Plants and Vegetables, by being bruised, usually become more transparent +than before, or at least in some degree or other change their Colours. +Nor is it much less to my purpose, that, by mixing divers Liquors, very +odd and remarkable Productions and Changes of Colours may be effected, +of which no cause can be more obvious and rational than that the saline +Corpuscles of one Liquor do variously act upon or unite with the tinging +Corpuscles of another, so as to make them swell, or shrink, (whereby not +only their bulk but their density also may be changed,) or to divide +them into smaller Corpuscles, (whereby a colour'd Liquor may become +transparent,) or to make many of them associate into one cluster, +whereby two transparent Liquors may compose a colour'd one. For we see +how apt those saline Menstruums are to penetrate and dissolve Substances +to which they are applied, and some of them to precipitate what others +dissolve. In like manner, if we consider the various Phænomena of the +Atmosphere, we may observe, that when Vapours are first raised, they +hinder not the transparency of the Air, being divided into parts too +small to cause any Reflexion in their Superficies. But when in order to +compose drops of Rain they begin to coalesce and constitute Globules of +all intermediate sizes, those Globules, when they become of convenient +size to reflect some Colours and transmit others, may constitute Clouds +of various Colours according to their sizes. And I see not what can be +rationally conceived in so transparent a Substance as Water for the +production of these Colours, besides the various sizes of its fluid and +globular Parcels. + + +PROP. VI. + +_The parts of Bodies on which their Colours depend, are denser than the +Medium which pervades their Interstices._ + +This will appear by considering, that the Colour of a Body depends not +only on the Rays which are incident perpendicularly on its parts, but on +those also which are incident at all other Angles. And that according to +the 7th Observation, a very little variation of obliquity will change +the reflected Colour, where the thin Body or small Particles is rarer +than the ambient Medium, insomuch that such a small Particle will at +diversly oblique Incidences reflect all sorts of Colours, in so great a +variety that the Colour resulting from them all, confusedly reflected +from a heap of such Particles, must rather be a white or grey than any +other Colour, or at best it must be but a very imperfect and dirty +Colour. Whereas if the thin Body or small Particle be much denser than +the ambient Medium, the Colours, according to the 19th Observation, are +so little changed by the variation of obliquity, that the Rays which +are reflected least obliquely may predominate over the rest, so much as +to cause a heap of such Particles to appear very intensely of their +Colour. + +It conduces also something to the confirmation of this Proposition, +that, according to the 22d Observation, the Colours exhibited by the +denser thin Body within the rarer, are more brisk than those exhibited +by the rarer within the denser. + + +PROP. VII. + +_The bigness of the component parts of natural Bodies may be conjectured +by their Colours._ + +For since the parts of these Bodies, by _Prop._ 5. do most probably +exhibit the same Colours with a Plate of equal thickness, provided they +have the same refractive density; and since their parts seem for the +most part to have much the same density with Water or Glass, as by many +circumstances is obvious to collect; to determine the sizes of those +parts, you need only have recourse to the precedent Tables, in which the +thickness of Water or Glass exhibiting any Colour is expressed. Thus if +it be desired to know the diameter of a Corpuscle, which being of equal +density with Glass shall reflect green of the third Order; the Number +16-1/4 shews it to be (16-1/4)/10000 parts of an Inch. + +The greatest difficulty is here to know of what Order the Colour of any +Body is. And for this end we must have recourse to the 4th and 18th +Observations; from whence may be collected these particulars. + +_Scarlets_, and other _reds_, _oranges_, and _yellows_, if they be pure +and intense, are most probably of the second order. Those of the first +and third order also may be pretty good; only the yellow of the first +order is faint, and the orange and red of the third Order have a great +Mixture of violet and blue. + +There may be good _Greens_ of the fourth Order, but the purest are of +the third. And of this Order the green of all Vegetables seems to be, +partly by reason of the Intenseness of their Colours, and partly because +when they wither some of them turn to a greenish yellow, and others to a +more perfect yellow or orange, or perhaps to red, passing first through +all the aforesaid intermediate Colours. Which Changes seem to be +effected by the exhaling of the Moisture which may leave the tinging +Corpuscles more dense, and something augmented by the Accretion of the +oily and earthy Part of that Moisture. Now the green, without doubt, is +of the same Order with those Colours into which it changeth, because the +Changes are gradual, and those Colours, though usually not very full, +yet are often too full and lively to be of the fourth Order. + +_Blues_ and _Purples_ may be either of the second or third Order, but +the best are of the third. Thus the Colour of Violets seems to be of +that Order, because their Syrup by acid Liquors turns red, and by +urinous and alcalizate turns green. For since it is of the Nature of +Acids to dissolve or attenuate, and of Alcalies to precipitate or +incrassate, if the Purple Colour of the Syrup was of the second Order, +an acid Liquor by attenuating its tinging Corpuscles would change it to +a red of the first Order, and an Alcali by incrassating them would +change it to a green of the second Order; which red and green, +especially the green, seem too imperfect to be the Colours produced by +these Changes. But if the said Purple be supposed of the third Order, +its Change to red of the second, and green of the third, may without any +Inconvenience be allow'd. + +If there be found any Body of a deeper and less reddish Purple than that +of the Violets, its Colour most probably is of the second Order. But yet +there being no Body commonly known whose Colour is constantly more deep +than theirs, I have made use of their Name to denote the deepest and +least reddish Purples, such as manifestly transcend their Colour in +purity. + +The _blue_ of the first Order, though very faint and little, may +possibly be the Colour of some Substances; and particularly the azure +Colour of the Skies seems to be of this Order. For all Vapours when they +begin to condense and coalesce into small Parcels, become first of that +Bigness, whereby such an Azure must be reflected before they can +constitute Clouds of other Colours. And so this being the first Colour +which Vapours begin to reflect, it ought to be the Colour of the finest +and most transparent Skies, in which Vapours are not arrived to that +Grossness requisite to reflect other Colours, as we find it is by +Experience. + +_Whiteness_, if most intense and luminous, is that of the first Order, +if less strong and luminous, a Mixture of the Colours of several Orders. +Of this last kind is the Whiteness of Froth, Paper, Linnen, and most +white Substances; of the former I reckon that of white Metals to be. For +whilst the densest of Metals, Gold, if foliated, is transparent, and all +Metals become transparent if dissolved in Menstruums or vitrified, the +Opacity of white Metals ariseth not from their Density alone. They being +less dense than Gold would be more transparent than it, did not some +other Cause concur with their Density to make them opake. And this Cause +I take to be such a Bigness of their Particles as fits them to reflect +the white of the first order. For, if they be of other Thicknesses they +may reflect other Colours, as is manifest by the Colours which appear +upon hot Steel in tempering it, and sometimes upon the Surface of melted +Metals in the Skin or Scoria which arises upon them in their cooling. +And as the white of the first order is the strongest which can be made +by Plates of transparent Substances, so it ought to be stronger in the +denser Substances of Metals than in the rarer of Air, Water, and Glass. +Nor do I see but that metallick Substances of such a Thickness as may +fit them to reflect the white of the first order, may, by reason of +their great Density (according to the Tenor of the first of these +Propositions) reflect all the Light incident upon them, and so be as +opake and splendent as it's possible for any Body to be. Gold, or Copper +mix'd with less than half their Weight of Silver, or Tin, or Regulus of +Antimony, in fusion, or amalgamed with a very little Mercury, become +white; which shews both that the Particles of white Metals have much +more Superficies, and so are smaller, than those of Gold and Copper, and +also that they are so opake as not to suffer the Particles of Gold or +Copper to shine through them. Now it is scarce to be doubted but that +the Colours of Gold and Copper are of the second and third order, and +therefore the Particles of white Metals cannot be much bigger than is +requisite to make them reflect the white of the first order. The +Volatility of Mercury argues that they are not much bigger, nor may they +be much less, lest they lose their Opacity, and become either +transparent as they do when attenuated by Vitrification, or by Solution +in Menstruums, or black as they do when ground smaller, by rubbing +Silver, or Tin, or Lead, upon other Substances to draw black Lines. The +first and only Colour which white Metals take by grinding their +Particles smaller, is black, and therefore their white ought to be that +which borders upon the black Spot in the Center of the Rings of Colours, +that is, the white of the first order. But, if you would hence gather +the Bigness of metallick Particles, you must allow for their Density. +For were Mercury transparent, its Density is such that the Sine of +Incidence upon it (by my Computation) would be to the Sine of its +Refraction, as 71 to 20, or 7 to 2. And therefore the Thickness of its +Particles, that they may exhibit the same Colours with those of Bubbles +of Water, ought to be less than the Thickness of the Skin of those +Bubbles in the Proportion of 2 to 7. Whence it's possible, that the +Particles of Mercury may be as little as the Particles of some +transparent and volatile Fluids, and yet reflect the white of the first +order. + +Lastly, for the production of _black_, the Corpuscles must be less than +any of those which exhibit Colours. For at all greater sizes there is +too much Light reflected to constitute this Colour. But if they be +supposed a little less than is requisite to reflect the white and very +faint blue of the first order, they will, according to the 4th, 8th, +17th and 18th Observations, reflect so very little Light as to appear +intensely black, and yet may perhaps variously refract it to and fro +within themselves so long, until it happen to be stifled and lost, by +which means they will appear black in all positions of the Eye without +any transparency. And from hence may be understood why Fire, and the +more subtile dissolver Putrefaction, by dividing the Particles of +Substances, turn them to black, why small quantities of black Substances +impart their Colour very freely and intensely to other Substances to +which they are applied; the minute Particles of these, by reason of +their very great number, easily overspreading the gross Particles of +others; why Glass ground very elaborately with Sand on a Copper Plate, +'till it be well polish'd, makes the Sand, together with what is worn +off from the Glass and Copper, become very black: why black Substances +do soonest of all others become hot in the Sun's Light and burn, (which +Effect may proceed partly from the multitude of Refractions in a little +room, and partly from the easy Commotion of so very small Corpuscles;) +and why blacks are usually a little inclined to a bluish Colour. For +that they are so may be seen by illuminating white Paper by Light +reflected from black Substances. For the Paper will usually appear of a +bluish white; and the reason is, that black borders in the obscure blue +of the order described in the 18th Observation, and therefore reflects +more Rays of that Colour than of any other. + +In these Descriptions I have been the more particular, because it is not +impossible but that Microscopes may at length be improved to the +discovery of the Particles of Bodies on which their Colours depend, if +they are not already in some measure arrived to that degree of +perfection. For if those Instruments are or can be so far improved as +with sufficient distinctness to represent Objects five or six hundred +times bigger than at a Foot distance they appear to our naked Eyes, I +should hope that we might be able to discover some of the greatest of +those Corpuscles. And by one that would magnify three or four thousand +times perhaps they might all be discover'd, but those which produce +blackness. In the mean while I see nothing material in this Discourse +that may rationally be doubted of, excepting this Position: That +transparent Corpuscles of the same thickness and density with a Plate, +do exhibit the same Colour. And this I would have understood not without +some Latitude, as well because those Corpuscles may be of irregular +Figures, and many Rays must be obliquely incident on them, and so have +a shorter way through them than the length of their Diameters, as +because the straitness of the Medium put in on all sides within such +Corpuscles may a little alter its Motions or other qualities on which +the Reflexion depends. But yet I cannot much suspect the last, because I +have observed of some small Plates of Muscovy Glass which were of an +even thickness, that through a Microscope they have appeared of the same +Colour at their edges and corners where the included Medium was +terminated, which they appeared of in other places. However it will add +much to our Satisfaction, if those Corpuscles can be discover'd with +Microscopes; which if we shall at length attain to, I fear it will be +the utmost improvement of this Sense. For it seems impossible to see the +more secret and noble Works of Nature within the Corpuscles by reason of +their transparency. + + +PROP. VIII. + +_The Cause of Reflexion is not the impinging of Light on the solid or +impervious parts of Bodies, as is commonly believed._ + +This will appear by the following Considerations. First, That in the +passage of Light out of Glass into Air there is a Reflexion as strong as +in its passage out of Air into Glass, or rather a little stronger, and +by many degrees stronger than in its passage out of Glass into Water. +And it seems not probable that Air should have more strongly reflecting +parts than Water or Glass. But if that should possibly be supposed, yet +it will avail nothing; for the Reflexion is as strong or stronger when +the Air is drawn away from the Glass, (suppose by the Air-Pump invented +by _Otto Gueriet_, and improved and made useful by Mr. _Boyle_) as when +it is adjacent to it. Secondly, If Light in its passage out of Glass +into Air be incident more obliquely than at an Angle of 40 or 41 Degrees +it is wholly reflected, if less obliquely it is in great measure +transmitted. Now it is not to be imagined that Light at one degree of +obliquity should meet with Pores enough in the Air to transmit the +greater part of it, and at another degree of obliquity should meet with +nothing but parts to reflect it wholly, especially considering that in +its passage out of Air into Glass, how oblique soever be its Incidence, +it finds Pores enough in the Glass to transmit a great part of it. If +any Man suppose that it is not reflected by the Air, but by the outmost +superficial parts of the Glass, there is still the same difficulty: +Besides, that such a Supposition is unintelligible, and will also appear +to be false by applying Water behind some part of the Glass instead of +Air. For so in a convenient obliquity of the Rays, suppose of 45 or 46 +Degrees, at which they are all reflected where the Air is adjacent to +the Glass, they shall be in great measure transmitted where the Water is +adjacent to it; which argues, that their Reflexion or Transmission +depends on the constitution of the Air and Water behind the Glass, and +not on the striking of the Rays upon the parts of the Glass. Thirdly, +If the Colours made by a Prism placed at the entrance of a Beam of Light +into a darken'd Room be successively cast on a second Prism placed at a +greater distance from the former, in such manner that they are all alike +incident upon it, the second Prism may be so inclined to the incident +Rays, that those which are of a blue Colour shall be all reflected by +it, and yet those of a red Colour pretty copiously transmitted. Now if +the Reflexion be caused by the parts of Air or Glass, I would ask, why +at the same Obliquity of Incidence the blue should wholly impinge on +those parts, so as to be all reflected, and yet the red find Pores +enough to be in a great measure transmitted. Fourthly, Where two Glasses +touch one another, there is no sensible Reflexion, as was declared in +the first Observation; and yet I see no reason why the Rays should not +impinge on the parts of Glass, as much when contiguous to other Glass as +when contiguous to Air. Fifthly, When the top of a Water-Bubble (in the +17th Observation,) by the continual subsiding and exhaling of the Water +grew very thin, there was such a little and almost insensible quantity +of Light reflected from it, that it appeared intensely black; whereas +round about that black Spot, where the Water was thicker, the Reflexion +was so strong as to make the Water seem very white. Nor is it only at +the least thickness of thin Plates or Bubbles, that there is no manifest +Reflexion, but at many other thicknesses continually greater and +greater. For in the 15th Observation the Rays of the same Colour were by +turns transmitted at one thickness, and reflected at another thickness, +for an indeterminate number of Successions. And yet in the Superficies +of the thinned Body, where it is of any one thickness, there are as many +parts for the Rays to impinge on, as where it is of any other thickness. +Sixthly, If Reflexion were caused by the parts of reflecting Bodies, it +would be impossible for thin Plates or Bubbles, at one and the same +place, to reflect the Rays of one Colour, and transmit those of another, +as they do according to the 13th and 15th Observations. For it is not to +be imagined that at one place the Rays which, for instance, exhibit a +blue Colour, should have the fortune to dash upon the parts, and those +which exhibit a red to hit upon the Pores of the Body; and then at +another place, where the Body is either a little thicker or a little +thinner, that on the contrary the blue should hit upon its pores, and +the red upon its parts. Lastly, Were the Rays of Light reflected by +impinging on the solid parts of Bodies, their Reflexions from polish'd +Bodies could not be so regular as they are. For in polishing Glass with +Sand, Putty, or Tripoly, it is not to be imagined that those Substances +can, by grating and fretting the Glass, bring all its least Particles to +an accurate Polish; so that all their Surfaces shall be truly plain or +truly spherical, and look all the same way, so as together to compose +one even Surface. The smaller the Particles of those Substances are, the +smaller will be the Scratches by which they continually fret and wear +away the Glass until it be polish'd; but be they never so small they can +wear away the Glass no otherwise than by grating and scratching it, and +breaking the Protuberances; and therefore polish it no otherwise than by +bringing its roughness to a very fine Grain, so that the Scratches and +Frettings of the Surface become too small to be visible. And therefore +if Light were reflected by impinging upon the solid parts of the Glass, +it would be scatter'd as much by the most polish'd Glass as by the +roughest. So then it remains a Problem, how Glass polish'd by fretting +Substances can reflect Light so regularly as it does. And this Problem +is scarce otherwise to be solved, than by saying, that the Reflexion of +a Ray is effected, not by a single point of the reflecting Body, but by +some power of the Body which is evenly diffused all over its Surface, +and by which it acts upon the Ray without immediate Contact. For that +the parts of Bodies do act upon Light at a distance shall be shewn +hereafter. + +Now if Light be reflected, not by impinging on the solid parts of +Bodies, but by some other principle; it's probable that as many of its +Rays as impinge on the solid parts of Bodies are not reflected but +stifled and lost in the Bodies. For otherwise we must allow two sorts of +Reflexions. Should all the Rays be reflected which impinge on the +internal parts of clear Water or Crystal, those Substances would rather +have a cloudy Colour than a clear Transparency. To make Bodies look +black, it's necessary that many Rays be stopp'd, retained, and lost in +them; and it seems not probable that any Rays can be stopp'd and +stifled in them which do not impinge on their parts. + +And hence we may understand that Bodies are much more rare and porous +than is commonly believed. Water is nineteen times lighter, and by +consequence nineteen times rarer than Gold; and Gold is so rare as very +readily and without the least opposition to transmit the magnetick +Effluvia, and easily to admit Quicksilver into its Pores, and to let +Water pass through it. For a concave Sphere of Gold filled with Water, +and solder'd up, has, upon pressing the Sphere with great force, let the +Water squeeze through it, and stand all over its outside in multitudes +of small Drops, like Dew, without bursting or cracking the Body of the +Gold, as I have been inform'd by an Eye witness. From all which we may +conclude, that Gold has more Pores than solid parts, and by consequence +that Water has above forty times more Pores than Parts. And he that +shall find out an Hypothesis, by which Water may be so rare, and yet not +be capable of compression by force, may doubtless by the same Hypothesis +make Gold, and Water, and all other Bodies, as much rarer as he pleases; +so that Light may find a ready passage through transparent Substances. + +The Magnet acts upon Iron through all dense Bodies not magnetick nor red +hot, without any diminution of its Virtue; as for instance, through +Gold, Silver, Lead, Glass, Water. The gravitating Power of the Sun is +transmitted through the vast Bodies of the Planets without any +diminution, so as to act upon all their parts to their very centers +with the same Force and according to the same Laws, as if the part upon +which it acts were not surrounded with the Body of the Planet, The Rays +of Light, whether they be very small Bodies projected, or only Motion or +Force propagated, are moved in right Lines; and whenever a Ray of Light +is by any Obstacle turned out of its rectilinear way, it will never +return into the same rectilinear way, unless perhaps by very great +accident. And yet Light is transmitted through pellucid solid Bodies in +right Lines to very great distances. How Bodies can have a sufficient +quantity of Pores for producing these Effects is very difficult to +conceive, but perhaps not altogether impossible. For the Colours of +Bodies arise from the Magnitudes of the Particles which reflect them, as +was explained above. Now if we conceive these Particles of Bodies to be +so disposed amongst themselves, that the Intervals or empty Spaces +between them may be equal in magnitude to them all; and that these +Particles may be composed of other Particles much smaller, which have as +much empty Space between them as equals all the Magnitudes of these +smaller Particles: And that in like manner these smaller Particles are +again composed of others much smaller, all which together are equal to +all the Pores or empty Spaces between them; and so on perpetually till +you come to solid Particles, such as have no Pores or empty Spaces +within them: And if in any gross Body there be, for instance, three such +degrees of Particles, the least of which are solid; this Body will have +seven times more Pores than solid Parts. But if there be four such +degrees of Particles, the least of which are solid, the Body will have +fifteen times more Pores than solid Parts. If there be five degrees, the +Body will have one and thirty times more Pores than solid Parts. If six +degrees, the Body will have sixty and three times more Pores than solid +Parts. And so on perpetually. And there are other ways of conceiving how +Bodies may be exceeding porous. But what is really their inward Frame is +not yet known to us. + + +PROP. IX. + +_Bodies reflect and refract Light by one and the same power, variously +exercised in various Circumstances._ + +This appears by several Considerations. First, Because when Light goes +out of Glass into Air, as obliquely as it can possibly do. If its +Incidence be made still more oblique, it becomes totally reflected. For +the power of the Glass after it has refracted the Light as obliquely as +is possible, if the Incidence be still made more oblique, becomes too +strong to let any of its Rays go through, and by consequence causes +total Reflexions. Secondly, Because Light is alternately reflected and +transmitted by thin Plates of Glass for many Successions, accordingly as +the thickness of the Plate increases in an arithmetical Progression. For +here the thickness of the Glass determines whether that Power by which +Glass acts upon Light shall cause it to be reflected, or suffer it to +be transmitted. And, Thirdly, because those Surfaces of transparent +Bodies which have the greatest refracting power, reflect the greatest +quantity of Light, as was shewn in the first Proposition. + + +PROP. X. + +_If Light be swifter in Bodies than in Vacuo, in the proportion of the +Sines which measure the Refraction of the Bodies, the Forces of the +Bodies to reflect and refract Light, are very nearly proportional to the +densities of the same Bodies; excepting that unctuous and sulphureous +Bodies refract more than others of this same density._ + +[Illustration: FIG. 8.] + +Let AB represent the refracting plane Surface of any Body, and IC a Ray +incident very obliquely upon the Body in C, so that the Angle ACI may be +infinitely little, and let CR be the refracted Ray. From a given Point B +perpendicular to the refracting Surface erect BR meeting with the +refracting Ray CR in R, and if CR represent the Motion of the refracted +Ray, and this Motion be distinguish'd into two Motions CB and BR, +whereof CB is parallel to the refracting Plane, and BR perpendicular to +it: CB shall represent the Motion of the incident Ray, and BR the +Motion generated by the Refraction, as Opticians have of late explain'd. + +Now if any Body or Thing, in moving through any Space of a given breadth +terminated on both sides by two parallel Planes, be urged forward in all +parts of that Space by Forces tending directly forwards towards the last +Plane, and before its Incidence on the first Plane, had no Motion +towards it, or but an infinitely little one; and if the Forces in all +parts of that Space, between the Planes, be at equal distances from the +Planes equal to one another, but at several distances be bigger or less +in any given Proportion, the Motion generated by the Forces in the whole +passage of the Body or thing through that Space shall be in a +subduplicate Proportion of the Forces, as Mathematicians will easily +understand. And therefore, if the Space of activity of the refracting +Superficies of the Body be consider'd as such a Space, the Motion of the +Ray generated by the refracting Force of the Body, during its passage +through that Space, that is, the Motion BR, must be in subduplicate +Proportion of that refracting Force. I say therefore, that the Square of +the Line BR, and by consequence the refracting Force of the Body, is +very nearly as the density of the same Body. For this will appear by the +following Table, wherein the Proportion of the Sines which measure the +Refractions of several Bodies, the Square of BR, supposing CB an unite, +the Densities of the Bodies estimated by their Specifick Gravities, and +their Refractive Power in respect of their Densities are set down in +several Columns. + +---------------------+----------------+----------------+----------+----------- + | | | | + | | The Square | The | The + | | of BR, to | density | refractive + | The Proportion | which the | and | Power of + | of the Sines of| refracting | specifick| the Body + | Incidence and | force of the | gravity | in respect + The refracting | Refraction of | Body is | of the | of its + Bodies. | yellow Light. | proportionate. | Body. | density. +---------------------+----------------+----------------+----------+----------- +A Pseudo-Topazius, | | | | + being a natural, | | | | + pellucid, brittle, | 23 to 14 | 1'699 | 4'27 | 3979 + hairy Stone, of a | | | | + yellow Colour. | | | | +Air. | 3201 to 3200 | 0'000625 | 0'0012 | 5208 +Glass of Antimony. | 17 to 9 | 2'568 | 5'28 | 4864 +A Selenitis. | 61 to 41 | 1'213 | 2'252 | 5386 +Glass vulgar. | 31 to 20 | 1'4025 | 2'58 | 5436 +Crystal of the Rock. | 25 to 16 | 1'445 | 2'65 | 5450 +Island Crystal. | 5 to 3 | 1'778 | 2'72 | 6536 +Sal Gemmæ. | 17 to 11 | 1'388 | 2'143 | 6477 +Alume. | 35 to 24 | 1'1267 | 1'714 | 6570 +Borax. | 22 to 15 | 1'1511 | 1'714 | 6716 +Niter. | 32 to 21 | 1'345 | 1'9 | 7079 +Dantzick Vitriol. | 303 to 200 | 1'295 | 1'715 | 7551 +Oil of Vitriol. | 10 to 7 | 1'041 | 1'7 | 6124 +Rain Water. | 529 to 396 | 0'7845 | 1' | 7845 +Gum Arabick. | 31 to 21 | 1'179 | 1'375 | 8574 +Spirit of Wine well | | | | + rectified. | 100 to 73 | 0'8765 | 0'866 | 10121 +Camphire. | 3 to 2 | 1'25 | 0'996 | 12551 +Oil Olive. | 22 to 15 | 1'1511 | 0'913 | 12607 +Linseed Oil. | 40 to 27 | 1'1948 | 0'932 | 12819 +Spirit of Turpentine.| 25 to 17 | 1'1626 | 0'874 | 13222 +Amber. | 14 to 9 | 1'42 | 1'04 | 13654 +A Diamond. | 100 to 41 | 4'949 | 3'4 | 14556 +---------------------+----------------+----------------+----------+----------- + +The Refraction of the Air in this Table is determin'd by that of the +Atmosphere observed by Astronomers. For, if Light pass through many +refracting Substances or Mediums gradually denser and denser, and +terminated with parallel Surfaces, the Sum of all the Refractions will +be equal to the single Refraction which it would have suffer'd in +passing immediately out of the first Medium into the last. And this +holds true, though the Number of the refracting Substances be increased +to Infinity, and the Distances from one another as much decreased, so +that the Light may be refracted in every Point of its Passage, and by +continual Refractions bent into a Curve-Line. And therefore the whole +Refraction of Light in passing through the Atmosphere from the highest +and rarest Part thereof down to the lowest and densest Part, must be +equal to the Refraction which it would suffer in passing at like +Obliquity out of a Vacuum immediately into Air of equal Density with +that in the lowest Part of the Atmosphere. + +Now, although a Pseudo-Topaz, a Selenitis, Rock Crystal, Island Crystal, +Vulgar Glass (that is, Sand melted together) and Glass of Antimony, +which are terrestrial stony alcalizate Concretes, and Air which probably +arises from such Substances by Fermentation, be Substances very +differing from one another in Density, yet by this Table, they have +their refractive Powers almost in the same Proportion to one another as +their Densities are, excepting that the Refraction of that strange +Substance, Island Crystal is a little bigger than the rest. And +particularly Air, which is 3500 Times rarer than the Pseudo-Topaz, and +4400 Times rarer than Glass of Antimony, and 2000 Times rarer than the +Selenitis, Glass vulgar, or Crystal of the Rock, has notwithstanding its +rarity the same refractive Power in respect of its Density which those +very dense Substances have in respect of theirs, excepting so far as +those differ from one another. + +Again, the Refraction of Camphire, Oil Olive, Linseed Oil, Spirit of +Turpentine and Amber, which are fat sulphureous unctuous Bodies, and a +Diamond, which probably is an unctuous Substance coagulated, have their +refractive Powers in Proportion to one another as their Densities +without any considerable Variation. But the refractive Powers of these +unctuous Substances are two or three Times greater in respect of their +Densities than the refractive Powers of the former Substances in respect +of theirs. + +Water has a refractive Power in a middle degree between those two sorts +of Substances, and probably is of a middle nature. For out of it grow +all vegetable and animal Substances, which consist as well of +sulphureous fat and inflamable Parts, as of earthy lean and alcalizate +ones. + +Salts and Vitriols have refractive Powers in a middle degree between +those of earthy Substances and Water, and accordingly are composed of +those two sorts of Substances. For by distillation and rectification of +their Spirits a great Part of them goes into Water, and a great Part +remains behind in the form of a dry fix'd Earth capable of +Vitrification. + +Spirit of Wine has a refractive Power in a middle degree between those +of Water and oily Substances, and accordingly seems to be composed of +both, united by Fermentation; the Water, by means of some saline Spirits +with which 'tis impregnated, dissolving the Oil, and volatizing it by +the Action. For Spirit of Wine is inflamable by means of its oily Parts, +and being distilled often from Salt of Tartar, grow by every +distillation more and more aqueous and phlegmatick. And Chymists +observe, that Vegetables (as Lavender, Rue, Marjoram, &c.) distilled +_per se_, before fermentation yield Oils without any burning Spirits, +but after fermentation yield ardent Spirits without Oils: Which shews, +that their Oil is by fermentation converted into Spirit. They find also, +that if Oils be poured in a small quantity upon fermentating Vegetables, +they distil over after fermentation in the form of Spirits. + +So then, by the foregoing Table, all Bodies seem to have their +refractive Powers proportional to their Densities, (or very nearly;) +excepting so far as they partake more or less of sulphureous oily +Particles, and thereby have their refractive Power made greater or less. +Whence it seems rational to attribute the refractive Power of all Bodies +chiefly, if not wholly, to the sulphureous Parts with which they abound. +For it's probable that all Bodies abound more or less with Sulphurs. And +as Light congregated by a Burning-glass acts most upon sulphureous +Bodies, to turn them into Fire and Flame; so, since all Action is +mutual, Sulphurs ought to act most upon Light. For that the action +between Light and Bodies is mutual, may appear from this Consideration; +That the densest Bodies which refract and reflect Light most strongly, +grow hottest in the Summer Sun, by the action of the refracted or +reflected Light. + +I have hitherto explain'd the power of Bodies to reflect and refract, +and shew'd, that thin transparent Plates, Fibres, and Particles, do, +according to their several thicknesses and densities, reflect several +sorts of Rays, and thereby appear of several Colours; and by consequence +that nothing more is requisite for producing all the Colours of natural +Bodies, than the several sizes and densities of their transparent +Particles. But whence it is that these Plates, Fibres, and Particles, +do, according to their several thicknesses and densities, reflect +several sorts of Rays, I have not yet explain'd. To give some insight +into this matter, and make way for understanding the next part of this +Book, I shall conclude this part with a few more Propositions. Those +which preceded respect the nature of Bodies, these the nature of Light: +For both must be understood, before the reason of their Actions upon one +another can be known. And because the last Proposition depended upon the +velocity of Light, I will begin with a Proposition of that kind. + + +PROP. XI. + +_Light is propagated from luminous Bodies in time, and spends about +seven or eight Minutes of an Hour in passing from the Sun to the Earth._ + +This was observed first by _Roemer_, and then by others, by means of the +Eclipses of the Satellites of _Jupiter_. For these Eclipses, when the +Earth is between the Sun and _Jupiter_, happen about seven or eight +Minutes sooner than they ought to do by the Tables, and when the Earth +is beyond the Sun they happen about seven or eight Minutes later than +they ought to do; the reason being, that the Light of the Satellites has +farther to go in the latter case than in the former by the Diameter of +the Earth's Orbit. Some inequalities of time may arise from the +Excentricities of the Orbs of the Satellites; but those cannot answer in +all the Satellites, and at all times to the Position and Distance of the +Earth from the Sun. The mean motions of _Jupiter_'s Satellites is also +swifter in his descent from his Aphelium to his Perihelium, than in his +ascent in the other half of his Orb. But this inequality has no respect +to the position of the Earth, and in the three interior Satellites is +insensible, as I find by computation from the Theory of their Gravity. + + +PROP. XII. + +_Every Ray of Light in its passage through any refracting Surface is put +into a certain transient Constitution or State, which in the progress of +the Ray returns at equal Intervals, and disposes the Ray at every return +to be easily transmitted through the next refracting Surface, and +between the returns to be easily reflected by it._ + +This is manifest by the 5th, 9th, 12th, and 15th Observations. For by +those Observations it appears, that one and the same sort of Rays at +equal Angles of Incidence on any thin transparent Plate, is alternately +reflected and transmitted for many Successions accordingly as the +thickness of the Plate increases in arithmetical Progression of the +Numbers, 0, 1, 2, 3, 4, 5, 6, 7, 8, &c. so that if the first Reflexion +(that which makes the first or innermost of the Rings of Colours there +described) be made at the thickness 1, the Rays shall be transmitted at +the thicknesses 0, 2, 4, 6, 8, 10, 12, &c. and thereby make the central +Spot and Rings of Light, which appear by transmission, and be reflected +at the thickness 1, 3, 5, 7, 9, 11, &c. and thereby make the Rings which +appear by Reflexion. And this alternate Reflexion and Transmission, as I +gather by the 24th Observation, continues for above an hundred +vicissitudes, and by the Observations in the next part of this Book, for +many thousands, being propagated from one Surface of a Glass Plate to +the other, though the thickness of the Plate be a quarter of an Inch or +above: So that this alternation seems to be propagated from every +refracting Surface to all distances without end or limitation. + +This alternate Reflexion and Refraction depends on both the Surfaces of +every thin Plate, because it depends on their distance. By the 21st +Observation, if either Surface of a thin Plate of _Muscovy_ Glass be +wetted, the Colours caused by the alternate Reflexion and Refraction +grow faint, and therefore it depends on them both. + +It is therefore perform'd at the second Surface; for if it were +perform'd at the first, before the Rays arrive at the second, it would +not depend on the second. + +It is also influenced by some action or disposition, propagated from the +first to the second, because otherwise at the second it would not depend +on the first. And this action or disposition, in its propagation, +intermits and returns by equal Intervals, because in all its progress it +inclines the Ray at one distance from the first Surface to be reflected +by the second, at another to be transmitted by it, and that by equal +Intervals for innumerable vicissitudes. And because the Ray is disposed +to Reflexion at the distances 1, 3, 5, 7, 9, &c. and to Transmission at +the distances 0, 2, 4, 6, 8, 10, &c. (for its transmission through the +first Surface, is at the distance 0, and it is transmitted through both +together, if their distance be infinitely little or much less than 1) +the disposition to be transmitted at the distances 2, 4, 6, 8, 10, &c. +is to be accounted a return of the same disposition which the Ray first +had at the distance 0, that is at its transmission through the first +refracting Surface. All which is the thing I would prove. + +What kind of action or disposition this is; Whether it consists in a +circulating or a vibrating motion of the Ray, or of the Medium, or +something else, I do not here enquire. Those that are averse from +assenting to any new Discoveries, but such as they can explain by an +Hypothesis, may for the present suppose, that as Stones by falling upon +Water put the Water into an undulating Motion, and all Bodies by +percussion excite vibrations in the Air; so the Rays of Light, by +impinging on any refracting or reflecting Surface, excite vibrations in +the refracting or reflecting Medium or Substance, and by exciting them +agitate the solid parts of the refracting or reflecting Body, and by +agitating them cause the Body to grow warm or hot; that the vibrations +thus excited are propagated in the refracting or reflecting Medium or +Substance, much after the manner that vibrations are propagated in the +Air for causing Sound, and move faster than the Rays so as to overtake +them; and that when any Ray is in that part of the vibration which +conspires with its Motion, it easily breaks through a refracting +Surface, but when it is in the contrary part of the vibration which +impedes its Motion, it is easily reflected; and, by consequence, that +every Ray is successively disposed to be easily reflected, or easily +transmitted, by every vibration which overtakes it. But whether this +Hypothesis be true or false I do not here consider. I content my self +with the bare Discovery, that the Rays of Light are by some cause or +other alternately disposed to be reflected or refracted for many +vicissitudes. + + +DEFINITION. + +_The returns of the disposition of any Ray to be reflected I will call +its_ Fits of easy Reflexion, _and those of its disposition to be +transmitted its_ Fits of easy Transmission, _and the space it passes +between every return and the next return, the_ Interval of its Fits. + + +PROP. XIII. + +_The reason why the Surfaces of all thick transparent Bodies reflect +part of the Light incident on them, and refract the rest, is, that some +Rays at their Incidence are in Fits of easy Reflexion, and others in +Fits of easy Transmission._ + +This may be gather'd from the 24th Observation, where the Light +reflected by thin Plates of Air and Glass, which to the naked Eye +appear'd evenly white all over the Plate, did through a Prism appear +waved with many Successions of Light and Darkness made by alternate Fits +of easy Reflexion and easy Transmission, the Prism severing and +distinguishing the Waves of which the white reflected Light was +composed, as was explain'd above. + +And hence Light is in Fits of easy Reflexion and easy Transmission, +before its Incidence on transparent Bodies. And probably it is put into +such fits at its first emission from luminous Bodies, and continues in +them during all its progress. For these Fits are of a lasting nature, as +will appear by the next part of this Book. + +In this Proposition I suppose the transparent Bodies to be thick; +because if the thickness of the Body be much less than the Interval of +the Fits of easy Reflexion and Transmission of the Rays, the Body loseth +its reflecting power. For if the Rays, which at their entering into the +Body are put into Fits of easy Transmission, arrive at the farthest +Surface of the Body before they be out of those Fits, they must be +transmitted. And this is the reason why Bubbles of Water lose their +reflecting power when they grow very thin; and why all opake Bodies, +when reduced into very small parts, become transparent. + + +PROP. XIV. + +_Those Surfaces of transparent Bodies, which if the Ray be in a Fit of +Refraction do refract it most strongly, if the Ray be in a Fit of +Reflexion do reflect it most easily._ + +For we shewed above, in _Prop._ 8. that the cause of Reflexion is not +the impinging of Light on the solid impervious parts of Bodies, but some +other power by which those solid parts act on Light at a distance. We +shewed also in _Prop._ 9. that Bodies reflect and refract Light by one +and the same power, variously exercised in various circumstances; and in +_Prop._ 1. that the most strongly refracting Surfaces reflect the most +Light: All which compared together evince and rarify both this and the +last Proposition. + + +PROP. XV. + +_In any one and the same sort of Rays, emerging in any Angle out of any +refracting Surface into one and the same Medium, the Interval of the +following Fits of easy Reflexion and Transmission are either accurately +or very nearly, as the Rectangle of the Secant of the Angle of +Refraction, and of the Secant of another Angle, whose Sine is the first +of 106 arithmetical mean Proportionals, between the Sines of Incidence +and Refraction, counted from the Sine of Refraction._ + +This is manifest by the 7th and 19th Observations. + + +PROP. XVI. + +_In several sorts of Rays emerging in equal Angles out of any refracting +Surface into the same Medium, the Intervals of the following Fits of +easy Reflexion and easy Transmission are either accurately, or very +nearly, as the Cube-Roots of the Squares of the lengths of a Chord, +which found the Notes in an Eight_, sol, la, fa, sol, la, mi, fa, sol, +_with all their intermediate degrees answering to the Colours of those +Rays, according to the Analogy described in the seventh Experiment of +the second Part of the first Book._ + +This is manifest by the 13th and 14th Observations. + + +PROP. XVII. + +_If Rays of any sort pass perpendicularly into several Mediums, the +Intervals of the Fits of easy Reflexion and Transmission in any one +Medium, are to those Intervals in any other, as the Sine of Incidence to +the Sine of Refraction, when the Rays pass out of the first of those two +Mediums into the second._ + +This is manifest by the 10th Observation. + + +PROP. XVIII. + +_If the Rays which paint the Colour in the Confine of yellow and orange +pass perpendicularly out of any Medium into Air, the Intervals of their +Fits of easy Reflexion are the 1/89000th part of an Inch. And of the +same length are the Intervals of their Fits of easy Transmission._ + +This is manifest by the 6th Observation. From these Propositions it is +easy to collect the Intervals of the Fits of easy Reflexion and easy +Transmission of any sort of Rays refracted in any angle into any Medium; +and thence to know, whether the Rays shall be reflected or transmitted +at their subsequent Incidence upon any other pellucid Medium. Which +thing, being useful for understanding the next part of this Book, was +here to be set down. And for the same reason I add the two following +Propositions. + + +PROP. XIX. + +_If any sort of Rays falling on the polite Surface of any pellucid +Medium be reflected back, the Fits of easy Reflexion, which they have at +the point of Reflexion, shall still continue to return; and the Returns +shall be at distances from the point of Reflexion in the arithmetical +progression of the Numbers 2, 4, 6, 8, 10, 12, &c. and between these +Fits the Rays shall be in Fits of easy Transmission._ + +For since the Fits of easy Reflexion and easy Transmission are of a +returning nature, there is no reason why these Fits, which continued +till the Ray arrived at the reflecting Medium, and there inclined the +Ray to Reflexion, should there cease. And if the Ray at the point of +Reflexion was in a Fit of easy Reflexion, the progression of the +distances of these Fits from that point must begin from 0, and so be of +the Numbers 0, 2, 4, 6, 8, &c. And therefore the progression of the +distances of the intermediate Fits of easy Transmission, reckon'd from +the same point, must be in the progression of the odd Numbers 1, 3, 5, +7, 9, &c. contrary to what happens when the Fits are propagated from +points of Refraction. + + +PROP. XX. + +_The Intervals of the Fits of easy Reflexion and easy Transmission, +propagated from points of Reflexion into any Medium, are equal to the +Intervals of the like Fits, which the same Rays would have, if refracted +into the same Medium in Angles of Refraction equal to their Angles of +Reflexion._ + +For when Light is reflected by the second Surface of thin Plates, it +goes out afterwards freely at the first Surface to make the Rings of +Colours which appear by Reflexion; and, by the freedom of its egress, +makes the Colours of these Rings more vivid and strong than those which +appear on the other side of the Plates by the transmitted Light. The +reflected Rays are therefore in Fits of easy Transmission at their +egress; which would not always happen, if the Intervals of the Fits +within the Plate after Reflexion were not equal, both in length and +number, to their Intervals before it. And this confirms also the +proportions set down in the former Proposition. For if the Rays both in +going in and out at the first Surface be in Fits of easy Transmission, +and the Intervals and Numbers of those Fits between the first and second +Surface, before and after Reflexion, be equal, the distances of the Fits +of easy Transmission from either Surface, must be in the same +progression after Reflexion as before; that is, from the first Surface +which transmitted them in the progression of the even Numbers 0, 2, 4, +6, 8, &c. and from the second which reflected them, in that of the odd +Numbers 1, 3, 5, 7, &c. But these two Propositions will become much more +evident by the Observations in the following part of this Book. + + + + +THE + +SECOND BOOK + +OF + +OPTICKS + + +_PART IV._ + +_Observations concerning the Reflexions and Colours of thick transparent +polish'd Plates._ + +There is no Glass or Speculum how well soever polished, but, besides the +Light which it refracts or reflects regularly, scatters every way +irregularly a faint Light, by means of which the polish'd Surface, when +illuminated in a dark room by a beam of the Sun's Light, may be easily +seen in all positions of the Eye. There are certain Phænomena of this +scatter'd Light, which when I first observed them, seem'd very strange +and surprizing to me. My Observations were as follows. + +_Obs._ 1. The Sun shining into my darken'd Chamber through a hole one +third of an Inch wide, I let the intromitted beam of Light fall +perpendicularly upon a Glass Speculum ground concave on one side and +convex on the other, to a Sphere of five Feet and eleven Inches Radius, +and Quick-silver'd over on the convex side. And holding a white opake +Chart, or a Quire of Paper at the center of the Spheres to which the +Speculum was ground, that is, at the distance of about five Feet and +eleven Inches from the Speculum, in such manner, that the beam of Light +might pass through a little hole made in the middle of the Chart to the +Speculum, and thence be reflected back to the same hole: I observed upon +the Chart four or five concentric Irises or Rings of Colours, like +Rain-bows, encompassing the hole much after the manner that those, which +in the fourth and following Observations of the first part of this Book +appear'd between the Object-glasses, encompassed the black Spot, but yet +larger and fainter than those. These Rings as they grew larger and +larger became diluter and fainter, so that the fifth was scarce visible. +Yet sometimes, when the Sun shone very clear, there appear'd faint +Lineaments of a sixth and seventh. If the distance of the Chart from the +Speculum was much greater or much less than that of six Feet, the Rings +became dilute and vanish'd. And if the distance of the Speculum from the +Window was much greater than that of six Feet, the reflected beam of +Light would be so broad at the distance of six Feet from the Speculum +where the Rings appear'd, as to obscure one or two of the innermost +Rings. And therefore I usually placed the Speculum at about six Feet +from the Window; so that its Focus might there fall in with the center +of its concavity at the Rings upon the Chart. And this Posture is always +to be understood in the following Observations where no other is +express'd. + +_Obs._ 2. The Colours of these Rain-bows succeeded one another from the +center outwards, in the same form and order with those which were made +in the ninth Observation of the first Part of this Book by Light not +reflected, but transmitted through the two Object-glasses. For, first, +there was in their common center a white round Spot of faint Light, +something broader than the reflected beam of Light, which beam sometimes +fell upon the middle of the Spot, and sometimes by a little inclination +of the Speculum receded from the middle, and left the Spot white to the +center. + +This white Spot was immediately encompassed with a dark grey or russet, +and that dark grey with the Colours of the first Iris; which Colours on +the inside next the dark grey were a little violet and indigo, and next +to that a blue, which on the outside grew pale, and then succeeded a +little greenish yellow, and after that a brighter yellow, and then on +the outward edge of the Iris a red which on the outside inclined to +purple. + +This Iris was immediately encompassed with a second, whose Colours were +in order from the inside outwards, purple, blue, green, yellow, light +red, a red mix'd with purple. + +Then immediately follow'd the Colours of the third Iris, which were in +order outwards a green inclining to purple, a good green, and a red more +bright than that of the former Iris. + +The fourth and fifth Iris seem'd of a bluish green within, and red +without, but so faintly that it was difficult to discern the Colours. + +_Obs._ 3. Measuring the Diameters of these Rings upon the Chart as +accurately as I could, I found them also in the same proportion to one +another with the Rings made by Light transmitted through the two +Object-glasses. For the Diameters of the four first of the bright Rings +measured between the brightest parts of their Orbits, at the distance of +six Feet from the Speculum were 1-11/16, 2-3/8, 2-11/12, 3-3/8 Inches, +whose Squares are in arithmetical progression of the numbers 1, 2, 3, 4. +If the white circular Spot in the middle be reckon'd amongst the Rings, +and its central Light, where it seems to be most luminous, be put +equipollent to an infinitely little Ring; the Squares of the Diameters +of the Rings will be in the progression 0, 1, 2, 3, 4, &c. I measured +also the Diameters of the dark Circles between these luminous ones, and +found their Squares in the progression of the numbers 1/2, 1-1/2, 2-1/2, +3-1/2, &c. the Diameters of the first four at the distance of six Feet +from the Speculum, being 1-3/16, 2-1/16, 2-2/3, 3-3/20 Inches. If the +distance of the Chart from the Speculum was increased or diminished, the +Diameters of the Circles were increased or diminished proportionally. + +_Obs._ 4. By the analogy between these Rings and those described in the +Observations of the first Part of this Book, I suspected that there +were many more of them which spread into one another, and by interfering +mix'd their Colours, and diluted one another so that they could not be +seen apart. I viewed them therefore through a Prism, as I did those in +the 24th Observation of the first Part of this Book. And when the Prism +was so placed as by refracting the Light of their mix'd Colours to +separate them, and distinguish the Rings from one another, as it did +those in that Observation, I could then see them distincter than before, +and easily number eight or nine of them, and sometimes twelve or +thirteen. And had not their Light been so very faint, I question not but +that I might have seen many more. + +_Obs._ 5. Placing a Prism at the Window to refract the intromitted beam +of Light, and cast the oblong Spectrum of Colours on the Speculum: I +covered the Speculum with a black Paper which had in the middle of it a +hole to let any one of the Colours pass through to the Speculum, whilst +the rest were intercepted by the Paper. And now I found Rings of that +Colour only which fell upon the Speculum. If the Speculum was +illuminated with red, the Rings were totally red with dark Intervals, if +with blue they were totally blue, and so of the other Colours. And when +they were illuminated with any one Colour, the Squares of their +Diameters measured between their most luminous Parts, were in the +arithmetical Progression of the Numbers, 0, 1, 2, 3, 4 and the Squares +of the Diameters of their dark Intervals in the Progression of the +intermediate Numbers 1/2, 1-1/2, 2-1/2, 3-1/2. But if the Colour was +varied, they varied their Magnitude. In the red they were largest, in +the indigo and violet least, and in the intermediate Colours yellow, +green, and blue, they were of several intermediate Bignesses answering +to the Colour, that is, greater in yellow than in green, and greater in +green than in blue. And hence I knew, that when the Speculum was +illuminated with white Light, the red and yellow on the outside of the +Rings were produced by the least refrangible Rays, and the blue and +violet by the most refrangible, and that the Colours of each Ring spread +into the Colours of the neighbouring Rings on either side, after the +manner explain'd in the first and second Part of this Book, and by +mixing diluted one another so that they could not be distinguish'd, +unless near the Center where they were least mix'd. For in this +Observation I could see the Rings more distinctly, and to a greater +Number than before, being able in the yellow Light to number eight or +nine of them, besides a faint shadow of a tenth. To satisfy my self how +much the Colours of the several Rings spread into one another, I +measured the Diameters of the second and third Rings, and found them +when made by the Confine of the red and orange to be to the same +Diameters when made by the Confine of blue and indigo, as 9 to 8, or +thereabouts. For it was hard to determine this Proportion accurately. +Also the Circles made successively by the red, yellow, and green, +differ'd more from one another than those made successively by the +green, blue, and indigo. For the Circle made by the violet was too dark +to be seen. To carry on the Computation, let us therefore suppose that +the Differences of the Diameters of the Circles made by the outmost red, +the Confine of red and orange, the Confine of orange and yellow, the +Confine of yellow and green, the Confine of green and blue, the Confine +of blue and indigo, the Confine of indigo and violet, and outmost +violet, are in proportion as the Differences of the Lengths of a +Monochord which sound the Tones in an Eight; _sol_, _la_, _fa_, _sol_, +_la_, _mi_, _fa_, _sol_, that is, as the Numbers 1/9, 1/18, 1/12, 1/12, +2/27, 1/27, 1/18. And if the Diameter of the Circle made by the Confine +of red and orange be 9A, and that of the Circle made by the Confine of +blue and indigo be 8A as above; their difference 9A-8A will be to the +difference of the Diameters of the Circles made by the outmost red, and +by the Confine of red and orange, as 1/18 + 1/12 + 1/12 + 2/27 to 1/9, +that is as 8/27 to 1/9, or 8 to 3, and to the difference of the Circles +made by the outmost violet, and by the Confine of blue and indigo, as +1/18 + 1/12 + 1/12 + 2/27 to 1/27 + 1/18, that is, as 8/27 to 5/54, or +as 16 to 5. And therefore these differences will be 3/8A and 5/16A. Add +the first to 9A and subduct the last from 8A, and you will have the +Diameters of the Circles made by the least and most refrangible Rays +75/8A and ((61-1/2)/8)A. These diameters are therefore to one another as +75 to 61-1/2 or 50 to 41, and their Squares as 2500 to 1681, that is, as +3 to 2 very nearly. Which proportion differs not much from the +proportion of the Diameters of the Circles made by the outmost red and +outmost violet, in the 13th Observation of the first part of this Book. + +_Obs._ 6. Placing my Eye where these Rings appear'd plainest, I saw the +Speculum tinged all over with Waves of Colours, (red, yellow, green, +blue;) like those which in the Observations of the first part of this +Book appeared between the Object-glasses, and upon Bubbles of Water, but +much larger. And after the manner of those, they were of various +magnitudes in various Positions of the Eye, swelling and shrinking as I +moved my Eye this way and that way. They were formed like Arcs of +concentrick Circles, as those were; and when my Eye was over against the +center of the concavity of the Speculum, (that is, 5 Feet and 10 Inches +distant from the Speculum,) their common center was in a right Line with +that center of concavity, and with the hole in the Window. But in other +postures of my Eye their center had other positions. They appear'd by +the Light of the Clouds propagated to the Speculum through the hole in +the Window; and when the Sun shone through that hole upon the Speculum, +his Light upon it was of the Colour of the Ring whereon it fell, but by +its splendor obscured the Rings made by the Light of the Clouds, unless +when the Speculum was removed to a great distance from the Window, so +that his Light upon it might be broad and faint. By varying the position +of my Eye, and moving it nearer to or farther from the direct beam of +the Sun's Light, the Colour of the Sun's reflected Light constantly +varied upon the Speculum, as it did upon my Eye, the same Colour always +appearing to a Bystander upon my Eye which to me appear'd upon the +Speculum. And thence I knew that the Rings of Colours upon the Chart +were made by these reflected Colours, propagated thither from the +Speculum in several Angles, and that their production depended not upon +the termination of Light and Shadow. + +_Obs._ 7. By the Analogy of all these Phænomena with those of the like +Rings of Colours described in the first part of this Book, it seemed to +me that these Colours were produced by this thick Plate of Glass, much +after the manner that those were produced by very thin Plates. For, upon +trial, I found that if the Quick-silver were rubb'd off from the +backside of the Speculum, the Glass alone would cause the same Rings of +Colours, but much more faint than before; and therefore the Phænomenon +depends not upon the Quick-silver, unless so far as the Quick-silver by +increasing the Reflexion of the backside of the Glass increases the +Light of the Rings of Colours. I found also that a Speculum of Metal +without Glass made some Years since for optical uses, and very well +wrought, produced none of those Rings; and thence I understood that +these Rings arise not from one specular Surface alone, but depend upon +the two Surfaces of the Plate of Glass whereof the Speculum was made, +and upon the thickness of the Glass between them. For as in the 7th and +19th Observations of the first part of this Book a thin Plate of Air, +Water, or Glass of an even thickness appeared of one Colour when the +Rays were perpendicular to it, of another when they were a little +oblique, of another when more oblique, of another when still more +oblique, and so on; so here, in the sixth Observation, the Light which +emerged out of the Glass in several Obliquities, made the Glass appear +of several Colours, and being propagated in those Obliquities to the +Chart, there painted Rings of those Colours. And as the reason why a +thin Plate appeared of several Colours in several Obliquities of the +Rays, was, that the Rays of one and the same sort are reflected by the +thin Plate at one obliquity and transmitted at another, and those of +other sorts transmitted where these are reflected, and reflected where +these are transmitted: So the reason why the thick Plate of Glass +whereof the Speculum was made did appear of various Colours in various +Obliquities, and in those Obliquities propagated those Colours to the +Chart, was, that the Rays of one and the same sort did at one Obliquity +emerge out of the Glass, at another did not emerge, but were reflected +back towards the Quick-silver by the hither Surface of the Glass, and +accordingly as the Obliquity became greater and greater, emerged and +were reflected alternately for many Successions; and that in one and the +same Obliquity the Rays of one sort were reflected, and those of another +transmitted. This is manifest by the fifth Observation of this part of +this Book. For in that Observation, when the Speculum was illuminated by +any one of the prismatick Colours, that Light made many Rings of the +same Colour upon the Chart with dark Intervals, and therefore at its +emergence out of the Speculum was alternately transmitted and not +transmitted from the Speculum to the Chart for many Successions, +according to the various Obliquities of its Emergence. And when the +Colour cast on the Speculum by the Prism was varied, the Rings became of +the Colour cast on it, and varied their bigness with their Colour, and +therefore the Light was now alternately transmitted and not transmitted +from the Speculum to the Chart at other Obliquities than before. It +seemed to me therefore that these Rings were of one and the same +original with those of thin Plates, but yet with this difference, that +those of thin Plates are made by the alternate Reflexions and +Transmissions of the Rays at the second Surface of the Plate, after one +passage through it; but here the Rays go twice through the Plate before +they are alternately reflected and transmitted. First, they go through +it from the first Surface to the Quick-silver, and then return through +it from the Quick-silver to the first Surface, and there are either +transmitted to the Chart or reflected back to the Quick-silver, +accordingly as they are in their Fits of easy Reflexion or Transmission +when they arrive at that Surface. For the Intervals of the Fits of the +Rays which fall perpendicularly on the Speculum, and are reflected back +in the same perpendicular Lines, by reason of the equality of these +Angles and Lines, are of the same length and number within the Glass +after Reflexion as before, by the 19th Proposition of the third part of +this Book. And therefore since all the Rays that enter through the +first Surface are in their Fits of easy Transmission at their entrance, +and as many of these as are reflected by the second are in their Fits of +easy Reflexion there, all these must be again in their Fits of easy +Transmission at their return to the first, and by consequence there go +out of the Glass to the Chart, and form upon it the white Spot of Light +in the center of the Rings. For the reason holds good in all sorts of +Rays, and therefore all sorts must go out promiscuously to that Spot, +and by their mixture cause it to be white. But the Intervals of the Fits +of those Rays which are reflected more obliquely than they enter, must +be greater after Reflexion than before, by the 15th and 20th +Propositions. And thence it may happen that the Rays at their return to +the first Surface, may in certain Obliquities be in Fits of easy +Reflexion, and return back to the Quick-silver, and in other +intermediate Obliquities be again in Fits of easy Transmission, and so +go out to the Chart, and paint on it the Rings of Colours about the +white Spot. And because the Intervals of the Fits at equal obliquities +are greater and fewer in the less refrangible Rays, and less and more +numerous in the more refrangible, therefore the less refrangible at +equal obliquities shall make fewer Rings than the more refrangible, and +the Rings made by those shall be larger than the like number of Rings +made by these; that is, the red Rings shall be larger than the yellow, +the yellow than the green, the green than the blue, and the blue than +the violet, as they were really found to be in the fifth Observation. +And therefore the first Ring of all Colours encompassing the white Spot +of Light shall be red without any violet within, and yellow, and green, +and blue in the middle, as it was found in the second Observation; and +these Colours in the second Ring, and those that follow, shall be more +expanded, till they spread into one another, and blend one another by +interfering. + +These seem to be the reasons of these Rings in general; and this put me +upon observing the thickness of the Glass, and considering whether the +dimensions and proportions of the Rings may be truly derived from it by +computation. + +_Obs._ 8. I measured therefore the thickness of this concavo-convex +Plate of Glass, and found it every where 1/4 of an Inch precisely. Now, +by the sixth Observation of the first Part of this Book, a thin Plate of +Air transmits the brightest Light of the first Ring, that is, the bright +yellow, when its thickness is the 1/89000th part of an Inch; and by the +tenth Observation of the same Part, a thin Plate of Glass transmits the +same Light of the same Ring, when its thickness is less in proportion of +the Sine of Refraction to the Sine of Incidence, that is, when its +thickness is the 11/1513000th or 1/137545th part of an Inch, supposing +the Sines are as 11 to 17. And if this thickness be doubled, it +transmits the same bright Light of the second Ring; if tripled, it +transmits that of the third, and so on; the bright yellow Light in all +these cases being in its Fits of Transmission. And therefore if its +thickness be multiplied 34386 times, so as to become 1/4 of an Inch, it +transmits the same bright Light of the 34386th Ring. Suppose this be the +bright yellow Light transmitted perpendicularly from the reflecting +convex side of the Glass through the concave side to the white Spot in +the center of the Rings of Colours on the Chart: And by a Rule in the +7th and 19th Observations in the first Part of this Book, and by the +15th and 20th Propositions of the third Part of this Book, if the Rays +be made oblique to the Glass, the thickness of the Glass requisite to +transmit the same bright Light of the same Ring in any obliquity, is to +this thickness of 1/4 of an Inch, as the Secant of a certain Angle to +the Radius, the Sine of which Angle is the first of an hundred and six +arithmetical Means between the Sines of Incidence and Refraction, +counted from the Sine of Incidence when the Refraction is made out of +any plated Body into any Medium encompassing it; that is, in this case, +out of Glass into Air. Now if the thickness of the Glass be increased by +degrees, so as to bear to its first thickness, (_viz._ that of a quarter +of an Inch,) the Proportions which 34386 (the number of Fits of the +perpendicular Rays in going through the Glass towards the white Spot in +the center of the Rings,) hath to 34385, 34384, 34383, and 34382, (the +numbers of the Fits of the oblique Rays in going through the Glass +towards the first, second, third, and fourth Rings of Colours,) and if +the first thickness be divided into 100000000 equal parts, the increased +thicknesses will be 100002908, 100005816, 100008725, and 100011633, and +the Angles of which these thicknesses are Secants will be 26´ 13´´, 37´ +5´´, 45´ 6´´, and 52´ 26´´, the Radius being 100000000; and the Sines of +these Angles are 762, 1079, 1321, and 1525, and the proportional Sines +of Refraction 1172, 1659, 2031, and 2345, the Radius being 100000. For +since the Sines of Incidence out of Glass into Air are to the Sines of +Refraction as 11 to 17, and to the above-mentioned Secants as 11 to the +first of 106 arithmetical Means between 11 and 17, that is, as 11 to +11-6/106, those Secants will be to the Sines of Refraction as 11-6/106, +to 17, and by this Analogy will give these Sines. So then, if the +obliquities of the Rays to the concave Surface of the Glass be such that +the Sines of their Refraction in passing out of the Glass through that +Surface into the Air be 1172, 1659, 2031, 2345, the bright Light of the +34386th Ring shall emerge at the thicknesses of the Glass, which are to +1/4 of an Inch as 34386 to 34385, 34384, 34383, 34382, respectively. And +therefore, if the thickness in all these Cases be 1/4 of an Inch (as it +is in the Glass of which the Speculum was made) the bright Light of the +34385th Ring shall emerge where the Sine of Refraction is 1172, and that +of the 34384th, 34383th, and 34382th Ring where the Sine is 1659, 2031, +and 2345 respectively. And in these Angles of Refraction the Light of +these Rings shall be propagated from the Speculum to the Chart, and +there paint Rings about the white central round Spot of Light which we +said was the Light of the 34386th Ring. And the Semidiameters of these +Rings shall subtend the Angles of Refraction made at the +Concave-Surface of the Speculum, and by consequence their Diameters +shall be to the distance of the Chart from the Speculum as those Sines +of Refraction doubled are to the Radius, that is, as 1172, 1659, 2031, +and 2345, doubled are to 100000. And therefore, if the distance of the +Chart from the Concave-Surface of the Speculum be six Feet (as it was in +the third of these Observations) the Diameters of the Rings of this +bright yellow Light upon the Chart shall be 1'688, 2'389, 2'925, 3'375 +Inches: For these Diameters are to six Feet, as the above-mention'd +Sines doubled are to the Radius. Now, these Diameters of the bright +yellow Rings, thus found by Computation are the very same with those +found in the third of these Observations by measuring them, _viz._ with +1-11/16, 2-3/8, 2-11/12, and 3-3/8 Inches, and therefore the Theory of +deriving these Rings from the thickness of the Plate of Glass of which +the Speculum was made, and from the Obliquity of the emerging Rays +agrees with the Observation. In this Computation I have equalled the +Diameters of the bright Rings made by Light of all Colours, to the +Diameters of the Rings made by the bright yellow. For this yellow makes +the brightest Part of the Rings of all Colours. If you desire the +Diameters of the Rings made by the Light of any other unmix'd Colour, +you may find them readily by putting them to the Diameters of the bright +yellow ones in a subduplicate Proportion of the Intervals of the Fits of +the Rays of those Colours when equally inclined to the refracting or +reflecting Surface which caused those Fits, that is, by putting the +Diameters of the Rings made by the Rays in the Extremities and Limits of +the seven Colours, red, orange, yellow, green, blue, indigo, violet, +proportional to the Cube-roots of the Numbers, 1, 8/9, 5/6, 3/4, 2/3, +3/5, 9/16, 1/2, which express the Lengths of a Monochord sounding the +Notes in an Eighth: For by this means the Diameters of the Rings of +these Colours will be found pretty nearly in the same Proportion to one +another, which they ought to have by the fifth of these Observations. + +And thus I satisfy'd my self, that these Rings were of the same kind and +Original with those of thin Plates, and by consequence that the Fits or +alternate Dispositions of the Rays to be reflected and transmitted are +propagated to great distances from every reflecting and refracting +Surface. But yet to put the matter out of doubt, I added the following +Observation. + +_Obs._ 9. If these Rings thus depend on the thickness of the Plate of +Glass, their Diameters at equal distances from several Speculums made of +such concavo-convex Plates of Glass as are ground on the same Sphere, +ought to be reciprocally in a subduplicate Proportion of the thicknesses +of the Plates of Glass. And if this Proportion be found true by +experience it will amount to a demonstration that these Rings (like +those formed in thin Plates) do depend on the thickness of the Glass. I +procured therefore another concavo-convex Plate of Glass ground on both +sides to the same Sphere with the former Plate. Its thickness was 5/62 +Parts of an Inch; and the Diameters of the three first bright Rings +measured between the brightest Parts of their Orbits at the distance of +six Feet from the Glass were 3·4-1/6·5-1/8· Inches. Now, the thickness +of the other Glass being 1/4 of an Inch was to the thickness of this +Glass as 1/4 to 5/62, that is as 31 to 10, or 310000000 to 100000000, +and the Roots of these Numbers are 17607 and 10000, and in the +Proportion of the first of these Roots to the second are the Diameters +of the bright Rings made in this Observation by the thinner Glass, +3·4-1/6·5-1/8, to the Diameters of the same Rings made in the third of +these Observations by the thicker Glass 1-11/16, 2-3/8. 2-11/12, that +is, the Diameters of the Rings are reciprocally in a subduplicate +Proportion of the thicknesses of the Plates of Glass. + +So then in Plates of Glass which are alike concave on one side, and +alike convex on the other side, and alike quick-silver'd on the convex +sides, and differ in nothing but their thickness, the Diameters of the +Rings are reciprocally in a subduplicate Proportion of the thicknesses +of the Plates. And this shews sufficiently that the Rings depend on both +the Surfaces of the Glass. They depend on the convex Surface, because +they are more luminous when that Surface is quick-silver'd over than +when it is without Quick-silver. They depend also upon the concave +Surface, because without that Surface a Speculum makes them not. They +depend on both Surfaces, and on the distances between them, because +their bigness is varied by varying only that distance. And this +dependence is of the same kind with that which the Colours of thin +Plates have on the distance of the Surfaces of those Plates, because the +bigness of the Rings, and their Proportion to one another, and the +variation of their bigness arising from the variation of the thickness +of the Glass, and the Orders of their Colours, is such as ought to +result from the Propositions in the end of the third Part of this Book, +derived from the Phænomena of the Colours of thin Plates set down in the +first Part. + +There are yet other Phænomena of these Rings of Colours, but such as +follow from the same Propositions, and therefore confirm both the Truth +of those Propositions, and the Analogy between these Rings and the Rings +of Colours made by very thin Plates. I shall subjoin some of them. + +_Obs._ 10. When the beam of the Sun's Light was reflected back from the +Speculum not directly to the hole in the Window, but to a place a little +distant from it, the common center of that Spot, and of all the Rings of +Colours fell in the middle way between the beam of the incident Light, +and the beam of the reflected Light, and by consequence in the center of +the spherical concavity of the Speculum, whenever the Chart on which the +Rings of Colours fell was placed at that center. And as the beam of +reflected Light by inclining the Speculum receded more and more from the +beam of incident Light and from the common center of the colour'd Rings +between them, those Rings grew bigger and bigger, and so also did the +white round Spot, and new Rings of Colours emerged successively out of +their common center, and the white Spot became a white Ring +encompassing them; and the incident and reflected beams of Light always +fell upon the opposite parts of this white Ring, illuminating its +Perimeter like two mock Suns in the opposite parts of an Iris. So then +the Diameter of this Ring, measured from the middle of its Light on one +side to the middle of its Light on the other side, was always equal to +the distance between the middle of the incident beam of Light, and the +middle of the reflected beam measured at the Chart on which the Rings +appeared: And the Rays which form'd this Ring were reflected by the +Speculum in Angles equal to their Angles of Incidence, and by +consequence to their Angles of Refraction at their entrance into the +Glass, but yet their Angles of Reflexion were not in the same Planes +with their Angles of Incidence. + +_Obs._ 11. The Colours of the new Rings were in a contrary order to +those of the former, and arose after this manner. The white round Spot +of Light in the middle of the Rings continued white to the center till +the distance of the incident and reflected beams at the Chart was about +7/8 parts of an Inch, and then it began to grow dark in the middle. And +when that distance was about 1-3/16 of an Inch, the white Spot was +become a Ring encompassing a dark round Spot which in the middle +inclined to violet and indigo. And the luminous Rings encompassing it +were grown equal to those dark ones which in the four first Observations +encompassed them, that is to say, the white Spot was grown a white Ring +equal to the first of those dark Rings, and the first of those luminous +Rings was now grown equal to the second of those dark ones, and the +second of those luminous ones to the third of those dark ones, and so +on. For the Diameters of the luminous Rings were now 1-3/16, 2-1/16, +2-2/3, 3-3/20, &c. Inches. + +When the distance between the incident and reflected beams of Light +became a little bigger, there emerged out of the middle of the dark Spot +after the indigo a blue, and then out of that blue a pale green, and +soon after a yellow and red. And when the Colour at the center was +brightest, being between yellow and red, the bright Rings were grown +equal to those Rings which in the four first Observations next +encompassed them; that is to say, the white Spot in the middle of those +Rings was now become a white Ring equal to the first of those bright +Rings, and the first of those bright ones was now become equal to the +second of those, and so on. For the Diameters of the white Ring, and of +the other luminous Rings encompassing it, were now 1-11/16, 2-3/8, +2-11/12, 3-3/8, &c. or thereabouts. + +When the distance of the two beams of Light at the Chart was a little +more increased, there emerged out of the middle in order after the red, +a purple, a blue, a green, a yellow, and a red inclining much to purple, +and when the Colour was brightest being between yellow and red, the +former indigo, blue, green, yellow and red, were become an Iris or Ring +of Colours equal to the first of those luminous Rings which appeared in +the four first Observations, and the white Ring which was now become +the second of the luminous Rings was grown equal to the second of those, +and the first of those which was now become the third Ring was become +equal to the third of those, and so on. For their Diameters were +1-11/16, 2-3/8, 2-11/12, 3-3/8 Inches, the distance of the two beams of +Light, and the Diameter of the white Ring being 2-3/8 Inches. + +When these two beams became more distant there emerged out of the middle +of the purplish red, first a darker round Spot, and then out of the +middle of that Spot a brighter. And now the former Colours (purple, +blue, green, yellow, and purplish red) were become a Ring equal to the +first of the bright Rings mentioned in the four first Observations, and +the Rings about this Ring were grown equal to the Rings about that +respectively; the distance between the two beams of Light and the +Diameter of the white Ring (which was now become the third Ring) being +about 3 Inches. + +The Colours of the Rings in the middle began now to grow very dilute, +and if the distance between the two Beams was increased half an Inch, or +an Inch more, they vanish'd whilst the white Ring, with one or two of +the Rings next it on either side, continued still visible. But if the +distance of the two beams of Light was still more increased, these also +vanished: For the Light which coming from several parts of the hole in +the Window fell upon the Speculum in several Angles of Incidence, made +Rings of several bignesses, which diluted and blotted out one another, +as I knew by intercepting some part of that Light. For if I intercepted +that part which was nearest to the Axis of the Speculum the Rings would +be less, if the other part which was remotest from it they would be +bigger. + +_Obs._ 12. When the Colours of the Prism were cast successively on the +Speculum, that Ring which in the two last Observations was white, was of +the same bigness in all the Colours, but the Rings without it were +greater in the green than in the blue, and still greater in the yellow, +and greatest in the red. And, on the contrary, the Rings within that +white Circle were less in the green than in the blue, and still less in +the yellow, and least in the red. For the Angles of Reflexion of those +Rays which made this Ring, being equal to their Angles of Incidence, the +Fits of every reflected Ray within the Glass after Reflexion are equal +in length and number to the Fits of the same Ray within the Glass before +its Incidence on the reflecting Surface. And therefore since all the +Rays of all sorts at their entrance into the Glass were in a Fit of +Transmission, they were also in a Fit of Transmission at their returning +to the same Surface after Reflexion; and by consequence were +transmitted, and went out to the white Ring on the Chart. This is the +reason why that Ring was of the same bigness in all the Colours, and why +in a mixture of all it appears white. But in Rays which are reflected in +other Angles, the Intervals of the Fits of the least refrangible being +greatest, make the Rings of their Colour in their progress from this +white Ring, either outwards or inwards, increase or decrease by the +greatest steps; so that the Rings of this Colour without are greatest, +and within least. And this is the reason why in the last Observation, +when the Speculum was illuminated with white Light, the exterior Rings +made by all Colours appeared red without and blue within, and the +interior blue without and red within. + +These are the Phænomena of thick convexo-concave Plates of Glass, which +are every where of the same thickness. There are yet other Phænomena +when these Plates are a little thicker on one side than on the other, +and others when the Plates are more or less concave than convex, or +plano-convex, or double-convex. For in all these cases the Plates make +Rings of Colours, but after various manners; all which, so far as I have +yet observed, follow from the Propositions in the end of the third part +of this Book, and so conspire to confirm the truth of those +Propositions. But the Phænomena are too various, and the Calculations +whereby they follow from those Propositions too intricate to be here +prosecuted. I content my self with having prosecuted this kind of +Phænomena so far as to discover their Cause, and by discovering it to +ratify the Propositions in the third Part of this Book. + +_Obs._ 13. As Light reflected by a Lens quick-silver'd on the backside +makes the Rings of Colours above described, so it ought to make the like +Rings of Colours in passing through a drop of Water. At the first +Reflexion of the Rays within the drop, some Colours ought to be +transmitted, as in the case of a Lens, and others to be reflected back +to the Eye. For instance, if the Diameter of a small drop or globule of +Water be about the 500th part of an Inch, so that a red-making Ray in +passing through the middle of this globule has 250 Fits of easy +Transmission within the globule, and that all the red-making Rays which +are at a certain distance from this middle Ray round about it have 249 +Fits within the globule, and all the like Rays at a certain farther +distance round about it have 248 Fits, and all those at a certain +farther distance 247 Fits, and so on; these concentrick Circles of Rays +after their transmission, falling on a white Paper, will make +concentrick Rings of red upon the Paper, supposing the Light which +passes through one single globule, strong enough to be sensible. And, in +like manner, the Rays of other Colours will make Rings of other Colours. +Suppose now that in a fair Day the Sun shines through a thin Cloud of +such globules of Water or Hail, and that the globules are all of the +same bigness; and the Sun seen through this Cloud shall appear +encompassed with the like concentrick Rings of Colours, and the Diameter +of the first Ring of red shall be 7-1/4 Degrees, that of the second +10-1/4 Degrees, that of the third 12 Degrees 33 Minutes. And accordingly +as the Globules of Water are bigger or less, the Rings shall be less or +bigger. This is the Theory, and Experience answers it. For in _June_ +1692, I saw by reflexion in a Vessel of stagnating Water three Halos, +Crowns, or Rings of Colours about the Sun, like three little Rain-bows, +concentrick to his Body. The Colours of the first or innermost Crown +were blue next the Sun, red without, and white in the middle between the +blue and red. Those of the second Crown were purple and blue within, and +pale red without, and green in the middle. And those of the third were +pale blue within, and pale red without; these Crowns enclosed one +another immediately, so that their Colours proceeded in this continual +order from the Sun outward: blue, white, red; purple, blue, green, pale +yellow and red; pale blue, pale red. The Diameter of the second Crown +measured from the middle of the yellow and red on one side of the Sun, +to the middle of the same Colour on the other side was 9-1/3 Degrees, or +thereabouts. The Diameters of the first and third I had not time to +measure, but that of the first seemed to be about five or six Degrees, +and that of the third about twelve. The like Crowns appear sometimes +about the Moon; for in the beginning of the Year 1664, _Febr._ 19th at +Night, I saw two such Crowns about her. The Diameter of the first or +innermost was about three Degrees, and that of the second about five +Degrees and an half. Next about the Moon was a Circle of white, and next +about that the inner Crown, which was of a bluish green within next the +white, and of a yellow and red without, and next about these Colours +were blue and green on the inside of the outward Crown, and red on the +outside of it. At the same time there appear'd a Halo about 22 Degrees +35´ distant from the center of the Moon. It was elliptical, and its long +Diameter was perpendicular to the Horizon, verging below farthest from +the Moon. I am told that the Moon has sometimes three or more +concentrick Crowns of Colours encompassing one another next about her +Body. The more equal the globules of Water or Ice are to one another, +the more Crowns of Colours will appear, and the Colours will be the more +lively. The Halo at the distance of 22-1/2 Degrees from the Moon is of +another sort. By its being oval and remoter from the Moon below than +above, I conclude, that it was made by Refraction in some sort of Hail +or Snow floating in the Air in an horizontal posture, the refracting +Angle being about 58 or 60 Degrees. + + + + +THE + +THIRD BOOK + +OF + +OPTICKS + + +_PART I._ + +_Observations concerning the Inflexions of the Rays of Light, and the +Colours made thereby._ + +Grimaldo has inform'd us, that if a beam of the Sun's Light be let into +a dark Room through a very small hole, the Shadows of things in this +Light will be larger than they ought to be if the Rays went on by the +Bodies in straight Lines, and that these Shadows have three parallel +Fringes, Bands or Ranks of colour'd Light adjacent to them. But if the +Hole be enlarged the Fringes grow broad and run into one another, so +that they cannot be distinguish'd. These broad Shadows and Fringes have +been reckon'd by some to proceed from the ordinary refraction of the +Air, but without due examination of the Matter. For the circumstances of +the Phænomenon, so far as I have observed them, are as follows. + +_Obs._ 1. I made in a piece of Lead a small Hole with a Pin, whose +breadth was the 42d part of an Inch. For 21 of those Pins laid together +took up the breadth of half an Inch. Through this Hole I let into my +darken'd Chamber a beam of the Sun's Light, and found that the Shadows +of Hairs, Thred, Pins, Straws, and such like slender Substances placed +in this beam of Light, were considerably broader than they ought to be, +if the Rays of Light passed on by these Bodies in right Lines. And +particularly a Hair of a Man's Head, whose breadth was but the 280th +part of an Inch, being held in this Light, at the distance of about +twelve Feet from the Hole, did cast a Shadow which at the distance of +four Inches from the Hair was the sixtieth part of an Inch broad, that +is, above four times broader than the Hair, and at the distance of two +Feet from the Hair was about the eight and twentieth part of an Inch +broad, that is, ten times broader than the Hair, and at the distance of +ten Feet was the eighth part of an Inch broad, that is 35 times broader. + +Nor is it material whether the Hair be encompassed with Air, or with any +other pellucid Substance. For I wetted a polish'd Plate of Glass, and +laid the Hair in the Water upon the Glass, and then laying another +polish'd Plate of Glass upon it, so that the Water might fill up the +space between the Glasses, I held them in the aforesaid beam of Light, +so that the Light might pass through them perpendicularly, and the +Shadow of the Hair was at the same distances as big as before. The +Shadows of Scratches made in polish'd Plates of Glass were also much +broader than they ought to be, and the Veins in polish'd Plates of Glass +did also cast the like broad Shadows. And therefore the great breadth of +these Shadows proceeds from some other cause than the Refraction of the +Air. + +Let the Circle X [in _Fig._ 1.] represent the middle of the Hair; ADG, +BEH, CFI, three Rays passing by one side of the Hair at several +distances; KNQ, LOR, MPS, three other Rays passing by the other side of +the Hair at the like distances; D, E, F, and N, O, P, the places where +the Rays are bent in their passage by the Hair; G, H, I, and Q, R, S, +the places where the Rays fall on a Paper GQ; IS the breadth of the +Shadow of the Hair cast on the Paper, and TI, VS, two Rays passing to +the Points I and S without bending when the Hair is taken away. And it's +manifest that all the Light between these two Rays TI and VS is bent in +passing by the Hair, and turned aside from the Shadow IS, because if any +part of this Light were not bent it would fall on the Paper within the +Shadow, and there illuminate the Paper, contrary to experience. And +because when the Paper is at a great distance from the Hair, the Shadow +is broad, and therefore the Rays TI and VS are at a great distance from +one another, it follows that the Hair acts upon the Rays of Light at a +good distance in their passing by it. But the Action is strongest on the +Rays which pass by at least distances, and grows weaker and weaker +accordingly as the Rays pass by at distances greater and greater, as is +represented in the Scheme: For thence it comes to pass, that the Shadow +of the Hair is much broader in proportion to the distance of the Paper +from the Hair, when the Paper is nearer the Hair, than when it is at a +great distance from it. + +_Obs._ 2. The Shadows of all Bodies (Metals, Stones, Glass, Wood, Horn, +Ice, &c.) in this Light were border'd with three Parallel Fringes or +Bands of colour'd Light, whereof that which was contiguous to the Shadow +was broadest and most luminous, and that which was remotest from it was +narrowest, and so faint, as not easily to be visible. It was difficult +to distinguish the Colours, unless when the Light fell very obliquely +upon a smooth Paper, or some other smooth white Body, so as to make them +appear much broader than they would otherwise do. And then the Colours +were plainly visible in this Order: The first or innermost Fringe was +violet and deep blue next the Shadow, and then light blue, green, and +yellow in the middle, and red without. The second Fringe was almost +contiguous to the first, and the third to the second, and both were blue +within, and yellow and red without, but their Colours were very faint, +especially those of the third. The Colours therefore proceeded in this +order from the Shadow; violet, indigo, pale blue, green, yellow, red; +blue, yellow, red; pale blue, pale yellow and red. The Shadows made by +Scratches and Bubbles in polish'd Plates of Glass were border'd with the +like Fringes of colour'd Light. And if Plates of Looking-glass sloop'd +off near the edges with a Diamond-cut, be held in the same beam of +Light, the Light which passes through the parallel Planes of the Glass +will be border'd with the like Fringes of Colours where those Planes +meet with the Diamond-cut, and by this means there will sometimes appear +four or five Fringes of Colours. Let AB, CD [in _Fig._ 2.] represent the +parallel Planes of a Looking-glass, and BD the Plane of the Diamond-cut, +making at B a very obtuse Angle with the Plane AB. And let all the Light +between the Rays ENI and FBM pass directly through the parallel Planes +of the Glass, and fall upon the Paper between I and M, and all the Light +between the Rays GO and HD be refracted by the oblique Plane of the +Diamond-cut BD, and fall upon the Paper between K and L; and the Light +which passes directly through the parallel Planes of the Glass, and +falls upon the Paper between I and M, will be border'd with three or +more Fringes at M. + +[Illustration: FIG. 1.] + +[Illustration: FIG. 2.] + +So by looking on the Sun through a Feather or black Ribband held close +to the Eye, several Rain-bows will appear; the Shadows which the Fibres +or Threds cast on the _Tunica Retina_, being border'd with the like +Fringes of Colours. + +_Obs._ 3. When the Hair was twelve Feet distant from this Hole, and its +Shadow fell obliquely upon a flat white Scale of Inches and Parts of an +Inch placed half a Foot beyond it, and also when the Shadow fell +perpendicularly upon the same Scale placed nine Feet beyond it; I +measured the breadth of the Shadow and Fringes as accurately as I could, +and found them in Parts of an Inch as follows. + +-------------------------------------------+-----------+-------- + | half a | Nine + At the Distance of | Foot | Feet +-------------------------------------------+-----------+-------- +The breadth of the Shadow | 1/54 | 1/9 +-------------------------------------------+-----------+-------- +The breadth between the Middles of the | 1/38 | + brightest Light of the innermost Fringes | or | + on either side the Shadow | 1/39 | 7/50 +-------------------------------------------+-----------+-------- +The breadth between the Middles of the | | + brightest Light of the middlemost Fringes| | + on either side the Shadow | 1/23-1/2 | 4/17 +-------------------------------------------+-----------+-------- +The breadth between the Middles of the | 1/18 | + brightest Light of the outmost Fringes | or | + on either side the Shadow | 1/18-1/2 | 3/10 +-------------------------------------------+-----------+-------- +The distance between the Middles of the | | + brightest Light of the first and second | | + Fringes | 1/120 | 1/21 +-------------------------------------------+-----------+-------- +The distance between the Middles of the | | + brightest Light of the second and third | | + Fringes | 1/170 | 1/31 +-------------------------------------------+-----------+-------- +The breadth of the luminous Part (green, | | + white, yellow, and red) of the first | | + Fringe | 1/170 | 1/32 +-------------------------------------------+-----------+-------- +The breadth of the darker Space between | | + the first and second Fringes | 1/240 | 1/45 +-------------------------------------------+-----------+-------- +The breadth of the luminous Part of the | | + second Fringe | 1/290 | 1/55 +-------------------------------------------+-----------+-------- +The breadth of the darker Space between | | + the second and third Fringes | 1/340 | 1/63 +-------------------------------------------+-----------+-------- + +These Measures I took by letting the Shadow of the Hair, at half a Foot +distance, fall so obliquely on the Scale, as to appear twelve times +broader than when it fell perpendicularly on it at the same distance, +and setting down in this Table the twelfth part of the Measures I then +took. + +_Obs._ 4. When the Shadow and Fringes were cast obliquely upon a smooth +white Body, and that Body was removed farther and farther from the Hair, +the first Fringe began to appear and look brighter than the rest of the +Light at the distance of less than a quarter of an Inch from the Hair, +and the dark Line or Shadow between that and the second Fringe began to +appear at a less distance from the Hair than that of the third part of +an Inch. The second Fringe began to appear at a distance from the Hair +of less than half an Inch, and the Shadow between that and the third +Fringe at a distance less than an inch, and the third Fringe at a +distance less than three Inches. At greater distances they became much +more sensible, but kept very nearly the same proportion of their +breadths and intervals which they had at their first appearing. For the +distance between the middle of the first, and middle of the second +Fringe, was to the distance between the middle of the second and middle +of the third Fringe, as three to two, or ten to seven. And the last of +these two distances was equal to the breadth of the bright Light or +luminous part of the first Fringe. And this breadth was to the breadth +of the bright Light of the second Fringe as seven to four, and to the +dark Interval of the first and second Fringe as three to two, and to +the like dark Interval between the second and third as two to one. For +the breadths of the Fringes seem'd to be in the progression of the +Numbers 1, sqrt(1/3), sqrt(1/5), and their Intervals to be in the +same progression with them; that is, the Fringes and their Intervals +together to be in the continual progression of the Numbers 1, +sqrt(1/2), sqrt(1/3), sqrt(1/4), sqrt(1/5), or thereabouts. And +these Proportions held the same very nearly at all distances from the +Hair; the dark Intervals of the Fringes being as broad in proportion to +the breadth of the Fringes at their first appearance as afterwards at +great distances from the Hair, though not so dark and distinct. + +_Obs._ 5. The Sun shining into my darken'd Chamber through a hole a +quarter of an Inch broad, I placed at the distance of two or three Feet +from the Hole a Sheet of Pasteboard, which was black'd all over on both +sides, and in the middle of it had a hole about three quarters of an +Inch square for the Light to pass through. And behind the hole I +fasten'd to the Pasteboard with Pitch the blade of a sharp Knife, to +intercept some part of the Light which passed through the hole. The +Planes of the Pasteboard and blade of the Knife were parallel to one +another, and perpendicular to the Rays. And when they were so placed +that none of the Sun's Light fell on the Pasteboard, but all of it +passed through the hole to the Knife, and there part of it fell upon the +blade of the Knife, and part of it passed by its edge; I let this part +of the Light which passed by, fall on a white Paper two or three Feet +beyond the Knife, and there saw two streams of faint Light shoot out +both ways from the beam of Light into the shadow, like the Tails of +Comets. But because the Sun's direct Light by its brightness upon the +Paper obscured these faint streams, so that I could scarce see them, I +made a little hole in the midst of the Paper for that Light to pass +through and fall on a black Cloth behind it; and then I saw the two +streams plainly. They were like one another, and pretty nearly equal in +length, and breadth, and quantity of Light. Their Light at that end next +the Sun's direct Light was pretty strong for the space of about a +quarter of an Inch, or half an Inch, and in all its progress from that +direct Light decreased gradually till it became insensible. The whole +length of either of these streams measured upon the paper at the +distance of three Feet from the Knife was about six or eight Inches; so +that it subtended an Angle at the edge of the Knife of about 10 or 12, +or at most 14 Degrees. Yet sometimes I thought I saw it shoot three or +four Degrees farther, but with a Light so very faint that I could scarce +perceive it, and suspected it might (in some measure at least) arise +from some other cause than the two streams did. For placing my Eye in +that Light beyond the end of that stream which was behind the Knife, and +looking towards the Knife, I could see a line of Light upon its edge, +and that not only when my Eye was in the line of the Streams, but also +when it was without that line either towards the point of the Knife, or +towards the handle. This line of Light appear'd contiguous to the edge +of the Knife, and was narrower than the Light of the innermost Fringe, +and narrowest when my Eye was farthest from the direct Light, and +therefore seem'd to pass between the Light of that Fringe and the edge +of the Knife, and that which passed nearest the edge to be most bent, +though not all of it. + +_Obs._ 6. I placed another Knife by this, so that their edges might be +parallel, and look towards one another, and that the beam of Light might +fall upon both the Knives, and some part of it pass between their edges. +And when the distance of their edges was about the 400th part of an +Inch, the stream parted in the middle, and left a Shadow between the two +parts. This Shadow was so black and dark that all the Light which passed +between the Knives seem'd to be bent, and turn'd aside to the one hand +or to the other. And as the Knives still approach'd one another the +Shadow grew broader, and the streams shorter at their inward ends which +were next the Shadow, until upon the contact of the Knives the whole +Light vanish'd, leaving its place to the Shadow. + +And hence I gather that the Light which is least bent, and goes to the +inward ends of the streams, passes by the edges of the Knives at the +greatest distance, and this distance when the Shadow begins to appear +between the streams, is about the 800th part of an Inch. And the Light +which passes by the edges of the Knives at distances still less and +less, is more and more bent, and goes to those parts of the streams +which are farther and farther from the direct Light; because when the +Knives approach one another till they touch, those parts of the streams +vanish last which are farthest from the direct Light. + +_Obs._ 7. In the fifth Observation the Fringes did not appear, but by +reason of the breadth of the hole in the Window became so broad as to +run into one another, and by joining, to make one continued Light in the +beginning of the streams. But in the sixth, as the Knives approached one +another, a little before the Shadow appeared between the two streams, +the Fringes began to appear on the inner ends of the Streams on either +side of the direct Light; three on one side made by the edge of one +Knife, and three on the other side made by the edge of the other Knife. +They were distinctest when the Knives were placed at the greatest +distance from the hole in the Window, and still became more distinct by +making the hole less, insomuch that I could sometimes see a faint +lineament of a fourth Fringe beyond the three above mention'd. And as +the Knives continually approach'd one another, the Fringes grew +distincter and larger, until they vanish'd. The outmost Fringe vanish'd +first, and the middlemost next, and the innermost last. And after they +were all vanish'd, and the line of Light which was in the middle between +them was grown very broad, enlarging it self on both sides into the +streams of Light described in the fifth Observation, the above-mention'd +Shadow began to appear in the middle of this line, and divide it along +the middle into two lines of Light, and increased until the whole Light +vanish'd. This enlargement of the Fringes was so great that the Rays +which go to the innermost Fringe seem'd to be bent above twenty times +more when this Fringe was ready to vanish, than when one of the Knives +was taken away. + +And from this and the former Observation compared, I gather, that the +Light of the first Fringe passed by the edge of the Knife at a distance +greater than the 800th part of an Inch, and the Light of the second +Fringe passed by the edge of the Knife at a greater distance than the +Light of the first Fringe did, and that of the third at a greater +distance than that of the second, and that of the streams of Light +described in the fifth and sixth Observations passed by the edges of the +Knives at less distances than that of any of the Fringes. + +_Obs._ 8. I caused the edges of two Knives to be ground truly strait, +and pricking their points into a Board so that their edges might look +towards one another, and meeting near their points contain a rectilinear +Angle, I fasten'd their Handles together with Pitch to make this Angle +invariable. The distance of the edges of the Knives from one another at +the distance of four Inches from the angular Point, where the edges of +the Knives met, was the eighth part of an Inch; and therefore the Angle +contain'd by the edges was about one Degree 54: The Knives thus fix'd +together I placed in a beam of the Sun's Light, let into my darken'd +Chamber through a Hole the 42d Part of an Inch wide, at the distance of +10 or 15 Feet from the Hole, and let the Light which passed between +their edges fall very obliquely upon a smooth white Ruler at the +distance of half an Inch, or an Inch from the Knives, and there saw the +Fringes by the two edges of the Knives run along the edges of the +Shadows of the Knives in Lines parallel to those edges without growing +sensibly broader, till they met in Angles equal to the Angle contained +by the edges of the Knives, and where they met and joined they ended +without crossing one another. But if the Ruler was held at a much +greater distance from the Knives, the Fringes where they were farther +from the Place of their Meeting, were a little narrower, and became +something broader and broader as they approach'd nearer and nearer to +one another, and after they met they cross'd one another, and then +became much broader than before. + +Whence I gather that the distances at which the Fringes pass by the +Knives are not increased nor alter'd by the approach of the Knives, but +the Angles in which the Rays are there bent are much increased by that +approach; and that the Knife which is nearest any Ray determines which +way the Ray shall be bent, and the other Knife increases the bent. + +_Obs._ 9. When the Rays fell very obliquely upon the Ruler at the +distance of the third Part of an Inch from the Knives, the dark Line +between the first and second Fringe of the Shadow of one Knife, and the +dark Line between the first and second Fringe of the Shadow of the other +knife met with one another, at the distance of the fifth Part of an Inch +from the end of the Light which passed between the Knives at the +concourse of their edges. And therefore the distance of the edges of the +Knives at the meeting of these dark Lines was the 160th Part of an Inch. +For as four Inches to the eighth Part of an Inch, so is any Length of +the edges of the Knives measured from the point of their concourse to +the distance of the edges of the Knives at the end of that Length, and +so is the fifth Part of an Inch to the 160th Part. So then the dark +Lines above-mention'd meet in the middle of the Light which passes +between the Knives where they are distant the 160th Part of an Inch, and +the one half of that Light passes by the edge of one Knife at a distance +not greater than the 320th Part of an Inch, and falling upon the Paper +makes the Fringes of the Shadow of that Knife, and the other half passes +by the edge of the other Knife, at a distance not greater than the 320th +Part of an Inch, and falling upon the Paper makes the Fringes of the +Shadow of the other Knife. But if the Paper be held at a distance from +the Knives greater than the third Part of an Inch, the dark Lines +above-mention'd meet at a greater distance than the fifth Part of an +Inch from the end of the Light which passed between the Knives at the +concourse of their edges; and therefore the Light which falls upon the +Paper where those dark Lines meet passes between the Knives where the +edges are distant above the 160th part of an Inch. + +For at another time, when the two Knives were distant eight Feet and +five Inches from the little hole in the Window, made with a small Pin as +above, the Light which fell upon the Paper where the aforesaid dark +lines met, passed between the Knives, where the distance between their +edges was as in the following Table, when the distance of the Paper from +the Knives was also as follows. + +-----------------------------+------------------------------ + | Distances between the edges + Distances of the Paper | of the Knives in millesimal + from the Knives in Inches. | parts of an Inch. +-----------------------------+------------------------------ + 1-1/2. | 0'012 + 3-1/3. | 0'020 + 8-3/5. | 0'034 + 32. | 0'057 + 96. | 0'081 + 131. | 0'087 +_____________________________|______________________________ + +And hence I gather, that the Light which makes the Fringes upon the +Paper is not the same Light at all distances of the Paper from the +Knives, but when the Paper is held near the Knives, the Fringes are made +by Light which passes by the edges of the Knives at a less distance, and +is more bent than when the Paper is held at a greater distance from the +Knives. + +[Illustration: FIG. 3.] + +_Obs._ 10. When the Fringes of the Shadows of the Knives fell +perpendicularly upon a Paper at a great distance from the Knives, they +were in the form of Hyperbola's, and their Dimensions were as follows. +Let CA, CB [in _Fig._ 3.] represent Lines drawn upon the Paper parallel +to the edges of the Knives, and between which all the Light would fall, +if it passed between the edges of the Knives without inflexion; DE a +Right Line drawn through C making the Angles ACD, BCE, equal to one +another, and terminating all the Light which falls upon the Paper from +the point where the edges of the Knives meet; _eis_, _fkt_, and _glv_, +three hyperbolical Lines representing the Terminus of the Shadow of one +of the Knives, the dark Line between the first and second Fringes of +that Shadow, and the dark Line between the second and third Fringes of +the same Shadow; _xip_, _ykq_, and _zlr_, three other hyperbolical Lines +representing the Terminus of the Shadow of the other Knife, the dark +Line between the first and second Fringes of that Shadow, and the dark +line between the second and third Fringes of the same Shadow. And +conceive that these three Hyperbola's are like and equal to the former +three, and cross them in the points _i_, _k_, and _l_, and that the +Shadows of the Knives are terminated and distinguish'd from the first +luminous Fringes by the lines _eis_ and _xip_, until the meeting and +crossing of the Fringes, and then those lines cross the Fringes in the +form of dark lines, terminating the first luminous Fringes within side, +and distinguishing them from another Light which begins to appear at +_i_, and illuminates all the triangular space _ip_DE_s_ comprehended by +these dark lines, and the right line DE. Of these Hyperbola's one +Asymptote is the line DE, and their other Asymptotes are parallel to the +lines CA and CB. Let _rv_ represent a line drawn any where upon the +Paper parallel to the Asymptote DE, and let this line cross the right +lines AC in _m_, and BC in _n_, and the six dark hyperbolical lines in +_p_, _q_, _r_; _s_, _t_, _v_; and by measuring the distances _ps_, _qt_, +_rv_, and thence collecting the lengths of the Ordinates _np_, _nq_, +_nr_ or _ms_, _mt_, _mv_, and doing this at several distances of the +line _rv_ from the Asymptote DD, you may find as many points of these +Hyperbola's as you please, and thereby know that these curve lines are +Hyperbola's differing little from the conical Hyperbola. And by +measuring the lines C_i_, C_k_, C_l_, you may find other points of these +Curves. + +For instance; when the Knives were distant from the hole in the Window +ten Feet, and the Paper from the Knives nine Feet, and the Angle +contained by the edges of the Knives to which the Angle ACB is equal, +was subtended by a Chord which was to the Radius as 1 to 32, and the +distance of the line _rv_ from the Asymptote DE was half an Inch: I +measured the lines _ps_, _qt_, _rv_, and found them 0'35, 0'65, 0'98 +Inches respectively; and by adding to their halfs the line 1/2 _mn_, +(which here was the 128th part of an Inch, or 0'0078 Inches,) the Sums +_np_, _nq_, _nr_, were 0'1828, 0'3328, 0'4978 Inches. I measured also +the distances of the brightest parts of the Fringes which run between +_pq_ and _st_, _qr_ and _tv_, and next beyond _r_ and _v_, and found +them 0'5, 0'8, and 1'17 Inches. + +_Obs._ 11. The Sun shining into my darken'd Room through a small round +hole made in a Plate of Lead with a slender Pin, as above; I placed at +the hole a Prism to refract the Light, and form on the opposite Wall the +Spectrum of Colours, described in the third Experiment of the first +Book. And then I found that the Shadows of all Bodies held in the +colour'd Light between the Prism and the Wall, were border'd with +Fringes of the Colour of that Light in which they were held. In the full +red Light they were totally red without any sensible blue or violet, and +in the deep blue Light they were totally blue without any sensible red +or yellow; and so in the green Light they were totally green, excepting +a little yellow and blue, which were mixed in the green Light of the +Prism. And comparing the Fringes made in the several colour'd Lights, I +found that those made in the red Light were largest, those made in the +violet were least, and those made in the green were of a middle bigness. +For the Fringes with which the Shadow of a Man's Hair were bordered, +being measured cross the Shadow at the distance of six Inches from the +Hair, the distance between the middle and most luminous part of the +first or innermost Fringe on one side of the Shadow, and that of the +like Fringe on the other side of the Shadow, was in the full red Light +1/37-1/4 of an Inch, and in the full violet 7/46. And the like distance +between the middle and most luminous parts of the second Fringes on +either side the Shadow was in the full red Light 1/22, and in the violet +1/27 of an Inch. And these distances of the Fringes held the same +proportion at all distances from the Hair without any sensible +variation. + +So then the Rays which made these Fringes in the red Light passed by the +Hair at a greater distance than those did which made the like Fringes in +the violet; and therefore the Hair in causing these Fringes acted alike +upon the red Light or least refrangible Rays at a greater distance, and +upon the violet or most refrangible Rays at a less distance, and by +those actions disposed the red Light into Larger Fringes, and the violet +into smaller, and the Lights of intermediate Colours into Fringes of +intermediate bignesses without changing the Colour of any sort of Light. + +When therefore the Hair in the first and second of these Observations +was held in the white beam of the Sun's Light, and cast a Shadow which +was border'd with three Fringes of coloured Light, those Colours arose +not from any new modifications impress'd upon the Rays of Light by the +Hair, but only from the various inflexions whereby the several Sorts of +Rays were separated from one another, which before separation, by the +mixture of all their Colours, composed the white beam of the Sun's +Light, but whenever separated compose Lights of the several Colours +which they are originally disposed to exhibit. In this 11th Observation, +where the Colours are separated before the Light passes by the Hair, the +least refrangible Rays, which when separated from the rest make red, +were inflected at a greater distance from the Hair, so as to make three +red Fringes at a greater distance from the middle of the Shadow of the +Hair; and the most refrangible Rays which when separated make violet, +were inflected at a less distance from the Hair, so as to make three +violet Fringes at a less distance from the middle of the Shadow of the +Hair. And other Rays of intermediate degrees of Refrangibility were +inflected at intermediate distances from the Hair, so as to make Fringes +of intermediate Colours at intermediate distances from the middle of the +Shadow of the Hair. And in the second Observation, where all the Colours +are mix'd in the white Light which passes by the Hair, these Colours are +separated by the various inflexions of the Rays, and the Fringes which +they make appear all together, and the innermost Fringes being +contiguous make one broad Fringe composed of all the Colours in due +order, the violet lying on the inside of the Fringe next the Shadow, the +red on the outside farthest from the Shadow, and the blue, green, and +yellow, in the middle. And, in like manner, the middlemost Fringes of +all the Colours lying in order, and being contiguous, make another broad +Fringe composed of all the Colours; and the outmost Fringes of all the +Colours lying in order, and being contiguous, make a third broad Fringe +composed of all the Colours. These are the three Fringes of colour'd +Light with which the Shadows of all Bodies are border'd in the second +Observation. + +When I made the foregoing Observations, I design'd to repeat most of +them with more care and exactness, and to make some new ones for +determining the manner how the Rays of Light are bent in their passage +by Bodies, for making the Fringes of Colours with the dark lines between +them. But I was then interrupted, and cannot now think of taking these +things into farther Consideration. And since I have not finish'd this +part of my Design, I shall conclude with proposing only some Queries, in +order to a farther search to be made by others. + +_Query_ 1. Do not Bodies act upon Light at a distance, and by their +action bend its Rays; and is not this action (_cæteris paribus_) +strongest at the least distance? + +_Qu._ 2. Do not the Rays which differ in Refrangibility differ also in +Flexibity; and are they not by their different Inflexions separated from +one another, so as after separation to make the Colours in the three +Fringes above described? And after what manner are they inflected to +make those Fringes? + +_Qu._ 3. Are not the Rays of Light in passing by the edges and sides of +Bodies, bent several times backwards and forwards, with a motion like +that of an Eel? And do not the three Fringes of colour'd Light +above-mention'd arise from three such bendings? + +_Qu._ 4. Do not the Rays of Light which fall upon Bodies, and are +reflected or refracted, begin to bend before they arrive at the Bodies; +and are they not reflected, refracted, and inflected, by one and the +same Principle, acting variously in various Circumstances? + +_Qu._ 5. Do not Bodies and Light act mutually upon one another; that is +to say, Bodies upon Light in emitting, reflecting, refracting and +inflecting it, and Light upon Bodies for heating them, and putting their +parts into a vibrating motion wherein heat consists? + +_Qu._ 6. Do not black Bodies conceive heat more easily from Light than +those of other Colours do, by reason that the Light falling on them is +not reflected outwards, but enters the Bodies, and is often reflected +and refracted within them, until it be stifled and lost? + +_Qu._ 7. Is not the strength and vigor of the action between Light and +sulphureous Bodies observed above, one reason why sulphureous Bodies +take fire more readily, and burn more vehemently than other Bodies do? + +_Qu._ 8. Do not all fix'd Bodies, when heated beyond a certain degree, +emit Light and shine; and is not this Emission perform'd by the +vibrating motions of their parts? And do not all Bodies which abound +with terrestrial parts, and especially with sulphureous ones, emit Light +as often as those parts are sufficiently agitated; whether that +agitation be made by Heat, or by Friction, or Percussion, or +Putrefaction, or by any vital Motion, or any other Cause? As for +instance; Sea-Water in a raging Storm; Quick-silver agitated in _vacuo_; +the Back of a Cat, or Neck of a Horse, obliquely struck or rubbed in a +dark place; Wood, Flesh and Fish while they putrefy; Vapours arising +from putrefy'd Waters, usually call'd _Ignes Fatui_; Stacks of moist Hay +or Corn growing hot by fermentation; Glow-worms and the Eyes of some +Animals by vital Motions; the vulgar _Phosphorus_ agitated by the +attrition of any Body, or by the acid Particles of the Air; Amber and +some Diamonds by striking, pressing or rubbing them; Scrapings of Steel +struck off with a Flint; Iron hammer'd very nimbly till it become so hot +as to kindle Sulphur thrown upon it; the Axletrees of Chariots taking +fire by the rapid rotation of the Wheels; and some Liquors mix'd with +one another whose Particles come together with an Impetus, as Oil of +Vitriol distilled from its weight of Nitre, and then mix'd with twice +its weight of Oil of Anniseeds. So also a Globe of Glass about 8 or 10 +Inches in diameter, being put into a Frame where it may be swiftly +turn'd round its Axis, will in turning shine where it rubs against the +palm of ones Hand apply'd to it: And if at the same time a piece of +white Paper or white Cloth, or the end of ones Finger be held at the +distance of about a quarter of an Inch or half an Inch from that part of +the Glass where it is most in motion, the electrick Vapour which is +excited by the friction of the Glass against the Hand, will by dashing +against the white Paper, Cloth or Finger, be put into such an agitation +as to emit Light, and make the white Paper, Cloth or Finger, appear +lucid like a Glowworm; and in rushing out of the Glass will sometimes +push against the finger so as to be felt. And the same things have been +found by rubbing a long and large Cylinder or Glass or Amber with a +Paper held in ones hand, and continuing the friction till the Glass grew +warm. + +_Qu._ 9. Is not Fire a Body heated so hot as to emit Light copiously? +For what else is a red hot Iron than Fire? And what else is a burning +Coal than red hot Wood? + +_Qu._ 10. Is not Flame a Vapour, Fume or Exhalation heated red hot, that +is, so hot as to shine? For Bodies do not flame without emitting a +copious Fume, and this Fume burns in the Flame. The _Ignis Fatuus_ is a +Vapour shining without heat, and is there not the same difference +between this Vapour and Flame, as between rotten Wood shining without +heat and burning Coals of Fire? In distilling hot Spirits, if the Head +of the Still be taken off, the Vapour which ascends out of the Still +will take fire at the Flame of a Candle, and turn into Flame, and the +Flame will run along the Vapour from the Candle to the Still. Some +Bodies heated by Motion, or Fermentation, if the heat grow intense, fume +copiously, and if the heat be great enough the Fumes will shine and +become Flame. Metals in fusion do not flame for want of a copious Fume, +except Spelter, which fumes copiously, and thereby flames. All flaming +Bodies, as Oil, Tallow, Wax, Wood, fossil Coals, Pitch, Sulphur, by +flaming waste and vanish into burning Smoke, which Smoke, if the Flame +be put out, is very thick and visible, and sometimes smells strongly, +but in the Flame loses its smell by burning, and according to the nature +of the Smoke the Flame is of several Colours, as that of Sulphur blue, +that of Copper open'd with sublimate green, that of Tallow yellow, that +of Camphire white. Smoke passing through Flame cannot but grow red hot, +and red hot Smoke can have no other appearance than that of Flame. When +Gun-powder takes fire, it goes away into Flaming Smoke. For the Charcoal +and Sulphur easily take fire, and set fire to the Nitre, and the Spirit +of the Nitre being thereby rarified into Vapour, rushes out with +Explosion much after the manner that the Vapour of Water rushes out of +an Æolipile; the Sulphur also being volatile is converted into Vapour, +and augments the Explosion. And the acid Vapour of the Sulphur (namely +that which distils under a Bell into Oil of Sulphur,) entring violently +into the fix'd Body of the Nitre, sets loose the Spirit of the Nitre, +and excites a great Fermentation, whereby the Heat is farther augmented, +and the fix'd Body of the Nitre is also rarified into Fume, and the +Explosion is thereby made more vehement and quick. For if Salt of Tartar +be mix'd with Gun-powder, and that Mixture be warm'd till it takes fire, +the Explosion will be more violent and quick than that of Gun-powder +alone; which cannot proceed from any other cause than the action of the +Vapour of the Gun-powder upon the Salt of Tartar, whereby that Salt is +rarified. The Explosion of Gun-powder arises therefore from the violent +action whereby all the Mixture being quickly and vehemently heated, is +rarified and converted into Fume and Vapour: which Vapour, by the +violence of that action, becoming so hot as to shine, appears in the +form of Flame. + +_Qu._ 11. Do not great Bodies conserve their heat the longest, their +parts heating one another, and may not great dense and fix'd Bodies, +when heated beyond a certain degree, emit Light so copiously, as by the +Emission and Re-action of its Light, and the Reflexions and Refractions +of its Rays within its Pores to grow still hotter, till it comes to a +certain period of heat, such as is that of the Sun? And are not the Sun +and fix'd Stars great Earths vehemently hot, whose heat is conserved by +the greatness of the Bodies, and the mutual Action and Reaction between +them, and the Light which they emit, and whose parts are kept from +fuming away, not only by their fixity, but also by the vast weight and +density of the Atmospheres incumbent upon them; and very strongly +compressing them, and condensing the Vapours and Exhalations which arise +from them? For if Water be made warm in any pellucid Vessel emptied of +Air, that Water in the _Vacuum_ will bubble and boil as vehemently as it +would in the open Air in a Vessel set upon the Fire till it conceives a +much greater heat. For the weight of the incumbent Atmosphere keeps down +the Vapours, and hinders the Water from boiling, until it grow much +hotter than is requisite to make it boil _in vacuo_. Also a mixture of +Tin and Lead being put upon a red hot Iron _in vacuo_ emits a Fume and +Flame, but the same Mixture in the open Air, by reason of the incumbent +Atmosphere, does not so much as emit any Fume which can be perceived by +Sight. In like manner the great weight of the Atmosphere which lies upon +the Globe of the Sun may hinder Bodies there from rising up and going +away from the Sun in the form of Vapours and Fumes, unless by means of a +far greater heat than that which on the Surface of our Earth would very +easily turn them into Vapours and Fumes. And the same great weight may +condense those Vapours and Exhalations as soon as they shall at any time +begin to ascend from the Sun, and make them presently fall back again +into him, and by that action increase his Heat much after the manner +that in our Earth the Air increases the Heat of a culinary Fire. And the +same weight may hinder the Globe of the Sun from being diminish'd, +unless by the Emission of Light, and a very small quantity of Vapours +and Exhalations. + +_Qu._ 12. Do not the Rays of Light in falling upon the bottom of the Eye +excite Vibrations in the _Tunica Retina_? Which Vibrations, being +propagated along the solid Fibres of the optick Nerves into the Brain, +cause the Sense of seeing. For because dense Bodies conserve their Heat +a long time, and the densest Bodies conserve their Heat the longest, the +Vibrations of their parts are of a lasting nature, and therefore may be +propagated along solid Fibres of uniform dense Matter to a great +distance, for conveying into the Brain the impressions made upon all the +Organs of Sense. For that Motion which can continue long in one and the +same part of a Body, can be propagated a long way from one part to +another, supposing the Body homogeneal, so that the Motion may not be +reflected, refracted, interrupted or disorder'd by any unevenness of the +Body. + +_Qu._ 13. Do not several sorts of Rays make Vibrations of several +bignesses, which according to their bignesses excite Sensations of +several Colours, much after the manner that the Vibrations of the Air, +according to their several bignesses excite Sensations of several +Sounds? And particularly do not the most refrangible Rays excite the +shortest Vibrations for making a Sensation of deep violet, the least +refrangible the largest for making a Sensation of deep red, and the +several intermediate sorts of Rays, Vibrations of several intermediate +bignesses to make Sensations of the several intermediate Colours? + +_Qu._ 14. May not the harmony and discord of Colours arise from the +proportions of the Vibrations propagated through the Fibres of the +optick Nerves into the Brain, as the harmony and discord of Sounds arise +from the proportions of the Vibrations of the Air? For some Colours, if +they be view'd together, are agreeable to one another, as those of Gold +and Indigo, and others disagree. + +_Qu._ 15. Are not the Species of Objects seen with both Eyes united +where the optick Nerves meet before they come into the Brain, the Fibres +on the right side of both Nerves uniting there, and after union going +thence into the Brain in the Nerve which is on the right side of the +Head, and the Fibres on the left side of both Nerves uniting in the same +place, and after union going into the Brain in the Nerve which is on the +left side of the Head, and these two Nerves meeting in the Brain in such +a manner that their Fibres make but one entire Species or Picture, half +of which on the right side of the Sensorium comes from the right side of +both Eyes through the right side of both optick Nerves to the place +where the Nerves meet, and from thence on the right side of the Head +into the Brain, and the other half on the left side of the Sensorium +comes in like manner from the left side of both Eyes. For the optick +Nerves of such Animals as look the same way with both Eyes (as of Men, +Dogs, Sheep, Oxen, &c.) meet before they come into the Brain, but the +optick Nerves of such Animals as do not look the same way with both Eyes +(as of Fishes, and of the Chameleon,) do not meet, if I am rightly +inform'd. + +_Qu._ 16. When a Man in the dark presses either corner of his Eye with +his Finger, and turns his Eye away from his Finger, he will see a Circle +of Colours like those in the Feather of a Peacock's Tail. If the Eye and +the Finger remain quiet these Colours vanish in a second Minute of Time, +but if the Finger be moved with a quavering Motion they appear again. Do +not these Colours arise from such Motions excited in the bottom of the +Eye by the Pressure and Motion of the Finger, as, at other times are +excited there by Light for causing Vision? And do not the Motions once +excited continue about a Second of Time before they cease? And when a +Man by a stroke upon his Eye sees a flash of Light, are not the like +Motions excited in the _Retina_ by the stroke? And when a Coal of Fire +moved nimbly in the circumference of a Circle, makes the whole +circumference appear like a Circle of Fire; is it not because the +Motions excited in the bottom of the Eye by the Rays of Light are of a +lasting nature, and continue till the Coal of Fire in going round +returns to its former place? And considering the lastingness of the +Motions excited in the bottom of the Eye by Light, are they not of a +vibrating nature? + +_Qu._ 17. If a stone be thrown into stagnating Water, the Waves excited +thereby continue some time to arise in the place where the Stone fell +into the Water, and are propagated from thence in concentrick Circles +upon the Surface of the Water to great distances. And the Vibrations or +Tremors excited in the Air by percussion, continue a little time to move +from the place of percussion in concentrick Spheres to great distances. +And in like manner, when a Ray of Light falls upon the Surface of any +pellucid Body, and is there refracted or reflected, may not Waves of +Vibrations, or Tremors, be thereby excited in the refracting or +reflecting Medium at the point of Incidence, and continue to arise +there, and to be propagated from thence as long as they continue to +arise and be propagated, when they are excited in the bottom of the Eye +by the Pressure or Motion of the Finger, or by the Light which comes +from the Coal of Fire in the Experiments above-mention'd? and are not +these Vibrations propagated from the point of Incidence to great +distances? And do they not overtake the Rays of Light, and by overtaking +them successively, do they not put them into the Fits of easy Reflexion +and easy Transmission described above? For if the Rays endeavour to +recede from the densest part of the Vibration, they may be alternately +accelerated and retarded by the Vibrations overtaking them. + +_Qu._ 18. If in two large tall cylindrical Vessels of Glass inverted, +two little Thermometers be suspended so as not to touch the Vessels, and +the Air be drawn out of one of these Vessels, and these Vessels thus +prepared be carried out of a cold place into a warm one; the Thermometer +_in vacuo_ will grow warm as much, and almost as soon as the Thermometer +which is not _in vacuo_. And when the Vessels are carried back into the +cold place, the Thermometer _in vacuo_ will grow cold almost as soon as +the other Thermometer. Is not the Heat of the warm Room convey'd through +the _Vacuum_ by the Vibrations of a much subtiler Medium than Air, which +after the Air was drawn out remained in the _Vacuum_? And is not this +Medium the same with that Medium by which Light is refracted and +reflected, and by whose Vibrations Light communicates Heat to Bodies, +and is put into Fits of easy Reflexion and easy Transmission? And do not +the Vibrations of this Medium in hot Bodies contribute to the +intenseness and duration of their Heat? And do not hot Bodies +communicate their Heat to contiguous cold ones, by the Vibrations of +this Medium propagated from them into the cold ones? And is not this +Medium exceedingly more rare and subtile than the Air, and exceedingly +more elastick and active? And doth it not readily pervade all Bodies? +And is it not (by its elastick force) expanded through all the Heavens? + +_Qu._ 19. Doth not the Refraction of Light proceed from the different +density of this Æthereal Medium in different places, the Light receding +always from the denser parts of the Medium? And is not the density +thereof greater in free and open Spaces void of Air and other grosser +Bodies, than within the Pores of Water, Glass, Crystal, Gems, and other +compact Bodies? For when Light passes through Glass or Crystal, and +falling very obliquely upon the farther Surface thereof is totally +reflected, the total Reflexion ought to proceed rather from the density +and vigour of the Medium without and beyond the Glass, than from the +rarity and weakness thereof. + +_Qu._ 20. Doth not this Æthereal Medium in passing out of Water, Glass, +Crystal, and other compact and dense Bodies into empty Spaces, grow +denser and denser by degrees, and by that means refract the Rays of +Light not in a point, but by bending them gradually in curve Lines? And +doth not the gradual condensation of this Medium extend to some distance +from the Bodies, and thereby cause the Inflexions of the Rays of Light, +which pass by the edges of dense Bodies, at some distance from the +Bodies? + +_Qu._ 21. Is not this Medium much rarer within the dense Bodies of the +Sun, Stars, Planets and Comets, than in the empty celestial Spaces +between them? And in passing from them to great distances, doth it not +grow denser and denser perpetually, and thereby cause the gravity of +those great Bodies towards one another, and of their parts towards the +Bodies; every Body endeavouring to go from the denser parts of the +Medium towards the rarer? For if this Medium be rarer within the Sun's +Body than at its Surface, and rarer there than at the hundredth part of +an Inch from its Body, and rarer there than at the fiftieth part of an +Inch from its Body, and rarer there than at the Orb of _Saturn_; I see +no reason why the Increase of density should stop any where, and not +rather be continued through all distances from the Sun to _Saturn_, and +beyond. And though this Increase of density may at great distances be +exceeding slow, yet if the elastick force of this Medium be exceeding +great, it may suffice to impel Bodies from the denser parts of the +Medium towards the rarer, with all that power which we call Gravity. And +that the elastick force of this Medium is exceeding great, may be +gather'd from the swiftness of its Vibrations. Sounds move about 1140 +_English_ Feet in a second Minute of Time, and in seven or eight Minutes +of Time they move about one hundred _English_ Miles. Light moves from +the Sun to us in about seven or eight Minutes of Time, which distance is +about 70,000,000 _English_ Miles, supposing the horizontal Parallax of +the Sun to be about 12´´. And the Vibrations or Pulses of this Medium, +that they may cause the alternate Fits of easy Transmission and easy +Reflexion, must be swifter than Light, and by consequence above 700,000 +times swifter than Sounds. And therefore the elastick force of this +Medium, in proportion to its density, must be above 700000 x 700000 +(that is, above 490,000,000,000) times greater than the elastick force +of the Air is in proportion to its density. For the Velocities of the +Pulses of elastick Mediums are in a subduplicate _Ratio_ of the +Elasticities and the Rarities of the Mediums taken together. + +As Attraction is stronger in small Magnets than in great ones in +proportion to their Bulk, and Gravity is greater in the Surfaces of +small Planets than in those of great ones in proportion to their bulk, +and small Bodies are agitated much more by electric attraction than +great ones; so the smallness of the Rays of Light may contribute very +much to the power of the Agent by which they are refracted. And so if +any one should suppose that _Æther_ (like our Air) may contain Particles +which endeavour to recede from one another (for I do not know what this +_Æther_ is) and that its Particles are exceedingly smaller than those of +Air, or even than those of Light: The exceeding smallness of its +Particles may contribute to the greatness of the force by which those +Particles may recede from one another, and thereby make that Medium +exceedingly more rare and elastick than Air, and by consequence +exceedingly less able to resist the motions of Projectiles, and +exceedingly more able to press upon gross Bodies, by endeavouring to +expand it self. + +_Qu._ 22. May not Planets and Comets, and all gross Bodies, perform +their Motions more freely, and with less resistance in this Æthereal +Medium than in any Fluid, which fills all Space adequately without +leaving any Pores, and by consequence is much denser than Quick-silver +or Gold? And may not its resistance be so small, as to be +inconsiderable? For instance; If this _Æther_ (for so I will call it) +should be supposed 700000 times more elastick than our Air, and above +700000 times more rare; its resistance would be above 600,000,000 times +less than that of Water. And so small a resistance would scarce make any +sensible alteration in the Motions of the Planets in ten thousand +Years. If any one would ask how a Medium can be so rare, let him tell me +how the Air, in the upper parts of the Atmosphere, can be above an +hundred thousand thousand times rarer than Gold. Let him also tell me, +how an electrick Body can by Friction emit an Exhalation so rare and +subtile, and yet so potent, as by its Emission to cause no sensible +Diminution of the weight of the electrick Body, and to be expanded +through a Sphere, whose Diameter is above two Feet, and yet to be able +to agitate and carry up Leaf Copper, or Leaf Gold, at the distance of +above a Foot from the electrick Body? And how the Effluvia of a Magnet +can be so rare and subtile, as to pass through a Plate of Glass without +any Resistance or Diminution of their Force, and yet so potent as to +turn a magnetick Needle beyond the Glass? + +_Qu._ 23. Is not Vision perform'd chiefly by the Vibrations of this +Medium, excited in the bottom of the Eye by the Rays of Light, and +propagated through the solid, pellucid and uniform Capillamenta of the +optick Nerves into the place of Sensation? And is not Hearing perform'd +by the Vibrations either of this or some other Medium, excited in the +auditory Nerves by the Tremors of the Air, and propagated through the +solid, pellucid and uniform Capillamenta of those Nerves into the place +of Sensation? And so of the other Senses. + +_Qu._ 24. Is not Animal Motion perform'd by the Vibrations of this +Medium, excited in the Brain by the power of the Will, and propagated +from thence through the solid, pellucid and uniform Capillamenta of the +Nerves into the Muscles, for contracting and dilating them? I suppose +that the Capillamenta of the Nerves are each of them solid and uniform, +that the vibrating Motion of the Æthereal Medium may be propagated along +them from one end to the other uniformly, and without interruption: For +Obstructions in the Nerves create Palsies. And that they may be +sufficiently uniform, I suppose them to be pellucid when view'd singly, +tho' the Reflexions in their cylindrical Surfaces may make the whole +Nerve (composed of many Capillamenta) appear opake and white. For +opacity arises from reflecting Surfaces, such as may disturb and +interrupt the Motions of this Medium. + +[Sidenote: _See the following Scheme, p. 356._] + +_Qu._ 25. Are there not other original Properties of the Rays of Light, +besides those already described? An instance of another original +Property we have in the Refraction of Island Crystal, described first by +_Erasmus Bartholine_, and afterwards more exactly by _Hugenius_, in his +Book _De la Lumiere_. This Crystal is a pellucid fissile Stone, clear as +Water or Crystal of the Rock, and without Colour; enduring a red Heat +without losing its transparency, and in a very strong Heat calcining +without Fusion. Steep'd a Day or two in Water, it loses its natural +Polish. Being rubb'd on Cloth, it attracts pieces of Straws and other +light things, like Ambar or Glass; and with _Aqua fortis_ it makes an +Ebullition. It seems to be a sort of Talk, and is found in form of an +oblique Parallelopiped, with six parallelogram Sides and eight solid +Angles. The obtuse Angles of the Parallelograms are each of them 101 +Degrees and 52 Minutes; the acute ones 78 Degrees and 8 Minutes. Two of +the solid Angles opposite to one another, as C and E, are compassed each +of them with three of these obtuse Angles, and each of the other six +with one obtuse and two acute ones. It cleaves easily in planes parallel +to any of its Sides, and not in any other Planes. It cleaves with a +glossy polite Surface not perfectly plane, but with some little +unevenness. It is easily scratch'd, and by reason of its softness it +takes a Polish very difficultly. It polishes better upon polish'd +Looking-glass than upon Metal, and perhaps better upon Pitch, Leather or +Parchment. Afterwards it must be rubb'd with a little Oil or white of an +Egg, to fill up its Scratches; whereby it will become very transparent +and polite. But for several Experiments, it is not necessary to polish +it. If a piece of this crystalline Stone be laid upon a Book, every +Letter of the Book seen through it will appear double, by means of a +double Refraction. And if any beam of Light falls either +perpendicularly, or in any oblique Angle upon any Surface of this +Crystal, it becomes divided into two beams by means of the same double +Refraction. Which beams are of the same Colour with the incident beam of +Light, and seem equal to one another in the quantity of their Light, or +very nearly equal. One of these Refractions is perform'd by the usual +Rule of Opticks, the Sine of Incidence out of Air into this Crystal +being to the Sine of Refraction, as five to three. The other +Refraction, which may be called the unusual Refraction, is perform'd by +the following Rule. + +[Illustration: FIG. 4.] + +Let ADBC represent the refracting Surface of the Crystal, C the biggest +solid Angle at that Surface, GEHF the opposite Surface, and CK a +perpendicular on that Surface. This perpendicular makes with the edge of +the Crystal CF, an Angle of 19 Degr. 3'. Join KF, and in it take KL, so +that the Angle KCL be 6 Degr. 40'. and the Angle LCF 12 Degr. 23'. And +if ST represent any beam of Light incident at T in any Angle upon the +refracting Surface ADBC, let TV be the refracted beam determin'd by the +given Portion of the Sines 5 to 3, according to the usual Rule of +Opticks. Draw VX parallel and equal to KL. Draw it the same way from V +in which L lieth from K; and joining TX, this line TX shall be the other +refracted beam carried from T to X, by the unusual Refraction. + +If therefore the incident beam ST be perpendicular to the refracting +Surface, the two beams TV and TX, into which it shall become divided, +shall be parallel to the lines CK and CL; one of those beams going +through the Crystal perpendicularly, as it ought to do by the usual Laws +of Opticks, and the other TX by an unusual Refraction diverging from the +perpendicular, and making with it an Angle VTX of about 6-2/3 Degrees, +as is found by Experience. And hence, the Plane VTX, and such like +Planes which are parallel to the Plane CFK, may be called the Planes of +perpendicular Refraction. And the Coast towards which the lines KL and +VX are drawn, may be call'd the Coast of unusual Refraction. + +In like manner Crystal of the Rock has a double Refraction: But the +difference of the two Refractions is not so great and manifest as in +Island Crystal. + +When the beam ST incident on Island Crystal is divided into two beams TV +and TX, and these two beams arrive at the farther Surface of the Glass; +the beam TV, which was refracted at the first Surface after the usual +manner, shall be again refracted entirely after the usual manner at the +second Surface; and the beam TX, which was refracted after the unusual +manner in the first Surface, shall be again refracted entirely after the +unusual manner in the second Surface; so that both these beams shall +emerge out of the second Surface in lines parallel to the first incident +beam ST. + +And if two pieces of Island Crystal be placed one after another, in such +manner that all the Surfaces of the latter be parallel to all the +corresponding Surfaces of the former: The Rays which are refracted after +the usual manner in the first Surface of the first Crystal, shall be +refracted after the usual manner in all the following Surfaces; and the +Rays which are refracted after the unusual manner in the first Surface, +shall be refracted after the unusual manner in all the following +Surfaces. And the same thing happens, though the Surfaces of the +Crystals be any ways inclined to one another, provided that their Planes +of perpendicular Refraction be parallel to one another. + +And therefore there is an original difference in the Rays of Light, by +means of which some Rays are in this Experiment constantly refracted +after the usual manner, and others constantly after the unusual manner: +For if the difference be not original, but arises from new Modifications +impress'd on the Rays at their first Refraction, it would be alter'd by +new Modifications in the three following Refractions; whereas it suffers +no alteration, but is constant, and has the same effect upon the Rays in +all the Refractions. The unusual Refraction is therefore perform'd by an +original property of the Rays. And it remains to be enquired, whether +the Rays have not more original Properties than are yet discover'd. + +_Qu._ 26. Have not the Rays of Light several sides, endued with several +original Properties? For if the Planes of perpendicular Refraction of +the second Crystal be at right Angles with the Planes of perpendicular +Refraction of the first Crystal, the Rays which are refracted after the +usual manner in passing through the first Crystal, will be all of them +refracted after the unusual manner in passing through the second +Crystal; and the Rays which are refracted after the unusual manner in +passing through the first Crystal, will be all of them refracted after +the usual manner in passing through the second Crystal. And therefore +there are not two sorts of Rays differing in their nature from one +another, one of which is constantly and in all Positions refracted after +the usual manner, and the other constantly and in all Positions after +the unusual manner. The difference between the two sorts of Rays in the +Experiment mention'd in the 25th Question, was only in the Positions of +the Sides of the Rays to the Planes of perpendicular Refraction. For one +and the same Ray is here refracted sometimes after the usual, and +sometimes after the unusual manner, according to the Position which its +Sides have to the Crystals. If the Sides of the Ray are posited the same +way to both Crystals, it is refracted after the same manner in them +both: But if that side of the Ray which looks towards the Coast of the +unusual Refraction of the first Crystal, be 90 Degrees from that side of +the same Ray which looks toward the Coast of the unusual Refraction of +the second Crystal, (which may be effected by varying the Position of +the second Crystal to the first, and by consequence to the Rays of +Light,) the Ray shall be refracted after several manners in the several +Crystals. There is nothing more required to determine whether the Rays +of Light which fall upon the second Crystal shall be refracted after +the usual or after the unusual manner, but to turn about this Crystal, +so that the Coast of this Crystal's unusual Refraction may be on this or +on that side of the Ray. And therefore every Ray may be consider'd as +having four Sides or Quarters, two of which opposite to one another +incline the Ray to be refracted after the unusual manner, as often as +either of them are turn'd towards the Coast of unusual Refraction; and +the other two, whenever either of them are turn'd towards the Coast of +unusual Refraction, do not incline it to be otherwise refracted than +after the usual manner. The two first may therefore be call'd the Sides +of unusual Refraction. And since these Dispositions were in the Rays +before their Incidence on the second, third, and fourth Surfaces of the +two Crystals, and suffered no alteration (so far as appears,) by the +Refraction of the Rays in their passage through those Surfaces, and the +Rays were refracted by the same Laws in all the four Surfaces; it +appears that those Dispositions were in the Rays originally, and +suffer'd no alteration by the first Refraction, and that by means of +those Dispositions the Rays were refracted at their Incidence on the +first Surface of the first Crystal, some of them after the usual, and +some of them after the unusual manner, accordingly as their Sides of +unusual Refraction were then turn'd towards the Coast of the unusual +Refraction of that Crystal, or sideways from it. + +Every Ray of Light has therefore two opposite Sides, originally endued +with a Property on which the unusual Refraction depends, and the other +two opposite Sides not endued with that Property. And it remains to be +enquired, whether there are not more Properties of Light by which the +Sides of the Rays differ, and are distinguished from one another. + +In explaining the difference of the Sides of the Rays above mention'd, I +have supposed that the Rays fall perpendicularly on the first Crystal. +But if they fall obliquely on it, the Success is the same. Those Rays +which are refracted after the usual manner in the first Crystal, will be +refracted after the unusual manner in the second Crystal, supposing the +Planes of perpendicular Refraction to be at right Angles with one +another, as above; and on the contrary. + +If the Planes of the perpendicular Refraction of the two Crystals be +neither parallel nor perpendicular to one another, but contain an acute +Angle: The two beams of Light which emerge out of the first Crystal, +will be each of them divided into two more at their Incidence on the +second Crystal. For in this case the Rays in each of the two beams will +some of them have their Sides of unusual Refraction, and some of them +their other Sides turn'd towards the Coast of the unusual Refraction of +the second Crystal. + +_Qu._ 27. Are not all Hypotheses erroneous which have hitherto been +invented for explaining the Phænomena of Light, by new Modifications of +the Rays? For those Phænomena depend not upon new Modifications, as has +been supposed, but upon the original and unchangeable Properties of the +Rays. + +_Qu._ 28. Are not all Hypotheses erroneous, in which Light is supposed +to consist in Pression or Motion, propagated through a fluid Medium? For +in all these Hypotheses the Phænomena of Light have been hitherto +explain'd by supposing that they arise from new Modifications of the +Rays; which is an erroneous Supposition. + +If Light consisted only in Pression propagated without actual Motion, it +would not be able to agitate and heat the Bodies which refract and +reflect it. If it consisted in Motion propagated to all distances in an +instant, it would require an infinite force every moment, in every +shining Particle, to generate that Motion. And if it consisted in +Pression or Motion, propagated either in an instant or in time, it would +bend into the Shadow. For Pression or Motion cannot be propagated in a +Fluid in right Lines, beyond an Obstacle which stops part of the Motion, +but will bend and spread every way into the quiescent Medium which lies +beyond the Obstacle. Gravity tends downwards, but the Pressure of Water +arising from Gravity tends every way with equal Force, and is propagated +as readily, and with as much force sideways as downwards, and through +crooked passages as through strait ones. The Waves on the Surface of +stagnating Water, passing by the sides of a broad Obstacle which stops +part of them, bend afterwards and dilate themselves gradually into the +quiet Water behind the Obstacle. The Waves, Pulses or Vibrations of the +Air, wherein Sounds consist, bend manifestly, though not so much as the +Waves of Water. For a Bell or a Cannon may be heard beyond a Hill which +intercepts the sight of the sounding Body, and Sounds are propagated as +readily through crooked Pipes as through streight ones. But Light is +never known to follow crooked Passages nor to bend into the Shadow. For +the fix'd Stars by the Interposition of any of the Planets cease to be +seen. And so do the Parts of the Sun by the Interposition of the Moon, +_Mercury_ or _Venus_. The Rays which pass very near to the edges of any +Body, are bent a little by the action of the Body, as we shew'd above; +but this bending is not towards but from the Shadow, and is perform'd +only in the passage of the Ray by the Body, and at a very small distance +from it. So soon as the Ray is past the Body, it goes right on. + +[Sidenote: _Mais pour dire comment cela se fait, je n'ay rien trove +jusqu' ici qui me satisfasse._ C. H. de la lumiere, c. 5, p. 91.] + +To explain the unusual Refraction of Island Crystal by Pression or +Motion propagated, has not hitherto been attempted (to my knowledge) +except by _Huygens_, who for that end supposed two several vibrating +Mediums within that Crystal. But when he tried the Refractions in two +successive pieces of that Crystal, and found them such as is mention'd +above; he confessed himself at a loss for explaining them. For Pressions +or Motions, propagated from a shining Body through an uniform Medium, +must be on all sides alike; whereas by those Experiments it appears, +that the Rays of Light have different Properties in their different +Sides. He suspected that the Pulses of _Æther_ in passing through the +first Crystal might receive certain new Modifications, which might +determine them to be propagated in this or that Medium within the +second Crystal, according to the Position of that Crystal. But what +Modifications those might be he could not say, nor think of any thing +satisfactory in that Point. And if he had known that the unusual +Refraction depends not on new Modifications, but on the original and +unchangeable Dispositions of the Rays, he would have found it as +difficult to explain how those Dispositions which he supposed to be +impress'd on the Rays by the first Crystal, could be in them before +their Incidence on that Crystal, and in general, how all Rays emitted by +shining Bodies, can have those Dispositions in them from the beginning. +To me, at least, this seems inexplicable, if Light be nothing else than +Pression or Motion propagated through _Æther_. + +And it is as difficult to explain by these Hypotheses, how Rays can be +alternately in Fits of easy Reflexion and easy Transmission; unless +perhaps one might suppose that there are in all Space two Æthereal +vibrating Mediums, and that the Vibrations of one of them constitute +Light, and the Vibrations of the other are swifter, and as often as they +overtake the Vibrations of the first, put them into those Fits. But how +two _Æthers_ can be diffused through all Space, one of which acts upon +the other, and by consequence is re-acted upon, without retarding, +shattering, dispersing and confounding one anothers Motions, is +inconceivable. And against filling the Heavens with fluid Mediums, +unless they be exceeding rare, a great Objection arises from the regular +and very lasting Motions of the Planets and Comets in all manner of +Courses through the Heavens. For thence it is manifest, that the Heavens +are void of all sensible Resistance, and by consequence of all sensible +Matter. + +For the resisting Power of fluid Mediums arises partly from the +Attrition of the Parts of the Medium, and partly from the _Vis inertiæ_ +of the Matter. That part of the Resistance of a spherical Body which +arises from the Attrition of the Parts of the Medium is very nearly as +the Diameter, or, at the most, as the _Factum_ of the Diameter, and the +Velocity of the spherical Body together. And that part of the Resistance +which arises from the _Vis inertiæ_ of the Matter, is as the Square of +that _Factum_. And by this difference the two sorts of Resistance may be +distinguish'd from one another in any Medium; and these being +distinguish'd, it will be found that almost all the Resistance of Bodies +of a competent Magnitude moving in Air, Water, Quick-silver, and such +like Fluids with a competent Velocity, arises from the _Vis inertiæ_ of +the Parts of the Fluid. + +Now that part of the resisting Power of any Medium which arises from the +Tenacity, Friction or Attrition of the Parts of the Medium, may be +diminish'd by dividing the Matter into smaller Parts, and making the +Parts more smooth and slippery: But that part of the Resistance which +arises from the _Vis inertiæ_, is proportional to the Density of the +Matter, and cannot be diminish'd by dividing the Matter into smaller +Parts, nor by any other means than by decreasing the Density of the +Medium. And for these Reasons the Density of fluid Mediums is very +nearly proportional to their Resistance. Liquors which differ not much +in Density, as Water, Spirit of Wine, Spirit of Turpentine, hot Oil, +differ not much in Resistance. Water is thirteen or fourteen times +lighter than Quick-silver and by consequence thirteen or fourteen times +rarer, and its Resistance is less than that of Quick-silver in the same +Proportion, or thereabouts, as I have found by Experiments made with +Pendulums. The open Air in which we breathe is eight or nine hundred +times lighter than Water, and by consequence eight or nine hundred times +rarer, and accordingly its Resistance is less than that of Water in the +same Proportion, or thereabouts; as I have also found by Experiments +made with Pendulums. And in thinner Air the Resistance is still less, +and at length, by ratifying the Air, becomes insensible. For small +Feathers falling in the open Air meet with great Resistance, but in a +tall Glass well emptied of Air, they fall as fast as Lead or Gold, as I +have seen tried several times. Whence the Resistance seems still to +decrease in proportion to the Density of the Fluid. For I do not find by +any Experiments, that Bodies moving in Quick-silver, Water or Air, meet +with any other sensible Resistance than what arises from the Density and +Tenacity of those sensible Fluids, as they would do if the Pores of +those Fluids, and all other Spaces, were filled with a dense and +subtile Fluid. Now if the Resistance in a Vessel well emptied of Air, +was but an hundred times less than in the open Air, it would be about a +million of times less than in Quick-silver. But it seems to be much less +in such a Vessel, and still much less in the Heavens, at the height of +three or four hundred Miles from the Earth, or above. For Mr. _Boyle_ +has shew'd that Air may be rarified above ten thousand times in Vessels +of Glass; and the Heavens are much emptier of Air than any _Vacuum_ we +can make below. For since the Air is compress'd by the Weight of the +incumbent Atmosphere, and the Density of Air is proportional to the +Force compressing it, it follows by Computation, that at the height of +about seven and a half _English_ Miles from the Earth, the Air is four +times rarer than at the Surface of the Earth; and at the height of 15 +Miles it is sixteen times rarer than that at the Surface of the Earth; +and at the height of 22-1/2, 30, or 38 Miles, it is respectively 64, +256, or 1024 times rarer, or thereabouts; and at the height of 76, 152, +228 Miles, it is about 1000000, 1000000000000, or 1000000000000000000 +times rarer; and so on. + +Heat promotes Fluidity very much by diminishing the Tenacity of Bodies. +It makes many Bodies fluid which are not fluid in cold, and increases +the Fluidity of tenacious Liquids, as of Oil, Balsam, and Honey, and +thereby decreases their Resistance. But it decreases not the Resistance +of Water considerably, as it would do if any considerable part of the +Resistance of Water arose from the Attrition or Tenacity of its Parts. +And therefore the Resistance of Water arises principally and almost +entirely from the _Vis inertiæ_ of its Matter; and by consequence, if +the Heavens were as dense as Water, they would not have much less +Resistance than Water; if as dense as Quick-silver, they would not have +much less Resistance than Quick-silver; if absolutely dense, or full of +Matter without any _Vacuum_, let the Matter be never so subtil and +fluid, they would have a greater Resistance than Quick-silver. A solid +Globe in such a Medium would lose above half its Motion in moving three +times the length of its Diameter, and a Globe not solid (such as are the +Planets,) would be retarded sooner. And therefore to make way for the +regular and lasting Motions of the Planets and Comets, it's necessary to +empty the Heavens of all Matter, except perhaps some very thin Vapours, +Steams, or Effluvia, arising from the Atmospheres of the Earth, Planets, +and Comets, and from such an exceedingly rare Æthereal Medium as we +described above. A dense Fluid can be of no use for explaining the +Phænomena of Nature, the Motions of the Planets and Comets being better +explain'd without it. It serves only to disturb and retard the Motions +of those great Bodies, and make the Frame of Nature languish: And in the +Pores of Bodies, it serves only to stop the vibrating Motions of their +Parts, wherein their Heat and Activity consists. And as it is of no use, +and hinders the Operations of Nature, and makes her languish, so there +is no evidence for its Existence, and therefore it ought to be rejected. +And if it be rejected, the Hypotheses that Light consists in Pression +or Motion, propagated through such a Medium, are rejected with it. + +And for rejecting such a Medium, we have the Authority of those the +oldest and most celebrated Philosophers of _Greece_ and _Phoenicia_, +who made a _Vacuum_, and Atoms, and the Gravity of Atoms, the first +Principles of their Philosophy; tacitly attributing Gravity to some +other Cause than dense Matter. Later Philosophers banish the +Consideration of such a Cause out of natural Philosophy, feigning +Hypotheses for explaining all things mechanically, and referring other +Causes to Metaphysicks: Whereas the main Business of natural Philosophy +is to argue from Phænomena without feigning Hypotheses, and to deduce +Causes from Effects, till we come to the very first Cause, which +certainly is not mechanical; and not only to unfold the Mechanism of the +World, but chiefly to resolve these and such like Questions. What is +there in places almost empty of Matter, and whence is it that the Sun +and Planets gravitate towards one another, without dense Matter between +them? Whence is it that Nature doth nothing in vain; and whence arises +all that Order and Beauty which we see in the World? To what end are +Comets, and whence is it that Planets move all one and the same way in +Orbs concentrick, while Comets move all manner of ways in Orbs very +excentrick; and what hinders the fix'd Stars from falling upon one +another? How came the Bodies of Animals to be contrived with so much +Art, and for what ends were their several Parts? Was the Eye contrived +without Skill in Opticks, and the Ear without Knowledge of Sounds? How +do the Motions of the Body follow from the Will, and whence is the +Instinct in Animals? Is not the Sensory of Animals that place to which +the sensitive Substance is present, and into which the sensible Species +of Things are carried through the Nerves and Brain, that there they may +be perceived by their immediate presence to that Substance? And these +things being rightly dispatch'd, does it not appear from Phænomena that +there is a Being incorporeal, living, intelligent, omnipresent, who in +infinite Space, as it were in his Sensory, sees the things themselves +intimately, and throughly perceives them, and comprehends them wholly by +their immediate presence to himself: Of which things the Images only +carried through the Organs of Sense into our little Sensoriums, are +there seen and beheld by that which in us perceives and thinks. And +though every true Step made in this Philosophy brings us not immediately +to the Knowledge of the first Cause, yet it brings us nearer to it, and +on that account is to be highly valued. + +_Qu._ 29. Are not the Rays of Light very small Bodies emitted from +shining Substances? For such Bodies will pass through uniform Mediums in +right Lines without bending into the Shadow, which is the Nature of the +Rays of Light. They will also be capable of several Properties, and be +able to conserve their Properties unchanged in passing through several +Mediums, which is another Condition of the Rays of Light. Pellucid +Substances act upon the Rays of Light at a distance in refracting, +reflecting, and inflecting them, and the Rays mutually agitate the Parts +of those Substances at a distance for heating them; and this Action and +Re-action at a distance very much resembles an attractive Force between +Bodies. If Refraction be perform'd by Attraction of the Rays, the Sines +of Incidence must be to the Sines of Refraction in a given Proportion, +as we shew'd in our Principles of Philosophy: And this Rule is true by +Experience. The Rays of Light in going out of Glass into a _Vacuum_, are +bent towards the Glass; and if they fall too obliquely on the _Vacuum_, +they are bent backwards into the Glass, and totally reflected; and this +Reflexion cannot be ascribed to the Resistance of an absolute _Vacuum_, +but must be caused by the Power of the Glass attracting the Rays at +their going out of it into the _Vacuum_, and bringing them back. For if +the farther Surface of the Glass be moisten'd with Water or clear Oil, +or liquid and clear Honey, the Rays which would otherwise be reflected +will go into the Water, Oil, or Honey; and therefore are not reflected +before they arrive at the farther Surface of the Glass, and begin to go +out of it. If they go out of it into the Water, Oil, or Honey, they go +on, because the Attraction of the Glass is almost balanced and rendered +ineffectual by the contrary Attraction of the Liquor. But if they go out +of it into a _Vacuum_ which has no Attraction to balance that of the +Glass, the Attraction of the Glass either bends and refracts them, or +brings them back and reflects them. And this is still more evident by +laying together two Prisms of Glass, or two Object-glasses of very long +Telescopes, the one plane, the other a little convex, and so compressing +them that they do not fully touch, nor are too far asunder. For the +Light which falls upon the farther Surface of the first Glass where the +Interval between the Glasses is not above the ten hundred thousandth +Part of an Inch, will go through that Surface, and through the Air or +_Vacuum_ between the Glasses, and enter into the second Glass, as was +explain'd in the first, fourth, and eighth Observations of the first +Part of the second Book. But, if the second Glass be taken away, the +Light which goes out of the second Surface of the first Glass into the +Air or _Vacuum_, will not go on forwards, but turns back into the first +Glass, and is reflected; and therefore it is drawn back by the Power of +the first Glass, there being nothing else to turn it back. Nothing more +is requisite for producing all the variety of Colours, and degrees of +Refrangibility, than that the Rays of Light be Bodies of different +Sizes, the least of which may take violet the weakest and darkest of the +Colours, and be more easily diverted by refracting Surfaces from the +right Course; and the rest as they are bigger and bigger, may make the +stronger and more lucid Colours, blue, green, yellow, and red, and be +more and more difficultly diverted. Nothing more is requisite for +putting the Rays of Light into Fits of easy Reflexion and easy +Transmission, than that they be small Bodies which by their attractive +Powers, or some other Force, stir up Vibrations in what they act upon, +which Vibrations being swifter than the Rays, overtake them +successively, and agitate them so as by turns to increase and decrease +their Velocities, and thereby put them into those Fits. And lastly, the +unusual Refraction of Island-Crystal looks very much as if it were +perform'd by some kind of attractive virtue lodged in certain Sides both +of the Rays, and of the Particles of the Crystal. For were it not for +some kind of Disposition or Virtue lodged in some Sides of the Particles +of the Crystal, and not in their other Sides, and which inclines and +bends the Rays towards the Coast of unusual Refraction, the Rays which +fall perpendicularly on the Crystal, would not be refracted towards that +Coast rather than towards any other Coast, both at their Incidence and +at their Emergence, so as to emerge perpendicularly by a contrary +Situation of the Coast of unusual Refraction at the second Surface; the +Crystal acting upon the Rays after they have pass'd through it, and are +emerging into the Air; or, if you please, into a _Vacuum_. And since the +Crystal by this Disposition or Virtue does not act upon the Rays, unless +when one of their Sides of unusual Refraction looks towards that Coast, +this argues a Virtue or Disposition in those Sides of the Rays, which +answers to, and sympathizes with that Virtue or Disposition of the +Crystal, as the Poles of two Magnets answer to one another. And as +Magnetism may be intended and remitted, and is found only in the Magnet +and in Iron: So this Virtue of refracting the perpendicular Rays is +greater in Island-Crystal, less in Crystal of the Rock, and is not yet +found in other Bodies. I do not say that this Virtue is magnetical: It +seems to be of another kind. I only say, that whatever it be, it's +difficult to conceive how the Rays of Light, unless they be Bodies, can +have a permanent Virtue in two of their Sides which is not in their +other Sides, and this without any regard to their Position to the Space +or Medium through which they pass. + +What I mean in this Question by a _Vacuum_, and by the Attractions of +the Rays of Light towards Glass or Crystal, may be understood by what +was said in the 18th, 19th, and 20th Questions. + +_Quest._ 30. Are not gross Bodies and Light convertible into one +another, and may not Bodies receive much of their Activity from the +Particles of Light which enter their Composition? For all fix'd Bodies +being heated emit Light so long as they continue sufficiently hot, and +Light mutually stops in Bodies as often as its Rays strike upon their +Parts, as we shew'd above. I know no Body less apt to shine than Water; +and yet Water by frequent Distillations changes into fix'd Earth, as Mr. +_Boyle_ has try'd; and then this Earth being enabled to endure a +sufficient Heat, shines by Heat like other Bodies. + +The changing of Bodies into Light, and Light into Bodies, is very +conformable to the Course of Nature, which seems delighted with +Transmutations. Water, which is a very fluid tasteless Salt, she changes +by Heat into Vapour, which is a sort of Air, and by Cold into Ice, which +is a hard, pellucid, brittle, fusible Stone; and this Stone returns into +Water by Heat, and Vapour returns into Water by Cold. Earth by Heat +becomes Fire, and by Cold returns into Earth. Dense Bodies by +Fermentation rarify into several sorts of Air, and this Air by +Fermentation, and sometimes without it, returns into dense Bodies. +Mercury appears sometimes in the form of a fluid Metal, sometimes in the +form of a hard brittle Metal, sometimes in the form of a corrosive +pellucid Salt call'd Sublimate, sometimes in the form of a tasteless, +pellucid, volatile white Earth, call'd _Mercurius Dulcis_; or in that of +a red opake volatile Earth, call'd Cinnaber; or in that of a red or +white Precipitate, or in that of a fluid Salt; and in Distillation it +turns into Vapour, and being agitated _in Vacuo_, it shines like Fire. +And after all these Changes it returns again into its first form of +Mercury. Eggs grow from insensible Magnitudes, and change into Animals; +Tadpoles into Frogs; and Worms into Flies. All Birds, Beasts and Fishes, +Insects, Trees, and other Vegetables, with their several Parts, grow out +of Water and watry Tinctures and Salts, and by Putrefaction return again +into watry Substances. And Water standing a few Days in the open Air, +yields a Tincture, which (like that of Malt) by standing longer yields a +Sediment and a Spirit, but before Putrefaction is fit Nourishment for +Animals and Vegetables. And among such various and strange +Transmutations, why may not Nature change Bodies into Light, and Light +into Bodies? + +_Quest._ 31. Have not the small Particles of Bodies certain Powers, +Virtues, or Forces, by which they act at a distance, not only upon the +Rays of Light for reflecting, refracting, and inflecting them, but also +upon one another for producing a great Part of the Phænomena of Nature? +For it's well known, that Bodies act one upon another by the Attractions +of Gravity, Magnetism, and Electricity; and these Instances shew the +Tenor and Course of Nature, and make it not improbable but that there +may be more attractive Powers than these. For Nature is very consonant +and conformable to her self. How these Attractions may be perform'd, I +do not here consider. What I call Attraction may be perform'd by +impulse, or by some other means unknown to me. I use that Word here to +signify only in general any Force by which Bodies tend towards one +another, whatsoever be the Cause. For we must learn from the Phænomena +of Nature what Bodies attract one another, and what are the Laws and +Properties of the Attraction, before we enquire the Cause by which the +Attraction is perform'd. The Attractions of Gravity, Magnetism, and +Electricity, reach to very sensible distances, and so have been observed +by vulgar Eyes, and there may be others which reach to so small +distances as hitherto escape Observation; and perhaps electrical +Attraction may reach to such small distances, even without being excited +by Friction. + +For when Salt of Tartar runs _per Deliquium_, is not this done by an +Attraction between the Particles of the Salt of Tartar, and the +Particles of the Water which float in the Air in the form of Vapours? +And why does not common Salt, or Salt-petre, or Vitriol, run _per +Deliquium_, but for want of such an Attraction? Or why does not Salt of +Tartar draw more Water out of the Air than in a certain Proportion to +its quantity, but for want of an attractive Force after it is satiated +with Water? And whence is it but from this attractive Power that Water +which alone distils with a gentle luke-warm Heat, will not distil from +Salt of Tartar without a great Heat? And is it not from the like +attractive Power between the Particles of Oil of Vitriol and the +Particles of Water, that Oil of Vitriol draws to it a good quantity of +Water out of the Air, and after it is satiated draws no more, and in +Distillation lets go the Water very difficultly? And when Water and Oil +of Vitriol poured successively into the same Vessel grow very hot in the +mixing, does not this Heat argue a great Motion in the Parts of the +Liquors? And does not this Motion argue, that the Parts of the two +Liquors in mixing coalesce with Violence, and by consequence rush +towards one another with an accelerated Motion? And when _Aqua fortis_, +or Spirit of Vitriol poured upon Filings of Iron dissolves the Filings +with a great Heat and Ebullition, is not this Heat and Ebullition +effected by a violent Motion of the Parts, and does not that Motion +argue that the acid Parts of the Liquor rush towards the Parts of the +Metal with violence, and run forcibly into its Pores till they get +between its outmost Particles, and the main Mass of the Metal, and +surrounding those Particles loosen them from the main Mass, and set them +at liberty to float off into the Water? And when the acid Particles, +which alone would distil with an easy Heat, will not separate from the +Particles of the Metal without a very violent Heat, does not this +confirm the Attraction between them? + +When Spirit of Vitriol poured upon common Salt or Salt-petre makes an +Ebullition with the Salt, and unites with it, and in Distillation the +Spirit of the common Salt or Salt-petre comes over much easier than it +would do before, and the acid part of the Spirit of Vitriol stays +behind; does not this argue that the fix'd Alcaly of the Salt attracts +the acid Spirit of the Vitriol more strongly than its own Spirit, and +not being able to hold them both, lets go its own? And when Oil of +Vitriol is drawn off from its weight of Nitre, and from both the +Ingredients a compound Spirit of Nitre is distilled, and two parts of +this Spirit are poured on one part of Oil of Cloves or Carraway Seeds, +or of any ponderous Oil of vegetable or animal Substances, or Oil of +Turpentine thicken'd with a little Balsam of Sulphur, and the Liquors +grow so very hot in mixing, as presently to send up a burning Flame; +does not this very great and sudden Heat argue that the two Liquors mix +with violence, and that their Parts in mixing run towards one another +with an accelerated Motion, and clash with the greatest Force? And is it +not for the same reason that well rectified Spirit of Wine poured on the +same compound Spirit flashes; and that the _Pulvis fulminans_, composed +of Sulphur, Nitre, and Salt of Tartar, goes off with a more sudden and +violent Explosion than Gun-powder, the acid Spirits of the Sulphur and +Nitre rushing towards one another, and towards the Salt of Tartar, with +so great a violence, as by the shock to turn the whole at once into +Vapour and Flame? Where the Dissolution is slow, it makes a slow +Ebullition and a gentle Heat; and where it is quicker, it makes a +greater Ebullition with more heat; and where it is done at once, the +Ebullition is contracted into a sudden Blast or violent Explosion, with +a heat equal to that of Fire and Flame. So when a Drachm of the +above-mention'd compound Spirit of Nitre was poured upon half a Drachm +of Oil of Carraway Seeds _in vacuo_, the Mixture immediately made a +flash like Gun-powder, and burst the exhausted Receiver, which was a +Glass six Inches wide, and eight Inches deep. And even the gross Body of +Sulphur powder'd, and with an equal weight of Iron Filings and a little +Water made into Paste, acts upon the Iron, and in five or six hours +grows too hot to be touch'd, and emits a Flame. And by these Experiments +compared with the great quantity of Sulphur with which the Earth +abounds, and the warmth of the interior Parts of the Earth, and hot +Springs, and burning Mountains, and with Damps, mineral Coruscations, +Earthquakes, hot suffocating Exhalations, Hurricanes, and Spouts; we may +learn that sulphureous Steams abound in the Bowels of the Earth and +ferment with Minerals, and sometimes take fire with a sudden Coruscation +and Explosion; and if pent up in subterraneous Caverns, burst the +Caverns with a great shaking of the Earth, as in springing of a Mine. +And then the Vapour generated by the Explosion, expiring through the +Pores of the Earth, feels hot and suffocates, and makes Tempests and +Hurricanes, and sometimes causes the Land to slide, or the Sea to boil, +and carries up the Water thereof in Drops, which by their weight fall +down again in Spouts. Also some sulphureous Steams, at all times when +the Earth is dry, ascending into the Air, ferment there with nitrous +Acids, and sometimes taking fire cause Lightning and Thunder, and fiery +Meteors. For the Air abounds with acid Vapours fit to promote +Fermentations, as appears by the rusting of Iron and Copper in it, the +kindling of Fire by blowing, and the beating of the Heart by means of +Respiration. Now the above-mention'd Motions are so great and violent as +to shew that in Fermentations the Particles of Bodies which almost rest, +are put into new Motions by a very potent Principle, which acts upon +them only when they approach one another, and causes them to meet and +clash with great violence, and grow hot with the motion, and dash one +another into pieces, and vanish into Air, and Vapour, and Flame. + +When Salt of Tartar _per deliquium_, being poured into the Solution of +any Metal, precipitates the Metal and makes it fall down to the bottom +of the Liquor in the form of Mud: Does not this argue that the acid +Particles are attracted more strongly by the Salt of Tartar than by the +Metal, and by the stronger Attraction go from the Metal to the Salt of +Tartar? And so when a Solution of Iron in _Aqua fortis_ dissolves the +_Lapis Calaminaris_, and lets go the Iron, or a Solution of Copper +dissolves Iron immersed in it and lets go the Copper, or a Solution of +Silver dissolves Copper and lets go the Silver, or a Solution of Mercury +in _Aqua fortis_ being poured upon Iron, Copper, Tin, or Lead, dissolves +the Metal and lets go the Mercury; does not this argue that the acid +Particles of the _Aqua fortis_ are attracted more strongly by the _Lapis +Calaminaris_ than by Iron, and more strongly by Iron than by Copper, and +more strongly by Copper than by Silver, and more strongly by Iron, +Copper, Tin, and Lead, than by Mercury? And is it not for the same +reason that Iron requires more _Aqua fortis_ to dissolve it than Copper, +and Copper more than the other Metals; and that of all Metals, Iron is +dissolved most easily, and is most apt to rust; and next after Iron, +Copper? + +When Oil of Vitriol is mix'd with a little Water, or is run _per +deliquium_, and in Distillation the Water ascends difficultly, and +brings over with it some part of the Oil of Vitriol in the form of +Spirit of Vitriol, and this Spirit being poured upon Iron, Copper, or +Salt of Tartar, unites with the Body and lets go the Water; doth not +this shew that the acid Spirit is attracted by the Water, and more +attracted by the fix'd Body than by the Water, and therefore lets go the +Water to close with the fix'd Body? And is it not for the same reason +that the Water and acid Spirits which are mix'd together in Vinegar, +_Aqua fortis_, and Spirit of Salt, cohere and rise together in +Distillation; but if the _Menstruum_ be poured on Salt of Tartar, or on +Lead, or Iron, or any fix'd Body which it can dissolve, the Acid by a +stronger Attraction adheres to the Body, and lets go the Water? And is +it not also from a mutual Attraction that the Spirits of Soot and +Sea-Salt unite and compose the Particles of Sal-armoniac, which are less +volatile than before, because grosser and freer from Water; and that the +Particles of Sal-armoniac in Sublimation carry up the Particles of +Antimony, which will not sublime alone; and that the Particles of +Mercury uniting with the acid Particles of Spirit of Salt compose +Mercury sublimate, and with the Particles of Sulphur, compose Cinnaber; +and that the Particles of Spirit of Wine and Spirit of Urine well +rectified unite, and letting go the Water which dissolved them, compose +a consistent Body; and that in subliming Cinnaber from Salt of Tartar, +or from quick Lime, the Sulphur by a stronger Attraction of the Salt or +Lime lets go the Mercury, and stays with the fix'd Body; and that when +Mercury sublimate is sublimed from Antimony, or from Regulus of +Antimony, the Spirit of Salt lets go the Mercury, and unites with the +antimonial metal which attracts it more strongly, and stays with it till +the Heat be great enough to make them both ascend together, and then +carries up the Metal with it in the form of a very fusible Salt, called +Butter of Antimony, although the Spirit of Salt alone be almost as +volatile as Water, and the Antimony alone as fix'd as Lead? + +When _Aqua fortis_ dissolves Silver and not Gold, and _Aqua regia_ +dissolves Gold and not Silver, may it not be said that _Aqua fortis_ is +subtil enough to penetrate Gold as well as Silver, but wants the +attractive Force to give it Entrance; and that _Aqua regia_ is subtil +enough to penetrate Silver as well as Gold, but wants the attractive +Force to give it Entrance? For _Aqua regia_ is nothing else than _Aqua +fortis_ mix'd with some Spirit of Salt, or with Sal-armoniac; and even +common Salt dissolved in _Aqua fortis_, enables the _Menstruum_ to +dissolve Gold, though the Salt be a gross Body. When therefore Spirit of +Salt precipitates Silver out of _Aqua fortis_, is it not done by +attracting and mixing with the _Aqua fortis_, and not attracting, or +perhaps repelling Silver? And when Water precipitates Antimony out of +the Sublimate of Antimony and Sal-armoniac, or out of Butter of +Antimony, is it not done by its dissolving, mixing with, and weakening +the Sal-armoniac or Spirit of Salt, and its not attracting, or perhaps +repelling the Antimony? And is it not for want of an attractive virtue +between the Parts of Water and Oil, of Quick-silver and Antimony, of +Lead and Iron, that these Substances do not mix; and by a weak +Attraction, that Quick-silver and Copper mix difficultly; and from a +strong one, that Quick-silver and Tin, Antimony and Iron, Water and +Salts, mix readily? And in general, is it not from the same Principle +that Heat congregates homogeneal Bodies, and separates heterogeneal +ones? + +When Arsenick with Soap gives a Regulus, and with Mercury sublimate a +volatile fusible Salt, like Butter of Antimony, doth not this shew that +Arsenick, which is a Substance totally volatile, is compounded of fix'd +and volatile Parts, strongly cohering by a mutual Attraction, so that +the volatile will not ascend without carrying up the fixed? And so, when +an equal weight of Spirit of Wine and Oil of Vitriol are digested +together, and in Distillation yield two fragrant and volatile Spirits +which will not mix with one another, and a fix'd black Earth remains +behind; doth not this shew that Oil of Vitriol is composed of volatile +and fix'd Parts strongly united by Attraction, so as to ascend together +in form of a volatile, acid, fluid Salt, until the Spirit of Wine +attracts and separates the volatile Parts from the fixed? And therefore, +since Oil of Sulphur _per Campanam_ is of the same Nature with Oil of +Vitriol, may it not be inferred, that Sulphur is also a mixture of +volatile and fix'd Parts so strongly cohering by Attraction, as to +ascend together in Sublimation. By dissolving Flowers of Sulphur in Oil +of Turpentine, and distilling the Solution, it is found that Sulphur is +composed of an inflamable thick Oil or fat Bitumen, an acid Salt, a very +fix'd Earth, and a little Metal. The three first were found not much +unequal to one another, the fourth in so small a quantity as scarce to +be worth considering. The acid Salt dissolved in Water, is the same with +Oil of Sulphur _per Campanam_, and abounding much in the Bowels of the +Earth, and particularly in Markasites, unites it self to the other +Ingredients of the Markasite, which are, Bitumen, Iron, Copper, and +Earth, and with them compounds Allum, Vitriol, and Sulphur. With the +Earth alone it compounds Allum; with the Metal alone, or Metal and +Earth together, it compounds Vitriol; and with the Bitumen and Earth it +compounds Sulphur. Whence it comes to pass that Markasites abound with +those three Minerals. And is it not from the mutual Attraction of the +Ingredients that they stick together for compounding these Minerals, and +that the Bitumen carries up the other Ingredients of the Sulphur, which +without it would not sublime? And the same Question may be put +concerning all, or almost all the gross Bodies in Nature. For all the +Parts of Animals and Vegetables are composed of Substances volatile and +fix'd, fluid and solid, as appears by their Analysis; and so are Salts +and Minerals, so far as Chymists have been hitherto able to examine +their Composition. + +When Mercury sublimate is re-sublimed with fresh Mercury, and becomes +_Mercurius Dulcis_, which is a white tasteless Earth scarce dissolvable +in Water, and _Mercurius Dulcis_ re-sublimed with Spirit of Salt returns +into Mercury sublimate; and when Metals corroded with a little acid turn +into rust, which is an Earth tasteless and indissolvable in Water, and +this Earth imbibed with more acid becomes a metallick Salt; and when +some Stones, as Spar of Lead, dissolved in proper _Menstruums_ become +Salts; do not these things shew that Salts are dry Earth and watry Acid +united by Attraction, and that the Earth will not become a Salt without +so much acid as makes it dissolvable in Water? Do not the sharp and +pungent Tastes of Acids arise from the strong Attraction whereby the +acid Particles rush upon and agitate the Particles of the Tongue? And +when Metals are dissolved in acid _Menstruums_, and the Acids in +conjunction with the Metal act after a different manner, so that the +Compound has a different Taste much milder than before, and sometimes a +sweet one; is it not because the Acids adhere to the metallick +Particles, and thereby lose much of their Activity? And if the Acid be +in too small a Proportion to make the Compound dissolvable in Water, +will it not by adhering strongly to the Metal become unactive and lose +its Taste, and the Compound be a tasteless Earth? For such things as are +not dissolvable by the Moisture of the Tongue, act not upon the Taste. + +As Gravity makes the Sea flow round the denser and weightier Parts of +the Globe of the Earth, so the Attraction may make the watry Acid flow +round the denser and compacter Particles of Earth for composing the +Particles of Salt. For otherwise the Acid would not do the Office of a +Medium between the Earth and common Water, for making Salts dissolvable +in the Water; nor would Salt of Tartar readily draw off the Acid from +dissolved Metals, nor Metals the Acid from Mercury. Now, as in the great +Globe of the Earth and Sea, the densest Bodies by their Gravity sink +down in Water, and always endeavour to go towards the Center of the +Globe; so in Particles of Salt, the densest Matter may always endeavour +to approach the Center of the Particle: So that a Particle of Salt may +be compared to a Chaos; being dense, hard, dry, and earthy in the +Center; and rare, soft, moist, and watry in the Circumference. And +hence it seems to be that Salts are of a lasting Nature, being scarce +destroy'd, unless by drawing away their watry Parts by violence, or by +letting them soak into the Pores of the central Earth by a gentle Heat +in Putrefaction, until the Earth be dissolved by the Water, and +separated into smaller Particles, which by reason of their Smallness +make the rotten Compound appear of a black Colour. Hence also it may be, +that the Parts of Animals and Vegetables preserve their several Forms, +and assimilate their Nourishment; the soft and moist Nourishment easily +changing its Texture by a gentle Heat and Motion, till it becomes like +the dense, hard, dry, and durable Earth in the Center of each Particle. +But when the Nourishment grows unfit to be assimilated, or the central +Earth grows too feeble to assimilate it, the Motion ends in Confusion, +Putrefaction, and Death. + +If a very small quantity of any Salt or Vitriol be dissolved in a great +quantity of Water, the Particles of the Salt or Vitriol will not sink to +the bottom, though they be heavier in Specie than the Water, but will +evenly diffuse themselves into all the Water, so as to make it as saline +at the top as at the bottom. And does not this imply that the Parts of +the Salt or Vitriol recede from one another, and endeavour to expand +themselves, and get as far asunder as the quantity of Water in which +they float, will allow? And does not this Endeavour imply that they have +a repulsive Force by which they fly from one another, or at least, that +they attract the Water more strongly than they do one another? For as +all things ascend in Water which are less attracted than Water, by the +gravitating Power of the Earth; so all the Particles of Salt which float +in Water, and are less attracted than Water by any one Particle of Salt, +must recede from that Particle, and give way to the more attracted +Water. + +When any saline Liquor is evaporated to a Cuticle and let cool, the Salt +concretes in regular Figures; which argues, that the Particles of the +Salt before they concreted, floated in the Liquor at equal distances in +rank and file, and by consequence that they acted upon one another by +some Power which at equal distances is equal, at unequal distances +unequal. For by such a Power they will range themselves uniformly, and +without it they will float irregularly, and come together as +irregularly. And since the Particles of Island-Crystal act all the same +way upon the Rays of Light for causing the unusual Refraction, may it +not be supposed that in the Formation of this Crystal, the Particles not +only ranged themselves in rank and file for concreting in regular +Figures, but also by some kind of polar Virtue turned their homogeneal +Sides the same way. + +The Parts of all homogeneal hard Bodies which fully touch one another, +stick together very strongly. And for explaining how this may be, some +have invented hooked Atoms, which is begging the Question; and others +tell us that Bodies are glued together by rest, that is, by an occult +Quality, or rather by nothing; and others, that they stick together by +conspiring Motions, that is, by relative rest amongst themselves. I had +rather infer from their Cohesion, that their Particles attract one +another by some Force, which in immediate Contact is exceeding strong, +at small distances performs the chymical Operations above-mention'd, and +reaches not far from the Particles with any sensible Effect. + +All Bodies seem to be composed of hard Particles: For otherwise Fluids +would not congeal; as Water, Oils, Vinegar, and Spirit or Oil of Vitriol +do by freezing; Mercury by Fumes of Lead; Spirit of Nitre and Mercury, +by dissolving the Mercury and evaporating the Flegm; Spirit of Wine and +Spirit of Urine, by deflegming and mixing them; and Spirit of Urine and +Spirit of Salt, by subliming them together to make Sal-armoniac. Even +the Rays of Light seem to be hard Bodies; for otherwise they would not +retain different Properties in their different Sides. And therefore +Hardness may be reckon'd the Property of all uncompounded Matter. At +least, this seems to be as evident as the universal Impenetrability of +Matter. For all Bodies, so far as Experience reaches, are either hard, +or may be harden'd; and we have no other Evidence of universal +Impenetrability, besides a large Experience without an experimental +Exception. Now if compound Bodies are so very hard as we find some of +them to be, and yet are very porous, and consist of Parts which are only +laid together; the simple Particles which are void of Pores, and were +never yet divided, must be much harder. For such hard Particles being +heaped up together, can scarce touch one another in more than a few +Points, and therefore must be separable by much less Force than is +requisite to break a solid Particle, whose Parts touch in all the Space +between them, without any Pores or Interstices to weaken their Cohesion. +And how such very hard Particles which are only laid together and touch +only in a few Points, can stick together, and that so firmly as they do, +without the assistance of something which causes them to be attracted or +press'd towards one another, is very difficult to conceive. + +The same thing I infer also from the cohering of two polish'd Marbles +_in vacuo_, and from the standing of Quick-silver in the Barometer at +the height of 50, 60 or 70 Inches, or above, when ever it is well-purged +of Air and carefully poured in, so that its Parts be every where +contiguous both to one another and to the Glass. The Atmosphere by its +weight presses the Quick-silver into the Glass, to the height of 29 or +30 Inches. And some other Agent raises it higher, not by pressing it +into the Glass, but by making its Parts stick to the Glass, and to one +another. For upon any discontinuation of Parts, made either by Bubbles +or by shaking the Glass, the whole Mercury falls down to the height of +29 or 30 Inches. + +And of the same kind with these Experiments are those that follow. If +two plane polish'd Plates of Glass (suppose two pieces of a polish'd +Looking-glass) be laid together, so that their sides be parallel and at +a very small distance from one another, and then their lower edges be +dipped into Water, the Water will rise up between them. And the less +the distance of the Glasses is, the greater will be the height to which +the Water will rise. If the distance be about the hundredth part of an +Inch, the Water will rise to the height of about an Inch; and if the +distance be greater or less in any Proportion, the height will be +reciprocally proportional to the distance very nearly. For the +attractive Force of the Glasses is the same, whether the distance +between them be greater or less; and the weight of the Water drawn up is +the same, if the height of it be reciprocally proportional to the +distance of the Glasses. And in like manner, Water ascends between two +Marbles polish'd plane, when their polish'd sides are parallel, and at a +very little distance from one another, And if slender Pipes of Glass be +dipped at one end into stagnating Water, the Water will rise up within +the Pipe, and the height to which it rises will be reciprocally +proportional to the Diameter of the Cavity of the Pipe, and will equal +the height to which it rises between two Planes of Glass, if the +Semi-diameter of the Cavity of the Pipe be equal to the distance between +the Planes, or thereabouts. And these Experiments succeed after the same +manner _in vacuo_ as in the open Air, (as hath been tried before the +Royal Society,) and therefore are not influenced by the Weight or +Pressure of the Atmosphere. + +And if a large Pipe of Glass be filled with sifted Ashes well pressed +together in the Glass, and one end of the Pipe be dipped into stagnating +Water, the Water will rise up slowly in the Ashes, so as in the space +of a Week or Fortnight to reach up within the Glass, to the height of 30 +or 40 Inches above the stagnating Water. And the Water rises up to this +height by the Action only of those Particles of the Ashes which are upon +the Surface of the elevated Water; the Particles which are within the +Water, attracting or repelling it as much downwards as upwards. And +therefore the Action of the Particles is very strong. But the Particles +of the Ashes being not so dense and close together as those of Glass, +their Action is not so strong as that of Glass, which keeps Quick-silver +suspended to the height of 60 or 70 Inches, and therefore acts with a +Force which would keep Water suspended to the height of above 60 Feet. + +By the same Principle, a Sponge sucks in Water, and the Glands in the +Bodies of Animals, according to their several Natures and Dispositions, +suck in various Juices from the Blood. + +If two plane polish'd Plates of Glass three or four Inches broad, and +twenty or twenty five long, be laid one of them parallel to the Horizon, +the other upon the first, so as at one of their ends to touch one +another, and contain an Angle of about 10 or 15 Minutes, and the same be +first moisten'd on their inward sides with a clean Cloth dipp'd into Oil +of Oranges or Spirit of Turpentine, and a Drop or two of the Oil or +Spirit be let fall upon the lower Glass at the other; so soon as the +upper Glass is laid down upon the lower, so as to touch it at one end as +above, and to touch the Drop at the other end, making with the lower +Glass an Angle of about 10 or 15 Minutes; the Drop will begin to move +towards the Concourse of the Glasses, and will continue to move with an +accelerated Motion, till it arrives at that Concourse of the Glasses. +For the two Glasses attract the Drop, and make it run that way towards +which the Attractions incline. And if when the Drop is in motion you +lift up that end of the Glasses where they meet, and towards which the +Drop moves, the Drop will ascend between the Glasses, and therefore is +attracted. And as you lift up the Glasses more and more, the Drop will +ascend slower and slower, and at length rest, being then carried +downward by its Weight, as much as upwards by the Attraction. And by +this means you may know the Force by which the Drop is attracted at all +distances from the Concourse of the Glasses. + +Now by some Experiments of this kind, (made by Mr. _Hauksbee_) it has +been found that the Attraction is almost reciprocally in a duplicate +Proportion of the distance of the middle of the Drop from the Concourse +of the Glasses, _viz._ reciprocally in a simple Proportion, by reason of +the spreading of the Drop, and its touching each Glass in a larger +Surface; and again reciprocally in a simple Proportion, by reason of the +Attractions growing stronger within the same quantity of attracting +Surface. The Attraction therefore within the same quantity of attracting +Surface, is reciprocally as the distance between the Glasses. And +therefore where the distance is exceeding small, the Attraction must be +exceeding great. By the Table in the second Part of the second Book, +wherein the thicknesses of colour'd Plates of Water between two Glasses +are set down, the thickness of the Plate where it appears very black, is +three eighths of the ten hundred thousandth part of an Inch. And where +the Oil of Oranges between the Glasses is of this thickness, the +Attraction collected by the foregoing Rule, seems to be so strong, as +within a Circle of an Inch in diameter, to suffice to hold up a Weight +equal to that of a Cylinder of Water of an Inch in diameter, and two or +three Furlongs in length. And where it is of a less thickness the +Attraction may be proportionally greater, and continue to increase, +until the thickness do not exceed that of a single Particle of the Oil. +There are therefore Agents in Nature able to make the Particles of +Bodies stick together by very strong Attractions. And it is the Business +of experimental Philosophy to find them out. + +Now the smallest Particles of Matter may cohere by the strongest +Attractions, and compose bigger Particles of weaker Virtue; and many of +these may cohere and compose bigger Particles whose Virtue is still +weaker, and so on for divers Successions, until the Progression end in +the biggest Particles on which the Operations in Chymistry, and the +Colours of natural Bodies depend, and which by cohering compose Bodies +of a sensible Magnitude. If the Body is compact, and bends or yields +inward to Pression without any sliding of its Parts, it is hard and +elastick, returning to its Figure with a Force rising from the mutual +Attraction of its Parts. If the Parts slide upon one another, the Body +is malleable or soft. If they slip easily, and are of a fit Size to be +agitated by Heat, and the Heat is big enough to keep them in Agitation, +the Body is fluid; and if it be apt to stick to things, it is humid; and +the Drops of every fluid affect a round Figure by the mutual Attraction +of their Parts, as the Globe of the Earth and Sea affects a round Figure +by the mutual Attraction of its Parts by Gravity. + +Since Metals dissolved in Acids attract but a small quantity of the +Acid, their attractive Force can reach but to a small distance from +them. And as in Algebra, where affirmative Quantities vanish and cease, +there negative ones begin; so in Mechanicks, where Attraction ceases, +there a repulsive Virtue ought to succeed. And that there is such a +Virtue, seems to follow from the Reflexions and Inflexions of the Rays +of Light. For the Rays are repelled by Bodies in both these Cases, +without the immediate Contact of the reflecting or inflecting Body. It +seems also to follow from the Emission of Light; the Ray so soon as it +is shaken off from a shining Body by the vibrating Motion of the Parts +of the Body, and gets beyond the reach of Attraction, being driven away +with exceeding great Velocity. For that Force which is sufficient to +turn it back in Reflexion, may be sufficient to emit it. It seems also +to follow from the Production of Air and Vapour. The Particles when they +are shaken off from Bodies by Heat or Fermentation, so soon as they are +beyond the reach of the Attraction of the Body, receding from it, and +also from one another with great Strength, and keeping at a distance, +so as sometimes to take up above a Million of Times more space than they +did before in the form of a dense Body. Which vast Contraction and +Expansion seems unintelligible, by feigning the Particles of Air to be +springy and ramous, or rolled up like Hoops, or by any other means than +a repulsive Power. The Particles of Fluids which do not cohere too +strongly, and are of such a Smallness as renders them most susceptible +of those Agitations which keep Liquors in a Fluor, are most easily +separated and rarified into Vapour, and in the Language of the Chymists, +they are volatile, rarifying with an easy Heat, and condensing with +Cold. But those which are grosser, and so less susceptible of Agitation, +or cohere by a stronger Attraction, are not separated without a stronger +Heat, or perhaps not without Fermentation. And these last are the Bodies +which Chymists call fix'd, and being rarified by Fermentation, become +true permanent Air; those Particles receding from one another with the +greatest Force, and being most difficultly brought together, which upon +Contact cohere most strongly. And because the Particles of permanent Air +are grosser, and arise from denser Substances than those of Vapours, +thence it is that true Air is more ponderous than Vapour, and that a +moist Atmosphere is lighter than a dry one, quantity for quantity. From +the same repelling Power it seems to be that Flies walk upon the Water +without wetting their Feet; and that the Object-glasses of long +Telescopes lie upon one another without touching; and that dry Powders +are difficultly made to touch one another so as to stick together, +unless by melting them, or wetting them with Water, which by exhaling +may bring them together; and that two polish'd Marbles, which by +immediate Contact stick together, are difficultly brought so close +together as to stick. + +And thus Nature will be very conformable to her self and very simple, +performing all the great Motions of the heavenly Bodies by the +Attraction of Gravity which intercedes those Bodies, and almost all the +small ones of their Particles by some other attractive and repelling +Powers which intercede the Particles. The _Vis inertiæ_ is a passive +Principle by which Bodies persist in their Motion or Rest, receive +Motion in proportion to the Force impressing it, and resist as much as +they are resisted. By this Principle alone there never could have been +any Motion in the World. Some other Principle was necessary for putting +Bodies into Motion; and now they are in Motion, some other Principle is +necessary for conserving the Motion. For from the various Composition of +two Motions, 'tis very certain that there is not always the same +quantity of Motion in the World. For if two Globes joined by a slender +Rod, revolve about their common Center of Gravity with an uniform +Motion, while that Center moves on uniformly in a right Line drawn in +the Plane of their circular Motion; the Sum of the Motions of the two +Globes, as often as the Globes are in the right Line described by their +common Center of Gravity, will be bigger than the Sum of their Motions, +when they are in a Line perpendicular to that right Line. By this +Instance it appears that Motion may be got or lost. But by reason of the +Tenacity of Fluids, and Attrition of their Parts, and the Weakness of +Elasticity in Solids, Motion is much more apt to be lost than got, and +is always upon the Decay. For Bodies which are either absolutely hard, +or so soft as to be void of Elasticity, will not rebound from one +another. Impenetrability makes them only stop. If two equal Bodies meet +directly _in vacuo_, they will by the Laws of Motion stop where they +meet, and lose all their Motion, and remain in rest, unless they be +elastick, and receive new Motion from their Spring. If they have so much +Elasticity as suffices to make them re-bound with a quarter, or half, or +three quarters of the Force with which they come together, they will +lose three quarters, or half, or a quarter of their Motion. And this may +be try'd, by letting two equal Pendulums fall against one another from +equal heights. If the Pendulums be of Lead or soft Clay, they will lose +all or almost all their Motions: If of elastick Bodies they will lose +all but what they recover from their Elasticity. If it be said, that +they can lose no Motion but what they communicate to other Bodies, the +consequence is, that _in vacuo_ they can lose no Motion, but when they +meet they must go on and penetrate one another's Dimensions. If three +equal round Vessels be filled, the one with Water, the other with Oil, +the third with molten Pitch, and the Liquors be stirred about alike to +give them a vortical Motion; the Pitch by its Tenacity will lose its +Motion quickly, the Oil being less tenacious will keep it longer, and +the Water being less tenacious will keep it longest, but yet will lose +it in a short time. Whence it is easy to understand, that if many +contiguous Vortices of molten Pitch were each of them as large as those +which some suppose to revolve about the Sun and fix'd Stars, yet these +and all their Parts would, by their Tenacity and Stiffness, communicate +their Motion to one another till they all rested among themselves. +Vortices of Oil or Water, or some fluider Matter, might continue longer +in Motion; but unless the Matter were void of all Tenacity and Attrition +of Parts, and Communication of Motion, (which is not to be supposed,) +the Motion would constantly decay. Seeing therefore the variety of +Motion which we find in the World is always decreasing, there is a +necessity of conserving and recruiting it by active Principles, such as +are the cause of Gravity, by which Planets and Comets keep their Motions +in their Orbs, and Bodies acquire great Motion in falling; and the cause +of Fermentation, by which the Heart and Blood of Animals are kept in +perpetual Motion and Heat; the inward Parts of the Earth are constantly +warm'd, and in some places grow very hot; Bodies burn and shine, +Mountains take fire, the Caverns of the Earth are blown up, and the Sun +continues violently hot and lucid, and warms all things by his Light. +For we meet with very little Motion in the World, besides what is owing +to these active Principles. And if it were not for these Principles, the +Bodies of the Earth, Planets, Comets, Sun, and all things in them, +would grow cold and freeze, and become inactive Masses; and all +Putrefaction, Generation, Vegetation and Life would cease, and the +Planets and Comets would not remain in their Orbs. + +All these things being consider'd, it seems probable to me, that God in +the Beginning form'd Matter in solid, massy, hard, impenetrable, +moveable Particles, of such Sizes and Figures, and with such other +Properties, and in such Proportion to Space, as most conduced to the End +for which he form'd them; and that these primitive Particles being +Solids, are incomparably harder than any porous Bodies compounded of +them; even so very hard, as never to wear or break in pieces; no +ordinary Power being able to divide what God himself made one in the +first Creation. While the Particles continue entire, they may compose +Bodies of one and the same Nature and Texture in all Ages: But should +they wear away, or break in pieces, the Nature of Things depending on +them, would be changed. Water and Earth, composed of old worn Particles +and Fragments of Particles, would not be of the same Nature and Texture +now, with Water and Earth composed of entire Particles in the Beginning. +And therefore, that Nature may be lasting, the Changes of corporeal +Things are to be placed only in the various Separations and new +Associations and Motions of these permanent Particles; compound Bodies +being apt to break, not in the midst of solid Particles, but where those +Particles are laid together, and only touch in a few Points. + +It seems to me farther, that these Particles have not only a _Vis +inertiæ_, accompanied with such passive Laws of Motion as naturally +result from that Force, but also that they are moved by certain active +Principles, such as is that of Gravity, and that which causes +Fermentation, and the Cohesion of Bodies. These Principles I consider, +not as occult Qualities, supposed to result from the specifick Forms of +Things, but as general Laws of Nature, by which the Things themselves +are form'd; their Truth appearing to us by Phænomena, though their +Causes be not yet discover'd. For these are manifest Qualities, and +their Causes only are occult. And the _Aristotelians_ gave the Name of +occult Qualities, not to manifest Qualities, but to such Qualities only +as they supposed to lie hid in Bodies, and to be the unknown Causes of +manifest Effects: Such as would be the Causes of Gravity, and of +magnetick and electrick Attractions, and of Fermentations, if we should +suppose that these Forces or Actions arose from Qualities unknown to us, +and uncapable of being discovered and made manifest. Such occult +Qualities put a stop to the Improvement of natural Philosophy, and +therefore of late Years have been rejected. To tell us that every +Species of Things is endow'd with an occult specifick Quality by which +it acts and produces manifest Effects, is to tell us nothing: But to +derive two or three general Principles of Motion from Phænomena, and +afterwards to tell us how the Properties and Actions of all corporeal +Things follow from those manifest Principles, would be a very great step +in Philosophy, though the Causes of those Principles were not yet +discover'd: And therefore I scruple not to propose the Principles of +Motion above-mention'd, they being of very general Extent, and leave +their Causes to be found out. + +Now by the help of these Principles, all material Things seem to have +been composed of the hard and solid Particles above-mention'd, variously +associated in the first Creation by the Counsel of an intelligent Agent. +For it became him who created them to set them in order. And if he did +so, it's unphilosophical to seek for any other Origin of the World, or +to pretend that it might arise out of a Chaos by the mere Laws of +Nature; though being once form'd, it may continue by those Laws for many +Ages. For while Comets move in very excentrick Orbs in all manner of +Positions, blind Fate could never make all the Planets move one and the +same way in Orbs concentrick, some inconsiderable Irregularities +excepted, which may have risen from the mutual Actions of Comets and +Planets upon one another, and which will be apt to increase, till this +System wants a Reformation. Such a wonderful Uniformity in the Planetary +System must be allowed the Effect of Choice. And so must the Uniformity +in the Bodies of Animals, they having generally a right and a left side +shaped alike, and on either side of their Bodies two Legs behind, and +either two Arms, or two Legs, or two Wings before upon their Shoulders, +and between their Shoulders a Neck running down into a Back-bone, and a +Head upon it; and in the Head two Ears, two Eyes, a Nose, a Mouth, and +a Tongue, alike situated. Also the first Contrivance of those very +artificial Parts of Animals, the Eyes, Ears, Brain, Muscles, Heart, +Lungs, Midriff, Glands, Larynx, Hands, Wings, swimming Bladders, natural +Spectacles, and other Organs of Sense and Motion; and the Instinct of +Brutes and Insects, can be the effect of nothing else than the Wisdom +and Skill of a powerful ever-living Agent, who being in all Places, is +more able by his Will to move the Bodies within his boundless uniform +Sensorium, and thereby to form and reform the Parts of the Universe, +than we are by our Will to move the Parts of our own Bodies. And yet we +are not to consider the World as the Body of God, or the several Parts +thereof, as the Parts of God. He is an uniform Being, void of Organs, +Members or Parts, and they are his Creatures subordinate to him, and +subservient to his Will; and he is no more the Soul of them, than the +Soul of Man is the Soul of the Species of Things carried through the +Organs of Sense into the place of its Sensation, where it perceives them +by means of its immediate Presence, without the Intervention of any +third thing. The Organs of Sense are not for enabling the Soul to +perceive the Species of Things in its Sensorium, but only for conveying +them thither; and God has no need of such Organs, he being every where +present to the Things themselves. And since Space is divisible _in +infinitum_, and Matter is not necessarily in all places, it may be also +allow'd that God is able to create Particles of Matter of several Sizes +and Figures, and in several Proportions to Space, and perhaps of +different Densities and Forces, and thereby to vary the Laws of Nature, +and make Worlds of several sorts in several Parts of the Universe. At +least, I see nothing of Contradiction in all this. + +As in Mathematicks, so in Natural Philosophy, the Investigation of +difficult Things by the Method of Analysis, ought ever to precede the +Method of Composition. This Analysis consists in making Experiments and +Observations, and in drawing general Conclusions from them by Induction, +and admitting of no Objections against the Conclusions, but such as are +taken from Experiments, or other certain Truths. For Hypotheses are not +to be regarded in experimental Philosophy. And although the arguing from +Experiments and Observations by Induction be no Demonstration of general +Conclusions; yet it is the best way of arguing which the Nature of +Things admits of, and may be looked upon as so much the stronger, by how +much the Induction is more general. And if no Exception occur from +Phænomena, the Conclusion may be pronounced generally. But if at any +time afterwards any Exception shall occur from Experiments, it may then +begin to be pronounced with such Exceptions as occur. By this way of +Analysis we may proceed from Compounds to Ingredients, and from Motions +to the Forces producing them; and in general, from Effects to their +Causes, and from particular Causes to more general ones, till the +Argument end in the most general. This is the Method of Analysis: And +the Synthesis consists in assuming the Causes discover'd, and +establish'd as Principles, and by them explaining the Phænomena +proceeding from them, and proving the Explanations. + +In the two first Books of these Opticks, I proceeded by this Analysis to +discover and prove the original Differences of the Rays of Light in +respect of Refrangibility, Reflexibility, and Colour, and their +alternate Fits of easy Reflexion and easy Transmission, and the +Properties of Bodies, both opake and pellucid, on which their Reflexions +and Colours depend. And these Discoveries being proved, may be assumed +in the Method of Composition for explaining the Phænomena arising from +them: An Instance of which Method I gave in the End of the first Book. +In this third Book I have only begun the Analysis of what remains to be +discover'd about Light and its Effects upon the Frame of Nature, hinting +several things about it, and leaving the Hints to be examin'd and +improv'd by the farther Experiments and Observations of such as are +inquisitive. And if natural Philosophy in all its Parts, by pursuing +this Method, shall at length be perfected, the Bounds of Moral +Philosophy will be also enlarged. For so far as we can know by natural +Philosophy what is the first Cause, what Power he has over us, and what +Benefits we receive from him, so far our Duty towards him, as well as +that towards one another, will appear to us by the Light of Nature. And +no doubt, if the Worship of false Gods had not blinded the Heathen, +their moral Philosophy would have gone farther than to the four +Cardinal Virtues; and instead of teaching the Transmigration of Souls, +and to worship the Sun and Moon, and dead Heroes, they would have taught +us to worship our true Author and Benefactor, as their Ancestors did +under the Government of _Noah_ and his Sons before they corrupted +themselves. \ No newline at end of file From f493e557232e223e313b4641d12e502c69bfe632 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 24 Sep 2018 12:26:58 -0700 Subject: [PATCH 0435/1663] cmd/compile: document regalloc fields Document what the fields of regalloc mean. Hopefully will help people understand how the register allocator works. Change-Id: Ic322ed2019cc839b812740afe8cd2cf0b61da046 Reviewed-on: https://go-review.googlesource.com/137016 Reviewed-by: Brad Fitzpatrick --- src/cmd/compile/internal/ssa/gen/main.go | 9 +++++++-- src/cmd/compile/internal/ssa/op.go | 12 ++++++++++-- src/cmd/compile/internal/ssa/regalloc.go | 2 ++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/main.go b/src/cmd/compile/internal/ssa/gen/main.go index f35a991db2521..f7195bf536305 100644 --- a/src/cmd/compile/internal/ssa/gen/main.go +++ b/src/cmd/compile/internal/ssa/gen/main.go @@ -63,9 +63,14 @@ type blockData struct { } type regInfo struct { - inputs []regMask + // inputs[i] encodes the set of registers allowed for the i'th input. + // Inputs that don't use registers (flags, memory, etc.) should be 0. + inputs []regMask + // clobbers encodes the set of registers that are overwritten by + // the instruction (other than the output registers). clobbers regMask - outputs []regMask + // outpus[i] encodes the set of registers allowed for the i'th output. + outputs []regMask } type regMask uint64 diff --git a/src/cmd/compile/internal/ssa/op.go b/src/cmd/compile/internal/ssa/op.go index 610921808e723..43f5c59591a00 100644 --- a/src/cmd/compile/internal/ssa/op.go +++ b/src/cmd/compile/internal/ssa/op.go @@ -50,9 +50,17 @@ type outputInfo struct { } type regInfo struct { - inputs []inputInfo // ordered in register allocation order + // inputs encodes the register restrictions for an instruction's inputs. + // Each entry specifies an allowed register set for a particular input. + // They are listed in the order in which regalloc should pick a register + // from the register set (most constrained first). + // Inputs which do not need registers are not listed. + inputs []inputInfo + // clobbers encodes the set of registers that are overwritten by + // the instruction (other than the output registers). clobbers regMask - outputs []outputInfo // ordered in register allocation order + // outputs is the same as inputs, but for the outputs of the instruction. + outputs []outputInfo } type auxType int8 diff --git a/src/cmd/compile/internal/ssa/regalloc.go b/src/cmd/compile/internal/ssa/regalloc.go index 278da6fe99fd3..8946cf6b5c083 100644 --- a/src/cmd/compile/internal/ssa/regalloc.go +++ b/src/cmd/compile/internal/ssa/regalloc.go @@ -150,6 +150,8 @@ type register uint8 const noRegister register = 255 +// A regMask encodes a set of machine registers. +// TODO: regMask -> regSet? type regMask uint64 func (m regMask) String() string { From 01b7c2db156cc40e928bb95ec7f980f0ab22aa26 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 24 Sep 2018 19:12:54 +0000 Subject: [PATCH 0436/1663] cmd/vendor: update golang.org/x/sys/windows for windows/arm support Updates to golang.org/x/sys git rev 90868a75f. Updates golang/go#26148 Change-Id: Ic687e7e0e171690e8d937c7bb29b0e55316f874a Reviewed-on: https://go-review.googlesource.com/137015 Reviewed-by: Ian Lance Taylor --- .../golang.org/x/sys/windows/aliases.go | 13 ++ .../x/sys/windows/asm_windows_arm.s | 11 ++ .../sys/windows/registry/zsyscall_windows.go | 2 +- .../x/sys/windows/security_windows.go | 4 +- .../golang.org/x/sys/windows/service.go | 18 ++ .../x/sys/windows/svc/mgr/config.go | 38 ++-- .../x/sys/windows/svc/mgr/mgr_test.go | 113 +++++++++++ .../x/sys/windows/svc/mgr/recovery.go | 135 +++++++++++++ .../golang.org/x/sys/windows/svc/sys_arm.s | 38 ++++ .../x/sys/windows/syscall_windows.go | 60 +++++- .../x/sys/windows/syscall_windows_test.go | 6 + .../golang.org/x/sys/windows/types_windows.go | 180 +++++++++++++++--- .../x/sys/windows/types_windows_arm.go | 22 +++ .../x/sys/windows/zsyscall_windows.go | 2 +- src/cmd/vendor/vendor.json | 32 ++-- 15 files changed, 613 insertions(+), 61 deletions(-) create mode 100644 src/cmd/vendor/golang.org/x/sys/windows/aliases.go create mode 100644 src/cmd/vendor/golang.org/x/sys/windows/asm_windows_arm.s create mode 100644 src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/recovery.go create mode 100644 src/cmd/vendor/golang.org/x/sys/windows/svc/sys_arm.s create mode 100644 src/cmd/vendor/golang.org/x/sys/windows/types_windows_arm.go diff --git a/src/cmd/vendor/golang.org/x/sys/windows/aliases.go b/src/cmd/vendor/golang.org/x/sys/windows/aliases.go new file mode 100644 index 0000000000000..af3af60db9707 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/sys/windows/aliases.go @@ -0,0 +1,13 @@ +// Copyright 2018 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. + +// +build windows +// +build go1.9 + +package windows + +import "syscall" + +type Errno = syscall.Errno +type SysProcAttr = syscall.SysProcAttr diff --git a/src/cmd/vendor/golang.org/x/sys/windows/asm_windows_arm.s b/src/cmd/vendor/golang.org/x/sys/windows/asm_windows_arm.s new file mode 100644 index 0000000000000..55d8b91a28680 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/sys/windows/asm_windows_arm.s @@ -0,0 +1,11 @@ +// Copyright 2018 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 "textflag.h" + +TEXT ·getprocaddress(SB),NOSPLIT,$0 + B syscall·getprocaddress(SB) + +TEXT ·loadlibrary(SB),NOSPLIT,$0 + B syscall·loadlibrary(SB) diff --git a/src/cmd/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go b/src/cmd/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go index ceebdd7726d0d..3778075da0f54 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/registry/zsyscall_windows.go @@ -1,4 +1,4 @@ -// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT +// Code generated by 'go generate'; DO NOT EDIT. package registry diff --git a/src/cmd/vendor/golang.org/x/sys/windows/security_windows.go b/src/cmd/vendor/golang.org/x/sys/windows/security_windows.go index f1ec5dc4ee798..4f17a3331fd04 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/security_windows.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/security_windows.go @@ -296,6 +296,7 @@ const ( TOKEN_ADJUST_PRIVILEGES TOKEN_ADJUST_GROUPS TOKEN_ADJUST_DEFAULT + TOKEN_ADJUST_SESSIONID TOKEN_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY | @@ -305,7 +306,8 @@ const ( TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | - TOKEN_ADJUST_DEFAULT + TOKEN_ADJUST_DEFAULT | + TOKEN_ADJUST_SESSIONID TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY TOKEN_WRITE = STANDARD_RIGHTS_WRITE | TOKEN_ADJUST_PRIVILEGES | diff --git a/src/cmd/vendor/golang.org/x/sys/windows/service.go b/src/cmd/vendor/golang.org/x/sys/windows/service.go index 24aa90bbbe1dd..62fc31b40bd92 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/service.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/service.go @@ -43,6 +43,11 @@ const ( SC_STATUS_PROCESS_INFO = 0 + SC_ACTION_NONE = 0 + SC_ACTION_RESTART = 1 + SC_ACTION_REBOOT = 2 + SC_ACTION_RUN_COMMAND = 3 + SERVICE_STOPPED = 1 SERVICE_START_PENDING = 2 SERVICE_STOP_PENDING = 3 @@ -148,6 +153,19 @@ type ENUM_SERVICE_STATUS_PROCESS struct { ServiceStatusProcess SERVICE_STATUS_PROCESS } +type SERVICE_FAILURE_ACTIONS struct { + ResetPeriod uint32 + RebootMsg *uint16 + Command *uint16 + ActionsCount uint32 + Actions *SC_ACTION +} + +type SC_ACTION struct { + Type uint32 + Delay uint32 +} + //sys CloseServiceHandle(handle Handle) (err error) = advapi32.CloseServiceHandle //sys CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access uint32, srvType uint32, startType uint32, errCtl uint32, pathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (handle Handle, err error) [failretval==0] = advapi32.CreateServiceW //sys OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenServiceW diff --git a/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/config.go b/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/config.go index 03bf41f51629a..d804e31f1f3e7 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/config.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/config.go @@ -88,23 +88,11 @@ func (s *Service) Config() (Config, error) { } } - var p2 *windows.SERVICE_DESCRIPTION - n = uint32(1024) - for { - b := make([]byte, n) - p2 = (*windows.SERVICE_DESCRIPTION)(unsafe.Pointer(&b[0])) - err := windows.QueryServiceConfig2(s.Handle, - windows.SERVICE_CONFIG_DESCRIPTION, &b[0], n, &n) - if err == nil { - break - } - if err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER { - return Config{}, err - } - if n <= uint32(len(b)) { - return Config{}, err - } + b, err := s.queryServiceConfig2(windows.SERVICE_CONFIG_DESCRIPTION) + if err != nil { + return Config{}, err } + p2 := (*windows.SERVICE_DESCRIPTION)(unsafe.Pointer(&b[0])) return Config{ ServiceType: p.ServiceType, @@ -137,3 +125,21 @@ func (s *Service) UpdateConfig(c Config) error { } return updateDescription(s.Handle, c.Description) } + +// queryServiceConfig2 calls Windows QueryServiceConfig2 with infoLevel parameter and returns retrieved service configuration information. +func (s *Service) queryServiceConfig2(infoLevel uint32) ([]byte, error) { + n := uint32(1024) + for { + b := make([]byte, n) + err := windows.QueryServiceConfig2(s.Handle, infoLevel, &b[0], n, &n) + if err == nil { + return b, nil + } + if err.(syscall.Errno) != syscall.ERROR_INSUFFICIENT_BUFFER { + return nil, err + } + if n <= uint32(len(b)) { + return nil, err + } + } +} diff --git a/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go b/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go index 1569a22177eba..9171f5bcf1414 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/mgr_test.go @@ -95,6 +95,113 @@ func testConfig(t *testing.T, s *mgr.Service, should mgr.Config) mgr.Config { return is } +func testRecoveryActions(t *testing.T, s *mgr.Service, should []mgr.RecoveryAction) { + is, err := s.RecoveryActions() + if err != nil { + t.Fatalf("RecoveryActions failed: %s", err) + } + if len(should) != len(is) { + t.Errorf("recovery action mismatch: contains %v actions, but should have %v", len(is), len(should)) + } + for i, _ := range is { + if should[i].Type != is[i].Type { + t.Errorf("recovery action mismatch: Type is %v, but should have %v", is[i].Type, should[i].Type) + } + if should[i].Delay != is[i].Delay { + t.Errorf("recovery action mismatch: Delay is %v, but should have %v", is[i].Delay, should[i].Delay) + } + } +} + +func testResetPeriod(t *testing.T, s *mgr.Service, should uint32) { + is, err := s.ResetPeriod() + if err != nil { + t.Fatalf("ResetPeriod failed: %s", err) + } + if should != is { + t.Errorf("reset period mismatch: reset period is %v, but should have %v", is, should) + } +} + +func testSetRecoveryActions(t *testing.T, s *mgr.Service) { + r := []mgr.RecoveryAction{ + mgr.RecoveryAction{ + Type: mgr.NoAction, + Delay: 60000 * time.Millisecond, + }, + mgr.RecoveryAction{ + Type: mgr.ServiceRestart, + Delay: 4 * time.Minute, + }, + mgr.RecoveryAction{ + Type: mgr.ServiceRestart, + Delay: time.Minute, + }, + mgr.RecoveryAction{ + Type: mgr.RunCommand, + Delay: 4000 * time.Millisecond, + }, + } + + // 4 recovery actions with reset period + err := s.SetRecoveryActions(r, uint32(10000)) + if err != nil { + t.Fatalf("SetRecoveryActions failed: %v", err) + } + testRecoveryActions(t, s, r) + testResetPeriod(t, s, uint32(10000)) + + // Infinite reset period + err = s.SetRecoveryActions(r, syscall.INFINITE) + if err != nil { + t.Fatalf("SetRecoveryActions failed: %v", err) + } + testRecoveryActions(t, s, r) + testResetPeriod(t, s, syscall.INFINITE) + + // nil recovery actions + err = s.SetRecoveryActions(nil, 0) + if err.Error() != "recoveryActions cannot be nil" { + t.Fatalf("SetRecoveryActions failed with unexpected error message of %q", err) + } + + // Delete all recovery actions and reset period + err = s.ResetRecoveryActions() + if err != nil { + t.Fatalf("ResetRecoveryActions failed: %v", err) + } + testRecoveryActions(t, s, nil) + testResetPeriod(t, s, 0) +} + +func testRebootMessage(t *testing.T, s *mgr.Service, should string) { + err := s.SetRebootMessage(should) + if err != nil { + t.Fatalf("SetRebootMessage failed: %v", err) + } + is, err := s.RebootMessage() + if err != nil { + t.Fatalf("RebootMessage failed: %v", err) + } + if should != is { + t.Errorf("reboot message mismatch: message is %q, but should have %q", is, should) + } +} + +func testRecoveryCommand(t *testing.T, s *mgr.Service, should string) { + err := s.SetRecoveryCommand(should) + if err != nil { + t.Fatalf("SetRecoveryCommand failed: %v", err) + } + is, err := s.RecoveryCommand() + if err != nil { + t.Fatalf("RecoveryCommand failed: %v", err) + } + if should != is { + t.Errorf("recovery command mismatch: command is %q, but should have %q", is, should) + } +} + func remove(t *testing.T, s *mgr.Service) { err := s.Delete() if err != nil { @@ -165,5 +272,11 @@ func TestMyService(t *testing.T) { t.Errorf("ListServices failed to find %q service", name) } + testSetRecoveryActions(t, s) + testRebootMessage(t, s, "myservice failed") + testRebootMessage(t, s, "") // delete reboot message + testRecoveryCommand(t, s, "sc query myservice") + testRecoveryCommand(t, s, "") // delete recovery command + remove(t, s) } diff --git a/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/recovery.go b/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/recovery.go new file mode 100644 index 0000000000000..71ce2b8199fa6 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/sys/windows/svc/mgr/recovery.go @@ -0,0 +1,135 @@ +// Copyright 2018 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. + +// +build windows + +package mgr + +import ( + "errors" + "syscall" + "time" + "unsafe" + + "golang.org/x/sys/windows" +) + +const ( + // Possible recovery actions that the service control manager can perform. + NoAction = windows.SC_ACTION_NONE // no action + ComputerReboot = windows.SC_ACTION_REBOOT // reboot the computer + ServiceRestart = windows.SC_ACTION_RESTART // restart the service + RunCommand = windows.SC_ACTION_RUN_COMMAND // run a command +) + +// RecoveryAction represents an action that the service control manager can perform when service fails. +// A service is considered failed when it terminates without reporting a status of SERVICE_STOPPED to the service controller. +type RecoveryAction struct { + Type int // one of NoAction, ComputerReboot, ServiceRestart or RunCommand + Delay time.Duration // the time to wait before performing the specified action +} + +// SetRecoveryActions sets actions that service controller performs when service fails and +// the time after which to reset the service failure count to zero if there are no failures, in seconds. +// Specify INFINITE to indicate that service failure count should never be reset. +func (s *Service) SetRecoveryActions(recoveryActions []RecoveryAction, resetPeriod uint32) error { + if recoveryActions == nil { + return errors.New("recoveryActions cannot be nil") + } + actions := []windows.SC_ACTION{} + for _, a := range recoveryActions { + action := windows.SC_ACTION{ + Type: uint32(a.Type), + Delay: uint32(a.Delay.Nanoseconds() / 1000000), + } + actions = append(actions, action) + } + rActions := windows.SERVICE_FAILURE_ACTIONS{ + ActionsCount: uint32(len(actions)), + Actions: &actions[0], + ResetPeriod: resetPeriod, + } + return windows.ChangeServiceConfig2(s.Handle, windows.SERVICE_CONFIG_FAILURE_ACTIONS, (*byte)(unsafe.Pointer(&rActions))) +} + +// RecoveryActions returns actions that service controller performs when service fails. +// The service control manager counts the number of times service s has failed since the system booted. +// The count is reset to 0 if the service has not failed for ResetPeriod seconds. +// When the service fails for the Nth time, the service controller performs the action specified in element [N-1] of returned slice. +// If N is greater than slice length, the service controller repeats the last action in the slice. +func (s *Service) RecoveryActions() ([]RecoveryAction, error) { + b, err := s.queryServiceConfig2(windows.SERVICE_CONFIG_FAILURE_ACTIONS) + if err != nil { + return nil, err + } + p := (*windows.SERVICE_FAILURE_ACTIONS)(unsafe.Pointer(&b[0])) + if p.Actions == nil { + return nil, err + } + + var recoveryActions []RecoveryAction + actions := (*[1024]windows.SC_ACTION)(unsafe.Pointer(p.Actions))[:p.ActionsCount] + for _, action := range actions { + recoveryActions = append(recoveryActions, RecoveryAction{Type: int(action.Type), Delay: time.Duration(action.Delay) * time.Millisecond}) + } + return recoveryActions, nil +} + +// ResetRecoveryActions deletes both reset period and array of failure actions. +func (s *Service) ResetRecoveryActions() error { + actions := make([]windows.SC_ACTION, 1) + rActions := windows.SERVICE_FAILURE_ACTIONS{ + Actions: &actions[0], + } + return windows.ChangeServiceConfig2(s.Handle, windows.SERVICE_CONFIG_FAILURE_ACTIONS, (*byte)(unsafe.Pointer(&rActions))) +} + +// ResetPeriod is the time after which to reset the service failure +// count to zero if there are no failures, in seconds. +func (s *Service) ResetPeriod() (uint32, error) { + b, err := s.queryServiceConfig2(windows.SERVICE_CONFIG_FAILURE_ACTIONS) + if err != nil { + return 0, err + } + p := (*windows.SERVICE_FAILURE_ACTIONS)(unsafe.Pointer(&b[0])) + return p.ResetPeriod, nil +} + +// SetRebootMessage sets service s reboot message. +// If msg is "", the reboot message is deleted and no message is broadcast. +func (s *Service) SetRebootMessage(msg string) error { + rActions := windows.SERVICE_FAILURE_ACTIONS{ + RebootMsg: syscall.StringToUTF16Ptr(msg), + } + return windows.ChangeServiceConfig2(s.Handle, windows.SERVICE_CONFIG_FAILURE_ACTIONS, (*byte)(unsafe.Pointer(&rActions))) +} + +// RebootMessage is broadcast to server users before rebooting in response to the ComputerReboot service controller action. +func (s *Service) RebootMessage() (string, error) { + b, err := s.queryServiceConfig2(windows.SERVICE_CONFIG_FAILURE_ACTIONS) + if err != nil { + return "", err + } + p := (*windows.SERVICE_FAILURE_ACTIONS)(unsafe.Pointer(&b[0])) + return toString(p.RebootMsg), nil +} + +// SetRecoveryCommand sets the command line of the process to execute in response to the RunCommand service controller action. +// If cmd is "", the command is deleted and no program is run when the service fails. +func (s *Service) SetRecoveryCommand(cmd string) error { + rActions := windows.SERVICE_FAILURE_ACTIONS{ + Command: syscall.StringToUTF16Ptr(cmd), + } + return windows.ChangeServiceConfig2(s.Handle, windows.SERVICE_CONFIG_FAILURE_ACTIONS, (*byte)(unsafe.Pointer(&rActions))) +} + +// RecoveryCommand is the command line of the process to execute in response to the RunCommand service controller action. This process runs under the same account as the service. +func (s *Service) RecoveryCommand() (string, error) { + b, err := s.queryServiceConfig2(windows.SERVICE_CONFIG_FAILURE_ACTIONS) + if err != nil { + return "", err + } + p := (*windows.SERVICE_FAILURE_ACTIONS)(unsafe.Pointer(&b[0])) + return toString(p.Command), nil +} diff --git a/src/cmd/vendor/golang.org/x/sys/windows/svc/sys_arm.s b/src/cmd/vendor/golang.org/x/sys/windows/svc/sys_arm.s new file mode 100644 index 0000000000000..33c692a8dea4b --- /dev/null +++ b/src/cmd/vendor/golang.org/x/sys/windows/svc/sys_arm.s @@ -0,0 +1,38 @@ +// Copyright 2018 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. + +// +build windows + +#include "textflag.h" + +// func servicemain(argc uint32, argv **uint16) +TEXT ·servicemain(SB),NOSPLIT|NOFRAME,$0 + MOVM.DB.W [R4, R14], (R13) // push {r4, lr} + MOVW R13, R4 + BIC $0x7, R13 // alignment for ABI + + MOVW R0, ·sArgc(SB) + MOVW R1, ·sArgv(SB) + + MOVW ·sName(SB), R0 + MOVW ·ctlHandlerExProc(SB), R1 + MOVW $0, R2 + MOVW ·cRegisterServiceCtrlHandlerExW(SB), R3 + BL (R3) + CMP $0, R0 + BEQ exit + MOVW R0, ·ssHandle(SB) + + MOVW ·goWaitsH(SB), R0 + MOVW ·cSetEvent(SB), R1 + BL (R1) + + MOVW ·cWaitsH(SB), R0 + MOVW $-1, R1 + MOVW ·cWaitForSingleObject(SB), R2 + BL (R2) + +exit: + MOVW R4, R13 // free extra stack space + MOVM.IA.W (R13), [R4, R15] // pop {r4, pc} diff --git a/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows.go b/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows.go index 1e9f4bb4a3762..8a00b71f1d1ad 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows.go @@ -112,12 +112,14 @@ func Getpagesize() int { return 4096 } // NewCallback converts a Go function to a function pointer conforming to the stdcall calling convention. // This is useful when interoperating with Windows code requiring callbacks. +// The argument is expected to be a function with with one uintptr-sized result. The function must not have arguments with size larger than the size of uintptr. func NewCallback(fn interface{}) uintptr { return syscall.NewCallback(fn) } // NewCallbackCDecl converts a Go function to a function pointer conforming to the cdecl calling convention. // This is useful when interoperating with Windows code requiring callbacks. +// The argument is expected to be a function with with one uintptr-sized result. The function must not have arguments with size larger than the size of uintptr. func NewCallbackCDecl(fn interface{}) uintptr { return syscall.NewCallbackCDecl(fn) } @@ -653,7 +655,7 @@ type RawSockaddr struct { type RawSockaddrAny struct { Addr RawSockaddr - Pad [96]int8 + Pad [100]int8 } type Sockaddr interface { @@ -702,19 +704,69 @@ func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, int32, error) { return unsafe.Pointer(&sa.raw), int32(unsafe.Sizeof(sa.raw)), nil } +type RawSockaddrUnix struct { + Family uint16 + Path [UNIX_PATH_MAX]int8 +} + type SockaddrUnix struct { Name string + raw RawSockaddrUnix } func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, int32, error) { - // TODO(brainman): implement SockaddrUnix.sockaddr() - return nil, 0, syscall.EWINDOWS + name := sa.Name + n := len(name) + if n > len(sa.raw.Path) { + return nil, 0, syscall.EINVAL + } + if n == len(sa.raw.Path) && name[0] != '@' { + return nil, 0, syscall.EINVAL + } + sa.raw.Family = AF_UNIX + for i := 0; i < n; i++ { + sa.raw.Path[i] = int8(name[i]) + } + // length is family (uint16), name, NUL. + sl := int32(2) + if n > 0 { + sl += int32(n) + 1 + } + if sa.raw.Path[0] == '@' { + sa.raw.Path[0] = 0 + // Don't count trailing NUL for abstract address. + sl-- + } + + return unsafe.Pointer(&sa.raw), sl, nil } func (rsa *RawSockaddrAny) Sockaddr() (Sockaddr, error) { switch rsa.Addr.Family { case AF_UNIX: - return nil, syscall.EWINDOWS + pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa)) + sa := new(SockaddrUnix) + if pp.Path[0] == 0 { + // "Abstract" Unix domain socket. + // Rewrite leading NUL as @ for textual display. + // (This is the standard convention.) + // Not friendly to overwrite in place, + // but the callers below don't care. + pp.Path[0] = '@' + } + + // Assume path ends at NUL. + // This is not technically the Linux semantics for + // abstract Unix domain sockets--they are supposed + // to be uninterpreted fixed-size binary blobs--but + // everyone uses this convention. + n := 0 + for n < len(pp.Path) && pp.Path[n] != 0 { + n++ + } + bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n] + sa.Name = string(bytes) + return sa, nil case AF_INET: pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa)) diff --git a/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows_test.go b/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows_test.go index 9c7133cc41137..0e27464e8c4c1 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows_test.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/syscall_windows_test.go @@ -105,3 +105,9 @@ func ExampleLoadLibrary() { build := uint16(r >> 16) print("windows version ", major, ".", minor, " (Build ", build, ")\n") } + +func TestTOKEN_ALL_ACCESS(t *testing.T) { + if windows.TOKEN_ALL_ACCESS != 0xF01FF { + t.Errorf("TOKEN_ALL_ACCESS = %x, want 0xF01FF", windows.TOKEN_ALL_ACCESS) + } +} diff --git a/src/cmd/vendor/golang.org/x/sys/windows/types_windows.go b/src/cmd/vendor/golang.org/x/sys/windows/types_windows.go index 52c2037b68edb..141ca81bd74d9 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/types_windows.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/types_windows.go @@ -94,16 +94,29 @@ const ( FILE_APPEND_DATA = 0x00000004 FILE_WRITE_ATTRIBUTES = 0x00000100 - FILE_SHARE_READ = 0x00000001 - FILE_SHARE_WRITE = 0x00000002 - FILE_SHARE_DELETE = 0x00000004 - FILE_ATTRIBUTE_READONLY = 0x00000001 - FILE_ATTRIBUTE_HIDDEN = 0x00000002 - FILE_ATTRIBUTE_SYSTEM = 0x00000004 - FILE_ATTRIBUTE_DIRECTORY = 0x00000010 - FILE_ATTRIBUTE_ARCHIVE = 0x00000020 - FILE_ATTRIBUTE_NORMAL = 0x00000080 - FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400 + FILE_SHARE_READ = 0x00000001 + FILE_SHARE_WRITE = 0x00000002 + FILE_SHARE_DELETE = 0x00000004 + + FILE_ATTRIBUTE_READONLY = 0x00000001 + FILE_ATTRIBUTE_HIDDEN = 0x00000002 + FILE_ATTRIBUTE_SYSTEM = 0x00000004 + FILE_ATTRIBUTE_DIRECTORY = 0x00000010 + FILE_ATTRIBUTE_ARCHIVE = 0x00000020 + FILE_ATTRIBUTE_DEVICE = 0x00000040 + FILE_ATTRIBUTE_NORMAL = 0x00000080 + FILE_ATTRIBUTE_TEMPORARY = 0x00000100 + FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200 + FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400 + FILE_ATTRIBUTE_COMPRESSED = 0x00000800 + FILE_ATTRIBUTE_OFFLINE = 0x00001000 + FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000 + FILE_ATTRIBUTE_ENCRYPTED = 0x00004000 + FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x00008000 + FILE_ATTRIBUTE_VIRTUAL = 0x00010000 + FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x00020000 + FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x00040000 + FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x00400000 INVALID_FILE_ATTRIBUTES = 0xffffffff @@ -257,15 +270,87 @@ const ( USAGE_MATCH_TYPE_AND = 0 USAGE_MATCH_TYPE_OR = 1 + /* msgAndCertEncodingType values for CertOpenStore function */ X509_ASN_ENCODING = 0x00000001 PKCS_7_ASN_ENCODING = 0x00010000 - CERT_STORE_PROV_MEMORY = 2 - - CERT_STORE_ADD_ALWAYS = 4 - + /* storeProvider values for CertOpenStore function */ + CERT_STORE_PROV_MSG = 1 + CERT_STORE_PROV_MEMORY = 2 + CERT_STORE_PROV_FILE = 3 + CERT_STORE_PROV_REG = 4 + CERT_STORE_PROV_PKCS7 = 5 + CERT_STORE_PROV_SERIALIZED = 6 + CERT_STORE_PROV_FILENAME_A = 7 + CERT_STORE_PROV_FILENAME_W = 8 + CERT_STORE_PROV_FILENAME = CERT_STORE_PROV_FILENAME_W + CERT_STORE_PROV_SYSTEM_A = 9 + CERT_STORE_PROV_SYSTEM_W = 10 + CERT_STORE_PROV_SYSTEM = CERT_STORE_PROV_SYSTEM_W + CERT_STORE_PROV_COLLECTION = 11 + CERT_STORE_PROV_SYSTEM_REGISTRY_A = 12 + CERT_STORE_PROV_SYSTEM_REGISTRY_W = 13 + CERT_STORE_PROV_SYSTEM_REGISTRY = CERT_STORE_PROV_SYSTEM_REGISTRY_W + CERT_STORE_PROV_PHYSICAL_W = 14 + CERT_STORE_PROV_PHYSICAL = CERT_STORE_PROV_PHYSICAL_W + CERT_STORE_PROV_SMART_CARD_W = 15 + CERT_STORE_PROV_SMART_CARD = CERT_STORE_PROV_SMART_CARD_W + CERT_STORE_PROV_LDAP_W = 16 + CERT_STORE_PROV_LDAP = CERT_STORE_PROV_LDAP_W + CERT_STORE_PROV_PKCS12 = 17 + + /* store characteristics (low WORD of flag) for CertOpenStore function */ + CERT_STORE_NO_CRYPT_RELEASE_FLAG = 0x00000001 + CERT_STORE_SET_LOCALIZED_NAME_FLAG = 0x00000002 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG = 0x00000004 - + CERT_STORE_DELETE_FLAG = 0x00000010 + CERT_STORE_UNSAFE_PHYSICAL_FLAG = 0x00000020 + CERT_STORE_SHARE_STORE_FLAG = 0x00000040 + CERT_STORE_SHARE_CONTEXT_FLAG = 0x00000080 + CERT_STORE_MANIFOLD_FLAG = 0x00000100 + CERT_STORE_ENUM_ARCHIVED_FLAG = 0x00000200 + CERT_STORE_UPDATE_KEYID_FLAG = 0x00000400 + CERT_STORE_BACKUP_RESTORE_FLAG = 0x00000800 + CERT_STORE_MAXIMUM_ALLOWED_FLAG = 0x00001000 + CERT_STORE_CREATE_NEW_FLAG = 0x00002000 + CERT_STORE_OPEN_EXISTING_FLAG = 0x00004000 + CERT_STORE_READONLY_FLAG = 0x00008000 + + /* store locations (high WORD of flag) for CertOpenStore function */ + CERT_SYSTEM_STORE_CURRENT_USER = 0x00010000 + CERT_SYSTEM_STORE_LOCAL_MACHINE = 0x00020000 + CERT_SYSTEM_STORE_CURRENT_SERVICE = 0x00040000 + CERT_SYSTEM_STORE_SERVICES = 0x00050000 + CERT_SYSTEM_STORE_USERS = 0x00060000 + CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY = 0x00070000 + CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY = 0x00080000 + CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE = 0x00090000 + CERT_SYSTEM_STORE_UNPROTECTED_FLAG = 0x40000000 + CERT_SYSTEM_STORE_RELOCATE_FLAG = 0x80000000 + + /* Miscellaneous high-WORD flags for CertOpenStore function */ + CERT_REGISTRY_STORE_REMOTE_FLAG = 0x00010000 + CERT_REGISTRY_STORE_SERIALIZED_FLAG = 0x00020000 + CERT_REGISTRY_STORE_ROAMING_FLAG = 0x00040000 + CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG = 0x00080000 + CERT_REGISTRY_STORE_LM_GPT_FLAG = 0x01000000 + CERT_REGISTRY_STORE_CLIENT_GPT_FLAG = 0x80000000 + CERT_FILE_STORE_COMMIT_ENABLE_FLAG = 0x00010000 + CERT_LDAP_STORE_SIGN_FLAG = 0x00010000 + CERT_LDAP_STORE_AREC_EXCLUSIVE_FLAG = 0x00020000 + CERT_LDAP_STORE_OPENED_FLAG = 0x00040000 + CERT_LDAP_STORE_UNBIND_FLAG = 0x00080000 + + /* addDisposition values for CertAddCertificateContextToStore function */ + CERT_STORE_ADD_NEW = 1 + CERT_STORE_ADD_USE_EXISTING = 2 + CERT_STORE_ADD_REPLACE_EXISTING = 3 + CERT_STORE_ADD_ALWAYS = 4 + CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES = 5 + CERT_STORE_ADD_NEWER = 6 + CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES = 7 + + /* ErrorStatus values for CertTrustStatus struct */ CERT_TRUST_NO_ERROR = 0x00000000 CERT_TRUST_IS_NOT_TIME_VALID = 0x00000001 CERT_TRUST_IS_REVOKED = 0x00000004 @@ -282,11 +367,31 @@ const ( CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT = 0x00002000 CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT = 0x00004000 CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT = 0x00008000 + CERT_TRUST_IS_PARTIAL_CHAIN = 0x00010000 + CERT_TRUST_CTL_IS_NOT_TIME_VALID = 0x00020000 + CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID = 0x00040000 + CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE = 0x00080000 + CERT_TRUST_HAS_WEAK_SIGNATURE = 0x00100000 CERT_TRUST_IS_OFFLINE_REVOCATION = 0x01000000 CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY = 0x02000000 CERT_TRUST_IS_EXPLICIT_DISTRUST = 0x04000000 CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT = 0x08000000 + /* InfoStatus values for CertTrustStatus struct */ + CERT_TRUST_HAS_EXACT_MATCH_ISSUER = 0x00000001 + CERT_TRUST_HAS_KEY_MATCH_ISSUER = 0x00000002 + CERT_TRUST_HAS_NAME_MATCH_ISSUER = 0x00000004 + CERT_TRUST_IS_SELF_SIGNED = 0x00000008 + CERT_TRUST_HAS_PREFERRED_ISSUER = 0x00000100 + CERT_TRUST_HAS_ISSUANCE_CHAIN_POLICY = 0x00000400 + CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS = 0x00000400 + CERT_TRUST_IS_PEER_TRUSTED = 0x00000800 + CERT_TRUST_HAS_CRL_VALIDITY_EXTENDED = 0x00001000 + CERT_TRUST_IS_FROM_EXCLUSIVE_TRUST_STORE = 0x00002000 + CERT_TRUST_IS_CA_TRUSTED = 0x00004000 + CERT_TRUST_IS_COMPLEX_CHAIN = 0x00010000 + + /* policyOID values for CertVerifyCertificateChainPolicy function */ CERT_CHAIN_POLICY_BASE = 1 CERT_CHAIN_POLICY_AUTHENTICODE = 2 CERT_CHAIN_POLICY_AUTHENTICODE_TS = 3 @@ -295,6 +400,7 @@ const ( CERT_CHAIN_POLICY_NT_AUTH = 6 CERT_CHAIN_POLICY_MICROSOFT_ROOT = 7 CERT_CHAIN_POLICY_EV = 8 + CERT_CHAIN_POLICY_SSL_F12 = 9 CERT_E_EXPIRED = 0x800B0101 CERT_E_ROLE = 0x800B0103 @@ -302,8 +408,16 @@ const ( CERT_E_UNTRUSTEDROOT = 0x800B0109 CERT_E_CN_NO_MATCH = 0x800B010F + /* AuthType values for SSLExtraCertChainPolicyPara struct */ AUTHTYPE_CLIENT = 1 AUTHTYPE_SERVER = 2 + + /* Checks values for SSLExtraCertChainPolicyPara struct */ + SECURITY_FLAG_IGNORE_REVOCATION = 0x00000080 + SECURITY_FLAG_IGNORE_UNKNOWN_CA = 0x00000100 + SECURITY_FLAG_IGNORE_WRONG_USAGE = 0x00000200 + SECURITY_FLAG_IGNORE_CERT_CN_INVALID = 0x00001000 + SECURITY_FLAG_IGNORE_CERT_DATE_INVALID = 0x00002000 ) var ( @@ -312,6 +426,14 @@ var ( OID_SGC_NETSCAPE = []byte("2.16.840.1.113730.4.1\x00") ) +// Pointer represents a pointer to an arbitrary Windows type. +// +// Pointer-typed fields may point to one of many different types. It's +// up to the caller to provide a pointer to the appropriate type, cast +// to Pointer. The caller must obey the unsafe.Pointer rules while +// doing so. +type Pointer *struct{} + // Invented values to support what package os expects. type Timeval struct { Sec int32 @@ -880,11 +1002,15 @@ type MibIfRow struct { Descr [MAXLEN_IFDESCR]byte } +type CertInfo struct { + // Not implemented +} + type CertContext struct { EncodingType uint32 EncodedCert *byte Length uint32 - CertInfo uintptr + CertInfo *CertInfo Store Handle } @@ -899,12 +1025,16 @@ type CertChainContext struct { RevocationFreshnessTime uint32 } +type CertTrustListInfo struct { + // Not implemented +} + type CertSimpleChain struct { Size uint32 TrustStatus CertTrustStatus NumElements uint32 Elements **CertChainElement - TrustListInfo uintptr + TrustListInfo *CertTrustListInfo HasRevocationFreshnessTime uint32 RevocationFreshnessTime uint32 } @@ -919,14 +1049,18 @@ type CertChainElement struct { ExtendedErrorInfo *uint16 } +type CertRevocationCrlInfo struct { + // Not implemented +} + type CertRevocationInfo struct { Size uint32 RevocationResult uint32 RevocationOid *byte - OidSpecificInfo uintptr + OidSpecificInfo Pointer HasFreshnessTime uint32 FreshnessTime uint32 - CrlInfo uintptr // *CertRevocationCrlInfo + CrlInfo *CertRevocationCrlInfo } type CertTrustStatus struct { @@ -957,7 +1091,7 @@ type CertChainPara struct { type CertChainPolicyPara struct { Size uint32 Flags uint32 - ExtraPolicyPara uintptr + ExtraPolicyPara Pointer } type SSLExtraCertChainPolicyPara struct { @@ -972,7 +1106,7 @@ type CertChainPolicyStatus struct { Error uint32 ChainIndex uint32 ElementIndex uint32 - ExtraPolicyStatus uintptr + ExtraPolicyStatus Pointer } const ( @@ -1319,7 +1453,7 @@ type SmallRect struct { Bottom int16 } -// Used with GetConsoleScreenBuffer to retreive information about a console +// Used with GetConsoleScreenBuffer to retrieve information about a console // screen buffer. See // https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str // for details. @@ -1331,3 +1465,5 @@ type ConsoleScreenBufferInfo struct { Window SmallRect MaximumWindowSize Coord } + +const UNIX_PATH_MAX = 108 // defined in afunix.h diff --git a/src/cmd/vendor/golang.org/x/sys/windows/types_windows_arm.go b/src/cmd/vendor/golang.org/x/sys/windows/types_windows_arm.go new file mode 100644 index 0000000000000..74571e3600b3b --- /dev/null +++ b/src/cmd/vendor/golang.org/x/sys/windows/types_windows_arm.go @@ -0,0 +1,22 @@ +// Copyright 2018 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. + +package windows + +type WSAData struct { + Version uint16 + HighVersion uint16 + Description [WSADESCRIPTION_LEN + 1]byte + SystemStatus [WSASYS_STATUS_LEN + 1]byte + MaxSockets uint16 + MaxUdpDg uint16 + VendorInfo *byte +} + +type Servent struct { + Name *byte + Aliases **byte + Port uint16 + Proto *byte +} diff --git a/src/cmd/vendor/golang.org/x/sys/windows/zsyscall_windows.go b/src/cmd/vendor/golang.org/x/sys/windows/zsyscall_windows.go index 318c61634e1d1..fc56aec035b08 100644 --- a/src/cmd/vendor/golang.org/x/sys/windows/zsyscall_windows.go +++ b/src/cmd/vendor/golang.org/x/sys/windows/zsyscall_windows.go @@ -1,4 +1,4 @@ -// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT +// Code generated by 'go generate'; DO NOT EDIT. package windows diff --git a/src/cmd/vendor/vendor.json b/src/cmd/vendor/vendor.json index 8009661879382..6e077e4ae17c5 100644 --- a/src/cmd/vendor/vendor.json +++ b/src/cmd/vendor/vendor.json @@ -131,40 +131,40 @@ "revisionTime": "2018-06-27T13:57:12Z" }, { - "checksumSHA1": "y0x0I9zDxnxn9nCxwP/MdPyq1E8=", + "checksumSHA1": "s+lofQ+SCdhmy0cQp9FpdQncuuI=", "path": "golang.org/x/sys/windows", - "revision": "c11f84a56e43e20a78cee75a7c034031ecf57d1f", - "revisionTime": "2018-05-25T13:55:20Z" + "revision": "90868a75fefd03942536221d7c0e2f84ec62a668", + "revisionTime": "2018-08-01T20:46:00Z" }, { - "checksumSHA1": "BnZkq/3Ejb7961bDhybRraW6jzI=", + "checksumSHA1": "yEg3f1MGwuyDh5NrNEGkWKlTyqY=", "path": "golang.org/x/sys/windows/registry", - "revision": "c11f84a56e43e20a78cee75a7c034031ecf57d1f", - "revisionTime": "2018-05-25T13:55:20Z" + "revision": "90868a75fefd03942536221d7c0e2f84ec62a668", + "revisionTime": "2018-08-01T20:46:00Z" }, { - "checksumSHA1": "dQbFeoiAxfB3WFFVcAdeSwSgeDk=", + "checksumSHA1": "ZDwqsuoZqQq/XMQ0R0dJ4oK41lU=", "path": "golang.org/x/sys/windows/svc", - "revision": "c11f84a56e43e20a78cee75a7c034031ecf57d1f", - "revisionTime": "2018-05-25T13:55:20Z" + "revision": "90868a75fefd03942536221d7c0e2f84ec62a668", + "revisionTime": "2018-08-01T20:46:00Z" }, { "checksumSHA1": "e9KJPWrdqg5PMkbE2w60Io8rY4M=", "path": "golang.org/x/sys/windows/svc/debug", - "revision": "c11f84a56e43e20a78cee75a7c034031ecf57d1f", - "revisionTime": "2018-05-25T13:55:20Z" + "revision": "90868a75fefd03942536221d7c0e2f84ec62a668", + "revisionTime": "2018-08-01T20:46:00Z" }, { "checksumSHA1": "dz53pQfqAnXG8HdJj+nazXN9YRw=", "path": "golang.org/x/sys/windows/svc/eventlog", - "revision": "c11f84a56e43e20a78cee75a7c034031ecf57d1f", - "revisionTime": "2018-05-25T13:55:20Z" + "revision": "90868a75fefd03942536221d7c0e2f84ec62a668", + "revisionTime": "2018-08-01T20:46:00Z" }, { - "checksumSHA1": "wz+0tf0Z7cVBaz/35P1m1cAiI7k=", + "checksumSHA1": "vV6Mr/b+1GaHiHLnq2zEejQJVec=", "path": "golang.org/x/sys/windows/svc/mgr", - "revision": "c11f84a56e43e20a78cee75a7c034031ecf57d1f", - "revisionTime": "2018-05-25T13:55:20Z" + "revision": "90868a75fefd03942536221d7c0e2f84ec62a668", + "revisionTime": "2018-08-01T20:46:00Z" } ], "rootPath": "/cmd" From b3369063e52571be1cdf0e7a16f99b12c2a23914 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 24 Sep 2018 16:48:54 +0000 Subject: [PATCH 0437/1663] test: skip some tests on noopt builder Adds a new build tag "gcflags_noopt" that can be used in test/*.go tests. Fixes #27833 Change-Id: I4ea0ccd9e9e58c4639de18645fec81eb24a3a929 Reviewed-on: https://go-review.googlesource.com/136898 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- test/checkbce.go | 2 +- test/fixedbugs/issue7921.go | 1 + test/nosplit.go | 2 +- test/run.go | 16 ++++++++++++---- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/test/checkbce.go b/test/checkbce.go index 770c4c2a94e71..ef4e584ca0923 100644 --- a/test/checkbce.go +++ b/test/checkbce.go @@ -1,4 +1,4 @@ -// +build amd64 +// +build amd64,!gcflags_noopt // errorcheck -0 -d=ssa/check_bce/debug=3 // Copyright 2016 The Go Authors. All rights reserved. diff --git a/test/fixedbugs/issue7921.go b/test/fixedbugs/issue7921.go index e30e556353b2e..ac2b494ebc684 100644 --- a/test/fixedbugs/issue7921.go +++ b/test/fixedbugs/issue7921.go @@ -1,3 +1,4 @@ +// +build !gcflags_noopt // errorcheck -0 -m // Copyright 2018 The Go Authors. All rights reserved. diff --git a/test/nosplit.go b/test/nosplit.go index b821d23859d53..1855c010ae3a1 100644 --- a/test/nosplit.go +++ b/test/nosplit.go @@ -1,4 +1,4 @@ -// +build !nacl,!js +// +build !nacl,!js,!gcflags_noopt // run // Copyright 2014 The Go Authors. All rights reserved. diff --git a/test/run.go b/test/run.go index 24a4d4f425fe1..d0dccb4f23d19 100644 --- a/test/run.go +++ b/test/run.go @@ -354,8 +354,9 @@ func goDirPackages(longdir string, singlefilepkgs bool) ([][]string, error) { } type context struct { - GOOS string - GOARCH string + GOOS string + GOARCH string + noOptEnv bool } // shouldTest looks for build tags in a source file and returns @@ -375,10 +376,13 @@ func shouldTest(src string, goos, goarch string) (ok bool, whyNot string) { if len(line) == 0 || line[0] != '+' { continue } + gcFlags := os.Getenv("GO_GCFLAGS") ctxt := &context{ - GOOS: goos, - GOARCH: goarch, + GOOS: goos, + GOARCH: goarch, + noOptEnv: strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"), } + words := strings.Fields(line) if words[0] == "+build" { ok := false @@ -425,6 +429,10 @@ func (ctxt *context) match(name string) bool { return true } + if ctxt.noOptEnv && name == "gcflags_noopt" { + return true + } + if name == "test_run" { return true } From c5a8d1d2f92678b3e17781dd1315f15e24da00f3 Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Fri, 21 Sep 2018 10:48:05 +1000 Subject: [PATCH 0438/1663] fmt: add a package-level example illustrating basic formats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is much left out here—the space of possibilities is very large—but this example shows all that most programmers will need to know for most printing problems. Update #27554. Change-Id: Ib6ae651d5c3720cf7fe1a05ffd0859a5b56a9157 Reviewed-on: https://go-review.googlesource.com/136616 Reviewed-by: Ian Lance Taylor --- src/fmt/example_test.go | 149 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index 0ec374d217213..bf9a6078f18c7 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -7,8 +7,10 @@ package fmt_test import ( "fmt" "io" + "math" "os" "strings" + "time" ) // The Errorf function lets us use formatting features @@ -131,3 +133,150 @@ func ExampleSprint() { // thereare99gophers // 17 } + +// These examples demonstrate the basics of printing using a format string. Printf, +// Sprintf, and Fprintf all take a format string that specifies how to format the +// subsequent arguments. For example, %d (we call that a 'verb') says to print the +// corresponding argument, which must be an integer (or something containing an +// integer, such as a slice of ints) in decimal. The verb %v ('v' for 'value') +// always formats the argument in its default form, just how Print or Println would +// show it. The special verb %T ('T' for 'Type') prints the type of the argument +// rather than its value. The examples are not exhaustive; see the package comment +// for all the details. +func Example_formats() { + // A basic set of examples showing that %v is the default format, in this + // case decimal for integers, which can be explicitly requested with %d; + // the output is just what Println generates. + integer := 23 + // Each of these prints "23" (without the quotes). + fmt.Println(integer) + fmt.Printf("%v\n", integer) + fmt.Printf("%d\n", integer) + + // The special verb %T shows the type of an item rather than its value. + fmt.Printf("%T %T\n", integer, &integer) + // Result: int *int + + // Println(x) is the same as Printf("%v\n", x) so we will use only Printf + // in the following examples. Each one demonstrates how to format values of + // a particular type, such as integers or strings. We start each format + // string with %v to show the default output and follow that with one or + // more custom formats. + + // Booleans print as "true" or "false" with %v or %t. + truth := true + fmt.Printf("%v %t\n", truth, truth) + // Result: true true + + // Integers print as decimals with %v and %d, + // or in hex with %x, octal with %o, or binary with %b. + answer := 42 + fmt.Printf("%v %d %x %o %b\n", answer, answer, answer, answer, answer) + // Result: 42 42 2a 52 101010 + + // Floats have multiple formats: %v and %g print a compact representation, + // while %f prints a decimal point and %e uses exponential notation. The + // format %6.2f used here shows how to set the width and precision to + // control the appearance of a floating-point value. In this instance, 6 is + // the total width of the printed text for the value (note the extra spaces + // in the output) and 2 is the number of decimal places to show. + pi := math.Pi + fmt.Printf("%v %g %.2f (%6.2f) %e\n", pi, pi, pi, pi, pi) + // Result: 3.141592653589793 3.141592653589793 3.14 ( 3.14) 3.141593e+00 + + // Complex numbers format as parenthesized pairs of floats, with an 'i' + // after the imaginary part. + point := 110.7 + 22.5i + fmt.Printf("%v %g %.2f %.2e\n", point, point, point, point) + // Result: (110.7+22.5i) (110.7+22.5i) (110.70+22.50i) (1.11e+02+2.25e+01i) + + // Runes are integers but when printed with %c show the character with that + // Unicode value. The %q verb shows them as quoted characters, %U as a + // hex Unicode code point, and %#U as both a code point and a quoted + // printable form if the rune is printable. + smile := '😀' + fmt.Printf("%v %d %c %q %U %#U\n", smile, smile, smile, smile, smile, smile) + // Result: 128512 128512 😀 '😀' U+1F600 U+1F600 '😀' + + // Strings are formatted with %v and %s as-is, with %q as quoted strings, + // and %#q as backquoted strings. + placeholders := `foo "bar"` + fmt.Printf("%v %s %q %#q\n", placeholders, placeholders, placeholders, placeholders) + // Result: foo "bar" foo "bar" "foo \"bar\"" `foo "bar"` + + // Maps formatted with %v show keys and values in their default formats. + // The %#v form (the # is called a "flag" in this context) shows the map in + // the Go source format. + isLegume := map[string]bool{ + "peanut": true, + // TODO: Include this line when maps are printed in deterministic order. + // See Issue #21095 + // "dachshund": false, + } + fmt.Printf("%v %#v\n", isLegume, isLegume) + // Result: map[peanut:true] map[string]bool{"peanut":true} + + // Structs formatted with %v show field values in their default formats. + // The %+v form shows the fields by name, while %#v formats the struct in + // Go source format. + person := struct { + Name string + Age int + }{"Kim", 22} + fmt.Printf("%v %+v %#v\n", person, person, person) + // Result: {Kim 22} {Name:Kim Age:22} struct { Name string; Age int }{Name:"Kim", Age:22} + + // The default format for a pointer shows the underlying value preceded by + // an ampersand. The %p verb prints the pointer value in hex. We use a + // typed nil for the argument to %p here because the value of any non-nil + // pointer would change from run to run; run the commented-out Printf + // call yourself to see. + pointer := &person + fmt.Printf("%v %p\n", pointer, (*int)(nil)) + // Result: &{Kim 22} 0x0 + // fmt.Printf("%v %p\n", pointer, pointer) + // Result: &{Kim 22} 0x010203 // See comment above. + + // Arrays and slices are formatted by applying the format to each element. + greats := [5]string{"Katano", "Kobayashi", "Kurosawa", "Miyazaki", "Ozu"} + fmt.Printf("%v %q\n", greats, greats) + // Result: [Katano Kobayashi Kurosawa Miyazaki Ozu] ["Katano" "Kobayashi" "Kurosawa" "Miyazaki" "Ozu"] + + kGreats := greats[:3] + fmt.Printf("%v %q %#v\n", kGreats, kGreats, kGreats) + // Result: [Katano Kobayashi Kurosawa] ["Katano" "Kobayashi" "Kurosawa"] []string{"Katano", "Kobayashi", "Kurosawa"} + + // Byte slices are special. Integer verbs like %d print the elements in + // that format. The %s and %q forms treat the slice like a string. The %x + // verb has a special form with the space flag that puts a space between + // the bytes. + cmd := []byte("a⌘") + fmt.Printf("%v %d %s %q %x % x\n", cmd, cmd, cmd, cmd, cmd, cmd) + // Result: [97 226 140 152] [97 226 140 152] a⌘ "a⌘" 61e28c98 61 e2 8c 98 + + // Types that implement Stringer are printed the same as strings. Because + // Stringers return a string, we can print them using a string-specific + // verb such as %q. + now := time.Unix(123456789, 0).UTC() // time.Time implements fmt.Stringer. + fmt.Printf("%v %q\n", now, now) + // Result: 1973-11-29 21:33:09 +0000 UTC "1973-11-29 21:33:09 +0000 UTC" + + // Output: + // 23 + // 23 + // 23 + // int *int + // true true + // 42 42 2a 52 101010 + // 3.141592653589793 3.141592653589793 3.14 ( 3.14) 3.141593e+00 + // (110.7+22.5i) (110.7+22.5i) (110.70+22.50i) (1.11e+02+2.25e+01i) + // 128512 128512 😀 '😀' U+1F600 U+1F600 '😀' + // foo "bar" foo "bar" "foo \"bar\"" `foo "bar"` + // map[peanut:true] map[string]bool{"peanut":true} + // {Kim 22} {Name:Kim Age:22} struct { Name string; Age int }{Name:"Kim", Age:22} + // &{Kim 22} 0x0 + // [Katano Kobayashi Kurosawa Miyazaki Ozu] ["Katano" "Kobayashi" "Kurosawa" "Miyazaki" "Ozu"] + // [Katano Kobayashi Kurosawa] ["Katano" "Kobayashi" "Kurosawa"] []string{"Katano", "Kobayashi", "Kurosawa"} + // [97 226 140 152] [97 226 140 152] a⌘ "a⌘" 61e28c98 61 e2 8c 98 + // 1973-11-29 21:33:09 +0000 UTC "1973-11-29 21:33:09 +0000 UTC" +} From 206fd7886b717d49758de9c125c1fd3575d74ef6 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 21 Sep 2018 21:03:35 -0700 Subject: [PATCH 0439/1663] spec: be more precise about the moment deferred functions are executed Fixes #27802. Change-Id: I7ea9f7279300a55b0cb851893edc591a6f84e324 Reviewed-on: https://go-review.googlesource.com/136758 Reviewed-by: Rob Pike Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 57bb3b53f581d..32336e86f866d 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -5546,7 +5546,10 @@

Defer statements

and saved anew but the actual function is not invoked. Instead, deferred functions are invoked immediately before the surrounding function returns, in the reverse order -they were deferred. +they were deferred. That is, if the surrounding function +returns through an explicit
return statement, +deferred functions are executed after any result parameters are set +by that return statement but before the function returns to its caller. If a deferred function value evaluates to nil, execution panics when the function is invoked, not when the "defer" statement is executed. @@ -5572,12 +5575,13 @@

Defer statements

defer fmt.Print(i) } -// f returns 1 +// f returns 42 func f() (result int) { defer func() { - result++ + // result is accessed after it was set to 6 by the return statement + result *= 7 }() - return 0 + return 6 } From 5be78668ef311576c945c4dfc6cfb0716236a89f Mon Sep 17 00:00:00 2001 From: Rob Pike Date: Fri, 21 Sep 2018 09:47:31 +1000 Subject: [PATCH 0440/1663] fmt: unify the printing examples Provide an example for each of the printing functions (Print, Sprintf, Fprintln etc.), and make them all produce the same output so their usage can be compared. Also add a package-level example explaining the difference between how Printf, Println, and Print behave. There are more examples to come. Update #27554. Change-Id: Ide03e5233f3762a9ee2ac0269f534ab927562ce2 Reviewed-on: https://go-review.googlesource.com/136615 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot --- src/fmt/example_test.go | 193 +++++++++++++++++++++++++++------------- 1 file changed, 132 insertions(+), 61 deletions(-) diff --git a/src/fmt/example_test.go b/src/fmt/example_test.go index bf9a6078f18c7..ecf3391ce7ce4 100644 --- a/src/fmt/example_test.go +++ b/src/fmt/example_test.go @@ -19,6 +19,7 @@ func ExampleErrorf() { const name, id = "bueller", 17 err := fmt.Errorf("user %q (id %d) not found", name, id) fmt.Println(err.Error()) + // Output: user "bueller" (id 17) not found } @@ -31,7 +32,7 @@ func ExampleFscanf() { r := strings.NewReader("5 true gophers") n, err := fmt.Fscanf(r, "%d %t %s", &i, &b, &s) if err != nil { - panic(err) + fmt.Fprintf(os.Stderr, "Fscanf: %v\n", err) } fmt.Println(i, b, s) fmt.Println(n) @@ -40,98 +41,168 @@ func ExampleFscanf() { // 3 } -func ExampleSprintf() { - i := 30 - s := "Aug" - sf := fmt.Sprintf("Today is %d %s", i, s) - fmt.Println(sf) - fmt.Println(len(sf)) +func ExampleFscanln() { + s := `dmr 1771 1.61803398875 + ken 271828 3.14159` + r := strings.NewReader(s) + var a string + var b int + var c float64 + for { + n, err := fmt.Fscanln(r, &a, &b, &c) + if err == io.EOF { + break + } + if err != nil { + panic(err) + } + fmt.Printf("%d: %s, %d, %f\n", n, a, b, c) + } // Output: - // Today is 30 Aug - // 15 + // 3: dmr, 1771, 1.618034 + // 3: ken, 271828, 3.141590 } func ExamplePrint() { - n, err := fmt.Print("there", "are", 99, "gophers", "\n") - if err != nil { - panic(err) - } - fmt.Print(n) + const name, age = "Kim", 22 + fmt.Print(name, " is ", age, " years old.\n") + + // It is conventional not to worry about any + // error returned by Print. + // Output: - // thereare99gophers - // 18 + // Kim is 22 years old. } func ExamplePrintln() { - n, err := fmt.Println("there", "are", 99, "gophers") - if err != nil { - panic(err) - } - fmt.Print(n) + const name, age = "Kim", 22 + fmt.Println(name, "is", age, "years old.") + + // It is conventional not to worry about any + // error returned by Println. + + // Output: + // Kim is 22 years old. +} + +func ExamplePrintf() { + const name, age = "Kim", 22 + fmt.Printf("%s is %d years old.\n", name, age) + + // It is conventional not to worry about any + // error returned by Printf. + + // Output: + // Kim is 22 years old. +} + +func ExampleSprint() { + const name, age = "Kim", 22 + s := fmt.Sprint(name, " is ", age, " years old.\n") + + io.WriteString(os.Stdout, s) // Ignoring error for simplicity. + // Output: - // there are 99 gophers - // 21 + // Kim is 22 years old. } func ExampleSprintln() { - s := "Aug" - sl := fmt.Sprintln("Today is 30", s) - fmt.Printf("%q", sl) + const name, age = "Kim", 22 + s := fmt.Sprintln(name, "is", age, "years old.") + + io.WriteString(os.Stdout, s) // Ignoring error for simplicity. + + // Output: + // Kim is 22 years old. +} + +func ExampleSprintf() { + const name, age = "Kim", 22 + s := fmt.Sprintf("%s is %d years old.\n", name, age) + + io.WriteString(os.Stdout, s) // Ignoring error for simplicity. + // Output: - // "Today is 30 Aug\n" + // Kim is 22 years old. } func ExampleFprint() { - n, err := fmt.Fprint(os.Stdout, "there", "are", 99, "gophers", "\n") + const name, age = "Kim", 22 + n, err := fmt.Fprint(os.Stdout, name, " is ", age, " years old.\n") + + // The n and err return values from Fprint are + // those returned by the underlying io.Writer. if err != nil { - panic(err) + fmt.Fprintf(os.Stderr, "Fprint: %v\n", err) } - fmt.Print(n) + fmt.Print(n, " bytes written.\n") + // Output: - // thereare99gophers - // 18 + // Kim is 22 years old. + // 21 bytes written. } func ExampleFprintln() { - n, err := fmt.Fprintln(os.Stdout, "there", "are", 99, "gophers") + const name, age = "Kim", 22 + n, err := fmt.Fprintln(os.Stdout, name, "is", age, "years old.") + + // The n and err return values from Fprintln are + // those returned by the underlying io.Writer. if err != nil { - panic(err) + fmt.Fprintf(os.Stderr, "Fprintln: %v\n", err) } - fmt.Print(n) + fmt.Println(n, "bytes written.") + // Output: - // there are 99 gophers - // 21 + // Kim is 22 years old. + // 21 bytes written. } -func ExampleFscanln() { - s := `dmr 1771 1.61803398875 - ken 271828 3.14159` - r := strings.NewReader(s) - var a string - var b int - var c float64 - for { - n, err := fmt.Fscanln(r, &a, &b, &c) - if err == io.EOF { - break - } - if err != nil { - panic(err) - } - fmt.Printf("%d: %s, %d, %f\n", n, a, b, c) +func ExampleFprintf() { + const name, age = "Kim", 22 + n, err := fmt.Fprintf(os.Stdout, "%s is %d years old.\n", name, age) + + // The n and err return values from Fprintf are + // those returned by the underlying io.Writer. + if err != nil { + fmt.Fprintf(os.Stderr, "Fprintf: %v\n", err) } + fmt.Printf("%d bytes written.\n", n) + // Output: - // 3: dmr, 1771, 1.618034 - // 3: ken, 271828, 3.141590 + // Kim is 22 years old. + // 21 bytes written. } -func ExampleSprint() { - s := fmt.Sprint("there", "are", "99", "gophers") - fmt.Println(s) - fmt.Println(len(s)) +// Print, Println, and Printf lay out their arguments differently. In this example +// we can compare their behaviors. Println always adds blanks between the items it +// prints, while Print adds blanks only between non-string arguments and Printf +// does exactly what it is told. +// Sprint, Sprintln, Sprintf, Fprint, Fprintln, and Fprintf behave the same as +// their corresponding Print, Println, and Printf functions shown here. +func Example_printers() { + a, b := 3.0, 4.0 + h := math.Hypot(a, b) + + // Print inserts blanks between arguments when neither is a string. + // It does not add a newline to the output, so we add one explicitly. + fmt.Print("The vector (", a, b, ") has length ", h, ".\n") + + // Println always inserts spaces between its arguments, + // so it cannot be used to produce the same output as Print in this case; + // its output has extra spaces. + // Also, Println always adds a newline to the output. + fmt.Println("The vector (", a, b, ") has length", h, ".") + + // Printf provides complete control but is more complex to use. + // It does not add a newline to the output, so we add one explicitly + // at the end of the format specifier string. + fmt.Printf("The vector (%g %g) has length %g.\n", a, b, h) + // Output: - // thereare99gophers - // 17 + // The vector (3 4) has length 5. + // The vector ( 3 4 ) has length 5 . + // The vector (3 4) has length 5. } // These examples demonstrate the basics of printing using a format string. Printf, From 8c1c6702f1a29f1944e6d0035dd8430dc8b43deb Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Mon, 24 Sep 2018 23:05:39 +0200 Subject: [PATCH 0441/1663] test: restore binary.BigEndian use in checkbce CL 136855 removed the encoding/binary dependency from the checkbce.go test by defining a local Uint64 to fix the noopt builder; then a more general mechanism to skip tests on the noopt builder was introduced in CL 136898, so we can now restore the binary.Uint64 calls in testbce. Change-Id: I3efbb41be0bfc446a7e638ce6a593371ead2684f Reviewed-on: https://go-review.googlesource.com/137056 Run-TryBot: Alberto Donizetti Reviewed-by: Giovanni Bajo Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- test/checkbce.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/test/checkbce.go b/test/checkbce.go index ef4e584ca0923..a8f060aa72eb6 100644 --- a/test/checkbce.go +++ b/test/checkbce.go @@ -10,6 +10,8 @@ package main +import "encoding/binary" + func f0(a []int) { a[0] = 1 // ERROR "Found IsInBounds$" a[0] = 1 @@ -142,18 +144,12 @@ func g4(a [100]int) { } } -func Uint64(b []byte) uint64 { - _ = b[7] // ERROR "Found IsInBounds$" - return uint64(b[7]) | uint64(b[6])<<8 | uint64(b[5])<<16 | uint64(b[4])<<24 | - uint64(b[3])<<32 | uint64(b[2])<<40 | uint64(b[1])<<48 | uint64(b[0])<<56 -} - func decode1(data []byte) (x uint64) { for len(data) >= 32 { - x += Uint64(data[:8]) - x += Uint64(data[8:16]) - x += Uint64(data[16:24]) - x += Uint64(data[24:32]) + x += binary.BigEndian.Uint64(data[:8]) + x += binary.BigEndian.Uint64(data[8:16]) + x += binary.BigEndian.Uint64(data[16:24]) + x += binary.BigEndian.Uint64(data[24:32]) data = data[32:] } return x @@ -163,13 +159,13 @@ func decode2(data []byte) (x uint64) { // TODO(rasky): this should behave like decode1 and compile to no // boundchecks. We're currently not able to remove all of them. for len(data) >= 32 { - x += Uint64(data) + x += binary.BigEndian.Uint64(data) data = data[8:] - x += Uint64(data) // ERROR "Found IsInBounds$" + x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$" data = data[8:] - x += Uint64(data) // ERROR "Found IsInBounds$" + x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$" data = data[8:] - x += Uint64(data) // ERROR "Found IsInBounds$" + x += binary.BigEndian.Uint64(data) // ERROR "Found IsInBounds$" data = data[8:] } return x From 0ee8a559e5778b4dbfa20c524867112693ba607f Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 24 Jul 2018 23:59:48 +0000 Subject: [PATCH 0442/1663] cmd/compile/internal/ssa: fix a typo Change-Id: Ie3a8c54fe5e1b94f506cc0e6f650aab441d28a75 Reviewed-on: https://go-review.googlesource.com/137115 Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/prove.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/compile/internal/ssa/prove.go b/src/cmd/compile/internal/ssa/prove.go index af2b9ef0ed79c..6462370d5cb14 100644 --- a/src/cmd/compile/internal/ssa/prove.go +++ b/src/cmd/compile/internal/ssa/prove.go @@ -58,7 +58,7 @@ func (r relation) String() string { } // domain represents the domain of a variable pair in which a set -// of relations is known. For example, relations learned for unsigned +// of relations is known. For example, relations learned for unsigned // pairs cannot be transferred to signed pairs because the same bit // representation can mean something else. type domain uint @@ -625,7 +625,7 @@ var ( // For example: // OpLess8: {signed, lt}, // v1 = (OpLess8 v2 v3). - // If v1 branch is taken than we learn that the rangeMaks + // If v1 branch is taken then we learn that the rangeMask // can be at most lt. domainRelationTable = map[Op]struct { d domain From c7ac645d28b99f163c46e2b8622ca7b60dc212ce Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 20 Sep 2018 11:43:42 +0200 Subject: [PATCH 0443/1663] runtime: fix reference to sys{Fault,Free,Reserve,Unused,Used} in comments Change-Id: Icbaedc49c810c63c51d56ae394d2f70e4d64b3e0 Reviewed-on: https://go-review.googlesource.com/136495 Run-TryBot: Tobias Klauser TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/runtime/malloc.go | 18 +++++++++--------- src/runtime/mgcsweep.go | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index 07e0a67240ceb..c6c969a3bf008 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -328,27 +328,27 @@ var physPageSize uintptr // may use larger alignment, so the caller must be careful to realign the // memory obtained by sysAlloc. // -// SysUnused notifies the operating system that the contents +// sysUnused notifies the operating system that the contents // of the memory region are no longer needed and can be reused // for other purposes. -// SysUsed notifies the operating system that the contents +// sysUsed notifies the operating system that the contents // of the memory region are needed again. // -// SysFree returns it unconditionally; this is only used if +// sysFree returns it unconditionally; this is only used if // an out-of-memory error has been detected midway through -// an allocation. It is okay if SysFree is a no-op. +// an allocation. It is okay if sysFree is a no-op. // -// SysReserve reserves address space without allocating memory. +// sysReserve reserves address space without allocating memory. // If the pointer passed to it is non-nil, the caller wants the -// reservation there, but SysReserve can still choose another +// reservation there, but sysReserve can still choose another // location if that one is unavailable. -// NOTE: SysReserve returns OS-aligned memory, but the heap allocator +// NOTE: sysReserve returns OS-aligned memory, but the heap allocator // may use larger alignment, so the caller must be careful to realign the // memory obtained by sysAlloc. // -// SysMap maps previously reserved address space for use. +// sysMap maps previously reserved address space for use. // -// SysFault marks a (already sysAlloc'd) region to fault +// sysFault marks a (already sysAlloc'd) region to fault // if accessed. Used only for debugging the runtime. func mallocinit() { diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go index c7baa455fe19e..71f5c4b3a9dcb 100644 --- a/src/runtime/mgcsweep.go +++ b/src/runtime/mgcsweep.go @@ -339,18 +339,18 @@ func (s *mspan) sweep(preserve bool) bool { // Free large span to heap // NOTE(rsc,dvyukov): The original implementation of efence - // in CL 22060046 used SysFree instead of SysFault, so that + // in CL 22060046 used sysFree instead of sysFault, so that // the operating system would eventually give the memory // back to us again, so that an efence program could run // longer without running out of memory. Unfortunately, - // calling SysFree here without any kind of adjustment of the + // calling sysFree here without any kind of adjustment of the // heap data structures means that when the memory does // come back to us, we have the wrong metadata for it, either in // the MSpan structures or in the garbage collection bitmap. - // Using SysFault here means that the program will run out of + // Using sysFault here means that the program will run out of // memory fairly quickly in efence mode, but at least it won't // have mysterious crashes due to confused memory reuse. - // It should be possible to switch back to SysFree if we also + // It should be possible to switch back to sysFree if we also // implement and then call some kind of MHeap_DeleteSpan. if debug.efence > 0 { s.limit = 0 // prevent mlookup from finding this span From b84a58095f11ba3122b88847d1b0a73c57c1632c Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Sat, 8 Sep 2018 17:00:00 +0100 Subject: [PATCH 0444/1663] image/png: pack image data for small bitdepth paletted images Bit packs image data when writing images with fewer than 16 colors in its palette. Reading of bit packed image data was already implemented. Fixes #19879 Change-Id: I0a06f9599a163931e20d3503fc3722e5101f0070 Reviewed-on: https://go-review.googlesource.com/134235 Reviewed-by: Nigel Tao --- src/image/png/writer.go | 73 +++++++++++++++++++---- src/image/png/writer_test.go | 108 +++++++++++++++++++++++++++++++++++ 2 files changed, 170 insertions(+), 11 deletions(-) diff --git a/src/image/png/writer.go b/src/image/png/writer.go index de8c28e919684..c03335120eb27 100644 --- a/src/image/png/writer.go +++ b/src/image/png/writer.go @@ -137,6 +137,15 @@ func (e *encoder) writeIHDR() { case cbP8: e.tmp[8] = 8 e.tmp[9] = ctPaletted + case cbP4: + e.tmp[8] = 4 + e.tmp[9] = ctPaletted + case cbP2: + e.tmp[8] = 2 + e.tmp[9] = ctPaletted + case cbP1: + e.tmp[8] = 1 + e.tmp[9] = ctPaletted case cbTCA8: e.tmp[8] = 8 e.tmp[9] = ctTrueColorAlpha @@ -305,31 +314,38 @@ func (e *encoder) writeImage(w io.Writer, m image.Image, cb int, level int) erro } defer e.zw.Close() - bpp := 0 // Bytes per pixel. + bitsPerPixel := 0 switch cb { case cbG8: - bpp = 1 + bitsPerPixel = 8 case cbTC8: - bpp = 3 + bitsPerPixel = 24 case cbP8: - bpp = 1 + bitsPerPixel = 8 + case cbP4: + bitsPerPixel = 4 + case cbP2: + bitsPerPixel = 2 + case cbP1: + bitsPerPixel = 1 case cbTCA8: - bpp = 4 + bitsPerPixel = 32 case cbTC16: - bpp = 6 + bitsPerPixel = 48 case cbTCA16: - bpp = 8 + bitsPerPixel = 64 case cbG16: - bpp = 2 + bitsPerPixel = 16 } + // cr[*] and pr are the bytes for the current and previous row. // cr[0] is unfiltered (or equivalently, filtered with the ftNone filter). // cr[ft], for non-zero filter types ft, are buffers for transforming cr[0] under the // other PNG filter types. These buffers are allocated once and re-used for each row. // The +1 is for the per-row filter type, which is at cr[*][0]. b := m.Bounds() - sz := 1 + bpp*b.Dx() + sz := 1 + (bitsPerPixel*b.Dx()+7)/8 for i := range e.cr { if cap(e.cr[i]) < sz { e.cr[i] = make([]uint8, sz) @@ -405,6 +421,30 @@ func (e *encoder) writeImage(w io.Writer, m image.Image, cb int, level int) erro i += 1 } } + + case cbP4, cbP2, cbP1: + pi := m.(image.PalettedImage) + + var a uint8 + var c int + for x := b.Min.X; x < b.Max.X; x++ { + a = a< Date: Tue, 25 Sep 2018 15:33:49 +0100 Subject: [PATCH 0445/1663] image: avoid sharing test images between tests and benchmarks CL 136796 introduced benchmarks and refactored tests to use a common list of test images. The tests now fail when run with count > 2 since they rely on a fresh image each run. Fix this by changing the list of test images to a list of test image generator functions. Change-Id: I5884c6bccba5e29bf84ee546fa501bc258379f42 Reviewed-on: https://go-review.googlesource.com/137295 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/image/image_test.go | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/image/image_test.go b/src/image/image_test.go index 6f49752a25fb4..dfd8eb35a804d 100644 --- a/src/image/image_test.go +++ b/src/image/image_test.go @@ -24,25 +24,27 @@ func cmp(cm color.Model, c0, c1 color.Color) bool { var testImages = []struct { name string - image image + image func() image }{ - {"rgba", NewRGBA(Rect(0, 0, 10, 10))}, - {"rgba64", NewRGBA64(Rect(0, 0, 10, 10))}, - {"nrgba", NewNRGBA(Rect(0, 0, 10, 10))}, - {"nrgba64", NewNRGBA64(Rect(0, 0, 10, 10))}, - {"alpha", NewAlpha(Rect(0, 0, 10, 10))}, - {"alpha16", NewAlpha16(Rect(0, 0, 10, 10))}, - {"gray", NewGray(Rect(0, 0, 10, 10))}, - {"gray16", NewGray16(Rect(0, 0, 10, 10))}, - {"paletted", NewPaletted(Rect(0, 0, 10, 10), color.Palette{ - Transparent, - Opaque, - })}, + {"rgba", func() image { return NewRGBA(Rect(0, 0, 10, 10)) }}, + {"rgba64", func() image { return NewRGBA64(Rect(0, 0, 10, 10)) }}, + {"nrgba", func() image { return NewNRGBA(Rect(0, 0, 10, 10)) }}, + {"nrgba64", func() image { return NewNRGBA64(Rect(0, 0, 10, 10)) }}, + {"alpha", func() image { return NewAlpha(Rect(0, 0, 10, 10)) }}, + {"alpha16", func() image { return NewAlpha16(Rect(0, 0, 10, 10)) }}, + {"gray", func() image { return NewGray(Rect(0, 0, 10, 10)) }}, + {"gray16", func() image { return NewGray16(Rect(0, 0, 10, 10)) }}, + {"paletted", func() image { + return NewPaletted(Rect(0, 0, 10, 10), color.Palette{ + Transparent, + Opaque, + }) + }}, } func TestImage(t *testing.T) { for _, tc := range testImages { - m := tc.image + m := tc.image() if !Rect(0, 0, 10, 10).Eq(m.Bounds()) { t.Errorf("%T: want bounds %v, got %v", m, Rect(0, 0, 10, 10), m.Bounds()) continue @@ -120,9 +122,11 @@ func Test16BitsPerColorChannel(t *testing.T) { func BenchmarkAt(b *testing.B) { for _, tc := range testImages { b.Run(tc.name, func(b *testing.B) { + m := tc.image() b.ReportAllocs() + b.ResetTimer() for i := 0; i < b.N; i++ { - tc.image.At(4, 5) + m.At(4, 5) } }) } @@ -132,9 +136,11 @@ func BenchmarkSet(b *testing.B) { c := color.Gray{0xff} for _, tc := range testImages { b.Run(tc.name, func(b *testing.B) { + m := tc.image() b.ReportAllocs() + b.ResetTimer() for i := 0; i < b.N; i++ { - tc.image.Set(4, 5, c) + m.Set(4, 5, c) } }) } From eff3de0e63a905fa29715d63393860dbab92294f Mon Sep 17 00:00:00 2001 From: David Heuschmann Date: Wed, 19 Sep 2018 17:00:09 +0200 Subject: [PATCH 0446/1663] os/user: note in doc that user.Current is being cached user.Current caches the current user after its first call, so changes to the uid after the first call will not affect its result. As this might be unexpected, it should be mentioned in the docs. Fixes #27659 Change-Id: I8b3323d55441d9a79bc9534c6490884d8561889b Reviewed-on: https://go-review.googlesource.com/136315 Reviewed-by: Ian Lance Taylor --- src/os/user/lookup.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/os/user/lookup.go b/src/os/user/lookup.go index 2243a25788aed..b36b7c01c0b1c 100644 --- a/src/os/user/lookup.go +++ b/src/os/user/lookup.go @@ -7,6 +7,10 @@ package user import "sync" // Current returns the current user. +// +// The first call will cache the current user information. +// Subsequent calls will return the cached value and will not reflect +// changes to the current user. func Current() (*User, error) { cache.Do(func() { cache.u, cache.err = current() }) if cache.err != nil { From 5b2e2b6cf4762792a4d53d55203aebb383e79dde Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Tue, 25 Sep 2018 19:54:23 +0200 Subject: [PATCH 0447/1663] doc/faq: fix link to 2018 ISMM keynote Fixes #27860 Change-Id: I5d7a858a8d2c97dd4deb9f98c35e71fc75fca997 Reviewed-on: https://go-review.googlesource.com/137356 Reviewed-by: Brad Fitzpatrick --- doc/go_faq.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/go_faq.html b/doc/go_faq.html index 7c4263b090377..6bc9d6ef15300 100644 --- a/doc/go_faq.html +++ b/doc/go_faq.html @@ -2458,7 +2458,7 @@

Work continues to refine the algorithm, reduce overhead and latency further, and to explore new approaches. The 2018 -ISMM keynote +ISMM keynote by Rick Hudson of the Go team describes the progress so far and suggests some future approaches.

From e0bde68c80a3f87c6411f4ebf4b6881abf2387b4 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 25 Sep 2018 10:24:53 -0700 Subject: [PATCH 0448/1663] cmd/go: skip some tests that don't work with gccgo Also in TestRelativeGOBINFail change to the test directory, to avoid picking up whatever files are in the current directory. Change-Id: Icac576dafa016555a9f27d026d0e965dc5cdfea0 Reviewed-on: https://go-review.googlesource.com/137337 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/go/go_test.go | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index e7d96f62360fa..962b52fd3de55 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -1187,6 +1187,7 @@ func TestImportCycle(t *testing.T) { } func TestListImportMap(t *testing.T) { + skipIfGccgo(t, "gccgo does not have standard packages") tg := testgo(t) defer tg.cleanup() tg.parallel() @@ -1420,6 +1421,7 @@ func TestRelativeGOBINFail(t *testing.T) { defer tg.cleanup() tg.tempFile("triv.go", `package main; func main() {}`) tg.setenv("GOBIN", ".") + tg.cd(tg.path(".")) tg.runFail("install") tg.grepStderr("cannot install, GOBIN must be an absolute path", "go install must fail if $GOBIN is a relative path") } @@ -1731,20 +1733,23 @@ func TestGoListDeps(t *testing.T) { tg.run("list", "-deps", "p1") tg.grepStdout("p1/p2/p3/p4", "-deps p1 does not mention p4") - // Check the list is in dependency order. - tg.run("list", "-deps", "math") - want := "internal/cpu\nunsafe\nmath\n" - out := tg.stdout.String() - if !strings.Contains(out, "internal/cpu") { - // Some systems don't use internal/cpu. - want = "unsafe\nmath\n" - } - if tg.stdout.String() != want { - t.Fatalf("list -deps math: wrong order\nhave %q\nwant %q", tg.stdout.String(), want) + if runtime.Compiler != "gccgo" { + // Check the list is in dependency order. + tg.run("list", "-deps", "math") + want := "internal/cpu\nunsafe\nmath\n" + out := tg.stdout.String() + if !strings.Contains(out, "internal/cpu") { + // Some systems don't use internal/cpu. + want = "unsafe\nmath\n" + } + if tg.stdout.String() != want { + t.Fatalf("list -deps math: wrong order\nhave %q\nwant %q", tg.stdout.String(), want) + } } } func TestGoListTest(t *testing.T) { + skipIfGccgo(t, "gccgo does not have standard packages") tg := testgo(t) defer tg.cleanup() tg.parallel() @@ -1817,6 +1822,7 @@ func TestGoListCompiledCgo(t *testing.T) { } func TestGoListExport(t *testing.T) { + skipIfGccgo(t, "gccgo does not have standard packages") tg := testgo(t) defer tg.cleanup() tg.parallel() @@ -2053,6 +2059,7 @@ func TestGoTestCpuprofileLeavesBinaryBehind(t *testing.T) { } func TestGoTestCpuprofileDashOControlsBinaryLocation(t *testing.T) { + skipIfGccgo(t, "gccgo has no standard packages") tooSlow(t) tg := testgo(t) defer tg.cleanup() @@ -2109,6 +2116,7 @@ func TestGoTestDashCDashOControlsBinaryLocation(t *testing.T) { } func TestGoTestDashOWritesBinary(t *testing.T) { + skipIfGccgo(t, "gccgo has no standard packages") tooSlow(t) tg := testgo(t) defer tg.cleanup() @@ -2404,6 +2412,7 @@ func checkCoverage(tg *testgoData, data string) { } func TestCoverageRuns(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tooSlow(t) tg := testgo(t) defer tg.cleanup() @@ -2415,6 +2424,7 @@ func TestCoverageRuns(t *testing.T) { } func TestCoverageDotImport(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tg := testgo(t) defer tg.cleanup() tg.parallel() @@ -2427,6 +2437,7 @@ func TestCoverageDotImport(t *testing.T) { // Check that coverage analysis uses set mode. // Also check that coverage profiles merge correctly. func TestCoverageUsesSetMode(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tooSlow(t) tg := testgo(t) defer tg.cleanup() @@ -2457,6 +2468,7 @@ func TestCoverageUsesAtomicModeForRace(t *testing.T) { if !canRace { t.Skip("skipping because race detector not supported") } + skipIfGccgo(t, "gccgo has no cover tool") tg := testgo(t) defer tg.cleanup() @@ -2474,6 +2486,7 @@ func TestCoverageUsesAtomicModeForRace(t *testing.T) { } func TestCoverageSyncAtomicImport(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tooSlow(t) tg := testgo(t) defer tg.cleanup() @@ -2495,6 +2508,7 @@ func TestCoverageDepLoop(t *testing.T) { } func TestCoverageImportMainLoop(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tg := testgo(t) defer tg.cleanup() tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata")) @@ -2505,6 +2519,7 @@ func TestCoverageImportMainLoop(t *testing.T) { } func TestCoveragePattern(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tooSlow(t) tg := testgo(t) defer tg.cleanup() @@ -2520,6 +2535,7 @@ func TestCoveragePattern(t *testing.T) { } func TestCoverageErrorLine(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tooSlow(t) tg := testgo(t) defer tg.cleanup() @@ -2563,6 +2579,7 @@ func TestTestBuildFailureOutput(t *testing.T) { } func TestCoverageFunc(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tooSlow(t) tg := testgo(t) defer tg.cleanup() @@ -2578,6 +2595,7 @@ func TestCoverageFunc(t *testing.T) { // Issue 24588. func TestCoverageDashC(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tg := testgo(t) defer tg.cleanup() tg.parallel() @@ -2686,6 +2704,7 @@ func main() { } func TestCoverageWithCgo(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tooSlow(t) if !canCgo { t.Skip("skipping because cgo not enabled") @@ -5158,6 +5177,7 @@ func TestCacheCoverage(t *testing.T) { } func TestCacheVet(t *testing.T) { + skipIfGccgo(t, "gccgo has no standard packages") tg := testgo(t) defer tg.cleanup() tg.parallel() @@ -6076,6 +6096,7 @@ func TestNoRelativeTmpdir(t *testing.T) { // Issue 24704. func TestLinkerTmpDirIsDeleted(t *testing.T) { + skipIfGccgo(t, "gccgo does not use cmd/link") if !canCgo { t.Skip("skipping because cgo not enabled") } @@ -6123,6 +6144,7 @@ func TestLinkerTmpDirIsDeleted(t *testing.T) { } func testCDAndGOPATHAreDifferent(tg *testgoData, cd, gopath string) { + skipIfGccgo(tg.t, "gccgo does not support -ldflags -X") tg.setenv("GOPATH", gopath) tg.tempDir("dir") @@ -6178,6 +6200,7 @@ func TestGoBuildDashODevNull(t *testing.T) { // Issue 25093. func TestCoverpkgTestOnly(t *testing.T) { + skipIfGccgo(t, "gccgo has no cover tool") tg := testgo(t) defer tg.cleanup() tg.parallel() From e945623930d2c85b9a81476203451ca8f4092875 Mon Sep 17 00:00:00 2001 From: Lynn Boger Date: Tue, 11 Sep 2018 11:42:15 -0400 Subject: [PATCH 0449/1663] runtime: improve CALLFN macro for ppc64x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The previous CALLFN macro was copying a single byte at a time which is extremely inefficient on ppc64x. This changes the macro so it copies 8 bytes at a time. benchmark in reflect: name old time/op new time/op delta Call-8 177ns ± 0% 165ns ± 0% -6.78% (p=1.000 n=1+1) CallArgCopy/size=128-8 194ns ± 0% 140ns ± 0% -27.84% (p=1.000 n=1+1) CallArgCopy/size=256-8 253ns ± 0% 159ns ± 0% -37.15% (p=1.000 n=1+1) CallArgCopy/size=1024-8 612ns ± 0% 222ns ± 0% -63.73% (p=1.000 n=1+1) CallArgCopy/size=4096-8 2.14µs ± 0% 0.53µs ± 0% -75.01% (p=1.000 n=1+1) CallArgCopy/size=65536-8 33.0µs ± 0% 7.3µs ± 0% -77.72% (p=1.000 n=1+1) Change-Id: I71f6ee788264e61bb072264d21b77b83592c9dca Reviewed-on: https://go-review.googlesource.com/134635 Run-TryBot: Lynn Boger TryBot-Result: Gobot Gobot Reviewed-by: Carlos Eduardo Seo Reviewed-by: Michael Munday --- src/runtime/asm_ppc64x.s | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/src/runtime/asm_ppc64x.s b/src/runtime/asm_ppc64x.s index 57877c0194c7d..b180cb06ab9d0 100644 --- a/src/runtime/asm_ppc64x.s +++ b/src/runtime/asm_ppc64x.s @@ -390,15 +390,36 @@ TEXT NAME(SB), WRAPPER, $MAXSIZE-24; \ /* copy arguments to stack */ \ MOVD arg+16(FP), R3; \ MOVWZ argsize+24(FP), R4; \ - MOVD R1, R5; \ - ADD $(FIXED_FRAME-1), R5; \ - SUB $1, R3; \ - ADD R5, R4; \ - CMP R5, R4; \ - BEQ 4(PC); \ - MOVBZU 1(R3), R6; \ - MOVBZU R6, 1(R5); \ - BR -4(PC); \ + MOVD R1, R5; \ + CMP R4, $8; \ + BLT tailsetup; \ + /* copy 8 at a time if possible */ \ + ADD $(FIXED_FRAME-8), R5; \ + SUB $8, R3; \ +top: \ + MOVDU 8(R3), R7; \ + MOVDU R7, 8(R5); \ + SUB $8, R4; \ + CMP R4, $8; \ + BGE top; \ + /* handle remaining bytes */ \ + CMP $0, R4; \ + BEQ callfn; \ + ADD $7, R3; \ + ADD $7, R5; \ + BR tail; \ +tailsetup: \ + CMP $0, R4; \ + BEQ callfn; \ + ADD $(FIXED_FRAME-1), R5; \ + SUB $1, R3; \ +tail: \ + MOVBU 1(R3), R6; \ + MOVBU R6, 1(R5); \ + SUB $1, R4; \ + CMP $0, R4; \ + BGT tail; \ +callfn: \ /* call function */ \ MOVD f+8(FP), R11; \ MOVD (R11), R12; \ From 5bba5053675f102a3a81242e8f7551791ae5a56e Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Mon, 24 Sep 2018 10:20:46 +0100 Subject: [PATCH 0450/1663] image/draw: optimize bounds checks in loops MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use subslices with known length and cap to give bounds checking hints to the compiler. Improves over the earlier pointer based optimizations in https://go-review.googlesource.com/c/go/+/14093 for GlyphOver but not for FillOver so the latter is left unchanged. See #27857 for discussion of small caps used in subslices. name old time/op new time/op delta FillOver-8 607µs ± 1% 609µs ± 1% ~ (p=0.447 n=9+10) FillSrc-8 23.0µs ± 1% 22.9µs ± 2% ~ (p=0.412 n=9+10) CopyOver-8 647µs ± 0% 560µs ± 0% -13.43% (p=0.000 n=9+10) CopySrc-8 19.3µs ± 1% 19.1µs ± 2% -0.66% (p=0.029 n=10+10) NRGBAOver-8 697µs ± 1% 651µs ± 1% -6.64% (p=0.000 n=10+10) NRGBASrc-8 405µs ± 1% 347µs ± 0% -14.23% (p=0.000 n=10+10) YCbCr-8 432µs ± 2% 431µs ± 1% ~ (p=0.764 n=10+9) Gray-8 164µs ± 1% 139µs ± 1% -15.44% (p=0.000 n=10+10) CMYK-8 498µs ± 0% 461µs ± 0% -7.49% (p=0.000 n=10+9) GlyphOver-8 220µs ± 0% 199µs ± 0% -9.52% (p=0.000 n=9+10) RGBA-8 3.81ms ± 5% 3.79ms ± 5% ~ (p=0.549 n=9+10) Paletted-8 1.73ms ± 0% 1.73ms ± 1% ~ (p=0.278 n=10+9) GenericOver-8 11.0ms ± 2% 11.0ms ± 1% ~ (p=0.842 n=9+10) GenericMaskOver-8 5.29ms ± 1% 5.30ms ± 0% ~ (p=0.182 n=9+10) GenericSrc-8 4.24ms ± 1% 4.24ms ± 0% ~ (p=0.436 n=9+9) GenericMaskSrc-8 7.89ms ± 1% 7.90ms ± 2% ~ (p=0.631 n=10+10) Change-Id: I6fe1b21bb5e255826cbfdd2e73efd5858cd5557c Reviewed-on: https://go-review.googlesource.com/136935 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/image/draw/draw.go | 126 ++++++++++++++++++++--------------------- 1 file changed, 63 insertions(+), 63 deletions(-) diff --git a/src/image/draw/draw.go b/src/image/draw/draw.go index 977d7c522153a..3ff1828dc0c0a 100644 --- a/src/image/draw/draw.go +++ b/src/image/draw/draw.go @@ -309,23 +309,20 @@ func drawCopyOver(dst *image.RGBA, r image.Rectangle, src *image.RGBA, sp image. dpix := dst.Pix[d0:] spix := src.Pix[s0:] for i := i0; i != i1; i += idelta { - sr := uint32(spix[i+0]) * 0x101 - sg := uint32(spix[i+1]) * 0x101 - sb := uint32(spix[i+2]) * 0x101 - sa := uint32(spix[i+3]) * 0x101 - - dr := &dpix[i+0] - dg := &dpix[i+1] - db := &dpix[i+2] - da := &dpix[i+3] + s := spix[i : i+4 : i+4] // Small cap improves performance, see https://golang.org/issue/27857 + sr := uint32(s[0]) * 0x101 + sg := uint32(s[1]) * 0x101 + sb := uint32(s[2]) * 0x101 + sa := uint32(s[3]) * 0x101 // The 0x101 is here for the same reason as in drawRGBA. a := (m - sa) * 0x101 - *dr = uint8((uint32(*dr)*a/m + sr) >> 8) - *dg = uint8((uint32(*dg)*a/m + sg) >> 8) - *db = uint8((uint32(*db)*a/m + sb) >> 8) - *da = uint8((uint32(*da)*a/m + sa) >> 8) + d := dpix[i : i+4 : i+4] // Small cap improves performance, see https://golang.org/issue/27857 + d[0] = uint8((uint32(d[0])*a/m + sr) >> 8) + d[1] = uint8((uint32(d[1])*a/m + sg) >> 8) + d[2] = uint8((uint32(d[2])*a/m + sb) >> 8) + d[3] = uint8((uint32(d[3])*a/m + sa) >> 8) } d0 += ddelta s0 += sdelta @@ -372,23 +369,25 @@ func drawNRGBAOver(dst *image.RGBA, r image.Rectangle, src *image.NRGBA, sp imag for i, si := i0, si0; i < i1; i, si = i+4, si+4 { // Convert from non-premultiplied color to pre-multiplied color. - sa := uint32(spix[si+3]) * 0x101 - sr := uint32(spix[si+0]) * sa / 0xff - sg := uint32(spix[si+1]) * sa / 0xff - sb := uint32(spix[si+2]) * sa / 0xff - - dr := uint32(dpix[i+0]) - dg := uint32(dpix[i+1]) - db := uint32(dpix[i+2]) - da := uint32(dpix[i+3]) + s := spix[si : si+4 : si+4] // Small cap improves performance, see https://golang.org/issue/27857 + sa := uint32(s[3]) * 0x101 + sr := uint32(s[0]) * sa / 0xff + sg := uint32(s[1]) * sa / 0xff + sb := uint32(s[2]) * sa / 0xff + + d := dpix[i : i+4 : i+4] // Small cap improves performance, see https://golang.org/issue/27857 + dr := uint32(d[0]) + dg := uint32(d[1]) + db := uint32(d[2]) + da := uint32(d[3]) // The 0x101 is here for the same reason as in drawRGBA. a := (m - sa) * 0x101 - dpix[i+0] = uint8((dr*a/m + sr) >> 8) - dpix[i+1] = uint8((dg*a/m + sg) >> 8) - dpix[i+2] = uint8((db*a/m + sb) >> 8) - dpix[i+3] = uint8((da*a/m + sa) >> 8) + d[0] = uint8((dr*a/m + sr) >> 8) + d[1] = uint8((dg*a/m + sg) >> 8) + d[2] = uint8((db*a/m + sb) >> 8) + d[3] = uint8((da*a/m + sa) >> 8) } } } @@ -407,15 +406,17 @@ func drawNRGBASrc(dst *image.RGBA, r image.Rectangle, src *image.NRGBA, sp image for i, si := i0, si0; i < i1; i, si = i+4, si+4 { // Convert from non-premultiplied color to pre-multiplied color. - sa := uint32(spix[si+3]) * 0x101 - sr := uint32(spix[si+0]) * sa / 0xff - sg := uint32(spix[si+1]) * sa / 0xff - sb := uint32(spix[si+2]) * sa / 0xff - - dpix[i+0] = uint8(sr >> 8) - dpix[i+1] = uint8(sg >> 8) - dpix[i+2] = uint8(sb >> 8) - dpix[i+3] = uint8(sa >> 8) + s := spix[si : si+4 : si+4] // Small cap improves performance, see https://golang.org/issue/27857 + sa := uint32(s[3]) * 0x101 + sr := uint32(s[0]) * sa / 0xff + sg := uint32(s[1]) * sa / 0xff + sb := uint32(s[2]) * sa / 0xff + + d := dpix[i : i+4 : i+4] // Small cap improves performance, see https://golang.org/issue/27857 + d[0] = uint8(sr >> 8) + d[1] = uint8(sg >> 8) + d[2] = uint8(sb >> 8) + d[3] = uint8(sa >> 8) } } } @@ -434,10 +435,11 @@ func drawGray(dst *image.RGBA, r image.Rectangle, src *image.Gray, sp image.Poin for i, si := i0, si0; i < i1; i, si = i+4, si+1 { p := spix[si] - dpix[i+0] = p - dpix[i+1] = p - dpix[i+2] = p - dpix[i+3] = 255 + d := dpix[i : i+4 : i+4] // Small cap improves performance, see https://golang.org/issue/27857 + d[0] = p + d[1] = p + d[2] = p + d[3] = 255 } } } @@ -455,9 +457,10 @@ func drawCMYK(dst *image.RGBA, r image.Rectangle, src *image.CMYK, sp image.Poin spix := src.Pix[sy*src.Stride:] for i, si := i0, si0; i < i1; i, si = i+4, si+4 { - dpix[i+0], dpix[i+1], dpix[i+2] = - color.CMYKToRGB(spix[si+0], spix[si+1], spix[si+2], spix[si+3]) - dpix[i+3] = 255 + s := spix[si : si+4 : si+4] // Small cap improves performance, see https://golang.org/issue/27857 + d := dpix[i : i+4 : i+4] + d[0], d[1], d[2] = color.CMYKToRGB(s[0], s[1], s[2], s[3]) + d[3] = 255 } } } @@ -475,18 +478,14 @@ func drawGlyphOver(dst *image.RGBA, r image.Rectangle, src *image.Uniform, mask } ma |= ma << 8 - dr := &dst.Pix[i+0] - dg := &dst.Pix[i+1] - db := &dst.Pix[i+2] - da := &dst.Pix[i+3] - // The 0x101 is here for the same reason as in drawRGBA. a := (m - (sa * ma / m)) * 0x101 - *dr = uint8((uint32(*dr)*a + sr*ma) / m >> 8) - *dg = uint8((uint32(*dg)*a + sg*ma) / m >> 8) - *db = uint8((uint32(*db)*a + sb*ma) / m >> 8) - *da = uint8((uint32(*da)*a + sa*ma) / m >> 8) + d := dst.Pix[i : i+4 : i+4] // Small cap improves performance, see https://golang.org/issue/27857 + d[0] = uint8((uint32(d[0])*a + sr*ma) / m >> 8) + d[1] = uint8((uint32(d[1])*a + sg*ma) / m >> 8) + d[2] = uint8((uint32(d[2])*a + sb*ma) / m >> 8) + d[3] = uint8((uint32(d[3])*a + sa*ma) / m >> 8) } i0 += dst.Stride i1 += dst.Stride @@ -518,11 +517,12 @@ func drawRGBA(dst *image.RGBA, r image.Rectangle, src image.Image, sp image.Poin _, _, _, ma = mask.At(mx, my).RGBA() } sr, sg, sb, sa := src.At(sx, sy).RGBA() + d := dst.Pix[i : i+4 : i+4] // Small cap improves performance, see https://golang.org/issue/27857 if op == Over { - dr := uint32(dst.Pix[i+0]) - dg := uint32(dst.Pix[i+1]) - db := uint32(dst.Pix[i+2]) - da := uint32(dst.Pix[i+3]) + dr := uint32(d[0]) + dg := uint32(d[1]) + db := uint32(d[2]) + da := uint32(d[3]) // dr, dg, db and da are all 8-bit color at the moment, ranging in [0,255]. // We work in 16-bit color, and so would normally do: @@ -532,16 +532,16 @@ func drawRGBA(dst *image.RGBA, r image.Rectangle, src image.Image, sp image.Poin // This yields the same result, but is fewer arithmetic operations. a := (m - (sa * ma / m)) * 0x101 - dst.Pix[i+0] = uint8((dr*a + sr*ma) / m >> 8) - dst.Pix[i+1] = uint8((dg*a + sg*ma) / m >> 8) - dst.Pix[i+2] = uint8((db*a + sb*ma) / m >> 8) - dst.Pix[i+3] = uint8((da*a + sa*ma) / m >> 8) + d[0] = uint8((dr*a + sr*ma) / m >> 8) + d[1] = uint8((dg*a + sg*ma) / m >> 8) + d[2] = uint8((db*a + sb*ma) / m >> 8) + d[3] = uint8((da*a + sa*ma) / m >> 8) } else { - dst.Pix[i+0] = uint8(sr * ma / m >> 8) - dst.Pix[i+1] = uint8(sg * ma / m >> 8) - dst.Pix[i+2] = uint8(sb * ma / m >> 8) - dst.Pix[i+3] = uint8(sa * ma / m >> 8) + d[0] = uint8(sr * ma / m >> 8) + d[1] = uint8(sg * ma / m >> 8) + d[2] = uint8(sb * ma / m >> 8) + d[3] = uint8(sa * ma / m >> 8) } } i0 += dy * dst.Stride From 23f75541946884167364a5cc513699661dcfe8ff Mon Sep 17 00:00:00 2001 From: Carlos Eduardo Seo Date: Fri, 21 Sep 2018 16:06:32 -0300 Subject: [PATCH 0451/1663] internal/bytealg: improve performance of IndexByte for ppc64x Use addi+lvx instruction fusion and remove register dependencies in the main loop to improve performance. benchmark old ns/op new ns/op delta BenchmarkIndexByte/10-192 9.86 9.75 -1.12% BenchmarkIndexByte/32-192 15.6 11.2 -28.21% BenchmarkIndexByte/4K-192 155 97.6 -37.03% BenchmarkIndexByte/4M-192 171790 129650 -24.53% BenchmarkIndexByte/64M-192 6530982 5018424 -23.16% benchmark old MB/s new MB/s speedup BenchmarkIndexByte/10-192 1013.72 1025.76 1.01x BenchmarkIndexByte/32-192 2049.47 2868.01 1.40x BenchmarkIndexByte/4K-192 26422.69 41975.67 1.59x BenchmarkIndexByte/4M-192 24415.17 32350.74 1.33x BenchmarkIndexByte/64M-192 10275.46 13372.50 1.30x Change-Id: Iedf17f01f374d58e85dcd6a972209bfcb7eb6063 Reviewed-on: https://go-review.googlesource.com/137415 Run-TryBot: Lynn Boger TryBot-Result: Gobot Gobot Reviewed-by: Lynn Boger --- src/internal/bytealg/indexbyte_ppc64x.s | 28 ++++++++++++++----------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/internal/bytealg/indexbyte_ppc64x.s b/src/internal/bytealg/indexbyte_ppc64x.s index ccf897d99c451..61b33bc9cb27b 100644 --- a/src/internal/bytealg/indexbyte_ppc64x.s +++ b/src/internal/bytealg/indexbyte_ppc64x.s @@ -38,14 +38,14 @@ TEXT strings·IndexByte(SB),NOSPLIT|NOFRAME,$0-32 BR indexbytebody<>(SB) TEXT indexbytebody<>(SB),NOSPLIT|NOFRAME,$0-0 - DCBT (R3) // Prepare cache line. MOVD R3,R17 // Save base address for calculating the index later. RLDICR $0,R3,$60,R8 // Align address to doubleword boundary in R8. RLDIMI $8,R5,$48,R5 // Replicating the byte across the register. ADD R4,R3,R7 // Last acceptable address in R7. + DCBT (R8) // Prepare cache line. RLDIMI $16,R5,$32,R5 - CMPU R4,$32 // Check if it's a small string (<32 bytes). Those will be processed differently. + CMPU R4,$32 // Check if it's a small string (≤32 bytes). Those will be processed differently. MOVD $-1,R9 WORD $0x54661EB8 // Calculate padding in R6 (rlwinm r6,r3,3,26,28). RLDIMI $32,R5,$0,R5 @@ -56,7 +56,7 @@ TEXT indexbytebody<>(SB),NOSPLIT|NOFRAME,$0-0 #else SRD R6,R9,R9 // Same for Big Endian #endif - BLE small_string // Jump to the small string case if it's <32 bytes. + BLE small_string // Jump to the small string case if it's ≤32 bytes. // If we are 64-byte aligned, branch to qw_align just to get the auxiliary values // in V0, V1 and V10, then branch to the preloop. @@ -97,7 +97,7 @@ qw_align: LVSL (R0+R0),V11 VSLB V11,V10,V10 VSPLTB $7,V1,V1 // Replicate byte across V1 - CMPU R4, $64 // If len <= 64, don't use the vectorized loop + CMPU R4, $64 // If len ≤ 64, don't use the vectorized loop BLE tail // We will load 4 quardwords per iteration in the loop, so check for @@ -131,7 +131,7 @@ qw_align: // 64-byte aligned. Prepare for the main loop. preloop: CMPU R4,$64 - BLE tail // If len <= 64, don't use the vectorized loop + BLE tail // If len ≤ 64, don't use the vectorized loop // We are now aligned to a 64-byte boundary. We will load 4 quadwords // per loop iteration. The last doubleword is in R10, so our loop counter @@ -140,30 +140,34 @@ preloop: SRD $6,R6,R9 // Loop counter in R9 MOVD R9,CTR + ADD $-64,R8,R8 // Adjust index for loop entry MOVD $16,R11 // Load offsets for the vector loads MOVD $32,R9 MOVD $48,R7 // Main loop we will load 64 bytes per iteration loop: + ADD $64,R8,R8 // Fuse addi+lvx for performance LVX (R8+R0),V2 // Load 4 16-byte vectors - LVX (R11+R8),V3 - LVX (R9+R8),V4 - LVX (R7+R8),V5 + LVX (R8+R11),V3 VCMPEQUB V1,V2,V6 // Look for byte in each vector VCMPEQUB V1,V3,V7 + + LVX (R8+R9),V4 + LVX (R8+R7),V5 VCMPEQUB V1,V4,V8 VCMPEQUB V1,V5,V9 + VOR V6,V7,V11 // Compress the result in a single vector VOR V8,V9,V12 - VOR V11,V12,V11 - VCMPEQUBCC V0,V11,V11 // Check for byte + VOR V11,V12,V13 + VCMPEQUBCC V0,V13,V14 // Check for byte BGE CR6,found - ADD $64,R8,R8 BC 16,0,loop // bdnz loop - // Handle the tailing bytes or R4 <= 64 + // Handle the tailing bytes or R4 ≤ 64 RLDICL $0,R6,$58,R4 + ADD $64,R8,R8 tail: CMPU R4,$0 BEQ notfound From b83ef36d6acb351ac50c5c7199fd683fb5226983 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 25 Sep 2018 12:49:22 -0700 Subject: [PATCH 0452/1663] go/build: move isStandardPackage to new internal/goroot package The module code in cmd/go sometimes needs to know whether it is looking at a standard package, and currently uses gc-specific code for that. This CL moves the existing isStandardPackage code in the go/build package, which works for both gc and gccgo, into a new internal/goroot package so that cmd/go can call it. The changes to cmd/go will be in a subsequent CL. Change-Id: Ic1ce4c022a932c6b3e99fa062631577085cc6ecb Reviewed-on: https://go-review.googlesource.com/137435 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/go/build/build.go | 3 +- src/go/build/deps_test.go | 3 +- src/go/build/gc.go | 120 ------------------------------ src/go/build/gccgo.go | 6 -- src/internal/goroot/gc.go | 140 +++++++++++++++++++++++++++++++++++ src/internal/goroot/gccgo.go | 27 +++++++ 6 files changed, 171 insertions(+), 128 deletions(-) create mode 100644 src/internal/goroot/gc.go create mode 100644 src/internal/goroot/gccgo.go diff --git a/src/go/build/build.go b/src/go/build/build.go index b68a712a7daba..14b007c25a7a5 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -12,6 +12,7 @@ import ( "go/doc" "go/parser" "go/token" + "internal/goroot" "io" "io/ioutil" "log" @@ -656,7 +657,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa } tried.goroot = dir } - if ctxt.Compiler == "gccgo" && isStandardPackage(path) { + if ctxt.Compiler == "gccgo" && goroot.IsStandardPackage(ctxt.GOROOT, ctxt.Compiler, path) { p.Dir = ctxt.joinPath(ctxt.GOROOT, "src", path) p.Goroot = true p.Root = ctxt.GOROOT diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index 244c745d41df1..91617714f6cc4 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -258,7 +258,7 @@ var pkgDeps = map[string][]string{ "encoding/pem": {"L4"}, "encoding/xml": {"L4", "encoding"}, "flag": {"L4", "OS"}, - "go/build": {"L4", "OS", "GOPARSER"}, + "go/build": {"L4", "OS", "GOPARSER", "internal/goroot"}, "html": {"L4"}, "image/draw": {"L4", "image/internal/imageutil"}, "image/gif": {"L4", "compress/lzw", "image/color/palette", "image/draw"}, @@ -266,6 +266,7 @@ var pkgDeps = map[string][]string{ "image/jpeg": {"L4", "image/internal/imageutil"}, "image/png": {"L4", "compress/zlib"}, "index/suffixarray": {"L4", "regexp"}, + "internal/goroot": {"L4", "OS"}, "internal/singleflight": {"sync"}, "internal/trace": {"L4", "OS"}, "math/big": {"L4"}, diff --git a/src/go/build/gc.go b/src/go/build/gc.go index e2be2cbb1d18f..3025cd5681591 100644 --- a/src/go/build/gc.go +++ b/src/go/build/gc.go @@ -7,131 +7,11 @@ package build import ( - "os" - "os/exec" "path/filepath" "runtime" - "strings" - "sync" ) // getToolDir returns the default value of ToolDir. func getToolDir() string { return filepath.Join(runtime.GOROOT(), "pkg/tool/"+runtime.GOOS+"_"+runtime.GOARCH) } - -// isStandardPackage is not used for the gc toolchain. -// However, this function may be called when using `go build -compiler=gccgo`. -func isStandardPackage(path string) bool { - return gccgoSearch.isStandard(path) -} - -// gccgoSearch holds the gccgo search directories. -type gccgoDirs struct { - once sync.Once - dirs []string -} - -// gccgoSearch is used to check whether a gccgo package exists in the -// standard library. -var gccgoSearch gccgoDirs - -// init finds the gccgo search directories. If this fails it leaves dirs == nil. -func (gd *gccgoDirs) init() { - gccgo := os.Getenv("GCCGO") - if gccgo == "" { - gccgo = "gccgo" - } - bin, err := exec.LookPath(gccgo) - if err != nil { - return - } - - allDirs, err := exec.Command(bin, "-print-search-dirs").Output() - if err != nil { - return - } - versionB, err := exec.Command(bin, "-dumpversion").Output() - if err != nil { - return - } - version := strings.TrimSpace(string(versionB)) - machineB, err := exec.Command(bin, "-dumpmachine").Output() - if err != nil { - return - } - machine := strings.TrimSpace(string(machineB)) - - dirsEntries := strings.Split(string(allDirs), "\n") - const prefix = "libraries: =" - var dirs []string - for _, dirEntry := range dirsEntries { - if strings.HasPrefix(dirEntry, prefix) { - dirs = filepath.SplitList(strings.TrimPrefix(dirEntry, prefix)) - break - } - } - if len(dirs) == 0 { - return - } - - var lastDirs []string - for _, dir := range dirs { - goDir := filepath.Join(dir, "go", version) - if fi, err := os.Stat(goDir); err == nil && fi.IsDir() { - gd.dirs = append(gd.dirs, goDir) - goDir = filepath.Join(goDir, machine) - if fi, err = os.Stat(goDir); err == nil && fi.IsDir() { - gd.dirs = append(gd.dirs, goDir) - } - } - if fi, err := os.Stat(dir); err == nil && fi.IsDir() { - lastDirs = append(lastDirs, dir) - } - } - gd.dirs = append(gd.dirs, lastDirs...) -} - -// isStandard returns whether path is a standard library for gccgo. -func (gd *gccgoDirs) isStandard(path string) bool { - // Quick check: if the first path component has a '.', it's not - // in the standard library. This skips most GOPATH directories. - i := strings.Index(path, "/") - if i < 0 { - i = len(path) - } - if strings.Contains(path[:i], ".") { - return false - } - - if path == "unsafe" { - // Special case. - return true - } - - gd.once.Do(gd.init) - if gd.dirs == nil { - // We couldn't find the gccgo search directories. - // Best guess, since the first component did not contain - // '.', is that this is a standard library package. - return true - } - - for _, dir := range gd.dirs { - full := filepath.Join(dir, path) - pkgdir, pkg := filepath.Split(full) - for _, p := range [...]string{ - full, - full + ".gox", - pkgdir + "lib" + pkg + ".so", - pkgdir + "lib" + pkg + ".a", - full + ".o", - } { - if fi, err := os.Stat(p); err == nil && !fi.IsDir() { - return true - } - } - } - - return false -} diff --git a/src/go/build/gccgo.go b/src/go/build/gccgo.go index 59e089d69db2c..c6aac9aa1bc2d 100644 --- a/src/go/build/gccgo.go +++ b/src/go/build/gccgo.go @@ -12,9 +12,3 @@ import "runtime" func getToolDir() string { return envOr("GCCGOTOOLDIR", runtime.GCCGOTOOLDIR) } - -// isStandardPackage returns whether path names a standard library package. -// This uses a list generated at build time. -func isStandardPackage(path string) bool { - return stdpkg[path] -} diff --git a/src/internal/goroot/gc.go b/src/internal/goroot/gc.go new file mode 100644 index 0000000000000..b9da9a53014f4 --- /dev/null +++ b/src/internal/goroot/gc.go @@ -0,0 +1,140 @@ +// Copyright 2018 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. + +// +build gc + +package goroot + +import ( + "os" + "os/exec" + "path/filepath" + "strings" + "sync" +) + +// IsStandardPackage returns whether path is a standard package, +// given goroot and compiler. +func IsStandardPackage(goroot, compiler, path string) bool { + switch compiler { + case "gc": + dir := filepath.Join(goroot, "src", path) + _, err := os.Stat(dir) + return err == nil + case "gccgo": + return gccgoSearch.isStandard(path) + default: + panic("unknown compiler " + compiler) + } +} + +// gccgoSearch holds the gccgo search directories. +type gccgoDirs struct { + once sync.Once + dirs []string +} + +// gccgoSearch is used to check whether a gccgo package exists in the +// standard library. +var gccgoSearch gccgoDirs + +// init finds the gccgo search directories. If this fails it leaves dirs == nil. +func (gd *gccgoDirs) init() { + gccgo := os.Getenv("GCCGO") + if gccgo == "" { + gccgo = "gccgo" + } + bin, err := exec.LookPath(gccgo) + if err != nil { + return + } + + allDirs, err := exec.Command(bin, "-print-search-dirs").Output() + if err != nil { + return + } + versionB, err := exec.Command(bin, "-dumpversion").Output() + if err != nil { + return + } + version := strings.TrimSpace(string(versionB)) + machineB, err := exec.Command(bin, "-dumpmachine").Output() + if err != nil { + return + } + machine := strings.TrimSpace(string(machineB)) + + dirsEntries := strings.Split(string(allDirs), "\n") + const prefix = "libraries: =" + var dirs []string + for _, dirEntry := range dirsEntries { + if strings.HasPrefix(dirEntry, prefix) { + dirs = filepath.SplitList(strings.TrimPrefix(dirEntry, prefix)) + break + } + } + if len(dirs) == 0 { + return + } + + var lastDirs []string + for _, dir := range dirs { + goDir := filepath.Join(dir, "go", version) + if fi, err := os.Stat(goDir); err == nil && fi.IsDir() { + gd.dirs = append(gd.dirs, goDir) + goDir = filepath.Join(goDir, machine) + if fi, err = os.Stat(goDir); err == nil && fi.IsDir() { + gd.dirs = append(gd.dirs, goDir) + } + } + if fi, err := os.Stat(dir); err == nil && fi.IsDir() { + lastDirs = append(lastDirs, dir) + } + } + gd.dirs = append(gd.dirs, lastDirs...) +} + +// isStandard returns whether path is a standard library for gccgo. +func (gd *gccgoDirs) isStandard(path string) bool { + // Quick check: if the first path component has a '.', it's not + // in the standard library. This skips most GOPATH directories. + i := strings.Index(path, "/") + if i < 0 { + i = len(path) + } + if strings.Contains(path[:i], ".") { + return false + } + + if path == "unsafe" { + // Special case. + return true + } + + gd.once.Do(gd.init) + if gd.dirs == nil { + // We couldn't find the gccgo search directories. + // Best guess, since the first component did not contain + // '.', is that this is a standard library package. + return true + } + + for _, dir := range gd.dirs { + full := filepath.Join(dir, path) + pkgdir, pkg := filepath.Split(full) + for _, p := range [...]string{ + full, + full + ".gox", + pkgdir + "lib" + pkg + ".so", + pkgdir + "lib" + pkg + ".a", + full + ".o", + } { + if fi, err := os.Stat(p); err == nil && !fi.IsDir() { + return true + } + } + } + + return false +} diff --git a/src/internal/goroot/gccgo.go b/src/internal/goroot/gccgo.go new file mode 100644 index 0000000000000..098e77d893f4b --- /dev/null +++ b/src/internal/goroot/gccgo.go @@ -0,0 +1,27 @@ +// Copyright 2018 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. + +// +build gccgo + +package goroot + +import ( + "os" + "path/filepath" +) + +// IsStandardPackage returns whether path is a standard package, +// given goroot and compiler. +func IsStandardPackage(goroot, compiler, path string) bool { + switch compiler { + case "gc": + dir := filepath.Join(goroot, "src", path) + _, err := os.Stat(dir) + return err == nil + case "gccgo": + return stdpkg[path] + default: + panic("unknown compiler " + compiler) + } +} From 93ad702251e3b72bb90df5d7c29204e0edef4351 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 25 Sep 2018 13:01:27 -0700 Subject: [PATCH 0453/1663] cmd/go: use internal/goroot to check for a standard library package Change-Id: I739728f976162a0b8425a93666e3694d967dceb7 Reviewed-on: https://go-review.googlesource.com/137436 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/cmd/go/internal/modload/build.go | 11 +++++------ src/cmd/go/internal/modload/import.go | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cmd/go/internal/modload/build.go b/src/cmd/go/internal/modload/build.go index 06636c4f4ff42..acee4a91e7ce3 100644 --- a/src/cmd/go/internal/modload/build.go +++ b/src/cmd/go/internal/modload/build.go @@ -14,6 +14,7 @@ import ( "cmd/go/internal/search" "encoding/hex" "fmt" + "internal/goroot" "os" "path/filepath" "strings" @@ -30,13 +31,11 @@ func isStandardImportPath(path string) bool { func findStandardImportPath(path string) string { if search.IsStandardImportPath(path) { - dir := filepath.Join(cfg.GOROOT, "src", path) - if _, err := os.Stat(dir); err == nil { - return dir + if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, path) { + return filepath.Join(cfg.GOROOT, "src", path) } - dir = filepath.Join(cfg.GOROOT, "src/vendor", path) - if _, err := os.Stat(dir); err == nil { - return dir + if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, "vendor/"+path) { + return filepath.Join(cfg.GOROOT, "src/vendor", path) } } return "" diff --git a/src/cmd/go/internal/modload/import.go b/src/cmd/go/internal/modload/import.go index 12d9407f6e696..44c2a2372670b 100644 --- a/src/cmd/go/internal/modload/import.go +++ b/src/cmd/go/internal/modload/import.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "go/build" + "internal/goroot" "os" "path/filepath" "strings" @@ -60,8 +61,8 @@ func Import(path string) (m module.Version, dir string, err error) { if strings.HasPrefix(path, "golang_org/") { return module.Version{}, filepath.Join(cfg.GOROOT, "src/vendor", path), nil } - dir := filepath.Join(cfg.GOROOT, "src", path) - if _, err := os.Stat(dir); err == nil { + if goroot.IsStandardPackage(cfg.GOROOT, cfg.BuildContext.Compiler, path) { + dir := filepath.Join(cfg.GOROOT, "src", path) return module.Version{}, dir, nil } } From 699da6bd134c22ac174ec1accae9ae8218f873f7 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 25 Sep 2018 15:16:17 -0700 Subject: [PATCH 0454/1663] go/build: support Import of local import path in standard library for gccgo It's possible for a local import path to refer to a standard library package. This was not being correctly handled for gccgo. When using gccgo, change the code to permit the existing lexical test, and to accept a missing directory for a standard package found via a local impor path. Change-Id: Ia9829e55c0ff62e7d1f01a1d6dc9fcff521501ca Reviewed-on: https://go-review.googlesource.com/137439 Run-TryBot: Ian Lance Taylor Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/go/build/build.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/go/build/build.go b/src/go/build/build.go index 14b007c25a7a5..fc8d37789f8ee 100644 --- a/src/go/build/build.go +++ b/src/go/build/build.go @@ -544,7 +544,7 @@ func (ctxt *Context) Import(path string, srcDir string, mode ImportMode) (*Packa inTestdata := func(sub string) bool { return strings.Contains(sub, "/testdata/") || strings.HasSuffix(sub, "/testdata") || strings.HasPrefix(sub, "testdata/") || sub == "testdata" } - if ctxt.GOROOT != "" && ctxt.Compiler != "gccgo" { + if ctxt.GOROOT != "" { root := ctxt.joinPath(ctxt.GOROOT, "src") if sub, ok := ctxt.hasSubdir(root, p.Dir); ok && !inTestdata(sub) { p.Goroot = true @@ -715,6 +715,11 @@ Found: // non-nil *Package returned when an error occurs. // We need to do this before we return early on FindOnly flag. if IsLocalImport(path) && !ctxt.isDir(p.Dir) { + if ctxt.Compiler == "gccgo" && p.Goroot { + // gccgo has no sources for GOROOT packages. + return p, nil + } + // package was not found return p, fmt.Errorf("cannot find package %q in:\n\t%s", path, p.Dir) } From 4a0dad211c2158e8763c6fd230fbdc1c7d566cb9 Mon Sep 17 00:00:00 2001 From: Michael McLoughlin Date: Sun, 23 Sep 2018 20:29:33 -0700 Subject: [PATCH 0455/1663] crypto/cipher: 8K benchmarks for AES stream modes Some parallelizable cipher modes may achieve peak performance for larger block sizes. For this reason the AES-GCM mode already has an 8K benchmark alongside the 1K version. This change introduces 8K benchmarks for additional AES stream cipher modes. Updates #20967 Change-Id: If97c6fbf31222602dcc200f8f418d95908ec1202 Reviewed-on: https://go-review.googlesource.com/136897 Reviewed-by: Brad Fitzpatrick Reviewed-by: Filippo Valsorda Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/crypto/cipher/benchmark_test.go | 67 ++++++++++------------------- 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/src/crypto/cipher/benchmark_test.go b/src/crypto/cipher/benchmark_test.go index 1a3f1bdfacabe..90d0cd71385fb 100644 --- a/src/crypto/cipher/benchmark_test.go +++ b/src/crypto/cipher/benchmark_test.go @@ -81,70 +81,49 @@ func BenchmarkAESGCMOpen8K(b *testing.B) { benchmarkAESGCMOpen(b, make([]byte, 8*1024)) } -// If we test exactly 1K blocks, we would generate exact multiples of -// the cipher's block size, and the cipher stream fragments would -// always be wordsize aligned, whereas non-aligned is a more typical -// use-case. -const almost1K = 1024 - 5 - -func BenchmarkAESCFBEncrypt1K(b *testing.B) { - buf := make([]byte, almost1K) +func benchmarkAESStream(b *testing.B, mode func(cipher.Block, []byte) cipher.Stream, buf []byte) { b.SetBytes(int64(len(buf))) var key [16]byte var iv [16]byte aes, _ := aes.NewCipher(key[:]) - ctr := cipher.NewCFBEncrypter(aes, iv[:]) + stream := mode(aes, iv[:]) b.ResetTimer() for i := 0; i < b.N; i++ { - ctr.XORKeyStream(buf, buf) + stream.XORKeyStream(buf, buf) } } -func BenchmarkAESCFBDecrypt1K(b *testing.B) { - buf := make([]byte, almost1K) - b.SetBytes(int64(len(buf))) - - var key [16]byte - var iv [16]byte - aes, _ := aes.NewCipher(key[:]) - ctr := cipher.NewCFBDecrypter(aes, iv[:]) +// If we test exactly 1K blocks, we would generate exact multiples of +// the cipher's block size, and the cipher stream fragments would +// always be wordsize aligned, whereas non-aligned is a more typical +// use-case. +const almost1K = 1024 - 5 +const almost8K = 8*1024 - 5 - b.ResetTimer() - for i := 0; i < b.N; i++ { - ctr.XORKeyStream(buf, buf) - } +func BenchmarkAESCFBEncrypt1K(b *testing.B) { + benchmarkAESStream(b, cipher.NewCFBEncrypter, make([]byte, almost1K)) } -func BenchmarkAESOFB1K(b *testing.B) { - buf := make([]byte, almost1K) - b.SetBytes(int64(len(buf))) +func BenchmarkAESCFBDecrypt1K(b *testing.B) { + benchmarkAESStream(b, cipher.NewCFBDecrypter, make([]byte, almost1K)) +} - var key [16]byte - var iv [16]byte - aes, _ := aes.NewCipher(key[:]) - ctr := cipher.NewOFB(aes, iv[:]) +func BenchmarkAESCFBDecrypt8K(b *testing.B) { + benchmarkAESStream(b, cipher.NewCFBDecrypter, make([]byte, almost8K)) +} - b.ResetTimer() - for i := 0; i < b.N; i++ { - ctr.XORKeyStream(buf, buf) - } +func BenchmarkAESOFB1K(b *testing.B) { + benchmarkAESStream(b, cipher.NewOFB, make([]byte, almost1K)) } func BenchmarkAESCTR1K(b *testing.B) { - buf := make([]byte, almost1K) - b.SetBytes(int64(len(buf))) - - var key [16]byte - var iv [16]byte - aes, _ := aes.NewCipher(key[:]) - ctr := cipher.NewCTR(aes, iv[:]) + benchmarkAESStream(b, cipher.NewCTR, make([]byte, almost1K)) +} - b.ResetTimer() - for i := 0; i < b.N; i++ { - ctr.XORKeyStream(buf, buf) - } +func BenchmarkAESCTR8K(b *testing.B) { + benchmarkAESStream(b, cipher.NewCTR, make([]byte, almost8K)) } func BenchmarkAESCBCEncrypt1K(b *testing.B) { From 1058aecf611fc85365f87733f8588ef1cd31c8cd Mon Sep 17 00:00:00 2001 From: Ingo Oeser Date: Wed, 12 Sep 2018 01:16:29 +0200 Subject: [PATCH 0456/1663] net/http: configure http2 transport only once it looks like we should abort trying to configure the http2 transport again, once it has been configured already. Otherwise there will be no effect of these checks and changes, as they will be overridden later again and the disable logic below will have no effect, too. So it really looks like we just forgot a return statement here. Change-Id: Ic99b3bbc662a4e1e1bdbde77681bd1ae597255ad Reviewed-on: https://go-review.googlesource.com/134795 Reviewed-by: Brad Fitzpatrick --- src/net/http/transport.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/net/http/transport.go b/src/net/http/transport.go index ffe4cdc0d6dba..b8788654b769a 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -286,6 +286,7 @@ func (t *Transport) onceSetNextProtoDefaults() { if v := rv.Field(0); v.CanInterface() { if h2i, ok := v.Interface().(h2Transport); ok { t.h2transport = h2i + return } } } From 14e7f174c1bfb80192274b049487716cdde0b4ee Mon Sep 17 00:00:00 2001 From: Tom Thorogood Date: Wed, 26 Sep 2018 11:29:18 +0000 Subject: [PATCH 0457/1663] strings: use Builder in ToUpper and ToLower MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Map was optimized to use Builder in 45c7d80832, which avoided the []byte to string converstion. This left the ToUpper and ToLower ASCII fast path with an extra allocation over Map. name old time/op new time/op delta ToUpper/#00-12 3.59ns ± 4% 3.71ns ± 1% ~ (p=0.056 n=5+5) ToUpper/ONLYUPPER-12 11.8ns ± 2% 10.5ns ± 2% -10.85% (p=0.008 n=5+5) ToUpper/abc-12 31.8ns ± 1% 25.3ns ± 1% -20.40% (p=0.008 n=5+5) ToUpper/AbC123-12 46.2ns ± 7% 31.9ns ± 8% -30.89% (p=0.008 n=5+5) ToUpper/azAZ09_-12 47.1ns ± 8% 32.6ns ± 4% -30.77% (p=0.008 n=5+5) ToUpper/longStrinGwitHmixofsmaLLandcAps-12 137ns ±15% 104ns ±11% -24.11% (p=0.008 n=5+5) ToUpper/longɐstringɐwithɐnonasciiⱯchars-12 231ns ± 1% 228ns ± 1% ~ (p=0.079 n=5+5) ToUpper/ɐɐɐɐɐ-12 207ns ± 3% 206ns ± 1% ~ (p=0.913 n=5+5) ToUpper/a\u0080\U0010ffff-12 90.8ns ± 1% 89.6ns ± 1% -1.30% (p=0.024 n=5+5) ToLower/#00-12 3.59ns ± 1% 4.26ns ± 2% +18.66% (p=0.008 n=5+5) ToLower/abc-12 6.32ns ± 1% 6.62ns ± 1% +4.72% (p=0.008 n=5+5) ToLower/AbC123-12 45.0ns ±13% 31.5ns ± 4% -29.89% (p=0.008 n=5+5) ToLower/azAZ09_-12 48.8ns ± 6% 33.2ns ± 3% -31.91% (p=0.008 n=5+5) ToLower/longStrinGwitHmixofsmaLLandcAps-12 149ns ±13% 98ns ± 8% -34.30% (p=0.008 n=5+5) ToLower/LONGⱯSTRINGⱯWITHⱯNONASCIIⱯCHARS-12 237ns ± 4% 237ns ± 2% ~ (p=0.635 n=5+5) ToLower/ⱭⱭⱭⱭⱭ-12 181ns ± 1% 181ns ± 1% ~ (p=0.762 n=5+5) ToLower/A\u0080\U0010ffff-12 90.6ns ± 1% 92.5ns ± 1% +2.05% (p=0.016 n=5+5) name old alloc/op new alloc/op delta ToUpper/#00-12 0.00B 0.00B ~ (all equal) ToUpper/ONLYUPPER-12 0.00B 0.00B ~ (all equal) ToUpper/abc-12 6.00B ± 0% 3.00B ± 0% -50.00% (p=0.008 n=5+5) ToUpper/AbC123-12 16.0B ± 0% 8.0B ± 0% -50.00% (p=0.008 n=5+5) ToUpper/azAZ09_-12 16.0B ± 0% 8.0B ± 0% -50.00% (p=0.008 n=5+5) ToUpper/longStrinGwitHmixofsmaLLandcAps-12 64.0B ± 0% 32.0B ± 0% -50.00% (p=0.008 n=5+5) ToUpper/longɐstringɐwithɐnonasciiⱯchars-12 48.0B ± 0% 48.0B ± 0% ~ (all equal) ToUpper/ɐɐɐɐɐ-12 48.0B ± 0% 48.0B ± 0% ~ (all equal) ToUpper/a\u0080\U0010ffff-12 16.0B ± 0% 16.0B ± 0% ~ (all equal) ToLower/#00-12 0.00B 0.00B ~ (all equal) ToLower/abc-12 0.00B 0.00B ~ (all equal) ToLower/AbC123-12 16.0B ± 0% 8.0B ± 0% -50.00% (p=0.008 n=5+5) ToLower/azAZ09_-12 16.0B ± 0% 8.0B ± 0% -50.00% (p=0.008 n=5+5) ToLower/longStrinGwitHmixofsmaLLandcAps-12 64.0B ± 0% 32.0B ± 0% -50.00% (p=0.008 n=5+5) ToLower/LONGⱯSTRINGⱯWITHⱯNONASCIIⱯCHARS-12 48.0B ± 0% 48.0B ± 0% ~ (all equal) ToLower/ⱭⱭⱭⱭⱭ-12 32.0B ± 0% 32.0B ± 0% ~ (all equal) ToLower/A\u0080\U0010ffff-12 16.0B ± 0% 16.0B ± 0% ~ (all equal) name old allocs/op new allocs/op delta ToUpper/#00-12 0.00 0.00 ~ (all equal) ToUpper/ONLYUPPER-12 0.00 0.00 ~ (all equal) ToUpper/abc-12 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.008 n=5+5) ToUpper/AbC123-12 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.008 n=5+5) ToUpper/azAZ09_-12 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.008 n=5+5) ToUpper/longStrinGwitHmixofsmaLLandcAps-12 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.008 n=5+5) ToUpper/longɐstringɐwithɐnonasciiⱯchars-12 1.00 ± 0% 1.00 ± 0% ~ (all equal) ToUpper/ɐɐɐɐɐ-12 2.00 ± 0% 2.00 ± 0% ~ (all equal) ToUpper/a\u0080\U0010ffff-12 1.00 ± 0% 1.00 ± 0% ~ (all equal) ToLower/#00-12 0.00 0.00 ~ (all equal) ToLower/abc-12 0.00 0.00 ~ (all equal) ToLower/AbC123-12 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.008 n=5+5) ToLower/azAZ09_-12 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.008 n=5+5) ToLower/longStrinGwitHmixofsmaLLandcAps-12 2.00 ± 0% 1.00 ± 0% -50.00% (p=0.008 n=5+5) ToLower/LONGⱯSTRINGⱯWITHⱯNONASCIIⱯCHARS-12 1.00 ± 0% 1.00 ± 0% ~ (all equal) ToLower/ⱭⱭⱭⱭⱭ-12 1.00 ± 0% 1.00 ± 0% ~ (all equal) ToLower/A\u0080\U0010ffff-12 1.00 ± 0% 1.00 ± 0% ~ (all equal) Updates #26304 Change-Id: I4179e21d5e60d950b925fe3ffc74b376b82812d2 GitHub-Last-Rev: 2c7c3bb75b8fb16fed5f0c8979ee9941675ed6bf GitHub-Pull-Request: golang/go#27872 Reviewed-on: https://go-review.googlesource.com/137575 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/strings/strings.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/strings/strings.go b/src/strings/strings.go index 26aceda2121b1..b033c38e91e35 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -561,15 +561,16 @@ func ToUpper(s string) string { if !hasLower { return s } - b := make([]byte, len(s)) + var b Builder + b.Grow(len(s)) for i := 0; i < len(s); i++ { c := s[i] if c >= 'a' && c <= 'z' { c -= 'a' - 'A' } - b[i] = c + b.WriteByte(c) } - return string(b) + return b.String() } return Map(unicode.ToUpper, s) } @@ -590,15 +591,16 @@ func ToLower(s string) string { if !hasUpper { return s } - b := make([]byte, len(s)) + var b Builder + b.Grow(len(s)) for i := 0; i < len(s); i++ { c := s[i] if c >= 'A' && c <= 'Z' { c += 'a' - 'A' } - b[i] = c + b.WriteByte(c) } - return string(b) + return b.String() } return Map(unicode.ToLower, s) } From 541f9c0345d4ec52d9f4be5913bf8097f687e819 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Tue, 25 Sep 2018 22:19:47 +0200 Subject: [PATCH 0458/1663] cmd/compile: update TestNexting golden file This change updates the expected output of the gdb debugging session in the TestNexting internal/ssa test, aligning it with the changes introduced in CL 134555. Fixes #27863 Change-Id: I29e747930c7668b429e8936ad230c4d6aa24fdac Reviewed-on: https://go-review.googlesource.com/137455 Reviewed-by: Than McIntosh --- .../internal/ssa/testdata/hist.gdb-opt.nexts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts b/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts index ad2719185e501..6586f243e2f83 100644 --- a/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts +++ b/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts @@ -19,7 +19,7 @@ dy = 65: if len(os.Args) > 1 { 73: scanner := bufio.NewScanner(reader) 74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (struct bufio.Scanner *) +scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) @@ -29,7 +29,7 @@ i = 1 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ 74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (struct bufio.Scanner *) +scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) @@ -39,7 +39,7 @@ i = 1 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ 74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (struct bufio.Scanner *) +scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) @@ -49,7 +49,7 @@ i = 1 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ 74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (struct bufio.Scanner *) +scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) @@ -59,7 +59,7 @@ i = 2 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ 74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (struct bufio.Scanner *) +scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) @@ -69,7 +69,7 @@ i = 2 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ 74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (struct bufio.Scanner *) +scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) @@ -79,7 +79,7 @@ i = 2 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ 74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (struct bufio.Scanner *) +scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) @@ -89,7 +89,7 @@ i = 4 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ 74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (struct bufio.Scanner *) +scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) @@ -99,7 +99,7 @@ i = 4 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ 74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (struct bufio.Scanner *) +scanner = (bufio.Scanner *) 75: s := scanner.Text() 76: i, err := strconv.ParseInt(s, 10, 64) 77: if err != nil { //gdb-dbg=(i) //gdb-opt=(err,hist,i) @@ -109,7 +109,7 @@ i = 5 81: hist = ensure(int(i), hist) 82: hist[int(i)]++ 74: for scanner.Scan() { //gdb-opt=(scanner/A) -scanner = (struct bufio.Scanner *) +scanner = (bufio.Scanner *) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) a = 0 From b50210f5719c15cd512857e2e29e1de152155b35 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 26 Sep 2018 17:54:47 +0000 Subject: [PATCH 0459/1663] Revert "net/url: escape URL.RawQuery on Parse if it contains invalid characters" This reverts commit CL 99135 (git rev 1040626c0ce4a1bc2b312aa0866ffeb2ff53c1ab). Reason for revert: breaks valid code; see #27302 Fixes #27302 Updates #22907 Change-Id: I82bb0c28ae1683140c71e7a2224c4ded3f4acea1 Reviewed-on: https://go-review.googlesource.com/137716 Reviewed-by: Ian Lance Taylor --- src/net/url/url.go | 51 +---------------------------------------- src/net/url/url_test.go | 11 --------- 2 files changed, 1 insertion(+), 61 deletions(-) diff --git a/src/net/url/url.go b/src/net/url/url.go index b678b82352e05..702f9124bfe8d 100644 --- a/src/net/url/url.go +++ b/src/net/url/url.go @@ -534,13 +534,7 @@ func parse(rawurl string, viaRequest bool) (*URL, error) { url.ForceQuery = true rest = rest[:len(rest)-1] } else { - var q string - rest, q = split(rest, "?", true) - if validQuery(q) { - url.RawQuery = q - } else { - url.RawQuery = QueryEscape(q) - } + rest, url.RawQuery = split(rest, "?", true) } if !strings.HasPrefix(rest, "/") { @@ -1139,46 +1133,3 @@ func validUserinfo(s string) bool { } return true } - -// validQuery reports whether s is a valid query string per RFC 3986 -// Section 3.4: -// query = *( pchar / "/" / "?" ) -// pchar = unreserved / pct-encoded / sub-delims / ":" / "@" -// unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" -// sub-delims = "!" / "$" / "&" / "'" / "(" / ")" -// / "*" / "+" / "," / ";" / "=" -func validQuery(s string) bool { - pctEnc := 0 - - for _, r := range s { - if pctEnc > 0 { - if uint32(r) > 255 || !ishex(byte(r)) { - return false - } - pctEnc-- - continue - } else if r == '%' { - pctEnc = 2 - continue - } - - if 'A' <= r && r <= 'Z' { - continue - } - if 'a' <= r && r <= 'z' { - continue - } - if '0' <= r && r <= '9' { - continue - } - switch r { - case '-', '.', '_', '~', '!', '$', '&', '\'', '(', ')', - '*', '+', ',', ';', '=', ':', '@', '/', '?': - continue - default: - return false - } - } - - return true -} diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go index 231340a9eb89d..5d3f91248f42e 100644 --- a/src/net/url/url_test.go +++ b/src/net/url/url_test.go @@ -590,16 +590,6 @@ var urltests = []URLTest{ }, "mailto:?subject=hi", }, - { - "https://example.com/search?q=Фотки собак&source=lnms", - &URL{ - Scheme: "https", - Host: "example.com", - Path: "/search", - RawQuery: "q%3D%D0%A4%D0%BE%D1%82%D0%BA%D0%B8+%D1%81%D0%BE%D0%B1%D0%B0%D0%BA%26source%3Dlnms", - }, - "https://example.com/search?q%3D%D0%A4%D0%BE%D1%82%D0%BA%D0%B8+%D1%81%D0%BE%D0%B1%D0%B0%D0%BA%26source%3Dlnms", - }, } // more useful string for debugging than fmt's struct printer @@ -1449,7 +1439,6 @@ func TestParseErrors(t *testing.T) { {"cache_object:foo", true}, {"cache_object:foo/bar", true}, {"cache_object/:foo/bar", false}, - {"https://example.com/search?q=Фотки собак&source=lnms", false}, } for _, tt := range tests { u, err := Parse(tt.in) From 9eb53ab9bc3b89d960c23ab47b3d7bc3fc201fd7 Mon Sep 17 00:00:00 2001 From: Brian Kessler Date: Tue, 14 Aug 2018 16:41:22 -0600 Subject: [PATCH 0460/1663] cmd/compile: intrinsify math/bits.Mul MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add SSA rules to intrinsify Mul/Mul64 (AMD64 and ARM64). SSA rules for other functions and architectures are left as a future optimization. Benchmark results on AMD64/ARM64 before and after SSA implementation are below. amd64 name old time/op new time/op delta Add-4 1.78ns ± 0% 1.85ns ±12% ~ (p=0.397 n=4+5) Add32-4 1.71ns ± 1% 1.70ns ± 0% ~ (p=0.683 n=5+5) Add64-4 1.80ns ± 2% 1.77ns ± 0% -1.22% (p=0.048 n=5+5) Sub-4 1.78ns ± 0% 1.78ns ± 0% ~ (all equal) Sub32-4 1.78ns ± 1% 1.78ns ± 0% ~ (p=1.000 n=5+5) Sub64-4 1.78ns ± 1% 1.78ns ± 0% ~ (p=0.968 n=5+4) Mul-4 11.5ns ± 1% 1.8ns ± 2% -84.39% (p=0.008 n=5+5) Mul32-4 1.39ns ± 0% 1.38ns ± 3% ~ (p=0.175 n=5+5) Mul64-4 6.85ns ± 1% 1.78ns ± 1% -73.97% (p=0.008 n=5+5) Div-4 57.1ns ± 1% 56.7ns ± 0% ~ (p=0.087 n=5+5) Div32-4 18.0ns ± 0% 18.0ns ± 0% ~ (all equal) Div64-4 56.4ns ±10% 53.6ns ± 1% ~ (p=0.071 n=5+5) arm64 name old time/op new time/op delta Add-96 5.51ns ± 0% 5.51ns ± 0% ~ (all equal) Add32-96 5.51ns ± 0% 5.51ns ± 0% ~ (all equal) Add64-96 5.52ns ± 0% 5.51ns ± 0% ~ (p=0.444 n=5+5) Sub-96 5.51ns ± 0% 5.51ns ± 0% ~ (all equal) Sub32-96 5.51ns ± 0% 5.51ns ± 0% ~ (all equal) Sub64-96 5.51ns ± 0% 5.51ns ± 0% ~ (all equal) Mul-96 34.6ns ± 0% 5.0ns ± 0% -85.52% (p=0.008 n=5+5) Mul32-96 4.51ns ± 0% 4.51ns ± 0% ~ (all equal) Mul64-96 21.1ns ± 0% 5.0ns ± 0% -76.26% (p=0.008 n=5+5) Div-96 64.7ns ± 0% 64.7ns ± 0% ~ (all equal) Div32-96 17.0ns ± 0% 17.0ns ± 0% ~ (all equal) Div64-96 53.1ns ± 0% 53.1ns ± 0% ~ (all equal) Updates #24813 Change-Id: I9bda6d2102f65cae3d436a2087b47ed8bafeb068 Reviewed-on: https://go-review.googlesource.com/129415 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/gc/ssa.go | 6 ++++++ test/codegen/mathbits.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/cmd/compile/internal/gc/ssa.go b/src/cmd/compile/internal/gc/ssa.go index 2ee966d890f85..8df8023d18bec 100644 --- a/src/cmd/compile/internal/gc/ssa.go +++ b/src/cmd/compile/internal/gc/ssa.go @@ -3435,6 +3435,12 @@ func init() { addF("math/bits", "OnesCount", makeOnesCountAMD64(ssa.OpPopCount64, ssa.OpPopCount32), sys.AMD64) + alias("math/bits", "Mul", "math/bits", "Mul64", sys.ArchAMD64, sys.ArchARM64) + addF("math/bits", "Mul64", + func(s *state, n *Node, args []*ssa.Value) *ssa.Value { + return s.newValue2(ssa.OpMul64uhilo, types.NewTuple(types.Types[TUINT64], types.Types[TUINT64]), args[0], args[1]) + }, + sys.AMD64, sys.ARM64) /******** sync/atomic ********/ diff --git a/test/codegen/mathbits.go b/test/codegen/mathbits.go index 28354ed65175c..834b08f1015b0 100644 --- a/test/codegen/mathbits.go +++ b/test/codegen/mathbits.go @@ -302,3 +302,19 @@ func IterateBits8(n uint8) int { } return i } + +// --------------- // +// bits.Mul* // +// --------------- // + +func Mul(x, y uint) (hi, lo uint) { + // amd64:"MULQ" + // arm64:"UMULH","MUL" + return bits.Mul(x, y) +} + +func Mul64(x, y uint64) (hi, lo uint64) { + // amd64:"MULQ" + // arm64:"UMULH","MUL" + return bits.Mul64(x, y) +} From 5a8c11ce3e7a87485defafb78c7bcf14f9d7b5a2 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 26 Sep 2018 16:39:02 -0400 Subject: [PATCH 0461/1663] runtime: rename _MSpan* constants to mSpan* We already aliased mSpanInUse to _MSpanInUse. The dual constants are getting annoying, so fix all of these to use the mSpan* naming convention. This was done automatically with: sed -i -re 's/_?MSpan(Dead|InUse|Manual|Free)/mSpan\1/g' *.go plus deleting the existing definition of mSpanInUse. Change-Id: I09979d9d491d06c10689cea625dc57faa9cc6767 Reviewed-on: https://go-review.googlesource.com/137875 Run-TryBot: Austin Clements Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/runtime/cgocheck.go | 2 +- src/runtime/heapdump.go | 8 ++--- src/runtime/malloc.go | 2 -- src/runtime/mbitmap.go | 4 +-- src/runtime/mgcmark.go | 6 ++-- src/runtime/mgcsweep.go | 2 +- src/runtime/mheap.go | 64 ++++++++++++++++----------------- src/runtime/mstats.go | 2 +- src/runtime/runtime-gdb_test.go | 2 +- src/runtime/stack.go | 4 +-- 10 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/runtime/cgocheck.go b/src/runtime/cgocheck.go index 73cb6ecae2b49..ac57e0344eea6 100644 --- a/src/runtime/cgocheck.go +++ b/src/runtime/cgocheck.go @@ -126,7 +126,7 @@ func cgoCheckTypedBlock(typ *_type, src unsafe.Pointer, off, size uintptr) { } s := spanOfUnchecked(uintptr(src)) - if s.state == _MSpanManual { + if s.state == mSpanManual { // There are no heap bits for value stored on the stack. // For a channel receive src might be on the stack of some // other goroutine, so we can't unwind the stack even if diff --git a/src/runtime/heapdump.go b/src/runtime/heapdump.go index 0fc02a8e8068b..e2c6f18714d1e 100644 --- a/src/runtime/heapdump.go +++ b/src/runtime/heapdump.go @@ -430,7 +430,7 @@ func dumproots() { // MSpan.types for _, s := range mheap_.allspans { - if s.state == _MSpanInUse { + if s.state == mSpanInUse { // Finalizers for sp := s.specials; sp != nil; sp = sp.next { if sp.kind != _KindSpecialFinalizer { @@ -453,7 +453,7 @@ var freemark [_PageSize / 8]bool func dumpobjs() { for _, s := range mheap_.allspans { - if s.state != _MSpanInUse { + if s.state != mSpanInUse { continue } p := s.base() @@ -616,7 +616,7 @@ func dumpmemprof_callback(b *bucket, nstk uintptr, pstk *uintptr, size, allocs, func dumpmemprof() { iterate_memprof(dumpmemprof_callback) for _, s := range mheap_.allspans { - if s.state != _MSpanInUse { + if s.state != mSpanInUse { continue } for sp := s.specials; sp != nil; sp = sp.next { @@ -637,7 +637,7 @@ var dumphdr = []byte("go1.7 heap dump\n") func mdump() { // make sure we're done sweeping for _, s := range mheap_.allspans { - if s.state == _MSpanInUse { + if s.state == mSpanInUse { s.ensureSwept() } } diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index c6c969a3bf008..dd88d353ddc7b 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -124,8 +124,6 @@ const ( // have the most objects per span. maxObjsPerSpan = pageSize / 8 - mSpanInUse = _MSpanInUse - concurrentSweep = _ConcurrentSweep _PageSize = 1 << _PageShift diff --git a/src/runtime/mbitmap.go b/src/runtime/mbitmap.go index e217e7695fdd4..553d83f7f2da8 100644 --- a/src/runtime/mbitmap.go +++ b/src/runtime/mbitmap.go @@ -365,7 +365,7 @@ func findObject(p, refBase, refOff uintptr) (base uintptr, s *mspan, objIndex ui s = spanOf(p) // If p is a bad pointer, it may not be in s's bounds. if s == nil || p < s.base() || p >= s.limit || s.state != mSpanInUse { - if s == nil || s.state == _MSpanManual { + if s == nil || s.state == mSpanManual { // If s is nil, the virtual address has never been part of the heap. // This pointer may be to some mmap'd region, so we allow it. // Pointers into stacks are also ok, the runtime manages these explicitly. @@ -611,7 +611,7 @@ func bulkBarrierPreWrite(dst, src, size uintptr) { } } return - } else if s.state != _MSpanInUse || dst < s.base() || s.limit <= dst { + } else if s.state != mSpanInUse || dst < s.base() || s.limit <= dst { // dst was heap memory at some point, but isn't now. // It can't be a global. It must be either our stack, // or in the case of direct channel sends, it could be diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index 69ff895512faa..f713841cfa856 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -1239,7 +1239,7 @@ func gcDumpObject(label string, obj, off uintptr) { skipped := false size := s.elemsize - if s.state == _MSpanManual && size == 0 { + if s.state == mSpanManual && size == 0 { // We're printing something from a stack frame. We // don't know how big it is, so just show up to an // including off. @@ -1335,7 +1335,7 @@ var useCheckmark = false func initCheckmarks() { useCheckmark = true for _, s := range mheap_.allspans { - if s.state == _MSpanInUse { + if s.state == mSpanInUse { heapBitsForAddr(s.base()).initCheckmarkSpan(s.layout()) } } @@ -1344,7 +1344,7 @@ func initCheckmarks() { func clearCheckmarks() { useCheckmark = false for _, s := range mheap_.allspans { - if s.state == _MSpanInUse { + if s.state == mSpanInUse { heapBitsForAddr(s.base()).clearCheckmarkSpan(s.layout()) } } diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go index 71f5c4b3a9dcb..ecfdee59f483b 100644 --- a/src/runtime/mgcsweep.go +++ b/src/runtime/mgcsweep.go @@ -159,7 +159,7 @@ func (s *mspan) ensureSwept() { if atomic.Load(&s.sweepgen) == sg { return } - // The caller must be sure that the span is a MSpanInUse span. + // The caller must be sure that the span is a mSpanInUse span. if atomic.Cas(&s.sweepgen, sg-2, sg-1) { s.sweep(false) return diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index 00ecfa2d66cb6..65d6b0c7d44b7 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -82,7 +82,7 @@ type mheap struct { // accounting for current progress. If we could only adjust // the slope, it would create a discontinuity in debt if any // progress has already been made. - pagesInUse uint64 // pages of spans in stats _MSpanInUse; R/W with mheap.lock + pagesInUse uint64 // pages of spans in stats mSpanInUse; R/W with mheap.lock pagesSwept uint64 // pages swept this cycle; updated atomically pagesSweptBasis uint64 // pagesSwept to use as the origin of the sweep ratio; updated atomically sweepHeapLiveBasis uint64 // value of heap_live to use as the origin of sweep ratio; written with lock, read without @@ -199,18 +199,18 @@ type arenaHint struct { // An MSpan is a run of pages. // -// When a MSpan is in the heap free list, state == MSpanFree +// When a MSpan is in the heap free list, state == mSpanFree // and heapmap(s->start) == span, heapmap(s->start+s->npages-1) == span. // -// When a MSpan is allocated, state == MSpanInUse or MSpanManual +// When a MSpan is allocated, state == mSpanInUse or mSpanManual // and heapmap(i) == span for all s->start <= i < s->start+s->npages. // Every MSpan is in one doubly-linked list, // either one of the MHeap's free lists or one of the // MCentral's span lists. -// An MSpan representing actual memory has state _MSpanInUse, -// _MSpanManual, or _MSpanFree. Transitions between these states are +// An MSpan representing actual memory has state mSpanInUse, +// mSpanManual, or mSpanFree. Transitions between these states are // constrained as follows: // // * A span may transition from free to in-use or manual during any GC @@ -226,19 +226,19 @@ type arenaHint struct { type mSpanState uint8 const ( - _MSpanDead mSpanState = iota - _MSpanInUse // allocated for garbage collected heap - _MSpanManual // allocated for manual management (e.g., stack allocator) - _MSpanFree + mSpanDead mSpanState = iota + mSpanInUse // allocated for garbage collected heap + mSpanManual // allocated for manual management (e.g., stack allocator) + mSpanFree ) // mSpanStateNames are the names of the span states, indexed by // mSpanState. var mSpanStateNames = []string{ - "_MSpanDead", - "_MSpanInUse", - "_MSpanManual", - "_MSpanFree", + "mSpanDead", + "mSpanInUse", + "mSpanManual", + "mSpanFree", } // mSpanList heads a linked list of spans. @@ -258,7 +258,7 @@ type mspan struct { startAddr uintptr // address of first byte of span aka s.base() npages uintptr // number of pages in span - manualFreeList gclinkptr // list of free objects in _MSpanManual spans + manualFreeList gclinkptr // list of free objects in mSpanManual spans // freeindex is the slot index between 0 and nelems at which to begin scanning // for the next free object in this span. @@ -458,7 +458,7 @@ func (i arenaIdx) l2() uint { } // inheap reports whether b is a pointer into a (potentially dead) heap object. -// It returns false for pointers into _MSpanManual spans. +// It returns false for pointers into mSpanManual spans. // Non-preemptible because it is used by write barriers. //go:nowritebarrier //go:nosplit @@ -477,7 +477,7 @@ func inHeapOrStack(b uintptr) bool { return false } switch s.state { - case mSpanInUse, _MSpanManual: + case mSpanInUse, mSpanManual: return b < s.limit default: return false @@ -696,7 +696,7 @@ func (h *mheap) alloc_m(npage uintptr, spanclass spanClass, large bool) *mspan { // able to map interior pointer to containing span. atomic.Store(&s.sweepgen, h.sweepgen) h.sweepSpans[h.sweepgen/2%2].push(s) // Add to swept in-use list. - s.state = _MSpanInUse + s.state = mSpanInUse s.allocCount = 0 s.spanclass = spanclass if sizeclass := spanclass.sizeclass(); sizeclass == 0 { @@ -788,7 +788,7 @@ func (h *mheap) allocManual(npage uintptr, stat *uint64) *mspan { lock(&h.lock) s := h.allocSpanLocked(npage, stat) if s != nil { - s.state = _MSpanManual + s.state = mSpanManual s.manualFreeList = 0 s.allocCount = 0 s.spanclass = 0 @@ -829,7 +829,7 @@ func (h *mheap) setSpans(base, npage uintptr, s *mspan) { // Allocates a span of the given size. h must be locked. // The returned span has been removed from the -// free list, but its state is still MSpanFree. +// free list, but its state is still mSpanFree. func (h *mheap) allocSpanLocked(npage uintptr, stat *uint64) *mspan { var list *mSpanList var s *mspan @@ -857,7 +857,7 @@ func (h *mheap) allocSpanLocked(npage uintptr, stat *uint64) *mspan { HaveSpan: // Mark span in use. - if s.state != _MSpanFree { + if s.state != mSpanFree { throw("MHeap_AllocLocked - MSpan not free") } if s.npages < npage { @@ -878,10 +878,10 @@ HaveSpan: h.setSpan(t.base(), t) h.setSpan(t.base()+t.npages*pageSize-1, t) t.needzero = s.needzero - s.state = _MSpanManual // prevent coalescing with s - t.state = _MSpanManual + s.state = mSpanManual // prevent coalescing with s + t.state = mSpanManual h.freeSpanLocked(t, false, false, s.unusedsince) - s.state = _MSpanFree + s.state = mSpanFree } s.unusedsince = 0 @@ -930,7 +930,7 @@ func (h *mheap) grow(npage uintptr) bool { s.init(uintptr(v), size/pageSize) h.setSpans(s.base(), s.npages, s) atomic.Store(&s.sweepgen, h.sweepgen) - s.state = _MSpanInUse + s.state = mSpanInUse h.pagesInUse += uint64(s.npages) h.freeSpanLocked(s, false, true, 0) return true @@ -986,11 +986,11 @@ func (h *mheap) freeManual(s *mspan, stat *uint64) { // s must be on a busy list (h.busy or h.busylarge) or unlinked. func (h *mheap) freeSpanLocked(s *mspan, acctinuse, acctidle bool, unusedsince int64) { switch s.state { - case _MSpanManual: + case mSpanManual: if s.allocCount != 0 { throw("MHeap_FreeSpanLocked - invalid stack free") } - case _MSpanInUse: + case mSpanInUse: if s.allocCount != 0 || s.sweepgen != h.sweepgen { print("MHeap_FreeSpanLocked - span ", s, " ptr ", hex(s.base()), " allocCount ", s.allocCount, " sweepgen ", s.sweepgen, "/", h.sweepgen, "\n") throw("MHeap_FreeSpanLocked - invalid free") @@ -1006,7 +1006,7 @@ func (h *mheap) freeSpanLocked(s *mspan, acctinuse, acctidle bool, unusedsince i if acctidle { memstats.heap_idle += uint64(s.npages << _PageShift) } - s.state = _MSpanFree + s.state = mSpanFree if s.inList() { h.busyList(s.npages).remove(s) } @@ -1020,7 +1020,7 @@ func (h *mheap) freeSpanLocked(s *mspan, acctinuse, acctidle bool, unusedsince i s.npreleased = 0 // Coalesce with earlier, later spans. - if before := spanOf(s.base() - 1); before != nil && before.state == _MSpanFree { + if before := spanOf(s.base() - 1); before != nil && before.state == mSpanFree { // Now adjust s. s.startAddr = before.startAddr s.npages += before.npages @@ -1035,12 +1035,12 @@ func (h *mheap) freeSpanLocked(s *mspan, acctinuse, acctidle bool, unusedsince i } else { h.freeList(before.npages).remove(before) } - before.state = _MSpanDead + before.state = mSpanDead h.spanalloc.free(unsafe.Pointer(before)) } // Now check to see if next (greater addresses) span is free and can be coalesced. - if after := spanOf(s.base() + s.npages*pageSize); after != nil && after.state == _MSpanFree { + if after := spanOf(s.base() + s.npages*pageSize); after != nil && after.state == mSpanFree { s.npages += after.npages s.npreleased += after.npreleased s.needzero |= after.needzero @@ -1050,7 +1050,7 @@ func (h *mheap) freeSpanLocked(s *mspan, acctinuse, acctidle bool, unusedsince i } else { h.freeList(after.npages).remove(after) } - after.state = _MSpanDead + after.state = mSpanDead h.spanalloc.free(unsafe.Pointer(after)) } @@ -1187,7 +1187,7 @@ func (span *mspan) init(base uintptr, npages uintptr) { span.spanclass = 0 span.incache = false span.elemsize = 0 - span.state = _MSpanDead + span.state = mSpanDead span.unusedsince = 0 span.npreleased = 0 span.speciallock.key = 0 diff --git a/src/runtime/mstats.go b/src/runtime/mstats.go index f67d05414daf2..1bd65660520b7 100644 --- a/src/runtime/mstats.go +++ b/src/runtime/mstats.go @@ -38,7 +38,7 @@ type mstats struct { heap_alloc uint64 // bytes allocated and not yet freed (same as alloc above) heap_sys uint64 // virtual address space obtained from system for GC'd heap heap_idle uint64 // bytes in idle spans - heap_inuse uint64 // bytes in _MSpanInUse spans + heap_inuse uint64 // bytes in mSpanInUse spans heap_released uint64 // bytes released to the os heap_objects uint64 // total number of allocated objects diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go index d9c6f6d22a24b..1ed6b3930384e 100644 --- a/src/runtime/runtime-gdb_test.go +++ b/src/runtime/runtime-gdb_test.go @@ -484,7 +484,7 @@ func TestGdbConst(t *testing.T) { "-ex", "print main.aConstant", "-ex", "print main.largeConstant", "-ex", "print main.minusOne", - "-ex", "print 'runtime._MSpanInUse'", + "-ex", "print 'runtime.mSpanInUse'", "-ex", "print 'runtime._PageSize'", filepath.Join(dir, "a.exe"), } diff --git a/src/runtime/stack.go b/src/runtime/stack.go index c7bfc0434bae4..d56b864c5ec44 100644 --- a/src/runtime/stack.go +++ b/src/runtime/stack.go @@ -211,7 +211,7 @@ func stackpoolalloc(order uint8) gclinkptr { // Adds stack x to the free pool. Must be called with stackpoolmu held. func stackpoolfree(x gclinkptr, order uint8) { s := spanOfUnchecked(uintptr(x)) - if s.state != _MSpanManual { + if s.state != mSpanManual { throw("freeing stack not in a stack span") } if s.manualFreeList.ptr() == nil { @@ -459,7 +459,7 @@ func stackfree(stk stack) { } } else { s := spanOfUnchecked(uintptr(v)) - if s.state != _MSpanManual { + if s.state != mSpanManual { println(hex(s.base()), v) throw("bad span state") } From ebdc0b8d68e04ad383088c8b3ab963de4a9b5c5d Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 26 Sep 2018 20:19:11 +0000 Subject: [PATCH 0462/1663] bytes, strings: add ReplaceAll Credit to Harald Nordgren for the proposal in https://golang.org/cl/137456 and #27864. Fixes #27864 Change-Id: I80546683b0623124fe4627a71af88add2f6c1c27 Reviewed-on: https://go-review.googlesource.com/137855 Reviewed-by: Ian Lance Taylor --- src/bytes/bytes.go | 9 +++++++++ src/bytes/bytes_test.go | 6 ++++++ src/strings/strings.go | 9 +++++++++ src/strings/strings_test.go | 6 ++++++ 4 files changed, 30 insertions(+) diff --git a/src/bytes/bytes.go b/src/bytes/bytes.go index 876fa3c1edda6..6492db088a056 100644 --- a/src/bytes/bytes.go +++ b/src/bytes/bytes.go @@ -774,6 +774,15 @@ func Replace(s, old, new []byte, n int) []byte { return t[0:w] } +// ReplaceAll returns a copy of the slice s with all +// non-overlapping instances of old replaced by new. +// If old is empty, it matches at the beginning of the slice +// and after each UTF-8 sequence, yielding up to k+1 replacements +// for a k-rune slice. +func ReplaceAll(s, old, new []byte) []byte { + return Replace(s, old, new, -1) +} + // EqualFold reports whether s and t, interpreted as UTF-8 strings, // are equal under Unicode case-folding. func EqualFold(s, t []byte) bool { diff --git a/src/bytes/bytes_test.go b/src/bytes/bytes_test.go index 55a22bae22a1d..f4c0ffd2a91f7 100644 --- a/src/bytes/bytes_test.go +++ b/src/bytes/bytes_test.go @@ -1362,6 +1362,12 @@ func TestReplace(t *testing.T) { if cap(in) == cap(out) && &in[:1][0] == &out[:1][0] { t.Errorf("Replace(%q, %q, %q, %d) didn't copy", tt.in, tt.old, tt.new, tt.n) } + if tt.n == -1 { + out := ReplaceAll(in, []byte(tt.old), []byte(tt.new)) + if s := string(out); s != tt.out { + t.Errorf("ReplaceAll(%q, %q, %q) = %q, want %q", tt.in, tt.old, tt.new, s, tt.out) + } + } } } diff --git a/src/strings/strings.go b/src/strings/strings.go index b033c38e91e35..00200e4e24df0 100644 --- a/src/strings/strings.go +++ b/src/strings/strings.go @@ -874,6 +874,15 @@ func Replace(s, old, new string, n int) string { return string(t[0:w]) } +// ReplaceAll returns a copy of the string s with all +// non-overlapping instances of old replaced by new. +// If old is empty, it matches at the beginning of the string +// and after each UTF-8 sequence, yielding up to k+1 replacements +// for a k-rune string. +func ReplaceAll(s, old, new string) string { + return Replace(s, old, new, -1) +} + // EqualFold reports whether s and t, interpreted as UTF-8 strings, // are equal under Unicode case-folding. func EqualFold(s, t string) bool { diff --git a/src/strings/strings_test.go b/src/strings/strings_test.go index 20bc484f3950b..bb6a5b931b85d 100644 --- a/src/strings/strings_test.go +++ b/src/strings/strings_test.go @@ -1243,6 +1243,12 @@ func TestReplace(t *testing.T) { if s := Replace(tt.in, tt.old, tt.new, tt.n); s != tt.out { t.Errorf("Replace(%q, %q, %q, %d) = %q, want %q", tt.in, tt.old, tt.new, tt.n, s, tt.out) } + if tt.n == -1 { + s := ReplaceAll(tt.in, tt.old, tt.new) + if s != tt.out { + t.Errorf("ReplaceAll(%q, %q, %q) = %q, want %q", tt.in, tt.old, tt.new, s, tt.out) + } + } } } From e35a41261b19589f40d32bd66274c23ab4b9b32e Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 25 Sep 2018 14:32:44 -0700 Subject: [PATCH 0463/1663] reflect: use correct write barrier operations for method funcs Fix the code to use write barriers on heap memory, and no write barriers on stack memory. These errors were discoverd as part of fixing #27695. They may have something to do with that issue, but hard to be sure. The core cause is different, so this fix is a separate CL. Update #27695 Change-Id: Ib005f6b3308de340be83c3d07d049d5e316b1e3c Reviewed-on: https://go-review.googlesource.com/137438 Reviewed-by: Austin Clements --- src/reflect/type.go | 2 ++ src/reflect/value.go | 39 ++++++++++++++++++++++++++------------- src/runtime/mbarrier.go | 13 +++++++++++++ 3 files changed, 41 insertions(+), 13 deletions(-) diff --git a/src/reflect/type.go b/src/reflect/type.go index 58cfc0e884035..6b0ce431a6771 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -3066,6 +3066,8 @@ func funcLayout(t *rtype, rcvr *rtype) (frametype *rtype, argSize, retOffset uin // space no matter how big they actually are. if ifaceIndir(rcvr) || rcvr.pointers() { ptrmap.append(1) + } else { + ptrmap.append(0) } offset += ptrSize } diff --git a/src/reflect/value.go b/src/reflect/value.go index 1c3e590377ff6..854a5b153ec87 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -453,15 +453,14 @@ func (v Value) call(op string, in []Value) []Value { var ret []Value if nout == 0 { - // This is untyped because the frame is really a - // stack, even though it's a heap object. - memclrNoHeapPointers(args, frametype.size) + typedmemclr(frametype, args) framePool.Put(args) } else { // Zero the now unused input area of args, // because the Values returned by this function contain pointers to the args object, // and will thus keep the args object alive indefinitely. - memclrNoHeapPointers(args, retOffset) + typedmemclrpartial(frametype, args, 0, retOffset) + // Wrap Values around return values in args. ret = make([]Value, nout) off = retOffset @@ -472,6 +471,10 @@ func (v Value) call(op string, in []Value) []Value { if tv.Size() != 0 { fl := flagIndir | flag(tv.Kind()) ret[i] = Value{tv.common(), add(args, off, "tv.Size() != 0"), fl} + // Note: this does introduce false sharing between results - + // if any result is live, they are all live. + // (And the space for the args is live as well, but as we've + // cleared that space it isn't as big a deal.) } else { // For zero-sized return value, args+off may point to the next object. // In this case, return the zero value instead. @@ -660,6 +663,8 @@ func callMethod(ctxt *methodValue, frame unsafe.Pointer) { } // Call. + // Call copies the arguments from args to the stack, calls fn, + // and then copies the results back into args. call(frametype, fn, args, uint32(frametype.size), uint32(retOffset)) // Copy return values. On amd64p32, the beginning of return values @@ -673,16 +678,14 @@ func callMethod(ctxt *methodValue, frame unsafe.Pointer) { if runtime.GOARCH == "amd64p32" { callerRetOffset = align(argSize-ptrSize, 8) } - typedmemmovepartial(frametype, - add(frame, callerRetOffset, "frametype.size > retOffset"), + // This copies to the stack. Write barriers are not needed. + memmove(add(frame, callerRetOffset, "frametype.size > retOffset"), add(args, retOffset, "frametype.size > retOffset"), - retOffset, frametype.size-retOffset) } - // This is untyped because the frame is really a stack, even - // though it's a heap object. - memclrNoHeapPointers(args, frametype.size) + // Put the args scratch space back in the pool. + typedmemclr(frametype, args) framePool.Put(args) // See the comment in callReflect. @@ -2641,6 +2644,10 @@ func call(argtype *rtype, fn, arg unsafe.Pointer, n uint32, retoffset uint32) func ifaceE2I(t *rtype, src interface{}, dst unsafe.Pointer) +// memmove copies size bytes to dst from src. No write barriers are used. +//go:noescape +func memmove(dst, src unsafe.Pointer, size uintptr) + // typedmemmove copies a value of type t to dst from src. //go:noescape func typedmemmove(t *rtype, dst, src unsafe.Pointer) @@ -2650,14 +2657,20 @@ func typedmemmove(t *rtype, dst, src unsafe.Pointer) //go:noescape func typedmemmovepartial(t *rtype, dst, src unsafe.Pointer, off, size uintptr) +// typedmemclr zeros the value at ptr of type t. +//go:noescape +func typedmemclr(t *rtype, ptr unsafe.Pointer) + +// typedmemclrpartial is like typedmemclr but assumes that +// dst points off bytes into the value and only clears size bytes. +//go:noescape +func typedmemclrpartial(t *rtype, ptr unsafe.Pointer, off, size uintptr) + // typedslicecopy copies a slice of elemType values from src to dst, // returning the number of elements copied. //go:noescape func typedslicecopy(elemType *rtype, dst, src sliceHeader) int -//go:noescape -func memclrNoHeapPointers(ptr unsafe.Pointer, n uintptr) - // Dummy annotation marking that the value x escapes, // for use in cases where the reflect code is so clever that // the compiler cannot follow. diff --git a/src/runtime/mbarrier.go b/src/runtime/mbarrier.go index 5142f4327a2a4..6da8cf2ccb81f 100644 --- a/src/runtime/mbarrier.go +++ b/src/runtime/mbarrier.go @@ -318,6 +318,19 @@ func typedmemclr(typ *_type, ptr unsafe.Pointer) { memclrNoHeapPointers(ptr, typ.size) } +//go:linkname reflect_typedmemclr reflect.typedmemclr +func reflect_typedmemclr(typ *_type, ptr unsafe.Pointer) { + typedmemclr(typ, ptr) +} + +//go:linkname reflect_typedmemclrpartial reflect.typedmemclrpartial +func reflect_typedmemclrpartial(typ *_type, ptr unsafe.Pointer, off, size uintptr) { + if typ.kind&kindNoPointers == 0 { + bulkBarrierPreWrite(uintptr(ptr), 0, size) + } + memclrNoHeapPointers(ptr, size) +} + // memclrHasPointers clears n bytes of typed memory starting at ptr. // The caller must ensure that the type of the object at ptr has // pointers, usually by checking typ.kind&kindNoPointers. However, ptr From da0d1a44bac379f5acedb1933f85400de08f4ac6 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Wed, 26 Sep 2018 21:10:21 +0000 Subject: [PATCH 0464/1663] all: use strings.ReplaceAll and bytes.ReplaceAll where applicable I omitted vendor directories and anything necessary for bootstrapping. (Tested by bootstrapping with Go 1.4) Updates #27864 Change-Id: I7d9b68d0372d3a34dee22966cca323513ece7e8a Reviewed-on: https://go-review.googlesource.com/137856 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/fix/main.go | 2 +- src/cmd/fix/typecheck.go | 4 ++-- src/cmd/go/go_test.go | 10 +++++----- src/cmd/go/internal/envcmd/env.go | 2 +- src/cmd/go/internal/get/vcs.go | 2 +- src/cmd/go/internal/modconv/convert_test.go | 2 +- src/cmd/go/internal/modfetch/codehost/codehost.go | 2 +- src/cmd/go/internal/modfetch/coderepo_test.go | 12 ++++++------ src/cmd/go/internal/modfetch/proxy.go | 2 +- src/cmd/go/internal/modload/import_test.go | 2 +- src/cmd/go/internal/modload/query_test.go | 2 +- src/cmd/go/internal/search/search.go | 4 ++-- src/cmd/go/internal/work/build.go | 4 ++-- src/cmd/go/internal/work/exec.go | 10 +++++----- src/cmd/go/proxy_test.go | 4 ++-- src/cmd/go/script_test.go | 12 ++++++------ src/cmd/go/testdata/addmod.go | 2 +- src/cmd/go/vendor_test.go | 2 +- src/cmd/gofmt/gofmt_test.go | 2 +- src/cmd/internal/goobj/read.go | 2 +- src/cmd/trace/trace.go | 2 +- src/cmd/vet/main.go | 2 +- src/cmd/vet/vet_test.go | 2 +- src/crypto/rsa/pss_test.go | 2 +- src/crypto/x509/root_darwin_arm_gen.go | 6 +++--- src/encoding/base32/base32_test.go | 10 +++++----- src/encoding/base64/base64_test.go | 8 ++++---- src/flag/flag.go | 2 +- src/go/constant/value_test.go | 2 +- src/go/doc/doc_test.go | 6 +++--- src/go/printer/example_test.go | 4 ++-- src/html/template/js.go | 2 +- src/html/template/url.go | 2 +- src/mime/multipart/formdata_test.go | 8 ++++---- src/mime/multipart/multipart_test.go | 6 +++--- src/net/http/cgi/child.go | 2 +- src/net/http/httputil/dump_test.go | 2 +- src/net/http/readrequest_test.go | 2 +- src/net/http/request_test.go | 6 +++--- src/net/http/serve_test.go | 2 +- src/net/lookup_windows_test.go | 2 +- src/net/mail/message_test.go | 4 ++-- src/net/net_windows_test.go | 2 +- src/net/url/example_test.go | 2 +- src/net/url/url_test.go | 6 +++--- src/os/path_windows_test.go | 6 +++--- src/path/filepath/path.go | 4 ++-- src/path/filepath/path_test.go | 2 +- src/path/filepath/path_windows.go | 2 +- src/path/filepath/path_windows_test.go | 2 +- src/runtime/pprof/internal/profile/profile.go | 2 +- src/runtime/pprof/pprof_test.go | 2 +- src/runtime/runtime-gdb_test.go | 2 +- src/strings/example_test.go | 2 +- src/testing/sub_test.go | 4 ++-- src/text/template/exec.go | 2 +- 56 files changed, 104 insertions(+), 104 deletions(-) diff --git a/src/cmd/fix/main.go b/src/cmd/fix/main.go index f06abae171b0e..f54a5e0d963bf 100644 --- a/src/cmd/fix/main.go +++ b/src/cmd/fix/main.go @@ -52,7 +52,7 @@ func usage() { fmt.Fprintf(os.Stderr, "\n%s\n", f.name) } desc := strings.TrimSpace(f.desc) - desc = strings.Replace(desc, "\n", "\n\t", -1) + desc = strings.ReplaceAll(desc, "\n", "\n\t") fmt.Fprintf(os.Stderr, "\t%s\n", desc) } os.Exit(2) diff --git a/src/cmd/fix/typecheck.go b/src/cmd/fix/typecheck.go index eafb626c74768..66e0cdcec056d 100644 --- a/src/cmd/fix/typecheck.go +++ b/src/cmd/fix/typecheck.go @@ -193,12 +193,12 @@ func typecheck(cfg *TypeConfig, f *ast.File) (typeof map[interface{}]string, ass var params, results []string for _, p := range fn.Type.Params.List { t := gofmt(p.Type) - t = strings.Replace(t, "_Ctype_", "C.", -1) + t = strings.ReplaceAll(t, "_Ctype_", "C.") params = append(params, t) } for _, r := range fn.Type.Results.List { t := gofmt(r.Type) - t = strings.Replace(t, "_Ctype_", "C.", -1) + t = strings.ReplaceAll(t, "_Ctype_", "C.") results = append(results, t) } cfg.External["C."+fn.Name.Name[7:]] = joinFunc(params, results) diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index 962b52fd3de55..139ee73ae097f 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -1090,7 +1090,7 @@ func testMove(t *testing.T, vcs, url, base, config string) { path := tg.path(filepath.Join("src", config)) data, err := ioutil.ReadFile(path) tg.must(err) - data = bytes.Replace(data, []byte(base), []byte(base+"XXX"), -1) + data = bytes.ReplaceAll(data, []byte(base), []byte(base+"XXX")) tg.must(ioutil.WriteFile(path, data, 0644)) } if vcs == "git" { @@ -2360,14 +2360,14 @@ func TestShadowingLogic(t *testing.T) { // The math in root1 is not "math" because the standard math is. tg.run("list", "-f", "({{.ImportPath}}) ({{.ConflictDir}})", "./testdata/shadow/root1/src/math") - pwdForwardSlash := strings.Replace(pwd, string(os.PathSeparator), "/", -1) + pwdForwardSlash := strings.ReplaceAll(pwd, string(os.PathSeparator), "/") if !strings.HasPrefix(pwdForwardSlash, "/") { pwdForwardSlash = "/" + pwdForwardSlash } // The output will have makeImportValid applies, but we only // bother to deal with characters we might reasonably see. for _, r := range " :" { - pwdForwardSlash = strings.Replace(pwdForwardSlash, string(r), "_", -1) + pwdForwardSlash = strings.ReplaceAll(pwdForwardSlash, string(r), "_") } want := "(_" + pwdForwardSlash + "/testdata/shadow/root1/src/math) (" + filepath.Join(runtime.GOROOT(), "src", "math") + ")" if strings.TrimSpace(tg.getStdout()) != want { @@ -2557,7 +2557,7 @@ func TestCoverageErrorLine(t *testing.T) { // It's OK that stderr2 drops the character position in the error, // because of the //line directive (see golang.org/issue/22662). - stderr = strings.Replace(stderr, "p.go:4:2:", "p.go:4:", -1) + stderr = strings.ReplaceAll(stderr, "p.go:4:2:", "p.go:4:") if stderr != stderr2 { t.Logf("test -cover changed error messages:\nbefore:\n%s\n\nafter:\n%s", stderr, stderr2) t.Skip("golang.org/issue/22660") @@ -6171,7 +6171,7 @@ func TestCDAndGOPATHAreDifferent(t *testing.T) { testCDAndGOPATHAreDifferent(tg, cd, gopath) if runtime.GOOS == "windows" { - testCDAndGOPATHAreDifferent(tg, cd, strings.Replace(gopath, `\`, `/`, -1)) + testCDAndGOPATHAreDifferent(tg, cd, strings.ReplaceAll(gopath, `\`, `/`)) testCDAndGOPATHAreDifferent(tg, cd, strings.ToUpper(gopath)) testCDAndGOPATHAreDifferent(tg, cd, strings.ToLower(gopath)) } diff --git a/src/cmd/go/internal/envcmd/env.go b/src/cmd/go/internal/envcmd/env.go index afadbade38ef7..85a42e0519ad6 100644 --- a/src/cmd/go/internal/envcmd/env.go +++ b/src/cmd/go/internal/envcmd/env.go @@ -203,7 +203,7 @@ func runEnv(cmd *base.Command, args []string) { fmt.Printf("%s=\"%s\"\n", e.Name, e.Value) case "plan9": if strings.IndexByte(e.Value, '\x00') < 0 { - fmt.Printf("%s='%s'\n", e.Name, strings.Replace(e.Value, "'", "''", -1)) + fmt.Printf("%s='%s'\n", e.Name, strings.ReplaceAll(e.Value, "'", "''")) } else { v := strings.Split(e.Value, "\x00") fmt.Printf("%s=(", e.Name) diff --git a/src/cmd/go/internal/get/vcs.go b/src/cmd/go/internal/get/vcs.go index 0f7b623ec31e8..173934b84ec96 100644 --- a/src/cmd/go/internal/get/vcs.go +++ b/src/cmd/go/internal/get/vcs.go @@ -964,7 +964,7 @@ func matchGoImport(imports []metaImport, importPath string) (metaImport, error) // expand rewrites s to replace {k} with match[k] for each key k in match. func expand(match map[string]string, s string) string { for k, v := range match { - s = strings.Replace(s, "{"+k+"}", v, -1) + s = strings.ReplaceAll(s, "{"+k+"}", v) } return s } diff --git a/src/cmd/go/internal/modconv/convert_test.go b/src/cmd/go/internal/modconv/convert_test.go index ad27abb8ef7e1..4d55d73f21423 100644 --- a/src/cmd/go/internal/modconv/convert_test.go +++ b/src/cmd/go/internal/modconv/convert_test.go @@ -146,7 +146,7 @@ func TestConvertLegacyConfig(t *testing.T) { } for _, tt := range tests { - t.Run(strings.Replace(tt.path, "/", "_", -1)+"_"+tt.vers, func(t *testing.T) { + t.Run(strings.ReplaceAll(tt.path, "/", "_")+"_"+tt.vers, func(t *testing.T) { f, err := modfile.Parse("golden", []byte(tt.gomod), nil) if err != nil { t.Fatal(err) diff --git a/src/cmd/go/internal/modfetch/codehost/codehost.go b/src/cmd/go/internal/modfetch/codehost/codehost.go index 4103ddc717f49..4205cd26bda11 100644 --- a/src/cmd/go/internal/modfetch/codehost/codehost.go +++ b/src/cmd/go/internal/modfetch/codehost/codehost.go @@ -185,7 +185,7 @@ func (e *RunError) Error() string { text := e.Cmd + ": " + e.Err.Error() stderr := bytes.TrimRight(e.Stderr, "\n") if len(stderr) > 0 { - text += ":\n\t" + strings.Replace(string(stderr), "\n", "\n\t", -1) + text += ":\n\t" + strings.ReplaceAll(string(stderr), "\n", "\n\t") } return text } diff --git a/src/cmd/go/internal/modfetch/coderepo_test.go b/src/cmd/go/internal/modfetch/coderepo_test.go index 79b82786cb965..0b62b9ee76bd5 100644 --- a/src/cmd/go/internal/modfetch/coderepo_test.go +++ b/src/cmd/go/internal/modfetch/coderepo_test.go @@ -423,7 +423,7 @@ func TestCodeRepo(t *testing.T) { } } } - t.Run(strings.Replace(tt.path, "/", "_", -1)+"/"+tt.rev, f) + t.Run(strings.ReplaceAll(tt.path, "/", "_")+"/"+tt.rev, f) if strings.HasPrefix(tt.path, vgotest1git) { for _, alt := range altVgotests { // Note: Communicating with f through tt; should be cleaned up. @@ -442,7 +442,7 @@ func TestCodeRepo(t *testing.T) { tt.rev = remap(tt.rev, m) tt.gomoderr = remap(tt.gomoderr, m) tt.ziperr = remap(tt.ziperr, m) - t.Run(strings.Replace(tt.path, "/", "_", -1)+"/"+tt.rev, f) + t.Run(strings.ReplaceAll(tt.path, "/", "_")+"/"+tt.rev, f) tt = old } } @@ -473,9 +473,9 @@ func remap(name string, m map[string]string) string { } } for k, v := range m { - name = strings.Replace(name, k, v, -1) + name = strings.ReplaceAll(name, k, v) if codehost.AllHex(k) { - name = strings.Replace(name, k[:12], v[:12], -1) + name = strings.ReplaceAll(name, k[:12], v[:12]) } } return name @@ -522,7 +522,7 @@ func TestCodeRepoVersions(t *testing.T) { } defer os.RemoveAll(tmpdir) for _, tt := range codeRepoVersionsTests { - t.Run(strings.Replace(tt.path, "/", "_", -1), func(t *testing.T) { + t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) { repo, err := Lookup(tt.path) if err != nil { t.Fatalf("Lookup(%q): %v", tt.path, err) @@ -570,7 +570,7 @@ func TestLatest(t *testing.T) { } defer os.RemoveAll(tmpdir) for _, tt := range latestTests { - name := strings.Replace(tt.path, "/", "_", -1) + name := strings.ReplaceAll(tt.path, "/", "_") t.Run(name, func(t *testing.T) { repo, err := Lookup(tt.path) if err != nil { diff --git a/src/cmd/go/internal/modfetch/proxy.go b/src/cmd/go/internal/modfetch/proxy.go index 5f856b80d2e16..7c78502f318d7 100644 --- a/src/cmd/go/internal/modfetch/proxy.go +++ b/src/cmd/go/internal/modfetch/proxy.go @@ -248,5 +248,5 @@ func (p *proxyRepo) Zip(version string, tmpdir string) (tmpfile string, err erro // That is, it escapes things like ? and # (which really shouldn't appear anyway). // It does not escape / to %2F: our REST API is designed so that / can be left as is. func pathEscape(s string) string { - return strings.Replace(url.PathEscape(s), "%2F", "/", -1) + return strings.ReplaceAll(url.PathEscape(s), "%2F", "/") } diff --git a/src/cmd/go/internal/modload/import_test.go b/src/cmd/go/internal/modload/import_test.go index 3f4ddab436cc4..9422a3d960c16 100644 --- a/src/cmd/go/internal/modload/import_test.go +++ b/src/cmd/go/internal/modload/import_test.go @@ -45,7 +45,7 @@ func TestImport(t *testing.T) { testenv.MustHaveExternalNetwork(t) for _, tt := range importTests { - t.Run(strings.Replace(tt.path, "/", "_", -1), func(t *testing.T) { + t.Run(strings.ReplaceAll(tt.path, "/", "_"), func(t *testing.T) { // Note that there is no build list, so Import should always fail. m, dir, err := Import(tt.path) if err == nil { diff --git a/src/cmd/go/internal/modload/query_test.go b/src/cmd/go/internal/modload/query_test.go index 7f3ffabef7420..9b07383217175 100644 --- a/src/cmd/go/internal/modload/query_test.go +++ b/src/cmd/go/internal/modload/query_test.go @@ -132,7 +132,7 @@ func TestQuery(t *testing.T) { ok, _ := path.Match(allow, m.Version) return ok } - t.Run(strings.Replace(tt.path, "/", "_", -1)+"/"+tt.query+"/"+allow, func(t *testing.T) { + t.Run(strings.ReplaceAll(tt.path, "/", "_")+"/"+tt.query+"/"+allow, func(t *testing.T) { info, err := Query(tt.path, tt.query, allowed) if tt.err != "" { if err != nil && err.Error() == tt.err { diff --git a/src/cmd/go/internal/search/search.go b/src/cmd/go/internal/search/search.go index 60ae73696bb4c..0ca60e73497e2 100644 --- a/src/cmd/go/internal/search/search.go +++ b/src/cmd/go/internal/search/search.go @@ -275,7 +275,7 @@ func MatchPattern(pattern string) func(name string) bool { case strings.HasSuffix(re, `/\.\.\.`): re = strings.TrimSuffix(re, `/\.\.\.`) + `(/\.\.\.)?` } - re = strings.Replace(re, `\.\.\.`, `[^`+vendorChar+`]*`, -1) + re = strings.ReplaceAll(re, `\.\.\.`, `[^`+vendorChar+`]*`) reg := regexp.MustCompile(`^` + re + `$`) @@ -353,7 +353,7 @@ func CleanPatterns(patterns []string) []string { // as a courtesy to Windows developers, rewrite \ to / // in command-line arguments. Handles .\... and so on. if filepath.Separator == '\\' { - a = strings.Replace(a, `\`, `/`, -1) + a = strings.ReplaceAll(a, `\`, `/`) } // Put argument in canonical form, but preserve leading ./. diff --git a/src/cmd/go/internal/work/build.go b/src/cmd/go/internal/work/build.go index dd482b677d574..145b87513a916 100644 --- a/src/cmd/go/internal/work/build.go +++ b/src/cmd/go/internal/work/build.go @@ -398,10 +398,10 @@ func libname(args []string, pkgs []*load.Package) (string, error) { arg = bp.ImportPath } } - appendName(strings.Replace(arg, "/", "-", -1)) + appendName(strings.ReplaceAll(arg, "/", "-")) } else { for _, pkg := range pkgs { - appendName(strings.Replace(pkg.ImportPath, "/", "-", -1)) + appendName(strings.ReplaceAll(pkg.ImportPath, "/", "-")) } } } else if haveNonMeta { // have both meta package and a non-meta one diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index 01414a3d5775b..158f5f3b173db 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -1705,14 +1705,14 @@ func (b *Builder) fmtcmd(dir string, format string, args ...interface{}) string if dir[len(dir)-1] == filepath.Separator { dot += string(filepath.Separator) } - cmd = strings.Replace(" "+cmd, " "+dir, dot, -1)[1:] + cmd = strings.ReplaceAll(" "+cmd, " "+dir, dot)[1:] if b.scriptDir != dir { b.scriptDir = dir cmd = "cd " + dir + "\n" + cmd } } if b.WorkDir != "" { - cmd = strings.Replace(cmd, b.WorkDir, "$WORK", -1) + cmd = strings.ReplaceAll(cmd, b.WorkDir, "$WORK") } return cmd } @@ -1754,10 +1754,10 @@ func (b *Builder) showOutput(a *Action, dir, desc, out string) { prefix := "# " + desc suffix := "\n" + out if reldir := base.ShortPath(dir); reldir != dir { - suffix = strings.Replace(suffix, " "+dir, " "+reldir, -1) - suffix = strings.Replace(suffix, "\n"+dir, "\n"+reldir, -1) + suffix = strings.ReplaceAll(suffix, " "+dir, " "+reldir) + suffix = strings.ReplaceAll(suffix, "\n"+dir, "\n"+reldir) } - suffix = strings.Replace(suffix, " "+b.WorkDir, " $WORK", -1) + suffix = strings.ReplaceAll(suffix, " "+b.WorkDir, " $WORK") if a != nil && a.output != nil { a.output = append(a.output, prefix...) diff --git a/src/cmd/go/proxy_test.go b/src/cmd/go/proxy_test.go index 212e5aa08f7a1..97fc4b0e80735 100644 --- a/src/cmd/go/proxy_test.go +++ b/src/cmd/go/proxy_test.go @@ -78,7 +78,7 @@ func readModList() { if i < 0 { continue } - encPath := strings.Replace(name[:i], "_", "/", -1) + encPath := strings.ReplaceAll(name[:i], "_", "/") path, err := module.DecodePath(encPath) if err != nil { fmt.Fprintf(os.Stderr, "go proxy_test: %v\n", err) @@ -256,7 +256,7 @@ func readArchive(path, vers string) *txtar.Archive { return nil } - prefix := strings.Replace(enc, "/", "_", -1) + prefix := strings.ReplaceAll(enc, "/", "_") name := filepath.Join(cmdGoDir, "testdata/mod", prefix+"_"+encVers+".txt") a := archiveCache.Do(name, func() interface{} { a, err := txtar.ParseFile(name) diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go index 7c083a87b932f..31c6ede2a59a3 100644 --- a/src/cmd/go/script_test.go +++ b/src/cmd/go/script_test.go @@ -329,7 +329,7 @@ func (ts *testScript) cmdAddcrlf(neg bool, args []string) { file = ts.mkabs(file) data, err := ioutil.ReadFile(file) ts.check(err) - ts.check(ioutil.WriteFile(file, bytes.Replace(data, []byte("\n"), []byte("\r\n"), -1), 0666)) + ts.check(ioutil.WriteFile(file, bytes.ReplaceAll(data, []byte("\n"), []byte("\r\n")), 0666)) } } @@ -630,7 +630,7 @@ func scriptMatch(ts *testScript, neg bool, args []string, text, name string) { } // Matching against workdir would be misleading. - text = strings.Replace(text, ts.workdir, "$WORK", -1) + text = strings.ReplaceAll(text, ts.workdir, "$WORK") if neg { if re.MatchString(text) { @@ -691,7 +691,7 @@ func (ts *testScript) cmdSymlink(neg bool, args []string) { // abbrev abbreviates the actual work directory in the string s to the literal string "$WORK". func (ts *testScript) abbrev(s string) string { - s = strings.Replace(s, ts.workdir, "$WORK", -1) + s = strings.ReplaceAll(s, ts.workdir, "$WORK") if *testWork { // Expose actual $WORK value in environment dump on first line of work script, // so that the user can find out what directory -testwork left behind. @@ -885,17 +885,17 @@ var diffTests = []struct { func TestDiff(t *testing.T) { for _, tt := range diffTests { // Turn spaces into \n. - text1 := strings.Replace(tt.text1, " ", "\n", -1) + text1 := strings.ReplaceAll(tt.text1, " ", "\n") if text1 != "" { text1 += "\n" } - text2 := strings.Replace(tt.text2, " ", "\n", -1) + text2 := strings.ReplaceAll(tt.text2, " ", "\n") if text2 != "" { text2 += "\n" } out := diff(text1, text2) // Cut final \n, cut spaces, turn remaining \n into spaces. - out = strings.Replace(strings.Replace(strings.TrimSuffix(out, "\n"), " ", "", -1), "\n", " ", -1) + out = strings.ReplaceAll(strings.ReplaceAll(strings.TrimSuffix(out, "\n"), " ", ""), "\n", " ") if out != tt.diff { t.Errorf("diff(%q, %q) = %q, want %q", text1, text2, out, tt.diff) } diff --git a/src/cmd/go/testdata/addmod.go b/src/cmd/go/testdata/addmod.go index 19850af0f37b2..8bb6056a540ae 100644 --- a/src/cmd/go/testdata/addmod.go +++ b/src/cmd/go/testdata/addmod.go @@ -142,7 +142,7 @@ func main() { } data := txtar.Format(a) - target := filepath.Join("mod", strings.Replace(path, "/", "_", -1)+"_"+vers+".txt") + target := filepath.Join("mod", strings.ReplaceAll(path, "/", "_")+"_"+vers+".txt") if err := ioutil.WriteFile(target, data, 0666); err != nil { log.Printf("%s: %v", arg, err) exitCode = 1 diff --git a/src/cmd/go/vendor_test.go b/src/cmd/go/vendor_test.go index 22aa643b0032e..c302d7e9b5841 100644 --- a/src/cmd/go/vendor_test.go +++ b/src/cmd/go/vendor_test.go @@ -37,7 +37,7 @@ func TestVendorImports(t *testing.T) { vend/x/vendor/p/p [notfound] vend/x/vendor/r [] ` - want = strings.Replace(want+"\t", "\n\t\t", "\n", -1) + want = strings.ReplaceAll(want+"\t", "\n\t\t", "\n") want = strings.TrimPrefix(want, "\n") have := tg.stdout.String() diff --git a/src/cmd/gofmt/gofmt_test.go b/src/cmd/gofmt/gofmt_test.go index 16b653b6460d7..3008365cd237c 100644 --- a/src/cmd/gofmt/gofmt_test.go +++ b/src/cmd/gofmt/gofmt_test.go @@ -200,7 +200,7 @@ func TestDiff(t *testing.T) { } if runtime.GOOS == "windows" { - b = bytes.Replace(b, []byte{'\r', '\n'}, []byte{'\n'}, -1) + b = bytes.ReplaceAll(b, []byte{'\r', '\n'}, []byte{'\n'}) } bs := bytes.SplitN(b, []byte{'\n'}, 3) diff --git a/src/cmd/internal/goobj/read.go b/src/cmd/internal/goobj/read.go index e39180cad666c..2d618eefa557a 100644 --- a/src/cmd/internal/goobj/read.go +++ b/src/cmd/internal/goobj/read.go @@ -293,7 +293,7 @@ func (r *objReader) readRef() { // In a symbol name in an object file, "". denotes the // prefix for the package in which the object file has been found. // Expand it. - name = strings.Replace(name, `"".`, r.pkgprefix, -1) + name = strings.ReplaceAll(name, `"".`, r.pkgprefix) // An individual object file only records version 0 (extern) or 1 (static). // To make static symbols unique across all files being read, we diff --git a/src/cmd/trace/trace.go b/src/cmd/trace/trace.go index 676b9ffa5ab6b..07fc4333eba2e 100644 --- a/src/cmd/trace/trace.go +++ b/src/cmd/trace/trace.go @@ -38,7 +38,7 @@ func httpTrace(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusInternalServerError) return } - html := strings.Replace(templTrace, "{{PARAMS}}", r.Form.Encode(), -1) + html := strings.ReplaceAll(templTrace, "{{PARAMS}}", r.Form.Encode()) w.Write([]byte(html)) } diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go index 646adf4d76d5f..6e885121c8cd5 100644 --- a/src/cmd/vet/main.go +++ b/src/cmd/vet/main.go @@ -273,7 +273,7 @@ func main() { // Accept space-separated tags because that matches // the go command's other subcommands. // Accept commas because go tool vet traditionally has. - tagList = strings.Fields(strings.Replace(*tags, ",", " ", -1)) + tagList = strings.Fields(strings.ReplaceAll(*tags, ",", " ")) initPrintFlags() initUnusedFlags() diff --git a/src/cmd/vet/vet_test.go b/src/cmd/vet/vet_test.go index 90665d77bc655..df84d6cc98378 100644 --- a/src/cmd/vet/vet_test.go +++ b/src/cmd/vet/vet_test.go @@ -243,7 +243,7 @@ func errorCheck(outStr string, wantAuto bool, fullshort ...string) (err error) { for i := range out { for j := 0; j < len(fullshort); j += 2 { full, short := fullshort[j], fullshort[j+1] - out[i] = strings.Replace(out[i], full, short, -1) + out[i] = strings.ReplaceAll(out[i], full, short) } } diff --git a/src/crypto/rsa/pss_test.go b/src/crypto/rsa/pss_test.go index cae24e58c6794..dfa8d8bb5ad02 100644 --- a/src/crypto/rsa/pss_test.go +++ b/src/crypto/rsa/pss_test.go @@ -103,7 +103,7 @@ func TestPSSGolden(t *testing.T) { switch { case len(line) == 0: if len(partialValue) > 0 { - values <- strings.Replace(partialValue, " ", "", -1) + values <- strings.ReplaceAll(partialValue, " ", "") partialValue = "" lastWasValue = true } diff --git a/src/crypto/x509/root_darwin_arm_gen.go b/src/crypto/x509/root_darwin_arm_gen.go index b5580d6f02a3b..bc44124a78556 100644 --- a/src/crypto/x509/root_darwin_arm_gen.go +++ b/src/crypto/x509/root_darwin_arm_gen.go @@ -154,9 +154,9 @@ func fetchCertIDs() ([]certID, error) { values := regexp.MustCompile("(?s)(.*?)").FindAllStringSubmatch(row, -1) name := values[cols["Certificate name"]][1] fingerprint := values[cols["Fingerprint (SHA-256)"]][1] - fingerprint = strings.Replace(fingerprint, "
", "", -1) - fingerprint = strings.Replace(fingerprint, "\n", "", -1) - fingerprint = strings.Replace(fingerprint, " ", "", -1) + fingerprint = strings.ReplaceAll(fingerprint, "
", "") + fingerprint = strings.ReplaceAll(fingerprint, "\n", "") + fingerprint = strings.ReplaceAll(fingerprint, " ", "") fingerprint = strings.ToLower(fingerprint) ids = append(ids, certID{ diff --git a/src/encoding/base32/base32_test.go b/src/encoding/base32/base32_test.go index c5506ed4de70d..b74054ba40227 100644 --- a/src/encoding/base32/base32_test.go +++ b/src/encoding/base32/base32_test.go @@ -425,7 +425,7 @@ IZJAOZSWY2LUEBSXG43FEBRWS3DMOVWSAZDPNRXXEZJAMV2SAZTVM5UWC5BANZ2WY3DBBJYGC4TJMF NZ2CYIDTOVXHIIDJNYFGG5LMOBQSA4LVNEQG6ZTGNFRWSYJAMRSXGZLSOVXHIIDNN5WGY2LUEBQW42 LNEBUWIIDFON2CA3DBMJXXE5LNFY== ====` - encodedShort := strings.Replace(encoded, "\n", "", -1) + encodedShort := strings.ReplaceAll(encoded, "\n", "") dec := NewDecoder(StdEncoding, strings.NewReader(encoded)) res1, err := ioutil.ReadAll(dec) @@ -465,7 +465,7 @@ func TestWithCustomPadding(t *testing.T) { for _, testcase := range pairs { defaultPadding := StdEncoding.EncodeToString([]byte(testcase.decoded)) customPadding := StdEncoding.WithPadding('@').EncodeToString([]byte(testcase.decoded)) - expected := strings.Replace(defaultPadding, "=", "@", -1) + expected := strings.ReplaceAll(defaultPadding, "=", "@") if expected != customPadding { t.Errorf("Expected custom %s, got %s", expected, customPadding) @@ -675,7 +675,7 @@ func TestWithoutPaddingClose(t *testing.T) { expected := testpair.encoded if encoding.padChar == NoPadding { - expected = strings.Replace(expected, "=", "", -1) + expected = strings.ReplaceAll(expected, "=", "") } res := buf.String() @@ -697,7 +697,7 @@ func TestDecodeReadAll(t *testing.T) { for encIndex, encoding := range encodings { encoded := pair.encoded if encoding.padChar == NoPadding { - encoded = strings.Replace(encoded, "=", "", -1) + encoded = strings.ReplaceAll(encoded, "=", "") } decReader, err := ioutil.ReadAll(NewDecoder(encoding, strings.NewReader(encoded))) @@ -723,7 +723,7 @@ func TestDecodeSmallBuffer(t *testing.T) { for encIndex, encoding := range encodings { encoded := pair.encoded if encoding.padChar == NoPadding { - encoded = strings.Replace(encoded, "=", "", -1) + encoded = strings.ReplaceAll(encoded, "=", "") } decoder := NewDecoder(encoding, strings.NewReader(encoded)) diff --git a/src/encoding/base64/base64_test.go b/src/encoding/base64/base64_test.go index f019654f5b57e..f7f312ca39324 100644 --- a/src/encoding/base64/base64_test.go +++ b/src/encoding/base64/base64_test.go @@ -53,8 +53,8 @@ func stdRef(ref string) string { // Convert a reference string to URL-encoding func urlRef(ref string) string { - ref = strings.Replace(ref, "+", "-", -1) - ref = strings.Replace(ref, "/", "_", -1) + ref = strings.ReplaceAll(ref, "+", "-") + ref = strings.ReplaceAll(ref, "/", "_") return ref } @@ -72,7 +72,7 @@ func rawURLRef(ref string) string { var funnyEncoding = NewEncoding(encodeStd).WithPadding(rune('@')) func funnyRef(ref string) string { - return strings.Replace(ref, "=", "@", -1) + return strings.ReplaceAll(ref, "=", "@") } type encodingTest struct { @@ -418,7 +418,7 @@ j+mSARB/17pKVXYWHXjsj7yIex0PadzXMO1zT5KHoNA3HT8ietoGhgjsfA+CSnvvqh/jJtqsrwOv 2b6NGNzXfTYexzJ+nU7/ALkf4P8Awv6P9KvTQQ4AgyDqCF85Pho3CTB7eHwXoH+LT65uZbX9X+o2 bqbPb06551Y4 ` - encodedShort := strings.Replace(encoded, "\n", "", -1) + encodedShort := strings.ReplaceAll(encoded, "\n", "") dec := NewDecoder(StdEncoding, strings.NewReader(encoded)) res1, err := ioutil.ReadAll(dec) diff --git a/src/flag/flag.go b/src/flag/flag.go index 2cd7829c1a69b..ae84e1f775e92 100644 --- a/src/flag/flag.go +++ b/src/flag/flag.go @@ -472,7 +472,7 @@ func (f *FlagSet) PrintDefaults() { // for both 4- and 8-space tab stops. s += "\n \t" } - s += strings.Replace(usage, "\n", "\n \t", -1) + s += strings.ReplaceAll(usage, "\n", "\n \t") if !isZeroValue(flag, flag.DefValue) { if _, ok := flag.Value.(*stringValue); ok { diff --git a/src/go/constant/value_test.go b/src/go/constant/value_test.go index e6fca76e182bc..68b87eaa5571d 100644 --- a/src/go/constant/value_test.go +++ b/src/go/constant/value_test.go @@ -296,7 +296,7 @@ func val(lit string) Value { switch first, last := lit[0], lit[len(lit)-1]; { case first == '"' || first == '`': tok = token.STRING - lit = strings.Replace(lit, "_", " ", -1) + lit = strings.ReplaceAll(lit, "_", " ") case first == '\'': tok = token.CHAR case last == 'i': diff --git a/src/go/doc/doc_test.go b/src/go/doc/doc_test.go index 902a79f63f59a..0b2d2b63ccc09 100644 --- a/src/go/doc/doc_test.go +++ b/src/go/doc/doc_test.go @@ -40,7 +40,7 @@ func readTemplate(filename string) *template.Template { func nodeFmt(node interface{}, fset *token.FileSet) string { var buf bytes.Buffer printer.Fprint(&buf, fset, node) - return strings.Replace(strings.TrimSpace(buf.String()), "\n", "\n\t", -1) + return strings.ReplaceAll(strings.TrimSpace(buf.String()), "\n", "\n\t") } func synopsisFmt(s string) string { @@ -53,7 +53,7 @@ func synopsisFmt(s string) string { } s = strings.TrimSpace(s) + " ..." } - return "// " + strings.Replace(s, "\n", " ", -1) + return "// " + strings.ReplaceAll(s, "\n", " ") } func indentFmt(indent, s string) string { @@ -62,7 +62,7 @@ func indentFmt(indent, s string) string { end = "\n" s = s[:len(s)-1] } - return indent + strings.Replace(s, "\n", "\n"+indent, -1) + end + return indent + strings.ReplaceAll(s, "\n", "\n"+indent) + end } func isGoFile(fi os.FileInfo) bool { diff --git a/src/go/printer/example_test.go b/src/go/printer/example_test.go index e570040ba1f6d..30816931a8b2f 100644 --- a/src/go/printer/example_test.go +++ b/src/go/printer/example_test.go @@ -48,7 +48,7 @@ func ExampleFprint() { // and trim leading and trailing white space. s := buf.String() s = s[1 : len(s)-1] - s = strings.TrimSpace(strings.Replace(s, "\n\t", "\n", -1)) + s = strings.TrimSpace(strings.ReplaceAll(s, "\n\t", "\n")) // Print the cleaned-up body text to stdout. fmt.Println(s) @@ -61,7 +61,7 @@ func ExampleFprint() { // // s := buf.String() // s = s[1 : len(s)-1] - // s = strings.TrimSpace(strings.Replace(s, "\n\t", "\n", -1)) + // s = strings.TrimSpace(strings.ReplaceAll(s, "\n\t", "\n")) // // fmt.Println(s) } diff --git a/src/html/template/js.go b/src/html/template/js.go index 33a18b41864cc..2291f47c33ed8 100644 --- a/src/html/template/js.go +++ b/src/html/template/js.go @@ -172,7 +172,7 @@ func jsValEscaper(args ...interface{}) string { // turning into // x//* error marshaling y: // second line of error message */null - return fmt.Sprintf(" /* %s */null ", strings.Replace(err.Error(), "*/", "* /", -1)) + return fmt.Sprintf(" /* %s */null ", strings.ReplaceAll(err.Error(), "*/", "* /")) } // TODO: maybe post-process output to prevent it from containing diff --git a/src/html/template/url.go b/src/html/template/url.go index f0516300deb8c..8a4f727e50f25 100644 --- a/src/html/template/url.go +++ b/src/html/template/url.go @@ -156,7 +156,7 @@ func srcsetFilterAndEscaper(args ...interface{}) string { s = b.String() } // Additionally, commas separate one source from another. - return strings.Replace(s, ",", "%2c", -1) + return strings.ReplaceAll(s, ",", "%2c") } var b bytes.Buffer diff --git a/src/mime/multipart/formdata_test.go b/src/mime/multipart/formdata_test.go index 2d6a830cb669b..105a82c417063 100644 --- a/src/mime/multipart/formdata_test.go +++ b/src/mime/multipart/formdata_test.go @@ -13,7 +13,7 @@ import ( ) func TestReadForm(t *testing.T) { - b := strings.NewReader(strings.Replace(message, "\n", "\r\n", -1)) + b := strings.NewReader(strings.ReplaceAll(message, "\n", "\r\n")) r := NewReader(b, boundary) f, err := r.ReadForm(25) if err != nil { @@ -39,7 +39,7 @@ func TestReadForm(t *testing.T) { } func TestReadFormWithNamelessFile(t *testing.T) { - b := strings.NewReader(strings.Replace(messageWithFileWithoutName, "\n", "\r\n", -1)) + b := strings.NewReader(strings.ReplaceAll(messageWithFileWithoutName, "\n", "\r\n")) r := NewReader(b, boundary) f, err := r.ReadForm(25) if err != nil { @@ -54,7 +54,7 @@ func TestReadFormWithNamelessFile(t *testing.T) { func TestReadFormWithTextContentType(t *testing.T) { // From https://github.com/golang/go/issues/24041 - b := strings.NewReader(strings.Replace(messageWithTextContentType, "\n", "\r\n", -1)) + b := strings.NewReader(strings.ReplaceAll(messageWithTextContentType, "\n", "\r\n")) r := NewReader(b, boundary) f, err := r.ReadForm(25) if err != nil { @@ -184,7 +184,7 @@ Content-Disposition: form-data; name="largetext" --MyBoundary-- ` - testBody := strings.Replace(message, "\n", "\r\n", -1) + testBody := strings.ReplaceAll(message, "\n", "\r\n") testCases := []struct { name string maxMemory int64 diff --git a/src/mime/multipart/multipart_test.go b/src/mime/multipart/multipart_test.go index abe1cc8e77cc7..7bf606765ce9e 100644 --- a/src/mime/multipart/multipart_test.go +++ b/src/mime/multipart/multipart_test.go @@ -105,7 +105,7 @@ never read data useless trailer ` - testBody = strings.Replace(testBody, "\n", sep, -1) + testBody = strings.ReplaceAll(testBody, "\n", sep) return strings.Replace(testBody, "[longline]", longLine, 1) } @@ -151,7 +151,7 @@ func testMultipart(t *testing.T, r io.Reader, onlyNewlines bool) { adjustNewlines := func(s string) string { if onlyNewlines { - return strings.Replace(s, "\r\n", "\n", -1) + return strings.ReplaceAll(s, "\r\n", "\n") } return s } @@ -299,7 +299,7 @@ foo-bar: baz Oh no, premature EOF! ` - body := strings.Replace(testBody, "\n", "\r\n", -1) + body := strings.ReplaceAll(testBody, "\n", "\r\n") bodyReader := strings.NewReader(body) r := NewReader(bodyReader, "MyBoundary") diff --git a/src/net/http/cgi/child.go b/src/net/http/cgi/child.go index da12ac34980b8..10325c2eb5ae0 100644 --- a/src/net/http/cgi/child.go +++ b/src/net/http/cgi/child.go @@ -86,7 +86,7 @@ func RequestFromMap(params map[string]string) (*http.Request, error) { if !strings.HasPrefix(k, "HTTP_") || k == "HTTP_HOST" { continue } - r.Header.Add(strings.Replace(k[5:], "_", "-", -1), v) + r.Header.Add(strings.ReplaceAll(k[5:], "_", "-"), v) } // TODO: cookies. parsing them isn't exported, though. diff --git a/src/net/http/httputil/dump_test.go b/src/net/http/httputil/dump_test.go index 5703a7fb866a0..63312dd885690 100644 --- a/src/net/http/httputil/dump_test.go +++ b/src/net/http/httputil/dump_test.go @@ -370,7 +370,7 @@ func TestDumpResponse(t *testing.T) { } got := string(gotb) got = strings.TrimSpace(got) - got = strings.Replace(got, "\r", "", -1) + got = strings.ReplaceAll(got, "\r", "") if got != tt.want { t.Errorf("%d.\nDumpResponse got:\n%s\n\nWant:\n%s\n", i, got, tt.want) diff --git a/src/net/http/readrequest_test.go b/src/net/http/readrequest_test.go index 18eed345a8422..517a8189e1580 100644 --- a/src/net/http/readrequest_test.go +++ b/src/net/http/readrequest_test.go @@ -438,7 +438,7 @@ func TestReadRequest(t *testing.T) { // reqBytes treats req as a request (with \n delimiters) and returns it with \r\n delimiters, // ending in \r\n\r\n func reqBytes(req string) []byte { - return []byte(strings.Replace(strings.TrimSpace(req), "\n", "\r\n", -1) + "\r\n\r\n") + return []byte(strings.ReplaceAll(strings.TrimSpace(req), "\n", "\r\n") + "\r\n\r\n") } var badRequestTests = []struct { diff --git a/src/net/http/request_test.go b/src/net/http/request_test.go index 7a83ae5b1cef3..e8005571df975 100644 --- a/src/net/http/request_test.go +++ b/src/net/http/request_test.go @@ -878,7 +878,7 @@ func testMissingFile(t *testing.T, req *Request) { } func newTestMultipartRequest(t *testing.T) *Request { - b := strings.NewReader(strings.Replace(message, "\n", "\r\n", -1)) + b := strings.NewReader(strings.ReplaceAll(message, "\n", "\r\n")) req, err := NewRequest("POST", "/", b) if err != nil { t.Fatal("NewRequest:", err) @@ -970,8 +970,8 @@ Content-Disposition: form-data; name="textb" ` func benchmarkReadRequest(b *testing.B, request string) { - request = request + "\n" // final \n - request = strings.Replace(request, "\n", "\r\n", -1) // expand \n to \r\n + request = request + "\n" // final \n + request = strings.ReplaceAll(request, "\n", "\r\n") // expand \n to \r\n b.SetBytes(int64(len(request))) r := bufio.NewReader(&infiniteReader{buf: []byte(request)}) b.ReportAllocs() diff --git a/src/net/http/serve_test.go b/src/net/http/serve_test.go index 8dae95678da29..b12fcf4f9eb2e 100644 --- a/src/net/http/serve_test.go +++ b/src/net/http/serve_test.go @@ -130,7 +130,7 @@ func (c *testConn) Close() error { // reqBytes treats req as a request (with \n delimiters) and returns it with \r\n delimiters, // ending in \r\n\r\n func reqBytes(req string) []byte { - return []byte(strings.Replace(strings.TrimSpace(req), "\n", "\r\n", -1) + "\r\n\r\n") + return []byte(strings.ReplaceAll(strings.TrimSpace(req), "\n", "\r\n") + "\r\n\r\n") } type handlerTest struct { diff --git a/src/net/lookup_windows_test.go b/src/net/lookup_windows_test.go index cebb2d0558976..d3748f28c3f98 100644 --- a/src/net/lookup_windows_test.go +++ b/src/net/lookup_windows_test.go @@ -150,7 +150,7 @@ func nslookup(qtype, name string) (string, error) { if err := cmd.Run(); err != nil { return "", err } - r := strings.Replace(out.String(), "\r\n", "\n", -1) + r := strings.ReplaceAll(out.String(), "\r\n", "\n") // nslookup stderr output contains also debug information such as // "Non-authoritative answer" and it doesn't return the correct errcode if strings.Contains(err.String(), "can't find") { diff --git a/src/net/mail/message_test.go b/src/net/mail/message_test.go index b19da52c423a7..14ac9192a4af0 100644 --- a/src/net/mail/message_test.go +++ b/src/net/mail/message_test.go @@ -668,9 +668,9 @@ func TestAddressParser(t *testing.T) { switch charset { case "iso-8859-15": - in = bytes.Replace(in, []byte("\xf6"), []byte("ö"), -1) + in = bytes.ReplaceAll(in, []byte("\xf6"), []byte("ö")) case "windows-1252": - in = bytes.Replace(in, []byte("\xe9"), []byte("é"), -1) + in = bytes.ReplaceAll(in, []byte("\xe9"), []byte("é")) } return bytes.NewReader(in), nil diff --git a/src/net/net_windows_test.go b/src/net/net_windows_test.go index 8dfd3129802c2..8aa719f433afa 100644 --- a/src/net/net_windows_test.go +++ b/src/net/net_windows_test.go @@ -571,7 +571,7 @@ func TestInterfaceHardwareAddrWithGetmac(t *testing.T) { // skip these return } - addr = strings.Replace(addr, "-", ":", -1) + addr = strings.ReplaceAll(addr, "-", ":") cname := getValue("Connection Name") want[cname] = addr group = make(map[string]string) diff --git a/src/net/url/example_test.go b/src/net/url/example_test.go index d8eb6dcd20c7b..ad67f5328a868 100644 --- a/src/net/url/example_test.go +++ b/src/net/url/example_test.go @@ -219,5 +219,5 @@ func toJSON(m interface{}) string { if err != nil { log.Fatal(err) } - return strings.Replace(string(js), ",", ", ", -1) + return strings.ReplaceAll(string(js), ",", ", ") } diff --git a/src/net/url/url_test.go b/src/net/url/url_test.go index 5d3f91248f42e..7c4ada245a7a3 100644 --- a/src/net/url/url_test.go +++ b/src/net/url/url_test.go @@ -848,18 +848,18 @@ func TestUnescape(t *testing.T) { in := tt.in out := tt.out if strings.Contains(tt.in, "+") { - in = strings.Replace(tt.in, "+", "%20", -1) + in = strings.ReplaceAll(tt.in, "+", "%20") actual, err := PathUnescape(in) if actual != tt.out || (err != nil) != (tt.err != nil) { t.Errorf("PathUnescape(%q) = %q, %s; want %q, %s", in, actual, err, tt.out, tt.err) } if tt.err == nil { - s, err := QueryUnescape(strings.Replace(tt.in, "+", "XXX", -1)) + s, err := QueryUnescape(strings.ReplaceAll(tt.in, "+", "XXX")) if err != nil { continue } in = tt.in - out = strings.Replace(s, "XXX", "+", -1) + out = strings.ReplaceAll(s, "XXX", "+") } } diff --git a/src/os/path_windows_test.go b/src/os/path_windows_test.go index 00a3e63bf3cec..f1745ad132e76 100644 --- a/src/os/path_windows_test.go +++ b/src/os/path_windows_test.go @@ -38,10 +38,10 @@ func TestFixLongPath(t *testing.T) { {`\\?\c:\long\foo.txt`, `\\?\c:\long\foo.txt`}, {`\\?\c:\long/foo.txt`, `\\?\c:\long/foo.txt`}, } { - in := strings.Replace(test.in, "long", veryLong, -1) - want := strings.Replace(test.want, "long", veryLong, -1) + in := strings.ReplaceAll(test.in, "long", veryLong) + want := strings.ReplaceAll(test.want, "long", veryLong) if got := os.FixLongPath(in); got != want { - got = strings.Replace(got, veryLong, "long", -1) + got = strings.ReplaceAll(got, veryLong, "long") t.Errorf("fixLongPath(%q) = %q; want %q", test.in, got, test.want) } } diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go index 1508137a33d1d..aba1717e7d5e0 100644 --- a/src/path/filepath/path.go +++ b/src/path/filepath/path.go @@ -166,7 +166,7 @@ func ToSlash(path string) string { if Separator == '/' { return path } - return strings.Replace(path, string(Separator), "/", -1) + return strings.ReplaceAll(path, string(Separator), "/") } // FromSlash returns the result of replacing each slash ('/') character @@ -176,7 +176,7 @@ func FromSlash(path string) string { if Separator == '/' { return path } - return strings.Replace(path, "/", string(Separator), -1) + return strings.ReplaceAll(path, "/", string(Separator)) } // SplitList splits a list of paths joined by the OS-specific ListSeparator, diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index a221a3d4fac64..e1b5ad1d40c9c 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -1062,7 +1062,7 @@ func TestAbs(t *testing.T) { } for _, path := range absTests { - path = strings.Replace(path, "$", root, -1) + path = strings.ReplaceAll(path, "$", root) info, err := os.Stat(path) if err != nil { t.Errorf("%s: %s", path, err) diff --git a/src/path/filepath/path_windows.go b/src/path/filepath/path_windows.go index 519b6ebc329cc..6a144d9e0b5fa 100644 --- a/src/path/filepath/path_windows.go +++ b/src/path/filepath/path_windows.go @@ -100,7 +100,7 @@ func splitList(path string) []string { // Remove quotes. for i, s := range list { - list[i] = strings.Replace(s, `"`, ``, -1) + list[i] = strings.ReplaceAll(s, `"`, ``) } return list diff --git a/src/path/filepath/path_windows_test.go b/src/path/filepath/path_windows_test.go index e36a3c9b64636..63eab18116cf5 100644 --- a/src/path/filepath/path_windows_test.go +++ b/src/path/filepath/path_windows_test.go @@ -431,7 +431,7 @@ func TestToNorm(t *testing.T) { t.Fatal(err) } - err = os.MkdirAll(strings.Replace(testPath, "{{tmp}}", ctmp, -1), 0777) + err = os.MkdirAll(strings.ReplaceAll(testPath, "{{tmp}}", ctmp), 0777) if err != nil { t.Fatal(err) } diff --git a/src/runtime/pprof/internal/profile/profile.go b/src/runtime/pprof/internal/profile/profile.go index 64c3e3f054d38..863bd403a445d 100644 --- a/src/runtime/pprof/internal/profile/profile.go +++ b/src/runtime/pprof/internal/profile/profile.go @@ -200,7 +200,7 @@ var libRx = regexp.MustCompile(`([.]so$|[.]so[._][0-9]+)`) // first. func (p *Profile) setMain() { for i := 0; i < len(p.Mapping); i++ { - file := strings.TrimSpace(strings.Replace(p.Mapping[i].File, "(deleted)", "", -1)) + file := strings.TrimSpace(strings.ReplaceAll(p.Mapping[i].File, "(deleted)", "")) if len(file) == 0 { continue } diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index 126ba50054e57..593924183f67e 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -602,7 +602,7 @@ func TestBlockProfile(t *testing.T) { } for _, test := range tests { - if !regexp.MustCompile(strings.Replace(test.re, "\t", "\t+", -1)).MatchString(prof) { + if !regexp.MustCompile(strings.ReplaceAll(test.re, "\t", "\t+")).MatchString(prof) { t.Errorf("Bad %v entry, expect:\n%v\ngot:\n%v", test.name, test.re, prof) } } diff --git a/src/runtime/runtime-gdb_test.go b/src/runtime/runtime-gdb_test.go index 1ed6b3930384e..26f507159b8a6 100644 --- a/src/runtime/runtime-gdb_test.go +++ b/src/runtime/runtime-gdb_test.go @@ -490,7 +490,7 @@ func TestGdbConst(t *testing.T) { } got, _ := exec.Command("gdb", args...).CombinedOutput() - sgot := strings.Replace(string(got), "\r\n", "\n", -1) + sgot := strings.ReplaceAll(string(got), "\r\n", "\n") t.Logf("output %q", sgot) diff --git a/src/strings/example_test.go b/src/strings/example_test.go index 607e4a0a70e7a..103ef51f29edb 100644 --- a/src/strings/example_test.go +++ b/src/strings/example_test.go @@ -199,7 +199,7 @@ func ExampleRepeat() { func ExampleReplace() { fmt.Println(strings.Replace("oink oink oink", "k", "ky", 2)) - fmt.Println(strings.Replace("oink oink oink", "oink", "moo", -1)) + fmt.Println(strings.ReplaceAll("oink oink oink", "oink", "moo")) // Output: // oinky oinky oink // moo moo moo diff --git a/src/testing/sub_test.go b/src/testing/sub_test.go index 9af3909b3556e..29803c06e2f9c 100644 --- a/src/testing/sub_test.go +++ b/src/testing/sub_test.go @@ -594,8 +594,8 @@ func TestBRun(t *T) { func makeRegexp(s string) string { s = regexp.QuoteMeta(s) - s = strings.Replace(s, ":NNN:", `:\d\d\d:`, -1) - s = strings.Replace(s, "N\\.NNs", `\d*\.\d*s`, -1) + s = strings.ReplaceAll(s, ":NNN:", `:\d\d\d:`) + s = strings.ReplaceAll(s, "N\\.NNs", `\d*\.\d*s`) return s } diff --git a/src/text/template/exec.go b/src/text/template/exec.go index 214f72d51b32a..1d04c2982f806 100644 --- a/src/text/template/exec.go +++ b/src/text/template/exec.go @@ -102,7 +102,7 @@ func (s *state) at(node parse.Node) { // doublePercent returns the string with %'s replaced by %%, if necessary, // so it can be used safely inside a Printf format string. func doublePercent(str string) string { - return strings.Replace(str, "%", "%%", -1) + return strings.ReplaceAll(str, "%", "%%") } // TODO: It would be nice if ExecError was more broken down, but From 94f48ddb96c4dfc919ae024f64df19d764f5fb5b Mon Sep 17 00:00:00 2001 From: Ian Gudger Date: Wed, 5 Sep 2018 23:53:36 -0700 Subject: [PATCH 0465/1663] net: fail fast for DNS rcode success with no answers of requested type DNS responses which do not contain answers of the requested type return errNoSuchHost, the same error as rcode name error. Prior to golang.org/cl/37879, both cases resulted in no additional name servers being consulted for the question. That CL changed the behavior for both cases. Issue #25336 was filed about the rcode name error case and golang.org/cl/113815 fixed it. This CL fixes the no answers of requested type case as well. Fixes #27525 Change-Id: I52fadedcd195f16adf62646b76bea2ab3b15d117 Reviewed-on: https://go-review.googlesource.com/133675 Run-TryBot: Ian Gudger TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/net/dnsclient_unix.go | 115 +++++++++++++++----------- src/net/dnsclient_unix_test.go | 143 ++++++++++++++++++++------------- 2 files changed, 158 insertions(+), 100 deletions(-) diff --git a/src/net/dnsclient_unix.go b/src/net/dnsclient_unix.go index 2fee3346e92dc..9a0b1d69a81b1 100644 --- a/src/net/dnsclient_unix.go +++ b/src/net/dnsclient_unix.go @@ -27,6 +27,20 @@ import ( "golang_org/x/net/dns/dnsmessage" ) +var ( + errLameReferral = errors.New("lame referral") + errCannotUnmarshalDNSMessage = errors.New("cannot unmarshal DNS message") + errCannotMarshalDNSMessage = errors.New("cannot marshal DNS message") + errServerMisbehaving = errors.New("server misbehaving") + errInvalidDNSResponse = errors.New("invalid DNS response") + errNoAnswerFromDNSServer = errors.New("no answer from DNS server") + + // errServerTemporarlyMisbehaving is like errServerMisbehaving, except + // that when it gets translated to a DNSError, the IsTemporary field + // gets set to true. + errServerTemporarlyMisbehaving = errors.New("server misbehaving") +) + func newRequest(q dnsmessage.Question) (id uint16, udpReq, tcpReq []byte, err error) { id = uint16(rand.Int()) ^ uint16(time.Now().UnixNano()) b := dnsmessage.NewBuilder(make([]byte, 2, 514), dnsmessage.Header{ID: id, RecursionDesired: true}) @@ -105,14 +119,14 @@ func dnsStreamRoundTrip(c Conn, id uint16, query dnsmessage.Question, b []byte) var p dnsmessage.Parser h, err := p.Start(b[:n]) if err != nil { - return dnsmessage.Parser{}, dnsmessage.Header{}, errors.New("cannot unmarshal DNS message") + return dnsmessage.Parser{}, dnsmessage.Header{}, errCannotUnmarshalDNSMessage } q, err := p.Question() if err != nil { - return dnsmessage.Parser{}, dnsmessage.Header{}, errors.New("cannot unmarshal DNS message") + return dnsmessage.Parser{}, dnsmessage.Header{}, errCannotUnmarshalDNSMessage } if !checkResponse(id, query, h, q) { - return dnsmessage.Parser{}, dnsmessage.Header{}, errors.New("invalid DNS response") + return dnsmessage.Parser{}, dnsmessage.Header{}, errInvalidDNSResponse } return p, h, nil } @@ -122,7 +136,7 @@ func (r *Resolver) exchange(ctx context.Context, server string, q dnsmessage.Que q.Class = dnsmessage.ClassINET id, udpReq, tcpReq, err := newRequest(q) if err != nil { - return dnsmessage.Parser{}, dnsmessage.Header{}, errors.New("cannot marshal DNS message") + return dnsmessage.Parser{}, dnsmessage.Header{}, errCannotMarshalDNSMessage } for _, network := range []string{"udp", "tcp"} { ctx, cancel := context.WithDeadline(ctx, time.Now().Add(timeout)) @@ -147,31 +161,31 @@ func (r *Resolver) exchange(ctx context.Context, server string, q dnsmessage.Que return dnsmessage.Parser{}, dnsmessage.Header{}, mapErr(err) } if err := p.SkipQuestion(); err != dnsmessage.ErrSectionDone { - return dnsmessage.Parser{}, dnsmessage.Header{}, errors.New("invalid DNS response") + return dnsmessage.Parser{}, dnsmessage.Header{}, errInvalidDNSResponse } if h.Truncated { // see RFC 5966 continue } return p, h, nil } - return dnsmessage.Parser{}, dnsmessage.Header{}, errors.New("no answer from DNS server") + return dnsmessage.Parser{}, dnsmessage.Header{}, errNoAnswerFromDNSServer } // checkHeader performs basic sanity checks on the header. func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header, name, server string) error { + if h.RCode == dnsmessage.RCodeNameError { + return errNoSuchHost + } + _, err := p.AnswerHeader() if err != nil && err != dnsmessage.ErrSectionDone { - return &DNSError{ - Err: "cannot unmarshal DNS message", - Name: name, - Server: server, - } + return errCannotUnmarshalDNSMessage } // libresolv continues to the next server when it receives // an invalid referral response. See golang.org/issue/15434. if h.RCode == dnsmessage.RCodeSuccess && !h.Authoritative && !h.RecursionAvailable && err == dnsmessage.ErrSectionDone { - return &DNSError{Err: "lame referral", Name: name, Server: server} + return errLameReferral } if h.RCode != dnsmessage.RCodeSuccess && h.RCode != dnsmessage.RCodeNameError { @@ -180,11 +194,10 @@ func checkHeader(p *dnsmessage.Parser, h dnsmessage.Header, name, server string) // a name error and we didn't get success, // the server is behaving incorrectly or // having temporary trouble. - err := &DNSError{Err: "server misbehaving", Name: name, Server: server} if h.RCode == dnsmessage.RCodeServerFailure { - err.IsTemporary = true + return errServerTemporarlyMisbehaving } - return err + return errServerMisbehaving } return nil @@ -194,28 +207,16 @@ func skipToAnswer(p *dnsmessage.Parser, qtype dnsmessage.Type, name, server stri for { h, err := p.AnswerHeader() if err == dnsmessage.ErrSectionDone { - return &DNSError{ - Err: errNoSuchHost.Error(), - Name: name, - Server: server, - } + return errNoSuchHost } if err != nil { - return &DNSError{ - Err: "cannot unmarshal DNS message", - Name: name, - Server: server, - } + return errCannotUnmarshalDNSMessage } if h.Type == qtype { return nil } if err := p.SkipAnswer(); err != nil { - return &DNSError{ - Err: "cannot unmarshal DNS message", - Name: name, - Server: server, - } + return errCannotUnmarshalDNSMessage } } } @@ -229,7 +230,7 @@ func (r *Resolver) tryOneName(ctx context.Context, cfg *dnsConfig, name string, n, err := dnsmessage.NewName(name) if err != nil { - return dnsmessage.Parser{}, "", errors.New("cannot marshal DNS message") + return dnsmessage.Parser{}, "", errCannotMarshalDNSMessage } q := dnsmessage.Question{ Name: n, @@ -243,38 +244,62 @@ func (r *Resolver) tryOneName(ctx context.Context, cfg *dnsConfig, name string, p, h, err := r.exchange(ctx, server, q, cfg.timeout) if err != nil { - lastErr = &DNSError{ + dnsErr := &DNSError{ Err: err.Error(), Name: name, Server: server, } if nerr, ok := err.(Error); ok && nerr.Timeout() { - lastErr.(*DNSError).IsTimeout = true + dnsErr.IsTimeout = true } // Set IsTemporary for socket-level errors. Note that this flag // may also be used to indicate a SERVFAIL response. if _, ok := err.(*OpError); ok { - lastErr.(*DNSError).IsTemporary = true + dnsErr.IsTemporary = true } + lastErr = dnsErr continue } - // The name does not exist, so trying another server won't help. - // - // TODO: indicate this in a more obvious way, such as a field on DNSError? - if h.RCode == dnsmessage.RCodeNameError { - return dnsmessage.Parser{}, "", &DNSError{Err: errNoSuchHost.Error(), Name: name, Server: server} - } - - lastErr = checkHeader(&p, h, name, server) - if lastErr != nil { + if err := checkHeader(&p, h, name, server); err != nil { + dnsErr := &DNSError{ + Err: err.Error(), + Name: name, + Server: server, + } + if err == errServerTemporarlyMisbehaving { + dnsErr.IsTemporary = true + } + if err == errNoSuchHost { + // The name does not exist, so trying + // another server won't help. + // + // TODO: indicate this in a more + // obvious way, such as a field on + // DNSError? + return p, server, dnsErr + } + lastErr = dnsErr continue } - lastErr = skipToAnswer(&p, qtype, name, server) - if lastErr == nil { + err = skipToAnswer(&p, qtype, name, server) + if err == nil { return p, server, nil } + lastErr = &DNSError{ + Err: err.Error(), + Name: name, + Server: server, + } + if err == errNoSuchHost { + // The name does not exist, so trying another + // server won't help. + // + // TODO: indicate this in a more obvious way, + // such as a field on DNSError? + return p, server, lastErr + } } } return dnsmessage.Parser{}, "", lastErr diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go index bb014b903ab93..9e4ebcc7bbef8 100644 --- a/src/net/dnsclient_unix_test.go +++ b/src/net/dnsclient_unix_test.go @@ -1427,28 +1427,35 @@ func TestDNSGoroutineRace(t *testing.T) { } } +func lookupWithFake(fake fakeDNSServer, name string, typ dnsmessage.Type) error { + r := Resolver{PreferGo: true, Dial: fake.DialContext} + + resolvConf.mu.RLock() + conf := resolvConf.dnsConfig + resolvConf.mu.RUnlock() + + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + _, _, err := r.tryOneName(ctx, conf, name, typ) + return err +} + // Issue 8434: verify that Temporary returns true on an error when rcode // is SERVFAIL func TestIssue8434(t *testing.T) { - msg := dnsmessage.Message{ - Header: dnsmessage.Header{ - RCode: dnsmessage.RCodeServerFailure, + err := lookupWithFake(fakeDNSServer{ + rh: func(n, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) { + return dnsmessage.Message{ + Header: dnsmessage.Header{ + ID: q.ID, + Response: true, + RCode: dnsmessage.RCodeServerFailure, + }, + Questions: q.Questions, + }, nil }, - } - b, err := msg.Pack() - if err != nil { - t.Fatal("Pack failed:", err) - } - var p dnsmessage.Parser - h, err := p.Start(b) - if err != nil { - t.Fatal("Start failed:", err) - } - if err := p.SkipAllQuestions(); err != nil { - t.Fatal("SkipAllQuestions failed:", err) - } - - err = checkHeader(&p, h, "golang.org", "foo:53") + }, "golang.org.", dnsmessage.TypeALL) if err == nil { t.Fatal("expected an error") } @@ -1464,50 +1471,76 @@ func TestIssue8434(t *testing.T) { } } -// Issue 12778: verify that NXDOMAIN without RA bit errors as -// "no such host" and not "server misbehaving" +// TestNoSuchHost verifies that tryOneName works correctly when the domain does +// not exist. +// +// Issue 12778: verify that NXDOMAIN without RA bit errors as "no such host" +// and not "server misbehaving" // // Issue 25336: verify that NXDOMAIN errors fail fast. -func TestIssue12778(t *testing.T) { - lookups := 0 - fake := fakeDNSServer{ - rh: func(n, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) { - lookups++ - return dnsmessage.Message{ - Header: dnsmessage.Header{ - ID: q.ID, - Response: true, - RCode: dnsmessage.RCodeNameError, - RecursionAvailable: false, - }, - Questions: q.Questions, - }, nil +// +// Issue 27525: verify that empty answers fail fast. +func TestNoSuchHost(t *testing.T) { + tests := []struct { + name string + f func(string, string, dnsmessage.Message, time.Time) (dnsmessage.Message, error) + }{ + { + "NXDOMAIN", + func(n, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) { + return dnsmessage.Message{ + Header: dnsmessage.Header{ + ID: q.ID, + Response: true, + RCode: dnsmessage.RCodeNameError, + RecursionAvailable: false, + }, + Questions: q.Questions, + }, nil + }, + }, + { + "no answers", + func(n, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) { + return dnsmessage.Message{ + Header: dnsmessage.Header{ + ID: q.ID, + Response: true, + RCode: dnsmessage.RCodeSuccess, + RecursionAvailable: false, + Authoritative: true, + }, + Questions: q.Questions, + }, nil + }, }, } - r := Resolver{PreferGo: true, Dial: fake.DialContext} - - resolvConf.mu.RLock() - conf := resolvConf.dnsConfig - resolvConf.mu.RUnlock() - ctx, cancel := context.WithCancel(context.Background()) - defer cancel() - - _, _, err := r.tryOneName(ctx, conf, ".", dnsmessage.TypeALL) + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + lookups := 0 + err := lookupWithFake(fakeDNSServer{ + rh: func(n, s string, q dnsmessage.Message, d time.Time) (dnsmessage.Message, error) { + lookups++ + return test.f(n, s, q, d) + }, + }, ".", dnsmessage.TypeALL) - if lookups != 1 { - t.Errorf("got %d lookups, wanted 1", lookups) - } + if lookups != 1 { + t.Errorf("got %d lookups, wanted 1", lookups) + } - if err == nil { - t.Fatal("expected an error") - } - de, ok := err.(*DNSError) - if !ok { - t.Fatalf("err = %#v; wanted a *net.DNSError", err) - } - if de.Err != errNoSuchHost.Error() { - t.Fatalf("Err = %#v; wanted %q", de.Err, errNoSuchHost.Error()) + if err == nil { + t.Fatal("expected an error") + } + de, ok := err.(*DNSError) + if !ok { + t.Fatalf("err = %#v; wanted a *net.DNSError", err) + } + if de.Err != errNoSuchHost.Error() { + t.Fatalf("Err = %#v; wanted %q", de.Err, errNoSuchHost.Error()) + } + }) } } From 10aeb672e0183b63b6e2d59e49c38c8e83ea6113 Mon Sep 17 00:00:00 2001 From: Tim Cooper Date: Wed, 13 Jun 2018 21:19:22 -0300 Subject: [PATCH 0466/1663] image: make RegisterFormat safe for concurrent use Fixes #25884 Change-Id: I5478846ef78aecac32078ea8c3248db52f1bb534 Reviewed-on: https://go-review.googlesource.com/118755 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/image/format.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/image/format.go b/src/image/format.go index 3668de4e6858a..a53b8f9b55488 100644 --- a/src/image/format.go +++ b/src/image/format.go @@ -8,6 +8,8 @@ import ( "bufio" "errors" "io" + "sync" + "sync/atomic" ) // ErrFormat indicates that decoding encountered an unknown format. @@ -21,7 +23,10 @@ type format struct { } // Formats is the list of registered formats. -var formats []format +var ( + formatsMu sync.Mutex + atomicFormats atomic.Value +) // RegisterFormat registers an image format for use by Decode. // Name is the name of the format, like "jpeg" or "png". @@ -30,7 +35,10 @@ var formats []format // Decode is the function that decodes the encoded image. // DecodeConfig is the function that decodes just its configuration. func RegisterFormat(name, magic string, decode func(io.Reader) (Image, error), decodeConfig func(io.Reader) (Config, error)) { - formats = append(formats, format{name, magic, decode, decodeConfig}) + formatsMu.Lock() + formats, _ := atomicFormats.Load().([]format) + atomicFormats.Store(append(formats, format{name, magic, decode, decodeConfig})) + formatsMu.Unlock() } // A reader is an io.Reader that can also peek ahead. @@ -62,6 +70,7 @@ func match(magic string, b []byte) bool { // Sniff determines the format of r's data. func sniff(r reader) format { + formats, _ := atomicFormats.Load().([]format) for _, f := range formats { b, err := r.Peek(len(f.magic)) if err == nil && match(f.magic, b) { From ae9c822f78d5048aa4290b06a5a38f67aaf23dbe Mon Sep 17 00:00:00 2001 From: David Heuschmann Date: Sat, 15 Sep 2018 13:04:59 +0200 Subject: [PATCH 0467/1663] cmd/compile: use more specific error message for assignment mismatch Show a more specifc error message in the form of "%d variables but %v returns %d values" if an assignment mismatch occurs with a function or method call on the right. Fixes #27595 Change-Id: Ibc97d070662b08f150ac22d686059cf224e012ab Reviewed-on: https://go-review.googlesource.com/135575 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/cmd/compile/internal/gc/typecheck.go | 9 +++++++-- test/fixedbugs/issue26616.go | 10 +++++----- test/fixedbugs/issue27595.go | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 test/fixedbugs/issue27595.go diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 69dced00ac729..24aba6bac4d1e 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -3341,7 +3341,7 @@ func typecheckas(n *Node) { checkassign(n, n.Left) if n.Right != nil && n.Right.Type != nil { if n.Right.Type.IsFuncArgStruct() { - yyerror("assignment mismatch: 1 variable but %d values", n.Right.Type.NumFields()) + yyerror("assignment mismatch: 1 variable but %v returns %d values", n.Right.Left, n.Right.Type.NumFields()) // Multi-value RHS isn't actually valid for OAS; nil out // to indicate failed typechecking. n.Right.Type = nil @@ -3486,7 +3486,12 @@ func typecheckas2(n *Node) { } mismatch: - yyerror("assignment mismatch: %d variables but %d values", cl, cr) + switch r.Op { + default: + yyerror("assignment mismatch: %d variable but %d values", cl, cr) + case OCALLFUNC, OCALLMETH, OCALLINTER: + yyerror("assignment mismatch: %d variables but %v returns %d values", cl, r.Left, cr) + } // second half of dance out: diff --git a/test/fixedbugs/issue26616.go b/test/fixedbugs/issue26616.go index 46136dc68f532..e5565b68ca55a 100644 --- a/test/fixedbugs/issue26616.go +++ b/test/fixedbugs/issue26616.go @@ -6,13 +6,13 @@ package p -var x int = three() // ERROR "1 variable but 3 values" +var x int = three() // ERROR "assignment mismatch: 1 variable but three returns 3 values" func f() { - var _ int = three() // ERROR "1 variable but 3 values" - var a int = three() // ERROR "1 variable but 3 values" - a = three() // ERROR "1 variable but 3 values" - b := three() // ERROR "1 variable but 3 values" + var _ int = three() // ERROR "assignment mismatch: 1 variable but three returns 3 values" + var a int = three() // ERROR "assignment mismatch: 1 variable but three returns 3 values" + a = three() // ERROR "assignment mismatch: 1 variable but three returns 3 values" + b := three() // ERROR "assignment mismatch: 1 variable but three returns 3 values" _, _ = a, b } diff --git a/test/fixedbugs/issue27595.go b/test/fixedbugs/issue27595.go new file mode 100644 index 0000000000000..af5c7a10d9b01 --- /dev/null +++ b/test/fixedbugs/issue27595.go @@ -0,0 +1,19 @@ +// errorcheck + +// Copyright 2018 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. + +package main + +var a = twoResults() // ERROR "assignment mismatch: 1 variable but twoResults returns 2 values" +var b, c, d = twoResults() // ERROR "assignment mismatch: 3 variables but twoResults returns 2 values" +var e, f = oneResult() // ERROR "assignment mismatch: 2 variables but oneResult returns 1 values" + +func twoResults() (int, int) { + return 1, 2 +} + +func oneResult() int { + return 1 +} From 9c81402f58ae83987f32153c1587c9f03b4a5769 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Tue, 25 Sep 2018 15:31:23 -0700 Subject: [PATCH 0468/1663] go/internal/gccgoimporter: fix updating of "forward declared" types The existing code uses a type map which associates a type number with a type; references to existing types are expressed via the type number in the export data. Before this CL, type map entries were set when a type was read in completely, which meant that recursive references to types (i.e., type map entries) that were in the middle of construction (i.e., where the type map was not yet updated) would lead to nil types. Such cycles are usually created via defined types which introduce a types.Named entry into the type map before the underlying type is parsed; in this case the code worked. In case of type aliases, no such "forwarder" exists and type cycles lead to nil types. This CL fixes the problem by a) updating the type map as soon as a type becomes available but before the type's components are parsed; b) keeping track of a list of type map entries that may need to be updated together (because of aliases that may all refer to the same type); and c) adding (redundant) markers to the type map to detect algorithmic errors. Also: - distinguish between parseInt and parseInt64 - added more test cases Fixes #27856. Change-Id: Iba701439ea3231aa435b7b80ea2d419db2af3be1 Reviewed-on: https://go-review.googlesource.com/137857 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- .../internal/gccgoimporter/importer_test.go | 4 +- src/go/internal/gccgoimporter/parser.go | 224 ++++++++++++------ .../gccgoimporter/testdata/aliases.go | 65 +++++ .../gccgoimporter/testdata/aliases.gox | 33 +++ .../gccgoimporter/testdata/issue27856.go | 9 + .../gccgoimporter/testdata/issue27856.gox | 9 + 6 files changed, 275 insertions(+), 69 deletions(-) create mode 100644 src/go/internal/gccgoimporter/testdata/aliases.go create mode 100644 src/go/internal/gccgoimporter/testdata/aliases.gox create mode 100644 src/go/internal/gccgoimporter/testdata/issue27856.go create mode 100644 src/go/internal/gccgoimporter/testdata/issue27856.gox diff --git a/src/go/internal/gccgoimporter/importer_test.go b/src/go/internal/gccgoimporter/importer_test.go index 5a699687bd4e8..15494fd6b38f6 100644 --- a/src/go/internal/gccgoimporter/importer_test.go +++ b/src/go/internal/gccgoimporter/importer_test.go @@ -102,8 +102,10 @@ var importerTests = [...]importerTest{ {pkgpath: "unicode", name: "MaxRune", want: "const MaxRune untyped rune", wantval: "1114111"}, {pkgpath: "imports", wantinits: []string{"imports..import", "fmt..import", "math..import"}}, {pkgpath: "importsar", name: "Hello", want: "var Hello string"}, - {pkgpath: "alias", name: "IntAlias2", want: "type IntAlias2 = Int"}, + {pkgpath: "aliases", name: "A14", want: "type A14 = func(int, T0) chan T2"}, + {pkgpath: "aliases", name: "C0", want: "type C0 struct{f1 C1; f2 C1}"}, {pkgpath: "escapeinfo", name: "NewT", want: "func NewT(data []byte) *T"}, + {pkgpath: "issue27856", name: "M", want: "type M struct{E F}"}, } func TestGoxImporter(t *testing.T) { diff --git a/src/go/internal/gccgoimporter/parser.go b/src/go/internal/gccgoimporter/parser.go index 9f8c19b63887e..f64be54d663ce 100644 --- a/src/go/internal/gccgoimporter/parser.go +++ b/src/go/internal/gccgoimporter/parser.go @@ -378,52 +378,80 @@ func (p *parser) parseConst(pkg *types.Package) *types.Const { return types.NewConst(token.NoPos, pkg, name, typ, val) } +// reserved is a singleton type used to fill type map slots that have +// been reserved (i.e., for which a type number has been parsed) but +// which don't have their actual type yet. When the type map is updated, +// the actual type must replace a reserved entry (or we have an internal +// error). Used for self-verification only - not required for correctness. +var reserved = new(struct{ types.Type }) + +// reserve reserves the type map entry n for future use. +func (p *parser) reserve(n int) { + if p.typeMap[n] != nil { + p.errorf("internal error: type %d already used", n) + } + p.typeMap[n] = reserved +} + +// update sets the type map entries for the given type numbers nlist to t. +func (p *parser) update(t types.Type, nlist []int) { + for _, n := range nlist { + if p.typeMap[n] != reserved { + p.errorf("internal error: typeMap[%d] not reserved", n) + } + p.typeMap[n] = t + } +} + // NamedType = TypeName [ "=" ] Type { Method } . // TypeName = ExportedName . // Method = "func" "(" Param ")" Name ParamList ResultList ";" . -func (p *parser) parseNamedType(n int) types.Type { +func (p *parser) parseNamedType(nlist []int) types.Type { pkg, name := p.parseExportedName() scope := pkg.Scope() + obj := scope.Lookup(name) + if obj != nil && obj.Type() == nil { + p.errorf("%v has nil type", obj) + } + // type alias if p.tok == '=' { - // type alias p.next() - typ := p.parseType(pkg) - if obj := scope.Lookup(name); obj != nil { - typ = obj.Type() // use previously imported type - if typ == nil { - p.errorf("%v (type alias) used in cycle", obj) - } - } else { - obj = types.NewTypeName(token.NoPos, pkg, name, typ) - scope.Insert(obj) + if obj != nil { + // use the previously imported (canonical) type + t := obj.Type() + p.update(t, nlist) + p.parseType(pkg) // discard + return t } - p.typeMap[n] = typ - return typ + t := p.parseType(pkg, nlist...) + obj = types.NewTypeName(token.NoPos, pkg, name, t) + scope.Insert(obj) + return t } - // named type - obj := scope.Lookup(name) + // defined type if obj == nil { - // a named type may be referred to before the underlying type - // is known - set it up + // A named type may be referred to before the underlying type + // is known - set it up. tname := types.NewTypeName(token.NoPos, pkg, name, nil) types.NewNamed(tname, nil, nil) scope.Insert(tname) obj = tname } - typ := obj.Type() - p.typeMap[n] = typ + // use the previously imported (canonical), or newly created type + t := obj.Type() + p.update(t, nlist) - nt, ok := typ.(*types.Named) + nt, ok := t.(*types.Named) if !ok { // This can happen for unsafe.Pointer, which is a TypeName holding a Basic type. pt := p.parseType(pkg) - if pt != typ { + if pt != t { p.error("unexpected underlying type for non-named TypeName") } - return typ + return t } underlying := p.parseType(pkg) @@ -449,41 +477,70 @@ func (p *parser) parseNamedType(n int) types.Type { return nt } -func (p *parser) parseInt() int64 { +func (p *parser) parseInt64() int64 { lit := p.expect(scanner.Int) - n, err := strconv.ParseInt(lit, 10, 0) + n, err := strconv.ParseInt(lit, 10, 64) if err != nil { p.error(err) } return n } +func (p *parser) parseInt() int { + lit := p.expect(scanner.Int) + n, err := strconv.ParseInt(lit, 10, 0 /* int */) + if err != nil { + p.error(err) + } + return int(n) +} + // ArrayOrSliceType = "[" [ int ] "]" Type . -func (p *parser) parseArrayOrSliceType(pkg *types.Package) types.Type { +func (p *parser) parseArrayOrSliceType(pkg *types.Package, nlist []int) types.Type { p.expect('[') if p.tok == ']' { p.next() - return types.NewSlice(p.parseType(pkg)) + + t := new(types.Slice) + p.update(t, nlist) + + *t = *types.NewSlice(p.parseType(pkg)) + return t } - n := p.parseInt() + t := new(types.Array) + p.update(t, nlist) + + len := p.parseInt64() p.expect(']') - return types.NewArray(p.parseType(pkg), n) + + *t = *types.NewArray(p.parseType(pkg), len) + return t } // MapType = "map" "[" Type "]" Type . -func (p *parser) parseMapType(pkg *types.Package) types.Type { +func (p *parser) parseMapType(pkg *types.Package, nlist []int) types.Type { p.expectKeyword("map") + + t := new(types.Map) + p.update(t, nlist) + p.expect('[') key := p.parseType(pkg) p.expect(']') elem := p.parseType(pkg) - return types.NewMap(key, elem) + + *t = *types.NewMap(key, elem) + return t } // ChanType = "chan" ["<-" | "-<"] Type . -func (p *parser) parseChanType(pkg *types.Package) types.Type { +func (p *parser) parseChanType(pkg *types.Package, nlist []int) types.Type { p.expectKeyword("chan") + + t := new(types.Chan) + p.update(t, nlist) + dir := types.SendRecv switch p.tok { case '-': @@ -500,13 +557,17 @@ func (p *parser) parseChanType(pkg *types.Package) types.Type { } } - return types.NewChan(dir, p.parseType(pkg)) + *t = *types.NewChan(dir, p.parseType(pkg)) + return t } // StructType = "struct" "{" { Field } "}" . -func (p *parser) parseStructType(pkg *types.Package) types.Type { +func (p *parser) parseStructType(pkg *types.Package, nlist []int) types.Type { p.expectKeyword("struct") + t := new(types.Struct) + p.update(t, nlist) + var fields []*types.Var var tags []string @@ -519,7 +580,8 @@ func (p *parser) parseStructType(pkg *types.Package) types.Type { } p.expect('}') - return types.NewStruct(fields, tags) + *t = *types.NewStruct(fields, tags) + return t } // ParamList = "(" [ { Parameter "," } Parameter ] ")" . @@ -562,10 +624,15 @@ func (p *parser) parseResultList(pkg *types.Package) *types.Tuple { } // FunctionType = ParamList ResultList . -func (p *parser) parseFunctionType(pkg *types.Package) *types.Signature { +func (p *parser) parseFunctionType(pkg *types.Package, nlist []int) *types.Signature { + t := new(types.Signature) + p.update(t, nlist) + params, isVariadic := p.parseParamList(pkg) results := p.parseResultList(pkg) - return types.NewSignature(nil, params, results, isVariadic) + + *t = *types.NewSignature(nil, params, results, isVariadic) + return t } // Func = Name FunctionType . @@ -577,13 +644,16 @@ func (p *parser) parseFunc(pkg *types.Package) *types.Func { p.discardDirectiveWhileParsingTypes(pkg) return nil } - return types.NewFunc(token.NoPos, pkg, name, p.parseFunctionType(pkg)) + return types.NewFunc(token.NoPos, pkg, name, p.parseFunctionType(pkg, nil)) } // InterfaceType = "interface" "{" { ("?" Type | Func) ";" } "}" . -func (p *parser) parseInterfaceType(pkg *types.Package) types.Type { +func (p *parser) parseInterfaceType(pkg *types.Package, nlist []int) types.Type { p.expectKeyword("interface") + t := new(types.Interface) + p.update(t, nlist) + var methods []*types.Func var embeddeds []types.Type @@ -600,53 +670,61 @@ func (p *parser) parseInterfaceType(pkg *types.Package) types.Type { } p.expect('}') - return types.NewInterfaceType(methods, embeddeds) + *t = *types.NewInterfaceType(methods, embeddeds) + return t } // PointerType = "*" ("any" | Type) . -func (p *parser) parsePointerType(pkg *types.Package) types.Type { +func (p *parser) parsePointerType(pkg *types.Package, nlist []int) types.Type { p.expect('*') if p.tok == scanner.Ident { p.expectKeyword("any") - return types.Typ[types.UnsafePointer] + t := types.Typ[types.UnsafePointer] + p.update(t, nlist) + return t } - return types.NewPointer(p.parseType(pkg)) + + t := new(types.Pointer) + p.update(t, nlist) + + *t = *types.NewPointer(p.parseType(pkg)) + + return t } -// TypeDefinition = NamedType | MapType | ChanType | StructType | InterfaceType | PointerType | ArrayOrSliceType | FunctionType . -func (p *parser) parseTypeDefinition(pkg *types.Package, n int) types.Type { - var t types.Type +// TypeSpec = NamedType | MapType | ChanType | StructType | InterfaceType | PointerType | ArrayOrSliceType | FunctionType . +func (p *parser) parseTypeSpec(pkg *types.Package, nlist []int) types.Type { switch p.tok { case scanner.String: - t = p.parseNamedType(n) + return p.parseNamedType(nlist) case scanner.Ident: switch p.lit { case "map": - t = p.parseMapType(pkg) + return p.parseMapType(pkg, nlist) case "chan": - t = p.parseChanType(pkg) + return p.parseChanType(pkg, nlist) case "struct": - t = p.parseStructType(pkg) + return p.parseStructType(pkg, nlist) case "interface": - t = p.parseInterfaceType(pkg) + return p.parseInterfaceType(pkg, nlist) } case '*': - t = p.parsePointerType(pkg) + return p.parsePointerType(pkg, nlist) case '[': - t = p.parseArrayOrSliceType(pkg) + return p.parseArrayOrSliceType(pkg, nlist) case '(': - t = p.parseFunctionType(pkg) + return p.parseFunctionType(pkg, nlist) } - p.typeMap[n] = t - return t + p.errorf("expected type name or literal, got %s", scanner.TokenString(p.tok)) + return nil } const ( @@ -700,29 +778,39 @@ func lookupBuiltinType(typ int) types.Type { }[typ] } -// Type = "<" "type" ( "-" int | int [ TypeDefinition ] ) ">" . -func (p *parser) parseType(pkg *types.Package) (t types.Type) { +// Type = "<" "type" ( "-" int | int [ TypeSpec ] ) ">" . +// +// parseType updates the type map to t for all type numbers n. +// +func (p *parser) parseType(pkg *types.Package, n ...int) (t types.Type) { p.expect('<') p.expectKeyword("type") switch p.tok { case scanner.Int: - n := p.parseInt() - + n1 := p.parseInt() if p.tok == '>' { - t = p.typeMap[int(n)] + t = p.typeMap[n1] + switch t { + case nil: + p.errorf("invalid type number, type %d not yet declared", n1) + case reserved: + p.errorf("invalid type cycle, type %d not yet defined", n1) + } + p.update(t, n) } else { - t = p.parseTypeDefinition(pkg, int(n)) + p.reserve(n1) + t = p.parseTypeSpec(pkg, append(n, n1)) } case '-': p.next() - n := p.parseInt() - t = lookupBuiltinType(int(n)) + n1 := p.parseInt() + t = lookupBuiltinType(n1) + p.update(t, n) default: p.errorf("expected type number, got %s (%q)", scanner.TokenString(p.tok), p.lit) - return nil } p.expect('>') @@ -735,7 +823,7 @@ func (p *parser) parsePackageInit() PackageInit { initfunc := p.parseUnquotedString() priority := -1 if p.version == "v1" { - priority = int(p.parseInt()) + priority = p.parseInt() } return PackageInit{Name: name, InitFunc: initfunc, Priority: priority} } @@ -781,7 +869,7 @@ func (p *parser) parseInitDataDirective() { case "priority": p.next() - p.initdata.Priority = int(p.parseInt()) + p.initdata.Priority = p.parseInt() p.expect(';') case "init": @@ -795,8 +883,8 @@ func (p *parser) parseInitDataDirective() { p.next() // The graph data is thrown away for now. for p.tok != ';' && p.tok != scanner.EOF { - p.parseInt() - p.parseInt() + p.parseInt64() + p.parseInt64() } p.expect(';') diff --git a/src/go/internal/gccgoimporter/testdata/aliases.go b/src/go/internal/gccgoimporter/testdata/aliases.go new file mode 100644 index 0000000000000..cfb59b3e315ba --- /dev/null +++ b/src/go/internal/gccgoimporter/testdata/aliases.go @@ -0,0 +1,65 @@ +package aliases + +type ( + T0 [10]int + T1 []byte + T2 struct { + x int + } + T3 interface { + m() T2 + } + T4 func(int, T0) chan T2 +) + +// basic aliases +type ( + Ai = int + A0 = T0 + A1 = T1 + A2 = T2 + A3 = T3 + A4 = T4 + + A10 = [10]int + A11 = []byte + A12 = struct { + x int + } + A13 = interface { + m() A2 + } + A14 = func(int, A0) chan A2 +) + +// alias receiver types +func (T0) m1() {} +func (A0) m2() {} + +// alias receiver types (long type declaration chains) +type ( + V0 = V1 + V1 = (V2) + V2 = (V3) + V3 = T0 +) + +func (V1) n() {} + +// cycles +type C0 struct { + f1 C1 + f2 C2 +} + +type ( + C1 *C0 + C2 = C1 +) + +type ( + C5 struct { + f *C6 + } + C6 = C5 +) diff --git a/src/go/internal/gccgoimporter/testdata/aliases.gox b/src/go/internal/gccgoimporter/testdata/aliases.gox new file mode 100644 index 0000000000000..2428c06874368 --- /dev/null +++ b/src/go/internal/gccgoimporter/testdata/aliases.gox @@ -0,0 +1,33 @@ +v2; +package aliases; +prefix go; +package aliases go.aliases go.aliases; +type > + func (? ) .go.aliases.m1 (); + func (? ) .go.aliases.m2 (); + func (? >>>) .go.aliases.n (); +>>; +type >>>; +type >>; +type >>; +type ; }>>; +type ; }>>>; }>>; +type , ? ) >>>; +type ; +type ; }>>>; +type , ? ) >>>>; +type >; +type >>; .go.aliases.f2 >; }>>; +type ; +type ; +type >>; }>>; +type ; +type ; +type ; +type ; +type ; +type ; +type >; +type ; +type ; +type ; diff --git a/src/go/internal/gccgoimporter/testdata/issue27856.go b/src/go/internal/gccgoimporter/testdata/issue27856.go new file mode 100644 index 0000000000000..bf361e1cd803b --- /dev/null +++ b/src/go/internal/gccgoimporter/testdata/issue27856.go @@ -0,0 +1,9 @@ +package lib + +type M struct { + E E +} +type F struct { + _ *M +} +type E = F diff --git a/src/go/internal/gccgoimporter/testdata/issue27856.gox b/src/go/internal/gccgoimporter/testdata/issue27856.gox new file mode 100644 index 0000000000000..6665e64021b95 --- /dev/null +++ b/src/go/internal/gccgoimporter/testdata/issue27856.gox @@ -0,0 +1,9 @@ +v2; +package main; +pkgpath main; +import runtime runtime "runtime"; +init runtime runtime..import sys runtime_internal_sys..import; +init_graph 0 1; +type ; }>>>; }>>>; +type ; +type ; From d1594055ccb667882b7be2a3224abc14f13f6737 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 26 Sep 2018 16:56:19 -0700 Subject: [PATCH 0469/1663] go/internal/gccgoimporter: use a slice instead of a map for type map (optimization) ggcgo's export format numbers types consecutively, starting at 1. This makes it trivially possible to use a slice (list) instead of map for the internal types map. Change-Id: Ib7814d7fabffac0ad2b56f04a5dad7d6d4c4dd0e Reviewed-on: https://go-review.googlesource.com/137935 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/go/internal/gccgoimporter/parser.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/src/go/internal/gccgoimporter/parser.go b/src/go/internal/gccgoimporter/parser.go index f64be54d663ce..9a94c3369e943 100644 --- a/src/go/internal/gccgoimporter/parser.go +++ b/src/go/internal/gccgoimporter/parser.go @@ -26,7 +26,7 @@ type parser struct { pkgname string // name of imported package pkg *types.Package // reference to imported package imports map[string]*types.Package // package path -> package object - typeMap map[int]types.Type // type number -> type + typeList []types.Type // type number -> type initdata InitData // package init priority data } @@ -38,7 +38,7 @@ func (p *parser) init(filename string, src io.Reader, imports map[string]*types. p.scanner.Filename = filename // for good error messages p.next() p.imports = imports - p.typeMap = make(map[int]types.Type) + p.typeList = make([]types.Type, 1 /* type numbers start at 1 */, 16) } type importError struct { @@ -387,19 +387,19 @@ var reserved = new(struct{ types.Type }) // reserve reserves the type map entry n for future use. func (p *parser) reserve(n int) { - if p.typeMap[n] != nil { - p.errorf("internal error: type %d already used", n) + if n != len(p.typeList) { + p.errorf("invalid type number %d (out of sync)", n) } - p.typeMap[n] = reserved + p.typeList = append(p.typeList, reserved) } // update sets the type map entries for the given type numbers nlist to t. func (p *parser) update(t types.Type, nlist []int) { for _, n := range nlist { - if p.typeMap[n] != reserved { - p.errorf("internal error: typeMap[%d] not reserved", n) + if p.typeList[n] != reserved { + p.errorf("typeMap[%d] not reserved", n) } - p.typeMap[n] = t + p.typeList[n] = t } } @@ -790,11 +790,8 @@ func (p *parser) parseType(pkg *types.Package, n ...int) (t types.Type) { case scanner.Int: n1 := p.parseInt() if p.tok == '>' { - t = p.typeMap[n1] - switch t { - case nil: - p.errorf("invalid type number, type %d not yet declared", n1) - case reserved: + t = p.typeList[n1] + if t == reserved { p.errorf("invalid type cycle, type %d not yet defined", n1) } p.update(t, n) @@ -986,7 +983,7 @@ func (p *parser) parsePackage() *types.Package { for p.tok != scanner.EOF { p.parseDirective() } - for _, typ := range p.typeMap { + for _, typ := range p.typeList { if it, ok := typ.(*types.Interface); ok { it.Complete() } From 141eacd27298c1d9f6019f0d1bde90ad8d07bebe Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Wed, 26 Sep 2018 20:19:14 -0700 Subject: [PATCH 0470/1663] go/internal/gccgo: remove unused test file Follow-up on https://go-review.googlesource.com/c/go/+/137857/4 which didn't remove this test file after it was removed from the list of importer tests in importer_test.go. Change-Id: Ib89cb3a6d976115da42c33443529ea27bd1ce838 Reviewed-on: https://go-review.googlesource.com/137975 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/go/internal/gccgoimporter/testdata/alias.gox | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/go/internal/gccgoimporter/testdata/alias.gox diff --git a/src/go/internal/gccgoimporter/testdata/alias.gox b/src/go/internal/gccgoimporter/testdata/alias.gox deleted file mode 100644 index ced7d84c4f615..0000000000000 --- a/src/go/internal/gccgoimporter/testdata/alias.gox +++ /dev/null @@ -1,4 +0,0 @@ -v1; -package alias; -pkgpath alias; -type >>>) < type 114>; M2 () ; }>>; From bf70ba07014c15e0b58a308080aa568c8a35f532 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Wed, 19 Sep 2018 12:46:09 +0530 Subject: [PATCH 0471/1663] go/build: clarify that there are no build tags for minor releases Fixes #26458 Change-Id: If932718ca8a2b230ab52495c1a7a82d86ab1325b Reviewed-on: https://go-review.googlesource.com/136215 Reviewed-by: Ian Lance Taylor --- src/go/build/doc.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/go/build/doc.go b/src/go/build/doc.go index 69613e359c24c..d803b8967b6df 100644 --- a/src/go/build/doc.go +++ b/src/go/build/doc.go @@ -110,6 +110,9 @@ // - "go1.11", from Go version 1.11 onward // - any additional words listed in ctxt.BuildTags // +// There are no build tags for beta or minor releases. Programs that need the +// minor release number can call runtime.Version. +// // If a file's name, after stripping the extension and a possible _test suffix, // matches any of the following patterns: // *_GOOS From 4ba4c5ae795f30f167faef7c15dba3e32afc53d0 Mon Sep 17 00:00:00 2001 From: esell Date: Thu, 30 Aug 2018 12:22:53 -0600 Subject: [PATCH 0472/1663] net/http: add http.NotFoundHandler example Change-Id: I6a69c7a5b829a967d75e1c79210a4906c0d8f505 Reviewed-on: https://go-review.googlesource.com/132276 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/example_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/net/http/example_test.go b/src/net/http/example_test.go index f5c47d0bd4461..2a09f5f6c6965 100644 --- a/src/net/http/example_test.go +++ b/src/net/http/example_test.go @@ -173,3 +173,21 @@ func ExampleHandleFunc() { log.Fatal(http.ListenAndServe(":8080", nil)) } + +func newPeopleHandler() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + fmt.Fprintln(w, "This is the people handler.") + }) +} + +func ExampleNotFoundHandler() { + mux := http.NewServeMux() + + // Create sample handler to returns 404 + mux.Handle("/resources", http.NotFoundHandler()) + + // Create sample handler that returns 200 + mux.Handle("/resources/people/", newPeopleHandler()) + + log.Fatal(http.ListenAndServe(":8080", mux)) +} From 1c8943bd59157878141faab0c93848f45d3d51d1 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Tue, 25 Sep 2018 11:52:24 +0200 Subject: [PATCH 0473/1663] cmd/link: move DIE of global variables to their compile unit The DIEs for global variables were all assigned to the first emitted compile unit in debug_info, regardless of what it was. Move them instead to their respective compile units. Change-Id: If794fa0ba4702f5b959c6e8c16119b16e7ecf6d8 Reviewed-on: https://go-review.googlesource.com/137235 Reviewed-by: Than McIntosh --- .../compile/internal/ssa/stmtlines_test.go | 3 + src/cmd/internal/dwarf/dwarf.go | 13 ++ src/cmd/link/dwarf_test.go | 3 + src/cmd/link/internal/ld/dwarf.go | 126 ++++++++++-------- src/cmd/link/internal/objfile/objfile.go | 2 +- 5 files changed, 88 insertions(+), 59 deletions(-) diff --git a/src/cmd/compile/internal/ssa/stmtlines_test.go b/src/cmd/compile/internal/ssa/stmtlines_test.go index 1081f83f6d278..c0fc7adab5449 100644 --- a/src/cmd/compile/internal/ssa/stmtlines_test.go +++ b/src/cmd/compile/internal/ssa/stmtlines_test.go @@ -62,6 +62,9 @@ func TestStmtLines(t *testing.T) { if pkgname == "runtime" { continue } + if e.Val(dwarf.AttrStmtList) == nil { + continue + } lrdr, err := dw.LineReader(e) must(err) diff --git a/src/cmd/internal/dwarf/dwarf.go b/src/cmd/internal/dwarf/dwarf.go index 96fb2b765b8eb..355091fedaa20 100644 --- a/src/cmd/internal/dwarf/dwarf.go +++ b/src/cmd/internal/dwarf/dwarf.go @@ -304,6 +304,7 @@ const ( const ( DW_ABRV_NULL = iota DW_ABRV_COMPUNIT + DW_ABRV_COMPUNIT_TEXTLESS DW_ABRV_FUNCTION DW_ABRV_FUNCTION_ABSTRACT DW_ABRV_FUNCTION_CONCRETE @@ -368,6 +369,18 @@ var abbrevs = [DW_NABRV]dwAbbrev{ }, }, + /* COMPUNIT_TEXTLESS */ + { + DW_TAG_compile_unit, + DW_CHILDREN_yes, + []dwAttrForm{ + {DW_AT_name, DW_FORM_string}, + {DW_AT_language, DW_FORM_data1}, + {DW_AT_comp_dir, DW_FORM_string}, + {DW_AT_producer, DW_FORM_string}, + }, + }, + /* FUNCTION */ { DW_TAG_subprogram, diff --git a/src/cmd/link/dwarf_test.go b/src/cmd/link/dwarf_test.go index ff11689bbccc0..2c01456f6b0e3 100644 --- a/src/cmd/link/dwarf_test.go +++ b/src/cmd/link/dwarf_test.go @@ -122,6 +122,9 @@ func testDWARF(t *testing.T, buildmode string, expectDWARF bool, env ...string) r.SkipChildren() continue } + if cu.Val(dwarf.AttrStmtList) == nil { + continue + } lr, err := d.LineReader(cu) if err != nil { t.Fatal(err) diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index 2164fa80a0f2b..743f4cedd4bf7 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -5,7 +5,7 @@ // TODO/NICETOHAVE: // - eliminate DW_CLS_ if not used // - package info in compilation units -// - assign global variables and types to their packages +// - assign types to their packages // - gdb uses c syntax, meaning clumsy quoting is needed for go identifiers. eg // ptype struct '[]uint8' and qualifiers need to be quoted away // - file:line info for variables @@ -106,15 +106,8 @@ func writeabbrev(ctxt *Link) *sym.Symbol { return s } -/* - * Root DIEs for compilation units, types and global variables. - */ -var dwroot dwarf.DWDie - var dwtypes dwarf.DWDie -var dwglobals dwarf.DWDie - func newattr(die *dwarf.DWDie, attr uint16, cls int, value int64, data interface{}) *dwarf.DWAttr { a := new(dwarf.DWAttr) a.Link = die.Attr @@ -835,7 +828,11 @@ func synthesizechantypes(ctxt *Link, die *dwarf.DWDie) { } func dwarfDefineGlobal(ctxt *Link, s *sym.Symbol, str string, v int64, gotype *sym.Symbol) { - dv := newdie(ctxt, &dwglobals, dwarf.DW_ABRV_VARIABLE, str, int(s.Version)) + lib := s.Lib + if lib == nil { + lib = ctxt.LibraryByPkg["runtime"] + } + dv := newdie(ctxt, ctxt.compUnitByPackage[lib].dwinfo, dwarf.DW_ABRV_VARIABLE, str, int(s.Version)) newabslocexprattr(dv, v, s) if s.Version == 0 { newattr(dv, dwarf.DW_AT_external, dwarf.DW_CLS_FLAG, 1, 0) @@ -910,10 +907,11 @@ func calcCompUnitRanges(ctxt *Link) { } } -func movetomodule(parent *dwarf.DWDie) { - die := dwroot.Child.Child +func movetomodule(ctxt *Link, parent *dwarf.DWDie) { + runtimelib := ctxt.LibraryByPkg["runtime"] + die := ctxt.compUnitByPackage[runtimelib].dwinfo.Child if die == nil { - dwroot.Child.Child = parent.Child + ctxt.compUnitByPackage[runtimelib].dwinfo.Child = parent.Child return } for die.Link != nil { @@ -1067,7 +1065,7 @@ func importInfoSymbol(ctxt *Link, dsym *sym.Symbol) { } } -func writelines(ctxt *Link, unit *compilationUnit, ls *sym.Symbol) (dwinfo *dwarf.DWDie) { +func writelines(ctxt *Link, unit *compilationUnit, ls *sym.Symbol) { var dwarfctxt dwarf.Context = dwctxt{ctxt} is_stmt := uint8(1) // initially = recommended default_is_stmt = 1, tracks is_stmt toggles. @@ -1076,29 +1074,7 @@ func writelines(ctxt *Link, unit *compilationUnit, ls *sym.Symbol) (dwinfo *dwar headerstart := int64(-1) headerend := int64(-1) - lang := dwarf.DW_LANG_Go - - dwinfo = newdie(ctxt, &dwroot, dwarf.DW_ABRV_COMPUNIT, unit.lib.Pkg, 0) - newattr(dwinfo, dwarf.DW_AT_language, dwarf.DW_CLS_CONSTANT, int64(lang), 0) - newattr(dwinfo, dwarf.DW_AT_stmt_list, dwarf.DW_CLS_PTR, ls.Size, ls) - // OS X linker requires compilation dir or absolute path in comp unit name to output debug info. - compDir := getCompilationDir() - // TODO: Make this be the actual compilation directory, not - // the linker directory. If we move CU construction into the - // compiler, this should happen naturally. - newattr(dwinfo, dwarf.DW_AT_comp_dir, dwarf.DW_CLS_STRING, int64(len(compDir)), compDir) - producerExtra := ctxt.Syms.Lookup(dwarf.CUInfoPrefix+"producer."+unit.lib.Pkg, 0) - producer := "Go cmd/compile " + objabi.Version - if len(producerExtra.P) > 0 { - // We put a semicolon before the flags to clearly - // separate them from the version, which can be long - // and have lots of weird things in it in development - // versions. We promise not to put a semicolon in the - // version, so it should be safe for readers to scan - // forward to the semicolon. - producer += "; " + string(producerExtra.P) - } - newattr(dwinfo, dwarf.DW_AT_producer, dwarf.DW_CLS_STRING, int64(len(producer)), producer) + newattr(unit.dwinfo, dwarf.DW_AT_stmt_list, dwarf.DW_CLS_PTR, ls.Size, ls) // Write .debug_line Line Number Program Header (sec 6.2.4) // Fields marked with (*) must be changed for 64-bit dwarf @@ -1300,8 +1276,6 @@ func writelines(ctxt *Link, unit *compilationUnit, ls *sym.Symbol) (dwinfo *dwar } } } - - return dwinfo } // writepcranges generates the DW_AT_ranges table for compilation unit cu. @@ -1468,15 +1442,13 @@ func writeinfo(ctxt *Link, syms []*sym.Symbol, units []*compilationUnit, abbrevs var dwarfctxt dwarf.Context = dwctxt{ctxt} - // Re-index per-package information by its CU die. - unitByDIE := make(map[*dwarf.DWDie]*compilationUnit) for _, u := range units { - unitByDIE[u.dwinfo] = u - } - - for compunit := dwroot.Child; compunit != nil; compunit = compunit.Link { + compunit := u.dwinfo s := dtolsym(compunit.Sym) - u := unitByDIE[compunit] + + if len(u.lib.Textp) == 0 && u.dwinfo.Child == nil { + continue + } // Write .debug_info Compilation Unit Header (sec 7.5.1) // Fields marked with (*) must be changed for 64-bit dwarf @@ -1536,7 +1508,11 @@ func writepub(ctxt *Link, sname string, ispub func(*dwarf.DWDie) bool, syms []*s s.Type = sym.SDWARFSECT syms = append(syms, s) - for compunit := dwroot.Child; compunit != nil; compunit = compunit.Link { + for _, u := range ctxt.compUnits { + if len(u.lib.Textp) == 0 && u.dwinfo.Child == nil { + continue + } + compunit := u.dwinfo sectionstart := s.Size culength := uint32(getattr(compunit, dwarf.DW_AT_byte_size).Value) + 4 @@ -1671,13 +1647,10 @@ func dwarfGenerateDebugInfo(ctxt *Link) { defgotype(ctxt, lookupOrDiag(ctxt, typ)) } - // Create DIEs for global variables and the types they use. - genasmsym(ctxt, defdwsymb) + // fake root DIE for compile unit DIEs + var dwroot dwarf.DWDie for _, lib := range ctxt.Library { - if len(lib.Textp) == 0 { - continue - } unit := &compilationUnit{lib: lib} if s := ctxt.Syms.ROLookup(dwarf.ConstInfoPrefix+lib.Pkg, 0); s != nil { importInfoSymbol(ctxt, s) @@ -1686,6 +1659,31 @@ func dwarfGenerateDebugInfo(ctxt *Link) { ctxt.compUnits = append(ctxt.compUnits, unit) ctxt.compUnitByPackage[lib] = unit + unit.dwinfo = newdie(ctxt, &dwroot, dwarf.DW_ABRV_COMPUNIT, unit.lib.Pkg, 0) + newattr(unit.dwinfo, dwarf.DW_AT_language, dwarf.DW_CLS_CONSTANT, int64(dwarf.DW_LANG_Go), 0) + // OS X linker requires compilation dir or absolute path in comp unit name to output debug info. + compDir := getCompilationDir() + // TODO: Make this be the actual compilation directory, not + // the linker directory. If we move CU construction into the + // compiler, this should happen naturally. + newattr(unit.dwinfo, dwarf.DW_AT_comp_dir, dwarf.DW_CLS_STRING, int64(len(compDir)), compDir) + producerExtra := ctxt.Syms.Lookup(dwarf.CUInfoPrefix+"producer."+unit.lib.Pkg, 0) + producer := "Go cmd/compile " + objabi.Version + if len(producerExtra.P) > 0 { + // We put a semicolon before the flags to clearly + // separate them from the version, which can be long + // and have lots of weird things in it in development + // versions. We promise not to put a semicolon in the + // version, so it should be safe for readers to scan + // forward to the semicolon. + producer += "; " + string(producerExtra.P) + } + newattr(unit.dwinfo, dwarf.DW_AT_producer, dwarf.DW_CLS_STRING, int64(len(producer)), producer) + + if len(lib.Textp) == 0 { + unit.dwinfo.Abbrev = dwarf.DW_ABRV_COMPUNIT_TEXTLESS + } + // Scan all functions in this compilation unit, create DIEs for all // referenced types, create the file table for debug_line, find all // referenced abstract functions. @@ -1726,6 +1724,9 @@ func dwarfGenerateDebugInfo(ctxt *Link) { } } + // Create DIEs for global variables and the types they use. + genasmsym(ctxt, defdwsymb) + synthesizestringtypes(ctxt, dwtypes.Child) synthesizeslicetypes(ctxt, dwtypes.Child) synthesizemaptypes(ctxt, dwtypes.Child) @@ -1758,19 +1759,19 @@ func dwarfGenerateDebugSyms(ctxt *Link) { debugRanges.Attr |= sym.AttrReachable syms = append(syms, debugLine) for _, u := range ctxt.compUnits { - u.dwinfo = writelines(ctxt, u, debugLine) + reversetree(&u.dwinfo.Child) + if u.dwinfo.Abbrev == dwarf.DW_ABRV_COMPUNIT_TEXTLESS { + continue + } + writelines(ctxt, u, debugLine) writepcranges(ctxt, u.dwinfo, u.lib.Textp[0], u.pcs, debugRanges) } // newdie adds DIEs to the *beginning* of the parent's DIE list. // Now that we're done creating DIEs, reverse the trees so DIEs // appear in the order they were created. - reversetree(&dwroot.Child) reversetree(&dwtypes.Child) - reversetree(&dwglobals.Child) - - movetomodule(&dwtypes) - movetomodule(&dwglobals) + movetomodule(ctxt, &dwtypes) // Need to reorder symbols so sym.SDWARFINFO is after all sym.SDWARFSECT // (but we need to generate dies before writepub) @@ -2005,5 +2006,14 @@ func (v compilationUnitByStartPC) Len() int { return len(v) } func (v compilationUnitByStartPC) Swap(i, j int) { v[i], v[j] = v[j], v[i] } func (v compilationUnitByStartPC) Less(i, j int) bool { - return v[i].lib.Textp[0].Value < v[j].lib.Textp[0].Value + switch { + case len(v[i].lib.Textp) == 0 && len(v[j].lib.Textp) == 0: + return v[i].lib.Pkg < v[j].lib.Pkg + case len(v[i].lib.Textp) != 0 && len(v[j].lib.Textp) == 0: + return true + case len(v[i].lib.Textp) == 0 && len(v[j].lib.Textp) != 0: + return false + default: + return v[i].lib.Textp[0].Value < v[j].lib.Textp[0].Value + } } diff --git a/src/cmd/link/internal/objfile/objfile.go b/src/cmd/link/internal/objfile/objfile.go index e3800de30413b..3a8923b07333f 100644 --- a/src/cmd/link/internal/objfile/objfile.go +++ b/src/cmd/link/internal/objfile/objfile.go @@ -203,6 +203,7 @@ func (r *objReader) readSym() { overwrite: s.File = pkg + s.Lib = r.lib if dupok { s.Attr |= sym.AttrDuplicateOK } @@ -320,7 +321,6 @@ overwrite: s.FuncInfo.IsStmtSym = r.syms.Lookup(dwarf.IsStmtPrefix+s.Name, int(s.Version)) - s.Lib = r.lib if !dupok { if s.Attr.OnList() { log.Fatalf("symbol %s listed multiple times", s.Name) From 019aee55d3f99f61aa685370f3a644ec78de1e61 Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Wed, 26 Sep 2018 20:08:03 +0200 Subject: [PATCH 0474/1663] cmd/go/internal/modfetch: update expected tags for external repos Updates #27692 Change-Id: Ia32b9e401dfe1fbb64b7f1311d85b7a1ab959bc0 Reviewed-on: https://go-review.googlesource.com/137775 Run-TryBot: Alberto Donizetti TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- src/cmd/go/internal/modfetch/coderepo_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmd/go/internal/modfetch/coderepo_test.go b/src/cmd/go/internal/modfetch/coderepo_test.go index 0b62b9ee76bd5..73c4bd2ccab9d 100644 --- a/src/cmd/go/internal/modfetch/coderepo_test.go +++ b/src/cmd/go/internal/modfetch/coderepo_test.go @@ -505,11 +505,11 @@ var codeRepoVersionsTests = []struct { }, { path: "gopkg.in/russross/blackfriday.v2", - versions: []string{"v2.0.0"}, + versions: []string{"v2.0.0", "v2.0.1"}, }, { path: "gopkg.in/natefinch/lumberjack.v2", - versions: nil, + versions: []string{"v2.0.0"}, }, } From 31d19c0ba34782d16b91e9d41aa88147e858bb34 Mon Sep 17 00:00:00 2001 From: Than McIntosh Date: Thu, 27 Sep 2018 08:46:08 -0400 Subject: [PATCH 0475/1663] test: add testcase for gccgo compile failure Also includes a small tweak to test/run.go to allow package names with Unicode letters (as opposed to just ASCII chars). Updates #27836 Change-Id: Idbf0bdea24174808cddcb69974dab820eb13e521 Reviewed-on: https://go-review.googlesource.com/138075 Reviewed-by: Cherry Zhang --- "test/fixedbugs/issue27836.dir/\303\204foo.go" | 13 +++++++++++++ "test/fixedbugs/issue27836.dir/\303\204main.go" | 13 +++++++++++++ test/fixedbugs/issue27836.go | 7 +++++++ test/run.go | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 "test/fixedbugs/issue27836.dir/\303\204foo.go" create mode 100644 "test/fixedbugs/issue27836.dir/\303\204main.go" create mode 100644 test/fixedbugs/issue27836.go diff --git "a/test/fixedbugs/issue27836.dir/\303\204foo.go" "b/test/fixedbugs/issue27836.dir/\303\204foo.go" new file mode 100644 index 0000000000000..8b6a814c3c4de --- /dev/null +++ "b/test/fixedbugs/issue27836.dir/\303\204foo.go" @@ -0,0 +1,13 @@ +package Äfoo + +var ÄbarV int = 101 + +func Äbar(x int) int { + defer func() { ÄbarV += 3 }() + return Äblix(x) +} + +func Äblix(x int) int { + defer func() { ÄbarV += 9 }() + return ÄbarV + x +} diff --git "a/test/fixedbugs/issue27836.dir/\303\204main.go" "b/test/fixedbugs/issue27836.dir/\303\204main.go" new file mode 100644 index 0000000000000..25d2c71fc00a9 --- /dev/null +++ "b/test/fixedbugs/issue27836.dir/\303\204main.go" @@ -0,0 +1,13 @@ +package main + +import ( + "fmt" + + "./Äfoo" + Äblix "./Äfoo" +) + +func main() { + fmt.Printf("Äfoo.Äbar(33) returns %v\n", Äfoo.Äbar(33)) + fmt.Printf("Äblix.Äbar(33) returns %v\n", Äblix.Äbar(33)) +} diff --git a/test/fixedbugs/issue27836.go b/test/fixedbugs/issue27836.go new file mode 100644 index 0000000000000..128cf9d06ad6e --- /dev/null +++ b/test/fixedbugs/issue27836.go @@ -0,0 +1,7 @@ +// compiledir + +// Copyright 2018 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. + +package ignored diff --git a/test/run.go b/test/run.go index d0dccb4f23d19..3af6d1466be8b 100644 --- a/test/run.go +++ b/test/run.go @@ -321,7 +321,7 @@ func goDirFiles(longdir string) (filter []os.FileInfo, err error) { return } -var packageRE = regexp.MustCompile(`(?m)^package (\w+)`) +var packageRE = regexp.MustCompile(`(?m)^package ([\p{Lu}\p{Ll}\w]+)`) // If singlefilepkgs is set, each file is considered a separate package // even if the package names are the same. From a6df1cece7f6b62a1e1b09f9027692ac0d5411a1 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Mon, 24 Sep 2018 06:08:54 -0400 Subject: [PATCH 0476/1663] net: concatenate multiple TXT strings in single TXT record When go resolver was changed to use dnsmessage.Parser, LookupTXT returned two strings in one record as two different records. This change reverts back to concatenating multiple strings in a single TXT record. Fixes #27763 Change-Id: Ice226fcb2be4be58853de34ed35b4627acb429ea Reviewed-on: https://go-review.googlesource.com/136955 Reviewed-by: Ian Gudger Reviewed-by: Brad Fitzpatrick Run-TryBot: Ian Gudger TryBot-Result: Gobot Gobot --- src/net/dnsclient_unix_test.go | 53 ++++++++++++++++++++++++++++++++++ src/net/lookup_unix.go | 16 ++++++++-- 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/net/dnsclient_unix_test.go b/src/net/dnsclient_unix_test.go index 9e4ebcc7bbef8..9482fc466f443 100644 --- a/src/net/dnsclient_unix_test.go +++ b/src/net/dnsclient_unix_test.go @@ -1568,3 +1568,56 @@ func TestDNSDialTCP(t *testing.T) { t.Fatal("exhange failed:", err) } } + +// Issue 27763: verify that two strings in one TXT record are concatenated. +func TestTXTRecordTwoStrings(t *testing.T) { + fake := fakeDNSServer{ + rh: func(n, _ string, q dnsmessage.Message, _ time.Time) (dnsmessage.Message, error) { + r := dnsmessage.Message{ + Header: dnsmessage.Header{ + ID: q.Header.ID, + Response: true, + RCode: dnsmessage.RCodeSuccess, + }, + Questions: q.Questions, + Answers: []dnsmessage.Resource{ + { + Header: dnsmessage.ResourceHeader{ + Name: q.Questions[0].Name, + Type: dnsmessage.TypeA, + Class: dnsmessage.ClassINET, + }, + Body: &dnsmessage.TXTResource{ + TXT: []string{"string1 ", "string2"}, + }, + }, + { + Header: dnsmessage.ResourceHeader{ + Name: q.Questions[0].Name, + Type: dnsmessage.TypeA, + Class: dnsmessage.ClassINET, + }, + Body: &dnsmessage.TXTResource{ + TXT: []string{"onestring"}, + }, + }, + }, + } + return r, nil + }, + } + r := Resolver{PreferGo: true, Dial: fake.DialContext} + txt, err := r.lookupTXT(context.Background(), "golang.org") + if err != nil { + t.Fatal("LookupTXT failed:", err) + } + if want := 2; len(txt) != want { + t.Fatalf("len(txt), got %d, want %d", len(txt), want) + } + if want := "string1 string2"; txt[0] != want { + t.Errorf("txt[0], got %q, want %q", txt[0], want) + } + if want := "onestring"; txt[1] != want { + t.Errorf("txt[1], got %q, want %q", txt[1], want) + } +} diff --git a/src/net/lookup_unix.go b/src/net/lookup_unix.go index 04f443bb1aa74..1266680706902 100644 --- a/src/net/lookup_unix.go +++ b/src/net/lookup_unix.go @@ -300,11 +300,21 @@ func (r *Resolver) lookupTXT(ctx context.Context, name string) ([]string, error) Server: server, } } + // Multiple strings in one TXT record need to be + // concatenated without separator to be consistent + // with previous Go resolver. + n := 0 + for _, s := range txt.TXT { + n += len(s) + } + txtJoin := make([]byte, 0, n) + for _, s := range txt.TXT { + txtJoin = append(txtJoin, s...) + } if len(txts) == 0 { - txts = txt.TXT - } else { - txts = append(txts, txt.TXT...) + txts = make([]string, 0, 1) } + txts = append(txts, string(txtJoin)) } return txts, nil } From 06afc8b152bc01e1b4f5dce074bae531dd29a9b9 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 19 Sep 2018 16:42:13 -0400 Subject: [PATCH 0477/1663] runtime: simplify the control flow in sweepone Ending a loop with a break is confusing. Rewrite the loop so the default behavior is to loop and then do the "post-loop" work outside of the loop. Change-Id: Ie49b4132541dfb5124c31a8163f2c883aa4abc75 Reviewed-on: https://go-review.googlesource.com/138155 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/mgcsweep.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go index ecfdee59f483b..5cdede002a188 100644 --- a/src/runtime/mgcsweep.go +++ b/src/runtime/mgcsweep.go @@ -88,10 +88,11 @@ func sweepone() uintptr { } atomic.Xadd(&mheap_.sweepers, +1) - npages := ^uintptr(0) + // Find a span to sweep. + var s *mspan sg := mheap_.sweepgen for { - s := mheap_.sweepSpans[1-sg/2%2].pop() + s = mheap_.sweepSpans[1-sg/2%2].pop() if s == nil { atomic.Store(&mheap_.sweepdone, 1) break @@ -106,9 +107,14 @@ func sweepone() uintptr { } continue } - if s.sweepgen != sg-2 || !atomic.Cas(&s.sweepgen, sg-2, sg-1) { - continue + if s.sweepgen == sg-2 && atomic.Cas(&s.sweepgen, sg-2, sg-1) { + break } + } + + // Sweep the span we found. + npages := ^uintptr(0) + if s != nil { npages = s.npages if !s.sweep(false) { // Span is still in-use, so this returned no @@ -116,7 +122,6 @@ func sweepone() uintptr { // move to the swept in-use list. npages = 0 } - break } // Decrement the number of active sweepers and if this is the From 6a6f4a46536e9b2fb2bfb825269d6bd5e823fe8f Mon Sep 17 00:00:00 2001 From: Travis Bischel Date: Sun, 9 Sep 2018 14:45:34 -0700 Subject: [PATCH 0478/1663] net/textproto: redo BenchmarkReadMIMEHeader This benchmark is odd currently because it uses inconsistent cases between benchmark iterations, and each iteration actually does a bit of testing. This separates the two benchmark cases into two separate benchmarks and removes the testing done on each iteration. The unit tests above suffice. The benchmark being more succinct will make it easier to gauge the benefits of any future MIME header reading changes. Change-Id: I2399fab28067f1aeec3d9b16951d39d787f8b39c Reviewed-on: https://go-review.googlesource.com/134225 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/textproto/reader_test.go | 44 ++++++++++++++------------------ 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/src/net/textproto/reader_test.go b/src/net/textproto/reader_test.go index 7cff7b4579754..f85fbdc36d7d9 100644 --- a/src/net/textproto/reader_test.go +++ b/src/net/textproto/reader_test.go @@ -382,31 +382,25 @@ Non-Interned: test func BenchmarkReadMIMEHeader(b *testing.B) { b.ReportAllocs() - var buf bytes.Buffer - br := bufio.NewReader(&buf) - r := NewReader(br) - for i := 0; i < b.N; i++ { - var want int - var find string - if (i & 1) == 1 { - buf.WriteString(clientHeaders) - want = 10 - find = "Cookie" - } else { - buf.WriteString(serverHeaders) - want = 9 - find = "Via" - } - h, err := r.ReadMIMEHeader() - if err != nil { - b.Fatal(err) - } - if len(h) != want { - b.Fatalf("wrong number of headers: got %d, want %d", len(h), want) - } - if _, ok := h[find]; !ok { - b.Fatalf("did not find key %s", find) - } + for _, set := range []struct { + name string + headers string + }{ + {"client_headers", clientHeaders}, + {"server_headers", serverHeaders}, + } { + b.Run(set.name, func(b *testing.B) { + var buf bytes.Buffer + br := bufio.NewReader(&buf) + r := NewReader(br) + + for i := 0; i < b.N; i++ { + buf.WriteString(set.headers) + if _, err := r.ReadMIMEHeader(); err != nil { + b.Fatal(err) + } + } + }) } } From 756c352963f4decbf898f244876855aab747afdc Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Tue, 25 Sep 2018 20:34:15 -0700 Subject: [PATCH 0479/1663] sync: simplify (*entry).tryStore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The only change to the go build -gcflags=-m=2 output was to remove these two lines: sync/map.go:178:26: &e.p escapes to heap sync/map.go:178:26: from &e.p (passed to call[argument escapes]) at sync/map.go:178:25 Benchstat report for sync.Map benchmarks: name old time/op new time/op delta LoadMostlyHits/*sync_test.DeepCopyMap-12 10.6ns ±11% 10.2ns ± 3% ~ (p=0.299 n=10+8) LoadMostlyHits/*sync_test.RWMutexMap-12 54.6ns ± 3% 54.6ns ± 2% ~ (p=0.782 n=10+10) LoadMostlyHits/*sync.Map-12 10.1ns ± 1% 10.1ns ± 1% ~ (p=1.127 n=10+8) LoadMostlyMisses/*sync_test.DeepCopyMap-12 8.65ns ± 1% 8.77ns ± 5% +1.39% (p=0.017 n=9+10) LoadMostlyMisses/*sync_test.RWMutexMap-12 53.6ns ± 2% 53.8ns ± 2% ~ (p=0.408 n=10+9) LoadMostlyMisses/*sync.Map-12 7.37ns ± 1% 7.46ns ± 1% +1.19% (p=0.000 n=9+10) LoadOrStoreBalanced/*sync_test.RWMutexMap-12 895ns ± 4% 906ns ± 3% ~ (p=0.203 n=9+10) LoadOrStoreBalanced/*sync.Map-12 872ns ±10% 804ns ±12% -7.75% (p=0.014 n=10+10) LoadOrStoreUnique/*sync_test.RWMutexMap-12 1.29µs ± 2% 1.28µs ± 1% ~ (p=0.586 n=10+9) LoadOrStoreUnique/*sync.Map-12 1.30µs ± 7% 1.40µs ± 2% +6.95% (p=0.000 n=9+10) LoadOrStoreCollision/*sync_test.DeepCopyMap-12 6.98ns ± 1% 6.91ns ± 1% -1.10% (p=0.000 n=10+10) LoadOrStoreCollision/*sync_test.RWMutexMap-12 371ns ± 1% 372ns ± 2% ~ (p=0.679 n=9+9) LoadOrStoreCollision/*sync.Map-12 5.49ns ± 1% 5.49ns ± 1% ~ (p=0.732 n=9+10) Range/*sync_test.DeepCopyMap-12 2.49µs ± 1% 2.50µs ± 0% ~ (p=0.148 n=10+10) Range/*sync_test.RWMutexMap-12 54.7µs ± 1% 54.6µs ± 3% ~ (p=0.549 n=9+10) Range/*sync.Map-12 2.74µs ± 1% 2.76µs ± 1% +0.68% (p=0.011 n=10+8) AdversarialAlloc/*sync_test.DeepCopyMap-12 2.52µs ± 5% 2.54µs ± 7% ~ (p=0.225 n=10+10) AdversarialAlloc/*sync_test.RWMutexMap-12 108ns ± 1% 107ns ± 1% ~ (p=0.101 n=10+9) AdversarialAlloc/*sync.Map-12 712ns ± 2% 714ns ± 3% ~ (p=0.984 n=8+10) AdversarialDelete/*sync_test.DeepCopyMap-12 581ns ± 3% 578ns ± 3% ~ (p=0.781 n=9+9) AdversarialDelete/*sync_test.RWMutexMap-12 126ns ± 2% 126ns ± 1% ~ (p=0.883 n=10+10) AdversarialDelete/*sync.Map-12 155ns ± 8% 158ns ± 2% ~ (p=0.158 n=10+9) Change-Id: I1ed8e3109baca03087d0fad3df769fc7e38f6dbb Reviewed-on: https://go-review.googlesource.com/137441 Reviewed-by: Bryan C. Mills Reviewed-by: Brad Fitzpatrick --- src/sync/map.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/sync/map.go b/src/sync/map.go index c4a0dc4194ab6..c6aa308856584 100644 --- a/src/sync/map.go +++ b/src/sync/map.go @@ -167,18 +167,14 @@ func (m *Map) Store(key, value interface{}) { // If the entry is expunged, tryStore returns false and leaves the entry // unchanged. func (e *entry) tryStore(i *interface{}) bool { - p := atomic.LoadPointer(&e.p) - if p == expunged { - return false - } for { - if atomic.CompareAndSwapPointer(&e.p, p, unsafe.Pointer(i)) { - return true - } - p = atomic.LoadPointer(&e.p) + p := atomic.LoadPointer(&e.p) if p == expunged { return false } + if atomic.CompareAndSwapPointer(&e.p, p, unsafe.Pointer(i)) { + return true + } } } From 75f4aa86bacb668348e788692974aa554cc61915 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 27 Sep 2018 14:52:41 -0700 Subject: [PATCH 0480/1663] doc: mention -compressdwarf=false on gdb page Update #11799 Change-Id: I2646a52bfb8aecb67a664a7c6fba25511a1aa49f Reviewed-on: https://go-review.googlesource.com/138182 Reviewed-by: Heschi Kreinick Reviewed-by: David Chase --- doc/debugging_with_gdb.html | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/doc/debugging_with_gdb.html b/doc/debugging_with_gdb.html index f3b4e37a2827e..a6b0054d4fb34 100644 --- a/doc/debugging_with_gdb.html +++ b/doc/debugging_with_gdb.html @@ -180,6 +180,15 @@

Known Issues

that needs to be quoted. It objects even more strongly to method names of the form pkg.(*MyType).Meth.
  • All global variables are lumped into package "main".
  • +
  • As of Go 1.11, debug information is compressed by default. +Older versions of gdb, such as the one available by default on MacOS, +do not understand the compression. +You can generate uncompressed debug information by using go +build -ldflags=-compressdwarf=false. +(For convenience you can put the -ldflags option in +the GOFLAGS +environment variable so that you don't have to specify it each time.) +
  • Tutorial

    From d3dcd89130674ee56a3ae55021e4b14ef989cf8a Mon Sep 17 00:00:00 2001 From: Ian Davis Date: Fri, 28 Sep 2018 09:26:20 +0100 Subject: [PATCH 0481/1663] all: remove repeated "the" from comments A simple grep over the codebase for "the the" which is often missed by humans. Change-Id: Ie4b4f07abfc24c73dcd51c8ef1edf4f73514a21c Reviewed-on: https://go-review.googlesource.com/138335 Reviewed-by: Dave Cheney --- src/cmd/go/internal/modload/query.go | 2 +- src/crypto/x509/cert_pool.go | 2 +- src/net/http/transport.go | 2 +- src/net/http/transport_test.go | 4 ++-- src/os/os_unix_test.go | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go index 3b550f1db7f74..0921d683f0420 100644 --- a/src/cmd/go/internal/modload/query.go +++ b/src/cmd/go/internal/modload/query.go @@ -207,7 +207,7 @@ func matchSemverPrefix(p, v string) bool { // If multiple modules with revisions matching the query provide the requested // package, QueryPackage picks the one with the longest module path. // -// If the path is in the the main module and the query is "latest", +// If the path is in the main module and the query is "latest", // QueryPackage returns Target as the version. func QueryPackage(path, query string, allowed func(module.Version) bool) (module.Version, *modfetch.RevInfo, error) { if _, ok := dirInModule(path, Target.Path, ModRoot, true); ok { diff --git a/src/crypto/x509/cert_pool.go b/src/crypto/x509/cert_pool.go index 86aba6710daf8..7cc1dd4eb6f01 100644 --- a/src/crypto/x509/cert_pool.go +++ b/src/crypto/x509/cert_pool.go @@ -50,7 +50,7 @@ func (s *CertPool) copy() *CertPool { // Any mutations to the returned pool are not written to disk and do // not affect any other pool returned by SystemCertPool. // -// New changes in the the system cert pool might not be reflected +// New changes in the system cert pool might not be reflected // in subsequent calls. func SystemCertPool() (*CertPool, error) { if runtime.GOOS == "windows" { diff --git a/src/net/http/transport.go b/src/net/http/transport.go index b8788654b769a..7f8fd505bd9dd 100644 --- a/src/net/http/transport.go +++ b/src/net/http/transport.go @@ -278,7 +278,7 @@ func (t *Transport) onceSetNextProtoDefaults() { // If they've already configured http2 with // golang.org/x/net/http2 instead of the bundled copy, try to - // get at its http2.Transport value (via the the "https" + // get at its http2.Transport value (via the "https" // altproto map) so we can call CloseIdleConnections on it if // requested. (Issue 22891) altProto, _ := t.altProto.Load().(map[string]RoundTripper) diff --git a/src/net/http/transport_test.go b/src/net/http/transport_test.go index 327b3b4996c90..739fe5f59718a 100644 --- a/src/net/http/transport_test.go +++ b/src/net/http/transport_test.go @@ -4753,7 +4753,7 @@ func TestClientTimeoutKillsConn_BeforeHeaders(t *testing.T) { } case <-time.After(timeout * 10): // If we didn't get into the Handler in 50ms, that probably means - // the builder was just slow and the the Get failed in that time + // the builder was just slow and the Get failed in that time // but never made it to the server. That's fine. We'll usually // test the part above on faster machines. t.Skip("skipping test on slow builder") @@ -4764,7 +4764,7 @@ func TestClientTimeoutKillsConn_BeforeHeaders(t *testing.T) { // conn is closed so that it's not reused. // // This is the test variant that has the server send response headers -// first, and time out during the the write of the response body. +// first, and time out during the write of the response body. func TestClientTimeoutKillsConn_AfterHeaders(t *testing.T) { setParallel(t) defer afterTest(t) diff --git a/src/os/os_unix_test.go b/src/os/os_unix_test.go index 54f121ef4c2d5..1077d7861357c 100644 --- a/src/os/os_unix_test.go +++ b/src/os/os_unix_test.go @@ -234,7 +234,7 @@ func newFileTest(t *testing.T, blocking bool) { } defer syscall.Close(p[1]) - // Set the the read-side to non-blocking. + // Set the read-side to non-blocking. if !blocking { if err := syscall.SetNonblock(p[0], true); err != nil { syscall.Close(p[0]) From 38861b5127b2de907e879420f29f3ef4bab75f84 Mon Sep 17 00:00:00 2001 From: Chris Broadfoot Date: Fri, 28 Sep 2018 02:02:22 -0700 Subject: [PATCH 0482/1663] doc: add go1.11 to contrib.html Missing from https://golang.org/project Change-Id: I6cb769ae861a81f0264bae624b5fe8d70aa92497 Reviewed-on: https://go-review.googlesource.com/138355 Reviewed-by: Dave Cheney --- doc/contrib.html | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/contrib.html b/doc/contrib.html index e63bcce142f93..b4b19a6af75ed 100644 --- a/doc/contrib.html +++ b/doc/contrib.html @@ -34,6 +34,7 @@

    Release History

    A summary of the changes between Go releases. Notes for the major releases:

      +
    • Go 1.11 (August 2018)
    • Go 1.10 (February 2018)
    • Go 1.9 (August 2017)
    • Go 1.8 (February 2017)
    • From bf8e6b70276ddfd3e070964542020fe782c1eec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Date: Thu, 27 Sep 2018 15:26:18 +0200 Subject: [PATCH 0483/1663] go/build, runtime/internal/sys: add GOOS=aix This is the first commit of a series that will add AIX as an operating system target for ppc64 architecture. Updates #25893 Change-Id: I865b67a9c98277c11c1a56107be404ac5253277d Reviewed-on: https://go-review.googlesource.com/138115 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/go/build/syslist.go | 2 +- src/runtime/internal/sys/zgoos_aix.go | 21 +++++++++++++++++++++ src/runtime/internal/sys/zgoos_android.go | 1 + src/runtime/internal/sys/zgoos_darwin.go | 1 + src/runtime/internal/sys/zgoos_dragonfly.go | 1 + src/runtime/internal/sys/zgoos_freebsd.go | 1 + src/runtime/internal/sys/zgoos_linux.go | 1 + src/runtime/internal/sys/zgoos_nacl.go | 1 + src/runtime/internal/sys/zgoos_netbsd.go | 1 + src/runtime/internal/sys/zgoos_openbsd.go | 1 + src/runtime/internal/sys/zgoos_plan9.go | 1 + src/runtime/internal/sys/zgoos_solaris.go | 1 + src/runtime/internal/sys/zgoos_windows.go | 1 + src/runtime/internal/sys/zgoos_zos.go | 1 + 14 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 src/runtime/internal/sys/zgoos_aix.go diff --git a/src/go/build/syslist.go b/src/go/build/syslist.go index d7938fad54f96..597212b6d0d37 100644 --- a/src/go/build/syslist.go +++ b/src/go/build/syslist.go @@ -4,5 +4,5 @@ package build -const goosList = "android darwin dragonfly freebsd js linux nacl netbsd openbsd plan9 solaris windows zos " +const goosList = "aix android darwin dragonfly freebsd js linux nacl netbsd openbsd plan9 solaris windows zos " const goarchList = "386 amd64 amd64p32 arm armbe arm64 arm64be ppc64 ppc64le mips mipsle mips64 mips64le mips64p32 mips64p32le ppc riscv riscv64 s390 s390x sparc sparc64 wasm " diff --git a/src/runtime/internal/sys/zgoos_aix.go b/src/runtime/internal/sys/zgoos_aix.go new file mode 100644 index 0000000000000..9ce5b3434f9fd --- /dev/null +++ b/src/runtime/internal/sys/zgoos_aix.go @@ -0,0 +1,21 @@ +// Code generated by gengoos.go using 'go generate'. DO NOT EDIT. + +// +build aix + +package sys + +const GOOS = `aix` + +const GoosAndroid = 0 +const GoosAix = 1 +const GoosDarwin = 0 +const GoosDragonfly = 0 +const GoosFreebsd = 0 +const GoosLinux = 0 +const GoosNacl = 0 +const GoosNetbsd = 0 +const GoosOpenbsd = 0 +const GoosPlan9 = 0 +const GoosSolaris = 0 +const GoosWindows = 0 +const GoosZos = 0 diff --git a/src/runtime/internal/sys/zgoos_android.go b/src/runtime/internal/sys/zgoos_android.go index bfdc37792e8e0..36a5768ab6559 100644 --- a/src/runtime/internal/sys/zgoos_android.go +++ b/src/runtime/internal/sys/zgoos_android.go @@ -7,6 +7,7 @@ package sys const GOOS = `android` const GoosAndroid = 1 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 0 const GoosFreebsd = 0 diff --git a/src/runtime/internal/sys/zgoos_darwin.go b/src/runtime/internal/sys/zgoos_darwin.go index 1c4667f6debee..10c0e88e9a930 100644 --- a/src/runtime/internal/sys/zgoos_darwin.go +++ b/src/runtime/internal/sys/zgoos_darwin.go @@ -7,6 +7,7 @@ package sys const GOOS = `darwin` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 1 const GoosDragonfly = 0 const GoosFreebsd = 0 diff --git a/src/runtime/internal/sys/zgoos_dragonfly.go b/src/runtime/internal/sys/zgoos_dragonfly.go index 728bf6abe85e5..5cb47cb84e920 100644 --- a/src/runtime/internal/sys/zgoos_dragonfly.go +++ b/src/runtime/internal/sys/zgoos_dragonfly.go @@ -7,6 +7,7 @@ package sys const GOOS = `dragonfly` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 1 const GoosFreebsd = 0 diff --git a/src/runtime/internal/sys/zgoos_freebsd.go b/src/runtime/internal/sys/zgoos_freebsd.go index a8d659169b11d..470406ce5ff7f 100644 --- a/src/runtime/internal/sys/zgoos_freebsd.go +++ b/src/runtime/internal/sys/zgoos_freebsd.go @@ -7,6 +7,7 @@ package sys const GOOS = `freebsd` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 0 const GoosFreebsd = 1 diff --git a/src/runtime/internal/sys/zgoos_linux.go b/src/runtime/internal/sys/zgoos_linux.go index 289400c6122c5..76235b748c1c2 100644 --- a/src/runtime/internal/sys/zgoos_linux.go +++ b/src/runtime/internal/sys/zgoos_linux.go @@ -8,6 +8,7 @@ package sys const GOOS = `linux` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 0 const GoosFreebsd = 0 diff --git a/src/runtime/internal/sys/zgoos_nacl.go b/src/runtime/internal/sys/zgoos_nacl.go index 3fedb0a2c3b1b..6d28b596678c8 100644 --- a/src/runtime/internal/sys/zgoos_nacl.go +++ b/src/runtime/internal/sys/zgoos_nacl.go @@ -7,6 +7,7 @@ package sys const GOOS = `nacl` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 0 const GoosFreebsd = 0 diff --git a/src/runtime/internal/sys/zgoos_netbsd.go b/src/runtime/internal/sys/zgoos_netbsd.go index 3346e3711ca35..ef8d938ddbc83 100644 --- a/src/runtime/internal/sys/zgoos_netbsd.go +++ b/src/runtime/internal/sys/zgoos_netbsd.go @@ -7,6 +7,7 @@ package sys const GOOS = `netbsd` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 0 const GoosFreebsd = 0 diff --git a/src/runtime/internal/sys/zgoos_openbsd.go b/src/runtime/internal/sys/zgoos_openbsd.go index 13c0323249d2e..2e438473964ca 100644 --- a/src/runtime/internal/sys/zgoos_openbsd.go +++ b/src/runtime/internal/sys/zgoos_openbsd.go @@ -7,6 +7,7 @@ package sys const GOOS = `openbsd` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 0 const GoosFreebsd = 0 diff --git a/src/runtime/internal/sys/zgoos_plan9.go b/src/runtime/internal/sys/zgoos_plan9.go index 6b2e977b5ea32..ed598dcaaca8e 100644 --- a/src/runtime/internal/sys/zgoos_plan9.go +++ b/src/runtime/internal/sys/zgoos_plan9.go @@ -7,6 +7,7 @@ package sys const GOOS = `plan9` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 0 const GoosFreebsd = 0 diff --git a/src/runtime/internal/sys/zgoos_solaris.go b/src/runtime/internal/sys/zgoos_solaris.go index cbf70f079a39c..fe690df6c2220 100644 --- a/src/runtime/internal/sys/zgoos_solaris.go +++ b/src/runtime/internal/sys/zgoos_solaris.go @@ -7,6 +7,7 @@ package sys const GOOS = `solaris` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 0 const GoosFreebsd = 0 diff --git a/src/runtime/internal/sys/zgoos_windows.go b/src/runtime/internal/sys/zgoos_windows.go index 70839ca7938ef..ea7c43bdf4d9a 100644 --- a/src/runtime/internal/sys/zgoos_windows.go +++ b/src/runtime/internal/sys/zgoos_windows.go @@ -7,6 +7,7 @@ package sys const GOOS = `windows` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 0 const GoosFreebsd = 0 diff --git a/src/runtime/internal/sys/zgoos_zos.go b/src/runtime/internal/sys/zgoos_zos.go index ecf449f70348c..d4027cf876890 100644 --- a/src/runtime/internal/sys/zgoos_zos.go +++ b/src/runtime/internal/sys/zgoos_zos.go @@ -7,6 +7,7 @@ package sys const GOOS = `zos` const GoosAndroid = 0 +const GoosAix = 0 const GoosDarwin = 0 const GoosDragonfly = 0 const GoosFreebsd = 0 From d60cf39f8e58211c9d4d507d673131f32623d5cc Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 27 Sep 2018 13:21:03 +0000 Subject: [PATCH 0484/1663] cmd/compile: optimize arm64's MADD and MSUB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL implements constant folding for MADD/MSUB on arm64. 1. The total size of pkg/android_arm64/ decreases about 4KB, excluding cmd/compile/ . 2. There is no regression in the go1 benchmark, excluding noise. name old time/op new time/op delta BinaryTree17-4 16.4s ± 1% 16.5s ± 1% +0.24% (p=0.008 n=29+29) Fannkuch11-4 8.73s ± 0% 8.71s ± 0% -0.15% (p=0.000 n=29+29) FmtFprintfEmpty-4 174ns ± 0% 174ns ± 0% ~ (all equal) FmtFprintfString-4 370ns ± 0% 372ns ± 2% +0.53% (p=0.007 n=24+30) FmtFprintfInt-4 419ns ± 0% 419ns ± 0% ~ (all equal) FmtFprintfIntInt-4 673ns ± 1% 661ns ± 1% -1.81% (p=0.000 n=30+27) FmtFprintfPrefixedInt-4 806ns ± 0% 805ns ± 0% ~ (p=0.957 n=28+27) FmtFprintfFloat-4 1.09µs ± 0% 1.09µs ± 0% -0.04% (p=0.001 n=22+30) FmtManyArgs-4 2.67µs ± 0% 2.68µs ± 0% +0.03% (p=0.045 n=29+28) GobDecode-4 33.2ms ± 1% 32.5ms ± 1% -2.11% (p=0.000 n=29+29) GobEncode-4 29.5ms ± 0% 29.2ms ± 0% -1.04% (p=0.000 n=28+28) Gzip-4 1.39s ± 2% 1.38s ± 1% -0.48% (p=0.023 n=30+30) Gunzip-4 139ms ± 0% 139ms ± 0% ~ (p=0.616 n=30+28) HTTPClientServer-4 766µs ± 4% 758µs ± 3% -1.03% (p=0.013 n=28+29) JSONEncode-4 49.7ms ± 0% 49.6ms ± 0% -0.24% (p=0.000 n=30+30) JSONDecode-4 266ms ± 0% 268ms ± 1% +1.07% (p=0.000 n=29+30) Mandelbrot200-4 16.6ms ± 0% 16.6ms ± 0% ~ (p=0.248 n=30+29) GoParse-4 15.9ms ± 0% 16.0ms ± 0% +0.76% (p=0.000 n=29+29) RegexpMatchEasy0_32-4 381ns ± 0% 380ns ± 0% -0.14% (p=0.000 n=30+30) RegexpMatchEasy0_1K-4 1.18µs ± 0% 1.19µs ± 1% +0.30% (p=0.000 n=29+30) RegexpMatchEasy1_32-4 357ns ± 0% 357ns ± 0% ~ (all equal) RegexpMatchEasy1_1K-4 2.04µs ± 0% 2.05µs ± 0% +0.50% (p=0.000 n=26+28) RegexpMatchMedium_32-4 590ns ± 0% 589ns ± 0% -0.12% (p=0.000 n=30+23) RegexpMatchMedium_1K-4 162µs ± 0% 162µs ± 0% ~ (p=0.318 n=28+25) RegexpMatchHard_32-4 9.56µs ± 0% 9.56µs ± 0% ~ (p=0.072 n=30+29) RegexpMatchHard_1K-4 287µs ± 0% 287µs ± 0% -0.02% (p=0.005 n=28+28) Revcomp-4 2.50s ± 0% 2.51s ± 0% ~ (p=0.246 n=29+29) Template-4 312ms ± 1% 313ms ± 1% +0.46% (p=0.002 n=30+30) TimeParse-4 1.68µs ± 0% 1.67µs ± 0% -0.31% (p=0.000 n=27+29) TimeFormat-4 1.66µs ± 0% 1.64µs ± 0% -0.92% (p=0.000 n=29+26) [Geo mean] 247µs 246µs -0.15% name old speed new speed delta GobDecode-4 23.1MB/s ± 1% 23.6MB/s ± 0% +2.17% (p=0.000 n=29+28) GobEncode-4 26.0MB/s ± 0% 26.3MB/s ± 0% +1.05% (p=0.000 n=28+28) Gzip-4 14.0MB/s ± 2% 14.1MB/s ± 1% +0.47% (p=0.026 n=30+30) Gunzip-4 139MB/s ± 0% 139MB/s ± 0% ~ (p=0.624 n=30+28) JSONEncode-4 39.1MB/s ± 0% 39.2MB/s ± 0% +0.24% (p=0.000 n=30+30) JSONDecode-4 7.31MB/s ± 0% 7.23MB/s ± 1% -1.07% (p=0.000 n=28+30) GoParse-4 3.65MB/s ± 0% 3.62MB/s ± 0% -0.77% (p=0.000 n=29+29) RegexpMatchEasy0_32-4 84.0MB/s ± 0% 84.1MB/s ± 0% +0.18% (p=0.000 n=28+30) RegexpMatchEasy0_1K-4 864MB/s ± 0% 861MB/s ± 1% -0.29% (p=0.000 n=29+30) RegexpMatchEasy1_32-4 89.5MB/s ± 0% 89.5MB/s ± 0% ~ (p=0.841 n=28+28) RegexpMatchEasy1_1K-4 502MB/s ± 0% 500MB/s ± 0% -0.51% (p=0.000 n=29+29) RegexpMatchMedium_32-4 1.69MB/s ± 0% 1.70MB/s ± 0% +0.41% (p=0.000 n=26+30) RegexpMatchMedium_1K-4 6.31MB/s ± 0% 6.30MB/s ± 0% ~ (p=0.129 n=30+25) RegexpMatchHard_32-4 3.35MB/s ± 0% 3.35MB/s ± 0% ~ (p=0.657 n=30+29) RegexpMatchHard_1K-4 3.57MB/s ± 0% 3.57MB/s ± 0% ~ (all equal) Revcomp-4 102MB/s ± 0% 101MB/s ± 0% ~ (p=0.213 n=29+29) Template-4 6.22MB/s ± 1% 6.19MB/s ± 1% -0.42% (p=0.005 n=30+29) [Geo mean] 24.1MB/s 24.2MB/s +0.08% Change-Id: I6c02d3c9975f6bd8bc215cb1fc14d29602b45649 Reviewed-on: https://go-review.googlesource.com/138095 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/ssa/gen/ARM64.rules | 112 +- src/cmd/compile/internal/ssa/rewriteARM64.go | 6776 ++++++++++++------ test/codegen/arithmetic.go | 15 +- 3 files changed, 4525 insertions(+), 2378 deletions(-) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index 8fb39538c2a1c..3fce018d45ef5 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -1154,15 +1154,15 @@ (MULW (NEG x) y) -> (MNEGW x y) // madd/msub -(ADD a l:(MUL x y)) && l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MADD a x y) -(SUB a l:(MUL x y)) && l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MSUB a x y) -(ADD a l:(MNEG x y)) && l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MSUB a x y) -(SUB a l:(MNEG x y)) && l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MADD a x y) +(ADD a l:(MUL x y)) && l.Uses==1 && clobber(l) -> (MADD a x y) +(SUB a l:(MUL x y)) && l.Uses==1 && clobber(l) -> (MSUB a x y) +(ADD a l:(MNEG x y)) && l.Uses==1 && clobber(l) -> (MSUB a x y) +(SUB a l:(MNEG x y)) && l.Uses==1 && clobber(l) -> (MADD a x y) -(ADD a l:(MULW x y)) && l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MADDW a x y) -(SUB a l:(MULW x y)) && l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MSUBW a x y) -(ADD a l:(MNEGW x y)) && l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MSUBW a x y) -(SUB a l:(MNEGW x y)) && l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) -> (MADDW a x y) +(ADD a l:(MULW x y)) && a.Type.Size() != 8 && l.Uses==1 && clobber(l) -> (MADDW a x y) +(SUB a l:(MULW x y)) && a.Type.Size() != 8 && l.Uses==1 && clobber(l) -> (MSUBW a x y) +(ADD a l:(MNEGW x y)) && a.Type.Size() != 8 && l.Uses==1 && clobber(l) -> (MSUBW a x y) +(SUB a l:(MNEGW x y)) && a.Type.Size() != 8 && l.Uses==1 && clobber(l) -> (MADDW a x y) // mul by constant (MUL x (MOVDconst [-1])) -> (NEG x) @@ -1210,6 +1210,94 @@ (MNEGW x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) (MNEGW x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) +(MADD a x (MOVDconst [-1])) -> (SUB a x) +(MADD a _ (MOVDconst [0])) -> a +(MADD a x (MOVDconst [1])) -> (ADD a x) +(MADD a x (MOVDconst [c])) && isPowerOfTwo(c) -> (ADDshiftLL a x [log2(c)]) +(MADD a x (MOVDconst [c])) && isPowerOfTwo(c-1) && c>=3 -> (ADD a (ADDshiftLL x x [log2(c-1)])) +(MADD a x (MOVDconst [c])) && isPowerOfTwo(c+1) && c>=7 -> (SUB a (SUBshiftLL x x [log2(c+1)])) +(MADD a x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) -> (SUBshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) +(MADD a x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) -> (ADDshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) +(MADD a x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) -> (SUBshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) +(MADD a x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) -> (ADDshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + +(MADD a (MOVDconst [-1]) x) -> (SUB a x) +(MADD a (MOVDconst [0]) _) -> a +(MADD a (MOVDconst [1]) x) -> (ADD a x) +(MADD a (MOVDconst [c]) x) && isPowerOfTwo(c) -> (ADDshiftLL a x [log2(c)]) +(MADD a (MOVDconst [c]) x) && isPowerOfTwo(c-1) && c>=3 -> (ADD a (ADDshiftLL x x [log2(c-1)])) +(MADD a (MOVDconst [c]) x) && isPowerOfTwo(c+1) && c>=7 -> (SUB a (SUBshiftLL x x [log2(c+1)])) +(MADD a (MOVDconst [c]) x) && c%3 == 0 && isPowerOfTwo(c/3) -> (SUBshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) +(MADD a (MOVDconst [c]) x) && c%5 == 0 && isPowerOfTwo(c/5) -> (ADDshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) +(MADD a (MOVDconst [c]) x) && c%7 == 0 && isPowerOfTwo(c/7) -> (SUBshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) +(MADD a (MOVDconst [c]) x) && c%9 == 0 && isPowerOfTwo(c/9) -> (ADDshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + +(MADDW a x (MOVDconst [c])) && int32(c)==-1 -> (SUB a x) +(MADDW a _ (MOVDconst [c])) && int32(c)==0 -> a +(MADDW a x (MOVDconst [c])) && int32(c)==1 -> (ADD a x) +(MADDW a x (MOVDconst [c])) && isPowerOfTwo(c) -> (ADDshiftLL a x [log2(c)]) +(MADDW a x (MOVDconst [c])) && isPowerOfTwo(c-1) && int32(c)>=3 -> (ADD a (ADDshiftLL x x [log2(c-1)])) +(MADDW a x (MOVDconst [c])) && isPowerOfTwo(c+1) && int32(c)>=7 -> (SUB a (SUBshiftLL x x [log2(c+1)])) +(MADDW a x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (SUBshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) +(MADDW a x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (ADDshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) +(MADDW a x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (SUBshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) +(MADDW a x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (ADDshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + +(MADDW a (MOVDconst [c]) x) && int32(c)==-1 -> (SUB a x) +(MADDW a (MOVDconst [c]) _) && int32(c)==0 -> a +(MADDW a (MOVDconst [c]) x) && int32(c)==1 -> (ADD a x) +(MADDW a (MOVDconst [c]) x) && isPowerOfTwo(c) -> (ADDshiftLL a x [log2(c)]) +(MADDW a (MOVDconst [c]) x) && isPowerOfTwo(c-1) && int32(c)>=3 -> (ADD a (ADDshiftLL x x [log2(c-1)])) +(MADDW a (MOVDconst [c]) x) && isPowerOfTwo(c+1) && int32(c)>=7 -> (SUB a (SUBshiftLL x x [log2(c+1)])) +(MADDW a (MOVDconst [c]) x) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (SUBshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) +(MADDW a (MOVDconst [c]) x) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (ADDshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) +(MADDW a (MOVDconst [c]) x) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (SUBshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) +(MADDW a (MOVDconst [c]) x) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (ADDshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + +(MSUB a x (MOVDconst [-1])) -> (ADD a x) +(MSUB a _ (MOVDconst [0])) -> a +(MSUB a x (MOVDconst [1])) -> (SUB a x) +(MSUB a x (MOVDconst [c])) && isPowerOfTwo(c) -> (SUBshiftLL a x [log2(c)]) +(MSUB a x (MOVDconst [c])) && isPowerOfTwo(c-1) && c>=3 -> (SUB a (ADDshiftLL x x [log2(c-1)])) +(MSUB a x (MOVDconst [c])) && isPowerOfTwo(c+1) && c>=7 -> (ADD a (SUBshiftLL x x [log2(c+1)])) +(MSUB a x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) -> (ADDshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) +(MSUB a x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) -> (SUBshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) +(MSUB a x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) -> (ADDshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) +(MSUB a x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) -> (SUBshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + +(MSUB a (MOVDconst [-1]) x) -> (ADD a x) +(MSUB a (MOVDconst [0]) _) -> a +(MSUB a (MOVDconst [1]) x) -> (SUB a x) +(MSUB a (MOVDconst [c]) x) && isPowerOfTwo(c) -> (SUBshiftLL a x [log2(c)]) +(MSUB a (MOVDconst [c]) x) && isPowerOfTwo(c-1) && c>=3 -> (SUB a (ADDshiftLL x x [log2(c-1)])) +(MSUB a (MOVDconst [c]) x) && isPowerOfTwo(c+1) && c>=7 -> (ADD a (SUBshiftLL x x [log2(c+1)])) +(MSUB a (MOVDconst [c]) x) && c%3 == 0 && isPowerOfTwo(c/3) -> (ADDshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) +(MSUB a (MOVDconst [c]) x) && c%5 == 0 && isPowerOfTwo(c/5) -> (SUBshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) +(MSUB a (MOVDconst [c]) x) && c%7 == 0 && isPowerOfTwo(c/7) -> (ADDshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) +(MSUB a (MOVDconst [c]) x) && c%9 == 0 && isPowerOfTwo(c/9) -> (SUBshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + +(MSUBW a x (MOVDconst [c])) && int32(c)==-1 -> (ADD a x) +(MSUBW a _ (MOVDconst [c])) && int32(c)==0 -> a +(MSUBW a x (MOVDconst [c])) && int32(c)==1 -> (SUB a x) +(MSUBW a x (MOVDconst [c])) && isPowerOfTwo(c) -> (SUBshiftLL a x [log2(c)]) +(MSUBW a x (MOVDconst [c])) && isPowerOfTwo(c-1) && int32(c)>=3 -> (SUB a (ADDshiftLL x x [log2(c-1)])) +(MSUBW a x (MOVDconst [c])) && isPowerOfTwo(c+1) && int32(c)>=7 -> (ADD a (SUBshiftLL x x [log2(c+1)])) +(MSUBW a x (MOVDconst [c])) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (ADDshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) +(MSUBW a x (MOVDconst [c])) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (SUBshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) +(MSUBW a x (MOVDconst [c])) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (ADDshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) +(MSUBW a x (MOVDconst [c])) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (SUBshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + +(MSUBW a (MOVDconst [c]) x) && int32(c)==-1 -> (ADD a x) +(MSUBW a (MOVDconst [c]) _) && int32(c)==0 -> a +(MSUBW a (MOVDconst [c]) x) && int32(c)==1 -> (SUB a x) +(MSUBW a (MOVDconst [c]) x) && isPowerOfTwo(c) -> (SUBshiftLL a x [log2(c)]) +(MSUBW a (MOVDconst [c]) x) && isPowerOfTwo(c-1) && int32(c)>=3 -> (SUB a (ADDshiftLL x x [log2(c-1)])) +(MSUBW a (MOVDconst [c]) x) && isPowerOfTwo(c+1) && int32(c)>=7 -> (ADD a (SUBshiftLL x x [log2(c+1)])) +(MSUBW a (MOVDconst [c]) x) && c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) -> (ADDshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) +(MSUBW a (MOVDconst [c]) x) && c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) -> (SUBshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) +(MSUBW a (MOVDconst [c]) x) && c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) -> (ADDshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) +(MSUBW a (MOVDconst [c]) x) && c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) -> (SUBshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + // div by constant (UDIV x (MOVDconst [1])) -> x (UDIV x (MOVDconst [c])) && isPowerOfTwo(c) -> (SRLconst [log2(c)] x) @@ -1261,6 +1349,14 @@ (MULW (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(int32(c)*int32(d))]) (MNEG (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [-c*d]) (MNEGW (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [-int64(int32(c)*int32(d))]) +(MADD (MOVDconst [c]) x y) -> (ADDconst [c] (MUL x y)) +(MADDW (MOVDconst [c]) x y) -> (ADDconst [c] (MULW x y)) +(MSUB (MOVDconst [c]) x y) -> (ADDconst [c] (MNEG x y)) +(MSUBW (MOVDconst [c]) x y) -> (ADDconst [c] (MNEGW x y)) +(MADD a (MOVDconst [c]) (MOVDconst [d])) -> (ADDconst [c*d] a) +(MADDW a (MOVDconst [c]) (MOVDconst [d])) -> (ADDconst [int64(int32(c)*int32(d))] a) +(MSUB a (MOVDconst [c]) (MOVDconst [d])) -> (SUBconst [c*d] a) +(MSUBW a (MOVDconst [c]) (MOVDconst [d])) -> (SUBconst [int64(int32(c)*int32(d))] a) (DIV (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [c/d]) (UDIV (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(uint64(c)/uint64(d))]) (DIVW (MOVDconst [c]) (MOVDconst [d])) -> (MOVDconst [int64(int32(c)/int32(d))]) diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index 5bf165df48f6d..f07ab4209087f 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -139,6 +139,10 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64LessThan_0(v) case OpARM64LessThanU: return rewriteValueARM64_OpARM64LessThanU_0(v) + case OpARM64MADD: + return rewriteValueARM64_OpARM64MADD_0(v) || rewriteValueARM64_OpARM64MADD_10(v) || rewriteValueARM64_OpARM64MADD_20(v) + case OpARM64MADDW: + return rewriteValueARM64_OpARM64MADDW_0(v) || rewriteValueARM64_OpARM64MADDW_10(v) || rewriteValueARM64_OpARM64MADDW_20(v) case OpARM64MNEG: return rewriteValueARM64_OpARM64MNEG_0(v) || rewriteValueARM64_OpARM64MNEG_10(v) || rewriteValueARM64_OpARM64MNEG_20(v) case OpARM64MNEGW: @@ -245,6 +249,10 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64MOVWstorezeroidx_0(v) case OpARM64MOVWstorezeroidx4: return rewriteValueARM64_OpARM64MOVWstorezeroidx4_0(v) + case OpARM64MSUB: + return rewriteValueARM64_OpARM64MSUB_0(v) || rewriteValueARM64_OpARM64MSUB_10(v) || rewriteValueARM64_OpARM64MSUB_20(v) + case OpARM64MSUBW: + return rewriteValueARM64_OpARM64MSUBW_0(v) || rewriteValueARM64_OpARM64MSUBW_10(v) || rewriteValueARM64_OpARM64MSUBW_20(v) case OpARM64MUL: return rewriteValueARM64_OpARM64MUL_0(v) || rewriteValueARM64_OpARM64MUL_10(v) || rewriteValueARM64_OpARM64MUL_20(v) case OpARM64MULW: @@ -924,7 +932,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { return true } // match: (ADD a l:(MUL x y)) - // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: l.Uses==1 && clobber(l) // result: (MADD a x y) for { _ = v.Args[1] @@ -936,7 +944,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] - if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MADD) @@ -946,7 +954,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { return true } // match: (ADD l:(MUL x y) a) - // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: l.Uses==1 && clobber(l) // result: (MADD a x y) for { _ = v.Args[1] @@ -958,7 +966,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { x := l.Args[0] y := l.Args[1] a := v.Args[1] - if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MADD) @@ -968,7 +976,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { return true } // match: (ADD a l:(MNEG x y)) - // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: l.Uses==1 && clobber(l) // result: (MSUB a x y) for { _ = v.Args[1] @@ -980,7 +988,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] - if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MSUB) @@ -990,7 +998,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { return true } // match: (ADD l:(MNEG x y) a) - // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: l.Uses==1 && clobber(l) // result: (MSUB a x y) for { _ = v.Args[1] @@ -1002,7 +1010,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { x := l.Args[0] y := l.Args[1] a := v.Args[1] - if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MSUB) @@ -1012,7 +1020,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { return true } // match: (ADD a l:(MULW x y)) - // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: a.Type.Size() != 8 && l.Uses==1 && clobber(l) // result: (MADDW a x y) for { _ = v.Args[1] @@ -1024,7 +1032,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] - if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(a.Type.Size() != 8 && l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MADDW) @@ -1034,7 +1042,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { return true } // match: (ADD l:(MULW x y) a) - // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: a.Type.Size() != 8 && l.Uses==1 && clobber(l) // result: (MADDW a x y) for { _ = v.Args[1] @@ -1046,7 +1054,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { x := l.Args[0] y := l.Args[1] a := v.Args[1] - if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(a.Type.Size() != 8 && l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MADDW) @@ -1056,7 +1064,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { return true } // match: (ADD a l:(MNEGW x y)) - // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: a.Type.Size() != 8 && l.Uses==1 && clobber(l) // result: (MSUBW a x y) for { _ = v.Args[1] @@ -1068,7 +1076,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] - if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(a.Type.Size() != 8 && l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MSUBW) @@ -1078,7 +1086,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { return true } // match: (ADD l:(MNEGW x y) a) - // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: a.Type.Size() != 8 && l.Uses==1 && clobber(l) // result: (MSUBW a x y) for { _ = v.Args[1] @@ -1090,7 +1098,7 @@ func rewriteValueARM64_OpARM64ADD_0(v *Value) bool { x := l.Args[0] y := l.Args[1] a := v.Args[1] - if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(a.Type.Size() != 8 && l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MSUBW) @@ -6515,192 +6523,229 @@ func rewriteValueARM64_OpARM64LessThanU_0(v *Value) bool { } return false } -func rewriteValueARM64_OpARM64MNEG_0(v *Value) bool { +func rewriteValueARM64_OpARM64MADD_0(v *Value) bool { b := v.Block _ = b - // match: (MNEG x (MOVDconst [-1])) + // match: (MADD a x (MOVDconst [-1])) // cond: - // result: x + // result: (SUB a x) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != -1 { + if v_2.AuxInt != -1 { break } - v.reset(OpCopy) - v.Type = x.Type + v.reset(OpARM64SUB) + v.AddArg(a) v.AddArg(x) return true } - // match: (MNEG (MOVDconst [-1]) x) + // match: (MADD a _ (MOVDconst [0])) // cond: - // result: x + // result: a for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != -1 { + if v_2.AuxInt != 0 { break } - x := v.Args[1] v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) + v.Type = a.Type + v.AddArg(a) return true } - // match: (MNEG _ (MOVDconst [0])) + // match: (MADD a x (MOVDconst [1])) // cond: - // result: (MOVDconst [0]) + // result: (ADD a x) for { - _ = v.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 0 { + if v_2.AuxInt != 1 { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64ADD) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MNEG (MOVDconst [0]) _) - // cond: - // result: (MOVDconst [0]) + // match: (MADD a x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (ADDshiftLL a x [log2(c)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != 0 { + c := v_2.AuxInt + if !(isPowerOfTwo(c)) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MNEG x (MOVDconst [1])) - // cond: - // result: (NEG x) + // match: (MADD a x (MOVDconst [c])) + // cond: isPowerOfTwo(c-1) && c>=3 + // result: (ADD a (ADDshiftLL x x [log2(c-1)])) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 1 { + c := v_2.AuxInt + if !(isPowerOfTwo(c-1) && c >= 3) { break } - v.reset(OpARM64NEG) - v.AddArg(x) + v.reset(OpARM64ADD) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MNEG (MOVDconst [1]) x) - // cond: - // result: (NEG x) + // match: (MADD a x (MOVDconst [c])) + // cond: isPowerOfTwo(c+1) && c>=7 + // result: (SUB a (SUBshiftLL x x [log2(c+1)])) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != 1 { + c := v_2.AuxInt + if !(isPowerOfTwo(c+1) && c >= 7) { break } - x := v.Args[1] - v.reset(OpARM64NEG) - v.AddArg(x) + v.reset(OpARM64SUB) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MNEG x (MOVDconst [c])) - // cond: isPowerOfTwo(c) - // result: (NEG (SLLconst [log2(c)] x)) + // match: (MADD a x (MOVDconst [c])) + // cond: c%3 == 0 && isPowerOfTwo(c/3) + // result: (SUBshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c)) { + c := v_2.AuxInt + if !(c%3 == 0 && isPowerOfTwo(c/3)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 3) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: isPowerOfTwo(c) - // result: (NEG (SLLconst [log2(c)] x)) + // match: (MADD a x (MOVDconst [c])) + // cond: c%5 == 0 && isPowerOfTwo(c/5) + // result: (ADDshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c)) { + c := v_2.AuxInt + if !(c%5 == 0 && isPowerOfTwo(c/5)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 5) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEG x (MOVDconst [c])) - // cond: isPowerOfTwo(c-1) && c >= 3 - // result: (NEG (ADDshiftLL x x [log2(c-1)])) + // match: (MADD a x (MOVDconst [c])) + // cond: c%7 == 0 && isPowerOfTwo(c/7) + // result: (SUBshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c-1) && c >= 3) { + c := v_2.AuxInt + if !(c%7 == 0 && isPowerOfTwo(c/7)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c - 1) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 7) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: isPowerOfTwo(c-1) && c >= 3 - // result: (NEG (ADDshiftLL x x [log2(c-1)])) + // match: (MADD a x (MOVDconst [c])) + // cond: c%9 == 0 && isPowerOfTwo(c/9) + // result: (ADDshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c-1) && c >= 3) { + c := v_2.AuxInt + if !(c%9 == 0 && isPowerOfTwo(c/9)) { break } - v.reset(OpARM64NEG) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 9) + v.AddArg(a) v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c - 1) + v0.AuxInt = 3 v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) @@ -6708,488 +6753,508 @@ func rewriteValueARM64_OpARM64MNEG_0(v *Value) bool { } return false } -func rewriteValueARM64_OpARM64MNEG_10(v *Value) bool { +func rewriteValueARM64_OpARM64MADD_10(v *Value) bool { b := v.Block _ = b - // match: (MNEG x (MOVDconst [c])) - // cond: isPowerOfTwo(c+1) && c >= 7 - // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) + // match: (MADD a (MOVDconst [-1]) x) + // cond: + // result: (SUB a x) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c+1) && c >= 7) { + if v_1.AuxInt != -1 { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c + 1) - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) + x := v.Args[2] + v.reset(OpARM64SUB) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: isPowerOfTwo(c+1) && c >= 7 - // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) + // match: (MADD a (MOVDconst [0]) _) + // cond: + // result: a for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c+1) && c >= 7) { + if v_1.AuxInt != 0 { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c + 1) - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpCopy) + v.Type = a.Type + v.AddArg(a) return true } - // match: (MNEG x (MOVDconst [c])) - // cond: c%3 == 0 && isPowerOfTwo(c/3) - // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + // match: (MADD a (MOVDconst [1]) x) + // cond: + // result: (ADD a x) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(c%3 == 0 && isPowerOfTwo(c/3)) { + if v_1.AuxInt != 1 { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + x := v.Args[2] + v.reset(OpARM64ADD) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: c%3 == 0 && isPowerOfTwo(c/3) - // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + // match: (MADD a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c) + // result: (ADDshiftLL a x [log2(c)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%3 == 0 && isPowerOfTwo(c/3)) { + c := v_1.AuxInt + x := v.Args[2] + if !(isPowerOfTwo(c)) { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MNEG x (MOVDconst [c])) - // cond: c%5 == 0 && isPowerOfTwo(c/5) - // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) + // match: (MADD a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c-1) && c>=3 + // result: (ADD a (ADDshiftLL x x [log2(c-1)])) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(c%5 == 0 && isPowerOfTwo(c/5)) { + x := v.Args[2] + if !(isPowerOfTwo(c-1) && c >= 3) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 5) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 2 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) + v.reset(OpARM64ADD) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: c%5 == 0 && isPowerOfTwo(c/5) - // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) + // match: (MADD a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c+1) && c>=7 + // result: (SUB a (SUBshiftLL x x [log2(c+1)])) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%5 == 0 && isPowerOfTwo(c/5)) { + c := v_1.AuxInt + x := v.Args[2] + if !(isPowerOfTwo(c+1) && c >= 7) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 5) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 2 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) + v.reset(OpARM64SUB) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v0.AddArg(x) + v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEG x (MOVDconst [c])) - // cond: c%7 == 0 && isPowerOfTwo(c/7) - // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + // match: (MADD a (MOVDconst [c]) x) + // cond: c%3 == 0 && isPowerOfTwo(c/3) + // result: (SUBshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(c%7 == 0 && isPowerOfTwo(c/7)) { + x := v.Args[2] + if !(c%3 == 0 && isPowerOfTwo(c/3)) { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 7) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 3) + v.AddArg(a) v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 3 + v0.AuxInt = 2 v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEG (MOVDconst [c]) x) - // cond: c%7 == 0 && isPowerOfTwo(c/7) - // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + // match: (MADD a (MOVDconst [c]) x) + // cond: c%5 == 0 && isPowerOfTwo(c/5) + // result: (ADDshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%7 == 0 && isPowerOfTwo(c/7)) { + c := v_1.AuxInt + x := v.Args[2] + if !(c%5 == 0 && isPowerOfTwo(c/5)) { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 7) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 3 + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 5) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEG x (MOVDconst [c])) - // cond: c%9 == 0 && isPowerOfTwo(c/9) - // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + // match: (MADD a (MOVDconst [c]) x) + // cond: c%7 == 0 && isPowerOfTwo(c/7) + // result: (SUBshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(c%9 == 0 && isPowerOfTwo(c/9)) { + x := v.Args[2] + if !(c%7 == 0 && isPowerOfTwo(c/7)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 9) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 3 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 7) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEG (MOVDconst [c]) x) + // match: (MADD a (MOVDconst [c]) x) // cond: c%9 == 0 && isPowerOfTwo(c/9) - // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + // result: (ADDshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] + c := v_1.AuxInt + x := v.Args[2] if !(c%9 == 0 && isPowerOfTwo(c/9)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 9) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 3 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 9) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) v.AddArg(v0) return true } return false } -func rewriteValueARM64_OpARM64MNEG_20(v *Value) bool { - // match: (MNEG (MOVDconst [c]) (MOVDconst [d])) +func rewriteValueARM64_OpARM64MADD_20(v *Value) bool { + b := v.Block + _ = b + // match: (MADD (MOVDconst [c]) x y) // cond: - // result: (MOVDconst [-c*d]) + // result: (ADDconst [c] (MUL x y)) for { - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break - } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = -c * d + x := v.Args[1] + y := v.Args[2] + v.reset(OpARM64ADDconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64MUL, x.Type) + v0.AddArg(x) + v0.AddArg(y) + v.AddArg(v0) return true } - // match: (MNEG (MOVDconst [d]) (MOVDconst [c])) + // match: (MADD a (MOVDconst [c]) (MOVDconst [d])) // cond: - // result: (MOVDconst [-c*d]) + // result: (ADDconst [c*d] a) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - d := v_0.AuxInt + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = -c * d + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { + break + } + d := v_2.AuxInt + v.reset(OpARM64ADDconst) + v.AuxInt = c * d + v.AddArg(a) return true } return false } -func rewriteValueARM64_OpARM64MNEGW_0(v *Value) bool { +func rewriteValueARM64_OpARM64MADDW_0(v *Value) bool { b := v.Block _ = b - // match: (MNEGW x (MOVDconst [c])) + // match: (MADDW a x (MOVDconst [c])) // cond: int32(c)==-1 - // result: x + // result: (SUB a x) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { - break + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { + break } - c := v_1.AuxInt + c := v_2.AuxInt if !(int32(c) == -1) { break } - v.reset(OpCopy) - v.Type = x.Type + v.reset(OpARM64SUB) + v.AddArg(a) v.AddArg(x) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: int32(c)==-1 - // result: x + // match: (MADDW a _ (MOVDconst [c])) + // cond: int32(c)==0 + // result: a for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(int32(c) == -1) { + c := v_2.AuxInt + if !(int32(c) == 0) { break } v.reset(OpCopy) - v.Type = x.Type - v.AddArg(x) + v.Type = a.Type + v.AddArg(a) return true } - // match: (MNEGW _ (MOVDconst [c])) - // cond: int32(c)==0 - // result: (MOVDconst [0]) + // match: (MADDW a x (MOVDconst [c])) + // cond: int32(c)==1 + // result: (ADD a x) for { - _ = v.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(int32(c) == 0) { + c := v_2.AuxInt + if !(int32(c) == 1) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64ADD) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MNEGW (MOVDconst [c]) _) - // cond: int32(c)==0 - // result: (MOVDconst [0]) + // match: (MADDW a x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (ADDshiftLL a x [log2(c)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - if !(int32(c) == 0) { + c := v_2.AuxInt + if !(isPowerOfTwo(c)) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: int32(c)==1 - // result: (NEG x) + // match: (MADDW a x (MOVDconst [c])) + // cond: isPowerOfTwo(c-1) && int32(c)>=3 + // result: (ADD a (ADDshiftLL x x [log2(c-1)])) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(int32(c) == 1) { + c := v_2.AuxInt + if !(isPowerOfTwo(c-1) && int32(c) >= 3) { break } - v.reset(OpARM64NEG) - v.AddArg(x) + v.reset(OpARM64ADD) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: int32(c)==1 - // result: (NEG x) + // match: (MADDW a x (MOVDconst [c])) + // cond: isPowerOfTwo(c+1) && int32(c)>=7 + // result: (SUB a (SUBshiftLL x x [log2(c+1)])) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(int32(c) == 1) { + c := v_2.AuxInt + if !(isPowerOfTwo(c+1) && int32(c) >= 7) { break } - v.reset(OpARM64NEG) - v.AddArg(x) + v.reset(OpARM64SUB) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: isPowerOfTwo(c) - // result: (NEG (SLLconst [log2(c)] x)) + // match: (MADDW a x (MOVDconst [c])) + // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) + // result: (SUBshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c)) { + c := v_2.AuxInt + if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 3) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: isPowerOfTwo(c) - // result: (NEG (SLLconst [log2(c)] x)) + // match: (MADDW a x (MOVDconst [c])) + // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) + // result: (ADDshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c)) { + c := v_2.AuxInt + if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 5) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: isPowerOfTwo(c-1) && int32(c) >= 3 - // result: (NEG (ADDshiftLL x x [log2(c-1)])) + // match: (MADDW a x (MOVDconst [c])) + // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) + // result: (SUBshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) for { - _ = v.Args[1] - x := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - if !(isPowerOfTwo(c-1) && int32(c) >= 3) { + c := v_2.AuxInt + if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c - 1) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 7) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: isPowerOfTwo(c-1) && int32(c) >= 3 - // result: (NEG (ADDshiftLL x x [log2(c-1)])) + // match: (MADDW a x (MOVDconst [c])) + // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) + // result: (ADDshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c-1) && int32(c) >= 3) { + c := v_2.AuxInt + if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { break } - v.reset(OpARM64NEG) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 9) + v.AddArg(a) v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c - 1) + v0.AuxInt = 3 v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) @@ -7197,196 +7262,205 @@ func rewriteValueARM64_OpARM64MNEGW_0(v *Value) bool { } return false } -func rewriteValueARM64_OpARM64MNEGW_10(v *Value) bool { +func rewriteValueARM64_OpARM64MADDW_10(v *Value) bool { b := v.Block _ = b - // match: (MNEGW x (MOVDconst [c])) - // cond: isPowerOfTwo(c+1) && int32(c) >= 7 - // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) + // match: (MADDW a (MOVDconst [c]) x) + // cond: int32(c)==-1 + // result: (SUB a x) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(isPowerOfTwo(c+1) && int32(c) >= 7) { + x := v.Args[2] + if !(int32(c) == -1) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c + 1) - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpARM64SUB) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: isPowerOfTwo(c+1) && int32(c) >= 7 - // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) + // match: (MADDW a (MOVDconst [c]) _) + // cond: int32(c)==0 + // result: a for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(isPowerOfTwo(c+1) && int32(c) >= 7) { + c := v_1.AuxInt + if !(int32(c) == 0) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v0.AuxInt = log2(c + 1) - v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) - v1.AddArg(x) - v0.AddArg(v1) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpCopy) + v.Type = a.Type + v.AddArg(a) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) - // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + // match: (MADDW a (MOVDconst [c]) x) + // cond: int32(c)==1 + // result: (ADD a x) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { + x := v.Args[2] + if !(int32(c) == 1) { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 2 - v0.AddArg(x) - v0.AddArg(x) - v.AddArg(v0) + v.reset(OpARM64ADD) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) - // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) + // match: (MADDW a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c) + // result: (ADDshiftLL a x [log2(c)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { + c := v_1.AuxInt + x := v.Args[2] + if !(isPowerOfTwo(c)) { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 3) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 2 + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c) + v.AddArg(a) + v.AddArg(x) + return true + } + // match: (MADDW a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c-1) && int32(c)>=3 + // result: (ADD a (ADDshiftLL x x [log2(c-1)])) + for { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + x := v.Args[2] + if !(isPowerOfTwo(c-1) && int32(c) >= 3) { + break + } + v.reset(OpARM64ADD) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) - // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) + // match: (MADDW a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c+1) && int32(c)>=7 + // result: (SUB a (SUBshiftLL x x [log2(c+1)])) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { + x := v.Args[2] + if !(isPowerOfTwo(c+1) && int32(c) >= 7) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 5) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 2 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) + v.reset(OpARM64SUB) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v0.AddArg(x) + v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) - // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) + // match: (MADDW a (MOVDconst [c]) x) + // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) + // result: (SUBshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] - if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { + c := v_1.AuxInt + x := v.Args[2] + if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 5) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 2 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 3) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEGW x (MOVDconst [c])) - // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) - // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + // match: (MADDW a (MOVDconst [c]) x) + // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) + // result: (ADDshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { + x := v.Args[2] + if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type - v.AuxInt = log2(c / 7) - v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) - v0.AuxInt = 3 + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 5) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 v0.AddArg(x) v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEGW (MOVDconst [c]) x) + // match: (MADDW a (MOVDconst [c]) x) // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) - // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + // result: (SUBshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - x := v.Args[1] + c := v_1.AuxInt + x := v.Args[2] if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { break } - v.reset(OpARM64SLLconst) - v.Type = x.Type + v.reset(OpARM64SUBshiftLL) v.AuxInt = log2(c / 7) + v.AddArg(a) v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) v0.AuxInt = 3 v0.AddArg(x) @@ -7394,880 +7468,1832 @@ func rewriteValueARM64_OpARM64MNEGW_10(v *Value) bool { v.AddArg(v0) return true } - // match: (MNEGW x (MOVDconst [c])) + // match: (MADDW a (MOVDconst [c]) x) // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) - // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + // result: (ADDshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) for { - _ = v.Args[1] - x := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt + x := v.Args[2] if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { break } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 9) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 3 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 9) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) v.AddArg(v0) return true } - // match: (MNEGW (MOVDconst [c]) x) - // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) - // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + return false +} +func rewriteValueARM64_OpARM64MADDW_20(v *Value) bool { + b := v.Block + _ = b + // match: (MADDW (MOVDconst [c]) x y) + // cond: + // result: (ADDconst [c] (MULW x y)) for { - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt x := v.Args[1] - if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { - break - } - v.reset(OpARM64NEG) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) - v0.AuxInt = log2(c / 9) - v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) - v1.AuxInt = 3 - v1.AddArg(x) - v1.AddArg(x) - v0.AddArg(v1) + y := v.Args[2] + v.reset(OpARM64ADDconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64MULW, x.Type) + v0.AddArg(x) + v0.AddArg(y) v.AddArg(v0) return true } - return false -} -func rewriteValueARM64_OpARM64MNEGW_20(v *Value) bool { - // match: (MNEGW (MOVDconst [c]) (MOVDconst [d])) + // match: (MADDW a (MOVDconst [c]) (MOVDconst [d])) // cond: - // result: (MOVDconst [-int64(int32(c)*int32(d))]) + // result: (ADDconst [int64(int32(c)*int32(d))] a) for { - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - c := v_0.AuxInt + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - d := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = -int64(int32(c) * int32(d)) + c := v_1.AuxInt + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { + break + } + d := v_2.AuxInt + v.reset(OpARM64ADDconst) + v.AuxInt = int64(int32(c) * int32(d)) + v.AddArg(a) return true } - // match: (MNEGW (MOVDconst [d]) (MOVDconst [c])) + return false +} +func rewriteValueARM64_OpARM64MNEG_0(v *Value) bool { + b := v.Block + _ = b + // match: (MNEG x (MOVDconst [-1])) // cond: - // result: (MOVDconst [-int64(int32(c)*int32(d))]) + // result: x for { _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { - break - } - d := v_0.AuxInt + x := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = -int64(int32(c) * int32(d)) + if v_1.AuxInt != -1 { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64MOD_0(v *Value) bool { - // match: (MOD (MOVDconst [c]) (MOVDconst [d])) + // match: (MNEG (MOVDconst [-1]) x) // cond: - // result: (MOVDconst [c%d]) + // result: x for { _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt + if v_0.AuxInt != -1 { + break + } + x := v.Args[1] + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) + return true + } + // match: (MNEG _ (MOVDconst [0])) + // cond: + // result: (MOVDconst [0]) + for { + _ = v.Args[1] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - d := v_1.AuxInt + if v_1.AuxInt != 0 { + break + } v.reset(OpARM64MOVDconst) - v.AuxInt = c % d + v.AuxInt = 0 return true } - return false -} -func rewriteValueARM64_OpARM64MODW_0(v *Value) bool { - // match: (MODW (MOVDconst [c]) (MOVDconst [d])) + // match: (MNEG (MOVDconst [0]) _) // cond: - // result: (MOVDconst [int64(int32(c)%int32(d))]) + // result: (MOVDconst [0]) for { _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_0.AuxInt != 0 { break } - d := v_1.AuxInt v.reset(OpARM64MOVDconst) - v.AuxInt = int64(int32(c) % int32(d)) + v.AuxInt = 0 return true } - return false -} -func rewriteValueARM64_OpARM64MOVBUload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVBUload [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBUload [off1+off2] {sym} ptr mem) + // match: (MNEG x (MOVDconst [1])) + // cond: + // result: (NEG x) for { - off1 := v.AuxInt - sym := v.Aux _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_1.AuxInt != 1 { break } - v.reset(OpARM64MOVBUload) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64NEG) + v.AddArg(x) return true } - // match: (MOVBUload [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVBUloadidx ptr idx mem) + // match: (MNEG (MOVDconst [1]) x) + // cond: + // result: (NEG x) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + if v_0.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + if v_0.AuxInt != 1 { break } - v.reset(OpARM64MOVBUloadidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + x := v.Args[1] + v.reset(OpARM64NEG) + v.AddArg(x) return true } - // match: (MOVBUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // match: (MNEG x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (NEG (SLLconst [log2(c)] x)) for { - off1 := v.AuxInt - sym1 := v.Aux _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_1.AuxInt + if !(isPowerOfTwo(c)) { break } - v.reset(OpARM64MOVBUload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBUload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) - // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) - // result: (MOVDconst [0]) + // match: (MNEG (MOVDconst [c]) x) + // cond: isPowerOfTwo(c) + // result: (NEG (SLLconst [log2(c)] x)) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[1] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVBstorezero { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - off2 := v_1.AuxInt - sym2 := v_1.Aux - _ = v_1.Args[1] - ptr2 := v_1.Args[0] - if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c)) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c) + v0.AddArg(x) + v.AddArg(v0) return true } - return false -} -func rewriteValueARM64_OpARM64MOVBUloadidx_0(v *Value) bool { - // match: (MOVBUloadidx ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVBUload [c] ptr mem) + // match: (MNEG x (MOVDconst [c])) + // cond: isPowerOfTwo(c-1) && c >= 3 + // result: (NEG (ADDshiftLL x x [log2(c-1)])) for { - _ = v.Args[2] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVBUload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + if !(isPowerOfTwo(c-1) && c >= 3) { + break + } + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBUloadidx (MOVDconst [c]) ptr mem) - // cond: - // result: (MOVBUload [c] ptr mem) + // match: (MNEG (MOVDconst [c]) x) + // cond: isPowerOfTwo(c-1) && c >= 3 + // result: (NEG (ADDshiftLL x x [log2(c-1)])) for { - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVBUload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVBUloadidx ptr idx (MOVBstorezeroidx ptr2 idx2 _)) - // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) - // result: (MOVDconst [0]) - for { - _ = v.Args[2] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVBstorezeroidx { - break - } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + x := v.Args[1] + if !(isPowerOfTwo(c-1) && c >= 3) { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } return false } -func rewriteValueARM64_OpARM64MOVBUreg_0(v *Value) bool { - // match: (MOVBUreg x:(MOVBUload _ _)) - // cond: - // result: (MOVDreg x) +func rewriteValueARM64_OpARM64MNEG_10(v *Value) bool { + b := v.Block + _ = b + // match: (MNEG x (MOVDconst [c])) + // cond: isPowerOfTwo(c+1) && c >= 7 + // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) for { + _ = v.Args[1] x := v.Args[0] - if x.Op != OpARM64MOVBUload { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_1.AuxInt + if !(isPowerOfTwo(c+1) && c >= 7) { + break + } + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBUreg x:(MOVBUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MNEG (MOVDconst [c]) x) + // cond: isPowerOfTwo(c+1) && c >= 7 + // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) for { - x := v.Args[0] - if x.Op != OpARM64MOVBUloadidx { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c+1) && c >= 7) { + break + } + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBUreg x:(MOVBUreg _)) - // cond: - // result: (MOVDreg x) + // match: (MNEG x (MOVDconst [c])) + // cond: c%3 == 0 && isPowerOfTwo(c/3) + // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) for { + _ = v.Args[1] x := v.Args[0] - if x.Op != OpARM64MOVBUreg { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVBUreg (ANDconst [c] x)) - // cond: - // result: (ANDconst [c&(1<<8-1)] x) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64ANDconst { + c := v_1.AuxInt + if !(c%3 == 0 && isPowerOfTwo(c/3)) { break } - c := v_0.AuxInt - x := v_0.Args[0] - v.reset(OpARM64ANDconst) - v.AuxInt = c & (1<<8 - 1) - v.AddArg(x) + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBUreg (MOVDconst [c])) - // cond: - // result: (MOVDconst [int64(uint8(c))]) + // match: (MNEG (MOVDconst [c]) x) + // cond: c%3 == 0 && isPowerOfTwo(c/3) + // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) for { + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(uint8(c)) + x := v.Args[1] + if !(c%3 == 0 && isPowerOfTwo(c/3)) { + break + } + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBUreg x) - // cond: x.Type.IsBoolean() - // result: (MOVDreg x) + // match: (MNEG x (MOVDconst [c])) + // cond: c%5 == 0 && isPowerOfTwo(c/5) + // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) for { + _ = v.Args[1] x := v.Args[0] - if !(x.Type.IsBoolean()) { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) + c := v_1.AuxInt + if !(c%5 == 0 && isPowerOfTwo(c/5)) { + break + } + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 5) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 2 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) return true } - // match: (MOVBUreg (SLLconst [sc] x)) - // cond: isARM64BFMask(sc, 1<<8-1, sc) - // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc))] x) + // match: (MNEG (MOVDconst [c]) x) + // cond: c%5 == 0 && isPowerOfTwo(c/5) + // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) for { + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if v_0.Op != OpARM64MOVDconst { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<8-1, sc)) { + c := v_0.AuxInt + x := v.Args[1] + if !(c%5 == 0 && isPowerOfTwo(c/5)) { break } - v.reset(OpARM64UBFIZ) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc)) - v.AddArg(x) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 5) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 2 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) return true } - // match: (MOVBUreg (SRLconst [sc] x)) - // cond: isARM64BFMask(sc, 1<<8-1, 0) - // result: (UBFX [arm64BFAuxInt(sc, 8)] x) + // match: (MNEG x (MOVDconst [c])) + // cond: c%7 == 0 && isPowerOfTwo(c/7) + // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<8-1, 0)) { + c := v_1.AuxInt + if !(c%7 == 0 && isPowerOfTwo(c/7)) { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc, 8) - v.AddArg(x) + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - return false -} -func rewriteValueARM64_OpARM64MOVBload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVBload [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBload [off1+off2] {sym} ptr mem) + // match: (MNEG (MOVDconst [c]) x) + // cond: c%7 == 0 && isPowerOfTwo(c/7) + // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) for { - off1 := v.AuxInt - sym := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + if v_0.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_0.AuxInt + x := v.Args[1] + if !(c%7 == 0 && isPowerOfTwo(c/7)) { break } - v.reset(OpARM64MOVBload) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBload [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVBloadidx ptr idx mem) + // match: (MNEG x (MOVDconst [c])) + // cond: c%9 == 0 && isPowerOfTwo(c/9) + // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + c := v_1.AuxInt + if !(c%9 == 0 && isPowerOfTwo(c/9)) { break } - v.reset(OpARM64MOVBloadidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 9) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 3 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) return true } - // match: (MOVBload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // match: (MNEG (MOVDconst [c]) x) + // cond: c%9 == 0 && isPowerOfTwo(c/9) + // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) for { - off1 := v.AuxInt - sym1 := v.Aux _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + if v_0.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_0.AuxInt + x := v.Args[1] + if !(c%9 == 0 && isPowerOfTwo(c/9)) { break } - v.reset(OpARM64MOVBload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 9) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 3 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) return true } - // match: (MOVBload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) - // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) - // result: (MOVDconst [0]) + return false +} +func rewriteValueARM64_OpARM64MNEG_20(v *Value) bool { + // match: (MNEG (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [-c*d]) for { - off := v.AuxInt - sym := v.Aux _ = v.Args[1] - ptr := v.Args[0] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt v_1 := v.Args[1] - if v_1.Op != OpARM64MOVBstorezero { + if v_1.Op != OpARM64MOVDconst { break } - off2 := v_1.AuxInt - sym2 := v_1.Aux - _ = v_1.Args[1] - ptr2 := v_1.Args[0] - if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = -c * d + return true + } + // match: (MNEG (MOVDconst [d]) (MOVDconst [c])) + // cond: + // result: (MOVDconst [-c*d]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + d := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } + c := v_1.AuxInt v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + v.AuxInt = -c * d return true } return false } -func rewriteValueARM64_OpARM64MOVBloadidx_0(v *Value) bool { - // match: (MOVBloadidx ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVBload [c] ptr mem) +func rewriteValueARM64_OpARM64MNEGW_0(v *Value) bool { + b := v.Block + _ = b + // match: (MNEGW x (MOVDconst [c])) + // cond: int32(c)==-1 + // result: x for { - _ = v.Args[2] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVBload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + if !(int32(c) == -1) { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - // match: (MOVBloadidx (MOVDconst [c]) ptr mem) - // cond: - // result: (MOVBload [c] ptr mem) + // match: (MNEGW (MOVDconst [c]) x) + // cond: int32(c)==-1 + // result: x for { - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVBload) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + x := v.Args[1] + if !(int32(c) == -1) { + break + } + v.reset(OpCopy) + v.Type = x.Type + v.AddArg(x) return true } - // match: (MOVBloadidx ptr idx (MOVBstorezeroidx ptr2 idx2 _)) - // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // match: (MNEGW _ (MOVDconst [c])) + // cond: int32(c)==0 // result: (MOVDconst [0]) for { - _ = v.Args[2] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVBstorezeroidx { + _ = v.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + c := v_1.AuxInt + if !(int32(c) == 0) { break } v.reset(OpARM64MOVDconst) v.AuxInt = 0 return true } - return false -} -func rewriteValueARM64_OpARM64MOVBreg_0(v *Value) bool { - // match: (MOVBreg x:(MOVBload _ _)) - // cond: - // result: (MOVDreg x) + // match: (MNEGW (MOVDconst [c]) _) + // cond: int32(c)==0 + // result: (MOVDconst [0]) for { - x := v.Args[0] - if x.Op != OpARM64MOVBload { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVBreg x:(MOVBloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBloadidx { + c := v_0.AuxInt + if !(int32(c) == 0) { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVBreg x:(MOVBreg _)) - // cond: - // result: (MOVDreg x) + // match: (MNEGW x (MOVDconst [c])) + // cond: int32(c)==1 + // result: (NEG x) for { + _ = v.Args[1] x := v.Args[0] - if x.Op != OpARM64MOVBreg { + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDreg) + c := v_1.AuxInt + if !(int32(c) == 1) { + break + } + v.reset(OpARM64NEG) v.AddArg(x) return true } - // match: (MOVBreg (MOVDconst [c])) - // cond: - // result: (MOVDconst [int64(int8(c))]) + // match: (MNEGW (MOVDconst [c]) x) + // cond: int32(c)==1 + // result: (NEG x) for { + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(int8(c)) + x := v.Args[1] + if !(int32(c) == 1) { + break + } + v.reset(OpARM64NEG) + v.AddArg(x) return true } - // match: (MOVBreg (SLLconst [lc] x)) - // cond: lc < 8 - // result: (SBFIZ [arm64BFAuxInt(lc, 8-lc)] x) + // match: (MNEGW x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (NEG (SLLconst [log2(c)] x)) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - lc := v_0.AuxInt - x := v_0.Args[0] - if !(lc < 8) { + c := v_1.AuxInt + if !(isPowerOfTwo(c)) { break } - v.reset(OpARM64SBFIZ) - v.AuxInt = arm64BFAuxInt(lc, 8-lc) - v.AddArg(x) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c) + v0.AddArg(x) + v.AddArg(v0) return true } - return false -} -func rewriteValueARM64_OpARM64MOVBstore_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVBstore [off1] {sym} (ADDconst [off2] ptr) val mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBstore [off1+off2] {sym} ptr val mem) + // match: (MNEGW (MOVDconst [c]) x) + // cond: isPowerOfTwo(c) + // result: (NEG (SLLconst [log2(c)] x)) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + if v_0.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c)) { break } - v.reset(OpARM64MOVBstore) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [off] {sym} (ADD ptr idx) val mem) - // cond: off == 0 && sym == nil - // result: (MOVBstoreidx ptr idx val mem) + // match: (MNEGW x (MOVDconst [c])) + // cond: isPowerOfTwo(c-1) && int32(c) >= 3 + // result: (NEG (ADDshiftLL x x [log2(c-1)])) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - val := v.Args[1] - mem := v.Args[2] - if !(off == 0 && sym == nil) { + c := v_1.AuxInt + if !(isPowerOfTwo(c-1) && int32(c) >= 3) { break } - v.reset(OpARM64MOVBstoreidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + // match: (MNEGW (MOVDconst [c]) x) + // cond: isPowerOfTwo(c-1) && int32(c) >= 3 + // result: (NEG (ADDshiftLL x x [log2(c-1)])) for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + if v_0.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c-1) && int32(c) >= 3) { break } - v.reset(OpARM64MOVBstore) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [off] {sym} ptr (MOVDconst [0]) mem) - // cond: - // result: (MOVBstorezero [off] {sym} ptr mem) + return false +} +func rewriteValueARM64_OpARM64MNEGW_10(v *Value) bool { + b := v.Block + _ = b + // match: (MNEGW x (MOVDconst [c])) + // cond: isPowerOfTwo(c+1) && int32(c) >= 7 + // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 0 { + c := v_1.AuxInt + if !(isPowerOfTwo(c+1) && int32(c) >= 7) { break } - mem := v.Args[2] - v.reset(OpARM64MOVBstorezero) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [off] {sym} ptr (MOVBreg x) mem) - // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + // match: (MNEGW (MOVDconst [c]) x) + // cond: isPowerOfTwo(c+1) && int32(c) >= 7 + // result: (NEG (ADDshiftLL (NEG x) x [log2(c+1)])) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVBreg { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) - return true - } - // match: (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) - // cond: - // result: (MOVBstore [off] {sym} ptr x mem) - for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVBUreg { + c := v_0.AuxInt + x := v.Args[1] + if !(isPowerOfTwo(c+1) && int32(c) >= 7) { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v1 := b.NewValue0(v.Pos, OpARM64NEG, x.Type) + v1.AddArg(x) + v0.AddArg(v1) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [off] {sym} ptr (MOVHreg x) mem) - // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + // match: (MNEGW x (MOVDconst [c])) + // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) + // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVHreg { + if v_1.Op != OpARM64MOVDconst { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) + c := v_1.AuxInt + if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { + break + } + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) - // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + // match: (MNEGW (MOVDconst [c]) x) + // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) + // result: (SLLconst [log2(c/3)] (SUBshiftLL x x [2])) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVHUreg { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) + c := v_0.AuxInt + x := v.Args[1] + if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { + break + } + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 3) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVBstore [off] {sym} ptr (MOVWreg x) mem) - // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + // match: (MNEGW x (MOVDconst [c])) + // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) + // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] + _ = v.Args[1] + x := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWreg { + if v_1.Op != OpARM64MOVDconst { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVBstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) + c := v_1.AuxInt + if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { + break + } + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 5) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 2 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) return true } - // match: (MOVBstore [off] {sym} ptr (MOVWUreg x) mem) - // cond: - // result: (MOVBstore [off] {sym} ptr x mem) + // match: (MNEGW (MOVDconst [c]) x) + // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) + // result: (NEG (SLLconst [log2(c/5)] (ADDshiftLL x x [2]))) for { - off := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { + break + } + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 5) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 2 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + // match: (MNEGW x (MOVDconst [c])) + // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) + // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { + break + } + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEGW (MOVDconst [c]) x) + // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) + // result: (SLLconst [log2(c/7)] (SUBshiftLL x x [3])) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { + break + } + v.reset(OpARM64SLLconst) + v.Type = x.Type + v.AuxInt = log2(c / 7) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MNEGW x (MOVDconst [c])) + // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) + // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + for { + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { + break + } + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 9) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 3 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + // match: (MNEGW (MOVDconst [c]) x) + // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) + // result: (NEG (SLLconst [log2(c/9)] (ADDshiftLL x x [3]))) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { + break + } + v.reset(OpARM64NEG) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = log2(c / 9) + v1 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v1.AuxInt = 3 + v1.AddArg(x) + v1.AddArg(x) + v0.AddArg(v1) + v.AddArg(v0) + return true + } + return false +} +func rewriteValueARM64_OpARM64MNEGW_20(v *Value) bool { + // match: (MNEGW (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [-int64(int32(c)*int32(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = -int64(int32(c) * int32(d)) + return true + } + // match: (MNEGW (MOVDconst [d]) (MOVDconst [c])) + // cond: + // result: (MOVDconst [-int64(int32(c)*int32(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + d := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = -int64(int32(c) * int32(d)) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOD_0(v *Value) bool { + // match: (MOD (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [c%d]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = c % d + return true + } + return false +} +func rewriteValueARM64_OpARM64MODW_0(v *Value) bool { + // match: (MODW (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (MOVDconst [int64(int32(c)%int32(d))]) + for { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + d := v_1.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(int32(c) % int32(d)) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBUload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVBUload [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBUload [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { + break + } + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBUload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBUload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVBUloadidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVBUloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVBUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBUload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBUload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) + // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) + // result: (MOVDconst [0]) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVBstorezero { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + _ = v_1.Args[1] + ptr2 := v_1.Args[0] + if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBUloadidx_0(v *Value) bool { + // match: (MOVBUloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVBUload [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVBUload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBUloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (MOVBUload [c] ptr mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVBUload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBUloadidx ptr idx (MOVBstorezeroidx ptr2 idx2 _)) + // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // result: (MOVDconst [0]) + for { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVBstorezeroidx { + break + } + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBUreg_0(v *Value) bool { + // match: (MOVBUreg x:(MOVBUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBUreg x:(MOVBUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUloadidx { + break + } + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBUreg x:(MOVBUreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUreg { + break + } + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBUreg (ANDconst [c] x)) + // cond: + // result: (ANDconst [c&(1<<8-1)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64ANDconst { + break + } + c := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ANDconst) + v.AuxInt = c & (1<<8 - 1) + v.AddArg(x) + return true + } + // match: (MOVBUreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(uint8(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(uint8(c)) + return true + } + // match: (MOVBUreg x) + // cond: x.Type.IsBoolean() + // result: (MOVDreg x) + for { + x := v.Args[0] + if !(x.Type.IsBoolean()) { + break + } + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBUreg (SLLconst [sc] x)) + // cond: isARM64BFMask(sc, 1<<8-1, sc) + // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc))] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { + break + } + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<8-1, sc)) { + break + } + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<8-1, sc)) + v.AddArg(x) + return true + } + // match: (MOVBUreg (SRLconst [sc] x)) + // cond: isARM64BFMask(sc, 1<<8-1, 0) + // result: (UBFX [arm64BFAuxInt(sc, 8)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SRLconst { + break + } + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<8-1, 0)) { + break + } + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc, 8) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVBload [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBload [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { + break + } + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVBloadidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVBloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVBload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBload [off] {sym} ptr (MOVBstorezero [off2] {sym2} ptr2 _)) + // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) + // result: (MOVDconst [0]) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVBstorezero { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + _ = v_1.Args[1] + ptr2 := v_1.Args[0] + if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBloadidx_0(v *Value) bool { + // match: (MOVBloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVBload [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVBload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBloadidx (MOVDconst [c]) ptr mem) + // cond: + // result: (MOVBload [c] ptr mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVBload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBloadidx ptr idx (MOVBstorezeroidx ptr2 idx2 _)) + // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // result: (MOVDconst [0]) + for { + _ = v.Args[2] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVBstorezeroidx { + break + } + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBreg_0(v *Value) bool { + // match: (MOVBreg x:(MOVBload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBreg x:(MOVBloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBloadidx { + break + } + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBreg x:(MOVBreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBreg { + break + } + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVBreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(int8(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(int8(c)) + return true + } + // match: (MOVBreg (SLLconst [lc] x)) + // cond: lc < 8 + // result: (SBFIZ [arm64BFAuxInt(lc, 8-lc)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { + break + } + lc := v_0.AuxInt + x := v_0.Args[0] + if !(lc < 8) { + break + } + v.reset(OpARM64SBFIZ) + v.AuxInt = arm64BFAuxInt(lc, 8-lc) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVBstore_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVBstore [off1] {sym} (ADDconst [off2] ptr) val mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBstore [off1+off2] {sym} ptr val mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { + break + } + off2 := v_0.AuxInt + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBstore) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} (ADD ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (MOVBstoreidx ptr idx val mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVBstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVBstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVBstore) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVDconst [0]) mem) + // cond: + // result: (MOVBstorezero [off] {sym} ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + if v_1.AuxInt != 0 { + break + } + mem := v.Args[2] + v.reset(OpARM64MOVBstorezero) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVBreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVBreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVBUreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVBUreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVHreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVHreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVHUreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVHUreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVWreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVBstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVBstore [off] {sym} ptr (MOVWUreg x) mem) + // cond: + // result: (MOVBstore [off] {sym} ptr x mem) + for { + off := v.AuxInt sym := v.Aux _ = v.Args[2] ptr := v.Args[0] @@ -14508,9 +15534,403 @@ func rewriteValueARM64_OpARM64MOVHstorezeroidx_0(v *Value) bool { v.AddArg(mem) return true } - // match: (MOVHstorezeroidx (MOVDconst [c]) idx mem) + // match: (MOVHstorezeroidx (MOVDconst [c]) idx mem) + // cond: + // result: (MOVHstorezero [c] idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + idx := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVHstorezero) + v.AuxInt = c + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVHstorezeroidx ptr (SLLconst [1] idx) mem) + // cond: + // result: (MOVHstorezeroidx2 ptr idx mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SLLconst { + break + } + if v_1.AuxInt != 1 { + break + } + idx := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVHstorezeroidx2) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVHstorezeroidx ptr (ADD idx idx) mem) + // cond: + // result: (MOVHstorezeroidx2 ptr idx mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64ADD { + break + } + _ = v_1.Args[1] + idx := v_1.Args[0] + if idx != v_1.Args[1] { + break + } + mem := v.Args[2] + v.reset(OpARM64MOVHstorezeroidx2) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVHstorezeroidx (SLLconst [1] idx) ptr mem) + // cond: + // result: (MOVHstorezeroidx2 ptr idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { + break + } + if v_0.AuxInt != 1 { + break + } + idx := v_0.Args[0] + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVHstorezeroidx2) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVHstorezeroidx (ADD idx idx) ptr mem) + // cond: + // result: (MOVHstorezeroidx2 ptr idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + idx := v_0.Args[0] + if idx != v_0.Args[1] { + break + } + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVHstorezeroidx2) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVHstorezeroidx ptr (ADDconst [2] idx) x:(MOVHstorezeroidx ptr idx mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVWstorezeroidx ptr idx mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64ADDconst { + break + } + if v_1.AuxInt != 2 { + break + } + idx := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVHstorezeroidx { + break + } + _ = x.Args[2] + if ptr != x.Args[0] { + break + } + if idx != x.Args[1] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && clobber(x)) { + break + } + v.reset(OpARM64MOVWstorezeroidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVHstorezeroidx2_0(v *Value) bool { + // match: (MOVHstorezeroidx2 ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVHstorezero [c<<1] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVHstorezero) + v.AuxInt = c << 1 + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVQstorezero_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVQstorezero [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVQstorezero [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { + break + } + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVQstorezero) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVQstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVQstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVQstorezero) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVWUload [off] {sym} ptr (FMOVSstore [off] {sym} ptr val _)) + // cond: + // result: (FMOVSfpgp val) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FMOVSstore { + break + } + if v_1.AuxInt != off { + break + } + if v_1.Aux != sym { + break + } + _ = v_1.Args[2] + if ptr != v_1.Args[0] { + break + } + val := v_1.Args[1] + v.reset(OpARM64FMOVSfpgp) + v.AddArg(val) + return true + } + // match: (MOVWUload [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWUload [off1+off2] {sym} ptr mem) + for { + off1 := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDconst { + break + } + off2 := v_0.AuxInt + ptr := v_0.Args[0] + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVWUload) + v.AuxInt = off1 + off2 + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVWUload [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVWUloadidx ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVWUloadidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVWUload [off] {sym} (ADDshiftLL [2] ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVWUloadidx4 ptr idx mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { + break + } + if v_0.AuxInt != 2 { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVWUloadidx4) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVWUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + mem := v.Args[1] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVWUload) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVWUload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) + // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) + // result: (MOVDconst [0]) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[1] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWstorezero { + break + } + off2 := v_1.AuxInt + sym2 := v_1.Aux + _ = v_1.Args[1] + ptr2 := v_1.Args[0] + if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + break + } + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWUloadidx_0(v *Value) bool { + // match: (MOVWUloadidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVWUload [c] ptr mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVWUload) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVWUloadidx (MOVDconst [c]) ptr mem) // cond: - // result: (MOVHstorezero [c] idx mem) + // result: (MOVWUload [c] ptr mem) for { _ = v.Args[2] v_0 := v.Args[0] @@ -14518,17 +15938,17 @@ func rewriteValueARM64_OpARM64MOVHstorezeroidx_0(v *Value) bool { break } c := v_0.AuxInt - idx := v.Args[1] + ptr := v.Args[1] mem := v.Args[2] - v.reset(OpARM64MOVHstorezero) + v.reset(OpARM64MOVWUload) v.AuxInt = c - v.AddArg(idx) + v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVHstorezeroidx ptr (SLLconst [1] idx) mem) + // match: (MOVWUloadidx ptr (SLLconst [2] idx) mem) // cond: - // result: (MOVHstorezeroidx2 ptr idx mem) + // result: (MOVWUloadidx4 ptr idx mem) for { _ = v.Args[2] ptr := v.Args[0] @@ -14536,231 +15956,321 @@ func rewriteValueARM64_OpARM64MOVHstorezeroidx_0(v *Value) bool { if v_1.Op != OpARM64SLLconst { break } - if v_1.AuxInt != 1 { + if v_1.AuxInt != 2 { break } idx := v_1.Args[0] mem := v.Args[2] - v.reset(OpARM64MOVHstorezeroidx2) + v.reset(OpARM64MOVWUloadidx4) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstorezeroidx ptr (ADD idx idx) mem) + // match: (MOVWUloadidx (SLLconst [2] idx) ptr mem) // cond: - // result: (MOVHstorezeroidx2 ptr idx mem) + // result: (MOVWUloadidx4 ptr idx mem) for { _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADD { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - _ = v_1.Args[1] - idx := v_1.Args[0] - if idx != v_1.Args[1] { + if v_0.AuxInt != 2 { break } + idx := v_0.Args[0] + ptr := v.Args[1] mem := v.Args[2] - v.reset(OpARM64MOVHstorezeroidx2) + v.reset(OpARM64MOVWUloadidx4) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstorezeroidx (SLLconst [1] idx) ptr mem) - // cond: - // result: (MOVHstorezeroidx2 ptr idx mem) + // match: (MOVWUloadidx ptr idx (MOVWstorezeroidx ptr2 idx2 _)) + // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) + // result: (MOVDconst [0]) for { _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWstorezeroidx { break } - if v_0.AuxInt != 1 { + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { break } - idx := v_0.Args[0] - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVHstorezeroidx2) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 return true } - // match: (MOVHstorezeroidx (ADD idx idx) ptr mem) + return false +} +func rewriteValueARM64_OpARM64MOVWUloadidx4_0(v *Value) bool { + // match: (MOVWUloadidx4 ptr (MOVDconst [c]) mem) // cond: - // result: (MOVHstorezeroidx2 ptr idx mem) + // result: (MOVWUload [c<<2] ptr mem) for { _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { - break - } - _ = v_0.Args[1] - idx := v_0.Args[0] - if idx != v_0.Args[1] { + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - ptr := v.Args[1] + c := v_1.AuxInt mem := v.Args[2] - v.reset(OpARM64MOVHstorezeroidx2) + v.reset(OpARM64MOVWUload) + v.AuxInt = c << 2 v.AddArg(ptr) - v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVHstorezeroidx ptr (ADDconst [2] idx) x:(MOVHstorezeroidx ptr idx mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVWstorezeroidx ptr idx mem) + // match: (MOVWUloadidx4 ptr idx (MOVWstorezeroidx4 ptr2 idx2 _)) + // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) + // result: (MOVDconst [0]) for { _ = v.Args[2] ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWstorezeroidx4 { break } - if v_1.AuxInt != 2 { + _ = v_2.Args[2] + ptr2 := v_2.Args[0] + idx2 := v_2.Args[1] + if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { break } - idx := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVHstorezeroidx { + v.reset(OpARM64MOVDconst) + v.AuxInt = 0 + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWUreg_0(v *Value) bool { + // match: (MOVWUreg x:(MOVBUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUload { break } - _ = x.Args[2] - if ptr != x.Args[0] { + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVHUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUload { break } - if idx != x.Args[1] { + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVWUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVWUload { break } - mem := x.Args[2] - if !(x.Uses == 1 && clobber(x)) { + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVBUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUloadidx { break } - v.reset(OpARM64MOVWstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64MOVHstorezeroidx2_0(v *Value) bool { - // match: (MOVHstorezeroidx2 ptr (MOVDconst [c]) mem) + // match: (MOVWUreg x:(MOVHUloadidx _ _ _)) // cond: - // result: (MOVHstorezero [c<<1] ptr mem) + // result: (MOVDreg x) for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + x := v.Args[0] + if x.Op != OpARM64MOVHUloadidx { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVHstorezero) - v.AuxInt = c << 1 - v.AddArg(ptr) - v.AddArg(mem) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64MOVQstorezero_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVQstorezero [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVQstorezero [off1+off2] {sym} ptr mem) + // match: (MOVWUreg x:(MOVWUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + x := v.Args[0] + if x.Op != OpARM64MOVWUloadidx { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVHUloadidx2 _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUloadidx2 { break } - v.reset(OpARM64MOVQstorezero) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } - // match: (MOVQstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVQstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // match: (MOVWUreg x:(MOVWUloadidx4 _ _ _)) + // cond: + // result: (MOVDreg x) for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + x := v.Args[0] + if x.Op != OpARM64MOVWUloadidx4 { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVBUreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUreg { break } - v.reset(OpARM64MOVQstorezero) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg x:(MOVHUreg _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUreg { + break + } + v.reset(OpARM64MOVDreg) + v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVWUload [off] {sym} ptr (FMOVSstore [off] {sym} ptr val _)) +func rewriteValueARM64_OpARM64MOVWUreg_10(v *Value) bool { + // match: (MOVWUreg x:(MOVWUreg _)) // cond: - // result: (FMOVSfpgp val) + // result: (MOVDreg x) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64FMOVSstore { + x := v.Args[0] + if x.Op != OpARM64MOVWUreg { break } - if v_1.AuxInt != off { + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWUreg (ANDconst [c] x)) + // cond: + // result: (ANDconst [c&(1<<32-1)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64ANDconst { break } - if v_1.Aux != sym { + c := v_0.AuxInt + x := v_0.Args[0] + v.reset(OpARM64ANDconst) + v.AuxInt = c & (1<<32 - 1) + v.AddArg(x) + return true + } + // match: (MOVWUreg (MOVDconst [c])) + // cond: + // result: (MOVDconst [int64(uint32(c))]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - _ = v_1.Args[2] - if ptr != v_1.Args[0] { + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = int64(uint32(c)) + return true + } + // match: (MOVWUreg (SLLconst [sc] x)) + // cond: isARM64BFMask(sc, 1<<32-1, sc) + // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc))] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - val := v_1.Args[1] - v.reset(OpARM64FMOVSfpgp) - v.AddArg(val) + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<32-1, sc)) { + break + } + v.reset(OpARM64UBFIZ) + v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc)) + v.AddArg(x) return true } - // match: (MOVWUload [off1] {sym} (ADDconst [off2] ptr) mem) + // match: (MOVWUreg (SRLconst [sc] x)) + // cond: isARM64BFMask(sc, 1<<32-1, 0) + // result: (UBFX [arm64BFAuxInt(sc, 32)] x) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64SRLconst { + break + } + sc := v_0.AuxInt + x := v_0.Args[0] + if !(isARM64BFMask(sc, 1<<32-1, 0)) { + break + } + v.reset(OpARM64UBFX) + v.AuxInt = arm64BFAuxInt(sc, 32) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWload_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVWload [off1] {sym} (ADDconst [off2] ptr) mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWUload [off1+off2] {sym} ptr mem) + // result: (MOVWload [off1+off2] {sym} ptr mem) for { off1 := v.AuxInt sym := v.Aux @@ -14775,16 +16285,16 @@ func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVWUload) + v.reset(OpARM64MOVWload) v.AuxInt = off1 + off2 v.Aux = sym v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVWUload [off] {sym} (ADD ptr idx) mem) + // match: (MOVWload [off] {sym} (ADD ptr idx) mem) // cond: off == 0 && sym == nil - // result: (MOVWUloadidx ptr idx mem) + // result: (MOVWloadidx ptr idx mem) for { off := v.AuxInt sym := v.Aux @@ -14800,15 +16310,15 @@ func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVWUloadidx) + v.reset(OpARM64MOVWloadidx) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWUload [off] {sym} (ADDshiftLL [2] ptr idx) mem) + // match: (MOVWload [off] {sym} (ADDshiftLL [2] ptr idx) mem) // cond: off == 0 && sym == nil - // result: (MOVWUloadidx4 ptr idx mem) + // result: (MOVWloadidx4 ptr idx mem) for { off := v.AuxInt sym := v.Aux @@ -14827,15 +16337,15 @@ func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVWUloadidx4) + v.reset(OpARM64MOVWloadidx4) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWUload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) + // match: (MOVWload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWUload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // result: (MOVWload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) for { off1 := v.AuxInt sym1 := v.Aux @@ -14851,14 +16361,14 @@ func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVWUload) + v.reset(OpARM64MOVWload) v.AuxInt = off1 + off2 v.Aux = mergeSym(sym1, sym2) v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVWUload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) + // match: (MOVWload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) // result: (MOVDconst [0]) for { @@ -14883,10 +16393,10 @@ func rewriteValueARM64_OpARM64MOVWUload_0(v *Value) bool { } return false } -func rewriteValueARM64_OpARM64MOVWUloadidx_0(v *Value) bool { - // match: (MOVWUloadidx ptr (MOVDconst [c]) mem) +func rewriteValueARM64_OpARM64MOVWloadidx_0(v *Value) bool { + // match: (MOVWloadidx ptr (MOVDconst [c]) mem) // cond: - // result: (MOVWUload [c] ptr mem) + // result: (MOVWload [c] ptr mem) for { _ = v.Args[2] ptr := v.Args[0] @@ -14896,15 +16406,15 @@ func rewriteValueARM64_OpARM64MOVWUloadidx_0(v *Value) bool { } c := v_1.AuxInt mem := v.Args[2] - v.reset(OpARM64MOVWUload) + v.reset(OpARM64MOVWload) v.AuxInt = c v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVWUloadidx (MOVDconst [c]) ptr mem) + // match: (MOVWloadidx (MOVDconst [c]) ptr mem) // cond: - // result: (MOVWUload [c] ptr mem) + // result: (MOVWload [c] ptr mem) for { _ = v.Args[2] v_0 := v.Args[0] @@ -14914,15 +16424,15 @@ func rewriteValueARM64_OpARM64MOVWUloadidx_0(v *Value) bool { c := v_0.AuxInt ptr := v.Args[1] mem := v.Args[2] - v.reset(OpARM64MOVWUload) + v.reset(OpARM64MOVWload) v.AuxInt = c v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVWUloadidx ptr (SLLconst [2] idx) mem) + // match: (MOVWloadidx ptr (SLLconst [2] idx) mem) // cond: - // result: (MOVWUloadidx4 ptr idx mem) + // result: (MOVWloadidx4 ptr idx mem) for { _ = v.Args[2] ptr := v.Args[0] @@ -14935,15 +16445,15 @@ func rewriteValueARM64_OpARM64MOVWUloadidx_0(v *Value) bool { } idx := v_1.Args[0] mem := v.Args[2] - v.reset(OpARM64MOVWUloadidx4) + v.reset(OpARM64MOVWloadidx4) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWUloadidx (SLLconst [2] idx) ptr mem) + // match: (MOVWloadidx (SLLconst [2] idx) ptr mem) // cond: - // result: (MOVWUloadidx4 ptr idx mem) + // result: (MOVWloadidx4 ptr idx mem) for { _ = v.Args[2] v_0 := v.Args[0] @@ -14956,13 +16466,13 @@ func rewriteValueARM64_OpARM64MOVWUloadidx_0(v *Value) bool { idx := v_0.Args[0] ptr := v.Args[1] mem := v.Args[2] - v.reset(OpARM64MOVWUloadidx4) + v.reset(OpARM64MOVWloadidx4) v.AddArg(ptr) v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWUloadidx ptr idx (MOVWstorezeroidx ptr2 idx2 _)) + // match: (MOVWloadidx ptr idx (MOVWstorezeroidx ptr2 idx2 _)) // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) // result: (MOVDconst [0]) for { @@ -14985,10 +16495,10 @@ func rewriteValueARM64_OpARM64MOVWUloadidx_0(v *Value) bool { } return false } -func rewriteValueARM64_OpARM64MOVWUloadidx4_0(v *Value) bool { - // match: (MOVWUloadidx4 ptr (MOVDconst [c]) mem) +func rewriteValueARM64_OpARM64MOVWloadidx4_0(v *Value) bool { + // match: (MOVWloadidx4 ptr (MOVDconst [c]) mem) // cond: - // result: (MOVWUload [c<<2] ptr mem) + // result: (MOVWload [c<<2] ptr mem) for { _ = v.Args[2] ptr := v.Args[0] @@ -14998,13 +16508,13 @@ func rewriteValueARM64_OpARM64MOVWUloadidx4_0(v *Value) bool { } c := v_1.AuxInt mem := v.Args[2] - v.reset(OpARM64MOVWUload) + v.reset(OpARM64MOVWload) v.AuxInt = c << 2 v.AddArg(ptr) v.AddArg(mem) return true } - // match: (MOVWUloadidx4 ptr idx (MOVWstorezeroidx4 ptr2 idx2 _)) + // match: (MOVWloadidx4 ptr idx (MOVWstorezeroidx4 ptr2 idx2 _)) // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) // result: (MOVDconst [0]) for { @@ -15027,8 +16537,21 @@ func rewriteValueARM64_OpARM64MOVWUloadidx4_0(v *Value) bool { } return false } -func rewriteValueARM64_OpARM64MOVWUreg_0(v *Value) bool { - // match: (MOVWUreg x:(MOVBUload _ _)) +func rewriteValueARM64_OpARM64MOVWreg_0(v *Value) bool { + // match: (MOVWreg x:(MOVBload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVBUload _ _)) // cond: // result: (MOVDreg x) for { @@ -15036,43 +16559,108 @@ func rewriteValueARM64_OpARM64MOVWUreg_0(v *Value) bool { if x.Op != OpARM64MOVBUload { break } - _ = x.Args[1] + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVHload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVHUload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVHUload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVWload _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVWload { + break + } + _ = x.Args[1] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVBloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBloadidx { + break + } + _ = x.Args[2] + v.reset(OpARM64MOVDreg) + v.AddArg(x) + return true + } + // match: (MOVWreg x:(MOVBUloadidx _ _ _)) + // cond: + // result: (MOVDreg x) + for { + x := v.Args[0] + if x.Op != OpARM64MOVBUloadidx { + break + } + _ = x.Args[2] v.reset(OpARM64MOVDreg) v.AddArg(x) return true } - // match: (MOVWUreg x:(MOVHUload _ _)) + // match: (MOVWreg x:(MOVHloadidx _ _ _)) // cond: // result: (MOVDreg x) for { x := v.Args[0] - if x.Op != OpARM64MOVHUload { + if x.Op != OpARM64MOVHloadidx { break } - _ = x.Args[1] + _ = x.Args[2] v.reset(OpARM64MOVDreg) v.AddArg(x) return true } - // match: (MOVWUreg x:(MOVWUload _ _)) + // match: (MOVWreg x:(MOVHUloadidx _ _ _)) // cond: // result: (MOVDreg x) for { x := v.Args[0] - if x.Op != OpARM64MOVWUload { + if x.Op != OpARM64MOVHUloadidx { break } - _ = x.Args[1] + _ = x.Args[2] v.reset(OpARM64MOVDreg) v.AddArg(x) return true } - // match: (MOVWUreg x:(MOVBUloadidx _ _ _)) + // match: (MOVWreg x:(MOVWloadidx _ _ _)) // cond: // result: (MOVDreg x) for { x := v.Args[0] - if x.Op != OpARM64MOVBUloadidx { + if x.Op != OpARM64MOVWloadidx { break } _ = x.Args[2] @@ -15080,12 +16668,15 @@ func rewriteValueARM64_OpARM64MOVWUreg_0(v *Value) bool { v.AddArg(x) return true } - // match: (MOVWUreg x:(MOVHUloadidx _ _ _)) + return false +} +func rewriteValueARM64_OpARM64MOVWreg_10(v *Value) bool { + // match: (MOVWreg x:(MOVHloadidx2 _ _ _)) // cond: // result: (MOVDreg x) for { x := v.Args[0] - if x.Op != OpARM64MOVHUloadidx { + if x.Op != OpARM64MOVHloadidx2 { break } _ = x.Args[2] @@ -15093,12 +16684,12 @@ func rewriteValueARM64_OpARM64MOVWUreg_0(v *Value) bool { v.AddArg(x) return true } - // match: (MOVWUreg x:(MOVWUloadidx _ _ _)) + // match: (MOVWreg x:(MOVHUloadidx2 _ _ _)) // cond: // result: (MOVDreg x) for { x := v.Args[0] - if x.Op != OpARM64MOVWUloadidx { + if x.Op != OpARM64MOVHUloadidx2 { break } _ = x.Args[2] @@ -15106,12 +16697,12 @@ func rewriteValueARM64_OpARM64MOVWUreg_0(v *Value) bool { v.AddArg(x) return true } - // match: (MOVWUreg x:(MOVHUloadidx2 _ _ _)) + // match: (MOVWreg x:(MOVWloadidx4 _ _ _)) // cond: // result: (MOVDreg x) for { x := v.Args[0] - if x.Op != OpARM64MOVHUloadidx2 { + if x.Op != OpARM64MOVWloadidx4 { break } _ = x.Args[2] @@ -15119,20 +16710,19 @@ func rewriteValueARM64_OpARM64MOVWUreg_0(v *Value) bool { v.AddArg(x) return true } - // match: (MOVWUreg x:(MOVWUloadidx4 _ _ _)) + // match: (MOVWreg x:(MOVBreg _)) // cond: // result: (MOVDreg x) for { x := v.Args[0] - if x.Op != OpARM64MOVWUloadidx4 { + if x.Op != OpARM64MOVBreg { break } - _ = x.Args[2] v.reset(OpARM64MOVDreg) v.AddArg(x) return true } - // match: (MOVWUreg x:(MOVBUreg _)) + // match: (MOVWreg x:(MOVBUreg _)) // cond: // result: (MOVDreg x) for { @@ -15144,51 +16734,45 @@ func rewriteValueARM64_OpARM64MOVWUreg_0(v *Value) bool { v.AddArg(x) return true } - // match: (MOVWUreg x:(MOVHUreg _)) + // match: (MOVWreg x:(MOVHreg _)) // cond: // result: (MOVDreg x) for { x := v.Args[0] - if x.Op != OpARM64MOVHUreg { + if x.Op != OpARM64MOVHreg { break } v.reset(OpARM64MOVDreg) v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64MOVWUreg_10(v *Value) bool { - // match: (MOVWUreg x:(MOVWUreg _)) + // match: (MOVWreg x:(MOVHreg _)) // cond: // result: (MOVDreg x) for { x := v.Args[0] - if x.Op != OpARM64MOVWUreg { + if x.Op != OpARM64MOVHreg { break } v.reset(OpARM64MOVDreg) v.AddArg(x) return true } - // match: (MOVWUreg (ANDconst [c] x)) + // match: (MOVWreg x:(MOVWreg _)) // cond: - // result: (ANDconst [c&(1<<32-1)] x) + // result: (MOVDreg x) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64ANDconst { + x := v.Args[0] + if x.Op != OpARM64MOVWreg { break } - c := v_0.AuxInt - x := v_0.Args[0] - v.reset(OpARM64ANDconst) - v.AuxInt = c & (1<<32 - 1) + v.reset(OpARM64MOVDreg) v.AddArg(x) return true } - // match: (MOVWUreg (MOVDconst [c])) + // match: (MOVWreg (MOVDconst [c])) // cond: - // result: (MOVDconst [int64(uint32(c))]) + // result: (MOVDconst [int64(int32(c))]) for { v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { @@ -15196,83 +16780,89 @@ func rewriteValueARM64_OpARM64MOVWUreg_10(v *Value) bool { } c := v_0.AuxInt v.reset(OpARM64MOVDconst) - v.AuxInt = int64(uint32(c)) + v.AuxInt = int64(int32(c)) return true } - // match: (MOVWUreg (SLLconst [sc] x)) - // cond: isARM64BFMask(sc, 1<<32-1, sc) - // result: (UBFIZ [arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc))] x) + // match: (MOVWreg (SLLconst [lc] x)) + // cond: lc < 32 + // result: (SBFIZ [arm64BFAuxInt(lc, 32-lc)] x) for { v_0 := v.Args[0] if v_0.Op != OpARM64SLLconst { break } - sc := v_0.AuxInt - x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<32-1, sc)) { - break - } - v.reset(OpARM64UBFIZ) - v.AuxInt = arm64BFAuxInt(sc, arm64BFWidth(1<<32-1, sc)) - v.AddArg(x) - return true - } - // match: (MOVWUreg (SRLconst [sc] x)) - // cond: isARM64BFMask(sc, 1<<32-1, 0) - // result: (UBFX [arm64BFAuxInt(sc, 32)] x) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64SRLconst { - break - } - sc := v_0.AuxInt + lc := v_0.AuxInt x := v_0.Args[0] - if !(isARM64BFMask(sc, 1<<32-1, 0)) { + if !(lc < 32) { break } - v.reset(OpARM64UBFX) - v.AuxInt = arm64BFAuxInt(sc, 32) + v.reset(OpARM64SBFIZ) + v.AuxInt = arm64BFAuxInt(lc, 32-lc) v.AddArg(x) return true } return false } -func rewriteValueARM64_OpARM64MOVWload_0(v *Value) bool { +func rewriteValueARM64_OpARM64MOVWstore_0(v *Value) bool { b := v.Block _ = b config := b.Func.Config _ = config - // match: (MOVWload [off1] {sym} (ADDconst [off2] ptr) mem) + // match: (MOVWstore [off] {sym} ptr (FMOVSfpgp val) mem) + // cond: + // result: (FMOVSstore [off] {sym} ptr val mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64FMOVSfpgp { + break + } + val := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64FMOVSstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVWstore [off1] {sym} (ADDconst [off2] ptr) val mem) // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWload [off1+off2] {sym} ptr mem) + // result: (MOVWstore [off1+off2] {sym} ptr val mem) for { off1 := v.AuxInt sym := v.Aux - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADDconst { break } off2 := v_0.AuxInt ptr := v_0.Args[0] - mem := v.Args[1] + val := v.Args[1] + mem := v.Args[2] if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVWload) + v.reset(OpARM64MOVWstore) v.AuxInt = off1 + off2 v.Aux = sym v.AddArg(ptr) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWload [off] {sym} (ADD ptr idx) mem) + // match: (MOVWstore [off] {sym} (ADD ptr idx) val mem) // cond: off == 0 && sym == nil - // result: (MOVWloadidx ptr idx mem) + // result: (MOVWstoreidx ptr idx val mem) for { off := v.AuxInt sym := v.Aux - _ = v.Args[1] + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break @@ -15280,23 +16870,392 @@ func rewriteValueARM64_OpARM64MOVWload_0(v *Value) bool { _ = v_0.Args[1] ptr := v_0.Args[0] idx := v_0.Args[1] - mem := v.Args[1] + val := v.Args[1] + mem := v.Args[2] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVWstore [off] {sym} (ADDshiftLL [2] ptr idx) val mem) + // cond: off == 0 && sym == nil + // result: (MOVWstoreidx4 ptr idx val mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { + break + } + if v_0.AuxInt != 2 { + break + } + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + val := v.Args[1] + mem := v.Args[2] if !(off == 0 && sym == nil) { break } - v.reset(OpARM64MOVWloadidx) - v.AddArg(ptr) - v.AddArg(idx) + v.reset(OpARM64MOVWstoreidx4) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVWstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) + // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + for { + off1 := v.AuxInt + sym1 := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDaddr { + break + } + off2 := v_0.AuxInt + sym2 := v_0.Aux + ptr := v_0.Args[0] + val := v.Args[1] + mem := v.Args[2] + if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + break + } + v.reset(OpARM64MOVWstore) + v.AuxInt = off1 + off2 + v.Aux = mergeSym(sym1, sym2) + v.AddArg(ptr) + v.AddArg(val) + v.AddArg(mem) + return true + } + // match: (MOVWstore [off] {sym} ptr (MOVDconst [0]) mem) + // cond: + // result: (MOVWstorezero [off] {sym} ptr mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + if v_1.AuxInt != 0 { + break + } + mem := v.Args[2] + v.reset(OpARM64MOVWstorezero) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVWstore [off] {sym} ptr (MOVWreg x) mem) + // cond: + // result: (MOVWstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVWstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVWstore [off] {sym} ptr (MOVWUreg x) mem) + // cond: + // result: (MOVWstore [off] {sym} ptr x mem) + for { + off := v.AuxInt + sym := v.Aux + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVWUreg { + break + } + x := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVWstore) + v.AuxInt = off + v.Aux = sym + v.AddArg(ptr) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVWstore [i] {s} ptr0 (SRLconst [32] w) x:(MOVWstore [i-4] {s} ptr1 w mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVDstore [i-4] {s} ptr0 w mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + if v_1.AuxInt != 32 { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstore { + break + } + if x.AuxInt != i-4 { + break + } + if x.Aux != s { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + if w != x.Args[1] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstore) + v.AuxInt = i - 4 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w) + v.AddArg(mem) + return true + } + // match: (MOVWstore [4] {s} (ADD ptr0 idx0) (SRLconst [32] w) x:(MOVWstoreidx ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVDstoreidx ptr1 idx1 w mem) + for { + if v.AuxInt != 4 { + break + } + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + if v_1.AuxInt != 32 { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MOVWstore_10(v *Value) bool { + b := v.Block + _ = b + // match: (MOVWstore [4] {s} (ADDshiftLL [2] ptr0 idx0) (SRLconst [32] w) x:(MOVWstoreidx4 ptr1 idx1 w mem)) + // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) + // result: (MOVDstoreidx ptr1 (SLLconst [2] idx1) w mem) + for { + if v.AuxInt != 4 { + break + } + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { + break + } + if v_0.AuxInt != 2 { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + if v_1.AuxInt != 32 { + break + } + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstoreidx4 { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + if w != x.Args[2] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr1) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) + v0.AuxInt = 2 + v0.AddArg(idx1) + v.AddArg(v0) + v.AddArg(w) + v.AddArg(mem) + return true + } + // match: (MOVWstore [i] {s} ptr0 (SRLconst [j] w) x:(MOVWstore [i-4] {s} ptr1 w0:(SRLconst [j-32] w) mem)) + // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVDstore [i-4] {s} ptr0 w0 mem) + for { + i := v.AuxInt + s := v.Aux + _ = v.Args[2] + ptr0 := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstore { + break + } + if x.AuxInt != i-4 { + break + } + if x.Aux != s { + break + } + _ = x.Args[2] + ptr1 := x.Args[0] + w0 := x.Args[1] + if w0.Op != OpARM64SRLconst { + break + } + if w0.AuxInt != j-32 { + break + } + if w != w0.Args[0] { + break + } + mem := x.Args[2] + if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstore) + v.AuxInt = i - 4 + v.Aux = s + v.AddArg(ptr0) + v.AddArg(w0) + v.AddArg(mem) + return true + } + // match: (MOVWstore [4] {s} (ADD ptr0 idx0) (SRLconst [j] w) x:(MOVWstoreidx ptr1 idx1 w0:(SRLconst [j-32] w) mem)) + // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) + // result: (MOVDstoreidx ptr1 idx1 w0 mem) + for { + if v.AuxInt != 4 { + break + } + s := v.Aux + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { + break + } + _ = v_0.Args[1] + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { + break + } + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstoreidx { + break + } + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + w0 := x.Args[2] + if w0.Op != OpARM64SRLconst { + break + } + if w0.AuxInt != j-32 { + break + } + if w != w0.Args[0] { + break + } + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr1) + v.AddArg(idx1) + v.AddArg(w0) v.AddArg(mem) return true } - // match: (MOVWload [off] {sym} (ADDshiftLL [2] ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVWloadidx4 ptr idx mem) + // match: (MOVWstore [4] {s} (ADDshiftLL [2] ptr0 idx0) (SRLconst [j] w) x:(MOVWstoreidx4 ptr1 idx1 w0:(SRLconst [j-32] w) mem)) + // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) + // result: (MOVDstoreidx ptr1 (SLLconst [2] idx1) w0 mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] + if v.AuxInt != 4 { + break + } + s := v.Aux + _ = v.Args[2] v_0 := v.Args[0] if v_0.Op != OpARM64ADDshiftLL { break @@ -15305,110 +17264,93 @@ func rewriteValueARM64_OpARM64MOVWload_0(v *Value) bool { break } _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + ptr0 := v_0.Args[0] + idx0 := v_0.Args[1] + v_1 := v.Args[1] + if v_1.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVWloadidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) - return true - } - // match: (MOVWload [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWload [off1+off2] {mergeSym(sym1,sym2)} ptr mem) - for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + j := v_1.AuxInt + w := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstoreidx4 { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + _ = x.Args[3] + ptr1 := x.Args[0] + idx1 := x.Args[1] + w0 := x.Args[2] + if w0.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVWload) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) - return true - } - // match: (MOVWload [off] {sym} ptr (MOVWstorezero [off2] {sym2} ptr2 _)) - // cond: sym == sym2 && off == off2 && isSamePtr(ptr, ptr2) - // result: (MOVDconst [0]) - for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWstorezero { + if w0.AuxInt != j-32 { break } - off2 := v_1.AuxInt - sym2 := v_1.Aux - _ = v_1.Args[1] - ptr2 := v_1.Args[0] - if !(sym == sym2 && off == off2 && isSamePtr(ptr, ptr2)) { + if w != w0.Args[0] { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 + mem := x.Args[3] + if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + break + } + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr1) + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) + v0.AuxInt = 2 + v0.AddArg(idx1) + v.AddArg(v0) + v.AddArg(w0) + v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVWloadidx_0(v *Value) bool { - // match: (MOVWloadidx ptr (MOVDconst [c]) mem) +func rewriteValueARM64_OpARM64MOVWstoreidx_0(v *Value) bool { + // match: (MOVWstoreidx ptr (MOVDconst [c]) val mem) // cond: - // result: (MOVWload [c] ptr mem) + // result: (MOVWstore [c] ptr val mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVWload) + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVWstore) v.AuxInt = c v.AddArg(ptr) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWloadidx (MOVDconst [c]) ptr mem) + // match: (MOVWstoreidx (MOVDconst [c]) idx val mem) // cond: - // result: (MOVWload [c] ptr mem) + // result: (MOVWstore [c] idx val mem) for { - _ = v.Args[2] + _ = v.Args[3] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVWload) + idx := v.Args[1] + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVWstore) v.AuxInt = c - v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWloadidx ptr (SLLconst [2] idx) mem) + // match: (MOVWstoreidx ptr (SLLconst [2] idx) val mem) // cond: - // result: (MOVWloadidx4 ptr idx mem) + // result: (MOVWstoreidx4 ptr idx val mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64SLLconst { @@ -15418,18 +17360,20 @@ func rewriteValueARM64_OpARM64MOVWloadidx_0(v *Value) bool { break } idx := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVWloadidx4) + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx4) v.AddArg(ptr) v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWloadidx (SLLconst [2] idx) ptr mem) + // match: (MOVWstoreidx (SLLconst [2] idx) ptr val mem) // cond: - // result: (MOVWloadidx4 ptr idx mem) + // result: (MOVWstoreidx4 ptr idx val mem) for { - _ = v.Args[2] + _ = v.Args[3] v_0 := v.Args[0] if v_0.Op != OpARM64SLLconst { break @@ -15439,459 +17383,245 @@ func rewriteValueARM64_OpARM64MOVWloadidx_0(v *Value) bool { } idx := v_0.Args[0] ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVWloadidx4) + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx4) v.AddArg(ptr) v.AddArg(idx) + v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWloadidx ptr idx (MOVWstorezeroidx ptr2 idx2 _)) - // cond: (isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) - // result: (MOVDconst [0]) + // match: (MOVWstoreidx ptr idx (MOVDconst [0]) mem) + // cond: + // result: (MOVWstorezeroidx ptr idx mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] idx := v.Args[1] v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWstorezeroidx { - break - } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) || isSamePtr(ptr, idx2) && isSamePtr(idx, ptr2)) { + if v_2.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVWloadidx4_0(v *Value) bool { - // match: (MOVWloadidx4 ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVWload [c<<2] ptr mem) - for { - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + if v_2.AuxInt != 0 { break } - c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVWload) - v.AuxInt = c << 2 + mem := v.Args[3] + v.reset(OpARM64MOVWstorezeroidx) v.AddArg(ptr) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWloadidx4 ptr idx (MOVWstorezeroidx4 ptr2 idx2 _)) - // cond: isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2) - // result: (MOVDconst [0]) + // match: (MOVWstoreidx ptr idx (MOVWreg x) mem) + // cond: + // result: (MOVWstoreidx ptr idx x mem) for { - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] idx := v.Args[1] v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWstorezeroidx4 { - break - } - _ = v_2.Args[2] - ptr2 := v_2.Args[0] - idx2 := v_2.Args[1] - if !(isSamePtr(ptr, ptr2) && isSamePtr(idx, idx2)) { - break - } - v.reset(OpARM64MOVDconst) - v.AuxInt = 0 - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVWreg_0(v *Value) bool { - // match: (MOVWreg x:(MOVBload _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBload { - break - } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVBUload _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBUload { - break - } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVHload _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHload { - break - } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVHUload _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHUload { - break - } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVWload _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVWload { - break - } - _ = x.Args[1] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVBloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBloadidx { - break - } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVBUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBUloadidx { - break - } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVHloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHloadidx { - break - } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVHUloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHUloadidx { - break - } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVWloadidx _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVWloadidx { - break - } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - return false -} -func rewriteValueARM64_OpARM64MOVWreg_10(v *Value) bool { - // match: (MOVWreg x:(MOVHloadidx2 _ _ _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHloadidx2 { + if v_2.Op != OpARM64MOVWreg { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(x) + v.AddArg(mem) return true } - // match: (MOVWreg x:(MOVHUloadidx2 _ _ _)) + // match: (MOVWstoreidx ptr idx (MOVWUreg x) mem) // cond: - // result: (MOVDreg x) + // result: (MOVWstoreidx ptr idx x mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVHUloadidx2 { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWUreg { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(x) + v.AddArg(mem) return true } - // match: (MOVWreg x:(MOVWloadidx4 _ _ _)) - // cond: - // result: (MOVDreg x) + // match: (MOVWstoreidx ptr (ADDconst [4] idx) (SRLconst [32] w) x:(MOVWstoreidx ptr idx w mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVDstoreidx ptr idx w mem) for { - x := v.Args[0] - if x.Op != OpARM64MOVWloadidx4 { + _ = v.Args[3] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64ADDconst { break } - _ = x.Args[2] - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVBreg _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBreg { + if v_1.AuxInt != 4 { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVBUreg _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVBUreg { + idx := v_1.Args[0] + v_2 := v.Args[2] + if v_2.Op != OpARM64SRLconst { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVHreg _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHreg { + if v_2.AuxInt != 32 { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVHreg _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVHreg { + w := v_2.Args[0] + x := v.Args[3] + if x.Op != OpARM64MOVWstoreidx { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg x:(MOVWreg _)) - // cond: - // result: (MOVDreg x) - for { - x := v.Args[0] - if x.Op != OpARM64MOVWreg { + _ = x.Args[3] + if ptr != x.Args[0] { break } - v.reset(OpARM64MOVDreg) - v.AddArg(x) - return true - } - // match: (MOVWreg (MOVDconst [c])) - // cond: - // result: (MOVDconst [int64(int32(c))]) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + if idx != x.Args[1] { break } - c := v_0.AuxInt - v.reset(OpARM64MOVDconst) - v.AuxInt = int64(int32(c)) - return true - } - // match: (MOVWreg (SLLconst [lc] x)) - // cond: lc < 32 - // result: (SBFIZ [arm64BFAuxInt(lc, 32-lc)] x) - for { - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + if w != x.Args[2] { break } - lc := v_0.AuxInt - x := v_0.Args[0] - if !(lc < 32) { + mem := x.Args[3] + if !(x.Uses == 1 && clobber(x)) { break } - v.reset(OpARM64SBFIZ) - v.AuxInt = arm64BFAuxInt(lc, 32-lc) - v.AddArg(x) + v.reset(OpARM64MOVDstoreidx) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(w) + v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVWstore_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVWstore [off] {sym} ptr (FMOVSfpgp val) mem) +func rewriteValueARM64_OpARM64MOVWstoreidx4_0(v *Value) bool { + // match: (MOVWstoreidx4 ptr (MOVDconst [c]) val mem) // cond: - // result: (FMOVSstore [off] {sym} ptr val mem) + // result: (MOVWstore [c<<2] ptr val mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] + _ = v.Args[3] ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64FMOVSfpgp { - break - } - val := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64FMOVSstore) - v.AuxInt = off - v.Aux = sym + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + val := v.Args[2] + mem := v.Args[3] + v.reset(OpARM64MOVWstore) + v.AuxInt = c << 2 v.AddArg(ptr) v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWstore [off1] {sym} (ADDconst [off2] ptr) val mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWstore [off1+off2] {sym} ptr val mem) + // match: (MOVWstoreidx4 ptr idx (MOVDconst [0]) mem) + // cond: + // result: (MOVWstorezeroidx4 ptr idx mem) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + if v_2.AuxInt != 0 { break } - v.reset(OpARM64MOVWstore) - v.AuxInt = off1 + off2 - v.Aux = sym + mem := v.Args[3] + v.reset(OpARM64MOVWstorezeroidx4) v.AddArg(ptr) - v.AddArg(val) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWstore [off] {sym} (ADD ptr idx) val mem) - // cond: off == 0 && sym == nil - // result: (MOVWstoreidx ptr idx val mem) + // match: (MOVWstoreidx4 ptr idx (MOVWreg x) mem) + // cond: + // result: (MOVWstoreidx4 ptr idx x mem) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWreg { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - val := v.Args[1] - mem := v.Args[2] - if !(off == 0 && sym == nil) { + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx4) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(x) + v.AddArg(mem) + return true + } + // match: (MOVWstoreidx4 ptr idx (MOVWUreg x) mem) + // cond: + // result: (MOVWstoreidx4 ptr idx x mem) + for { + _ = v.Args[3] + ptr := v.Args[0] + idx := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVWUreg { break } - v.reset(OpARM64MOVWstoreidx) + x := v_2.Args[0] + mem := v.Args[3] + v.reset(OpARM64MOVWstoreidx4) v.AddArg(ptr) v.AddArg(idx) - v.AddArg(val) + v.AddArg(x) v.AddArg(mem) return true } - // match: (MOVWstore [off] {sym} (ADDshiftLL [2] ptr idx) val mem) - // cond: off == 0 && sym == nil - // result: (MOVWstoreidx4 ptr idx val mem) + return false +} +func rewriteValueARM64_OpARM64MOVWstorezero_0(v *Value) bool { + b := v.Block + _ = b + config := b.Func.Config + _ = config + // match: (MOVWstorezero [off1] {sym} (ADDconst [off2] ptr) mem) + // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) + // result: (MOVWstorezero [off1+off2] {sym} ptr mem) for { - off := v.AuxInt + off1 := v.AuxInt sym := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { - break - } - if v_0.AuxInt != 2 { + if v_0.Op != OpARM64ADDconst { break } - _ = v_0.Args[1] + off2 := v_0.AuxInt ptr := v_0.Args[0] - idx := v_0.Args[1] - val := v.Args[1] - mem := v.Args[2] - if !(off == 0 && sym == nil) { + mem := v.Args[1] + if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVWstoreidx4) + v.reset(OpARM64MOVWstorezero) + v.AuxInt = off1 + off2 + v.Aux = sym v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWstore [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) val mem) + // match: (MOVWstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWstore [off1+off2] {mergeSym(sym1,sym2)} ptr val mem) + // result: (MOVWstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) for { off1 := v.AuxInt sym1 := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64MOVDaddr { break @@ -15899,138 +17629,106 @@ func rewriteValueARM64_OpARM64MOVWstore_0(v *Value) bool { off2 := v_0.AuxInt sym2 := v_0.Aux ptr := v_0.Args[0] - val := v.Args[1] - mem := v.Args[2] + mem := v.Args[1] if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { break } - v.reset(OpARM64MOVWstore) + v.reset(OpARM64MOVWstorezero) v.AuxInt = off1 + off2 v.Aux = mergeSym(sym1, sym2) v.AddArg(ptr) - v.AddArg(val) v.AddArg(mem) return true } - // match: (MOVWstore [off] {sym} ptr (MOVDconst [0]) mem) - // cond: - // result: (MOVWstorezero [off] {sym} ptr mem) + // match: (MOVWstorezero [off] {sym} (ADD ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVWstorezeroidx ptr idx mem) for { off := v.AuxInt sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADD { break } - if v_1.AuxInt != 0 { + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { break } - mem := v.Args[2] - v.reset(OpARM64MOVWstorezero) - v.AuxInt = off - v.Aux = sym + v.reset(OpARM64MOVWstorezeroidx) v.AddArg(ptr) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWstore [off] {sym} ptr (MOVWreg x) mem) - // cond: - // result: (MOVWstore [off] {sym} ptr x mem) + // match: (MOVWstorezero [off] {sym} (ADDshiftLL [2] ptr idx) mem) + // cond: off == 0 && sym == nil + // result: (MOVWstorezeroidx4 ptr idx mem) for { off := v.AuxInt sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWreg { + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64ADDshiftLL { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVWstore) - v.AuxInt = off - v.Aux = sym - v.AddArg(ptr) - v.AddArg(x) - v.AddArg(mem) - return true - } - // match: (MOVWstore [off] {sym} ptr (MOVWUreg x) mem) - // cond: - // result: (MOVWstore [off] {sym} ptr x mem) - for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[2] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVWUreg { + if v_0.AuxInt != 2 { break } - x := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVWstore) - v.AuxInt = off - v.Aux = sym + _ = v_0.Args[1] + ptr := v_0.Args[0] + idx := v_0.Args[1] + mem := v.Args[1] + if !(off == 0 && sym == nil) { + break + } + v.reset(OpARM64MOVWstorezeroidx4) v.AddArg(ptr) - v.AddArg(x) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWstore [i] {s} ptr0 (SRLconst [32] w) x:(MOVWstore [i-4] {s} ptr1 w mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVDstore [i-4] {s} ptr0 w mem) + // match: (MOVWstorezero [i] {s} ptr0 x:(MOVWstorezero [j] {s} ptr1 mem)) + // cond: x.Uses == 1 && areAdjacentOffsets(i,j,4) && is32Bit(min(i,j)) && isSamePtr(ptr0, ptr1) && clobber(x) + // result: (MOVDstorezero [min(i,j)] {s} ptr0 mem) for { i := v.AuxInt s := v.Aux - _ = v.Args[2] + _ = v.Args[1] ptr0 := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - if v_1.AuxInt != 32 { - break - } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstore { - break - } - if x.AuxInt != i-4 { + x := v.Args[1] + if x.Op != OpARM64MOVWstorezero { break } + j := x.AuxInt if x.Aux != s { break } - _ = x.Args[2] + _ = x.Args[1] ptr1 := x.Args[0] - if w != x.Args[1] { - break - } - mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + mem := x.Args[1] + if !(x.Uses == 1 && areAdjacentOffsets(i, j, 4) && is32Bit(min(i, j)) && isSamePtr(ptr0, ptr1) && clobber(x)) { break } - v.reset(OpARM64MOVDstore) - v.AuxInt = i - 4 + v.reset(OpARM64MOVDstorezero) + v.AuxInt = min(i, j) v.Aux = s v.AddArg(ptr0) - v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVWstore [4] {s} (ADD ptr0 idx0) (SRLconst [32] w) x:(MOVWstoreidx ptr1 idx1 w mem)) + // match: (MOVWstorezero [4] {s} (ADD ptr0 idx0) x:(MOVWstorezeroidx ptr1 idx1 mem)) // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVDstoreidx ptr1 idx1 w mem) + // result: (MOVDstorezeroidx ptr1 idx1 mem) for { if v.AuxInt != 4 { break } s := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64ADD { break @@ -16038,49 +17736,32 @@ func rewriteValueARM64_OpARM64MOVWstore_0(v *Value) bool { _ = v_0.Args[1] ptr0 := v_0.Args[0] idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - if v_1.AuxInt != 32 { - break - } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstoreidx { + x := v.Args[1] + if x.Op != OpARM64MOVWstorezeroidx { break } - _ = x.Args[3] + _ = x.Args[2] ptr1 := x.Args[0] idx1 := x.Args[1] - if w != x.Args[2] { - break - } - mem := x.Args[3] + mem := x.Args[2] if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { break } - v.reset(OpARM64MOVDstoreidx) + v.reset(OpARM64MOVDstorezeroidx) v.AddArg(ptr1) v.AddArg(idx1) - v.AddArg(w) v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVWstore_10(v *Value) bool { - b := v.Block - _ = b - // match: (MOVWstore [4] {s} (ADDshiftLL [2] ptr0 idx0) (SRLconst [32] w) x:(MOVWstoreidx4 ptr1 idx1 w mem)) + // match: (MOVWstorezero [4] {s} (ADDshiftLL [2] ptr0 idx0) x:(MOVWstorezeroidx4 ptr1 idx1 mem)) // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVDstoreidx ptr1 (SLLconst [2] idx1) w mem) + // result: (MOVDstorezeroidx ptr1 (SLLconst [2] idx1) mem) for { if v.AuxInt != 4 { break } s := v.Aux - _ = v.Args[2] + _ = v.Args[1] v_0 := v.Args[0] if v_0.Op != OpARM64ADDshiftLL { break @@ -16091,816 +17772,1179 @@ func rewriteValueARM64_OpARM64MOVWstore_10(v *Value) bool { _ = v_0.Args[1] ptr0 := v_0.Args[0] idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { - break - } - if v_1.AuxInt != 32 { - break - } - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstoreidx4 { + x := v.Args[1] + if x.Op != OpARM64MOVWstorezeroidx4 { break } - _ = x.Args[3] + _ = x.Args[2] ptr1 := x.Args[0] idx1 := x.Args[1] - if w != x.Args[2] { - break - } - mem := x.Args[3] + mem := x.Args[2] if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { break } - v.reset(OpARM64MOVDstoreidx) + v.reset(OpARM64MOVDstorezeroidx) v.AddArg(ptr1) v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) v0.AuxInt = 2 v0.AddArg(idx1) v.AddArg(v0) - v.AddArg(w) v.AddArg(mem) return true } - // match: (MOVWstore [i] {s} ptr0 (SRLconst [j] w) x:(MOVWstore [i-4] {s} ptr1 w0:(SRLconst [j-32] w) mem)) - // cond: x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVDstore [i-4] {s} ptr0 w0 mem) + return false +} +func rewriteValueARM64_OpARM64MOVWstorezeroidx_0(v *Value) bool { + // match: (MOVWstorezeroidx ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVWstorezero [c] ptr mem) for { - i := v.AuxInt - s := v.Aux _ = v.Args[2] - ptr0 := v.Args[0] + ptr := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + if v_1.Op != OpARM64MOVDconst { break } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstore { + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVWstorezero) + v.AuxInt = c + v.AddArg(ptr) + v.AddArg(mem) + return true + } + // match: (MOVWstorezeroidx (MOVDconst [c]) idx mem) + // cond: + // result: (MOVWstorezero [c] idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if x.AuxInt != i-4 { + c := v_0.AuxInt + idx := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVWstorezero) + v.AuxInt = c + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVWstorezeroidx ptr (SLLconst [2] idx) mem) + // cond: + // result: (MOVWstorezeroidx4 ptr idx mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64SLLconst { break } - if x.Aux != s { + if v_1.AuxInt != 2 { break } - _ = x.Args[2] - ptr1 := x.Args[0] - w0 := x.Args[1] - if w0.Op != OpARM64SRLconst { + idx := v_1.Args[0] + mem := v.Args[2] + v.reset(OpARM64MOVWstorezeroidx4) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVWstorezeroidx (SLLconst [2] idx) ptr mem) + // cond: + // result: (MOVWstorezeroidx4 ptr idx mem) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64SLLconst { break } - if w0.AuxInt != j-32 { + if v_0.AuxInt != 2 { break } - if w != w0.Args[0] { + idx := v_0.Args[0] + ptr := v.Args[1] + mem := v.Args[2] + v.reset(OpARM64MOVWstorezeroidx4) + v.AddArg(ptr) + v.AddArg(idx) + v.AddArg(mem) + return true + } + // match: (MOVWstorezeroidx ptr (ADDconst [4] idx) x:(MOVWstorezeroidx ptr idx mem)) + // cond: x.Uses == 1 && clobber(x) + // result: (MOVDstorezeroidx ptr idx mem) + for { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64ADDconst { + break + } + if v_1.AuxInt != 4 { + break + } + idx := v_1.Args[0] + x := v.Args[2] + if x.Op != OpARM64MOVWstorezeroidx { + break + } + _ = x.Args[2] + if ptr != x.Args[0] { + break + } + if idx != x.Args[1] { break } mem := x.Args[2] - if !(x.Uses == 1 && isSamePtr(ptr0, ptr1) && clobber(x)) { + if !(x.Uses == 1 && clobber(x)) { break } - v.reset(OpARM64MOVDstore) - v.AuxInt = i - 4 - v.Aux = s - v.AddArg(ptr0) - v.AddArg(w0) + v.reset(OpARM64MOVDstorezeroidx) + v.AddArg(ptr) + v.AddArg(idx) v.AddArg(mem) return true } - // match: (MOVWstore [4] {s} (ADD ptr0 idx0) (SRLconst [j] w) x:(MOVWstoreidx ptr1 idx1 w0:(SRLconst [j-32] w) mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVDstoreidx ptr1 idx1 w0 mem) + return false +} +func rewriteValueARM64_OpARM64MOVWstorezeroidx4_0(v *Value) bool { + // match: (MOVWstorezeroidx4 ptr (MOVDconst [c]) mem) + // cond: + // result: (MOVWstorezero [c<<2] ptr mem) for { - if v.AuxInt != 4 { + _ = v.Args[2] + ptr := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - s := v.Aux + c := v_1.AuxInt + mem := v.Args[2] + v.reset(OpARM64MOVWstorezero) + v.AuxInt = c << 2 + v.AddArg(ptr) + v.AddArg(mem) + return true + } + return false +} +func rewriteValueARM64_OpARM64MSUB_0(v *Value) bool { + b := v.Block + _ = b + // match: (MSUB a x (MOVDconst [-1])) + // cond: + // result: (ADD a x) + for { _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + if v_2.AuxInt != -1 { break } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstoreidx { + v.reset(OpARM64ADD) + v.AddArg(a) + v.AddArg(x) + return true + } + // match: (MSUB a _ (MOVDconst [0])) + // cond: + // result: a + for { + _ = v.Args[2] + a := v.Args[0] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - w0 := x.Args[2] - if w0.Op != OpARM64SRLconst { + if v_2.AuxInt != 0 { break } - if w0.AuxInt != j-32 { + v.reset(OpCopy) + v.Type = a.Type + v.AddArg(a) + return true + } + // match: (MSUB a x (MOVDconst [1])) + // cond: + // result: (SUB a x) + for { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { + break + } + if v_2.AuxInt != 1 { + break + } + v.reset(OpARM64SUB) + v.AddArg(a) + v.AddArg(x) + return true + } + // match: (MSUB a x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (SUBshiftLL a x [log2(c)]) + for { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { + break + } + c := v_2.AuxInt + if !(isPowerOfTwo(c)) { break } - if w != w0.Args[0] { + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c) + v.AddArg(a) + v.AddArg(x) + return true + } + // match: (MSUB a x (MOVDconst [c])) + // cond: isPowerOfTwo(c-1) && c>=3 + // result: (SUB a (ADDshiftLL x x [log2(c-1)])) + for { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + c := v_2.AuxInt + if !(isPowerOfTwo(c-1) && c >= 3) { break } - v.reset(OpARM64MOVDstoreidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(w0) - v.AddArg(mem) + v.reset(OpARM64SUB) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstore [4] {s} (ADDshiftLL [2] ptr0 idx0) (SRLconst [j] w) x:(MOVWstoreidx4 ptr1 idx1 w0:(SRLconst [j-32] w) mem)) - // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVDstoreidx ptr1 (SLLconst [2] idx1) w0 mem) + // match: (MSUB a x (MOVDconst [c])) + // cond: isPowerOfTwo(c+1) && c>=7 + // result: (ADD a (SUBshiftLL x x [log2(c+1)])) for { - if v.AuxInt != 4 { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - s := v.Aux + c := v_2.AuxInt + if !(isPowerOfTwo(c+1) && c >= 7) { + break + } + v.reset(OpARM64ADD) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MSUB a x (MOVDconst [c])) + // cond: c%3 == 0 && isPowerOfTwo(c/3) + // result: (ADDshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) + for { _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != 2 { + c := v_2.AuxInt + if !(c%3 == 0 && isPowerOfTwo(c/3)) { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - v_1 := v.Args[1] - if v_1.Op != OpARM64SRLconst { + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 3) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MSUB a x (MOVDconst [c])) + // cond: c%5 == 0 && isPowerOfTwo(c/5) + // result: (SUBshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) + for { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - j := v_1.AuxInt - w := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstoreidx4 { + c := v_2.AuxInt + if !(c%5 == 0 && isPowerOfTwo(c/5)) { break } - _ = x.Args[3] - ptr1 := x.Args[0] - idx1 := x.Args[1] - w0 := x.Args[2] - if w0.Op != OpARM64SRLconst { + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 5) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MSUB a x (MOVDconst [c])) + // cond: c%7 == 0 && isPowerOfTwo(c/7) + // result: (ADDshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) + for { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - if w0.AuxInt != j-32 { + c := v_2.AuxInt + if !(c%7 == 0 && isPowerOfTwo(c/7)) { break } - if w != w0.Args[0] { + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 7) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MSUB a x (MOVDconst [c])) + // cond: c%9 == 0 && isPowerOfTwo(c/9) + // result: (SUBshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + for { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + c := v_2.AuxInt + if !(c%9 == 0 && isPowerOfTwo(c/9)) { break } - v.reset(OpARM64MOVDstoreidx) - v.AddArg(ptr1) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) - v0.AuxInt = 2 - v0.AddArg(idx1) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 9) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) v.AddArg(v0) - v.AddArg(w0) - v.AddArg(mem) return true } return false } -func rewriteValueARM64_OpARM64MOVWstoreidx_0(v *Value) bool { - // match: (MOVWstoreidx ptr (MOVDconst [c]) val mem) +func rewriteValueARM64_OpARM64MSUB_10(v *Value) bool { + b := v.Block + _ = b + // match: (MSUB a (MOVDconst [-1]) x) // cond: - // result: (MOVWstore [c] ptr val mem) + // result: (ADD a x) for { - _ = v.Args[3] - ptr := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVWstore) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + if v_1.AuxInt != -1 { + break + } + x := v.Args[2] + v.reset(OpARM64ADD) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MOVWstoreidx (MOVDconst [c]) idx val mem) + // match: (MSUB a (MOVDconst [0]) _) // cond: - // result: (MOVWstore [c] idx val mem) + // result: a for { - _ = v.Args[3] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - idx := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVWstore) - v.AuxInt = c - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + if v_1.AuxInt != 0 { + break + } + v.reset(OpCopy) + v.Type = a.Type + v.AddArg(a) return true } - // match: (MOVWstoreidx ptr (SLLconst [2] idx) val mem) + // match: (MSUB a (MOVDconst [1]) x) // cond: - // result: (MOVWstoreidx4 ptr idx val mem) + // result: (SUB a x) for { - _ = v.Args[3] - ptr := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SLLconst { + if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 2 { + if v_1.AuxInt != 1 { break } - idx := v_1.Args[0] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + x := v.Args[2] + v.reset(OpARM64SUB) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MOVWstoreidx (SLLconst [2] idx) ptr val mem) - // cond: - // result: (MOVWstoreidx4 ptr idx val mem) + // match: (MSUB a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c) + // result: (SUBshiftLL a x [log2(c)]) for { - _ = v.Args[3] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != 2 { + c := v_1.AuxInt + x := v.Args[2] + if !(isPowerOfTwo(c)) { break } - idx := v_0.Args[0] - ptr := v.Args[1] - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(val) - v.AddArg(mem) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MOVWstoreidx ptr idx (MOVDconst [0]) mem) - // cond: - // result: (MOVWstorezeroidx ptr idx mem) + // match: (MSUB a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c-1) && c>=3 + // result: (SUB a (ADDshiftLL x x [log2(c-1)])) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if v_2.AuxInt != 0 { + c := v_1.AuxInt + x := v.Args[2] + if !(isPowerOfTwo(c-1) && c >= 3) { break } - mem := v.Args[3] - v.reset(OpARM64MOVWstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64SUB) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstoreidx ptr idx (MOVWreg x) mem) - // cond: - // result: (MOVWstoreidx ptr idx x mem) + // match: (MSUB a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c+1) && c>=7 + // result: (ADD a (SUBshiftLL x x [log2(c+1)])) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWreg { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(x) - v.AddArg(mem) + c := v_1.AuxInt + x := v.Args[2] + if !(isPowerOfTwo(c+1) && c >= 7) { + break + } + v.reset(OpARM64ADD) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstoreidx ptr idx (MOVWUreg x) mem) - // cond: - // result: (MOVWstoreidx ptr idx x mem) + // match: (MSUB a (MOVDconst [c]) x) + // cond: c%3 == 0 && isPowerOfTwo(c/3) + // result: (ADDshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] - v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWUreg { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(x) - v.AddArg(mem) + c := v_1.AuxInt + x := v.Args[2] + if !(c%3 == 0 && isPowerOfTwo(c/3)) { + break + } + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 3) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstoreidx ptr (ADDconst [4] idx) (SRLconst [32] w) x:(MOVWstoreidx ptr idx w mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVDstoreidx ptr idx w mem) + // match: (MSUB a (MOVDconst [c]) x) + // cond: c%5 == 0 && isPowerOfTwo(c/5) + // result: (SUBshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) for { - _ = v.Args[3] - ptr := v.Args[0] + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { + if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 4 { + c := v_1.AuxInt + x := v.Args[2] + if !(c%5 == 0 && isPowerOfTwo(c/5)) { break } - idx := v_1.Args[0] - v_2 := v.Args[2] - if v_2.Op != OpARM64SRLconst { + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 5) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MSUB a (MOVDconst [c]) x) + // cond: c%7 == 0 && isPowerOfTwo(c/7) + // result: (ADDshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) + for { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if v_2.AuxInt != 32 { + c := v_1.AuxInt + x := v.Args[2] + if !(c%7 == 0 && isPowerOfTwo(c/7)) { break } - w := v_2.Args[0] - x := v.Args[3] - if x.Op != OpARM64MOVWstoreidx { + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 7) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MSUB a (MOVDconst [c]) x) + // cond: c%9 == 0 && isPowerOfTwo(c/9) + // result: (SUBshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + for { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[3] - if ptr != x.Args[0] { + c := v_1.AuxInt + x := v.Args[2] + if !(c%9 == 0 && isPowerOfTwo(c/9)) { break } - if idx != x.Args[1] { + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 9) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + return false +} +func rewriteValueARM64_OpARM64MSUB_20(v *Value) bool { + b := v.Block + _ = b + // match: (MSUB (MOVDconst [c]) x y) + // cond: + // result: (ADDconst [c] (MNEG x y)) + for { + _ = v.Args[2] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } - if w != x.Args[2] { + c := v_0.AuxInt + x := v.Args[1] + y := v.Args[2] + v.reset(OpARM64ADDconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64MNEG, x.Type) + v0.AddArg(x) + v0.AddArg(y) + v.AddArg(v0) + return true + } + // match: (MSUB a (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (SUBconst [c*d] a) + for { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - mem := x.Args[3] - if !(x.Uses == 1 && clobber(x)) { + c := v_1.AuxInt + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - v.reset(OpARM64MOVDstoreidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(w) - v.AddArg(mem) + d := v_2.AuxInt + v.reset(OpARM64SUBconst) + v.AuxInt = c * d + v.AddArg(a) return true } return false } -func rewriteValueARM64_OpARM64MOVWstoreidx4_0(v *Value) bool { - // match: (MOVWstoreidx4 ptr (MOVDconst [c]) val mem) - // cond: - // result: (MOVWstore [c<<2] ptr val mem) +func rewriteValueARM64_OpARM64MSUBW_0(v *Value) bool { + b := v.Block + _ = b + // match: (MSUBW a x (MOVDconst [c])) + // cond: int32(c)==-1 + // result: (ADD a x) for { - _ = v.Args[3] - ptr := v.Args[0] - v_1 := v.Args[1] - if v_1.Op != OpARM64MOVDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - c := v_1.AuxInt - val := v.Args[2] - mem := v.Args[3] - v.reset(OpARM64MOVWstore) - v.AuxInt = c << 2 - v.AddArg(ptr) - v.AddArg(val) - v.AddArg(mem) + c := v_2.AuxInt + if !(int32(c) == -1) { + break + } + v.reset(OpARM64ADD) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MOVWstoreidx4 ptr idx (MOVDconst [0]) mem) - // cond: - // result: (MOVWstorezeroidx4 ptr idx mem) + // match: (MSUBW a _ (MOVDconst [c])) + // cond: int32(c)==0 + // result: a for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] + _ = v.Args[2] + a := v.Args[0] v_2 := v.Args[2] if v_2.Op != OpARM64MOVDconst { break } - if v_2.AuxInt != 0 { + c := v_2.AuxInt + if !(int32(c) == 0) { break } - mem := v.Args[3] - v.reset(OpARM64MOVWstorezeroidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpCopy) + v.Type = a.Type + v.AddArg(a) return true } - // match: (MOVWstoreidx4 ptr idx (MOVWreg x) mem) - // cond: - // result: (MOVWstoreidx4 ptr idx x mem) + // match: (MSUBW a x (MOVDconst [c])) + // cond: int32(c)==1 + // result: (SUB a x) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWreg { + if v_2.Op != OpARM64MOVDconst { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx4) - v.AddArg(ptr) - v.AddArg(idx) + c := v_2.AuxInt + if !(int32(c) == 1) { + break + } + v.reset(OpARM64SUB) + v.AddArg(a) v.AddArg(x) - v.AddArg(mem) return true } - // match: (MOVWstoreidx4 ptr idx (MOVWUreg x) mem) - // cond: - // result: (MOVWstoreidx4 ptr idx x mem) + // match: (MSUBW a x (MOVDconst [c])) + // cond: isPowerOfTwo(c) + // result: (SUBshiftLL a x [log2(c)]) for { - _ = v.Args[3] - ptr := v.Args[0] - idx := v.Args[1] + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] v_2 := v.Args[2] - if v_2.Op != OpARM64MOVWUreg { + if v_2.Op != OpARM64MOVDconst { break } - x := v_2.Args[0] - mem := v.Args[3] - v.reset(OpARM64MOVWstoreidx4) - v.AddArg(ptr) - v.AddArg(idx) + c := v_2.AuxInt + if !(isPowerOfTwo(c)) { + break + } + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c) + v.AddArg(a) v.AddArg(x) - v.AddArg(mem) return true } - return false -} -func rewriteValueARM64_OpARM64MOVWstorezero_0(v *Value) bool { - b := v.Block - _ = b - config := b.Func.Config - _ = config - // match: (MOVWstorezero [off1] {sym} (ADDconst [off2] ptr) mem) - // cond: is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWstorezero [off1+off2] {sym} ptr mem) + // match: (MSUBW a x (MOVDconst [c])) + // cond: isPowerOfTwo(c-1) && int32(c)>=3 + // result: (SUB a (ADDshiftLL x x [log2(c-1)])) for { - off1 := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDconst { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - ptr := v_0.Args[0] - mem := v.Args[1] - if !(is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_2.AuxInt + if !(isPowerOfTwo(c-1) && int32(c) >= 3) { break } - v.reset(OpARM64MOVWstorezero) - v.AuxInt = off1 + off2 - v.Aux = sym - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64SUB) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstorezero [off1] {sym1} (MOVDaddr [off2] {sym2} ptr) mem) - // cond: canMergeSym(sym1,sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared) - // result: (MOVWstorezero [off1+off2] {mergeSym(sym1,sym2)} ptr mem) + // match: (MSUBW a x (MOVDconst [c])) + // cond: isPowerOfTwo(c+1) && int32(c)>=7 + // result: (ADD a (SUBshiftLL x x [log2(c+1)])) for { - off1 := v.AuxInt - sym1 := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDaddr { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - off2 := v_0.AuxInt - sym2 := v_0.Aux - ptr := v_0.Args[0] - mem := v.Args[1] - if !(canMergeSym(sym1, sym2) && is32Bit(off1+off2) && (ptr.Op != OpSB || !config.ctxt.Flag_shared)) { + c := v_2.AuxInt + if !(isPowerOfTwo(c+1) && int32(c) >= 7) { break } - v.reset(OpARM64MOVWstorezero) - v.AuxInt = off1 + off2 - v.Aux = mergeSym(sym1, sym2) - v.AddArg(ptr) - v.AddArg(mem) + v.reset(OpARM64ADD) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstorezero [off] {sym} (ADD ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVWstorezeroidx ptr idx mem) + // match: (MSUBW a x (MOVDconst [c])) + // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) + // result: (ADDshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + c := v_2.AuxInt + if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { break } - v.reset(OpARM64MOVWstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 3) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstorezero [off] {sym} (ADDshiftLL [2] ptr idx) mem) - // cond: off == 0 && sym == nil - // result: (MOVWstorezeroidx4 ptr idx mem) + // match: (MSUBW a x (MOVDconst [c])) + // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) + // result: (SUBshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) for { - off := v.AuxInt - sym := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { - break - } - if v_0.AuxInt != 2 { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - _ = v_0.Args[1] - ptr := v_0.Args[0] - idx := v_0.Args[1] - mem := v.Args[1] - if !(off == 0 && sym == nil) { + c := v_2.AuxInt + if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { break } - v.reset(OpARM64MOVWstorezeroidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 5) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstorezero [i] {s} ptr0 x:(MOVWstorezero [j] {s} ptr1 mem)) - // cond: x.Uses == 1 && areAdjacentOffsets(i,j,4) && is32Bit(min(i,j)) && isSamePtr(ptr0, ptr1) && clobber(x) - // result: (MOVDstorezero [min(i,j)] {s} ptr0 mem) + // match: (MSUBW a x (MOVDconst [c])) + // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) + // result: (ADDshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) for { - i := v.AuxInt - s := v.Aux - _ = v.Args[1] - ptr0 := v.Args[0] + _ = v.Args[2] + a := v.Args[0] x := v.Args[1] - if x.Op != OpARM64MOVWstorezero { - break - } - j := x.AuxInt - if x.Aux != s { + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - _ = x.Args[1] - ptr1 := x.Args[0] - mem := x.Args[1] - if !(x.Uses == 1 && areAdjacentOffsets(i, j, 4) && is32Bit(min(i, j)) && isSamePtr(ptr0, ptr1) && clobber(x)) { + c := v_2.AuxInt + if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { break } - v.reset(OpARM64MOVDstorezero) - v.AuxInt = min(i, j) - v.Aux = s - v.AddArg(ptr0) - v.AddArg(mem) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 7) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstorezero [4] {s} (ADD ptr0 idx0) x:(MOVWstorezeroidx ptr1 idx1 mem)) - // cond: x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x) - // result: (MOVDstorezeroidx ptr1 idx1 mem) + // match: (MSUBW a x (MOVDconst [c])) + // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) + // result: (SUBshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) for { - if v.AuxInt != 4 { + _ = v.Args[2] + a := v.Args[0] + x := v.Args[1] + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { break } - s := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADD { + c := v_2.AuxInt + if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - x := v.Args[1] - if x.Op != OpARM64MOVWstorezeroidx { + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 9) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + return false +} +func rewriteValueARM64_OpARM64MSUBW_10(v *Value) bool { + b := v.Block + _ = b + // match: (MSUBW a (MOVDconst [c]) x) + // cond: int32(c)==-1 + // result: (ADD a x) + for { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - ptr1 := x.Args[0] - idx1 := x.Args[1] - mem := x.Args[2] - if !(x.Uses == 1 && s == nil && (isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) || isSamePtr(ptr0, idx1) && isSamePtr(idx0, ptr1)) && clobber(x)) { + c := v_1.AuxInt + x := v.Args[2] + if !(int32(c) == -1) { break } - v.reset(OpARM64MOVDstorezeroidx) - v.AddArg(ptr1) - v.AddArg(idx1) - v.AddArg(mem) + v.reset(OpARM64ADD) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MOVWstorezero [4] {s} (ADDshiftLL [2] ptr0 idx0) x:(MOVWstorezeroidx4 ptr1 idx1 mem)) - // cond: x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x) - // result: (MOVDstorezeroidx ptr1 (SLLconst [2] idx1) mem) + // match: (MSUBW a (MOVDconst [c]) _) + // cond: int32(c)==0 + // result: a for { - if v.AuxInt != 4 { - break - } - s := v.Aux - _ = v.Args[1] - v_0 := v.Args[0] - if v_0.Op != OpARM64ADDshiftLL { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != 2 { + c := v_1.AuxInt + if !(int32(c) == 0) { break } - _ = v_0.Args[1] - ptr0 := v_0.Args[0] - idx0 := v_0.Args[1] - x := v.Args[1] - if x.Op != OpARM64MOVWstorezeroidx4 { + v.reset(OpCopy) + v.Type = a.Type + v.AddArg(a) + return true + } + // match: (MSUBW a (MOVDconst [c]) x) + // cond: int32(c)==1 + // result: (SUB a x) + for { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - ptr1 := x.Args[0] - idx1 := x.Args[1] - mem := x.Args[2] - if !(x.Uses == 1 && s == nil && isSamePtr(ptr0, ptr1) && isSamePtr(idx0, idx1) && clobber(x)) { + c := v_1.AuxInt + x := v.Args[2] + if !(int32(c) == 1) { break } - v.reset(OpARM64MOVDstorezeroidx) - v.AddArg(ptr1) - v0 := b.NewValue0(v.Pos, OpARM64SLLconst, idx1.Type) - v0.AuxInt = 2 - v0.AddArg(idx1) - v.AddArg(v0) - v.AddArg(mem) + v.reset(OpARM64SUB) + v.AddArg(a) + v.AddArg(x) return true } - return false -} -func rewriteValueARM64_OpARM64MOVWstorezeroidx_0(v *Value) bool { - // match: (MOVWstorezeroidx ptr (MOVDconst [c]) mem) - // cond: - // result: (MOVWstorezero [c] ptr mem) + // match: (MSUBW a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c) + // result: (SUBshiftLL a x [log2(c)]) for { _ = v.Args[2] - ptr := v.Args[0] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVWstorezero) - v.AuxInt = c - v.AddArg(ptr) - v.AddArg(mem) + x := v.Args[2] + if !(isPowerOfTwo(c)) { + break + } + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c) + v.AddArg(a) + v.AddArg(x) return true } - // match: (MOVWstorezeroidx (MOVDconst [c]) idx mem) - // cond: - // result: (MOVWstorezero [c] idx mem) + // match: (MSUBW a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c-1) && int32(c)>=3 + // result: (SUB a (ADDshiftLL x x [log2(c-1)])) for { _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - c := v_0.AuxInt - idx := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVWstorezero) - v.AuxInt = c - v.AddArg(idx) - v.AddArg(mem) + c := v_1.AuxInt + x := v.Args[2] + if !(isPowerOfTwo(c-1) && int32(c) >= 3) { + break + } + v.reset(OpARM64SUB) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = log2(c - 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstorezeroidx ptr (SLLconst [2] idx) mem) - // cond: - // result: (MOVWstorezeroidx4 ptr idx mem) + // match: (MSUBW a (MOVDconst [c]) x) + // cond: isPowerOfTwo(c+1) && int32(c)>=7 + // result: (ADD a (SUBshiftLL x x [log2(c+1)])) for { _ = v.Args[2] - ptr := v.Args[0] + a := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64SLLconst { + if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 2 { + c := v_1.AuxInt + x := v.Args[2] + if !(isPowerOfTwo(c+1) && int32(c) >= 7) { break } - idx := v_1.Args[0] - mem := v.Args[2] - v.reset(OpARM64MOVWstorezeroidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64ADD) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = log2(c + 1) + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstorezeroidx (SLLconst [2] idx) ptr mem) - // cond: - // result: (MOVWstorezeroidx4 ptr idx mem) + // match: (MSUBW a (MOVDconst [c]) x) + // cond: c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c) + // result: (ADDshiftLL a (SUBshiftLL x x [2]) [log2(c/3)]) for { _ = v.Args[2] - v_0 := v.Args[0] - if v_0.Op != OpARM64SLLconst { + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - if v_0.AuxInt != 2 { + c := v_1.AuxInt + x := v.Args[2] + if !(c%3 == 0 && isPowerOfTwo(c/3) && is32Bit(c)) { break } - idx := v_0.Args[0] - ptr := v.Args[1] - mem := v.Args[2] - v.reset(OpARM64MOVWstorezeroidx4) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 3) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } - // match: (MOVWstorezeroidx ptr (ADDconst [4] idx) x:(MOVWstorezeroidx ptr idx mem)) - // cond: x.Uses == 1 && clobber(x) - // result: (MOVDstorezeroidx ptr idx mem) + // match: (MSUBW a (MOVDconst [c]) x) + // cond: c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c) + // result: (SUBshiftLL a (ADDshiftLL x x [2]) [log2(c/5)]) for { _ = v.Args[2] - ptr := v.Args[0] + a := v.Args[0] v_1 := v.Args[1] - if v_1.Op != OpARM64ADDconst { + if v_1.Op != OpARM64MOVDconst { break } - if v_1.AuxInt != 4 { + c := v_1.AuxInt + x := v.Args[2] + if !(c%5 == 0 && isPowerOfTwo(c/5) && is32Bit(c)) { break } - idx := v_1.Args[0] - x := v.Args[2] - if x.Op != OpARM64MOVWstorezeroidx { + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 5) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 2 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MSUBW a (MOVDconst [c]) x) + // cond: c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c) + // result: (ADDshiftLL a (SUBshiftLL x x [3]) [log2(c/7)]) + for { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - _ = x.Args[2] - if ptr != x.Args[0] { + c := v_1.AuxInt + x := v.Args[2] + if !(c%7 == 0 && isPowerOfTwo(c/7) && is32Bit(c)) { break } - if idx != x.Args[1] { + v.reset(OpARM64ADDshiftLL) + v.AuxInt = log2(c / 7) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64SUBshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (MSUBW a (MOVDconst [c]) x) + // cond: c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c) + // result: (SUBshiftLL a (ADDshiftLL x x [3]) [log2(c/9)]) + for { + _ = v.Args[2] + a := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { break } - mem := x.Args[2] - if !(x.Uses == 1 && clobber(x)) { + c := v_1.AuxInt + x := v.Args[2] + if !(c%9 == 0 && isPowerOfTwo(c/9) && is32Bit(c)) { break } - v.reset(OpARM64MOVDstorezeroidx) - v.AddArg(ptr) - v.AddArg(idx) - v.AddArg(mem) + v.reset(OpARM64SUBshiftLL) + v.AuxInt = log2(c / 9) + v.AddArg(a) + v0 := b.NewValue0(v.Pos, OpARM64ADDshiftLL, x.Type) + v0.AuxInt = 3 + v0.AddArg(x) + v0.AddArg(x) + v.AddArg(v0) return true } return false } -func rewriteValueARM64_OpARM64MOVWstorezeroidx4_0(v *Value) bool { - // match: (MOVWstorezeroidx4 ptr (MOVDconst [c]) mem) +func rewriteValueARM64_OpARM64MSUBW_20(v *Value) bool { + b := v.Block + _ = b + // match: (MSUBW (MOVDconst [c]) x y) // cond: - // result: (MOVWstorezero [c<<2] ptr mem) + // result: (ADDconst [c] (MNEGW x y)) for { _ = v.Args[2] - ptr := v.Args[0] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + y := v.Args[2] + v.reset(OpARM64ADDconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64MNEGW, x.Type) + v0.AddArg(x) + v0.AddArg(y) + v.AddArg(v0) + return true + } + // match: (MSUBW a (MOVDconst [c]) (MOVDconst [d])) + // cond: + // result: (SUBconst [int64(int32(c)*int32(d))] a) + for { + _ = v.Args[2] + a := v.Args[0] v_1 := v.Args[1] if v_1.Op != OpARM64MOVDconst { break } c := v_1.AuxInt - mem := v.Args[2] - v.reset(OpARM64MOVWstorezero) - v.AuxInt = c << 2 - v.AddArg(ptr) - v.AddArg(mem) + v_2 := v.Args[2] + if v_2.Op != OpARM64MOVDconst { + break + } + d := v_2.AuxInt + v.reset(OpARM64SUBconst) + v.AuxInt = int64(int32(c) * int32(d)) + v.AddArg(a) return true } return false @@ -26956,7 +29000,7 @@ func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { return true } // match: (SUB a l:(MUL x y)) - // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: l.Uses==1 && clobber(l) // result: (MSUB a x y) for { _ = v.Args[1] @@ -26968,7 +29012,7 @@ func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] - if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MSUB) @@ -26978,7 +29022,7 @@ func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { return true } // match: (SUB a l:(MNEG x y)) - // cond: l.Uses==1 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: l.Uses==1 && clobber(l) // result: (MADD a x y) for { _ = v.Args[1] @@ -26990,7 +29034,7 @@ func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] - if !(l.Uses == 1 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MADD) @@ -27000,7 +29044,7 @@ func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { return true } // match: (SUB a l:(MULW x y)) - // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: a.Type.Size() != 8 && l.Uses==1 && clobber(l) // result: (MSUBW a x y) for { _ = v.Args[1] @@ -27012,7 +29056,7 @@ func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] - if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(a.Type.Size() != 8 && l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MSUBW) @@ -27022,7 +29066,7 @@ func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { return true } // match: (SUB a l:(MNEGW x y)) - // cond: l.Uses==1 && a.Type.Size() != 8 && x.Op!=OpARM64MOVDconst && y.Op!=OpARM64MOVDconst && a.Op!=OpARM64MOVDconst && clobber(l) + // cond: a.Type.Size() != 8 && l.Uses==1 && clobber(l) // result: (MADDW a x y) for { _ = v.Args[1] @@ -27034,7 +29078,7 @@ func rewriteValueARM64_OpARM64SUB_0(v *Value) bool { _ = l.Args[1] x := l.Args[0] y := l.Args[1] - if !(l.Uses == 1 && a.Type.Size() != 8 && x.Op != OpARM64MOVDconst && y.Op != OpARM64MOVDconst && a.Op != OpARM64MOVDconst && clobber(l)) { + if !(a.Type.Size() != 8 && l.Uses == 1 && clobber(l)) { break } v.reset(OpARM64MADDW) @@ -39865,4 +41909,4 @@ func rewriteBlockARM64(b *Block) bool { } } return false -} +} \ No newline at end of file diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index c0539256d52e2..05a28695d49e4 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -206,8 +206,15 @@ func AddMul(x int) int { return 2*x + 1 } -func MULA(a, b, c uint32) uint32 { - // arm:`MULA` - // arm64:`MADDW` - return a*b + c +func MULA(a, b, c uint32) (uint32, uint32, uint32) { + // arm:`MULA`,-`MUL\s` + // arm64:`MADDW`,-`MULW` + r0 := a*b + c + // arm:`MULA`-`MUL\s` + // arm64:`MADDW`,-`MULW` + r1 := c*79 + a + // arm:`ADD`,-`MULA`-`MUL\s` + // arm64:`ADD`,-`MADD`,-`MULW` + r2 := b*64 + c + return r0, r1, r2 } From 5aeecc4530657ab366122424b3ad78de83bc19ff Mon Sep 17 00:00:00 2001 From: Ben Shi Date: Thu, 27 Sep 2018 06:21:14 +0000 Subject: [PATCH 0485/1663] cmd/compile: optimize arm64's code with more shifted operations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL optimizes arm64's NEG/MVN/TST/CMN with a shifted operand. 1. The total size of pkg/android_arm64 decreases about 0.2KB, excluding cmd/compile/ . 2. The go1 benchmark shows no regression, excluding noise. name old time/op new time/op delta BinaryTree17-4 16.4s ± 1% 16.4s ± 1% ~ (p=0.914 n=29+29) Fannkuch11-4 8.72s ± 0% 8.72s ± 0% ~ (p=0.274 n=30+29) FmtFprintfEmpty-4 174ns ± 0% 174ns ± 0% ~ (all equal) FmtFprintfString-4 370ns ± 0% 370ns ± 0% ~ (all equal) FmtFprintfInt-4 419ns ± 0% 419ns ± 0% ~ (all equal) FmtFprintfIntInt-4 672ns ± 1% 675ns ± 2% ~ (p=0.217 n=28+30) FmtFprintfPrefixedInt-4 806ns ± 0% 806ns ± 0% ~ (p=0.402 n=30+28) FmtFprintfFloat-4 1.09µs ± 0% 1.09µs ± 0% +0.02% (p=0.011 n=22+27) FmtManyArgs-4 2.67µs ± 0% 2.68µs ± 0% ~ (p=0.279 n=29+30) GobDecode-4 33.1ms ± 1% 33.1ms ± 0% ~ (p=0.052 n=28+29) GobEncode-4 29.6ms ± 0% 29.6ms ± 0% +0.08% (p=0.013 n=28+29) Gzip-4 1.38s ± 2% 1.39s ± 2% ~ (p=0.071 n=29+29) Gunzip-4 139ms ± 0% 139ms ± 0% ~ (p=0.265 n=29+29) HTTPClientServer-4 789µs ± 4% 785µs ± 4% ~ (p=0.206 n=29+28) JSONEncode-4 49.7ms ± 0% 49.6ms ± 0% -0.24% (p=0.000 n=30+30) JSONDecode-4 266ms ± 1% 267ms ± 1% +0.34% (p=0.000 n=30+30) Mandelbrot200-4 16.6ms ± 0% 16.6ms ± 0% ~ (p=0.835 n=28+30) GoParse-4 15.9ms ± 0% 15.8ms ± 0% -0.29% (p=0.000 n=27+30) RegexpMatchEasy0_32-4 380ns ± 0% 381ns ± 0% +0.18% (p=0.000 n=30+30) RegexpMatchEasy0_1K-4 1.18µs ± 0% 1.19µs ± 0% +0.23% (p=0.000 n=30+30) RegexpMatchEasy1_32-4 357ns ± 0% 358ns ± 0% +0.28% (p=0.000 n=29+29) RegexpMatchEasy1_1K-4 2.04µs ± 0% 2.04µs ± 0% +0.06% (p=0.006 n=30+30) RegexpMatchMedium_32-4 589ns ± 0% 590ns ± 0% +0.24% (p=0.000 n=28+30) RegexpMatchMedium_1K-4 162µs ± 0% 162µs ± 0% -0.01% (p=0.027 n=26+29) RegexpMatchHard_32-4 9.58µs ± 0% 9.58µs ± 0% ~ (p=0.935 n=30+30) RegexpMatchHard_1K-4 287µs ± 0% 287µs ± 0% ~ (p=0.387 n=29+30) Revcomp-4 2.50s ± 0% 2.50s ± 0% -0.10% (p=0.020 n=28+28) Template-4 310ms ± 0% 310ms ± 1% ~ (p=0.406 n=30+30) TimeParse-4 1.68µs ± 0% 1.68µs ± 0% +0.03% (p=0.014 n=30+17) TimeFormat-4 1.65µs ± 0% 1.66µs ± 0% +0.32% (p=0.000 n=27+29) [Geo mean] 247µs 247µs +0.05% name old speed new speed delta GobDecode-4 23.2MB/s ± 0% 23.2MB/s ± 0% -0.08% (p=0.032 n=27+29) GobEncode-4 26.0MB/s ± 0% 25.9MB/s ± 0% -0.10% (p=0.011 n=29+29) Gzip-4 14.1MB/s ± 2% 14.0MB/s ± 2% ~ (p=0.081 n=29+29) Gunzip-4 139MB/s ± 0% 139MB/s ± 0% ~ (p=0.290 n=29+29) JSONEncode-4 39.0MB/s ± 0% 39.1MB/s ± 0% +0.25% (p=0.000 n=29+30) JSONDecode-4 7.30MB/s ± 1% 7.28MB/s ± 1% -0.33% (p=0.000 n=30+30) GoParse-4 3.65MB/s ± 0% 3.66MB/s ± 0% +0.29% (p=0.000 n=27+30) RegexpMatchEasy0_32-4 84.1MB/s ± 0% 84.0MB/s ± 0% -0.17% (p=0.000 n=30+28) RegexpMatchEasy0_1K-4 864MB/s ± 0% 862MB/s ± 0% -0.24% (p=0.000 n=30+30) RegexpMatchEasy1_32-4 89.5MB/s ± 0% 89.3MB/s ± 0% -0.18% (p=0.000 n=28+24) RegexpMatchEasy1_1K-4 502MB/s ± 0% 502MB/s ± 0% -0.05% (p=0.008 n=30+29) RegexpMatchMedium_32-4 1.70MB/s ± 0% 1.69MB/s ± 0% -0.59% (p=0.000 n=29+30) RegexpMatchMedium_1K-4 6.31MB/s ± 0% 6.31MB/s ± 0% +0.05% (p=0.005 n=30+26) RegexpMatchHard_32-4 3.34MB/s ± 0% 3.34MB/s ± 0% ~ (all equal) RegexpMatchHard_1K-4 3.57MB/s ± 0% 3.57MB/s ± 0% ~ (all equal) Revcomp-4 102MB/s ± 0% 102MB/s ± 0% +0.10% (p=0.022 n=28+28) Template-4 6.26MB/s ± 0% 6.26MB/s ± 1% ~ (p=0.768 n=30+30) [Geo mean] 24.2MB/s 24.1MB/s -0.08% Change-Id: I494f9db7f8a568a00e9c74ae25086a58b2221683 Reviewed-on: https://go-review.googlesource.com/137976 Run-TryBot: Ben Shi TryBot-Result: Gobot Gobot Reviewed-by: Cherry Zhang --- src/cmd/compile/internal/arm64/ssa.go | 12 +- src/cmd/compile/internal/ssa/gen/ARM64.rules | 30 + src/cmd/compile/internal/ssa/gen/ARM64Ops.go | 12 + src/cmd/compile/internal/ssa/opGen.go | 168 ++++ src/cmd/compile/internal/ssa/rewriteARM64.go | 794 ++++++++++++++++++- test/codegen/arithmetic.go | 2 +- test/codegen/comparisons.go | 8 + 7 files changed, 994 insertions(+), 32 deletions(-) diff --git a/src/cmd/compile/internal/arm64/ssa.go b/src/cmd/compile/internal/arm64/ssa.go index 482442cd22532..87703dd80df82 100644 --- a/src/cmd/compile/internal/arm64/ssa.go +++ b/src/cmd/compile/internal/arm64/ssa.go @@ -255,6 +255,12 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.Reg = v.Args[1].Reg() p.To.Type = obj.TYPE_REG p.To.Reg = v.Reg() + case ssa.OpARM64MVNshiftLL, ssa.OpARM64NEGshiftLL: + genshift(s, v.Op.Asm(), 0, v.Args[0].Reg(), v.Reg(), arm64.SHIFT_LL, v.AuxInt) + case ssa.OpARM64MVNshiftRL, ssa.OpARM64NEGshiftRL: + genshift(s, v.Op.Asm(), 0, v.Args[0].Reg(), v.Reg(), arm64.SHIFT_LR, v.AuxInt) + case ssa.OpARM64MVNshiftRA, ssa.OpARM64NEGshiftRA: + genshift(s, v.Op.Asm(), 0, v.Args[0].Reg(), v.Reg(), arm64.SHIFT_AR, v.AuxInt) case ssa.OpARM64ADDshiftLL, ssa.OpARM64SUBshiftLL, ssa.OpARM64ANDshiftLL, @@ -317,11 +323,11 @@ func ssaGenValue(s *gc.SSAGenState, v *ssa.Value) { p.From.Type = obj.TYPE_CONST p.From.Offset = v.AuxInt p.Reg = v.Args[0].Reg() - case ssa.OpARM64CMPshiftLL: + case ssa.OpARM64CMPshiftLL, ssa.OpARM64CMNshiftLL, ssa.OpARM64TSTshiftLL: genshift(s, v.Op.Asm(), v.Args[0].Reg(), v.Args[1].Reg(), 0, arm64.SHIFT_LL, v.AuxInt) - case ssa.OpARM64CMPshiftRL: + case ssa.OpARM64CMPshiftRL, ssa.OpARM64CMNshiftRL, ssa.OpARM64TSTshiftRL: genshift(s, v.Op.Asm(), v.Args[0].Reg(), v.Args[1].Reg(), 0, arm64.SHIFT_LR, v.AuxInt) - case ssa.OpARM64CMPshiftRA: + case ssa.OpARM64CMPshiftRA, ssa.OpARM64CMNshiftRA, ssa.OpARM64TSTshiftRA: genshift(s, v.Op.Asm(), v.Args[0].Reg(), v.Args[1].Reg(), 0, arm64.SHIFT_AR, v.AuxInt) case ssa.OpARM64MOVDaddr: p := s.Prog(arm64.AMOVD) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64.rules b/src/cmd/compile/internal/ssa/gen/ARM64.rules index 3fce018d45ef5..659081ec8b01c 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64.rules +++ b/src/cmd/compile/internal/ssa/gen/ARM64.rules @@ -1605,6 +1605,12 @@ (CSEL0 {arm64Negate(bool.Op)} x flagArg(bool)) // absorb shifts into ops +(NEG x:(SLLconst [c] y)) && clobberIfDead(x) -> (NEGshiftLL [c] y) +(NEG x:(SRLconst [c] y)) && clobberIfDead(x) -> (NEGshiftRL [c] y) +(NEG x:(SRAconst [c] y)) && clobberIfDead(x) -> (NEGshiftRA [c] y) +(MVN x:(SLLconst [c] y)) && clobberIfDead(x) -> (MVNshiftLL [c] y) +(MVN x:(SRLconst [c] y)) && clobberIfDead(x) -> (MVNshiftRL [c] y) +(MVN x:(SRAconst [c] y)) && clobberIfDead(x) -> (MVNshiftRA [c] y) (ADD x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) -> (ADDshiftLL x0 y [c]) (ADD x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) -> (ADDshiftRL x0 y [c]) (ADD x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) -> (ADDshiftRA x0 y [c]) @@ -1635,6 +1641,12 @@ (CMP x0:(SRLconst [c] y) x1) && clobberIfDead(x0) -> (InvertFlags (CMPshiftRL x1 y [c])) (CMP x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) -> (CMPshiftRA x0 y [c]) (CMP x0:(SRAconst [c] y) x1) && clobberIfDead(x0) -> (InvertFlags (CMPshiftRA x1 y [c])) +(CMN x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) -> (CMNshiftLL x0 y [c]) +(CMN x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) -> (CMNshiftRL x0 y [c]) +(CMN x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) -> (CMNshiftRA x0 y [c]) +(TST x0 x1:(SLLconst [c] y)) && clobberIfDead(x1) -> (TSTshiftLL x0 y [c]) +(TST x0 x1:(SRLconst [c] y)) && clobberIfDead(x1) -> (TSTshiftRL x0 y [c]) +(TST x0 x1:(SRAconst [c] y)) && clobberIfDead(x1) -> (TSTshiftRA x0 y [c]) // prefer *const ops to *shift ops (ADDshiftLL (MOVDconst [c]) x [d]) -> (ADDconst [c] (SLLconst x [d])) @@ -1652,8 +1664,20 @@ (CMPshiftLL (MOVDconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SLLconst x [d]))) (CMPshiftRL (MOVDconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SRLconst x [d]))) (CMPshiftRA (MOVDconst [c]) x [d]) -> (InvertFlags (CMPconst [c] (SRAconst x [d]))) +(CMNshiftLL (MOVDconst [c]) x [d]) -> (CMNconst [c] (SLLconst x [d])) +(CMNshiftRL (MOVDconst [c]) x [d]) -> (CMNconst [c] (SRLconst x [d])) +(CMNshiftRA (MOVDconst [c]) x [d]) -> (CMNconst [c] (SRAconst x [d])) +(TSTshiftLL (MOVDconst [c]) x [d]) -> (TSTconst [c] (SLLconst x [d])) +(TSTshiftRL (MOVDconst [c]) x [d]) -> (TSTconst [c] (SRLconst x [d])) +(TSTshiftRA (MOVDconst [c]) x [d]) -> (TSTconst [c] (SRAconst x [d])) // constant folding in *shift ops +(MVNshiftLL (MOVDconst [c]) [d]) -> (MOVDconst [^int64(uint64(c)< (MOVDconst [^int64(uint64(c)>>uint64(d))]) +(MVNshiftRA (MOVDconst [c]) [d]) -> (MOVDconst [^(c>>uint64(d))]) +(NEGshiftLL (MOVDconst [c]) [d]) -> (MOVDconst [-int64(uint64(c)< (MOVDconst [-int64(uint64(c)>>uint64(d))]) +(NEGshiftRA (MOVDconst [c]) [d]) -> (MOVDconst [-(c>>uint64(d))]) (ADDshiftLL x (MOVDconst [c]) [d]) -> (ADDconst x [int64(uint64(c)< (ADDconst x [int64(uint64(c)>>uint64(d))]) (ADDshiftRA x (MOVDconst [c]) [d]) -> (ADDconst x [c>>uint64(d)]) @@ -1681,6 +1705,12 @@ (CMPshiftLL x (MOVDconst [c]) [d]) -> (CMPconst x [int64(uint64(c)< (CMPconst x [int64(uint64(c)>>uint64(d))]) (CMPshiftRA x (MOVDconst [c]) [d]) -> (CMPconst x [c>>uint64(d)]) +(CMNshiftLL x (MOVDconst [c]) [d]) -> (CMNconst x [int64(uint64(c)< (CMNconst x [int64(uint64(c)>>uint64(d))]) +(CMNshiftRA x (MOVDconst [c]) [d]) -> (CMNconst x [c>>uint64(d)]) +(TSTshiftLL x (MOVDconst [c]) [d]) -> (TSTconst x [int64(uint64(c)< (TSTconst x [int64(uint64(c)>>uint64(d))]) +(TSTshiftRA x (MOVDconst [c]) [d]) -> (TSTconst x [c>>uint64(d)]) // simplification with *shift ops (SUBshiftLL x (SLLconst x [c]) [d]) && c==d -> (MOVDconst [0]) diff --git a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go index 4381c081b7b25..fc0a41527b2e7 100644 --- a/src/cmd/compile/internal/ssa/gen/ARM64Ops.go +++ b/src/cmd/compile/internal/ssa/gen/ARM64Ops.go @@ -273,6 +273,12 @@ func init() { {name: "FCMPD", argLength: 2, reg: fp2flags, asm: "FCMPD", typ: "Flags"}, // arg0 compare to arg1, float64 // shifted ops + {name: "MVNshiftLL", argLength: 1, reg: gp11, asm: "MVN", aux: "Int64"}, // ^(arg0<>auxInt), unsigned shift + {name: "MVNshiftRA", argLength: 1, reg: gp11, asm: "MVN", aux: "Int64"}, // ^(arg0>>auxInt), signed shift + {name: "NEGshiftLL", argLength: 1, reg: gp11, asm: "NEG", aux: "Int64"}, // -(arg0<>auxInt), unsigned shift + {name: "NEGshiftRA", argLength: 1, reg: gp11, asm: "NEG", aux: "Int64"}, // -(arg0>>auxInt), signed shift {name: "ADDshiftLL", argLength: 2, reg: gp21, asm: "ADD", aux: "Int64"}, // arg0 + arg1<>auxInt, unsigned shift {name: "ADDshiftRA", argLength: 2, reg: gp21, asm: "ADD", aux: "Int64"}, // arg0 + arg1>>auxInt, signed shift @@ -300,6 +306,12 @@ func init() { {name: "CMPshiftLL", argLength: 2, reg: gp2flags, asm: "CMP", aux: "Int64", typ: "Flags"}, // arg0 compare to arg1<>auxInt, unsigned shift {name: "CMPshiftRA", argLength: 2, reg: gp2flags, asm: "CMP", aux: "Int64", typ: "Flags"}, // arg0 compare to arg1>>auxInt, signed shift + {name: "CMNshiftLL", argLength: 2, reg: gp2flags, asm: "CMN", aux: "Int64", typ: "Flags"}, // (arg0 + arg1<>auxInt) compare to 0, unsigned shift + {name: "CMNshiftRA", argLength: 2, reg: gp2flags, asm: "CMN", aux: "Int64", typ: "Flags"}, // (arg0 + arg1>>auxInt) compare to 0, signed shift + {name: "TSTshiftLL", argLength: 2, reg: gp2flags, asm: "TST", aux: "Int64", typ: "Flags"}, // (arg0 & arg1<>auxInt) compare to 0, unsigned shift + {name: "TSTshiftRA", argLength: 2, reg: gp2flags, asm: "TST", aux: "Int64", typ: "Flags"}, // (arg0 & arg1>>auxInt) compare to 0, signed shift // bitfield ops // for all bitfield ops lsb is auxInt>>8, width is auxInt&0xff diff --git a/src/cmd/compile/internal/ssa/opGen.go b/src/cmd/compile/internal/ssa/opGen.go index fe63633750dec..5f5345ad5ca2d 100644 --- a/src/cmd/compile/internal/ssa/opGen.go +++ b/src/cmd/compile/internal/ssa/opGen.go @@ -1172,6 +1172,12 @@ const ( OpARM64TSTWconst OpARM64FCMPS OpARM64FCMPD + OpARM64MVNshiftLL + OpARM64MVNshiftRL + OpARM64MVNshiftRA + OpARM64NEGshiftLL + OpARM64NEGshiftRL + OpARM64NEGshiftRA OpARM64ADDshiftLL OpARM64ADDshiftRL OpARM64ADDshiftRA @@ -1199,6 +1205,12 @@ const ( OpARM64CMPshiftLL OpARM64CMPshiftRL OpARM64CMPshiftRA + OpARM64CMNshiftLL + OpARM64CMNshiftRL + OpARM64CMNshiftRA + OpARM64TSTshiftLL + OpARM64TSTshiftRL + OpARM64TSTshiftRA OpARM64BFI OpARM64BFXIL OpARM64SBFIZ @@ -15553,6 +15565,90 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "MVNshiftLL", + auxType: auxInt64, + argLen: 1, + asm: arm64.AMVN, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, + { + name: "MVNshiftRL", + auxType: auxInt64, + argLen: 1, + asm: arm64.AMVN, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, + { + name: "MVNshiftRA", + auxType: auxInt64, + argLen: 1, + asm: arm64.AMVN, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, + { + name: "NEGshiftLL", + auxType: auxInt64, + argLen: 1, + asm: arm64.ANEG, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, + { + name: "NEGshiftRL", + auxType: auxInt64, + argLen: 1, + asm: arm64.ANEG, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, + { + name: "NEGshiftRA", + auxType: auxInt64, + argLen: 1, + asm: arm64.ANEG, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + outputs: []outputInfo{ + {0, 670826495}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 R30 + }, + }, + }, { name: "ADDshiftLL", auxType: auxInt64, @@ -15949,6 +16045,78 @@ var opcodeTable = [...]opInfo{ }, }, }, + { + name: "CMNshiftLL", + auxType: auxInt64, + argLen: 2, + asm: arm64.ACMN, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + }, + }, + { + name: "CMNshiftRL", + auxType: auxInt64, + argLen: 2, + asm: arm64.ACMN, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + }, + }, + { + name: "CMNshiftRA", + auxType: auxInt64, + argLen: 2, + asm: arm64.ACMN, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + }, + }, + { + name: "TSTshiftLL", + auxType: auxInt64, + argLen: 2, + asm: arm64.ATST, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + }, + }, + { + name: "TSTshiftRL", + auxType: auxInt64, + argLen: 2, + asm: arm64.ATST, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + }, + }, + { + name: "TSTshiftRA", + auxType: auxInt64, + argLen: 2, + asm: arm64.ATST, + reg: regInfo{ + inputs: []inputInfo{ + {0, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + {1, 805044223}, // R0 R1 R2 R3 R4 R5 R6 R7 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R19 R20 R21 R22 R23 R24 R25 R26 g R30 + }, + }, + }, { name: "BFI", auxType: auxInt64, diff --git a/src/cmd/compile/internal/ssa/rewriteARM64.go b/src/cmd/compile/internal/ssa/rewriteARM64.go index f07ab4209087f..95011eab48069 100644 --- a/src/cmd/compile/internal/ssa/rewriteARM64.go +++ b/src/cmd/compile/internal/ssa/rewriteARM64.go @@ -51,6 +51,12 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64CMNWconst_0(v) case OpARM64CMNconst: return rewriteValueARM64_OpARM64CMNconst_0(v) + case OpARM64CMNshiftLL: + return rewriteValueARM64_OpARM64CMNshiftLL_0(v) + case OpARM64CMNshiftRA: + return rewriteValueARM64_OpARM64CMNshiftRA_0(v) + case OpARM64CMNshiftRL: + return rewriteValueARM64_OpARM64CMNshiftRL_0(v) case OpARM64CMP: return rewriteValueARM64_OpARM64CMP_0(v) case OpARM64CMPW: @@ -259,8 +265,20 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64MULW_0(v) || rewriteValueARM64_OpARM64MULW_10(v) || rewriteValueARM64_OpARM64MULW_20(v) case OpARM64MVN: return rewriteValueARM64_OpARM64MVN_0(v) + case OpARM64MVNshiftLL: + return rewriteValueARM64_OpARM64MVNshiftLL_0(v) + case OpARM64MVNshiftRA: + return rewriteValueARM64_OpARM64MVNshiftRA_0(v) + case OpARM64MVNshiftRL: + return rewriteValueARM64_OpARM64MVNshiftRL_0(v) case OpARM64NEG: return rewriteValueARM64_OpARM64NEG_0(v) + case OpARM64NEGshiftLL: + return rewriteValueARM64_OpARM64NEGshiftLL_0(v) + case OpARM64NEGshiftRA: + return rewriteValueARM64_OpARM64NEGshiftRA_0(v) + case OpARM64NEGshiftRL: + return rewriteValueARM64_OpARM64NEGshiftRL_0(v) case OpARM64NotEqual: return rewriteValueARM64_OpARM64NotEqual_0(v) case OpARM64OR: @@ -317,6 +335,12 @@ func rewriteValueARM64(v *Value) bool { return rewriteValueARM64_OpARM64TSTWconst_0(v) case OpARM64TSTconst: return rewriteValueARM64_OpARM64TSTconst_0(v) + case OpARM64TSTshiftLL: + return rewriteValueARM64_OpARM64TSTshiftLL_0(v) + case OpARM64TSTshiftRA: + return rewriteValueARM64_OpARM64TSTshiftRA_0(v) + case OpARM64TSTshiftRL: + return rewriteValueARM64_OpARM64TSTshiftRL_0(v) case OpARM64UBFIZ: return rewriteValueARM64_OpARM64UBFIZ_0(v) case OpARM64UBFX: @@ -3340,6 +3364,132 @@ func rewriteValueARM64_OpARM64CMN_0(v *Value) bool { v.AddArg(x) return true } + // match: (CMN x0 x1:(SLLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (CMNshiftLL x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SLLconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64CMNshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (CMN x1:(SLLconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (CMNshiftLL x0 y [c]) + for { + _ = v.Args[1] + x1 := v.Args[0] + if x1.Op != OpARM64SLLconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64CMNshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (CMN x0 x1:(SRLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (CMNshiftRL x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRLconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64CMNshiftRL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (CMN x1:(SRLconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (CMNshiftRL x0 y [c]) + for { + _ = v.Args[1] + x1 := v.Args[0] + if x1.Op != OpARM64SRLconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64CMNshiftRL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (CMN x0 x1:(SRAconst [c] y)) + // cond: clobberIfDead(x1) + // result: (CMNshiftRA x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRAconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64CMNshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (CMN x1:(SRAconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (CMNshiftRA x0 y [c]) + for { + _ = v.Args[1] + x1 := v.Args[0] + if x1.Op != OpARM64SRAconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64CMNshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } return false } func rewriteValueARM64_OpARM64CMNW_0(v *Value) bool { @@ -3543,6 +3693,132 @@ func rewriteValueARM64_OpARM64CMNconst_0(v *Value) bool { } return false } +func rewriteValueARM64_OpARM64CMNshiftLL_0(v *Value) bool { + b := v.Block + _ = b + // match: (CMNshiftLL (MOVDconst [c]) x [d]) + // cond: + // result: (CMNconst [c] (SLLconst x [d])) + for { + d := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64CMNconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (CMNshiftLL x (MOVDconst [c]) [d]) + // cond: + // result: (CMNconst x [int64(uint64(c)< x [d])) + for { + d := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64CMNconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SRAconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (CMNshiftRA x (MOVDconst [c]) [d]) + // cond: + // result: (CMNconst x [c>>uint64(d)]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64CMNconst) + v.AuxInt = c >> uint64(d) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64CMNshiftRL_0(v *Value) bool { + b := v.Block + _ = b + // match: (CMNshiftRL (MOVDconst [c]) x [d]) + // cond: + // result: (CMNconst [c] (SRLconst x [d])) + for { + d := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64CMNconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SRLconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (CMNshiftRL x (MOVDconst [c]) [d]) + // cond: + // result: (CMNconst x [int64(uint64(c)>>uint64(d))]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64CMNconst) + v.AuxInt = int64(uint64(c) >> uint64(d)) + v.AddArg(x) + return true + } + return false +} func rewriteValueARM64_OpARM64CMP_0(v *Value) bool { b := v.Block _ = b @@ -19959,47 +20235,152 @@ func rewriteValueARM64_OpARM64MVN_0(v *Value) bool { v.AuxInt = ^c return true } - return false -} -func rewriteValueARM64_OpARM64NEG_0(v *Value) bool { - // match: (NEG (MUL x y)) - // cond: - // result: (MNEG x y) + // match: (MVN x:(SLLconst [c] y)) + // cond: clobberIfDead(x) + // result: (MVNshiftLL [c] y) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MUL { + x := v.Args[0] + if x.Op != OpARM64SLLconst { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - v.reset(OpARM64MNEG) - v.AddArg(x) + c := x.AuxInt + y := x.Args[0] + if !(clobberIfDead(x)) { + break + } + v.reset(OpARM64MVNshiftLL) + v.AuxInt = c v.AddArg(y) return true } - // match: (NEG (MULW x y)) - // cond: - // result: (MNEGW x y) + // match: (MVN x:(SRLconst [c] y)) + // cond: clobberIfDead(x) + // result: (MVNshiftRL [c] y) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MULW { + x := v.Args[0] + if x.Op != OpARM64SRLconst { break } - _ = v_0.Args[1] - x := v_0.Args[0] - y := v_0.Args[1] - v.reset(OpARM64MNEGW) - v.AddArg(x) + c := x.AuxInt + y := x.Args[0] + if !(clobberIfDead(x)) { + break + } + v.reset(OpARM64MVNshiftRL) + v.AuxInt = c v.AddArg(y) return true } - // match: (NEG (MOVDconst [c])) - // cond: - // result: (MOVDconst [-c]) + // match: (MVN x:(SRAconst [c] y)) + // cond: clobberIfDead(x) + // result: (MVNshiftRA [c] y) for { - v_0 := v.Args[0] - if v_0.Op != OpARM64MOVDconst { + x := v.Args[0] + if x.Op != OpARM64SRAconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(clobberIfDead(x)) { + break + } + v.reset(OpARM64MVNshiftRA) + v.AuxInt = c + v.AddArg(y) + return true + } + return false +} +func rewriteValueARM64_OpARM64MVNshiftLL_0(v *Value) bool { + // match: (MVNshiftLL (MOVDconst [c]) [d]) + // cond: + // result: (MOVDconst [^int64(uint64(c)<>uint64(d))]) + for { + d := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = ^(c >> uint64(d)) + return true + } + return false +} +func rewriteValueARM64_OpARM64MVNshiftRL_0(v *Value) bool { + // match: (MVNshiftRL (MOVDconst [c]) [d]) + // cond: + // result: (MOVDconst [^int64(uint64(c)>>uint64(d))]) + for { + d := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = ^int64(uint64(c) >> uint64(d)) + return true + } + return false +} +func rewriteValueARM64_OpARM64NEG_0(v *Value) bool { + // match: (NEG (MUL x y)) + // cond: + // result: (MNEG x y) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MUL { + break + } + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + v.reset(OpARM64MNEG) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (NEG (MULW x y)) + // cond: + // result: (MNEGW x y) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MULW { + break + } + _ = v_0.Args[1] + x := v_0.Args[0] + y := v_0.Args[1] + v.reset(OpARM64MNEGW) + v.AddArg(x) + v.AddArg(y) + return true + } + // match: (NEG (MOVDconst [c])) + // cond: + // result: (MOVDconst [-c]) + for { + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { break } c := v_0.AuxInt @@ -20007,6 +20388,111 @@ func rewriteValueARM64_OpARM64NEG_0(v *Value) bool { v.AuxInt = -c return true } + // match: (NEG x:(SLLconst [c] y)) + // cond: clobberIfDead(x) + // result: (NEGshiftLL [c] y) + for { + x := v.Args[0] + if x.Op != OpARM64SLLconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(clobberIfDead(x)) { + break + } + v.reset(OpARM64NEGshiftLL) + v.AuxInt = c + v.AddArg(y) + return true + } + // match: (NEG x:(SRLconst [c] y)) + // cond: clobberIfDead(x) + // result: (NEGshiftRL [c] y) + for { + x := v.Args[0] + if x.Op != OpARM64SRLconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(clobberIfDead(x)) { + break + } + v.reset(OpARM64NEGshiftRL) + v.AuxInt = c + v.AddArg(y) + return true + } + // match: (NEG x:(SRAconst [c] y)) + // cond: clobberIfDead(x) + // result: (NEGshiftRA [c] y) + for { + x := v.Args[0] + if x.Op != OpARM64SRAconst { + break + } + c := x.AuxInt + y := x.Args[0] + if !(clobberIfDead(x)) { + break + } + v.reset(OpARM64NEGshiftRA) + v.AuxInt = c + v.AddArg(y) + return true + } + return false +} +func rewriteValueARM64_OpARM64NEGshiftLL_0(v *Value) bool { + // match: (NEGshiftLL (MOVDconst [c]) [d]) + // cond: + // result: (MOVDconst [-int64(uint64(c)<>uint64(d))]) + for { + d := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = -(c >> uint64(d)) + return true + } + return false +} +func rewriteValueARM64_OpARM64NEGshiftRL_0(v *Value) bool { + // match: (NEGshiftRL (MOVDconst [c]) [d]) + // cond: + // result: (MOVDconst [-int64(uint64(c)>>uint64(d))]) + for { + d := v.AuxInt + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + v.reset(OpARM64MOVDconst) + v.AuxInt = -int64(uint64(c) >> uint64(d)) + return true + } return false } func rewriteValueARM64_OpARM64NotEqual_0(v *Value) bool { @@ -29431,6 +29917,132 @@ func rewriteValueARM64_OpARM64TST_0(v *Value) bool { v.AddArg(x) return true } + // match: (TST x0 x1:(SLLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (TSTshiftLL x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SLLconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64TSTshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (TST x1:(SLLconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (TSTshiftLL x0 y [c]) + for { + _ = v.Args[1] + x1 := v.Args[0] + if x1.Op != OpARM64SLLconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64TSTshiftLL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (TST x0 x1:(SRLconst [c] y)) + // cond: clobberIfDead(x1) + // result: (TSTshiftRL x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRLconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64TSTshiftRL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (TST x1:(SRLconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (TSTshiftRL x0 y [c]) + for { + _ = v.Args[1] + x1 := v.Args[0] + if x1.Op != OpARM64SRLconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64TSTshiftRL) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (TST x0 x1:(SRAconst [c] y)) + // cond: clobberIfDead(x1) + // result: (TSTshiftRA x0 y [c]) + for { + _ = v.Args[1] + x0 := v.Args[0] + x1 := v.Args[1] + if x1.Op != OpARM64SRAconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64TSTshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } + // match: (TST x1:(SRAconst [c] y) x0) + // cond: clobberIfDead(x1) + // result: (TSTshiftRA x0 y [c]) + for { + _ = v.Args[1] + x1 := v.Args[0] + if x1.Op != OpARM64SRAconst { + break + } + c := x1.AuxInt + y := x1.Args[0] + x0 := v.Args[1] + if !(clobberIfDead(x1)) { + break + } + v.reset(OpARM64TSTshiftRA) + v.AuxInt = c + v.AddArg(x0) + v.AddArg(y) + return true + } return false } func rewriteValueARM64_OpARM64TSTW_0(v *Value) bool { @@ -29570,6 +30182,132 @@ func rewriteValueARM64_OpARM64TSTconst_0(v *Value) bool { } return false } +func rewriteValueARM64_OpARM64TSTshiftLL_0(v *Value) bool { + b := v.Block + _ = b + // match: (TSTshiftLL (MOVDconst [c]) x [d]) + // cond: + // result: (TSTconst [c] (SLLconst x [d])) + for { + d := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64TSTconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SLLconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (TSTshiftLL x (MOVDconst [c]) [d]) + // cond: + // result: (TSTconst x [int64(uint64(c)< x [d])) + for { + d := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64TSTconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SRAconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (TSTshiftRA x (MOVDconst [c]) [d]) + // cond: + // result: (TSTconst x [c>>uint64(d)]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64TSTconst) + v.AuxInt = c >> uint64(d) + v.AddArg(x) + return true + } + return false +} +func rewriteValueARM64_OpARM64TSTshiftRL_0(v *Value) bool { + b := v.Block + _ = b + // match: (TSTshiftRL (MOVDconst [c]) x [d]) + // cond: + // result: (TSTconst [c] (SRLconst x [d])) + for { + d := v.AuxInt + _ = v.Args[1] + v_0 := v.Args[0] + if v_0.Op != OpARM64MOVDconst { + break + } + c := v_0.AuxInt + x := v.Args[1] + v.reset(OpARM64TSTconst) + v.AuxInt = c + v0 := b.NewValue0(v.Pos, OpARM64SRLconst, x.Type) + v0.AuxInt = d + v0.AddArg(x) + v.AddArg(v0) + return true + } + // match: (TSTshiftRL x (MOVDconst [c]) [d]) + // cond: + // result: (TSTconst x [int64(uint64(c)>>uint64(d))]) + for { + d := v.AuxInt + _ = v.Args[1] + x := v.Args[0] + v_1 := v.Args[1] + if v_1.Op != OpARM64MOVDconst { + break + } + c := v_1.AuxInt + v.reset(OpARM64TSTconst) + v.AuxInt = int64(uint64(c) >> uint64(d)) + v.AddArg(x) + return true + } + return false +} func rewriteValueARM64_OpARM64UBFIZ_0(v *Value) bool { // match: (UBFIZ [bfc] (SLLconst [sc] x)) // cond: sc < getARM64BFwidth(bfc) diff --git a/test/codegen/arithmetic.go b/test/codegen/arithmetic.go index 05a28695d49e4..8e2a210948859 100644 --- a/test/codegen/arithmetic.go +++ b/test/codegen/arithmetic.go @@ -44,7 +44,7 @@ func Pow2Muls(n1, n2 int) (int, int) { // amd64:"SHLQ\t[$]6",-"IMULQ" // 386:"SHLL\t[$]6",-"IMULL" // arm:"SLL\t[$]6",-"MUL" - // arm64:"LSL\t[$]6",-"MUL" + // arm64:`NEG\sR[0-9]+<<6,\sR[0-9]+`,-`LSL`,-`MUL` b := -64 * n2 return a, b diff --git a/test/codegen/comparisons.go b/test/codegen/comparisons.go index d5bade97cce8f..072393f3a6f7c 100644 --- a/test/codegen/comparisons.go +++ b/test/codegen/comparisons.go @@ -183,6 +183,10 @@ func CmpToZero(a, b, d int32, e, f int64) int32 { // arm:`AND`,-`TST` // 386:`ANDL` c6 := a&d >= 0 + // arm64:`TST\sR[0-9]+<<3,\sR[0-9]+` + c7 := e&(f<<3) < 0 + // arm64:`CMN\sR[0-9]+<<3,\sR[0-9]+` + c8 := e+(f<<3) < 0 if c0 { return 1 } else if c1 { @@ -197,6 +201,10 @@ func CmpToZero(a, b, d int32, e, f int64) int32 { return b + d } else if c6 { return a & d + } else if c7 { + return 7 + } else if c8 { + return 8 } else { return 0 } From eac99c44667a748f8b00f38c5f44beb41e1b4503 Mon Sep 17 00:00:00 2001 From: Alessandro Arzilli Date: Fri, 28 Sep 2018 16:01:45 +0200 Subject: [PATCH 0486/1663] doc: remove "known bug" about global variables in debug_info. This hasn't been true at least since 1.4. Until golang.org/cl/137235 they were lumped together into a random compile unit, now they are assigned to the correct one. Change-Id: Ib66539bd67af3e9daeecac8bf5f32c10e62e11b1 Reviewed-on: https://go-review.googlesource.com/138415 Reviewed-by: Than McIntosh Reviewed-by: David Chase --- doc/debugging_with_gdb.html | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/debugging_with_gdb.html b/doc/debugging_with_gdb.html index a6b0054d4fb34..fd2c83192508c 100644 --- a/doc/debugging_with_gdb.html +++ b/doc/debugging_with_gdb.html @@ -179,7 +179,6 @@

      Known Issues

      "fmt.Print" as an unstructured literal with a "." that needs to be quoted. It objects even more strongly to method names of the form pkg.(*MyType).Meth. -
    • All global variables are lumped into package "main".
    • As of Go 1.11, debug information is compressed by default. Older versions of gdb, such as the one available by default on MacOS, do not understand the compression. From 2d23ece135076698ea4724b02f07d71d1f2145fb Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sat, 22 Sep 2018 15:59:01 -0400 Subject: [PATCH 0487/1663] runtime: remove redundant locking in mcache.refill mcache.refill acquires g.m.locks, which is pointless because the caller itself absolutely must have done so already to prevent ownership of mcache from shifting. Also, mcache.refill's documentation is generally a bit out-of-date, so this cleans this up. Change-Id: Idc8de666fcaf3c3d96006bd23a8f307539587d6c Reviewed-on: https://go-review.googlesource.com/138195 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Rick Hudson --- src/runtime/mcache.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/runtime/mcache.go b/src/runtime/mcache.go index d0b007f915e76..8486f69569ef3 100644 --- a/src/runtime/mcache.go +++ b/src/runtime/mcache.go @@ -101,12 +101,12 @@ func freemcache(c *mcache) { }) } -// Gets a span that has a free object in it and assigns it -// to be the cached span for the given sizeclass. Returns this span. +// refill acquires a new span of span class spc for c. This span will +// have at least one free object. The current span in c must be full. +// +// Must run in a non-preemptible context since otherwise the owner of +// c could change. func (c *mcache) refill(spc spanClass) { - _g_ := getg() - - _g_.m.locks++ // Return the current cached span to the central lists. s := c.alloc[spc] @@ -129,7 +129,6 @@ func (c *mcache) refill(spc spanClass) { } c.alloc[spc] = s - _g_.m.locks-- } func (c *mcache) releaseAll() { From 01e6cfc2a0b2f9e363c6e305b14f3393d06b13b8 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Sun, 23 Sep 2018 19:12:15 -0400 Subject: [PATCH 0488/1663] runtime: don't call mcache.refill on systemstack mcache.refill doesn't need to run on the system stack; it just needs to be non-preemptible. Its only caller, mcache.nextFree, also needs to be non-preemptible, so we can remove the unnecessary systemstack switch. Change-Id: Iba5b3f4444855f1dc134485ba588efff3b54c426 Reviewed-on: https://go-review.googlesource.com/138196 Run-TryBot: Austin Clements Reviewed-by: Rick Hudson TryBot-Result: Gobot Gobot --- src/runtime/malloc.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/runtime/malloc.go b/src/runtime/malloc.go index dd88d353ddc7b..5755c9e263585 100644 --- a/src/runtime/malloc.go +++ b/src/runtime/malloc.go @@ -733,6 +733,9 @@ func nextFreeFast(s *mspan) gclinkptr { // weight allocation. If it is a heavy weight allocation the caller must // determine whether a new GC cycle needs to be started or if the GC is active // whether this goroutine needs to assist the GC. +// +// Must run in a non-preemptible context since otherwise the owner of +// c could change. func (c *mcache) nextFree(spc spanClass) (v gclinkptr, s *mspan, shouldhelpgc bool) { s = c.alloc[spc] shouldhelpgc = false @@ -743,9 +746,7 @@ func (c *mcache) nextFree(spc spanClass) (v gclinkptr, s *mspan, shouldhelpgc bo println("runtime: s.allocCount=", s.allocCount, "s.nelems=", s.nelems) throw("s.allocCount != s.nelems && freeIndex == s.nelems") } - systemstack(func() { - c.refill(spc) - }) + c.refill(spc) shouldhelpgc = true s = c.alloc[spc] From 067bb443af6b44cb026ab182a26d157dbd1b2dd6 Mon Sep 17 00:00:00 2001 From: Katie Hockman Date: Fri, 28 Sep 2018 13:50:57 -0400 Subject: [PATCH 0489/1663] compress: move benchmark text from src/testdata to src/compress/testdata This text is used mainly for benchmark compression testing, and in one net test. The text was prevoiusly in a src/testdata directory, but since that directory would only include one file, the text is moved to the existing src/compression/testdata directory. This does not cause any change to the benchmark results. Updates #27151 Change-Id: I38ab5089dfe744189a970947d15be50ef1d48517 Reviewed-on: https://go-review.googlesource.com/138495 Run-TryBot: Katie Hockman TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- misc/nacl/testzip.proto | 2 -- src/compress/flate/deflate_test.go | 4 ++-- src/compress/flate/reader_test.go | 2 +- src/{ => compress}/testdata/Isaac.Newton-Opticks.txt | 0 src/net/sendfile_test.go | 2 +- 5 files changed, 4 insertions(+), 6 deletions(-) rename src/{ => compress}/testdata/Isaac.Newton-Opticks.txt (100%) diff --git a/misc/nacl/testzip.proto b/misc/nacl/testzip.proto index 1e9279e4e0c13..f15a2ab224636 100644 --- a/misc/nacl/testzip.proto +++ b/misc/nacl/testzip.proto @@ -177,8 +177,6 @@ go src=.. strconv testdata + - testdata - + text template testdata diff --git a/src/compress/flate/deflate_test.go b/src/compress/flate/deflate_test.go index 831be2198cadb..46d917c01ec82 100644 --- a/src/compress/flate/deflate_test.go +++ b/src/compress/flate/deflate_test.go @@ -371,7 +371,7 @@ var deflateInflateStringTests = []deflateInflateStringTest{ [...]int{100018, 50650, 50960, 51150, 50930, 50790, 50790, 50790, 50790, 50790, 43683}, }, { - "../../testdata/Isaac.Newton-Opticks.txt", + "../testdata/Isaac.Newton-Opticks.txt", "Isaac.Newton-Opticks", [...]int{567248, 218338, 198211, 193152, 181100, 175427, 175427, 173597, 173422, 173422, 325240}, }, @@ -654,7 +654,7 @@ func (w *failWriter) Write(b []byte) (int, error) { func TestWriterPersistentError(t *testing.T) { t.Parallel() - d, err := ioutil.ReadFile("../../testdata/Isaac.Newton-Opticks.txt") + d, err := ioutil.ReadFile("../testdata/Isaac.Newton-Opticks.txt") if err != nil { t.Fatalf("ReadFile: %v", err) } diff --git a/src/compress/flate/reader_test.go b/src/compress/flate/reader_test.go index 9d2943a54077c..e1c3dff11ba88 100644 --- a/src/compress/flate/reader_test.go +++ b/src/compress/flate/reader_test.go @@ -28,7 +28,7 @@ var suites = []struct{ name, file string }{ // reasonably compressible. {"Digits", "../testdata/e.txt"}, // Newton is Isaac Newtons's educational text on Opticks. - {"Newton", "../../testdata/Isaac.Newton-Opticks.txt"}, + {"Newton", "../testdata/Isaac.Newton-Opticks.txt"}, } func BenchmarkDecode(b *testing.B) { diff --git a/src/testdata/Isaac.Newton-Opticks.txt b/src/compress/testdata/Isaac.Newton-Opticks.txt similarity index 100% rename from src/testdata/Isaac.Newton-Opticks.txt rename to src/compress/testdata/Isaac.Newton-Opticks.txt diff --git a/src/net/sendfile_test.go b/src/net/sendfile_test.go index f133744a66545..7077cc36e8080 100644 --- a/src/net/sendfile_test.go +++ b/src/net/sendfile_test.go @@ -17,7 +17,7 @@ import ( ) const ( - newton = "../testdata/Isaac.Newton-Opticks.txt" + newton = "../compress/testdata/Isaac.Newton-Opticks.txt" newtonLen = 567198 newtonSHA256 = "d4a9ac22462b35e7821a4f2706c211093da678620a8f9997989ee7cf8d507bbd" ) From 7dda5123d8753cfd1f041e1d1537bb5493cd5e5d Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 28 Sep 2018 10:41:31 -0700 Subject: [PATCH 0490/1663] cmd/go: permit some more x86 compiler options Permit -mssse3, -maes, -mvaes, and various -mavxNNN options. Change-Id: If496df6b84eca37897fd603a6480c9f63e7f7382 Reviewed-on: https://go-review.googlesource.com/138476 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/cmd/go/internal/work/security.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/cmd/go/internal/work/security.go b/src/cmd/go/internal/work/security.go index 2132c5f3e15f4..1a401b8981ec2 100644 --- a/src/cmd/go/internal/work/security.go +++ b/src/cmd/go/internal/work/security.go @@ -89,7 +89,9 @@ var validCompilerFlags = []*regexp.Regexp{ re(`-m32`), re(`-m64`), re(`-m(abi|arch|cpu|fpu|tune)=([^@\-].*)`), + re(`-m(no-)?v?aes`), re(`-marm`), + re(`-m(no-)?avx[0-9a-z]*`), re(`-mfloat-abi=([^@\-].*)`), re(`-mfpmath=[0-9a-z,+]*`), re(`-m(no-)?avx[0-9a-z.]*`), @@ -100,6 +102,7 @@ var validCompilerFlags = []*regexp.Regexp{ re(`-miphoneos-version-min=(.+)`), re(`-mnop-fun-dllimport`), re(`-m(no-)?sse[0-9.]*`), + re(`-m(no-)?ssse3`), re(`-mthumb(-interwork)?`), re(`-mthreads`), re(`-mwindows`), From 1c95d9728aa5c8638db1bbabfb6ae764c4613c68 Mon Sep 17 00:00:00 2001 From: Alex Brainman Date: Sat, 8 Sep 2018 16:05:29 +1000 Subject: [PATCH 0491/1663] os: use FILE_FLAG_OPEN_REPARSE_POINT in SameFile SameFile opens file to discover identifier and volume serial number that uniquely identify the file. SameFile uses Windows CreateFile API to open the file, and that works well for files and directories. But CreateFile always follows symlinks, so SameFile always opens symlink target instead of symlink itself. This CL uses FILE_FLAG_OPEN_REPARSE_POINT flag to adjust CreateFile behavior when handling symlinks. As per https://docs.microsoft.com/en-us/windows/desktop/FileIO/symbolic-link-effects-on-file-systems-functions#createfile-and-createfiletransacted "... If FILE_FLAG_OPEN_REPARSE_POINT is specified and: If an existing file is opened and it is a symbolic link, the handle returned is a handle to the symbolic link. ...". I also added new tests for both issue #21854 and #27225. Issue #27225 is still to be fixed, so skipping the test on windows for the moment. Fixes #21854 Updates #27225 Change-Id: I8aaa13ad66ce3b4074991bb50994d2aeeeaa7c95 Reviewed-on: https://go-review.googlesource.com/134195 Run-TryBot: Alex Brainman Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/os/os_windows_test.go | 62 +-------- src/os/stat_test.go | 276 ++++++++++++++++++++++++++++++++++++++ src/os/types_windows.go | 8 +- 3 files changed, 284 insertions(+), 62 deletions(-) create mode 100644 src/os/stat_test.go diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go index 8984dd2c6623d..c5553694880ee 100644 --- a/src/os/os_windows_test.go +++ b/src/os/os_windows_test.go @@ -895,16 +895,6 @@ func main() { } } -func testIsDir(t *testing.T, path string, fi os.FileInfo) { - t.Helper() - if !fi.IsDir() { - t.Errorf("%q should be a directory", path) - } - if fi.Mode()&os.ModeSymlink != 0 { - t.Errorf("%q should not be a symlink", path) - } -} - func findOneDriveDir() (string, error) { // as per https://stackoverflow.com/questions/42519624/how-to-determine-location-of-onedrive-on-windows-7-and-8-in-c const onedrivekey = `SOFTWARE\Microsoft\OneDrive` @@ -927,57 +917,7 @@ func TestOneDrive(t *testing.T) { if err != nil { t.Skipf("Skipping, because we did not find OneDrive directory: %v", err) } - - // test os.Stat - fi, err := os.Stat(dir) - if err != nil { - t.Fatal(err) - } - testIsDir(t, dir, fi) - - // test os.Lstat - fi, err = os.Lstat(dir) - if err != nil { - t.Fatal(err) - } - testIsDir(t, dir, fi) - - // test os.File.Stat - f, err := os.Open(dir) - if err != nil { - t.Fatal(err) - } - defer f.Close() - - fi, err = f.Stat() - if err != nil { - t.Fatal(err) - } - testIsDir(t, dir, fi) - - // test os.FileInfo returned by os.Readdir - parent, err := os.Open(filepath.Dir(dir)) - if err != nil { - t.Fatal(err) - } - defer parent.Close() - - fis, err := parent.Readdir(-1) - if err != nil { - t.Fatal(err) - } - fi = nil - base := filepath.Base(dir) - for _, fi2 := range fis { - if fi2.Name() == base { - fi = fi2 - break - } - } - if fi == nil { - t.Errorf("failed to find %q in its parent", dir) - } - testIsDir(t, dir, fi) + testDirStats(t, dir) } func TestWindowsDevNullFile(t *testing.T) { diff --git a/src/os/stat_test.go b/src/os/stat_test.go new file mode 100644 index 0000000000000..d59edeb547a16 --- /dev/null +++ b/src/os/stat_test.go @@ -0,0 +1,276 @@ +// Copyright 2018 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. + +package os_test + +import ( + "internal/testenv" + "io/ioutil" + "os" + "path/filepath" + "runtime" + "testing" +) + +// testStatAndLstat verifies that all os.Stat, os.Lstat os.File.Stat and os.Readdir work. +func testStatAndLstat(t *testing.T, path string, isLink bool, statCheck, lstatCheck func(*testing.T, string, os.FileInfo)) { + // test os.Stat + sfi, err := os.Stat(path) + if err != nil { + t.Error(err) + return + } + statCheck(t, path, sfi) + + // test os.Lstat + lsfi, err := os.Lstat(path) + if err != nil { + t.Error(err) + return + } + lstatCheck(t, path, lsfi) + + if isLink { + if os.SameFile(sfi, lsfi) { + t.Errorf("stat and lstat of %q should not be the same", path) + } + } else { + if !os.SameFile(sfi, lsfi) { + t.Errorf("stat and lstat of %q should be the same", path) + } + } + + // test os.File.Stat + f, err := os.Open(path) + if err != nil { + t.Error(err) + return + } + defer f.Close() + + sfi2, err := f.Stat() + if err != nil { + t.Error(err) + return + } + statCheck(t, path, sfi2) + + if !os.SameFile(sfi, sfi2) { + t.Errorf("stat of open %q file and stat of %q should be the same", path, path) + } + + if isLink { + if os.SameFile(sfi2, lsfi) { + t.Errorf("stat of opened %q file and lstat of %q should not be the same", path, path) + } + } else { + if !os.SameFile(sfi2, lsfi) { + t.Errorf("stat of opened %q file and lstat of %q should be the same", path, path) + } + } + + // test os.FileInfo returned by os.Readdir + if len(path) > 0 && os.IsPathSeparator(path[len(path)-1]) { + // skip os.Readdir test of directories with slash at the end + return + } + parentdir := filepath.Dir(path) + parent, err := os.Open(parentdir) + if err != nil { + t.Error(err) + return + } + defer parent.Close() + + fis, err := parent.Readdir(-1) + if err != nil { + t.Error(err) + return + } + var lsfi2 os.FileInfo + base := filepath.Base(path) + for _, fi2 := range fis { + if fi2.Name() == base { + lsfi2 = fi2 + break + } + } + if lsfi2 == nil { + t.Errorf("failed to find %q in its parent", path) + return + } + lstatCheck(t, path, lsfi2) + + if !os.SameFile(lsfi, lsfi2) { + t.Errorf("lstat of %q file in %q directory and %q should be the same", lsfi2.Name(), parentdir, path) + } +} + +// testIsDir verifies that fi refers to directory. +func testIsDir(t *testing.T, path string, fi os.FileInfo) { + t.Helper() + if !fi.IsDir() { + t.Errorf("%q should be a directory", path) + } + if fi.Mode()&os.ModeSymlink != 0 { + t.Errorf("%q should not be a symlink", path) + } +} + +// testIsSymlink verifies that fi refers to symlink. +func testIsSymlink(t *testing.T, path string, fi os.FileInfo) { + t.Helper() + if fi.IsDir() { + t.Errorf("%q should not be a directory", path) + } + if fi.Mode()&os.ModeSymlink == 0 { + t.Errorf("%q should be a symlink", path) + } +} + +// testIsFile verifies that fi refers to file. +func testIsFile(t *testing.T, path string, fi os.FileInfo) { + t.Helper() + if fi.IsDir() { + t.Errorf("%q should not be a directory", path) + } + if fi.Mode()&os.ModeSymlink != 0 { + t.Errorf("%q should not be a symlink", path) + } +} + +func testDirStats(t *testing.T, path string) { + testStatAndLstat(t, path, false, testIsDir, testIsDir) +} + +func testFileStats(t *testing.T, path string) { + testStatAndLstat(t, path, false, testIsFile, testIsFile) +} + +func testSymlinkStats(t *testing.T, path string, isdir bool) { + if isdir { + testStatAndLstat(t, path, true, testIsDir, testIsSymlink) + } else { + testStatAndLstat(t, path, true, testIsFile, testIsSymlink) + } +} + +func testSymlinkSameFile(t *testing.T, path, link string) { + pathfi, err := os.Stat(path) + if err != nil { + t.Error(err) + return + } + + linkfi, err := os.Stat(link) + if err != nil { + t.Error(err) + return + } + if !os.SameFile(pathfi, linkfi) { + t.Errorf("os.Stat(%q) and os.Stat(%q) are not the same file", path, link) + } + + linkfi, err = os.Lstat(link) + if err != nil { + t.Error(err) + return + } + if os.SameFile(pathfi, linkfi) { + t.Errorf("os.Stat(%q) and os.Lstat(%q) are the same file", path, link) + } +} + +func TestDirAndSymlinkStats(t *testing.T) { + testenv.MustHaveSymlink(t) + + tmpdir, err := ioutil.TempDir("", "TestDirAndSymlinkStats") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpdir) + + dir := filepath.Join(tmpdir, "dir") + err = os.Mkdir(dir, 0777) + if err != nil { + t.Fatal(err) + } + testDirStats(t, dir) + + dirlink := filepath.Join(tmpdir, "link") + err = os.Symlink(dir, dirlink) + if err != nil { + t.Fatal(err) + } + testSymlinkStats(t, dirlink, true) + testSymlinkSameFile(t, dir, dirlink) +} + +func TestFileAndSymlinkStats(t *testing.T) { + testenv.MustHaveSymlink(t) + + tmpdir, err := ioutil.TempDir("", "TestFileAndSymlinkStats") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpdir) + + file := filepath.Join(tmpdir, "file") + err = ioutil.WriteFile(file, []byte(""), 0644) + if err != nil { + t.Fatal(err) + } + testFileStats(t, file) + + filelink := filepath.Join(tmpdir, "link") + err = os.Symlink(file, filelink) + if err != nil { + t.Fatal(err) + } + testSymlinkStats(t, filelink, false) + testSymlinkSameFile(t, file, filelink) +} + +// see issue 27225 for details +func TestSymlinkWithTrailingSlash(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("skipping on windows; issue 27225") + } + + testenv.MustHaveSymlink(t) + + tmpdir, err := ioutil.TempDir("", "TestSymlinkWithTrailingSlash") + if err != nil { + t.Fatal(err) + } + defer os.RemoveAll(tmpdir) + + dir := filepath.Join(tmpdir, "dir") + err = os.Mkdir(dir, 0777) + if err != nil { + t.Fatal(err) + } + dirlink := filepath.Join(tmpdir, "link") + err = os.Symlink(dir, dirlink) + if err != nil { + t.Fatal(err) + } + dirlinkWithSlash := dirlink + string(os.PathSeparator) + + testDirStats(t, dirlinkWithSlash) + + fi1, err := os.Stat(dir) + if err != nil { + t.Error(err) + return + } + fi2, err := os.Stat(dirlinkWithSlash) + if err != nil { + t.Error(err) + return + } + if !os.SameFile(fi1, fi2) { + t.Errorf("os.Stat(%q) and os.Stat(%q) are not the same file", dir, dirlinkWithSlash) + } +} diff --git a/src/os/types_windows.go b/src/os/types_windows.go index f3297c033856a..7ebeec50eff4a 100644 --- a/src/os/types_windows.go +++ b/src/os/types_windows.go @@ -211,7 +211,13 @@ func (fs *fileStat) loadFileId() error { if err != nil { return err } - h, err := syscall.CreateFile(pathp, 0, 0, nil, syscall.OPEN_EXISTING, syscall.FILE_FLAG_BACKUP_SEMANTICS, 0) + attrs := uint32(syscall.FILE_FLAG_BACKUP_SEMANTICS) + if fs.isSymlink() { + // Use FILE_FLAG_OPEN_REPARSE_POINT, otherwise CreateFile will follow symlink. + // See https://docs.microsoft.com/en-us/windows/desktop/FileIO/symbolic-link-effects-on-file-systems-functions#createfile-and-createfiletransacted + attrs |= syscall.FILE_FLAG_OPEN_REPARSE_POINT + } + h, err := syscall.CreateFile(pathp, 0, 0, nil, syscall.OPEN_EXISTING, attrs, 0) if err != nil { return err } From d1f7470c217691dca4e339c77bf8c4175b8db168 Mon Sep 17 00:00:00 2001 From: QtRoS Date: Tue, 25 Sep 2018 00:01:39 +0300 Subject: [PATCH 0492/1663] path/filepath: fix Windows-specific Clean bug Fixes #27791 Change-Id: I762fa663379086c24cb4ddc8233a2c0a82b1238e Reviewed-on: https://go-review.googlesource.com/137055 Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot Reviewed-by: Alex Brainman --- src/path/filepath/path.go | 11 ++++++++--- src/path/filepath/path_test.go | 3 +++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go index aba1717e7d5e0..bbb90306a7f38 100644 --- a/src/path/filepath/path.go +++ b/src/path/filepath/path.go @@ -96,14 +96,19 @@ func Clean(path string) string { } return originalPath + "." } + + n := len(path) + if volLen > 2 && n == 1 && os.IsPathSeparator(path[0]) { + // UNC volume name with trailing slash. + return FromSlash(originalPath[:volLen]) + } rooted := os.IsPathSeparator(path[0]) // Invariants: // reading from path; r is index of next byte to process. - // writing to buf; w is index of next byte to write. - // dotdot is index in buf where .. must stop, either because + // writing to out; w is index of next byte to write. + // dotdot is index in out where .. must stop, either because // it is the leading slash or it is a leading ../../.. prefix. - n := len(path) out := lazybuf{path: path, volAndPath: originalPath, volLen: volLen} r, dotdot := 0, 0 if rooted { diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index e1b5ad1d40c9c..eddae4755be6d 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -92,6 +92,9 @@ var wincleantests = []PathTest{ {`//host/share/foo/../baz`, `\\host\share\baz`}, {`\\a\b\..\c`, `\\a\b\c`}, {`\\a\b`, `\\a\b`}, + {`\\a\b\`, `\\a\b`}, + {`\\folder\share\foo`, `\\folder\share\foo`}, + {`\\folder\share\foo\`, `\\folder\share\foo`}, } func TestClean(t *testing.T) { From a0e7f12771c2e84e626dcf5e30da5d62a3b1adf6 Mon Sep 17 00:00:00 2001 From: Jake B Date: Sat, 29 Sep 2018 04:06:00 +0000 Subject: [PATCH 0493/1663] misc/wasm: add polyfill for TextEncoder/TextDecoder for Edge support Edge supports WASM but not TextEncoder or TextDecoder. This PR adds a polyfill to `misc/wasm/wasm_exec.js` to fix this. Fixes #27295 Change-Id: Ie35ee5604529b170a5dc380eb286f71bdd691d3e GitHub-Last-Rev: a587edae2806e1ca9b6be1c5dfd8824568373bdb GitHub-Pull-Request: golang/go#27296 Reviewed-on: https://go-review.googlesource.com/131718 Reviewed-by: Agniva De Sarker Reviewed-by: Richard Musiol --- misc/wasm/wasm_exec.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/misc/wasm/wasm_exec.html b/misc/wasm/wasm_exec.html index f5e21e40f335b..7ccdf0abd24f3 100644 --- a/misc/wasm/wasm_exec.html +++ b/misc/wasm/wasm_exec.html @@ -12,6 +12,11 @@ + + + + + + +
      Loading plot...
      + + +` diff --git a/src/internal/traceparser/gc.go b/src/internal/traceparser/gc.go new file mode 100644 index 0000000000000..7e349308d79dd --- /dev/null +++ b/src/internal/traceparser/gc.go @@ -0,0 +1,248 @@ +// 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. + +package traceparser + +import ( + "strings" + "time" +) + +// MutatorUtil is a change in mutator utilization at a particular +// time. Mutator utilization functions are represented as a +// time-ordered []MutatorUtil. +type MutatorUtil struct { + Time int64 + // Util is the mean mutator utilization starting at Time. This + // is in the range [0, 1]. + Util float64 +} + +// MutatorUtilization returns the mutator utilization function for the +// given trace. This function will always end with 0 utilization. The +// bounds of the function are implicit in the first and last event; +// outside of these bounds the function is undefined. +func (p *Parsed) MutatorUtilization() []MutatorUtil { + events := p.Events + if len(events) == 0 { + return nil + } + + gomaxprocs, gcPs, stw := 1, 0, 0 + out := []MutatorUtil{{events[0].Ts, 1}} + assists := map[uint64]bool{} + block := map[uint64]*Event{} + bgMark := map[uint64]bool{} + for _, ev := range events { + switch ev.Type { + case EvGomaxprocs: + gomaxprocs = int(ev.Args[0]) + case EvGCSTWStart: + stw++ + case EvGCSTWDone: + stw-- + case EvGCMarkAssistStart: + gcPs++ + assists[ev.G] = true + case EvGCMarkAssistDone: + gcPs-- + delete(assists, ev.G) + case EvGoStartLabel: + if strings.HasPrefix(ev.SArgs[0], "GC ") && ev.SArgs[0] != "GC (idle)" { + // Background mark worker. + bgMark[ev.G] = true + gcPs++ + } + fallthrough + case EvGoStart: + if assists[ev.G] { + // Unblocked during assist. + gcPs++ + } + block[ev.G] = ev.Link + default: + if ev != block[ev.G] { + continue + } + + if assists[ev.G] { + // Blocked during assist. + gcPs-- + } + if bgMark[ev.G] { + // Background mark worker done. + gcPs-- + delete(bgMark, ev.G) + } + delete(block, ev.G) + } + + ps := gcPs + if stw > 0 { + ps = gomaxprocs + } + mu := MutatorUtil{ev.Ts, 1 - float64(ps)/float64(gomaxprocs)} + if mu.Util == out[len(out)-1].Util { + // No change. + continue + } + if mu.Time == out[len(out)-1].Time { + // Take the lowest utilization at a time stamp. + if mu.Util < out[len(out)-1].Util { + out[len(out)-1] = mu + } + } else { + out = append(out, mu) + } + } + + // Add final 0 utilization event. This is important to mark + // the end of the trace. The exact value shouldn't matter + // since no window should extend beyond this, but using 0 is + // symmetric with the start of the trace. + endTime := events[len(events)-1].Ts + if out[len(out)-1].Time == endTime { + out[len(out)-1].Util = 0 + } else { + out = append(out, MutatorUtil{endTime, 0}) + } + + return out +} + +// totalUtil is total utilization, measured in nanoseconds. This is a +// separate type primarily to distinguish it from mean utilization, +// which is also a float64. +type totalUtil float64 + +func totalUtilOf(meanUtil float64, dur int64) totalUtil { + return totalUtil(meanUtil * float64(dur)) +} + +// mean returns the mean utilization over dur. +func (u totalUtil) mean(dur time.Duration) float64 { + return float64(u) / float64(dur) +} + +// An MMUCurve is the minimum mutator utilization curve across +// multiple window sizes. +type MMUCurve struct { + util []MutatorUtil + // sums[j] is the cumulative sum of util[:j]. + sums []totalUtil +} + +// NewMMUCurve returns an MMU curve for the given mutator utilization +// function. +func NewMMUCurve(util []MutatorUtil) *MMUCurve { + // Compute cumulative sum. + sums := make([]totalUtil, len(util)) + var prev MutatorUtil + var sum totalUtil + for j, u := range util { + sum += totalUtilOf(prev.Util, u.Time-prev.Time) + sums[j] = sum + prev = u + } + + return &MMUCurve{util, sums} +} + +// MMU returns the minimum mutator utilization for the given time +// window. This is the minimum utilization for all windows of this +// duration across the execution. The returned value is in the range +// [0, 1]. +func (c *MMUCurve) MMU(window time.Duration) (mmu float64) { + if window <= 0 { + return 0 + } + util := c.util + if max := time.Duration(util[len(util)-1].Time - util[0].Time); window > max { + window = max + } + + mmu = 1.0 + + // We think of the mutator utilization over time as the + // box-filtered utilization function, which we call the + // "windowed mutator utilization function". The resulting + // function is continuous and piecewise linear (unless + // window==0, which we handle elsewhere), where the boundaries + // between segments occur when either edge of the window + // encounters a change in the instantaneous mutator + // utilization function. Hence, the minimum of this function + // will always occur when one of the edges of the window + // aligns with a utilization change, so these are the only + // points we need to consider. + // + // We compute the mutator utilization function incrementally + // by tracking the integral from t=0 to the left edge of the + // window and to the right edge of the window. + left := integrator{c, 0} + right := left + time := util[0].Time + for { + // Advance edges to time and time+window. + mu := (right.advance(time+int64(window)) - left.advance(time)).mean(window) + if mu < mmu { + mmu = mu + if mmu == 0 { + // The minimum can't go any lower than + // zero, so stop early. + break + } + } + + // Advance the window to the next time where either + // the left or right edge of the window encounters a + // change in the utilization curve. + if t1, t2 := left.next(time), right.next(time+int64(window))-int64(window); t1 < t2 { + time = t1 + } else { + time = t2 + } + if time > util[len(util)-1].Time-int64(window) { + break + } + } + return mmu +} + +// An integrator tracks a position in a utilization function and +// integrates it. +type integrator struct { + u *MMUCurve + // pos is the index in u.util of the current time's non-strict + // predecessor. + pos int +} + +// advance returns the integral of the utilization function from 0 to +// time. advance must be called on monotonically increasing values of +// times. +func (in *integrator) advance(time int64) totalUtil { + util, pos := in.u.util, in.pos + // Advance pos until pos+1 is time's strict successor (making + // pos time's non-strict predecessor). + for pos+1 < len(util) && util[pos+1].Time <= time { + pos++ + } + in.pos = pos + var partial totalUtil + if time != util[pos].Time { + partial = totalUtilOf(util[pos].Util, time-util[pos].Time) + } + return in.u.sums[pos] + partial +} + +// next returns the smallest time t' > time of a change in the +// utilization function. +func (in *integrator) next(time int64) int64 { + for _, u := range in.u.util[in.pos:] { + if u.Time > time { + return u.Time + } + } + return 1<<63 - 1 +} diff --git a/src/internal/traceparser/gc_test.go b/src/internal/traceparser/gc_test.go new file mode 100644 index 0000000000000..821b0f217cb44 --- /dev/null +++ b/src/internal/traceparser/gc_test.go @@ -0,0 +1,158 @@ +// 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. + +package traceparser + +import ( + "math" + "testing" + "time" +) + +// aeq returns true if x and y are equal up to 8 digits (1 part in 100 +// million). +func aeq(x, y float64) bool { + if x < 0 && y < 0 { + x, y = -x, -y + } + const digits = 8 + factor := 1 - math.Pow(10, -digits+1) + return x*factor <= y && y*factor <= x +} + +func TestMMU(t *testing.T) { + t.Parallel() + + // MU + // 1.0 ***** ***** ***** + // 0.5 * * * * + // 0.0 ***** ***** + // 0 1 2 3 4 5 + util := []MutatorUtil{ + {0e9, 1}, + {1e9, 0}, + {2e9, 1}, + {3e9, 0}, + {4e9, 1}, + {5e9, 0}, + } + mmuCurve := NewMMUCurve(util) + + for _, test := range []struct { + window time.Duration + want float64 + }{ + {0, 0}, + {time.Millisecond, 0}, + {time.Second, 0}, + {2 * time.Second, 0.5}, + {3 * time.Second, 1 / 3.0}, + {4 * time.Second, 0.5}, + {5 * time.Second, 3 / 5.0}, + {6 * time.Second, 3 / 5.0}, + } { + if got := mmuCurve.MMU(test.window); !aeq(test.want, got) { + t.Errorf("for %s window, want mu = %f, got %f", test.window, test.want, got) + } + } +} + +func TestMMUTrace(t *testing.T) { + t.Parallel() + + p, err := New("../trace/testdata/stress_1_10_good") + if err != nil { + t.Fatalf("failed to read input file: %v", err) + } + if err := p.Parse(0, 1<<62, nil); err != nil { + t.Fatalf("failed to parse trace: %s", err) + } + mu := p.MutatorUtilization() + mmuCurve := NewMMUCurve(mu) + + // Test the optimized implementation against the "obviously + // correct" implementation. + for window := time.Nanosecond; window < 10*time.Second; window *= 10 { + want := mmuSlow(mu, window) + got := mmuCurve.MMU(window) + if !aeq(want, got) { + t.Errorf("want %f, got %f mutator utilization in window %s", want, got, window) + } + } +} + +func BenchmarkMMU(b *testing.B) { + p, err := New("../trace/testdata/stress_1_10_good") + if err != nil { + b.Fatalf("failed to read input file: %v", err) + } + if err := p.Parse(0, 1<<62, nil); err != nil { + b.Fatalf("failed to parse trace: %s", err) + } + mu := p.MutatorUtilization() + b.ResetTimer() + + for i := 0; i < b.N; i++ { + mmuCurve := NewMMUCurve(mu) + xMin, xMax := time.Microsecond, time.Second + logMin, logMax := math.Log(float64(xMin)), math.Log(float64(xMax)) + const samples = 100 + for i := 0; i < samples; i++ { + window := time.Duration(math.Exp(float64(i)/(samples-1)*(logMax-logMin) + logMin)) + mmuCurve.MMU(window) + } + } +} + +func mmuSlow(util []MutatorUtil, window time.Duration) (mmu float64) { + if max := time.Duration(util[len(util)-1].Time - util[0].Time); window > max { + window = max + } + + mmu = 1.0 + + // muInWindow returns the mean mutator utilization between + // util[0].Time and end. + muInWindow := func(util []MutatorUtil, end int64) float64 { + total := 0.0 + var prevU MutatorUtil + for _, u := range util { + if u.Time > end { + total += prevU.Util * float64(end-prevU.Time) + break + } + total += prevU.Util * float64(u.Time-prevU.Time) + prevU = u + } + return total / float64(end-util[0].Time) + } + update := func() { + for i, u := range util { + if u.Time+int64(window) > util[len(util)-1].Time { + break + } + mmu = math.Min(mmu, muInWindow(util[i:], u.Time+int64(window))) + } + } + + // Consider all left-aligned windows. + update() + // Reverse the trace. Slightly subtle because each MutatorUtil + // is a *change*. + rutil := make([]MutatorUtil, len(util)) + if util[len(util)-1].Util != 0 { + panic("irreversible trace") + } + for i, u := range util { + util1 := 0.0 + if i != 0 { + util1 = util[i-1].Util + } + rutil[len(rutil)-i-1] = MutatorUtil{Time: -u.Time, Util: util1} + } + util = rutil + // Consider all right-aligned windows. + update() + return +} From c6c602a92612a855d8eb2f649f3dff75bb5fb9ad Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 28 Aug 2017 12:29:07 -0400 Subject: [PATCH 0966/1663] internal/trace: use MU slope to optimize MMU This commit speeds up MMU construction by ~10X (and reduces the number of windows considered by ~20X) by using an observation about the maximum slope of the windowed mutator utilization function to advance the window time in jumps if the window's current mean mutator utilization is much larger than the current minimum. Change-Id: If3cba5da0c4adc37b568740f940793e491e96a51 Reviewed-on: https://go-review.googlesource.com/c/60791 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim --- src/internal/traceparser/gc.go | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/internal/traceparser/gc.go b/src/internal/traceparser/gc.go index 7e349308d79dd..66c68cb450241 100644 --- a/src/internal/traceparser/gc.go +++ b/src/internal/traceparser/gc.go @@ -194,6 +194,12 @@ func (c *MMUCurve) MMU(window time.Duration) (mmu float64) { } } + // The maximum slope of the windowed mutator + // utilization function is 1/window, so we can always + // advance the time by at least (mu - mmu) * window + // without dropping below mmu. + minTime := time + int64((mu-mmu)*float64(window)) + // Advance the window to the next time where either // the left or right edge of the window encounters a // change in the utilization curve. @@ -202,6 +208,9 @@ func (c *MMUCurve) MMU(window time.Duration) (mmu float64) { } else { time = t2 } + if time < minTime { + time = minTime + } if time > util[len(util)-1].Time-int64(window) { break } @@ -225,8 +234,28 @@ func (in *integrator) advance(time int64) totalUtil { util, pos := in.u.util, in.pos // Advance pos until pos+1 is time's strict successor (making // pos time's non-strict predecessor). - for pos+1 < len(util) && util[pos+1].Time <= time { - pos++ + // + // Very often, this will be nearby, so we optimize that case, + // but it may be arbitrarily far away, so we handled that + // efficiently, too. + const maxSeq = 8 + if pos+maxSeq < len(util) && util[pos+maxSeq].Time > time { + // Nearby. Use a linear scan. + for pos+1 < len(util) && util[pos+1].Time <= time { + pos++ + } + } else { + // Far. Binary search for time's strict successor. + l, r := pos, len(util) + for l < r { + h := int(uint(l+r) >> 1) + if util[h].Time <= time { + l = h + 1 + } else { + r = h + } + } + pos = l - 1 // Non-strict predecessor. } in.pos = pos var partial totalUtil From 52ee654b25970a0b8c0ce9d2c8eda604df2026bb Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 8 Aug 2017 18:15:32 -0400 Subject: [PATCH 0967/1663] internal/trace: use banding to optimize MMU computation This further optimizes MMU construction by first computing a low-resolution summary of the utilization curve. This "band" summary lets us compute the worst-possible window starting in each of these low-resolution bands (even without knowing where in the band the window falls). This in turn lets us compute precise minimum mutator utilization only in the worst low-resolution bands until we can show that any remaining bands can't possibly contain a worse window. This slows down MMU construction for small traces, but these are reasonably fast to compute either way. For large traces (e.g., 150,000+ utilization changes) it's significantly faster. Change-Id: Ie66454e71f3fb06be3f6173b6d91ad75c61bda48 Reviewed-on: https://go-review.googlesource.com/c/60792 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim --- src/go/build/deps_test.go | 2 +- src/internal/traceparser/gc.go | 182 ++++++++++++++++++++++++++++++++- 2 files changed, 179 insertions(+), 5 deletions(-) diff --git a/src/go/build/deps_test.go b/src/go/build/deps_test.go index ec6e6b4890c28..d632954d0c4b3 100644 --- a/src/go/build/deps_test.go +++ b/src/go/build/deps_test.go @@ -273,7 +273,7 @@ var pkgDeps = map[string][]string{ "internal/goroot": {"L4", "OS"}, "internal/singleflight": {"sync"}, "internal/trace": {"L4", "OS"}, - "internal/traceparser": {"L4", "internal/traceparser/filebuf"}, + "internal/traceparser": {"L4", "internal/traceparser/filebuf", "container/heap"}, "internal/traceparser/filebuf": {"L4", "OS"}, "math/big": {"L4"}, "mime": {"L4", "OS", "syscall", "internal/syscall/windows/registry"}, diff --git a/src/internal/traceparser/gc.go b/src/internal/traceparser/gc.go index 66c68cb450241..0be78e71e3b95 100644 --- a/src/internal/traceparser/gc.go +++ b/src/internal/traceparser/gc.go @@ -5,6 +5,8 @@ package traceparser import ( + "container/heap" + "math" "strings" "time" ) @@ -131,6 +133,24 @@ type MMUCurve struct { util []MutatorUtil // sums[j] is the cumulative sum of util[:j]. sums []totalUtil + // bands summarizes util in non-overlapping bands of duration + // bandDur. + bands []mmuBand + // bandDur is the duration of each band. + bandDur int64 +} + +type mmuBand struct { + // minUtil is the minimum instantaneous mutator utilization in + // this band. + minUtil float64 + // cumUtil is the cumulative total mutator utilization between + // time 0 and the left edge of this band. + cumUtil totalUtil + + // integrator is the integrator for the left edge of this + // band. + integrator integrator } // NewMMUCurve returns an MMU curve for the given mutator utilization @@ -146,7 +166,77 @@ func NewMMUCurve(util []MutatorUtil) *MMUCurve { prev = u } - return &MMUCurve{util, sums} + // Divide the utilization curve up into equal size + // non-overlapping "bands" and compute a summary for each of + // these bands. + // + // Compute the duration of each band. + numBands := 1000 + if numBands > len(util) { + // There's no point in having lots of bands if there + // aren't many events. + numBands = len(util) + } + dur := util[len(util)-1].Time - util[0].Time + bandDur := (dur + int64(numBands) - 1) / int64(numBands) + if bandDur < 1 { + bandDur = 1 + } + // Compute the bands. There are numBands+1 bands in order to + // record the final cumulative sum. + bands := make([]mmuBand, numBands+1) + c := MMUCurve{util, sums, bands, bandDur} + leftSum := integrator{&c, 0} + for i := range bands { + startTime, endTime := c.bandTime(i) + cumUtil := leftSum.advance(startTime) + predIdx := leftSum.pos + minUtil := 1.0 + for i := predIdx; i < len(util) && util[i].Time < endTime; i++ { + minUtil = math.Min(minUtil, util[i].Util) + } + bands[i] = mmuBand{minUtil, cumUtil, leftSum} + } + + return &c +} + +func (c *MMUCurve) bandTime(i int) (start, end int64) { + start = int64(i)*c.bandDur + c.util[0].Time + end = start + c.bandDur + return +} + +type bandUtil struct { + // Band index + i int + // Lower bound of mutator utilization for all windows + // with a left edge in this band. + utilBound float64 +} + +type bandUtilHeap []bandUtil + +func (h bandUtilHeap) Len() int { + return len(h) +} + +func (h bandUtilHeap) Less(i, j int) bool { + return h[i].utilBound < h[j].utilBound +} + +func (h bandUtilHeap) Swap(i, j int) { + h[i], h[j] = h[j], h[i] +} + +func (h *bandUtilHeap) Push(x interface{}) { + *h = append(*h, x.(bandUtil)) +} + +func (h *bandUtilHeap) Pop() interface{} { + x := (*h)[len(*h)-1] + *h = (*h)[:len(*h)-1] + return x } // MMU returns the minimum mutator utilization for the given time @@ -162,7 +252,88 @@ func (c *MMUCurve) MMU(window time.Duration) (mmu float64) { window = max } + bandU := bandUtilHeap(c.mkBandUtil(window)) + + // Process bands from lowest utilization bound to highest. + heap.Init(&bandU) + + // Refine each band into a precise window and MMU until the + // precise MMU is less than the lowest band bound. mmu = 1.0 + for len(bandU) > 0 && bandU[0].utilBound < mmu { + mmu = c.bandMMU(bandU[0].i, window, mmu) + heap.Pop(&bandU) + } + return mmu +} + +func (c *MMUCurve) mkBandUtil(window time.Duration) []bandUtil { + // For each band, compute the worst-possible total mutator + // utilization for all windows that start in that band. + + // minBands is the minimum number of bands a window can span + // and maxBands is the maximum number of bands a window can + // span in any alignment. + minBands := int((int64(window) + c.bandDur - 1) / c.bandDur) + maxBands := int((int64(window) + 2*(c.bandDur-1)) / c.bandDur) + if window > 1 && maxBands < 2 { + panic("maxBands < 2") + } + tailDur := int64(window) % c.bandDur + nUtil := len(c.bands) - maxBands + 1 + if nUtil < 0 { + nUtil = 0 + } + bandU := make([]bandUtil, nUtil) + for i := range bandU { + // To compute the worst-case MU, we assume the minimum + // for any bands that are only partially overlapped by + // some window and the mean for any bands that are + // completely covered by all windows. + var util totalUtil + + // Find the lowest and second lowest of the partial + // bands. + l := c.bands[i].minUtil + r1 := c.bands[i+minBands-1].minUtil + r2 := c.bands[i+maxBands-1].minUtil + minBand := math.Min(l, math.Min(r1, r2)) + // Assume the worst window maximally overlaps the + // worst minimum and then the rest overlaps the second + // worst minimum. + if minBands == 1 { + util += totalUtilOf(minBand, int64(window)) + } else { + util += totalUtilOf(minBand, c.bandDur) + midBand := 0.0 + switch { + case minBand == l: + midBand = math.Min(r1, r2) + case minBand == r1: + midBand = math.Min(l, r2) + case minBand == r2: + midBand = math.Min(l, r1) + } + util += totalUtilOf(midBand, tailDur) + } + + // Add the total mean MU of bands that are completely + // overlapped by all windows. + if minBands > 2 { + util += c.bands[i+minBands-1].cumUtil - c.bands[i+1].cumUtil + } + + bandU[i] = bandUtil{i, util.mean(window)} + } + + return bandU +} + +// bandMMU computes the precise minimum mutator utilization for +// windows with a left edge in band bandIdx. +func (c *MMUCurve) bandMMU(bandIdx int, window time.Duration, curMMU float64) (mmu float64) { + util := c.util + mmu = curMMU // We think of the mutator utilization over time as the // box-filtered utilization function, which we call the @@ -179,9 +350,12 @@ func (c *MMUCurve) MMU(window time.Duration) (mmu float64) { // We compute the mutator utilization function incrementally // by tracking the integral from t=0 to the left edge of the // window and to the right edge of the window. - left := integrator{c, 0} + left := c.bands[bandIdx].integrator right := left - time := util[0].Time + time, endTime := c.bandTime(bandIdx) + if utilEnd := util[len(util)-1].Time - int64(window); utilEnd < endTime { + endTime = utilEnd + } for { // Advance edges to time and time+window. mu := (right.advance(time+int64(window)) - left.advance(time)).mean(window) @@ -211,7 +385,7 @@ func (c *MMUCurve) MMU(window time.Duration) (mmu float64) { if time < minTime { time = minTime } - if time > util[len(util)-1].Time-int64(window) { + if time >= endTime { break } } From cbe04e8d70c32b9477ebcde5265bc17cc41af4a7 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Wed, 26 Jul 2017 12:21:15 -0400 Subject: [PATCH 0968/1663] internal/trace: track worst N mutator utilization windows This will let the trace viewer show specifically when poor utilization happened and link to specific instances in the trace. Change-Id: I1f03a0f9d9a7570009bb15762e7b8b6f215e9423 Reviewed-on: https://go-review.googlesource.com/c/60793 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim --- src/internal/traceparser/gc.go | 151 ++++++++++++++++++++++++---- src/internal/traceparser/gc_test.go | 32 ++++-- 2 files changed, 157 insertions(+), 26 deletions(-) diff --git a/src/internal/traceparser/gc.go b/src/internal/traceparser/gc.go index 0be78e71e3b95..313e23edf6efd 100644 --- a/src/internal/traceparser/gc.go +++ b/src/internal/traceparser/gc.go @@ -7,6 +7,7 @@ package traceparser import ( "container/heap" "math" + "sort" "strings" "time" ) @@ -239,13 +240,135 @@ func (h *bandUtilHeap) Pop() interface{} { return x } +// UtilWindow is a specific window at Time. +type UtilWindow struct { + Time int64 + // MutatorUtil is the mean mutator utilization in this window. + MutatorUtil float64 +} + +type utilHeap []UtilWindow + +func (h utilHeap) Len() int { + return len(h) +} + +func (h utilHeap) Less(i, j int) bool { + if h[i].MutatorUtil != h[j].MutatorUtil { + return h[i].MutatorUtil > h[j].MutatorUtil + } + return h[i].Time > h[j].Time +} + +func (h utilHeap) Swap(i, j int) { + h[i], h[j] = h[j], h[i] +} + +func (h *utilHeap) Push(x interface{}) { + *h = append(*h, x.(UtilWindow)) +} + +func (h *utilHeap) Pop() interface{} { + x := (*h)[len(*h)-1] + *h = (*h)[:len(*h)-1] + return x +} + +// An accumulator collects different MMU-related statistics depending +// on what's desired. +type accumulator struct { + mmu float64 + + // bound is the mutator utilization bound where adding any + // mutator utilization above this bound cannot affect the + // accumulated statistics. + bound float64 + + // Worst N window tracking + nWorst int + wHeap utilHeap +} + +// addMU records mutator utilization mu over the given window starting +// at time. +// +// It returns true if further calls to addMU would be pointless. +func (acc *accumulator) addMU(time int64, mu float64, window time.Duration) bool { + if mu < acc.mmu { + acc.mmu = mu + } + acc.bound = acc.mmu + + if acc.nWorst == 0 { + // If the minimum has reached zero, it can't go any + // lower, so we can stop early. + return mu == 0 + } + + // Consider adding this window to the n worst. + if len(acc.wHeap) < acc.nWorst || mu < acc.wHeap[0].MutatorUtil { + // This window is lower than the K'th worst window. + // + // Check if there's any overlapping window + // already in the heap and keep whichever is + // worse. + for i, ui := range acc.wHeap { + if time+int64(window) > ui.Time && ui.Time+int64(window) > time { + if ui.MutatorUtil <= mu { + // Keep the first window. + goto keep + } else { + // Replace it with this window. + heap.Remove(&acc.wHeap, i) + break + } + } + } + + heap.Push(&acc.wHeap, UtilWindow{time, mu}) + if len(acc.wHeap) > acc.nWorst { + heap.Pop(&acc.wHeap) + } + keep: + } + if len(acc.wHeap) < acc.nWorst { + // We don't have N windows yet, so keep accumulating. + acc.bound = 1.0 + } else { + // Anything above the least worst window has no effect. + acc.bound = math.Max(acc.bound, acc.wHeap[0].MutatorUtil) + } + + // If we've found enough 0 utilizations, we can stop immediately. + return len(acc.wHeap) == acc.nWorst && acc.wHeap[0].MutatorUtil == 0 +} + // MMU returns the minimum mutator utilization for the given time // window. This is the minimum utilization for all windows of this // duration across the execution. The returned value is in the range // [0, 1]. func (c *MMUCurve) MMU(window time.Duration) (mmu float64) { + acc := accumulator{mmu: 1.0, bound: 1.0} + c.mmu(window, &acc) + return acc.mmu +} + +// Examples returns n specific examples of the lowest mutator +// utilization for the given window size. The returned windows will be +// disjoint (otherwise there would be a huge number of +// mostly-overlapping windows at the single lowest point). There are +// no guarantees on which set of disjoint windows this returns. +func (c *MMUCurve) Examples(window time.Duration, n int) (worst []UtilWindow) { + acc := accumulator{mmu: 1.0, bound: 1.0, nWorst: n} + c.mmu(window, &acc) + sort.Sort(sort.Reverse(acc.wHeap)) + return ([]UtilWindow)(acc.wHeap) +} + +func (c *MMUCurve) mmu(window time.Duration, acc *accumulator) { if window <= 0 { - return 0 + acc.mmu = 0 + return } util := c.util if max := time.Duration(util[len(util)-1].Time - util[0].Time); window > max { @@ -257,14 +380,13 @@ func (c *MMUCurve) MMU(window time.Duration) (mmu float64) { // Process bands from lowest utilization bound to highest. heap.Init(&bandU) - // Refine each band into a precise window and MMU until the - // precise MMU is less than the lowest band bound. - mmu = 1.0 - for len(bandU) > 0 && bandU[0].utilBound < mmu { - mmu = c.bandMMU(bandU[0].i, window, mmu) + // Refine each band into a precise window and MMU until + // refining the next lowest band can no longer affect the MMU + // or windows. + for len(bandU) > 0 && bandU[0].utilBound < acc.bound { + c.bandMMU(bandU[0].i, window, acc) heap.Pop(&bandU) } - return mmu } func (c *MMUCurve) mkBandUtil(window time.Duration) []bandUtil { @@ -331,9 +453,8 @@ func (c *MMUCurve) mkBandUtil(window time.Duration) []bandUtil { // bandMMU computes the precise minimum mutator utilization for // windows with a left edge in band bandIdx. -func (c *MMUCurve) bandMMU(bandIdx int, window time.Duration, curMMU float64) (mmu float64) { +func (c *MMUCurve) bandMMU(bandIdx int, window time.Duration, acc *accumulator) { util := c.util - mmu = curMMU // We think of the mutator utilization over time as the // box-filtered utilization function, which we call the @@ -359,20 +480,15 @@ func (c *MMUCurve) bandMMU(bandIdx int, window time.Duration, curMMU float64) (m for { // Advance edges to time and time+window. mu := (right.advance(time+int64(window)) - left.advance(time)).mean(window) - if mu < mmu { - mmu = mu - if mmu == 0 { - // The minimum can't go any lower than - // zero, so stop early. - break - } + if acc.addMU(time, mu, window) { + break } // The maximum slope of the windowed mutator // utilization function is 1/window, so we can always // advance the time by at least (mu - mmu) * window // without dropping below mmu. - minTime := time + int64((mu-mmu)*float64(window)) + minTime := time + int64((mu-acc.bound)*float64(window)) // Advance the window to the next time where either // the left or right edge of the window encounters a @@ -389,7 +505,6 @@ func (c *MMUCurve) bandMMU(bandIdx int, window time.Duration, curMMU float64) (m break } } - return mmu } // An integrator tracks a position in a utilization function and diff --git a/src/internal/traceparser/gc_test.go b/src/internal/traceparser/gc_test.go index 821b0f217cb44..65772be7172c4 100644 --- a/src/internal/traceparser/gc_test.go +++ b/src/internal/traceparser/gc_test.go @@ -42,19 +42,35 @@ func TestMMU(t *testing.T) { for _, test := range []struct { window time.Duration want float64 + worst []float64 }{ - {0, 0}, - {time.Millisecond, 0}, - {time.Second, 0}, - {2 * time.Second, 0.5}, - {3 * time.Second, 1 / 3.0}, - {4 * time.Second, 0.5}, - {5 * time.Second, 3 / 5.0}, - {6 * time.Second, 3 / 5.0}, + {0, 0, []float64{}}, + {time.Millisecond, 0, []float64{0, 0}}, + {time.Second, 0, []float64{0, 0}}, + {2 * time.Second, 0.5, []float64{0.5, 0.5}}, + {3 * time.Second, 1 / 3.0, []float64{1 / 3.0}}, + {4 * time.Second, 0.5, []float64{0.5}}, + {5 * time.Second, 3 / 5.0, []float64{3 / 5.0}}, + {6 * time.Second, 3 / 5.0, []float64{3 / 5.0}}, } { if got := mmuCurve.MMU(test.window); !aeq(test.want, got) { t.Errorf("for %s window, want mu = %f, got %f", test.window, test.want, got) } + worst := mmuCurve.Examples(test.window, 2) + // Which exact windows are returned is unspecified + // (and depends on the exact banding), so we just + // check that we got the right number with the right + // utilizations. + if len(worst) != len(test.worst) { + t.Errorf("for %s window, want worst %v, got %v", test.window, test.worst, worst) + } else { + for i := range worst { + if worst[i].MutatorUtil != test.worst[i] { + t.Errorf("for %s window, want worst %v, got %v", test.window, test.worst, worst) + break + } + } + } } } From 603af813d6b93cf734b67551c2e776a1417e4603 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 28 Jul 2017 10:24:39 -0400 Subject: [PATCH 0969/1663] cmd/trace: list and link to worst mutator utilization windows This adds the ability to click a point on the MMU graph to show a list of the worst 10 mutator utilization windows of the selected size. This list in turn links to the trace viewer to drill down on specifically what happened in each specific window. Change-Id: Ic1b72d8b37fbf2212211c513cf36b34788b30133 Reviewed-on: https://go-review.googlesource.com/c/60795 Run-TryBot: Austin Clements Reviewed-by: Hyang-Ah Hana Kim TryBot-Result: Gobot Gobot --- src/cmd/trace/main.go | 2 +- src/cmd/trace/mmu.go | 81 ++++++++++++++++++++++++++++++++++++++++-- src/cmd/trace/trace.go | 30 +++++++++++----- 3 files changed, 101 insertions(+), 12 deletions(-) diff --git a/src/cmd/trace/main.go b/src/cmd/trace/main.go index f6ec38d673a83..2f71a3d4bd4cf 100644 --- a/src/cmd/trace/main.go +++ b/src/cmd/trace/main.go @@ -189,7 +189,7 @@ var templMain = template.Must(template.New("").Parse(` {{if $}} {{range $e := $}} - View trace ({{$e.Name}})
      + View trace ({{$e.Name}})
      {{end}}
      {{else}} diff --git a/src/cmd/trace/mmu.go b/src/cmd/trace/mmu.go index cc14025d3822f..f76e0d0e5fa86 100644 --- a/src/cmd/trace/mmu.go +++ b/src/cmd/trace/mmu.go @@ -13,6 +13,7 @@ import ( "log" "math" "net/http" + "strconv" "strings" "sync" "time" @@ -21,6 +22,7 @@ import ( func init() { http.HandleFunc("/mmu", httpMMU) http.HandleFunc("/mmuPlot", httpMMUPlot) + http.HandleFunc("/mmuDetails", httpMMUDetails) } var mmuCache struct { @@ -98,6 +100,9 @@ var templMMU = ` google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(refreshChart); + var chart; + var curve; + function niceDuration(ns) { if (ns < 1e3) { return ns + 'ns'; } else if (ns < 1e6) { return ns / 1e3 + 'µs'; } @@ -114,7 +119,7 @@ var templMMU = ` } function drawChart(plotData) { - var curve = plotData.curve; + curve = plotData.curve; var data = new google.visualization.DataTable(); data.addColumn('number', 'Window duration'); data.addColumn('number', 'Minimum mutator utilization'); @@ -148,13 +153,85 @@ var templMMU = ` var container = $('#mmu_chart'); container.empty(); - var chart = new google.visualization.LineChart(container[0]); + chart = new google.visualization.LineChart(container[0]); + chart = new google.visualization.LineChart(document.getElementById('mmu_chart')); chart.draw(data, options); + + google.visualization.events.addListener(chart, 'select', selectHandler); + } + + function selectHandler() { + var items = chart.getSelection(); + if (items.length === 0) { + return; + } + var details = $('#details'); + details.empty(); + var windowNS = curve[items[0].row][0]; + var url = '/mmuDetails?window=' + windowNS; + $.getJSON(url) + .fail(function(xhr, status, error) { + details.text(status + ': ' + url + ' could not be loaded'); + }) + .done(function(worst) { + details.text('Lowest mutator utilization in ' + niceDuration(windowNS) + ' windows:'); + for (var i = 0; i < worst.length; i++) { + details.append($('
      ')); + var text = worst[i].MutatorUtil.toFixed(3) + ' at time ' + niceDuration(worst[i].Time); + details.append($('').text(text).attr('href', worst[i].URL)); + } + }); }
      Loading plot...
      +
      Select a point for details.
      ` + +// httpMMUDetails serves details of an MMU graph at a particular window. +func httpMMUDetails(w http.ResponseWriter, r *http.Request) { + _, mmuCurve, err := getMMUCurve() + if err != nil { + http.Error(w, fmt.Sprintf("failed to parse events: %v", err), http.StatusInternalServerError) + return + } + + windowStr := r.FormValue("window") + window, err := strconv.ParseUint(windowStr, 10, 64) + if err != nil { + http.Error(w, fmt.Sprintf("failed to parse window parameter %q: %v", windowStr, err), http.StatusBadRequest) + return + } + worst := mmuCurve.Examples(time.Duration(window), 10) + + // Construct a link for each window. + var links []linkedUtilWindow + for _, ui := range worst { + links = append(links, newLinkedUtilWindow(ui, time.Duration(window))) + } + + err = json.NewEncoder(w).Encode(links) + if err != nil { + log.Printf("failed to serialize trace: %v", err) + return + } +} + +type linkedUtilWindow struct { + trace.UtilWindow + URL string +} + +func newLinkedUtilWindow(ui trace.UtilWindow, window time.Duration) linkedUtilWindow { + // Find the range containing this window. + var r Range + for _, r = range ranges { + if r.EndTime > ui.Time { + break + } + } + return linkedUtilWindow{ui, fmt.Sprintf("%s#%v:%v", r.URL(), float64(ui.Time)/1e6, float64(ui.Time+int64(window))/1e6)} +} diff --git a/src/cmd/trace/trace.go b/src/cmd/trace/trace.go index d0e0acd78ca21..d467f371fa604 100644 --- a/src/cmd/trace/trace.go +++ b/src/cmd/trace/trace.go @@ -272,9 +272,15 @@ func httpJSONTrace(w http.ResponseWriter, r *http.Request) { // Range is a named range type Range struct { - Name string - Start int - End int + Name string + Start int + End int + StartTime int64 + EndTime int64 +} + +func (r Range) URL() string { + return fmt.Sprintf("/trace?start=%d&end=%d", r.Start, r.End) } // splitTrace splits the trace into a number of ranges, @@ -345,10 +351,14 @@ func splittingTraceConsumer(max int) (*splitter, traceConsumer) { start := 0 for i, ev := range sizes { if sum+ev.Sz > max { + startTime := time.Duration(sizes[start].Time * 1000) + endTime := time.Duration(ev.Time * 1000) ranges = append(ranges, Range{ - Name: fmt.Sprintf("%v-%v", time.Duration(sizes[start].Time*1000), time.Duration(ev.Time*1000)), - Start: start, - End: i + 1, + Name: fmt.Sprintf("%v-%v", startTime, endTime), + Start: start, + End: i + 1, + StartTime: int64(startTime), + EndTime: int64(endTime), }) start = i + 1 sum = minSize @@ -363,9 +373,11 @@ func splittingTraceConsumer(max int) (*splitter, traceConsumer) { if end := len(sizes) - 1; start < end { ranges = append(ranges, Range{ - Name: fmt.Sprintf("%v-%v", time.Duration(sizes[start].Time*1000), time.Duration(sizes[end].Time*1000)), - Start: start, - End: end, + Name: fmt.Sprintf("%v-%v", time.Duration(sizes[start].Time*1000), time.Duration(sizes[end].Time*1000)), + Start: start, + End: end, + StartTime: int64(sizes[start].Time * 1000), + EndTime: int64(sizes[end].Time * 1000), }) } s.Ranges = ranges From 27920c8ddc609662540deaf5a3d3b4fce03abeea Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 28 Jul 2017 13:51:58 -0400 Subject: [PATCH 0970/1663] internal/trace: flags for what to include in GC utilization Change-Id: I4ba963b003cb25b39d7575d423f17930d84f3f69 Reviewed-on: https://go-review.googlesource.com/c/60796 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim --- src/cmd/trace/mmu.go | 2 +- src/internal/traceparser/gc.go | 48 ++++++++++++++++++++++++----- src/internal/traceparser/gc_test.go | 4 +-- 3 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/cmd/trace/mmu.go b/src/cmd/trace/mmu.go index f76e0d0e5fa86..2a07be4ba2d1f 100644 --- a/src/cmd/trace/mmu.go +++ b/src/cmd/trace/mmu.go @@ -38,7 +38,7 @@ func getMMUCurve() ([]trace.MutatorUtil, *trace.MMUCurve, error) { if err != nil { mmuCache.err = err } else { - mmuCache.util = tr.MutatorUtilization() + mmuCache.util = tr.MutatorUtilization(trace.UtilSTW | trace.UtilBackground | trace.UtilAssist) mmuCache.mmuCurve = trace.NewMMUCurve(mmuCache.util) } }) diff --git a/src/internal/traceparser/gc.go b/src/internal/traceparser/gc.go index 313e23edf6efd..ab0c640e26cb0 100644 --- a/src/internal/traceparser/gc.go +++ b/src/internal/traceparser/gc.go @@ -22,11 +22,27 @@ type MutatorUtil struct { Util float64 } +// UtilFlags controls the behavior of MutatorUtilization. +type UtilFlags int + +const ( + // UtilSTW means utilization should account for STW events. + UtilSTW UtilFlags = 1 << iota + // UtilBackground means utilization should account for + // background mark workers. + UtilBackground + // UtilAssist means utilization should account for mark + // assists. + UtilAssist + // UtilSweep means utilization should account for sweeping. + UtilSweep +) + // MutatorUtilization returns the mutator utilization function for the // given trace. This function will always end with 0 utilization. The // bounds of the function are implicit in the first and last event; // outside of these bounds the function is undefined. -func (p *Parsed) MutatorUtilization() []MutatorUtil { +func (p *Parsed) MutatorUtilization(flags UtilFlags) []MutatorUtil { events := p.Events if len(events) == 0 { return nil @@ -42,17 +58,33 @@ func (p *Parsed) MutatorUtilization() []MutatorUtil { case EvGomaxprocs: gomaxprocs = int(ev.Args[0]) case EvGCSTWStart: - stw++ + if flags&UtilSTW != 0 { + stw++ + } case EvGCSTWDone: - stw-- + if flags&UtilSTW != 0 { + stw-- + } case EvGCMarkAssistStart: - gcPs++ - assists[ev.G] = true + if flags&UtilAssist != 0 { + gcPs++ + assists[ev.G] = true + } case EvGCMarkAssistDone: - gcPs-- - delete(assists, ev.G) + if flags&UtilAssist != 0 { + gcPs-- + delete(assists, ev.G) + } + case EvGCSweepStart: + if flags&UtilSweep != 0 { + gcPs++ + } + case EvGCSweepDone: + if flags&UtilSweep != 0 { + gcPs-- + } case EvGoStartLabel: - if strings.HasPrefix(ev.SArgs[0], "GC ") && ev.SArgs[0] != "GC (idle)" { + if flags&UtilBackground != 0 && strings.HasPrefix(ev.SArgs[0], "GC ") && ev.SArgs[0] != "GC (idle)" { // Background mark worker. bgMark[ev.G] = true gcPs++ diff --git a/src/internal/traceparser/gc_test.go b/src/internal/traceparser/gc_test.go index 65772be7172c4..f1416fa9f92ee 100644 --- a/src/internal/traceparser/gc_test.go +++ b/src/internal/traceparser/gc_test.go @@ -84,7 +84,7 @@ func TestMMUTrace(t *testing.T) { if err := p.Parse(0, 1<<62, nil); err != nil { t.Fatalf("failed to parse trace: %s", err) } - mu := p.MutatorUtilization() + mu := p.MutatorUtilization(UtilSTW | UtilBackground | UtilAssist) mmuCurve := NewMMUCurve(mu) // Test the optimized implementation against the "obviously @@ -106,7 +106,7 @@ func BenchmarkMMU(b *testing.B) { if err := p.Parse(0, 1<<62, nil); err != nil { b.Fatalf("failed to parse trace: %s", err) } - mu := p.MutatorUtilization() + mu := p.MutatorUtilization(UtilSTW | UtilBackground | UtilAssist | UtilSweep) b.ResetTimer() for i := 0; i < b.N; i++ { From bef4efc822794ea2e7310756bc546bf6930fc066 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 28 Jul 2017 16:26:51 -0400 Subject: [PATCH 0971/1663] internal/trace: add "per-P" MMU analysis The current MMU analysis considers all Ps together, so if, for example, one of four Ps is blocked, mutator utilization is 75%. However, this is less useful for understanding the impact on individual goroutines because that one blocked goroutine could be blocked for a very long time, but we still appear to have good utilization. Hence, this introduces a new flag that does a "per-P" analysis where the utilization of each P is considered independently. The MMU is then the combination of the MMU for each P's utilization function. Change-Id: Id67b980d4d82b511d28300cdf92ccbb5ae8f0c78 Reviewed-on: https://go-review.googlesource.com/c/60797 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim --- src/cmd/trace/mmu.go | 15 +- src/internal/traceparser/gc.go | 216 ++++++++++++++++++++-------- src/internal/traceparser/gc_test.go | 6 +- 3 files changed, 172 insertions(+), 65 deletions(-) diff --git a/src/cmd/trace/mmu.go b/src/cmd/trace/mmu.go index 2a07be4ba2d1f..d3b6768686a2d 100644 --- a/src/cmd/trace/mmu.go +++ b/src/cmd/trace/mmu.go @@ -27,12 +27,12 @@ func init() { var mmuCache struct { init sync.Once - util []trace.MutatorUtil + util [][]trace.MutatorUtil mmuCurve *trace.MMUCurve err error } -func getMMUCurve() ([]trace.MutatorUtil, *trace.MMUCurve, error) { +func getMMUCurve() ([][]trace.MutatorUtil, *trace.MMUCurve, error) { mmuCache.init.Do(func() { tr, err := parseTrace() if err != nil { @@ -69,7 +69,16 @@ func httpMMUPlot(w http.ResponseWriter, r *http.Request) { // Cover six orders of magnitude. xMax := xMin * 1e6 // But no more than the length of the trace. - if maxMax := time.Duration(mu[len(mu)-1].Time - mu[0].Time); xMax > maxMax { + minEvent, maxEvent := mu[0][0].Time, mu[0][len(mu[0])-1].Time + for _, mu1 := range mu[1:] { + if mu1[0].Time < minEvent { + minEvent = mu1[0].Time + } + if mu1[len(mu1)-1].Time > maxEvent { + maxEvent = mu1[len(mu1)-1].Time + } + } + if maxMax := time.Duration(maxEvent - minEvent); xMax > maxMax { xMax = maxMax } // Compute MMU curve. diff --git a/src/internal/traceparser/gc.go b/src/internal/traceparser/gc.go index ab0c640e26cb0..569ab86b826ba 100644 --- a/src/internal/traceparser/gc.go +++ b/src/internal/traceparser/gc.go @@ -36,27 +36,64 @@ const ( UtilAssist // UtilSweep means utilization should account for sweeping. UtilSweep + + // UtilPerProc means each P should be given a separate + // utilization function. Otherwise, there is a single function + // and each P is given a fraction of the utilization. + UtilPerProc ) -// MutatorUtilization returns the mutator utilization function for the -// given trace. This function will always end with 0 utilization. The -// bounds of the function are implicit in the first and last event; -// outside of these bounds the function is undefined. -func (p *Parsed) MutatorUtilization(flags UtilFlags) []MutatorUtil { +// MutatorUtilization returns a set of mutator utilization functions +// for the given trace. Each function will always end with 0 +// utilization. The bounds of each function are implicit in the first +// and last event; outside of these bounds each function is undefined. +// +// If the UtilPerProc flag is not given, this always returns a single +// utilization function. Otherwise, it returns one function per P. +func (p *Parsed) MutatorUtilization(flags UtilFlags) [][]MutatorUtil { events := p.Events if len(events) == 0 { return nil } - gomaxprocs, gcPs, stw := 1, 0, 0 - out := []MutatorUtil{{events[0].Ts, 1}} + type perP struct { + // gc > 0 indicates that GC is active on this P. + gc int + // series the logical series number for this P. This + // is necessary because Ps may be removed and then + // re-added, and then the new P needs a new series. + series int + } + ps := []perP{} + stw := 0 + + out := [][]MutatorUtil{} assists := map[uint64]bool{} block := map[uint64]*Event{} bgMark := map[uint64]bool{} + for _, ev := range events { switch ev.Type { case EvGomaxprocs: - gomaxprocs = int(ev.Args[0]) + gomaxprocs := int(ev.Args[0]) + if len(ps) > gomaxprocs { + if flags&UtilPerProc != 0 { + // End each P's series. + for _, p := range ps[gomaxprocs:] { + out[p.series] = addUtil(out[p.series], MutatorUtil{ev.Ts, 0}) + } + } + ps = ps[:gomaxprocs] + } + for len(ps) < gomaxprocs { + // Start new P's series. + series := 0 + if flags&UtilPerProc != 0 || len(out) == 0 { + series = len(out) + out = append(out, []MutatorUtil{{ev.Ts, 1}}) + } + ps = append(ps, perP{series: series}) + } case EvGCSTWStart: if flags&UtilSTW != 0 { stw++ @@ -67,33 +104,41 @@ func (p *Parsed) MutatorUtilization(flags UtilFlags) []MutatorUtil { } case EvGCMarkAssistStart: if flags&UtilAssist != 0 { - gcPs++ + ps[ev.P].gc++ assists[ev.G] = true } case EvGCMarkAssistDone: if flags&UtilAssist != 0 { - gcPs-- + ps[ev.P].gc-- delete(assists, ev.G) } case EvGCSweepStart: if flags&UtilSweep != 0 { - gcPs++ + ps[ev.P].gc++ } case EvGCSweepDone: if flags&UtilSweep != 0 { - gcPs-- + ps[ev.P].gc-- } case EvGoStartLabel: if flags&UtilBackground != 0 && strings.HasPrefix(ev.SArgs[0], "GC ") && ev.SArgs[0] != "GC (idle)" { // Background mark worker. - bgMark[ev.G] = true - gcPs++ + // + // If we're in per-proc mode, we don't + // count dedicated workers because + // they kick all of the goroutines off + // that P, so don't directly + // contribute to goroutine latency. + if !(flags&UtilPerProc != 0 && ev.SArgs[0] == "GC (dedicated)") { + bgMark[ev.G] = true + ps[ev.P].gc++ + } } fallthrough case EvGoStart: if assists[ev.G] { // Unblocked during assist. - gcPs++ + ps[ev.P].gc++ } block[ev.G] = ev.Link default: @@ -103,49 +148,77 @@ func (p *Parsed) MutatorUtilization(flags UtilFlags) []MutatorUtil { if assists[ev.G] { // Blocked during assist. - gcPs-- + ps[ev.P].gc-- } if bgMark[ev.G] { // Background mark worker done. - gcPs-- + ps[ev.P].gc-- delete(bgMark, ev.G) } delete(block, ev.G) } - ps := gcPs - if stw > 0 { - ps = gomaxprocs - } - mu := MutatorUtil{ev.Ts, 1 - float64(ps)/float64(gomaxprocs)} - if mu.Util == out[len(out)-1].Util { - // No change. - continue - } - if mu.Time == out[len(out)-1].Time { - // Take the lowest utilization at a time stamp. - if mu.Util < out[len(out)-1].Util { - out[len(out)-1] = mu + if flags&UtilPerProc == 0 { + // Compute the current average utilization. + if len(ps) == 0 { + continue } + gcPs := 0 + if stw > 0 { + gcPs = len(ps) + } else { + for i := range ps { + if ps[i].gc > 0 { + gcPs++ + } + } + } + mu := MutatorUtil{ev.Ts, 1 - float64(gcPs)/float64(len(ps))} + + // Record the utilization change. (Since + // len(ps) == len(out), we know len(out) > 0.) + out[0] = addUtil(out[0], mu) } else { - out = append(out, mu) + // Check for per-P utilization changes. + for i := range ps { + p := &ps[i] + util := 1.0 + if stw > 0 || p.gc > 0 { + util = 0.0 + } + out[p.series] = addUtil(out[p.series], MutatorUtil{ev.Ts, util}) + } } } - // Add final 0 utilization event. This is important to mark - // the end of the trace. The exact value shouldn't matter - // since no window should extend beyond this, but using 0 is - // symmetric with the start of the trace. - endTime := events[len(events)-1].Ts - if out[len(out)-1].Time == endTime { - out[len(out)-1].Util = 0 - } else { - out = append(out, MutatorUtil{endTime, 0}) + // Add final 0 utilization event to any remaining series. This + // is important to mark the end of the trace. The exact value + // shouldn't matter since no window should extend beyond this, + // but using 0 is symmetric with the start of the trace. + mu := MutatorUtil{events[len(events)-1].Ts, 0} + for i := range ps { + out[ps[i].series] = addUtil(out[ps[i].series], mu) } - return out } +func addUtil(util []MutatorUtil, mu MutatorUtil) []MutatorUtil { + if len(util) > 0 { + if mu.Util == util[len(util)-1].Util { + // No change. + return util + } + if mu.Time == util[len(util)-1].Time { + // Take the lowest utilization at a time stamp. + if mu.Util < util[len(util)-1].Util { + util[len(util)-1] = mu + } + return util + } + } + return append(util, mu) +} + // totalUtil is total utilization, measured in nanoseconds. This is a // separate type primarily to distinguish it from mean utilization, // which is also a float64. @@ -163,6 +236,10 @@ func (u totalUtil) mean(dur time.Duration) float64 { // An MMUCurve is the minimum mutator utilization curve across // multiple window sizes. type MMUCurve struct { + series []mmuSeries +} + +type mmuSeries struct { util []MutatorUtil // sums[j] is the cumulative sum of util[:j]. sums []totalUtil @@ -188,7 +265,15 @@ type mmuBand struct { // NewMMUCurve returns an MMU curve for the given mutator utilization // function. -func NewMMUCurve(util []MutatorUtil) *MMUCurve { +func NewMMUCurve(utils [][]MutatorUtil) *MMUCurve { + series := make([]mmuSeries, len(utils)) + for i, util := range utils { + series[i] = newMMUSeries(util) + } + return &MMUCurve{series} +} + +func newMMUSeries(util []MutatorUtil) mmuSeries { // Compute cumulative sum. sums := make([]totalUtil, len(util)) var prev MutatorUtil @@ -218,10 +303,10 @@ func NewMMUCurve(util []MutatorUtil) *MMUCurve { // Compute the bands. There are numBands+1 bands in order to // record the final cumulative sum. bands := make([]mmuBand, numBands+1) - c := MMUCurve{util, sums, bands, bandDur} - leftSum := integrator{&c, 0} + s := mmuSeries{util, sums, bands, bandDur} + leftSum := integrator{&s, 0} for i := range bands { - startTime, endTime := c.bandTime(i) + startTime, endTime := s.bandTime(i) cumUtil := leftSum.advance(startTime) predIdx := leftSum.pos minUtil := 1.0 @@ -231,16 +316,18 @@ func NewMMUCurve(util []MutatorUtil) *MMUCurve { bands[i] = mmuBand{minUtil, cumUtil, leftSum} } - return &c + return s } -func (c *MMUCurve) bandTime(i int) (start, end int64) { - start = int64(i)*c.bandDur + c.util[0].Time - end = start + c.bandDur +func (s *mmuSeries) bandTime(i int) (start, end int64) { + start = int64(i)*s.bandDur + s.util[0].Time + end = start + s.bandDur return } type bandUtil struct { + // Utilization series index + series int // Band index i int // Lower bound of mutator utilization for all windows @@ -402,12 +489,22 @@ func (c *MMUCurve) mmu(window time.Duration, acc *accumulator) { acc.mmu = 0 return } - util := c.util - if max := time.Duration(util[len(util)-1].Time - util[0].Time); window > max { - window = max - } - bandU := bandUtilHeap(c.mkBandUtil(window)) + var bandU bandUtilHeap + windows := make([]time.Duration, len(c.series)) + for i, s := range c.series { + windows[i] = window + if max := time.Duration(s.util[len(s.util)-1].Time - s.util[0].Time); window > max { + windows[i] = max + } + + bandU1 := bandUtilHeap(s.mkBandUtil(i, windows[i])) + if bandU == nil { + bandU = bandU1 + } else { + bandU = append(bandU, bandU1...) + } + } // Process bands from lowest utilization bound to highest. heap.Init(&bandU) @@ -416,12 +513,13 @@ func (c *MMUCurve) mmu(window time.Duration, acc *accumulator) { // refining the next lowest band can no longer affect the MMU // or windows. for len(bandU) > 0 && bandU[0].utilBound < acc.bound { - c.bandMMU(bandU[0].i, window, acc) + i := bandU[0].series + c.series[i].bandMMU(bandU[0].i, windows[i], acc) heap.Pop(&bandU) } } -func (c *MMUCurve) mkBandUtil(window time.Duration) []bandUtil { +func (c *mmuSeries) mkBandUtil(series int, window time.Duration) []bandUtil { // For each band, compute the worst-possible total mutator // utilization for all windows that start in that band. @@ -477,7 +575,7 @@ func (c *MMUCurve) mkBandUtil(window time.Duration) []bandUtil { util += c.bands[i+minBands-1].cumUtil - c.bands[i+1].cumUtil } - bandU[i] = bandUtil{i, util.mean(window)} + bandU[i] = bandUtil{series, i, util.mean(window)} } return bandU @@ -485,7 +583,7 @@ func (c *MMUCurve) mkBandUtil(window time.Duration) []bandUtil { // bandMMU computes the precise minimum mutator utilization for // windows with a left edge in band bandIdx. -func (c *MMUCurve) bandMMU(bandIdx int, window time.Duration, acc *accumulator) { +func (c *mmuSeries) bandMMU(bandIdx int, window time.Duration, acc *accumulator) { util := c.util // We think of the mutator utilization over time as the @@ -542,7 +640,7 @@ func (c *MMUCurve) bandMMU(bandIdx int, window time.Duration, acc *accumulator) // An integrator tracks a position in a utilization function and // integrates it. type integrator struct { - u *MMUCurve + u *mmuSeries // pos is the index in u.util of the current time's non-strict // predecessor. pos int diff --git a/src/internal/traceparser/gc_test.go b/src/internal/traceparser/gc_test.go index f1416fa9f92ee..b438a2931f0dc 100644 --- a/src/internal/traceparser/gc_test.go +++ b/src/internal/traceparser/gc_test.go @@ -29,14 +29,14 @@ func TestMMU(t *testing.T) { // 0.5 * * * * // 0.0 ***** ***** // 0 1 2 3 4 5 - util := []MutatorUtil{ + util := [][]MutatorUtil{{ {0e9, 1}, {1e9, 0}, {2e9, 1}, {3e9, 0}, {4e9, 1}, {5e9, 0}, - } + }} mmuCurve := NewMMUCurve(util) for _, test := range []struct { @@ -90,7 +90,7 @@ func TestMMUTrace(t *testing.T) { // Test the optimized implementation against the "obviously // correct" implementation. for window := time.Nanosecond; window < 10*time.Second; window *= 10 { - want := mmuSlow(mu, window) + want := mmuSlow(mu[0], window) got := mmuCurve.MMU(window) if !aeq(want, got) { t.Errorf("want %f, got %f mutator utilization in window %s", want, got, window) From b2e8dd187343cf3059e373374426833d1a676a3e Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 28 Jul 2017 16:30:05 -0400 Subject: [PATCH 0972/1663] cmd/trace: expose MMU analysis flags in web UI Change-Id: I672240487172380c9eef61837b41698021aaf834 Reviewed-on: https://go-review.googlesource.com/c/60798 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim --- src/cmd/trace/mmu.go | 133 ++++++++++++++++++++++++++++++++++++++----- 1 file changed, 119 insertions(+), 14 deletions(-) diff --git a/src/cmd/trace/mmu.go b/src/cmd/trace/mmu.go index d3b6768686a2d..3fae3d6645b17 100644 --- a/src/cmd/trace/mmu.go +++ b/src/cmd/trace/mmu.go @@ -25,24 +25,54 @@ func init() { http.HandleFunc("/mmuDetails", httpMMUDetails) } -var mmuCache struct { +var utilFlagNames = map[string]trace.UtilFlags{ + "perProc": trace.UtilPerProc, + "stw": trace.UtilSTW, + "background": trace.UtilBackground, + "assist": trace.UtilAssist, + "sweep": trace.UtilSweep, +} + +type mmuCacheEntry struct { init sync.Once util [][]trace.MutatorUtil mmuCurve *trace.MMUCurve err error } -func getMMUCurve() ([][]trace.MutatorUtil, *trace.MMUCurve, error) { - mmuCache.init.Do(func() { +var mmuCache struct { + m map[trace.UtilFlags]*mmuCacheEntry + lock sync.Mutex +} + +func init() { + mmuCache.m = make(map[trace.UtilFlags]*mmuCacheEntry) +} + +func getMMUCurve(r *http.Request) ([][]trace.MutatorUtil, *trace.MMUCurve, error) { + var flags trace.UtilFlags + for _, flagStr := range strings.Split(r.FormValue("flags"), "|") { + flags |= utilFlagNames[flagStr] + } + + mmuCache.lock.Lock() + c := mmuCache.m[flags] + if c == nil { + c = new(mmuCacheEntry) + mmuCache.m[flags] = c + } + mmuCache.lock.Unlock() + + c.init.Do(func() { tr, err := parseTrace() if err != nil { - mmuCache.err = err + c.err = err } else { - mmuCache.util = tr.MutatorUtilization(trace.UtilSTW | trace.UtilBackground | trace.UtilAssist) - mmuCache.mmuCurve = trace.NewMMUCurve(mmuCache.util) + c.util = tr.MutatorUtilization(flags) + c.mmuCurve = trace.NewMMUCurve(c.util) } }) - return mmuCache.util, mmuCache.mmuCurve, mmuCache.err + return c.util, c.mmuCurve, c.err } // httpMMU serves the MMU plot page. @@ -52,7 +82,7 @@ func httpMMU(w http.ResponseWriter, r *http.Request) { // httpMMUPlot serves the JSON data for the MMU plot. func httpMMUPlot(w http.ResponseWriter, r *http.Request) { - mu, mmuCurve, err := getMMUCurve() + mu, mmuCurve, err := getMMUCurve(r) if err != nil { http.Error(w, fmt.Sprintf("failed to parse events: %v", err), http.StatusInternalServerError) return @@ -107,7 +137,8 @@ var templMMU = ` + -
      Loading plot...
      +
      +
      Loading plot...
      +
      +

      + View
      + + ?Consider whole system utilization. For example, if one of four procs is available to the mutator, mutator utilization will be 0.25. This is the standard definition of an MMU.
      + + ?Consider per-goroutine utilization. When even one goroutine is interrupted by GC, mutator utilization is 0.
      +

      +

      + Include
      + + ?Stop-the-world stops all goroutines simultaneously.
      + + ?Background workers are GC-specific goroutines. 25% of the CPU is dedicated to background workers during GC.
      + + ?Mark assists are performed by allocation to prevent the mutator from outpacing GC.
      + + ?Sweep reclaims unused memory between GCs. (Enabling this may be very slow.).
      +

      +
      +
      Select a point for details.
      @@ -202,7 +307,7 @@ var templMMU = ` // httpMMUDetails serves details of an MMU graph at a particular window. func httpMMUDetails(w http.ResponseWriter, r *http.Request) { - _, mmuCurve, err := getMMUCurve() + _, mmuCurve, err := getMMUCurve(r) if err != nil { http.Error(w, fmt.Sprintf("failed to parse events: %v", err), http.StatusInternalServerError) return From 33563d1cfc7939d99d18e58cea7eedd6fb1c6ed6 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 17 Aug 2017 11:31:03 -0400 Subject: [PATCH 0973/1663] internal/trace: support for mutator utilization distributions This adds support for computing the quantiles of a mutator utilization distribution. Change-Id: Ia8b3ed14bf415c234e2f567360fd1b361d28bd40 Reviewed-on: https://go-review.googlesource.com/c/60799 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim --- src/internal/traceparser/gc.go | 143 ++++++++++++++++- src/internal/traceparser/gc_test.go | 22 ++- src/internal/traceparser/mud.go | 223 +++++++++++++++++++++++++++ src/internal/traceparser/mud_test.go | 87 +++++++++++ 4 files changed, 467 insertions(+), 8 deletions(-) create mode 100644 src/internal/traceparser/mud.go create mode 100644 src/internal/traceparser/mud_test.go diff --git a/src/internal/traceparser/gc.go b/src/internal/traceparser/gc.go index 569ab86b826ba..a5b29112b35dc 100644 --- a/src/internal/traceparser/gc.go +++ b/src/internal/traceparser/gc.go @@ -273,6 +273,10 @@ func NewMMUCurve(utils [][]MutatorUtil) *MMUCurve { return &MMUCurve{series} } +// bandsPerSeries is the number of bands to divide each series into. +// This is only changed by tests. +var bandsPerSeries = 1000 + func newMMUSeries(util []MutatorUtil) mmuSeries { // Compute cumulative sum. sums := make([]totalUtil, len(util)) @@ -289,7 +293,7 @@ func newMMUSeries(util []MutatorUtil) mmuSeries { // these bands. // // Compute the duration of each band. - numBands := 1000 + numBands := bandsPerSeries if numBands > len(util) { // There's no point in having lots of bands if there // aren't many events. @@ -393,8 +397,8 @@ func (h *utilHeap) Pop() interface{} { return x } -// An accumulator collects different MMU-related statistics depending -// on what's desired. +// An accumulator takes a windowed mutator utilization function and +// tracks various statistics for that function. type accumulator struct { mmu float64 @@ -406,10 +410,30 @@ type accumulator struct { // Worst N window tracking nWorst int wHeap utilHeap -} -// addMU records mutator utilization mu over the given window starting -// at time. + // Mutator utilization distribution tracking + mud *mud + // preciseMass is the distribution mass that must be precise + // before accumulation is stopped. + preciseMass float64 + // lastTime and lastMU are the previous point added to the + // windowed mutator utilization function. + lastTime int64 + lastMU float64 +} + +// resetTime declares a discontinuity in the windowed mutator +// utilization function by resetting the current time. +func (acc *accumulator) resetTime() { + // This only matters for distribution collection, since that's + // the only thing that depends on the progression of the + // windowed mutator utilization function. + acc.lastTime = math.MaxInt64 +} + +// addMU adds a point to the windowed mutator utilization function at +// (time, mu). This must be called for monotonically increasing values +// of time. // // It returns true if further calls to addMU would be pointless. func (acc *accumulator) addMU(time int64, mu float64, window time.Duration) bool { @@ -458,6 +482,25 @@ func (acc *accumulator) addMU(time int64, mu float64, window time.Duration) bool acc.bound = math.Max(acc.bound, acc.wHeap[0].MutatorUtil) } + if acc.mud != nil { + if acc.lastTime != math.MaxInt64 { + // Update distribution. + acc.mud.add(acc.lastMU, mu, float64(time-acc.lastTime)) + } + acc.lastTime, acc.lastMU = time, mu + if _, mudBound, ok := acc.mud.approxInvCumulativeSum(); ok { + acc.bound = math.Max(acc.bound, mudBound) + } else { + // We haven't accumulated enough total precise + // mass yet to even reach our goal, so keep + // accumulating. + acc.bound = 1 + } + // It's not worth checking percentiles every time, so + // just keep accumulating this band. + return false + } + // If we've found enough 0 utilizations, we can stop immediately. return len(acc.wHeap) == acc.nWorst && acc.wHeap[0].MutatorUtil == 0 } @@ -484,6 +527,85 @@ func (c *MMUCurve) Examples(window time.Duration, n int) (worst []UtilWindow) { return ([]UtilWindow)(acc.wHeap) } +// MUD returns mutator utilization distribution quantiles for the +// given window size. +// +// The mutator utilization distribution is the distribution of mean +// mutator utilization across all windows of the given window size in +// the trace. +// +// The minimum mutator utilization is the minimum (0th percentile) of +// this distribution. (However, if only the minimum is desired, it's +// more efficient to use the MMU method.) +func (c *MMUCurve) MUD(window time.Duration, quantiles []float64) []float64 { + if len(quantiles) == 0 { + return []float64{} + } + + // Each unrefined band contributes a known total mass to the + // distribution (bandDur except at the end), but in an unknown + // way. However, we know that all the mass it contributes must + // be at or above its worst-case mean mutator utilization. + // + // Hence, we refine bands until the highest desired + // distribution quantile is less than the next worst-case mean + // mutator utilization. At this point, all further + // contributions to the distribution must be beyond the + // desired quantile and hence cannot affect it. + // + // First, find the highest desired distribution quantile. + maxQ := quantiles[0] + for _, q := range quantiles { + if q > maxQ { + maxQ = q + } + } + // The distribution's mass is in units of time (it's not + // normalized because this would make it more annoying to + // account for future contributions of unrefined bands). The + // total final mass will be the duration of the trace itself + // minus the window size. Using this, we can compute the mass + // corresponding to quantile maxQ. + var duration int64 + for _, s := range c.series { + duration1 := s.util[len(s.util)-1].Time - s.util[0].Time + if duration1 >= int64(window) { + duration += duration1 - int64(window) + } + } + qMass := float64(duration) * maxQ + + // Accumulate the MUD until we have precise information for + // everything to the left of qMass. + acc := accumulator{mmu: 1.0, bound: 1.0, preciseMass: qMass, mud: new(mud)} + acc.mud.setTrackMass(qMass) + c.mmu(window, &acc) + + // Evaluate the quantiles on the accumulated MUD. + out := make([]float64, len(quantiles)) + for i := range out { + mu, _ := acc.mud.invCumulativeSum(float64(duration) * quantiles[i]) + if math.IsNaN(mu) { + // There are a few legitimate ways this can + // happen: + // + // 1. If the window is the full trace + // duration, then the windowed MU function is + // only defined at a single point, so the MU + // distribution is not well-defined. + // + // 2. If there are no events, then the MU + // distribution has no mass. + // + // Either way, all of the quantiles will have + // converged toward the MMU at this point. + mu = acc.mmu + } + out[i] = mu + } + return out +} + func (c *MMUCurve) mmu(window time.Duration, acc *accumulator) { if window <= 0 { acc.mmu = 0 @@ -607,12 +729,16 @@ func (c *mmuSeries) bandMMU(bandIdx int, window time.Duration, acc *accumulator) if utilEnd := util[len(util)-1].Time - int64(window); utilEnd < endTime { endTime = utilEnd } + acc.resetTime() for { // Advance edges to time and time+window. mu := (right.advance(time+int64(window)) - left.advance(time)).mean(window) if acc.addMU(time, mu, window) { break } + if time == endTime { + break + } // The maximum slope of the windowed mutator // utilization function is 1/window, so we can always @@ -632,7 +758,10 @@ func (c *mmuSeries) bandMMU(bandIdx int, window time.Duration, acc *accumulator) time = minTime } if time >= endTime { - break + // For MMUs we could stop here, but for MUDs + // it's important that we span the entire + // band. + time = endTime } } } diff --git a/src/internal/traceparser/gc_test.go b/src/internal/traceparser/gc_test.go index b438a2931f0dc..1cd8fb6f780aa 100644 --- a/src/internal/traceparser/gc_test.go +++ b/src/internal/traceparser/gc_test.go @@ -75,7 +75,8 @@ func TestMMU(t *testing.T) { } func TestMMUTrace(t *testing.T) { - t.Parallel() + // Can't be t.Parallel() because it modifies the + // testingOneBand package variable. p, err := New("../trace/testdata/stress_1_10_good") if err != nil { @@ -96,6 +97,25 @@ func TestMMUTrace(t *testing.T) { t.Errorf("want %f, got %f mutator utilization in window %s", want, got, window) } } + + // Test MUD with band optimization against MUD without band + // optimization. We don't have a simple testing implementation + // of MUDs (the simplest implementation is still quite + // complex), but this is still a pretty good test. + defer func(old int) { bandsPerSeries = old }(bandsPerSeries) + bandsPerSeries = 1 + mmuCurve2 := NewMMUCurve(mu) + quantiles := []float64{0, 1 - .999, 1 - .99} + for window := time.Microsecond; window < time.Second; window *= 10 { + mud1 := mmuCurve.MUD(window, quantiles) + mud2 := mmuCurve2.MUD(window, quantiles) + for i := range mud1 { + if !aeq(mud1[i], mud2[i]) { + t.Errorf("for quantiles %v at window %v, want %v, got %v", quantiles, window, mud2, mud1) + break + } + } + } } func BenchmarkMMU(b *testing.B) { diff --git a/src/internal/traceparser/mud.go b/src/internal/traceparser/mud.go new file mode 100644 index 0000000000000..8eed89ff36319 --- /dev/null +++ b/src/internal/traceparser/mud.go @@ -0,0 +1,223 @@ +// 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. + +package traceparser + +import ( + "math" + "sort" +) + +// mud is an updatable mutator utilization distribution. +// +// This is a continuous distribution of duration over mutator +// utilization. For example, the integral from mutator utilization a +// to b is the total duration during which the mutator utilization was +// in the range [a, b]. +// +// This distribution is *not* normalized (it is not a probability +// distribution). This makes it easier to work with as it's being +// updated. +// +// It is represented as the sum of scaled uniform distribution +// functions and Dirac delta functions (which are treated as +// degenerate uniform distributions). +type mud struct { + sorted, unsorted []edge + + // trackMass is the inverse cumulative sum to track as the + // distribution is updated. + trackMass float64 + // trackBucket is the bucket in which trackMass falls. If the + // total mass of the distribution is < trackMass, this is + // len(hist). + trackBucket int + // trackSum is the cumulative sum of hist[:trackBucket]. Once + // trackSum >= trackMass, trackBucket must be recomputed. + trackSum float64 + + // hist is a hierarchical histogram of distribution mass. + hist [mudDegree]float64 +} + +const ( + // mudDegree is the number of buckets in the MUD summary + // histogram. + mudDegree = 1024 +) + +type edge struct { + // At x, the function increases by y. + x, delta float64 + // Additionally at x is a Dirac delta function with area dirac. + dirac float64 +} + +// add adds a uniform function over [l, r] scaled so the total weight +// of the uniform is area. If l==r, this adds a Dirac delta function. +func (d *mud) add(l, r, area float64) { + if area == 0 { + return + } + + if r < l { + l, r = r, l + } + + // Add the edges. + if l == r { + d.unsorted = append(d.unsorted, edge{l, 0, area}) + } else { + delta := area / (r - l) + d.unsorted = append(d.unsorted, edge{l, delta, 0}, edge{r, -delta, 0}) + } + + // Update the histogram. + h := &d.hist + lbFloat, lf := math.Modf(l * mudDegree) + lb := int(lbFloat) + if lb >= mudDegree { + lb, lf = mudDegree-1, 1 + } + if l == r { + h[lb] += area + } else { + rbFloat, rf := math.Modf(r * mudDegree) + rb := int(rbFloat) + if rb >= mudDegree { + rb, rf = mudDegree-1, 1 + } + if lb == rb { + h[lb] += area + } else { + perBucket := area / (r - l) / mudDegree + h[lb] += perBucket * (1 - lf) + h[rb] += perBucket * rf + for i := lb + 1; i < rb; i++ { + h[i] += perBucket + } + } + } + + // Update mass tracking. + if thresh := float64(d.trackBucket) / mudDegree; l < thresh { + if r < thresh { + d.trackSum += area + } else { + d.trackSum += area * (thresh - l) / (r - l) + } + if d.trackSum >= d.trackMass { + // The tracked mass now falls in a different + // bucket. Recompute the inverse cumulative sum. + d.setTrackMass(d.trackMass) + } + } +} + +// setTrackMass sets the mass to track the inverse cumulative sum for. +// +// Specifically, mass is a cumulative duration, and the mutator +// utilization bounds for this duration can be queried using +// approxInvCumulativeSum. +func (d *mud) setTrackMass(mass float64) { + d.trackMass = mass + + // Find the bucket currently containing trackMass by computing + // the cumulative sum. + sum := 0.0 + for i, val := range d.hist[:] { + newSum := sum + val + if newSum > mass { + // mass falls in bucket i. + d.trackBucket = i + d.trackSum = sum + return + } + sum = newSum + } + d.trackBucket = len(d.hist) + d.trackSum = sum +} + +// approxInvCumulativeSum is like invCumulativeSum, but specifically +// operates on the tracked mass and returns an upper and lower bound +// approximation of the inverse cumulative sum. +// +// The true inverse cumulative sum will be in the range [lower, upper). +func (d *mud) approxInvCumulativeSum() (float64, float64, bool) { + if d.trackBucket == len(d.hist) { + return math.NaN(), math.NaN(), false + } + return float64(d.trackBucket) / mudDegree, float64(d.trackBucket+1) / mudDegree, true +} + +// invCumulativeSum returns x such that the integral of d from -∞ to x +// is y. If the total weight of d is less than y, it returns the +// maximum of the distribution and false. +// +// Specifically, y is a cumulative duration, and invCumulativeSum +// returns the mutator utilization x such that at least y time has +// been spent with mutator utilization <= x. +func (d *mud) invCumulativeSum(y float64) (float64, bool) { + if len(d.sorted) == 0 && len(d.unsorted) == 0 { + return math.NaN(), false + } + + // Sort edges. + edges := d.unsorted + sort.Slice(edges, func(i, j int) bool { + return edges[i].x < edges[j].x + }) + // Merge with sorted edges. + d.unsorted = nil + if d.sorted == nil { + d.sorted = edges + } else { + oldSorted := d.sorted + newSorted := make([]edge, len(oldSorted)+len(edges)) + i, j := 0, 0 + for o := range newSorted { + if i >= len(oldSorted) { + copy(newSorted[o:], edges[j:]) + break + } else if j >= len(edges) { + copy(newSorted[o:], oldSorted[i:]) + break + } else if oldSorted[i].x < edges[j].x { + newSorted[o] = oldSorted[i] + i++ + } else { + newSorted[o] = edges[j] + j++ + } + } + d.sorted = newSorted + } + + // Traverse edges in order computing a cumulative sum. + csum, rate, prevX := 0.0, 0.0, 0.0 + for _, e := range d.sorted { + newCsum := csum + (e.x-prevX)*rate + if newCsum >= y { + // y was exceeded between the previous edge + // and this one. + if rate == 0 { + // Anywhere between prevX and + // e.x will do. We return e.x + // because that takes care of + // the y==0 case naturally. + return e.x, true + } + return (y-csum)/rate + prevX, true + } + newCsum += e.dirac + if newCsum >= y { + // y was exceeded by the Dirac delta at e.x. + return e.x, true + } + csum, prevX = newCsum, e.x + rate += e.delta + } + return prevX, false +} diff --git a/src/internal/traceparser/mud_test.go b/src/internal/traceparser/mud_test.go new file mode 100644 index 0000000000000..6e048fcf19c65 --- /dev/null +++ b/src/internal/traceparser/mud_test.go @@ -0,0 +1,87 @@ +// 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. + +package traceparser + +import ( + "math/rand" + "testing" +) + +func TestMUD(t *testing.T) { + // Insert random uniforms and check histogram mass and + // cumulative sum approximations. + rnd := rand.New(rand.NewSource(42)) + mass := 0.0 + var mud mud + for i := 0; i < 100; i++ { + area, l, r := rnd.Float64(), rnd.Float64(), rnd.Float64() + if rnd.Intn(10) == 0 { + r = l + } + t.Log(l, r, area) + mud.add(l, r, area) + mass += area + + // Check total histogram weight. + hmass := 0.0 + for _, val := range mud.hist { + hmass += val + } + if !aeq(mass, hmass) { + t.Fatalf("want mass %g, got %g", mass, hmass) + } + + // Check inverse cumulative sum approximations. + for j := 0.0; j < mass; j += mass * 0.099 { + mud.setTrackMass(j) + l, u, ok := mud.approxInvCumulativeSum() + inv, ok2 := mud.invCumulativeSum(j) + if !ok || !ok2 { + t.Fatalf("inverse cumulative sum failed: approx %v, exact %v", ok, ok2) + } + if !(l <= inv && inv < u) { + t.Fatalf("inverse(%g) = %g, not ∈ [%g, %g)", j, inv, l, u) + } + } + } +} + +func TestMUDTracking(t *testing.T) { + // Test that the tracked mass is tracked correctly across + // updates. + rnd := rand.New(rand.NewSource(42)) + const uniforms = 100 + for trackMass := 0.0; trackMass < uniforms; trackMass += uniforms / 50 { + var mud mud + mass := 0.0 + mud.setTrackMass(trackMass) + for i := 0; i < uniforms; i++ { + area, l, r := rnd.Float64(), rnd.Float64(), rnd.Float64() + mud.add(l, r, area) + mass += area + l, u, ok := mud.approxInvCumulativeSum() + inv, ok2 := mud.invCumulativeSum(trackMass) + + if mass < trackMass { + if ok { + t.Errorf("approx(%g) = [%g, %g), but mass = %g", trackMass, l, u, mass) + } + if ok2 { + t.Errorf("exact(%g) = %g, but mass = %g", trackMass, inv, mass) + } + } else { + if !ok { + t.Errorf("approx(%g) failed, but mass = %g", trackMass, mass) + } + if !ok2 { + t.Errorf("exact(%g) failed, but mass = %g", trackMass, mass) + } + if ok && ok2 && !(l <= inv && inv < u) { + t.Errorf("inverse(%g) = %g, not ∈ [%g, %g)", trackMass, inv, l, u) + } + } + } + } +} From b251d7fbe6d69e1ce81baf7959062ae489858f31 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 17 Aug 2017 18:11:01 -0400 Subject: [PATCH 0974/1663] cmd/trace: display p99.9, p99 and p95 MUT This uses the mutator utilization distribution to compute the p99.9, p99, and p95 mutator utilization topograph lines and display them along with the MMU. Change-Id: I8c7e0ec326aa4bc00619ec7562854253f01cc802 Reviewed-on: https://go-review.googlesource.com/c/60800 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim --- src/cmd/trace/mmu.go | 41 +++++++++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/cmd/trace/mmu.go b/src/cmd/trace/mmu.go index 3fae3d6645b17..062e5ad2ca16e 100644 --- a/src/cmd/trace/mmu.go +++ b/src/cmd/trace/mmu.go @@ -88,6 +88,14 @@ func httpMMUPlot(w http.ResponseWriter, r *http.Request) { return } + var quantiles []float64 + for _, flagStr := range strings.Split(r.FormValue("flags"), "|") { + if flagStr == "mut" { + quantiles = []float64{0, 1 - .999, 1 - .99, 1 - .95} + break + } + } + // Find a nice starting point for the plot. xMin := time.Second for xMin > 1 { @@ -114,15 +122,21 @@ func httpMMUPlot(w http.ResponseWriter, r *http.Request) { // Compute MMU curve. logMin, logMax := math.Log(float64(xMin)), math.Log(float64(xMax)) const samples = 100 - plot := make([][2]float64, samples) + plot := make([][]float64, samples) for i := 0; i < samples; i++ { window := time.Duration(math.Exp(float64(i)/(samples-1)*(logMax-logMin) + logMin)) - y := mmuCurve.MMU(window) - plot[i] = [2]float64{float64(window), y} + if quantiles == nil { + plot[i] = make([]float64, 2) + plot[i][1] = mmuCurve.MMU(window) + } else { + plot[i] = make([]float64, 1+len(quantiles)) + copy(plot[i][1:], mmuCurve.MUD(window, quantiles)) + } + plot[i][0] = float64(window) } // Create JSON response. - err = json.NewEncoder(w).Encode(map[string]interface{}{"xMin": int64(xMin), "xMax": int64(xMax), "curve": plot}) + err = json.NewEncoder(w).Encode(map[string]interface{}{"xMin": int64(xMin), "xMax": int64(xMax), "quantiles": quantiles, "curve": plot}) if err != nil { log.Printf("failed to serialize response: %v", err) return @@ -150,6 +164,10 @@ var templMMU = ` else { return ns / 1e9 + 's'; } } + function niceQuantile(q) { + return 'p' + q*100; + } + function mmuFlags() { var flags = ""; $("#options input").each(function(i, elt) { @@ -181,6 +199,11 @@ var templMMU = ` var data = new google.visualization.DataTable(); data.addColumn('number', 'Window duration'); data.addColumn('number', 'Minimum mutator utilization'); + if (plotData.quantiles) { + for (var i = 1; i < plotData.quantiles.length; i++) { + data.addColumn('number', niceQuantile(1 - plotData.quantiles[i]) + ' MU'); + } + } data.addRows(curve); for (var i = 0; i < curve.length; i++) { data.setFormattedValue(i, 0, niceDuration(curve[i][0])); @@ -201,6 +224,7 @@ var templMMU = ` maxValue: 1.0, }, legend: { position: 'none' }, + focusTarget: 'category', width: 900, height: 500, chartArea: { width: '80%', height: '80%' }, @@ -208,6 +232,10 @@ var templMMU = ` for (var v = plotData.xMin; v <= plotData.xMax; v *= 10) { options.hAxis.ticks.push({v:v, f:niceDuration(v)}); } + if (plotData.quantiles) { + options.vAxis.title = 'Mutator utilization'; + options.legend.position = 'in'; + } var container = $('#mmu_chart'); container.empty(); @@ -298,6 +326,11 @@ var templMMU = ` ?Sweep reclaims unused memory between GCs. (Enabling this may be very slow.).

      +

      + Display
      + + ?Display percentile mutator utilization in addition to minimum. E.g., p99 MU drops the worst 1% of windows.
      +

      Select a point for details.
      From e72595ee0f97746be3ce594834a7003d5e804795 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Tue, 25 Jul 2017 15:03:44 -0400 Subject: [PATCH 0975/1663] cmd/trace: notes on MMU view improvements Change-Id: Ib9dcdc76095f6718f1cdc83349503f52567c76d4 Reviewed-on: https://go-review.googlesource.com/c/60801 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Hyang-Ah Hana Kim --- src/cmd/trace/mmu.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/cmd/trace/mmu.go b/src/cmd/trace/mmu.go index 062e5ad2ca16e..6a7d28e61de64 100644 --- a/src/cmd/trace/mmu.go +++ b/src/cmd/trace/mmu.go @@ -4,6 +4,25 @@ // Minimum mutator utilization (MMU) graphing. +// TODO: +// +// In worst window list, show break-down of GC utilization sources +// (STW, assist, etc). Probably requires a different MutatorUtil +// representation. +// +// When a window size is selected, show a second plot of the mutator +// utilization distribution for that window size. +// +// Render plot progressively so rough outline is visible quickly even +// for very complex MUTs. Start by computing just a few window sizes +// and then add more window sizes. +// +// Consider using sampling to compute an approximate MUT. This would +// work by sampling the mutator utilization at randomly selected +// points in time in the trace to build an empirical distribution. We +// could potentially put confidence intervals on these estimates and +// render this progressively as we refine the distributions. + package main import ( From 2ae8bf7054b3320682e547396d9b6b5e51f5ade1 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Wed, 17 Oct 2018 20:16:45 +0000 Subject: [PATCH 0976/1663] runtime: fix stale comments about mheap and mspan As of 07e738e all spans are allocated out of a treap, and not just large spans or spans for large objects. Also, now we have a separate treap for spans that have been scavenged. Change-Id: I9c2cb7b6798fc536bbd34835da2e888224fd7ed4 Reviewed-on: https://go-review.googlesource.com/c/142958 Reviewed-by: Austin Clements --- src/runtime/mheap.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index 8f6db8eec52ab..56ec3d4465d6f 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -21,7 +21,7 @@ import ( const minPhysPageSize = 4096 // Main malloc heap. -// The heap itself is the "free[]" and "large" arrays, +// The heap itself is the "free" and "scav" treaps, // but all the other global data is here too. // // mheap must not be heap-allocated because it contains mSpanLists, @@ -147,7 +147,7 @@ type mheap struct { spanalloc fixalloc // allocator for span* cachealloc fixalloc // allocator for mcache* - treapalloc fixalloc // allocator for treapNodes* used by large objects + treapalloc fixalloc // allocator for treapNodes* specialfinalizeralloc fixalloc // allocator for specialfinalizer* specialprofilealloc fixalloc // allocator for specialprofile* speciallock mutex // lock for special record allocators. @@ -198,15 +198,16 @@ type arenaHint struct { // An MSpan is a run of pages. // -// When a MSpan is in the heap free list, state == mSpanFree +// When a MSpan is in the heap free treap, state == mSpanFree // and heapmap(s->start) == span, heapmap(s->start+s->npages-1) == span. +// If the MSpan is in the heap scav treap, then in addition to the +// above scavenged == true. scavenged == false in all other cases. // // When a MSpan is allocated, state == mSpanInUse or mSpanManual // and heapmap(i) == span for all s->start <= i < s->start+s->npages. -// Every MSpan is in one doubly-linked list, -// either one of the MHeap's free lists or one of the -// MCentral's span lists. +// Every MSpan is in one doubly-linked list, either in the MHeap's +// busy list or one of the MCentral's span lists. // An MSpan representing actual memory has state mSpanInUse, // mSpanManual, or mSpanFree. Transitions between these states are @@ -848,7 +849,7 @@ func (h *mheap) setSpans(base, npage uintptr, s *mspan) { // Allocates a span of the given size. h must be locked. // The returned span has been removed from the -// free list, but its state is still mSpanFree. +// free structures, but its state is still mSpanFree. func (h *mheap) allocSpanLocked(npage uintptr, stat *uint64) *mspan { var s *mspan From 3377b4673d6e0ca1a9bba1c7196d7e673ddb8108 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 2 Nov 2018 21:41:41 -0700 Subject: [PATCH 0977/1663] cmd/compile: encapsulate and document two types.Type internal fields Change-Id: I5f7d2155c2c3a47dabdf16fe46b122ede81de4fc Reviewed-on: https://go-review.googlesource.com/c/147284 Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/reflect.go | 2 +- src/cmd/compile/internal/gc/typecheck.go | 6 ++---- src/cmd/compile/internal/types/type.go | 20 ++++++++++++++------ 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/cmd/compile/internal/gc/reflect.go b/src/cmd/compile/internal/gc/reflect.go index 415d3cd5948b7..50b741358f41e 100644 --- a/src/cmd/compile/internal/gc/reflect.go +++ b/src/cmd/compile/internal/gc/reflect.go @@ -812,7 +812,7 @@ func dcommontype(lsym *obj.LSym, t *types.Type) int { sptrWeak := true var sptr *obj.LSym - if !t.IsPtr() || t.PtrBase != nil { + if !t.IsPtr() || t.IsPtrElem() { tptr := types.NewPtr(t) if t.Sym != nil || methods(tptr) != nil { sptrWeak = false diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index be11a9841f0bf..2a595214842d1 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -3671,8 +3671,7 @@ func copytype(n *Node, t *types.Type) { embedlineno := n.Type.ForwardType().Embedlineno l := n.Type.ForwardType().Copyto - ptrBase := n.Type.PtrBase - sliceOf := n.Type.SliceOf + cache := n.Type.Cache // TODO(mdempsky): Fix Type rekinding. *n.Type = *t @@ -3693,8 +3692,7 @@ func copytype(n *Node, t *types.Type) { t.Nod = asTypesNode(n) t.SetDeferwidth(false) - t.PtrBase = ptrBase - t.SliceOf = sliceOf + t.Cache = cache // Propagate go:notinheap pragma from the Name to the Type. if n.Name != nil && n.Name.Param != nil && n.Name.Param.Pragma&NotInHeap != 0 { diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index 39f4d2aa7b06b..b20039239b9cf 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -149,8 +149,11 @@ type Type struct { Nod *Node // canonical OTYPE node Orig *Type // original type (type literal or predefined type) - SliceOf *Type - PtrBase *Type + // Cache of composite types, with this type being the element type. + Cache struct { + ptr *Type // *T, or nil + slice *Type // []T, or nil + } Sym *Sym // symbol containing name, for named types Vargen int32 // unique name for OTYPE/ONAME @@ -488,7 +491,7 @@ func NewArray(elem *Type, bound int64) *Type { // NewSlice returns the slice Type with element type elem. func NewSlice(elem *Type) *Type { - if t := elem.SliceOf; t != nil { + if t := elem.Cache.slice; t != nil { if t.Elem() != elem { Fatalf("elem mismatch") } @@ -497,7 +500,7 @@ func NewSlice(elem *Type) *Type { t := New(TSLICE) t.Extra = Slice{Elem: elem} - elem.SliceOf = t + elem.Cache.slice = t return t } @@ -551,7 +554,7 @@ func NewPtr(elem *Type) *Type { Fatalf("NewPtr: pointer to elem Type is nil") } - if t := elem.PtrBase; t != nil { + if t := elem.Cache.ptr; t != nil { if t.Elem() != elem { Fatalf("NewPtr: elem mismatch") } @@ -563,7 +566,7 @@ func NewPtr(elem *Type) *Type { t.Width = int64(Widthptr) t.Align = uint8(Widthptr) if NewPtrCacheEnabled { - elem.PtrBase = t + elem.Cache.ptr = t } return t } @@ -1258,6 +1261,11 @@ func (t *Type) IsPtr() bool { return t.Etype == TPTR } +// IsPtrElem reports whether t is the element of a pointer (to t). +func (t *Type) IsPtrElem() bool { + return t.Cache.ptr != nil +} + // IsUnsafePtr reports whether t is an unsafe pointer. func (t *Type) IsUnsafePtr() bool { return t.Etype == TUNSAFEPTR From e6305380a067c51223a59baf8a77575595a5f1e6 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 2 Nov 2018 23:28:26 -0700 Subject: [PATCH 0978/1663] cmd/compile: reintroduce work-around for cyclic alias declarations This change re-introduces (temporarily) a work-around for recursive alias type declarations, originally in https://golang.org/cl/35831/ (intended as fix for #18640). The work-around was removed later for a more comprehensive cycle detection check. That check contained a subtle error which made the code appear to work, while in fact creating incorrect types internally. See #25838 for details. By re-introducing the original work-around, we eliminate problems with many simple recursive type declarations involving aliases; specifically cases such as #27232 and #27267. However, the more general problem remains. This CL also fixes the subtle error (incorrect variable use when analyzing a type cycle) mentioned above and now issues a fatal error with a reference to the relevant issue (rather than crashing later during the compilation). While not great, this is better than the current status. The long-term solution will need to address these cycles (see #25838). As a consequence, several old test cases are not accepted anymore by the compiler since they happened to work accidentally only. This CL disables parts or all code of those test cases. The issues are: #18640, #23823, and #24939. One of the new test cases (fixedbugs/issue27232.go) exposed a go/types issue. The test case is excluded from the go/types test suite and an issue was filed (#28576). Updates #18640. Updates #23823. Updates #24939. Updates #25838. Updates #28576. Fixes #27232. Fixes #27267. Change-Id: I6c2d10da98bfc6f4f445c755fcaab17fc7b214c5 Reviewed-on: https://go-review.googlesource.com/c/147286 Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/gc/main.go | 8 ++++++-- src/cmd/compile/internal/gc/typecheck.go | 12 ++++++++++-- src/go/types/stdlib_test.go | 1 + test/fixedbugs/issue18640.go | 5 ++--- test/fixedbugs/issue23823.go | 8 ++++++-- test/fixedbugs/issue24939.go | 4 +++- test/fixedbugs/issue27232.go | 19 +++++++++++++++++++ test/fixedbugs/issue27267.go | 21 +++++++++++++++++++++ 8 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 test/fixedbugs/issue27232.go create mode 100644 test/fixedbugs/issue27267.go diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 49a4e05d99efe..78142d3bf82bc 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -491,13 +491,17 @@ func Main(archInit func(*Arch)) { // Phase 1: const, type, and names and types of funcs. // This will gather all the information about types // and methods but doesn't depend on any of it. + // + // We also defer type alias declarations until phase 2 + // to avoid cycles like #18640. + // TODO(gri) Remove this again once we have a fix for #25838. defercheckwidth() // Don't use range--typecheck can add closures to xtop. timings.Start("fe", "typecheck", "top1") for i := 0; i < len(xtop); i++ { n := xtop[i] - if op := n.Op; op != ODCL && op != OAS && op != OAS2 { + if op := n.Op; op != ODCL && op != OAS && op != OAS2 && (op != ODCLTYPE || !n.Left.Name.Param.Alias) { xtop[i] = typecheck(n, Etop) } } @@ -509,7 +513,7 @@ func Main(archInit func(*Arch)) { timings.Start("fe", "typecheck", "top2") for i := 0; i < len(xtop); i++ { n := xtop[i] - if op := n.Op; op == ODCL || op == OAS || op == OAS2 { + if op := n.Op; op == ODCL || op == OAS || op == OAS2 || op == ODCLTYPE && n.Left.Name.Param.Alias { xtop[i] = typecheck(n, Etop) } } diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 2a595214842d1..06dd176b3718d 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -255,8 +255,16 @@ func typecheck(n *Node, top int) (res *Node) { // since it would expand indefinitely when aliases // are substituted. cycle := cycleFor(n) - for _, n := range cycle { - if n.Name != nil && !n.Name.Param.Alias { + for _, n1 := range cycle { + if n1.Name != nil && !n1.Name.Param.Alias { + // Cycle is ok. But if n is an alias type and doesn't + // have a type yet, we have a recursive type declaration + // with aliases that we can't handle properly yet. + // Report an error rather than crashing later. + if n.Name != nil && n.Name.Param.Alias && n.Type == nil { + lineno = n.Pos + Fatalf("cannot handle alias type declaration (issue #25838): %v", n) + } lineno = lno return n } diff --git a/src/go/types/stdlib_test.go b/src/go/types/stdlib_test.go index 84908fd190c4e..a4ff1ab9a86de 100644 --- a/src/go/types/stdlib_test.go +++ b/src/go/types/stdlib_test.go @@ -180,6 +180,7 @@ func TestStdFixed(t *testing.T) { "issue22200b.go", // go/types does not have constraints on stack size "issue25507.go", // go/types does not have constraints on stack size "issue20780.go", // go/types does not have constraints on stack size + "issue27232.go", // go/types has a bug with alias type (issue #28576) ) } diff --git a/test/fixedbugs/issue18640.go b/test/fixedbugs/issue18640.go index 60abd31f760cf..091bbe596b22b 100644 --- a/test/fixedbugs/issue18640.go +++ b/test/fixedbugs/issue18640.go @@ -20,8 +20,7 @@ type ( d = c ) -// The compiler reports an incorrect (non-alias related) -// type cycle here (via dowith()). Disabled for now. +// The compiler cannot handle these cases. Disabled for now. // See issue #25838. /* type ( @@ -32,7 +31,6 @@ type ( i = j j = e ) -*/ type ( a1 struct{ *b1 } @@ -45,3 +43,4 @@ type ( b2 = c2 c2 struct{ *b2 } ) +*/ diff --git a/test/fixedbugs/issue23823.go b/test/fixedbugs/issue23823.go index 2f802d0988606..9297966cbd6f6 100644 --- a/test/fixedbugs/issue23823.go +++ b/test/fixedbugs/issue23823.go @@ -1,4 +1,4 @@ -// errorcheck +// compile // Copyright 2018 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style @@ -6,10 +6,14 @@ package p +// The compiler cannot handle this. Disabled for now. +// See issue #25838. +/* type I1 = interface { I2 } -type I2 interface { // ERROR "invalid recursive type" +type I2 interface { I1 } +*/ diff --git a/test/fixedbugs/issue24939.go b/test/fixedbugs/issue24939.go index 26530e95b29ee..0ae6f2b9f2600 100644 --- a/test/fixedbugs/issue24939.go +++ b/test/fixedbugs/issue24939.go @@ -15,7 +15,9 @@ type M interface { } type P = interface { - I() M + // The compiler cannot handle this case. Disabled for now. + // See issue #25838. + // I() M } func main() {} diff --git a/test/fixedbugs/issue27232.go b/test/fixedbugs/issue27232.go new file mode 100644 index 0000000000000..3a1cc87e4cb96 --- /dev/null +++ b/test/fixedbugs/issue27232.go @@ -0,0 +1,19 @@ +// compile + +// Copyright 2018 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. + +package p + +type F = func(T) + +type T interface { + m(F) +} + +type t struct{} + +func (t) m(F) {} + +var _ T = &t{} diff --git a/test/fixedbugs/issue27267.go b/test/fixedbugs/issue27267.go new file mode 100644 index 0000000000000..ebae44f48fefc --- /dev/null +++ b/test/fixedbugs/issue27267.go @@ -0,0 +1,21 @@ +// compile + +// Copyright 2018 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. + +package p + +// 1st test case from issue +type F = func(E) // compiles if not type alias or moved below E struct +type E struct { + f F +} + +var x = E{func(E) {}} + +// 2nd test case from issue +type P = *S +type S struct { + p P +} From a540aa338a3145ab32ca4409919c82722f8724f3 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Mon, 5 Nov 2018 10:33:28 -0800 Subject: [PATCH 0979/1663] test: add test that gccgo failed to compile Updates #28601 Change-Id: I734fc5ded153126d384f0df912ecd4d208005e49 Reviewed-on: https://go-review.googlesource.com/c/147537 Run-TryBot: Ian Lance Taylor Reviewed-by: Cherry Zhang --- test/fixedbugs/issue28601.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 test/fixedbugs/issue28601.go diff --git a/test/fixedbugs/issue28601.go b/test/fixedbugs/issue28601.go new file mode 100644 index 0000000000000..ec367e9282d74 --- /dev/null +++ b/test/fixedbugs/issue28601.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2018 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. + +// Failed to compile with gccgo. + +package p + +import "unsafe" + +const w int = int(unsafe.Sizeof(0)) + +var a [w]byte From f1a9f1df5070f69685e269de940c6218f899d228 Mon Sep 17 00:00:00 2001 From: Yury Smolsky Date: Wed, 31 Oct 2018 00:19:35 +0200 Subject: [PATCH 0980/1663] go/doc: inspect function signature for building playground examples This documentation example was broken: https://golang.org/pkg/image/png/#example_Decode. It did not have the "io" package imported, The package was referenced in the result type of the function. The "playExample" function did not inspect the result types of declared functions. This CL adds inspecting of parameters and result types of functions. Fixes #28492 Updates #9679 Change-Id: I6d8b11bad2db8ea8ba69039cfaa914093bdd5132 Reviewed-on: https://go-review.googlesource.com/c/146118 Run-TryBot: Yury Smolsky TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/go/doc/example.go | 12 ++++++++ src/go/doc/example_test.go | 62 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/src/go/doc/example.go b/src/go/doc/example.go index d6d4ece3a8e39..cf3547810ad1b 100644 --- a/src/go/doc/example.go +++ b/src/go/doc/example.go @@ -219,6 +219,18 @@ func playExample(file *ast.File, f *ast.FuncDecl) *ast.File { for i := 0; i < len(depDecls); i++ { switch d := depDecls[i].(type) { case *ast.FuncDecl: + // Inspect types of parameters and results. See #28492. + if d.Type.Params != nil { + for _, p := range d.Type.Params.List { + ast.Inspect(p.Type, inspectFunc) + } + } + if d.Type.Results != nil { + for _, r := range d.Type.Results.List { + ast.Inspect(r.Type, inspectFunc) + } + } + ast.Inspect(d.Body, inspectFunc) case *ast.GenDecl: for _, spec := range d.Specs { diff --git a/src/go/doc/example_test.go b/src/go/doc/example_test.go index 552a51bf74219..0d2bf72e319b6 100644 --- a/src/go/doc/example_test.go +++ b/src/go/doc/example_test.go @@ -351,6 +351,68 @@ func TestExamplesWholeFile(t *testing.T) { } } +const exampleInspectSignature = `package foo_test + +import ( + "bytes" + "io" +) + +func getReader() io.Reader { return nil } + +func do(b bytes.Reader) {} + +func Example() { + getReader() + do() + // Output: +} + +func ExampleIgnored() { +} +` + +const exampleInspectSignatureOutput = `package main + +import ( + "bytes" + "io" +) + +func getReader() io.Reader { return nil } + +func do(b bytes.Reader) {} + +func main() { + getReader() + do() +} +` + +func TestExampleInspectSignature(t *testing.T) { + // Verify that "bytes" and "io" are imported. See issue #28492. + fset := token.NewFileSet() + file, err := parser.ParseFile(fset, "test.go", strings.NewReader(exampleInspectSignature), parser.ParseComments) + if err != nil { + t.Fatal(err) + } + es := doc.Examples(file) + if len(es) != 2 { + t.Fatalf("wrong number of examples; got %d want 2", len(es)) + } + // We are interested in the first example only. + e := es[0] + if e.Name != "" { + t.Errorf("got Name == %q, want %q", e.Name, "") + } + if g, w := formatFile(t, fset, e.Play), exampleInspectSignatureOutput; g != w { + t.Errorf("got Play == %q, want %q", g, w) + } + if g, w := e.Output, ""; g != w { + t.Errorf("got Output == %q, want %q", g, w) + } +} + func formatFile(t *testing.T, fset *token.FileSet, n *ast.File) string { if n == nil { return "" From 9c89923266a372e9357dc3296b6c53bb931dd4a9 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Mon, 5 Nov 2018 12:36:42 -0500 Subject: [PATCH 0981/1663] runtime: deflake TestTracebackAncestors TestTracebackAncestors has a ~0.1% chance of failing with more goroutines in the traceback than expected. This happens because there's a window between each goroutine starting its child and that goroutine actually exiting. The test captures its own stack trace after everything is "done", but if this happens during that window, it will include the goroutine that's in the process of being torn down. Here's an example of such a failure: https://build.golang.org/log/fad10d0625295eb79fa879f53b8b32b9d0596af8 This CL fixes this by recording the goroutines that are expected to exit and removing them from the stack trace. With this fix, this test passed 15,000 times with no failures. Change-Id: I71e7c6282987a15e8b74188b9c585aa2ca97cbcd Reviewed-on: https://go-review.googlesource.com/c/147517 Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- .../testdata/testprog/traceback_ancestors.go | 56 +++++++++++++++++-- 1 file changed, 51 insertions(+), 5 deletions(-) diff --git a/src/runtime/testdata/testprog/traceback_ancestors.go b/src/runtime/testdata/testprog/traceback_ancestors.go index fe57c1c157e68..0ee402c4bdc60 100644 --- a/src/runtime/testdata/testprog/traceback_ancestors.go +++ b/src/runtime/testdata/testprog/traceback_ancestors.go @@ -5,8 +5,10 @@ package main import ( + "bytes" "fmt" "runtime" + "strings" ) func init() { @@ -18,25 +20,50 @@ const numFrames = 2 func TracebackAncestors() { w := make(chan struct{}) - recurseThenCallGo(w, numGoroutines, numFrames) + recurseThenCallGo(w, numGoroutines, numFrames, true) <-w printStack() close(w) } +var ignoreGoroutines = make(map[string]bool) + func printStack() { buf := make([]byte, 1024) for { n := runtime.Stack(buf, true) if n < len(buf) { - fmt.Print(string(buf[:n])) + tb := string(buf[:n]) + + // Delete any ignored goroutines, if present. + pos := 0 + for pos < len(tb) { + next := pos + strings.Index(tb[pos:], "\n\n") + if next < pos { + next = len(tb) + } else { + next += len("\n\n") + } + + if strings.HasPrefix(tb[pos:], "goroutine ") { + id := tb[pos+len("goroutine "):] + id = id[:strings.IndexByte(id, ' ')] + if ignoreGoroutines[id] { + tb = tb[:pos] + tb[next:] + next = pos + } + } + pos = next + } + + fmt.Print(tb) return } buf = make([]byte, 2*len(buf)) } } -func recurseThenCallGo(w chan struct{}, frames int, goroutines int) { +func recurseThenCallGo(w chan struct{}, frames int, goroutines int, main bool) { if frames == 0 { // Signal to TracebackAncestors that we are done recursing and starting goroutines. w <- struct{}{} @@ -44,10 +71,29 @@ func recurseThenCallGo(w chan struct{}, frames int, goroutines int) { return } if goroutines == 0 { + // Record which goroutine this is so we can ignore it + // in the traceback if it hasn't finished exiting by + // the time we printStack. + if !main { + ignoreGoroutines[goroutineID()] = true + } + // Start the next goroutine now that there are no more recursions left // for this current goroutine. - go recurseThenCallGo(w, frames-1, numFrames) + go recurseThenCallGo(w, frames-1, numFrames, false) return } - recurseThenCallGo(w, frames, goroutines-1) + recurseThenCallGo(w, frames, goroutines-1, main) +} + +func goroutineID() string { + buf := make([]byte, 128) + runtime.Stack(buf, false) + const prefix = "goroutine " + if !bytes.HasPrefix(buf, []byte(prefix)) { + panic(fmt.Sprintf("expected %q at beginning of traceback:\n%s", prefix, buf)) + } + buf = buf[len(prefix):] + n := bytes.IndexByte(buf, ' ') + return string(buf[:n]) } From 44dcb5cb61aee5435e0b3c78544a1d3352a4cc98 Mon Sep 17 00:00:00 2001 From: Michael Anthony Knyszek Date: Mon, 5 Nov 2018 19:26:25 +0000 Subject: [PATCH 0982/1663] runtime: clean up MSpan* MCache* MCentral* in docs This change cleans up references to MSpan, MCache, and MCentral in the docs via a bunch of sed invocations to better reflect the Go names for the equivalent structures (i.e. mspan, mcache, mcentral) and their methods (i.e. MSpan_Sweep -> mspan.sweep). Change-Id: Ie911ac975a24bd25200a273086dd835ab78b1711 Reviewed-on: https://go-review.googlesource.com/c/147557 Reviewed-by: Austin Clements Run-TryBot: Austin Clements TryBot-Result: Gobot Gobot --- src/runtime/heapdump.go | 4 ++-- src/runtime/mcache.go | 2 +- src/runtime/mcentral.go | 10 ++++----- src/runtime/mfixalloc.go | 2 +- src/runtime/mgcmark.go | 2 +- src/runtime/mgcsweep.go | 20 +++++++++--------- src/runtime/mheap.go | 44 ++++++++++++++++++++-------------------- src/runtime/mstats.go | 2 +- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/runtime/heapdump.go b/src/runtime/heapdump.go index eadbcaeee12b7..ca56708a04d81 100644 --- a/src/runtime/heapdump.go +++ b/src/runtime/heapdump.go @@ -428,7 +428,7 @@ func dumproots() { dumpmemrange(unsafe.Pointer(firstmoduledata.bss), firstmoduledata.ebss-firstmoduledata.bss) dumpfields(firstmoduledata.gcbssmask) - // MSpan.types + // mspan.types for _, s := range mheap_.allspans { if s.state == mSpanInUse { // Finalizers @@ -661,7 +661,7 @@ func writeheapdump_m(fd uintptr) { _g_.waitreason = waitReasonDumpingHeap // Update stats so we can dump them. - // As a side effect, flushes all the MCaches so the MSpan.freelist + // As a side effect, flushes all the mcaches so the mspan.freelist // lists contain all the free objects. updatememstats() diff --git a/src/runtime/mcache.go b/src/runtime/mcache.go index e20e92cdf47c6..7895e489bccae 100644 --- a/src/runtime/mcache.go +++ b/src/runtime/mcache.go @@ -79,7 +79,7 @@ type stackfreelist struct { size uintptr // total size of stacks in list } -// dummy MSpan that contains no free objects. +// dummy mspan that contains no free objects. var emptymspan mspan func allocmcache() *mcache { diff --git a/src/runtime/mcentral.go b/src/runtime/mcentral.go index f108bfc31e02d..a60eb9fd0ca5b 100644 --- a/src/runtime/mcentral.go +++ b/src/runtime/mcentral.go @@ -6,8 +6,8 @@ // // See malloc.go for an overview. // -// The MCentral doesn't actually contain the list of free objects; the MSpan does. -// Each MCentral is two lists of MSpans: those with free objects (c->nonempty) +// The mcentral doesn't actually contain the list of free objects; the mspan does. +// Each mcentral is two lists of mspans: those with free objects (c->nonempty) // and those that are completely allocated (c->empty). package runtime @@ -36,7 +36,7 @@ func (c *mcentral) init(spc spanClass) { c.empty.init() } -// Allocate a span to use in an MCache. +// Allocate a span to use in an mcache. func (c *mcentral) cacheSpan() *mspan { // Deduct credit for this span allocation and sweep if necessary. spanBytes := uintptr(class_to_allocnpages[c.spanclass.sizeclass()]) * _PageSize @@ -146,7 +146,7 @@ havespan: return s } -// Return span from an MCache. +// Return span from an mcache. func (c *mcentral) uncacheSpan(s *mspan) { if s.allocCount == 0 { throw("uncaching span but s.allocCount == 0") @@ -231,7 +231,7 @@ func (c *mcentral) freeSpan(s *mspan, preserve bool, wasempty bool) bool { } // delay updating sweepgen until here. This is the signal that - // the span may be used in an MCache, so it must come after the + // the span may be used in an mcache, so it must come after the // linked list operations above (actually, just after the // lock of c above.) atomic.Store(&s.sweepgen, mheap_.sweepgen) diff --git a/src/runtime/mfixalloc.go b/src/runtime/mfixalloc.go index 1febe782bb6e4..f9dd6ca474dfc 100644 --- a/src/runtime/mfixalloc.go +++ b/src/runtime/mfixalloc.go @@ -12,7 +12,7 @@ import "unsafe" // FixAlloc is a simple free-list allocator for fixed size objects. // Malloc uses a FixAlloc wrapped around sysAlloc to manage its -// MCache and MSpan objects. +// mcache and mspan objects. // // Memory returned by fixalloc.alloc is zeroed by default, but the // caller may take responsibility for zeroing allocations by setting diff --git a/src/runtime/mgcmark.go b/src/runtime/mgcmark.go index 14f09700eedbf..28260ab7060bb 100644 --- a/src/runtime/mgcmark.go +++ b/src/runtime/mgcmark.go @@ -178,7 +178,7 @@ func markroot(gcw *gcWork, i uint32) { systemstack(markrootFreeGStacks) case baseSpans <= i && i < baseStacks: - // mark MSpan.specials + // mark mspan.specials markrootSpans(gcw, int(i-baseSpans)) default: diff --git a/src/runtime/mgcsweep.go b/src/runtime/mgcsweep.go index 627a6a023f9d8..6733aa9b4a8aa 100644 --- a/src/runtime/mgcsweep.go +++ b/src/runtime/mgcsweep.go @@ -152,7 +152,7 @@ func (s *mspan) ensureSwept() { // (if GC is triggered on another goroutine). _g_ := getg() if _g_.m.locks == 0 && _g_.m.mallocing == 0 && _g_ != _g_.m.g0 { - throw("MSpan_EnsureSwept: m is not locked") + throw("mspan.ensureSwept: m is not locked") } sg := mheap_.sweepgen @@ -178,7 +178,7 @@ func (s *mspan) ensureSwept() { // Sweep frees or collects finalizers for blocks not marked in the mark phase. // It clears the mark bits in preparation for the next GC round. // Returns true if the span was returned to heap. -// If preserve=true, don't return it to heap nor relink in MCentral lists; +// If preserve=true, don't return it to heap nor relink in mcentral lists; // caller takes care of it. //TODO go:nowritebarrier func (s *mspan) sweep(preserve bool) bool { @@ -186,12 +186,12 @@ func (s *mspan) sweep(preserve bool) bool { // GC must not start while we are in the middle of this function. _g_ := getg() if _g_.m.locks == 0 && _g_.m.mallocing == 0 && _g_ != _g_.m.g0 { - throw("MSpan_Sweep: m is not locked") + throw("mspan.sweep: m is not locked") } sweepgen := mheap_.sweepgen if s.state != mSpanInUse || s.sweepgen != sweepgen-1 { - print("MSpan_Sweep: state=", s.state, " sweepgen=", s.sweepgen, " mheap.sweepgen=", sweepgen, "\n") - throw("MSpan_Sweep: bad span state") + print("mspan.sweep: state=", s.state, " sweepgen=", s.sweepgen, " mheap.sweepgen=", sweepgen, "\n") + throw("mspan.sweep: bad span state") } if trace.enabled { @@ -327,8 +327,8 @@ func (s *mspan) sweep(preserve bool) bool { // The span must be in our exclusive ownership until we update sweepgen, // check for potential races. if s.state != mSpanInUse || s.sweepgen != sweepgen-1 { - print("MSpan_Sweep: state=", s.state, " sweepgen=", s.sweepgen, " mheap.sweepgen=", sweepgen, "\n") - throw("MSpan_Sweep: bad span state after sweep") + print("mspan.sweep: state=", s.state, " sweepgen=", s.sweepgen, " mheap.sweepgen=", sweepgen, "\n") + throw("mspan.sweep: bad span state after sweep") } // Serialization point. // At this point the mark bits are cleared and allocation ready @@ -339,7 +339,7 @@ func (s *mspan) sweep(preserve bool) bool { if nfreed > 0 && spc.sizeclass() != 0 { c.local_nsmallfree[spc.sizeclass()] += uintptr(nfreed) res = mheap_.central[spc].mcentral.freeSpan(s, preserve, wasempty) - // MCentral_FreeSpan updates sweepgen + // mcentral.freeSpan updates sweepgen } else if freeToHeap { // Free large span to heap @@ -351,12 +351,12 @@ func (s *mspan) sweep(preserve bool) bool { // calling sysFree here without any kind of adjustment of the // heap data structures means that when the memory does // come back to us, we have the wrong metadata for it, either in - // the MSpan structures or in the garbage collection bitmap. + // the mspan structures or in the garbage collection bitmap. // Using sysFault here means that the program will run out of // memory fairly quickly in efence mode, but at least it won't // have mysterious crashes due to confused memory reuse. // It should be possible to switch back to sysFree if we also - // implement and then call some kind of MHeap_DeleteSpan. + // implement and then call some kind of mheap.deleteSpan. if debug.efence > 0 { s.limit = 0 // prevent mlookup from finding this span sysFault(unsafe.Pointer(s.base()), size) diff --git a/src/runtime/mheap.go b/src/runtime/mheap.go index 56ec3d4465d6f..43f59adb8af28 100644 --- a/src/runtime/mheap.go +++ b/src/runtime/mheap.go @@ -136,8 +136,8 @@ type mheap struct { // _ uint32 // ensure 64-bit alignment of central // central free lists for small size classes. - // the padding makes sure that the MCentrals are - // spaced CacheLinePadSize bytes apart, so that each MCentral.lock + // the padding makes sure that the mcentrals are + // spaced CacheLinePadSize bytes apart, so that each mcentral.lock // gets its own cache line. // central is indexed by spanClass. central [numSpanClasses]struct { @@ -196,20 +196,20 @@ type arenaHint struct { next *arenaHint } -// An MSpan is a run of pages. +// An mspan is a run of pages. // -// When a MSpan is in the heap free treap, state == mSpanFree +// When a mspan is in the heap free treap, state == mSpanFree // and heapmap(s->start) == span, heapmap(s->start+s->npages-1) == span. -// If the MSpan is in the heap scav treap, then in addition to the +// If the mspan is in the heap scav treap, then in addition to the // above scavenged == true. scavenged == false in all other cases. // -// When a MSpan is allocated, state == mSpanInUse or mSpanManual +// When a mspan is allocated, state == mSpanInUse or mSpanManual // and heapmap(i) == span for all s->start <= i < s->start+s->npages. -// Every MSpan is in one doubly-linked list, either in the MHeap's -// busy list or one of the MCentral's span lists. +// Every mspan is in one doubly-linked list, either in the mheap's +// busy list or one of the mcentral's span lists. -// An MSpan representing actual memory has state mSpanInUse, +// An mspan representing actual memory has state mSpanInUse, // mSpanManual, or mSpanFree. Transitions between these states are // constrained as follows: // @@ -880,10 +880,10 @@ func (h *mheap) allocSpanLocked(npage uintptr, stat *uint64) *mspan { HaveSpan: // Mark span in use. if s.state != mSpanFree { - throw("MHeap_AllocLocked - MSpan not free") + throw("mheap.allocLocked - mspan not free") } if s.npages < npage { - throw("MHeap_AllocLocked - bad npages") + throw("mheap.allocLocked - bad npages") } // First, subtract any memory that was released back to @@ -1022,16 +1022,16 @@ func (h *mheap) freeSpanLocked(s *mspan, acctinuse, acctidle bool, unusedsince i switch s.state { case mSpanManual: if s.allocCount != 0 { - throw("MHeap_FreeSpanLocked - invalid stack free") + throw("mheap.freeSpanLocked - invalid stack free") } case mSpanInUse: if s.allocCount != 0 || s.sweepgen != h.sweepgen { - print("MHeap_FreeSpanLocked - span ", s, " ptr ", hex(s.base()), " allocCount ", s.allocCount, " sweepgen ", s.sweepgen, "/", h.sweepgen, "\n") - throw("MHeap_FreeSpanLocked - invalid free") + print("mheap.freeSpanLocked - span ", s, " ptr ", hex(s.base()), " allocCount ", s.allocCount, " sweepgen ", s.sweepgen, "/", h.sweepgen, "\n") + throw("mheap.freeSpanLocked - invalid free") } h.pagesInUse -= uint64(s.npages) default: - throw("MHeap_FreeSpanLocked - invalid span state") + throw("mheap.freeSpanLocked - invalid span state") } if acctinuse { @@ -1251,9 +1251,9 @@ func (list *mSpanList) init() { func (list *mSpanList) remove(span *mspan) { if span.list != list { - print("runtime: failed MSpanList_Remove span.npages=", span.npages, + print("runtime: failed mSpanList.remove span.npages=", span.npages, " span=", span, " prev=", span.prev, " span.list=", span.list, " list=", list, "\n") - throw("MSpanList_Remove") + throw("mSpanList.remove") } if list.first == span { list.first = span.next @@ -1276,8 +1276,8 @@ func (list *mSpanList) isEmpty() bool { func (list *mSpanList) insert(span *mspan) { if span.next != nil || span.prev != nil || span.list != nil { - println("runtime: failed MSpanList_Insert", span, span.next, span.prev, span.list) - throw("MSpanList_Insert") + println("runtime: failed mSpanList.insert", span, span.next, span.prev, span.list) + throw("mSpanList.insert") } span.next = list.first if list.first != nil { @@ -1294,8 +1294,8 @@ func (list *mSpanList) insert(span *mspan) { func (list *mSpanList) insertBack(span *mspan) { if span.next != nil || span.prev != nil || span.list != nil { - println("runtime: failed MSpanList_InsertBack", span, span.next, span.prev, span.list) - throw("MSpanList_InsertBack") + println("runtime: failed mSpanList.insertBack", span, span.next, span.prev, span.list) + throw("mSpanList.insertBack") } span.prev = list.last if list.last != nil { @@ -1523,7 +1523,7 @@ func setprofilebucket(p unsafe.Pointer, b *bucket) { } // Do whatever cleanup needs to be done to deallocate s. It has -// already been unlinked from the MSpan specials list. +// already been unlinked from the mspan specials list. func freespecial(s *special, p unsafe.Pointer, size uintptr) { switch s.kind { case _KindSpecialFinalizer: diff --git a/src/runtime/mstats.go b/src/runtime/mstats.go index fd576b7ae051a..9250865ed180e 100644 --- a/src/runtime/mstats.go +++ b/src/runtime/mstats.go @@ -529,7 +529,7 @@ func updatememstats() { memstats.by_size[i].nfree = 0 } - // Flush MCache's to MCentral. + // Flush mcache's to mcentral. systemstack(flushallmcaches) // Aggregate local stats. From 9e619739fdc4cbaeb00a10ef95ce3e5d6996e8a7 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sat, 3 Nov 2018 09:09:28 -0700 Subject: [PATCH 0983/1663] cmd/compile: copy all fields during SubstAny MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consider these functions: func f(a any) int func g(a any) int Prior to this change, since f and g have identical signatures, they would share a single generated func type. types.SubstAny makes a shallow type copy, even after instantiation, f and g share a single generated Result type. So if you instantiate f with any=T, call dowidth, instantiate g with any=U, and call dowidth, and if sizeof(T) != sizeof(U), then the Offset of the result for f is now wrong. I don't believe this happens at all right now, but it bit me hard when experimenting with some other compiler changes. And it's hard to debug. It results in rare stack corruption, causing problems far from the actual source of the problem. To fix this, change SubstAny to make deep copies of TSTRUCTs. name old alloc/op new alloc/op delta Template 35.3MB ± 0% 35.4MB ± 0% +0.23% (p=0.008 n=5+5) Unicode 29.1MB ± 0% 29.1MB ± 0% +0.16% (p=0.008 n=5+5) GoTypes 122MB ± 0% 122MB ± 0% +0.16% (p=0.008 n=5+5) Compiler 513MB ± 0% 514MB ± 0% +0.19% (p=0.008 n=5+5) SSA 1.94GB ± 0% 1.94GB ± 0% +0.01% (p=0.008 n=5+5) Flate 24.2MB ± 0% 24.2MB ± 0% +0.08% (p=0.008 n=5+5) GoParser 28.5MB ± 0% 28.5MB ± 0% +0.24% (p=0.008 n=5+5) Reflect 86.2MB ± 0% 86.3MB ± 0% +0.09% (p=0.008 n=5+5) Tar 34.9MB ± 0% 34.9MB ± 0% +0.13% (p=0.008 n=5+5) XML 47.0MB ± 0% 47.1MB ± 0% +0.18% (p=0.008 n=5+5) [Geo mean] 80.9MB 81.0MB +0.15% name old allocs/op new allocs/op delta Template 348k ± 0% 349k ± 0% +0.38% (p=0.008 n=5+5) Unicode 340k ± 0% 340k ± 0% +0.21% (p=0.008 n=5+5) GoTypes 1.27M ± 0% 1.28M ± 0% +0.27% (p=0.008 n=5+5) Compiler 4.90M ± 0% 4.92M ± 0% +0.36% (p=0.008 n=5+5) SSA 15.3M ± 0% 15.3M ± 0% +0.03% (p=0.008 n=5+5) Flate 232k ± 0% 233k ± 0% +0.14% (p=0.008 n=5+5) GoParser 291k ± 0% 292k ± 0% +0.42% (p=0.008 n=5+5) Reflect 1.05M ± 0% 1.05M ± 0% +0.14% (p=0.008 n=5+5) Tar 343k ± 0% 344k ± 0% +0.22% (p=0.008 n=5+5) XML 428k ± 0% 430k ± 0% +0.36% (p=0.008 n=5+5) [Geo mean] 807k 809k +0.25% Change-Id: I62134db642206cded01920dc1d8a7da61f7ca0ac Reviewed-on: https://go-review.googlesource.com/c/147038 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Matthew Dempsky --- src/cmd/compile/internal/types/type.go | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/cmd/compile/internal/types/type.go b/src/cmd/compile/internal/types/type.go index b20039239b9cf..45355e5798ce3 100644 --- a/src/cmd/compile/internal/types/type.go +++ b/src/cmd/compile/internal/types/type.go @@ -665,23 +665,18 @@ func SubstAny(t *Type, types *[]*Type) *Type { } case TSTRUCT: + // Make a copy of all fields, including ones whose type does not change. + // This prevents aliasing across functions, which can lead to later + // fields getting their Offset incorrectly overwritten. fields := t.FieldSlice() - var nfs []*Field + nfs := make([]*Field, len(fields)) for i, f := range fields { nft := SubstAny(f.Type, types) - if nft == f.Type { - continue - } - if nfs == nil { - nfs = append([]*Field(nil), fields...) - } nfs[i] = f.Copy() nfs[i].Type = nft } - if nfs != nil { - t = t.copy() - t.SetFields(nfs) - } + t = t.copy() + t.SetFields(nfs) } return t From 5848b6c9b854546473814c8752ee117a71bb8b54 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 29 Oct 2018 13:54:24 -0700 Subject: [PATCH 0984/1663] cmd/compile: shrink specialized convT2x call sites MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit convT2E16 and other specialized type-to-interface routines accept a type/itab argument and return a complete interface value. However, we know enough in the routine to do without the type. And the caller can construct the interface value using the type. Doing so shrinks the call sites of ten of the specialized convT2x routines. It also lets us unify the empty and non-empty interface routines. Cuts 12k off cmd/go. name old time/op new time/op delta ConvT2ESmall-8 2.96ns ± 2% 2.34ns ± 4% -21.01% (p=0.000 n=175+189) ConvT2EUintptr-8 3.00ns ± 3% 2.34ns ± 4% -22.02% (p=0.000 n=189+187) ConvT2ELarge-8 21.3ns ± 7% 21.5ns ± 5% +1.02% (p=0.000 n=200+197) ConvT2ISmall-8 2.99ns ± 4% 2.33ns ± 3% -21.95% (p=0.000 n=193+184) ConvT2IUintptr-8 3.02ns ± 3% 2.33ns ± 3% -22.82% (p=0.000 n=198+190) ConvT2ILarge-8 21.7ns ± 5% 22.2ns ± 4% +2.31% (p=0.000 n=199+198) ConvT2Ezero/zero/16-8 2.96ns ± 2% 2.33ns ± 3% -21.11% (p=0.000 n=174+187) ConvT2Ezero/zero/32-8 2.96ns ± 1% 2.35ns ± 4% -20.62% (p=0.000 n=163+193) ConvT2Ezero/zero/64-8 2.99ns ± 2% 2.34ns ± 4% -21.78% (p=0.000 n=183+188) ConvT2Ezero/zero/str-8 3.27ns ± 3% 2.54ns ± 3% -22.32% (p=0.000 n=195+192) ConvT2Ezero/zero/slice-8 3.46ns ± 4% 2.81ns ± 3% -18.96% (p=0.000 n=197+164) ConvT2Ezero/zero/big-8 88.4ns ±20% 90.0ns ±20% +1.84% (p=0.000 n=196+198) ConvT2Ezero/nonzero/16-8 12.6ns ± 3% 12.3ns ± 3% -2.34% (p=0.000 n=167+196) ConvT2Ezero/nonzero/32-8 12.3ns ± 4% 11.9ns ± 3% -2.95% (p=0.000 n=187+193) ConvT2Ezero/nonzero/64-8 14.2ns ± 6% 13.8ns ± 5% -2.94% (p=0.000 n=198+199) ConvT2Ezero/nonzero/str-8 27.2ns ± 5% 26.8ns ± 5% -1.33% (p=0.000 n=200+198) ConvT2Ezero/nonzero/slice-8 33.3ns ± 8% 33.1ns ± 6% -0.82% (p=0.000 n=199+200) ConvT2Ezero/nonzero/big-8 88.8ns ±22% 90.2ns ±18% +1.58% (p=0.000 n=200+199) Neligible toolspeed impact. name old alloc/op new alloc/op delta Template 35.4MB ± 0% 35.3MB ± 0% -0.06% (p=0.008 n=5+5) Unicode 29.1MB ± 0% 29.1MB ± 0% ~ (p=0.310 n=5+5) GoTypes 122MB ± 0% 122MB ± 0% -0.08% (p=0.008 n=5+5) Compiler 514MB ± 0% 513MB ± 0% -0.02% (p=0.008 n=5+5) SSA 1.94GB ± 0% 1.94GB ± 0% -0.01% (p=0.008 n=5+5) Flate 24.2MB ± 0% 24.2MB ± 0% ~ (p=0.548 n=5+5) GoParser 28.5MB ± 0% 28.5MB ± 0% -0.05% (p=0.016 n=5+5) Reflect 86.3MB ± 0% 86.2MB ± 0% -0.02% (p=0.008 n=5+5) Tar 34.9MB ± 0% 34.9MB ± 0% ~ (p=0.095 n=5+5) XML 47.1MB ± 0% 47.1MB ± 0% -0.05% (p=0.008 n=5+5) [Geo mean] 81.0MB 81.0MB -0.03% name old allocs/op new allocs/op delta Template 349k ± 0% 349k ± 0% -0.08% (p=0.008 n=5+5) Unicode 340k ± 0% 340k ± 0% ~ (p=0.111 n=5+5) GoTypes 1.28M ± 0% 1.28M ± 0% -0.09% (p=0.008 n=5+5) Compiler 4.92M ± 0% 4.92M ± 0% -0.08% (p=0.008 n=5+5) SSA 15.3M ± 0% 15.3M ± 0% -0.03% (p=0.008 n=5+5) Flate 233k ± 0% 233k ± 0% ~ (p=0.500 n=5+5) GoParser 292k ± 0% 292k ± 0% -0.06% (p=0.008 n=5+5) Reflect 1.05M ± 0% 1.05M ± 0% -0.02% (p=0.008 n=5+5) Tar 344k ± 0% 343k ± 0% -0.06% (p=0.008 n=5+5) XML 430k ± 0% 429k ± 0% -0.08% (p=0.008 n=5+5) [Geo mean] 809k 809k -0.05% name old object-bytes new object-bytes delta Template 507kB ± 0% 507kB ± 0% -0.04% (p=0.008 n=5+5) Unicode 225kB ± 0% 225kB ± 0% ~ (all equal) GoTypes 1.85MB ± 0% 1.85MB ± 0% -0.08% (p=0.008 n=5+5) Compiler 6.75MB ± 0% 6.75MB ± 0% +0.01% (p=0.008 n=5+5) SSA 21.4MB ± 0% 21.4MB ± 0% -0.02% (p=0.008 n=5+5) Flate 328kB ± 0% 328kB ± 0% -0.03% (p=0.008 n=5+5) GoParser 403kB ± 0% 402kB ± 0% -0.06% (p=0.008 n=5+5) Reflect 1.41MB ± 0% 1.41MB ± 0% -0.03% (p=0.008 n=5+5) Tar 457kB ± 0% 457kB ± 0% -0.05% (p=0.008 n=5+5) XML 601kB ± 0% 600kB ± 0% -0.16% (p=0.008 n=5+5) [Geo mean] 1.05MB 1.04MB -0.05% Change-Id: I677a4108c0ecd32617549294036aa84f9214c4fe Reviewed-on: https://go-review.googlesource.com/c/147360 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall Reviewed-by: Martin Möhrmann --- src/cmd/compile/internal/gc/builtin.go | 302 +++++++++--------- .../compile/internal/gc/builtin/runtime.go | 22 +- src/cmd/compile/internal/gc/walk.go | 71 ++-- src/runtime/iface.go | 134 +++----- 4 files changed, 242 insertions(+), 287 deletions(-) diff --git a/src/cmd/compile/internal/gc/builtin.go b/src/cmd/compile/internal/gc/builtin.go index 325bf4aa0ec70..4e9f11c8b3205 100644 --- a/src/cmd/compile/internal/gc/builtin.go +++ b/src/cmd/compile/internal/gc/builtin.go @@ -51,110 +51,105 @@ var runtimeDecls = [...]struct { {"decoderune", funcTag, 50}, {"countrunes", funcTag, 51}, {"convI2I", funcTag, 52}, - {"convT2E", funcTag, 53}, - {"convT2E16", funcTag, 52}, - {"convT2E32", funcTag, 52}, - {"convT2E64", funcTag, 52}, - {"convT2Estring", funcTag, 52}, - {"convT2Eslice", funcTag, 52}, - {"convT2Enoptr", funcTag, 53}, - {"convT2I", funcTag, 53}, - {"convT2I16", funcTag, 52}, - {"convT2I32", funcTag, 52}, - {"convT2I64", funcTag, 52}, - {"convT2Istring", funcTag, 52}, - {"convT2Islice", funcTag, 52}, - {"convT2Inoptr", funcTag, 53}, + {"convT16", funcTag, 54}, + {"convT32", funcTag, 54}, + {"convT64", funcTag, 54}, + {"convTstring", funcTag, 54}, + {"convTslice", funcTag, 54}, + {"convT2E", funcTag, 55}, + {"convT2Enoptr", funcTag, 55}, + {"convT2I", funcTag, 55}, + {"convT2Inoptr", funcTag, 55}, {"assertE2I", funcTag, 52}, - {"assertE2I2", funcTag, 54}, + {"assertE2I2", funcTag, 56}, {"assertI2I", funcTag, 52}, - {"assertI2I2", funcTag, 54}, - {"panicdottypeE", funcTag, 55}, - {"panicdottypeI", funcTag, 55}, - {"panicnildottype", funcTag, 56}, - {"ifaceeq", funcTag, 59}, - {"efaceeq", funcTag, 59}, - {"fastrand", funcTag, 61}, - {"makemap64", funcTag, 63}, - {"makemap", funcTag, 64}, - {"makemap_small", funcTag, 65}, - {"mapaccess1", funcTag, 66}, - {"mapaccess1_fast32", funcTag, 67}, - {"mapaccess1_fast64", funcTag, 67}, - {"mapaccess1_faststr", funcTag, 67}, - {"mapaccess1_fat", funcTag, 68}, - {"mapaccess2", funcTag, 69}, - {"mapaccess2_fast32", funcTag, 70}, - {"mapaccess2_fast64", funcTag, 70}, - {"mapaccess2_faststr", funcTag, 70}, - {"mapaccess2_fat", funcTag, 71}, - {"mapassign", funcTag, 66}, - {"mapassign_fast32", funcTag, 67}, - {"mapassign_fast32ptr", funcTag, 67}, - {"mapassign_fast64", funcTag, 67}, - {"mapassign_fast64ptr", funcTag, 67}, - {"mapassign_faststr", funcTag, 67}, - {"mapiterinit", funcTag, 72}, - {"mapdelete", funcTag, 72}, - {"mapdelete_fast32", funcTag, 73}, - {"mapdelete_fast64", funcTag, 73}, - {"mapdelete_faststr", funcTag, 73}, - {"mapiternext", funcTag, 74}, - {"mapclear", funcTag, 75}, - {"makechan64", funcTag, 77}, - {"makechan", funcTag, 78}, - {"chanrecv1", funcTag, 80}, - {"chanrecv2", funcTag, 81}, - {"chansend1", funcTag, 83}, + {"assertI2I2", funcTag, 56}, + {"panicdottypeE", funcTag, 57}, + {"panicdottypeI", funcTag, 57}, + {"panicnildottype", funcTag, 58}, + {"ifaceeq", funcTag, 60}, + {"efaceeq", funcTag, 60}, + {"fastrand", funcTag, 62}, + {"makemap64", funcTag, 64}, + {"makemap", funcTag, 65}, + {"makemap_small", funcTag, 66}, + {"mapaccess1", funcTag, 67}, + {"mapaccess1_fast32", funcTag, 68}, + {"mapaccess1_fast64", funcTag, 68}, + {"mapaccess1_faststr", funcTag, 68}, + {"mapaccess1_fat", funcTag, 69}, + {"mapaccess2", funcTag, 70}, + {"mapaccess2_fast32", funcTag, 71}, + {"mapaccess2_fast64", funcTag, 71}, + {"mapaccess2_faststr", funcTag, 71}, + {"mapaccess2_fat", funcTag, 72}, + {"mapassign", funcTag, 67}, + {"mapassign_fast32", funcTag, 68}, + {"mapassign_fast32ptr", funcTag, 68}, + {"mapassign_fast64", funcTag, 68}, + {"mapassign_fast64ptr", funcTag, 68}, + {"mapassign_faststr", funcTag, 68}, + {"mapiterinit", funcTag, 73}, + {"mapdelete", funcTag, 73}, + {"mapdelete_fast32", funcTag, 74}, + {"mapdelete_fast64", funcTag, 74}, + {"mapdelete_faststr", funcTag, 74}, + {"mapiternext", funcTag, 75}, + {"mapclear", funcTag, 76}, + {"makechan64", funcTag, 78}, + {"makechan", funcTag, 79}, + {"chanrecv1", funcTag, 81}, + {"chanrecv2", funcTag, 82}, + {"chansend1", funcTag, 84}, {"closechan", funcTag, 23}, - {"writeBarrier", varTag, 85}, - {"typedmemmove", funcTag, 86}, - {"typedmemclr", funcTag, 87}, - {"typedslicecopy", funcTag, 88}, - {"selectnbsend", funcTag, 89}, - {"selectnbrecv", funcTag, 90}, - {"selectnbrecv2", funcTag, 92}, - {"selectsetpc", funcTag, 56}, - {"selectgo", funcTag, 93}, + {"writeBarrier", varTag, 86}, + {"typedmemmove", funcTag, 87}, + {"typedmemclr", funcTag, 88}, + {"typedslicecopy", funcTag, 89}, + {"selectnbsend", funcTag, 90}, + {"selectnbrecv", funcTag, 91}, + {"selectnbrecv2", funcTag, 93}, + {"selectsetpc", funcTag, 58}, + {"selectgo", funcTag, 94}, {"block", funcTag, 5}, - {"makeslice", funcTag, 94}, - {"makeslice64", funcTag, 95}, - {"growslice", funcTag, 97}, - {"memmove", funcTag, 98}, - {"memclrNoHeapPointers", funcTag, 99}, - {"memclrHasPointers", funcTag, 99}, - {"memequal", funcTag, 100}, - {"memequal8", funcTag, 101}, - {"memequal16", funcTag, 101}, - {"memequal32", funcTag, 101}, - {"memequal64", funcTag, 101}, - {"memequal128", funcTag, 101}, - {"int64div", funcTag, 102}, - {"uint64div", funcTag, 103}, - {"int64mod", funcTag, 102}, - {"uint64mod", funcTag, 103}, - {"float64toint64", funcTag, 104}, - {"float64touint64", funcTag, 105}, - {"float64touint32", funcTag, 106}, - {"int64tofloat64", funcTag, 107}, - {"uint64tofloat64", funcTag, 108}, - {"uint32tofloat64", funcTag, 109}, - {"complex128div", funcTag, 110}, - {"racefuncenter", funcTag, 111}, + {"makeslice", funcTag, 95}, + {"makeslice64", funcTag, 96}, + {"growslice", funcTag, 98}, + {"memmove", funcTag, 99}, + {"memclrNoHeapPointers", funcTag, 100}, + {"memclrHasPointers", funcTag, 100}, + {"memequal", funcTag, 101}, + {"memequal8", funcTag, 102}, + {"memequal16", funcTag, 102}, + {"memequal32", funcTag, 102}, + {"memequal64", funcTag, 102}, + {"memequal128", funcTag, 102}, + {"int64div", funcTag, 103}, + {"uint64div", funcTag, 104}, + {"int64mod", funcTag, 103}, + {"uint64mod", funcTag, 104}, + {"float64toint64", funcTag, 105}, + {"float64touint64", funcTag, 106}, + {"float64touint32", funcTag, 107}, + {"int64tofloat64", funcTag, 108}, + {"uint64tofloat64", funcTag, 109}, + {"uint32tofloat64", funcTag, 110}, + {"complex128div", funcTag, 111}, + {"racefuncenter", funcTag, 112}, {"racefuncenterfp", funcTag, 5}, {"racefuncexit", funcTag, 5}, - {"raceread", funcTag, 111}, - {"racewrite", funcTag, 111}, - {"racereadrange", funcTag, 112}, - {"racewriterange", funcTag, 112}, - {"msanread", funcTag, 112}, - {"msanwrite", funcTag, 112}, + {"raceread", funcTag, 112}, + {"racewrite", funcTag, 112}, + {"racereadrange", funcTag, 113}, + {"racewriterange", funcTag, 113}, + {"msanread", funcTag, 113}, + {"msanwrite", funcTag, 113}, {"support_popcnt", varTag, 11}, {"support_sse41", varTag, 11}, } func runtimeTypes() []*types.Type { - var typs [113]*types.Type + var typs [114]*types.Type typs[0] = types.Bytetype typs[1] = types.NewPtr(typs[0]) typs[2] = types.Types[TANY] @@ -208,65 +203,66 @@ func runtimeTypes() []*types.Type { typs[50] = functype(nil, []*Node{anonfield(typs[21]), anonfield(typs[32])}, []*Node{anonfield(typs[40]), anonfield(typs[32])}) typs[51] = functype(nil, []*Node{anonfield(typs[21])}, []*Node{anonfield(typs[32])}) typs[52] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2])}, []*Node{anonfield(typs[2])}) - typs[53] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[3])}, []*Node{anonfield(typs[2])}) - typs[54] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2])}, []*Node{anonfield(typs[2]), anonfield(typs[11])}) - typs[55] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[1]), anonfield(typs[1])}, nil) - typs[56] = functype(nil, []*Node{anonfield(typs[1])}, nil) - typs[57] = types.NewPtr(typs[47]) - typs[58] = types.Types[TUNSAFEPTR] - typs[59] = functype(nil, []*Node{anonfield(typs[57]), anonfield(typs[58]), anonfield(typs[58])}, []*Node{anonfield(typs[11])}) - typs[60] = types.Types[TUINT32] - typs[61] = functype(nil, nil, []*Node{anonfield(typs[60])}) - typs[62] = types.NewMap(typs[2], typs[2]) - typs[63] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[3])}, []*Node{anonfield(typs[62])}) - typs[64] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[32]), anonfield(typs[3])}, []*Node{anonfield(typs[62])}) - typs[65] = functype(nil, nil, []*Node{anonfield(typs[62])}) - typs[66] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[62]), anonfield(typs[3])}, []*Node{anonfield(typs[3])}) - typs[67] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[62]), anonfield(typs[2])}, []*Node{anonfield(typs[3])}) - typs[68] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[62]), anonfield(typs[3]), anonfield(typs[1])}, []*Node{anonfield(typs[3])}) - typs[69] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[62]), anonfield(typs[3])}, []*Node{anonfield(typs[3]), anonfield(typs[11])}) - typs[70] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[62]), anonfield(typs[2])}, []*Node{anonfield(typs[3]), anonfield(typs[11])}) - typs[71] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[62]), anonfield(typs[3]), anonfield(typs[1])}, []*Node{anonfield(typs[3]), anonfield(typs[11])}) - typs[72] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[62]), anonfield(typs[3])}, nil) - typs[73] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[62]), anonfield(typs[2])}, nil) - typs[74] = functype(nil, []*Node{anonfield(typs[3])}, nil) - typs[75] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[62])}, nil) - typs[76] = types.NewChan(typs[2], types.Cboth) - typs[77] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15])}, []*Node{anonfield(typs[76])}) - typs[78] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[32])}, []*Node{anonfield(typs[76])}) - typs[79] = types.NewChan(typs[2], types.Crecv) - typs[80] = functype(nil, []*Node{anonfield(typs[79]), anonfield(typs[3])}, nil) - typs[81] = functype(nil, []*Node{anonfield(typs[79]), anonfield(typs[3])}, []*Node{anonfield(typs[11])}) - typs[82] = types.NewChan(typs[2], types.Csend) - typs[83] = functype(nil, []*Node{anonfield(typs[82]), anonfield(typs[3])}, nil) - typs[84] = types.NewArray(typs[0], 3) - typs[85] = tostruct([]*Node{namedfield("enabled", typs[11]), namedfield("pad", typs[84]), namedfield("needed", typs[11]), namedfield("cgo", typs[11]), namedfield("alignme", typs[17])}) - typs[86] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[3]), anonfield(typs[3])}, nil) - typs[87] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[3])}, nil) - typs[88] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2]), anonfield(typs[2])}, []*Node{anonfield(typs[32])}) - typs[89] = functype(nil, []*Node{anonfield(typs[82]), anonfield(typs[3])}, []*Node{anonfield(typs[11])}) - typs[90] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[79])}, []*Node{anonfield(typs[11])}) - typs[91] = types.NewPtr(typs[11]) - typs[92] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[91]), anonfield(typs[79])}, []*Node{anonfield(typs[11])}) - typs[93] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[1]), anonfield(typs[32])}, []*Node{anonfield(typs[32]), anonfield(typs[11])}) - typs[94] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[32]), anonfield(typs[32])}, []*Node{anonfield(typs[58])}) - typs[95] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[15])}, []*Node{anonfield(typs[58])}) - typs[96] = types.NewSlice(typs[2]) - typs[97] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[96]), anonfield(typs[32])}, []*Node{anonfield(typs[96])}) - typs[98] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3]), anonfield(typs[47])}, nil) - typs[99] = functype(nil, []*Node{anonfield(typs[58]), anonfield(typs[47])}, nil) - typs[100] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3]), anonfield(typs[47])}, []*Node{anonfield(typs[11])}) - typs[101] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3])}, []*Node{anonfield(typs[11])}) - typs[102] = functype(nil, []*Node{anonfield(typs[15]), anonfield(typs[15])}, []*Node{anonfield(typs[15])}) - typs[103] = functype(nil, []*Node{anonfield(typs[17]), anonfield(typs[17])}, []*Node{anonfield(typs[17])}) - typs[104] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[15])}) - typs[105] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[17])}) - typs[106] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[60])}) - typs[107] = functype(nil, []*Node{anonfield(typs[15])}, []*Node{anonfield(typs[13])}) - typs[108] = functype(nil, []*Node{anonfield(typs[17])}, []*Node{anonfield(typs[13])}) - typs[109] = functype(nil, []*Node{anonfield(typs[60])}, []*Node{anonfield(typs[13])}) - typs[110] = functype(nil, []*Node{anonfield(typs[19]), anonfield(typs[19])}, []*Node{anonfield(typs[19])}) - typs[111] = functype(nil, []*Node{anonfield(typs[47])}, nil) - typs[112] = functype(nil, []*Node{anonfield(typs[47]), anonfield(typs[47])}, nil) + typs[53] = types.Types[TUNSAFEPTR] + typs[54] = functype(nil, []*Node{anonfield(typs[2])}, []*Node{anonfield(typs[53])}) + typs[55] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[3])}, []*Node{anonfield(typs[2])}) + typs[56] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2])}, []*Node{anonfield(typs[2]), anonfield(typs[11])}) + typs[57] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[1]), anonfield(typs[1])}, nil) + typs[58] = functype(nil, []*Node{anonfield(typs[1])}, nil) + typs[59] = types.NewPtr(typs[47]) + typs[60] = functype(nil, []*Node{anonfield(typs[59]), anonfield(typs[53]), anonfield(typs[53])}, []*Node{anonfield(typs[11])}) + typs[61] = types.Types[TUINT32] + typs[62] = functype(nil, nil, []*Node{anonfield(typs[61])}) + typs[63] = types.NewMap(typs[2], typs[2]) + typs[64] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[3])}, []*Node{anonfield(typs[63])}) + typs[65] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[32]), anonfield(typs[3])}, []*Node{anonfield(typs[63])}) + typs[66] = functype(nil, nil, []*Node{anonfield(typs[63])}) + typs[67] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[63]), anonfield(typs[3])}, []*Node{anonfield(typs[3])}) + typs[68] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[63]), anonfield(typs[2])}, []*Node{anonfield(typs[3])}) + typs[69] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[63]), anonfield(typs[3]), anonfield(typs[1])}, []*Node{anonfield(typs[3])}) + typs[70] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[63]), anonfield(typs[3])}, []*Node{anonfield(typs[3]), anonfield(typs[11])}) + typs[71] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[63]), anonfield(typs[2])}, []*Node{anonfield(typs[3]), anonfield(typs[11])}) + typs[72] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[63]), anonfield(typs[3]), anonfield(typs[1])}, []*Node{anonfield(typs[3]), anonfield(typs[11])}) + typs[73] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[63]), anonfield(typs[3])}, nil) + typs[74] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[63]), anonfield(typs[2])}, nil) + typs[75] = functype(nil, []*Node{anonfield(typs[3])}, nil) + typs[76] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[63])}, nil) + typs[77] = types.NewChan(typs[2], types.Cboth) + typs[78] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15])}, []*Node{anonfield(typs[77])}) + typs[79] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[32])}, []*Node{anonfield(typs[77])}) + typs[80] = types.NewChan(typs[2], types.Crecv) + typs[81] = functype(nil, []*Node{anonfield(typs[80]), anonfield(typs[3])}, nil) + typs[82] = functype(nil, []*Node{anonfield(typs[80]), anonfield(typs[3])}, []*Node{anonfield(typs[11])}) + typs[83] = types.NewChan(typs[2], types.Csend) + typs[84] = functype(nil, []*Node{anonfield(typs[83]), anonfield(typs[3])}, nil) + typs[85] = types.NewArray(typs[0], 3) + typs[86] = tostruct([]*Node{namedfield("enabled", typs[11]), namedfield("pad", typs[85]), namedfield("needed", typs[11]), namedfield("cgo", typs[11]), namedfield("alignme", typs[17])}) + typs[87] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[3]), anonfield(typs[3])}, nil) + typs[88] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[3])}, nil) + typs[89] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[2]), anonfield(typs[2])}, []*Node{anonfield(typs[32])}) + typs[90] = functype(nil, []*Node{anonfield(typs[83]), anonfield(typs[3])}, []*Node{anonfield(typs[11])}) + typs[91] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[80])}, []*Node{anonfield(typs[11])}) + typs[92] = types.NewPtr(typs[11]) + typs[93] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[92]), anonfield(typs[80])}, []*Node{anonfield(typs[11])}) + typs[94] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[1]), anonfield(typs[32])}, []*Node{anonfield(typs[32]), anonfield(typs[11])}) + typs[95] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[32]), anonfield(typs[32])}, []*Node{anonfield(typs[53])}) + typs[96] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[15]), anonfield(typs[15])}, []*Node{anonfield(typs[53])}) + typs[97] = types.NewSlice(typs[2]) + typs[98] = functype(nil, []*Node{anonfield(typs[1]), anonfield(typs[97]), anonfield(typs[32])}, []*Node{anonfield(typs[97])}) + typs[99] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3]), anonfield(typs[47])}, nil) + typs[100] = functype(nil, []*Node{anonfield(typs[53]), anonfield(typs[47])}, nil) + typs[101] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3]), anonfield(typs[47])}, []*Node{anonfield(typs[11])}) + typs[102] = functype(nil, []*Node{anonfield(typs[3]), anonfield(typs[3])}, []*Node{anonfield(typs[11])}) + typs[103] = functype(nil, []*Node{anonfield(typs[15]), anonfield(typs[15])}, []*Node{anonfield(typs[15])}) + typs[104] = functype(nil, []*Node{anonfield(typs[17]), anonfield(typs[17])}, []*Node{anonfield(typs[17])}) + typs[105] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[15])}) + typs[106] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[17])}) + typs[107] = functype(nil, []*Node{anonfield(typs[13])}, []*Node{anonfield(typs[61])}) + typs[108] = functype(nil, []*Node{anonfield(typs[15])}, []*Node{anonfield(typs[13])}) + typs[109] = functype(nil, []*Node{anonfield(typs[17])}, []*Node{anonfield(typs[13])}) + typs[110] = functype(nil, []*Node{anonfield(typs[61])}, []*Node{anonfield(typs[13])}) + typs[111] = functype(nil, []*Node{anonfield(typs[19]), anonfield(typs[19])}, []*Node{anonfield(typs[19])}) + typs[112] = functype(nil, []*Node{anonfield(typs[47])}, nil) + typs[113] = functype(nil, []*Node{anonfield(typs[47]), anonfield(typs[47])}, nil) return typs[:] } diff --git a/src/cmd/compile/internal/gc/builtin/runtime.go b/src/cmd/compile/internal/gc/builtin/runtime.go index e6d174bc4b44a..1eaf332e5020f 100644 --- a/src/cmd/compile/internal/gc/builtin/runtime.go +++ b/src/cmd/compile/internal/gc/builtin/runtime.go @@ -61,23 +61,23 @@ func slicestringcopy(to any, fr any) int func decoderune(string, int) (retv rune, retk int) func countrunes(string) int -// interface conversions +// Non-empty-interface to non-empty-interface conversion. func convI2I(typ *byte, elem any) (ret any) +// Specialized type-to-interface conversion. +// These return only a data pointer. +func convT16(val any) unsafe.Pointer // val must be uint16-like (same size and alignment as a uint16) +func convT32(val any) unsafe.Pointer // val must be uint32-like (same size and alignment as a uint32) +func convT64(val any) unsafe.Pointer // val must be uint64-like (same size and alignment as a uint64 and contains no pointers) +func convTstring(val any) unsafe.Pointer // val must be a string +func convTslice(val any) unsafe.Pointer // val must be a slice + +// Type to empty-interface conversion. func convT2E(typ *byte, elem *any) (ret any) -func convT2E16(typ *byte, val any) (ret any) -func convT2E32(typ *byte, val any) (ret any) -func convT2E64(typ *byte, val any) (ret any) -func convT2Estring(typ *byte, val any) (ret any) // val must be a string -func convT2Eslice(typ *byte, val any) (ret any) // val must be a slice func convT2Enoptr(typ *byte, elem *any) (ret any) +// Type to non-empty-interface conversion. func convT2I(tab *byte, elem *any) (ret any) -func convT2I16(tab *byte, val any) (ret any) -func convT2I32(tab *byte, val any) (ret any) -func convT2I64(tab *byte, val any) (ret any) -func convT2Istring(tab *byte, val any) (ret any) // val must be a string -func convT2Islice(tab *byte, val any) (ret any) // val must be a slice func convT2Inoptr(tab *byte, elem *any) (ret any) // interface type assertions x.(T) diff --git a/src/cmd/compile/internal/gc/walk.go b/src/cmd/compile/internal/gc/walk.go index 0e07efa0d9965..fd484a647244a 100644 --- a/src/cmd/compile/internal/gc/walk.go +++ b/src/cmd/compile/internal/gc/walk.go @@ -384,41 +384,31 @@ func convFuncName(from, to *types.Type) (fnname string, needsaddr bool) { tkind := to.Tie() switch from.Tie() { case 'I': - switch tkind { - case 'I': + if tkind == 'I' { return "convI2I", false } case 'T': + switch { + case from.Size() == 2 && from.Align == 2: + return "convT16", false + case from.Size() == 4 && from.Align == 4 && !types.Haspointers(from): + return "convT32", false + case from.Size() == 8 && from.Align == types.Types[TUINT64].Align && !types.Haspointers(from): + return "convT64", false + case from.IsString(): + return "convTstring", false + case from.IsSlice(): + return "convTslice", false + } + switch tkind { case 'E': - switch { - case from.Size() == 2 && from.Align == 2: - return "convT2E16", false - case from.Size() == 4 && from.Align == 4 && !types.Haspointers(from): - return "convT2E32", false - case from.Size() == 8 && from.Align == types.Types[TUINT64].Align && !types.Haspointers(from): - return "convT2E64", false - case from.IsString(): - return "convT2Estring", false - case from.IsSlice(): - return "convT2Eslice", false - case !types.Haspointers(from): + if !types.Haspointers(from) { return "convT2Enoptr", true } return "convT2E", true case 'I': - switch { - case from.Size() == 2 && from.Align == 2: - return "convT2I16", false - case from.Size() == 4 && from.Align == 4 && !types.Haspointers(from): - return "convT2I32", false - case from.Size() == 8 && from.Align == types.Types[TUINT64].Align && !types.Haspointers(from): - return "convT2I64", false - case from.IsString(): - return "convT2Istring", false - case from.IsSlice(): - return "convT2Islice", false - case !types.Haspointers(from): + if !types.Haspointers(from) { return "convT2Inoptr", true } return "convT2I", true @@ -925,6 +915,34 @@ opswitch: break } + fnname, needsaddr := convFuncName(n.Left.Type, n.Type) + + if !needsaddr && !n.Left.Type.IsInterface() { + // Use a specialized conversion routine that only returns a data pointer. + // ptr = convT2X(val) + // e = iface{typ/tab, ptr} + fn := syslook(fnname) + dowidth(n.Left.Type) + fn = substArgTypes(fn, n.Left.Type) + dowidth(fn.Type) + call := nod(OCALL, fn, nil) + call.List.Set1(n.Left) + call = typecheck(call, Erv) + call = walkexpr(call, init) + call = safeexpr(call, init) + var tab *Node + if n.Type.IsEmptyInterface() { + tab = typename(n.Left.Type) + } else { + tab = itabname(n.Left.Type, n.Type) + } + e := nod(OEFACE, tab, call) + e.Type = n.Type + e.SetTypecheck(1) + n = e + break + } + var ll []*Node if n.Type.IsEmptyInterface() { if !n.Left.Type.IsInterface() { @@ -938,7 +956,6 @@ opswitch: } } - fnname, needsaddr := convFuncName(n.Left.Type, n.Type) v := n.Left if needsaddr { // Types of large or unknown size are passed by reference. diff --git a/src/runtime/iface.go b/src/runtime/iface.go index 1ef9825a486cc..8eca2e849d511 100644 --- a/src/runtime/iface.go +++ b/src/runtime/iface.go @@ -267,6 +267,34 @@ func panicnildottype(want *_type) { // Just to match other nil conversion errors, we don't for now. } +// The specialized convTx routines need a type descriptor to use when calling mallocgc. +// We don't need the type to be exact, just to have the correct size, alignment, and pointer-ness. +// However, when debugging, it'd be nice to have some indication in mallocgc where the types came from, +// so we use named types here. +// We then construct interface values of these types, +// and then extract the type word to use as needed. +type ( + uint16InterfacePtr uint16 + uint32InterfacePtr uint32 + uint64InterfacePtr uint64 + stringInterfacePtr string + sliceInterfacePtr []byte +) + +var ( + uint16Eface interface{} = uint16InterfacePtr(0) + uint32Eface interface{} = uint32InterfacePtr(0) + uint64Eface interface{} = uint64InterfacePtr(0) + stringEface interface{} = stringInterfacePtr("") + sliceEface interface{} = sliceInterfacePtr(nil) + + uint16Type *_type = (*eface)(unsafe.Pointer(&uint16Eface))._type + uint32Type *_type = (*eface)(unsafe.Pointer(&uint32Eface))._type + uint64Type *_type = (*eface)(unsafe.Pointer(&uint64Eface))._type + stringType *_type = (*eface)(unsafe.Pointer(&stringEface))._type + sliceType *_type = (*eface)(unsafe.Pointer(&sliceEface))._type +) + // The conv and assert functions below do very similar things. // The convXXX functions are guaranteed by the compiler to succeed. // The assertXXX functions may fail (either panicking or returning false, @@ -290,69 +318,54 @@ func convT2E(t *_type, elem unsafe.Pointer) (e eface) { return } -func convT2E16(t *_type, val uint16) (e eface) { - var x unsafe.Pointer +func convT16(val uint16) (x unsafe.Pointer) { if val == 0 { x = unsafe.Pointer(&zeroVal[0]) } else { - x = mallocgc(2, t, false) + x = mallocgc(2, uint16Type, false) *(*uint16)(x) = val } - e._type = t - e.data = x return } -func convT2E32(t *_type, val uint32) (e eface) { - var x unsafe.Pointer +func convT32(val uint32) (x unsafe.Pointer) { if val == 0 { x = unsafe.Pointer(&zeroVal[0]) } else { - x = mallocgc(4, t, false) + x = mallocgc(4, uint32Type, false) *(*uint32)(x) = val } - e._type = t - e.data = x return } -func convT2E64(t *_type, val uint64) (e eface) { - var x unsafe.Pointer +func convT64(val uint64) (x unsafe.Pointer) { if val == 0 { x = unsafe.Pointer(&zeroVal[0]) } else { - x = mallocgc(8, t, false) + x = mallocgc(8, uint64Type, false) *(*uint64)(x) = val } - e._type = t - e.data = x return } -func convT2Estring(t *_type, val string) (e eface) { - var x unsafe.Pointer +func convTstring(val string) (x unsafe.Pointer) { if val == "" { x = unsafe.Pointer(&zeroVal[0]) } else { - x = mallocgc(unsafe.Sizeof(val), t, true) + x = mallocgc(unsafe.Sizeof(val), stringType, true) *(*string)(x) = val } - e._type = t - e.data = x return } -func convT2Eslice(t *_type, val []byte) (e eface) { +func convTslice(val []byte) (x unsafe.Pointer) { // Note: this must work for any element type, not just byte. - var x unsafe.Pointer if (*slice)(unsafe.Pointer(&val)).array == nil { x = unsafe.Pointer(&zeroVal[0]) } else { - x = mallocgc(unsafe.Sizeof(val), t, true) + x = mallocgc(unsafe.Sizeof(val), sliceType, true) *(*[]byte)(x) = val } - e._type = t - e.data = x return } @@ -385,77 +398,6 @@ func convT2I(tab *itab, elem unsafe.Pointer) (i iface) { return } -func convT2I16(tab *itab, val uint16) (i iface) { - t := tab._type - var x unsafe.Pointer - if val == 0 { - x = unsafe.Pointer(&zeroVal[0]) - } else { - x = mallocgc(2, t, false) - *(*uint16)(x) = val - } - i.tab = tab - i.data = x - return -} - -func convT2I32(tab *itab, val uint32) (i iface) { - t := tab._type - var x unsafe.Pointer - if val == 0 { - x = unsafe.Pointer(&zeroVal[0]) - } else { - x = mallocgc(4, t, false) - *(*uint32)(x) = val - } - i.tab = tab - i.data = x - return -} - -func convT2I64(tab *itab, val uint64) (i iface) { - t := tab._type - var x unsafe.Pointer - if val == 0 { - x = unsafe.Pointer(&zeroVal[0]) - } else { - x = mallocgc(8, t, false) - *(*uint64)(x) = val - } - i.tab = tab - i.data = x - return -} - -func convT2Istring(tab *itab, val string) (i iface) { - t := tab._type - var x unsafe.Pointer - if val == "" { - x = unsafe.Pointer(&zeroVal[0]) - } else { - x = mallocgc(unsafe.Sizeof(val), t, true) - *(*string)(x) = val - } - i.tab = tab - i.data = x - return -} - -func convT2Islice(tab *itab, val []byte) (i iface) { - // Note: this must work for any element type, not just byte. - t := tab._type - var x unsafe.Pointer - if (*slice)(unsafe.Pointer(&val)).array == nil { - x = unsafe.Pointer(&zeroVal[0]) - } else { - x = mallocgc(unsafe.Sizeof(val), t, true) - *(*[]byte)(x) = val - } - i.tab = tab - i.data = x - return -} - func convT2Inoptr(tab *itab, elem unsafe.Pointer) (i iface) { t := tab._type if raceenabled { From 9fc22d29092933460fe00bdaccea179f29e9960d Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 2 Nov 2018 11:23:54 +0100 Subject: [PATCH 0985/1663] net: update zoneCache on cache misses to cover appearing interfaces performance differences are in measurement noise as per benchcmp: benchmark old ns/op new ns/op delta BenchmarkUDP6LinkLocalUnicast-12 5012 5009 -0.06% Fixes #28535 Change-Id: Id022e2ed089ce8388a2398e755848ec94e77e653 Reviewed-on: https://go-review.googlesource.com/c/146941 Run-TryBot: Mikio Hara Reviewed-by: Mikio Hara --- src/net/interface.go | 40 ++++++++++++++++++++++++--------- src/net/interface_bsd_test.go | 5 +++++ src/net/interface_linux_test.go | 25 +++++++++++++++++++++ src/net/interface_unix_test.go | 34 ++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 10 deletions(-) diff --git a/src/net/interface.go b/src/net/interface.go index 375a4568e3f28..46b0400f2f5ec 100644 --- a/src/net/interface.go +++ b/src/net/interface.go @@ -102,7 +102,7 @@ func Interfaces() ([]Interface, error) { return nil, &OpError{Op: "route", Net: "ip+net", Source: nil, Addr: nil, Err: err} } if len(ift) != 0 { - zoneCache.update(ift) + zoneCache.update(ift, false) } return ift, nil } @@ -159,7 +159,7 @@ func InterfaceByName(name string) (*Interface, error) { return nil, &OpError{Op: "route", Net: "ip+net", Source: nil, Addr: nil, Err: err} } if len(ift) != 0 { - zoneCache.update(ift) + zoneCache.update(ift, false) } for _, ifi := range ift { if name == ifi.Name { @@ -187,18 +187,21 @@ var zoneCache = ipv6ZoneCache{ toName: make(map[int]string), } -func (zc *ipv6ZoneCache) update(ift []Interface) { +// update refreshes the network interface information if the cache was last +// updated more than 1 minute ago, or if force is set. It returns whether the +// cache was updated. +func (zc *ipv6ZoneCache) update(ift []Interface, force bool) (updated bool) { zc.Lock() defer zc.Unlock() now := time.Now() - if zc.lastFetched.After(now.Add(-60 * time.Second)) { - return + if !force && zc.lastFetched.After(now.Add(-60*time.Second)) { + return false } zc.lastFetched = now if len(ift) == 0 { var err error if ift, err = interfaceTable(0); err != nil { - return + return false } } zc.toIndex = make(map[string]int, len(ift)) @@ -209,16 +212,25 @@ func (zc *ipv6ZoneCache) update(ift []Interface) { zc.toName[ifi.Index] = ifi.Name } } + return true } func (zc *ipv6ZoneCache) name(index int) string { if index == 0 { return "" } - zoneCache.update(nil) + updated := zoneCache.update(nil, false) zoneCache.RLock() - defer zoneCache.RUnlock() name, ok := zoneCache.toName[index] + zoneCache.RUnlock() + if !ok { + if !updated { + zoneCache.update(nil, true) + zoneCache.RLock() + name, ok = zoneCache.toName[index] + zoneCache.RUnlock() + } + } if !ok { name = uitoa(uint(index)) } @@ -229,10 +241,18 @@ func (zc *ipv6ZoneCache) index(name string) int { if name == "" { return 0 } - zoneCache.update(nil) + updated := zoneCache.update(nil, false) zoneCache.RLock() - defer zoneCache.RUnlock() index, ok := zoneCache.toIndex[name] + zoneCache.RUnlock() + if !ok { + if !updated { + zoneCache.update(nil, true) + zoneCache.RLock() + index, ok = zoneCache.toIndex[name] + zoneCache.RUnlock() + } + } if !ok { index, _, _ = dtoi(name) } diff --git a/src/net/interface_bsd_test.go b/src/net/interface_bsd_test.go index 69b0fbcab3de3..947dde71e61b2 100644 --- a/src/net/interface_bsd_test.go +++ b/src/net/interface_bsd_test.go @@ -7,6 +7,7 @@ package net import ( + "errors" "fmt" "os/exec" "runtime" @@ -53,3 +54,7 @@ func (ti *testInterface) setPointToPoint(suffix int) error { }) return nil } + +func (ti *testInterface) setLinkLocal(suffix int) error { + return errors.New("not yet implemented for BSD") +} diff --git a/src/net/interface_linux_test.go b/src/net/interface_linux_test.go index 6959ddb3d930f..0699fec636833 100644 --- a/src/net/interface_linux_test.go +++ b/src/net/interface_linux_test.go @@ -35,6 +35,31 @@ func (ti *testInterface) setBroadcast(suffix int) error { return nil } +func (ti *testInterface) setLinkLocal(suffix int) error { + ti.name = fmt.Sprintf("gotest%d", suffix) + xname, err := exec.LookPath("ip") + if err != nil { + return err + } + ti.setupCmds = append(ti.setupCmds, &exec.Cmd{ + Path: xname, + Args: []string{"ip", "link", "add", ti.name, "type", "dummy"}, + }) + ti.setupCmds = append(ti.setupCmds, &exec.Cmd{ + Path: xname, + Args: []string{"ip", "address", "add", ti.local, "dev", ti.name}, + }) + ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{ + Path: xname, + Args: []string{"ip", "address", "del", ti.local, "dev", ti.name}, + }) + ti.teardownCmds = append(ti.teardownCmds, &exec.Cmd{ + Path: xname, + Args: []string{"ip", "link", "delete", ti.name, "type", "dummy"}, + }) + return nil +} + func (ti *testInterface) setPointToPoint(suffix int) error { ti.name = fmt.Sprintf("gotest%d", suffix) xname, err := exec.LookPath("ip") diff --git a/src/net/interface_unix_test.go b/src/net/interface_unix_test.go index c3d981dc5c54b..20e75cd036795 100644 --- a/src/net/interface_unix_test.go +++ b/src/net/interface_unix_test.go @@ -176,3 +176,37 @@ func TestInterfaceArrivalAndDeparture(t *testing.T) { } } } + +func TestInterfaceArrivalAndDepartureZoneCache(t *testing.T) { + if testing.Short() { + t.Skip("avoid external network") + } + if os.Getuid() != 0 { + t.Skip("must be root") + } + + // Ensure zoneCache is filled: + _, _ = Listen("tcp", "[fe80::1%nonexistant]:0") + + ti := &testInterface{local: "fe80::1"} + if err := ti.setLinkLocal(0); err != nil { + t.Skipf("test requires external command: %v", err) + } + if err := ti.setup(); err != nil { + t.Fatal(err) + } + defer ti.teardown() + + time.Sleep(3 * time.Millisecond) + + // If Listen fails (on Linux with “bind: invalid argument”), zoneCache was + // not updated when encountering a nonexistant interface: + ln, err := Listen("tcp", "[fe80::1%"+ti.name+"]:0") + if err != nil { + t.Fatal(err) + } + ln.Close() + if err := ti.teardown(); err != nil { + t.Fatal(err) + } +} From c1a16b7dadfee27b03a2a70a20c3cf339a069a40 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Sun, 28 Oct 2018 11:19:33 -0700 Subject: [PATCH 0986/1663] cmd/compile: loop in disjoint OpOffPtr check We collapse OpOffPtrs during generic rewrites. However, we also use disjoint at the same time. Instead of waiting for all OpOffPtrs to be collapsed before the disjointness rules can kick in, burrow through all OpOffPtrs immediately. Change-Id: I60d0a70a9b4605b1817db7c4aab0c0d789651c90 Reviewed-on: https://go-review.googlesource.com/c/145206 Run-TryBot: Josh Bleecher Snyder Reviewed-by: Michael Munday Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/rewrite.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmd/compile/internal/ssa/rewrite.go b/src/cmd/compile/internal/ssa/rewrite.go index ed5bce861e48b..17d7cb341412b 100644 --- a/src/cmd/compile/internal/ssa/rewrite.go +++ b/src/cmd/compile/internal/ssa/rewrite.go @@ -542,7 +542,7 @@ func disjoint(p1 *Value, n1 int64, p2 *Value, n2 int64) bool { } baseAndOffset := func(ptr *Value) (base *Value, offset int64) { base, offset = ptr, 0 - if base.Op == OpOffPtr { + for base.Op == OpOffPtr { offset += base.AuxInt base = base.Args[0] } From 510eea2dfcabbc8916c7c59aa37046269ad29497 Mon Sep 17 00:00:00 2001 From: Mikio Hara Date: Tue, 6 Nov 2018 12:48:17 +0900 Subject: [PATCH 0987/1663] net/http: update bundled SOCKS client Updates socks_bundle.go to git rev 26e67e7 for: - 26e67e7 internal/socks: fix socket descriptor leakage in Dialer.Dial Change-Id: I9ab27a85504d77f1ca2e97cb005f5e37fd3c3ff4 Reviewed-on: https://go-review.googlesource.com/c/147717 Run-TryBot: Mikio Hara Reviewed-by: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- src/net/http/socks_bundle.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/net/http/socks_bundle.go b/src/net/http/socks_bundle.go index e4314b4128306..e6640dd404df2 100644 --- a/src/net/http/socks_bundle.go +++ b/src/net/http/socks_bundle.go @@ -380,6 +380,7 @@ func (d *socksDialer) Dial(network, address string) (net.Conn, error) { return nil, &net.OpError{Op: d.cmd.String(), Net: network, Source: proxy, Addr: dst, Err: err} } if _, err := d.DialWithConn(context.Background(), c, network, address); err != nil { + c.Close() return nil, err } return c, nil From 0e4a0b93d25f56eda3b6026a98bdee4cf6fc7b8f Mon Sep 17 00:00:00 2001 From: Raghavendra Nagaraj Date: Tue, 6 Nov 2018 09:02:03 +0000 Subject: [PATCH 0988/1663] reflect: fix StructOf panics from too many methods in embedded fields Previously we panicked if the number of methods present for an embedded field was >= 32. This change removes that limit and now StructOf dynamically calls itself to create space for the number of methods. Fixes #25402 Change-Id: I3b1deb119796d25f7e6eee1cdb126327b49a0b5e GitHub-Last-Rev: 16da71ad6b23563f3ed26f1914adf41e3d42de69 GitHub-Pull-Request: golang/go#26865 Reviewed-on: https://go-review.googlesource.com/c/128479 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/reflect/all_test.go | 11 ++++++ src/reflect/type.go | 79 ++++++++++------------------------------- 2 files changed, 30 insertions(+), 60 deletions(-) diff --git a/src/reflect/all_test.go b/src/reflect/all_test.go index c463b61c57b89..4b215f120c963 100644 --- a/src/reflect/all_test.go +++ b/src/reflect/all_test.go @@ -5019,6 +5019,17 @@ func TestStructOfWithInterface(t *testing.T) { }) } +func TestStructOfTooManyFields(t *testing.T) { + // Bug Fix: #25402 - this should not panic + tt := StructOf([]StructField{ + {Name: "Time", Type: TypeOf(time.Time{}), Anonymous: true}, + }) + + if _, present := tt.MethodByName("After"); !present { + t.Errorf("Expected method `After` to be found") + } +} + func TestChanOf(t *testing.T) { // check construction and use of type not in binary type T string diff --git a/src/reflect/type.go b/src/reflect/type.go index a04234ca69282..5bbab79fc0775 100644 --- a/src/reflect/type.go +++ b/src/reflect/type.go @@ -1889,6 +1889,8 @@ func MapOf(key, elem Type) Type { return ti.(Type) } +// TODO(crawshaw): as these funcTypeFixedN structs have no methods, +// they could be defined at runtime using the StructOf function. type funcTypeFixed4 struct { funcType args [4]*rtype @@ -2278,42 +2280,6 @@ type structTypeUncommon struct { u uncommonType } -// A *rtype representing a struct is followed directly in memory by an -// array of method objects representing the methods attached to the -// struct. To get the same layout for a run time generated type, we -// need an array directly following the uncommonType memory. The types -// structTypeFixed4, ...structTypeFixedN are used to do this. -// -// A similar strategy is used for funcTypeFixed4, ...funcTypeFixedN. - -// TODO(crawshaw): as these structTypeFixedN and funcTypeFixedN structs -// have no methods, they could be defined at runtime using the StructOf -// function. - -type structTypeFixed4 struct { - structType - u uncommonType - m [4]method -} - -type structTypeFixed8 struct { - structType - u uncommonType - m [8]method -} - -type structTypeFixed16 struct { - structType - u uncommonType - m [16]method -} - -type structTypeFixed32 struct { - structType - u uncommonType - m [32]method -} - // isLetter reports whether a given 'rune' is classified as a Letter. func isLetter(ch rune) bool { return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_' || ch >= utf8.RuneSelf && unicode.IsLetter(ch) @@ -2571,33 +2537,26 @@ func StructOf(fields []StructField) Type { var typ *structType var ut *uncommonType - switch { - case len(methods) == 0: + if len(methods) == 0 { t := new(structTypeUncommon) typ = &t.structType ut = &t.u - case len(methods) <= 4: - t := new(structTypeFixed4) - typ = &t.structType - ut = &t.u - copy(t.m[:], methods) - case len(methods) <= 8: - t := new(structTypeFixed8) - typ = &t.structType - ut = &t.u - copy(t.m[:], methods) - case len(methods) <= 16: - t := new(structTypeFixed16) - typ = &t.structType - ut = &t.u - copy(t.m[:], methods) - case len(methods) <= 32: - t := new(structTypeFixed32) - typ = &t.structType - ut = &t.u - copy(t.m[:], methods) - default: - panic("reflect.StructOf: too many methods") + } else { + // A *rtype representing a struct is followed directly in memory by an + // array of method objects representing the methods attached to the + // struct. To get the same layout for a run time generated type, we + // need an array directly following the uncommonType memory. + // A similar strategy is used for funcTypeFixed4, ...funcTypeFixedN. + tt := New(StructOf([]StructField{ + {Name: "S", Type: TypeOf(structType{})}, + {Name: "U", Type: TypeOf(uncommonType{})}, + {Name: "M", Type: ArrayOf(len(methods), TypeOf(methods[0]))}, + })) + + typ = (*structType)(unsafe.Pointer(tt.Elem().Field(0).UnsafeAddr())) + ut = (*uncommonType)(unsafe.Pointer(tt.Elem().Field(1).UnsafeAddr())) + + copy(tt.Elem().Field(2).Slice(0, len(methods)).Interface().([]method), methods) } // TODO(sbinet): Once we allow embedding multiple types, // methods will need to be sorted like the compiler does. From e1978a2d7a6deac29aa778a17a1cbea25586abc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Chigot?= Date: Fri, 2 Nov 2018 13:14:07 +0100 Subject: [PATCH 0989/1663] cmd/compile/internal/gc: update cgo_import_dynamic for AIX On AIX, cmd/link needs two information in order to generate a dynamic import, the library and its object needed. Currently, cmd/link isn't able to retrieve this object only with the name of the library. Therefore, the library pattern in cgo_import_dynamic must be "lib.a/obj.o". Change-Id: Ib8b8aaa9807c9fa6af46ece4e312d58073ed6ec1 Reviewed-on: https://go-review.googlesource.com/c/146957 Run-TryBot: Ian Lance Taylor TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- src/cmd/cgo/doc.go | 4 ++ src/cmd/compile/internal/gc/lex.go | 8 ++++ src/cmd/compile/internal/gc/lex_test.go | 56 ++++++++++++++++++++----- 3 files changed, 57 insertions(+), 11 deletions(-) diff --git a/src/cmd/cgo/doc.go b/src/cmd/cgo/doc.go index 157cd94d653ab..08d64130df436 100644 --- a/src/cmd/cgo/doc.go +++ b/src/cmd/cgo/doc.go @@ -827,6 +827,10 @@ The directives are: possibly version in the dynamic library, and the optional "" names the specific library where the symbol should be found. + On AIX, the library pattern is slightly different. It must be + "lib.a/obj.o" with obj.o the member of this library exporting + this symbol. + In the , # or @ can be used to introduce a symbol version. Examples: diff --git a/src/cmd/compile/internal/gc/lex.go b/src/cmd/compile/internal/gc/lex.go index 3b302a5124bd0..bd68ebffff0a2 100644 --- a/src/cmd/compile/internal/gc/lex.go +++ b/src/cmd/compile/internal/gc/lex.go @@ -114,6 +114,14 @@ func (p *noder) pragcgo(pos syntax.Pos, text string) { case len(f) == 3 && !isQuoted(f[1]) && !isQuoted(f[2]): case len(f) == 4 && !isQuoted(f[1]) && !isQuoted(f[2]) && isQuoted(f[3]): f[3] = strings.Trim(f[3], `"`) + if objabi.GOOS == "aix" && f[3] != "" { + // On Aix, library pattern must be "lib.a/object.o" + n := strings.Split(f[3], "/") + if len(n) != 2 || !strings.HasSuffix(n[0], ".a") || !strings.HasSuffix(n[1], ".o") { + p.error(syntax.Error{Pos: pos, Msg: `usage: //go:cgo_import_dynamic local [remote ["lib.a/object.o"]]`}) + return + } + } default: p.error(syntax.Error{Pos: pos, Msg: `usage: //go:cgo_import_dynamic local [remote ["library"]]`}) return diff --git a/src/cmd/compile/internal/gc/lex_test.go b/src/cmd/compile/internal/gc/lex_test.go index fecf570fa1615..e05726c9f35fa 100644 --- a/src/cmd/compile/internal/gc/lex_test.go +++ b/src/cmd/compile/internal/gc/lex_test.go @@ -7,6 +7,7 @@ package gc import ( "cmd/compile/internal/syntax" "reflect" + "runtime" "testing" ) @@ -49,10 +50,12 @@ func TestPragmaFields(t *testing.T) { } func TestPragcgo(t *testing.T) { - var tests = []struct { + type testStruct struct { in string want []string - }{ + } + + var tests = []testStruct{ {`go:cgo_export_dynamic local`, []string{`cgo_export_dynamic`, `local`}}, {`go:cgo_export_dynamic local remote`, []string{`cgo_export_dynamic`, `local`, `remote`}}, {`go:cgo_export_dynamic local' remote'`, []string{`cgo_export_dynamic`, `local'`, `remote'`}}, @@ -61,8 +64,6 @@ func TestPragcgo(t *testing.T) { {`go:cgo_export_static local' remote'`, []string{`cgo_export_static`, `local'`, `remote'`}}, {`go:cgo_import_dynamic local`, []string{`cgo_import_dynamic`, `local`}}, {`go:cgo_import_dynamic local remote`, []string{`cgo_import_dynamic`, `local`, `remote`}}, - {`go:cgo_import_dynamic local remote "library"`, []string{`cgo_import_dynamic`, `local`, `remote`, `library`}}, - {`go:cgo_import_dynamic local' remote' "lib rary"`, []string{`cgo_import_dynamic`, `local'`, `remote'`, `lib rary`}}, {`go:cgo_import_static local`, []string{`cgo_import_static`, `local`}}, {`go:cgo_import_static local'`, []string{`cgo_import_static`, `local'`}}, {`go:cgo_dynamic_linker "/path/"`, []string{`cgo_dynamic_linker`, `/path/`}}, @@ -71,17 +72,50 @@ func TestPragcgo(t *testing.T) { {`go:cgo_ldflag "a rg"`, []string{`cgo_ldflag`, `a rg`}}, } + if runtime.GOOS != "aix" { + tests = append(tests, []testStruct{ + {`go:cgo_import_dynamic local remote "library"`, []string{`cgo_import_dynamic`, `local`, `remote`, `library`}}, + {`go:cgo_import_dynamic local' remote' "lib rary"`, []string{`cgo_import_dynamic`, `local'`, `remote'`, `lib rary`}}, + }...) + } else { + // cgo_import_dynamic with a library is slightly different on AIX + // as the library field must follow the pattern [libc.a/object.o]. + tests = append(tests, []testStruct{ + {`go:cgo_import_dynamic local remote "lib.a/obj.o"`, []string{`cgo_import_dynamic`, `local`, `remote`, `lib.a/obj.o`}}, + // This test must fail. + {`go:cgo_import_dynamic local' remote' "library"`, []string{`: usage: //go:cgo_import_dynamic local [remote ["lib.a/object.o"]]`}}, + }...) + + } + var p noder var nopos syntax.Pos for _, tt := range tests { - p.pragcgobuf = nil - p.pragcgo(nopos, tt.in) - got := p.pragcgobuf - want := [][]string{tt.want} - if !reflect.DeepEqual(got, want) { - t.Errorf("pragcgo(%q) = %q; want %q", tt.in, got, want) - continue + p.err = make(chan syntax.Error) + gotch := make(chan [][]string) + go func() { + p.pragcgobuf = nil + p.pragcgo(nopos, tt.in) + if p.pragcgobuf != nil { + gotch <- p.pragcgobuf + } + }() + + select { + case e := <-p.err: + want := tt.want[0] + if e.Error() != want { + t.Errorf("pragcgo(%q) = %q; want %q", tt.in, e, want) + continue + } + case got := <-gotch: + want := [][]string{tt.want} + if !reflect.DeepEqual(got, want) { + t.Errorf("pragcgo(%q) = %q; want %q", tt.in, got, want) + continue + } } + } } From aa9bcea3907a74f45303b3bdb603b9952cc72b7b Mon Sep 17 00:00:00 2001 From: Lynn Boger Date: Fri, 5 Oct 2018 14:21:39 -0400 Subject: [PATCH 0990/1663] runtime: improve performance of memclr, memmove on ppc64x MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This improves the asm implementations for memmove and memclr on ppc64x through use of vsx loads and stores when size is >= 32 bytes. For memclr, dcbz is used when the size is >= 512 and aligned to 128. Memclr/64 13.3ns ± 0% 10.7ns ± 0% -19.55% (p=0.000 n=8+7) Memclr/96 14.9ns ± 0% 11.4ns ± 0% -23.49% (p=0.000 n=8+8) Memclr/128 16.3ns ± 0% 12.3ns ± 0% -24.54% (p=0.000 n=8+8) Memclr/160 17.3ns ± 0% 13.0ns ± 0% -24.86% (p=0.000 n=8+8) Memclr/256 20.0ns ± 0% 15.3ns ± 0% -23.62% (p=0.000 n=8+8) Memclr/512 34.2ns ± 0% 10.2ns ± 0% -70.20% (p=0.000 n=8+8) Memclr/4096 178ns ± 0% 23ns ± 0% -87.13% (p=0.000 n=8+8) Memclr/65536 2.67µs ± 0% 0.30µs ± 0% -88.89% (p=0.000 n=7+8) Memclr/1M 43.2µs ± 0% 10.0µs ± 0% -76.85% (p=0.000 n=8+8) Memclr/4M 173µs ± 0% 40µs ± 0% -76.88% (p=0.000 n=8+8) Memclr/8M 349µs ± 0% 82µs ± 0% -76.58% (p=0.000 n=8+8) Memclr/16M 701µs ± 7% 672µs ± 0% -4.05% (p=0.040 n=8+7) Memclr/64M 2.70ms ± 0% 2.67ms ± 0% -0.96% (p=0.000 n=8+7) Memmove/32 6.59ns ± 0% 5.84ns ± 0% -11.34% (p=0.029 n=4+4) Memmove/64 7.91ns ± 0% 6.97ns ± 0% -11.92% (p=0.029 n=4+4) Memmove/128 10.5ns ± 0% 8.8ns ± 0% -16.24% (p=0.029 n=4+4) Memmove/256 21.0ns ± 0% 12.9ns ± 0% -38.57% (p=0.029 n=4+4) Memmove/512 28.4ns ± 0% 26.2ns ± 0% -7.75% (p=0.029 n=4+4) Memmove/1024 48.2ns ± 1% 39.4ns ± 0% -18.26% (p=0.029 n=4+4) Memmove/2048 85.4ns ± 0% 69.0ns ± 0% -19.20% (p=0.029 n=4+4) Memmove/4096 159ns ± 0% 128ns ± 0% -19.50% (p=0.029 n=4+4) Change-Id: I8c1adf88790845bf31444a15249456006eb5bf8b Reviewed-on: https://go-review.googlesource.com/c/141217 Run-TryBot: Lynn Boger TryBot-Result: Gobot Gobot Reviewed-by: Michael Munday --- src/runtime/memclr_ppc64x.s | 129 +++++++++++++++++++++++++++++++---- src/runtime/memmove_ppc64x.s | 51 +++++++++----- 2 files changed, 149 insertions(+), 31 deletions(-) diff --git a/src/runtime/memclr_ppc64x.s b/src/runtime/memclr_ppc64x.s index 3b23ce89d87b1..072963f75687d 100644 --- a/src/runtime/memclr_ppc64x.s +++ b/src/runtime/memclr_ppc64x.s @@ -14,34 +14,68 @@ TEXT runtime·memclrNoHeapPointers(SB), NOSPLIT|NOFRAME, $0-16 // Determine if there are doublewords to clear check: ANDCC $7, R4, R5 // R5: leftover bytes to clear - SRAD $3, R4, R6 // R6: double words to clear + SRD $3, R4, R6 // R6: double words to clear CMP R6, $0, CR1 // CR1[EQ] set if no double words - BC 12, 6, nozerolarge // only single bytes - MOVD R6, CTR // R6 = number of double words - SRADCC $2, R6, R7 // 32 byte chunks? - BNE zero32setup + BC 12, 6, nozerolarge // only single bytes + CMP R4, $512 + BLT under512 // special case for < 512 + ANDCC $127, R3, R8 // check for 128 alignment of address + BEQ zero512setup + + ANDCC $7, R3, R15 + BEQ zero512xsetup // at least 8 byte aligned + + // zero bytes up to 8 byte alignment + + ANDCC $1, R3, R15 // check for byte alignment + BEQ byte2 + MOVB R0, 0(R3) // zero 1 byte + ADD $1, R3 // bump ptr by 1 + ADD $-1, R4 + +byte2: + ANDCC $2, R3, R15 // check for 2 byte alignment + BEQ byte4 + MOVH R0, 0(R3) // zero 2 bytes + ADD $2, R3 // bump ptr by 2 + ADD $-2, R4 + +byte4: + ANDCC $4, R3, R15 // check for 4 byte alignment + BEQ zero512xsetup + MOVW R0, 0(R3) // zero 4 bytes + ADD $4, R3 // bump ptr by 4 + ADD $-4, R4 + BR zero512xsetup // ptr should now be 8 byte aligned + +under512: + MOVD R6, CTR // R6 = number of double words + SRDCC $2, R6, R7 // 32 byte chunks? + BNE zero32setup // Clear double words zero8: MOVD R0, 0(R3) // double word ADD $8, R3 + ADD $-8, R4 BC 16, 0, zero8 // dec ctr, br zero8 if ctr not 0 - BR nozerolarge // handle remainder + BR nozerolarge // handle leftovers // Prepare to clear 32 bytes at a time. zero32setup: - DCBTST (R3) // prepare data cache - MOVD R7, CTR // number of 32 byte chunks + DCBTST (R3) // prepare data cache + XXLXOR VS32, VS32, VS32 // clear VS32 (V0) + MOVD R7, CTR // number of 32 byte chunks + MOVD $16, R8 zero32: - MOVD R0, 0(R3) // clear 4 double words - MOVD R0, 8(R3) - MOVD R0, 16(R3) - MOVD R0, 24(R3) + STXVD2X VS32, (R3+R0) // store 16 bytes + STXVD2X VS32, (R3+R8) ADD $32, R3 + ADD $-32, R4 BC 16, 0, zero32 // dec ctr, br zero32 if ctr not 0 RLDCLCC $61, R4, $3, R6 // remaining doublewords BEQ nozerolarge @@ -49,8 +83,8 @@ zero32: BR zero8 nozerolarge: - CMP R5, $0 // any remaining bytes - BC 4, 1, LR // ble lr + ANDCC $7, R4, R5 // any remaining bytes + BC 4, 1, LR // ble lr zerotail: MOVD R5, CTR // set up to clear tail bytes @@ -60,3 +94,70 @@ zerotailloop: ADD $1, R3 BC 16, 0, zerotailloop // dec ctr, br zerotailloop if ctr not 0 RET + +zero512xsetup: // 512 chunk with extra needed + ANDCC $8, R3, R11 // 8 byte alignment? + BEQ zero512setup16 + MOVD R0, 0(R3) // clear 8 bytes + ADD $8, R3 // update ptr to next 8 + ADD $-8, R4 // dec count by 8 + +zero512setup16: + ANDCC $127, R3, R14 // < 128 byte alignment + BEQ zero512setup // handle 128 byte alignment + MOVD $128, R15 + SUB R14, R15, R14 // find increment to 128 alignment + SRD $4, R14, R15 // number of 16 byte chunks + +zero512presetup: + MOVD R15, CTR // loop counter of 16 bytes + XXLXOR VS32, VS32, VS32 // clear VS32 (V0) + +zero512preloop: // clear up to 128 alignment + STXVD2X VS32, (R3+R0) // clear 16 bytes + ADD $16, R3 // update ptr + ADD $-16, R4 // dec count + BC 16, 0, zero512preloop + +zero512setup: // setup for dcbz loop + CMP R4, $512 // check if at least 512 + BLT remain + SRD $9, R4, R8 // loop count for 512 chunks + MOVD R8, CTR // set up counter + MOVD $128, R9 // index regs for 128 bytes + MOVD $256, R10 + MOVD $384, R11 + +zero512: + DCBZ (R3+R0) // clear first chunk + DCBZ (R3+R9) // clear second chunk + DCBZ (R3+R10) // clear third chunk + DCBZ (R3+R11) // clear fourth chunk + ADD $512, R3 + ADD $-512, R4 + BC 16, 0, zero512 + +remain: + CMP R4, $128 // check if 128 byte chunks left + BLT smaller + DCBZ (R3+R0) // clear 128 + ADD $128, R3 + ADD $-128, R4 + BR remain + +smaller: + ANDCC $127, R4, R7 // find leftovers + BEQ done + CMP R7, $64 // more than 64, do 32 at a time + BLT zero8setup // less than 64, do 8 at a time + SRD $5, R7, R7 // set up counter for 32 + BR zero32setup + +zero8setup: + SRDCC $3, R7, R7 // less than 8 bytes + BEQ nozerolarge + MOVD R7, CTR + BR zero8 + +done: + RET diff --git a/src/runtime/memmove_ppc64x.s b/src/runtime/memmove_ppc64x.s index b79f76d38874d..60cbcc41ec569 100644 --- a/src/runtime/memmove_ppc64x.s +++ b/src/runtime/memmove_ppc64x.s @@ -16,7 +16,7 @@ TEXT runtime·memmove(SB), NOSPLIT|NOFRAME, $0-24 // copy so a more efficient move can be done check: ANDCC $7, R5, R7 // R7: bytes to copy - SRAD $3, R5, R6 // R6: double words to copy + SRD $3, R5, R6 // R6: double words to copy CMP R6, $0, CR1 // CR1[EQ] set if no double words to copy // Determine overlap by subtracting dest - src and comparing against the @@ -31,9 +31,9 @@ check: // Copying forward if no overlap. BC 12, 6, noforwardlarge // "BEQ CR1, noforwardlarge" - MOVD R6,CTR // R6 = number of double words - SRADCC $2,R6,R8 // 32 byte chunks? + SRDCC $2,R6,R8 // 32 byte chunks? BNE forward32setup // + MOVD R6,CTR // R6 = number of double words // Move double words @@ -51,17 +51,14 @@ forward32setup: DCBTST (R3) // prepare data cache DCBT (R4) MOVD R8, CTR // double work count + MOVD $16, R8 forward32: - MOVD 0(R4), R8 // load 4 double words - MOVD 8(R4), R9 - MOVD 16(R4), R14 - MOVD 24(R4), R15 - ADD $32,R4 - MOVD R8, 0(R3) // store those 4 - MOVD R9, 8(R3) - MOVD R14,16(R3) - MOVD R15,24(R3) + LXVD2X (R4+R0), VS32 // load 16 bytes + LXVD2X (R4+R8), VS33 + ADD $32, R4 + STXVD2X VS32, (R3+R0) // store 16 bytes + STXVD2X VS33, (R3+R8) ADD $32,R3 // bump up for next set BC 16, 0, forward32 // continue RLDCLCC $61,R5,$3,R6 // remaining doublewords @@ -71,7 +68,7 @@ forward32: noforwardlarge: CMP R7,$0 // any remaining bytes - BC 4, 1, LR + BC 4, 1, LR // ble lr forwardtail: MOVD R7, CTR // move tail bytes @@ -101,19 +98,39 @@ backwardtailloop: SUB $1,R4 MOVBZ R8, -1(R3) SUB $1,R3 - BC 16, 0, backwardtailloop + BC 16, 0, backwardtailloop // bndz nobackwardtail: - CMP R6,$0 - BC 4, 5, LR + BC 4, 5, LR // ble CR1 lr backwardlarge: MOVD R6, CTR + SUB R3, R4, R9 // Use vsx if moving + CMP R9, $32 // at least 32 byte chunks + BLT backwardlargeloop // and distance >= 32 + SRDCC $2,R6,R8 // 32 byte chunks + BNE backward32setup backwardlargeloop: MOVD -8(R4), R8 SUB $8,R4 MOVD R8, -8(R3) SUB $8,R3 - BC 16, 0, backwardlargeloop // + BC 16, 0, backwardlargeloop // bndz RET + +backward32setup: + MOVD R8, CTR // set up loop ctr + MOVD $16, R8 // 32 bytes at at time + +backward32loop: + SUB $32, R4 + SUB $32, R3 + LXVD2X (R4+R0), VS32 // load 16 bytes + LXVD2X (R4+R8), VS33 + STXVD2X VS32, (R3+R0) // store 16 bytes + STXVD2X VS33, (R3+R8) + BC 16, 0, backward32loop // bndz + BC 4, 5, LR // ble CR1 lr + MOVD R6, CTR + BR backwardlargeloop From 8b4692096bf85f04df53d4104cb82cc3c8095df7 Mon Sep 17 00:00:00 2001 From: Alan Donovan Date: Mon, 5 Nov 2018 15:51:35 -0500 Subject: [PATCH 0991/1663] cmd/vendor: add x/tools/go/analysis/cmd/vet-lite + deps This change adds the vet-lite command (the future cmd/vet) and all its dependencies from x/tools, but not its tests and their dependencies. It was created with these commands: $ (cd $GOPATH/src/golang.org/x/tools && git checkout c76e1ad) $ cd GOROOT/src/cmd $ govendor add $(go list -deps golang.org/x/tools/go/analysis/cmd/vet-lite | grep golang.org/x/tools) $ rm -fr $(find vendor/golang.org/x/tools/ -name testdata) $ rm $(find vendor/golang.org/x/tools/ -name \*_test.go) I feel sure I am holding govendor wrong. Please advise. A followup CL will make cmd/vet behave like vet-lite, initially just for users that opt in, and soon after for all users, at which point cmd/vet will be replaced in its entirety by a copy of vet-lite's small main.go. In the meantime, anyone can try the new tool using these commands: $ go build cmd/vendor/golang.org/x/tools/go/analysis/cmd/vet-lite $ export GOVETTOOL=$(which vet-lite) $ go vet your/project/... Change-Id: Iea168111a32ce62f82f9fb706385ca0f368bc869 Reviewed-on: https://go-review.googlesource.com/c/147444 Reviewed-by: Russ Cox --- src/cmd/vendor/golang.org/x/tools/LICENSE | 27 + src/cmd/vendor/golang.org/x/tools/PATENTS | 22 + .../x/tools/go/analysis/analysis.go | 192 ++++ .../x/tools/go/analysis/cmd/vet-lite/main.go | 83 ++ .../golang.org/x/tools/go/analysis/doc.go | 328 ++++++ .../analysis/internal/analysisflags/flags.go | 223 ++++ .../tools/go/analysis/internal/facts/facts.go | 299 ++++++ .../go/analysis/internal/facts/imports.go | 88 ++ .../internal/unitchecker/unitchecker.go | 306 ++++++ .../go/analysis/passes/asmdecl/asmdecl.go | 759 ++++++++++++++ .../tools/go/analysis/passes/assign/assign.go | 68 ++ .../tools/go/analysis/passes/atomic/atomic.go | 96 ++ .../x/tools/go/analysis/passes/bools/bools.go | 214 ++++ .../go/analysis/passes/buildtag/buildtag.go | 159 +++ .../go/analysis/passes/cgocall/cgocall.go | 226 ++++ .../go/analysis/passes/composite/composite.go | 108 ++ .../go/analysis/passes/composite/whitelist.go | 33 + .../go/analysis/passes/copylock/copylock.go | 300 ++++++ .../go/analysis/passes/ctrlflow/ctrlflow.go | 225 ++++ .../passes/httpresponse/httpresponse.go | 177 ++++ .../go/analysis/passes/inspect/inspect.go | 45 + .../passes/internal/analysisutil/util.go | 106 ++ .../passes/loopclosure/loopclosure.go | 130 +++ .../analysis/passes/lostcancel/lostcancel.go | 304 ++++++ .../go/analysis/passes/nilfunc/nilfunc.go | 74 ++ .../go/analysis/passes/pkgfact/pkgfact.go | 127 +++ .../tools/go/analysis/passes/printf/printf.go | 964 ++++++++++++++++++ .../tools/go/analysis/passes/printf/types.go | 223 ++++ .../x/tools/go/analysis/passes/shift/dead.go | 101 ++ .../x/tools/go/analysis/passes/shift/shift.go | 128 +++ .../analysis/passes/stdmethods/stdmethods.go | 211 ++++ .../go/analysis/passes/structtag/structtag.go | 260 +++++ .../x/tools/go/analysis/passes/tests/tests.go | 175 ++++ .../passes/unreachable/unreachable.go | 314 ++++++ .../go/analysis/passes/unsafeptr/unsafeptr.go | 130 +++ .../passes/unusedresult/unusedresult.go | 131 +++ .../x/tools/go/analysis/validate.go | 104 ++ .../x/tools/go/ast/astutil/enclosing.go | 627 ++++++++++++ .../x/tools/go/ast/astutil/imports.go | 471 +++++++++ .../x/tools/go/ast/astutil/rewrite.go | 477 +++++++++ .../golang.org/x/tools/go/ast/astutil/util.go | 14 + .../x/tools/go/ast/inspector/inspector.go | 182 ++++ .../x/tools/go/ast/inspector/typeof.go | 216 ++++ .../golang.org/x/tools/go/cfg/builder.go | 510 +++++++++ .../vendor/golang.org/x/tools/go/cfg/cfg.go | 150 +++ .../x/tools/go/types/objectpath/objectpath.go | 523 ++++++++++ .../x/tools/go/types/typeutil/callee.go | 46 + .../x/tools/go/types/typeutil/imports.go | 31 + .../x/tools/go/types/typeutil/map.go | 313 ++++++ .../tools/go/types/typeutil/methodsetcache.go | 72 ++ .../x/tools/go/types/typeutil/ui.go | 52 + src/cmd/vendor/vendor.json | 204 ++++ 52 files changed, 11348 insertions(+) create mode 100644 src/cmd/vendor/golang.org/x/tools/LICENSE create mode 100644 src/cmd/vendor/golang.org/x/tools/PATENTS create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/analysis.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/cmd/vet-lite/main.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/doc.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/flags.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/facts.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/imports.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/internal/unitchecker/unitchecker.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/asmdecl/asmdecl.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/assign/assign.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/atomic/atomic.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/bools/bools.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/buildtag/buildtag.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/cgocall/cgocall.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/composite.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/whitelist.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/copylock/copylock.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/ctrlflow/ctrlflow.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/httpresponse/httpresponse.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/inspect/inspect.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/loopclosure/loopclosure.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/lostcancel/lostcancel.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/nilfunc/nilfunc.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/pkgfact/pkgfact.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/printf.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/types.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/dead.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/shift.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/stdmethods/stdmethods.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/tests/tests.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unreachable/unreachable.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unsafeptr/unsafeptr.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unusedresult/unusedresult.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/analysis/validate.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/ast/astutil/enclosing.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/ast/astutil/imports.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/ast/astutil/util.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/ast/inspector/inspector.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/ast/inspector/typeof.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/cfg/builder.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/cfg/cfg.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/types/objectpath/objectpath.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/types/typeutil/callee.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/types/typeutil/imports.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/types/typeutil/map.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/types/typeutil/methodsetcache.go create mode 100644 src/cmd/vendor/golang.org/x/tools/go/types/typeutil/ui.go diff --git a/src/cmd/vendor/golang.org/x/tools/LICENSE b/src/cmd/vendor/golang.org/x/tools/LICENSE new file mode 100644 index 0000000000000..6a66aea5eafe0 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/LICENSE @@ -0,0 +1,27 @@ +Copyright (c) 2009 The Go Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/src/cmd/vendor/golang.org/x/tools/PATENTS b/src/cmd/vendor/golang.org/x/tools/PATENTS new file mode 100644 index 0000000000000..733099041f84f --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/PATENTS @@ -0,0 +1,22 @@ +Additional IP Rights Grant (Patents) + +"This implementation" means the copyrightable works distributed by +Google as part of the Go project. + +Google hereby grants to You a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable (except as stated in this section) +patent license to make, have made, use, offer to sell, sell, import, +transfer and otherwise run, modify and propagate the contents of this +implementation of Go, where such license applies only to those patent +claims, both currently owned or controlled by Google and acquired in +the future, licensable by Google that are necessarily infringed by this +implementation of Go. This grant does not include claims that would be +infringed only as a consequence of further modification of this +implementation. If you or your agent or exclusive licensee institute or +order or agree to the institution of patent litigation against any +entity (including a cross-claim or counterclaim in a lawsuit) alleging +that this implementation of Go or any code incorporated within this +implementation of Go constitutes direct or contributory patent +infringement, or inducement of patent infringement, then any patent +rights granted to you under this License for this implementation of Go +shall terminate as of the date such litigation is filed. diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/analysis.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/analysis.go new file mode 100644 index 0000000000000..21baa02a8de38 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/analysis.go @@ -0,0 +1,192 @@ +package analysis + +import ( + "flag" + "fmt" + "go/ast" + "go/token" + "go/types" + "reflect" +) + +// An Analyzer describes an analysis function and its options. +type Analyzer struct { + // The Name of the analyzer must be a valid Go identifier + // as it may appear in command-line flags, URLs, and so on. + Name string + + // Doc is the documentation for the analyzer. + // The part before the first "\n\n" is the title + // (no capital or period, max ~60 letters). + Doc string + + // Flags defines any flags accepted by the analyzer. + // The manner in which these flags are exposed to the user + // depends on the driver which runs the analyzer. + Flags flag.FlagSet + + // Run applies the analyzer to a package. + // It returns an error if the analyzer failed. + // + // On success, the Run function may return a result + // computed by the Analyzer; its type must match ResultType. + // The driver makes this result available as an input to + // another Analyzer that depends directly on this one (see + // Requires) when it analyzes the same package. + // + // To pass analysis results between packages (and thus + // potentially between address spaces), use Facts, which are + // serializable. + Run func(*Pass) (interface{}, error) + + // RunDespiteErrors allows the driver to invoke + // the Run method of this analyzer even on a + // package that contains parse or type errors. + RunDespiteErrors bool + + // Requires is a set of analyzers that must run successfully + // before this one on a given package. This analyzer may inspect + // the outputs produced by each analyzer in Requires. + // The graph over analyzers implied by Requires edges must be acyclic. + // + // Requires establishes a "horizontal" dependency between + // analysis passes (different analyzers, same package). + Requires []*Analyzer + + // ResultType is the type of the optional result of the Run function. + ResultType reflect.Type + + // FactTypes indicates that this analyzer imports and exports + // Facts of the specified concrete types. + // An analyzer that uses facts may assume that its import + // dependencies have been similarly analyzed before it runs. + // Facts must be pointers. + // + // FactTypes establishes a "vertical" dependency between + // analysis passes (same analyzer, different packages). + FactTypes []Fact +} + +func (a *Analyzer) String() string { return a.Name } + +// A Pass provides information to the Run function that +// applies a specific analyzer to a single Go package. +// +// It forms the interface between the analysis logic and the driver +// program, and has both input and an output components. +// +// As in a compiler, one pass may depend on the result computed by another. +// +// The Run function should not call any of the Pass functions concurrently. +type Pass struct { + Analyzer *Analyzer // the identity of the current analyzer + + // syntax and type information + Fset *token.FileSet // file position information + Files []*ast.File // the abstract syntax tree of each file + OtherFiles []string // names of non-Go files of this package + Pkg *types.Package // type information about the package + TypesInfo *types.Info // type information about the syntax trees + + // Report reports a Diagnostic, a finding about a specific location + // in the analyzed source code such as a potential mistake. + // It may be called by the Run function. + Report func(Diagnostic) + + // ResultOf provides the inputs to this analysis pass, which are + // the corresponding results of its prerequisite analyzers. + // The map keys are the elements of Analysis.Required, + // and the type of each corresponding value is the required + // analysis's ResultType. + ResultOf map[*Analyzer]interface{} + + // -- facts -- + + // ImportObjectFact retrieves a fact associated with obj. + // Given a value ptr of type *T, where *T satisfies Fact, + // ImportObjectFact copies the value to *ptr. + // + // ImportObjectFact panics if called after the pass is complete. + // ImportObjectFact is not concurrency-safe. + ImportObjectFact func(obj types.Object, fact Fact) bool + + // ImportPackageFact retrieves a fact associated with package pkg, + // which must be this package or one of its dependencies. + // See comments for ImportObjectFact. + ImportPackageFact func(pkg *types.Package, fact Fact) bool + + // ExportObjectFact associates a fact of type *T with the obj, + // replacing any previous fact of that type. + // + // ExportObjectFact panics if it is called after the pass is + // complete, or if obj does not belong to the package being analyzed. + // ExportObjectFact is not concurrency-safe. + ExportObjectFact func(obj types.Object, fact Fact) + + // ExportPackageFact associates a fact with the current package. + // See comments for ExportObjectFact. + ExportPackageFact func(fact Fact) + + /* Further fields may be added in future. */ + // For example, suggested or applied refactorings. +} + +// Reportf is a helper function that reports a Diagnostic using the +// specified position and formatted error message. +func (pass *Pass) Reportf(pos token.Pos, format string, args ...interface{}) { + msg := fmt.Sprintf(format, args...) + pass.Report(Diagnostic{Pos: pos, Message: msg}) +} + +func (pass *Pass) String() string { + return fmt.Sprintf("%s@%s", pass.Analyzer.Name, pass.Pkg.Path()) +} + +// A Fact is an intermediate fact produced during analysis. +// +// Each fact is associated with a named declaration (a types.Object) or +// with a package as a whole. A single object or package may have +// multiple associated facts, but only one of any particular fact type. +// +// A Fact represents a predicate such as "never returns", but does not +// represent the subject of the predicate such as "function F" or "package P". +// +// Facts may be produced in one analysis pass and consumed by another +// analysis pass even if these are in different address spaces. +// If package P imports Q, all facts about Q produced during +// analysis of that package will be available during later analysis of P. +// Facts are analogous to type export data in a build system: +// just as export data enables separate compilation of several passes, +// facts enable "separate analysis". +// +// Each pass (a, p) starts with the set of facts produced by the +// same analyzer a applied to the packages directly imported by p. +// The analysis may add facts to the set, and they may be exported in turn. +// An analysis's Run function may retrieve facts by calling +// Pass.Import{Object,Package}Fact and update them using +// Pass.Export{Object,Package}Fact. +// +// A fact is logically private to its Analysis. To pass values +// between different analyzers, use the results mechanism; +// see Analyzer.Requires, Analyzer.ResultType, and Pass.ResultOf. +// +// A Fact type must be a pointer. +// Facts are encoded and decoded using encoding/gob. +// A Fact may implement the GobEncoder/GobDecoder interfaces +// to customize its encoding. Fact encoding should not fail. +// +// A Fact should not be modified once exported. +type Fact interface { + AFact() // dummy method to avoid type errors +} + +// A Diagnostic is a message associated with a source location. +// +// An Analyzer may return a variety of diagnostics; the optional Category, +// which should be a constant, may be used to classify them. +// It is primarily intended to make it easy to look up documentation. +type Diagnostic struct { + Pos token.Pos + Category string // optional + Message string +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/cmd/vet-lite/main.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/cmd/vet-lite/main.go new file mode 100644 index 0000000000000..ae66a7df28dec --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/cmd/vet-lite/main.go @@ -0,0 +1,83 @@ +// The vet-lite command is a driver for static checkers conforming to +// the golang.org/x/tools/go/analysis API. It must be run by go vet: +// +// $ GOVETTOOL=$(which vet-lite) go vet +// +// For a checker also capable of running standalone, use multichecker. +package main + +import ( + "flag" + "log" + "strings" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/internal/analysisflags" + "golang.org/x/tools/go/analysis/internal/unitchecker" + + "golang.org/x/tools/go/analysis/passes/asmdecl" + "golang.org/x/tools/go/analysis/passes/assign" + "golang.org/x/tools/go/analysis/passes/atomic" + "golang.org/x/tools/go/analysis/passes/bools" + "golang.org/x/tools/go/analysis/passes/buildtag" + "golang.org/x/tools/go/analysis/passes/cgocall" + "golang.org/x/tools/go/analysis/passes/composite" + "golang.org/x/tools/go/analysis/passes/copylock" + "golang.org/x/tools/go/analysis/passes/httpresponse" + "golang.org/x/tools/go/analysis/passes/loopclosure" + "golang.org/x/tools/go/analysis/passes/lostcancel" + "golang.org/x/tools/go/analysis/passes/nilfunc" + "golang.org/x/tools/go/analysis/passes/pkgfact" + "golang.org/x/tools/go/analysis/passes/printf" + "golang.org/x/tools/go/analysis/passes/shift" + "golang.org/x/tools/go/analysis/passes/stdmethods" + "golang.org/x/tools/go/analysis/passes/structtag" + "golang.org/x/tools/go/analysis/passes/tests" + "golang.org/x/tools/go/analysis/passes/unreachable" + "golang.org/x/tools/go/analysis/passes/unsafeptr" + "golang.org/x/tools/go/analysis/passes/unusedresult" +) + +var analyzers = []*analysis.Analyzer{ + // For now, just the traditional vet suite: + asmdecl.Analyzer, + assign.Analyzer, + atomic.Analyzer, + bools.Analyzer, + buildtag.Analyzer, + cgocall.Analyzer, + composite.Analyzer, + copylock.Analyzer, + httpresponse.Analyzer, + loopclosure.Analyzer, + lostcancel.Analyzer, + nilfunc.Analyzer, + pkgfact.Analyzer, + printf.Analyzer, + // shadow.Analyzer, // experimental; not enabled by default + shift.Analyzer, + stdmethods.Analyzer, + structtag.Analyzer, + tests.Analyzer, + unreachable.Analyzer, + unsafeptr.Analyzer, + unusedresult.Analyzer, +} + +func main() { + log.SetFlags(0) + log.SetPrefix("vet: ") + + if err := analysis.Validate(analyzers); err != nil { + log.Fatal(err) + } + + analyzers = analysisflags.Parse(analyzers, true) + + args := flag.Args() + if len(args) != 1 || !strings.HasSuffix(args[0], ".cfg") { + log.Fatalf("invalid command: want .cfg file (this reduced version of vet is intended to be run only by the 'go vet' command)") + } + + unitchecker.Main(args[0], analyzers) +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/doc.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/doc.go new file mode 100644 index 0000000000000..4223ab80fc199 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/doc.go @@ -0,0 +1,328 @@ +/* + +The analysis package defines the interface between a modular static +analysis and an analysis driver program. + + +THIS INTERFACE IS EXPERIMENTAL AND SUBJECT TO CHANGE. +We aim to finalize it by November 2018. + +Background + +A static analysis is a function that inspects a package of Go code and +reports a set of diagnostics (typically mistakes in the code), and +perhaps produces other results as well, such as suggested refactorings +or other facts. An analysis that reports mistakes is informally called a +"checker". For example, the printf checker reports mistakes in +fmt.Printf format strings. + +A "modular" analysis is one that inspects one package at a time but can +save information from a lower-level package and use it when inspecting a +higher-level package, analogous to separate compilation in a toolchain. +The printf checker is modular: when it discovers that a function such as +log.Fatalf delegates to fmt.Printf, it records this fact, and checks +calls to that function too, including calls made from another package. + +By implementing a common interface, checkers from a variety of sources +can be easily selected, incorporated, and reused in a wide range of +driver programs including command-line tools (such as vet), text editors and +IDEs, build and test systems (such as go build, Bazel, or Buck), test +frameworks, code review tools, code-base indexers (such as SourceGraph), +documentation viewers (such as godoc), batch pipelines for large code +bases, and so on. + + +Analyzer + +The primary type in the API is Analyzer. An Analyzer statically +describes an analysis function: its name, documentation, flags, +relationship to other analyzers, and of course, its logic. + +To define an analysis, a user declares a (logically constant) variable +of type Analyzer. Here is a typical example from one of the analyzers in +the go/analysis/passes/ subdirectory: + + package unusedresult + + var Analyzer = &analysis.Analyzer{ + Name: "unusedresult", + Doc: "check for unused results of calls to some functions", + Run: run, + ... + } + + func run(pass *analysis.Pass) (interface{}, error) { + ... + } + + +An analysis driver is a program such as vet that runs a set of +analyses and prints the diagnostics that they report. +The driver program must import the list of Analyzers it needs. +Typically each Analyzer resides in a separate package. +To add a new Analyzer to an existing driver, add another item to the list: + + import ( "unusedresult"; "nilness"; "printf" ) + + var analyses = []*analysis.Analyzer{ + unusedresult.Analyzer, + nilness.Analyzer, + printf.Analyzer, + } + +A driver may use the name, flags, and documentation to provide on-line +help that describes the analyses its performs. +The vet command, shown below, is an example of a driver that runs +multiple analyzers. It is based on the multichecker package +(see the "Standalone commands" section for details). + + $ go build golang.org/x/tools/cmd/vet + $ ./vet help + vet is a tool for static analysis of Go programs. + + Usage: vet [-flag] [package] + + Registered analyzers: + + asmdecl report mismatches between assembly files and Go declarations + assign check for useless assignments + atomic check for common mistakes using the sync/atomic package + ... + unusedresult check for unused results of calls to some functions + + $ ./vet help unusedresult + unusedresult: check for unused results of calls to some functions + + Analyzer flags: + + -unusedresult.funcs value + comma-separated list of functions whose results must be used (default Error,String) + -unusedresult.stringmethods value + comma-separated list of names of methods of type func() string whose results must be used + + Some functions like fmt.Errorf return a result and have no side effects, + so it is always a mistake to discard the result. This analyzer reports + calls to certain functions in which the result of the call is ignored. + + The set of functions may be controlled using flags. + +The Analyzer type has more fields besides those shown above: + + type Analyzer struct { + Name string + Doc string + Flags flag.FlagSet + Run func(*Pass) (interface{}, error) + RunDespiteErrors bool + ResultType reflect.Type + Requires []*Analyzer + FactTypes []Fact + } + +The Flags field declares a set of named (global) flag variables that +control analysis behavior. Unlike vet, analysis flags are not declared +directly in the command line FlagSet; it is up to the driver to set the +flag variables. A driver for a single analysis, a, might expose its flag +f directly on the command line as -f, whereas a driver for multiple +analyses might prefix the flag name by the analysis name (-a.f) to avoid +ambiguity. An IDE might expose the flags through a graphical interface, +and a batch pipeline might configure them from a config file. +See the "findcall" analyzer for an example of flags in action. + +The RunDespiteErrors flag indicates whether the analysis is equipped to +handle ill-typed code. If not, the driver will skip the analysis if +there were parse or type errors. +The optional ResultType field specifies the type of the result value +computed by this analysis and made available to other analyses. +The Requires field specifies a list of analyses upon which +this one depends and whose results it may access, and it constrains the +order in which a driver may run analyses. +The FactTypes field is discussed in the section on Modularity. +The analysis package provides a Validate function to perform basic +sanity checks on an Analyzer, such as that its Requires graph is +acyclic, its fact and result types are unique, and so on. + +Finally, the Run field contains a function to be called by the driver to +execute the analysis on a single package. The driver passes it an +instance of the Pass type. + + +Pass + +A Pass describes a single unit of work: the application of a particular +Analyzer to a particular package of Go code. +The Pass provides information to the Analyzer's Run function about the +package being analyzed, and provides operations to the Run function for +reporting diagnostics and other information back to the driver. + + type Pass struct { + Fset *token.FileSet + Files []*ast.File + OtherFiles []string + Pkg *types.Package + TypesInfo *types.Info + ResultOf map[*Analyzer]interface{} + Report func(Diagnostic) + ... + } + +The Fset, Files, Pkg, and TypesInfo fields provide the syntax trees, +type information, and source positions for a single package of Go code. + +The OtherFiles field provides the names, but not the contents, of non-Go +files such as assembly that are part of this package. See the "asmdecl" +or "buildtags" analyzers for examples of loading non-Go files and report +diagnostics against them. + +The ResultOf field provides the results computed by the analyzers +required by this one, as expressed in its Analyzer.Requires field. The +driver runs the required analyzers first and makes their results +available in this map. Each Analyzer must return a value of the type +described in its Analyzer.ResultType field. +For example, the "ctrlflow" analyzer returns a *ctrlflow.CFGs, which +provides a control-flow graph for each function in the package (see +golang.org/x/tools/go/cfg); the "inspect" analyzer returns a value that +enables other Analyzers to traverse the syntax trees of the package more +efficiently; and the "buildssa" analyzer constructs an SSA-form +intermediate representation. +Each of these Analyzers extends the capabilities of later Analyzers +without adding a dependency to the core API, so an analysis tool pays +only for the extensions it needs. + +The Report function emits a diagnostic, a message associated with a +source position. For most analyses, diagnostics are their primary +result. +For convenience, Pass provides a helper method, Reportf, to report a new +diagnostic by formatting a string. +Diagnostic is defined as: + + type Diagnostic struct { + Pos token.Pos + Category string // optional + Message string + } + +The optional Category field is a short identifier that classifies the +kind of message when an analysis produces several kinds of diagnostic. + +Most Analyzers inspect typed Go syntax trees, but a few, such as asmdecl +and buildtag, inspect the raw text of Go source files or even non-Go +files such as assembly. To report a diagnostic against a line of a +raw text file, use the following sequence: + + content, err := ioutil.ReadFile(filename) + if err != nil { ... } + tf := fset.AddFile(filename, -1, len(content)) + tf.SetLinesForContent(content) + ... + pass.Reportf(tf.LineStart(line), "oops") + + +Modular analysis with Facts + +To improve efficiency and scalability, large programs are routinely +built using separate compilation: units of the program are compiled +separately, and recompiled only when one of their dependencies changes; +independent modules may be compiled in parallel. The same technique may +be applied to static analyses, for the same benefits. Such analyses are +described as "modular". + +A compiler’s type checker is an example of a modular static analysis. +Many other checkers we would like to apply to Go programs can be +understood as alternative or non-standard type systems. For example, +vet's printf checker infers whether a function has the "printf wrapper" +type, and it applies stricter checks to calls of such functions. In +addition, it records which functions are printf wrappers for use by +later analysis units to identify other printf wrappers by induction. +A result such as “f is a printf wrapper” that is not interesting by +itself but serves as a stepping stone to an interesting result (such as +a diagnostic) is called a "fact". + +The analysis API allows an analysis to define new types of facts, to +associate facts of these types with objects (named entities) declared +within the current package, or with the package as a whole, and to query +for an existing fact of a given type associated with an object or +package. + +An Analyzer that uses facts must declare their types: + + var Analyzer = &analysis.Analyzer{ + Name: "printf", + FactTypes: []reflect.Type{reflect.TypeOf(new(isWrapper))}, + ... + } + + type isWrapper struct{} // => *types.Func f “is a printf wrapper” + +A driver program ensures that facts for a pass’s dependencies are +generated before analyzing the pass and are responsible for propagating +facts between from one pass to another, possibly across address spaces. +Consequently, Facts must be serializable. The API requires that drivers +use the gob encoding, an efficient, robust, self-describing binary +protocol. A fact type may implement the GobEncoder/GobDecoder interfaces +if the default encoding is unsuitable. Facts should be stateless. + +The Pass type has functions to import and export facts, +associated either with an object or with a package: + + type Pass struct { + ... + ExportObjectFact func(types.Object, Fact) + ImportObjectFact func(types.Object, Fact) bool + + ExportPackageFact func(fact Fact) + ImportPackageFact func(*types.Package, Fact) bool + } + +An Analyzer may only export facts associated with the current package or +its objects, though it may import facts from any package or object that +is an import dependency of the current package. + +Conceptually, ExportObjectFact(obj, fact) inserts fact into a hidden map keyed by +the pair (obj, TypeOf(fact)), and the ImportObjectFact function +retrieves the entry from this map and copies its value into the variable +pointed to by fact. This scheme assumes that the concrete type of fact +is a pointer; this assumption is checked by the Validate function. +See the "printf" analyzer for an example of object facts in action. + + +Testing an Analyzer + +The analysistest subpackage provides utilities for testing an Analyzer. +In a few lines of code, it is possible to run an analyzer on a package +of testdata files and check that it reported all the expected +diagnostics and facts (and no more). Expectations are expressed using +"// want ..." comments in the input code. + + +Standalone commands + +Analyzers are provided in the form of packages that a driver program is +expected to import. The vet command imports a set of several analyses, +but users may wish to define their own analysis commands that perform +additional checks. To simplify the task of creating an analysis command, +either for a single analyzer or for a whole suite, we provide the +singlechecker and multichecker subpackages. + +The singlechecker package provides the main function for a command that +runs one analysis. By convention, each analyzer such as +go/passes/findcall should be accompanied by a singlechecker-based +command such as go/analysis/passes/findcall/cmd/findcall, defined in its +entirety as: + + package main + + import ( + "golang.org/x/tools/go/analysis/passes/findcall" + "golang.org/x/tools/go/analysis/singlechecker" + ) + + func main() { singlechecker.Main(findcall.Analyzer) } + +A tool that provides multiple analyzers can use multichecker in a +similar way, giving it the list of Analyzers. + + + +*/ +package analysis diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/flags.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/flags.go new file mode 100644 index 0000000000000..d6c13f2685c8f --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/analysisflags/flags.go @@ -0,0 +1,223 @@ +// Copyright 2018 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. + +// Package analysisflags defines helpers for processing flags of +// analysis driver tools. +package analysisflags + +import ( + "crypto/sha256" + "encoding/json" + "flag" + "fmt" + "io" + "log" + "os" + "strconv" + + "golang.org/x/tools/go/analysis" +) + +// Parse creates a flag for each of the analyzer's flags, +// including (in multi mode) an --analysis.enable flag, +// parses the flags, then filters and returns the list of +// analyzers enabled by flags. +func Parse(analyzers []*analysis.Analyzer, multi bool) []*analysis.Analyzer { + // Connect each analysis flag to the command line as -analysis.flag. + type analysisFlag struct { + Name string + Bool bool + Usage string + } + var analysisFlags []analysisFlag + + enabled := make(map[*analysis.Analyzer]*triState) + for _, a := range analyzers { + var prefix string + + // Add -analysis.enable flag. + if multi { + prefix = a.Name + "." + + enable := new(triState) + enableName := prefix + "enable" + enableUsage := "enable " + a.Name + " analysis" + flag.Var(enable, enableName, enableUsage) + enabled[a] = enable + analysisFlags = append(analysisFlags, analysisFlag{enableName, true, enableUsage}) + } + + a.Flags.VisitAll(func(f *flag.Flag) { + if !multi && flag.Lookup(f.Name) != nil { + log.Printf("%s flag -%s would conflict with driver; skipping", a.Name, f.Name) + return + } + + name := prefix + f.Name + flag.Var(f.Value, name, f.Usage) + + var isBool bool + if b, ok := f.Value.(interface{ IsBoolFlag() bool }); ok { + isBool = b.IsBoolFlag() + } + analysisFlags = append(analysisFlags, analysisFlag{name, isBool, f.Usage}) + }) + } + + // standard flags: -flags, -V. + printflags := flag.Bool("flags", false, "print analyzer flags in JSON") + addVersionFlag() + + flag.Parse() // (ExitOnError) + + // -flags: print flags so that go vet knows which ones are legitimate. + if *printflags { + data, err := json.MarshalIndent(analysisFlags, "", "\t") + if err != nil { + log.Fatal(err) + } + os.Stdout.Write(data) + os.Exit(0) + } + + // If any --foo.enable flag is true, run only those analyzers. Otherwise, + // if any --foo.enable flag is false, run all but those analyzers. + if multi { + var hasTrue, hasFalse bool + for _, ts := range enabled { + switch *ts { + case setTrue: + hasTrue = true + case setFalse: + hasFalse = true + } + } + + var keep []*analysis.Analyzer + if hasTrue { + for _, a := range analyzers { + if *enabled[a] == setTrue { + keep = append(keep, a) + } + } + analyzers = keep + } else if hasFalse { + for _, a := range analyzers { + if *enabled[a] != setFalse { + keep = append(keep, a) + } + } + analyzers = keep + } + } + + return analyzers +} + +// addVersionFlag registers a -V flag that, if set, +// prints the executable version and exits 0. +// +// It is a variable not a function to permit easy +// overriding in the copy vendored in $GOROOT/src/cmd/vet: +// +// func init() { addVersionFlag = objabi.AddVersionFlag } +var addVersionFlag = func() { + flag.Var(versionFlag{}, "V", "print version and exit") +} + +// versionFlag minimally complies with the -V protocol required by "go vet". +type versionFlag struct{} + +func (versionFlag) IsBoolFlag() bool { return true } +func (versionFlag) Get() interface{} { return nil } +func (versionFlag) String() string { return "" } +func (versionFlag) Set(s string) error { + if s != "full" { + log.Fatalf("unsupported flag value: -V=%s", s) + } + + // This replicates the miminal subset of + // cmd/internal/objabi.AddVersionFlag, which is private to the + // go tool yet forms part of our command-line interface. + // TODO(adonovan): clarify the contract. + + // Print the tool version so the build system can track changes. + // Formats: + // $progname version devel ... buildID=... + // $progname version go1.9.1 + progname := os.Args[0] + f, err := os.Open(progname) + if err != nil { + log.Fatal(err) + } + h := sha256.New() + if _, err := io.Copy(h, f); err != nil { + log.Fatal(err) + } + f.Close() + fmt.Printf("%s version devel comments-go-here buildID=%02x\n", + progname, string(h.Sum(nil))) + os.Exit(0) + return nil +} + +// A triState is a boolean that knows whether +// it has been set to either true or false. +// It is used to identify whether a flag appears; +// the standard boolean flag cannot +// distinguish missing from unset. +// It also satisfies flag.Value. +type triState int + +const ( + unset triState = iota + setTrue + setFalse +) + +func triStateFlag(name string, value triState, usage string) *triState { + flag.Var(&value, name, usage) + return &value +} + +// triState implements flag.Value, flag.Getter, and flag.boolFlag. +// They work like boolean flags: we can say vet -printf as well as vet -printf=true +func (ts *triState) Get() interface{} { + return *ts == setTrue +} + +func (ts triState) isTrue() bool { + return ts == setTrue +} + +func (ts *triState) Set(value string) error { + b, err := strconv.ParseBool(value) + if err != nil { + // This error message looks poor but package "flag" adds + // "invalid boolean value %q for -foo.enable: %s" + return fmt.Errorf("want true or false") + } + if b { + *ts = setTrue + } else { + *ts = setFalse + } + return nil +} + +func (ts *triState) String() string { + switch *ts { + case unset: + return "true" + case setTrue: + return "true" + case setFalse: + return "false" + } + panic("not reached") +} + +func (ts triState) IsBoolFlag() bool { + return true +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/facts.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/facts.go new file mode 100644 index 0000000000000..468f148900f9f --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/facts.go @@ -0,0 +1,299 @@ +// Copyright 2018 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. + +// Package facts defines a serializable set of analysis.Fact. +// +// It provides a partial implementation of the Fact-related parts of the +// analysis.Pass interface for use in analysis drivers such as "go vet" +// and other build systems. +// +// The serial format is unspecified and may change, so the same version +// of this package must be used for reading and writing serialized facts. +// +// The handling of facts in the analysis system parallels the handling +// of type information in the compiler: during compilation of package P, +// the compiler emits an export data file that describes the type of +// every object (named thing) defined in package P, plus every object +// indirectly reachable from one of those objects. Thus the downstream +// compiler of package Q need only load one export data file per direct +// import of Q, and it will learn everything about the API of package P +// and everything it needs to know about the API of P's dependencies. +// +// Similarly, analysis of package P emits a fact set containing facts +// about all objects exported from P, plus additional facts about only +// those objects of P's dependencies that are reachable from the API of +// package P; the downstream analysis of Q need only load one fact set +// per direct import of Q. +// +// The notion of "exportedness" that matters here is that of the +// compiler. According to the language spec, a method pkg.T.f is +// unexported simply because its name starts with lowercase. But the +// compiler must nonethless export f so that downstream compilations can +// accurately ascertain whether pkg.T implements an interface pkg.I +// defined as interface{f()}. Exported thus means "described in export +// data". +// +package facts + +import ( + "bytes" + "encoding/gob" + "fmt" + "go/types" + "io/ioutil" + "log" + "reflect" + "sort" + "sync" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/types/objectpath" +) + +const debug = false + +// A Set is a set of analysis.Facts. +// +// Decode creates a Set of facts by reading from the imports of a given +// package, and Encode writes out the set. Between these operation, +// the Import and Export methods will query and update the set. +// +// All of Set's methods except String are safe to call concurrently. +type Set struct { + pkg *types.Package + mu sync.Mutex + m map[key]analysis.Fact +} + +type key struct { + pkg *types.Package + obj types.Object // (object facts only) + t reflect.Type +} + +// ImportObjectFact implements analysis.Pass.ImportObjectFact. +func (s *Set) ImportObjectFact(obj types.Object, ptr analysis.Fact) bool { + if obj == nil { + panic("nil object") + } + key := key{pkg: obj.Pkg(), obj: obj, t: reflect.TypeOf(ptr)} + s.mu.Lock() + defer s.mu.Unlock() + if v, ok := s.m[key]; ok { + reflect.ValueOf(ptr).Elem().Set(reflect.ValueOf(v).Elem()) + return true + } + return false +} + +// ExportObjectFact implements analysis.Pass.ExportObjectFact. +func (s *Set) ExportObjectFact(obj types.Object, fact analysis.Fact) { + if obj.Pkg() != s.pkg { + log.Panicf("in package %s: ExportObjectFact(%s, %T): can't set fact on object belonging another package", + s.pkg, obj, fact) + } + key := key{pkg: obj.Pkg(), obj: obj, t: reflect.TypeOf(fact)} + s.mu.Lock() + s.m[key] = fact // clobber any existing entry + s.mu.Unlock() +} + +// ImportPackageFact implements analysis.Pass.ImportPackageFact. +func (s *Set) ImportPackageFact(pkg *types.Package, ptr analysis.Fact) bool { + if pkg == nil { + panic("nil package") + } + key := key{pkg: pkg, t: reflect.TypeOf(ptr)} + s.mu.Lock() + defer s.mu.Unlock() + if v, ok := s.m[key]; ok { + reflect.ValueOf(ptr).Elem().Set(reflect.ValueOf(v).Elem()) + return true + } + return false +} + +// ExportPackageFact implements analysis.Pass.ExportPackageFact. +func (s *Set) ExportPackageFact(fact analysis.Fact) { + key := key{pkg: s.pkg, t: reflect.TypeOf(fact)} + s.mu.Lock() + s.m[key] = fact // clobber any existing entry + s.mu.Unlock() +} + +// gobFact is the Gob declaration of a serialized fact. +type gobFact struct { + PkgPath string // path of package + Object objectpath.Path // optional path of object relative to package itself + Fact analysis.Fact // type and value of user-defined Fact +} + +// Decode decodes all the facts relevant to the analysis of package pkg. +// The read function reads serialized fact data from an external source +// for one of of pkg's direct imports. The empty file is a valid +// encoding of an empty fact set. +// +// It is the caller's responsibility to call gob.Register on all +// necessary fact types. +func Decode(pkg *types.Package, read func(packagePath string) ([]byte, error)) (*Set, error) { + // Compute the import map for this package. + // See the package doc comment. + packages := importMap(pkg.Imports()) + + // Read facts from imported packages. + // Facts may describe indirectly imported packages, or their objects. + m := make(map[key]analysis.Fact) // one big bucket + for _, imp := range pkg.Imports() { + logf := func(format string, args ...interface{}) { + if debug { + prefix := fmt.Sprintf("in %s, importing %s: ", + pkg.Path(), imp.Path()) + log.Print(prefix, fmt.Sprintf(format, args...)) + } + } + + // Read the gob-encoded facts. + data, err := read(imp.Path()) + if err != nil { + return nil, fmt.Errorf("in %s, can't import facts for package %q: %v", + pkg.Path(), imp.Path(), err) + } + if len(data) == 0 { + continue // no facts + } + var gobFacts []gobFact + if err := gob.NewDecoder(bytes.NewReader(data)).Decode(&gobFacts); err != nil { + return nil, fmt.Errorf("decoding facts for %q: %v", imp.Path(), err) + } + if debug { + logf("decoded %d facts: %v", len(gobFacts), gobFacts) + } + + // Parse each one into a key and a Fact. + for _, f := range gobFacts { + factPkg := packages[f.PkgPath] + if factPkg == nil { + // Fact relates to a dependency that was + // unused in this translation unit. Skip. + logf("no package %q; discarding %v", f.PkgPath, f.Fact) + continue + } + key := key{pkg: factPkg, t: reflect.TypeOf(f.Fact)} + if f.Object != "" { + // object fact + obj, err := objectpath.Object(factPkg, f.Object) + if err != nil { + // (most likely due to unexported object) + // TODO(adonovan): audit for other possibilities. + logf("no object for path: %v; discarding %s", err, f.Fact) + continue + } + key.obj = obj + logf("read %T fact %s for %v", f.Fact, f.Fact, key.obj) + } else { + // package fact + logf("read %T fact %s for %v", f.Fact, f.Fact, factPkg) + } + m[key] = f.Fact + } + } + + return &Set{pkg: pkg, m: m}, nil +} + +// Encode encodes a set of facts to a memory buffer. +// +// It may fail if one of the Facts could not be gob-encoded, but this is +// a sign of a bug in an Analyzer. +func (s *Set) Encode() []byte { + + // TODO(adonovan): opt: use a more efficient encoding + // that avoids repeating PkgPath for each fact. + + // Gather all facts, including those from imported packages. + var gobFacts []gobFact + + s.mu.Lock() + for k, fact := range s.m { + if debug { + log.Printf("%v => %s\n", k, fact) + } + var object objectpath.Path + if k.obj != nil { + path, err := objectpath.For(k.obj) + if err != nil { + if debug { + log.Printf("discarding fact %s about %s\n", fact, k.obj) + } + continue // object not accessible from package API; discard fact + } + object = path + } + gobFacts = append(gobFacts, gobFact{ + PkgPath: k.pkg.Path(), + Object: object, + Fact: fact, + }) + } + s.mu.Unlock() + + // Sort facts by (package, object, type) for determinism. + sort.Slice(gobFacts, func(i, j int) bool { + x, y := gobFacts[i], gobFacts[j] + if x.PkgPath != y.PkgPath { + return x.PkgPath < y.PkgPath + } + if x.Object != y.Object { + return x.Object < y.Object + } + tx := reflect.TypeOf(x.Fact) + ty := reflect.TypeOf(y.Fact) + if tx != ty { + return tx.String() < ty.String() + } + return false // equal + }) + + var buf bytes.Buffer + if len(gobFacts) > 0 { + if err := gob.NewEncoder(&buf).Encode(gobFacts); err != nil { + // Fact encoding should never fail. Identify the culprit. + for _, gf := range gobFacts { + if err := gob.NewEncoder(ioutil.Discard).Encode(gf); err != nil { + fact := gf.Fact + pkgpath := reflect.TypeOf(fact).Elem().PkgPath() + log.Panicf("internal error: gob encoding of analysis fact %s failed: %v; please report a bug against fact %T in package %q", + fact, err, fact, pkgpath) + } + } + } + } + + if debug { + log.Printf("package %q: encode %d facts, %d bytes\n", + s.pkg.Path(), len(gobFacts), buf.Len()) + } + + return buf.Bytes() +} + +// String is provided only for debugging, and must not be called +// concurrent with any Import/Export method. +func (s *Set) String() string { + var buf bytes.Buffer + buf.WriteString("{") + for k, f := range s.m { + if buf.Len() > 1 { + buf.WriteString(", ") + } + if k.obj != nil { + buf.WriteString(k.obj.String()) + } else { + buf.WriteString(k.pkg.Path()) + } + fmt.Fprintf(&buf, ": %v", f) + } + buf.WriteString("}") + return buf.String() +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/imports.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/imports.go new file mode 100644 index 0000000000000..34740f48e04ca --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/facts/imports.go @@ -0,0 +1,88 @@ +// Copyright 2018 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. + +package facts + +import "go/types" + +// importMap computes the import map for a package by traversing the +// entire exported API each of its imports. +// +// This is a workaround for the fact that we cannot access the map used +// internally by the types.Importer returned by go/importer. The entries +// in this map are the packages and objects that may be relevant to the +// current analysis unit. +// +// Packages in the map that are only indirectly imported may be +// incomplete (!pkg.Complete()). +// +func importMap(imports []*types.Package) map[string]*types.Package { + objects := make(map[types.Object]bool) + packages := make(map[string]*types.Package) + + var addObj func(obj types.Object) bool + var addType func(T types.Type) + + addObj = func(obj types.Object) bool { + if !objects[obj] { + objects[obj] = true + addType(obj.Type()) + if pkg := obj.Pkg(); pkg != nil { + packages[pkg.Path()] = pkg + } + return true + } + return false + } + + addType = func(T types.Type) { + switch T := T.(type) { + case *types.Basic: + // nop + case *types.Named: + if addObj(T.Obj()) { + for i := 0; i < T.NumMethods(); i++ { + addObj(T.Method(i)) + } + } + case *types.Pointer: + addType(T.Elem()) + case *types.Slice: + addType(T.Elem()) + case *types.Array: + addType(T.Elem()) + case *types.Chan: + addType(T.Elem()) + case *types.Map: + addType(T.Key()) + addType(T.Elem()) + case *types.Signature: + addType(T.Params()) + addType(T.Results()) + case *types.Struct: + for i := 0; i < T.NumFields(); i++ { + addObj(T.Field(i)) + } + case *types.Tuple: + for i := 0; i < T.Len(); i++ { + addObj(T.At(i)) + } + case *types.Interface: + for i := 0; i < T.NumMethods(); i++ { + addObj(T.Method(i)) + } + } + } + + for _, imp := range imports { + packages[imp.Path()] = imp + + scope := imp.Scope() + for _, name := range scope.Names() { + addObj(scope.Lookup(name)) + } + } + + return packages +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/unitchecker/unitchecker.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/unitchecker/unitchecker.go new file mode 100644 index 0000000000000..b67c943b4e261 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/internal/unitchecker/unitchecker.go @@ -0,0 +1,306 @@ +// Copyright 2018 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. + +// The unitchecker package defines the main function for an analysis +// driver that analyzes a single compilation unit during a build. +// It is invoked by a build system such as "go vet": +// +// $ GOVETTOOL=$(which vet) go vet +// +// It supports the following command-line protocol: +// +// -V=full describe executable (to the build tool) +// -flags describe flags (to the build tool) +// foo.cfg description of compilation unit (from the build tool) +// +// This package does not depend on go/packages. +// If you need a standalone tool, use multichecker, +// which supports this mode but can also load packages +// from source using go/packages. +package unitchecker + +// TODO(adonovan): +// - with gccgo, go build does not build standard library, +// so we will not get to analyze it. Yet we must in order +// to create base facts for, say, the fmt package for the +// printf checker. +// - support JSON output, factored with multichecker. + +import ( + "encoding/gob" + "encoding/json" + "fmt" + "go/ast" + "go/build" + "go/importer" + "go/parser" + "go/token" + "go/types" + "io" + "io/ioutil" + "log" + "os" + "sort" + "strings" + "sync" + "time" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/internal/facts" +) + +// A Config describes a compilation unit to be analyzed. +// It is provided to the tool in a JSON-encoded file +// whose name ends with ".cfg". +type Config struct { + Compiler string + Dir string + ImportPath string + GoFiles []string + OtherFiles []string // TODO(adonovan): make go vet populate this (github.com/golang/go/issues/27665) + ImportMap map[string]string + PackageFile map[string]string + Standard map[string]bool + PackageVetx map[string]string + VetxOnly bool + VetxOutput string + SucceedOnTypecheckFailure bool +} + +// Main reads the *.cfg file, runs the analysis, +// and calls os.Exit with an appropriate error code. +func Main(configFile string, analyzers []*analysis.Analyzer) { + cfg, err := readConfig(configFile) + if err != nil { + log.Fatal(err) + } + + fset := token.NewFileSet() + diags, err := run(fset, cfg, analyzers) + if err != nil { + log.Fatal(err) + } + + if len(diags) > 0 { + for _, diag := range diags { + fmt.Fprintf(os.Stderr, "%s: %s\n", fset.Position(diag.Pos), diag.Message) + } + os.Exit(1) + } + + os.Exit(0) +} + +func readConfig(filename string) (*Config, error) { + data, err := ioutil.ReadFile(filename) + if err != nil { + return nil, err + } + cfg := new(Config) + if err := json.Unmarshal(data, cfg); err != nil { + return nil, fmt.Errorf("cannot decode JSON config file %s: %v", filename, err) + } + if len(cfg.GoFiles) == 0 { + // The go command disallows packages with no files. + // The only exception is unsafe, but the go command + // doesn't call vet on it. + return nil, fmt.Errorf("package has no files: %s", cfg.ImportPath) + } + return cfg, nil +} + +func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]analysis.Diagnostic, error) { + // Load, parse, typecheck. + var files []*ast.File + for _, name := range cfg.GoFiles { + f, err := parser.ParseFile(fset, name, nil, parser.ParseComments) + if err != nil { + if cfg.SucceedOnTypecheckFailure { + // Silently succeed; let the compiler + // report parse errors. + err = nil + } + return nil, err + } + files = append(files, f) + } + compilerImporter := importer.For(cfg.Compiler, func(path string) (io.ReadCloser, error) { + // path is a resolved package path, not an import path. + file, ok := cfg.PackageFile[path] + if !ok { + if cfg.Compiler == "gccgo" && cfg.Standard[path] { + return nil, nil // fall back to default gccgo lookup + } + return nil, fmt.Errorf("no package file for %q", path) + } + return os.Open(file) + }) + importer := importerFunc(func(importPath string) (*types.Package, error) { + path, ok := cfg.ImportMap[importPath] // resolve vendoring, etc + if !ok { + return nil, fmt.Errorf("can't resolve import %q", path) + } + return compilerImporter.Import(path) + }) + tc := &types.Config{ + Importer: importer, + Sizes: types.SizesFor("gc", build.Default.GOARCH), // assume gccgo ≡ gc? + } + info := &types.Info{ + Types: make(map[ast.Expr]types.TypeAndValue), + Defs: make(map[*ast.Ident]types.Object), + Uses: make(map[*ast.Ident]types.Object), + Implicits: make(map[ast.Node]types.Object), + Scopes: make(map[ast.Node]*types.Scope), + Selections: make(map[*ast.SelectorExpr]*types.Selection), + } + pkg, err := tc.Check(cfg.ImportPath, fset, files, info) + if err != nil { + if cfg.SucceedOnTypecheckFailure { + // Silently succeed; let the compiler + // report type errors. + err = nil + } + return nil, err + } + + // Register fact types with gob. + // In VetxOnly mode, analyzers are only for their facts, + // so we can skip any analysis that neither produces facts + // nor depends on any analysis that produces facts. + // Also build a map to hold working state and result. + type action struct { + once sync.Once + result interface{} + err error + usesFacts bool // (transitively uses) + diagnostics []analysis.Diagnostic + } + actions := make(map[*analysis.Analyzer]*action) + var registerFacts func(a *analysis.Analyzer) bool + registerFacts = func(a *analysis.Analyzer) bool { + act, ok := actions[a] + if !ok { + act = new(action) + var usesFacts bool + for _, f := range a.FactTypes { + usesFacts = true + gob.Register(f) + } + for _, req := range a.Requires { + if registerFacts(req) { + usesFacts = true + } + } + act.usesFacts = usesFacts + actions[a] = act + } + return act.usesFacts + } + var filtered []*analysis.Analyzer + for _, a := range analyzers { + if registerFacts(a) || !cfg.VetxOnly { + filtered = append(filtered, a) + } + } + analyzers = filtered + + // Read facts from imported packages. + read := func(path string) ([]byte, error) { + if vetx, ok := cfg.PackageVetx[path]; ok { + return ioutil.ReadFile(vetx) + } + return nil, nil // no .vetx file, no facts + } + facts, err := facts.Decode(pkg, read) + if err != nil { + return nil, err + } + + // In parallel, execute the DAG of analyzers. + var exec func(a *analysis.Analyzer) *action + var execAll func(analyzers []*analysis.Analyzer) + exec = func(a *analysis.Analyzer) *action { + act := actions[a] + act.once.Do(func() { + execAll(a.Requires) // prefetch dependencies in parallel + + // The inputs to this analysis are the + // results of its prerequisites. + inputs := make(map[*analysis.Analyzer]interface{}) + var failed []string + for _, req := range a.Requires { + reqact := exec(req) + if reqact.err != nil { + failed = append(failed, req.String()) + continue + } + inputs[req] = reqact.result + } + + // Report an error if any dependency failed. + if failed != nil { + sort.Strings(failed) + act.err = fmt.Errorf("failed prerequisites: %s", strings.Join(failed, ", ")) + return + } + + pass := &analysis.Pass{ + Analyzer: a, + Fset: fset, + Files: files, + OtherFiles: cfg.OtherFiles, + Pkg: pkg, + TypesInfo: info, + ResultOf: inputs, + Report: func(d analysis.Diagnostic) { act.diagnostics = append(act.diagnostics, d) }, + ImportObjectFact: facts.ImportObjectFact, + ExportObjectFact: facts.ExportObjectFact, + ImportPackageFact: facts.ImportPackageFact, + ExportPackageFact: facts.ExportPackageFact, + } + + t0 := time.Now() + act.result, act.err = a.Run(pass) + if false { + log.Printf("analysis %s = %s", pass, time.Since(t0)) + } + }) + return act + } + execAll = func(analyzers []*analysis.Analyzer) { + var wg sync.WaitGroup + for _, a := range analyzers { + wg.Add(1) + go func(a *analysis.Analyzer) { + _ = exec(a) + wg.Done() + }(a) + } + wg.Wait() + } + + execAll(analyzers) + + // Return diagnostics from root analyzers. + var diags []analysis.Diagnostic + for _, a := range analyzers { + act := actions[a] + if act.err != nil { + return nil, act.err // some analysis failed + } + diags = append(diags, act.diagnostics...) + } + + data := facts.Encode() + if err := ioutil.WriteFile(cfg.VetxOutput, data, 0666); err != nil { + return nil, fmt.Errorf("failed to write analysis facts: %v", err) + } + + return diags, nil +} + +type importerFunc func(path string) (*types.Package, error) + +func (f importerFunc) Import(path string) (*types.Package, error) { return f(path) } diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/asmdecl/asmdecl.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/asmdecl/asmdecl.go new file mode 100644 index 0000000000000..11dfbf6bc8e30 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/asmdecl/asmdecl.go @@ -0,0 +1,759 @@ +// Copyright 2013 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. + +// Package asmdecl defines an Analyzer that reports mismatches between +// assembly files and Go declarations. +package asmdecl + +import ( + "bytes" + "fmt" + "go/ast" + "go/build" + "go/token" + "go/types" + "log" + "regexp" + "strconv" + "strings" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" +) + +var Analyzer = &analysis.Analyzer{ + Name: "asmdecl", + Doc: "report mismatches between assembly files and Go declarations", + Run: run, +} + +// 'kind' is a kind of assembly variable. +// The kinds 1, 2, 4, 8 stand for values of that size. +type asmKind int + +// These special kinds are not valid sizes. +const ( + asmString asmKind = 100 + iota + asmSlice + asmArray + asmInterface + asmEmptyInterface + asmStruct + asmComplex +) + +// An asmArch describes assembly parameters for an architecture +type asmArch struct { + name string + bigEndian bool + stack string + lr bool + // calculated during initialization + sizes types.Sizes + intSize int + ptrSize int + maxAlign int +} + +// An asmFunc describes the expected variables for a function on a given architecture. +type asmFunc struct { + arch *asmArch + size int // size of all arguments + vars map[string]*asmVar + varByOffset map[int]*asmVar +} + +// An asmVar describes a single assembly variable. +type asmVar struct { + name string + kind asmKind + typ string + off int + size int + inner []*asmVar +} + +var ( + asmArch386 = asmArch{name: "386", bigEndian: false, stack: "SP", lr: false} + asmArchArm = asmArch{name: "arm", bigEndian: false, stack: "R13", lr: true} + asmArchArm64 = asmArch{name: "arm64", bigEndian: false, stack: "RSP", lr: true} + asmArchAmd64 = asmArch{name: "amd64", bigEndian: false, stack: "SP", lr: false} + asmArchAmd64p32 = asmArch{name: "amd64p32", bigEndian: false, stack: "SP", lr: false} + asmArchMips = asmArch{name: "mips", bigEndian: true, stack: "R29", lr: true} + asmArchMipsLE = asmArch{name: "mipsle", bigEndian: false, stack: "R29", lr: true} + asmArchMips64 = asmArch{name: "mips64", bigEndian: true, stack: "R29", lr: true} + asmArchMips64LE = asmArch{name: "mips64le", bigEndian: false, stack: "R29", lr: true} + asmArchPpc64 = asmArch{name: "ppc64", bigEndian: true, stack: "R1", lr: true} + asmArchPpc64LE = asmArch{name: "ppc64le", bigEndian: false, stack: "R1", lr: true} + asmArchS390X = asmArch{name: "s390x", bigEndian: true, stack: "R15", lr: true} + asmArchWasm = asmArch{name: "wasm", bigEndian: false, stack: "SP", lr: false} + + arches = []*asmArch{ + &asmArch386, + &asmArchArm, + &asmArchArm64, + &asmArchAmd64, + &asmArchAmd64p32, + &asmArchMips, + &asmArchMipsLE, + &asmArchMips64, + &asmArchMips64LE, + &asmArchPpc64, + &asmArchPpc64LE, + &asmArchS390X, + &asmArchWasm, + } +) + +func init() { + for _, arch := range arches { + arch.sizes = types.SizesFor("gc", arch.name) + if arch.sizes == nil { + // TODO(adonovan): fix: now that asmdecl is not in the standard + // library we cannot assume types.SizesFor is consistent with arches. + // For now, assume 64-bit norms and print a warning. + // But this warning should really be deferred until we attempt to use + // arch, which is very unlikely. + arch.sizes = types.SizesFor("gc", "amd64") + log.Printf("unknown architecture %s", arch.name) + } + arch.intSize = int(arch.sizes.Sizeof(types.Typ[types.Int])) + arch.ptrSize = int(arch.sizes.Sizeof(types.Typ[types.UnsafePointer])) + arch.maxAlign = int(arch.sizes.Alignof(types.Typ[types.Int64])) + } +} + +var ( + re = regexp.MustCompile + asmPlusBuild = re(`//\s+\+build\s+([^\n]+)`) + asmTEXT = re(`\bTEXT\b(.*)·([^\(]+)\(SB\)(?:\s*,\s*([0-9A-Z|+()]+))?(?:\s*,\s*\$(-?[0-9]+)(?:-([0-9]+))?)?`) + asmDATA = re(`\b(DATA|GLOBL)\b`) + asmNamedFP = re(`([a-zA-Z0-9_\xFF-\x{10FFFF}]+)(?:\+([0-9]+))\(FP\)`) + asmUnnamedFP = re(`[^+\-0-9](([0-9]+)\(FP\))`) + asmSP = re(`[^+\-0-9](([0-9]+)\(([A-Z0-9]+)\))`) + asmOpcode = re(`^\s*(?:[A-Z0-9a-z_]+:)?\s*([A-Z]+)\s*([^,]*)(?:,\s*(.*))?`) + ppc64Suff = re(`([BHWD])(ZU|Z|U|BR)?$`) +) + +func run(pass *analysis.Pass) (interface{}, error) { + // No work if no assembly files. + var sfiles []string + for _, fname := range pass.OtherFiles { + if strings.HasSuffix(fname, ".s") { + sfiles = append(sfiles, fname) + } + } + if sfiles == nil { + return nil, nil + } + + // Gather declarations. knownFunc[name][arch] is func description. + knownFunc := make(map[string]map[string]*asmFunc) + + for _, f := range pass.Files { + for _, decl := range f.Decls { + if decl, ok := decl.(*ast.FuncDecl); ok && decl.Body == nil { + knownFunc[decl.Name.Name] = asmParseDecl(pass, decl) + } + } + } + +Files: + for _, fname := range sfiles { + content, tf, err := analysisutil.ReadFile(pass.Fset, fname) + if err != nil { + return nil, err + } + + // Determine architecture from file name if possible. + var arch string + var archDef *asmArch + for _, a := range arches { + if strings.HasSuffix(fname, "_"+a.name+".s") { + arch = a.name + archDef = a + break + } + } + + lines := strings.SplitAfter(string(content), "\n") + var ( + fn *asmFunc + fnName string + localSize, argSize int + wroteSP bool + haveRetArg bool + retLine []int + ) + + flushRet := func() { + if fn != nil && fn.vars["ret"] != nil && !haveRetArg && len(retLine) > 0 { + v := fn.vars["ret"] + for _, line := range retLine { + pass.Reportf(analysisutil.LineStart(tf, line), "[%s] %s: RET without writing to %d-byte ret+%d(FP)", arch, fnName, v.size, v.off) + } + } + retLine = nil + } + for lineno, line := range lines { + lineno++ + + badf := func(format string, args ...interface{}) { + pass.Reportf(analysisutil.LineStart(tf, lineno), "[%s] %s: %s", arch, fnName, fmt.Sprintf(format, args...)) + } + + if arch == "" { + // Determine architecture from +build line if possible. + if m := asmPlusBuild.FindStringSubmatch(line); m != nil { + // There can be multiple architectures in a single +build line, + // so accumulate them all and then prefer the one that + // matches build.Default.GOARCH. + var archCandidates []*asmArch + for _, fld := range strings.Fields(m[1]) { + for _, a := range arches { + if a.name == fld { + archCandidates = append(archCandidates, a) + } + } + } + for _, a := range archCandidates { + if a.name == build.Default.GOARCH { + archCandidates = []*asmArch{a} + break + } + } + if len(archCandidates) > 0 { + arch = archCandidates[0].name + archDef = archCandidates[0] + } + } + } + + if m := asmTEXT.FindStringSubmatch(line); m != nil { + flushRet() + if arch == "" { + // Arch not specified by filename or build tags. + // Fall back to build.Default.GOARCH. + for _, a := range arches { + if a.name == build.Default.GOARCH { + arch = a.name + archDef = a + break + } + } + if arch == "" { + badf("%s: cannot determine architecture for assembly file") + continue Files + } + } + fnName = m[2] + if pkgName := strings.TrimSpace(m[1]); pkgName != "" { + pathParts := strings.Split(pkgName, "∕") + pkgName = pathParts[len(pathParts)-1] + if pkgName != pass.Pkg.Path() { + badf("[%s] cannot check cross-package assembly function: %s is in package %s", arch, fnName, pkgName) + fn = nil + fnName = "" + continue + } + } + flag := m[3] + fn = knownFunc[fnName][arch] + if fn != nil { + size, _ := strconv.Atoi(m[5]) + if size != fn.size && (flag != "7" && !strings.Contains(flag, "NOSPLIT") || size != 0) { + badf("wrong argument size %d; expected $...-%d", size, fn.size) + } + } + localSize, _ = strconv.Atoi(m[4]) + localSize += archDef.intSize + if archDef.lr && !strings.Contains(flag, "NOFRAME") { + // Account for caller's saved LR + localSize += archDef.intSize + } + argSize, _ = strconv.Atoi(m[5]) + if fn == nil && !strings.Contains(fnName, "<>") { + badf("function %s missing Go declaration", fnName) + } + wroteSP = false + haveRetArg = false + continue + } else if strings.Contains(line, "TEXT") && strings.Contains(line, "SB") { + // function, but not visible from Go (didn't match asmTEXT), so stop checking + flushRet() + fn = nil + fnName = "" + continue + } + + if strings.Contains(line, "RET") { + retLine = append(retLine, lineno) + } + + if fnName == "" { + continue + } + + if asmDATA.FindStringSubmatch(line) != nil { + fn = nil + } + + if archDef == nil { + continue + } + + if strings.Contains(line, ", "+archDef.stack) || strings.Contains(line, ",\t"+archDef.stack) { + wroteSP = true + continue + } + + for _, m := range asmSP.FindAllStringSubmatch(line, -1) { + if m[3] != archDef.stack || wroteSP { + continue + } + off := 0 + if m[1] != "" { + off, _ = strconv.Atoi(m[2]) + } + if off >= localSize { + if fn != nil { + v := fn.varByOffset[off-localSize] + if v != nil { + badf("%s should be %s+%d(FP)", m[1], v.name, off-localSize) + continue + } + } + if off >= localSize+argSize { + badf("use of %s points beyond argument frame", m[1]) + continue + } + badf("use of %s to access argument frame", m[1]) + } + } + + if fn == nil { + continue + } + + for _, m := range asmUnnamedFP.FindAllStringSubmatch(line, -1) { + off, _ := strconv.Atoi(m[2]) + v := fn.varByOffset[off] + if v != nil { + badf("use of unnamed argument %s; offset %d is %s+%d(FP)", m[1], off, v.name, v.off) + } else { + badf("use of unnamed argument %s", m[1]) + } + } + + for _, m := range asmNamedFP.FindAllStringSubmatch(line, -1) { + name := m[1] + off := 0 + if m[2] != "" { + off, _ = strconv.Atoi(m[2]) + } + if name == "ret" || strings.HasPrefix(name, "ret_") { + haveRetArg = true + } + v := fn.vars[name] + if v == nil { + // Allow argframe+0(FP). + if name == "argframe" && off == 0 { + continue + } + v = fn.varByOffset[off] + if v != nil { + badf("unknown variable %s; offset %d is %s+%d(FP)", name, off, v.name, v.off) + } else { + badf("unknown variable %s", name) + } + continue + } + asmCheckVar(badf, fn, line, m[0], off, v) + } + } + flushRet() + } + return nil, nil +} + +func asmKindForType(t types.Type, size int) asmKind { + switch t := t.Underlying().(type) { + case *types.Basic: + switch t.Kind() { + case types.String: + return asmString + case types.Complex64, types.Complex128: + return asmComplex + } + return asmKind(size) + case *types.Pointer, *types.Chan, *types.Map, *types.Signature: + return asmKind(size) + case *types.Struct: + return asmStruct + case *types.Interface: + if t.Empty() { + return asmEmptyInterface + } + return asmInterface + case *types.Array: + return asmArray + case *types.Slice: + return asmSlice + } + panic("unreachable") +} + +// A component is an assembly-addressable component of a composite type, +// or a composite type itself. +type component struct { + size int + offset int + kind asmKind + typ string + suffix string // Such as _base for string base, _0_lo for lo half of first element of [1]uint64 on 32 bit machine. + outer string // The suffix for immediately containing composite type. +} + +func newComponent(suffix string, kind asmKind, typ string, offset, size int, outer string) component { + return component{suffix: suffix, kind: kind, typ: typ, offset: offset, size: size, outer: outer} +} + +// componentsOfType generates a list of components of type t. +// For example, given string, the components are the string itself, the base, and the length. +func componentsOfType(arch *asmArch, t types.Type) []component { + return appendComponentsRecursive(arch, t, nil, "", 0) +} + +// appendComponentsRecursive implements componentsOfType. +// Recursion is required to correct handle structs and arrays, +// which can contain arbitrary other types. +func appendComponentsRecursive(arch *asmArch, t types.Type, cc []component, suffix string, off int) []component { + s := t.String() + size := int(arch.sizes.Sizeof(t)) + kind := asmKindForType(t, size) + cc = append(cc, newComponent(suffix, kind, s, off, size, suffix)) + + switch kind { + case 8: + if arch.ptrSize == 4 { + w1, w2 := "lo", "hi" + if arch.bigEndian { + w1, w2 = w2, w1 + } + cc = append(cc, newComponent(suffix+"_"+w1, 4, "half "+s, off, 4, suffix)) + cc = append(cc, newComponent(suffix+"_"+w2, 4, "half "+s, off+4, 4, suffix)) + } + + case asmEmptyInterface: + cc = append(cc, newComponent(suffix+"_type", asmKind(arch.ptrSize), "interface type", off, arch.ptrSize, suffix)) + cc = append(cc, newComponent(suffix+"_data", asmKind(arch.ptrSize), "interface data", off+arch.ptrSize, arch.ptrSize, suffix)) + + case asmInterface: + cc = append(cc, newComponent(suffix+"_itable", asmKind(arch.ptrSize), "interface itable", off, arch.ptrSize, suffix)) + cc = append(cc, newComponent(suffix+"_data", asmKind(arch.ptrSize), "interface data", off+arch.ptrSize, arch.ptrSize, suffix)) + + case asmSlice: + cc = append(cc, newComponent(suffix+"_base", asmKind(arch.ptrSize), "slice base", off, arch.ptrSize, suffix)) + cc = append(cc, newComponent(suffix+"_len", asmKind(arch.intSize), "slice len", off+arch.ptrSize, arch.intSize, suffix)) + cc = append(cc, newComponent(suffix+"_cap", asmKind(arch.intSize), "slice cap", off+arch.ptrSize+arch.intSize, arch.intSize, suffix)) + + case asmString: + cc = append(cc, newComponent(suffix+"_base", asmKind(arch.ptrSize), "string base", off, arch.ptrSize, suffix)) + cc = append(cc, newComponent(suffix+"_len", asmKind(arch.intSize), "string len", off+arch.ptrSize, arch.intSize, suffix)) + + case asmComplex: + fsize := size / 2 + cc = append(cc, newComponent(suffix+"_real", asmKind(fsize), fmt.Sprintf("real(complex%d)", size*8), off, fsize, suffix)) + cc = append(cc, newComponent(suffix+"_imag", asmKind(fsize), fmt.Sprintf("imag(complex%d)", size*8), off+fsize, fsize, suffix)) + + case asmStruct: + tu := t.Underlying().(*types.Struct) + fields := make([]*types.Var, tu.NumFields()) + for i := 0; i < tu.NumFields(); i++ { + fields[i] = tu.Field(i) + } + offsets := arch.sizes.Offsetsof(fields) + for i, f := range fields { + cc = appendComponentsRecursive(arch, f.Type(), cc, suffix+"_"+f.Name(), off+int(offsets[i])) + } + + case asmArray: + tu := t.Underlying().(*types.Array) + elem := tu.Elem() + // Calculate offset of each element array. + fields := []*types.Var{ + types.NewVar(token.NoPos, nil, "fake0", elem), + types.NewVar(token.NoPos, nil, "fake1", elem), + } + offsets := arch.sizes.Offsetsof(fields) + elemoff := int(offsets[1]) + for i := 0; i < int(tu.Len()); i++ { + cc = appendComponentsRecursive(arch, elem, cc, suffix+"_"+strconv.Itoa(i), i*elemoff) + } + } + + return cc +} + +// asmParseDecl parses a function decl for expected assembly variables. +func asmParseDecl(pass *analysis.Pass, decl *ast.FuncDecl) map[string]*asmFunc { + var ( + arch *asmArch + fn *asmFunc + offset int + ) + + // addParams adds asmVars for each of the parameters in list. + // isret indicates whether the list are the arguments or the return values. + // TODO(adonovan): simplify by passing (*types.Signature).{Params,Results} + // instead of list. + addParams := func(list []*ast.Field, isret bool) { + argnum := 0 + for _, fld := range list { + t := pass.TypesInfo.Types[fld.Type].Type + + // Work around github.com/golang/go/issues/28277. + if t == nil { + if ell, ok := fld.Type.(*ast.Ellipsis); ok { + t = types.NewSlice(pass.TypesInfo.Types[ell.Elt].Type) + } + } + + align := int(arch.sizes.Alignof(t)) + size := int(arch.sizes.Sizeof(t)) + offset += -offset & (align - 1) + cc := componentsOfType(arch, t) + + // names is the list of names with this type. + names := fld.Names + if len(names) == 0 { + // Anonymous args will be called arg, arg1, arg2, ... + // Similarly so for return values: ret, ret1, ret2, ... + name := "arg" + if isret { + name = "ret" + } + if argnum > 0 { + name += strconv.Itoa(argnum) + } + names = []*ast.Ident{ast.NewIdent(name)} + } + argnum += len(names) + + // Create variable for each name. + for _, id := range names { + name := id.Name + for _, c := range cc { + outer := name + c.outer + v := asmVar{ + name: name + c.suffix, + kind: c.kind, + typ: c.typ, + off: offset + c.offset, + size: c.size, + } + if vo := fn.vars[outer]; vo != nil { + vo.inner = append(vo.inner, &v) + } + fn.vars[v.name] = &v + for i := 0; i < v.size; i++ { + fn.varByOffset[v.off+i] = &v + } + } + offset += size + } + } + } + + m := make(map[string]*asmFunc) + for _, arch = range arches { + fn = &asmFunc{ + arch: arch, + vars: make(map[string]*asmVar), + varByOffset: make(map[int]*asmVar), + } + offset = 0 + addParams(decl.Type.Params.List, false) + if decl.Type.Results != nil && len(decl.Type.Results.List) > 0 { + offset += -offset & (arch.maxAlign - 1) + addParams(decl.Type.Results.List, true) + } + fn.size = offset + m[arch.name] = fn + } + + return m +} + +// asmCheckVar checks a single variable reference. +func asmCheckVar(badf func(string, ...interface{}), fn *asmFunc, line, expr string, off int, v *asmVar) { + m := asmOpcode.FindStringSubmatch(line) + if m == nil { + if !strings.HasPrefix(strings.TrimSpace(line), "//") { + badf("cannot find assembly opcode") + } + return + } + + // Determine operand sizes from instruction. + // Typically the suffix suffices, but there are exceptions. + var src, dst, kind asmKind + op := m[1] + switch fn.arch.name + "." + op { + case "386.FMOVLP": + src, dst = 8, 4 + case "arm.MOVD": + src = 8 + case "arm.MOVW": + src = 4 + case "arm.MOVH", "arm.MOVHU": + src = 2 + case "arm.MOVB", "arm.MOVBU": + src = 1 + // LEA* opcodes don't really read the second arg. + // They just take the address of it. + case "386.LEAL": + dst = 4 + case "amd64.LEAQ": + dst = 8 + case "amd64p32.LEAL": + dst = 4 + default: + switch fn.arch.name { + case "386", "amd64": + if strings.HasPrefix(op, "F") && (strings.HasSuffix(op, "D") || strings.HasSuffix(op, "DP")) { + // FMOVDP, FXCHD, etc + src = 8 + break + } + if strings.HasPrefix(op, "P") && strings.HasSuffix(op, "RD") { + // PINSRD, PEXTRD, etc + src = 4 + break + } + if strings.HasPrefix(op, "F") && (strings.HasSuffix(op, "F") || strings.HasSuffix(op, "FP")) { + // FMOVFP, FXCHF, etc + src = 4 + break + } + if strings.HasSuffix(op, "SD") { + // MOVSD, SQRTSD, etc + src = 8 + break + } + if strings.HasSuffix(op, "SS") { + // MOVSS, SQRTSS, etc + src = 4 + break + } + if strings.HasPrefix(op, "SET") { + // SETEQ, etc + src = 1 + break + } + switch op[len(op)-1] { + case 'B': + src = 1 + case 'W': + src = 2 + case 'L': + src = 4 + case 'D', 'Q': + src = 8 + } + case "ppc64", "ppc64le": + // Strip standard suffixes to reveal size letter. + m := ppc64Suff.FindStringSubmatch(op) + if m != nil { + switch m[1][0] { + case 'B': + src = 1 + case 'H': + src = 2 + case 'W': + src = 4 + case 'D': + src = 8 + } + } + case "mips", "mipsle", "mips64", "mips64le": + switch op { + case "MOVB", "MOVBU": + src = 1 + case "MOVH", "MOVHU": + src = 2 + case "MOVW", "MOVWU", "MOVF": + src = 4 + case "MOVV", "MOVD": + src = 8 + } + case "s390x": + switch op { + case "MOVB", "MOVBZ": + src = 1 + case "MOVH", "MOVHZ": + src = 2 + case "MOVW", "MOVWZ", "FMOVS": + src = 4 + case "MOVD", "FMOVD": + src = 8 + } + } + } + if dst == 0 { + dst = src + } + + // Determine whether the match we're holding + // is the first or second argument. + if strings.Index(line, expr) > strings.Index(line, ",") { + kind = dst + } else { + kind = src + } + + vk := v.kind + vs := v.size + vt := v.typ + switch vk { + case asmInterface, asmEmptyInterface, asmString, asmSlice: + // allow reference to first word (pointer) + vk = v.inner[0].kind + vs = v.inner[0].size + vt = v.inner[0].typ + } + + if off != v.off { + var inner bytes.Buffer + for i, vi := range v.inner { + if len(v.inner) > 1 { + fmt.Fprintf(&inner, ",") + } + fmt.Fprintf(&inner, " ") + if i == len(v.inner)-1 { + fmt.Fprintf(&inner, "or ") + } + fmt.Fprintf(&inner, "%s+%d(FP)", vi.name, vi.off) + } + badf("invalid offset %s; expected %s+%d(FP)%s", expr, v.name, v.off, inner.String()) + return + } + if kind != 0 && kind != vk { + var inner bytes.Buffer + if len(v.inner) > 0 { + fmt.Fprintf(&inner, " containing") + for i, vi := range v.inner { + if i > 0 && len(v.inner) > 2 { + fmt.Fprintf(&inner, ",") + } + fmt.Fprintf(&inner, " ") + if i > 0 && i == len(v.inner)-1 { + fmt.Fprintf(&inner, "and ") + } + fmt.Fprintf(&inner, "%s+%d(FP)", vi.name, vi.off) + } + } + badf("invalid %s of %s; %s is %d-byte value%s", op, expr, vt, vs, inner.String()) + } +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/assign/assign.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/assign/assign.go new file mode 100644 index 0000000000000..4dff2908c32b4 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/assign/assign.go @@ -0,0 +1,68 @@ +// Copyright 2013 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. + +// Package assign defines an Analyzer that detects useless assignments. +package assign + +// TODO(adonovan): check also for assignments to struct fields inside +// methods that are on T instead of *T. + +import ( + "go/ast" + "go/token" + "reflect" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `check for useless assignments + +This checker reports assignments of the form x = x or a[i] = a[i]. +These are almost always useless, and even when they aren't they are +usually a mistake.` + +var Analyzer = &analysis.Analyzer{ + Name: "assign", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.AssignStmt)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + stmt := n.(*ast.AssignStmt) + if stmt.Tok != token.ASSIGN { + return // ignore := + } + if len(stmt.Lhs) != len(stmt.Rhs) { + // If LHS and RHS have different cardinality, they can't be the same. + return + } + for i, lhs := range stmt.Lhs { + rhs := stmt.Rhs[i] + if analysisutil.HasSideEffects(pass.TypesInfo, lhs) || + analysisutil.HasSideEffects(pass.TypesInfo, rhs) { + continue // expressions may not be equal + } + if reflect.TypeOf(lhs) != reflect.TypeOf(rhs) { + continue // short-circuit the heavy-weight gofmt check + } + le := analysisutil.Format(pass.Fset, lhs) + re := analysisutil.Format(pass.Fset, rhs) + if le == re { + pass.Reportf(stmt.Pos(), "self-assignment of %s to %s", re, le) + } + } + }) + + return nil, nil +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/atomic/atomic.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/atomic/atomic.go new file mode 100644 index 0000000000000..45243d6f8c0d9 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/atomic/atomic.go @@ -0,0 +1,96 @@ +// Copyright 2013 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. + +// Package atomic defines an Analyzer that checks for common mistakes +// using the sync/atomic package. +package atomic + +import ( + "go/ast" + "go/token" + "go/types" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `check for common mistakes using the sync/atomic package + +The atomic checker looks for assignment statements of the form: + + x = atomic.AddUint64(&x, 1) + +which are not atomic.` + +var Analyzer = &analysis.Analyzer{ + Name: "atomic", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + RunDespiteErrors: true, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.AssignStmt)(nil), + } + inspect.Preorder(nodeFilter, func(node ast.Node) { + n := node.(*ast.AssignStmt) + if len(n.Lhs) != len(n.Rhs) { + return + } + if len(n.Lhs) == 1 && n.Tok == token.DEFINE { + return + } + + for i, right := range n.Rhs { + call, ok := right.(*ast.CallExpr) + if !ok { + continue + } + sel, ok := call.Fun.(*ast.SelectorExpr) + if !ok { + continue + } + pkgIdent, _ := sel.X.(*ast.Ident) + pkgName, ok := pass.TypesInfo.Uses[pkgIdent].(*types.PkgName) + if !ok || pkgName.Imported().Path() != "sync/atomic" { + continue + } + + switch sel.Sel.Name { + case "AddInt32", "AddInt64", "AddUint32", "AddUint64", "AddUintptr": + checkAtomicAddAssignment(pass, n.Lhs[i], call) + } + } + }) + return nil, nil +} + +// checkAtomicAddAssignment walks the atomic.Add* method calls checking +// for assigning the return value to the same variable being used in the +// operation +func checkAtomicAddAssignment(pass *analysis.Pass, left ast.Expr, call *ast.CallExpr) { + if len(call.Args) != 2 { + return + } + arg := call.Args[0] + broken := false + + gofmt := func(e ast.Expr) string { return analysisutil.Format(pass.Fset, e) } + + if uarg, ok := arg.(*ast.UnaryExpr); ok && uarg.Op == token.AND { + broken = gofmt(left) == gofmt(uarg.X) + } else if star, ok := left.(*ast.StarExpr); ok { + broken = gofmt(star.X) == gofmt(arg) + } + + if broken { + pass.Reportf(left.Pos(), "direct assignment to atomic value") + } +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/bools/bools.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/bools/bools.go new file mode 100644 index 0000000000000..0e6f2695f3dc7 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/bools/bools.go @@ -0,0 +1,214 @@ +// Copyright 2014 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. + +// Package bools defines an Analyzer that detects common mistakes +// involving boolean operators. +package bools + +import ( + "go/ast" + "go/token" + "go/types" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" + "golang.org/x/tools/go/ast/inspector" +) + +var Analyzer = &analysis.Analyzer{ + Name: "bools", + Doc: "check for common mistakes involving boolean operators", + Requires: []*analysis.Analyzer{inspect.Analyzer}, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.BinaryExpr)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + e := n.(*ast.BinaryExpr) + + var op boolOp + switch e.Op { + case token.LOR: + op = or + case token.LAND: + op = and + default: + return + } + + // TODO(adonovan): this reports n(n-1)/2 errors for an + // expression e||...||e of depth n. Fix. + // See https://github.com/golang/go/issues/28086. + comm := op.commutativeSets(pass.TypesInfo, e) + for _, exprs := range comm { + op.checkRedundant(pass, exprs) + op.checkSuspect(pass, exprs) + } + }) + return nil, nil +} + +type boolOp struct { + name string + tok token.Token // token corresponding to this operator + badEq token.Token // token corresponding to the equality test that should not be used with this operator +} + +var ( + or = boolOp{"or", token.LOR, token.NEQ} + and = boolOp{"and", token.LAND, token.EQL} +) + +// commutativeSets returns all side effect free sets of +// expressions in e that are connected by op. +// For example, given 'a || b || f() || c || d' with the or op, +// commutativeSets returns {{b, a}, {d, c}}. +func (op boolOp) commutativeSets(info *types.Info, e *ast.BinaryExpr) [][]ast.Expr { + exprs := op.split(e) + + // Partition the slice of expressions into commutative sets. + i := 0 + var sets [][]ast.Expr + for j := 0; j <= len(exprs); j++ { + if j == len(exprs) || hasSideEffects(info, exprs[j]) { + if i < j { + sets = append(sets, exprs[i:j]) + } + i = j + 1 + } + } + + return sets +} + +// checkRedundant checks for expressions of the form +// e && e +// e || e +// Exprs must contain only side effect free expressions. +func (op boolOp) checkRedundant(pass *analysis.Pass, exprs []ast.Expr) { + seen := make(map[string]bool) + for _, e := range exprs { + efmt := analysisutil.Format(pass.Fset, e) + if seen[efmt] { + pass.Reportf(e.Pos(), "redundant %s: %s %s %s", op.name, efmt, op.tok, efmt) + } else { + seen[efmt] = true + } + } +} + +// checkSuspect checks for expressions of the form +// x != c1 || x != c2 +// x == c1 && x == c2 +// where c1 and c2 are constant expressions. +// If c1 and c2 are the same then it's redundant; +// if c1 and c2 are different then it's always true or always false. +// Exprs must contain only side effect free expressions. +func (op boolOp) checkSuspect(pass *analysis.Pass, exprs []ast.Expr) { + // seen maps from expressions 'x' to equality expressions 'x != c'. + seen := make(map[string]string) + + for _, e := range exprs { + bin, ok := e.(*ast.BinaryExpr) + if !ok || bin.Op != op.badEq { + continue + } + + // In order to avoid false positives, restrict to cases + // in which one of the operands is constant. We're then + // interested in the other operand. + // In the rare case in which both operands are constant + // (e.g. runtime.GOOS and "windows"), we'll only catch + // mistakes if the LHS is repeated, which is how most + // code is written. + var x ast.Expr + switch { + case pass.TypesInfo.Types[bin.Y].Value != nil: + x = bin.X + case pass.TypesInfo.Types[bin.X].Value != nil: + x = bin.Y + default: + continue + } + + // e is of the form 'x != c' or 'x == c'. + xfmt := analysisutil.Format(pass.Fset, x) + efmt := analysisutil.Format(pass.Fset, e) + if prev, found := seen[xfmt]; found { + // checkRedundant handles the case in which efmt == prev. + if efmt != prev { + pass.Reportf(e.Pos(), "suspect %s: %s %s %s", op.name, efmt, op.tok, prev) + } + } else { + seen[xfmt] = efmt + } + } +} + +// hasSideEffects reports whether evaluation of e has side effects. +func hasSideEffects(info *types.Info, e ast.Expr) bool { + safe := true + ast.Inspect(e, func(node ast.Node) bool { + switch n := node.(type) { + case *ast.CallExpr: + typVal := info.Types[n.Fun] + switch { + case typVal.IsType(): + // Type conversion, which is safe. + case typVal.IsBuiltin(): + // Builtin func, conservatively assumed to not + // be safe for now. + safe = false + return false + default: + // A non-builtin func or method call. + // Conservatively assume that all of them have + // side effects for now. + safe = false + return false + } + case *ast.UnaryExpr: + if n.Op == token.ARROW { + safe = false + return false + } + } + return true + }) + return !safe +} + +// split returns a slice of all subexpressions in e that are connected by op. +// For example, given 'a || (b || c) || d' with the or op, +// split returns []{d, c, b, a}. +func (op boolOp) split(e ast.Expr) (exprs []ast.Expr) { + for { + e = unparen(e) + if b, ok := e.(*ast.BinaryExpr); ok && b.Op == op.tok { + exprs = append(exprs, op.split(b.Y)...) + e = b.X + } else { + exprs = append(exprs, e) + break + } + } + return +} + +// unparen returns e with any enclosing parentheses stripped. +func unparen(e ast.Expr) ast.Expr { + for { + p, ok := e.(*ast.ParenExpr) + if !ok { + return e + } + e = p.X + } +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/buildtag/buildtag.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/buildtag/buildtag.go new file mode 100644 index 0000000000000..5a441e609b629 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/buildtag/buildtag.go @@ -0,0 +1,159 @@ +// Copyright 2013 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. + +// Package buildtag defines an Analyzer that checks build tags. +package buildtag + +import ( + "bytes" + "fmt" + "go/ast" + "strings" + "unicode" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" +) + +var Analyzer = &analysis.Analyzer{ + Name: "buildtag", + Doc: "check that +build tags are well-formed and correctly located", + Run: runBuildTag, +} + +func runBuildTag(pass *analysis.Pass) (interface{}, error) { + for _, f := range pass.Files { + checkGoFile(pass, f) + } + for _, name := range pass.OtherFiles { + if err := checkOtherFile(pass, name); err != nil { + return nil, err + } + } + return nil, nil +} + +func checkGoFile(pass *analysis.Pass, f *ast.File) { + pastCutoff := false + for _, group := range f.Comments { + // A +build comment is ignored after or adjoining the package declaration. + if group.End()+1 >= f.Package { + pastCutoff = true + } + + // "+build" is ignored within or after a /*...*/ comment. + if !strings.HasPrefix(group.List[0].Text, "//") { + pastCutoff = true + continue + } + + // Check each line of a //-comment. + for _, c := range group.List { + if !strings.Contains(c.Text, "+build") { + continue + } + if err := checkLine(c.Text, pastCutoff); err != nil { + pass.Reportf(c.Pos(), "%s", err) + } + } + } +} + +func checkOtherFile(pass *analysis.Pass, filename string) error { + content, tf, err := analysisutil.ReadFile(pass.Fset, filename) + if err != nil { + return err + } + + // We must look at the raw lines, as build tags may appear in non-Go + // files such as assembly files. + lines := bytes.SplitAfter(content, nl) + + // Determine cutpoint where +build comments are no longer valid. + // They are valid in leading // comments in the file followed by + // a blank line. + // + // This must be done as a separate pass because of the + // requirement that the comment be followed by a blank line. + var cutoff int + for i, line := range lines { + line = bytes.TrimSpace(line) + if !bytes.HasPrefix(line, slashSlash) { + if len(line) > 0 { + break + } + cutoff = i + } + } + + for i, line := range lines { + line = bytes.TrimSpace(line) + if !bytes.HasPrefix(line, slashSlash) { + continue + } + if !bytes.Contains(line, []byte("+build")) { + continue + } + if err := checkLine(string(line), i >= cutoff); err != nil { + pass.Reportf(analysisutil.LineStart(tf, i+1), "%s", err) + continue + } + } + return nil +} + +// checkLine checks a line that starts with "//" and contains "+build". +func checkLine(line string, pastCutoff bool) error { + line = strings.TrimPrefix(line, "//") + line = strings.TrimSpace(line) + + if strings.HasPrefix(line, "+build") { + fields := strings.Fields(line) + if fields[0] != "+build" { + // Comment is something like +buildasdf not +build. + return fmt.Errorf("possible malformed +build comment") + } + if pastCutoff { + return fmt.Errorf("+build comment must appear before package clause and be followed by a blank line") + } + if err := checkArguments(fields); err != nil { + return err + } + } else { + // Comment with +build but not at beginning. + if !pastCutoff { + return fmt.Errorf("possible malformed +build comment") + } + } + return nil +} + +func checkArguments(fields []string) error { + // The original version of this checker in vet could examine + // files with malformed build tags that would cause the file to + // be always ignored by "go build". However, drivers for the new + // analysis API will analyze only the files selected to form a + // package, so these checks will never fire. + // TODO(adonovan): rethink this. + + for _, arg := range fields[1:] { + for _, elem := range strings.Split(arg, ",") { + if strings.HasPrefix(elem, "!!") { + return fmt.Errorf("invalid double negative in build constraint: %s", arg) + } + elem = strings.TrimPrefix(elem, "!") + for _, c := range elem { + if !unicode.IsLetter(c) && !unicode.IsDigit(c) && c != '_' && c != '.' { + return fmt.Errorf("invalid non-alphanumeric build constraint: %s", arg) + } + } + } + } + return nil +} + +var ( + nl = []byte("\n") + slashSlash = []byte("//") +) diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/cgocall/cgocall.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/cgocall/cgocall.go new file mode 100644 index 0000000000000..7eb24a4a91e61 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/cgocall/cgocall.go @@ -0,0 +1,226 @@ +// Copyright 2015 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. + +// Package cgocall defines an Analyzer that detects some violations of +// the cgo pointer passing rules. +package cgocall + +import ( + "fmt" + "go/ast" + "go/token" + "go/types" + "log" + "strings" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `detect some violations of the cgo pointer passing rules + +Check for invalid cgo pointer passing. +This looks for code that uses cgo to call C code passing values +whose types are almost always invalid according to the cgo pointer +sharing rules. +Specifically, it warns about attempts to pass a Go chan, map, func, +or slice to C, either directly, or via a pointer, array, or struct.` + +var Analyzer = &analysis.Analyzer{ + Name: "cgocall", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + RunDespiteErrors: true, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.CallExpr)(nil), + } + inspect.WithStack(nodeFilter, func(n ast.Node, push bool, stack []ast.Node) bool { + if !push { + return true + } + call, name := findCall(pass.Fset, stack) + if call == nil { + return true // not a call we need to check + } + + // A call to C.CBytes passes a pointer but is always safe. + if name == "CBytes" { + return true + } + + if false { + fmt.Printf("%s: inner call to C.%s\n", pass.Fset.Position(n.Pos()), name) + fmt.Printf("%s: outer call to C.%s\n", pass.Fset.Position(call.Lparen), name) + } + + for _, arg := range call.Args { + if !typeOKForCgoCall(cgoBaseType(pass.TypesInfo, arg), make(map[types.Type]bool)) { + pass.Reportf(arg.Pos(), "possibly passing Go type with embedded pointer to C") + break + } + + // Check for passing the address of a bad type. + if conv, ok := arg.(*ast.CallExpr); ok && len(conv.Args) == 1 && + isUnsafePointer(pass.TypesInfo, conv.Fun) { + arg = conv.Args[0] + } + if u, ok := arg.(*ast.UnaryExpr); ok && u.Op == token.AND { + if !typeOKForCgoCall(cgoBaseType(pass.TypesInfo, u.X), make(map[types.Type]bool)) { + pass.Reportf(arg.Pos(), "possibly passing Go type with embedded pointer to C") + break + } + } + } + return true + }) + return nil, nil +} + +// findCall returns the CallExpr that we need to check, which may not be +// the same as the one we're currently visiting, due to code generation. +// It also returns the name of the function, such as "f" for C.f(...). +// +// This checker was initially written in vet to inpect unprocessed cgo +// source files using partial type information. However, Analyzers in +// the new analysis API are presented with the type-checked, processed +// Go ASTs resulting from cgo processing files, so we must choose +// between: +// +// a) locating the cgo file (e.g. from //line directives) +// and working with that, or +// b) working with the file generated by cgo. +// +// We cannot use (a) because it does not provide type information, which +// the analyzer needs, and it is infeasible for the analyzer to run the +// type checker on this file. Thus we choose (b), which is fragile, +// because the checker may need to change each time the cgo processor +// changes. +// +// Consider a cgo source file containing this header: +// +// /* void f(void *x, *y); */ +// import "C" +// +// The cgo tool expands a call such as: +// +// C.f(x, y) +// +// to this: +// +// 1 func(param0, param1 unsafe.Pointer) { +// 2 ... various checks on params ... +// 3 (_Cfunc_f)(param0, param1) +// 4 }(x, y) +// +// We first locate the _Cfunc_f call on line 3, then +// walk up the stack of enclosing nodes until we find +// the call on line 4. +// +func findCall(fset *token.FileSet, stack []ast.Node) (*ast.CallExpr, string) { + last := len(stack) - 1 + call := stack[last].(*ast.CallExpr) + if id, ok := analysisutil.Unparen(call.Fun).(*ast.Ident); ok { + if name := strings.TrimPrefix(id.Name, "_Cfunc_"); name != id.Name { + // Find the outer call with the arguments (x, y) we want to check. + for i := last - 1; i >= 0; i-- { + if outer, ok := stack[i].(*ast.CallExpr); ok { + return outer, name + } + } + // This shouldn't happen. + // Perhaps the code generator has changed? + log.Printf("%s: can't find outer call for C.%s(...)", + fset.Position(call.Lparen), name) + } + } + return nil, "" +} + +// cgoBaseType tries to look through type conversions involving +// unsafe.Pointer to find the real type. It converts: +// unsafe.Pointer(x) => x +// *(*unsafe.Pointer)(unsafe.Pointer(&x)) => x +func cgoBaseType(info *types.Info, arg ast.Expr) types.Type { + switch arg := arg.(type) { + case *ast.CallExpr: + if len(arg.Args) == 1 && isUnsafePointer(info, arg.Fun) { + return cgoBaseType(info, arg.Args[0]) + } + case *ast.StarExpr: + call, ok := arg.X.(*ast.CallExpr) + if !ok || len(call.Args) != 1 { + break + } + // Here arg is *f(v). + t := info.Types[call.Fun].Type + if t == nil { + break + } + ptr, ok := t.Underlying().(*types.Pointer) + if !ok { + break + } + // Here arg is *(*p)(v) + elem, ok := ptr.Elem().Underlying().(*types.Basic) + if !ok || elem.Kind() != types.UnsafePointer { + break + } + // Here arg is *(*unsafe.Pointer)(v) + call, ok = call.Args[0].(*ast.CallExpr) + if !ok || len(call.Args) != 1 { + break + } + // Here arg is *(*unsafe.Pointer)(f(v)) + if !isUnsafePointer(info, call.Fun) { + break + } + // Here arg is *(*unsafe.Pointer)(unsafe.Pointer(v)) + u, ok := call.Args[0].(*ast.UnaryExpr) + if !ok || u.Op != token.AND { + break + } + // Here arg is *(*unsafe.Pointer)(unsafe.Pointer(&v)) + return cgoBaseType(info, u.X) + } + + return info.Types[arg].Type +} + +// typeOKForCgoCall reports whether the type of arg is OK to pass to a +// C function using cgo. This is not true for Go types with embedded +// pointers. m is used to avoid infinite recursion on recursive types. +func typeOKForCgoCall(t types.Type, m map[types.Type]bool) bool { + if t == nil || m[t] { + return true + } + m[t] = true + switch t := t.Underlying().(type) { + case *types.Chan, *types.Map, *types.Signature, *types.Slice: + return false + case *types.Pointer: + return typeOKForCgoCall(t.Elem(), m) + case *types.Array: + return typeOKForCgoCall(t.Elem(), m) + case *types.Struct: + for i := 0; i < t.NumFields(); i++ { + if !typeOKForCgoCall(t.Field(i).Type(), m) { + return false + } + } + } + return true +} + +func isUnsafePointer(info *types.Info, e ast.Expr) bool { + t := info.Types[e].Type + return t != nil && t.Underlying() == types.Typ[types.UnsafePointer] +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/composite.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/composite.go new file mode 100644 index 0000000000000..b7cfe8a95d365 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/composite.go @@ -0,0 +1,108 @@ +// Copyright 2012 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. + +// Package composite defines an Analyzer that checks for unkeyed +// composite literals. +package composite + +import ( + "go/ast" + "go/types" + "strings" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `checked for unkeyed composite literals + +This analyzer reports a diagnostic for composite literals of struct +types imported from another package that do not use the field-keyed +syntax. Such literals are fragile because the addition of a new field +(even if unexported) to the struct will cause compilation to fail.` + +var Analyzer = &analysis.Analyzer{ + Name: "composites", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + RunDespiteErrors: true, + Run: run, +} + +var whitelist = true + +func init() { + Analyzer.Flags.BoolVar(&whitelist, "whitelist", whitelist, "use composite white list; for testing only") +} + +// runUnkeyedLiteral checks if a composite literal is a struct literal with +// unkeyed fields. +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.CompositeLit)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + cl := n.(*ast.CompositeLit) + + typ := pass.TypesInfo.Types[cl].Type + if typ == nil { + // cannot determine composite literals' type, skip it + return + } + typeName := typ.String() + if whitelist && unkeyedLiteral[typeName] { + // skip whitelisted types + return + } + under := typ.Underlying() + for { + ptr, ok := under.(*types.Pointer) + if !ok { + break + } + under = ptr.Elem().Underlying() + } + if _, ok := under.(*types.Struct); !ok { + // skip non-struct composite literals + return + } + if isLocalType(pass, typ) { + // allow unkeyed locally defined composite literal + return + } + + // check if the CompositeLit contains an unkeyed field + allKeyValue := true + for _, e := range cl.Elts { + if _, ok := e.(*ast.KeyValueExpr); !ok { + allKeyValue = false + break + } + } + if allKeyValue { + // all the composite literal fields are keyed + return + } + + pass.Reportf(cl.Pos(), "%s composite literal uses unkeyed fields", typeName) + }) + return nil, nil +} + +func isLocalType(pass *analysis.Pass, typ types.Type) bool { + switch x := typ.(type) { + case *types.Struct: + // struct literals are local types + return true + case *types.Pointer: + return isLocalType(pass, x.Elem()) + case *types.Named: + // names in package foo are local to foo_test too + return strings.TrimSuffix(x.Obj().Pkg().Path(), "_test") == strings.TrimSuffix(pass.Pkg.Path(), "_test") + } + return false +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/whitelist.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/whitelist.go new file mode 100644 index 0000000000000..ab609f279bcb1 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/composite/whitelist.go @@ -0,0 +1,33 @@ +// Copyright 2013 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. + +package composite + +// unkeyedLiteral is a white list of types in the standard packages +// that are used with unkeyed literals we deem to be acceptable. +var unkeyedLiteral = map[string]bool{ + // These image and image/color struct types are frozen. We will never add fields to them. + "image/color.Alpha16": true, + "image/color.Alpha": true, + "image/color.CMYK": true, + "image/color.Gray16": true, + "image/color.Gray": true, + "image/color.NRGBA64": true, + "image/color.NRGBA": true, + "image/color.NYCbCrA": true, + "image/color.RGBA64": true, + "image/color.RGBA": true, + "image/color.YCbCr": true, + "image.Point": true, + "image.Rectangle": true, + "image.Uniform": true, + + "unicode.Range16": true, + + // These three structs are used in generated test main files, + // but the generator can be trusted. + "testing.InternalBenchmark": true, + "testing.InternalExample": true, + "testing.InternalTest": true, +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/copylock/copylock.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/copylock/copylock.go new file mode 100644 index 0000000000000..067aed57df30c --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/copylock/copylock.go @@ -0,0 +1,300 @@ +// Copyright 2013 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. + +// Package copylock defines an Analyzer that checks for locks +// erroneously passed by value. +package copylock + +import ( + "bytes" + "fmt" + "go/ast" + "go/token" + "go/types" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `check for locks erroneously passed by value + +Inadvertently copying a value containing a lock, such as sync.Mutex or +sync.WaitGroup, may cause both copies to malfunction. Generally such +values should be referred to through a pointer.` + +var Analyzer = &analysis.Analyzer{ + Name: "copylocks", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + RunDespiteErrors: true, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.AssignStmt)(nil), + (*ast.CallExpr)(nil), + (*ast.CompositeLit)(nil), + (*ast.FuncDecl)(nil), + (*ast.FuncLit)(nil), + (*ast.GenDecl)(nil), + (*ast.RangeStmt)(nil), + (*ast.ReturnStmt)(nil), + } + inspect.Preorder(nodeFilter, func(node ast.Node) { + switch node := node.(type) { + case *ast.RangeStmt: + checkCopyLocksRange(pass, node) + case *ast.FuncDecl: + checkCopyLocksFunc(pass, node.Name.Name, node.Recv, node.Type) + case *ast.FuncLit: + checkCopyLocksFunc(pass, "func", nil, node.Type) + case *ast.CallExpr: + checkCopyLocksCallExpr(pass, node) + case *ast.AssignStmt: + checkCopyLocksAssign(pass, node) + case *ast.GenDecl: + checkCopyLocksGenDecl(pass, node) + case *ast.CompositeLit: + checkCopyLocksCompositeLit(pass, node) + case *ast.ReturnStmt: + checkCopyLocksReturnStmt(pass, node) + } + }) + return nil, nil +} + +// checkCopyLocksAssign checks whether an assignment +// copies a lock. +func checkCopyLocksAssign(pass *analysis.Pass, as *ast.AssignStmt) { + for i, x := range as.Rhs { + if path := lockPathRhs(pass, x); path != nil { + pass.Reportf(x.Pos(), "assignment copies lock value to %v: %v", analysisutil.Format(pass.Fset, as.Lhs[i]), path) + } + } +} + +// checkCopyLocksGenDecl checks whether lock is copied +// in variable declaration. +func checkCopyLocksGenDecl(pass *analysis.Pass, gd *ast.GenDecl) { + if gd.Tok != token.VAR { + return + } + for _, spec := range gd.Specs { + valueSpec := spec.(*ast.ValueSpec) + for i, x := range valueSpec.Values { + if path := lockPathRhs(pass, x); path != nil { + pass.Reportf(x.Pos(), "variable declaration copies lock value to %v: %v", valueSpec.Names[i].Name, path) + } + } + } +} + +// checkCopyLocksCompositeLit detects lock copy inside a composite literal +func checkCopyLocksCompositeLit(pass *analysis.Pass, cl *ast.CompositeLit) { + for _, x := range cl.Elts { + if node, ok := x.(*ast.KeyValueExpr); ok { + x = node.Value + } + if path := lockPathRhs(pass, x); path != nil { + pass.Reportf(x.Pos(), "literal copies lock value from %v: %v", analysisutil.Format(pass.Fset, x), path) + } + } +} + +// checkCopyLocksReturnStmt detects lock copy in return statement +func checkCopyLocksReturnStmt(pass *analysis.Pass, rs *ast.ReturnStmt) { + for _, x := range rs.Results { + if path := lockPathRhs(pass, x); path != nil { + pass.Reportf(x.Pos(), "return copies lock value: %v", path) + } + } +} + +// checkCopyLocksCallExpr detects lock copy in the arguments to a function call +func checkCopyLocksCallExpr(pass *analysis.Pass, ce *ast.CallExpr) { + var id *ast.Ident + switch fun := ce.Fun.(type) { + case *ast.Ident: + id = fun + case *ast.SelectorExpr: + id = fun.Sel + } + if fun, ok := pass.TypesInfo.Uses[id].(*types.Builtin); ok { + switch fun.Name() { + case "new", "len", "cap", "Sizeof": + return + } + } + for _, x := range ce.Args { + if path := lockPathRhs(pass, x); path != nil { + pass.Reportf(x.Pos(), "call of %s copies lock value: %v", analysisutil.Format(pass.Fset, ce.Fun), path) + } + } +} + +// checkCopyLocksFunc checks whether a function might +// inadvertently copy a lock, by checking whether +// its receiver, parameters, or return values +// are locks. +func checkCopyLocksFunc(pass *analysis.Pass, name string, recv *ast.FieldList, typ *ast.FuncType) { + if recv != nil && len(recv.List) > 0 { + expr := recv.List[0].Type + if path := lockPath(pass.Pkg, pass.TypesInfo.Types[expr].Type); path != nil { + pass.Reportf(expr.Pos(), "%s passes lock by value: %v", name, path) + } + } + + if typ.Params != nil { + for _, field := range typ.Params.List { + expr := field.Type + if path := lockPath(pass.Pkg, pass.TypesInfo.Types[expr].Type); path != nil { + pass.Reportf(expr.Pos(), "%s passes lock by value: %v", name, path) + } + } + } + + // Don't check typ.Results. If T has a Lock field it's OK to write + // return T{} + // because that is returning the zero value. Leave result checking + // to the return statement. +} + +// checkCopyLocksRange checks whether a range statement +// might inadvertently copy a lock by checking whether +// any of the range variables are locks. +func checkCopyLocksRange(pass *analysis.Pass, r *ast.RangeStmt) { + checkCopyLocksRangeVar(pass, r.Tok, r.Key) + checkCopyLocksRangeVar(pass, r.Tok, r.Value) +} + +func checkCopyLocksRangeVar(pass *analysis.Pass, rtok token.Token, e ast.Expr) { + if e == nil { + return + } + id, isId := e.(*ast.Ident) + if isId && id.Name == "_" { + return + } + + var typ types.Type + if rtok == token.DEFINE { + if !isId { + return + } + obj := pass.TypesInfo.Defs[id] + if obj == nil { + return + } + typ = obj.Type() + } else { + typ = pass.TypesInfo.Types[e].Type + } + + if typ == nil { + return + } + if path := lockPath(pass.Pkg, typ); path != nil { + pass.Reportf(e.Pos(), "range var %s copies lock: %v", analysisutil.Format(pass.Fset, e), path) + } +} + +type typePath []types.Type + +// String pretty-prints a typePath. +func (path typePath) String() string { + n := len(path) + var buf bytes.Buffer + for i := range path { + if i > 0 { + fmt.Fprint(&buf, " contains ") + } + // The human-readable path is in reverse order, outermost to innermost. + fmt.Fprint(&buf, path[n-i-1].String()) + } + return buf.String() +} + +func lockPathRhs(pass *analysis.Pass, x ast.Expr) typePath { + if _, ok := x.(*ast.CompositeLit); ok { + return nil + } + if _, ok := x.(*ast.CallExpr); ok { + // A call may return a zero value. + return nil + } + if star, ok := x.(*ast.StarExpr); ok { + if _, ok := star.X.(*ast.CallExpr); ok { + // A call may return a pointer to a zero value. + return nil + } + } + return lockPath(pass.Pkg, pass.TypesInfo.Types[x].Type) +} + +// lockPath returns a typePath describing the location of a lock value +// contained in typ. If there is no contained lock, it returns nil. +func lockPath(tpkg *types.Package, typ types.Type) typePath { + if typ == nil { + return nil + } + + for { + atyp, ok := typ.Underlying().(*types.Array) + if !ok { + break + } + typ = atyp.Elem() + } + + // We're only interested in the case in which the underlying + // type is a struct. (Interfaces and pointers are safe to copy.) + styp, ok := typ.Underlying().(*types.Struct) + if !ok { + return nil + } + + // We're looking for cases in which a pointer to this type + // is a sync.Locker, but a value is not. This differentiates + // embedded interfaces from embedded values. + if types.Implements(types.NewPointer(typ), lockerType) && !types.Implements(typ, lockerType) { + return []types.Type{typ} + } + + // In go1.10, sync.noCopy did not implement Locker. + // (The Unlock method was added only in CL 121876.) + // TODO(adonovan): remove workaround when we drop go1.10. + if named, ok := typ.(*types.Named); ok && + named.Obj().Name() == "noCopy" && + named.Obj().Pkg().Path() == "sync" { + return []types.Type{typ} + } + + nfields := styp.NumFields() + for i := 0; i < nfields; i++ { + ftyp := styp.Field(i).Type() + subpath := lockPath(tpkg, ftyp) + if subpath != nil { + return append(subpath, typ) + } + } + + return nil +} + +var lockerType *types.Interface + +// Construct a sync.Locker interface type. +func init() { + nullary := types.NewSignature(nil, nil, nil, false) // func() + methods := []*types.Func{ + types.NewFunc(token.NoPos, nil, "Lock", nullary), + types.NewFunc(token.NoPos, nil, "Unlock", nullary), + } + lockerType = types.NewInterface(methods, nil).Complete() +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/ctrlflow/ctrlflow.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/ctrlflow/ctrlflow.go new file mode 100644 index 0000000000000..75655c5bad482 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/ctrlflow/ctrlflow.go @@ -0,0 +1,225 @@ +// Copyright 2018 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. + +// Package ctrlflow is an analysis that provides a syntactic +// control-flow graph (CFG) for the body of a function. +// It records whether a function cannot return. +// By itself, it does not report any diagnostics. +package ctrlflow + +import ( + "go/ast" + "go/types" + "log" + "reflect" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/ast/inspector" + "golang.org/x/tools/go/cfg" + "golang.org/x/tools/go/types/typeutil" +) + +var Analyzer = &analysis.Analyzer{ + Name: "ctrlflow", + Doc: "build a control-flow graph", + Run: run, + ResultType: reflect.TypeOf(new(CFGs)), + FactTypes: []analysis.Fact{new(noReturn)}, + Requires: []*analysis.Analyzer{inspect.Analyzer}, +} + +// noReturn is a fact indicating that a function does not return. +type noReturn struct{} + +func (*noReturn) AFact() {} + +func (*noReturn) String() string { return "noReturn" } + +// A CFGs holds the control-flow graphs +// for all the functions of the current package. +type CFGs struct { + defs map[*ast.Ident]types.Object // from Pass.TypesInfo.Defs + funcDecls map[*types.Func]*declInfo + funcLits map[*ast.FuncLit]*litInfo + pass *analysis.Pass // transient; nil after construction +} + +// CFGs has two maps: funcDecls for named functions and funcLits for +// unnamed ones. Unlike funcLits, the funcDecls map is not keyed by its +// syntax node, *ast.FuncDecl, because callMayReturn needs to do a +// look-up by *types.Func, and you can get from an *ast.FuncDecl to a +// *types.Func but not the other way. + +type declInfo struct { + decl *ast.FuncDecl + cfg *cfg.CFG // iff decl.Body != nil + started bool // to break cycles + noReturn bool +} + +type litInfo struct { + cfg *cfg.CFG + noReturn bool +} + +// FuncDecl returns the control-flow graph for a named function. +// It returns nil if decl.Body==nil. +func (c *CFGs) FuncDecl(decl *ast.FuncDecl) *cfg.CFG { + if decl.Body == nil { + return nil + } + fn := c.defs[decl.Name].(*types.Func) + return c.funcDecls[fn].cfg +} + +// FuncLit returns the control-flow graph for a literal function. +func (c *CFGs) FuncLit(lit *ast.FuncLit) *cfg.CFG { + return c.funcLits[lit].cfg +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + // Because CFG construction consumes and produces noReturn + // facts, CFGs for exported FuncDecls must be built before 'run' + // returns; we cannot construct them lazily. + // (We could build CFGs for FuncLits lazily, + // but the benefit is marginal.) + + // Pass 1. Map types.Funcs to ast.FuncDecls in this package. + funcDecls := make(map[*types.Func]*declInfo) // functions and methods + funcLits := make(map[*ast.FuncLit]*litInfo) + + var decls []*types.Func // keys(funcDecls), in order + var lits []*ast.FuncLit // keys(funcLits), in order + + nodeFilter := []ast.Node{ + (*ast.FuncDecl)(nil), + (*ast.FuncLit)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + switch n := n.(type) { + case *ast.FuncDecl: + fn := pass.TypesInfo.Defs[n.Name].(*types.Func) + funcDecls[fn] = &declInfo{decl: n} + decls = append(decls, fn) + + case *ast.FuncLit: + funcLits[n] = new(litInfo) + lits = append(lits, n) + } + }) + + c := &CFGs{ + defs: pass.TypesInfo.Defs, + funcDecls: funcDecls, + funcLits: funcLits, + pass: pass, + } + + // Pass 2. Build CFGs. + + // Build CFGs for named functions. + // Cycles in the static call graph are broken + // arbitrarily but deterministically. + // We create noReturn facts as discovered. + for _, fn := range decls { + c.buildDecl(fn, funcDecls[fn]) + } + + // Build CFGs for literal functions. + // These aren't relevant to facts (since they aren't named) + // but are required for the CFGs.FuncLit API. + for _, lit := range lits { + li := funcLits[lit] + if li.cfg == nil { + li.cfg = cfg.New(lit.Body, c.callMayReturn) + if !hasReachableReturn(li.cfg) { + li.noReturn = true + } + } + } + + // All CFGs are now built. + c.pass = nil + + return c, nil +} + +// di.cfg may be nil on return. +func (c *CFGs) buildDecl(fn *types.Func, di *declInfo) { + // buildDecl may call itself recursively for the same function, + // because cfg.New is passed the callMayReturn method, which + // builds the CFG of the callee, leading to recursion. + // The buildDecl call tree thus resembles the static call graph. + // We mark each node when we start working on it to break cycles. + + if !di.started { // break cycle + di.started = true + + if isIntrinsicNoReturn(fn) { + di.noReturn = true + } + if di.decl.Body != nil { + di.cfg = cfg.New(di.decl.Body, c.callMayReturn) + if !hasReachableReturn(di.cfg) { + di.noReturn = true + } + } + if di.noReturn { + c.pass.ExportObjectFact(fn, new(noReturn)) + } + + // debugging + if false { + log.Printf("CFG for %s:\n%s (noreturn=%t)\n", fn, di.cfg.Format(c.pass.Fset), di.noReturn) + } + } +} + +// callMayReturn reports whether the called function may return. +// It is passed to the CFG builder. +func (c *CFGs) callMayReturn(call *ast.CallExpr) (r bool) { + if id, ok := call.Fun.(*ast.Ident); ok && c.pass.TypesInfo.Uses[id] == panicBuiltin { + return false // panic never returns + } + + // Is this a static call? + fn := typeutil.StaticCallee(c.pass.TypesInfo, call) + if fn == nil { + return true // callee not statically known; be conservative + } + + // Function or method declared in this package? + if di, ok := c.funcDecls[fn]; ok { + c.buildDecl(fn, di) + return !di.noReturn + } + + // Not declared in this package. + // Is there a fact from another package? + return !c.pass.ImportObjectFact(fn, new(noReturn)) +} + +var panicBuiltin = types.Universe.Lookup("panic").(*types.Builtin) + +func hasReachableReturn(g *cfg.CFG) bool { + for _, b := range g.Blocks { + if b.Live && b.Return() != nil { + return true + } + } + return false +} + +// isIntrinsicNoReturn reports whether a function intrinsically never +// returns because it stops execution of the calling thread. +// It is the base case in the recursion. +func isIntrinsicNoReturn(fn *types.Func) bool { + // Add functions here as the need arises, but don't allocate memory. + path, name := fn.Pkg().Path(), fn.Name() + return path == "syscall" && (name == "Exit" || name == "ExitProcess" || name == "ExitThread") || + path == "runtime" && name == "Goexit" +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/httpresponse/httpresponse.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/httpresponse/httpresponse.go new file mode 100644 index 0000000000000..0cf21b8cd1e8b --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/httpresponse/httpresponse.go @@ -0,0 +1,177 @@ +// Copyright 2016 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. + +// Package httpresponse defines an Analyzer that checks for mistakes +// using HTTP responses. +package httpresponse + +import ( + "go/ast" + "go/types" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `check for mistakes using HTTP responses + +A common mistake when using the net/http package is to defer a function +call to close the http.Response Body before checking the error that +determines whether the response is valid: + + resp, err := http.Head(url) + defer resp.Body.Close() + if err != nil { + log.Fatal(err) + } + // (defer statement belongs here) + +This checker helps uncover latent nil dereference bugs by reporting a +diagnostic for such mistakes.` + +var Analyzer = &analysis.Analyzer{ + Name: "httpresponse", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + // Fast path: if the package doesn't import net/http, + // skip the traversal. + if !imports(pass.Pkg, "net/http") { + return nil, nil + } + + nodeFilter := []ast.Node{ + (*ast.CallExpr)(nil), + } + inspect.WithStack(nodeFilter, func(n ast.Node, push bool, stack []ast.Node) bool { + if !push { + return true + } + call := n.(*ast.CallExpr) + if !isHTTPFuncOrMethodOnClient(pass.TypesInfo, call) { + return true // the function call is not related to this check. + } + + // Find the innermost containing block, and get the list + // of statements starting with the one containing call. + stmts := restOfBlock(stack) + if len(stmts) < 2 { + return true // the call to the http function is the last statement of the block. + } + + asg, ok := stmts[0].(*ast.AssignStmt) + if !ok { + return true // the first statement is not assignment. + } + resp := rootIdent(asg.Lhs[0]) + if resp == nil { + return true // could not find the http.Response in the assignment. + } + + def, ok := stmts[1].(*ast.DeferStmt) + if !ok { + return true // the following statement is not a defer. + } + root := rootIdent(def.Call.Fun) + if root == nil { + return true // could not find the receiver of the defer call. + } + + if resp.Obj == root.Obj { + pass.Reportf(root.Pos(), "using %s before checking for errors", resp.Name) + } + return true + }) + return nil, nil +} + +// isHTTPFuncOrMethodOnClient checks whether the given call expression is on +// either a function of the net/http package or a method of http.Client that +// returns (*http.Response, error). +func isHTTPFuncOrMethodOnClient(info *types.Info, expr *ast.CallExpr) bool { + fun, _ := expr.Fun.(*ast.SelectorExpr) + sig, _ := info.Types[fun].Type.(*types.Signature) + if sig == nil { + return false // the call is not of the form x.f() + } + + res := sig.Results() + if res.Len() != 2 { + return false // the function called does not return two values. + } + if ptr, ok := res.At(0).Type().(*types.Pointer); !ok || !isNamedType(ptr.Elem(), "net/http", "Response") { + return false // the first return type is not *http.Response. + } + + errorType := types.Universe.Lookup("error").Type() + if !types.Identical(res.At(1).Type(), errorType) { + return false // the second return type is not error + } + + typ := info.Types[fun.X].Type + if typ == nil { + id, ok := fun.X.(*ast.Ident) + return ok && id.Name == "http" // function in net/http package. + } + + if isNamedType(typ, "net/http", "Client") { + return true // method on http.Client. + } + ptr, ok := typ.(*types.Pointer) + return ok && isNamedType(ptr.Elem(), "net/http", "Client") // method on *http.Client. +} + +// restOfBlock, given a traversal stack, finds the innermost containing +// block and returns the suffix of its statements starting with the +// current node (the last element of stack). +func restOfBlock(stack []ast.Node) []ast.Stmt { + for i := len(stack) - 1; i >= 0; i-- { + if b, ok := stack[i].(*ast.BlockStmt); ok { + for j, v := range b.List { + if v == stack[i+1] { + return b.List[j:] + } + } + break + } + } + return nil +} + +// rootIdent finds the root identifier x in a chain of selections x.y.z, or nil if not found. +func rootIdent(n ast.Node) *ast.Ident { + switch n := n.(type) { + case *ast.SelectorExpr: + return rootIdent(n.X) + case *ast.Ident: + return n + default: + return nil + } +} + +// isNamedType reports whether t is the named type path.name. +func isNamedType(t types.Type, path, name string) bool { + n, ok := t.(*types.Named) + if !ok { + return false + } + obj := n.Obj() + return obj.Name() == name && obj.Pkg() != nil && obj.Pkg().Path() == path +} + +func imports(pkg *types.Package, path string) bool { + for _, imp := range pkg.Imports() { + if imp.Path() == path { + return true + } + } + return false +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/inspect/inspect.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/inspect/inspect.go new file mode 100644 index 0000000000000..bd06549984a2a --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/inspect/inspect.go @@ -0,0 +1,45 @@ +// Copyright 2018 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. + +// Package inspect defines an Analyzer that provides an AST inspector +// (golang.org/x/tools/go/ast/inspect.Inspect) for the syntax trees of a +// package. It is only a building block for other analyzers. +// +// Example of use in another analysis: +// +// import "golang.org/x/tools/go/analysis/passes/inspect" +// +// var Analyzer = &analysis.Analyzer{ +// ... +// Requires: reflect.TypeOf(new(inspect.Analyzer)), +// } +// +// func run(pass *analysis.Pass) (interface{}, error) { +// inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) +// inspect.Preorder(nil, func(n ast.Node) { +// ... +// }) +// return nil +// } +// +package inspect + +import ( + "reflect" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/ast/inspector" +) + +var Analyzer = &analysis.Analyzer{ + Name: "inspect", + Doc: "optimize AST traversal for later passes", + Run: run, + RunDespiteErrors: true, + ResultType: reflect.TypeOf(new(inspector.Inspector)), +} + +func run(pass *analysis.Pass) (interface{}, error) { + return inspector.New(pass.Files), nil +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go new file mode 100644 index 0000000000000..13a458d9d6be7 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/internal/analysisutil/util.go @@ -0,0 +1,106 @@ +// Package analysisutil defines various helper functions +// used by two or more packages beneath go/analysis. +package analysisutil + +import ( + "bytes" + "go/ast" + "go/printer" + "go/token" + "go/types" + "io/ioutil" +) + +// Format returns a string representation of the expression. +func Format(fset *token.FileSet, x ast.Expr) string { + var b bytes.Buffer + printer.Fprint(&b, fset, x) + return b.String() +} + +// HasSideEffects reports whether evaluation of e has side effects. +func HasSideEffects(info *types.Info, e ast.Expr) bool { + safe := true + ast.Inspect(e, func(node ast.Node) bool { + switch n := node.(type) { + case *ast.CallExpr: + typVal := info.Types[n.Fun] + switch { + case typVal.IsType(): + // Type conversion, which is safe. + case typVal.IsBuiltin(): + // Builtin func, conservatively assumed to not + // be safe for now. + safe = false + return false + default: + // A non-builtin func or method call. + // Conservatively assume that all of them have + // side effects for now. + safe = false + return false + } + case *ast.UnaryExpr: + if n.Op == token.ARROW { + safe = false + return false + } + } + return true + }) + return !safe +} + +// Unparen returns e with any enclosing parentheses stripped. +func Unparen(e ast.Expr) ast.Expr { + for { + p, ok := e.(*ast.ParenExpr) + if !ok { + return e + } + e = p.X + } +} + +// ReadFile reads a file and adds it to the FileSet +// so that we can report errors against it using lineStart. +func ReadFile(fset *token.FileSet, filename string) ([]byte, *token.File, error) { + content, err := ioutil.ReadFile(filename) + if err != nil { + return nil, nil, err + } + tf := fset.AddFile(filename, -1, len(content)) + tf.SetLinesForContent(content) + return content, tf, nil +} + +// LineStart returns the position of the start of the specified line +// within file f, or NoPos if there is no line of that number. +func LineStart(f *token.File, line int) token.Pos { + // Use binary search to find the start offset of this line. + // + // TODO(adonovan): eventually replace this function with the + // simpler and more efficient (*go/token.File).LineStart, added + // in go1.12. + + min := 0 // inclusive + max := f.Size() // exclusive + for { + offset := (min + max) / 2 + pos := f.Pos(offset) + posn := f.Position(pos) + if posn.Line == line { + return pos - (token.Pos(posn.Column) - 1) + } + + if min+1 >= max { + return token.NoPos + } + + if posn.Line < line { + min = offset + } else { + max = offset + } + } +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/loopclosure/loopclosure.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/loopclosure/loopclosure.go new file mode 100644 index 0000000000000..da0714069f7b1 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/loopclosure/loopclosure.go @@ -0,0 +1,130 @@ +// Copyright 2012 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. + +// Package loopclosure defines an Analyzer that checks for references to +// enclosing loop variables from within nested functions. +package loopclosure + +import ( + "go/ast" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/ast/inspector" +) + +// TODO(adonovan): also report an error for the following structure, +// which is often used to ensure that deferred calls do not accumulate +// in a loop: +// +// for i, x := range c { +// func() { +// ...reference to i or x... +// }() +// } + +const Doc = `check references to loop variables from within nested functions + +This analyzer checks for references to loop variables from within a +function literal inside the loop body. It checks only instances where +the function literal is called in a defer or go statement that is the +last statement in the loop body, as otherwise we would need whole +program analysis. + +For example: + + for i, v := range s { + go func() { + println(i, v) // not what you might expect + }() + } + +See: https://golang.org/doc/go_faq.html#closures_and_goroutines` + +var Analyzer = &analysis.Analyzer{ + Name: "loopclosure", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.RangeStmt)(nil), + (*ast.ForStmt)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + // Find the variables updated by the loop statement. + var vars []*ast.Ident + addVar := func(expr ast.Expr) { + if id, ok := expr.(*ast.Ident); ok { + vars = append(vars, id) + } + } + var body *ast.BlockStmt + switch n := n.(type) { + case *ast.RangeStmt: + body = n.Body + addVar(n.Key) + addVar(n.Value) + case *ast.ForStmt: + body = n.Body + switch post := n.Post.(type) { + case *ast.AssignStmt: + // e.g. for p = head; p != nil; p = p.next + for _, lhs := range post.Lhs { + addVar(lhs) + } + case *ast.IncDecStmt: + // e.g. for i := 0; i < n; i++ + addVar(post.X) + } + } + if vars == nil { + return + } + + // Inspect a go or defer statement + // if it's the last one in the loop body. + // (We give up if there are following statements, + // because it's hard to prove go isn't followed by wait, + // or defer by return.) + if len(body.List) == 0 { + return + } + var last *ast.CallExpr + switch s := body.List[len(body.List)-1].(type) { + case *ast.GoStmt: + last = s.Call + case *ast.DeferStmt: + last = s.Call + default: + return + } + lit, ok := last.Fun.(*ast.FuncLit) + if !ok { + return + } + ast.Inspect(lit.Body, func(n ast.Node) bool { + id, ok := n.(*ast.Ident) + if !ok || id.Obj == nil { + return true + } + if pass.TypesInfo.Types[id].Type == nil { + // Not referring to a variable (e.g. struct field name) + return true + } + for _, v := range vars { + if v.Obj == id.Obj { + pass.Reportf(id.Pos(), "loop variable %s captured by func literal", + id.Name) + } + } + return true + }) + }) + return nil, nil +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/lostcancel/lostcancel.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/lostcancel/lostcancel.go new file mode 100644 index 0000000000000..fcf9f553a9f0b --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/lostcancel/lostcancel.go @@ -0,0 +1,304 @@ +// Copyright 2016 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. + +// Package lostcancel defines an Analyzer that checks for failure to +// call a context cancelation function. +package lostcancel + +import ( + "fmt" + "go/ast" + "go/types" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/ctrlflow" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/ast/inspector" + "golang.org/x/tools/go/cfg" +) + +const Doc = `check cancel func returned by context.WithCancel is called + +The cancelation function returned by context.WithCancel, WithTimeout, +and WithDeadline must be called or the new context will remain live +until its parent context is cancelled. +(The background context is never cancelled.)` + +var Analyzer = &analysis.Analyzer{ + Name: "lostcancel", + Doc: Doc, + Run: run, + Requires: []*analysis.Analyzer{ + inspect.Analyzer, + ctrlflow.Analyzer, + }, +} + +const debug = false + +var contextPackage = "context" + +// checkLostCancel reports a failure to the call the cancel function +// returned by context.WithCancel, either because the variable was +// assigned to the blank identifier, or because there exists a +// control-flow path from the call to a return statement and that path +// does not "use" the cancel function. Any reference to the variable +// counts as a use, even within a nested function literal. +// +// checkLostCancel analyzes a single named or literal function. +func run(pass *analysis.Pass) (interface{}, error) { + // Fast path: bypass check if file doesn't use context.WithCancel. + if !hasImport(pass.Pkg, contextPackage) { + return nil, nil + } + + // Call runFunc for each Func{Decl,Lit}. + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + nodeTypes := []ast.Node{ + (*ast.FuncLit)(nil), + (*ast.FuncDecl)(nil), + } + inspect.Preorder(nodeTypes, func(n ast.Node) { + runFunc(pass, n) + }) + return nil, nil +} + +func runFunc(pass *analysis.Pass, node ast.Node) { + // Maps each cancel variable to its defining ValueSpec/AssignStmt. + cancelvars := make(map[*types.Var]ast.Node) + + // TODO(adonovan): opt: refactor to make a single pass + // over the AST using inspect.WithStack and node types + // {FuncDecl,FuncLit,CallExpr,SelectorExpr}. + + // Find the set of cancel vars to analyze. + stack := make([]ast.Node, 0, 32) + ast.Inspect(node, func(n ast.Node) bool { + switch n.(type) { + case *ast.FuncLit: + if len(stack) > 0 { + return false // don't stray into nested functions + } + case nil: + stack = stack[:len(stack)-1] // pop + return true + } + stack = append(stack, n) // push + + // Look for [{AssignStmt,ValueSpec} CallExpr SelectorExpr]: + // + // ctx, cancel := context.WithCancel(...) + // ctx, cancel = context.WithCancel(...) + // var ctx, cancel = context.WithCancel(...) + // + if isContextWithCancel(pass.TypesInfo, n) && isCall(stack[len(stack)-2]) { + var id *ast.Ident // id of cancel var + stmt := stack[len(stack)-3] + switch stmt := stmt.(type) { + case *ast.ValueSpec: + if len(stmt.Names) > 1 { + id = stmt.Names[1] + } + case *ast.AssignStmt: + if len(stmt.Lhs) > 1 { + id, _ = stmt.Lhs[1].(*ast.Ident) + } + } + if id != nil { + if id.Name == "_" { + pass.Reportf(id.Pos(), + "the cancel function returned by context.%s should be called, not discarded, to avoid a context leak", + n.(*ast.SelectorExpr).Sel.Name) + } else if v, ok := pass.TypesInfo.Uses[id].(*types.Var); ok { + cancelvars[v] = stmt + } else if v, ok := pass.TypesInfo.Defs[id].(*types.Var); ok { + cancelvars[v] = stmt + } + } + } + + return true + }) + + if len(cancelvars) == 0 { + return // no need to inspect CFG + } + + // Obtain the CFG. + cfgs := pass.ResultOf[ctrlflow.Analyzer].(*ctrlflow.CFGs) + var g *cfg.CFG + var sig *types.Signature + switch node := node.(type) { + case *ast.FuncDecl: + g = cfgs.FuncDecl(node) + sig, _ = pass.TypesInfo.Defs[node.Name].Type().(*types.Signature) + case *ast.FuncLit: + g = cfgs.FuncLit(node) + sig, _ = pass.TypesInfo.Types[node.Type].Type.(*types.Signature) + } + if sig == nil { + return // missing type information + } + + // Print CFG. + if debug { + fmt.Println(g.Format(pass.Fset)) + } + + // Examine the CFG for each variable in turn. + // (It would be more efficient to analyze all cancelvars in a + // single pass over the AST, but seldom is there more than one.) + for v, stmt := range cancelvars { + if ret := lostCancelPath(pass, g, v, stmt, sig); ret != nil { + lineno := pass.Fset.Position(stmt.Pos()).Line + pass.Reportf(stmt.Pos(), "the %s function is not used on all paths (possible context leak)", v.Name()) + pass.Reportf(ret.Pos(), "this return statement may be reached without using the %s var defined on line %d", v.Name(), lineno) + } + } +} + +func isCall(n ast.Node) bool { _, ok := n.(*ast.CallExpr); return ok } + +func hasImport(pkg *types.Package, path string) bool { + for _, imp := range pkg.Imports() { + if imp.Path() == path { + return true + } + } + return false +} + +// isContextWithCancel reports whether n is one of the qualified identifiers +// context.With{Cancel,Timeout,Deadline}. +func isContextWithCancel(info *types.Info, n ast.Node) bool { + if sel, ok := n.(*ast.SelectorExpr); ok { + switch sel.Sel.Name { + case "WithCancel", "WithTimeout", "WithDeadline": + if x, ok := sel.X.(*ast.Ident); ok { + if pkgname, ok := info.Uses[x].(*types.PkgName); ok { + return pkgname.Imported().Path() == contextPackage + } + // Import failed, so we can't check package path. + // Just check the local package name (heuristic). + return x.Name == "context" + } + } + } + return false +} + +// lostCancelPath finds a path through the CFG, from stmt (which defines +// the 'cancel' variable v) to a return statement, that doesn't "use" v. +// If it finds one, it returns the return statement (which may be synthetic). +// sig is the function's type, if known. +func lostCancelPath(pass *analysis.Pass, g *cfg.CFG, v *types.Var, stmt ast.Node, sig *types.Signature) *ast.ReturnStmt { + vIsNamedResult := sig != nil && tupleContains(sig.Results(), v) + + // uses reports whether stmts contain a "use" of variable v. + uses := func(pass *analysis.Pass, v *types.Var, stmts []ast.Node) bool { + found := false + for _, stmt := range stmts { + ast.Inspect(stmt, func(n ast.Node) bool { + switch n := n.(type) { + case *ast.Ident: + if pass.TypesInfo.Uses[n] == v { + found = true + } + case *ast.ReturnStmt: + // A naked return statement counts as a use + // of the named result variables. + if n.Results == nil && vIsNamedResult { + found = true + } + } + return !found + }) + } + return found + } + + // blockUses computes "uses" for each block, caching the result. + memo := make(map[*cfg.Block]bool) + blockUses := func(pass *analysis.Pass, v *types.Var, b *cfg.Block) bool { + res, ok := memo[b] + if !ok { + res = uses(pass, v, b.Nodes) + memo[b] = res + } + return res + } + + // Find the var's defining block in the CFG, + // plus the rest of the statements of that block. + var defblock *cfg.Block + var rest []ast.Node +outer: + for _, b := range g.Blocks { + for i, n := range b.Nodes { + if n == stmt { + defblock = b + rest = b.Nodes[i+1:] + break outer + } + } + } + if defblock == nil { + panic("internal error: can't find defining block for cancel var") + } + + // Is v "used" in the remainder of its defining block? + if uses(pass, v, rest) { + return nil + } + + // Does the defining block return without using v? + if ret := defblock.Return(); ret != nil { + return ret + } + + // Search the CFG depth-first for a path, from defblock to a + // return block, in which v is never "used". + seen := make(map[*cfg.Block]bool) + var search func(blocks []*cfg.Block) *ast.ReturnStmt + search = func(blocks []*cfg.Block) *ast.ReturnStmt { + for _, b := range blocks { + if !seen[b] { + seen[b] = true + + // Prune the search if the block uses v. + if blockUses(pass, v, b) { + continue + } + + // Found path to return statement? + if ret := b.Return(); ret != nil { + if debug { + fmt.Printf("found path to return in block %s\n", b) + } + return ret // found + } + + // Recur + if ret := search(b.Succs); ret != nil { + if debug { + fmt.Printf(" from block %s\n", b) + } + return ret + } + } + } + return nil + } + return search(defblock.Succs) +} + +func tupleContains(tuple *types.Tuple, v *types.Var) bool { + for i := 0; i < tuple.Len(); i++ { + if tuple.At(i) == v { + return true + } + } + return false +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/nilfunc/nilfunc.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/nilfunc/nilfunc.go new file mode 100644 index 0000000000000..9c2d4df20a087 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/nilfunc/nilfunc.go @@ -0,0 +1,74 @@ +// Copyright 2013 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. + +// Package nilfunc defines an Analyzer that checks for useless +// comparisons against nil. +package nilfunc + +import ( + "go/ast" + "go/token" + "go/types" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `check for useless comparisons between functions and nil + +A useless comparison is one like f == nil as opposed to f() == nil.` + +var Analyzer = &analysis.Analyzer{ + Name: "nilfunc", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.BinaryExpr)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + e := n.(*ast.BinaryExpr) + + // Only want == or != comparisons. + if e.Op != token.EQL && e.Op != token.NEQ { + return + } + + // Only want comparisons with a nil identifier on one side. + var e2 ast.Expr + switch { + case pass.TypesInfo.Types[e.X].IsNil(): + e2 = e.Y + case pass.TypesInfo.Types[e.Y].IsNil(): + e2 = e.X + default: + return + } + + // Only want identifiers or selector expressions. + var obj types.Object + switch v := e2.(type) { + case *ast.Ident: + obj = pass.TypesInfo.Uses[v] + case *ast.SelectorExpr: + obj = pass.TypesInfo.Uses[v.Sel] + default: + return + } + + // Only want functions. + if _, ok := obj.(*types.Func); !ok { + return + } + + pass.Reportf(e.Pos(), "comparison of function %v %v nil is always %v", obj.Name(), e.Op, e.Op == token.NEQ) + }) + return nil, nil +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/pkgfact/pkgfact.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/pkgfact/pkgfact.go new file mode 100644 index 0000000000000..e0530867329fb --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/pkgfact/pkgfact.go @@ -0,0 +1,127 @@ +// Copyright 2018 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. + +// The pkgfact package is a demonstration and test of the package fact +// mechanism. +// +// The output of the pkgfact analysis is a set of key/values pairs +// gathered from the analyzed package and its imported dependencies. +// Each key/value pair comes from a top-level constant declaration +// whose name starts and ends with "_". For example: +// +// package p +// +// const _greeting_ = "hello" +// const _audience_ = "world" +// +// the pkgfact analysis output for package p would be: +// +// {"greeting": "hello", "audience": "world"}. +// +// In addition, the analysis reports a diagnostic at each import +// showing which key/value pairs it contributes. +package pkgfact + +import ( + "fmt" + "go/ast" + "go/token" + "go/types" + "reflect" + "sort" + "strings" + + "golang.org/x/tools/go/analysis" +) + +var Analyzer = &analysis.Analyzer{ + Name: "pkgfact", + Doc: "gather name/value pairs from constant declarations", + Run: run, + FactTypes: []analysis.Fact{new(pairsFact)}, + ResultType: reflect.TypeOf(map[string]string{}), +} + +// A pairsFact is a package-level fact that records +// an set of key=value strings accumulated from constant +// declarations in this package and its dependencies. +// Elements are ordered by keys, which are unique. +type pairsFact []string + +func (f *pairsFact) AFact() {} +func (f *pairsFact) String() string { return "pairs(" + strings.Join(*f, ", ") + ")" } + +func run(pass *analysis.Pass) (interface{}, error) { + result := make(map[string]string) + + // At each import, print the fact from the imported + // package and accumulate its information into the result. + // (Warning: accumulation leads to quadratic growth of work.) + doImport := func(spec *ast.ImportSpec) { + pkg := imported(pass.TypesInfo, spec) + var fact pairsFact + if pass.ImportPackageFact(pkg, &fact) { + for _, pair := range fact { + eq := strings.IndexByte(pair, '=') + result[pair[:eq]] = pair[1+eq:] + } + pass.Reportf(spec.Pos(), "%s", strings.Join(fact, " ")) + } + } + + // At each "const _name_ = value", add a fact into env. + doConst := func(spec *ast.ValueSpec) { + if len(spec.Names) == len(spec.Values) { + for i := range spec.Names { + name := spec.Names[i].Name + if strings.HasPrefix(name, "_") && strings.HasSuffix(name, "_") { + + if key := strings.Trim(name, "_"); key != "" { + value := pass.TypesInfo.Types[spec.Values[i]].Value.String() + result[key] = value + } + } + } + } + } + + for _, f := range pass.Files { + for _, decl := range f.Decls { + if decl, ok := decl.(*ast.GenDecl); ok { + for _, spec := range decl.Specs { + switch decl.Tok { + case token.IMPORT: + doImport(spec.(*ast.ImportSpec)) + case token.CONST: + doConst(spec.(*ast.ValueSpec)) + } + } + } + } + } + + // Sort/deduplicate the result and save it as a package fact. + keys := make([]string, 0, len(result)) + for key := range result { + keys = append(keys, key) + } + sort.Strings(keys) + var fact pairsFact + for _, key := range keys { + fact = append(fact, fmt.Sprintf("%s=%s", key, result[key])) + } + if len(fact) > 0 { + pass.ExportPackageFact(&fact) + } + + return result, nil +} + +func imported(info *types.Info, spec *ast.ImportSpec) *types.Package { + obj, ok := info.Implicits[spec] + if !ok { + obj = info.Defs[spec.Name] // renaming import + } + return obj.(*types.PkgName).Imported() +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/printf.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/printf.go new file mode 100644 index 0000000000000..23f634fd98eb0 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/printf.go @@ -0,0 +1,964 @@ +// 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. + +// This file contains the printf-checker. + +package printf + +import ( + "bytes" + "fmt" + "go/ast" + "go/constant" + "go/token" + "go/types" + "regexp" + "sort" + "strconv" + "strings" + "unicode/utf8" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" + "golang.org/x/tools/go/ast/inspector" + "golang.org/x/tools/go/types/typeutil" +) + +func init() { + Analyzer.Flags.Var(isPrint, "funcs", "comma-separated list of print function names to check") +} + +var Analyzer = &analysis.Analyzer{ + Name: "printf", + Doc: "check printf-like invocations", + Requires: []*analysis.Analyzer{inspect.Analyzer}, + Run: run, + FactTypes: []analysis.Fact{new(isWrapper)}, +} + +const doc = `check consistency of Printf format strings and arguments + +The check applies to known functions (for example, those in package fmt) +as well as any detected wrappers of known functions. + +A function that wants to avail itself of printf checking but does not +get found by this analyzer's heuristics (for example, due to use of +dynamic calls) can insert a bogus call: + + if false { + fmt.Sprintf(format, args...) // enable printf checking + } + +The -funcs flag specifies a comma-separated list of names of additional +known formatting functions or methods. If the name contains a period, +it must denote a specific function using one of the following forms: + + dir/pkg.Function + dir/pkg.Type.Method + (*dir/pkg.Type).Method + +Otherwise the name is interpreted as a case-insensitive unqualified +identifier such as "errorf". Either way, if a listed name ends in f, the +function is assumed to be Printf-like, taking a format string before the +argument list. Otherwise it is assumed to be Print-like, taking a list +of arguments with no format string. +` + +// isWrapper is a fact indicating that a function is a print or printf wrapper. +type isWrapper struct{ Printf bool } + +func (f *isWrapper) AFact() {} + +func (f *isWrapper) String() string { + if f.Printf { + return "printfWrapper" + } else { + return "printWrapper" + } +} + +func run(pass *analysis.Pass) (interface{}, error) { + findPrintfLike(pass) + checkCall(pass) + return nil, nil +} + +type printfWrapper struct { + obj *types.Func + fdecl *ast.FuncDecl + format *types.Var + args *types.Var + callers []printfCaller + failed bool // if true, not a printf wrapper +} + +type printfCaller struct { + w *printfWrapper + call *ast.CallExpr +} + +// maybePrintfWrapper decides whether decl (a declared function) may be a wrapper +// around a fmt.Printf or fmt.Print function. If so it returns a printfWrapper +// function describing the declaration. Later processing will analyze the +// graph of potential printf wrappers to pick out the ones that are true wrappers. +// A function may be a Printf or Print wrapper if its last argument is ...interface{}. +// If the next-to-last argument is a string, then this may be a Printf wrapper. +// Otherwise it may be a Print wrapper. +func maybePrintfWrapper(info *types.Info, decl ast.Decl) *printfWrapper { + // Look for functions with final argument type ...interface{}. + fdecl, ok := decl.(*ast.FuncDecl) + if !ok || fdecl.Body == nil { + return nil + } + fn := info.Defs[fdecl.Name].(*types.Func) + + sig := fn.Type().(*types.Signature) + if !sig.Variadic() { + return nil // not variadic + } + + params := sig.Params() + nparams := params.Len() // variadic => nonzero + + args := params.At(nparams - 1) + iface, ok := args.Type().(*types.Slice).Elem().(*types.Interface) + if !ok || !iface.Empty() { + return nil // final (args) param is not ...interface{} + } + + // Is second last param 'format string'? + var format *types.Var + if nparams >= 2 { + if p := params.At(nparams - 2); p.Type() == types.Typ[types.String] { + format = p + } + } + + return &printfWrapper{ + obj: fn, + fdecl: fdecl, + format: format, + args: args, + } +} + +// findPrintfLike scans the entire package to find printf-like functions. +func findPrintfLike(pass *analysis.Pass) (interface{}, error) { + // Gather potential wrappers and call graph between them. + byObj := make(map[*types.Func]*printfWrapper) + var wrappers []*printfWrapper + for _, file := range pass.Files { + for _, decl := range file.Decls { + w := maybePrintfWrapper(pass.TypesInfo, decl) + if w == nil { + continue + } + byObj[w.obj] = w + wrappers = append(wrappers, w) + } + } + + // Walk the graph to figure out which are really printf wrappers. + for _, w := range wrappers { + // Scan function for calls that could be to other printf-like functions. + ast.Inspect(w.fdecl.Body, func(n ast.Node) bool { + if w.failed { + return false + } + + // TODO: Relax these checks; issue 26555. + if assign, ok := n.(*ast.AssignStmt); ok { + for _, lhs := range assign.Lhs { + if match(pass.TypesInfo, lhs, w.format) || + match(pass.TypesInfo, lhs, w.args) { + // Modifies the format + // string or args in + // some way, so not a + // simple wrapper. + w.failed = true + return false + } + } + } + if un, ok := n.(*ast.UnaryExpr); ok && un.Op == token.AND { + if match(pass.TypesInfo, un.X, w.format) || + match(pass.TypesInfo, un.X, w.args) { + // Taking the address of the + // format string or args, + // so not a simple wrapper. + w.failed = true + return false + } + } + + call, ok := n.(*ast.CallExpr) + if !ok || len(call.Args) == 0 || !match(pass.TypesInfo, call.Args[len(call.Args)-1], w.args) { + return true + } + + fn, kind := printfNameAndKind(pass, call) + if kind != 0 { + checkPrintfFwd(pass, w, call, kind) + return true + } + + // If the call is to another function in this package, + // maybe we will find out it is printf-like later. + // Remember this call for later checking. + if fn != nil && fn.Pkg() == pass.Pkg && byObj[fn] != nil { + callee := byObj[fn] + callee.callers = append(callee.callers, printfCaller{w, call}) + } + + return true + }) + } + return nil, nil +} + +func match(info *types.Info, arg ast.Expr, param *types.Var) bool { + id, ok := arg.(*ast.Ident) + return ok && info.ObjectOf(id) == param +} + +const ( + kindPrintf = 1 + kindPrint = 2 +) + +// checkPrintfFwd checks that a printf-forwarding wrapper is forwarding correctly. +// It diagnoses writing fmt.Printf(format, args) instead of fmt.Printf(format, args...). +func checkPrintfFwd(pass *analysis.Pass, w *printfWrapper, call *ast.CallExpr, kind int) { + matched := kind == kindPrint || + kind == kindPrintf && len(call.Args) >= 2 && match(pass.TypesInfo, call.Args[len(call.Args)-2], w.format) + if !matched { + return + } + + if !call.Ellipsis.IsValid() { + typ, ok := pass.TypesInfo.Types[call.Fun].Type.(*types.Signature) + if !ok { + return + } + if len(call.Args) > typ.Params().Len() { + // If we're passing more arguments than what the + // print/printf function can take, adding an ellipsis + // would break the program. For example: + // + // func foo(arg1 string, arg2 ...interface{} { + // fmt.Printf("%s %v", arg1, arg2) + // } + return + } + desc := "printf" + if kind == kindPrint { + desc = "print" + } + pass.Reportf(call.Pos(), "missing ... in args forwarded to %s-like function", desc) + return + } + fn := w.obj + var fact isWrapper + if !pass.ImportObjectFact(fn, &fact) { + fact.Printf = kind == kindPrintf + pass.ExportObjectFact(fn, &fact) + for _, caller := range w.callers { + checkPrintfFwd(pass, caller.w, caller.call, kind) + } + } +} + +// isPrint records the print functions. +// If a key ends in 'f' then it is assumed to be a formatted print. +// +// Keys are either values returned by (*types.Func).FullName, +// or case-insensitive identifiers such as "errorf". +// +// The -funcs flag adds to this set. +var isPrint = stringSet{ + "fmt.Errorf": true, + "fmt.Fprint": true, + "fmt.Fprintf": true, + "fmt.Fprintln": true, + "fmt.Print": true, // technically these three + "fmt.Printf": true, // are redundant because they + "fmt.Println": true, // forward to Fprint{,f,ln} + "fmt.Sprint": true, + "fmt.Sprintf": true, + "fmt.Sprintln": true, + + // *testing.T and B are detected by induction, but testing.TB is + // an interface and the inference can't follow dynamic calls. + "(testing.TB).Error": true, + "(testing.TB).Errorf": true, + "(testing.TB).Fatal": true, + "(testing.TB).Fatalf": true, + "(testing.TB).Log": true, + "(testing.TB).Logf": true, + "(testing.TB).Skip": true, + "(testing.TB).Skipf": true, +} + +// formatString returns the format string argument and its index within +// the given printf-like call expression. +// +// The last parameter before variadic arguments is assumed to be +// a format string. +// +// The first string literal or string constant is assumed to be a format string +// if the call's signature cannot be determined. +// +// If it cannot find any format string parameter, it returns ("", -1). +func formatString(pass *analysis.Pass, call *ast.CallExpr) (format string, idx int) { + typ := pass.TypesInfo.Types[call.Fun].Type + if typ != nil { + if sig, ok := typ.(*types.Signature); ok { + if !sig.Variadic() { + // Skip checking non-variadic functions. + return "", -1 + } + idx := sig.Params().Len() - 2 + if idx < 0 { + // Skip checking variadic functions without + // fixed arguments. + return "", -1 + } + s, ok := stringConstantArg(pass, call, idx) + if !ok { + // The last argument before variadic args isn't a string. + return "", -1 + } + return s, idx + } + } + + // Cannot determine call's signature. Fall back to scanning for the first + // string constant in the call. + for idx := range call.Args { + if s, ok := stringConstantArg(pass, call, idx); ok { + return s, idx + } + if pass.TypesInfo.Types[call.Args[idx]].Type == types.Typ[types.String] { + // Skip checking a call with a non-constant format + // string argument, since its contents are unavailable + // for validation. + return "", -1 + } + } + return "", -1 +} + +// stringConstantArg returns call's string constant argument at the index idx. +// +// ("", false) is returned if call's argument at the index idx isn't a string +// constant. +func stringConstantArg(pass *analysis.Pass, call *ast.CallExpr, idx int) (string, bool) { + if idx >= len(call.Args) { + return "", false + } + arg := call.Args[idx] + lit := pass.TypesInfo.Types[arg].Value + if lit != nil && lit.Kind() == constant.String { + return constant.StringVal(lit), true + } + return "", false +} + +// checkCall triggers the print-specific checks if the call invokes a print function. +func checkCall(pass *analysis.Pass) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + nodeFilter := []ast.Node{ + (*ast.CallExpr)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + call := n.(*ast.CallExpr) + fn, kind := printfNameAndKind(pass, call) + switch kind { + case kindPrintf: + checkPrintf(pass, call, fn) + case kindPrint: + checkPrint(pass, call, fn) + } + }) +} + +func printfNameAndKind(pass *analysis.Pass, call *ast.CallExpr) (fn *types.Func, kind int) { + fn, _ = typeutil.Callee(pass.TypesInfo, call).(*types.Func) + if fn == nil { + return nil, 0 + } + + var fact isWrapper + if pass.ImportObjectFact(fn, &fact) { + if fact.Printf { + return fn, kindPrintf + } else { + return fn, kindPrint + } + } + + _, ok := isPrint[fn.FullName()] + if !ok { + // Next look up just "printf", for use with -printf.funcs. + _, ok = isPrint[strings.ToLower(fn.Name())] + } + if ok { + if strings.HasSuffix(fn.Name(), "f") { + kind = kindPrintf + } else { + kind = kindPrint + } + } + return fn, kind +} + +// isFormatter reports whether t satisfies fmt.Formatter. +// Unlike fmt.Stringer, it's impossible to satisfy fmt.Formatter without importing fmt. +func isFormatter(pass *analysis.Pass, t types.Type) bool { + for _, imp := range pass.Pkg.Imports() { + if imp.Path() == "fmt" { + formatter := imp.Scope().Lookup("Formatter").Type().Underlying().(*types.Interface) + return types.Implements(t, formatter) + } + } + return false +} + +// formatState holds the parsed representation of a printf directive such as "%3.*[4]d". +// It is constructed by parsePrintfVerb. +type formatState struct { + verb rune // the format verb: 'd' for "%d" + format string // the full format directive from % through verb, "%.3d". + name string // Printf, Sprintf etc. + flags []byte // the list of # + etc. + argNums []int // the successive argument numbers that are consumed, adjusted to refer to actual arg in call + firstArg int // Index of first argument after the format in the Printf call. + // Used only during parse. + pass *analysis.Pass + call *ast.CallExpr + argNum int // Which argument we're expecting to format now. + hasIndex bool // Whether the argument is indexed. + indexPending bool // Whether we have an indexed argument that has not resolved. + nbytes int // number of bytes of the format string consumed. +} + +// checkPrintf checks a call to a formatted print routine such as Printf. +func checkPrintf(pass *analysis.Pass, call *ast.CallExpr, fn *types.Func) { + format, idx := formatString(pass, call) + if idx < 0 { + if false { + pass.Reportf(call.Lparen, "can't check non-constant format in call to %s", fn.Name()) + } + return + } + + firstArg := idx + 1 // Arguments are immediately after format string. + if !strings.Contains(format, "%") { + if len(call.Args) > firstArg { + pass.Reportf(call.Lparen, "%s call has arguments but no formatting directives", fn.Name()) + } + return + } + // Hard part: check formats against args. + argNum := firstArg + maxArgNum := firstArg + anyIndex := false + for i, w := 0, 0; i < len(format); i += w { + w = 1 + if format[i] != '%' { + continue + } + state := parsePrintfVerb(pass, call, fn.Name(), format[i:], firstArg, argNum) + if state == nil { + return + } + w = len(state.format) + if !okPrintfArg(pass, call, state) { // One error per format is enough. + return + } + if state.hasIndex { + anyIndex = true + } + if len(state.argNums) > 0 { + // Continue with the next sequential argument. + argNum = state.argNums[len(state.argNums)-1] + 1 + } + for _, n := range state.argNums { + if n >= maxArgNum { + maxArgNum = n + 1 + } + } + } + // Dotdotdot is hard. + if call.Ellipsis.IsValid() && maxArgNum >= len(call.Args)-1 { + return + } + // If any formats are indexed, extra arguments are ignored. + if anyIndex { + return + } + // There should be no leftover arguments. + if maxArgNum != len(call.Args) { + expect := maxArgNum - firstArg + numArgs := len(call.Args) - firstArg + pass.Reportf(call.Pos(), "%s call needs %v but has %v", fn.Name(), count(expect, "arg"), count(numArgs, "arg")) + } +} + +// parseFlags accepts any printf flags. +func (s *formatState) parseFlags() { + for s.nbytes < len(s.format) { + switch c := s.format[s.nbytes]; c { + case '#', '0', '+', '-', ' ': + s.flags = append(s.flags, c) + s.nbytes++ + default: + return + } + } +} + +// scanNum advances through a decimal number if present. +func (s *formatState) scanNum() { + for ; s.nbytes < len(s.format); s.nbytes++ { + c := s.format[s.nbytes] + if c < '0' || '9' < c { + return + } + } +} + +// parseIndex scans an index expression. It returns false if there is a syntax error. +func (s *formatState) parseIndex() bool { + if s.nbytes == len(s.format) || s.format[s.nbytes] != '[' { + return true + } + // Argument index present. + s.nbytes++ // skip '[' + start := s.nbytes + s.scanNum() + ok := true + if s.nbytes == len(s.format) || s.nbytes == start || s.format[s.nbytes] != ']' { + ok = false + s.nbytes = strings.Index(s.format, "]") + if s.nbytes < 0 { + s.pass.Reportf(s.call.Pos(), "%s format %s is missing closing ]", s.name, s.format) + return false + } + } + arg32, err := strconv.ParseInt(s.format[start:s.nbytes], 10, 32) + if err != nil || !ok || arg32 <= 0 || arg32 > int64(len(s.call.Args)-s.firstArg) { + s.pass.Reportf(s.call.Pos(), "%s format has invalid argument index [%s]", s.name, s.format[start:s.nbytes]) + return false + } + s.nbytes++ // skip ']' + arg := int(arg32) + arg += s.firstArg - 1 // We want to zero-index the actual arguments. + s.argNum = arg + s.hasIndex = true + s.indexPending = true + return true +} + +// parseNum scans a width or precision (or *). It returns false if there's a bad index expression. +func (s *formatState) parseNum() bool { + if s.nbytes < len(s.format) && s.format[s.nbytes] == '*' { + if s.indexPending { // Absorb it. + s.indexPending = false + } + s.nbytes++ + s.argNums = append(s.argNums, s.argNum) + s.argNum++ + } else { + s.scanNum() + } + return true +} + +// parsePrecision scans for a precision. It returns false if there's a bad index expression. +func (s *formatState) parsePrecision() bool { + // If there's a period, there may be a precision. + if s.nbytes < len(s.format) && s.format[s.nbytes] == '.' { + s.flags = append(s.flags, '.') // Treat precision as a flag. + s.nbytes++ + if !s.parseIndex() { + return false + } + if !s.parseNum() { + return false + } + } + return true +} + +// parsePrintfVerb looks the formatting directive that begins the format string +// and returns a formatState that encodes what the directive wants, without looking +// at the actual arguments present in the call. The result is nil if there is an error. +func parsePrintfVerb(pass *analysis.Pass, call *ast.CallExpr, name, format string, firstArg, argNum int) *formatState { + state := &formatState{ + format: format, + name: name, + flags: make([]byte, 0, 5), + argNum: argNum, + argNums: make([]int, 0, 1), + nbytes: 1, // There's guaranteed to be a percent sign. + firstArg: firstArg, + pass: pass, + call: call, + } + // There may be flags. + state.parseFlags() + // There may be an index. + if !state.parseIndex() { + return nil + } + // There may be a width. + if !state.parseNum() { + return nil + } + // There may be a precision. + if !state.parsePrecision() { + return nil + } + // Now a verb, possibly prefixed by an index (which we may already have). + if !state.indexPending && !state.parseIndex() { + return nil + } + if state.nbytes == len(state.format) { + pass.Reportf(call.Pos(), "%s format %s is missing verb at end of string", name, state.format) + return nil + } + verb, w := utf8.DecodeRuneInString(state.format[state.nbytes:]) + state.verb = verb + state.nbytes += w + if verb != '%' { + state.argNums = append(state.argNums, state.argNum) + } + state.format = state.format[:state.nbytes] + return state +} + +// printfArgType encodes the types of expressions a printf verb accepts. It is a bitmask. +type printfArgType int + +const ( + argBool printfArgType = 1 << iota + argInt + argRune + argString + argFloat + argComplex + argPointer + anyType printfArgType = ^0 +) + +type printVerb struct { + verb rune // User may provide verb through Formatter; could be a rune. + flags string // known flags are all ASCII + typ printfArgType +} + +// Common flag sets for printf verbs. +const ( + noFlag = "" + numFlag = " -+.0" + sharpNumFlag = " -+.0#" + allFlags = " -+.0#" +) + +// printVerbs identifies which flags are known to printf for each verb. +var printVerbs = []printVerb{ + // '-' is a width modifier, always valid. + // '.' is a precision for float, max width for strings. + // '+' is required sign for numbers, Go format for %v. + // '#' is alternate format for several verbs. + // ' ' is spacer for numbers + {'%', noFlag, 0}, + {'b', numFlag, argInt | argFloat | argComplex}, + {'c', "-", argRune | argInt}, + {'d', numFlag, argInt | argPointer}, + {'e', sharpNumFlag, argFloat | argComplex}, + {'E', sharpNumFlag, argFloat | argComplex}, + {'f', sharpNumFlag, argFloat | argComplex}, + {'F', sharpNumFlag, argFloat | argComplex}, + {'g', sharpNumFlag, argFloat | argComplex}, + {'G', sharpNumFlag, argFloat | argComplex}, + {'o', sharpNumFlag, argInt}, + {'p', "-#", argPointer}, + {'q', " -+.0#", argRune | argInt | argString}, + {'s', " -+.0", argString}, + {'t', "-", argBool}, + {'T', "-", anyType}, + {'U', "-#", argRune | argInt}, + {'v', allFlags, anyType}, + {'x', sharpNumFlag, argRune | argInt | argString | argPointer}, + {'X', sharpNumFlag, argRune | argInt | argString | argPointer}, +} + +// okPrintfArg compares the formatState to the arguments actually present, +// reporting any discrepancies it can discern. If the final argument is ellipsissed, +// there's little it can do for that. +func okPrintfArg(pass *analysis.Pass, call *ast.CallExpr, state *formatState) (ok bool) { + var v printVerb + found := false + // Linear scan is fast enough for a small list. + for _, v = range printVerbs { + if v.verb == state.verb { + found = true + break + } + } + + // Does current arg implement fmt.Formatter? + formatter := false + if state.argNum < len(call.Args) { + if tv, ok := pass.TypesInfo.Types[call.Args[state.argNum]]; ok { + formatter = isFormatter(pass, tv.Type) + } + } + + if !formatter { + if !found { + pass.Reportf(call.Pos(), "%s format %s has unknown verb %c", state.name, state.format, state.verb) + return false + } + for _, flag := range state.flags { + // TODO: Disable complaint about '0' for Go 1.10. To be fixed properly in 1.11. + // See issues 23598 and 23605. + if flag == '0' { + continue + } + if !strings.ContainsRune(v.flags, rune(flag)) { + pass.Reportf(call.Pos(), "%s format %s has unrecognized flag %c", state.name, state.format, flag) + return false + } + } + } + // Verb is good. If len(state.argNums)>trueArgs, we have something like %.*s and all + // but the final arg must be an integer. + trueArgs := 1 + if state.verb == '%' { + trueArgs = 0 + } + nargs := len(state.argNums) + for i := 0; i < nargs-trueArgs; i++ { + argNum := state.argNums[i] + if !argCanBeChecked(pass, call, i, state) { + return + } + arg := call.Args[argNum] + if !matchArgType(pass, argInt, nil, arg) { + pass.Reportf(call.Pos(), "%s format %s uses non-int %s as argument of *", state.name, state.format, analysisutil.Format(pass.Fset, arg)) + return false + } + } + + if state.verb == '%' || formatter { + return true + } + argNum := state.argNums[len(state.argNums)-1] + if !argCanBeChecked(pass, call, len(state.argNums)-1, state) { + return false + } + arg := call.Args[argNum] + if isFunctionValue(pass, arg) && state.verb != 'p' && state.verb != 'T' { + pass.Reportf(call.Pos(), "%s format %s arg %s is a func value, not called", state.name, state.format, analysisutil.Format(pass.Fset, arg)) + return false + } + if !matchArgType(pass, v.typ, nil, arg) { + typeString := "" + if typ := pass.TypesInfo.Types[arg].Type; typ != nil { + typeString = typ.String() + } + pass.Reportf(call.Pos(), "%s format %s has arg %s of wrong type %s", state.name, state.format, analysisutil.Format(pass.Fset, arg), typeString) + return false + } + if v.typ&argString != 0 && v.verb != 'T' && !bytes.Contains(state.flags, []byte{'#'}) && recursiveStringer(pass, arg) { + pass.Reportf(call.Pos(), "%s format %s with arg %s causes recursive String method call", state.name, state.format, analysisutil.Format(pass.Fset, arg)) + return false + } + return true +} + +// recursiveStringer reports whether the argument e is a potential +// recursive call to stringer, such as t and &t in these examples: +// +// func (t *T) String() string { printf("%s", t) } +// func (t T) String() string { printf("%s", t) } +// func (t T) String() string { printf("%s", &t) } +// +func recursiveStringer(pass *analysis.Pass, e ast.Expr) bool { + typ := pass.TypesInfo.Types[e].Type + + // It's unlikely to be a recursive stringer if it has a Format method. + if isFormatter(pass, typ) { + return false + } + + // Does e allow e.String()? + obj, _, _ := types.LookupFieldOrMethod(typ, false, pass.Pkg, "String") + stringMethod, ok := obj.(*types.Func) + if !ok { + return false + } + + // Is the expression e within the body of that String method? + return stringMethod.Pkg() == pass.Pkg && stringMethod.Scope().Contains(e.Pos()) +} + +// isFunctionValue reports whether the expression is a function as opposed to a function call. +// It is almost always a mistake to print a function value. +func isFunctionValue(pass *analysis.Pass, e ast.Expr) bool { + if typ := pass.TypesInfo.Types[e].Type; typ != nil { + _, ok := typ.(*types.Signature) + return ok + } + return false +} + +// argCanBeChecked reports whether the specified argument is statically present; +// it may be beyond the list of arguments or in a terminal slice... argument, which +// means we can't see it. +func argCanBeChecked(pass *analysis.Pass, call *ast.CallExpr, formatArg int, state *formatState) bool { + argNum := state.argNums[formatArg] + if argNum <= 0 { + // Shouldn't happen, so catch it with prejudice. + panic("negative arg num") + } + if argNum < len(call.Args)-1 { + return true // Always OK. + } + if call.Ellipsis.IsValid() { + return false // We just can't tell; there could be many more arguments. + } + if argNum < len(call.Args) { + return true + } + // There are bad indexes in the format or there are fewer arguments than the format needs. + // This is the argument number relative to the format: Printf("%s", "hi") will give 1 for the "hi". + arg := argNum - state.firstArg + 1 // People think of arguments as 1-indexed. + pass.Reportf(call.Pos(), "%s format %s reads arg #%d, but call has %v", state.name, state.format, arg, count(len(call.Args)-state.firstArg, "arg")) + return false +} + +// printFormatRE is the regexp we match and report as a possible format string +// in the first argument to unformatted prints like fmt.Print. +// We exclude the space flag, so that printing a string like "x % y" is not reported as a format. +var printFormatRE = regexp.MustCompile(`%` + flagsRE + numOptRE + `\.?` + numOptRE + indexOptRE + verbRE) + +const ( + flagsRE = `[+\-#]*` + indexOptRE = `(\[[0-9]+\])?` + numOptRE = `([0-9]+|` + indexOptRE + `\*)?` + verbRE = `[bcdefgopqstvxEFGTUX]` +) + +// checkPrint checks a call to an unformatted print routine such as Println. +func checkPrint(pass *analysis.Pass, call *ast.CallExpr, fn *types.Func) { + firstArg := 0 + typ := pass.TypesInfo.Types[call.Fun].Type + if typ == nil { + // Skip checking functions with unknown type. + return + } + if sig, ok := typ.(*types.Signature); ok { + if !sig.Variadic() { + // Skip checking non-variadic functions. + return + } + params := sig.Params() + firstArg = params.Len() - 1 + + typ := params.At(firstArg).Type() + typ = typ.(*types.Slice).Elem() + it, ok := typ.(*types.Interface) + if !ok || !it.Empty() { + // Skip variadic functions accepting non-interface{} args. + return + } + } + args := call.Args + if len(args) <= firstArg { + // Skip calls without variadic args. + return + } + args = args[firstArg:] + + if firstArg == 0 { + if sel, ok := call.Args[0].(*ast.SelectorExpr); ok { + if x, ok := sel.X.(*ast.Ident); ok { + if x.Name == "os" && strings.HasPrefix(sel.Sel.Name, "Std") { + pass.Reportf(call.Pos(), "%s does not take io.Writer but has first arg %s", fn.Name(), analysisutil.Format(pass.Fset, call.Args[0])) + } + } + } + } + + arg := args[0] + if lit, ok := arg.(*ast.BasicLit); ok && lit.Kind == token.STRING { + // Ignore trailing % character in lit.Value. + // The % in "abc 0.0%" couldn't be a formatting directive. + s := strings.TrimSuffix(lit.Value, `%"`) + if strings.Contains(s, "%") { + m := printFormatRE.FindStringSubmatch(s) + if m != nil { + pass.Reportf(call.Pos(), "%s call has possible formatting directive %s", fn.Name(), m[0]) + } + } + } + if strings.HasSuffix(fn.Name(), "ln") { + // The last item, if a string, should not have a newline. + arg = args[len(args)-1] + if lit, ok := arg.(*ast.BasicLit); ok && lit.Kind == token.STRING { + str, _ := strconv.Unquote(lit.Value) + if strings.HasSuffix(str, "\n") { + pass.Reportf(call.Pos(), "%s arg list ends with redundant newline", fn.Name()) + } + } + } + for _, arg := range args { + if isFunctionValue(pass, arg) { + pass.Reportf(call.Pos(), "%s arg %s is a func value, not called", fn.Name(), analysisutil.Format(pass.Fset, arg)) + } + if recursiveStringer(pass, arg) { + pass.Reportf(call.Pos(), "%s arg %s causes recursive call to String method", fn.Name(), analysisutil.Format(pass.Fset, arg)) + } + } +} + +// count(n, what) returns "1 what" or "N whats" +// (assuming the plural of what is whats). +func count(n int, what string) string { + if n == 1 { + return "1 " + what + } + return fmt.Sprintf("%d %ss", n, what) +} + +// stringSet is a set-of-nonempty-strings-valued flag. +// Note: elements without a '.' get lower-cased. +type stringSet map[string]bool + +func (ss stringSet) String() string { + var list []string + for name := range ss { + list = append(list, name) + } + sort.Strings(list) + return strings.Join(list, ",") +} + +func (ss stringSet) Set(flag string) error { + for _, name := range strings.Split(flag, ",") { + if len(name) == 0 { + return fmt.Errorf("empty string") + } + if !strings.Contains(name, ".") { + name = strings.ToLower(name) + } + ss[name] = true + } + return nil +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/types.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/types.go new file mode 100644 index 0000000000000..701d08bea2bb1 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/printf/types.go @@ -0,0 +1,223 @@ +package printf + +import ( + "go/ast" + "go/build" + "go/types" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" +) + +var errorType = types.Universe.Lookup("error").Type().Underlying().(*types.Interface) + +// matchArgType reports an error if printf verb t is not appropriate +// for operand arg. +// +// typ is used only for recursive calls; external callers must supply nil. +// +// (Recursion arises from the compound types {map,chan,slice} which +// may be printed with %d etc. if that is appropriate for their element +// types.) +func matchArgType(pass *analysis.Pass, t printfArgType, typ types.Type, arg ast.Expr) bool { + return matchArgTypeInternal(pass, t, typ, arg, make(map[types.Type]bool)) +} + +// matchArgTypeInternal is the internal version of matchArgType. It carries a map +// remembering what types are in progress so we don't recur when faced with recursive +// types or mutually recursive types. +func matchArgTypeInternal(pass *analysis.Pass, t printfArgType, typ types.Type, arg ast.Expr, inProgress map[types.Type]bool) bool { + // %v, %T accept any argument type. + if t == anyType { + return true + } + if typ == nil { + // external call + typ = pass.TypesInfo.Types[arg].Type + if typ == nil { + return true // probably a type check problem + } + } + // If the type implements fmt.Formatter, we have nothing to check. + if isFormatter(pass, typ) { + return true + } + // If we can use a string, might arg (dynamically) implement the Stringer or Error interface? + if t&argString != 0 && isConvertibleToString(pass, typ) { + return true + } + + typ = typ.Underlying() + if inProgress[typ] { + // We're already looking at this type. The call that started it will take care of it. + return true + } + inProgress[typ] = true + + switch typ := typ.(type) { + case *types.Signature: + return t&argPointer != 0 + + case *types.Map: + // Recur: map[int]int matches %d. + return t&argPointer != 0 || + (matchArgTypeInternal(pass, t, typ.Key(), arg, inProgress) && matchArgTypeInternal(pass, t, typ.Elem(), arg, inProgress)) + + case *types.Chan: + return t&argPointer != 0 + + case *types.Array: + // Same as slice. + if types.Identical(typ.Elem().Underlying(), types.Typ[types.Byte]) && t&argString != 0 { + return true // %s matches []byte + } + // Recur: []int matches %d. + return t&argPointer != 0 || matchArgTypeInternal(pass, t, typ.Elem(), arg, inProgress) + + case *types.Slice: + // Same as array. + if types.Identical(typ.Elem().Underlying(), types.Typ[types.Byte]) && t&argString != 0 { + return true // %s matches []byte + } + // Recur: []int matches %d. But watch out for + // type T []T + // If the element is a pointer type (type T[]*T), it's handled fine by the Pointer case below. + return t&argPointer != 0 || matchArgTypeInternal(pass, t, typ.Elem(), arg, inProgress) + + case *types.Pointer: + // Ugly, but dealing with an edge case: a known pointer to an invalid type, + // probably something from a failed import. + if typ.Elem().String() == "invalid type" { + if false { + pass.Reportf(arg.Pos(), "printf argument %v is pointer to invalid or unknown type", analysisutil.Format(pass.Fset, arg)) + } + return true // special case + } + // If it's actually a pointer with %p, it prints as one. + if t == argPointer { + return true + } + // If it's pointer to struct, that's equivalent in our analysis to whether we can print the struct. + if str, ok := typ.Elem().Underlying().(*types.Struct); ok { + return matchStructArgType(pass, t, str, arg, inProgress) + } + // Check whether the rest can print pointers. + return t&argPointer != 0 + + case *types.Struct: + return matchStructArgType(pass, t, typ, arg, inProgress) + + case *types.Interface: + // There's little we can do. + // Whether any particular verb is valid depends on the argument. + // The user may have reasonable prior knowledge of the contents of the interface. + return true + + case *types.Basic: + switch typ.Kind() { + case types.UntypedBool, + types.Bool: + return t&argBool != 0 + + case types.UntypedInt, + types.Int, + types.Int8, + types.Int16, + types.Int32, + types.Int64, + types.Uint, + types.Uint8, + types.Uint16, + types.Uint32, + types.Uint64, + types.Uintptr: + return t&argInt != 0 + + case types.UntypedFloat, + types.Float32, + types.Float64: + return t&argFloat != 0 + + case types.UntypedComplex, + types.Complex64, + types.Complex128: + return t&argComplex != 0 + + case types.UntypedString, + types.String: + return t&argString != 0 + + case types.UnsafePointer: + return t&(argPointer|argInt) != 0 + + case types.UntypedRune: + return t&(argInt|argRune) != 0 + + case types.UntypedNil: + return false + + case types.Invalid: + if false { + pass.Reportf(arg.Pos(), "printf argument %v has invalid or unknown type", analysisutil.Format(pass.Fset, arg)) + } + return true // Probably a type check problem. + } + panic("unreachable") + } + + return false +} + +func isConvertibleToString(pass *analysis.Pass, typ types.Type) bool { + if bt, ok := typ.(*types.Basic); ok && bt.Kind() == types.UntypedNil { + // We explicitly don't want untyped nil, which is + // convertible to both of the interfaces below, as it + // would just panic anyway. + return false + } + if types.ConvertibleTo(typ, errorType) { + return true // via .Error() + } + + // Does it implement fmt.Stringer? + if obj, _, _ := types.LookupFieldOrMethod(typ, false, nil, "String"); obj != nil { + if fn, ok := obj.(*types.Func); ok { + sig := fn.Type().(*types.Signature) + if sig.Params().Len() == 0 && + sig.Results().Len() == 1 && + sig.Results().At(0).Type() == types.Typ[types.String] { + return true + } + } + } + + return false +} + +// hasBasicType reports whether x's type is a types.Basic with the given kind. +func hasBasicType(pass *analysis.Pass, x ast.Expr, kind types.BasicKind) bool { + t := pass.TypesInfo.Types[x].Type + if t != nil { + t = t.Underlying() + } + b, ok := t.(*types.Basic) + return ok && b.Kind() == kind +} + +// matchStructArgType reports whether all the elements of the struct match the expected +// type. For instance, with "%d" all the elements must be printable with the "%d" format. +func matchStructArgType(pass *analysis.Pass, t printfArgType, typ *types.Struct, arg ast.Expr, inProgress map[types.Type]bool) bool { + for i := 0; i < typ.NumFields(); i++ { + typf := typ.Field(i) + if !matchArgTypeInternal(pass, t, typf.Type(), arg, inProgress) { + return false + } + if t&argString != 0 && !typf.Exported() && isConvertibleToString(pass, typf.Type()) { + // Issue #17798: unexported Stringer or error cannot be properly fomatted. + return false + } + } + return true +} + +var archSizes = types.SizesFor("gc", build.Default.GOARCH) diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/dead.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/dead.go new file mode 100644 index 0000000000000..43415a98d61fe --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/dead.go @@ -0,0 +1,101 @@ +// 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. + +package shift + +// Simplified dead code detector. +// Used for skipping shift checks on unreachable arch-specific code. + +import ( + "go/ast" + "go/constant" + "go/types" +) + +// updateDead puts unreachable "if" and "case" nodes into dead. +func updateDead(info *types.Info, dead map[ast.Node]bool, node ast.Node) { + if dead[node] { + // The node is already marked as dead. + return + } + + // setDead marks the node and all the children as dead. + setDead := func(n ast.Node) { + ast.Inspect(n, func(node ast.Node) bool { + if node != nil { + dead[node] = true + } + return true + }) + } + + switch stmt := node.(type) { + case *ast.IfStmt: + // "if" branch is dead if its condition evaluates + // to constant false. + v := info.Types[stmt.Cond].Value + if v == nil { + return + } + if !constant.BoolVal(v) { + setDead(stmt.Body) + return + } + if stmt.Else != nil { + setDead(stmt.Else) + } + case *ast.SwitchStmt: + // Case clause with empty switch tag is dead if it evaluates + // to constant false. + if stmt.Tag == nil { + BodyLoopBool: + for _, stmt := range stmt.Body.List { + cc := stmt.(*ast.CaseClause) + if cc.List == nil { + // Skip default case. + continue + } + for _, expr := range cc.List { + v := info.Types[expr].Value + if v == nil || v.Kind() != constant.Bool || constant.BoolVal(v) { + continue BodyLoopBool + } + } + setDead(cc) + } + return + } + + // Case clause is dead if its constant value doesn't match + // the constant value from the switch tag. + // TODO: This handles integer comparisons only. + v := info.Types[stmt.Tag].Value + if v == nil || v.Kind() != constant.Int { + return + } + tagN, ok := constant.Uint64Val(v) + if !ok { + return + } + BodyLoopInt: + for _, x := range stmt.Body.List { + cc := x.(*ast.CaseClause) + if cc.List == nil { + // Skip default case. + continue + } + for _, expr := range cc.List { + v := info.Types[expr].Value + if v == nil { + continue BodyLoopInt + } + n, ok := constant.Uint64Val(v) + if !ok || tagN == n { + continue BodyLoopInt + } + } + setDead(cc) + } + } +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/shift.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/shift.go new file mode 100644 index 0000000000000..56b150b2b132c --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/shift/shift.go @@ -0,0 +1,128 @@ +// Copyright 2014 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. + +// Package shift defines an Analyzer that checks for shifts that exceed +// the width of an integer. +package shift + +// TODO(adonovan): integrate with ctrflow (CFG-based) dead code analysis. May +// have impedance mismatch due to its (non-)treatment of constant +// expressions (such as runtime.GOARCH=="386"). + +import ( + "go/ast" + "go/build" + "go/constant" + "go/token" + "go/types" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" + "golang.org/x/tools/go/ast/inspector" +) + +var Analyzer = &analysis.Analyzer{ + Name: "shift", + Doc: "check for shifts that equal or exceed the width of the integer", + Requires: []*analysis.Analyzer{inspect.Analyzer}, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + // Do a complete pass to compute dead nodes. + dead := make(map[ast.Node]bool) + nodeFilter := []ast.Node{ + (*ast.IfStmt)(nil), + (*ast.SwitchStmt)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + // TODO(adonovan): move updateDead into this file. + updateDead(pass.TypesInfo, dead, n) + }) + + nodeFilter = []ast.Node{ + (*ast.AssignStmt)(nil), + (*ast.BinaryExpr)(nil), + } + inspect.Preorder(nodeFilter, func(node ast.Node) { + if dead[node] { + // Skip shift checks on unreachable nodes. + return + } + + switch node := node.(type) { + case *ast.BinaryExpr: + if node.Op == token.SHL || node.Op == token.SHR { + checkLongShift(pass, node, node.X, node.Y) + } + case *ast.AssignStmt: + if len(node.Lhs) != 1 || len(node.Rhs) != 1 { + return + } + if node.Tok == token.SHL_ASSIGN || node.Tok == token.SHR_ASSIGN { + checkLongShift(pass, node, node.Lhs[0], node.Rhs[0]) + } + } + }) + return nil, nil +} + +// checkLongShift checks if shift or shift-assign operations shift by more than +// the length of the underlying variable. +func checkLongShift(pass *analysis.Pass, node ast.Node, x, y ast.Expr) { + if pass.TypesInfo.Types[x].Value != nil { + // Ignore shifts of constants. + // These are frequently used for bit-twiddling tricks + // like ^uint(0) >> 63 for 32/64 bit detection and compatibility. + return + } + + v := pass.TypesInfo.Types[y].Value + if v == nil { + return + } + amt, ok := constant.Int64Val(v) + if !ok { + return + } + t := pass.TypesInfo.Types[x].Type + if t == nil { + return + } + b, ok := t.Underlying().(*types.Basic) + if !ok { + return + } + var size int64 + switch b.Kind() { + case types.Uint8, types.Int8: + size = 8 + case types.Uint16, types.Int16: + size = 16 + case types.Uint32, types.Int32: + size = 32 + case types.Uint64, types.Int64: + size = 64 + case types.Int, types.Uint: + size = uintBitSize + case types.Uintptr: + size = uintptrBitSize + default: + return + } + if amt >= size { + ident := analysisutil.Format(pass.Fset, x) + pass.Reportf(node.Pos(), "%s (%d bits) too small for shift of %d", ident, size, amt) + } +} + +var ( + uintBitSize = 8 * archSizes.Sizeof(types.Typ[types.Uint]) + uintptrBitSize = 8 * archSizes.Sizeof(types.Typ[types.Uintptr]) +) + +var archSizes = types.SizesFor("gc", build.Default.GOARCH) diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/stdmethods/stdmethods.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/stdmethods/stdmethods.go new file mode 100644 index 0000000000000..eead289e4ccba --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/stdmethods/stdmethods.go @@ -0,0 +1,211 @@ +// 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. + +// Package stdmethods defines an Analyzer that checks for misspellings +// in the signatures of methods similar to well-known interfaces. +package stdmethods + +import ( + "bytes" + "fmt" + "go/ast" + "go/printer" + "go/token" + "go/types" + "strings" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `check signature of methods of well-known interfaces + +Sometimes a type may be intended to satisfy an interface but may fail to +do so because of a mistake in its method signature. +For example, the result of this WriteTo method should be (int64, error), +not error, to satisfy io.WriterTo: + + type myWriterTo struct{...} + func (myWriterTo) WriteTo(w io.Writer) error { ... } + +This check ensures that each method whose name matches one of several +well-known interface methods from the standard library has the correct +signature for that interface. + +Checked method names include: + Format GobEncode GobDecode MarshalJSON MarshalXML + Peek ReadByte ReadFrom ReadRune Scan Seek + UnmarshalJSON UnreadByte UnreadRune WriteByte + WriteTo +` + +var Analyzer = &analysis.Analyzer{ + Name: "stdmethods", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + Run: run, +} + +// canonicalMethods lists the input and output types for Go methods +// that are checked using dynamic interface checks. Because the +// checks are dynamic, such methods would not cause a compile error +// if they have the wrong signature: instead the dynamic check would +// fail, sometimes mysteriously. If a method is found with a name listed +// here but not the input/output types listed here, vet complains. +// +// A few of the canonical methods have very common names. +// For example, a type might implement a Scan method that +// has nothing to do with fmt.Scanner, but we still want to check +// the methods that are intended to implement fmt.Scanner. +// To do that, the arguments that have a = prefix are treated as +// signals that the canonical meaning is intended: if a Scan +// method doesn't have a fmt.ScanState as its first argument, +// we let it go. But if it does have a fmt.ScanState, then the +// rest has to match. +var canonicalMethods = map[string]struct{ args, results []string }{ + // "Flush": {{}, {"error"}}, // http.Flusher and jpeg.writer conflict + "Format": {[]string{"=fmt.State", "rune"}, []string{}}, // fmt.Formatter + "GobDecode": {[]string{"[]byte"}, []string{"error"}}, // gob.GobDecoder + "GobEncode": {[]string{}, []string{"[]byte", "error"}}, // gob.GobEncoder + "MarshalJSON": {[]string{}, []string{"[]byte", "error"}}, // json.Marshaler + "MarshalXML": {[]string{"*xml.Encoder", "xml.StartElement"}, []string{"error"}}, // xml.Marshaler + "ReadByte": {[]string{}, []string{"byte", "error"}}, // io.ByteReader + "ReadFrom": {[]string{"=io.Reader"}, []string{"int64", "error"}}, // io.ReaderFrom + "ReadRune": {[]string{}, []string{"rune", "int", "error"}}, // io.RuneReader + "Scan": {[]string{"=fmt.ScanState", "rune"}, []string{"error"}}, // fmt.Scanner + "Seek": {[]string{"=int64", "int"}, []string{"int64", "error"}}, // io.Seeker + "UnmarshalJSON": {[]string{"[]byte"}, []string{"error"}}, // json.Unmarshaler + "UnmarshalXML": {[]string{"*xml.Decoder", "xml.StartElement"}, []string{"error"}}, // xml.Unmarshaler + "UnreadByte": {[]string{}, []string{"error"}}, + "UnreadRune": {[]string{}, []string{"error"}}, + "WriteByte": {[]string{"byte"}, []string{"error"}}, // jpeg.writer (matching bufio.Writer) + "WriteTo": {[]string{"=io.Writer"}, []string{"int64", "error"}}, // io.WriterTo +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.FuncDecl)(nil), + (*ast.InterfaceType)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + switch n := n.(type) { + case *ast.FuncDecl: + if n.Recv != nil { + canonicalMethod(pass, n.Name, n.Type) + } + case *ast.InterfaceType: + for _, field := range n.Methods.List { + for _, id := range field.Names { + canonicalMethod(pass, id, field.Type.(*ast.FuncType)) + } + } + } + }) + return nil, nil +} + +func canonicalMethod(pass *analysis.Pass, id *ast.Ident, t *ast.FuncType) { + // Expected input/output. + expect, ok := canonicalMethods[id.Name] + if !ok { + return + } + + // Actual input/output + args := typeFlatten(t.Params.List) + var results []ast.Expr + if t.Results != nil { + results = typeFlatten(t.Results.List) + } + + // Do the =s (if any) all match? + if !matchParams(pass, expect.args, args, "=") || !matchParams(pass, expect.results, results, "=") { + return + } + + // Everything must match. + if !matchParams(pass, expect.args, args, "") || !matchParams(pass, expect.results, results, "") { + expectFmt := id.Name + "(" + argjoin(expect.args) + ")" + if len(expect.results) == 1 { + expectFmt += " " + argjoin(expect.results) + } else if len(expect.results) > 1 { + expectFmt += " (" + argjoin(expect.results) + ")" + } + + var buf bytes.Buffer + if err := printer.Fprint(&buf, pass.Fset, t); err != nil { + fmt.Fprintf(&buf, "<%s>", err) + } + actual := buf.String() + actual = strings.TrimPrefix(actual, "func") + actual = id.Name + actual + + pass.Reportf(id.Pos(), "method %s should have signature %s", actual, expectFmt) + } +} + +func argjoin(x []string) string { + y := make([]string, len(x)) + for i, s := range x { + if s[0] == '=' { + s = s[1:] + } + y[i] = s + } + return strings.Join(y, ", ") +} + +// Turn parameter list into slice of types +// (in the ast, types are Exprs). +// Have to handle f(int, bool) and f(x, y, z int) +// so not a simple 1-to-1 conversion. +func typeFlatten(l []*ast.Field) []ast.Expr { + var t []ast.Expr + for _, f := range l { + if len(f.Names) == 0 { + t = append(t, f.Type) + continue + } + for range f.Names { + t = append(t, f.Type) + } + } + return t +} + +// Does each type in expect with the given prefix match the corresponding type in actual? +func matchParams(pass *analysis.Pass, expect []string, actual []ast.Expr, prefix string) bool { + for i, x := range expect { + if !strings.HasPrefix(x, prefix) { + continue + } + if i >= len(actual) { + return false + } + if !matchParamType(pass.Fset, pass.Pkg, x, actual[i]) { + return false + } + } + if prefix == "" && len(actual) > len(expect) { + return false + } + return true +} + +// Does this one type match? +func matchParamType(fset *token.FileSet, pkg *types.Package, expect string, actual ast.Expr) bool { + expect = strings.TrimPrefix(expect, "=") + // Strip package name if we're in that package. + if n := len(pkg.Name()); len(expect) > n && expect[:n] == pkg.Name() && expect[n] == '.' { + expect = expect[n+1:] + } + + // Overkill but easy. + var buf bytes.Buffer + printer.Fprint(&buf, fset, actual) + return buf.String() == expect +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go new file mode 100644 index 0000000000000..78133fe6f30a9 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/structtag/structtag.go @@ -0,0 +1,260 @@ +// 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. + +// Package structtag defines an Analyzer that checks struct field tags +// are well formed. +package structtag + +import ( + "errors" + "go/ast" + "go/token" + "go/types" + "path/filepath" + "reflect" + "strconv" + "strings" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `check that struct field tags conform to reflect.StructTag.Get + +Also report certain struct tags (json, xml) used with unexported fields.` + +var Analyzer = &analysis.Analyzer{ + Name: "structtag", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + RunDespiteErrors: true, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.StructType)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + styp := pass.TypesInfo.Types[n.(*ast.StructType)].Type.(*types.Struct) + var seen map[[2]string]token.Pos + for i := 0; i < styp.NumFields(); i++ { + field := styp.Field(i) + tag := styp.Tag(i) + checkCanonicalFieldTag(pass, field, tag, &seen) + } + }) + return nil, nil +} + +var checkTagDups = []string{"json", "xml"} +var checkTagSpaces = map[string]bool{"json": true, "xml": true, "asn1": true} + +// checkCanonicalFieldTag checks a single struct field tag. +func checkCanonicalFieldTag(pass *analysis.Pass, field *types.Var, tag string, seen *map[[2]string]token.Pos) { + for _, key := range checkTagDups { + checkTagDuplicates(pass, tag, key, field, field, seen) + } + + if err := validateStructTag(tag); err != nil { + pass.Reportf(field.Pos(), "struct field tag %#q not compatible with reflect.StructTag.Get: %s", tag, err) + } + + // Check for use of json or xml tags with unexported fields. + + // Embedded struct. Nothing to do for now, but that + // may change, depending on what happens with issue 7363. + // TODO(adonovan): investigate, now that that issue is fixed. + if field.Anonymous() { + return + } + + if field.Exported() { + return + } + + for _, enc := range [...]string{"json", "xml"} { + if reflect.StructTag(tag).Get(enc) != "" { + pass.Reportf(field.Pos(), "struct field %s has %s tag but is not exported", field.Name(), enc) + return + } + } +} + +// checkTagDuplicates checks a single struct field tag to see if any tags are +// duplicated. nearest is the field that's closest to the field being checked, +// while still being part of the top-level struct type. +func checkTagDuplicates(pass *analysis.Pass, tag, key string, nearest, field *types.Var, seen *map[[2]string]token.Pos) { + val := reflect.StructTag(tag).Get(key) + if val == "-" { + // Ignored, even if the field is anonymous. + return + } + if val == "" || val[0] == ',' { + if field.Anonymous() { + typ, ok := field.Type().Underlying().(*types.Struct) + if !ok { + return + } + for i := 0; i < typ.NumFields(); i++ { + field := typ.Field(i) + if !field.Exported() { + continue + } + tag := typ.Tag(i) + checkTagDuplicates(pass, tag, key, nearest, field, seen) + } + } + // Ignored if the field isn't anonymous. + return + } + if key == "xml" && field.Name() == "XMLName" { + // XMLName defines the XML element name of the struct being + // checked. That name cannot collide with element or attribute + // names defined on other fields of the struct. Vet does not have a + // check for untagged fields of type struct defining their own name + // by containing a field named XMLName; see issue 18256. + return + } + if i := strings.Index(val, ","); i >= 0 { + if key == "xml" { + // Use a separate namespace for XML attributes. + for _, opt := range strings.Split(val[i:], ",") { + if opt == "attr" { + key += " attribute" // Key is part of the error message. + break + } + } + } + val = val[:i] + } + if *seen == nil { + *seen = map[[2]string]token.Pos{} + } + if pos, ok := (*seen)[[2]string{key, val}]; ok { + posn := pass.Fset.Position(pos) + posn.Filename = filepath.Base(posn.Filename) + posn.Column = 0 + pass.Reportf(nearest.Pos(), "struct field %s repeats %s tag %q also at %s", field.Name(), key, val, posn) + } else { + (*seen)[[2]string{key, val}] = field.Pos() + } +} + +var ( + errTagSyntax = errors.New("bad syntax for struct tag pair") + errTagKeySyntax = errors.New("bad syntax for struct tag key") + errTagValueSyntax = errors.New("bad syntax for struct tag value") + errTagValueSpace = errors.New("suspicious space in struct tag value") + errTagSpace = errors.New("key:\"value\" pairs not separated by spaces") +) + +// validateStructTag parses the struct tag and returns an error if it is not +// in the canonical format, which is a space-separated list of key:"value" +// settings. The value may contain spaces. +func validateStructTag(tag string) error { + // This code is based on the StructTag.Get code in package reflect. + + n := 0 + for ; tag != ""; n++ { + if n > 0 && tag != "" && tag[0] != ' ' { + // More restrictive than reflect, but catches likely mistakes + // like `x:"foo",y:"bar"`, which parses as `x:"foo" ,y:"bar"` with second key ",y". + return errTagSpace + } + // Skip leading space. + i := 0 + for i < len(tag) && tag[i] == ' ' { + i++ + } + tag = tag[i:] + if tag == "" { + break + } + + // Scan to colon. A space, a quote or a control character is a syntax error. + // Strictly speaking, control chars include the range [0x7f, 0x9f], not just + // [0x00, 0x1f], but in practice, we ignore the multi-byte control characters + // as it is simpler to inspect the tag's bytes than the tag's runes. + i = 0 + for i < len(tag) && tag[i] > ' ' && tag[i] != ':' && tag[i] != '"' && tag[i] != 0x7f { + i++ + } + if i == 0 { + return errTagKeySyntax + } + if i+1 >= len(tag) || tag[i] != ':' { + return errTagSyntax + } + if tag[i+1] != '"' { + return errTagValueSyntax + } + key := tag[:i] + tag = tag[i+1:] + + // Scan quoted string to find value. + i = 1 + for i < len(tag) && tag[i] != '"' { + if tag[i] == '\\' { + i++ + } + i++ + } + if i >= len(tag) { + return errTagValueSyntax + } + qvalue := tag[:i+1] + tag = tag[i+1:] + + value, err := strconv.Unquote(qvalue) + if err != nil { + return errTagValueSyntax + } + + if !checkTagSpaces[key] { + continue + } + + switch key { + case "xml": + // If the first or last character in the XML tag is a space, it is + // suspicious. + if strings.Trim(value, " ") != value { + return errTagValueSpace + } + + // If there are multiple spaces, they are suspicious. + if strings.Count(value, " ") > 1 { + return errTagValueSpace + } + + // If there is no comma, skip the rest of the checks. + comma := strings.IndexRune(value, ',') + if comma < 0 { + continue + } + + // If the character before a comma is a space, this is suspicious. + if comma > 0 && value[comma-1] == ' ' { + return errTagValueSpace + } + value = value[comma+1:] + case "json": + // JSON allows using spaces in the name, so skip it. + comma := strings.IndexRune(value, ',') + if comma < 0 { + continue + } + value = value[comma+1:] + } + + if strings.IndexByte(value, ' ') >= 0 { + return errTagValueSpace + } + } + return nil +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/tests/tests.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/tests/tests.go new file mode 100644 index 0000000000000..35b0a3e7cc2d5 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/tests/tests.go @@ -0,0 +1,175 @@ +// Copyright 2015 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. + +// Package tests defines an Analyzer that checks for common mistaken +// usages of tests and examples. +package tests + +import ( + "go/ast" + "go/types" + "strings" + "unicode" + "unicode/utf8" + + "golang.org/x/tools/go/analysis" +) + +const Doc = `check for common mistaken usages of tests and examples + +The tests checker walks Test, Benchmark and Example functions checking +malformed names, wrong signatures and examples documenting non-existent +identifiers.` + +var Analyzer = &analysis.Analyzer{ + Name: "tests", + Doc: Doc, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + for _, f := range pass.Files { + if !strings.HasSuffix(pass.Fset.File(f.Pos()).Name(), "_test.go") { + continue + } + for _, decl := range f.Decls { + fn, ok := decl.(*ast.FuncDecl) + if !ok || fn.Recv != nil { + // Ignore non-functions or functions with receivers. + continue + } + + switch { + case strings.HasPrefix(fn.Name.Name, "Example"): + checkExample(pass, fn) + case strings.HasPrefix(fn.Name.Name, "Test"): + checkTest(pass, fn, "Test") + case strings.HasPrefix(fn.Name.Name, "Benchmark"): + checkTest(pass, fn, "Benchmark") + } + } + } + return nil, nil +} + +func isExampleSuffix(s string) bool { + r, size := utf8.DecodeRuneInString(s) + return size > 0 && unicode.IsLower(r) +} + +func isTestSuffix(name string) bool { + if len(name) == 0 { + // "Test" is ok. + return true + } + r, _ := utf8.DecodeRuneInString(name) + return !unicode.IsLower(r) +} + +func isTestParam(typ ast.Expr, wantType string) bool { + ptr, ok := typ.(*ast.StarExpr) + if !ok { + // Not a pointer. + return false + } + // No easy way of making sure it's a *testing.T or *testing.B: + // ensure the name of the type matches. + if name, ok := ptr.X.(*ast.Ident); ok { + return name.Name == wantType + } + if sel, ok := ptr.X.(*ast.SelectorExpr); ok { + return sel.Sel.Name == wantType + } + return false +} + +func lookup(pkg *types.Package, name string) types.Object { + if o := pkg.Scope().Lookup(name); o != nil { + return o + } + + // If this package is ".../foo_test" and it imports a package + // ".../foo", try looking in the latter package. + // This heuristic should work even on build systems that do not + // record any special link between the packages. + if basePath := strings.TrimSuffix(pkg.Path(), "_test"); basePath != pkg.Path() { + for _, imp := range pkg.Imports() { + if imp.Path() == basePath { + return imp.Scope().Lookup(name) + } + } + } + return nil +} + +func checkExample(pass *analysis.Pass, fn *ast.FuncDecl) { + fnName := fn.Name.Name + if params := fn.Type.Params; len(params.List) != 0 { + pass.Reportf(fn.Pos(), "%s should be niladic", fnName) + } + if results := fn.Type.Results; results != nil && len(results.List) != 0 { + pass.Reportf(fn.Pos(), "%s should return nothing", fnName) + } + + if fnName == "Example" { + // Nothing more to do. + return + } + + var ( + exName = strings.TrimPrefix(fnName, "Example") + elems = strings.SplitN(exName, "_", 3) + ident = elems[0] + obj = lookup(pass.Pkg, ident) + ) + if ident != "" && obj == nil { + // Check ExampleFoo and ExampleBadFoo. + pass.Reportf(fn.Pos(), "%s refers to unknown identifier: %s", fnName, ident) + // Abort since obj is absent and no subsequent checks can be performed. + return + } + if len(elems) < 2 { + // Nothing more to do. + return + } + + if ident == "" { + // Check Example_suffix and Example_BadSuffix. + if residual := strings.TrimPrefix(exName, "_"); !isExampleSuffix(residual) { + pass.Reportf(fn.Pos(), "%s has malformed example suffix: %s", fnName, residual) + } + return + } + + mmbr := elems[1] + if !isExampleSuffix(mmbr) { + // Check ExampleFoo_Method and ExampleFoo_BadMethod. + if obj, _, _ := types.LookupFieldOrMethod(obj.Type(), true, obj.Pkg(), mmbr); obj == nil { + pass.Reportf(fn.Pos(), "%s refers to unknown field or method: %s.%s", fnName, ident, mmbr) + } + } + if len(elems) == 3 && !isExampleSuffix(elems[2]) { + // Check ExampleFoo_Method_suffix and ExampleFoo_Method_Badsuffix. + pass.Reportf(fn.Pos(), "%s has malformed example suffix: %s", fnName, elems[2]) + } +} + +func checkTest(pass *analysis.Pass, fn *ast.FuncDecl, prefix string) { + // Want functions with 0 results and 1 parameter. + if fn.Type.Results != nil && len(fn.Type.Results.List) > 0 || + fn.Type.Params == nil || + len(fn.Type.Params.List) != 1 || + len(fn.Type.Params.List[0].Names) > 1 { + return + } + + // The param must look like a *testing.T or *testing.B. + if !isTestParam(fn.Type.Params.List[0].Type, prefix[:1]) { + return + } + + if !isTestSuffix(fn.Name.Name[len(prefix):]) { + pass.Reportf(fn.Pos(), "%s has malformed name: first letter after '%s' must not be lowercase", fn.Name.Name, prefix) + } +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unreachable/unreachable.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unreachable/unreachable.go new file mode 100644 index 0000000000000..19bc9c2db988b --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unreachable/unreachable.go @@ -0,0 +1,314 @@ +// Copyright 2013 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. + +// Package unreachable defines an Analyzer that checks for unreachable code. +package unreachable + +// TODO(adonovan): use the new cfg package, which is more precise. + +import ( + "go/ast" + "go/token" + "log" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `check for unreachable code + +The unreachable analyzer finds statements that execution can never reach +because they are preceded by an return statement, a call to panic, an +infinite loop, or similar constructs.` + +var Analyzer = &analysis.Analyzer{ + Name: "unreachable", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + RunDespiteErrors: true, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.FuncDecl)(nil), + (*ast.FuncLit)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + var body *ast.BlockStmt + switch n := n.(type) { + case *ast.FuncDecl: + body = n.Body + case *ast.FuncLit: + body = n.Body + } + if body == nil { + return + } + d := &deadState{ + pass: pass, + hasBreak: make(map[ast.Stmt]bool), + hasGoto: make(map[string]bool), + labels: make(map[string]ast.Stmt), + } + d.findLabels(body) + d.reachable = true + d.findDead(body) + }) + return nil, nil +} + +type deadState struct { + pass *analysis.Pass + hasBreak map[ast.Stmt]bool + hasGoto map[string]bool + labels map[string]ast.Stmt + breakTarget ast.Stmt + + reachable bool +} + +// findLabels gathers information about the labels defined and used by stmt +// and about which statements break, whether a label is involved or not. +func (d *deadState) findLabels(stmt ast.Stmt) { + switch x := stmt.(type) { + default: + log.Fatalf("%s: internal error in findLabels: unexpected statement %T", d.pass.Fset.Position(x.Pos()), x) + + case *ast.AssignStmt, + *ast.BadStmt, + *ast.DeclStmt, + *ast.DeferStmt, + *ast.EmptyStmt, + *ast.ExprStmt, + *ast.GoStmt, + *ast.IncDecStmt, + *ast.ReturnStmt, + *ast.SendStmt: + // no statements inside + + case *ast.BlockStmt: + for _, stmt := range x.List { + d.findLabels(stmt) + } + + case *ast.BranchStmt: + switch x.Tok { + case token.GOTO: + if x.Label != nil { + d.hasGoto[x.Label.Name] = true + } + + case token.BREAK: + stmt := d.breakTarget + if x.Label != nil { + stmt = d.labels[x.Label.Name] + } + if stmt != nil { + d.hasBreak[stmt] = true + } + } + + case *ast.IfStmt: + d.findLabels(x.Body) + if x.Else != nil { + d.findLabels(x.Else) + } + + case *ast.LabeledStmt: + d.labels[x.Label.Name] = x.Stmt + d.findLabels(x.Stmt) + + // These cases are all the same, but the x.Body only works + // when the specific type of x is known, so the cases cannot + // be merged. + case *ast.ForStmt: + outer := d.breakTarget + d.breakTarget = x + d.findLabels(x.Body) + d.breakTarget = outer + + case *ast.RangeStmt: + outer := d.breakTarget + d.breakTarget = x + d.findLabels(x.Body) + d.breakTarget = outer + + case *ast.SelectStmt: + outer := d.breakTarget + d.breakTarget = x + d.findLabels(x.Body) + d.breakTarget = outer + + case *ast.SwitchStmt: + outer := d.breakTarget + d.breakTarget = x + d.findLabels(x.Body) + d.breakTarget = outer + + case *ast.TypeSwitchStmt: + outer := d.breakTarget + d.breakTarget = x + d.findLabels(x.Body) + d.breakTarget = outer + + case *ast.CommClause: + for _, stmt := range x.Body { + d.findLabels(stmt) + } + + case *ast.CaseClause: + for _, stmt := range x.Body { + d.findLabels(stmt) + } + } +} + +// findDead walks the statement looking for dead code. +// If d.reachable is false on entry, stmt itself is dead. +// When findDead returns, d.reachable tells whether the +// statement following stmt is reachable. +func (d *deadState) findDead(stmt ast.Stmt) { + // Is this a labeled goto target? + // If so, assume it is reachable due to the goto. + // This is slightly conservative, in that we don't + // check that the goto is reachable, so + // L: goto L + // will not provoke a warning. + // But it's good enough. + if x, isLabel := stmt.(*ast.LabeledStmt); isLabel && d.hasGoto[x.Label.Name] { + d.reachable = true + } + + if !d.reachable { + switch stmt.(type) { + case *ast.EmptyStmt: + // do not warn about unreachable empty statements + default: + d.pass.Reportf(stmt.Pos(), "unreachable code") + d.reachable = true // silence error about next statement + } + } + + switch x := stmt.(type) { + default: + log.Fatalf("%s: internal error in findDead: unexpected statement %T", d.pass.Fset.Position(x.Pos()), x) + + case *ast.AssignStmt, + *ast.BadStmt, + *ast.DeclStmt, + *ast.DeferStmt, + *ast.EmptyStmt, + *ast.GoStmt, + *ast.IncDecStmt, + *ast.SendStmt: + // no control flow + + case *ast.BlockStmt: + for _, stmt := range x.List { + d.findDead(stmt) + } + + case *ast.BranchStmt: + switch x.Tok { + case token.BREAK, token.GOTO, token.FALLTHROUGH: + d.reachable = false + case token.CONTINUE: + // NOTE: We accept "continue" statements as terminating. + // They are not necessary in the spec definition of terminating, + // because a continue statement cannot be the final statement + // before a return. But for the more general problem of syntactically + // identifying dead code, continue redirects control flow just + // like the other terminating statements. + d.reachable = false + } + + case *ast.ExprStmt: + // Call to panic? + call, ok := x.X.(*ast.CallExpr) + if ok { + name, ok := call.Fun.(*ast.Ident) + if ok && name.Name == "panic" && name.Obj == nil { + d.reachable = false + } + } + + case *ast.ForStmt: + d.findDead(x.Body) + d.reachable = x.Cond != nil || d.hasBreak[x] + + case *ast.IfStmt: + d.findDead(x.Body) + if x.Else != nil { + r := d.reachable + d.reachable = true + d.findDead(x.Else) + d.reachable = d.reachable || r + } else { + // might not have executed if statement + d.reachable = true + } + + case *ast.LabeledStmt: + d.findDead(x.Stmt) + + case *ast.RangeStmt: + d.findDead(x.Body) + d.reachable = true + + case *ast.ReturnStmt: + d.reachable = false + + case *ast.SelectStmt: + // NOTE: Unlike switch and type switch below, we don't care + // whether a select has a default, because a select without a + // default blocks until one of the cases can run. That's different + // from a switch without a default, which behaves like it has + // a default with an empty body. + anyReachable := false + for _, comm := range x.Body.List { + d.reachable = true + for _, stmt := range comm.(*ast.CommClause).Body { + d.findDead(stmt) + } + anyReachable = anyReachable || d.reachable + } + d.reachable = anyReachable || d.hasBreak[x] + + case *ast.SwitchStmt: + anyReachable := false + hasDefault := false + for _, cas := range x.Body.List { + cc := cas.(*ast.CaseClause) + if cc.List == nil { + hasDefault = true + } + d.reachable = true + for _, stmt := range cc.Body { + d.findDead(stmt) + } + anyReachable = anyReachable || d.reachable + } + d.reachable = anyReachable || d.hasBreak[x] || !hasDefault + + case *ast.TypeSwitchStmt: + anyReachable := false + hasDefault := false + for _, cas := range x.Body.List { + cc := cas.(*ast.CaseClause) + if cc.List == nil { + hasDefault = true + } + d.reachable = true + for _, stmt := range cc.Body { + d.findDead(stmt) + } + anyReachable = anyReachable || d.reachable + } + d.reachable = anyReachable || d.hasBreak[x] || !hasDefault + } +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unsafeptr/unsafeptr.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unsafeptr/unsafeptr.go new file mode 100644 index 0000000000000..116d622b362af --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unsafeptr/unsafeptr.go @@ -0,0 +1,130 @@ +// Copyright 2014 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. + +// Package unsafeptr defines an Analyzer that checks for invalid +// conversions of uintptr to unsafe.Pointer. +package unsafeptr + +import ( + "go/ast" + "go/token" + "go/types" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/ast/inspector" +) + +const Doc = `check for invalid conversions of uintptr to unsafe.Pointer + +The unsafeptr analyzer reports likely incorrect uses of unsafe.Pointer +to convert integers to pointers. A conversion from uintptr to +unsafe.Pointer is invalid if it implies that there is a uintptr-typed +word in memory that holds a pointer value, because that word will be +invisible to stack copying and to the garbage collector.` + +var Analyzer = &analysis.Analyzer{ + Name: "unsafeptr", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + Run: run, +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.CallExpr)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + x := n.(*ast.CallExpr) + if len(x.Args) != 1 { + return + } + if hasBasicType(pass.TypesInfo, x.Fun, types.UnsafePointer) && + hasBasicType(pass.TypesInfo, x.Args[0], types.Uintptr) && + !isSafeUintptr(pass.TypesInfo, x.Args[0]) { + pass.Reportf(x.Pos(), "possible misuse of unsafe.Pointer") + } + }) + return nil, nil +} + +// isSafeUintptr reports whether x - already known to be a uintptr - +// is safe to convert to unsafe.Pointer. It is safe if x is itself derived +// directly from an unsafe.Pointer via conversion and pointer arithmetic +// or if x is the result of reflect.Value.Pointer or reflect.Value.UnsafeAddr +// or obtained from the Data field of a *reflect.SliceHeader or *reflect.StringHeader. +func isSafeUintptr(info *types.Info, x ast.Expr) bool { + switch x := x.(type) { + case *ast.ParenExpr: + return isSafeUintptr(info, x.X) + + case *ast.SelectorExpr: + switch x.Sel.Name { + case "Data": + // reflect.SliceHeader and reflect.StringHeader are okay, + // but only if they are pointing at a real slice or string. + // It's not okay to do: + // var x SliceHeader + // x.Data = uintptr(unsafe.Pointer(...)) + // ... use x ... + // p := unsafe.Pointer(x.Data) + // because in the middle the garbage collector doesn't + // see x.Data as a pointer and so x.Data may be dangling + // by the time we get to the conversion at the end. + // For now approximate by saying that *Header is okay + // but Header is not. + pt, ok := info.Types[x.X].Type.(*types.Pointer) + if ok { + t, ok := pt.Elem().(*types.Named) + if ok && t.Obj().Pkg().Path() == "reflect" { + switch t.Obj().Name() { + case "StringHeader", "SliceHeader": + return true + } + } + } + } + + case *ast.CallExpr: + switch len(x.Args) { + case 0: + // maybe call to reflect.Value.Pointer or reflect.Value.UnsafeAddr. + sel, ok := x.Fun.(*ast.SelectorExpr) + if !ok { + break + } + switch sel.Sel.Name { + case "Pointer", "UnsafeAddr": + t, ok := info.Types[sel.X].Type.(*types.Named) + if ok && t.Obj().Pkg().Path() == "reflect" && t.Obj().Name() == "Value" { + return true + } + } + + case 1: + // maybe conversion of uintptr to unsafe.Pointer + return hasBasicType(info, x.Fun, types.Uintptr) && + hasBasicType(info, x.Args[0], types.UnsafePointer) + } + + case *ast.BinaryExpr: + switch x.Op { + case token.ADD, token.SUB, token.AND_NOT: + return isSafeUintptr(info, x.X) && !isSafeUintptr(info, x.Y) + } + } + return false +} + +// hasBasicType reports whether x's type is a types.Basic with the given kind. +func hasBasicType(info *types.Info, x ast.Expr, kind types.BasicKind) bool { + t := info.Types[x].Type + if t != nil { + t = t.Underlying() + } + b, ok := t.(*types.Basic) + return ok && b.Kind() == kind +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unusedresult/unusedresult.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unusedresult/unusedresult.go new file mode 100644 index 0000000000000..76d4ab2382767 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/passes/unusedresult/unusedresult.go @@ -0,0 +1,131 @@ +// Copyright 2015 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. + +// Package unusedresult defines an analyzer that checks for unused +// results of calls to certain pure functions. +package unusedresult + +import ( + "go/ast" + "go/token" + "go/types" + "sort" + "strings" + + "golang.org/x/tools/go/analysis" + "golang.org/x/tools/go/analysis/passes/inspect" + "golang.org/x/tools/go/analysis/passes/internal/analysisutil" + "golang.org/x/tools/go/ast/inspector" +) + +// TODO(adonovan): make this analysis modular: export a mustUseResult +// fact for each function that tail-calls one of the functions that we +// check, and check those functions too. + +const Doc = `check for unused results of calls to some functions + +Some functions like fmt.Errorf return a result and have no side effects, +so it is always a mistake to discard the result. This analyzer reports +calls to certain functions in which the result of the call is ignored. + +The set of functions may be controlled using flags.` + +var Analyzer = &analysis.Analyzer{ + Name: "unusedresult", + Doc: Doc, + Requires: []*analysis.Analyzer{inspect.Analyzer}, + Run: run, +} + +// flags +var funcs, stringMethods stringSetFlag + +func init() { + // TODO(adonovan): provide a comment syntax to allow users to + // add their functions to this set using facts. + funcs.Set("errors.New,fmt.Errorf,fmt.Sprintf,fmt.Sprint,sort.Reverse") + Analyzer.Flags.Var(&funcs, "funcs", + "comma-separated list of functions whose results must be used") + + stringMethods.Set("Error,String") + Analyzer.Flags.Var(&stringMethods, "stringmethods", + "comma-separated list of names of methods of type func() string whose results must be used") +} + +func run(pass *analysis.Pass) (interface{}, error) { + inspect := pass.ResultOf[inspect.Analyzer].(*inspector.Inspector) + + nodeFilter := []ast.Node{ + (*ast.ExprStmt)(nil), + } + inspect.Preorder(nodeFilter, func(n ast.Node) { + call, ok := analysisutil.Unparen(n.(*ast.ExprStmt).X).(*ast.CallExpr) + if !ok { + return // not a call statement + } + fun := analysisutil.Unparen(call.Fun) + + if pass.TypesInfo.Types[fun].IsType() { + return // a conversion, not a call + } + + selector, ok := fun.(*ast.SelectorExpr) + if !ok { + return // neither a method call nor a qualified ident + } + + sel, ok := pass.TypesInfo.Selections[selector] + if ok && sel.Kind() == types.MethodVal { + // method (e.g. foo.String()) + obj := sel.Obj().(*types.Func) + sig := sel.Type().(*types.Signature) + if types.Identical(sig, sigNoArgsStringResult) { + if stringMethods[obj.Name()] { + pass.Reportf(call.Lparen, "result of (%s).%s call not used", + sig.Recv().Type(), obj.Name()) + } + } + } else if !ok { + // package-qualified function (e.g. fmt.Errorf) + obj := pass.TypesInfo.Uses[selector.Sel] + if obj, ok := obj.(*types.Func); ok { + qname := obj.Pkg().Path() + "." + obj.Name() + if funcs[qname] { + pass.Reportf(call.Lparen, "result of %v call not used", qname) + } + } + } + }) + return nil, nil +} + +// func() string +var sigNoArgsStringResult = types.NewSignature(nil, nil, + types.NewTuple(types.NewVar(token.NoPos, nil, "", types.Typ[types.String])), + false) + +type stringSetFlag map[string]bool + +func (ss *stringSetFlag) String() string { + var items []string + for item := range *ss { + items = append(items, item) + } + sort.Strings(items) + return strings.Join(items, ",") +} + +func (ss *stringSetFlag) Set(s string) error { + m := make(map[string]bool) // clobber previous value + if s != "" { + for _, name := range strings.Split(s, ",") { + if name == "" { + continue // TODO: report error? proceed? + } + m[name] = true + } + } + *ss = m + return nil +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/analysis/validate.go b/src/cmd/vendor/golang.org/x/tools/go/analysis/validate.go new file mode 100644 index 0000000000000..6e6cf4984fedc --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/analysis/validate.go @@ -0,0 +1,104 @@ +package analysis + +import ( + "fmt" + "reflect" + "unicode" +) + +// Validate reports an error if any of the analyzers are misconfigured. +// Checks include: +// that the name is a valid identifier; +// that analyzer names are unique; +// that the Requires graph is acylic; +// that analyzer fact types are unique; +// that each fact type is a pointer. +func Validate(analyzers []*Analyzer) error { + names := make(map[string]bool) + + // Map each fact type to its sole generating analyzer. + factTypes := make(map[reflect.Type]*Analyzer) + + // Traverse the Requires graph, depth first. + const ( + white = iota + grey + black + finished + ) + color := make(map[*Analyzer]uint8) + var visit func(a *Analyzer) error + visit = func(a *Analyzer) error { + if a == nil { + return fmt.Errorf("nil *Analyzer") + } + if color[a] == white { + color[a] = grey + + // names + if !validIdent(a.Name) { + return fmt.Errorf("invalid analyzer name %q", a) + } + if names[a.Name] { + return fmt.Errorf("duplicate analyzer name %q", a) + } + names[a.Name] = true + + if a.Doc == "" { + return fmt.Errorf("analyzer %q is undocumented", a) + } + + // fact types + for _, f := range a.FactTypes { + if f == nil { + return fmt.Errorf("analyzer %s has nil FactType", a) + } + t := reflect.TypeOf(f) + if prev := factTypes[t]; prev != nil { + return fmt.Errorf("fact type %s registered by two analyzers: %v, %v", + t, a, prev) + } + if t.Kind() != reflect.Ptr { + return fmt.Errorf("%s: fact type %s is not a pointer", a, t) + } + factTypes[t] = a + } + + // recursion + for i, req := range a.Requires { + if err := visit(req); err != nil { + return fmt.Errorf("%s.Requires[%d]: %v", a.Name, i, err) + } + } + color[a] = black + } + + return nil + } + for _, a := range analyzers { + if err := visit(a); err != nil { + return err + } + } + + // Reject duplicates among analyzers. + // Precondition: color[a] == black. + // Postcondition: color[a] == finished. + for _, a := range analyzers { + if color[a] == finished { + return fmt.Errorf("duplicate analyzer: %s", a.Name) + } + color[a] = finished + } + + return nil +} + +func validIdent(name string) bool { + for i, r := range name { + if !(r == '_' || unicode.IsLetter(r) || i > 0 && unicode.IsDigit(r)) { + return false + } + } + return name != "" +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/enclosing.go b/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/enclosing.go new file mode 100644 index 0000000000000..6b7052b892ca0 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/enclosing.go @@ -0,0 +1,627 @@ +// Copyright 2013 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. + +package astutil + +// This file defines utilities for working with source positions. + +import ( + "fmt" + "go/ast" + "go/token" + "sort" +) + +// PathEnclosingInterval returns the node that encloses the source +// interval [start, end), and all its ancestors up to the AST root. +// +// The definition of "enclosing" used by this function considers +// additional whitespace abutting a node to be enclosed by it. +// In this example: +// +// z := x + y // add them +// <-A-> +// <----B-----> +// +// the ast.BinaryExpr(+) node is considered to enclose interval B +// even though its [Pos()..End()) is actually only interval A. +// This behaviour makes user interfaces more tolerant of imperfect +// input. +// +// This function treats tokens as nodes, though they are not included +// in the result. e.g. PathEnclosingInterval("+") returns the +// enclosing ast.BinaryExpr("x + y"). +// +// If start==end, the 1-char interval following start is used instead. +// +// The 'exact' result is true if the interval contains only path[0] +// and perhaps some adjacent whitespace. It is false if the interval +// overlaps multiple children of path[0], or if it contains only +// interior whitespace of path[0]. +// In this example: +// +// z := x + y // add them +// <--C--> <---E--> +// ^ +// D +// +// intervals C, D and E are inexact. C is contained by the +// z-assignment statement, because it spans three of its children (:=, +// x, +). So too is the 1-char interval D, because it contains only +// interior whitespace of the assignment. E is considered interior +// whitespace of the BlockStmt containing the assignment. +// +// Precondition: [start, end) both lie within the same file as root. +// TODO(adonovan): return (nil, false) in this case and remove precond. +// Requires FileSet; see loader.tokenFileContainsPos. +// +// Postcondition: path is never nil; it always contains at least 'root'. +// +func PathEnclosingInterval(root *ast.File, start, end token.Pos) (path []ast.Node, exact bool) { + // fmt.Printf("EnclosingInterval %d %d\n", start, end) // debugging + + // Precondition: node.[Pos..End) and adjoining whitespace contain [start, end). + var visit func(node ast.Node) bool + visit = func(node ast.Node) bool { + path = append(path, node) + + nodePos := node.Pos() + nodeEnd := node.End() + + // fmt.Printf("visit(%T, %d, %d)\n", node, nodePos, nodeEnd) // debugging + + // Intersect [start, end) with interval of node. + if start < nodePos { + start = nodePos + } + if end > nodeEnd { + end = nodeEnd + } + + // Find sole child that contains [start, end). + children := childrenOf(node) + l := len(children) + for i, child := range children { + // [childPos, childEnd) is unaugmented interval of child. + childPos := child.Pos() + childEnd := child.End() + + // [augPos, augEnd) is whitespace-augmented interval of child. + augPos := childPos + augEnd := childEnd + if i > 0 { + augPos = children[i-1].End() // start of preceding whitespace + } + if i < l-1 { + nextChildPos := children[i+1].Pos() + // Does [start, end) lie between child and next child? + if start >= augEnd && end <= nextChildPos { + return false // inexact match + } + augEnd = nextChildPos // end of following whitespace + } + + // fmt.Printf("\tchild %d: [%d..%d)\tcontains interval [%d..%d)?\n", + // i, augPos, augEnd, start, end) // debugging + + // Does augmented child strictly contain [start, end)? + if augPos <= start && end <= augEnd { + _, isToken := child.(tokenNode) + return isToken || visit(child) + } + + // Does [start, end) overlap multiple children? + // i.e. left-augmented child contains start + // but LR-augmented child does not contain end. + if start < childEnd && end > augEnd { + break + } + } + + // No single child contained [start, end), + // so node is the result. Is it exact? + + // (It's tempting to put this condition before the + // child loop, but it gives the wrong result in the + // case where a node (e.g. ExprStmt) and its sole + // child have equal intervals.) + if start == nodePos && end == nodeEnd { + return true // exact match + } + + return false // inexact: overlaps multiple children + } + + if start > end { + start, end = end, start + } + + if start < root.End() && end > root.Pos() { + if start == end { + end = start + 1 // empty interval => interval of size 1 + } + exact = visit(root) + + // Reverse the path: + for i, l := 0, len(path); i < l/2; i++ { + path[i], path[l-1-i] = path[l-1-i], path[i] + } + } else { + // Selection lies within whitespace preceding the + // first (or following the last) declaration in the file. + // The result nonetheless always includes the ast.File. + path = append(path, root) + } + + return +} + +// tokenNode is a dummy implementation of ast.Node for a single token. +// They are used transiently by PathEnclosingInterval but never escape +// this package. +// +type tokenNode struct { + pos token.Pos + end token.Pos +} + +func (n tokenNode) Pos() token.Pos { + return n.pos +} + +func (n tokenNode) End() token.Pos { + return n.end +} + +func tok(pos token.Pos, len int) ast.Node { + return tokenNode{pos, pos + token.Pos(len)} +} + +// childrenOf returns the direct non-nil children of ast.Node n. +// It may include fake ast.Node implementations for bare tokens. +// it is not safe to call (e.g.) ast.Walk on such nodes. +// +func childrenOf(n ast.Node) []ast.Node { + var children []ast.Node + + // First add nodes for all true subtrees. + ast.Inspect(n, func(node ast.Node) bool { + if node == n { // push n + return true // recur + } + if node != nil { // push child + children = append(children, node) + } + return false // no recursion + }) + + // Then add fake Nodes for bare tokens. + switch n := n.(type) { + case *ast.ArrayType: + children = append(children, + tok(n.Lbrack, len("[")), + tok(n.Elt.End(), len("]"))) + + case *ast.AssignStmt: + children = append(children, + tok(n.TokPos, len(n.Tok.String()))) + + case *ast.BasicLit: + children = append(children, + tok(n.ValuePos, len(n.Value))) + + case *ast.BinaryExpr: + children = append(children, tok(n.OpPos, len(n.Op.String()))) + + case *ast.BlockStmt: + children = append(children, + tok(n.Lbrace, len("{")), + tok(n.Rbrace, len("}"))) + + case *ast.BranchStmt: + children = append(children, + tok(n.TokPos, len(n.Tok.String()))) + + case *ast.CallExpr: + children = append(children, + tok(n.Lparen, len("(")), + tok(n.Rparen, len(")"))) + if n.Ellipsis != 0 { + children = append(children, tok(n.Ellipsis, len("..."))) + } + + case *ast.CaseClause: + if n.List == nil { + children = append(children, + tok(n.Case, len("default"))) + } else { + children = append(children, + tok(n.Case, len("case"))) + } + children = append(children, tok(n.Colon, len(":"))) + + case *ast.ChanType: + switch n.Dir { + case ast.RECV: + children = append(children, tok(n.Begin, len("<-chan"))) + case ast.SEND: + children = append(children, tok(n.Begin, len("chan<-"))) + case ast.RECV | ast.SEND: + children = append(children, tok(n.Begin, len("chan"))) + } + + case *ast.CommClause: + if n.Comm == nil { + children = append(children, + tok(n.Case, len("default"))) + } else { + children = append(children, + tok(n.Case, len("case"))) + } + children = append(children, tok(n.Colon, len(":"))) + + case *ast.Comment: + // nop + + case *ast.CommentGroup: + // nop + + case *ast.CompositeLit: + children = append(children, + tok(n.Lbrace, len("{")), + tok(n.Rbrace, len("{"))) + + case *ast.DeclStmt: + // nop + + case *ast.DeferStmt: + children = append(children, + tok(n.Defer, len("defer"))) + + case *ast.Ellipsis: + children = append(children, + tok(n.Ellipsis, len("..."))) + + case *ast.EmptyStmt: + // nop + + case *ast.ExprStmt: + // nop + + case *ast.Field: + // TODO(adonovan): Field.{Doc,Comment,Tag}? + + case *ast.FieldList: + children = append(children, + tok(n.Opening, len("(")), + tok(n.Closing, len(")"))) + + case *ast.File: + // TODO test: Doc + children = append(children, + tok(n.Package, len("package"))) + + case *ast.ForStmt: + children = append(children, + tok(n.For, len("for"))) + + case *ast.FuncDecl: + // TODO(adonovan): FuncDecl.Comment? + + // Uniquely, FuncDecl breaks the invariant that + // preorder traversal yields tokens in lexical order: + // in fact, FuncDecl.Recv precedes FuncDecl.Type.Func. + // + // As a workaround, we inline the case for FuncType + // here and order things correctly. + // + children = nil // discard ast.Walk(FuncDecl) info subtrees + children = append(children, tok(n.Type.Func, len("func"))) + if n.Recv != nil { + children = append(children, n.Recv) + } + children = append(children, n.Name) + if n.Type.Params != nil { + children = append(children, n.Type.Params) + } + if n.Type.Results != nil { + children = append(children, n.Type.Results) + } + if n.Body != nil { + children = append(children, n.Body) + } + + case *ast.FuncLit: + // nop + + case *ast.FuncType: + if n.Func != 0 { + children = append(children, + tok(n.Func, len("func"))) + } + + case *ast.GenDecl: + children = append(children, + tok(n.TokPos, len(n.Tok.String()))) + if n.Lparen != 0 { + children = append(children, + tok(n.Lparen, len("(")), + tok(n.Rparen, len(")"))) + } + + case *ast.GoStmt: + children = append(children, + tok(n.Go, len("go"))) + + case *ast.Ident: + children = append(children, + tok(n.NamePos, len(n.Name))) + + case *ast.IfStmt: + children = append(children, + tok(n.If, len("if"))) + + case *ast.ImportSpec: + // TODO(adonovan): ImportSpec.{Doc,EndPos}? + + case *ast.IncDecStmt: + children = append(children, + tok(n.TokPos, len(n.Tok.String()))) + + case *ast.IndexExpr: + children = append(children, + tok(n.Lbrack, len("{")), + tok(n.Rbrack, len("}"))) + + case *ast.InterfaceType: + children = append(children, + tok(n.Interface, len("interface"))) + + case *ast.KeyValueExpr: + children = append(children, + tok(n.Colon, len(":"))) + + case *ast.LabeledStmt: + children = append(children, + tok(n.Colon, len(":"))) + + case *ast.MapType: + children = append(children, + tok(n.Map, len("map"))) + + case *ast.ParenExpr: + children = append(children, + tok(n.Lparen, len("(")), + tok(n.Rparen, len(")"))) + + case *ast.RangeStmt: + children = append(children, + tok(n.For, len("for")), + tok(n.TokPos, len(n.Tok.String()))) + + case *ast.ReturnStmt: + children = append(children, + tok(n.Return, len("return"))) + + case *ast.SelectStmt: + children = append(children, + tok(n.Select, len("select"))) + + case *ast.SelectorExpr: + // nop + + case *ast.SendStmt: + children = append(children, + tok(n.Arrow, len("<-"))) + + case *ast.SliceExpr: + children = append(children, + tok(n.Lbrack, len("[")), + tok(n.Rbrack, len("]"))) + + case *ast.StarExpr: + children = append(children, tok(n.Star, len("*"))) + + case *ast.StructType: + children = append(children, tok(n.Struct, len("struct"))) + + case *ast.SwitchStmt: + children = append(children, tok(n.Switch, len("switch"))) + + case *ast.TypeAssertExpr: + children = append(children, + tok(n.Lparen-1, len(".")), + tok(n.Lparen, len("(")), + tok(n.Rparen, len(")"))) + + case *ast.TypeSpec: + // TODO(adonovan): TypeSpec.{Doc,Comment}? + + case *ast.TypeSwitchStmt: + children = append(children, tok(n.Switch, len("switch"))) + + case *ast.UnaryExpr: + children = append(children, tok(n.OpPos, len(n.Op.String()))) + + case *ast.ValueSpec: + // TODO(adonovan): ValueSpec.{Doc,Comment}? + + case *ast.BadDecl, *ast.BadExpr, *ast.BadStmt: + // nop + } + + // TODO(adonovan): opt: merge the logic of ast.Inspect() into + // the switch above so we can make interleaved callbacks for + // both Nodes and Tokens in the right order and avoid the need + // to sort. + sort.Sort(byPos(children)) + + return children +} + +type byPos []ast.Node + +func (sl byPos) Len() int { + return len(sl) +} +func (sl byPos) Less(i, j int) bool { + return sl[i].Pos() < sl[j].Pos() +} +func (sl byPos) Swap(i, j int) { + sl[i], sl[j] = sl[j], sl[i] +} + +// NodeDescription returns a description of the concrete type of n suitable +// for a user interface. +// +// TODO(adonovan): in some cases (e.g. Field, FieldList, Ident, +// StarExpr) we could be much more specific given the path to the AST +// root. Perhaps we should do that. +// +func NodeDescription(n ast.Node) string { + switch n := n.(type) { + case *ast.ArrayType: + return "array type" + case *ast.AssignStmt: + return "assignment" + case *ast.BadDecl: + return "bad declaration" + case *ast.BadExpr: + return "bad expression" + case *ast.BadStmt: + return "bad statement" + case *ast.BasicLit: + return "basic literal" + case *ast.BinaryExpr: + return fmt.Sprintf("binary %s operation", n.Op) + case *ast.BlockStmt: + return "block" + case *ast.BranchStmt: + switch n.Tok { + case token.BREAK: + return "break statement" + case token.CONTINUE: + return "continue statement" + case token.GOTO: + return "goto statement" + case token.FALLTHROUGH: + return "fall-through statement" + } + case *ast.CallExpr: + if len(n.Args) == 1 && !n.Ellipsis.IsValid() { + return "function call (or conversion)" + } + return "function call" + case *ast.CaseClause: + return "case clause" + case *ast.ChanType: + return "channel type" + case *ast.CommClause: + return "communication clause" + case *ast.Comment: + return "comment" + case *ast.CommentGroup: + return "comment group" + case *ast.CompositeLit: + return "composite literal" + case *ast.DeclStmt: + return NodeDescription(n.Decl) + " statement" + case *ast.DeferStmt: + return "defer statement" + case *ast.Ellipsis: + return "ellipsis" + case *ast.EmptyStmt: + return "empty statement" + case *ast.ExprStmt: + return "expression statement" + case *ast.Field: + // Can be any of these: + // struct {x, y int} -- struct field(s) + // struct {T} -- anon struct field + // interface {I} -- interface embedding + // interface {f()} -- interface method + // func (A) func(B) C -- receiver, param(s), result(s) + return "field/method/parameter" + case *ast.FieldList: + return "field/method/parameter list" + case *ast.File: + return "source file" + case *ast.ForStmt: + return "for loop" + case *ast.FuncDecl: + return "function declaration" + case *ast.FuncLit: + return "function literal" + case *ast.FuncType: + return "function type" + case *ast.GenDecl: + switch n.Tok { + case token.IMPORT: + return "import declaration" + case token.CONST: + return "constant declaration" + case token.TYPE: + return "type declaration" + case token.VAR: + return "variable declaration" + } + case *ast.GoStmt: + return "go statement" + case *ast.Ident: + return "identifier" + case *ast.IfStmt: + return "if statement" + case *ast.ImportSpec: + return "import specification" + case *ast.IncDecStmt: + if n.Tok == token.INC { + return "increment statement" + } + return "decrement statement" + case *ast.IndexExpr: + return "index expression" + case *ast.InterfaceType: + return "interface type" + case *ast.KeyValueExpr: + return "key/value association" + case *ast.LabeledStmt: + return "statement label" + case *ast.MapType: + return "map type" + case *ast.Package: + return "package" + case *ast.ParenExpr: + return "parenthesized " + NodeDescription(n.X) + case *ast.RangeStmt: + return "range loop" + case *ast.ReturnStmt: + return "return statement" + case *ast.SelectStmt: + return "select statement" + case *ast.SelectorExpr: + return "selector" + case *ast.SendStmt: + return "channel send" + case *ast.SliceExpr: + return "slice expression" + case *ast.StarExpr: + return "*-operation" // load/store expr or pointer type + case *ast.StructType: + return "struct type" + case *ast.SwitchStmt: + return "switch statement" + case *ast.TypeAssertExpr: + return "type assertion" + case *ast.TypeSpec: + return "type specification" + case *ast.TypeSwitchStmt: + return "type switch" + case *ast.UnaryExpr: + return fmt.Sprintf("unary %s operation", n.Op) + case *ast.ValueSpec: + return "value specification" + + } + panic(fmt.Sprintf("unexpected node type: %T", n)) +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/imports.go b/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/imports.go new file mode 100644 index 0000000000000..04ad6795d921e --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/imports.go @@ -0,0 +1,471 @@ +// Copyright 2013 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. + +// Package astutil contains common utilities for working with the Go AST. +package astutil // import "golang.org/x/tools/go/ast/astutil" + +import ( + "fmt" + "go/ast" + "go/token" + "strconv" + "strings" +) + +// AddImport adds the import path to the file f, if absent. +func AddImport(fset *token.FileSet, f *ast.File, ipath string) (added bool) { + return AddNamedImport(fset, f, "", ipath) +} + +// AddNamedImport adds the import path to the file f, if absent. +// If name is not empty, it is used to rename the import. +// +// For example, calling +// AddNamedImport(fset, f, "pathpkg", "path") +// adds +// import pathpkg "path" +func AddNamedImport(fset *token.FileSet, f *ast.File, name, ipath string) (added bool) { + if imports(f, ipath) { + return false + } + + newImport := &ast.ImportSpec{ + Path: &ast.BasicLit{ + Kind: token.STRING, + Value: strconv.Quote(ipath), + }, + } + if name != "" { + newImport.Name = &ast.Ident{Name: name} + } + + // Find an import decl to add to. + // The goal is to find an existing import + // whose import path has the longest shared + // prefix with ipath. + var ( + bestMatch = -1 // length of longest shared prefix + lastImport = -1 // index in f.Decls of the file's final import decl + impDecl *ast.GenDecl // import decl containing the best match + impIndex = -1 // spec index in impDecl containing the best match + + isThirdPartyPath = isThirdParty(ipath) + ) + for i, decl := range f.Decls { + gen, ok := decl.(*ast.GenDecl) + if ok && gen.Tok == token.IMPORT { + lastImport = i + // Do not add to import "C", to avoid disrupting the + // association with its doc comment, breaking cgo. + if declImports(gen, "C") { + continue + } + + // Match an empty import decl if that's all that is available. + if len(gen.Specs) == 0 && bestMatch == -1 { + impDecl = gen + } + + // Compute longest shared prefix with imports in this group and find best + // matched import spec. + // 1. Always prefer import spec with longest shared prefix. + // 2. While match length is 0, + // - for stdlib package: prefer first import spec. + // - for third party package: prefer first third party import spec. + // We cannot use last import spec as best match for third party package + // because grouped imports are usually placed last by goimports -local + // flag. + // See issue #19190. + seenAnyThirdParty := false + for j, spec := range gen.Specs { + impspec := spec.(*ast.ImportSpec) + p := importPath(impspec) + n := matchLen(p, ipath) + if n > bestMatch || (bestMatch == 0 && !seenAnyThirdParty && isThirdPartyPath) { + bestMatch = n + impDecl = gen + impIndex = j + } + seenAnyThirdParty = seenAnyThirdParty || isThirdParty(p) + } + } + } + + // If no import decl found, add one after the last import. + if impDecl == nil { + impDecl = &ast.GenDecl{ + Tok: token.IMPORT, + } + if lastImport >= 0 { + impDecl.TokPos = f.Decls[lastImport].End() + } else { + // There are no existing imports. + // Our new import, preceded by a blank line, goes after the package declaration + // and after the comment, if any, that starts on the same line as the + // package declaration. + impDecl.TokPos = f.Package + + file := fset.File(f.Package) + pkgLine := file.Line(f.Package) + for _, c := range f.Comments { + if file.Line(c.Pos()) > pkgLine { + break + } + // +2 for a blank line + impDecl.TokPos = c.End() + 2 + } + } + f.Decls = append(f.Decls, nil) + copy(f.Decls[lastImport+2:], f.Decls[lastImport+1:]) + f.Decls[lastImport+1] = impDecl + } + + // Insert new import at insertAt. + insertAt := 0 + if impIndex >= 0 { + // insert after the found import + insertAt = impIndex + 1 + } + impDecl.Specs = append(impDecl.Specs, nil) + copy(impDecl.Specs[insertAt+1:], impDecl.Specs[insertAt:]) + impDecl.Specs[insertAt] = newImport + pos := impDecl.Pos() + if insertAt > 0 { + // If there is a comment after an existing import, preserve the comment + // position by adding the new import after the comment. + if spec, ok := impDecl.Specs[insertAt-1].(*ast.ImportSpec); ok && spec.Comment != nil { + pos = spec.Comment.End() + } else { + // Assign same position as the previous import, + // so that the sorter sees it as being in the same block. + pos = impDecl.Specs[insertAt-1].Pos() + } + } + if newImport.Name != nil { + newImport.Name.NamePos = pos + } + newImport.Path.ValuePos = pos + newImport.EndPos = pos + + // Clean up parens. impDecl contains at least one spec. + if len(impDecl.Specs) == 1 { + // Remove unneeded parens. + impDecl.Lparen = token.NoPos + } else if !impDecl.Lparen.IsValid() { + // impDecl needs parens added. + impDecl.Lparen = impDecl.Specs[0].Pos() + } + + f.Imports = append(f.Imports, newImport) + + if len(f.Decls) <= 1 { + return true + } + + // Merge all the import declarations into the first one. + var first *ast.GenDecl + for i := 0; i < len(f.Decls); i++ { + decl := f.Decls[i] + gen, ok := decl.(*ast.GenDecl) + if !ok || gen.Tok != token.IMPORT || declImports(gen, "C") { + continue + } + if first == nil { + first = gen + continue // Don't touch the first one. + } + // We now know there is more than one package in this import + // declaration. Ensure that it ends up parenthesized. + first.Lparen = first.Pos() + // Move the imports of the other import declaration to the first one. + for _, spec := range gen.Specs { + spec.(*ast.ImportSpec).Path.ValuePos = first.Pos() + first.Specs = append(first.Specs, spec) + } + f.Decls = append(f.Decls[:i], f.Decls[i+1:]...) + i-- + } + + return true +} + +func isThirdParty(importPath string) bool { + // Third party package import path usually contains "." (".com", ".org", ...) + // This logic is taken from golang.org/x/tools/imports package. + return strings.Contains(importPath, ".") +} + +// DeleteImport deletes the import path from the file f, if present. +func DeleteImport(fset *token.FileSet, f *ast.File, path string) (deleted bool) { + return DeleteNamedImport(fset, f, "", path) +} + +// DeleteNamedImport deletes the import with the given name and path from the file f, if present. +func DeleteNamedImport(fset *token.FileSet, f *ast.File, name, path string) (deleted bool) { + var delspecs []*ast.ImportSpec + var delcomments []*ast.CommentGroup + + // Find the import nodes that import path, if any. + for i := 0; i < len(f.Decls); i++ { + decl := f.Decls[i] + gen, ok := decl.(*ast.GenDecl) + if !ok || gen.Tok != token.IMPORT { + continue + } + for j := 0; j < len(gen.Specs); j++ { + spec := gen.Specs[j] + impspec := spec.(*ast.ImportSpec) + if impspec.Name == nil && name != "" { + continue + } + if impspec.Name != nil && impspec.Name.Name != name { + continue + } + if importPath(impspec) != path { + continue + } + + // We found an import spec that imports path. + // Delete it. + delspecs = append(delspecs, impspec) + deleted = true + copy(gen.Specs[j:], gen.Specs[j+1:]) + gen.Specs = gen.Specs[:len(gen.Specs)-1] + + // If this was the last import spec in this decl, + // delete the decl, too. + if len(gen.Specs) == 0 { + copy(f.Decls[i:], f.Decls[i+1:]) + f.Decls = f.Decls[:len(f.Decls)-1] + i-- + break + } else if len(gen.Specs) == 1 { + if impspec.Doc != nil { + delcomments = append(delcomments, impspec.Doc) + } + if impspec.Comment != nil { + delcomments = append(delcomments, impspec.Comment) + } + for _, cg := range f.Comments { + // Found comment on the same line as the import spec. + if cg.End() < impspec.Pos() && fset.Position(cg.End()).Line == fset.Position(impspec.Pos()).Line { + delcomments = append(delcomments, cg) + break + } + } + + spec := gen.Specs[0].(*ast.ImportSpec) + + // Move the documentation right after the import decl. + if spec.Doc != nil { + for fset.Position(gen.TokPos).Line+1 < fset.Position(spec.Doc.Pos()).Line { + fset.File(gen.TokPos).MergeLine(fset.Position(gen.TokPos).Line) + } + } + for _, cg := range f.Comments { + if cg.End() < spec.Pos() && fset.Position(cg.End()).Line == fset.Position(spec.Pos()).Line { + for fset.Position(gen.TokPos).Line+1 < fset.Position(spec.Pos()).Line { + fset.File(gen.TokPos).MergeLine(fset.Position(gen.TokPos).Line) + } + break + } + } + } + if j > 0 { + lastImpspec := gen.Specs[j-1].(*ast.ImportSpec) + lastLine := fset.Position(lastImpspec.Path.ValuePos).Line + line := fset.Position(impspec.Path.ValuePos).Line + + // We deleted an entry but now there may be + // a blank line-sized hole where the import was. + if line-lastLine > 1 { + // There was a blank line immediately preceding the deleted import, + // so there's no need to close the hole. + // Do nothing. + } else if line != fset.File(gen.Rparen).LineCount() { + // There was no blank line. Close the hole. + fset.File(gen.Rparen).MergeLine(line) + } + } + j-- + } + } + + // Delete imports from f.Imports. + for i := 0; i < len(f.Imports); i++ { + imp := f.Imports[i] + for j, del := range delspecs { + if imp == del { + copy(f.Imports[i:], f.Imports[i+1:]) + f.Imports = f.Imports[:len(f.Imports)-1] + copy(delspecs[j:], delspecs[j+1:]) + delspecs = delspecs[:len(delspecs)-1] + i-- + break + } + } + } + + // Delete comments from f.Comments. + for i := 0; i < len(f.Comments); i++ { + cg := f.Comments[i] + for j, del := range delcomments { + if cg == del { + copy(f.Comments[i:], f.Comments[i+1:]) + f.Comments = f.Comments[:len(f.Comments)-1] + copy(delcomments[j:], delcomments[j+1:]) + delcomments = delcomments[:len(delcomments)-1] + i-- + break + } + } + } + + if len(delspecs) > 0 { + panic(fmt.Sprintf("deleted specs from Decls but not Imports: %v", delspecs)) + } + + return +} + +// RewriteImport rewrites any import of path oldPath to path newPath. +func RewriteImport(fset *token.FileSet, f *ast.File, oldPath, newPath string) (rewrote bool) { + for _, imp := range f.Imports { + if importPath(imp) == oldPath { + rewrote = true + // record old End, because the default is to compute + // it using the length of imp.Path.Value. + imp.EndPos = imp.End() + imp.Path.Value = strconv.Quote(newPath) + } + } + return +} + +// UsesImport reports whether a given import is used. +func UsesImport(f *ast.File, path string) (used bool) { + spec := importSpec(f, path) + if spec == nil { + return + } + + name := spec.Name.String() + switch name { + case "": + // If the package name is not explicitly specified, + // make an educated guess. This is not guaranteed to be correct. + lastSlash := strings.LastIndex(path, "/") + if lastSlash == -1 { + name = path + } else { + name = path[lastSlash+1:] + } + case "_", ".": + // Not sure if this import is used - err on the side of caution. + return true + } + + ast.Walk(visitFn(func(n ast.Node) { + sel, ok := n.(*ast.SelectorExpr) + if ok && isTopName(sel.X, name) { + used = true + } + }), f) + + return +} + +type visitFn func(node ast.Node) + +func (fn visitFn) Visit(node ast.Node) ast.Visitor { + fn(node) + return fn +} + +// imports returns true if f imports path. +func imports(f *ast.File, path string) bool { + return importSpec(f, path) != nil +} + +// importSpec returns the import spec if f imports path, +// or nil otherwise. +func importSpec(f *ast.File, path string) *ast.ImportSpec { + for _, s := range f.Imports { + if importPath(s) == path { + return s + } + } + return nil +} + +// importPath returns the unquoted import path of s, +// or "" if the path is not properly quoted. +func importPath(s *ast.ImportSpec) string { + t, err := strconv.Unquote(s.Path.Value) + if err == nil { + return t + } + return "" +} + +// declImports reports whether gen contains an import of path. +func declImports(gen *ast.GenDecl, path string) bool { + if gen.Tok != token.IMPORT { + return false + } + for _, spec := range gen.Specs { + impspec := spec.(*ast.ImportSpec) + if importPath(impspec) == path { + return true + } + } + return false +} + +// matchLen returns the length of the longest path segment prefix shared by x and y. +func matchLen(x, y string) int { + n := 0 + for i := 0; i < len(x) && i < len(y) && x[i] == y[i]; i++ { + if x[i] == '/' { + n++ + } + } + return n +} + +// isTopName returns true if n is a top-level unresolved identifier with the given name. +func isTopName(n ast.Expr, name string) bool { + id, ok := n.(*ast.Ident) + return ok && id.Name == name && id.Obj == nil +} + +// Imports returns the file imports grouped by paragraph. +func Imports(fset *token.FileSet, f *ast.File) [][]*ast.ImportSpec { + var groups [][]*ast.ImportSpec + + for _, decl := range f.Decls { + genDecl, ok := decl.(*ast.GenDecl) + if !ok || genDecl.Tok != token.IMPORT { + break + } + + group := []*ast.ImportSpec{} + + var lastLine int + for _, spec := range genDecl.Specs { + importSpec := spec.(*ast.ImportSpec) + pos := importSpec.Path.ValuePos + line := fset.Position(pos).Line + if lastLine > 0 && pos > 0 && line-lastLine > 1 { + groups = append(groups, group) + group = []*ast.ImportSpec{} + } + group = append(group, importSpec) + lastLine = line + } + groups = append(groups, group) + } + + return groups +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go b/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go new file mode 100644 index 0000000000000..cf72ea990bda2 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/rewrite.go @@ -0,0 +1,477 @@ +// 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. + +package astutil + +import ( + "fmt" + "go/ast" + "reflect" + "sort" +) + +// An ApplyFunc is invoked by Apply for each node n, even if n is nil, +// before and/or after the node's children, using a Cursor describing +// the current node and providing operations on it. +// +// The return value of ApplyFunc controls the syntax tree traversal. +// See Apply for details. +type ApplyFunc func(*Cursor) bool + +// Apply traverses a syntax tree recursively, starting with root, +// and calling pre and post for each node as described below. +// Apply returns the syntax tree, possibly modified. +// +// If pre is not nil, it is called for each node before the node's +// children are traversed (pre-order). If pre returns false, no +// children are traversed, and post is not called for that node. +// +// If post is not nil, and a prior call of pre didn't return false, +// post is called for each node after its children are traversed +// (post-order). If post returns false, traversal is terminated and +// Apply returns immediately. +// +// Only fields that refer to AST nodes are considered children; +// i.e., token.Pos, Scopes, Objects, and fields of basic types +// (strings, etc.) are ignored. +// +// Children are traversed in the order in which they appear in the +// respective node's struct definition. A package's files are +// traversed in the filenames' alphabetical order. +// +func Apply(root ast.Node, pre, post ApplyFunc) (result ast.Node) { + parent := &struct{ ast.Node }{root} + defer func() { + if r := recover(); r != nil && r != abort { + panic(r) + } + result = parent.Node + }() + a := &application{pre: pre, post: post} + a.apply(parent, "Node", nil, root) + return +} + +var abort = new(int) // singleton, to signal termination of Apply + +// A Cursor describes a node encountered during Apply. +// Information about the node and its parent is available +// from the Node, Parent, Name, and Index methods. +// +// If p is a variable of type and value of the current parent node +// c.Parent(), and f is the field identifier with name c.Name(), +// the following invariants hold: +// +// p.f == c.Node() if c.Index() < 0 +// p.f[c.Index()] == c.Node() if c.Index() >= 0 +// +// The methods Replace, Delete, InsertBefore, and InsertAfter +// can be used to change the AST without disrupting Apply. +type Cursor struct { + parent ast.Node + name string + iter *iterator // valid if non-nil + node ast.Node +} + +// Node returns the current Node. +func (c *Cursor) Node() ast.Node { return c.node } + +// Parent returns the parent of the current Node. +func (c *Cursor) Parent() ast.Node { return c.parent } + +// Name returns the name of the parent Node field that contains the current Node. +// If the parent is a *ast.Package and the current Node is a *ast.File, Name returns +// the filename for the current Node. +func (c *Cursor) Name() string { return c.name } + +// Index reports the index >= 0 of the current Node in the slice of Nodes that +// contains it, or a value < 0 if the current Node is not part of a slice. +// The index of the current node changes if InsertBefore is called while +// processing the current node. +func (c *Cursor) Index() int { + if c.iter != nil { + return c.iter.index + } + return -1 +} + +// field returns the current node's parent field value. +func (c *Cursor) field() reflect.Value { + return reflect.Indirect(reflect.ValueOf(c.parent)).FieldByName(c.name) +} + +// Replace replaces the current Node with n. +// The replacement node is not walked by Apply. +func (c *Cursor) Replace(n ast.Node) { + if _, ok := c.node.(*ast.File); ok { + file, ok := n.(*ast.File) + if !ok { + panic("attempt to replace *ast.File with non-*ast.File") + } + c.parent.(*ast.Package).Files[c.name] = file + return + } + + v := c.field() + if i := c.Index(); i >= 0 { + v = v.Index(i) + } + v.Set(reflect.ValueOf(n)) +} + +// Delete deletes the current Node from its containing slice. +// If the current Node is not part of a slice, Delete panics. +// As a special case, if the current node is a package file, +// Delete removes it from the package's Files map. +func (c *Cursor) Delete() { + if _, ok := c.node.(*ast.File); ok { + delete(c.parent.(*ast.Package).Files, c.name) + return + } + + i := c.Index() + if i < 0 { + panic("Delete node not contained in slice") + } + v := c.field() + l := v.Len() + reflect.Copy(v.Slice(i, l), v.Slice(i+1, l)) + v.Index(l - 1).Set(reflect.Zero(v.Type().Elem())) + v.SetLen(l - 1) + c.iter.step-- +} + +// InsertAfter inserts n after the current Node in its containing slice. +// If the current Node is not part of a slice, InsertAfter panics. +// Apply does not walk n. +func (c *Cursor) InsertAfter(n ast.Node) { + i := c.Index() + if i < 0 { + panic("InsertAfter node not contained in slice") + } + v := c.field() + v.Set(reflect.Append(v, reflect.Zero(v.Type().Elem()))) + l := v.Len() + reflect.Copy(v.Slice(i+2, l), v.Slice(i+1, l)) + v.Index(i + 1).Set(reflect.ValueOf(n)) + c.iter.step++ +} + +// InsertBefore inserts n before the current Node in its containing slice. +// If the current Node is not part of a slice, InsertBefore panics. +// Apply will not walk n. +func (c *Cursor) InsertBefore(n ast.Node) { + i := c.Index() + if i < 0 { + panic("InsertBefore node not contained in slice") + } + v := c.field() + v.Set(reflect.Append(v, reflect.Zero(v.Type().Elem()))) + l := v.Len() + reflect.Copy(v.Slice(i+1, l), v.Slice(i, l)) + v.Index(i).Set(reflect.ValueOf(n)) + c.iter.index++ +} + +// application carries all the shared data so we can pass it around cheaply. +type application struct { + pre, post ApplyFunc + cursor Cursor + iter iterator +} + +func (a *application) apply(parent ast.Node, name string, iter *iterator, n ast.Node) { + // convert typed nil into untyped nil + if v := reflect.ValueOf(n); v.Kind() == reflect.Ptr && v.IsNil() { + n = nil + } + + // avoid heap-allocating a new cursor for each apply call; reuse a.cursor instead + saved := a.cursor + a.cursor.parent = parent + a.cursor.name = name + a.cursor.iter = iter + a.cursor.node = n + + if a.pre != nil && !a.pre(&a.cursor) { + a.cursor = saved + return + } + + // walk children + // (the order of the cases matches the order of the corresponding node types in go/ast) + switch n := n.(type) { + case nil: + // nothing to do + + // Comments and fields + case *ast.Comment: + // nothing to do + + case *ast.CommentGroup: + if n != nil { + a.applyList(n, "List") + } + + case *ast.Field: + a.apply(n, "Doc", nil, n.Doc) + a.applyList(n, "Names") + a.apply(n, "Type", nil, n.Type) + a.apply(n, "Tag", nil, n.Tag) + a.apply(n, "Comment", nil, n.Comment) + + case *ast.FieldList: + a.applyList(n, "List") + + // Expressions + case *ast.BadExpr, *ast.Ident, *ast.BasicLit: + // nothing to do + + case *ast.Ellipsis: + a.apply(n, "Elt", nil, n.Elt) + + case *ast.FuncLit: + a.apply(n, "Type", nil, n.Type) + a.apply(n, "Body", nil, n.Body) + + case *ast.CompositeLit: + a.apply(n, "Type", nil, n.Type) + a.applyList(n, "Elts") + + case *ast.ParenExpr: + a.apply(n, "X", nil, n.X) + + case *ast.SelectorExpr: + a.apply(n, "X", nil, n.X) + a.apply(n, "Sel", nil, n.Sel) + + case *ast.IndexExpr: + a.apply(n, "X", nil, n.X) + a.apply(n, "Index", nil, n.Index) + + case *ast.SliceExpr: + a.apply(n, "X", nil, n.X) + a.apply(n, "Low", nil, n.Low) + a.apply(n, "High", nil, n.High) + a.apply(n, "Max", nil, n.Max) + + case *ast.TypeAssertExpr: + a.apply(n, "X", nil, n.X) + a.apply(n, "Type", nil, n.Type) + + case *ast.CallExpr: + a.apply(n, "Fun", nil, n.Fun) + a.applyList(n, "Args") + + case *ast.StarExpr: + a.apply(n, "X", nil, n.X) + + case *ast.UnaryExpr: + a.apply(n, "X", nil, n.X) + + case *ast.BinaryExpr: + a.apply(n, "X", nil, n.X) + a.apply(n, "Y", nil, n.Y) + + case *ast.KeyValueExpr: + a.apply(n, "Key", nil, n.Key) + a.apply(n, "Value", nil, n.Value) + + // Types + case *ast.ArrayType: + a.apply(n, "Len", nil, n.Len) + a.apply(n, "Elt", nil, n.Elt) + + case *ast.StructType: + a.apply(n, "Fields", nil, n.Fields) + + case *ast.FuncType: + a.apply(n, "Params", nil, n.Params) + a.apply(n, "Results", nil, n.Results) + + case *ast.InterfaceType: + a.apply(n, "Methods", nil, n.Methods) + + case *ast.MapType: + a.apply(n, "Key", nil, n.Key) + a.apply(n, "Value", nil, n.Value) + + case *ast.ChanType: + a.apply(n, "Value", nil, n.Value) + + // Statements + case *ast.BadStmt: + // nothing to do + + case *ast.DeclStmt: + a.apply(n, "Decl", nil, n.Decl) + + case *ast.EmptyStmt: + // nothing to do + + case *ast.LabeledStmt: + a.apply(n, "Label", nil, n.Label) + a.apply(n, "Stmt", nil, n.Stmt) + + case *ast.ExprStmt: + a.apply(n, "X", nil, n.X) + + case *ast.SendStmt: + a.apply(n, "Chan", nil, n.Chan) + a.apply(n, "Value", nil, n.Value) + + case *ast.IncDecStmt: + a.apply(n, "X", nil, n.X) + + case *ast.AssignStmt: + a.applyList(n, "Lhs") + a.applyList(n, "Rhs") + + case *ast.GoStmt: + a.apply(n, "Call", nil, n.Call) + + case *ast.DeferStmt: + a.apply(n, "Call", nil, n.Call) + + case *ast.ReturnStmt: + a.applyList(n, "Results") + + case *ast.BranchStmt: + a.apply(n, "Label", nil, n.Label) + + case *ast.BlockStmt: + a.applyList(n, "List") + + case *ast.IfStmt: + a.apply(n, "Init", nil, n.Init) + a.apply(n, "Cond", nil, n.Cond) + a.apply(n, "Body", nil, n.Body) + a.apply(n, "Else", nil, n.Else) + + case *ast.CaseClause: + a.applyList(n, "List") + a.applyList(n, "Body") + + case *ast.SwitchStmt: + a.apply(n, "Init", nil, n.Init) + a.apply(n, "Tag", nil, n.Tag) + a.apply(n, "Body", nil, n.Body) + + case *ast.TypeSwitchStmt: + a.apply(n, "Init", nil, n.Init) + a.apply(n, "Assign", nil, n.Assign) + a.apply(n, "Body", nil, n.Body) + + case *ast.CommClause: + a.apply(n, "Comm", nil, n.Comm) + a.applyList(n, "Body") + + case *ast.SelectStmt: + a.apply(n, "Body", nil, n.Body) + + case *ast.ForStmt: + a.apply(n, "Init", nil, n.Init) + a.apply(n, "Cond", nil, n.Cond) + a.apply(n, "Post", nil, n.Post) + a.apply(n, "Body", nil, n.Body) + + case *ast.RangeStmt: + a.apply(n, "Key", nil, n.Key) + a.apply(n, "Value", nil, n.Value) + a.apply(n, "X", nil, n.X) + a.apply(n, "Body", nil, n.Body) + + // Declarations + case *ast.ImportSpec: + a.apply(n, "Doc", nil, n.Doc) + a.apply(n, "Name", nil, n.Name) + a.apply(n, "Path", nil, n.Path) + a.apply(n, "Comment", nil, n.Comment) + + case *ast.ValueSpec: + a.apply(n, "Doc", nil, n.Doc) + a.applyList(n, "Names") + a.apply(n, "Type", nil, n.Type) + a.applyList(n, "Values") + a.apply(n, "Comment", nil, n.Comment) + + case *ast.TypeSpec: + a.apply(n, "Doc", nil, n.Doc) + a.apply(n, "Name", nil, n.Name) + a.apply(n, "Type", nil, n.Type) + a.apply(n, "Comment", nil, n.Comment) + + case *ast.BadDecl: + // nothing to do + + case *ast.GenDecl: + a.apply(n, "Doc", nil, n.Doc) + a.applyList(n, "Specs") + + case *ast.FuncDecl: + a.apply(n, "Doc", nil, n.Doc) + a.apply(n, "Recv", nil, n.Recv) + a.apply(n, "Name", nil, n.Name) + a.apply(n, "Type", nil, n.Type) + a.apply(n, "Body", nil, n.Body) + + // Files and packages + case *ast.File: + a.apply(n, "Doc", nil, n.Doc) + a.apply(n, "Name", nil, n.Name) + a.applyList(n, "Decls") + // Don't walk n.Comments; they have either been walked already if + // they are Doc comments, or they can be easily walked explicitly. + + case *ast.Package: + // collect and sort names for reproducible behavior + var names []string + for name := range n.Files { + names = append(names, name) + } + sort.Strings(names) + for _, name := range names { + a.apply(n, name, nil, n.Files[name]) + } + + default: + panic(fmt.Sprintf("Apply: unexpected node type %T", n)) + } + + if a.post != nil && !a.post(&a.cursor) { + panic(abort) + } + + a.cursor = saved +} + +// An iterator controls iteration over a slice of nodes. +type iterator struct { + index, step int +} + +func (a *application) applyList(parent ast.Node, name string) { + // avoid heap-allocating a new iterator for each applyList call; reuse a.iter instead + saved := a.iter + a.iter.index = 0 + for { + // must reload parent.name each time, since cursor modifications might change it + v := reflect.Indirect(reflect.ValueOf(parent)).FieldByName(name) + if a.iter.index >= v.Len() { + break + } + + // element x may be nil in a bad AST - be cautious + var x ast.Node + if e := v.Index(a.iter.index); e.IsValid() { + x = e.Interface().(ast.Node) + } + + a.iter.step = 1 + a.apply(parent, name, &a.iter, x) + a.iter.index += a.iter.step + } + a.iter = saved +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/util.go b/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/util.go new file mode 100644 index 0000000000000..7630629824af1 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/ast/astutil/util.go @@ -0,0 +1,14 @@ +package astutil + +import "go/ast" + +// Unparen returns e with any enclosing parentheses stripped. +func Unparen(e ast.Expr) ast.Expr { + for { + p, ok := e.(*ast.ParenExpr) + if !ok { + return e + } + e = p.X + } +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/ast/inspector/inspector.go b/src/cmd/vendor/golang.org/x/tools/go/ast/inspector/inspector.go new file mode 100644 index 0000000000000..db88a951090a5 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/ast/inspector/inspector.go @@ -0,0 +1,182 @@ +// Copyright 2018 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. + +// Package inspector provides helper functions for traversal over the +// syntax trees of a package, including node filtering by type, and +// materialization of the traversal stack. +// +// During construction, the inspector does a complete traversal and +// builds a list of push/pop events and their node type. Subsequent +// method calls that request a traversal scan this list, rather than walk +// the AST, and perform type filtering using efficient bit sets. +// +// Experiments suggest the inspector's traversals are about 2.5x faster +// than ast.Inspect, but it may take around 5 traversals for this +// benefit to amortize the inspector's construction cost. +// If efficiency is the primary concern, do not use use Inspector for +// one-off traversals. +package inspector + +// There are four orthogonal features in a traversal: +// 1 type filtering +// 2 pruning +// 3 postorder calls to f +// 4 stack +// Rather than offer all of them in the API, +// only a few combinations are exposed: +// - Preorder is the fastest and has fewest features, +// but is the most commonly needed traversal. +// - Nodes and WithStack both provide pruning and postorder calls, +// even though few clients need it, because supporting two versions +// is not justified. +// More combinations could be supported by expressing them as +// wrappers around a more generic traversal, but this was measured +// and found to degrade performance significantly (30%). + +import ( + "go/ast" +) + +// An Inspector provides methods for inspecting +// (traversing) the syntax trees of a package. +type Inspector struct { + events []event +} + +// New returns an Inspector for the specified syntax trees. +func New(files []*ast.File) *Inspector { + return &Inspector{traverse(files)} +} + +// An event represents a push or a pop +// of an ast.Node during a traversal. +type event struct { + node ast.Node + typ uint64 // typeOf(node) + index int // 1 + index of corresponding pop event, or 0 if this is a pop +} + +// Preorder visits all the nodes of the files supplied to New in +// depth-first order. It calls f(n) for each node n before it visits +// n's children. +// +// The types argument, if non-empty, enables type-based filtering of +// events. The function f if is called only for nodes whose type +// matches an element of the types slice. +func (in *Inspector) Preorder(types []ast.Node, f func(ast.Node)) { + // Because it avoids postorder calls to f, and the pruning + // check, Preorder is almost twice as fast as Nodes. The two + // features seem to contribute similar slowdowns (~1.4x each). + + mask := maskOf(types) + for i := 0; i < len(in.events); { + ev := in.events[i] + if ev.typ&mask != 0 { + if ev.index > 0 { + f(ev.node) + } + } + i++ + } +} + +// Nodes visits the nodes of the files supplied to New in depth-first +// order. It calls f(n, true) for each node n before it visits n's +// children. If f returns true, Nodes invokes f recursively for each +// of the non-nil children of the node, followed by a call of +// f(n, false). +// +// The types argument, if non-empty, enables type-based filtering of +// events. The function f if is called only for nodes whose type +// matches an element of the types slice. +func (in *Inspector) Nodes(types []ast.Node, f func(n ast.Node, push bool) (prune bool)) { + mask := maskOf(types) + for i := 0; i < len(in.events); { + ev := in.events[i] + if ev.typ&mask != 0 { + if ev.index > 0 { + // push + if !f(ev.node, true) { + i = ev.index // jump to corresponding pop + 1 + continue + } + } else { + // pop + f(ev.node, false) + } + } + i++ + } +} + +// WithStack visits nodes in a similar manner to Nodes, but it +// supplies each call to f an additional argument, the current +// traversal stack. The stack's first element is the outermost node, +// an *ast.File; its last is the innermost, n. +func (in *Inspector) WithStack(types []ast.Node, f func(n ast.Node, push bool, stack []ast.Node) (prune bool)) { + mask := maskOf(types) + var stack []ast.Node + for i := 0; i < len(in.events); { + ev := in.events[i] + if ev.index > 0 { + // push + stack = append(stack, ev.node) + if ev.typ&mask != 0 { + if !f(ev.node, true, stack) { + i = ev.index + stack = stack[:len(stack)-1] + continue + } + } + } else { + // pop + if ev.typ&mask != 0 { + f(ev.node, false, stack) + } + stack = stack[:len(stack)-1] + } + i++ + } +} + +// traverse builds the table of events representing a traversal. +func traverse(files []*ast.File) []event { + // Preallocate approximate number of events + // based on source file extent. + // This makes traverse faster by 4x (!). + var extent int + for _, f := range files { + extent += int(f.End() - f.Pos()) + } + // This estimate is based on the net/http package. + events := make([]event, 0, extent*33/100) + + var stack []event + for _, f := range files { + ast.Inspect(f, func(n ast.Node) bool { + if n != nil { + // push + ev := event{ + node: n, + typ: typeOf(n), + index: len(events), // push event temporarily holds own index + } + stack = append(stack, ev) + events = append(events, ev) + } else { + // pop + ev := stack[len(stack)-1] + stack = stack[:len(stack)-1] + + events[ev.index].index = len(events) + 1 // make push refer to pop + + ev.index = 0 // turn ev into a pop event + events = append(events, ev) + } + return true + }) + } + + return events +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/ast/inspector/typeof.go b/src/cmd/vendor/golang.org/x/tools/go/ast/inspector/typeof.go new file mode 100644 index 0000000000000..d61301b133dfd --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/ast/inspector/typeof.go @@ -0,0 +1,216 @@ +package inspector + +// This file defines func typeOf(ast.Node) uint64. +// +// The initial map-based implementation was too slow; +// see https://go-review.googlesource.com/c/tools/+/135655/1/go/ast/inspector/inspector.go#196 + +import "go/ast" + +const ( + nArrayType = iota + nAssignStmt + nBadDecl + nBadExpr + nBadStmt + nBasicLit + nBinaryExpr + nBlockStmt + nBranchStmt + nCallExpr + nCaseClause + nChanType + nCommClause + nComment + nCommentGroup + nCompositeLit + nDeclStmt + nDeferStmt + nEllipsis + nEmptyStmt + nExprStmt + nField + nFieldList + nFile + nForStmt + nFuncDecl + nFuncLit + nFuncType + nGenDecl + nGoStmt + nIdent + nIfStmt + nImportSpec + nIncDecStmt + nIndexExpr + nInterfaceType + nKeyValueExpr + nLabeledStmt + nMapType + nPackage + nParenExpr + nRangeStmt + nReturnStmt + nSelectStmt + nSelectorExpr + nSendStmt + nSliceExpr + nStarExpr + nStructType + nSwitchStmt + nTypeAssertExpr + nTypeSpec + nTypeSwitchStmt + nUnaryExpr + nValueSpec +) + +// typeOf returns a distinct single-bit value that represents the type of n. +// +// Various implementations were benchmarked with BenchmarkNewInspector: +// GOGC=off +// - type switch 4.9-5.5ms 2.1ms +// - binary search over a sorted list of types 5.5-5.9ms 2.5ms +// - linear scan, frequency-ordered list 5.9-6.1ms 2.7ms +// - linear scan, unordered list 6.4ms 2.7ms +// - hash table 6.5ms 3.1ms +// A perfect hash seemed like overkill. +// +// The compiler's switch statement is the clear winner +// as it produces a binary tree in code, +// with constant conditions and good branch prediction. +// (Sadly it is the most verbose in source code.) +// Binary search suffered from poor branch prediction. +// +func typeOf(n ast.Node) uint64 { + // Fast path: nearly half of all nodes are identifiers. + if _, ok := n.(*ast.Ident); ok { + return 1 << nIdent + } + + // These cases include all nodes encountered by ast.Inspect. + switch n.(type) { + case *ast.ArrayType: + return 1 << nArrayType + case *ast.AssignStmt: + return 1 << nAssignStmt + case *ast.BadDecl: + return 1 << nBadDecl + case *ast.BadExpr: + return 1 << nBadExpr + case *ast.BadStmt: + return 1 << nBadStmt + case *ast.BasicLit: + return 1 << nBasicLit + case *ast.BinaryExpr: + return 1 << nBinaryExpr + case *ast.BlockStmt: + return 1 << nBlockStmt + case *ast.BranchStmt: + return 1 << nBranchStmt + case *ast.CallExpr: + return 1 << nCallExpr + case *ast.CaseClause: + return 1 << nCaseClause + case *ast.ChanType: + return 1 << nChanType + case *ast.CommClause: + return 1 << nCommClause + case *ast.Comment: + return 1 << nComment + case *ast.CommentGroup: + return 1 << nCommentGroup + case *ast.CompositeLit: + return 1 << nCompositeLit + case *ast.DeclStmt: + return 1 << nDeclStmt + case *ast.DeferStmt: + return 1 << nDeferStmt + case *ast.Ellipsis: + return 1 << nEllipsis + case *ast.EmptyStmt: + return 1 << nEmptyStmt + case *ast.ExprStmt: + return 1 << nExprStmt + case *ast.Field: + return 1 << nField + case *ast.FieldList: + return 1 << nFieldList + case *ast.File: + return 1 << nFile + case *ast.ForStmt: + return 1 << nForStmt + case *ast.FuncDecl: + return 1 << nFuncDecl + case *ast.FuncLit: + return 1 << nFuncLit + case *ast.FuncType: + return 1 << nFuncType + case *ast.GenDecl: + return 1 << nGenDecl + case *ast.GoStmt: + return 1 << nGoStmt + case *ast.Ident: + return 1 << nIdent + case *ast.IfStmt: + return 1 << nIfStmt + case *ast.ImportSpec: + return 1 << nImportSpec + case *ast.IncDecStmt: + return 1 << nIncDecStmt + case *ast.IndexExpr: + return 1 << nIndexExpr + case *ast.InterfaceType: + return 1 << nInterfaceType + case *ast.KeyValueExpr: + return 1 << nKeyValueExpr + case *ast.LabeledStmt: + return 1 << nLabeledStmt + case *ast.MapType: + return 1 << nMapType + case *ast.Package: + return 1 << nPackage + case *ast.ParenExpr: + return 1 << nParenExpr + case *ast.RangeStmt: + return 1 << nRangeStmt + case *ast.ReturnStmt: + return 1 << nReturnStmt + case *ast.SelectStmt: + return 1 << nSelectStmt + case *ast.SelectorExpr: + return 1 << nSelectorExpr + case *ast.SendStmt: + return 1 << nSendStmt + case *ast.SliceExpr: + return 1 << nSliceExpr + case *ast.StarExpr: + return 1 << nStarExpr + case *ast.StructType: + return 1 << nStructType + case *ast.SwitchStmt: + return 1 << nSwitchStmt + case *ast.TypeAssertExpr: + return 1 << nTypeAssertExpr + case *ast.TypeSpec: + return 1 << nTypeSpec + case *ast.TypeSwitchStmt: + return 1 << nTypeSwitchStmt + case *ast.UnaryExpr: + return 1 << nUnaryExpr + case *ast.ValueSpec: + return 1 << nValueSpec + } + return 0 +} + +func maskOf(nodes []ast.Node) uint64 { + if nodes == nil { + return 1<<64 - 1 // match all node types + } + var mask uint64 + for _, n := range nodes { + mask |= typeOf(n) + } + return mask +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/cfg/builder.go b/src/cmd/vendor/golang.org/x/tools/go/cfg/builder.go new file mode 100644 index 0000000000000..24e1aba033922 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/cfg/builder.go @@ -0,0 +1,510 @@ +// Copyright 2016 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. + +package cfg + +// This file implements the CFG construction pass. + +import ( + "fmt" + "go/ast" + "go/token" +) + +type builder struct { + cfg *CFG + mayReturn func(*ast.CallExpr) bool + current *Block + lblocks map[*ast.Object]*lblock // labeled blocks + targets *targets // linked stack of branch targets +} + +func (b *builder) stmt(_s ast.Stmt) { + // The label of the current statement. If non-nil, its _goto + // target is always set; its _break and _continue are set only + // within the body of switch/typeswitch/select/for/range. + // It is effectively an additional default-nil parameter of stmt(). + var label *lblock +start: + switch s := _s.(type) { + case *ast.BadStmt, + *ast.SendStmt, + *ast.IncDecStmt, + *ast.GoStmt, + *ast.DeferStmt, + *ast.EmptyStmt, + *ast.AssignStmt: + // No effect on control flow. + b.add(s) + + case *ast.ExprStmt: + b.add(s) + if call, ok := s.X.(*ast.CallExpr); ok && !b.mayReturn(call) { + // Calls to panic, os.Exit, etc, never return. + b.current = b.newBlock("unreachable.call") + } + + case *ast.DeclStmt: + // Treat each var ValueSpec as a separate statement. + d := s.Decl.(*ast.GenDecl) + if d.Tok == token.VAR { + for _, spec := range d.Specs { + if spec, ok := spec.(*ast.ValueSpec); ok { + b.add(spec) + } + } + } + + case *ast.LabeledStmt: + label = b.labeledBlock(s.Label) + b.jump(label._goto) + b.current = label._goto + _s = s.Stmt + goto start // effectively: tailcall stmt(g, s.Stmt, label) + + case *ast.ReturnStmt: + b.add(s) + b.current = b.newBlock("unreachable.return") + + case *ast.BranchStmt: + b.branchStmt(s) + + case *ast.BlockStmt: + b.stmtList(s.List) + + case *ast.IfStmt: + if s.Init != nil { + b.stmt(s.Init) + } + then := b.newBlock("if.then") + done := b.newBlock("if.done") + _else := done + if s.Else != nil { + _else = b.newBlock("if.else") + } + b.add(s.Cond) + b.ifelse(then, _else) + b.current = then + b.stmt(s.Body) + b.jump(done) + + if s.Else != nil { + b.current = _else + b.stmt(s.Else) + b.jump(done) + } + + b.current = done + + case *ast.SwitchStmt: + b.switchStmt(s, label) + + case *ast.TypeSwitchStmt: + b.typeSwitchStmt(s, label) + + case *ast.SelectStmt: + b.selectStmt(s, label) + + case *ast.ForStmt: + b.forStmt(s, label) + + case *ast.RangeStmt: + b.rangeStmt(s, label) + + default: + panic(fmt.Sprintf("unexpected statement kind: %T", s)) + } +} + +func (b *builder) stmtList(list []ast.Stmt) { + for _, s := range list { + b.stmt(s) + } +} + +func (b *builder) branchStmt(s *ast.BranchStmt) { + var block *Block + switch s.Tok { + case token.BREAK: + if s.Label != nil { + if lb := b.labeledBlock(s.Label); lb != nil { + block = lb._break + } + } else { + for t := b.targets; t != nil && block == nil; t = t.tail { + block = t._break + } + } + + case token.CONTINUE: + if s.Label != nil { + if lb := b.labeledBlock(s.Label); lb != nil { + block = lb._continue + } + } else { + for t := b.targets; t != nil && block == nil; t = t.tail { + block = t._continue + } + } + + case token.FALLTHROUGH: + for t := b.targets; t != nil; t = t.tail { + block = t._fallthrough + } + + case token.GOTO: + if s.Label != nil { + block = b.labeledBlock(s.Label)._goto + } + } + if block == nil { + block = b.newBlock("undefined.branch") + } + b.jump(block) + b.current = b.newBlock("unreachable.branch") +} + +func (b *builder) switchStmt(s *ast.SwitchStmt, label *lblock) { + if s.Init != nil { + b.stmt(s.Init) + } + if s.Tag != nil { + b.add(s.Tag) + } + done := b.newBlock("switch.done") + if label != nil { + label._break = done + } + // We pull the default case (if present) down to the end. + // But each fallthrough label must point to the next + // body block in source order, so we preallocate a + // body block (fallthru) for the next case. + // Unfortunately this makes for a confusing block order. + var defaultBody *[]ast.Stmt + var defaultFallthrough *Block + var fallthru, defaultBlock *Block + ncases := len(s.Body.List) + for i, clause := range s.Body.List { + body := fallthru + if body == nil { + body = b.newBlock("switch.body") // first case only + } + + // Preallocate body block for the next case. + fallthru = done + if i+1 < ncases { + fallthru = b.newBlock("switch.body") + } + + cc := clause.(*ast.CaseClause) + if cc.List == nil { + // Default case. + defaultBody = &cc.Body + defaultFallthrough = fallthru + defaultBlock = body + continue + } + + var nextCond *Block + for _, cond := range cc.List { + nextCond = b.newBlock("switch.next") + b.add(cond) // one half of the tag==cond condition + b.ifelse(body, nextCond) + b.current = nextCond + } + b.current = body + b.targets = &targets{ + tail: b.targets, + _break: done, + _fallthrough: fallthru, + } + b.stmtList(cc.Body) + b.targets = b.targets.tail + b.jump(done) + b.current = nextCond + } + if defaultBlock != nil { + b.jump(defaultBlock) + b.current = defaultBlock + b.targets = &targets{ + tail: b.targets, + _break: done, + _fallthrough: defaultFallthrough, + } + b.stmtList(*defaultBody) + b.targets = b.targets.tail + } + b.jump(done) + b.current = done +} + +func (b *builder) typeSwitchStmt(s *ast.TypeSwitchStmt, label *lblock) { + if s.Init != nil { + b.stmt(s.Init) + } + if s.Assign != nil { + b.add(s.Assign) + } + + done := b.newBlock("typeswitch.done") + if label != nil { + label._break = done + } + var default_ *ast.CaseClause + for _, clause := range s.Body.List { + cc := clause.(*ast.CaseClause) + if cc.List == nil { + default_ = cc + continue + } + body := b.newBlock("typeswitch.body") + var next *Block + for _, casetype := range cc.List { + next = b.newBlock("typeswitch.next") + // casetype is a type, so don't call b.add(casetype). + // This block logically contains a type assertion, + // x.(casetype), but it's unclear how to represent x. + _ = casetype + b.ifelse(body, next) + b.current = next + } + b.current = body + b.typeCaseBody(cc, done) + b.current = next + } + if default_ != nil { + b.typeCaseBody(default_, done) + } else { + b.jump(done) + } + b.current = done +} + +func (b *builder) typeCaseBody(cc *ast.CaseClause, done *Block) { + b.targets = &targets{ + tail: b.targets, + _break: done, + } + b.stmtList(cc.Body) + b.targets = b.targets.tail + b.jump(done) +} + +func (b *builder) selectStmt(s *ast.SelectStmt, label *lblock) { + // First evaluate channel expressions. + // TODO(adonovan): fix: evaluate only channel exprs here. + for _, clause := range s.Body.List { + if comm := clause.(*ast.CommClause).Comm; comm != nil { + b.stmt(comm) + } + } + + done := b.newBlock("select.done") + if label != nil { + label._break = done + } + + var defaultBody *[]ast.Stmt + for _, cc := range s.Body.List { + clause := cc.(*ast.CommClause) + if clause.Comm == nil { + defaultBody = &clause.Body + continue + } + body := b.newBlock("select.body") + next := b.newBlock("select.next") + b.ifelse(body, next) + b.current = body + b.targets = &targets{ + tail: b.targets, + _break: done, + } + switch comm := clause.Comm.(type) { + case *ast.ExprStmt: // <-ch + // nop + case *ast.AssignStmt: // x := <-states[state].Chan + b.add(comm.Lhs[0]) + } + b.stmtList(clause.Body) + b.targets = b.targets.tail + b.jump(done) + b.current = next + } + if defaultBody != nil { + b.targets = &targets{ + tail: b.targets, + _break: done, + } + b.stmtList(*defaultBody) + b.targets = b.targets.tail + b.jump(done) + } + b.current = done +} + +func (b *builder) forStmt(s *ast.ForStmt, label *lblock) { + // ...init... + // jump loop + // loop: + // if cond goto body else done + // body: + // ...body... + // jump post + // post: (target of continue) + // ...post... + // jump loop + // done: (target of break) + if s.Init != nil { + b.stmt(s.Init) + } + body := b.newBlock("for.body") + done := b.newBlock("for.done") // target of 'break' + loop := body // target of back-edge + if s.Cond != nil { + loop = b.newBlock("for.loop") + } + cont := loop // target of 'continue' + if s.Post != nil { + cont = b.newBlock("for.post") + } + if label != nil { + label._break = done + label._continue = cont + } + b.jump(loop) + b.current = loop + if loop != body { + b.add(s.Cond) + b.ifelse(body, done) + b.current = body + } + b.targets = &targets{ + tail: b.targets, + _break: done, + _continue: cont, + } + b.stmt(s.Body) + b.targets = b.targets.tail + b.jump(cont) + + if s.Post != nil { + b.current = cont + b.stmt(s.Post) + b.jump(loop) // back-edge + } + b.current = done +} + +func (b *builder) rangeStmt(s *ast.RangeStmt, label *lblock) { + b.add(s.X) + + if s.Key != nil { + b.add(s.Key) + } + if s.Value != nil { + b.add(s.Value) + } + + // ... + // loop: (target of continue) + // if ... goto body else done + // body: + // ... + // jump loop + // done: (target of break) + + loop := b.newBlock("range.loop") + b.jump(loop) + b.current = loop + + body := b.newBlock("range.body") + done := b.newBlock("range.done") + b.ifelse(body, done) + b.current = body + + if label != nil { + label._break = done + label._continue = loop + } + b.targets = &targets{ + tail: b.targets, + _break: done, + _continue: loop, + } + b.stmt(s.Body) + b.targets = b.targets.tail + b.jump(loop) // back-edge + b.current = done +} + +// -------- helpers -------- + +// Destinations associated with unlabeled for/switch/select stmts. +// We push/pop one of these as we enter/leave each construct and for +// each BranchStmt we scan for the innermost target of the right type. +// +type targets struct { + tail *targets // rest of stack + _break *Block + _continue *Block + _fallthrough *Block +} + +// Destinations associated with a labeled block. +// We populate these as labels are encountered in forward gotos or +// labeled statements. +// +type lblock struct { + _goto *Block + _break *Block + _continue *Block +} + +// labeledBlock returns the branch target associated with the +// specified label, creating it if needed. +// +func (b *builder) labeledBlock(label *ast.Ident) *lblock { + lb := b.lblocks[label.Obj] + if lb == nil { + lb = &lblock{_goto: b.newBlock(label.Name)} + if b.lblocks == nil { + b.lblocks = make(map[*ast.Object]*lblock) + } + b.lblocks[label.Obj] = lb + } + return lb +} + +// newBlock appends a new unconnected basic block to b.cfg's block +// slice and returns it. +// It does not automatically become the current block. +// comment is an optional string for more readable debugging output. +func (b *builder) newBlock(comment string) *Block { + g := b.cfg + block := &Block{ + Index: int32(len(g.Blocks)), + comment: comment, + } + block.Succs = block.succs2[:0] + g.Blocks = append(g.Blocks, block) + return block +} + +func (b *builder) add(n ast.Node) { + b.current.Nodes = append(b.current.Nodes, n) +} + +// jump adds an edge from the current block to the target block, +// and sets b.current to nil. +func (b *builder) jump(target *Block) { + b.current.Succs = append(b.current.Succs, target) + b.current = nil +} + +// ifelse emits edges from the current block to the t and f blocks, +// and sets b.current to nil. +func (b *builder) ifelse(t, f *Block) { + b.current.Succs = append(b.current.Succs, t, f) + b.current = nil +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/cfg/cfg.go b/src/cmd/vendor/golang.org/x/tools/go/cfg/cfg.go new file mode 100644 index 0000000000000..b075034bb4514 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/cfg/cfg.go @@ -0,0 +1,150 @@ +// Copyright 2016 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. + +// This package constructs a simple control-flow graph (CFG) of the +// statements and expressions within a single function. +// +// Use cfg.New to construct the CFG for a function body. +// +// The blocks of the CFG contain all the function's non-control +// statements. The CFG does not contain control statements such as If, +// Switch, Select, and Branch, but does contain their subexpressions. +// For example, this source code: +// +// if x := f(); x != nil { +// T() +// } else { +// F() +// } +// +// produces this CFG: +// +// 1: x := f() +// x != nil +// succs: 2, 3 +// 2: T() +// succs: 4 +// 3: F() +// succs: 4 +// 4: +// +// The CFG does contain Return statements; even implicit returns are +// materialized (at the position of the function's closing brace). +// +// The CFG does not record conditions associated with conditional branch +// edges, nor the short-circuit semantics of the && and || operators, +// nor abnormal control flow caused by panic. If you need this +// information, use golang.org/x/tools/go/ssa instead. +// +package cfg + +import ( + "bytes" + "fmt" + "go/ast" + "go/format" + "go/token" +) + +// A CFG represents the control-flow graph of a single function. +// +// The entry point is Blocks[0]; there may be multiple return blocks. +type CFG struct { + Blocks []*Block // block[0] is entry; order otherwise undefined +} + +// A Block represents a basic block: a list of statements and +// expressions that are always evaluated sequentially. +// +// A block may have 0-2 successors: zero for a return block or a block +// that calls a function such as panic that never returns; one for a +// normal (jump) block; and two for a conditional (if) block. +type Block struct { + Nodes []ast.Node // statements, expressions, and ValueSpecs + Succs []*Block // successor nodes in the graph + Index int32 // index within CFG.Blocks + Live bool // block is reachable from entry + + comment string // for debugging + succs2 [2]*Block // underlying array for Succs +} + +// New returns a new control-flow graph for the specified function body, +// which must be non-nil. +// +// The CFG builder calls mayReturn to determine whether a given function +// call may return. For example, calls to panic, os.Exit, and log.Fatal +// do not return, so the builder can remove infeasible graph edges +// following such calls. The builder calls mayReturn only for a +// CallExpr beneath an ExprStmt. +func New(body *ast.BlockStmt, mayReturn func(*ast.CallExpr) bool) *CFG { + b := builder{ + mayReturn: mayReturn, + cfg: new(CFG), + } + b.current = b.newBlock("entry") + b.stmt(body) + + // Compute liveness (reachability from entry point), breadth-first. + q := make([]*Block, 0, len(b.cfg.Blocks)) + q = append(q, b.cfg.Blocks[0]) // entry point + for len(q) > 0 { + b := q[len(q)-1] + q = q[:len(q)-1] + + if !b.Live { + b.Live = true + q = append(q, b.Succs...) + } + } + + // Does control fall off the end of the function's body? + // Make implicit return explicit. + if b.current != nil && b.current.Live { + b.add(&ast.ReturnStmt{ + Return: body.End() - 1, + }) + } + + return b.cfg +} + +func (b *Block) String() string { + return fmt.Sprintf("block %d (%s)", b.Index, b.comment) +} + +// Return returns the return statement at the end of this block if present, nil otherwise. +func (b *Block) Return() (ret *ast.ReturnStmt) { + if len(b.Nodes) > 0 { + ret, _ = b.Nodes[len(b.Nodes)-1].(*ast.ReturnStmt) + } + return +} + +// Format formats the control-flow graph for ease of debugging. +func (g *CFG) Format(fset *token.FileSet) string { + var buf bytes.Buffer + for _, b := range g.Blocks { + fmt.Fprintf(&buf, ".%d: # %s\n", b.Index, b.comment) + for _, n := range b.Nodes { + fmt.Fprintf(&buf, "\t%s\n", formatNode(fset, n)) + } + if len(b.Succs) > 0 { + fmt.Fprintf(&buf, "\tsuccs:") + for _, succ := range b.Succs { + fmt.Fprintf(&buf, " %d", succ.Index) + } + buf.WriteByte('\n') + } + buf.WriteByte('\n') + } + return buf.String() +} + +func formatNode(fset *token.FileSet, n ast.Node) string { + var buf bytes.Buffer + format.Node(&buf, fset, n) + // Indent secondary lines by a tab. + return string(bytes.Replace(buf.Bytes(), []byte("\n"), []byte("\n\t"), -1)) +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/types/objectpath/objectpath.go b/src/cmd/vendor/golang.org/x/tools/go/types/objectpath/objectpath.go new file mode 100644 index 0000000000000..0d85488efb619 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/types/objectpath/objectpath.go @@ -0,0 +1,523 @@ +// Copyright 2018 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. + +// Package objectpath defines a naming scheme for types.Objects +// (that is, named entities in Go programs) relative to their enclosing +// package. +// +// Type-checker objects are canonical, so they are usually identified by +// their address in memory (a pointer), but a pointer has meaning only +// within one address space. By contrast, objectpath names allow the +// identity of an object to be sent from one program to another, +// establishing a correspondence between types.Object variables that are +// distinct but logically equivalent. +// +// A single object may have multiple paths. In this example, +// type A struct{ X int } +// type B A +// the field X has two paths due to its membership of both A and B. +// The For(obj) function always returns one of these paths, arbitrarily +// but consistently. +package objectpath + +import ( + "fmt" + "strconv" + "strings" + + "go/types" +) + +// A Path is an opaque name that identifies a types.Object +// relative to its package. Conceptually, the name consists of a +// sequence of destructuring operations applied to the package scope +// to obtain the original object. +// The name does not include the package itself. +type Path string + +// Encoding +// +// An object path is a textual and (with training) human-readable encoding +// of a sequence of destructuring operators, starting from a types.Package. +// The sequences represent a path through the package/object/type graph. +// We classify these operators by their type: +// +// PO package->object Package.Scope.Lookup +// OT object->type Object.Type +// TT type->type Type.{Elem,Key,Params,Results,Underlying} [EKPRU] +// TO type->object Type.{At,Field,Method,Obj} [AFMO] +// +// All valid paths start with a package and end at an object +// and thus may be defined by the regular language: +// +// objectpath = PO (OT TT* TO)* +// +// The concrete encoding follows directly: +// - The only PO operator is Package.Scope.Lookup, which requires an identifier. +// - The only OT operator is Object.Type, +// which we encode as '.' because dot cannot appear in an identifier. +// - The TT operators are encoded as [EKPRU]. +// - The OT operators are encoded as [AFMO]; +// three of these (At,Field,Method) require an integer operand, +// which is encoded as a string of decimal digits. +// These indices are stable across different representations +// of the same package, even source and export data. +// +// In the example below, +// +// package p +// +// type T interface { +// f() (a string, b struct{ X int }) +// } +// +// field X has the path "T.UM0.RA1.F0", +// representing the following sequence of operations: +// +// p.Lookup("T") T +// .Type().Underlying().Method(0). f +// .Type().Results().At(1) b +// .Type().Field(0) X +// +// The encoding is not maximally compact---every R or P is +// followed by an A, for example---but this simplifies the +// encoder and decoder. +// +const ( + // object->type operators + opType = '.' // .Type() (Object) + + // type->type operators + opElem = 'E' // .Elem() (Pointer, Slice, Array, Chan, Map) + opKey = 'K' // .Key() (Map) + opParams = 'P' // .Params() (Signature) + opResults = 'R' // .Results() (Signature) + opUnderlying = 'U' // .Underlying() (Named) + + // type->object operators + opAt = 'A' // .At(i) (Tuple) + opField = 'F' // .Field(i) (Struct) + opMethod = 'M' // .Method(i) (Named or Interface; not Struct: "promoted" names are ignored) + opObj = 'O' // .Obj() (Named) +) + +// The For function returns the path to an object relative to its package, +// or an error if the object is not accessible from the package's Scope. +// +// The For function guarantees to return a path only for the following objects: +// - package-level types +// - exported package-level non-types +// - methods +// - parameter and result variables +// - struct fields +// These objects are sufficient to define the API of their package. +// The objects described by a package's export data are drawn from this set. +// +// For does not return a path for predeclared names, imported package +// names, local names, and unexported package-level names (except +// types). +// +// Example: given this definition, +// +// package p +// +// type T interface { +// f() (a string, b struct{ X int }) +// } +// +// For(X) would return a path that denotes the following sequence of operations: +// +// p.Scope().Lookup("T") (TypeName T) +// .Type().Underlying().Method(0). (method Func f) +// .Type().Results().At(1) (field Var b) +// .Type().Field(0) (field Var X) +// +// where p is the package (*types.Package) to which X belongs. +func For(obj types.Object) (Path, error) { + pkg := obj.Pkg() + + // This table lists the cases of interest. + // + // Object Action + // ------ ------ + // nil reject + // builtin reject + // pkgname reject + // label reject + // var + // package-level accept + // func param/result accept + // local reject + // struct field accept + // const + // package-level accept + // local reject + // func + // package-level accept + // init functions reject + // concrete method accept + // interface method accept + // type + // package-level accept + // local reject + // + // The only accessible package-level objects are members of pkg itself. + // + // The cases are handled in four steps: + // + // 1. reject nil and builtin + // 2. accept package-level objects + // 3. reject obviously invalid objects + // 4. search the API for the path to the param/result/field/method. + + // 1. reference to nil or builtin? + if pkg == nil { + return "", fmt.Errorf("predeclared %s has no path", obj) + } + scope := pkg.Scope() + + // 2. package-level object? + if scope.Lookup(obj.Name()) == obj { + // Only exported objects (and non-exported types) have a path. + // Non-exported types may be referenced by other objects. + if _, ok := obj.(*types.TypeName); !ok && !obj.Exported() { + return "", fmt.Errorf("no path for non-exported %v", obj) + } + return Path(obj.Name()), nil + } + + // 3. Not a package-level object. + // Reject obviously non-viable cases. + switch obj := obj.(type) { + case *types.Const, // Only package-level constants have a path. + *types.TypeName, // Only package-level types have a path. + *types.Label, // Labels are function-local. + *types.PkgName: // PkgNames are file-local. + return "", fmt.Errorf("no path for %v", obj) + + case *types.Var: + // Could be: + // - a field (obj.IsField()) + // - a func parameter or result + // - a local var. + // Sadly there is no way to distinguish + // a param/result from a local + // so we must proceed to the find. + + case *types.Func: + // A func, if not package-level, must be a method. + if recv := obj.Type().(*types.Signature).Recv(); recv == nil { + return "", fmt.Errorf("func is not a method: %v", obj) + } + // TODO(adonovan): opt: if the method is concrete, + // do a specialized version of the rest of this function so + // that it's O(1) not O(|scope|). Basically 'find' is needed + // only for struct fields and interface methods. + + default: + panic(obj) + } + + // 4. Search the API for the path to the var (field/param/result) or method. + + // First inspect package-level named types. + // In the presence of path aliases, these give + // the best paths because non-types may + // refer to types, but not the reverse. + empty := make([]byte, 0, 48) // initial space + for _, name := range scope.Names() { + o := scope.Lookup(name) + tname, ok := o.(*types.TypeName) + if !ok { + continue // handle non-types in second pass + } + + path := append(empty, name...) + path = append(path, opType) + + T := o.Type() + + if tname.IsAlias() { + // type alias + if r := find(obj, T, path); r != nil { + return Path(r), nil + } + } else { + // defined (named) type + if r := find(obj, T.Underlying(), append(path, opUnderlying)); r != nil { + return Path(r), nil + } + } + } + + // Then inspect everything else: + // non-types, and declared methods of defined types. + for _, name := range scope.Names() { + o := scope.Lookup(name) + path := append(empty, name...) + if _, ok := o.(*types.TypeName); !ok { + if o.Exported() { + // exported non-type (const, var, func) + if r := find(obj, o.Type(), append(path, opType)); r != nil { + return Path(r), nil + } + } + continue + } + + // Inspect declared methods of defined types. + if T, ok := o.Type().(*types.Named); ok { + path = append(path, opType) + for i := 0; i < T.NumMethods(); i++ { + m := T.Method(i) + path2 := appendOpArg(path, opMethod, i) + if m == obj { + return Path(path2), nil // found declared method + } + if r := find(obj, m.Type(), append(path2, opType)); r != nil { + return Path(r), nil + } + } + } + } + + return "", fmt.Errorf("can't find path for %v in %s", obj, pkg.Path()) +} + +func appendOpArg(path []byte, op byte, arg int) []byte { + path = append(path, op) + path = strconv.AppendInt(path, int64(arg), 10) + return path +} + +// find finds obj within type T, returning the path to it, or nil if not found. +func find(obj types.Object, T types.Type, path []byte) []byte { + switch T := T.(type) { + case *types.Basic, *types.Named: + // Named types belonging to pkg were handled already, + // so T must belong to another package. No path. + return nil + case *types.Pointer: + return find(obj, T.Elem(), append(path, opElem)) + case *types.Slice: + return find(obj, T.Elem(), append(path, opElem)) + case *types.Array: + return find(obj, T.Elem(), append(path, opElem)) + case *types.Chan: + return find(obj, T.Elem(), append(path, opElem)) + case *types.Map: + if r := find(obj, T.Key(), append(path, opKey)); r != nil { + return r + } + return find(obj, T.Elem(), append(path, opElem)) + case *types.Signature: + if r := find(obj, T.Params(), append(path, opParams)); r != nil { + return r + } + return find(obj, T.Results(), append(path, opResults)) + case *types.Struct: + for i := 0; i < T.NumFields(); i++ { + f := T.Field(i) + path2 := appendOpArg(path, opField, i) + if f == obj { + return path2 // found field var + } + if r := find(obj, f.Type(), append(path2, opType)); r != nil { + return r + } + } + return nil + case *types.Tuple: + for i := 0; i < T.Len(); i++ { + v := T.At(i) + path2 := appendOpArg(path, opAt, i) + if v == obj { + return path2 // found param/result var + } + if r := find(obj, v.Type(), append(path2, opType)); r != nil { + return r + } + } + return nil + case *types.Interface: + for i := 0; i < T.NumMethods(); i++ { + m := T.Method(i) + path2 := appendOpArg(path, opMethod, i) + if m == obj { + return path2 // found interface method + } + if r := find(obj, m.Type(), append(path2, opType)); r != nil { + return r + } + } + return nil + } + panic(T) +} + +// Object returns the object denoted by path p within the package pkg. +func Object(pkg *types.Package, p Path) (types.Object, error) { + if p == "" { + return nil, fmt.Errorf("empty path") + } + + pathstr := string(p) + var pkgobj, suffix string + if dot := strings.IndexByte(pathstr, opType); dot < 0 { + pkgobj = pathstr + } else { + pkgobj = pathstr[:dot] + suffix = pathstr[dot:] // suffix starts with "." + } + + obj := pkg.Scope().Lookup(pkgobj) + if obj == nil { + return nil, fmt.Errorf("package %s does not contain %q", pkg.Path(), pkgobj) + } + + // abtraction of *types.{Pointer,Slice,Array,Chan,Map} + type hasElem interface { + Elem() types.Type + } + // abstraction of *types.{Interface,Named} + type hasMethods interface { + Method(int) *types.Func + NumMethods() int + } + + // The loop state is the pair (t, obj), + // exactly one of which is non-nil, initially obj. + // All suffixes start with '.' (the only object->type operation), + // followed by optional type->type operations, + // then a type->object operation. + // The cycle then repeats. + var t types.Type + for suffix != "" { + code := suffix[0] + suffix = suffix[1:] + + // Codes [AFM] have an integer operand. + var index int + switch code { + case opAt, opField, opMethod: + rest := strings.TrimLeft(suffix, "0123456789") + numerals := suffix[:len(suffix)-len(rest)] + suffix = rest + i, err := strconv.Atoi(numerals) + if err != nil { + return nil, fmt.Errorf("invalid path: bad numeric operand %q for code %q", numerals, code) + } + index = int(i) + case opObj: + // no operand + default: + // The suffix must end with a type->object operation. + if suffix == "" { + return nil, fmt.Errorf("invalid path: ends with %q, want [AFMO]", code) + } + } + + if code == opType { + if t != nil { + return nil, fmt.Errorf("invalid path: unexpected %q in type context", opType) + } + t = obj.Type() + obj = nil + continue + } + + if t == nil { + return nil, fmt.Errorf("invalid path: code %q in object context", code) + } + + // Inv: t != nil, obj == nil + + switch code { + case opElem: + hasElem, ok := t.(hasElem) // Pointer, Slice, Array, Chan, Map + if !ok { + return nil, fmt.Errorf("cannot apply %q to %s (got %T, want pointer, slice, array, chan or map)", code, t, t) + } + t = hasElem.Elem() + + case opKey: + mapType, ok := t.(*types.Map) + if !ok { + return nil, fmt.Errorf("cannot apply %q to %s (got %T, want map)", code, t, t) + } + t = mapType.Key() + + case opParams: + sig, ok := t.(*types.Signature) + if !ok { + return nil, fmt.Errorf("cannot apply %q to %s (got %T, want signature)", code, t, t) + } + t = sig.Params() + + case opResults: + sig, ok := t.(*types.Signature) + if !ok { + return nil, fmt.Errorf("cannot apply %q to %s (got %T, want signature)", code, t, t) + } + t = sig.Results() + + case opUnderlying: + named, ok := t.(*types.Named) + if !ok { + return nil, fmt.Errorf("cannot apply %q to %s (got %s, want named)", code, t, t) + } + t = named.Underlying() + + case opAt: + tuple, ok := t.(*types.Tuple) + if !ok { + return nil, fmt.Errorf("cannot apply %q to %s (got %s, want tuple)", code, t, t) + } + if n := tuple.Len(); index >= n { + return nil, fmt.Errorf("tuple index %d out of range [0-%d)", index, n) + } + obj = tuple.At(index) + t = nil + + case opField: + structType, ok := t.(*types.Struct) + if !ok { + return nil, fmt.Errorf("cannot apply %q to %s (got %T, want struct)", code, t, t) + } + if n := structType.NumFields(); index >= n { + return nil, fmt.Errorf("field index %d out of range [0-%d)", index, n) + } + obj = structType.Field(index) + t = nil + + case opMethod: + hasMethods, ok := t.(hasMethods) // Interface or Named + if !ok { + return nil, fmt.Errorf("cannot apply %q to %s (got %s, want interface or named)", code, t, t) + } + if n := hasMethods.NumMethods(); index >= n { + return nil, fmt.Errorf("method index %d out of range [0-%d)", index, n) + } + obj = hasMethods.Method(index) + t = nil + + case opObj: + named, ok := t.(*types.Named) + if !ok { + return nil, fmt.Errorf("cannot apply %q to %s (got %s, want named)", code, t, t) + } + obj = named.Obj() + t = nil + + default: + return nil, fmt.Errorf("invalid path: unknown code %q", code) + } + } + + if obj.Pkg() != pkg { + return nil, fmt.Errorf("path denotes %s, which belongs to a different package", obj) + } + + return obj, nil // success +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/callee.go b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/callee.go new file mode 100644 index 0000000000000..38f596daf9e22 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/callee.go @@ -0,0 +1,46 @@ +// Copyright 2018 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. + +package typeutil + +import ( + "go/ast" + "go/types" + + "golang.org/x/tools/go/ast/astutil" +) + +// Callee returns the named target of a function call, if any: +// a function, method, builtin, or variable. +func Callee(info *types.Info, call *ast.CallExpr) types.Object { + var obj types.Object + switch fun := astutil.Unparen(call.Fun).(type) { + case *ast.Ident: + obj = info.Uses[fun] // type, var, builtin, or declared func + case *ast.SelectorExpr: + if sel, ok := info.Selections[fun]; ok { + obj = sel.Obj() // method or field + } else { + obj = info.Uses[fun.Sel] // qualified identifier? + } + } + if _, ok := obj.(*types.TypeName); ok { + return nil // T(x) is a conversion, not a call + } + return obj +} + +// StaticCallee returns the target (function or method) of a static +// function call, if any. It returns nil for calls to builtins. +func StaticCallee(info *types.Info, call *ast.CallExpr) *types.Func { + if f, ok := Callee(info, call).(*types.Func); ok && !interfaceMethod(f) { + return f + } + return nil +} + +func interfaceMethod(f *types.Func) bool { + recv := f.Type().(*types.Signature).Recv() + return recv != nil && types.IsInterface(recv.Type()) +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/imports.go b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/imports.go new file mode 100644 index 0000000000000..9c441dba9c06b --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/imports.go @@ -0,0 +1,31 @@ +// Copyright 2014 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. + +package typeutil + +import "go/types" + +// Dependencies returns all dependencies of the specified packages. +// +// Dependent packages appear in topological order: if package P imports +// package Q, Q appears earlier than P in the result. +// The algorithm follows import statements in the order they +// appear in the source code, so the result is a total order. +// +func Dependencies(pkgs ...*types.Package) []*types.Package { + var result []*types.Package + seen := make(map[*types.Package]bool) + var visit func(pkgs []*types.Package) + visit = func(pkgs []*types.Package) { + for _, p := range pkgs { + if !seen[p] { + seen[p] = true + visit(p.Imports()) + result = append(result, p) + } + } + } + visit(pkgs) + return result +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/map.go b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/map.go new file mode 100644 index 0000000000000..c7f7545006409 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/map.go @@ -0,0 +1,313 @@ +// Copyright 2014 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. + +// Package typeutil defines various utilities for types, such as Map, +// a mapping from types.Type to interface{} values. +package typeutil // import "golang.org/x/tools/go/types/typeutil" + +import ( + "bytes" + "fmt" + "go/types" + "reflect" +) + +// Map is a hash-table-based mapping from types (types.Type) to +// arbitrary interface{} values. The concrete types that implement +// the Type interface are pointers. Since they are not canonicalized, +// == cannot be used to check for equivalence, and thus we cannot +// simply use a Go map. +// +// Just as with map[K]V, a nil *Map is a valid empty map. +// +// Not thread-safe. +// +type Map struct { + hasher Hasher // shared by many Maps + table map[uint32][]entry // maps hash to bucket; entry.key==nil means unused + length int // number of map entries +} + +// entry is an entry (key/value association) in a hash bucket. +type entry struct { + key types.Type + value interface{} +} + +// SetHasher sets the hasher used by Map. +// +// All Hashers are functionally equivalent but contain internal state +// used to cache the results of hashing previously seen types. +// +// A single Hasher created by MakeHasher() may be shared among many +// Maps. This is recommended if the instances have many keys in +// common, as it will amortize the cost of hash computation. +// +// A Hasher may grow without bound as new types are seen. Even when a +// type is deleted from the map, the Hasher never shrinks, since other +// types in the map may reference the deleted type indirectly. +// +// Hashers are not thread-safe, and read-only operations such as +// Map.Lookup require updates to the hasher, so a full Mutex lock (not a +// read-lock) is require around all Map operations if a shared +// hasher is accessed from multiple threads. +// +// If SetHasher is not called, the Map will create a private hasher at +// the first call to Insert. +// +func (m *Map) SetHasher(hasher Hasher) { + m.hasher = hasher +} + +// Delete removes the entry with the given key, if any. +// It returns true if the entry was found. +// +func (m *Map) Delete(key types.Type) bool { + if m != nil && m.table != nil { + hash := m.hasher.Hash(key) + bucket := m.table[hash] + for i, e := range bucket { + if e.key != nil && types.Identical(key, e.key) { + // We can't compact the bucket as it + // would disturb iterators. + bucket[i] = entry{} + m.length-- + return true + } + } + } + return false +} + +// At returns the map entry for the given key. +// The result is nil if the entry is not present. +// +func (m *Map) At(key types.Type) interface{} { + if m != nil && m.table != nil { + for _, e := range m.table[m.hasher.Hash(key)] { + if e.key != nil && types.Identical(key, e.key) { + return e.value + } + } + } + return nil +} + +// Set sets the map entry for key to val, +// and returns the previous entry, if any. +func (m *Map) Set(key types.Type, value interface{}) (prev interface{}) { + if m.table != nil { + hash := m.hasher.Hash(key) + bucket := m.table[hash] + var hole *entry + for i, e := range bucket { + if e.key == nil { + hole = &bucket[i] + } else if types.Identical(key, e.key) { + prev = e.value + bucket[i].value = value + return + } + } + + if hole != nil { + *hole = entry{key, value} // overwrite deleted entry + } else { + m.table[hash] = append(bucket, entry{key, value}) + } + } else { + if m.hasher.memo == nil { + m.hasher = MakeHasher() + } + hash := m.hasher.Hash(key) + m.table = map[uint32][]entry{hash: {entry{key, value}}} + } + + m.length++ + return +} + +// Len returns the number of map entries. +func (m *Map) Len() int { + if m != nil { + return m.length + } + return 0 +} + +// Iterate calls function f on each entry in the map in unspecified order. +// +// If f should mutate the map, Iterate provides the same guarantees as +// Go maps: if f deletes a map entry that Iterate has not yet reached, +// f will not be invoked for it, but if f inserts a map entry that +// Iterate has not yet reached, whether or not f will be invoked for +// it is unspecified. +// +func (m *Map) Iterate(f func(key types.Type, value interface{})) { + if m != nil { + for _, bucket := range m.table { + for _, e := range bucket { + if e.key != nil { + f(e.key, e.value) + } + } + } + } +} + +// Keys returns a new slice containing the set of map keys. +// The order is unspecified. +func (m *Map) Keys() []types.Type { + keys := make([]types.Type, 0, m.Len()) + m.Iterate(func(key types.Type, _ interface{}) { + keys = append(keys, key) + }) + return keys +} + +func (m *Map) toString(values bool) string { + if m == nil { + return "{}" + } + var buf bytes.Buffer + fmt.Fprint(&buf, "{") + sep := "" + m.Iterate(func(key types.Type, value interface{}) { + fmt.Fprint(&buf, sep) + sep = ", " + fmt.Fprint(&buf, key) + if values { + fmt.Fprintf(&buf, ": %q", value) + } + }) + fmt.Fprint(&buf, "}") + return buf.String() +} + +// String returns a string representation of the map's entries. +// Values are printed using fmt.Sprintf("%v", v). +// Order is unspecified. +// +func (m *Map) String() string { + return m.toString(true) +} + +// KeysString returns a string representation of the map's key set. +// Order is unspecified. +// +func (m *Map) KeysString() string { + return m.toString(false) +} + +//////////////////////////////////////////////////////////////////////// +// Hasher + +// A Hasher maps each type to its hash value. +// For efficiency, a hasher uses memoization; thus its memory +// footprint grows monotonically over time. +// Hashers are not thread-safe. +// Hashers have reference semantics. +// Call MakeHasher to create a Hasher. +type Hasher struct { + memo map[types.Type]uint32 +} + +// MakeHasher returns a new Hasher instance. +func MakeHasher() Hasher { + return Hasher{make(map[types.Type]uint32)} +} + +// Hash computes a hash value for the given type t such that +// Identical(t, t') => Hash(t) == Hash(t'). +func (h Hasher) Hash(t types.Type) uint32 { + hash, ok := h.memo[t] + if !ok { + hash = h.hashFor(t) + h.memo[t] = hash + } + return hash +} + +// hashString computes the Fowler–Noll–Vo hash of s. +func hashString(s string) uint32 { + var h uint32 + for i := 0; i < len(s); i++ { + h ^= uint32(s[i]) + h *= 16777619 + } + return h +} + +// hashFor computes the hash of t. +func (h Hasher) hashFor(t types.Type) uint32 { + // See Identical for rationale. + switch t := t.(type) { + case *types.Basic: + return uint32(t.Kind()) + + case *types.Array: + return 9043 + 2*uint32(t.Len()) + 3*h.Hash(t.Elem()) + + case *types.Slice: + return 9049 + 2*h.Hash(t.Elem()) + + case *types.Struct: + var hash uint32 = 9059 + for i, n := 0, t.NumFields(); i < n; i++ { + f := t.Field(i) + if f.Anonymous() { + hash += 8861 + } + hash += hashString(t.Tag(i)) + hash += hashString(f.Name()) // (ignore f.Pkg) + hash += h.Hash(f.Type()) + } + return hash + + case *types.Pointer: + return 9067 + 2*h.Hash(t.Elem()) + + case *types.Signature: + var hash uint32 = 9091 + if t.Variadic() { + hash *= 8863 + } + return hash + 3*h.hashTuple(t.Params()) + 5*h.hashTuple(t.Results()) + + case *types.Interface: + var hash uint32 = 9103 + for i, n := 0, t.NumMethods(); i < n; i++ { + // See go/types.identicalMethods for rationale. + // Method order is not significant. + // Ignore m.Pkg(). + m := t.Method(i) + hash += 3*hashString(m.Name()) + 5*h.Hash(m.Type()) + } + return hash + + case *types.Map: + return 9109 + 2*h.Hash(t.Key()) + 3*h.Hash(t.Elem()) + + case *types.Chan: + return 9127 + 2*uint32(t.Dir()) + 3*h.Hash(t.Elem()) + + case *types.Named: + // Not safe with a copying GC; objects may move. + return uint32(reflect.ValueOf(t.Obj()).Pointer()) + + case *types.Tuple: + return h.hashTuple(t) + } + panic(t) +} + +func (h Hasher) hashTuple(tuple *types.Tuple) uint32 { + // See go/types.identicalTypes for rationale. + n := tuple.Len() + var hash uint32 = 9137 + 2*uint32(n) + for i := 0; i < n; i++ { + hash += 3 * h.Hash(tuple.At(i).Type()) + } + return hash +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/methodsetcache.go b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/methodsetcache.go new file mode 100644 index 0000000000000..32084610f49a0 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/methodsetcache.go @@ -0,0 +1,72 @@ +// Copyright 2014 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. + +// This file implements a cache of method sets. + +package typeutil + +import ( + "go/types" + "sync" +) + +// A MethodSetCache records the method set of each type T for which +// MethodSet(T) is called so that repeat queries are fast. +// The zero value is a ready-to-use cache instance. +type MethodSetCache struct { + mu sync.Mutex + named map[*types.Named]struct{ value, pointer *types.MethodSet } // method sets for named N and *N + others map[types.Type]*types.MethodSet // all other types +} + +// MethodSet returns the method set of type T. It is thread-safe. +// +// If cache is nil, this function is equivalent to types.NewMethodSet(T). +// Utility functions can thus expose an optional *MethodSetCache +// parameter to clients that care about performance. +// +func (cache *MethodSetCache) MethodSet(T types.Type) *types.MethodSet { + if cache == nil { + return types.NewMethodSet(T) + } + cache.mu.Lock() + defer cache.mu.Unlock() + + switch T := T.(type) { + case *types.Named: + return cache.lookupNamed(T).value + + case *types.Pointer: + if N, ok := T.Elem().(*types.Named); ok { + return cache.lookupNamed(N).pointer + } + } + + // all other types + // (The map uses pointer equivalence, not type identity.) + mset := cache.others[T] + if mset == nil { + mset = types.NewMethodSet(T) + if cache.others == nil { + cache.others = make(map[types.Type]*types.MethodSet) + } + cache.others[T] = mset + } + return mset +} + +func (cache *MethodSetCache) lookupNamed(named *types.Named) struct{ value, pointer *types.MethodSet } { + if cache.named == nil { + cache.named = make(map[*types.Named]struct{ value, pointer *types.MethodSet }) + } + // Avoid recomputing mset(*T) for each distinct Pointer + // instance whose underlying type is a named type. + msets, ok := cache.named[named] + if !ok { + msets.value = types.NewMethodSet(named) + msets.pointer = types.NewMethodSet(types.NewPointer(named)) + cache.named[named] = msets + } + return msets +} diff --git a/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/ui.go b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/ui.go new file mode 100644 index 0000000000000..9849c24cef3f8 --- /dev/null +++ b/src/cmd/vendor/golang.org/x/tools/go/types/typeutil/ui.go @@ -0,0 +1,52 @@ +// Copyright 2014 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. + +package typeutil + +// This file defines utilities for user interfaces that display types. + +import "go/types" + +// IntuitiveMethodSet returns the intuitive method set of a type T, +// which is the set of methods you can call on an addressable value of +// that type. +// +// The result always contains MethodSet(T), and is exactly MethodSet(T) +// for interface types and for pointer-to-concrete types. +// For all other concrete types T, the result additionally +// contains each method belonging to *T if there is no identically +// named method on T itself. +// +// This corresponds to user intuition about method sets; +// this function is intended only for user interfaces. +// +// The order of the result is as for types.MethodSet(T). +// +func IntuitiveMethodSet(T types.Type, msets *MethodSetCache) []*types.Selection { + isPointerToConcrete := func(T types.Type) bool { + ptr, ok := T.(*types.Pointer) + return ok && !types.IsInterface(ptr.Elem()) + } + + var result []*types.Selection + mset := msets.MethodSet(T) + if types.IsInterface(T) || isPointerToConcrete(T) { + for i, n := 0, mset.Len(); i < n; i++ { + result = append(result, mset.At(i)) + } + } else { + // T is some other concrete type. + // Report methods of T and *T, preferring those of T. + pmset := msets.MethodSet(types.NewPointer(T)) + for i, n := 0, pmset.Len(); i < n; i++ { + meth := pmset.At(i) + if m := mset.Lookup(meth.Obj().Pkg(), meth.Obj().Name()); m != nil { + meth = m + } + result = append(result, meth) + } + + } + return result +} diff --git a/src/cmd/vendor/vendor.json b/src/cmd/vendor/vendor.json index 6e077e4ae17c5..b952b93c08a59 100644 --- a/src/cmd/vendor/vendor.json +++ b/src/cmd/vendor/vendor.json @@ -165,6 +165,210 @@ "path": "golang.org/x/sys/windows/svc/mgr", "revision": "90868a75fefd03942536221d7c0e2f84ec62a668", "revisionTime": "2018-08-01T20:46:00Z" + }, + { + "checksumSHA1": "witNkDO7koGO7+oxpBMZBvoxz3c=", + "path": "golang.org/x/tools/go/analysis", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "NPcubwbqmr2yGfGztLqizwbXrwM=", + "path": "golang.org/x/tools/go/analysis/cmd/vet-lite", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "kWG+JiD2mA+2pnSeYJrKLHHgT+s=", + "path": "golang.org/x/tools/go/analysis/internal/analysisflags", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "c4FY3+yRC2GHON66hIU254nQxA8=", + "path": "golang.org/x/tools/go/analysis/internal/facts", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "Zuz7FbEMWtUNCKTA+ofVkkDl1Ic=", + "path": "golang.org/x/tools/go/analysis/internal/unitchecker", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "fxi2KL0typcqGp87Qa9CxSp89Sk=", + "path": "golang.org/x/tools/go/analysis/passes/asmdecl", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "AK5vKjJmQD1u/6v/s107upAF03w=", + "path": "golang.org/x/tools/go/analysis/passes/assign", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "qRQNlOhRmTPecqsjJMf3Rxd7M1g=", + "path": "golang.org/x/tools/go/analysis/passes/atomic", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "zhnbma06ExmGYTu5QaGAi5+QciY=", + "path": "golang.org/x/tools/go/analysis/passes/bools", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "HWcvlzqG20E9BaG4/j3u9tnUyZ4=", + "path": "golang.org/x/tools/go/analysis/passes/buildtag", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "ekVwfAw224CT/eBihMCzAOzIHiE=", + "path": "golang.org/x/tools/go/analysis/passes/cgocall", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "dwtQdPi0Jb9BYVr0Gynh5NpCSz8=", + "path": "golang.org/x/tools/go/analysis/passes/composite", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "6M8xb//gcLk3dSpRq6/fb/8Wvqk=", + "path": "golang.org/x/tools/go/analysis/passes/copylock", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "DPQnIktTEV7cNBNDRIpg0OK6v9Q=", + "path": "golang.org/x/tools/go/analysis/passes/ctrlflow", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "GJjZZhXYqMoGmym/2DpExqHP+Cw=", + "path": "golang.org/x/tools/go/analysis/passes/httpresponse", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "Q76YV1xYtBCBsZk7uKXqih7iHL4=", + "path": "golang.org/x/tools/go/analysis/passes/inspect", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "Y7NBmaqiGnVWf3yn16cwbWmgUhI=", + "path": "golang.org/x/tools/go/analysis/passes/internal/analysisutil", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "Fjj6sV+qmJwvxGt/i8fLIma9Lzs=", + "path": "golang.org/x/tools/go/analysis/passes/loopclosure", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "VZE2qx/m2esvfEreS0RCaVoWYhc=", + "path": "golang.org/x/tools/go/analysis/passes/lostcancel", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "xf9nMwSbFWJXDC9W+Gnus+uU0Nw=", + "path": "golang.org/x/tools/go/analysis/passes/nilfunc", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "PKByrfYKilYhkhAE01z5Om0Tr+w=", + "path": "golang.org/x/tools/go/analysis/passes/pkgfact", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "BrlVsK8u6SPMyvoWdkwS4IAXVRI=", + "path": "golang.org/x/tools/go/analysis/passes/printf", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "3w9Q99Mxrf8qEU+FH7lSyy5hwc4=", + "path": "golang.org/x/tools/go/analysis/passes/shift", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "oeR6BB6OmfoYReHyNLEX9BbF1cI=", + "path": "golang.org/x/tools/go/analysis/passes/stdmethods", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "rPSH7/W3vsomdmSIgdEDrzaCQyk=", + "path": "golang.org/x/tools/go/analysis/passes/structtag", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "yHrglPUc3Ia12nwO0l/I0ArT3to=", + "path": "golang.org/x/tools/go/analysis/passes/tests", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "en0VsP2OoNX40F/bNfbO6geSgi4=", + "path": "golang.org/x/tools/go/analysis/passes/unreachable", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "641akvyeQUx5MqoHiyKwRps4vEg=", + "path": "golang.org/x/tools/go/analysis/passes/unsafeptr", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "cm27h0jINv4jlgiHMn7q572FXTY=", + "path": "golang.org/x/tools/go/analysis/passes/unusedresult", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "/bQnex6L/nyDuZCIIRbM6Is/IRY=", + "path": "golang.org/x/tools/go/ast/astutil", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "qnZLWirp4hAxafiKvH+nnmgGf8Q=", + "path": "golang.org/x/tools/go/ast/inspector", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "+g97ZSLGNNbqfBzpYje8fA5PvXs=", + "path": "golang.org/x/tools/go/cfg", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "JWIR0GVqbDYhTW9mh4zpY/ve6Ro=", + "path": "golang.org/x/tools/go/types/objectpath", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" + }, + { + "checksumSHA1": "kyVWOWK3PkDKCtXRJffE60MrfOo=", + "path": "golang.org/x/tools/go/types/typeutil", + "revision": "c76e1ad98a635a7c069d7ab43d31fcf38381facc", + "revisionTime": "2018-11-05T19:48:08Z" } ], "rootPath": "/cmd" From 95a4f793c077ab7b13fdb7505b65ff19a97a07f9 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 6 Nov 2018 10:16:17 -0800 Subject: [PATCH 0992/1663] cmd/compile: don't deadcode eliminate labels Dead-code eliminating labels is tricky because there might be gotos that can still reach them. Bug probably introduced with CL 91056 Fixes #28616 Change-Id: I6680465134e3486dcb658896f5172606cc51b104 Reviewed-on: https://go-review.googlesource.com/c/147817 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick Reviewed-by: Iskander Sharipov --- src/cmd/compile/internal/gc/typecheck.go | 12 +++++++++++- test/fixedbugs/issue28616.go | 25 ++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 test/fixedbugs/issue28616.go diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index 06dd176b3718d..8ec60cbbba763 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -4084,6 +4084,12 @@ func deadcode(fn *Node) { } func deadcodeslice(nn Nodes) { + var lastLabel = -1 + for i, n := range nn.Slice() { + if n != nil && n.Op == OLABEL { + lastLabel = i + } + } for i, n := range nn.Slice() { // Cut is set to true when all nodes after i'th position // should be removed. @@ -4106,10 +4112,14 @@ func deadcodeslice(nn Nodes) { // If "then" or "else" branch ends with panic or return statement, // it is safe to remove all statements after this node. // isterminating is not used to avoid goto-related complications. + // We must be careful not to deadcode-remove labels, as they + // might be the target of a goto. See issue 28616. if body := body.Slice(); len(body) != 0 { switch body[(len(body) - 1)].Op { case ORETURN, ORETJMP, OPANIC: - cut = true + if i > lastLabel { + cut = true + } } } } diff --git a/test/fixedbugs/issue28616.go b/test/fixedbugs/issue28616.go new file mode 100644 index 0000000000000..f1ba97479756e --- /dev/null +++ b/test/fixedbugs/issue28616.go @@ -0,0 +1,25 @@ +// compile + +// Copyright 2018 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. + +// Make sure we don't dead code eliminate a label. + +package p + +var i int + +func f() { + + if true { + + if i == 1 { + goto label + } + + return + } + +label: +} From 35c05542938416cde6a366505c24568ea5ccd98e Mon Sep 17 00:00:00 2001 From: Cherry Zhang Date: Fri, 2 Nov 2018 16:51:14 -0400 Subject: [PATCH 0993/1663] cmd/asm: rename R18 to R18_PLATFORM on ARM64 In ARM64 ABI, R18 is the "platform register", the use of which is OS specific. The OS could choose to reserve this register. In practice, it seems fine to use R18 on Linux but not on darwin (iOS). Rename R18 to R18_PLATFORM to prevent accidental use. There is no R18 usage within the standard library (besides tests, which are updated). Fixes #26110 Change-Id: Icef7b9549e2049db1df307a0180a3c90a12d7a84 Reviewed-on: https://go-review.googlesource.com/c/147218 Run-TryBot: Cherry Zhang TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- doc/asm.html | 1 + src/cmd/asm/internal/arch/arch.go | 3 ++ src/cmd/asm/internal/asm/operand_test.go | 1 + src/cmd/asm/internal/asm/testdata/arm64.s | 8 +-- src/cmd/asm/internal/asm/testdata/arm64enc.s | 54 ++++++++++---------- src/cmd/internal/obj/arm64/doc.go | 10 ++-- 6 files changed, 41 insertions(+), 36 deletions(-) diff --git a/doc/asm.html b/doc/asm.html index f2f8fad5766c2..debb1e2fc6a1d 100644 --- a/doc/asm.html +++ b/doc/asm.html @@ -740,6 +740,7 @@

      ARM64

      R18 is the "platform register", reserved on the Apple platform. +To prevent accidental misuse, the register is named R18_PLATFORM. R27 and R28 are reserved by the compiler and linker. R29 is the frame pointer. R30 is the link register. diff --git a/src/cmd/asm/internal/arch/arch.go b/src/cmd/asm/internal/arch/arch.go index ecea6ba97d0f0..eaa5cb89580fc 100644 --- a/src/cmd/asm/internal/arch/arch.go +++ b/src/cmd/asm/internal/arch/arch.go @@ -258,6 +258,9 @@ func archArm64() *Arch { for i := arm64.REG_R0; i <= arm64.REG_R31; i++ { register[obj.Rconv(i)] = int16(i) } + // Rename R18 to R18_PLATFORM to avoid accidental use. + register["R18_PLATFORM"] = register["R18"] + delete(register, "R18") for i := arm64.REG_F0; i <= arm64.REG_F31; i++ { register[obj.Rconv(i)] = int16(i) } diff --git a/src/cmd/asm/internal/asm/operand_test.go b/src/cmd/asm/internal/asm/operand_test.go index df60b71ebd53d..69393b6b2052a 100644 --- a/src/cmd/asm/internal/asm/operand_test.go +++ b/src/cmd/asm/internal/asm/operand_test.go @@ -607,6 +607,7 @@ var arm64OperandTests = []operandTest{ {"R0", "R0"}, {"R10", "R10"}, {"R11", "R11"}, + {"R18_PLATFORM", "R18"}, {"$4503601774854144.0", "$(4503601774854144.0)"}, {"$runtime·badsystemstack(SB)", "$runtime.badsystemstack(SB)"}, {"ZR", "ZR"}, diff --git a/src/cmd/asm/internal/asm/testdata/arm64.s b/src/cmd/asm/internal/asm/testdata/arm64.s index b851ba411ef79..a577c4da9dde6 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64.s +++ b/src/cmd/asm/internal/asm/testdata/arm64.s @@ -47,8 +47,8 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8 ADD R2.SXTX<<1, RSP, RSP // ffe7228b ADD ZR.SXTX<<1, R2, R3 // 43e43f8b ADDW R2.SXTW, R10, R12 // 4cc1220b - ADD R18.UXTX, R14, R17 // d161328b - ADDSW R18.UXTW, R14, R17 // d141322b + ADD R19.UXTX, R14, R17 // d161338b + ADDSW R19.UXTW, R14, R17 // d141332b ADDS R12.SXTX, R3, R1 // 61e02cab SUB R19.UXTH<<4, R2, R21 // 553033cb SUBW R1.UXTX<<1, R3, R2 // 6264214b @@ -144,7 +144,7 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8 MOVD (R2)(R6.SXTW), R4 // 44c866f8 MOVD (R3)(R6), R5 // MOVD (R3)(R6*1), R5 // 656866f8 MOVD (R2)(R6), R4 // MOVD (R2)(R6*1), R4 // 446866f8 - MOVWU (R19)(R18<<2), R18 // 727a72b8 + MOVWU (R19)(R20<<2), R20 // 747a74b8 MOVD (R2)(R6<<3), R4 // 447866f8 MOVD (R3)(R7.SXTX<<3), R8 // 68f867f8 MOVWU (R5)(R4.UXTW), R10 // aa4864b8 @@ -154,7 +154,7 @@ TEXT foo(SB), DUPOK|NOSPLIT, $-8 MOVHU (R1)(R2<<1), R5 // 25786278 MOVB (R9)(R3.UXTW), R6 // 2649a338 MOVB (R10)(R6), R15 // MOVB (R10)(R6*1), R15 // 4f69a638 - MOVH (R5)(R7.SXTX<<1), R18 // b2f8a778 + MOVH (R5)(R7.SXTX<<1), R19 // b3f8a778 MOVH (R8)(R4<<1), R10 // 0a79a478 MOVW (R9)(R8.SXTW<<2), R19 // 33d9a8b8 MOVW (R1)(R4.SXTX), R11 // 2be8a4b8 diff --git a/src/cmd/asm/internal/asm/testdata/arm64enc.s b/src/cmd/asm/internal/asm/testdata/arm64enc.s index 432ab74493c20..a2850e2e46b69 100644 --- a/src/cmd/asm/internal/asm/testdata/arm64enc.s +++ b/src/cmd/asm/internal/asm/testdata/arm64enc.s @@ -56,7 +56,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 BFXILW $3, R27, $23, R14 // 6e670333 BFXIL $26, R8, $16, R20 // 14a55ab3 BICW R7@>15, R5, R16 // b03ce70a - BIC R12@>13, R12, R18 // 9235ec8a + BIC R12@>13, R12, R19 // 9335ec8a BICSW R25->20, R3, R20 // 7450b96a BICS R19->12, R1, R23 // 3730b3ea BICS R19, R1, R23 // 370033ea @@ -76,7 +76,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 CCMN LE, R30, R12, $6 // c6d34cba CCMPW VS, R29, $15, $7 // a76b4f7a CCMP LE, R7, $19, $3 // e3d853fa - CCMPW HS, R18, R6, $0 // 4022467a + CCMPW HS, R19, R6, $0 // 6022467a CCMP LT, R30, R6, $7 // c7b346fa CCMN MI, ZR, R1, $4 // e44341ba CSINCW HS, ZR, R27, R14 // ee279b1a @@ -118,7 +118,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 CRC32H R3, R21, R27 // bb46c31a CRC32W R22, R30, R9 // c94bd61a CRC32X R20, R4, R15 // 8f4cd49a - CRC32CB R18, R27, R22 // 7653d21a + CRC32CB R19, R27, R22 // 7653d31a CRC32CH R21, R0, R20 // 1454d51a CRC32CW R9, R3, R21 // 7558c91a CRC32CX R11, R0, R24 // 185ccb9a @@ -133,7 +133,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 CSINVW AL, R23, R21, R5 // e5e2955a CSINV LO, R2, R11, R14 // 4e308bda CSNEGW HS, R16, R29, R10 // 0a269d5a - CSNEG NE, R21, R18, R11 // ab1692da + CSNEG NE, R21, R19, R11 // ab1693da //TODO DC DCPS1 $11378 // 418ea5d4 DCPS2 $10699 // 6239a5d4 @@ -185,23 +185,23 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 MOVBU.P 42(R2), R12 // 4ca44238 MOVBU.W -27(R2), R14 // 4e5c5e38 MOVBU 2916(R24), R3 // 03936d39 - MOVBU (R18)(R14<<0), R23 // 577a6e38 + MOVBU (R19)(R14<<0), R23 // 777a6e38 MOVBU (R2)(R8.SXTX), R19 // 53e86838 MOVBU (R27)(R23), R14 // MOVBU (R27)(R23*1), R14 // 6e6b7738 MOVHU.P 107(R14), R13 // cdb54678 MOVHU.W 192(R3), R2 // 620c4c78 - MOVHU 6844(R4), R18 // 92787579 + MOVHU 6844(R4), R19 // 93787579 MOVHU (R5)(R25.SXTW), R15 // afc87978 - //TODO MOVBW.P 77(R18), R11 // 4bd6c438 + //TODO MOVBW.P 77(R19), R11 // 6bd6c438 MOVB.P 36(RSP), R27 // fb478238 - //TODO MOVBW.W -57(R18), R13 // 4d7edc38 + //TODO MOVBW.W -57(R19), R13 // 6d7edc38 MOVB.W -178(R16), R24 // 18ee9438 //TODO MOVBW 430(R8), R22 // 16b9c639 MOVB 997(R9), R23 // 37958f39 //TODO MOVBW (R2<<1)(R21), R15 // af7ae238 //TODO MOVBW (R26)(R0), R21 // 1568fa38 MOVB (R5)(R15), R16 // MOVB (R5)(R15*1), R16 // b068af38 - MOVB (R18)(R26.SXTW), R19 // 53caba38 + MOVB (R19)(R26.SXTW), R19 // 73caba38 MOVB (R29)(R30), R14 // MOVB (R29)(R30*1), R14 // ae6bbe38 //TODO MOVHW.P 218(R22), R25 // d9a6cd78 MOVH.P 179(R23), R5 // e5368b78 @@ -212,7 +212,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 //TODO MOVHW (R22)(R24.SXTX), R4 // c4eaf878 MOVH (R26)(R30.UXTW<<1), ZR // 5f5bbe78 MOVW.P -58(R16), R2 // 02669cb8 - MOVW.W -216(R18), R8 // 488e92b8 + MOVW.W -216(R19), R8 // 688e92b8 MOVW 4764(R23), R10 // ea9e92b9 MOVW (R8)(R3.UXTW), R17 // 1149a3b8 //TODO LDTR -0x1e(R3), R4 // 64285eb8 @@ -297,7 +297,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 RET // c0035fd6 REVW R8, R10 // 0a09c05a REV R1, R2 // 220cc0da - REV16W R21, R18 // b206c05a + REV16W R21, R19 // b306c05a REV16 R25, R4 // 2407c0da REV32 R27, R21 // 750bc0da EXTRW $27, R4, R25, R19 // 336f8413 @@ -308,7 +308,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 ROR R0, R23, R2 // e22ec09a SBCW R4, R8, R24 // 1801045a SBC R25, R10, R26 // 5a0119da - SBCSW R27, R18, R18 // 52021b7a + SBCSW R27, R19, R19 // 73021b7a SBCS R5, R9, R5 // 250105fa SBFIZW $9, R10, $18, R22 // 56451713 SBFIZ $6, R11, $15, R20 // 74397a93 @@ -337,7 +337,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 //TODO STNPW 44(R1), R3, R10 // 2a8c0528 //TODO STNP 0x108(R3), ZR, R7 // 67fc10a8 LDP.P -384(R3), (R22, R26) // 7668e8a8 - LDP.W 280(R8), (R18, R11) // 12add1a9 + LDP.W 280(R8), (R19, R11) // 13add1a9 STP.P (R22, R27), 352(R0) // 166c96a8 STP.W (R17, R11), 96(R8) // 112d86a9 MOVW.P R20, -28(R1) // 34441eb8 @@ -360,22 +360,22 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 MOVB R2, (R29)(R26) // MOVB R2, (R29)(R26*1) // a26b3a38 MOVH R11, -80(R23) // eb021b78 MOVH R11, (R27)(R14.SXTW<<1) // 6bdb2e78 - MOVB R18, (R0)(R4) // MOVB R18, (R0)(R4*1) // 12682438 + MOVB R19, (R0)(R4) // MOVB R19, (R0)(R4*1) // 13682438 MOVB R1, (R6)(R4) // MOVB R1, (R6)(R4*1) // c1682438 MOVH R3, (R11)(R13<<1) // 63792d78 //TODO STTR 55(R4), R29 // 9d7803b8 //TODO STTR 124(R5), R25 // b9c807f8 //TODO STTRB -28(R23), R16 // f04a1e38 - //TODO STTRH 9(R10), R18 // 52990078 + //TODO STTRH 9(R10), R19 // 53990078 STXP (R1, R2), (R3), R10 // 61082ac8 STXP (R1, R2), (RSP), R10 // e10b2ac8 STXPW (R1, R2), (R3), R10 // 61082a88 STXPW (R1, R2), (RSP), R10 // e10b2a88 - STXRW R2, (R19), R18 // 627e1288 + STXRW R2, (R19), R20 // 627e1488 STXR R15, (R21), R13 // af7e0dc8 STXRB R7, (R9), R24 // 277d1808 STXRH R12, (R3), R8 // 6c7c0848 - SUBW R20.UXTW<<2, R23, R18 // f24a344b + SUBW R20.UXTW<<2, R23, R19 // f34a344b SUB R5.SXTW<<2, R1, R26 // 3ac825cb SUB $(1923<<12), R4, R27 // SUB $7876608, R4, R27 // 9b0c5ed1 SUBW $(1923<<12), R4, R27 // SUBW $7876608, R4, R27 // 9b0c5e51 @@ -410,12 +410,12 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 UBFXW $3, R7, $20, R15 // ef580353 UBFX $33, R17, $25, R5 // 25e661d3 UDIVW R8, R21, R15 // af0ac81a - UDIV R2, R18, R21 // 550ac29a + UDIV R2, R19, R21 // 750ac29a UMADDL R0, R20, R17, R17 // 3152a09b UMSUBL R22, R4, R3, R7 // 6790b69b - UMNEGL R3, R18, R1 // 41fea39b + UMNEGL R3, R19, R1 // 61fea39b UMULH R24, R20, R24 // 987ed89b - UMULL R18, R22, R19 // d37eb29b + UMULL R19, R22, R19 // d37eb39b UXTBW R2, R6 // 461c0053 UXTHW R7, R20 // f43c0053 VCNT V0.B8, V0.B8 // 0058200e @@ -471,7 +471,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 //TODO FCVTAS F27, R7 // 6703241e //TODO FCVTAS F19, R26 // 7a02249e //TODO FCVTAS F4, R0 // 8000641e - //TODO FCVTAS F3, R18 // 7200649e + //TODO FCVTAS F3, R19 // 7300649e //TODO FCVTAU F18, F28 // 5cca217e //TODO VFCVTAU V30.S4, V27.S4 // dbcb216e //TODO FCVTAU F0, R2 // 0200251e @@ -482,16 +482,16 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 //TODO VFCVTL2 V15.H8, V25.S4 // f979214e //TODO FCVTMS F21, F28 // bcba215e //TODO VFCVTMS V5.D2, V2.D2 // a2b8614e - //TODO FCVTMS F31, R18 // f203301e + //TODO FCVTMS F31, R19 // f303301e //TODO FCVTMS F23, R16 // f002309e //TODO FCVTMS F16, R22 // 1602701e //TODO FCVTMS F14, R19 // d301709e //TODO FCVTMU F14, F8 // c8b9217e //TODO VFCVTMU V7.D2, V1.D2 // e1b8616e //TODO FCVTMU F2, R0 // 4000311e - //TODO FCVTMU F23, R18 // f202319e + //TODO FCVTMU F23, R19 // f302319e //TODO FCVTMU F16, R17 // 1102711e - //TODO FCVTMU F12, R18 // 9201719e + //TODO FCVTMU F12, R19 // 9301719e //TODO VFCVTN V23.D2, V26.S2 // fa6a610e //TODO VFCVTN2 V2.D2, V31.S4 // 5f68614e //TODO FCVTNS F3, F27 // 7ba8215e @@ -540,7 +540,7 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 //TODO FCVTZU $14, F24, R20 // 14cb191e //TODO FCVTZU $6, F25, R17 // 31eb199e //TODO FCVTZU $5, F17, R10 // 2aee591e - //TODO FCVTZU $6, F7, R18 // f2e8599e + //TODO FCVTZU $6, F7, R19 // f3e8599e FCVTZUSW F2, R9 // 4900391e FCVTZUS F12, R29 // 9d01399e FCVTZUDW F27, R22 // 7603791e @@ -682,11 +682,11 @@ TEXT asmtest(SB),DUPOK|NOSPLIT,$-8 VLD1.P (R19)(R4), [V24.B8, V25.B8] // VLD1.P (R19)(R4*1), [V24.B8, V25.B8] // 78a2c40c VLD1.P (R20)(R8), [V7.H8, V8.H8, V9.H8] // VLD1.P (R20)(R8*1), [V7.H8, V8.H8, V9.H8] // 8766c84c VLD1.P 32(R30), [V5.B8, V6.B8, V7.B8, V8.B8] // c523df0c - VLD1 (R18), V14.B[15] // 4e1e404d + VLD1 (R19), V14.B[15] // 6e1e404d VLD1 (R29), V0.H[1] // a04b400d VLD1 (R27), V2.S[0] // 6283400d VLD1 (R21), V5.D[1] // a586404d - VLD1.P 1(R18), V10.B[14] // 4a1adf4d + VLD1.P 1(R19), V10.B[14] // 6a1adf4d VLD1.P (R3)(R14), V16.B[11] // VLD1.P (R3)(R14*1), V16.B[11] // 700cce4d VLD1.P 2(R1), V28.H[2] // 3c50df0d VLD1.P (R13)(R20), V9.H[2] // VLD1.P (R13)(R20*1), V9.H[2] // a951d40d diff --git a/src/cmd/internal/obj/arm64/doc.go b/src/cmd/internal/obj/arm64/doc.go index 845fb2281701f..7fb129989b110 100644 --- a/src/cmd/internal/obj/arm64/doc.go +++ b/src/cmd/internal/obj/arm64/doc.go @@ -89,7 +89,7 @@ such as str, stur, strb, sturb, strh, sturh stlr, stlrb. stlrh, st1. Examples: MOVD R29, 384(R19) <=> str x29, [x19,#384] MOVB.P R30, 30(R4) <=> strb w30, [x4],#30 - STLRH R21, (R18) <=> stlrh w21, [x18] + STLRH R21, (R19) <=> stlrh w21, [x19] (2) MADD, MADDW, MSUB, MSUBW, SMADDL, SMSUBL, UMADDL, UMSUBL , , , @@ -127,7 +127,7 @@ such as str, stur, strb, sturb, strh, sturh stlr, stlrb. stlrh, st1. Examples: CCMN VS, R13, R22, $10 <=> ccmn x13, x22, #0xa, vs - CCMPW HS, R18, R14, $11 <=> ccmp w18, w14, #0xb, cs + CCMPW HS, R19, R14, $11 <=> ccmp w19, w14, #0xb, cs (9) CSEL, CSELW, CSNEG, CSNEGW, CSINC, CSINCW , , , ; FCSELD, FCSELS , , , @@ -144,12 +144,12 @@ FCSELD, FCSELS , , , Examples: STLXR ZR, (R15), R16 <=> stlxr w16, xzr, [x15] - STXRB R9, (R21), R18 <=> stxrb w18, w9, [x21] + STXRB R9, (R21), R19 <=> stxrb w19, w9, [x21] (12) STLXP, STLXPW, STXP, STXPW (, ), (), Examples: - STLXP (R17, R18), (R4), R5 <=> stlxp w5, x17, x18, [x4] + STLXP (R17, R19), (R4), R5 <=> stlxp w5, x17, x19, [x4] STXPW (R30, R25), (R22), R13 <=> stxp w13, w30, w25, [x22] 2. Expressions for special arguments. @@ -173,7 +173,7 @@ Extended registers are written as {.{<<}}. can be UXTB, UXTH, UXTW, UXTX, SXTB, SXTH, SXTW or SXTX. Examples: - ADDS R18.UXTB<<4, R9, R26 <=> adds x26, x9, w18, uxtb #4 + ADDS R19.UXTB<<4, R9, R26 <=> adds x26, x9, w19, uxtb #4 ADDSW R14.SXTX, R14, R6 <=> adds w6, w14, w14, sxtx Memory references: [{,#0}] is written as (Rn|RSP), a base register and an immediate From 9c772522ea365be6a916d428a981969befedad7f Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Tue, 6 Nov 2018 19:43:55 +0100 Subject: [PATCH 0994/1663] cmd/compile: add new format to known_formats This change fixes a TestFormat failure in fmt_test by adding a recently introduced new known format (%q for syntax.Error). Fixes #28621 Change-Id: I026ec88c334549a957a692c1652a860c57e23dae Reviewed-on: https://go-review.googlesource.com/c/147837 Reviewed-by: Ian Lance Taylor --- src/cmd/compile/fmt_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/src/cmd/compile/fmt_test.go b/src/cmd/compile/fmt_test.go index eaa2aa8dbd8d9..05d13b58a565c 100644 --- a/src/cmd/compile/fmt_test.go +++ b/src/cmd/compile/fmt_test.go @@ -660,6 +660,7 @@ var knownFormats = map[string]string{ "cmd/compile/internal/ssa.rbrank %d": "", "cmd/compile/internal/ssa.regMask %d": "", "cmd/compile/internal/ssa.register %d": "", + "cmd/compile/internal/syntax.Error %q": "", "cmd/compile/internal/syntax.Expr %#v": "", "cmd/compile/internal/syntax.Node %T": "", "cmd/compile/internal/syntax.Operator %s": "", From ca33f33b1420cf333c59c6458bb9bc8910c91ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 25 Oct 2018 13:42:46 +0100 Subject: [PATCH 0995/1663] cmd/go: make 'go test -h' print two lines MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Like every other command's -h flag. To achieve this, pass the command's usage function to the cmdflag package, since that package is used by multiple commands and cannot directly access *base.Command. This also lets us get rid of testFlag1 and testFlag2, and instead have contiguous raw strings for the test and testflag help docs. Fixes #26999. Change-Id: I2ebd66835ee61fa83270816a01fa312425224bb3 Reviewed-on: https://go-review.googlesource.com/c/144558 Run-TryBot: Daniel Martí TryBot-Result: Gobot Gobot Reviewed-by: Alan Donovan --- src/cmd/go/internal/cmdflag/flag.go | 6 ++--- src/cmd/go/internal/test/test.go | 36 ++++++++-------------------- src/cmd/go/internal/test/testflag.go | 4 ++-- src/cmd/go/internal/vet/vet.go | 2 +- src/cmd/go/internal/vet/vetflag.go | 4 ++-- src/cmd/go/main.go | 11 --------- src/cmd/go/testdata/script/help.txt | 8 ++++++- 7 files changed, 25 insertions(+), 46 deletions(-) diff --git a/src/cmd/go/internal/cmdflag/flag.go b/src/cmd/go/internal/cmdflag/flag.go index b2a67e6f74a82..7f2c53def8fa2 100644 --- a/src/cmd/go/internal/cmdflag/flag.go +++ b/src/cmd/go/internal/cmdflag/flag.go @@ -79,15 +79,15 @@ func AddKnownFlags(cmd string, defns []*Defn) { // Parse sees if argument i is present in the definitions and if so, // returns its definition, value, and whether it consumed an extra word. -// If the flag begins (cmd+".") it is ignored for the purpose of this function. -func Parse(cmd string, defns []*Defn, args []string, i int) (f *Defn, value string, extra bool) { +// If the flag begins (cmd.Name()+".") it is ignored for the purpose of this function. +func Parse(cmd string, usage func(), defns []*Defn, args []string, i int) (f *Defn, value string, extra bool) { arg := args[i] if strings.HasPrefix(arg, "--") { // reduce two minuses to one arg = arg[1:] } switch arg { case "-?", "-h", "-help": - base.Usage() + usage() } if arg == "" || arg[0] != '-' { return diff --git a/src/cmd/go/internal/test/test.go b/src/cmd/go/internal/test/test.go index 750b515e41487..b38eb4c41dafa 100644 --- a/src/cmd/go/internal/test/test.go +++ b/src/cmd/go/internal/test/test.go @@ -124,16 +124,6 @@ A cached test result is treated as executing in no time at all, so a successful package test result will be cached and reused regardless of -timeout setting. -` + strings.TrimSpace(testFlag1) + ` See 'go help testflag' for details. - -For more about build flags, see 'go help build'. -For more about specifying packages, see 'go help packages'. - -See also: go build, go vet. -`, -} - -const testFlag1 = ` In addition to the build flags, the flags handled by 'go test' itself are: -args @@ -164,15 +154,13 @@ In addition to the build flags, the flags handled by 'go test' itself are: The test still runs (unless -c or -i is specified). The test binary also accepts flags that control execution of the test; these -flags are also accessible by 'go test'. -` - -// Usage prints the usage message for 'go test -h' and exits. -func Usage() { - os.Stderr.WriteString("usage: " + testUsage + "\n\n" + - strings.TrimSpace(testFlag1) + "\n\n\t" + - strings.TrimSpace(testFlag2) + "\n") - os.Exit(2) +flags are also accessible by 'go test'. See 'go help testflag' for details. + +For more about build flags, see 'go help build'. +For more about specifying packages, see 'go help packages'. + +See also: go build, go vet. +`, } var HelpTestflag = &base.Command{ @@ -190,11 +178,6 @@ options of pprof control how the information is presented. The following flags are recognized by the 'go test' command and control the execution of any test: - ` + strings.TrimSpace(testFlag2) + ` -`, -} - -const testFlag2 = ` -bench regexp Run only those benchmarks matching a regular expression. By default, no benchmarks are run. @@ -414,7 +397,8 @@ In the first example, the -x and the second -v are passed through to the test binary unchanged and with no effect on the go command itself. In the second example, the argument math is passed through to the test binary, instead of being interpreted as the package list. -` +`, +} var HelpTestfunc = &base.Command{ UsageLine: "testfunc", @@ -532,7 +516,7 @@ var testVetFlags = []string{ func runTest(cmd *base.Command, args []string) { modload.LoadTests = true - pkgArgs, testArgs = testFlags(args) + pkgArgs, testArgs = testFlags(cmd.Usage, args) work.FindExecCmd() // initialize cached result diff --git a/src/cmd/go/internal/test/testflag.go b/src/cmd/go/internal/test/testflag.go index 73f8c69d9e171..ebcf49a4e9c92 100644 --- a/src/cmd/go/internal/test/testflag.go +++ b/src/cmd/go/internal/test/testflag.go @@ -87,7 +87,7 @@ func init() { // to allow both // go test fmt -custom-flag-for-fmt-test // go test -x math -func testFlags(args []string) (packageNames, passToTest []string) { +func testFlags(usage func(), args []string) (packageNames, passToTest []string) { args = str.StringList(cmdflag.FindGOFLAGS(testFlagDefn), args) inPkg := false var explicitArgs []string @@ -108,7 +108,7 @@ func testFlags(args []string) (packageNames, passToTest []string) { inPkg = false } - f, value, extraWord := cmdflag.Parse(cmd, testFlagDefn, args, i) + f, value, extraWord := cmdflag.Parse(cmd, usage, testFlagDefn, args, i) if f == nil { // This is a flag we do not know; we must assume // that any args we see after this might be flag diff --git a/src/cmd/go/internal/vet/vet.go b/src/cmd/go/internal/vet/vet.go index b64bf3f8e8784..616f774bf6459 100644 --- a/src/cmd/go/internal/vet/vet.go +++ b/src/cmd/go/internal/vet/vet.go @@ -38,7 +38,7 @@ See also: go fmt, go fix. func runVet(cmd *base.Command, args []string) { modload.LoadTests = true - vetFlags, pkgArgs := vetFlags(args) + vetFlags, pkgArgs := vetFlags(cmd.Usage, args) work.BuildInit() work.VetFlags = vetFlags diff --git a/src/cmd/go/internal/vet/vetflag.go b/src/cmd/go/internal/vet/vetflag.go index cfa4352cb99e1..22bce16cf3429 100644 --- a/src/cmd/go/internal/vet/vetflag.go +++ b/src/cmd/go/internal/vet/vetflag.go @@ -40,7 +40,7 @@ var vetTool = os.Getenv("GOVETTOOL") // vetFlags processes the command line, splitting it at the first non-flag // into the list of flags and list of packages. -func vetFlags(args []string) (passToVet, packageNames []string) { +func vetFlags(usage func(), args []string) (passToVet, packageNames []string) { // Query the vet command for its flags. tool := vetTool if tool != "" { @@ -108,7 +108,7 @@ func vetFlags(args []string) (passToVet, packageNames []string) { return args[:i], args[i:] } - f, value, extraWord := cmdflag.Parse("vet", vetFlagDefn, args, i) + f, value, extraWord := cmdflag.Parse("vet", usage, vetFlagDefn, args, i) if f == nil { fmt.Fprintf(os.Stderr, "vet: flag %q not defined\n", args[i]) fmt.Fprintf(os.Stderr, "Run \"go help vet\" for more information\n") diff --git a/src/cmd/go/main.go b/src/cmd/go/main.go index d6934ce5e9096..6a188262cce67 100644 --- a/src/cmd/go/main.go +++ b/src/cmd/go/main.go @@ -235,17 +235,6 @@ func init() { } func mainUsage() { - // special case "go test -h" - if len(os.Args) > 1 && os.Args[1] == "test" { - test.Usage() - } - // Since vet shares code with test in cmdflag, it doesn't show its - // command usage properly. For now, special case it too. - // TODO(mvdan): fix the cmdflag package instead; see - // golang.org/issue/26999 - if len(os.Args) > 1 && os.Args[1] == "vet" { - vet.CmdVet.Usage() - } help.PrintUsage(os.Stderr, base.Go) os.Exit(2) } diff --git a/src/cmd/go/testdata/script/help.txt b/src/cmd/go/testdata/script/help.txt index 656e68010090d..3d0650880e603 100644 --- a/src/cmd/go/testdata/script/help.txt +++ b/src/cmd/go/testdata/script/help.txt @@ -35,7 +35,13 @@ stderr 'Run ''go help mod'' for usage.' stderr 'usage: go vet' stderr 'Run ''go help vet'' for details' +# Earlier versions of Go printed a large document here, instead of these two +# lines. +! go test -h +stderr 'usage: go test' +stderr 'Run ''go help test'' for details' + # go help get shows usage for get go help get stdout 'usage: go get' -stdout 'get when using GOPATH' \ No newline at end of file +stdout 'get when using GOPATH' From 7cd2a51c8c1b84191e518ac39b0890ffd56d852b Mon Sep 17 00:00:00 2001 From: Alberto Donizetti Date: Tue, 6 Nov 2018 22:08:30 +0100 Subject: [PATCH 0996/1663] cmd/compile: update TestNexting golden file This change updates the expected output of the gdb debugging session in the TestNexting internal/ssa test, aligning it with the changes introduced in CL 147360. Fixes the longtest builder. Change-Id: I5b5c22e1cf5e205967ff8359dc6c1485c815428e Reviewed-on: https://go-review.googlesource.com/c/147957 Run-TryBot: Alberto Donizetti Reviewed-by: Keith Randall Reviewed-by: David Chase TryBot-Result: Gobot Gobot --- src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts b/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts index 8664ea77c43e7..b2f32167078a6 100644 --- a/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts +++ b/src/cmd/compile/internal/ssa/testdata/hist.gdb-opt.nexts @@ -123,6 +123,7 @@ t = 0 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a 90: t += i * a +92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) a = 3 @@ -131,6 +132,7 @@ t = 3 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a 90: t += i * a +92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) a = 0 @@ -144,6 +146,7 @@ t = 9 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a 90: t += i * a +92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) a = 1 @@ -152,6 +155,7 @@ t = 17 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a 90: t += i * a +92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) a = 0 From 6fc479166a42f859ec8cfbb3e583f941160e069c Mon Sep 17 00:00:00 2001 From: David Chase Date: Tue, 6 Nov 2018 16:42:13 -0500 Subject: [PATCH 0997/1663] cmd/compile: update TestNexting golden file for Delve This change updates the expected output of the delve debugging session in the TestNexting internal/ssa test, aligning it with the changes introduced in CL 147360 and earlier. Change-Id: I1cc788d02433624a36f4690f24201569d765e5d3 Reviewed-on: https://go-review.googlesource.com/c/147998 Run-TryBot: David Chase TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts b/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts index 7eb1d3a35b6ed..89d0b1b6373fc 100644 --- a/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts +++ b/src/cmd/compile/internal/ssa/testdata/hist.dlv-opt.nexts @@ -58,11 +58,13 @@ 87: if a == 0 { //gdb-opt=(a,n,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) +92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a 90: t += i * a 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) +92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a 90: t += i * a 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) @@ -70,11 +72,13 @@ 87: if a == 0 { //gdb-opt=(a,n,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) +92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a 90: t += i * a 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 86: for i, a := range hist { 87: if a == 0 { //gdb-opt=(a,n,t) +92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) 91: n += a 90: t += i * a 92: fmt.Fprintf(os.Stderr, "%d\t%d\t%d\t%d\t%d\n", i, a, n, i*a, t) //gdb-dbg=(n,i,t) From 1100df58238a1b1c55af148a880b48caf4be6504 Mon Sep 17 00:00:00 2001 From: Diogo Pinela Date: Tue, 30 Oct 2018 22:58:24 +0000 Subject: [PATCH 0998/1663] go/internal/gcimporter: ensure tests pass even if GOROOT is read-only This mainly entails writing compiler output files to a temporary directory, as well as the corrupted files in TestVersionHandling. Updates #28387 Change-Id: I6b3619a91fff27011c7d73daa4febd14a6c5c348 Reviewed-on: https://go-review.googlesource.com/c/146119 Run-TryBot: Robert Griesemer TryBot-Result: Gobot Gobot Reviewed-by: Robert Griesemer --- src/go/internal/gcimporter/gcimporter_test.go | 113 +++++++++++------- 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/src/go/internal/gcimporter/gcimporter_test.go b/src/go/internal/gcimporter/gcimporter_test.go index d496f2e57d384..222b36c883688 100644 --- a/src/go/internal/gcimporter/gcimporter_test.go +++ b/src/go/internal/gcimporter/gcimporter_test.go @@ -34,16 +34,23 @@ func skipSpecialPlatforms(t *testing.T) { } } -func compile(t *testing.T, dirname, filename string) string { - cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", filename) +// compile runs the compiler on filename, with dirname as the working directory, +// and writes the output file to outdirname. +func compile(t *testing.T, dirname, filename, outdirname string) string { + // filename must end with ".go" + if !strings.HasSuffix(filename, ".go") { + t.Fatalf("filename doesn't end in .go: %s", filename) + } + basename := filepath.Base(filename) + outname := filepath.Join(outdirname, basename[:len(basename)-2]+"o") + cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", "-o", outname, filename) cmd.Dir = dirname out, err := cmd.CombinedOutput() if err != nil { t.Logf("%s", out) t.Fatalf("go tool compile %s failed: %s", filename, err) } - // filename should end with ".go" - return filepath.Join(dirname, filename[:len(filename)-2]+"o") + return outname } func testPath(t *testing.T, path, srcDir string) *types.Package { @@ -88,17 +95,30 @@ func testDir(t *testing.T, dir string, endTime time.Time) (nimports int) { return } +func mktmpdir(t *testing.T) string { + tmpdir, err := ioutil.TempDir("", "gcimporter_test") + if err != nil { + t.Fatal("mktmpdir:", err) + } + if err := os.Mkdir(filepath.Join(tmpdir, "testdata"), 0700); err != nil { + os.RemoveAll(tmpdir) + t.Fatal("mktmpdir:", err) + } + return tmpdir +} + func TestImportTestdata(t *testing.T) { // This package only handles gc export data. if runtime.Compiler != "gc" { t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) } - if outFn := compile(t, "testdata", "exports.go"); outFn != "" { - defer os.Remove(outFn) - } + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + + compile(t, "testdata", "exports.go", filepath.Join(tmpdir, "testdata")) - if pkg := testPath(t, "./testdata/exports", "."); pkg != nil { + if pkg := testPath(t, "./testdata/exports", tmpdir); pkg != nil { // The package's Imports list must include all packages // explicitly imported by exports.go, plus all packages // referenced indirectly via exported objects in exports.go. @@ -131,6 +151,13 @@ func TestVersionHandling(t *testing.T) { t.Fatal(err) } + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + corruptdir := filepath.Join(tmpdir, "testdata", "versions") + if err := os.Mkdir(corruptdir, 0700); err != nil { + t.Fatal(err) + } + for _, f := range list { name := f.Name() if !strings.HasSuffix(name, ".a") { @@ -178,12 +205,11 @@ func TestVersionHandling(t *testing.T) { } // 4) write the file pkgpath += "_corrupted" - filename := filepath.Join(dir, pkgpath) + ".a" + filename := filepath.Join(corruptdir, pkgpath) + ".a" ioutil.WriteFile(filename, data, 0666) - defer os.Remove(filename) // test that importing the corrupted file results in an error - _, err = Import(make(map[string]*types.Package), pkgpath, dir, nil) + _, err = Import(make(map[string]*types.Package), pkgpath, corruptdir, nil) if err == nil { t.Errorf("import corrupted %q succeeded", pkgpath) } else if msg := err.Error(); !strings.Contains(msg, "version skew") { @@ -315,7 +341,7 @@ func TestIssue5815(t *testing.T) { t.Skipf("gc-built packages not available (compiler = %s)", runtime.Compiler) } - pkg := importPkg(t, "strings") + pkg := importPkg(t, "strings", ".") scope := pkg.Scope() for _, name := range scope.Names() { @@ -373,15 +399,22 @@ func TestIssue13566(t *testing.T) { t.Skip("avoid dealing with relative paths/drive letters on windows") } - if f := compile(t, "testdata", "a.go"); f != "" { - defer os.Remove(f) - } - if f := compile(t, "testdata", "b.go"); f != "" { - defer os.Remove(f) + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + testoutdir := filepath.Join(tmpdir, "testdata") + + // b.go needs to be compiled from the output directory so that the compiler can + // find the compiled package a. We pass the full path to compile() so that we + // don't have to copy the file to that directory. + bpath, err := filepath.Abs(filepath.Join("testdata", "b.go")) + if err != nil { + t.Fatal(err) } + compile(t, "testdata", "a.go", testoutdir) + compile(t, testoutdir, bpath, testoutdir) // import must succeed (test for issue at hand) - pkg := importPkg(t, "./testdata/b") + pkg := importPkg(t, "./testdata/b", tmpdir) // make sure all indirectly imported packages have names for _, imp := range pkg.Imports() { @@ -451,9 +484,10 @@ func TestIssue15517(t *testing.T) { t.Skip("avoid dealing with relative paths/drive letters on windows") } - if f := compile(t, "testdata", "p.go"); f != "" { - defer os.Remove(f) - } + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + + compile(t, "testdata", "p.go", filepath.Join(tmpdir, "testdata")) // Multiple imports of p must succeed without redeclaration errors. // We use an import path that's not cleaned up so that the eventual @@ -469,7 +503,7 @@ func TestIssue15517(t *testing.T) { // The same issue occurs with vendoring.) imports := make(map[string]*types.Package) for i := 0; i < 3; i++ { - if _, err := Import(imports, "./././testdata/p", ".", nil); err != nil { + if _, err := Import(imports, "./././testdata/p", tmpdir, nil); err != nil { t.Fatal(err) } } @@ -489,11 +523,7 @@ func TestIssue15920(t *testing.T) { t.Skip("avoid dealing with relative paths/drive letters on windows") } - if f := compile(t, "testdata", "issue15920.go"); f != "" { - defer os.Remove(f) - } - - importPkg(t, "./testdata/issue15920") + compileAndImportPkg(t, "issue15920") } func TestIssue20046(t *testing.T) { @@ -510,12 +540,8 @@ func TestIssue20046(t *testing.T) { t.Skip("avoid dealing with relative paths/drive letters on windows") } - if f := compile(t, "testdata", "issue20046.go"); f != "" { - defer os.Remove(f) - } - // "./issue20046".V.M must exist - pkg := importPkg(t, "./testdata/issue20046") + pkg := compileAndImportPkg(t, "issue20046") obj := lookupObj(t, pkg.Scope(), "V") if m, index, indirect := types.LookupFieldOrMethod(obj.Type(), false, nil, "M"); m == nil { t.Fatalf("V.M not found (index = %v, indirect = %v)", index, indirect) @@ -535,11 +561,7 @@ func TestIssue25301(t *testing.T) { t.Skip("avoid dealing with relative paths/drive letters on windows") } - if f := compile(t, "testdata", "issue25301.go"); f != "" { - defer os.Remove(f) - } - - importPkg(t, "./testdata/issue25301") + compileAndImportPkg(t, "issue25301") } func TestIssue25596(t *testing.T) { @@ -556,21 +578,24 @@ func TestIssue25596(t *testing.T) { t.Skip("avoid dealing with relative paths/drive letters on windows") } - if f := compile(t, "testdata", "issue25596.go"); f != "" { - defer os.Remove(f) - } - - importPkg(t, "./testdata/issue25596") + compileAndImportPkg(t, "issue25596") } -func importPkg(t *testing.T, path string) *types.Package { - pkg, err := Import(make(map[string]*types.Package), path, ".", nil) +func importPkg(t *testing.T, path, srcDir string) *types.Package { + pkg, err := Import(make(map[string]*types.Package), path, srcDir, nil) if err != nil { t.Fatal(err) } return pkg } +func compileAndImportPkg(t *testing.T, name string) *types.Package { + tmpdir := mktmpdir(t) + defer os.RemoveAll(tmpdir) + compile(t, "testdata", name+".go", filepath.Join(tmpdir, "testdata")) + return importPkg(t, "./testdata/"+name, tmpdir) +} + func lookupObj(t *testing.T, scope *types.Scope, name string) types.Object { if obj := scope.Lookup(name); obj != nil { return obj From c0a40e4fe5d4649672d0d430ca26551841fc4852 Mon Sep 17 00:00:00 2001 From: "Hana (Hyang-Ah) Kim" Date: Tue, 6 Nov 2018 17:48:08 -0500 Subject: [PATCH 0999/1663] cmd/vendor: update github.com/google/pprof Sync @ fde099a (Oct 26, 2018) Also update misc/nacl/testzip.proto to include new testdata. Change-Id: If41590be9f395a591056e89a417b589c4ba71b1a Reviewed-on: https://go-review.googlesource.com/c/147979 Run-TryBot: Hyang-Ah Hana Kim TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- misc/nacl/testzip.proto | 3 + .../github.com/google/pprof/driver/driver.go | 43 +++-- .../pprof/internal/binutils/binutils.go | 109 ++++++++++-- .../pprof/internal/binutils/binutils_test.go | 29 +++ .../internal/binutils/testdata/malformed_elf | 1 + .../binutils/testdata/malformed_macho | 1 + .../google/pprof/internal/driver/cli.go | 7 +- .../google/pprof/internal/driver/commands.go | 38 ++-- .../google/pprof/internal/driver/driver.go | 64 +++---- .../pprof/internal/driver/driver_test.go | 117 +++++++++++-- .../google/pprof/internal/driver/fetch.go | 60 ++----- .../pprof/internal/driver/fetch_test.go | 165 +++++++++++++++--- .../google/pprof/internal/driver/flags.go | 78 +++++++++ .../pprof/internal/driver/flamegraph.go | 18 +- .../pprof/internal/driver/flamegraph_test.go | 46 ----- .../pprof/internal/driver/interactive_test.go | 19 +- .../google/pprof/internal/driver/options.go | 64 +------ .../pprof.cpu.flat.addresses.noinlines.text | 7 + ...prof.cpu.flat.filefunctions.noinlines.text | 5 + .../pprof.cpu.flat.functions.noinlines.text | 5 + .../driver/testdata/pprof.cpu.lines.topproto | 3 + .../driver/testdata/pprof.longNameFuncs.dot | 9 + .../driver/testdata/pprof.longNameFuncs.text | 5 + .../google/pprof/internal/driver/webhtml.go | 84 ++++++--- .../google/pprof/internal/driver/webui.go | 26 +-- .../google/pprof/internal/elfexec/elfexec.go | 28 +-- .../pprof/internal/elfexec/elfexec_test.go | 11 +- .../google/pprof/internal/graph/dotgraph.go | 1 + .../google/pprof/internal/graph/graph.go | 29 ++- .../google/pprof/internal/graph/graph_test.go | 157 +++++++++++++++++ .../google/pprof/internal/plugin/plugin.go | 15 +- .../google/pprof/internal/report/report.go | 24 ++- .../pprof/internal/report/report_test.go | 21 ++- .../pprof/internal/symbolizer/symbolizer.go | 31 +--- .../internal/symbolizer/symbolizer_test.go | 4 +- .../google/pprof/internal/symbolz/symbolz.go | 35 +++- .../pprof/internal/symbolz/symbolz_test.go | 28 +++ .../pprof/internal/transport/transport.go | 131 ++++++++++++++ .../pprof/profile/legacy_java_profile.go | 2 +- .../google/pprof/profile/profile.go | 6 + .../google/pprof/profile/profile_test.go | 53 ++++++ .../profile/testdata/java.contention.string | 2 +- src/cmd/vendor/vendor.json | 88 +++++----- 43 files changed, 1227 insertions(+), 445 deletions(-) create mode 100644 src/cmd/vendor/github.com/google/pprof/internal/binutils/testdata/malformed_elf create mode 100644 src/cmd/vendor/github.com/google/pprof/internal/binutils/testdata/malformed_macho create mode 100644 src/cmd/vendor/github.com/google/pprof/internal/driver/flags.go delete mode 100644 src/cmd/vendor/github.com/google/pprof/internal/driver/flamegraph_test.go create mode 100644 src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.addresses.noinlines.text create mode 100644 src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.filefunctions.noinlines.text create mode 100644 src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.functions.noinlines.text create mode 100644 src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.lines.topproto create mode 100644 src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.longNameFuncs.dot create mode 100644 src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.longNameFuncs.text create mode 100644 src/cmd/vendor/github.com/google/pprof/internal/transport/transport.go diff --git a/misc/nacl/testzip.proto b/misc/nacl/testzip.proto index 7f524cac48276..c2afa1020aae1 100644 --- a/misc/nacl/testzip.proto +++ b/misc/nacl/testzip.proto @@ -50,6 +50,9 @@ go src=.. google pprof internal + binutils + testdata + + driver testdata + diff --git a/src/cmd/vendor/github.com/google/pprof/driver/driver.go b/src/cmd/vendor/github.com/google/pprof/driver/driver.go index 3735d6ace9900..b1c745bacdb59 100644 --- a/src/cmd/vendor/github.com/google/pprof/driver/driver.go +++ b/src/cmd/vendor/github.com/google/pprof/driver/driver.go @@ -17,6 +17,7 @@ package driver import ( "io" + "net/http" "regexp" "time" @@ -48,13 +49,14 @@ func (o *Options) internalOptions() *plugin.Options { } } return &plugin.Options{ - Writer: o.Writer, - Flagset: o.Flagset, - Fetch: o.Fetch, - Sym: sym, - Obj: obj, - UI: o.UI, - HTTPServer: httpServer, + Writer: o.Writer, + Flagset: o.Flagset, + Fetch: o.Fetch, + Sym: sym, + Obj: obj, + UI: o.UI, + HTTPServer: httpServer, + HTTPTransport: o.HTTPTransport, } } @@ -64,13 +66,14 @@ type HTTPServerArgs plugin.HTTPServerArgs // Options groups all the optional plugins into pprof. type Options struct { - Writer Writer - Flagset FlagSet - Fetch Fetcher - Sym Symbolizer - Obj ObjTool - UI UI - HTTPServer func(*HTTPServerArgs) error + Writer Writer + Flagset FlagSet + Fetch Fetcher + Sym Symbolizer + Obj ObjTool + UI UI + HTTPServer func(*HTTPServerArgs) error + HTTPTransport http.RoundTripper } // Writer provides a mechanism to write data under a certain name, @@ -100,12 +103,16 @@ type FlagSet interface { // single flag StringList(name string, def string, usage string) *[]*string - // ExtraUsage returns any additional text that should be - // printed after the standard usage message. - // The typical use of ExtraUsage is to show any custom flags - // defined by the specific pprof plugins being used. + // ExtraUsage returns any additional text that should be printed after the + // standard usage message. The extra usage message returned includes all text + // added with AddExtraUsage(). + // The typical use of ExtraUsage is to show any custom flags defined by the + // specific pprof plugins being used. ExtraUsage() string + // AddExtraUsage appends additional text to the end of the extra usage message. + AddExtraUsage(eu string) + // Parse initializes the flags with their values for this run // and returns the non-flag command line arguments. // If an unknown flag is encountered or there are no arguments, diff --git a/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go b/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go index 12b6a5c4b262e..309561112ce2c 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils.go @@ -18,11 +18,14 @@ package binutils import ( "debug/elf" "debug/macho" + "encoding/binary" "fmt" + "io" "os" "os/exec" "path/filepath" "regexp" + "runtime" "strings" "sync" @@ -173,12 +176,8 @@ func (bu *Binutils) Open(name string, start, limit, offset uint64) (plugin.ObjFi b := bu.get() // Make sure file is a supported executable. - // The pprof driver uses Open to sniff the difference - // between an executable and a profile. - // For now, only ELF is supported. - // Could read the first few bytes of the file and - // use a table of prefixes if we need to support other - // systems at some point. + // This uses magic numbers, mainly to provide better error messages but + // it should also help speed. if _, err := os.Stat(name); err != nil { // For testing, do not require file name to exist. @@ -188,21 +187,54 @@ func (bu *Binutils) Open(name string, start, limit, offset uint64) (plugin.ObjFi return nil, err } - if f, err := b.openELF(name, start, limit, offset); err == nil { + // Read the first 4 bytes of the file. + + f, err := os.Open(name) + if err != nil { + return nil, fmt.Errorf("error opening %s: %v", name, err) + } + defer f.Close() + + var header [4]byte + if _, err = io.ReadFull(f, header[:]); err != nil { + return nil, fmt.Errorf("error reading magic number from %s: %v", name, err) + } + + elfMagic := string(header[:]) + + // Match against supported file types. + if elfMagic == elf.ELFMAG { + f, err := b.openELF(name, start, limit, offset) + if err != nil { + return nil, fmt.Errorf("error reading ELF file %s: %v", name, err) + } return f, nil } - if f, err := b.openMachO(name, start, limit, offset); err == nil { + + // Mach-O magic numbers can be big or little endian. + machoMagicLittle := binary.LittleEndian.Uint32(header[:]) + machoMagicBig := binary.BigEndian.Uint32(header[:]) + + if machoMagicLittle == macho.Magic32 || machoMagicLittle == macho.Magic64 || + machoMagicBig == macho.Magic32 || machoMagicBig == macho.Magic64 { + f, err := b.openMachO(name, start, limit, offset) + if err != nil { + return nil, fmt.Errorf("error reading Mach-O file %s: %v", name, err) + } + return f, nil + } + if machoMagicLittle == macho.MagicFat || machoMagicBig == macho.MagicFat { + f, err := b.openFatMachO(name, start, limit, offset) + if err != nil { + return nil, fmt.Errorf("error reading fat Mach-O file %s: %v", name, err) + } return f, nil } - return nil, fmt.Errorf("unrecognized binary: %s", name) + + return nil, fmt.Errorf("unrecognized binary format: %s", name) } -func (b *binrep) openMachO(name string, start, limit, offset uint64) (plugin.ObjFile, error) { - of, err := macho.Open(name) - if err != nil { - return nil, fmt.Errorf("error parsing %s: %v", name, err) - } - defer of.Close() +func (b *binrep) openMachOCommon(name string, of *macho.File, start, limit, offset uint64) (plugin.ObjFile, error) { // Subtract the load address of the __TEXT section. Usually 0 for shared // libraries or 0x100000000 for executables. You can check this value by @@ -225,6 +257,53 @@ func (b *binrep) openMachO(name string, start, limit, offset uint64) (plugin.Obj return &fileAddr2Line{file: file{b: b, name: name, base: base}}, nil } +func (b *binrep) openFatMachO(name string, start, limit, offset uint64) (plugin.ObjFile, error) { + of, err := macho.OpenFat(name) + if err != nil { + return nil, fmt.Errorf("error parsing %s: %v", name, err) + } + defer of.Close() + + if len(of.Arches) == 0 { + return nil, fmt.Errorf("empty fat Mach-O file: %s", name) + } + + var arch macho.Cpu + // Use the host architecture. + // TODO: This is not ideal because the host architecture may not be the one + // that was profiled. E.g. an amd64 host can profile a 386 program. + switch runtime.GOARCH { + case "386": + arch = macho.Cpu386 + case "amd64", "amd64p32": + arch = macho.CpuAmd64 + case "arm", "armbe", "arm64", "arm64be": + arch = macho.CpuArm + case "ppc": + arch = macho.CpuPpc + case "ppc64", "ppc64le": + arch = macho.CpuPpc64 + default: + return nil, fmt.Errorf("unsupported host architecture for %s: %s", name, runtime.GOARCH) + } + for i := range of.Arches { + if of.Arches[i].Cpu == arch { + return b.openMachOCommon(name, of.Arches[i].File, start, limit, offset) + } + } + return nil, fmt.Errorf("architecture not found in %s: %s", name, runtime.GOARCH) +} + +func (b *binrep) openMachO(name string, start, limit, offset uint64) (plugin.ObjFile, error) { + of, err := macho.Open(name) + if err != nil { + return nil, fmt.Errorf("error parsing %s: %v", name, err) + } + defer of.Close() + + return b.openMachOCommon(name, of, start, limit, offset) +} + func (b *binrep) openELF(name string, start, limit, offset uint64) (plugin.ObjFile, error) { ef, err := elf.Open(name) if err != nil { diff --git a/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils_test.go b/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils_test.go index d844ed7e4e7e0..17d4225a87fd1 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils_test.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/binutils/binutils_test.go @@ -22,6 +22,7 @@ import ( "reflect" "regexp" "runtime" + "strings" "testing" "github.com/google/pprof/internal/plugin" @@ -361,3 +362,31 @@ func TestLLVMSymbolizer(t *testing.T) { } } } + +func TestOpenMalformedELF(t *testing.T) { + // Test that opening a malformed ELF file will report an error containing + // the word "ELF". + bu := &Binutils{} + _, err := bu.Open(filepath.Join("testdata", "malformed_elf"), 0, 0, 0) + if err == nil { + t.Fatalf("Open: unexpected success") + } + + if !strings.Contains(err.Error(), "ELF") { + t.Errorf("Open: got %v, want error containing 'ELF'", err) + } +} + +func TestOpenMalformedMachO(t *testing.T) { + // Test that opening a malformed Mach-O file will report an error containing + // the word "Mach-O". + bu := &Binutils{} + _, err := bu.Open(filepath.Join("testdata", "malformed_macho"), 0, 0, 0) + if err == nil { + t.Fatalf("Open: unexpected success") + } + + if !strings.Contains(err.Error(), "Mach-O") { + t.Errorf("Open: got %v, want error containing 'Mach-O'", err) + } +} diff --git a/src/cmd/vendor/github.com/google/pprof/internal/binutils/testdata/malformed_elf b/src/cmd/vendor/github.com/google/pprof/internal/binutils/testdata/malformed_elf new file mode 100644 index 0000000000000..f0b503b0b6c52 --- /dev/null +++ b/src/cmd/vendor/github.com/google/pprof/internal/binutils/testdata/malformed_elf @@ -0,0 +1 @@ +ELF \ No newline at end of file diff --git a/src/cmd/vendor/github.com/google/pprof/internal/binutils/testdata/malformed_macho b/src/cmd/vendor/github.com/google/pprof/internal/binutils/testdata/malformed_macho new file mode 100644 index 0000000000000..b01ddf69a9a27 --- /dev/null +++ b/src/cmd/vendor/github.com/google/pprof/internal/binutils/testdata/malformed_macho @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/cli.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/cli.go index a5153e151132b..dfedf9d8491cd 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/cli.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/cli.go @@ -45,8 +45,8 @@ type source struct { func parseFlags(o *plugin.Options) (*source, []string, error) { flag := o.Flagset // Comparisons. - flagBase := flag.StringList("base", "", "Source for base profile for profile subtraction") - flagDiffBase := flag.StringList("diff_base", "", "Source for diff base profile for comparison") + flagDiffBase := flag.StringList("diff_base", "", "Source of base profile for comparison") + flagBase := flag.StringList("base", "", "Source of base profile for profile subtraction") // Source options. flagSymbolize := flag.String("symbolize", "", "Options for profile symbolization") flagBuildID := flag.String("buildid", "", "Override build id for first mapping") @@ -312,7 +312,8 @@ var usageMsgSrc = "\n\n" + " -buildid Override build id for main binary\n" + " -add_comment Free-form annotation to add to the profile\n" + " Displayed on some reports or with pprof -comments\n" + - " -base source Source of profile to use as baseline\n" + + " -diff_base source Source of base profile for comparison\n" + + " -base source Source of base profile for profile subtraction\n" + " profile.pb.gz Profile in compressed protobuf format\n" + " legacy_profile Profile in legacy pprof format\n" + " http://host/profile URL for profile handler to retrieve\n" + diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/commands.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/commands.go index 91d32d1e716d4..ab073d878d547 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/commands.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/commands.go @@ -228,17 +228,17 @@ var pprofVariables = variables{ // Output granularity "functions": &variable{boolKind, "t", "granularity", helpText( "Aggregate at the function level.", - "Takes into account the filename/lineno where the function was defined.")}, + "Ignores the filename where the function was defined.")}, + "filefunctions": &variable{boolKind, "t", "granularity", helpText( + "Aggregate at the function level.", + "Takes into account the filename where the function was defined.")}, "files": &variable{boolKind, "f", "granularity", "Aggregate at the file level."}, "lines": &variable{boolKind, "f", "granularity", "Aggregate at the source code line level."}, "addresses": &variable{boolKind, "f", "granularity", helpText( - "Aggregate at the function level.", + "Aggregate at the address level.", "Includes functions' addresses in the output.")}, - "noinlines": &variable{boolKind, "f", "granularity", helpText( - "Aggregate at the function level.", - "Attributes inlined functions to their first out-of-line caller.")}, - "addressnoinlines": &variable{boolKind, "f", "granularity", helpText( - "Aggregate at the function level, including functions' addresses in the output.", + "noinlines": &variable{boolKind, "f", "", helpText( + "Ignore inlines.", "Attributes inlined functions to their first out-of-line caller.")}, } @@ -337,21 +337,27 @@ func listHelp(c string, redirect bool) string { // browsers returns a list of commands to attempt for web visualization. func browsers() []string { - cmds := []string{"chrome", "google-chrome", "firefox"} + var cmds []string + if userBrowser := os.Getenv("BROWSER"); userBrowser != "" { + cmds = append(cmds, userBrowser) + } switch runtime.GOOS { case "darwin": - return append(cmds, "/usr/bin/open") + cmds = append(cmds, "/usr/bin/open") case "windows": - return append(cmds, "cmd /c start") + cmds = append(cmds, "cmd /c start") default: - userBrowser := os.Getenv("BROWSER") - if userBrowser != "" { - cmds = append([]string{userBrowser, "sensible-browser"}, cmds...) - } else { - cmds = append([]string{"sensible-browser"}, cmds...) + // Commands opening browsers are prioritized over xdg-open, so browser() + // command can be used on linux to open the .svg file generated by the -web + // command (the .svg file includes embedded javascript so is best viewed in + // a browser). + cmds = append(cmds, []string{"chrome", "google-chrome", "chromium", "firefox", "sensible-browser"}...) + if os.Getenv("DISPLAY") != "" { + // xdg-open is only for use in a desktop environment. + cmds = append(cmds, "xdg-open") } - return append(cmds, "xdg-open") } + return cmds } var kcachegrind = []string{"kcachegrind"} diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/driver.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/driver.go index 2dabc3017b57e..45f1846749cbe 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/driver.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/driver.go @@ -152,20 +152,33 @@ func generateReport(p *profile.Profile, cmd []string, vars variables, o *plugin. } func applyCommandOverrides(cmd string, outputFormat int, v variables) variables { - trim, tagfilter, filter := v["trim"].boolValue(), true, true + // Some report types override the trim flag to false below. This is to make + // sure the default heuristics of excluding insignificant nodes and edges + // from the call graph do not apply. One example where it is important is + // annotated source or disassembly listing. Those reports run on a specific + // function (or functions), but the trimming is applied before the function + // data is selected. So, with trimming enabled, the report could end up + // showing no data if the specified function is "uninteresting" as far as the + // trimming is concerned. + trim := v["trim"].boolValue() switch cmd { - case "callgrind", "kcachegrind": - trim = false - v.set("addresses", "t") case "disasm", "weblist": trim = false - v.set("addressnoinlines", "t") + v.set("addresses", "t") + // Force the 'noinlines' mode so that source locations for a given address + // collapse and there is only one for the given address. Without this + // cumulative metrics would be double-counted when annotating the assembly. + // This is because the merge is done by address and in case of an inlined + // stack each of the inlined entries is a separate callgraph node. + v.set("noinlines", "t") case "peek": - trim, tagfilter, filter = false, false, false + trim = false case "list": - v.set("nodecount", "0") + trim = false v.set("lines", "t") + // Do not force 'noinlines' to be false so that specifying + // "-list foo -noinlines" is supported and works as expected. case "text", "top", "topproto": if v["nodecount"].intValue() == -1 { v.set("nodecount", "0") @@ -176,9 +189,11 @@ func applyCommandOverrides(cmd string, outputFormat int, v variables) variables } } - if outputFormat == report.Proto || outputFormat == report.Raw { - trim, tagfilter, filter = false, false, false + switch outputFormat { + case report.Proto, report.Raw, report.Callgrind: + trim = false v.set("addresses", "t") + v.set("noinlines", "f") } if !trim { @@ -186,43 +201,32 @@ func applyCommandOverrides(cmd string, outputFormat int, v variables) variables v.set("nodefraction", "0") v.set("edgefraction", "0") } - if !tagfilter { - v.set("tagfocus", "") - v.set("tagignore", "") - } - if !filter { - v.set("focus", "") - v.set("ignore", "") - v.set("hide", "") - v.set("show", "") - v.set("show_from", "") - } return v } func aggregate(prof *profile.Profile, v variables) error { - var inlines, function, filename, linenumber, address bool + var function, filename, linenumber, address bool + inlines := !v["noinlines"].boolValue() switch { case v["addresses"].boolValue(): - return nil + if inlines { + return nil + } + function = true + filename = true + linenumber = true + address = true case v["lines"].boolValue(): - inlines = true function = true filename = true linenumber = true case v["files"].boolValue(): - inlines = true filename = true case v["functions"].boolValue(): - inlines = true - function = true - case v["noinlines"].boolValue(): function = true - case v["addressnoinlines"].boolValue(): + case v["filefunctions"].boolValue(): function = true filename = true - linenumber = true - address = true default: return fmt.Errorf("unexpected granularity") } diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/driver_test.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/driver_test.go index ff6afe9cff7e5..90f89dc7bc85a 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/driver_test.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/driver_test.go @@ -53,6 +53,9 @@ func TestParse(t *testing.T) { flags, source string }{ {"text,functions,flat", "cpu"}, + {"text,functions,noinlines,flat", "cpu"}, + {"text,filefunctions,noinlines,flat", "cpu"}, + {"text,addresses,noinlines,flat", "cpu"}, {"tree,addresses,flat,nodecount=4", "cpusmall"}, {"text,functions,flat,nodecount=5,call_tree", "unknown"}, {"text,alloc_objects,flat", "heap_alloc"}, @@ -63,6 +66,7 @@ func TestParse(t *testing.T) { {"text,lines,cum,show=[12]00", "cpu"}, {"text,lines,cum,hide=line[X3]0,focus=[12]00", "cpu"}, {"topproto,lines,cum,hide=mangled[X3]0", "cpu"}, + {"topproto,lines", "cpu"}, {"tree,lines,cum,focus=[24]00", "heap"}, {"tree,relative_percentages,cum,focus=[24]00", "heap"}, {"tree,lines,cum,show_from=line2", "cpu"}, @@ -92,6 +96,8 @@ func TestParse(t *testing.T) { {"peek=line.*01", "cpu"}, {"weblist=line[13],addresses,flat", "cpu"}, {"tags,tagfocus=400kb:", "heap_request"}, + {"dot", "longNameFuncs"}, + {"text", "longNameFuncs"}, } baseVars := pprofVariables @@ -108,9 +114,6 @@ func TestParse(t *testing.T) { flags := strings.Split(tc.flags, ",") - // Skip the output format in the first flag, to output to a proto - addFlags(&f, flags[1:]) - // Encode profile into a protobuf and decode it again. protoTempFile, err := ioutil.TempFile("", "profile_proto") if err != nil { @@ -123,11 +126,13 @@ func TestParse(t *testing.T) { if flags[0] == "topproto" { f.bools["proto"] = false f.bools["topproto"] = true + f.bools["addresses"] = true } // First pprof invocation to save the profile into a profile.proto. - o1 := setDefaults(nil) - o1.Flagset = f + // Pass in flag set hen setting defaults, because otherwise default + // transport will try to add flags to the default flag set. + o1 := setDefaults(&plugin.Options{Flagset: f}) o1.Fetch = testFetcher{} o1.Sym = testSymbolizer{} o1.UI = testUI @@ -144,28 +149,28 @@ func TestParse(t *testing.T) { } defer os.Remove(outputTempFile.Name()) defer outputTempFile.Close() + + f = baseFlags() f.strings["output"] = outputTempFile.Name() f.args = []string{protoTempFile.Name()} - var solution string + delete(f.bools, "proto") + addFlags(&f, flags) + solution := solutionFilename(tc.source, &f) // Apply the flags for the second pprof run, and identify name of // the file containing expected results if flags[0] == "topproto" { + addFlags(&f, flags) solution = solutionFilename(tc.source, &f) delete(f.bools, "topproto") f.bools["text"] = true - } else { - delete(f.bools, "proto") - addFlags(&f, flags[:1]) - solution = solutionFilename(tc.source, &f) } - // The add_comment flag is not idempotent so only apply it on the first run. - delete(f.strings, "add_comment") // Second pprof invocation to read the profile from profile.proto // and generate a report. - o2 := setDefaults(nil) - o2.Flagset = f + // Pass in flag set hen setting defaults, because otherwise default + // transport will try to add flags to the default flag set. + o2 := setDefaults(&plugin.Options{Flagset: f}) o2.Sym = testSymbolizeDemangler{} o2.Obj = new(mockObjTool) o2.UI = testUI @@ -250,7 +255,8 @@ func testSourceURL(port int) string { func solutionFilename(source string, f *testFlags) string { name := []string{"pprof", strings.TrimPrefix(source, testSourceURL(8000))} name = addString(name, f, []string{"flat", "cum"}) - name = addString(name, f, []string{"functions", "files", "lines", "addresses"}) + name = addString(name, f, []string{"functions", "filefunctions", "files", "lines", "addresses"}) + name = addString(name, f, []string{"noinlines"}) name = addString(name, f, []string{"inuse_space", "inuse_objects", "alloc_space", "alloc_objects"}) name = addString(name, f, []string{"relative_percentages"}) name = addString(name, f, []string{"seconds"}) @@ -293,6 +299,8 @@ type testFlags struct { func (testFlags) ExtraUsage() string { return "" } +func (testFlags) AddExtraUsage(eu string) {} + func (f testFlags) Bool(s string, d bool, c string) *bool { if b, ok := f.bools[s]; ok { return &b @@ -436,6 +444,8 @@ func (testFetcher) Fetch(s string, d, t time.Duration) (*profile.Profile, string p = contentionProfile() case "symbolz": p = symzProfile() + case "longNameFuncs": + p = longNameFuncsProfile() default: return nil, "", fmt.Errorf("unexpected source: %s", s) } @@ -519,6 +529,83 @@ func fakeDemangler(name string) string { } } +// Returns a profile with function names which should be shortened in +// graph and flame views. +func longNameFuncsProfile() *profile.Profile { + var longNameFuncsM = []*profile.Mapping{ + { + ID: 1, + Start: 0x1000, + Limit: 0x4000, + File: "/path/to/testbinary", + HasFunctions: true, + HasFilenames: true, + HasLineNumbers: true, + HasInlineFrames: true, + }, + } + + var longNameFuncsF = []*profile.Function{ + {ID: 1, Name: "path/to/package1.object.function1", SystemName: "path/to/package1.object.function1", Filename: "path/to/package1.go"}, + {ID: 2, Name: "(anonymous namespace)::Bar::Foo", SystemName: "(anonymous namespace)::Bar::Foo", Filename: "a/long/path/to/package2.cc"}, + {ID: 3, Name: "java.bar.foo.FooBar.run(java.lang.Runnable)", SystemName: "java.bar.foo.FooBar.run(java.lang.Runnable)", Filename: "FooBar.java"}, + } + + var longNameFuncsL = []*profile.Location{ + { + ID: 1000, + Mapping: longNameFuncsM[0], + Address: 0x1000, + Line: []profile.Line{ + {Function: longNameFuncsF[0], Line: 1}, + }, + }, + { + ID: 2000, + Mapping: longNameFuncsM[0], + Address: 0x2000, + Line: []profile.Line{ + {Function: longNameFuncsF[1], Line: 4}, + }, + }, + { + ID: 3000, + Mapping: longNameFuncsM[0], + Address: 0x3000, + Line: []profile.Line{ + {Function: longNameFuncsF[2], Line: 9}, + }, + }, + } + + return &profile.Profile{ + PeriodType: &profile.ValueType{Type: "cpu", Unit: "milliseconds"}, + Period: 1, + DurationNanos: 10e9, + SampleType: []*profile.ValueType{ + {Type: "samples", Unit: "count"}, + {Type: "cpu", Unit: "milliseconds"}, + }, + Sample: []*profile.Sample{ + { + Location: []*profile.Location{longNameFuncsL[0], longNameFuncsL[1], longNameFuncsL[2]}, + Value: []int64{1000, 1000}, + }, + { + Location: []*profile.Location{longNameFuncsL[0], longNameFuncsL[1]}, + Value: []int64{100, 100}, + }, + { + Location: []*profile.Location{longNameFuncsL[2]}, + Value: []int64{10, 10}, + }, + }, + Location: longNameFuncsL, + Function: longNameFuncsF, + Mapping: longNameFuncsM, + } +} + func cpuProfile() *profile.Profile { var cpuM = []*profile.Mapping{ { diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go index 7a7a1a20f2a2e..b8a69e87fce75 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch.go @@ -16,7 +16,6 @@ package driver import ( "bytes" - "crypto/tls" "fmt" "io" "io/ioutil" @@ -57,7 +56,7 @@ func fetchProfiles(s *source, o *plugin.Options) (*profile.Profile, error) { }) } - p, pbase, m, mbase, save, err := grabSourcesAndBases(sources, bases, o.Fetch, o.Obj, o.UI) + p, pbase, m, mbase, save, err := grabSourcesAndBases(sources, bases, o.Fetch, o.Obj, o.UI, o.HTTPTransport) if err != nil { return nil, err } @@ -123,7 +122,7 @@ func fetchProfiles(s *source, o *plugin.Options) (*profile.Profile, error) { return p, nil } -func grabSourcesAndBases(sources, bases []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI) (*profile.Profile, *profile.Profile, plugin.MappingSources, plugin.MappingSources, bool, error) { +func grabSourcesAndBases(sources, bases []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (*profile.Profile, *profile.Profile, plugin.MappingSources, plugin.MappingSources, bool, error) { wg := sync.WaitGroup{} wg.Add(2) var psrc, pbase *profile.Profile @@ -133,11 +132,11 @@ func grabSourcesAndBases(sources, bases []profileSource, fetch plugin.Fetcher, o var countsrc, countbase int go func() { defer wg.Done() - psrc, msrc, savesrc, countsrc, errsrc = chunkedGrab(sources, fetch, obj, ui) + psrc, msrc, savesrc, countsrc, errsrc = chunkedGrab(sources, fetch, obj, ui, tr) }() go func() { defer wg.Done() - pbase, mbase, savebase, countbase, errbase = chunkedGrab(bases, fetch, obj, ui) + pbase, mbase, savebase, countbase, errbase = chunkedGrab(bases, fetch, obj, ui, tr) }() wg.Wait() save := savesrc || savebase @@ -167,7 +166,7 @@ func grabSourcesAndBases(sources, bases []profileSource, fetch plugin.Fetcher, o // chunkedGrab fetches the profiles described in source and merges them into // a single profile. It fetches a chunk of profiles concurrently, with a maximum // chunk size to limit its memory usage. -func chunkedGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI) (*profile.Profile, plugin.MappingSources, bool, int, error) { +func chunkedGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (*profile.Profile, plugin.MappingSources, bool, int, error) { const chunkSize = 64 var p *profile.Profile @@ -180,7 +179,7 @@ func chunkedGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTo if end > len(sources) { end = len(sources) } - chunkP, chunkMsrc, chunkSave, chunkCount, chunkErr := concurrentGrab(sources[start:end], fetch, obj, ui) + chunkP, chunkMsrc, chunkSave, chunkCount, chunkErr := concurrentGrab(sources[start:end], fetch, obj, ui, tr) switch { case chunkErr != nil: return nil, nil, false, 0, chunkErr @@ -204,13 +203,13 @@ func chunkedGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTo } // concurrentGrab fetches multiple profiles concurrently -func concurrentGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI) (*profile.Profile, plugin.MappingSources, bool, int, error) { +func concurrentGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (*profile.Profile, plugin.MappingSources, bool, int, error) { wg := sync.WaitGroup{} wg.Add(len(sources)) for i := range sources { go func(s *profileSource) { defer wg.Done() - s.p, s.msrc, s.remote, s.err = grabProfile(s.source, s.addr, fetch, obj, ui) + s.p, s.msrc, s.remote, s.err = grabProfile(s.source, s.addr, fetch, obj, ui, tr) }(&sources[i]) } wg.Wait() @@ -310,7 +309,7 @@ const testSourceAddress = "pproftest.local" // grabProfile fetches a profile. Returns the profile, sources for the // profile mappings, a bool indicating if the profile was fetched // remotely, and an error. -func grabProfile(s *source, source string, fetcher plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI) (p *profile.Profile, msrc plugin.MappingSources, remote bool, err error) { +func grabProfile(s *source, source string, fetcher plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (p *profile.Profile, msrc plugin.MappingSources, remote bool, err error) { var src string duration, timeout := time.Duration(s.Seconds)*time.Second, time.Duration(s.Timeout)*time.Second if fetcher != nil { @@ -321,7 +320,7 @@ func grabProfile(s *source, source string, fetcher plugin.Fetcher, obj plugin.Ob } if err != nil || p == nil { // Fetch the profile over HTTP or from a file. - p, src, err = fetch(source, duration, timeout, ui) + p, src, err = fetch(source, duration, timeout, ui, tr) if err != nil { return } @@ -461,7 +460,7 @@ mapping: // fetch fetches a profile from source, within the timeout specified, // producing messages through the ui. It returns the profile and the // url of the actual source of the profile for remote profiles. -func fetch(source string, duration, timeout time.Duration, ui plugin.UI) (p *profile.Profile, src string, err error) { +func fetch(source string, duration, timeout time.Duration, ui plugin.UI, tr http.RoundTripper) (p *profile.Profile, src string, err error) { var f io.ReadCloser if sourceURL, timeout := adjustURL(source, duration, timeout); sourceURL != "" { @@ -469,7 +468,7 @@ func fetch(source string, duration, timeout time.Duration, ui plugin.UI) (p *pro if duration > 0 { ui.Print(fmt.Sprintf("Please wait... (%v)", duration)) } - f, err = fetchURL(sourceURL, timeout) + f, err = fetchURL(sourceURL, timeout, tr) src = sourceURL } else if isPerfFile(source) { f, err = convertPerfData(source, ui) @@ -484,8 +483,12 @@ func fetch(source string, duration, timeout time.Duration, ui plugin.UI) (p *pro } // fetchURL fetches a profile from a URL using HTTP. -func fetchURL(source string, timeout time.Duration) (io.ReadCloser, error) { - resp, err := httpGet(source, timeout) +func fetchURL(source string, timeout time.Duration, tr http.RoundTripper) (io.ReadCloser, error) { + client := &http.Client{ + Transport: tr, + Timeout: timeout + 5*time.Second, + } + resp, err := client.Get(source) if err != nil { return nil, fmt.Errorf("http fetch: %v", err) } @@ -582,30 +585,3 @@ func adjustURL(source string, duration, timeout time.Duration) (string, time.Dur u.RawQuery = values.Encode() return u.String(), timeout } - -// httpGet is a wrapper around http.Get; it is defined as a variable -// so it can be redefined during for testing. -var httpGet = func(source string, timeout time.Duration) (*http.Response, error) { - url, err := url.Parse(source) - if err != nil { - return nil, err - } - - var tlsConfig *tls.Config - if url.Scheme == "https+insecure" { - tlsConfig = &tls.Config{ - InsecureSkipVerify: true, - } - url.Scheme = "https" - source = url.String() - } - - client := &http.Client{ - Transport: &http.Transport{ - Proxy: http.ProxyFromEnvironment, - TLSClientConfig: tlsConfig, - ResponseHeaderTimeout: timeout + 5*time.Second, - }, - } - return client.Get(source) -} diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch_test.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch_test.go index e67b2e9f87108..b9e9dfe8f450b 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch_test.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/fetch_test.go @@ -24,8 +24,8 @@ import ( "fmt" "io/ioutil" "math/big" + "net" "net/http" - "net/url" "os" "path/filepath" "reflect" @@ -39,6 +39,7 @@ import ( "github.com/google/pprof/internal/plugin" "github.com/google/pprof/internal/proftest" "github.com/google/pprof/internal/symbolizer" + "github.com/google/pprof/internal/transport" "github.com/google/pprof/profile" ) @@ -173,12 +174,6 @@ func (testFile) Close() error { func TestFetch(t *testing.T) { const path = "testdata/" - - // Intercept http.Get calls from HTTPFetcher. - savedHTTPGet := httpGet - defer func() { httpGet = savedHTTPGet }() - httpGet = stubHTTPGet - type testcase struct { source, execName string } @@ -188,7 +183,7 @@ func TestFetch(t *testing.T) { {path + "go.nomappings.crash", "/bin/gotest.exe"}, {"http://localhost/profile?file=cppbench.cpu", ""}, } { - p, _, _, err := grabProfile(&source{ExecName: tc.execName}, tc.source, nil, testObj{}, &proftest.TestUI{T: t}) + p, _, _, err := grabProfile(&source{ExecName: tc.execName}, tc.source, nil, testObj{}, &proftest.TestUI{T: t}, &httpTransport{}) if err != nil { t.Fatalf("%s: %s", tc.source, err) } @@ -449,8 +444,9 @@ func TestFetchWithBase(t *testing.T) { f.args = tc.sources o := setDefaults(&plugin.Options{ - UI: &proftest.TestUI{T: t, AllowRx: "Local symbolization failed|Some binary filenames not available"}, - Flagset: f, + UI: &proftest.TestUI{T: t, AllowRx: "Local symbolization failed|Some binary filenames not available"}, + Flagset: f, + HTTPTransport: transport.New(nil), }) src, _, err := parseFlags(o) @@ -503,19 +499,14 @@ func mappingSources(key, source string, start uint64) plugin.MappingSources { } } -// stubHTTPGet intercepts a call to http.Get and rewrites it to use -// "file://" to get the profile directly from a file. -func stubHTTPGet(source string, _ time.Duration) (*http.Response, error) { - url, err := url.Parse(source) - if err != nil { - return nil, err - } +type httpTransport struct{} - values := url.Query() +func (tr *httpTransport) RoundTrip(req *http.Request) (*http.Response, error) { + values := req.URL.Query() file := values.Get("file") if file == "" { - return nil, fmt.Errorf("want .../file?profile, got %s", source) + return nil, fmt.Errorf("want .../file?profile, got %s", req.URL.String()) } t := &http.Transport{} @@ -532,7 +523,7 @@ func closedError() string { return "use of closed" } -func TestHttpsInsecure(t *testing.T) { +func TestHTTPSInsecure(t *testing.T) { if runtime.GOOS == "nacl" || runtime.GOOS == "js" { t.Skip("test assumes tcp available") } @@ -553,7 +544,8 @@ func TestHttpsInsecure(t *testing.T) { pprofVariables = baseVars.makeCopy() defer func() { pprofVariables = baseVars }() - tlsConfig := &tls.Config{Certificates: []tls.Certificate{selfSignedCert(t)}} + tlsCert, _, _ := selfSignedCert(t, "") + tlsConfig := &tls.Config{Certificates: []tls.Certificate{tlsCert}} l, err := tls.Listen("tcp", "localhost:0", tlsConfig) if err != nil { @@ -586,8 +578,9 @@ func TestHttpsInsecure(t *testing.T) { Symbolize: "remote", } o := &plugin.Options{ - Obj: &binutils.Binutils{}, - UI: &proftest.TestUI{T: t, AllowRx: "Saved profile in"}, + Obj: &binutils.Binutils{}, + UI: &proftest.TestUI{T: t, AllowRx: "Saved profile in"}, + HTTPTransport: transport.New(nil), } o.Sym = &symbolizer.Symbolizer{Obj: o.Obj, UI: o.UI} p, err := fetchProfiles(s, o) @@ -600,7 +593,122 @@ func TestHttpsInsecure(t *testing.T) { if len(p.Function) == 0 { t.Fatalf("fetchProfiles(%s) got non-symbolized profile: len(p.Function)==0", address) } - if err := checkProfileHasFunction(p, "TestHttpsInsecure"); err != nil { + if err := checkProfileHasFunction(p, "TestHTTPSInsecure"); err != nil { + t.Fatalf("fetchProfiles(%s) %v", address, err) + } +} + +func TestHTTPSWithServerCertFetch(t *testing.T) { + if runtime.GOOS == "nacl" || runtime.GOOS == "js" { + t.Skip("test assumes tcp available") + } + saveHome := os.Getenv(homeEnv()) + tempdir, err := ioutil.TempDir("", "home") + if err != nil { + t.Fatal("creating temp dir: ", err) + } + defer os.RemoveAll(tempdir) + + // pprof writes to $HOME/pprof by default which is not necessarily + // writeable (e.g. on a Debian buildd) so set $HOME to something we + // know we can write to for the duration of the test. + os.Setenv(homeEnv(), tempdir) + defer os.Setenv(homeEnv(), saveHome) + + baseVars := pprofVariables + pprofVariables = baseVars.makeCopy() + defer func() { pprofVariables = baseVars }() + + cert, certBytes, keyBytes := selfSignedCert(t, "localhost") + cas := x509.NewCertPool() + cas.AppendCertsFromPEM(certBytes) + + tlsConfig := &tls.Config{ + RootCAs: cas, + Certificates: []tls.Certificate{cert}, + ClientAuth: tls.RequireAndVerifyClientCert, + ClientCAs: cas, + } + + l, err := tls.Listen("tcp", "localhost:0", tlsConfig) + if err != nil { + t.Fatalf("net.Listen: got error %v, want no error", err) + } + + donec := make(chan error, 1) + go func(donec chan<- error) { + donec <- http.Serve(l, nil) + }(donec) + defer func() { + if got, want := <-donec, closedError(); !strings.Contains(got.Error(), want) { + t.Fatalf("Serve got error %v, want %q", got, want) + } + }() + defer l.Close() + + outputTempFile, err := ioutil.TempFile("", "profile_output") + if err != nil { + t.Fatalf("Failed to create tempfile: %v", err) + } + defer os.Remove(outputTempFile.Name()) + defer outputTempFile.Close() + + // Get port from the address, so request to the server can be made using + // the host name specified in certificates. + _, portStr, err := net.SplitHostPort(l.Addr().String()) + if err != nil { + t.Fatalf("cannot get port from URL: %v", err) + } + address := "https://" + "localhost:" + portStr + "/debug/pprof/goroutine" + s := &source{ + Sources: []string{address}, + Seconds: 10, + Timeout: 10, + Symbolize: "remote", + } + + certTempFile, err := ioutil.TempFile("", "cert_output") + if err != nil { + t.Errorf("cannot create cert tempfile: %v", err) + } + defer os.Remove(certTempFile.Name()) + defer certTempFile.Close() + certTempFile.Write(certBytes) + + keyTempFile, err := ioutil.TempFile("", "key_output") + if err != nil { + t.Errorf("cannot create key tempfile: %v", err) + } + defer os.Remove(keyTempFile.Name()) + defer keyTempFile.Close() + keyTempFile.Write(keyBytes) + + f := &testFlags{ + strings: map[string]string{ + "tls_cert": certTempFile.Name(), + "tls_key": keyTempFile.Name(), + "tls_ca": certTempFile.Name(), + }, + } + o := &plugin.Options{ + Obj: &binutils.Binutils{}, + UI: &proftest.TestUI{T: t, AllowRx: "Saved profile in"}, + Flagset: f, + HTTPTransport: transport.New(f), + } + + o.Sym = &symbolizer.Symbolizer{Obj: o.Obj, UI: o.UI, Transport: o.HTTPTransport} + p, err := fetchProfiles(s, o) + if err != nil { + t.Fatal(err) + } + if len(p.SampleType) == 0 { + t.Fatalf("fetchProfiles(%s) got empty profile: len(p.SampleType)==0", address) + } + if len(p.Function) == 0 { + t.Fatalf("fetchProfiles(%s) got non-symbolized profile: len(p.Function)==0", address) + } + if err := checkProfileHasFunction(p, "TestHTTPSWithServerCertFetch"); err != nil { t.Fatalf("fetchProfiles(%s) %v", address, err) } } @@ -614,7 +722,10 @@ func checkProfileHasFunction(p *profile.Profile, fname string) error { return fmt.Errorf("got %s, want function %q", p.String(), fname) } -func selfSignedCert(t *testing.T) tls.Certificate { +// selfSignedCert generates a self-signed certificate, and returns the +// generated certificate, and byte arrays containing the certificate and +// key associated with the certificate. +func selfSignedCert(t *testing.T, host string) (tls.Certificate, []byte, []byte) { privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) if err != nil { t.Fatalf("failed to generate private key: %v", err) @@ -629,6 +740,8 @@ func selfSignedCert(t *testing.T) tls.Certificate { SerialNumber: big.NewInt(1), NotBefore: time.Now(), NotAfter: time.Now().Add(10 * time.Minute), + IsCA: true, + DNSNames: []string{host}, } b, err = x509.CreateCertificate(rand.Reader, &tmpl, &tmpl, privKey.Public(), privKey) @@ -641,5 +754,5 @@ func selfSignedCert(t *testing.T) tls.Certificate { if err != nil { t.Fatalf("failed to create TLS key pair: %v", err) } - return cert + return cert, bc, bk } diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/flags.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/flags.go new file mode 100644 index 0000000000000..c48fb5cd2e337 --- /dev/null +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/flags.go @@ -0,0 +1,78 @@ +package driver + +import ( + "flag" + "strings" +) + +// GoFlags implements the plugin.FlagSet interface. +type GoFlags struct { + UsageMsgs []string +} + +// Bool implements the plugin.FlagSet interface. +func (*GoFlags) Bool(o string, d bool, c string) *bool { + return flag.Bool(o, d, c) +} + +// Int implements the plugin.FlagSet interface. +func (*GoFlags) Int(o string, d int, c string) *int { + return flag.Int(o, d, c) +} + +// Float64 implements the plugin.FlagSet interface. +func (*GoFlags) Float64(o string, d float64, c string) *float64 { + return flag.Float64(o, d, c) +} + +// String implements the plugin.FlagSet interface. +func (*GoFlags) String(o, d, c string) *string { + return flag.String(o, d, c) +} + +// BoolVar implements the plugin.FlagSet interface. +func (*GoFlags) BoolVar(b *bool, o string, d bool, c string) { + flag.BoolVar(b, o, d, c) +} + +// IntVar implements the plugin.FlagSet interface. +func (*GoFlags) IntVar(i *int, o string, d int, c string) { + flag.IntVar(i, o, d, c) +} + +// Float64Var implements the plugin.FlagSet interface. +// the value of the flag. +func (*GoFlags) Float64Var(f *float64, o string, d float64, c string) { + flag.Float64Var(f, o, d, c) +} + +// StringVar implements the plugin.FlagSet interface. +func (*GoFlags) StringVar(s *string, o, d, c string) { + flag.StringVar(s, o, d, c) +} + +// StringList implements the plugin.FlagSet interface. +func (*GoFlags) StringList(o, d, c string) *[]*string { + return &[]*string{flag.String(o, d, c)} +} + +// ExtraUsage implements the plugin.FlagSet interface. +func (f *GoFlags) ExtraUsage() string { + return strings.Join(f.UsageMsgs, "\n") +} + +// AddExtraUsage implements the plugin.FlagSet interface. +func (f *GoFlags) AddExtraUsage(eu string) { + f.UsageMsgs = append(f.UsageMsgs, eu) +} + +// Parse implements the plugin.FlagSet interface. +func (*GoFlags) Parse(usage func()) []string { + flag.Usage = usage + flag.Parse() + args := flag.Args() + if len(args) == 0 { + usage() + } + return args +} diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/flamegraph.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/flamegraph.go index c9b9a5398f4db..13613cff86f59 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/flamegraph.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/flamegraph.go @@ -55,7 +55,7 @@ func (ui *webInterface) flamegraph(w http.ResponseWriter, req *http.Request) { v := n.CumValue() fullName := n.Info.PrintableName() node := &treeNode{ - Name: getNodeShortName(fullName), + Name: graph.ShortenFunctionName(fullName), FullName: fullName, Cum: v, CumFormat: config.FormatValue(v), @@ -101,19 +101,3 @@ func (ui *webInterface) flamegraph(w http.ResponseWriter, req *http.Request) { Nodes: nodeArr, }) } - -// getNodeShortName builds a short node name from fullName. -func getNodeShortName(name string) string { - chunks := strings.SplitN(name, "(", 2) - head := chunks[0] - pathSep := strings.LastIndexByte(head, '/') - if pathSep == -1 || pathSep+1 >= len(head) { - return name - } - // Check if name is a stdlib package, i.e. doesn't have "." before "/" - if dot := strings.IndexByte(head, '.'); dot == -1 || dot > pathSep { - return name - } - // Trim package path prefix from node name - return name[pathSep+1:] -} diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/flamegraph_test.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/flamegraph_test.go deleted file mode 100644 index c1a887c830ca1..0000000000000 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/flamegraph_test.go +++ /dev/null @@ -1,46 +0,0 @@ -package driver - -import "testing" - -func TestGetNodeShortName(t *testing.T) { - type testCase struct { - name string - want string - } - testcases := []testCase{ - { - "root", - "root", - }, - { - "syscall.Syscall", - "syscall.Syscall", - }, - { - "net/http.(*conn).serve", - "net/http.(*conn).serve", - }, - { - "github.com/blah/foo.Foo", - "foo.Foo", - }, - { - "github.com/blah/foo_bar.(*FooBar).Foo", - "foo_bar.(*FooBar).Foo", - }, - { - "encoding/json.(*structEncoder).(encoding/json.encode)-fm", - "encoding/json.(*structEncoder).(encoding/json.encode)-fm", - }, - { - "github.com/blah/blah/vendor/gopkg.in/redis.v3.(*baseClient).(github.com/blah/blah/vendor/gopkg.in/redis.v3.process)-fm", - "redis.v3.(*baseClient).(github.com/blah/blah/vendor/gopkg.in/redis.v3.process)-fm", - }, - } - for _, tc := range testcases { - name := getNodeShortName(tc.name) - if got, want := name, tc.want; got != want { - t.Errorf("for %s, got %q, want %q", tc.name, got, want) - } - } -} diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/interactive_test.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/interactive_test.go index 8d775e16bdbc0..758adf9bdced1 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/interactive_test.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/interactive_test.go @@ -23,6 +23,7 @@ import ( "github.com/google/pprof/internal/plugin" "github.com/google/pprof/internal/proftest" "github.com/google/pprof/internal/report" + "github.com/google/pprof/internal/transport" "github.com/google/pprof/profile" ) @@ -41,7 +42,10 @@ func TestShell(t *testing.T) { // Random interleave of independent scripts pprofVariables = testVariables(savedVariables) - o := setDefaults(nil) + + // pass in HTTPTransport when setting defaults, because otherwise default + // transport will try to add flags to the default flag set. + o := setDefaults(&plugin.Options{HTTPTransport: transport.New(nil)}) o.UI = newUI(t, interleave(script, 0)) if err := interactive(p, o); err != nil { t.Error("first attempt:", err) @@ -259,12 +263,13 @@ func TestInteractiveCommands(t *testing.T) { { "weblist find -test", map[string]string{ - "functions": "false", - "addressnoinlines": "true", - "nodecount": "0", - "cum": "false", - "flat": "true", - "ignore": "test", + "functions": "false", + "addresses": "true", + "noinlines": "true", + "nodecount": "0", + "cum": "false", + "flat": "true", + "ignore": "test", }, }, { diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/options.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/options.go index 34167d4bf5793..6e8f9fca25493 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/options.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/options.go @@ -16,7 +16,6 @@ package driver import ( "bufio" - "flag" "fmt" "io" "os" @@ -25,6 +24,7 @@ import ( "github.com/google/pprof/internal/binutils" "github.com/google/pprof/internal/plugin" "github.com/google/pprof/internal/symbolizer" + "github.com/google/pprof/internal/transport" ) // setDefaults returns a new plugin.Options with zero fields sets to @@ -38,7 +38,7 @@ func setDefaults(o *plugin.Options) *plugin.Options { d.Writer = oswriter{} } if d.Flagset == nil { - d.Flagset = goFlags{} + d.Flagset = &GoFlags{} } if d.Obj == nil { d.Obj = &binutils.Binutils{} @@ -46,67 +46,15 @@ func setDefaults(o *plugin.Options) *plugin.Options { if d.UI == nil { d.UI = &stdUI{r: bufio.NewReader(os.Stdin)} } + if d.HTTPTransport == nil { + d.HTTPTransport = transport.New(d.Flagset) + } if d.Sym == nil { - d.Sym = &symbolizer.Symbolizer{Obj: d.Obj, UI: d.UI} + d.Sym = &symbolizer.Symbolizer{Obj: d.Obj, UI: d.UI, Transport: d.HTTPTransport} } return d } -// goFlags returns a flagset implementation based on the standard flag -// package from the Go distribution. It implements the plugin.FlagSet -// interface. -type goFlags struct{} - -func (goFlags) Bool(o string, d bool, c string) *bool { - return flag.Bool(o, d, c) -} - -func (goFlags) Int(o string, d int, c string) *int { - return flag.Int(o, d, c) -} - -func (goFlags) Float64(o string, d float64, c string) *float64 { - return flag.Float64(o, d, c) -} - -func (goFlags) String(o, d, c string) *string { - return flag.String(o, d, c) -} - -func (goFlags) BoolVar(b *bool, o string, d bool, c string) { - flag.BoolVar(b, o, d, c) -} - -func (goFlags) IntVar(i *int, o string, d int, c string) { - flag.IntVar(i, o, d, c) -} - -func (goFlags) Float64Var(f *float64, o string, d float64, c string) { - flag.Float64Var(f, o, d, c) -} - -func (goFlags) StringVar(s *string, o, d, c string) { - flag.StringVar(s, o, d, c) -} - -func (goFlags) StringList(o, d, c string) *[]*string { - return &[]*string{flag.String(o, d, c)} -} - -func (goFlags) ExtraUsage() string { - return "" -} - -func (goFlags) Parse(usage func()) []string { - flag.Usage = usage - flag.Parse() - args := flag.Args() - if len(args) == 0 { - usage() - } - return args -} - type stdUI struct { r *bufio.Reader } diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.addresses.noinlines.text b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.addresses.noinlines.text new file mode 100644 index 0000000000000..d53c44dad9153 --- /dev/null +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.addresses.noinlines.text @@ -0,0 +1,7 @@ +Showing nodes accounting for 1.12s, 100% of 1.12s total +Dropped 1 node (cum <= 0.06s) + flat flat% sum% cum cum% + 1.10s 98.21% 98.21% 1.10s 98.21% 0000000000001000 line1000 testdata/file1000.src:1 + 0.01s 0.89% 99.11% 1.01s 90.18% 0000000000002000 line2000 testdata/file2000.src:4 + 0.01s 0.89% 100% 1.01s 90.18% 0000000000003000 line3000 testdata/file3000.src:6 + 0 0% 100% 0.10s 8.93% 0000000000003001 line3000 testdata/file3000.src:9 diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.filefunctions.noinlines.text b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.filefunctions.noinlines.text new file mode 100644 index 0000000000000..88fb760759c88 --- /dev/null +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.filefunctions.noinlines.text @@ -0,0 +1,5 @@ +Showing nodes accounting for 1.12s, 100% of 1.12s total + flat flat% sum% cum cum% + 1.10s 98.21% 98.21% 1.10s 98.21% line1000 testdata/file1000.src + 0.01s 0.89% 99.11% 1.01s 90.18% line2000 testdata/file2000.src + 0.01s 0.89% 100% 1.12s 100% line3000 testdata/file3000.src diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.functions.noinlines.text b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.functions.noinlines.text new file mode 100644 index 0000000000000..493b4912de1c6 --- /dev/null +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.flat.functions.noinlines.text @@ -0,0 +1,5 @@ +Showing nodes accounting for 1.12s, 100% of 1.12s total + flat flat% sum% cum cum% + 1.10s 98.21% 98.21% 1.10s 98.21% line1000 + 0.01s 0.89% 99.11% 1.01s 90.18% line2000 + 0.01s 0.89% 100% 1.12s 100% line3000 diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.lines.topproto b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.lines.topproto new file mode 100644 index 0000000000000..33bf6814a463c --- /dev/null +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.cpu.lines.topproto @@ -0,0 +1,3 @@ +Showing nodes accounting for 1s, 100% of 1s total + flat flat% sum% cum cum% + 1s 100% 100% 1s 100% mangled1000 testdata/file1000.src:1 diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.longNameFuncs.dot b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.longNameFuncs.dot new file mode 100644 index 0000000000000..474a5108ba1c3 --- /dev/null +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.longNameFuncs.dot @@ -0,0 +1,9 @@ +digraph "testbinary" { +node [style=filled fillcolor="#f8f8f8"] +subgraph cluster_L { "File: testbinary" [shape=box fontsize=16 label="File: testbinary\lType: cpu\lDuration: 10s, Total samples = 1.11s (11.10%)\lShowing nodes accounting for 1.11s, 100% of 1.11s total\l" tooltip="testbinary"] } +N1 [label="package1\nobject\nfunction1\n1.10s (99.10%)" id="node1" fontsize=24 shape=box tooltip="path/to/package1.object.function1 (1.10s)" color="#b20000" fillcolor="#edd5d5"] +N2 [label="FooBar\nrun\n0.01s (0.9%)\nof 1.01s (90.99%)" id="node2" fontsize=10 shape=box tooltip="java.bar.foo.FooBar.run(java.lang.Runnable) (1.01s)" color="#b20400" fillcolor="#edd6d5"] +N3 [label="Bar\nFoo\n0 of 1.10s (99.10%)" id="node3" fontsize=8 shape=box tooltip="(anonymous namespace)::Bar::Foo (1.10s)" color="#b20000" fillcolor="#edd5d5"] +N3 -> N1 [label=" 1.10s" weight=100 penwidth=5 color="#b20000" tooltip="(anonymous namespace)::Bar::Foo -> path/to/package1.object.function1 (1.10s)" labeltooltip="(anonymous namespace)::Bar::Foo -> path/to/package1.object.function1 (1.10s)"] +N2 -> N3 [label=" 1s" weight=91 penwidth=5 color="#b20500" tooltip="java.bar.foo.FooBar.run(java.lang.Runnable) -> (anonymous namespace)::Bar::Foo (1s)" labeltooltip="java.bar.foo.FooBar.run(java.lang.Runnable) -> (anonymous namespace)::Bar::Foo (1s)"] +} diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.longNameFuncs.text b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.longNameFuncs.text new file mode 100644 index 0000000000000..39cb24ed6a202 --- /dev/null +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/testdata/pprof.longNameFuncs.text @@ -0,0 +1,5 @@ +Showing nodes accounting for 1.11s, 100% of 1.11s total + flat flat% sum% cum cum% + 1.10s 99.10% 99.10% 1.10s 99.10% path/to/package1.object.function1 + 0.01s 0.9% 100% 1.01s 90.99% java.bar.foo.FooBar.run(java.lang.Runnable) + 0 0% 100% 1.10s 99.10% (anonymous namespace)::Bar::Foo diff --git a/src/cmd/vendor/github.com/google/pprof/internal/driver/webhtml.go b/src/cmd/vendor/github.com/google/pprof/internal/driver/webhtml.go index c3f9c384f8a66..74104899ca0ae 100644 --- a/src/cmd/vendor/github.com/google/pprof/internal/driver/webhtml.go +++ b/src/cmd/vendor/github.com/google/pprof/internal/driver/webhtml.go @@ -249,6 +249,21 @@ table tr td { + {{$sampleLen := len .SampleTypes}} + {{if gt $sampleLen 1}} +

      + {{end}} +