From a51870b143350b611a6b097e85b676c18678ee13 Mon Sep 17 00:00:00 2001 From: Shankar Easwaran Date: Wed, 30 Jan 2013 04:49:54 +0000 Subject: [PATCH] add Relocation helper functions llvm-svn: 173895 --- .../lld/ReaderWriter/RelocationHelperFunctions.h | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 lld/include/lld/ReaderWriter/RelocationHelperFunctions.h diff --git a/lld/include/lld/ReaderWriter/RelocationHelperFunctions.h b/lld/include/lld/ReaderWriter/RelocationHelperFunctions.h new file mode 100644 index 0000000..cfdbd14 --- /dev/null +++ b/lld/include/lld/ReaderWriter/RelocationHelperFunctions.h @@ -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 (valBit) << off; + ++off; + } + } + return result; +} + +template +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(valBit) << bit; + ++off; + } + } + return result; +} + +} // namespace lld + +#endif // LLD_READER_WRITER_RELOCATION_HELPER_FUNCTIONS_H -- 2.7.4