From patchwork Mon Oct 17 13:00:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 3434 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1433007wrs; Mon, 17 Oct 2022 06:01:51 -0700 (PDT) X-Google-Smtp-Source: AMsMyM76a3o6gbBjpjoEJnyinHBQnqPhAPkBbmKmEepDBMU7fCwlUqMpxRIUs2rjM0qSIsA2CrS9 X-Received: by 2002:a05:6402:4446:b0:457:eebd:fe52 with SMTP id o6-20020a056402444600b00457eebdfe52mr10147344edb.234.1666011710925; Mon, 17 Oct 2022 06:01:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666011710; cv=none; d=google.com; s=arc-20160816; b=QKdTwaYGg1eGJQzK4wC3J11fQEvaXs0rAKTuh2P9blG6/lPXDCZZfjPt8WsvVu5gm9 Ofmk4ak6xyGJyyYsR4zmu25wyOlCnvR83cZQGn+G/W/OI+48ExJJy0v4eOQsTDwgfbHR JdMP9d3nqKjwSTa9fwK/phTMcZh9C/oFmsRh7/0p4SpNoB8XQmwCK9/oY5JtjvaCwc3T fnK5dBbOZDmbZT1LgLAS7M0en2sdjL3zW9dr2cUCHzRUMFvdwOuY38+oz3sQgGfkMg7Y oJ0gKUIe27mxXg1KO0F5Eri6rkpRx67L7aGYMOo8rKDjIHCIPkYsv7eIUmvuoAA1zq1/ rEpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:message-id:date:subject:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=0pF0Zn+7Oegb0R6wtL/4/apOr3Zib8Mswvm/hFXlA1k=; b=OL7GOBK2cF4aaGmwMQa671qZaJVFcQQJ/riQ6ywcByrim85ltEfUISks8mUOK/sKQO 3GK3yMgPRjEWXlkyuz56aYuKXOIaF27/KNH9uVfPo4NWwEvzs8tex1uIxsVZqqEDQI7w Gyb18PeNlO6YZ4FkFRaEXosI2a7bzzFlOqGHa3hJ/Ll6QGHn5jyeztynsKOCiL2mNzPC ayGjp5aSdFh/1YecpTeQmnlgKCj54qJ4CxeTHbP03Q831PovSLFPdnoMrk9tDcmBrWMv x0wTZklV0gEU8pSDHjDG6cJ5+VHbNRP6QnQPvN3YQVEm8z9aYf1JAPyzd6iU+DuyrM4n dNMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vMshNMGv; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id b25-20020aa7dc19000000b0045ccd2c9944si7521142edu.233.2022.10.17.06.01.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Oct 2022 06:01:50 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vMshNMGv; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A386838582A7 for ; Mon, 17 Oct 2022 13:01:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A386838582A7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666011709; bh=0pF0Zn+7Oegb0R6wtL/4/apOr3Zib8Mswvm/hFXlA1k=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=vMshNMGvH3MOYMPVyKzL4JWlGtW/ymLOwOiNhZ6kbE2pOrsQj2CXE2R5wHw/ZgB30 7laRMMfX+SmbIt3NKCvyLYqCnVEqCevdEosgSMPn/2U+8HzIDefVBPCPrQhmIcbsyL +j1au6A/y+fv2hsh7+si1I5iOCcKyVkYboxn54cg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 83D08385841D for ; Mon, 17 Oct 2022 13:00:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 83D08385841D Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-620-cCgJS7GbNg2m-jUAogaKMg-1; Mon, 17 Oct 2022 09:00:40 -0400 X-MC-Unique: cCgJS7GbNg2m-jUAogaKMg-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7D21F3814943 for ; Mon, 17 Oct 2022 13:00:40 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.193.168]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 16F0C2166B29 for ; Mon, 17 Oct 2022 13:00:39 +0000 (UTC) To: gcc-patches@gcc.gnu.org Subject: [PATCH] libgcc: Mostly vectorize CIE encoding extraction for FDEs Date: Mon, 17 Oct 2022 15:00:38 +0200 Message-ID: <87edv6mwp5.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.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.3 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746939895499201031?= X-GMAIL-MSGID: =?utf-8?q?1746939895499201031?= "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. --- libgcc/unwind-dw2-fde.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) base-commit: de84a1e4b107b803ec3b064c3771a6ed8c0e201e diff --git a/libgcc/unwind-dw2-fde.c b/libgcc/unwind-dw2-fde.c index 3c0cc654ec0..4e3a54c5a1a 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,61 @@ 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 = *(const unsigned long long *) &cie->version; + +#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) {