From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by mx.groups.io with SMTP id smtpd.web11.38492.1683393861585270438 for ; Sat, 06 May 2023 10:24:21 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="signature has expired" header.i=@bsdio.com header.s=fm1 header.b=mMlFsea7; spf=pass (domain: bsdio.com, ip: 66.111.4.27, mailfrom: rebecca@bsdio.com) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id EDE6B5C0253; Sat, 6 May 2023 13:24:20 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Sat, 06 May 2023 13:24:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bsdio.com; h=cc :cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm1; t=1683393860; x= 1683480260; bh=tFS3ZcJfi9mONwedpnh/JOqkiY1VORKdVqZ/EVsqdP4=; b=m MlFsea7qFEHqSeDzWgq0ilnG0R4WZ308+njp1olU649lBB8kySUFaVjsdpuzvGMr 64hvxin97O7KabH/twm3qKKCeTDssrKxojNN20nyVAHaHFKLqFk0Rq268ktQXoZw 5EAMhTkRJ01wNKSZVUqelQJRNg6strvPS9ERs3F8oG+K5mnxtboeHGrI0oVfEFtq +42+T8dEV/TNz3I88HZrpK5Iae0Rnna7YI2h7we+QQkda3lcrvHqCTP1N3riDbSB x57SytBUpoxo1adMLyzqxlZok74HtrE0jenDBXVcfjQ27XDMnAi2aFfrlTy4vVW6 Vt0Q3cwIlexuccLwE2N+w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1683393860; x= 1683480260; bh=tFS3ZcJfi9mONwedpnh/JOqkiY1VORKdVqZ/EVsqdP4=; b=G VpEoC2QZ/UU/3u7nwLc/EnCTQI6OWHViJbkDB07kVuu5MgWp4e+vT/yEhYcn70qr TOX/L36eU19InjjjPtudJXujLcAoarbDM6InDzM5Z7WXXOhzTLGbuRxBcSA+57mf kckWRbYvXegNhXtewlHGn6Z38nVgpX7bzvN38mDd0+jTK2INomtw2jVi0WAPnbcM vgzUQo2uD4+FrB+Tyjw+5+qCb2OyzvcMsgVajyArG29ocB5Yu6PhxVCNayKmqHTh rfCzhpUQi8YfKMCrXbNwUwuY6dMwhrH+RwX8vVxSn1ml+CR/kPkweHtKiZ/e7/GV 4gn1PmM2WYckEAWZZwzPA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvhedrfeefgedgledtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephffvvefufffkofgjfhgggfestdekredtredttdenucfhrhhomheptfgvsggv tggtrgcuvehrrghnuceorhgvsggvtggtrgessghsughiohdrtghomheqnecuggftrfgrth htvghrnhepveegudefjeevkeeuffffgeefgfeghfeuveetgeeuieevvdekudfhhfeivddv ueelnecuffhomhgrihhnpehtihgrnhhotghorhgvrdhorhhgpdgrshhmshihnhgthhhroh hnihiirghtihhonhdrshgsnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehm rghilhhfrhhomheprhgvsggvtggtrgessghsughiohdrtghomh X-ME-Proxy: Feedback-ID: i5b994698:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sat, 6 May 2023 13:24:19 -0400 (EDT) From: "Rebecca Cran" To: devel@edk2.groups.io, Andrew Fish , Leif Lindholm , Michael D Kinney , Liming Gao , Bob Feng , Yuwei Chen Cc: Dongyan Qian , Zhiguang Liu , Chao Li Subject: [PATCH v2 1/7] BaseSynchronizationLib: Fix LoongArch64 synchronization functions Date: Sat, 6 May 2023 11:23:56 -0600 Message-Id: <20230506172402.116-2-rebecca@bsdio.com> X-Mailer: git-send-email 2.40.0.windows.1 In-Reply-To: <20230506172402.116-1-rebecca@bsdio.com> References: <20230506172402.116-1-rebecca@bsdio.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Dongyan Qian REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4432 There is a return value bug: The sc.w/sc.d instruction will destroy the reg_t0, use reg_t1 to avoid context reg_t0 being corrupted. Adjust Check that ptr align is UINT16. Optimize function SyncIncrement and SyncDecrement. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Cc: Chao Li Signed-off-by: Dongyan Qian Reviewed-by: Chao Li --- MdePkg/Library/BaseSynchronizationLib/LoongArch64/AsmSynchronization.S | 30 ++++++++------------ MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchronization.c | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-) diff --git a/MdePkg/Library/BaseSynchronizationLib/LoongArch64/AsmSynchronization.S b/MdePkg/Library/BaseSynchronizationLib/LoongArch64/AsmSynchronization.S index fdd50c54b5f3..03865bf2c966 100644 --- a/MdePkg/Library/BaseSynchronizationLib/LoongArch64/AsmSynchronization.S +++ b/MdePkg/Library/BaseSynchronizationLib/LoongArch64/AsmSynchronization.S @@ -53,9 +53,9 @@ ASM_PFX(AsmInternalSyncCompareExchange32): 1: ll.w $t0, $a0, 0x0 bne $t0, $a1, 2f - move $t0, $a2 - sc.w $t0, $a0, 0x0 - beqz $t0, 1b + move $t1, $a2 + sc.w $t1, $a0, 0x0 + beqz $t1, 1b b 3f 2: dbar 0 @@ -76,9 +76,9 @@ ASM_PFX(AsmInternalSyncCompareExchange64): 1: ll.d $t0, $a0, 0x0 bne $t0, $a1, 2f - move $t0, $a2 - sc.d $t0, $a0, 0x0 - beqz $t0, 1b + move $t1, $a2 + sc.d $t1, $a0, 0x0 + beqz $t1, 1b b 3f 2: dbar 0 @@ -94,13 +94,10 @@ AsmInternalSyncIncrement ( ) **/ ASM_PFX(AsmInternalSyncIncrement): - move $t0, $a0 - dbar 0 - ld.w $t1, $t0, 0x0 - li.w $t2, 1 - amadd.w $t1, $t2, $t0 + li.w $t0, 1 + amadd.w $zero, $t0, $a0 - ld.w $a0, $t0, 0x0 + ld.w $a0, $a0, 0 jirl $zero, $ra, 0 /** @@ -111,12 +108,9 @@ AsmInternalSyncDecrement ( ) **/ ASM_PFX(AsmInternalSyncDecrement): - move $t0, $a0 - dbar 0 - ld.w $t1, $t0, 0x0 - li.w $t2, -1 - amadd.w $t1, $t2, $t0 + li.w $t0, -1 + amadd.w $zero, $t0, $a0 - ld.w $a0, $t0, 0x0 + ld.w $a0, $a0, 0 jirl $zero, $ra, 0 .end diff --git a/MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchronization.c b/MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchronization.c index d696c8ce102f..6baf841c9b09 100644 --- a/MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchronization.c +++ b/MdePkg/Library/BaseSynchronizationLib/LoongArch64/Synchronization.c @@ -81,7 +81,7 @@ InternalSyncCompareExchange16 ( volatile UINT32 *Ptr32; /* Check that ptr is naturally aligned */ - ASSERT (!((UINT64)Value & (sizeof (Value) - 1))); + ASSERT (!((UINT64)Value & (sizeof (UINT16) - 1))); /* Mask inputs to the correct size. */ Mask = (((~0UL) - (1UL << (0)) + 1) & (~0UL >> (64 - 1 - ((sizeof (UINT16) * 8) - 1)))); -- 2.40.0.windows.1