[llvm-commits] [llvm] r117124 - in /llvm/trunk: cmake/config-ix.cmake include/llvm/Config/config.h.cmake include/llvm/Support/Endian.h
Michael J. Spencer
bigcheesegs at gmail.com
Fri Oct 22 11:45:12 PDT 2010
Author: mspencer
Date: Fri Oct 22 13:45:12 2010
New Revision: 117124
URL: http://llvm.org/viewvc/llvm-project?rev=117124&view=rev
Log:
Endian: Get rid of LLVM_IS_HOST_BIG_ENDIAN.
Modified:
llvm/trunk/cmake/config-ix.cmake
llvm/trunk/include/llvm/Config/config.h.cmake
llvm/trunk/include/llvm/Support/Endian.h
Modified: llvm/trunk/cmake/config-ix.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/cmake/config-ix.cmake?rev=117124&r1=117123&r2=117124&view=diff
==============================================================================
--- llvm/trunk/cmake/config-ix.cmake (original)
+++ llvm/trunk/cmake/config-ix.cmake Fri Oct 22 13:45:12 2010
@@ -258,8 +258,6 @@
endif()
endif()
-test_big_endian(LLVM_IS_HOST_BIG_ENDIAN)
-
if( ENABLE_THREADS )
message(STATUS "Threads enabled.")
else( ENABLE_THREADS )
Modified: llvm/trunk/include/llvm/Config/config.h.cmake
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Config/config.h.cmake?rev=117124&r1=117123&r2=117124&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Config/config.h.cmake (original)
+++ llvm/trunk/include/llvm/Config/config.h.cmake Fri Oct 22 13:45:12 2010
@@ -506,9 +506,6 @@
/* Define if this is Win32ish platform */
#cmakedefine LLVM_ON_WIN32 ${LLVM_ON_WIN32}
-/* Define if this is targeting a big endian system */
-#cmakedefine LLVM_IS_HOST_BIG_ENDIAN ${LLVM_IS_HOST_BIG_ENDIAN}
-
/* Added by Kevin -- Maximum path length */
#cmakedefine MAXPATHLEN ${MAXPATHLEN}
Modified: llvm/trunk/include/llvm/Support/Endian.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/Endian.h?rev=117124&r1=117123&r2=117124&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/Endian.h (original)
+++ llvm/trunk/include/llvm/Support/Endian.h Fri Oct 22 13:45:12 2010
@@ -15,6 +15,7 @@
#define LLVM_SUPPORT_ENDIAN_H
#include "llvm/Config/config.h"
+#include "llvm/System/Host.h"
#include "llvm/System/SwapByteOrder.h"
#include "llvm/Support/type_traits.h"
@@ -24,19 +25,6 @@
enum endianness {big, little};
enum alignment {unaligned, aligned};
-template<typename value_type, int host, int target>
-static typename enable_if_c<host == target, value_type>::type
-SwapByteOrderIfDifferent(value_type value) {
- // Target endianess is the same as the host. Just pass the value through.
- return value;
-}
-
-template<typename value_type, int host, int target>
-static typename enable_if_c<host != target, value_type>::type
-SwapByteOrderIfDifferent(value_type value) {
- return sys::SwapByteOrder<value_type>(value);
-}
-
namespace detail {
template<typename value_type, alignment align>
@@ -60,52 +48,49 @@
} // end namespace detail
-#if defined(LLVM_IS_HOST_BIG_ENDIAN) \
- || defined(_BIG_ENDIAN) || defined(__BIG_ENDIAN__)
-static const endianness host_endianness = big;
-#else
-static const endianness host_endianness = little;
-#endif
-
-struct endian {
- template<typename value_type, alignment align>
- static value_type read_le(const void *memory) {
- return SwapByteOrderIfDifferent<value_type, host_endianness, little>(
- reinterpret_cast<const detail::alignment_access_helper
- <value_type, align> *>(memory)->val);
- }
-
- template<typename value_type, alignment align>
- static void write_le(void *memory, value_type value) {
- reinterpret_cast<detail::alignment_access_helper<value_type, align> *>
- (memory)->val =
- SwapByteOrderIfDifferent< value_type
- , host_endianness
- , little>(value);
- }
-
- template<typename value_type, alignment align>
- static value_type read_be(const void *memory) {
- return SwapByteOrderIfDifferent<value_type, host_endianness, big>(
- reinterpret_cast<const detail::alignment_access_helper
- <value_type, align> *>(memory)->val);
- }
-
- template<typename value_type, alignment align>
- static void write_be(void *memory, value_type value) {
- reinterpret_cast<detail::alignment_access_helper
- <value_type, align> *>(memory)->val =
- SwapByteOrderIfDifferent< value_type
- , host_endianness
- , big>(value);
+namespace endian {
+ template<typename value_type, alignment align>
+ static value_type read_le(const void *memory) {
+ value_type t =
+ reinterpret_cast<const detail::alignment_access_helper
+ <value_type, align> *>(memory)->val;
+ if (sys::isBigEndianHost())
+ return sys::SwapByteOrder(t);
+ return t;
+ }
+
+ template<typename value_type, alignment align>
+ static void write_le(void *memory, value_type value) {
+ if (sys::isBigEndianHost())
+ value = sys::SwapByteOrder(value);
+ reinterpret_cast<detail::alignment_access_helper<value_type, align> *>
+ (memory)->val = value;
+ }
+
+ template<typename value_type, alignment align>
+ static value_type read_be(const void *memory) {
+ value_type t =
+ reinterpret_cast<const detail::alignment_access_helper
+ <value_type, align> *>(memory)->val;
+ if (sys::isLittleEndianHost())
+ return sys::SwapByteOrder(t);
+ return t;
+ }
+
+ template<typename value_type, alignment align>
+ static void write_be(void *memory, value_type value) {
+ if (sys::isLittleEndianHost())
+ value = sys::SwapByteOrder(value);
+ reinterpret_cast<detail::alignment_access_helper<value_type, align> *>
+ (memory)->val = value;
}
};
namespace detail {
template<typename value_type,
- endianness target_endianness,
- alignment target_alignment>
+ endianness endian,
+ alignment align>
class packed_endian_specific_integral;
template<typename value_type>
More information about the llvm-commits
mailing list