[PATCH v2] debug.h: hint a compiler: TRACE is not executed in common usage

Konstantin Kharlamov Hi-Angel at yandex.ru
Tue Jan 29 00:36:43 CST 2019


Below are results of running "the big keybench" benchmark of Xonotic
under "perf".  They're negligible, still, it might make more difference
for slower machines or distinct workloads.

branch-misses:
vanilla-wine  | patched-wine  | improvement
------------------------------|------------
1,757,439,276 | 1,749,075,739 |  -8,363,537
1,750,670,918 | 1,746,169,971 |  -4,500,947
1,746,488,762 | 1,748,569,739 |   2,080,977
1,753,328,811 | 1,739,515,555 | -13,813,256

Command line example for testing:
export WINEPREFIX=~/.wineTESTING; perf stat -B -e cache-misses,branch-misses,faults ~/Projects/wine/test-build/loader/wine ./xonotic-x86.exe -benchmark demos/the-big-keybench

Changes in v2:
	* Don't put custom macro into WinAPI header (Alexandre Julliard)
	* Capitalize macros (Me)

Signed-off-by: Konstantin Kharlamov <Hi-Angel at yandex.ru>
---
 include/wine/debug.h | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/include/wine/debug.h b/include/wine/debug.h
index 07ac88d264..53d61f16b8 100644
--- a/include/wine/debug.h
+++ b/include/wine/debug.h
@@ -57,8 +57,17 @@ struct __wine_debug_channel
     char name[15];
 };
 
+/* Branch hints for performance critical code */
+#ifdef __GNUC__
+# define LIKELY(expr) (__builtin_expect(expr, 1))
+# define UNLIKELY(expr) (__builtin_expect(expr, 0))
+#else
+# define LIKELY(expr) (expr)
+# define UNLIKELY(expr) (expr)
+#endif
+
 #ifndef WINE_NO_TRACE_MSGS
-# define __WINE_GET_DEBUGGING_TRACE(dbch) ((dbch)->flags & (1 << __WINE_DBCL_TRACE))
+# define __WINE_GET_DEBUGGING_TRACE(dbch) UNLIKELY((dbch)->flags & (1 << __WINE_DBCL_TRACE))
 #else
 # define __WINE_GET_DEBUGGING_TRACE(dbch) 0
 #endif
-- 
2.20.1




More information about the wine-devel mailing list