[FFmpeg-devel] [PATCH] Fast half-float to float conversion
Jimmy Christensen
jimmy
Wed Jul 1 13:12:58 CEST 2009
On 2009-07-01 12:59, Reimar D?ffinger wrote:
> On Wed, Jul 01, 2009 at 12:52:08PM +0200, Jimmy Christensen wrote:
>> I modified for the purpose I need it for. Converting from half-float to
>> unsigned int.
>>
>> uint16_t av_halflt2uint(uint16_t v){
>> uint16_t nosign = v+v;
>> if (v>>15)
>> return 0; // negatives are not interesting so clamp it to 0
>> if (nosign>= 0xfc00)
>> return 65535; // Anything above 1 should be clamped to 65535
>> if (nosign< 0x0200)
>> return ldexp((v&0x3ff), 1-25)*65535; // denormal or 0
>> return ldexp((v&0x3ff) + (1<<10), (v>>10&0x1f)-25)*65535;
>> }
>
> That function is useless for any other use.
> In addition, I really half to say that this is a very "half-assed" way
> to optimize it.
> There is no need for the extremely slow ldexp function etc. if you want
> to convert to int anyway, and denormals will always end up as 0 anyway.
> I'd appreciate if you'd take it seriously when I say there is _no point_
> in optimizing it before you know what exactly you need. That means in
> particular that the code where you use it has passed at least a first
> review.
First of all I do take this seriously, but you have to excuse me that
I'm not good at this kind of code. It was a "half-assed" attempt to
optimimze it because I'm a "half-hassed" programmer at this. This is why
I in the first place ask people like yourself for help.
The above code is only in the decoder and nowhere else. So it doesn't
need to be used for anything else. For doing a "general" fast half-float
to float converter I leave that to someone else, as I'm not up to the task.
More information about the ffmpeg-devel
mailing list