🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #187

Re: Performance of xchg reg,reg

#187
From: Dan Cross
Date: Sun, 18 Oct 2026 17:09
81 lines
4854 bytes
In article <1792265982-5857@newsgrouper.org>,
MitchAlsup  <user5857@newsgrouper.org.invalid> wrote:
>cross@spitfire.i.gajendra.net (Dan Cross) posted:
>
>> In article <1792257076-5857@newsgrouper.org>,
>> MitchAlsup  <user5857@newsgrouper.org.invalid> wrote:
>> >cross@spitfire.i.gajendra.net (Dan Cross) posted:
>> >
>> >> In article <11au1vu$3ks5m$2@dont-email.me>,
>> >> Thomas Koenig <tkoenig@netcologne.de> wrote:
>> >> >Dan Cross <cross@spitfire.i.gajendra.net> schrieb:
>> >> >> Unfortunately, the information is spread across two sections,
>> >> >> and they contradict.  The description in the `LOCK` prefix
>> >> >> section in the latest version of the Intel SDM includes the text
>> >> >> Anton quoted, while the description of `XCHG` itself makes clear
>> >> >> that the destination operand must be a memory operand for the
>> >> >> locking protocol to automatically apply.  Which is correct?
>> >> >
>> >> >What would be the meaning of LOCK with memory operands?  I can't
>> >> >think of any.
>> >> 
>> >> Using the `LOCK` prefix without a destination operand that is a
>> >> memory operand is an error, and the SDM is quite explicit about
>> >> that.  In fact, it says that an explicit `LOCK` prefix on an
>> >> `XCHG` a register destination operand is _not_ permitted and
>> >> "may" generate an `#UD` exception.
>> >> 
>> >> But sadly, when talking about an `XCHG` _without_ an explicit
>> >> operand, it is left ambiguous; all it says is that, "The `XCHG`
>> >> instruction always asserts the `LOCK#` signal regardless of the
>> >> presence or absence of the `LOCK` prefix."  Devoid of the rest
>> >> of the surrounding context, one could interpret that to mean
>> >> that an `XCHG` _always_ forces a bus lock, irrespective of the
>> >> type of its desintation operand.
>> >> 
>> >> Why? 
>> >
>> >Older machines performed the read, returned the read data to
>> >a core and then sent the data to be written back to memory;
>> >where the time between the read and the write was unknowable.
>> >
>> >Some newer machines take the data to be written and package it
>> >up in an interconnect transaction so the read and write happen
>> >on back-to-back cycles with no possibility of interference.
>> >These are ATOMIC even without any bus-locking. The data read 
>> >out is returned to the core.
>> 
>> No, I get that; I mean in the case where both operands to `XCHG`
>> are _register_ operands.
>> 
>> 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. It took
>me nearly 40 years of doing so to get to the point a mischievous
>engineer could NOT misunderstand what I had written. It is harder
>wo write high quality documentation than perform circuit design.
>
>What they wrote may have well been exactly what the HW did back then
>but somewhere between then and now architects and designers figured
>out other ways and nobody went back to fully scrub the documents.

Maybe?  Probably?  I don't know.  *shrug*

I'm not trying to impugn the tech writers at Intel, who I think
generally do a great job.  But this particular paragraph has
obviously lead to some confusion.

Again, I think that, at the end of the day, `xchg reg, reg` has
no effect on memory ordering at all, and that sentence is meant
to be read within the context of that paragraph; ie, the `LOCK`
prefix is implied if it's not specifically given _and_ the
destination is a memory operand.

	- Dan C.
Technical Details
Message-ID: <11b2ufv$pje$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-mail
References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <1792257076-5857@newsgrouper.org> <11b0bd3$b5b$1@reader2.panix.com> <1792265982-5857@newsgrouper.org>

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:09:19 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <11b2ufv$pje$1@reader2.panix.com>
References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <1792257076-5857@newsgrouper.org> <11b0bd3$b5b$1@reader2.panix.com> <1792265982-5857@newsgrouper.org>
Injection-Date: Sun, 18 Oct 2026 17:09:19 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80";
	logging-data="26222"; mail-complaints-to="abuse@panix.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: cross@spitfire.i.gajendra.net (Dan Cross)