aboutsummaryrefslogtreecommitdiff
path: root/src/utils/common.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/common.h')
-rw-r--r--src/utils/common.h26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/utils/common.h b/src/utils/common.h
index 2e599f0..f75ace8 100644
--- a/src/utils/common.h
+++ b/src/utils/common.h
@@ -21,15 +21,17 @@
#include <intrin.h>
#pragma intrinsic(_BitScanForward)
#pragma intrinsic(_BitScanReverse)
-#if defined(_M_X64) || defined(_M_ARM) || defined(_M_ARM64)
+#if defined(_M_X64) || defined(_M_ARM64)
#pragma intrinsic(_BitScanReverse64)
#define HAVE_BITSCANREVERSE64
-#endif // defined(_M_X64) || defined(_M_ARM) || defined(_M_ARM64)
+#endif // defined(_M_X64) || defined(_M_ARM64)
#endif // defined(_MSC_VER)
+#include <algorithm>
#include <cassert>
#include <cstddef>
#include <cstdint>
+#include <cstdlib>
#include <cstring>
#include <type_traits>
@@ -40,6 +42,26 @@
namespace libgav1 {
+// LIBGAV1_RESTRICT
+// Declares a pointer with the restrict type qualifier if available.
+// This allows code to hint to the compiler that only this pointer references a
+// particular object or memory region within the scope of the block in which it
+// is declared. This may allow for improved optimizations due to the lack of
+// pointer aliasing. See also:
+// https://en.cppreference.com/w/c/language/restrict
+// Note a template alias is not used for compatibility with older compilers
+// (e.g., gcc < 10) that do not expand the type when instantiating a template
+// function, either explicitly or in an assignment to a function pointer as is
+// done within the dsp code. RestrictPtr<T>::type is an alternative to this,
+// similar to std::add_const, but for conciseness the macro is preferred.
+#ifdef __GNUC__
+#define LIBGAV1_RESTRICT __restrict__
+#elif defined(_MSC_VER)
+#define LIBGAV1_RESTRICT __restrict
+#else
+#define LIBGAV1_RESTRICT
+#endif
+
// Aligns |value| to the desired |alignment|. |alignment| must be a power of 2.
template <typename T>
inline T Align(T value, T alignment) {