diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2020-04-06 15:21:16 +0200 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2020-04-06 15:51:24 +0200 |
commit | 880ec421dd206605e174abbfcb91a9573a2c1428 (patch) | |
tree | ccab1d5b0d5f1345ff79b686e02cb979c218191a /llvm/lib/MC/MCStreamer.cpp | |
parent | 6babae74c735bb40611cef9aaffd95c19f2c0743 (diff) | |
download | llvm-880ec421dd206605e174abbfcb91a9573a2c1428.zip llvm-880ec421dd206605e174abbfcb91a9573a2c1428.tar.gz llvm-880ec421dd206605e174abbfcb91a9573a2c1428.tar.bz2 |
[MC] Use a byte_swap in emitIntValue instead of doing it in a loop. NFCI.
Diffstat (limited to 'llvm/lib/MC/MCStreamer.cpp')
-rw-r--r-- | llvm/lib/MC/MCStreamer.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/llvm/lib/MC/MCStreamer.cpp b/llvm/lib/MC/MCStreamer.cpp index 78c1e9e..af5249d 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 |