]> git.baikalelectronics.ru Git - kernel.git/commit
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)
commit469c0a3af71525dbd96bb7ab120987d5d7a5b414
tree26ecaba917e5a2af4390ba7ae07feab1a1233586
parent3c9a6ce5f602f5351c03dc856a6c0ab7a67a7d4d
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