Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2459480rdh; Wed, 27 Sep 2023 03:24:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGcsrOSYM/7mjK8TgopknjRHp629PU0y+vwBzb7Wqi3LCToqhwOZP5AuP/WsihLTS9wqOvU X-Received: by 2002:a17:902:c94d:b0:1c6:9312:187 with SMTP id i13-20020a170902c94d00b001c693120187mr1461123pla.3.1695810293843; Wed, 27 Sep 2023 03:24:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695810293; cv=none; d=google.com; s=arc-20160816; b=YGy95gwxYiXmdLl81TX8QhPZ+6/3ZrmgCehVQFdDWkGPyJm334V2XNzrCPi5NvcfO3 us2HZRiFzO236/1rwkjtMIEEGijn5h5L8ZFwnKrXQAra73b2jDLwxI28rPhqzQa7Q/zh bVY5Pt12mxavFzSybn6CeJih7mjEeUZon/3qoBCd3wpopMG9ecpP7tAiR1u9UC42x6X2 D/AoR9ISc7zLu2xMFe0l4H60Df5naH/ZcJalU0UuB5u2eTlM6ex1PFy4LZcQmMfflDZn mkO2IprU3q/E87eL3pGf8pgQvboVNujMJHODrO8UkTTXZ0BoXQYceE8gcoGH6fEzuPhP iXEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=WKL4SUlvuVnRixbAxC7CAkvo9/4L7BDjoTHiJWU8xO8=; fh=YeMt132Usghl/nW9bOYiUGkNv17zIMtOzYiAH5oqoio=; b=aZ+rWkSQ3wC85olKKJi0cbWlCwKBhouSZug3SvT/F9SeFhW1IUDFl+QCD/6fNbeOSR RbevBugjGUqQzA7hSlrzsxzBEtZ1WpZwbPoJFNdZkUFl0RzAw3UX2HoCIIh/DqZXjy6n K5IdguOcpSC+HPMJJz+J4rkBFp/XVrjnrggrJ7uhQo5locwPwACIICklDUP5dEqkGPLF YEZCeQJ5aLbM+60zmBIf1BA4vyF8Ti4pKVMev4LGSwhP9nUPCWTJxivBY4eOTawhXP6x 8PbkIBL1DhNU+GEiPToGK5VSRq8xNImTnlKkeSjPQFx9o1FXzdayRRFmNspDhQ7ZQbLO DxjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GwtzGeDf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id kx11-20020a170902f94b00b001c62acfa473si4925606plb.62.2023.09.27.03.24.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 03:24:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GwtzGeDf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C7A99808DB56; Tue, 26 Sep 2023 22:45:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229504AbjI0Fpb (ORCPT + 99 others); Wed, 27 Sep 2023 01:45:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbjI0Fo4 (ORCPT ); Wed, 27 Sep 2023 01:44:56 -0400 Received: from mail-ua1-x935.google.com (mail-ua1-x935.google.com [IPv6:2607:f8b0:4864:20::935]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C61F17A95; Tue, 26 Sep 2023 19:10:35 -0700 (PDT) Received: by mail-ua1-x935.google.com with SMTP id a1e0cc1a2514c-7a803afa8c5so3543033241.0; 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=vger.kernel.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=GwtzGeDfBFzEsSHV6iGIRcIWldwrN9B4DMEhcjql4Rqizxm51/qVknW0hDWVqYvS/F kVaZlJ5I9Cr58DWhrG0aKzB1gsU7IUC5YVU+Pbn9HLI8pDoq+holdDkiouhg86NBFv1J Uh9H8C0Tp47Y/51HUAMPIuO0MmwM9Jx4qb4ij9RYuzmh7yzr0k3IJ2CIEMRYRSPrNWMG es32ey2uGge7QDtTmDHz2jIRUjX/rJGv5Gca9nh9DOAATG3QmBiJ27y+O+0QqcyGxQSI MqizjvatqOdgy5FfwTbZxG3GQVZcbC83b8OzI/7o5gJqKqKRR+eLIU8WliUDt79BpOPH 86fA== 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=YmBU9OdfFUFFlwdS/ut1JkCocXmIrRus37YZit/IBkYWRIw4t8YMzxvYJH6k/dL15y s+yifciIhjedYBu9spaxdtAeVbQlzhhWUtFs8vUjUw+QwjMpJlevViYI18GPsAvxsI4j mjpUffKAnRKJS0zf6u1uh6pT+/tqgduyZuDB8tLYrUwaJpbIwK5p4ogQXvokh3al2lrg Ha3cJcCCwjz83Fc4y2g0/E9MQfq1LhgmFmwnFLryZ2vztAhcjqXeTPB4Rkj9r2lT3ysS SnyjGQcnW4rQgBneOfw4HNCoO3BfDcZhPBA+AVbERSpfl5Vh7StpoTSK3Tq5ML8m22FC ttdQ== X-Gm-Message-State: AOJu0YysS5oFS3kgzF9IKRsyUz5w4vD+I2xjQWluJt1AjJqKEdmynZvD OnBUv0iI4ATkHeAnePGSdzE= 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 26 Sep 2023 22:45:59 -0700 (PDT) > > +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