From: ramregar <ram@ramregar.com>
To: linux-assembly@vger.kernel.org
Subject: correct use of mfence
Date: Fri, 27 Feb 2009 15:07:01 -0800 (PST) [thread overview]
Message-ID: <22256244.post@talk.nabble.com> (raw)
Hi,
I am writting atomic inc/dec/cas operations in assembly.
increment64(__int64* value, int val)
{
__int64* temp = &val;
_asm
{
push edi
push ebx
mov edi, pValue
mov eax, [edi]
mov edx, [edi+4]
again:
mov ecx, edx
mov ebx, eax
add ebx, 1
adc ecx, 0
mfence
lock cmpxchg8b [edi]
mfence
jnz again
mov eax, temp
mov [eax], ebx
mov [eax+4], ecx
pop ebx
pop edi
}
}
Requirement is that it should work on single and multi-core
hardwares.
1. Use of mfence is not clear to me. So I temporarily put mfence
before and after cmpxchg8b. I am looking for correct use of mfence
opcode in this context. I would like to know how many lines mfence
serializes before its use.
MFENCE:
This serializing operation guarantees that every load and store
instruction that precedes in program order the MFENCE instruction is
globally visible before any load or store instruction that follows the
MFENCE instruction is globally visible
2. If i use mfence then also i need to use lock opcode before
cmpxchg8b?
What is the correct use of mfence in above assembly code.
Thanks,
Ram
--
View this message in context: http://www.nabble.com/correct-use-of-mfence-tp22256244p22256244.html
Sent from the linux-assembly mailing list archive at Nabble.com.
reply other threads:[~2009-02-27 23:07 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=22256244.post@talk.nabble.com \
--to=ram@ramregar.com \
--cc=linux-assembly@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).