Skip to contentSkip to conversation

vmxnet: Don't use bswap_64 for constants

PATCH In review Richard Henderson 3 participants 4 messages Mar 27, 2013 – Mar 28, 2013

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmxnet: Don't use bswap_64 for constants

This macro is used in the context of defining enum values. We can't use a function call in that case.

---
 hw/vmxnet3.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/vmxnet3.h +9 -1
index 7db0c8f..cd9ac85 100644
@@ -37,7 +37,15 @@
 #define __packed QEMU_PACKED
 
 #if defined(HOST_WORDS_BIGENDIAN)
-#define const_cpu_to_le64(x) bswap_64(x)
+#define const_cpu_to_le64(x) \
+        (((x & 0x00000000000000ffULL) << 56) | \
+         ((x & 0x000000000000ff00ULL) << 40) | \
+         ((x & 0x0000000000ff0000ULL) << 24) | \
+         ((x & 0x00000000ff000000ULL) <<  8) | \
+         ((x & 0x000000ff00000000ULL) >>  8) | \
+         ((x & 0x0000ff0000000000ULL) >> 24) | \
+         ((x & 0x00ff000000000000ULL) >> 40) | \
+         ((x & 0xff00000000000000ULL) >> 56))
 #define __BIG_ENDIAN_BITFIELD
 #else
 #define const_cpu_to_le64(x) (x)
Signature · 1 line
1.8.1.4
#1 lore raw

Am 27.03.2013 19:47, schrieb Richard Henderson:

Quoted 17 lines

This macro is used in the context of defining enum values. We can't use a function call in that case.

---
 hw/vmxnet3.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/vmxnet3.h +0 -0
index 7db0c8f..cd9ac85 100644
@@ -37,7 +37,15 @@
 #define __packed QEMU_PACKED
 
 #if defined(HOST_WORDS_BIGENDIAN)

hw/vmxnet3.h line 48

Quoted 10 lines
hw/vmxnet3.h +9 -1
-#define const_cpu_to_le64(x) bswap_64(x)
+#define const_cpu_to_le64(x) \
+        (((x & 0x00000000000000ffULL) << 56) | \
+         ((x & 0x000000000000ff00ULL) << 40) | \
+         ((x & 0x0000000000ff0000ULL) << 24) | \
+         ((x & 0x00000000ff000000ULL) <<  8) | \
+         ((x & 0x000000ff00000000ULL) >>  8) | \
+         ((x & 0x0000ff0000000000ULL) >> 24) | \
+         ((x & 0x00ff000000000000ULL) >> 40) | \
+         ((x & 0xff00000000000000ULL) >> 56))

Being a macro, shouldn't this better use (x) for operator precedence?

Andreas

Quoted 4 lines
hw/vmxnet3.h +0 -0
 #define __BIG_ENDIAN_BITFIELD
 #else
 #define const_cpu_to_le64(x) (x)
Signature · 2 lines
SUSE LINUX Products GmbH, Maxfeldstr. 5, 90409 Nürnberg, Germany
GF: Jeff Hawn, Jennifer Guild, Felix Imendörffer; HRB 16746 AG Nürnberg
#2 lore raw
Quoted 17 lines · Andreas Färber

Am 27.03.2013 19:47, schrieb Richard Henderson:

Quoted 16 lines

This macro is used in the context of defining enum values. We can't use a function call in that case.

---
  hw/vmxnet3.h | 10 +++++++++-
  1 file changed, 9 insertions(+), 1 deletion(-)
hw/vmxnet3.h +0 -0
index 7db0c8f..cd9ac85 100644
@@ -37,7 +37,15 @@
  #define __packed QEMU_PACKED
 
Quoted 13 lines

hw/vmxnet3.h line 48

Quoted 11 lines
hw/vmxnet3.h +9 -1
  #if defined(HOST_WORDS_BIGENDIAN)
-#define const_cpu_to_le64(x) bswap_64(x)
+#define const_cpu_to_le64(x) \
+        (((x & 0x00000000000000ffULL) << 56) | \
+         ((x & 0x000000000000ff00ULL) << 40) | \
+         ((x & 0x0000000000ff0000ULL) << 24) | \
+         ((x & 0x00000000ff000000ULL) <<  8) | \
+         ((x & 0x000000ff00000000ULL) >>  8) | \
+         ((x & 0x0000ff0000000000ULL) >> 24) | \
+         ((x & 0x00ff000000000000ULL) >> 40) | \
+         ((x & 0xff00000000000000ULL) >> 56))

Being a macro, shouldn't this better use (x) for operator precedence?

It doesn't matter for this usage.

Nor, according to other threads that appeared on the list today, is this the right fix, since the bswap itself turns out to be bogus.

Myself, I never tested the driver code, just fixed the compile error.

r~

#3 lore raw
Quoted 32 lines · Richard Henderson
Quoted 17 lines · Andreas Färber

Am 27.03.2013 19:47, schrieb Richard Henderson:

Quoted 16 lines

This macro is used in the context of defining enum values. We can't use a function call in that case.

---
 hw/vmxnet3.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
hw/vmxnet3.h +0 -0
index 7db0c8f..cd9ac85 100644
@@ -37,7 +37,15 @@
 #define __packed QEMU_PACKED
 
Quoted 13 lines

hw/vmxnet3.h line 48

Quoted 11 lines
hw/vmxnet3.h +9 -1
 #if defined(HOST_WORDS_BIGENDIAN)
-#define const_cpu_to_le64(x) bswap_64(x)
+#define const_cpu_to_le64(x) \
+        (((x & 0x00000000000000ffULL) << 56) | \
+         ((x & 0x000000000000ff00ULL) << 40) | \
+         ((x & 0x0000000000ff0000ULL) << 24) | \
+         ((x & 0x00000000ff000000ULL) <<  8) | \
+         ((x & 0x000000ff00000000ULL) >>  8) | \
+         ((x & 0x0000ff0000000000ULL) >> 24) | \
+         ((x & 0x00ff000000000000ULL) >> 40) | \
+         ((x & 0xff00000000000000ULL) >> 56))

Being a macro, shouldn't this better use (x) for operator precedence?

Quoted 4 lines

It doesn't matter for this usage.

Nor, according to other threads that appeared on the list today, is this the right fix, since the bswap itself turns out to be bogus.

Dmitry said he's sending a fix, will wait for that.

Stefan