"Ronald S. Bultje" <[email protected]> writes:

> Hi,
>
> 2011/5/13 Måns Rullgård <[email protected]>:
>> I'd prefer if argument were the number of bits to saturate at.  It could
>> also be used in few places in ac3dsp.c.
>>
>> Here's a patch I had sitting around for the unsigned version:
>>
>> diff --git a/libavutil/common.h b/libavutil/common.h
>> index 5814297..b694e63 100644
>> --- a/libavutil/common.h
>> +++ b/libavutil/common.h
>> @@ -169,6 +169,12 @@ static av_always_inline av_const int32_t 
>> av_clipl_int32_c(int64_t a)
>>     else                                         return a;
>>  }
>>
>> +static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
>> +{
>> +    if (a & ~((1<<p) - 1)) return -a >> 31 & ((1<<p) - 1);
>> +    else                   return  a;
>> +}
>> +
>>  /**
>>  * Clip a float value into the amin-amax range.
>>  * @param a value to clip
>> @@ -362,6 +368,9 @@ static av_always_inline av_const int 
>> av_popcount_c(uint32_t x)
>>  #ifndef av_clipl_int32
>>  #   define av_clipl_int32   av_clipl_int32_c
>>  #endif
>> +#ifndef av_clip_uintp2
>> +#   define av_clip_uintp2   av_clip_uintp2_c
>> +#endif
>>  #ifndef av_clipf
>>  #   define av_clipf         av_clipf_c
>>  #endif
>
> Looks fantastic to me, please apply, or else I'll integrate it here
> and redo my patches on top of it.

Proper patch attached.  Please test it with your (reworked) patch and
push if it works.

-- 
Måns Rullgård
[email protected]
>From ca27f1fcfd680901171e8323287803a83872b419 Mon Sep 17 00:00:00 2001
From: Mans Rullgard <[email protected]>
Date: Fri, 13 May 2011 16:39:17 +0100
Subject: [PATCH] Add av_clip_uintp2() function

Signed-off-by: Mans Rullgard <[email protected]>
---
 libavutil/common.h |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/libavutil/common.h b/libavutil/common.h
index e5c1dfd..a985fa4 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -170,6 +170,18 @@ static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a)
 }
 
 /**
+ * Clip a signed integer to an unsigned power of two range.
+ * @param  a value to clip
+ * @param  p bit position to clip at
+ * @return clipped value
+ */
+static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p)
+{
+    if (a & ~((1<<p) - 1)) return -a >> 31 & ((1<<p) - 1);
+    else                   return  a;
+}
+
+/**
  * Clip a float value into the amin-amax range.
  * @param a value to clip
  * @param amin minimum value of the clip range
@@ -362,6 +374,9 @@ static av_always_inline av_const int av_popcount_c(uint32_t x)
 #ifndef av_clipl_int32
 #   define av_clipl_int32   av_clipl_int32_c
 #endif
+#ifndef av_clip_uintp2
+#   define av_clip_uintp2   av_clip_uintp2_c
+#endif
 #ifndef av_clipf
 #   define av_clipf         av_clipf_c
 #endif
-- 
1.7.4.5

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to