From patchwork Wed May 3 06:02:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 89571 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1102673vqo; Tue, 2 May 2023 23:02:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5MqrukPkfY9m1AXVWCSYcI0IP8KHe7YyOr7XmmxvoqyuCBYABAoSikHu9hg7gHRrug0S4/ X-Received: by 2002:a17:907:2da3:b0:95e:d468:c35f with SMTP id gt35-20020a1709072da300b0095ed468c35fmr2247688ejc.57.1683093765377; Tue, 02 May 2023 23:02:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683093765; cv=none; d=google.com; s=arc-20160816; b=zRa6M9hiA4BCjprns/KwVWnh6LDeOQPEjf3aQ5UYzBulc9Gv352iaoog207V3RiB9S UNeusXEpignZCmjQFAz7dVJR0qbpRf/Hltk1AXNjf0YXOokotJ74K+GZkOvg+unRueHu ZRyn1OYpTbEDE7hnXRxbjzZBRGueuXUH/0dHOfbE4B3DwtVsixb+sd48pjqDVy2p/Pp7 AShslKDzdlMDbpNxJquQb85MJTw4CVbt4vsHB+RecBfOh2uyhtOD68YduWn2XFYoFpgy M1Y/xyQv7iwt4biVp7XVifp+LLwEA8C/aPxXAFzmDl1Obe5nWm38WkUI+086ouYKvGQz fDwA== 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-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=wiFE9s361u3ymD7IkoEZgvvjMlyf2x3i0D4osXVMHlg=; b=PuAM0TdB9kX7oSy757U/Xvrucj3P52tGbW6hd3EC0AqwnfFKl3p9DeRNxqQTH0Np2b ITGoSlNPoogW5A8C/P/fKtJA+IKXqKdV9yeDYRO547uji5xNC5NEqc/GJPq3uoH5WjIc CgosJPYyjqFoIEJLjpEwXW4EU6EmX+5lbaRS4Kr5C1cwixuTKNoMt8L3YLQjZt1HWlby b2wihBfYWxchwT8LEERIMbm7pS5et7Z4U0LDMz+25ES6HMz0w+rx1Dsj+oQMFhkztqD0 k2+/iMuLa2327y6251chzFb3vbgSZzF6GqNZHGJGLA1orQLeSn8QAldr3HINdmg4dIWU eS4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=SOsvyLgX; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ww3-20020a170907084300b009572cf7a877si23293148ejb.986.2023.05.02.23.02.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 23:02:45 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=SOsvyLgX; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 46C7D385771A for ; Wed, 3 May 2023 06:02:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 46C7D385771A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1683093742; bh=wiFE9s361u3ymD7IkoEZgvvjMlyf2x3i0D4osXVMHlg=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=SOsvyLgXnfFeBvhLKkvl0F+Aic1qrSL+vSeZjqjXiiT0NNrWL590mstb8DP1fGf7q ppHu8aaIxocZ2HNY3/i2bj9/2G04+C14tl3Vfzx/0F85RDuPGQKHD7kK7Q+f0xcsNS E4r2bddJC+oIL80UrMiyIZXi+ZY043Als5NoeG9A= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 4E0B33856DF4 for ; Wed, 3 May 2023 06:02:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4E0B33856DF4 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1ab01bf474aso21282675ad.1 for ; Tue, 02 May 2023 23:02:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683093732; x=1685685732; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=wiFE9s361u3ymD7IkoEZgvvjMlyf2x3i0D4osXVMHlg=; b=V4WZx/b+bReSqTlGD/z84TGk7FAVhZAJZz3tNe1DdmzSmO/19p7NU3vlxf3NT8+VMs xehgLXg7zeDrk+MQlwxm4dO74i6dC42C1A9MfbzvArdK0oEtr77UYO5W8GvDEkXVpnWZ BeGiQXKklrUybXEgWsXkohut3SheuXJXOmtcP0Ud3Y1IW5C2Xj214We7X2OB+Wvk7Rvg kKNkvQlCpWUAXtcngBcQZb6C/jLwJAtTXeTQ7icgQOhJFcYTvt4HEl9Hc1B8efMFSiry TY7kzyvwbPhrAVd7LM/H8cphRIKKXA4BAbrPkQ0cjQRKFnbg/j1OSKMNdsGqQGIhpoBT iCvA== X-Gm-Message-State: AC+VfDwEP7EqLNYxCqCtQvw7TK0CJYQKg0gBdtvjpvpTEtmJVrFyZILg +vhelfdZQ8H+rbAUyyWHmbSSkWemJYQ= X-Received: by 2002:a17:903:1d0:b0:1a9:6bd4:236a with SMTP id e16-20020a17090301d000b001a96bd4236amr888578plh.69.1683093731879; Tue, 02 May 2023 23:02:11 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:e289:4864:2d83:727f]) by smtp.gmail.com with ESMTPSA id bd2-20020a170902830200b001a68d45e52dsm20763000plb.249.2023.05.02.23.02.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 May 2023 23:02:11 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 424C41142C83; Wed, 3 May 2023 15:32:09 +0930 (ACST) Date: Wed, 3 May 2023 15:32:09 +0930 To: binutils@sourceware.org Subject: hash.c: replace some unsigned long with unsigned int Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3034.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764851728046496524?= X-GMAIL-MSGID: =?utf-8?q?1764851728046496524?= * hash.c (higher_prime_number): Use uint32_t param, return value, tables and variables. (bfd_default_hash_table_size): Make it an unsigned int. (bfd_hash_set_default_size): Use unsigned int param and return. * bfd-in.h (bfd_hash_set_default_size): Update prototype. * bfd-in2.h: Regenerate. diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index de7285626cd..0a4da9aa407 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -333,7 +333,7 @@ extern void bfd_hash_traverse /* Allows the default size of a hash table to be configured. New hash tables allocated using bfd_hash_table_init will be created with this size. */ -extern unsigned long bfd_hash_set_default_size (unsigned long); +extern unsigned int bfd_hash_set_default_size (unsigned int); /* This structure is used to keep track of stabs in sections information while linking. */ diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index c7bcd5f51fb..f5e1c1380c0 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -340,7 +340,7 @@ extern void bfd_hash_traverse /* Allows the default size of a hash table to be configured. New hash tables allocated using bfd_hash_table_init will be created with this size. */ -extern unsigned long bfd_hash_set_default_size (unsigned long); +extern unsigned int bfd_hash_set_default_size (unsigned int); /* This structure is used to keep track of stabs in sections information while linking. */ diff --git a/bfd/hash.c b/bfd/hash.c index 6e60bedc05b..add7d10ecb3 100644 --- a/bfd/hash.c +++ b/bfd/hash.c @@ -304,50 +304,49 @@ SUBSUBSECTION greater than N, and near a power of two. Copied from libiberty. Returns zero for ridiculously large N to signify an error. */ -static unsigned long -higher_prime_number (unsigned long n) +static uint32_t +higher_prime_number (uint32_t n) { /* These are primes that are near, but slightly smaller than, a power of two. */ - static const unsigned long primes[] = + static const uint32_t primes[] = { - (unsigned long) 31, - (unsigned long) 61, - (unsigned long) 127, - (unsigned long) 251, - (unsigned long) 509, - (unsigned long) 1021, - (unsigned long) 2039, - (unsigned long) 4093, - (unsigned long) 8191, - (unsigned long) 16381, - (unsigned long) 32749, - (unsigned long) 65521, - (unsigned long) 131071, - (unsigned long) 262139, - (unsigned long) 524287, - (unsigned long) 1048573, - (unsigned long) 2097143, - (unsigned long) 4194301, - (unsigned long) 8388593, - (unsigned long) 16777213, - (unsigned long) 33554393, - (unsigned long) 67108859, - (unsigned long) 134217689, - (unsigned long) 268435399, - (unsigned long) 536870909, - (unsigned long) 1073741789, - (unsigned long) 2147483647, - /* 4294967291L */ - ((unsigned long) 2147483647) + ((unsigned long) 2147483644), + UINT32_C (31), + UINT32_C (61), + UINT32_C (127), + UINT32_C (251), + UINT32_C (509), + UINT32_C (1021), + UINT32_C (2039), + UINT32_C (4093), + UINT32_C (8191), + UINT32_C (16381), + UINT32_C (32749), + UINT32_C (65521), + UINT32_C (131071), + UINT32_C (262139), + UINT32_C (524287), + UINT32_C (1048573), + UINT32_C (2097143), + UINT32_C (4194301), + UINT32_C (8388593), + UINT32_C (16777213), + UINT32_C (33554393), + UINT32_C (67108859), + UINT32_C (134217689), + UINT32_C (268435399), + UINT32_C (536870909), + UINT32_C (1073741789), + UINT32_C (2147483647), + UINT32_C (4294967291) }; - const unsigned long *low = &primes[0]; - const unsigned long *high = &primes[sizeof (primes) / sizeof (primes[0])]; + const uint32_t *low = &primes[0]; + const uint32_t *high = &primes[sizeof (primes) / sizeof (primes[0])]; while (low != high) { - const unsigned long *mid = low + (high - low) / 2; + const uint32_t *mid = low + (high - low) / 2; if (n >= *mid) low = mid + 1; else @@ -360,7 +359,7 @@ higher_prime_number (unsigned long n) return *low; } -static unsigned long bfd_default_hash_table_size = DEFAULT_SIZE; +static unsigned int bfd_default_hash_table_size = DEFAULT_SIZE; /* Create a new hash table, given a number of entries. */ @@ -660,15 +659,15 @@ bfd_hash_traverse (struct bfd_hash_table *table, out: table->frozen = 0; } - -unsigned long -bfd_hash_set_default_size (unsigned long hash_size) + +unsigned int +bfd_hash_set_default_size (unsigned int hash_size) { /* These silly_size values result in around 1G and 32M of memory being allocated for the table of pointers. Note that the number of elements allocated will be almost twice the size of any power of two chosen here. */ - unsigned long silly_size = sizeof (size_t) > 4 ? 0x4000000 : 0x400000; + unsigned int silly_size = sizeof (size_t) > 4 ? 0x4000000 : 0x400000; if (hash_size > silly_size) hash_size = silly_size; else if (hash_size != 0)