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

Git pushed a commit to branch master
in repository ffmpeg.

commit 66f7e9db714a4cb12431c9e20d20207dcceacc55
Author:     Zhao Zhili <[email protected]>
AuthorDate: Mon Oct 6 17:19:05 2025 +0800
Commit:     Andreas Rheinhardt <[email protected]>
CommitDate: Sun Jan 4 15:49:30 2026 +0100

    avutil/crc: use arm64 crc32 instruction
    
    On rpi5 A76
    crc_32_ieee_le_c:                       23146.3 ( 1.00x)
    crc_32_ieee_le_crc:                      1060.1 (21.83x)
    
    On RK3566 A55
    crc_32_ieee_le_c:                       28773.8 ( 1.00x)
    crc_32_ieee_le_crc:                      2602.4 (11.06x)
    
    Co-authored-by: Andreas Rheinhardt <[email protected]>
    Signed-off-by: Andreas Rheinhardt <[email protected]>
---
 libavutil/aarch64/Makefile |  2 ++
 libavutil/aarch64/crc.S    | 69 ++++++++++++++++++++++++++++++++++++++++++++++
 libavutil/aarch64/crc.h    | 68 +++++++++++++++++++++++++++++++++++++++++++++
 libavutil/crc.c            | 14 ++++++++--
 4 files changed, 150 insertions(+), 3 deletions(-)

diff --git a/libavutil/aarch64/Makefile b/libavutil/aarch64/Makefile
index 744c2c53d7..b70702902f 100644
--- a/libavutil/aarch64/Makefile
+++ b/libavutil/aarch64/Makefile
@@ -2,6 +2,8 @@ OBJS += aarch64/cpu.o                                           
      \
         aarch64/float_dsp_init.o                                      \
         aarch64/tx_float_init.o                                       \
 
+ARMV8-OBJS += aarch64/crc.o
+
 NEON-OBJS += aarch64/float_dsp_neon.o                                 \
              aarch64/tx_float_neon.o                                  \
 
diff --git a/libavutil/aarch64/crc.S b/libavutil/aarch64/crc.S
new file mode 100644
index 0000000000..892c7ff229
--- /dev/null
+++ b/libavutil/aarch64/crc.S
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2025 Zhao Zhili <[email protected]>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * FFmpeg 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "asm.S"
+
+#if HAVE_ARM_CRC
+ENABLE_ARM_CRC
+
+.macro crc32_byte
+        ldrb            w5, [x2], #1
+        subs            x4, x4, #1
+        crc32b          w0, w0, w5
+.endm
+
+function ff_crc32_aarch64, export=1
+        and             x4, x2, #7          // non-aligned buffer addr
+        mov             w0, w1
+        cbz             x3, 8f
+
+        cbz             x4, 2f
+
+        mov             x5, #8
+        sub             x4, x5, x4
+        cmp             x4, x3
+        csel            x4, x4, x3, lo
+        sub             x3, x3, x4
+1:
+        // loop on non-aligned buffer
+        crc32_byte
+        b.ne            1b
+2:
+        // loop on aligned buffer
+        bic             x5, x3, #15
+        and             x4, x3, #15
+        cbz             x5, 4f
+3:
+        ldp             x6, x7, [x2], #16
+        subs            x5, x5, #16
+        crc32x          w0, w0, x6
+        crc32x          w0, w0, x7
+        b.ne            3b
+4:
+        cbz             x4, 8f
+5:
+        crc32_byte
+        b.ne            5b
+8:
+        ret
+endfunc
+
+DISABLE_ARM_CRC
+#endif
diff --git a/libavutil/aarch64/crc.h b/libavutil/aarch64/crc.h
new file mode 100644
index 0000000000..08efdd28f3
--- /dev/null
+++ b/libavutil/aarch64/crc.h
@@ -0,0 +1,68 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg 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.
+ *
+ * FFmpeg 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVUTIL_AARCH64_CRC_H
+#define AVUTIL_AARCH64_CRC_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "config.h"
+
+#include "cpu.h"
+#include "libavutil/attributes_internal.h"
+#include "libavutil/avassert.h"
+#include "libavutil/cpu.h"
+#include "libavutil/crc.h"
+
+FF_VISIBILITY_PUSH_HIDDEN
+uint32_t ff_crc32_aarch64(const AVCRC *ctx, uint32_t crc, const uint8_t 
*buffer,
+                          size_t length);
+FF_VISIBILITY_POP_HIDDEN
+
+static inline uint32_t ff_crc_aarch64(const AVCRC *ctx, uint32_t crc,
+                                      const uint8_t *buffer, size_t length)
+{
+#if HAVE_ARM_CRC
+    av_assert2(ctx[0] == AV_CRC_32_IEEE_LE + 1);
+    return ff_crc32_aarch64(ctx, crc, buffer, length);
+#else
+    av_unreachable("AARCH64 has only AV_CRC_32_IEEE_LE arch-specific CRC 
code");
+    return 0;
+#endif
+}
+
+static inline const AVCRC *ff_crc_get_table_aarch64(AVCRCId crc_id)
+{
+#if HAVE_ARM_CRC
+    static const AVCRC crc32_ieee_le_ctx[] = {
+        AV_CRC_32_IEEE_LE + 1
+    };
+
+    if (crc_id != AV_CRC_32_IEEE_LE)
+        return NULL;
+
+    int cpu_flags = av_get_cpu_flags();
+    if (have_arm_crc(cpu_flags)) {
+        return crc32_ieee_le_ctx;
+    }
+#endif
+    return NULL;
+}
+
+#endif /* AVUTIL_AARCH64_CRC_H */
diff --git a/libavutil/crc.c b/libavutil/crc.c
index 0b8d66d86d..c8ccaf8162 100644
--- a/libavutil/crc.c
+++ b/libavutil/crc.c
@@ -25,7 +25,9 @@
 #include "bswap.h"
 #include "crc.h"
 #include "error.h"
-#if ARCH_X86
+#if ARCH_AARCH64
+#include "libavutil/aarch64/crc.h"
+#elif ARCH_X86
 #include "libavutil/x86/crc.h"
 #endif
 
@@ -386,7 +388,11 @@ const AVCRC *av_crc_get_table(AVCRCId crc_id)
         return NULL;
 // Check for arch-specific extensions first to avoid initializing
 // ordinary CRC tables unnecessarily.
-#if ARCH_X86
+#if ARCH_AARCH64
+    const AVCRC *table = ff_crc_get_table_aarch64(crc_id);
+    if (table)
+        return table;
+#elif ARCH_X86
     const AVCRC *table = ff_crc_get_table_x86(crc_id);
     if (table)
         return table;
@@ -412,7 +418,9 @@ uint32_t av_crc(const AVCRC *ctx, uint32_t crc,
                 const uint8_t *buffer, size_t length)
 {
     if (ctx[0]) {
-#if ARCH_X86
+#if ARCH_AARCH64
+        return ff_crc_aarch64(ctx, crc, buffer, length);
+#elif ARCH_X86
         return ff_crc_x86(ctx, crc, buffer, length);
 #endif
     }

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

Reply via email to