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.
Modified files: Index: src/include/assert.h diff -u src/include/assert.h:1.26 src/include/assert.h:1.27 --- src/include/assert.h:1.26 Tue Sep 12 22:08:24 2023 +++ src/include/assert.h Sat Mar 29 01:43:38 2025 @@ -1,4 +1,4 @@ -/* $NetBSD: assert.h,v 1.26 2023/09/12 22:08:24 rillig Exp $ */ +/* $NetBSD: assert.h,v 1.27 2025/03/29 01:43:38 riastradh Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -52,12 +52,12 @@ #else /* !NDEBUG */ # if __STDC__ # define assert(e) \ - ((e) ? __static_cast(void,0) : __assert13(__FILE__, __LINE__, \ - __assert_function__, #e)) + (__predict_true(e) ? __static_cast(void,0) \ + : __assert13(__FILE__, __LINE__, __assert_function__, #e)) # else /* PCC */ # define assert(e) \ - ((e) ? __static_cast(void,0) : __assert13(__FILE__, __LINE__, \ - __assert_function__, "e")) + (__predict_true(e) ? __static_cast(void,0) \ + : __assert13(__FILE__, __LINE__, __assert_function__, "e")) # endif /* !__STDC__ */ #endif /* NDEBUG */ @@ -67,12 +67,12 @@ #else /* _DIAGNOSTIC */ # if __STDC__ # define _DIAGASSERT(e) \ - ((e) ? __static_cast(void,0) : __diagassert13(__FILE__, __LINE__, \ - __assert_function__, #e)) + (__predict_true(e) ? __static_cast(void,0) \ + : __diagassert13(__FILE__, __LINE__, __assert_function__, #e)) # else /* !__STDC__ */ # define _DIAGASSERT(e) \ - ((e) ? __static_cast(void,0) : __diagassert13(__FILE__, __LINE__, \ - __assert_function__, "e")) + (__predict_true(e) ? __static_cast(void,0) \ + : __diagassert13(__FILE__, __LINE__, __assert_function__, "e")) # endif #endif /* _DIAGNOSTIC */