[FFmpeg-devel] [PATCH 1/2] avutil/common: add FFDIFFSIGN macro
gajjanag at mit.edu
Tue Nov 3 22:33:05 CET 2015
On Sun, Nov 1, 2015 at 5:54 PM, Michael Niedermayer
<michael at niedermayer.cc> wrote:
> On Sun, Nov 01, 2015 at 12:19:47PM -0500, Ganesh Ajjanagadde wrote:
>> This is of use for defining comparator callbacks. Common approaches like
>> return x-y are not safe due to the risks of overflow.
>> Furthermore, the (x > y) - (x < y) trick is optimized to branchless
>> This also documents this macro accordingly.
>> Signed-off-by: Ganesh Ajjanagadde <gajjanagadde at gmail.com>
>> libavutil/common.h | 11 +++++++++++
>> 1 file changed, 11 insertions(+)
>> diff --git a/libavutil/common.h b/libavutil/common.h
>> index 6594f7d..6f0f582 100644
>> --- a/libavutil/common.h
>> +++ b/libavutil/common.h
>> @@ -76,6 +76,17 @@
>> #define FFNABS(a) ((a) <= 0 ? (a) : (-(a)))
>> + * Comparator.
>> + * For two numerical expressions x and y, gives 1 if x > y, -1 if x < y, and 0
>> + * if x == y. This is useful for instance in a qsort comparator callback.
>> + * Furthermore, compilers are able to optimize this to branchless code, and
>> + * there is no risk of overflow with signed types.
>> + * As with many macros, this evaluates its argument multiple times, it thus
>> + * must not have a side-effect.
>> + */
>> +#define FFDIFFSIGN(x,y) (((x)>(y)) - ((x)<(y)))
> (maybe wait a bit before pushing so others can comment too, people
> may find the text too verbose or something else)
Been 2 days, it is a internal macro (FF prefix), and docs/name can
always be changed if need be.
In absence of objections and reviews from you and Clement for the
second patch and an from you for this one, pushed.
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
> It is dangerous to be right in matters on which the established authorities
> are wrong. -- Voltaire
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
More information about the ffmpeg-devel