Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2017-03-28 19:02:26 +0300
committerbubnikv <bubnikv@gmail.com>2017-03-28 19:02:26 +0300
commit4bbb1f4b63c7533029397b0b502c91ffa76badbf (patch)
tree2e636fc981828dbc230adfa9674765a14c5d652e /xs/src/libslic3r/Utils.hpp
parent2da3388aa594af87d1a93529749167273baf20ed (diff)
Rewrote next_highest_power_of_2 as a template as OSX had issues with
the previous implementation.
Diffstat (limited to 'xs/src/libslic3r/Utils.hpp')
-rw-r--r--xs/src/libslic3r/Utils.hpp24
1 files changed, 8 insertions, 16 deletions
diff --git a/xs/src/libslic3r/Utils.hpp b/xs/src/libslic3r/Utils.hpp
index 5bbf1b624..0b6b87d28 100644
--- a/xs/src/libslic3r/Utils.hpp
+++ b/xs/src/libslic3r/Utils.hpp
@@ -8,28 +8,20 @@ extern void trace(unsigned int level, const char *message);
// Compute the next highest power of 2 of 32-bit v
// 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)
- -- v;
- v |= v >> 1;
- v |= v >> 2;
- v |= v >> 4;
- v |= v >> 8;
- v |= v >> 16;
- v |= v >> 32;
+ if (sizeof(T) >= sizeof(uint16_t))
+ v |= v >> 8;
+ if (sizeof(T) >= sizeof(uint32_t))
+ v |= v >> 16;
+ if (sizeof(T) >= sizeof(uint64_t))
+ v |= v >> 32;
return ++ v;
}