Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4335)

Issue 6506089: code review 6506089: cmd/gc: recognize small TPTR64 values as small integer ... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
11 years, 7 months ago by nigeltao
Modified:
11 years, 7 months ago
Reviewers:
CC:
rsc, dave_cheney.net, remyoudompheng, golang-dev
Visibility:
Public.

Description

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

Patch Set 1 #

Patch Set 2 : diff -r 0a0666f2fe86 https://go.googlecode.com/hg/ #

Patch Set 3 : diff -r 0a0666f2fe86 https://go.googlecode.com/hg/ #

Patch Set 4 : diff -r 3796fdf0d0b8 https://go.googlecode.com/hg/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+1 line, -0 lines) Patch
M src/cmd/gc/const.c View 1 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 8
nigeltao
Hello rsc@golang.org (cc: golang-dev@googlegroups.com, remyoudompheng@gmail.com), I'd like you to review this change to https://go.googlecode.com/hg/
11 years, 7 months ago (2012-09-09 01:33:11 UTC) #1
dave_cheney.net
Nice. Could you explain why ret is a TPTR64? With my limited understanding of the ...
11 years, 7 months ago (2012-09-09 01:38:26 UTC) #2
remyoudompheng
ret is not a PTR64. The range loop is tranformed by the frontend in: for ...
11 years, 7 months ago (2012-09-09 05:19:46 UTC) #3
dave_cheney.net
Ahh, thank you. To indulge me further, why does it matter if the size of ...
11 years, 7 months ago (2012-09-09 05:37:49 UTC) #4
remyoudompheng
On 2012/09/09 05:37:49, dfc wrote: > Ahh, thank you. To indulge me further, why does ...
11 years, 7 months ago (2012-09-09 06:22:14 UTC) #5
dave_cheney.net
> It's because (correct me if I'm wrong) although x86-64 is 64 bits, there is ...
11 years, 7 months ago (2012-09-09 06:35:10 UTC) #6
rsc
LGTM
11 years, 7 months ago (2012-09-11 02:19:49 UTC) #7
nigeltao
11 years, 7 months ago (2012-09-11 09:44:44 UTC) #8
*** 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
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b