[FFmpeg-devel] [PATCH 00/12] replace round by lrint/llrint

Ganesh Ajjanagadde gajjanagadde at gmail.com
Sat Dec 19 06:45:26 CET 2015


The chief difference between round and lrint/llrint lies in somewhat nuanced semantics:
1. (minor) round inherently returns a double precision value, so this is then
implicitly cast to an integer afterwards. Nothing inherently wrong with this,
but the implicit cast may be easily missed.
2. l(l)rint uses the superior "Dutch/Gaussian" rounding, i.e it rounds half-way points
to even numbers instead of biasing away from zero, which is actually forced by round.
Of course, this does not eliminate all sources of such bias (e.g y-0.5 always being
even), but it is observed to be far better in practice.

On x86-64, they map to cvtsd2si and cvttsd2si (extra t for truncation), which
turn out to have identical cycle times. Same goes for the vector variants.

This patchset accordingly removes all needless round instructions.

In a few cases, speedups are actually obtained, i.e changes are not purely cosmetic/
theoretical for the halfway cases. When observed, they have been noted in respective
commit messages.

Patchset tested with FATE.

Ganesh Ajjanagadde (12):
  lavfi/vf_idet: replace round and cast by lrint
  lavfi/vf_colorchannelmixer: replace round by lrint
  lavfi/vf_colorlevels: replace round by lrint
  lavfi/vf_drawtext: replace round by llrint
  lavfi/vsrc_mandelbrot: replace round by lrint
  lavf/hlsenc: replace round by lrint
  lavc/libvpxenc: replace round by lrint
  lavfi/vf_crop: replace round by lrint
  lavfi/af_dynaudnorm: replace round by lrint
  lavfi/vf_cropdetect: replace round by lrint
  lavfi/vf_histogram: replace round by lrint
  lavd/pulse_audio_enc: replace lround by lrint

 libavcodec/libvpxenc.c             |  4 ++--
 libavdevice/pulse_audio_enc.c      |  2 +-
 libavfilter/af_dynaudnorm.c        |  2 +-
 libavfilter/vf_colorchannelmixer.c | 38 +++++++++++++++++++-------------------
 libavfilter/vf_colorlevels.c       | 16 ++++++++--------
 libavfilter/vf_crop.c              |  2 +-
 libavfilter/vf_cropdetect.c        |  2 +-
 libavfilter/vf_drawtext.c          |  2 +-
 libavfilter/vf_histogram.c         |  2 +-
 libavfilter/vf_idet.c              |  2 +-
 libavfilter/vsrc_mandelbrot.c      |  2 +-
 libavformat/hlsenc.c               |  2 +-
 12 files changed, 38 insertions(+), 38 deletions(-)

-- 
2.6.4



More information about the ffmpeg-devel mailing list