Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1655041pxb; Tue, 26 Oct 2021 13:08:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyeV574uOQAtMCSG0K6SxoLb2WNbG6wszzKIxVxQSk8GbYYgA5wfdZfwvdImUlZr0P+4XTX X-Received: by 2002:a17:907:3d8f:: with SMTP id he15mr32238574ejc.225.1635278926726; Tue, 26 Oct 2021 13:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635278926; cv=none; d=google.com; s=arc-20160816; b=tTp/vpoCvpA5DHP70FfZbrm2h115rzpUWfywXl/PaBL0vwgJLFy7FV+RBwgr74KwxP 5uiIefj6DlHVy/y7mct57nRSoQwuXDWuzpRD+qLaGOZiHm2wtZe2QDokOi/lWc/geeKt 4cA58WkDi+HdpNtM+kh4mUtWl4H89r/XUFKg0t+V1YVCLxCKeVHMGdLo9PuTkIc/GK/+ Mxu2Wg0EjgpkYqGxCX19g02MrKWmN1fskW4mlJKq6bMutIKL/xjGFbWa4ba3dvKaEzE7 uVwASIaTdNKmmTTQgo/1OdVEopNBq20X+E78vrfL8IpjTXMbzZbILxD9fbQpKiNn1w7+ +n6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=V9amYGegQJ8S7wpYJOaO0b9hJ0MAlXfb64mMet8FQ/Q=; b=IVz7N4oe9+u/77TnPz+D9qsPncpycu/EZaihqZaGWvB168AQ5sNDvulQCg0B1s4wn4 26qzkw+aRHd/pR5tPqDP1dabnTAPjfYd0G4BpNCGyc+vMmM5MpcZ/Ob3h55f4lU8fW+C V59HhfNUH+UfQL8jjtGk3+/KgHwus32WPDFnNRvgZQ/k8ot+yuha+o3VIhtorz8wqcpg OX9jctRhi8vtJRjzd3jKn9IxHUOXWD8z61j7kmijCYmY3XoIgUvc8w9MlAmGU+Uh+KqI 66xEhhppOvbjtOxuEP4OSo8dFlBD5ZPUlcKxgyWj33Nc4RL3i4jRpt6p+iONDKYpZTkh piYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcdkim header.b="aJEU3/GS"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id gt37si16634583ejc.454.2021.10.26.13.07.52; Tue, 26 Oct 2021 13:08:46 -0700 (PDT) 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=@quicinc.com header.s=qcdkim header.b="aJEU3/GS"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236844AbhJZOn5 (ORCPT + 99 others); Tue, 26 Oct 2021 10:43:57 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:58898 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235433AbhJZOnz (ORCPT ); Tue, 26 Oct 2021 10:43:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1635259291; x=1666795291; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=V9amYGegQJ8S7wpYJOaO0b9hJ0MAlXfb64mMet8FQ/Q=; b=aJEU3/GSW0r1EU2SvCfHmCYMasjZOB8/VNwldUzsL1afAYG+FLSfUIsA XW8cjyo18SJBwGH6F/53c6YQUwJychFOHVg9NyUX6sAorMGovIhB1DqI/ v7qwkdYvtk1TZtTHSsz2qbVVSx8+Ap6GLqJGbQSc1qcdm3OUs6do7oYFk 4=; Received: from ironmsg-lv-alpha.qualcomm.com ([10.47.202.13]) by alexa-out.qualcomm.com with ESMTP; 26 Oct 2021 07:41:31 -0700 X-QCInternal: smtphost Received: from nalasex01a.na.qualcomm.com ([10.47.209.196]) by ironmsg-lv-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Oct 2021 07:41:30 -0700 Received: from qian-HP-Z2-SFF-G5-Workstation.qualcomm.com (10.80.80.8) by nalasex01a.na.qualcomm.com (10.47.209.196) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.7; Tue, 26 Oct 2021 07:41:29 -0700 From: Qian Cai To: Yury Norov CC: Andy Shevchenko , Rasmus Villemoes , , Qian Cai Subject: [PATCH] bitmap: simplify GENMASK(size - 1, 0) lines Date: Tue, 26 Oct 2021 10:41:08 -0400 Message-ID: <20211026144108.35373-1-quic_qiancai@quicinc.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01a.na.qualcomm.com (10.47.209.196) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since "size" is an "unsigned int", the rvalue "size - 1" will still be "unsigned int" according to the C standard (3.2.1.5 Usual arithmetic conversions). Therefore, GENMASK(size - 1, 0) will always return 0UL. Those are also caught by GCC (W=2): ./include/linux/find.h: In function 'find_first_bit': ./include/linux/bits.h:25:22: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits] 25 | __is_constexpr((l) > (h)), (l) > (h), 0))) | ^ ./include/linux/build_bug.h:16:62: note: in definition of macro 'BUILD_BUG_ON_ZERO' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) | ^ ./include/linux/bits.h:25:3: note: in expansion of macro '__is_constexpr' 25 | __is_constexpr((l) > (h)), (l) > (h), 0))) | ^~~~~~~~~~~~~~ ./include/linux/bits.h:38:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 38 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) | ^~~~~~~~~~~~~~~~~~~ ./include/linux/find.h:119:31: note: in expansion of macro 'GENMASK' 119 | unsigned long val = *addr & GENMASK(size - 1, 0); | ^~~~~~~ ./include/linux/bits.h:25:34: warning: comparison of unsigned expression in '< 0' is always false [-Wtype-limits] 25 | __is_constexpr((l) > (h)), (l) > (h), 0))) | ^ ./include/linux/build_bug.h:16:62: note: in definition of macro 'BUILD_BUG_ON_ZERO' 16 | #define BUILD_BUG_ON_ZERO(e) ((int)(sizeof(struct { int:(-!!(e)); }))) | ^ ./include/linux/bits.h:38:3: note: in expansion of macro 'GENMASK_INPUT_CHECK' 38 | (GENMASK_INPUT_CHECK(h, l) + __GENMASK(h, l)) | ^~~~~~~~~~~~~~~~~~~ ./include/linux/find.h:119:31: note: in expansion of macro 'GENMASK' 119 | unsigned long val = *addr & GENMASK(size - 1, 0); | ^~~~~~~ Signed-off-by: Qian Cai --- include/linux/find.h | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/include/linux/find.h b/include/linux/find.h index 5bb6db213bcb..5ce2b17aea42 100644 --- a/include/linux/find.h +++ b/include/linux/find.h @@ -115,11 +115,8 @@ unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size, static inline unsigned long find_first_bit(const unsigned long *addr, unsigned long size) { - if (small_const_nbits(size)) { - unsigned long val = *addr & GENMASK(size - 1, 0); - - return val ? __ffs(val) : size; - } + if (small_const_nbits(size)) + return size; return _find_first_bit(addr, size); } @@ -140,11 +137,8 @@ unsigned long find_first_and_bit(const unsigned long *addr1, const unsigned long *addr2, unsigned long size) { - if (small_const_nbits(size)) { - unsigned long val = *addr1 & *addr2 & GENMASK(size - 1, 0); - - return val ? __ffs(val) : size; - } + if (small_const_nbits(size)) + return size; return _find_first_and_bit(addr1, addr2, size); } @@ -162,11 +156,8 @@ unsigned long find_first_and_bit(const unsigned long *addr1, static inline unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) { - if (small_const_nbits(size)) { - unsigned long val = *addr | ~GENMASK(size - 1, 0); - - return val == ~0UL ? size : ffz(val); - } + if (small_const_nbits(size)) + return size; return _find_first_zero_bit(addr, size); } @@ -183,11 +174,8 @@ unsigned long find_first_zero_bit(const unsigned long *addr, unsigned long size) static inline unsigned long find_last_bit(const unsigned long *addr, unsigned long size) { - if (small_const_nbits(size)) { - unsigned long val = *addr & GENMASK(size - 1, 0); - - return val ? __fls(val) : size; - } + if (small_const_nbits(size)) + return size; return _find_last_bit(addr, size); } -- 2.30.2