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 18EFA43B76; Tue, 5 Mar 2024 19:08:40 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EB78640271; Tue, 5 Mar 2024 19:08:39 +0100 (CET) Received: from mail.lysator.liu.se (mail.lysator.liu.se [130.236.254.3]) by mails.dpdk.org (Postfix) with ESMTP id 333D940270 for ; Tue, 5 Mar 2024 19:08:38 +0100 (CET) Received: from mail.lysator.liu.se (localhost [127.0.0.1]) by mail.lysator.liu.se (Postfix) with ESMTP id E0E01F17F for ; Tue, 5 Mar 2024 19:08:37 +0100 (CET) Received: by mail.lysator.liu.se (Postfix, from userid 1004) id D3131F1ED; Tue, 5 Mar 2024 19:08:37 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on hermod.lysator.liu.se X-Spam-Level: X-Spam-Status: No, score=-1.4 required=5.0 tests=ALL_TRUSTED,AWL, T_SCC_BODY_TEXT_LINE autolearn=disabled version=4.0.0 X-Spam-Score: -1.4 Received: from [192.168.1.59] (h-62-63-215-114.A163.priv.bahnhof.se [62.63.215.114]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.lysator.liu.se (Postfix) with ESMTPSA id 6C3ABF28E; Tue, 5 Mar 2024 19:08:36 +0100 (CET) Message-ID: <5c43fd54-6e59-4882-9efa-f3b3dff98b11@lysator.liu.se> Date: Tue, 5 Mar 2024 19:08:36 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC 2/7] eal: add generic bit manipulation macros Content-Language: en-US To: Tyler Retzlaff , =?UTF-8?Q?Mattias_R=C3=B6nnblom?= Cc: dev@dpdk.org, Heng Wang References: <20240302135328.531940-1-mattias.ronnblom@ericsson.com> <20240302135328.531940-3-mattias.ronnblom@ericsson.com> <20240304164224.GB16065@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> From: =?UTF-8?Q?Mattias_R=C3=B6nnblom?= In-Reply-To: <20240304164224.GB16065@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: ClamAV using ClamSMTP 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 2024-03-04 17:42, Tyler Retzlaff wrote: > On Sat, Mar 02, 2024 at 02:53:23PM +0100, Mattias Rönnblom wrote: >> Add bit-level test/set/clear/assign macros operating on both 32-bit >> and 64-bit words by means of C11 generic selection. >> >> Signed-off-by: Mattias Rönnblom >> --- > > _Generic is nice here. should we discourage direct use of the inline > functions in preference of using the macro always? either way lgtm. > That was something I considered, but decided against it for RFC v1. I wasn't even sure people would like _Generic. The big upside of having only the _Generic macros would be a much smaller API, but maybe a tiny bit less (type-)safe to use. Also, _Generic is new for DPDK, so who knows what issues it might cause with old compilers. Thanks. > Acked-by: Tyler Retzlaff > >> lib/eal/include/rte_bitops.h | 81 ++++++++++++++++++++++++++++++++++++ >> 1 file changed, 81 insertions(+) >> >> diff --git a/lib/eal/include/rte_bitops.h b/lib/eal/include/rte_bitops.h >> index 9a368724d5..afd0f11033 100644 >> --- a/lib/eal/include/rte_bitops.h >> +++ b/lib/eal/include/rte_bitops.h >> @@ -107,6 +107,87 @@ extern "C" { >> #define RTE_FIELD_GET64(mask, reg) \ >> ((typeof(mask))(((reg) & (mask)) >> rte_ctz64(mask))) >> >> +/** >> + * Test bit in word. >> + * >> + * Generic selection macro to test the value of a bit in a 32-bit or >> + * 64-bit word. The type of operation depends on the type of the @c >> + * addr parameter. >> + * >> + * This macro does not give any guarantees in regards to memory >> + * ordering or atomicity. >> + * >> + * @param addr >> + * A pointer to the word to modify. >> + * @param nr >> + * The index of the bit. >> + */ >> +#define rte_bit_test(addr, nr) \ >> + _Generic((addr), \ >> + uint32_t *: rte_bit_test32, \ >> + uint64_t *: rte_bit_test64)(addr, nr) >> + >> +/** >> + * Set bit in word. >> + * >> + * Generic selection macro to set a bit in a 32-bit or 64-bit >> + * word. The type of operation depends on the type of the @c addr >> + * parameter. >> + * >> + * This macro does not give any guarantees in regards to memory >> + * ordering or atomicity. >> + * >> + * @param addr >> + * A pointer to the word to modify. >> + * @param nr >> + * The index of the bit. >> + */ >> +#define rte_bit_set(addr, nr) \ >> + _Generic((addr), \ >> + uint32_t *: rte_bit_set32, \ >> + uint64_t *: rte_bit_set64)(addr, nr) >> + >> +/** >> + * Clear bit in word. >> + * >> + * Generic selection macro to clear a bit in a 32-bit or 64-bit >> + * word. The type of operation depends on the type of the @c addr >> + * parameter. >> + * >> + * This macro does not give any guarantees in regards to memory >> + * ordering or atomicity. >> + * >> + * @param addr >> + * A pointer to the word to modify. >> + * @param nr >> + * The index of the bit. >> + */ >> +#define rte_bit_clear(addr, nr) \ >> + _Generic((addr), \ >> + uint32_t *: rte_bit_clear32, \ >> + uint64_t *: rte_bit_clear64)(addr, nr) >> + >> +/** >> + * Assign a value to a bit in word. >> + * >> + * Generic selection macro to assign a value to a bit in a 32-bit or 64-bit >> + * word. The type of operation depends on the type of the @c addr parameter. >> + * >> + * This macro does not give any guarantees in regards to memory >> + * ordering or atomicity. >> + * >> + * @param addr >> + * A pointer to the word to modify. >> + * @param nr >> + * The index of the bit. >> + * @param value >> + * The new value of the bit - true for '1', or false for '0'. >> + */ >> +#define rte_bit_assign(addr, nr, value) \ >> + _Generic((addr), \ >> + uint32_t *: rte_bit_assign32, \ >> + uint64_t *: rte_bit_assign64)(addr, nr, value) >> + >> /** >> * Test if a particular bit in a 32-bit word is set. >> * >> -- >> 2.34.1