From nobody Mon Feb 9 13:57:55 2026 Received: from mail-yx1-f52.google.com (mail-yx1-f52.google.com [74.125.224.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7665D266565 for ; Tue, 23 Dec 2025 16:23:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766506989; cv=none; b=br0x1k6HPqeFTMArZ73wmqb/2KiaLAvmJE//424yon1Se5Z3FC++MIDF4j9Up1ZUX0Xa7tkamGtTZ8R20/dPIbPXWbH1pMtInxMFzz9DBccR+RIwlgNfw7zG2vmo4OEFdZcvf8frl5su/XWo/P4cIwlwB5r/PHhMIDwIqMQSztQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1766506989; c=relaxed/simple; bh=W7Kmewx74CQUT/jw/IRpbzAwhK2jEyGtRXl+6mNIgrE=; h=From:To:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kMqRjydrMVbCK9NHhhIQ4U+U9V67mUq1iOBDv1kGs8xGaaejzCR8d/faIA2rXrv0fryL4+YzMfJr9UBEDkpCvZu4aq4LMAMVmxzZ+EXq4/KBVO3ZkK9dOpPLj6O4iQ8Sj9GJfv7BPnZE4V8CpjJR+iQQHPe1Hkubnfe/uIBb5Lw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=nq7tIh2k; arc=none smtp.client-ip=74.125.224.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nq7tIh2k" Received: by mail-yx1-f52.google.com with SMTP id 956f58d0204a3-6446c2bbfe3so4148157d50.1 for ; Tue, 23 Dec 2025 08:23:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1766506986; x=1767111786; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=Bu9hANCrqcrzn01CQ6+qCySerDAxUYWA0/vX02ujpFY=; b=nq7tIh2kzYWqMiVm/Q8VV2UVz2XH0jrChkZxwqvFiCXxFP/xkSeEpLoRP+u0i9mV56 fR603QXjP82JJw0/Q/uZEOUSQpwfSt3hmrD9UIMnCwiwagzGvR9yzQzAxa4dhbEMGx0T rizA829xQ2ErDAtt+N0r+YfbGqAqUZcv2HQ3CUQ2IYE6xUfVH0hXCI6HmmrjysCTukW4 7B72ks7aNTcMa8nw8lNS9PeUkt1DHzRr2xoCmLFhGBQleB9E6T8gmDPTq5lC7wtR+s3A VpZlb/bCtmF44PDw7AfkK7ONSTqM95EsI53X2L4LewkVTbfW4Wi3R9PqyxivGqAsi+m4 1etw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1766506986; x=1767111786; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=Bu9hANCrqcrzn01CQ6+qCySerDAxUYWA0/vX02ujpFY=; b=m+GY8f477Cap5Q/axzR+B9usdCOF64i1UJGUCtT9gPm7FheRfOHwCLw45T+6mQzvzu +3sBnXiWhv+c4SN4SfCkg06bc2s0GKd1onB8/02Z4WW9Wrun8124bG+lfr5tiiYnKBVa CisTekyxnYdrZ+3EP3GMQmzfGPOXKg76bZY5IZWcgFrfmI2RID/1U/02Vl5UDKmQTseH 4tCbHsHgS8q1uLOTLJVCsKYEFspP135mDMos8C8KyhOBhm47/U+NLb3w0g32kUdDfON/ 1RhsQYX3N0/5eKcOGxoi6wcXIY1htFCeBPHRDT5ueBOMn2incrlg2tiXabD33Rkp0Gno SJTg== X-Forwarded-Encrypted: i=1; AJvYcCWUQ5qnFE4dl7LZuhWXZPM8J0roq6Nt4NN8rsn/U5Xrl2qWzjjHVIvZleQ7EhLJOSOWS3YnyucbQOXtj3Y=@vger.kernel.org X-Gm-Message-State: AOJu0YxQceEsqEoaHmCOTTGNu5zMhwLT5IsQ0GFUG3+wL+IztUkPN0Gl vE52pvjVyehXjJ2/bMAPIf4NfezoV55YYszPSCJswK3p5tn09eFM0QsO X-Gm-Gg: AY/fxX4xY0GnskFN8Wj3l4ReFheiQANNoqwcHLZaB1kfBHi1RS56d5UZK8C9A9DY4xV ZLgTbiR/tlhdY7Et8JXKmzkcK5cMFGgA/p+e4RIwcfgRbQSByEe9ghDxnMedEMa3XDAze6Ud5W5 h7yPT7m98zyHLVH8Qsl5mNBF5LUKUBJb8aAXodVVo9/BUU6pbL2enYTBVV6zBto0Ll6/tx+xBJ7 K3614gkSFdUWJxikfgo7qvzGGH/xu7/oLtYrEQCoRtIkIgtxq4H1cEGNELvWvcSsFiVuOYX+ZkE 5OaCJFFmpLYyMQsgqFeoIVijcW9hoKoVvK4FnmEflsWichTfvqF4XIgc0Hxo1H0rWPCajgZJ+O2 VSVD0m2pH+MbNUm7ufCTcGLSQJJ2yezRDKODvSTaMZkA62irIK94BptDzIb/vrvsBKQ42UYBIGn 8dNMa7wNE= X-Google-Smtp-Source: AGHT+IExQlcrRvP5bpGZsniR6NEoCL2BesRdWqeHSXBthxN++RkTXQKi6hOc4cN4HB6bL+lo8PUVtA== X-Received: by 2002:a53:da86:0:b0:63f:9c11:cfed with SMTP id 956f58d0204a3-6466a842daamr9378345d50.32.1766506986363; Tue, 23 Dec 2025 08:23:06 -0800 (PST) Received: from localhost ([2601:346:0:79bd:4913:14a4:1114:ff0d]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-6466a8b16e2sm7101778d50.2.2025.12.23.08.23.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Dec 2025 08:23:06 -0800 (PST) From: "Yury Norov (NVIDIA)" To: Tony Nguyen , Przemek Kitszel , Andrew Lunn , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yury Norov , Rasmus Villemoes , Andrew Morton , intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] bitmap: introduce bitmap_weighted_xor() Date: Tue, 23 Dec 2025 11:23:00 -0500 Message-ID: <20251223162303.434659-2-yury.norov@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251223162303.434659-1-yury.norov@gmail.com> References: <20251223162303.434659-1-yury.norov@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The function helps to XOR bitmaps and calculate Hamming weight of the result in one pass. Signed-off-by: Yury Norov (NVIDIA) --- include/linux/bitmap.h | 14 ++++++++++++++ lib/bitmap.c | 7 +++++++ 2 files changed, 21 insertions(+) diff --git a/include/linux/bitmap.h b/include/linux/bitmap.h index 0f4789e1f7cb..7ecf56e0d3b5 100644 --- a/include/linux/bitmap.h +++ b/include/linux/bitmap.h @@ -169,6 +169,8 @@ void __bitmap_or(unsigned long *dst, const unsigned lon= g *bitmap1, const unsigned long *bitmap2, unsigned int nbits); unsigned int __bitmap_weighted_or(unsigned long *dst, const unsigned long = *bitmap1, const unsigned long *bitmap2, unsigned int nbits); +unsigned int __bitmap_weighted_xor(unsigned long *dst, const unsigned long= *bitmap1, + const unsigned long *bitmap2, unsigned int nbits); void __bitmap_xor(unsigned long *dst, const unsigned long *bitmap1, const unsigned long *bitmap2, unsigned int nbits); bool __bitmap_andnot(unsigned long *dst, const unsigned long *bitmap1, @@ -355,6 +357,18 @@ unsigned int bitmap_weighted_or(unsigned long *dst, co= nst unsigned long *src1, } } =20 +static __always_inline +unsigned int bitmap_weighted_xor(unsigned long *dst, const unsigned long *= src1, + const unsigned long *src2, unsigned int nbits) +{ + if (small_const_nbits(nbits)) { + *dst =3D *src1 ^ *src2; + return hweight_long(*dst & BITMAP_LAST_WORD_MASK(nbits)); + } else { + return __bitmap_weighted_xor(dst, src1, src2, nbits); + } +} + static __always_inline void bitmap_xor(unsigned long *dst, const unsigned long *src1, const unsigned long *src2, unsigned int nbits) diff --git a/lib/bitmap.c b/lib/bitmap.c index 698d15933c84..bed32b8cd23a 100644 --- a/lib/bitmap.c +++ b/lib/bitmap.c @@ -382,6 +382,13 @@ unsigned int __bitmap_weighted_or(unsigned long *dst, = const unsigned long *bitma return BITMAP_WEIGHT(({dst[idx] =3D bitmap1[idx] | bitmap2[idx]; dst[idx]= ; }), bits); } =20 +unsigned int __bitmap_weighted_xor(unsigned long *dst, const unsigned long= *bitmap1, + const unsigned long *bitmap2, unsigned int bits) +{ + return BITMAP_WEIGHT(({dst[idx] =3D bitmap1[idx] ^ bitmap2[idx]; dst[idx]= ; }), bits); +} +EXPORT_SYMBOL(__bitmap_weighted_xor); + unsigned long __bitmap_weight_from(const unsigned long *bitmap, unsigned int start, unsigned int nbits) { --=20 2.43.0