From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F1BC5E7F150 for ; Wed, 27 Sep 2023 02:11:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mPMLUaO7NKA5G0IMtaMYNtnc8bv6FgBiVSWDgeMS8NA=; b=tfqQYtChhC/6Z4 heLdNe2y9+xDBH4mMeubQSyKV64B8+B4STQ5z47A7IsUrzZr0yGPbinB6HmckBA4OFrfZ38CEb4hn OWEy0LFPUESslpwufdaixCPaOW3ooeX2ZJy3DfWNDJAkmeEK1bFnXSg5F3hJzg+lX25bA5kJfe00F AlPl7lUrFiD4uAT1ccr+v9x8/Ye1CUa0Q2pBi0TioNYiIhrYWLMqjfYrRjMDozOwkW9lw50dlX0nv sE2+WDceKsT5aWaFYiN5Aznj5xXc04h5xc2NP2+RqYcd9jm1j7Pe+/pwGvOUCugvqVR5jEhK3QFEJ ETgPfTCVGp4+yyVWdHkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qlK0f-00HLlZ-1D; Wed, 27 Sep 2023 02:10:41 +0000 Received: from mail-ua1-x92f.google.com ([2607:f8b0:4864:20::92f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qlK0c-00HLkv-28 for linux-arm-kernel@lists.infradead.org; Wed, 27 Sep 2023 02:10:39 +0000 Received: by mail-ua1-x92f.google.com with SMTP id a1e0cc1a2514c-79df12ff0f0so3531627241.3 for ; Tue, 26 Sep 2023 19:10:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1695780635; x=1696385435; darn=lists.infradead.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=WKL4SUlvuVnRixbAxC7CAkvo9/4L7BDjoTHiJWU8xO8=; b=hTyzv1MhyAN1T8BNxCFJ3IPRiLA69hmQlQf/MIc8262voRuOhjN3HiWzzvYonuIW4n k6l1pUh0HrQtYPBX8uFIH6yAm27tSaVzZoCBdsf5fI31kPPP6YhRELqTwdfWv9grtZEQ Cg9Sw6+vWHytQmwFW0Piu2/O2edETbWza5vBVmyyu+6P9yEsyCf9S88/ytAIz2/TgyfT qNqVbUBCTjZwEvvJnXxapMEsunBcuuriOh2agaAPKzpOybZ5TcV4+qJo9xtjybmPPsmR TJ66pl+oq0xa+Q2M7huKCH5rEztN8lAaZ7sZdvfobCeiQjQtoto5IFp/Ct1+JupUbw9Z gVIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1695780635; x=1696385435; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=WKL4SUlvuVnRixbAxC7CAkvo9/4L7BDjoTHiJWU8xO8=; b=WhHw22G1W3+prsryg0nzYH/8T5dlkxoaZRdr7XsRW5bEXMejVzvVQC3Zmx6UcKcRte 7pwOKfGgO2UXHTEoMnk2u16wmLMnkmlNC9eRgT3aSmobuSXvfSQb4N41H7uVraDFcsN5 254pRBpxs7mR1cjK4F/2pdJTxwON5UnI5faXPCzhcCUIhGQzR096MPiFxDE/rkKgU/s4 mjrsTCbsg488Eqe6pUU0PJDnCtfX1v1ML8Au/yGGZgYV0bC4TuIDXblZlhlBz0wK6Gmj Mh0Sudzkfua1m27+ZP5Kzrbc/nFFXHx0wpYLAsd764AoASOAon//uGp7cLBls4Yn0oy0 jz/Q== X-Gm-Message-State: AOJu0YzHmEoVD+EIg06OkLsdwIgFDvAXYqJrZ3wN3/J1T9IzUQTIDZlV MX7X+0ZDijPMV6a9KX/c/kWiozw5a+w= X-Google-Smtp-Source: AGHT+IHmdRYR7cdIAn645+suJYO7QlP7I9lThH4myZHlqL/SN4GDcg/vIpMfEu82+zwwo2bYF8JGHA== X-Received: by 2002:a67:f50a:0:b0:44d:50f8:10 with SMTP id u10-20020a67f50a000000b0044d50f80010mr817363vsn.25.1695780634699; Tue, 26 Sep 2023 19:10:34 -0700 (PDT) Received: from localhost ([2607:fb90:be31:4195:106f:1ded:e602:ed9b]) by smtp.gmail.com with ESMTPSA id dm6-20020a056130130600b0048b7c4e8277sm1156945uab.15.2023.09.26.19.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Sep 2023 19:10:34 -0700 (PDT) Date: Tue, 26 Sep 2023 19:10:33 -0700 From: Yury Norov To: Andy Shevchenko Cc: Linus Walleij , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Shubhrajyoti Datta , Srinivas Neeli , Michal Simek , Bartosz Golaszewski , Andy Shevchenko , Rasmus Villemoes , Marek =?iso-8859-1?Q?Beh=FAn?= Subject: Re: [PATCH v1 2/5] lib/bitmap: Introduce bitmap_scatter() and bitmap_gather() helpers Message-ID: References: <20230926052007.3917389-1-andriy.shevchenko@linux.intel.com> <20230926052007.3917389-3-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230926_191038_714355_7FEA59FE X-CRM114-Status: GOOD ( 12.77 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org > > +unsigned int bitmap_gather(unsigned long *dst, const unsigned long *src, > > + const unsigned long *mask, unsigned int nbits) > > +{ > > + unsigned int bit; > > + int n = 0; > > + > > + bitmap_zero(dst, nbits); > > + > > + for_each_set_bit(bit, mask, nbits) > > + __assign_bit(n++, dst, test_bit(bit, src)); > > + > > + return n; > > +} > > +EXPORT_SYMBOL(bitmap_gather); So, if mask is 0b01, and src is 0b10, the output will be 0b00. To me it sounds like you've gathered nothing, while the intention was to gather all source bits to bit #0. This is my understanding of the word 'gather', and this is how bitmap_remap() works. bitmap_remap() handles it by wrapping around 0: set_bit(find_nth_bit(new, nbits, n % w), dst); In your case, it may look like: n = off = 0; while (1) { off += n; n = 0; for_each_set_bit(bit, mask, nbits) { if (bit + off >= nbits) return; __assign_bit(n++, dst, test_bit(bit + off, src)); } } (Not tested, except that on piece of paper.) If you claim you're replacing bitmap_remap(), you should correctly handle the above case; when src == dst; when mask is empty, and probably more... Thanks, Yury _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel