From patchwork Sun Jul 22 10:47:57 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yevgeny Kliteynik X-Patchwork-Id: 1224251 X-Patchwork-Delegate: alexne@voltaire.com Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id B917340D36 for ; Sun, 22 Jul 2012 10:59:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750996Ab2GVK7H (ORCPT ); Sun, 22 Jul 2012 06:59:07 -0400 Received: from eu2sys200bog108.obsmtp.com ([207.126.150.236]:43558 "HELO eu2sys200bog108.obsmtp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751426Ab2GVK6o (ORCPT ); Sun, 22 Jul 2012 06:58:44 -0400 Received: from MTLCAS01.mtl.com ([194.90.237.34]) (using TLSv1) by eu2sys200bob108.postini.com ([207.126.147.11]) with SMTP ID DSNKUAvc4sLWod2YQuEQ2ZCi6zbNhryqeo6S@postini.com; Sun, 22 Jul 2012 10:58:43 UTC Received: from [10.7.17.62] (10.0.13.1) by MTLCAS01.mtl.com (10.0.8.71) with Microsoft SMTP Server id 14.2.247.3; Sun, 22 Jul 2012 13:47:57 +0300 Message-ID: <500BDA5D.3000908@mellanox.co.il> Date: Sun, 22 Jul 2012 13:47:57 +0300 From: Yevgeny Kliteynik Reply-To: User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Linux RDMA , , "Yevgeny Kliteynik" Subject: [PATCH 2/3] complib: define "if" statements with branch prediction hints X-Originating-IP: [10.0.13.1] Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org 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 --- include/complib/cl_types_osd.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 #include #include + +/* + * 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_ */