public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9002] libstdc++: Use memset to optimize std::bitset::set() [PR113807]
@ 2024-02-15 11:44 Jonathan Wakely
0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2024-02-15 11:44 UTC (permalink / raw)
To: gcc-cvs, libstdc++-cvs
https://gcc.gnu.org/g:e7ae13a858f36031b8fd3aa07362752ff2b19b2e
commit r14-9002-ge7ae13a858f36031b8fd3aa07362752ff2b19b2e
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Thu Feb 8 15:46:08 2024 +0000
libstdc++: Use memset to optimize std::bitset::set() [PR113807]
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.
Diff:
---
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 3243c6497314..16c4040f532f 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-02-15 11:44 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:44 [gcc r14-9002] 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).