diff mbox series

[FFmpeg-devel,v3,4/4] avcodec/mips: cabac.h provide fallback for wsbh instruction

Message ID 20210723055344.21961-5-jiaxun.yang@flygoat.com
State New
Headers show
Series avcodec Loongson-2 MMI fixes | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Jiaxun Yang July 23, 2021, 5:53 a.m. UTC
wsbh is only avilable for MIPS R2+.
Provide a fallback for older processors.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
Reviewed-by: Shiyou Yin <yinshiyou-hf@loongson.cn>
---
 libavcodec/mips/cabac.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Shiyou Yin July 28, 2021, 1:53 a.m. UTC | #1
> 2021年7月23日 下午1:53,Jiaxun Yang <jiaxun.yang@flygoat.com> 写道:
> 
> wsbh is only avilable for MIPS R2+.
> Provide a fallback for older processors.
> 
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> Reviewed-by: Shiyou Yin <yinshiyou-hf@loongson.cn>
> ---
> libavcodec/mips/cabac.h | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
> 
> diff --git a/libavcodec/mips/cabac.h b/libavcodec/mips/cabac.h
> index f1e953dabe..39c308c7e0 100644
> --- a/libavcodec/mips/cabac.h
> +++ b/libavcodec/mips/cabac.h
> @@ -77,7 +77,15 @@ static av_always_inline int get_cabac_inline_mips(CABACContext *c,
>         "lhu          %[tmp0],       0(%[c_bytestream])            \n\t"
> #else
>         "lhu          %[tmp0],       0(%[c_bytestream])            \n\t"
> +#if HAVE_MIPS32R2 || HAVE_MIPS64R2
>         "wsbh         %[tmp0],       %[tmp0]                       \n\t"
> +#else
> +        "and          %[tmp1],      %[tmp0],         0xff00ff00    \n\t"
> +        "srl          %[tmp1],      %[tmp1],         8             \n\t"
> +        "and          %[tmp0],      %[tmp0],         0x00ff00ff    \n\t"
> +        "sll          %[tmp0],      %[tmp0],         8             \n\t"
> +        "or           %[tmp0],      %[tmp0],         %[tmp1]       \n\t"
> +#endif
> #endif
>         PTR_SLL      "%[tmp0],       %[tmp0],        0x01          \n\t"
>         PTR_SUBU     "%[tmp0],       %[tmp0],        %[cabac_mask] \n\t"
> @@ -125,7 +133,15 @@ static av_always_inline int get_cabac_bypass_mips(CABACContext *c)
>         "lhu        %[tmp1],         0(%[c_bytestream])                   \n\t"
> #else
>         "lhu        %[tmp1],         0(%[c_bytestream])                   \n\t"
> +#if HAVE_MIPS32R2 || HAVE_MIPS64R2
>         "wsbh       %[tmp1],         %[tmp1]                              \n\t"
> +#else
> +        "and        %[tmp0],         %[tmp1],         0xff00ff00          \n\t"
> +        "srl        %[tmp0],         %[tmp0],         8                   \n\t"
> +        "and        %[tmp1],         %[tmp1],         0x00ff00ff          \n\t"
> +        "sll        %[tmp1],         %[tmp1],         8                   \n\t"
> +        "or         %[tmp1],         %[tmp1],         %[tmp0]             \n\t"
> +#endif
> #endif
>         PTR_SLL    "%[tmp1],         %[tmp1],         0x01                \n\t"
>         PTR_SUBU   "%[tmp1],         %[tmp1],         %[cabac_mask]       \n\t"
> @@ -169,7 +185,15 @@ static av_always_inline int get_cabac_bypass_sign_mips(CABACContext *c, int val)
>         "lhu        %[tmp1],         0(%[c_bytestream])                   \n\t"
> #else
>         "lhu        %[tmp1],         0(%[c_bytestream])                   \n\t"
> +#if HAVE_MIPS32R2 || HAVE_MIPS64R2
>         "wsbh       %[tmp1],         %[tmp1]                              \n\t"
> +#else
> +        "and        %[tmp0],         %[tmp1],         0xff00ff00          \n\t"
> +        "srl        %[tmp0],         %[tmp0],         8                   \n\t"
> +        "and        %[tmp1],         %[tmp1],         0x00ff00ff          \n\t"
> +        "sll        %[tmp1],         %[tmp1],         8                   \n\t"
> +        "or         %[tmp1],         %[tmp1],         %[tmp0]             \n\t"
> +#endif
> #endif
>         PTR_SLL    "%[tmp1],         %[tmp1],         0x01                \n\t"
>         PTR_SUBU   "%[tmp1],         %[tmp1],         %[cabac_mask]       \n\t"
> -- 
> 2.32.0

LGTM
diff mbox series

Patch

diff --git a/libavcodec/mips/cabac.h b/libavcodec/mips/cabac.h
index f1e953dabe..39c308c7e0 100644
--- a/libavcodec/mips/cabac.h
+++ b/libavcodec/mips/cabac.h
@@ -77,7 +77,15 @@  static av_always_inline int get_cabac_inline_mips(CABACContext *c,
         "lhu          %[tmp0],       0(%[c_bytestream])            \n\t"
 #else
         "lhu          %[tmp0],       0(%[c_bytestream])            \n\t"
+#if HAVE_MIPS32R2 || HAVE_MIPS64R2
         "wsbh         %[tmp0],       %[tmp0]                       \n\t"
+#else
+        "and          %[tmp1],      %[tmp0],         0xff00ff00    \n\t"
+        "srl          %[tmp1],      %[tmp1],         8             \n\t"
+        "and          %[tmp0],      %[tmp0],         0x00ff00ff    \n\t"
+        "sll          %[tmp0],      %[tmp0],         8             \n\t"
+        "or           %[tmp0],      %[tmp0],         %[tmp1]       \n\t"
+#endif
 #endif
         PTR_SLL      "%[tmp0],       %[tmp0],        0x01          \n\t"
         PTR_SUBU     "%[tmp0],       %[tmp0],        %[cabac_mask] \n\t"
@@ -125,7 +133,15 @@  static av_always_inline int get_cabac_bypass_mips(CABACContext *c)
         "lhu        %[tmp1],         0(%[c_bytestream])                   \n\t"
 #else
         "lhu        %[tmp1],         0(%[c_bytestream])                   \n\t"
+#if HAVE_MIPS32R2 || HAVE_MIPS64R2
         "wsbh       %[tmp1],         %[tmp1]                              \n\t"
+#else
+        "and        %[tmp0],         %[tmp1],         0xff00ff00          \n\t"
+        "srl        %[tmp0],         %[tmp0],         8                   \n\t"
+        "and        %[tmp1],         %[tmp1],         0x00ff00ff          \n\t"
+        "sll        %[tmp1],         %[tmp1],         8                   \n\t"
+        "or         %[tmp1],         %[tmp1],         %[tmp0]             \n\t"
+#endif
 #endif
         PTR_SLL    "%[tmp1],         %[tmp1],         0x01                \n\t"
         PTR_SUBU   "%[tmp1],         %[tmp1],         %[cabac_mask]       \n\t"
@@ -169,7 +185,15 @@  static av_always_inline int get_cabac_bypass_sign_mips(CABACContext *c, int val)
         "lhu        %[tmp1],         0(%[c_bytestream])                   \n\t"
 #else
         "lhu        %[tmp1],         0(%[c_bytestream])                   \n\t"
+#if HAVE_MIPS32R2 || HAVE_MIPS64R2
         "wsbh       %[tmp1],         %[tmp1]                              \n\t"
+#else
+        "and        %[tmp0],         %[tmp1],         0xff00ff00          \n\t"
+        "srl        %[tmp0],         %[tmp0],         8                   \n\t"
+        "and        %[tmp1],         %[tmp1],         0x00ff00ff          \n\t"
+        "sll        %[tmp1],         %[tmp1],         8                   \n\t"
+        "or         %[tmp1],         %[tmp1],         %[tmp0]             \n\t"
+#endif
 #endif
         PTR_SLL    "%[tmp1],         %[tmp1],         0x01                \n\t"
         PTR_SUBU   "%[tmp1],         %[tmp1],         %[cabac_mask]       \n\t"