From d7f9529bdd8b24701f8c1c2e62a52c8a7e908137 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 10 Jul 2015 18:01:56 -0300 Subject: [PATCH 1/2] Common: Fix mask generation in BitField Fixes #913 --- src/common/bit_field.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 1f3ecf8441..257d5577d4 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h @@ -188,7 +188,7 @@ private: __forceinline StorageType GetMask() const { - return ((~(StorageTypeU)0) >> (8 * sizeof(T)-bits)) << position; + return (((StorageTypeU)~0) >> (8 * sizeof(T)-bits)) << position; } StorageType storage; From d5b52805014f537082afae79dc212958295ca9dc Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Fri, 10 Jul 2015 18:02:56 -0300 Subject: [PATCH 2/2] Common: Remove redundant masking in BitField For the signed case, the shifts already remove the rest of the value, so ANDing by the mask is redundant. --- src/common/bit_field.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/bit_field.h b/src/common/bit_field.h index 257d5577d4..3bc53500d8 100644 --- a/src/common/bit_field.h +++ b/src/common/bit_field.h @@ -160,7 +160,7 @@ public: if (std::numeric_limits::is_signed) { std::size_t shift = 8 * sizeof(T)-bits; - return (T)(((storage & GetMask()) << (shift - position)) >> shift); + return (T)((storage << (shift - position)) >> shift); } else {