From nobody Tue Jun 04 18:02:23 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Vtz2R6t7bz5MKrl; Tue, 04 Jun 2024 18:02:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Vtz2R6Hdjz4NXf; Tue, 4 Jun 2024 18:02:23 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717524143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=02IGJ3Oa/EFnZi8v2kDdqbc6ioKA271Y/g+a6WUuivk=; b=tM0InckHh6r6Uc4h8wkVK9lt7mfw+XCCO8znpjGB5elFL0qr/4Mj4LE/6of7+T7N8YYAPT K7PUFkfj28cV2fVhm3cPbXUN0QnNM92E+M2eO6t5fZjQZarAB7DsrRKw0Vb3+rJANpUdIh Br8U4jv7KcEOFJxz0fm5GKqnxz4D+ORbh5pG3tPiNv/Nv/xhTHiXIT0Xd4PmhRw2aGzyz7 xe+gXm6Z/audscwfy7Y7ek5vPoXU0M6tbNmFAIhN6+iHYaG/o0Wtd69ElZ7KHTdt13P5UR mpbxemXDuQ58trTEP9jdUu2E4i9jaWiDCaEUIevtmYy5VXM6P6nGN1sJoQnOBg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1717524143; a=rsa-sha256; cv=none; b=R5AoYnEUFHl2c5VrQ3gbWPuLBwxZv/jtxNktp/lI9pkAcXtM41sabpnd8NCVncFL0x3E3k 2i9EQsBEas2yYaSM32vZrAHEMda02Wzivgb+T80JOGnUsE6HwR16sJ2FLNBKqvIB89HSLu vN7nKK8m65GrwAdeUoIVSAwPMgZj/0yQIgNwMwt7XV+sRPCuhA8n6SZidrErB4hJHdOBtT iX7K9l9y1sk5H8VDGPxus8J+dUMp4xIqkNea6ZxSIYG4Uxlp1oy4Mfgi7cesfhmiF8eLeY EZswlHMIxLCxuHlrhIHl8JLvD7YIUy6cP0GXIAFMeKzDIhOX5pTNAAfWYdCwfg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1717524143; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=02IGJ3Oa/EFnZi8v2kDdqbc6ioKA271Y/g+a6WUuivk=; b=Hz7hU+tObGzWxQq8U0uu9gtUiXEXFmb1yOr9e0F2bVfD79/5HC36wkS6udf0TolMaQumrF gsqbdedEomcZH8fPhOLxpIeWTEviMR5UU1TBgrulZMc/ag4mK5BBcRCN8KNYREi4kgUG++ NT5qR3TERygiatHcK3UobqIKIeVgi7BLCV0RIkIddYVcwkyD2+ejUF/svlWoPP35mQwiBy svqZ7ihJmAegd4Jcybm2SelmtMfnO4+zu7FJxAfIzhB/2ckP4wvu7OiNegY6pGJr1Z3+aL Z70WDnMNcqEgL8VM0sOozgzNTF47Qi5V0U+Ly12xypQhCqWO6tK+Rv/EZgCEtw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Vtz2R5vYBzTBL; Tue, 4 Jun 2024 18:02:23 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 454I2NaL071877; Tue, 4 Jun 2024 18:02:23 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 454I2N1c071874; Tue, 4 Jun 2024 18:02:23 GMT (envelope-from git) Date: Tue, 4 Jun 2024 18:02:23 GMT Message-Id: <202406041802.454I2N1c071874@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: 9ff1462976fc - main - x86: simplify ceil(log2(x)) function List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 9ff1462976fce4f4389be9a3357eadd22d04d308 Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=9ff1462976fce4f4389be9a3357eadd22d04d308 commit 9ff1462976fce4f4389be9a3357eadd22d04d308 Author: Doug Moore AuthorDate: 2024-06-04 18:00:25 +0000 Commit: Doug Moore CommitDate: 2024-06-04 18:00:25 +0000 x86: simplify ceil(log2(x)) function A function called mask_width in one place and log2 in the other calculates its value in a more complex way than necessary. A simpler implementation offered here saves a few bytes in the functions that call it. Reviewed by: alc, avg Differential Revision: https://reviews.freebsd.org/D45483 --- sys/amd64/vmm/x86.c | 5 ++--- sys/x86/x86/mp_x86.c | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/sys/amd64/vmm/x86.c b/sys/amd64/vmm/x86.c index 3cf689217590..aa8f87c98fe8 100644 --- a/sys/amd64/vmm/x86.c +++ b/sys/amd64/vmm/x86.c @@ -61,14 +61,13 @@ SYSCTL_INT(_hw_vmm_topology, OID_AUTO, cpuid_leaf_b, CTLFLAG_RDTUN, &cpuid_leaf_b, 0, NULL); /* - * Round up to the next power of two, if necessary, and then take log2. - * Returns -1 if argument is zero. + * Compute ceil(log2(x)). Returns -1 if x is zero. */ static __inline int log2(u_int x) { - return (fls(x << (1 - powerof2(x))) - 1); + return (x == 0 ? -1 : fls(x - 1)); } int diff --git a/sys/x86/x86/mp_x86.c b/sys/x86/x86/mp_x86.c index 1027c2c8972b..3c08f7fa987d 100644 --- a/sys/x86/x86/mp_x86.c +++ b/sys/x86/x86/mp_x86.c @@ -183,15 +183,13 @@ mem_range_AP_init(void) } /* - * Round up to the next power of two, if necessary, and then - * take log2. - * Returns -1 if argument is zero. + * Compute ceil(log2(x)). Returns -1 if x is zero. */ static __inline int mask_width(u_int x) { - return (fls(x << (1 - powerof2(x))) - 1); + return (x == 0 ? -1 : fls(x - 1)); } /*