From mboxrd@z Thu Jan 1 00:00:00 1970 From: Andy Shevchenko Subject: Re: [PATCH v10 01/10] bitops: Introduce the for_each_set_clump8 macro Date: Fri, 22 Mar 2019 20:22:44 +0200 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 Return-path: Content-Disposition: inline In-Reply-To: <0e4d352418252d480dfc7d529604819f8ff88d9c.1552566113.git.vilhelm.gray@gmail.com> Sender: linux-kernel-owner@vger.kernel.org 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 List-Id: linux-gpio@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 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 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS, URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1586C43381 for ; Fri, 22 Mar 2019 18:23:01 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A68BD21917 for ; Fri, 22 Mar 2019 18:23:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bLwPXefJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A68BD21917 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject: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=3671vZkmTVn1NwN3eVNd1NZgSIUWKfG1NFk+l+yhbOY=; b=bLwPXefJiKBf+F SK6x1HtUyvzL0xqGgJb0ZPzihFkh1YN6NAvUZJWSsMSuF4sWL/7UCMuVtTAgAxGliLUHS89aB7FtO oQ6B0V7gujpohxnCFP60VXsbKlTC7kIxqQ4pMnbagO9AM6envhF5D2+8oVxlhcy6wnTK8UA1O/4Bm lnaoUGCpRUay8We2PI/3Iuj/ITK227pMnZDRg+auT3zHYqi0bGaba4+ZGNhOrb7IqCGf+VXrvkaJ6 +oppq3BI0oebUZsdD+C+iVaMxfd/YOVaex0x9f95hQXjjeJUq28NEkg4dVTjQdOHojOpgIzDE692e orF+T6ihyi/G0c28sCLw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1h7Oog-0008QQ-Jq; Fri, 22 Mar 2019 18:22:54 +0000 Received: from mga07.intel.com ([134.134.136.100]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1h7Ooc-0008Ph-K3 for linux-arm-kernel@lists.infradead.org; Fri, 22 Mar 2019 18:22:52 +0000 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga105.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 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-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) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190322_112250_717512_28875DD6 X-CRM114-Status: GOOD ( 13.32 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Arnd Bergmann , yamada.masahiro@socionext.com, linus.walleij@linaro.org, linux@rasmusvillemoes.dk, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, akpm@linux-foundation.org, linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.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 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel