Skip to contentSkip to conversation

dm vdo: use kernel byteswapping routines instead of GCC ones

PATCH Superseded Matthew Sakai 3 participants 4 messages Mar 20, 2024 – Mar 21, 2024

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Matthew Sakai

author maintainer
#0 lore raw

PATCH 1/1 dm vdo: use kernel byteswapping routines instead of GCC ones

From: Ken Raeburn <[email protected]>

---
 drivers/md/dm-vdo/murmurhash3.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/md/dm-vdo/murmurhash3.c +4 -14
index 00c9b9c05001..124026cb676a 100644
@@ -8,6 +8,8 @@
 
 #include "murmurhash3.h"
 
+#include <asm/byteorder.h>
+
 static inline u64 rotl64(u64 x, s8 r)
 {
 	return (x << r) | (x >> (64 - r));
@@ -16,24 +18,12 @@ static inline u64 rotl64(u64 x, s8 r)
 #define ROTL64(x, y) rotl64(x, y)
 static __always_inline u64 getblock64(const u64 *p, int i)
 {
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-	return p[i];
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-	return __builtin_bswap64(p[i]);
-#else
-#error "can't figure out byte order"
-#endif
+	return le64_to_cpup(&p[i]);
 }
 
 static __always_inline void putblock64(u64 *p, int i, u64 value)
 {
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-	p[i] = value;
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-	p[i] = __builtin_bswap64(value);
-#else
-#error "can't figure out byte order"
-#endif
+	p[i] = cpu_to_le64(value);
 }
 
 /* Finalization mix - force all bits of a hash block to avalanche */
Signature · 1 line
2.42.0
Tested-by on v1 1/1
#1 lore raw
Quoted 5 lines · Matthew Sakai

From: Ken Raeburn <[email protected]>

Quoted 47 lines
---
 drivers/md/dm-vdo/murmurhash3.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
drivers/md/dm-vdo/murmurhash3.c +4 -14
index 00c9b9c05001..124026cb676a 100644
@@ -8,6 +8,8 @@
 
 #include "murmurhash3.h"
 
+#include <asm/byteorder.h>
+
 static inline u64 rotl64(u64 x, s8 r)
 {
 	return (x << r) | (x >> (64 - r));
@@ -16,24 +18,12 @@ static inline u64 rotl64(u64 x, s8 r)
 #define ROTL64(x, y) rotl64(x, y)
 static __always_inline u64 getblock64(const u64 *p, int i)
 {
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-	return p[i];
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-	return __builtin_bswap64(p[i]);
-#else
-#error "can't figure out byte order"
-#endif
+	return le64_to_cpup(&p[i]);
 }
 
 static __always_inline void putblock64(u64 *p, int i, u64 value)
 {
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-	p[i] = value;
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-	p[i] = __builtin_bswap64(value);
-#else
-#error "can't figure out byte order"
-#endif
+	p[i] = cpu_to_le64(value);
 }
 
 /* Finalization mix - force all bits of a hash block to avalanche */
Signature · 1 line
2.42.0
#2 lore raw
In reply to Matthew Sakai
Quoted 13 lines · Matthew Sakai

static __always_inline u64 getblock64(const u64 *p, int i) {

drivers/md/dm-vdo/murmurhash3.c +1 -7
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-	return p[i];
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-	return __builtin_bswap64(p[i]);
-#else
-#error "can't figure out byte order"
-#endif
+	return le64_to_cpup(&p[i]);
 }
 
 static __always_inline void putblock64(u64 *p, int i, u64 value)

drivers/md/dm-vdo/murmurhash3.c static inline u64 rotl64(u64 x, s8 r) · line 27

Quoted 10 lines
drivers/md/dm-vdo/murmurhash3.c +1 -7
 {
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-	p[i] = value;
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-	p[i] = __builtin_bswap64(value);
-#else
-#error "can't figure out byte order"
-#endif
+	p[i] = cpu_to_le64(value);
 }

This is very broken. What you're actually looking for is get_unaligned_le64() and put_unaligned_le64(). And they should be folded directly into the caller.

- Eric

author maintainer
#3 lore raw
Quoted 28 lines · Eric Biggers
Quoted 13 lines · Matthew Sakai
  static __always_inline u64 getblock64(const u64 *p, int i)
  {
drivers/md/dm-vdo/murmurhash3.c +1 -7
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-	return p[i];
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-	return __builtin_bswap64(p[i]);
-#else
-#error "can't figure out byte order"
-#endif
+	return le64_to_cpup(&p[i]);
  }
 
  static __always_inline void putblock64(u64 *p, int i, u64 value)

drivers/md/dm-vdo/murmurhash3.c static inline u64 rotl64(u64 x, s8 r) · line 27

Quoted 10 lines
drivers/md/dm-vdo/murmurhash3.c +1 -7
  {
-#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
-	p[i] = value;
-#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
-	p[i] = __builtin_bswap64(value);
-#else
-#error "can't figure out byte order"
-#endif
+	p[i] = cpu_to_le64(value);
  }

This is very broken. What you're actually looking for is get_unaligned_le64() and put_unaligned_le64(). And they should be folded directly into the caller.

Quoted 2 lines

- Eric

Thanks for the suggestion. We'll work on a v2 to include this.

Matt