diff mbox

[2/3] complib: define "if" statements with branch prediction hints

Message ID 500BDA5D.3000908@mellanox.co.il (mailing list archive)
State Rejected
Delegated to: Alex Netes
Headers show

Commit Message

Yevgeny Kliteynik July 22, 2012, 10:47 a.m. UTC
Similar to "likely" and "unlikely" that are used in kernel,
defined "if_PT" and "if_PF" for "predict true" and "predict
false" respectively.

Signed-off-by: Yevgeny Kliteynik <kliteyn@dev.mellanox.co.il>

---
 include/complib/cl_types_osd.h | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/include/complib/cl_types_osd.h b/include/complib/cl_types_osd.h
index ce1a452..f9abb28 100644
--- a/include/complib/cl_types_osd.h
+++ b/include/complib/cl_types_osd.h
@@ -1,6 +1,6 @@ 
 /*
  * Copyright (c) 2004-2009 Voltaire, Inc. All rights reserved.
- * Copyright (c) 2002-2005 Mellanox Technologies LTD. All rights reserved.
+ * Copyright (c) 2002-2012 Mellanox Technologies LTD. All rights reserved.
  * Copyright (c) 1996-2003 Intel Corporation. All rights reserved.
  *
  * This software is available to you under a choice of one of two
@@ -64,6 +64,21 @@  BEGIN_C_DECLS
 #include <inttypes.h>
 #include <assert.h>
 #include <string.h>
+
+/*
+ * Branch prediction hints
+ */
+#if defined(HAVE_BUILTIN_EXPECT)
+#define CL_PREDICT_TRUE(exp)	__builtin_expect( ((uintptr_t)(exp)), 1 )
+#define CL_PREDICT_FALSE(exp)	__builtin_expect( ((uintptr_t)(exp)), 0 )
+#else
+#define CL_PREDICT_TRUE(exp)	(exp)
+#define CL_PREDICT_FALSE(exp)	(exp)
+#endif
+
+#define if_PF(cond)		if(CL_PREDICT_FALSE(cond))
+#define if_PT(cond)		if(CL_PREDICT_TRUE(cond))
+
 #if defined (_DEBUG_)
 #define CL_ASSERT	assert
 #else				/* _DEBUG_ */