@@ -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 */
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(-)