• 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
..
cmd Loading commit data...
lib9 Loading commit data...
libbio Loading commit data...
libmach Loading commit data...
pkg Loading commit data...
Make.dist Loading commit data...
all.bash Loading commit data...
all.bat Loading commit data...
all.rc Loading commit data...
clean.bash Loading commit data...
clean.bat Loading commit data...
clean.rc Loading commit data...
make.bash Loading commit data...
make.bat Loading commit data...
make.rc Loading commit data...
run.bash Loading commit data...
run.bat Loading commit data...
run.rc Loading commit data...
sudo.bash Loading commit data...