From b211fe005860db3ceff5fd56af9951d6d1f44325 Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Fri, 7 May 2021 14:14:39 -0700 Subject: cmd/compile: remove bit operations that modify memory directly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These operations (BT{S,R,C}{Q,L}modify) are quite a bit slower than other ways of doing the same thing. Without the BTxmodify operations, there are two fallback ways the compiler performs these operations: AND/OR/XOR operations directly on memory, or load-BTx-write sequences. The compiler kinda chooses one arbitrarily depending on rewrite rule application order. Currently, it uses load-BTx-write for the Const benchmarks and AND/OR/XOR directly to memory for the non-Const benchmarks. TBD, someone might investigate which of the two fallback strategies is really better. For now, they are both better than BTx ops. name old time/op new time/op delta BitSet-8 1.09µs ± 2% 0.64µs ± 5% -41.60% (p=0.000 n=9+10) BitClear-8 1.15µs ± 3% 0.68µs ± 6% -41.00% (p=0.000 n=10+10) BitToggle-8 1.18µs ± 4% 0.73µs ± 2% -38.36% (p=0.000 n=10+8) BitSetConst-8 37.0ns ± 7% 25.8ns ± 2% -30.24% (p=0.000 n=10+10) BitClearConst-8 30.7ns ± 2% 25.0ns ±12% -18.46% (p=0.000 n=10+10) BitToggleConst-8 36.9ns ± 1% 23.8ns ± 3% -35.46% (p=0.000 n=9+10) Fixes #45790 Update #45242 Change-Id: Ie33a72dc139f261af82db15d446cd0855afb4e59 Reviewed-on: https://go-review.googlesource.com/c/go/+/318149 Trust: Keith Randall Run-TryBot: Keith Randall TryBot-Result: Go Bot Reviewed-by: Ben Shi --- test/codegen/bits.go | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'test/codegen/bits.go') diff --git a/test/codegen/bits.go b/test/codegen/bits.go index 2bd92dd51b..8117a62307 100644 --- a/test/codegen/bits.go +++ b/test/codegen/bits.go @@ -270,18 +270,6 @@ func bitOpOnMem(a []uint32, b, c, d uint32) { a[1] |= 220 // amd64:`XORL\s[$]240,\s8\([A-Z][A-Z0-9]+\)` a[2] ^= 240 - // amd64:`BTRL\s[$]15,\s12\([A-Z][A-Z0-9]+\)`,-`ANDL` - a[3] &= 0xffff7fff - // amd64:`BTSL\s[$]14,\s16\([A-Z][A-Z0-9]+\)`,-`ORL` - a[4] |= 0x4000 - // amd64:`BTCL\s[$]13,\s20\([A-Z][A-Z0-9]+\)`,-`XORL` - a[5] ^= 0x2000 - // amd64:`BTRL\s[A-Z][A-Z0-9]+,\s24\([A-Z][A-Z0-9]+\)` - a[6] &^= 1 << (b & 31) - // amd64:`BTSL\s[A-Z][A-Z0-9]+,\s28\([A-Z][A-Z0-9]+\)` - a[7] |= 1 << (c & 31) - // amd64:`BTCL\s[A-Z][A-Z0-9]+,\s32\([A-Z][A-Z0-9]+\)` - a[8] ^= 1 << (d & 31) } func bitcheckMostNegative(b uint8) bool { -- cgit v1.3