From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7871) id 776F538582B1; Mon, 7 Nov 2022 08:40:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 776F538582B1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667810445; bh=3sU266TOZ5AqRms0XGIcLqQPOLWbcxPJUSBuk8SustM=; h=From:To:Subject:Date:From; b=eMFBHcVVMhfbr5Z4Ro7Ot+rT0YsVMoPO9CXeFf+sSle5BOaKyXZBnzNWGoGXLit32 +tPtVgwQ6sgW0khZXt+1uarEe3r7m1oXegYtP0F3Tf5F5dYQcFzyBgd1wtodPa3Kls Sy9yolFJ6SD9t4MOi9Lu7MkgHQITkixgsXpWtL2Q= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Marc Poulhi?s To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3745] ada: Tune hash function for cross-reference entries X-Act-Checkin: gcc X-Git-Author: Piotr Trojanek X-Git-Refname: refs/heads/master X-Git-Oldrev: dc3208e698b2f424d892d3c9e5d5562ccde9e4cf X-Git-Newrev: bcb3f09ec6cb9b2c6e58243d05b5a0fc33e909f1 Message-Id: <20221107084045.776F538582B1@sourceware.org> Date: Mon, 7 Nov 2022 08:40:22 +0000 (GMT) List-Id: https://gcc.gnu.org/g:bcb3f09ec6cb9b2c6e58243d05b5a0fc33e909f1 commit r13-3745-gbcb3f09ec6cb9b2c6e58243d05b5a0fc33e909f1 Author: Piotr Trojanek Date: Tue Oct 18 09:33:38 2022 +0200 ada: Tune hash function for cross-reference entries 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. Diff: --- 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.