FAQ

Search Discussions

  • Nigeltao at Sep 11, 2012 at 9:44 am
    *** Submitted as
    http://code.google.com/p/go/source/detail?r=46e193d130ce ***

    cmd/gc: recognize small TPTR64 values as small integer constants.

    Given the following Go program:

    func sum(s []int) int {
    ret := 0
    for _, x := range s {
    ret += x
    }
    return ret
    }

    6g would previously generate:

    --- prog list "sum" ---
    0000 (main.go:3) TEXT sum+0(SB),$0-24
    0001 (main.go:5) MOVQ s+0(FP),CX
    0002 (main.go:5) MOVL s+8(FP),DI
    0003 (main.go:5) MOVL s+12(FP),BX
    0004 (main.go:4) MOVL $0,SI
    0005 (main.go:5) MOVL $0,AX
    0006 (main.go:5) JMP ,8
    0007 (main.go:5) INCL ,AX
    0008 (main.go:5) CMPL AX,DI
    0009 (main.go:5) JGE $0,16
    0010 (main.go:5) MOVL (CX),DX
    0011 (main.go:5) MOVQ $4,BX
    0012 (main.go:5) ADDQ CX,BX
    0013 (main.go:5) MOVQ BX,CX
    0014 (main.go:6) ADDL DX,SI
    0015 (main.go:5) JMP ,7
    0016 (main.go:8) MOVL SI,.noname+16(FP)
    0017 (main.go:8) RET ,

    and now generates:

    --- prog list "sum" ---
    0000 (main.go:3) TEXT sum+0(SB),$0-24
    0001 (main.go:5) MOVQ s+0(FP),CX
    0002 (main.go:5) MOVL s+8(FP),DI
    0003 (main.go:5) MOVL s+12(FP),BX
    0004 (main.go:4) MOVL $0,SI
    0005 (main.go:5) MOVL $0,AX
    0006 (main.go:5) JMP ,8
    0007 (main.go:5) INCL ,AX
    0008 (main.go:5) CMPL AX,DI
    0009 (main.go:5) JGE $0,14
    0010 (main.go:5) MOVL (CX),BP
    0011 (main.go:5) ADDQ $4,CX
    0012 (main.go:6) ADDL BP,SI
    0013 (main.go:5) JMP ,7
    0014 (main.go:8) MOVL SI,.noname+16(FP)
    0015 (main.go:8) RET ,

    The key difference is that
    0011 (main.go:5) MOVQ $4,BX
    0012 (main.go:5) ADDQ CX,BX
    0013 (main.go:5) MOVQ BX,CX
    has changed to
    0011 (main.go:5) ADDQ $4,CX

    R=rsc, dave, remyoudompheng
    CC=golang-dev
    http://codereview.appspot.com/6506089


    http://codereview.appspot.com/6506089/

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-dev @
categoriesgo
postedSep 11, '12 at 2:19a
activeSep 11, '12 at 9:44a
posts2
users2
websitegolang.org

2 users in discussion

Nigeltao: 1 post Rsc: 1 post

People

Translate

site design / logo © 2022 Grokbase