[FFmpeg-cvslog] libavutil: Add av_clip_intp2

Peter Meerwald git at videolan.org
Sat Feb 21 11:15:26 CET 2015


ffmpeg | branch: master | Peter Meerwald <pmeerw at pmeerw.net> | Fri Feb 20 01:35:33 2015 +0100| [bf07d813f6c88b5a76980f321cf7272d799c4216] | committer: Luca Barbato

libavutil: Add av_clip_intp2

there already is a function, av_clip_uintp2() that clips a signed integer
to an unsigned power-of-two range, i.e. 0,2^p-1

this patch adds a function av_clip_intp2() that clips a signed integer
to a signed power-of-two range, i.e. -(2^p),(2^p-1)

the new function can be used as a special case for av_clip(), e.g.
av_clip(x, -8192, 8191) can be rewritten as av_clip_intp2(x, 13)

there are ARM instructions, usat and ssat resp., which map nicely to these
functions (see next patch)

Signed-off-by: Peter Meerwald <pmeerw at pmeerw.net>
Signed-off-by: Luca Barbato <lu_zero at gentoo.org>

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

 libavutil/common.h |   17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/libavutil/common.h b/libavutil/common.h
index eb40e12..3265f9c 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -153,6 +153,20 @@ static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a)
 }
 
 /**
+ * Clip a signed integer into the -(2^p),(2^p-1) range.
+ * @param  a value to clip
+ * @param  p bit position to clip at
+ * @return clipped value
+ */
+static av_always_inline av_const int av_clip_intp2_c(int a, int p)
+{
+    if ((a + (1 << p)) & ~((1 << (p + 1)) - 1))
+        return (a >> 31) ^ ((1 << p) - 1);
+    else
+        return a;
+}
+
+/**
  * Clip a signed integer to an unsigned power of two range.
  * @param  a value to clip
  * @param  p bit position to clip at
@@ -386,6 +400,9 @@ static av_always_inline av_const int av_popcount64_c(uint64_t x)
 #ifndef av_clipl_int32
 #   define av_clipl_int32   av_clipl_int32_c
 #endif
+#ifndef av_clip_intp2
+#   define av_clip_intp2    av_clip_intp2_c
+#endif
 #ifndef av_clip_uintp2
 #   define av_clip_uintp2   av_clip_uintp2_c
 #endif



More information about the ffmpeg-cvslog mailing list