Patchwork avutil: change GET_UTF8 to not use av_log2()

login
register
mail settings
Submitter Mans Rullgard
Date Nov. 13, 2012, 3:50 p.m.
Message ID <1352821811-22393-1-git-send-email-mans@mansr.com>
Download mbox | patch
Permalink /patch/30530/
State Committed
Commit 7ba0c1b390a6ea67ca5e9cbade3005285b51b70f
Headers show

Comments

Mans Rullgard - Nov. 13, 2012, 3:50 p.m.
This removes an inter-library dependency on ff_log2_tab causing
linking errors in some configurations.

Signed-off-by: Mans Rullgard <mans@mansr.com>
---
 libavutil/common.h | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
Luca Barbato - Nov. 13, 2012, 4:50 p.m.
On 11/13/2012 04:50 PM, Mans Rullgard wrote:
> This removes an inter-library dependency on ff_log2_tab causing
> linking errors in some configurations.

Looks nicer.
Reinhard Tartler - Nov. 13, 2012, 5:28 p.m.
On Tue, Nov 13, 2012 at 4:50 PM, Mans Rullgard <mans@mansr.com> wrote:
> This removes an inter-library dependency on ff_log2_tab causing
> linking errors in some configurations.
>
> Signed-off-by: Mans Rullgard <mans@mansr.com>
> ---
>  libavutil/common.h | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/libavutil/common.h b/libavutil/common.h
> index 3465863..cc4df16 100644
> --- a/libavutil/common.h
> +++ b/libavutil/common.h
> @@ -252,16 +252,17 @@ static av_always_inline av_const int av_popcount64_c(uint64_t x)
>  #define GET_UTF8(val, GET_BYTE, ERROR)\
>      val= GET_BYTE;\
>      {\
> -        int ones= 7 - av_log2(val ^ 255);\
> -        if(ones==1)\
> +        uint32_t top = (val & 128) >> 1;\
> +        if ((val & 0xc0) == 0x80)\
>              ERROR\
> -        val&= 127>>ones;\
> -        while(--ones > 0){\
> +        while (val & top) {\
>              int tmp= GET_BYTE - 128;\
>              if(tmp>>6)\
>                  ERROR\
>              val= (val<<6) + tmp;\
> +            top <<= 5;\
>          }\
> +        val &= (top << 1) - 1;\
>      }
>
>  /**
> --

I can confirm that this patch unbreaks the ff_log2_tab related linking
issues I encountered earlier this week.

Patch OK.

Patch

diff --git a/libavutil/common.h b/libavutil/common.h
index 3465863..cc4df16 100644
--- a/libavutil/common.h
+++ b/libavutil/common.h
@@ -252,16 +252,17 @@  static av_always_inline av_const int av_popcount64_c(uint64_t x)
 #define GET_UTF8(val, GET_BYTE, ERROR)\
     val= GET_BYTE;\
     {\
-        int ones= 7 - av_log2(val ^ 255);\
-        if(ones==1)\
+        uint32_t top = (val & 128) >> 1;\
+        if ((val & 0xc0) == 0x80)\
             ERROR\
-        val&= 127>>ones;\
-        while(--ones > 0){\
+        while (val & top) {\
             int tmp= GET_BYTE - 128;\
             if(tmp>>6)\
                 ERROR\
             val= (val<<6) + tmp;\
+            top <<= 5;\
         }\
+        val &= (top << 1) - 1;\
     }
 
 /**