From owner-dev-commits-src-branches@freebsd.org Mon Aug 30 12:43:09 2021 Return-Path: Delivered-To: dev-commits-src-branches@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id AA613675C2E; Mon, 30 Aug 2021 12:43:09 +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 4Gyqjn4SkBz3nqq; Mon, 30 Aug 2021 12:43:09 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 778AB1E050; Mon, 30 Aug 2021 12:43:09 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 17UCh9f2034846; Mon, 30 Aug 2021 12:43:09 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 17UCh9Xk034845; Mon, 30 Aug 2021 12:43:09 GMT (envelope-from git) Date: Mon, 30 Aug 2021 12:43:09 GMT Message-Id: <202108301243.17UCh9Xk034845@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Andrew Turner Subject: git: 45f92b1e834c - stable/13 - Split out the arm64 ID field comparison function MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 45f92b1e834c11093d8c1fd4fb7654a14e0b2de1 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-branches@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commits to the stable branches of the FreeBSD src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 30 Aug 2021 12:43:09 -0000 The branch stable/13 has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=45f92b1e834c11093d8c1fd4fb7654a14e0b2de1 commit 45f92b1e834c11093d8c1fd4fb7654a14e0b2de1 Author: Andrew Turner AuthorDate: 2021-07-16 12:46:59 +0000 Commit: Andrew Turner CommitDate: 2021-08-30 11:22:21 +0000 Split out the arm64 ID field comparison function This will be useful in an update for finding which HWCAPS to set. Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D31200 (cherry picked from commit 04f6015706f73c90ba78699953d0d4d0b0237298) --- sys/arm64/arm64/identcpu.c | 48 ++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/sys/arm64/arm64/identcpu.c b/sys/arm64/arm64/identcpu.c index 522526b92307..233b036f4499 100644 --- a/sys/arm64/arm64/identcpu.c +++ b/sys/arm64/arm64/identcpu.c @@ -1348,22 +1348,26 @@ get_kernel_reg(u_int reg, uint64_t *val) return (false); } -static uint64_t -update_lower_register(uint64_t val, uint64_t new_val, u_int shift, - int width, bool sign) +/* + * Compares two field values that may be signed or unsigned. + * Returns: + * < 0 when a is less than b + * = 0 when a equals b + * > 0 when a is greater than b + */ +static int +mrs_field_cmp(uint64_t a, uint64_t b, u_int shift, int width, bool sign) { uint64_t mask; - uint64_t new_field, old_field; - bool update; KASSERT(width > 0 && width < 64, ("%s: Invalid width %d", __func__, width)); mask = (1ul << width) - 1; - new_field = (new_val >> shift) & mask; - old_field = (val >> shift) & mask; + /* Move the field to the lower bits */ + a = (a >> shift) & mask; + b = (b >> shift) & mask; - update = false; if (sign) { /* * The field is signed. Toggle the upper bit so the comparison @@ -1371,17 +1375,29 @@ update_lower_register(uint64_t val, uint64_t new_val, u_int shift, * i.e. those with a 0 bit, larger than negative numbers, * i.e. those with a 1 bit, in an unsigned comparison. */ - if ((new_field ^ (1ul << (width - 1))) < - (old_field ^ (1ul << (width - 1)))) - update = true; - } else { - if (new_field < old_field) - update = true; + a ^= 1ul << (width - 1); + b ^= 1ul << (width - 1); } - if (update) { + return (a - b); +} + +static uint64_t +update_lower_register(uint64_t val, uint64_t new_val, u_int shift, + int width, bool sign) +{ + uint64_t mask; + + KASSERT(width > 0 && width < 64, ("%s: Invalid width %d", __func__, + width)); + + /* + * If the new value is less than the existing value update it. + */ + if (mrs_field_cmp(new_val, val, shift, width, sign) < 0) { + mask = (1ul << width) - 1; val &= ~(mask << shift); - val |= new_field << shift; + val |= new_val & (mask << shift); } return (val);