mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-08-16 10:15:58 +08:00
Rewrote next_highest_power_of_2 as a template as OSX had issues with
the previous implementation.
This commit is contained in:
parent
2da3388aa5
commit
4bbb1f4b63
@ -8,27 +8,19 @@ extern void trace(unsigned int level, const char *message);
|
|||||||
|
|
||||||
// Compute the next highest power of 2 of 32-bit v
|
// Compute the next highest power of 2 of 32-bit v
|
||||||
// http://graphics.stanford.edu/~seander/bithacks.html
|
// http://graphics.stanford.edu/~seander/bithacks.html
|
||||||
inline uint32_t next_highest_power_of_2(uint32_t v)
|
template<typename T>
|
||||||
{
|
inline T next_highest_power_of_2(T v)
|
||||||
if (v != 0)
|
|
||||||
-- v;
|
|
||||||
v |= v >> 1;
|
|
||||||
v |= v >> 2;
|
|
||||||
v |= v >> 4;
|
|
||||||
v |= v >> 8;
|
|
||||||
v |= v >> 16;
|
|
||||||
return ++ v;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline uint64_t next_highest_power_of_2(uint64_t v)
|
|
||||||
{
|
{
|
||||||
if (v != 0)
|
if (v != 0)
|
||||||
-- v;
|
-- v;
|
||||||
v |= v >> 1;
|
v |= v >> 1;
|
||||||
v |= v >> 2;
|
v |= v >> 2;
|
||||||
v |= v >> 4;
|
v |= v >> 4;
|
||||||
|
if (sizeof(T) >= sizeof(uint16_t))
|
||||||
v |= v >> 8;
|
v |= v >> 8;
|
||||||
|
if (sizeof(T) >= sizeof(uint32_t))
|
||||||
v |= v >> 16;
|
v |= v >> 16;
|
||||||
|
if (sizeof(T) >= sizeof(uint64_t))
|
||||||
v |= v >> 32;
|
v |= v >> 32;
|
||||||
return ++ v;
|
return ++ v;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user