From 50b11318febd74c26cc466cc4557347bcb53181a Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Mon, 20 Apr 2020 14:43:30 -0700 Subject: cmd/compile: use oneBit instead of isPowerOfTwo in bit optimization This optimization works on any integer with exactly one bit set. This is identical to being a power of two, except in the most negative number. Use oneBit instead. The rule now triggers in a few more places in std+cmd, in packages encoding/asn1, crypto/elliptic, and vendor/golang.org/x/crypto/cryptobyte. This change obviates the need for CL 222479 by doing this optimization consistently in the compiler. Change-Id: I983c6235290fdc634fda5e11b10f1f8ce041272f Reviewed-on: https://go-review.googlesource.com/c/go/+/229124 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- test/codegen/bits.go | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/codegen/bits.go') diff --git a/test/codegen/bits.go b/test/codegen/bits.go index 18f9daf7cf..0a5428b55a 100644 --- a/test/codegen/bits.go +++ b/test/codegen/bits.go @@ -278,6 +278,11 @@ func bitOpOnMem(a []uint32) { a[5] ^= 0x2000 } +func bitcheckMostNegative(b uint8) bool { + // amd64:"TESTB" + return b&0x80 == 0x80 +} + // Check AND masking on arm64 (Issue #19857) func and_mask_1(a uint64) uint64 { -- cgit v1.3