Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/videolan/dav1d.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenrik Gramner <gramner@twoorioles.com>2019-08-09 23:41:18 +0300
committerHenrik Gramner <henrik@gramner.com>2019-08-19 01:02:29 +0300
commit6751c9803695a2f12afb8f2cf080a4f9c2c8973a (patch)
tree96fb5e7a7c85f880080aeb154ae935de6e44b5bb
parent3d94fb9aff5d2837c9ee0c13fff3d4e2424623ae (diff)
Utilize the constraints in assertions to improve code generation
When compiling in release mode, instead of just deleting assertions, use them to give hints to the compiler. This allows for slightly better code generation in some cases.
-rw-r--r--examples/dav1dplay.c6
-rw-r--r--include/common/attributes.h8
-rw-r--r--include/common/mem.h3
-rw-r--r--src/cdef_tmpl.c1
-rw-r--r--src/cdf.c1
-rw-r--r--src/data.c2
-rw-r--r--src/env.h1
-rw-r--r--src/film_grain_tmpl.c1
-rw-r--r--src/getbits.c2
-rw-r--r--src/intra_edge.c3
-rw-r--r--src/ipred_prepare_tmpl.c1
-rw-r--r--src/ipred_tmpl.c1
-rw-r--r--src/itx_tmpl.c1
-rw-r--r--src/lf_apply_tmpl.c1
-rw-r--r--src/lf_mask.c1
-rw-r--r--src/mc_tmpl.c1
-rw-r--r--src/msac.h3
-rw-r--r--src/obu.c3
-rw-r--r--src/picture.c1
-rw-r--r--src/ppc/cdef_init_tmpl.c9
-rw-r--r--src/ref_mvs.c1
-rw-r--r--src/warpmv.c1
-rw-r--r--tests/checkasm/mc.c2
-rw-r--r--tools/dav1d.c1
-rw-r--r--tools/dav1d_cli_parse.c1
-rw-r--r--tools/input/annexb.c1
-rw-r--r--tools/input/input.c3
-rw-r--r--tools/input/ivf.c1
-rw-r--r--tools/output/output.c3
29 files changed, 28 insertions, 36 deletions
diff --git a/examples/dav1dplay.c b/examples/dav1dplay.c
index 1f418e2..faf51e7 100644
--- a/examples/dav1dplay.c
+++ b/examples/dav1dplay.c
@@ -27,14 +27,14 @@
#include "config.h"
#include "vcs_version.h"
-#include <stdio.h>
+#include <getopt.h>
#include <stdint.h>
+#include <stdio.h>
#include <string.h>
-#include <assert.h>
-#include <getopt.h>
#include <SDL.h>
+#include "common/attributes.h"
#include "dav1d/dav1d.h"
diff --git a/include/common/attributes.h b/include/common/attributes.h
index 3f32c0d..6590fe4 100644
--- a/include/common/attributes.h
+++ b/include/common/attributes.h
@@ -92,6 +92,14 @@
#define NOINLINE __attribute__((noinline))
#endif /* !_MSC_VER */
+#if defined(NDEBUG) && defined(__GNUC__)
+#define assert(x) do { if (!(x)) __builtin_unreachable(); } while (0)
+#elif defined(NDEBUG) && defined(_MSC_VER)
+#define assert __assume
+#else
+#include <assert.h>
+#endif
+
#if defined(__GNUC__) && !defined(__INTEL_COMPILER) && !defined(__clang__)
# define dav1d_uninit(x) x=x
#else
diff --git a/include/common/mem.h b/include/common/mem.h
index 3fbcdbc..a633b2a 100644
--- a/include/common/mem.h
+++ b/include/common/mem.h
@@ -28,13 +28,14 @@
#ifndef DAV1D_COMMON_MEM_H
#define DAV1D_COMMON_MEM_H
-#include <assert.h>
#include <stdlib.h>
#if defined(HAVE_ALIGNED_MALLOC) || defined(HAVE_MEMALIGN)
#include <malloc.h>
#endif
+#include "common/attributes.h"
+
/*
* Allocate 32-byte aligned memory. The return value can be released
* by calling the standard free() function.
diff --git a/src/cdef_tmpl.c b/src/cdef_tmpl.c
index 41a9e0b..875ad60 100644
--- a/src/cdef_tmpl.c
+++ b/src/cdef_tmpl.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <stdlib.h>
#include "common/intops.h"
diff --git a/src/cdf.c b/src/cdf.c
index 46cd9a1..545d07e 100644
--- a/src/cdf.c
+++ b/src/cdf.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <string.h>
#include "src/thread.h"
diff --git a/src/data.c b/src/data.c
index e1d1cc3..29e83ea 100644
--- a/src/data.c
+++ b/src/data.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdlib.h>
@@ -35,6 +34,7 @@
#include "dav1d/data.h"
+#include "common/attributes.h"
#include "common/validate.h"
#include "src/data.h"
diff --git a/src/env.h b/src/env.h
index 1f23ac1..3ec4a53 100644
--- a/src/env.h
+++ b/src/env.h
@@ -28,7 +28,6 @@
#ifndef DAV1D_SRC_ENV_H
#define DAV1D_SRC_ENV_H
-#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
diff --git a/src/film_grain_tmpl.c b/src/film_grain_tmpl.c
index 1d6a419..b715b5a 100644
--- a/src/film_grain_tmpl.c
+++ b/src/film_grain_tmpl.c
@@ -28,7 +28,6 @@
#include "config.h"
-#include <assert.h>
#include <stdint.h>
#include "common.h"
diff --git a/src/getbits.c b/src/getbits.c
index 770fd33..c185053 100644
--- a/src/getbits.c
+++ b/src/getbits.c
@@ -27,8 +27,6 @@
#include "config.h"
-#include <assert.h>
-
#include "common/intops.h"
#include "src/getbits.h"
diff --git a/src/intra_edge.c b/src/intra_edge.c
index 4cac7cd..684d113 100644
--- a/src/intra_edge.c
+++ b/src/intra_edge.c
@@ -27,9 +27,10 @@
#include "config.h"
-#include <assert.h>
#include <stdlib.h>
+#include "common/attributes.h"
+
#include "src/intra_edge.h"
#include "src/levels.h"
diff --git a/src/ipred_prepare_tmpl.c b/src/ipred_prepare_tmpl.c
index 5eaabfc..0bf9de9 100644
--- a/src/ipred_prepare_tmpl.c
+++ b/src/ipred_prepare_tmpl.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <stdint.h>
#include <string.h>
diff --git a/src/ipred_tmpl.c b/src/ipred_tmpl.c
index 09be553..68fb9ec 100644
--- a/src/ipred_tmpl.c
+++ b/src/ipred_tmpl.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/itx_tmpl.c b/src/itx_tmpl.c
index 0fc21ca..70e8824 100644
--- a/src/itx_tmpl.c
+++ b/src/itx_tmpl.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
diff --git a/src/lf_apply_tmpl.c b/src/lf_apply_tmpl.c
index e9831ab..4e860f4 100644
--- a/src/lf_apply_tmpl.c
+++ b/src/lf_apply_tmpl.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <string.h>
#include "common/intops.h"
diff --git a/src/lf_mask.c b/src/lf_mask.c
index b9dd7c3..5cdbfba 100644
--- a/src/lf_mask.c
+++ b/src/lf_mask.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <string.h>
#include "common/intops.h"
diff --git a/src/mc_tmpl.c b/src/mc_tmpl.c
index 9744f24..20bef0d 100644
--- a/src/mc_tmpl.c
+++ b/src/mc_tmpl.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <stdlib.h>
#include <string.h>
diff --git a/src/msac.h b/src/msac.h
index d8ba05a..ad7cff0 100644
--- a/src/msac.h
+++ b/src/msac.h
@@ -28,10 +28,11 @@
#ifndef DAV1D_SRC_MSAC_H
#define DAV1D_SRC_MSAC_H
-#include <assert.h>
#include <stdint.h>
#include <stdlib.h>
+#include "common/attributes.h"
+
typedef size_t ec_win;
typedef struct MsacContext {
diff --git a/src/obu.c b/src/obu.c
index 2389efc..72d0152 100644
--- a/src/obu.c
+++ b/src/obu.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stdio.h>
@@ -1275,8 +1274,10 @@ int dav1d_parse_obus(Dav1dContext *const c, Dav1dData *const in, int global) {
c->frame_hdr_ref = dav1d_ref_create(sizeof(Dav1dFrameHeader));
if (!c->frame_hdr_ref) return DAV1D_ERR(ENOMEM);
}
+#ifndef NDEBUG
// ensure that the reference is writable
assert(dav1d_ref_is_writable(c->frame_hdr_ref));
+#endif
c->frame_hdr = c->frame_hdr_ref->data;
memset(c->frame_hdr, 0, sizeof(*c->frame_hdr));
c->frame_hdr->temporal_id = temporal_id;
diff --git a/src/picture.c b/src/picture.c
index c94eafb..b39e068 100644
--- a/src/picture.c
+++ b/src/picture.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
diff --git a/src/ppc/cdef_init_tmpl.c b/src/ppc/cdef_init_tmpl.c
index 1d226c2..5ea4458 100644
--- a/src/ppc/cdef_init_tmpl.c
+++ b/src/ppc/cdef_init_tmpl.c
@@ -24,16 +24,15 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <assert.h>
#include <stdlib.h>
-#include "src/ppc/types.h"
-
#include "common/bitdepth.h"
+#include "common/intops.h"
-#include "src/cpu.h"
#include "src/cdef.h"
-#include "common/intops.h"
+#include "src/cpu.h"
+
+#include "src/ppc/types.h"
#if BITDEPTH == 8
static inline i16x8 vconstrain(const i16x8 diff, const int16_t threshold,
diff --git a/src/ref_mvs.c b/src/ref_mvs.c
index 5d36696..ec5e5f6 100644
--- a/src/ref_mvs.c
+++ b/src/ref_mvs.c
@@ -47,7 +47,6 @@
#include "config.h"
-#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
diff --git a/src/warpmv.c b/src/warpmv.c
index ae31315..7eb330a 100644
--- a/src/warpmv.c
+++ b/src/warpmv.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <stdlib.h>
#include "common/intops.h"
diff --git a/tests/checkasm/mc.c b/tests/checkasm/mc.c
index 3a892ed..d4357c8 100644
--- a/tests/checkasm/mc.c
+++ b/tests/checkasm/mc.c
@@ -27,8 +27,6 @@
#include "tests/checkasm/checkasm.h"
-#include <assert.h>
-
#include "src/levels.h"
#include "src/mc.h"
diff --git a/tools/dav1d.c b/tools/dav1d.c
index e57140e..1277cc6 100644
--- a/tools/dav1d.c
+++ b/tools/dav1d.c
@@ -29,7 +29,6 @@
#include "vcs_version.h"
#include "cli_config.h"
-#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <math.h>
diff --git a/tools/dav1d_cli_parse.c b/tools/dav1d_cli_parse.c
index a2c183c..266527d 100644
--- a/tools/dav1d_cli_parse.c
+++ b/tools/dav1d_cli_parse.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <getopt.h>
#include <limits.h>
#include <math.h>
diff --git a/tools/input/annexb.c b/tools/input/annexb.c
index bf51ae4..4567f94 100644
--- a/tools/input/annexb.c
+++ b/tools/input/annexb.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
diff --git a/tools/input/input.c b/tools/input/input.c
index 95235ac..53e77bd 100644
--- a/tools/input/input.c
+++ b/tools/input/input.c
@@ -27,12 +27,13 @@
#include "config.h"
-#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "common/attributes.h"
+
#include "input/input.h"
#include "input/demuxer.h"
diff --git a/tools/input/ivf.c b/tools/input/ivf.c
index d67028a..e83dd6d 100644
--- a/tools/input/ivf.c
+++ b/tools/input/ivf.c
@@ -27,7 +27,6 @@
#include "config.h"
-#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
diff --git a/tools/output/output.c b/tools/output/output.c
index f6e40a1..85b4a75 100644
--- a/tools/output/output.c
+++ b/tools/output/output.c
@@ -27,12 +27,13 @@
#include "config.h"
-#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include "common/attributes.h"
+
#include "output/output.h"
#include "output/muxer.h"