diff options
author | Rémi Verschelde <remi@verschelde.fr> | 2016-02-29 07:29:57 +0100 |
---|---|---|
committer | Rémi Verschelde <remi@verschelde.fr> | 2016-02-29 07:29:57 +0100 |
commit | 445d38b7280b25caec1b9728f68d0aa0f69917b6 (patch) | |
tree | e65118dacf919f9bdb7e5d83b7248b7b18dd9055 | |
parent | 640443be6a81c2b5a0f7182bf51b6196fbfc6215 (diff) | |
parent | 0b24a13fa0116e63a70b6ccbd77c75fcb31c21eb (diff) |
Merge pull request #3875 from est31/master
Fix crash with release mode
-rw-r--r-- | core/typedefs.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/core/typedefs.h b/core/typedefs.h index 48acca326e..eab0ebc545 100644 --- a/core/typedefs.h +++ b/core/typedefs.h @@ -188,13 +188,22 @@ static _FORCE_INLINE_ unsigned int nearest_power_of_2(unsigned int x) { return ++x; } +// We need this definition inside the function below. +static inline int get_shift_from_power_of_2(unsigned int p_pixel); + template<class T> static _FORCE_INLINE_ T nearest_power_of_2_templated(T x) { --x; + + // The number of operations on x is the base two logarithm + // of the p_number of bits in the type. Add three to account + // for sizeof(T) being in bytes. + size_t num = get_shift_from_power_of_2(sizeof(T)) + 3; + // If the compiler is smart, it unrolls this loop // If its dumb, this is a bit slow. - for (size_t i = 0; i < sizeof(T); i++) + for (size_t i = 0; i < num; i++) x |= x >> (1 << i); return ++x; |