Commit 993381a2 authored by Sam Hocevar's avatar Sam Hocevar

 . moved swab32 from input_ext-dec.h to common.h. We probably won't need
   it anymore really soon, since ntohl() and htonl() seem to be properly
   optimized when gcc is passed the right optimization flags.

 . fixed GetBits32 and RemoveBits32. I know the #ifdefs are useless since
   we only support u32 words, but it's a safe reminder. Comments appreciated
   on this fix since I may have b0rked something -- it runs well here though.
parent bf10480d
......@@ -3,7 +3,7 @@
* Collection of useful common types and macros definitions
*****************************************************************************
* Copyright (C) 1998, 1999, 2000 VideoLAN
* $Id: common.h,v 1.22 2001/01/09 21:03:47 sam Exp $
* $Id: common.h,v 1.23 2001/01/11 15:35:35 sam Exp $
*
* Authors: Samuel Hocevar <sam@via.ecp.fr>
* Vincent Seguin <seguin@via.ecp.fr>
......@@ -145,6 +145,31 @@ typedef struct video_parser_s * p_video_parser_t;
#define MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
#endif
/*
* This is stolen from the livid source who stole it from the kernel
*/
#if defined(SYS_BEOS)
# define swab32(x) B_BENDIAN_TO_HOST_INT32(x)
#else
# ifdef WORDS_BIG_ENDIAN
# define swab32(x) (x)
# else
# if defined (HAVE_X86_BSWAP)
static __inline__ const u32 __i386_swab32( u32 x )
{
__asm__("bswap %0" : "=r" (x) : "0" (x));
return x;
}
# define swab32(x) __i386_swab32(x)
# else
# define swab32(x) \
( ( (u32)(((u8*)&x)[0]) << 24 ) | ( (u32)(((u8*)&x)[1]) << 16 ) |\
( (u32)(((u8*)&x)[2]) << 8 ) | ( (u32)(((u8*)&x)[3])) )
# endif
# endif
#endif
/* MSB (big endian)/LSB (little endian) conversions - network order is always
* MSB, and should be used for both network communications and files. Note that
* byte orders other than little and big endians are not supported, but only
......@@ -169,5 +194,6 @@ typedef struct video_parser_s * p_video_parser_t;
#endif
/* Macros with automatic casts */
#define U32_AT(p) ( ntohl ( *( (u32 *)(p) ) ) )
#define U32_AT(p) ( swab32 ( *( (u32 *)(p) ) ) )
#define U16_AT(p) ( ntohs ( *( (u16 *)(p) ) ) )
......@@ -2,7 +2,7 @@
* input_ext-dec.h: structures exported to the VideoLAN decoders
*****************************************************************************
* Copyright (C) 1999, 2000 VideoLAN
* $Id: input_ext-dec.h,v 1.10 2001/01/10 19:22:10 massiot Exp $
* $Id: input_ext-dec.h,v 1.11 2001/01/11 15:35:35 sam Exp $
*
* Authors:
*
......@@ -242,33 +242,6 @@ static __inline__ void DumpBits( bit_stream_t * p_bit_stream, int i_bits )
# error Not supported word
#endif
/*
* This is stolen from the livid source who stole it from the kernel
* FIXME: The macro swab32 for little endian machines does
* not seem to work correctly
*/
#if defined(SYS_BEOS)
# define swab32(x) B_BENDIAN_TO_HOST_INT32(x)
#else
# ifdef WORDS_BIG_ENDIAN
# define swab32(x) (x)
# else
# if defined (HAVE_X86_BSWAP)
static __inline__ const u32 __i386_swab32( u32 x )
{
__asm__("bswap %0" : "=r" (x) : "0" (x));
return x;
}
# define swab32(x) __i386_swab32(x)
# else
# define swab32(x) \
( ( (u32)(((u8*)&x)[0]) << 24 ) | ( (u32)(((u8*)&x)[1]) << 16 ) |\
( (u32)(((u8*)&x)[2]) << 8 ) | ( (u32)(((u8*)&x)[3])) )
# endif
# endif
#endif
/*****************************************************************************
* ShowBits : return i_bits bits from the bit stream
*****************************************************************************/
......@@ -313,6 +286,7 @@ static __inline__ WORD_TYPE GetWord( bit_stream_t * p_bit_stream )
/*****************************************************************************
* RemoveBits : removes i_bits bits from the bit buffer
* XXX: do not use for 32 bits, see RemoveBits32
*****************************************************************************/
static __inline__ void RemoveBits( bit_stream_t * p_bit_stream, int i_bits )
{
......@@ -330,17 +304,31 @@ static __inline__ void RemoveBits( bit_stream_t * p_bit_stream, int i_bits )
/*****************************************************************************
* RemoveBits32 : removes 32 bits from the bit buffer (and as a side effect,
* refill it). This should be faster than RemoveBits, though
* RemoveBits will work, too.
* refill it)
*****************************************************************************/
static __inline__ void RemoveBits32( bit_stream_t * p_bit_stream )
{
#if (WORD_TYPE == u32)
/* If we are word aligned, do not touch the buffer */
if( p_bit_stream->fifo.i_available == 0 )
{
if( p_bit_stream->p_byte > p_bit_stream->p_end - sizeof(WORD_TYPE) )
{
p_bit_stream->pf_next_data_packet( p_bit_stream );
}
((WORD_TYPE *)p_bit_stream->p_byte)++;
return;
}
#endif
p_bit_stream->fifo.buffer = GetWord( p_bit_stream )
<< (32 - p_bit_stream->fifo.i_available);
}
/*****************************************************************************
* GetBits : returns i_bits bits from the bit stream and removes them
* XXX: do not use for 32 bits, see GetBits32
*****************************************************************************/
static __inline__ WORD_TYPE GetBits( bit_stream_t * p_bit_stream, int i_bits )
{
......@@ -372,13 +360,21 @@ static __inline__ WORD_TYPE GetBits32( bit_stream_t * p_bit_stream )
{
WORD_TYPE i_result;
#if (WORD_TYPE == u32)
/* If we are word aligned, do not touch the buffer */
if( p_bit_stream->fifo.i_available == 0 )
{
return( GetWord( p_bit_stream ) );
}
#endif
i_result = p_bit_stream->fifo.buffer;
p_bit_stream->fifo.buffer = GetWord( p_bit_stream );
i_result |= p_bit_stream->fifo.buffer
>> (p_bit_stream->fifo.i_available);
p_bit_stream->fifo.buffer <<= (8 * sizeof(WORD_TYPE)
- p_bit_stream->fifo.i_available);
return( i_result );
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment