Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
* [FFmpeg-devel] [PATCH] arm: Skip certain inline assembly functions if built without optimizations
@ 2022-08-26  8:34 Martin Storsjö
  2022-08-26 12:48 ` James Almer
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Storsjö @ 2022-08-26  8:34 UTC (permalink / raw)
  To: ffmpeg-devel

These inline assembly functions rely on being inlined into the
caller, so that the parameter "int p" can be a known assembly time
constant, instead of a variable parameter.

__OPTIMIZE__ is a built-in define which is set by both GCC and Clang
(the two main compilers supporting our inline assembly) when
optimizations are enabled.

This fixes building for arm targets with optimizations disabled.
---
With older GCC versions, the inline assembly in libavcodec/arm/aac.h
also might need to be disabled, but it does build successfully
with optimizations disabled with modern LLVM and GCC, so not touching
it immediately as part of this patch.
---
 libavutil/arm/intmath.h | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libavutil/arm/intmath.h b/libavutil/arm/intmath.h
index 5311a7d52b..67a8e72dc0 100644
--- a/libavutil/arm/intmath.h
+++ b/libavutil/arm/intmath.h
@@ -62,6 +62,7 @@ static av_always_inline av_const int av_clip_int16_arm(int a)
     return x;
 }
 
+#ifdef __OPTIMIZE__
 #define av_clip_intp2 av_clip_intp2_arm
 static av_always_inline av_const int av_clip_intp2_arm(int a, int p)
 {
@@ -77,6 +78,7 @@ static av_always_inline av_const unsigned av_clip_uintp2_arm(int a, int p)
     __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
     return x;
 }
+#endif
 
 #define av_sat_add32 av_sat_add32_arm
 static av_always_inline int av_sat_add32_arm(int a, int b)
-- 
2.25.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH] arm: Skip certain inline assembly functions if built without optimizations
  2022-08-26  8:34 [FFmpeg-devel] [PATCH] arm: Skip certain inline assembly functions if built without optimizations Martin Storsjö
@ 2022-08-26 12:48 ` James Almer
  2022-08-26 19:30   ` [FFmpeg-devel] [PATCH v2] arm: Check the build time constants in av_clip_*intp2 Martin Storsjö
  0 siblings, 1 reply; 4+ messages in thread
From: James Almer @ 2022-08-26 12:48 UTC (permalink / raw)
  To: ffmpeg-devel

On 8/26/2022 5:34 AM, Martin Storsjö wrote:
> These inline assembly functions rely on being inlined into the
> caller, so that the parameter "int p" can be a known assembly time
> constant, instead of a variable parameter.
> 
> __OPTIMIZE__ is a built-in define which is set by both GCC and Clang
> (the two main compilers supporting our inline assembly) when
> optimizations are enabled.
> 
> This fixes building for arm targets with optimizations disabled.

You could instead use av_builtin_constant_p() to check this at compile 
time. See how it's used for av_mod_uintp2_bmi2() in libavutil/x86/intmath.h

> ---
> With older GCC versions, the inline assembly in libavcodec/arm/aac.h
> also might need to be disabled, but it does build successfully
> with optimizations disabled with modern LLVM and GCC, so not touching
> it immediately as part of this patch.
> ---
>   libavutil/arm/intmath.h | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/libavutil/arm/intmath.h b/libavutil/arm/intmath.h
> index 5311a7d52b..67a8e72dc0 100644
> --- a/libavutil/arm/intmath.h
> +++ b/libavutil/arm/intmath.h
> @@ -62,6 +62,7 @@ static av_always_inline av_const int av_clip_int16_arm(int a)
>       return x;
>   }
>   
> +#ifdef __OPTIMIZE__
>   #define av_clip_intp2 av_clip_intp2_arm
>   static av_always_inline av_const int av_clip_intp2_arm(int a, int p)
>   {
> @@ -77,6 +78,7 @@ static av_always_inline av_const unsigned av_clip_uintp2_arm(int a, int p)
>       __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
>       return x;
>   }
> +#endif
>   
>   #define av_sat_add32 av_sat_add32_arm
>   static av_always_inline int av_sat_add32_arm(int a, int b)
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [FFmpeg-devel] [PATCH v2] arm: Check the build time constants in av_clip_*intp2
  2022-08-26 12:48 ` James Almer
@ 2022-08-26 19:30   ` Martin Storsjö
  2022-09-02 13:26     ` Martin Storsjö
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Storsjö @ 2022-08-26 19:30 UTC (permalink / raw)
  To: ffmpeg-devel

This fixes building for arm targets with optimizations disabled.
---
 libavutil/arm/intmath.h | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)

diff --git a/libavutil/arm/intmath.h b/libavutil/arm/intmath.h
index 5311a7d52b..f19b21e98d 100644
--- a/libavutil/arm/intmath.h
+++ b/libavutil/arm/intmath.h
@@ -65,17 +65,29 @@ static av_always_inline av_const int av_clip_int16_arm(int a)
 #define av_clip_intp2 av_clip_intp2_arm
 static av_always_inline av_const int av_clip_intp2_arm(int a, int p)
 {
-    unsigned x;
-    __asm__ ("ssat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p+1));
-    return x;
+    if (av_builtin_constant_p(p)) {
+        unsigned x;
+        __asm__ ("ssat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p+1));
+        return x;
+    } else {
+        if (((unsigned)a + (1 << p)) & ~((2 << p) - 1))
+            return (a >> 31) ^ ((1 << p) - 1);
+        else
+            return a;
+    }
 }
 
 #define av_clip_uintp2 av_clip_uintp2_arm
 static av_always_inline av_const unsigned av_clip_uintp2_arm(int a, int p)
 {
-    unsigned x;
-    __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
-    return x;
+    if (av_builtin_constant_p(p)) {
+        unsigned x;
+        __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
+        return x;
+    } else {
+        if (a & ~((1<<p) - 1)) return (~a) >> 31 & ((1<<p) - 1);
+        else                   return  a;
+    }
 }
 
 #define av_sat_add32 av_sat_add32_arm
-- 
2.25.1

_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [FFmpeg-devel] [PATCH v2] arm: Check the build time constants in av_clip_*intp2
  2022-08-26 19:30   ` [FFmpeg-devel] [PATCH v2] arm: Check the build time constants in av_clip_*intp2 Martin Storsjö
@ 2022-09-02 13:26     ` Martin Storsjö
  0 siblings, 0 replies; 4+ messages in thread
From: Martin Storsjö @ 2022-09-02 13:26 UTC (permalink / raw)
  To: ffmpeg-devel

On Fri, 26 Aug 2022, Martin Storsjö wrote:

> This fixes building for arm targets with optimizations disabled.
> ---
> libavutil/arm/intmath.h | 24 ++++++++++++++++++------
> 1 file changed, 18 insertions(+), 6 deletions(-)
>
> diff --git a/libavutil/arm/intmath.h b/libavutil/arm/intmath.h
> index 5311a7d52b..f19b21e98d 100644
> --- a/libavutil/arm/intmath.h
> +++ b/libavutil/arm/intmath.h
> @@ -65,17 +65,29 @@ static av_always_inline av_const int av_clip_int16_arm(int a)
> #define av_clip_intp2 av_clip_intp2_arm
> static av_always_inline av_const int av_clip_intp2_arm(int a, int p)
> {
> -    unsigned x;
> -    __asm__ ("ssat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p+1));
> -    return x;
> +    if (av_builtin_constant_p(p)) {
> +        unsigned x;
> +        __asm__ ("ssat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p+1));
> +        return x;
> +    } else {
> +        if (((unsigned)a + (1 << p)) & ~((2 << p) - 1))
> +            return (a >> 31) ^ ((1 << p) - 1);
> +        else
> +            return a;
> +    }
> }
>
> #define av_clip_uintp2 av_clip_uintp2_arm
> static av_always_inline av_const unsigned av_clip_uintp2_arm(int a, int p)
> {
> -    unsigned x;
> -    __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
> -    return x;
> +    if (av_builtin_constant_p(p)) {
> +        unsigned x;
> +        __asm__ ("usat %0, %2, %1" : "=r"(x) : "r"(a), "i"(p));
> +        return x;
> +    } else {
> +        if (a & ~((1<<p) - 1)) return (~a) >> 31 & ((1<<p) - 1);
> +        else                   return  a;
> +    }
> }
>
> #define av_sat_add32 av_sat_add32_arm
> -- 
> 2.25.1

OK'd by James on irc, will push later today.

// Martin
_______________________________________________
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".

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-09-02 13:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26  8:34 [FFmpeg-devel] [PATCH] arm: Skip certain inline assembly functions if built without optimizations Martin Storsjö
2022-08-26 12:48 ` James Almer
2022-08-26 19:30   ` [FFmpeg-devel] [PATCH v2] arm: Check the build time constants in av_clip_*intp2 Martin Storsjö
2022-09-02 13:26     ` Martin Storsjö

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git