🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #143

Re: Performance of xchg reg,reg

#143
From: Anton Ertl
Date: Fri, 16 Oct 2026 05:50
29 lines
2467 bytes
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>Well, for some reason the LOCK prefix is implied for XCHG.

According to <https://www.felixcloutier.com/x86/xchg> (which is based
on (I think) Intel's documentation):

|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.

This does not cover the "xchg reg, reg" case.

<https://www.felixcloutier.com/x86/lock> says:
|The XCHG instruction always asserts the LOCK# signal regardless of the
|presence or absence of the LOCK prefix.

This seems to include the "xchg reg, reg" case, but asserting the
LOCK# signal would make no difference, because: "the LOCK# signal
ensures that the processor has exclusive use of any shared memory
while the signal is asserted" and "the processor’s cache coherency
mechanism ensures that the operation is carried out atomically with
regards to memory", but "xchg reg, reg" does not use memory at all,
and other processors have no access to a processor's registers.

- anton
-- 
'Anyone trying for "industrial quality" ISA should avoid undefined behavior.'
  Mitch Alsup, <c17fcd89-f024-40e7-a594-88a85ac10d20o@googlegroups.com>
Technical Details
Message-ID: <2026Oct16.075055@mips.complang.tuwien.ac.at>
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
References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <11arg45$2p70p$1@dont-email.me>

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: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.arch
Subject: Re: Performance of xchg reg,reg
Date: Fri, 16 Oct 2026 05:50:55 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 29
Message-ID: <2026Oct16.075055@mips.complang.tuwien.ac.at>
References: <2026Oct13.104347@mips.complang.tuwien.ac.at> <11arg45$2p70p$1@dont-email.me>
Injection-Date: Fri, 16 Oct 2026 06:05:34 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3173223"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+n0aMtNKGeB0qy/ACexIHI"; posting-host="eb1d16796a2f3c3c419013704a6bb9be"
Cancel-Lock: sha1:KIbeo7kctES1Hur7prz8V2mwIwE= sha256:1QO04b+DN8YgttlMZ9Duneh7X1jajsjyxBNuq7nsaQk=
	sha1:/AqT6W0djhbhocmwV5Ku0bMd9d0= sha256:UlnwAkZXSQ6ujv7Doy+wCa9p3bxQoFMdDq/vAJX7qjM=
X-newsreader: xrn 10.11