From 611706b17136beb602711f7bfebd15622f73f58f Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Tue, 1 Aug 2023 14:32:56 -0700 Subject: cmd/compile: don't use BTS when OR works, add direct memory BTS operations Stop using BTSconst and friends when ORLconst can be used instead. OR can be issued by more function units than BTS can, so it could lead to better IPC. OR might take a few more bytes to encode, but not a lot more. Still use BTSconst for cases where the constant otherwise wouldn't fit and would require a separate movabs instruction to materialize the constant. This happens when setting bits 31-63 of 64-bit targets. Add BTS-to-memory operations so we don't need to load/bts/store. Fixes #61694 Change-Id: I00379608df8fb0167cb01466e97d11dec7c1596c Reviewed-on: https://go-review.googlesource.com/c/go/+/515755 Reviewed-by: Keith Randall Run-TryBot: Keith Randall TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- test/codegen/memops.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/codegen/memops.go') diff --git a/test/codegen/memops.go b/test/codegen/memops.go index f6cf9450a1..e5e89c2acc 100644 --- a/test/codegen/memops.go +++ b/test/codegen/memops.go @@ -372,3 +372,32 @@ func storeTest(a []bool, v int, i int) { // amd64: `BTL\t\$1,`,`SETCS\t3\([A-Z]+[0-9]*\)\([A-Z]+[0-9]*\*1\)` a[3+i] = v&2 != 0 } + +func bitOps(p *[12]uint64) { + // amd64: `ORQ\t\$8, \(AX\)` + p[0] |= 8 + // amd64: `ORQ\t\$1073741824, 8\(AX\)` + p[1] |= 1 << 30 + // amd64: `BTSQ\t\$31, 16\(AX\)` + p[2] |= 1 << 31 + // amd64: `BTSQ\t\$63, 24\(AX\)` + p[3] |= 1 << 63 + + // amd64: `ANDQ\t\$-9, 32\(AX\)` + p[4] &^= 8 + // amd64: `ANDQ\t\$-1073741825, 40\(AX\)` + p[5] &^= 1 << 30 + // amd64: `BTRQ\t\$31, 48\(AX\)` + p[6] &^= 1 << 31 + // amd64: `BTRQ\t\$63, 56\(AX\)` + p[7] &^= 1 << 63 + + // amd64: `XORQ\t\$8, 64\(AX\)` + p[8] ^= 8 + // amd64: `XORQ\t\$1073741824, 72\(AX\)` + p[9] ^= 1 << 30 + // amd64: `BTCQ\t\$31, 80\(AX\)` + p[10] ^= 1 << 31 + // amd64: `BTCQ\t\$63, 88\(AX\)` + p[11] ^= 1 << 63 +} -- cgit v1.3