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 A788B46077; Tue, 14 Jan 2025 20:20:09 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6768440299; Tue, 14 Jan 2025 20:20:08 +0100 (CET) Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mails.dpdk.org (Postfix) with ESMTP id 881F940298 for ; Tue, 14 Jan 2025 20:20:06 +0100 (CET) Received: by linux.microsoft.com (Postfix, from userid 1213) id 9394D2043F24; Tue, 14 Jan 2025 11:20:05 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 9394D2043F24 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1736882405; bh=z34ZL8DrHWAYtV5ltQ3aeeaGykvHruWN15d/6NpvT7w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=SHTqoTxlOH5S3MvOPN3dWBLqaxAyVwMNuv7YAyIFWEYld8alJzdXYKmKw2Tzk/DBg attH3xKZZTP7lVtVi3VY/ZG5lBHvsigKD/KmTJVa4z4MnBsUgiEVwMYm6ZgM25D9Ib Bzn3weHUmU2FKvvomgL3ssRML6WOTNLg5kLaMZrk= Date: Tue, 14 Jan 2025 11:20:05 -0800 From: Andre Muezerie To: Bruce Richardson Cc: Stephen Hemminger , dev@dpdk.org Subject: Re: [PATCH v11 0/3] add diagnostics macros to make code portable Message-ID: <20250114192005.GA19265@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> References: <1735263196-2809-1-git-send-email-andremue@linux.microsoft.com> <1735918611-17374-1-git-send-email-andremue@linux.microsoft.com> <20250103112402.64bf2d96@pi5> <20250103212634.GA24552@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20250108024647.GA15780@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) 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, Jan 08, 2025 at 09:20:27AM +0000, Bruce Richardson wrote: > On Tue, Jan 07, 2025 at 06:46:48PM -0800, Andre Muezerie wrote: > > On Mon, Jan 06, 2025 at 11:00:15AM +0000, Bruce Richardson wrote: > > > On Fri, Jan 03, 2025 at 01:26:34PM -0800, Andre Muezerie wrote: > > > > On Fri, Jan 03, 2025 at 11:24:02AM -0800, Stephen Hemminger wrote: > > > > > On Fri, 3 Jan 2025 07:36:48 -0800 > > > > > Andre Muezerie wrote: > > > > > > > > > > > From: Andre Muezerie > > > > > > To: andremue@linux.microsoft.com > > > > > > Cc: dev@dpdk.org, stephen@networkplumber.org > > > > > > Subject: [PATCH v11 0/3] add diagnostics macros to make code portable > > > > > > Date: Fri, 3 Jan 2025 07:36:48 -0800 > > > > > > X-Mailer: git-send-email 1.8.3.1 > > > > > > > > > > > > It was a common pattern to have "GCC diagnostic ignored" pragmas > > > > > > sprinkled over the code and only activate these pragmas for certain > > > > > > compilers (gcc and clang). Clang supports GCC's pragma for > > > > > > compatibility with existing source code, so #pragma GCC diagnostic > > > > > > and #pragma clang diagnostic are synonyms for Clang > > > > > > (https://clang.llvm.org/docs/UsersManual.html). > > > > > > > > > > > > Now that effort is being made to make the code compatible with MSVC > > > > > > these expressions would become more complex. It makes sense to hide > > > > > > this complexity behind macros. This makes maintenance easier as these > > > > > > macros are defined in a single place. As a plus the code becomes > > > > > > more readable as well. > > > > > > > > > > Since 90% of these cases are about removing const from a pointer, > > > > > maybe it would be better to have a macro that did that? > > > > > > > > > > Would not work for base driver code which is pretending to be platform independent. > > > > > > > > Most of the warnings I've seen were about dropping the volatile qualifier, like the one below: > > > > > > > > ../drivers/net/i40e/i40e_rxtx_vec_sse.c:42:32: warning: cast from 'volatile struct i40e_32byte_rx_desc::(unnamed at ../drivers/net/i40e/base/i40e_type.h:803:2) *' to '__attribute__((__vector_size__(2 * sizeof(long long)))) long long *' drops volatile qualifier [-Wcast-qual] > > > > 42 | _mm_store_si128((__m128i *)&rxdp[i].read, > > > > | ^ > > > > > > > > To make sure I understood your suggestion correctly, you're proposing to replace this > > > > > > > > __rte_diagnostic_push > > > > __rte_diagnostic_ignored_wcast_qual > > > > _mm_store_si128((__m128i *)&rxdp[i].read, dma_addr0); > > > > __rte_diagnostic_pop > > > > > > > > > > > > with something like this? > > > > > > > > _mm_store_si128(RTE_IGNORE_CAST_QUAL((__m128i *)&rxdp[i].read), dma_addr0); > > > > > > > > This could be done, and I think it does look better, despite the slight line length increase. > > > > > > +1 for this option. One macro can be used to drop all qualifiers, both > > > const and volatile, right? > > > > Yes, a single macro can drop all qualifiers. I did realize though that the macro must involve the entire expression - it cannot be used just around one parameter, unfortunately. > > > For many use cases, those involving pointers, the qualifiers can be cast > away by passing through a uintptr_t. Just tested this with gcc and clang: > > volatile int x = 5; > int *y = (int *)(uintptr_t)&x; > printf("*y = %d\n", *y); > > works without warnings or errors. Does this similarly work with MSVC? If > so, we can do a macro specifically for pointers types, which should cover > 99% of what we need. > > /Bruce Yes, that also works with MSVC. So for the macro you mentioned, is this what you had in mind? old code: _mm_store_si128((__m128i *)&rxdp[i].read, dma_addr0); new code: #define RTE_IGNORE_CAST_QUAL(X) \ (uintptr_t)(X) _mm_store_si128((__m128i *)RTE_IGNORE_CAST_QUAL(&rxdp[i].read), dma_addr0);