OSDN Git Service

powerpc/bitops: Use immediate operand when possible
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Tue, 21 Sep 2021 15:09:47 +0000 (17:09 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 30 Nov 2021 00:45:50 +0000 (11:45 +1100)
commitfb350784d8d17952afa93383bb47aaa6b715c459
tree7d34b3ef5c68f16b5165f86d94e06cbab76e0c03
parentaebd1fb45c622e9a2b06fb70665d084d3a8d6c78
powerpc/bitops: Use immediate operand when possible

Today we get the following code generation for bitops like
set or clear bit:

c0009fe0: 39 40 08 00  li      r10,2048
c0009fe4: 7c e0 40 28  lwarx   r7,0,r8
c0009fe8: 7c e7 53 78  or      r7,r7,r10
c0009fec: 7c e0 41 2d  stwcx.  r7,0,r8

c000d568: 39 00 18 00  li      r8,6144
c000d56c: 7c c0 38 28  lwarx   r6,0,r7
c000d570: 7c c6 40 78  andc    r6,r6,r8
c000d574: 7c c0 39 2d  stwcx.  r6,0,r7

Most set bits are constant on lower 16 bits, so it can easily
be replaced by the "immediate" version of the operation. Allow
GCC to choose between the normal or immediate form.

For clear bits, on 32 bits 'rlwinm' can be used instead of 'andc' for
when all bits to be cleared are consecutive.

On 64 bits we don't have any equivalent single operation for clearing,
single bits or a few bits, we'd need two 'rldicl' so it is not
worth it, the li/andc sequence is doing the same.

With this patch we get:

c0009fe0: 7d 00 50 28  lwarx   r8,0,r10
c0009fe4: 61 08 08 00  ori     r8,r8,2048
c0009fe8: 7d 00 51 2d  stwcx.  r8,0,r10

c000d558: 7c e0 40 28  lwarx   r7,0,r8
c000d55c: 54 e7 05 64  rlwinm  r7,r7,0,21,18
c000d560: 7c e0 41 2d  stwcx.  r7,0,r8

On pmac32_defconfig, it reduces the text by approx 10 kbytes.

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Reviewed-by: Segher Boessenkool <segher@kernel.crashing.org>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/e6f815d9181bab09df3b350af51149437863e9f9.1632236981.git.christophe.leroy@csgroup.eu
arch/powerpc/include/asm/bitops.h