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 #if defined(__x86_64__) || defined(_M_X64) // 64bit
typedef uint64_t vp8l_atype_t; // accumulator type typedef uint64_t vp8l_atype_t; // accumulator type
typedef uint32_t vp8l_wtype_t; // writing type typedef uint32_t vp8l_wtype_t; // writing type
#define WSWAP htole32 #define WSWAP HToLE32
#else #else
typedef uint32_t vp8l_atype_t; typedef uint32_t vp8l_atype_t;
typedef uint16_t vp8l_wtype_t; typedef uint16_t vp8l_wtype_t;
#define WSWAP htole16 #define WSWAP HToLE16
#endif #endif
typedef struct { typedef struct {

View File

@ -20,38 +20,17 @@
// some endian fix (e.g.: mips-gcc doesn't define __BIG_ENDIAN__) // some endian fix (e.g.: mips-gcc doesn't define __BIG_ENDIAN__)
#if !defined(WORDS_BIGENDIAN) && \ #if !defined(WORDS_BIGENDIAN) && \
(defined(__BIG_ENDIAN__) || \ (defined(__BIG_ENDIAN__) || defined(_M_PPC) || \
(defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__))) (defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)))
#define WORDS_BIGENDIAN #define WORDS_BIGENDIAN
#endif #endif
// endian-specific htoleXX() definition #if defined(WORDS_BIGENDIAN)
// TODO(skal): add a test for htoleXX() in endian.h and others in autoconf or #define HToLE32 BSwap32
// remove it and replace with a generic implementation. #define HToLE16 BSwap16
#if defined(_WIN32) #else
#if !defined(_M_PPC) #define HToLE32(x) (x)
#define htole32(x) (x) #define HToLE16(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>
#endif #endif
// gcc 4.3 has builtin functions for swap32/swap64 // gcc 4.3 has builtin functions for swap32/swap64