diff options
author | 2015-09-18 10:33:52 -0400 | |
---|---|---|
committer | 2015-09-18 12:12:03 -0400 | |
commit | a4ce5ecbd09bf64c82f44d4cb57c003703800884 (patch) | |
tree | 677e6416385357eb65f78f990a1e63dfb376a107 /3rdparty/libflac/src | |
parent | 6b79dc22758f631d837bc3e9f873f56ade6b0baf (diff) |
Backport libflac endian patch from https://github.com/xiph/flac/commit/a5d1d4f0c520529c9c49bb3d2e82232144ca2f6d (nw)
Diffstat (limited to '3rdparty/libflac/src')
-rw-r--r-- | 3rdparty/libflac/src/libFLAC/bitreader.c | 52 | ||||
-rw-r--r-- | 3rdparty/libflac/src/libFLAC/bitwriter.c | 28 |
2 files changed, 4 insertions, 76 deletions
diff --git a/3rdparty/libflac/src/libFLAC/bitreader.c b/3rdparty/libflac/src/libFLAC/bitreader.c index e2a4ba3bd16..b48847d5e28 100644 --- a/3rdparty/libflac/src/libFLAC/bitreader.c +++ b/3rdparty/libflac/src/libFLAC/bitreader.c @@ -35,19 +35,11 @@ #include <stdlib.h> /* for malloc() */ #include <string.h> /* for memcpy(), memset() */ -#ifdef _MSC_VER -#include <winsock.h> /* for ntohl() */ -#elif defined FLAC__SYS_DARWIN -#include <machine/endian.h> /* for ntohl() */ -#elif defined __MINGW32__ -#include <winsock.h> /* for ntohl() */ -#else -#include <netinet/in.h> /* for ntohl() */ -#endif #include "private/bitmath.h" #include "private/bitreader.h" #include "private/crc.h" #include "FLAC/assert.h" +#include "share/endswap.h" /* Things should be fastest when this matches the machine word size */ /* WATCHOUT: if you change this you must also change the following #defines down to COUNT_ZERO_MSBS below to match */ @@ -61,11 +53,7 @@ typedef FLAC__uint32 brword; #if WORDS_BIGENDIAN #define SWAP_BE_WORD_TO_HOST(x) (x) #else -#ifdef _MSC_VER -#define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x) -#else -#define SWAP_BE_WORD_TO_HOST(x) ntohl(x) -#endif +#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x) #endif /* counts the # of zero MSBs in a word */ #define COUNT_ZERO_MSBS(word) ( \ @@ -149,35 +137,6 @@ struct FLAC__BitReader { FLAC__CPUInfo cpu_info; }; -#ifdef _MSC_VER -/* OPT: an MSVC built-in would be better */ -static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x) -{ - x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); - return (x>>16) | (x<<16); -} - -#if defined(_M_IX86) -static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len) -{ - __asm { - mov edx, start - mov ecx, len - test ecx, ecx -loop1: - jz done1 - mov eax, [edx] - bswap eax - mov [edx], eax - add edx, 4 - dec ecx - jmp short loop1 -done1: - } -} -#endif -#endif - static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word) { register unsigned crc = br->read_crc16; @@ -266,13 +225,6 @@ FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br) #if WORDS_BIGENDIAN #else end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD; -# if defined(_MSC_VER) && (FLAC__BYTES_PER_WORD == 4) && defined(_M_IX86) - if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) { - start = br->words; - local_swap32_block_(br->buffer + start, end - start); - } - else -# endif for(start = br->words; start < end; start++) br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]); #endif diff --git a/3rdparty/libflac/src/libFLAC/bitwriter.c b/3rdparty/libflac/src/libFLAC/bitwriter.c index 089ff872b59..441122ee883 100644 --- a/3rdparty/libflac/src/libFLAC/bitwriter.c +++ b/3rdparty/libflac/src/libFLAC/bitwriter.c @@ -35,22 +35,11 @@ #include <stdlib.h> /* for malloc() */ #include <string.h> /* for memcpy(), memset() */ -#ifdef _MSC_VER -#include <winsock.h> /* for ntohl() */ -#elif defined FLAC__SYS_DARWIN -#include <machine/endian.h> /* for ntohl() */ -#elif defined __MINGW32__ -#include <winsock.h> /* for ntohl() */ -#else -#include <netinet/in.h> /* for ntohl() */ -#endif -#if 0 /* UNUSED */ -#include "private/bitmath.h" -#endif #include "private/bitwriter.h" #include "private/crc.h" #include "FLAC/assert.h" #include "share/alloc.h" +#include "share/endswap.h" /* Things should be fastest when this matches the machine word size */ /* WATCHOUT: if you change this you must also change the following #defines down to SWAP_BE_WORD_TO_HOST below to match */ @@ -63,11 +52,7 @@ typedef FLAC__uint32 bwword; #if WORDS_BIGENDIAN #define SWAP_BE_WORD_TO_HOST(x) (x) #else -#ifdef _MSC_VER -#define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x) -#else -#define SWAP_BE_WORD_TO_HOST(x) ntohl(x) -#endif +#define SWAP_BE_WORD_TO_HOST(x) ENDSWAP_32(x) #endif /* @@ -107,15 +92,6 @@ struct FLAC__BitWriter { unsigned bits; /* # of used bits in accum */ }; -#ifdef _MSC_VER -/* OPT: an MSVC built-in would be better */ -static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x) -{ - x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); - return (x>>16) | (x<<16); -} -#endif - /* * WATCHOUT: The current implementation only grows the buffer. */ static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add) { |