<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <p><font size="2">Reviewed-by: Chao Li <a class="moz-txt-link-rfc2396E" href="mailto:lichao@loongson.cn"><lichao@loongson.cn></a></font><br>
    </p>
    <div class="moz-signature"
      signature-switch-id="18b8a24a-8ce6-4aca-a108-921eeebcd5e9"><br>
      <div
        style="width:15%;height:1px;background-color:grey;transform:scaleY(0.3)"></div>
      <div style="color:grey;font-size:11px">Thanks,<br>
        Chao<br>
      </div>
    </div>
    <div class="moz-cite-prefix">在 2023/4/27 22:51, Dongyan Qian 写道:<br>
    </div>
    <blockquote type="cite"
      cite="mid:20230427145143.1614681-1-qiandongyan@loongson.cn">
      <pre class="moz-quote-pre" wrap="">REF: <a class="moz-txt-link-freetext" href="https://bugzilla.tianocore.org/show_bug.cgi?id=4432">https://bugzilla.tianocore.org/show_bug.cgi?id=4432</a>

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 <a class="moz-txt-link-rfc2396E" href="mailto:michael.d.kinney@intel.com"><michael.d.kinney@intel.com></a>
Cc: Liming Gao <a class="moz-txt-link-rfc2396E" href="mailto:gaoliming@byosoft.com.cn"><gaoliming@byosoft.com.cn></a>
Cc: Zhiguang Liu <a class="moz-txt-link-rfc2396E" href="mailto:zhiguang.liu@intel.com"><zhiguang.liu@intel.com></a>
Cc: Chao Li <a class="moz-txt-link-rfc2396E" href="mailto:lichao@loongson.cn"><lichao@loongson.cn></a>
Signed-off-by: Dongyan Qian <a class="moz-txt-link-rfc2396E" href="mailto:qiandongyan@loongson.cn"><qiandongyan@loongson.cn></a>
---
 .../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
</pre>
    </blockquote>
  </body>
</html>


<div width="1" style="color:white;clear:both">_._,_._,_</div>
<hr>


Groups.io Links:<p>


  
    You receive all messages sent to this group.
  
  


<p>
<a target="_blank" href="https://edk2.groups.io/g/devel/message/103730">View/Reply Online (#103730)</a> |


  

|

  <a target="_blank" href="https://groups.io/mt/98538295/1813853">Mute This Topic</a>

| <a href="https://edk2.groups.io/g/devel/post">New Topic</a><br>




<a href="https://edk2.groups.io/g/devel/editsub/1813853">Your Subscription</a> |
<a href="mailto:devel+owner@edk2.groups.io">Contact Group Owner</a> |

<a href="https://edk2.groups.io/g/devel/unsub">Unsubscribe</a>

 [edk2-devel-archive@redhat.com]<br>
<div width="1" style="color:white;clear:both">_._,_._,_</div>