summaryrefslogtreecommitdiff
path: root/test/codegen/bits.go
diff options
context:
space:
mode:
authorLE Manh Cuong <cuong.manhle.vn@gmail.com>2019-05-08 17:02:23 +0700
committerDaniel Martí <mvdan@mvdan.cc>2019-08-27 18:01:16 +0000
commitc5f142fa9fb6e00b0877ba4b6e9ab77d22ac50cd (patch)
tree3f958cb07e741c3abe5597ef81c15b6f4e2c1491 /test/codegen/bits.go
parentae68a912725e5a3a0482bc5945687663f2ddafe3 (diff)
downloadgo-git-c5f142fa9fb6e00b0877ba4b6e9ab77d22ac50cd.tar.gz
cmd/compile: optimize bitset tests
The assembly output for x & c == c, where c is power of 2: MOVQ "".set+8(SP), AX ANDQ $8, AX CMPQ AX, $8 SETEQ "".~r2+24(SP) With optimization using bitset: MOVQ "".set+8(SP), AX BTL $3, AX SETCS "".~r2+24(SP) output less than 1 instruction. However, there is no speed improvement: name old time/op new time/op delta AllBitSet-8 0.35ns ± 0% 0.35ns ± 0% ~ (all equal) Fixes #31904 Change-Id: I5dca4e410bf45716ed2145e3473979ec997e35d4 Reviewed-on: https://go-review.googlesource.com/c/go/+/175957 Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'test/codegen/bits.go')
-rw-r--r--test/codegen/bits.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/test/codegen/bits.go b/test/codegen/bits.go
index 65d57c8f9f..18f9daf7cf 100644
--- a/test/codegen/bits.go
+++ b/test/codegen/bits.go
@@ -314,3 +314,15 @@ func op_orn(x, y uint32) uint32 {
// arm64:`ORN\t`,-`ORR`
return x | ^y
}
+
+// check bitsets
+func bitSetPowerOf2Test(x int) bool {
+ // amd64:"BTL\t[$]3"
+ return x&8 == 8
+}
+
+func bitSetTest(x int) bool {
+ // amd64:"ANDQ\t[$]9, AX"
+ // amd64:"CMPQ\tAX, [$]9"
+ return x&9 == 9
+}