[FFmpeg-devel] [PATCH] [libavutil] Add saturated add/sub operations for int64_t.

Michael Niedermayer michael at niedermayer.cc
Fri May 15 22:58:23 EEST 2020


On Thu, May 14, 2020 at 12:46:56PM -0700, Dale Curtis wrote:
> On Thu, May 14, 2020 at 11:47 AM Michael Niedermayer <michael at niedermayer.cc>
> wrote:
> 
> > On Fri, May 01, 2020 at 11:42:43AM -0700, Dale Curtis wrote:
> > > On Fri, May 1, 2020 at 10:57 AM Carl Eugen Hoyos <ceffmpeg at gmail.com>
> > wrote:
> > >
> > > > Could you confirm that you attached the wrong patch?
> > > >
> > >
> > > No, I sent the patches without completing the rebase. Sorry.
> > >
> > > - dale
> >
> > >  common.h |   36 ++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 36 insertions(+)
> > > f5567ae046c0c2d4ac9053611457b9d9045b6ccb  sat_math_v4.patch
> > > From 06c20d84e3bf0f56bcba63ef8e74812e796f3ffe Mon Sep 17 00:00:00 2001
> > > From: Dale Curtis <dalecurtis at chromium.org>
> > > Date: Thu, 30 Apr 2020 15:16:31 -0700
> > > Subject: [PATCH 1/2] Add saturated add/sub operations for int64_t.
> > >
> > > Many places are using their own custom code for handling overflow
> > > around timestamps or other int64_t values. There are enough of these
> > > now that having some common saturated math functions seems sound.
> > >
> > > Signed-off-by: Dale Curtis <dalecurtis at chromium.org>
> > > ---
> > >  libavutil/common.h | 36 ++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 36 insertions(+)
> > >
> > > diff --git a/libavutil/common.h b/libavutil/common.h
> > > index 142ff9abe7..11907e5ba7 100644
> > > --- a/libavutil/common.h
> > > +++ b/libavutil/common.h
> > > @@ -291,6 +291,36 @@ static av_always_inline int av_sat_dsub32_c(int a,
> > int b)
> > >      return av_sat_sub32(a, av_sat_add32(b, b));
> > >  }
> > >
> > > +/**
> > > + * Add two signed 64-bit values with saturation.
> > > + *
> > > + * @param  a one value
> > > + * @param  b another value
> > > + * @return sum with signed saturation
> > > + */
> > > +static av_always_inline int64_t av_sat_add64_c(int64_t a, int64_t b) {
> > > +  if (b >= 0 && a >= INT64_MAX - b)
> > > +    return INT64_MAX;
> > > +  if (b <= 0 && a <= INT64_MIN - b)
> > > +    return INT64_MIN;
> > > +  return a + b;
> > > +}
> > > +
> > > +/**
> > > + * Subtract two signed 64-bit values with saturation.
> > > + *
> > > + * @param  a one value
> > > + * @param  b another value
> > > + * @return difference with signed saturation
> > > + */
> > > +static av_always_inline int64_t av_sat_sub64_c(int64_t a, int64_t b) {
> > > +  if (b <= 0 && a >= INT64_MAX + b) {
> > > +    return INT64_MAX;
> > > +  if (b >= 0 && a <= INT64_MIN + b) {
> > > +    return INT64_MIN;
> >
> > the { are not paired with }
> > this will not build
> >
> > indention level also does not match the rest of the code
> >
> >
> Fixed, sorry about that.
> 
> - dale

>  common.h |   36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)
> 15c7cc73889c7f758aaf2dc341f192918cd2828c  sat_math_v5.patch
> From 4becb3c5f712db8b10f4b86b2c7a9f3e4eb27e98 Mon Sep 17 00:00:00 2001
> From: Dale Curtis <dalecurtis at chromium.org>
> Date: Thu, 30 Apr 2020 15:16:31 -0700
> Subject: [PATCH 1/2] Add saturated add/sub operations for int64_t.
> 
> Many places are using their own custom code for handling overflow
> around timestamps or other int64_t values. There are enough of these
> now that having some common saturated math functions seems sound.
> 
> Signed-off-by: Dale Curtis <dalecurtis at chromium.org>
> ---
>  libavutil/common.h | 36 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 36 insertions(+)

will apply

thx

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20200515/3c235321/attachment.sig>


More information about the ffmpeg-devel mailing list