From: Jani Nikula <jani.nikula@intel.com>
To: linux-kernel@vger.kernel.org
Cc: intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
jani.nikula@intel.com,
"Andrew Morton" <akpm@linux-foundation.org>,
"Christian König" <christian.koenig@amd.com>,
"David Gow" <davidgow@google.com>
Subject: [PATCH 1/4] log2: add helper __IS_POWER_OF_2()
Date: Thu, 30 Mar 2023 13:42:40 +0300 [thread overview]
Message-ID: <20230330104243.2120761-2-jani.nikula@intel.com> (raw)
In-Reply-To: <20230330104243.2120761-1-jani.nikula@intel.com>
Add a helper to avoid duplication in the subsequent changes.
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Christian König <christian.koenig@amd.com>
Cc: David Gow <davidgow@google.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
---
include/linux/log2.h | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/include/linux/log2.h b/include/linux/log2.h
index 9f30d087a128..19e773116ae3 100644
--- a/include/linux/log2.h
+++ b/include/linux/log2.h
@@ -33,6 +33,8 @@ int __ilog2_u64(u64 n)
}
#endif
+#define __IS_POWER_OF_2(n) ((n) != 0 && (((n) & ((n) - 1)) == 0))
+
/**
* is_power_of_2() - check if a value is a power of two
* @n: the value to check
@@ -44,7 +46,7 @@ int __ilog2_u64(u64 n)
static inline __attribute__((const))
bool is_power_of_2(unsigned long n)
{
- return (n != 0 && ((n & (n - 1)) == 0));
+ return __IS_POWER_OF_2(n);
}
/**
--
2.39.2
next prev parent reply other threads:[~2023-03-30 10:43 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-30 10:42 [PATCH 0/4] log2: make is_power_of_2() more generic Jani Nikula
2023-03-30 10:42 ` Jani Nikula [this message]
2023-03-30 10:42 ` [PATCH 2/4] log2: have is_power_of_2() support bigger types than unsigned long Jani Nikula
2023-03-30 10:42 ` [PATCH 3/4] log2: allow use of is_power_of_2() in constant expressions Jani Nikula
2023-03-30 10:42 ` [PATCH 4/4] drm/i915/reg: use is_power_of_2() from log2.h Jani Nikula
2023-03-30 10:59 ` [PATCH 0/4] log2: make is_power_of_2() more generic Christian König
2023-03-30 19:50 ` Andrew Morton
2023-03-30 21:53 ` David Laight
2023-03-30 22:18 ` Andrew Morton
2023-03-31 7:33 ` David Laight
2023-03-31 8:31 ` Jani Nikula
2023-04-05 15:27 ` Steven Price
2024-04-12 10:01 ` Jani Nikula
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230330104243.2120761-2-jani.nikula@intel.com \
--to=jani.nikula@intel.com \
--cc=akpm@linux-foundation.org \
--cc=christian.koenig@amd.com \
--cc=davidgow@google.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox