From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nikolay Borisov Subject: Re: [RFC][PATCH] kernel.h: Add generic roundup_64() macro Date: Fri, 24 May 2019 19:30:45 +0300 Message-ID: References: <20190523100013.52a8d2a6@gandalf.local.home> <20190523112740.7167aba4@gandalf.local.home> <20190524112656.5ef67c6c@gandalf.local.home> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: In-Reply-To: <20190524112656.5ef67c6c@gandalf.local.home> Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org To: Steven Rostedt , Roger Willcocks Cc: Linus Torvalds , LKML , Ben Skeggs , David Airlie , Daniel Vetter , Leon Romanovsky , Doug Ledford , Jason Gunthorpe , "Darrick J. Wong" , linux-xfs@vger.kernel.org, dri-devel , nouveau@lists.freedesktop.org, linux-rdma , Andrew Morton List-Id: linux-rdma@vger.kernel.org On 24.05.19 г. 18:26 ч., Steven Rostedt wrote: > On Fri, 24 May 2019 16:11:14 +0100 > Roger Willcocks wrote: > >> On 23/05/2019 16:27, Steven Rostedt wrote: >>> >>> I haven't yet tested this, but what about something like the following: >>> >>> ...perhaps forget about the constant check, and just force >>> the power of two check: >>> >>> \ >>> if (!(__y & (__y >> 1))) { \ >>> __x = round_up(x, y); \ >>> } else { \ >> >> You probably want >> >>            if (!(__y & (__y - 1)) >> >> -- > > Yes I do. I corrected it in my next email. > > http://lkml.kernel.org/r/20190523133648.591f9e78@gandalf.local.home Or perhaps just using is_power_of_2 from include/linux/log2.h ? > >> #define roundup(x, y) ( \ >> { \ >> typeof(y) __y = y; \ >> typeof(x) __x; \ >> \ >> if (__y & (__y - 1)) \ >> __x = round_up(x, __y); \ >> else \ >> __x = (((x) + (__y - 1)) / __y) * __y; \ >> __x; \ >> }) > > > -- Steve >