<div class="zcontentRow"><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><span style="font-family: 微软雅黑, "Microsoft YaHei";">Hi chen,</span></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><span style="font-family: 微软雅黑, "Microsoft YaHei";"><br></span></p><p>I'll submit a new patch to address these two points.</p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><div unonameen="Wu Changsheng0318004250" unonamech="吴昌盛0318004250" class="zMailSign"><p style="display: none;" unonameen="Wu Changsheng0318004250" unonamech="吴昌盛0318004250" class="zMailSignTitle"><label class="sign_nameUno"></label><span class="sign_arrow"></span></p><div class="zMailSignContent"><p style="box-sizing: border-box; outline: 0px; white-space: normal; font-family: Arial, Helvetica, "Microsoft Yahei", sans-serif; margin-top: 0px; margin-bottom: 0px; padding: 0px; min-height: 14px; background-color: rgb(255, 255, 255); line-height: normal;">Best Wishes!</p><p style="box-sizing: border-box; outline: 0px; white-space: normal; font-family: Arial, Helvetica, "Microsoft Yahei", sans-serif; margin-top: 0px; margin-bottom: 0px; padding: 0px; min-height: 14px; background-color: rgb(255, 255, 255); line-height: normal;">Changsheng Wu</p><p style="box-sizing: border-box; outline: 0px; white-space: normal; font-family: Arial, Helvetica, "Microsoft Yahei", sans-serif; margin-top: 0px; margin-bottom: 0px; padding: 0px; min-height: 14px; background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box; outline: 0px; font-family: arial, sans-serif, "Myriad Pro"; line-height: normal;">E:wu.changsheng@sanechips.com.cn</span></p><p style="box-sizing: border-box; outline: 0px; white-space: normal; font-family: Arial, Helvetica, "Microsoft Yahei", sans-serif; margin-top: 0px; margin-bottom: 0px; padding: 0px; min-height: 14px; background-color: rgb(255, 255, 255); line-height: normal;">SANECHIPS TECHNOLOGY CO.,LTD.</p><p><br></p></div></div><div class="zhistoryRow" style="display:block"><div class="zhistoryDes" style="width: 100%; height: 28px; line-height: 28px; background-color: #E0E5E9; color: #1388FF; text-align: center;">Original</div><div id="zwriteHistoryContainer"><div class="control-group zhistoryPanel"><div class="zhistoryHeader" style="padding: 8px; background-color: #F5F6F8;"><div><strong>From: </strong><span class="zreadUserName">chen <chenm003@163.com></span></div><div><strong>To: </strong><span class="zreadUserName" style="display: inline;">吴昌盛0318004250;</span></div><div><strong>Cc: </strong><span class="zreadUserName" style="display: inline;">x265-devel@videolan.org <x265-devel@videolan.org>;</span><span class="zreadUserName" style="display: inline;">贺雨娇0318004338;</span><span class="zreadUserName" style="display: inline;">沈显来0318003851;</span><span class="zreadUserName" style="display: inline;">袁佳0318004243;</span></div><div><strong>Date: </strong><span class="">2025年10月01日 13:31</span></div><div><strong>Subject: </strong><span class="zreadTitle"><strong>Re:Re: [x265] RISCV64:supports RISCV compile</strong></span></div></div><div class="zhistoryContent"><div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial" data-ntes="ntes_mail_body_root"><div id="spnEditorContent"><div style="margin: 0;">Hi Changsheng,</div><br><div style="margin: 0;">1. "-O2" is better</div><div style="margin: 0;">2.  declaration of cpu_detect need match x265 framework, I suggest fix in RV patch.<br>As you said, the declaration issue affects all ARM platforms, including ARM and AARCH64, we'll fix it.</div><br></div><div style="margin: 0;">Regards,<br>Chen</div><p>2025-10-01 07:37:48,wu.changsheng@sanechips.com.cn </p><blockquote style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid" id="isReplyContent"><div class=""><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;">Hi chen,<br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p>Both of my implementations are consistent with the aarch64 version. Could you clarify what you were expecting instead?</p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><span style="font-family: Arial;">>+ set(RISCV64_ARGS -O3)</span><br style="font-family: Arial; white-space: normal;"><span style="font-family: Arial;">>default to -O3?</span></p><p>Use O2 or no optimization flag.</p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p style="font-family: Arial; white-space: normal; word-break: break-word !important;"><span style="font-family: Helvetica, "Microsoft Yahei", verdana;">>+uint32_t cpu_detect(bool benableavx512)</span><br><span style="font-family: Helvetica, "Microsoft Yahei", verdana;">>+    int flags = 0;</span></p><p style="font-family: Arial; white-space: normal; word-break: break-word !important;"><span style="font-family: Helvetica, "Microsoft Yahei", verdana;">>+static inline int riscv64_cpu_detect()<br></span>>uint32_t?</p><p>I can change it to uint32_t, but that would make it inconsistent with the existing aarch64 implementation.</p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><div class="zMailSign" unonamech="吴昌盛0318004250" unonameen="Wu Changsheng0318004250"><p class="zMailSignTitle" unonamech="吴昌盛0318004250" unonameen="Wu Changsheng0318004250" style="display: none;"><label class="sign_nameUno"></label><span class="sign_arrow"></span></p><div class="zMailSignContent"><p style="box-sizing: border-box; outline: 0px; white-space: normal; font-family: Arial, Helvetica, "Microsoft Yahei", sans-serif; margin-top: 0px; margin-bottom: 0px; padding: 0px; min-height: 14px; background-color: rgb(255, 255, 255); line-height: normal;">Best Wishes!</p><p style="box-sizing: border-box; outline: 0px; white-space: normal; font-family: Arial, Helvetica, "Microsoft Yahei", sans-serif; margin-top: 0px; margin-bottom: 0px; padding: 0px; min-height: 14px; background-color: rgb(255, 255, 255); line-height: normal;">Changsheng Wu</p><p style="box-sizing: border-box; outline: 0px; white-space: normal; font-family: Arial, Helvetica, "Microsoft Yahei", sans-serif; margin-top: 0px; margin-bottom: 0px; padding: 0px; min-height: 14px; background-color: rgb(255, 255, 255);"><span style="box-sizing: border-box; outline: 0px; font-family: arial, sans-serif, "Myriad Pro"; line-height: normal;">E:wu.changsheng@sanechips.com.cn</span></p><p style="box-sizing: border-box; outline: 0px; white-space: normal; font-family: Arial, Helvetica, "Microsoft Yahei", sans-serif; margin-top: 0px; margin-bottom: 0px; padding: 0px; min-height: 14px; background-color: rgb(255, 255, 255); line-height: normal;">SANECHIPS TECHNOLOGY CO.,LTD.</p><p><br></p></div></div><p><br></p></div></blockquote></div></div></div><div class="control-group zhistoryPanel"><div style="padding: 8px; background-color: #F5F6F8;" class="zhistoryHeader"><div><strong>From: </strong><span class="zreadUserName">chen <chenm003@163.com></span></div><div><strong>To: </strong><span style="display: inline;" class="zreadUserName">Development for x265 <x265-devel@videolan.org>;</span></div><div><strong>Cc: </strong><span style="display: inline;" class="zreadUserName">吴昌盛0318004250;</span><span style="display: inline;" class="zreadUserName">贺雨娇0318004338;</span></div><div><strong>Date: </strong><span class="">2025年09月30日 23:20</span></div><div><strong>Subject: </strong><span class="zreadTitle"><strong>Re:[x265] RISCV64:supports RISCV compile</strong></span></div></div><div class="zhistoryContent"><div data-ntes="ntes_mail_body_root" style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><div id="spnEditorContent"><div style="margin: 0;">Hi Changsheng,</div><br><div style="margin: 0;">Thank for the patch, looks good to me,<br>some comments,</div><br><div style="margin: 0;">+        set(RISCV64_ARGS -O3)<br>default to -O3?</div><div style="margin: 0;"><p style="word-break: break-word !important;"><span style="font-family:Helvetica, Microsoft Yahei, verdana">+uint32_t cpu_detect(bool benableavx512)</span><br><span style="font-family:Helvetica, Microsoft Yahei, verdana">+    int flags = 0;</span></p><p style="word-break: break-word !important;"><span style="font-family:Helvetica, Microsoft Yahei, verdana">+static inline int riscv64_cpu_detect()<br></span><span style="font-family: Arial;">uint32_t?</span></p></div><br><div style="margin: 0;">Regards,<br>Chen</div><br><br><br><br></div><br><p>At 2025-09-30 15:37:31, wu.changsheng@sanechips.com.cn wrote:</p><blockquote id="isReplyContent" style="PADDING-LEFT: 1ex; MARGIN: 0px 0px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid"><div class=""><p>From 32232389434ac0834deb07dba60a10500ccc4226 Mon Sep 17 00:00:00 2001</p><p>From: Changsheng Wu <wu.changsheng@sanechips.com.cn></p><p>Date: Wed, 6 Aug 2025 01:18:13 +0800</p><p>Subject: [PATCH] RISCV64:supports RISCV compile</p><p><br></p><p>This patch is a basic enablement that supports RISC-V compile.</p><p>We are working on adding vector optimizations with RISC-V RVV</p><p>extensions, and will push the implementations later.</p><p>---</p><p> source/CMakeLists.txt                    | 98 ++++++++++++++++++++++--</p><p> source/common/CMakeLists.txt             | 21 +++++</p><p> source/common/cpu.cpp                    | 18 +++++</p><p> source/common/param.cpp                  |  2 +-</p><p> source/common/primitives.cpp             |  4 +-</p><p> source/common/riscv64/asm-primitives.cpp | 59 ++++++++++++++</p><p> source/common/riscv64/cpu.h              | 70 +++++++++++++++++</p><p> source/test/testbench.cpp                |  8 +-</p><p> source/test/testharness.h                |  4 +-</p><p> source/x265.h                            |  3 +</p><p> 10 files changed, 274 insertions(+), 13 deletions(-)</p><p> create mode 100644 source/common/riscv64/asm-primitives.cpp</p><p> create mode 100644 source/common/riscv64/cpu.h</p><p><br></p><p>diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt</p><p>index 4160514b9..b6d360dd6 100755</p><p>--- a/source/CMakeLists.txt</p><p>+++ b/source/CMakeLists.txt</p><p>@@ -44,11 +44,13 @@ endif()</p><p> set(X86_ALIASES x86 i386 i686 x86_64 amd64)</p><p> set(ARM_ALIASES armv6l armv7l)</p><p> set(ARM64_ALIASES arm64 arm64e aarch64)</p><p>+set(RISCV64_ALIASES riscv64)</p><p> list(FIND X86_ALIASES "${SYSPROC}" X86MATCH)</p><p> list(FIND ARM_ALIASES "${SYSPROC}" ARMMATCH)</p><p> list(FIND ARM64_ALIASES "${SYSPROC}" ARM64MATCH)</p><p> set(POWER_ALIASES powerpc64 powerpc64le ppc64 ppc64le)</p><p> list(FIND POWER_ALIASES "${SYSPROC}" POWERMATCH)</p><p>+list(FIND RISCV64_ALIASES "${SYSPROC}" RISCV64MATCH)</p><p> if(X86MATCH GREATER "-1")</p><p>     set(X86 1)</p><p>     add_definitions(-DX265_ARCH_X86=1)</p><p>@@ -108,6 +110,13 @@ elseif(ARM64MATCH GREATER "-1")</p><p>     set(AARCH64_SVE2_FLAG "-march=armv9-a+i8mm+sve2")</p><p>     # SVE2 BitPerm implies +dotprod, +sve, and +sve2.</p><p>     set(AARCH64_SVE2_BITPERM_FLAG "-march=armv9-a+i8mm+sve2-bitperm")</p><p>+elseif(RISCV64MATCH GREATER "-1")</p><p>+    message(STATUS "Detected RISCV64 target processor")</p><p>+    set(RISCV64 1)</p><p>+</p><p>+    option(RISCV64_RUNTIME_CPU_DETECT "Enable RISCV64 run-time CPU feature detection" ON)</p><p>+</p><p>+    option(ENABLE_RVV "Enable RVV" ON)</p><p> else()</p><p>     message(STATUS "CMAKE_SYSTEM_PROCESSOR value `${CMAKE_SYSTEM_PROCESSOR}` is unknown")</p><p>     message(STATUS "Please add this value near ${CMAKE_CURRENT_LIST_FILE}:${CMAKE_CURRENT_LIST_LINE}")</p><p>@@ -171,7 +180,7 @@ if(UNIX)</p><p>     endif(X64)</p><p> endif(UNIX)</p><p><br></p><p>-if((X64 AND NOT WIN32) OR ARM64 OR PPC64)</p><p>+if((X64 AND NOT WIN32) OR ARM64 OR PPC64 OR RISCV64)</p><p>     option(ENABLE_PIC "Enable Position Independent Code" ON)</p><p> else()</p><p>     option(ENABLE_PIC "Enable Position Independent Code" OFF)</p><p>@@ -440,6 +449,68 @@ int main() { return 0; }")</p><p>             set(ARM_ARGS ${ARM_ARGS} -flax-vector-conversions=none)</p><p>         endif()</p><p>     endif()</p><p>+    if(RISCV64)</p><p>+        add_definitions(-DX265_ARCH_RISCV64=1)</p><p>+</p><p>+        if (RISCV64_RUNTIME_CPU_DETECT)</p><p>+            add_definitions(-DRISCV64_RUNTIME_CPU_DETECT=1)</p><p>+            message(STATUS "Configuring build for run-time CPU feature detection")</p><p>+        endif()</p><p>+</p><p>+        if(RISCV64_RUNTIME_CPU_DETECT OR CROSS_COMPILE_RISCV64)</p><p>+            # Add all extensions when compiling for run-time CPU feature detection or cross compiling.</p><p>+            set(CPU_HAS_RVV 1)</p><p>+        else()</p><p>+            if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin")</p><p>+                find_package(RVV)</p><p>+            else()</p><p>+                message(STATUS "Compile-time CPU feature detection unsupported on this platform")</p><p>+            endif()</p><p>+        endif()</p><p>+</p><p>+        if(ENABLE_RVV)</p><p>+            set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})</p><p>+            set(OLD_CMAKE_TRY_COMPILE_TARGET_TYPE ${CMAKE_TRY_COMPILE_TARGET_TYPE})</p><p>+            set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)</p><p>+            # When compilation target is a STATIC_LIBRARY, the LINK_OPTIONS are</p><p>+            # passed to the archiver, so we must backup, clear and restore these.</p><p>+            # https://gitlab.kitware.com/cmake/cmake/-/issues/23454</p><p>+            set(OLD_CMAKE_REQUIRED_LINK_OPTIONS ${CMAKE_REQUIRED_LINK_OPTIONS})</p><p>+            set(CMAKE_REQUIRED_LINK_OPTIONS "")</p><p>+</p><p>+            # Check whether the compiler can compile RVV functions that require</p><p>+            # backup/restore of RVV registers according to AAPCS.</p><p>+            # https://github.com/llvm/llvm-project/issues/80009.</p><p>+            set(RVV_COMPILATION_TEST [[</p><p>+int main() {</p><p>+  asm volatile(".option arch, +v; vsetvli t0, a0, e32, m1, ta, ma");</p><p>+  return 0;</p><p>+}]])</p><p>+</p><p>+            check_c_source_compiles("${RVV_COMPILATION_TEST}" RVV_COMPILATION_C_TEST_COMPILED)</p><p>+            check_cxx_source_compiles("${RVV_COMPILATION_TEST}" RVV_COMPILATION_CXX_TEST_COMPILED)</p><p>+</p><p>+            set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})</p><p>+            set(CMAKE_TRY_COMPILE_TARGET_TYPE ${OLD_CMAKE_TRY_COMPILE_TARGET_TYPE})</p><p>+            set(CMAKE_REQUIRED_LINK_OPTIONS ${OLD_CMAKE_REQUIRED_LINK_OPTIONS})</p><p>+            if (NOT(RVV_COMPILATION_C_TEST_COMPILED AND RVV_COMPILATION_CXX_TEST_COMPILED))</p><p>+                set(ENABLE_RVV OFF CACHE BOOL "" FORCE)</p><p>+                message(STATUS "Disabling RVV")</p><p>+            endif()</p><p>+        endif()</p><p>+</p><p>+        if(NOT ENABLE_RVV)</p><p>+            message(STATUS "Disabling RVV")</p><p>+            set(CPU_HAS_RVV 0)</p><p>+        endif()</p><p>+</p><p>+        if(CPU_HAS_RVV)</p><p>+            message(STATUS "Found RVV")</p><p>+            add_definitions(-DHAVE_RVV=1)</p><p>+        endif()</p><p>+</p><p>+        set(RISCV64_ARGS -O3)</p><p>+    endif()</p><p>     if(ENABLE_PIC)</p><p>         list(APPEND ARM_ARGS -DPIC -fPIC)</p><p>     endif()</p><p>@@ -492,7 +563,7 @@ int main() { return 0; }")</p><p>     if (CC_HAS_FAST_MATH)</p><p>         add_definitions(-ffast-math)</p><p>     endif()</p><p>-    if (NOT (ARM64 OR CROSS_COMPILE_ARM64))</p><p>+    if (NOT (ARM64 OR CROSS_COMPILE_ARM64 OR RISCV64 OR CROSS_COMPILE_RISCV64))</p><p>         check_cxx_compiler_flag(-mstackrealign CC_HAS_STACK_REALIGN)</p><p>         if (CC_HAS_STACK_REALIGN)</p><p>             add_definitions(-mstackrealign)</p><p>@@ -548,6 +619,8 @@ if(ARM OR CROSS_COMPILE_ARM OR ARM64 OR CROSS_COMPILE_ARM64)</p><p>     if (NOT ENABLE_NEON)</p><p>         set(ENABLE_ASSEMBLY OFF CACHE BOOL "" FORCE)</p><p>     endif()</p><p>+elseif((RISCV64 OR CROSS_COMPILE_RISCV64) AND ENABLE_RVV)</p><p>+    option(ENABLE_ASSEMBLY "Enable use of assembly coded primitives" ON)</p><p> elseif(NASM_FOUND AND X86)</p><p>     if (NASM_VERSION_STRING VERSION_LESS "2.13.0")</p><p>         message(STATUS "Nasm version ${NASM_VERSION_STRING} is too old. 2.13.0 or later required")</p><p>@@ -584,7 +657,7 @@ if(EXTRA_LIB)</p><p> endif(EXTRA_LIB)</p><p> mark_as_advanced(EXTRA_LIB EXTRA_LINK_FLAGS)</p><p><br></p><p>-if(X64 OR ARM64 OR PPC64)</p><p>+if(X64 OR ARM64 OR PPC64 OR RISCV64)</p><p>     # NOTE: We only officially support high-bit-depth compiles of x265</p><p>     # on 64bit architectures. Main10 plus large resolution plus slow</p><p>     # preset plus 32bit address space usually means malloc failure.  You</p><p>@@ -593,7 +666,7 @@ if(X64 OR ARM64 OR PPC64)</p><p>     # license" so to speak.  If it breaks you get to keep both halves.</p><p>     # You will need to disable assembly manually.</p><p>     option(HIGH_BIT_DEPTH "Store pixel samples as 16bit values (Main10/Main12)" OFF)</p><p>-endif(X64 OR ARM64 OR PPC64)</p><p>+endif(X64 OR ARM64 OR PPC64 OR RISCV64)</p><p> if(HIGH_BIT_DEPTH)</p><p>     option(MAIN12 "Support Main12 instead of Main10" OFF)</p><p>     if(MAIN12)</p><p>@@ -640,7 +713,7 @@ else()</p><p> endif()</p><p> add_definitions(-DX265_NS=${X265_NS})</p><p><br></p><p>-if(ARM64)</p><p>+if(ARM64 OR RISCV64)</p><p>   if(HIGH_BIT_DEPTH)</p><p>     if(MAIN12)</p><p>       list(APPEND ASM_FLAGS -DHIGH_BIT_DEPTH=1 -DBIT_DEPTH=12 -DX265_NS=${X265_NS})</p><p>@@ -650,7 +723,7 @@ if(ARM64)</p><p>   else()</p><p>     list(APPEND ASM_FLAGS -DHIGH_BIT_DEPTH=0 -DBIT_DEPTH=8 -DX265_NS=${X265_NS})</p><p>   endif()</p><p>-endif(ARM64)</p><p>+endif(ARM64 OR RISCV64)</p><p><br></p><p> option(WARNINGS_AS_ERRORS "Stop compiles on first warning" OFF)</p><p> if(WARNINGS_AS_ERRORS)</p><p>@@ -847,6 +920,19 @@ if((MSVC_IDE OR XCODE OR GCC) AND ENABLE_ASSEMBLY)</p><p>                     DEPENDS ${ASM_SRC})</p><p>             endforeach()</p><p>         endif()</p><p>+    elseif(RISCV64 OR CROSS_COMPILE_RISCV64)</p><p>+    # compile RISCV64 arch asm files here</p><p>+        enable_language(ASM)</p><p>+        foreach(ASM ${RISCV64_ASMS})</p><p>+            set(ASM_SRC ${CMAKE_CURRENT_SOURCE_DIR}/common/riscv64/${ASM})</p><p>+            list(APPEND ASM_SRCS ${ASM_SRC})</p><p>+            list(APPEND ASM_OBJS ${ASM}.${SUFFIX})</p><p>+            add_custom_command(</p><p>+                OUTPUT ${ASM}.${SUFFIX}</p><p>+                COMMAND ${CMAKE_CXX_COMPILER}</p><p>+                ARGS ${RISCV64_ARGS} ${ASM_FLAGS} -c ${ASM_SRC} -o ${ASM}.${SUFFIX}</p><p>+                DEPENDS ${ASM_SRC})</p><p>+        endforeach()</p><p>     elseif(X86)</p><p>     # compile X86 arch asm files here</p><p>         foreach(ASM ${MSVC_ASMS})</p><p>diff --git a/source/common/CMakeLists.txt b/source/common/CMakeLists.txt</p><p>index 2de780931..d88c00e61 100644</p><p>--- a/source/common/CMakeLists.txt</p><p>+++ b/source/common/CMakeLists.txt</p><p>@@ -164,6 +164,27 @@ if(ENABLE_ASSEMBLY AND (ARM64 OR CROSS_COMPILE_ARM64))</p><p>     endif()</p><p> endif(ENABLE_ASSEMBLY AND (ARM64 OR CROSS_COMPILE_ARM64))</p><p><br></p><p>+if(ENABLE_ASSEMBLY AND (RISCV64 OR CROSS_COMPILE_RISCV64))</p><p>+    if(GCC AND (CMAKE_CXX_FLAGS_RELEASE MATCHES "-O3"))</p><p>+        message(STATUS "Detected CXX compiler using -O3 optimization level")</p><p>+        add_definitions(-DAUTO_VECTORIZE=1)</p><p>+    endif()</p><p>+</p><p>+    # Add riscv64 intrinsics files here.</p><p>+    set(C_SRCS_RVV asm-primitives.cpp)</p><p>+    enable_language(ASM)</p><p>+</p><p>+    foreach(SRC ${C_SRCS_RVV})</p><p>+        set(ASM_PRIMITIVES ${ASM_PRIMITIVES} riscv64/${SRC})</p><p>+    endforeach()</p><p>+</p><p>+    source_group(Assembly FILES ${ASM_PRIMITIVES})</p><p>+</p><p>+    if(RISCV64_WARNINGS_AS_ERRORS)</p><p>+        set_source_files_properties(${ASM_PRIMITIVES} PROPERTIES COMPILE_FLAGS -Werror)</p><p>+    endif()</p><p>+endif(ENABLE_ASSEMBLY AND (RISCV64 OR CROSS_COMPILE_RISCV64))</p><p>+</p><p> if(POWER)</p><p>     set_source_files_properties(version.cpp PROPERTIES COMPILE_FLAGS -DX265_VERSION=${X265_VERSION})</p><p>     if(ENABLE_ALTIVEC)</p><p>diff --git a/source/common/cpu.cpp b/source/common/cpu.cpp</p><p>index 00defd837..c7ce9f3eb 100644</p><p>--- a/source/common/cpu.cpp</p><p>+++ b/source/common/cpu.cpp</p><p>@@ -129,6 +129,9 @@ const cpu_name_t cpu_names[] =</p><p> #elif X265_ARCH_POWER8</p><p>     { "Altivec",         X265_CPU_ALTIVEC },</p><p><br></p><p>+#elif X265_ARCH_RISCV64</p><p>+    { "RVV",           X265_CPU_RVV },</p><p>+</p><p> #endif // if X265_ARCH_X86</p><p>     { "", 0 },</p><p> };</p><p>@@ -409,6 +412,21 @@ uint32_t cpu_detect(bool benableavx512)</p><p>     return flags;</p><p> }</p><p><br></p><p>+#elif X265_ARCH_RISCV64</p><p>+#include "riscv64/cpu.h"</p><p>+</p><p>+uint32_t cpu_detect(bool benableavx512)</p><p>+{</p><p>+    (void)benableavx512;</p><p>+    int flags = 0;</p><p>+</p><p>+#ifdef ENABLE_ASSEMBLY</p><p>+    flags = riscv64_cpu_detect();</p><p>+#endif</p><p>+</p><p>+    return flags;</p><p>+}</p><p>+</p><p> #elif X265_ARCH_POWER8</p><p><br></p><p> uint32_t cpu_detect(bool benableavx512)</p><p>diff --git a/source/common/param.cpp b/source/common/param.cpp</p><p>index c06862b9e..b6ed8553c 100755</p><p>--- a/source/common/param.cpp</p><p>+++ b/source/common/param.cpp</p><p>@@ -1955,7 +1955,7 @@ int x265_check_params(x265_param* param)</p><p>             CHECK(param->hmeRange[level] < 0 || param->hmeRange[level] >= 32768,</p><p>                 "Search Range for HME levels must be between 0 and 32768");</p><p>     }</p><p>-#if !X86_64 && !X265_ARCH_ARM64</p><p>+#if !X86_64 && !X265_ARCH_ARM64 && !X265_ARCH_RISCV64</p><p>     CHECK(param->searchMethod == X265_SEA && (param->sourceWidth > 840 || param->sourceHeight > 480),</p><p>         "SEA motion search does not support resolutions greater than 480p in 32 bit build");</p><p> #endif</p><p>diff --git a/source/common/primitives.cpp b/source/common/primitives.cpp</p><p>index 83ebc455e..55f702c7b 100644</p><p>--- a/source/common/primitives.cpp</p><p>+++ b/source/common/primitives.cpp</p><p>@@ -91,7 +91,7 @@ void setupAliasPrimitives(EncoderPrimitives &p)</p><p>     /* at HIGH_BIT_DEPTH, pixel == short so we can alias many primitives */</p><p>     for (int i = 0; i < NUM_CU_SIZES; i++)</p><p>     {</p><p>-#if !defined(X265_ARCH_ARM64)</p><p>+#if !defined(X265_ARCH_ARM64) && !defined(X265_ARCH_RISCV64)</p><p>         p.cu[i].sse_pp = (pixel_sse_t)p.cu[i].sse_ss;</p><p> #endif</p><p><br></p><p>@@ -260,7 +260,7 @@ void x265_setup_primitives(x265_param *param)</p><p>             primitives.cu[i].intra_pred_allangs = NULL;</p><p><br></p><p> #if ENABLE_ASSEMBLY</p><p>-#if defined(X265_ARCH_X86) || defined(X265_ARCH_ARM64)</p><p>+#if defined(X265_ARCH_X86) || defined(X265_ARCH_ARM64) || defined(X265_ARCH_RISCV64)</p><p>         setupIntrinsicPrimitives(primitives, param->cpuid);</p><p> #endif</p><p>         setupAssemblyPrimitives(primitives, param->cpuid);</p><p>diff --git a/source/common/riscv64/asm-primitives.cpp b/source/common/riscv64/asm-primitives.cpp</p><p>new file mode 100644</p><p>index 000000000..edc04cbcd</p><p>--- /dev/null</p><p>+++ b/source/common/riscv64/asm-primitives.cpp</p><p>@@ -0,0 +1,59 @@</p><p>+/*****************************************************************************</p><p>+ * Copyright (C) 2020 MulticoreWare, Inc</p><p>+ *</p><p>+ * Authors: Changsheng Wu <wu.changsheng@sanechips.com.cn></p><p>+ *</p><p>+ * This program is free software; you can redistribute it and/or modify</p><p>+ * it under the terms of the GNU General Public License as published by</p><p>+ * the Free Software Foundation; either version 2 of the License, or</p><p>+ * (at your option) any later version.</p><p>+ *</p><p>+ * This program is distributed in the hope that it will be useful,</p><p>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</p><p>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</p><p>+ * GNU General Public License for more details.</p><p>+ *</p><p>+ * You should have received a copy of the GNU General Public License</p><p>+ * along with this program; if not, write to the Free Software</p><p>+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.</p><p>+ *</p><p>+ * This program is also available under a commercial proprietary license.</p><p>+ * For more information, contact us at license @ x265.com.</p><p>+ *****************************************************************************/</p><p>+</p><p>+</p><p>+#include "common.h"</p><p>+#include "primitives.h"</p><p>+#include "x265.h"</p><p>+#include "cpu.h"</p><p>+</p><p>+#if defined(__GNUC__)</p><p>+#define GCC_VERSION (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)</p><p>+#endif</p><p>+</p><p>+namespace X265_NS</p><p>+{</p><p>+// private x265 namespace</p><p>+</p><p>+</p><p>+void setupRVVPrimitives(EncoderPrimitives &p)</p><p>+{</p><p>+}</p><p>+</p><p>+void setupAssemblyPrimitives(EncoderPrimitives &p, int cpuMask)</p><p>+{</p><p>+    if (cpuMask & X265_CPU_RVV)</p><p>+    {</p><p>+        setupRVVPrimitives(p);</p><p>+    }</p><p>+}</p><p>+</p><p>+void setupIntrinsicPrimitives(EncoderPrimitives &p, int cpuMask)</p><p>+{</p><p>+    (void)p;</p><p>+    if (cpuMask & X265_CPU_RVV)</p><p>+    {</p><p>+    }</p><p>+}</p><p>+</p><p>+} // namespace X265_NS</p><p>diff --git a/source/common/riscv64/cpu.h b/source/common/riscv64/cpu.h</p><p>new file mode 100644</p><p>index 000000000..2f591c404</p><p>--- /dev/null</p><p>+++ b/source/common/riscv64/cpu.h</p><p>@@ -0,0 +1,70 @@</p><p>+/*****************************************************************************</p><p>+ * Copyright (C) 2025 MulticoreWare, Inc</p><p>+ *</p><p>+ * Authors: Changsheng Wu <wu.changsheng@sanechips.com.cn></p><p>+ *</p><p>+ * This program is free software; you can redistribute it and/or modify</p><p>+ * it under the terms of the GNU General Public License as published by</p><p>+ * the Free Software Foundation; either version 2 of the License, or</p><p>+ * (at your option) any later version.</p><p>+ *</p><p>+ * This program is distributed in the hope that it will be useful,</p><p>+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</p><p>+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</p><p>+ * GNU General Public License for more details.</p><p>+ *</p><p>+ * You should have received a copy of the GNU General Public License</p><p>+ * along with this program; if not, write to the Free Software</p><p>+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111, USA.</p><p>+ *</p><p>+ * This program is also available under a commercial proprietary license.</p><p>+ * For more information, contact us at license @ x265.com.</p><p>+ *****************************************************************************/</p><p>+</p><p>+#ifndef X265_COMMON_RISCV64_CPU_H</p><p>+#define X265_COMMON_RISCV64_CPU_H</p><p>+</p><p>+#include "x265.h"</p><p>+</p><p>+#if RISCV64_RUNTIME_CPU_DETECT</p><p>+</p><p>+#if defined(__linux__)</p><p>+</p><p>+#include <sys/auxv.h></p><p>+</p><p>+#define HWCAP_RISCV64_RVV     (1 << ('V' - 'A'))</p><p>+</p><p>+static inline int riscv64_cpu_detect()</p><p>+{</p><p>+    int flags = 0;</p><p>+</p><p>+    unsigned long hwcap = getauxval(AT_HWCAP);</p><p>+</p><p>+    if (hwcap & HWCAP_RISCV64_RVV)</p><p>+        flags |= X265_CPU_RVV;</p><p>+</p><p>+    return flags;</p><p>+}</p><p>+</p><p>+#else // defined(__linux__)</p><p>+#error                                                                 \</p><p>+    "Run-time CPU feature detection selected, but no detection method" \</p><p>+    "available for your platform. Rerun cmake configure with"          \</p><p>+    "-DRISCV64_RUNTIME_CPU_DETECT=OFF."</p><p>+#endif // defined(__linux__)</p><p>+</p><p>+#else // if AARCH64_RUNTIME_CPU_DETECT</p><p>+</p><p>+static inline int riscv64_cpu_detect()</p><p>+{</p><p>+    int flags = 0;</p><p>+</p><p>+#if HAVE_RVV</p><p>+    flags |= X265_CPU_RVV;</p><p>+#endif</p><p>+    return flags;</p><p>+}</p><p>+</p><p>+#endif // if RISCV64_RUNTIME_CPU_DETECT</p><p>+</p><p>+#endif // ifndef X265_COMMON_RISCV64_CPU_H</p><p>diff --git a/source/test/testbench.cpp b/source/test/testbench.cpp</p><p>index fb5b4252f..a93f131c0 100644</p><p>--- a/source/test/testbench.cpp</p><p>+++ b/source/test/testbench.cpp</p><p>@@ -96,7 +96,7 @@ struct test_arch_t</p><p>     { "AVX2", X265_CPU_AVX2 },</p><p>     { "BMI2", X265_CPU_AVX2 | X265_CPU_BMI1 | X265_CPU_BMI2 },</p><p>     { "AVX512", X265_CPU_AVX512 },</p><p>-#else</p><p>+#elif X265_ARCH_ARM64 || X265_ARCH_ARM</p><p>     { "ARMv6", X265_CPU_ARMV6 },</p><p>     { "NEON", X265_CPU_NEON },</p><p>     { "Neon_DotProd", X265_CPU_NEON_DOTPROD },</p><p>@@ -105,6 +105,8 @@ struct test_arch_t</p><p>     { "SVE2", X265_CPU_SVE2 },</p><p>     { "SVE2_BitPerm", X265_CPU_SVE2_BITPERM },</p><p>     { "FastNeonMRC", X265_CPU_FAST_NEON_MRC },</p><p>+#elif X265_ARCH_RISCV64</p><p>+    { "RVV", X265_CPU_RVV},</p><p> #endif</p><p>     { "", 0 },</p><p> };</p><p>@@ -226,7 +228,7 @@ int main(int argc, char *argv[])</p><p>         printf("Testing primitives: %s\n", testArch[i].name);</p><p>         fflush(stdout);</p><p><br></p><p>-#if defined(X265_ARCH_X86) || defined(X265_ARCH_ARM64)</p><p>+#if defined(X265_ARCH_X86) || defined(X265_ARCH_ARM64) || defined(X265_ARCH_RISCV64)</p><p>         EncoderPrimitives vecprim;</p><p>         memset(&vecprim, 0, sizeof(vecprim));</p><p>         setupIntrinsicPrimitives(vecprim, testArch[i].flag);</p><p>@@ -268,7 +270,7 @@ int main(int argc, char *argv[])</p><p>     {</p><p>         EncoderPrimitives optprim;</p><p>         memset(&optprim, 0, sizeof(optprim));</p><p>-#if defined(X265_ARCH_X86) || defined(X265_ARCH_ARM64)</p><p>+#if defined(X265_ARCH_X86) || defined(X265_ARCH_ARM64) || defined(X265_ARCH_RISCV64)</p><p>         setupIntrinsicPrimitives(optprim, cpuid);</p><p> #endif</p><p><br></p><p>diff --git a/source/test/testharness.h b/source/test/testharness.h</p><p>index 368c865ee..e54d05a8e 100644</p><p>--- a/source/test/testharness.h</p><p>+++ b/source/test/testharness.h</p><p>@@ -90,6 +90,8 @@ static inline uint32_t __rdtsc(void)</p><p> #elif  X265_ARCH_ARM64</p><p>     asm volatile("isb" : : : "memory");</p><p>     asm volatile("mrs %x0, cntvct_el0" : "=r"(a));</p><p>+#elif  X265_ARCH_RISCV64</p><p>+    asm volatile("rdtime %0" : "=r"(a));</p><p> #endif</p><p>     return a;</p><p> }</p><p>@@ -139,7 +141,7 @@ int PFX(stack_pagealign)(int (*func)(), int align);</p><p>  * needs an explicit asm check because it only sometimes crashes in normal use. */</p><p> intptr_t PFX(checkasm_call)(intptr_t (*func)(), int *ok, ...);</p><p> float PFX(checkasm_call_float)(float (*func)(), int *ok, ...);</p><p>-#elif (X265_ARCH_ARM == 0 && X265_ARCH_ARM64 == 0)</p><p>+#elif (X265_ARCH_ARM == 0 && X265_ARCH_ARM64 == 0 && X265_ARCH_RISCV64 == 0)</p><p> #define PFX(stack_pagealign)(func, align) func()</p><p> #endif</p><p><br></p><p>diff --git a/source/x265.h b/source/x265.h</p><p>index 31cd760e4..afd629d61 100644</p><p>--- a/source/x265.h</p><p>+++ b/source/x265.h</p><p>@@ -560,6 +560,9 @@ typedef enum</p><p> #define X265_CPU_NEON_I8MM       (1 << 6)   /* AArch64 Neon I8MM */</p><p> #define X265_CPU_SVE2_BITPERM    (1 << 7)   /* AArch64 SVE2 BitPerm */</p><p><br></p><p>+/* RISCV */</p><p>+#define X265_CPU_RVV             (1 << 0)   /* RISCV vector */</p><p>+</p><p> /* IBM Power8 */</p><p> #define X265_CPU_ALTIVEC         0x0000001</p><p><br></p><p>--</p><p>2.43.0</p><p style="font-size:14px;font-family:微软雅黑,Microsoft YaHei;"><br></p><p><br></p></div></blockquote></div></div></div></div></div><p><br></p></div>