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: 15444 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp278645wru; Fri, 4 Nov 2022 02:38:44 -0700 (PDT) X-Google-Smtp-Source: AMsMyM45JVe96SEEdpf0TfLx4ejGthM5aXDbVaHmnOlKFZmqKxxG9ctXjYczKBbdeDHugqyGyO68 X-Received: by 2002:a05:6402:b56:b0:461:91aa:11b7 with SMTP id bx22-20020a0564020b5600b0046191aa11b7mr35617149edb.220.1667554724345; Fri, 04 Nov 2022 02:38:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667554724; cv=none; d=google.com; s=arc-20160816; b=cYiNQWEOHharVhPuvz/oZbxHYvJZgBvbs7HTFnVSYNtwJzkux4XkUzx0BqmGIjZma/ TOR0jKaRL1SsR9fI6wnL1+FXMGYtCSAK9+0UaUY4SUGEv4dzHpx9IJV4ttj3HdtqnBJ8 Wg5SS4T9P8WWVsNyBb82m+u2Sl+r5xOhgf21nqCCN6+SOjAp6vIae70DH2WZXai5TLri +VbiTiCMqaNicg13Wwx/yaL/0WFeYUa9mKjW3hrAWn17S2u4ERccQV5PUlpMVVfejJT1 gbGIZd5QVTasIxlHXzbLq9AYX59s1bJYprBk8Lmwmu8+2wUMKOTiPzDaNzltKvJn4WYT 6npA== 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=4F6JquYWwGBGYv5c+ehsOFprIaT//Dh76iRuDufiLDk=; b=cl8gn3gzmRxIiQu3JVlcryFlY/XJflHPc1S+XyWZCEK9U71fsz3+qv0y2C2ofEEpl0 gXqMa2hlTKWHH0OSMAkXPdUVfYWk/YeKLFQ+o94yxPsxRJpaHaiD/4sxQI0oEGt7MEAL afj49p1pomlyoEmUnux/7gFuhp0qYspROrJay4DFF0tI/yy5a5JlDJLmdOC9uI3NwnbY qfWrzTcu9F8qIoGmKT/VXKFdDowFrTZX0XG0WsaEwYO17by8Zy/3hRSx8urPN+S1ZwDj 6dAQajQ/EnQ9BeHqqcN4dnWqoeikRWJ0xcezu2iT/JaHtVc3ls2Og68OgbeSfbQAIPj6 Ek7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fB4VNWPI; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id jg7-20020a170907970700b007940226fd21si5027076ejc.903.2022.11.04.02.38.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Nov 2022 02:38:44 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=fB4VNWPI; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 5961C3858293 for ; Fri, 4 Nov 2022 09:38:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5961C3858293 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667554723; 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=fB4VNWPIo1KRZCcpwTZNegsjT/0X2R9Q9lP/dFNV6o5KP3DrnuxwR2kExUObQMZ8+ y2WEBiw6+7vWQQIBwyvTc+sAPVPtscKVS/diU2zRzCPCIN1CbJlBXh+2BRIhO4WQ2Q hM770RxDekNInPKitknaaT3QcQ8t4lwSWyNRekgc= 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748557862348929644?= X-GMAIL-MSGID: =?utf-8?q?1748557862348929644?= "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) {