Skip to content

Commit 67b92d6

Browse files
committed
x86/intmath: add VEX encoded versions of av_clipf() and av_clipd()
Prevents mixing inlined SSE instructions and AVX instructions when the compiler generates the latter. Signed-off-by: James Almer <[email protected]>
1 parent b2aec70 commit 67b92d6

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

libavutil/x86/intmath.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,36 @@ static av_always_inline av_const float av_clipf_sse(float a, float amin, float a
134134

135135
#endif /* __SSE__ */
136136

137+
#if defined(__AVX__) && !defined(__INTEL_COMPILER)
138+
139+
#undef av_clipd
140+
#define av_clipd av_clipd_avx
141+
static av_always_inline av_const double av_clipd_avx(double a, double amin, double amax)
142+
{
143+
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
144+
if (amin > amax) abort();
145+
#endif
146+
__asm__ ("vmaxsd %1, %0, %0 \n\t"
147+
"vminsd %2, %0, %0 \n\t"
148+
: "+&x"(a) : "xm"(amin), "xm"(amax));
149+
return a;
150+
}
151+
152+
#undef av_clipf
153+
#define av_clipf av_clipf_avx
154+
static av_always_inline av_const float av_clipf_avx(float a, float amin, float amax)
155+
{
156+
#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
157+
if (amin > amax) abort();
158+
#endif
159+
__asm__ ("vmaxss %1, %0, %0 \n\t"
160+
"vminss %2, %0, %0 \n\t"
161+
: "+&x"(a) : "xm"(amin), "xm"(amax));
162+
return a;
163+
}
164+
165+
#endif /* __AVX__ */
166+
137167
#endif /* __GNUC__ */
138168

139169
#endif /* AVUTIL_X86_INTMATH_H */

0 commit comments

Comments
 (0)