Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] avutil/x86/intmath: remove inline assembly for av_clip{f, d}
@ 2025-05-14  0:45 James Almer
  0 siblings, 0 replies; only message in thread
From: James Almer @ 2025-05-14  0:45 UTC (permalink / raw)
  To: ffmpeg-devel

It's only supported by GCC, and everything inside the __asm__() block is
invisible to the compiler's scheduler.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 libavutil/x86/intmath.h | 55 ++++++++---------------------------------
 1 file changed, 10 insertions(+), 45 deletions(-)

diff --git a/libavutil/x86/intmath.h b/libavutil/x86/intmath.h
index 4893a1f1b4..e6d8de5f67 100644
--- a/libavutil/x86/intmath.h
+++ b/libavutil/x86/intmath.h
@@ -23,6 +23,7 @@
 
 #include <stdint.h>
 #include <stdlib.h>
+#include "config.h"
 #if HAVE_FAST_CLZ
 #if defined(_MSC_VER)
 #include <intrin.h>
@@ -30,7 +31,9 @@
 #include <immintrin.h>
 #endif
 #endif
-#include "config.h"
+#if HAVE_INTRINSICS_SSE2 && defined(__SSE2__)
+#include <emmintrin.h>
+#endif
 
 #if HAVE_FAST_CLZ
 #if (defined(__INTEL_COMPILER) && (__INTEL_COMPILER>=1216)) || defined(_MSC_VER)
@@ -114,7 +117,7 @@ static av_always_inline av_const unsigned av_zero_extend_bmi2(unsigned a, unsign
 
 #endif /* __BMI2__ */
 
-#if defined(__SSE2__) && !defined(__INTEL_COMPILER)
+#if HAVE_INTRINSICS_SSE2 && defined(__SSE2__)
 
 #define av_clipd av_clipd_sse2
 static av_always_inline av_const double av_clipd_sse2(double a, double amin, double amax)
@@ -122,59 +125,21 @@ static av_always_inline av_const double av_clipd_sse2(double a, double amin, dou
 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
     if (amin > amax) abort();
 #endif
-    __asm__ ("maxsd %1, %0 \n\t"
-             "minsd %2, %0 \n\t"
-             : "+&x"(a) : "xm"(amin), "xm"(amax));
-    return a;
+    __m128d _a = _mm_min_sd(_mm_max_sd(_mm_set_sd(a), _mm_set_sd(amin)), _mm_set_sd(amax));
+    return _mm_cvtsd_f64(_a);
 }
 
-#endif /* __SSE2__ */
-
-#if defined(__SSE__) && !defined(__INTEL_COMPILER)
-
 #define av_clipf av_clipf_sse
 static av_always_inline av_const float av_clipf_sse(float a, float amin, float amax)
 {
 #if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
     if (amin > amax) abort();
 #endif
-    __asm__ ("maxss %1, %0 \n\t"
-             "minss %2, %0 \n\t"
-             : "+&x"(a) : "xm"(amin), "xm"(amax));
-    return a;
-}
-
-#endif /* __SSE__ */
-
-#if defined(__AVX__) && !defined(__INTEL_COMPILER)
-
-#undef av_clipd
-#define av_clipd av_clipd_avx
-static av_always_inline av_const double av_clipd_avx(double a, double amin, double amax)
-{
-#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
-    if (amin > amax) abort();
-#endif
-    __asm__ ("vmaxsd %1, %0, %0 \n\t"
-             "vminsd %2, %0, %0 \n\t"
-             : "+&x"(a) : "xm"(amin), "xm"(amax));
-    return a;
-}
-
-#undef av_clipf
-#define av_clipf av_clipf_avx
-static av_always_inline av_const float av_clipf_avx(float a, float amin, float amax)
-{
-#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2
-    if (amin > amax) abort();
-#endif
-    __asm__ ("vmaxss %1, %0, %0 \n\t"
-             "vminss %2, %0, %0 \n\t"
-             : "+&x"(a) : "xm"(amin), "xm"(amax));
-    return a;
+    __m128 _a = _mm_min_ss(_mm_max_ss(_mm_set_ss(a), _mm_set_ss(amin)), _mm_set_ss(amax));
+    return _mm_cvtss_f32(_a);
 }
 
-#endif /* __AVX__ */
+#endif /* HAVE_INTRINSICS_SSE2 && defined(__SSE2__) */
 
 #endif /* __GNUC__ */
 
-- 
2.49.0

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2025-05-14  0:46 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-05-14  0:45 [FFmpeg-devel] [PATCH] avutil/x86/intmath: remove inline assembly for av_clip{f, d} James Almer

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git