From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3A28743902; Fri, 19 Jan 2024 21:58:51 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id B59AE42B71; Fri, 19 Jan 2024 21:58:50 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id B03254029F for ; Fri, 19 Jan 2024 21:58:48 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1086) id C485F20DFD6B; Fri, 19 Jan 2024 12:58:47 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C485F20DFD6B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1705697927; bh=uIOU4KVLW98f2+pYQ9c2+DJ4jGM090FQJwygssxkRqY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=T2xxuAwcQ8XwSh2g7Aj9Ywueaj78BS/WxhMRifPfeRbzSzDp67qo9RFE3EERgHZB1 xyVNfq4hc20niXEaL8iin2TnG2WPzy88vDWVpG+BwuPJmkkZ9vNURne0Y1QLW6YFam NTkP3WkeVQ/uNQLWDzME/LUjSYcss53iBX9IOEAQ= Date: Fri, 19 Jan 2024 12:58:47 -0800 From: Tyler Retzlaff To: Stephen Hemminger Cc: dev@dpdk.org Subject: Re: [PATCH v4 1/6] eal: introduce RTE_MIN_T() and RTE_MAX_T() macros Message-ID: <20240119205847.GA24862@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <20231111172153.57461-1-stephen@networkplumber.org> <20240117182541.211125-1-stephen@networkplumber.org> <20240117182541.211125-2-stephen@networkplumber.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240117182541.211125-2-stephen@networkplumber.org> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On Wed, Jan 17, 2024 at 10:19:55AM -0800, Stephen Hemminger wrote: > These macros work like RTE_MIN and RTE_MAX but take an explicit > type. Necessary when being used in static assertions since > RTE_MIN and RTE_MAX use temporary variables which confuses > compilers constant expression checks. These macros could also > be useful in other scenarios when bounded range is useful. > > Naming is chosen to be similar to Linux kernel conventions. parameter ordering seems weird, also Linux kernel copied? just curious more than anything. if not i would put 't' as the first parameter. Acked-by: Tyler Retzlaff > > Signed-off-by: Stephen Hemminger > --- > lib/eal/include/rte_common.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) > > diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h > index c1ba32d00e47..33680e818bfb 100644 > --- a/lib/eal/include/rte_common.h > +++ b/lib/eal/include/rte_common.h > @@ -585,6 +585,14 @@ __extension__ typedef uint64_t RTE_MARKER64[0]; > _a < _b ? _a : _b; \ > }) > > +/** > + * Macro to return the minimum of two numbers > + * does not use temporarys so not safe if a or b is expression > + * but is guaranteed to be constant for use in static_assert() > + */ > +#define RTE_MIN_T(a, b, t) \ > + ((t)(a) < (t)(b) ? (t)(a) : (t)(b)) > + > /** > * Macro to return the maximum of two numbers > */ > @@ -595,6 +603,14 @@ __extension__ typedef uint64_t RTE_MARKER64[0]; > _a > _b ? _a : _b; \ > }) > > +/** > + * Macro to return the maxiimum of two numbers > + * does not use temporarys so not safe if a or b is expression > + * but is guaranteed to be constant for use in static_assert() > + */ > +#define RTE_MAX_T(a, b, t) \ > + ((t)(a) > (t)(b) ? (t)(a) : (t)(b)) > + > /*********** Other general functions / macros ********/ > > #ifndef offsetof > -- > 2.43.0