mirror of
https://git.ffmpeg.org/ffmpeg.git
synced 2024-12-23 07:42:51 +00:00
bswap: make generic implementation more compiler-friendly
With these changes, gcc 4.5 and later recognise it as a bswap and use the proper instructions on ARM and x86. On x86, the 16-bit bswap is recognised from gcc 4.1. Signed-off-by: Mans Rullgard <mans@mansr.com>
This commit is contained in:
parent
5695ae46f8
commit
f64c2e710f
@ -51,6 +51,7 @@ static av_always_inline av_const unsigned av_bswap16(unsigned x)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !AV_GCC_VERSION_AT_LEAST(4,5)
|
||||||
#define av_bswap32 av_bswap32
|
#define av_bswap32 av_bswap32
|
||||||
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
||||||
{
|
{
|
||||||
@ -66,6 +67,7 @@ static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
|||||||
#endif /* HAVE_ARMV6 */
|
#endif /* HAVE_ARMV6 */
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
#endif /* !AV_GCC_VERSION_AT_LEAST(4,5) */
|
||||||
|
|
||||||
#endif /* __ARMCC_VERSION */
|
#endif /* __ARMCC_VERSION */
|
||||||
|
|
||||||
|
@ -65,23 +65,14 @@ static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
|
|||||||
#ifndef av_bswap32
|
#ifndef av_bswap32
|
||||||
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
||||||
{
|
{
|
||||||
x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
|
return AV_BSWAP32C(x);
|
||||||
x= (x>>16) | (x<<16);
|
|
||||||
return x;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef av_bswap64
|
#ifndef av_bswap64
|
||||||
static inline uint64_t av_const av_bswap64(uint64_t x)
|
static inline uint64_t av_const av_bswap64(uint64_t x)
|
||||||
{
|
{
|
||||||
union {
|
return (uint64_t)av_bswap32(x) << 32 | av_bswap32(x >> 32);
|
||||||
uint64_t ll;
|
|
||||||
uint32_t l[2];
|
|
||||||
} w, r;
|
|
||||||
w.ll = x;
|
|
||||||
r.l[0] = av_bswap32 (w.l[1]);
|
|
||||||
r.l[1] = av_bswap32 (w.l[0]);
|
|
||||||
return r.ll;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -28,13 +28,16 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "libavutil/attributes.h"
|
#include "libavutil/attributes.h"
|
||||||
|
|
||||||
|
#if !AV_GCC_VERSION_AT_LEAST(4,1)
|
||||||
#define av_bswap16 av_bswap16
|
#define av_bswap16 av_bswap16
|
||||||
static av_always_inline av_const unsigned av_bswap16(unsigned x)
|
static av_always_inline av_const unsigned av_bswap16(unsigned x)
|
||||||
{
|
{
|
||||||
__asm__("rorw $8, %w0" : "+r"(x));
|
__asm__("rorw $8, %w0" : "+r"(x));
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
#endif /* !AV_GCC_VERSION_AT_LEAST(4,1) */
|
||||||
|
|
||||||
|
#if !AV_GCC_VERSION_AT_LEAST(4,5)
|
||||||
#define av_bswap32 av_bswap32
|
#define av_bswap32 av_bswap32
|
||||||
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
|
||||||
{
|
{
|
||||||
@ -57,5 +60,6 @@ static inline uint64_t av_const av_bswap64(uint64_t x)
|
|||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* !AV_GCC_VERSION_AT_LEAST(4,5) */
|
||||||
|
|
||||||
#endif /* AVUTIL_X86_BSWAP_H */
|
#endif /* AVUTIL_X86_BSWAP_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user