From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id CNv2KjEd72HzWwAAWB0awg (envelope-from ) for ; Mon, 24 Jan 2022 16:42:09 -0500 Received: by simark.ca (Postfix, from userid 112) id AE2461F3B6; Mon, 24 Jan 2022 16:42:09 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.2 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5D7BF1EA69 for ; Mon, 24 Jan 2022 16:42:09 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 644383858013 for ; Mon, 24 Jan 2022 21:42:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 644383858013 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1643060528; bh=GkolQaYuDNU2K7z1ExEsc3IyKwIHcQ7rLT3i6WJ+vUc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=POMm4js3Uds0aCuXe8KODkcq8w1ofpkETld6St4j1bfiIKNlGN2pUAP+2UnyQMXxH f5Jz/VLOFJfGfPPnVYtfMrKuJiKiQi/SE+zA+M2VVVJmQXSraM9IApn3S9jogMUia8 726aC3ard280ju925SZJfglBCyz16Rq5ka9qbbp0= Received: from barracuda.ebox.ca (barracuda.ebox.ca [96.127.255.19]) by sourceware.org (Postfix) with ESMTPS id AA6953858412 for ; Mon, 24 Jan 2022 21:41:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AA6953858412 X-ASG-Debug-ID: 1643060501-0c856e06ab20a380001-fS2M51 Received: from smtp.ebox.ca (smtp.ebox.ca [96.127.255.82]) by barracuda.ebox.ca with ESMTP id ZWr0H6o40tLPdQNP (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Mon, 24 Jan 2022 16:41:41 -0500 (EST) X-Barracuda-Envelope-From: simon.marchi@polymtl.ca X-Barracuda-RBL-Trusted-Forwarder: 96.127.255.82 Received: from simark.localdomain (192-222-157-6.qc.cable.ebox.net [192.222.157.6]) by smtp.ebox.ca (Postfix) with ESMTP id 9CA07441D64; Mon, 24 Jan 2022 16:41:41 -0500 (EST) X-Barracuda-RBL-IP: 192.222.157.6 X-Barracuda-Effective-Source-IP: 192-222-157-6.qc.cable.ebox.net[192.222.157.6] X-Barracuda-Apparent-Source-IP: 192.222.157.6 To: gdb-patches@sourceware.org Subject: [PATCH] gdbsupport: simplify ptid_t::is_pid implementation Date: Mon, 24 Jan 2022 16:41:41 -0500 X-ASG-Orig-Subj: [PATCH] gdbsupport: simplify ptid_t::is_pid implementation Message-Id: <20220124214141.1571525-1-simon.marchi@polymtl.ca> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Barracuda-Connect: smtp.ebox.ca[96.127.255.82] X-Barracuda-Start-Time: 1643060501 X-Barracuda-Encrypted: DHE-RSA-AES256-SHA X-Barracuda-URL: https://96.127.255.19:443/cgi-mod/mark.cgi X-Barracuda-BRTS-Status: 1 X-Virus-Scanned: by bsmtpd at ebox.ca X-Barracuda-Scan-Msg-Size: 3377 X-Barracuda-Spam-Score: 0.00 X-Barracuda-Spam-Status: No, SCORE=0.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=8.0 tests= X-Barracuda-Spam-Report: Code version 3.2, rules version 3.2.3.95550 Rule breakdown below pts rule name description ---- ---------------------- -------------------------------------------------- X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "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