Article View: comp.arch
Article #194Re: Performance of xchg reg,reg
From: Michael S
Date: Sun, 18 Oct 2026 17:54
Date: Sun, 18 Oct 2026 17:54
93 lines
5627 bytes
5627 bytes
On Sun, 18 Oct 2026 17:40:00 -0000 (UTC)
cross@spitfire.i.gajendra.net (Dan Cross) wrote:
> In article <20261018184318.00000bee@yahoo.com>,
> Michael S <already5chosen@yahoo.com> wrote:
> >On Sun, 18 Oct 2026 15:08:23 GMT
> >anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:
> >
> >> MitchAlsup <user5857@newsgrouper.org.invalid> writes:
> >> >cross@spitfire.i.gajendra.net (Dan Cross) posted:
> >> >> What I'm saying is that, as written, the bits in the `LOCK`
> >> >> description above _could_ be interpreted to mean that _any_
> >> >> `XCHG` will always assert the `LOCK#` signal, including an
> >> >> `XCHG` that does not touch memory at all. The "Why?" was
> >> >> rhetorical, as in, "Why would the system do that?" For example,
> >> >> if one wrote, `xchg %ecx, %eax`, why should that assert `LOCK#`?
> >> >> Truly I don't know, and I was just speculating.
> >> >
> >> >Writing high quality documentation is fundamentally hard.
> >>
> >> I don't think that's the issue here. They just did not limit the
> >> sentence "The XCHG instruction always asserts the LOCK# signal
> >> regardless of the presence or absence of the LOCK prefix." to XCHG
> >> instructions with memory operands. That would be easy to fix, but
> >> they did not. And Chris M. Thomasson understood it as including
> >> XCHG reg, reg.
> >>
> >> My guess is that it is easy to fix in principle, but you have to
> >> deal with all kinds of red tape for such a fix, so unless there is
> >> good reason, you don't do it.
> >
> >Frankly, I don't understand what both you and Dan Cross are talking
> >about.
>
> Because you are not reading the same thing we are.
>
> >I don't see how sentence from Intel's manual ("If a memory operand is
> >referenced, the processor’s locking protocol is automatically
> >implemented for the duration of the exchange operation, regardless of
> >the presence or absence of the LOCK prefix or of the value of the
> >IOPL") or sentence from AMD's manual ("If either operand references
> >memory, the processor locks automatically, whether or not the LOCK
> >prefix is used and independently of the value of IOPL.") can be
> >pssibly misunderstood.
>
> Which part of the Intel and AMD manuals?
>
> What Anton raised, and what I'm also referring to, is a a single
> sentence in the SDM's description of the `LOCK` prefix. For
> reference, I am looking at Volume 2A, order number 253666-093US,
> published Sept 2026, page 3-565.
>
> Tucked away in the "Description" section, at the end the third
> paragraph, which describes what instructions can be prefaced by
> `LOCK` and under what conditions, is the single sentence that
> reads: "The `XCHG` instruction always asserts the `LOCK#` signal
> regardless of the presence or absence of the `LOCK` prefix."
> Note: that is a direct quote from the reference.
>
> We know that `XCHG` with a memory destination operand is atomic
> and affects memory ordering, etc, regardless of whether the
> `LOCK` prefix is explicitly given or not. The issue is that
> that sentence, taken in complete isolation, makes it sound like
> this is _also_ the case for `xchg reg, reg`, where the
> destination is a _register_ operand.
>
> I claim that that is a misreading, and that a reader should
> interpret that last sentence in the context of the first
> sentence in that paragraph, that refers specifically to memory
> operands; furthermore, other parts of the SDM are clear that
> `xchg reg, reg` has no impact on memory ordering, bus locks,
> etc.
>
> Regardless, that sentence is ambiguous. References to the
> description of `XCHG`, or to the locking protocols in volume 3,
> does not change that.
>
> The latest version of the entire Intel SDM is available online:
> https://www.intel.com/content/www/us/en/developer/articles/technical/intel-sdm.html
> I had already quoted the paragarph in question in its entirely.
>
> - Dan C.
>
When I want to know what particular insruction does I go to respective
section in Instruction Set Reference.
I can believe that there exist other methodes, but I prefere mine.
Technical Details
Message-ID:
<20261018205430.00001490@yahoo.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mailReferences:
<2026Oct13.104347@mips.complang.tuwien.ac.at> <1792265982-5857@newsgrouper.org> <2026Oct18.170823@mips.complang.tuwien.ac.at> <20261018184318.00000bee@yahoo.com> <11b309g$9mv$1@reader2.panix.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail From: Michael S <already5chosen@yahoo.com> Newsgroups: comp.arch Subject: Re: Performance of xchg reg,reg Date: Sun, 18 Oct 2026 20:54:30 +0300 Organization: A noiseless patient Spider Lines: 93 Message-ID: <20261018205430.00001490@yahoo.com> References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <1792265982-5857@newsgrouper.org> <2026Oct18.170823@mips.complang.tuwien.ac.at> <20261018184318.00000bee@yahoo.com> <11b309g$9mv$1@reader2.panix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Injection-Date: Sun, 18 Oct 2026 17:54:47 +0000 (UTC) Injection-Info: dont-email.me; logging-data="1262206"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19t5Tkd/JJ6/wdgKA6Qvx8IWdGHjyllnkA="; posting-host="f3ba9e4a06adc8c40e079351cfd7a0db" Cancel-Lock: sha1:mfsWu1zN37Vc4daqQjdAjiWsN6A= sha256:ddcJY6pRWDgASjeCEG22uBMiglD74fThD8Ps6rPun9I= sha1:6lHKLRyrho3FeY1Ei7ReTzvXkgo= sha256:c483sVejI+BiUGAd/qJk06yqf+0azz8QCSN3BXRXBV8= X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)