From nobody Fri May 3 05:43:56 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail(p=none dis=none) header.from=nxp.com Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1518174078847363.2154477830569; Fri, 9 Feb 2018 03:01:18 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id F074C223DB794; Fri, 9 Feb 2018 02:55:30 -0800 (PST) Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30080.outbound.protection.outlook.com [40.107.3.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C4E50223DB786 for ; Fri, 9 Feb 2018 02:55:27 -0800 (PST) Received: from uefi-workstation.ap.freescale.net (192.88.169.1) by AM6PR0402MB3944.eurprd04.prod.outlook.com (2603:10a6:209:1c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.485.10; Fri, 9 Feb 2018 11:01:04 +0000 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=40.107.3.80; helo=eur03-am5-obe.outbound.protection.outlook.com; envelope-from=pankaj.bansal@nxp.com; receiver=edk2-devel@lists.01.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=3b33c0wXVhS7XpLt7w7HYuP6dq623ZPQ4d9iVDD5wnw=; b=lLZjzdwIUGA7USGT1vGyB8M89CayapvJZx3i21ZLcg+Zze+Qux9JeyyD5BccFBnPbk8BLPRvNlHdC+OudXhS1x8LvQgvWHEpdL3OM6BqchKdbwAM30E58FJVsHpTjauLxVGzchP/0tkF6O3TWC9Rrz9kH5oUy4uDcY+AAUDuU3A= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=pankaj.bansal@nxp.com; From: Pankaj Bansal To: edk2-devel@lists.01.org Date: Fri, 9 Feb 2018 16:29:56 +0530 Message-Id: <1518173996-26906-1-git-send-email-pankaj.bansal@nxp.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 X-Originating-IP: [192.88.169.1] X-ClientProxiedBy: PN1PR0101CA0006.INDPRD01.PROD.OUTLOOK.COM (2603:1096:c00:e::16) To AM6PR0402MB3944.eurprd04.prod.outlook.com (2603:10a6:209:1c::19) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 8af924ce-d041-4fc1-f0dd-08d56fac6a86 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:AM6PR0402MB3944; X-Microsoft-Exchange-Diagnostics: 1; AM6PR0402MB3944; 3:SXBlOt6wBZPLFWzRgMku1tiiKUBeSW7i3NhHn9IJkxdYIBXagAOWX0v1s71XSBGBGAxYm8EvbWEByGlAK3k6Ssl4O3+fMx3UMqEuFmZFmtY7iYFgF8pfTgTDQPyOpUToPPKNgFssFdo/RUhs2Gb1nQ8ch2CbHojq3abasboj57ZP772z4pmPO2UHaFZf/6r0MmEHWnH2WL1QGc0wqwRYvqGwdrr/IKzX6jl1mgB2NS+uZsq0QKpR36SD5F00VWS0; 25:n7R7Xitg/DOnz2KLyy/r/xy9KB96V5uLArb27WP1CupX7mKQG3L2LpFV5IUgEq+kPoA5jda/9iVZgLFaekazYK1ukcTr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85poxNzY+8Un/xTrCexy/7BbHe1z5Uj6pxdNF8usZgB1G/JZc5iwpWNIorlOERXtNoQ0JJE4B9cSs26XafIvEOhKhkB0vVlyzWsvvjUbWiCwAFuUO6L4O2Y99VlkLDJV+ek8UXp69ZtdSsZznO0YNVnVePPVlrb7tlKWB0EeO8n91H4QknEUQQXepX5Ue0OQfsEHdxQiYwrNudKPWA7Fr02BCmDcvhDweS9cd3kXwKhZ6IwjtEyZqBVomfmWL0rITy0EpNbtjXGllrw82FbUsHXNm2+sakIRfgp7I5NJJahKK+zVuGXLU9wymGaQTBDU26zSTIsPGzAJim9jqz7j5bRqqtQFWdA7M8a+s= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197)(228905959029699); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(10201501046)(3231101)(2400082)(944501161)(93006095)(93001095)(6055026)(6041288)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:AM6PR0402MB3944; BCL:0; PCL:0; RULEID:; SRVR:AM6PR0402MB3944; X-Forefront-PRVS: 057859F9C5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(376002)(346002)(39860400002)(39380400002)(396003)(366004)(199004)(189003)(5660300001)(53936002)(316002)(6116002)(68736007)(3846002)(7736002)(305945005)(8936002)(51416003)(16586007)(54906003)(52116002)(36756003)(8676002)(2351001)(16526019)(81166006)(106356001)(26005)(6666003)(6506007)(386003)(6916009)(86362001)(81156014)(186003)(2361001)(66066001)(478600001)(6486002)(50226002)(4326008)(50466002)(48376002)(2906002)(105586002)(25786009)(47776003)(97736004)(6512007)(19627235001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM6PR0402MB3944; H:uefi-workstation.ap.freescale.net; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM6PR0402MB3944; 23:pAY7WhjPj4WIe4l6iW7Xbda5r6cCFTvqUU8Vcnh?= =?us-ascii?Q?mU8hpcAoU/ptkEHQw57HXLwrZhBoYKPPmmfRxDHQ7AuoFLYD065TgsV//ojp?= =?us-ascii?Q?HL6qvQpGKnBVBVZpgpuqUJwB8Gtc2+a/eMwX6IFOW4fZJuTOACxfofL7gWD2?= =?us-ascii?Q?BqgMVEj988MBorZY2kgWricXnfFHBX8cApy+D2j0ZMD0/xp05PZMQ9cbz7j8?= =?us-ascii?Q?9XOhetcJjHX4O13VjrnPiDJZuF6Vy4WLxUhXCJV4uNMnNQdXZwMsjcv9/Uj4?= =?us-ascii?Q?4tBH/FxYNQ9NsFMyAHf0RfnrUDaFPfvQjXLc3DQvCbaepBaMGo8NC2KOr4EA?= =?us-ascii?Q?9KYTuq6dWVN2EhQlZeX05HsXJ6cWnznsrI3eydNXcfZTEooH6BtsCQ1VPCVf?= =?us-ascii?Q?DVU8Vfd80VwqP+gmBWXjfcIkgeeyJV8QJwR0uzvo/Pu7WVnJCQftTKefUbek?= =?us-ascii?Q?uUer1vwK1XqsHKzIzUyLzgQi5Pz4wH8tMoGH2m7tMe+TpeVGVfRU+nXje//b?= =?us-ascii?Q?C2xr0qlQYIrFRyr+Ob+ZIv49r4oXKYmLHMUKCOnpvEXEMav672qOnSr6SCXy?= =?us-ascii?Q?BO45fTi+9gHFVHLKWHPIwBKiy3HYjJN2+SCLsDaR408cw5kSO7Un0Tn+XES4?= =?us-ascii?Q?VIkWi6t0aDWAVfXhjAdOyWyWA5HY25k435kVCd1Vk+aU5AFLt2liKQwNEmN1?= =?us-ascii?Q?okxsHngXQ6rKxLpCrSPGll3BjZN/7nKm3rq1M2qosMdJ7GvjTe9i0TpnhDXm?= =?us-ascii?Q?Lwk8g20sggEMtYlAEEv09BVyIhtF5SzZDT/IW/cbXZ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6CFEtiuEeWd69J7Lx0IBhLSt1eu7NftIWc1BnJE=; 7:QLnIxMuf/XhmVD4XSiPQAs37noN8K35iIE0Ir1ZolAhWWNB8gngo+WTLgv9yvXo0Ae8iX+l2CFNrHCdbTcCSbTsFmt7emkvFG0mubh9m9rVt5d6cOsGyLxSTPFmvYLesXjZ0BKmui6tBNt3m0qfL7Q0PlnNRijgRV12gjul0Lx9imnvJrG6Nh/JSbGsYyYD7k5XLZ8t8bHdZWQ4WN7373FKpkb0d4/U4RD/Jqpb2kYa2xBdl9jYHpx9fXBQgDYBM SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2018 11:01:04.5860 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8af924ce-d041-4fc1-f0dd-08d56fac6a86 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR0402MB3944 Subject: [edk2] [RFC] MdePkg/BaseLib: Change BitField functions. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Liming Gao Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The bit field functions in MdePkg are not working as expected. The restrictions on Value parameter such that Value should not be greater than the bitmask value range specified by StartBit and EndBit doesn't seem to make sense. Also the restriction on End bit to not be equal to start bit prohibits single bit change. This is an attempt to correct these limitations. Cc: Michael D Kinney Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Pankaj Bansal --- Notes: This is a RFC patch. MdePkg/Library/BaseLib/BitField.c | 179 ++++++++++++++-------------- 1 file changed, 89 insertions(+), 90 deletions(-) diff --git a/MdePkg/Library/BaseLib/BitField.c b/MdePkg/Library/BaseLib/Bit= Field.c index eb9e276..2b5be52 100644 --- a/MdePkg/Library/BaseLib/BitField.c +++ b/MdePkg/Library/BaseLib/BitField.c @@ -2,6 +2,8 @@ Bit field functions of BaseLib. =20 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.
+ Copyright 2018 NXP + This program and the accompanying materials are licensed and made available under the terms and conditions of the BS= D License which accompanies this distribution. The full text of the license may b= e found at @@ -14,6 +16,12 @@ =20 #include "BaseLibInternals.h" =20 +#define BITMASK_UNITN(StartBit, EndBit) \ + (((MAX_UINTN) << (StartBit)) & (MAX_UINTN >> ((sizeof (UINTN) * 8) - 1= - (EndBit)))) + +#define BITMASK_UNIT64(StartBit, EndBit) \ + (((MAX_UINT64) << (StartBit)) & (MAX_UINT64 >> ((sizeof (UINT64) * 8) = - 1 - (EndBit)))) + /** Worker function that returns a bit field from Operand. =20 @@ -34,11 +42,9 @@ InternalBaseLibBitFieldReadUint ( IN UINTN EndBit ) { - // - // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit] - // are 1's while bit[EndBit + 1] thru the most significant bit are 0's. - // - return (Operand & ~((UINTN)-2 << EndBit)) >> StartBit; + UINTN Mask =3D BITMASK_UNITN (StartBit, EndBit); + + return ( (Operand & Mask) >> StartBit); } =20 /** @@ -68,19 +74,9 @@ InternalBaseLibBitFieldOrUint ( IN UINTN OrData ) { - // - // Higher bits in OrData those are not used must be zero.=20 - // - // EndBit - StartBit + 1 might be 32 while the result right shifting 32 = on a 32bit integer is undefined, - // So the logic is updated to right shift (EndBit - StartBit) bits and c= ompare the last bit directly. - // - ASSERT ((OrData >> (EndBit - StartBit)) =3D=3D ((OrData >> (EndBit - Sta= rtBit)) & 1)); - =20 - // - // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit] - // are 1's while bit[EndBit + 1] thru the most significant bit are 0's. - // - return Operand | ((OrData << StartBit) & ~((UINTN) -2 << EndBit)); + UINTN Mask =3D BITMASK_UNITN (StartBit, EndBit); + + return ( ( (Operand | OrData) & Mask) | (Operand & ~Mask)); } =20 /** @@ -110,19 +106,38 @@ InternalBaseLibBitFieldAndUint ( IN UINTN AndData ) { - // - // Higher bits in AndData those are not used must be zero.=20 - // - // EndBit - StartBit + 1 might be 32 while the result right shifting 32 = on a 32bit integer is undefined, - // So the logic is updated to right shift (EndBit - StartBit) bits and c= ompare the last bit directly. - // - ASSERT ((AndData >> (EndBit - StartBit)) =3D=3D ((AndData >> (EndBit - S= tartBit)) & 1)); - - // - // ~((UINTN)-2 << EndBit) is a mask in which bit[0] thru bit[EndBit] - // are 1's while bit[EndBit + 1] thru the most significant bit are 0's. - // - return Operand & ~((~AndData << StartBit) & ~((UINTN)-2 << EndBit)); + UINTN Mask =3D BITMASK_UNITN (StartBit, EndBit); + + return ( ( (Operand & AndData) & Mask) | (Operand & ~Mask)); +} + +/** + Worker function that writes a bit field to an value, and returns the res= ult. + + Writes Value to the bit field specified by the StartBit and the EndBit in + Operand. All other bits in Operand are preserved. The new 8-bit value is + returned. + + @param Operand Operand on which to perform the bitfield operation. + @param StartBit The ordinal of the least significant bit in the bit fi= eld. + @param EndBit The ordinal of the most significant bit in the bit fie= ld. + @param Value The new value of the bit field. + + @return The new value. + +**/ +UINTN +EFIAPI +InternalBaseLibBitFieldWriteUint ( + IN UINTN Operand, + IN UINTN StartBit, + IN UINTN EndBit, + IN UINTN Value + ) +{ + UINTN Mask =3D BITMASK_UNITN (StartBit, EndBit); + + return ( (Value & Mask) | (Operand & ~Mask)); } =20 /** @@ -153,7 +168,7 @@ BitFieldRead8 ( ) { ASSERT (EndBit < 8); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return (UINT8)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBit= ); } =20 @@ -190,8 +205,8 @@ BitFieldWrite8 ( ) { ASSERT (EndBit < 8); - ASSERT (StartBit <=3D EndBit); - return BitFieldAndThenOr8 (Operand, StartBit, EndBit, 0, Value); + ASSERT (StartBit < EndBit); + return (UINT8)InternalBaseLibBitFieldWriteUint (Operand, StartBit, EndBi= t, Value); } =20 /** @@ -228,7 +243,7 @@ BitFieldOr8 ( ) { ASSERT (EndBit < 8); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return (UINT8)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit, = OrData); } =20 @@ -266,7 +281,7 @@ BitFieldAnd8 ( ) { ASSERT (EndBit < 8); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return (UINT8)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit,= AndData); } =20 @@ -275,7 +290,7 @@ BitFieldAnd8 ( bitwise OR, and returns the result. =20 Performs a bitwise AND between the bit field specified by StartBit and E= ndBit - in Operand and the value specified by AndData, followed by a bitwise=20 + in Operand and the value specified by AndData, followed by a bitwise OR with value specified by OrData. All other bits in Operand are preserved. The new 8-bit value is returned. =20 @@ -308,7 +323,7 @@ BitFieldAndThenOr8 ( ) { ASSERT (EndBit < 8); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return BitFieldOr8 ( BitFieldAnd8 (Operand, StartBit, EndBit, AndData), StartBit, @@ -345,7 +360,7 @@ BitFieldRead16 ( ) { ASSERT (EndBit < 16); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return (UINT16)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBi= t); } =20 @@ -382,8 +397,8 @@ BitFieldWrite16 ( ) { ASSERT (EndBit < 16); - ASSERT (StartBit <=3D EndBit); - return BitFieldAndThenOr16 (Operand, StartBit, EndBit, 0, Value); + ASSERT (StartBit < EndBit); + return (UINT16)InternalBaseLibBitFieldWriteUint (Operand, StartBit, EndB= it, Value); } =20 /** @@ -420,7 +435,7 @@ BitFieldOr16 ( ) { ASSERT (EndBit < 16); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return (UINT16)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit,= OrData); } =20 @@ -458,7 +473,7 @@ BitFieldAnd16 ( ) { ASSERT (EndBit < 16); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return (UINT16)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit= , AndData); } =20 @@ -467,7 +482,7 @@ BitFieldAnd16 ( bitwise OR, and returns the result. =20 Performs a bitwise AND between the bit field specified by StartBit and E= ndBit - in Operand and the value specified by AndData, followed by a bitwise=20 + in Operand and the value specified by AndData, followed by a bitwise OR with value specified by OrData. All other bits in Operand are preserved. The new 16-bit value is returned. =20 @@ -500,7 +515,7 @@ BitFieldAndThenOr16 ( ) { ASSERT (EndBit < 16); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return BitFieldOr16 ( BitFieldAnd16 (Operand, StartBit, EndBit, AndData), StartBit, @@ -537,7 +552,7 @@ BitFieldRead32 ( ) { ASSERT (EndBit < 32); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return (UINT32)InternalBaseLibBitFieldReadUint (Operand, StartBit, EndBi= t); } =20 @@ -574,8 +589,8 @@ BitFieldWrite32 ( ) { ASSERT (EndBit < 32); - ASSERT (StartBit <=3D EndBit); - return BitFieldAndThenOr32 (Operand, StartBit, EndBit, 0, Value); + ASSERT (StartBit < EndBit); + return (UINT32)InternalBaseLibBitFieldWriteUint (Operand, StartBit, EndB= it, Value); } =20 /** @@ -612,7 +627,7 @@ BitFieldOr32 ( ) { ASSERT (EndBit < 32); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return (UINT32)InternalBaseLibBitFieldOrUint (Operand, StartBit, EndBit,= OrData); } =20 @@ -650,7 +665,7 @@ BitFieldAnd32 ( ) { ASSERT (EndBit < 32); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return (UINT32)InternalBaseLibBitFieldAndUint (Operand, StartBit, EndBit= , AndData); } =20 @@ -659,7 +674,7 @@ BitFieldAnd32 ( bitwise OR, and returns the result. =20 Performs a bitwise AND between the bit field specified by StartBit and E= ndBit - in Operand and the value specified by AndData, followed by a bitwise=20 + in Operand and the value specified by AndData, followed by a bitwise OR with value specified by OrData. All other bits in Operand are preserved. The new 32-bit value is returned. =20 @@ -692,7 +707,7 @@ BitFieldAndThenOr32 ( ) { ASSERT (EndBit < 32); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return BitFieldOr32 ( BitFieldAnd32 (Operand, StartBit, EndBit, AndData), StartBit, @@ -729,8 +744,11 @@ BitFieldRead64 ( ) { ASSERT (EndBit < 64); - ASSERT (StartBit <=3D EndBit); - return RShiftU64 (Operand & ~LShiftU64 ((UINT64)-2, EndBit), StartBit); + ASSERT (StartBit < EndBit); + + UINT64 Mask =3D BITMASK_UNIT64 (StartBit, EndBit); + + return ( (Operand & Mask) >> StartBit); } =20 /** @@ -766,8 +784,11 @@ BitFieldWrite64 ( ) { ASSERT (EndBit < 64); - ASSERT (StartBit <=3D EndBit); - return BitFieldAndThenOr64 (Operand, StartBit, EndBit, 0, Value); + ASSERT (StartBit < EndBit); + + UINT64 Mask =3D BITMASK_UNIT64 (StartBit, EndBit); + + return ( (Value & Mask) | (Operand & ~Mask)); } =20 /** @@ -803,23 +824,12 @@ BitFieldOr64 ( IN UINT64 OrData ) { - UINT64 Value1; - UINT64 Value2; - ASSERT (EndBit < 64); - ASSERT (StartBit <=3D EndBit); - // - // Higher bits in OrData those are not used must be zero.=20 - // - // EndBit - StartBit + 1 might be 64 while the result right shifting 64 = on RShiftU64() API is invalid, - // So the logic is updated to right shift (EndBit - StartBit) bits and c= ompare the last bit directly. - // - ASSERT (RShiftU64 (OrData, EndBit - StartBit) =3D=3D (RShiftU64 (OrData,= EndBit - StartBit) & 1)); - - Value1 =3D LShiftU64 (OrData, StartBit); - Value2 =3D LShiftU64 ((UINT64) - 2, EndBit); - - return Operand | (Value1 & ~Value2); + ASSERT (StartBit < EndBit); + + UINT64 Mask =3D BITMASK_UNIT64 (StartBit, EndBit); + + return ( ( (Operand | OrData) & Mask) | (Operand & ~Mask)); } =20 /** @@ -855,23 +865,12 @@ BitFieldAnd64 ( IN UINT64 AndData ) { - UINT64 Value1; - UINT64 Value2; - =20 ASSERT (EndBit < 64); - ASSERT (StartBit <=3D EndBit); - // - // Higher bits in AndData those are not used must be zero.=20 - // - // EndBit - StartBit + 1 might be 64 while the right shifting 64 on RShi= ftU64() API is invalid, - // So the logic is updated to right shift (EndBit - StartBit) bits and c= ompare the last bit directly. - // - ASSERT (RShiftU64 (AndData, EndBit - StartBit) =3D=3D (RShiftU64 (AndDat= a, EndBit - StartBit) & 1)); - - Value1 =3D LShiftU64 (~AndData, StartBit); - Value2 =3D LShiftU64 ((UINT64)-2, EndBit); - - return Operand & ~(Value1 & ~Value2); + ASSERT (StartBit < EndBit); + + UINT64 Mask =3D BITMASK_UNIT64 (StartBit, EndBit); + + return ( ( (Operand & AndData) & Mask) | (Operand & ~Mask)); } =20 /** @@ -879,7 +878,7 @@ BitFieldAnd64 ( bitwise OR, and returns the result. =20 Performs a bitwise AND between the bit field specified by StartBit and E= ndBit - in Operand and the value specified by AndData, followed by a bitwise=20 + in Operand and the value specified by AndData, followed by a bitwise OR with value specified by OrData. All other bits in Operand are preserved. The new 64-bit value is returned. =20 @@ -912,7 +911,7 @@ BitFieldAndThenOr64 ( ) { ASSERT (EndBit < 64); - ASSERT (StartBit <=3D EndBit); + ASSERT (StartBit < EndBit); return BitFieldOr64 ( BitFieldAnd64 (Operand, StartBit, EndBit, AndData), StartBit, --=20 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel