From patchwork Mon Nov 7 08:41:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 16327 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp1923875wru; Mon, 7 Nov 2022 00:56:16 -0800 (PST) X-Google-Smtp-Source: AMsMyM5smxTogIBS3Iuy7sgwrIJmx/j795zbgwGbXE3/wpRDyHl1AZRZKlcywCZK7RKXIyfQ0kpI X-Received: by 2002:a17:906:dc93:b0:7ad:ca82:4cb9 with SMTP id cs19-20020a170906dc9300b007adca824cb9mr40140140ejc.521.1667811376667; Mon, 07 Nov 2022 00:56:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667811376; cv=none; d=google.com; s=arc-20160816; b=E6CbkGaEbBmjCzXFnVWYrpF6JlbGWIYaMGWt1qfKk4HUykHiEr21OfZuND2Y8+bONU UtIepwybLKCntq62uy4TCL8AW68CSUuyZr0Perp5TODkyMJCvr/txC4Ef0drajPoijFU QQjKQMrGVPKrEDVbXycE3ebZqP3iczNVw300/jdnzgOVuvfAV6P3cFC+MOPy9dth/2WQ q6C8PWdpICqWY0eFdDttsNZ6asqabwEdHYMzjqWQ1DEfzb8NCFqrttL0rFwynOhcOTgB cxb/Rt/Rqb1BG2CUBjACkGZTql+taQhohN03kMs2scjmczzcdlRS3XEEP+Mbh0rEhPcK WsBQ== 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 :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=uj5BaDz4LAc1UoxmXbBgaRveRcffxi8Nm31rguWpFNc=; b=W51MDyBWdFHmymn8qf82Anmm8cJZTWdayQ+brsJzLCZLsGBbsejx7e9SSKf9yV1D14 ykizKWVik8pNdI5l1uFAYYmpyPbURUT7CVwrqkXd+zcgRTu9/Y/Aw4RcBRrdrOdUgfHH cLAW0CRqokXoLadM12QiIpt15HomQ9Az4JV2hHOAV4WM32yK2Vglh9WyycVn4elKZ2GL osuXZUuf1hNaElck+C+/ZvUpxbgn6iVUfnhcYm1Th8y9Uo1ouGd83cd9ZYtkGnwHdmDD tTATRhpi3Yg8B3ciBSCggDLwil7zKBO83sF+Cq0DBpuA5lrlF+QFIhS3OqpVcYVyHR+m COWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U3uW8HeA; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id s6-20020a170906bc4600b007416e100f3dsi5742100ejv.986.2022.11.07.00.56.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 00:56:16 -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=@gcc.gnu.org header.s=default header.b=U3uW8HeA; 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 EDC63385558E for ; Mon, 7 Nov 2022 08:51:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EDC63385558E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667811074; bh=uj5BaDz4LAc1UoxmXbBgaRveRcffxi8Nm31rguWpFNc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=U3uW8HeABUnioUXrAG2gK6AaHSeP5wacjbDIR0c7CgJfQUy0f4+pErnVSxw5V6O7L HIWWafevF/p7s5nVK9AH3IN4/R7UNIA62sU8I8tCRNhagfPI+YYmTUBWTahmzC2fy7 DJHmf38nXTGLI4feg2RBRzhHkPBLY5yJKOi1fTOM= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by sourceware.org (Postfix) with ESMTPS id BBD6238576BB for ; Mon, 7 Nov 2022 08:41:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org BBD6238576BB Received: by mail-wm1-x32e.google.com with SMTP id t4so6386487wmj.5 for ; Mon, 07 Nov 2022 00:41:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=uj5BaDz4LAc1UoxmXbBgaRveRcffxi8Nm31rguWpFNc=; b=faGjcgxJ0vYATdJ1G8eTFQk5G9GHz7QA28c73rlOy87jWV2OwbpKk5CMC+7k3eoUUJ PuLiGhsdO6HPIHWb9PnN5cZUgUQ8cbs0YlUjSNYDi30cXpazywtrg2GEmQOKhzeYqdXR DUmp01rx/6sERw37LqTtIhYjcFWFXub/AuBwyN2i6K0Bbfph+rWH+X1Wsb+EiBH/oI31 jSWGt9VmRJJIb3r1ZwVKCoaP3xRlygeXUbnHMe/ssSLodQxHwkzCzeRieDRRmQXQmE7E XuuZfqGjQYq48wFhYU/kU+ulRGhTyPfEv9abnjBjB1NqEnuw/YqEJBKZ1PVpagWd+mLd 80aw== X-Gm-Message-State: ACrzQf20vg4qTUgP76wBayx0i5qO73pkgXi/z2Qo/KK5soOlumLO1+ut mqPDtq4VYtOtnT2ypkBTrjHcRibXUs0Vfw== X-Received: by 2002:a05:600c:554b:b0:3cf:84ea:3097 with SMTP id iz11-20020a05600c554b00b003cf84ea3097mr18903174wmb.100.1667810510532; Mon, 07 Nov 2022 00:41:50 -0800 (PST) Received: from poulhies-Precision-5550.lan (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id f10-20020a05600c154a00b003a2f2bb72d5sm14333202wmg.45.2022.11.07.00.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Nov 2022 00:41:50 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [COMMITTED] ada: Tune hash function for cross-reference entries Date: Mon, 7 Nov 2022 09:41:47 +0100 Message-Id: <20221107084147.152022-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: =?utf-8?q?Marc_Poulhi=C3=A8s?= 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?1748826982088572448?= X-GMAIL-MSGID: =?utf-8?q?1748826982088572448?= From: Piotr Trojanek Tune the hash function that combines entity identifiers with source locations of where those entities are referenced. Previously the source location was multiplied by 2 ** 7 (i.e. shifted left by 7 bits), then added to the entity identifier, and finally divided modulo 2 ** 16 (i.e. masked to only use the lowest 16 bits). This hash routine caused collisions that could make some tests up to twice slower. With a large entity number the source location was only contributing few bits to the hash value. This large entity number might correspond to entity like Ada.Characters.Latin_1.NUL that occurs thousands of times in generated code. gcc/ada/ * lib-xref.adb (Hash): Tune hash function. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/lib-xref.adb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gcc/ada/lib-xref.adb b/gcc/ada/lib-xref.adb index 043444c0ea3..5a1538e523c 100644 --- a/gcc/ada/lib-xref.adb +++ b/gcc/ada/lib-xref.adb @@ -1271,10 +1271,10 @@ package body Lib.Xref is XE : Xref_Entry renames Xrefs.Table (F); type M is mod 2**32; - H : constant M := M (XE.Key.Ent) + 2 ** 7 * M (abs XE.Key.Loc); + H : constant M := 3 * M (XE.Key.Ent) + 5 * M (abs XE.Key.Loc); -- It would be more natural to write: -- - -- H : constant M := M'Mod (XE.Key.Ent) + 2**7 * M'Mod (XE.Key.Loc); + -- H : constant M := 3 * M'Mod (XE.Key.Ent) + 5 * M'Mod (XE.Key.Loc); -- -- But we can't use M'Mod, because it prevents bootstrapping with older -- compilers. Loc can be negative, so we do "abs" before converting.