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.100; helo=mga07.intel.com; envelope-from=liming.gao@intel.com; receiver=edk2-devel@lists.01.org Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) (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 57D1C2096F350 for ; Thu, 5 Jul 2018 07:08:03 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Jul 2018 07:08:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.51,312,1526367600"; d="scan'208";a="52217041" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga007.fm.intel.com with ESMTP; 05 Jul 2018 07:07:44 -0700 Received: from fmsmsx120.amr.corp.intel.com (10.18.124.208) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 5 Jul 2018 07:07:44 -0700 Received: from shsmsx151.ccr.corp.intel.com (10.239.6.50) by fmsmsx120.amr.corp.intel.com (10.18.124.208) with Microsoft SMTP Server (TLS) id 14.3.319.2; Thu, 5 Jul 2018 07:07:43 -0700 Received: from shsmsx104.ccr.corp.intel.com ([169.254.5.81]) by SHSMSX151.ccr.corp.intel.com ([169.254.3.17]) with mapi id 14.03.0319.002; Thu, 5 Jul 2018 22:07:42 +0800 From: "Gao, Liming" To: "Tomas Pilar (tpilar)" , "edk2-devel@lists.01.org" CC: "Kinney, Michael D" Thread-Topic: [PATCH v3] MdePkg/BaseLib: Add bit field population calculating methods Thread-Index: AQHUE5+nGAbDaVOmJkmLKKZoVCRYF6SAq4xQ Date: Thu, 5 Jul 2018 14:07:41 +0000 Message-ID: <4A89E2EF3DFEDB4C8BFDE51014F606A14E2B6B4C@SHSMSX104.ccr.corp.intel.com> References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNjQwMGNlMjAtM2M2OC00OWM1LTkxNmUtNjlhNmRmMTRlNmRmIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiUEtnRmUzQ3g4Y3l4Q2FkYUxFbVBkSGJrVHNZMTV4TFB6VTNXUlUxa0o2NkZJQ3pZNENkbkY4UEc3dTRubGxlViJ9 dlp-product: dlpe-windows dlp-version: 11.0.200.100 dlp-reaction: no-action x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH v3] MdePkg/BaseLib: Add bit field population calculating 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: Thu, 05 Jul 2018 14:08:03 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Tom: When I use VS2015 to compile it, I meet with below error. Could you fix t= hem? Edk2\MdePkg\Library\BaseLib\BitField.c(1002): error C2220: warning treated = as error - no 'object' file generated Edk2\MdePkg\Library\BaseLib\BitField.c(1002): warning C4244: '=3D': convers= ion from 'UINT64' to 'UINT32', possible loss of data Edk2\MdePkg\Library\BaseLib\BitField.c(1005): warning C4244: 'function': co= nversion from 'UINT64' to 'UINT32', possible loss of data Thanks Liming > -----Original Message----- > From: Tomas Pilar (tpilar) [mailto:tpilar@solarflare.com] > Sent: Wednesday, July 4, 2018 10:02 PM > To: edk2-devel@lists.01.org > Cc: Kinney, Michael D ; Gao, Liming > Subject: [PATCH v3] MdePkg/BaseLib: Add bit field population calculating = methods >=20 > Add 32-bit and 64-bit functions that count number of set bits in a bitfie= ld > using a divide-and-count method. >=20 > Contributed-under: TianoCore Contribution Agreement 1.1 > Signed-off-by: Tomas Pilar > Cc: Liming Gao > Cc: Michael D Kinney > --- > MdePkg/Include/Library/BaseLib.h | 56 ++++++++++++++++++++++++++ > MdePkg/Library/BaseLib/BitField.c | 85 +++++++++++++++++++++++++++++++++= ++++++ > 2 files changed, 141 insertions(+) >=20 > diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/Ba= seLib.h > index 1db3a04..123ae19 100644 > --- a/MdePkg/Include/Library/BaseLib.h > +++ b/MdePkg/Include/Library/BaseLib.h > @@ -4609,6 +4609,62 @@ BitFieldAndThenOr64 ( > IN UINT64 OrData > ); >=20 > +/** > + 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 = field. > + Range 0..31. > + @param EndBit The ordinal of the most significant bit in the bit f= ield. > + Range 0..31. > + > + @return The number of bits set between StartBit and EndBit. > + > +**/ > +UINT8 > +EFIAPI > +BitFieldCountOnes32 ( > + 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 = field. > + Range 0..63. > + > + @return The number of bits set between StartBit and EndBit. > + > +**/ > +UINT8 > +EFIAPI > +BitFieldCountOnes64 ( > + 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/B= itField.c > index d2d3150..8acd345 100644 > --- a/MdePkg/Library/BaseLib/BitField.c > +++ b/MdePkg/Library/BaseLib/BitField.c > @@ -920,3 +920,88 @@ 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 = field. > + Range 0..31. > + @param EndBit The ordinal of the most significant bit in the bit f= ield. > + Range 0..31. > + > + @return The number of bits set between StartBit and EndBit. > + > +**/ > +UINT8 > +EFIAPI > +BitFieldCountOnes32 ( > + IN UINT32 Operand, > + IN UINTN StartBit, > + IN UINTN EndBit > + ) > +{ > + UINT32 Count; > + > + ASSERT (EndBit < 32); > + ASSERT (StartBit <=3D EndBit); > + > + 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 = field. > + Range 0..63. > + > + @return The number of bits set between StartBit and EndBit. > + > +**/ > +UINT8 > +EFIAPI > +BitFieldCountOnes64 ( > + IN UINT64 Operand, > + IN UINTN StartBit, > + IN UINTN EndBit > + ) > +{ > + UINT32 BitField; > + UINT8 Count; > + > + ASSERT (EndBit < 64); > + ASSERT (StartBit <=3D EndBit); > + > + BitField =3D BitFieldRead64 (Operand, StartBit, EndBit); > + Count =3D BitFieldCountOnes32 (BitField, 0, 31); > + > + return Count + BitFieldCountOnes32 (RShiftU64(BitField, 32), 0, 31); > +} > + > -- > 2.9.5