From: Simon Marchi <simon.marchi@polymtl.ca>
To: gdb-patches@sourceware.org
Subject: [PATCH] gdbsupport: simplify ptid_t::is_pid implementation
Date: Mon, 24 Jan 2022 16:41:41 -0500 [thread overview]
Message-ID: <20220124214141.1571525-1-simon.marchi@polymtl.ca> (raw)
The current ptid_t::is_pid implementation makes more comparisons than
necessary. We can simplify it to just check that the pid value is
positive and the other two components are 0.
The only difference in behavior I can see between the old and new
implementation is that we would previously return true for a ptid like
(-2,0,0), and we would now return false. But AFAIK, negative pid values
other than -1 (for minus_one_ptid) are not allowed.
Out of curiosity, I compiled a dummy function that calls ptid_t::is_pid
to see the generated assembly before and after. The new version is much
shorter (not that I think that it will make a real world difference).
Before:
0000000000000060 <_Z4test6ptid_t>:
60: 8b 44 24 08 mov 0x8(%rsp),%eax
64: 48 8b 54 24 10 mov 0x10(%rsp),%rdx
69: 48 8b 4c 24 18 mov 0x18(%rsp),%rcx
6e: 85 c0 test %eax,%eax
70: 74 1e je 90 <_Z4test6ptid_t+0x30>
72: 83 f8 ff cmp $0xffffffff,%eax
75: 74 11 je 88 <_Z4test6ptid_t+0x28>
77: 48 85 d2 test %rdx,%rdx
7a: 75 34 jne b0 <_Z4test6ptid_t+0x50>
7c: 48 85 c9 test %rcx,%rcx
7f: 0f 94 c0 sete %al
82: c3 ret
83: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
88: 31 c0 xor %eax,%eax
8a: 48 85 d2 test %rdx,%rdx
8d: 74 11 je a0 <_Z4test6ptid_t+0x40>
8f: c3 ret
90: 48 85 d2 test %rdx,%rdx
93: 75 fa jne 8f <_Z4test6ptid_t+0x2f>
95: 48 85 c9 test %rcx,%rcx
98: 75 e2 jne 7c <_Z4test6ptid_t+0x1c>
9a: c3 ret
9b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
a0: 48 85 c9 test %rcx,%rcx
a3: 75 d7 jne 7c <_Z4test6ptid_t+0x1c>
a5: c3 ret
After:
0000000000000060 <_Z4test6ptid_t>:
60: 8b 54 24 08 mov 0x8(%rsp),%edx
64: 31 c0 xor %eax,%eax
66: 85 d2 test %edx,%edx
68: 7e 0d jle 77 <_Z4test6ptid_t+0x17>
6a: 48 8b 44 24 18 mov 0x18(%rsp),%rax
6f: 48 0b 44 24 10 or 0x10(%rsp),%rax
74: 0f 94 c0 sete %al
77: c3 ret
Change-Id: I40f2cd8a3736c9abe37bfa2b03df6068d9581ba2
---
gdbsupport/ptid.h | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/gdbsupport/ptid.h b/gdbsupport/ptid.h
index d66cd9884590..5b38742b7606 100644
--- a/gdbsupport/ptid.h
+++ b/gdbsupport/ptid.h
@@ -83,10 +83,7 @@ class ptid_t
constexpr bool is_pid () const
{
- return (*this != make_null ()
- && *this != make_minus_one ()
- && m_lwp == 0
- && m_tid == 0);
+ return m_pid > 0 && m_lwp == 0 && m_tid == 0;
}
/* Compare two ptids to see if they are equal. */
base-commit: 94fd627d46e7774e96a381cc9174cedcbf6e5577
--
2.34.1
next reply other threads:[~2022-01-24 21:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 21:41 Simon Marchi [this message]
2022-01-25 23:53 ` Kevin Buettner
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=20220124214141.1571525-1-simon.marchi@polymtl.ca \
--to=simon.marchi@polymtl.ca \
--cc=gdb-patches@sourceware.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).