mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Denis Orlov <denorl2009@gmail.com>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>,
	Denis Orlov <denorl2009@gmail.com>
Subject: [PATCH 2/3] include: bitops: allow BIT* macros to be used in assembly code
Date: Fri,  9 Jun 2023 07:54:08 +0300	[thread overview]
Message-ID: <20230609045829.2225-3-denorl2009@gmail.com> (raw)
In-Reply-To: <20230609045829.2225-1-denorl2009@gmail.com>

Use UL/ULL() macros for those so that corresponding suffixes only appear
when we are compiling C code. Hide all the other functions/macros that
we can't use in assembly with '#ifndef __ASSEMBLY__'.

Signed-off-by: Denis Orlov <denorl2009@gmail.com>
---
 include/linux/bitops.h | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/include/linux/bitops.h b/include/linux/bitops.h
index eb5ff37f2f..d9a5a81a9c 100644
--- a/include/linux/bitops.h
+++ b/include/linux/bitops.h
@@ -2,14 +2,16 @@
 
 #ifndef _LINUX_BITOPS_H
 #define _LINUX_BITOPS_H
+
 #include <linux/types.h>
+#include <linux/const.h>
 
 #ifdef	__KERNEL__
-#define BIT(nr)			(1UL << (nr))
-#define BIT_ULL(nr)		(1ULL << (nr))
-#define BIT_MASK(nr)		(1UL << ((nr) % BITS_PER_LONG))
+#define BIT(nr)			(UL(1) << (nr))
+#define BIT_ULL(nr)		(ULL(1) << (nr))
+#define BIT_MASK(nr)		(UL(1) << ((nr) % BITS_PER_LONG))
 #define BIT_WORD(nr)		((nr) / BITS_PER_LONG)
-#define BIT_ULL_MASK(nr)	(1ULL << ((nr) % BITS_PER_LONG_LONG))
+#define BIT_ULL_MASK(nr)	(ULL(1) << ((nr) % BITS_PER_LONG_LONG))
 #define BIT_ULL_WORD(nr)	((nr) / BITS_PER_LONG_LONG)
 #define BITS_PER_BYTE		8
 #define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_BYTE * sizeof(long))
@@ -21,11 +23,14 @@
  * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000.
  */
 #define GENMASK(h, l) \
-	(((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h))))
+	(((~UL(0)) - (UL(1) << (l)) + 1) & \
+	 (~UL(0) >> (BITS_PER_LONG - 1 - (h))))
 
 #define GENMASK_ULL(h, l) \
-	(((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h))))
+	(((~ULL(0)) - (ULL(1) << (l)) + 1) & \
+	 (~ULL(0) >> (BITS_PER_LONG_LONG - 1 - (h))))
 
+#ifndef __ASSEMBLY__
 /*
  * Include this here because some architectures need generic_ffs/fls in
  * scope
@@ -237,5 +242,6 @@ extern unsigned long find_last_bit(const unsigned long *addr,
 				   unsigned long size);
 #endif
 
+#endif /* !(__ASSEMBLY__) */
 #endif /* __KERNEL__ */
 #endif
-- 
2.41.0




  parent reply	other threads:[~2023-06-09  5:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09  4:54 [PATCH 0/3] include: bitops/const: partial update from Linux Denis Orlov
2023-06-09  4:54 ` [PATCH 1/3] include: const: make UL/ULL() macros commonly available Denis Orlov
2023-06-09  4:54 ` Denis Orlov [this message]
2023-06-09  4:54 ` [PATCH 3/3] include: bitops: import more BITS_TO_* defines from linux Denis Orlov
2023-06-09  6:30 ` [PATCH 0/3] include: bitops/const: partial update from Linux Sascha Hauer

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=20230609045829.2225-3-denorl2009@gmail.com \
    --to=denorl2009@gmail.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.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