[FFmpeg-devel] [PATCH] AAC: type puns for 16 bit floating point rounding

Uoti Urpala uoti.urpala
Thu Dec 4 14:46:42 CET 2008


On Thu, 2008-12-04 at 09:35 +0000, M?ns Rullg?rd wrote:
> Uoti Urpala <uoti.urpala at pp1.inet.fi> writes:
> 
> > On Thu, 2008-12-04 at 03:13 +0000, M?ns Rullg?rd wrote:
> >> > @@ -838,24 +842,45 @@ static int decode_spectrum_and_dequant(AACContext * ac, float coef[1024], GetBit
> >> >  }
> >> >  
> >> >  static av_always_inline float flt16_round(float pf) {
> >> > +#ifdef ENABLE_IEEE754_PUN
> >> > +    union float754 tmp;
> >> > +    tmp.f = pf;
> >> > +    tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U;
> >> > +    return tmp.f;
> >> > +#else
> >> 
> >> Are this things safe under strict aliasing rules?
> >
> > Yes GCC does guarantee that it will work (all the accesses use
> > unionvalue.field syntax with the same union).
> 
> What gcc does is irrelevant.  Is it guaranteed by the C standard?

The GCC behavior is more relevant than the standard in this case. The
standard won't guarantee that any such type punning code works anyway.
The reliability of such optimizations has to be determined based on the
probability that it will work in practice. GCC has the strictest
aliasing requirements and it seems unlikely that some compiler would use
more strict ones in the future (and if some compiler will use a
significantly stricter interpretation of the standard then other parts
of FFmpeg will likely fail to compile correctly too, this one being an
easy one to diagnose and fix).





More information about the ffmpeg-devel mailing list