powerpc/atomics: Use immediate operand when possible
authorChristophe Leroy <christophe.leroy@csgroup.eu>
Tue, 21 Sep 2021 15:09:48 +0000 (17:09 +0200)
committerMichael Ellerman <mpe@ellerman.id.au>
Tue, 30 Nov 2021 00:45:57 +0000 (11:45 +1100)
commit41d65207de9fbff58acd8937a7c3f8940c186a87
tree26ecaba917e5a2af4390ba7ae07feab1a1233586
parentfb350784d8d17952afa93383bb47aaa6b715c459
powerpc/atomics: Use immediate operand when possible

Today we get the following code generation for atomic operations:

c001bb2c: 39 20 00 01  li      r9,1
c001bb30: 7d 40 18 28  lwarx   r10,0,r3
c001bb34: 7d 09 50 50  subf    r8,r9,r10
c001bb38: 7d 00 19 2d  stwcx.  r8,0,r3

c001c7a8: 39 40 00 01  li      r10,1
c001c7ac: 7d 00 18 28  lwarx   r8,0,r3
c001c7b0: 7c ea 42 14  add     r7,r10,r8
c001c7b4: 7c e0 19 2d  stwcx.  r7,0,r3

By allowing GCC to choose between immediate or regular operation,
we get:

c001bb2c: 7d 20 18 28  lwarx   r9,0,r3
c001bb30: 39 49 ff ff  addi    r10,r9,-1
c001bb34: 7d 40 19 2d  stwcx.  r10,0,r3
--
c001c7a4: 7d 40 18 28  lwarx   r10,0,r3
c001c7a8: 39 0a 00 01  addi    r8,r10,1
c001c7ac: 7d 00 19 2d  stwcx.  r8,0,r3

For "and", the dot form has to be used because "andi" doesn't exist.

For logical operations we use unsigned 16 bits immediate.
For arithmetic operations we use signed 16 bits immediate.

On pmac32_defconfig, it reduces the text by approx another 8 kbytes.

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