[llvm] 880ec42 - [MC] Use a byte_swap in emitIntValue instead of doing it in a loop. NFCI.

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 6 06:51:36 PDT 2020


Author: Benjamin Kramer
Date: 2020-04-06T15:51:24+02:00
New Revision: 880ec421dd206605e174abbfcb91a9573a2c1428

URL: https://github.com/llvm/llvm-project/commit/880ec421dd206605e174abbfcb91a9573a2c1428
DIFF: https://github.com/llvm/llvm-project/commit/880ec421dd206605e174abbfcb91a9573a2c1428.diff

LOG: [MC] Use a byte_swap in emitIntValue instead of doing it in a loop.  NFCI.

Added: 
    

Modified: 
    llvm/lib/MC/MCStreamer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp
index 78c1e9ead83c..af5249dd5519 100644
--- a/llvm/lib/MC/MCStreamer.cpp
+++ b/llvm/lib/MC/MCStreamer.cpp
@@ -132,13 +132,11 @@ void MCStreamer::emitIntValue(uint64_t Value, unsigned Size) {
   assert(1 <= Size && Size <= 8 && "Invalid size");
   assert((isUIntN(8 * Size, Value) || isIntN(8 * Size, Value)) &&
          "Invalid size");
-  char buf[8];
-  const bool isLittleEndian = Context.getAsmInfo()->isLittleEndian();
-  for (unsigned i = 0; i != Size; ++i) {
-    unsigned index = isLittleEndian ? i : (Size - i - 1);
-    buf[i] = uint8_t(Value >> (index * 8));
-  }
-  emitBytes(StringRef(buf, Size));
+  const bool IsLittleEndian = Context.getAsmInfo()->isLittleEndian();
+  uint64_t Swapped = support::endian::byte_swap(
+      Value, IsLittleEndian ? support::little : support::big);
+  unsigned Index = IsLittleEndian ? 0 : 8 - Size;
+  emitBytes(StringRef(reinterpret_cast<char *>(&Swapped) + Index, Size));
 }
 
 /// EmitULEB128IntValue - Special case of EmitULEB128Value that avoids the


        


More information about the llvm-commits mailing list