aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/common.h
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2002-07-09 19:22:50 +0000
committerMichael Niedermayer <michaelni@gmx.at>2002-07-09 19:22:50 +0000
commitef5e74bbfdd8198e6e9eb082a299a77d401c5464 (patch)
tree02bcb56a0ae4797df62557ec8743789b3e60ff0f /libavcodec/common.h
parentdf595131bbb520ee7ec91d05467ee63e58d6d8e4 (diff)
downloadffmpeg-ef5e74bbfdd8198e6e9eb082a299a77d401c5464.tar.gz
c std doesnt like negative shifts -> use asm
Originally committed as revision 730 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/common.h')
-rw-r--r--libavcodec/common.h38
1 files changed, 26 insertions, 12 deletions
diff --git a/libavcodec/common.h b/libavcodec/common.h
index 3af4755c1c..61eee5f287 100644
--- a/libavcodec/common.h
+++ b/libavcodec/common.h
@@ -165,11 +165,25 @@ inline void dprintf(const char* fmt,...) {}
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#define MIN(a,b) ((a) > (b) ? (b) : (a))
-#if defined ARCH_X86 && (__GNUC__ != 3 || __GNUC_MINOR__ > 1)
-// inverse for shift optimization (gcc should do that ...)
-#define INV32(a) (-a)
+#ifdef ARCH_X86
+// avoid +32 for shift optimization (gcc should do that ...)
+static inline int32_t NEG_SSR32( int32_t a, int8_t s){
+ asm ("sarl %1, %0\n\t"
+ : "+r" (a)
+ : "ic" ((uint8_t)(-s))
+ );
+ return a;
+}
+static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
+ asm ("shrl %1, %0\n\t"
+ : "+r" (a)
+ : "ic" ((uint8_t)(-s))
+ );
+ return a;
+}
#else
-#define INV32(a) (32-a)
+#define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s)))
+#define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s)))
#endif
/* bit output */
@@ -530,10 +544,10 @@ for examples see get_bits, show_bits, skip_bits, get_vlc
# define LAST_SKIP_CACHE(name, gb, num) ;
# define SHOW_UBITS(name, gb, num)\
- (((uint32_t)name##_cache)>>INV32(num))
+ NEG_USR32(name##_cache, num)
# define SHOW_SBITS(name, gb, num)\
- (((int32_t)name##_cache)>>INV32(num))
+ NEG_SSR32(name##_cache, num)
# define GET_CACHE(name, gb)\
((uint32_t)name##_cache)
@@ -579,10 +593,10 @@ static inline int get_bits_count(GetBitContext *s){
# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
# define SHOW_UBITS(name, gb, num)\
- (((uint32_t)name##_cache)>>INV32(num))
+ NEG_USR32(name##_cache, num)
# define SHOW_SBITS(name, gb, num)\
- (((int32_t)name##_cache)>>INV32(num))
+ NEG_SSR32(name##_cache, num)
# define GET_CACHE(name, gb)\
((uint32_t)name##_cache)
@@ -610,7 +624,7 @@ static inline int get_bits_count(GetBitContext *s){
# define UPDATE_CACHE(name, gb)\
if(name##_bit_count > 0){\
const uint32_t next= be2me_32( *name##_buffer_ptr );\
- name##_cache0 |= next>>INV32(name##_bit_count);\
+ name##_cache0 |= NEG_USR32(next,name##_bit_count);\
name##_cache1 |= next<<name##_bit_count;\
name##_buffer_ptr++;\
name##_bit_count-= 32;\
@@ -627,7 +641,7 @@ static inline int get_bits_count(GetBitContext *s){
#else
# define SKIP_CACHE(name, gb, num)\
name##_cache0 <<= (num);\
- name##_cache0 |= name##_cache1 >>INV32(num);\
+ name##_cache0 |= NEG_USR32(name##_cache1,num);\
name##_cache1 <<= (num);
#endif
@@ -644,10 +658,10 @@ static inline int get_bits_count(GetBitContext *s){
# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num)
# define SHOW_UBITS(name, gb, num)\
- (((uint32_t)name##_cache0)>>INV32(num))
+ NEG_USR32(name##_cache0, num)
# define SHOW_SBITS(name, gb, num)\
- (((int32_t)name##_cache0)>>INV32(num))
+ NEG_SSR32(name##_cache0, num)
# define GET_CACHE(name, gb)\
(name##_cache0)