1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19/**
20 * @file
21 * @ingroup lavu
22 * Utility Preprocessor macros
23 */
24
25#ifndef AVUTIL_MACROS_H
26#define AVUTIL_MACROS_H
27
28#include "libavutil/avconfig.h"
29
30#if AV_HAVE_BIGENDIAN
31# define AV_NE(be, le) (be)
32#else
33# define AV_NE(be, le) (le)
34#endif
35
36/**
37 * Comparator.
38 * For two numerical expressions x and y, gives 1 if x > y, -1 if x < y, and 0
39 * if x == y. This is useful for instance in a qsort comparator callback.
40 * Furthermore, compilers are able to optimize this to branchless code, and
41 * there is no risk of overflow with signed types.
42 * As with many macros, this evaluates its argument multiple times, it thus
43 * must not have a side-effect.
44 */
45#define FFDIFFSIGN(x,y) (((x)>(y)) - ((x)<(y)))
46
47#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
48#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
49#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
50#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
51
52#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
53#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
54
55#define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24))
56#define MKBETAG(a,b,c,d) ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24))
57
58/**
59 * @addtogroup preproc_misc Preprocessor String Macros
60 *
61 * String manipulation macros
62 *
63 * @{
64 */
65
66#define AV_STRINGIFY(s) AV_TOSTRING(s)
67#define AV_TOSTRING(s) #s
68
69#define AV_GLUE(a, b) a ## b
70#define AV_JOIN(a, b) AV_GLUE(a, b)
71
72/**
73 * @}
74 */
75
76#define AV_PRAGMA(s) _Pragma(#s)
77
78#define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
79
80#endif /* AVUTIL_MACROS_H */
81