From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from loongson.cn (loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web10.9142.1682643560574550568 for ; Thu, 27 Apr 2023 17:59:21 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: loongson.cn, ip: 114.242.206.163, mailfrom: lichao@loongson.cn) Received: from loongson.cn (unknown [10.40.24.149]) by gateway (Coremail) with SMTP id _____8AxdfBlGktkDeYBAA--.3335S3; Fri, 28 Apr 2023 08:59:17 +0800 (CST) Received: from [10.40.24.149] (unknown [10.40.24.149]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxCLZiGktk+Y0_AA--.20519S3; Fri, 28 Apr 2023 08:59:14 +0800 (CST) Message-ID: Date: Fri, 28 Apr 2023 08:59:14 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [edk2-devel] [PATCH] BaseSynchronizationLib: Fix LoongArch64 synchronization functions To: devel@edk2.groups.io, qiandongyan@loongson.cn Cc: Michael D Kinney , Liming Gao , Zhiguang Liu References: <20230427145143.1614681-1-qiandongyan@loongson.cn> From: "Chao Li" In-Reply-To: <20230427145143.1614681-1-qiandongyan@loongson.cn> X-CM-TRANSID: AQAAf8AxCLZiGktk+Y0_AA--.20519S3 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAPCGRKZfsKSwAAs3 X-Coremail-Antispam: 1Uk129KBjvJXoW7uFWfZF1fJryxGw17Zr18Zrb_yoW8ur1fpr 13t34akF15Kw4fG3W8KFs8JF15XFy8CFyDGa98Jw18ArWDtryv934agr4xXFy09FWxua4I v3W7KrsYk3WUCrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj DUYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUUb4AYFVCjjxCrM7AC8VAFwI0_Jr0_ Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s1l1IIY67AEw4v_Jrv_JF1l8cAvFV AK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xvwVC0I7IYx2IY67AKxVW8JVW5JwA2 z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4x0Y4vEx4A2jsIE14v26F4j6r4UJw A2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UM2AIxVAIcxkEcVAq07x20xvEncxIr21l 57IF6xkI12xvs2x26I8E6xACxx1lYx0E2Ix0cI8IcVAFwI0_JrI_JrylYx0Ex4A2jsIE14 v26r1j6r4UMcvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvEwIxGrwCjr7xvwVCIw2I0I7xG 6c02F41lc7I2V7IY0VAS07AlzVAYIcxG8wCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7x kEbVWUJVW8JwC20s026c02F40E14v26r106r1rMI8I3I0E7480Y4vE14v26r106r1rMI8E 67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCw CI42IY6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1x MIIF0xvEx4A2jsIE14v26r1j6r4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Jr0_GrUvcSsGvf C2KfnxnUUI43ZEXa7IU14rW5UUUUU== Content-Type: multipart/alternative; boundary="------------m0U7PVaj5kKb0wVtCx8BKmYe" --------------m0U7PVaj5kKb0wVtCx8BKmYe Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Reviewed-by: Chao Li Thanks, Chao 在 2023/4/27 22:51, Dongyan Qian 写道: > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4432 > > The sc.w/sc.d instruction will destroy the reg_t0 > Use reg_t1 to avoid context reg_t0 being corrupted. > Optimize function SyncIncrement and SyncDecrement. > > Cc: Michael D Kinney > Cc: Liming Gao > Cc: Zhiguang Liu > Cc: Chao Li > Signed-off-by: Dongyan Qian > --- > .../LoongArch64/AsmSynchronization.S | 30 ++++++++----------- > 1 file changed, 12 insertions(+), 18 deletions(-) > > diff --git a/MdePkg/Library/BaseSynchronizationLib/LoongArch64/AsmSynchronization.S b/MdePkg/Library/BaseSynchronizationLib/LoongArch64/AsmSynchronization.S > index fdd50c54b5..03865bf2c9 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 --------------m0U7PVaj5kKb0wVtCx8BKmYe Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

Reviewed-by: Chao Li <lichao@loongson.cn>


Thanks,
Chao
在 2023/4/27 22:51, Dongyan Qian 写道:
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4432

The sc.w/sc.d instruction will destroy the reg_t0
Use reg_t1 to avoid context reg_t0 being corrupted.
Optimize function SyncIncrement and SyncDecrement.

Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang.liu@intel.com>
Cc: Chao Li <lichao@loongson.cn>
Signed-off-by: Dongyan Qian <qiandongyan@loongson.cn>
---
 .../LoongArch64/AsmSynchronization.S          | 30 ++++++++-----------
 1 file changed, 12 insertions(+), 18 deletions(-)

diff --git a/MdePkg/Library/BaseSynchronizationLib/LoongArch64/AsmSynchronization.S b/MdePkg/Library/BaseSynchronizationLib/LoongArch64/AsmSynchronization.S
index fdd50c54b5..03865bf2c9 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
--------------m0U7PVaj5kKb0wVtCx8BKmYe--