[FFmpeg-cvslog] arm: Check the build time constants in av_clip_*intp2

Martin Storsjö git at videolan.org
Fri Sep 2 23:31:13 EEST 2022


ffmpeg | branch: master | Martin Storsjö <martin at martin.st> | Fri Aug 26 11:26:32 2022 +0300| [0dd8fe6f4b072077d2d87eb3a2933e145ac41df1] | committer: Martin Storsjö

arm: Check the build time constants in av_clip_*intp2

This fixes building for arm targets with optimizations disabled.

Signed-off-by: Martin Storsjö <martin at martin.st>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=0dd8fe6f4b072077d2d87eb3a2933e145ac41df1
---

 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



More information about the ffmpeg-cvslog mailing list