[FFmpeg-devel] [PATCH] Fast half-float to float conversion

Jimmy Christensen jimmy
Wed Jul 1 07:42:45 CEST 2009


On 2009-06-30 15:50, Reimar D?ffinger wrote:
> On Tue, Jun 30, 2009 at 03:09:33PM +0200, Jimmy Christensen wrote:
>>> Lastly it seems to me that this code would belong into
>>> libavutil/intfloat_readwrite.*
>>
>> You are probably right.
>
> Personally I'd suggest doing a stupid implementation for
> libavutil/intfloat_readwrite.*, something like this (certainly
> not a beauty, possibly buggy, does not support denormals, though since
> they are rare it probably wouldn't be a big issue to add handling for
> them in if (nosign<  0x0400)).
> float av_int2halflt(int16_t v){
>      uint16_t nosign = v+v;
>      if (nosign>= 0xfc00) {
>          if (nosign == 0xfc00) return v>>15 ? -1.0/0.0 : 1.0/0.0;
>          else return 0.0/0.0;
>      }
>      if (nosign<  0x0400) return 0; // denormal or 0
>      return ldexp((v&0x3ff) + (1<<11)) * (v>>15|1), (v>>10&0x1f)-26);
> }
>
>
> And consider an optimized version only after it is actually used and
> thus it is clear what kind of optimizations are necessary/most useful.
> E.g. the table based approach probably is hard to SIMD and thus might be
> a bad idea if you want to convert a lot of data.

I tried testing with the code that you posted but it doesn't seem to 
work? The image looks quite clamped.

Also according to the original author the table conversion does 
implement denormals, zero, infinite and NaN.

-- 
Best Regards
Jimmy Christensen
Developer
Ghost A/S



More information about the ffmpeg-devel mailing list