From c5f142fa9fb6e00b0877ba4b6e9ab77d22ac50cd Mon Sep 17 00:00:00 2001 From: LE Manh Cuong Date: Wed, 8 May 2019 17:02:23 +0700 Subject: cmd/compile: optimize bitset tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 TryBot-Result: Gobot Gobot Reviewed-by: Keith Randall --- test/codegen/bits.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test/codegen/bits.go') 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 +} -- cgit v1.2.1