Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2019487ybp; Thu, 10 Oct 2019 00:42:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyxBA5ycMwccjYu58MwsGyRJ7tzlpo+iQUD8cNe1e9oHfjT0kI1kSZeQKoLZ+mxPSI1+aeS X-Received: by 2002:a17:906:86c8:: with SMTP id j8mr1379601ejy.32.1570693350989; Thu, 10 Oct 2019 00:42:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570693350; cv=none; d=google.com; s=arc-20160816; b=iZ3v5j6v+0sS3ATOEoh7FemK+KbJfNHVhn0DZ5Pz6hwxX8ZTMciMg5G9u4Pth/+tsn pOvgAPj+hoGa6X9VRceJ0gvXRzyed3gzRCGwCSrLNloHXN0h2Ca2L1rIkk1htAmJPmnP +q67pYUh/KDHJFDzokfAZ+8n9o+P8AlUUx9dviB78260Zdx8ryYk0+wUimRQ+WqWW5lL lNtTQ/q4SKWIMu94yVXt/fITgpJlTNfIP62BYjMuhZR1csKShwznA0fOaqeNK0PCkXgz i2XNmPEi8Poxv4JjGmYBmh0UonYOzUgrW5JPA7ArFjFto+WQIfkhzwRLeY9lJ2CE7RuE 9FnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=NURwLHdKTSUja8QJMkMZYKyjuSxICE5fd85HFToXHUo=; b=otwxyUMyvgzQJkys1+NWnwoDuqJAuGtIpRkdxVA+Ui6OIERS9jfsb4cBXg7Y22ejRU A39c+jxyaIdKfbxQ06h0JTtnZ3RUV4gI8x68H5zaUSpaPJBuZljWxR6+ojbN4qiA5s6c NevbePAY3PnPZG5xjrvWw9+QzR1FpxTfq4uM4uj2vednPLvQpwg0yn7Ok6wOybNjECMV b6MppbKKoKYYbBu659v4mkSjK7AkxNJAsu5sGxtpBEImQMeDh0OfBUur4s0bb7ElGNS7 iSWrw7XdWoaWTG9sS843MoQn+AY0UA7Mf0Bs98+qQGGQ66N0OsplBU5NuG4ChOfSj1m2 4LnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q1RVugoY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p43si3057238edc.368.2019.10.10.00.42.07; Thu, 10 Oct 2019 00:42:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=q1RVugoY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733175AbfJJHmB (ORCPT + 99 others); Thu, 10 Oct 2019 03:42:01 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:35840 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727196AbfJJHmB (ORCPT ); Thu, 10 Oct 2019 03:42:01 -0400 Received: by mail-pg1-f193.google.com with SMTP id 23so3129538pgk.3; Thu, 10 Oct 2019 00:42:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NURwLHdKTSUja8QJMkMZYKyjuSxICE5fd85HFToXHUo=; b=q1RVugoYID1AntkYDacABjtI5fJI2xoh0kTSCp11ZmTPy2LsAOnqdkLl0dgT/wt0Ek JiPGbQPc0bUJQCNscgMRBLCd2g4y6E6UPh7YTmevt5wTSP3McI3jGC0xuIWsiCZ72TA7 qklewgxuJP+GT9GiJyZazmKqlg+3K8MDdsU1drkv2VslNNVYeaywlhRwa6lN+3MsG/Yx NAardTvdjDDzxhCGflO+ITcQs+MH5S6y9SJ5JfOFMsmHHLoWV04JLW5YMMbivlJGzr79 VEKnWfxJQa2wECy3tgO0xtCbEFQMNn4Dqp0PJDdGXNhqNPfWfFNalY3Yh/3KfAQiVfZM g1Ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NURwLHdKTSUja8QJMkMZYKyjuSxICE5fd85HFToXHUo=; b=W2H6CtI8rFlFvKQGagb9QdozY4A/jgIVKsqNatB9XA8lqHMKVurm1lgWWFjnzCgQNQ NG64g5VuIYzdOmKoiUW2zqnWwUBBhvIKlIHIEJBZ9pkiReDADMmI8xid56TCODRTgR8l zzMaZ1fekzKZQ7POHJcbKhVPej/Xa2yg2frw9lp4ufk2Ply5PKFijQS8CDGePLLtE4S/ NGAXWLMMrxCgp9dYSbNLMvQmxT8DowYbf5LtvAOTaLILb+A2RRMjPXbCw3TQhXpl9Ewn powMPlFJrU8karpQrYOASlw7uof0sX+Yza0Iv2k4hPzmkKv5UFVc1QMQWn4pDvFbJs+P rdKw== X-Gm-Message-State: APjAAAUae8LJDZ+5xpsyaWdkypXwim17Y9aAK8/NLtovV3lde3ZpCCWX iArubk1ogRL/x5tnF7hlsbqM/spgmzAvUmpmfSk= X-Received: by 2002:a17:90a:b391:: with SMTP id e17mr10016417pjr.132.1570693320245; Thu, 10 Oct 2019 00:42:00 -0700 (PDT) MIME-Version: 1.0 References: <893c3b4f03266c9496137cc98ac2b1bd27f92c73.1570633189.git.vilhelm.gray@gmail.com> <20191009170917.GG32742@smile.fi.intel.com> In-Reply-To: From: Andy Shevchenko Date: Thu, 10 Oct 2019 10:41:49 +0300 Message-ID: Subject: Re: [PATCH v17 01/14] bitops: Introduce the for_each_set_clump8 macro To: Geert Uytterhoeven Cc: Masahiro Yamada , Andy Shevchenko , William Breathitt Gray , Linus Walleij , Bartosz Golaszewski , Andrew Morton , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , linux-arch , Rasmus Villemoes , linux-arm-kernel , Linux PM mailing list , Phil Reid , Lukas Wunner , sean.nyekjaer@prevas.dk, morten.tiljeset@prevas.dk, Arnd Bergmann Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 10, 2019 at 9:29 AM Geert Uytterhoeven wrote: > On Thu, Oct 10, 2019 at 7:49 AM Andy Shevchenko > wrote: > > On Thu, Oct 10, 2019 at 5:31 AM Masahiro Yamada > > wrote: > > > On Thu, Oct 10, 2019 at 3:54 AM Geert Uytterhoeven wrote: > > > > On Wed, Oct 9, 2019 at 7:09 PM Andy Shevchenko > > > > wrote: > > > > > On Thu, Oct 10, 2019 at 01:28:08AM +0900, Masahiro Yamada wrote: > > > > > > On Thu, Oct 10, 2019 at 12:27 AM William Breathitt Gray > > > > > > wrote: > > > > > > > > > > > > > > This macro iterates for each 8-bit group of bits (clump) with set bits, > > > > > > > within a bitmap memory region. For each iteration, "start" is set to the > > > > > > > bit offset of the found clump, while the respective clump value is > > > > > > > stored to the location pointed by "clump". Additionally, the > > > > > > > bitmap_get_value8 and bitmap_set_value8 functions are introduced to > > > > > > > respectively get and set an 8-bit value in a bitmap memory region. > > > > > > > > > > > Why is the return type "unsigned long" where you know > > > > > > it return the 8-bit value ? > > > > > > > > > > Because bitmap API operates on unsigned long type. This is not only > > > > > consistency, but for sake of flexibility in case we would like to introduce > > > > > more calls like clump16 or so. > > > > > > > > TBH, that doesn't convince me: those functions explicitly take/return an > > > > 8-bit value, and have "8" in their name. The 8-bit value is never > > > > really related to, retrieved from, or stored in a full "unsigned long" > > > > element of a bitmap, only to/from/in a part (byte) of it. > > > > > > > > Following your rationale, all of iowrite{8,16,32,64}*() should take an > > > > "unsigned long" value, too. > > > > > > > > > > +1 > > > > > > Using u8/u16/u32/u64 looks more consistent with other bitmap helpers. > > > > > > void bitmap_from_arr32(unsigned long *bitmap, const u32 *buf, unsigned > > > int nbits); > > > void bitmap_to_arr32(u32 *buf, const unsigned long *bitmap, unsigned int nbits); > > > static inline void bitmap_from_u64(unsigned long *dst, u64 mask); > > > > > > > > > > > > If you want to see more examples from other parts, > > > > Geert's and yours examples both are not related. They are about > > fixed-width properies when we know that is the part of protocol. > > Here we have no protocol which stricts us to the mentioned fixed-width types. > > Yes you have: they are functions to store/retrieve an 8-bit value from > the middle of the bitmap, which is reflected in their names ("clump8", > "value8"). > The input/output value is clearly separated from the actual bitmap, > which is referenced by the "unsigned long *". > > If you add new "value16" functions, they will be intended to store/retrieve > 16-bit values. And if I add 4-bit, 12-bit or 24-bit values, what should I use? > Besides, if retrieving an 8-bit value requires passing an > "unsigned long *", the caller needs two variables: one unsigned long to > pass the address of, and one u8 to copy the returned value into. Why do you need a temporary variable? In some cases it might make sense, but in general simple cases I don't see what you may achieve with it. I looked at bitmap.h and see few functions may have benefited of actually eliminating a use of long -> u8 -> long conversion. Here is the question what we are mostly doing after we got a clump out of bitmap. > > So, I can tell an opposite, your arguments didn't convince me. > > > > Imagine the function which does an or / and / xor operation on bitmap. > > Now, when I supply unsigned long, I will see > > operations on one type in _one_ function independently of the size. > > Your proposal will make an unneded churn. > > Depends on what kind of value you will use to do the logical operation > with the bitmap: > - Full bitmap => unsigned long * + size, > - Single bitmap "word" => unsigned long, > - 8-bit value => u8, > - 16-bit value => u16 -- With Best Regards, Andy Shevchenko