Message ID | 20240212214912.2550529-1-ppalka@redhat.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp185335dyb; Mon, 12 Feb 2024 13:50:22 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVpPqj8IVgpXQFBmZOcVKz8mr1KKq+mOKQVGrsF7Eg8id6OBagT7hNxlVQyfCUbsZrQu/WkyAJSmWcmeadaxkkBrh3I7w== X-Google-Smtp-Source: AGHT+IF4auZEQw7XtVLHJwZY89xopChYa/+o5jEO7FcykUjKTXbGSBzYEszK/Ekp8uya80v1aGKK X-Received: by 2002:a05:620a:17a3:b0:785:d7ed:7eed with SMTP id ay35-20020a05620a17a300b00785d7ed7eedmr4530631qkb.21.1707774622186; Mon, 12 Feb 2024 13:50:22 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707774622; cv=pass; d=google.com; s=arc-20160816; b=RSH+RoS4tGjBDPu9CQlK3ydlN29AP1aGl98mFG8zcT/m9PrJtyaUU68Oy+gPy/6Dd5 1ttAGpEjSS+0eah/N57uq9FxFiS+Npbq41EOYW5zLTs9HYIUyHtNxlDXKUzuZiuGjRid 790V6tTZpgrDnllvXZ9s25lpPq/W7XrGOu/r5q/Iv8VWs/rQ+bUOaJSOS/DsLtuy5Ojq 8V8cL+s+ZBHyeajjDVc5O7QdJ2mAMQZrK54jY0vAaR3a3phEkB3lPWrKEVPEgq9tWCJk 2q8Sb8FpXVFAydVl5if6MpwSLVDYiQ/g9MlvIV0fHefnx6rkbdfnHBy6iUFnbZjOn9YR hCCg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=7r/+3Cmpk95Bgd5s7no63ARO15Q+pZY3iZzzluNoPA8=; fh=BHVParim0LyodH3QTCboJdey52hHfoCPnUvHizSXcZE=; b=TZAD6Tjh6J63EpaObGn12muoi5oJivMkDsR0qNttfo03WLlWv4qNInb/y/4JvBMgY7 7pTFI4wYCMGjOhXMUfs0rJOpxw/ehj+9P9OYuHlsBRAJFQkGM4vRrojVc74wet5H5FGZ +7ne1q7kH1o8SDqWi4CLHflvX398cZEMytouDoZ6Q59mc02rFBtlRNNJ8Ld5khoutz/e mnMIBZmyXQItPzlWki8/OyKlP8YYYwxGUj2DrR61QhIxhtDUUm2EXyJCngkNvxlke+og mR5e9yILDrxsAshiUlDZNG/slpYOCUMMUF5uEsmecxIZqtJ2dP9v6kAdmqFIa2Ct6Imb Vc9A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=Z0IUZybw; arc=pass (i=1); 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=redhat.com X-Forwarded-Encrypted: i=2; AJvYcCWpGrXRajSt8lIdy68EcQdjrEm0OXvpTH4E+L53IprQCeEhtJlbTupH5uuDvkALDHQSr0yWuFIHIQ1g+jsOhsBoGd8Fag== Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v7-20020a05620a090700b007836d3975b3si6547644qkv.273.2024.02.12.13.50.22 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 13:50:22 -0800 (PST) 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=@redhat.com header.s=mimecast20190719 header.b=Z0IUZybw; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D16E03858C52 for <ouuuleilei@gmail.com>; Mon, 12 Feb 2024 21:50:21 +0000 (GMT) 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 018C23858C52 for <gcc-patches@gcc.gnu.org>; Mon, 12 Feb 2024 21:49:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 018C23858C52 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 018C23858C52 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707774582; cv=none; b=n8/J0uV3GEsPoB355KWa2k5HX7DJVdEqfm74nADkOnd2KvA3l/44sURC4cSJv7+rX59aby34vgWafF+Zcz6ZmdiTeG72VBJzw0497pWDKasBX00K1QHSSAM38sPj88ozS1sxzNlUa0WjKFYvKSnng0Htkyy92JxJQsQ0PS2SRbs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707774582; c=relaxed/simple; bh=0LeXPg/32rHNHALrujMVmmAc4+vcUBqPuFOvtYjzgWY=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DFhSXP0ek3mJX8zvZqACUVpp5bAm+oyr8OnwbPBPk0zcYqTbSWsUQQQ/FtZinGy37qqasshGKzXI9a3f9RizQK47cRAkY9Smcv9ObOlCF7TQmgKzwZ8bYJNk+gTGh3XhOnj0hwV4PlwUpTbWoZEwGm4KmQfj+NS9ffC7IHmXw3g= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1707774580; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7r/+3Cmpk95Bgd5s7no63ARO15Q+pZY3iZzzluNoPA8=; b=Z0IUZybwu1fPB0jEvSFWDSq/Ju5o+nK/ja6r+rAmgw4iAImYH8XkeP6VuVjWEPq96FaT5E b4XxFlxDuQcRiwILl3zFnOcxlp77Hi3bmXEjbFBMgJBo8rCyXJpRJCVoHhQLbVlpdNRbjS zYtgxwGcahPTkfaMuDW8pGZdvBsM6w0= Received: from mail-vk1-f199.google.com (mail-vk1-f199.google.com [209.85.221.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-180-Ft6NX8BWN4GE5c78FzdOyw-1; Mon, 12 Feb 2024 16:49:39 -0500 X-MC-Unique: Ft6NX8BWN4GE5c78FzdOyw-1 Received: by mail-vk1-f199.google.com with SMTP id 71dfb90a1353d-4c03c3af896so978926e0c.0 for <gcc-patches@gcc.gnu.org>; Mon, 12 Feb 2024 13:49:39 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707774578; x=1708379378; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7r/+3Cmpk95Bgd5s7no63ARO15Q+pZY3iZzzluNoPA8=; b=LlDdPQ8pa4LnpOrkebvSpJAPTUyJ1HBeM4v4Xxnc/9W4Ek0HhCMDle/z41VgIMOaxr FdqIUq9Y3nJ4NFp9ZPTl2okIrE2oIJleGewLgmmOoTqI7u3cidvxewUvZb8cP0PqwYpM BDta8G1AZKmzzpFwU5mVWG984FS/QRx4gYEir0/Md4RuienlTsAyE4Ge1fc4fVU/2/+U TYOK1GFsIVLl8zSCKsJne2OCbQc7Vu8R1y3TNQfpDC4Z/iYeRgFGJ3ZP6RK0UgNwMH8V U39IYd0wggWoE0+iXm3z3b+9/ZQbILvuLFFNRQchT+9Uk+pFr9sstxUXNAfJtgrHYYYE xafg== X-Gm-Message-State: AOJu0YzqQ4GCDf2ZxwQCkccsQlMLtxSnS/BrpYNcO839DGaf7Iw8c4ab 5PdOhED76K05fXOGmzPq8x+TEP6a1eiNPcIv45FhC3uBW47eU/44+NgTekdzRDqLpnvuxyFawRq 54E3xZFd34ivqHfyFyLkTJOLBG535IwnCtPMdUx6IM8AstUgXP2wSOiUwsODV2oxJZ8WdwoN4/j ypruhHY9B7LTRvzDf2udOtm+G5adt7B/R3bSzp X-Received: by 2002:a1f:ea04:0:b0:4c0:26cb:2e72 with SMTP id i4-20020a1fea04000000b004c026cb2e72mr4249096vkh.3.1707774577786; Mon, 12 Feb 2024 13:49:37 -0800 (PST) X-Received: by 2002:a1f:ea04:0:b0:4c0:26cb:2e72 with SMTP id i4-20020a1fea04000000b004c026cb2e72mr4249082vkh.3.1707774577450; Mon, 12 Feb 2024 13:49:37 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVXH9zOoXCwATixe700d+T2GIjeJxcaypsJ2k81s5VeCXg28NvfY+Ayb4vQDC3dld+Ak56cV8QZKaI7dhIbPzMf9V3wKMvaUscLr/I0h6WTKLs= Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id of5-20020a056214434500b0067cd5c86936sm586480qvb.79.2024.02.12.13.49.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 13:49:37 -0800 (PST) From: Patrick Palka <ppalka@redhat.com> To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, Patrick Palka <ppalka@redhat.com> Subject: [PATCH] c++/modules: use optimized crc32 from zlib Date: Mon, 12 Feb 2024 16:49:12 -0500 Message-ID: <20240212214912.2550529-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.561.g235986be82 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.2 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE, URIBL_BLACK 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.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790731482074304747 X-GMAIL-MSGID: 1790731482074304747 |
Series |
c++/modules: use optimized crc32 from zlib
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Patrick Palka
Feb. 12, 2024, 9:49 p.m. UTC
Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- The current implementation of bytes::calc_crc computes the checksum one byte at a time, and turns out to be quite slow, taking 5% and 15% of time compiling and streaming in the std module respectively. We have a crc32_unsigned routine that handles 4 bytes at a time which could speed up this hot function, but we also have a bundled zlib with highly optimized crc routines that can handle up to 32 bytes at a time. So this patch makes us use zlib's crc32 in this hot code path. According to some perf experiments this reduces the overhead of calc_crc from 15% of total time to 3% when streaming in the std module. gcc/cp/ChangeLog: * Make-lang.in (CFLAGS-cp/module.o): Add $(ZLIBINC). * module.cc: Include <zlib.h>. (bytes::calc_crc): Use crc32 from zlib. (bytes_out::set_crc): Use crc32_combine from zlib. --- gcc/cp/Make-lang.in | 2 +- gcc/cp/module.cc | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-)
Comments
On 2/12/24 16:49, Patrick Palka wrote: > Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK > for trunk? OK. > -- >8 -- > > The current implementation of bytes::calc_crc computes the checksum one > byte at a time, and turns out to be quite slow, taking 5% and 15% of > time compiling and streaming in the std module respectively. We have > a crc32_unsigned routine that handles 4 bytes at a time which could > speed up this hot function, but we also have a bundled zlib with highly > optimized crc routines that can handle up to 32 bytes at a time. > > So this patch makes us use zlib's crc32 in this hot code path. > According to some perf experiments this reduces the overhead of calc_crc > from 15% of total time to 3% when streaming in the std module. > > gcc/cp/ChangeLog: > > * Make-lang.in (CFLAGS-cp/module.o): Add $(ZLIBINC). > * module.cc: Include <zlib.h>. > (bytes::calc_crc): Use crc32 from zlib. > (bytes_out::set_crc): Use crc32_combine from zlib. > --- > gcc/cp/Make-lang.in | 2 +- > gcc/cp/module.cc | 8 +++----- > 2 files changed, 4 insertions(+), 6 deletions(-) > > diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in > index 630db41d87e..f153891a1ef 100644 > --- a/gcc/cp/Make-lang.in > +++ b/gcc/cp/Make-lang.in > @@ -55,7 +55,7 @@ c++.serial = cc1plus$(exeext) > CFLAGS-cp/g++spec.o += $(DRIVER_DEFINES) > > CFLAGS-cp/module.o += -DHOST_MACHINE=\"$(host)\" \ > - -DTARGET_MACHINE=\"$(target)\" > + -DTARGET_MACHINE=\"$(target)\" $(ZLIBINC) > > # In non-release builds, use a date-related module version. > ifneq ($(DEVPHASE_c),) > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > index 86e43aee542..c94f4a257de 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -233,6 +233,7 @@ Classes used: > /* This TU doesn't need or want to see the networking. */ > #define CODY_NETWORKING 0 > #include "mapper-client.h" > +#include <zlib.h> // for crc32, crc32_combine > > #if 0 // 1 for testing no mmap > #define MAPPED_READING 0 > @@ -487,10 +488,7 @@ protected: > unsigned > bytes::calc_crc (unsigned l) const > { > - unsigned crc = 0; > - for (size_t ix = 4; ix < l; ix++) > - crc = crc32_byte (crc, buffer[ix]); > - return crc; > + return crc32 (0, (unsigned char *)buffer + 4, l - 4); > } > > class elf_in; > @@ -717,7 +715,7 @@ bytes_out::set_crc (unsigned *crc_ptr) > unsigned crc = calc_crc (pos); > unsigned accum = *crc_ptr; > /* Only mix the existing *CRC_PTR if it is non-zero. */ > - accum = accum ? crc32_unsigned (accum, crc) : crc; > + accum = accum ? crc32_combine (accum, crc, pos - 4) : crc; > *crc_ptr = accum; > > /* Buffer will be sufficiently aligned. */
diff --git a/gcc/cp/Make-lang.in b/gcc/cp/Make-lang.in index 630db41d87e..f153891a1ef 100644 --- a/gcc/cp/Make-lang.in +++ b/gcc/cp/Make-lang.in @@ -55,7 +55,7 @@ c++.serial = cc1plus$(exeext) CFLAGS-cp/g++spec.o += $(DRIVER_DEFINES) CFLAGS-cp/module.o += -DHOST_MACHINE=\"$(host)\" \ - -DTARGET_MACHINE=\"$(target)\" + -DTARGET_MACHINE=\"$(target)\" $(ZLIBINC) # In non-release builds, use a date-related module version. ifneq ($(DEVPHASE_c),) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 86e43aee542..c94f4a257de 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -233,6 +233,7 @@ Classes used: /* This TU doesn't need or want to see the networking. */ #define CODY_NETWORKING 0 #include "mapper-client.h" +#include <zlib.h> // for crc32, crc32_combine #if 0 // 1 for testing no mmap #define MAPPED_READING 0 @@ -487,10 +488,7 @@ protected: unsigned bytes::calc_crc (unsigned l) const { - unsigned crc = 0; - for (size_t ix = 4; ix < l; ix++) - crc = crc32_byte (crc, buffer[ix]); - return crc; + return crc32 (0, (unsigned char *)buffer + 4, l - 4); } class elf_in; @@ -717,7 +715,7 @@ bytes_out::set_crc (unsigned *crc_ptr) unsigned crc = calc_crc (pos); unsigned accum = *crc_ptr; /* Only mix the existing *CRC_PTR if it is non-zero. */ - accum = accum ? crc32_unsigned (accum, crc) : crc; + accum = accum ? crc32_combine (accum, crc, pos - 4) : crc; *crc_ptr = accum; /* Buffer will be sufficiently aligned. */