1
0
mirror of https://github.com/golang/go synced 2024-11-20 07:54:39 -07:00
go/src/cmd/6c
Matthew Dempsky bb192d1399 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 #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://golang.org/cl/7069056
2013-01-18 17:29:53 -05:00
..
cgen.c cmd/6c: Optimize rotate expressions to use rotate instructions. 2013-01-18 17:29:53 -05:00
div.c various: avoid %ld etc 2010-10-13 16:20:22 -04:00
doc.go cmd/5a, cmd/5c, cmd/6a, cmd/6c, cmd/8a, cmd/8c, cmd/ld: update reference 2013-01-18 13:39:53 -08:00
gc.h cmd/{5g,6g,8g,6c}: remove unused macro, use %E to print etype. 2012-09-24 23:44:00 +02:00
list.c cmd/6c, cmd/8c: add fixjmp step to regopt. 2012-12-06 07:20:03 +01:00
machcap.c move 6c/pgen.c, 6c/pswt.c into cc 2009-07-07 10:07:15 -07:00
Makefile build: delete make paraphernalia 2012-02-06 13:34:25 -05:00
mul.c cmd/6c, cmd/8c: use signed char explicitly in mul.c 2012-11-09 21:06:45 +01:00
peep.c cmd/6c: Improve peep hole optimization of rotate and shift instructions. 2013-01-18 16:33:25 -05:00
reg.c cmd/6c, cmd/8c: add fixjmp step to regopt. 2012-12-06 07:20:03 +01:00
sgen.c amd64: use segment memory for thread-local storage 2010-08-04 17:50:22 -07:00
swt.c cmd/cgo, cmd/cc, cmd/ld: detect dynamic linker automatically 2012-05-05 01:54:16 +08:00
txt.c cmd/6c: Optimize rotate expressions to use rotate instructions. 2013-01-18 17:29:53 -05:00