2015-03-05 10:45:56 -05:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
|
// “Abstract” syntax representation.
|
|
|
|
|
|
|
|
|
|
package gc
|
|
|
|
|
|
|
|
|
|
// A Node is a single node in the syntax tree.
|
|
|
|
|
// Actually the syntax tree is a syntax DAG, because there is only one
|
|
|
|
|
// node with Op=ONAME for a given instance of a variable x.
|
|
|
|
|
// The same is true for Op=OTYPE and Op=OLITERAL.
|
|
|
|
|
type Node struct {
|
2015-03-05 13:57:36 -05:00
|
|
|
// Tree structure.
|
|
|
|
|
// Generic recursive walks should follow these fields.
|
|
|
|
|
Left *Node
|
|
|
|
|
Right *Node
|
|
|
|
|
Ninit *NodeList
|
|
|
|
|
Nbody *NodeList
|
|
|
|
|
List *NodeList
|
|
|
|
|
Rlist *NodeList
|
|
|
|
|
|
|
|
|
|
// most nodes
|
2015-05-27 10:44:43 -04:00
|
|
|
Type *Type
|
|
|
|
|
Orig *Node // original form, for printing, and tracking copies of ONAMEs
|
2015-03-05 13:57:36 -05:00
|
|
|
|
|
|
|
|
// func
|
2015-03-25 19:33:01 -07:00
|
|
|
Func *Func
|
2015-03-05 13:57:36 -05:00
|
|
|
|
|
|
|
|
// ONAME
|
2015-05-27 07:31:56 -04:00
|
|
|
Name *Name
|
2015-03-05 13:57:36 -05:00
|
|
|
|
2015-05-27 00:47:05 -04:00
|
|
|
Sym *Sym // various
|
|
|
|
|
E interface{} // Opt or Val, see methods below
|
2015-03-05 13:57:36 -05:00
|
|
|
|
2015-05-26 21:30:20 -04:00
|
|
|
Xoffset int64
|
2015-05-18 15:49:02 -07:00
|
|
|
|
2015-05-27 00:44:05 -04:00
|
|
|
Lineno int32
|
2015-05-18 15:49:02 -07:00
|
|
|
|
|
|
|
|
// OREGISTER, OINDREG
|
|
|
|
|
Reg int16
|
|
|
|
|
|
2015-05-26 23:42:41 -04:00
|
|
|
Esc uint16 // EscXXX
|
2015-05-18 15:49:02 -07:00
|
|
|
|
|
|
|
|
Op uint8
|
|
|
|
|
Nointerface bool
|
|
|
|
|
Ullman uint8 // sethi/ullman number
|
|
|
|
|
Addable bool // addressable
|
|
|
|
|
Etype uint8 // op for OASOP, etype for OTYPE, exclam for export, 6g saved reg
|
|
|
|
|
Bounded bool // bounds check unnecessary
|
|
|
|
|
Class uint8 // PPARAM, PAUTO, PEXTERN, etc
|
|
|
|
|
Embedded uint8 // ODCLFIELD embedded type
|
|
|
|
|
Colas bool // OAS resulting from :=
|
|
|
|
|
Diag uint8 // already printed error about this
|
|
|
|
|
Noescape bool // func arguments do not escape; TODO(rsc): move Noescape to Func struct (see CL 7360)
|
|
|
|
|
Walkdef uint8
|
|
|
|
|
Typecheck uint8
|
|
|
|
|
Local bool
|
|
|
|
|
Dodata uint8
|
|
|
|
|
Initorder uint8
|
|
|
|
|
Used bool
|
|
|
|
|
Isddd bool // is the argument variadic
|
|
|
|
|
Implicit bool
|
|
|
|
|
Addrtaken bool // address taken, even if not moved to heap
|
|
|
|
|
Assigned bool // is the variable ever assigned to
|
|
|
|
|
Likely int8 // likeliness of if statement
|
|
|
|
|
Hasbreak bool // has break statement
|
2015-05-27 00:47:05 -04:00
|
|
|
hasVal int8 // +1 for Val, -1 for Opt, 0 for not yet set
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Val returns the Val for the node.
|
|
|
|
|
func (n *Node) Val() Val {
|
|
|
|
|
if n.hasVal != +1 {
|
|
|
|
|
return Val{}
|
|
|
|
|
}
|
|
|
|
|
return Val{n.E}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetVal sets the Val for the node, which must not have been used with SetOpt.
|
|
|
|
|
func (n *Node) SetVal(v Val) {
|
|
|
|
|
if n.hasVal == -1 {
|
|
|
|
|
Debug['h'] = 1
|
|
|
|
|
Dump("have Opt", n)
|
|
|
|
|
Fatal("have Opt")
|
|
|
|
|
}
|
|
|
|
|
n.hasVal = +1
|
|
|
|
|
n.E = v.U
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Opt returns the optimizer data for the node.
|
|
|
|
|
func (n *Node) Opt() interface{} {
|
|
|
|
|
if n.hasVal != -1 {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
return n.E
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetOpt sets the optimizer data for the node, which must not have been used with SetVal.
|
|
|
|
|
// SetOpt(nil) is ignored for Vals to simplify call sites that are clearing Opts.
|
|
|
|
|
func (n *Node) SetOpt(x interface{}) {
|
|
|
|
|
if x == nil && n.hasVal >= 0 {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if n.hasVal == +1 {
|
|
|
|
|
Debug['h'] = 1
|
|
|
|
|
Dump("have Val", n)
|
|
|
|
|
Fatal("have Val")
|
|
|
|
|
}
|
|
|
|
|
n.hasVal = -1
|
|
|
|
|
n.E = x
|
2015-03-10 21:37:13 -07:00
|
|
|
}
|
|
|
|
|
|
2015-05-26 23:18:27 -04:00
|
|
|
// Name holds Node fields used only by named nodes (ONAME, OPACK, some OLITERAL).
|
2015-04-03 17:43:38 -07:00
|
|
|
type Name struct {
|
2015-06-03 14:16:01 -04:00
|
|
|
Pack *Node // real package for import . names
|
|
|
|
|
Pkg *Pkg // pkg for OPACK nodes
|
|
|
|
|
Heapaddr *Node // temp holding heap address of param
|
|
|
|
|
Inlvar *Node // ONAME substitute while inlining
|
|
|
|
|
Defn *Node // initializing assignment
|
|
|
|
|
Curfn *Node // function for local variables
|
|
|
|
|
Param *Param
|
2015-05-14 19:33:31 -07:00
|
|
|
Decldepth int32 // declaration loop depth, increased for every loop or label
|
2015-06-03 14:16:01 -04:00
|
|
|
Vargen int32 // unique name for ONAME within a function. Function outputs are numbered starting at one.
|
2015-05-26 23:56:14 -04:00
|
|
|
Iota int32 // value if this name is iota
|
2015-05-27 00:44:05 -04:00
|
|
|
Funcdepth int32
|
|
|
|
|
Method bool // OCALLMETH name
|
2015-04-03 17:43:38 -07:00
|
|
|
Readonly bool
|
|
|
|
|
Captured bool // is the variable captured by a closure
|
|
|
|
|
Byval bool // is the variable captured by value or by reference
|
|
|
|
|
Needzero bool // if it contains pointers, needs to be zeroed on function entry
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-18 10:27:59 -07:00
|
|
|
type Param struct {
|
|
|
|
|
Ntype *Node
|
|
|
|
|
|
|
|
|
|
// ONAME func param with PHEAP
|
|
|
|
|
Outerexpr *Node // expression copied into closure for variable
|
|
|
|
|
Stackparam *Node // OPARAM node referring to stack copy of param
|
|
|
|
|
|
2015-05-26 21:49:31 -04:00
|
|
|
// ONAME PPARAM
|
|
|
|
|
Field *Type // TFIELD in arg struct
|
|
|
|
|
|
2015-05-18 10:27:59 -07:00
|
|
|
// ONAME closure param with PPARAMREF
|
|
|
|
|
Outer *Node // outer PPARAMREF in nested closure
|
|
|
|
|
Closure *Node // ONAME/PHEAP <-> ONAME/PPARAMREF
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-10 21:37:13 -07:00
|
|
|
// Func holds Node fields used only with function-like nodes.
|
|
|
|
|
type Func struct {
|
2015-05-26 21:49:31 -04:00
|
|
|
Shortname *Node
|
|
|
|
|
Enter *NodeList
|
|
|
|
|
Exit *NodeList
|
|
|
|
|
Cvars *NodeList // closure params
|
|
|
|
|
Dcl *NodeList // autodcl for this func/closure
|
|
|
|
|
Inldcl *NodeList // copy of dcl for use in inlining
|
|
|
|
|
Closgen int
|
|
|
|
|
Outerfunc *Node
|
|
|
|
|
Fieldtrack []*Type
|
2015-05-27 00:44:05 -04:00
|
|
|
Outer *Node // outer func for closure
|
|
|
|
|
Ntype *Node // signature
|
|
|
|
|
Top int // top context (Ecall, Eproc, etc)
|
|
|
|
|
Closure *Node // OCLOSURE <-> ODCLFUNC
|
2015-05-27 07:31:56 -04:00
|
|
|
FCurfn *Node
|
2015-05-27 10:42:55 -04:00
|
|
|
Nname *Node
|
2015-03-10 21:37:13 -07:00
|
|
|
|
|
|
|
|
Inl *NodeList // copy of the body for use in inlining
|
|
|
|
|
InlCost int32
|
2015-05-27 00:44:05 -04:00
|
|
|
Depth int32
|
2015-03-10 21:37:13 -07:00
|
|
|
|
2015-03-05 13:57:36 -05:00
|
|
|
Endlineno int32
|
2015-03-10 21:37:13 -07:00
|
|
|
|
|
|
|
|
Nosplit bool // func should not execute on separate stack
|
|
|
|
|
Nowritebarrier bool // emit compiler error instead of write barrier
|
|
|
|
|
Dupok bool // duplicate definitions ok
|
|
|
|
|
Wrapper bool // is method wrapper
|
|
|
|
|
Needctxt bool // function uses context register (has closure variables)
|
2015-03-05 10:45:56 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Node ops.
|
|
|
|
|
const (
|
|
|
|
|
OXXX = iota
|
2015-03-05 13:57:36 -05:00
|
|
|
|
|
|
|
|
// names
|
|
|
|
|
ONAME // var, const or func name
|
|
|
|
|
ONONAME // unnamed arg or return value: f(int, string) (int, error) { etc }
|
|
|
|
|
OTYPE // type name
|
|
|
|
|
OPACK // import
|
|
|
|
|
OLITERAL // literal
|
|
|
|
|
|
|
|
|
|
// expressions
|
|
|
|
|
OADD // x + y
|
|
|
|
|
OSUB // x - y
|
|
|
|
|
OOR // x | y
|
|
|
|
|
OXOR // x ^ y
|
|
|
|
|
OADDSTR // s + "foo"
|
|
|
|
|
OADDR // &x
|
|
|
|
|
OANDAND // b0 && b1
|
|
|
|
|
OAPPEND // append
|
|
|
|
|
OARRAYBYTESTR // string(bytes)
|
|
|
|
|
OARRAYBYTESTRTMP // string(bytes) ephemeral
|
|
|
|
|
OARRAYRUNESTR // string(runes)
|
|
|
|
|
OSTRARRAYBYTE // []byte(s)
|
|
|
|
|
OSTRARRAYBYTETMP // []byte(s) ephemeral
|
|
|
|
|
OSTRARRAYRUNE // []rune(s)
|
|
|
|
|
OAS // x = y or x := y
|
|
|
|
|
OAS2 // x, y, z = xx, yy, zz
|
|
|
|
|
OAS2FUNC // x, y = f()
|
|
|
|
|
OAS2RECV // x, ok = <-c
|
|
|
|
|
OAS2MAPR // x, ok = m["foo"]
|
|
|
|
|
OAS2DOTTYPE // x, ok = I.(int)
|
|
|
|
|
OASOP // x += y
|
cmd/internal/gc: emit write barriers at lower level
This is primarily preparation for inlining, not an optimization by itself,
but it still helps some.
name old new delta
BenchmarkBinaryTree17 18.2s × (0.99,1.01) 17.9s × (0.99,1.01) -1.57%
BenchmarkFannkuch11 4.44s × (1.00,1.00) 4.42s × (1.00,1.00) -0.40%
BenchmarkFmtFprintfEmpty 119ns × (0.95,1.02) 118ns × (0.96,1.02) ~
BenchmarkFmtFprintfString 501ns × (0.99,1.02) 486ns × (0.99,1.01) -2.89%
BenchmarkFmtFprintfInt 474ns × (0.99,1.00) 457ns × (0.99,1.01) -3.59%
BenchmarkFmtFprintfIntInt 792ns × (1.00,1.00) 768ns × (1.00,1.01) -3.03%
BenchmarkFmtFprintfPrefixedInt 574ns × (1.00,1.01) 584ns × (0.99,1.03) +1.83%
BenchmarkFmtFprintfFloat 749ns × (1.00,1.00) 739ns × (0.99,1.00) -1.34%
BenchmarkFmtManyArgs 2.94µs × (1.00,1.01) 2.77µs × (1.00,1.00) -5.76%
BenchmarkGobDecode 39.5ms × (0.99,1.01) 39.3ms × (0.99,1.01) ~
BenchmarkGobEncode 39.4ms × (1.00,1.01) 39.4ms × (0.99,1.00) ~
BenchmarkGzip 658ms × (1.00,1.01) 661ms × (0.99,1.01) ~
BenchmarkGunzip 142ms × (1.00,1.00) 142ms × (1.00,1.00) +0.22%
BenchmarkHTTPClientServer 134µs × (0.99,1.01) 133µs × (0.98,1.01) ~
BenchmarkJSONEncode 57.1ms × (0.99,1.01) 56.5ms × (0.99,1.01) ~
BenchmarkJSONDecode 141ms × (1.00,1.00) 143ms × (1.00,1.00) +1.09%
BenchmarkMandelbrot200 6.01ms × (1.00,1.00) 6.01ms × (1.00,1.00) ~
BenchmarkGoParse 10.1ms × (0.91,1.09) 9.6ms × (0.94,1.07) ~
BenchmarkRegexpMatchEasy0_32 207ns × (1.00,1.01) 210ns × (1.00,1.00) +1.45%
BenchmarkRegexpMatchEasy0_1K 592ns × (0.99,1.00) 596ns × (0.99,1.01) +0.68%
BenchmarkRegexpMatchEasy1_32 184ns × (0.99,1.01) 184ns × (0.99,1.01) ~
BenchmarkRegexpMatchEasy1_1K 1.01µs × (1.00,1.00) 1.01µs × (0.99,1.01) ~
BenchmarkRegexpMatchMedium_32 327ns × (0.99,1.00) 327ns × (1.00,1.01) ~
BenchmarkRegexpMatchMedium_1K 92.5µs × (1.00,1.00) 93.0µs × (1.00,1.02) +0.48%
BenchmarkRegexpMatchHard_32 4.79µs × (0.95,1.00) 4.76µs × (0.95,1.01) ~
BenchmarkRegexpMatchHard_1K 136µs × (1.00,1.00) 136µs × (1.00,1.01) ~
BenchmarkRevcomp 900ms × (0.99,1.01) 892ms × (1.00,1.01) ~
BenchmarkTemplate 170ms × (0.99,1.01) 175ms × (0.99,1.00) +2.95%
BenchmarkTimeParse 645ns × (1.00,1.00) 638ns × (1.00,1.00) -1.16%
BenchmarkTimeFormat 740ns × (1.00,1.00) 772ns × (1.00,1.00) +4.39%
Change-Id: I0be905e32791e0cb70ff01f169c4b309a971d981
Reviewed-on: https://go-review.googlesource.com/9159
Reviewed-by: Rick Hudson <rlh@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
2015-04-17 00:25:10 -04:00
|
|
|
OASWB // OAS but with write barrier
|
2015-03-05 13:57:36 -05:00
|
|
|
OCALL // function call, method call or type conversion, possibly preceded by defer or go.
|
|
|
|
|
OCALLFUNC // f()
|
|
|
|
|
OCALLMETH // t.Method()
|
|
|
|
|
OCALLINTER // err.Error()
|
|
|
|
|
OCALLPART // t.Method (without ())
|
|
|
|
|
OCAP // cap
|
|
|
|
|
OCLOSE // close
|
|
|
|
|
OCLOSURE // f = func() { etc }
|
|
|
|
|
OCMPIFACE // err1 == err2
|
|
|
|
|
OCMPSTR // s1 == s2
|
|
|
|
|
OCOMPLIT // composite literal, typechecking may convert to a more specific OXXXLIT.
|
|
|
|
|
OMAPLIT // M{"foo":3, "bar":4}
|
|
|
|
|
OSTRUCTLIT // T{x:3, y:4}
|
|
|
|
|
OARRAYLIT // [2]int{3, 4}
|
|
|
|
|
OPTRLIT // &T{x:3, y:4}
|
|
|
|
|
OCONV // var i int; var u uint; i = int(u)
|
|
|
|
|
OCONVIFACE // I(t)
|
|
|
|
|
OCONVNOP // type Int int; var i int; var j Int; i = int(j)
|
|
|
|
|
OCOPY // copy
|
|
|
|
|
ODCL // var x int
|
|
|
|
|
ODCLFUNC // func f() or func (r) f()
|
|
|
|
|
ODCLFIELD // struct field, interface field, or func/method argument/return value.
|
|
|
|
|
ODCLCONST // const pi = 3.14
|
|
|
|
|
ODCLTYPE // type Int int
|
|
|
|
|
ODELETE // delete
|
|
|
|
|
ODOT // t.x
|
|
|
|
|
ODOTPTR // p.x that is implicitly (*p).x
|
|
|
|
|
ODOTMETH // t.Method
|
|
|
|
|
ODOTINTER // err.Error
|
|
|
|
|
OXDOT // t.x, typechecking may convert to a more specific ODOTXXX.
|
|
|
|
|
ODOTTYPE // e = err.(MyErr)
|
|
|
|
|
ODOTTYPE2 // e, ok = err.(MyErr)
|
|
|
|
|
OEQ // x == y
|
|
|
|
|
ONE // x != y
|
|
|
|
|
OLT // x < y
|
|
|
|
|
OLE // x <= y
|
|
|
|
|
OGE // x >= y
|
|
|
|
|
OGT // x > y
|
|
|
|
|
OIND // *p
|
|
|
|
|
OINDEX // a[i]
|
|
|
|
|
OINDEXMAP // m[s]
|
|
|
|
|
OKEY // The x:3 in t{x:3, y:4}, the 1:2 in a[1:2], the 2:20 in [3]int{2:20}, etc.
|
|
|
|
|
OPARAM // The on-stack copy of a parameter or return value that escapes.
|
|
|
|
|
OLEN // len
|
|
|
|
|
OMAKE // make, typechecking may convert to a more specific OMAKEXXX.
|
|
|
|
|
OMAKECHAN // make(chan int)
|
|
|
|
|
OMAKEMAP // make(map[string]int)
|
|
|
|
|
OMAKESLICE // make([]int, 0)
|
|
|
|
|
OMUL // *
|
|
|
|
|
ODIV // x / y
|
|
|
|
|
OMOD // x % y
|
|
|
|
|
OLSH // x << u
|
|
|
|
|
ORSH // x >> u
|
|
|
|
|
OAND // x & y
|
|
|
|
|
OANDNOT // x &^ y
|
|
|
|
|
ONEW // new
|
|
|
|
|
ONOT // !b
|
|
|
|
|
OCOM // ^x
|
|
|
|
|
OPLUS // +x
|
|
|
|
|
OMINUS // -y
|
|
|
|
|
OOROR // b1 || b2
|
|
|
|
|
OPANIC // panic
|
|
|
|
|
OPRINT // print
|
|
|
|
|
OPRINTN // println
|
|
|
|
|
OPAREN // (x)
|
|
|
|
|
OSEND // c <- x
|
|
|
|
|
OSLICE // v[1:2], typechecking may convert to a more specific OSLICEXXX.
|
|
|
|
|
OSLICEARR // a[1:2]
|
|
|
|
|
OSLICESTR // s[1:2]
|
|
|
|
|
OSLICE3 // v[1:2:3], typechecking may convert to OSLICE3ARR.
|
|
|
|
|
OSLICE3ARR // a[1:2:3]
|
|
|
|
|
ORECOVER // recover
|
|
|
|
|
ORECV // <-c
|
|
|
|
|
ORUNESTR // string(i)
|
|
|
|
|
OSELRECV // case x = <-c:
|
|
|
|
|
OSELRECV2 // case x, ok = <-c:
|
|
|
|
|
OIOTA // iota
|
|
|
|
|
OREAL // real
|
|
|
|
|
OIMAG // imag
|
|
|
|
|
OCOMPLEX // complex
|
|
|
|
|
|
|
|
|
|
// statements
|
|
|
|
|
OBLOCK // block of code
|
|
|
|
|
OBREAK // break
|
|
|
|
|
OCASE // case, after being verified by swt.c's casebody.
|
|
|
|
|
OXCASE // case, before verification.
|
|
|
|
|
OCONTINUE // continue
|
|
|
|
|
ODEFER // defer
|
|
|
|
|
OEMPTY // no-op
|
|
|
|
|
OFALL // fallthrough, after being verified by swt.c's casebody.
|
|
|
|
|
OXFALL // fallthrough, before verification.
|
|
|
|
|
OFOR // for
|
|
|
|
|
OGOTO // goto
|
|
|
|
|
OIF // if
|
|
|
|
|
OLABEL // label:
|
|
|
|
|
OPROC // go
|
|
|
|
|
ORANGE // range
|
|
|
|
|
ORETURN // return
|
|
|
|
|
OSELECT // select
|
|
|
|
|
OSWITCH // switch x
|
|
|
|
|
OTYPESW // switch err.(type)
|
|
|
|
|
|
|
|
|
|
// types
|
|
|
|
|
OTCHAN // chan int
|
|
|
|
|
OTMAP // map[string]int
|
|
|
|
|
OTSTRUCT // struct{}
|
|
|
|
|
OTINTER // interface{}
|
|
|
|
|
OTFUNC // func()
|
|
|
|
|
OTARRAY // []int, [8]int, [N]int or [...]int
|
|
|
|
|
|
|
|
|
|
// misc
|
|
|
|
|
ODDD // func f(args ...int) or f(l...) or var a = [...]int{0, 1, 2}.
|
|
|
|
|
ODDDARG // func f(args ...int), introduced by escape analysis.
|
|
|
|
|
OINLCALL // intermediary representation of an inlined call.
|
|
|
|
|
OEFACE // itable and data words of an empty-interface value.
|
|
|
|
|
OITAB // itable word of an interface value.
|
|
|
|
|
OSPTR // base pointer of a slice or string.
|
|
|
|
|
OCLOSUREVAR // variable reference at beginning of closure function
|
|
|
|
|
OCFUNC // reference to c function pointer (not go func value)
|
|
|
|
|
OCHECKNIL // emit code to ensure pointer/interface not nil
|
|
|
|
|
OVARKILL // variable is dead
|
|
|
|
|
|
|
|
|
|
// thearch-specific registers
|
|
|
|
|
OREGISTER // a register, such as AX.
|
|
|
|
|
OINDREG // offset plus indirect of a register, such as 8(SP).
|
|
|
|
|
|
2015-04-01 16:02:34 -04:00
|
|
|
// arch-specific opcodes
|
2015-03-05 13:57:36 -05:00
|
|
|
OCMP // compare: ACMP.
|
|
|
|
|
ODEC // decrement: ADEC.
|
|
|
|
|
OINC // increment: AINC.
|
|
|
|
|
OEXTEND // extend: ACWD/ACDQ/ACQO.
|
|
|
|
|
OHMUL // high mul: AMUL/AIMUL for unsigned/signed (OMUL uses AIMUL for both).
|
|
|
|
|
OLROT // left rotate: AROL.
|
|
|
|
|
ORROTC // right rotate-carry: ARCR.
|
|
|
|
|
ORETJMP // return to other function
|
2015-03-18 17:26:36 -04:00
|
|
|
OPS // compare parity set (for x86 NaN check)
|
cmd/internal/gc, cmd/6g: generate boolean values without jumps
Use SETcc instructions instead of Jcc to generate boolean values.
This generates shorter, jump-free code, which may in turn enable other
peephole optimizations.
For example, given
func f(i, j int) bool {
return i == j
}
Before
"".f t=1 size=32 value=0 args=0x18 locals=0x0
0x0000 00000 (x.go:3) TEXT "".f(SB), $0-24
0x0000 00000 (x.go:3) FUNCDATA $0, gclocals·b4c25e9b09fd0cf9bb429dcefe91c353(SB)
0x0000 00000 (x.go:3) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0000 00000 (x.go:4) MOVQ "".i+8(FP), BX
0x0005 00005 (x.go:4) MOVQ "".j+16(FP), BP
0x000a 00010 (x.go:4) CMPQ BX, BP
0x000d 00013 (x.go:4) JEQ 21
0x000f 00015 (x.go:4) MOVB $0, "".~r2+24(FP)
0x0014 00020 (x.go:4) RET
0x0015 00021 (x.go:4) MOVB $1, "".~r2+24(FP)
0x001a 00026 (x.go:4) JMP 20
After
"".f t=1 size=32 value=0 args=0x18 locals=0x0
0x0000 00000 (x.go:3) TEXT "".f(SB), $0-24
0x0000 00000 (x.go:3) FUNCDATA $0, gclocals·b4c25e9b09fd0cf9bb429dcefe91c353(SB)
0x0000 00000 (x.go:3) FUNCDATA $1, gclocals·33cdeccccebe80329f1fdbee7f5874cb(SB)
0x0000 00000 (x.go:4) MOVQ "".i+8(FP), BX
0x0005 00005 (x.go:4) MOVQ "".j+16(FP), BP
0x000a 00010 (x.go:4) CMPQ BX, BP
0x000d 00013 (x.go:4) SETEQ "".~r2+24(FP)
0x0012 00018 (x.go:4) RET
regexp benchmarks, best of 12 runs:
benchmark old ns/op new ns/op delta
BenchmarkNotOnePassShortB 782 733 -6.27%
BenchmarkLiteral 180 171 -5.00%
BenchmarkNotLiteral 2855 2721 -4.69%
BenchmarkMatchHard_32 2672 2557 -4.30%
BenchmarkMatchHard_1K 80182 76732 -4.30%
BenchmarkMatchEasy1_32M 76440180 73304748 -4.10%
BenchmarkMatchEasy1_32K 68798 66350 -3.56%
BenchmarkAnchoredLongMatch 482 465 -3.53%
BenchmarkMatchEasy1_1M 2373042 2292692 -3.39%
BenchmarkReplaceAll 2776 2690 -3.10%
BenchmarkNotOnePassShortA 1397 1360 -2.65%
BenchmarkMatchClass_InRange 3842 3742 -2.60%
BenchmarkMatchEasy0_32 125 122 -2.40%
BenchmarkMatchEasy0_32K 11414 11164 -2.19%
BenchmarkMatchEasy0_1K 668 654 -2.10%
BenchmarkAnchoredShortMatch 260 255 -1.92%
BenchmarkAnchoredLiteralShortNonMatch 164 161 -1.83%
BenchmarkOnePassShortB 623 612 -1.77%
BenchmarkOnePassShortA 801 788 -1.62%
BenchmarkMatchClass 4094 4033 -1.49%
BenchmarkMatchEasy0_32M 14078800 13890704 -1.34%
BenchmarkMatchHard_32K 4095844 4045820 -1.22%
BenchmarkMatchEasy1_1K 1663 1643 -1.20%
BenchmarkMatchHard_1M 131261708 129708215 -1.18%
BenchmarkMatchHard_32M 4210112412 4169292003 -0.97%
BenchmarkMatchMedium_32K 2460752 2438611 -0.90%
BenchmarkMatchEasy0_1M 422914 419672 -0.77%
BenchmarkMatchMedium_1M 78581121 78040160 -0.69%
BenchmarkMatchMedium_32M 2515287278 2498464906 -0.67%
BenchmarkMatchMedium_32 1754 1746 -0.46%
BenchmarkMatchMedium_1K 52105 52106 +0.00%
BenchmarkAnchoredLiteralLongNonMatch 185 185 +0.00%
BenchmarkMatchEasy1_32 107 107 +0.00%
BenchmarkOnePassLongNotPrefix 505 505 +0.00%
BenchmarkOnePassLongPrefix 147 147 +0.00%
The godoc binary is ~0.12% smaller after this CL.
Updates #5729.
toolstash -cmp passes for all architectures other than amd64 and amd64p32.
Other architectures can be done in follow-up CLs.
Change-Id: I0e167e259274b722958567fc0af83a17ca002da7
Reviewed-on: https://go-review.googlesource.com/2284
Reviewed-by: Russ Cox <rsc@golang.org>
2015-04-08 09:54:15 -07:00
|
|
|
OPC // compare parity clear (for x86 NaN check)
|
2015-04-01 16:02:34 -04:00
|
|
|
OSQRT // sqrt(float64), on systems that have hw support
|
2015-04-03 12:23:28 -04:00
|
|
|
OGETG // runtime.getg() (read g pointer)
|
2015-03-05 13:57:36 -05:00
|
|
|
|
2015-03-05 10:45:56 -05:00
|
|
|
OEND
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// A NodeList is a linked list of nodes.
|
|
|
|
|
// TODO(rsc): Some uses of NodeList should be made into slices.
|
|
|
|
|
// The remaining ones probably just need a simple linked list,
|
|
|
|
|
// not one with concatenation support.
|
|
|
|
|
type NodeList struct {
|
|
|
|
|
N *Node
|
|
|
|
|
Next *NodeList
|
|
|
|
|
End *NodeList
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// concat returns the concatenation of the lists a and b.
|
|
|
|
|
// The storage taken by both is reused for the result.
|
|
|
|
|
func concat(a *NodeList, b *NodeList) *NodeList {
|
|
|
|
|
if a == nil {
|
|
|
|
|
return b
|
|
|
|
|
}
|
|
|
|
|
if b == nil {
|
|
|
|
|
return a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
a.End.Next = b
|
|
|
|
|
a.End = b.End
|
|
|
|
|
b.End = nil
|
|
|
|
|
return a
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// list1 returns a one-element list containing n.
|
|
|
|
|
func list1(n *Node) *NodeList {
|
|
|
|
|
if n == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if n.Op == OBLOCK && n.Ninit == nil {
|
|
|
|
|
// Flatten list and steal storage.
|
|
|
|
|
// Poison pointer to catch errant uses.
|
|
|
|
|
l := n.List
|
|
|
|
|
|
|
|
|
|
n.List = nil
|
|
|
|
|
return l
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l := new(NodeList)
|
|
|
|
|
l.N = n
|
|
|
|
|
l.End = l
|
|
|
|
|
return l
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// list returns the result of appending n to l.
|
|
|
|
|
func list(l *NodeList, n *Node) *NodeList {
|
|
|
|
|
return concat(l, list1(n))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// listsort sorts *l in place according to the 3-way comparison function f.
|
|
|
|
|
// The algorithm is mergesort, so it is guaranteed to be O(n log n).
|
|
|
|
|
func listsort(l **NodeList, f func(*Node, *Node) int) {
|
|
|
|
|
if *l == nil || (*l).Next == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l1 := *l
|
|
|
|
|
l2 := *l
|
|
|
|
|
for {
|
|
|
|
|
l2 = l2.Next
|
|
|
|
|
if l2 == nil {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
l2 = l2.Next
|
|
|
|
|
if l2 == nil {
|
|
|
|
|
break
|
|
|
|
|
}
|
|
|
|
|
l1 = l1.Next
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l2 = l1.Next
|
|
|
|
|
l1.Next = nil
|
|
|
|
|
l2.End = (*l).End
|
|
|
|
|
(*l).End = l1
|
|
|
|
|
|
|
|
|
|
l1 = *l
|
|
|
|
|
listsort(&l1, f)
|
|
|
|
|
listsort(&l2, f)
|
|
|
|
|
|
|
|
|
|
if f(l1.N, l2.N) < 0 {
|
|
|
|
|
*l = l1
|
|
|
|
|
} else {
|
|
|
|
|
*l = l2
|
|
|
|
|
l2 = l1
|
|
|
|
|
l1 = *l
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// now l1 == *l; and l1 < l2
|
|
|
|
|
|
|
|
|
|
var le *NodeList
|
|
|
|
|
for (l1 != nil) && (l2 != nil) {
|
|
|
|
|
for (l1.Next != nil) && f(l1.Next.N, l2.N) < 0 {
|
|
|
|
|
l1 = l1.Next
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// l1 is last one from l1 that is < l2
|
|
|
|
|
le = l1.Next // le is the rest of l1, first one that is >= l2
|
|
|
|
|
if le != nil {
|
|
|
|
|
le.End = (*l).End
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(*l).End = l1 // cut *l at l1
|
|
|
|
|
*l = concat(*l, l2) // glue l2 to *l's tail
|
|
|
|
|
|
|
|
|
|
l1 = l2 // l1 is the first element of *l that is < the new l2
|
|
|
|
|
l2 = le // ... because l2 now is the old tail of l1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
*l = concat(*l, l2) // any remainder
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// count returns the length of the list l.
|
|
|
|
|
func count(l *NodeList) int {
|
|
|
|
|
n := int64(0)
|
|
|
|
|
for ; l != nil; l = l.Next {
|
|
|
|
|
n++
|
|
|
|
|
}
|
|
|
|
|
if int64(int(n)) != n { // Overflow.
|
|
|
|
|
Yyerror("too many elements in list")
|
|
|
|
|
}
|
|
|
|
|
return int(n)
|
|
|
|
|
}
|