From 53cd7c7bf0a100d01fc31caf3c20987e66a9ed64 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Tue, 25 Apr 2017 12:51:17 -0700 Subject: bytesex: more endianness detection hacks A few more tricks for sussing out endinanness, and add an ultimate fallback option. Signed-off-by: H. Peter Anvin --- include/bytesex.h | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) (limited to 'include/bytesex.h') diff --git a/include/bytesex.h b/include/bytesex.h index 376bb6d6..ee20adff 100644 --- a/include/bytesex.h +++ b/include/bytesex.h @@ -223,8 +223,42 @@ static inline uint64_t cpu_to_le64(uint64_t v) #else /* not WORDS_LITTLEENDIAN or WORDS_BIGENDIAN */ -#error "Update byteord.h to include arbitrary byte orders" +static inline uint16_t cpu_to_le16(uint16_t v) +{ + union u16 { + uint16_t v; + uint8_t c[2]; + } x; + uint8_t *cp = &x.c; + + WRITESHORT(cp, v); + return x.v; +} + +static inline uint32_t cpu_to_le32(uint32_t v) +{ + union u32 { + uint32_t v; + uint8_t c[4]; + } x; + uint8_t *cp = &x.c; + + WRITELONG(cp, v); + return x.v; +} + +static inline uint64_t cpu_to_le64(uint64_t v) +{ + union u64 { + uint64_t v; + uint8_t c[8]; + } x; + uint8_t *cp = &x.c; + + WRITEDLONG(cp, v); + return x.v; +} #endif -#endif /* NASM_BYTEORD_H */ +#endif /* NASM_BYTESEX_H */ -- cgit v1.2.1