1
0
mirror of https://github.com/golang/go synced 2024-11-23 08:10:03 -07:00

cmd/compile: superficial cleanup in alg.go

Passes toolstash -cmp.

Change-Id: I6ec2143a30c1f2c15f8ec74422c954ed6b9b1a0f
Reviewed-on: https://go-review.googlesource.com/20452
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Josh Bleecher Snyder 2016-02-28 14:56:31 -08:00
parent 4db3dde522
commit 903f096992

View File

@ -59,28 +59,16 @@ func algtype1(t *Type, bad **Type) int {
} }
switch t.Etype { switch t.Etype {
// will be defined later.
case TANY, TFORW: case TANY, TFORW:
// will be defined later.
*bad = t *bad = t
return -1 return -1
case TINT8, case TINT8, TUINT8, TINT16, TUINT16,
TUINT8, TINT32, TUINT32, TINT64, TUINT64,
TINT16, TINT, TUINT, TUINTPTR,
TUINT16, TBOOL, TPTR32, TPTR64,
TINT32, TCHAN, TUNSAFEPTR:
TUINT32,
TINT64,
TUINT64,
TINT,
TUINT,
TUINTPTR,
TBOOL,
TPTR32,
TPTR64,
TCHAN,
TUNSAFEPTR:
return AMEM return AMEM
case TFUNC, TMAP: case TFUNC, TMAP:
@ -119,11 +107,14 @@ func algtype1(t *Type, bad **Type) int {
} }
a := algtype1(t.Type, bad) a := algtype1(t.Type, bad)
if a == ANOEQ || a == AMEM { switch a {
if a == ANOEQ && bad != nil { case AMEM:
return AMEM
case ANOEQ:
if bad != nil {
*bad = t *bad = t
} }
return a return ANOEQ
} }
switch t.Bound { switch t.Bound {
@ -155,7 +146,6 @@ func algtype1(t *Type, bad **Type) int {
// equality need special compare. // equality need special compare.
if a != AMEM || isblanksym(f.Sym) || ispaddedfield(t, f) { if a != AMEM || isblanksym(f.Sym) || ispaddedfield(t, f) {
ret = -1 ret = -1
continue
} }
} }
@ -306,32 +296,23 @@ func genhash(sym *Sym, t *Type) {
func hashfor(t *Type) *Node { func hashfor(t *Type) *Node {
var sym *Sym var sym *Sym
a := algtype1(t, nil) switch algtype1(t, nil) {
switch a {
case AMEM: case AMEM:
Fatalf("hashfor with AMEM type") Fatalf("hashfor with AMEM type")
case AINTER: case AINTER:
sym = Pkglookup("interhash", Runtimepkg) sym = Pkglookup("interhash", Runtimepkg)
case ANILINTER: case ANILINTER:
sym = Pkglookup("nilinterhash", Runtimepkg) sym = Pkglookup("nilinterhash", Runtimepkg)
case ASTRING: case ASTRING:
sym = Pkglookup("strhash", Runtimepkg) sym = Pkglookup("strhash", Runtimepkg)
case AFLOAT32: case AFLOAT32:
sym = Pkglookup("f32hash", Runtimepkg) sym = Pkglookup("f32hash", Runtimepkg)
case AFLOAT64: case AFLOAT64:
sym = Pkglookup("f64hash", Runtimepkg) sym = Pkglookup("f64hash", Runtimepkg)
case ACPLX64: case ACPLX64:
sym = Pkglookup("c64hash", Runtimepkg) sym = Pkglookup("c64hash", Runtimepkg)
case ACPLX128: case ACPLX128:
sym = Pkglookup("c128hash", Runtimepkg) sym = Pkglookup("c128hash", Runtimepkg)
default: default:
sym = typesymprefix(".hash", t) sym = typesymprefix(".hash", t)
} }
@ -521,8 +502,6 @@ func eqfield(p *Node, q *Node, field *Node) *Node {
// eqmem returns the node // eqmem returns the node
// memequal(&p.field, &q.field [, size]) // memequal(&p.field, &q.field [, size])
func eqmem(p *Node, q *Node, field *Node, size int64) *Node { func eqmem(p *Node, q *Node, field *Node, size int64) *Node {
var needsize int
nx := Nod(OADDR, Nod(OXDOT, p, field), nil) nx := Nod(OADDR, Nod(OXDOT, p, field), nil)
nx.Etype = 1 // does not escape nx.Etype = 1 // does not escape
ny := Nod(OADDR, Nod(OXDOT, q, field), nil) ny := Nod(OADDR, Nod(OXDOT, q, field), nil)
@ -530,32 +509,29 @@ func eqmem(p *Node, q *Node, field *Node, size int64) *Node {
typecheck(&nx, Erv) typecheck(&nx, Erv)
typecheck(&ny, Erv) typecheck(&ny, Erv)
call := Nod(OCALL, eqmemfunc(size, nx.Type.Type, &needsize), nil) fn, needsize := eqmemfunc(size, nx.Type.Type)
call := Nod(OCALL, fn, nil)
call.List.Append(nx) call.List.Append(nx)
call.List.Append(ny) call.List.Append(ny)
if needsize != 0 { if needsize {
call.List.Append(Nodintconst(size)) call.List.Append(Nodintconst(size))
} }
return call return call
} }
func eqmemfunc(size int64, type_ *Type, needsize *int) *Node { func eqmemfunc(size int64, t *Type) (fn *Node, needsize bool) {
var fn *Node
switch size { switch size {
default: default:
fn = syslook("memequal") fn = syslook("memequal")
*needsize = 1 needsize = true
case 1, 2, 4, 8, 16: case 1, 2, 4, 8, 16:
buf := fmt.Sprintf("memequal%d", int(size)*8) buf := fmt.Sprintf("memequal%d", int(size)*8)
fn = syslook(buf) fn = syslook(buf)
*needsize = 0
} }
substArgTypes(&fn, type_, type_) substArgTypes(&fn, t, t)
return fn return fn, needsize
} }
// memrun finds runs of struct fields for which memory-only algs are appropriate. // memrun finds runs of struct fields for which memory-only algs are appropriate.