[PR] riscv: asm: Move lx and sx macros to asm.S (PR #24230)

CheryDan via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <[email protected]>
PR #24230 opened by CheryDan
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24230
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24230.patch

# Move common `lx` and `sx` macros to `asm.S`

## Summary

Move the XLEN-dependent `lx` and `sx` assembly macros to the common `asm.S` header.

These macros are currently defined in multiple assembly files. Keeping a single shared definition avoids duplication and makes future maintenance easier.

## Changes

* Add the common `lx` and `sx` macro definitions to `asm.S`.
* Remove the duplicated definitions from individual assembly files.
* Reuse the shared macros from `asm.S`.

No functional behavior is changed by this patch.



>From a2a763cc428f740b3dc83bf4c3800022ee14c231 Mon Sep 17 00:00:00 2001
From: daichengrong <[email protected]>
Date: Fri, 21 Aug 2026 17:36:03 +0800
Subject: [PATCH] riscv: asm: Move lx and sx macros to asm.S

The lx and sx macros provide XLEN-dependent aliases for load and store
instructions and are currently duplicated in several assembly files.

Move the common definitions to asm.S and reuse them from there to avoid
duplicating the same macros across multiple files.

Signed-off-by: daichengrong <[email protected]>
---
 libavcodec/riscv/h264addpx_rvv.S | 10 ----------
 libavcodec/riscv/h264idct_rvv.S  | 10 ----------
 libavcodec/riscv/h264qpel_rvv.S  | 20 --------------------
 libavcodec/riscv/startcode_rvb.S | 10 ----------
 libavutil/riscv/asm.S            | 18 ++++++++++++++++++
 5 files changed, 18 insertions(+), 50 deletions(-)

diff --git a/libavcodec/riscv/h264addpx_rvv.S b/libavcodec/riscv/h264addpx_rvv.S
index 82739881d9..cf3b742294 100644
--- a/libavcodec/riscv/h264addpx_rvv.S
+++ b/libavcodec/riscv/h264addpx_rvv.S
@@ -26,16 +26,6 @@
 
 #include "libavutil/riscv/asm.S"
 
-        .macro  sx rd, addr
-#if (__riscv_xlen == 32)
-        sw      \rd, \addr
-#elif (__riscv_xlen == 64)
-        sd      \rd, \addr
-#else
-        sq      \rd, \addr
-#endif
-        .endm
-
 func ff_h264_add_pixels4_8_rvv, zve32x
         lpad    0
         vsetivli        zero, 4, e8, mf4, ta, ma
diff --git a/libavcodec/riscv/h264idct_rvv.S b/libavcodec/riscv/h264idct_rvv.S
index 2a40e87d62..7242dab9dc 100644
--- a/libavcodec/riscv/h264idct_rvv.S
+++ b/libavcodec/riscv/h264idct_rvv.S
@@ -29,16 +29,6 @@
 
 #include "libavutil/riscv/asm.S"
 
-        .macro  sx rd, addr
-#if (__riscv_xlen == 32)
-        sw      \rd, \addr
-#elif (__riscv_xlen == 64)
-        sd      \rd, \addr
-#else
-        sq      \rd, \addr
-#endif
-        .endm
-
         .variant_cc ff_h264_idct4_rvv
 func ff_h264_idct4_rvv, zve32x
         vsra.vi v5, v1, 1
diff --git a/libavcodec/riscv/h264qpel_rvv.S b/libavcodec/riscv/h264qpel_rvv.S
index df6796748f..5351bf918f 100644
--- a/libavcodec/riscv/h264qpel_rvv.S
+++ b/libavcodec/riscv/h264qpel_rvv.S
@@ -28,26 +28,6 @@
 
 #include "libavutil/riscv/asm.S"
 
-.macro  lx rd, addr
-#if (__riscv_xlen == 32)
-        lw      \rd, \addr
-#elif (__riscv_xlen == 64)
-        ld      \rd, \addr
-#else
-        lq      \rd, \addr
-#endif
-.endm
-
-.macro  sx rd, addr
-#if (__riscv_xlen == 32)
-        sw      \rd, \addr
-#elif (__riscv_xlen == 64)
-        sd      \rd, \addr
-#else
-        sq      \rd, \addr
-#endif
-.endm
-
 #define XSZ            (__riscv_xlen / 8)
 #define STACK_ALIGN(x) (((x) + 15) & ~15)
 
diff --git a/libavcodec/riscv/startcode_rvb.S b/libavcodec/riscv/startcode_rvb.S
index eec92d3340..c131ebdf59 100644
--- a/libavcodec/riscv/startcode_rvb.S
+++ b/libavcodec/riscv/startcode_rvb.S
@@ -26,16 +26,6 @@
 
 #include "libavutil/riscv/asm.S"
 
-        .macro  lx rd, addr
-#if (__riscv_xlen == 32)
-        lw      \rd, \addr
-#elif (__riscv_xlen == 64)
-        ld      \rd, \addr
-#else
-        lq      \rd, \addr
-#endif
-        .endm
-
 func ff_startcode_find_candidate_rvb, zbb
         lpad    0
         add     a1, a0, a1
diff --git a/libavutil/riscv/asm.S b/libavutil/riscv/asm.S
index ec68a042d1..d65fc94a61 100644
--- a/libavutil/riscv/asm.S
+++ b/libavutil/riscv/asm.S
@@ -237,3 +237,21 @@
         .macro  vntypei rd, rs, n=1
         vwtypei \rd, \rs, -(\n)
         .endm
+
+#if (__riscv_xlen == 32)
+        .macro  lx      rd, addr
+                lw      \rd, \addr
+        .endm
+
+        .macro  sx      rs, addr
+                sw      \rs, \addr
+        .endm
+#elif (__riscv_xlen == 64)
+        .macro  lx      rd, addr
+                ld      \rd, \addr
+        .endm
+
+        .macro  sx      rs, addr
+                sd      \rs, \addr
+        .endm
+#endif
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.