restored some libflac code omitted in initial commit allowing big-endian compilation without hacks (nw)

This commit is contained in:
Oliver Stöneberg 2014-03-06 12:52:23 +00:00
parent e451a22cfb
commit 2d66475bbe
2 changed files with 27 additions and 13 deletions

View File

@ -35,7 +35,15 @@
#include <stdlib.h> /* for malloc() */ #include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcpy(), memset() */ #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/bitmath.h"
#include "private/bitreader.h" #include "private/bitreader.h"
#include "private/crc.h" #include "private/crc.h"
@ -56,7 +64,7 @@ typedef FLAC__uint32 brword;
#ifdef _MSC_VER #ifdef _MSC_VER
#define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x) #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
#else #else
#define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x) #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
#endif #endif
#endif #endif
/* counts the # of zero MSBs in a word */ /* counts the # of zero MSBs in a word */
@ -141,17 +149,15 @@ struct FLAC__BitReader {
FLAC__CPUInfo cpu_info; FLAC__CPUInfo cpu_info;
}; };
#ifdef _MSC_VER
#if !WORDS_BIGENDIAN /* OPT: an MSVC built-in would be better */
static FLAC__uint32 local_swap32_(FLAC__uint32 x) static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
{ {
x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
return (x>>16) | (x<<16); return (x>>16) | (x<<16);
} }
#endif
#if defined(_MSC_VER) && defined(_M_IX86) #if defined(_M_IX86)
/* OPT: an MSVC built-in would be better */
static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len) static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
{ {
__asm { __asm {
@ -170,6 +176,7 @@ done1:
} }
} }
#endif #endif
#endif
static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word) static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
{ {

View File

@ -35,7 +35,15 @@
#include <stdlib.h> /* for malloc() */ #include <stdlib.h> /* for malloc() */
#include <string.h> /* for memcpy(), memset() */ #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 */ #if 0 /* UNUSED */
#include "private/bitmath.h" #include "private/bitmath.h"
#endif #endif
@ -58,7 +66,7 @@ typedef FLAC__uint32 bwword;
#ifdef _MSC_VER #ifdef _MSC_VER
#define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x) #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
#else #else
#define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x) #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
#endif #endif
#endif #endif
@ -99,10 +107,9 @@ struct FLAC__BitWriter {
unsigned bits; /* # of used bits in accum */ unsigned bits; /* # of used bits in accum */
}; };
#ifdef _MSC_VER
/* OPT: an MSVC built-in would be better */ /* OPT: an MSVC built-in would be better */
#if !WORDS_BIGENDIAN static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
static FLAC__uint32 local_swap32_(FLAC__uint32 x)
{ {
x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
return (x>>16) | (x<<16); return (x>>16) | (x<<16);