• 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
..
Makefile Loading commit data...
acid.c Loading commit data...
bits.c Loading commit data...
cc.h Loading commit data...
cc.y Loading commit data...
com.c Loading commit data...
com64.c Loading commit data...
dcl.c Loading commit data...
doc.go Loading commit data...
dpchk.c Loading commit data...
funct.c Loading commit data...
godefs.c Loading commit data...
lex.c Loading commit data...
lexbody Loading commit data...
mac.c Loading commit data...
macbody Loading commit data...
omachcap.c Loading commit data...
pgen.c Loading commit data...
pswt.c Loading commit data...
scon.c Loading commit data...
sub.c Loading commit data...
y.tab.c Loading commit data...
y.tab.h Loading commit data...