Commit 6751c980 authored by Henrik Gramner's avatar Henrik Gramner Committed by Henrik Gramner

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.
parent 3d94fb9a
......@@ -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"
......
......@@ -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
......
......@@ -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.
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include "common/intops.h"
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <string.h>
#include "src/thread.h"
......
......@@ -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"
......
......@@ -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>
......
......@@ -28,7 +28,6 @@
#include "config.h"
#include <assert.h>
#include <stdint.h>
#include "common.h"
......
......@@ -27,8 +27,6 @@
#include "config.h"
#include <assert.h>
#include "common/intops.h"
#include "src/getbits.h"
......
......@@ -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"
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <stdint.h>
#include <string.h>
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <string.h>
#include "common/intops.h"
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <string.h>
#include "common/intops.h"
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include <string.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 {
......
......@@ -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;
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
......
......@@ -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,
......
......@@ -47,7 +47,6 @@
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include "common/intops.h"
......
......@@ -27,8 +27,6 @@
#include "tests/checkasm/checkasm.h"
#include <assert.h>
#include "src/levels.h"
#include "src/mc.h"
......
......@@ -29,7 +29,6 @@
#include "vcs_version.h"
#include "cli_config.h"
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <math.h>
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <getopt.h>
#include <limits.h>
#include <math.h>
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
......
......@@ -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"
......
......@@ -27,7 +27,6 @@
#include "config.h"
#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <stdint.h>
......
......@@ -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"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment