Commit 1c767fe664 for ffmpeg

commit 1c767fe664526d5e6b2619f846c1dc77d4dc3e4e
Author: Michael Niedermayer <michael@niedermayer.cc>
Date:   Sun Oct 18 04:28:30 2026 +0200

    avutil/mips/mmiutils: provide the Loongson MMI mnemonics GNU binutils lacks

    GNU binutils spells the MMI instructions pxor, pand, por, pnor, ssrld
    and sslld as xor, and, or, nor, dsrl and dsll on floating point
    registers, with -march=loongson2e/2f/3a and since 2.32 with
    -mloongson-mmi; the p-named entries in its opcode table are the R5900
    instructions on general purpose registers. The other 43 p-named MMI
    instructions FFmpeg uses are spelled the same by everyone. Loongson's
    gcc toolchain accepts both spellings (ebedd26eef), the binutils 2.24
    of their cross-gcc-4.9.3-n64-loongson-rc6.1 only the GNU ones.

    Since 903c5d58f0 configure probes pxor and so silently disables MMI
    with every GNU binutils. Probe Loongson's spelling first and fall
    back to the GNU one together with assembler macros that define the
    six names, as asmdefs.h already does for parse_r. The macros assemble
    to the same encodings as the GNU spelling with binutils 2.24, 2.28
    and 2.42.

    The GNU fallback is limited to little-endian mips64: the MMI code does
    not build for O32 and its unaligned loads assume little-endian.

diff --git a/configure b/configure
index 60e380d83d..ce0ed2397d 100755
--- a/configure
+++ b/configure
@@ -2597,6 +2597,7 @@ TOOLCHAIN_FEATURES="
     ibm_asm
     inline_asm_direct_symbol_refs
     inline_asm_nonlocal_labels
+    loongson_mmi_mnemonics
     pragma_deprecated
     rsync_contimeout
     symver_asm_label
@@ -6658,7 +6659,14 @@ elif enabled mips; then
     enabled loongson3 && check_inline_asm loongson3 '"gsldxc1 $f0, 0($2, $3)"' '-mloongson-ext' && append MMIFLAGS '-mloongson-ext'

     # MMI can be detected at runtime too
-    enabled mmi && check_inline_asm mmi '"pxor $f0, $f0, $f0"' '-mloongson-mmi' && append MMIFLAGS '-mloongson-mmi'
+    enabled mmi && {
+        check_inline_asm loongson_mmi_mnemonics '"pxor $f0, $f0, $f0\n\tssrld $f0, $f0, $f0"' '-mloongson-mmi' || {
+            # the MMI code does not build for O32 and assumes little-endian
+            disable mmi
+            enabled mips64 && ! enabled bigendian &&
+                check_inline_asm mmi '"xor $f0, $f0, $f0"' '-mloongson-mmi'
+        }
+    } && append MMIFLAGS '-mloongson-mmi'

     if enabled bigendian && enabled msa; then
         disable msa
diff --git a/libavutil/mips/mmiutils.h b/libavutil/mips/mmiutils.h
index 7991e14e84..47cdb19f1c 100644
--- a/libavutil/mips/mmiutils.h
+++ b/libavutil/mips/mmiutils.h
@@ -29,6 +29,16 @@
 #include "libavutil/mem_internal.h"
 #include "libavutil/mips/asmdefs.h"

+#if !HAVE_LOONGSON_MMI_MNEMONICS
+/* GNU binutils lacks Loongson's names for these MMI instructions */
+__asm__(".macro pxor  d, s, t\n\txor  \\d, \\s, \\t\n\t.endm\n"
+        ".macro pand  d, s, t\n\tand  \\d, \\s, \\t\n\t.endm\n"
+        ".macro por   d, s, t\n\tor   \\d, \\s, \\t\n\t.endm\n"
+        ".macro pnor  d, s, t\n\tnor  \\d, \\s, \\t\n\t.endm\n"
+        ".macro ssrld d, s, t\n\tdsrl \\d, \\s, \\t\n\t.endm\n"
+        ".macro sslld d, s, t\n\tdsll \\d, \\s, \\t\n\t.endm\n");
+#endif
+
 /*
  * These were used to define temporary registers for MMI marcos
  * however now we're using $at. They're theoretically unnecessary