Skip to contentSkip to conversation

introduce lower_32_bits() macro

PATCH In review Joerg Roedel 4 participants 8 messages Jul 25, 2008 – Jul 28, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 introduce lower_32_bits() macro

The file kernel.h contains the upper_32_bits macro. This patch adds the other part, the lower_32_bits macro. Its first use will be in the driver for AMD IOMMU.

---
 include/linux/kernel.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/kernel.h +6 -0
index f9cd7a5..6fd2977 100644
@@ -73,6 +73,12 @@ extern const char linux_proc_banner[];
  */
 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
 
+/**
+ * lower_32_bits - return bits 0-31 of a number
+ * @n: the number we're accessing
+ */
+#define lower_32_bits(n) ((n) & 0xffffffffULL)
+
 #define	KERN_EMERG	"<0>"	/* system is unusable			*/
 #define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
 #define	KERN_CRIT	"<2>"	/* critical conditions			*/
Signature · 1 line
1.5.3.7
#1 lore raw
Quoted 14 lines · Joerg Roedel

The file kernel.h contains the upper_32_bits macro. This patch adds the other part, the lower_32_bits macro. Its first use will be in the driver for AMD IOMMU.

---
 include/linux/kernel.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/kernel.h +0 -0
index f9cd7a5..6fd2977 100644

include/linux/kernel.h extern const char linux_proc_banner[]; · line 81

Quoted 9 lines
include/linux/kernel.h +6 -0
@@ -73,6 +73,12 @@ extern const char linux_proc_banner[];
  */
 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
 
+/**
+ * lower_32_bits - return bits 0-31 of a number
+ * @n: the number we're accessing
+ */
+#define lower_32_bits(n) ((n) & 0xffffffffULL)
+

NAK. These are assymmetric with regards to type, which is the *last* thing we want.

The symmetric definition would be ((u32)(n)), but that's already idiomatic use, so why not use it as-is?

-hpa

#2 lore raw
Quoted 18 lines · On Fri, 25 Jul 2008 12:06:27 -0400 "H. Peter Anvin" <[email protected]> wrote:
Quoted 17 lines · Joerg Roedel

The file kernel.h contains the upper_32_bits macro. This patch adds the other part, the lower_32_bits macro. Its first use will be in the driver for AMD IOMMU.

---
 include/linux/kernel.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/kernel.h +0 -0
index f9cd7a5..6fd2977 100644
@@ -73,6 +73,12 @@ extern const char linux_proc_banner[];
  */
 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
 
Quoted 9 lines

include/linux/kernel.h extern const char linux_proc_banner[]; · line 81

Quoted 6 lines
include/linux/kernel.h +6 -0
+/**
+ * lower_32_bits - return bits 0-31 of a number
+ * @n: the number we're accessing
+ */
+#define lower_32_bits(n) ((n) & 0xffffffffULL)
+

NAK. These are assymmetric with regards to type, which is the *last* thing we want.

Yes, it will convert a 32-bit expression into a 64-bit one.

Quoted 2 lines

The symmetric definition would be ((u32)(n)), but that's already idiomatic use, so why not use it as-is?

There's some readability benefit. Sometimes it is hard to understand why some random open-coded cast was used. But I seem to recall that there was another reason why we decided we needed this. I forget, and so apparently did the changelog author ;)

#3 lore raw
Quoted 4 lines

There's some readability benefit. Sometimes it is hard to understand why some random open-coded cast was used. But I seem to recall that there was another reason why we decided we needed this. I forget, and so apparently did the changelog author ;)

The guy who added the macro explained it in a comment ;)

* A basic shift-right of a 64- or 32-bit quantity. Use this to suppress
* the "right shift count >= width of type" warning when that quantity is
* 32-bits.

- R.

#4 lore raw
Quoted 10 lines · Roland Dreier
Quoted 4 lines

There's some readability benefit. Sometimes it is hard to understand why some random open-coded cast was used. But I seem to recall that there was another reason why we decided we needed this. I forget, and so apparently did the changelog author ;)

The guy who added the macro explained it in a comment ;)

* A basic shift-right of a 64- or 32-bit quantity. Use this to suppress
* the "right shift count >= width of type" warning when that quantity is
* 32-bits.

That was for upper_32_bits() -- and can also be done with an internal (u64) cast; it would be interesting to find out if that would generate better code.

-hpa

#5 lore raw
In reply to Andrew Morton
Quoted 11 lines · Andrew Morton
Quoted 10 lines

include/linux/kernel.h extern const char linux_proc_banner[]; · line 81

Quoted 9 lines

*/
#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))

include/linux/kernel.h +6 -0
+/**
+ * lower_32_bits - return bits 0-31 of a number
+ * @n: the number we're accessing
+ */
+#define lower_32_bits(n) ((n) & 0xffffffffULL)
+

NAK. These are assymmetric with regards to type, which is the *last* thing we want.

Quoted 2 lines

Yes, it will convert a 32-bit expression into a 64-bit one.

Sort of. upper_32_bits() takes a 32- or 64-bit expression, and delivers the upper 32 bits *as a 32-bit number*. An equivalent expression would be:

	((u32)((u64)(n) >> 32))

... which might actually produce better code, for all I know.

Logically speaking, if we have a lower_32_bits() macro, it should also produce a 32-bit type as result.

-hpa

#6 lore raw
In reply to H. Peter Anvin
Quoted 25 lines · H. Peter Anvin
Quoted 12 lines · Joerg Roedel

The file kernel.h contains the upper_32_bits macro. This patch adds the other part, the lower_32_bits macro. Its first use will be in the driver for AMD IOMMU.

---
include/linux/kernel.h | 6 ++++++

1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/kernel.h +0 -0
index f9cd7a5..6fd2977 100644

include/linux/kernel.h extern const char linux_proc_banner[]; · line 80

Quoted 8 lines
include/linux/kernel.h +6 -0
@@ -73,6 +73,12 @@ extern const char linux_proc_banner[];
 */
 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
+/**
+ * lower_32_bits - return bits 0-31 of a number
+ * @n: the number we're accessing
+ */
+#define lower_32_bits(n) ((n) & 0xffffffffULL)
+

NAK. These are assymmetric with regards to type, which is the *last* thing we want.

Quoted 2 lines

The symmetric definition would be ((u32)(n)), but that's already idiomatic use, so why not use it as-is?

Ok, true. Sorry for the broken patch. I will send an updated one.

Joerg

Signature · 6 lines
           |           AMD Saxony Limited Liability Company & Co. KG
 Operating |         Wilschdorfer Landstr. 101, 01109 Dresden, Germany
 System    |                  Register Court Dresden: HRA 4896
 Research  |              General Partner authorized to represent:
 Center    |             AMD Saxony LLC (Wilmington, Delaware, US)
           | General Manager of AMD Saxony LLC: Dr. Hans-R. Deppe, Thomas McCoy
#7 lore raw

PATCH 1/1 introduce lower_32_bits() macro

In reply to H. Peter Anvin

The file kernel.h contains the upper_32_bits macro. This patch adds the other part, the lower_32_bits macro. Its first use will be in the driver for AMD IOMMU.

Cc H. Peter Anvin <[email protected]>
---
 include/linux/kernel.h |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
include/linux/kernel.h +6 -0
index fdbbf72..aaa998f 100644
@@ -75,6 +75,12 @@ extern const char linux_proc_banner[];
  */
 #define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
 
+/**
+ * lower_32_bits - return bits 0-31 of a number
+ * @n: the number we're accessing
+ */
+#define lower_32_bits(n) ((u32)(n))
+
 #define	KERN_EMERG	"<0>"	/* system is unusable			*/
 #define	KERN_ALERT	"<1>"	/* action must be taken immediately	*/
 #define	KERN_CRIT	"<2>"	/* critical conditions			*/
Signature · 1 line
1.5.3.7