diff options
author | Henrik Gramner <gramner@twoorioles.com> | 2020-02-01 16:17:35 +0300 |
---|---|---|
committer | Henrik Gramner <gramner@twoorioles.com> | 2020-02-01 16:17:35 +0300 |
commit | fbc1b4204c9b6a8d274f4a11d03fd98bb22704e6 (patch) | |
tree | 1089d7f143ee897a1a11e91f922a6f71577fe574 /include | |
parent | 9c29f229c5aa7d2d9564d44e8932011f23ac4e77 (diff) |
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.
Diffstat (limited to 'include')
-rw-r--r-- | include/common/bitdepth.h | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/include/common/bitdepth.h b/include/common/bitdepth.h index 1d608eb..66c8eaf 100644 --- 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 @@ typedef int16_t coef; #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 @@ static inline void pixel_set(pixel *const dst, const int val, const int num) { #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 |