diff mbox

[RFC,10/10] tools: Use reasonable defaults for the default access

Message ID 1402441994-16780-11-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
By default, as long as we are using gcc, use struct access for the
native byte order and byte swap it for the reverse byte order.  This
works well on most gcc targets.  If we are not compiling with gcc,
then we cannot assume that struct access is safe, and so fall back to
the most generic portable form ([bl]e_byteshift.h).

However, there are some architectures on which this generates poor
code even with gcc, and so some architectures may want to implement
specific overrides in this header file.

Signed-off-by: H. Peter Anvin <hpa@zytor.com>
---
 tools/include/tools/unaligned.h | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/tools/include/tools/unaligned.h b/tools/include/tools/unaligned.h
index a3d43989bd25..1ef19a1ca9b4 100644
--- a/tools/include/tools/unaligned.h
+++ b/tools/include/tools/unaligned.h
@@ -30,7 +30,21 @@  struct _packed_u64_struct {
 
 #endif /* __GNUC__ */
 
-#include <tools/unaligned/le_byteshift.h>
-#include <tools/unaligned/be_byteshift.h>
+#if defined(__GNUC__) && (__BYTE_ORDER == __LITTLE_ENDIAN)
+
+# include <tools/unaligned/le_struct.h>
+# include <tools/unaligned/be_swap.h>
+
+#elif defined(__GNUC__) && (__BYTE_ORDER == __BIG_ENDIAN)
+
+# include <tools/unaligned/be_struct.h>
+# include <tools/unaligned/le_swap.h>
+
+#else /* No idea what we actually are dealing with */
+
+# include <tools/unaligned/be_byteshift.h>
+# include <tools/unaligned/le_byteshift.h>
+
+#endif
 
 #endif /* TOOLS_UNALIGNED_H */