* [committed] libstdc++: Use memset to optimize std::bitset::set() [PR113807]
@ 2024-02-15 11:46 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2024-02-15 11:46 UTC (permalink / raw)
To: libstdc++, gcc-patches
Tested aarch64-linux and x86_64-linux. Pushed to trunk.
-- >8 --
As pointed out in the PR we already do this for reset().
libstdc++-v3/ChangeLog:
PR libstdc++/113807
* include/std/bitset (bitset::set()): Use memset instead of a
loop over the individual words.
---
libstdc++-v3/include/std/bitset | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index 3243c649731..16c4040f532 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -177,8 +177,15 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
_GLIBCXX14_CONSTEXPR void
_M_do_set() _GLIBCXX_NOEXCEPT
{
- for (size_t __i = 0; __i < _Nw; __i++)
- _M_w[__i] = ~static_cast<_WordT>(0);
+#if __cplusplus >= 201402L
+ if (__builtin_is_constant_evaluated())
+ {
+ for (_WordT& __w : _M_w)
+ __w = ~static_cast<_WordT>(0);;
+ return;
+ }
+#endif
+ __builtin_memset(_M_w, 0xFF, _Nw * sizeof(_WordT));
}
_GLIBCXX14_CONSTEXPR void
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-15 11:46 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-15 11:46 [committed] libstdc++: Use memset to optimize std::bitset::set() [PR113807] Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).