diff --git a/headers/private/kernel/util/BitUtils.h b/headers/private/kernel/util/BitUtils.h new file mode 100644 index 0000000000..60cbcb0a0a --- /dev/null +++ b/headers/private/kernel/util/BitUtils.h @@ -0,0 +1,42 @@ +/* + * Copyright 2013 Haiku, Inc. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Paweł Dziepak, pdziepak@quarnos.org + */ +#ifndef KERNEL_UTIL_BITUTIL_H +#define KERNEL_UTIL_BITUTIL_H + + +#include + + +// http://graphics.stanford.edu/~seander/bithacks.html +static inline uint32 +nextPowerOf2(uint32 v) +{ + v--; + v |= v >> 1; + v |= v >> 2; + v |= v >> 4; + v |= v >> 8; + v |= v >> 16; + v++; + + return v; +} + + +// http://graphics.stanford.edu/~seander/bithacks.html +static inline uint32 +countSetBits(uint32 v) +{ + v = v - ((v >> 1) & 0x55555555); + v = (v & 0x33333333) + ((v >> 2) & 0x33333333); + return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; +} + + +#endif // KERNEL_UTIL_RANDOM_H + diff --git a/src/system/kernel/arch/x86/arch_cpu.cpp b/src/system/kernel/arch/x86/arch_cpu.cpp index 090e7fc87d..da9bc039c5 100644 --- a/src/system/kernel/arch/x86/arch_cpu.cpp +++ b/src/system/kernel/arch/x86/arch_cpu.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -129,32 +130,6 @@ static uint32 sHierarchyMask[CPU_TOPOLOGY_LEVELS]; static uint32 sHierarchyShift[CPU_TOPOLOGY_LEVELS]; -// http://graphics.stanford.edu/~seander/bithacks.html -static inline uint32 -nextPowerOf2(uint32 v) -{ - v--; - v |= v >> 1; - v |= v >> 2; - v |= v >> 4; - v |= v >> 8; - v |= v >> 16; - v++; - - return v; -} - - -// http://graphics.stanford.edu/~seander/bithacks.html -static inline uint32 -countSetBits(uint32 v) -{ - v = v - ((v >> 1) & 0x55555555); - v = (v & 0x33333333) + ((v >> 2) & 0x33333333); - return (((v + (v >> 4)) & 0xF0F0F0F) * 0x1010101) >> 24; -} - - static status_t acpi_shutdown(bool rebootSystem) {