ref: fbc1b4204c9b6a8d274f4a11d03fd98bb22704e6
parent: 9c29f229c5aa7d2d9564d44e8932011f23ac4e77
author: Henrik Gramner <gramner@twoorioles.com>
date: Sat Feb 1 09:17:35 EST 2020
Avoid masking the lsb in high bit-depth stride calculations We specify most strides in bytes, but since C defines offsets in multiples of sizeof(type) we use the PXSTRIDE() macro to downshift the strides by one in high-bit depth templated files. This however means that the compiler is required to mask away the least significant bit, because it could in theory be non-zero. Avoid that by telling the compiler (when compiled in release mode) that the lsb is in fact guaranteed to always be zero.
--- a/include/common/bitdepth.h
+++ b/include/common/bitdepth.h
@@ -31,6 +31,8 @@
#include <stdint.h>
#include <string.h>
+#include "common/attributes.h"
+
#if !defined(BITDEPTH)
typedef void pixel;
typedef void coef;
@@ -47,7 +49,7 @@
#define iclip_pixel iclip_u8
#define PIX_HEX_FMT "%02x"
#define bitfn(x) x##_8bpc
-#define PXSTRIDE(x) x
+#define PXSTRIDE(x) (x)
#define highbd_only(x)
#define HIGHBD_DECL_SUFFIX /* nothing */
#define HIGHBD_CALL_SUFFIX /* nothing */
@@ -70,7 +72,10 @@
#define HIGHBD_TAIL_SUFFIX , bitdepth_max
#define bitdepth_from_max(bitdepth_max) (32 - clz(bitdepth_max))
#define bitfn(x) x##_16bpc
-#define PXSTRIDE(x) (x >> 1)
+static inline ptrdiff_t PXSTRIDE(const ptrdiff_t x) {
+ assert(!(x & 1));
+ return x >> 1;
+}
#define highbd_only(x) x
#else
#error invalid value for bitdepth