Eduardo José Gómez Hernández has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/44166 )

Change subject: arch-x86: Fixed locked cmpxchg8b allows reordering
......................................................................

arch-x86: Fixed locked cmpxchg8b allows reordering

Locked versions of cmpxcgh8b (and cmpxcgh16b) should
be guarded by mfences to prevent reordering from
surrounding memory instructions.

Change-Id: I4a04bb871b4f9a38efd78df194b43f785d5d2236
---
M src/arch/x86/isa/insts/general_purpose/semaphores.py
1 file changed, 29 insertions(+), 2 deletions(-)



diff --git a/src/arch/x86/isa/insts/general_purpose/semaphores.py b/src/arch/x86/isa/insts/general_purpose/semaphores.py
index de7c6ef..ba17541 100644
--- a/src/arch/x86/isa/insts/general_purpose/semaphores.py
+++ b/src/arch/x86/isa/insts/general_purpose/semaphores.py
@@ -159,10 +159,37 @@
 microcode += cmpxchg8bCode % {"rdip": "rdip t7", "sib": "riprel",
                               "l": "", "ul": "",
                               "suffix": "P"}
-microcode += cmpxchg8bCode % {"rdip": "", "sib": "sib",
+
+cmpxchg8bLockedCode = '''
+def macroop CMPXCHG8B_%(suffix)s {
+    .adjust_env clampOsz
+    %(rdip)s
+    mfence
+    lea t1, seg, %(sib)s, disp, dataSize=asz
+    ldsplit%(l)s (t2, t3), seg, [1, t0, t1], disp=0
+
+    sub t0, rax, t2, flags=(ZF,)
+    br label("doneComparing"), flags=(nCZF,)
+    sub t0, rdx, t3, flags=(ZF,)
+doneComparing:
+
+    # If they're equal, set t3:t2 to rbx:rcx to write to memory
+    mov t2, t2, rbx, flags=(CZF,)
+    mov t3, t3, rcx, flags=(CZF,)
+
+    # If they're not equal, set rdx:rax to the value from memory.
+    mov rax, rax, t2, flags=(nCZF,)
+    mov rdx, rdx, t3, flags=(nCZF,)
+
+    # Write to memory
+    stsplit%(ul)s (t2, t3), seg, [1, t0, t1], disp=0
+    mfence
+};
+'''
+microcode += cmpxchg8bLockedCode % {"rdip": "", "sib": "sib",
                               "l": "l", "ul": "ul",
                               "suffix": "LOCKED_M"}
-microcode += cmpxchg8bCode % {"rdip": "rdip t7", "sib": "riprel",
+microcode += cmpxchg8bLockedCode % {"rdip": "rdip t7", "sib": "riprel",
                               "l": "l", "ul": "ul",
                               "suffix": "LOCKED_P"}


--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/44166
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I4a04bb871b4f9a38efd78df194b43f785d5d2236
Gerrit-Change-Number: 44166
Gerrit-PatchSet: 1
Gerrit-Owner: Eduardo José Gómez Hernández <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to