diff mbox

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

Message ID 1402441994-16780-10-git-send-email-hpa@zytor.com (mailing list archive)
State New, archived
Headers show

Commit Message

H. Peter Anvin June 10, 2014, 11:13 p.m. UTC
Common selection infrastructure for picking the best byte swap method.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 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 mbox

Patch

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 */