add Relocation helper functions

llvm-svn: 173895
This commit is contained in:
Shankar Easwaran 2013-01-30 04:49:54 +00:00
parent 6396922186
commit a51870b143
1 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,52 @@
//===- lld/ReaderWriter/RelocationHelperFunctions.h------------------------===//
//
// The LLVM Linker
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_READER_WRITER_RELOCATION_HELPER_FUNCTIONS_H
#define LLD_READER_WRITER_RELOCATION_HELPER_FUNCTIONS_H
namespace lld {
/// \brief Return the bits that are described by the mask
template < typename T >
T BitsGather(T val, T mask)
{
T result = 0;
size_t off = 0;
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;
++off;
}
}
return result;
}
template <typename T>
T BitsScatter(T val, T mask)
{
T result = 0;
size_t off = 0;
for (size_t bit = 0; bit != sizeof (T) * 8; ++bit) {
const bool valBit = (val >> off) & 1;
const bool maskBit = (mask >> bit) & 1;
if (maskBit) {
result |= static_cast<T>(valBit) << bit;
++off;
}
}
return result;
}
} // namespace lld
#endif // LLD_READER_WRITER_RELOCATION_HELPER_FUNCTIONS_H