From patchwork Mon Feb 12 21:49:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1897980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Z0IUZybw; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TYdRJ7371z23hw for ; Tue, 13 Feb 2024 08:50:04 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D230B3858407 for ; Mon, 12 Feb 2024 21:50:02 +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 ; 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 ; 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-Google-Smtp-Source: AGHT+IEYtwPL1IttbTKgYVSuArRF6eeWDfINh2lK22ZBCbtdknTF3xhPd0UM6jrO7iyaJCoMs7CzQQ== 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 To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, Patrick Palka 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org 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 . (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 // 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. */