From 5cdb132228b90732d57215893a9910ded694c585 Mon Sep 17 00:00:00 2001 From: "Paul E. Murphy" Date: Tue, 27 Jun 2023 17:17:33 -0500 Subject: cmd/compile/internal/ssa: improve masking codegen on PPC64 Generate RLDIC[LR] instead of MOVD mask, Rx; AND Rx, Ry, Rz. This helps reduce code size, and reduces the latency caused by the constant load. Similarly, for smaller-than-register values, truncate constants which exceed the range of the value's type to avoid needing to load a constant. Change-Id: I6019684795eb8962d4fd6d9585d08b17c15e7d64 Reviewed-on: https://go-review.googlesource.com/c/go/+/515576 Reviewed-by: Lynn Boger Reviewed-by: Dmitri Shuralyov Run-TryBot: Paul Murphy TryBot-Result: Gopher Robot Reviewed-by: Cherry Mui --- test/codegen/bits.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'test/codegen/bits.go') diff --git a/test/codegen/bits.go b/test/codegen/bits.go index 88d5ebe9cf..67daf12d62 100644 --- a/test/codegen/bits.go +++ b/test/codegen/bits.go @@ -394,3 +394,29 @@ func zeroextendAndMask8to64(a int8, b int16) (x, y uint64) { return } + +// Verify rotate and mask instructions, and further simplified instructions for small types +func bitRotateAndMask(io64 [4]uint64, io32 [4]uint32, io16 [4]uint16, io8 [4]uint8) { + // ppc64x: "RLDICR\t[$]0, R[0-9]*, [$]47, R" + io64[0] = io64[0] & 0xFFFFFFFFFFFF0000 + // ppc64x: "RLDICL\t[$]0, R[0-9]*, [$]16, R" + io64[1] = io64[1] & 0x0000FFFFFFFFFFFF + // ppc64x: -"SRD", -"AND", "RLDICL\t[$]60, R[0-9]*, [$]16, R" + io64[2] = (io64[2] >> 4) & 0x0000FFFFFFFFFFFF + // ppc64x: -"SRD", -"AND", "RLDICL\t[$]36, R[0-9]*, [$]28, R" + io64[3] = (io64[3] >> 28) & 0x0000FFFFFFFFFFFF + + // ppc64x: "RLWNM\t[$]0, R[0-9]*, [$]4, [$]19, R" + io32[0] = io32[0] & 0x0FFFF000 + // ppc64x: "RLWNM\t[$]0, R[0-9]*, [$]20, [$]3, R" + io32[1] = io32[1] & 0xF0000FFF + // ppc64x: -"RLWNM", MOVD, AND + io32[2] = io32[2] & 0xFFFF0002 + + var bigc uint32 = 0x12345678 + // ppc64x: "ANDCC\t[$]22136" + io16[0] = io16[0] & uint16(bigc) + + // ppc64x: "ANDCC\t[$]120" + io8[0] = io8[0] & uint8(bigc) +} -- cgit v1.3