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@xxxxxxxxx> --- tools/include/tools/unaligned.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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 */ -- 1.9.3 -- To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html