]> git.ipfire.org Git - thirdparty/gcc.git/commit
LoongArch: Fix the semantic of 16B CAS
authorXi Ruoyao <xry111@xry111.site>
Mon, 18 Aug 2025 09:18:32 +0000 (17:18 +0800)
committerXi Ruoyao <xry111@xry111.site>
Thu, 11 Sep 2025 10:49:36 +0000 (18:49 +0800)
commit4fcb26a35785c67f35ecceb34632dbf5456d240f
tree684a4e7b3d30b8e1f22175a303b90c44b577c957
parent13ec1769fa2404eec8c34ce8e0b87fc28ff5ac76
LoongArch: Fix the semantic of 16B CAS

In a CAS operation, even if expected != *memory we still need to do an
atomic load of *memory into output.  But I made a mistake in the initial
implementation, causing the output to contain junk in this situation.

Like a normal atomic load, the atomic load embedded in the CAS semantic
is required to work on read-only page.  Thus we cannot rely on sc.q to
ensure the atomicity of the load.  Use LSX to perform the load instead,
and also use LSX to compare the 16B values to keep the ll-sc loop body
short.

gcc/ChangeLog:

* config/loongarch/sync.md (atomic_compare_and_swapti_scq):
Require LSX.  Change the operands for the output, the memory,
and the expected value to LSX vector modes.  Add a FCCmode
output to indicate if CAS has written the desired value into
memory.  Use LSX to atomically load both words of the 16B value
in memory.
(atomic_compare_and_swapti): Pun the modes to satisify
the new atomic_compare_and_swapti_scq implementation.  Read the
bool return value from the FCC instead of performing a
comparision.
gcc/config/loongarch/sync.md