From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.20; helo=mga02.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id BA93B20968918 for ; Mon, 2 Jul 2018 01:22:44 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jul 2018 01:22:44 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,298,1526367600"; d="scan'208";a="237167428" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga005.jf.intel.com with ESMTP; 02 Jul 2018 01:22:27 -0700 Received: from fmsmsx120.amr.corp.intel.com (10.18.124.208) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 2 Jul 2018 01:22:24 -0700 Received: from shsmsx152.ccr.corp.intel.com (10.239.6.52) by fmsmsx120.amr.corp.intel.com (10.18.124.208) with Microsoft SMTP Server (TLS) id 14.3.319.2; Mon, 2 Jul 2018 01:22:23 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.87]) by SHSMSX152.ccr.corp.intel.com ([169.254.6.70]) with mapi id 14.03.0319.002; Mon, 2 Jul 2018 16:22:22 +0800 From: "Gao, Liming" To: "Tomas Pilar (tpilar)" , "edk2-devel@lists.01.org" Thread-Topic: [edk2] [PATCH] MdePkg/BaseLib: Add bit field Hamming weight calculation methods Thread-Index: AQHUD41wxdKOt+iKDkeramiFx9WXY6R7m7VA Date: Mon, 2 Jul 2018 08:22:21 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E2A0C7F@SHSMSX104.ccr.corp.intel.com> References: <737e881b-e3fc-1523-2b11-f324e1d398a7@solarflare.com> In-Reply-To: <737e881b-e3fc-1523-2b11-f324e1d398a7@solarflare.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdePkg/BaseLib: Add bit field Hamming weight calculation methods X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 02 Jul 2018 08:22:44 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Tomas: Could you share some background what code depends on new added APIs?=20 Thanks Liming >-----Original Message----- >From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of >Tomas Pilar (tpilar) >Sent: Friday, June 29, 2018 5:42 PM >To: edk2-devel@lists.01.org >Subject: [edk2] [PATCH] MdePkg/BaseLib: Add bit field Hamming weight >calculation methods > >Add 32-bit and 64-bit functions that count number of set bits in a bitfiel= d >using the divide-and-count method. > >Contributed-under: TianoCore Contribution Agreement 1.1 >Signed-off-by: Tomas Pilar >--- > MdePkg/Include/Library/BaseLib.h | 56 +++++++++++++++++++++++++++ > MdePkg/Library/BaseLib/BitField.c | 79 >+++++++++++++++++++++++++++++++++++++++ > 2 files changed, 135 insertions(+) > >diff --git a/MdePkg/Include/Library/BaseLib.h >b/MdePkg/Include/Library/BaseLib.h >index 1db3a04..7eb0488 100644 >--- a/MdePkg/Include/Library/BaseLib.h >+++ b/MdePkg/Include/Library/BaseLib.h >@@ -4609,6 +4609,62 @@ BitFieldAndThenOr64 ( > IN UINT64 OrData > ); > >+/** >+ Reads a bit field from a 32-bit value, counts and returns >+ the number of set bits. >+ >+ Counts the number of set bits in the bit field specified by >+ StartBit and EndBit in Operand. The count is returned. >+ >+ If StartBit is greater than 31, then ASSERT(). >+ If EndBit is greater than 31, then ASSERT(). >+ If EndBit is less than StartBit, then ASSERT(). >+ >+ @param Operand Operand on which to perform the bitfield operation. >+ @param StartBit The ordinal of the least significant bit in the bit f= ield. >+ Range 0..31. >+ @param EndBit The ordinal of the most significant bit in the bit fi= eld. >+ Range 0..31. >+ >+ @return The number of bits set between StartBit and EndBit. >+ >+**/ >+UINT8 >+EFIAPI >+BitFieldHammingWeight32 ( >+ IN UINT32 Operand, >+ IN UINTN StartBit, >+ IN UINTN EndBit >+ ); >+ >+/** >+ Reads a bit field from a 64-bit value, counts and returns >+ the number of set bits. >+ >+ Counts the number of set bits in the bit field specified by >+ StartBit and EndBit in Operand. The count is returned. >+ >+ If StartBit is greater than 63, then ASSERT(). >+ If EndBit is greater than 63, then ASSERT(). >+ If EndBit is less than StartBit, then ASSERT(). >+ >+ @param Operand Operand on which to perform the bitfield operation. >+ @param StartBit The ordinal of the least significant bit in the bit = field. >+ Range 0..63. >+ @param EndBit The ordinal of the most significant bit in the bit f= ield. >+ Range 0..63. >+ >+ @return The number of bits set between StartBit and EndBit. >+ >+**/ >+UINT8 >+EFIAPI >+BitFieldHammingWeight64 ( >+ IN UINT64 Operand, >+ IN UINTN StartBit, >+ IN UINTN EndBit >+ ); >+ > // > // Base Library Checksum Functions > // >diff --git a/MdePkg/Library/BaseLib/BitField.c >b/MdePkg/Library/BaseLib/BitField.c >index d2d3150..af06db8 100644 >--- a/MdePkg/Library/BaseLib/BitField.c >+++ b/MdePkg/Library/BaseLib/BitField.c >@@ -920,3 +920,82 @@ BitFieldAndThenOr64 ( > OrData > ); > } >+ >+/** >+ Reads a bit field from a 32-bit value, counts and returns >+ the number of set bits. >+ >+ Counts the number of set bits in the bit field specified by >+ StartBit and EndBit in Operand. The count is returned. >+ >+ If StartBit is greater than 31, then ASSERT(). >+ If EndBit is greater than 31, then ASSERT(). >+ If EndBit is less than StartBit, then ASSERT(). >+ >+ @param Operand Operand on which to perform the bitfield operation. >+ @param StartBit The ordinal of the least significant bit in the bit f= ield. >+ Range 0..31. >+ @param EndBit The ordinal of the most significant bit in the bit fi= eld. >+ Range 0..31. >+ >+ @return The number of bits set between StartBit and EndBit. >+ >+**/ >+UINT8 >+EFIAPI >+BitFieldHammingWeight32 ( >+ IN UINT32 Operand, >+ IN UINTN StartBit, >+ IN UINTN EndBit >+ ) >+{ >+ ASSERT (EndBit < 32); >+ ASSERT (StartBit <=3D EndBit); >+ >+ UINT32 Count =3D BitFieldRead32 (Operand, StartBit, EndBit); >+ Count -=3D ((Count >> 1) & 0x55555555); >+ Count =3D (Count & 0x33333333) + ((Count >> 2) & 0x33333333); >+ Count +=3D Count >> 4; >+ Count &=3D 0x0F0F0F0F; >+ Count +=3D Count >> 8; >+ Count +=3D Count >> 16; >+ >+ return (UINT8) Count & 0x3F; >+} >+ >+/** >+ Reads a bit field from a 64-bit value, counts and returns >+ the number of set bits. >+ >+ Counts the number of set bits in the bit field specified by >+ StartBit and EndBit in Operand. The count is returned. >+ >+ If StartBit is greater than 63, then ASSERT(). >+ If EndBit is greater than 63, then ASSERT(). >+ If EndBit is less than StartBit, then ASSERT(). >+ >+ @param Operand Operand on which to perform the bitfield operation. >+ @param StartBit The ordinal of the least significant bit in the bit = field. >+ Range 0..63. >+ @param EndBit The ordinal of the most significant bit in the bit f= ield. >+ Range 0..63. >+ >+ @return The number of bits set between StartBit and EndBit. >+ >+**/ >+UINT8 >+EFIAPI >+BitFieldHammingWeight64 ( >+ IN UINT64 Operand, >+ IN UINTN StartBit, >+ IN UINTN EndBit >+ ) >+{ >+ ASSERT (EndBit < 64); >+ ASSERT (StartBit <=3D EndBit); >+ >+ UINT64 BitField =3D BitFieldRead64 (Operand, StartBit, EndBit); >+ UINT8 Count =3D BitFieldHammingWeight32 (BitField, 0, 31); >+ return Count + BitFieldHammingWeight32(RShiftU64(BitField, 32), 0, 31); >+} >+ >-- >2.9.5 > >_______________________________________________ >edk2-devel mailing list >edk2-devel@lists.01.org >https://lists.01.org/mailman/listinfo/edk2-devel