public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdbsupport: simplify ptid_t::is_pid implementation
@ 2022-01-24 21:41 Simon Marchi
  2022-01-25 23:53 ` Kevin Buettner
  0 siblings, 1 reply; 2+ messages in thread
From: Simon Marchi @ 2022-01-24 21:41 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] gdbsupport: simplify ptid_t::is_pid implementation
  2022-01-24 21:41 [PATCH] gdbsupport: simplify ptid_t::is_pid implementation Simon Marchi
@ 2022-01-25 23:53 ` Kevin Buettner
  0 siblings, 0 replies; 2+ messages in thread
From: Kevin Buettner @ 2022-01-25 23:53 UTC (permalink / raw)
  To: Simon Marchi via Gdb-patches

On Mon, 24 Jan 2022 16:41:41 -0500
Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> wrote:

> 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.

LGTM.

Kevin


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-01-25 23:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-24 21:41 [PATCH] gdbsupport: simplify ptid_t::is_pid implementation Simon Marchi
2022-01-25 23:53 ` Kevin Buettner

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).