[FFmpeg-devel] [PATCH 0/2] first steps to resolving float to int undefined behavior
Michael Niedermayer
michael at niedermayer.cc
Mon Nov 2 01:15:04 CET 2015
On Sun, Nov 01, 2015 at 06:51:19PM -0500, Ganesh Ajjanagadde wrote:
> On Sun, Nov 1, 2015 at 6:25 PM, Nicolas George <george at nsup.org> wrote:
> > Le primidi 11 brumaire, an CCXXIV, Ronald S. Bultje a écrit :
> >> So, is this a bug in llrint, or is this a failure to use llrint, or is this
> >> different from llrint? It sounds to me that llrint should be used, not our
> >> own alternative.
> >
> > Is there a sized version of the function? int64rint? Otherwise, these
> > functions for the native types are as useless as the native types
> > themselves.
>
> No, not in ISO C, or even libc AFAIK. ISO C tends to favor the
> "non-sized" types in their signatures. The reason (I believe) stems
> from the fact that an implementation is free to not even define the
> sized types:
> 7.20.1.1, point 3 - "These types are optional. However, if an
> implementation provides integer types with widths of 8, 16, 32, or 64
> bits, no padding bits, and (for the signed types) that have a two’s
> complement representation [all platforms supported by the project], it
> shall define the corresponding typedef names." -
> Thus they want to limit their scope to mostly (or perharps only?) stdint.h.
>
> Even otherwise, these functions are somewhat useless due to the
> undefined behavior outside the range. All they really do is get
> rounding done correctly according to the current FPU environment and
> associated rounding modes, which can be manipulated in C99/C11.
quite some of the undefined behavior also makes more optimizations
possible for advanced compilers
random silly example
min = 0;
for(i=0; i<N; i++) {
float c = whatever()
min = fmin(min, c);
out[i] = llrint(c);
}
here the compiler can remove any and all handling of NaN and +-Inf
from fmin() because llrint(c) implies c is within the range
represetable of the integer types
with a llrint() equivalent that is defined for all cases this is not
possible anymore
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
During times of universal deceit, telling the truth becomes a
revolutionary act. -- George Orwell
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20151102/b222c24d/attachment.sig>
More information about the ffmpeg-devel
mailing list