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

Jimmy Christensen jimmy
Tue Jun 30 11:06:27 CEST 2009

On 2009-06-30 10:57, M?ns Rullg?rd wrote:
> Jimmy Christensen<jimmy at ghost.dk>  writes:
>> On 2009-06-30 10:01, M?ns Rullg?rd wrote:
>>> Jimmy Christensen<jimmy at ghost.dk>   writes:
>>>> Hi,
>>>> I'm almost done with my OpenEXR decoder, but since it can work in a
>>>> half-float format I wanted a fast half-float to float conversion. I
>>>> found one in the FOX toolkit which uses a table lookup. I didn't want
>>>> the table lookup in the OpenEXR decoder only, since a few other
>>>> formats can use half-floats aswell. So instead I submit the half-float
>>>> to float first as a libavutil header.
>>> ARM NEON has hardware support for half-precision floating point.  This
>>> conversion should be done in a way that allows using such CPU-specific
>>> functionality.
>> I don't have access to any ARM NEON processors. How should I proceed
>> with this?
> Make the function convert an array instead of single values, and put
> some macros or something in place so it can be overridden by
> cpu-specific code.  See bswap.h or mathops.h for examples.

Will do. Thanks for the notice.

>>>> The code is derivative work from the FOX toolkit, but I have already
>>>> asked permission to include it in the ffmpeg project, granted that I
>>>> stated origin and a link to the paper describing the table lookup. The
>>>> paper can be seen here :
>>>> http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
>>>> I have tested the code with the before mentioned OpenEXR decoder and
>>>> it works as expected with half floats.
>>> Those tables look trivial enough that I have a hard time seeing how
>>> they could be covered by copyright at all.  It's just a simple
>>> rescaling.
>> Hehe. Was just a simple copy/paste from a previous header :) Will
>> remove the copyright. I just asked for permission of pure politeness.
> Is it copied from someone else's code?  If so, placing your name in
> the copyright header is wrong.  What copyright statement, if any, was
> on the original?

The code is modified from C++ to standard C and names are changed. Will 
add the original authors name in copyright aswell.

The original copyright from FXhalf.h/cpp :

> /********************************************************************************
> *                                                                               *
> *                     H a l f - F l o a t   S u p p o r t                       *
> *                                                                               *
> *********************************************************************************
> * Copyright (C) 2008,2009 by Jeroen van der Zijp.   All Rights Reserved.        *
> *********************************************************************************
> * This library is free software; you can redistribute it and/or modify          *
> * it under the terms of the GNU Lesser General Public License as published by   *
> * the Free Software Foundation; either version 3 of the License, or             *
> * (at your option) any later version.                                           *
> *                                                                               *
> * This library is distributed in the hope that it will be useful,               *
> * but WITHOUT ANY WARRANTY; without even the implied warranty of                *
> * GNU Lesser General Public License for more details.                           *
> *                                                                               *
> * You should have received a copy of the GNU Lesser General Public License      *
> * along with this program.  If not, see <http://www.gnu.org/licenses/>          *
> ********************************************************************************/

> It is also debatable whether we need the conversion to support
> denormal numbers.  I doubt these will occur in image data.  If this is
> not required, simple arithmetic conversion of exponent and mantissa is
> probably faster than table lookup.

Will do some testing.

The main point of posting it was to get some input on the approach.

Best Regards
Jimmy Christensen
Ghost A/S

More information about the ffmpeg-devel mailing list