public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [Patch] MdePkg/PciSegmentLib: Optimize PCI_SEGMENT_LIB_ADDRESS()
@ 2016-10-26 21:18 Michael Kinney
  2016-10-27  3:17 ` Gao, Liming
  0 siblings, 1 reply; 2+ messages in thread
From: Michael Kinney @ 2016-10-26 21:18 UTC (permalink / raw)
  To: edk2-devel; +Cc: Liming Gao

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 <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Michael Kinney <michael.d.kinney@intel.com>
---
 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.<BR>
+Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
 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



^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-27  3:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-26 21:18 [Patch] MdePkg/PciSegmentLib: Optimize PCI_SEGMENT_LIB_ADDRESS() Michael Kinney
2016-10-27  3:17 ` Gao, Liming

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox