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 58196438F1; Thu, 18 Jan 2024 10:35:59 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 45E8F410E6; Thu, 18 Jan 2024 10:35:59 +0100 (CET) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by mails.dpdk.org (Postfix) with ESMTP id 6518B400D7 for ; Thu, 18 Jan 2024 10:35:58 +0100 (CET) Received: from mail.maildlp.com (unknown [172.18.186.31]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4TFyGZ2XpYz6K99P; Thu, 18 Jan 2024 17:33:10 +0800 (CST) Received: from frapeml100008.china.huawei.com (unknown [7.182.85.131]) by mail.maildlp.com (Postfix) with ESMTPS id D5B6A1400CD; Thu, 18 Jan 2024 17:35:57 +0800 (CST) Received: from frapeml500007.china.huawei.com (7.182.85.172) by frapeml100008.china.huawei.com (7.182.85.131) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Thu, 18 Jan 2024 10:35:57 +0100 Received: from frapeml500007.china.huawei.com ([7.182.85.172]) by frapeml500007.china.huawei.com ([7.182.85.172]) with mapi id 15.01.2507.035; Thu, 18 Jan 2024 10:35:57 +0100 From: Konstantin Ananyev To: Stephen Hemminger , "dev@dpdk.org" Subject: RE: [PATCH v4 1/6] eal: introduce RTE_MIN_T() and RTE_MAX_T() macros Thread-Topic: [PATCH v4 1/6] eal: introduce RTE_MIN_T() and RTE_MAX_T() macros Thread-Index: AQHaSXKuPqrg3IUteUqucWIe7p9McrDfUH3w Date: Thu, 18 Jan 2024 09:35:57 +0000 Message-ID: References: <20231111172153.57461-1-stephen@networkplumber.org> <20240117182541.211125-1-stephen@networkplumber.org> <20240117182541.211125-2-stephen@networkplumber.org> In-Reply-To: <20240117182541.211125-2-stephen@networkplumber.org> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.206.138.42] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 > 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. >=20 > Naming is chosen to be similar to Linux kernel conventions. >=20 > Signed-off-by: Stephen Hemminger > --- > lib/eal/include/rte_common.h | 16 ++++++++++++++++ > 1 file changed, 16 insertions(+) >=20 > 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; \ > }) >=20 > +/** > + * 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; \ > }) >=20 > +/** > + * 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 ********/ >=20 > #ifndef offsetof > -- Acked-by: Konstantin Ananyev =20 > 2.43.0