Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp919312img; Fri, 22 Mar 2019 11:23:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqytda8J0aSzFeM9EHsUmbrEfWkEBwH4vhLK3u7br0GRsENy5I4w1whflsS2xLEpNlFqlsKQ X-Received: by 2002:a63:42c4:: with SMTP id p187mr9725688pga.219.1553279024479; Fri, 22 Mar 2019 11:23:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553279024; cv=none; d=google.com; s=arc-20160816; b=D/2nBYFfAFGrIub6Toz1BPseZBlxjaoE7H1TlPP5KBP51muddrJr+i3KbQY6bwO9VH lQ3jfBtc8Sk+rgtzti3B/z+PLIDdUpyU65DFcxDHOA4PA3BUKLXyMI214OP3RqCE66sg JbYCNNYq4fDDqaxK1WiTiIGND3Dk5LR7UojM8b18CE5tnZXEwdG+6UlQ1m/GAvnu7B56 xtkny2C68yM7Eia5cwxi3y934B5ibIjQXlhsl2hSAJuG8Zqm6MAiri3ihMgb3CFWI/64 SrEpMRg6huZiGbYBBP86EEdwAJPlaACK5wi9zjbLzufeIBI/3phZDcgSAj6MgQN6zDHr OvTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:organization:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=DbEXBJ++33tUIScXKgiKc6bBjJa5W1T1GRYlwHHYRSo=; b=mu3709dKOUdiPgaYMtqKkuv2UPNgc0LSP5W3Pmi8IQ+acCQcT6Cg46chIeukb5rv+0 zwpxXuEE88MY7jlN+2EeINXn5YwWz6gmIuJF0yMrMK2gE/+k4sKcMG+CO9YEHD37drV/ KZyd+wHe/fZtTuw4lnNfWYdAZs6cPl13jxxGms1kgLyRVA5tIYij/tvGSBbL/eIx2hEW 5ZMyW7HTeApSbS/Qbk7QvW403Yo/fs1wd41Fo6da2iHat7+tw7dmMdfVAw1PEdVWvnxI C+eI5rD3T2TZBUoVHy0kWsBjf8vF5Q2m4uIJhSWOkLjXg3ib5XTlF3zWnttFKbRCfEPj dZ+w== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s61si7926330plb.305.2019.03.22.11.23.27; Fri, 22 Mar 2019 11:23:44 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727117AbfCVSWu (ORCPT + 99 others); Fri, 22 Mar 2019 14:22:50 -0400 Received: from mga06.intel.com ([134.134.136.31]:1681 "EHLO mga06.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726875AbfCVSWt (ORCPT ); Fri, 22 Mar 2019 14:22:49 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Mar 2019 11:22:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.60,256,1549958400"; d="scan'208";a="331109085" Received: from smile.fi.intel.com (HELO smile) ([10.237.72.86]) by fmsmga005.fm.intel.com with ESMTP; 22 Mar 2019 11:22:45 -0700 Received: from andy by smile with local (Exim 4.92) (envelope-from ) id 1h7OoW-0005Wr-F7; Fri, 22 Mar 2019 20:22:44 +0200 Date: Fri, 22 Mar 2019 20:22:44 +0200 From: Andy Shevchenko To: William Breathitt Gray Cc: linus.walleij@linaro.org, akpm@linux-foundation.org, linux-gpio@vger.kernel.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux@rasmusvillemoes.dk, yamada.masahiro@socionext.com, bgolaszewski@baylibre.com, linux-arm-kernel@lists.infradead.org, Arnd Bergmann Subject: Re: [PATCH v10 01/10] bitops: Introduce the for_each_set_clump8 macro Message-ID: <20190322182244.GZ9224@smile.fi.intel.com> References: <0e4d352418252d480dfc7d529604819f8ff88d9c.1552566113.git.vilhelm.gray@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0e4d352418252d480dfc7d529604819f8ff88d9c.1552566113.git.vilhelm.gray@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 14, 2019 at 09:30:02PM +0900, 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. > +void bitmap_set_value8(unsigned long *const bitmap, const unsigned int size, > + const unsigned long value, const unsigned int start) > +{ > + const size_t index = BIT_WORD(start); > + const unsigned int offset = start % BITS_PER_LONG; > + const unsigned int low_width = (offset + 8 > BITS_PER_LONG) ? > + BITS_PER_LONG - offset : 8; > + const unsigned long low_mask = GENMASK(offset + low_width - 1, offset); I think unsigned long low_mask = GENMASK(low_width - 1, 0) << offset; will generate better code. > + const unsigned int high_width = 8 - low_width; > + const unsigned long high_mask = GENMASK(high_width - 1, 0); > + > + /* set lower portion */ > + bitmap[index] &= ~low_mask; > + bitmap[index] |= value << offset; > + > + /* set higher portion if space available in bitmap */ > + if (high_width && start + 8 <= size) { > + bitmap[index + 1] &= ~high_mask; > + bitmap[index + 1] |= value >> low_width; > + } > +} > +EXPORT_SYMBOL(bitmap_set_value8); -- With Best Regards, Andy Shevchenko