[llvm-commits] [llvm] r111230 - /llvm/trunk/include/llvm/MC/MCObjectWriter.h
Benjamin Kramer
benny.kra at googlemail.com
Tue Aug 17 06:55:45 PDT 2010
Author: d0k
Date: Tue Aug 17 08:55:45 2010
New Revision: 111230
URL: http://llvm.org/viewvc/llvm-project?rev=111230&view=rev
Log:
Micro-optimize MCObjectWriter to do a byteswap if necessary and then write the
whole integer to the stream instead of doing byte-sized writes.
Modified:
llvm/trunk/include/llvm/MC/MCObjectWriter.h
Modified: llvm/trunk/include/llvm/MC/MCObjectWriter.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCObjectWriter.h?rev=111230&r1=111229&r2=111230&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCObjectWriter.h (original)
+++ llvm/trunk/include/llvm/MC/MCObjectWriter.h Tue Aug 17 08:55:45 2010
@@ -10,8 +10,10 @@
#ifndef LLVM_MC_MCOBJECTWRITER_H
#define LLVM_MC_MCOBJECTWRITER_H
+#include "llvm/Support/MathExtras.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/System/DataTypes.h"
+#include "llvm/System/Host.h"
#include <cassert>
namespace llvm {
@@ -92,54 +94,57 @@
}
void WriteLE16(uint16_t Value) {
- Write8(uint8_t(Value >> 0));
- Write8(uint8_t(Value >> 8));
+ if (sys::isBigEndianHost())
+ Value = ByteSwap_16(Value);
+ OS << StringRef((const char*)&Value, sizeof(Value));
}
void WriteLE32(uint32_t Value) {
- WriteLE16(uint16_t(Value >> 0));
- WriteLE16(uint16_t(Value >> 16));
+ if (sys::isBigEndianHost())
+ Value = ByteSwap_32(Value);
+ OS << StringRef((const char*)&Value, sizeof(Value));
}
void WriteLE64(uint64_t Value) {
- WriteLE32(uint32_t(Value >> 0));
- WriteLE32(uint32_t(Value >> 32));
+ if (sys::isBigEndianHost())
+ Value = ByteSwap_64(Value);
+ OS << StringRef((const char*)&Value, sizeof(Value));
}
void WriteBE16(uint16_t Value) {
- Write8(uint8_t(Value >> 8));
- Write8(uint8_t(Value >> 0));
+ if (sys::isLittleEndianHost())
+ Value = ByteSwap_16(Value);
+ OS << StringRef((const char*)&Value, sizeof(Value));
}
void WriteBE32(uint32_t Value) {
- WriteBE16(uint16_t(Value >> 16));
- WriteBE16(uint16_t(Value >> 0));
+ if (sys::isLittleEndianHost())
+ Value = ByteSwap_32(Value);
+ OS << StringRef((const char*)&Value, sizeof(Value));
}
void WriteBE64(uint64_t Value) {
- WriteBE32(uint32_t(Value >> 32));
- WriteBE32(uint32_t(Value >> 0));
+ if (sys::isLittleEndianHost())
+ Value = ByteSwap_64(Value);
+ OS << StringRef((const char*)&Value, sizeof(Value));
}
void Write16(uint16_t Value) {
- if (IsLittleEndian)
- WriteLE16(Value);
- else
- WriteBE16(Value);
+ if (IsLittleEndian != sys::isLittleEndianHost())
+ Value = ByteSwap_16(Value);
+ OS << StringRef((const char*)&Value, sizeof(Value));
}
void Write32(uint32_t Value) {
- if (IsLittleEndian)
- WriteLE32(Value);
- else
- WriteBE32(Value);
+ if (IsLittleEndian != sys::isLittleEndianHost())
+ Value = ByteSwap_32(Value);
+ OS << StringRef((const char*)&Value, sizeof(Value));
}
void Write64(uint64_t Value) {
- if (IsLittleEndian)
- WriteLE64(Value);
- else
- WriteBE64(Value);
+ if (IsLittleEndian != sys::isLittleEndianHost())
+ Value = ByteSwap_64(Value);
+ OS << StringRef((const char*)&Value, sizeof(Value));
}
void WriteZeros(unsigned N) {
More information about the llvm-commits
mailing list