diff mbox series

[FFmpeg-devel,4/7] avutil/riscv/asm: add stack pushing helpers

Message ID 20240813140338.143045-4-jdek@itanimul.li
State New
Headers show
Series [FFmpeg-devel,1/7] checkasm: add csv/tsv bench output | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished

Commit Message

J. Dekker Aug. 13, 2024, 2:03 p.m. UTC
From: Niklas Haas <git@haasn.dev>

Instead of duplicating these common macros in every file, add them to
the shared utility file. Also add a base case for sanity.
---
 libavcodec/riscv/h264addpx_rvv.S | 10 ----------
 libavcodec/riscv/h264idct_rvv.S  | 10 ----------
 libavcodec/riscv/startcode_rvb.S | 10 ----------
 libavutil/riscv/asm.S            | 34 ++++++++++++++++++++++++++++++++
 4 files changed, 34 insertions(+), 30 deletions(-)

Comments

Rémi Denis-Courmont Aug. 13, 2024, 3:51 p.m. UTC | #1
Le 13 août 2024 17:03:33 GMT+03:00, "J. Dekker" <jdek@itanimul.li> a écrit :
>From: Niklas Haas <git@haasn.dev>
>
>Instead of duplicating these common macros in every file, add them to
>the shared utility file. Also add a base case for sanity.

Is `#error` a standard directive of C11?

>---
> libavcodec/riscv/h264addpx_rvv.S | 10 ----------
> libavcodec/riscv/h264idct_rvv.S  | 10 ----------
> libavcodec/riscv/startcode_rvb.S | 10 ----------
> libavutil/riscv/asm.S            | 34 ++++++++++++++++++++++++++++++++
> 4 files changed, 34 insertions(+), 30 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 d2f77a5b47..076935a5d5 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/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..175f2a8672 100644
>--- a/libavutil/riscv/asm.S
>+++ b/libavutil/riscv/asm.S
>@@ -237,3 +237,37 @@
>         .macro  vntypei rd, rs, n=1
>         vwtypei \rd, \rs, -(\n)
>         .endm
>+
>+        /**
>+         * Write an XLEN-sized register to an address.
>+         * @param rs source register
>+         * @param addr address to write to
>+         */
>+        .macro  sx rs, addr
>+#if (__riscv_xlen == 32)
>+        sw      \rs, \addr
>+#elif (__riscv_xlen == 64)
>+        sd      \rs, \addr
>+#elif (__riscv_xlen == 128)
>+        sq      \rs, \addr
>+#else
>+#error Unhandled value of XLEN
>+#endif
>+        .endm
>+
>+        /**
>+         * Read an XLEN-sized register from an address.
>+         * @param[out] rd destination register
>+         * @param addr address to read from
>+         */
>+        .macro  lx rd, addr
>+#if (__riscv_xlen == 32)
>+        lw      \rd, \addr
>+#elif (__riscv_xlen == 64)
>+        ld      \rd, \addr
>+#elif (__riscv_xlen == 128)
>+        lq      \rd, \addr
>+#else
>+#error Unhandled value of XLEN
>+#endif
>+        .endm
Marvin Scholz Aug. 13, 2024, 4:10 p.m. UTC | #2
On 13 Aug 2024, at 17:51, Rémi Denis-Courmont wrote:

> Le 13 août 2024 17:03:33 GMT+03:00, "J. Dekker" <jdek@itanimul.li> a écrit :
>> From: Niklas Haas <git@haasn.dev>
>>
>> Instead of duplicating these common macros in every file, add them to
>> the shared utility file. Also add a base case for sanity.
>
> Is `#error` a standard directive of C11?

The #error directive dates back to C89:
https://en.cppreference.com/w/c/preprocessor/error

>
>> ---
>> libavcodec/riscv/h264addpx_rvv.S | 10 ----------
>> libavcodec/riscv/h264idct_rvv.S  | 10 ----------
>> libavcodec/riscv/startcode_rvb.S | 10 ----------
>> libavutil/riscv/asm.S            | 34 ++++++++++++++++++++++++++++++++
>> 4 files changed, 34 insertions(+), 30 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 d2f77a5b47..076935a5d5 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/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..175f2a8672 100644
>> --- a/libavutil/riscv/asm.S
>> +++ b/libavutil/riscv/asm.S
>> @@ -237,3 +237,37 @@
>>         .macro  vntypei rd, rs, n=1
>>         vwtypei \rd, \rs, -(\n)
>>         .endm
>> +
>> +        /**
>> +         * Write an XLEN-sized register to an address.
>> +         * @param rs source register
>> +         * @param addr address to write to
>> +         */
>> +        .macro  sx rs, addr
>> +#if (__riscv_xlen == 32)
>> +        sw      \rs, \addr
>> +#elif (__riscv_xlen == 64)
>> +        sd      \rs, \addr
>> +#elif (__riscv_xlen == 128)
>> +        sq      \rs, \addr
>> +#else
>> +#error Unhandled value of XLEN
>> +#endif
>> +        .endm
>> +
>> +        /**
>> +         * Read an XLEN-sized register from an address.
>> +         * @param[out] rd destination register
>> +         * @param addr address to read from
>> +         */
>> +        .macro  lx rd, addr
>> +#if (__riscv_xlen == 32)
>> +        lw      \rd, \addr
>> +#elif (__riscv_xlen == 64)
>> +        ld      \rd, \addr
>> +#elif (__riscv_xlen == 128)
>> +        lq      \rd, \addr
>> +#else
>> +#error Unhandled value of XLEN
>> +#endif
>> +        .endm
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Rémi Denis-Courmont Aug. 13, 2024, 4:13 p.m. UTC | #3
Le 13 août 2024 19:10:48 GMT+03:00, epirat07@gmail.com a écrit :
>On 13 Aug 2024, at 17:51, Rémi Denis-Courmont wrote:
>
>> Le 13 août 2024 17:03:33 GMT+03:00, "J. Dekker" <jdek@itanimul.li> a écrit :
>>> From: Niklas Haas <git@haasn.dev>
>>>
>>> Instead of duplicating these common macros in every file, add them to
>>> the shared utility file. Also add a base case for sanity.
>>
>> Is `#error` a standard directive of C11?
>
>The #error directive dates back to C89:
>https://en.cppreference.com/w/c/preprocessor/error

Ok thanks. Any reason not to use an assembler directive though?

>>
>>> ---
>>> libavcodec/riscv/h264addpx_rvv.S | 10 ----------
>>> libavcodec/riscv/h264idct_rvv.S  | 10 ----------
>>> libavcodec/riscv/startcode_rvb.S | 10 ----------
>>> libavutil/riscv/asm.S            | 34 ++++++++++++++++++++++++++++++++
>>> 4 files changed, 34 insertions(+), 30 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 d2f77a5b47..076935a5d5 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/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..175f2a8672 100644
>>> --- a/libavutil/riscv/asm.S
>>> +++ b/libavutil/riscv/asm.S
>>> @@ -237,3 +237,37 @@
>>>         .macro  vntypei rd, rs, n=1
>>>         vwtypei \rd, \rs, -(\n)
>>>         .endm
>>> +
>>> +        /**
>>> +         * Write an XLEN-sized register to an address.
>>> +         * @param rs source register
>>> +         * @param addr address to write to
>>> +         */
>>> +        .macro  sx rs, addr
>>> +#if (__riscv_xlen == 32)
>>> +        sw      \rs, \addr
>>> +#elif (__riscv_xlen == 64)
>>> +        sd      \rs, \addr
>>> +#elif (__riscv_xlen == 128)
>>> +        sq      \rs, \addr
>>> +#else
>>> +#error Unhandled value of XLEN
>>> +#endif
>>> +        .endm
>>> +
>>> +        /**
>>> +         * Read an XLEN-sized register from an address.
>>> +         * @param[out] rd destination register
>>> +         * @param addr address to read from
>>> +         */
>>> +        .macro  lx rd, addr
>>> +#if (__riscv_xlen == 32)
>>> +        lw      \rd, \addr
>>> +#elif (__riscv_xlen == 64)
>>> +        ld      \rd, \addr
>>> +#elif (__riscv_xlen == 128)
>>> +        lq      \rd, \addr
>>> +#else
>>> +#error Unhandled value of XLEN
>>> +#endif
>>> +        .endm
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
>_______________________________________________
>ffmpeg-devel mailing list
>ffmpeg-devel@ffmpeg.org
>https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>To unsubscribe, visit link above, or email
>ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
diff mbox series

Patch

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 d2f77a5b47..076935a5d5 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/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..175f2a8672 100644
--- a/libavutil/riscv/asm.S
+++ b/libavutil/riscv/asm.S
@@ -237,3 +237,37 @@ 
         .macro  vntypei rd, rs, n=1
         vwtypei \rd, \rs, -(\n)
         .endm
+
+        /**
+         * Write an XLEN-sized register to an address.
+         * @param rs source register
+         * @param addr address to write to
+         */
+        .macro  sx rs, addr
+#if (__riscv_xlen == 32)
+        sw      \rs, \addr
+#elif (__riscv_xlen == 64)
+        sd      \rs, \addr
+#elif (__riscv_xlen == 128)
+        sq      \rs, \addr
+#else
+#error Unhandled value of XLEN
+#endif
+        .endm
+
+        /**
+         * Read an XLEN-sized register from an address.
+         * @param[out] rd destination register
+         * @param addr address to read from
+         */
+        .macro  lx rd, addr
+#if (__riscv_xlen == 32)
+        lw      \rd, \addr
+#elif (__riscv_xlen == 64)
+        ld      \rd, \addr
+#elif (__riscv_xlen == 128)
+        lq      \rd, \addr
+#else
+#error Unhandled value of XLEN
+#endif
+        .endm