[gcc r15-2653] libstdc++: Use memcmp to optimize std::bitset::_M_is_equal() [PR113807]
Jonathan Wakely
redi@gcc.gnu.org
Thu Aug 1 21:11:30 GMT 2024
https://gcc.gnu.org/g:e1729eb80489e6c8e03d7c9a072736350407c7f4
commit r15-2653-ge1729eb80489e6c8e03d7c9a072736350407c7f4
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Feb 8 15:46:08 2024 +0000
libstdc++: Use memcmp to optimize std::bitset::_M_is_equal() [PR113807]
As noted in the PR the compiler doesn't seem able to do this on its own,
so we get better code at all optimization levels by using memcmp.
libstdc++-v3/ChangeLog:
PR libstdc++/113807
* include/std/bitset (bitset::_M_is_equal()): Use memcmp to
optimize operator==.
Diff:
---
libstdc++-v3/include/std/bitset | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index ccd6d19f7a40..e5d677ff059c 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -205,10 +205,16 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX14_CONSTEXPR bool
_M_is_equal(const _Base_bitset<_Nw>& __x) const _GLIBCXX_NOEXCEPT
{
- for (size_t __i = 0; __i < _Nw; ++__i)
- if (_M_w[__i] != __x._M_w[__i])
- return false;
- return true;
+#if __cplusplus >= 201402L
+ if (__builtin_is_constant_evaluated())
+ {
+ for (size_t __i = 0; __i < _Nw; ++__i)
+ if (_M_w[__i] != __x._M_w[__i])
+ return false;
+ return true;
+ }
+#endif
+ return !__builtin_memcmp(_M_w, __x._M_w, _Nw * sizeof(_WordT));
}
template<size_t _Nb>
More information about the Libstdc++-cvs
mailing list