[PATCH] D48147: Add comment to scatter-bit operation, make it faster and rename it.

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 18 11:06:00 PDT 2018


ruiu updated this revision to Diff 156111.
ruiu added a comment.

- restore the original code
- renamed Result -> Ret for consistency with other functions


https://reviews.llvm.org/D48147

Files:
  lld/ELF/Arch/Hexagon.cpp


Index: lld/ELF/Arch/Hexagon.cpp
===================================================================
--- lld/ELF/Arch/Hexagon.cpp
+++ lld/ELF/Arch/Hexagon.cpp
@@ -35,19 +35,28 @@
 // Support V60 only at the moment.
 uint32_t Hexagon::calcEFlags() const { return 0x60; }
 
-static uint32_t applyMask(uint32_t Mask, uint32_t Data) {
-  uint32_t Result = 0;
+// This function scatter Val's bits as instructed by Mask.
+// Here is an example:
+//
+//  Val:    abcd efgh ijkl mnop
+//  Mask:   1110 0001 1111 0001
+//  Result: hij0 000k lmno 000p
+//
+// Some CPUs support this operation as a single instruction.
+// For example, Intel BMI2 extension has this operation as PDEP.
+static inline uint32_t scatter(uint32_t Val, uint32_t Mask) {
+  uint32_t Ret = 0;
   size_t Off = 0;
 
   for (size_t Bit = 0; Bit != 32; ++Bit) {
     uint32_t ValBit = (Data >> Off) & 1;
     uint32_t MaskBit = (Mask >> Bit) & 1;
     if (MaskBit) {
-      Result |= (ValBit << Bit);
+      Ret |= (ValBit << Bit);
       ++Off;
     }
   }
-  return Result;
+  return Ret;
 }
 
 RelExpr Hexagon::getRelExpr(RelType Type, const Symbol &S,
@@ -67,7 +76,7 @@
   case R_HEX_NONE:
     break;
   case R_HEX_B22_PCREL:
-    or32le(Loc, applyMask(0x1ff3ffe, Val >> 2));
+    or32le(Loc, scatter(Val >> 2, 0x1ff3ffe));
     break;
   default:
     error(getErrorLocation(Loc) + "unrecognized reloc " + toString(Type));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48147.156111.patch
Type: text/x-patch
Size: 1389 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180718/1ba49a5a/attachment.bin>


More information about the llvm-commits mailing list