Received: by 2002:a05:6a10:7420:0:0:0:0 with SMTP id hk32csp3597993pxb; Mon, 21 Feb 2022 01:24:17 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxDEiVlihdqnLX6uJL/HMGgDsmfiFH21Mr6m0kb1TWcY43NbqgOn1qEUZj21wpLAPEGypX X-Received: by 2002:a17:90a:bb06:b0:1b8:ee0d:7684 with SMTP id u6-20020a17090abb0600b001b8ee0d7684mr20459740pjr.15.1645435457092; Mon, 21 Feb 2022 01:24:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1645435457; cv=none; d=google.com; s=arc-20160816; b=pbuj7hdt1mdIEqiVpzxs5BoNzheckySVX8ggUwkIXpNIY/8z8YN4DG4NnqeB5NEU/c 8fuv4TyHSYUjYevCEPSE2YGgdMv9Hf06Jy9uw+yYRwNPb2R5vw1PUDY+EdZQwUlw7kUI WIN1X9Q0lNLWlrTmifgzbGN/zjvNxFGbPTQPZ/7Rg5YMT7uHbaWmL8v6AHAWyBuhmzx2 3NRK9txcrCP7pvFxvyEO4cztUA/UGNWDAdvp/y/GJQzU0GpobI8a4bTmyhJx7DTv0fSm f+EGEvHu/CKFo2zC6ALeRkFMDRkxzzzTJom+KWYNpJHzssZABoFN20qQwpFL3e5mtxkR 24Eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:dkim-signature:dkim-filter; bh=H1BI137TQVD0IUIV2Akwp3DX/CDXZ2SZLX9a456H6tM=; b=ZPATrKCBtuHTUN3F1p05AQILaPi5h9/omL5dPXfK1x0T4+ZXvWjwRlXgY9uBtpU0oL YLkN9Gu6IhBhGISKuqDXD0vNFMXpe58eV/jxbsyiKBMiOa+ZEZUqKVlg6R1tA6HkgEoC 9zvmUNjS9qF6y83rTmJMMVl/0MD/9BKjXAjE/GRc1dBb7DcoE0AdFytoagQ4w8nKupD/ wpM2OkUEsbNXM7jz4KQK4R/ZuHup5w8FbKF8K61EWM6dFBC3RnHzt/OTRgvrf6IlAUVM RzUUekn4JyPnEfkexZ7XQJwVPHZA/ejgBB40lf63/5Y3Ehb5/sf+Rgm9q2Xr15rKaL0k OpZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=tKEzkfG7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y36si17462799pga.623.2022.02.21.01.24.03; Mon, 21 Feb 2022 01:24:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@efficios.com header.s=default header.b=tKEzkfG7; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=efficios.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239738AbiBRVQd (ORCPT + 99 others); Fri, 18 Feb 2022 16:16:33 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:42434 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239658AbiBRVQL (ORCPT ); Fri, 18 Feb 2022 16:16:11 -0500 Received: from mail.efficios.com (mail.efficios.com [167.114.26.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EE1C22402C1; Fri, 18 Feb 2022 13:15:52 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 5D0923BAC81; Fri, 18 Feb 2022 16:06:46 -0500 (EST) Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id C4s-otjKdnzx; Fri, 18 Feb 2022 16:06:45 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by mail.efficios.com (Postfix) with ESMTP id 3C0BC3BAC08; Fri, 18 Feb 2022 16:06:45 -0500 (EST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.efficios.com 3C0BC3BAC08 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=efficios.com; s=default; t=1645218405; bh=H1BI137TQVD0IUIV2Akwp3DX/CDXZ2SZLX9a456H6tM=; h=From:To:Date:Message-Id; b=tKEzkfG7PGZjAzJkK4utsGhL+ZAcBe2p49eg1uSb6X63SQBFwUQtZQuJQJIfByPxQ 9qgyMzi8Ep0a/6jaiA+PeL7Ke/lbFl37ERUnjRzVF+Uu7KNKQ4q302ijvg0GQ3DzSK msmreRhyfKA9eoyW6tjqm8/re8pSF8vYRWUo/EW32xe3T9jaiECg+KevZHfDIxMPun rsXzuXGF+7rJqvVodNlhGoacGC03UxnH2CA4kGxn6fjo8hS66rC1PAqliTjPdTphw9 uJIgVn9X7Vs3ZLy2/6/bXFDafE1I5fT2nM84/7HPhsO32E4gz3wgi4+TjX3gXvudXA nyglD/BLCXGsw== X-Virus-Scanned: amavisd-new at efficios.com Received: from mail.efficios.com ([127.0.0.1]) by localhost (mail03.efficios.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id aVdYg6aUs7zb; Fri, 18 Feb 2022 16:06:45 -0500 (EST) Received: from localhost.localdomain (192-222-180-24.qc.cable.ebox.net [192.222.180.24]) by mail.efficios.com (Postfix) with ESMTPSA id B61673BAC00; Fri, 18 Feb 2022 16:06:43 -0500 (EST) From: Mathieu Desnoyers To: Peter Zijlstra Cc: linux-kernel@vger.kernel.org, Thomas Gleixner , "Paul E . McKenney" , Boqun Feng , "H . Peter Anvin" , Paul Turner , linux-api@vger.kernel.org, Christian Brauner , Florian Weimer , David.Laight@ACULAB.COM, carlos@redhat.com, Peter Oskolkov , Mathieu Desnoyers Subject: [RFC PATCH v2 06/11] lib: invert _find_next_bit source arguments Date: Fri, 18 Feb 2022 16:06:28 -0500 Message-Id: <20220218210633.23345-7-mathieu.desnoyers@efficios.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220218210633.23345-1-mathieu.desnoyers@efficios.com> References: <20220218210633.23345-1-mathieu.desnoyers@efficios.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Apply bit-invert operations before the AND operation in _find_next_bit. Allows AND operations on combined bitmasks in which we search either for one or zero, e.g.: find first bit which is both zero in one bitmask AND one in the second bitmask. The existing use for find first zero bit does not use the second argument, so whether the inversion is performed before or after the AND operator does not matter. Signed-off-by: Mathieu Desnoyers --- include/linux/find.h | 13 +++++++------ lib/find_bit.c | 17 ++++++++--------- tools/include/linux/find.h | 9 +++++---- tools/lib/find_bit.c | 17 ++++++++--------- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/linux/find.h b/include/linux/find.h index 5bb6db213bcb..41941cb9cad7 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -10,7 +10,8 @@ extern unsigned long _find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long nbits, - unsigned long start, unsigned long invert, unsigned long le); + unsigned long start, unsigned long invert_src1, + unsigned long src2, unsigned long le); extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size); extern unsigned long _find_first_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size); @@ -41,7 +42,7 @@ unsigned long find_next_bit(const unsigned long *addr, unsigned long size, return val ? __ffs(val) : size; } - return _find_next_bit(addr, NULL, size, offset, 0UL, 0); + return _find_next_bit(addr, NULL, size, offset, 0UL, 0UL, 0); } #endif @@ -71,7 +72,7 @@ unsigned long find_next_and_bit(const unsigned long *addr1, return val ? __ffs(val) : size; } - return _find_next_bit(addr1, addr2, size, offset, 0UL, 0); + return _find_next_bit(addr1, addr2, size, offset, 0UL, 0UL, 0); } #endif @@ -99,7 +100,7 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, return val == ~0UL ? size : ffz(val); } - return _find_next_bit(addr, NULL, size, offset, ~0UL, 0); + return _find_next_bit(addr, NULL, size, offset, ~0UL, 0UL, 0); } #endif @@ -247,7 +248,7 @@ unsigned long find_next_zero_bit_le(const void *addr, unsigned return val == ~0UL ? size : ffz(val); } - return _find_next_bit(addr, NULL, size, offset, ~0UL, 1); + return _find_next_bit(addr, NULL, size, offset, ~0UL, 0UL, 1); } #endif @@ -266,7 +267,7 @@ unsigned long find_next_bit_le(const void *addr, unsigned return val ? __ffs(val) : size; } - return _find_next_bit(addr, NULL, size, offset, 0UL, 1); + return _find_next_bit(addr, NULL, size, offset, 0UL, 0UL, 1); } #endif diff --git a/lib/find_bit.c b/lib/find_bit.c index 1b8e4b2a9cba..73e78565e691 100644 --- a/lib/find_bit.c +++ b/lib/find_bit.c @@ -25,23 +25,23 @@ /* * This is a common helper function for find_next_bit, find_next_zero_bit, and * find_next_and_bit. The differences are: - * - The "invert" argument, which is XORed with each fetched word before - * searching it for one bits. + * - The "invert_src1" and "invert_src2" arguments, which are XORed to + * each source word before applying the 'and' operator. * - The optional "addr2", which is anded with "addr1" if present. */ unsigned long _find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long nbits, - unsigned long start, unsigned long invert, unsigned long le) + unsigned long start, unsigned long invert_src1, + unsigned long invert_src2, unsigned long le) { unsigned long tmp, mask; if (unlikely(start >= nbits)) return nbits; - tmp = addr1[start / BITS_PER_LONG]; + tmp = addr1[start / BITS_PER_LONG] ^ invert_src1; if (addr2) - tmp &= addr2[start / BITS_PER_LONG]; - tmp ^= invert; + tmp &= addr2[start / BITS_PER_LONG] ^ invert_src2; /* Handle 1st word. */ mask = BITMAP_FIRST_WORD_MASK(start); @@ -57,10 +57,9 @@ unsigned long _find_next_bit(const unsigned long *addr1, if (start >= nbits) return nbits; - tmp = addr1[start / BITS_PER_LONG]; + tmp = addr1[start / BITS_PER_LONG] ^ invert_src1; if (addr2) - tmp &= addr2[start / BITS_PER_LONG]; - tmp ^= invert; + tmp &= addr2[start / BITS_PER_LONG] ^ invert_src2; } if (le) diff --git a/tools/include/linux/find.h b/tools/include/linux/find.h index 47e2bd6c5174..5ab0c95086ad 100644 --- a/tools/include/linux/find.h +++ b/tools/include/linux/find.h @@ -10,7 +10,8 @@ extern unsigned long _find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long nbits, - unsigned long start, unsigned long invert, unsigned long le); + unsigned long start, unsigned long invert_src1, + unsigned long src2, unsigned long le); extern unsigned long _find_first_bit(const unsigned long *addr, unsigned long size); extern unsigned long _find_first_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size); @@ -41,7 +42,7 @@ unsigned long find_next_bit(const unsigned long *addr, unsigned long size, return val ? __ffs(val) : size; } - return _find_next_bit(addr, NULL, size, offset, 0UL, 0); + return _find_next_bit(addr, NULL, size, offset, 0UL, 0UL, 0); } #endif @@ -71,7 +72,7 @@ unsigned long find_next_and_bit(const unsigned long *addr1, return val ? __ffs(val) : size; } - return _find_next_bit(addr1, addr2, size, offset, 0UL, 0); + return _find_next_bit(addr1, addr2, size, offset, 0UL, 0UL, 0); } #endif @@ -99,7 +100,7 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, return val == ~0UL ? size : ffz(val); } - return _find_next_bit(addr, NULL, size, offset, ~0UL, 0); + return _find_next_bit(addr, NULL, size, offset, ~0UL, 0UL, 0); } #endif diff --git a/tools/lib/find_bit.c b/tools/lib/find_bit.c index ba4b8d94e004..4176232de7f9 100644 --- a/tools/lib/find_bit.c +++ b/tools/lib/find_bit.c @@ -24,13 +24,14 @@ /* * This is a common helper function for find_next_bit, find_next_zero_bit, and * find_next_and_bit. The differences are: - * - The "invert" argument, which is XORed with each fetched word before - * searching it for one bits. + * - The "invert_src1" and "invert_src2" arguments, which are XORed to + * each source word before applying the 'and' operator. * - The optional "addr2", which is anded with "addr1" if present. */ unsigned long _find_next_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long nbits, - unsigned long start, unsigned long invert, unsigned long le) + unsigned long start, unsigned long invert_src1, + unsigned long invert_src2, unsigned long le) { unsigned long tmp, mask; (void) le; @@ -38,10 +39,9 @@ unsigned long _find_next_bit(const unsigned long *addr1, if (unlikely(start >= nbits)) return nbits; - tmp = addr1[start / BITS_PER_LONG]; + tmp = addr1[start / BITS_PER_LONG] ^ invert_src1; if (addr2) - tmp &= addr2[start / BITS_PER_LONG]; - tmp ^= invert; + tmp &= addr2[start / BITS_PER_LONG] ^ invert_src2; /* Handle 1st word. */ mask = BITMAP_FIRST_WORD_MASK(start); @@ -64,10 +64,9 @@ unsigned long _find_next_bit(const unsigned long *addr1, if (start >= nbits) return nbits; - tmp = addr1[start / BITS_PER_LONG]; + tmp = addr1[start / BITS_PER_LONG] ^ invert_src1; if (addr2) - tmp &= addr2[start / BITS_PER_LONG]; - tmp ^= invert; + tmp &= addr2[start / BITS_PER_LONG] ^ invert_src2; } #if (0) -- 2.17.1