From nobody Tue Apr 02 07:24:17 2024 X-Original-To: dev-commits-src-all@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 4V7zsG0XJLz5GKqn; Tue, 2 Apr 2024 07:24:18 +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 4V7zsF6vDBz4Gth; Tue, 2 Apr 2024 07:24:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712042658; 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=Od5eLS81RgmiB1eG+sa77dhuhHt5FyEcxuL9Uwus7zI=; b=Ir8ahJo+OukN5bwwksL1c7uBiIWQY+qGeKfa2aXSy44sFpFEZGOmYsX70EUhVy8RC0287M D6JPg33OxUiZcDzFOgSNrWv+GS5j84uzI1c2FsvbM6xzIvSLikiRfCQcNyHeOOwEFzesad r00ctYTbguYlT9h16PQ6b9UGa8ND4UZeaaF7WXXbjUiElArs1cFI36scsMlrTiO04/1VEN qvguRH6Sl1jV2uUlahZTC0v3o+majjt+rkkhp3xmBBKdB072I7VcjeAFhFNO5U6Bt4qkE2 R4SSa/7kcpeNEY6D/XkLeTaI/8MgHTFTOfKR39UBrkq4wSEEA7BWUZZMUKlr+A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712042658; a=rsa-sha256; cv=none; b=EBMY++tn3kq2MkOzBMUHgzqnSCR/nkKfuBVgoKmAGE1gfAtlKM1LPIBGR0uzBeZTZtuQHr oOlsz8Y1b3pZw7GJoup85sF+A3ZfRUOHNj3SaZXiiJBhYJfyNvd2TTTCto0k5raSULr8mG MW689NxoytfJFuvA071gVl/DuQhFEQqOp71FhPb+GLB0heiJw4ol82Kw5ASeXpuwB1vi5o b9w1/+hc01p9BbmENy541V/re4r/pF0k7py6sRLtzozGcgpr82d+L/4P1b4twfvD24LwPp vgzuYhwpDDYOD6OJLFm63tvI5uJgcVoAKTQysF0P560bWMtGEms/5/6g0985QQ== 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=1712042658; 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=Od5eLS81RgmiB1eG+sa77dhuhHt5FyEcxuL9Uwus7zI=; b=dZ+Gfid6ijGUiXlIBMGdLp8U/sXZfqQFqKGJRinL+D/sXgrSahNtab16g1KK1mryVJkVC5 sVpKHmyFb3SSp0Jg8w9mc8V8WC0xR5noiw0lBsl+BBQCH6j7R6P8F8pNOMyLUYb7gIqz+q gbl2wJWUtdwV4CCp+KC7OhGgFgDwUQnPKUTd14NFsTO9qsCX9CKb24hMA+lXzol4nrxS5r QXcdEhyaTty4ASImn5yV+5NAXlnFViWKiglc+jPxqPScL/dXO7v+3hqGwM147JDy9byZ2D YrUVuz96VfIFCRrk0EEzA6mpRvMQDYH2ZkbK5vxeTAURRHHe5xNVNtuun+ooDQ== 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 4V7zsF6VfYzgTQ; Tue, 2 Apr 2024 07:24:17 +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 4327OH5A060704; Tue, 2 Apr 2024 07:24:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 4327OH84060701; Tue, 2 Apr 2024 07:24:17 GMT (envelope-from git) Date: Tue, 2 Apr 2024 07:24:17 GMT Message-Id: <202404020724.4327OH84060701@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Lawrence Stewart Subject: git: 743d4b7cc5e2 - main - Fix the logic which determines if the destination Q variable can represent the source Q variable's value with full accuracy. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: lstewart X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 743d4b7cc5e217a2120b3b5d4d1b284e1e5b7ea2 Auto-Submitted: auto-generated The branch main has been updated by lstewart: URL: https://cgit.FreeBSD.org/src/commit/?id=743d4b7cc5e217a2120b3b5d4d1b284e1e5b7ea2 commit 743d4b7cc5e217a2120b3b5d4d1b284e1e5b7ea2 Author: Lawrence Stewart AuthorDate: 2024-04-02 05:07:04 +0000 Commit: Lawrence Stewart CommitDate: 2024-04-02 06:16:00 +0000 Fix the logic which determines if the destination Q variable can represent the source Q variable's value with full accuracy. The new logic is mostly self explanatory except for the value fit checks. If b has fewer integer bits than a, 0 == (Q_GIABSVAL(a) & (~Q_TC(a, 0) << Q_NIBITS(b))) is checking that a's integer value does not have high-order bits set above what b is capable of storing. If b has fewer fractional bits than a, 0 == (Q_GFABSVAL(a) & ~(~Q_TC(a, 0) << (Q_NFBITS(a) - Q_NFBITS(b))))) is checking that a's fractional value does not have low-order bits set below what b is capable of storing. Obtained from: Netflix, Inc. MFC afer: 1 week --- sys/sys/qmath.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/sys/sys/qmath.h b/sys/sys/qmath.h index fa5acdb985be..bfaad75e77ee 100644 --- a/sys/sys/qmath.h +++ b/sys/sys/qmath.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2018 Netflix, Inc. + * Copyright (c) 2018-2024 Netflix, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -378,15 +378,18 @@ typedef u64q_t umaxq_t; #define Q_QMINQ(a, b) (Q_LT(a, b) ? (a) : (b)) /* - * Test if 'a' can be represented by 'b' with full accuracy (T) or not (F). - * The type casting has to be done to a's type so that any truncation caused by - * the casts will not affect the logic. + * Test if 'a' can be represented by 'b' with full accuracy (0) or not + * (EOVERFLOW). If 'b' has fewer integer and/or fractional bits than 'a', + * the integer and fractional values stored in 'a' must fit in the available + * number of integer and fractional bits in 'b'. */ -#define Q_QCANREPQ(a, b) \ - ((((Q_LTZ(a) && Q_SIGNED(b)) || !Q_LTZ(a)) && \ - Q_GIABSVAL(a) <= Q_TC(a, Q_IMAXVAL(b)) && \ - Q_GFABSVAL(a) <= Q_TC(a, Q_FMAXVAL(b))) ? \ - 0 : EOVERFLOW) +#define Q_QCANREPQ(a, b) (( \ + (!Q_LTZ(a) || Q_SIGNED(b)) \ + && ( Q_NIBITS(a) <= Q_NIBITS(b) \ + || 0 == (Q_GIABSVAL(a) & (~Q_TC(a, 0) << Q_NIBITS(b)))) \ + && ( Q_NFBITS(a) <= Q_NFBITS(b) \ + || 0 == (Q_GFABSVAL(a) & ~(~Q_TC(a, 0) << (Q_NFBITS(a) - Q_NFBITS(b))))) \ + ) ? 0 : EOVERFLOW) /* Test if raw integer value 'i' can be represented by 'q' (T) or not (F). */ #define Q_QCANREPI(q, i) \