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 4A14344101; Wed, 29 May 2024 13:42:40 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3B0184069D; Wed, 29 May 2024 13:42:40 +0200 (CEST) Received: from shelob.oktetlabs.ru (shelob.oktetlabs.ru [91.220.146.113]) by mails.dpdk.org (Postfix) with ESMTP id F2F9640697 for ; Wed, 29 May 2024 13:42:38 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 shelob.oktetlabs.ru 5BED538 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=oktetlabs.ru; s=default; t=1716982957; bh=ulcBHw8PhHwOr45ItK6DqS1JnxRY70IgCNd96bVoO50=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=YLAVlv0cIb8Iz26eK2zAVDC1bYXjvYxh40CNhuodBtI0B92EOIrJb0nI8aN/q72OK qn5lG6jp0Ygu8tiE+0awYVLcVv9ztaXtB/NTkKwVd+8N+enbvklR6Yh4n8N5heu/pY wtt9+cu2eWMxXyV/i/5cjZJoknhoH79CDaXRhMQ4= Received: from [192.168.1.39] (unknown [188.170.73.49]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by shelob.oktetlabs.ru (Postfix) with ESMTPSA id 5BED538; Wed, 29 May 2024 14:42:37 +0300 (MSK) Message-ID: <45817bea-30f4-4bff-8439-07f1c6cca77e@oktetlabs.ru> Date: Wed, 29 May 2024 14:42:30 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/2] eal: provide macro for GCC builtin constant intrinsic To: =?UTF-8?Q?Morten_Br=C3=B8rup?= , Stephen Hemminger , Tyler Retzlaff Cc: dev@dpdk.org References: <1710970416-27841-1-git-send-email-roretzla@linux.microsoft.com> <1710970416-27841-2-git-send-email-roretzla@linux.microsoft.com> <20240331150327.71312354@hermes.local> <98CBD80474FA8B44BF855DF32C47DC35E9F345@smartserver.smartshare.dk> Content-Language: en-US From: Andrew Rybchenko In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35E9F345@smartserver.smartshare.dk> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 4/1/24 11:34, Morten Brørup wrote: >> From: Stephen Hemminger [mailto:stephen@networkplumber.org] >> Sent: Monday, 1 April 2024 00.03 >> >> On Wed, 20 Mar 2024 14:33:35 -0700 >> Tyler Retzlaff wrote: >> >>> +#ifdef RTE_TOOLCHAIN_MSVC >>> +#define __rte_constant(e) 0 >>> +#else >>> +#define __rte_constant(e) __extension__(__builtin_constant_p(e)) >>> +#endif >>> + >> >> >> I did some looking around and some other project have macros >> for expressing constant expression vs constant. >> >> Implementing this with some form of sizeof math is possible. >> For example in linux/compiler.h >> >> /* >> * This returns a constant expression while determining if an argument >> is >> * a constant expression, most importantly without evaluating the >> argument. >> * Glory to Martin Uecker >> * >> * Details: >> * - sizeof() return an integer constant expression, and does not >> evaluate >> * the value of its operand; it only examines the type of its operand. >> * - The results of comparing two integer constant expressions is also >> * an integer constant expression. >> * - The first literal "8" isn't important. It could be any literal >> value. >> * - The second literal "8" is to avoid warnings about unaligned >> pointers; >> * this could otherwise just be "1". >> * - (long)(x) is used to avoid warnings about 64-bit types on 32-bit >> * architectures. >> * - The C Standard defines "null pointer constant", "(void *)0", as >> * distinct from other void pointers. >> * - If (x) is an integer constant expression, then the "* 0l" resolves >> * it into an integer constant expression of value 0. Since it is cast >> to >> * "void *", this makes the second operand a null pointer constant. >> * - If (x) is not an integer constant expression, then the second >> operand >> * resolves to a void pointer (but not a null pointer constant: the >> value >> * is not an integer constant 0). >> * - The conditional operator's third operand, "(int *)8", is an object >> * pointer (to type "int"). >> * - The behavior (including the return type) of the conditional >> operator >> * ("operand1 ? operand2 : operand3") depends on the kind of >> expressions >> * given for the second and third operands. This is the central >> mechanism >> * of the macro: >> * - When one operand is a null pointer constant (i.e. when x is an >> integer >> * constant expression) and the other is an object pointer (i.e. our >> * third operand), the conditional operator returns the type of the >> * object pointer operand (i.e. "int *). Here, within the sizeof(), >> we >> * would then get: >> * sizeof(*((int *)(...)) == sizeof(int) == 4 >> * - When one operand is a void pointer (i.e. when x is not an integer >> * constant expression) and the other is an object pointer (i.e. our >> * third operand), the conditional operator returns a "void *" type. >> * Here, within the sizeof(), we would then get: >> * sizeof(*((void *)(...)) == sizeof(void) == 1 >> * - The equality comparison to "sizeof(int)" therefore depends on (x): >> * sizeof(int) == sizeof(int) (x) was a constant expression >> * sizeof(int) != sizeof(void) (x) was not a constant expression >> */ >> #define __is_constexpr(x) \ >> (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int >> *)8))) > > Nice! > If the author is willing to license it under the BSD license, we can copy it as is. > > We might want to add a couple of build time checks to verify that it does what is expected; to catch any changes in compiler behavior. > LGTM too, but meanwhile we can continue without it just to unblock build on MSVC