[FFmpeg-devel] -fsingle-precision-constant

Måns Rullgård mans
Thu May 13 20:28:18 CEST 2010


Michael Niedermayer <michaelni at gmx.at> writes:

> On Thu, May 13, 2010 at 08:53:27PM +0300, Uoti Urpala wrote:
>> On Thu, 2010-05-13 at 19:44 +0200, Michael Niedermayer wrote:
>> > On Thu, May 13, 2010 at 01:31:07PM -0400, Ronald S. Bultje wrote:
>> > > On Thu, May 13, 2010 at 1:13 PM, Michael Niedermayer <michaelni at gmx.at> wrote:
>> > > > when i looked at the asm gcc generates for mp3float i noticed
>> > > > it converts floats to doubles all over the place.  Adding
>> > > > -fsingle-precision-constant makes the code a whole 10% faster
>> > > > overall on core2
>> > > 
>> > > What if you add "f" as a postfix to relevant constants? Or can you
>> > > give examples of functions where this is an issue so we can be more
>> > > helpful?
>> > 
>> > all functions i guess
>> > 
>> > like
>> > float func(float f){
>> >     return f*1.2;
>> > }
>> 
>> Here "1.2" is a constant of type "double", and since one operand is a
>
> sure
> what pisses me off is that the compiler acts very unreasonable in practical
> terms for an optimizing compiler.
> floating point calculations are not exact theres no point to 
> convert every float that is multiplied by a constant to double before the
> multiply and back to float afterwards. This just doesnt gain much, its
> unreasonable and unexpected behavior.
>
>> double the multiplication is also a multiplication at double precision.
>> As 1.2 is not exactly representable it is not possible to optimize it to
>> a float without losing precision.
>
> floating point is inherently approximate, thus limiting optimizations to
> being binary identical to some arbitrarily picked approximation is quite
> silly besides gcc doesnt do this in other cases and i seriously doubt that
> other compilers optimize floating point code so narrowly

Silly as it is, that is what the relevant standards mandate, and GCC
cannot do things differently.  Complain to the ISO C and IEEE754
committees instead.

My theory is that those who wrote the standards only cared about
double precision.  The scientific/HPC crowd tend to be like that.

-- 
M?ns Rullg?rd
mans at mansr.com



More information about the ffmpeg-devel mailing list