This is an automated email from the git hooks/post-receive script.

Git pushed a commit to branch master
in repository ffmpeg.

commit 784f4c10cd1f05f23f197af2456a4f461ca24167
Author:     Niklas Haas <[email protected]>
AuthorDate: Tue Jul 14 13:54:22 2026 +0200
Commit:     Niklas Haas <[email protected]>
CommitDate: Fri Jul 17 13:23:21 2026 +0000

    swscale/uops: add ff_sws_shuffle_mask() helper
    
    This takes an arbitrary shuffle mask and expands it out to the needed number
    of bytes by repeating pixels.
    
    I decided to have the implementation live in ops_optimizer.c to locate
    it closer to the code where these shuffle masks are generated, to aid
    in understanding, and because the optimizer will itself use it (in the
    following commit).
    
    Signed-off-by: Niklas Haas <[email protected]>
---
 libswscale/ops_optimizer.c | 24 ++++++++++++++++++++++++
 libswscale/uops.h          | 15 +++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/libswscale/ops_optimizer.c b/libswscale/ops_optimizer.c
index d4360fa46f..2c53e8e234 100644
--- a/libswscale/ops_optimizer.c
+++ b/libswscale/ops_optimizer.c
@@ -948,6 +948,30 @@ int ff_sws_solve_shuffle(const SwsOpList *const ops, 
uint8_t shuffle[],
     return AVERROR(EINVAL);
 }
 
+int ff_sws_shuffle_mask(const SwsUOp *uop, int8_t shuffle[], int size)
+{
+    const SwsShuffleUOp *par = &uop->par.shuffle;
+    av_assert1(uop->uop == SWS_UOP_RW_SHUFFLE);
+    av_assert1(par->write_size <= sizeof(uop->data.shuffle.mask));
+    av_assert1(size <= INT8_MAX);
+
+    const int num_groups = size / FFMAX(par->read_size, par->write_size);
+    if (!num_groups)
+        return AVERROR(EINVAL);
+
+    memset(shuffle, 0, size);
+    for (int n = 0; n < num_groups; n++) {
+        const int base_in  = n * par->read_size;
+        const int base_out = n * par->write_size;
+        for (int i = 0; i < par->write_size; i++) {
+            const int8_t idx = uop->data.shuffle.mask[i];
+            shuffle[base_out + i] = idx + (idx >= 0) * base_in;
+        }
+    }
+
+    return num_groups;
+}
+
 int ff_sws_uop_list_optimize(SwsContext *ctx, SwsUOpFlags flags, SwsUOpList 
*uops)
 {
 #if 0
diff --git a/libswscale/uops.h b/libswscale/uops.h
index 28a7e4e874..198e6caea9 100644
--- a/libswscale/uops.h
+++ b/libswscale/uops.h
@@ -320,4 +320,19 @@ int ff_sws_uop_list_optimize(SwsContext *ctx, SwsUOpFlags 
flags, SwsUOpList *uop
 int ff_sws_ops_translate(SwsContext *ctx, const SwsOpList *ops,
                          SwsUOpFlags flags, SwsUOpList *uops);
 
+/**
+ * Compute a shuffle mask for `pshufb`-style ASM functions, by repeating
+ * the shuffle pattern for as many groups as will fit.
+ *
+ * @param uop         An operation of type SWS_UOP_RW_SHUFFLE.
+ * @param shuffle     The output shuffle index mask (or -1 to clear bytes).
+ * @param size        The maximum size (in bytes) of the output shuffle mask.
+ *
+ * @return the number of groups on success, or a negative error code.
+ *
+ * @note The shuffle mask is already pre-expanded to fill up to 16 bytes,
+ *       so this is only needed for larger shuffle instructions (e.g. vpermb).
+ */
+int ff_sws_shuffle_mask(const SwsUOp *uop, int8_t shuffle[], int size);
+
 #endif

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

Reply via email to