NetBSD Problem Report #59231

From www@netbsd.org  Sat Mar 29 01:37:20 2025
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 4DC821A9239
	for <gnats-bugs@gnats.NetBSD.org>; Sat, 29 Mar 2025 01:37:20 +0000 (UTC)
Message-Id: <20250329013718.D19381A923D@mollari.NetBSD.org>
Date: Sat, 29 Mar 2025 01:37:18 +0000 (UTC)
From: campbell+netbsd@mumble.net
Reply-To: campbell+netbsd@mumble.net
To: gnats-bugs@NetBSD.org
Subject: assert.h: missing branch prediction
X-Send-Pr-Version: www-1.0

>Number:         59231
>Category:       lib
>Synopsis:       assert.h: missing branch prediction
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    lib-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 29 01:40:00 +0000 2025
>Last-Modified:  Sat Mar 29 15:50:00 +0000 2025
>Originator:     Taylor R Campbell
>Release:        current, 10, 9, ...
>Organization:
The NetBSD Assertion
>Environment:
>Description:
The assert() macro, and its cousin _DIAGASSERT for NetBSD-internal library use, gives no hints to the compiler that the condition being asserted is expected to be true.

As a result, the compiler is left to guess which way to prioritize branches, and will often create suboptimal decisions under the premise that the condition has just as good a chance of being false.  For example, the compiler is apt to allocate a stack frame in what is otherwise a leaf routine just because it has a subroutine call to __assert13.
>How-To-Repeat:
code inspection
>Fix:
__predict_true

>Audit-Trail:
From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59231 CVS commit: src/include
Date: Sat, 29 Mar 2025 01:43:38 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Mar 29 01:43:38 UTC 2025

 Modified Files:
 	src/include: assert.h

 Log Message:
 assert.h: Sprinkle __predict_true.

 Assertions are always supposed to be true, so this should be a good
 prediction.

 This matches what we have done for KASSERT in the kernel since the
 year 2000.

 PR lib/59231: assert.h: missing branch prediction


 To generate a diff of this commit:
 cvs rdiff -u -r1.26 -r1.27 src/include/assert.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Taylor R Campbell" <riastradh@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/59231 CVS commit: src/sys/sys
Date: Sat, 29 Mar 2025 15:48:26 +0000

 Module Name:	src
 Committed By:	riastradh
 Date:		Sat Mar 29 15:48:26 UTC 2025

 Modified Files:
 	src/sys/sys: cdefs.h

 Log Message:
 __predict_true/false: Make these work with C++ too.

 Should fix build after recent assert.h change.

 error: no match for `operator!=' (operand types are `...' and `int')

 PR lib/59231: assert.h: missing branch prediction


 To generate a diff of this commit:
 cvs rdiff -u -r1.163 -r1.164 src/sys/sys/cdefs.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.47 2022/09/11 19:34:41 kim Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2025 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.