From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1 with cipher CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id E53011A1E43 for ; Wed, 26 Oct 2016 14:18:15 -0700 (PDT) Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP; 26 Oct 2016 14:18:16 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,551,1473145200"; d="scan'208";a="24123991" Received: from mdkinney-mobl.amr.corp.intel.com ([10.232.96.18]) by orsmga005.jf.intel.com with ESMTP; 26 Oct 2016 14:18:14 -0700 From: Michael Kinney To: edk2-devel@lists.01.org Cc: Liming Gao Date: Wed, 26 Oct 2016 14:18:12 -0700 Message-Id: <1477516692-8972-1-git-send-email-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.6.3.windows.1 Subject: [Patch] MdePkg/PciSegmentLib: Optimize PCI_SEGMENT_LIB_ADDRESS() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 26 Oct 2016 21:18:16 -0000 The PCI_SEGMENT_LIB_ADDRESS() macro puts the Segment number into bits 32..47 of the logical address that is returned. The portable method to put Segment in this bit range is to use LShitU64(). For 64-bit CPUs, this is optimized well by the compiler. For 32-bit CPUs, a call to LSHiftU64() is included in the generated binaries. However, if the Segment parameter is 0, then no shift is required. Add a check for Segment set to 0 and provide an optimized macro implementation that does not call LShiftU64(). Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Michael Kinney --- MdePkg/Include/Library/PciSegmentLib.h | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/MdePkg/Include/Library/PciSegmentLib.h b/MdePkg/Include/Library/PciSegmentLib.h index 1135010..5175e07 100644 --- a/MdePkg/Include/Library/PciSegmentLib.h +++ b/MdePkg/Include/Library/PciSegmentLib.h @@ -23,7 +23,7 @@ access method. Modules will typically use the PCI Segment Library for its PCI configuration accesses when PCI Segments other than Segment #0 must be accessed. -Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -56,11 +56,18 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ #define PCI_SEGMENT_LIB_ADDRESS(Segment,Bus,Device,Function,Register) \ - ( ((Register) & 0xfff) | \ - (((Function) & 0x07) << 12) | \ - (((Device) & 0x1f) << 15) | \ - (((Bus) & 0xff) << 20) | \ - (LShiftU64((Segment) & 0xffff, 32)) \ + ((Segment != 0) ? \ + ( ((Register) & 0xfff) | \ + (((Function) & 0x07) << 12) | \ + (((Device) & 0x1f) << 15) | \ + (((Bus) & 0xff) << 20) | \ + (LShiftU64 ((Segment) & 0xffff, 32)) \ + ) : \ + ( ((Register) & 0xfff) | \ + (((Function) & 0x07) << 12) | \ + (((Device) & 0x1f) << 15) | \ + (((Bus) & 0xff) << 20) \ + ) \ ) /** -- 2.6.3.windows.1