[PATCH RFC 09/10] tools: Add common infrastructure for byte swapping

From: H. Peter Anvin
Date: Tue Jun 10 2014 - 19:15:35 EST


Common selection infrastructure for picking the best byte swap method.

Signed-off-by: H. Peter Anvin <hpa@xxxxxxxxx>
---
tools/include/tools/unaligned/be_swap.h | 15 +++++++++++++++
tools/include/tools/unaligned/le_swap.h | 15 +++++++++++++++
2 files changed, 30 insertions(+)
create mode 100644 tools/include/tools/unaligned/be_swap.h
create mode 100644 tools/include/tools/unaligned/le_swap.h

diff --git a/tools/include/tools/unaligned/be_swap.h b/tools/include/tools/unaligned/be_swap.h
new file mode 100644
index 000000000000..f0effb8fc6ca
--- /dev/null
+++ b/tools/include/tools/unaligned/be_swap.h
@@ -0,0 +1,15 @@
+#ifndef TOOLS_BE_SWAP_H
+#define TOOLS_BE_SWAP_H
+
+#ifdef htole64
+/* Prefer the <endian.h> infrastructure if it exists */
+# include <tools/unaligned/be_endian.h>
+#elif TOOLS_UNALIGNED_GCC >= 0x040800
+/* This version of gcc is new enough to have __builtin_bswap*() */
+# include <tools/unaligned/be_bswap.h>
+#else
+/* This always works */
+# include <tools/unaligned/be_byteshift.h>
+#endif
+
+#endif /* TOOLS_BE_SWAP_H */
diff --git a/tools/include/tools/unaligned/le_swap.h b/tools/include/tools/unaligned/le_swap.h
new file mode 100644
index 000000000000..8952723c1dff
--- /dev/null
+++ b/tools/include/tools/unaligned/le_swap.h
@@ -0,0 +1,15 @@
+#ifndef TOOLS_LE_SWAP_H
+#define TOOLS_LE_SWAP_H
+
+#ifdef htobe64
+/* Prefer the <endian.h> infrastructure if it exists */
+# include <tools/unaligned/le_endian.h>
+#elif TOOLS_UNALIGNED_GCC >= 0x040800
+/* This version of gcc is new enough to have __builtin_bswap*() */
+# include <tools/unaligned/le_bswap.h>
+#else
+/* This always works */
+# include <tools/unaligned/le_byteshift.h>
+#endif
+
+#endif /* TOOLS_LE_SWAP_H */
--
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/