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 96254A0A0C; Wed, 28 Jul 2021 17:22:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 53B2040E64; Wed, 28 Jul 2021 17:22:27 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0b-0016f401.pphosted.com [67.231.156.173]) by mails.dpdk.org (Postfix) with ESMTP id 3C14A40142 for ; Wed, 28 Jul 2021 17:22:26 +0200 (CEST) Received: from pps.filterd (m0045851.ppops.net [127.0.0.1]) by mx0b-0016f401.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 16SFAIPk009957; Wed, 28 Jul 2021 08:22:25 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=ehesLgXU0+jlpp0xE706XFRN+mPPfZMnLB8RoF8K99k=; b=ff5x/gjpGCAFp+Xd0/CShQFAXF2SUK5fNZPxwKNhxlzrImlZz2AdPcuawumAhVpeTeTU LkW/3E3bgX737k+uJQCtSArzIhKvxCHfBX8KlLoTz+ayX+nkvlC57h6qn+yrPB1IImvH yFGv3OQMhkz45FkJ6/IJixy3g5EjKUAmG6shzl72jYiaBL73qGgAbyvK+I3X3l+8kHJT bEZbfKZAhN7A3Rzz0MptvyxKv+J+q4fh9SiRYDgiJFpOrmn9bNYHA2A1RSEP+oblUnZI Ie+nDyfbL7QH7WRZHGyeqLqaVuG3BykgWv+bvPYqz2YQ4juRl/DrsyRBUC2x/CAkwCdx eQ== Received: from dc5-exch02.marvell.com ([199.233.59.182]) by mx0b-0016f401.pphosted.com with ESMTP id 3a35pr0xef-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 28 Jul 2021 08:22:25 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Wed, 28 Jul 2021 08:22:23 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Wed, 28 Jul 2021 08:22:23 -0700 Received: from localhost.localdomain (unknown [10.28.34.29]) by maili.marvell.com (Postfix) with ESMTP id ADE035E687D; Wed, 28 Jul 2021 08:22:21 -0700 (PDT) From: Shijith Thotton To: CC: Shijith Thotton , , , Date: Wed, 28 Jul 2021 20:51:42 +0530 Message-ID: <921c4cfaa08605cac9dd1f63b52139c0860cd622.1627485542.git.sthotton@marvell.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: rtJtyuDlKMmI-8lsgcbiE3WJ_XLDbPtg X-Proofpoint-GUID: rtJtyuDlKMmI-8lsgcbiE3WJ_XLDbPtg X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391, 18.0.790 definitions=2021-07-28_08:2021-07-27, 2021-07-28 signatures=0 Subject: [dpdk-dev] [PATCH] eal: add macro to swap two numbers 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 Sender: "dev" Added a macro to swap two numbers and updated common autotest for the same. Signed-off-by: Shijith Thotton --- Needed-for: drivers: add external clock support for cnxk timer app/test/test_common.c | 4 ++++ lib/eal/include/rte_common.h | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/app/test/test_common.c b/app/test/test_common.c index 12bd1cad90..ef177cecb1 100644 --- a/app/test/test_common.c +++ b/app/test/test_common.c @@ -30,9 +30,13 @@ test_macros(int __rte_unused unused_parm) return -1;} uintptr_t unused = 0; + unsigned int smaller = SMALLER, bigger = BIGGER; RTE_SET_USED(unused); + RTE_SWAP(smaller, bigger); + if (smaller != BIGGER && bigger != SMALLER) + FAIL_MACRO(RTE_SWAP); if ((uintptr_t)RTE_PTR_ADD(SMALLER, PTR_DIFF) != BIGGER) FAIL_MACRO(RTE_PTR_ADD); if ((uintptr_t)RTE_PTR_SUB(BIGGER, PTR_DIFF) != SMALLER) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index d5a32c66a5..09661a5469 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -810,6 +810,14 @@ rte_log2_u64(uint64_t v) /** Number of elements in the array. */ #define RTE_DIM(a) (sizeof (a) / sizeof ((a)[0])) +/** Macro to swap two numbers. */ +#define RTE_SWAP(a, b) \ + __extension__ ({ \ + typeof (a) _a = a; \ + a = b; \ + b = _a; \ + }) + /** * Converts a numeric string to the equivalent uint64_t value. * As well as straight number conversion, also recognises the suffixes -- 2.25.1