Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp416499rdb; Thu, 22 Feb 2024 07:41:09 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWnwj6hvybyB9ygG8tn34Sh6nUlWNd5JPXZ/oagAuMLFuq47eT2rcjMqnWkdmCTreD8XOrJNO0I9jEqaT/x3uZgHFS8p+rm93pWrtOPEw== X-Google-Smtp-Source: AGHT+IGqFpM4LSlHuLjPD08Iy91kc16iJf0/rw1CpHbaMEu9LaXOFpGqDk+YibvqFOysK39hVuPu X-Received: by 2002:a05:620a:2629:b0:787:a084:a84c with SMTP id z41-20020a05620a262900b00787a084a84cmr2192275qko.26.1708616469333; Thu, 22 Feb 2024 07:41:09 -0800 (PST) Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id f21-20020a05620a409500b0078787ecc201si3800759qko.778.2024.02.22.07.41.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 07:41:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@intel.com header.s=Intel header.b=OM0uGCBz; arc=fail (body hash mismatch); spf=pass (google.com: domain of linux-kernel+bounces-76793-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76793-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 12B951C23040 for ; Thu, 22 Feb 2024 15:41:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 582A114F9D1; Thu, 22 Feb 2024 15:39:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=intel.com header.i=@intel.com header.b="OM0uGCBz" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.15]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B611D14E2EA; Thu, 22 Feb 2024 15:39:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.15 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708616377; cv=none; b=uIwH4rzAyT6+162aY/Q43Z4OtXmP9jmg8cMEYZX8cMBk6axVb68hS19YMziCvHmzy+Hl1Pf9WKsqM6mae14ehxJIOfhNdex9hQge5H554e/0C6mI/y2FKF5KNs3wZ+GMAcLPss/j4a84G0/nxJoJr9rTD9xn1abYSmfXKBI0xqs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708616377; c=relaxed/simple; bh=VwHg7LUdcIrFoPjrcD5ddqTta7KlIaNL26jH4Yy3jIM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sE0XxqQv+/cfvJOOy1GB5XU8q8PPEeMttZSnFsZvCCDYJF43dt+MI6/wXSlXsGO9o+Aq+r2WLYDtLz8FUOtv2JzwoqN8xo7QyEsxb54F7VRWf3QiG7M3AkZeQCObLqekbB3kwkvHjNncDWaPUB15BQ9ow4FUPa7JmZMeLN9v28Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=OM0uGCBz; arc=none smtp.client-ip=192.198.163.15 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1708616375; x=1740152375; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=VwHg7LUdcIrFoPjrcD5ddqTta7KlIaNL26jH4Yy3jIM=; b=OM0uGCBzKRcWGJByDuqLzYS3Tf5nT1AwoTlclXoLB4dAKtEkUI1QR2Pn hGsGva+jZRo6OL/yZrhjkPXclK0gEjIc8OuXoEONlsjWQMEjiMMZtcZ6H zLVCLvXR8RLt8wVACPcLomJUm2SVgwWPHb344mU6tZKNGYq5cHaHgdpON h2rat+VDy5yQsQkMt+EiNTITVC/MpXPKIFKUmqBV5Grxk1OF5+hJl8a+s ZNOQXEN8jmWLykE0h5UIECO5xKqReXwBK/2YcwG9Wk8kLL4G2t7vrZvLt HCFhgNVgC5tmxDn4u05L8vHEsZObut6M5G3qLxw2EqIBLZoErr0/f54aq Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10992"; a="2985497" X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="2985497" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmvoesa109.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 07:39:34 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10992"; a="913544289" X-IronPort-AV: E=Sophos;i="6.06,179,1705392000"; d="scan'208";a="913544289" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga002.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Feb 2024 07:39:31 -0800 Received: from andy by smile.fi.intel.com with local (Exim 4.97) (envelope-from ) id 1rdBAV-00000006fLv-3ofM; Thu, 22 Feb 2024 17:39:27 +0200 Date: Thu, 22 Feb 2024 17:39:27 +0200 From: Andy Shevchenko To: Herve Codina Cc: Vadim Fedorenko , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Yury Norov , Rasmus Villemoes , linux-kernel@vger.kernel.org, netdev@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Andrew Lunn , Mark Brown , Christophe Leroy , Thomas Petazzoni Subject: Re: [PATCH v4 3/5] lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers Message-ID: References: <20240222142219.441767-1-herve.codina@bootlin.com> <20240222142219.441767-4-herve.codina@bootlin.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240222142219.441767-4-herve.codina@bootlin.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo On Thu, Feb 22, 2024 at 03:22:16PM +0100, Herve Codina wrote: > From: Andy Shevchenko > > These helpers scatters or gathers a bitmap with the help of the mask > position bits parameter. > > bitmap_scatter() does the following: > src: 0000000001011010 > |||||| > +------+||||| > | +----+|||| > | |+----+||| > | || +-+|| > | || | || > mask: ...v..vv...v..vv > ...0..11...0..10 > dst: 0000001100000010 > > and bitmap_gather() performs this one: > mask: ...v..vv...v..vv > src: 0000001100000010 > ^ ^^ ^ 0 > | || | 10 > | || > 010 > | |+--> 1010 > | +--> 11010 > +----> 011010 > dst: 0000000000011010 > > bitmap_gather() can the seen as the reverse bitmap_scatter() operation. > The original work was done by Andy Shevchenko. Mine SoB is enough for a credit, but thank you :-) .. > +/** > + * bitmap_gather - Gather a bitmap according to given mask > + * @dst: gathered bitmap > + * @src: scattered bitmap > + * @mask: mask representing bits to extract from in the scattered bitmap > + * @nbits: number of bits in each of these bitmaps > + * > + * Gathers bitmap with sparse bits according to the given @mask. > + * > + * Example: > + * If @src bitmap = 0x0302, with @mask = 0x1313, @dst will be 0x001a. > + * > + * Or in binary form > + * @src @mask @dst > + * 0000001100000010 0001001100010011 0000000000011010 > + * > + * (Bits 0, 1, 4, 8, 9, 12 are copied to the bits 0, 1, 2, 3, 4, 5) > + * > + * A more 'visual' description of the operation: > + * mask: ...v..vv...v..vv > + * src: 0000001100000010 > + * ^ ^^ ^ 0 > + * | || | 10 > + * | || > 010 > + * | |+--> 1010 > + * | +--> 11010 > + * +----> 011010 > + * dst: 0000000000011010 Cool! > + * A relationship exists between bitmap_gather() and bitmap_scatter() (See Either '... (see' or '(). See' > + * bitmap_scatter() for the bitmap scatter detailed operations). > + * Suppose scattered computed using bitmap_scatter(scattered, src, mask, n). > + * The operation bitmap_gather(result, scattered, mask, n) leads to a result > + * equal or equivalent to src. This paragraph... > + * The result can be 'equivalent' because bitmap_scatter() and bitmap_gather() > + * are not bijective. > + * The result and src values are equivalent in that sense that a call to > + * bitmap_scatter(res, src, mask, n) and a call to bitmap_scatter(res, result, > + * mask, n) will lead to the same res value. ..seems duplicating this one. I would drop the latter one. > + */ -- With Best Regards, Andy Shevchenko