Skip to content

Commit d4f0c05

Browse files
committed
[libc++] Use __builtin_bswapg to implement std::byteswap if it's available
1 parent 4d09368 commit d4f0c05

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

libcxx/include/__bit/byteswap.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ _LIBCPP_BEGIN_NAMESPACE_STD
2424

2525
template <integral _Tp>
2626
[[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp byteswap(_Tp __val) noexcept {
27+
#if __has_builtin(__builtin_bswapg)
28+
return __builtin_bswapg(__val);
29+
#else
2730
if constexpr (sizeof(_Tp) == 1) {
2831
return __val;
2932
} else if constexpr (sizeof(_Tp) == 2) {
@@ -44,6 +47,7 @@ template <integral _Tp>
4447
} else {
4548
static_assert(sizeof(_Tp) == 0, "byteswap is unimplemented for integral types of this size");
4649
}
50+
#endif
4751
}
4852

4953
#endif // _LIBCPP_STD_VER >= 23

0 commit comments

Comments
 (0)