PR #22810 opened by Kacper Michajłow (kasper93)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22810
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/22810.patch


From dc34f0f2efb07de4a5280f4b47932e28bc36daa3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= <[email protected]>
Date: Tue, 14 Apr 2026 01:29:32 +0200
Subject: [PATCH] swscale/ops: add DECL_FUNC0/DECL_IMPL0 and put function
 signature in common place
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Kacper Michajłow <[email protected]>
---
 libswscale/ops_backend.h     | 19 ++++++---
 libswscale/ops_tmpl_common.c |  5 +--
 libswscale/ops_tmpl_int.c    | 80 +++++++++++++++++-------------------
 3 files changed, 52 insertions(+), 52 deletions(-)

diff --git a/libswscale/ops_backend.h b/libswscale/ops_backend.h
index f97b4303aa..453f6bea5f 100644
--- a/libswscale/ops_backend.h
+++ b/libswscale/ops_backend.h
@@ -78,6 +78,12 @@ typedef struct SwsOpIter {
                                           block_t z, block_t w,                
 \
                                           __VA_ARGS__)
 
+#define DECL_FUNC0(NAME)                                                       
 \
+    static av_always_inline void fn(NAME)(SwsOpIter *restrict iter,            
 \
+                                          const SwsOpImpl *restrict impl,      
 \
+                                          block_t x, block_t y,                
 \
+                                          block_t z, block_t w)
+
 #define DECL_READ(NAME, ...)                                                   
 \
     DECL_FUNC(NAME, const pixel_t *restrict in0, const pixel_t *restrict in1,  
 \
                     const pixel_t *restrict in2, const pixel_t *restrict in3,  
 \
@@ -102,14 +108,17 @@ typedef struct SwsOpIter {
                (pixel_t *) iter->out[2], (pixel_t *) iter->out[3], __VA_ARGS__)
 
 /* Helper macros to declare continuation functions */
-#define DECL_IMPL(FUNC, NAME, ...)                                             
 \
+#define DECL_IMPL_SIG(NAME)                                                    
 \
     static void av_flatten fn(NAME)(SwsOpIter *restrict iter,                  
 \
                                     const SwsOpImpl *restrict impl,            
 \
                                     void *restrict x, void *restrict y,        
 \
-                                    void *restrict z, void *restrict w)        
 \
-    {                                                                          
 \
-        CALL(FUNC, __VA_ARGS__);                                               
 \
-    }
+                                    void *restrict z, void *restrict w)
+
+#define DECL_IMPL(FUNC, NAME, ...)                                             
 \
+    DECL_IMPL_SIG(NAME) { CALL(FUNC, __VA_ARGS__); }
+
+#define DECL_IMPL0(FUNC, NAME)                                                 
 \
+    DECL_IMPL_SIG(NAME) { fn(FUNC)(iter, impl, x, y, z, w); }
 
 /* Helper macro to call into the next continuation */
 #define CONTINUE(X, Y, Z, W)                                                   
 \
diff --git a/libswscale/ops_tmpl_common.c b/libswscale/ops_tmpl_common.c
index 0763a08b1c..32d5857c8a 100644
--- a/libswscale/ops_tmpl_common.c
+++ b/libswscale/ops_tmpl_common.c
@@ -293,10 +293,7 @@ DECL_READ(filter_h, const int elems)
 }
 
 #define WRAP_FILTER(FUNC, DIR, ELEMS, SUFFIX)                                  
 \
-static av_flatten void fn(FUNC##ELEMS##SUFFIX)(SwsOpIter *restrict iter,       
 \
-                                             const SwsOpImpl *restrict impl,   
 \
-                                             void *restrict x, void *restrict 
y,\
-                                             void *restrict z, void *restrict 
w)\
+DECL_IMPL_SIG(FUNC##ELEMS##SUFFIX)                                             
 \
 {                                                                              
 \
     CALL_READ(FUNC##SUFFIX, ELEMS);                                            
 \
 }                                                                              
 \
diff --git a/libswscale/ops_tmpl_int.c b/libswscale/ops_tmpl_int.c
index baa3526029..bdf55eac2a 100644
--- a/libswscale/ops_tmpl_int.c
+++ b/libswscale/ops_tmpl_int.c
@@ -119,10 +119,7 @@ DECL_WRITE(write_packed, const int elems)
 }
 
 #define WRAP_READ(FUNC, ELEMS, FRAC, PACKED)                                   
 \
-static av_flatten void fn(FUNC##ELEMS)(SwsOpIter *restrict iter,               
 \
-                                       const SwsOpImpl *restrict impl,         
 \
-                                       void *restrict x, void *restrict y,     
 \
-                                       void *restrict z, void *restrict w)     
 \
+DECL_IMPL_SIG(FUNC##ELEMS)                                                     
 \
 {                                                                              
 \
     CALL_READ(FUNC, ELEMS);                                                    
 \
     for (int i = 0; i < (PACKED ? 1 : ELEMS); i++)                             
 \
@@ -147,10 +144,7 @@ WRAP_READ(read_packed, 3, 0, true)
 WRAP_READ(read_packed, 4, 0, true)
 
 #define WRAP_WRITE(FUNC, ELEMS, FRAC, PACKED)                                  
 \
-static av_flatten void fn(FUNC##ELEMS)(SwsOpIter *restrict iter,               
 \
-                                       const SwsOpImpl *restrict impl,         
 \
-                                       void *restrict x, void *restrict y,     
 \
-                                       void *restrict z, void *restrict w)     
 \
+DECL_IMPL_SIG(FUNC##ELEMS)                                                     
 \
 {                                                                              
 \
     CALL_WRITE(FUNC, ELEMS);                                                   
 \
     for (int i = 0; i < (PACKED ? 1 : ELEMS); i++)                             
 \
@@ -303,48 +297,48 @@ WRAP_COMMON_PATTERNS(expand32,
 );
 #endif
 
-DECL_FUNC(pack, const int bits0, const int bits1, const int bits2, const int 
bits3)
-{
-    SWS_LOOP
-    for (int i = 0; i < SWS_BLOCK_SIZE; i++) {
-        x[i] = x[i] << (bits1 + bits2 + bits3);
-        if (bits1)
-            x[i] |= y[i] << (bits2 + bits3);
-        if (bits2)
-            x[i] |= z[i] << bits3;
-        if (bits3)
-            x[i] |= w[i];
-    }
-
-    CONTINUE(x, y, z, w);
-}
-
-DECL_FUNC(unpack, const int bits0, const int bits1, const int bits2, const int 
bits3)
-{
-    SWS_LOOP
-    for (int i = 0; i < SWS_BLOCK_SIZE; i++) {
-        const pixel_t val = x[i];
-        x[i] = val >> (bits1 + bits2 + bits3);
-        if (bits1)
-            y[i] = (val >> (bits2 + bits3)) & ((1 << bits1) - 1);
-        if (bits2)
-            z[i] = (val >> bits3) & ((1 << bits2) - 1);
-        if (bits3)
-            w[i] = val & ((1 << bits3) - 1);
-    }
-
-    CONTINUE(x, y, z, w);
-}
-
 #define WRAP_PACK_UNPACK(X, Y, Z, W)                                           
 \
-DECL_IMPL(pack, pack_##X##Y##Z##W, X, Y, Z, W)                                 
 \
+DECL_FUNC0(pack_##X##Y##Z##W##_impl)                                           
 \
+{                                                                              
 \
+    SWS_LOOP                                                                   
 \
+    for (int i = 0; i < SWS_BLOCK_SIZE; i++) {                                 
 \
+        x[i] = x[i] << (Y+Z+W);                                                
 \
+        if (Y)                                                                 
 \
+            x[i] |= y[i] << (Z+W);                                             
 \
+        if (Z)                                                                 
 \
+            x[i] |= z[i] << W;                                                 
 \
+        if (W)                                                                 
 \
+            x[i] |= w[i];                                                      
 \
+    }                                                                          
 \
+                                                                               
 \
+    CONTINUE(x, y, z, w);                                                      
 \
+}                                                                              
 \
+                                                                               
 \
+DECL_IMPL0(pack_##X##Y##Z##W##_impl, pack_##X##Y##Z##W)                        
 \
                                                                                
 \
 DECL_ENTRY(pack_##X##Y##Z##W,                                                  
 \
     .op = SWS_OP_PACK,                                                         
 \
     .pack.pattern = { X, Y, Z, W },                                            
 \
 );                                                                             
 \
                                                                                
 \
-DECL_IMPL(unpack, unpack_##X##Y##Z##W, X, Y, Z, W)                             
 \
+DECL_FUNC0(unpack_##X##Y##Z##W##_impl)                                         
 \
+{                                                                              
 \
+    SWS_LOOP                                                                   
 \
+    for (int i = 0; i < SWS_BLOCK_SIZE; i++) {                                 
 \
+        const pixel_t val = x[i];                                              
 \
+        x[i] = val >> (Y+Z+W);                                                 
 \
+        if (Y)                                                                 
 \
+            y[i] = (val >> (Z+W)) & ((1 << Y) - 1);                            
 \
+        if (Z)                                                                 
 \
+            z[i] = (val >> W) & ((1 << Z) - 1);                                
 \
+        if (W)                                                                 
 \
+            w[i] = val & ((1 << W) - 1);                                       
 \
+    }                                                                          
 \
+                                                                               
 \
+    CONTINUE(x, y, z, w);                                                      
 \
+}                                                                              
 \
+                                                                               
 \
+DECL_IMPL0(unpack_##X##Y##Z##W##_impl, unpack_##X##Y##Z##W)                    
 \
                                                                                
 \
 DECL_ENTRY(unpack_##X##Y##Z##W,                                                
 \
     .op = SWS_OP_UNPACK,                                                       
 \
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to