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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 037A0C001B0 for ; Mon, 17 Jul 2023 15:03:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229749AbjGQPDn (ORCPT ); Mon, 17 Jul 2023 11:03:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229739AbjGQPDl (ORCPT ); Mon, 17 Jul 2023 11:03:41 -0400 Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9715B9 for ; Mon, 17 Jul 2023 08:03:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1689606219; x=1721142219; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=zDv2lDctT5fbcckIC6WwWPCqBgFU1iff9oIJZnsJfSc=; b=IzmrrjzfMLUEzAf/Jl7IHpVGaWMb042XuY0CpH8w5RSzsFYDJF7ZHwkY BLdyi7tZj+JQGDkSU1EwppmUD24nyHvpUXW2trhuC2gKexvW3wm95Qc3m 2SqIZ1+THA//TLitwsLWNglM0/HWcCm2qxdOCV9UbvI2zXp71ch2arDPJ bJNB14BEr9iIzLbH+Iv+mV7PSov3BvS/qYFjB/+rrtgTLUgRBMaczvSE4 fVmktyPbPK74BW8IN/NTOaO8Vo9Q41xK/RM+BS2HvrnOBU9h+0NFO7lnF xQ5rSEbvU1bKGVTm9zfFTWRjlXMTSyALkAR4K/gabuGwb5ANZoNfWm7o7 A==; X-IronPort-AV: E=McAfee;i="6600,9927,10774"; a="363415142" X-IronPort-AV: E=Sophos;i="6.01,211,1684825200"; d="scan'208";a="363415142" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2023 08:03:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10774"; a="1053927770" X-IronPort-AV: E=Sophos;i="6.01,211,1684825200"; d="scan'208";a="1053927770" Received: from smile.fi.intel.com ([10.237.72.54]) by fmsmga005.fm.intel.com with ESMTP; 17 Jul 2023 08:03:34 -0700 Received: from andy by smile.fi.intel.com with local (Exim 4.96) (envelope-from ) id 1qLPl6-001zWM-29; Mon, 17 Jul 2023 18:03:32 +0300 Date: Mon, 17 Jul 2023 18:03:32 +0300 From: Andy Shevchenko To: Alexander Potapenko Cc: catalin.marinas@arm.com, will@kernel.org, pcc@google.com, andreyknvl@gmail.com, linux@rasmusvillemoes.dk, yury.norov@gmail.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, eugenis@google.com, syednwaris@gmail.com, william.gray@linaro.org, Arnd Bergmann Subject: Re: [PATCH v3 1/5] lib/bitmap: add bitmap_{set,get}_value() Message-ID: References: <20230717113709.328671-1-glider@google.com> <20230717113709.328671-2-glider@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jul 17, 2023 at 04:53:51PM +0200, Alexander Potapenko wrote: ... > > > I remember that this construction may bring horrible code on some architectures > > > with some version(s) of the compiler (*). > > > > Wow, even the trunk Clang and GCC seem to generate better code for > > your version of this line: https://godbolt.org/z/36Kqxhe6j > > Oh wait. > First, my Godbolt reproducer is incorrect, it is using sizeof(unsigned > long) instead of 8 * sizeof(unsigned long) for BITS_PER_LONG. Still slightly better. And note, that the same GENMASK() is used at the beginning of the function. Compiler actually might cache it. > > > To fix that I found an easy refactoring: > > > > > > map[index] &= ~(GENMASK(nbits, 0) << offset)); > > > > > Second, the line above should probably be: > map[index] &= ~(GENMASK(nbits - 1, 0) << offset)); > > , right? Yes. -- With Best Regards, Andy Shevchenko