From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FAKE_REPLY_C,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 69BE8C2D0C1 for ; Thu, 5 Dec 2019 22:30:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3C6E42464E for ; Thu, 5 Dec 2019 22:30:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575585054; bh=rwc2W/J/V58JZoKOWg2doRruK6KWPbQgM5Sb2F/Ai60=; h=Date:From:To:Cc:Subject:In-Reply-To:List-ID:From; b=ErfjxFZLPZDhYvM17yImvQ770tEUIilTK5bhU6iZNFPnsAdfqziqKMbDT32+ZwJbv seet2UFJeO8fkYw0d6+CWVGGd1Ik/i4LiZj27mw9L3Pe9KNWN8qbuneH+RKqU1D2Cu fuYiv+Ta2iqrTI8W3X9CPHgvOqv+hQd6Puy2hgqc= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727907AbfLEWas (ORCPT ); Thu, 5 Dec 2019 17:30:48 -0500 Received: from mail.kernel.org ([198.145.29.99]:43900 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727595AbfLEWas (ORCPT ); Thu, 5 Dec 2019 17:30:48 -0500 Received: from localhost (mobile-166-170-221-197.mycingular.net [166.170.221.197]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 84F6520707; Thu, 5 Dec 2019 22:30:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575585047; bh=rwc2W/J/V58JZoKOWg2doRruK6KWPbQgM5Sb2F/Ai60=; h=Date:From:To:Cc:Subject:In-Reply-To:From; b=cliOZcUxDWzGZ1UQTKJkPsD++s/EPrjyE7H/snJuA3uqE7NURH520sOnVje6nd0Ts Td38CmfeZyMBlRyr+Rypsepv/EG8hoAOa7B7sJiJzOVgMDkiBquX3yxdZnHzKOkS/c BBv+wew7DxEj2QDNBsIebdp/nYnu0CS5l8OPwMaM= Date: Thu, 5 Dec 2019 16:30:44 -0600 From: Bjorn Helgaas To: Nicolas Saenz Julienne Cc: andrew.murray@arm.com, maz@kernel.org, linux-kernel@vger.kernel.org, Michael Turquette , Stephen Boyd , Emilio =?iso-8859-1?Q?L=F3pez?= , Maxime Ripard , Chen-Yu Tsai , Mike Marciniszyn , Dennis Dalessandro , Yishai Hadas , Moni Shoua , David Woodhouse , Lu Baolu , Joerg Roedel , Tom Lendacky , Mirko Lindner , Stephen Hemminger , Jiri Pirko , Solarflare linux maintainers , Edward Cree , Martin Habets , Eric Biederman , Thomas Graf , Herbert Xu , james.quinlan@broadcom.com, mbrugger@suse.com, f.fainelli@gmail.com, phil@raspberrypi.org, wahrenst@gmx.net, jeremy.linton@arm.com, linux-pci@vger.kernel.org, linux-rpi-kernel@lists.infradead.org, Robin Murphy , Doug Ledford , Jason Gunthorpe , "David S. Miller" , Trond Myklebust , Anna Schumaker , "J. Bruce Fields" , Chuck Lever , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-rdma@vger.kernel.org, iommu@lists.linux-foundation.org, netdev@vger.kernel.org, kexec@lists.infradead.org, linux-nfs@vger.kernel.org Subject: Re: [PATCH v4 7/8] linux/log2.h: Fix 64bit calculations in roundup/down_pow_two() Message-ID: <20191205223044.GA250573@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191203114743.1294-8-nsaenzjulienne@suse.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org You got the "n" on "down" in the subject, but still missing "of" ;) On Tue, Dec 03, 2019 at 12:47:40PM +0100, Nicolas Saenz Julienne wrote: > Some users need to make sure their rounding function accepts and returns > 64bit long variables regardless of the architecture. Sadly > roundup/rounddown_pow_two() takes and returns unsigned longs. It turns > out ilog2() already handles 32/64bit calculations properly, and being > the building block to the round functions we can rework them as a > wrapper around it. Missing "of" in the function names here. s/a wrapper/wrappers/ IIUC the point of this is that roundup_pow_of_two() returned "unsigned long", which can be either 32 or 64 bits (worth pointing out, I think), and many callers need something that returns "unsigned long long" (always 64 bits). It's a nice simplification to remove the "__" variants. Just as a casual reader of this commit message, I'd like to know why we had both the roundup and the __roundup versions in the first place, and why we no longer need both. > -#define roundup_pow_of_two(n) \ > -( \ > - __builtin_constant_p(n) ? ( \ > - (n == 1) ? 1 : \ > - (1UL << (ilog2((n) - 1) + 1)) \ > - ) : \ > - __roundup_pow_of_two(n) \ > - ) > +#define roundup_pow_of_two(n) \ > +( \ > + (__builtin_constant_p(n) && ((n) == 1)) ? \ > + 1 : (1ULL << (ilog2((n) - 1) + 1)) \ > +) Should the resulting type of this expression always be a ULL, even when n==1, i.e., should it be this? 1ULL : (1ULL << (ilog2((n) - 1) + 1)) \ Or maybe there's no case where that makes a difference? Bjorn