From: Jonathan Wakely <jwakely@redhat.com>
To: Jonathan Wakely <jwakely@redhat.com>
Cc: "libstdc++" <libstdc++@gcc.gnu.org>,
gcc Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [committed] libstdc++: Improve behaviour of std::stacktrace::current
Date: Mon, 11 Apr 2022 22:27:55 +0100 [thread overview]
Message-ID: <CACb0b4kfdwQ5V-tJxw1WSPG3PtZ81wVBUx68DymQeic178Qzkg@mail.gmail.com> (raw)
In-Reply-To: <20220411170124.169564-1-jwakely@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 822 bytes --]
On Mon, 11 Apr 2022 at 18:03, Jonathan Wakely via Libstdc++
<libstdc++@gcc.gnu.org> wrote:
> // Precondition: _M_frames == nullptr
> pointer
> _M_allocate(allocator_type& __alloc, size_type __n) noexcept
> {
> __try
> {
> - _M_frames = __n ? __alloc.allocate(__n) : nullptr;
> - _M_capacity = __n;
> + if (0 < __n && __n <= _S_max_size(__alloc)) [[unlikely]]
I originally changed this to return early if the size isn't OK:
if (unlikely condition)
return nullptr;
but in the version I pushed it's:
if (likely condition)
// do allocation
but forgot to change the attribute to match.
Fixed by the attached. Tested x86_64-linux and pushed to trunk.
I have further improvements to stacktrace::current coming tomorrow.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 852 bytes --]
commit b1124648ff8f655307f264d7b353fd68e3b03e9c
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Mon Apr 11 20:13:44 2022
libstdc++: Fix incorrect branch prediction hint in std::stacktrace
libstdc++-v3/ChangeLog:
* include/std/stacktrace (basic_stacktrace::_Impl::_M_allocate):
Change [[unlikely]] attribute to [[likely]].
diff --git a/libstdc++-v3/include/std/stacktrace b/libstdc++-v3/include/std/stacktrace
index dd78c71c5dc..79038e803f2 100644
--- a/libstdc++-v3/include/std/stacktrace
+++ b/libstdc++-v3/include/std/stacktrace
@@ -579,7 +579,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
{
__try
{
- if (0 < __n && __n <= _S_max_size(__alloc)) [[unlikely]]
+ if (0 < __n && __n <= _S_max_size(__alloc)) [[likely]]
{
_M_frames = __alloc.allocate(__n);
_M_capacity = __n;
prev parent reply other threads:[~2022-04-11 21:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-11 17:01 Jonathan Wakely
2022-04-11 21:27 ` Jonathan Wakely [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CACb0b4kfdwQ5V-tJxw1WSPG3PtZ81wVBUx68DymQeic178Qzkg@mail.gmail.com \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).