From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752390AbbCXLtR (ORCPT ); Tue, 24 Mar 2015 07:49:17 -0400 Received: from service87.mimecast.com ([91.220.42.44]:50835 "EHLO service87.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752184AbbCXLtQ convert rfc822-to-8bit (ORCPT ); Tue, 24 Mar 2015 07:49:16 -0400 Date: Tue, 24 Mar 2015 11:49:12 +0000 From: Javi Merino To: Jeff Epler Cc: "akpm@linux-foundation.org" , "intel-gfx@lists.freedesktop.org" , "dri-devel@lists.freedesktop.org" , "linux-kernel@vger.kernel.org" , Daniel Vetter , Jani Nikula , David Airlie , "Darrick J. Wong" , Guenter Roeck , Alex Elder Subject: Re: [PATCH 1/4] kernel.h: Implement DIV_ROUND_CLOSEST_ULL Message-ID: <20150324114912.GA3982@e104805> References: <1426850083-11049-1-git-send-email-javi.merino@arm.com> <1426850083-11049-2-git-send-email-javi.merino@arm.com> <20150323123404.GC17049@unpythonic.net> <20150323170416.GA6161@e104805> MIME-Version: 1.0 In-Reply-To: <20150323170416.GA6161@e104805> User-Agent: Mutt/1.5.21 (2010-09-15) X-OriginalArrivalTime: 24 Mar 2015 11:49:11.0862 (UTC) FILETIME=[8B7BDD60:01D06628] X-MC-Unique: 115032411491400501 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 23, 2015 at 05:04:16PM +0000, Javi Merino wrote: > On Mon, Mar 23, 2015 at 12:34:04PM +0000, Jeff Epler wrote: > > On Fri, Mar 20, 2015 at 11:14:40AM +0000, Javi Merino wrote: > > > +/* > > > + * Same as above but for u64 dividends. divisor must be a 32-bit > > > + * number. > > > + */ > > > +#define DIV_ROUND_CLOSEST_ULL(x, divisor)( \ > > > +{ \ > > > + unsigned long long _tmp = (x) + (divisor) / 2; \ > > > + do_div(_tmp, divisor); \ > > > + _tmp; \ > > > +} \ > > > +) > > > > The macro evaluates 'divisor' twice. > > Good catch. That needs to be fixed. I could do the typeof trick that > DIV_ROUND_CLOSEST() does but it's probably better to just create a > static function as Alex Elder suggests. I'll send a v2 tomorrow with > a static function instead. Nah, thinking about it and seeing the other macros in this file (esp. DIV_ROUND_UP() and DIV_ROUND_UP_ULL()) I don't think a static function gives you anything. I'll just modify the macro to look similar to DIV_ROUND_CLOSEST() Cheers, Javi