[vlc-commits] [Git][videolan/vlc][master] deinterlace-merge: move sse2 functions to isa/x86 and wire up isa/x86 in both...

Steve Lhomme (@robUx4) gitlab at videolan.org
Fri Jul 10 04:10:05 UTC 2026



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
6f33fb8e by Mazen Hassan at 2026-07-10T03:53:38+00:00
deinterlace-merge: move sse2 functions to isa/x86 and wire up isa/x86 in both meson and autotools build system

- - - - -


8 changed files:

- modules/Makefile.am
- + modules/isa/x86/Makefile.am
- + modules/isa/x86/deinterlace.c
- + modules/isa/x86/meson.build
- modules/meson.build
- modules/video_filter/deinterlace/deinterlace.c
- modules/video_filter/deinterlace/merge.c
- modules/video_filter/deinterlace/merge.h


Changes:

=====================================
modules/Makefile.am
=====================================
@@ -79,6 +79,7 @@ include hw/mmal/Makefile.am
 include isa/aarch64/Makefile.am
 include isa/arm/Makefile.am
 include isa/riscv/Makefile.am
+include isa/x86/Makefile.am
 include keystore/Makefile.am
 include logger/Makefile.am
 include lua/Makefile.am


=====================================
modules/isa/x86/Makefile.am
=====================================
@@ -0,0 +1,17 @@
+x86dir = $(pluginsdir)/x86
+
+x86_PLUGINS =
+x86_LTLIBRARIES =
+if HAVE_PARTIAL_LINKING
+noinst_LTLIBRARIES += $(x86_PLUGINS)
+else
+x86_LTLIBRARIES += $(x86_PLUGINS)
+endif
+
+libdeinterlace_x86_plugin_la_SOURCES = \
+    isa/x86/deinterlace.c
+
+if HAVE_SSE2
+x86_PLUGINS += \
+    libdeinterlace_x86_plugin.la 
+endif


=====================================
modules/isa/x86/deinterlace.c
=====================================
@@ -0,0 +1,102 @@
+/*****************************************************************************
+ * deinterlace.c: X86 deinterlacing functions
+ *****************************************************************************
+ * Copyright (C) 2011, 2026 VLC authors and VideoLAN
+ * 
+ * Author: Sam Hocevar <sam at zoy.org>                      (generic C routine)
+ *         Sigmund Augdal Helberg <sigmunau at videolan.org> (MMXEXT, 3DNow, SSE2)
+ *         Mazen Ewiss <mazenrory at gmail.com>         (moved functions to x86)
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
+#include <vlc_cpu.h>
+#include <vlc_plugin.h>
+#include <stdint.h>
+#include "../../video_filter/deinterlace/merge.h"
+VLC_SSE
+static void Merge8BitSSE2( void *_p_dest, const void *_p_s1, const void *_p_s2,
+                    size_t i_bytes )
+{
+    uint8_t *p_dest = _p_dest;
+    const uint8_t *p_s1 = _p_s1;
+    const uint8_t *p_s2 = _p_s2;
+
+    for( ; i_bytes > 0 && ((uintptr_t)p_s1 & 15); i_bytes-- )
+        *p_dest++ = ( *p_s1++ + *p_s2++ + 1) >> 1;
+
+    for( ; i_bytes >= 16; i_bytes -= 16 )
+    {
+        __asm__  __volatile__( "movdqu %2,%%xmm1;"
+                               "pavgb %1, %%xmm1;"
+                               "movdqu %%xmm1, %0" :"=m" (*p_dest):
+                                                 "m" (*p_s1),
+                                                 "m" (*p_s2) : "xmm1" );
+        p_dest += 16;
+        p_s1 += 16;
+        p_s2 += 16;
+    }
+
+    for( ; i_bytes > 0; i_bytes-- )
+        *p_dest++ = ( *p_s1++ + *p_s2++ + 1) >> 1;
+}
+
+VLC_SSE
+static void Merge16BitSSE2( void *_p_dest, const void *_p_s1, const void *_p_s2,
+                     size_t i_bytes )
+{
+    uint16_t *p_dest = _p_dest;
+    const uint16_t *p_s1 = _p_s1;
+    const uint16_t *p_s2 = _p_s2;
+
+    size_t i_words = i_bytes / 2;
+    for( ; i_words > 0 && ((uintptr_t)p_s1 & 15); i_words-- )
+        *p_dest++ = ( *p_s1++ + *p_s2++ + 1) >> 1;
+
+    for( ; i_words >= 8; i_words -= 8 )
+    {
+        __asm__  __volatile__( "movdqu %2,%%xmm1;"
+                               "pavgw %1, %%xmm1;"
+                               "movdqu %%xmm1, %0" :"=m" (*p_dest):
+                                                 "m" (*p_s1),
+                                                 "m" (*p_s2) : "xmm1" );
+        p_dest += 8;
+        p_s1 += 8;
+        p_s2 += 8;
+    }
+
+    for( ; i_words > 0; i_words-- )
+        *p_dest++ = ( *p_s1++ + *p_s2++ + 1) >> 1;
+}
+
+
+static void Probe(void *data)
+{
+    if (vlc_CPU_SSE2()) {
+        struct deinterlace_functions *const f = data;
+
+        f->merges[0] = Merge8BitSSE2;
+        f->merges[1] = Merge16BitSSE2;
+    }
+}
+
+vlc_module_begin()
+    set_description("X86 optimisation for deinterlacing")
+    set_cpu_funcs("deinterlace functions", Probe, 20)
+vlc_module_end()


=====================================
modules/isa/x86/meson.build
=====================================
@@ -0,0 +1,5 @@
+vlc_modules += {
+     'name' : 'deinterlace_x86',
+     'sources' : files('deinterlace.c'),
+     'enabled' : have_sse2,
+ }


=====================================
modules/meson.build
=====================================
@@ -369,6 +369,9 @@ subdir('visualization')
 # lua module
 subdir('lua')
 
+#x86 modules
+subdir('isa/x86')
+
 # muxer modules
 if get_option('stream_outputs')
     subdir('mux')


=====================================
modules/video_filter/deinterlace/deinterlace.c
=====================================
@@ -558,19 +558,13 @@ notsupp:
     if( pixel_size == 1 && vlc_CPU_ALTIVEC() )
         p_sys->pf_merge = MergeAltivec;
     else
-#endif
-#if defined(CAN_COMPILE_SSE2)
-    if( vlc_CPU_SSE2() )
-    {
-        p_sys->pf_merge = pixel_size == 1 ? Merge8BitSSE2 : Merge16BitSSE2;
-        p_sys->pf_end_merge = EndSSE;
-    }
-    else
 #endif
     {
         vlc_CPU_functions_init_once("deinterlace functions", &funcs);
         p_sys->pf_merge = funcs.merges[stdc_trailing_zeros(pixel_size)];
-#if defined(__i386__) || defined(__x86_64__)
+#if defined(CAN_COMPILE_SSE2) && (defined(__i386__) || defined(__x86_64__))
+        p_sys->pf_end_merge = vlc_CPU_SSE2() ? EndSSE : NULL;
+#elif defined(__i386__) || defined(__x86_64__)
         p_sys->pf_end_merge = NULL;
 #endif
     }


=====================================
modules/video_filter/deinterlace/merge.c
=====================================
@@ -63,64 +63,6 @@ void Merge16BitGeneric( void *_p_dest, const void *_p_s1,
         *p_dest++ = ( *p_s1++ + *p_s2++ + 1) >> 1;
 }
 
-#if defined(CAN_COMPILE_SSE2)
-VLC_SSE
-void Merge8BitSSE2( void *_p_dest, const void *_p_s1, const void *_p_s2,
-                    size_t i_bytes )
-{
-    uint8_t *p_dest = _p_dest;
-    const uint8_t *p_s1 = _p_s1;
-    const uint8_t *p_s2 = _p_s2;
-
-    for( ; i_bytes > 0 && ((uintptr_t)p_s1 & 15); i_bytes-- )
-        *p_dest++ = ( *p_s1++ + *p_s2++ + 1) >> 1;
-
-    for( ; i_bytes >= 16; i_bytes -= 16 )
-    {
-        __asm__  __volatile__( "movdqu %2,%%xmm1;"
-                               "pavgb %1, %%xmm1;"
-                               "movdqu %%xmm1, %0" :"=m" (*p_dest):
-                                                 "m" (*p_s1),
-                                                 "m" (*p_s2) : "xmm1" );
-        p_dest += 16;
-        p_s1 += 16;
-        p_s2 += 16;
-    }
-
-    for( ; i_bytes > 0; i_bytes-- )
-        *p_dest++ = ( *p_s1++ + *p_s2++ + 1) >> 1;
-}
-
-VLC_SSE
-void Merge16BitSSE2( void *_p_dest, const void *_p_s1, const void *_p_s2,
-                     size_t i_bytes )
-{
-    uint16_t *p_dest = _p_dest;
-    const uint16_t *p_s1 = _p_s1;
-    const uint16_t *p_s2 = _p_s2;
-
-    size_t i_words = i_bytes / 2;
-    for( ; i_words > 0 && ((uintptr_t)p_s1 & 15); i_words-- )
-        *p_dest++ = ( *p_s1++ + *p_s2++ + 1) >> 1;
-
-    for( ; i_words >= 8; i_words -= 8 )
-    {
-        __asm__  __volatile__( "movdqu %2,%%xmm1;"
-                               "pavgw %1, %%xmm1;"
-                               "movdqu %%xmm1, %0" :"=m" (*p_dest):
-                                                 "m" (*p_s1),
-                                                 "m" (*p_s2) : "xmm1" );
-        p_dest += 8;
-        p_s1 += 8;
-        p_s2 += 8;
-    }
-
-    for( ; i_words > 0; i_words-- )
-        *p_dest++ = ( *p_s1++ + *p_s2++ + 1) >> 1;
-}
-
-#endif
-
 #ifdef CAN_COMPILE_C_ALTIVEC
 VLC_ALTIVEC
 void MergeAltivec( void *_p_dest, const void *_p_s1,


=====================================
modules/video_filter/deinterlace/merge.h
=====================================
@@ -141,27 +141,6 @@ void Merge16BitGeneric( void *_p_dest, const void *_p_s1, const void *_p_s2,
 void MergeAltivec ( void *, const void *, const void *, size_t );
 #endif
 
-#if defined(CAN_COMPILE_SSE2)
-/**
- * SSE2 routine to blend pixels from two picture lines.
- *
- * @param _p_dest Target
- * @param _p_s1 Source line A
- * @param _p_s2 Source line B
- * @param i_bytes Number of bytes to merge
- */
-void Merge8BitSSE2( void *, const void *, const void *, size_t );
-/**
- * SSE2 routine to blend pixels from two picture lines.
- *
- * @param _p_dest Target
- * @param _p_s1 Source line A
- * @param _p_s2 Source line B
- * @param i_bytes Number of bytes to merge
- */
-void Merge16BitSSE2( void *, const void *, const void *, size_t );
-#endif
-
 /*****************************************************************************
  * EndMerge routines
  *****************************************************************************/



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6f33fb8eb39b9599757dec3f2e63df8ac9f33872

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/6f33fb8eb39b9599757dec3f2e63df8ac9f33872
You're receiving this email because of your account on code.videolan.org. Manage all notifications: https://code.videolan.org/-/profile/notifications | Help: https://code.videolan.org/help




More information about the vlc-commits mailing list