endian_inl.h: implement htoleXX with BSwapXX

+ s/htole(16|32)/HToLE$1/ to avoid any name conflicts

Change-Id: Ic1c84711557e50f73d83ca5aa2b3992ac6738216
This commit is contained in:
James Zern 2014-07-04 00:50:34 -07:00
parent f2664d1aab
commit e458badcc3
2 changed files with 9 additions and 30 deletions

View File

@ -72,11 +72,11 @@ static WEBP_INLINE size_t VP8BitWriterSize(const VP8BitWriter* const bw) {
#if defined(__x86_64__) || defined(_M_X64) // 64bit
typedef uint64_t vp8l_atype_t; // accumulator type
typedef uint32_t vp8l_wtype_t; // writing type
#define WSWAP htole32
#define WSWAP HToLE32
#else
typedef uint32_t vp8l_atype_t;
typedef uint16_t vp8l_wtype_t;
#define WSWAP htole16
#define WSWAP HToLE16
#endif
typedef struct {

View File

@ -20,38 +20,17 @@
// some endian fix (e.g.: mips-gcc doesn't define __BIG_ENDIAN__)
#if !defined(WORDS_BIGENDIAN) && \
(defined(__BIG_ENDIAN__) || \
(defined(__BIG_ENDIAN__) || defined(_M_PPC) || \
(defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)))
#define WORDS_BIGENDIAN
#endif
// endian-specific htoleXX() definition
// TODO(skal): add a test for htoleXX() in endian.h and others in autoconf or
// remove it and replace with a generic implementation.
#if defined(_WIN32)
#if !defined(_M_PPC)
#define htole32(x) (x)
#define htole16(x) (x)
#else // PPC is BIG_ENDIAN
#include <stdlib.h>
#define htole32(x) (_byteswap_ulong((unsigned long)(x)))
#define htole16(x) (_byteswap_ushort((unsigned short)(x)))
#endif // _M_PPC
#elif defined(__OpenBSD__) || defined(__NetBSD__) || defined(__FreeBSD__) || \
defined(__DragonFly__)
#include <sys/endian.h>
#elif defined(__APPLE__)
#include <libkern/OSByteOrder.h>
#define htole32 OSSwapHostToLittleInt32
#define htole16 OSSwapHostToLittleInt16
#elif defined(__native_client__) && !defined(__GLIBC__)
// NaCl without glibc is assumed to be little-endian
#define htole32(x) (x)
#define htole16(x) (x)
#elif defined(__QNX__)
#include <net/netbyte.h>
#else // pretty much all linux and/or glibc
#include <endian.h>
#if defined(WORDS_BIGENDIAN)
#define HToLE32 BSwap32
#define HToLE16 BSwap16
#else
#define HToLE32(x) (x)
#define HToLE16(x) (x)
#endif
// gcc 4.3 has builtin functions for swap32/swap64