🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.arch
Article #167

Re: Performance of xchg reg,reg

#167
From: Thomas Koenig
Date: Sat, 17 Oct 2026 09:48
56 lines
3715 bytes
Scott Lurndal <scott@slp53.sl.home> schrieb:
> Thomas Koenig <tkoenig@netcologne.de> writes:
>>Dan Cross <cross@spitfire.i.gajendra.net> schrieb:
>>> In article <20261016113441.00002a5f@yahoo.com>,
>>> Michael S  <already5chosen@yahoo.com> wrote:
>>>>On Fri, 16 Oct 2026 05:50:55 GMT
>>>>anton@mips.complang.tuwien.ac.at (Anton Ertl) wrote:
>>>>
>>>>> "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, 
>>>>
>>>>No, it does not.
>>>
>>> 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.
>
> Did you mean 'without memory operands'?

Yes.  I canceled the article, but either was too late or some
server does not honor the cancel.

> It's clear that there
> is no need to acquire the cache and/or system lock if there
> are no memory operands, and a substantial performance penalty;
> besides, which cache line would it use for the case where both
> operands are registers?

Exactly.

-- 
This USENET posting was made without artificial intelligence,
artificial impertinence, artificial arrogance, artificial stupidity,
artificial flavorings or artificial colorants.
Technical Details
Message-ID: <11avg8t$2skj$1@dont-email.me>
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> <2026Oct16.075055@mips.complang.tuwien.ac.at> <20261016113441.00002a5f@yahoo.com> <11atq3a$nqi$1@reader2.panix.com> <11au1vu$3ks5m$2@dont-email.me> <g4wAS.119956$2%g.24960@fx41.iad>

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: Thomas Koenig <tkoenig@netcologne.de>
Newsgroups: comp.arch
Subject: Re: Performance of xchg reg,reg
Date: Sat, 17 Oct 2026 09:48:13 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <11avg8t$2skj$1@dont-email.me>
References: <2026Oct13.104347@mips.complang.tuwien.ac.at>
 <11arg45$2p70p$1@dont-email.me>
 <2026Oct16.075055@mips.complang.tuwien.ac.at>
 <20261016113441.00002a5f@yahoo.com> <11atq3a$nqi$1@reader2.panix.com>
 <11au1vu$3ks5m$2@dont-email.me> <g4wAS.119956$2%g.24960@fx41.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 17 Oct 2026 09:48:13 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="94867"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18JwCqn+mdZS7cc00uvpCCNnWDv0SrogUE="; posting-host="1d7488cb12994fd593f79ba654feadc7"
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:BLHRRB0/SS+HnKnYGGuGmn0e86E= sha256:nh9++Wv8Z82dpIVyJ6e58mfpLflZcAJScphSUi+m0Uw=
	sha1:sYRdtYDbUGCYiPf4vizqf7GEVtk= sha256:DiCEjJ5cFiMXdhp2siTvrGp1FCtzXCfbeF0S5qYlLOA=