From nobody Sat Dec 14 00:11:54 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 4Y968B4Bd8z5gMG5; Sat, 14 Dec 2024 00:11:54 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Y968B1xgMz3x78; Sat, 14 Dec 2024 00:11:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734135114; 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=AqasK76F2oxu0JsgFqgUzuO6J3L8eQDY1dIiyqVSzEU=; b=xmmmLKNHqWInVla3Zvs+RANuhEdRm0DbcH1iWvSpAut09DETIhzDBB4L43fzJqI7DVZZpi 3/a0wB8uTGOqiPbii2EfeMLzAAieMELvoeXvqx9lMRfkfkMC6kvL7JoXYxkxHH7rpfUOsc mnHpBOThXTeRV5N0P0uvI8ewOCeeWrmjOGF4CRj/VLhulsxw7yQimCjOGWgHc4FeFf1ffq rq2Akdm2TYE2+35eVjDDz0ES2O+ZsoFNuR2/QqVAO8/NJmeui6Tzh4oMd6yKyUTH3PgGVr WdSFUZY5Nq5fHtMOwQhHANj6cuP6Vv6Uvdd/xaHHqacCGtJTGFW0ZcPxMA1lAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1734135114; 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=AqasK76F2oxu0JsgFqgUzuO6J3L8eQDY1dIiyqVSzEU=; b=ho2+k0vzvZiHPzyiHBgOK3jLIO46ufz0J39ID0QYdklEC02E6lXP53vVIktROhpqGrvx17 2FWuw+FSYvY7ywVObHF7nR12I8bHrhIMd7tbrNSDvNHo337ovBxj6BJguEIdimxZlm5dTI TZFQvmAI1vptnKbJWnLyWbkkJDYW9bcXcI7A/l00exDCmQmnRmfI5LtpHS+MmjV409im11 bMeus3ibCgYBvcWVjXGhUB39WFGn06/wv7PgMILak8rDJSe2hwW/zEr9NK7JlsrSeh+erh r3b8gZ4m+U7vL6xR0lENljztx8MMAsbSOub2GUbuFwrchTatckFhC2e1OUa6+A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1734135114; a=rsa-sha256; cv=none; b=Dh8WNSWIlBBrZSIKUCznMonnKs6FklVqEAoE+f22DVcyXhiUs39MQcdxJUXYd3oQGk92i6 S9HzlvysXYBbF9TXhRwl7FWrCaLVkeibLyXVfT1/ACaKilQ8L8iqmkjByatZno3STC86Vl RSQ3mneUUF3eqHuF/d+pJVebsjNDTnOdE9gA8UhX3cOoKAjgN78XGlbsQHz/Ipa61Kfypd VOAia8MxwAnLOG4sj0esRiCIoaxTGCrpP+7niGdMlamaYsiuaHYwQ/3bn+1Tun+LjfS7fs XEB7T1uif+GikkbwfG7D7s48eyUB7uJyrwgPFvGWT8lRvQLN0Jru+64yN6N5CQ== 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 4Y968B1YzPz10D6; Sat, 14 Dec 2024 00:11:54 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4BE0BsPY055343; Sat, 14 Dec 2024 00:11:54 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BE0BsR9055340; Sat, 14 Dec 2024 00:11:54 GMT (envelope-from git) Date: Sat, 14 Dec 2024 00:11:54 GMT Message-Id: <202412140011.4BE0BsR9055340@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Brooks Davis Subject: git: ecfe30854204 - stable/14 - style(9): Add comments about branch prediction 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: brooks X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: ecfe30854204e8de29ae637d493bd9de689ababa Auto-Submitted: auto-generated The branch stable/14 has been updated by brooks: URL: https://cgit.FreeBSD.org/src/commit/?id=ecfe30854204e8de29ae637d493bd9de689ababa commit ecfe30854204e8de29ae637d493bd9de689ababa Author: Warner Losh AuthorDate: 2024-07-03 18:52:38 +0000 Commit: Brooks Davis CommitDate: 2024-12-13 21:34:08 +0000 style(9): Add comments about branch prediction This is a partial merge of: cdefs.h: Add back comment about branch prediction Add back, with editing, the comments about branch prediction, when to use it, etc. Offer stronger opinions about this in style(9). Add in the convention for FreeBSD that we do only the entire expression in the if expression. Advise use only when it makes things measurably faster. Requested by: jhb Sponsored by: Netflix Reviewed by: brooks, jhb Differential Revision: https://reviews.freebsd.org/D45837 (cherry picked from commit fd31c0946ee2240491db1301c2d33eb846221a54) --- share/man/man9/style.9 | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/share/man/man9/style.9 b/share/man/man9/style.9 index a4ff85a07bcd..2e7c614b2a6d 100644 --- a/share/man/man9/style.9 +++ b/share/man/man9/style.9 @@ -908,6 +908,22 @@ New code should use .Fn _Static_assert instead of the older .Fn CTASSERT . +.Pp +.Fn __predict_true +and +.Fn __predict_false +should only be used in frequently executed code when it makes the code +measurably faster. +It is wasteful to make predictions for infrequently run code, like subsystem +initialization. +When using branch prediction hints, atypical error conditions should use +.Fn __predict_false +(document the exceptions). +Operations that almost always succeed use +.Fn __predict_true . +Only use the annotation for the entire if statement, rather than individual clauses. +Do not add these annotations without empirical evidence of the likelihood of the +branch. .Sh FILES .Bl -tag -width indent .It Pa /usr/src/tools/build/checkstyle9.pl