Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1400540

Re: powerpc: Discard ffs() function and use builtin_ffs instead

From Christophe Leroy <christophe.leroy@c-s.fr>
Newsgroups linux.kernel
Subject Re: powerpc: Discard ffs() function and use builtin_ffs instead
Date 2016-05-13 09:00 +0200
Message-ID <ryfeO-6kr-21@gated-at.bofh.it> (permalink)
References <ryeC5-5YC-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw



Le 13/05/2016 à 08:16, Michael Ellerman a écrit :
> On Thu, 2016-12-05 at 15:32:22 UTC, Christophe Leroy wrote:
>> With the ffs() function as defined in arch/powerpc/include/asm/bitops.h
>> GCC will not optimise the code in case of constant parameter, as shown
>> by the small exemple below.
>>
>> int ffs_test(void)
>> {
>> 	return 4 << ffs(31);
>> }
>>
>> c0012334 <ffs_test>:
>> c0012334:       39 20 00 01     li      r9,1
>> c0012338:       38 60 00 04     li      r3,4
>> c001233c:       7d 29 00 34     cntlzw  r9,r9
>> c0012340:       21 29 00 20     subfic  r9,r9,32
>> c0012344:       7c 63 48 30     slw     r3,r3,r9
>> c0012348:       4e 80 00 20     blr
>>
>> With this patch, the same function will compile as follows:
>>
>> c0012334 <ffs_test>:
>> c0012334:       38 60 00 08     li      r3,8
>> c0012338:       4e 80 00 20     blr
>
> But what code does it generate when it's not a constant?

The generated code is the same with and without the patch when not a 
constant:

int ffs_test2(int x)
{
     return ffs(x);
}

c001233c <ffs_test2>:
c001233c:       7d 23 00 d0     neg     r9,r3
c0012340:       7d 23 18 38     and     r3,r9,r3
c0012344:       7c 63 00 34     cntlzw  r3,r3
c0012348:       20 63 00 20     subfic  r3,r3,32
c001234c:       4e 80 00 20     blr

>
> And which gcc version first added the builtin version?
Don't know, but __builtin_ffs() is already used in 
arch/powerpc/include/asm/page_32.h

Christophe

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH] powerpc: Discard ffs() function and use builtin_ffs instead Christophe Leroy <christophe.leroy@c-s.fr> - 2016-05-12 17:40 +0200
  Re: powerpc: Discard ffs() function and use builtin_ffs instead Michael Ellerman <mpe@ellerman.id.au> - 2016-05-13 08:20 +0200
    Re: powerpc: Discard ffs() function and use builtin_ffs instead Christophe Leroy <christophe.leroy@c-s.fr> - 2016-05-13 09:00 +0200
    Re: powerpc: Discard ffs() function and use builtin_ffs instead Gabriel Paubert <paubert@iram.es> - 2016-05-13 11:10 +0200

csiph-web