mirror of
https://github.com/boostorg/endian.git
synced 2025-07-29 20:17:26 +02:00
For X86 and X64 architectures, which permit unaligned loads and stores, unaligned little endian buffer and arithmetic types use regular loads and stores when the size is exact. This makes unaligned little endian buffer and arithmetic types significantly more efficient on these architectures.(Pull request from Jeremy Maitin-Shepard) Docs updated, but timing results have not yet been updated.
This commit is contained in:
@ -632,6 +632,11 @@ review</a></h3>
|
||||
uint8_t</code> have been added for improved generality. (Pierre Talbot)</li>
|
||||
<li>Overloads of <code>endian_reverse_inplace()</code> have been replaced with a single <code>
|
||||
endian_reverse_inplace()</code> template. (Pierre Talbot)</li>
|
||||
<li>For X86 and X64 architectures, which permit unaligned loads and stores,
|
||||
unaligned little endian buffer and arithmetic types use regular loads and
|
||||
stores when the size is exact. This makes unaligned little endian buffer and
|
||||
arithmetic types significantly more efficient on these architectures. (Jeremy
|
||||
Maitin-Shepard)</li>
|
||||
<li>C++11 features affecting interfaces, such as <code>noexcept</code>, are now used.
|
||||
C++03 compilers are still
|
||||
supported.</li>
|
||||
@ -641,15 +646,15 @@ review</a></h3>
|
||||
<h2><a name="Acknowledgements">Acknowledgements</a></h2>
|
||||
<p>Comments and suggestions were received from Adder, Benaka Moorthi,
|
||||
Christopher Kohlhoff, Cliff Green, Daniel James, Gennaro Proto, Giovanni Piero
|
||||
Deretta, Gordon Woodhull, dizzy, Hartmut Kaiser, Jeff Flinn, John Filo, John
|
||||
Deretta, Gordon Woodhull, dizzy, Hartmut Kaiser, Jeff Flinn, Jeremy Maitin-Shepard, John Filo, John
|
||||
Maddock, Kim Barrett, Marsh Ray, Martin Bonner, Mathias Gaunard, Matias
|
||||
Capeletto, Neil Mayhew, Paul Bristow, Pierre Talbot, Phil Endecott, Pyry Jahkola,
|
||||
Rene Rivera, Robert Stewart, Roland Schwarz, Scott McMurray, Sebastian Redl, Tim
|
||||
Blechmann, Tim Moore, tymofey, Tomas Puverle, Vincente Botet, Yuval Ronen and
|
||||
Vitaly Budovski,.</p>
|
||||
Vitaly Budovsk. Apologies if anyone has been missed.</p>
|
||||
<hr>
|
||||
<p>Last revised:
|
||||
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->04 January, 2015<!--webbot bot="Timestamp" endspan i-checksum="38892" --></p>
|
||||
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%d %B, %Y" startspan -->06 January, 2015<!--webbot bot="Timestamp" endspan i-checksum="38896" --></p>
|
||||
<p>© Copyright Beman Dawes, 2011, 2013</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. See
|
||||
<a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/ LICENSE_1_0.txt</a></p>
|
||||
|
@ -291,6 +291,16 @@ namespace endian
|
||||
inline
|
||||
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.
|
||||
{
|
||||
return *reinterpret_cast<T const *>(bytes);
|
||||
}
|
||||
# endif
|
||||
return unrolled_byte_loops<T, n_bytes>::load_little
|
||||
(static_cast<const unsigned char*>(bytes));
|
||||
}
|
||||
@ -307,6 +317,17 @@ namespace endian
|
||||
inline
|
||||
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.
|
||||
{
|
||||
*reinterpret_cast<T *>(bytes) = value;
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
unrolled_byte_loops<T, n_bytes>::store_little
|
||||
(static_cast<char*>(bytes), value);
|
||||
}
|
||||
|
@ -26,16 +26,26 @@ int cpp_main(int, char *[])
|
||||
{
|
||||
cout << "byte swap intrinsics: " BOOST_ENDIAN_INTRINSIC_MSG << endl;
|
||||
|
||||
cout << " construct" << endl;
|
||||
cout << " construct big endian aligned" << endl;
|
||||
bel::big_int32_buf_t x(1122334455);
|
||||
|
||||
cout << " assign from built-in integer" << endl;
|
||||
cout << " assign to buffer from built-in integer" << endl;
|
||||
x = 1234567890;
|
||||
|
||||
cout << " operator==(buffer, built-in)" << endl;
|
||||
cout << " operator==(buffer.value(), built-in)" << endl;
|
||||
bool b1(x.value() == 1234567890);
|
||||
BOOST_TEST(b1);
|
||||
|
||||
cout << " construct little endian unaligned" << endl;
|
||||
bel::little_int32_buf_ut x2(1122334455);
|
||||
|
||||
cout << " assign to buffer from built-in integer" << endl;
|
||||
x2 = 1234567890;
|
||||
|
||||
cout << " operator==(buffer.value(), built-in)" << endl;
|
||||
bool b2(x2.value() == 1234567890);
|
||||
BOOST_TEST(b2);
|
||||
|
||||
cout << " done" << endl;
|
||||
|
||||
return ::boost::report_errors();
|
||||
|
@ -92,6 +92,7 @@
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AssemblerOutput>AssemblyAndSourceCode</AssemblerOutput>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@ -122,6 +123,7 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AssemblerOutput>AssemblyAndSourceCode</AssemblerOutput>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
@ -140,6 +142,7 @@
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<AssemblerOutput>AssemblyAndSourceCode</AssemblerOutput>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
Reference in New Issue
Block a user