forked from boostorg/endian
Cosmetic fixes
This commit is contained in:
@ -284,18 +284,13 @@ namespace endian
|
||||
T load_big_endian(const void* bytes) BOOST_NOEXCEPT
|
||||
{
|
||||
# if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
|
||||
// On x86 (which is little endian), unaligned loads are permitted
|
||||
if (sizeof(T) == n_bytes) // GCC 4.9, VC++ 14.0, and probably others, elide this
|
||||
// test and generate code only for the applicable return
|
||||
// case since sizeof(T) and n_bytes are known at compile
|
||||
// time.
|
||||
// All major x86 compilers elide this test and optimize out memcpy
|
||||
// (the x86 architecture allows unaligned loads, but -fsanitize=undefined does not)
|
||||
if (sizeof(T) == n_bytes)
|
||||
{
|
||||
// Avoids -fsanitize=undefined violations due to unaligned loads
|
||||
// All major x86 compilers optimize a short-sized memcpy into a single instruction
|
||||
|
||||
T t = 0;
|
||||
T t;
|
||||
std::memcpy( &t, bytes, sizeof(T) );
|
||||
return big_to_native(t);
|
||||
return endian::big_to_native(t);
|
||||
}
|
||||
# endif
|
||||
return unrolled_byte_loops<T, n_bytes>::load_big
|
||||
@ -307,18 +302,13 @@ namespace endian
|
||||
T load_little_endian(const void* bytes) BOOST_NOEXCEPT
|
||||
{
|
||||
# if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
|
||||
// On x86 (which is little endian), unaligned loads are permitted
|
||||
if (sizeof(T) == n_bytes) // GCC 4.9, VC++ 14.0, and probably others, elide this
|
||||
// test and generate code only for the applicable return
|
||||
// case since sizeof(T) and n_bytes are known at compile
|
||||
// time.
|
||||
// All major x86 compilers elide this test and optimize out memcpy
|
||||
// (the x86 architecture allows unaligned loads, but -fsanitize=undefined does not)
|
||||
if (sizeof(T) == n_bytes)
|
||||
{
|
||||
// Avoids -fsanitize=undefined violations due to unaligned loads
|
||||
// All major x86 compilers optimize a short-sized memcpy into a single instruction
|
||||
|
||||
T t;
|
||||
std::memcpy( &t, bytes, sizeof(T) );
|
||||
return t;
|
||||
return t; // or endian::little_to_native(t) if we ever extend the #ifdef to non-x86
|
||||
}
|
||||
# endif
|
||||
return unrolled_byte_loops<T, n_bytes>::load_little
|
||||
@ -330,16 +320,11 @@ namespace endian
|
||||
void store_big_endian(void* bytes, T value) BOOST_NOEXCEPT
|
||||
{
|
||||
# if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
|
||||
// On x86 (which is little endian), unaligned stores are permitted
|
||||
if (sizeof(T) == n_bytes) // GCC 4.9, VC++ 14.0, and probably others, elide this
|
||||
// test and generate code only for the applicable return
|
||||
// case since sizeof(T) and n_bytes are known at compile
|
||||
// time.
|
||||
// All major x86 compilers elide this test and optimize out memcpy
|
||||
// (the x86 architecture allows unaligned loads, but -fsanitize=undefined does not)
|
||||
if (sizeof(T) == n_bytes)
|
||||
{
|
||||
// Avoids -fsanitize=undefined violations due to unaligned stores
|
||||
// All major x86 compilers optimize a short-sized memcpy into a single instruction
|
||||
|
||||
boost::endian::native_to_big_inplace(value);
|
||||
endian::native_to_big_inplace(value);
|
||||
std::memcpy( bytes, &value, sizeof(T) );
|
||||
return;
|
||||
}
|
||||
@ -353,15 +338,12 @@ namespace endian
|
||||
void store_little_endian(void* bytes, T value) BOOST_NOEXCEPT
|
||||
{
|
||||
# if defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)
|
||||
// On x86 (which is little endian), unaligned stores are permitted
|
||||
if (sizeof(T) == n_bytes) // GCC 4.9, VC++ 14.0, and probably others, elide this
|
||||
// test and generate code only for the applicable return
|
||||
// case since sizeof(T) and n_bytes are known at compile
|
||||
// time.
|
||||
// All major x86 compilers elide this test and optimize out memcpy
|
||||
// (the x86 architecture allows unaligned loads, but -fsanitize=undefined does not)
|
||||
if (sizeof(T) == n_bytes)
|
||||
{
|
||||
// Avoids -fsanitize=undefined violations due to unaligned stores
|
||||
// All major x86 compilers optimize a short-sized memcpy into a single instruction
|
||||
|
||||
// if we ever extend the #ifdef to non-x86:
|
||||
// endian::native_to_little_inplace(value);
|
||||
std::memcpy( bytes, &value, sizeof(T) );
|
||||
return;
|
||||
}
|
||||
|
Reference in New Issue
Block a user