summaryrefslogtreecommitdiff
path: root/src/cmd/8c/txt.c
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2013-01-18 17:29:53 -0500
committerMatthew Dempsky <mdempsky@google.com>2013-01-18 17:29:53 -0500
commitdf1ad20b3f949ac7154133b10ed2b8c230a2678b (patch)
tree7215dd8ce776e0ec08c5d3273607219c74bd68af /src/cmd/8c/txt.c
parent431793477499ec24686b519cb427c3ff7ba7b4bc (diff)
downloadgo-df1ad20b3f949ac7154133b10ed2b8c230a2678b.tar.gz
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>
Diffstat (limited to 'src/cmd/8c/txt.c')
-rw-r--r--src/cmd/8c/txt.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cmd/8c/txt.c b/src/cmd/8c/txt.c
index d229462da..d7873e385 100644
--- a/src/cmd/8c/txt.c
+++ b/src/cmd/8c/txt.c
@@ -1253,6 +1253,14 @@ gopcode(int o, Type *ty, Node *f, Node *t)
a = ASALW;
break;
+ case OROTL:
+ a = AROLL;
+ if(et == TCHAR || et == TUCHAR)
+ a = AROLB;
+ if(et == TSHORT || et == TUSHORT)
+ a = AROLW;
+ break;
+
case OFUNC:
a = ACALL;
break;