From patchwork Thu Oct 5 16:39:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 821941 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-463553-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GR2CPz1t"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3y7JQn4MjNz9t16 for ; Fri, 6 Oct 2017 03:39:59 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=bL3wx/kBhMz3gK/qCpIeRUQR2Np2rWqZjVm+nYGtLDdoSp za+uKQwaCbNe/MCK0WMDueBXxTzR5uJrmW+txX/abyA9lVyignkA8SLFrpDJ5IRM slCgH99JVx63xwruZf48btVZG0KcnMNccqyxujyBZBi2qR4edJJ39Ktvy2j78= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=njwkz9DosC7ja40BDzr112N+lwg=; b=GR2CPz1tZWZpVqdrkrLX Li+1xMj6NLp5tQwd8aGkfIRgCX2w0hhVHXTWCXMpb1oMztPAWyeaQoUL9fI2X7nL IaYtbpNSKqrd4bMGAMZs7J5swDwsK7YDrLNvxo63Zkg5QLyqIo157wIHn70Js5H/ EffuZZRn7XHTFLogXrSnCh4= Received: (qmail 21728 invoked by alias); 5 Oct 2017 16:39:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 21717 invoked by uid 89); 5 Oct 2017 16:39:49 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=percentage, PIN, temporal, 4329 X-HELO: mail-wm0-f44.google.com Received: from mail-wm0-f44.google.com (HELO mail-wm0-f44.google.com) (74.125.82.44) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 05 Oct 2017 16:39:48 +0000 Received: by mail-wm0-f44.google.com with SMTP id q132so3350031wmd.2 for ; Thu, 05 Oct 2017 09:39:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=nr6ZmWqcNbBoNeRIf/bC0Cc/WTB3FyRlLyX5EwXBijA=; b=kCmOQVWsSYJEgxvqRHQOtJi9+QvuSfy43vUiSNaG5Tw2zIc4ItaaGukOqWheM1DHNw audnWk+VQmBeQW/av2/DrwzBAeh7dUWO3otWubVZjlIyTHpTlUI7WSRXRAdSNQPVKzkC jfpjy2Ia0E9eLaeFPnExIC/5rMLeAB83nGAqMpAd+QVFX9VaVBKduduDWudwid4NQuHT Jk+BFEMsJiW4lv9pE2wNKp0LuqVXrl1mENHLbduFxnNs7HiTqVaaSeoWRAZV51REKon9 ReFFnXQ9yTDd02T6EsfF6D8uz7GDLni++g3Bk0fCHcAJHS2DGqbArL8pNTqbjMirHVbv SYxw== X-Gm-Message-State: AMCzsaW1XeiH26m5AeeaBsnoKxK/pMGGInPFkTTThm1/KZ8c2Ar/87Yh 8XuYNAJ1K8R5+7+1oqD6rQ9pvyp+YCKVCFLG2kFvj7XY X-Google-Smtp-Source: AOwi7QBneeyRasq4sYO8baQjN9VAFsGsBeElZZoDBImwswS0nf9d5j972YVQEFW+Aja81kyyNNGwKKIQ57AF2SRucvw= X-Received: by 10.80.135.11 with SMTP id i11mr8478655edb.31.1507221585609; Thu, 05 Oct 2017 09:39:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.80.179.240 with HTTP; Thu, 5 Oct 2017 09:39:44 -0700 (PDT) From: Ian Lance Taylor Date: Thu, 5 Oct 2017 09:39:44 -0700 Message-ID: Subject: libbacktrace patch committed: Minor decompression improvement To: gcc-patches I've committed a patch to libbacktrace to speed up decompression a few percent by loading 32-bit values rather than 8-bit bytes. Bootstrapped and ran libbacktrace and Go tests on x86_64-pc-linux-gnu. Committed to mainline. Ian 2017-10-05 Ian Lance Taylor * elf.c (elf_zlib_fetch): Change pval argument to uint64_t *. Read a four byte integer. (elf_zlib_inflate): Change val to uint64_t. Align pin to a 32-bit boundary before ever calling elf_zlib_fetch. * ztest.c (test_large): Simplify print statements a bit. Index: elf.c =================================================================== --- elf.c (revision 253376) +++ elf.c (working copy) @@ -1031,11 +1031,12 @@ elf_zlib_failed(void) static int elf_zlib_fetch (const unsigned char **ppin, const unsigned char *pinend, - uint32_t *pval, unsigned int *pbits) + uint64_t *pval, unsigned int *pbits) { unsigned int bits; const unsigned char *pin; - uint32_t val; + uint64_t val; + uint32_t next; bits = *pbits; if (bits >= 15) @@ -1043,20 +1044,25 @@ elf_zlib_fetch (const unsigned char **pp pin = *ppin; val = *pval; - if (unlikely (pinend - pin < 2)) + if (unlikely (pinend - pin < 4)) { elf_zlib_failed (); return 0; } - val |= pin[0] << bits; - val |= pin[1] << (bits + 8); - bits += 16; - pin += 2; - - /* We will need the next two bytes soon. We ask for high temporal - locality because we will need the whole cache line soon. */ - __builtin_prefetch (pin, 0, 3); - __builtin_prefetch (pin + 1, 0, 3); + + /* We've ensured that PIN is aligned. */ + next = *(const uint32_t *)pin; + +#if __BYTE_ORDER == __ORDER_BIG_ENDIAN + next = __builtin_bswap32 (next); +#endif + + val |= (uint64_t)next << bits; + bits += 32; + pin += 4; + + /* We will need the next four bytes soon. */ + __builtin_prefetch (pin, 0, 0); *ppin = pin; *pval = val; @@ -1566,7 +1572,7 @@ elf_zlib_inflate (const unsigned char *p poutend = pout + sout; while ((pinend - pin) > 4) { - uint32_t val; + uint64_t val; unsigned int bits; int last; @@ -1601,10 +1607,19 @@ elf_zlib_inflate (const unsigned char *p } pin += 2; - /* Read blocks until one is marked last. */ + /* Align PIN to a 32-bit boundary. */ val = 0; bits = 0; + while ((((uintptr_t) pin) & 3) != 0) + { + val |= (uint64_t)*pin << bits; + bits += 8; + ++pin; + } + + /* Read blocks until one is marked last. */ + last = 0; while (!last) @@ -1671,6 +1686,14 @@ elf_zlib_inflate (const unsigned char *p pout += len; pin += len; + /* Align PIN. */ + while ((((uintptr_t) pin) & 3) != 0) + { + val |= (uint64_t)*pin << bits; + bits += 8; + ++pin; + } + /* Go around to read the next block. */ continue; } Index: ztest.c =================================================================== --- ztest.c (revision 253377) +++ ztest.c (working copy) @@ -432,9 +432,9 @@ test_large (struct backtrace_state *stat ctime = average_time (ctimes, trials); ztime = average_time (ztimes, trials); - printf ("backtrace time: %zu ns\n", ctime); - printf ("zlib time: : %zu ns\n", ztime); - printf ("percentage : %g\n", (double) ztime / (double) ctime); + printf ("backtrace: %zu ns\n", ctime); + printf ("zlib : %zu ns\n", ztime); + printf ("ratio : %g\n", (double) ztime / (double) ctime); return;