Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp319384pxu; Thu, 3 Dec 2020 00:36:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxezMvhmph8UB5cHLI95fiiE/3n0XakaJO5IuzDEPAuHimhmdiSAEzOSvz7L0r4wr4Emcsh X-Received: by 2002:a17:906:268c:: with SMTP id t12mr1496871ejc.91.1606984576507; Thu, 03 Dec 2020 00:36:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606984576; cv=none; d=google.com; s=arc-20160816; b=x5CJNdVEE7/IHFZrF6smhwe0XzzkvRmDeFQ069ki1SkO6rZB74LRUGgNmO+63S2z9U HqBhWHrTR7/1RFAmKfO7KsF8qs7Fb6JTmzKrTfXTCapKw/fKdRgiZB69pWlbLOMcSP+F rAlVuKcgPIHYleYhdxE8VPHeY12EclW3XOEwkUF7LvQQ5LfTh6WGYlI2AzfQVmUqVYxy QUiYyVZNaXRIs6jnazdURL/a6+HGfE9ASCEkCapYKFWsgpk53EkNYL/58/XY0Ow7PN5N P/wl+3JYcRt2d0t3GdnSdYY/oEBiRhLI73Zm+85jwrngqpm2hk/jdHCW7yy503sWM76d FF4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=9dfbprICCCrSs+WBMIlheF+1A8ZYjR+D6Ak7ORnabGY=; b=TmmYJ7YLRx+3NXJh5bMfxTmhJUSU+E2VXoOzMa/Ow2vaIMhNyxwjBzVKjlwdm8pWLb 0CbJBP5RGRvVOccnAkAbUhGTcRTfiPqvKMfm72gLCeHe46k+5ywBL1eWNV5DruJMz2tL zgImv2i5PD2/t5MD9cIiQWaZV0FJDgiKf85FHD9yfWrcRuT88qXG+vQQM/iOHnW1tIGO DZuV2NKj+rNybVdZJ5yAEqwmuFbn9JxvL8LolTiMGyHBb0F1UNGs8dHIKxHkWaUYevfx uONdhPq7Lt7ipMAI/K3+V9DP3ePEXFl/v3KkjkLs4zk+5WIGfIqsKRmD5kR3mdiG4BwW NGlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=NJFoncHy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u26si539068edo.164.2020.12.03.00.35.52; Thu, 03 Dec 2020 00:36:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@rasmusvillemoes.dk header.s=google header.b=NJFoncHy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727146AbgLCIec (ORCPT + 99 others); Thu, 3 Dec 2020 03:34:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725912AbgLCIec (ORCPT ); Thu, 3 Dec 2020 03:34:32 -0500 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C2A6C061A4D for ; Thu, 3 Dec 2020 00:33:51 -0800 (PST) Received: by mail-ej1-x636.google.com with SMTP id bo9so2131294ejb.13 for ; Thu, 03 Dec 2020 00:33:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rasmusvillemoes.dk; s=google; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=9dfbprICCCrSs+WBMIlheF+1A8ZYjR+D6Ak7ORnabGY=; b=NJFoncHy+4AOXb8Innv/FCULVy0+N8C7fKWW18kIlWveSqghbWln7vhBxVw1/MrCbP muzrjYmmSF/uZXoGtZoHS3YpuHHXFjBdvVyCorQAXPpE+ZblkanGJzdANqXD+bhDTu0R PKs+K6h1GAnSl7O5Qc4QYird35hgdQ2EcSawU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=9dfbprICCCrSs+WBMIlheF+1A8ZYjR+D6Ak7ORnabGY=; b=Fr9BDpOzq9ROzd9xZzk9PjIO4KEMqL7MuaM+I3S8P0jcYdiizWdvPMYXuo4pNR/meK gmpIacn+eoTSEErWGiSSTnDZWp3e5VJXIc/HIshrs3GMcLaLJH47JIq3FA4Sb1cFIAyS vV9hgs9TM4P83esbx83SZrrT9B8qgKzEjl/lrSjjOPQEUOgVly6GQSDsdGTsXX1FeQi1 3+U3XfYE8JOYut9spj4LgMBC3aQ76ORktdWbReqzrqCFvgrZzfsvnuITEtDFzbWhZPEX Gh6Ak4cfPvno2StA27z57H4c3D8s9KSnKigJnRnVl8p6vyX+4LBIvmD/L2oB4rWUic7+ CnUQ== X-Gm-Message-State: AOAM530l6+sxQTazJTGpuvXGZh1PUZNN3eRBT7TqkZGVppyUUU/bJH00 yHajZk/xGV90c8tMOxMHacEVfOfwttOxjw== X-Received: by 2002:a17:906:6010:: with SMTP id o16mr1518630ejj.55.1606984430082; Thu, 03 Dec 2020 00:33:50 -0800 (PST) Received: from [192.168.1.149] (5.186.115.188.cgn.fibianet.dk. [5.186.115.188]) by smtp.gmail.com with ESMTPSA id n4sm641113edt.46.2020.12.03.00.33.48 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2020 00:33:49 -0800 (PST) Subject: Re: To: Yun Levi , Yury Norov Cc: dushistov@mail.ru, Arnd Bergmann , Andrew Morton , "Gustavo A. R. Silva" , William Breathitt Gray , richard.weiyang@linux.alibaba.com, joseph.qi@linux.alibaba.com, skalluru@marvell.com, Josh Poimboeuf , Linux Kernel Mailing List , linux-arch@vger.kernel.org, Andy Shevchenko References: <20201202094717.GX4077@smile.fi.intel.com> From: Rasmus Villemoes Message-ID: Date: Thu, 3 Dec 2020 09:33:48 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 03/12/2020 02.23, Yun Levi wrote: > On Thu, Dec 3, 2020 at 7:51 AM Yun Levi wrote: >> >> On Thu, Dec 3, 2020 at 6:26 AM Yury Norov wrote: >>> >>> On Wed, Dec 2, 2020 at 10:22 AM Yun Levi wrote: >>>> >>>> On Thu, Dec 3, 2020 at 2:26 AM Yury Norov wrote: >>>> >>>>> Also look at lib/find_bit_benchmark.c >>>> Thanks. I'll see. >>>> >>>>> We need find_next_*_bit() because find_first_*_bit() can start searching only at word-aligned >>>>> bits. In the case of find_last_*_bit(), we can start at any bit. So, if my understanding is correct, >>>>> for the purpose of reverse traversing we can go with already existing find_last_bit(), >>>> >>>> Thank you. I haven't thought that way. >>>> But I think if we implement reverse traversing using find_last_bit(), >>>> we have a problem. >>>> Suppose the last bit 0, 1, 2, is set. >>>> If we start >>>> find_last_bit(bitmap, 3) ==> return 2; >>>> find_last_bit(bitmap, 2) ==> return 1; >>>> find_last_bit(bitmap, 1) ==> return 0; >>>> find_last_bit(bitmap, 0) ===> return 0? // here we couldn't Either just make the return type of all find_prev/find_last be signed int and use -1 as the sentinel to indicate "no such position exists", so the loop condition would be foo >= 0. Or, change the condition from "stop if we get the size returned" to "only continue if we get something strictly less than the size we passed in (i.e., something which can possibly be a valid bit index). In the latter case, both (unsigned)-1 aka UINT_MAX and the actual size value passed work equally well as a sentinel. If one uses UINT_MAX, a for_each_bit_reverse() macro would just be something like for (i = find_last_bit(bitmap, size); i < size; i = find_last_bit(bitmap, i)) if one wants to use the size argument as the sentinel, the caller would have to supply a scratch variable to keep track of the last i value: for (j = size, i = find_last_bit(bitmap, j); i < j; j = i, i = find_last_bit(bitmap, j)) which is probably a little less ergonomic. Rasmus