From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751548AbdBATFB (ORCPT ); Wed, 1 Feb 2017 14:05:01 -0500 Received: from smtprelay0195.hostedemail.com ([216.40.44.195]:52954 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751047AbdBATFA (ORCPT ); Wed, 1 Feb 2017 14:05:00 -0500 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1431:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:1801:2198:2199:2393:2553:2559:2562:2828:3138:3139:3140:3141:3142:3354:3622:3865:3868:3870:3871:3872:3874:4321:4605:5007:6120:7901:7904:10004:10400:10848:11026:11232:11658:11914:12043:12295:12438:12555:12740:12760:12895:12986:13439:14181:14659:14721:21080:21451:30054:30060:30090:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:2,LUA_SUMMARY:none X-HE-Tag: lake44_825e8670f8340 X-Filterd-Recvd-Size: 3947 Message-ID: <1485975894.2560.13.camel@perches.com> Subject: Re: Build failure with v4.9-rc1 and GCC trunk -- compiler weirdness From: Joe Perches To: Ard Biesheuvel , Laura Abbott Cc: Will Deacon , Linus Torvalds , Markus Trippelsdorf , "linux-arm-kernel@lists.infradead.org" , Linux Kernel Mailing List , Peter Zijlstra , Ingo Molnar , james.greenhalgh@arm.com, Gregory Clement , Stephen Boyd Date: Wed, 01 Feb 2017 11:04:54 -0800 In-Reply-To: References: <20161017183806.GG5601@arm.com> <20161019153746.GA4411@x4> <20161019155658.GB4411@x4> <20161019162222.GT9193@arm.com> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.22.3-0ubuntu0.1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 2017-02-01 at 18:19 +0000, Ard Biesheuvel wrote: > On 1 February 2017 at 17:36, Ard Biesheuvel wrote: > > I still think order_base_2() is broken, since it may invoke > > roundup_pow_of_two() with an input value that is documented as > > producing undefined output. I would argue that the below is the > > correct fix. > > > > diff --git a/include/linux/log2.h b/include/linux/log2.h > > index fd7ff3d91e6a..46523731bec0 100644 > > --- a/include/linux/log2.h > > +++ b/include/linux/log2.h > > @@ -203,6 +203,18 @@ unsigned long __rounddown_pow_of_two(unsigned long n) > > * ... and so on. > > */ > > > > -#define order_base_2(n) ilog2(roundup_pow_of_two(n)) > > +static inline __attribute__((__const__)) > > +unsigned long __order_base_2(unsigned long n) > > +{ > > + return n ? 1UL << fls_long(n - 1) : 1; > > +} > > + > > +#define order_base_2(n) \ > > +( \ > > + __builtin_constant_p(n) ? ( \ > > + ((n) < 2) ? (n) : \ > > + ilog2((n) - 1) + 1) : \ > > + ilog2(__order_base_2(n)) \ > > + ) > > > > #endif /* _LINUX_LOG2_H */ > > Actually, there is a still a redundant shift/fls() in there, this is > even simpler: > > diff --git a/include/linux/log2.h b/include/linux/log2.h > index fd7ff3d91e6a..4741534bd7af 100644 > --- a/include/linux/log2.h > +++ b/include/linux/log2.h > @@ -203,6 +203,18 @@ unsigned long __rounddown_pow_of_two(unsigned long n) > * ... and so on. > */ > > -#define order_base_2(n) ilog2(roundup_pow_of_two(n)) > +static inline __attribute__((__const__)) commonly __attribute_const__ > +unsigned long __order_base_2(unsigned long n) > +{ > + return n > 1 ? ilog2(n - 1) + 1 : 0; > +} > + > +#define order_base_2(n) \ > +( \ > + __builtin_constant_p(n) ? ( \ > + ((n) < 2) ? (n) : \ > + ilog2((n) - 1) + 1) : \ > + __order_base_2(n) \ > + ) Does this work properly when n is a signed negative value?