🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #195

Re: Performance of xchg reg,reg

#195
From: Dan Cross
Date: Sun, 18 Oct 2026 17:59
84 lines
4535 bytes
In article <2026Oct18.170823@mips.complang.tuwien.ac.at>,
Anton Ertl <anton@mips.complang.tuwien.ac.at> 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.

Nah; the SDM changes all the time.  It's hard to hand out
citations to it without an explicit version because of that.
There are mistakes all over it; most of them are pretty minor,
like cross-referring to an old section number or something.
Each revision fixes a few and adds a few others.

I think it just hasn't occurred to anyone that it could be
clearer.

>This sentence already exists in my 1994-vintage Pentium Processor
>User's Manual Vol. 3.  There it is preceeded by:
>
>|The LOCK prefix functions only with the following instructions:
>|
>|...
>|XCHG reg, mem
>|XCHG mem, reg
>|...
>
>With no occurence of XCHG reg, reg anywhere.  But, OTOH, this is not
>really a contradiction to the sentence "The XCHG instruction always
>asserts the LOCK# signal regardless of the presence or absence of the
>LOCK prefix."

Right.  The current text says more or less the same thing,
though phrased slightly differently: "The LOCK prefix can be
prepended only to the following instructions and only to those
forms of the instructions where the destination operand is a
memory operand: [list of instructions...]."

>>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.
>
>Actually <https://www.felixcloutier.com/x86/lock> then says that
>"Beginning with the P6 family processors, when [...], the LOCK# signal
>is generally not asserted [...]" and still explains mechanism, finally
>saying "the operation is carried out atomically with regards to
>memory."  If they wrote that as the description of the LOCK prefix,
>much of the rest could be deleted.
>
>Generally, an architecture manual should talk about architectural
>effects, not about asserted signals.
>
>The operational semantics given in
><https://www.felixcloutier.com/x86/lock> is:
>
>| AssertLOCK#(DurationOfAccompaningInstruction);
>
>Oh boy.

That part is fine.  It's talking about the _explicit_ presence
of a `LOCK` prefix, and given the constraints on the
'accompaning' [sic] instruction, that tracks exactly what the
description says.  Volume 3A, sec 11.1.2, describes bus locking,
and what "asserting LOCK#" means.

	- Dan C.
Technical Details
Message-ID: <11b31ef$qiv$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> <11b0bd3$b5b$1@reader2.panix.com> <1792265982-5857@newsgrouper.org> <2026Oct18.170823@mips.complang.tuwien.ac.at>

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