master: loongarch: Adhere to architectural spec for amor_db.d instruction

snuglas via Sbcl-commits <[email protected]> Tue, 21 Jul 2026 19:51:45 +0000
Newsgroups gmane.lisp.steel-bank.cvs
Message-ID <[email protected]>
The branch "master" has been updated in SBCL:
       via  8a0d86c58fc7ec330f99eabced873e5e75496265 (commit)
      from  7ab7c5accbd24412da524c85e008bb21a8c96d05 (commit)

- Log -----------------------------------------------------------------
commit 8a0d86c58fc7ec330f99eabced873e5e75496265
Author: Douglas Katzman <[email protected]>
Date:   Tue Jul 21 19:51:40 2026 +0000

    loongarch: Adhere to architectural spec for amor_db.d instruction
    
    Section 2.2.7 Atomic Memory Access Instructions
     "If the AM* atomic memory access instruction has the same register number
      [for] rd and rk, the execution result is uncertain."
    https://loongson.github.io/LoongArch-Documentation/LoongArch-Vol1-EN.html#_amswapaddandorxormaxmindb_wd_ammaxmin_db_wudu
    
    While "uncertain" could just mean that the result is unpredictable and it's
    fine if you don't care, QEMU version 11 gives you a SIGILL in this case.
---
 src/assembly/loongarch64/alloc.lisp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/assembly/loongarch64/alloc.lisp b/src/assembly/loongarch64/alloc.lisp
index 988d20701..37056452f 100644
--- a/src/assembly/loongarch64/alloc.lisp
+++ b/src/assembly/loongarch64/alloc.lisp
@@ -19,19 +19,20 @@
     ((:arg symbol (descriptor-reg) l0-offset)
      (:temp free-tls-index (any-reg) l1-offset)
      (:temp temp (non-descriptor-reg) nl1-offset)
+     (:temp const (non-descriptor-reg) nl2-offset)
      (:res tls-index (unsigned-reg) nl0-offset))
   (inst addi.d free-tls-index null-tn (+ (static-symbol-offset '*free-tls-index*)
                                        (ash symbol-value-slot word-shift)
                                        (- other-pointer-lowtag)))
   (pseudo-atomic (temp)
     ACQUIRE-LOCK
-    (inst li temp 1)
-    (inst slli.d temp temp (1- n-word-bits))
+    (inst li const 1)
+    (inst slli.d const const (1- n-word-bits))
     WITH-LOCK-BIT
     (loadw tls-index free-tls-index)
     ;; The MSB (i.e. sign) is the semaphore.
     (inst blt tls-index zero-tn WITH-LOCK-BIT)
-    (inst amor_db.d temp temp free-tls-index)
+    (inst amor_db.d temp const free-tls-index)
     (inst bne tls-index temp ACQUIRE-LOCK)
 
     ;; With the spinlock now held, see if the symbol's tls-index has

-----------------------------------------------------------------------


hooks/post-receive
-- 
SBCL