]> git.ipfire.org Git - thirdparty/gcc.git/commit - libstdc++-v3/include/std/bit
libstdc++: Implement std::byteswap for C++23
authorJakub Jelinek <jakub@redhat.com>
Sun, 28 Nov 2021 15:32:24 +0000 (16:32 +0100)
committerJakub Jelinek <jakub@redhat.com>
Sun, 28 Nov 2021 15:33:33 +0000 (16:33 +0100)
commit7393fa8b1d21eeeb37e59ff8efaebf178fd891e5
treee9783e8c9b7f6b196d9548b10793d0d9c88f83db
parent7a66c4909fd175ba429f39a3ca30be39ea02ae64
libstdc++: Implement std::byteswap for C++23

This patch attempts to implement P1272R4 (except for the std::bit_cast
changes in there which seem quite unrelated to this and will need to be
fixed on the compiler side).
While at least for GCC __builtin_bswap{16,32,64,128} should work fine
in constant expressions, I wonder about other compilers, so I'm using
a fallback implementation for constexpr evaluation always.
If you think that is unnecessary, I can drop the
__cpp_if_consteval >= 202106L &&
if !consteval
  {
and
  }
and reformat.
The fallback implementation is an attempt to make it work even for integral
types that don't have number of bytes divisible by 2 or when __CHAR_BIT__
is e.g. 16.

2021-11-28  Jakub Jelinek  <jakub@redhat.com>

* include/std/bit (__cpp_lib_byteswap, byteswap): Define.
* include/std/version (__cpp_lib_byteswap): Define.
* testsuite/26_numerics/bit/bit.byteswap/byteswap.cc: New test.
* testsuite/26_numerics/bit/bit.byteswap/version.cc: New test.
libstdc++-v3/include/std/bit
libstdc++-v3/include/std/version
libstdc++-v3/testsuite/26_numerics/bit/bit.byteswap/byteswap.cc [new file with mode: 0644]
libstdc++-v3/testsuite/26_numerics/bit/bit.byteswap/version.cc [new file with mode: 0644]