diff --git a/llvm/include/llvm/Support/OnDiskHashTable.h b/llvm/include/llvm/Support/OnDiskHashTable.h --- a/llvm/include/llvm/Support/OnDiskHashTable.h +++ b/llvm/include/llvm/Support/OnDiskHashTable.h @@ -17,7 +17,6 @@ #include "llvm/Support/Allocator.h" #include "llvm/Support/DataTypes.h" #include "llvm/Support/EndianStream.h" -#include "llvm/Support/Host.h" #include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include diff --git a/llvm/lib/Support/FoldingSet.cpp b/llvm/lib/Support/FoldingSet.cpp --- a/llvm/lib/Support/FoldingSet.cpp +++ b/llvm/lib/Support/FoldingSet.cpp @@ -15,8 +15,8 @@ #include "llvm/ADT/StringRef.h" #include "llvm/Support/Allocator.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/Host.h" #include "llvm/Support/MathExtras.h" +#include "llvm/Support/SwapByteOrder.h" #include #include using namespace llvm; diff --git a/llvm/lib/Support/SHA1.cpp b/llvm/lib/Support/SHA1.cpp --- a/llvm/lib/Support/SHA1.cpp +++ b/llvm/lib/Support/SHA1.cpp @@ -18,15 +18,11 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Endian.h" -#include "llvm/Support/Host.h" +#include "llvm/Support/SwapByteOrder.h" #include using namespace llvm; -#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN -#define SHA_BIG_ENDIAN -#endif - static inline uint32_t rol(uint32_t Number, int Bits) { return (Number << Bits) | (Number >> (32 - Bits)); } @@ -192,11 +188,11 @@ } void SHA1::addUncounted(uint8_t Data) { -#ifdef SHA_BIG_ENDIAN - InternalState.Buffer.C[InternalState.BufferOffset] = Data; -#else - InternalState.Buffer.C[InternalState.BufferOffset ^ 3] = Data; -#endif + if (sys::IsBigEndianHost) { + InternalState.Buffer.C[InternalState.BufferOffset] = Data; + } else { + InternalState.Buffer.C[InternalState.BufferOffset ^ 3] = Data; + } InternalState.BufferOffset++; if (InternalState.BufferOffset == BLOCK_LENGTH) { @@ -267,20 +263,17 @@ // Pad to complete the last block pad(); -#ifdef SHA_BIG_ENDIAN - // Just copy the current state - for (int i = 0; i < 5; i++) { - HashResult[i] = InternalState.State[i]; - } -#else - // Swap byte order back - for (int i = 0; i < 5; i++) { - HashResult[i] = (((InternalState.State[i]) << 24) & 0xff000000) | - (((InternalState.State[i]) << 8) & 0x00ff0000) | - (((InternalState.State[i]) >> 8) & 0x0000ff00) | - (((InternalState.State[i]) >> 24) & 0x000000ff); + if (sys::IsBigEndianHost) { + // Just copy the current state + for (int i = 0; i < 5; i++) { + HashResult[i] = InternalState.State[i]; + } + } else { + // Swap byte order back + for (int i = 0; i < 5; i++) { + HashResult[i] = sys::getSwappedBytes(InternalState.State[i]); + } } -#endif } std::array SHA1::final() { diff --git a/llvm/lib/Support/SHA256.cpp b/llvm/lib/Support/SHA256.cpp --- a/llvm/lib/Support/SHA256.cpp +++ b/llvm/lib/Support/SHA256.cpp @@ -23,15 +23,11 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/Endian.h" -#include "llvm/Support/Host.h" +#include "llvm/Support/SwapByteOrder.h" #include namespace llvm { -#if defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN -#define SHA_BIG_ENDIAN -#endif - #define SHR(x, c) ((x) >> (c)) #define ROTR(x, n) (((x) >> n) | ((x) << (32 - (n)))) @@ -171,11 +167,11 @@ } void SHA256::addUncounted(uint8_t Data) { -#ifdef SHA_BIG_ENDIAN - InternalState.Buffer.C[InternalState.BufferOffset] = Data; -#else - InternalState.Buffer.C[InternalState.BufferOffset ^ 3] = Data; -#endif + if (sys::IsBigEndianHost) { + InternalState.Buffer.C[InternalState.BufferOffset] = Data; + } else { + InternalState.Buffer.C[InternalState.BufferOffset ^ 3] = Data; + } InternalState.BufferOffset++; if (InternalState.BufferOffset == BLOCK_LENGTH) { @@ -247,20 +243,17 @@ // Pad to complete the last block pad(); -#ifdef SHA_BIG_ENDIAN - // Just copy the current state - for (int i = 0; i < 8; i++) { - HashResult[i] = InternalState.State[i]; - } -#else - // Swap byte order back - for (int i = 0; i < 8; i++) { - HashResult[i] = (((InternalState.State[i]) << 24) & 0xff000000) | - (((InternalState.State[i]) << 8) & 0x00ff0000) | - (((InternalState.State[i]) >> 8) & 0x0000ff00) | - (((InternalState.State[i]) >> 24) & 0x000000ff); + if (sys::IsBigEndianHost) { + // Just copy the current state + for (int i = 0; i < 8; i++) { + HashResult[i] = InternalState.State[i]; + } + } else { + // Swap byte order back + for (int i = 0; i < 8; i++) { + HashResult[i] = sys::getSwappedBytes(InternalState.State[i]); + } } -#endif } std::array SHA256::final() {