• Matthew Dempsky's avatar
    cmd/6c: Optimize rotate expressions to use rotate instructions. · bb192d13
    Matthew Dempsky authored
    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
    bb192d13
Name
Last commit
Last update
..
5a Loading commit data...
5c Loading commit data...
5g Loading commit data...
5l Loading commit data...
6a Loading commit data...
6c Loading commit data...
6g Loading commit data...
6l Loading commit data...
8a Loading commit data...
8c Loading commit data...
8g Loading commit data...
8l Loading commit data...
addr2line Loading commit data...
api Loading commit data...
cc Loading commit data...
cgo Loading commit data...
cov Loading commit data...
dist Loading commit data...
fix Loading commit data...
gc Loading commit data...
go Loading commit data...
godoc Loading commit data...
gofmt Loading commit data...
ld Loading commit data...
nm Loading commit data...
objdump Loading commit data...
pack Loading commit data...
prof Loading commit data...
vet Loading commit data...
yacc Loading commit data...