diff options
author | bubnikv <bubnikv@gmail.com> | 2017-03-28 18:09:57 +0300 |
---|---|---|
committer | bubnikv <bubnikv@gmail.com> | 2017-03-28 18:09:57 +0300 |
commit | 3ebf0ce7fd4bc235bda47187363ca3a25400ae03 (patch) | |
tree | a411444c05b2487bf90a787c7ffcf7c80dd074e4 /xs/src/libslic3r/Utils.hpp | |
parent | 1fb302d480258705895877d086265a735fdfe76d (diff) |
Improved memory allocation efficiency of the 3D path preview generator.
Diffstat (limited to 'xs/src/libslic3r/Utils.hpp')
-rw-r--r-- | xs/src/libslic3r/Utils.hpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/xs/src/libslic3r/Utils.hpp b/xs/src/libslic3r/Utils.hpp index 5e55ccd2b..5bbf1b624 100644 --- a/xs/src/libslic3r/Utils.hpp +++ b/xs/src/libslic3r/Utils.hpp @@ -6,6 +6,33 @@ namespace Slic3r { extern void set_logging_level(unsigned int level); 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) +{ + 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; + return ++ v; +} + } // namespace Slic3r #endif // slic3r_Utils_hpp_ |