aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-04-17 22:50:50 -0700
committerChris Robinson <[email protected]>2018-04-17 22:50:50 -0700
commit150586d7fef722da17b96697ca0c1f78b2d10eb4 (patch)
tree03ad2bd434e6cfce4bfb2007ffc82ff1dc624639
parent09194fd4886d81ca28f88760e8ae4efad368227e (diff)
Add an ASSUME macro that requires a true condition
-rw-r--r--Alc/mixer/mixer_c.c2
-rw-r--r--Alc/mixer/mixer_neon.c2
-rw-r--r--Alc/mixer/mixer_sse.c2
-rw-r--r--OpenAL32/Include/alMain.h17
4 files changed, 23 insertions, 0 deletions
diff --git a/Alc/mixer/mixer_c.c b/Alc/mixer/mixer_c.c
index e40c2cad..ee667671 100644
--- a/Alc/mixer/mixer_c.c
+++ b/Alc/mixer/mixer_c.c
@@ -65,6 +65,8 @@ const ALfloat *Resample_bsinc_C(const InterpState *state, const ALfloat *restric
ALsizei j_f, pi, i;
ALfloat pf, r;
+ ASSUME(m > 0);
+
src += state->bsinc.l;
for(i = 0;i < dstlen;i++)
{
diff --git a/Alc/mixer/mixer_neon.c b/Alc/mixer/mixer_neon.c
index 7f8dd1d4..e8a85f71 100644
--- a/Alc/mixer/mixer_neon.c
+++ b/Alc/mixer/mixer_neon.c
@@ -78,6 +78,8 @@ const ALfloat *Resample_bsinc_Neon(const InterpState *state,
float32x4_t r4;
ALfloat pf;
+ ASSUME(m > 0);
+
src += state->bsinc.l;
for(i = 0;i < dstlen;i++)
{
diff --git a/Alc/mixer/mixer_sse.c b/Alc/mixer/mixer_sse.c
index c9615c25..5c181c75 100644
--- a/Alc/mixer/mixer_sse.c
+++ b/Alc/mixer/mixer_sse.c
@@ -24,6 +24,8 @@ const ALfloat *Resample_bsinc_SSE(const InterpState *state, const ALfloat *restr
ALfloat pf;
__m128 r4;
+ ASSUME(m > 0);
+
src += state->bsinc.l;
for(i = 0;i < dstlen;i++)
{
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 783a90de..77144a29 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -42,11 +42,28 @@
#ifdef __GNUC__
+/* LIKELY optimizes the case where the condition is true. The condition is not
+ * required to be true, but it can result in more optimal code for the true
+ * path at the expense of a less optimal false path.
+ */
#define LIKELY(x) __builtin_expect(!!(x), !0)
+/* The opposite of LIKELY, optimizing the case where the condition is false. */
#define UNLIKELY(x) __builtin_expect(!!(x), 0)
+/* Unlike LIKELY, ASSUME requires the condition to be true or else it invokes
+ * undefined behavior. It's essentially an assert without actually checking the
+ * condition at run-time, allowing for stronger optimizations than LIKELY.
+ */
+#define ASSUME(x) do { if(!(x)) __builtin_unreachable(); } while(0)
+
#else
+
#define LIKELY(x) (!!(x))
#define UNLIKELY(x) (!!(x))
+#ifdef _MSC_VER
+#define ASSUME __assume
+#else
+#define ASSUME(x) ((void)0)
+#endif
#endif
#ifndef UINT64_MAX