History

avcodec/x86/mathops: clip constants used with shift instructions within inline assembly

Fixes assembling with binutil as >= 2.41

Rémi Denis-Courmont committed 3 years ago

Commit effadce1 parent ccc68491 file · +23 −3Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/x86/mathops.h+23−3
@@ -35,12 +35,20 @@ · 34 unmodified lines
3535 static av_always_inline av_const int MULL(int a, int b, unsigned shift)
3636 {
3737 int rt, dummy;
38+ if (__builtin_constant_p(shift))
3839 __asm__ (
3940 "imull %3 \n\t"
4041 "shrdl %4, %%edx, %%eax \n\t"
4142 :"=a"(rt), "=d"(dummy)
42− :"a"(a), "rm"(b), "ci"((uint8_t)shift)
43+ :"a"(a), "rm"(b), "i"(shift & 0x1F)
4344 );
45+ else
46+ __asm__ (
47+ "imull %3 \n\t"
48+ "shrdl %4, %%edx, %%eax \n\t"
49+ :"=a"(rt), "=d"(dummy)
50+ :"a"(a), "rm"(b), "c"((uint8_t)shift)
51+ );
4452 return rt;
4553 }
4654
@@ -113,19 +121,31 @@ __asm__ volatile(\ · 66 unmodified lines
113121 // avoid +32 for shift optimization (gcc should do that ...)
114122 #define NEG_SSR32 NEG_SSR32
115123 static inline int32_t NEG_SSR32( int32_t a, int8_t s){
124+ if (__builtin_constant_p(s))
116125 __asm__ ("sarl %1, %0\n\t"
117126 : "+r" (a)
118− : "ic" ((uint8_t)(-s))
127+ : "i" (-s & 0x1F)
119128 );
129+ else
130+ __asm__ ("sarl %1, %0\n\t"
131+ : "+r" (a)
132+ : "c" ((uint8_t)(-s))
133+ );
120134 return a;
121135 }
122136
123137 #define NEG_USR32 NEG_USR32
124138 static inline uint32_t NEG_USR32(uint32_t a, int8_t s){
139+ if (__builtin_constant_p(s))
125140 __asm__ ("shrl %1, %0\n\t"
126141 : "+r" (a)
127− : "ic" ((uint8_t)(-s))
142+ : "i" (-s & 0x1F)
128143 );
144+ else
145+ __asm__ ("shrl %1, %0\n\t"
146+ : "+r" (a)
147+ : "c" ((uint8_t)(-s))
148+ );
129149 return a;
130150 }
131151

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t