From patchwork Fri Nov 4 09:37:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 59893 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4BFF83858298 for ; Fri, 4 Nov 2022 09:38:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4BFF83858298 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667554709; bh=4F6JquYWwGBGYv5c+ehsOFprIaT//Dh76iRuDufiLDk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=t9dvcdxIQSGcIOo9jVseHcVO/C9Fq3x3GetSaivqvTkA7mZTBdNrPV3tjmoNeeU8i w/ZQVcz8io7v5CnfA/T0wGtm49WEL1IXtpJ9S8tr8m6o1loHbHvnFjdlTouKMnc/ll RQQqciu0xWbHNtxH/FbI73a7xUD6nkBjitfbTf8Y= X-Original-To: gcc-patches@sourceware.org Delivered-To: gcc-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 7FC7A3858422 for ; Fri, 4 Nov 2022 09:38:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7FC7A3858422 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-617-mo7pVrTyNaCvKbWCcOwbeQ-1; Fri, 04 Nov 2022 05:37:58 -0400 X-MC-Unique: mo7pVrTyNaCvKbWCcOwbeQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 69270101A54E; Fri, 4 Nov 2022 09:37:58 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.2.16.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DD8AB4EA5C; Fri, 4 Nov 2022 09:37:57 +0000 (UTC) To: gcc-patches@sourceware.org Subject: [PATCH v2] libgcc: Mostly vectorize CIE encoding extraction for FDEs Date: Fri, 04 Nov 2022 10:37:56 +0100 Message-ID: <878rkr12mj.fsf@oldenburg.str.redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Gcc-patches From: Florian Weimer Reply-To: Florian Weimer Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" "zR" and "zPLR" are the most common augmentations. Use a simple SIMD-with-in-a-register technique to check for both augmentations, and that the following variable-length integers have length 1, to get more quickly at the encoding field. libgcc/ * unwind-dw2-fde.c (get_cie_encoding_slow): Rename from get_cie_encoding. Mark as noinline. (get_cie_encoding): Add fast path for "zR" and "zPLR" augmentations. Call get_cie_encoding_slow as a fall-back. --- v2: Use memcpy to avoid a potential aliasing violation. libgcc/unwind-dw2-fde.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-) base-commit: e724b0480bfa5ec04f39be8c7290330b495c59de diff --git a/libgcc/unwind-dw2-fde.c b/libgcc/unwind-dw2-fde.c index 3c0cc654ec0..21eee77882e 100644 --- a/libgcc/unwind-dw2-fde.c +++ b/libgcc/unwind-dw2-fde.c @@ -333,8 +333,10 @@ base_from_object (unsigned char encoding, const struct object *ob) /* Return the FDE pointer encoding from the CIE. */ /* ??? This is a subset of extract_cie_info from unwind-dw2.c. */ -static int -get_cie_encoding (const struct dwarf_cie *cie) +/* Disable inlining because the function is only used as a slow path in + get_cie_encoding below. */ +static int __attribute__ ((noinline)) +get_cie_encoding_slow (const struct dwarf_cie *cie) { const unsigned char *aug, *p; _Unwind_Ptr dummy; @@ -389,6 +391,62 @@ get_cie_encoding (const struct dwarf_cie *cie) } } +static inline int +get_cie_encoding (const struct dwarf_cie *cie) +{ + /* Fast path for some augmentations and single-byte variable-length + integers. Do this only for targets that align struct dwarf_cie to 8 + bytes, which ensures that at least 8 bytes are available starting at + cie->version. */ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ \ + || __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ + if (__alignof (*cie) == 8 && sizeof (unsigned long long) == 8) + { + unsigned long long value; + memcpy (&value, &cie->version, sizeof (value)); + +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ +#define C(x) __builtin_bswap64 (x) +#else +#define C(x) x +#endif + + /* Fast path for "zR". Check for version 1, the "zR" string and that + the sleb128/uleb128 values are single bytes. In the comments + below, '1', 'c', 'd', 'r', 'l' are version, code alignment, data + alignment, return address column, augmentation length. Note that + with CIE version 1, the return address column is byte-encoded. */ + unsigned long long expected = + /* 1 z R 0 c d r l. */ + C (0x017a520000000000ULL); + unsigned long long mask = + /* 1 z R 0 c d r l. */ + C (0xffffffff80800080ULL); + + if ((value & mask) == expected) + return cie->augmentation[7]; + + /* Fast path for "zPLR". */ + expected = + /* 1 z P L R 0 c d. */ + C (0x017a504c52000000ULL); + mask = + /* 1 z P L R 0 c d. */ + C (0xffffffffffff8080ULL); +#undef C + + /* Validate the augmentation length, and return the enconding after + it. No check for the return address column because it is + byte-encoded with CIE version 1. */ + if (__builtin_expect ((value & mask) == expected + && (cie->augmentation[8] & 0x80) == 0, 1)) + return cie->augmentation[9]; + } +#endif + + return get_cie_encoding_slow (cie); +} + static inline int get_fde_encoding (const struct dwarf_fde *f) {