From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755132AbbCSQD2 (ORCPT ); Thu, 19 Mar 2015 12:03:28 -0400 Received: from smtprelay0172.hostedemail.com ([216.40.44.172]:40149 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1755060AbbCSQD0 (ORCPT ); Thu, 19 Mar 2015 12:03:26 -0400 X-Session-Marker: 726F737465647440676F6F646D69732E6F7267 X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,rostedt@goodmis.org,:::::::::,RULES_HIT:41:355:379:541:599:800:960:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2553:2559:2562:2731:2890:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:3872:3874:4042:4321:5007:6261:7875:7903:9108:10004:10400:10848:10967:11026:11232:11473:11658:11914:12043:12291:12438:12517:12519:12555:12683:12740:13069:13161:13229:13311:13357:21080,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 X-HE-Tag: wind04_a4b85e9231d X-Filterd-Recvd-Size: 2654 Date: Thu, 19 Mar 2015 12:03:23 -0400 From: Steven Rostedt To: Bartosz Golaszewski Cc: LKML , Guenter Roeck , lm-sensors , Andrew Morton Subject: Re: [PATCH v3 1/4] util_macros.h: add find_closest() macro Message-ID: <20150319120323.375ff43c@gandalf.local.home> In-Reply-To: <1426775420-31350-2-git-send-email-bgolaszewski@baylibre.com> References: <1426775420-31350-1-git-send-email-bgolaszewski@baylibre.com> <1426775420-31350-2-git-send-email-bgolaszewski@baylibre.com> X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org BTW, it's best to email this account and not my Red Hat one. On Thu, 19 Mar 2015 11:53:06 -0400 Bartosz Golaszewski wrote: > Searching for the member of an array closest to 'x' is > duplicated in several places. > > Add a new include - util_macros.h - and two macros that > implement this algorithm for arrays sorted both in ascending > and descending order. > > Signed-off-by: Bartosz Golaszewski > --- > include/linux/util_macros.h | 39 +++++++++++++++++++++++++++++++++++++++ > 1 file changed, 39 insertions(+) > create mode 100644 include/linux/util_macros.h > > diff --git a/include/linux/util_macros.h b/include/linux/util_macros.h > new file mode 100644 > index 0000000..f2097ce > --- /dev/null > +++ b/include/linux/util_macros.h > @@ -0,0 +1,39 @@ > +#ifndef _LINUX_HELPER_MACROS_H_ > +#define _LINUX_HELPER_MACROS_H_ > + > +#define __find_closest(x, a, as, op)( \ > +{ \ > + typeof(as) _i, _as = (as) - 1; \ > + typeof(x) _x = (x); \ > + typeof(*a) *_a = (a); \ The above variables are not very unique. I've been thinking about all the variables that are defined in macros, and we may want to establish some kind of naming convention to keep from having name space collisions. Maybe something like... typeof(as) __fc_i_, __fc_a_ = (as) -1; typeof(__fc_x_) = (x); typeof(*a) *__fc_a_ = (a); -- Steve > + for (_i = 0; _i < _as; _i++) { \ > + if (_x op DIV_ROUND_CLOSEST(_a[_i] + _a[_i + 1], 2)) \ > + break; \ > + } \ > + (_i); \ > +})