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 87F2945BD5; Fri, 25 Oct 2024 13:52:37 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 738B3402ED; Fri, 25 Oct 2024 13:52:35 +0200 (CEST) Received: from dkmailrelay1.smartsharesystems.com (smartserver.smartsharesystems.com [77.243.40.215]) by mails.dpdk.org (Postfix) with ESMTP id 16EC6402BC for ; Fri, 25 Oct 2024 13:52:34 +0200 (CEST) Received: from smartserver.smartsharesystems.com (smartserver.smartsharesys.local [192.168.4.10]) by dkmailrelay1.smartsharesystems.com (Postfix) with ESMTP id EE61B20718; Fri, 25 Oct 2024 13:52:33 +0200 (CEST) Received: from dkrd4.smartsharesys.local ([192.168.4.26]) by smartserver.smartsharesystems.com with Microsoft SMTPSVC(6.0.3790.4675); Fri, 25 Oct 2024 13:52:33 +0200 From: =?UTF-8?q?Morten=20Br=C3=B8rup?= To: dev@dpdk.org, Tyler Retzlaff , Thomas Monjalon , Ferruh Yigit , Andrew Rybchenko , Ajit Khaparde , Somnath Kotur , Bruce Richardson , Gaetan Rivet , Jie Hai , Long Li , Wei Hu Cc: =?UTF-8?q?Morten=20Br=C3=B8rup?= Subject: [PATCH 1/2] eal: add unreachable and precondition hints Date: Fri, 25 Oct 2024 11:52:22 +0000 Message-ID: <20241025115223.1230680-2-mb@smartsharesystems.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241025115223.1230680-1-mb@smartsharesystems.com> References: <20241025115223.1230680-1-mb@smartsharesystems.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-OriginalArrivalTime: 25 Oct 2024 11:52:33.0720 (UTC) FILETIME=[60D73380:01DB26D4] 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 Added two new compiler/optimizer hints: * The __rte_unreachable hint for use in points in code known never to be reached. * The __rte_assume hint for providing information about preconditions the compiler/optimizer might be unable to figure out by itself. Signed-off-by: Morten Brørup --- lib/eal/include/rte_common.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/eal/include/rte_common.h b/lib/eal/include/rte_common.h index c79f9ed319..2f143c87e4 100644 --- a/lib/eal/include/rte_common.h +++ b/lib/eal/include/rte_common.h @@ -366,6 +366,16 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) #define __rte_noreturn __attribute__((noreturn)) #endif +/** + * Hint point in program never reached + */ +#if defined(RTE_TOOLCHAIN_GCC) || defined(RTE_TOOLCHAIN_CLANG) +#define __rte_unreachable() __extension__(__builtin_unreachable()) +#else +/* MSVC or ICC */ +#define __rte_unreachable() __assume(0) +#endif + /** * Issue a warning in case the function's return value is ignored. * @@ -423,6 +433,23 @@ static void __attribute__((destructor(RTE_PRIO(prio)), used)) func(void) #define __rte_cold __attribute__((cold)) #endif +/** + * Hint precondition + * + * @warning Depending on the compiler, any code in ``condition`` might be executed. + * This currently only occurs with GCC prior to version 13. + */ +#if defined(RTE_TOOLCHAIN_GCC) && (GCC_VERSION >= 130000) +#define __rte_assume(condition) __attribute__((assume(condition))) +#elif defined(RTE_TOOLCHAIN_GCC) +#define __rte_assume(condition) do { if (!(condition)) __rte_unreachable(); } while (0) +#elif defined(RTE_TOOLCHAIN_CLANG) +#define __rte_assume(condition) __extension__(__builtin_assume(condition)) +#else +/* MSVC or ICC */ +#define __rte_assume(condition) __assume(condition) +#endif + /** * Disable AddressSanitizer on some code */ -- 2.43.0