Article View: comp.arch
Article #189Re: Performance of xchg reg,reg
From: Dan Cross
Date: Sun, 18 Oct 2026 17:40
Date: Sun, 18 Oct 2026 17:40
80 lines
4693 bytes
4693 bytes
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.
Technical Details
Message-ID:
<11b309g$9mv$1@reader2.panix.com>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!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>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail From: cross@spitfire.i.gajendra.net (Dan Cross) Newsgroups: comp.arch Subject: Re: Performance of xchg reg,reg Date: Sun, 18 Oct 2026 17:40:00 -0000 (UTC) Organization: PANIX Public Access Internet and UNIX, NYC Message-ID: <11b309g$9mv$1@reader2.panix.com> References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <1792265982-5857@newsgrouper.org> <2026Oct18.170823@mips.complang.tuwien.ac.at> <20261018184318.00000bee@yahoo.com> Injection-Date: Sun, 18 Oct 2026 17:40:00 -0000 (UTC) Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80"; logging-data="9951"; mail-complaints-to="abuse@panix.com" X-Newsreader: trn 4.0-test77 (Sep 1, 2010) Originator: cross@spitfire.i.gajendra.net (Dan Cross)