From 0f6c38288807f79c01a659c4187bdc69fa92845f Mon Sep 17 00:00:00 2001 From: Pip Cet Date: Sun, 31 May 2026 06:24:58 +0000 Subject: [PATCH] Make 'likely' macro available in all of Emacs (bug#81115) * src/android.c (likely): Move ... * src/conf_post.h (likely): ... here. Ensure true values which aren't equal to 1 are still predicted correctly. --- src/android.c | 2 -- src/conf_post.h | 5 +++++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/android.c b/src/android.c index 7ff7f26b527..034e1db2dd6 100644 --- a/src/android.c +++ b/src/android.c @@ -6158,8 +6158,6 @@ android_build_jstring (const char *text) if global_foo cannot be allocated, and after the global reference is created. */ -#define likely(cond) __builtin_expect (cond, 1) - /* Check for JNI exceptions and call memory_full in that situation. */ diff --git a/src/conf_post.h b/src/conf_post.h index e0bb753df56..74742ac16dc 100644 --- a/src/conf_post.h +++ b/src/conf_post.h @@ -371,6 +371,11 @@ extern int emacs_setenv_TZ (char const *); # define UNINIT /* empty */ #endif +/* likely (COND) is equivalent to COND ? 1 : 0, but instructs the + compiler to provide static branch prediction hints to the CPU so that + the branch isn't mispredicted. */ +#define likely(cond) __builtin_expect (!!(cond), 1) + /* Emacs needs neither glibc strftime behavior for AM and PM indicators, nor Gnulib strftime support for non-Gregorian calendars. */ #define REQUIRE_GNUISH_STRFTIME_AM_PM false