[lld] r173895 - add Relocation helper functions

Shankar Easwaran shankare at codeaurora.org
Tue Jan 29 20:49:55 PST 2013


Author: shankare
Date: Tue Jan 29 22:49:54 2013
New Revision: 173895

URL: http://llvm.org/viewvc/llvm-project?rev=173895&view=rev
Log:
add Relocation helper functions

Added:
    lld/trunk/include/lld/ReaderWriter/RelocationHelperFunctions.h

Added: lld/trunk/include/lld/ReaderWriter/RelocationHelperFunctions.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/ReaderWriter/RelocationHelperFunctions.h?rev=173895&view=auto
==============================================================================
--- lld/trunk/include/lld/ReaderWriter/RelocationHelperFunctions.h (added)
+++ lld/trunk/include/lld/ReaderWriter/RelocationHelperFunctions.h Tue Jan 29 22:49:54 2013
@@ -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





More information about the llvm-commits mailing list