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 AE36843D98; Mon, 1 Apr 2024 00:03:33 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3AE8840272; Mon, 1 Apr 2024 00:03:33 +0200 (CEST) Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by mails.dpdk.org (Postfix) with ESMTP id 1BCB84026F for ; Mon, 1 Apr 2024 00:03:31 +0200 (CEST) Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e6ca2ac094so3122144b3a.0 for ; Sun, 31 Mar 2024 15:03:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20230601.gappssmtp.com; s=20230601; t=1711922610; x=1712527410; darn=dpdk.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:from:to:cc:subject:date :message-id:reply-to; bh=egogvquzw9ICyrfdhYgAnQPSMlaBaQ1e6r339Wc9kBk=; b=NaYMF/T+KJTMxHXrlLAi0/9kmKFzb7DNXlqDBXAsYEharxdoUIMf9VQyktI3ulbtNC C4MjqNYr1CMdatwIFrm8c8ZfbVobQKztGQUEPND6fCPzGl33BkeJLVvRI6KfzEaVNkNE dTnQttrQj2XctQUjRIysYeGI/qESi4y8AUgyiw29Yv629w15ukLn2xrIbVHNur0xBZSX WzKDhH1eDsxGEosLVCzThRO+7d3zKNiroWfWf2kd3zDtIN76fudNfo5AZO9loU79kR5x E3xr4LkHsQQxKdf1hDXDWe+7OEkoKO+B++7i7oHRx/Ru6KKNY6+BtrGMLp43s80b5JrR W14w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711922610; x=1712527410; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:subject:cc:to:from:date:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=egogvquzw9ICyrfdhYgAnQPSMlaBaQ1e6r339Wc9kBk=; b=i9/A798Vm/p+9rBljuPx8CHMGyFUhs9bQojP+3qEakwWzhnS55J/SZBfLBLyna51ql J069sPzs3iyobNcz6gA2l3JTB38oLB0h7sGtfMioS7f8fArVSZxQGESoXjRgdbhEcWz7 CyOilA6u549ZYVZuoSuY2/3gbO1PS45VZLdAp4F4VVw3gemnlRVJ+pKzlBiDfBqkrMTq Ke+7/jHHEDEMnKmsFP/y5FQOM4nwK4Vi50BNbrQ7tkR8auYQABrIewerAV/xPULhjh0f ZtxvyZU9fcXfkV53HKPENgLgVbvJ8f+74j/Nw0LCJf/smmXKqwXgTRaCeBHJ7RoOKdqs zCiw== X-Gm-Message-State: AOJu0YxEdstVbl2aRw65BXaZr24RDJRVk5hHegjqE0/5GMWF9o1KSiUt 9njiLX/fA005GEl4fX/xY2YM8QbMBcJCfe/buwXWhn0CdG0tpj8G7oqvOrOMRmc= X-Google-Smtp-Source: AGHT+IFC438LhsfIZIUL7GjjqxeMsUJLRkcWvS33IMb9nN/K9uTosg4BAMmRYpRIZm47hHhN6Kq4Hg== X-Received: by 2002:a05:6a20:1790:b0:1a3:7f5f:57e8 with SMTP id bl16-20020a056a20179000b001a37f5f57e8mr4941917pzb.36.1711922610032; Sun, 31 Mar 2024 15:03:30 -0700 (PDT) Received: from hermes.local (204-195-123-203.wavecable.com. [204.195.123.203]) by smtp.gmail.com with ESMTPSA id m12-20020aa78a0c000000b006ea98271e43sm6764242pfa.144.2024.03.31.15.03.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 31 Mar 2024 15:03:29 -0700 (PDT) Date: Sun, 31 Mar 2024 15:03:27 -0700 From: Stephen Hemminger To: Tyler Retzlaff Cc: dev@dpdk.org, Morten =?UTF-8?B?QnLDuHJ1cA==?= , Andrew Rybchenko Subject: Re: [PATCH 1/2] eal: provide macro for GCC builtin constant intrinsic Message-ID: <20240331150327.71312354@hermes.local> In-Reply-To: <1710970416-27841-2-git-send-email-roretzla@linux.microsoft.com> References: <1710970416-27841-1-git-send-email-roretzla@linux.microsoft.com> <1710970416-27841-2-git-send-email-roretzla@linux.microsoft.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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, 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)))