From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751419AbcEMI76 (ORCPT ); Fri, 13 May 2016 04:59:58 -0400 Received: from navarro.puc.rediris.es ([130.206.18.139]:58446 "EHLO navarro.puc.rediris.es" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750889AbcEMI7z (ORCPT ); Fri, 13 May 2016 04:59:55 -0400 X-Greylist: delayed 1782 seconds by postgrey-1.27 at vger.kernel.org; Fri, 13 May 2016 04:59:55 EDT X-Envelope-From: paubert@iram.es Date: Fri, 13 May 2016 10:29:35 +0200 From: Gabriel Paubert To: Michael Ellerman Cc: Christophe Leroy , Benjamin Herrenschmidt , Paul Mackerras , Scott Wood , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: powerpc: Discard ffs() function and use builtin_ffs instead Message-ID: <20160513082935.GC23474@visitor2.iram.es> References: <20160512153222.6109E1A239A@localhost.localdomain> <3r5flF6kL6z9t5R@ozlabs.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3r5flF6kL6z9t5R@ozlabs.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-Spamina-Bogosity: Unsure X-Spamina-Spam-Score: -1.0 (-) X-Spamina-Spam-Report: Content analysis details: (-1.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -1.0 ALL_TRUSTED Passed through trusted hosts only via SMTP -0.0 BAYES_40 BODY: Bayes spam probability is 20 to 40% [score: 0.2915] Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 13, 2016 at 04:16:57PM +1000, Michael Ellerman wrote: > 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 : > > 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 : > > 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? > > And which gcc version first added the builtin version? It already existed in gcc-2.95, which you do not want to use to compile anything today but I have in a corner of a chroot environment to maintain ~1997 vintage embedded stuff, running a 2.2.12 kernel! Hopefully this clears up your concerns :-) Cheers, Gabriel