diff options
author | Rui Ueyama <ruiu@google.com> | 2014-01-13 22:29:16 +0000 |
---|---|---|
committer | Rui Ueyama <ruiu@google.com> | 2014-01-13 22:29:16 +0000 |
commit | 0c306ba08c69480f2f196ea021e2f89aae1d35ef (patch) | |
tree | b7bba646ed9031f28104ad3b80ec5d3deb88cf1b | |
parent | d2215375a8b3442639f3fe09043acf6b68105340 (diff) | |
download | bcm5719-llvm-0c306ba08c69480f2f196ea021e2f89aae1d35ef.tar.gz bcm5719-llvm-0c306ba08c69480f2f196ea021e2f89aae1d35ef.zip |
Add comment to bit manipulation functions.
llvm-svn: 199156
-rw-r--r-- | lld/include/lld/ReaderWriter/RelocationHelperFunctions.h | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/lld/include/lld/ReaderWriter/RelocationHelperFunctions.h b/lld/include/lld/ReaderWriter/RelocationHelperFunctions.h index 427f66120fc..f02b5ef1496 100644 --- a/lld/include/lld/ReaderWriter/RelocationHelperFunctions.h +++ b/lld/include/lld/ReaderWriter/RelocationHelperFunctions.h @@ -12,32 +12,36 @@ namespace lld { -/// \brief Return the bits that are described by the mask -template < typename T > -T gatherBits(T val, T mask) -{ +/// Gather val's bits as specified by the mask. Example: +/// +/// Val: 0bABCDEFGHIJKLMN +/// Mask: 0b10111100001011 +/// Output: 0b000000ACDEFKMN +template <typename T> T gatherBits(T val, T mask) { T result = 0; size_t off = 0; - for (size_t bit = 0; bit != sizeof (T) * 8; ++bit) { + for (size_t bit = 0; bit != sizeof(T) * 8; ++bit) { const bool valBit = (val >> bit) & 1; const bool maskBit = (mask >> bit) & 1; if (maskBit) { - result |= static_cast <T> (valBit) << off; + result |= static_cast<T>(valBit) << off; ++off; } } return result; } -/// \brief Set the bits as described by the mask -template <typename T> -T scatterBits(T val, T mask) -{ +/// Scatter val's bits as specified by the mask. Example: +/// +/// Val: 0bABCDEFG +/// Mask: 0b10111100001011 +/// Output: 0b00ABCD0000E0FG +template <typename T> T scatterBits(T val, T mask) { T result = 0; size_t off = 0; - for (size_t bit = 0; bit != sizeof (T) * 8; ++bit) { + for (size_t bit = 0; bit != sizeof(T) * 8; ++bit) { const bool valBit = (val >> off) & 1; const bool maskBit = (mask >> bit) & 1; if (maskBit) { |