2012/1/2 Måns Rullgård <[email protected]>:
> Daniel Verkamp <[email protected]> writes:
>
>> ---
>>  libavutil/common.h |   18 ++++++++++++++++++
>>  1 files changed, 18 insertions(+), 0 deletions(-)
>>
>> diff --git a/libavutil/common.h b/libavutil/common.h
>> index 7e93a1a..847b8d6 100644
>> --- a/libavutil/common.h
>> +++ b/libavutil/common.h
>> @@ -218,6 +218,21 @@ static av_always_inline av_const int 
>> av_popcount_c(uint32_t x)
>>      return (x + (x >> 16)) & 0x3F;
>>  }
>>
>> +/**
>> + * Count number of bits set to one in x
>> + * @param x value to count bits of
>> + * @return the number of bits set to one in x
>> + */
>> +static av_always_inline av_const int av_popcount64_c(uint64_t x)
>> +{
>> +    x -= ((x >> 1) & 0x5555555555555555);
>> +    x = (x & 0x3333333333333333) + ((x  >> 2) & 0x3333333333333333);
>> +    x =    (x + (x >> 4))  & 0x0F0F0F0F0F0F0F0F;
>> +    x =    (x + (x >> 8))  & 0x00FF00FF00FF00FF;
>> +    x =    (x + (x >> 16)) & 0x0000FFFF0000FFFF;
>> +    return (x + (x >> 32)) & 0x7F;
>> +}
>
> Why not av_popcount32(x) + av_popcount32(x >> 32)?  That way it will
> make use of any special 32-bit popcount implementation that might be
> available.  If there is none, it should compile to the same code as your
> version.
>

That's probably saner (although it generates more code for x86-64).
Patch attached.
From b7cf33bf2dbe74f168d20e721612ec95a8ae1a0c Mon Sep 17 00:00:00 2001
From: Daniel Verkamp <[email protected]>
Date: Sun, 1 Jan 2012 17:18:16 -0700
Subject: [PATCH 1/2] Add av_popcount64

---
 libavutil/common.h |   13 +++++++++++++
 1 files changed, 13 insertions(+), 0 deletions(-)

diff --git a/libavutil/common.h b/libavutil/common.h
index 7e93a1a..c99d858 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -218,6 +218,16 @@ static av_always_inline av_const int 
av_popcount_c(uint32_t x)
     return (x + (x >> 16)) & 0x3F;
 }
 
+/**
+ * Count number of bits set to one in x
+ * @param x value to count bits of
+ * @return the number of bits set to one in x
+ */
+static av_always_inline av_const int av_popcount64_c(uint64_t x)
+{
+    return av_popcount(x) + av_popcount(x >> 32);
+}
+
 #define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24))
 #define MKBETAG(a,b,c,d) ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 
24))
 
@@ -383,3 +393,6 @@ static av_always_inline av_const int av_popcount_c(uint32_t 
x)
 #ifndef av_popcount
 #   define av_popcount      av_popcount_c
 #endif
+#ifndef av_popcount64
+#   define av_popcount64    av_popcount64_c
+#endif
-- 
1.7.8

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

Reply via email to