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

Issue 7069056: code review 7069056: cmd/6c: Optimize rotate expressions to use rotate instr... (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 6 months ago by mdempsky
Modified:
12 years, 6 months ago
Reviewers:
CC:
rsc, minux1, golang-dev
Visibility:
Public.

Description

cmd/6c: Optimize rotate expressions to use rotate instructions. For simplicity, only recognizes expressions of the exact form "(x << a) | (x >> b)" where x is a variable and a and b are integer constant expressions that add to x's bit width. Fixes issue 4629. $ cat rotate.c unsigned int rotate(unsigned int x) { x = (x << 3) | (x >> (sizeof(x) * 8 - 3)); return x; } ## BEFORE $ go tool 6c -S rotate.c (rotate.c:2) TEXT rotate+0(SB),$0-8 (rotate.c:2) MOVL x+0(FP),!!DX (rotate.c:4) MOVL DX,!!AX (rotate.c:4) SALL $3,!!AX (rotate.c:4) MOVL DX,!!CX (rotate.c:4) SHRL $29,!!CX (rotate.c:4) ORL CX,!!AX (rotate.c:5) RET ,!! (rotate.c:5) RET ,!! (rotate.c:5) END ,!! ## AFTER $ go tool 6c -S rotate.c (rotate.c:2) TEXT rotate+0(SB),$0-8 (rotate.c:4) MOVL x+0(FP),!!AX (rotate.c:4) ROLL $3,!!AX (rotate.c:5) RET ,!! (rotate.c:5) RET ,!! (rotate.c:5) END ,!!

Patch Set 1 #

Patch Set 2 : diff -r 8906cf341c9b https://code.google.com/p/go #

Patch Set 3 : diff -r 8906cf341c9b https://code.google.com/p/go #

Patch Set 4 : diff -r afa30db15b70 https://code.google.com/p/go #

Patch Set 5 : diff -r afa30db15b70 https://code.google.com/p/go #

Patch Set 6 : diff -r fe640aeda5f2 https://code.google.com/p/go #

Patch Set 7 : diff -r fe640aeda5f2 https://code.google.com/p/go #

Patch Set 8 : diff -r fe640aeda5f2 https://code.google.com/p/go #

Patch Set 9 : diff -r fc9545bf5a1f https://code.google.com/p/go #

Patch Set 10 : diff -r 8d1bf4554310 https://code.google.com/p/go #

Total comments: 1
Unified diffs Side-by-side diffs Delta from patch set Stats (+44 lines, -0 lines) Patch
M src/cmd/6c/cgen.c View 1 2 3 4 1 chunk +12 lines, -0 lines 1 comment Download
M src/cmd/6c/txt.c View 1 1 chunk +10 lines, -0 lines 0 comments Download
M src/cmd/8c/cgen.c View 1 2 3 4 5 6 7 8 9 1 chunk +12 lines, -0 lines 0 comments Download
M src/cmd/8c/txt.c View 1 2 3 4 5 6 7 8 9 1 chunk +8 lines, -0 lines 0 comments Download
M src/cmd/cc/cc.h View 1 1 chunk +1 line, -0 lines 0 comments Download
M src/cmd/cc/sub.c View 1 2 3 4 5 6 7 1 chunk +1 line, -0 lines 0 comments Download

Messages

Total messages: 7
mdempsky
Hello rsc@golang.org (cc: golang-dev@googlegroups.com), I'd like you to review this change to https://code.google.com/p/go
12 years, 6 months ago (2013-01-10 01:58:47 UTC) #1
rsc
Please add 8c too. It should be mostly copy and paste.
12 years, 6 months ago (2013-01-18 21:46:49 UTC) #2
mdempsky
On 2013/01/18 21:46:49, rsc wrote: > Please add 8c too. It should be mostly copy ...
12 years, 6 months ago (2013-01-18 22:18:00 UTC) #3
minux1
I guess I will need to port these changes to cmd/5c. https://codereview.appspot.com/7069056/diff/18001/src/cmd/6c/cgen.c File src/cmd/6c/cgen.c (right): ...
12 years, 6 months ago (2013-01-18 22:27:38 UTC) #4
rsc
On Fri, Jan 18, 2013 at 5:27 PM, <minux.ma@gmail.com> wrote: > I guess I will ...
12 years, 6 months ago (2013-01-18 22:28:19 UTC) #5
rsc
FWIW, I am not too worried about XOR, nor am I worried about >> | ...
12 years, 6 months ago (2013-01-18 22:29:11 UTC) #6
rsc
12 years, 6 months ago (2013-01-18 22:29:58 UTC) #7
*** Submitted as https://code.google.com/p/go/source/detail?r=3a0b341a95de ***

cmd/6c: Optimize rotate expressions to use rotate instructions.

For simplicity, only recognizes expressions of the exact form
"(x << a) | (x >> b)" where x is a variable and a and b are
integer constant expressions that add to x's bit width.

Fixes issue 4629.

$ cat rotate.c
unsigned int
rotate(unsigned int x)
{
        x = (x << 3) | (x >> (sizeof(x) * 8 - 3));
        return x;
}

## BEFORE
$ go tool 6c -S rotate.c
(rotate.c:2)	TEXT	rotate+0(SB),$0-8
(rotate.c:2)	MOVL	x+0(FP),!!DX
(rotate.c:4)	MOVL	DX,!!AX
(rotate.c:4)	SALL	$3,!!AX
(rotate.c:4)	MOVL	DX,!!CX
(rotate.c:4)	SHRL	$29,!!CX
(rotate.c:4)	ORL	CX,!!AX
(rotate.c:5)	RET	,!!
(rotate.c:5)	RET	,!!
(rotate.c:5)	END	,!!

## AFTER
$ go tool 6c -S rotate.c
(rotate.c:2)	TEXT	rotate+0(SB),$0-8
(rotate.c:4)	MOVL	x+0(FP),!!AX
(rotate.c:4)	ROLL	$3,!!AX
(rotate.c:5)	RET	,!!
(rotate.c:5)	RET	,!!
(rotate.c:5)	END	,!!

R=rsc, minux.ma
CC=golang-dev
https://codereview.appspot.com/7069056

Committer: Russ Cox <rsc@golang.org>
Sign in to reply to this message.

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