changeset 32118:61d014959a8b

new OCTAVE_LIKELY and OCTAVE_UNLIKELY macros * oct-conf-post-public.in.h (OCTAVE_LIKELY, OCTAVE_UNLIKELY): New branch hint macros defined using __builtin_expect.
author Petter T. <petter.vilhelm@gmail.com>
date Wed, 14 Jun 2023 16:02:51 -0400
parents 5e207c861831
children 6870df38af9c
files oct-conf-post-public.in.h
diffstat 1 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/oct-conf-post-public.in.h	Wed Jun 14 16:02:37 2023 -0400
+++ b/oct-conf-post-public.in.h	Wed Jun 14 16:02:51 2023 -0400
@@ -66,6 +66,16 @@
 /* #  undef HAVE_OCTAVE_UNUSED_ATTR */
 #endif
 
+/* Branch hint macros for use in if condititions.
+   Returns logical value of x. */
+#if defined (__GNUC__)
+#  define OCTAVE_LIKELY(x) __builtin_expect (!!(x), 1)
+#  define OCTAVE_UNLIKELY(x) __builtin_expect (!!(x), 0)
+#else
+#  define OCTAVE_LIKELY(x) !!(x)
+#  define OCTAVE_UNLIKELY(x) !!(x)
+#endif
+
 #if defined (__MINGW32__)
   /* MinGW requires special handling due to different format specifiers
    * on different platforms.  The macro __MINGW_PRINTF_FORMAT maps to